feat(chat): render commercial actions and persist greetings

This commit is contained in:
Codex
2026-07-23 14:52:34 +08:00
parent b1f52c68e8
commit 537a0a2c36
26 changed files with 548 additions and 1 deletions
+16
View File
@@ -12,6 +12,10 @@ import { getApiConfig } from "@/core/net/config/api_config";
import { ExceptionHandler } from "@/core/errors";
import { AppEnvUtil } from "@/utils/app-env";
import { Logger } from "@/utils/logger";
import {
CommercialActionSchema,
type CommercialAction,
} from "@/data/schemas/chat";
const log = new Logger("ChatWebSocket");
const RECONNECT_DELAY_MS = 3000;
@@ -40,6 +44,7 @@ export class ChatWebSocket {
onVoiceReady: ((index: number, audioUrl: string) => void) | null = null;
onImage: ((url: string) => void) | null = null;
onPaywallStatus: ((payload: PaywallStatusPayload) => void) | null = null;
onCommercialAction: ((action: CommercialAction) => void) | null = null;
onError: ((errorMessage: string) => void) | null = null;
constructor(
@@ -140,6 +145,12 @@ export class ChatWebSocket {
url?: string | null;
};
lockDetail?: Partial<PaywallStatusPayload>;
actionId?: string;
type?: string;
copy?: string;
ctaLabel?: string;
target?: string;
ruleId?: string;
};
};
try {
@@ -179,6 +190,11 @@ export class ChatWebSocket {
});
break;
}
case "commercial_action": {
const action = CommercialActionSchema.safeParse(payload.data);
if (action.success) this.onCommercialAction?.(action.data);
break;
}
case "error":
this.onError?.(payload.error ?? "Unknown error");
break;