@useago/sdk 0.3.3 → 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-tVsApEAh.js +72 -0
- package/dist/devtools.cjs +26 -26
- package/dist/devtools.d.cts +16 -26
- package/dist/devtools.d.ts +16 -26
- package/dist/devtools.js +55 -55
- 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 +46 -43
- package/dist/react.cjs +19 -19
- package/dist/react.d.cts +67 -8
- package/dist/react.d.ts +67 -8
- package/dist/react.js +1066 -1051
- 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 -0
- package/dist/widget.d.cts +635 -0
- package/dist/widget.d.ts +635 -0
- package/dist/widget.js +418 -0
- package/package.json +58 -15
- package/dist/AgoClient-bjN-z2ZQ.cjs +0 -6
- package/dist/createMockClient-D6uVh-B9.js +0 -254
- package/dist/createMockClient-DecMEUcK.cjs +0 -1
- /package/dist/{functions-DdROP6Ui.js → functions-C1-5vadY.js} +0 -0
- /package/dist/{functions-Bz-1Bs3I.cjs → functions-DsmzgHjC.cjs} +0 -0
package/dist/widget.d.ts
CHANGED
|
@@ -1,3 +1,282 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Agent information
|
|
3
|
+
*/
|
|
4
|
+
declare interface AgoAgent {
|
|
5
|
+
id: string;
|
|
6
|
+
name: string;
|
|
7
|
+
displayName?: string;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Main SDK client for AGO Chat integration
|
|
12
|
+
*/
|
|
13
|
+
declare class AgoClient {
|
|
14
|
+
private httpClient;
|
|
15
|
+
private functionRegistry;
|
|
16
|
+
private contextRegistry;
|
|
17
|
+
private eventEmitter;
|
|
18
|
+
private config;
|
|
19
|
+
constructor(config: AgoConfig);
|
|
20
|
+
/**
|
|
21
|
+
* Send a message and receive a streaming response
|
|
22
|
+
*/
|
|
23
|
+
sendMessage(content: string, options?: SendMessageOptions): Promise<AgoMessage>;
|
|
24
|
+
private processSSEResponse;
|
|
25
|
+
private handleClientFunctionInvocation;
|
|
26
|
+
/**
|
|
27
|
+
* Get list of conversations
|
|
28
|
+
*/
|
|
29
|
+
getConversations(): Promise<Conversation[]>;
|
|
30
|
+
/**
|
|
31
|
+
* Get a specific conversation with messages
|
|
32
|
+
*/
|
|
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;
|
|
40
|
+
/**
|
|
41
|
+
* Get messages for a conversation
|
|
42
|
+
*/
|
|
43
|
+
getMessages(conversationId: string): Promise<AgoMessage[]>;
|
|
44
|
+
/**
|
|
45
|
+
* Submit form data for a tool call
|
|
46
|
+
*/
|
|
47
|
+
submitToolCallForm(toolCallId: string, formData: Record<string, unknown>): Promise<void>;
|
|
48
|
+
/**
|
|
49
|
+
* Confirm a tool call
|
|
50
|
+
*/
|
|
51
|
+
confirmToolCall(toolCallId: string): Promise<void>;
|
|
52
|
+
/**
|
|
53
|
+
* Reject a tool call
|
|
54
|
+
*/
|
|
55
|
+
rejectToolCall(toolCallId: string): Promise<void>;
|
|
56
|
+
/**
|
|
57
|
+
* Relay a completed form collector's values to a server-configured destination.
|
|
58
|
+
*
|
|
59
|
+
* Used by `createFormCollector` / `useFormCollector` in `{ via: "backend" }` mode:
|
|
60
|
+
* the browser never holds the destination URL or its secret — the backend resolves
|
|
61
|
+
* `destination` (a named, opted-in tool) and forwards the values from the server.
|
|
62
|
+
*/
|
|
63
|
+
submitFormCollector(destination: string, values: Record<string, unknown>): Promise<unknown>;
|
|
64
|
+
/**
|
|
65
|
+
* Submit feedback for a message
|
|
66
|
+
*/
|
|
67
|
+
submitFeedback(messageId: string, rating: "positive" | "negative"): Promise<void>;
|
|
68
|
+
/**
|
|
69
|
+
* Register a client-side function that AGO can call.
|
|
70
|
+
* Accepts either a definition object or (name, handler, schema) args.
|
|
71
|
+
*
|
|
72
|
+
* ```ts
|
|
73
|
+
* // Single-object (preferred)
|
|
74
|
+
* client.registerFunction({
|
|
75
|
+
* name: "lookupOrder",
|
|
76
|
+
* description: "Look up an order",
|
|
77
|
+
* parameters: { type: "object", properties: { id: { type: "string" } } },
|
|
78
|
+
* handler: async (args) => fetchOrder(args.id),
|
|
79
|
+
* });
|
|
80
|
+
*
|
|
81
|
+
* // Classic 3-arg form
|
|
82
|
+
* client.registerFunction("lookupOrder", handler, schema);
|
|
83
|
+
* ```
|
|
84
|
+
*/
|
|
85
|
+
registerFunction(definition: ClientFunctionDefinition): void;
|
|
86
|
+
registerFunction(name: string, handler: ClientFunctionHandler, schema: Omit<ClientFunctionSchema, "name">): void;
|
|
87
|
+
/**
|
|
88
|
+
* Short alias for `registerFunction`. Also accepts an array of definitions.
|
|
89
|
+
*
|
|
90
|
+
* ```ts
|
|
91
|
+
* client.register(lookupOrder);
|
|
92
|
+
* client.register([lookupOrder, cancelOrder]);
|
|
93
|
+
* ```
|
|
94
|
+
*/
|
|
95
|
+
register(definition: ClientFunctionDefinition | ClientFunctionDefinition[]): void;
|
|
96
|
+
/**
|
|
97
|
+
* Unregister a client-side function
|
|
98
|
+
*/
|
|
99
|
+
unregisterFunction(name: string): boolean;
|
|
100
|
+
/**
|
|
101
|
+
* Get all registered function schemas
|
|
102
|
+
*/
|
|
103
|
+
getRegisteredFunctions(): ClientFunctionSchema[];
|
|
104
|
+
/**
|
|
105
|
+
* Register a navigation function that lets AGO navigate users to different pages.
|
|
106
|
+
* @param navigate - A callback that performs the navigation (e.g. react-router's navigate)
|
|
107
|
+
* @param routes - Map of route names to paths, with descriptions for the LLM
|
|
108
|
+
*/
|
|
109
|
+
registerNavigationFunction(navigate: (path: string) => void, routes: Array<{
|
|
110
|
+
name: string;
|
|
111
|
+
path: string;
|
|
112
|
+
description: string;
|
|
113
|
+
}>): void;
|
|
114
|
+
/**
|
|
115
|
+
* Register or update a piece of client-side context.
|
|
116
|
+
* This context is sent with every message so the AI understands the user's situation.
|
|
117
|
+
*
|
|
118
|
+
* ```ts
|
|
119
|
+
* client.setContext("order-page", {
|
|
120
|
+
* name: "Order detail",
|
|
121
|
+
* description: "User is viewing order #123",
|
|
122
|
+
* data: { orderId: "123", status: "shipped" },
|
|
123
|
+
* });
|
|
124
|
+
* ```
|
|
125
|
+
*/
|
|
126
|
+
setContext(key: string, entry: ContextEntry): void;
|
|
127
|
+
/**
|
|
128
|
+
* Remove a previously registered context entry.
|
|
129
|
+
*/
|
|
130
|
+
removeContext(key: string): boolean;
|
|
131
|
+
/**
|
|
132
|
+
* Register a dynamic context provider. The callback is invoked every time
|
|
133
|
+
* a message is sent, so the AI always gets the freshest data.
|
|
134
|
+
*
|
|
135
|
+
* Use this for context that lives outside React state — global stores,
|
|
136
|
+
* refs, or computed values.
|
|
137
|
+
*
|
|
138
|
+
* ```ts
|
|
139
|
+
* client.addDynamicContext("cart", () => ({
|
|
140
|
+
* name: "Checkout",
|
|
141
|
+
* data: { itemCount: cart.items.length, total: cart.total },
|
|
142
|
+
* }));
|
|
143
|
+
* ```
|
|
144
|
+
*/
|
|
145
|
+
addDynamicContext(key: string, provider: DynamicContextProvider): void;
|
|
146
|
+
/**
|
|
147
|
+
* Remove a dynamic context provider.
|
|
148
|
+
*/
|
|
149
|
+
removeDynamicContext(key: string): boolean;
|
|
150
|
+
/**
|
|
151
|
+
* Enable automatic capture of the current browser page (URL + title).
|
|
152
|
+
* Injected as a dynamic context entry named `browser-page`.
|
|
153
|
+
*/
|
|
154
|
+
enableAutoPageContext(): void;
|
|
155
|
+
/**
|
|
156
|
+
* Get the current context snapshot.
|
|
157
|
+
*/
|
|
158
|
+
getContextSnapshot(): ContextSnapshot | null;
|
|
159
|
+
/**
|
|
160
|
+
* Subscribe to an event
|
|
161
|
+
*/
|
|
162
|
+
on<K extends AgoEventName>(event: K, handler: AgoEventHandler<K>): void;
|
|
163
|
+
/**
|
|
164
|
+
* Unsubscribe from an event
|
|
165
|
+
*/
|
|
166
|
+
off<K extends AgoEventName>(event: K, handler: AgoEventHandler<K>): void;
|
|
167
|
+
/**
|
|
168
|
+
* Subscribe to an event once — auto-unsubscribes after the first call.
|
|
169
|
+
*/
|
|
170
|
+
once<K extends AgoEventName>(event: K, handler: AgoEventHandler<K>): void;
|
|
171
|
+
/**
|
|
172
|
+
* Returns a Promise that resolves the next time `event` fires.
|
|
173
|
+
*
|
|
174
|
+
* ```ts
|
|
175
|
+
* const msg = await client.waitFor("message:complete", { timeout: 10000 });
|
|
176
|
+
* ```
|
|
177
|
+
*/
|
|
178
|
+
waitFor<K extends AgoEventName>(event: K, options?: {
|
|
179
|
+
timeout?: number;
|
|
180
|
+
}): Promise<AgoClientEvents[K]>;
|
|
181
|
+
/**
|
|
182
|
+
* Update client configuration
|
|
183
|
+
*/
|
|
184
|
+
updateConfig(config: Partial<AgoConfig>): void;
|
|
185
|
+
/**
|
|
186
|
+
* Clean up resources
|
|
187
|
+
*/
|
|
188
|
+
destroy(): void;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
/**
|
|
192
|
+
* SDK Events
|
|
193
|
+
*/
|
|
194
|
+
declare interface AgoClientEvents {
|
|
195
|
+
"message:start": {
|
|
196
|
+
conversationId: string;
|
|
197
|
+
messageId: string;
|
|
198
|
+
};
|
|
199
|
+
"message:chunk": {
|
|
200
|
+
content: string;
|
|
201
|
+
conversationId: string;
|
|
202
|
+
messageId: string;
|
|
203
|
+
};
|
|
204
|
+
"message:complete": AgoMessage;
|
|
205
|
+
"message:error": {
|
|
206
|
+
error: string;
|
|
207
|
+
conversationId?: string;
|
|
208
|
+
messageId?: string;
|
|
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;
|
|
216
|
+
"toolCall:received": ToolCallData;
|
|
217
|
+
"toolCall:form": ToolCallData;
|
|
218
|
+
"function:invoke": ClientFunctionInvocation;
|
|
219
|
+
"function:result": {
|
|
220
|
+
invocationId: string;
|
|
221
|
+
result: unknown;
|
|
222
|
+
error?: string;
|
|
223
|
+
};
|
|
224
|
+
"connection:status": {
|
|
225
|
+
connected: boolean;
|
|
226
|
+
};
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
/**
|
|
230
|
+
* SDK Configuration
|
|
231
|
+
*/
|
|
232
|
+
declare interface AgoConfig {
|
|
233
|
+
/** API base URL (e.g., https://YOUR-DOMAIN.useago.com) */
|
|
234
|
+
baseUrl: string;
|
|
235
|
+
/** Widget ID (X-Widget-Id header). Auto-generated if not provided. */
|
|
236
|
+
widgetId?: string;
|
|
237
|
+
/** Default agent (id or slug) for new conversations. Shorthand for `defaultAgentId`. */
|
|
238
|
+
agent?: string;
|
|
239
|
+
/** Default agent ID for new conversations. Prefer `agent`. */
|
|
240
|
+
defaultAgentId?: string;
|
|
241
|
+
/** Permission name to apply to all requests (sent as `X-Widget-Permission`). Mirrors the widget's `window.AGO.permission`. */
|
|
242
|
+
permission?: string;
|
|
243
|
+
/** User email for identification */
|
|
244
|
+
userEmail?: string;
|
|
245
|
+
/** JWT token for authenticated users */
|
|
246
|
+
userJwt?: string;
|
|
247
|
+
/** Enable debug logging */
|
|
248
|
+
debug?: boolean;
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
declare type AgoEventHandler<K extends AgoEventName> = (data: AgoClientEvents[K]) => void;
|
|
252
|
+
|
|
253
|
+
declare type AgoEventName = keyof AgoClientEvents;
|
|
254
|
+
|
|
255
|
+
/**
|
|
256
|
+
* Message from AGO
|
|
257
|
+
*/
|
|
258
|
+
declare interface AgoMessage {
|
|
259
|
+
id: string;
|
|
260
|
+
conversationId: string;
|
|
261
|
+
content: string;
|
|
262
|
+
role: "user" | "assistant";
|
|
263
|
+
status: MessageStatus;
|
|
264
|
+
agent?: AgoAgent;
|
|
265
|
+
sources?: AgoSource[];
|
|
266
|
+
toolCalls?: ToolCallData[];
|
|
267
|
+
followUpReplies?: string[];
|
|
268
|
+
createdAt: Date;
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
/**
|
|
272
|
+
* Knowledge source citation
|
|
273
|
+
*/
|
|
274
|
+
declare interface AgoSource {
|
|
275
|
+
id: string;
|
|
276
|
+
title: string;
|
|
277
|
+
url?: string;
|
|
278
|
+
}
|
|
279
|
+
|
|
1
280
|
/**
|
|
2
281
|
* Widget configuration types.
|
|
3
282
|
*
|
|
@@ -38,4 +317,360 @@ export declare interface AgoWidgetConfig {
|
|
|
38
317
|
metadata?: Record<string, unknown>;
|
|
39
318
|
}
|
|
40
319
|
|
|
320
|
+
/** Handle returned by {@link mountChatWidget}. */
|
|
321
|
+
export declare interface ChatWidgetHandle {
|
|
322
|
+
/** The AGO client backing the widget. */
|
|
323
|
+
client: AgoClient;
|
|
324
|
+
/** The root element the widget rendered into. */
|
|
325
|
+
element: HTMLElement;
|
|
326
|
+
/** Programmatically send a message (same path as the input). */
|
|
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[]>;
|
|
342
|
+
/** Remove listeners, uninstall forms, and clear the DOM. */
|
|
343
|
+
destroy: () => void;
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
/**
|
|
347
|
+
* Single-object function definition — combines name, schema, and handler.
|
|
348
|
+
*
|
|
349
|
+
* ```ts
|
|
350
|
+
* const fn = defineFunction({
|
|
351
|
+
* name: "lookupOrder",
|
|
352
|
+
* description: "Look up an order by ID",
|
|
353
|
+
* parameters: { type: "object", properties: { id: { type: "string" } }, required: ["id"] },
|
|
354
|
+
* handler: async (args) => fetchOrder(args.id as string),
|
|
355
|
+
* });
|
|
356
|
+
* client.registerFunction(fn);
|
|
357
|
+
* ```
|
|
358
|
+
*/
|
|
359
|
+
declare interface ClientFunctionDefinition {
|
|
360
|
+
name: string;
|
|
361
|
+
description: string;
|
|
362
|
+
parameters: ClientFunctionSchema["parameters"];
|
|
363
|
+
handler: ClientFunctionHandler;
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
/**
|
|
367
|
+
* Function handler type
|
|
368
|
+
*/
|
|
369
|
+
declare type ClientFunctionHandler = (args: Record<string, unknown>) => Promise<unknown> | unknown;
|
|
370
|
+
|
|
371
|
+
declare interface ClientFunctionInvocation {
|
|
372
|
+
invocationId: string;
|
|
373
|
+
functionName: string;
|
|
374
|
+
arguments: Record<string, unknown>;
|
|
375
|
+
conversationId: string;
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
/**
|
|
379
|
+
* Schema for a client-side function that AGO can call
|
|
380
|
+
*/
|
|
381
|
+
declare interface ClientFunctionSchema {
|
|
382
|
+
/** Function name (must be unique) */
|
|
383
|
+
name: string;
|
|
384
|
+
/** Description for the LLM to understand when to call this function */
|
|
385
|
+
description: string;
|
|
386
|
+
/** JSON Schema for function parameters */
|
|
387
|
+
parameters: {
|
|
388
|
+
type: "object";
|
|
389
|
+
properties: Record<string, {
|
|
390
|
+
type: string;
|
|
391
|
+
description?: string;
|
|
392
|
+
enum?: string[];
|
|
393
|
+
default?: unknown;
|
|
394
|
+
}>;
|
|
395
|
+
required?: string[];
|
|
396
|
+
};
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
/**
|
|
400
|
+
* A single piece of context the client wants the LLM to know about.
|
|
401
|
+
*/
|
|
402
|
+
declare interface ContextEntry {
|
|
403
|
+
/** Human-readable label (e.g. "Order detail", "Current user") */
|
|
404
|
+
name?: string;
|
|
405
|
+
/** Short description of what this context represents */
|
|
406
|
+
description?: string;
|
|
407
|
+
/** Arbitrary structured data the AI should know about */
|
|
408
|
+
data?: Record<string, unknown>;
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
/**
|
|
412
|
+
* Serialised client context sent with each message.
|
|
413
|
+
*/
|
|
414
|
+
declare interface ContextSnapshot {
|
|
415
|
+
/** All active context entries keyed by their registration key */
|
|
416
|
+
entries: Record<string, ContextEntry>;
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
/**
|
|
420
|
+
* Conversation/Thread
|
|
421
|
+
*/
|
|
422
|
+
declare interface Conversation {
|
|
423
|
+
id: string;
|
|
424
|
+
title: string;
|
|
425
|
+
lastMessageDate: Date;
|
|
426
|
+
messages?: AgoMessage[];
|
|
427
|
+
}
|
|
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
|
+
|
|
483
|
+
export declare interface CreateFormCollectorOptions<V = Record<string, unknown>> {
|
|
484
|
+
/** Short identifier; becomes the `update_<name>` / `submit_<name>` function names. */
|
|
485
|
+
name: string;
|
|
486
|
+
/** What the form is, for the LLM. */
|
|
487
|
+
description: string;
|
|
488
|
+
/** The single source of truth for the form's fields. */
|
|
489
|
+
schema: FormCollectorSchema;
|
|
490
|
+
/** How the completed form is submitted. Default: `false` (collect only). */
|
|
491
|
+
submit?: SubmitConfig<V>;
|
|
492
|
+
/** Pre-filled values. */
|
|
493
|
+
initialValues?: Partial<V>;
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
/**
|
|
497
|
+
* A function that returns a fresh context entry on demand.
|
|
498
|
+
* Evaluated every time a message is sent — use it to pull data from stores,
|
|
499
|
+
* refs, or any source that isn't captured by React state.
|
|
500
|
+
*/
|
|
501
|
+
declare type DynamicContextProvider = () => ContextEntry | null | undefined;
|
|
502
|
+
|
|
503
|
+
/**
|
|
504
|
+
* JSON-schema shape of a form's fields — identical to a client function's
|
|
505
|
+
* `parameters`, so one schema feeds the store, the update function, and the
|
|
506
|
+
* dynamic context with no second type.
|
|
507
|
+
*/
|
|
508
|
+
declare type FormCollectorSchema = ClientFunctionSchema["parameters"];
|
|
509
|
+
|
|
510
|
+
declare interface FormField {
|
|
511
|
+
type: "string" | "number" | "boolean" | "array";
|
|
512
|
+
title?: string;
|
|
513
|
+
description?: string;
|
|
514
|
+
enum?: string[];
|
|
515
|
+
default?: unknown;
|
|
516
|
+
}
|
|
517
|
+
|
|
518
|
+
/**
|
|
519
|
+
* Form schema for tool calls requiring user input
|
|
520
|
+
*/
|
|
521
|
+
declare interface FormSchema {
|
|
522
|
+
type: "object";
|
|
523
|
+
properties: Record<string, FormField>;
|
|
524
|
+
required?: string[];
|
|
525
|
+
}
|
|
526
|
+
|
|
527
|
+
declare type MessageStatus = "IN_PROGRESS" | "DONE" | "ERROR" | "TODO" | "CANCELED";
|
|
528
|
+
|
|
529
|
+
/**
|
|
530
|
+
* Mount a complete, dependency-free chat widget into any DOM element — no React,
|
|
531
|
+
* Vue, or Angular required. Mirrors the React `<ChatWidget>`: it streams replies,
|
|
532
|
+
* renders clickable suggested replies, and installs conversational form collectors.
|
|
533
|
+
*
|
|
534
|
+
* Message content is rendered as plain text (no markdown) to stay dependency-free;
|
|
535
|
+
* use the React `<Message>` component if you need GitHub-flavored markdown.
|
|
536
|
+
*
|
|
537
|
+
* ```ts
|
|
538
|
+
* import { mountChatWidget } from "@useago/sdk/widget";
|
|
539
|
+
*
|
|
540
|
+
* const widget = mountChatWidget("#chat", {
|
|
541
|
+
* config: { baseUrl: "https://YOUR-DOMAIN.useago.com" },
|
|
542
|
+
* title: "Book a demo",
|
|
543
|
+
* forms: [{
|
|
544
|
+
* name: "demo_request",
|
|
545
|
+
* description: "A request to book a product demo.",
|
|
546
|
+
* schema: {
|
|
547
|
+
* type: "object",
|
|
548
|
+
* properties: { name: { type: "string" }, email: { type: "string" } },
|
|
549
|
+
* required: ["name", "email"],
|
|
550
|
+
* },
|
|
551
|
+
* submit: { via: "backend", destination: "demo_webhook" },
|
|
552
|
+
* }],
|
|
553
|
+
* });
|
|
554
|
+
* // later: widget.destroy();
|
|
555
|
+
* ```
|
|
556
|
+
*/
|
|
557
|
+
export declare function mountChatWidget(target: string | HTMLElement, options: MountChatWidgetOptions): ChatWidgetHandle;
|
|
558
|
+
|
|
559
|
+
/**
|
|
560
|
+
* Options for {@link mountChatWidget} — the framework-agnostic (pure TS/JS)
|
|
561
|
+
* equivalent of the React `<ChatWidget>` component. Same features: conversational
|
|
562
|
+
* forms (form creator) and clickable suggested replies.
|
|
563
|
+
*/
|
|
564
|
+
export declare interface MountChatWidgetOptions {
|
|
565
|
+
/** An existing AGO client. Provide this OR `config`. */
|
|
566
|
+
client?: AgoClient;
|
|
567
|
+
/** Config to build a client when `client` is not supplied. `baseUrl` is required. */
|
|
568
|
+
config?: AgoConfig;
|
|
569
|
+
/** Initial conversation ID to continue. */
|
|
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>;
|
|
580
|
+
/** Widget title shown in the header. */
|
|
581
|
+
title?: string;
|
|
582
|
+
/** Message shown before any conversation has started. */
|
|
583
|
+
welcomeMessage?: string;
|
|
584
|
+
/** Input placeholder. */
|
|
585
|
+
placeholder?: string;
|
|
586
|
+
/** Enable file attachments. */
|
|
587
|
+
allowFiles?: boolean;
|
|
588
|
+
/** Widget height (number → px). */
|
|
589
|
+
height?: string | number;
|
|
590
|
+
/** URL of a logo shown in the header. */
|
|
591
|
+
logoUrl?: string;
|
|
592
|
+
/** Show the agent name above assistant messages. Defaults to `false`. */
|
|
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;
|
|
601
|
+
/**
|
|
602
|
+
* Conversational forms the agent can fill and submit during the chat. Each
|
|
603
|
+
* config is installed as a {@link createFormCollector} for the lifetime of the
|
|
604
|
+
* widget (removed on `destroy()`).
|
|
605
|
+
*/
|
|
606
|
+
forms?: CreateFormCollectorOptions[];
|
|
607
|
+
/**
|
|
608
|
+
* How clicking a suggested follow-up reply behaves. Defaults to sending the
|
|
609
|
+
* reply as a new user message. Pass a handler to override, or `false` to
|
|
610
|
+
* render the suggestions as non-interactive.
|
|
611
|
+
*/
|
|
612
|
+
onFollowUpClick?: ((reply: string) => void) | false;
|
|
613
|
+
/** Called when the user sends a message. */
|
|
614
|
+
onMessageSent?: (content: string) => void;
|
|
615
|
+
/** Called when an assistant message completes. */
|
|
616
|
+
onMessageReceived?: (message: {
|
|
617
|
+
id: string;
|
|
618
|
+
content: string;
|
|
619
|
+
}) => void;
|
|
620
|
+
}
|
|
621
|
+
|
|
622
|
+
/**
|
|
623
|
+
* Options for sending a message
|
|
624
|
+
*/
|
|
625
|
+
declare interface SendMessageOptions {
|
|
626
|
+
/** Existing conversation ID */
|
|
627
|
+
conversationId?: string;
|
|
628
|
+
/** Override default agent */
|
|
629
|
+
agentId?: string;
|
|
630
|
+
/** File attachments */
|
|
631
|
+
files?: File[];
|
|
632
|
+
}
|
|
633
|
+
|
|
634
|
+
/** The slice of the Web Storage API that {@link createStore} relies on. */
|
|
635
|
+
declare type StorageLike = Pick<Storage, "getItem" | "setItem">;
|
|
636
|
+
|
|
637
|
+
/**
|
|
638
|
+
* Where a completed form is sent.
|
|
639
|
+
* - `"https://..."` (a bare string) — shorthand for `{ via: "client", url }`: the browser
|
|
640
|
+
* POSTs the values to that URL.
|
|
641
|
+
* - `{ via: "client", url }` — same, written out.
|
|
642
|
+
* - `{ via: "client", handler }` — the browser runs your own submit logic.
|
|
643
|
+
* - `{ via: "backend", destination }` — the browser relays the values to the backend,
|
|
644
|
+
* which forwards them to the server-configured destination (URL + secret stay server-side).
|
|
645
|
+
* - `false` — collect only, no submit function.
|
|
646
|
+
*/
|
|
647
|
+
declare type SubmitConfig<V = Record<string, unknown>> = string | {
|
|
648
|
+
via: "client";
|
|
649
|
+
url: string;
|
|
650
|
+
} | {
|
|
651
|
+
via: "client";
|
|
652
|
+
handler: (values: V) => Promise<unknown> | unknown;
|
|
653
|
+
} | {
|
|
654
|
+
via: "backend";
|
|
655
|
+
destination: string;
|
|
656
|
+
} | false;
|
|
657
|
+
|
|
658
|
+
/**
|
|
659
|
+
* Tool call data from SSE stream
|
|
660
|
+
*/
|
|
661
|
+
declare interface ToolCallData {
|
|
662
|
+
id: string;
|
|
663
|
+
type: ToolCallType;
|
|
664
|
+
status: string;
|
|
665
|
+
toolName: string;
|
|
666
|
+
toolDisplayName?: string;
|
|
667
|
+
message?: string;
|
|
668
|
+
formSchema?: FormSchema;
|
|
669
|
+
data?: Record<string, unknown>;
|
|
670
|
+
functionName?: string;
|
|
671
|
+
arguments?: Record<string, unknown>;
|
|
672
|
+
}
|
|
673
|
+
|
|
674
|
+
declare type ToolCallType = "form" | "confirmation_input" | "status_message" | "progress_indicator" | "client_function" | "reasoning" | "mcp_ui_resource";
|
|
675
|
+
|
|
41
676
|
export { }
|