@useago/sdk 1.5.2 → 1.5.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.
Files changed (45) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/README.md +10 -0
  3. package/dist/AgoClient-BW0YZsis.js +1681 -0
  4. package/dist/AgoClient-Ba3ICq4K.cjs +8 -0
  5. package/dist/angular.cjs +1 -1
  6. package/dist/angular.d.cts +352 -0
  7. package/dist/angular.d.ts +352 -0
  8. package/dist/angular.js +1 -1
  9. package/dist/{createConversationSession-DPrrr70o.js → createConversationSession-BjsgjL-v.js} +3 -3
  10. package/dist/createConversationSession-okoz3teC.cjs +1 -0
  11. package/dist/createFormCollector-BWIh1pMl.cjs +1 -0
  12. package/dist/createFormCollector-Bay2UpRv.js +279 -0
  13. package/dist/createMockClient-DcuNlufr.js +97 -0
  14. package/dist/createMockClient-Dw-cyISN.cjs +1 -0
  15. package/dist/devtools.d.cts +352 -0
  16. package/dist/devtools.d.ts +352 -0
  17. package/dist/index.cjs +1 -1
  18. package/dist/index.d.cts +564 -0
  19. package/dist/index.d.ts +564 -0
  20. package/dist/index.js +97 -90
  21. package/dist/react.cjs +3 -3
  22. package/dist/react.d.cts +430 -0
  23. package/dist/react.d.ts +430 -0
  24. package/dist/react.js +600 -443
  25. package/dist/testing.cjs +1 -1
  26. package/dist/testing.d.cts +352 -0
  27. package/dist/testing.d.ts +352 -0
  28. package/dist/testing.js +1 -1
  29. package/dist/vue.cjs +1 -1
  30. package/dist/vue.d.cts +373 -0
  31. package/dist/vue.d.ts +373 -0
  32. package/dist/vue.js +133 -110
  33. package/dist/widget.cjs +1 -1
  34. package/dist/widget.d.cts +349 -0
  35. package/dist/widget.d.ts +349 -0
  36. package/dist/widget.js +7 -7
  37. package/llms-full.txt +29 -0
  38. package/package.json +1 -1
  39. package/dist/AgoClient-5VGybmvz.cjs +0 -8
  40. package/dist/AgoClient-DXrH2AMi.js +0 -964
  41. package/dist/createConversationSession-0WTqcCLK.cjs +0 -1
  42. package/dist/createFormCollector-1GKKwQV_.cjs +0 -1
  43. package/dist/createFormCollector-DYh90kiG.js +0 -305
  44. package/dist/createMockClient-C-wrjb2C.cjs +0 -1
  45. package/dist/createMockClient-we-XoPom.js +0 -79
@@ -0,0 +1,279 @@
1
+ import { h as R, v as w } from "./AgoClient-BW0YZsis.js";
2
+ var j = /^[a-zA-Z0-9_-]{1,40}$/, V = (s) => s == null || s === "";
3
+ function S(s, e) {
4
+ if ("anyOf" in s) return s.anyOf.some((c) => S(c, e));
5
+ if ("allOf" in s) return s.allOf.every((c) => S(c, e));
6
+ const l = e[s.property];
7
+ if (V(l)) return !1;
8
+ if (Array.isArray(s.value)) return s.value.some((c) => String(l) === String(c));
9
+ if (!s.op) return String(l) === String(s.value);
10
+ const i = Number(l), a = Number(s.value);
11
+ if (Number.isNaN(i) || Number.isNaN(a)) return !1;
12
+ switch (s.op) {
13
+ case ">=":
14
+ return i >= a;
15
+ case "<=":
16
+ return i <= a;
17
+ case ">":
18
+ return i > a;
19
+ case "<":
20
+ return i < a;
21
+ default:
22
+ return w.warn(`Unknown requiredWhen op "${s.op}"; treating as not required.`), !1;
23
+ }
24
+ }
25
+ function p(s, e) {
26
+ const l = s.properties ?? {}, i = /* @__PURE__ */ new Set();
27
+ for (const c of s.required ?? []) {
28
+ const d = l[c]?.requiredWhen;
29
+ (!d || S(d, e)) && i.add(c);
30
+ }
31
+ for (const [c, d] of Object.entries(l)) d.requiredWhen && S(d.requiredWhen, e) && i.add(c);
32
+ const a = [...i].filter((c) => V(e[c]));
33
+ return {
34
+ missing: a,
35
+ complete: a.length === 0
36
+ };
37
+ }
38
+ function B(s) {
39
+ const e = {};
40
+ for (const [l, i] of Object.entries(s.properties ?? {})) e[l] = {
41
+ type: i.type,
42
+ ...i.description != null && { description: i.description },
43
+ ...i.enum && { enum: i.enum },
44
+ ...i.default !== void 0 && { default: i.default }
45
+ };
46
+ return {
47
+ type: "object",
48
+ properties: e,
49
+ required: []
50
+ };
51
+ }
52
+ function L(s) {
53
+ const { name: e, description: l, schema: i } = s;
54
+ if (!j.test(e)) throw new Error(`Invalid form collector name "${e}": must match ${j} (it becomes the update_/submit_ function names).`);
55
+ const a = typeof s.submit == "string" ? s.submit ? {
56
+ via: "client",
57
+ url: s.submit
58
+ } : !1 : s.submit ?? !1;
59
+ s.autoSubmit === !0 && !a && w.warn(`FormCollector "${e}": autoSubmit is ignored because no submit target is configured.`);
60
+ const c = (s.autoSubmit ?? !0) && !!a, d = i.properties ?? {}, $ = (t) => {
61
+ const r = {};
62
+ for (const [o, n] of Object.entries(t)) {
63
+ const u = d[o];
64
+ if (u)
65
+ if (n == null) r[o] = n;
66
+ else if (u.type === "number" || u.type === "integer") {
67
+ const f = typeof n == "number" ? n : Number(n);
68
+ r[o] = Number.isNaN(f) ? n : f;
69
+ } else u.type === "boolean" ? r[o] = typeof n == "boolean" ? n : n === "true" ? !0 : n === "false" ? !1 : !!n : r[o] = n;
70
+ }
71
+ return r;
72
+ }, C = s.initialValues ?? {}, m = R({
73
+ values: C,
74
+ submitted: !1
75
+ }), F = (t) => {
76
+ const r = m.get(), o = {
77
+ ...r,
78
+ values: {
79
+ ...r.values,
80
+ ...t
81
+ }
82
+ };
83
+ return m.set(o), o;
84
+ };
85
+ let b = null;
86
+ const k = (t, r) => {
87
+ b?.emitFormEvent("form:error", {
88
+ name: e,
89
+ values: t,
90
+ error: r
91
+ });
92
+ };
93
+ let h = null;
94
+ const A = async () => {
95
+ const { values: t } = m.get(), { complete: r, missing: o } = p(i, t);
96
+ if (!r) return {
97
+ ok: !1,
98
+ missing: o
99
+ };
100
+ if (!a) return {
101
+ ok: !1,
102
+ error: "No submit target configured for this form collector."
103
+ };
104
+ const n = t;
105
+ try {
106
+ let u;
107
+ if (a.via === "client") if ("handler" in a) u = await a.handler(n);
108
+ else {
109
+ const f = await fetch(a.url, {
110
+ method: "POST",
111
+ headers: { "Content-Type": "application/json" },
112
+ credentials: "include",
113
+ body: JSON.stringify(n)
114
+ });
115
+ if (!f.ok) {
116
+ const W = `Submit failed: HTTP ${f.status}`;
117
+ return k(n, W), {
118
+ ok: !1,
119
+ error: W
120
+ };
121
+ }
122
+ u = await f.json().catch(() => {
123
+ });
124
+ }
125
+ else {
126
+ if (!b) return {
127
+ ok: !1,
128
+ error: "Backend submit requires install(client) (or useFormCollector) first."
129
+ };
130
+ u = await b.submitFormCollector(e, n);
131
+ }
132
+ return m.set({
133
+ ...m.get(),
134
+ submitted: !0,
135
+ submitResult: u
136
+ }), b?.emitFormEvent("form:submitted", {
137
+ name: e,
138
+ values: n,
139
+ result: u
140
+ }), {
141
+ ok: !0,
142
+ result: u
143
+ };
144
+ } catch (u) {
145
+ const f = u instanceof Error ? u.message : "Submit failed";
146
+ return w.error(`FormCollector "${e}" submit failed:`, u), k(n, f), {
147
+ ok: !1,
148
+ error: f
149
+ };
150
+ }
151
+ }, N = () => h || (h = (async () => {
152
+ try {
153
+ return await A();
154
+ } finally {
155
+ h = null;
156
+ }
157
+ })(), h), q = async () => {
158
+ if (!c || !a) return null;
159
+ const { values: t, submitted: r } = m.get();
160
+ return r || !p(i, t).complete ? null : N();
161
+ }, x = {
162
+ name: `update_${e}`,
163
+ 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.`,
164
+ parameters: B(i),
165
+ handler: async (t) => {
166
+ const r = F($(t)), { missing: o } = p(i, r.values), n = await q();
167
+ return n ? n.ok ? {
168
+ ok: !0,
169
+ values: r.values,
170
+ missing: o,
171
+ submitted: !0
172
+ } : {
173
+ ok: !0,
174
+ values: r.values,
175
+ missing: o,
176
+ submitted: !1,
177
+ submitError: n.error
178
+ } : {
179
+ ok: !0,
180
+ values: r.values,
181
+ missing: o
182
+ };
183
+ }
184
+ }, y = [x];
185
+ a && !c && y.push({
186
+ name: `submit_${e}`,
187
+ 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.`,
188
+ parameters: {
189
+ type: "object",
190
+ properties: {}
191
+ },
192
+ handler: () => N()
193
+ });
194
+ const I = "client__", _ = a ? `submit_${e}` : null, D = (t) => {
195
+ const r = t.functionName ?? t.toolName;
196
+ if (r)
197
+ return r.startsWith(I) ? r.slice(8) : r;
198
+ }, O = (t) => {
199
+ let r = { ...C }, o = !1;
200
+ for (const n of t) {
201
+ const u = D(n);
202
+ u === x.name ? n.arguments && (r = {
203
+ ...r,
204
+ ...$(n.arguments)
205
+ }) : _ && u === _ && n.status?.toLowerCase() === "done" && (o = !0);
206
+ }
207
+ m.set({
208
+ values: r,
209
+ submitted: o
210
+ });
211
+ }, g = `form:${e}`, v = `${g}:definition`, T = () => ({
212
+ name: `Form definition: ${e}`,
213
+ description: `${l} Some fields are conditionally required; the requiredWhen field in the schema tells you when each becomes required. The form schema is the following: ${JSON.stringify(i)}.`,
214
+ stable: !0
215
+ }), E = () => {
216
+ const { values: t, submitted: r } = m.get(), { missing: o, complete: n } = p(i, t), u = a ? c ? " The form is submitted automatically as soon as every required field is filled, so there is no submit function to call." : ` When nothing is missing and the user confirms, call submit_${e}.` : "", f = r ? `The "${e}" form has been submitted.` : `You are currently collecting information from the user to fill the "${e}" form.`;
217
+ return {
218
+ name: `Form: ${e}`,
219
+ description: `${f} The form's schema and field requirements are in the "${v}" client context. Call update_${e} with any fields the user provides; ask only for what is still missing.${u}`,
220
+ data: {
221
+ values: t,
222
+ missing: o,
223
+ complete: n,
224
+ submitted: r
225
+ }
226
+ };
227
+ }, P = (t) => {
228
+ O((t.messages ?? []).flatMap((r) => r.toolCalls ?? []));
229
+ };
230
+ return {
231
+ name: e,
232
+ store: m,
233
+ functions: y,
234
+ contextKey: g,
235
+ contextProvider: E,
236
+ definitionContextKey: v,
237
+ definitionContextProvider: T,
238
+ install: (t) => {
239
+ b = t;
240
+ for (const o of y) t.register(o);
241
+ t.addDynamicContext(v, T), t.addDynamicContext(g, E);
242
+ const r = m.subscribe(() => t.notifyContextChanged());
243
+ return t.on("conversation:loaded", P), () => {
244
+ r();
245
+ for (const o of y) t.unregisterFunction(o.name);
246
+ t.removeDynamicContext(g), t.removeDynamicContext(v), t.off("conversation:loaded", P), b === t && (b = null);
247
+ };
248
+ },
249
+ hydrate: O,
250
+ submit: N,
251
+ getValues: () => m.get().values,
252
+ setValues: (t) => {
253
+ F($(t)), q();
254
+ },
255
+ reset: () => {
256
+ m.set({
257
+ values: C,
258
+ submitted: !1
259
+ });
260
+ },
261
+ getStatus: () => p(i, m.get().values)
262
+ };
263
+ }
264
+ async function K(s, e) {
265
+ const l = await s.getFormCollector(e.name);
266
+ return L({
267
+ name: l.name,
268
+ description: e.description ?? l.description,
269
+ schema: e.schema ?? l.schema,
270
+ submit: e.submit ?? l.submit,
271
+ initialValues: e.initialValues,
272
+ autoSubmit: e.autoSubmit ?? l.autoSubmit
273
+ });
274
+ }
275
+ export {
276
+ p as n,
277
+ K as r,
278
+ L as t
279
+ };
@@ -0,0 +1,97 @@
1
+ function v(g = {}) {
2
+ const { overrides: u = {} } = g, a = {
3
+ id: "mock-msg-1",
4
+ conversationId: "mock-conv-1",
5
+ content: "Mock response",
6
+ role: "assistant",
7
+ status: "DONE",
8
+ createdAt: /* @__PURE__ */ new Date()
9
+ }, l = {
10
+ id: "mock-conv-1",
11
+ title: "Mock Conversation",
12
+ lastMessageDate: /* @__PURE__ */ new Date()
13
+ }, o = /* @__PURE__ */ new Map(), c = [], m = {
14
+ sendMessage: async () => a,
15
+ continueMessage: async () => a,
16
+ resumePendingClientFunctions: async () => null,
17
+ registerResumeGate: () => () => {
18
+ },
19
+ getConversations: async () => [l],
20
+ getConversation: async () => l,
21
+ getMessages: async () => [a],
22
+ submitToolCallForm: async () => ({ status: "completed" }),
23
+ confirmToolCall: async () => {
24
+ },
25
+ rejectToolCall: async () => {
26
+ },
27
+ submitFeedback: async () => {
28
+ },
29
+ registerFunction: () => {
30
+ },
31
+ unregisterFunction: () => !0,
32
+ getRegisteredFunctions: () => [],
33
+ executeClientFunction: async () => {
34
+ },
35
+ getContextSnapshot: () => null,
36
+ notifyContextChanged: () => {
37
+ },
38
+ setContext: () => {
39
+ },
40
+ removeContext: () => !0,
41
+ addDynamicContext: () => {
42
+ },
43
+ removeDynamicContext: () => !0,
44
+ registerNavigationFunction: () => {
45
+ },
46
+ unregisterNavigationFunction: () => {
47
+ },
48
+ getConfiguredAgent: () => {
49
+ },
50
+ getHttp: () => ({
51
+ get: async () => ({}),
52
+ post: async () => ({})
53
+ }),
54
+ emitProactiveEvent: (e, t) => {
55
+ const n = o.get(e);
56
+ n && [...n].forEach((s) => s(t));
57
+ },
58
+ on: (e, t) => {
59
+ o.has(e) || o.set(e, /* @__PURE__ */ new Set()), o.get(e).add(t);
60
+ },
61
+ off: (e, t) => {
62
+ o.get(e)?.delete(t);
63
+ },
64
+ once: (e, t) => {
65
+ const n = (...s) => {
66
+ o.get(e)?.delete(n), t(...s);
67
+ };
68
+ o.has(e) || o.set(e, /* @__PURE__ */ new Set()), o.get(e).add(n);
69
+ },
70
+ waitFor: (e, t) => new Promise((n, s) => {
71
+ let r;
72
+ const d = (f) => {
73
+ r && clearTimeout(r), o.get(e)?.delete(d), n(f);
74
+ };
75
+ o.has(e) || o.set(e, /* @__PURE__ */ new Set()), o.get(e).add(d), t?.timeout && (r = setTimeout(() => {
76
+ o.get(e)?.delete(d), s(/* @__PURE__ */ new Error(`waitFor("${e}") timed out after ${t.timeout}ms`));
77
+ }, t.timeout));
78
+ }),
79
+ updateConfig: () => {
80
+ },
81
+ destroy: () => {
82
+ o.clear();
83
+ },
84
+ ...u
85
+ }, i = {};
86
+ for (const [e, t] of Object.entries(m)) i[e] = (...n) => (c.push({
87
+ method: e,
88
+ args: n
89
+ }), t(...n));
90
+ return i.proactive = null, i.__calls = c, i.__callsFor = (e) => c.filter((t) => t.method === e), i.__emitEvent = (e, t) => {
91
+ const n = o.get(e);
92
+ n && [...n].forEach((s) => s(t));
93
+ }, i;
94
+ }
95
+ export {
96
+ v as t
97
+ };
@@ -0,0 +1 @@
1
+ function C(u={}){const{overrides:g={}}=u,a={id:"mock-msg-1",conversationId:"mock-conv-1",content:"Mock response",role:"assistant",status:"DONE",createdAt:new Date},l={id:"mock-conv-1",title:"Mock Conversation",lastMessageDate:new Date},o=new Map,r=[],m={sendMessage:async()=>a,continueMessage:async()=>a,resumePendingClientFunctions:async()=>null,registerResumeGate:()=>()=>{},getConversations:async()=>[l],getConversation:async()=>l,getMessages:async()=>[a],submitToolCallForm:async()=>({status:"completed"}),confirmToolCall:async()=>{},rejectToolCall:async()=>{},submitFeedback:async()=>{},registerFunction:()=>{},unregisterFunction:()=>!0,getRegisteredFunctions:()=>[],executeClientFunction:async()=>{},getContextSnapshot:()=>null,notifyContextChanged:()=>{},setContext:()=>{},removeContext:()=>!0,addDynamicContext:()=>{},removeDynamicContext:()=>!0,registerNavigationFunction:()=>{},unregisterNavigationFunction:()=>{},getConfiguredAgent:()=>{},getHttp:()=>({get:async()=>({}),post:async()=>({})}),emitProactiveEvent:(e,t)=>{const n=o.get(e);n&&[...n].forEach(s=>s(t))},on:(e,t)=>{o.has(e)||o.set(e,new Set),o.get(e).add(t)},off:(e,t)=>{o.get(e)?.delete(t)},once:(e,t)=>{const n=(...s)=>{o.get(e)?.delete(n),t(...s)};o.has(e)||o.set(e,new Set),o.get(e).add(n)},waitFor:(e,t)=>new Promise((n,s)=>{let c;const d=f=>{c&&clearTimeout(c),o.get(e)?.delete(d),n(f)};o.has(e)||o.set(e,new Set),o.get(e).add(d),t?.timeout&&(c=setTimeout(()=>{o.get(e)?.delete(d),s(new Error(`waitFor("${e}") timed out after ${t.timeout}ms`))},t.timeout))}),updateConfig:()=>{},destroy:()=>{o.clear()},...g},i={};for(const[e,t]of Object.entries(m))i[e]=(...n)=>(r.push({method:e,args:n}),t(...n));return i.proactive=null,i.__calls=r,i.__callsFor=e=>r.filter(t=>t.method===e),i.__emitEvent=(e,t)=>{const n=o.get(e);n&&[...n].forEach(s=>s(t))},i}Object.defineProperty(exports,"createMockClient",{enumerable:!0,get:function(){return C}});