@useago/sdk 0.4.4 → 0.4.6
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/{createConversationSession-XkiOGAUT.js → createConversationSession-D-eq8VIo.js} +1 -1
- package/dist/{createConversationSession-DibXdxoC.cjs → createConversationSession-DGcM_Z3f.cjs} +1 -1
- package/dist/createFormCollector-DON4vdJV.js +244 -0
- package/dist/createFormCollector-IO6bfPQx.cjs +1 -0
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +49 -4
- package/dist/index.d.ts +49 -4
- package/dist/index.js +2 -2
- package/dist/react.cjs +1 -1
- package/dist/react.d.cts +49 -4
- package/dist/react.d.ts +49 -4
- package/dist/react.js +1 -1
- package/dist/widget.cjs +5 -1
- package/dist/widget.d.cts +75 -6
- package/dist/widget.d.ts +75 -6
- package/dist/widget.js +417 -234
- package/package.json +1 -1
- package/dist/createFormCollector-D4-yZh1i.js +0 -207
- package/dist/createFormCollector-DLwgDX24.cjs +0 -1
package/dist/{createConversationSession-XkiOGAUT.js → createConversationSession-D-eq8VIo.js}
RENAMED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { r as d } from "./createFormCollector-
|
|
1
|
+
import { r as d } from "./createFormCollector-DON4vdJV.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) => {
|
package/dist/{createConversationSession-DibXdxoC.cjs → createConversationSession-DGcM_Z3f.cjs}
RENAMED
|
@@ -1 +1 @@
|
|
|
1
|
-
const d=require("./createFormCollector-
|
|
1
|
+
const d=require("./createFormCollector-IO6bfPQx.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 _}});
|
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
import { s as _ } from "./AgoClient-rvTz2thR.js";
|
|
2
|
+
function E(n, e) {
|
|
3
|
+
const l = e ? e.storage ?? (typeof localStorage < "u" ? localStorage : void 0) : void 0;
|
|
4
|
+
let t = n;
|
|
5
|
+
if (e && l) try {
|
|
6
|
+
const c = l.getItem(e.key);
|
|
7
|
+
c != null && (t = JSON.parse(c));
|
|
8
|
+
} catch {
|
|
9
|
+
}
|
|
10
|
+
const i = /* @__PURE__ */ new Set(), f = () => i.forEach((c) => c(t));
|
|
11
|
+
function m() {
|
|
12
|
+
if (e && l) try {
|
|
13
|
+
l.setItem(e.key, JSON.stringify(t));
|
|
14
|
+
} catch {
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
return {
|
|
18
|
+
get: () => t,
|
|
19
|
+
set: (c) => {
|
|
20
|
+
t = c, m(), f();
|
|
21
|
+
},
|
|
22
|
+
subscribe: (c) => (i.add(c), () => {
|
|
23
|
+
i.delete(c);
|
|
24
|
+
})
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
var q = /^[a-zA-Z0-9_-]{1,40}$/, O = (n) => n == null || n === "";
|
|
28
|
+
function F(n, e) {
|
|
29
|
+
const l = e[n.property];
|
|
30
|
+
if (O(l)) return !1;
|
|
31
|
+
if (Array.isArray(n.value)) return n.value.some((f) => String(l) === String(f));
|
|
32
|
+
if (!n.op) return String(l) === String(n.value);
|
|
33
|
+
const t = Number(l), i = Number(n.value);
|
|
34
|
+
if (Number.isNaN(t) || Number.isNaN(i)) return !1;
|
|
35
|
+
switch (n.op) {
|
|
36
|
+
case ">=":
|
|
37
|
+
return t >= i;
|
|
38
|
+
case "<=":
|
|
39
|
+
return t <= i;
|
|
40
|
+
case ">":
|
|
41
|
+
return t > i;
|
|
42
|
+
case "<":
|
|
43
|
+
return t < i;
|
|
44
|
+
default:
|
|
45
|
+
return _.warn(`Unknown requiredWhen op "${n.op}"; treating as not required.`), !1;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
function y(n, e) {
|
|
49
|
+
const l = n.properties ?? {}, t = /* @__PURE__ */ new Set();
|
|
50
|
+
for (const f of n.required ?? []) {
|
|
51
|
+
const m = l[f]?.requiredWhen;
|
|
52
|
+
(!m || F(m, e)) && t.add(f);
|
|
53
|
+
}
|
|
54
|
+
for (const [f, m] of Object.entries(l)) m.requiredWhen && F(m.requiredWhen, e) && t.add(f);
|
|
55
|
+
const i = [...t].filter((f) => O(e[f]));
|
|
56
|
+
return {
|
|
57
|
+
missing: i,
|
|
58
|
+
complete: i.length === 0
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
function P(n) {
|
|
62
|
+
const e = {};
|
|
63
|
+
for (const [l, t] of Object.entries(n.properties ?? {})) e[l] = {
|
|
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 I(n) {
|
|
76
|
+
const { name: e, description: l, schema: t } = n;
|
|
77
|
+
if (!q.test(e)) throw new Error(`Invalid form collector name "${e}": must match ${q} (it becomes the update_/submit_ function names).`);
|
|
78
|
+
const i = typeof n.submit == "string" ? n.submit ? {
|
|
79
|
+
via: "client",
|
|
80
|
+
url: n.submit
|
|
81
|
+
} : !1 : n.submit ?? !1, f = t.properties ?? {}, m = (r) => {
|
|
82
|
+
const s = {};
|
|
83
|
+
for (const [a, o] of Object.entries(r)) {
|
|
84
|
+
const u = f[a];
|
|
85
|
+
if (u)
|
|
86
|
+
if (o == null) s[a] = o;
|
|
87
|
+
else if (u.type === "number" || u.type === "integer") {
|
|
88
|
+
const p = typeof o == "number" ? o : Number(o);
|
|
89
|
+
s[a] = Number.isNaN(p) ? o : p;
|
|
90
|
+
} else u.type === "boolean" ? s[a] = typeof o == "boolean" ? o : o === "true" ? !0 : o === "false" ? !1 : !!o : s[a] = o;
|
|
91
|
+
}
|
|
92
|
+
return s;
|
|
93
|
+
}, c = n.initialValues ?? {}, d = E({
|
|
94
|
+
values: c,
|
|
95
|
+
submitted: !1
|
|
96
|
+
}), v = (r) => {
|
|
97
|
+
const s = d.get(), a = {
|
|
98
|
+
...s,
|
|
99
|
+
values: {
|
|
100
|
+
...s.values,
|
|
101
|
+
...r
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
return d.set(a), a;
|
|
105
|
+
};
|
|
106
|
+
let h = null;
|
|
107
|
+
const N = async () => {
|
|
108
|
+
const { values: r } = d.get(), { complete: s, missing: a } = y(t, r);
|
|
109
|
+
if (!s) return {
|
|
110
|
+
ok: !1,
|
|
111
|
+
missing: a
|
|
112
|
+
};
|
|
113
|
+
if (!i) return {
|
|
114
|
+
ok: !1,
|
|
115
|
+
error: "No submit target configured for this form collector."
|
|
116
|
+
};
|
|
117
|
+
const o = r;
|
|
118
|
+
try {
|
|
119
|
+
let u;
|
|
120
|
+
if (i.via === "client") if ("handler" in i) u = await i.handler(o);
|
|
121
|
+
else {
|
|
122
|
+
const p = await fetch(i.url, {
|
|
123
|
+
method: "POST",
|
|
124
|
+
headers: { "Content-Type": "application/json" },
|
|
125
|
+
credentials: "include",
|
|
126
|
+
body: JSON.stringify(o)
|
|
127
|
+
});
|
|
128
|
+
if (!p.ok) return {
|
|
129
|
+
ok: !1,
|
|
130
|
+
error: `Submit failed: HTTP ${p.status}`
|
|
131
|
+
};
|
|
132
|
+
u = await p.json().catch(() => {
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
else {
|
|
136
|
+
if (!h) return {
|
|
137
|
+
ok: !1,
|
|
138
|
+
error: "Backend submit requires install(client) (or useFormCollector) first."
|
|
139
|
+
};
|
|
140
|
+
u = await h.submitFormCollector(i.destination, o);
|
|
141
|
+
}
|
|
142
|
+
return d.set({
|
|
143
|
+
...d.get(),
|
|
144
|
+
submitted: !0
|
|
145
|
+
}), {
|
|
146
|
+
ok: !0,
|
|
147
|
+
result: u
|
|
148
|
+
};
|
|
149
|
+
} catch (u) {
|
|
150
|
+
const p = u instanceof Error ? u.message : "Submit failed";
|
|
151
|
+
return _.error(`FormCollector "${e}" submit failed:`, u), {
|
|
152
|
+
ok: !1,
|
|
153
|
+
error: p
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
}, $ = {
|
|
157
|
+
name: `update_${e}`,
|
|
158
|
+
description: `Fill or update fields of the "${e}" form. ${l} 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(m(r)), { missing: a } = y(t, s.values);
|
|
162
|
+
return {
|
|
163
|
+
ok: !0,
|
|
164
|
+
values: s.values,
|
|
165
|
+
missing: a
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
}, b = [$];
|
|
169
|
+
i && b.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 = i ? `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 }, a = !1;
|
|
184
|
+
for (const o of r) {
|
|
185
|
+
const u = x(o);
|
|
186
|
+
u === $.name ? o.arguments && (s = {
|
|
187
|
+
...s,
|
|
188
|
+
...m(o.arguments)
|
|
189
|
+
}) : S && u === S && o.status?.toLowerCase() === "done" && (a = !0);
|
|
190
|
+
}
|
|
191
|
+
d.set({
|
|
192
|
+
values: s,
|
|
193
|
+
submitted: a
|
|
194
|
+
});
|
|
195
|
+
}, g = `form:${e}`, C = () => {
|
|
196
|
+
const { values: r, submitted: s } = d.get(), { missing: a, complete: o } = y(t, r), u = i ? ` When nothing is missing and the user confirms, call submit_${e}.` : "", p = 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: `${p} ${l} 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.${u}`,
|
|
200
|
+
data: {
|
|
201
|
+
missing: a,
|
|
202
|
+
complete: o,
|
|
203
|
+
submitted: s
|
|
204
|
+
}
|
|
205
|
+
};
|
|
206
|
+
}, k = (r) => {
|
|
207
|
+
w((r.messages ?? []).flatMap((s) => s.toolCalls ?? []));
|
|
208
|
+
};
|
|
209
|
+
return {
|
|
210
|
+
name: e,
|
|
211
|
+
store: d,
|
|
212
|
+
functions: b,
|
|
213
|
+
contextKey: g,
|
|
214
|
+
contextProvider: C,
|
|
215
|
+
install: (r) => {
|
|
216
|
+
h = r;
|
|
217
|
+
for (const a of b) r.register(a);
|
|
218
|
+
r.addDynamicContext(g, C);
|
|
219
|
+
const s = d.subscribe(() => r.notifyContextChanged());
|
|
220
|
+
return r.on("conversation:loaded", k), () => {
|
|
221
|
+
s();
|
|
222
|
+
for (const a of b) r.unregisterFunction(a.name);
|
|
223
|
+
r.removeDynamicContext(g), r.off("conversation:loaded", k), h === r && (h = null);
|
|
224
|
+
};
|
|
225
|
+
},
|
|
226
|
+
hydrate: w,
|
|
227
|
+
submit: N,
|
|
228
|
+
getValues: () => d.get().values,
|
|
229
|
+
setValues: (r) => {
|
|
230
|
+
v(m(r));
|
|
231
|
+
},
|
|
232
|
+
reset: () => {
|
|
233
|
+
d.set({
|
|
234
|
+
values: c,
|
|
235
|
+
submitted: !1
|
|
236
|
+
});
|
|
237
|
+
}
|
|
238
|
+
};
|
|
239
|
+
}
|
|
240
|
+
export {
|
|
241
|
+
y as n,
|
|
242
|
+
E as r,
|
|
243
|
+
I as t
|
|
244
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const O=require("./AgoClient-D4EL6nva.cjs");function _(o,e){const l=e?e.storage??(typeof localStorage<"u"?localStorage:void 0):void 0;let t=o;if(e&&l)try{const c=l.getItem(e.key);c!=null&&(t=JSON.parse(c))}catch{}const i=new Set,f=()=>i.forEach(c=>c(t));function m(){if(e&&l)try{l.setItem(e.key,JSON.stringify(t))}catch{}}return{get:()=>t,set:c=>{t=c,m(),f()},subscribe:c=>(i.add(c),()=>{i.delete(c)})}}var q=/^[a-zA-Z0-9_-]{1,40}$/,P=o=>o==null||o==="";function F(o,e){const l=e[o.property];if(P(l))return!1;if(Array.isArray(o.value))return o.value.some(f=>String(l)===String(f));if(!o.op)return String(l)===String(o.value);const t=Number(l),i=Number(o.value);if(Number.isNaN(t)||Number.isNaN(i))return!1;switch(o.op){case">=":return t>=i;case"<=":return t<=i;case">":return t>i;case"<":return t<i;default:return O.logger.warn(`Unknown requiredWhen op "${o.op}"; treating as not required.`),!1}}function g(o,e){const l=o.properties??{},t=new Set;for(const f of o.required??[]){const m=l[f]?.requiredWhen;(!m||F(m,e))&&t.add(f)}for(const[f,m]of Object.entries(l))m.requiredWhen&&F(m.requiredWhen,e)&&t.add(f);const i=[...t].filter(f=>P(e[f]));return{missing:i,complete:i.length===0}}function E(o){const e={};for(const[l,t]of Object.entries(o.properties??{}))e[l]={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 W(o){const{name:e,description:l,schema:t}=o;if(!q.test(e))throw new Error(`Invalid form collector name "${e}": must match ${q} (it becomes the update_/submit_ function names).`);const i=typeof o.submit=="string"?o.submit?{via:"client",url:o.submit}:!1:o.submit??!1,f=t.properties??{},m=r=>{const n={};for(const[a,s]of Object.entries(r)){const u=f[a];if(u)if(s==null)n[a]=s;else if(u.type==="number"||u.type==="integer"){const b=typeof s=="number"?s:Number(s);n[a]=Number.isNaN(b)?s:b}else u.type==="boolean"?n[a]=typeof s=="boolean"?s:s==="true"?!0:s==="false"?!1:!!s:n[a]=s}return n},c=o.initialValues??{},d=_({values:c,submitted:!1}),v=r=>{const n=d.get(),a={...n,values:{...n.values,...r}};return d.set(a),a};let p=null;const N=async()=>{const{values:r}=d.get(),{complete:n,missing:a}=g(t,r);if(!n)return{ok:!1,missing:a};if(!i)return{ok:!1,error:"No submit target configured for this form collector."};const s=r;try{let u;if(i.via==="client")if("handler"in i)u=await i.handler(s);else{const b=await fetch(i.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}`};u=await b.json().catch(()=>{})}else{if(!p)return{ok:!1,error:"Backend submit requires install(client) (or useFormCollector) first."};u=await p.submitFormCollector(i.destination,s)}return d.set({...d.get(),submitted:!0}),{ok:!0,result:u}}catch(u){const b=u instanceof Error?u.message:"Submit failed";return O.logger.error(`FormCollector "${e}" submit failed:`,u),{ok:!1,error:b}}},S={name:`update_${e}`,description:`Fill or update fields of the "${e}" form. ${l} 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:E(t),handler:r=>{const n=v(m(r)),{missing:a}=g(t,n.values);return{ok:!0,values:n.values,missing:a}}},h=[S];i&&h.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__",$=i?`submit_${e}`:null,j=r=>{const n=r.functionName??r.toolName;if(n)return n.startsWith(T)?n.slice(8):n},w=r=>{let n={...c},a=!1;for(const s of r){const u=j(s);u===S.name?s.arguments&&(n={...n,...m(s.arguments)}):$&&u===$&&s.status?.toLowerCase()==="done"&&(a=!0)}d.set({values:n,submitted:a})},y=`form:${e}`,C=()=>{const{values:r,submitted:n}=d.get(),{missing:a,complete:s}=g(t,r),u=i?` 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} ${l} 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.${u}`,data:{missing:a,complete:s,submitted:n}}},k=r=>{w((r.messages??[]).flatMap(n=>n.toolCalls??[]))};return{name:e,store:d,functions:h,contextKey:y,contextProvider:C,install:r=>{p=r;for(const a of h)r.register(a);r.addDynamicContext(y,C);const n=d.subscribe(()=>r.notifyContextChanged());return r.on("conversation:loaded",k),()=>{n();for(const a of h)r.unregisterFunction(a.name);r.removeDynamicContext(y),r.off("conversation:loaded",k),p===r&&(p=null)}},hydrate:w,submit:N,getValues:()=>d.get().values,setValues:r=>{v(m(r))},reset:()=>{d.set({values:c,submitted:!1})}}}Object.defineProperty(exports,"createFormCollector",{enumerable:!0,get:function(){return W}});Object.defineProperty(exports,"createStore",{enumerable:!0,get:function(){return _}});Object.defineProperty(exports,"deriveFormStatus",{enumerable:!0,get:function(){return g}});
|
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("./AgoClient-D4EL6nva.cjs"),m=require("./createFormCollector-
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("./AgoClient-D4EL6nva.cjs"),m=require("./createFormCollector-IO6bfPQx.cjs"),A=require("./createConversationSession-DGcM_Z3f.cjs"),C=require("./createMockClient-zHQ0cjUH.cjs"),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;
|
package/dist/index.d.cts
CHANGED
|
@@ -745,6 +745,11 @@ export declare function defineFunction(definition: ClientFunctionDefinition): Cl
|
|
|
745
745
|
* Pure — the single home for the "required + non-empty" rule, shared by the update
|
|
746
746
|
* handler, submit, the dynamic context, and the React hook. Derived on read so the
|
|
747
747
|
* store only ever holds canonical state ({@link FormCollectorState}).
|
|
748
|
+
*
|
|
749
|
+
* Requiredness is answer-dependent: a field listed in `required` is required unless
|
|
750
|
+
* it carries a `requiredWhen` that doesn't currently hold, and any field whose
|
|
751
|
+
* `requiredWhen` holds becomes required. So conditional fields surface in `missing`
|
|
752
|
+
* exactly when the answers make them relevant.
|
|
748
753
|
*/
|
|
749
754
|
export declare function deriveFormStatus(schema: FormCollectorSchema, values: Partial<Record<string, unknown>>): FormCollectorStatus;
|
|
750
755
|
|
|
@@ -807,11 +812,14 @@ export declare interface FormCollector<V = Record<string, unknown>> {
|
|
|
807
812
|
}
|
|
808
813
|
|
|
809
814
|
/**
|
|
810
|
-
*
|
|
811
|
-
*
|
|
812
|
-
* dynamic context with no second type.
|
|
815
|
+
* Shape of a form's fields. Mirrors a client function's `parameters` (so the same
|
|
816
|
+
* 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.
|
|
813
817
|
*/
|
|
814
|
-
export declare
|
|
818
|
+
export declare interface FormCollectorSchema {
|
|
819
|
+
type: "object";
|
|
820
|
+
properties: Record<string, FormFieldSchema>;
|
|
821
|
+
required?: string[];
|
|
822
|
+
}
|
|
815
823
|
|
|
816
824
|
/** Canonical, source-of-truth state held in the collector's store. */
|
|
817
825
|
export declare interface FormCollectorState<V = Record<string, unknown>> {
|
|
@@ -837,6 +845,43 @@ export declare interface FormField {
|
|
|
837
845
|
default?: unknown;
|
|
838
846
|
}
|
|
839
847
|
|
|
848
|
+
/**
|
|
849
|
+
* A field's conditional-requiredness rule. The field becomes required exactly
|
|
850
|
+
* when the controlling `property` matches `value` against the answers collected
|
|
851
|
+
* so far:
|
|
852
|
+
* - a single `value`, no `op` — equality (compared as strings);
|
|
853
|
+
* - a single `value` with `op` — numeric comparison (both sides coerced to numbers);
|
|
854
|
+
* - an array `value`, no `op` — "one of": matches when the property equals any
|
|
855
|
+
* listed value.
|
|
856
|
+
*
|
|
857
|
+
* SDK-only — it is stripped from the schema before it reaches the LLM tool
|
|
858
|
+
*/
|
|
859
|
+
declare interface FormFieldCondition {
|
|
860
|
+
/** The controlling field whose value the rule tests. */
|
|
861
|
+
property: string;
|
|
862
|
+
/** Comparison operator; omitted means equality. Ignored when `value` is an array. */
|
|
863
|
+
op?: ">=" | "<=" | ">" | "<";
|
|
864
|
+
/**
|
|
865
|
+
* The value(s) to test the controlling field against. A single value is an
|
|
866
|
+
* equality (or, with `op`, a numeric comparison); an array is an "is one of"
|
|
867
|
+
* membership test, e.g. `value: ["1", "2", "3"]`.
|
|
868
|
+
*/
|
|
869
|
+
value: string | number | Array<string | number>;
|
|
870
|
+
}
|
|
871
|
+
|
|
872
|
+
/** A single field's schema: the wire-legal keys plus the SDK-only `requiredWhen`. */
|
|
873
|
+
declare interface FormFieldSchema {
|
|
874
|
+
type: string;
|
|
875
|
+
description?: string;
|
|
876
|
+
enum?: string[];
|
|
877
|
+
default?: unknown;
|
|
878
|
+
/**
|
|
879
|
+
* Makes the field required only while this condition holds. Drives the dynamic
|
|
880
|
+
* `missing` list; stripped before the LLM tool — see {@link toWireParameters}.
|
|
881
|
+
*/
|
|
882
|
+
requiredWhen?: FormFieldCondition;
|
|
883
|
+
}
|
|
884
|
+
|
|
840
885
|
/**
|
|
841
886
|
* Form schema for tool calls requiring user input
|
|
842
887
|
*/
|
package/dist/index.d.ts
CHANGED
|
@@ -745,6 +745,11 @@ export declare function defineFunction(definition: ClientFunctionDefinition): Cl
|
|
|
745
745
|
* Pure — the single home for the "required + non-empty" rule, shared by the update
|
|
746
746
|
* handler, submit, the dynamic context, and the React hook. Derived on read so the
|
|
747
747
|
* store only ever holds canonical state ({@link FormCollectorState}).
|
|
748
|
+
*
|
|
749
|
+
* Requiredness is answer-dependent: a field listed in `required` is required unless
|
|
750
|
+
* it carries a `requiredWhen` that doesn't currently hold, and any field whose
|
|
751
|
+
* `requiredWhen` holds becomes required. So conditional fields surface in `missing`
|
|
752
|
+
* exactly when the answers make them relevant.
|
|
748
753
|
*/
|
|
749
754
|
export declare function deriveFormStatus(schema: FormCollectorSchema, values: Partial<Record<string, unknown>>): FormCollectorStatus;
|
|
750
755
|
|
|
@@ -807,11 +812,14 @@ export declare interface FormCollector<V = Record<string, unknown>> {
|
|
|
807
812
|
}
|
|
808
813
|
|
|
809
814
|
/**
|
|
810
|
-
*
|
|
811
|
-
*
|
|
812
|
-
* dynamic context with no second type.
|
|
815
|
+
* Shape of a form's fields. Mirrors a client function's `parameters` (so the same
|
|
816
|
+
* 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.
|
|
813
817
|
*/
|
|
814
|
-
export declare
|
|
818
|
+
export declare interface FormCollectorSchema {
|
|
819
|
+
type: "object";
|
|
820
|
+
properties: Record<string, FormFieldSchema>;
|
|
821
|
+
required?: string[];
|
|
822
|
+
}
|
|
815
823
|
|
|
816
824
|
/** Canonical, source-of-truth state held in the collector's store. */
|
|
817
825
|
export declare interface FormCollectorState<V = Record<string, unknown>> {
|
|
@@ -837,6 +845,43 @@ export declare interface FormField {
|
|
|
837
845
|
default?: unknown;
|
|
838
846
|
}
|
|
839
847
|
|
|
848
|
+
/**
|
|
849
|
+
* A field's conditional-requiredness rule. The field becomes required exactly
|
|
850
|
+
* when the controlling `property` matches `value` against the answers collected
|
|
851
|
+
* so far:
|
|
852
|
+
* - a single `value`, no `op` — equality (compared as strings);
|
|
853
|
+
* - a single `value` with `op` — numeric comparison (both sides coerced to numbers);
|
|
854
|
+
* - an array `value`, no `op` — "one of": matches when the property equals any
|
|
855
|
+
* listed value.
|
|
856
|
+
*
|
|
857
|
+
* SDK-only — it is stripped from the schema before it reaches the LLM tool
|
|
858
|
+
*/
|
|
859
|
+
declare interface FormFieldCondition {
|
|
860
|
+
/** The controlling field whose value the rule tests. */
|
|
861
|
+
property: string;
|
|
862
|
+
/** Comparison operator; omitted means equality. Ignored when `value` is an array. */
|
|
863
|
+
op?: ">=" | "<=" | ">" | "<";
|
|
864
|
+
/**
|
|
865
|
+
* The value(s) to test the controlling field against. A single value is an
|
|
866
|
+
* equality (or, with `op`, a numeric comparison); an array is an "is one of"
|
|
867
|
+
* membership test, e.g. `value: ["1", "2", "3"]`.
|
|
868
|
+
*/
|
|
869
|
+
value: string | number | Array<string | number>;
|
|
870
|
+
}
|
|
871
|
+
|
|
872
|
+
/** A single field's schema: the wire-legal keys plus the SDK-only `requiredWhen`. */
|
|
873
|
+
declare interface FormFieldSchema {
|
|
874
|
+
type: string;
|
|
875
|
+
description?: string;
|
|
876
|
+
enum?: string[];
|
|
877
|
+
default?: unknown;
|
|
878
|
+
/**
|
|
879
|
+
* Makes the field required only while this condition holds. Drives the dynamic
|
|
880
|
+
* `missing` list; stripped before the LLM tool — see {@link toWireParameters}.
|
|
881
|
+
*/
|
|
882
|
+
requiredWhen?: FormFieldCondition;
|
|
883
|
+
}
|
|
884
|
+
|
|
840
885
|
/**
|
|
841
886
|
* Form schema for tool calls requiring user input
|
|
842
887
|
*/
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { a as w, c as h, d as A, f as y, i as C, l as E, n as S, o as b, r as v, s as k, t as d, u as M } from "./AgoClient-rvTz2thR.js";
|
|
2
|
-
import { n as T, r as I, t as U } from "./createFormCollector-
|
|
3
|
-
import { t as O } from "./createConversationSession-
|
|
2
|
+
import { n as T, r as I, t as U } from "./createFormCollector-DON4vdJV.js";
|
|
3
|
+
import { t as O } from "./createConversationSession-D-eq8VIo.js";
|
|
4
4
|
import { t as x } from "./createMockClient-DwdxNwEn.js";
|
|
5
5
|
import { a as N, c as D, d as H, f as J, i as R, l as j, m as B, o as P, p as $, r as z, s as K, t as Q, u as V } from "./functions-C1-5vadY.js";
|
|
6
6
|
function W(e) {
|