@useago/sdk 1.4.2 → 1.4.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 (38) hide show
  1. package/README.md +4 -1
  2. package/dist/AgoClient-CMDVqNaH.cjs +8 -0
  3. package/dist/{AgoClient-BdtuHX7k.js → AgoClient-S8oeNnAE.js} +273 -157
  4. package/dist/angular.cjs +1 -1
  5. package/dist/angular.d.cts +121 -4
  6. package/dist/angular.d.ts +121 -4
  7. package/dist/angular.js +1 -1
  8. package/dist/{createConversationSession-B8zfTL78.cjs → createConversationSession-CmBq7uGi.cjs} +1 -1
  9. package/dist/{createConversationSession-CWpf4u6I.js → createConversationSession-DoUHdVNR.js} +1 -1
  10. package/dist/{createFormCollector-BB_l0Sia.cjs → createFormCollector-Bz_0IJ0Q.cjs} +1 -1
  11. package/dist/{createFormCollector-B4n0_diV.js → createFormCollector-vy-QvFja.js} +1 -1
  12. package/dist/createMockClient-BSr-UV8R.cjs +1 -0
  13. package/dist/{createMockClient-d-arlmCq.js → createMockClient-bAZ9KBHC.js} +18 -15
  14. package/dist/devtools.d.cts +120 -3
  15. package/dist/devtools.d.ts +120 -3
  16. package/dist/index.cjs +1 -1
  17. package/dist/index.d.cts +132 -3
  18. package/dist/index.d.ts +132 -3
  19. package/dist/index.js +4 -4
  20. package/dist/react.cjs +3 -3
  21. package/dist/react.d.cts +134 -9
  22. package/dist/react.d.ts +134 -9
  23. package/dist/react.js +440 -429
  24. package/dist/testing.cjs +1 -1
  25. package/dist/testing.d.cts +120 -3
  26. package/dist/testing.d.ts +120 -3
  27. package/dist/testing.js +1 -1
  28. package/dist/vue.cjs +1 -1
  29. package/dist/vue.d.cts +127 -4
  30. package/dist/vue.d.ts +127 -4
  31. package/dist/vue.js +1 -1
  32. package/dist/widget.cjs +3 -3
  33. package/dist/widget.d.cts +120 -3
  34. package/dist/widget.d.ts +120 -3
  35. package/dist/widget.js +120 -120
  36. package/package.json +1 -1
  37. package/dist/AgoClient-CRAnT4qE.cjs +0 -8
  38. package/dist/createMockClient-ucPENDzz.cjs +0 -1
package/dist/testing.cjs CHANGED
@@ -1 +1 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./createMockClient-ucPENDzz.cjs");exports.createMockClient=e.createMockClient;
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./createMockClient-BSr-UV8R.cjs");exports.createMockClient=e.createMockClient;
@@ -39,12 +39,45 @@ declare class AgoClient {
39
39
  private config;
40
40
  /** Conversations already warned about an empty reply (one warning each). */
41
41
  private warnedEmptyConversations;
42
+ /** Paused turns awaiting auto-resume, keyed by assistant message id. */
43
+ private pendingResumes;
44
+ /** App-provided gate deciding WHEN a paused turn resumes (see {@link registerResumeGate}). */
45
+ private resumeGate;
42
46
  constructor(config: AgoConfig);
43
47
  /**
44
48
  * Send a message and receive a streaming response
45
49
  */
46
50
  sendMessage(content: string, options?: SendMessageOptions): Promise<AgoMessage>;
47
51
  private processSSEResponse;
52
+ private resolveClientFunctionsMode;
53
+ /**
54
+ * Register a gate deciding WHEN a paused turn resumes. The SDK still decides
55
+ * *whether* (it resumes once every waiting result is submitted); the gate only
56
+ * delays the continue call — e.g. `useAgoAutoContinueAfterNavigation` waits for
57
+ * the destination page to register its page state. One gate at a time (last
58
+ * registration wins). Returns an unregister function.
59
+ */
60
+ registerResumeGate(gate: ResumeGate): () => void;
61
+ /**
62
+ * Resume a turn paused on client function results (`WAITING_CLIENT`).
63
+ *
64
+ * Sends the CURRENT page's registered functions and context — the page may
65
+ * have changed since the pause (that's the point of pausing on a navigation) —
66
+ * and streams the continuation through the same event pipeline as
67
+ * `sendMessage`, so `message:chunk` / `message:complete` (or another
68
+ * `message:waiting-client` for chained pauses) fire as usual.
69
+ *
70
+ * The SDK calls this automatically after submitting the waiting results; call
71
+ * it manually only for custom flows (e.g. after restoring a reloaded page via
72
+ * {@link resumePendingClientFunctions}).
73
+ */
74
+ continueMessage(messageId: string): Promise<AgoMessage>;
75
+ /**
76
+ * Record one of the two auto-resume preconditions for a paused turn and fire
77
+ * the resume when both are in (see {@link PendingResume}).
78
+ */
79
+ private markResumeSignal;
80
+ private runAutoResume;
48
81
  /**
49
82
  * Detect a reply that completed as DONE with no content and no activity —
50
83
  * today's backend answers an unknown `agent` slug with an empty 200, which
@@ -77,9 +110,25 @@ declare class AgoClient {
77
110
  */
78
111
  getMessages(conversationId: string): Promise<AgoMessage[]>;
79
112
  /**
80
- * Submit form data for a tool call
113
+ * Resume a turn left paused on client function results by a page reload.
114
+ *
115
+ * A paused turn (pause mode) survives a full reload: the backend keeps the
116
+ * assistant message in `WAITING_CLIENT` with its waiting tool calls. After
117
+ * restoring the conversation (`getConversation`) and re-registering the page's
118
+ * functions, call this: it re-executes each waiting client function through the
119
+ * registry, submits the results, and continues the turn.
120
+ *
121
+ * Opt-in on purpose — re-running functions on reload can be surprising (e.g. a
122
+ * navigation function would navigate again), so the app decides. Returns the
123
+ * resumed turn's final message, or `null` when there was nothing to resume or
124
+ * some waiting function is not registered on this page.
125
+ */
126
+ resumePendingClientFunctions(conversation: Conversation): Promise<AgoMessage | null>;
127
+ /**
128
+ * Submit form data for a tool call. The response's `resume` field (pause mode
129
+ * only) tells whether the paused turn is ready to be resumed.
81
130
  */
82
- submitToolCallForm(toolCallId: string, formData: Record<string, unknown>): Promise<void>;
131
+ submitToolCallForm(toolCallId: string, formData: Record<string, unknown>): Promise<SubmitToolCallResult>;
83
132
  /**
84
133
  * Confirm a tool call
85
134
  */
@@ -152,6 +201,12 @@ declare class AgoClient {
152
201
  * the agent know *where* it is after it navigates (e.g. so auto-continuation
153
202
  * can apply page state on the destination), not just how to navigate away.
154
203
  *
204
+ * Routes may contain `:param` placeholders (`/users/:id`). Each distinct
205
+ * placeholder becomes a top-level string argument of `navigateToPage`
206
+ * (`{ page: "userDetail", id: "42" }`), so one route covers every detail
207
+ * page of an entity. Flat arguments only: nested object parameters are not
208
+ * reliably rendered to the model, so placeholders must not be named `page`.
209
+ *
155
210
  * @param navigate - A callback that performs the navigation (e.g. react-router's navigate)
156
211
  * @param routes - Map of route names to paths, with descriptions for the LLM
157
212
  */
@@ -319,6 +374,19 @@ declare interface AgoClientEvents {
319
374
  */
320
375
  "message:answer-complete": AgoMessage;
321
376
  "message:complete": AgoMessage;
377
+ /**
378
+ * The turn paused on client function call(s) (pause mode): the stream closed
379
+ * with status `WAITING_CLIENT` instead of `DONE`. `message:complete` does NOT
380
+ * fire for this stream — it fires when the resumed turn concludes, so one
381
+ * logical turn still emits exactly one `message:complete`. The SDK submits the
382
+ * function results and resumes automatically; listen to this to know the agent
383
+ * is waiting on the page (e.g. to keep a "working…" indicator up).
384
+ */
385
+ "message:waiting-client": {
386
+ conversationId: string;
387
+ messageId: string;
388
+ waitingToolCallIds: string[];
389
+ };
322
390
  /**
323
391
  * A reply finished as `DONE` with empty content and no tool calls, client
324
392
  * functions, or follow-up replies — usually an unknown `agent` slug (the
@@ -406,6 +474,16 @@ declare interface AgoConfig {
406
474
  * event fires regardless of this setting.
407
475
  */
408
476
  warnOnEmptyReply?: boolean;
477
+ /**
478
+ * How the agent loop treats client function calls (requires backend support):
479
+ * - `"placeholder"` (default): the turn continues immediately on a placeholder
480
+ * result; the real result is only visible to the agent on later turns.
481
+ * - `"pause"`: the turn stops on client function call(s) with status
482
+ * `WAITING_CLIENT`; once every result is submitted, the SDK resumes the SAME
483
+ * turn via `POST /messages/{id}/continue`, so the agent sees the real results.
484
+ * Older backends ignore the flag, so `"pause"` degrades to legacy behavior.
485
+ */
486
+ clientFunctionsMode?: ClientFunctionsMode;
409
487
  }
410
488
 
411
489
  declare type AgoEventHandler<K extends AgoEventName> = (data: AgoClientEvents[K]) => void;
@@ -536,6 +614,9 @@ declare interface ClientFunctionSchema {
536
614
  };
537
615
  }
538
616
 
617
+ /** See {@link AgoConfig.clientFunctionsMode}. */
618
+ declare type ClientFunctionsMode = "placeholder" | "pause";
619
+
539
620
  /**
540
621
  * A single piece of context the client wants the LLM to know about.
541
622
  */
@@ -682,7 +763,13 @@ declare interface FormSchema {
682
763
  required?: string[];
683
764
  }
684
765
 
685
- declare type MessageStatus = "IN_PROGRESS" | "DONE" | "ERROR" | "TODO" | "CANCELED";
766
+ declare type MessageStatus = "IN_PROGRESS" | "DONE" | "ERROR" | "TODO" | "CANCELED"
767
+ /**
768
+ * The turn paused on client function call(s) (pause mode): the agent waits for
769
+ * every waiting call to be submitted, then the turn resumes via
770
+ * `continueMessage`. Not a final state.
771
+ */
772
+ | "WAITING_CLIENT";
686
773
 
687
774
  export declare interface MockAgoClient extends AgoClient {
688
775
  /**
@@ -714,6 +801,17 @@ export declare interface MockAgoClientOptions {
714
801
 
715
802
  declare type MockFn = (...args: any[]) => any;
716
803
 
804
+ /**
805
+ * Hook run before a paused turn is resumed, so the app controls WHEN the
806
+ * continuation fires (e.g. wait for the destination page to mount after a
807
+ * navigation). It must resolve — throwing or hanging blocks the resume; on
808
+ * timeout-style situations resolve anyway and let the agent conclude.
809
+ */
810
+ declare type ResumeGate = (info: {
811
+ conversationId: string;
812
+ messageId: string;
813
+ }) => Promise<void> | void;
814
+
717
815
  /**
718
816
  * Options for sending a message
719
817
  */
@@ -731,6 +829,8 @@ declare interface SendMessageOptions {
731
829
  * Requires backend support for the `hidden` flag; older backends ignore it.
732
830
  */
733
831
  hidden?: boolean;
832
+ /** Per-message override of {@link AgoConfig.clientFunctionsMode}. */
833
+ clientFunctionsMode?: ClientFunctionsMode;
734
834
  }
735
835
 
736
836
  /**
@@ -772,6 +872,8 @@ declare interface SSEChunkData {
772
872
  follow_up_replies?: string[];
773
873
  satisfaction_feedback?: unknown;
774
874
  ask_to_talk_to_human?: boolean;
875
+ /** Tool call ids still awaiting a client result, sent with the final `WAITING_CLIENT` event. */
876
+ waiting_tool_call_ids?: string[];
775
877
  }
776
878
 
777
879
  /**
@@ -796,6 +898,21 @@ declare type SubmitConfig<V = Record<string, unknown>> = string | {
796
898
  destination?: string;
797
899
  } | false;
798
900
 
901
+ /**
902
+ * Response of `POST /tool-calls/{id}/submit`. `resume` is only present when the
903
+ * tool call belongs to a turn paused on client functions (pause mode): `ready`
904
+ * flips to `true` once ALL waiting calls of that message are submitted, meaning
905
+ * the turn can be resumed via `continueMessage(resume.message_id)`.
906
+ */
907
+ declare interface SubmitToolCallResult {
908
+ status: string;
909
+ result?: unknown;
910
+ resume?: {
911
+ message_id: string;
912
+ ready: boolean;
913
+ };
914
+ }
915
+
799
916
  /**
800
917
  * Tool call data from SSE stream
801
918
  */
package/dist/testing.d.ts CHANGED
@@ -39,12 +39,45 @@ declare class AgoClient {
39
39
  private config;
40
40
  /** Conversations already warned about an empty reply (one warning each). */
41
41
  private warnedEmptyConversations;
42
+ /** Paused turns awaiting auto-resume, keyed by assistant message id. */
43
+ private pendingResumes;
44
+ /** App-provided gate deciding WHEN a paused turn resumes (see {@link registerResumeGate}). */
45
+ private resumeGate;
42
46
  constructor(config: AgoConfig);
43
47
  /**
44
48
  * Send a message and receive a streaming response
45
49
  */
46
50
  sendMessage(content: string, options?: SendMessageOptions): Promise<AgoMessage>;
47
51
  private processSSEResponse;
52
+ private resolveClientFunctionsMode;
53
+ /**
54
+ * Register a gate deciding WHEN a paused turn resumes. The SDK still decides
55
+ * *whether* (it resumes once every waiting result is submitted); the gate only
56
+ * delays the continue call — e.g. `useAgoAutoContinueAfterNavigation` waits for
57
+ * the destination page to register its page state. One gate at a time (last
58
+ * registration wins). Returns an unregister function.
59
+ */
60
+ registerResumeGate(gate: ResumeGate): () => void;
61
+ /**
62
+ * Resume a turn paused on client function results (`WAITING_CLIENT`).
63
+ *
64
+ * Sends the CURRENT page's registered functions and context — the page may
65
+ * have changed since the pause (that's the point of pausing on a navigation) —
66
+ * and streams the continuation through the same event pipeline as
67
+ * `sendMessage`, so `message:chunk` / `message:complete` (or another
68
+ * `message:waiting-client` for chained pauses) fire as usual.
69
+ *
70
+ * The SDK calls this automatically after submitting the waiting results; call
71
+ * it manually only for custom flows (e.g. after restoring a reloaded page via
72
+ * {@link resumePendingClientFunctions}).
73
+ */
74
+ continueMessage(messageId: string): Promise<AgoMessage>;
75
+ /**
76
+ * Record one of the two auto-resume preconditions for a paused turn and fire
77
+ * the resume when both are in (see {@link PendingResume}).
78
+ */
79
+ private markResumeSignal;
80
+ private runAutoResume;
48
81
  /**
49
82
  * Detect a reply that completed as DONE with no content and no activity —
50
83
  * today's backend answers an unknown `agent` slug with an empty 200, which
@@ -77,9 +110,25 @@ declare class AgoClient {
77
110
  */
78
111
  getMessages(conversationId: string): Promise<AgoMessage[]>;
79
112
  /**
80
- * Submit form data for a tool call
113
+ * Resume a turn left paused on client function results by a page reload.
114
+ *
115
+ * A paused turn (pause mode) survives a full reload: the backend keeps the
116
+ * assistant message in `WAITING_CLIENT` with its waiting tool calls. After
117
+ * restoring the conversation (`getConversation`) and re-registering the page's
118
+ * functions, call this: it re-executes each waiting client function through the
119
+ * registry, submits the results, and continues the turn.
120
+ *
121
+ * Opt-in on purpose — re-running functions on reload can be surprising (e.g. a
122
+ * navigation function would navigate again), so the app decides. Returns the
123
+ * resumed turn's final message, or `null` when there was nothing to resume or
124
+ * some waiting function is not registered on this page.
125
+ */
126
+ resumePendingClientFunctions(conversation: Conversation): Promise<AgoMessage | null>;
127
+ /**
128
+ * Submit form data for a tool call. The response's `resume` field (pause mode
129
+ * only) tells whether the paused turn is ready to be resumed.
81
130
  */
82
- submitToolCallForm(toolCallId: string, formData: Record<string, unknown>): Promise<void>;
131
+ submitToolCallForm(toolCallId: string, formData: Record<string, unknown>): Promise<SubmitToolCallResult>;
83
132
  /**
84
133
  * Confirm a tool call
85
134
  */
@@ -152,6 +201,12 @@ declare class AgoClient {
152
201
  * the agent know *where* it is after it navigates (e.g. so auto-continuation
153
202
  * can apply page state on the destination), not just how to navigate away.
154
203
  *
204
+ * Routes may contain `:param` placeholders (`/users/:id`). Each distinct
205
+ * placeholder becomes a top-level string argument of `navigateToPage`
206
+ * (`{ page: "userDetail", id: "42" }`), so one route covers every detail
207
+ * page of an entity. Flat arguments only: nested object parameters are not
208
+ * reliably rendered to the model, so placeholders must not be named `page`.
209
+ *
155
210
  * @param navigate - A callback that performs the navigation (e.g. react-router's navigate)
156
211
  * @param routes - Map of route names to paths, with descriptions for the LLM
157
212
  */
@@ -319,6 +374,19 @@ declare interface AgoClientEvents {
319
374
  */
320
375
  "message:answer-complete": AgoMessage;
321
376
  "message:complete": AgoMessage;
377
+ /**
378
+ * The turn paused on client function call(s) (pause mode): the stream closed
379
+ * with status `WAITING_CLIENT` instead of `DONE`. `message:complete` does NOT
380
+ * fire for this stream — it fires when the resumed turn concludes, so one
381
+ * logical turn still emits exactly one `message:complete`. The SDK submits the
382
+ * function results and resumes automatically; listen to this to know the agent
383
+ * is waiting on the page (e.g. to keep a "working…" indicator up).
384
+ */
385
+ "message:waiting-client": {
386
+ conversationId: string;
387
+ messageId: string;
388
+ waitingToolCallIds: string[];
389
+ };
322
390
  /**
323
391
  * A reply finished as `DONE` with empty content and no tool calls, client
324
392
  * functions, or follow-up replies — usually an unknown `agent` slug (the
@@ -406,6 +474,16 @@ declare interface AgoConfig {
406
474
  * event fires regardless of this setting.
407
475
  */
408
476
  warnOnEmptyReply?: boolean;
477
+ /**
478
+ * How the agent loop treats client function calls (requires backend support):
479
+ * - `"placeholder"` (default): the turn continues immediately on a placeholder
480
+ * result; the real result is only visible to the agent on later turns.
481
+ * - `"pause"`: the turn stops on client function call(s) with status
482
+ * `WAITING_CLIENT`; once every result is submitted, the SDK resumes the SAME
483
+ * turn via `POST /messages/{id}/continue`, so the agent sees the real results.
484
+ * Older backends ignore the flag, so `"pause"` degrades to legacy behavior.
485
+ */
486
+ clientFunctionsMode?: ClientFunctionsMode;
409
487
  }
410
488
 
411
489
  declare type AgoEventHandler<K extends AgoEventName> = (data: AgoClientEvents[K]) => void;
@@ -536,6 +614,9 @@ declare interface ClientFunctionSchema {
536
614
  };
537
615
  }
538
616
 
617
+ /** See {@link AgoConfig.clientFunctionsMode}. */
618
+ declare type ClientFunctionsMode = "placeholder" | "pause";
619
+
539
620
  /**
540
621
  * A single piece of context the client wants the LLM to know about.
541
622
  */
@@ -682,7 +763,13 @@ declare interface FormSchema {
682
763
  required?: string[];
683
764
  }
684
765
 
685
- declare type MessageStatus = "IN_PROGRESS" | "DONE" | "ERROR" | "TODO" | "CANCELED";
766
+ declare type MessageStatus = "IN_PROGRESS" | "DONE" | "ERROR" | "TODO" | "CANCELED"
767
+ /**
768
+ * The turn paused on client function call(s) (pause mode): the agent waits for
769
+ * every waiting call to be submitted, then the turn resumes via
770
+ * `continueMessage`. Not a final state.
771
+ */
772
+ | "WAITING_CLIENT";
686
773
 
687
774
  export declare interface MockAgoClient extends AgoClient {
688
775
  /**
@@ -714,6 +801,17 @@ export declare interface MockAgoClientOptions {
714
801
 
715
802
  declare type MockFn = (...args: any[]) => any;
716
803
 
804
+ /**
805
+ * Hook run before a paused turn is resumed, so the app controls WHEN the
806
+ * continuation fires (e.g. wait for the destination page to mount after a
807
+ * navigation). It must resolve — throwing or hanging blocks the resume; on
808
+ * timeout-style situations resolve anyway and let the agent conclude.
809
+ */
810
+ declare type ResumeGate = (info: {
811
+ conversationId: string;
812
+ messageId: string;
813
+ }) => Promise<void> | void;
814
+
717
815
  /**
718
816
  * Options for sending a message
719
817
  */
@@ -731,6 +829,8 @@ declare interface SendMessageOptions {
731
829
  * Requires backend support for the `hidden` flag; older backends ignore it.
732
830
  */
733
831
  hidden?: boolean;
832
+ /** Per-message override of {@link AgoConfig.clientFunctionsMode}. */
833
+ clientFunctionsMode?: ClientFunctionsMode;
734
834
  }
735
835
 
736
836
  /**
@@ -772,6 +872,8 @@ declare interface SSEChunkData {
772
872
  follow_up_replies?: string[];
773
873
  satisfaction_feedback?: unknown;
774
874
  ask_to_talk_to_human?: boolean;
875
+ /** Tool call ids still awaiting a client result, sent with the final `WAITING_CLIENT` event. */
876
+ waiting_tool_call_ids?: string[];
775
877
  }
776
878
 
777
879
  /**
@@ -796,6 +898,21 @@ declare type SubmitConfig<V = Record<string, unknown>> = string | {
796
898
  destination?: string;
797
899
  } | false;
798
900
 
901
+ /**
902
+ * Response of `POST /tool-calls/{id}/submit`. `resume` is only present when the
903
+ * tool call belongs to a turn paused on client functions (pause mode): `ready`
904
+ * flips to `true` once ALL waiting calls of that message are submitted, meaning
905
+ * the turn can be resumed via `continueMessage(resume.message_id)`.
906
+ */
907
+ declare interface SubmitToolCallResult {
908
+ status: string;
909
+ result?: unknown;
910
+ resume?: {
911
+ message_id: string;
912
+ ready: boolean;
913
+ };
914
+ }
915
+
799
916
  /**
800
917
  * Tool call data from SSE stream
801
918
  */
package/dist/testing.js CHANGED
@@ -1,4 +1,4 @@
1
- import { t as e } from "./createMockClient-d-arlmCq.js";
1
+ import { t as e } from "./createMockClient-bAZ9KBHC.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 U=require("./rolldown-runtime-16Nf8qvH.cjs"),p=require("./AgoClient-CRAnT4qE.cjs");let o=require("vue");var I=Symbol("ago-client"),S={install(t,n){const e=new p.AgoClient(n);t.provide(I,e)}};function d(t){if(t)return new p.AgoClient(t);const n=(0,o.inject)(I);if(!n)throw new Error("useAgo(): no AgoClient found. Either pass config or install AgoPlugin.");return n}function E(t={}){const n=t.client??d(),e=(0,o.ref)([]),s=(0,o.ref)(t.conversationId),i=(0,o.ref)(!1),r=(0,o.ref)(null),c=a=>{s.value||(s.value=a.conversationId)},f=a=>{const u=e.value.findIndex(v=>v.id===a.messageId);u>=0&&(e.value[u]={...e.value[u],content:e.value[u].content+a.content})},m=a=>{const u=e.value.findIndex(v=>v.id===a.id);u>=0?e.value[u]=a:e.value.push(a),i.value=!1},C=a=>{r.value=new Error(a.error),i.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,u){i.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:u});l.conversationId&&!s.value&&(s.value=l.conversationId),e.value=e.value.filter(w=>!w.id.startsWith("temp-"));const A={...v,id:v.id.replace("temp-","user-"),conversationId:l.conversationId};return e.value.some(w=>w.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"),i.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:i,error:r,conversationId:s,sendMessage:g,clearMessages:h}}function M(t={}){const n=t.client??d(),e=t.autoLoad??!0,s=(0,o.ref)([]),i=(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{i.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(){i.value=null}return(0,o.onMounted)(()=>{e&&f()}),{conversations:s,currentConversation:i,isLoading:r,error:c,selectConversation:m,startNewConversation:C,refreshConversations:f}}function L(t={}){const n=E({client:t.client,conversationId:t.conversationId}),e=M({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 y(t,n){const e=d();(0,o.onMounted)(()=>{e.registerFunction(t,n.handler,{description:n.description,parameters:n.parameters})}),(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 _(t,n){const e=d();(0,o.onMounted)(()=>{e.on(t,n)}),(0,o.onUnmounted)(()=>{e.off(t,n)})}function D(t){const n=(0,o.shallowRef)(t.get());return(0,o.onScopeDispose)(t.subscribe(e=>{n.value=e})),n}exports.AGO_CLIENT_KEY=I;exports.AgoPlugin=S;exports.useAgo=d;exports.useAgoEvents=_;exports.useAgoFunction=y;exports.useAgoNavigation=F;exports.useAgoPageState=P;exports.useAgoStore=D;exports.useChat=L;exports.useConversation=M;exports.useMessages=E;
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const U=require("./rolldown-runtime-16Nf8qvH.cjs"),p=require("./AgoClient-CMDVqNaH.cjs");let o=require("vue");var I=Symbol("ago-client"),S={install(t,n){const e=new p.AgoClient(n);t.provide(I,e)}};function d(t){if(t)return new p.AgoClient(t);const n=(0,o.inject)(I);if(!n)throw new Error("useAgo(): no AgoClient found. Either pass config or install AgoPlugin.");return n}function E(t={}){const n=t.client??d(),e=(0,o.ref)([]),s=(0,o.ref)(t.conversationId),i=(0,o.ref)(!1),r=(0,o.ref)(null),c=a=>{s.value||(s.value=a.conversationId)},f=a=>{const u=e.value.findIndex(v=>v.id===a.messageId);u>=0&&(e.value[u]={...e.value[u],content:e.value[u].content+a.content})},m=a=>{const u=e.value.findIndex(v=>v.id===a.id);u>=0?e.value[u]=a:e.value.push(a),i.value=!1},C=a=>{r.value=new Error(a.error),i.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,u){i.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:u});l.conversationId&&!s.value&&(s.value=l.conversationId),e.value=e.value.filter(w=>!w.id.startsWith("temp-"));const A={...v,id:v.id.replace("temp-","user-"),conversationId:l.conversationId};return e.value.some(w=>w.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"),i.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:i,error:r,conversationId:s,sendMessage:g,clearMessages:h}}function M(t={}){const n=t.client??d(),e=t.autoLoad??!0,s=(0,o.ref)([]),i=(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{i.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(){i.value=null}return(0,o.onMounted)(()=>{e&&f()}),{conversations:s,currentConversation:i,isLoading:r,error:c,selectConversation:m,startNewConversation:C,refreshConversations:f}}function L(t={}){const n=E({client:t.client,conversationId:t.conversationId}),e=M({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 y(t,n){const e=d();(0,o.onMounted)(()=>{e.registerFunction(t,n.handler,{description:n.description,parameters:n.parameters})}),(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 _(t,n){const e=d();(0,o.onMounted)(()=>{e.on(t,n)}),(0,o.onUnmounted)(()=>{e.off(t,n)})}function D(t){const n=(0,o.shallowRef)(t.get());return(0,o.onScopeDispose)(t.subscribe(e=>{n.value=e})),n}exports.AGO_CLIENT_KEY=I;exports.AgoPlugin=S;exports.useAgo=d;exports.useAgoEvents=_;exports.useAgoFunction=y;exports.useAgoNavigation=F;exports.useAgoPageState=P;exports.useAgoStore=D;exports.useChat=L;exports.useConversation=M;exports.useMessages=E;
package/dist/vue.d.cts CHANGED
@@ -47,12 +47,45 @@ declare class AgoClient {
47
47
  private config;
48
48
  /** Conversations already warned about an empty reply (one warning each). */
49
49
  private warnedEmptyConversations;
50
+ /** Paused turns awaiting auto-resume, keyed by assistant message id. */
51
+ private pendingResumes;
52
+ /** App-provided gate deciding WHEN a paused turn resumes (see {@link registerResumeGate}). */
53
+ private resumeGate;
50
54
  constructor(config: AgoConfig);
51
55
  /**
52
56
  * Send a message and receive a streaming response
53
57
  */
54
58
  sendMessage(content: string, options?: SendMessageOptions): Promise<AgoMessage>;
55
59
  private processSSEResponse;
60
+ private resolveClientFunctionsMode;
61
+ /**
62
+ * Register a gate deciding WHEN a paused turn resumes. The SDK still decides
63
+ * *whether* (it resumes once every waiting result is submitted); the gate only
64
+ * delays the continue call — e.g. `useAgoAutoContinueAfterNavigation` waits for
65
+ * the destination page to register its page state. One gate at a time (last
66
+ * registration wins). Returns an unregister function.
67
+ */
68
+ registerResumeGate(gate: ResumeGate): () => void;
69
+ /**
70
+ * Resume a turn paused on client function results (`WAITING_CLIENT`).
71
+ *
72
+ * Sends the CURRENT page's registered functions and context — the page may
73
+ * have changed since the pause (that's the point of pausing on a navigation) —
74
+ * and streams the continuation through the same event pipeline as
75
+ * `sendMessage`, so `message:chunk` / `message:complete` (or another
76
+ * `message:waiting-client` for chained pauses) fire as usual.
77
+ *
78
+ * The SDK calls this automatically after submitting the waiting results; call
79
+ * it manually only for custom flows (e.g. after restoring a reloaded page via
80
+ * {@link resumePendingClientFunctions}).
81
+ */
82
+ continueMessage(messageId: string): Promise<AgoMessage>;
83
+ /**
84
+ * Record one of the two auto-resume preconditions for a paused turn and fire
85
+ * the resume when both are in (see {@link PendingResume}).
86
+ */
87
+ private markResumeSignal;
88
+ private runAutoResume;
56
89
  /**
57
90
  * Detect a reply that completed as DONE with no content and no activity —
58
91
  * today's backend answers an unknown `agent` slug with an empty 200, which
@@ -85,9 +118,25 @@ declare class AgoClient {
85
118
  */
86
119
  getMessages(conversationId: string): Promise<AgoMessage[]>;
87
120
  /**
88
- * Submit form data for a tool call
121
+ * Resume a turn left paused on client function results by a page reload.
122
+ *
123
+ * A paused turn (pause mode) survives a full reload: the backend keeps the
124
+ * assistant message in `WAITING_CLIENT` with its waiting tool calls. After
125
+ * restoring the conversation (`getConversation`) and re-registering the page's
126
+ * functions, call this: it re-executes each waiting client function through the
127
+ * registry, submits the results, and continues the turn.
128
+ *
129
+ * Opt-in on purpose — re-running functions on reload can be surprising (e.g. a
130
+ * navigation function would navigate again), so the app decides. Returns the
131
+ * resumed turn's final message, or `null` when there was nothing to resume or
132
+ * some waiting function is not registered on this page.
133
+ */
134
+ resumePendingClientFunctions(conversation: Conversation): Promise<AgoMessage | null>;
135
+ /**
136
+ * Submit form data for a tool call. The response's `resume` field (pause mode
137
+ * only) tells whether the paused turn is ready to be resumed.
89
138
  */
90
- submitToolCallForm(toolCallId: string, formData: Record<string, unknown>): Promise<void>;
139
+ submitToolCallForm(toolCallId: string, formData: Record<string, unknown>): Promise<SubmitToolCallResult>;
91
140
  /**
92
141
  * Confirm a tool call
93
142
  */
@@ -160,6 +209,12 @@ declare class AgoClient {
160
209
  * the agent know *where* it is after it navigates (e.g. so auto-continuation
161
210
  * can apply page state on the destination), not just how to navigate away.
162
211
  *
212
+ * Routes may contain `:param` placeholders (`/users/:id`). Each distinct
213
+ * placeholder becomes a top-level string argument of `navigateToPage`
214
+ * (`{ page: "userDetail", id: "42" }`), so one route covers every detail
215
+ * page of an entity. Flat arguments only: nested object parameters are not
216
+ * reliably rendered to the model, so placeholders must not be named `page`.
217
+ *
163
218
  * @param navigate - A callback that performs the navigation (e.g. react-router's navigate)
164
219
  * @param routes - Map of route names to paths, with descriptions for the LLM
165
220
  */
@@ -327,6 +382,19 @@ declare interface AgoClientEvents {
327
382
  */
328
383
  "message:answer-complete": AgoMessage;
329
384
  "message:complete": AgoMessage;
385
+ /**
386
+ * The turn paused on client function call(s) (pause mode): the stream closed
387
+ * with status `WAITING_CLIENT` instead of `DONE`. `message:complete` does NOT
388
+ * fire for this stream — it fires when the resumed turn concludes, so one
389
+ * logical turn still emits exactly one `message:complete`. The SDK submits the
390
+ * function results and resumes automatically; listen to this to know the agent
391
+ * is waiting on the page (e.g. to keep a "working…" indicator up).
392
+ */
393
+ "message:waiting-client": {
394
+ conversationId: string;
395
+ messageId: string;
396
+ waitingToolCallIds: string[];
397
+ };
330
398
  /**
331
399
  * A reply finished as `DONE` with empty content and no tool calls, client
332
400
  * functions, or follow-up replies — usually an unknown `agent` slug (the
@@ -414,6 +482,16 @@ export declare interface AgoConfig {
414
482
  * event fires regardless of this setting.
415
483
  */
416
484
  warnOnEmptyReply?: boolean;
485
+ /**
486
+ * How the agent loop treats client function calls (requires backend support):
487
+ * - `"placeholder"` (default): the turn continues immediately on a placeholder
488
+ * result; the real result is only visible to the agent on later turns.
489
+ * - `"pause"`: the turn stops on client function call(s) with status
490
+ * `WAITING_CLIENT`; once every result is submitted, the SDK resumes the SAME
491
+ * turn via `POST /messages/{id}/continue`, so the agent sees the real results.
492
+ * Older backends ignore the flag, so `"pause"` degrades to legacy behavior.
493
+ */
494
+ clientFunctionsMode?: ClientFunctionsMode;
417
495
  }
418
496
 
419
497
  declare type AgoEventHandler<K extends AgoEventName> = (data: AgoClientEvents[K]) => void;
@@ -565,6 +643,9 @@ declare interface ClientFunctionSchema {
565
643
  };
566
644
  }
567
645
 
646
+ /** See {@link AgoConfig.clientFunctionsMode}. */
647
+ declare type ClientFunctionsMode = "placeholder" | "pause";
648
+
568
649
  /**
569
650
  * A single piece of context the client wants the LLM to know about.
570
651
  */
@@ -706,9 +787,32 @@ declare interface FormSchema {
706
787
  required?: string[];
707
788
  }
708
789
 
709
- declare type MessageStatus = "IN_PROGRESS" | "DONE" | "ERROR" | "TODO" | "CANCELED";
790
+ declare type MessageStatus = "IN_PROGRESS" | "DONE" | "ERROR" | "TODO" | "CANCELED"
791
+ /**
792
+ * The turn paused on client function call(s) (pause mode): the agent waits for
793
+ * every waiting call to be submitted, then the turn resumes via
794
+ * `continueMessage`. Not a final state.
795
+ */
796
+ | "WAITING_CLIENT";
797
+
798
+ declare type MessageStatus_2 = "IN_PROGRESS" | "DONE" | "ERROR" | "TODO" | "CANCELED"
799
+ /**
800
+ * The turn paused on client function call(s) (pause mode): the agent waits for
801
+ * every waiting call to be submitted, then the turn resumes via
802
+ * `continueMessage`. Not a final state.
803
+ */
804
+ | "WAITING_CLIENT";
710
805
 
711
- declare type MessageStatus_2 = "IN_PROGRESS" | "DONE" | "ERROR" | "TODO" | "CANCELED";
806
+ /**
807
+ * Hook run before a paused turn is resumed, so the app controls WHEN the
808
+ * continuation fires (e.g. wait for the destination page to mount after a
809
+ * navigation). It must resolve — throwing or hanging blocks the resume; on
810
+ * timeout-style situations resolve anyway and let the agent conclude.
811
+ */
812
+ declare type ResumeGate = (info: {
813
+ conversationId: string;
814
+ messageId: string;
815
+ }) => Promise<void> | void;
712
816
 
713
817
  /**
714
818
  * Options for sending a message
@@ -727,6 +831,8 @@ declare interface SendMessageOptions {
727
831
  * Requires backend support for the `hidden` flag; older backends ignore it.
728
832
  */
729
833
  hidden?: boolean;
834
+ /** Per-message override of {@link AgoConfig.clientFunctionsMode}. */
835
+ clientFunctionsMode?: ClientFunctionsMode;
730
836
  }
731
837
 
732
838
  /**
@@ -768,6 +874,8 @@ declare interface SSEChunkData {
768
874
  follow_up_replies?: string[];
769
875
  satisfaction_feedback?: unknown;
770
876
  ask_to_talk_to_human?: boolean;
877
+ /** Tool call ids still awaiting a client result, sent with the final `WAITING_CLIENT` event. */
878
+ waiting_tool_call_ids?: string[];
771
879
  }
772
880
 
773
881
  /**
@@ -813,6 +921,21 @@ declare type SubmitConfig<V = Record<string, unknown>> = string | {
813
921
  destination?: string;
814
922
  } | false;
815
923
 
924
+ /**
925
+ * Response of `POST /tool-calls/{id}/submit`. `resume` is only present when the
926
+ * tool call belongs to a turn paused on client functions (pause mode): `ready`
927
+ * flips to `true` once ALL waiting calls of that message are submitted, meaning
928
+ * the turn can be resumed via `continueMessage(resume.message_id)`.
929
+ */
930
+ declare interface SubmitToolCallResult {
931
+ status: string;
932
+ result?: unknown;
933
+ resume?: {
934
+ message_id: string;
935
+ ready: boolean;
936
+ };
937
+ }
938
+
816
939
  /**
817
940
  * Tool call data from SSE stream
818
941
  */