@useago/sdk 0.3.2 → 0.3.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 (121) 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/createFormCollector-ClzHfaBd.js +185 -0
  8. package/dist/createFormCollector-H4Me_2uj.cjs +1 -0
  9. package/dist/createMockClient-C50gjV0b.js +71 -0
  10. package/dist/createMockClient-DQvFFWnc.cjs +1 -0
  11. package/dist/devtools.cjs +26 -100
  12. package/dist/devtools.d.cts +443 -0
  13. package/dist/devtools.d.ts +443 -2
  14. package/dist/devtools.js +68 -93
  15. package/dist/functions-BH1X5kas.cjs +1 -0
  16. package/dist/functions-CWSRi3xv.js +312 -0
  17. package/dist/helpers.cjs +1 -15
  18. package/dist/{helpers/functions.d.ts → helpers.d.cts} +121 -62
  19. package/dist/helpers.d.ts +121 -2
  20. package/dist/helpers.js +16 -2
  21. package/dist/index.cjs +1 -347
  22. package/dist/index.d.cts +1150 -0
  23. package/dist/index.d.ts +1150 -20
  24. package/dist/index.js +129 -298
  25. package/dist/react.cjs +31 -22438
  26. package/dist/react.d.cts +999 -0
  27. package/dist/react.d.ts +999 -2
  28. package/dist/react.js +8416 -22376
  29. package/dist/rolldown-runtime-CaekUdDJ.cjs +1 -0
  30. package/dist/rolldown-runtime-DxmricAu.js +25 -0
  31. package/dist/vue.cjs +1 -336
  32. package/dist/vue.d.cts +1063 -0
  33. package/dist/vue.d.ts +1063 -2
  34. package/dist/vue.js +174 -316
  35. package/dist/widget.cjs +1 -0
  36. package/dist/widget.d.cts +577 -0
  37. package/dist/widget.d.ts +577 -2
  38. package/dist/widget.js +398 -0
  39. package/package.json +35 -24
  40. package/dist/AgoClient-DPZdN5n2.js +0 -905
  41. package/dist/AgoClient-DPZdN5n2.js.map +0 -1
  42. package/dist/AgoClient-wMVUQqCD.cjs +0 -976
  43. package/dist/AgoClient-wMVUQqCD.cjs.map +0 -1
  44. package/dist/angular/ago.service.d.ts +0 -98
  45. package/dist/angular/index.d.ts +0 -4
  46. package/dist/angular/provide.d.ts +0 -27
  47. package/dist/angular.cjs.map +0 -1
  48. package/dist/angular.js.map +0 -1
  49. package/dist/api/HttpClient.d.ts +0 -31
  50. package/dist/api/index.d.ts +0 -1
  51. package/dist/auto/createAgo.d.ts +0 -39
  52. package/dist/auto/index.d.ts +0 -1
  53. package/dist/client/AgoClient.d.ts +0 -169
  54. package/dist/client/errors.d.ts +0 -48
  55. package/dist/client/index.d.ts +0 -3
  56. package/dist/client/types.d.ts +0 -205
  57. package/dist/createMockClient-Ci_N2tH8.cjs +0 -104
  58. package/dist/createMockClient-Ci_N2tH8.cjs.map +0 -1
  59. package/dist/createMockClient-U0ae_AYy.js +0 -99
  60. package/dist/createMockClient-U0ae_AYy.js.map +0 -1
  61. package/dist/devtools/index.d.ts +0 -2
  62. package/dist/devtools/initDevPanel.d.ts +0 -15
  63. package/dist/devtools.cjs.map +0 -1
  64. package/dist/devtools.js.map +0 -1
  65. package/dist/functions/FunctionRegistry.d.ts +0 -41
  66. package/dist/functions/defineFunction.d.ts +0 -22
  67. package/dist/functions/index.d.ts +0 -2
  68. package/dist/functions/types.d.ts +0 -50
  69. package/dist/functions--c6lx3ic.cjs +0 -480
  70. package/dist/functions--c6lx3ic.cjs.map +0 -1
  71. package/dist/functions-C9F1dnmh.js +0 -398
  72. package/dist/functions-C9F1dnmh.js.map +0 -1
  73. package/dist/helpers/factory.d.ts +0 -20
  74. package/dist/helpers/index.d.ts +0 -1
  75. package/dist/index.cjs.map +0 -1
  76. package/dist/index.js.map +0 -1
  77. package/dist/react/components/ChatInput.d.ts +0 -12
  78. package/dist/react/components/ChatWidget.d.ts +0 -35
  79. package/dist/react/components/Markdown.d.ts +0 -12
  80. package/dist/react/components/Message.d.ts +0 -9
  81. package/dist/react/components/index.d.ts +0 -8
  82. package/dist/react/context/AgoContext.d.ts +0 -62
  83. package/dist/react/context/index.d.ts +0 -2
  84. package/dist/react/hooks/index.d.ts +0 -7
  85. package/dist/react/hooks/useAgo.d.ts +0 -14
  86. package/dist/react/hooks/useAgoContext.d.ts +0 -40
  87. package/dist/react/hooks/useAgoFunction.d.ts +0 -58
  88. package/dist/react/hooks/useAgoStore.d.ts +0 -17
  89. package/dist/react/hooks/useChat.d.ts +0 -45
  90. package/dist/react/hooks/useConversation.d.ts +0 -28
  91. package/dist/react/hooks/useMessages.d.ts +0 -26
  92. package/dist/react/index.d.ts +0 -24
  93. package/dist/react/testing.d.ts +0 -2
  94. package/dist/react.cjs.map +0 -1
  95. package/dist/react.js.map +0 -1
  96. package/dist/rolldown-runtime-BqCkTl7Q.cjs +0 -50
  97. package/dist/rolldown-runtime-CNZpIYwj.js +0 -33
  98. package/dist/state/ClientContextRegistry.d.ts +0 -64
  99. package/dist/state/createStore.d.ts +0 -30
  100. package/dist/streaming/SSEHandler.d.ts +0 -46
  101. package/dist/streaming/helpers.d.ts +0 -67
  102. package/dist/streaming/index.d.ts +0 -2
  103. package/dist/testing/createMockClient.d.ts +0 -42
  104. package/dist/testing/index.d.ts +0 -2
  105. package/dist/utils/eventEmitter.d.ts +0 -23
  106. package/dist/utils/index.d.ts +0 -2
  107. package/dist/utils/logger.d.ts +0 -14
  108. package/dist/vue/composables/useAgo.d.ts +0 -17
  109. package/dist/vue/composables/useAgoEvents.d.ts +0 -11
  110. package/dist/vue/composables/useAgoFunction.d.ts +0 -34
  111. package/dist/vue/composables/useAgoStore.d.ts +0 -18
  112. package/dist/vue/composables/useChat.d.ts +0 -251
  113. package/dist/vue/composables/useConversation.d.ts +0 -178
  114. package/dist/vue/composables/useMessages.d.ts +0 -89
  115. package/dist/vue/index.d.ts +0 -11
  116. package/dist/vue/plugin.d.ts +0 -16
  117. package/dist/vue/symbols.d.ts +0 -3
  118. package/dist/vue.cjs.map +0 -1
  119. package/dist/vue.js.map +0 -1
  120. package/dist/widget/index.d.ts +0 -1
  121. package/dist/widget/types.d.ts +0 -43
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,185 @@
1
+ import { s as _ } from "./AgoClient-DF7M2WAz.js";
2
+ function q(c, r) {
3
+ const u = r ? r.storage ?? (typeof localStorage < "u" ? localStorage : void 0) : void 0;
4
+ let a = c;
5
+ if (r && u) try {
6
+ const o = u.getItem(r.key);
7
+ o != null && (a = JSON.parse(o));
8
+ } catch {
9
+ }
10
+ const n = /* @__PURE__ */ new Set(), p = () => n.forEach((o) => o(a));
11
+ function b() {
12
+ if (r && u) try {
13
+ u.setItem(r.key, JSON.stringify(a));
14
+ } catch {
15
+ }
16
+ }
17
+ return {
18
+ get: () => a,
19
+ set: (o) => {
20
+ a = o, b(), p();
21
+ },
22
+ subscribe: (o) => (n.add(o), () => {
23
+ n.delete(o);
24
+ })
25
+ };
26
+ }
27
+ var N = /^[a-zA-Z0-9_-]{1,40}$/;
28
+ function E(c) {
29
+ const { name: r, description: u, schema: a } = c;
30
+ if (!N.test(r)) throw new Error(`Invalid form collector name "${r}": must match ${N} (it becomes the update_/submit_ function names).`);
31
+ const n = typeof c.submit == "string" ? c.submit ? {
32
+ via: "client",
33
+ url: c.submit
34
+ } : !1 : c.submit ?? !1, p = a.properties ?? {}, b = a.required ?? [], o = (e) => e == null || e === "", h = (e) => b.filter((t) => o(e[t])), v = (e) => {
35
+ const t = {};
36
+ for (const [i, s] of Object.entries(e)) {
37
+ const m = p[i];
38
+ if (m)
39
+ if (s == null) t[i] = s;
40
+ else if (m.type === "number" || m.type === "integer") {
41
+ const C = typeof s == "number" ? s : Number(s);
42
+ t[i] = Number.isNaN(C) ? s : C;
43
+ } else m.type === "boolean" ? t[i] = typeof s == "boolean" ? s : s === "true" ? !0 : s === "false" ? !1 : !!s : t[i] = s;
44
+ }
45
+ return t;
46
+ }, d = c.initialValues ?? {}, $ = h(d), l = q({
47
+ values: d,
48
+ missing: $,
49
+ complete: $.length === 0,
50
+ submitted: !1
51
+ }), k = (e) => {
52
+ const t = l.get(), i = {
53
+ ...t.values,
54
+ ...e
55
+ }, s = h(i), m = {
56
+ ...t,
57
+ values: i,
58
+ missing: s,
59
+ complete: s.length === 0
60
+ };
61
+ return l.set(m), m;
62
+ };
63
+ let f = null;
64
+ const S = async () => {
65
+ const e = l.get();
66
+ if (!e.complete) return {
67
+ ok: !1,
68
+ missing: e.missing
69
+ };
70
+ if (!n) return {
71
+ ok: !1,
72
+ error: "No submit target configured for this form collector."
73
+ };
74
+ const t = e.values;
75
+ try {
76
+ let i;
77
+ if (n.via === "client") if ("handler" in n) i = await n.handler(t);
78
+ else {
79
+ const s = await fetch(n.url, {
80
+ method: "POST",
81
+ headers: { "Content-Type": "application/json" },
82
+ credentials: "include",
83
+ body: JSON.stringify(t)
84
+ });
85
+ if (!s.ok) return {
86
+ ok: !1,
87
+ error: `Submit failed: HTTP ${s.status}`
88
+ };
89
+ i = await s.json().catch(() => {
90
+ });
91
+ }
92
+ else {
93
+ if (!f) return {
94
+ ok: !1,
95
+ error: "Backend submit requires install(client) (or useFormCollector) first."
96
+ };
97
+ i = await f.submitFormCollector(n.destination, t);
98
+ }
99
+ return l.set({
100
+ ...l.get(),
101
+ submitted: !0
102
+ }), {
103
+ ok: !0,
104
+ result: i
105
+ };
106
+ } catch (i) {
107
+ const s = i instanceof Error ? i.message : "Submit failed";
108
+ return _.error(`FormCollector "${r}" submit failed:`, i), {
109
+ ok: !1,
110
+ error: s
111
+ };
112
+ }
113
+ }, g = [{
114
+ name: `update_${r}`,
115
+ description: `Fill or update fields of the "${r}" form. ${u} 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
+ ...a,
118
+ required: []
119
+ },
120
+ handler: (e) => {
121
+ const t = k(v(e));
122
+ return {
123
+ ok: !0,
124
+ values: t.values,
125
+ missing: t.missing,
126
+ complete: t.complete
127
+ };
128
+ }
129
+ }];
130
+ n && g.push({
131
+ name: `submit_${r}`,
132
+ 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.`,
133
+ parameters: {
134
+ type: "object",
135
+ properties: {}
136
+ },
137
+ handler: () => S()
138
+ });
139
+ const y = `form:${r}`, w = () => {
140
+ const e = l.get(), t = n ? ` When all required fields are present and the user confirms, call submit_${r}.` : "";
141
+ return {
142
+ name: `Form: ${r}`,
143
+ description: `Conversational form the assistant is helping fill. ${u} Use update_${r} to record fields; ask the user only for what is still missing.${t}`,
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: r,
154
+ store: l,
155
+ functions: g,
156
+ contextKey: y,
157
+ contextProvider: w,
158
+ install: (e) => {
159
+ f = e;
160
+ for (const t of g) e.register(t);
161
+ return e.addDynamicContext(y, w), () => {
162
+ for (const t of g) e.unregisterFunction(t.name);
163
+ e.removeDynamicContext(y), f === e && (f = null);
164
+ };
165
+ },
166
+ submit: S,
167
+ getValues: () => l.get().values,
168
+ setValues: (e) => {
169
+ k(v(e));
170
+ },
171
+ reset: () => {
172
+ const e = h(d);
173
+ l.set({
174
+ values: d,
175
+ missing: e,
176
+ complete: e.length === 0,
177
+ submitted: !1
178
+ });
179
+ }
180
+ };
181
+ }
182
+ export {
183
+ q as n,
184
+ E as t
185
+ };
@@ -0,0 +1 @@
1
+ const _=require("./AgoClient-bjN-z2ZQ.cjs");function q(u,s){const c=s?s.storage??(typeof localStorage<"u"?localStorage:void 0):void 0;let a=u;if(s&&c)try{const o=c.getItem(s.key);o!=null&&(a=JSON.parse(o))}catch{}const i=new Set,b=()=>i.forEach(o=>o(a));function p(){if(s&&c)try{c.setItem(s.key,JSON.stringify(a))}catch{}}return{get:()=>a,set:o=>{a=o,p(),b()},subscribe:o=>(i.add(o),()=>{i.delete(o)})}}var N=/^[a-zA-Z0-9_-]{1,40}$/;function F(u){const{name:s,description:c,schema:a}=u;if(!N.test(s))throw new Error(`Invalid form collector name "${s}": must match ${N} (it becomes the update_/submit_ function names).`);const i=typeof u.submit=="string"?u.submit?{via:"client",url:u.submit}:!1:u.submit??!1,b=a.properties??{},p=a.required??[],o=e=>e==null||e==="",h=e=>p.filter(t=>o(e[t])),v=e=>{const t={};for(const[n,r]of Object.entries(e)){const m=b[n];if(m)if(r==null)t[n]=r;else if(m.type==="number"||m.type==="integer"){const w=typeof r=="number"?r:Number(r);t[n]=Number.isNaN(w)?r:w}else m.type==="boolean"?t[n]=typeof r=="boolean"?r:r==="true"?!0:r==="false"?!1:!!r:t[n]=r}return t},d=u.initialValues??{},$=h(d),l=q({values:d,missing:$,complete:$.length===0,submitted:!1}),S=e=>{const t=l.get(),n={...t.values,...e},r=h(n),m={...t,values:n,missing:r,complete:r.length===0};return l.set(m),m};let f=null;const k=async()=>{const e=l.get();if(!e.complete)return{ok:!1,missing:e.missing};if(!i)return{ok:!1,error:"No submit target configured for this form collector."};const t=e.values;try{let n;if(i.via==="client")if("handler"in i)n=await i.handler(t);else{const r=await fetch(i.url,{method:"POST",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify(t)});if(!r.ok)return{ok:!1,error:`Submit failed: HTTP ${r.status}`};n=await r.json().catch(()=>{})}else{if(!f)return{ok:!1,error:"Backend submit requires install(client) (or useFormCollector) first."};n=await f.submitFormCollector(i.destination,t)}return l.set({...l.get(),submitted:!0}),{ok:!0,result:n}}catch(n){const r=n instanceof Error?n.message:"Submit failed";return _.logger.error(`FormCollector "${s}" submit failed:`,n),{ok:!1,error:r}}},g=[{name:`update_${s}`,description:`Fill or update fields of the "${s}" form. ${c} 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=S(v(e));return{ok:!0,values:t.values,missing:t.missing,complete:t.complete}}}];i&&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:()=>k()});const y=`form:${s}`,C=()=>{const e=l.get(),t=i?` When all required fields are present and the user confirms, call submit_${s}.`:"";return{name:`Form: ${s}`,description:`Conversational form the assistant is helping fill. ${c} Use update_${s} to record fields; ask the user only for what is still missing.${t}`,data:{values:e.values,missing:e.missing,complete:e.complete,submitted:e.submitted}}};return{name:s,store:l,functions:g,contextKey:y,contextProvider:C,install:e=>{f=e;for(const t of g)e.register(t);return e.addDynamicContext(y,C),()=>{for(const t of g)e.unregisterFunction(t.name);e.removeDynamicContext(y),f===e&&(f=null)}},submit:k,getValues:()=>l.get().values,setValues:e=>{S(v(e))},reset:()=>{const e=h(d);l.set({values:d,missing:e,complete:e.length===0,submitted:!1})}}}Object.defineProperty(exports,"createFormCollector",{enumerable:!0,get:function(){return F}});Object.defineProperty(exports,"createStore",{enumerable:!0,get:function(){return q}});
@@ -0,0 +1,71 @@
1
+ function w(g = {}) {
2
+ const { overrides: m = {} } = g, d = {
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
+ }, t = /* @__PURE__ */ new Map(), i = [], u = {
14
+ sendMessage: async () => d,
15
+ getConversations: async () => [l],
16
+ getConversation: async () => l,
17
+ getMessages: async () => [d],
18
+ submitToolCallForm: async () => {
19
+ },
20
+ confirmToolCall: async () => {
21
+ },
22
+ rejectToolCall: async () => {
23
+ },
24
+ submitFeedback: async () => {
25
+ },
26
+ registerFunction: () => {
27
+ },
28
+ unregisterFunction: () => !0,
29
+ getRegisteredFunctions: () => [],
30
+ registerNavigationFunction: () => {
31
+ },
32
+ on: (e, o) => {
33
+ t.has(e) || t.set(e, /* @__PURE__ */ new Set()), t.get(e).add(o);
34
+ },
35
+ off: (e, o) => {
36
+ t.get(e)?.delete(o);
37
+ },
38
+ once: (e, o) => {
39
+ const s = (...a) => {
40
+ t.get(e)?.delete(s), o(...a);
41
+ };
42
+ t.has(e) || t.set(e, /* @__PURE__ */ new Set()), t.get(e).add(s);
43
+ },
44
+ waitFor: (e, o) => new Promise((s, a) => {
45
+ let r;
46
+ const c = (f) => {
47
+ r && clearTimeout(r), t.get(e)?.delete(c), s(f);
48
+ };
49
+ t.has(e) || t.set(e, /* @__PURE__ */ new Set()), t.get(e).add(c), o?.timeout && (r = setTimeout(() => {
50
+ t.get(e)?.delete(c), a(/* @__PURE__ */ new Error(`waitFor("${e}") timed out after ${o.timeout}ms`));
51
+ }, o.timeout));
52
+ }),
53
+ updateConfig: () => {
54
+ },
55
+ destroy: () => {
56
+ t.clear();
57
+ },
58
+ ...m
59
+ }, n = {};
60
+ for (const [e, o] of Object.entries(u)) n[e] = (...s) => (i.push({
61
+ method: e,
62
+ args: s
63
+ }), o(...s));
64
+ return n.__calls = i, n.__callsFor = (e) => i.filter((o) => o.method === e), n.__emitEvent = (e, o) => {
65
+ const s = t.get(e);
66
+ s && [...s].forEach((a) => a(o));
67
+ }, n;
68
+ }
69
+ export {
70
+ w as t
71
+ };
@@ -0,0 +1 @@
1
+ function w(u={}){const{overrides:g={}}=u,d={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},t=new Map,i=[],m={sendMessage:async()=>d,getConversations:async()=>[l],getConversation:async()=>l,getMessages:async()=>[d],submitToolCallForm:async()=>{},confirmToolCall:async()=>{},rejectToolCall:async()=>{},submitFeedback:async()=>{},registerFunction:()=>{},unregisterFunction:()=>!0,getRegisteredFunctions:()=>[],registerNavigationFunction:()=>{},on:(e,o)=>{t.has(e)||t.set(e,new Set),t.get(e).add(o)},off:(e,o)=>{t.get(e)?.delete(o)},once:(e,o)=>{const s=(...r)=>{t.get(e)?.delete(s),o(...r)};t.has(e)||t.set(e,new Set),t.get(e).add(s)},waitFor:(e,o)=>new Promise((s,r)=>{let a;const c=f=>{a&&clearTimeout(a),t.get(e)?.delete(c),s(f)};t.has(e)||t.set(e,new Set),t.get(e).add(c),o?.timeout&&(a=setTimeout(()=>{t.get(e)?.delete(c),r(new Error(`waitFor("${e}") timed out after ${o.timeout}ms`))},o.timeout))}),updateConfig:()=>{},destroy:()=>{t.clear()},...g},n={};for(const[e,o]of Object.entries(m))n[e]=(...s)=>(i.push({method:e,args:s}),o(...s));return n.__calls=i,n.__callsFor=e=>i.filter(o=>o.method===e),n.__emitEvent=(e,o)=>{const s=t.get(e);s&&[...s].forEach(r=>r(o))},n}Object.defineProperty(exports,"createMockClient",{enumerable:!0,get:function(){return w}});
package/dist/devtools.cjs CHANGED
@@ -1,88 +1,18 @@
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 g(t,a){if(!d)return;const e=document.createElement("div");e.className=`dev-log-line dev-log-${a}`,e.textContent=`${new Date().toLocaleTimeString()} ${t}`,d.appendChild(e),d.scrollTop=d.scrollHeight}var x="ago_dev_panel_collapsed";function r(t,a){t.classList.toggle("collapsed",a);const e=t.querySelector(".dev-toggle");e&&(e.textContent=a?"▢":"—",e.title=a?"Expand dev tools":"Collapse dev tools",e.setAttribute("aria-expanded",String(!a)));try{localStorage.setItem(x,a?"1":"0")}catch{}}function b(t){const{store:a,client:e,target:i}=t;u=a.get,m();const f=typeof i=="string"?document.querySelector(i):i instanceof Element?i:document.body,o=document.createElement("aside");o.id="ago-dev-panel",(f??document.body).appendChild(o),o.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(n=>n.name).join(", ")||"—"}</code></div>
47
9
  <div class="dev-section-label">JSON object (built by the agent)</div>
48
- <pre class="dev-state" id="dev-state"></pre>
10
+ <pre class="dev-state" id="ago-dev-state"></pre>
49
11
  <div class="dev-section-label">Function calls</div>
50
- <div class="dev-log" id="dev-log"></div>
12
+ <div class="dev-log" id="ago-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 = `
85
- #dev-panel {
14
+ `,s=o.querySelector("#ago-dev-state"),d=o.querySelector("#ago-dev-log"),o.querySelector(".dev-toggle")?.addEventListener("click",n=>{n.stopPropagation(),r(o,!o.classList.contains("collapsed"))}),o.addEventListener("click",()=>{o.classList.contains("collapsed")&&r(o,!1)});let c=!1;try{c=localStorage.getItem(x)==="1"}catch{}r(o,c),e.on("function:invoke",({functionName:n,arguments:l})=>{g(`→ ${n}(${JSON.stringify(l??{})})`,"invoke")}),e.on("function:result",({result:n,error:l})=>{g(l?`✗ error: ${l}`:`← ${JSON.stringify(n)}`,l?"error":"result")}),a.subscribe(p),p()}var v="ago-dev-panel-styles";function m(){if(document.getElementById(v))return;const t=document.createElement("style");t.id=v,t.textContent=h,document.head.appendChild(t)}var h=`
15
+ #ago-dev-panel {
86
16
  position: fixed;
87
17
  top: 16px;
88
18
  right: 16px;
@@ -103,8 +33,8 @@ var PANEL_CSS = `
103
33
  font-size: 12px;
104
34
  z-index: 1000;
105
35
  }
106
- #dev-panel .dev-head { display: flex; align-items: center; gap: 8px; }
107
- #dev-panel .dev-toggle {
36
+ #ago-dev-panel .dev-head { display: flex; align-items: center; gap: 8px; }
37
+ #ago-dev-panel .dev-toggle {
108
38
  margin-left: auto;
109
39
  flex: none;
110
40
  width: 22px;
@@ -120,19 +50,19 @@ var PANEL_CSS = `
120
50
  line-height: 1;
121
51
  cursor: pointer;
122
52
  }
123
- #dev-panel .dev-toggle:hover { color: #d7e0e8; border-color: #3a4655; }
124
- #dev-panel .dev-body { display: flex; flex-direction: column; gap: 8px; }
53
+ #ago-dev-panel .dev-toggle:hover { color: #d7e0e8; border-color: #3a4655; }
54
+ #ago-dev-panel .dev-body { display: flex; flex-direction: column; gap: 8px; }
125
55
 
126
56
  /* Collapsed: shrink to a small clickable widget showing only the DEV badge. */
127
- #dev-panel.collapsed {
57
+ #ago-dev-panel.collapsed {
128
58
  width: auto;
129
59
  cursor: pointer;
130
60
  padding: 8px 10px;
131
61
  }
132
- #dev-panel.collapsed .dev-title,
133
- #dev-panel.collapsed .dev-body { display: none; }
134
- #dev-panel.collapsed .dev-toggle { margin-left: 6px; }
135
- #dev-panel .dev-badge {
62
+ #ago-dev-panel.collapsed .dev-title,
63
+ #ago-dev-panel.collapsed .dev-body { display: none; }
64
+ #ago-dev-panel.collapsed .dev-toggle { margin-left: 6px; }
65
+ #ago-dev-panel .dev-badge {
136
66
  background: #f59e0b;
137
67
  color: #1c1206;
138
68
  font-weight: 700;
@@ -141,17 +71,17 @@ var PANEL_CSS = `
141
71
  padding: 2px 6px;
142
72
  border-radius: 5px;
143
73
  }
144
- #dev-panel .dev-title { color: #f59e0b; font-size: 11px; line-height: 1.3; }
145
- #dev-panel .dev-fns { color: #7c8a99; font-size: 11px; }
146
- #dev-panel .dev-fns code { color: #9ecbff; }
147
- #dev-panel .dev-section-label {
74
+ #ago-dev-panel .dev-title { color: #f59e0b; font-size: 11px; line-height: 1.3; }
75
+ #ago-dev-panel .dev-fns { color: #7c8a99; font-size: 11px; }
76
+ #ago-dev-panel .dev-fns code { color: #9ecbff; }
77
+ #ago-dev-panel .dev-section-label {
148
78
  color: #7c8a99;
149
79
  text-transform: uppercase;
150
80
  letter-spacing: .08em;
151
81
  font-size: 10px;
152
82
  margin-top: 4px;
153
83
  }
154
- #dev-panel .dev-state {
84
+ #ago-dev-panel .dev-state {
155
85
  margin: 0;
156
86
  padding: 8px;
157
87
  background: #060a0e;
@@ -161,7 +91,7 @@ var PANEL_CSS = `
161
91
  white-space: pre;
162
92
  color: #c8e6c9;
163
93
  }
164
- #dev-panel .dev-log {
94
+ #ago-dev-panel .dev-log {
165
95
  display: flex;
166
96
  flex-direction: column;
167
97
  gap: 2px;
@@ -171,12 +101,8 @@ var PANEL_CSS = `
171
101
  border-radius: 8px;
172
102
  padding: 6px 8px;
173
103
  }
174
- #dev-panel .dev-log-line { white-space: pre-wrap; word-break: break-word; line-height: 1.4; }
175
- #dev-panel .dev-log-invoke { color: #9ecbff; }
176
- #dev-panel .dev-log-result { color: #86efac; }
177
- #dev-panel .dev-log-error { color: #fca5a5; }
178
- `;
179
- //#endregion
180
- exports.initDevPanel = initDevPanel;
181
-
182
- //# sourceMappingURL=devtools.cjs.map
104
+ #ago-dev-panel .dev-log-line { white-space: pre-wrap; word-break: break-word; line-height: 1.4; }
105
+ #ago-dev-panel .dev-log-invoke { color: #9ecbff; }
106
+ #ago-dev-panel .dev-log-result { color: #86efac; }
107
+ #ago-dev-panel .dev-log-error { color: #fca5a5; }
108
+ `;exports.initDevPanel=b;