@useago/sdk 0.1.7 → 0.2.1
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/README.md +101 -6
- 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
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
//#region \0rolldown/runtime.js
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __commonJSMin = (cb, mod) => () => (mod || (cb((mod = { exports: {} }).exports, mod), cb = null), mod.exports);
|
|
9
|
+
var __exportAll = (all, no_symbols) => {
|
|
10
|
+
let target = {};
|
|
11
|
+
for (var name in all) __defProp(target, name, {
|
|
12
|
+
get: all[name],
|
|
13
|
+
enumerable: true
|
|
14
|
+
});
|
|
15
|
+
if (!no_symbols) __defProp(target, Symbol.toStringTag, { value: "Module" });
|
|
16
|
+
return target;
|
|
17
|
+
};
|
|
18
|
+
var __copyProps = (to, from, except, desc) => {
|
|
19
|
+
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
20
|
+
key = keys[i];
|
|
21
|
+
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
22
|
+
get: ((k) => from[k]).bind(null, key),
|
|
23
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
return to;
|
|
27
|
+
};
|
|
28
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
29
|
+
value: mod,
|
|
30
|
+
enumerable: true
|
|
31
|
+
}) : target, mod));
|
|
32
|
+
//#endregion
|
|
33
|
+
Object.defineProperty(exports, "__commonJSMin", {
|
|
34
|
+
enumerable: true,
|
|
35
|
+
get: function() {
|
|
36
|
+
return __commonJSMin;
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
Object.defineProperty(exports, "__exportAll", {
|
|
40
|
+
enumerable: true,
|
|
41
|
+
get: function() {
|
|
42
|
+
return __exportAll;
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
Object.defineProperty(exports, "__toESM", {
|
|
46
|
+
enumerable: true,
|
|
47
|
+
get: function() {
|
|
48
|
+
return __toESM;
|
|
49
|
+
}
|
|
50
|
+
});
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
//#region \0rolldown/runtime.js
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __commonJSMin = (cb, mod) => () => (mod || (cb((mod = { exports: {} }).exports, mod), cb = null), mod.exports);
|
|
9
|
+
var __exportAll = (all, no_symbols) => {
|
|
10
|
+
let target = {};
|
|
11
|
+
for (var name in all) __defProp(target, name, {
|
|
12
|
+
get: all[name],
|
|
13
|
+
enumerable: true
|
|
14
|
+
});
|
|
15
|
+
if (!no_symbols) __defProp(target, Symbol.toStringTag, { value: "Module" });
|
|
16
|
+
return target;
|
|
17
|
+
};
|
|
18
|
+
var __copyProps = (to, from, except, desc) => {
|
|
19
|
+
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
20
|
+
key = keys[i];
|
|
21
|
+
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
22
|
+
get: ((k) => from[k]).bind(null, key),
|
|
23
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
return to;
|
|
27
|
+
};
|
|
28
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
29
|
+
value: mod,
|
|
30
|
+
enumerable: true
|
|
31
|
+
}) : target, mod));
|
|
32
|
+
//#endregion
|
|
33
|
+
export { __exportAll as n, __toESM as r, __commonJSMin as t };
|
package/dist/vue.cjs
CHANGED
|
@@ -1,225 +1,303 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
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
|
+
*/
|
|
12
38
|
function useAgo(config) {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
if (!client) {
|
|
18
|
-
throw new Error(
|
|
19
|
-
"useAgo(): no AgoClient found. Either pass config or install AgoPlugin."
|
|
20
|
-
);
|
|
21
|
-
}
|
|
22
|
-
return client;
|
|
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;
|
|
23
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
|
+
*/
|
|
24
53
|
function useMessages(options = {}) {
|
|
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
|
-
|
|
116
|
-
|
|
117
|
-
return { messages, isLoading, error, conversationId, sendMessage, clearMessages };
|
|
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
|
+
};
|
|
118
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
|
+
*/
|
|
119
156
|
function useConversation(options = {}) {
|
|
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
|
-
|
|
161
|
-
|
|
162
|
-
|
|
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
|
+
};
|
|
163
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
|
+
*/
|
|
164
210
|
function useChat(options = {}) {
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
selectConversation: convResult.selectConversation,
|
|
189
|
-
startNewConversation: convResult.startNewConversation,
|
|
190
|
-
refreshConversations: convResult.refreshConversations
|
|
191
|
-
};
|
|
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
|
+
};
|
|
192
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
|
+
*/
|
|
193
248
|
function useAgoFunction(name, options) {
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
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
|
+
});
|
|
204
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
|
+
*/
|
|
205
271
|
function useAgoNavigation(navigate, routes) {
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
272
|
+
const client = useAgo();
|
|
273
|
+
(0, vue.onMounted)(() => {
|
|
274
|
+
client.registerNavigationFunction(navigate, routes);
|
|
275
|
+
});
|
|
276
|
+
(0, vue.onUnmounted)(() => {
|
|
277
|
+
client.unregisterFunction("navigateToPage");
|
|
278
|
+
});
|
|
213
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
|
+
*/
|
|
214
291
|
function useAgoEvents(event, handler) {
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
292
|
+
const client = useAgo();
|
|
293
|
+
(0, vue.onMounted)(() => {
|
|
294
|
+
client.on(event, handler);
|
|
295
|
+
});
|
|
296
|
+
(0, vue.onUnmounted)(() => {
|
|
297
|
+
client.off(event, handler);
|
|
298
|
+
});
|
|
222
299
|
}
|
|
300
|
+
//#endregion
|
|
223
301
|
exports.AGO_CLIENT_KEY = AGO_CLIENT_KEY;
|
|
224
302
|
exports.AgoPlugin = AgoPlugin;
|
|
225
303
|
exports.useAgo = useAgo;
|
|
@@ -229,4 +307,5 @@ exports.useAgoNavigation = useAgoNavigation;
|
|
|
229
307
|
exports.useChat = useChat;
|
|
230
308
|
exports.useConversation = useConversation;
|
|
231
309
|
exports.useMessages = useMessages;
|
|
232
|
-
|
|
310
|
+
|
|
311
|
+
//# sourceMappingURL=vue.cjs.map
|