@useago/sdk 1.5.0 → 1.5.3

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 (46) hide show
  1. package/CHANGELOG.md +48 -0
  2. package/dist/AgoClient-BGkFSNZF.cjs +8 -0
  3. package/dist/AgoClient-CW-BLT1_.js +1542 -0
  4. package/dist/angular.cjs +1 -1
  5. package/dist/angular.d.cts +390 -2
  6. package/dist/angular.d.ts +390 -2
  7. package/dist/angular.js +1 -1
  8. package/dist/createConversationSession-BCb0D6bt.cjs +1 -0
  9. package/dist/{createConversationSession-DCSWShaW.js → createConversationSession-C7cnnWKW.js} +3 -3
  10. package/dist/createFormCollector-iCDwAwYJ.js +279 -0
  11. package/dist/createFormCollector-t_fGyuTD.cjs +1 -0
  12. package/dist/createMockClient-Br0TWgLO.js +97 -0
  13. package/dist/createMockClient-BwNLPjeT.cjs +1 -0
  14. package/dist/devtools.d.cts +390 -2
  15. package/dist/devtools.d.ts +390 -2
  16. package/dist/helpers.d.cts +5 -0
  17. package/dist/helpers.d.ts +5 -0
  18. package/dist/index.cjs +1 -1
  19. package/dist/index.d.cts +605 -4
  20. package/dist/index.d.ts +605 -4
  21. package/dist/index.js +95 -90
  22. package/dist/react.cjs +3 -3
  23. package/dist/react.d.cts +561 -4
  24. package/dist/react.d.ts +561 -4
  25. package/dist/react.js +849 -517
  26. package/dist/testing.cjs +1 -1
  27. package/dist/testing.d.cts +390 -2
  28. package/dist/testing.d.ts +390 -2
  29. package/dist/testing.js +1 -1
  30. package/dist/vue.cjs +1 -1
  31. package/dist/vue.d.cts +411 -2
  32. package/dist/vue.d.ts +411 -2
  33. package/dist/vue.js +133 -110
  34. package/dist/widget.cjs +4 -4
  35. package/dist/widget.d.cts +387 -2
  36. package/dist/widget.d.ts +387 -2
  37. package/dist/widget.js +437 -423
  38. package/llms-full.txt +74 -2
  39. package/package.json +1 -1
  40. package/dist/AgoClient-q39FIjSC.js +0 -912
  41. package/dist/AgoClient-wcPRaIMs.cjs +0 -8
  42. package/dist/createConversationSession-BBYfQLLS.cjs +0 -1
  43. package/dist/createFormCollector-eimwwWEi.cjs +0 -1
  44. package/dist/createFormCollector-sB6rMccD.js +0 -299
  45. package/dist/createMockClient-BUc9PSbo.js +0 -79
  46. package/dist/createMockClient-CjdCqixj.cjs +0 -1
package/dist/index.d.ts CHANGED
@@ -69,8 +69,20 @@ export declare class AgoClient {
69
69
  private warnedEmptyConversations;
70
70
  /** Paused turns awaiting auto-resume, keyed by assistant message id. */
71
71
  private pendingResumes;
72
+ /**
73
+ * Client function invocations held pending user approval, keyed by
74
+ * invocationId (the tool-call id). Populated when {@link requiresApproval}
75
+ * matches; drained by {@link approveFunction} / {@link rejectFunction}.
76
+ */
77
+ private pendingApprovals;
72
78
  /** App-provided gate deciding WHEN a paused turn resumes (see {@link registerResumeGate}). */
73
79
  private resumeGate;
80
+ /**
81
+ * Proactive-mode controller, set when the client was created with
82
+ * `proactive` options or when `createAgoProactive(client, opts)` was called.
83
+ * `null` otherwise.
84
+ */
85
+ proactive: ProactiveController | null;
74
86
  constructor(config: AgoConfig);
75
87
  /**
76
88
  * Send a message and receive a streaming response
@@ -119,6 +131,24 @@ export declare class AgoClient {
119
131
  */
120
132
  private maybeFlagEmptyReply;
121
133
  private handleClientFunctionInvocation;
134
+ /**
135
+ * Whether a client function invocation must wait for explicit user approval.
136
+ * True when the {@link AgoConfig.approvalPolicy} returns true OR the function
137
+ * was registered with `requiresApproval: true` — the two OR together.
138
+ */
139
+ private requiresApproval;
140
+ /**
141
+ * Approve a client function call held by the approval gate: run it, submit its
142
+ * result, and let the paused turn resume. No-op if the invocation is unknown
143
+ * (already handled, or never gated).
144
+ */
145
+ approveFunction(invocationId: string): Promise<void>;
146
+ /**
147
+ * Reject a client function call held by the approval gate: submit a rejection
148
+ * result so the agent sees the user declined, and let the paused turn resume
149
+ * (the agent decides what to do next). No-op if the invocation is unknown.
150
+ */
151
+ rejectFunction(invocationId: string): Promise<void>;
122
152
  /**
123
153
  * Get list of conversations
124
154
  */
@@ -148,8 +178,10 @@ export declare class AgoClient {
148
178
  *
149
179
  * Opt-in on purpose — re-running functions on reload can be surprising (e.g. a
150
180
  * navigation function would navigate again), so the app decides. Returns the
151
- * resumed turn's final message, or `null` when there was nothing to resume or
152
- * some waiting function is not registered on this page.
181
+ * resumed turn's final message, or `null` when there was nothing to resume,
182
+ * some waiting function is not registered on this page, or a waiting call is
183
+ * gated by the approval policy (it is held for `approveFunction` /
184
+ * `rejectFunction` and the turn stays paused, exactly as on the live stream).
153
185
  */
154
186
  resumePendingClientFunctions(conversation: Conversation): Promise<AgoMessage | null>;
155
187
  /**
@@ -221,6 +253,14 @@ export declare class AgoClient {
221
253
  * Get all registered function schemas
222
254
  */
223
255
  getRegisteredFunctions(): ClientFunctionSchema[];
256
+ /**
257
+ * Execute a registered client function locally, through the same
258
+ * FunctionRegistry path (result-size guard, error wrapping) as agent-invoked
259
+ * calls. Used by proactive nudge actions, where the user's explicit click on
260
+ * the action button constitutes the approval — nothing is submitted to the
261
+ * backend (there is no tool call to answer).
262
+ */
263
+ executeClientFunction(name: string, args: Record<string, unknown>): Promise<unknown>;
224
264
  /**
225
265
  * Register a navigation function that lets AGO navigate users to different pages.
226
266
  *
@@ -322,6 +362,9 @@ export declare class AgoClient {
322
362
  */
323
363
  notifyContextChanged(): void;
324
364
  /* Excluded from this release type: emitFormEvent */
365
+ /* Excluded from this release type: emitProactiveEvent */
366
+ /* Excluded from this release type: getHttp */
367
+ /* Excluded from this release type: getConfiguredAgent */
325
368
  /**
326
369
  * Enable automatic capture of the current browser page (URL + title).
327
370
  * Injected as a dynamic context entry named `browser-page`.
@@ -366,6 +409,7 @@ export declare class AgoClient {
366
409
  * Clean up resources
367
410
  */
368
411
  destroy(): void;
412
+ /* Excluded from this release type: reviveAfterDestroy */
369
413
  }
370
414
 
371
415
  /**
@@ -444,6 +488,15 @@ export declare interface AgoClientEvents {
444
488
  "toolCall:received": ToolCallData;
445
489
  "toolCall:form": ToolCallData;
446
490
  "function:invoke": ClientFunctionInvocation;
491
+ /**
492
+ * A client function call is held pending the user's approval (pause mode +
493
+ * an {@link AgoConfig.approvalPolicy}/`requiresApproval` match). The turn stays
494
+ * at `WAITING_CLIENT`; call `approveFunction(invocationId)` to run it and
495
+ * resume, or `rejectFunction(invocationId)` to decline. Fires after
496
+ * `function:invoke` (which still fires for every call) and instead of the
497
+ * call running immediately.
498
+ */
499
+ "function:awaiting-approval": ClientFunctionInvocation;
447
500
  "function:result": {
448
501
  invocationId: string;
449
502
  result: unknown;
@@ -473,6 +526,25 @@ export declare interface AgoClientEvents {
473
526
  "connection:status": {
474
527
  connected: boolean;
475
528
  };
529
+ /**
530
+ * A proactive nudge passed every governor gate and is ready to display.
531
+ * `useProactiveNudge` / `<AgoNudge>` consume this; custom UIs should call
532
+ * `client.proactive.shown(nudge)` when they render it (impression tracking
533
+ * + frequency caps), then `accept(nudge)` / `dismiss(nudge)`.
534
+ */
535
+ "nudge:ready": ProactiveNudgeInstance;
536
+ /** A nudge was displayed to the user (fires once per nudge). */
537
+ "nudge:shown": {
538
+ nudge: ProactiveNudgeInstance;
539
+ };
540
+ /** The user dismissed the nudge (its trigger is suppressed, see governor). */
541
+ "nudge:dismissed": {
542
+ nudge: ProactiveNudgeInstance;
543
+ };
544
+ /** The user accepted the nudge (its action ran / the chat is being seeded). */
545
+ "nudge:accepted": {
546
+ nudge: ProactiveNudgeInstance;
547
+ };
476
548
  }
477
549
 
478
550
  /**
@@ -512,6 +584,20 @@ export declare interface AgoConfig {
512
584
  * Older backends ignore the flag, so `"pause"` degrades to legacy behavior.
513
585
  */
514
586
  clientFunctionsMode?: ClientFunctionsMode;
587
+ /**
588
+ * Gate client function calls behind explicit user approval. Return `true` for
589
+ * an invocation the user must approve/reject before it runs; return `false`
590
+ * (or omit the policy) to let it run immediately as before.
591
+ *
592
+ * Only effective in pause mode (`clientFunctionsMode: "pause"`) — a gated call
593
+ * holds at `WAITING_CLIENT`, the SDK emits `function:awaiting-approval`, and it
594
+ * runs (and the turn resumes) only after `approveFunction(invocationId)`; a
595
+ * `rejectFunction(invocationId)` submits a rejection so the agent sees the
596
+ * decline. In placeholder mode there is no pause to hold, so the policy is a
597
+ * no-op and the call runs normally. A per-function `requiresApproval: true`
598
+ * also gates a call; the policy and the flag OR together.
599
+ */
600
+ approvalPolicy?: (invocation: ClientFunctionInvocation) => boolean;
515
601
  /**
516
602
  * Max serialized size (bytes) of a client function result before the SDK
517
603
  * replaces it with a flagged, truncated preview. Everything a handler
@@ -520,6 +606,16 @@ export declare interface AgoConfig {
520
606
  * with `maxResultBytes` on its definition; `Infinity` disables the guard.
521
607
  */
522
608
  maxFunctionResultBytes?: number;
609
+ /**
610
+ * Enable the proactive mode: declarative triggers evaluated client-side
611
+ * against friction signals (dwell/idle time, rage clicks, route bounces…)
612
+ * that can surface a nudge before the user opens the chat. Equivalent to
613
+ * calling `createAgoProactive(client, proactive)` — the resulting controller
614
+ * is available as `client.proactive`. Requires the tenant-level kill-switch
615
+ * (`GET /api/sdk/v1/config` → `proactive.enabled`) to be on; disabled by
616
+ * default otherwise.
617
+ */
618
+ proactive?: ProactiveOptions;
523
619
  }
524
620
 
525
621
  /**
@@ -588,6 +684,11 @@ export declare class AgoNetworkError extends AgoError {
588
684
  export declare interface AgoPageStateOptions {
589
685
  /** Name of the synthesized client function. Defaults to "setPageState". */
590
686
  functionName?: string;
687
+ /**
688
+ * Require explicit user approval before this state change runs. See
689
+ * {@link AgoConfig.approvalPolicy} — pause mode only. Defaults to `false`.
690
+ */
691
+ requiresApproval?: boolean;
591
692
  }
592
693
 
593
694
  /**
@@ -796,6 +897,11 @@ export declare interface ClientFunctionDefinition {
796
897
  * `Infinity` disables the guard for this function.
797
898
  */
798
899
  maxResultBytes?: number;
900
+ /**
901
+ * Require explicit user approval before this function runs. See
902
+ * {@link AgoConfig.approvalPolicy} — pause mode only. ORs with the policy.
903
+ */
904
+ requiresApproval?: boolean;
799
905
  }
800
906
 
801
907
  /**
@@ -822,6 +928,11 @@ export declare type ClientFunctionRegisterOptions = Omit<ClientFunctionSchema, "
822
928
  * disables the guard for this function.
823
929
  */
824
930
  maxResultBytes?: number;
931
+ /**
932
+ * Require explicit user approval before this function runs. See
933
+ * {@link AgoConfig.approvalPolicy} — pause mode only. ORs with the policy.
934
+ */
935
+ requiresApproval?: boolean;
825
936
  };
826
937
 
827
938
  /**
@@ -862,6 +973,19 @@ export declare interface ContextEntry {
862
973
  description?: string;
863
974
  /** Arbitrary structured data the AI should know about */
864
975
  data?: Record<string, unknown>;
976
+ /**
977
+ * Marks the entry as constant for the whole conversation. The backend then
978
+ * pins it right after the system prompt, where LLM providers cache it across
979
+ * turns, instead of re-processing it next to every new user message.
980
+ *
981
+ * Only set this when the entry's content is byte-identical on every message
982
+ * of a conversation (a schema, a capability list, static instructions). A
983
+ * stable entry that changes between messages invalidates the provider's
984
+ * cache for the entire conversation history, which costs more than leaving
985
+ * the flag off. Default: `false` (re-sent near the newest user message).
986
+ * Backends that don't know the flag ignore it.
987
+ */
988
+ stable?: boolean;
865
989
  }
866
990
 
867
991
  /**
@@ -967,6 +1091,35 @@ export declare const copyToClipboard: ClientFunctionDefinition;
967
1091
  */
968
1092
  export declare function createAgo(overrides?: Partial<AgoConfig>): AgoClient;
969
1093
 
1094
+ /**
1095
+ * Attach the proactive mode to a client: starts the signal collector, the
1096
+ * trigger engine, and the nudge governor, and registers the aggregated
1097
+ * friction snapshot as a dynamic context provider so the reactive mode
1098
+ * benefits too (the agent "knows" the user hesitated on every message).
1099
+ *
1100
+ * ```ts
1101
+ * const proactive = createAgoProactive(client, {
1102
+ * triggers: [{
1103
+ * id: "kyc-doc-stuck",
1104
+ * when: { route: "/dossier/*", idleMs: 20000, pageState: { step: "documents" } },
1105
+ * cooldownMs: 300_000,
1106
+ * intervene: "agent",
1107
+ * goal: "Help the user upload their KYC documents",
1108
+ * }],
1109
+ * frequencyCap: { perSession: 3, perDay: 5 },
1110
+ * });
1111
+ * // later: proactive.destroy();
1112
+ * ```
1113
+ *
1114
+ * Also wired through the config: `new AgoClient({ ..., proactive })` attaches
1115
+ * it automatically and exposes it as `client.proactive`.
1116
+ *
1117
+ * Nothing fires until the backend confirms the feature: the engine reads the
1118
+ * `proactive.enabled` kill-switch from `GET /api/sdk/v1/config` and stays
1119
+ * disabled by default.
1120
+ */
1121
+ export declare function createAgoProactive(client: AgoClient, options: ProactiveOptions): ProactiveController;
1122
+
970
1123
  /**
971
1124
  * Identify a returning visitor with a single, stable anon id (one id, generated
972
1125
  * once and reused forever) and resume their last active thread.
@@ -1160,10 +1313,22 @@ export declare interface FormCollector<V = Record<string, unknown>> {
1160
1313
  store: Store<FormCollectorState<V>>;
1161
1314
  /** Client functions to register: `[update]` or `[update, submit]`. */
1162
1315
  functions: ClientFunctionDefinition[];
1163
- /** Dynamic-context key under which the form state is exposed. */
1316
+ /** Dynamic-context key under which the live form state is exposed. */
1164
1317
  contextKey: string;
1165
- /** Dynamic-context provider — re-read on every message. */
1318
+ /**
1319
+ * Dynamic-context provider for the live form state (phase, values, missing)
1320
+ * — re-read on every message. The schema itself rides in the companion
1321
+ * {@link definitionContextProvider} entry.
1322
+ */
1166
1323
  contextProvider: () => ContextEntry;
1324
+ /** Context key of the stable form definition (`<contextKey>:definition`). */
1325
+ definitionContextKey: string;
1326
+ /**
1327
+ * Provider for the form's definition (description + schema): identical on
1328
+ * every message and marked `stable: true`, so the backend can pin it in the
1329
+ * cacheable part of the prompt. Registered/removed by `install` alongside `contextProvider`.
1330
+ */
1331
+ definitionContextProvider: () => ContextEntry;
1167
1332
  /** Register the functions + dynamic context on a client. Returns an uninstall fn. */
1168
1333
  install: (client: AgoClient) => () => void;
1169
1334
  /**
@@ -1406,6 +1571,43 @@ export declare const getUserLocation: ClientFunctionDefinition;
1406
1571
  */
1407
1572
  export declare const highlightElement: ClientFunctionDefinition;
1408
1573
 
1574
+ /**
1575
+ * HTTP client with authentication headers
1576
+ */
1577
+ declare class HttpClient {
1578
+ private baseUrl;
1579
+ private headers;
1580
+ constructor(config: AgoConfig);
1581
+ /**
1582
+ * Update configuration (e.g., JWT token)
1583
+ */
1584
+ updateConfig(config: Partial<AgoConfig>): void;
1585
+ /**
1586
+ * Make a GET request
1587
+ */
1588
+ get<T>(path: string): Promise<T>;
1589
+ /**
1590
+ * Make a POST request with JSON body.
1591
+ *
1592
+ * `keepalive: true` lets the request survive a page unload (used by the
1593
+ * proactive event tracker's flush-on-hide — sendBeacon can't carry the auth
1594
+ * headers, so it's a keepalive fetch instead).
1595
+ */
1596
+ post<T>(path: string, body?: unknown, options?: {
1597
+ keepalive?: boolean;
1598
+ }): Promise<T>;
1599
+ /**
1600
+ * Make a POST request and return the raw Response (for streaming)
1601
+ */
1602
+ postStream(path: string, body?: unknown): Promise<Response>;
1603
+ /**
1604
+ * Make a POST request with FormData (for file uploads)
1605
+ */
1606
+ postFormData(path: string, formData: FormData): Promise<Response>;
1607
+ private request;
1608
+ private handleErrorResponse;
1609
+ }
1610
+
1409
1611
  /**
1410
1612
  * Check if an error is a network error that should trigger polling fallback
1411
1613
  */
@@ -1451,6 +1653,29 @@ declare class Logger {
1451
1653
 
1452
1654
  export declare const logger: Logger;
1453
1655
 
1656
+ /**
1657
+ * Match a pathname against a trigger route pattern. Mirrors the styles the
1658
+ * navigation function already understands (`:param` segments), plus globs:
1659
+ *
1660
+ * - exact: `/billing`
1661
+ * - `:param`: `/users/:id` matches `/users/42`
1662
+ * - `*` mid-path: matches exactly one segment (`/a/*` / `/b`)
1663
+ * - trailing `/*`: matches one or MORE remaining segments (`/dossier/*`
1664
+ * matches `/dossier/1` and `/dossier/1/docs`, not `/dossier`)
1665
+ * - `*` alone matches everything
1666
+ *
1667
+ * Trailing slashes on the pathname are tolerated.
1668
+ */
1669
+ export declare function matchesRoutePattern(pattern: string, pathname: string): boolean;
1670
+
1671
+ /**
1672
+ * Evaluate a trigger's `when` clause against a signals snapshot. Pure
1673
+ * conjunction: every specified matcher must pass. Numeric fields are `>=`
1674
+ * thresholds; `pageState` is a partial deep match; `fieldErrors` are per-name
1675
+ * minimum counts.
1676
+ */
1677
+ export declare function matchesWhen(when: ProactiveTriggerWhen, snapshot: SignalsSnapshot): boolean;
1678
+
1454
1679
  export declare type MessageStatus = "IN_PROGRESS" | "DONE" | "ERROR" | "TODO" | "CANCELED"
1455
1680
  /**
1456
1681
  * The turn paused on client function call(s) (pause mode): the agent waits for
@@ -1489,6 +1714,21 @@ export declare interface MockAgoClientOptions {
1489
1714
 
1490
1715
  declare type MockFn = (...args: any[]) => any;
1491
1716
 
1717
+ /**
1718
+ * Optional action attached to a nudge. Accepting a `functionName` action
1719
+ * executes the registered client function (same `FunctionRegistry` path as
1720
+ * agent-invoked calls); `setPageState` applies values through the registered
1721
+ * page-state controls.
1722
+ */
1723
+ export declare type NudgeAction = {
1724
+ label: string;
1725
+ functionName: string;
1726
+ arguments?: Record<string, unknown>;
1727
+ } | {
1728
+ label: string;
1729
+ setPageState: Record<string, unknown>;
1730
+ };
1731
+
1492
1732
  /**
1493
1733
  * Subscribe to failed form collector submissions (network/server failures).
1494
1734
  */
@@ -1552,6 +1792,13 @@ export declare function onToolCall(client: AgoClient, callback: (toolCall: ToolC
1552
1792
  */
1553
1793
  export declare const openUrl: ClientFunctionDefinition;
1554
1794
 
1795
+ /**
1796
+ * Partial deep match: every key/value present in `expected` must match the
1797
+ * corresponding value in `actual`. Nested objects recurse (partially); arrays
1798
+ * and primitives compare by deep equality.
1799
+ */
1800
+ export declare function partialDeepMatch(expected: unknown, actual: unknown): boolean;
1801
+
1555
1802
  export declare interface PersistOptions {
1556
1803
  /** Key under which the state is JSON-serialized. */
1557
1804
  key: string;
@@ -1559,6 +1806,196 @@ export declare interface PersistOptions {
1559
1806
  storage?: StorageLike;
1560
1807
  }
1561
1808
 
1809
+ /**
1810
+ * Controller returned by {@link createAgoProactive} (also available as
1811
+ * `client.proactive`).
1812
+ */
1813
+ export declare interface ProactiveController {
1814
+ /** Persistently opt this browser out of proactive nudges. */
1815
+ optOut(): void;
1816
+ /** Undo {@link optOut}. */
1817
+ optIn(): void;
1818
+ isOptedOut(): boolean;
1819
+ /**
1820
+ * Tell the governor the user is already engaged (e.g. the chat widget is
1821
+ * open) — nudges are suppressed while `true`. Call from the UI layer.
1822
+ */
1823
+ setEngaged(engaged: boolean): void;
1824
+ /** App-pushed field error counter (field NAME only — never values). */
1825
+ signalFieldError(fieldName: string): void;
1826
+ /** Current aggregated friction snapshot. */
1827
+ getSignalsSnapshot(): SignalsSnapshot;
1828
+ /** The nudge currently occupying the single-nudge slot, if any. */
1829
+ getActiveNudge(): ProactiveNudgeInstance | null;
1830
+ /**
1831
+ * Mark the nudge as displayed. Idempotent per nudge; counts it against the
1832
+ * frequency caps, tracks the impression, and emits `nudge:shown`.
1833
+ */
1834
+ shown(nudge: ProactiveNudgeInstance): void;
1835
+ /**
1836
+ * Accept the nudge: run its action (if any), emit `nudge:accepted`, track,
1837
+ * and — for agent nudges or nudges with a `goal` — pre-seed the chat with a
1838
+ * hidden kickoff message so the agent starts the turn with full context.
1839
+ */
1840
+ accept(nudge: ProactiveNudgeInstance): Promise<void>;
1841
+ /** Dismiss the nudge: suppress the trigger, track, emit `nudge:dismissed`. */
1842
+ dismiss(nudge: ProactiveNudgeInstance): void;
1843
+ /** Report a downstream conversion attributable to the nudge (analytics only). */
1844
+ markConverted(nudge: ProactiveNudgeInstance): void;
1845
+ /** Detach everything: listeners, timers, context provider, event flush. */
1846
+ destroy(): void;
1847
+ }
1848
+
1849
+ /**
1850
+ * Response of `POST {baseUrl}/api/sdk/v1/proactive/evaluate` (snake_case, as
1851
+ * on the wire). On 429 or any error the SDK treats the call as
1852
+ * `intervene: false`, silently (debug log only).
1853
+ */
1854
+ export declare interface ProactiveEvaluateResponse {
1855
+ intervene: boolean;
1856
+ message: string | null;
1857
+ action: {
1858
+ label: string;
1859
+ function_name: string;
1860
+ arguments?: Record<string, unknown>;
1861
+ } | null;
1862
+ /** Server-generated nudge uuid. */
1863
+ nudge_id: string;
1864
+ }
1865
+
1866
+ /** A concrete nudge produced by the engine, carried by every `nudge:*` event. */
1867
+ export declare interface ProactiveNudgeInstance {
1868
+ /** Client-generated uuid for this nudge instance (`client_nudge_id`). */
1869
+ id: string;
1870
+ triggerId: string;
1871
+ /** `static` = configured message; `agent` = backend LLM evaluation. */
1872
+ source: "static" | "agent";
1873
+ message: string;
1874
+ action?: NudgeAction;
1875
+ goal?: string;
1876
+ /** See {@link ProactiveTrigger.kickoff}. */
1877
+ kickoff?: string;
1878
+ createdAt: Date;
1879
+ /** Server-side nudge id (agent nudges only). */
1880
+ serverNudgeId?: string;
1881
+ }
1882
+
1883
+ /** Options for {@link createAgoProactive} / `AgoConfig.proactive`. */
1884
+ export declare interface ProactiveOptions {
1885
+ triggers: ProactiveTrigger[];
1886
+ /**
1887
+ * Global caps on nudges actually shown. `perSession` is in-memory (page
1888
+ * lifetime); `perDay` is persisted in localStorage with a date rollover —
1889
+ * best-effort by design (private browsing resets it); the costly LLM path is
1890
+ * additionally capped server-side.
1891
+ */
1892
+ frequencyCap?: {
1893
+ perSession?: number;
1894
+ perDay?: number;
1895
+ };
1896
+ /** Evaluation tick, ms. Default 1000. Zero network per tick. */
1897
+ tickMs?: number;
1898
+ /** Storage backend for persisted governance state. Default `localStorage`. */
1899
+ storage?: StorageLike;
1900
+ /** Storage key for persisted governance state. Default `"ago_proactive"`. */
1901
+ storageKey?: string;
1902
+ /** Tuning of the signal detectors (rage-click window, throttles…). */
1903
+ signals?: SignalCollectorTuning;
1904
+ /**
1905
+ * Local demos and tests ONLY: bypass the remote kill-switch. When set, the
1906
+ * `GET /config` fetch is skipped and the kill-switch takes this value.
1907
+ * Leave unset in production — the tenant admin controls the feature, and
1908
+ * the evaluate endpoint stays gated server-side regardless.
1909
+ */
1910
+ enabledOverride?: boolean;
1911
+ }
1912
+
1913
+ /** One entry of the `POST {baseUrl}/api/sdk/v1/proactive/events` batch. */
1914
+ export declare interface ProactiveTrackedEvent {
1915
+ clientNudgeId: string;
1916
+ triggerId: string;
1917
+ source: "static" | "agent";
1918
+ type: "shown" | "dismissed" | "accepted" | "converted";
1919
+ /** Nudge text, optional. */
1920
+ message?: string;
1921
+ /** Epoch ms; serialized as ISO-8601 `occurred_at`. */
1922
+ occurredAt: number;
1923
+ }
1924
+
1925
+ /** A declarative proactive trigger. */
1926
+ export declare interface ProactiveTrigger {
1927
+ /** Stable id, used for cooldowns, dismissal memory, and analytics. */
1928
+ id: string;
1929
+ /** Conjunction of matchers (see {@link ProactiveTriggerWhen}). */
1930
+ when: ProactiveTriggerWhen;
1931
+ /**
1932
+ * Min time between two firings of this trigger (persisted across reloads).
1933
+ * A firing is the moment the trigger passes the gates — including an agent
1934
+ * evaluation that decides NOT to intervene, so a persistent condition can't
1935
+ * hammer the evaluate endpoint. Default 60 000.
1936
+ */
1937
+ cooldownMs?: number;
1938
+ /**
1939
+ * `'agent'` asks the backend's fast-LLM second filter whether (and how) to
1940
+ * intervene; a `static` object shows the given message with no network call.
1941
+ */
1942
+ intervene: "agent" | {
1943
+ type: "static";
1944
+ message: string;
1945
+ action?: NudgeAction;
1946
+ };
1947
+ /**
1948
+ * What the agent should help with. Sent to the evaluate endpoint, and used to
1949
+ * pre-seed the chat turn when the user accepts the nudge.
1950
+ */
1951
+ goal?: string;
1952
+ /**
1953
+ * User-voice line used to OPEN the conversation when the user accepts this
1954
+ * nudge and no conversation exists yet — a hidden kickoff cannot start one
1955
+ * (the backend rejects it). Sent as a visible user message, so write it in
1956
+ * the app's language ("Oui, aidez-moi à choisir !"). When a conversation is
1957
+ * already open, the SDK sends a hidden meta kickoff instead and this field
1958
+ * is unused. Without it, accepting with no open conversation skips the chat
1959
+ * pre-seed (the nudge action still runs).
1960
+ */
1961
+ kickoff?: string;
1962
+ /**
1963
+ * How long a dismissal of this trigger's nudge suppresses it (persisted).
1964
+ * Default 24h.
1965
+ */
1966
+ resurfaceAfterMs?: number;
1967
+ }
1968
+
1969
+ /**
1970
+ * Conditions of a proactive trigger. Pure conjunction: EVERY specified matcher
1971
+ * must pass against the current {@link SignalsSnapshot}. Numeric fields are
1972
+ * `>=` thresholds.
1973
+ */
1974
+ export declare interface ProactiveTriggerWhen {
1975
+ /**
1976
+ * Route pattern the current pathname must match. Supports the SDK's route
1977
+ * styles: exact (`/billing`), `:param` segments (`/users/:id`), single-segment
1978
+ * wildcards (`/a/*` / `/b`), and a trailing `/*` that matches one or more
1979
+ * remaining segments (`/dossier/*`).
1980
+ */
1981
+ route?: string;
1982
+ /** Min time since the last user activity, ms. */
1983
+ idleMs?: number;
1984
+ /** Min time spent on the current route, ms. */
1985
+ dwellMs?: number;
1986
+ /**
1987
+ * Partial deep match against the registered page state (funnel step,
1988
+ * filters…). Every key present here must deep-match the live value.
1989
+ */
1990
+ pageState?: Partial<Record<string, unknown>>;
1991
+ /** Min rage-click bursts on the current route. */
1992
+ rageClicks?: number;
1993
+ /** Min A→B→A→B route oscillations this session. */
1994
+ routeBounces?: number;
1995
+ /** Per-field minimum error counts (field NAME → min count). */
1996
+ fieldErrors?: Record<string, number>;
1997
+ }
1998
+
1562
1999
  /**
1563
2000
  * Registered function with handler
1564
2001
  */
@@ -1567,6 +2004,8 @@ export declare interface RegisteredFunction {
1567
2004
  handler: ClientFunctionHandler;
1568
2005
  /** Per-function result-size ceiling; falls back to the registry default. */
1569
2006
  maxResultBytes?: number;
2007
+ /** Require explicit user approval before running (pause mode only). */
2008
+ requiresApproval?: boolean;
1570
2009
  }
1571
2010
 
1572
2011
  /**
@@ -1648,6 +2087,168 @@ export declare const showNotification: ClientFunctionDefinition;
1648
2087
  */
1649
2088
  export declare const showToast: ClientFunctionDefinition;
1650
2089
 
2090
+ /** One entry of the collector's ring buffer. */
2091
+ export declare interface Signal {
2092
+ type: SignalType;
2093
+ /** Pathname the signal happened on. */
2094
+ route: string;
2095
+ /** Epoch ms. */
2096
+ at: number;
2097
+ /** Optional counter (e.g. how many errors this field has produced so far). */
2098
+ count?: number;
2099
+ /** Small, PII-free metadata (field names, previous route…). */
2100
+ meta?: Record<string, string | number>;
2101
+ }
2102
+
2103
+ /**
2104
+ * Framework-agnostic collector of client-side friction signals: per-route
2105
+ * dwell time, idle time, route bounces (A→B→A→B), rage clicks, and app-pushed
2106
+ * field error counters. Attached to an `AgoClient` by `createAgoProactive`,
2107
+ * the same way `ClientContextRegistry` is attached.
2108
+ *
2109
+ * Route observation is poll-on-demand rather than a `history.pushState` patch:
2110
+ * the SDK must never mutate host globals (see CLAUDE.md scoping rules), so the
2111
+ * current pathname is (re)checked on `popstate`/`hashchange`, on throttled user
2112
+ * activity, and on every `getSnapshot()` — the proactive engine's ~1s tick
2113
+ * makes that an effective 1s poll, plenty for multi-second dwell thresholds.
2114
+ *
2115
+ * Privacy: only enums, counters, and paths are recorded. Field VALUES are never
2116
+ * read — `signalFieldError(fieldName)` takes the field name only.
2117
+ *
2118
+ * Listeners are passive and throttled, attached only by `start()` (i.e. only
2119
+ * when proactive mode is configured) and fully removed by `destroy()`.
2120
+ */
2121
+ export declare class SignalCollector {
2122
+ private readonly getPageState?;
2123
+ private readonly activityThrottleMs;
2124
+ private readonly rageClickCount;
2125
+ private readonly rageClickWindowMs;
2126
+ private readonly rageClickRadiusPx;
2127
+ private readonly maxRecentRoutes;
2128
+ private readonly maxSignals;
2129
+ private started;
2130
+ private teardowns;
2131
+ private route;
2132
+ private routeEnteredAt;
2133
+ private lastActivityAt;
2134
+ private lastHeavyActivityAt;
2135
+ private recentRoutes;
2136
+ private routeBounces;
2137
+ private rageClicks;
2138
+ private fieldErrors;
2139
+ private recentClicks;
2140
+ private signals;
2141
+ private listeners;
2142
+ constructor(options?: SignalCollectorOptions);
2143
+ /**
2144
+ * Attach the DOM listeners and start tracking. Idempotent; no-op outside a
2145
+ * browser (SSR).
2146
+ */
2147
+ start(): void;
2148
+ /** Remove every listener and reset transient buffers. */
2149
+ destroy(): void;
2150
+ /**
2151
+ * App-pushed signal: a form field produced a (repeated) validation error.
2152
+ * Pass the field NAME only — values are never read, so no PII is collected.
2153
+ */
2154
+ signalFieldError(fieldName: string): void;
2155
+ /**
2156
+ * Subscribe to raw signals (route changes, bounces, rage clicks, field
2157
+ * errors). Returns an unsubscribe function. Used by the proactive engine to
2158
+ * evaluate promptly instead of waiting for the next tick.
2159
+ */
2160
+ subscribe(listener: (signal: Signal) => void): () => void;
2161
+ /** The typed-signal ring buffer (most recent last, bounded). */
2162
+ getSignals(): Signal[];
2163
+ /**
2164
+ * Aggregated snapshot of the current friction state. Re-checks the route
2165
+ * first, so calling this on a periodic tick doubles as the route poll.
2166
+ *
2167
+ * `pageState: false` skips the page-state read — used by the
2168
+ * `friction_signals` dynamic context provider, both because page state
2169
+ * already rides in `client_context` under its own `page-state:*` entries and
2170
+ * because reading it from inside a context provider would recurse.
2171
+ */
2172
+ getSnapshot(opts?: {
2173
+ pageState?: boolean;
2174
+ }): SignalsSnapshot;
2175
+ private currentPathname;
2176
+ private readPageState;
2177
+ private recordActivity;
2178
+ /** Compare the live pathname with the tracked one; handle a route change. */
2179
+ private checkRoute;
2180
+ private onClick;
2181
+ /** Cheap fingerprint of the page state, for "did this click change anything". */
2182
+ private pageStateKey;
2183
+ private pushSignal;
2184
+ }
2185
+
2186
+ export declare interface SignalCollectorOptions extends SignalCollectorTuning {
2187
+ /**
2188
+ * Reads the current page state (the registered `AgoStateControl.get()`
2189
+ * snapshot). Wired by `createAgoProactive` to the client's `page-state:*`
2190
+ * dynamic context entries so funnel state is available to trigger matchers
2191
+ * without new plumbing.
2192
+ */
2193
+ getPageState?: () => Record<string, unknown> | null;
2194
+ }
2195
+
2196
+ /** Tuning knobs for the collector's detectors. All optional. */
2197
+ export declare interface SignalCollectorTuning {
2198
+ /** Min gap between heavy activity work (route checks, notifications), ms. Default 250. */
2199
+ activityThrottleMs?: number;
2200
+ /** Rage click: clicks needed to count a burst. Default 3. */
2201
+ rageClickCount?: number;
2202
+ /** Rage click: max time between first and last click of a burst, ms. Default 1000. */
2203
+ rageClickWindowMs?: number;
2204
+ /** Rage click: max radius between clicks of a burst, px. Default 24. */
2205
+ rageClickRadiusPx?: number;
2206
+ /** Max routes kept in the recent-route sequence. Default 10. */
2207
+ maxRecentRoutes?: number;
2208
+ /** Max typed signals kept in the ring buffer. Default 50. */
2209
+ maxSignals?: number;
2210
+ }
2211
+
2212
+ /**
2213
+ * Aggregated view of the current friction state. Registered as a dynamic
2214
+ * context provider (key `friction_signals`) so it rides along as
2215
+ * `client_context` on every message, and sent as `signals` to the proactive
2216
+ * evaluate endpoint.
2217
+ */
2218
+ export declare interface SignalsSnapshot {
2219
+ /** Current pathname. */
2220
+ route: string;
2221
+ /** Time spent on the current route, ms. */
2222
+ dwellMs: number;
2223
+ /** Time since the last user activity (pointer/key/scroll/touch), ms. */
2224
+ idleMs: number;
2225
+ /** Rage-click bursts detected on the current route. */
2226
+ rageClicks: number;
2227
+ /**
2228
+ * A→B→A→B route oscillations detected in the recent route sequence. Rolling
2229
+ * session counter (cross-route by nature); trigger cooldowns and dismissal
2230
+ * memory keep it from re-firing forever.
2231
+ */
2232
+ routeBounces: number;
2233
+ /** App-pushed field error counters (field NAME → count), current route only. */
2234
+ fieldErrors: Record<string, number>;
2235
+ /** Most recent pathnames, oldest first (bounded). */
2236
+ recentRoutes: string[];
2237
+ /**
2238
+ * Merged `AgoStateControl.get()` snapshot of the registered page-state
2239
+ * controls (funnel step, filters…), or `null` when none are registered.
2240
+ */
2241
+ pageState: Record<string, unknown> | null;
2242
+ }
2243
+
2244
+ /**
2245
+ * Typed friction signals collected client-side by the {@link SignalCollector}.
2246
+ *
2247
+ * Privacy rule: signals carry **enums, counters, and paths only** — never field
2248
+ * values or free text — so no PII ever leaves the page through this channel.
2249
+ */
2250
+ export declare type SignalType = "route_change" | "route_bounce" | "rage_click" | "field_error";
2251
+
1651
2252
  /**
1652
2253
  * SSE stream chunk data
1653
2254
  */