@useago/sdk 0.3.4 → 0.4.1
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/dist/AgoClient-B6PsfMeg.cjs +6 -0
- package/dist/{AgoClient-DF7M2WAz.js → AgoClient-BerJvssl.js} +235 -219
- package/dist/angular.cjs +1 -1
- package/dist/angular.d.cts +12 -0
- package/dist/angular.d.ts +12 -0
- package/dist/angular.js +1 -1
- package/dist/createConversationSession-CLZvxyuu.js +58 -0
- package/dist/createConversationSession-D3K5Gf1k.cjs +1 -0
- package/dist/createFormCollector-CD1rqRG4.js +208 -0
- package/dist/createFormCollector-D1FfiSgA.cjs +1 -0
- package/dist/createMockClient-DMFGIOtc.cjs +1 -0
- package/dist/{createMockClient-C50gjV0b.js → createMockClient-tVsApEAh.js} +1 -0
- package/dist/devtools.cjs +4 -4
- package/dist/devtools.d.cts +16 -26
- package/dist/devtools.d.ts +16 -26
- package/dist/devtools.js +35 -35
- package/dist/helpers.cjs +1 -1
- package/dist/helpers.js +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +102 -1
- package/dist/index.d.ts +102 -1
- package/dist/index.js +44 -42
- package/dist/react.cjs +1 -1
- package/dist/react.d.cts +20 -0
- package/dist/react.d.ts +20 -0
- package/dist/react.js +4 -4
- package/dist/vue.cjs +1 -1
- package/dist/vue.d.cts +12 -0
- package/dist/vue.d.ts +12 -0
- package/dist/vue.js +1 -1
- package/dist/widget.cjs +1 -1
- package/dist/widget.d.cts +99 -0
- package/dist/widget.d.ts +99 -0
- package/dist/widget.js +170 -150
- package/package.json +58 -15
- package/dist/AgoClient-bjN-z2ZQ.cjs +0 -6
- package/dist/createFormCollector-ClzHfaBd.js +0 -185
- package/dist/createFormCollector-H4Me_2uj.cjs +0 -1
- package/dist/createMockClient-DQvFFWnc.cjs +0 -1
- /package/dist/{functions-CWSRi3xv.js → functions-C1-5vadY.js} +0 -0
- /package/dist/{functions-BH1X5kas.cjs → functions-DsmzgHjC.cjs} +0 -0
package/dist/widget.d.cts
CHANGED
|
@@ -31,6 +31,12 @@ declare class AgoClient {
|
|
|
31
31
|
* Get a specific conversation with messages
|
|
32
32
|
*/
|
|
33
33
|
getConversation(conversationId: string): Promise<Conversation>;
|
|
34
|
+
/**
|
|
35
|
+
* Map the backend's snake_case `tool_call_data` entries onto the camelCase
|
|
36
|
+
* {@link ToolCallData} shape used everywhere else in the SDK. Mirrors
|
|
37
|
+
* `SSEHandler.parseToolCall` so persisted and streamed tool calls match.
|
|
38
|
+
*/
|
|
39
|
+
private static mapPersistedToolCalls;
|
|
34
40
|
/**
|
|
35
41
|
* Get messages for a conversation
|
|
36
42
|
*/
|
|
@@ -201,6 +207,12 @@ declare interface AgoClientEvents {
|
|
|
201
207
|
conversationId?: string;
|
|
202
208
|
messageId?: string;
|
|
203
209
|
};
|
|
210
|
+
/**
|
|
211
|
+
* A full conversation was loaded from the server (e.g. after a page reload).
|
|
212
|
+
* Carries the messages and their persisted tool calls so stateful helpers —
|
|
213
|
+
* notably `createFormCollector` — can replay them to restore their state.
|
|
214
|
+
*/
|
|
215
|
+
"conversation:loaded": Conversation;
|
|
204
216
|
"toolCall:received": ToolCallData;
|
|
205
217
|
"toolCall:form": ToolCallData;
|
|
206
218
|
"function:invoke": ClientFunctionInvocation;
|
|
@@ -313,6 +325,20 @@ export declare interface ChatWidgetHandle {
|
|
|
313
325
|
element: HTMLElement;
|
|
314
326
|
/** Programmatically send a message (same path as the input). */
|
|
315
327
|
sendMessage: (content: string, files?: File[]) => Promise<void>;
|
|
328
|
+
/**
|
|
329
|
+
* The conversation-persistence session, present only when `persistConversation`
|
|
330
|
+
* is set — exposes the stable `widgetId` and `session.clear()` to start a new thread.
|
|
331
|
+
*/
|
|
332
|
+
session?: ConversationSession;
|
|
333
|
+
/**
|
|
334
|
+
* The visitor's conversations (threads) — the vanilla equivalent of the React/Vue
|
|
335
|
+
* `useConversation().conversations`. Auto-loaded on mount and refreshed after each
|
|
336
|
+
* turn only when `loadThreads` is set; otherwise it stays empty until you call
|
|
337
|
+
* {@link ChatWidgetHandle.refreshThreads}.
|
|
338
|
+
*/
|
|
339
|
+
readonly threads: Conversation[];
|
|
340
|
+
/** Re-fetch the conversations list and update {@link ChatWidgetHandle.threads}. */
|
|
341
|
+
refreshThreads: () => Promise<Conversation[]>;
|
|
316
342
|
/** Remove listeners, uninstall forms, and clear the DOM. */
|
|
317
343
|
destroy: () => void;
|
|
318
344
|
}
|
|
@@ -400,6 +426,60 @@ declare interface Conversation {
|
|
|
400
426
|
messages?: AgoMessage[];
|
|
401
427
|
}
|
|
402
428
|
|
|
429
|
+
export declare interface ConversationSession {
|
|
430
|
+
/**
|
|
431
|
+
* The stable widget id identifying this visitor. Generated once and persisted
|
|
432
|
+
* forever, so a returning visitor keeps the same id (and therefore the same
|
|
433
|
+
* server-side conversation history) across reloads.
|
|
434
|
+
*/
|
|
435
|
+
readonly widgetId: string;
|
|
436
|
+
/**
|
|
437
|
+
* The last active thread id, decided **entirely on the front** so a reload costs
|
|
438
|
+
* no backend round-trip. Returns `null` when there is no cached thread, when its
|
|
439
|
+
* last message time is unknown, or when it has been idle longer than `ttlMs`.
|
|
440
|
+
*/
|
|
441
|
+
getLastActiveThread(): string | null;
|
|
442
|
+
/**
|
|
443
|
+
* Record (and refresh) the active thread together with the time of its last
|
|
444
|
+
* message — call it once per turn. The `lastMessageAt` drives the sliding TTL;
|
|
445
|
+
* omit it and the thread won't be resumed (no time → not displayed).
|
|
446
|
+
*/
|
|
447
|
+
setActiveThread(conversationId: string, lastMessageAt?: Date | number): void;
|
|
448
|
+
/** Forget the cached thread — e.g. on "new chat". */
|
|
449
|
+
clear(): void;
|
|
450
|
+
/** The resolved storage key holding the widget id — handy for debugging. */
|
|
451
|
+
readonly key: string;
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
export declare interface ConversationSessionOptions {
|
|
455
|
+
/**
|
|
456
|
+
* Storage backend. Defaults to `localStorage`, degrading to an in-memory store
|
|
457
|
+
* when storage is unavailable (SSR / disabled). Pass `sessionStorage` for a
|
|
458
|
+
* tab-scoped session, or any `{ getItem, setItem }` for a custom backend.
|
|
459
|
+
*/
|
|
460
|
+
storage?: StorageLike;
|
|
461
|
+
/**
|
|
462
|
+
* Storage key for the widget id. Default `"ago_widget_id"` — the same key the
|
|
463
|
+
* HTTP client reads, so the visitor's id is shared across the SDK.
|
|
464
|
+
*/
|
|
465
|
+
key?: string;
|
|
466
|
+
/**
|
|
467
|
+
* Explicit widget id to adopt (and persist) instead of reading or generating
|
|
468
|
+
* one — e.g. when the host app already has a stable visitor identifier.
|
|
469
|
+
*/
|
|
470
|
+
widgetId?: string;
|
|
471
|
+
/** Storage key for the cached last active thread. Default `"ago_last_thread"`. */
|
|
472
|
+
threadKey?: string;
|
|
473
|
+
/**
|
|
474
|
+
* Maximum idle age of a thread to still resume it, in milliseconds, compared
|
|
475
|
+
* against the recorded time of its last message. Checked entirely on the front
|
|
476
|
+
* (no backend call): a thread idle longer than this — or one with no recorded
|
|
477
|
+
* last-message time — is not resumed (`getLastActiveThread` returns `null`).
|
|
478
|
+
* Default 2h. Pass `Infinity` to never expire.
|
|
479
|
+
*/
|
|
480
|
+
ttlMs?: number;
|
|
481
|
+
}
|
|
482
|
+
|
|
403
483
|
export declare interface CreateFormCollectorOptions<V = Record<string, unknown>> {
|
|
404
484
|
/** Short identifier; becomes the `update_<name>` / `submit_<name>` function names. */
|
|
405
485
|
name: string;
|
|
@@ -488,6 +568,15 @@ export declare interface MountChatWidgetOptions {
|
|
|
488
568
|
config?: AgoConfig;
|
|
489
569
|
/** Initial conversation ID to continue. */
|
|
490
570
|
conversationId?: string;
|
|
571
|
+
/**
|
|
572
|
+
* Resume the visitor's last active thread across reloads. `true` enables defaults
|
|
573
|
+
* (localStorage, widget id under `ago_widget_id`); pass an object to set `storage`
|
|
574
|
+
* (e.g. `sessionStorage`), `key`, or an explicit `widgetId`. Built on
|
|
575
|
+
* {@link createConversationSession}: the visitor is identified by a single stable
|
|
576
|
+
* widget id and the backend hands back their most recently updated conversation.
|
|
577
|
+
* An explicit `conversationId` still wins as the initial thread. Off by default.
|
|
578
|
+
*/
|
|
579
|
+
persistConversation?: boolean | Partial<ConversationSessionOptions>;
|
|
491
580
|
/** Widget title shown in the header. */
|
|
492
581
|
title?: string;
|
|
493
582
|
/** Message shown before any conversation has started. */
|
|
@@ -502,6 +591,13 @@ export declare interface MountChatWidgetOptions {
|
|
|
502
591
|
logoUrl?: string;
|
|
503
592
|
/** Show the agent name above assistant messages. Defaults to `false`. */
|
|
504
593
|
showAgentName?: boolean;
|
|
594
|
+
/**
|
|
595
|
+
* Load the visitor's conversation list into `widget.threads` on mount and refresh
|
|
596
|
+
* it after each turn (one `GET /conversations` per load). Off by default to avoid
|
|
597
|
+
* the request when the integrator doesn't need it; `widget.refreshThreads()` stays
|
|
598
|
+
* callable on demand regardless.
|
|
599
|
+
*/
|
|
600
|
+
loadThreads?: boolean;
|
|
505
601
|
/**
|
|
506
602
|
* Conversational forms the agent can fill and submit during the chat. Each
|
|
507
603
|
* config is installed as a {@link createFormCollector} for the lifetime of the
|
|
@@ -535,6 +631,9 @@ declare interface SendMessageOptions {
|
|
|
535
631
|
files?: File[];
|
|
536
632
|
}
|
|
537
633
|
|
|
634
|
+
/** The slice of the Web Storage API that {@link createStore} relies on. */
|
|
635
|
+
declare type StorageLike = Pick<Storage, "getItem" | "setItem">;
|
|
636
|
+
|
|
538
637
|
/**
|
|
539
638
|
* Where a completed form is sent.
|
|
540
639
|
* - `"https://..."` (a bare string) — shorthand for `{ via: "client", url }`: the browser
|
package/dist/widget.d.ts
CHANGED
|
@@ -31,6 +31,12 @@ declare class AgoClient {
|
|
|
31
31
|
* Get a specific conversation with messages
|
|
32
32
|
*/
|
|
33
33
|
getConversation(conversationId: string): Promise<Conversation>;
|
|
34
|
+
/**
|
|
35
|
+
* Map the backend's snake_case `tool_call_data` entries onto the camelCase
|
|
36
|
+
* {@link ToolCallData} shape used everywhere else in the SDK. Mirrors
|
|
37
|
+
* `SSEHandler.parseToolCall` so persisted and streamed tool calls match.
|
|
38
|
+
*/
|
|
39
|
+
private static mapPersistedToolCalls;
|
|
34
40
|
/**
|
|
35
41
|
* Get messages for a conversation
|
|
36
42
|
*/
|
|
@@ -201,6 +207,12 @@ declare interface AgoClientEvents {
|
|
|
201
207
|
conversationId?: string;
|
|
202
208
|
messageId?: string;
|
|
203
209
|
};
|
|
210
|
+
/**
|
|
211
|
+
* A full conversation was loaded from the server (e.g. after a page reload).
|
|
212
|
+
* Carries the messages and their persisted tool calls so stateful helpers —
|
|
213
|
+
* notably `createFormCollector` — can replay them to restore their state.
|
|
214
|
+
*/
|
|
215
|
+
"conversation:loaded": Conversation;
|
|
204
216
|
"toolCall:received": ToolCallData;
|
|
205
217
|
"toolCall:form": ToolCallData;
|
|
206
218
|
"function:invoke": ClientFunctionInvocation;
|
|
@@ -313,6 +325,20 @@ export declare interface ChatWidgetHandle {
|
|
|
313
325
|
element: HTMLElement;
|
|
314
326
|
/** Programmatically send a message (same path as the input). */
|
|
315
327
|
sendMessage: (content: string, files?: File[]) => Promise<void>;
|
|
328
|
+
/**
|
|
329
|
+
* The conversation-persistence session, present only when `persistConversation`
|
|
330
|
+
* is set — exposes the stable `widgetId` and `session.clear()` to start a new thread.
|
|
331
|
+
*/
|
|
332
|
+
session?: ConversationSession;
|
|
333
|
+
/**
|
|
334
|
+
* The visitor's conversations (threads) — the vanilla equivalent of the React/Vue
|
|
335
|
+
* `useConversation().conversations`. Auto-loaded on mount and refreshed after each
|
|
336
|
+
* turn only when `loadThreads` is set; otherwise it stays empty until you call
|
|
337
|
+
* {@link ChatWidgetHandle.refreshThreads}.
|
|
338
|
+
*/
|
|
339
|
+
readonly threads: Conversation[];
|
|
340
|
+
/** Re-fetch the conversations list and update {@link ChatWidgetHandle.threads}. */
|
|
341
|
+
refreshThreads: () => Promise<Conversation[]>;
|
|
316
342
|
/** Remove listeners, uninstall forms, and clear the DOM. */
|
|
317
343
|
destroy: () => void;
|
|
318
344
|
}
|
|
@@ -400,6 +426,60 @@ declare interface Conversation {
|
|
|
400
426
|
messages?: AgoMessage[];
|
|
401
427
|
}
|
|
402
428
|
|
|
429
|
+
export declare interface ConversationSession {
|
|
430
|
+
/**
|
|
431
|
+
* The stable widget id identifying this visitor. Generated once and persisted
|
|
432
|
+
* forever, so a returning visitor keeps the same id (and therefore the same
|
|
433
|
+
* server-side conversation history) across reloads.
|
|
434
|
+
*/
|
|
435
|
+
readonly widgetId: string;
|
|
436
|
+
/**
|
|
437
|
+
* The last active thread id, decided **entirely on the front** so a reload costs
|
|
438
|
+
* no backend round-trip. Returns `null` when there is no cached thread, when its
|
|
439
|
+
* last message time is unknown, or when it has been idle longer than `ttlMs`.
|
|
440
|
+
*/
|
|
441
|
+
getLastActiveThread(): string | null;
|
|
442
|
+
/**
|
|
443
|
+
* Record (and refresh) the active thread together with the time of its last
|
|
444
|
+
* message — call it once per turn. The `lastMessageAt` drives the sliding TTL;
|
|
445
|
+
* omit it and the thread won't be resumed (no time → not displayed).
|
|
446
|
+
*/
|
|
447
|
+
setActiveThread(conversationId: string, lastMessageAt?: Date | number): void;
|
|
448
|
+
/** Forget the cached thread — e.g. on "new chat". */
|
|
449
|
+
clear(): void;
|
|
450
|
+
/** The resolved storage key holding the widget id — handy for debugging. */
|
|
451
|
+
readonly key: string;
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
export declare interface ConversationSessionOptions {
|
|
455
|
+
/**
|
|
456
|
+
* Storage backend. Defaults to `localStorage`, degrading to an in-memory store
|
|
457
|
+
* when storage is unavailable (SSR / disabled). Pass `sessionStorage` for a
|
|
458
|
+
* tab-scoped session, or any `{ getItem, setItem }` for a custom backend.
|
|
459
|
+
*/
|
|
460
|
+
storage?: StorageLike;
|
|
461
|
+
/**
|
|
462
|
+
* Storage key for the widget id. Default `"ago_widget_id"` — the same key the
|
|
463
|
+
* HTTP client reads, so the visitor's id is shared across the SDK.
|
|
464
|
+
*/
|
|
465
|
+
key?: string;
|
|
466
|
+
/**
|
|
467
|
+
* Explicit widget id to adopt (and persist) instead of reading or generating
|
|
468
|
+
* one — e.g. when the host app already has a stable visitor identifier.
|
|
469
|
+
*/
|
|
470
|
+
widgetId?: string;
|
|
471
|
+
/** Storage key for the cached last active thread. Default `"ago_last_thread"`. */
|
|
472
|
+
threadKey?: string;
|
|
473
|
+
/**
|
|
474
|
+
* Maximum idle age of a thread to still resume it, in milliseconds, compared
|
|
475
|
+
* against the recorded time of its last message. Checked entirely on the front
|
|
476
|
+
* (no backend call): a thread idle longer than this — or one with no recorded
|
|
477
|
+
* last-message time — is not resumed (`getLastActiveThread` returns `null`).
|
|
478
|
+
* Default 2h. Pass `Infinity` to never expire.
|
|
479
|
+
*/
|
|
480
|
+
ttlMs?: number;
|
|
481
|
+
}
|
|
482
|
+
|
|
403
483
|
export declare interface CreateFormCollectorOptions<V = Record<string, unknown>> {
|
|
404
484
|
/** Short identifier; becomes the `update_<name>` / `submit_<name>` function names. */
|
|
405
485
|
name: string;
|
|
@@ -488,6 +568,15 @@ export declare interface MountChatWidgetOptions {
|
|
|
488
568
|
config?: AgoConfig;
|
|
489
569
|
/** Initial conversation ID to continue. */
|
|
490
570
|
conversationId?: string;
|
|
571
|
+
/**
|
|
572
|
+
* Resume the visitor's last active thread across reloads. `true` enables defaults
|
|
573
|
+
* (localStorage, widget id under `ago_widget_id`); pass an object to set `storage`
|
|
574
|
+
* (e.g. `sessionStorage`), `key`, or an explicit `widgetId`. Built on
|
|
575
|
+
* {@link createConversationSession}: the visitor is identified by a single stable
|
|
576
|
+
* widget id and the backend hands back their most recently updated conversation.
|
|
577
|
+
* An explicit `conversationId` still wins as the initial thread. Off by default.
|
|
578
|
+
*/
|
|
579
|
+
persistConversation?: boolean | Partial<ConversationSessionOptions>;
|
|
491
580
|
/** Widget title shown in the header. */
|
|
492
581
|
title?: string;
|
|
493
582
|
/** Message shown before any conversation has started. */
|
|
@@ -502,6 +591,13 @@ export declare interface MountChatWidgetOptions {
|
|
|
502
591
|
logoUrl?: string;
|
|
503
592
|
/** Show the agent name above assistant messages. Defaults to `false`. */
|
|
504
593
|
showAgentName?: boolean;
|
|
594
|
+
/**
|
|
595
|
+
* Load the visitor's conversation list into `widget.threads` on mount and refresh
|
|
596
|
+
* it after each turn (one `GET /conversations` per load). Off by default to avoid
|
|
597
|
+
* the request when the integrator doesn't need it; `widget.refreshThreads()` stays
|
|
598
|
+
* callable on demand regardless.
|
|
599
|
+
*/
|
|
600
|
+
loadThreads?: boolean;
|
|
505
601
|
/**
|
|
506
602
|
* Conversational forms the agent can fill and submit during the chat. Each
|
|
507
603
|
* config is installed as a {@link createFormCollector} for the lifetime of the
|
|
@@ -535,6 +631,9 @@ declare interface SendMessageOptions {
|
|
|
535
631
|
files?: File[];
|
|
536
632
|
}
|
|
537
633
|
|
|
634
|
+
/** The slice of the Web Storage API that {@link createStore} relies on. */
|
|
635
|
+
declare type StorageLike = Pick<Storage, "getItem" | "setItem">;
|
|
636
|
+
|
|
538
637
|
/**
|
|
539
638
|
* Where a completed form is sent.
|
|
540
639
|
* - `"https://..."` (a bare string) — shorthand for `{ via: "client", url }`: the browser
|