@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/vue.js CHANGED
@@ -1,325 +1,183 @@
1
- import { t as AgoClient } from "./AgoClient-DPZdN5n2.js";
2
- import { computed, inject, onMounted, onScopeDispose, onUnmounted, ref, shallowRef } from "vue";
3
- //#region src/vue/symbols.ts
4
- var AGO_CLIENT_KEY = Symbol("ago-client");
5
- //#endregion
6
- //#region src/vue/plugin.ts
7
- /**
8
- * Vue plugin that provides an AgoClient to the entire app via inject/provide.
9
- *
10
- * ```ts
11
- * import { AgoPlugin } from "@useago/sdk/vue";
12
- *
13
- * app.use(AgoPlugin, { baseUrl: "https://YOUR-DOMAIN.useago.com" });
14
- * ```
15
- */
16
- var AgoPlugin = { install(app, options) {
17
- const client = new AgoClient(options);
18
- app.provide(AGO_CLIENT_KEY, client);
1
+ import { t as A } from "./AgoClient-DF7M2WAz.js";
2
+ import { computed as y, inject as F, onMounted as g, onScopeDispose as N, onUnmounted as I, ref as c, shallowRef as D } from "vue";
3
+ var L = /* @__PURE__ */ Symbol("ago-client"), b = { install(t, n) {
4
+ const e = new A(n);
5
+ t.provide(L, e);
19
6
  } };
20
- //#endregion
21
- //#region src/vue/composables/useAgo.ts
22
- /**
23
- * Get or create an AgoClient.
24
- *
25
- * - Without args: returns the client from `AgoPlugin` (throws if none).
26
- * - With config: creates a new client instance.
27
- *
28
- * ```ts
29
- * // From plugin
30
- * const client = useAgo();
31
- *
32
- * // Standalone
33
- * const client = useAgo({ baseUrl: "https://YOUR-DOMAIN.useago.com" });
34
- * ```
35
- */
36
- function useAgo(config) {
37
- if (config) return new AgoClient(config);
38
- const client = inject(AGO_CLIENT_KEY);
39
- if (!client) throw new Error("useAgo(): no AgoClient found. Either pass config or install AgoPlugin.");
40
- return client;
7
+ function m(t) {
8
+ if (t) return new A(t);
9
+ const n = F(L);
10
+ if (!n) throw new Error("useAgo(): no AgoClient found. Either pass config or install AgoPlugin.");
11
+ return n;
41
12
  }
42
- //#endregion
43
- //#region src/vue/composables/useMessages.ts
44
- /**
45
- * Composable to manage messages in a conversation.
46
- *
47
- * ```ts
48
- * const { messages, sendMessage, isLoading } = useMessages();
49
- * ```
50
- */
51
- function useMessages(options = {}) {
52
- const client = options.client ?? useAgo();
53
- const messages = ref([]);
54
- const conversationId = ref(options.conversationId);
55
- const isLoading = ref(false);
56
- const error = ref(null);
57
- const handleStart = (data) => {
58
- if (!conversationId.value) conversationId.value = data.conversationId;
59
- };
60
- const handleChunk = (data) => {
61
- const idx = messages.value.findIndex((m) => m.id === data.messageId);
62
- if (idx >= 0) messages.value[idx] = {
63
- ...messages.value[idx],
64
- content: messages.value[idx].content + data.content
65
- };
66
- };
67
- const handleComplete = (message) => {
68
- const idx = messages.value.findIndex((m) => m.id === message.id);
69
- if (idx >= 0) messages.value[idx] = message;
70
- else messages.value.push(message);
71
- isLoading.value = false;
72
- };
73
- const handleError = (data) => {
74
- error.value = new Error(data.error);
75
- isLoading.value = false;
76
- };
77
- onMounted(() => {
78
- client.on("message:start", handleStart);
79
- client.on("message:chunk", handleChunk);
80
- client.on("message:complete", handleComplete);
81
- client.on("message:error", handleError);
82
- });
83
- onUnmounted(() => {
84
- client.off("message:start", handleStart);
85
- client.off("message:chunk", handleChunk);
86
- client.off("message:complete", handleComplete);
87
- client.off("message:error", handleError);
88
- });
89
- async function sendMessage(content, files) {
90
- isLoading.value = true;
91
- error.value = null;
92
- const userMsg = {
93
- id: `temp-${Date.now()}`,
94
- conversationId: conversationId.value || "",
95
- content,
96
- role: "user",
97
- status: "DONE",
98
- createdAt: /* @__PURE__ */ new Date()
99
- };
100
- const assistantMsg = {
101
- id: `temp-assistant-${Date.now()}`,
102
- conversationId: conversationId.value || "",
103
- content: "",
104
- role: "assistant",
105
- status: "IN_PROGRESS",
106
- createdAt: /* @__PURE__ */ new Date()
107
- };
108
- messages.value.push(userMsg, assistantMsg);
109
- try {
110
- const response = await client.sendMessage(content, {
111
- conversationId: conversationId.value,
112
- files
113
- });
114
- if (response.conversationId && !conversationId.value) conversationId.value = response.conversationId;
115
- messages.value = messages.value.filter((m) => !m.id.startsWith("temp-"));
116
- const updatedUser = {
117
- ...userMsg,
118
- id: userMsg.id.replace("temp-", "user-"),
119
- conversationId: response.conversationId
120
- };
121
- if (!messages.value.some((m) => m.id === response.id)) messages.value.push(updatedUser, response);
122
- else messages.value.push(updatedUser);
123
- return response;
124
- } catch (err) {
125
- error.value = err instanceof Error ? err : /* @__PURE__ */ new Error("Failed to send");
126
- isLoading.value = false;
127
- messages.value = messages.value.filter((m) => !m.id.startsWith("temp-"));
128
- return null;
129
- }
130
- }
131
- function clearMessages() {
132
- messages.value = [];
133
- conversationId.value = void 0;
134
- error.value = null;
135
- }
136
- return {
137
- messages,
138
- isLoading,
139
- error,
140
- conversationId,
141
- sendMessage,
142
- clearMessages
143
- };
13
+ function S(t = {}) {
14
+ const n = t.client ?? m(), e = c([]), s = c(t.conversationId), r = c(!1), a = c(null), u = (o) => {
15
+ s.value || (s.value = o.conversationId);
16
+ }, f = (o) => {
17
+ const i = e.value.findIndex((v) => v.id === o.messageId);
18
+ i >= 0 && (e.value[i] = {
19
+ ...e.value[i],
20
+ content: e.value[i].content + o.content
21
+ });
22
+ }, h = (o) => {
23
+ const i = e.value.findIndex((v) => v.id === o.id);
24
+ i >= 0 ? e.value[i] = o : e.value.push(o), r.value = !1;
25
+ }, C = (o) => {
26
+ a.value = new Error(o.error), r.value = !1;
27
+ };
28
+ g(() => {
29
+ n.on("message:start", u), n.on("message:chunk", f), n.on("message:complete", h), n.on("message:error", C);
30
+ }), I(() => {
31
+ n.off("message:start", u), n.off("message:chunk", f), n.off("message:complete", h), n.off("message:error", C);
32
+ });
33
+ async function d(o, i) {
34
+ r.value = !0, a.value = null;
35
+ const v = {
36
+ id: `temp-${Date.now()}`,
37
+ conversationId: s.value || "",
38
+ content: o,
39
+ role: "user",
40
+ status: "DONE",
41
+ createdAt: /* @__PURE__ */ new Date()
42
+ }, M = {
43
+ id: `temp-assistant-${Date.now()}`,
44
+ conversationId: s.value || "",
45
+ content: "",
46
+ role: "assistant",
47
+ status: "IN_PROGRESS",
48
+ createdAt: /* @__PURE__ */ new Date()
49
+ };
50
+ e.value.push(v, M);
51
+ try {
52
+ const l = await n.sendMessage(o, {
53
+ conversationId: s.value,
54
+ files: i
55
+ });
56
+ l.conversationId && !s.value && (s.value = l.conversationId), e.value = e.value.filter((E) => !E.id.startsWith("temp-"));
57
+ const w = {
58
+ ...v,
59
+ id: v.id.replace("temp-", "user-"),
60
+ conversationId: l.conversationId
61
+ };
62
+ return e.value.some((E) => E.id === l.id) ? e.value.push(w) : e.value.push(w, l), l;
63
+ } catch (l) {
64
+ return a.value = l instanceof Error ? l : /* @__PURE__ */ new Error("Failed to send"), r.value = !1, e.value = e.value.filter((w) => !w.id.startsWith("temp-")), null;
65
+ }
66
+ }
67
+ function p() {
68
+ e.value = [], s.value = void 0, a.value = null;
69
+ }
70
+ return {
71
+ messages: e,
72
+ isLoading: r,
73
+ error: a,
74
+ conversationId: s,
75
+ sendMessage: d,
76
+ clearMessages: p
77
+ };
144
78
  }
145
- //#endregion
146
- //#region src/vue/composables/useConversation.ts
147
- /**
148
- * Composable to manage conversations.
149
- *
150
- * ```ts
151
- * const { conversations, selectConversation } = useConversation();
152
- * ```
153
- */
154
- function useConversation(options = {}) {
155
- const client = options.client ?? useAgo();
156
- const autoLoad = options.autoLoad ?? true;
157
- const conversations = ref([]);
158
- const currentConversation = ref(null);
159
- const isLoading = ref(false);
160
- const error = ref(null);
161
- async function refreshConversations() {
162
- isLoading.value = true;
163
- error.value = null;
164
- try {
165
- conversations.value = await client.getConversations();
166
- } catch (err) {
167
- error.value = err instanceof Error ? err : /* @__PURE__ */ new Error("Failed to load conversations");
168
- } finally {
169
- isLoading.value = false;
170
- }
171
- }
172
- async function selectConversation(id) {
173
- isLoading.value = true;
174
- error.value = null;
175
- try {
176
- currentConversation.value = await client.getConversation(id);
177
- } catch (err) {
178
- error.value = err instanceof Error ? err : /* @__PURE__ */ new Error("Failed to load conversation");
179
- } finally {
180
- isLoading.value = false;
181
- }
182
- }
183
- function startNewConversation() {
184
- currentConversation.value = null;
185
- }
186
- onMounted(() => {
187
- if (autoLoad) refreshConversations();
188
- });
189
- return {
190
- conversations,
191
- currentConversation,
192
- isLoading,
193
- error,
194
- selectConversation,
195
- startNewConversation,
196
- refreshConversations
197
- };
79
+ function x(t = {}) {
80
+ const n = t.client ?? m(), e = t.autoLoad ?? !0, s = c([]), r = c(null), a = c(!1), u = c(null);
81
+ async function f() {
82
+ a.value = !0, u.value = null;
83
+ try {
84
+ s.value = await n.getConversations();
85
+ } catch (d) {
86
+ u.value = d instanceof Error ? d : /* @__PURE__ */ new Error("Failed to load conversations");
87
+ } finally {
88
+ a.value = !1;
89
+ }
90
+ }
91
+ async function h(d) {
92
+ a.value = !0, u.value = null;
93
+ try {
94
+ r.value = await n.getConversation(d);
95
+ } catch (p) {
96
+ u.value = p instanceof Error ? p : /* @__PURE__ */ new Error("Failed to load conversation");
97
+ } finally {
98
+ a.value = !1;
99
+ }
100
+ }
101
+ function C() {
102
+ r.value = null;
103
+ }
104
+ return g(() => {
105
+ e && f();
106
+ }), {
107
+ conversations: s,
108
+ currentConversation: r,
109
+ isLoading: a,
110
+ error: u,
111
+ selectConversation: h,
112
+ startNewConversation: C,
113
+ refreshConversations: f
114
+ };
198
115
  }
199
- //#endregion
200
- //#region src/vue/composables/useChat.ts
201
- /**
202
- * All-in-one composable combining messages + conversations.
203
- *
204
- * ```ts
205
- * const { messages, sendMessage, conversations, selectConversation } = useChat();
206
- * ```
207
- */
208
- function useChat(options = {}) {
209
- const msgResult = useMessages({
210
- client: options.client,
211
- conversationId: options.conversationId
212
- });
213
- const convResult = useConversation({
214
- client: options.client,
215
- autoLoad: options.autoLoad
216
- });
217
- const error = computed(() => msgResult.error.value || convResult.error.value);
218
- return {
219
- messages: msgResult.messages,
220
- isLoading: msgResult.isLoading,
221
- error,
222
- sendMessage: msgResult.sendMessage,
223
- clearMessages: msgResult.clearMessages,
224
- conversationId: msgResult.conversationId,
225
- conversations: convResult.conversations,
226
- currentConversation: convResult.currentConversation,
227
- isConversationsLoading: convResult.isLoading,
228
- selectConversation: convResult.selectConversation,
229
- startNewConversation: convResult.startNewConversation,
230
- refreshConversations: convResult.refreshConversations
231
- };
116
+ function k(t = {}) {
117
+ const n = S({
118
+ client: t.client,
119
+ conversationId: t.conversationId
120
+ }), e = x({
121
+ client: t.client,
122
+ autoLoad: t.autoLoad
123
+ }), s = y(() => n.error.value || e.error.value);
124
+ return {
125
+ messages: n.messages,
126
+ isLoading: n.isLoading,
127
+ error: s,
128
+ sendMessage: n.sendMessage,
129
+ clearMessages: n.clearMessages,
130
+ conversationId: n.conversationId,
131
+ conversations: e.conversations,
132
+ currentConversation: e.currentConversation,
133
+ isConversationsLoading: e.isLoading,
134
+ selectConversation: e.selectConversation,
135
+ startNewConversation: e.startNewConversation,
136
+ refreshConversations: e.refreshConversations
137
+ };
232
138
  }
233
- //#endregion
234
- //#region src/vue/composables/useAgoFunction.ts
235
- /**
236
- * Register a client-side function with auto-cleanup on unmount.
237
- *
238
- * ```ts
239
- * useAgoFunction("showToast", {
240
- * description: "Show a toast",
241
- * parameters: { type: "object", properties: { message: { type: "string" } } },
242
- * handler: async (args) => { toast(args.message); return { shown: true }; },
243
- * });
244
- * ```
245
- */
246
- function useAgoFunction(name, options) {
247
- const client = useAgo();
248
- onMounted(() => {
249
- client.registerFunction(name, options.handler, {
250
- description: options.description,
251
- parameters: options.parameters
252
- });
253
- });
254
- onUnmounted(() => {
255
- client.unregisterFunction(name);
256
- });
139
+ function O(t, n) {
140
+ const e = m();
141
+ g(() => {
142
+ e.registerFunction(t, n.handler, {
143
+ description: n.description,
144
+ parameters: n.parameters
145
+ });
146
+ }), I(() => {
147
+ e.unregisterFunction(t);
148
+ });
257
149
  }
258
- /**
259
- * Register navigation routes with auto-cleanup on unmount.
260
- * Works with vue-router's `useRouter().push`.
261
- *
262
- * ```ts
263
- * const router = useRouter();
264
- * useAgoNavigation((path) => router.push(path), [
265
- * { name: "dashboard", path: "/dashboard", description: "Main dashboard" },
266
- * ]);
267
- * ```
268
- */
269
- function useAgoNavigation(navigate, routes) {
270
- const client = useAgo();
271
- onMounted(() => {
272
- client.registerNavigationFunction(navigate, routes);
273
- });
274
- onUnmounted(() => {
275
- client.unregisterFunction("navigateToPage");
276
- });
150
+ function _(t, n) {
151
+ const e = m();
152
+ g(() => {
153
+ e.registerNavigationFunction(t, n);
154
+ }), I(() => {
155
+ e.unregisterFunction("navigateToPage");
156
+ });
277
157
  }
278
- //#endregion
279
- //#region src/vue/composables/useAgoEvents.ts
280
- /**
281
- * Subscribe to AGO client events with auto-cleanup on unmount.
282
- *
283
- * ```ts
284
- * useAgoEvents("message:complete", (msg) => {
285
- * console.log("Got message:", msg.content);
286
- * });
287
- * ```
288
- */
289
- function useAgoEvents(event, handler) {
290
- const client = useAgo();
291
- onMounted(() => {
292
- client.on(event, handler);
293
- });
294
- onUnmounted(() => {
295
- client.off(event, handler);
296
- });
158
+ function G(t, n) {
159
+ const e = m();
160
+ g(() => {
161
+ e.on(t, n);
162
+ }), I(() => {
163
+ e.off(t, n);
164
+ });
297
165
  }
298
- //#endregion
299
- //#region src/vue/composables/useAgoStore.ts
300
- /**
301
- * Read a framework-agnostic AGO store (`createStore`) as a reactive Vue ref.
302
- *
303
- * The ref's `.value` updates on every `store.set(...)`. Mutate through the store,
304
- * not the ref. A `shallowRef` is used because the store replaces its value
305
- * wholesale, so deep reactivity would be wasted work.
306
- *
307
- * ```ts
308
- * const cart = createStore({ items: [] as string[] });
309
- *
310
- * // in setup():
311
- * const state = useAgoStore(cart);
312
- * // template: {{ state.items.length }}
313
- * ```
314
- */
315
- function useAgoStore(store) {
316
- const state = shallowRef(store.get());
317
- onScopeDispose(store.subscribe((next) => {
318
- state.value = next;
319
- }));
320
- return state;
166
+ function T(t) {
167
+ const n = D(t.get());
168
+ return N(t.subscribe((e) => {
169
+ n.value = e;
170
+ })), n;
321
171
  }
322
- //#endregion
323
- export { AGO_CLIENT_KEY, AgoPlugin, useAgo, useAgoEvents, useAgoFunction, useAgoNavigation, useAgoStore, useChat, useConversation, useMessages };
324
-
325
- //# sourceMappingURL=vue.js.map
172
+ export {
173
+ L as AGO_CLIENT_KEY,
174
+ b as AgoPlugin,
175
+ m as useAgo,
176
+ G as useAgoEvents,
177
+ O as useAgoFunction,
178
+ _ as useAgoNavigation,
179
+ T as useAgoStore,
180
+ k as useChat,
181
+ x as useConversation,
182
+ S as useMessages
183
+ };
package/dist/widget.cjs CHANGED
@@ -0,0 +1 @@
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const X=require("./AgoClient-bjN-z2ZQ.cjs"),Z=require("./createFormCollector-H4Me_2uj.cjs");var q='"IBM Plex Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif';function x(s,o){Object.assign(s.style,o)}function c(s={}){const o=document.createElement("div");return x(o,s),o}var P="ago-chat-widget-keyframes";function ee(){if(typeof document>"u"||document.getElementById(P))return;const s=document.createElement("style");s.id=P,s.textContent="@keyframes ago-pulse { 0%, 80%, 100% { opacity: 0.3; transform: scale(0.8); } 40% { opacity: 1; transform: scale(1); } }",document.head.appendChild(s)}function te(s){const o=typeof s=="string"?document.querySelector(s):s;if(!o)throw new Error(`mountChatWidget: target "${String(s)}" not found.`);return o}function ne(s,o){const{title:y="Chat",welcomeMessage:I="Hello! How can I help you today?",placeholder:R="Type a message...",allowFiles:u=!1,height:g=500,logoUrl:f,showAgentName:b=!1,forms:_,onFollowUpClick:k,onMessageSent:D,onMessageReceived:l}=o;if(!o.client&&!o.config?.baseUrl)throw new Error("mountChatWidget requires either `client` or `config` (with a baseUrl).");const i=o.client??new X.AgoClient(o.config),W=te(s);let m=o.conversationId,n=[],w=!1,v=null;const N=c({display:"flex",flexDirection:"column",height:typeof g=="number"?`${g}px`:g,border:"1px solid #dee3e8",borderRadius:"16px",overflow:"hidden",backgroundColor:"#fff",fontFamily:q,boxShadow:"rgba(15, 15, 15, 0.08) 0px 2px 16px 0px"});N.className="ago-chat-widget";const z=c({padding:"14px 16px",borderBottom:"1px solid #dee3e8",backgroundColor:"#03182f",color:"#e8f0fe",display:"flex",alignItems:"center",gap:"10px"});if(z.className="ago-chat-widget__header",f){const e=document.createElement("img");e.src=f,e.alt="Logo",x(e,{height:"24px",width:"auto"}),z.appendChild(e)}const F=document.createElement("h3");F.textContent=y,x(F,{margin:"0",fontSize:"15px",fontWeight:"600"}),z.appendChild(F);const E=c({flex:"1",overflow:"auto",padding:"16px",backgroundColor:"#fbfbfb"});E.className="ago-chat-widget__messages";const{inputRow:G,setDisabled:j,focus:K}=oe({placeholder:R,allowFiles:u,onSend:(e,t)=>{M(e,t)}});ee(),N.append(z,E,G),W.appendChild(N);const A=k!==!1,U=k===!1?void 0:k??(e=>{M(e)});function V(e){const t=e.role==="user",d=c({display:"flex",flexDirection:"column",alignItems:t?"flex-end":"flex-start",marginBottom:"16px"});if(d.className=`ago-message ago-message--${e.role}`,!t&&b&&e.agent){const a=c({fontSize:"13px",fontWeight:"500",color:"#30373e",marginBottom:"6px",padding:"0 4px"});a.className="ago-message__agent",a.textContent=e.agent.displayName||e.agent.name,d.appendChild(a)}if(!t&&e.sources&&e.sources.length>0){const a=c({display:"grid",gridTemplateColumns:"1fr 1fr",gap:"6px",marginBottom:"10px",width:"100%",maxWidth:"85%"});a.className="ago-message__sources",e.sources.forEach((p,r)=>{const C=p.url?document.createElement("a"):document.createElement("div");p.url&&C instanceof HTMLAnchorElement&&(C.href=p.url,C.target="_blank",C.rel="noopener noreferrer"),x(C,{display:"flex",alignItems:"center",gap:"8px",padding:"8px 10px",border:"1px solid #dee3e8",borderRadius:"8px",backgroundColor:"#fff",textDecoration:"none",color:"#30373e",fontSize:"12px",overflow:"hidden"});const $=c({flexShrink:"0",width:"18px",height:"18px",borderRadius:"3px",border:"1px solid #1b5fc4",color:"#1b5fc4",fontSize:"11px",fontWeight:"500",display:"flex",alignItems:"center",justifyContent:"center",backgroundColor:"#f0f4ff"});$.textContent=String(r+1);const L=c({overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"});L.textContent=p.title,L.title=p.title,C.append($,L),a.appendChild(C)}),d.appendChild(a)}const h=c({maxWidth:t?"75%":"100%",padding:t?"10px 14px":"2px 8px",borderRadius:t?"16px":"0",backgroundColor:t?"#03182f":"transparent",color:t?"#fff":"#30373e",wordBreak:"break-word",fontSize:"14px",lineHeight:"1.6",whiteSpace:"pre-wrap"});if(h.className="ago-message__content",e.content?h.textContent=e.content:e.status==="IN_PROGRESS"&&h.appendChild(Q()),d.appendChild(h),e.followUpReplies&&e.followUpReplies.length>0){const a=c({display:"flex",flexWrap:"wrap",gap:"8px",marginTop:"10px"});a.className="ago-message__followups";for(const p of e.followUpReplies){const r=document.createElement("button");r.type="button",r.className="ago-message__followup-btn",r.textContent=p,r.disabled=!A,x(r,{padding:"6px 14px",fontSize:"13px",borderRadius:"16px",border:"1px solid #dee3e8",backgroundColor:"#fff",color:"#30373e",cursor:A?"pointer":"default",transition:"border-color 0.15s"}),U&&r.addEventListener("click",()=>U(p)),r.addEventListener("mouseenter",()=>{r.style.borderColor="#1b5fc4"}),r.addEventListener("mouseleave",()=>{r.style.borderColor="#dee3e8"}),a.appendChild(r)}d.appendChild(a)}return d}function S(){if(E.replaceChildren(),n.length===0){const e=c({textAlign:"center",color:"#6b6d6f",padding:"24px 16px",fontSize:"14px",lineHeight:"1.5"});e.textContent=I,E.appendChild(e)}else for(const e of n)E.appendChild(V(e));if(v){const e=c({padding:"10px 14px",backgroundColor:"#fef2f2",color:"#dc2626",borderRadius:"12px",marginTop:"8px",fontSize:"13px",border:"1px solid #fecaca"});e.textContent=v,E.appendChild(e)}E.scrollTop=E.scrollHeight,j(w)}function Y(){for(let e=n.length-1;e>=0;e--){const t=n[e];if(t.role==="assistant"&&t.status==="IN_PROGRESS")return t}}const B=e=>{m||(m=e.conversationId)},H=e=>{const t=Y();t&&(t.content+=e.content,S())},O=e=>{const t=n.findIndex(d=>d.id===e.id||d.role==="assistant"&&d.status==="IN_PROGRESS");t>=0?n[t]=e:n.push(e),w=!1,S(),e.status==="DONE"&&l?.({id:e.id,content:e.content})},T=e=>{v=e.error,w=!1,n=n.filter(t=>!t.id.startsWith("temp-")),S()};i.on("message:start",B),i.on("message:chunk",H),i.on("message:complete",O),i.on("message:error",T);const J=(_??[]).map(e=>Z.createFormCollector(e).install(i));async function M(e,t){const d=e.trim();if(!d&&!t?.length||w)return;D?.(d),w=!0,v=null;const h=Date.now();n.push({id:`temp-user-${h}`,conversationId:m||"",content:d,role:"user",status:"DONE",createdAt:new Date}),n.push({id:`temp-assistant-${h}`,conversationId:m||"",content:"",role:"assistant",status:"IN_PROGRESS",createdAt:new Date}),S();try{const a=await i.sendMessage(d,{conversationId:m,files:t});a.conversationId&&!m&&(m=a.conversationId);const p=n.find(r=>r.id===`temp-user-${h}`);if(p&&(p.id=`user-${h}`,p.conversationId=a.conversationId),!n.some(r=>r.id===a.id)){const r=n.findIndex(C=>C.id===`temp-assistant-${h}`);r>=0?n[r]=a:n.push(a)}n=n.filter(r=>!r.id.startsWith("temp-")),w=!1,S()}catch(a){v=a instanceof Error?a.message:"Failed to send message",w=!1,n=n.filter(p=>!p.id.startsWith("temp-")),S()}}return S(),K(),{client:i,element:N,sendMessage:M,destroy(){i.off("message:start",B),i.off("message:chunk",H),i.off("message:complete",O),i.off("message:error",T),J.forEach(e=>e()),N.remove(),o.client||i.destroy()}};function Q(){const e=c({display:"flex",gap:"4px",padding:"4px 0"});for(let t=0;t<3;t++){const d=c({width:"6px",height:"6px",borderRadius:"50%",backgroundColor:"#b5bfc8",animation:"ago-pulse 1.2s ease-in-out infinite",animationDelay:`${t*.2}s`});e.appendChild(d)}return e}}function oe(s){let o=[];const y=document.createElement("form");x(y,{display:"flex",flexDirection:"column",gap:"8px",padding:"12px",borderTop:"1px solid #dee3e8",backgroundColor:"#fff"}),y.className="ago-chat-input";const I=c({display:"flex",flexWrap:"wrap",gap:"6px"}),R=c({display:"flex",gap:"8px",alignItems:"flex-end"}),u=document.createElement("textarea");u.placeholder=s.placeholder,u.rows=1,x(u,{flex:"1",resize:"none",padding:"10px 12px",border:"1px solid #dee3e8",borderRadius:"12px",fontSize:"14px",fontFamily:q,lineHeight:"1.4",maxHeight:"120px",outline:"none"});const g=document.createElement("button");g.type="submit",g.textContent="Send",x(g,{padding:"10px 16px",border:"none",borderRadius:"12px",backgroundColor:"#03182f",color:"#fff",fontSize:"14px",fontWeight:"500",cursor:"pointer"});let f=null,b=null;s.allowFiles&&(f=document.createElement("input"),f.type="file",f.multiple=!0,x(f,{display:"none"}),b=document.createElement("button"),b.type="button",b.textContent="📎",x(b,{padding:"10px 12px",border:"1px solid #dee3e8",borderRadius:"12px",backgroundColor:"#fff",cursor:"pointer",fontSize:"14px"}),b.addEventListener("click",()=>f?.click()),f.addEventListener("change",()=>{o=[...o,...Array.from(f?.files??[])],_()}));function _(){I.replaceChildren(),o.forEach((l,i)=>{const W=c({display:"flex",alignItems:"center",gap:"4px",padding:"4px 8px",backgroundColor:"#f0f4ff",border:"1px solid #dee3e8",borderRadius:"8px",fontSize:"12px"}),m=document.createElement("span");m.textContent=l.name;const n=document.createElement("button");n.type="button",n.textContent="×",x(n,{border:"none",background:"transparent",cursor:"pointer",fontSize:"14px",lineHeight:"1"}),n.addEventListener("click",()=>{o=o.filter((w,v)=>v!==i),_()}),W.append(m,n),I.appendChild(W)})}const k=()=>{const l=u.value,i=o;return u.value="",o=[],_(),{content:l,files:i}},D=()=>{const{content:l,files:i}=k();(l.trim()||i.length>0)&&s.onSend(l.trim(),i.length>0?i:void 0)};return y.addEventListener("submit",l=>{l.preventDefault(),D()}),u.addEventListener("keydown",l=>{l.key==="Enter"&&!l.shiftKey&&(l.preventDefault(),D())}),b&&R.appendChild(b),R.append(u,g),f&&y.appendChild(f),y.append(I,R),{inputRow:y,getValueAndClear:k,setDisabled:l=>{u.disabled=l,g.disabled=l,g.style.opacity=l?"0.6":"1",g.style.cursor=l?"not-allowed":"pointer"},focus:()=>u.focus()}}exports.mountChatWidget=ne;