@alxxsck/ai-assistant 1.2.0 → 1.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +17 -11
- package/dist/bridge-ai-chat-widget.es.js +1564 -1420
- package/dist/domain/command/CommandRuntime.d.ts +2 -8
- package/dist/domain/command/UiCommandService.d.ts +24 -0
- package/dist/domain/command/command.errors.d.ts +5 -0
- package/dist/domain/command/command.types.d.ts +70 -6
- package/dist/index.types.d.ts +1 -1
- package/package.json +1 -1
|
@@ -11,8 +11,7 @@ type InternalHandlers = {
|
|
|
11
11
|
};
|
|
12
12
|
export declare class CommandRuntime {
|
|
13
13
|
private readonly onStatus?;
|
|
14
|
-
private readonly
|
|
15
|
-
private readonly hostHandlers;
|
|
14
|
+
private readonly uiCommands;
|
|
16
15
|
private readonly internalHandlers;
|
|
17
16
|
private readonly internalHandlersReady;
|
|
18
17
|
private resolveInternalHandlers;
|
|
@@ -28,21 +27,16 @@ export declare class CommandRuntime {
|
|
|
28
27
|
destroy(): void;
|
|
29
28
|
private executeOnce;
|
|
30
29
|
private dispatch;
|
|
31
|
-
private executeTargetCommand;
|
|
32
30
|
private executeHighlight;
|
|
33
31
|
private executeShowCta;
|
|
34
|
-
private canOpenPage;
|
|
35
|
-
private canOpenModal;
|
|
36
32
|
private requireTarget;
|
|
33
|
+
private requireEnvelopeTarget;
|
|
37
34
|
private findTargetElement;
|
|
38
35
|
private applyDefaultHighlight;
|
|
39
36
|
private removeDefaultHighlight;
|
|
40
37
|
private requireInternal;
|
|
41
38
|
private requireString;
|
|
42
39
|
private firstDefined;
|
|
43
|
-
private applyUrlFallback;
|
|
44
|
-
private targetUrl;
|
|
45
|
-
private assertTargetCode;
|
|
46
40
|
private finish;
|
|
47
41
|
private storageKey;
|
|
48
42
|
private loadCompleted;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { HostCommandHandlerName, HostCommandHandlers, UiCommandActionSnapshot, UiCommandTarget, UiTarget } from "./command.types";
|
|
2
|
+
type NavigationCommandType = "open_page" | "open_modal";
|
|
3
|
+
export declare class UiCommandService {
|
|
4
|
+
private readonly targets;
|
|
5
|
+
private readonly handlers;
|
|
6
|
+
constructor(targets?: Record<string, UiTarget>, handlers?: HostCommandHandlers);
|
|
7
|
+
registerTarget(code: string, target: UiTarget): () => void;
|
|
8
|
+
getTarget(code: string): UiTarget | undefined;
|
|
9
|
+
getHandler<K extends HostCommandHandlerName>(name: K): HostCommandHandlers[K];
|
|
10
|
+
registerHandler<K extends HostCommandHandlerName>(name: K, handler: NonNullable<HostCommandHandlers[K]>): () => void;
|
|
11
|
+
resolveAction(commandType: NavigationCommandType, payload: Readonly<Record<string, unknown>>, target?: UiCommandTarget): Readonly<UiCommandActionSnapshot>;
|
|
12
|
+
execute(commandType: NavigationCommandType, commandId: string, payload: Readonly<Record<string, unknown>>, target?: UiCommandTarget): Promise<void>;
|
|
13
|
+
executeAction(action: Readonly<UiCommandActionSnapshot>, commandId: string, payload: Readonly<Record<string, unknown>>): Promise<void>;
|
|
14
|
+
canExecute(action: Readonly<UiCommandActionSnapshot>): boolean;
|
|
15
|
+
private resolveCanonicalAction;
|
|
16
|
+
private resolveLegacyAction;
|
|
17
|
+
private assertLegacyTarget;
|
|
18
|
+
private targetUrl;
|
|
19
|
+
private applyUrlFallback;
|
|
20
|
+
private isSameOriginUrl;
|
|
21
|
+
private requireNonEmptyString;
|
|
22
|
+
private assertTargetCode;
|
|
23
|
+
}
|
|
24
|
+
export {};
|
|
@@ -14,18 +14,35 @@ export type CommandEnvelope = {
|
|
|
14
14
|
sequence: number;
|
|
15
15
|
occurredAt: string;
|
|
16
16
|
data: {
|
|
17
|
+
contractVersion: number;
|
|
17
18
|
commandId: string;
|
|
18
19
|
scenarioRunId: string;
|
|
19
20
|
interactionSessionId: string;
|
|
20
21
|
commandType: string;
|
|
21
|
-
target?:
|
|
22
|
-
id?: string;
|
|
23
|
-
code?: string;
|
|
24
|
-
};
|
|
22
|
+
target?: UiCommandTarget;
|
|
25
23
|
payload: Record<string, unknown>;
|
|
26
24
|
expiresAt: string | null;
|
|
27
25
|
};
|
|
28
26
|
};
|
|
27
|
+
export type PageCommandTarget = {
|
|
28
|
+
id: string;
|
|
29
|
+
code: string;
|
|
30
|
+
kind: "page";
|
|
31
|
+
route: string;
|
|
32
|
+
};
|
|
33
|
+
export type ModalCommandTarget = {
|
|
34
|
+
id: string;
|
|
35
|
+
code: string;
|
|
36
|
+
kind: "modal";
|
|
37
|
+
modalName: string;
|
|
38
|
+
};
|
|
39
|
+
export type ElementCommandTarget = {
|
|
40
|
+
id: string;
|
|
41
|
+
code: string;
|
|
42
|
+
kind: "button" | "element" | "handler";
|
|
43
|
+
selector?: string;
|
|
44
|
+
};
|
|
45
|
+
export type UiCommandTarget = PageCommandTarget | ModalCommandTarget | ElementCommandTarget;
|
|
29
46
|
export type UiTargetKind = "button" | "element" | "modal" | "page";
|
|
30
47
|
export type UiTarget = {
|
|
31
48
|
kind: UiTargetKind;
|
|
@@ -33,6 +50,8 @@ export type UiTarget = {
|
|
|
33
50
|
selector?: string;
|
|
34
51
|
/** Trusted route used by the built-in openPage fallback. */
|
|
35
52
|
route?: string;
|
|
53
|
+
/** Legacy modal registry key used while commands do not contain a canonical target. */
|
|
54
|
+
modalName?: string;
|
|
36
55
|
/** Explicit URL fallback. It may include query parameters such as lola_modal. */
|
|
37
56
|
url?: string;
|
|
38
57
|
/** Query parameters merged into url, route, or the current location. Null removes a key. */
|
|
@@ -49,6 +68,49 @@ export type HostCommandContext = {
|
|
|
49
68
|
modalId?: string;
|
|
50
69
|
modalCode?: string;
|
|
51
70
|
};
|
|
71
|
+
export type OpenPageContext = {
|
|
72
|
+
commandId: string;
|
|
73
|
+
pageCode: string;
|
|
74
|
+
route: string;
|
|
75
|
+
payload: Readonly<Record<string, unknown>>;
|
|
76
|
+
/** @deprecated Use pageCode. */
|
|
77
|
+
target: string;
|
|
78
|
+
/** @deprecated The command type is fixed for this callback. */
|
|
79
|
+
commandType: "open_page";
|
|
80
|
+
/** @deprecated Use route. */
|
|
81
|
+
url: string;
|
|
82
|
+
/** @deprecated Used only by legacy local target integrations. */
|
|
83
|
+
targetDefinition?: UiTarget;
|
|
84
|
+
};
|
|
85
|
+
export type OpenModalContext = {
|
|
86
|
+
commandId: string;
|
|
87
|
+
modalCode: string;
|
|
88
|
+
modalName: string;
|
|
89
|
+
payload: Readonly<Record<string, unknown>>;
|
|
90
|
+
/** @deprecated Use modalCode. */
|
|
91
|
+
target: string;
|
|
92
|
+
/** @deprecated The command type is fixed for this callback. */
|
|
93
|
+
commandType: "open_modal";
|
|
94
|
+
/** @deprecated Use modalCode. */
|
|
95
|
+
modalId: string;
|
|
96
|
+
/** @deprecated Used only by legacy URL-based modal integrations. */
|
|
97
|
+
url?: string;
|
|
98
|
+
/** @deprecated Used only by legacy local target integrations. */
|
|
99
|
+
targetDefinition?: UiTarget;
|
|
100
|
+
};
|
|
101
|
+
export type UiCommandActionSnapshot = {
|
|
102
|
+
kind: "page";
|
|
103
|
+
code: string;
|
|
104
|
+
route: string;
|
|
105
|
+
target?: PageCommandTarget;
|
|
106
|
+
} | {
|
|
107
|
+
kind: "modal";
|
|
108
|
+
code: string;
|
|
109
|
+
modalName?: string;
|
|
110
|
+
url?: string;
|
|
111
|
+
selector?: string;
|
|
112
|
+
target?: ModalCommandTarget;
|
|
113
|
+
};
|
|
52
114
|
export type HighlightCommandContext = HostCommandContext & {
|
|
53
115
|
active: boolean;
|
|
54
116
|
element?: Element;
|
|
@@ -57,6 +119,8 @@ export type CtaCommandContext = Omit<HostCommandContext, "target"> & {
|
|
|
57
119
|
label: string;
|
|
58
120
|
action: "none" | "open_modal" | "open_page";
|
|
59
121
|
target?: string;
|
|
122
|
+
/** Resolved once when SHOW_CTA arrives and reused unchanged after the click. */
|
|
123
|
+
uiAction?: Readonly<UiCommandActionSnapshot>;
|
|
60
124
|
};
|
|
61
125
|
export type StartVoiceConversationCommandContext = {
|
|
62
126
|
commandId: string;
|
|
@@ -81,8 +145,8 @@ export type SpeakTextCommandContext = {
|
|
|
81
145
|
channels: 1;
|
|
82
146
|
};
|
|
83
147
|
export type HostCommandHandlers = {
|
|
84
|
-
openPage?: (context:
|
|
85
|
-
openModal?: (context:
|
|
148
|
+
openPage?: (context: OpenPageContext) => void | Promise<void>;
|
|
149
|
+
openModal?: (context: OpenModalContext) => void | Promise<void>;
|
|
86
150
|
highlight?: (context: HighlightCommandContext) => void | Promise<void>;
|
|
87
151
|
showCta?: (context: CtaCommandContext) => void | Promise<void>;
|
|
88
152
|
};
|
package/dist/index.types.d.ts
CHANGED
|
@@ -47,4 +47,4 @@ export declare class ChatWidgetInstance extends EventTarget {
|
|
|
47
47
|
addEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions): void;
|
|
48
48
|
}
|
|
49
49
|
export type { CustomerInteractionSession };
|
|
50
|
-
export type { CommandAck, CommandAckStatus, CommandEnvelope, CommandEventDetail, CommandType, CtaCommandContext, HighlightCommandContext, HostCommandContext, HostCommandHandler, HostCommandHandlerName, HostCommandHandlers, SpeakTextCommandContext, StartVoiceConversationCommandContext, UiTarget, UiTargetKind, } from "./domain/command/command.types";
|
|
50
|
+
export type { CommandAck, CommandAckStatus, CommandEnvelope, CommandEventDetail, CommandType, CtaCommandContext, HighlightCommandContext, HostCommandContext, HostCommandHandler, HostCommandHandlerName, HostCommandHandlers, ModalCommandTarget, OpenModalContext, OpenPageContext, PageCommandTarget, SpeakTextCommandContext, StartVoiceConversationCommandContext, UiCommandActionSnapshot, UiCommandTarget, UiTarget, UiTargetKind, } from "./domain/command/command.types";
|
package/package.json
CHANGED