@useago/sdk 1.0.0 → 1.0.1

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.
package/dist/angular.d.ts CHANGED
@@ -53,6 +53,13 @@ declare class AgoClient {
53
53
  * Reject a tool call
54
54
  */
55
55
  rejectToolCall(toolCallId: string): Promise<void>;
56
+ /**
57
+ * Fetch a backend-stored form collector definition by name (the single source
58
+ * of truth for the form's description, schema, and submit target). Used by
59
+ * `loadFormCollector` / the name-only form of `useFormCollector` so the schema
60
+ * lives in the backend instead of being hardcoded in client code.
61
+ */
62
+ getFormCollector(name: string): Promise<FormCollectorDefinition>;
56
63
  /**
57
64
  * Relay a completed form collector's values to a server-configured destination.
58
65
  *
@@ -477,6 +484,30 @@ export declare interface Conversation {
477
484
  */
478
485
  declare type DynamicContextProvider = () => ContextEntry | null | undefined;
479
486
 
487
+ /**
488
+ * The backend-stored shape returned by `GET /api/sdk/v1/forms/{name}` (see
489
+ * {@link AgoClient.getFormCollector}). Mirrors the persistable subset of
490
+ * {@link CreateFormCollectorOptions}: the `submit` here is never the client-only
491
+ * `handler` variant (a function can't be stored server-side).
492
+ */
493
+ declare interface FormCollectorDefinition<V = Record<string, unknown>> {
494
+ name: string;
495
+ description: string;
496
+ schema: FormCollectorSchema;
497
+ /** Server-stored submit target, if any. Absent means collect-only. */
498
+ submit?: SubmitConfig<V>;
499
+ }
500
+
501
+ /**
502
+ * Shape of a form's fields. Mirrors a client function's `parameters` (so the same
503
+ * object feeds the store, the update function, and the dynamic context). Additionally allows the SDK-only per-field `requiredWhen`, which {@link toWireParameters} removes before the schema reaches the LLM.
504
+ */
505
+ declare interface FormCollectorSchema {
506
+ type: "object";
507
+ properties: Record<string, FormFieldSchema>;
508
+ required?: string[];
509
+ }
510
+
480
511
  declare interface FormField {
481
512
  type: "string" | "number" | "boolean" | "array";
482
513
  title?: string;
@@ -485,6 +516,43 @@ declare interface FormField {
485
516
  default?: unknown;
486
517
  }
487
518
 
519
+ /**
520
+ * A field's conditional-requiredness rule. The field becomes required exactly
521
+ * when the controlling `property` matches `value` against the answers collected
522
+ * so far:
523
+ * - a single `value`, no `op` — equality (compared as strings);
524
+ * - a single `value` with `op` — numeric comparison (both sides coerced to numbers);
525
+ * - an array `value`, no `op` — "one of": matches when the property equals any
526
+ * listed value.
527
+ *
528
+ * SDK-only — it is stripped from the schema before it reaches the LLM tool
529
+ */
530
+ declare interface FormFieldCondition {
531
+ /** The controlling field whose value the rule tests. */
532
+ property: string;
533
+ /** Comparison operator; omitted means equality. Ignored when `value` is an array. */
534
+ op?: ">=" | "<=" | ">" | "<";
535
+ /**
536
+ * The value(s) to test the controlling field against. A single value is an
537
+ * equality (or, with `op`, a numeric comparison); an array is an "is one of"
538
+ * membership test, e.g. `value: ["1", "2", "3"]`.
539
+ */
540
+ value: string | number | Array<string | number>;
541
+ }
542
+
543
+ /** A single field's schema: the wire-legal keys plus the SDK-only `requiredWhen`. */
544
+ declare interface FormFieldSchema {
545
+ type: string;
546
+ description?: string;
547
+ enum?: string[];
548
+ default?: unknown;
549
+ /**
550
+ * Makes the field required only while this condition holds. Drives the dynamic
551
+ * `missing` list; stripped before the LLM tool — see {@link toWireParameters}.
552
+ */
553
+ requiredWhen?: FormFieldCondition;
554
+ }
555
+
488
556
  /**
489
557
  * Form schema for tool calls requiring user input
490
558
  */
@@ -541,6 +609,27 @@ declare interface SendMessageOptions {
541
609
  files?: File[];
542
610
  }
543
611
 
612
+ /**
613
+ * Where a completed form is sent.
614
+ * - `"https://..."` (a bare string) — shorthand for `{ via: "client", url }`: the browser
615
+ * POSTs the values to that URL.
616
+ * - `{ via: "client", url }` — same, written out.
617
+ * - `{ via: "client", handler }` — the browser runs your own submit logic.
618
+ * - `{ via: "backend", destination }` — the browser relays the values to the backend,
619
+ * which forwards them to the server-configured destination (URL + secret stay server-side).
620
+ * - `false` — collect only, no submit function.
621
+ */
622
+ declare type SubmitConfig<V = Record<string, unknown>> = string | {
623
+ via: "client";
624
+ url: string;
625
+ } | {
626
+ via: "client";
627
+ handler: (values: V) => Promise<unknown> | unknown;
628
+ } | {
629
+ via: "backend";
630
+ destination: string;
631
+ } | false;
632
+
544
633
  /**
545
634
  * Tool call data from SSE stream
546
635
  */
package/dist/angular.js CHANGED
@@ -1,4 +1,4 @@
1
- import { t as o } from "./AgoClient-BrYhSO5M.js";
1
+ import { t as o } from "./AgoClient-CZYNL25R.js";
2
2
  var n = class {
3
3
  constructor(t) {
4
4
  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-DaWZsBsI.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-Ca8wRrxc.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 { r as d } from "./createFormCollector-CPS2phYq.js";
1
+ import { i as d } from "./createFormCollector-Bk0DRhUf.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,257 @@
1
+ import { s as _ } from "./AgoClient-CZYNL25R.js";
2
+ function E(n, e) {
3
+ const i = e ? e.storage ?? (typeof localStorage < "u" ? localStorage : void 0) : void 0;
4
+ let t = n;
5
+ if (e && i) try {
6
+ const c = i.getItem(e.key);
7
+ c != null && (t = JSON.parse(c));
8
+ } catch {
9
+ }
10
+ const a = /* @__PURE__ */ new Set(), f = () => a.forEach((c) => c(t));
11
+ function d() {
12
+ if (e && i) try {
13
+ i.setItem(e.key, JSON.stringify(t));
14
+ } catch {
15
+ }
16
+ }
17
+ return {
18
+ get: () => t,
19
+ set: (c) => {
20
+ t = c, d(), f();
21
+ },
22
+ subscribe: (c) => (a.add(c), () => {
23
+ a.delete(c);
24
+ })
25
+ };
26
+ }
27
+ var F = /^[a-zA-Z0-9_-]{1,40}$/, O = (n) => n == null || n === "";
28
+ function q(n, e) {
29
+ const i = e[n.property];
30
+ if (O(i)) return !1;
31
+ if (Array.isArray(n.value)) return n.value.some((f) => String(i) === String(f));
32
+ if (!n.op) return String(i) === String(n.value);
33
+ const t = Number(i), a = Number(n.value);
34
+ if (Number.isNaN(t) || Number.isNaN(a)) return !1;
35
+ switch (n.op) {
36
+ case ">=":
37
+ return t >= a;
38
+ case "<=":
39
+ return t <= a;
40
+ case ">":
41
+ return t > a;
42
+ case "<":
43
+ return t < a;
44
+ default:
45
+ return _.warn(`Unknown requiredWhen op "${n.op}"; treating as not required.`), !1;
46
+ }
47
+ }
48
+ function g(n, e) {
49
+ const i = n.properties ?? {}, t = /* @__PURE__ */ new Set();
50
+ for (const f of n.required ?? []) {
51
+ const d = i[f]?.requiredWhen;
52
+ (!d || q(d, e)) && t.add(f);
53
+ }
54
+ for (const [f, d] of Object.entries(i)) d.requiredWhen && q(d.requiredWhen, e) && t.add(f);
55
+ const a = [...t].filter((f) => O(e[f]));
56
+ return {
57
+ missing: a,
58
+ complete: a.length === 0
59
+ };
60
+ }
61
+ function P(n) {
62
+ const e = {};
63
+ for (const [i, t] of Object.entries(n.properties ?? {})) e[i] = {
64
+ type: t.type,
65
+ ...t.description != null && { description: t.description },
66
+ ...t.enum && { enum: t.enum },
67
+ ...t.default !== void 0 && { default: t.default }
68
+ };
69
+ return {
70
+ type: "object",
71
+ properties: e,
72
+ required: []
73
+ };
74
+ }
75
+ function W(n) {
76
+ const { name: e, description: i, schema: t } = n;
77
+ if (!F.test(e)) throw new Error(`Invalid form collector name "${e}": must match ${F} (it becomes the update_/submit_ function names).`);
78
+ const a = typeof n.submit == "string" ? n.submit ? {
79
+ via: "client",
80
+ url: n.submit
81
+ } : !1 : n.submit ?? !1, f = t.properties ?? {}, d = (r) => {
82
+ const s = {};
83
+ for (const [u, o] of Object.entries(r)) {
84
+ const l = f[u];
85
+ if (l)
86
+ if (o == null) s[u] = o;
87
+ else if (l.type === "number" || l.type === "integer") {
88
+ const h = typeof o == "number" ? o : Number(o);
89
+ s[u] = Number.isNaN(h) ? o : h;
90
+ } else l.type === "boolean" ? s[u] = typeof o == "boolean" ? o : o === "true" ? !0 : o === "false" ? !1 : !!o : s[u] = o;
91
+ }
92
+ return s;
93
+ }, c = n.initialValues ?? {}, m = E({
94
+ values: c,
95
+ submitted: !1
96
+ }), v = (r) => {
97
+ const s = m.get(), u = {
98
+ ...s,
99
+ values: {
100
+ ...s.values,
101
+ ...r
102
+ }
103
+ };
104
+ return m.set(u), u;
105
+ };
106
+ let b = null;
107
+ const N = async () => {
108
+ const { values: r } = m.get(), { complete: s, missing: u } = g(t, r);
109
+ if (!s) return {
110
+ ok: !1,
111
+ missing: u
112
+ };
113
+ if (!a) return {
114
+ ok: !1,
115
+ error: "No submit target configured for this form collector."
116
+ };
117
+ const o = r;
118
+ try {
119
+ let l;
120
+ if (a.via === "client") if ("handler" in a) l = await a.handler(o);
121
+ else {
122
+ const h = await fetch(a.url, {
123
+ method: "POST",
124
+ headers: { "Content-Type": "application/json" },
125
+ credentials: "include",
126
+ body: JSON.stringify(o)
127
+ });
128
+ if (!h.ok) return {
129
+ ok: !1,
130
+ error: `Submit failed: HTTP ${h.status}`
131
+ };
132
+ l = await h.json().catch(() => {
133
+ });
134
+ }
135
+ else {
136
+ if (!b) return {
137
+ ok: !1,
138
+ error: "Backend submit requires install(client) (or useFormCollector) first."
139
+ };
140
+ l = await b.submitFormCollector(a.destination, o);
141
+ }
142
+ return m.set({
143
+ ...m.get(),
144
+ submitted: !0
145
+ }), {
146
+ ok: !0,
147
+ result: l
148
+ };
149
+ } catch (l) {
150
+ const h = l instanceof Error ? l.message : "Submit failed";
151
+ return _.error(`FormCollector "${e}" submit failed:`, l), {
152
+ ok: !1,
153
+ error: h
154
+ };
155
+ }
156
+ }, $ = {
157
+ name: `update_${e}`,
158
+ description: `Fill or update fields of the "${e}" form. ${i} 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.`,
159
+ parameters: P(t),
160
+ handler: (r) => {
161
+ const s = v(d(r)), { missing: u } = g(t, s.values);
162
+ return {
163
+ ok: !0,
164
+ values: s.values,
165
+ missing: u
166
+ };
167
+ }
168
+ }, p = [$];
169
+ a && p.push({
170
+ name: `submit_${e}`,
171
+ 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.`,
172
+ parameters: {
173
+ type: "object",
174
+ properties: {}
175
+ },
176
+ handler: () => N()
177
+ });
178
+ const T = "client__", S = a ? `submit_${e}` : null, x = (r) => {
179
+ const s = r.functionName ?? r.toolName;
180
+ if (s)
181
+ return s.startsWith(T) ? s.slice(8) : s;
182
+ }, w = (r) => {
183
+ let s = { ...c }, u = !1;
184
+ for (const o of r) {
185
+ const l = x(o);
186
+ l === $.name ? o.arguments && (s = {
187
+ ...s,
188
+ ...d(o.arguments)
189
+ }) : S && l === S && o.status?.toLowerCase() === "done" && (u = !0);
190
+ }
191
+ m.set({
192
+ values: s,
193
+ submitted: u
194
+ });
195
+ }, y = `form:${e}`, C = () => {
196
+ const { values: r, submitted: s } = m.get(), { missing: u, complete: o } = g(t, r), l = a ? ` When nothing is missing and the user confirms, call submit_${e}.` : "", h = s ? `The "${e}" form has been submitted.` : `You are currently collecting information from the user to fill the "${e}" form.`;
197
+ return {
198
+ name: `Form: ${e}`,
199
+ description: `${h} ${i} There are conditionnals questions/values to collected, you can find this information with the requiredWhen field in the form. The form schema is the following: ${JSON.stringify(t)}. Data collected so far: ${JSON.stringify(r)}. Call update_${e} with any fields the user provides; ask only for what is still missing.${l}`,
200
+ data: {
201
+ values: r,
202
+ missing: u,
203
+ complete: o,
204
+ submitted: s
205
+ }
206
+ };
207
+ }, k = (r) => {
208
+ w((r.messages ?? []).flatMap((s) => s.toolCalls ?? []));
209
+ };
210
+ return {
211
+ name: e,
212
+ store: m,
213
+ functions: p,
214
+ contextKey: y,
215
+ contextProvider: C,
216
+ install: (r) => {
217
+ b = r;
218
+ for (const u of p) r.register(u);
219
+ r.addDynamicContext(y, C);
220
+ const s = m.subscribe(() => r.notifyContextChanged());
221
+ return r.on("conversation:loaded", k), () => {
222
+ s();
223
+ for (const u of p) r.unregisterFunction(u.name);
224
+ r.removeDynamicContext(y), r.off("conversation:loaded", k), b === r && (b = null);
225
+ };
226
+ },
227
+ hydrate: w,
228
+ submit: N,
229
+ getValues: () => m.get().values,
230
+ setValues: (r) => {
231
+ v(d(r));
232
+ },
233
+ reset: () => {
234
+ m.set({
235
+ values: c,
236
+ submitted: !1
237
+ });
238
+ },
239
+ getStatus: () => g(t, m.get().values)
240
+ };
241
+ }
242
+ async function V(n, e) {
243
+ const i = await n.getFormCollector(e.name);
244
+ return W({
245
+ name: i.name,
246
+ description: e.description ?? i.description,
247
+ schema: e.schema ?? i.schema,
248
+ submit: e.submit ?? i.submit,
249
+ initialValues: e.initialValues
250
+ });
251
+ }
252
+ export {
253
+ E as i,
254
+ g as n,
255
+ V as r,
256
+ W as t
257
+ };
@@ -0,0 +1 @@
1
+ const O=require("./AgoClient-0x2Du_62.cjs");function _(o,e){const i=e?e.storage??(typeof localStorage<"u"?localStorage:void 0):void 0;let t=o;if(e&&i)try{const c=i.getItem(e.key);c!=null&&(t=JSON.parse(c))}catch{}const a=new Set,f=()=>a.forEach(c=>c(t));function d(){if(e&&i)try{i.setItem(e.key,JSON.stringify(t))}catch{}}return{get:()=>t,set:c=>{t=c,d(),f()},subscribe:c=>(a.add(c),()=>{a.delete(c)})}}var k=/^[a-zA-Z0-9_-]{1,40}$/,P=o=>o==null||o==="";function q(o,e){const i=e[o.property];if(P(i))return!1;if(Array.isArray(o.value))return o.value.some(f=>String(i)===String(f));if(!o.op)return String(i)===String(o.value);const t=Number(i),a=Number(o.value);if(Number.isNaN(t)||Number.isNaN(a))return!1;switch(o.op){case">=":return t>=a;case"<=":return t<=a;case">":return t>a;case"<":return t<a;default:return O.logger.warn(`Unknown requiredWhen op "${o.op}"; treating as not required.`),!1}}function p(o,e){const i=o.properties??{},t=new Set;for(const f of o.required??[]){const d=i[f]?.requiredWhen;(!d||q(d,e))&&t.add(f)}for(const[f,d]of Object.entries(i))d.requiredWhen&&q(d.requiredWhen,e)&&t.add(f);const a=[...t].filter(f=>P(e[f]));return{missing:a,complete:a.length===0}}function W(o){const e={};for(const[i,t]of Object.entries(o.properties??{}))e[i]={type:t.type,...t.description!=null&&{description:t.description},...t.enum&&{enum:t.enum},...t.default!==void 0&&{default:t.default}};return{type:"object",properties:e,required:[]}}function j(o){const{name:e,description:i,schema:t}=o;if(!k.test(e))throw new Error(`Invalid form collector name "${e}": must match ${k} (it becomes the update_/submit_ function names).`);const a=typeof o.submit=="string"?o.submit?{via:"client",url:o.submit}:!1:o.submit??!1,f=t.properties??{},d=r=>{const n={};for(const[u,s]of Object.entries(r)){const l=f[u];if(l)if(s==null)n[u]=s;else if(l.type==="number"||l.type==="integer"){const b=typeof s=="number"?s:Number(s);n[u]=Number.isNaN(b)?s:b}else l.type==="boolean"?n[u]=typeof s=="boolean"?s:s==="true"?!0:s==="false"?!1:!!s:n[u]=s}return n},c=o.initialValues??{},m=_({values:c,submitted:!1}),v=r=>{const n=m.get(),u={...n,values:{...n.values,...r}};return m.set(u),u};let h=null;const N=async()=>{const{values:r}=m.get(),{complete:n,missing:u}=p(t,r);if(!n)return{ok:!1,missing:u};if(!a)return{ok:!1,error:"No submit target configured for this form collector."};const s=r;try{let l;if(a.via==="client")if("handler"in a)l=await a.handler(s);else{const b=await fetch(a.url,{method:"POST",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify(s)});if(!b.ok)return{ok:!1,error:`Submit failed: HTTP ${b.status}`};l=await b.json().catch(()=>{})}else{if(!h)return{ok:!1,error:"Backend submit requires install(client) (or useFormCollector) first."};l=await h.submitFormCollector(a.destination,s)}return m.set({...m.get(),submitted:!0}),{ok:!0,result:l}}catch(l){const b=l instanceof Error?l.message:"Submit failed";return O.logger.error(`FormCollector "${e}" submit failed:`,l),{ok:!1,error:b}}},S={name:`update_${e}`,description:`Fill or update fields of the "${e}" form. ${i} 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:W(t),handler:r=>{const n=v(d(r)),{missing:u}=p(t,n.values);return{ok:!0,values:n.values,missing:u}}},g=[S];a&&g.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:()=>N()});const T="client__",C=a?`submit_${e}`:null,E=r=>{const n=r.functionName??r.toolName;if(n)return n.startsWith(T)?n.slice(8):n},$=r=>{let n={...c},u=!1;for(const s of r){const l=E(s);l===S.name?s.arguments&&(n={...n,...d(s.arguments)}):C&&l===C&&s.status?.toLowerCase()==="done"&&(u=!0)}m.set({values:n,submitted:u})},y=`form:${e}`,w=()=>{const{values:r,submitted:n}=m.get(),{missing:u,complete:s}=p(t,r),l=a?` When nothing is missing and the user confirms, call submit_${e}.`:"",b=n?`The "${e}" form has been submitted.`:`You are currently collecting information from the user to fill the "${e}" form.`;return{name:`Form: ${e}`,description:`${b} ${i} There are conditionnals questions/values to collected, you can find this information with the requiredWhen field in the form. The form schema is the following: ${JSON.stringify(t)}. Data collected so far: ${JSON.stringify(r)}. Call update_${e} with any fields the user provides; ask only for what is still missing.${l}`,data:{values:r,missing:u,complete:s,submitted:n}}},F=r=>{$((r.messages??[]).flatMap(n=>n.toolCalls??[]))};return{name:e,store:m,functions:g,contextKey:y,contextProvider:w,install:r=>{h=r;for(const u of g)r.register(u);r.addDynamicContext(y,w);const n=m.subscribe(()=>r.notifyContextChanged());return r.on("conversation:loaded",F),()=>{n();for(const u of g)r.unregisterFunction(u.name);r.removeDynamicContext(y),r.off("conversation:loaded",F),h===r&&(h=null)}},hydrate:$,submit:N,getValues:()=>m.get().values,setValues:r=>{v(d(r))},reset:()=>{m.set({values:c,submitted:!1})},getStatus:()=>p(t,m.get().values)}}async function x(o,e){const i=await o.getFormCollector(e.name);return j({name:i.name,description:e.description??i.description,schema:e.schema??i.schema,submit:e.submit??i.submit,initialValues:e.initialValues})}Object.defineProperty(exports,"createFormCollector",{enumerable:!0,get:function(){return j}});Object.defineProperty(exports,"createStore",{enumerable:!0,get:function(){return _}});Object.defineProperty(exports,"deriveFormStatus",{enumerable:!0,get:function(){return p}});Object.defineProperty(exports,"loadFormCollector",{enumerable:!0,get:function(){return x}});
@@ -53,6 +53,13 @@ declare class AgoClient {
53
53
  * Reject a tool call
54
54
  */
55
55
  rejectToolCall(toolCallId: string): Promise<void>;
56
+ /**
57
+ * Fetch a backend-stored form collector definition by name (the single source
58
+ * of truth for the form's description, schema, and submit target). Used by
59
+ * `loadFormCollector` / the name-only form of `useFormCollector` so the schema
60
+ * lives in the backend instead of being hardcoded in client code.
61
+ */
62
+ getFormCollector(name: string): Promise<FormCollectorDefinition>;
56
63
  /**
57
64
  * Relay a completed form collector's values to a server-configured destination.
58
65
  *
@@ -399,6 +406,30 @@ export declare interface DevPanelOptions {
399
406
  */
400
407
  declare type DynamicContextProvider = () => ContextEntry | null | undefined;
401
408
 
409
+ /**
410
+ * The backend-stored shape returned by `GET /api/sdk/v1/forms/{name}` (see
411
+ * {@link AgoClient.getFormCollector}). Mirrors the persistable subset of
412
+ * {@link CreateFormCollectorOptions}: the `submit` here is never the client-only
413
+ * `handler` variant (a function can't be stored server-side).
414
+ */
415
+ declare interface FormCollectorDefinition<V = Record<string, unknown>> {
416
+ name: string;
417
+ description: string;
418
+ schema: FormCollectorSchema;
419
+ /** Server-stored submit target, if any. Absent means collect-only. */
420
+ submit?: SubmitConfig<V>;
421
+ }
422
+
423
+ /**
424
+ * Shape of a form's fields. Mirrors a client function's `parameters` (so the same
425
+ * object feeds the store, the update function, and the dynamic context). Additionally allows the SDK-only per-field `requiredWhen`, which {@link toWireParameters} removes before the schema reaches the LLM.
426
+ */
427
+ declare interface FormCollectorSchema {
428
+ type: "object";
429
+ properties: Record<string, FormFieldSchema>;
430
+ required?: string[];
431
+ }
432
+
402
433
  declare interface FormField {
403
434
  type: "string" | "number" | "boolean" | "array";
404
435
  title?: string;
@@ -407,6 +438,43 @@ declare interface FormField {
407
438
  default?: unknown;
408
439
  }
409
440
 
441
+ /**
442
+ * A field's conditional-requiredness rule. The field becomes required exactly
443
+ * when the controlling `property` matches `value` against the answers collected
444
+ * so far:
445
+ * - a single `value`, no `op` — equality (compared as strings);
446
+ * - a single `value` with `op` — numeric comparison (both sides coerced to numbers);
447
+ * - an array `value`, no `op` — "one of": matches when the property equals any
448
+ * listed value.
449
+ *
450
+ * SDK-only — it is stripped from the schema before it reaches the LLM tool
451
+ */
452
+ declare interface FormFieldCondition {
453
+ /** The controlling field whose value the rule tests. */
454
+ property: string;
455
+ /** Comparison operator; omitted means equality. Ignored when `value` is an array. */
456
+ op?: ">=" | "<=" | ">" | "<";
457
+ /**
458
+ * The value(s) to test the controlling field against. A single value is an
459
+ * equality (or, with `op`, a numeric comparison); an array is an "is one of"
460
+ * membership test, e.g. `value: ["1", "2", "3"]`.
461
+ */
462
+ value: string | number | Array<string | number>;
463
+ }
464
+
465
+ /** A single field's schema: the wire-legal keys plus the SDK-only `requiredWhen`. */
466
+ declare interface FormFieldSchema {
467
+ type: string;
468
+ description?: string;
469
+ enum?: string[];
470
+ default?: unknown;
471
+ /**
472
+ * Makes the field required only while this condition holds. Drives the dynamic
473
+ * `missing` list; stripped before the LLM tool — see {@link toWireParameters}.
474
+ */
475
+ requiredWhen?: FormFieldCondition;
476
+ }
477
+
410
478
  /**
411
479
  * Form schema for tool calls requiring user input
412
480
  */
@@ -432,6 +500,27 @@ declare interface SendMessageOptions {
432
500
  files?: File[];
433
501
  }
434
502
 
503
+ /**
504
+ * Where a completed form is sent.
505
+ * - `"https://..."` (a bare string) — shorthand for `{ via: "client", url }`: the browser
506
+ * POSTs the values to that URL.
507
+ * - `{ via: "client", url }` — same, written out.
508
+ * - `{ via: "client", handler }` — the browser runs your own submit logic.
509
+ * - `{ via: "backend", destination }` — the browser relays the values to the backend,
510
+ * which forwards them to the server-configured destination (URL + secret stay server-side).
511
+ * - `false` — collect only, no submit function.
512
+ */
513
+ declare type SubmitConfig<V = Record<string, unknown>> = string | {
514
+ via: "client";
515
+ url: string;
516
+ } | {
517
+ via: "client";
518
+ handler: (values: V) => Promise<unknown> | unknown;
519
+ } | {
520
+ via: "backend";
521
+ destination: string;
522
+ } | false;
523
+
435
524
  /**
436
525
  * Tool call data from SSE stream
437
526
  */
@@ -53,6 +53,13 @@ declare class AgoClient {
53
53
  * Reject a tool call
54
54
  */
55
55
  rejectToolCall(toolCallId: string): Promise<void>;
56
+ /**
57
+ * Fetch a backend-stored form collector definition by name (the single source
58
+ * of truth for the form's description, schema, and submit target). Used by
59
+ * `loadFormCollector` / the name-only form of `useFormCollector` so the schema
60
+ * lives in the backend instead of being hardcoded in client code.
61
+ */
62
+ getFormCollector(name: string): Promise<FormCollectorDefinition>;
56
63
  /**
57
64
  * Relay a completed form collector's values to a server-configured destination.
58
65
  *
@@ -399,6 +406,30 @@ export declare interface DevPanelOptions {
399
406
  */
400
407
  declare type DynamicContextProvider = () => ContextEntry | null | undefined;
401
408
 
409
+ /**
410
+ * The backend-stored shape returned by `GET /api/sdk/v1/forms/{name}` (see
411
+ * {@link AgoClient.getFormCollector}). Mirrors the persistable subset of
412
+ * {@link CreateFormCollectorOptions}: the `submit` here is never the client-only
413
+ * `handler` variant (a function can't be stored server-side).
414
+ */
415
+ declare interface FormCollectorDefinition<V = Record<string, unknown>> {
416
+ name: string;
417
+ description: string;
418
+ schema: FormCollectorSchema;
419
+ /** Server-stored submit target, if any. Absent means collect-only. */
420
+ submit?: SubmitConfig<V>;
421
+ }
422
+
423
+ /**
424
+ * Shape of a form's fields. Mirrors a client function's `parameters` (so the same
425
+ * object feeds the store, the update function, and the dynamic context). Additionally allows the SDK-only per-field `requiredWhen`, which {@link toWireParameters} removes before the schema reaches the LLM.
426
+ */
427
+ declare interface FormCollectorSchema {
428
+ type: "object";
429
+ properties: Record<string, FormFieldSchema>;
430
+ required?: string[];
431
+ }
432
+
402
433
  declare interface FormField {
403
434
  type: "string" | "number" | "boolean" | "array";
404
435
  title?: string;
@@ -407,6 +438,43 @@ declare interface FormField {
407
438
  default?: unknown;
408
439
  }
409
440
 
441
+ /**
442
+ * A field's conditional-requiredness rule. The field becomes required exactly
443
+ * when the controlling `property` matches `value` against the answers collected
444
+ * so far:
445
+ * - a single `value`, no `op` — equality (compared as strings);
446
+ * - a single `value` with `op` — numeric comparison (both sides coerced to numbers);
447
+ * - an array `value`, no `op` — "one of": matches when the property equals any
448
+ * listed value.
449
+ *
450
+ * SDK-only — it is stripped from the schema before it reaches the LLM tool
451
+ */
452
+ declare interface FormFieldCondition {
453
+ /** The controlling field whose value the rule tests. */
454
+ property: string;
455
+ /** Comparison operator; omitted means equality. Ignored when `value` is an array. */
456
+ op?: ">=" | "<=" | ">" | "<";
457
+ /**
458
+ * The value(s) to test the controlling field against. A single value is an
459
+ * equality (or, with `op`, a numeric comparison); an array is an "is one of"
460
+ * membership test, e.g. `value: ["1", "2", "3"]`.
461
+ */
462
+ value: string | number | Array<string | number>;
463
+ }
464
+
465
+ /** A single field's schema: the wire-legal keys plus the SDK-only `requiredWhen`. */
466
+ declare interface FormFieldSchema {
467
+ type: string;
468
+ description?: string;
469
+ enum?: string[];
470
+ default?: unknown;
471
+ /**
472
+ * Makes the field required only while this condition holds. Drives the dynamic
473
+ * `missing` list; stripped before the LLM tool — see {@link toWireParameters}.
474
+ */
475
+ requiredWhen?: FormFieldCondition;
476
+ }
477
+
410
478
  /**
411
479
  * Form schema for tool calls requiring user input
412
480
  */
@@ -432,6 +500,27 @@ declare interface SendMessageOptions {
432
500
  files?: File[];
433
501
  }
434
502
 
503
+ /**
504
+ * Where a completed form is sent.
505
+ * - `"https://..."` (a bare string) — shorthand for `{ via: "client", url }`: the browser
506
+ * POSTs the values to that URL.
507
+ * - `{ via: "client", url }` — same, written out.
508
+ * - `{ via: "client", handler }` — the browser runs your own submit logic.
509
+ * - `{ via: "backend", destination }` — the browser relays the values to the backend,
510
+ * which forwards them to the server-configured destination (URL + secret stay server-side).
511
+ * - `false` — collect only, no submit function.
512
+ */
513
+ declare type SubmitConfig<V = Record<string, unknown>> = string | {
514
+ via: "client";
515
+ url: string;
516
+ } | {
517
+ via: "client";
518
+ handler: (values: V) => Promise<unknown> | unknown;
519
+ } | {
520
+ via: "backend";
521
+ destination: string;
522
+ } | false;
523
+
435
524
  /**
436
525
  * Tool call data from SSE stream
437
526
  */
package/dist/index.cjs CHANGED
@@ -1 +1 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("./AgoClient-CPqPT5s6.cjs"),m=require("./createFormCollector-DaWZsBsI.cjs"),A=require("./createConversationSession-CGRO0bs2.cjs"),C=require("./createMockClient-zHQ0cjUH.cjs");require("./testing.cjs");const g=require("./functions-DsmzgHjC.cjs");function h(e){return e}function E(e,o){return e.on("message:complete",o),()=>e.off("message:complete",o)}function S(e,o){return e.on("message:chunk",o),()=>e.off("message:chunk",o)}function y(e,o){return e.on("message:start",o),()=>e.off("message:start",o)}function b(e,o){return e.on("message:error",o),()=>e.off("message:error",o)}function v(e,o){return e.on("toolCall:received",o),()=>e.off("toolCall:received",o)}function M(e,o){return e.on("function:invoke",o),()=>e.off("function:invoke",o)}async function*k(e,o,l){const n=[];let r=null,a=!1;const c=s=>{n.push(s),r?.()},f=s=>c({type:"start",data:s}),t=s=>c({type:"chunk",data:s}),u=s=>{c({type:"complete",data:s}),a=!0,r?.()},d=s=>{c({type:"error",data:s}),a=!0,r?.()},p=s=>c({type:"toolCall",data:s});e.on("message:start",f),e.on("message:chunk",t),e.on("message:complete",u),e.on("message:error",d),e.on("toolCall:received",p),e.sendMessage(o,l).catch(()=>{a=!0,r?.()});try{for(;!a||n.length>0;)n.length>0?yield n.shift():(await new Promise(s=>{r=s}),r=null)}finally{e.off("message:start",f),e.off("message:chunk",t),e.off("message:complete",u),e.off("message:error",d),e.off("toolCall:received",p)}}function w(e){let o,l,n,r,a,c;if(typeof window<"u"&&window.AGO){const t=window.AGO;o=t.basepath,l=t.widgetId,n=t.agent||t.defaultAgent,r=t.permission,a=t.email,c=t.jwt}if(typeof document<"u"){const t=u=>document.querySelector(`meta[name="${u}"]`)?.getAttribute("content")||void 0;o=o||t("ago-base-url"),l=l||t("ago-widget-id"),n=n||t("ago-agent")||t("ago-agent-id"),r=r||t("ago-permission"),a=a||t("ago-user-email")}if(typeof document<"u"){const t=[document.body,...Array.from(document.querySelectorAll("script[data-ago-base-url]"))].filter(Boolean);for(const u of t)u&&(o=o||u.getAttribute("data-ago-base-url")||void 0,l=l||u.getAttribute("data-ago-widget-id")||void 0,n=n||u.getAttribute("data-ago-agent")||u.getAttribute("data-ago-agent-id")||void 0,r=r||u.getAttribute("data-ago-permission")||void 0,a=a||u.getAttribute("data-ago-user-email")||void 0)}o=e?.baseUrl||o,l=e?.widgetId||l,n=e?.agent||e?.defaultAgentId||n,r=e?.permission||r,a=e?.userEmail||a,c=e?.userJwt||c;const f=e?.debug;return o?{baseUrl:o,widgetId:l,agent:n,permission:r,userEmail:a,userJwt:c,debug:f}:null}function F(e){const o=w(e);if(!o)throw new Error('createAgo(): could not detect AGO configuration. Set window.AGO, add <meta name="ago-base-url">, or pass { baseUrl } explicitly.');return new i.AgoClient(o)}function q(e,o){return{...e,handler:o}}exports.AgoApiError=i.AgoApiError;exports.AgoClient=i.AgoClient;exports.AgoError=i.AgoError;exports.AgoFunctionError=i.AgoFunctionError;exports.AgoNetworkError=i.AgoNetworkError;exports.AgoStreamError=i.AgoStreamError;exports.ClientContextRegistry=i.ClientContextRegistry;exports.EventEmitter=i.EventEmitter;exports.FunctionRegistry=i.FunctionRegistry;exports.SSEHandler=i.SSEHandler;exports.autoDetectConfig=w;exports.copyToClipboard=g.copyToClipboard;exports.createAgo=F;exports.createConversationSession=A.createConversationSession;exports.createFormCollector=m.createFormCollector;exports.createMessageStream=k;exports.createMockClient=C.createMockClient;exports.createStore=m.createStore;exports.defineFunction=h;exports.deriveFormStatus=m.deriveFormStatus;exports.getLocalStorage=g.getLocalStorage;exports.getUserLocation=g.getUserLocation;exports.highlightElement=g.highlightElement;exports.isStreamNetworkError=i.isStreamNetworkError;exports.logger=i.logger;exports.onFunctionInvoke=M;exports.onMessage=E;exports.onMessageChunk=S;exports.onMessageError=b;exports.onMessageStart=y;exports.onToolCall=v;exports.openUrl=g.openUrl;exports.scrollToElement=g.scrollToElement;exports.setLocalStorage=g.setLocalStorage;exports.setTheme=g.setTheme;exports.showConfirmDialog=g.showConfirmDialog;exports.showNotification=g.showNotification;exports.showToast=g.showToast;exports.submitForm=g.submitForm;exports.trackEvent=g.trackEvent;exports.withHandler=q;
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("./AgoClient-0x2Du_62.cjs"),f=require("./createFormCollector-Ca8wRrxc.cjs"),w=require("./createConversationSession-BLZvXMmM.cjs"),A=require("./createMockClient-zHQ0cjUH.cjs");require("./testing.cjs");const g=require("./functions-DsmzgHjC.cjs");function h(e){return e}function E(e,o){return e.on("message:complete",o),()=>e.off("message:complete",o)}function S(e,o){return e.on("message:chunk",o),()=>e.off("message:chunk",o)}function y(e,o){return e.on("message:start",o),()=>e.off("message:start",o)}function b(e,o){return e.on("message:error",o),()=>e.off("message:error",o)}function v(e,o){return e.on("toolCall:received",o),()=>e.off("toolCall:received",o)}function F(e,o){return e.on("function:invoke",o),()=>e.off("function:invoke",o)}async function*M(e,o,l){const n=[];let r=null,a=!1;const c=s=>{n.push(s),r?.()},m=s=>c({type:"start",data:s}),t=s=>c({type:"chunk",data:s}),u=s=>{c({type:"complete",data:s}),a=!0,r?.()},d=s=>{c({type:"error",data:s}),a=!0,r?.()},C=s=>c({type:"toolCall",data:s});e.on("message:start",m),e.on("message:chunk",t),e.on("message:complete",u),e.on("message:error",d),e.on("toolCall:received",C),e.sendMessage(o,l).catch(()=>{a=!0,r?.()});try{for(;!a||n.length>0;)n.length>0?yield n.shift():(await new Promise(s=>{r=s}),r=null)}finally{e.off("message:start",m),e.off("message:chunk",t),e.off("message:complete",u),e.off("message:error",d),e.off("toolCall:received",C)}}function p(e){let o,l,n,r,a,c;if(typeof window<"u"&&window.AGO){const t=window.AGO;o=t.basepath,l=t.widgetId,n=t.agent||t.defaultAgent,r=t.permission,a=t.email,c=t.jwt}if(typeof document<"u"){const t=u=>document.querySelector(`meta[name="${u}"]`)?.getAttribute("content")||void 0;o=o||t("ago-base-url"),l=l||t("ago-widget-id"),n=n||t("ago-agent")||t("ago-agent-id"),r=r||t("ago-permission"),a=a||t("ago-user-email")}if(typeof document<"u"){const t=[document.body,...Array.from(document.querySelectorAll("script[data-ago-base-url]"))].filter(Boolean);for(const u of t)u&&(o=o||u.getAttribute("data-ago-base-url")||void 0,l=l||u.getAttribute("data-ago-widget-id")||void 0,n=n||u.getAttribute("data-ago-agent")||u.getAttribute("data-ago-agent-id")||void 0,r=r||u.getAttribute("data-ago-permission")||void 0,a=a||u.getAttribute("data-ago-user-email")||void 0)}o=e?.baseUrl||o,l=e?.widgetId||l,n=e?.agent||e?.defaultAgentId||n,r=e?.permission||r,a=e?.userEmail||a,c=e?.userJwt||c;const m=e?.debug;return o?{baseUrl:o,widgetId:l,agent:n,permission:r,userEmail:a,userJwt:c,debug:m}:null}function k(e){const o=p(e);if(!o)throw new Error('createAgo(): could not detect AGO configuration. Set window.AGO, add <meta name="ago-base-url">, or pass { baseUrl } explicitly.');return new i.AgoClient(o)}function q(e,o){return{...e,handler:o}}exports.AgoApiError=i.AgoApiError;exports.AgoClient=i.AgoClient;exports.AgoError=i.AgoError;exports.AgoFunctionError=i.AgoFunctionError;exports.AgoNetworkError=i.AgoNetworkError;exports.AgoStreamError=i.AgoStreamError;exports.ClientContextRegistry=i.ClientContextRegistry;exports.EventEmitter=i.EventEmitter;exports.FunctionRegistry=i.FunctionRegistry;exports.SSEHandler=i.SSEHandler;exports.autoDetectConfig=p;exports.copyToClipboard=g.copyToClipboard;exports.createAgo=k;exports.createConversationSession=w.createConversationSession;exports.createFormCollector=f.createFormCollector;exports.createMessageStream=M;exports.createMockClient=A.createMockClient;exports.createStore=f.createStore;exports.defineFunction=h;exports.deriveFormStatus=f.deriveFormStatus;exports.getLocalStorage=g.getLocalStorage;exports.getUserLocation=g.getUserLocation;exports.highlightElement=g.highlightElement;exports.isStreamNetworkError=i.isStreamNetworkError;exports.loadFormCollector=f.loadFormCollector;exports.logger=i.logger;exports.onFunctionInvoke=F;exports.onMessage=E;exports.onMessageChunk=S;exports.onMessageError=b;exports.onMessageStart=y;exports.onToolCall=v;exports.openUrl=g.openUrl;exports.scrollToElement=g.scrollToElement;exports.setLocalStorage=g.setLocalStorage;exports.setTheme=g.setTheme;exports.showConfirmDialog=g.showConfirmDialog;exports.showNotification=g.showNotification;exports.showToast=g.showToast;exports.submitForm=g.submitForm;exports.trackEvent=g.trackEvent;exports.withHandler=q;