@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/vue.d.cts CHANGED
@@ -4,6 +4,22 @@ import { InjectionKey } from 'vue';
4
4
  import { Ref } from 'vue';
5
5
  import { ShallowRef } from 'vue';
6
6
 
7
+ declare interface ActivityEntry {
8
+ ts: number;
9
+ actor: "user" | "agent";
10
+ name: string;
11
+ summary: string;
12
+ data?: Record<string, unknown>;
13
+ }
14
+
15
+ declare interface ActivityInput {
16
+ actor?: "user" | "agent";
17
+ name: string;
18
+ summary: string;
19
+ data?: Record<string, unknown>;
20
+ ts?: number;
21
+ }
22
+
7
23
  export declare const AGO_CLIENT_KEY: InjectionKey<AgoClient>;
8
24
 
9
25
  /**
@@ -44,6 +60,8 @@ declare class AgoClient {
44
60
  private functionRegistry;
45
61
  private contextRegistry;
46
62
  private eventEmitter;
63
+ private activityLedger;
64
+ private lastSentPageState;
47
65
  private config;
48
66
  /** Conversations already warned about an empty reply (one warning each). */
49
67
  private warnedEmptyConversations;
@@ -57,6 +75,12 @@ declare class AgoClient {
57
75
  private pendingApprovals;
58
76
  /** App-provided gate deciding WHEN a paused turn resumes (see {@link registerResumeGate}). */
59
77
  private resumeGate;
78
+ /**
79
+ * Proactive-mode controller, set when the client was created with
80
+ * `proactive` options or when `createAgoProactive(client, opts)` was called.
81
+ * `null` otherwise.
82
+ */
83
+ proactive: ProactiveController | null;
60
84
  constructor(config: AgoConfig);
61
85
  /**
62
86
  * Send a message and receive a streaming response
@@ -227,6 +251,14 @@ declare class AgoClient {
227
251
  * Get all registered function schemas
228
252
  */
229
253
  getRegisteredFunctions(): ClientFunctionSchema[];
254
+ /**
255
+ * Execute a registered client function locally, through the same
256
+ * FunctionRegistry path (result-size guard, error wrapping) as agent-invoked
257
+ * calls. Used by proactive nudge actions, where the user's explicit click on
258
+ * the action button constitutes the approval — nothing is submitted to the
259
+ * backend (there is no tool call to answer).
260
+ */
261
+ executeClientFunction(name: string, args: Record<string, unknown>): Promise<unknown>;
230
262
  /**
231
263
  * Register a navigation function that lets AGO navigate users to different pages.
232
264
  *
@@ -328,6 +360,9 @@ declare class AgoClient {
328
360
  */
329
361
  notifyContextChanged(): void;
330
362
  /* Excluded from this release type: emitFormEvent */
363
+ /* Excluded from this release type: emitProactiveEvent */
364
+ /* Excluded from this release type: getHttp */
365
+ /* Excluded from this release type: getConfiguredAgent */
331
366
  /**
332
367
  * Enable automatic capture of the current browser page (URL + title).
333
368
  * Injected as a dynamic context entry named `browser-page`.
@@ -337,6 +372,19 @@ declare class AgoClient {
337
372
  * Get the current context snapshot.
338
373
  */
339
374
  getContextSnapshot(): ContextSnapshot | null;
375
+ private buildSendContext;
376
+ /**
377
+ * Record something the user just did so the agent is aware of it on the next
378
+ * message. `actor` defaults to `"user"`. Keep `summary` short and high-signal
379
+ * (no raw payloads, secrets, or PII).
380
+ */
381
+ recordActivity(entry: ActivityInput): void;
382
+ /** Recent user + agent actions, oldest first (a copy). */
383
+ getRecentActivity(): ActivityEntry[];
384
+ clearActivity(): void;
385
+ private addActivity;
386
+ private recordAgentAction;
387
+ private registerActivityContext;
340
388
  /**
341
389
  * Subscribe to an event
342
390
  */
@@ -372,6 +420,7 @@ declare class AgoClient {
372
420
  * Clean up resources
373
421
  */
374
422
  destroy(): void;
423
+ /* Excluded from this release type: reviveAfterDestroy */
375
424
  }
376
425
 
377
426
  /**
@@ -488,6 +537,27 @@ declare interface AgoClientEvents {
488
537
  "connection:status": {
489
538
  connected: boolean;
490
539
  };
540
+ /**
541
+ * A proactive nudge passed every governor gate and is ready to display.
542
+ * `useProactiveNudge` / `<AgoNudge>` consume this; custom UIs should call
543
+ * `client.proactive.shown(nudge)` when they render it (impression tracking
544
+ * + frequency caps), then `accept(nudge)` / `dismiss(nudge)`.
545
+ */
546
+ "nudge:ready": ProactiveNudgeInstance;
547
+ /** A nudge was displayed to the user (fires once per nudge). */
548
+ "nudge:shown": {
549
+ nudge: ProactiveNudgeInstance;
550
+ };
551
+ /** The user dismissed the nudge (its trigger is suppressed, see governor). */
552
+ "nudge:dismissed": {
553
+ nudge: ProactiveNudgeInstance;
554
+ };
555
+ /** The user accepted the nudge (its action ran / the chat is being seeded). */
556
+ "nudge:accepted": {
557
+ nudge: ProactiveNudgeInstance;
558
+ };
559
+ /** A user- or agent-action was recorded into the activity ledger. */
560
+ "activity:recorded": ActivityEntry;
491
561
  }
492
562
 
493
563
  /**
@@ -549,6 +619,24 @@ export declare interface AgoConfig {
549
619
  * with `maxResultBytes` on its definition; `Infinity` disables the guard.
550
620
  */
551
621
  maxFunctionResultBytes?: number;
622
+ /**
623
+ * Max number of recent actions kept in the in-memory activity ledger that
624
+ * rides along as the `activity:recent` context entry. Older entries drop
625
+ * first. Default `10`. Larger values give the agent more history at the cost
626
+ * of tokens on every message. Each entry's `data` is also size-clamped (long
627
+ * strings truncated, large arrays capped) so one event can't bloat the context.
628
+ */
629
+ maxActivityEntries?: number;
630
+ /**
631
+ * Enable the proactive mode: declarative triggers evaluated client-side
632
+ * against friction signals (dwell/idle time, rage clicks, route bounces…)
633
+ * that can surface a nudge before the user opens the chat. Equivalent to
634
+ * calling `createAgoProactive(client, proactive)` — the resulting controller
635
+ * is available as `client.proactive`. Requires the tenant-level kill-switch
636
+ * (`GET /api/sdk/v1/config` → `proactive.enabled`) to be on; disabled by
637
+ * default otherwise.
638
+ */
639
+ proactive?: ProactiveOptions;
552
640
  }
553
641
 
554
642
  declare type AgoEventHandler<K extends AgoEventName> = (data: AgoClientEvents[K]) => void;
@@ -892,6 +980,43 @@ declare interface FormSchema {
892
980
  required?: string[];
893
981
  }
894
982
 
983
+ /**
984
+ * HTTP client with authentication headers
985
+ */
986
+ declare class HttpClient {
987
+ private baseUrl;
988
+ private headers;
989
+ constructor(config: AgoConfig);
990
+ /**
991
+ * Update configuration (e.g., JWT token)
992
+ */
993
+ updateConfig(config: Partial<AgoConfig>): void;
994
+ /**
995
+ * Make a GET request
996
+ */
997
+ get<T>(path: string): Promise<T>;
998
+ /**
999
+ * Make a POST request with JSON body.
1000
+ *
1001
+ * `keepalive: true` lets the request survive a page unload (used by the
1002
+ * proactive event tracker's flush-on-hide — sendBeacon can't carry the auth
1003
+ * headers, so it's a keepalive fetch instead).
1004
+ */
1005
+ post<T>(path: string, body?: unknown, options?: {
1006
+ keepalive?: boolean;
1007
+ }): Promise<T>;
1008
+ /**
1009
+ * Make a POST request and return the raw Response (for streaming)
1010
+ */
1011
+ postStream(path: string, body?: unknown): Promise<Response>;
1012
+ /**
1013
+ * Make a POST request with FormData (for file uploads)
1014
+ */
1015
+ postFormData(path: string, formData: FormData): Promise<Response>;
1016
+ private request;
1017
+ private handleErrorResponse;
1018
+ }
1019
+
895
1020
  declare type MessageStatus = "IN_PROGRESS" | "DONE" | "ERROR" | "TODO" | "CANCELED"
896
1021
  /**
897
1022
  * The turn paused on client function call(s) (pause mode): the agent waits for
@@ -908,6 +1033,182 @@ declare type MessageStatus_2 = "IN_PROGRESS" | "DONE" | "ERROR" | "TODO" | "CANC
908
1033
  */
909
1034
  | "WAITING_CLIENT";
910
1035
 
1036
+ /**
1037
+ * Optional action attached to a nudge. Accepting a `functionName` action
1038
+ * executes the registered client function (same `FunctionRegistry` path as
1039
+ * agent-invoked calls); `setPageState` applies values through the registered
1040
+ * page-state controls.
1041
+ */
1042
+ export declare type NudgeAction = {
1043
+ label: string;
1044
+ functionName: string;
1045
+ arguments?: Record<string, unknown>;
1046
+ } | {
1047
+ label: string;
1048
+ setPageState: Record<string, unknown>;
1049
+ };
1050
+
1051
+ /**
1052
+ * Controller returned by {@link createAgoProactive} (also available as
1053
+ * `client.proactive`).
1054
+ */
1055
+ export declare interface ProactiveController {
1056
+ /** Persistently opt this browser out of proactive nudges. */
1057
+ optOut(): void;
1058
+ /** Undo {@link optOut}. */
1059
+ optIn(): void;
1060
+ isOptedOut(): boolean;
1061
+ /**
1062
+ * Tell the governor the user is already engaged (e.g. the chat widget is
1063
+ * open) — nudges are suppressed while `true`. Call from the UI layer.
1064
+ */
1065
+ setEngaged(engaged: boolean): void;
1066
+ /** App-pushed field error counter (field NAME only — never values). */
1067
+ signalFieldError(fieldName: string): void;
1068
+ /** Current aggregated friction snapshot. */
1069
+ getSignalsSnapshot(): SignalsSnapshot;
1070
+ /** The nudge currently occupying the single-nudge slot, if any. */
1071
+ getActiveNudge(): ProactiveNudgeInstance | null;
1072
+ /**
1073
+ * Mark the nudge as displayed. Idempotent per nudge; counts it against the
1074
+ * frequency caps, tracks the impression, and emits `nudge:shown`.
1075
+ */
1076
+ shown(nudge: ProactiveNudgeInstance): void;
1077
+ /**
1078
+ * Accept the nudge: run its action (if any), emit `nudge:accepted`, track,
1079
+ * and — for agent nudges or nudges with a `goal` — pre-seed the chat with a
1080
+ * hidden kickoff message so the agent starts the turn with full context.
1081
+ */
1082
+ accept(nudge: ProactiveNudgeInstance): Promise<void>;
1083
+ /** Dismiss the nudge: suppress the trigger, track, emit `nudge:dismissed`. */
1084
+ dismiss(nudge: ProactiveNudgeInstance): void;
1085
+ /** Report a downstream conversion attributable to the nudge (analytics only). */
1086
+ markConverted(nudge: ProactiveNudgeInstance): void;
1087
+ /** Detach everything: listeners, timers, context provider, event flush. */
1088
+ destroy(): void;
1089
+ }
1090
+
1091
+ /** A concrete nudge produced by the engine, carried by every `nudge:*` event. */
1092
+ export declare interface ProactiveNudgeInstance {
1093
+ /** Client-generated uuid for this nudge instance (`client_nudge_id`). */
1094
+ id: string;
1095
+ triggerId: string;
1096
+ /** `static` = configured message; `agent` = backend LLM evaluation. */
1097
+ source: "static" | "agent";
1098
+ message: string;
1099
+ action?: NudgeAction;
1100
+ goal?: string;
1101
+ /** See {@link ProactiveTrigger.kickoff}. */
1102
+ kickoff?: string;
1103
+ createdAt: Date;
1104
+ /** Server-side nudge id (agent nudges only). */
1105
+ serverNudgeId?: string;
1106
+ }
1107
+
1108
+ /** Options for {@link createAgoProactive} / `AgoConfig.proactive`. */
1109
+ export declare interface ProactiveOptions {
1110
+ triggers: ProactiveTrigger[];
1111
+ /**
1112
+ * Global caps on nudges actually shown. `perSession` is in-memory (page
1113
+ * lifetime); `perDay` is persisted in localStorage with a date rollover —
1114
+ * best-effort by design (private browsing resets it); the costly LLM path is
1115
+ * additionally capped server-side.
1116
+ */
1117
+ frequencyCap?: {
1118
+ perSession?: number;
1119
+ perDay?: number;
1120
+ };
1121
+ /** Evaluation tick, ms. Default 1000. Zero network per tick. */
1122
+ tickMs?: number;
1123
+ /** Storage backend for persisted governance state. Default `localStorage`. */
1124
+ storage?: StorageLike;
1125
+ /** Storage key for persisted governance state. Default `"ago_proactive"`. */
1126
+ storageKey?: string;
1127
+ /** Tuning of the signal detectors (rage-click window, throttles…). */
1128
+ signals?: SignalCollectorTuning;
1129
+ /**
1130
+ * Local demos and tests ONLY: bypass the remote kill-switch. When set, the
1131
+ * `GET /config` fetch is skipped and the kill-switch takes this value.
1132
+ * Leave unset in production — the tenant admin controls the feature, and
1133
+ * the evaluate endpoint stays gated server-side regardless.
1134
+ */
1135
+ enabledOverride?: boolean;
1136
+ }
1137
+
1138
+ /** A declarative proactive trigger. */
1139
+ export declare interface ProactiveTrigger {
1140
+ /** Stable id, used for cooldowns, dismissal memory, and analytics. */
1141
+ id: string;
1142
+ /** Conjunction of matchers (see {@link ProactiveTriggerWhen}). */
1143
+ when: ProactiveTriggerWhen;
1144
+ /**
1145
+ * Min time between two firings of this trigger (persisted across reloads).
1146
+ * A firing is the moment the trigger passes the gates — including an agent
1147
+ * evaluation that decides NOT to intervene, so a persistent condition can't
1148
+ * hammer the evaluate endpoint. Default 60 000.
1149
+ */
1150
+ cooldownMs?: number;
1151
+ /**
1152
+ * `'agent'` asks the backend's fast-LLM second filter whether (and how) to
1153
+ * intervene; a `static` object shows the given message with no network call.
1154
+ */
1155
+ intervene: "agent" | {
1156
+ type: "static";
1157
+ message: string;
1158
+ action?: NudgeAction;
1159
+ };
1160
+ /**
1161
+ * What the agent should help with. Sent to the evaluate endpoint, and used to
1162
+ * pre-seed the chat turn when the user accepts the nudge.
1163
+ */
1164
+ goal?: string;
1165
+ /**
1166
+ * User-voice line used to OPEN the conversation when the user accepts this
1167
+ * nudge and no conversation exists yet — a hidden kickoff cannot start one
1168
+ * (the backend rejects it). Sent as a visible user message, so write it in
1169
+ * the app's language ("Oui, aidez-moi à choisir !"). When a conversation is
1170
+ * already open, the SDK sends a hidden meta kickoff instead and this field
1171
+ * is unused. Without it, accepting with no open conversation skips the chat
1172
+ * pre-seed (the nudge action still runs).
1173
+ */
1174
+ kickoff?: string;
1175
+ /**
1176
+ * How long a dismissal of this trigger's nudge suppresses it (persisted).
1177
+ * Default 24h.
1178
+ */
1179
+ resurfaceAfterMs?: number;
1180
+ }
1181
+
1182
+ /**
1183
+ * Conditions of a proactive trigger. Pure conjunction: EVERY specified matcher
1184
+ * must pass against the current {@link SignalsSnapshot}. Numeric fields are
1185
+ * `>=` thresholds.
1186
+ */
1187
+ declare interface ProactiveTriggerWhen {
1188
+ /**
1189
+ * Route pattern the current pathname must match. Supports the SDK's route
1190
+ * styles: exact (`/billing`), `:param` segments (`/users/:id`), single-segment
1191
+ * wildcards (`/a/*` / `/b`), and a trailing `/*` that matches one or more
1192
+ * remaining segments (`/dossier/*`).
1193
+ */
1194
+ route?: string;
1195
+ /** Min time since the last user activity, ms. */
1196
+ idleMs?: number;
1197
+ /** Min time spent on the current route, ms. */
1198
+ dwellMs?: number;
1199
+ /**
1200
+ * Partial deep match against the registered page state (funnel step,
1201
+ * filters…). Every key present here must deep-match the live value.
1202
+ */
1203
+ pageState?: Partial<Record<string, unknown>>;
1204
+ /** Min rage-click bursts on the current route. */
1205
+ rageClicks?: number;
1206
+ /** Min A→B→A→B route oscillations this session. */
1207
+ routeBounces?: number;
1208
+ /** Per-field minimum error counts (field NAME → min count). */
1209
+ fieldErrors?: Record<string, number>;
1210
+ }
1211
+
911
1212
  /**
912
1213
  * Hook run before a paused turn is resumed, so the app controls WHEN the
913
1214
  * continuation fires (e.g. wait for the destination page to mount after a
@@ -940,6 +1241,54 @@ declare interface SendMessageOptions {
940
1241
  clientFunctionsMode?: ClientFunctionsMode;
941
1242
  }
942
1243
 
1244
+ /** Tuning knobs for the collector's detectors. All optional. */
1245
+ declare interface SignalCollectorTuning {
1246
+ /** Min gap between heavy activity work (route checks, notifications), ms. Default 250. */
1247
+ activityThrottleMs?: number;
1248
+ /** Rage click: clicks needed to count a burst. Default 3. */
1249
+ rageClickCount?: number;
1250
+ /** Rage click: max time between first and last click of a burst, ms. Default 1000. */
1251
+ rageClickWindowMs?: number;
1252
+ /** Rage click: max radius between clicks of a burst, px. Default 24. */
1253
+ rageClickRadiusPx?: number;
1254
+ /** Max routes kept in the recent-route sequence. Default 10. */
1255
+ maxRecentRoutes?: number;
1256
+ /** Max typed signals kept in the ring buffer. Default 50. */
1257
+ maxSignals?: number;
1258
+ }
1259
+
1260
+ /**
1261
+ * Aggregated view of the current friction state. Registered as a dynamic
1262
+ * context provider (key `friction_signals`) so it rides along as
1263
+ * `client_context` on every message, and sent as `signals` to the proactive
1264
+ * evaluate endpoint.
1265
+ */
1266
+ declare interface SignalsSnapshot {
1267
+ /** Current pathname. */
1268
+ route: string;
1269
+ /** Time spent on the current route, ms. */
1270
+ dwellMs: number;
1271
+ /** Time since the last user activity (pointer/key/scroll/touch), ms. */
1272
+ idleMs: number;
1273
+ /** Rage-click bursts detected on the current route. */
1274
+ rageClicks: number;
1275
+ /**
1276
+ * A→B→A→B route oscillations detected in the recent route sequence. Rolling
1277
+ * session counter (cross-route by nature); trigger cooldowns and dismissal
1278
+ * memory keep it from re-firing forever.
1279
+ */
1280
+ routeBounces: number;
1281
+ /** App-pushed field error counters (field NAME → count), current route only. */
1282
+ fieldErrors: Record<string, number>;
1283
+ /** Most recent pathnames, oldest first (bounded). */
1284
+ recentRoutes: string[];
1285
+ /**
1286
+ * Merged `AgoStateControl.get()` snapshot of the registered page-state
1287
+ * controls (funnel step, filters…), or `null` when none are registered.
1288
+ */
1289
+ pageState: Record<string, unknown> | null;
1290
+ }
1291
+
943
1292
  /**
944
1293
  * SSE stream chunk data
945
1294
  */
@@ -983,6 +1332,9 @@ declare interface SSEChunkData {
983
1332
  waiting_tool_call_ids?: string[];
984
1333
  }
985
1334
 
1335
+ /** The slice of the Web Storage API that {@link createStore} relies on. */
1336
+ declare type StorageLike = Pick<Storage, "getItem" | "setItem">;
1337
+
986
1338
  /**
987
1339
  * A minimal observable store: one value, synchronous subscriptions, and
988
1340
  * optional persistence via {@link PersistOptions} (localStorage by default).
@@ -1788,4 +2140,25 @@ declare interface UseMessagesOptions {
1788
2140
  conversationId?: string;
1789
2141
  }
1790
2142
 
2143
+ /**
2144
+ * Consume proactive nudges (see `createAgoProactive` / `AgoConfig.proactive`)
2145
+ * with auto-cleanup on unmount. Vue mirror of the React `useProactiveNudge`.
2146
+ * Receiving a nudge marks it as shown (impression tracking + frequency caps),
2147
+ * so render only ONE consumer per nudge surface.
2148
+ *
2149
+ * ```ts
2150
+ * const { nudge, accept, dismiss } = useProactiveNudge();
2151
+ * ```
2152
+ */
2153
+ export declare function useProactiveNudge(): UseProactiveNudgeResult;
2154
+
2155
+ export declare interface UseProactiveNudgeResult {
2156
+ /** The active nudge, or `null` when none is ready. */
2157
+ nudge: ShallowRef<ProactiveNudgeInstance | null>;
2158
+ /** Accept the nudge: run its action, seed the chat when relevant, clear it. */
2159
+ accept: () => Promise<void>;
2160
+ /** Dismiss the nudge (suppresses its trigger, see the governor). */
2161
+ dismiss: () => void;
2162
+ }
2163
+
1791
2164
  export { }