@useago/sdk 1.5.2 → 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 (50) hide show
  1. package/dist/AgoClient-BGkFSNZF.cjs +8 -0
  2. package/dist/AgoClient-CW-BLT1_.js +1542 -0
  3. package/dist/angular.cjs +1 -1
  4. package/dist/angular.d.cts +311 -0
  5. package/dist/angular.d.ts +311 -0
  6. package/dist/angular.js +2 -2
  7. package/dist/createConversationSession-BCb0D6bt.cjs +1 -0
  8. package/dist/{createConversationSession-DPrrr70o.js → createConversationSession-C7cnnWKW.js} +3 -3
  9. package/dist/createFormCollector-iCDwAwYJ.js +279 -0
  10. package/dist/createFormCollector-t_fGyuTD.cjs +1 -0
  11. package/dist/createMockClient-Br0TWgLO.js +97 -0
  12. package/dist/createMockClient-BwNLPjeT.cjs +1 -0
  13. package/dist/devtools.d.cts +311 -0
  14. package/dist/devtools.d.ts +311 -0
  15. package/dist/functions-IGSjjvF4.cjs +1 -0
  16. package/dist/helpers.cjs +1 -1
  17. package/dist/helpers.js +1 -1
  18. package/dist/index.cjs +1 -1
  19. package/dist/index.d.cts +510 -0
  20. package/dist/index.d.ts +510 -0
  21. package/dist/index.js +95 -90
  22. package/dist/react.cjs +3 -3
  23. package/dist/react.d.cts +375 -0
  24. package/dist/react.d.ts +375 -0
  25. package/dist/react.js +559 -422
  26. package/dist/rolldown-runtime-16Nf8qvH.cjs +1 -0
  27. package/dist/testing.cjs +1 -1
  28. package/dist/testing.d.cts +311 -0
  29. package/dist/testing.d.ts +311 -0
  30. package/dist/testing.js +1 -1
  31. package/dist/vue.cjs +1 -1
  32. package/dist/vue.d.cts +332 -0
  33. package/dist/vue.d.ts +332 -0
  34. package/dist/vue.js +133 -110
  35. package/dist/widget.cjs +1 -1
  36. package/dist/widget.d.cts +308 -0
  37. package/dist/widget.d.ts +308 -0
  38. package/dist/widget.js +7 -7
  39. package/package.json +1 -1
  40. package/dist/AgoClient-5VGybmvz.cjs +0 -8
  41. package/dist/AgoClient-DXrH2AMi.js +0 -964
  42. package/dist/createConversationSession-0WTqcCLK.cjs +0 -1
  43. package/dist/createFormCollector-1GKKwQV_.cjs +0 -1
  44. package/dist/createFormCollector-DYh90kiG.js +0 -305
  45. package/dist/createMockClient-C-wrjb2C.cjs +0 -1
  46. package/dist/createMockClient-we-XoPom.js +0 -79
  47. package/dist/functions-CPs7omgM.cjs +0 -1
  48. /package/dist/{autoContinue-CP9pJR-V.cjs → autoContinue-CcCTva-D.cjs} +0 -0
  49. /package/dist/{autoContinue-CC8K9mBU.js → autoContinue-D3Mmaaca.js} +0 -0
  50. /package/dist/{functions-tzyOZNp6.js → functions-CApuQZ2b.js} +0 -0
package/dist/index.d.cts CHANGED
@@ -77,6 +77,12 @@ export declare class AgoClient {
77
77
  private pendingApprovals;
78
78
  /** App-provided gate deciding WHEN a paused turn resumes (see {@link registerResumeGate}). */
79
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;
80
86
  constructor(config: AgoConfig);
81
87
  /**
82
88
  * Send a message and receive a streaming response
@@ -247,6 +253,14 @@ export declare class AgoClient {
247
253
  * Get all registered function schemas
248
254
  */
249
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>;
250
264
  /**
251
265
  * Register a navigation function that lets AGO navigate users to different pages.
252
266
  *
@@ -348,6 +362,9 @@ export declare class AgoClient {
348
362
  */
349
363
  notifyContextChanged(): void;
350
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 */
351
368
  /**
352
369
  * Enable automatic capture of the current browser page (URL + title).
353
370
  * Injected as a dynamic context entry named `browser-page`.
@@ -392,6 +409,7 @@ export declare class AgoClient {
392
409
  * Clean up resources
393
410
  */
394
411
  destroy(): void;
412
+ /* Excluded from this release type: reviveAfterDestroy */
395
413
  }
396
414
 
397
415
  /**
@@ -508,6 +526,25 @@ export declare interface AgoClientEvents {
508
526
  "connection:status": {
509
527
  connected: boolean;
510
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
+ };
511
548
  }
512
549
 
513
550
  /**
@@ -569,6 +606,16 @@ export declare interface AgoConfig {
569
606
  * with `maxResultBytes` on its definition; `Infinity` disables the guard.
570
607
  */
571
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;
572
619
  }
573
620
 
574
621
  /**
@@ -1044,6 +1091,35 @@ export declare const copyToClipboard: ClientFunctionDefinition;
1044
1091
  */
1045
1092
  export declare function createAgo(overrides?: Partial<AgoConfig>): AgoClient;
1046
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
+
1047
1123
  /**
1048
1124
  * Identify a returning visitor with a single, stable anon id (one id, generated
1049
1125
  * once and reused forever) and resume their last active thread.
@@ -1495,6 +1571,43 @@ export declare const getUserLocation: ClientFunctionDefinition;
1495
1571
  */
1496
1572
  export declare const highlightElement: ClientFunctionDefinition;
1497
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
+
1498
1611
  /**
1499
1612
  * Check if an error is a network error that should trigger polling fallback
1500
1613
  */
@@ -1540,6 +1653,29 @@ declare class Logger {
1540
1653
 
1541
1654
  export declare const logger: Logger;
1542
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
+
1543
1679
  export declare type MessageStatus = "IN_PROGRESS" | "DONE" | "ERROR" | "TODO" | "CANCELED"
1544
1680
  /**
1545
1681
  * The turn paused on client function call(s) (pause mode): the agent waits for
@@ -1578,6 +1714,21 @@ export declare interface MockAgoClientOptions {
1578
1714
 
1579
1715
  declare type MockFn = (...args: any[]) => any;
1580
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
+
1581
1732
  /**
1582
1733
  * Subscribe to failed form collector submissions (network/server failures).
1583
1734
  */
@@ -1641,6 +1792,13 @@ export declare function onToolCall(client: AgoClient, callback: (toolCall: ToolC
1641
1792
  */
1642
1793
  export declare const openUrl: ClientFunctionDefinition;
1643
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
+
1644
1802
  export declare interface PersistOptions {
1645
1803
  /** Key under which the state is JSON-serialized. */
1646
1804
  key: string;
@@ -1648,6 +1806,196 @@ export declare interface PersistOptions {
1648
1806
  storage?: StorageLike;
1649
1807
  }
1650
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
+
1651
1999
  /**
1652
2000
  * Registered function with handler
1653
2001
  */
@@ -1739,6 +2087,168 @@ export declare const showNotification: ClientFunctionDefinition;
1739
2087
  */
1740
2088
  export declare const showToast: ClientFunctionDefinition;
1741
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
+
1742
2252
  /**
1743
2253
  * SSE stream chunk data
1744
2254
  */