@useago/sdk 0.3.2 → 0.3.4

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 (121) hide show
  1. package/dist/AgoClient-DF7M2WAz.js +575 -0
  2. package/dist/AgoClient-bjN-z2ZQ.cjs +6 -0
  3. package/dist/angular.cjs +1 -143
  4. package/dist/angular.d.cts +530 -0
  5. package/dist/angular.d.ts +530 -2
  6. package/dist/angular.js +71 -139
  7. package/dist/createFormCollector-ClzHfaBd.js +185 -0
  8. package/dist/createFormCollector-H4Me_2uj.cjs +1 -0
  9. package/dist/createMockClient-C50gjV0b.js +71 -0
  10. package/dist/createMockClient-DQvFFWnc.cjs +1 -0
  11. package/dist/devtools.cjs +26 -100
  12. package/dist/devtools.d.cts +443 -0
  13. package/dist/devtools.d.ts +443 -2
  14. package/dist/devtools.js +68 -93
  15. package/dist/functions-BH1X5kas.cjs +1 -0
  16. package/dist/functions-CWSRi3xv.js +312 -0
  17. package/dist/helpers.cjs +1 -15
  18. package/dist/{helpers/functions.d.ts → helpers.d.cts} +121 -62
  19. package/dist/helpers.d.ts +121 -2
  20. package/dist/helpers.js +16 -2
  21. package/dist/index.cjs +1 -347
  22. package/dist/index.d.cts +1150 -0
  23. package/dist/index.d.ts +1150 -20
  24. package/dist/index.js +129 -298
  25. package/dist/react.cjs +31 -22438
  26. package/dist/react.d.cts +999 -0
  27. package/dist/react.d.ts +999 -2
  28. package/dist/react.js +8416 -22376
  29. package/dist/rolldown-runtime-CaekUdDJ.cjs +1 -0
  30. package/dist/rolldown-runtime-DxmricAu.js +25 -0
  31. package/dist/vue.cjs +1 -336
  32. package/dist/vue.d.cts +1063 -0
  33. package/dist/vue.d.ts +1063 -2
  34. package/dist/vue.js +174 -316
  35. package/dist/widget.cjs +1 -0
  36. package/dist/widget.d.cts +577 -0
  37. package/dist/widget.d.ts +577 -2
  38. package/dist/widget.js +398 -0
  39. package/package.json +35 -24
  40. package/dist/AgoClient-DPZdN5n2.js +0 -905
  41. package/dist/AgoClient-DPZdN5n2.js.map +0 -1
  42. package/dist/AgoClient-wMVUQqCD.cjs +0 -976
  43. package/dist/AgoClient-wMVUQqCD.cjs.map +0 -1
  44. package/dist/angular/ago.service.d.ts +0 -98
  45. package/dist/angular/index.d.ts +0 -4
  46. package/dist/angular/provide.d.ts +0 -27
  47. package/dist/angular.cjs.map +0 -1
  48. package/dist/angular.js.map +0 -1
  49. package/dist/api/HttpClient.d.ts +0 -31
  50. package/dist/api/index.d.ts +0 -1
  51. package/dist/auto/createAgo.d.ts +0 -39
  52. package/dist/auto/index.d.ts +0 -1
  53. package/dist/client/AgoClient.d.ts +0 -169
  54. package/dist/client/errors.d.ts +0 -48
  55. package/dist/client/index.d.ts +0 -3
  56. package/dist/client/types.d.ts +0 -205
  57. package/dist/createMockClient-Ci_N2tH8.cjs +0 -104
  58. package/dist/createMockClient-Ci_N2tH8.cjs.map +0 -1
  59. package/dist/createMockClient-U0ae_AYy.js +0 -99
  60. package/dist/createMockClient-U0ae_AYy.js.map +0 -1
  61. package/dist/devtools/index.d.ts +0 -2
  62. package/dist/devtools/initDevPanel.d.ts +0 -15
  63. package/dist/devtools.cjs.map +0 -1
  64. package/dist/devtools.js.map +0 -1
  65. package/dist/functions/FunctionRegistry.d.ts +0 -41
  66. package/dist/functions/defineFunction.d.ts +0 -22
  67. package/dist/functions/index.d.ts +0 -2
  68. package/dist/functions/types.d.ts +0 -50
  69. package/dist/functions--c6lx3ic.cjs +0 -480
  70. package/dist/functions--c6lx3ic.cjs.map +0 -1
  71. package/dist/functions-C9F1dnmh.js +0 -398
  72. package/dist/functions-C9F1dnmh.js.map +0 -1
  73. package/dist/helpers/factory.d.ts +0 -20
  74. package/dist/helpers/index.d.ts +0 -1
  75. package/dist/index.cjs.map +0 -1
  76. package/dist/index.js.map +0 -1
  77. package/dist/react/components/ChatInput.d.ts +0 -12
  78. package/dist/react/components/ChatWidget.d.ts +0 -35
  79. package/dist/react/components/Markdown.d.ts +0 -12
  80. package/dist/react/components/Message.d.ts +0 -9
  81. package/dist/react/components/index.d.ts +0 -8
  82. package/dist/react/context/AgoContext.d.ts +0 -62
  83. package/dist/react/context/index.d.ts +0 -2
  84. package/dist/react/hooks/index.d.ts +0 -7
  85. package/dist/react/hooks/useAgo.d.ts +0 -14
  86. package/dist/react/hooks/useAgoContext.d.ts +0 -40
  87. package/dist/react/hooks/useAgoFunction.d.ts +0 -58
  88. package/dist/react/hooks/useAgoStore.d.ts +0 -17
  89. package/dist/react/hooks/useChat.d.ts +0 -45
  90. package/dist/react/hooks/useConversation.d.ts +0 -28
  91. package/dist/react/hooks/useMessages.d.ts +0 -26
  92. package/dist/react/index.d.ts +0 -24
  93. package/dist/react/testing.d.ts +0 -2
  94. package/dist/react.cjs.map +0 -1
  95. package/dist/react.js.map +0 -1
  96. package/dist/rolldown-runtime-BqCkTl7Q.cjs +0 -50
  97. package/dist/rolldown-runtime-CNZpIYwj.js +0 -33
  98. package/dist/state/ClientContextRegistry.d.ts +0 -64
  99. package/dist/state/createStore.d.ts +0 -30
  100. package/dist/streaming/SSEHandler.d.ts +0 -46
  101. package/dist/streaming/helpers.d.ts +0 -67
  102. package/dist/streaming/index.d.ts +0 -2
  103. package/dist/testing/createMockClient.d.ts +0 -42
  104. package/dist/testing/index.d.ts +0 -2
  105. package/dist/utils/eventEmitter.d.ts +0 -23
  106. package/dist/utils/index.d.ts +0 -2
  107. package/dist/utils/logger.d.ts +0 -14
  108. package/dist/vue/composables/useAgo.d.ts +0 -17
  109. package/dist/vue/composables/useAgoEvents.d.ts +0 -11
  110. package/dist/vue/composables/useAgoFunction.d.ts +0 -34
  111. package/dist/vue/composables/useAgoStore.d.ts +0 -18
  112. package/dist/vue/composables/useChat.d.ts +0 -251
  113. package/dist/vue/composables/useConversation.d.ts +0 -178
  114. package/dist/vue/composables/useMessages.d.ts +0 -89
  115. package/dist/vue/index.d.ts +0 -11
  116. package/dist/vue/plugin.d.ts +0 -16
  117. package/dist/vue/symbols.d.ts +0 -3
  118. package/dist/vue.cjs.map +0 -1
  119. package/dist/vue.js.map +0 -1
  120. package/dist/widget/index.d.ts +0 -1
  121. package/dist/widget/types.d.ts +0 -43
@@ -0,0 +1,999 @@
1
+ import { default as default_2 } from 'react';
2
+
3
+ /**
4
+ * Agent information
5
+ */
6
+ export declare interface AgoAgent {
7
+ id: string;
8
+ name: string;
9
+ displayName?: string;
10
+ }
11
+
12
+ /**
13
+ * Main SDK client for AGO Chat integration
14
+ */
15
+ declare class AgoClient {
16
+ private httpClient;
17
+ private functionRegistry;
18
+ private contextRegistry;
19
+ private eventEmitter;
20
+ private config;
21
+ constructor(config: AgoConfig);
22
+ /**
23
+ * Send a message and receive a streaming response
24
+ */
25
+ sendMessage(content: string, options?: SendMessageOptions): Promise<AgoMessage>;
26
+ private processSSEResponse;
27
+ private handleClientFunctionInvocation;
28
+ /**
29
+ * Get list of conversations
30
+ */
31
+ getConversations(): Promise<Conversation[]>;
32
+ /**
33
+ * Get a specific conversation with messages
34
+ */
35
+ getConversation(conversationId: string): Promise<Conversation>;
36
+ /**
37
+ * Get messages for a conversation
38
+ */
39
+ getMessages(conversationId: string): Promise<AgoMessage[]>;
40
+ /**
41
+ * Submit form data for a tool call
42
+ */
43
+ submitToolCallForm(toolCallId: string, formData: Record<string, unknown>): Promise<void>;
44
+ /**
45
+ * Confirm a tool call
46
+ */
47
+ confirmToolCall(toolCallId: string): Promise<void>;
48
+ /**
49
+ * Reject a tool call
50
+ */
51
+ rejectToolCall(toolCallId: string): Promise<void>;
52
+ /**
53
+ * Relay a completed form collector's values to a server-configured destination.
54
+ *
55
+ * Used by `createFormCollector` / `useFormCollector` in `{ via: "backend" }` mode:
56
+ * the browser never holds the destination URL or its secret — the backend resolves
57
+ * `destination` (a named, opted-in tool) and forwards the values from the server.
58
+ */
59
+ submitFormCollector(destination: string, values: Record<string, unknown>): Promise<unknown>;
60
+ /**
61
+ * Submit feedback for a message
62
+ */
63
+ submitFeedback(messageId: string, rating: "positive" | "negative"): Promise<void>;
64
+ /**
65
+ * Register a client-side function that AGO can call.
66
+ * Accepts either a definition object or (name, handler, schema) args.
67
+ *
68
+ * ```ts
69
+ * // Single-object (preferred)
70
+ * client.registerFunction({
71
+ * name: "lookupOrder",
72
+ * description: "Look up an order",
73
+ * parameters: { type: "object", properties: { id: { type: "string" } } },
74
+ * handler: async (args) => fetchOrder(args.id),
75
+ * });
76
+ *
77
+ * // Classic 3-arg form
78
+ * client.registerFunction("lookupOrder", handler, schema);
79
+ * ```
80
+ */
81
+ registerFunction(definition: ClientFunctionDefinition): void;
82
+ registerFunction(name: string, handler: ClientFunctionHandler, schema: Omit<ClientFunctionSchema, "name">): void;
83
+ /**
84
+ * Short alias for `registerFunction`. Also accepts an array of definitions.
85
+ *
86
+ * ```ts
87
+ * client.register(lookupOrder);
88
+ * client.register([lookupOrder, cancelOrder]);
89
+ * ```
90
+ */
91
+ register(definition: ClientFunctionDefinition | ClientFunctionDefinition[]): void;
92
+ /**
93
+ * Unregister a client-side function
94
+ */
95
+ unregisterFunction(name: string): boolean;
96
+ /**
97
+ * Get all registered function schemas
98
+ */
99
+ getRegisteredFunctions(): ClientFunctionSchema[];
100
+ /**
101
+ * Register a navigation function that lets AGO navigate users to different pages.
102
+ * @param navigate - A callback that performs the navigation (e.g. react-router's navigate)
103
+ * @param routes - Map of route names to paths, with descriptions for the LLM
104
+ */
105
+ registerNavigationFunction(navigate: (path: string) => void, routes: Array<{
106
+ name: string;
107
+ path: string;
108
+ description: string;
109
+ }>): void;
110
+ /**
111
+ * Register or update a piece of client-side context.
112
+ * This context is sent with every message so the AI understands the user's situation.
113
+ *
114
+ * ```ts
115
+ * client.setContext("order-page", {
116
+ * name: "Order detail",
117
+ * description: "User is viewing order #123",
118
+ * data: { orderId: "123", status: "shipped" },
119
+ * });
120
+ * ```
121
+ */
122
+ setContext(key: string, entry: ContextEntry): void;
123
+ /**
124
+ * Remove a previously registered context entry.
125
+ */
126
+ removeContext(key: string): boolean;
127
+ /**
128
+ * Register a dynamic context provider. The callback is invoked every time
129
+ * a message is sent, so the AI always gets the freshest data.
130
+ *
131
+ * Use this for context that lives outside React state — global stores,
132
+ * refs, or computed values.
133
+ *
134
+ * ```ts
135
+ * client.addDynamicContext("cart", () => ({
136
+ * name: "Checkout",
137
+ * data: { itemCount: cart.items.length, total: cart.total },
138
+ * }));
139
+ * ```
140
+ */
141
+ addDynamicContext(key: string, provider: DynamicContextProvider): void;
142
+ /**
143
+ * Remove a dynamic context provider.
144
+ */
145
+ removeDynamicContext(key: string): boolean;
146
+ /**
147
+ * Enable automatic capture of the current browser page (URL + title).
148
+ * Injected as a dynamic context entry named `browser-page`.
149
+ */
150
+ enableAutoPageContext(): void;
151
+ /**
152
+ * Get the current context snapshot.
153
+ */
154
+ getContextSnapshot(): ContextSnapshot | null;
155
+ /**
156
+ * Subscribe to an event
157
+ */
158
+ on<K extends AgoEventName>(event: K, handler: AgoEventHandler<K>): void;
159
+ /**
160
+ * Unsubscribe from an event
161
+ */
162
+ off<K extends AgoEventName>(event: K, handler: AgoEventHandler<K>): void;
163
+ /**
164
+ * Subscribe to an event once — auto-unsubscribes after the first call.
165
+ */
166
+ once<K extends AgoEventName>(event: K, handler: AgoEventHandler<K>): void;
167
+ /**
168
+ * Returns a Promise that resolves the next time `event` fires.
169
+ *
170
+ * ```ts
171
+ * const msg = await client.waitFor("message:complete", { timeout: 10000 });
172
+ * ```
173
+ */
174
+ waitFor<K extends AgoEventName>(event: K, options?: {
175
+ timeout?: number;
176
+ }): Promise<AgoClientEvents[K]>;
177
+ /**
178
+ * Update client configuration
179
+ */
180
+ updateConfig(config: Partial<AgoConfig>): void;
181
+ /**
182
+ * Clean up resources
183
+ */
184
+ destroy(): void;
185
+ }
186
+
187
+ /**
188
+ * SDK Events
189
+ */
190
+ declare interface AgoClientEvents {
191
+ "message:start": {
192
+ conversationId: string;
193
+ messageId: string;
194
+ };
195
+ "message:chunk": {
196
+ content: string;
197
+ conversationId: string;
198
+ messageId: string;
199
+ };
200
+ "message:complete": AgoMessage;
201
+ "message:error": {
202
+ error: string;
203
+ conversationId?: string;
204
+ messageId?: string;
205
+ };
206
+ "toolCall:received": ToolCallData;
207
+ "toolCall:form": ToolCallData;
208
+ "function:invoke": ClientFunctionInvocation;
209
+ "function:result": {
210
+ invocationId: string;
211
+ result: unknown;
212
+ error?: string;
213
+ };
214
+ "connection:status": {
215
+ connected: boolean;
216
+ };
217
+ }
218
+
219
+ /**
220
+ * SDK Configuration
221
+ */
222
+ export declare interface AgoConfig {
223
+ /** API base URL (e.g., https://YOUR-DOMAIN.useago.com) */
224
+ baseUrl: string;
225
+ /** Widget ID (X-Widget-Id header). Auto-generated if not provided. */
226
+ widgetId?: string;
227
+ /** Default agent (id or slug) for new conversations. Shorthand for `defaultAgentId`. */
228
+ agent?: string;
229
+ /** Default agent ID for new conversations. Prefer `agent`. */
230
+ defaultAgentId?: string;
231
+ /** Permission name to apply to all requests (sent as `X-Widget-Permission`). Mirrors the widget's `window.AGO.permission`. */
232
+ permission?: string;
233
+ /** User email for identification */
234
+ userEmail?: string;
235
+ /** JWT token for authenticated users */
236
+ userJwt?: string;
237
+ /** Enable debug logging */
238
+ debug?: boolean;
239
+ }
240
+
241
+ /**
242
+ * Top-level declarative configuration for the `AgoProvider`.
243
+ *
244
+ * - `tools` — full function definitions to expose to the AI app-wide
245
+ * - `helpers` — map of pre-built helper name → handler override (or `true` for default)
246
+ * - `pageContext` — `"auto"` enables automatic URL/title capture
247
+ */
248
+ export declare interface AgoDeclarativeConfig {
249
+ tools?: ClientFunctionDefinition[];
250
+ helpers?: Record<string, ClientFunctionHandler | true>;
251
+ pageContext?: "auto" | "manual";
252
+ }
253
+
254
+ declare type AgoEventHandler<K extends AgoEventName> = (data: AgoClientEvents[K]) => void;
255
+
256
+ declare type AgoEventName = keyof AgoClientEvents;
257
+
258
+ /**
259
+ * Message from AGO
260
+ */
261
+ export declare interface AgoMessage {
262
+ id: string;
263
+ conversationId: string;
264
+ content: string;
265
+ role: "user" | "assistant";
266
+ status: MessageStatus;
267
+ agent?: AgoAgent;
268
+ sources?: AgoSource[];
269
+ toolCalls?: ToolCallData[];
270
+ followUpReplies?: string[];
271
+ createdAt: Date;
272
+ }
273
+
274
+ /**
275
+ * Provides an AgoClient to all descendant components via React context.
276
+ *
277
+ * ```tsx
278
+ * // Minimal setup
279
+ * <AgoProvider baseUrl="https://YOUR-DOMAIN.useago.com">
280
+ * <App />
281
+ * </AgoProvider>
282
+ *
283
+ * // Declarative config — tools, helpers, page context
284
+ * <AgoProvider
285
+ * baseUrl="https://YOUR-DOMAIN.useago.com"
286
+ * tools={[lookupOrder, cancelOrder]}
287
+ * helpers={{
288
+ * showToast: (args) => toast(args.message as string),
289
+ * copyToClipboard: true, // use default handler
290
+ * }}
291
+ * pageContext="auto"
292
+ * >
293
+ * <App />
294
+ * </AgoProvider>
295
+ *
296
+ * // With a pre-built client (useful for testing)
297
+ * <AgoProvider client={myClient}>
298
+ * <App />
299
+ * </AgoProvider>
300
+ * ```
301
+ */
302
+ export declare const AgoProvider: default_2.FC<AgoProviderProps>;
303
+
304
+ export declare type AgoProviderProps = {
305
+ children: default_2.ReactNode;
306
+ } & AgoDeclarativeConfig & (({
307
+ client: AgoClient;
308
+ } & Partial<Record<keyof AgoConfig, never>>) | ({
309
+ client?: never;
310
+ } & AgoConfig));
311
+
312
+ export declare interface AgoRoute {
313
+ name: string;
314
+ path: string;
315
+ description: string;
316
+ }
317
+
318
+ /**
319
+ * Knowledge source citation
320
+ */
321
+ export declare interface AgoSource {
322
+ id: string;
323
+ title: string;
324
+ url?: string;
325
+ }
326
+
327
+ /**
328
+ * Chat input component with send button
329
+ */
330
+ export declare const ChatInput: default_2.FC<ChatInputProps>;
331
+
332
+ export declare interface ChatInputProps {
333
+ onSend: (message: string, files?: File[]) => void;
334
+ disabled?: boolean;
335
+ placeholder?: string;
336
+ allowFiles?: boolean;
337
+ className?: string;
338
+ }
339
+
340
+ /**
341
+ * Pre-built chat widget component
342
+ */
343
+ export declare const ChatWidget: default_2.FC<ChatWidgetProps>;
344
+
345
+ export declare interface ChatWidgetProps {
346
+ /** The AGO client instance. If omitted, reads from AgoProvider context. */
347
+ client?: AgoClient;
348
+ /** Initial conversation ID */
349
+ conversationId?: string;
350
+ /** Widget title */
351
+ title?: string;
352
+ /** Welcome message shown when no messages */
353
+ welcomeMessage?: string;
354
+ /** Input placeholder */
355
+ placeholder?: string;
356
+ /** Enable file attachments */
357
+ allowFiles?: boolean;
358
+ /** Widget height */
359
+ height?: string | number;
360
+ /** URL of a logo to display in the header */
361
+ logoUrl?: string;
362
+ /** Show the agent name above assistant messages. Defaults to `false`. */
363
+ showAgentName?: boolean;
364
+ /**
365
+ * Conversational forms the agent can fill and submit during the chat. Each
366
+ * config is installed as a {@link createFormCollector} (its `update_<name>` /
367
+ * `submit_<name>` functions + dynamic context) for the lifetime of the widget.
368
+ */
369
+ forms?: CreateFormCollectorOptions[];
370
+ /**
371
+ * How clicking a suggested follow-up reply behaves. Defaults to sending the
372
+ * reply as a new user message. Pass a handler to override, or `false` to
373
+ * render the suggestions as non-interactive.
374
+ */
375
+ onFollowUpClick?: ((reply: string) => void) | false;
376
+ /** Additional CSS class */
377
+ className?: string;
378
+ /** Callback when a message is sent */
379
+ onMessageSent?: (content: string) => void;
380
+ /** Callback when a message is received */
381
+ onMessageReceived?: (message: {
382
+ id: string;
383
+ content: string;
384
+ }) => void;
385
+ }
386
+
387
+ /**
388
+ * Single-object function definition — combines name, schema, and handler.
389
+ *
390
+ * ```ts
391
+ * const fn = defineFunction({
392
+ * name: "lookupOrder",
393
+ * description: "Look up an order by ID",
394
+ * parameters: { type: "object", properties: { id: { type: "string" } }, required: ["id"] },
395
+ * handler: async (args) => fetchOrder(args.id as string),
396
+ * });
397
+ * client.registerFunction(fn);
398
+ * ```
399
+ */
400
+ declare interface ClientFunctionDefinition {
401
+ name: string;
402
+ description: string;
403
+ parameters: ClientFunctionSchema["parameters"];
404
+ handler: ClientFunctionHandler;
405
+ }
406
+
407
+ /**
408
+ * Function handler type
409
+ */
410
+ declare type ClientFunctionHandler = (args: Record<string, unknown>) => Promise<unknown> | unknown;
411
+
412
+ declare interface ClientFunctionInvocation {
413
+ invocationId: string;
414
+ functionName: string;
415
+ arguments: Record<string, unknown>;
416
+ conversationId: string;
417
+ }
418
+
419
+ /**
420
+ * Schema for a client-side function that AGO can call
421
+ */
422
+ declare interface ClientFunctionSchema {
423
+ /** Function name (must be unique) */
424
+ name: string;
425
+ /** Description for the LLM to understand when to call this function */
426
+ description: string;
427
+ /** JSON Schema for function parameters */
428
+ parameters: {
429
+ type: "object";
430
+ properties: Record<string, {
431
+ type: string;
432
+ description?: string;
433
+ enum?: string[];
434
+ default?: unknown;
435
+ }>;
436
+ required?: string[];
437
+ };
438
+ }
439
+
440
+ /**
441
+ * A single piece of context the client wants the LLM to know about.
442
+ */
443
+ declare interface ContextEntry {
444
+ /** Human-readable label (e.g. "Order detail", "Current user") */
445
+ name?: string;
446
+ /** Short description of what this context represents */
447
+ description?: string;
448
+ /** Arbitrary structured data the AI should know about */
449
+ data?: Record<string, unknown>;
450
+ }
451
+
452
+ /**
453
+ * Serialised client context sent with each message.
454
+ */
455
+ declare interface ContextSnapshot {
456
+ /** All active context entries keyed by their registration key */
457
+ entries: Record<string, ContextEntry>;
458
+ }
459
+
460
+ /**
461
+ * Conversation/Thread
462
+ */
463
+ export declare interface Conversation {
464
+ id: string;
465
+ title: string;
466
+ lastMessageDate: Date;
467
+ messages?: AgoMessage[];
468
+ }
469
+
470
+ /**
471
+ * Wire one schema into a conversational form: an observable store, an
472
+ * `update_<name>` client function the agent calls to fill fields, a dynamic-context
473
+ * provider that tells the agent what's still missing, and an optional submit.
474
+ *
475
+ * ```ts
476
+ * const order = createFormCollector({
477
+ * name: "order",
478
+ * description: "The order the user wants to place",
479
+ * schema: {
480
+ * type: "object",
481
+ * properties: { product: { type: "string" }, quantity: { type: "number" } },
482
+ * required: ["product", "quantity"],
483
+ * },
484
+ * submit: { via: "client", url: "/api/orders" },
485
+ * });
486
+ * order.install(client);
487
+ * order.store.subscribe((s) => render(s));
488
+ * ```
489
+ */
490
+ export declare function createFormCollector<V = Record<string, unknown>>(options: CreateFormCollectorOptions<V>): FormCollector<V>;
491
+
492
+ export declare interface CreateFormCollectorOptions<V = Record<string, unknown>> {
493
+ /** Short identifier; becomes the `update_<name>` / `submit_<name>` function names. */
494
+ name: string;
495
+ /** What the form is, for the LLM. */
496
+ description: string;
497
+ /** The single source of truth for the form's fields. */
498
+ schema: FormCollectorSchema;
499
+ /** How the completed form is submitted. Default: `false` (collect only). */
500
+ submit?: SubmitConfig<V>;
501
+ /** Pre-filled values. */
502
+ initialValues?: Partial<V>;
503
+ }
504
+
505
+ /**
506
+ * Create a mock AgoClient for testing. Works with any framework.
507
+ *
508
+ * ```ts
509
+ * import { createMockClient } from "@useago/sdk/testing";
510
+ *
511
+ * const mock = createMockClient();
512
+ * mock.__emitEvent("message:complete", someMessage);
513
+ * expect(mock.__callsFor("sendMessage")).toHaveLength(1);
514
+ * ```
515
+ */
516
+ export declare function createMockClient(options?: MockAgoClientOptions): MockAgoClient;
517
+
518
+ /**
519
+ * A function that returns a fresh context entry on demand.
520
+ * Evaluated every time a message is sent — use it to pull data from stores,
521
+ * refs, or any source that isn't captured by React state.
522
+ */
523
+ declare type DynamicContextProvider = () => ContextEntry | null | undefined;
524
+
525
+ export declare interface FormCollector<V = Record<string, unknown>> {
526
+ name: string;
527
+ /** Observable store driving the form UI (read via `useAgoStore`). */
528
+ store: Store<FormCollectorState<V>>;
529
+ /** Client functions to register: `[update]` or `[update, submit]`. */
530
+ functions: ClientFunctionDefinition[];
531
+ /** Dynamic-context key under which the form state is exposed. */
532
+ contextKey: string;
533
+ /** Dynamic-context provider — re-read on every message. */
534
+ contextProvider: () => ContextEntry;
535
+ /** Register the functions + dynamic context on a client. Returns an uninstall fn. */
536
+ install: (client: AgoClient) => () => void;
537
+ /** Submit the form now (e.g. from a UI button). Blocks until required fields are filled. */
538
+ submit: () => Promise<FormSubmitResult>;
539
+ getValues: () => Partial<V>;
540
+ setValues: (patch: Partial<V>) => void;
541
+ reset: () => void;
542
+ }
543
+
544
+ /**
545
+ * JSON-schema shape of a form's fields — identical to a client function's
546
+ * `parameters`, so one schema feeds the store, the update function, and the
547
+ * dynamic context with no second type.
548
+ */
549
+ export declare type FormCollectorSchema = ClientFunctionSchema["parameters"];
550
+
551
+ /** Live state held in the collector's store. */
552
+ export declare interface FormCollectorState<V = Record<string, unknown>> {
553
+ /** Field values collected so far. */
554
+ values: Partial<V>;
555
+ /** Required field names still empty. */
556
+ missing: string[];
557
+ /** True when no required field is missing. */
558
+ complete: boolean;
559
+ /** True once a submit succeeded. */
560
+ submitted: boolean;
561
+ }
562
+
563
+ declare interface FormField {
564
+ type: "string" | "number" | "boolean" | "array";
565
+ title?: string;
566
+ description?: string;
567
+ enum?: string[];
568
+ default?: unknown;
569
+ }
570
+
571
+ /**
572
+ * Form schema for tool calls requiring user input
573
+ */
574
+ declare interface FormSchema {
575
+ type: "object";
576
+ properties: Record<string, FormField>;
577
+ required?: string[];
578
+ }
579
+
580
+ /** Result returned by `submit()` / the generated `submit_<name>` function. */
581
+ export declare interface FormSubmitResult {
582
+ ok: boolean;
583
+ missing?: string[];
584
+ result?: unknown;
585
+ error?: string;
586
+ }
587
+
588
+ /**
589
+ * Renders markdown content with GitHub-flavored markdown support
590
+ * (tables, task lists, strikethrough, autolinks) and inline-styled
591
+ * element renderers. Used by {@link Message} but exported so consumers
592
+ * building a custom chat UI can render assistant content the same way.
593
+ */
594
+ export declare const Markdown: default_2.FC<MarkdownProps>;
595
+
596
+ export declare interface MarkdownProps {
597
+ /** Raw markdown string to render. */
598
+ content: string;
599
+ }
600
+
601
+ export declare const Message: default_2.FC<MessageProps>;
602
+
603
+ export declare interface MessageProps {
604
+ message: AgoMessage;
605
+ className?: string;
606
+ /** Show the agent name above assistant messages. Defaults to `false`. */
607
+ showAgentName?: boolean;
608
+ /**
609
+ * Called when the user clicks a suggested follow-up reply. When omitted the
610
+ * follow-up buttons render but are not interactive (backwards-compatible).
611
+ */
612
+ onFollowUpClick?: (reply: string) => void;
613
+ }
614
+
615
+ declare type MessageStatus = "IN_PROGRESS" | "DONE" | "ERROR" | "TODO" | "CANCELED";
616
+
617
+ declare interface MockAgoClient extends AgoClient {
618
+ /**
619
+ * Simulate a server-pushed event.
620
+ * ```ts
621
+ * mock.__emitEvent("message:complete", { id: "1", content: "hi", ... });
622
+ * ```
623
+ */
624
+ __emitEvent<K extends AgoEventName>(event: K, data: AgoClientEvents[K]): void;
625
+ /**
626
+ * All recorded method calls: `[methodName, ...args][]`
627
+ */
628
+ __calls: Array<{
629
+ method: string;
630
+ args: unknown[];
631
+ }>;
632
+ /**
633
+ * Get calls for a specific method.
634
+ */
635
+ __callsFor(method: string): Array<{
636
+ method: string;
637
+ args: unknown[];
638
+ }>;
639
+ }
640
+
641
+ declare interface MockAgoClientOptions {
642
+ overrides?: Partial<Record<string, MockFn>>;
643
+ }
644
+
645
+ declare type MockFn = (...args: any[]) => any;
646
+
647
+ /**
648
+ * Options for sending a message
649
+ */
650
+ declare interface SendMessageOptions {
651
+ /** Existing conversation ID */
652
+ conversationId?: string;
653
+ /** Override default agent */
654
+ agentId?: string;
655
+ /** File attachments */
656
+ files?: File[];
657
+ }
658
+
659
+ /**
660
+ * A minimal observable store: one value, synchronous subscriptions, and
661
+ * optional persistence via {@link PersistOptions} (localStorage by default).
662
+ *
663
+ * ```ts
664
+ * const store = createStore({ count: 0 });
665
+ * store.subscribe((state) => save(state));
666
+ * store.set({ count: 1 }); // listeners fire synchronously
667
+ *
668
+ * const cart = createStore({ items: [] }, { key: "cart" }); // persisted
669
+ * ```
670
+ */
671
+ declare interface Store<T> {
672
+ /** Current state. */
673
+ get(): T;
674
+ /** Replace the state and notify subscribers synchronously. */
675
+ set(next: T): void;
676
+ /** Register a listener; returns a function that removes it. */
677
+ subscribe(listener: (state: T) => void): () => void;
678
+ }
679
+
680
+ /**
681
+ * Where a completed form is sent.
682
+ * - `"https://..."` (a bare string) — shorthand for `{ via: "client", url }`: the browser
683
+ * POSTs the values to that URL.
684
+ * - `{ via: "client", url }` — same, written out.
685
+ * - `{ via: "client", handler }` — the browser runs your own submit logic.
686
+ * - `{ via: "backend", destination }` — the browser relays the values to the backend,
687
+ * which forwards them to the server-configured destination (URL + secret stay server-side).
688
+ * - `false` — collect only, no submit function.
689
+ */
690
+ export declare type SubmitConfig<V = Record<string, unknown>> = string | {
691
+ via: "client";
692
+ url: string;
693
+ } | {
694
+ via: "client";
695
+ handler: (values: V) => Promise<unknown> | unknown;
696
+ } | {
697
+ via: "backend";
698
+ destination: string;
699
+ } | false;
700
+
701
+ /**
702
+ * Tool call data from SSE stream
703
+ */
704
+ export declare interface ToolCallData {
705
+ id: string;
706
+ type: ToolCallType;
707
+ status: string;
708
+ toolName: string;
709
+ toolDisplayName?: string;
710
+ message?: string;
711
+ formSchema?: FormSchema;
712
+ data?: Record<string, unknown>;
713
+ functionName?: string;
714
+ arguments?: Record<string, unknown>;
715
+ }
716
+
717
+ declare type ToolCallType = "form" | "confirmation_input" | "status_message" | "progress_indicator" | "client_function" | "reasoning" | "mcp_ui_resource";
718
+
719
+ /**
720
+ * Hook to create and manage an AgoClient instance
721
+ */
722
+ export declare function useAgo(config: UseAgoOptions): UseAgoResult;
723
+
724
+ /**
725
+ * Returns the AgoClient from the nearest AgoProvider.
726
+ * Throws if used outside of an AgoProvider.
727
+ */
728
+ export declare function useAgoClient(): AgoClient;
729
+
730
+ /**
731
+ * Declaratively expose a piece of context to the AI agent with every message.
732
+ *
733
+ * Accepts either:
734
+ * - An **object** — sent as-is on every message (re-registered when it changes).
735
+ * Use for data that already lives in React state.
736
+ * - A **function** — called lazily at each message send, so the AI always gets
737
+ * the freshest value. Use for data outside React state (global stores, refs,
738
+ * computed values).
739
+ *
740
+ * A unique key is auto-generated per component instance via `useId()`. Pass an
741
+ * explicit key as second argument to share context across components or
742
+ * reference it from elsewhere.
743
+ *
744
+ * ```tsx
745
+ * // Static object — captured at render time
746
+ * function OrderPage({ order }) {
747
+ * useAgoContext({
748
+ * name: "Order detail",
749
+ * description: "The user is viewing a specific order",
750
+ * data: { orderId: order.id, status: order.status },
751
+ * });
752
+ * }
753
+ *
754
+ * // Dynamic function — evaluated at each sendMessage
755
+ * function App() {
756
+ * const storeRef = useRef(reduxStore);
757
+ * useAgoContext(() => {
758
+ * const state = storeRef.current.getState();
759
+ * return { name: "App shell", data: { userId: state.auth.userId } };
760
+ * });
761
+ * }
762
+ *
763
+ * // With an explicit key
764
+ * useAgoContext({ name: "Sidebar filter", data: { filter } }, "sidebar-filter");
765
+ * ```
766
+ */
767
+ export declare function useAgoContext(entry: ContextEntry, key?: string): void;
768
+
769
+ export declare function useAgoContext(provider: DynamicContextProvider, key?: string): void;
770
+
771
+ /**
772
+ * Declaratively register a client-side function with the AGO agent.
773
+ * Automatically unregisters on unmount and re-registers when deps change.
774
+ *
775
+ * Accepts either a full definition object (preferred) or classic (name, options) args.
776
+ *
777
+ * ```tsx
778
+ * // Preferred — pass the whole definition
779
+ * useAgoFunction({
780
+ * name: "showToast",
781
+ * description: "Show a notification to the user",
782
+ * parameters: { type: "object", properties: { message: { type: "string" } } },
783
+ * handler: async (args) => { toast(args.message); return { shown: true }; },
784
+ * });
785
+ *
786
+ * // Or reuse a pre-defined function
787
+ * const lookupOrder = defineFunction({ name: "lookupOrder", ... });
788
+ * useAgoFunction(lookupOrder);
789
+ *
790
+ * // Classic form
791
+ * useAgoFunction("showToast", { description: "...", parameters: {...}, handler: async (args) => ... });
792
+ * ```
793
+ */
794
+ export declare function useAgoFunction(definition: ClientFunctionDefinition): void;
795
+
796
+ export declare function useAgoFunction(name: string, options: UseAgoFunctionOptions): void;
797
+
798
+ export declare interface UseAgoFunctionOptions {
799
+ description: string;
800
+ parameters: {
801
+ type: "object";
802
+ properties: Record<string, {
803
+ type: string;
804
+ description?: string;
805
+ enum?: string[];
806
+ default?: unknown;
807
+ }>;
808
+ required?: string[];
809
+ };
810
+ handler: ClientFunctionHandler;
811
+ }
812
+
813
+ /**
814
+ * Declaratively register navigation routes with the AGO agent.
815
+ * Wraps `registerNavigationFunction` with React lifecycle management.
816
+ *
817
+ * ```tsx
818
+ * const navigate = useNavigate();
819
+ * useAgoNavigation(navigate, [
820
+ * { name: "dashboard", path: "/dashboard", description: "Main dashboard" },
821
+ * { name: "settings", path: "/settings", description: "User settings" },
822
+ * ]);
823
+ * ```
824
+ */
825
+ export declare function useAgoNavigation(navigate: (path: string) => void, routes: AgoRoute[]): void;
826
+
827
+ export declare interface UseAgoOptions extends AgoConfig {
828
+ }
829
+
830
+ export declare interface UseAgoResult {
831
+ /** The AGO client instance */
832
+ client: AgoClient;
833
+ /** Whether the client is ready */
834
+ isReady: boolean;
835
+ }
836
+
837
+ /**
838
+ * Read a framework-agnostic AGO store (`createStore`) reactively in React.
839
+ *
840
+ * Re-renders the component whenever the store's value changes. Mutate the store
841
+ * via `store.set(...)`, not the value returned here.
842
+ *
843
+ * ```tsx
844
+ * const cart = createStore({ items: [] as string[] });
845
+ *
846
+ * function CartBadge() {
847
+ * const { items } = useAgoStore(cart);
848
+ * return <span>{items.length}</span>;
849
+ * }
850
+ * ```
851
+ */
852
+ export declare function useAgoStore<T>(store: Store<T>): T;
853
+
854
+ /**
855
+ * All-in-one hook for building a custom chat UI.
856
+ * Composes useMessages + useConversation.
857
+ *
858
+ * ```tsx
859
+ * const { messages, sendMessage, conversations, selectConversation } = useChat();
860
+ * ```
861
+ */
862
+ export declare function useChat(options?: UseChatOptions): UseChatResult;
863
+
864
+ export declare interface UseChatOptions {
865
+ /** AgoClient instance. If omitted, reads from AgoProvider context. */
866
+ client?: AgoClient;
867
+ /** Initial conversation ID to load */
868
+ conversationId?: string;
869
+ /** Auto-load conversation list on mount (default: true) */
870
+ autoLoad?: boolean;
871
+ }
872
+
873
+ export declare interface UseChatResult {
874
+ /** Messages in the current conversation */
875
+ messages: AgoMessage[];
876
+ /** Whether a message is being sent/streamed */
877
+ isLoading: boolean;
878
+ /** Current error */
879
+ error: Error | null;
880
+ /** Send a message */
881
+ sendMessage: (content: string, files?: File[]) => Promise<AgoMessage | null>;
882
+ /** Clear current messages */
883
+ clearMessages: () => void;
884
+ /** Current conversation ID */
885
+ conversationId: string | undefined;
886
+ /** All conversations */
887
+ conversations: Conversation[];
888
+ /** Currently selected conversation */
889
+ currentConversation: Conversation | null;
890
+ /** Whether conversations are loading */
891
+ isConversationsLoading: boolean;
892
+ /** Select a conversation by ID */
893
+ selectConversation: (conversationId: string) => Promise<void>;
894
+ /** Start a new conversation */
895
+ startNewConversation: () => void;
896
+ /** Refresh conversations list */
897
+ refreshConversations: () => Promise<void>;
898
+ }
899
+
900
+ /**
901
+ * Hook to manage conversations
902
+ */
903
+ export declare function useConversation({ client: clientProp, autoLoad, }?: UseConversationOptions): UseConversationResult;
904
+
905
+ export declare interface UseConversationOptions {
906
+ /** The AGO client instance. If omitted, reads from AgoProvider context. */
907
+ client?: AgoClient;
908
+ /** Auto-load conversations on mount */
909
+ autoLoad?: boolean;
910
+ }
911
+
912
+ export declare interface UseConversationResult {
913
+ /** List of conversations */
914
+ conversations: Conversation[];
915
+ /** Currently selected conversation */
916
+ currentConversation: Conversation | null;
917
+ /** Whether conversations are loading */
918
+ isLoading: boolean;
919
+ /** Current error, if any */
920
+ error: Error | null;
921
+ /** Select a conversation */
922
+ selectConversation: (conversationId: string) => Promise<void>;
923
+ /** Clear current conversation (start new) */
924
+ startNewConversation: () => void;
925
+ /** Refresh conversations list */
926
+ refreshConversations: () => Promise<void>;
927
+ }
928
+
929
+ /**
930
+ * React wiring for {@link createFormCollector}: registers the collector's client
931
+ * functions + dynamic context on mount, removes them on unmount, and returns the
932
+ * live store state.
933
+ *
934
+ * The collector is recreated only when `name`, the schema, or the submit target
935
+ * changes. Keep the schema and submit object stable (declare them outside render
936
+ * or memoize them) so an inline `handler` isn't captured stale.
937
+ *
938
+ * ```tsx
939
+ * const order = useFormCollector({
940
+ * name: "order",
941
+ * description: "The order the user wants to place",
942
+ * schema: {
943
+ * type: "object",
944
+ * properties: { product: { type: "string" }, quantity: { type: "number" } },
945
+ * required: ["product", "quantity"],
946
+ * },
947
+ * submit: { via: "backend", destination: "order_webhook" },
948
+ * });
949
+ *
950
+ * return (
951
+ * <div>
952
+ * {order.state.missing.length > 0
953
+ * ? `Still need: ${order.state.missing.join(", ")}`
954
+ * : "Ready to submit"}
955
+ * </div>
956
+ * );
957
+ * ```
958
+ */
959
+ export declare function useFormCollector<V = Record<string, unknown>>(options: CreateFormCollectorOptions<V>): UseFormCollectorResult<V>;
960
+
961
+ export declare interface UseFormCollectorResult<V = Record<string, unknown>> extends FormCollector<V> {
962
+ /** Live form state from the collector's store — re-renders on every change. */
963
+ state: FormCollectorState<V>;
964
+ }
965
+
966
+ /**
967
+ * Hook to manage messages in a conversation
968
+ */
969
+ export declare function useMessages({ client: clientProp, conversationId: initialConversationId, }?: UseMessagesOptions): UseMessagesResult;
970
+
971
+ export declare interface UseMessagesOptions {
972
+ /** The AGO client instance. If omitted, reads from AgoProvider context. */
973
+ client?: AgoClient;
974
+ /** Conversation ID to load messages for */
975
+ conversationId?: string;
976
+ }
977
+
978
+ export declare interface UseMessagesResult {
979
+ /** List of messages */
980
+ messages: AgoMessage[];
981
+ /** Whether a message is being sent */
982
+ isLoading: boolean;
983
+ /** Current error, if any */
984
+ error: Error | null;
985
+ /** Send a new message */
986
+ sendMessage: (content: string, files?: File[]) => Promise<AgoMessage | null>;
987
+ /** Clear messages */
988
+ clearMessages: () => void;
989
+ /** Current conversation ID */
990
+ conversationId: string | undefined;
991
+ }
992
+
993
+ /**
994
+ * Returns the AgoClient from context, or null if no provider exists.
995
+ * Use this when client access is optional.
996
+ */
997
+ export declare function useOptionalAgoClient(): AgoClient | null;
998
+
999
+ export { }