@sksharma72000/ai-chat-websdk 1.0.4 → 1.2.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.
@@ -9,6 +9,8 @@ interface UseChatModeProps {
9
9
  setIsPerformingClientAction: (v: boolean) => void;
10
10
  /** Async callback invoked on 401 — must return a fresh JWT string */
11
11
  onTokenExpired?: () => Promise<string>;
12
+ /** Called before sending the request body to the API. May modify and return the body. */
13
+ onBeforeMessageSend?: (body: any) => Promise<any> | any;
12
14
  /** Called after a successful token refresh so the parent can persist the new token */
13
15
  onTokenRefreshed?: (newToken: string) => void;
14
16
  }
@@ -18,5 +20,5 @@ interface UseChatModeReturn {
18
20
  optionIndex?: number;
19
21
  }) => Promise<AIResponseData>;
20
22
  }
21
- export declare function useChatMode({ apiUrl, jwtToken, sessionId, browserSession, setIsPerformingClientAction: _setIsPerformingClientAction, onTokenExpired, onTokenRefreshed, }: UseChatModeProps): UseChatModeReturn;
23
+ export declare function useChatMode({ apiUrl, jwtToken, sessionId, browserSession, setIsPerformingClientAction: _setIsPerformingClientAction, onTokenExpired, onBeforeMessageSend, onTokenRefreshed, }: UseChatModeProps): UseChatModeReturn;
22
24
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sksharma72000/ai-chat-websdk",
3
- "version": "1.0.4",
3
+ "version": "1.2.0",
4
4
  "description": "@sksharma72000/ai-chat-websdk is an embeddable, fully themeable AI chat widget for web apps. Supports JWT authentication with auto-refresh, rich content rendering (tables, code blocks, markdown), theming via CSS custom properties, and framework-agnostic mounting.",
5
5
  "main": "./ai-chat-websdk.umd.js",
6
6
  "module": "./ai-chat-websdk.es.js",
package/types/config.d.ts CHANGED
@@ -22,6 +22,13 @@ export interface SDKTheme {
22
22
  export interface SDKConfig {
23
23
  /** Base URL of the AI server, e.g. 'http://localhost:4001' */
24
24
  apiUrl: string;
25
+ /**
26
+ * Caller-supplied session identifier. When `initialize()` is called again
27
+ * with a different `chatID` the SDK creates a new `ai_sdk_correlation_id`
28
+ * so the conversation starts fresh. Repeated calls with the same `chatID`
29
+ * are no-ops (the existing session is preserved).
30
+ */
31
+ chatID?: string;
25
32
  /**
26
33
  * JWT token (full Authorization header value, e.g. 'Bearer eyJ…').
27
34
  * Sent as `Authorization` header on every API request.
@@ -60,6 +67,15 @@ export interface SDKConfig {
60
67
  * }
61
68
  */
62
69
  onTokenExpired?: () => Promise<string>;
70
+ /**
71
+ * Called immediately before the SDK sends the request body to the API.
72
+ * Receives the JS object that will be JSON-stringified. May modify and
73
+ * return the object (or a replacement). May be async.
74
+ *
75
+ * Example:
76
+ * onBeforeMessageSend: async (body) => { body.meta = { source: 'widget' }; return body }
77
+ */
78
+ onBeforeMessageSend?: (body: any) => Promise<any> | any;
63
79
  /**
64
80
  * When true the widget renders in embedded/panel mode:
65
81
  * - Chat opens immediately (no FAB step)
@@ -9,12 +9,15 @@ export declare class CorrelationIdManager {
9
9
  private static readonly SESSIONS_KEY;
10
10
  /** Key for the permanent browser-level identifier (never changes, survives session resets). */
11
11
  private static readonly BROWSER_SESSION_KEY;
12
+ private static readonly CHAT_ID_KEY;
12
13
  /**
13
14
  * Returns the permanent browser session token.
14
15
  * Created once and stored in localStorage forever — sent as the `browser-session` header
15
16
  * on every API request so the backend can group all chat sessions for this browser.
16
17
  */
17
18
  static getBrowserSession(): string;
19
+ static getChatId(): string | null;
20
+ static setChatId(chatId: string): void;
18
21
  static getCorrelationId(): string;
19
22
  /** Save the current session into the persisted list with a display name. */
20
23
  static saveCurrentSession(name: string): void;