@standardagents/vue 0.1.0-dev.ffffff
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/LICENSE.txt +48 -0
- package/README.md +379 -0
- package/dist/index.cjs +356 -0
- package/dist/index.d.cts +293 -0
- package/dist/index.d.ts +293 -0
- package/dist/index.js +314 -0
- package/package.json +55 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,293 @@
|
|
|
1
|
+
import * as vue from 'vue';
|
|
2
|
+
import { Ref, ComputedRef, InjectionKey, Plugin, PropType } from 'vue';
|
|
3
|
+
import * as _standardagents_client from '@standardagents/client';
|
|
4
|
+
import { AgentBuilderClient, SendMessagePayload, Message, ThreadFile } from '@standardagents/client';
|
|
5
|
+
export { AgentBuilderClient, AttachmentRef, ConnectionStatus, FileUploadManager, GetMessagesOptions, Message, SendMessagePayload, Thread, ThreadConnectionCallbacks, ThreadConnectionManager, ThreadConnectionOptions, ThreadFile, ThreadMessage, WorkItem, WorkMessage, generatePendingFileId, isImageMimeType, messagesToFiles, parseAttachments, readFileAsDataUrl, transformToWorkblocks } from '@standardagents/client';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Configuration for the StandardAgents plugin
|
|
9
|
+
*/
|
|
10
|
+
interface StandardAgentsConfig {
|
|
11
|
+
/** API endpoint URL */
|
|
12
|
+
endpoint: string;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Context value provided by the StandardAgents plugin
|
|
16
|
+
*/
|
|
17
|
+
interface StandardAgentsContext {
|
|
18
|
+
/** The AgentBuilder client instance */
|
|
19
|
+
client: AgentBuilderClient;
|
|
20
|
+
/** The API endpoint URL */
|
|
21
|
+
endpoint: string;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Options passed to ThreadProvider
|
|
25
|
+
*/
|
|
26
|
+
interface ThreadProviderOptions {
|
|
27
|
+
/** Whether to preload messages on mount (default: true) */
|
|
28
|
+
preload?: boolean;
|
|
29
|
+
/** Whether to connect to live updates (default: true) */
|
|
30
|
+
live?: boolean;
|
|
31
|
+
/** Transform messages to workblocks (default: false) */
|
|
32
|
+
useWorkblocks?: boolean;
|
|
33
|
+
/** Message depth to fetch (default: 0) */
|
|
34
|
+
depth?: number;
|
|
35
|
+
/** Include silent messages (default: false) */
|
|
36
|
+
includeSilent?: boolean;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Thread context value provided by ThreadProvider
|
|
40
|
+
*/
|
|
41
|
+
interface ThreadContext {
|
|
42
|
+
/** The thread ID */
|
|
43
|
+
threadId: string;
|
|
44
|
+
/** Options passed to the provider */
|
|
45
|
+
options: ThreadProviderOptions;
|
|
46
|
+
/** Current messages in the thread */
|
|
47
|
+
messages: Ref<_standardagents_client.Message[]>;
|
|
48
|
+
/** Messages transformed to workblocks (if useWorkblocks is true) */
|
|
49
|
+
workblocks: ComputedRef<_standardagents_client.ThreadMessage[]>;
|
|
50
|
+
/** Connection status */
|
|
51
|
+
status: Ref<_standardagents_client.ConnectionStatus>;
|
|
52
|
+
/** Connection status (alias for status) */
|
|
53
|
+
connectionStatus: Ref<_standardagents_client.ConnectionStatus>;
|
|
54
|
+
/** Whether the thread is currently loading */
|
|
55
|
+
isLoading: Ref<boolean>;
|
|
56
|
+
/** Whether the thread is currently loading (alias for isLoading) */
|
|
57
|
+
loading: Ref<boolean>;
|
|
58
|
+
/** Any error that occurred */
|
|
59
|
+
error: Ref<Error | null>;
|
|
60
|
+
/** Send a message to the thread */
|
|
61
|
+
sendMessage: (payload: SendMessagePayload) => Promise<Message>;
|
|
62
|
+
/** Stop the current execution */
|
|
63
|
+
stopExecution: () => Promise<void>;
|
|
64
|
+
/** Subscribe to custom events */
|
|
65
|
+
onEvent: <T = unknown>(eventType: string, callback: (data: T) => void) => () => void;
|
|
66
|
+
/** Subscribe to custom events (alias for onEvent) */
|
|
67
|
+
subscribeToEvent: <T = unknown>(eventType: string, callback: (data: T) => void) => () => void;
|
|
68
|
+
/** All files in the thread (pending uploads + committed from messages) */
|
|
69
|
+
files: ComputedRef<ThreadFile[]>;
|
|
70
|
+
/** Add files and start uploading immediately */
|
|
71
|
+
addFiles: (files: File[] | FileList) => void;
|
|
72
|
+
/** Remove a pending file (cannot remove committed files) */
|
|
73
|
+
removeFile: (id: string) => void;
|
|
74
|
+
/** Get the full URL for a file */
|
|
75
|
+
getFileUrl: (file: ThreadFile) => string;
|
|
76
|
+
/** Get the thumbnail URL for an image file */
|
|
77
|
+
getThumbnailUrl: (file: ThreadFile) => string;
|
|
78
|
+
/** Get preview URL - localPreviewUrl for pending images, thumbnail for committed */
|
|
79
|
+
getPreviewUrl: (file: ThreadFile) => string | null;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Options for useThread composable
|
|
83
|
+
*/
|
|
84
|
+
interface UseThreadOptions {
|
|
85
|
+
/** Whether to preload messages on mount (default: true) */
|
|
86
|
+
preload?: boolean;
|
|
87
|
+
/** Whether to connect to live updates (default: true) */
|
|
88
|
+
live?: boolean;
|
|
89
|
+
/** Transform messages to workblocks (default: false) */
|
|
90
|
+
useWorkblocks?: boolean;
|
|
91
|
+
/** Message depth to fetch (default: 0) */
|
|
92
|
+
depth?: number;
|
|
93
|
+
/** Include silent messages (default: false) */
|
|
94
|
+
includeSilent?: boolean;
|
|
95
|
+
/** Optional endpoint override */
|
|
96
|
+
endpoint?: string;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Injection key for StandardAgents context
|
|
100
|
+
*/
|
|
101
|
+
declare const StandardAgentsKey: InjectionKey<StandardAgentsContext>;
|
|
102
|
+
/**
|
|
103
|
+
* Injection key for Thread context
|
|
104
|
+
*/
|
|
105
|
+
declare const ThreadKey: InjectionKey<ThreadContext>;
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Vue plugin for Standard Agents
|
|
109
|
+
*
|
|
110
|
+
* @example
|
|
111
|
+
* ```typescript
|
|
112
|
+
* import { createApp } from 'vue'
|
|
113
|
+
* import { StandardAgentsPlugin } from '@standardagents/vue'
|
|
114
|
+
*
|
|
115
|
+
* const app = createApp(App)
|
|
116
|
+
* app.use(StandardAgentsPlugin, { endpoint: 'https://api.example.com' })
|
|
117
|
+
* ```
|
|
118
|
+
*/
|
|
119
|
+
declare const StandardAgentsPlugin: Plugin<StandardAgentsConfig>;
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Provider component that sets up a thread connection and provides context
|
|
123
|
+
* to all child components. Use `useThread()` in child components to access
|
|
124
|
+
* the thread context.
|
|
125
|
+
*
|
|
126
|
+
* @example
|
|
127
|
+
* ```vue
|
|
128
|
+
* <template>
|
|
129
|
+
* <ThreadProvider threadId="thread-123">
|
|
130
|
+
* <ChatMessages />
|
|
131
|
+
* </ThreadProvider>
|
|
132
|
+
* </template>
|
|
133
|
+
*
|
|
134
|
+
* <script setup>
|
|
135
|
+
* import { ThreadProvider } from '@standardagents/vue'
|
|
136
|
+
* </script>
|
|
137
|
+
* ```
|
|
138
|
+
*/
|
|
139
|
+
declare const ThreadProvider: vue.DefineComponent<vue.ExtractPropTypes<{
|
|
140
|
+
/**
|
|
141
|
+
* The thread ID to connect to
|
|
142
|
+
*/
|
|
143
|
+
threadId: {
|
|
144
|
+
type: PropType<string>;
|
|
145
|
+
required: true;
|
|
146
|
+
};
|
|
147
|
+
/**
|
|
148
|
+
* Whether to preload messages on mount (default: true)
|
|
149
|
+
*/
|
|
150
|
+
preload: {
|
|
151
|
+
type: PropType<boolean>;
|
|
152
|
+
default: undefined;
|
|
153
|
+
};
|
|
154
|
+
/**
|
|
155
|
+
* Whether to connect to live updates (default: true)
|
|
156
|
+
*/
|
|
157
|
+
live: {
|
|
158
|
+
type: PropType<boolean>;
|
|
159
|
+
default: undefined;
|
|
160
|
+
};
|
|
161
|
+
/**
|
|
162
|
+
* Transform messages to workblocks (default: false)
|
|
163
|
+
*/
|
|
164
|
+
useWorkblocks: {
|
|
165
|
+
type: PropType<boolean>;
|
|
166
|
+
default: undefined;
|
|
167
|
+
};
|
|
168
|
+
/**
|
|
169
|
+
* Message depth to fetch (default: 0)
|
|
170
|
+
*/
|
|
171
|
+
depth: {
|
|
172
|
+
type: PropType<number>;
|
|
173
|
+
default: undefined;
|
|
174
|
+
};
|
|
175
|
+
/**
|
|
176
|
+
* Include silent messages (default: false)
|
|
177
|
+
*/
|
|
178
|
+
includeSilent: {
|
|
179
|
+
type: PropType<boolean>;
|
|
180
|
+
default: undefined;
|
|
181
|
+
};
|
|
182
|
+
/**
|
|
183
|
+
* Optional endpoint override
|
|
184
|
+
*/
|
|
185
|
+
endpoint: {
|
|
186
|
+
type: PropType<string>;
|
|
187
|
+
default: undefined;
|
|
188
|
+
};
|
|
189
|
+
}>, () => vue.VNode<vue.RendererNode, vue.RendererElement, {
|
|
190
|
+
[key: string]: any;
|
|
191
|
+
}>[] | undefined, {}, {}, {}, vue.ComponentOptionsMixin, vue.ComponentOptionsMixin, {}, string, vue.PublicProps, Readonly<vue.ExtractPropTypes<{
|
|
192
|
+
/**
|
|
193
|
+
* The thread ID to connect to
|
|
194
|
+
*/
|
|
195
|
+
threadId: {
|
|
196
|
+
type: PropType<string>;
|
|
197
|
+
required: true;
|
|
198
|
+
};
|
|
199
|
+
/**
|
|
200
|
+
* Whether to preload messages on mount (default: true)
|
|
201
|
+
*/
|
|
202
|
+
preload: {
|
|
203
|
+
type: PropType<boolean>;
|
|
204
|
+
default: undefined;
|
|
205
|
+
};
|
|
206
|
+
/**
|
|
207
|
+
* Whether to connect to live updates (default: true)
|
|
208
|
+
*/
|
|
209
|
+
live: {
|
|
210
|
+
type: PropType<boolean>;
|
|
211
|
+
default: undefined;
|
|
212
|
+
};
|
|
213
|
+
/**
|
|
214
|
+
* Transform messages to workblocks (default: false)
|
|
215
|
+
*/
|
|
216
|
+
useWorkblocks: {
|
|
217
|
+
type: PropType<boolean>;
|
|
218
|
+
default: undefined;
|
|
219
|
+
};
|
|
220
|
+
/**
|
|
221
|
+
* Message depth to fetch (default: 0)
|
|
222
|
+
*/
|
|
223
|
+
depth: {
|
|
224
|
+
type: PropType<number>;
|
|
225
|
+
default: undefined;
|
|
226
|
+
};
|
|
227
|
+
/**
|
|
228
|
+
* Include silent messages (default: false)
|
|
229
|
+
*/
|
|
230
|
+
includeSilent: {
|
|
231
|
+
type: PropType<boolean>;
|
|
232
|
+
default: undefined;
|
|
233
|
+
};
|
|
234
|
+
/**
|
|
235
|
+
* Optional endpoint override
|
|
236
|
+
*/
|
|
237
|
+
endpoint: {
|
|
238
|
+
type: PropType<string>;
|
|
239
|
+
default: undefined;
|
|
240
|
+
};
|
|
241
|
+
}>> & Readonly<{}>, {
|
|
242
|
+
preload: boolean;
|
|
243
|
+
live: boolean;
|
|
244
|
+
useWorkblocks: boolean;
|
|
245
|
+
depth: number;
|
|
246
|
+
includeSilent: boolean;
|
|
247
|
+
endpoint: string;
|
|
248
|
+
}, {}, {}, {}, string, vue.ComponentProvideOptions, true, {}, any>;
|
|
249
|
+
|
|
250
|
+
/**
|
|
251
|
+
* Access the StandardAgents context
|
|
252
|
+
*
|
|
253
|
+
* @throws Error if used outside of StandardAgentsPlugin
|
|
254
|
+
* @returns The StandardAgents context with client and endpoint
|
|
255
|
+
*
|
|
256
|
+
* @example
|
|
257
|
+
* ```typescript
|
|
258
|
+
* const { client, endpoint } = useStandardAgents()
|
|
259
|
+
* ```
|
|
260
|
+
*/
|
|
261
|
+
declare function useStandardAgents(): StandardAgentsContext;
|
|
262
|
+
|
|
263
|
+
/**
|
|
264
|
+
* Hook to access the thread context.
|
|
265
|
+
*
|
|
266
|
+
* Must be used within a ThreadProvider. Returns the full thread context
|
|
267
|
+
* including messages, actions, and file management.
|
|
268
|
+
*
|
|
269
|
+
* @returns The thread context value
|
|
270
|
+
*
|
|
271
|
+
* @example
|
|
272
|
+
* ```vue
|
|
273
|
+
* <template>
|
|
274
|
+
* <ThreadProvider threadId="thread-123">
|
|
275
|
+
* <ChatMessages />
|
|
276
|
+
* </ThreadProvider>
|
|
277
|
+
* </template>
|
|
278
|
+
*
|
|
279
|
+
* <script setup>
|
|
280
|
+
* // In ChatMessages component:
|
|
281
|
+
* import { useThread } from '@standardagents/vue'
|
|
282
|
+
*
|
|
283
|
+
* const { messages, sendMessage, files } = useThread()
|
|
284
|
+
*
|
|
285
|
+
* async function handleSend() {
|
|
286
|
+
* await sendMessage({ role: 'user', content: 'Hello!' })
|
|
287
|
+
* }
|
|
288
|
+
* </script>
|
|
289
|
+
* ```
|
|
290
|
+
*/
|
|
291
|
+
declare function useThread(): ThreadContext;
|
|
292
|
+
|
|
293
|
+
export { type StandardAgentsConfig, type StandardAgentsContext, StandardAgentsKey, StandardAgentsPlugin, type ThreadContext, ThreadKey, ThreadProvider, type UseThreadOptions, useStandardAgents, useThread };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,314 @@
|
|
|
1
|
+
import { FileUploadManager, AgentBuilderClient, messagesToFiles, transformToWorkblocks, ThreadConnectionManager } from '@standardagents/client';
|
|
2
|
+
export { AgentBuilderClient, FileUploadManager, ThreadConnectionManager, generatePendingFileId, isImageMimeType, messagesToFiles, parseAttachments, readFileAsDataUrl, transformToWorkblocks } from '@standardagents/client';
|
|
3
|
+
import { defineComponent, provide, ref, computed, onMounted, onUnmounted, inject } from 'vue';
|
|
4
|
+
|
|
5
|
+
// src/plugin.ts
|
|
6
|
+
|
|
7
|
+
// src/types.ts
|
|
8
|
+
var StandardAgentsKey = Symbol("StandardAgents");
|
|
9
|
+
var ThreadKey = Symbol("Thread");
|
|
10
|
+
|
|
11
|
+
// src/plugin.ts
|
|
12
|
+
var StandardAgentsPlugin = {
|
|
13
|
+
install(app, options) {
|
|
14
|
+
if (!options?.endpoint) {
|
|
15
|
+
throw new Error("StandardAgentsPlugin requires an endpoint option");
|
|
16
|
+
}
|
|
17
|
+
const client = new AgentBuilderClient(options.endpoint);
|
|
18
|
+
const context = {
|
|
19
|
+
client,
|
|
20
|
+
endpoint: options.endpoint
|
|
21
|
+
};
|
|
22
|
+
app.provide(StandardAgentsKey, context);
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
function useStandardAgents() {
|
|
26
|
+
const context = inject(StandardAgentsKey);
|
|
27
|
+
if (!context) {
|
|
28
|
+
throw new Error(
|
|
29
|
+
"useStandardAgents must be used within a component where StandardAgentsPlugin is installed"
|
|
30
|
+
);
|
|
31
|
+
}
|
|
32
|
+
return context;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// src/composables/useThreadSetup.ts
|
|
36
|
+
var uploadManager = new FileUploadManager();
|
|
37
|
+
function useThreadSetup(threadId, options = {}) {
|
|
38
|
+
const {
|
|
39
|
+
preload = true,
|
|
40
|
+
live = true,
|
|
41
|
+
useWorkblocks = false,
|
|
42
|
+
depth = 0,
|
|
43
|
+
includeSilent = false,
|
|
44
|
+
endpoint: endpointOverride
|
|
45
|
+
} = options;
|
|
46
|
+
const context = useStandardAgents();
|
|
47
|
+
const client = endpointOverride ? new AgentBuilderClient(endpointOverride) : context.client;
|
|
48
|
+
const resolvedOptions = {
|
|
49
|
+
preload,
|
|
50
|
+
live,
|
|
51
|
+
useWorkblocks,
|
|
52
|
+
depth,
|
|
53
|
+
includeSilent
|
|
54
|
+
};
|
|
55
|
+
const messages = ref([]);
|
|
56
|
+
const status = ref("disconnected");
|
|
57
|
+
const isLoading = ref(preload);
|
|
58
|
+
const error = ref(null);
|
|
59
|
+
const pendingFiles = ref([]);
|
|
60
|
+
const committedFiles = computed(() => {
|
|
61
|
+
return messagesToFiles(messages.value);
|
|
62
|
+
});
|
|
63
|
+
const files = computed(() => {
|
|
64
|
+
return [...pendingFiles.value, ...committedFiles.value];
|
|
65
|
+
});
|
|
66
|
+
const eventHandlers = /* @__PURE__ */ new Map();
|
|
67
|
+
let connectionManager = null;
|
|
68
|
+
const workblocks = computed(() => {
|
|
69
|
+
if (!useWorkblocks) {
|
|
70
|
+
return messages.value;
|
|
71
|
+
}
|
|
72
|
+
return transformToWorkblocks(messages.value);
|
|
73
|
+
});
|
|
74
|
+
async function loadMessages() {
|
|
75
|
+
isLoading.value = true;
|
|
76
|
+
error.value = null;
|
|
77
|
+
try {
|
|
78
|
+
const loadedMessages = await client.getMessages(threadId, { depth, includeSilent });
|
|
79
|
+
messages.value = loadedMessages;
|
|
80
|
+
} catch (err) {
|
|
81
|
+
error.value = err instanceof Error ? err : new Error(String(err));
|
|
82
|
+
} finally {
|
|
83
|
+
isLoading.value = false;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
function connect() {
|
|
87
|
+
if (!live) return;
|
|
88
|
+
connectionManager = new ThreadConnectionManager(client, threadId, {
|
|
89
|
+
onStatusChange: (newStatus) => {
|
|
90
|
+
status.value = newStatus;
|
|
91
|
+
},
|
|
92
|
+
onMessage: (event) => {
|
|
93
|
+
if (event.type === "message_data") {
|
|
94
|
+
const existingIndex = messages.value.findIndex((m) => m.id === event.data.id);
|
|
95
|
+
if (existingIndex >= 0) {
|
|
96
|
+
messages.value[existingIndex] = event.data;
|
|
97
|
+
} else {
|
|
98
|
+
messages.value = [...messages.value, event.data];
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
},
|
|
102
|
+
onChunk: (event) => {
|
|
103
|
+
const existingIndex = messages.value.findIndex((m) => m.id === event.message_id);
|
|
104
|
+
if (existingIndex >= 0) {
|
|
105
|
+
const message = messages.value[existingIndex];
|
|
106
|
+
messages.value[existingIndex] = {
|
|
107
|
+
...message,
|
|
108
|
+
content: (message.content || "") + event.chunk
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
},
|
|
112
|
+
onEvent: (event) => {
|
|
113
|
+
const handlers = eventHandlers.get(event.eventType);
|
|
114
|
+
if (handlers) {
|
|
115
|
+
handlers.forEach((handler) => {
|
|
116
|
+
try {
|
|
117
|
+
handler(event.data);
|
|
118
|
+
} catch (err) {
|
|
119
|
+
console.error(`Error in event listener for "${event.eventType}":`, err);
|
|
120
|
+
}
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
},
|
|
124
|
+
onError: (err) => {
|
|
125
|
+
error.value = err instanceof Error ? err : new Error(String(err));
|
|
126
|
+
}
|
|
127
|
+
}, { depth, includeSilent });
|
|
128
|
+
connectionManager.connect();
|
|
129
|
+
}
|
|
130
|
+
async function sendMessage(payload) {
|
|
131
|
+
try {
|
|
132
|
+
return await client.sendMessage(threadId, payload);
|
|
133
|
+
} catch (err) {
|
|
134
|
+
error.value = err instanceof Error ? err : new Error(String(err));
|
|
135
|
+
throw err;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
async function stopExecution() {
|
|
139
|
+
try {
|
|
140
|
+
await client.stopExecution(threadId);
|
|
141
|
+
} catch (err) {
|
|
142
|
+
error.value = err instanceof Error ? err : new Error(String(err));
|
|
143
|
+
throw err;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
function addFiles(filesToAdd) {
|
|
147
|
+
const items = uploadManager.queueFiles(filesToAdd);
|
|
148
|
+
pendingFiles.value = [...pendingFiles.value, ...items.map((i) => i.pending)];
|
|
149
|
+
for (const { pending, file } of items) {
|
|
150
|
+
uploadManager.executeUpload(
|
|
151
|
+
threadId,
|
|
152
|
+
file,
|
|
153
|
+
pending.id,
|
|
154
|
+
client,
|
|
155
|
+
(updates) => {
|
|
156
|
+
pendingFiles.value = pendingFiles.value.map(
|
|
157
|
+
(f) => f.id === pending.id ? { ...f, ...updates } : f
|
|
158
|
+
);
|
|
159
|
+
}
|
|
160
|
+
).catch(() => {
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
function removeFile(id) {
|
|
165
|
+
pendingFiles.value = pendingFiles.value.filter((f) => f.id !== id);
|
|
166
|
+
}
|
|
167
|
+
function getFileUrl(file) {
|
|
168
|
+
if (!file.path) return "";
|
|
169
|
+
return client.getFileUrl(threadId, file.path);
|
|
170
|
+
}
|
|
171
|
+
function getThumbnailUrl(file) {
|
|
172
|
+
if (!file.path) return "";
|
|
173
|
+
return client.getThumbnailUrl(threadId, file.path);
|
|
174
|
+
}
|
|
175
|
+
function getPreviewUrl(file) {
|
|
176
|
+
if (!file.isImage) return null;
|
|
177
|
+
if (file.localPreviewUrl) {
|
|
178
|
+
return file.localPreviewUrl;
|
|
179
|
+
}
|
|
180
|
+
if (file.path) {
|
|
181
|
+
return getThumbnailUrl(file);
|
|
182
|
+
}
|
|
183
|
+
return null;
|
|
184
|
+
}
|
|
185
|
+
function onEvent(eventType, callback) {
|
|
186
|
+
if (!eventHandlers.has(eventType)) {
|
|
187
|
+
eventHandlers.set(eventType, /* @__PURE__ */ new Set());
|
|
188
|
+
}
|
|
189
|
+
eventHandlers.get(eventType).add(callback);
|
|
190
|
+
return () => {
|
|
191
|
+
const handlers = eventHandlers.get(eventType);
|
|
192
|
+
if (handlers) {
|
|
193
|
+
handlers.delete(callback);
|
|
194
|
+
if (handlers.size === 0) {
|
|
195
|
+
eventHandlers.delete(eventType);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
};
|
|
199
|
+
}
|
|
200
|
+
onMounted(() => {
|
|
201
|
+
if (preload) {
|
|
202
|
+
loadMessages();
|
|
203
|
+
}
|
|
204
|
+
connect();
|
|
205
|
+
});
|
|
206
|
+
onUnmounted(() => {
|
|
207
|
+
connectionManager?.disconnect();
|
|
208
|
+
eventHandlers.clear();
|
|
209
|
+
});
|
|
210
|
+
return {
|
|
211
|
+
threadId,
|
|
212
|
+
options: resolvedOptions,
|
|
213
|
+
messages,
|
|
214
|
+
workblocks,
|
|
215
|
+
status,
|
|
216
|
+
connectionStatus: status,
|
|
217
|
+
// alias
|
|
218
|
+
isLoading,
|
|
219
|
+
loading: isLoading,
|
|
220
|
+
// alias
|
|
221
|
+
error,
|
|
222
|
+
sendMessage,
|
|
223
|
+
stopExecution,
|
|
224
|
+
onEvent,
|
|
225
|
+
subscribeToEvent: onEvent,
|
|
226
|
+
// alias
|
|
227
|
+
// File management
|
|
228
|
+
files,
|
|
229
|
+
addFiles,
|
|
230
|
+
removeFile,
|
|
231
|
+
getFileUrl,
|
|
232
|
+
getThumbnailUrl,
|
|
233
|
+
getPreviewUrl
|
|
234
|
+
};
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
// src/components/ThreadProvider.ts
|
|
238
|
+
var ThreadProvider = defineComponent({
|
|
239
|
+
name: "ThreadProvider",
|
|
240
|
+
props: {
|
|
241
|
+
/**
|
|
242
|
+
* The thread ID to connect to
|
|
243
|
+
*/
|
|
244
|
+
threadId: {
|
|
245
|
+
type: String,
|
|
246
|
+
required: true
|
|
247
|
+
},
|
|
248
|
+
/**
|
|
249
|
+
* Whether to preload messages on mount (default: true)
|
|
250
|
+
*/
|
|
251
|
+
preload: {
|
|
252
|
+
type: Boolean,
|
|
253
|
+
default: void 0
|
|
254
|
+
},
|
|
255
|
+
/**
|
|
256
|
+
* Whether to connect to live updates (default: true)
|
|
257
|
+
*/
|
|
258
|
+
live: {
|
|
259
|
+
type: Boolean,
|
|
260
|
+
default: void 0
|
|
261
|
+
},
|
|
262
|
+
/**
|
|
263
|
+
* Transform messages to workblocks (default: false)
|
|
264
|
+
*/
|
|
265
|
+
useWorkblocks: {
|
|
266
|
+
type: Boolean,
|
|
267
|
+
default: void 0
|
|
268
|
+
},
|
|
269
|
+
/**
|
|
270
|
+
* Message depth to fetch (default: 0)
|
|
271
|
+
*/
|
|
272
|
+
depth: {
|
|
273
|
+
type: Number,
|
|
274
|
+
default: void 0
|
|
275
|
+
},
|
|
276
|
+
/**
|
|
277
|
+
* Include silent messages (default: false)
|
|
278
|
+
*/
|
|
279
|
+
includeSilent: {
|
|
280
|
+
type: Boolean,
|
|
281
|
+
default: void 0
|
|
282
|
+
},
|
|
283
|
+
/**
|
|
284
|
+
* Optional endpoint override
|
|
285
|
+
*/
|
|
286
|
+
endpoint: {
|
|
287
|
+
type: String,
|
|
288
|
+
default: void 0
|
|
289
|
+
}
|
|
290
|
+
},
|
|
291
|
+
setup(props, { slots }) {
|
|
292
|
+
const options = {};
|
|
293
|
+
if (props.preload !== void 0) options.preload = props.preload;
|
|
294
|
+
if (props.live !== void 0) options.live = props.live;
|
|
295
|
+
if (props.useWorkblocks !== void 0) options.useWorkblocks = props.useWorkblocks;
|
|
296
|
+
if (props.depth !== void 0) options.depth = props.depth;
|
|
297
|
+
if (props.includeSilent !== void 0) options.includeSilent = props.includeSilent;
|
|
298
|
+
if (props.endpoint !== void 0) options.endpoint = props.endpoint;
|
|
299
|
+
const context = useThreadSetup(props.threadId, options);
|
|
300
|
+
provide(ThreadKey, context);
|
|
301
|
+
return () => slots.default?.();
|
|
302
|
+
}
|
|
303
|
+
});
|
|
304
|
+
function useThread() {
|
|
305
|
+
const context = inject(ThreadKey);
|
|
306
|
+
if (!context) {
|
|
307
|
+
throw new Error(
|
|
308
|
+
'useThread must be used within a <ThreadProvider>. Wrap your component with <ThreadProvider threadId="...">.'
|
|
309
|
+
);
|
|
310
|
+
}
|
|
311
|
+
return context;
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
export { StandardAgentsKey, StandardAgentsPlugin, ThreadKey, ThreadProvider, useStandardAgents, useThread };
|
package/package.json
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@standardagents/vue",
|
|
3
|
+
"version": "0.1.0-dev.ffffff",
|
|
4
|
+
"description": "Vue SDK for Standard Agents",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.cjs",
|
|
7
|
+
"module": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"import": {
|
|
12
|
+
"types": "./dist/index.d.ts",
|
|
13
|
+
"default": "./dist/index.js"
|
|
14
|
+
},
|
|
15
|
+
"require": {
|
|
16
|
+
"types": "./dist/index.d.cts",
|
|
17
|
+
"default": "./dist/index.cjs"
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
"files": [
|
|
22
|
+
"dist"
|
|
23
|
+
],
|
|
24
|
+
"dependencies": {
|
|
25
|
+
"@standardagents/client": "0.1.0-dev.ffffff"
|
|
26
|
+
},
|
|
27
|
+
"peerDependencies": {
|
|
28
|
+
"vue": "^3.3.0"
|
|
29
|
+
},
|
|
30
|
+
"devDependencies": {
|
|
31
|
+
"@testing-library/vue": "^8.1.0",
|
|
32
|
+
"@types/node": "^22.10.2",
|
|
33
|
+
"@vitejs/plugin-vue": "^5.2.1",
|
|
34
|
+
"@vue/test-utils": "^2.4.6",
|
|
35
|
+
"happy-dom": "^15.11.7",
|
|
36
|
+
"tsup": "^8.3.5",
|
|
37
|
+
"typescript": "^5.7.2",
|
|
38
|
+
"vitest": "^2.1.8",
|
|
39
|
+
"vue": "^3.5.13"
|
|
40
|
+
},
|
|
41
|
+
"keywords": [
|
|
42
|
+
"vue",
|
|
43
|
+
"agents",
|
|
44
|
+
"ai",
|
|
45
|
+
"standardagents"
|
|
46
|
+
],
|
|
47
|
+
"license": "MIT",
|
|
48
|
+
"scripts": {
|
|
49
|
+
"build": "tsup",
|
|
50
|
+
"dev": "tsup --watch",
|
|
51
|
+
"test": "vitest run",
|
|
52
|
+
"test:watch": "vitest",
|
|
53
|
+
"typecheck": "tsc --noEmit"
|
|
54
|
+
}
|
|
55
|
+
}
|