@useago/sdk 1.5.0 → 1.5.2

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/CHANGELOG.md +48 -0
  2. package/dist/AgoClient-5VGybmvz.cjs +8 -0
  3. package/dist/AgoClient-DXrH2AMi.js +964 -0
  4. package/dist/angular.cjs +1 -1
  5. package/dist/angular.d.cts +79 -2
  6. package/dist/angular.d.ts +79 -2
  7. package/dist/angular.js +2 -2
  8. package/dist/{createConversationSession-BBYfQLLS.cjs → createConversationSession-0WTqcCLK.cjs} +1 -1
  9. package/dist/{createConversationSession-DCSWShaW.js → createConversationSession-DPrrr70o.js} +1 -1
  10. package/dist/createFormCollector-1GKKwQV_.cjs +1 -0
  11. package/dist/{createFormCollector-sB6rMccD.js → createFormCollector-DYh90kiG.js} +97 -91
  12. package/dist/devtools.d.cts +79 -2
  13. package/dist/devtools.d.ts +79 -2
  14. package/dist/functions-CPs7omgM.cjs +1 -0
  15. package/dist/helpers.cjs +1 -1
  16. package/dist/helpers.d.cts +5 -0
  17. package/dist/helpers.d.ts +5 -0
  18. package/dist/helpers.js +1 -1
  19. package/dist/index.cjs +1 -1
  20. package/dist/index.d.cts +95 -4
  21. package/dist/index.d.ts +95 -4
  22. package/dist/index.js +6 -6
  23. package/dist/react.cjs +3 -3
  24. package/dist/react.d.cts +186 -4
  25. package/dist/react.d.ts +186 -4
  26. package/dist/react.js +670 -475
  27. package/dist/testing.cjs +1 -1
  28. package/dist/testing.d.cts +79 -2
  29. package/dist/testing.d.ts +79 -2
  30. package/dist/testing.js +1 -1
  31. package/dist/vue.cjs +1 -1
  32. package/dist/vue.d.cts +79 -2
  33. package/dist/vue.d.ts +79 -2
  34. package/dist/vue.js +1 -1
  35. package/dist/widget.cjs +4 -4
  36. package/dist/widget.d.cts +79 -2
  37. package/dist/widget.d.ts +79 -2
  38. package/dist/widget.js +437 -423
  39. package/llms-full.txt +74 -2
  40. package/package.json +1 -1
  41. package/dist/AgoClient-q39FIjSC.js +0 -912
  42. package/dist/AgoClient-wcPRaIMs.cjs +0 -8
  43. package/dist/createFormCollector-eimwwWEi.cjs +0 -1
  44. package/dist/functions-IGSjjvF4.cjs +0 -1
  45. package/dist/rolldown-runtime-16Nf8qvH.cjs +0 -1
  46. /package/dist/{autoContinue-D3Mmaaca.js → autoContinue-CC8K9mBU.js} +0 -0
  47. /package/dist/{autoContinue-CcCTva-D.cjs → autoContinue-CP9pJR-V.cjs} +0 -0
  48. /package/dist/{createMockClient-CjdCqixj.cjs → createMockClient-C-wrjb2C.cjs} +0 -0
  49. /package/dist/{createMockClient-BUc9PSbo.js → createMockClient-we-XoPom.js} +0 -0
  50. /package/dist/{functions-CApuQZ2b.js → functions-tzyOZNp6.js} +0 -0
package/dist/angular.cjs CHANGED
@@ -1 +1 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("./AgoClient-wcPRaIMs.cjs"),c=require("./autoContinue-CcCTva-D.cjs");var n=class{constructor(t){this.client=new o.AgoClient(t),this.messages$=this.fromEvent("message:complete"),this.chunks$=this.fromEvent("message:chunk"),this.errors$=this.fromEvent("message:error"),this.messageStart$=this.fromEvent("message:start")}fromEvent(t){const e=this.client;return{subscribe(i){const r=s=>{i.next?.(s)};return e.on(t,r),{unsubscribe:()=>e.off(t,r)}}}}sendMessage(t,e){return this.client.sendMessage(t,e)}getConversations(){return this.client.getConversations()}getConversation(t){return this.client.getConversation(t)}getMessages(t){return this.client.getMessages(t)}submitToolCallForm(t,e){return this.client.submitToolCallForm(t,e)}confirmToolCall(t){return this.client.confirmToolCall(t)}rejectToolCall(t){return this.client.rejectToolCall(t)}submitFeedback(t,e){return this.client.submitFeedback(t,e)}registerFunction(t,e,i){typeof t=="object"?this.client.registerFunction(t):this.client.registerFunction(t,e,i)}unregisterFunction(t){return this.client.unregisterFunction(t)}registerNavigationFunction(t,e){this.client.registerNavigationFunction(t,e)}unregisterNavigationFunction(){this.client.unregisterNavigationFunction()}enableAutoContinueAfterNavigation(t){return c.attachAutoContinueAfterNavigation(this.client,t)}registerPageStateFunction(t,e){this.client.registerPageStateFunction(t,e)}unregisterPageStateFunction(t){this.client.unregisterPageStateFunction(t)}on(t,e){this.client.on(t,e)}off(t,e){this.client.off(t,e)}updateConfig(t){this.client.updateConfig(t)}getClient(){return this.client}destroy(){this.client.destroy()}};function u(t){return{provide:n,useValue:new n(t)}}exports.AgoService=n;exports.provideAgo=u;
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("./AgoClient-5VGybmvz.cjs"),c=require("./autoContinue-CP9pJR-V.cjs");var n=class{constructor(t){this.client=new o.AgoClient(t),this.messages$=this.fromEvent("message:complete"),this.chunks$=this.fromEvent("message:chunk"),this.errors$=this.fromEvent("message:error"),this.messageStart$=this.fromEvent("message:start")}fromEvent(t){const e=this.client;return{subscribe(i){const r=s=>{i.next?.(s)};return e.on(t,r),{unsubscribe:()=>e.off(t,r)}}}}sendMessage(t,e){return this.client.sendMessage(t,e)}getConversations(){return this.client.getConversations()}getConversation(t){return this.client.getConversation(t)}getMessages(t){return this.client.getMessages(t)}submitToolCallForm(t,e){return this.client.submitToolCallForm(t,e)}confirmToolCall(t){return this.client.confirmToolCall(t)}rejectToolCall(t){return this.client.rejectToolCall(t)}submitFeedback(t,e){return this.client.submitFeedback(t,e)}registerFunction(t,e,i){typeof t=="object"?this.client.registerFunction(t):this.client.registerFunction(t,e,i)}unregisterFunction(t){return this.client.unregisterFunction(t)}registerNavigationFunction(t,e){this.client.registerNavigationFunction(t,e)}unregisterNavigationFunction(){this.client.unregisterNavigationFunction()}enableAutoContinueAfterNavigation(t){return c.attachAutoContinueAfterNavigation(this.client,t)}registerPageStateFunction(t,e){this.client.registerPageStateFunction(t,e)}unregisterPageStateFunction(t){this.client.unregisterPageStateFunction(t)}on(t,e){this.client.on(t,e)}off(t,e){this.client.off(t,e)}updateConfig(t){this.client.updateConfig(t)}getClient(){return this.client}destroy(){this.client.destroy()}};function u(t){return{provide:n,useValue:new n(t)}}exports.AgoService=n;exports.provideAgo=u;
@@ -58,6 +58,12 @@ declare class AgoClient {
58
58
  private warnedEmptyConversations;
59
59
  /** Paused turns awaiting auto-resume, keyed by assistant message id. */
60
60
  private pendingResumes;
61
+ /**
62
+ * Client function invocations held pending user approval, keyed by
63
+ * invocationId (the tool-call id). Populated when {@link requiresApproval}
64
+ * matches; drained by {@link approveFunction} / {@link rejectFunction}.
65
+ */
66
+ private pendingApprovals;
61
67
  /** App-provided gate deciding WHEN a paused turn resumes (see {@link registerResumeGate}). */
62
68
  private resumeGate;
63
69
  constructor(config: AgoConfig);
@@ -108,6 +114,24 @@ declare class AgoClient {
108
114
  */
109
115
  private maybeFlagEmptyReply;
110
116
  private handleClientFunctionInvocation;
117
+ /**
118
+ * Whether a client function invocation must wait for explicit user approval.
119
+ * True when the {@link AgoConfig.approvalPolicy} returns true OR the function
120
+ * was registered with `requiresApproval: true` — the two OR together.
121
+ */
122
+ private requiresApproval;
123
+ /**
124
+ * Approve a client function call held by the approval gate: run it, submit its
125
+ * result, and let the paused turn resume. No-op if the invocation is unknown
126
+ * (already handled, or never gated).
127
+ */
128
+ approveFunction(invocationId: string): Promise<void>;
129
+ /**
130
+ * Reject a client function call held by the approval gate: submit a rejection
131
+ * result so the agent sees the user declined, and let the paused turn resume
132
+ * (the agent decides what to do next). No-op if the invocation is unknown.
133
+ */
134
+ rejectFunction(invocationId: string): Promise<void>;
111
135
  /**
112
136
  * Get list of conversations
113
137
  */
@@ -137,8 +161,10 @@ declare class AgoClient {
137
161
  *
138
162
  * Opt-in on purpose — re-running functions on reload can be surprising (e.g. a
139
163
  * navigation function would navigate again), so the app decides. Returns the
140
- * resumed turn's final message, or `null` when there was nothing to resume or
141
- * some waiting function is not registered on this page.
164
+ * resumed turn's final message, or `null` when there was nothing to resume,
165
+ * some waiting function is not registered on this page, or a waiting call is
166
+ * gated by the approval policy (it is held for `approveFunction` /
167
+ * `rejectFunction` and the turn stays paused, exactly as on the live stream).
142
168
  */
143
169
  resumePendingClientFunctions(conversation: Conversation): Promise<AgoMessage | null>;
144
170
  /**
@@ -433,6 +459,15 @@ export declare interface AgoClientEvents {
433
459
  "toolCall:received": ToolCallData;
434
460
  "toolCall:form": ToolCallData;
435
461
  "function:invoke": ClientFunctionInvocation;
462
+ /**
463
+ * A client function call is held pending the user's approval (pause mode +
464
+ * an {@link AgoConfig.approvalPolicy}/`requiresApproval` match). The turn stays
465
+ * at `WAITING_CLIENT`; call `approveFunction(invocationId)` to run it and
466
+ * resume, or `rejectFunction(invocationId)` to decline. Fires after
467
+ * `function:invoke` (which still fires for every call) and instead of the
468
+ * call running immediately.
469
+ */
470
+ "function:awaiting-approval": ClientFunctionInvocation;
436
471
  "function:result": {
437
472
  invocationId: string;
438
473
  result: unknown;
@@ -501,6 +536,20 @@ export declare interface AgoConfig {
501
536
  * Older backends ignore the flag, so `"pause"` degrades to legacy behavior.
502
537
  */
503
538
  clientFunctionsMode?: ClientFunctionsMode;
539
+ /**
540
+ * Gate client function calls behind explicit user approval. Return `true` for
541
+ * an invocation the user must approve/reject before it runs; return `false`
542
+ * (or omit the policy) to let it run immediately as before.
543
+ *
544
+ * Only effective in pause mode (`clientFunctionsMode: "pause"`) — a gated call
545
+ * holds at `WAITING_CLIENT`, the SDK emits `function:awaiting-approval`, and it
546
+ * runs (and the turn resumes) only after `approveFunction(invocationId)`; a
547
+ * `rejectFunction(invocationId)` submits a rejection so the agent sees the
548
+ * decline. In placeholder mode there is no pause to hold, so the policy is a
549
+ * no-op and the call runs normally. A per-function `requiresApproval: true`
550
+ * also gates a call; the policy and the flag OR together.
551
+ */
552
+ approvalPolicy?: (invocation: ClientFunctionInvocation) => boolean;
504
553
  /**
505
554
  * Max serialized size (bytes) of a client function result before the SDK
506
555
  * replaces it with a flagged, truncated preview. Everything a handler
@@ -545,6 +594,11 @@ export declare interface AgoMessage {
545
594
  export declare interface AgoPageStateOptions {
546
595
  /** Name of the synthesized client function. Defaults to "setPageState". */
547
596
  functionName?: string;
597
+ /**
598
+ * Require explicit user approval before this state change runs. See
599
+ * {@link AgoConfig.approvalPolicy} — pause mode only. Defaults to `false`.
600
+ */
601
+ requiresApproval?: boolean;
548
602
  }
549
603
 
550
604
  export declare type AgoProvideOptions = AgoConfig;
@@ -726,6 +780,11 @@ declare interface ClientFunctionDefinition {
726
780
  * `Infinity` disables the guard for this function.
727
781
  */
728
782
  maxResultBytes?: number;
783
+ /**
784
+ * Require explicit user approval before this function runs. See
785
+ * {@link AgoConfig.approvalPolicy} — pause mode only. ORs with the policy.
786
+ */
787
+ requiresApproval?: boolean;
729
788
  }
730
789
 
731
790
  /**
@@ -752,6 +811,11 @@ declare type ClientFunctionRegisterOptions = Omit<ClientFunctionSchema, "name">
752
811
  * disables the guard for this function.
753
812
  */
754
813
  maxResultBytes?: number;
814
+ /**
815
+ * Require explicit user approval before this function runs. See
816
+ * {@link AgoConfig.approvalPolicy} — pause mode only. ORs with the policy.
817
+ */
818
+ requiresApproval?: boolean;
755
819
  };
756
820
 
757
821
  /**
@@ -792,6 +856,19 @@ declare interface ContextEntry {
792
856
  description?: string;
793
857
  /** Arbitrary structured data the AI should know about */
794
858
  data?: Record<string, unknown>;
859
+ /**
860
+ * Marks the entry as constant for the whole conversation. The backend then
861
+ * pins it right after the system prompt, where LLM providers cache it across
862
+ * turns, instead of re-processing it next to every new user message.
863
+ *
864
+ * Only set this when the entry's content is byte-identical on every message
865
+ * of a conversation (a schema, a capability list, static instructions). A
866
+ * stable entry that changes between messages invalidates the provider's
867
+ * cache for the entire conversation history, which costs more than leaving
868
+ * the flag off. Default: `false` (re-sent near the newest user message).
869
+ * Backends that don't know the flag ignore it.
870
+ */
871
+ stable?: boolean;
795
872
  }
796
873
 
797
874
  /**
package/dist/angular.d.ts CHANGED
@@ -58,6 +58,12 @@ declare class AgoClient {
58
58
  private warnedEmptyConversations;
59
59
  /** Paused turns awaiting auto-resume, keyed by assistant message id. */
60
60
  private pendingResumes;
61
+ /**
62
+ * Client function invocations held pending user approval, keyed by
63
+ * invocationId (the tool-call id). Populated when {@link requiresApproval}
64
+ * matches; drained by {@link approveFunction} / {@link rejectFunction}.
65
+ */
66
+ private pendingApprovals;
61
67
  /** App-provided gate deciding WHEN a paused turn resumes (see {@link registerResumeGate}). */
62
68
  private resumeGate;
63
69
  constructor(config: AgoConfig);
@@ -108,6 +114,24 @@ declare class AgoClient {
108
114
  */
109
115
  private maybeFlagEmptyReply;
110
116
  private handleClientFunctionInvocation;
117
+ /**
118
+ * Whether a client function invocation must wait for explicit user approval.
119
+ * True when the {@link AgoConfig.approvalPolicy} returns true OR the function
120
+ * was registered with `requiresApproval: true` — the two OR together.
121
+ */
122
+ private requiresApproval;
123
+ /**
124
+ * Approve a client function call held by the approval gate: run it, submit its
125
+ * result, and let the paused turn resume. No-op if the invocation is unknown
126
+ * (already handled, or never gated).
127
+ */
128
+ approveFunction(invocationId: string): Promise<void>;
129
+ /**
130
+ * Reject a client function call held by the approval gate: submit a rejection
131
+ * result so the agent sees the user declined, and let the paused turn resume
132
+ * (the agent decides what to do next). No-op if the invocation is unknown.
133
+ */
134
+ rejectFunction(invocationId: string): Promise<void>;
111
135
  /**
112
136
  * Get list of conversations
113
137
  */
@@ -137,8 +161,10 @@ declare class AgoClient {
137
161
  *
138
162
  * Opt-in on purpose — re-running functions on reload can be surprising (e.g. a
139
163
  * navigation function would navigate again), so the app decides. Returns the
140
- * resumed turn's final message, or `null` when there was nothing to resume or
141
- * some waiting function is not registered on this page.
164
+ * resumed turn's final message, or `null` when there was nothing to resume,
165
+ * some waiting function is not registered on this page, or a waiting call is
166
+ * gated by the approval policy (it is held for `approveFunction` /
167
+ * `rejectFunction` and the turn stays paused, exactly as on the live stream).
142
168
  */
143
169
  resumePendingClientFunctions(conversation: Conversation): Promise<AgoMessage | null>;
144
170
  /**
@@ -433,6 +459,15 @@ export declare interface AgoClientEvents {
433
459
  "toolCall:received": ToolCallData;
434
460
  "toolCall:form": ToolCallData;
435
461
  "function:invoke": ClientFunctionInvocation;
462
+ /**
463
+ * A client function call is held pending the user's approval (pause mode +
464
+ * an {@link AgoConfig.approvalPolicy}/`requiresApproval` match). The turn stays
465
+ * at `WAITING_CLIENT`; call `approveFunction(invocationId)` to run it and
466
+ * resume, or `rejectFunction(invocationId)` to decline. Fires after
467
+ * `function:invoke` (which still fires for every call) and instead of the
468
+ * call running immediately.
469
+ */
470
+ "function:awaiting-approval": ClientFunctionInvocation;
436
471
  "function:result": {
437
472
  invocationId: string;
438
473
  result: unknown;
@@ -501,6 +536,20 @@ export declare interface AgoConfig {
501
536
  * Older backends ignore the flag, so `"pause"` degrades to legacy behavior.
502
537
  */
503
538
  clientFunctionsMode?: ClientFunctionsMode;
539
+ /**
540
+ * Gate client function calls behind explicit user approval. Return `true` for
541
+ * an invocation the user must approve/reject before it runs; return `false`
542
+ * (or omit the policy) to let it run immediately as before.
543
+ *
544
+ * Only effective in pause mode (`clientFunctionsMode: "pause"`) — a gated call
545
+ * holds at `WAITING_CLIENT`, the SDK emits `function:awaiting-approval`, and it
546
+ * runs (and the turn resumes) only after `approveFunction(invocationId)`; a
547
+ * `rejectFunction(invocationId)` submits a rejection so the agent sees the
548
+ * decline. In placeholder mode there is no pause to hold, so the policy is a
549
+ * no-op and the call runs normally. A per-function `requiresApproval: true`
550
+ * also gates a call; the policy and the flag OR together.
551
+ */
552
+ approvalPolicy?: (invocation: ClientFunctionInvocation) => boolean;
504
553
  /**
505
554
  * Max serialized size (bytes) of a client function result before the SDK
506
555
  * replaces it with a flagged, truncated preview. Everything a handler
@@ -545,6 +594,11 @@ export declare interface AgoMessage {
545
594
  export declare interface AgoPageStateOptions {
546
595
  /** Name of the synthesized client function. Defaults to "setPageState". */
547
596
  functionName?: string;
597
+ /**
598
+ * Require explicit user approval before this state change runs. See
599
+ * {@link AgoConfig.approvalPolicy} — pause mode only. Defaults to `false`.
600
+ */
601
+ requiresApproval?: boolean;
548
602
  }
549
603
 
550
604
  export declare type AgoProvideOptions = AgoConfig;
@@ -726,6 +780,11 @@ declare interface ClientFunctionDefinition {
726
780
  * `Infinity` disables the guard for this function.
727
781
  */
728
782
  maxResultBytes?: number;
783
+ /**
784
+ * Require explicit user approval before this function runs. See
785
+ * {@link AgoConfig.approvalPolicy} — pause mode only. ORs with the policy.
786
+ */
787
+ requiresApproval?: boolean;
729
788
  }
730
789
 
731
790
  /**
@@ -752,6 +811,11 @@ declare type ClientFunctionRegisterOptions = Omit<ClientFunctionSchema, "name">
752
811
  * disables the guard for this function.
753
812
  */
754
813
  maxResultBytes?: number;
814
+ /**
815
+ * Require explicit user approval before this function runs. See
816
+ * {@link AgoConfig.approvalPolicy} — pause mode only. ORs with the policy.
817
+ */
818
+ requiresApproval?: boolean;
755
819
  };
756
820
 
757
821
  /**
@@ -792,6 +856,19 @@ declare interface ContextEntry {
792
856
  description?: string;
793
857
  /** Arbitrary structured data the AI should know about */
794
858
  data?: Record<string, unknown>;
859
+ /**
860
+ * Marks the entry as constant for the whole conversation. The backend then
861
+ * pins it right after the system prompt, where LLM providers cache it across
862
+ * turns, instead of re-processing it next to every new user message.
863
+ *
864
+ * Only set this when the entry's content is byte-identical on every message
865
+ * of a conversation (a schema, a capability list, static instructions). A
866
+ * stable entry that changes between messages invalidates the provider's
867
+ * cache for the entire conversation history, which costs more than leaving
868
+ * the flag off. Default: `false` (re-sent near the newest user message).
869
+ * Backends that don't know the flag ignore it.
870
+ */
871
+ stable?: boolean;
795
872
  }
796
873
 
797
874
  /**
package/dist/angular.js CHANGED
@@ -1,5 +1,5 @@
1
- import { t as o } from "./AgoClient-q39FIjSC.js";
2
- import { t as c } from "./autoContinue-D3Mmaaca.js";
1
+ import { t as o } from "./AgoClient-DXrH2AMi.js";
2
+ import { t as c } from "./autoContinue-CC8K9mBU.js";
3
3
  var s = class {
4
4
  constructor(t) {
5
5
  this.client = new o(t), this.messages$ = this.fromEvent("message:complete"), this.chunks$ = this.fromEvent("message:chunk"), this.errors$ = this.fromEvent("message:error"), this.messageStart$ = this.fromEvent("message:start");
@@ -1 +1 @@
1
- const d=require("./createFormCollector-eimwwWEi.cjs");var f="ago_widget_id",g="ago_last_thread",y=7200*1e3;function v(){return typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,e=>{const r=Math.floor(Math.random()*16);return(e==="x"?r:r&3|8).toString(16)})}function _(e={}){const r=e.key??f,i=e.threadKey??g,u=e.ttlMs??y,l=e.storage??(typeof localStorage<"u"?localStorage:void 0);let n=e.widgetId??"";if(!n&&l)try{n=l.getItem(r)??""}catch{}if(n||(n=v()),l)try{l.setItem(r,n)}catch{}const o=d.createStore({value:null,lastMessageAt:null},{key:i,storage:l}),c=o.get();c.value!==null&&s(c.lastMessageAt)&&o.set({value:null,lastMessageAt:null});function s(t){return t===null?!0:Number.isFinite(u)?Date.now()-t>u:!1}return{widgetId:n,key:r,getLastActiveThread(){const{value:t,lastMessageAt:a}=o.get();return t===null||s(a)?null:t},setActiveThread(t,a){const x=a==null?null:a instanceof Date?a.getTime():a;o.set({value:t,lastMessageAt:x})},clear(){o.set({value:null,lastMessageAt:null})}}}Object.defineProperty(exports,"createConversationSession",{enumerable:!0,get:function(){return _}});
1
+ const d=require("./createFormCollector-1GKKwQV_.cjs");var f="ago_widget_id",g="ago_last_thread",y=7200*1e3;function v(){return typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,e=>{const r=Math.floor(Math.random()*16);return(e==="x"?r:r&3|8).toString(16)})}function _(e={}){const r=e.key??f,i=e.threadKey??g,u=e.ttlMs??y,l=e.storage??(typeof localStorage<"u"?localStorage:void 0);let n=e.widgetId??"";if(!n&&l)try{n=l.getItem(r)??""}catch{}if(n||(n=v()),l)try{l.setItem(r,n)}catch{}const o=d.createStore({value:null,lastMessageAt:null},{key:i,storage:l}),c=o.get();c.value!==null&&s(c.lastMessageAt)&&o.set({value:null,lastMessageAt:null});function s(t){return t===null?!0:Number.isFinite(u)?Date.now()-t>u:!1}return{widgetId:n,key:r,getLastActiveThread(){const{value:t,lastMessageAt:a}=o.get();return t===null||s(a)?null:t},setActiveThread(t,a){const x=a==null?null:a instanceof Date?a.getTime():a;o.set({value:t,lastMessageAt:x})},clear(){o.set({value:null,lastMessageAt:null})}}}Object.defineProperty(exports,"createConversationSession",{enumerable:!0,get:function(){return _}});
@@ -1,4 +1,4 @@
1
- import { i as d } from "./createFormCollector-sB6rMccD.js";
1
+ import { i as d } from "./createFormCollector-DYh90kiG.js";
2
2
  var f = "ago_widget_id", g = "ago_last_thread", y = 7200 * 1e3;
3
3
  function v() {
4
4
  return typeof crypto < "u" && typeof crypto.randomUUID == "function" ? crypto.randomUUID() : "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (e) => {
@@ -0,0 +1 @@
1
+ const w=require("./AgoClient-5VGybmvz.cjs");function A(n,e){const a=e?e.storage??(typeof localStorage<"u"?localStorage:void 0):void 0;let o=n;if(e&&a)try{const m=a.getItem(e.key);m!=null&&(o=JSON.parse(m))}catch{}const s=new Set,c=()=>s.forEach(m=>m(o));function b(){if(e&&a)try{a.setItem(e.key,JSON.stringify(o))}catch{}}return{get:()=>o,set:m=>{o=m,b(),c()},subscribe:m=>(s.add(m),()=>{s.delete(m)})}}var W=/^[a-zA-Z0-9_-]{1,40}$/,I=n=>n==null||n==="";function C(n,e){if("anyOf"in n)return n.anyOf.some(c=>C(c,e));if("allOf"in n)return n.allOf.every(c=>C(c,e));const a=e[n.property];if(I(a))return!1;if(Array.isArray(n.value))return n.value.some(c=>String(a)===String(c));if(!n.op)return String(a)===String(n.value);const o=Number(a),s=Number(n.value);if(Number.isNaN(o)||Number.isNaN(s))return!1;switch(n.op){case">=":return o>=s;case"<=":return o<=s;case">":return o>s;case"<":return o<s;default:return w.logger.warn(`Unknown requiredWhen op "${n.op}"; treating as not required.`),!1}}function y(n,e){const a=n.properties??{},o=new Set;for(const c of n.required??[]){const b=a[c]?.requiredWhen;(!b||C(b,e))&&o.add(c)}for(const[c,b]of Object.entries(a))b.requiredWhen&&C(b.requiredWhen,e)&&o.add(c);const s=[...o].filter(c=>I(e[c]));return{missing:s,complete:s.length===0}}function B(n){const e={};for(const[a,o]of Object.entries(n.properties??{}))e[a]={type:o.type,...o.description!=null&&{description:o.description},...o.enum&&{enum:o.enum},...o.default!==void 0&&{default:o.default}};return{type:"object",properties:e,required:[]}}function V(n){const{name:e,description:a,schema:o}=n;if(!W.test(e))throw new Error(`Invalid form collector name "${e}": must match ${W} (it becomes the update_/submit_ function names).`);const s=typeof n.submit=="string"?n.submit?{via:"client",url:n.submit}:!1:n.submit??!1;n.autoSubmit===!0&&!s&&w.logger.warn(`FormCollector "${e}": autoSubmit is ignored because no submit target is configured.`);const c=(n.autoSubmit??!0)&&!!s,b=o.properties??{},m=t=>{const r={};for(const[u,i]of Object.entries(t)){const l=b[u];if(l)if(i==null)r[u]=i;else if(l.type==="number"||l.type==="integer"){const d=typeof i=="number"?i:Number(i);r[u]=Number.isNaN(d)?i:d}else l.type==="boolean"?r[u]=typeof i=="boolean"?i:i==="true"?!0:i==="false"?!1:!!i:r[u]=i}return r},N=n.initialValues??{},f=A({values:N,submitted:!1}),F=t=>{const r=f.get(),u={...r,values:{...r.values,...t}};return f.set(u),u};let h=null;const k=(t,r)=>{h?.emitFormEvent("form:error",{name:e,values:t,error:r})};let g=null;const D=async()=>{const{values:t}=f.get(),{complete:r,missing:u}=y(o,t);if(!r)return{ok:!1,missing:u};if(!s)return{ok:!1,error:"No submit target configured for this form collector."};const i=t;try{let l;if(s.via==="client")if("handler"in s)l=await s.handler(i);else{const d=await fetch(s.url,{method:"POST",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify(i)});if(!d.ok){const j=`Submit failed: HTTP ${d.status}`;return k(i,j),{ok:!1,error:j}}l=await d.json().catch(()=>{})}else{if(!h)return{ok:!1,error:"Backend submit requires install(client) (or useFormCollector) first."};l=await h.submitFormCollector(e,i)}return f.set({...f.get(),submitted:!0,submitResult:l}),h?.emitFormEvent("form:submitted",{name:e,values:i,result:l}),{ok:!0,result:l}}catch(l){const d=l instanceof Error?l.message:"Submit failed";return w.logger.error(`FormCollector "${e}" submit failed:`,l),k(i,d),{ok:!1,error:d}}},$=()=>g||(g=(async()=>{try{return await D()}finally{g=null}})(),g),q=async()=>{if(!c||!s)return null;const{values:t,submitted:r}=f.get();return r||!y(o,t).complete?null:$()},O={name:`update_${e}`,description:`Fill or update fields of the "${e}" form. ${a} Pass any subset of fields; call it repeatedly to fill the form as the user provides information. Returns the current values and which required fields are still missing.`,parameters:B(o),handler:async t=>{const r=F(m(t)),{missing:u}=y(o,r.values),i=await q();return i?i.ok?{ok:!0,values:r.values,missing:u,submitted:!0}:{ok:!0,values:r.values,missing:u,submitted:!1,submitError:i.error}:{ok:!0,values:r.values,missing:u}}},p=[O];s&&!c&&p.push({name:`submit_${e}`,description:`Submit the completed "${e}" form. Only call this once every required field is collected and the user has confirmed. If fields are missing it returns them instead of submitting.`,parameters:{type:"object",properties:{}},handler:()=>$()});const J="client__",_=s?`submit_${e}`:null,R=t=>{const r=t.functionName??t.toolName;if(r)return r.startsWith(J)?r.slice(8):r},P=t=>{let r={...N},u=!1;for(const i of t){const l=R(i);l===O.name?i.arguments&&(r={...r,...m(i.arguments)}):_&&l===_&&i.status?.toLowerCase()==="done"&&(u=!0)}f.set({values:r,submitted:u})},v=`form:${e}`,S=`${v}:definition`,x=()=>({name:`Form definition: ${e}`,description:`${a} Some fields are conditionally required; the requiredWhen field in the schema tells you when each becomes required. The form schema is the following: ${JSON.stringify(o)}.`,stable:!0}),E=()=>{const{values:t,submitted:r}=f.get(),{missing:u,complete:i}=y(o,t),l=s?c?" The form is submitted automatically as soon as every required field is filled, so there is no submit function to call.":` When nothing is missing and the user confirms, call submit_${e}.`:"",d=r?`The "${e}" form has been submitted.`:`You are currently collecting information from the user to fill the "${e}" form.`;return{name:`Form: ${e}`,description:`${d} The form's schema and field requirements are in the "${S}" client context. Call update_${e} with any fields the user provides; ask only for what is still missing.${l}`,data:{values:t,missing:u,complete:i,submitted:r}}},T=t=>{P((t.messages??[]).flatMap(r=>r.toolCalls??[]))};return{name:e,store:f,functions:p,contextKey:v,contextProvider:E,definitionContextKey:S,definitionContextProvider:x,install:t=>{h=t;for(const u of p)t.register(u);t.addDynamicContext(S,x),t.addDynamicContext(v,E);const r=f.subscribe(()=>t.notifyContextChanged());return t.on("conversation:loaded",T),()=>{r();for(const u of p)t.unregisterFunction(u.name);t.removeDynamicContext(v),t.removeDynamicContext(S),t.off("conversation:loaded",T),h===t&&(h=null)}},hydrate:P,submit:$,getValues:()=>f.get().values,setValues:t=>{F(m(t)),q()},reset:()=>{f.set({values:N,submitted:!1})},getStatus:()=>y(o,f.get().values)}}async function L(n,e){const a=await n.getFormCollector(e.name);return V({name:a.name,description:e.description??a.description,schema:e.schema??a.schema,submit:e.submit??a.submit,initialValues:e.initialValues,autoSubmit:e.autoSubmit??a.autoSubmit})}Object.defineProperty(exports,"createFormCollector",{enumerable:!0,get:function(){return V}});Object.defineProperty(exports,"createStore",{enumerable:!0,get:function(){return A}});Object.defineProperty(exports,"deriveFormStatus",{enumerable:!0,get:function(){return y}});Object.defineProperty(exports,"loadFormCollector",{enumerable:!0,get:function(){return L}});