@useago/sdk 0.3.2 → 0.3.3

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 (116) hide show
  1. package/dist/AgoClient-DF7M2WAz.js +575 -0
  2. package/dist/AgoClient-bjN-z2ZQ.cjs +6 -0
  3. package/dist/angular.cjs +1 -143
  4. package/dist/angular.d.cts +530 -0
  5. package/dist/angular.d.ts +530 -2
  6. package/dist/angular.js +71 -139
  7. package/dist/createMockClient-D6uVh-B9.js +254 -0
  8. package/dist/createMockClient-DecMEUcK.cjs +1 -0
  9. package/dist/devtools.cjs +4 -78
  10. package/dist/devtools.d.cts +443 -0
  11. package/dist/devtools.d.ts +443 -2
  12. package/dist/devtools.js +46 -71
  13. package/dist/functions-Bz-1Bs3I.cjs +1 -0
  14. package/dist/functions-DdROP6Ui.js +312 -0
  15. package/dist/helpers.cjs +1 -15
  16. package/dist/{helpers/functions.d.ts → helpers.d.cts} +121 -62
  17. package/dist/helpers.d.ts +121 -2
  18. package/dist/helpers.js +16 -2
  19. package/dist/index.cjs +1 -347
  20. package/dist/index.d.cts +1150 -0
  21. package/dist/index.d.ts +1150 -20
  22. package/dist/index.js +128 -298
  23. package/dist/react.cjs +31 -22438
  24. package/dist/react.d.cts +960 -0
  25. package/dist/react.d.ts +960 -2
  26. package/dist/react.js +8401 -22376
  27. package/dist/rolldown-runtime-CaekUdDJ.cjs +1 -0
  28. package/dist/rolldown-runtime-DxmricAu.js +25 -0
  29. package/dist/vue.cjs +1 -336
  30. package/dist/vue.d.cts +1063 -0
  31. package/dist/vue.d.ts +1063 -2
  32. package/dist/vue.js +174 -316
  33. package/dist/{widget/types.d.ts → widget.d.cts} +41 -43
  34. package/dist/widget.d.ts +41 -2
  35. package/package.json +35 -24
  36. package/dist/AgoClient-DPZdN5n2.js +0 -905
  37. package/dist/AgoClient-DPZdN5n2.js.map +0 -1
  38. package/dist/AgoClient-wMVUQqCD.cjs +0 -976
  39. package/dist/AgoClient-wMVUQqCD.cjs.map +0 -1
  40. package/dist/angular/ago.service.d.ts +0 -98
  41. package/dist/angular/index.d.ts +0 -4
  42. package/dist/angular/provide.d.ts +0 -27
  43. package/dist/angular.cjs.map +0 -1
  44. package/dist/angular.js.map +0 -1
  45. package/dist/api/HttpClient.d.ts +0 -31
  46. package/dist/api/index.d.ts +0 -1
  47. package/dist/auto/createAgo.d.ts +0 -39
  48. package/dist/auto/index.d.ts +0 -1
  49. package/dist/client/AgoClient.d.ts +0 -169
  50. package/dist/client/errors.d.ts +0 -48
  51. package/dist/client/index.d.ts +0 -3
  52. package/dist/client/types.d.ts +0 -205
  53. package/dist/createMockClient-Ci_N2tH8.cjs +0 -104
  54. package/dist/createMockClient-Ci_N2tH8.cjs.map +0 -1
  55. package/dist/createMockClient-U0ae_AYy.js +0 -99
  56. package/dist/createMockClient-U0ae_AYy.js.map +0 -1
  57. package/dist/devtools/index.d.ts +0 -2
  58. package/dist/devtools/initDevPanel.d.ts +0 -15
  59. package/dist/devtools.cjs.map +0 -1
  60. package/dist/devtools.js.map +0 -1
  61. package/dist/functions/FunctionRegistry.d.ts +0 -41
  62. package/dist/functions/defineFunction.d.ts +0 -22
  63. package/dist/functions/index.d.ts +0 -2
  64. package/dist/functions/types.d.ts +0 -50
  65. package/dist/functions--c6lx3ic.cjs +0 -480
  66. package/dist/functions--c6lx3ic.cjs.map +0 -1
  67. package/dist/functions-C9F1dnmh.js +0 -398
  68. package/dist/functions-C9F1dnmh.js.map +0 -1
  69. package/dist/helpers/factory.d.ts +0 -20
  70. package/dist/helpers/index.d.ts +0 -1
  71. package/dist/index.cjs.map +0 -1
  72. package/dist/index.js.map +0 -1
  73. package/dist/react/components/ChatInput.d.ts +0 -12
  74. package/dist/react/components/ChatWidget.d.ts +0 -35
  75. package/dist/react/components/Markdown.d.ts +0 -12
  76. package/dist/react/components/Message.d.ts +0 -9
  77. package/dist/react/components/index.d.ts +0 -8
  78. package/dist/react/context/AgoContext.d.ts +0 -62
  79. package/dist/react/context/index.d.ts +0 -2
  80. package/dist/react/hooks/index.d.ts +0 -7
  81. package/dist/react/hooks/useAgo.d.ts +0 -14
  82. package/dist/react/hooks/useAgoContext.d.ts +0 -40
  83. package/dist/react/hooks/useAgoFunction.d.ts +0 -58
  84. package/dist/react/hooks/useAgoStore.d.ts +0 -17
  85. package/dist/react/hooks/useChat.d.ts +0 -45
  86. package/dist/react/hooks/useConversation.d.ts +0 -28
  87. package/dist/react/hooks/useMessages.d.ts +0 -26
  88. package/dist/react/index.d.ts +0 -24
  89. package/dist/react/testing.d.ts +0 -2
  90. package/dist/react.cjs.map +0 -1
  91. package/dist/react.js.map +0 -1
  92. package/dist/rolldown-runtime-BqCkTl7Q.cjs +0 -50
  93. package/dist/rolldown-runtime-CNZpIYwj.js +0 -33
  94. package/dist/state/ClientContextRegistry.d.ts +0 -64
  95. package/dist/state/createStore.d.ts +0 -30
  96. package/dist/streaming/SSEHandler.d.ts +0 -46
  97. package/dist/streaming/helpers.d.ts +0 -67
  98. package/dist/streaming/index.d.ts +0 -2
  99. package/dist/testing/createMockClient.d.ts +0 -42
  100. package/dist/testing/index.d.ts +0 -2
  101. package/dist/utils/eventEmitter.d.ts +0 -23
  102. package/dist/utils/index.d.ts +0 -2
  103. package/dist/utils/logger.d.ts +0 -14
  104. package/dist/vue/composables/useAgo.d.ts +0 -17
  105. package/dist/vue/composables/useAgoEvents.d.ts +0 -11
  106. package/dist/vue/composables/useAgoFunction.d.ts +0 -34
  107. package/dist/vue/composables/useAgoStore.d.ts +0 -18
  108. package/dist/vue/composables/useChat.d.ts +0 -251
  109. package/dist/vue/composables/useConversation.d.ts +0 -178
  110. package/dist/vue/composables/useMessages.d.ts +0 -89
  111. package/dist/vue/index.d.ts +0 -11
  112. package/dist/vue/plugin.d.ts +0 -16
  113. package/dist/vue/symbols.d.ts +0 -3
  114. package/dist/vue.cjs.map +0 -1
  115. package/dist/vue.js.map +0 -1
  116. package/dist/widget/index.d.ts +0 -1
package/dist/angular.js CHANGED
@@ -1,141 +1,73 @@
1
- import { t as AgoClient } from "./AgoClient-DPZdN5n2.js";
2
- //#region src/angular/ago.service.ts
3
- /**
4
- * Angular-style service wrapping AgoClient.
5
- * Provides RxJS-like Observables for streaming events and standard Promise-based methods.
6
- *
7
- * Usage with Angular DI:
8
- * ```ts
9
- * import { provideAgo, AgoService } from "@useago/sdk/angular";
10
- *
11
- * // In providers array:
12
- * provideAgo({ baseUrl: "https://YOUR-DOMAIN.useago.com" })
13
- *
14
- * // In component:
15
- * @Component({...})
16
- * export class ChatComponent {
17
- * private ago = inject(AgoService);
18
- * messages$ = this.ago.messages$;
19
- * }
20
- * ```
21
- *
22
- * Works without Angular DI too — just instantiate directly:
23
- * ```ts
24
- * const ago = new AgoService({ baseUrl: "https://YOUR-DOMAIN.useago.com" });
25
- * ```
26
- */
27
- var AgoService = class {
28
- constructor(config) {
29
- this.client = new AgoClient(config);
30
- this.messages$ = this.fromEvent("message:complete");
31
- this.chunks$ = this.fromEvent("message:chunk");
32
- this.errors$ = this.fromEvent("message:error");
33
- this.messageStart$ = this.fromEvent("message:start");
34
- }
35
- /** Create a minimal Observable from an AgoClient event */
36
- fromEvent(event) {
37
- const client = this.client;
38
- return { subscribe(observer) {
39
- const handler = (data) => {
40
- observer.next?.(data);
41
- };
42
- client.on(event, handler);
43
- return { unsubscribe: () => client.off(event, handler) };
44
- } };
45
- }
46
- /** Send a message and get a streaming response */
47
- sendMessage(content, options) {
48
- return this.client.sendMessage(content, options);
49
- }
50
- /** Get all conversations */
51
- getConversations() {
52
- return this.client.getConversations();
53
- }
54
- /** Get a specific conversation with messages */
55
- getConversation(id) {
56
- return this.client.getConversation(id);
57
- }
58
- /** Get messages for a conversation */
59
- getMessages(conversationId) {
60
- return this.client.getMessages(conversationId);
61
- }
62
- /** Submit form data for a tool call */
63
- submitToolCallForm(toolCallId, formData) {
64
- return this.client.submitToolCallForm(toolCallId, formData);
65
- }
66
- /** Confirm a tool call */
67
- confirmToolCall(toolCallId) {
68
- return this.client.confirmToolCall(toolCallId);
69
- }
70
- /** Reject a tool call */
71
- rejectToolCall(toolCallId) {
72
- return this.client.rejectToolCall(toolCallId);
73
- }
74
- /** Submit feedback for a message */
75
- submitFeedback(messageId, rating) {
76
- return this.client.submitFeedback(messageId, rating);
77
- }
78
- registerFunction(nameOrDef, handler, schema) {
79
- if (typeof nameOrDef === "object") this.client.registerFunction(nameOrDef);
80
- else this.client.registerFunction(nameOrDef, handler, schema);
81
- }
82
- /** Unregister a client-side function */
83
- unregisterFunction(name) {
84
- return this.client.unregisterFunction(name);
85
- }
86
- /** Register navigation routes */
87
- registerNavigationFunction(navigate, routes) {
88
- this.client.registerNavigationFunction(navigate, routes);
89
- }
90
- /** Subscribe to a client event */
91
- on(event, handler) {
92
- this.client.on(event, handler);
93
- }
94
- /** Unsubscribe from a client event */
95
- off(event, handler) {
96
- this.client.off(event, handler);
97
- }
98
- /** Update client config */
99
- updateConfig(config) {
100
- this.client.updateConfig(config);
101
- }
102
- /** Get the underlying AgoClient instance */
103
- getClient() {
104
- return this.client;
105
- }
106
- /** Destroy the service and clean up resources */
107
- destroy() {
108
- this.client.destroy();
109
- }
1
+ import { t as o } from "./AgoClient-DF7M2WAz.js";
2
+ var n = class {
3
+ constructor(t) {
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");
5
+ }
6
+ fromEvent(t) {
7
+ const e = this.client;
8
+ return { subscribe(i) {
9
+ const s = (r) => {
10
+ i.next?.(r);
11
+ };
12
+ return e.on(t, s), { unsubscribe: () => e.off(t, s) };
13
+ } };
14
+ }
15
+ sendMessage(t, e) {
16
+ return this.client.sendMessage(t, e);
17
+ }
18
+ getConversations() {
19
+ return this.client.getConversations();
20
+ }
21
+ getConversation(t) {
22
+ return this.client.getConversation(t);
23
+ }
24
+ getMessages(t) {
25
+ return this.client.getMessages(t);
26
+ }
27
+ submitToolCallForm(t, e) {
28
+ return this.client.submitToolCallForm(t, e);
29
+ }
30
+ confirmToolCall(t) {
31
+ return this.client.confirmToolCall(t);
32
+ }
33
+ rejectToolCall(t) {
34
+ return this.client.rejectToolCall(t);
35
+ }
36
+ submitFeedback(t, e) {
37
+ return this.client.submitFeedback(t, e);
38
+ }
39
+ registerFunction(t, e, i) {
40
+ typeof t == "object" ? this.client.registerFunction(t) : this.client.registerFunction(t, e, i);
41
+ }
42
+ unregisterFunction(t) {
43
+ return this.client.unregisterFunction(t);
44
+ }
45
+ registerNavigationFunction(t, e) {
46
+ this.client.registerNavigationFunction(t, e);
47
+ }
48
+ on(t, e) {
49
+ this.client.on(t, e);
50
+ }
51
+ off(t, e) {
52
+ this.client.off(t, e);
53
+ }
54
+ updateConfig(t) {
55
+ this.client.updateConfig(t);
56
+ }
57
+ getClient() {
58
+ return this.client;
59
+ }
60
+ destroy() {
61
+ this.client.destroy();
62
+ }
110
63
  };
111
- //#endregion
112
- //#region src/angular/provide.ts
113
- /**
114
- * Factory function that returns an Angular-compatible provider.
115
- * Use in your app's `providers` array or `bootstrapApplication`:
116
- *
117
- * ```ts
118
- * import { provideAgo, AgoService } from "@useago/sdk/angular";
119
- *
120
- * bootstrapApplication(AppComponent, {
121
- * providers: [provideAgo({ baseUrl: "https://YOUR-DOMAIN.useago.com" })],
122
- * });
123
- *
124
- * // Then inject in any component:
125
- * const ago = inject(AgoService);
126
- * ```
127
- *
128
- * Returns a provider tuple compatible with Angular's DI.
129
- * Since this package avoids a hard Angular dependency, the provider
130
- * is returned as a plain object — Angular's injector accepts this format.
131
- */
132
- function provideAgo(options) {
133
- return {
134
- provide: AgoService,
135
- useValue: new AgoService(options)
136
- };
64
+ function l(t) {
65
+ return {
66
+ provide: n,
67
+ useValue: new n(t)
68
+ };
137
69
  }
138
- //#endregion
139
- export { AgoService, provideAgo };
140
-
141
- //# sourceMappingURL=angular.js.map
70
+ export {
71
+ n as AgoService,
72
+ l as provideAgo
73
+ };
@@ -0,0 +1,254 @@
1
+ import { s as _ } from "./AgoClient-DF7M2WAz.js";
2
+ function N(d, n) {
3
+ const f = n ? n.storage ?? (typeof localStorage < "u" ? localStorage : void 0) : void 0;
4
+ let m = d;
5
+ if (n && f) try {
6
+ const a = f.getItem(n.key);
7
+ a != null && (m = JSON.parse(a));
8
+ } catch {
9
+ }
10
+ const t = /* @__PURE__ */ new Set(), h = () => t.forEach((a) => a(m));
11
+ function v() {
12
+ if (n && f) try {
13
+ f.setItem(n.key, JSON.stringify(m));
14
+ } catch {
15
+ }
16
+ }
17
+ return {
18
+ get: () => m,
19
+ set: (a) => {
20
+ m = a, v(), h();
21
+ },
22
+ subscribe: (a) => (t.add(a), () => {
23
+ t.delete(a);
24
+ })
25
+ };
26
+ }
27
+ var S = /^[a-zA-Z0-9_-]{1,40}$/;
28
+ function E(d) {
29
+ const { name: n, description: f, schema: m } = d;
30
+ if (!S.test(n)) throw new Error(`Invalid form collector name "${n}": must match ${S} (it becomes the update_/submit_ function names).`);
31
+ const t = typeof d.submit == "string" ? d.submit ? {
32
+ via: "client",
33
+ url: d.submit
34
+ } : !1 : d.submit ?? !1, h = m.properties ?? {}, v = m.required ?? [], a = (e) => e == null || e === "", s = (e) => v.filter((o) => a(e[o])), i = (e) => {
35
+ const o = {};
36
+ for (const [l, r] of Object.entries(e)) {
37
+ const b = h[l];
38
+ if (b)
39
+ if (r == null) o[l] = r;
40
+ else if (b.type === "number" || b.type === "integer") {
41
+ const F = typeof r == "number" ? r : Number(r);
42
+ o[l] = Number.isNaN(F) ? r : F;
43
+ } else b.type === "boolean" ? o[l] = typeof r == "boolean" ? r : r === "true" ? !0 : r === "false" ? !1 : !!r : o[l] = r;
44
+ }
45
+ return o;
46
+ }, c = d.initialValues ?? {}, g = s(c), u = N({
47
+ values: c,
48
+ missing: g,
49
+ complete: g.length === 0,
50
+ submitted: !1
51
+ }), y = (e) => {
52
+ const o = u.get(), l = {
53
+ ...o.values,
54
+ ...e
55
+ }, r = s(l), b = {
56
+ ...o,
57
+ values: l,
58
+ missing: r,
59
+ complete: r.length === 0
60
+ };
61
+ return u.set(b), b;
62
+ };
63
+ let p = null;
64
+ const C = async () => {
65
+ const e = u.get();
66
+ if (!e.complete) return {
67
+ ok: !1,
68
+ missing: e.missing
69
+ };
70
+ if (!t) return {
71
+ ok: !1,
72
+ error: "No submit target configured for this form collector."
73
+ };
74
+ const o = e.values;
75
+ try {
76
+ let l;
77
+ if (t.via === "client") if ("handler" in t) l = await t.handler(o);
78
+ else {
79
+ const r = await fetch(t.url, {
80
+ method: "POST",
81
+ headers: { "Content-Type": "application/json" },
82
+ credentials: "include",
83
+ body: JSON.stringify(o)
84
+ });
85
+ if (!r.ok) return {
86
+ ok: !1,
87
+ error: `Submit failed: HTTP ${r.status}`
88
+ };
89
+ l = await r.json().catch(() => {
90
+ });
91
+ }
92
+ else {
93
+ if (!p) return {
94
+ ok: !1,
95
+ error: "Backend submit requires install(client) (or useFormCollector) first."
96
+ };
97
+ l = await p.submitFormCollector(t.destination, o);
98
+ }
99
+ return u.set({
100
+ ...u.get(),
101
+ submitted: !0
102
+ }), {
103
+ ok: !0,
104
+ result: l
105
+ };
106
+ } catch (l) {
107
+ const r = l instanceof Error ? l.message : "Submit failed";
108
+ return _.error(`FormCollector "${n}" submit failed:`, l), {
109
+ ok: !1,
110
+ error: r
111
+ };
112
+ }
113
+ }, k = [{
114
+ name: `update_${n}`,
115
+ description: `Fill or update fields of the "${n}" 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.`,
116
+ parameters: {
117
+ ...m,
118
+ required: []
119
+ },
120
+ handler: (e) => {
121
+ const o = y(i(e));
122
+ return {
123
+ ok: !0,
124
+ values: o.values,
125
+ missing: o.missing,
126
+ complete: o.complete
127
+ };
128
+ }
129
+ }];
130
+ t && k.push({
131
+ name: `submit_${n}`,
132
+ description: `Submit the completed "${n}" 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.`,
133
+ parameters: {
134
+ type: "object",
135
+ properties: {}
136
+ },
137
+ handler: () => C()
138
+ });
139
+ const w = `form:${n}`, $ = () => {
140
+ const e = u.get(), o = t ? ` When all required fields are present and the user confirms, call submit_${n}.` : "";
141
+ return {
142
+ name: `Form: ${n}`,
143
+ description: `Conversational form the assistant is helping fill. ${f} Use update_${n} to record fields; ask the user only for what is still missing.${o}`,
144
+ data: {
145
+ values: e.values,
146
+ missing: e.missing,
147
+ complete: e.complete,
148
+ submitted: e.submitted
149
+ }
150
+ };
151
+ };
152
+ return {
153
+ name: n,
154
+ store: u,
155
+ functions: k,
156
+ contextKey: w,
157
+ contextProvider: $,
158
+ install: (e) => {
159
+ p = e;
160
+ for (const o of k) e.register(o);
161
+ return e.addDynamicContext(w, $), () => {
162
+ for (const o of k) e.unregisterFunction(o.name);
163
+ e.removeDynamicContext(w), p === e && (p = null);
164
+ };
165
+ },
166
+ submit: C,
167
+ getValues: () => u.get().values,
168
+ setValues: (e) => {
169
+ y(i(e));
170
+ },
171
+ reset: () => {
172
+ const e = s(c);
173
+ u.set({
174
+ values: c,
175
+ missing: e,
176
+ complete: e.length === 0,
177
+ submitted: !1
178
+ });
179
+ }
180
+ };
181
+ }
182
+ function O(d = {}) {
183
+ const { overrides: n = {} } = d, f = {
184
+ id: "mock-msg-1",
185
+ conversationId: "mock-conv-1",
186
+ content: "Mock response",
187
+ role: "assistant",
188
+ status: "DONE",
189
+ createdAt: /* @__PURE__ */ new Date()
190
+ }, m = {
191
+ id: "mock-conv-1",
192
+ title: "Mock Conversation",
193
+ lastMessageDate: /* @__PURE__ */ new Date()
194
+ }, t = /* @__PURE__ */ new Map(), h = [], v = {
195
+ sendMessage: async () => f,
196
+ getConversations: async () => [m],
197
+ getConversation: async () => m,
198
+ getMessages: async () => [f],
199
+ submitToolCallForm: async () => {
200
+ },
201
+ confirmToolCall: async () => {
202
+ },
203
+ rejectToolCall: async () => {
204
+ },
205
+ submitFeedback: async () => {
206
+ },
207
+ registerFunction: () => {
208
+ },
209
+ unregisterFunction: () => !0,
210
+ getRegisteredFunctions: () => [],
211
+ registerNavigationFunction: () => {
212
+ },
213
+ on: (s, i) => {
214
+ t.has(s) || t.set(s, /* @__PURE__ */ new Set()), t.get(s).add(i);
215
+ },
216
+ off: (s, i) => {
217
+ t.get(s)?.delete(i);
218
+ },
219
+ once: (s, i) => {
220
+ const c = (...g) => {
221
+ t.get(s)?.delete(c), i(...g);
222
+ };
223
+ t.has(s) || t.set(s, /* @__PURE__ */ new Set()), t.get(s).add(c);
224
+ },
225
+ waitFor: (s, i) => new Promise((c, g) => {
226
+ let u;
227
+ const y = (p) => {
228
+ u && clearTimeout(u), t.get(s)?.delete(y), c(p);
229
+ };
230
+ t.has(s) || t.set(s, /* @__PURE__ */ new Set()), t.get(s).add(y), i?.timeout && (u = setTimeout(() => {
231
+ t.get(s)?.delete(y), g(/* @__PURE__ */ new Error(`waitFor("${s}") timed out after ${i.timeout}ms`));
232
+ }, i.timeout));
233
+ }),
234
+ updateConfig: () => {
235
+ },
236
+ destroy: () => {
237
+ t.clear();
238
+ },
239
+ ...n
240
+ }, a = {};
241
+ for (const [s, i] of Object.entries(v)) a[s] = (...c) => (h.push({
242
+ method: s,
243
+ args: c
244
+ }), i(...c));
245
+ return a.__calls = h, a.__callsFor = (s) => h.filter((i) => i.method === s), a.__emitEvent = (s, i) => {
246
+ const c = t.get(s);
247
+ c && [...c].forEach((g) => g(i));
248
+ }, a;
249
+ }
250
+ export {
251
+ E as n,
252
+ N as r,
253
+ O as t
254
+ };
@@ -0,0 +1 @@
1
+ const M=require("./AgoClient-bjN-z2ZQ.cjs");function _(f,n){const d=n?n.storage??(typeof localStorage<"u"?localStorage:void 0):void 0;let m=f;if(n&&d)try{const a=d.getItem(n.key);a!=null&&(m=JSON.parse(a))}catch{}const t=new Set,b=()=>t.forEach(a=>a(m));function v(){if(n&&d)try{d.setItem(n.key,JSON.stringify(m))}catch{}}return{get:()=>m,set:a=>{m=a,v(),b()},subscribe:a=>(t.add(a),()=>{t.delete(a)})}}var S=/^[a-zA-Z0-9_-]{1,40}$/;function N(f){const{name:n,description:d,schema:m}=f;if(!S.test(n))throw new Error(`Invalid form collector name "${n}": must match ${S} (it becomes the update_/submit_ function names).`);const t=typeof f.submit=="string"?f.submit?{via:"client",url:f.submit}:!1:f.submit??!1,b=m.properties??{},v=m.required??[],a=e=>e==null||e==="",s=e=>v.filter(r=>a(e[r])),i=e=>{const r={};for(const[c,o]of Object.entries(e)){const p=b[c];if(p)if(o==null)r[c]=o;else if(p.type==="number"||p.type==="integer"){const F=typeof o=="number"?o:Number(o);r[c]=Number.isNaN(F)?o:F}else p.type==="boolean"?r[c]=typeof o=="boolean"?o:o==="true"?!0:o==="false"?!1:!!o:r[c]=o}return r},l=f.initialValues??{},g=s(l),u=_({values:l,missing:g,complete:g.length===0,submitted:!1}),y=e=>{const r=u.get(),c={...r.values,...e},o=s(c),p={...r,values:c,missing:o,complete:o.length===0};return u.set(p),p};let h=null;const C=async()=>{const e=u.get();if(!e.complete)return{ok:!1,missing:e.missing};if(!t)return{ok:!1,error:"No submit target configured for this form collector."};const r=e.values;try{let c;if(t.via==="client")if("handler"in t)c=await t.handler(r);else{const o=await fetch(t.url,{method:"POST",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify(r)});if(!o.ok)return{ok:!1,error:`Submit failed: HTTP ${o.status}`};c=await o.json().catch(()=>{})}else{if(!h)return{ok:!1,error:"Backend submit requires install(client) (or useFormCollector) first."};c=await h.submitFormCollector(t.destination,r)}return u.set({...u.get(),submitted:!0}),{ok:!0,result:c}}catch(c){const o=c instanceof Error?c.message:"Submit failed";return M.logger.error(`FormCollector "${n}" submit failed:`,c),{ok:!1,error:o}}},k=[{name:`update_${n}`,description:`Fill or update fields of the "${n}" form. ${d} 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:{...m,required:[]},handler:e=>{const r=y(i(e));return{ok:!0,values:r.values,missing:r.missing,complete:r.complete}}}];t&&k.push({name:`submit_${n}`,description:`Submit the completed "${n}" 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 w=`form:${n}`,$=()=>{const e=u.get(),r=t?` When all required fields are present and the user confirms, call submit_${n}.`:"";return{name:`Form: ${n}`,description:`Conversational form the assistant is helping fill. ${d} Use update_${n} to record fields; ask the user only for what is still missing.${r}`,data:{values:e.values,missing:e.missing,complete:e.complete,submitted:e.submitted}}};return{name:n,store:u,functions:k,contextKey:w,contextProvider:$,install:e=>{h=e;for(const r of k)e.register(r);return e.addDynamicContext(w,$),()=>{for(const r of k)e.unregisterFunction(r.name);e.removeDynamicContext(w),h===e&&(h=null)}},submit:C,getValues:()=>u.get().values,setValues:e=>{y(i(e))},reset:()=>{const e=s(l);u.set({values:l,missing:e,complete:e.length===0,submitted:!1})}}}function O(f={}){const{overrides:n={}}=f,d={id:"mock-msg-1",conversationId:"mock-conv-1",content:"Mock response",role:"assistant",status:"DONE",createdAt:new Date},m={id:"mock-conv-1",title:"Mock Conversation",lastMessageDate:new Date},t=new Map,b=[],v={sendMessage:async()=>d,getConversations:async()=>[m],getConversation:async()=>m,getMessages:async()=>[d],submitToolCallForm:async()=>{},confirmToolCall:async()=>{},rejectToolCall:async()=>{},submitFeedback:async()=>{},registerFunction:()=>{},unregisterFunction:()=>!0,getRegisteredFunctions:()=>[],registerNavigationFunction:()=>{},on:(s,i)=>{t.has(s)||t.set(s,new Set),t.get(s).add(i)},off:(s,i)=>{t.get(s)?.delete(i)},once:(s,i)=>{const l=(...g)=>{t.get(s)?.delete(l),i(...g)};t.has(s)||t.set(s,new Set),t.get(s).add(l)},waitFor:(s,i)=>new Promise((l,g)=>{let u;const y=h=>{u&&clearTimeout(u),t.get(s)?.delete(y),l(h)};t.has(s)||t.set(s,new Set),t.get(s).add(y),i?.timeout&&(u=setTimeout(()=>{t.get(s)?.delete(y),g(new Error(`waitFor("${s}") timed out after ${i.timeout}ms`))},i.timeout))}),updateConfig:()=>{},destroy:()=>{t.clear()},...n},a={};for(const[s,i]of Object.entries(v))a[s]=(...l)=>(b.push({method:s,args:l}),i(...l));return a.__calls=b,a.__callsFor=s=>b.filter(i=>i.method===s),a.__emitEvent=(s,i)=>{const l=t.get(s);l&&[...l].forEach(g=>g(i))},a}Object.defineProperty(exports,"createFormCollector",{enumerable:!0,get:function(){return N}});Object.defineProperty(exports,"createMockClient",{enumerable:!0,get:function(){return O}});Object.defineProperty(exports,"createStore",{enumerable:!0,get:function(){return _}});
package/dist/devtools.cjs CHANGED
@@ -1,87 +1,17 @@
1
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- //#region src/devtools/initDevPanel.ts
3
- var stateEl;
4
- var logEl;
5
- var getStateFn = () => ({});
6
- function renderState() {
7
- if (!stateEl) return;
8
- stateEl.textContent = JSON.stringify(getStateFn(), null, 2);
9
- }
10
- function logLine(text, kind) {
11
- if (!logEl) return;
12
- const line = document.createElement("div");
13
- line.className = `dev-log-line dev-log-${kind}`;
14
- line.textContent = `${(/* @__PURE__ */ new Date()).toLocaleTimeString()} ${text}`;
15
- logEl.appendChild(line);
16
- logEl.scrollTop = logEl.scrollHeight;
17
- }
18
- var COLLAPSE_KEY = "devPanelCollapsed";
19
- function setCollapsed(panel, collapsed) {
20
- panel.classList.toggle("collapsed", collapsed);
21
- const toggle = panel.querySelector(".dev-toggle");
22
- if (toggle) {
23
- toggle.textContent = collapsed ? "▢" : "—";
24
- toggle.title = collapsed ? "Expand dev tools" : "Collapse dev tools";
25
- toggle.setAttribute("aria-expanded", String(!collapsed));
26
- }
27
- try {
28
- localStorage.setItem(COLLAPSE_KEY, collapsed ? "1" : "0");
29
- } catch {}
30
- }
31
- function initDevPanel(options) {
32
- const { store, client, target } = options;
33
- getStateFn = store.get;
34
- injectStyles();
35
- const host = typeof target === "string" ? document.querySelector(target) : target instanceof Element ? target : document.body;
36
- const panel = document.createElement("aside");
37
- panel.id = "dev-panel";
38
- (host ?? document.body).appendChild(panel);
39
- panel.innerHTML = `
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});var s,d,u=()=>({});function p(){s&&(s.textContent=JSON.stringify(u(),null,2))}function v(o,n){if(!d)return;const e=document.createElement("div");e.className=`dev-log-line dev-log-${n}`,e.textContent=`${new Date().toLocaleTimeString()} ${o}`,d.appendChild(e),d.scrollTop=d.scrollHeight}var x="devPanelCollapsed";function r(o,n){o.classList.toggle("collapsed",n);const e=o.querySelector(".dev-toggle");e&&(e.textContent=n?"▢":"—",e.title=n?"Expand dev tools":"Collapse dev tools",e.setAttribute("aria-expanded",String(!n)));try{localStorage.setItem(x,n?"1":"0")}catch{}}function b(o){const{store:n,client:e,target:i}=o;u=n.get,m();const f=typeof i=="string"?document.querySelector(i):i instanceof Element?i:document.body,t=document.createElement("aside");t.id="dev-panel",(f??document.body).appendChild(t),t.innerHTML=`
40
2
  <div class="dev-head">
41
3
  <span class="dev-badge">DEV</span>
42
4
  <span class="dev-title">DEV TOOLS · client-side function state — not for production</span>
43
5
  <button type="button" class="dev-toggle" aria-label="Toggle dev tools">—</button>
44
6
  </div>
45
7
  <div class="dev-body">
46
- <div class="dev-fns">Registered functions: <code>${(client.getRegisteredFunctions?.() ?? []).map((f) => f.name).join(", ") || "—"}</code></div>
8
+ <div class="dev-fns">Registered functions: <code>${(e.getRegisteredFunctions?.()??[]).map(l=>l.name).join(", ")||"—"}</code></div>
47
9
  <div class="dev-section-label">JSON object (built by the agent)</div>
48
10
  <pre class="dev-state" id="dev-state"></pre>
49
11
  <div class="dev-section-label">Function calls</div>
50
12
  <div class="dev-log" id="dev-log"></div>
51
13
  </div>
52
- `;
53
- stateEl = panel.querySelector("#dev-state");
54
- logEl = panel.querySelector("#dev-log");
55
- panel.querySelector(".dev-toggle")?.addEventListener("click", (e) => {
56
- e.stopPropagation();
57
- setCollapsed(panel, !panel.classList.contains("collapsed"));
58
- });
59
- panel.addEventListener("click", () => {
60
- if (panel.classList.contains("collapsed")) setCollapsed(panel, false);
61
- });
62
- let startCollapsed = false;
63
- try {
64
- startCollapsed = localStorage.getItem(COLLAPSE_KEY) === "1";
65
- } catch {}
66
- setCollapsed(panel, startCollapsed);
67
- client.on("function:invoke", ({ functionName, arguments: args }) => {
68
- logLine(`→ ${functionName}(${JSON.stringify(args ?? {})})`, "invoke");
69
- });
70
- client.on("function:result", ({ result, error }) => {
71
- logLine(error ? `✗ error: ${error}` : `← ${JSON.stringify(result)}`, error ? "error" : "result");
72
- });
73
- store.subscribe(renderState);
74
- renderState();
75
- }
76
- var STYLE_ID = "dev-panel-styles";
77
- function injectStyles() {
78
- if (document.getElementById(STYLE_ID)) return;
79
- const style = document.createElement("style");
80
- style.id = STYLE_ID;
81
- style.textContent = PANEL_CSS;
82
- document.head.appendChild(style);
83
- }
84
- var PANEL_CSS = `
14
+ `,s=t.querySelector("#dev-state"),d=t.querySelector("#dev-log"),t.querySelector(".dev-toggle")?.addEventListener("click",l=>{l.stopPropagation(),r(t,!t.classList.contains("collapsed"))}),t.addEventListener("click",()=>{t.classList.contains("collapsed")&&r(t,!1)});let c=!1;try{c=localStorage.getItem(x)==="1"}catch{}r(t,c),e.on("function:invoke",({functionName:l,arguments:a})=>{v(`→ ${l}(${JSON.stringify(a??{})})`,"invoke")}),e.on("function:result",({result:l,error:a})=>{v(a?`✗ error: ${a}`:`← ${JSON.stringify(l)}`,a?"error":"result")}),n.subscribe(p),p()}var g="dev-panel-styles";function m(){if(document.getElementById(g))return;const o=document.createElement("style");o.id=g,o.textContent=h,document.head.appendChild(o)}var h=`
85
15
  #dev-panel {
86
16
  position: fixed;
87
17
  top: 16px;
@@ -175,8 +105,4 @@ var PANEL_CSS = `
175
105
  #dev-panel .dev-log-invoke { color: #9ecbff; }
176
106
  #dev-panel .dev-log-result { color: #86efac; }
177
107
  #dev-panel .dev-log-error { color: #fca5a5; }
178
- `;
179
- //#endregion
180
- exports.initDevPanel = initDevPanel;
181
-
182
- //# sourceMappingURL=devtools.cjs.map
108
+ `;exports.initDevPanel=b;