@useago/sdk 1.9.0 → 1.12.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. package/CHANGELOG.md +104 -0
  2. package/README.md +53 -0
  3. package/dist/angular.cjs +1 -1
  4. package/dist/angular.d.cts +313 -0
  5. package/dist/angular.d.ts +313 -0
  6. package/dist/angular.js +1 -1
  7. package/dist/{createConversationSession-BaaXBQ5b.js → createConversationSession-B1Qn-y0I.js} +1 -1
  8. package/dist/{createConversationSession-CU0b-t1W.cjs → createConversationSession-B3v_xOU7.cjs} +1 -1
  9. package/dist/{createFormCollector-DfN1xZBy.cjs → createFormCollector-FvwDOqnV.cjs} +1 -1
  10. package/dist/{createFormCollector-Cf7kGhCB.js → createFormCollector-m79zk_NA.js} +1 -1
  11. package/dist/createMockClient-BEOXI8yW.cjs +1 -0
  12. package/dist/{createMockClient-5YF-ZbVu.js → createMockClient-Beao82tu.js} +15 -3
  13. package/dist/devtools.d.cts +313 -0
  14. package/dist/devtools.d.ts +313 -0
  15. package/dist/index.cjs +1 -1
  16. package/dist/index.d.cts +389 -4
  17. package/dist/index.d.ts +389 -4
  18. package/dist/index.js +118 -114
  19. package/dist/react.cjs +1 -1
  20. package/dist/react.d.cts +313 -0
  21. package/dist/react.d.ts +313 -0
  22. package/dist/react.js +8 -6
  23. package/dist/sheetController-BThJRtOu.cjs +1 -0
  24. package/dist/sheetController-aEKXIvjk.js +343 -0
  25. package/dist/testing.cjs +1 -1
  26. package/dist/testing.d.cts +313 -0
  27. package/dist/testing.d.ts +313 -0
  28. package/dist/testing.js +1 -1
  29. package/dist/types-Ct1hlKwg.js +2408 -0
  30. package/dist/types-mcW8vB1U.cjs +10 -0
  31. package/dist/vue.cjs +1 -1
  32. package/dist/vue.d.cts +505 -0
  33. package/dist/vue.d.ts +505 -0
  34. package/dist/vue.js +1 -1
  35. package/dist/widget.cjs +6 -4
  36. package/dist/widget.d.cts +585 -2
  37. package/dist/widget.d.ts +585 -2
  38. package/dist/widget.js +3985 -995
  39. package/llms-full.txt +125 -6
  40. package/package.json +1 -1
  41. package/dist/createMockClient-BZbOe-23.cjs +0 -1
  42. package/dist/sheetController-CBUVOroo.js +0 -205
  43. package/dist/sheetController-DY-sC13T.cjs +0 -1
  44. package/dist/types-CPga11Of.js +0 -2068
  45. package/dist/types-D3YQl1jx.cjs +0 -9
package/dist/react.d.cts CHANGED
@@ -110,6 +110,7 @@ declare class AgoClient {
110
110
  private contextRegistry;
111
111
  private eventEmitter;
112
112
  private activityLedger;
113
+ private errorWatcher;
113
114
  private lastSentPageState;
114
115
  private config;
115
116
  /** Conversations already warned about an empty reply (one warning each). */
@@ -279,6 +280,26 @@ declare class AgoClient {
279
280
  * `SSEHandler.parseToolCall` so persisted and streamed tool calls match.
280
281
  */
281
282
  private static mapPersistedToolCalls;
283
+ /**
284
+ * The tenant's SDK configuration (`GET /api/sdk/v1/config`): per-permission
285
+ * agents, the ticket form the agent's `ago_ticketing` tool opens, and the
286
+ * file-attachment flag. The vanilla widget fetches it once, when a ticket
287
+ * form first appears in a conversation.
288
+ */
289
+ getConfig(): Promise<SdkConfig>;
290
+ /**
291
+ * The dashboard's home screen content. A starter card shows its
292
+ * `description` and sends its `initial_message`; one with neither is
293
+ * unusable and is dropped rather than rendered as an empty card.
294
+ */
295
+ private static mapHomePage;
296
+ private static mapTicketForm;
297
+ /**
298
+ * Create a support ticket (`POST /api/sdk/v1/tickets`, multipart). This is
299
+ * what the ticket form in the conversation does before it completes the
300
+ * `form` tool call with {@link submitToolCallForm}.
301
+ */
302
+ createTicket(input: CreateTicketInput): Promise<CreateTicketResult>;
282
303
  /**
283
304
  * Get messages for a conversation
284
305
  */
@@ -537,6 +558,15 @@ declare class AgoClient {
537
558
  /* Excluded from this release type: emitProactiveEvent */
538
559
  /* Excluded from this release type: getHttp */
539
560
  /* Excluded from this release type: getConfiguredAgent */
561
+ /**
562
+ * How the SDK identifies the visitor: the configured `userEmail`, and
563
+ * whether a `userJwt` is set. The ticket form asks for an email when it has
564
+ * neither.
565
+ */
566
+ getUserIdentity(): {
567
+ email?: string;
568
+ hasJwt: boolean;
569
+ };
540
570
  /**
541
571
  * Enable automatic capture of the current browser page (URL + title).
542
572
  * Injected as a dynamic context entry named `browser-page`.
@@ -559,6 +589,26 @@ declare class AgoClient {
559
589
  private addActivity;
560
590
  private recordAgentAction;
561
591
  private registerActivityContext;
592
+ /**
593
+ * Start capturing the page's JavaScript errors (uncaught exceptions,
594
+ * unhandled rejections, `console.error` calls, {@link reportError}) and send
595
+ * the recent ones as the `errors:recent` context entry on every message.
596
+ * Same as setting `errorWatcher` in the config. Calling it again replaces
597
+ * the watcher (and its options); the captured errors are not kept.
598
+ */
599
+ enableErrorWatcher(options?: ErrorWatcherOptions): void;
600
+ /** Stop capturing errors and drop the `errors:recent` context entry. */
601
+ disableErrorWatcher(): void;
602
+ /**
603
+ * Record an error the app caught itself (React error boundary, Vue
604
+ * `errorHandler`, Angular `ErrorHandler`, a try/catch) so the agent sees it
605
+ * like an uncaught one. No-op unless the error watcher is enabled. `context`
606
+ * is size-clamped before it is stored; keep it small and free of secrets.
607
+ */
608
+ reportError(error: unknown, context?: Record<string, unknown>): void;
609
+ /** Errors the watcher currently holds, oldest first (a copy). Empty when disabled. */
610
+ getRecentErrors(): CapturedError[];
611
+ clearErrors(): void;
562
612
  /**
563
613
  * Subscribe to an event
564
614
  */
@@ -753,6 +803,12 @@ declare interface AgoClientEvents {
753
803
  };
754
804
  /** A user- or agent-action was recorded into the activity ledger. */
755
805
  "activity:recorded": ActivityEntry;
806
+ /**
807
+ * The error watcher captured a JavaScript error (uncaught exception,
808
+ * unhandled rejection, `console.error` call, or `reportError`). Fires on
809
+ * repeats too, with the updated `count`. Requires `errorWatcher` in the config.
810
+ */
811
+ "error:captured": CapturedError;
756
812
  }
757
813
 
758
814
  /**
@@ -773,6 +829,8 @@ export declare interface AgoConfig {
773
829
  userEmail?: string;
774
830
  /** JWT token for authenticated users */
775
831
  userJwt?: string;
832
+ /** User metadata sent with messages. Use null to stop sending defaults. Not an authentication credential. */
833
+ metadata?: Record<string, unknown> | null;
776
834
  /** Enable debug logging */
777
835
  debug?: boolean;
778
836
  /**
@@ -832,6 +890,18 @@ export declare interface AgoConfig {
832
890
  * default otherwise.
833
891
  */
834
892
  proactive?: ProactiveOptions;
893
+ /**
894
+ * Capture the page's JavaScript errors as agent context. When set, the SDK
895
+ * listens for uncaught exceptions and unhandled promise rejections, wraps
896
+ * `console.error` (calling through; restored on `destroy`), and sends the
897
+ * recent errors (deduplicated, capped, pruned after 10 min) as the
898
+ * `errors:recent` context entry on every message. `true` uses the defaults;
899
+ * pass {@link ErrorWatcherOptions} to tune the caps or add a `filter` that
900
+ * redacts messages. Off by default: error messages can carry PII or internal
901
+ * URLs, so enabling it is the host's call. Errors also feed the proactive
902
+ * mode's `jsErrors` signal. See `client.reportError()` for caught errors.
903
+ */
904
+ errorWatcher?: boolean | ErrorWatcherOptions;
835
905
  }
836
906
 
837
907
  /**
@@ -1100,6 +1170,32 @@ declare type AgoStateSetResult = {
1100
1170
  result: "unchanged";
1101
1171
  };
1102
1172
 
1173
+ /** One JavaScript error captured on the page (deduplicated, see `count`). */
1174
+ declare interface CapturedError {
1175
+ type: CapturedErrorType;
1176
+ /** Error message, truncated to 500 chars. */
1177
+ message: string;
1178
+ /** Script URL the error came from, without its query string. */
1179
+ source?: string;
1180
+ line?: number;
1181
+ col?: number;
1182
+ /** Leading stack frames, truncated (see `maxStackChars`). */
1183
+ stack?: string;
1184
+ /** Pathname at capture time. */
1185
+ route: string;
1186
+ /** Epoch ms of the first occurrence. */
1187
+ firstAt: number;
1188
+ /** Epoch ms of the most recent occurrence. */
1189
+ lastAt: number;
1190
+ /** How many times this same error (type + message + source + line) fired. */
1191
+ count: number;
1192
+ /** App-provided context, manual reports only (size-clamped). */
1193
+ context?: Record<string, unknown>;
1194
+ }
1195
+
1196
+ /** How an error reached the watcher. */
1197
+ declare type CapturedErrorType = "error" | "unhandledrejection" | "console" | "manual";
1198
+
1103
1199
  /**
1104
1200
  * Chat input component with send button
1105
1201
  */
@@ -1434,6 +1530,30 @@ export declare interface CreateFormCollectorOptions<V = Record<string, unknown>>
1434
1530
  */
1435
1531
  export declare function createMockClient(options?: MockAgoClientOptions): MockAgoClient;
1436
1532
 
1533
+ /** Input of `AgoClient.createTicket` (`POST /api/sdk/v1/tickets`). */
1534
+ declare interface CreateTicketInput {
1535
+ subject: string;
1536
+ body: string;
1537
+ priority?: string;
1538
+ typology?: string;
1539
+ /** Conversation the ticket is filed from. */
1540
+ conversationId?: string;
1541
+ /** Reporter email, for a visitor the SDK does not otherwise identify. */
1542
+ email?: string;
1543
+ customFields?: Array<{
1544
+ id: string;
1545
+ value: string;
1546
+ }>;
1547
+ files?: File[];
1548
+ ticketFormId?: string;
1549
+ }
1550
+
1551
+ /** Response of `AgoClient.createTicket`. */
1552
+ declare interface CreateTicketResult {
1553
+ id: string;
1554
+ url?: string;
1555
+ }
1556
+
1437
1557
  export declare const DEFAULT_MESSAGE_FEEDBACK_LABELS: MessageFeedbackLabels;
1438
1558
 
1439
1559
  /**
@@ -1463,6 +1583,23 @@ declare interface ElementProps {
1463
1583
  attrs: Record<string, string | null>;
1464
1584
  }
1465
1585
 
1586
+ declare interface ErrorWatcherOptions {
1587
+ /** Max distinct errors kept. Oldest dropped first. Default 10. */
1588
+ maxErrors?: number;
1589
+ /**
1590
+ * Errors older than this are pruned when the buffer is read, so a crash from
1591
+ * an hour ago does not confuse the agent. Default 600 000 (10 min).
1592
+ */
1593
+ maxAgeMs?: number;
1594
+ /** Max chars of stack kept per error. Default 2000. */
1595
+ maxStackChars?: number;
1596
+ /**
1597
+ * Redact or drop an error before it is stored. Return the (possibly edited)
1598
+ * error to keep it, `null` to drop it. Runs on every capture, so keep it cheap.
1599
+ */
1600
+ filter?: (error: CapturedError) => CapturedError | null;
1601
+ }
1602
+
1466
1603
  /** The four values of {@link FeedbackReason}, in dashboard order. */
1467
1604
  export declare const FEEDBACK_REASONS: readonly FeedbackReason[];
1468
1605
 
@@ -2050,6 +2187,12 @@ declare interface ProactiveTriggerWhen {
2050
2187
  pageState?: Partial<Record<string, unknown>>;
2051
2188
  /** Min rage-click bursts on the current route. */
2052
2189
  rageClicks?: number;
2190
+ /**
2191
+ * Min JavaScript errors captured on the current route. Needs the client's
2192
+ * `errorWatcher` enabled; without it the count stays at 0 and the matcher
2193
+ * never passes.
2194
+ */
2195
+ jsErrors?: number;
2053
2196
  /** Min A→B→A→B route oscillations this session. */
2054
2197
  routeBounces?: number;
2055
2198
  /** Per-field minimum error counts (field NAME → min count). */
@@ -2067,10 +2210,69 @@ declare type ResumeGate = (info: {
2067
2210
  messageId: string;
2068
2211
  }) => Promise<void> | void;
2069
2212
 
2213
+ /** Response of `GET /api/sdk/v1/config` (see `AgoClient.getConfig`). */
2214
+ declare interface SdkConfig {
2215
+ permissions: SdkPermissionConfig[];
2216
+ proactive: {
2217
+ enabled: boolean;
2218
+ };
2219
+ }
2220
+
2221
+ /** The dashboard's home screen content (title, subtitle, starter cards). */
2222
+ declare interface SdkHomePageConfig {
2223
+ title?: string;
2224
+ /** Markdown. */
2225
+ subtitle?: string;
2226
+ starters: SdkHomeStarter[];
2227
+ widgetStarter?: SdkWidgetStarter;
2228
+ }
2229
+
2230
+ /**
2231
+ * A conversation starter card configured in the AGO dashboard. `label` is what
2232
+ * the card shows; clicking it sends `message`.
2233
+ */
2234
+ declare interface SdkHomeStarter {
2235
+ id: string;
2236
+ /** The card's text (the starter's `description` in the dashboard). */
2237
+ label: string;
2238
+ /** What is sent when the card is clicked. */
2239
+ message: string;
2240
+ /** Answer with this agent instead of the configured default. */
2241
+ agentId?: string;
2242
+ }
2243
+
2244
+ /** One permission's configuration in {@link SdkConfig}. */
2245
+ declare interface SdkPermissionConfig {
2246
+ id?: string;
2247
+ name?: string;
2248
+ displayName?: string;
2249
+ agents: Array<{
2250
+ id: string;
2251
+ name?: string;
2252
+ }>;
2253
+ ticketForm?: TicketForm;
2254
+ /** Home screen content, when the tenant configured one. */
2255
+ homePage?: SdkHomePageConfig;
2256
+ fileAttachmentsEnabled: boolean;
2257
+ voiceEnabled: boolean;
2258
+ }
2259
+
2260
+ /**
2261
+ * The starter the dashboard sends by itself on a fresh visit, before the
2262
+ * visitor types anything.
2263
+ */
2264
+ declare interface SdkWidgetStarter {
2265
+ id: string;
2266
+ message: string;
2267
+ agentId?: string;
2268
+ }
2269
+
2070
2270
  /**
2071
2271
  * Options for sending a message
2072
2272
  */
2073
2273
  declare interface SendMessageOptions {
2274
+ /** Replaces config.metadata for this message; null omits metadata for this message. */
2275
+ metadata?: Record<string, unknown> | null;
2074
2276
  /** Existing conversation ID */
2075
2277
  conversationId?: string;
2076
2278
  /** Override default agent */
@@ -2186,6 +2388,12 @@ declare interface SignalsSnapshot {
2186
2388
  idleMs: number;
2187
2389
  /** Rage-click bursts detected on the current route. */
2188
2390
  rageClicks: number;
2391
+ /**
2392
+ * JavaScript errors captured on the current route (count only; the messages
2393
+ * travel in `client_context` under `errors:recent`). Always `0` unless the
2394
+ * client has `errorWatcher` enabled.
2395
+ */
2396
+ jsErrors: number;
2189
2397
  /**
2190
2398
  * A→B→A→B route oscillations detected in the recent route sequence. Rolling
2191
2399
  * session counter (cross-route by nature); trigger cooldowns and dismissal
@@ -2244,6 +2452,13 @@ declare interface SSEChunkData {
2244
2452
  follow_up_replies?: string[];
2245
2453
  satisfaction_feedback?: unknown;
2246
2454
  ask_to_talk_to_human?: boolean;
2455
+ allowed_to_create_ticket?: boolean;
2456
+ ticket?: ToolCallTicketPrefill;
2457
+ mode?: "form" | "embed";
2458
+ ticket_form_id?: string;
2459
+ embed_html?: string;
2460
+ embed_description?: string;
2461
+ display_mode?: "collapsible" | "display" | "both";
2247
2462
  /** Tool call ids still awaiting a client result, sent with the final `WAITING_CLIENT` event. */
2248
2463
  waiting_tool_call_ids?: string[];
2249
2464
  }
@@ -2318,12 +2533,82 @@ export declare type SubmitConfig<V = Record<string, unknown>> = string | {
2318
2533
  declare interface SubmitToolCallResult {
2319
2534
  status: string;
2320
2535
  result?: unknown;
2536
+ /** Set when `status` is `"error"`. */
2537
+ error?: string;
2538
+ /** The ticket a ticketing `form` tool call resolved to, when it did. */
2539
+ ticket?: {
2540
+ ticket_id: string;
2541
+ ticket_url?: string;
2542
+ [key: string]: unknown;
2543
+ };
2321
2544
  resume?: {
2322
2545
  message_id: string;
2323
2546
  ready: boolean;
2324
2547
  };
2325
2548
  }
2326
2549
 
2550
+ /** A custom field of a ticket form. */
2551
+ declare interface TicketField {
2552
+ id: string;
2553
+ /** The key the ticketing backend expects; used as the submit key when set. */
2554
+ externalId?: string;
2555
+ title?: string;
2556
+ /** Field kind, e.g. `"text"`, `"checkbox"`, `"tagger"`. */
2557
+ type?: string;
2558
+ required: boolean;
2559
+ /** Carried in the submission but never shown. */
2560
+ hidden: boolean;
2561
+ active?: boolean;
2562
+ /** Bypass progressive disclosure, while still respecting conditions. */
2563
+ alwaysVisible?: boolean;
2564
+ regexpForValidation?: string;
2565
+ position: number;
2566
+ /** Non-empty turns the field into a select. */
2567
+ options: TicketFieldOption[];
2568
+ /** Show this field only when the parent field holds `conditionalFieldValue`. */
2569
+ conditionalFieldId?: string;
2570
+ /** Legacy comma-separated condition values. */
2571
+ conditionalFieldValue?: string;
2572
+ /** Takes precedence over conditionalFieldValue when non-empty. */
2573
+ conditionalFieldValues?: string[];
2574
+ }
2575
+
2576
+ /** An option of a ticket form field (`GET /config` → `ticket_form.fields[].options[]`). */
2577
+ declare interface TicketFieldOption {
2578
+ id: string;
2579
+ /** Label shown to the user. */
2580
+ name?: string;
2581
+ /** Value submitted. Falls back to `name` when absent. */
2582
+ value?: string;
2583
+ /** Preselected when the form opens. */
2584
+ default: boolean;
2585
+ /** A note shown under the field once this option is picked. */
2586
+ message?: string;
2587
+ messageType: "info" | "warning" | "danger";
2588
+ position?: number;
2589
+ group?: string;
2590
+ noDisplay?: boolean;
2591
+ conditionalFieldId?: string;
2592
+ /** Available when the parent matches any of these values. */
2593
+ conditionalFieldValues?: string[];
2594
+ }
2595
+
2596
+ /** The ticket form an agent's `ago_ticketing` tool opens in the conversation. */
2597
+ declare interface TicketForm {
2598
+ id: string;
2599
+ name?: string;
2600
+ /** `"form"` renders the SDK's own fields; `"embed"` hosts third-party HTML. */
2601
+ mode: "form" | "embed";
2602
+ showSubject: boolean;
2603
+ showBody: boolean;
2604
+ showPriority: boolean;
2605
+ showTypology: boolean;
2606
+ priorityTypologies?: string[];
2607
+ successMessageText?: string;
2608
+ successMessageUrlLabel?: string;
2609
+ fields: TicketField[];
2610
+ }
2611
+
2327
2612
  /**
2328
2613
  * Tool call data from SSE stream
2329
2614
  */
@@ -2338,6 +2623,34 @@ export declare interface ToolCallData {
2338
2623
  data?: Record<string, unknown>;
2339
2624
  functionName?: string;
2340
2625
  arguments?: Record<string, unknown>;
2626
+ /**
2627
+ * Where the hosted widget shows the call: in the collapsible "reasoning"
2628
+ * section, in the message body, or both. Absent means collapsible only.
2629
+ */
2630
+ displayMode?: "collapsible" | "display" | "both";
2631
+ /** The user asked to talk to a human. */
2632
+ askToTalkToHuman?: boolean;
2633
+ /** `false` when the tenant blocks ticket creation for this visitor. */
2634
+ allowedToCreateTicket?: boolean;
2635
+ /** Fields the agent pre-filled from the conversation. */
2636
+ ticket?: ToolCallTicketPrefill;
2637
+ /** `"embed"` hosts third-party HTML (`embedHtml`); otherwise the SDK's form. */
2638
+ mode?: "form" | "embed";
2639
+ ticketFormId?: string;
2640
+ embedHtml?: string;
2641
+ embedDescription?: string;
2642
+ }
2643
+
2644
+ /** The ticket the agent pre-filled on a ticketing `form` tool call. */
2645
+ declare interface ToolCallTicketPrefill {
2646
+ subject?: string;
2647
+ body?: string;
2648
+ typology?: string;
2649
+ priority?: string;
2650
+ tag?: string;
2651
+ products?: string[];
2652
+ /** Keyed by the field's external id, or a lowercased, underscored title. */
2653
+ custom_fields?: Record<string, string>;
2341
2654
  }
2342
2655
 
2343
2656
  declare type ToolCallType = "form" | "confirmation_input" | "status_message" | "progress_indicator" | "client_function" | "reasoning" | "mcp_ui_resource";