open-chat-studio-widget 0.7.0 → 0.9.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.
Files changed (35) hide show
  1. package/README.md +28 -26
  2. package/dist/cjs/{index-CvB341El.js → index-DDod9Zyw.js} +3 -3
  3. package/dist/cjs/{index-CvB341El.js.map → index-DDod9Zyw.js.map} +1 -1
  4. package/dist/cjs/loader.cjs.js +2 -2
  5. package/dist/cjs/open-chat-studio-widget.cjs.entry.js +282 -49
  6. package/dist/cjs/open-chat-studio-widget.cjs.entry.js.map +1 -1
  7. package/dist/cjs/open-chat-studio-widget.cjs.js +2 -2
  8. package/dist/cjs/open-chat-studio-widget.entry.cjs.js.map +1 -1
  9. package/dist/collection/components/ocs-chat/ocs-chat.js +176 -29
  10. package/dist/collection/components/ocs-chat/ocs-chat.js.map +1 -1
  11. package/dist/collection/services/chat-session-service.js +112 -8
  12. package/dist/collection/services/chat-session-service.js.map +1 -1
  13. package/dist/collection/services/file-attachment-manager.js +6 -0
  14. package/dist/collection/services/file-attachment-manager.js.map +1 -1
  15. package/dist/components/open-chat-studio-widget.js +284 -49
  16. package/dist/components/open-chat-studio-widget.js.map +1 -1
  17. package/dist/esm/{index-C2QZK0Ui.js → index-iUBQH9om.js} +3 -3
  18. package/dist/esm/{index-C2QZK0Ui.js.map → index-iUBQH9om.js.map} +1 -1
  19. package/dist/esm/loader.js +3 -3
  20. package/dist/esm/open-chat-studio-widget.entry.js +282 -49
  21. package/dist/esm/open-chat-studio-widget.entry.js.map +1 -1
  22. package/dist/esm/open-chat-studio-widget.js +3 -3
  23. package/dist/open-chat-studio-widget/open-chat-studio-widget.entry.esm.js.map +1 -1
  24. package/dist/open-chat-studio-widget/open-chat-studio-widget.esm.js +1 -1
  25. package/dist/open-chat-studio-widget/p-9c925476.entry.js +4 -0
  26. package/dist/open-chat-studio-widget/p-9c925476.entry.js.map +1 -0
  27. package/dist/open-chat-studio-widget/{p-C2QZK0Ui.js → p-iUBQH9om.js} +2 -2
  28. package/dist/open-chat-studio-widget/{p-C2QZK0Ui.js.map → p-iUBQH9om.js.map} +1 -1
  29. package/dist/types/components/ocs-chat/ocs-chat.d.ts +29 -1
  30. package/dist/types/components.d.ts +18 -2
  31. package/dist/types/services/chat-session-service.d.ts +27 -0
  32. package/dist/types/services/file-attachment-manager.d.ts +2 -0
  33. package/package.json +1 -1
  34. package/dist/open-chat-studio-widget/p-e87d4e31.entry.js +0 -4
  35. package/dist/open-chat-studio-widget/p-e87d4e31.entry.js.map +0 -1
@@ -83,6 +83,7 @@ export declare class OcsChat {
83
83
  userName?: string;
84
84
  /**
85
85
  * Whether to persist session data to local storage to allow resuming previous conversations after page reload.
86
+ * Ignored when `sessionId` is provided.
86
87
  */
87
88
  persistentSession: boolean;
88
89
  /**
@@ -117,9 +118,22 @@ export declare class OcsChat {
117
118
  * This is for internal use only and is not intended for public-facing widgets.
118
119
  */
119
120
  versionNumber?: number;
121
+ /**
122
+ * The ID of an existing chat session to connect to. When provided, the widget
123
+ * is bound to that session: local session persistence is disabled and the
124
+ * message history is loaded from the server. Intended for host pages that
125
+ * create the session server-side (e.g. the OCS web chat page).
126
+ */
127
+ sessionId?: string;
128
+ /**
129
+ * A session token proving access to the session named by `session-id`. Host
130
+ * pages that create the session server-side pass a server-minted token here so
131
+ * the widget can authenticate its requests. Only meaningful with `session-id`.
132
+ */
133
+ sessionToken?: string;
120
134
  error: string;
121
135
  messages: ChatMessage[];
122
- sessionId?: string;
136
+ activeSessionId?: string;
123
137
  isLoading: boolean;
124
138
  isTyping: boolean;
125
139
  typingProgressMessage: string;
@@ -168,12 +182,20 @@ export declare class OcsChat {
168
182
  private positionInitialized;
169
183
  private internalPageContext?;
170
184
  private sessionEpoch;
185
+ private currentSessionToken?;
171
186
  host: HTMLElement;
172
187
  componentWillLoad(): Promise<void>;
173
188
  componentDidLoad(): void;
174
189
  disconnectedCallback(): void;
190
+ private applySessionToken;
175
191
  private getChatService;
176
192
  private addErrorMessage;
193
+ /**
194
+ * Recover from a rejected session token (403). Unbound widgets discard the
195
+ * dead session/token, show a notice, and start fresh on the next send; bound
196
+ * widgets cannot restart a host-owned session, so they surface an error.
197
+ */
198
+ private handleSessionAccessError;
177
199
  private handleError;
178
200
  private parseJSONProp;
179
201
  private parseWelcomeMessages;
@@ -183,6 +205,11 @@ export declare class OcsChat {
183
205
  private loadTranslationsFromUrl;
184
206
  private cleanup;
185
207
  private startSession;
208
+ /**
209
+ * Load the full message history for a session provided via the `session-id`
210
+ * prop, then begin regular polling.
211
+ */
212
+ private loadBoundSessionHistory;
186
213
  private uploadFiles;
187
214
  private sendMessage;
188
215
  private handleStarterQuestionClick;
@@ -274,6 +301,7 @@ export declare class OcsChat {
274
301
  private restoreVisibleState;
275
302
  private clearSessionStorage;
276
303
  private isKioskMode;
304
+ private isSessionBound;
277
305
  private isLocalStorageAvailable;
278
306
  private showConfirmationDialog;
279
307
  private hideConfirmationDialog;
@@ -65,7 +65,7 @@ export namespace Components {
65
65
  */
66
66
  "pageContext"?: Record<string, any>;
67
67
  /**
68
- * Whether to persist session data to local storage to allow resuming previous conversations after page reload.
68
+ * Whether to persist session data to local storage to allow resuming previous conversations after page reload. Ignored when `sessionId` is provided.
69
69
  * @default true
70
70
  */
71
71
  "persistentSession": boolean;
@@ -79,6 +79,14 @@ export namespace Components {
79
79
  * @default 'right'
80
80
  */
81
81
  "position": 'left' | 'center' | 'right';
82
+ /**
83
+ * The ID of an existing chat session to connect to. When provided, the widget is bound to that session: local session persistence is disabled and the message history is loaded from the server. Intended for host pages that create the session server-side (e.g. the OCS web chat page).
84
+ */
85
+ "sessionId"?: string;
86
+ /**
87
+ * A session token proving access to the session named by `session-id`. Host pages that create the session server-side pass a server-minted token here so the widget can authenticate its requests. Only meaningful with `session-id`.
88
+ */
89
+ "sessionToken"?: string;
82
90
  /**
83
91
  * Whether to show the launcher button. Set to false to hide the button and open the chat window programmatically via the `visible` property.
84
92
  * @default true
@@ -184,7 +192,7 @@ declare namespace LocalJSX {
184
192
  */
185
193
  "pageContext"?: Record<string, any>;
186
194
  /**
187
- * Whether to persist session data to local storage to allow resuming previous conversations after page reload.
195
+ * Whether to persist session data to local storage to allow resuming previous conversations after page reload. Ignored when `sessionId` is provided.
188
196
  * @default true
189
197
  */
190
198
  "persistentSession"?: boolean;
@@ -198,6 +206,14 @@ declare namespace LocalJSX {
198
206
  * @default 'right'
199
207
  */
200
208
  "position"?: 'left' | 'center' | 'right';
209
+ /**
210
+ * The ID of an existing chat session to connect to. When provided, the widget is bound to that session: local session persistence is disabled and the message history is loaded from the server. Intended for host pages that create the session server-side (e.g. the OCS web chat page).
211
+ */
212
+ "sessionId"?: string;
213
+ /**
214
+ * A session token proving access to the session named by `session-id`. Host pages that create the session server-side pass a server-minted token here so the widget can authenticate its requests. Only meaningful with `session-id`.
215
+ */
216
+ "sessionToken"?: string;
201
217
  /**
202
218
  * Whether to show the launcher button. Set to false to hide the button and open the chat window programmatically via the `visible` property.
203
219
  * @default true
@@ -1,3 +1,8 @@
1
+ export declare class SessionAccessError extends Error {
2
+ readonly status: number;
3
+ readonly code?: string;
4
+ constructor(status: number, code: string | undefined, message: string);
5
+ }
1
6
  export type ChatRole = 'system' | 'user' | 'assistant';
2
7
  export interface ChatAttachment {
3
8
  name: string;
@@ -13,6 +18,7 @@ export interface ChatMessage {
13
18
  }
14
19
  export interface ChatStartSessionResponse {
15
20
  session_id: string;
21
+ session_token?: string | null;
16
22
  chatbot: unknown;
17
23
  participant: unknown;
18
24
  }
@@ -35,6 +41,7 @@ export interface ChatSessionServiceOptions {
35
41
  apiBaseUrl: string;
36
42
  embedKey?: string;
37
43
  widgetVersion: string;
44
+ sessionToken?: string;
38
45
  csrfTokenProvider?: (apiBaseUrl: string) => string | undefined;
39
46
  taskPollingIntervalMs?: number;
40
47
  taskPollingMaxAttempts?: number;
@@ -61,19 +68,39 @@ export declare class ChatSessionService {
61
68
  private readonly apiBaseUrl;
62
69
  private readonly embedKey?;
63
70
  private readonly widgetVersion;
71
+ private sessionToken?;
64
72
  private readonly csrfTokenProvider;
65
73
  private readonly taskPollingIntervalMs;
66
74
  private readonly taskPollingMaxAttempts;
67
75
  private readonly messagePollingIntervalMs;
68
76
  private messagePollingTimer?;
77
+ private loggedSunsetLevel?;
78
+ private static readonly MAX_HISTORY_PAGES;
69
79
  constructor(options: ChatSessionServiceOptions);
70
80
  startSession(requestBody: Record<string, unknown>): Promise<ChatStartSessionResponse>;
71
81
  sendMessage(sessionId: string, payload: Record<string, unknown>): Promise<ChatSendMessageResponse>;
72
82
  pollTaskOnce(sessionId: string, taskId: string): Promise<ChatTaskPollResponse>;
73
83
  pollTask(sessionId: string, taskId: string, callbacks: TaskPollingCallbacks): TaskPollingHandle;
74
84
  fetchMessages(sessionId: string, since?: string): Promise<ChatPollResponse>;
85
+ /**
86
+ * Fetch the complete message history for a session by paging through the
87
+ * poll endpoint until no more messages remain.
88
+ */
89
+ fetchAllMessages(sessionId: string): Promise<ChatMessage[]>;
75
90
  startMessagePolling(sessionId: string, callbacks: MessagePollingCallbacks): MessagePollingHandle;
76
91
  stopMessagePolling(): void;
92
+ setSessionToken(token?: string): void;
93
+ private request;
94
+ /**
95
+ * Log a deprecation warning (RFC 8594 `Deprecation`/`Sunset`/`Link` headers)
96
+ * when the server reports that this widget version is deprecated. Warns
97
+ * during the deprecation window and errors once the sunset date has passed.
98
+ * Logs at most once per level so polling does not flood the console.
99
+ */
100
+ private checkSunsetHeaders;
101
+ private parseSunsetDate;
102
+ private parseSuccessorUrl;
103
+ private raiseForStatus;
77
104
  private getJsonHeaders;
78
105
  private getCommonHeaders;
79
106
  }
@@ -19,11 +19,13 @@ export interface UploadContext {
19
19
  sessionId: string;
20
20
  participantId: string;
21
21
  participantName?: string;
22
+ sessionToken?: string;
22
23
  }
23
24
  export interface UploadResult {
24
25
  selectedFiles: SelectedFile[];
25
26
  uploadedIds: number[];
26
27
  errorMessage?: string;
28
+ tokenRejected?: boolean;
27
29
  }
28
30
  export declare class FileAttachmentManager {
29
31
  private readonly supportedExtensions;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "open-chat-studio-widget",
3
- "version": "0.7.0",
3
+ "version": "0.9.0",
4
4
  "description": "Chat component for Open Chat Studio",
5
5
  "main": "dist/index.cjs.js",
6
6
  "exports": "./dist/esm/open-chat-studio-widget.js",