@useago/sdk 0.4.2 → 0.4.4
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-DtaeA418.cjs → createConversationSession-DibXdxoC.cjs} +1 -1
- package/dist/{createConversationSession-D9FesBQS.js → createConversationSession-XkiOGAUT.js} +1 -1
- package/dist/createFormCollector-D4-yZh1i.js +207 -0
- package/dist/createFormCollector-DLwgDX24.cjs +1 -0
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +15 -3
- package/dist/index.d.ts +15 -3
- package/dist/index.js +59 -58
- package/dist/react.cjs +13 -13
- package/dist/react.d.cts +20 -5
- package/dist/react.d.ts +20 -5
- package/dist/react.js +1031 -1025
- package/dist/widget.cjs +1 -1
- package/dist/widget.d.cts +37 -0
- package/dist/widget.d.ts +37 -0
- package/dist/widget.js +205 -183
- package/package.json +1 -1
- package/dist/createFormCollector-BwvkKi48.js +0 -211
- package/dist/createFormCollector-Wb8Rr-U2.cjs +0 -1
package/dist/{createConversationSession-DtaeA418.cjs → createConversationSession-DibXdxoC.cjs}
RENAMED
|
@@ -1 +1 @@
|
|
|
1
|
-
const d=require("./createFormCollector-
|
|
1
|
+
const d=require("./createFormCollector-DLwgDX24.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 _}});
|
package/dist/{createConversationSession-D9FesBQS.js → createConversationSession-XkiOGAUT.js}
RENAMED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { r as d } from "./createFormCollector-D4-yZh1i.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,207 @@
|
|
|
1
|
+
import { s as E } from "./AgoClient-rvTz2thR.js";
|
|
2
|
+
function T(i, r) {
|
|
3
|
+
const f = r ? r.storage ?? (typeof localStorage < "u" ? localStorage : void 0) : void 0;
|
|
4
|
+
let a = i;
|
|
5
|
+
if (r && f) try {
|
|
6
|
+
const u = f.getItem(r.key);
|
|
7
|
+
u != null && (a = JSON.parse(u));
|
|
8
|
+
} catch {
|
|
9
|
+
}
|
|
10
|
+
const l = /* @__PURE__ */ new Set(), g = () => l.forEach((u) => u(a));
|
|
11
|
+
function d() {
|
|
12
|
+
if (r && f) try {
|
|
13
|
+
f.setItem(r.key, JSON.stringify(a));
|
|
14
|
+
} catch {
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
return {
|
|
18
|
+
get: () => a,
|
|
19
|
+
set: (u) => {
|
|
20
|
+
a = u, d(), g();
|
|
21
|
+
},
|
|
22
|
+
subscribe: (u) => (l.add(u), () => {
|
|
23
|
+
l.delete(u);
|
|
24
|
+
})
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
var k = /^[a-zA-Z0-9_-]{1,40}$/, I = (i) => i == null || i === "";
|
|
28
|
+
function y(i, r) {
|
|
29
|
+
const f = (i.required ?? []).filter((a) => I(r[a]));
|
|
30
|
+
return {
|
|
31
|
+
missing: f,
|
|
32
|
+
complete: f.length === 0
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
function q(i) {
|
|
36
|
+
const { name: r, description: f, schema: a } = i;
|
|
37
|
+
if (!k.test(r)) throw new Error(`Invalid form collector name "${r}": must match ${k} (it becomes the update_/submit_ function names).`);
|
|
38
|
+
const l = typeof i.submit == "string" ? i.submit ? {
|
|
39
|
+
via: "client",
|
|
40
|
+
url: i.submit
|
|
41
|
+
} : !1 : i.submit ?? !1, g = a.properties ?? {}, d = (e) => {
|
|
42
|
+
const t = {};
|
|
43
|
+
for (const [o, s] of Object.entries(e)) {
|
|
44
|
+
const n = g[o];
|
|
45
|
+
if (n)
|
|
46
|
+
if (s == null) t[o] = s;
|
|
47
|
+
else if (n.type === "number" || n.type === "integer") {
|
|
48
|
+
const m = typeof s == "number" ? s : Number(s);
|
|
49
|
+
t[o] = Number.isNaN(m) ? s : m;
|
|
50
|
+
} else n.type === "boolean" ? t[o] = typeof s == "boolean" ? s : s === "true" ? !0 : s === "false" ? !1 : !!s : t[o] = s;
|
|
51
|
+
}
|
|
52
|
+
return t;
|
|
53
|
+
}, u = i.initialValues ?? {}, c = T({
|
|
54
|
+
values: u,
|
|
55
|
+
submitted: !1
|
|
56
|
+
}), v = (e) => {
|
|
57
|
+
const t = c.get(), o = {
|
|
58
|
+
...t,
|
|
59
|
+
values: {
|
|
60
|
+
...t.values,
|
|
61
|
+
...e
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
return c.set(o), o;
|
|
65
|
+
};
|
|
66
|
+
let b = null;
|
|
67
|
+
const C = async () => {
|
|
68
|
+
const { values: e } = c.get(), { complete: t, missing: o } = y(a, e);
|
|
69
|
+
if (!t) return {
|
|
70
|
+
ok: !1,
|
|
71
|
+
missing: o
|
|
72
|
+
};
|
|
73
|
+
if (!l) return {
|
|
74
|
+
ok: !1,
|
|
75
|
+
error: "No submit target configured for this form collector."
|
|
76
|
+
};
|
|
77
|
+
const s = e;
|
|
78
|
+
try {
|
|
79
|
+
let n;
|
|
80
|
+
if (l.via === "client") if ("handler" in l) n = await l.handler(s);
|
|
81
|
+
else {
|
|
82
|
+
const m = await fetch(l.url, {
|
|
83
|
+
method: "POST",
|
|
84
|
+
headers: { "Content-Type": "application/json" },
|
|
85
|
+
credentials: "include",
|
|
86
|
+
body: JSON.stringify(s)
|
|
87
|
+
});
|
|
88
|
+
if (!m.ok) return {
|
|
89
|
+
ok: !1,
|
|
90
|
+
error: `Submit failed: HTTP ${m.status}`
|
|
91
|
+
};
|
|
92
|
+
n = await m.json().catch(() => {
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
else {
|
|
96
|
+
if (!b) return {
|
|
97
|
+
ok: !1,
|
|
98
|
+
error: "Backend submit requires install(client) (or useFormCollector) first."
|
|
99
|
+
};
|
|
100
|
+
n = await b.submitFormCollector(l.destination, s);
|
|
101
|
+
}
|
|
102
|
+
return c.set({
|
|
103
|
+
...c.get(),
|
|
104
|
+
submitted: !0
|
|
105
|
+
}), {
|
|
106
|
+
ok: !0,
|
|
107
|
+
result: n
|
|
108
|
+
};
|
|
109
|
+
} catch (n) {
|
|
110
|
+
const m = n instanceof Error ? n.message : "Submit failed";
|
|
111
|
+
return E.error(`FormCollector "${r}" submit failed:`, n), {
|
|
112
|
+
ok: !1,
|
|
113
|
+
error: m
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
}, N = {
|
|
117
|
+
name: `update_${r}`,
|
|
118
|
+
description: `Fill or update fields of the "${r}" form. ${f} 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.`,
|
|
119
|
+
parameters: {
|
|
120
|
+
...a,
|
|
121
|
+
required: []
|
|
122
|
+
},
|
|
123
|
+
handler: (e) => {
|
|
124
|
+
const t = v(d(e)), { missing: o } = y(a, t.values);
|
|
125
|
+
return {
|
|
126
|
+
ok: !0,
|
|
127
|
+
values: t.values,
|
|
128
|
+
missing: o
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
}, h = [N];
|
|
132
|
+
l && h.push({
|
|
133
|
+
name: `submit_${r}`,
|
|
134
|
+
description: `Submit the completed "${r}" 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.`,
|
|
135
|
+
parameters: {
|
|
136
|
+
type: "object",
|
|
137
|
+
properties: {}
|
|
138
|
+
},
|
|
139
|
+
handler: () => C()
|
|
140
|
+
});
|
|
141
|
+
const _ = "client__", $ = l ? `submit_${r}` : null, x = (e) => {
|
|
142
|
+
const t = e.functionName ?? e.toolName;
|
|
143
|
+
if (t)
|
|
144
|
+
return t.startsWith(_) ? t.slice(8) : t;
|
|
145
|
+
}, w = (e) => {
|
|
146
|
+
let t = { ...u }, o = !1;
|
|
147
|
+
for (const s of e) {
|
|
148
|
+
const n = x(s);
|
|
149
|
+
n === N.name ? s.arguments && (t = {
|
|
150
|
+
...t,
|
|
151
|
+
...d(s.arguments)
|
|
152
|
+
}) : $ && n === $ && s.status?.toLowerCase() === "done" && (o = !0);
|
|
153
|
+
}
|
|
154
|
+
c.set({
|
|
155
|
+
values: t,
|
|
156
|
+
submitted: o
|
|
157
|
+
});
|
|
158
|
+
}, p = `form:${r}`, F = () => {
|
|
159
|
+
const { values: e, submitted: t } = c.get(), { missing: o } = y(a, e), s = l ? ` When nothing is missing and the user confirms, call submit_${r}.` : "";
|
|
160
|
+
return {
|
|
161
|
+
name: `Form: ${r}`,
|
|
162
|
+
description: `Form being filled conversationally. ${f} Call update_${r} with any fields the user provides; ask only for what is still missing.${s}`,
|
|
163
|
+
data: {
|
|
164
|
+
values: e,
|
|
165
|
+
missing: o,
|
|
166
|
+
submitted: t
|
|
167
|
+
}
|
|
168
|
+
};
|
|
169
|
+
}, S = (e) => {
|
|
170
|
+
w((e.messages ?? []).flatMap((t) => t.toolCalls ?? []));
|
|
171
|
+
};
|
|
172
|
+
return {
|
|
173
|
+
name: r,
|
|
174
|
+
store: c,
|
|
175
|
+
functions: h,
|
|
176
|
+
contextKey: p,
|
|
177
|
+
contextProvider: F,
|
|
178
|
+
install: (e) => {
|
|
179
|
+
b = e;
|
|
180
|
+
for (const o of h) e.register(o);
|
|
181
|
+
e.addDynamicContext(p, F);
|
|
182
|
+
const t = c.subscribe(() => e.notifyContextChanged());
|
|
183
|
+
return e.on("conversation:loaded", S), () => {
|
|
184
|
+
t();
|
|
185
|
+
for (const o of h) e.unregisterFunction(o.name);
|
|
186
|
+
e.removeDynamicContext(p), e.off("conversation:loaded", S), b === e && (b = null);
|
|
187
|
+
};
|
|
188
|
+
},
|
|
189
|
+
hydrate: w,
|
|
190
|
+
submit: C,
|
|
191
|
+
getValues: () => c.get().values,
|
|
192
|
+
setValues: (e) => {
|
|
193
|
+
v(d(e));
|
|
194
|
+
},
|
|
195
|
+
reset: () => {
|
|
196
|
+
c.set({
|
|
197
|
+
values: u,
|
|
198
|
+
submitted: !1
|
|
199
|
+
});
|
|
200
|
+
}
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
export {
|
|
204
|
+
y as n,
|
|
205
|
+
T as r,
|
|
206
|
+
q as t
|
|
207
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const E=require("./AgoClient-D4EL6nva.cjs");function k(i,s){const f=s?s.storage??(typeof localStorage<"u"?localStorage:void 0):void 0;let a=i;if(s&&f)try{const u=f.getItem(s.key);u!=null&&(a=JSON.parse(u))}catch{}const l=new Set,y=()=>l.forEach(u=>u(a));function d(){if(s&&f)try{f.setItem(s.key,JSON.stringify(a))}catch{}}return{get:()=>a,set:u=>{a=u,d(),y()},subscribe:u=>(l.add(u),()=>{l.delete(u)})}}var _=/^[a-zA-Z0-9_-]{1,40}$/,T=i=>i==null||i==="";function h(i,s){const f=(i.required??[]).filter(a=>T(s[a]));return{missing:f,complete:f.length===0}}function j(i){const{name:s,description:f,schema:a}=i;if(!_.test(s))throw new Error(`Invalid form collector name "${s}": must match ${_} (it becomes the update_/submit_ function names).`);const l=typeof i.submit=="string"?i.submit?{via:"client",url:i.submit}:!1:i.submit??!1,y=a.properties??{},d=e=>{const t={};for(const[n,r]of Object.entries(e)){const o=y[n];if(o)if(r==null)t[n]=r;else if(o.type==="number"||o.type==="integer"){const m=typeof r=="number"?r:Number(r);t[n]=Number.isNaN(m)?r:m}else o.type==="boolean"?t[n]=typeof r=="boolean"?r:r==="true"?!0:r==="false"?!1:!!r:t[n]=r}return t},u=i.initialValues??{},c=k({values:u,submitted:!1}),v=e=>{const t=c.get(),n={...t,values:{...t.values,...e}};return c.set(n),n};let b=null;const C=async()=>{const{values:e}=c.get(),{complete:t,missing:n}=h(a,e);if(!t)return{ok:!1,missing:n};if(!l)return{ok:!1,error:"No submit target configured for this form collector."};const r=e;try{let o;if(l.via==="client")if("handler"in l)o=await l.handler(r);else{const m=await fetch(l.url,{method:"POST",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify(r)});if(!m.ok)return{ok:!1,error:`Submit failed: HTTP ${m.status}`};o=await m.json().catch(()=>{})}else{if(!b)return{ok:!1,error:"Backend submit requires install(client) (or useFormCollector) first."};o=await b.submitFormCollector(l.destination,r)}return c.set({...c.get(),submitted:!0}),{ok:!0,result:o}}catch(o){const m=o instanceof Error?o.message:"Submit failed";return E.logger.error(`FormCollector "${s}" submit failed:`,o),{ok:!1,error:m}}},N={name:`update_${s}`,description:`Fill or update fields of the "${s}" form. ${f} 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:{...a,required:[]},handler:e=>{const t=v(d(e)),{missing:n}=h(a,t.values);return{ok:!0,values:t.values,missing:n}}},g=[N];l&&g.push({name:`submit_${s}`,description:`Submit the completed "${s}" 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:()=>C()});const O="client__",$=l?`submit_${s}`:null,P=e=>{const t=e.functionName??e.toolName;if(t)return t.startsWith(O)?t.slice(8):t},F=e=>{let t={...u},n=!1;for(const r of e){const o=P(r);o===N.name?r.arguments&&(t={...t,...d(r.arguments)}):$&&o===$&&r.status?.toLowerCase()==="done"&&(n=!0)}c.set({values:t,submitted:n})},p=`form:${s}`,S=()=>{const{values:e,submitted:t}=c.get(),{missing:n}=h(a,e),r=l?` When nothing is missing and the user confirms, call submit_${s}.`:"";return{name:`Form: ${s}`,description:`Form being filled conversationally. ${f} Call update_${s} with any fields the user provides; ask only for what is still missing.${r}`,data:{values:e,missing:n,submitted:t}}},w=e=>{F((e.messages??[]).flatMap(t=>t.toolCalls??[]))};return{name:s,store:c,functions:g,contextKey:p,contextProvider:S,install:e=>{b=e;for(const n of g)e.register(n);e.addDynamicContext(p,S);const t=c.subscribe(()=>e.notifyContextChanged());return e.on("conversation:loaded",w),()=>{t();for(const n of g)e.unregisterFunction(n.name);e.removeDynamicContext(p),e.off("conversation:loaded",w),b===e&&(b=null)}},hydrate:F,submit:C,getValues:()=>c.get().values,setValues:e=>{v(d(e))},reset:()=>{c.set({values:u,submitted:!1})}}}Object.defineProperty(exports,"createFormCollector",{enumerable:!0,get:function(){return j}});Object.defineProperty(exports,"createStore",{enumerable:!0,get:function(){return k}});Object.defineProperty(exports,"deriveFormStatus",{enumerable:!0,get:function(){return h}});
|
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("./AgoClient-D4EL6nva.cjs"),
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("./AgoClient-D4EL6nva.cjs"),m=require("./createFormCollector-DLwgDX24.cjs"),A=require("./createConversationSession-DibXdxoC.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
|
@@ -740,6 +740,14 @@ export declare function createStore<T>(initial: T, persist?: PersistOptions): St
|
|
|
740
740
|
*/
|
|
741
741
|
export declare function defineFunction(definition: ClientFunctionDefinition): ClientFunctionDefinition;
|
|
742
742
|
|
|
743
|
+
/**
|
|
744
|
+
* Compute which required fields are still empty and whether the form is complete.
|
|
745
|
+
* Pure — the single home for the "required + non-empty" rule, shared by the update
|
|
746
|
+
* handler, submit, the dynamic context, and the React hook. Derived on read so the
|
|
747
|
+
* store only ever holds canonical state ({@link FormCollectorState}).
|
|
748
|
+
*/
|
|
749
|
+
export declare function deriveFormStatus(schema: FormCollectorSchema, values: Partial<Record<string, unknown>>): FormCollectorStatus;
|
|
750
|
+
|
|
743
751
|
/**
|
|
744
752
|
* A function that returns a fresh context entry on demand.
|
|
745
753
|
* Evaluated every time a message is sent — use it to pull data from stores,
|
|
@@ -805,16 +813,20 @@ export declare interface FormCollector<V = Record<string, unknown>> {
|
|
|
805
813
|
*/
|
|
806
814
|
export declare type FormCollectorSchema = ClientFunctionSchema["parameters"];
|
|
807
815
|
|
|
808
|
-
/**
|
|
816
|
+
/** Canonical, source-of-truth state held in the collector's store. */
|
|
809
817
|
export declare interface FormCollectorState<V = Record<string, unknown>> {
|
|
810
818
|
/** Field values collected so far. */
|
|
811
819
|
values: Partial<V>;
|
|
820
|
+
/** True once a submit succeeded. */
|
|
821
|
+
submitted: boolean;
|
|
822
|
+
}
|
|
823
|
+
|
|
824
|
+
/** Completeness status derived from values + schema — computed on read, never stored. */
|
|
825
|
+
export declare interface FormCollectorStatus {
|
|
812
826
|
/** Required field names still empty. */
|
|
813
827
|
missing: string[];
|
|
814
828
|
/** True when no required field is missing. */
|
|
815
829
|
complete: boolean;
|
|
816
|
-
/** True once a submit succeeded. */
|
|
817
|
-
submitted: boolean;
|
|
818
830
|
}
|
|
819
831
|
|
|
820
832
|
export declare interface FormField {
|
package/dist/index.d.ts
CHANGED
|
@@ -740,6 +740,14 @@ export declare function createStore<T>(initial: T, persist?: PersistOptions): St
|
|
|
740
740
|
*/
|
|
741
741
|
export declare function defineFunction(definition: ClientFunctionDefinition): ClientFunctionDefinition;
|
|
742
742
|
|
|
743
|
+
/**
|
|
744
|
+
* Compute which required fields are still empty and whether the form is complete.
|
|
745
|
+
* Pure — the single home for the "required + non-empty" rule, shared by the update
|
|
746
|
+
* handler, submit, the dynamic context, and the React hook. Derived on read so the
|
|
747
|
+
* store only ever holds canonical state ({@link FormCollectorState}).
|
|
748
|
+
*/
|
|
749
|
+
export declare function deriveFormStatus(schema: FormCollectorSchema, values: Partial<Record<string, unknown>>): FormCollectorStatus;
|
|
750
|
+
|
|
743
751
|
/**
|
|
744
752
|
* A function that returns a fresh context entry on demand.
|
|
745
753
|
* Evaluated every time a message is sent — use it to pull data from stores,
|
|
@@ -805,16 +813,20 @@ export declare interface FormCollector<V = Record<string, unknown>> {
|
|
|
805
813
|
*/
|
|
806
814
|
export declare type FormCollectorSchema = ClientFunctionSchema["parameters"];
|
|
807
815
|
|
|
808
|
-
/**
|
|
816
|
+
/** Canonical, source-of-truth state held in the collector's store. */
|
|
809
817
|
export declare interface FormCollectorState<V = Record<string, unknown>> {
|
|
810
818
|
/** Field values collected so far. */
|
|
811
819
|
values: Partial<V>;
|
|
820
|
+
/** True once a submit succeeded. */
|
|
821
|
+
submitted: boolean;
|
|
822
|
+
}
|
|
823
|
+
|
|
824
|
+
/** Completeness status derived from values + schema — computed on read, never stored. */
|
|
825
|
+
export declare interface FormCollectorStatus {
|
|
812
826
|
/** Required field names still empty. */
|
|
813
827
|
missing: string[];
|
|
814
828
|
/** True when no required field is missing. */
|
|
815
829
|
complete: boolean;
|
|
816
|
-
/** True once a submit succeeded. */
|
|
817
|
-
submitted: boolean;
|
|
818
830
|
}
|
|
819
831
|
|
|
820
832
|
export declare interface FormField {
|
package/dist/index.js
CHANGED
|
@@ -1,34 +1,34 @@
|
|
|
1
|
-
import { a as w, c as h, d as A, f as y, i as C, l as E, n as
|
|
2
|
-
import { n as T,
|
|
3
|
-
import { t as
|
|
4
|
-
import { t as
|
|
5
|
-
import { a as
|
|
6
|
-
function
|
|
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-D4-yZh1i.js";
|
|
3
|
+
import { t as O } from "./createConversationSession-XkiOGAUT.js";
|
|
4
|
+
import { t as x } from "./createMockClient-DwdxNwEn.js";
|
|
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
|
+
function W(e) {
|
|
7
7
|
return e;
|
|
8
8
|
}
|
|
9
|
-
function
|
|
9
|
+
function X(e, t) {
|
|
10
10
|
return e.on("message:complete", t), () => e.off("message:complete", t);
|
|
11
11
|
}
|
|
12
|
-
function
|
|
12
|
+
function Y(e, t) {
|
|
13
13
|
return e.on("message:chunk", t), () => e.off("message:chunk", t);
|
|
14
14
|
}
|
|
15
|
-
function
|
|
15
|
+
function Z(e, t) {
|
|
16
16
|
return e.on("message:start", t), () => e.off("message:start", t);
|
|
17
17
|
}
|
|
18
|
-
function
|
|
18
|
+
function _(e, t) {
|
|
19
19
|
return e.on("message:error", t), () => e.off("message:error", t);
|
|
20
20
|
}
|
|
21
|
-
function
|
|
21
|
+
function ee(e, t) {
|
|
22
22
|
return e.on("toolCall:received", t), () => e.off("toolCall:received", t);
|
|
23
23
|
}
|
|
24
|
-
function
|
|
24
|
+
function te(e, t) {
|
|
25
25
|
return e.on("function:invoke", t), () => e.off("function:invoke", t);
|
|
26
26
|
}
|
|
27
|
-
async function*
|
|
28
|
-
const
|
|
29
|
-
let r = null,
|
|
27
|
+
async function* oe(e, t, g) {
|
|
28
|
+
const a = [];
|
|
29
|
+
let r = null, n = !1;
|
|
30
30
|
const u = (s) => {
|
|
31
|
-
|
|
31
|
+
a.push(s), r?.();
|
|
32
32
|
}, f = (s) => u({
|
|
33
33
|
type: "start",
|
|
34
34
|
data: s
|
|
@@ -39,21 +39,21 @@ async function* te(e, t, g) {
|
|
|
39
39
|
u({
|
|
40
40
|
type: "complete",
|
|
41
41
|
data: s
|
|
42
|
-
}),
|
|
42
|
+
}), n = !0, r?.();
|
|
43
43
|
}, m = (s) => {
|
|
44
44
|
u({
|
|
45
45
|
type: "error",
|
|
46
46
|
data: s
|
|
47
|
-
}),
|
|
47
|
+
}), n = !0, r?.();
|
|
48
48
|
}, l = (s) => u({
|
|
49
49
|
type: "toolCall",
|
|
50
50
|
data: s
|
|
51
51
|
});
|
|
52
52
|
e.on("message:start", f), e.on("message:chunk", o), e.on("message:complete", i), e.on("message:error", m), e.on("toolCall:received", l), e.sendMessage(t, g).catch(() => {
|
|
53
|
-
|
|
53
|
+
n = !0, r?.();
|
|
54
54
|
});
|
|
55
55
|
try {
|
|
56
|
-
for (; !
|
|
56
|
+
for (; !n || a.length > 0; ) a.length > 0 ? yield a.shift() : (await new Promise((s) => {
|
|
57
57
|
r = s;
|
|
58
58
|
}), r = null);
|
|
59
59
|
} finally {
|
|
@@ -61,38 +61,38 @@ async function* te(e, t, g) {
|
|
|
61
61
|
}
|
|
62
62
|
}
|
|
63
63
|
function c(e) {
|
|
64
|
-
let t, g,
|
|
64
|
+
let t, g, a, r, n, u;
|
|
65
65
|
if (typeof window < "u" && window.AGO) {
|
|
66
66
|
const o = window.AGO;
|
|
67
|
-
t = o.basepath, g = o.widgetId,
|
|
67
|
+
t = o.basepath, g = o.widgetId, a = o.agent || o.defaultAgent, r = o.permission, n = o.email, u = o.jwt;
|
|
68
68
|
}
|
|
69
69
|
if (typeof document < "u") {
|
|
70
70
|
const o = (i) => document.querySelector(`meta[name="${i}"]`)?.getAttribute("content") || void 0;
|
|
71
|
-
t = t || o("ago-base-url"), g = g || o("ago-widget-id"),
|
|
71
|
+
t = t || o("ago-base-url"), g = g || o("ago-widget-id"), a = a || o("ago-agent") || o("ago-agent-id"), r = r || o("ago-permission"), n = n || o("ago-user-email");
|
|
72
72
|
}
|
|
73
73
|
if (typeof document < "u") {
|
|
74
74
|
const o = [document.body, ...Array.from(document.querySelectorAll("script[data-ago-base-url]"))].filter(Boolean);
|
|
75
75
|
for (const i of o)
|
|
76
|
-
i && (t = t || i.getAttribute("data-ago-base-url") || void 0, g = g || i.getAttribute("data-ago-widget-id") || void 0,
|
|
76
|
+
i && (t = t || i.getAttribute("data-ago-base-url") || void 0, g = g || i.getAttribute("data-ago-widget-id") || void 0, a = a || i.getAttribute("data-ago-agent") || i.getAttribute("data-ago-agent-id") || void 0, r = r || i.getAttribute("data-ago-permission") || void 0, n = n || i.getAttribute("data-ago-user-email") || void 0);
|
|
77
77
|
}
|
|
78
|
-
t = e?.baseUrl || t, g = e?.widgetId || g,
|
|
78
|
+
t = e?.baseUrl || t, g = e?.widgetId || g, a = e?.agent || e?.defaultAgentId || a, r = e?.permission || r, n = e?.userEmail || n, u = e?.userJwt || u;
|
|
79
79
|
const f = e?.debug;
|
|
80
80
|
return t ? {
|
|
81
81
|
baseUrl: t,
|
|
82
82
|
widgetId: g,
|
|
83
|
-
agent:
|
|
83
|
+
agent: a,
|
|
84
84
|
permission: r,
|
|
85
|
-
userEmail:
|
|
85
|
+
userEmail: n,
|
|
86
86
|
userJwt: u,
|
|
87
87
|
debug: f
|
|
88
88
|
} : null;
|
|
89
89
|
}
|
|
90
|
-
function
|
|
90
|
+
function re(e) {
|
|
91
91
|
const t = c(e);
|
|
92
92
|
if (!t) throw new Error('createAgo(): could not detect AGO configuration. Set window.AGO, add <meta name="ago-base-url">, or pass { baseUrl } explicitly.');
|
|
93
93
|
return new d(t);
|
|
94
94
|
}
|
|
95
|
-
function
|
|
95
|
+
function ae(e, t) {
|
|
96
96
|
return {
|
|
97
97
|
...e,
|
|
98
98
|
handler: t
|
|
@@ -106,37 +106,38 @@ export {
|
|
|
106
106
|
A as AgoNetworkError,
|
|
107
107
|
y as AgoStreamError,
|
|
108
108
|
w as ClientContextRegistry,
|
|
109
|
-
|
|
110
|
-
|
|
109
|
+
S as EventEmitter,
|
|
110
|
+
b as FunctionRegistry,
|
|
111
111
|
v as SSEHandler,
|
|
112
112
|
c as autoDetectConfig,
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
113
|
+
Q as copyToClipboard,
|
|
114
|
+
re as createAgo,
|
|
115
|
+
O as createConversationSession,
|
|
116
|
+
U as createFormCollector,
|
|
117
|
+
oe as createMessageStream,
|
|
118
|
+
x as createMockClient,
|
|
119
|
+
I as createStore,
|
|
120
|
+
W as defineFunction,
|
|
121
|
+
T as deriveFormStatus,
|
|
122
|
+
z as getLocalStorage,
|
|
123
|
+
R as getUserLocation,
|
|
124
|
+
N as highlightElement,
|
|
124
125
|
C as isStreamNetworkError,
|
|
125
126
|
k as logger,
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
127
|
+
te as onFunctionInvoke,
|
|
128
|
+
X as onMessage,
|
|
129
|
+
Y as onMessageChunk,
|
|
130
|
+
_ as onMessageError,
|
|
131
|
+
Z as onMessageStart,
|
|
132
|
+
ee as onToolCall,
|
|
133
|
+
P as openUrl,
|
|
134
|
+
K as scrollToElement,
|
|
135
|
+
D as setLocalStorage,
|
|
136
|
+
j as setTheme,
|
|
137
|
+
V as showConfirmDialog,
|
|
138
|
+
H as showNotification,
|
|
139
|
+
J as showToast,
|
|
140
|
+
$ as submitForm,
|
|
141
|
+
B as trackEvent,
|
|
142
|
+
ae as withHandler
|
|
142
143
|
};
|