@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/testing.d.ts 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;
@@ -868,6 +956,43 @@ declare interface FormSchema {
868
956
  required?: string[];
869
957
  }
870
958
 
959
+ /**
960
+ * HTTP client with authentication headers
961
+ */
962
+ declare class HttpClient {
963
+ private baseUrl;
964
+ private headers;
965
+ constructor(config: AgoConfig);
966
+ /**
967
+ * Update configuration (e.g., JWT token)
968
+ */
969
+ updateConfig(config: Partial<AgoConfig>): void;
970
+ /**
971
+ * Make a GET request
972
+ */
973
+ get<T>(path: string): Promise<T>;
974
+ /**
975
+ * Make a POST request with JSON body.
976
+ *
977
+ * `keepalive: true` lets the request survive a page unload (used by the
978
+ * proactive event tracker's flush-on-hide — sendBeacon can't carry the auth
979
+ * headers, so it's a keepalive fetch instead).
980
+ */
981
+ post<T>(path: string, body?: unknown, options?: {
982
+ keepalive?: boolean;
983
+ }): Promise<T>;
984
+ /**
985
+ * Make a POST request and return the raw Response (for streaming)
986
+ */
987
+ postStream(path: string, body?: unknown): Promise<Response>;
988
+ /**
989
+ * Make a POST request with FormData (for file uploads)
990
+ */
991
+ postFormData(path: string, formData: FormData): Promise<Response>;
992
+ private request;
993
+ private handleErrorResponse;
994
+ }
995
+
871
996
  declare type MessageStatus = "IN_PROGRESS" | "DONE" | "ERROR" | "TODO" | "CANCELED"
872
997
  /**
873
998
  * The turn paused on client function call(s) (pause mode): the agent waits for
@@ -906,6 +1031,182 @@ export declare interface MockAgoClientOptions {
906
1031
 
907
1032
  declare type MockFn = (...args: any[]) => any;
908
1033
 
1034
+ /**
1035
+ * Optional action attached to a nudge. Accepting a `functionName` action
1036
+ * executes the registered client function (same `FunctionRegistry` path as
1037
+ * agent-invoked calls); `setPageState` applies values through the registered
1038
+ * page-state controls.
1039
+ */
1040
+ declare type NudgeAction = {
1041
+ label: string;
1042
+ functionName: string;
1043
+ arguments?: Record<string, unknown>;
1044
+ } | {
1045
+ label: string;
1046
+ setPageState: Record<string, unknown>;
1047
+ };
1048
+
1049
+ /**
1050
+ * Controller returned by {@link createAgoProactive} (also available as
1051
+ * `client.proactive`).
1052
+ */
1053
+ declare interface ProactiveController {
1054
+ /** Persistently opt this browser out of proactive nudges. */
1055
+ optOut(): void;
1056
+ /** Undo {@link optOut}. */
1057
+ optIn(): void;
1058
+ isOptedOut(): boolean;
1059
+ /**
1060
+ * Tell the governor the user is already engaged (e.g. the chat widget is
1061
+ * open) — nudges are suppressed while `true`. Call from the UI layer.
1062
+ */
1063
+ setEngaged(engaged: boolean): void;
1064
+ /** App-pushed field error counter (field NAME only — never values). */
1065
+ signalFieldError(fieldName: string): void;
1066
+ /** Current aggregated friction snapshot. */
1067
+ getSignalsSnapshot(): SignalsSnapshot;
1068
+ /** The nudge currently occupying the single-nudge slot, if any. */
1069
+ getActiveNudge(): ProactiveNudgeInstance | null;
1070
+ /**
1071
+ * Mark the nudge as displayed. Idempotent per nudge; counts it against the
1072
+ * frequency caps, tracks the impression, and emits `nudge:shown`.
1073
+ */
1074
+ shown(nudge: ProactiveNudgeInstance): void;
1075
+ /**
1076
+ * Accept the nudge: run its action (if any), emit `nudge:accepted`, track,
1077
+ * and — for agent nudges or nudges with a `goal` — pre-seed the chat with a
1078
+ * hidden kickoff message so the agent starts the turn with full context.
1079
+ */
1080
+ accept(nudge: ProactiveNudgeInstance): Promise<void>;
1081
+ /** Dismiss the nudge: suppress the trigger, track, emit `nudge:dismissed`. */
1082
+ dismiss(nudge: ProactiveNudgeInstance): void;
1083
+ /** Report a downstream conversion attributable to the nudge (analytics only). */
1084
+ markConverted(nudge: ProactiveNudgeInstance): void;
1085
+ /** Detach everything: listeners, timers, context provider, event flush. */
1086
+ destroy(): void;
1087
+ }
1088
+
1089
+ /** A concrete nudge produced by the engine, carried by every `nudge:*` event. */
1090
+ declare interface ProactiveNudgeInstance {
1091
+ /** Client-generated uuid for this nudge instance (`client_nudge_id`). */
1092
+ id: string;
1093
+ triggerId: string;
1094
+ /** `static` = configured message; `agent` = backend LLM evaluation. */
1095
+ source: "static" | "agent";
1096
+ message: string;
1097
+ action?: NudgeAction;
1098
+ goal?: string;
1099
+ /** See {@link ProactiveTrigger.kickoff}. */
1100
+ kickoff?: string;
1101
+ createdAt: Date;
1102
+ /** Server-side nudge id (agent nudges only). */
1103
+ serverNudgeId?: string;
1104
+ }
1105
+
1106
+ /** Options for {@link createAgoProactive} / `AgoConfig.proactive`. */
1107
+ declare interface ProactiveOptions {
1108
+ triggers: ProactiveTrigger[];
1109
+ /**
1110
+ * Global caps on nudges actually shown. `perSession` is in-memory (page
1111
+ * lifetime); `perDay` is persisted in localStorage with a date rollover —
1112
+ * best-effort by design (private browsing resets it); the costly LLM path is
1113
+ * additionally capped server-side.
1114
+ */
1115
+ frequencyCap?: {
1116
+ perSession?: number;
1117
+ perDay?: number;
1118
+ };
1119
+ /** Evaluation tick, ms. Default 1000. Zero network per tick. */
1120
+ tickMs?: number;
1121
+ /** Storage backend for persisted governance state. Default `localStorage`. */
1122
+ storage?: StorageLike;
1123
+ /** Storage key for persisted governance state. Default `"ago_proactive"`. */
1124
+ storageKey?: string;
1125
+ /** Tuning of the signal detectors (rage-click window, throttles…). */
1126
+ signals?: SignalCollectorTuning;
1127
+ /**
1128
+ * Local demos and tests ONLY: bypass the remote kill-switch. When set, the
1129
+ * `GET /config` fetch is skipped and the kill-switch takes this value.
1130
+ * Leave unset in production — the tenant admin controls the feature, and
1131
+ * the evaluate endpoint stays gated server-side regardless.
1132
+ */
1133
+ enabledOverride?: boolean;
1134
+ }
1135
+
1136
+ /** A declarative proactive trigger. */
1137
+ declare interface ProactiveTrigger {
1138
+ /** Stable id, used for cooldowns, dismissal memory, and analytics. */
1139
+ id: string;
1140
+ /** Conjunction of matchers (see {@link ProactiveTriggerWhen}). */
1141
+ when: ProactiveTriggerWhen;
1142
+ /**
1143
+ * Min time between two firings of this trigger (persisted across reloads).
1144
+ * A firing is the moment the trigger passes the gates — including an agent
1145
+ * evaluation that decides NOT to intervene, so a persistent condition can't
1146
+ * hammer the evaluate endpoint. Default 60 000.
1147
+ */
1148
+ cooldownMs?: number;
1149
+ /**
1150
+ * `'agent'` asks the backend's fast-LLM second filter whether (and how) to
1151
+ * intervene; a `static` object shows the given message with no network call.
1152
+ */
1153
+ intervene: "agent" | {
1154
+ type: "static";
1155
+ message: string;
1156
+ action?: NudgeAction;
1157
+ };
1158
+ /**
1159
+ * What the agent should help with. Sent to the evaluate endpoint, and used to
1160
+ * pre-seed the chat turn when the user accepts the nudge.
1161
+ */
1162
+ goal?: string;
1163
+ /**
1164
+ * User-voice line used to OPEN the conversation when the user accepts this
1165
+ * nudge and no conversation exists yet — a hidden kickoff cannot start one
1166
+ * (the backend rejects it). Sent as a visible user message, so write it in
1167
+ * the app's language ("Oui, aidez-moi à choisir !"). When a conversation is
1168
+ * already open, the SDK sends a hidden meta kickoff instead and this field
1169
+ * is unused. Without it, accepting with no open conversation skips the chat
1170
+ * pre-seed (the nudge action still runs).
1171
+ */
1172
+ kickoff?: string;
1173
+ /**
1174
+ * How long a dismissal of this trigger's nudge suppresses it (persisted).
1175
+ * Default 24h.
1176
+ */
1177
+ resurfaceAfterMs?: number;
1178
+ }
1179
+
1180
+ /**
1181
+ * Conditions of a proactive trigger. Pure conjunction: EVERY specified matcher
1182
+ * must pass against the current {@link SignalsSnapshot}. Numeric fields are
1183
+ * `>=` thresholds.
1184
+ */
1185
+ declare interface ProactiveTriggerWhen {
1186
+ /**
1187
+ * Route pattern the current pathname must match. Supports the SDK's route
1188
+ * styles: exact (`/billing`), `:param` segments (`/users/:id`), single-segment
1189
+ * wildcards (`/a/*` / `/b`), and a trailing `/*` that matches one or more
1190
+ * remaining segments (`/dossier/*`).
1191
+ */
1192
+ route?: string;
1193
+ /** Min time since the last user activity, ms. */
1194
+ idleMs?: number;
1195
+ /** Min time spent on the current route, ms. */
1196
+ dwellMs?: number;
1197
+ /**
1198
+ * Partial deep match against the registered page state (funnel step,
1199
+ * filters…). Every key present here must deep-match the live value.
1200
+ */
1201
+ pageState?: Partial<Record<string, unknown>>;
1202
+ /** Min rage-click bursts on the current route. */
1203
+ rageClicks?: number;
1204
+ /** Min A→B→A→B route oscillations this session. */
1205
+ routeBounces?: number;
1206
+ /** Per-field minimum error counts (field NAME → min count). */
1207
+ fieldErrors?: Record<string, number>;
1208
+ }
1209
+
909
1210
  /**
910
1211
  * Hook run before a paused turn is resumed, so the app controls WHEN the
911
1212
  * continuation fires (e.g. wait for the destination page to mount after a
@@ -938,6 +1239,54 @@ declare interface SendMessageOptions {
938
1239
  clientFunctionsMode?: ClientFunctionsMode;
939
1240
  }
940
1241
 
1242
+ /** Tuning knobs for the collector's detectors. All optional. */
1243
+ declare interface SignalCollectorTuning {
1244
+ /** Min gap between heavy activity work (route checks, notifications), ms. Default 250. */
1245
+ activityThrottleMs?: number;
1246
+ /** Rage click: clicks needed to count a burst. Default 3. */
1247
+ rageClickCount?: number;
1248
+ /** Rage click: max time between first and last click of a burst, ms. Default 1000. */
1249
+ rageClickWindowMs?: number;
1250
+ /** Rage click: max radius between clicks of a burst, px. Default 24. */
1251
+ rageClickRadiusPx?: number;
1252
+ /** Max routes kept in the recent-route sequence. Default 10. */
1253
+ maxRecentRoutes?: number;
1254
+ /** Max typed signals kept in the ring buffer. Default 50. */
1255
+ maxSignals?: number;
1256
+ }
1257
+
1258
+ /**
1259
+ * Aggregated view of the current friction state. Registered as a dynamic
1260
+ * context provider (key `friction_signals`) so it rides along as
1261
+ * `client_context` on every message, and sent as `signals` to the proactive
1262
+ * evaluate endpoint.
1263
+ */
1264
+ declare interface SignalsSnapshot {
1265
+ /** Current pathname. */
1266
+ route: string;
1267
+ /** Time spent on the current route, ms. */
1268
+ dwellMs: number;
1269
+ /** Time since the last user activity (pointer/key/scroll/touch), ms. */
1270
+ idleMs: number;
1271
+ /** Rage-click bursts detected on the current route. */
1272
+ rageClicks: number;
1273
+ /**
1274
+ * A→B→A→B route oscillations detected in the recent route sequence. Rolling
1275
+ * session counter (cross-route by nature); trigger cooldowns and dismissal
1276
+ * memory keep it from re-firing forever.
1277
+ */
1278
+ routeBounces: number;
1279
+ /** App-pushed field error counters (field NAME → count), current route only. */
1280
+ fieldErrors: Record<string, number>;
1281
+ /** Most recent pathnames, oldest first (bounded). */
1282
+ recentRoutes: string[];
1283
+ /**
1284
+ * Merged `AgoStateControl.get()` snapshot of the registered page-state
1285
+ * controls (funnel step, filters…), or `null` when none are registered.
1286
+ */
1287
+ pageState: Record<string, unknown> | null;
1288
+ }
1289
+
941
1290
  /**
942
1291
  * SSE stream chunk data
943
1292
  */
@@ -981,6 +1330,9 @@ declare interface SSEChunkData {
981
1330
  waiting_tool_call_ids?: string[];
982
1331
  }
983
1332
 
1333
+ /** The slice of the Web Storage API that {@link createStore} relies on. */
1334
+ declare type StorageLike = Pick<Storage, "getItem" | "setItem">;
1335
+
984
1336
  /**
985
1337
  * Where a completed form is sent.
986
1338
  * - `"https://..."` (a bare string) — shorthand for `{ via: "client", url }`: the browser
package/dist/testing.js CHANGED
@@ -1,4 +1,4 @@
1
- import { t as e } from "./createMockClient-we-XoPom.js";
1
+ import { t as e } from "./createMockClient-DcuNlufr.js";
2
2
  export {
3
3
  e as createMockClient
4
4
  };
package/dist/vue.cjs CHANGED
@@ -1 +1 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const E=require("./AgoClient-5VGybmvz.cjs");let o=require("vue");var w=Symbol("ago-client"),S={install(t,n){const e=new E.AgoClient(n);t.provide(w,e)}};function d(t){if(t)return new E.AgoClient(t);const n=(0,o.inject)(w);if(!n)throw new Error("useAgo(): no AgoClient found. Either pass config or install AgoPlugin.");return n}function M(t={}){const n=t.client??d(),e=(0,o.ref)([]),s=(0,o.ref)(t.conversationId),u=(0,o.ref)(!1),r=(0,o.ref)(null),c=a=>{s.value||(s.value=a.conversationId)},f=a=>{const i=e.value.findIndex(v=>v.id===a.messageId);i>=0&&(e.value[i]={...e.value[i],content:e.value[i].content+a.content})},m=a=>{const i=e.value.findIndex(v=>v.id===a.id);i>=0?e.value[i]=a:e.value.push(a),u.value=!1},C=a=>{r.value=new Error(a.error),u.value=!1};(0,o.onMounted)(()=>{n.on("message:start",c),n.on("message:chunk",f),n.on("message:complete",m),n.on("message:error",C)}),(0,o.onUnmounted)(()=>{n.off("message:start",c),n.off("message:chunk",f),n.off("message:complete",m),n.off("message:error",C)});async function g(a,i){u.value=!0,r.value=null;const v={id:`temp-${Date.now()}`,conversationId:s.value||"",content:a,role:"user",status:"DONE",createdAt:new Date},N={id:`temp-assistant-${Date.now()}`,conversationId:s.value||"",content:"",role:"assistant",status:"IN_PROGRESS",createdAt:new Date};e.value.push(v,N);try{const l=await n.sendMessage(a,{conversationId:s.value,files:i});l.conversationId&&!s.value&&(s.value=l.conversationId),e.value=e.value.filter(I=>!I.id.startsWith("temp-"));const A={...v,id:v.id.replace("temp-","user-"),conversationId:l.conversationId};return e.value.some(I=>I.id===l.id)?e.value.push(A):e.value.push(A,l),l}catch(l){return r.value=l instanceof Error?l:new Error("Failed to send"),u.value=!1,e.value=e.value.filter(A=>!A.id.startsWith("temp-")),null}}function h(){e.value=[],s.value=void 0,r.value=null}return{messages:e,isLoading:u,error:r,conversationId:s,sendMessage:g,clearMessages:h}}function p(t={}){const n=t.client??d(),e=t.autoLoad??!0,s=(0,o.ref)([]),u=(0,o.ref)(null),r=(0,o.ref)(!1),c=(0,o.ref)(null);async function f(){r.value=!0,c.value=null;try{s.value=await n.getConversations()}catch(g){c.value=g instanceof Error?g:new Error("Failed to load conversations")}finally{r.value=!1}}async function m(g){r.value=!0,c.value=null;try{u.value=await n.getConversation(g)}catch(h){c.value=h instanceof Error?h:new Error("Failed to load conversation")}finally{r.value=!1}}function C(){u.value=null}return(0,o.onMounted)(()=>{e&&f()}),{conversations:s,currentConversation:u,isLoading:r,error:c,selectConversation:m,startNewConversation:C,refreshConversations:f}}function y(t={}){const n=M({client:t.client,conversationId:t.conversationId}),e=p({client:t.client,autoLoad:t.autoLoad}),s=(0,o.computed)(()=>n.error.value||e.error.value);return{messages:n.messages,isLoading:n.isLoading,error:s,sendMessage:n.sendMessage,clearMessages:n.clearMessages,conversationId:n.conversationId,conversations:e.conversations,currentConversation:e.currentConversation,isConversationsLoading:e.isLoading,selectConversation:e.selectConversation,startNewConversation:e.startNewConversation,refreshConversations:e.refreshConversations}}function L(t,n){const e=d();(0,o.onMounted)(()=>{e.registerFunction(t,n.handler,{description:n.description,parameters:n.parameters,maxResultBytes:n.maxResultBytes})}),(0,o.onUnmounted)(()=>{e.unregisterFunction(t)})}function F(t,n){const e=d();(0,o.onMounted)(()=>{e.registerNavigationFunction(t,n)}),(0,o.onUnmounted)(()=>{e.unregisterNavigationFunction()})}function P(t,n){const e=d(),s=n?.functionName??"setPageState";(0,o.onMounted)(()=>{e.registerPageStateFunction(t,{functionName:s})}),(0,o.onUnmounted)(()=>{e.unregisterPageStateFunction(s)})}function R(t,n){const e=d();(0,o.onMounted)(()=>{e.on(t,n)}),(0,o.onUnmounted)(()=>{e.off(t,n)})}function x(t){const n=(0,o.shallowRef)(t.get());return(0,o.onScopeDispose)(t.subscribe(e=>{n.value=e})),n}exports.AGO_CLIENT_KEY=w;exports.AgoPlugin=S;exports.useAgo=d;exports.useAgoEvents=R;exports.useAgoFunction=L;exports.useAgoNavigation=F;exports.useAgoPageState=P;exports.useAgoStore=x;exports.useChat=y;exports.useConversation=p;exports.useMessages=M;
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const I=require("./AgoClient-Ba3ICq4K.cjs");let o=require("vue");var w=Symbol("ago-client"),N={install(t,e){const n=new I.AgoClient(e);t.provide(w,n)}};function v(t){if(t)return new I.AgoClient(t);const e=(0,o.inject)(w);if(!e)throw new Error("useAgo(): no AgoClient found. Either pass config or install AgoPlugin.");return e}function M(t={}){const e=t.client??v(),n=(0,o.ref)([]),s=(0,o.ref)(t.conversationId),a=(0,o.ref)(!1),u=(0,o.ref)(null),c=r=>{s.value||(s.value=r.conversationId)},f=r=>{const i=n.value.findIndex(d=>d.id===r.messageId);i>=0&&(n.value[i]={...n.value[i],content:n.value[i].content+r.content})},m=r=>{const i=n.value.findIndex(d=>d.id===r.id);i>=0?n.value[i]=r:n.value.push(r),a.value=!1},C=r=>{u.value=new Error(r.error),a.value=!1};(0,o.onMounted)(()=>{e.on("message:start",c),e.on("message:chunk",f),e.on("message:complete",m),e.on("message:error",C)}),(0,o.onUnmounted)(()=>{e.off("message:start",c),e.off("message:chunk",f),e.off("message:complete",m),e.off("message:error",C)});async function g(r,i){a.value=!0,u.value=null;const d={id:`temp-${Date.now()}`,conversationId:s.value||"",content:r,role:"user",status:"DONE",createdAt:new Date},y={id:`temp-assistant-${Date.now()}`,conversationId:s.value||"",content:"",role:"assistant",status:"IN_PROGRESS",createdAt:new Date};n.value.push(d,y);try{const l=await e.sendMessage(r,{conversationId:s.value,files:i});l.conversationId&&!s.value&&(s.value=l.conversationId),n.value=n.value.filter(A=>!A.id.startsWith("temp-"));const p={...d,id:d.id.replace("temp-","user-"),conversationId:l.conversationId};return n.value.some(A=>A.id===l.id)?n.value.push(p):n.value.push(p,l),l}catch(l){return u.value=l instanceof Error?l:new Error("Failed to send"),a.value=!1,n.value=n.value.filter(p=>!p.id.startsWith("temp-")),null}}function h(){n.value=[],s.value=void 0,u.value=null}return{messages:n,isLoading:a,error:u,conversationId:s,sendMessage:g,clearMessages:h}}function E(t={}){const e=t.client??v(),n=t.autoLoad??!0,s=(0,o.ref)([]),a=(0,o.ref)(null),u=(0,o.ref)(!1),c=(0,o.ref)(null);async function f(){u.value=!0,c.value=null;try{s.value=await e.getConversations()}catch(g){c.value=g instanceof Error?g:new Error("Failed to load conversations")}finally{u.value=!1}}async function m(g){u.value=!0,c.value=null;try{a.value=await e.getConversation(g)}catch(h){c.value=h instanceof Error?h:new Error("Failed to load conversation")}finally{u.value=!1}}function C(){a.value=null}return(0,o.onMounted)(()=>{n&&f()}),{conversations:s,currentConversation:a,isLoading:u,error:c,selectConversation:m,startNewConversation:C,refreshConversations:f}}function S(t={}){const e=M({client:t.client,conversationId:t.conversationId}),n=E({client:t.client,autoLoad:t.autoLoad}),s=(0,o.computed)(()=>e.error.value||n.error.value);return{messages:e.messages,isLoading:e.isLoading,error:s,sendMessage:e.sendMessage,clearMessages:e.clearMessages,conversationId:e.conversationId,conversations:n.conversations,currentConversation:n.currentConversation,isConversationsLoading:n.isLoading,selectConversation:n.selectConversation,startNewConversation:n.startNewConversation,refreshConversations:n.refreshConversations}}function L(t,e){const n=v();(0,o.onMounted)(()=>{n.registerFunction(t,e.handler,{description:e.description,parameters:e.parameters,maxResultBytes:e.maxResultBytes})}),(0,o.onUnmounted)(()=>{n.unregisterFunction(t)})}function P(t,e){const n=v();(0,o.onMounted)(()=>{n.registerNavigationFunction(t,e)}),(0,o.onUnmounted)(()=>{n.unregisterNavigationFunction()})}function F(t,e){const n=v(),s=e?.functionName??"setPageState";(0,o.onMounted)(()=>{n.registerPageStateFunction(t,{functionName:s})}),(0,o.onUnmounted)(()=>{n.unregisterPageStateFunction(s)})}function R(t,e){const n=v();(0,o.onMounted)(()=>{n.on(t,e)}),(0,o.onUnmounted)(()=>{n.off(t,e)})}function U(t){const e=(0,o.shallowRef)(t.get());return(0,o.onScopeDispose)(t.subscribe(n=>{e.value=n})),e}function D(){const t=v(),e=(0,o.shallowRef)(null),n=a=>{e.value=a,t.proactive?.shown(a)},s=({nudge:a})=>{e.value?.id===a.id&&(e.value=null)};return(0,o.onMounted)(()=>{t.on("nudge:ready",n),t.on("nudge:accepted",s),t.on("nudge:dismissed",s)}),(0,o.onUnmounted)(()=>{t.off("nudge:ready",n),t.off("nudge:accepted",s),t.off("nudge:dismissed",s)}),{nudge:e,accept:async()=>{const a=e.value;a&&(e.value=null,await t.proactive?.accept(a))},dismiss:()=>{const a=e.value;a&&(e.value=null,t.proactive?.dismiss(a))}}}exports.AGO_CLIENT_KEY=w;exports.AgoPlugin=N;exports.useAgo=v;exports.useAgoEvents=R;exports.useAgoFunction=L;exports.useAgoNavigation=P;exports.useAgoPageState=F;exports.useAgoStore=U;exports.useChat=S;exports.useConversation=E;exports.useMessages=M;exports.useProactiveNudge=D;