@standardagents/vue 0.10.1-dev.d2d335e → 0.11.0-next.41deba4
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/index.cjs +116 -13
- package/dist/index.d.cts +5 -3
- package/dist/index.d.ts +5 -3
- package/dist/index.js +118 -15
- package/package.json +3 -3
package/dist/index.cjs
CHANGED
|
@@ -47,7 +47,7 @@ function fileToBase64(file) {
|
|
|
47
47
|
reader.readAsDataURL(file);
|
|
48
48
|
});
|
|
49
49
|
}
|
|
50
|
-
function useThreadSetup(
|
|
50
|
+
function useThreadSetup(threadIdInput, options = {}) {
|
|
51
51
|
const {
|
|
52
52
|
preload = true,
|
|
53
53
|
live = true,
|
|
@@ -56,6 +56,7 @@ function useThreadSetup(threadId, options = {}) {
|
|
|
56
56
|
includeSilent = false,
|
|
57
57
|
endpoint: endpointOverride
|
|
58
58
|
} = options;
|
|
59
|
+
const threadId = vue.computed(() => vue.toValue(threadIdInput));
|
|
59
60
|
const context = useStandardAgents();
|
|
60
61
|
const client$1 = endpointOverride ? new client.AgentBuilderClient(endpointOverride) : context.client;
|
|
61
62
|
const resolvedOptions = {
|
|
@@ -70,12 +71,12 @@ function useThreadSetup(threadId, options = {}) {
|
|
|
70
71
|
const isLoading = vue.ref(preload);
|
|
71
72
|
const error = vue.ref(null);
|
|
72
73
|
const pendingFiles = vue.ref([]);
|
|
74
|
+
const serverFiles = vue.ref([]);
|
|
73
75
|
const attachments = vue.ref([]);
|
|
74
|
-
const committedFiles = vue.computed(() => {
|
|
75
|
-
return client.messagesToFiles(messages.value);
|
|
76
|
-
});
|
|
77
76
|
const files = vue.computed(() => {
|
|
78
|
-
|
|
77
|
+
const serverPaths = new Set(serverFiles.value.map((f) => f.path));
|
|
78
|
+
const uniquePendingFiles = pendingFiles.value.filter((f) => !f.path || !serverPaths.has(f.path));
|
|
79
|
+
return [...uniquePendingFiles, ...serverFiles.value];
|
|
79
80
|
});
|
|
80
81
|
const eventHandlers = /* @__PURE__ */ new Map();
|
|
81
82
|
let connectionManager = null;
|
|
@@ -89,7 +90,7 @@ function useThreadSetup(threadId, options = {}) {
|
|
|
89
90
|
isLoading.value = true;
|
|
90
91
|
error.value = null;
|
|
91
92
|
try {
|
|
92
|
-
const loadedMessages = await client$1.getMessages(threadId, { depth, includeSilent });
|
|
93
|
+
const loadedMessages = await client$1.getMessages(threadId.value, { depth, includeSilent });
|
|
93
94
|
messages.value = loadedMessages;
|
|
94
95
|
} catch (err) {
|
|
95
96
|
error.value = err instanceof Error ? err : new Error(String(err));
|
|
@@ -97,9 +98,68 @@ function useThreadSetup(threadId, options = {}) {
|
|
|
97
98
|
isLoading.value = false;
|
|
98
99
|
}
|
|
99
100
|
}
|
|
101
|
+
async function loadFiles() {
|
|
102
|
+
try {
|
|
103
|
+
const fileList = await client$1.listFiles(threadId.value);
|
|
104
|
+
serverFiles.value = fileList.filter((f) => !f.isDirectory).map((f) => ({
|
|
105
|
+
id: f.path,
|
|
106
|
+
// Use path as ID for server files
|
|
107
|
+
name: f.name,
|
|
108
|
+
path: f.path,
|
|
109
|
+
mimeType: f.mimeType,
|
|
110
|
+
size: f.size,
|
|
111
|
+
isImage: f.mimeType.startsWith("image/"),
|
|
112
|
+
status: "committed",
|
|
113
|
+
localPreviewUrl: null
|
|
114
|
+
}));
|
|
115
|
+
} catch (err) {
|
|
116
|
+
console.error("Failed to load files:", err);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
function handleFileCreated(data) {
|
|
120
|
+
if (data.file.isDirectory) return;
|
|
121
|
+
const newFile = {
|
|
122
|
+
id: data.path,
|
|
123
|
+
name: data.file.name,
|
|
124
|
+
path: data.path,
|
|
125
|
+
mimeType: data.file.mimeType,
|
|
126
|
+
size: data.file.size,
|
|
127
|
+
isImage: data.file.mimeType?.startsWith("image/") || false,
|
|
128
|
+
status: "committed",
|
|
129
|
+
localPreviewUrl: null
|
|
130
|
+
};
|
|
131
|
+
const existingIndex = serverFiles.value.findIndex((f) => f.path === data.path);
|
|
132
|
+
if (existingIndex >= 0) {
|
|
133
|
+
serverFiles.value[existingIndex] = newFile;
|
|
134
|
+
} else {
|
|
135
|
+
serverFiles.value = [...serverFiles.value, newFile];
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
function handleFileUpdated(data) {
|
|
139
|
+
if (data.file.isDirectory) return;
|
|
140
|
+
const updatedFile = {
|
|
141
|
+
id: data.path,
|
|
142
|
+
name: data.file.name,
|
|
143
|
+
path: data.path,
|
|
144
|
+
mimeType: data.file.mimeType,
|
|
145
|
+
size: data.file.size,
|
|
146
|
+
isImage: data.file.mimeType?.startsWith("image/") || false,
|
|
147
|
+
status: "committed",
|
|
148
|
+
localPreviewUrl: null
|
|
149
|
+
};
|
|
150
|
+
const existingIndex = serverFiles.value.findIndex((f) => f.path === data.path);
|
|
151
|
+
if (existingIndex >= 0) {
|
|
152
|
+
serverFiles.value[existingIndex] = updatedFile;
|
|
153
|
+
} else {
|
|
154
|
+
serverFiles.value = [...serverFiles.value, updatedFile];
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
function handleFileDeleted(data) {
|
|
158
|
+
serverFiles.value = serverFiles.value.filter((f) => f.path !== data.path);
|
|
159
|
+
}
|
|
100
160
|
function connect() {
|
|
101
161
|
if (!live) return;
|
|
102
|
-
connectionManager = new client.ThreadConnectionManager(client$1, threadId, {
|
|
162
|
+
connectionManager = new client.ThreadConnectionManager(client$1, threadId.value, {
|
|
103
163
|
onStatusChange: (newStatus) => {
|
|
104
164
|
status.value = newStatus;
|
|
105
165
|
},
|
|
@@ -124,6 +184,13 @@ function useThreadSetup(threadId, options = {}) {
|
|
|
124
184
|
}
|
|
125
185
|
},
|
|
126
186
|
onEvent: (event) => {
|
|
187
|
+
if (event.eventType === "file_created") {
|
|
188
|
+
handleFileCreated(event.data);
|
|
189
|
+
} else if (event.eventType === "file_updated") {
|
|
190
|
+
handleFileUpdated(event.data);
|
|
191
|
+
} else if (event.eventType === "file_deleted") {
|
|
192
|
+
handleFileDeleted(event.data);
|
|
193
|
+
}
|
|
127
194
|
const handlers = eventHandlers.get(event.eventType);
|
|
128
195
|
if (handlers) {
|
|
129
196
|
handlers.forEach((handler) => {
|
|
@@ -177,7 +244,7 @@ function useThreadSetup(threadId, options = {}) {
|
|
|
177
244
|
height: a.height
|
|
178
245
|
}))
|
|
179
246
|
);
|
|
180
|
-
const result = await client$1.sendMessage(threadId, {
|
|
247
|
+
const result = await client$1.sendMessage(threadId.value, {
|
|
181
248
|
...payload,
|
|
182
249
|
attachments: attachmentPayloads.length > 0 ? attachmentPayloads : void 0
|
|
183
250
|
});
|
|
@@ -195,18 +262,29 @@ function useThreadSetup(threadId, options = {}) {
|
|
|
195
262
|
}
|
|
196
263
|
async function stopExecution() {
|
|
197
264
|
try {
|
|
198
|
-
await client$1.stopExecution(threadId);
|
|
265
|
+
await client$1.stopExecution(threadId.value);
|
|
199
266
|
} catch (err) {
|
|
200
267
|
error.value = err instanceof Error ? err : new Error(String(err));
|
|
201
268
|
throw err;
|
|
202
269
|
}
|
|
203
270
|
}
|
|
271
|
+
async function deleteMessage(messageId) {
|
|
272
|
+
const previousMessages = [...messages.value];
|
|
273
|
+
messages.value = messages.value.filter((m) => m.id !== messageId);
|
|
274
|
+
try {
|
|
275
|
+
await client$1.deleteMessage(threadId.value, messageId);
|
|
276
|
+
} catch (err) {
|
|
277
|
+
messages.value = previousMessages;
|
|
278
|
+
error.value = err instanceof Error ? err : new Error(String(err));
|
|
279
|
+
throw err;
|
|
280
|
+
}
|
|
281
|
+
}
|
|
204
282
|
function addFiles(filesToAdd) {
|
|
205
283
|
const items = uploadManager.queueFiles(filesToAdd);
|
|
206
284
|
pendingFiles.value = [...pendingFiles.value, ...items.map((i) => i.pending)];
|
|
207
285
|
for (const { pending, file } of items) {
|
|
208
286
|
uploadManager.executeUpload(
|
|
209
|
-
threadId,
|
|
287
|
+
threadId.value,
|
|
210
288
|
file,
|
|
211
289
|
pending.id,
|
|
212
290
|
client$1,
|
|
@@ -224,11 +302,11 @@ function useThreadSetup(threadId, options = {}) {
|
|
|
224
302
|
}
|
|
225
303
|
function getFileUrl(file) {
|
|
226
304
|
if (!file.path) return "";
|
|
227
|
-
return client$1.getFileUrl(threadId, file.path);
|
|
305
|
+
return client$1.getFileUrl(threadId.value, file.path);
|
|
228
306
|
}
|
|
229
307
|
function getThumbnailUrl(file) {
|
|
230
308
|
if (!file.path) return "";
|
|
231
|
-
return client$1.getThumbnailUrl(threadId, file.path);
|
|
309
|
+
return client$1.getThumbnailUrl(threadId.value, file.path);
|
|
232
310
|
}
|
|
233
311
|
function getPreviewUrl(file) {
|
|
234
312
|
if (!file.isImage) return null;
|
|
@@ -284,10 +362,34 @@ function useThreadSetup(threadId, options = {}) {
|
|
|
284
362
|
}
|
|
285
363
|
};
|
|
286
364
|
}
|
|
365
|
+
function disconnect() {
|
|
366
|
+
connectionManager?.disconnect();
|
|
367
|
+
connectionManager = null;
|
|
368
|
+
status.value = "disconnected";
|
|
369
|
+
}
|
|
370
|
+
vue.watch(threadId, (newThreadId, oldThreadId) => {
|
|
371
|
+
if (newThreadId !== oldThreadId) {
|
|
372
|
+
disconnect();
|
|
373
|
+
messages.value = [];
|
|
374
|
+
error.value = null;
|
|
375
|
+
pendingFiles.value = [];
|
|
376
|
+
serverFiles.value = [];
|
|
377
|
+
attachments.value.forEach((a) => {
|
|
378
|
+
if (a.previewUrl) URL.revokeObjectURL(a.previewUrl);
|
|
379
|
+
});
|
|
380
|
+
attachments.value = [];
|
|
381
|
+
if (preload) {
|
|
382
|
+
loadMessages();
|
|
383
|
+
}
|
|
384
|
+
loadFiles();
|
|
385
|
+
connect();
|
|
386
|
+
}
|
|
387
|
+
});
|
|
287
388
|
vue.onMounted(() => {
|
|
288
389
|
if (preload) {
|
|
289
390
|
loadMessages();
|
|
290
391
|
}
|
|
392
|
+
loadFiles();
|
|
291
393
|
connect();
|
|
292
394
|
});
|
|
293
395
|
vue.onUnmounted(() => {
|
|
@@ -311,6 +413,7 @@ function useThreadSetup(threadId, options = {}) {
|
|
|
311
413
|
error,
|
|
312
414
|
sendMessage,
|
|
313
415
|
stopExecution,
|
|
416
|
+
deleteMessage,
|
|
314
417
|
onEvent,
|
|
315
418
|
subscribeToEvent: onEvent,
|
|
316
419
|
// alias
|
|
@@ -391,7 +494,7 @@ var ThreadProvider = vue.defineComponent({
|
|
|
391
494
|
if (props.depth !== void 0) options.depth = props.depth;
|
|
392
495
|
if (props.includeSilent !== void 0) options.includeSilent = props.includeSilent;
|
|
393
496
|
if (props.endpoint !== void 0) options.endpoint = props.endpoint;
|
|
394
|
-
const context = useThreadSetup(props.threadId, options);
|
|
497
|
+
const context = useThreadSetup(() => props.threadId, options);
|
|
395
498
|
vue.provide(ThreadKey, context);
|
|
396
499
|
return () => slots.default?.();
|
|
397
500
|
}
|
package/dist/index.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as vue from 'vue';
|
|
2
|
-
import {
|
|
2
|
+
import { ComputedRef, Ref, InjectionKey, Plugin, PropType } from 'vue';
|
|
3
3
|
import * as _standardagents_client from '@standardagents/client';
|
|
4
4
|
import { AgentBuilderClient, SendMessagePayload, Message, ThreadFile, PendingAttachment } from '@standardagents/client';
|
|
5
5
|
export { AgentBuilderClient, AttachmentPayload, AttachmentRef, ConnectionStatus, FileUploadManager, GetMessagesOptions, Message, PendingAttachment, SendMessagePayload, Thread, ThreadConnectionCallbacks, ThreadConnectionManager, ThreadConnectionOptions, ThreadFile, ThreadMessage, WorkItem, WorkMessage, generatePendingFileId, isImageMimeType, messagesToFiles, parseAttachments, readFileAsDataUrl, transformToWorkblocks } from '@standardagents/client';
|
|
@@ -39,8 +39,8 @@ interface ThreadProviderOptions {
|
|
|
39
39
|
* Thread context value provided by ThreadProvider
|
|
40
40
|
*/
|
|
41
41
|
interface ThreadContext {
|
|
42
|
-
/** The thread ID */
|
|
43
|
-
threadId: string
|
|
42
|
+
/** The thread ID (computed to handle reactive input) */
|
|
43
|
+
threadId: ComputedRef<string>;
|
|
44
44
|
/** Options passed to the provider */
|
|
45
45
|
options: ThreadProviderOptions;
|
|
46
46
|
/** Current messages in the thread */
|
|
@@ -61,6 +61,8 @@ interface ThreadContext {
|
|
|
61
61
|
sendMessage: (payload: Omit<SendMessagePayload, 'attachments'>) => Promise<Message>;
|
|
62
62
|
/** Stop the current execution */
|
|
63
63
|
stopExecution: () => Promise<void>;
|
|
64
|
+
/** Delete a message from the thread (optimistically removes from UI) */
|
|
65
|
+
deleteMessage: (messageId: string) => Promise<void>;
|
|
64
66
|
/** Subscribe to custom events */
|
|
65
67
|
onEvent: <T = unknown>(eventType: string, callback: (data: T) => void) => () => void;
|
|
66
68
|
/** Subscribe to custom events (alias for onEvent) */
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as vue from 'vue';
|
|
2
|
-
import {
|
|
2
|
+
import { ComputedRef, Ref, InjectionKey, Plugin, PropType } from 'vue';
|
|
3
3
|
import * as _standardagents_client from '@standardagents/client';
|
|
4
4
|
import { AgentBuilderClient, SendMessagePayload, Message, ThreadFile, PendingAttachment } from '@standardagents/client';
|
|
5
5
|
export { AgentBuilderClient, AttachmentPayload, AttachmentRef, ConnectionStatus, FileUploadManager, GetMessagesOptions, Message, PendingAttachment, SendMessagePayload, Thread, ThreadConnectionCallbacks, ThreadConnectionManager, ThreadConnectionOptions, ThreadFile, ThreadMessage, WorkItem, WorkMessage, generatePendingFileId, isImageMimeType, messagesToFiles, parseAttachments, readFileAsDataUrl, transformToWorkblocks } from '@standardagents/client';
|
|
@@ -39,8 +39,8 @@ interface ThreadProviderOptions {
|
|
|
39
39
|
* Thread context value provided by ThreadProvider
|
|
40
40
|
*/
|
|
41
41
|
interface ThreadContext {
|
|
42
|
-
/** The thread ID */
|
|
43
|
-
threadId: string
|
|
42
|
+
/** The thread ID (computed to handle reactive input) */
|
|
43
|
+
threadId: ComputedRef<string>;
|
|
44
44
|
/** Options passed to the provider */
|
|
45
45
|
options: ThreadProviderOptions;
|
|
46
46
|
/** Current messages in the thread */
|
|
@@ -61,6 +61,8 @@ interface ThreadContext {
|
|
|
61
61
|
sendMessage: (payload: Omit<SendMessagePayload, 'attachments'>) => Promise<Message>;
|
|
62
62
|
/** Stop the current execution */
|
|
63
63
|
stopExecution: () => Promise<void>;
|
|
64
|
+
/** Delete a message from the thread (optimistically removes from UI) */
|
|
65
|
+
deleteMessage: (messageId: string) => Promise<void>;
|
|
64
66
|
/** Subscribe to custom events */
|
|
65
67
|
onEvent: <T = unknown>(eventType: string, callback: (data: T) => void) => () => void;
|
|
66
68
|
/** Subscribe to custom events (alias for onEvent) */
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { FileUploadManager, AgentBuilderClient,
|
|
1
|
+
import { FileUploadManager, AgentBuilderClient, transformToWorkblocks, ThreadConnectionManager } from '@standardagents/client';
|
|
2
2
|
export { AgentBuilderClient, FileUploadManager, ThreadConnectionManager, generatePendingFileId, isImageMimeType, messagesToFiles, parseAttachments, readFileAsDataUrl, transformToWorkblocks } from '@standardagents/client';
|
|
3
|
-
import { defineComponent, provide, ref,
|
|
3
|
+
import { defineComponent, provide, computed, toValue, ref, watch, onMounted, onUnmounted, inject } from 'vue';
|
|
4
4
|
|
|
5
5
|
// src/plugin.ts
|
|
6
6
|
|
|
@@ -46,7 +46,7 @@ function fileToBase64(file) {
|
|
|
46
46
|
reader.readAsDataURL(file);
|
|
47
47
|
});
|
|
48
48
|
}
|
|
49
|
-
function useThreadSetup(
|
|
49
|
+
function useThreadSetup(threadIdInput, options = {}) {
|
|
50
50
|
const {
|
|
51
51
|
preload = true,
|
|
52
52
|
live = true,
|
|
@@ -55,6 +55,7 @@ function useThreadSetup(threadId, options = {}) {
|
|
|
55
55
|
includeSilent = false,
|
|
56
56
|
endpoint: endpointOverride
|
|
57
57
|
} = options;
|
|
58
|
+
const threadId = computed(() => toValue(threadIdInput));
|
|
58
59
|
const context = useStandardAgents();
|
|
59
60
|
const client = endpointOverride ? new AgentBuilderClient(endpointOverride) : context.client;
|
|
60
61
|
const resolvedOptions = {
|
|
@@ -69,12 +70,12 @@ function useThreadSetup(threadId, options = {}) {
|
|
|
69
70
|
const isLoading = ref(preload);
|
|
70
71
|
const error = ref(null);
|
|
71
72
|
const pendingFiles = ref([]);
|
|
73
|
+
const serverFiles = ref([]);
|
|
72
74
|
const attachments = ref([]);
|
|
73
|
-
const committedFiles = computed(() => {
|
|
74
|
-
return messagesToFiles(messages.value);
|
|
75
|
-
});
|
|
76
75
|
const files = computed(() => {
|
|
77
|
-
|
|
76
|
+
const serverPaths = new Set(serverFiles.value.map((f) => f.path));
|
|
77
|
+
const uniquePendingFiles = pendingFiles.value.filter((f) => !f.path || !serverPaths.has(f.path));
|
|
78
|
+
return [...uniquePendingFiles, ...serverFiles.value];
|
|
78
79
|
});
|
|
79
80
|
const eventHandlers = /* @__PURE__ */ new Map();
|
|
80
81
|
let connectionManager = null;
|
|
@@ -88,7 +89,7 @@ function useThreadSetup(threadId, options = {}) {
|
|
|
88
89
|
isLoading.value = true;
|
|
89
90
|
error.value = null;
|
|
90
91
|
try {
|
|
91
|
-
const loadedMessages = await client.getMessages(threadId, { depth, includeSilent });
|
|
92
|
+
const loadedMessages = await client.getMessages(threadId.value, { depth, includeSilent });
|
|
92
93
|
messages.value = loadedMessages;
|
|
93
94
|
} catch (err) {
|
|
94
95
|
error.value = err instanceof Error ? err : new Error(String(err));
|
|
@@ -96,9 +97,68 @@ function useThreadSetup(threadId, options = {}) {
|
|
|
96
97
|
isLoading.value = false;
|
|
97
98
|
}
|
|
98
99
|
}
|
|
100
|
+
async function loadFiles() {
|
|
101
|
+
try {
|
|
102
|
+
const fileList = await client.listFiles(threadId.value);
|
|
103
|
+
serverFiles.value = fileList.filter((f) => !f.isDirectory).map((f) => ({
|
|
104
|
+
id: f.path,
|
|
105
|
+
// Use path as ID for server files
|
|
106
|
+
name: f.name,
|
|
107
|
+
path: f.path,
|
|
108
|
+
mimeType: f.mimeType,
|
|
109
|
+
size: f.size,
|
|
110
|
+
isImage: f.mimeType.startsWith("image/"),
|
|
111
|
+
status: "committed",
|
|
112
|
+
localPreviewUrl: null
|
|
113
|
+
}));
|
|
114
|
+
} catch (err) {
|
|
115
|
+
console.error("Failed to load files:", err);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
function handleFileCreated(data) {
|
|
119
|
+
if (data.file.isDirectory) return;
|
|
120
|
+
const newFile = {
|
|
121
|
+
id: data.path,
|
|
122
|
+
name: data.file.name,
|
|
123
|
+
path: data.path,
|
|
124
|
+
mimeType: data.file.mimeType,
|
|
125
|
+
size: data.file.size,
|
|
126
|
+
isImage: data.file.mimeType?.startsWith("image/") || false,
|
|
127
|
+
status: "committed",
|
|
128
|
+
localPreviewUrl: null
|
|
129
|
+
};
|
|
130
|
+
const existingIndex = serverFiles.value.findIndex((f) => f.path === data.path);
|
|
131
|
+
if (existingIndex >= 0) {
|
|
132
|
+
serverFiles.value[existingIndex] = newFile;
|
|
133
|
+
} else {
|
|
134
|
+
serverFiles.value = [...serverFiles.value, newFile];
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
function handleFileUpdated(data) {
|
|
138
|
+
if (data.file.isDirectory) return;
|
|
139
|
+
const updatedFile = {
|
|
140
|
+
id: data.path,
|
|
141
|
+
name: data.file.name,
|
|
142
|
+
path: data.path,
|
|
143
|
+
mimeType: data.file.mimeType,
|
|
144
|
+
size: data.file.size,
|
|
145
|
+
isImage: data.file.mimeType?.startsWith("image/") || false,
|
|
146
|
+
status: "committed",
|
|
147
|
+
localPreviewUrl: null
|
|
148
|
+
};
|
|
149
|
+
const existingIndex = serverFiles.value.findIndex((f) => f.path === data.path);
|
|
150
|
+
if (existingIndex >= 0) {
|
|
151
|
+
serverFiles.value[existingIndex] = updatedFile;
|
|
152
|
+
} else {
|
|
153
|
+
serverFiles.value = [...serverFiles.value, updatedFile];
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
function handleFileDeleted(data) {
|
|
157
|
+
serverFiles.value = serverFiles.value.filter((f) => f.path !== data.path);
|
|
158
|
+
}
|
|
99
159
|
function connect() {
|
|
100
160
|
if (!live) return;
|
|
101
|
-
connectionManager = new ThreadConnectionManager(client, threadId, {
|
|
161
|
+
connectionManager = new ThreadConnectionManager(client, threadId.value, {
|
|
102
162
|
onStatusChange: (newStatus) => {
|
|
103
163
|
status.value = newStatus;
|
|
104
164
|
},
|
|
@@ -123,6 +183,13 @@ function useThreadSetup(threadId, options = {}) {
|
|
|
123
183
|
}
|
|
124
184
|
},
|
|
125
185
|
onEvent: (event) => {
|
|
186
|
+
if (event.eventType === "file_created") {
|
|
187
|
+
handleFileCreated(event.data);
|
|
188
|
+
} else if (event.eventType === "file_updated") {
|
|
189
|
+
handleFileUpdated(event.data);
|
|
190
|
+
} else if (event.eventType === "file_deleted") {
|
|
191
|
+
handleFileDeleted(event.data);
|
|
192
|
+
}
|
|
126
193
|
const handlers = eventHandlers.get(event.eventType);
|
|
127
194
|
if (handlers) {
|
|
128
195
|
handlers.forEach((handler) => {
|
|
@@ -176,7 +243,7 @@ function useThreadSetup(threadId, options = {}) {
|
|
|
176
243
|
height: a.height
|
|
177
244
|
}))
|
|
178
245
|
);
|
|
179
|
-
const result = await client.sendMessage(threadId, {
|
|
246
|
+
const result = await client.sendMessage(threadId.value, {
|
|
180
247
|
...payload,
|
|
181
248
|
attachments: attachmentPayloads.length > 0 ? attachmentPayloads : void 0
|
|
182
249
|
});
|
|
@@ -194,18 +261,29 @@ function useThreadSetup(threadId, options = {}) {
|
|
|
194
261
|
}
|
|
195
262
|
async function stopExecution() {
|
|
196
263
|
try {
|
|
197
|
-
await client.stopExecution(threadId);
|
|
264
|
+
await client.stopExecution(threadId.value);
|
|
198
265
|
} catch (err) {
|
|
199
266
|
error.value = err instanceof Error ? err : new Error(String(err));
|
|
200
267
|
throw err;
|
|
201
268
|
}
|
|
202
269
|
}
|
|
270
|
+
async function deleteMessage(messageId) {
|
|
271
|
+
const previousMessages = [...messages.value];
|
|
272
|
+
messages.value = messages.value.filter((m) => m.id !== messageId);
|
|
273
|
+
try {
|
|
274
|
+
await client.deleteMessage(threadId.value, messageId);
|
|
275
|
+
} catch (err) {
|
|
276
|
+
messages.value = previousMessages;
|
|
277
|
+
error.value = err instanceof Error ? err : new Error(String(err));
|
|
278
|
+
throw err;
|
|
279
|
+
}
|
|
280
|
+
}
|
|
203
281
|
function addFiles(filesToAdd) {
|
|
204
282
|
const items = uploadManager.queueFiles(filesToAdd);
|
|
205
283
|
pendingFiles.value = [...pendingFiles.value, ...items.map((i) => i.pending)];
|
|
206
284
|
for (const { pending, file } of items) {
|
|
207
285
|
uploadManager.executeUpload(
|
|
208
|
-
threadId,
|
|
286
|
+
threadId.value,
|
|
209
287
|
file,
|
|
210
288
|
pending.id,
|
|
211
289
|
client,
|
|
@@ -223,11 +301,11 @@ function useThreadSetup(threadId, options = {}) {
|
|
|
223
301
|
}
|
|
224
302
|
function getFileUrl(file) {
|
|
225
303
|
if (!file.path) return "";
|
|
226
|
-
return client.getFileUrl(threadId, file.path);
|
|
304
|
+
return client.getFileUrl(threadId.value, file.path);
|
|
227
305
|
}
|
|
228
306
|
function getThumbnailUrl(file) {
|
|
229
307
|
if (!file.path) return "";
|
|
230
|
-
return client.getThumbnailUrl(threadId, file.path);
|
|
308
|
+
return client.getThumbnailUrl(threadId.value, file.path);
|
|
231
309
|
}
|
|
232
310
|
function getPreviewUrl(file) {
|
|
233
311
|
if (!file.isImage) return null;
|
|
@@ -283,10 +361,34 @@ function useThreadSetup(threadId, options = {}) {
|
|
|
283
361
|
}
|
|
284
362
|
};
|
|
285
363
|
}
|
|
364
|
+
function disconnect() {
|
|
365
|
+
connectionManager?.disconnect();
|
|
366
|
+
connectionManager = null;
|
|
367
|
+
status.value = "disconnected";
|
|
368
|
+
}
|
|
369
|
+
watch(threadId, (newThreadId, oldThreadId) => {
|
|
370
|
+
if (newThreadId !== oldThreadId) {
|
|
371
|
+
disconnect();
|
|
372
|
+
messages.value = [];
|
|
373
|
+
error.value = null;
|
|
374
|
+
pendingFiles.value = [];
|
|
375
|
+
serverFiles.value = [];
|
|
376
|
+
attachments.value.forEach((a) => {
|
|
377
|
+
if (a.previewUrl) URL.revokeObjectURL(a.previewUrl);
|
|
378
|
+
});
|
|
379
|
+
attachments.value = [];
|
|
380
|
+
if (preload) {
|
|
381
|
+
loadMessages();
|
|
382
|
+
}
|
|
383
|
+
loadFiles();
|
|
384
|
+
connect();
|
|
385
|
+
}
|
|
386
|
+
});
|
|
286
387
|
onMounted(() => {
|
|
287
388
|
if (preload) {
|
|
288
389
|
loadMessages();
|
|
289
390
|
}
|
|
391
|
+
loadFiles();
|
|
290
392
|
connect();
|
|
291
393
|
});
|
|
292
394
|
onUnmounted(() => {
|
|
@@ -310,6 +412,7 @@ function useThreadSetup(threadId, options = {}) {
|
|
|
310
412
|
error,
|
|
311
413
|
sendMessage,
|
|
312
414
|
stopExecution,
|
|
415
|
+
deleteMessage,
|
|
313
416
|
onEvent,
|
|
314
417
|
subscribeToEvent: onEvent,
|
|
315
418
|
// alias
|
|
@@ -390,7 +493,7 @@ var ThreadProvider = defineComponent({
|
|
|
390
493
|
if (props.depth !== void 0) options.depth = props.depth;
|
|
391
494
|
if (props.includeSilent !== void 0) options.includeSilent = props.includeSilent;
|
|
392
495
|
if (props.endpoint !== void 0) options.endpoint = props.endpoint;
|
|
393
|
-
const context = useThreadSetup(props.threadId, options);
|
|
496
|
+
const context = useThreadSetup(() => props.threadId, options);
|
|
394
497
|
provide(ThreadKey, context);
|
|
395
498
|
return () => slots.default?.();
|
|
396
499
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@standardagents/vue",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.11.0-next.41deba4",
|
|
4
4
|
"description": "Vue SDK for Standard Agents",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
"dist"
|
|
23
23
|
],
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@standardagents/client": "0.
|
|
25
|
+
"@standardagents/client": "0.11.0-next.41deba4"
|
|
26
26
|
},
|
|
27
27
|
"peerDependencies": {
|
|
28
28
|
"vue": "^3.3.0"
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
"@vue/test-utils": "^2.4.6",
|
|
35
35
|
"happy-dom": "^15.11.7",
|
|
36
36
|
"tsup": "^8.3.5",
|
|
37
|
-
"typescript": "^5.
|
|
37
|
+
"typescript": "^5.9.0",
|
|
38
38
|
"vitest": "^2.1.8",
|
|
39
39
|
"vue": "^3.5.13"
|
|
40
40
|
},
|