@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/dist/index.cjs ADDED
@@ -0,0 +1,356 @@
1
+ 'use strict';
2
+
3
+ var client = require('@standardagents/client');
4
+ var vue = require('vue');
5
+
6
+ // src/plugin.ts
7
+
8
+ // src/types.ts
9
+ var StandardAgentsKey = Symbol("StandardAgents");
10
+ var ThreadKey = Symbol("Thread");
11
+
12
+ // src/plugin.ts
13
+ var StandardAgentsPlugin = {
14
+ install(app, options) {
15
+ if (!options?.endpoint) {
16
+ throw new Error("StandardAgentsPlugin requires an endpoint option");
17
+ }
18
+ const client$1 = new client.AgentBuilderClient(options.endpoint);
19
+ const context = {
20
+ client: client$1,
21
+ endpoint: options.endpoint
22
+ };
23
+ app.provide(StandardAgentsKey, context);
24
+ }
25
+ };
26
+ function useStandardAgents() {
27
+ const context = vue.inject(StandardAgentsKey);
28
+ if (!context) {
29
+ throw new Error(
30
+ "useStandardAgents must be used within a component where StandardAgentsPlugin is installed"
31
+ );
32
+ }
33
+ return context;
34
+ }
35
+
36
+ // src/composables/useThreadSetup.ts
37
+ var uploadManager = new client.FileUploadManager();
38
+ function useThreadSetup(threadId, options = {}) {
39
+ const {
40
+ preload = true,
41
+ live = true,
42
+ useWorkblocks = false,
43
+ depth = 0,
44
+ includeSilent = false,
45
+ endpoint: endpointOverride
46
+ } = options;
47
+ const context = useStandardAgents();
48
+ const client$1 = endpointOverride ? new client.AgentBuilderClient(endpointOverride) : context.client;
49
+ const resolvedOptions = {
50
+ preload,
51
+ live,
52
+ useWorkblocks,
53
+ depth,
54
+ includeSilent
55
+ };
56
+ const messages = vue.ref([]);
57
+ const status = vue.ref("disconnected");
58
+ const isLoading = vue.ref(preload);
59
+ const error = vue.ref(null);
60
+ const pendingFiles = vue.ref([]);
61
+ const committedFiles = vue.computed(() => {
62
+ return client.messagesToFiles(messages.value);
63
+ });
64
+ const files = vue.computed(() => {
65
+ return [...pendingFiles.value, ...committedFiles.value];
66
+ });
67
+ const eventHandlers = /* @__PURE__ */ new Map();
68
+ let connectionManager = null;
69
+ const workblocks = vue.computed(() => {
70
+ if (!useWorkblocks) {
71
+ return messages.value;
72
+ }
73
+ return client.transformToWorkblocks(messages.value);
74
+ });
75
+ async function loadMessages() {
76
+ isLoading.value = true;
77
+ error.value = null;
78
+ try {
79
+ const loadedMessages = await client$1.getMessages(threadId, { depth, includeSilent });
80
+ messages.value = loadedMessages;
81
+ } catch (err) {
82
+ error.value = err instanceof Error ? err : new Error(String(err));
83
+ } finally {
84
+ isLoading.value = false;
85
+ }
86
+ }
87
+ function connect() {
88
+ if (!live) return;
89
+ connectionManager = new client.ThreadConnectionManager(client$1, threadId, {
90
+ onStatusChange: (newStatus) => {
91
+ status.value = newStatus;
92
+ },
93
+ onMessage: (event) => {
94
+ if (event.type === "message_data") {
95
+ const existingIndex = messages.value.findIndex((m) => m.id === event.data.id);
96
+ if (existingIndex >= 0) {
97
+ messages.value[existingIndex] = event.data;
98
+ } else {
99
+ messages.value = [...messages.value, event.data];
100
+ }
101
+ }
102
+ },
103
+ onChunk: (event) => {
104
+ const existingIndex = messages.value.findIndex((m) => m.id === event.message_id);
105
+ if (existingIndex >= 0) {
106
+ const message = messages.value[existingIndex];
107
+ messages.value[existingIndex] = {
108
+ ...message,
109
+ content: (message.content || "") + event.chunk
110
+ };
111
+ }
112
+ },
113
+ onEvent: (event) => {
114
+ const handlers = eventHandlers.get(event.eventType);
115
+ if (handlers) {
116
+ handlers.forEach((handler) => {
117
+ try {
118
+ handler(event.data);
119
+ } catch (err) {
120
+ console.error(`Error in event listener for "${event.eventType}":`, err);
121
+ }
122
+ });
123
+ }
124
+ },
125
+ onError: (err) => {
126
+ error.value = err instanceof Error ? err : new Error(String(err));
127
+ }
128
+ }, { depth, includeSilent });
129
+ connectionManager.connect();
130
+ }
131
+ async function sendMessage(payload) {
132
+ try {
133
+ return await client$1.sendMessage(threadId, payload);
134
+ } catch (err) {
135
+ error.value = err instanceof Error ? err : new Error(String(err));
136
+ throw err;
137
+ }
138
+ }
139
+ async function stopExecution() {
140
+ try {
141
+ await client$1.stopExecution(threadId);
142
+ } catch (err) {
143
+ error.value = err instanceof Error ? err : new Error(String(err));
144
+ throw err;
145
+ }
146
+ }
147
+ function addFiles(filesToAdd) {
148
+ const items = uploadManager.queueFiles(filesToAdd);
149
+ pendingFiles.value = [...pendingFiles.value, ...items.map((i) => i.pending)];
150
+ for (const { pending, file } of items) {
151
+ uploadManager.executeUpload(
152
+ threadId,
153
+ file,
154
+ pending.id,
155
+ client$1,
156
+ (updates) => {
157
+ pendingFiles.value = pendingFiles.value.map(
158
+ (f) => f.id === pending.id ? { ...f, ...updates } : f
159
+ );
160
+ }
161
+ ).catch(() => {
162
+ });
163
+ }
164
+ }
165
+ function removeFile(id) {
166
+ pendingFiles.value = pendingFiles.value.filter((f) => f.id !== id);
167
+ }
168
+ function getFileUrl(file) {
169
+ if (!file.path) return "";
170
+ return client$1.getFileUrl(threadId, file.path);
171
+ }
172
+ function getThumbnailUrl(file) {
173
+ if (!file.path) return "";
174
+ return client$1.getThumbnailUrl(threadId, file.path);
175
+ }
176
+ function getPreviewUrl(file) {
177
+ if (!file.isImage) return null;
178
+ if (file.localPreviewUrl) {
179
+ return file.localPreviewUrl;
180
+ }
181
+ if (file.path) {
182
+ return getThumbnailUrl(file);
183
+ }
184
+ return null;
185
+ }
186
+ function onEvent(eventType, callback) {
187
+ if (!eventHandlers.has(eventType)) {
188
+ eventHandlers.set(eventType, /* @__PURE__ */ new Set());
189
+ }
190
+ eventHandlers.get(eventType).add(callback);
191
+ return () => {
192
+ const handlers = eventHandlers.get(eventType);
193
+ if (handlers) {
194
+ handlers.delete(callback);
195
+ if (handlers.size === 0) {
196
+ eventHandlers.delete(eventType);
197
+ }
198
+ }
199
+ };
200
+ }
201
+ vue.onMounted(() => {
202
+ if (preload) {
203
+ loadMessages();
204
+ }
205
+ connect();
206
+ });
207
+ vue.onUnmounted(() => {
208
+ connectionManager?.disconnect();
209
+ eventHandlers.clear();
210
+ });
211
+ return {
212
+ threadId,
213
+ options: resolvedOptions,
214
+ messages,
215
+ workblocks,
216
+ status,
217
+ connectionStatus: status,
218
+ // alias
219
+ isLoading,
220
+ loading: isLoading,
221
+ // alias
222
+ error,
223
+ sendMessage,
224
+ stopExecution,
225
+ onEvent,
226
+ subscribeToEvent: onEvent,
227
+ // alias
228
+ // File management
229
+ files,
230
+ addFiles,
231
+ removeFile,
232
+ getFileUrl,
233
+ getThumbnailUrl,
234
+ getPreviewUrl
235
+ };
236
+ }
237
+
238
+ // src/components/ThreadProvider.ts
239
+ var ThreadProvider = vue.defineComponent({
240
+ name: "ThreadProvider",
241
+ props: {
242
+ /**
243
+ * The thread ID to connect to
244
+ */
245
+ threadId: {
246
+ type: String,
247
+ required: true
248
+ },
249
+ /**
250
+ * Whether to preload messages on mount (default: true)
251
+ */
252
+ preload: {
253
+ type: Boolean,
254
+ default: void 0
255
+ },
256
+ /**
257
+ * Whether to connect to live updates (default: true)
258
+ */
259
+ live: {
260
+ type: Boolean,
261
+ default: void 0
262
+ },
263
+ /**
264
+ * Transform messages to workblocks (default: false)
265
+ */
266
+ useWorkblocks: {
267
+ type: Boolean,
268
+ default: void 0
269
+ },
270
+ /**
271
+ * Message depth to fetch (default: 0)
272
+ */
273
+ depth: {
274
+ type: Number,
275
+ default: void 0
276
+ },
277
+ /**
278
+ * Include silent messages (default: false)
279
+ */
280
+ includeSilent: {
281
+ type: Boolean,
282
+ default: void 0
283
+ },
284
+ /**
285
+ * Optional endpoint override
286
+ */
287
+ endpoint: {
288
+ type: String,
289
+ default: void 0
290
+ }
291
+ },
292
+ setup(props, { slots }) {
293
+ const options = {};
294
+ if (props.preload !== void 0) options.preload = props.preload;
295
+ if (props.live !== void 0) options.live = props.live;
296
+ if (props.useWorkblocks !== void 0) options.useWorkblocks = props.useWorkblocks;
297
+ if (props.depth !== void 0) options.depth = props.depth;
298
+ if (props.includeSilent !== void 0) options.includeSilent = props.includeSilent;
299
+ if (props.endpoint !== void 0) options.endpoint = props.endpoint;
300
+ const context = useThreadSetup(props.threadId, options);
301
+ vue.provide(ThreadKey, context);
302
+ return () => slots.default?.();
303
+ }
304
+ });
305
+ function useThread() {
306
+ const context = vue.inject(ThreadKey);
307
+ if (!context) {
308
+ throw new Error(
309
+ 'useThread must be used within a <ThreadProvider>. Wrap your component with <ThreadProvider threadId="...">.'
310
+ );
311
+ }
312
+ return context;
313
+ }
314
+
315
+ Object.defineProperty(exports, "AgentBuilderClient", {
316
+ enumerable: true,
317
+ get: function () { return client.AgentBuilderClient; }
318
+ });
319
+ Object.defineProperty(exports, "FileUploadManager", {
320
+ enumerable: true,
321
+ get: function () { return client.FileUploadManager; }
322
+ });
323
+ Object.defineProperty(exports, "ThreadConnectionManager", {
324
+ enumerable: true,
325
+ get: function () { return client.ThreadConnectionManager; }
326
+ });
327
+ Object.defineProperty(exports, "generatePendingFileId", {
328
+ enumerable: true,
329
+ get: function () { return client.generatePendingFileId; }
330
+ });
331
+ Object.defineProperty(exports, "isImageMimeType", {
332
+ enumerable: true,
333
+ get: function () { return client.isImageMimeType; }
334
+ });
335
+ Object.defineProperty(exports, "messagesToFiles", {
336
+ enumerable: true,
337
+ get: function () { return client.messagesToFiles; }
338
+ });
339
+ Object.defineProperty(exports, "parseAttachments", {
340
+ enumerable: true,
341
+ get: function () { return client.parseAttachments; }
342
+ });
343
+ Object.defineProperty(exports, "readFileAsDataUrl", {
344
+ enumerable: true,
345
+ get: function () { return client.readFileAsDataUrl; }
346
+ });
347
+ Object.defineProperty(exports, "transformToWorkblocks", {
348
+ enumerable: true,
349
+ get: function () { return client.transformToWorkblocks; }
350
+ });
351
+ exports.StandardAgentsKey = StandardAgentsKey;
352
+ exports.StandardAgentsPlugin = StandardAgentsPlugin;
353
+ exports.ThreadKey = ThreadKey;
354
+ exports.ThreadProvider = ThreadProvider;
355
+ exports.useStandardAgents = useStandardAgents;
356
+ exports.useThread = useThread;
@@ -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 };