@useago/sdk 0.2.1 → 0.3.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/README.md +2 -1
- package/dist/AgoClient-B-SONi_K.js +861 -0
- package/dist/AgoClient-B-SONi_K.js.map +1 -0
- package/dist/AgoClient-xTWfMWKh.cjs +860 -0
- package/dist/AgoClient-xTWfMWKh.cjs.map +1 -0
- package/dist/angular.cjs +100 -138
- package/dist/angular.cjs.map +1 -1
- package/dist/angular.d.ts +0 -1
- package/dist/angular.js +103 -139
- package/dist/angular.js.map +1 -1
- package/dist/client/AgoClient.d.ts +0 -56
- package/dist/client/types.d.ts +1 -5
- package/dist/createMockClient-B1DcBiIK.js +94 -0
- package/dist/createMockClient-B1DcBiIK.js.map +1 -0
- package/dist/createMockClient-BqNSJUu4.cjs +93 -0
- package/dist/createMockClient-BqNSJUu4.cjs.map +1 -0
- package/dist/helpers.cjs +305 -14
- package/dist/helpers.cjs.map +1 -0
- package/dist/helpers.d.ts +0 -1
- package/dist/helpers.js +306 -2
- package/dist/helpers.js.map +1 -0
- package/dist/index.cjs +151 -284
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +0 -3
- package/dist/index.js +163 -258
- package/dist/index.js.map +1 -1
- package/dist/react/components/ChatWidget.d.ts +0 -2
- package/dist/react/components/Message.d.ts +0 -2
- package/dist/react/components/index.d.ts +0 -2
- package/dist/react/context/AgoContext.d.ts +3 -29
- package/dist/react/context/index.d.ts +1 -1
- package/dist/react/hooks/index.d.ts +0 -1
- package/dist/react/hooks/useAgoFunction.d.ts +2 -14
- package/dist/react/index.d.ts +1 -4
- package/dist/react.cjs +10274 -22104
- package/dist/react.cjs.map +1 -1
- package/dist/react.d.ts +0 -1
- package/dist/react.js +10289 -22103
- package/dist/react.js.map +1 -1
- package/dist/vue.cjs +208 -287
- package/dist/vue.cjs.map +1 -1
- package/dist/vue.d.ts +0 -1
- package/dist/vue.js +218 -287
- package/dist/vue.js.map +1 -1
- package/dist/widget/types.d.ts +0 -1
- package/dist/widget.cjs +2 -0
- package/dist/widget.cjs.map +1 -0
- package/dist/widget.d.ts +0 -1
- package/dist/widget.js +2 -0
- package/dist/widget.js.map +1 -0
- package/package.json +1 -1
- package/dist/AgoClient-CNT-8sh_.js +0 -905
- package/dist/AgoClient-CNT-8sh_.js.map +0 -1
- package/dist/AgoClient-D0l1GTRs.cjs +0 -976
- package/dist/AgoClient-D0l1GTRs.cjs.map +0 -1
- package/dist/createMockClient-Ci_N2tH8.cjs +0 -104
- package/dist/createMockClient-Ci_N2tH8.cjs.map +0 -1
- package/dist/createMockClient-U0ae_AYy.js +0 -99
- package/dist/createMockClient-U0ae_AYy.js.map +0 -1
- package/dist/functions--c6lx3ic.cjs +0 -480
- package/dist/functions--c6lx3ic.cjs.map +0 -1
- package/dist/functions-C9F1dnmh.js +0 -398
- package/dist/functions-C9F1dnmh.js.map +0 -1
- package/dist/helpers/factory.d.ts +0 -20
- package/dist/react/components/Markdown.d.ts +0 -12
- package/dist/react/hooks/useAgoContext.d.ts +0 -40
- package/dist/rolldown-runtime-BqCkTl7Q.cjs +0 -50
- package/dist/rolldown-runtime-CNZpIYwj.js +0 -33
- package/dist/state/ClientContextRegistry.d.ts +0 -64
package/dist/vue.cjs
CHANGED
|
@@ -1,303 +1,225 @@
|
|
|
1
|
+
"use strict";
|
|
1
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
require("./
|
|
3
|
-
const
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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
|
-
*/
|
|
3
|
+
const AgoClient = require("./AgoClient-xTWfMWKh.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
|
+
};
|
|
38
12
|
function useAgo(config) {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
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;
|
|
43
23
|
}
|
|
44
|
-
//#endregion
|
|
45
|
-
//#region src/vue/composables/useMessages.ts
|
|
46
|
-
/**
|
|
47
|
-
* Composable to manage messages in a conversation.
|
|
48
|
-
*
|
|
49
|
-
* ```ts
|
|
50
|
-
* const { messages, sendMessage, isLoading } = useMessages();
|
|
51
|
-
* ```
|
|
52
|
-
*/
|
|
53
24
|
function useMessages(options = {}) {
|
|
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
|
-
|
|
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
|
-
|
|
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 };
|
|
146
118
|
}
|
|
147
|
-
//#endregion
|
|
148
|
-
//#region src/vue/composables/useConversation.ts
|
|
149
|
-
/**
|
|
150
|
-
* Composable to manage conversations.
|
|
151
|
-
*
|
|
152
|
-
* ```ts
|
|
153
|
-
* const { conversations, selectConversation } = useConversation();
|
|
154
|
-
* ```
|
|
155
|
-
*/
|
|
156
119
|
function useConversation(options = {}) {
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
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
|
+
};
|
|
200
163
|
}
|
|
201
|
-
//#endregion
|
|
202
|
-
//#region src/vue/composables/useChat.ts
|
|
203
|
-
/**
|
|
204
|
-
* All-in-one composable combining messages + conversations.
|
|
205
|
-
*
|
|
206
|
-
* ```ts
|
|
207
|
-
* const { messages, sendMessage, conversations, selectConversation } = useChat();
|
|
208
|
-
* ```
|
|
209
|
-
*/
|
|
210
164
|
function useChat(options = {}) {
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
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
|
+
};
|
|
234
192
|
}
|
|
235
|
-
//#endregion
|
|
236
|
-
//#region src/vue/composables/useAgoFunction.ts
|
|
237
|
-
/**
|
|
238
|
-
* Register a client-side function with auto-cleanup on unmount.
|
|
239
|
-
*
|
|
240
|
-
* ```ts
|
|
241
|
-
* useAgoFunction("showToast", {
|
|
242
|
-
* description: "Show a toast",
|
|
243
|
-
* parameters: { type: "object", properties: { message: { type: "string" } } },
|
|
244
|
-
* handler: async (args) => { toast(args.message); return { shown: true }; },
|
|
245
|
-
* });
|
|
246
|
-
* ```
|
|
247
|
-
*/
|
|
248
193
|
function useAgoFunction(name, options) {
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
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
|
+
});
|
|
259
204
|
}
|
|
260
|
-
/**
|
|
261
|
-
* Register navigation routes with auto-cleanup on unmount.
|
|
262
|
-
* Works with vue-router's `useRouter().push`.
|
|
263
|
-
*
|
|
264
|
-
* ```ts
|
|
265
|
-
* const router = useRouter();
|
|
266
|
-
* useAgoNavigation((path) => router.push(path), [
|
|
267
|
-
* { name: "dashboard", path: "/dashboard", description: "Main dashboard" },
|
|
268
|
-
* ]);
|
|
269
|
-
* ```
|
|
270
|
-
*/
|
|
271
205
|
function useAgoNavigation(navigate, routes) {
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
206
|
+
const client = useAgo();
|
|
207
|
+
vue.onMounted(() => {
|
|
208
|
+
client.registerNavigationFunction(navigate, routes);
|
|
209
|
+
});
|
|
210
|
+
vue.onUnmounted(() => {
|
|
211
|
+
client.unregisterFunction("navigateToPage");
|
|
212
|
+
});
|
|
279
213
|
}
|
|
280
|
-
//#endregion
|
|
281
|
-
//#region src/vue/composables/useAgoEvents.ts
|
|
282
|
-
/**
|
|
283
|
-
* Subscribe to AGO client events with auto-cleanup on unmount.
|
|
284
|
-
*
|
|
285
|
-
* ```ts
|
|
286
|
-
* useAgoEvents("message:complete", (msg) => {
|
|
287
|
-
* console.log("Got message:", msg.content);
|
|
288
|
-
* });
|
|
289
|
-
* ```
|
|
290
|
-
*/
|
|
291
214
|
function useAgoEvents(event, handler) {
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
215
|
+
const client = useAgo();
|
|
216
|
+
vue.onMounted(() => {
|
|
217
|
+
client.on(event, handler);
|
|
218
|
+
});
|
|
219
|
+
vue.onUnmounted(() => {
|
|
220
|
+
client.off(event, handler);
|
|
221
|
+
});
|
|
299
222
|
}
|
|
300
|
-
//#endregion
|
|
301
223
|
exports.AGO_CLIENT_KEY = AGO_CLIENT_KEY;
|
|
302
224
|
exports.AgoPlugin = AgoPlugin;
|
|
303
225
|
exports.useAgo = useAgo;
|
|
@@ -307,5 +229,4 @@ exports.useAgoNavigation = useAgoNavigation;
|
|
|
307
229
|
exports.useChat = useChat;
|
|
308
230
|
exports.useConversation = useConversation;
|
|
309
231
|
exports.useMessages = useMessages;
|
|
310
|
-
|
|
311
|
-
//# sourceMappingURL=vue.cjs.map
|
|
232
|
+
//# sourceMappingURL=vue.cjs.map
|
package/dist/vue.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vue.cjs","names":[],"sources":["../src/vue/symbols.ts","../src/vue/plugin.ts","../src/vue/composables/useAgo.ts","../src/vue/composables/useMessages.ts","../src/vue/composables/useConversation.ts","../src/vue/composables/useChat.ts","../src/vue/composables/useAgoFunction.ts","../src/vue/composables/useAgoEvents.ts"],"sourcesContent":["import type { InjectionKey } from \"vue\";\nimport type { AgoClient } from \"../client/AgoClient\";\n\nexport const AGO_CLIENT_KEY: InjectionKey<AgoClient> = Symbol(\"ago-client\");\n","import type { App } from \"vue\";\nimport { AgoClient } from \"../client/AgoClient\";\nimport type { AgoConfig } from \"../client/types\";\nimport { AGO_CLIENT_KEY } from \"./symbols\";\n\nexport interface AgoPluginOptions extends AgoConfig {}\n\n/**\n * Vue plugin that provides an AgoClient to the entire app via inject/provide.\n *\n * ```ts\n * import { AgoPlugin } from \"@useago/sdk/vue\";\n *\n * app.use(AgoPlugin, { baseUrl: \"https://YOUR-DOMAIN.useago.com\" });\n * ```\n */\nexport const AgoPlugin = {\n install(app: App, options: AgoPluginOptions) {\n const client = new AgoClient(options);\n app.provide(AGO_CLIENT_KEY, client);\n },\n};\n","import { inject } from \"vue\";\nimport { AgoClient } from \"../../client/AgoClient\";\nimport type { AgoConfig } from \"../../client/types\";\nimport { AGO_CLIENT_KEY } from \"../symbols\";\n\n/**\n * Get or create an AgoClient.\n *\n * - Without args: returns the client from `AgoPlugin` (throws if none).\n * - With config: creates a new client instance.\n *\n * ```ts\n * // From plugin\n * const client = useAgo();\n *\n * // Standalone\n * const client = useAgo({ baseUrl: \"https://YOUR-DOMAIN.useago.com\" });\n * ```\n */\nexport function useAgo(config?: AgoConfig): AgoClient {\n if (config) {\n return new AgoClient(config);\n }\n\n const client = inject(AGO_CLIENT_KEY);\n if (!client) {\n throw new Error(\n \"useAgo(): no AgoClient found. Either pass config or install AgoPlugin.\"\n );\n }\n return client;\n}\n","import { ref, onMounted, onUnmounted } from \"vue\";\nimport type { AgoClient } from \"../../client/AgoClient\";\nimport type { AgoMessage } from \"../../client/types\";\nimport { useAgo } from \"./useAgo\";\n\nexport interface UseMessagesOptions {\n client?: AgoClient;\n conversationId?: string;\n}\n\n/**\n * Composable to manage messages in a conversation.\n *\n * ```ts\n * const { messages, sendMessage, isLoading } = useMessages();\n * ```\n */\nexport function useMessages(options: UseMessagesOptions = {}) {\n const client = options.client ?? useAgo();\n\n const messages = ref<AgoMessage[]>([]);\n const conversationId = ref<string | undefined>(options.conversationId);\n const isLoading = ref(false);\n const error = ref<Error | null>(null);\n\n const handleStart = (data: { conversationId: string; messageId: string }) => {\n if (!conversationId.value) {\n conversationId.value = data.conversationId;\n }\n };\n\n const handleChunk = (data: { content: string; messageId: string }) => {\n const idx = messages.value.findIndex((m: AgoMessage) => m.id === data.messageId);\n if (idx >= 0) {\n messages.value[idx] = {\n ...messages.value[idx],\n content: messages.value[idx].content + data.content,\n };\n }\n };\n\n const handleComplete = (message: AgoMessage) => {\n const idx = messages.value.findIndex((m: AgoMessage) => m.id === message.id);\n if (idx >= 0) {\n messages.value[idx] = message;\n } else {\n messages.value.push(message);\n }\n isLoading.value = false;\n };\n\n const handleError = (data: { error: string }) => {\n error.value = new Error(data.error);\n isLoading.value = false;\n };\n\n onMounted(() => {\n client.on(\"message:start\", handleStart);\n client.on(\"message:chunk\", handleChunk);\n client.on(\"message:complete\", handleComplete);\n client.on(\"message:error\", handleError);\n });\n\n onUnmounted(() => {\n client.off(\"message:start\", handleStart);\n client.off(\"message:chunk\", handleChunk);\n client.off(\"message:complete\", handleComplete);\n client.off(\"message:error\", handleError);\n });\n\n async function sendMessage(content: string, files?: File[]): Promise<AgoMessage | null> {\n isLoading.value = true;\n error.value = null;\n\n // Optimistic user message\n const userMsg: AgoMessage = {\n id: `temp-${Date.now()}`,\n conversationId: conversationId.value || \"\",\n content,\n role: \"user\",\n status: \"DONE\",\n createdAt: new Date(),\n };\n const assistantMsg: AgoMessage = {\n id: `temp-assistant-${Date.now()}`,\n conversationId: conversationId.value || \"\",\n content: \"\",\n role: \"assistant\",\n status: \"IN_PROGRESS\",\n createdAt: new Date(),\n };\n messages.value.push(userMsg, assistantMsg);\n\n try {\n const response = await client.sendMessage(content, {\n conversationId: conversationId.value,\n files,\n });\n if (response.conversationId && !conversationId.value) {\n conversationId.value = response.conversationId;\n }\n // Replace temp messages\n messages.value = messages.value.filter((m: AgoMessage) => !m.id.startsWith(\"temp-\"));\n const updatedUser = { ...userMsg, id: userMsg.id.replace(\"temp-\", \"user-\"), conversationId: response.conversationId };\n if (!messages.value.some((m: AgoMessage) => m.id === response.id)) {\n messages.value.push(updatedUser, response);\n } else {\n messages.value.push(updatedUser);\n }\n return response;\n } catch (err) {\n error.value = err instanceof Error ? err : new Error(\"Failed to send\");\n isLoading.value = false;\n messages.value = messages.value.filter((m: AgoMessage) => !m.id.startsWith(\"temp-\"));\n return null;\n }\n }\n\n function clearMessages() {\n messages.value = [];\n conversationId.value = undefined;\n error.value = null;\n }\n\n return { messages, isLoading, error, conversationId, sendMessage, clearMessages };\n}\n","import { ref, onMounted } from \"vue\";\nimport type { AgoClient } from \"../../client/AgoClient\";\nimport type { Conversation } from \"../../client/types\";\nimport { useAgo } from \"./useAgo\";\n\nexport interface UseConversationOptions {\n client?: AgoClient;\n autoLoad?: boolean;\n}\n\n/**\n * Composable to manage conversations.\n *\n * ```ts\n * const { conversations, selectConversation } = useConversation();\n * ```\n */\nexport function useConversation(options: UseConversationOptions = {}) {\n const client = options.client ?? useAgo();\n const autoLoad = options.autoLoad ?? true;\n\n const conversations = ref<Conversation[]>([]);\n const currentConversation = ref<Conversation | null>(null);\n const isLoading = ref(false);\n const error = ref<Error | null>(null);\n\n async function refreshConversations() {\n isLoading.value = true;\n error.value = null;\n try {\n conversations.value = await client.getConversations();\n } catch (err) {\n error.value = err instanceof Error ? err : new Error(\"Failed to load conversations\");\n } finally {\n isLoading.value = false;\n }\n }\n\n async function selectConversation(id: string) {\n isLoading.value = true;\n error.value = null;\n try {\n currentConversation.value = await client.getConversation(id);\n } catch (err) {\n error.value = err instanceof Error ? err : new Error(\"Failed to load conversation\");\n } finally {\n isLoading.value = false;\n }\n }\n\n function startNewConversation() {\n currentConversation.value = null;\n }\n\n onMounted(() => {\n if (autoLoad) refreshConversations();\n });\n\n return {\n conversations,\n currentConversation,\n isLoading,\n error,\n selectConversation,\n startNewConversation,\n refreshConversations,\n };\n}\n","import { computed } from \"vue\";\nimport type { AgoClient } from \"../../client/AgoClient\";\nimport { useMessages } from \"./useMessages\";\nimport { useConversation } from \"./useConversation\";\n\nexport interface UseChatOptions {\n client?: AgoClient;\n conversationId?: string;\n autoLoad?: boolean;\n}\n\n/**\n * All-in-one composable combining messages + conversations.\n *\n * ```ts\n * const { messages, sendMessage, conversations, selectConversation } = useChat();\n * ```\n */\nexport function useChat(options: UseChatOptions = {}) {\n const msgResult = useMessages({\n client: options.client,\n conversationId: options.conversationId,\n });\n\n const convResult = useConversation({\n client: options.client,\n autoLoad: options.autoLoad,\n });\n\n const error = computed(\n () => msgResult.error.value || convResult.error.value\n );\n\n return {\n // Messages\n messages: msgResult.messages,\n isLoading: msgResult.isLoading,\n error,\n sendMessage: msgResult.sendMessage,\n clearMessages: msgResult.clearMessages,\n conversationId: msgResult.conversationId,\n // Conversations\n conversations: convResult.conversations,\n currentConversation: convResult.currentConversation,\n isConversationsLoading: convResult.isLoading,\n selectConversation: convResult.selectConversation,\n startNewConversation: convResult.startNewConversation,\n refreshConversations: convResult.refreshConversations,\n };\n}\n","import { onMounted, onUnmounted } from \"vue\";\nimport type { ClientFunctionHandler, ClientFunctionSchema } from \"../../functions/types\";\nimport { useAgo } from \"./useAgo\";\n\n/**\n * Register a client-side function with auto-cleanup on unmount.\n *\n * ```ts\n * useAgoFunction(\"showToast\", {\n * description: \"Show a toast\",\n * parameters: { type: \"object\", properties: { message: { type: \"string\" } } },\n * handler: async (args) => { toast(args.message); return { shown: true }; },\n * });\n * ```\n */\nexport function useAgoFunction(\n name: string,\n options: {\n description: string;\n parameters: ClientFunctionSchema[\"parameters\"];\n handler: ClientFunctionHandler;\n }\n): void {\n const client = useAgo();\n\n onMounted(() => {\n client.registerFunction(name, options.handler, {\n description: options.description,\n parameters: options.parameters,\n });\n });\n\n onUnmounted(() => {\n client.unregisterFunction(name);\n });\n}\n\nexport interface AgoRoute {\n name: string;\n path: string;\n description: string;\n}\n\n/**\n * Register navigation routes with auto-cleanup on unmount.\n * Works with vue-router's `useRouter().push`.\n *\n * ```ts\n * const router = useRouter();\n * useAgoNavigation((path) => router.push(path), [\n * { name: \"dashboard\", path: \"/dashboard\", description: \"Main dashboard\" },\n * ]);\n * ```\n */\nexport function useAgoNavigation(\n navigate: (path: string) => void,\n routes: AgoRoute[]\n): void {\n const client = useAgo();\n\n onMounted(() => {\n client.registerNavigationFunction(navigate, routes);\n });\n\n onUnmounted(() => {\n client.unregisterFunction(\"navigateToPage\");\n });\n}\n","import { onMounted, onUnmounted } from \"vue\";\nimport type { AgoClientEvents, AgoEventName } from \"../../client/types\";\nimport { useAgo } from \"./useAgo\";\n\n/**\n * Subscribe to AGO client events with auto-cleanup on unmount.\n *\n * ```ts\n * useAgoEvents(\"message:complete\", (msg) => {\n * console.log(\"Got message:\", msg.content);\n * });\n * ```\n */\nexport function useAgoEvents<K extends AgoEventName>(\n event: K,\n handler: (data: AgoClientEvents[K]) => void\n): void {\n const client = useAgo();\n\n onMounted(() => {\n client.on(event, handler);\n });\n\n onUnmounted(() => {\n client.off(event, handler);\n });\n}\n"],"mappings":";;;;;AAGA,IAAa,iBAA0C,OAAO,aAAa;;;;;;;;;;;;ACa3E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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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