@useago/sdk 1.5.2 → 1.5.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 (45) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/README.md +10 -0
  3. package/dist/AgoClient-BW0YZsis.js +1681 -0
  4. package/dist/AgoClient-Ba3ICq4K.cjs +8 -0
  5. package/dist/angular.cjs +1 -1
  6. package/dist/angular.d.cts +352 -0
  7. package/dist/angular.d.ts +352 -0
  8. package/dist/angular.js +1 -1
  9. package/dist/{createConversationSession-DPrrr70o.js → createConversationSession-BjsgjL-v.js} +3 -3
  10. package/dist/createConversationSession-okoz3teC.cjs +1 -0
  11. package/dist/createFormCollector-BWIh1pMl.cjs +1 -0
  12. package/dist/createFormCollector-Bay2UpRv.js +279 -0
  13. package/dist/createMockClient-DcuNlufr.js +97 -0
  14. package/dist/createMockClient-Dw-cyISN.cjs +1 -0
  15. package/dist/devtools.d.cts +352 -0
  16. package/dist/devtools.d.ts +352 -0
  17. package/dist/index.cjs +1 -1
  18. package/dist/index.d.cts +564 -0
  19. package/dist/index.d.ts +564 -0
  20. package/dist/index.js +97 -90
  21. package/dist/react.cjs +3 -3
  22. package/dist/react.d.cts +430 -0
  23. package/dist/react.d.ts +430 -0
  24. package/dist/react.js +600 -443
  25. package/dist/testing.cjs +1 -1
  26. package/dist/testing.d.cts +352 -0
  27. package/dist/testing.d.ts +352 -0
  28. package/dist/testing.js +1 -1
  29. package/dist/vue.cjs +1 -1
  30. package/dist/vue.d.cts +373 -0
  31. package/dist/vue.d.ts +373 -0
  32. package/dist/vue.js +133 -110
  33. package/dist/widget.cjs +1 -1
  34. package/dist/widget.d.cts +349 -0
  35. package/dist/widget.d.ts +349 -0
  36. package/dist/widget.js +7 -7
  37. package/llms-full.txt +29 -0
  38. package/package.json +1 -1
  39. package/dist/AgoClient-5VGybmvz.cjs +0 -8
  40. package/dist/AgoClient-DXrH2AMi.js +0 -964
  41. package/dist/createConversationSession-0WTqcCLK.cjs +0 -1
  42. package/dist/createFormCollector-1GKKwQV_.cjs +0 -1
  43. package/dist/createFormCollector-DYh90kiG.js +0 -305
  44. package/dist/createMockClient-C-wrjb2C.cjs +0 -1
  45. package/dist/createMockClient-we-XoPom.js +0 -79
package/dist/widget.d.cts CHANGED
@@ -1,3 +1,19 @@
1
+ declare interface ActivityEntry {
2
+ ts: number;
3
+ actor: "user" | "agent";
4
+ name: string;
5
+ summary: string;
6
+ data?: Record<string, unknown>;
7
+ }
8
+
9
+ declare interface ActivityInput {
10
+ actor?: "user" | "agent";
11
+ name: string;
12
+ summary: string;
13
+ data?: Record<string, unknown>;
14
+ ts?: number;
15
+ }
16
+
1
17
  /**
2
18
  * Agent information
3
19
  */
@@ -36,6 +52,8 @@ declare class AgoClient {
36
52
  private functionRegistry;
37
53
  private contextRegistry;
38
54
  private eventEmitter;
55
+ private activityLedger;
56
+ private lastSentPageState;
39
57
  private config;
40
58
  /** Conversations already warned about an empty reply (one warning each). */
41
59
  private warnedEmptyConversations;
@@ -49,6 +67,12 @@ declare class AgoClient {
49
67
  private pendingApprovals;
50
68
  /** App-provided gate deciding WHEN a paused turn resumes (see {@link registerResumeGate}). */
51
69
  private resumeGate;
70
+ /**
71
+ * Proactive-mode controller, set when the client was created with
72
+ * `proactive` options or when `createAgoProactive(client, opts)` was called.
73
+ * `null` otherwise.
74
+ */
75
+ proactive: ProactiveController | null;
52
76
  constructor(config: AgoConfig);
53
77
  /**
54
78
  * Send a message and receive a streaming response
@@ -219,6 +243,14 @@ declare class AgoClient {
219
243
  * Get all registered function schemas
220
244
  */
221
245
  getRegisteredFunctions(): ClientFunctionSchema[];
246
+ /**
247
+ * Execute a registered client function locally, through the same
248
+ * FunctionRegistry path (result-size guard, error wrapping) as agent-invoked
249
+ * calls. Used by proactive nudge actions, where the user's explicit click on
250
+ * the action button constitutes the approval — nothing is submitted to the
251
+ * backend (there is no tool call to answer).
252
+ */
253
+ executeClientFunction(name: string, args: Record<string, unknown>): Promise<unknown>;
222
254
  /**
223
255
  * Register a navigation function that lets AGO navigate users to different pages.
224
256
  *
@@ -320,6 +352,9 @@ declare class AgoClient {
320
352
  */
321
353
  notifyContextChanged(): void;
322
354
  /* Excluded from this release type: emitFormEvent */
355
+ /* Excluded from this release type: emitProactiveEvent */
356
+ /* Excluded from this release type: getHttp */
357
+ /* Excluded from this release type: getConfiguredAgent */
323
358
  /**
324
359
  * Enable automatic capture of the current browser page (URL + title).
325
360
  * Injected as a dynamic context entry named `browser-page`.
@@ -329,6 +364,19 @@ declare class AgoClient {
329
364
  * Get the current context snapshot.
330
365
  */
331
366
  getContextSnapshot(): ContextSnapshot | null;
367
+ private buildSendContext;
368
+ /**
369
+ * Record something the user just did so the agent is aware of it on the next
370
+ * message. `actor` defaults to `"user"`. Keep `summary` short and high-signal
371
+ * (no raw payloads, secrets, or PII).
372
+ */
373
+ recordActivity(entry: ActivityInput): void;
374
+ /** Recent user + agent actions, oldest first (a copy). */
375
+ getRecentActivity(): ActivityEntry[];
376
+ clearActivity(): void;
377
+ private addActivity;
378
+ private recordAgentAction;
379
+ private registerActivityContext;
332
380
  /**
333
381
  * Subscribe to an event
334
382
  */
@@ -364,6 +412,7 @@ declare class AgoClient {
364
412
  * Clean up resources
365
413
  */
366
414
  destroy(): void;
415
+ /* Excluded from this release type: reviveAfterDestroy */
367
416
  }
368
417
 
369
418
  /**
@@ -480,6 +529,27 @@ declare interface AgoClientEvents {
480
529
  "connection:status": {
481
530
  connected: boolean;
482
531
  };
532
+ /**
533
+ * A proactive nudge passed every governor gate and is ready to display.
534
+ * `useProactiveNudge` / `<AgoNudge>` consume this; custom UIs should call
535
+ * `client.proactive.shown(nudge)` when they render it (impression tracking
536
+ * + frequency caps), then `accept(nudge)` / `dismiss(nudge)`.
537
+ */
538
+ "nudge:ready": ProactiveNudgeInstance;
539
+ /** A nudge was displayed to the user (fires once per nudge). */
540
+ "nudge:shown": {
541
+ nudge: ProactiveNudgeInstance;
542
+ };
543
+ /** The user dismissed the nudge (its trigger is suppressed, see governor). */
544
+ "nudge:dismissed": {
545
+ nudge: ProactiveNudgeInstance;
546
+ };
547
+ /** The user accepted the nudge (its action ran / the chat is being seeded). */
548
+ "nudge:accepted": {
549
+ nudge: ProactiveNudgeInstance;
550
+ };
551
+ /** A user- or agent-action was recorded into the activity ledger. */
552
+ "activity:recorded": ActivityEntry;
483
553
  }
484
554
 
485
555
  /**
@@ -541,6 +611,24 @@ declare interface AgoConfig {
541
611
  * with `maxResultBytes` on its definition; `Infinity` disables the guard.
542
612
  */
543
613
  maxFunctionResultBytes?: number;
614
+ /**
615
+ * Max number of recent actions kept in the in-memory activity ledger that
616
+ * rides along as the `activity:recent` context entry. Older entries drop
617
+ * first. Default `10`. Larger values give the agent more history at the cost
618
+ * of tokens on every message. Each entry's `data` is also size-clamped (long
619
+ * strings truncated, large arrays capped) so one event can't bloat the context.
620
+ */
621
+ maxActivityEntries?: number;
622
+ /**
623
+ * Enable the proactive mode: declarative triggers evaluated client-side
624
+ * against friction signals (dwell/idle time, rage clicks, route bounces…)
625
+ * that can surface a nudge before the user opens the chat. Equivalent to
626
+ * calling `createAgoProactive(client, proactive)` — the resulting controller
627
+ * is available as `client.proactive`. Requires the tenant-level kill-switch
628
+ * (`GET /api/sdk/v1/config` → `proactive.enabled`) to be on; disabled by
629
+ * default otherwise.
630
+ */
631
+ proactive?: ProactiveOptions;
544
632
  }
545
633
 
546
634
  declare type AgoEventHandler<K extends AgoEventName> = (data: AgoClientEvents[K]) => void;
@@ -995,6 +1083,43 @@ declare interface FormSchema {
995
1083
  required?: string[];
996
1084
  }
997
1085
 
1086
+ /**
1087
+ * HTTP client with authentication headers
1088
+ */
1089
+ declare class HttpClient {
1090
+ private baseUrl;
1091
+ private headers;
1092
+ constructor(config: AgoConfig);
1093
+ /**
1094
+ * Update configuration (e.g., JWT token)
1095
+ */
1096
+ updateConfig(config: Partial<AgoConfig>): void;
1097
+ /**
1098
+ * Make a GET request
1099
+ */
1100
+ get<T>(path: string): Promise<T>;
1101
+ /**
1102
+ * Make a POST request with JSON body.
1103
+ *
1104
+ * `keepalive: true` lets the request survive a page unload (used by the
1105
+ * proactive event tracker's flush-on-hide — sendBeacon can't carry the auth
1106
+ * headers, so it's a keepalive fetch instead).
1107
+ */
1108
+ post<T>(path: string, body?: unknown, options?: {
1109
+ keepalive?: boolean;
1110
+ }): Promise<T>;
1111
+ /**
1112
+ * Make a POST request and return the raw Response (for streaming)
1113
+ */
1114
+ postStream(path: string, body?: unknown): Promise<Response>;
1115
+ /**
1116
+ * Make a POST request with FormData (for file uploads)
1117
+ */
1118
+ postFormData(path: string, formData: FormData): Promise<Response>;
1119
+ private request;
1120
+ private handleErrorResponse;
1121
+ }
1122
+
998
1123
  /**
999
1124
  * Options for {@link loadFormCollector} / the name-only form of `useFormCollector`:
1000
1125
  * the `name` is required and the definition is fetched from the backend, while any
@@ -1231,6 +1356,182 @@ export declare interface MountChatWidgetOptions {
1231
1356
  }) => void;
1232
1357
  }
1233
1358
 
1359
+ /**
1360
+ * Optional action attached to a nudge. Accepting a `functionName` action
1361
+ * executes the registered client function (same `FunctionRegistry` path as
1362
+ * agent-invoked calls); `setPageState` applies values through the registered
1363
+ * page-state controls.
1364
+ */
1365
+ declare type NudgeAction = {
1366
+ label: string;
1367
+ functionName: string;
1368
+ arguments?: Record<string, unknown>;
1369
+ } | {
1370
+ label: string;
1371
+ setPageState: Record<string, unknown>;
1372
+ };
1373
+
1374
+ /**
1375
+ * Controller returned by {@link createAgoProactive} (also available as
1376
+ * `client.proactive`).
1377
+ */
1378
+ declare interface ProactiveController {
1379
+ /** Persistently opt this browser out of proactive nudges. */
1380
+ optOut(): void;
1381
+ /** Undo {@link optOut}. */
1382
+ optIn(): void;
1383
+ isOptedOut(): boolean;
1384
+ /**
1385
+ * Tell the governor the user is already engaged (e.g. the chat widget is
1386
+ * open) — nudges are suppressed while `true`. Call from the UI layer.
1387
+ */
1388
+ setEngaged(engaged: boolean): void;
1389
+ /** App-pushed field error counter (field NAME only — never values). */
1390
+ signalFieldError(fieldName: string): void;
1391
+ /** Current aggregated friction snapshot. */
1392
+ getSignalsSnapshot(): SignalsSnapshot;
1393
+ /** The nudge currently occupying the single-nudge slot, if any. */
1394
+ getActiveNudge(): ProactiveNudgeInstance | null;
1395
+ /**
1396
+ * Mark the nudge as displayed. Idempotent per nudge; counts it against the
1397
+ * frequency caps, tracks the impression, and emits `nudge:shown`.
1398
+ */
1399
+ shown(nudge: ProactiveNudgeInstance): void;
1400
+ /**
1401
+ * Accept the nudge: run its action (if any), emit `nudge:accepted`, track,
1402
+ * and — for agent nudges or nudges with a `goal` — pre-seed the chat with a
1403
+ * hidden kickoff message so the agent starts the turn with full context.
1404
+ */
1405
+ accept(nudge: ProactiveNudgeInstance): Promise<void>;
1406
+ /** Dismiss the nudge: suppress the trigger, track, emit `nudge:dismissed`. */
1407
+ dismiss(nudge: ProactiveNudgeInstance): void;
1408
+ /** Report a downstream conversion attributable to the nudge (analytics only). */
1409
+ markConverted(nudge: ProactiveNudgeInstance): void;
1410
+ /** Detach everything: listeners, timers, context provider, event flush. */
1411
+ destroy(): void;
1412
+ }
1413
+
1414
+ /** A concrete nudge produced by the engine, carried by every `nudge:*` event. */
1415
+ declare interface ProactiveNudgeInstance {
1416
+ /** Client-generated uuid for this nudge instance (`client_nudge_id`). */
1417
+ id: string;
1418
+ triggerId: string;
1419
+ /** `static` = configured message; `agent` = backend LLM evaluation. */
1420
+ source: "static" | "agent";
1421
+ message: string;
1422
+ action?: NudgeAction;
1423
+ goal?: string;
1424
+ /** See {@link ProactiveTrigger.kickoff}. */
1425
+ kickoff?: string;
1426
+ createdAt: Date;
1427
+ /** Server-side nudge id (agent nudges only). */
1428
+ serverNudgeId?: string;
1429
+ }
1430
+
1431
+ /** Options for {@link createAgoProactive} / `AgoConfig.proactive`. */
1432
+ declare interface ProactiveOptions {
1433
+ triggers: ProactiveTrigger[];
1434
+ /**
1435
+ * Global caps on nudges actually shown. `perSession` is in-memory (page
1436
+ * lifetime); `perDay` is persisted in localStorage with a date rollover —
1437
+ * best-effort by design (private browsing resets it); the costly LLM path is
1438
+ * additionally capped server-side.
1439
+ */
1440
+ frequencyCap?: {
1441
+ perSession?: number;
1442
+ perDay?: number;
1443
+ };
1444
+ /** Evaluation tick, ms. Default 1000. Zero network per tick. */
1445
+ tickMs?: number;
1446
+ /** Storage backend for persisted governance state. Default `localStorage`. */
1447
+ storage?: StorageLike;
1448
+ /** Storage key for persisted governance state. Default `"ago_proactive"`. */
1449
+ storageKey?: string;
1450
+ /** Tuning of the signal detectors (rage-click window, throttles…). */
1451
+ signals?: SignalCollectorTuning;
1452
+ /**
1453
+ * Local demos and tests ONLY: bypass the remote kill-switch. When set, the
1454
+ * `GET /config` fetch is skipped and the kill-switch takes this value.
1455
+ * Leave unset in production — the tenant admin controls the feature, and
1456
+ * the evaluate endpoint stays gated server-side regardless.
1457
+ */
1458
+ enabledOverride?: boolean;
1459
+ }
1460
+
1461
+ /** A declarative proactive trigger. */
1462
+ declare interface ProactiveTrigger {
1463
+ /** Stable id, used for cooldowns, dismissal memory, and analytics. */
1464
+ id: string;
1465
+ /** Conjunction of matchers (see {@link ProactiveTriggerWhen}). */
1466
+ when: ProactiveTriggerWhen;
1467
+ /**
1468
+ * Min time between two firings of this trigger (persisted across reloads).
1469
+ * A firing is the moment the trigger passes the gates — including an agent
1470
+ * evaluation that decides NOT to intervene, so a persistent condition can't
1471
+ * hammer the evaluate endpoint. Default 60 000.
1472
+ */
1473
+ cooldownMs?: number;
1474
+ /**
1475
+ * `'agent'` asks the backend's fast-LLM second filter whether (and how) to
1476
+ * intervene; a `static` object shows the given message with no network call.
1477
+ */
1478
+ intervene: "agent" | {
1479
+ type: "static";
1480
+ message: string;
1481
+ action?: NudgeAction;
1482
+ };
1483
+ /**
1484
+ * What the agent should help with. Sent to the evaluate endpoint, and used to
1485
+ * pre-seed the chat turn when the user accepts the nudge.
1486
+ */
1487
+ goal?: string;
1488
+ /**
1489
+ * User-voice line used to OPEN the conversation when the user accepts this
1490
+ * nudge and no conversation exists yet — a hidden kickoff cannot start one
1491
+ * (the backend rejects it). Sent as a visible user message, so write it in
1492
+ * the app's language ("Oui, aidez-moi à choisir !"). When a conversation is
1493
+ * already open, the SDK sends a hidden meta kickoff instead and this field
1494
+ * is unused. Without it, accepting with no open conversation skips the chat
1495
+ * pre-seed (the nudge action still runs).
1496
+ */
1497
+ kickoff?: string;
1498
+ /**
1499
+ * How long a dismissal of this trigger's nudge suppresses it (persisted).
1500
+ * Default 24h.
1501
+ */
1502
+ resurfaceAfterMs?: number;
1503
+ }
1504
+
1505
+ /**
1506
+ * Conditions of a proactive trigger. Pure conjunction: EVERY specified matcher
1507
+ * must pass against the current {@link SignalsSnapshot}. Numeric fields are
1508
+ * `>=` thresholds.
1509
+ */
1510
+ declare interface ProactiveTriggerWhen {
1511
+ /**
1512
+ * Route pattern the current pathname must match. Supports the SDK's route
1513
+ * styles: exact (`/billing`), `:param` segments (`/users/:id`), single-segment
1514
+ * wildcards (`/a/*` / `/b`), and a trailing `/*` that matches one or more
1515
+ * remaining segments (`/dossier/*`).
1516
+ */
1517
+ route?: string;
1518
+ /** Min time since the last user activity, ms. */
1519
+ idleMs?: number;
1520
+ /** Min time spent on the current route, ms. */
1521
+ dwellMs?: number;
1522
+ /**
1523
+ * Partial deep match against the registered page state (funnel step,
1524
+ * filters…). Every key present here must deep-match the live value.
1525
+ */
1526
+ pageState?: Partial<Record<string, unknown>>;
1527
+ /** Min rage-click bursts on the current route. */
1528
+ rageClicks?: number;
1529
+ /** Min A→B→A→B route oscillations this session. */
1530
+ routeBounces?: number;
1531
+ /** Per-field minimum error counts (field NAME → min count). */
1532
+ fieldErrors?: Record<string, number>;
1533
+ }
1534
+
1234
1535
  /**
1235
1536
  * Tiny, dependency-free markdown → DOM renderer for the vanilla chat widget.
1236
1537
  *
@@ -1291,6 +1592,54 @@ declare interface SendMessageOptions {
1291
1592
  clientFunctionsMode?: ClientFunctionsMode;
1292
1593
  }
1293
1594
 
1595
+ /** Tuning knobs for the collector's detectors. All optional. */
1596
+ declare interface SignalCollectorTuning {
1597
+ /** Min gap between heavy activity work (route checks, notifications), ms. Default 250. */
1598
+ activityThrottleMs?: number;
1599
+ /** Rage click: clicks needed to count a burst. Default 3. */
1600
+ rageClickCount?: number;
1601
+ /** Rage click: max time between first and last click of a burst, ms. Default 1000. */
1602
+ rageClickWindowMs?: number;
1603
+ /** Rage click: max radius between clicks of a burst, px. Default 24. */
1604
+ rageClickRadiusPx?: number;
1605
+ /** Max routes kept in the recent-route sequence. Default 10. */
1606
+ maxRecentRoutes?: number;
1607
+ /** Max typed signals kept in the ring buffer. Default 50. */
1608
+ maxSignals?: number;
1609
+ }
1610
+
1611
+ /**
1612
+ * Aggregated view of the current friction state. Registered as a dynamic
1613
+ * context provider (key `friction_signals`) so it rides along as
1614
+ * `client_context` on every message, and sent as `signals` to the proactive
1615
+ * evaluate endpoint.
1616
+ */
1617
+ declare interface SignalsSnapshot {
1618
+ /** Current pathname. */
1619
+ route: string;
1620
+ /** Time spent on the current route, ms. */
1621
+ dwellMs: number;
1622
+ /** Time since the last user activity (pointer/key/scroll/touch), ms. */
1623
+ idleMs: number;
1624
+ /** Rage-click bursts detected on the current route. */
1625
+ rageClicks: number;
1626
+ /**
1627
+ * A→B→A→B route oscillations detected in the recent route sequence. Rolling
1628
+ * session counter (cross-route by nature); trigger cooldowns and dismissal
1629
+ * memory keep it from re-firing forever.
1630
+ */
1631
+ routeBounces: number;
1632
+ /** App-pushed field error counters (field NAME → count), current route only. */
1633
+ fieldErrors: Record<string, number>;
1634
+ /** Most recent pathnames, oldest first (bounded). */
1635
+ recentRoutes: string[];
1636
+ /**
1637
+ * Merged `AgoStateControl.get()` snapshot of the registered page-state
1638
+ * controls (funnel step, filters…), or `null` when none are registered.
1639
+ */
1640
+ pageState: Record<string, unknown> | null;
1641
+ }
1642
+
1294
1643
  /**
1295
1644
  * SSE stream chunk data
1296
1645
  */