@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/widget.d.cts CHANGED
@@ -49,6 +49,12 @@ declare class AgoClient {
49
49
  private pendingApprovals;
50
50
  /** App-provided gate deciding WHEN a paused turn resumes (see {@link registerResumeGate}). */
51
51
  private resumeGate;
52
+ /**
53
+ * Proactive-mode controller, set when the client was created with
54
+ * `proactive` options or when `createAgoProactive(client, opts)` was called.
55
+ * `null` otherwise.
56
+ */
57
+ proactive: ProactiveController | null;
52
58
  constructor(config: AgoConfig);
53
59
  /**
54
60
  * Send a message and receive a streaming response
@@ -219,6 +225,14 @@ declare class AgoClient {
219
225
  * Get all registered function schemas
220
226
  */
221
227
  getRegisteredFunctions(): ClientFunctionSchema[];
228
+ /**
229
+ * Execute a registered client function locally, through the same
230
+ * FunctionRegistry path (result-size guard, error wrapping) as agent-invoked
231
+ * calls. Used by proactive nudge actions, where the user's explicit click on
232
+ * the action button constitutes the approval — nothing is submitted to the
233
+ * backend (there is no tool call to answer).
234
+ */
235
+ executeClientFunction(name: string, args: Record<string, unknown>): Promise<unknown>;
222
236
  /**
223
237
  * Register a navigation function that lets AGO navigate users to different pages.
224
238
  *
@@ -320,6 +334,9 @@ declare class AgoClient {
320
334
  */
321
335
  notifyContextChanged(): void;
322
336
  /* Excluded from this release type: emitFormEvent */
337
+ /* Excluded from this release type: emitProactiveEvent */
338
+ /* Excluded from this release type: getHttp */
339
+ /* Excluded from this release type: getConfiguredAgent */
323
340
  /**
324
341
  * Enable automatic capture of the current browser page (URL + title).
325
342
  * Injected as a dynamic context entry named `browser-page`.
@@ -364,6 +381,7 @@ declare class AgoClient {
364
381
  * Clean up resources
365
382
  */
366
383
  destroy(): void;
384
+ /* Excluded from this release type: reviveAfterDestroy */
367
385
  }
368
386
 
369
387
  /**
@@ -480,6 +498,25 @@ declare interface AgoClientEvents {
480
498
  "connection:status": {
481
499
  connected: boolean;
482
500
  };
501
+ /**
502
+ * A proactive nudge passed every governor gate and is ready to display.
503
+ * `useProactiveNudge` / `<AgoNudge>` consume this; custom UIs should call
504
+ * `client.proactive.shown(nudge)` when they render it (impression tracking
505
+ * + frequency caps), then `accept(nudge)` / `dismiss(nudge)`.
506
+ */
507
+ "nudge:ready": ProactiveNudgeInstance;
508
+ /** A nudge was displayed to the user (fires once per nudge). */
509
+ "nudge:shown": {
510
+ nudge: ProactiveNudgeInstance;
511
+ };
512
+ /** The user dismissed the nudge (its trigger is suppressed, see governor). */
513
+ "nudge:dismissed": {
514
+ nudge: ProactiveNudgeInstance;
515
+ };
516
+ /** The user accepted the nudge (its action ran / the chat is being seeded). */
517
+ "nudge:accepted": {
518
+ nudge: ProactiveNudgeInstance;
519
+ };
483
520
  }
484
521
 
485
522
  /**
@@ -541,6 +578,16 @@ declare interface AgoConfig {
541
578
  * with `maxResultBytes` on its definition; `Infinity` disables the guard.
542
579
  */
543
580
  maxFunctionResultBytes?: number;
581
+ /**
582
+ * Enable the proactive mode: declarative triggers evaluated client-side
583
+ * against friction signals (dwell/idle time, rage clicks, route bounces…)
584
+ * that can surface a nudge before the user opens the chat. Equivalent to
585
+ * calling `createAgoProactive(client, proactive)` — the resulting controller
586
+ * is available as `client.proactive`. Requires the tenant-level kill-switch
587
+ * (`GET /api/sdk/v1/config` → `proactive.enabled`) to be on; disabled by
588
+ * default otherwise.
589
+ */
590
+ proactive?: ProactiveOptions;
544
591
  }
545
592
 
546
593
  declare type AgoEventHandler<K extends AgoEventName> = (data: AgoClientEvents[K]) => void;
@@ -995,6 +1042,43 @@ declare interface FormSchema {
995
1042
  required?: string[];
996
1043
  }
997
1044
 
1045
+ /**
1046
+ * HTTP client with authentication headers
1047
+ */
1048
+ declare class HttpClient {
1049
+ private baseUrl;
1050
+ private headers;
1051
+ constructor(config: AgoConfig);
1052
+ /**
1053
+ * Update configuration (e.g., JWT token)
1054
+ */
1055
+ updateConfig(config: Partial<AgoConfig>): void;
1056
+ /**
1057
+ * Make a GET request
1058
+ */
1059
+ get<T>(path: string): Promise<T>;
1060
+ /**
1061
+ * Make a POST request with JSON body.
1062
+ *
1063
+ * `keepalive: true` lets the request survive a page unload (used by the
1064
+ * proactive event tracker's flush-on-hide — sendBeacon can't carry the auth
1065
+ * headers, so it's a keepalive fetch instead).
1066
+ */
1067
+ post<T>(path: string, body?: unknown, options?: {
1068
+ keepalive?: boolean;
1069
+ }): Promise<T>;
1070
+ /**
1071
+ * Make a POST request and return the raw Response (for streaming)
1072
+ */
1073
+ postStream(path: string, body?: unknown): Promise<Response>;
1074
+ /**
1075
+ * Make a POST request with FormData (for file uploads)
1076
+ */
1077
+ postFormData(path: string, formData: FormData): Promise<Response>;
1078
+ private request;
1079
+ private handleErrorResponse;
1080
+ }
1081
+
998
1082
  /**
999
1083
  * Options for {@link loadFormCollector} / the name-only form of `useFormCollector`:
1000
1084
  * the `name` is required and the definition is fetched from the backend, while any
@@ -1231,6 +1315,182 @@ export declare interface MountChatWidgetOptions {
1231
1315
  }) => void;
1232
1316
  }
1233
1317
 
1318
+ /**
1319
+ * Optional action attached to a nudge. Accepting a `functionName` action
1320
+ * executes the registered client function (same `FunctionRegistry` path as
1321
+ * agent-invoked calls); `setPageState` applies values through the registered
1322
+ * page-state controls.
1323
+ */
1324
+ declare type NudgeAction = {
1325
+ label: string;
1326
+ functionName: string;
1327
+ arguments?: Record<string, unknown>;
1328
+ } | {
1329
+ label: string;
1330
+ setPageState: Record<string, unknown>;
1331
+ };
1332
+
1333
+ /**
1334
+ * Controller returned by {@link createAgoProactive} (also available as
1335
+ * `client.proactive`).
1336
+ */
1337
+ declare interface ProactiveController {
1338
+ /** Persistently opt this browser out of proactive nudges. */
1339
+ optOut(): void;
1340
+ /** Undo {@link optOut}. */
1341
+ optIn(): void;
1342
+ isOptedOut(): boolean;
1343
+ /**
1344
+ * Tell the governor the user is already engaged (e.g. the chat widget is
1345
+ * open) — nudges are suppressed while `true`. Call from the UI layer.
1346
+ */
1347
+ setEngaged(engaged: boolean): void;
1348
+ /** App-pushed field error counter (field NAME only — never values). */
1349
+ signalFieldError(fieldName: string): void;
1350
+ /** Current aggregated friction snapshot. */
1351
+ getSignalsSnapshot(): SignalsSnapshot;
1352
+ /** The nudge currently occupying the single-nudge slot, if any. */
1353
+ getActiveNudge(): ProactiveNudgeInstance | null;
1354
+ /**
1355
+ * Mark the nudge as displayed. Idempotent per nudge; counts it against the
1356
+ * frequency caps, tracks the impression, and emits `nudge:shown`.
1357
+ */
1358
+ shown(nudge: ProactiveNudgeInstance): void;
1359
+ /**
1360
+ * Accept the nudge: run its action (if any), emit `nudge:accepted`, track,
1361
+ * and — for agent nudges or nudges with a `goal` — pre-seed the chat with a
1362
+ * hidden kickoff message so the agent starts the turn with full context.
1363
+ */
1364
+ accept(nudge: ProactiveNudgeInstance): Promise<void>;
1365
+ /** Dismiss the nudge: suppress the trigger, track, emit `nudge:dismissed`. */
1366
+ dismiss(nudge: ProactiveNudgeInstance): void;
1367
+ /** Report a downstream conversion attributable to the nudge (analytics only). */
1368
+ markConverted(nudge: ProactiveNudgeInstance): void;
1369
+ /** Detach everything: listeners, timers, context provider, event flush. */
1370
+ destroy(): void;
1371
+ }
1372
+
1373
+ /** A concrete nudge produced by the engine, carried by every `nudge:*` event. */
1374
+ declare interface ProactiveNudgeInstance {
1375
+ /** Client-generated uuid for this nudge instance (`client_nudge_id`). */
1376
+ id: string;
1377
+ triggerId: string;
1378
+ /** `static` = configured message; `agent` = backend LLM evaluation. */
1379
+ source: "static" | "agent";
1380
+ message: string;
1381
+ action?: NudgeAction;
1382
+ goal?: string;
1383
+ /** See {@link ProactiveTrigger.kickoff}. */
1384
+ kickoff?: string;
1385
+ createdAt: Date;
1386
+ /** Server-side nudge id (agent nudges only). */
1387
+ serverNudgeId?: string;
1388
+ }
1389
+
1390
+ /** Options for {@link createAgoProactive} / `AgoConfig.proactive`. */
1391
+ declare interface ProactiveOptions {
1392
+ triggers: ProactiveTrigger[];
1393
+ /**
1394
+ * Global caps on nudges actually shown. `perSession` is in-memory (page
1395
+ * lifetime); `perDay` is persisted in localStorage with a date rollover —
1396
+ * best-effort by design (private browsing resets it); the costly LLM path is
1397
+ * additionally capped server-side.
1398
+ */
1399
+ frequencyCap?: {
1400
+ perSession?: number;
1401
+ perDay?: number;
1402
+ };
1403
+ /** Evaluation tick, ms. Default 1000. Zero network per tick. */
1404
+ tickMs?: number;
1405
+ /** Storage backend for persisted governance state. Default `localStorage`. */
1406
+ storage?: StorageLike;
1407
+ /** Storage key for persisted governance state. Default `"ago_proactive"`. */
1408
+ storageKey?: string;
1409
+ /** Tuning of the signal detectors (rage-click window, throttles…). */
1410
+ signals?: SignalCollectorTuning;
1411
+ /**
1412
+ * Local demos and tests ONLY: bypass the remote kill-switch. When set, the
1413
+ * `GET /config` fetch is skipped and the kill-switch takes this value.
1414
+ * Leave unset in production — the tenant admin controls the feature, and
1415
+ * the evaluate endpoint stays gated server-side regardless.
1416
+ */
1417
+ enabledOverride?: boolean;
1418
+ }
1419
+
1420
+ /** A declarative proactive trigger. */
1421
+ declare interface ProactiveTrigger {
1422
+ /** Stable id, used for cooldowns, dismissal memory, and analytics. */
1423
+ id: string;
1424
+ /** Conjunction of matchers (see {@link ProactiveTriggerWhen}). */
1425
+ when: ProactiveTriggerWhen;
1426
+ /**
1427
+ * Min time between two firings of this trigger (persisted across reloads).
1428
+ * A firing is the moment the trigger passes the gates — including an agent
1429
+ * evaluation that decides NOT to intervene, so a persistent condition can't
1430
+ * hammer the evaluate endpoint. Default 60 000.
1431
+ */
1432
+ cooldownMs?: number;
1433
+ /**
1434
+ * `'agent'` asks the backend's fast-LLM second filter whether (and how) to
1435
+ * intervene; a `static` object shows the given message with no network call.
1436
+ */
1437
+ intervene: "agent" | {
1438
+ type: "static";
1439
+ message: string;
1440
+ action?: NudgeAction;
1441
+ };
1442
+ /**
1443
+ * What the agent should help with. Sent to the evaluate endpoint, and used to
1444
+ * pre-seed the chat turn when the user accepts the nudge.
1445
+ */
1446
+ goal?: string;
1447
+ /**
1448
+ * User-voice line used to OPEN the conversation when the user accepts this
1449
+ * nudge and no conversation exists yet — a hidden kickoff cannot start one
1450
+ * (the backend rejects it). Sent as a visible user message, so write it in
1451
+ * the app's language ("Oui, aidez-moi à choisir !"). When a conversation is
1452
+ * already open, the SDK sends a hidden meta kickoff instead and this field
1453
+ * is unused. Without it, accepting with no open conversation skips the chat
1454
+ * pre-seed (the nudge action still runs).
1455
+ */
1456
+ kickoff?: string;
1457
+ /**
1458
+ * How long a dismissal of this trigger's nudge suppresses it (persisted).
1459
+ * Default 24h.
1460
+ */
1461
+ resurfaceAfterMs?: number;
1462
+ }
1463
+
1464
+ /**
1465
+ * Conditions of a proactive trigger. Pure conjunction: EVERY specified matcher
1466
+ * must pass against the current {@link SignalsSnapshot}. Numeric fields are
1467
+ * `>=` thresholds.
1468
+ */
1469
+ declare interface ProactiveTriggerWhen {
1470
+ /**
1471
+ * Route pattern the current pathname must match. Supports the SDK's route
1472
+ * styles: exact (`/billing`), `:param` segments (`/users/:id`), single-segment
1473
+ * wildcards (`/a/*` / `/b`), and a trailing `/*` that matches one or more
1474
+ * remaining segments (`/dossier/*`).
1475
+ */
1476
+ route?: string;
1477
+ /** Min time since the last user activity, ms. */
1478
+ idleMs?: number;
1479
+ /** Min time spent on the current route, ms. */
1480
+ dwellMs?: number;
1481
+ /**
1482
+ * Partial deep match against the registered page state (funnel step,
1483
+ * filters…). Every key present here must deep-match the live value.
1484
+ */
1485
+ pageState?: Partial<Record<string, unknown>>;
1486
+ /** Min rage-click bursts on the current route. */
1487
+ rageClicks?: number;
1488
+ /** Min A→B→A→B route oscillations this session. */
1489
+ routeBounces?: number;
1490
+ /** Per-field minimum error counts (field NAME → min count). */
1491
+ fieldErrors?: Record<string, number>;
1492
+ }
1493
+
1234
1494
  /**
1235
1495
  * Tiny, dependency-free markdown → DOM renderer for the vanilla chat widget.
1236
1496
  *
@@ -1291,6 +1551,54 @@ declare interface SendMessageOptions {
1291
1551
  clientFunctionsMode?: ClientFunctionsMode;
1292
1552
  }
1293
1553
 
1554
+ /** Tuning knobs for the collector's detectors. All optional. */
1555
+ declare interface SignalCollectorTuning {
1556
+ /** Min gap between heavy activity work (route checks, notifications), ms. Default 250. */
1557
+ activityThrottleMs?: number;
1558
+ /** Rage click: clicks needed to count a burst. Default 3. */
1559
+ rageClickCount?: number;
1560
+ /** Rage click: max time between first and last click of a burst, ms. Default 1000. */
1561
+ rageClickWindowMs?: number;
1562
+ /** Rage click: max radius between clicks of a burst, px. Default 24. */
1563
+ rageClickRadiusPx?: number;
1564
+ /** Max routes kept in the recent-route sequence. Default 10. */
1565
+ maxRecentRoutes?: number;
1566
+ /** Max typed signals kept in the ring buffer. Default 50. */
1567
+ maxSignals?: number;
1568
+ }
1569
+
1570
+ /**
1571
+ * Aggregated view of the current friction state. Registered as a dynamic
1572
+ * context provider (key `friction_signals`) so it rides along as
1573
+ * `client_context` on every message, and sent as `signals` to the proactive
1574
+ * evaluate endpoint.
1575
+ */
1576
+ declare interface SignalsSnapshot {
1577
+ /** Current pathname. */
1578
+ route: string;
1579
+ /** Time spent on the current route, ms. */
1580
+ dwellMs: number;
1581
+ /** Time since the last user activity (pointer/key/scroll/touch), ms. */
1582
+ idleMs: number;
1583
+ /** Rage-click bursts detected on the current route. */
1584
+ rageClicks: number;
1585
+ /**
1586
+ * A→B→A→B route oscillations detected in the recent route sequence. Rolling
1587
+ * session counter (cross-route by nature); trigger cooldowns and dismissal
1588
+ * memory keep it from re-firing forever.
1589
+ */
1590
+ routeBounces: number;
1591
+ /** App-pushed field error counters (field NAME → count), current route only. */
1592
+ fieldErrors: Record<string, number>;
1593
+ /** Most recent pathnames, oldest first (bounded). */
1594
+ recentRoutes: string[];
1595
+ /**
1596
+ * Merged `AgoStateControl.get()` snapshot of the registered page-state
1597
+ * controls (funnel step, filters…), or `null` when none are registered.
1598
+ */
1599
+ pageState: Record<string, unknown> | null;
1600
+ }
1601
+
1294
1602
  /**
1295
1603
  * SSE stream chunk data
1296
1604
  */