@useago/sdk 0.1.6 → 0.1.7

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 (67) hide show
  1. package/dist/{createMockClient-BZKh_1em.cjs → AgoClient-BDO4avLq.cjs} +219 -124
  2. package/dist/AgoClient-BDO4avLq.cjs.map +1 -0
  3. package/dist/{createMockClient-uGlVyjbL.js → AgoClient-D-c91tx5.js} +221 -126
  4. package/dist/AgoClient-D-c91tx5.js.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 +105 -0
  9. package/dist/angular.cjs.map +1 -0
  10. package/dist/angular.d.ts +1 -0
  11. package/dist/angular.js +105 -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 +4 -6
  17. package/dist/createMockClient-B1DcBiIK.js +94 -0
  18. package/dist/createMockClient-B1DcBiIK.js.map +1 -0
  19. package/dist/createMockClient-BqNSJUu4.cjs +93 -0
  20. package/dist/createMockClient-BqNSJUu4.cjs.map +1 -0
  21. package/dist/functions-B0Z0rNQW.cjs +306 -0
  22. package/dist/functions-B0Z0rNQW.cjs.map +1 -0
  23. package/dist/functions-C-wLEc8b.js +306 -0
  24. package/dist/functions-C-wLEc8b.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 +17 -0
  29. package/dist/helpers.cjs.map +1 -0
  30. package/dist/helpers.d.ts +1 -0
  31. package/dist/helpers.js +17 -0
  32. package/dist/helpers.js.map +1 -0
  33. package/dist/index.cjs +179 -12
  34. package/dist/index.cjs.map +1 -1
  35. package/dist/index.d.ts +6 -0
  36. package/dist/index.js +173 -5
  37. package/dist/index.js.map +1 -1
  38. package/dist/react/context/AgoContext.d.ts +30 -4
  39. package/dist/react/context/index.d.ts +1 -1
  40. package/dist/react/hooks/index.d.ts +1 -0
  41. package/dist/react/hooks/useAgoContext.d.ts +40 -0
  42. package/dist/react/hooks/useAgoFunction.d.ts +14 -2
  43. package/dist/react/index.d.ts +2 -1
  44. package/dist/react.cjs +76 -11
  45. package/dist/react.cjs.map +1 -1
  46. package/dist/react.js +81 -17
  47. package/dist/react.js.map +1 -1
  48. package/dist/state/ClientContextRegistry.d.ts +64 -0
  49. package/dist/streaming/helpers.d.ts +67 -0
  50. package/dist/vue/composables/useAgo.d.ts +17 -0
  51. package/dist/vue/composables/useAgoEvents.d.ts +11 -0
  52. package/dist/vue/composables/useAgoFunction.d.ts +34 -0
  53. package/dist/vue/composables/useChat.d.ts +251 -0
  54. package/dist/vue/composables/useConversation.d.ts +178 -0
  55. package/dist/vue/composables/useMessages.d.ts +89 -0
  56. package/dist/vue/index.d.ts +10 -0
  57. package/dist/vue/plugin.d.ts +16 -0
  58. package/dist/vue/symbols.d.ts +3 -0
  59. package/dist/vue.cjs +232 -0
  60. package/dist/vue.cjs.map +1 -0
  61. package/dist/vue.d.ts +1 -0
  62. package/dist/vue.js +232 -0
  63. package/dist/vue.js.map +1 -0
  64. package/dist/widget/types.d.ts +1 -0
  65. package/package.json +23 -3
  66. package/dist/createMockClient-BZKh_1em.cjs.map +0 -1
  67. package/dist/createMockClient-uGlVyjbL.js.map +0 -1
@@ -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,232 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const AgoClient = require("./AgoClient-BDO4avLq.cjs");
4
+ const vue = require("vue");
5
+ const AGO_CLIENT_KEY = Symbol("ago-client");
6
+ const AgoPlugin = {
7
+ install(app, options) {
8
+ const client = new AgoClient.AgoClient(options);
9
+ app.provide(AGO_CLIENT_KEY, client);
10
+ }
11
+ };
12
+ function useAgo(config) {
13
+ if (config) {
14
+ return new AgoClient.AgoClient(config);
15
+ }
16
+ const client = vue.inject(AGO_CLIENT_KEY);
17
+ if (!client) {
18
+ throw new Error(
19
+ "useAgo(): no AgoClient found. Either pass config or install AgoPlugin."
20
+ );
21
+ }
22
+ return client;
23
+ }
24
+ function useMessages(options = {}) {
25
+ const client = options.client ?? useAgo();
26
+ const messages = vue.ref([]);
27
+ const conversationId = vue.ref(options.conversationId);
28
+ const isLoading = vue.ref(false);
29
+ const error = vue.ref(null);
30
+ const handleStart = (data) => {
31
+ if (!conversationId.value) {
32
+ conversationId.value = data.conversationId;
33
+ }
34
+ };
35
+ const handleChunk = (data) => {
36
+ const idx = messages.value.findIndex((m) => m.id === data.messageId);
37
+ if (idx >= 0) {
38
+ messages.value[idx] = {
39
+ ...messages.value[idx],
40
+ content: messages.value[idx].content + data.content
41
+ };
42
+ }
43
+ };
44
+ const handleComplete = (message) => {
45
+ const idx = messages.value.findIndex((m) => m.id === message.id);
46
+ if (idx >= 0) {
47
+ messages.value[idx] = message;
48
+ } else {
49
+ messages.value.push(message);
50
+ }
51
+ isLoading.value = false;
52
+ };
53
+ const handleError = (data) => {
54
+ error.value = new Error(data.error);
55
+ isLoading.value = false;
56
+ };
57
+ vue.onMounted(() => {
58
+ client.on("message:start", handleStart);
59
+ client.on("message:chunk", handleChunk);
60
+ client.on("message:complete", handleComplete);
61
+ client.on("message:error", handleError);
62
+ });
63
+ vue.onUnmounted(() => {
64
+ client.off("message:start", handleStart);
65
+ client.off("message:chunk", handleChunk);
66
+ client.off("message:complete", handleComplete);
67
+ client.off("message:error", handleError);
68
+ });
69
+ async function sendMessage(content, files) {
70
+ isLoading.value = true;
71
+ error.value = null;
72
+ const userMsg = {
73
+ id: `temp-${Date.now()}`,
74
+ conversationId: conversationId.value || "",
75
+ content,
76
+ role: "user",
77
+ status: "DONE",
78
+ createdAt: /* @__PURE__ */ new Date()
79
+ };
80
+ const assistantMsg = {
81
+ id: `temp-assistant-${Date.now()}`,
82
+ conversationId: conversationId.value || "",
83
+ content: "",
84
+ role: "assistant",
85
+ status: "IN_PROGRESS",
86
+ createdAt: /* @__PURE__ */ new Date()
87
+ };
88
+ messages.value.push(userMsg, assistantMsg);
89
+ try {
90
+ const response = await client.sendMessage(content, {
91
+ conversationId: conversationId.value,
92
+ files
93
+ });
94
+ if (response.conversationId && !conversationId.value) {
95
+ conversationId.value = response.conversationId;
96
+ }
97
+ messages.value = messages.value.filter((m) => !m.id.startsWith("temp-"));
98
+ const updatedUser = { ...userMsg, id: userMsg.id.replace("temp-", "user-"), conversationId: response.conversationId };
99
+ if (!messages.value.some((m) => m.id === response.id)) {
100
+ messages.value.push(updatedUser, response);
101
+ } else {
102
+ messages.value.push(updatedUser);
103
+ }
104
+ return response;
105
+ } catch (err) {
106
+ error.value = err instanceof Error ? err : new Error("Failed to send");
107
+ isLoading.value = false;
108
+ messages.value = messages.value.filter((m) => !m.id.startsWith("temp-"));
109
+ return null;
110
+ }
111
+ }
112
+ function clearMessages() {
113
+ messages.value = [];
114
+ conversationId.value = void 0;
115
+ error.value = null;
116
+ }
117
+ return { messages, isLoading, error, conversationId, sendMessage, clearMessages };
118
+ }
119
+ function useConversation(options = {}) {
120
+ const client = options.client ?? useAgo();
121
+ const autoLoad = options.autoLoad ?? true;
122
+ const conversations = vue.ref([]);
123
+ const currentConversation = vue.ref(null);
124
+ const isLoading = vue.ref(false);
125
+ const error = vue.ref(null);
126
+ async function refreshConversations() {
127
+ isLoading.value = true;
128
+ error.value = null;
129
+ try {
130
+ conversations.value = await client.getConversations();
131
+ } catch (err) {
132
+ error.value = err instanceof Error ? err : new Error("Failed to load conversations");
133
+ } finally {
134
+ isLoading.value = false;
135
+ }
136
+ }
137
+ async function selectConversation(id) {
138
+ isLoading.value = true;
139
+ error.value = null;
140
+ try {
141
+ currentConversation.value = await client.getConversation(id);
142
+ } catch (err) {
143
+ error.value = err instanceof Error ? err : new Error("Failed to load conversation");
144
+ } finally {
145
+ isLoading.value = false;
146
+ }
147
+ }
148
+ function startNewConversation() {
149
+ currentConversation.value = null;
150
+ }
151
+ vue.onMounted(() => {
152
+ if (autoLoad) refreshConversations();
153
+ });
154
+ return {
155
+ conversations,
156
+ currentConversation,
157
+ isLoading,
158
+ error,
159
+ selectConversation,
160
+ startNewConversation,
161
+ refreshConversations
162
+ };
163
+ }
164
+ function useChat(options = {}) {
165
+ const msgResult = useMessages({
166
+ client: options.client,
167
+ conversationId: options.conversationId
168
+ });
169
+ const convResult = useConversation({
170
+ client: options.client,
171
+ autoLoad: options.autoLoad
172
+ });
173
+ const error = vue.computed(
174
+ () => msgResult.error.value || convResult.error.value
175
+ );
176
+ return {
177
+ // Messages
178
+ messages: msgResult.messages,
179
+ isLoading: msgResult.isLoading,
180
+ error,
181
+ sendMessage: msgResult.sendMessage,
182
+ clearMessages: msgResult.clearMessages,
183
+ conversationId: msgResult.conversationId,
184
+ // Conversations
185
+ conversations: convResult.conversations,
186
+ currentConversation: convResult.currentConversation,
187
+ isConversationsLoading: convResult.isLoading,
188
+ selectConversation: convResult.selectConversation,
189
+ startNewConversation: convResult.startNewConversation,
190
+ refreshConversations: convResult.refreshConversations
191
+ };
192
+ }
193
+ function useAgoFunction(name, options) {
194
+ const client = useAgo();
195
+ vue.onMounted(() => {
196
+ client.registerFunction(name, options.handler, {
197
+ description: options.description,
198
+ parameters: options.parameters
199
+ });
200
+ });
201
+ vue.onUnmounted(() => {
202
+ client.unregisterFunction(name);
203
+ });
204
+ }
205
+ function useAgoNavigation(navigate, routes) {
206
+ const client = useAgo();
207
+ vue.onMounted(() => {
208
+ client.registerNavigationFunction(navigate, routes);
209
+ });
210
+ vue.onUnmounted(() => {
211
+ client.unregisterFunction("navigateToPage");
212
+ });
213
+ }
214
+ function useAgoEvents(event, handler) {
215
+ const client = useAgo();
216
+ vue.onMounted(() => {
217
+ client.on(event, handler);
218
+ });
219
+ vue.onUnmounted(() => {
220
+ client.off(event, handler);
221
+ });
222
+ }
223
+ exports.AGO_CLIENT_KEY = AGO_CLIENT_KEY;
224
+ exports.AgoPlugin = AgoPlugin;
225
+ exports.useAgo = useAgo;
226
+ exports.useAgoEvents = useAgoEvents;
227
+ exports.useAgoFunction = useAgoFunction;
228
+ exports.useAgoNavigation = useAgoNavigation;
229
+ exports.useChat = useChat;
230
+ exports.useConversation = useConversation;
231
+ exports.useMessages = useMessages;
232
+ //# sourceMappingURL=vue.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vue.cjs","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"],"names":["AgoClient","inject","ref","onMounted","onUnmounted","computed"],"mappings":";;;;AAGO,MAAM,iBAA0C,OAAO,YAAY;ACanE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,SAAS;AAAA,MAC7C,aAAa,QAAQ;AAAA,MACrB,YAAY,QAAQ;AAAA,IAAA,CACrB;AAAA,EACH,CAAC;AAEDC,MAAAA,YAAY,MAAM;AAChB,WAAO,mBAAmB,IAAI;AAAA,EAChC,CAAC;AACH;AAmBO,SAAS,iBACd,UACA,QACM;AACN,QAAM,SAAS,OAAA;AAEfD,MAAAA,UAAU,MAAM;AACd,WAAO,2BAA2B,UAAU,MAAM;AAAA,EACpD,CAAC;AAEDC,MAAAA,YAAY,MAAM;AAChB,WAAO,mBAAmB,gBAAgB;AAAA,EAC5C,CAAC;AACH;ACtDO,SAAS,aACd,OACA,SACM;AACN,QAAM,SAAS,OAAA;AAEfD,MAAAA,UAAU,MAAM;AACd,WAAO,GAAG,OAAO,OAAO;AAAA,EAC1B,CAAC;AAEDC,MAAAA,YAAY,MAAM;AAChB,WAAO,IAAI,OAAO,OAAO;AAAA,EAC3B,CAAC;AACH;;;;;;;;;;"}
package/dist/vue.d.ts ADDED
@@ -0,0 +1 @@
1
+ export * from './vue/index'
package/dist/vue.js ADDED
@@ -0,0 +1,232 @@
1
+ import { A as AgoClient } from "./AgoClient-D-c91tx5.js";
2
+ import { inject, ref, onMounted, onUnmounted, computed } from "vue";
3
+ const AGO_CLIENT_KEY = Symbol("ago-client");
4
+ const AgoPlugin = {
5
+ install(app, options) {
6
+ const client = new AgoClient(options);
7
+ app.provide(AGO_CLIENT_KEY, client);
8
+ }
9
+ };
10
+ function useAgo(config) {
11
+ if (config) {
12
+ return new AgoClient(config);
13
+ }
14
+ const client = inject(AGO_CLIENT_KEY);
15
+ if (!client) {
16
+ throw new Error(
17
+ "useAgo(): no AgoClient found. Either pass config or install AgoPlugin."
18
+ );
19
+ }
20
+ return client;
21
+ }
22
+ function useMessages(options = {}) {
23
+ const client = options.client ?? useAgo();
24
+ const messages = ref([]);
25
+ const conversationId = ref(options.conversationId);
26
+ const isLoading = ref(false);
27
+ const error = ref(null);
28
+ const handleStart = (data) => {
29
+ if (!conversationId.value) {
30
+ conversationId.value = data.conversationId;
31
+ }
32
+ };
33
+ const handleChunk = (data) => {
34
+ const idx = messages.value.findIndex((m) => m.id === data.messageId);
35
+ if (idx >= 0) {
36
+ messages.value[idx] = {
37
+ ...messages.value[idx],
38
+ content: messages.value[idx].content + data.content
39
+ };
40
+ }
41
+ };
42
+ const handleComplete = (message) => {
43
+ const idx = messages.value.findIndex((m) => m.id === message.id);
44
+ if (idx >= 0) {
45
+ messages.value[idx] = message;
46
+ } else {
47
+ messages.value.push(message);
48
+ }
49
+ isLoading.value = false;
50
+ };
51
+ const handleError = (data) => {
52
+ error.value = new Error(data.error);
53
+ isLoading.value = false;
54
+ };
55
+ onMounted(() => {
56
+ client.on("message:start", handleStart);
57
+ client.on("message:chunk", handleChunk);
58
+ client.on("message:complete", handleComplete);
59
+ client.on("message:error", handleError);
60
+ });
61
+ onUnmounted(() => {
62
+ client.off("message:start", handleStart);
63
+ client.off("message:chunk", handleChunk);
64
+ client.off("message:complete", handleComplete);
65
+ client.off("message:error", handleError);
66
+ });
67
+ async function sendMessage(content, files) {
68
+ isLoading.value = true;
69
+ error.value = null;
70
+ const userMsg = {
71
+ id: `temp-${Date.now()}`,
72
+ conversationId: conversationId.value || "",
73
+ content,
74
+ role: "user",
75
+ status: "DONE",
76
+ createdAt: /* @__PURE__ */ new Date()
77
+ };
78
+ const assistantMsg = {
79
+ id: `temp-assistant-${Date.now()}`,
80
+ conversationId: conversationId.value || "",
81
+ content: "",
82
+ role: "assistant",
83
+ status: "IN_PROGRESS",
84
+ createdAt: /* @__PURE__ */ new Date()
85
+ };
86
+ messages.value.push(userMsg, assistantMsg);
87
+ try {
88
+ const response = await client.sendMessage(content, {
89
+ conversationId: conversationId.value,
90
+ files
91
+ });
92
+ if (response.conversationId && !conversationId.value) {
93
+ conversationId.value = response.conversationId;
94
+ }
95
+ messages.value = messages.value.filter((m) => !m.id.startsWith("temp-"));
96
+ const updatedUser = { ...userMsg, id: userMsg.id.replace("temp-", "user-"), conversationId: response.conversationId };
97
+ if (!messages.value.some((m) => m.id === response.id)) {
98
+ messages.value.push(updatedUser, response);
99
+ } else {
100
+ messages.value.push(updatedUser);
101
+ }
102
+ return response;
103
+ } catch (err) {
104
+ error.value = err instanceof Error ? err : new Error("Failed to send");
105
+ isLoading.value = false;
106
+ messages.value = messages.value.filter((m) => !m.id.startsWith("temp-"));
107
+ return null;
108
+ }
109
+ }
110
+ function clearMessages() {
111
+ messages.value = [];
112
+ conversationId.value = void 0;
113
+ error.value = null;
114
+ }
115
+ return { messages, isLoading, error, conversationId, sendMessage, clearMessages };
116
+ }
117
+ function useConversation(options = {}) {
118
+ const client = options.client ?? useAgo();
119
+ const autoLoad = options.autoLoad ?? true;
120
+ const conversations = ref([]);
121
+ const currentConversation = ref(null);
122
+ const isLoading = ref(false);
123
+ const error = ref(null);
124
+ async function refreshConversations() {
125
+ isLoading.value = true;
126
+ error.value = null;
127
+ try {
128
+ conversations.value = await client.getConversations();
129
+ } catch (err) {
130
+ error.value = err instanceof Error ? err : new Error("Failed to load conversations");
131
+ } finally {
132
+ isLoading.value = false;
133
+ }
134
+ }
135
+ async function selectConversation(id) {
136
+ isLoading.value = true;
137
+ error.value = null;
138
+ try {
139
+ currentConversation.value = await client.getConversation(id);
140
+ } catch (err) {
141
+ error.value = err instanceof Error ? err : new Error("Failed to load conversation");
142
+ } finally {
143
+ isLoading.value = false;
144
+ }
145
+ }
146
+ function startNewConversation() {
147
+ currentConversation.value = null;
148
+ }
149
+ onMounted(() => {
150
+ if (autoLoad) refreshConversations();
151
+ });
152
+ return {
153
+ conversations,
154
+ currentConversation,
155
+ isLoading,
156
+ error,
157
+ selectConversation,
158
+ startNewConversation,
159
+ refreshConversations
160
+ };
161
+ }
162
+ function useChat(options = {}) {
163
+ const msgResult = useMessages({
164
+ client: options.client,
165
+ conversationId: options.conversationId
166
+ });
167
+ const convResult = useConversation({
168
+ client: options.client,
169
+ autoLoad: options.autoLoad
170
+ });
171
+ const error = computed(
172
+ () => msgResult.error.value || convResult.error.value
173
+ );
174
+ return {
175
+ // Messages
176
+ messages: msgResult.messages,
177
+ isLoading: msgResult.isLoading,
178
+ error,
179
+ sendMessage: msgResult.sendMessage,
180
+ clearMessages: msgResult.clearMessages,
181
+ conversationId: msgResult.conversationId,
182
+ // Conversations
183
+ conversations: convResult.conversations,
184
+ currentConversation: convResult.currentConversation,
185
+ isConversationsLoading: convResult.isLoading,
186
+ selectConversation: convResult.selectConversation,
187
+ startNewConversation: convResult.startNewConversation,
188
+ refreshConversations: convResult.refreshConversations
189
+ };
190
+ }
191
+ function useAgoFunction(name, options) {
192
+ const client = useAgo();
193
+ onMounted(() => {
194
+ client.registerFunction(name, options.handler, {
195
+ description: options.description,
196
+ parameters: options.parameters
197
+ });
198
+ });
199
+ onUnmounted(() => {
200
+ client.unregisterFunction(name);
201
+ });
202
+ }
203
+ function useAgoNavigation(navigate, routes) {
204
+ const client = useAgo();
205
+ onMounted(() => {
206
+ client.registerNavigationFunction(navigate, routes);
207
+ });
208
+ onUnmounted(() => {
209
+ client.unregisterFunction("navigateToPage");
210
+ });
211
+ }
212
+ function useAgoEvents(event, handler) {
213
+ const client = useAgo();
214
+ onMounted(() => {
215
+ client.on(event, handler);
216
+ });
217
+ onUnmounted(() => {
218
+ client.off(event, handler);
219
+ });
220
+ }
221
+ export {
222
+ AGO_CLIENT_KEY,
223
+ AgoPlugin,
224
+ useAgo,
225
+ useAgoEvents,
226
+ useAgoFunction,
227
+ useAgoNavigation,
228
+ useChat,
229
+ useConversation,
230
+ useMessages
231
+ };
232
+ //# sourceMappingURL=vue.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vue.js","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"],"names":[],"mappings":";;AAGO,MAAM,iBAA0C,OAAO,YAAY;ACanE,MAAM,YAAY;AAAA,EACvB,QAAQ,KAAU,SAA2B;AAC3C,UAAM,SAAS,IAAI,UAAU,OAAO;AACpC,QAAI,QAAQ,gBAAgB,MAAM;AAAA,EACpC;AACF;ACFO,SAAS,OAAO,QAA+B;AACpD,MAAI,QAAQ;AACV,WAAO,IAAI,UAAU,MAAM;AAAA,EAC7B;AAEA,QAAM,SAAS,OAAO,cAAc;AACpC,MAAI,CAAC,QAAQ;AACX,UAAM,IAAI;AAAA,MACR;AAAA,IAAA;AAAA,EAEJ;AACA,SAAO;AACT;ACdO,SAAS,YAAY,UAA8B,IAAI;AAC5D,QAAM,SAAS,QAAQ,UAAU,OAAA;AAEjC,QAAM,WAAW,IAAkB,EAAE;AACrC,QAAM,iBAAiB,IAAwB,QAAQ,cAAc;AACrE,QAAM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adata?: Record<string, unknown>;
37
38
  }
38
39
  declare global {
39
40
  interface Window {