@alxxsck/ai-assistant 2.20.0 → 2.22.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,6 +1,6 @@
1
1
  import type { AppApi } from "@/App";
2
2
  import type { WidgetConfig } from "@/index.types";
3
- import { type ConversationData, type MessageData, type RawMessageData, type SendMessageResult } from "./messages.api.types";
3
+ import { type ConversationData, type MessageData, type RawConversationData, type RawMessageData, type SendMessageResult } from "./messages.api.types";
4
4
  import type { ChatAttachment } from "@/domain/message/chat-experience";
5
5
  export declare const MAX_FETCH_MESSAGES = 100;
6
6
  export type CursorPage<T> = {
@@ -10,7 +10,6 @@ export type CursorPage<T> = {
10
10
  type VersionedCursorPage<T> = CursorPage<T> & {
11
11
  contractVersion?: unknown;
12
12
  };
13
- type ConversationsResponse = VersionedCursorPage<ConversationData>;
14
13
  export declare class ChatApiError extends Error {
15
14
  readonly status: number;
16
15
  constructor(status: number, message: string);
@@ -20,12 +19,19 @@ export declare class ChatContractError extends Error {
20
19
  }
21
20
  export declare const isConversationClosedError: (error: unknown) => boolean;
22
21
  export declare const requestChatJson: <T>(config: WidgetConfig, api: AppApi, path: string, init?: RequestInit) => Promise<T>;
23
- export declare const normalizeConversation: (conversation: ConversationData) => ConversationData;
22
+ export declare const normalizeConversation: (conversation: RawConversationData) => ConversationData;
24
23
  export declare const normalizeMessage: (message: RawMessageData, config: WidgetConfig) => MessageData;
24
+ export declare const normalizeMessageAuthorPresentation: (role: RawMessageData["role"], author: unknown) => Readonly<{
25
+ contractState: "VERSIONED" | "LEGACY";
26
+ displayName: string;
27
+ avatarAsset: import("@/domain/support-presentation/support-presentation.types").PresentationAvatarAsset | null;
28
+ presentationVersion: number | null;
29
+ legacyAvatarUrl: string | null;
30
+ }> | null;
25
31
  export declare const normalizeMessageForSession: (message: RawMessageData, interactionSessionId: string) => MessageData;
26
- export declare const listConversations: (config: WidgetConfig, api: AppApi, cursor?: string, signal?: AbortSignal) => Promise<ConversationsResponse>;
32
+ export declare const listConversations: (config: WidgetConfig, api: AppApi, cursor?: string, signal?: AbortSignal) => Promise<VersionedCursorPage<ConversationData>>;
27
33
  export declare const listConversationMessages: (config: WidgetConfig, api: AppApi, conversationId: string, cursor?: string, signal?: AbortSignal) => Promise<CursorPage<MessageData>>;
28
- export declare const createConversation: (config: WidgetConfig, api: AppApi) => Promise<ConversationData>;
34
+ export declare const createConversation: (config: WidgetConfig, api: AppApi, signal?: AbortSignal) => Promise<ConversationData>;
29
35
  export declare const selectConversation: (config: WidgetConfig, api: AppApi, conversationId: string, signal?: AbortSignal) => Promise<ConversationData>;
30
36
  export declare const getConversation: (config: WidgetConfig, api: AppApi, conversationId: string, signal?: AbortSignal) => Promise<ConversationData>;
31
37
  export declare function sendMessage(config: WidgetConfig, api: AppApi, messageText: string, conversationId?: string, clientMessageId?: `${string}-${string}-${string}-${string}-${string}`, attachments?: readonly ChatAttachment[]): Promise<SendMessageResult>;
@@ -103,6 +103,10 @@ export type ConversationData = {
103
103
  aiSuspension?: ConversationAISuspension;
104
104
  responderPresentation?: import("@/domain/support-presentation/support-presentation.types").SafeResponderPresentation;
105
105
  };
106
+ /** Untrusted transport shape before responder contract normalization. */
107
+ export type RawConversationData = Omit<ConversationData, "responderPresentation"> & {
108
+ responderPresentation?: unknown;
109
+ };
106
110
  export type MessageRole = "USER" | "ASSISTANT" | "ADMIN" | "SCENARIO" | "SYSTEM";
107
111
  export type RawMessageData = {
108
112
  id: string;
@@ -1,4 +1,4 @@
1
- import { a2 as A, a3 as e, a5 as s, H as n, a4 as r } from "./index-BVQY-1rm.js";
1
+ import { a1 as A, a2 as e, a4 as s, F as n, a3 as r } from "./index-C4NZpmiX.js";
2
2
  export {
3
3
  A as ChatWidgetInstance,
4
4
  e as EXTERNALLY_AVAILABLE_ACTIONS,
@@ -3,7 +3,7 @@ import type { CommandAck } from "@/domain/command/command.types";
3
3
  import type { CommandRuntime } from "@/domain/command/CommandRuntime";
4
4
  import type { MessageStoreActions } from "@/domain/message/message.store";
5
5
  type WidgetFrameDependencies = {
6
- messageActions: Pick<MessageStoreActions, "handleConversationCreated" | "handleScenarioChoiceLifecycleChanged" | "handleScenarioChoiceSubmissionResult" | "handleMessageDelta" | "handleMessagesAgenticSteps" | "handleMessage" | "handleChatTyping" | "handleSupportPresence" | "handleResponderPresentationChanged">;
6
+ messageActions: Pick<MessageStoreActions, "handleConversationCreated" | "handleScenarioChoiceLifecycleChanged" | "handleScenarioChoiceSubmissionResult" | "handleMessageDelta" | "handleMessagesAgenticSteps" | "handleMessage" | "handleChatTyping" | "handleResponderPresentationChanged">;
7
7
  commandRuntime: CommandRuntime;
8
8
  session: CustomerInteractionSession;
9
9
  sendAck: (ack: CommandAck) => Promise<unknown>;
@@ -20,14 +20,6 @@ export type ChatTypingState = {
20
20
  conversationId: string;
21
21
  actor: "ASSISTANT" | "ADMIN";
22
22
  active: boolean;
23
- displayName?: string;
24
- avatarUrl?: string | null;
25
- };
26
- export type SupportPresenceState = {
27
- conversationId: string;
28
- live: boolean;
29
- displayName?: string;
30
- avatarUrl?: string | null;
31
23
  };
32
24
  /**
33
25
  * Opt-in future frame fields. Unknown frames are ignored so the SDK remains
@@ -35,7 +27,6 @@ export type SupportPresenceState = {
35
27
  */
36
28
  export declare const normalizeChatExperienceFrame: (frame: unknown) => {
37
29
  typing: ChatTypingState | null;
38
- presence: SupportPresenceState | null;
39
30
  };
40
31
  /**
41
32
  * A deterministic transport for visual QA and integration tests. Production
@@ -2,7 +2,7 @@ import { type AgenticStepsAppendedData, type ChatMessageDeltaData, type Conversa
2
2
  import type { AppApi } from "@/App";
3
3
  import type { WidgetConfig } from "@/index.types";
4
4
  import { type MessageStreamState } from "./message-stream";
5
- import type { ChatAttachment, ChatTypingState, SupportPresenceState } from "./chat-experience";
5
+ import type { ChatAttachment, ChatTypingState } from "./chat-experience";
6
6
  import type { ResponderPresentationChanged, ScenarioConversationCreated } from "./cable/widget-message";
7
7
  import { type ScenarioChoiceLifecycleChanged, type ScenarioChoiceSubmissionResult } from "@/domain/scenario/scenario-choice";
8
8
  export interface ThreadSummary {
@@ -21,6 +21,7 @@ export type PendingCustomerMessage = {
21
21
  conversationId: string | undefined;
22
22
  afterMessageId: string | null;
23
23
  acknowledged: boolean;
24
+ acceptanceConfirmed?: boolean;
24
25
  canonicalMessageId: string | null;
25
26
  attachments: ChatAttachment[];
26
27
  readByAssistant: boolean;
@@ -54,7 +55,14 @@ export type MessageStore = {
54
55
  responsePhase: AgentResponsePhase;
55
56
  sendInFlight: boolean;
56
57
  typingByConversation: Map<string, ChatTypingState>;
57
- supportPresenceByConversation: Map<string, SupportPresenceState>;
58
+ concealedConversationIds: Set<string>;
59
+ concealedMessageIds: Set<string>;
60
+ inactiveConversationIds: Set<string>;
61
+ inactiveConversationUpdatedAt: Map<string, string | null>;
62
+ inactiveConversationRevalidation: Map<string, "ANY_OPEN" | "NEWER_OPEN" | "EXACT_ONLY">;
63
+ conversationScanCandidateIds: Set<string>;
64
+ conversationScanAuthorityVersion: number | null;
65
+ conversationScanSnapshots: Map<string, ConversationData>;
58
66
  assistantSuspendedConversationIds: Set<string>;
59
67
  actions: MessageStoreActions;
60
68
  };
@@ -68,6 +76,7 @@ export type MessageStoreActions = {
68
76
  handleScenarioChoiceSubmissionResult: (result: ScenarioChoiceSubmissionResult) => void;
69
77
  handleMessage: (message: MessageData) => void;
70
78
  handleResponderPresentationChanged: (hint: ResponderPresentationChanged) => void;
79
+ refreshResponderPresentation: (conversationId: string, minimumRevision?: string, retryAfterTransportFailure?: boolean) => void;
71
80
  handleMessageDelta: (delta: ChatMessageDeltaData) => void;
72
81
  settleMessageStream: (messageId: string) => void;
73
82
  sendMessage: (message: string, attachments?: ChatAttachment[]) => Promise<SendMessageResult | undefined>;
@@ -83,11 +92,10 @@ export type MessageStoreActions = {
83
92
  cancelThreadMessagesRequest: (conversationId: string) => void;
84
93
  cancelConversationPagination: () => void;
85
94
  setCurrentThreadMessages: (conversationId: string) => void;
86
- sendServiceMessage: (message: string) => Promise<void>;
87
95
  handleChatTyping: (typing: ChatTypingState) => void;
88
- handleSupportPresence: (presence: SupportPresenceState) => void;
96
+ clearTransientRealtimeState: () => void;
89
97
  updateConfig: (config: WidgetConfig, api: AppApi) => void;
90
- recoverMessages: (preserveLoadedConversations?: boolean) => Promise<void>;
98
+ recoverMessages: (preserveLoadedConversations?: boolean, preserveCurrentThread?: boolean) => Promise<void>;
91
99
  fetchMoreConversations: () => Promise<void>;
92
100
  };
93
101
  export declare const useMessageStore: import("zustand").UseBoundStore<import("zustand").StoreApi<MessageStore>>;
@@ -99,8 +107,9 @@ export declare const useIsLoadingMoreConversations: () => boolean;
99
107
  export declare const useCurrentThreadId: () => string | undefined;
100
108
  export declare const useCurrentResponderPresentation: () => Readonly<{
101
109
  contractState: "CURRENT" | "LEGACY" | "INCOMPATIBLE";
102
- schemaVersion: 0 | 1;
103
- mode: import("@/domain/support-presentation/support-presentation.types").ResponderMode | "UNKNOWN";
110
+ schemaVersion: 0 | 2;
111
+ humanSupport: import("@/domain/support-presentation/support-presentation.types").ResponderHumanSupportState | "UNKNOWN";
112
+ ai: import("@/domain/support-presentation/support-presentation.types").ResponderAIState | "UNKNOWN";
104
113
  identity: import("@/domain/support-presentation/support-presentation.types").ResponderIdentity;
105
114
  displayName: string | null;
106
115
  avatarAsset: import("@/domain/support-presentation/support-presentation.types").PresentationAvatarAsset | null;
@@ -124,8 +133,8 @@ export declare const useIsResponseActive: () => boolean;
124
133
  export declare const selectCurrentThreadPendingCustomerMessage: (state: MessageStore) => PendingCustomerMessage | null;
125
134
  export declare const usePendingCustomerMessage: () => PendingCustomerMessage | null;
126
135
  export declare const useMessageStream: (messageId: string) => MessageStreamState | undefined;
127
- export declare const useCurrentChatTyping: () => ChatTypingState | null;
128
- export declare const useCurrentSupportPresence: () => SupportPresenceState | null;
136
+ export declare const selectCurrentChatTypingByActor: (state: MessageStore, actor: ChatTypingState["actor"]) => ChatTypingState | null;
137
+ export declare const useCurrentChatTypingByActor: (actor: ChatTypingState["actor"]) => ChatTypingState | null;
129
138
  export declare const selectIsCurrentConversationAISuspended: (state: MessageStore) => boolean;
130
139
  export declare const useCurrentConversationAISuspended: () => boolean;
131
140
  export declare const useMessageStoreActions: () => MessageStoreActions;
@@ -34,11 +34,13 @@ export declare class PresentationAvatarResolver {
34
34
  private readonly queue;
35
35
  private readonly authorityListeners;
36
36
  private readonly conversationEpochs;
37
+ private readonly activeKeys;
37
38
  private activeCount;
38
39
  private generation;
39
40
  constructor(config: WidgetConfig, api: AppApi, options?: ResolverOptions);
40
41
  resolve(request: PresentationAvatarRequest): Promise<ResolvedPresentationAvatar | null>;
41
42
  private drainQueue;
43
+ private releaseActiveSlot;
42
44
  private trimCache;
43
45
  private loadGrant;
44
46
  replaceSession(config: WidgetConfig, api: AppApi): void;
@@ -0,0 +1,13 @@
1
+ import { type SafeResponderPresentation } from "./support-presentation.types";
2
+ export type ResponderReconciliationOutcome = "APPLIED" | "REPLAY" | "STALE" | "HINT_AHEAD" | "INCOMPATIBLE";
3
+ export type ResponderReconciliation = Readonly<{
4
+ presentation: SafeResponderPresentation;
5
+ outcome: ResponderReconciliationOutcome;
6
+ }>;
7
+ export declare const compareResponderRevisions: (left: string, right: string) => number;
8
+ /**
9
+ * The one merge rule for REST snapshots and revision-only realtime hints.
10
+ * The backend owns the compound revision; consumers never compare or advance
11
+ * individual source revisions themselves.
12
+ */
13
+ export declare function reconcileResponderPresentation(current: SafeResponderPresentation | undefined, incoming: SafeResponderPresentation, minimumRevision?: string): ResponderReconciliation;
@@ -3,18 +3,24 @@ export type PresentationAvatarAsset = Readonly<{
3
3
  version: number;
4
4
  }>;
5
5
  export type MessageAuthorPresentation = Readonly<{
6
+ /** Internal provenance marker; never serialized back to the backend. */
7
+ contractState: "VERSIONED" | "LEGACY";
6
8
  displayName: string;
7
9
  avatarAsset: PresentationAvatarAsset | null;
8
10
  presentationVersion: number | null;
9
11
  legacyAvatarUrl: string | null;
10
12
  }>;
11
- export declare const RESPONDER_MODES: readonly ["LOLA", "SUPPORT_REQUESTED", "SUPPORT_LIVE", "SUPPORT_AWAY", "LOLA_SUSPENDED"];
12
- export type ResponderMode = (typeof RESPONDER_MODES)[number];
13
+ export declare const RESPONDER_HUMAN_SUPPORT_STATES: readonly ["NONE", "ROUTING", "ASSIGNED"];
14
+ export declare const RESPONDER_AI_STATES: readonly ["ACTIVE", "SUSPENDED"];
15
+ export type ResponderHumanSupportState = (typeof RESPONDER_HUMAN_SUPPORT_STATES)[number];
16
+ export type ResponderAIState = (typeof RESPONDER_AI_STATES)[number];
13
17
  export type ResponderIdentity = "LOLA" | "SUPPORT";
14
18
  export type ResponderSourceRevisions = Readonly<{
15
19
  conversationUpdatedAt: string;
16
20
  escalationVersionSum: string;
17
21
  escalationUpdatedAt: string | null;
22
+ assignmentVersionSum: string;
23
+ assignmentUpdatedAt: string | null;
18
24
  aiSuspensionVersion: string | null;
19
25
  aiSuspensionUpdatedAt: string | null;
20
26
  lolaPresentationVersion: number | null;
@@ -22,8 +28,9 @@ export type ResponderSourceRevisions = Readonly<{
22
28
  avatarAssetUpdatedAt: string | null;
23
29
  }>;
24
30
  export type ResponderPresentation = Readonly<{
25
- schemaVersion: 1;
26
- mode: ResponderMode;
31
+ schemaVersion: 2;
32
+ humanSupport: ResponderHumanSupportState;
33
+ ai: ResponderAIState;
27
34
  identity: ResponderIdentity;
28
35
  displayName: string;
29
36
  avatarAsset: PresentationAvatarAsset | null;
@@ -35,8 +42,9 @@ export type ResponderPresentation = Readonly<{
35
42
  }>;
36
43
  export type SafeResponderPresentation = Readonly<{
37
44
  contractState: "CURRENT" | "LEGACY" | "INCOMPATIBLE";
38
- schemaVersion: 0 | 1;
39
- mode: ResponderMode | "UNKNOWN";
45
+ schemaVersion: 0 | 2;
46
+ humanSupport: ResponderHumanSupportState | "UNKNOWN";
47
+ ai: ResponderAIState | "UNKNOWN";
40
48
  identity: ResponderIdentity;
41
49
  displayName: string | null;
42
50
  avatarAsset: PresentationAvatarAsset | null;
@@ -48,6 +56,7 @@ export type SafeResponderPresentation = Readonly<{
48
56
  }>;
49
57
  export declare const LEGACY_RESPONDER_PRESENTATION: SafeResponderPresentation;
50
58
  export declare const INCOMPATIBLE_RESPONDER_PRESENTATION: SafeResponderPresentation;
59
+ export declare const isCanonicalResponderRevision: (value: unknown) => value is string;
51
60
  export declare function parseMessageAuthorPresentation(value: unknown): MessageAuthorPresentation | null;
52
61
  export declare function parseResponderPresentation(value: unknown): ResponderPresentation | null;
53
62
  export declare function normalizeResponderPresentation(value: unknown): SafeResponderPresentation;
@@ -27,7 +27,6 @@ declare const en: {
27
27
  readonly system: "System";
28
28
  readonly aiAssistant: "AI assistant";
29
29
  readonly waiting: "Waiting for a specialist";
30
- readonly live: "Specialist is here";
31
30
  readonly away: "We’ll reply here";
32
31
  readonly paused: "AI is paused";
33
32
  readonly unavailable: "Support status unavailable";