@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/testing.d.ts 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;
@@ -868,6 +915,43 @@ declare interface FormSchema {
868
915
  required?: string[];
869
916
  }
870
917
 
918
+ /**
919
+ * HTTP client with authentication headers
920
+ */
921
+ declare class HttpClient {
922
+ private baseUrl;
923
+ private headers;
924
+ constructor(config: AgoConfig);
925
+ /**
926
+ * Update configuration (e.g., JWT token)
927
+ */
928
+ updateConfig(config: Partial<AgoConfig>): void;
929
+ /**
930
+ * Make a GET request
931
+ */
932
+ get<T>(path: string): Promise<T>;
933
+ /**
934
+ * Make a POST request with JSON body.
935
+ *
936
+ * `keepalive: true` lets the request survive a page unload (used by the
937
+ * proactive event tracker's flush-on-hide — sendBeacon can't carry the auth
938
+ * headers, so it's a keepalive fetch instead).
939
+ */
940
+ post<T>(path: string, body?: unknown, options?: {
941
+ keepalive?: boolean;
942
+ }): Promise<T>;
943
+ /**
944
+ * Make a POST request and return the raw Response (for streaming)
945
+ */
946
+ postStream(path: string, body?: unknown): Promise<Response>;
947
+ /**
948
+ * Make a POST request with FormData (for file uploads)
949
+ */
950
+ postFormData(path: string, formData: FormData): Promise<Response>;
951
+ private request;
952
+ private handleErrorResponse;
953
+ }
954
+
871
955
  declare type MessageStatus = "IN_PROGRESS" | "DONE" | "ERROR" | "TODO" | "CANCELED"
872
956
  /**
873
957
  * The turn paused on client function call(s) (pause mode): the agent waits for
@@ -906,6 +990,182 @@ export declare interface MockAgoClientOptions {
906
990
 
907
991
  declare type MockFn = (...args: any[]) => any;
908
992
 
993
+ /**
994
+ * Optional action attached to a nudge. Accepting a `functionName` action
995
+ * executes the registered client function (same `FunctionRegistry` path as
996
+ * agent-invoked calls); `setPageState` applies values through the registered
997
+ * page-state controls.
998
+ */
999
+ declare type NudgeAction = {
1000
+ label: string;
1001
+ functionName: string;
1002
+ arguments?: Record<string, unknown>;
1003
+ } | {
1004
+ label: string;
1005
+ setPageState: Record<string, unknown>;
1006
+ };
1007
+
1008
+ /**
1009
+ * Controller returned by {@link createAgoProactive} (also available as
1010
+ * `client.proactive`).
1011
+ */
1012
+ declare interface ProactiveController {
1013
+ /** Persistently opt this browser out of proactive nudges. */
1014
+ optOut(): void;
1015
+ /** Undo {@link optOut}. */
1016
+ optIn(): void;
1017
+ isOptedOut(): boolean;
1018
+ /**
1019
+ * Tell the governor the user is already engaged (e.g. the chat widget is
1020
+ * open) — nudges are suppressed while `true`. Call from the UI layer.
1021
+ */
1022
+ setEngaged(engaged: boolean): void;
1023
+ /** App-pushed field error counter (field NAME only — never values). */
1024
+ signalFieldError(fieldName: string): void;
1025
+ /** Current aggregated friction snapshot. */
1026
+ getSignalsSnapshot(): SignalsSnapshot;
1027
+ /** The nudge currently occupying the single-nudge slot, if any. */
1028
+ getActiveNudge(): ProactiveNudgeInstance | null;
1029
+ /**
1030
+ * Mark the nudge as displayed. Idempotent per nudge; counts it against the
1031
+ * frequency caps, tracks the impression, and emits `nudge:shown`.
1032
+ */
1033
+ shown(nudge: ProactiveNudgeInstance): void;
1034
+ /**
1035
+ * Accept the nudge: run its action (if any), emit `nudge:accepted`, track,
1036
+ * and — for agent nudges or nudges with a `goal` — pre-seed the chat with a
1037
+ * hidden kickoff message so the agent starts the turn with full context.
1038
+ */
1039
+ accept(nudge: ProactiveNudgeInstance): Promise<void>;
1040
+ /** Dismiss the nudge: suppress the trigger, track, emit `nudge:dismissed`. */
1041
+ dismiss(nudge: ProactiveNudgeInstance): void;
1042
+ /** Report a downstream conversion attributable to the nudge (analytics only). */
1043
+ markConverted(nudge: ProactiveNudgeInstance): void;
1044
+ /** Detach everything: listeners, timers, context provider, event flush. */
1045
+ destroy(): void;
1046
+ }
1047
+
1048
+ /** A concrete nudge produced by the engine, carried by every `nudge:*` event. */
1049
+ declare interface ProactiveNudgeInstance {
1050
+ /** Client-generated uuid for this nudge instance (`client_nudge_id`). */
1051
+ id: string;
1052
+ triggerId: string;
1053
+ /** `static` = configured message; `agent` = backend LLM evaluation. */
1054
+ source: "static" | "agent";
1055
+ message: string;
1056
+ action?: NudgeAction;
1057
+ goal?: string;
1058
+ /** See {@link ProactiveTrigger.kickoff}. */
1059
+ kickoff?: string;
1060
+ createdAt: Date;
1061
+ /** Server-side nudge id (agent nudges only). */
1062
+ serverNudgeId?: string;
1063
+ }
1064
+
1065
+ /** Options for {@link createAgoProactive} / `AgoConfig.proactive`. */
1066
+ declare interface ProactiveOptions {
1067
+ triggers: ProactiveTrigger[];
1068
+ /**
1069
+ * Global caps on nudges actually shown. `perSession` is in-memory (page
1070
+ * lifetime); `perDay` is persisted in localStorage with a date rollover —
1071
+ * best-effort by design (private browsing resets it); the costly LLM path is
1072
+ * additionally capped server-side.
1073
+ */
1074
+ frequencyCap?: {
1075
+ perSession?: number;
1076
+ perDay?: number;
1077
+ };
1078
+ /** Evaluation tick, ms. Default 1000. Zero network per tick. */
1079
+ tickMs?: number;
1080
+ /** Storage backend for persisted governance state. Default `localStorage`. */
1081
+ storage?: StorageLike;
1082
+ /** Storage key for persisted governance state. Default `"ago_proactive"`. */
1083
+ storageKey?: string;
1084
+ /** Tuning of the signal detectors (rage-click window, throttles…). */
1085
+ signals?: SignalCollectorTuning;
1086
+ /**
1087
+ * Local demos and tests ONLY: bypass the remote kill-switch. When set, the
1088
+ * `GET /config` fetch is skipped and the kill-switch takes this value.
1089
+ * Leave unset in production — the tenant admin controls the feature, and
1090
+ * the evaluate endpoint stays gated server-side regardless.
1091
+ */
1092
+ enabledOverride?: boolean;
1093
+ }
1094
+
1095
+ /** A declarative proactive trigger. */
1096
+ declare interface ProactiveTrigger {
1097
+ /** Stable id, used for cooldowns, dismissal memory, and analytics. */
1098
+ id: string;
1099
+ /** Conjunction of matchers (see {@link ProactiveTriggerWhen}). */
1100
+ when: ProactiveTriggerWhen;
1101
+ /**
1102
+ * Min time between two firings of this trigger (persisted across reloads).
1103
+ * A firing is the moment the trigger passes the gates — including an agent
1104
+ * evaluation that decides NOT to intervene, so a persistent condition can't
1105
+ * hammer the evaluate endpoint. Default 60 000.
1106
+ */
1107
+ cooldownMs?: number;
1108
+ /**
1109
+ * `'agent'` asks the backend's fast-LLM second filter whether (and how) to
1110
+ * intervene; a `static` object shows the given message with no network call.
1111
+ */
1112
+ intervene: "agent" | {
1113
+ type: "static";
1114
+ message: string;
1115
+ action?: NudgeAction;
1116
+ };
1117
+ /**
1118
+ * What the agent should help with. Sent to the evaluate endpoint, and used to
1119
+ * pre-seed the chat turn when the user accepts the nudge.
1120
+ */
1121
+ goal?: string;
1122
+ /**
1123
+ * User-voice line used to OPEN the conversation when the user accepts this
1124
+ * nudge and no conversation exists yet — a hidden kickoff cannot start one
1125
+ * (the backend rejects it). Sent as a visible user message, so write it in
1126
+ * the app's language ("Oui, aidez-moi à choisir !"). When a conversation is
1127
+ * already open, the SDK sends a hidden meta kickoff instead and this field
1128
+ * is unused. Without it, accepting with no open conversation skips the chat
1129
+ * pre-seed (the nudge action still runs).
1130
+ */
1131
+ kickoff?: string;
1132
+ /**
1133
+ * How long a dismissal of this trigger's nudge suppresses it (persisted).
1134
+ * Default 24h.
1135
+ */
1136
+ resurfaceAfterMs?: number;
1137
+ }
1138
+
1139
+ /**
1140
+ * Conditions of a proactive trigger. Pure conjunction: EVERY specified matcher
1141
+ * must pass against the current {@link SignalsSnapshot}. Numeric fields are
1142
+ * `>=` thresholds.
1143
+ */
1144
+ declare interface ProactiveTriggerWhen {
1145
+ /**
1146
+ * Route pattern the current pathname must match. Supports the SDK's route
1147
+ * styles: exact (`/billing`), `:param` segments (`/users/:id`), single-segment
1148
+ * wildcards (`/a/*` / `/b`), and a trailing `/*` that matches one or more
1149
+ * remaining segments (`/dossier/*`).
1150
+ */
1151
+ route?: string;
1152
+ /** Min time since the last user activity, ms. */
1153
+ idleMs?: number;
1154
+ /** Min time spent on the current route, ms. */
1155
+ dwellMs?: number;
1156
+ /**
1157
+ * Partial deep match against the registered page state (funnel step,
1158
+ * filters…). Every key present here must deep-match the live value.
1159
+ */
1160
+ pageState?: Partial<Record<string, unknown>>;
1161
+ /** Min rage-click bursts on the current route. */
1162
+ rageClicks?: number;
1163
+ /** Min A→B→A→B route oscillations this session. */
1164
+ routeBounces?: number;
1165
+ /** Per-field minimum error counts (field NAME → min count). */
1166
+ fieldErrors?: Record<string, number>;
1167
+ }
1168
+
909
1169
  /**
910
1170
  * Hook run before a paused turn is resumed, so the app controls WHEN the
911
1171
  * continuation fires (e.g. wait for the destination page to mount after a
@@ -938,6 +1198,54 @@ declare interface SendMessageOptions {
938
1198
  clientFunctionsMode?: ClientFunctionsMode;
939
1199
  }
940
1200
 
1201
+ /** Tuning knobs for the collector's detectors. All optional. */
1202
+ declare interface SignalCollectorTuning {
1203
+ /** Min gap between heavy activity work (route checks, notifications), ms. Default 250. */
1204
+ activityThrottleMs?: number;
1205
+ /** Rage click: clicks needed to count a burst. Default 3. */
1206
+ rageClickCount?: number;
1207
+ /** Rage click: max time between first and last click of a burst, ms. Default 1000. */
1208
+ rageClickWindowMs?: number;
1209
+ /** Rage click: max radius between clicks of a burst, px. Default 24. */
1210
+ rageClickRadiusPx?: number;
1211
+ /** Max routes kept in the recent-route sequence. Default 10. */
1212
+ maxRecentRoutes?: number;
1213
+ /** Max typed signals kept in the ring buffer. Default 50. */
1214
+ maxSignals?: number;
1215
+ }
1216
+
1217
+ /**
1218
+ * Aggregated view of the current friction state. Registered as a dynamic
1219
+ * context provider (key `friction_signals`) so it rides along as
1220
+ * `client_context` on every message, and sent as `signals` to the proactive
1221
+ * evaluate endpoint.
1222
+ */
1223
+ declare interface SignalsSnapshot {
1224
+ /** Current pathname. */
1225
+ route: string;
1226
+ /** Time spent on the current route, ms. */
1227
+ dwellMs: number;
1228
+ /** Time since the last user activity (pointer/key/scroll/touch), ms. */
1229
+ idleMs: number;
1230
+ /** Rage-click bursts detected on the current route. */
1231
+ rageClicks: number;
1232
+ /**
1233
+ * A→B→A→B route oscillations detected in the recent route sequence. Rolling
1234
+ * session counter (cross-route by nature); trigger cooldowns and dismissal
1235
+ * memory keep it from re-firing forever.
1236
+ */
1237
+ routeBounces: number;
1238
+ /** App-pushed field error counters (field NAME → count), current route only. */
1239
+ fieldErrors: Record<string, number>;
1240
+ /** Most recent pathnames, oldest first (bounded). */
1241
+ recentRoutes: string[];
1242
+ /**
1243
+ * Merged `AgoStateControl.get()` snapshot of the registered page-state
1244
+ * controls (funnel step, filters…), or `null` when none are registered.
1245
+ */
1246
+ pageState: Record<string, unknown> | null;
1247
+ }
1248
+
941
1249
  /**
942
1250
  * SSE stream chunk data
943
1251
  */
@@ -981,6 +1289,9 @@ declare interface SSEChunkData {
981
1289
  waiting_tool_call_ids?: string[];
982
1290
  }
983
1291
 
1292
+ /** The slice of the Web Storage API that {@link createStore} relies on. */
1293
+ declare type StorageLike = Pick<Storage, "getItem" | "setItem">;
1294
+
984
1295
  /**
985
1296
  * Where a completed form is sent.
986
1297
  * - `"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-Br0TWgLO.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 D=require("./rolldown-runtime-16Nf8qvH.cjs"),I=require("./AgoClient-BGkFSNZF.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 _(t){const e=(0,o.shallowRef)(t.get());return(0,o.onScopeDispose)(t.subscribe(n=>{e.value=n})),e}function U(){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=_;exports.useChat=S;exports.useConversation=E;exports.useMessages=M;exports.useProactiveNudge=U;