@useago/sdk 0.1.7 → 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.
- package/dist/AgoClient-CNT-8sh_.js +905 -0
- package/dist/AgoClient-CNT-8sh_.js.map +1 -0
- package/dist/AgoClient-D0l1GTRs.cjs +976 -0
- package/dist/AgoClient-D0l1GTRs.cjs.map +1 -0
- package/dist/angular.cjs +138 -100
- package/dist/angular.cjs.map +1 -1
- package/dist/angular.d.ts +1 -0
- package/dist/angular.js +139 -103
- package/dist/angular.js.map +1 -1
- package/dist/client/types.d.ts +5 -1
- package/dist/createMockClient-Ci_N2tH8.cjs +104 -0
- package/dist/createMockClient-Ci_N2tH8.cjs.map +1 -0
- package/dist/createMockClient-U0ae_AYy.js +99 -0
- package/dist/createMockClient-U0ae_AYy.js.map +1 -0
- package/dist/functions--c6lx3ic.cjs +480 -0
- package/dist/functions--c6lx3ic.cjs.map +1 -0
- package/dist/functions-C9F1dnmh.js +398 -0
- package/dist/functions-C9F1dnmh.js.map +1 -0
- package/dist/helpers.cjs +14 -16
- package/dist/helpers.d.ts +1 -0
- package/dist/helpers.js +2 -17
- package/dist/index.cjs +281 -153
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +256 -166
- package/dist/index.js.map +1 -1
- package/dist/react/components/ChatWidget.d.ts +2 -0
- package/dist/react/components/Markdown.d.ts +12 -0
- package/dist/react/components/Message.d.ts +2 -0
- package/dist/react/components/index.d.ts +2 -0
- package/dist/react/index.d.ts +2 -0
- package/dist/react.cjs +22099 -10333
- package/dist/react.cjs.map +1 -1
- package/dist/react.d.ts +1 -0
- package/dist/react.js +22099 -10349
- package/dist/react.js.map +1 -1
- package/dist/rolldown-runtime-BqCkTl7Q.cjs +50 -0
- package/dist/rolldown-runtime-CNZpIYwj.js +33 -0
- package/dist/vue.cjs +287 -208
- package/dist/vue.cjs.map +1 -1
- package/dist/vue.d.ts +1 -0
- package/dist/vue.js +287 -218
- package/dist/vue.js.map +1 -1
- package/dist/widget.cjs +0 -2
- package/dist/widget.d.ts +1 -0
- package/dist/widget.js +0 -2
- package/package.json +8 -6
- package/dist/AgoClient-BDO4avLq.cjs +0 -1036
- package/dist/AgoClient-BDO4avLq.cjs.map +0 -1
- package/dist/AgoClient-D-c91tx5.js +0 -1037
- package/dist/AgoClient-D-c91tx5.js.map +0 -1
- package/dist/createMockClient-B1DcBiIK.js +0 -94
- package/dist/createMockClient-B1DcBiIK.js.map +0 -1
- package/dist/createMockClient-BqNSJUu4.cjs +0 -93
- package/dist/createMockClient-BqNSJUu4.cjs.map +0 -1
- package/dist/functions-B0Z0rNQW.cjs +0 -306
- package/dist/functions-B0Z0rNQW.cjs.map +0 -1
- package/dist/functions-C-wLEc8b.js +0 -306
- package/dist/functions-C-wLEc8b.js.map +0 -1
- package/dist/helpers.cjs.map +0 -1
- package/dist/helpers.js.map +0 -1
- package/dist/widget.cjs.map +0 -1
- package/dist/widget.js.map +0 -1
package/dist/vue.cjs.map
CHANGED
|
@@ -1 +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,MAAM,YAAY;AAAA,EACvB,QAAQ,KAAU,SAA2B;AAC3C,UAAM,SAAS,IAAIA,UAAAA,UAAU,OAAO;AACpC,QAAI,QAAQ,gBAAgB,MAAM;AAAA,EACpC;AACF;ACFO,SAAS,OAAO,QAA+B;AACpD,MAAI,QAAQ;AACV,WAAO,IAAIA,UAAAA,UAAU,MAAM;AAAA,EAC7B;AAEA,QAAM,SAASC,IAAAA,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,WAAWC,IAAAA,IAAkB,EAAE;AACrC,QAAM,iBAAiBA,IAAAA,IAAwB,QAAQ,cAAc;AACrE,QAAM,YAAYA,IAAAA,IAAI,KAAK;AAC3B,QAAM,QAAQA,IAAAA,IAAkB,IAAI;AAEpC,QAAM,cAAc,CAAC,SAAwD;AAC3E,QAAI,CAAC,eAAe,OAAO;AACzB,qBAAe,QAAQ,KAAK;AAAA,IAC9B;AAAA,EACF;AAEA,QAAM,cAAc,CAAC,SAAiD;AACpE,UAAM,MAAM,SAAS,MAAM,UAAU,CAAC,MAAkB,EAAE,OAAO,KAA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,UAAU,UAAU;AAAA,IACpB,WAAW,UAAU;AAAA,IACrB;AAAA,IACA,aAAa,UAAU;AAAA,IACvB,eAAe,UAAU;AAAA,IACzB,gBAAgB,UAAU;AAAA;AAAA,IAE1B,eAAe,WAAW;AAAA,IAC1B,qBAAqB,WAAW;AAAA,IAChC,wBAAwB,WAAW;AAAA,IACnC,oBAAoB,WAAW;AAAA,IAC/B,sBAAsB,WAAW;AAAA,IACjC,sBAAsB,WAAW;AAAA,EAAA;AAErC;AClCO,SAAS,eACd,MACA,SAKM;AACN,QAAM,SAAS,OAAA;AAEfF,MAAAA,UAAU,MAAM;AACd,WAAO,iBAAiB,MAAM,QAAQ,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;;;;;;;;;;"}
|
|
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,YAAY,EACvB,QAAQ,KAAU,SAA2B;CAC3C,MAAM,SAAS,IAAI,kBAAA,UAAU,QAAQ;AACrC,KAAI,QAAQ,gBAAgB,OAAO;GAEtC;;;;;;;;;;;;;;;;;ACFD,SAAgB,OAAO,QAA+B;AACpD,KAAI,OACF,QAAO,IAAI,kBAAA,UAAU,OAAO;CAG9B,MAAM,UAAA,GAAA,IAAA,QAAgB,eAAe;AACrC,KAAI,CAAC,OACH,OAAM,IAAI,MACR,yEACD;AAEH,QAAO;;;;;;;;;;;ACbT,SAAgB,YAAY,UAA8B,EAAE,EAAE;CAC5D,MAAM,SAAS,QAAQ,UAAU,QAAQ;CAEzC,MAAM,YAAA,GAAA,IAAA,KAA6B,EAAE,CAAC;CACtC,MAA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;;;ACjCH,SAAgB,eACd,MACA,SAKM;CACN,MAAM,SAAS,QAAQ;AAEvB,EAAA,GAAA,IAAA,iBAAgB;AACd,SAAO,iBAAiB,MAAM,QAAQ,SAAS;GAC7C,aAAa,QAAQ;GACrB,YAAY,QAAQ;GACrB,CAAC;GACF;AAEF,EAAA,GAAA,IAAA,mBAAkB;AAChB,SAAO,mBAAmB,KAAK;GAC/B;;;;;;;;;;;;;AAoBJ,SAAgB,iBACd,UACA,QACM;CACN,MAAM,SAAS,QAAQ;AAEvB,EAAA,GAAA,IAAA,iBAAgB;AACd,SAAO,2BAA2B,UAAU,OAAO;GACnD;AAEF,EAAA,GAAA,IAAA,mBAAkB;AAChB,SAAO,mBAAmB,iBAAiB;GAC3C;;;;;;;;;;;;;ACrDJ,SAAgB,aACd,OACA,SACM;CACN,MAAM,SAAS,QAAQ;AAEvB,EAAA,GAAA,IAAA,iBAAgB;AACd,SAAO,GAAG,OAAO,QAAQ;GACzB;AAEF,EAAA,GAAA,IAAA,mBAAkB;AAChB,SAAO,IAAI,OAAO,QAAQ;GAC1B"}
|
package/dist/vue.d.ts
CHANGED
package/dist/vue.js
CHANGED
|
@@ -1,232 +1,301 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
import { t as AgoClient } from "./AgoClient-CNT-8sh_.js";
|
|
2
|
+
import { computed, inject, onMounted, onUnmounted, ref } 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);
|
|
19
|
+
} };
|
|
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
|
+
*/
|
|
10
36
|
function useAgo(config) {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
if (!client) {
|
|
16
|
-
throw new Error(
|
|
17
|
-
"useAgo(): no AgoClient found. Either pass config or install AgoPlugin."
|
|
18
|
-
);
|
|
19
|
-
}
|
|
20
|
-
return client;
|
|
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;
|
|
21
41
|
}
|
|
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
|
+
*/
|
|
22
51
|
function useMessages(options = {}) {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
return { messages, isLoading, error, conversationId, sendMessage, clearMessages };
|
|
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
|
+
};
|
|
116
144
|
}
|
|
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
|
+
*/
|
|
117
154
|
function useConversation(options = {}) {
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
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
|
+
};
|
|
161
198
|
}
|
|
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
|
+
*/
|
|
162
208
|
function useChat(options = {}) {
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
selectConversation: convResult.selectConversation,
|
|
187
|
-
startNewConversation: convResult.startNewConversation,
|
|
188
|
-
refreshConversations: convResult.refreshConversations
|
|
189
|
-
};
|
|
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
|
+
};
|
|
190
232
|
}
|
|
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
|
+
*/
|
|
191
246
|
function useAgoFunction(name, options) {
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
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
|
+
});
|
|
202
257
|
}
|
|
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
|
+
*/
|
|
203
269
|
function useAgoNavigation(navigate, routes) {
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
270
|
+
const client = useAgo();
|
|
271
|
+
onMounted(() => {
|
|
272
|
+
client.registerNavigationFunction(navigate, routes);
|
|
273
|
+
});
|
|
274
|
+
onUnmounted(() => {
|
|
275
|
+
client.unregisterFunction("navigateToPage");
|
|
276
|
+
});
|
|
211
277
|
}
|
|
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
|
+
*/
|
|
212
289
|
function useAgoEvents(event, handler) {
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
290
|
+
const client = useAgo();
|
|
291
|
+
onMounted(() => {
|
|
292
|
+
client.on(event, handler);
|
|
293
|
+
});
|
|
294
|
+
onUnmounted(() => {
|
|
295
|
+
client.off(event, handler);
|
|
296
|
+
});
|
|
220
297
|
}
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
useAgoEvents,
|
|
226
|
-
useAgoFunction,
|
|
227
|
-
useAgoNavigation,
|
|
228
|
-
useChat,
|
|
229
|
-
useConversation,
|
|
230
|
-
useMessages
|
|
231
|
-
};
|
|
232
|
-
//# sourceMappingURL=vue.js.map
|
|
298
|
+
//#endregion
|
|
299
|
+
export { AGO_CLIENT_KEY, AgoPlugin, useAgo, useAgoEvents, useAgoFunction, useAgoNavigation, useChat, useConversation, useMessages };
|
|
300
|
+
|
|
301
|
+
//# sourceMappingURL=vue.js.map
|