@alxxsck/ai-assistant 2.18.0 → 2.20.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.
@@ -1,4 +1,4 @@
1
- import { a0 as A, a1 as e, a3 as s, G as n, a2 as r } from "./index-raaheNwM.js";
1
+ import { a2 as A, a3 as e, a5 as s, H as n, a4 as r } from "./index-BVQY-1rm.js";
2
2
  export {
3
3
  A as ChatWidgetInstance,
4
4
  e as EXTERNALLY_AVAILABLE_ACTIONS,
@@ -2,9 +2,12 @@ import type { AppApi } from "@/App";
2
2
  import type { Avatar } from "@/avatar/Avatar";
3
3
  import type { WidgetConfig } from "@/index.types";
4
4
  import type { CtaCommandContext } from "@/domain/command/command.types";
5
+ import type { SurfaceTransitionContext } from "@/domain/scenario-interaction/scenario-interaction.types";
5
6
  type ChatWidgetContextValue = {
6
7
  open: boolean;
7
8
  setOpen: (v: boolean) => void;
9
+ transitionSurface: (open: boolean, context: SurfaceTransitionContext) => void;
10
+ surfaceEpisodeId: string | null;
8
11
  isFullscreen: boolean;
9
12
  setFullscreen: (fullscreen: boolean) => void;
10
13
  contentActivated: boolean;
@@ -1,9 +1,10 @@
1
1
  import type { CustomerInteractionSession } from "@/types";
2
2
  import { type CommandAck, type CommandEnvelope, type CommandEventDetail, type CtaCommandContext, type HostCommandHandlerName, type HostCommandHandlers, type SpeakTextCommandContext, type StartVoiceConversationCommandContext, type UiTarget } from "./command.types";
3
+ import type { ScenarioInteractionRuntime } from "@/domain/scenario-interaction/ScenarioInteractionRuntime";
3
4
  type AckSender = (ack: CommandAck) => Promise<unknown>;
4
5
  type InternalHandlers = {
5
- setAssistantVisible?: (visible: boolean) => void;
6
- setChatOpen?: (open: boolean) => void;
6
+ setAssistantVisible?: (visible: boolean, commandId: string) => void;
7
+ setChatOpen?: (open: boolean, commandId: string) => void;
7
8
  playAnimation?: (animation: string, expiresAt?: string | null) => void | Promise<void>;
8
9
  showCta?: (context: CtaCommandContext) => void;
9
10
  connectTelegram?: (context: CtaCommandContext) => void | Promise<void>;
@@ -12,6 +13,7 @@ type InternalHandlers = {
12
13
  };
13
14
  export declare class CommandRuntime {
14
15
  private readonly onStatus?;
16
+ private readonly scenarioInteractions?;
15
17
  private readonly uiCommands;
16
18
  private readonly internalHandlers;
17
19
  private readonly internalHandlersReady;
@@ -19,16 +21,25 @@ export declare class CommandRuntime {
19
21
  private readonly completed;
20
22
  private readonly inFlight;
21
23
  private readonly highlights;
22
- constructor(targets?: Record<string, UiTarget>, handlers?: HostCommandHandlers, onStatus?: ((detail: CommandEventDetail) => void) | undefined);
24
+ private readonly targetObservationCleanups;
25
+ private readonly targetActivationOwners;
26
+ private readonly activeCustomHighlights;
27
+ private readonly targetHighlightOperations;
28
+ private principalSessionId;
29
+ private principalGeneration;
30
+ private destroyed;
31
+ constructor(targets?: Record<string, UiTarget>, handlers?: HostCommandHandlers, onStatus?: ((detail: CommandEventDetail) => void) | undefined, scenarioInteractions?: ScenarioInteractionRuntime | undefined);
23
32
  registerTarget(code: string, target: UiTarget): () => void;
24
33
  registerHostHandler<K extends HostCommandHandlerName>(name: K, handler: NonNullable<HostCommandHandlers[K]>): () => void;
25
34
  setInternalHandlers(handlers: InternalHandlers): () => void;
26
35
  execute(envelope: CommandEnvelope, session: CustomerInteractionSession, sendAck: AckSender): Promise<void>;
36
+ updateSession(session: CustomerInteractionSession): void;
27
37
  executeCtaAction(context: CtaCommandContext): Promise<void>;
28
38
  destroy(): void;
29
39
  private executeOnce;
30
40
  private dispatch;
31
41
  private executeHighlight;
42
+ private executeHighlightSerial;
32
43
  private executeShowCta;
33
44
  private executeConnectTelegram;
34
45
  private requireTarget;
@@ -37,10 +48,22 @@ export declare class CommandRuntime {
37
48
  private findTargetElement;
38
49
  private applyDefaultHighlight;
39
50
  private removeDefaultHighlight;
51
+ private observeTarget;
52
+ private createTargetActivationReporter;
53
+ private removeTargetObservation;
54
+ private removeTargetTracking;
55
+ private deactivateCustomHighlight;
56
+ private removeCustomHighlightForCommand;
57
+ private invokeCustomHighlight;
58
+ private queueCustomHighlightCleanup;
59
+ private clearCustomHighlights;
40
60
  private requireInternal;
41
61
  private requireString;
42
62
  private firstDefined;
43
63
  private finish;
64
+ private ensurePrincipal;
65
+ private resetPrincipalState;
66
+ private isCurrentPrincipal;
44
67
  private storageKey;
45
68
  private loadCompleted;
46
69
  private saveCompleted;
@@ -91,6 +91,12 @@ export type UiCommandActionSnapshot = {
91
91
  export type HighlightCommandContext = HostCommandContext & {
92
92
  active: boolean;
93
93
  element?: Element;
94
+ /**
95
+ * Reports the product action caused by this active highlight. Call it
96
+ * synchronously from the host-owned action handler, before navigation. The
97
+ * SDK records only that activation happened; it does not infer its outcome.
98
+ */
99
+ reportActivation: () => void;
94
100
  };
95
101
  export type CtaCommandContext = Omit<HostCommandContext, "target"> & {
96
102
  label: string;
@@ -3,8 +3,10 @@ import { AnyCableService } from "./AnyCable.service";
3
3
  import { NetworkStatus } from "./CableContext.types";
4
4
  import type { WidgetConfig } from "@/index.types";
5
5
  import type { CommandRuntime } from "@/domain/command/CommandRuntime";
6
+ import { EndUserTypingClient } from "@/domain/message/typing/end-user-typing.client";
6
7
  interface CableContextType {
7
8
  anycableService: AnyCableService | null;
9
+ endUserTypingClient: EndUserTypingClient;
8
10
  networkStatus: NetworkStatus;
9
11
  }
10
12
  interface CableProviderProps {
@@ -0,0 +1,38 @@
1
+ export declare const END_USER_TYPING_IDLE_MS = 2000;
2
+ export declare const END_USER_TYPING_RENEW_MS = 3000;
3
+ export type EndUserTypingCommand = Readonly<{
4
+ conversationId: string;
5
+ isTyping: boolean;
6
+ }>;
7
+ export interface EndUserTypingSocket {
8
+ isConnected(): boolean;
9
+ onConnect(listener: () => void): void;
10
+ offConnect(listener: () => void): void;
11
+ connect(): void;
12
+ disconnect(): void;
13
+ send(command: EndUserTypingCommand): void;
14
+ }
15
+ type EndUserTypingSocketFactory = (accessToken: string) => EndUserTypingSocket;
16
+ /**
17
+ * Sends content-free, volatile typing hints for the one conversation being edited.
18
+ * The socket is created lazily and no command is queued while the transport is offline.
19
+ */
20
+ export declare class EndUserTypingClient {
21
+ private readonly accessToken;
22
+ private readonly socketFactory;
23
+ private readonly now;
24
+ private socket;
25
+ private conversationId;
26
+ private lastPublicationAt;
27
+ private idleTimer;
28
+ constructor(accessToken: string, socketFactory?: EndUserTypingSocketFactory, now?: () => number);
29
+ markActivity(conversationId: string): void;
30
+ stop(): void;
31
+ dispose(): void;
32
+ private readonly handleConnect;
33
+ private publish;
34
+ private ensureSocket;
35
+ private scheduleIdleStop;
36
+ private clearIdleTimer;
37
+ }
38
+ export {};
@@ -0,0 +1,91 @@
1
+ import type { CustomerInteractionSession } from "@/types";
2
+ import { type ScenarioInteractionDraft, type ScenarioInteractionObservation } from "./scenario-interaction.types";
3
+ type CollectorOptions = {
4
+ baseUrl?: string;
5
+ queueLimit?: number;
6
+ batchLimit?: number;
7
+ flushIntervalMs?: number;
8
+ requestTimeoutMs?: number;
9
+ fetch?: typeof fetch;
10
+ createId?: () => string;
11
+ now?: () => number;
12
+ random?: () => number;
13
+ };
14
+ export declare class ScenarioInteractionCollector {
15
+ private readonly getSession;
16
+ private readonly onSessionExpired;
17
+ private readonly queue;
18
+ private readonly baseUrl;
19
+ private readonly queueLimit;
20
+ private readonly batchLimit;
21
+ private readonly flushIntervalMs;
22
+ private readonly requestTimeoutMs;
23
+ private readonly fetchImpl;
24
+ private readonly createId;
25
+ private readonly now;
26
+ private readonly random;
27
+ private sequence;
28
+ private capabilities;
29
+ private capabilityRequest;
30
+ private flushRequest;
31
+ private capabilityRequestControl;
32
+ private batchRequestControl;
33
+ private batchRequestUsesKeepalive;
34
+ private flushTimer;
35
+ private retryTimer;
36
+ private capabilityRetryTimer;
37
+ private retryAttempt;
38
+ private capabilityRetryAttempt;
39
+ private batchRetriesSuspended;
40
+ private capabilityRetriesSuspended;
41
+ private awaitingRenewalToken;
42
+ private sessionGeneration;
43
+ private quotaBlockedUntil;
44
+ private admissionWindowStartedAt;
45
+ private admissionCount;
46
+ private started;
47
+ private destroyed;
48
+ private principalSessionId;
49
+ private principalAccessToken;
50
+ constructor(getSession: () => CustomerInteractionSession, onSessionExpired: () => void, options?: CollectorOptions);
51
+ start(): void;
52
+ destroy(): void;
53
+ updateSession(session: CustomerInteractionSession): boolean;
54
+ enqueue(draft: ScenarioInteractionDraft): string | null;
55
+ getQueueSnapshot(): readonly ScenarioInteractionObservation[];
56
+ isSendingEnabled(): boolean;
57
+ getPrincipalSessionId(): string;
58
+ flush(options?: {
59
+ keepalive?: boolean;
60
+ }): Promise<void>;
61
+ private readonly onOnlineOrFocus;
62
+ private readonly onVisibilityChange;
63
+ private readonly onPageHide;
64
+ private buildObservation;
65
+ private buildDetails;
66
+ private ensureCapabilities;
67
+ private loadCapabilities;
68
+ private flushOnce;
69
+ private selectBatch;
70
+ private dropUnsupportedObservations;
71
+ private isSupported;
72
+ private sessionNeedsRenewal;
73
+ private isCurrentGeneration;
74
+ private nextSequence;
75
+ private abortPendingRequests;
76
+ private createRequestControl;
77
+ private finishRequestControl;
78
+ private handleUnauthorized;
79
+ private scheduleFlush;
80
+ private scheduleRetry;
81
+ private scheduleCapabilityRetry;
82
+ private clearFlushTimer;
83
+ private clearTimers;
84
+ private clearRetryTimer;
85
+ private clearCapabilityRetryTimer;
86
+ private retryDelay;
87
+ private disableSending;
88
+ private admitWithinSessionQuota;
89
+ private isQuotaBlocked;
90
+ }
91
+ export {};
@@ -0,0 +1,28 @@
1
+ import type { CustomerInteractionSession } from "@/types";
2
+ import { ScenarioInteractionCollector } from "./ScenarioInteractionCollector";
3
+ import type { EngagementSubject, PresentationSubject, SurfaceState, SurfaceTransition, SurfaceTransitionContext } from "./scenario-interaction.types";
4
+ type RuntimeOptions = ConstructorParameters<typeof ScenarioInteractionCollector>[2];
5
+ export declare class ScenarioInteractionRuntime {
6
+ readonly collector: ScenarioInteractionCollector;
7
+ private readonly surfaceController;
8
+ private readonly presented;
9
+ private readonly engaged;
10
+ constructor(getSession: () => CustomerInteractionSession, onSessionExpired: () => void, options?: RuntimeOptions);
11
+ start(): void;
12
+ destroy(): void;
13
+ updateSession(session: CustomerInteractionSession): void;
14
+ transitionSurface(nextState: SurfaceState, context: SurfaceTransitionContext): SurfaceTransition;
15
+ getSurfaceState(): SurfaceState;
16
+ getSurfaceEpisodeId(): string | null;
17
+ getPrincipalSessionId(): string;
18
+ recordPresented(subject: PresentationSubject, expectedEpisodeId?: string | null): boolean;
19
+ recordEngagement(subject: EngagementSubject): boolean;
20
+ recordTargetPresented(commandId: string, surfaceEpisodeId?: string | null): boolean;
21
+ recordTargetActivation(commandId: string, surfaceEpisodeId?: string | null): boolean;
22
+ observeHighlightedTarget(input: {
23
+ element: Element;
24
+ commandId: string;
25
+ }): () => void;
26
+ private markCurrentTargetContext;
27
+ }
28
+ export {};
@@ -0,0 +1,13 @@
1
+ import type { ScenarioInteractionDraft, SurfaceState, SurfaceTransition, SurfaceTransitionContext } from "./scenario-interaction.types";
2
+ export declare class SurfaceController {
3
+ private readonly observe;
4
+ private readonly createId;
5
+ private state;
6
+ private episode;
7
+ constructor(observe: (draft: ScenarioInteractionDraft) => void, createId?: () => string);
8
+ transition(nextState: SurfaceState, context: SurfaceTransitionContext): SurfaceTransition;
9
+ getState(): SurfaceState;
10
+ getEpisodeId(): string | null;
11
+ markScenarioContext(attributionHandle: string): void;
12
+ replacePrincipal(): void;
13
+ }
@@ -0,0 +1,12 @@
1
+ export declare const PRESENTATION_INTERSECTION_RATIO = 0.5;
2
+ export declare const PRESENTATION_DWELL_MS = 500;
3
+ type PresentationObserverInput = {
4
+ element: Element;
5
+ isActive: () => boolean;
6
+ isPresentable?: () => boolean;
7
+ onPresented: () => void;
8
+ intersectionRatio?: number;
9
+ dwellMs?: number;
10
+ };
11
+ export declare const observePresentedElement: ({ element, isActive, isPresentable, onPresented, intersectionRatio, dwellMs, }: PresentationObserverInput) => (() => void);
12
+ export {};
@@ -0,0 +1,7 @@
1
+ import type { ScenarioInteractionRuntime } from "./ScenarioInteractionRuntime";
2
+ export type ScenarioInteractionContextValue = {
3
+ open: boolean;
4
+ surfaceEpisodeId: string | null;
5
+ runtime: ScenarioInteractionRuntime;
6
+ };
7
+ export declare const ScenarioInteractionContext: import("react").Context<ScenarioInteractionContextValue | null>;
@@ -0,0 +1,84 @@
1
+ export declare const SCENARIO_INTERACTION_VERSION: 1;
2
+ export declare const SCENARIO_INTERACTION_KINDS: readonly ["SURFACE_STATE_CHANGED", "EXPERIENCE_PRESENTED", "EXPERIENCE_ENGAGED"];
3
+ export declare const SCENARIO_INTERACTION_TYPES: readonly ["CHAT_OPENED", "CHAT_CLOSED", "MESSAGE_PRESENTED", "CHOICE_PRESENTED", "CTA_PRESENTED", "CTA_CLICKED", "CTA_DISMISSED", "TARGET_PRESENTED", "TARGET_ACTIVATED"];
4
+ export declare const SCENARIO_INTERACTION_ACTORS: readonly ["USER", "SCENARIO", "HOST"];
5
+ export declare const SCENARIO_INTERACTION_SUBJECT_KINDS: readonly ["SURFACE", "MESSAGE", "CHOICE", "CTA", "TARGET"];
6
+ export declare const SCENARIO_INTERACTION_RESULTS: readonly ["SUCCEEDED", "FAILED"];
7
+ export declare const SCENARIO_INTERACTION_REASONS: readonly ["USER_LAUNCHER", "USER_CLOSE_BUTTON", "HOST_SET_OPEN", "SCENARIO_COMMAND", "UNKNOWN"];
8
+ export type ScenarioInteractionKind = (typeof SCENARIO_INTERACTION_KINDS)[number];
9
+ export type ScenarioInteractionType = (typeof SCENARIO_INTERACTION_TYPES)[number];
10
+ export type ScenarioInteractionActor = (typeof SCENARIO_INTERACTION_ACTORS)[number];
11
+ export type ScenarioInteractionSubjectKind = (typeof SCENARIO_INTERACTION_SUBJECT_KINDS)[number];
12
+ export type ScenarioInteractionResult = (typeof SCENARIO_INTERACTION_RESULTS)[number];
13
+ export type ScenarioInteractionReason = (typeof SCENARIO_INTERACTION_REASONS)[number];
14
+ export type ScenarioInteractionDetails = {
15
+ presentationOrdinal?: number;
16
+ };
17
+ export type ScenarioInteractionObservation = {
18
+ clientObservationId: string;
19
+ version: typeof SCENARIO_INTERACTION_VERSION;
20
+ kind: ScenarioInteractionKind;
21
+ type: ScenarioInteractionType;
22
+ actor: ScenarioInteractionActor;
23
+ occurredAt: string;
24
+ sequence: number;
25
+ surfaceEpisodeId?: string;
26
+ subjectKind?: ScenarioInteractionSubjectKind;
27
+ subjectId?: string;
28
+ result?: ScenarioInteractionResult;
29
+ reason?: ScenarioInteractionReason;
30
+ attributionHandle?: string;
31
+ details?: ScenarioInteractionDetails;
32
+ };
33
+ export type ScenarioInteractionDraft = Omit<ScenarioInteractionObservation, "clientObservationId" | "version" | "occurredAt" | "sequence">;
34
+ export type ScenarioInteractionCapabilities = {
35
+ version: number;
36
+ maxBatchItems: number;
37
+ maxRequestBytes: number;
38
+ sessionHourlyLimit: number;
39
+ retentionDays: number;
40
+ kinds: readonly ScenarioInteractionKind[];
41
+ types: readonly ScenarioInteractionType[];
42
+ actors: readonly ScenarioInteractionActor[];
43
+ attributionHandleSupported: boolean;
44
+ };
45
+ export type ScenarioInteractionReceipt = {
46
+ clientObservationId: string;
47
+ status: "ACCEPTED" | "DUPLICATE" | "IGNORED_NO_INTEREST" | "REJECTED";
48
+ code?: string | null;
49
+ observationId?: string | null;
50
+ runId?: string | null;
51
+ };
52
+ export type ScenarioInteractionBatchResponse = {
53
+ receipts: ScenarioInteractionReceipt[];
54
+ };
55
+ export type SurfaceState = "OPEN" | "CLOSED";
56
+ export type SurfaceTransitionActor = ScenarioInteractionActor | "SYSTEM";
57
+ /** Exact SDK-local reasons; state-changing reasons are preserved on the wire. */
58
+ export type SurfaceTransitionReason = "USER_LAUNCHER" | "USER_CLOSE_BUTTON" | "VOICE_SWITCH_TO_TEXT" | "HOST_SET_OPEN" | "SCENARIO_COMMAND" | "SYSTEM_RESTORE";
59
+ export type SurfaceTransitionContext = {
60
+ actor: SurfaceTransitionActor;
61
+ reason: SurfaceTransitionReason;
62
+ sourceCommandId?: string;
63
+ };
64
+ export type SurfaceTransition = {
65
+ changed: boolean;
66
+ from: SurfaceState;
67
+ to: SurfaceState;
68
+ episodeId: string | null;
69
+ context: SurfaceTransitionContext;
70
+ };
71
+ export type PresentationSubject = {
72
+ subjectKind: Extract<ScenarioInteractionSubjectKind, "MESSAGE" | "CHOICE" | "CTA" | "TARGET">;
73
+ subjectId: string;
74
+ actor?: ScenarioInteractionActor;
75
+ attributionHandle?: string;
76
+ presentationOrdinal?: number;
77
+ };
78
+ export type EngagementSubject = {
79
+ type: Extract<ScenarioInteractionType, "CTA_CLICKED" | "CTA_DISMISSED" | "TARGET_ACTIVATED">;
80
+ subjectKind: Extract<ScenarioInteractionSubjectKind, "CTA" | "TARGET">;
81
+ subjectId: string;
82
+ attributionHandle?: string;
83
+ result?: ScenarioInteractionResult;
84
+ };
@@ -0,0 +1,4 @@
1
+ import { type RefObject } from "react";
2
+ import type { PresentationSubject } from "./scenario-interaction.types";
3
+ import type { ScenarioInteractionRuntime } from "./ScenarioInteractionRuntime";
4
+ export declare const useScenarioPresentation: (runtime: ScenarioInteractionRuntime | undefined, ref: RefObject<Element | null>, active: boolean, episodeId: string | null, subject: PresentationSubject | null, isPresentable?: () => boolean) => void;