feat(chat): add support action cards and live entitlements

This commit is contained in:
Codex
2026-07-24 17:59:57 +08:00
parent 19b8fc51d6
commit 76bffc1a0d
52 changed files with 1151 additions and 40 deletions
+10
View File
@@ -14,6 +14,8 @@ import { AppEnvUtil } from "@/utils/app-env";
import { Logger } from "@/utils/logger";
import {
CommercialActionSchema,
ChatActionSchema,
type ChatAction,
type CommercialAction,
} from "@/data/schemas/chat";
@@ -45,6 +47,7 @@ export class ChatWebSocket {
onImage: ((url: string) => void) | null = null;
onPaywallStatus: ((payload: PaywallStatusPayload) => void) | null = null;
onCommercialAction: ((action: CommercialAction) => void) | null = null;
onChatAction: ((action: ChatAction) => void) | null = null;
onError: ((errorMessage: string) => void) | null = null;
constructor(
@@ -151,6 +154,8 @@ export class ChatWebSocket {
ctaLabel?: string;
target?: string;
ruleId?: string;
kind?: string;
orderId?: string | null;
};
};
try {
@@ -195,6 +200,11 @@ export class ChatWebSocket {
if (action.success) this.onCommercialAction?.(action.data);
break;
}
case "chat_action": {
const action = ChatActionSchema.safeParse(payload.data);
if (action.success) this.onChatAction?.(action.data);
break;
}
case "error":
this.onError?.(payload.error ?? "Unknown error");
break;