@useago/sdk 0.3.1 → 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 (113) hide show
  1. package/README.md +2 -0
  2. package/dist/AgoClient-DF7M2WAz.js +575 -0
  3. package/dist/AgoClient-bjN-z2ZQ.cjs +6 -0
  4. package/dist/angular.cjs +1 -143
  5. package/dist/angular.d.cts +530 -0
  6. package/dist/angular.d.ts +530 -2
  7. package/dist/angular.js +71 -139
  8. package/dist/createMockClient-D6uVh-B9.js +254 -0
  9. package/dist/createMockClient-DecMEUcK.cjs +1 -0
  10. package/dist/devtools.cjs +108 -0
  11. package/dist/devtools.d.cts +443 -0
  12. package/dist/devtools.d.ts +443 -0
  13. package/dist/devtools.js +156 -0
  14. package/dist/functions-Bz-1Bs3I.cjs +1 -0
  15. package/dist/functions-DdROP6Ui.js +312 -0
  16. package/dist/helpers.cjs +1 -15
  17. package/dist/{helpers/functions.d.ts → helpers.d.cts} +121 -62
  18. package/dist/helpers.d.ts +121 -2
  19. package/dist/helpers.js +16 -2
  20. package/dist/index.cjs +1 -335
  21. package/dist/index.d.cts +1150 -0
  22. package/dist/index.d.ts +1150 -20
  23. package/dist/index.js +128 -286
  24. package/dist/react.cjs +31 -22438
  25. package/dist/react.d.cts +960 -0
  26. package/dist/react.d.ts +960 -2
  27. package/dist/react.js +8401 -22376
  28. package/dist/rolldown-runtime-CaekUdDJ.cjs +1 -0
  29. package/dist/rolldown-runtime-DxmricAu.js +25 -0
  30. package/dist/vue.cjs +1 -336
  31. package/dist/vue.d.cts +1063 -0
  32. package/dist/vue.d.ts +1063 -2
  33. package/dist/vue.js +174 -316
  34. package/dist/{widget/types.d.ts → widget.d.cts} +41 -43
  35. package/dist/widget.d.ts +41 -2
  36. package/package.json +37 -21
  37. package/dist/AgoClient-CNT-8sh_.js +0 -905
  38. package/dist/AgoClient-CNT-8sh_.js.map +0 -1
  39. package/dist/AgoClient-D0l1GTRs.cjs +0 -976
  40. package/dist/AgoClient-D0l1GTRs.cjs.map +0 -1
  41. package/dist/angular/ago.service.d.ts +0 -98
  42. package/dist/angular/index.d.ts +0 -4
  43. package/dist/angular/provide.d.ts +0 -27
  44. package/dist/angular.cjs.map +0 -1
  45. package/dist/angular.js.map +0 -1
  46. package/dist/api/HttpClient.d.ts +0 -31
  47. package/dist/api/index.d.ts +0 -1
  48. package/dist/auto/createAgo.d.ts +0 -39
  49. package/dist/auto/index.d.ts +0 -1
  50. package/dist/client/AgoClient.d.ts +0 -169
  51. package/dist/client/errors.d.ts +0 -48
  52. package/dist/client/index.d.ts +0 -3
  53. package/dist/client/types.d.ts +0 -205
  54. package/dist/createMockClient-Ci_N2tH8.cjs +0 -104
  55. package/dist/createMockClient-Ci_N2tH8.cjs.map +0 -1
  56. package/dist/createMockClient-U0ae_AYy.js +0 -99
  57. package/dist/createMockClient-U0ae_AYy.js.map +0 -1
  58. package/dist/functions/FunctionRegistry.d.ts +0 -41
  59. package/dist/functions/defineFunction.d.ts +0 -22
  60. package/dist/functions/index.d.ts +0 -2
  61. package/dist/functions/types.d.ts +0 -50
  62. package/dist/functions--c6lx3ic.cjs +0 -480
  63. package/dist/functions--c6lx3ic.cjs.map +0 -1
  64. package/dist/functions-C9F1dnmh.js +0 -398
  65. package/dist/functions-C9F1dnmh.js.map +0 -1
  66. package/dist/helpers/factory.d.ts +0 -20
  67. package/dist/helpers/index.d.ts +0 -1
  68. package/dist/index.cjs.map +0 -1
  69. package/dist/index.js.map +0 -1
  70. package/dist/react/components/ChatInput.d.ts +0 -12
  71. package/dist/react/components/ChatWidget.d.ts +0 -35
  72. package/dist/react/components/Markdown.d.ts +0 -12
  73. package/dist/react/components/Message.d.ts +0 -9
  74. package/dist/react/components/index.d.ts +0 -8
  75. package/dist/react/context/AgoContext.d.ts +0 -62
  76. package/dist/react/context/index.d.ts +0 -2
  77. package/dist/react/hooks/index.d.ts +0 -7
  78. package/dist/react/hooks/useAgo.d.ts +0 -14
  79. package/dist/react/hooks/useAgoContext.d.ts +0 -40
  80. package/dist/react/hooks/useAgoFunction.d.ts +0 -58
  81. package/dist/react/hooks/useAgoStore.d.ts +0 -17
  82. package/dist/react/hooks/useChat.d.ts +0 -45
  83. package/dist/react/hooks/useConversation.d.ts +0 -28
  84. package/dist/react/hooks/useMessages.d.ts +0 -26
  85. package/dist/react/index.d.ts +0 -24
  86. package/dist/react/testing.d.ts +0 -2
  87. package/dist/react.cjs.map +0 -1
  88. package/dist/react.js.map +0 -1
  89. package/dist/rolldown-runtime-BqCkTl7Q.cjs +0 -50
  90. package/dist/rolldown-runtime-CNZpIYwj.js +0 -33
  91. package/dist/state/ClientContextRegistry.d.ts +0 -64
  92. package/dist/state/createStore.d.ts +0 -18
  93. package/dist/streaming/SSEHandler.d.ts +0 -46
  94. package/dist/streaming/helpers.d.ts +0 -67
  95. package/dist/streaming/index.d.ts +0 -2
  96. package/dist/testing/createMockClient.d.ts +0 -42
  97. package/dist/testing/index.d.ts +0 -2
  98. package/dist/utils/eventEmitter.d.ts +0 -23
  99. package/dist/utils/index.d.ts +0 -2
  100. package/dist/utils/logger.d.ts +0 -14
  101. package/dist/vue/composables/useAgo.d.ts +0 -17
  102. package/dist/vue/composables/useAgoEvents.d.ts +0 -11
  103. package/dist/vue/composables/useAgoFunction.d.ts +0 -34
  104. package/dist/vue/composables/useAgoStore.d.ts +0 -18
  105. package/dist/vue/composables/useChat.d.ts +0 -251
  106. package/dist/vue/composables/useConversation.d.ts +0 -178
  107. package/dist/vue/composables/useMessages.d.ts +0 -89
  108. package/dist/vue/index.d.ts +0 -11
  109. package/dist/vue/plugin.d.ts +0 -16
  110. package/dist/vue/symbols.d.ts +0 -3
  111. package/dist/vue.cjs.map +0 -1
  112. package/dist/vue.js.map +0 -1
  113. package/dist/widget/index.d.ts +0 -1
package/dist/index.js CHANGED
@@ -1,297 +1,139 @@
1
- import { a as ClientContextRegistry, c as AgoApiError, d as AgoNetworkError, f as AgoStreamError, i as isStreamNetworkError, l as AgoError, n as EventEmitter, o as FunctionRegistry, r as SSEHandler, s as logger, t as AgoClient, u as AgoFunctionError } from "./AgoClient-CNT-8sh_.js";
2
- import { t as createMockClient } from "./createMockClient-U0ae_AYy.js";
3
- import { a as highlightElement, c as setLocalStorage, d as showNotification, f as showToast, i as getUserLocation, l as setTheme, m as trackEvent, o as openUrl, p as submitForm, r as getLocalStorage, s as scrollToElement, t as copyToClipboard, u as showConfirmDialog } from "./functions-C9F1dnmh.js";
4
- //#region src/state/createStore.ts
5
- function createStore(initial) {
6
- let state = initial;
7
- const subscribers = /* @__PURE__ */ new Set();
8
- return {
9
- get: () => state,
10
- set: (next) => {
11
- state = next;
12
- subscribers.forEach((fn) => fn(state));
13
- },
14
- subscribe: (fn) => {
15
- subscribers.add(fn);
16
- return () => {
17
- subscribers.delete(fn);
18
- };
19
- }
20
- };
1
+ import { a as w, c as h, d as A, f as y, i as C, l as E, n as b, o as S, r as v, s as k, t as d, u as M } from "./AgoClient-DF7M2WAz.js";
2
+ import { n as T, r as I, t as U } from "./createMockClient-D6uVh-B9.js";
3
+ import { a as O, c as q, d as x, f as L, i as N, l as D, m as H, o as J, p as R, r as j, s as B, t as P, u as $ } from "./functions-DdROP6Ui.js";
4
+ function z(e) {
5
+ return e;
21
6
  }
22
- //#endregion
23
- //#region src/functions/defineFunction.ts
24
- /**
25
- * Create a reusable function definition.
26
- * Returns the same object — this is an identity function for discoverability and type-checking.
27
- *
28
- * ```ts
29
- * // Define once, reuse anywhere
30
- * export const lookupOrder = defineFunction({
31
- * name: "lookupOrder",
32
- * description: "Look up an order by ID",
33
- * parameters: { type: "object", properties: { id: { type: "string" } }, required: ["id"] },
34
- * handler: async (args) => fetchOrder(args.id as string),
35
- * });
36
- *
37
- * // Register with client
38
- * client.registerFunction(lookupOrder);
39
- *
40
- * // Or use in React
41
- * useAgoFunction(lookupOrder.name, lookupOrder);
42
- * ```
43
- */
44
- function defineFunction(definition) {
45
- return definition;
7
+ function K(e, t) {
8
+ return e.on("message:complete", t), () => e.off("message:complete", t);
46
9
  }
47
- //#endregion
48
- //#region src/streaming/helpers.ts
49
- /**
50
- * Subscribe to complete messages with a simple callback. Returns an unsubscribe function.
51
- *
52
- * ```ts
53
- * const unsub = onMessage(client, (msg) => console.log(msg.content));
54
- * // later: unsub();
55
- * ```
56
- */
57
- function onMessage(client, callback) {
58
- client.on("message:complete", callback);
59
- return () => client.off("message:complete", callback);
10
+ function Q(e, t) {
11
+ return e.on("message:chunk", t), () => e.off("message:chunk", t);
60
12
  }
61
- /**
62
- * Subscribe to streaming text chunks.
63
- *
64
- * ```ts
65
- * onMessageChunk(client, ({ content }) => {
66
- * outputEl.textContent += content;
67
- * });
68
- * ```
69
- */
70
- function onMessageChunk(client, callback) {
71
- client.on("message:chunk", callback);
72
- return () => client.off("message:chunk", callback);
13
+ function V(e, t) {
14
+ return e.on("message:start", t), () => e.off("message:start", t);
73
15
  }
74
- /**
75
- * Subscribe to message start events.
76
- */
77
- function onMessageStart(client, callback) {
78
- client.on("message:start", callback);
79
- return () => client.off("message:start", callback);
16
+ function W(e, t) {
17
+ return e.on("message:error", t), () => e.off("message:error", t);
80
18
  }
81
- /**
82
- * Subscribe to message errors.
83
- */
84
- function onMessageError(client, callback) {
85
- client.on("message:error", callback);
86
- return () => client.off("message:error", callback);
19
+ function X(e, t) {
20
+ return e.on("toolCall:received", t), () => e.off("toolCall:received", t);
87
21
  }
88
- /**
89
- * Subscribe to tool call events.
90
- */
91
- function onToolCall(client, callback) {
92
- client.on("toolCall:received", callback);
93
- return () => client.off("toolCall:received", callback);
22
+ function Y(e, t) {
23
+ return e.on("function:invoke", t), () => e.off("function:invoke", t);
94
24
  }
95
- /**
96
- * Subscribe to client function invocations.
97
- */
98
- function onFunctionInvoke(client, callback) {
99
- client.on("function:invoke", callback);
100
- return () => client.off("function:invoke", callback);
25
+ async function* Z(e, t, g) {
26
+ const n = [];
27
+ let r = null, a = !1;
28
+ const u = (s) => {
29
+ n.push(s), r?.();
30
+ }, f = (s) => u({
31
+ type: "start",
32
+ data: s
33
+ }), o = (s) => u({
34
+ type: "chunk",
35
+ data: s
36
+ }), i = (s) => {
37
+ u({
38
+ type: "complete",
39
+ data: s
40
+ }), a = !0, r?.();
41
+ }, l = (s) => {
42
+ u({
43
+ type: "error",
44
+ data: s
45
+ }), a = !0, r?.();
46
+ }, m = (s) => u({
47
+ type: "toolCall",
48
+ data: s
49
+ });
50
+ e.on("message:start", f), e.on("message:chunk", o), e.on("message:complete", i), e.on("message:error", l), e.on("toolCall:received", m), e.sendMessage(t, g).catch(() => {
51
+ a = !0, r?.();
52
+ });
53
+ try {
54
+ for (; !a || n.length > 0; ) n.length > 0 ? yield n.shift() : (await new Promise((s) => {
55
+ r = s;
56
+ }), r = null);
57
+ } finally {
58
+ e.off("message:start", f), e.off("message:chunk", o), e.off("message:complete", i), e.off("message:error", l), e.off("toolCall:received", m);
59
+ }
101
60
  }
102
- /**
103
- * Send a message and iterate over chunks as an async generator.
104
- * Gives you full control over how you process the stream.
105
- *
106
- * ```ts
107
- * for await (const chunk of createMessageStream(client, "Hello!")) {
108
- * console.log(chunk.type, chunk.data);
109
- * }
110
- * ```
111
- */
112
- async function* createMessageStream(client, content, options) {
113
- const queue = [];
114
- let resolve = null;
115
- let done = false;
116
- const push = (event) => {
117
- queue.push(event);
118
- resolve?.();
119
- };
120
- const onStart = (data) => push({
121
- type: "start",
122
- data
123
- });
124
- const onChunk = (data) => push({
125
- type: "chunk",
126
- data
127
- });
128
- const onComplete = (data) => {
129
- push({
130
- type: "complete",
131
- data
132
- });
133
- done = true;
134
- resolve?.();
135
- };
136
- const onError = (data) => {
137
- push({
138
- type: "error",
139
- data
140
- });
141
- done = true;
142
- resolve?.();
143
- };
144
- const onTool = (data) => push({
145
- type: "toolCall",
146
- data
147
- });
148
- client.on("message:start", onStart);
149
- client.on("message:chunk", onChunk);
150
- client.on("message:complete", onComplete);
151
- client.on("message:error", onError);
152
- client.on("toolCall:received", onTool);
153
- client.sendMessage(content, options).catch(() => {
154
- done = true;
155
- resolve?.();
156
- });
157
- try {
158
- while (!done || queue.length > 0) if (queue.length > 0) yield queue.shift();
159
- else {
160
- await new Promise((r) => {
161
- resolve = r;
162
- });
163
- resolve = null;
164
- }
165
- } finally {
166
- client.off("message:start", onStart);
167
- client.off("message:chunk", onChunk);
168
- client.off("message:complete", onComplete);
169
- client.off("message:error", onError);
170
- client.off("toolCall:received", onTool);
171
- }
61
+ function c(e) {
62
+ let t, g, n, r, a, u;
63
+ if (typeof window < "u" && window.AGO) {
64
+ const o = window.AGO;
65
+ t = o.basepath, g = o.widgetId, n = o.agent || o.defaultAgent, r = o.permission, a = o.email, u = o.jwt;
66
+ }
67
+ if (typeof document < "u") {
68
+ const o = (i) => document.querySelector(`meta[name="${i}"]`)?.getAttribute("content") || void 0;
69
+ t = t || o("ago-base-url"), g = g || o("ago-widget-id"), n = n || o("ago-agent") || o("ago-agent-id"), r = r || o("ago-permission"), a = a || o("ago-user-email");
70
+ }
71
+ if (typeof document < "u") {
72
+ const o = [document.body, ...Array.from(document.querySelectorAll("script[data-ago-base-url]"))].filter(Boolean);
73
+ for (const i of o)
74
+ i && (t = t || i.getAttribute("data-ago-base-url") || void 0, g = g || i.getAttribute("data-ago-widget-id") || void 0, n = n || i.getAttribute("data-ago-agent") || i.getAttribute("data-ago-agent-id") || void 0, r = r || i.getAttribute("data-ago-permission") || void 0, a = a || i.getAttribute("data-ago-user-email") || void 0);
75
+ }
76
+ t = e?.baseUrl || t, g = e?.widgetId || g, n = e?.agent || e?.defaultAgentId || n, r = e?.permission || r, a = e?.userEmail || a, u = e?.userJwt || u;
77
+ const f = e?.debug;
78
+ return t ? {
79
+ baseUrl: t,
80
+ widgetId: g,
81
+ agent: n,
82
+ permission: r,
83
+ userEmail: a,
84
+ userJwt: u,
85
+ debug: f
86
+ } : null;
172
87
  }
173
- //#endregion
174
- //#region src/auto/createAgo.ts
175
- /**
176
- * Auto-detect AGO configuration from the DOM environment.
177
- *
178
- * Checks (in order of priority):
179
- * 1. `window.AGO` global object (widget config)
180
- * 2. `<meta>` tags: `<meta name="ago-api-key" content="...">`
181
- * 3. `data-ago-*` attributes on `<body>` or `<script data-ago-api-key="...">`
182
- * 4. Explicit overrides passed as argument
183
- *
184
- * Returns null if no API key can be found.
185
- */
186
- function autoDetectConfig(overrides) {
187
- let baseUrl;
188
- let widgetId;
189
- let agent;
190
- let permission;
191
- let userEmail;
192
- let userJwt;
193
- if (typeof window !== "undefined" && window.AGO) {
194
- const ago = window.AGO;
195
- baseUrl = ago.basepath;
196
- widgetId = ago.widgetId;
197
- agent = ago.agent || ago.defaultAgent;
198
- permission = ago.permission;
199
- userEmail = ago.email;
200
- userJwt = ago.jwt;
201
- }
202
- if (typeof document !== "undefined") {
203
- const getMeta = (name) => document.querySelector(`meta[name="${name}"]`)?.getAttribute("content") || void 0;
204
- baseUrl = baseUrl || getMeta("ago-base-url");
205
- widgetId = widgetId || getMeta("ago-widget-id");
206
- agent = agent || getMeta("ago-agent") || getMeta("ago-agent-id");
207
- permission = permission || getMeta("ago-permission");
208
- userEmail = userEmail || getMeta("ago-user-email");
209
- }
210
- if (typeof document !== "undefined") {
211
- const sources = [document.body, ...Array.from(document.querySelectorAll("script[data-ago-base-url]"))].filter(Boolean);
212
- for (const el of sources) {
213
- if (!el) continue;
214
- baseUrl = baseUrl || el.getAttribute("data-ago-base-url") || void 0;
215
- widgetId = widgetId || el.getAttribute("data-ago-widget-id") || void 0;
216
- agent = agent || el.getAttribute("data-ago-agent") || el.getAttribute("data-ago-agent-id") || void 0;
217
- permission = permission || el.getAttribute("data-ago-permission") || void 0;
218
- userEmail = userEmail || el.getAttribute("data-ago-user-email") || void 0;
219
- }
220
- }
221
- baseUrl = overrides?.baseUrl || baseUrl;
222
- widgetId = overrides?.widgetId || widgetId;
223
- agent = overrides?.agent || overrides?.defaultAgentId || agent;
224
- permission = overrides?.permission || permission;
225
- userEmail = overrides?.userEmail || userEmail;
226
- userJwt = overrides?.userJwt || userJwt;
227
- const debug = overrides?.debug;
228
- if (!baseUrl) return null;
229
- return {
230
- baseUrl,
231
- widgetId,
232
- agent,
233
- permission,
234
- userEmail,
235
- userJwt,
236
- debug
237
- };
88
+ function _(e) {
89
+ const t = c(e);
90
+ if (!t) throw new Error('createAgo(): could not detect AGO configuration. Set window.AGO, add <meta name="ago-base-url">, or pass { baseUrl } explicitly.');
91
+ return new d(t);
238
92
  }
239
- /**
240
- * Create an AgoClient with zero configuration.
241
- * Auto-detects config from window.AGO, meta tags, and data-ago-* attributes.
242
- *
243
- * ```html
244
- * <!-- In your HTML -->
245
- * <meta name="ago-base-url" content="https://YOUR-DOMAIN.useago.com">
246
- *
247
- * <!-- Or on a script tag -->
248
- * <script src="app.js" data-ago-base-url="https://YOUR-DOMAIN.useago.com"><\/script>
249
- * ```
250
- *
251
- * ```ts
252
- * import { createAgo } from "@useago/sdk";
253
- *
254
- * // Zero config — picks up from DOM
255
- * const client = createAgo();
256
- *
257
- * // Or with partial overrides
258
- * const client = createAgo({ debug: true });
259
- * ```
260
- *
261
- * Throws if no base URL can be detected.
262
- */
263
- function createAgo(overrides) {
264
- const config = autoDetectConfig(overrides);
265
- if (!config) throw new Error("createAgo(): could not detect AGO configuration. Set window.AGO, add <meta name=\"ago-base-url\">, or pass { baseUrl } explicitly.");
266
- return new AgoClient(config);
93
+ function ee(e, t) {
94
+ return {
95
+ ...e,
96
+ handler: t
97
+ };
267
98
  }
268
- //#endregion
269
- //#region src/helpers/factory.ts
270
- /**
271
- * Attach a handler to a pre-built function definition.
272
- *
273
- * Pre-built helpers (`showToast`, `trackEvent`, ...) ship with a no-op or
274
- * console-logging default handler. Use `withHandler` to wire them up to
275
- * your actual implementation without mutating the original definition.
276
- *
277
- * ```ts
278
- * import { showToast, withHandler } from "@useago/sdk";
279
- *
280
- * client.register(
281
- * withHandler(showToast, (args) => {
282
- * myToast(args.message as string);
283
- * return { shown: true };
284
- * })
285
- * );
286
- * ```
287
- */
288
- function withHandler(definition, handler) {
289
- return {
290
- ...definition,
291
- handler
292
- };
293
- }
294
- //#endregion
295
- export { AgoApiError, AgoClient, AgoError, AgoFunctionError, AgoNetworkError, AgoStreamError, ClientContextRegistry, EventEmitter, FunctionRegistry, SSEHandler, autoDetectConfig, copyToClipboard, createAgo, createMessageStream, createMockClient, createStore, defineFunction, getLocalStorage, getUserLocation, highlightElement, isStreamNetworkError, logger, onFunctionInvoke, onMessage, onMessageChunk, onMessageError, onMessageStart, onToolCall, openUrl, scrollToElement, setLocalStorage, setTheme, showConfirmDialog, showNotification, showToast, submitForm, trackEvent, withHandler };
296
-
297
- //# sourceMappingURL=index.js.map
99
+ export {
100
+ h as AgoApiError,
101
+ d as AgoClient,
102
+ E as AgoError,
103
+ M as AgoFunctionError,
104
+ A as AgoNetworkError,
105
+ y as AgoStreamError,
106
+ w as ClientContextRegistry,
107
+ b as EventEmitter,
108
+ S as FunctionRegistry,
109
+ v as SSEHandler,
110
+ c as autoDetectConfig,
111
+ P as copyToClipboard,
112
+ _ as createAgo,
113
+ T as createFormCollector,
114
+ Z as createMessageStream,
115
+ U as createMockClient,
116
+ I as createStore,
117
+ z as defineFunction,
118
+ j as getLocalStorage,
119
+ N as getUserLocation,
120
+ O as highlightElement,
121
+ C as isStreamNetworkError,
122
+ k as logger,
123
+ Y as onFunctionInvoke,
124
+ K as onMessage,
125
+ Q as onMessageChunk,
126
+ W as onMessageError,
127
+ V as onMessageStart,
128
+ X as onToolCall,
129
+ J as openUrl,
130
+ B as scrollToElement,
131
+ q as setLocalStorage,
132
+ D as setTheme,
133
+ $ as showConfirmDialog,
134
+ x as showNotification,
135
+ L as showToast,
136
+ R as submitForm,
137
+ H as trackEvent,
138
+ ee as withHandler
139
+ };