@useago/sdk 0.1.6 → 0.2.0

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 (79) hide show
  1. package/dist/AgoClient-CNT-8sh_.js +905 -0
  2. package/dist/AgoClient-CNT-8sh_.js.map +1 -0
  3. package/dist/AgoClient-D0l1GTRs.cjs +976 -0
  4. package/dist/AgoClient-D0l1GTRs.cjs.map +1 -0
  5. package/dist/angular/ago.service.d.ts +98 -0
  6. package/dist/angular/index.d.ts +4 -0
  7. package/dist/angular/provide.d.ts +27 -0
  8. package/dist/angular.cjs +143 -0
  9. package/dist/angular.cjs.map +1 -0
  10. package/dist/angular.d.ts +2 -0
  11. package/dist/angular.js +141 -0
  12. package/dist/angular.js.map +1 -0
  13. package/dist/auto/createAgo.d.ts +39 -0
  14. package/dist/auto/index.d.ts +1 -0
  15. package/dist/client/AgoClient.d.ts +56 -0
  16. package/dist/client/types.d.ts +9 -7
  17. package/dist/createMockClient-Ci_N2tH8.cjs +104 -0
  18. package/dist/createMockClient-Ci_N2tH8.cjs.map +1 -0
  19. package/dist/createMockClient-U0ae_AYy.js +99 -0
  20. package/dist/createMockClient-U0ae_AYy.js.map +1 -0
  21. package/dist/functions--c6lx3ic.cjs +480 -0
  22. package/dist/functions--c6lx3ic.cjs.map +1 -0
  23. package/dist/functions-C9F1dnmh.js +398 -0
  24. package/dist/functions-C9F1dnmh.js.map +1 -0
  25. package/dist/helpers/factory.d.ts +20 -0
  26. package/dist/helpers/functions.d.ts +62 -0
  27. package/dist/helpers/index.d.ts +1 -0
  28. package/dist/helpers.cjs +15 -0
  29. package/dist/helpers.d.ts +2 -0
  30. package/dist/helpers.js +2 -0
  31. package/dist/index.cjs +312 -17
  32. package/dist/index.cjs.map +1 -1
  33. package/dist/index.d.ts +6 -0
  34. package/dist/index.js +277 -19
  35. package/dist/index.js.map +1 -1
  36. package/dist/react/components/ChatWidget.d.ts +2 -0
  37. package/dist/react/components/Markdown.d.ts +12 -0
  38. package/dist/react/components/Message.d.ts +2 -0
  39. package/dist/react/components/index.d.ts +2 -0
  40. package/dist/react/context/AgoContext.d.ts +30 -4
  41. package/dist/react/context/index.d.ts +1 -1
  42. package/dist/react/hooks/index.d.ts +1 -0
  43. package/dist/react/hooks/useAgoContext.d.ts +40 -0
  44. package/dist/react/hooks/useAgoFunction.d.ts +14 -2
  45. package/dist/react/index.d.ts +4 -1
  46. package/dist/react.cjs +22104 -10273
  47. package/dist/react.cjs.map +1 -1
  48. package/dist/react.d.ts +1 -0
  49. package/dist/react.js +22103 -10289
  50. package/dist/react.js.map +1 -1
  51. package/dist/rolldown-runtime-BqCkTl7Q.cjs +50 -0
  52. package/dist/rolldown-runtime-CNZpIYwj.js +33 -0
  53. package/dist/state/ClientContextRegistry.d.ts +64 -0
  54. package/dist/streaming/helpers.d.ts +67 -0
  55. package/dist/vue/composables/useAgo.d.ts +17 -0
  56. package/dist/vue/composables/useAgoEvents.d.ts +11 -0
  57. package/dist/vue/composables/useAgoFunction.d.ts +34 -0
  58. package/dist/vue/composables/useChat.d.ts +251 -0
  59. package/dist/vue/composables/useConversation.d.ts +178 -0
  60. package/dist/vue/composables/useMessages.d.ts +89 -0
  61. package/dist/vue/index.d.ts +10 -0
  62. package/dist/vue/plugin.d.ts +16 -0
  63. package/dist/vue/symbols.d.ts +3 -0
  64. package/dist/vue.cjs +311 -0
  65. package/dist/vue.cjs.map +1 -0
  66. package/dist/vue.d.ts +2 -0
  67. package/dist/vue.js +301 -0
  68. package/dist/vue.js.map +1 -0
  69. package/dist/widget/types.d.ts +1 -0
  70. package/dist/widget.cjs +0 -2
  71. package/dist/widget.d.ts +1 -0
  72. package/dist/widget.js +0 -2
  73. package/package.json +29 -7
  74. package/dist/createMockClient-BZKh_1em.cjs +0 -941
  75. package/dist/createMockClient-BZKh_1em.cjs.map +0 -1
  76. package/dist/createMockClient-uGlVyjbL.js +0 -942
  77. package/dist/createMockClient-uGlVyjbL.js.map +0 -1
  78. package/dist/widget.cjs.map +0 -1
  79. package/dist/widget.js.map +0 -1
@@ -0,0 +1,178 @@
1
+ import type { AgoClient } from "../../client/AgoClient";
2
+ import type { Conversation } from "../../client/types";
3
+ export interface UseConversationOptions {
4
+ client?: AgoClient;
5
+ autoLoad?: boolean;
6
+ }
7
+ /**
8
+ * Composable to manage conversations.
9
+ *
10
+ * ```ts
11
+ * const { conversations, selectConversation } = useConversation();
12
+ * ```
13
+ */
14
+ export declare function useConversation(options?: UseConversationOptions): {
15
+ conversations: import("vue").Ref<{
16
+ id: string;
17
+ title: string;
18
+ lastMessageDate: Date;
19
+ messages?: {
20
+ id: string;
21
+ conversationId: string;
22
+ content: string;
23
+ role: "user" | "assistant";
24
+ status: import("../..").MessageStatus;
25
+ agent?: {
26
+ id: string;
27
+ name: string;
28
+ displayName?: string | undefined;
29
+ } | undefined;
30
+ sources?: {
31
+ id: string;
32
+ title: string;
33
+ url?: string | undefined;
34
+ }[] | undefined;
35
+ toolCalls?: {
36
+ id: string;
37
+ type: import("../..").ToolCallType;
38
+ status: string;
39
+ toolName: string;
40
+ toolDisplayName?: string | undefined;
41
+ message?: string | undefined;
42
+ formSchema?: {
43
+ type: "object";
44
+ properties: Record<string, import("../..").FormField>;
45
+ required?: string[] | undefined;
46
+ } | undefined;
47
+ data?: Record<string, unknown> | undefined;
48
+ functionName?: string | undefined;
49
+ arguments?: Record<string, unknown> | undefined;
50
+ }[] | undefined;
51
+ followUpReplies?: string[] | undefined;
52
+ createdAt: Date;
53
+ }[] | undefined;
54
+ }[], Conversation[] | {
55
+ id: string;
56
+ title: string;
57
+ lastMessageDate: Date;
58
+ messages?: {
59
+ id: string;
60
+ conversationId: string;
61
+ content: string;
62
+ role: "user" | "assistant";
63
+ status: import("../..").MessageStatus;
64
+ agent?: {
65
+ id: string;
66
+ name: string;
67
+ displayName?: string | undefined;
68
+ } | undefined;
69
+ sources?: {
70
+ id: string;
71
+ title: string;
72
+ url?: string | undefined;
73
+ }[] | undefined;
74
+ toolCalls?: {
75
+ id: string;
76
+ type: import("../..").ToolCallType;
77
+ status: string;
78
+ toolName: string;
79
+ toolDisplayName?: string | undefined;
80
+ message?: string | undefined;
81
+ formSchema?: {
82
+ type: "object";
83
+ properties: Record<string, import("../..").FormField>;
84
+ required?: string[] | undefined;
85
+ } | undefined;
86
+ data?: Record<string, unknown> | undefined;
87
+ functionName?: string | undefined;
88
+ arguments?: Record<string, unknown> | undefined;
89
+ }[] | undefined;
90
+ followUpReplies?: string[] | undefined;
91
+ createdAt: Date;
92
+ }[] | undefined;
93
+ }[]>;
94
+ currentConversation: import("vue").Ref<{
95
+ id: string;
96
+ title: string;
97
+ lastMessageDate: Date;
98
+ messages?: {
99
+ id: string;
100
+ conversationId: string;
101
+ content: string;
102
+ role: "user" | "assistant";
103
+ status: import("../..").MessageStatus;
104
+ agent?: {
105
+ id: string;
106
+ name: string;
107
+ displayName?: string | undefined;
108
+ } | undefined;
109
+ sources?: {
110
+ id: string;
111
+ title: string;
112
+ url?: string | undefined;
113
+ }[] | undefined;
114
+ toolCalls?: {
115
+ id: string;
116
+ type: import("../..").ToolCallType;
117
+ status: string;
118
+ toolName: string;
119
+ toolDisplayName?: string | undefined;
120
+ message?: string | undefined;
121
+ formSchema?: {
122
+ type: "object";
123
+ properties: Record<string, import("../..").FormField>;
124
+ required?: string[] | undefined;
125
+ } | undefined;
126
+ data?: Record<string, unknown> | undefined;
127
+ functionName?: string | undefined;
128
+ arguments?: Record<string, unknown> | undefined;
129
+ }[] | undefined;
130
+ followUpReplies?: string[] | undefined;
131
+ createdAt: Date;
132
+ }[] | undefined;
133
+ } | null, Conversation | {
134
+ id: string;
135
+ title: string;
136
+ lastMessageDate: Date;
137
+ messages?: {
138
+ id: string;
139
+ conversationId: string;
140
+ content: string;
141
+ role: "user" | "assistant";
142
+ status: import("../..").MessageStatus;
143
+ agent?: {
144
+ id: string;
145
+ name: string;
146
+ displayName?: string | undefined;
147
+ } | undefined;
148
+ sources?: {
149
+ id: string;
150
+ title: string;
151
+ url?: string | undefined;
152
+ }[] | undefined;
153
+ toolCalls?: {
154
+ id: string;
155
+ type: import("../..").ToolCallType;
156
+ status: string;
157
+ toolName: string;
158
+ toolDisplayName?: string | undefined;
159
+ message?: string | undefined;
160
+ formSchema?: {
161
+ type: "object";
162
+ properties: Record<string, import("../..").FormField>;
163
+ required?: string[] | undefined;
164
+ } | undefined;
165
+ data?: Record<string, unknown> | undefined;
166
+ functionName?: string | undefined;
167
+ arguments?: Record<string, unknown> | undefined;
168
+ }[] | undefined;
169
+ followUpReplies?: string[] | undefined;
170
+ createdAt: Date;
171
+ }[] | undefined;
172
+ } | null>;
173
+ isLoading: import("vue").Ref<boolean, boolean>;
174
+ error: import("vue").Ref<Error | null, Error | null>;
175
+ selectConversation: (id: string) => Promise<void>;
176
+ startNewConversation: () => void;
177
+ refreshConversations: () => Promise<void>;
178
+ };
@@ -0,0 +1,89 @@
1
+ import type { AgoClient } from "../../client/AgoClient";
2
+ import type { AgoMessage } from "../../client/types";
3
+ export interface UseMessagesOptions {
4
+ client?: AgoClient;
5
+ conversationId?: string;
6
+ }
7
+ /**
8
+ * Composable to manage messages in a conversation.
9
+ *
10
+ * ```ts
11
+ * const { messages, sendMessage, isLoading } = useMessages();
12
+ * ```
13
+ */
14
+ export declare function useMessages(options?: UseMessagesOptions): {
15
+ messages: import("vue").Ref<{
16
+ id: string;
17
+ conversationId: string;
18
+ content: string;
19
+ role: "user" | "assistant";
20
+ status: import("../..").MessageStatus;
21
+ agent?: {
22
+ id: string;
23
+ name: string;
24
+ displayName?: string | undefined;
25
+ } | undefined;
26
+ sources?: {
27
+ id: string;
28
+ title: string;
29
+ url?: string | undefined;
30
+ }[] | undefined;
31
+ toolCalls?: {
32
+ id: string;
33
+ type: import("../..").ToolCallType;
34
+ status: string;
35
+ toolName: string;
36
+ toolDisplayName?: string | undefined;
37
+ message?: string | undefined;
38
+ formSchema?: {
39
+ type: "object";
40
+ properties: Record<string, import("../..").FormField>;
41
+ required?: string[] | undefined;
42
+ } | undefined;
43
+ data?: Record<string, unknown> | undefined;
44
+ functionName?: string | undefined;
45
+ arguments?: Record<string, unknown> | undefined;
46
+ }[] | undefined;
47
+ followUpReplies?: string[] | undefined;
48
+ createdAt: Date;
49
+ }[], AgoMessage[] | {
50
+ id: string;
51
+ conversationId: string;
52
+ content: string;
53
+ role: "user" | "assistant";
54
+ status: import("../..").MessageStatus;
55
+ agent?: {
56
+ id: string;
57
+ name: string;
58
+ displayName?: string | undefined;
59
+ } | undefined;
60
+ sources?: {
61
+ id: string;
62
+ title: string;
63
+ url?: string | undefined;
64
+ }[] | undefined;
65
+ toolCalls?: {
66
+ id: string;
67
+ type: import("../..").ToolCallType;
68
+ status: string;
69
+ toolName: string;
70
+ toolDisplayName?: string | undefined;
71
+ message?: string | undefined;
72
+ formSchema?: {
73
+ type: "object";
74
+ properties: Record<string, import("../..").FormField>;
75
+ required?: string[] | undefined;
76
+ } | undefined;
77
+ data?: Record<string, unknown> | undefined;
78
+ functionName?: string | undefined;
79
+ arguments?: Record<string, unknown> | undefined;
80
+ }[] | undefined;
81
+ followUpReplies?: string[] | undefined;
82
+ createdAt: Date;
83
+ }[]>;
84
+ isLoading: import("vue").Ref<boolean, boolean>;
85
+ error: import("vue").Ref<Error | null, Error | null>;
86
+ conversationId: import("vue").Ref<string | undefined, string | undefined>;
87
+ sendMessage: (content: string, files?: File[]) => Promise<AgoMessage | null>;
88
+ clearMessages: () => void;
89
+ };
@@ -0,0 +1,10 @@
1
+ export { AgoPlugin } from "./plugin";
2
+ export type { AgoPluginOptions } from "./plugin";
3
+ export { useAgo } from "./composables/useAgo";
4
+ export { useChat } from "./composables/useChat";
5
+ export { useMessages } from "./composables/useMessages";
6
+ export { useConversation } from "./composables/useConversation";
7
+ export { useAgoFunction, useAgoNavigation } from "./composables/useAgoFunction";
8
+ export { useAgoEvents } from "./composables/useAgoEvents";
9
+ export { AGO_CLIENT_KEY } from "./symbols";
10
+ export type { AgoConfig, AgoMessage, Conversation, AgoAgent, AgoSource, ToolCallData, } from "../client/types";
@@ -0,0 +1,16 @@
1
+ import type { App } from "vue";
2
+ import type { AgoConfig } from "../client/types";
3
+ export interface AgoPluginOptions extends AgoConfig {
4
+ }
5
+ /**
6
+ * Vue plugin that provides an AgoClient to the entire app via inject/provide.
7
+ *
8
+ * ```ts
9
+ * import { AgoPlugin } from "@useago/sdk/vue";
10
+ *
11
+ * app.use(AgoPlugin, { baseUrl: "https://YOUR-DOMAIN.useago.com" });
12
+ * ```
13
+ */
14
+ export declare const AgoPlugin: {
15
+ install(app: App, options: AgoPluginOptions): void;
16
+ };
@@ -0,0 +1,3 @@
1
+ import type { InjectionKey } from "vue";
2
+ import type { AgoClient } from "../client/AgoClient";
3
+ export declare const AGO_CLIENT_KEY: InjectionKey<AgoClient>;
package/dist/vue.cjs ADDED
@@ -0,0 +1,311 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ require("./rolldown-runtime-BqCkTl7Q.cjs");
3
+ const require_AgoClient = require("./AgoClient-D0l1GTRs.cjs");
4
+ let vue = require("vue");
5
+ //#region src/vue/symbols.ts
6
+ var AGO_CLIENT_KEY = Symbol("ago-client");
7
+ //#endregion
8
+ //#region src/vue/plugin.ts
9
+ /**
10
+ * Vue plugin that provides an AgoClient to the entire app via inject/provide.
11
+ *
12
+ * ```ts
13
+ * import { AgoPlugin } from "@useago/sdk/vue";
14
+ *
15
+ * app.use(AgoPlugin, { baseUrl: "https://YOUR-DOMAIN.useago.com" });
16
+ * ```
17
+ */
18
+ var AgoPlugin = { install(app, options) {
19
+ const client = new require_AgoClient.AgoClient(options);
20
+ app.provide(AGO_CLIENT_KEY, client);
21
+ } };
22
+ //#endregion
23
+ //#region src/vue/composables/useAgo.ts
24
+ /**
25
+ * Get or create an AgoClient.
26
+ *
27
+ * - Without args: returns the client from `AgoPlugin` (throws if none).
28
+ * - With config: creates a new client instance.
29
+ *
30
+ * ```ts
31
+ * // From plugin
32
+ * const client = useAgo();
33
+ *
34
+ * // Standalone
35
+ * const client = useAgo({ baseUrl: "https://YOUR-DOMAIN.useago.com" });
36
+ * ```
37
+ */
38
+ function useAgo(config) {
39
+ if (config) return new require_AgoClient.AgoClient(config);
40
+ const client = (0, vue.inject)(AGO_CLIENT_KEY);
41
+ if (!client) throw new Error("useAgo(): no AgoClient found. Either pass config or install AgoPlugin.");
42
+ return client;
43
+ }
44
+ //#endregion
45
+ //#region src/vue/composables/useMessages.ts
46
+ /**
47
+ * Composable to manage messages in a conversation.
48
+ *
49
+ * ```ts
50
+ * const { messages, sendMessage, isLoading } = useMessages();
51
+ * ```
52
+ */
53
+ function useMessages(options = {}) {
54
+ const client = options.client ?? useAgo();
55
+ const messages = (0, vue.ref)([]);
56
+ const conversationId = (0, vue.ref)(options.conversationId);
57
+ const isLoading = (0, vue.ref)(false);
58
+ const error = (0, vue.ref)(null);
59
+ const handleStart = (data) => {
60
+ if (!conversationId.value) conversationId.value = data.conversationId;
61
+ };
62
+ const handleChunk = (data) => {
63
+ const idx = messages.value.findIndex((m) => m.id === data.messageId);
64
+ if (idx >= 0) messages.value[idx] = {
65
+ ...messages.value[idx],
66
+ content: messages.value[idx].content + data.content
67
+ };
68
+ };
69
+ const handleComplete = (message) => {
70
+ const idx = messages.value.findIndex((m) => m.id === message.id);
71
+ if (idx >= 0) messages.value[idx] = message;
72
+ else messages.value.push(message);
73
+ isLoading.value = false;
74
+ };
75
+ const handleError = (data) => {
76
+ error.value = new Error(data.error);
77
+ isLoading.value = false;
78
+ };
79
+ (0, vue.onMounted)(() => {
80
+ client.on("message:start", handleStart);
81
+ client.on("message:chunk", handleChunk);
82
+ client.on("message:complete", handleComplete);
83
+ client.on("message:error", handleError);
84
+ });
85
+ (0, vue.onUnmounted)(() => {
86
+ client.off("message:start", handleStart);
87
+ client.off("message:chunk", handleChunk);
88
+ client.off("message:complete", handleComplete);
89
+ client.off("message:error", handleError);
90
+ });
91
+ async function sendMessage(content, files) {
92
+ isLoading.value = true;
93
+ error.value = null;
94
+ const userMsg = {
95
+ id: `temp-${Date.now()}`,
96
+ conversationId: conversationId.value || "",
97
+ content,
98
+ role: "user",
99
+ status: "DONE",
100
+ createdAt: /* @__PURE__ */ new Date()
101
+ };
102
+ const assistantMsg = {
103
+ id: `temp-assistant-${Date.now()}`,
104
+ conversationId: conversationId.value || "",
105
+ content: "",
106
+ role: "assistant",
107
+ status: "IN_PROGRESS",
108
+ createdAt: /* @__PURE__ */ new Date()
109
+ };
110
+ messages.value.push(userMsg, assistantMsg);
111
+ try {
112
+ const response = await client.sendMessage(content, {
113
+ conversationId: conversationId.value,
114
+ files
115
+ });
116
+ if (response.conversationId && !conversationId.value) conversationId.value = response.conversationId;
117
+ messages.value = messages.value.filter((m) => !m.id.startsWith("temp-"));
118
+ const updatedUser = {
119
+ ...userMsg,
120
+ id: userMsg.id.replace("temp-", "user-"),
121
+ conversationId: response.conversationId
122
+ };
123
+ if (!messages.value.some((m) => m.id === response.id)) messages.value.push(updatedUser, response);
124
+ else messages.value.push(updatedUser);
125
+ return response;
126
+ } catch (err) {
127
+ error.value = err instanceof Error ? err : /* @__PURE__ */ new Error("Failed to send");
128
+ isLoading.value = false;
129
+ messages.value = messages.value.filter((m) => !m.id.startsWith("temp-"));
130
+ return null;
131
+ }
132
+ }
133
+ function clearMessages() {
134
+ messages.value = [];
135
+ conversationId.value = void 0;
136
+ error.value = null;
137
+ }
138
+ return {
139
+ messages,
140
+ isLoading,
141
+ error,
142
+ conversationId,
143
+ sendMessage,
144
+ clearMessages
145
+ };
146
+ }
147
+ //#endregion
148
+ //#region src/vue/composables/useConversation.ts
149
+ /**
150
+ * Composable to manage conversations.
151
+ *
152
+ * ```ts
153
+ * const { conversations, selectConversation } = useConversation();
154
+ * ```
155
+ */
156
+ function useConversation(options = {}) {
157
+ const client = options.client ?? useAgo();
158
+ const autoLoad = options.autoLoad ?? true;
159
+ const conversations = (0, vue.ref)([]);
160
+ const currentConversation = (0, vue.ref)(null);
161
+ const isLoading = (0, vue.ref)(false);
162
+ const error = (0, vue.ref)(null);
163
+ async function refreshConversations() {
164
+ isLoading.value = true;
165
+ error.value = null;
166
+ try {
167
+ conversations.value = await client.getConversations();
168
+ } catch (err) {
169
+ error.value = err instanceof Error ? err : /* @__PURE__ */ new Error("Failed to load conversations");
170
+ } finally {
171
+ isLoading.value = false;
172
+ }
173
+ }
174
+ async function selectConversation(id) {
175
+ isLoading.value = true;
176
+ error.value = null;
177
+ try {
178
+ currentConversation.value = await client.getConversation(id);
179
+ } catch (err) {
180
+ error.value = err instanceof Error ? err : /* @__PURE__ */ new Error("Failed to load conversation");
181
+ } finally {
182
+ isLoading.value = false;
183
+ }
184
+ }
185
+ function startNewConversation() {
186
+ currentConversation.value = null;
187
+ }
188
+ (0, vue.onMounted)(() => {
189
+ if (autoLoad) refreshConversations();
190
+ });
191
+ return {
192
+ conversations,
193
+ currentConversation,
194
+ isLoading,
195
+ error,
196
+ selectConversation,
197
+ startNewConversation,
198
+ refreshConversations
199
+ };
200
+ }
201
+ //#endregion
202
+ //#region src/vue/composables/useChat.ts
203
+ /**
204
+ * All-in-one composable combining messages + conversations.
205
+ *
206
+ * ```ts
207
+ * const { messages, sendMessage, conversations, selectConversation } = useChat();
208
+ * ```
209
+ */
210
+ function useChat(options = {}) {
211
+ const msgResult = useMessages({
212
+ client: options.client,
213
+ conversationId: options.conversationId
214
+ });
215
+ const convResult = useConversation({
216
+ client: options.client,
217
+ autoLoad: options.autoLoad
218
+ });
219
+ const error = (0, vue.computed)(() => msgResult.error.value || convResult.error.value);
220
+ return {
221
+ messages: msgResult.messages,
222
+ isLoading: msgResult.isLoading,
223
+ error,
224
+ sendMessage: msgResult.sendMessage,
225
+ clearMessages: msgResult.clearMessages,
226
+ conversationId: msgResult.conversationId,
227
+ conversations: convResult.conversations,
228
+ currentConversation: convResult.currentConversation,
229
+ isConversationsLoading: convResult.isLoading,
230
+ selectConversation: convResult.selectConversation,
231
+ startNewConversation: convResult.startNewConversation,
232
+ refreshConversations: convResult.refreshConversations
233
+ };
234
+ }
235
+ //#endregion
236
+ //#region src/vue/composables/useAgoFunction.ts
237
+ /**
238
+ * Register a client-side function with auto-cleanup on unmount.
239
+ *
240
+ * ```ts
241
+ * useAgoFunction("showToast", {
242
+ * description: "Show a toast",
243
+ * parameters: { type: "object", properties: { message: { type: "string" } } },
244
+ * handler: async (args) => { toast(args.message); return { shown: true }; },
245
+ * });
246
+ * ```
247
+ */
248
+ function useAgoFunction(name, options) {
249
+ const client = useAgo();
250
+ (0, vue.onMounted)(() => {
251
+ client.registerFunction(name, options.handler, {
252
+ description: options.description,
253
+ parameters: options.parameters
254
+ });
255
+ });
256
+ (0, vue.onUnmounted)(() => {
257
+ client.unregisterFunction(name);
258
+ });
259
+ }
260
+ /**
261
+ * Register navigation routes with auto-cleanup on unmount.
262
+ * Works with vue-router's `useRouter().push`.
263
+ *
264
+ * ```ts
265
+ * const router = useRouter();
266
+ * useAgoNavigation((path) => router.push(path), [
267
+ * { name: "dashboard", path: "/dashboard", description: "Main dashboard" },
268
+ * ]);
269
+ * ```
270
+ */
271
+ function useAgoNavigation(navigate, routes) {
272
+ const client = useAgo();
273
+ (0, vue.onMounted)(() => {
274
+ client.registerNavigationFunction(navigate, routes);
275
+ });
276
+ (0, vue.onUnmounted)(() => {
277
+ client.unregisterFunction("navigateToPage");
278
+ });
279
+ }
280
+ //#endregion
281
+ //#region src/vue/composables/useAgoEvents.ts
282
+ /**
283
+ * Subscribe to AGO client events with auto-cleanup on unmount.
284
+ *
285
+ * ```ts
286
+ * useAgoEvents("message:complete", (msg) => {
287
+ * console.log("Got message:", msg.content);
288
+ * });
289
+ * ```
290
+ */
291
+ function useAgoEvents(event, handler) {
292
+ const client = useAgo();
293
+ (0, vue.onMounted)(() => {
294
+ client.on(event, handler);
295
+ });
296
+ (0, vue.onUnmounted)(() => {
297
+ client.off(event, handler);
298
+ });
299
+ }
300
+ //#endregion
301
+ exports.AGO_CLIENT_KEY = AGO_CLIENT_KEY;
302
+ exports.AgoPlugin = AgoPlugin;
303
+ exports.useAgo = useAgo;
304
+ exports.useAgoEvents = useAgoEvents;
305
+ exports.useAgoFunction = useAgoFunction;
306
+ exports.useAgoNavigation = useAgoNavigation;
307
+ exports.useChat = useChat;
308
+ exports.useConversation = useConversation;
309
+ exports.useMessages = useMessages;
310
+
311
+ //# sourceMappingURL=vue.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vue.cjs","names":[],"sources":["../src/vue/symbols.ts","../src/vue/plugin.ts","../src/vue/composables/useAgo.ts","../src/vue/composables/useMessages.ts","../src/vue/composables/useConversation.ts","../src/vue/composables/useChat.ts","../src/vue/composables/useAgoFunction.ts","../src/vue/composables/useAgoEvents.ts"],"sourcesContent":["import type { InjectionKey } from \"vue\";\nimport type { AgoClient } from \"../client/AgoClient\";\n\nexport const AGO_CLIENT_KEY: InjectionKey<AgoClient> = Symbol(\"ago-client\");\n","import type { App } from \"vue\";\nimport { AgoClient } from \"../client/AgoClient\";\nimport type { AgoConfig } from \"../client/types\";\nimport { AGO_CLIENT_KEY } from \"./symbols\";\n\nexport interface AgoPluginOptions extends AgoConfig {}\n\n/**\n * Vue plugin that provides an AgoClient to the entire app via inject/provide.\n *\n * ```ts\n * import { AgoPlugin } from \"@useago/sdk/vue\";\n *\n * app.use(AgoPlugin, { baseUrl: \"https://YOUR-DOMAIN.useago.com\" });\n * ```\n */\nexport const AgoPlugin = {\n install(app: App, options: AgoPluginOptions) {\n const client = new AgoClient(options);\n app.provide(AGO_CLIENT_KEY, client);\n },\n};\n","import { inject } from \"vue\";\nimport { AgoClient } from \"../../client/AgoClient\";\nimport type { AgoConfig } from \"../../client/types\";\nimport { AGO_CLIENT_KEY } from \"../symbols\";\n\n/**\n * Get or create an AgoClient.\n *\n * - Without args: returns the client from `AgoPlugin` (throws if none).\n * - With config: creates a new client instance.\n *\n * ```ts\n * // From plugin\n * const client = useAgo();\n *\n * // Standalone\n * const client = useAgo({ baseUrl: \"https://YOUR-DOMAIN.useago.com\" });\n * ```\n */\nexport function useAgo(config?: AgoConfig): AgoClient {\n if (config) {\n return new AgoClient(config);\n }\n\n const client = inject(AGO_CLIENT_KEY);\n if (!client) {\n throw new Error(\n \"useAgo(): no AgoClient found. Either pass config or install AgoPlugin.\"\n );\n }\n return client;\n}\n","import { ref, onMounted, onUnmounted } from \"vue\";\nimport type { AgoClient } from \"../../client/AgoClient\";\nimport type { AgoMessage } from \"../../client/types\";\nimport { useAgo } from \"./useAgo\";\n\nexport interface UseMessagesOptions {\n client?: AgoClient;\n conversationId?: string;\n}\n\n/**\n * Composable to manage messages in a conversation.\n *\n * ```ts\n * const { messages, sendMessage, isLoading } = useMessages();\n * ```\n */\nexport function useMessages(options: UseMessagesOptions = {}) {\n const client = options.client ?? useAgo();\n\n const messages = ref<AgoMessage[]>([]);\n const conversationId = ref<string | undefined>(options.conversationId);\n const isLoading = ref(false);\n const error = ref<Error | null>(null);\n\n const handleStart = (data: { conversationId: string; messageId: string }) => {\n if (!conversationId.value) {\n conversationId.value = data.conversationId;\n }\n };\n\n const handleChunk = (data: { content: string; messageId: string }) => {\n const idx = messages.value.findIndex((m: AgoMessage) => m.id === data.messageId);\n if (idx >= 0) {\n messages.value[idx] = {\n ...messages.value[idx],\n content: messages.value[idx].content + data.content,\n };\n }\n };\n\n const handleComplete = (message: AgoMessage) => {\n const idx = messages.value.findIndex((m: AgoMessage) => m.id === message.id);\n if (idx >= 0) {\n messages.value[idx] = message;\n } else {\n messages.value.push(message);\n }\n isLoading.value = false;\n };\n\n const handleError = (data: { error: string }) => {\n error.value = new Error(data.error);\n isLoading.value = false;\n };\n\n onMounted(() => {\n client.on(\"message:start\", handleStart);\n client.on(\"message:chunk\", handleChunk);\n client.on(\"message:complete\", handleComplete);\n client.on(\"message:error\", handleError);\n });\n\n onUnmounted(() => {\n client.off(\"message:start\", handleStart);\n client.off(\"message:chunk\", handleChunk);\n client.off(\"message:complete\", handleComplete);\n client.off(\"message:error\", handleError);\n });\n\n async function sendMessage(content: string, files?: File[]): Promise<AgoMessage | null> {\n isLoading.value = true;\n error.value = null;\n\n // Optimistic user message\n const userMsg: AgoMessage = {\n id: `temp-${Date.now()}`,\n conversationId: conversationId.value || \"\",\n content,\n role: \"user\",\n status: \"DONE\",\n createdAt: new Date(),\n };\n const assistantMsg: AgoMessage = {\n id: `temp-assistant-${Date.now()}`,\n conversationId: conversationId.value || \"\",\n content: \"\",\n role: \"assistant\",\n status: \"IN_PROGRESS\",\n createdAt: new Date(),\n };\n messages.value.push(userMsg, assistantMsg);\n\n try {\n const response = await client.sendMessage(content, {\n conversationId: conversationId.value,\n files,\n });\n if (response.conversationId && !conversationId.value) {\n conversationId.value = response.conversationId;\n }\n // Replace temp messages\n messages.value = messages.value.filter((m: AgoMessage) => !m.id.startsWith(\"temp-\"));\n const updatedUser = { ...userMsg, id: userMsg.id.replace(\"temp-\", \"user-\"), conversationId: response.conversationId };\n if (!messages.value.some((m: AgoMessage) => m.id === response.id)) {\n messages.value.push(updatedUser, response);\n } else {\n messages.value.push(updatedUser);\n }\n return response;\n } catch (err) {\n error.value = err instanceof Error ? err : new Error(\"Failed to send\");\n isLoading.value = false;\n messages.value = messages.value.filter((m: AgoMessage) => !m.id.startsWith(\"temp-\"));\n return null;\n }\n }\n\n function clearMessages() {\n messages.value = [];\n conversationId.value = undefined;\n error.value = null;\n }\n\n return { messages, isLoading, error, conversationId, sendMessage, clearMessages };\n}\n","import { ref, onMounted } from \"vue\";\nimport type { AgoClient } from \"../../client/AgoClient\";\nimport type { Conversation } from \"../../client/types\";\nimport { useAgo } from \"./useAgo\";\n\nexport interface UseConversationOptions {\n client?: AgoClient;\n autoLoad?: boolean;\n}\n\n/**\n * Composable to manage conversations.\n *\n * ```ts\n * const { conversations, selectConversation } = useConversation();\n * ```\n */\nexport function useConversation(options: UseConversationOptions = {}) {\n const client = options.client ?? useAgo();\n const autoLoad = options.autoLoad ?? true;\n\n const conversations = ref<Conversation[]>([]);\n const currentConversation = ref<Conversation | null>(null);\n const isLoading = ref(false);\n const error = ref<Error | null>(null);\n\n async function refreshConversations() {\n isLoading.value = true;\n error.value = null;\n try {\n conversations.value = await client.getConversations();\n } catch (err) {\n error.value = err instanceof Error ? err : new Error(\"Failed to load conversations\");\n } finally {\n isLoading.value = false;\n }\n }\n\n async function selectConversation(id: string) {\n isLoading.value = true;\n error.value = null;\n try {\n currentConversation.value = await client.getConversation(id);\n } catch (err) {\n error.value = err instanceof Error ? err : new Error(\"Failed to load conversation\");\n } finally {\n isLoading.value = false;\n }\n }\n\n function startNewConversation() {\n currentConversation.value = null;\n }\n\n onMounted(() => {\n if (autoLoad) refreshConversations();\n });\n\n return {\n conversations,\n currentConversation,\n isLoading,\n error,\n selectConversation,\n startNewConversation,\n refreshConversations,\n };\n}\n","import { computed } from \"vue\";\nimport type { AgoClient } from \"../../client/AgoClient\";\nimport { useMessages } from \"./useMessages\";\nimport { useConversation } from \"./useConversation\";\n\nexport interface UseChatOptions {\n client?: AgoClient;\n conversationId?: string;\n autoLoad?: boolean;\n}\n\n/**\n * All-in-one composable combining messages + conversations.\n *\n * ```ts\n * const { messages, sendMessage, conversations, selectConversation } = useChat();\n * ```\n */\nexport function useChat(options: UseChatOptions = {}) {\n const msgResult = useMessages({\n client: options.client,\n conversationId: options.conversationId,\n });\n\n const convResult = useConversation({\n client: options.client,\n autoLoad: options.autoLoad,\n });\n\n const error = computed(\n () => msgResult.error.value || convResult.error.value\n );\n\n return {\n // Messages\n messages: msgResult.messages,\n isLoading: msgResult.isLoading,\n error,\n sendMessage: msgResult.sendMessage,\n clearMessages: msgResult.clearMessages,\n conversationId: msgResult.conversationId,\n // Conversations\n conversations: convResult.conversations,\n currentConversation: convResult.currentConversation,\n isConversationsLoading: convResult.isLoading,\n selectConversation: convResult.selectConversation,\n startNewConversation: convResult.startNewConversation,\n refreshConversations: convResult.refreshConversations,\n };\n}\n","import { onMounted, onUnmounted } from \"vue\";\nimport type { ClientFunctionHandler, ClientFunctionSchema } from \"../../functions/types\";\nimport { useAgo } from \"./useAgo\";\n\n/**\n * Register a client-side function with auto-cleanup on unmount.\n *\n * ```ts\n * useAgoFunction(\"showToast\", {\n * description: \"Show a toast\",\n * parameters: { type: \"object\", properties: { message: { type: \"string\" } } },\n * handler: async (args) => { toast(args.message); return { shown: true }; },\n * });\n * ```\n */\nexport function useAgoFunction(\n name: string,\n options: {\n description: string;\n parameters: ClientFunctionSchema[\"parameters\"];\n handler: ClientFunctionHandler;\n }\n): void {\n const client = useAgo();\n\n onMounted(() => {\n client.registerFunction(name, options.handler, {\n description: options.description,\n parameters: options.parameters,\n });\n });\n\n onUnmounted(() => {\n client.unregisterFunction(name);\n });\n}\n\nexport interface AgoRoute {\n name: string;\n path: string;\n description: string;\n}\n\n/**\n * Register navigation routes with auto-cleanup on unmount.\n * Works with vue-router's `useRouter().push`.\n *\n * ```ts\n * const router = useRouter();\n * useAgoNavigation((path) => router.push(path), [\n * { name: \"dashboard\", path: \"/dashboard\", description: \"Main dashboard\" },\n * ]);\n * ```\n */\nexport function useAgoNavigation(\n navigate: (path: string) => void,\n routes: AgoRoute[]\n): void {\n const client = useAgo();\n\n onMounted(() => {\n client.registerNavigationFunction(navigate, routes);\n });\n\n onUnmounted(() => {\n client.unregisterFunction(\"navigateToPage\");\n });\n}\n","import { onMounted, onUnmounted } from \"vue\";\nimport type { AgoClientEvents, AgoEventName } from \"../../client/types\";\nimport { useAgo } from \"./useAgo\";\n\n/**\n * Subscribe to AGO client events with auto-cleanup on unmount.\n *\n * ```ts\n * useAgoEvents(\"message:complete\", (msg) => {\n * console.log(\"Got message:\", msg.content);\n * });\n * ```\n */\nexport function useAgoEvents<K extends AgoEventName>(\n event: K,\n handler: (data: AgoClientEvents[K]) => void\n): void {\n const client = useAgo();\n\n onMounted(() => {\n client.on(event, handler);\n });\n\n onUnmounted(() => {\n client.off(event, handler);\n });\n}\n"],"mappings":";;;;;AAGA,IAAa,iBAA0C,OAAO,aAAa;;;;;;;;;;;;ACa3E,IAAa,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