UNPKG

@llamaindex/ui

Version:

A comprehensive UI component library built with React, TypeScript, and Tailwind CSS for LlamaIndex applications

975 lines (967 loc) 31.8 kB
'use strict'; var chunkUAOG2ZNN_js = require('./chunk-UAOG2ZNN.js'); var chunk27UZIVVO_js = require('./chunk-27UZIVVO.js'); var chunk2XLCATQN_js = require('./chunk-2XLCATQN.js'); var chunk4FEBFYQ7_js = require('./chunk-4FEBFYQ7.js'); var chunkHK7TFVDA_js = require('./chunk-HK7TFVDA.js'); var chunkNTTWA5KH_js = require('./chunk-NTTWA5KH.js'); var zustand = require('zustand'); var workflowsClient = require('@llamaindex/workflows-client'); var react = require('react'); var lucideReact = require('lucide-react'); var jsxRuntime = require('react/jsx-runtime'); var sonner = require('sonner'); // src/lib/shared-streaming.ts var SharedStreamingManager = class { constructor() { this.activeStreams = /* @__PURE__ */ new Map(); } /** * Subscribe to a shared stream identified by key. * If stream already exists, reuses it and sends historical events. * If stream doesn't exist, creates a new one using the executor. * * @param streamKey - Unique identifier for the stream * @param subscriber - Event handlers for the stream * @param executor - Function that performs the actual streaming * @param externalSignal - Optional abort signal from caller * @returns Promise that resolves with all events and unsubscribe function */ subscribe(streamKey, subscriber, executor, externalSignal) { const existingStream = this.activeStreams.get(streamKey); if (existingStream) { return this.subscribeToExistingStream( streamKey, existingStream, subscriber, externalSignal ); } return this.createNewStream( streamKey, subscriber, executor, externalSignal ); } /** * Get current events for a stream without subscribing */ getStreamEvents(streamKey) { const stream = this.activeStreams.get(streamKey); return stream ? [...stream.events] : []; } /** * get configuration for a stream */ getStreamConfig(streamKey) { const stream = this.activeStreams.get(streamKey); return stream ? { includeInternal: stream.includeInternal } : { includeInternal: false }; } /** * Check if a stream is currently active */ isStreamActive(streamKey) { return this.activeStreams.has(streamKey); } /** * Get number of subscribers for a stream */ getSubscriberCount(streamKey) { const stream = this.activeStreams.get(streamKey); return stream ? stream.subscribers.size : 0; } /** * Force close a stream and all its subscribers */ closeStream(streamKey) { const stream = this.activeStreams.get(streamKey); if (stream) { stream.controller.abort(); this.cleanupStream(streamKey); } } /** * Close all active streams */ closeAllStreams() { for (const streamKey of this.activeStreams.keys()) { this.closeStream(streamKey); } } subscribeToExistingStream(streamKey, stream, subscriber, externalSignal) { var _a, _b, _c, _d, _e; stream.subscribers.add(subscriber); try { (_a = subscriber.onStart) == null ? void 0 : _a.call(subscriber); for (const event of stream.events) { (_b = subscriber.onData) == null ? void 0 : _b.call(subscriber, event); } if (stream.isCompleted) { if (stream.error) { (_c = subscriber.onError) == null ? void 0 : _c.call(subscriber, stream.error); } else { (_d = subscriber.onFinish) == null ? void 0 : _d.call(subscriber, stream.events); } (_e = subscriber.onComplete) == null ? void 0 : _e.call(subscriber); } } catch (error) { console.error("Error sending historical events to subscriber:", error); } const handleExternalAbort = () => { this.unsubscribe(streamKey, subscriber); }; if (externalSignal) { if (externalSignal.aborted) { this.unsubscribe(streamKey, subscriber); } else { externalSignal.addEventListener("abort", handleExternalAbort); } } const unsubscribe = () => { if (externalSignal) { externalSignal.removeEventListener("abort", handleExternalAbort); } this.unsubscribe(streamKey, subscriber); }; return { promise: stream.promise, unsubscribe }; } createNewStream(streamKey, subscriber, executor, externalSignal, includeInternal) { const controller = new AbortController(); const subscribers = /* @__PURE__ */ new Set([subscriber]); const events = []; const streamState = { controller, promise: Promise.resolve([]), // Will be replaced below subscribers, events, isCompleted: false, error: null, includeInternal: includeInternal != null ? includeInternal : false }; this.activeStreams.set(streamKey, streamState); const handleExternalAbort = () => { this.unsubscribe(streamKey, subscriber); }; if (externalSignal) { if (externalSignal.aborted) { this.unsubscribe(streamKey, subscriber); return { promise: Promise.resolve([]), unsubscribe: () => { } }; } externalSignal.addEventListener("abort", handleExternalAbort); } const compositeSubscriber = { onStart: () => { streamState.subscribers.forEach((sub) => { var _a; try { (_a = sub.onStart) == null ? void 0 : _a.call(sub); } catch (error) { console.error("Error in subscriber onStart:", error); } }); }, onData: (event) => { events.push(event); streamState.subscribers.forEach((sub) => { var _a; try { (_a = sub.onData) == null ? void 0 : _a.call(sub, event); } catch (error) { console.error("Error in subscriber onData:", error); } }); }, onError: (error) => { streamState.error = error; streamState.isCompleted = true; streamState.subscribers.forEach((sub) => { var _a, _b; try { (_a = sub.onError) == null ? void 0 : _a.call(sub, error); (_b = sub.onComplete) == null ? void 0 : _b.call(sub); } catch (err) { console.error("Error in subscriber onError:", err); } }); this.cleanupStream(streamKey); }, onFinish: (allEvents) => { streamState.isCompleted = true; streamState.subscribers.forEach((sub) => { var _a, _b; try { (_a = sub.onFinish) == null ? void 0 : _a.call(sub, allEvents); (_b = sub.onComplete) == null ? void 0 : _b.call(sub); } catch (error) { console.error("Error in subscriber onFinish:", error); } }); this.cleanupStream(streamKey); } }; const streamPromise = this.executeStream( executor, compositeSubscriber, controller.signal ); streamState.promise = streamPromise; const unsubscribe = () => { if (externalSignal) { externalSignal.removeEventListener("abort", handleExternalAbort); } this.unsubscribe(streamKey, subscriber); }; return { promise: streamPromise, unsubscribe }; } async executeStream(executor, subscriber, signal) { var _a; try { return await executor(subscriber, signal); } catch (error) { const err = error instanceof Error ? error : new Error(String(error)); (_a = subscriber.onError) == null ? void 0 : _a.call(subscriber, err); throw err; } } unsubscribe(streamKey, subscriber) { const stream = this.activeStreams.get(streamKey); if (!stream) return; stream.subscribers.delete(subscriber); if (stream.subscribers.size === 0) { try { stream.controller.abort(); } catch (e) { } this.cleanupStream(streamKey); } } cleanupStream(streamKey) { this.activeStreams.delete(streamKey); } }; var workflowStreamingManager = new SharedStreamingManager(); async function getRunningHandlers(params) { var _a, _b; const resp = await workflowsClient.getHandlers({ client: params.client }); const allHandlers = (_b = (_a = resp.data) == null ? void 0 : _a.handlers) != null ? _b : []; return allHandlers.filter((handler) => handler.status === "running").map((handler) => { var _a2; return { handler_id: (_a2 = handler.handler_id) != null ? _a2 : "", status: handler.status }; }); } async function createHandler(params) { var _a; const data = await workflowsClient.postWorkflowsByNameRunNowait({ client: params.client, path: { name: params.workflowName }, body: { start_event: params.eventData } }); if (!data.data) { throw new Error("Handler creation failed"); } return { handler_id: (_a = data.data.handler_id) != null ? _a : "", status: "running", workflowName: params.workflowName }; } function fetchHandlerEvents(params, callback) { const streamKey = `handler:${params.handlerId}`; const executor = async (subscriber2, signal) => { var _a, _b, _c; (_a = subscriber2.onStart) == null ? void 0 : _a.call(subscriber2); const accumulatedEvents = []; const onMessage = (event) => { var _a2; const workflowEvent = { type: event.qualified_name, data: event.value }; accumulatedEvents.push(workflowEvent); try { (_a2 = subscriber2.onData) == null ? void 0 : _a2.call(subscriber2, workflowEvent); } catch (error) { console.error("Error in subscriber onData:", error); } const stopEvent = [workflowEvent].find( (event2) => event2.type === "workflow.events.StopEvent" /* StopEvent */.toString() ); if (stopEvent) { if (callback == null ? void 0 : callback.onStopEvent) { callback.onStopEvent(stopEvent); } return true; } return false; }; const baseUrl = ((_b = params.client.getConfig().baseUrl) != null ? _b : "").replace( /\/$/, "" ); const urlParams = new URLSearchParams(); urlParams.set("sse", "true"); if (params.includeInternal) { urlParams.set("include_internal", "true"); } const eventSource = new EventSource( `${baseUrl}/events/${encodeURIComponent(params.handlerId)}?${urlParams.toString()}`, { withCredentials: true } ); await processUntilClosed( eventSource, onMessage, signal, () => ( // EventSource does not complete until the backoff reconnect gets a 204. Proactively check for completion. workflowsClient.getResultsByHandlerId({ client: params.client, path: { handler_id: params.handlerId } }).then((res) => { var _a2, _b2; return ((_b2 = (_a2 = res.data) == null ? void 0 : _a2.result) != null ? _b2 : null) !== null; }) ) ); (_c = subscriber2.onFinish) == null ? void 0 : _c.call(subscriber2, accumulatedEvents); return accumulatedEvents; }; const subscriber = { onStart: callback == null ? void 0 : callback.onStart, onData: callback == null ? void 0 : callback.onData, onError: callback == null ? void 0 : callback.onError, onFinish: callback == null ? void 0 : callback.onFinish }; const { promise, unsubscribe } = workflowStreamingManager.subscribe( streamKey, subscriber, executor, params.signal ); return { promise, unsubscribe }; } async function sendEventToHandler(params) { const rawEvent = toRawEvent(params.event); const data = await workflowsClient.postEventsByHandlerId({ client: params.client, path: { handler_id: params.handlerId }, body: { event: JSON.stringify(rawEvent), step: params.step } }); return data.data; } function toRawEvent(event) { var _a; return { __is_pydantic: true, value: (_a = event.data) != null ? _a : {}, qualified_name: event.type }; } function processUntilClosed(eventSource, callback, abortSignal, checkComplete) { let resolve = () => { }; const onAbort = () => { eventSource.close(); resolve(); }; const promise = new Promise((_resolve) => { resolve = _resolve; }); abortSignal.addEventListener("abort", onAbort); const onMessage = (event) => { try { if (callback(JSON.parse(event.data))) { eventSource.close(); resolve(); } } catch (error) { console.error("Unexpected error in processUntilClosed callback:", error); } }; eventSource.addEventListener("message", onMessage); let checkCompletePromise = null; let lastCheckTime = 0; const onError = (_) => { if (eventSource.readyState == EventSource.CLOSED) { resolve(); } const now = Date.now(); if (!checkCompletePromise && checkComplete && now - lastCheckTime > 1e4) { lastCheckTime = now; checkCompletePromise = checkComplete(); } checkCompletePromise == null ? void 0 : checkCompletePromise.then((complete) => { if (complete) { eventSource.close(); resolve(); } else { checkCompletePromise = null; } }); }; eventSource.addEventListener("error", onError); return promise.then(() => { eventSource.removeEventListener("message", onMessage); eventSource.removeEventListener("error", onError); abortSignal.removeEventListener("abort", onAbort); }); } // src/workflows/store/handler-store.ts var createHandlerStore = (client) => zustand.create()((set, get) => ({ // Initial state handlers: {}, events: {}, // Basic operations clearCompleted: () => set({ handlers: Object.fromEntries( Object.entries(get().handlers).filter( ([, t]) => t.status !== "complete" && t.status !== "failed" ) ) }), createHandler: async (workflowName, input) => { var _a; const workflowHandler = await createHandler({ client, eventData: input, workflowName }); const handler = { handler_id: (_a = workflowHandler.handler_id) != null ? _a : "", status: workflowHandler.status, workflowName: workflowHandler.workflowName }; set((state) => ({ handlers: chunkNTTWA5KH_js.__spreadProps(chunkNTTWA5KH_js.__spreadValues({}, state.handlers), { [handler.handler_id]: handler }), events: chunkNTTWA5KH_js.__spreadProps(chunkNTTWA5KH_js.__spreadValues({}, state.events), { [handler.handler_id]: [] }) })); try { get().subscribe(handler.handler_id); } catch (error) { console.error( `Failed to auto-subscribe to handler ${handler.handler_id}:`, error ); } return handler; }, clearEvents: (handlerId) => set((state) => ({ events: chunkNTTWA5KH_js.__spreadProps(chunkNTTWA5KH_js.__spreadValues({}, state.events), { [handlerId]: [] }) })), // Server synchronization sync: async () => { try { const serverHandlers = await getRunningHandlers({ client }); const newHandlersRecord = Object.fromEntries( serverHandlers.map((handler) => [handler.handler_id, handler]) ); set({ handlers: newHandlersRecord }); serverHandlers.forEach((handler) => { if (handler.status === "running" && !get().isSubscribed(handler.handler_id)) { get().subscribe(handler.handler_id); } }); } catch (error) { console.error("Failed to sync with server:", error); } }, // Stream subscription management subscribe: (handlerId, cfg) => { var _a; const handler = get().handlers[handlerId]; if (!handler) { console.warn(`Handler ${handlerId} not found for subscription`); return; } const currentStream = workflowStreamingManager.getStreamConfig( handlerStreamKey(handlerId) ); const shouldRestartStream = !!(cfg == null ? void 0 : cfg.includeInternal) && !currentStream.includeInternal; if (workflowStreamingManager.isStreamActive(handlerStreamKey(handlerId)) && !shouldRestartStream) { return; } if (shouldRestartStream) { workflowStreamingManager.closeStream(handlerStreamKey(handlerId)); } const callback = { onData: (event) => { set((state) => ({ events: chunkNTTWA5KH_js.__spreadProps(chunkNTTWA5KH_js.__spreadValues({}, state.events), { [handlerId]: [...state.events[handlerId] || [], event] }) })); }, onFinish: () => { set((state) => ({ handlers: chunkNTTWA5KH_js.__spreadProps(chunkNTTWA5KH_js.__spreadValues({}, state.handlers), { [handlerId]: chunkNTTWA5KH_js.__spreadProps(chunkNTTWA5KH_js.__spreadValues({}, state.handlers[handlerId]), { status: "complete", updatedAt: /* @__PURE__ */ new Date() }) }) })); }, onError: (error) => { if (error.name === "AbortError" || error.name === "TypeError" && error.message.includes("network error")) { return; } set((state) => ({ handlers: chunkNTTWA5KH_js.__spreadProps(chunkNTTWA5KH_js.__spreadValues({}, state.handlers), { [handlerId]: chunkNTTWA5KH_js.__spreadProps(chunkNTTWA5KH_js.__spreadValues({}, state.handlers[handlerId]), { status: "failed", updatedAt: /* @__PURE__ */ new Date() }) }) })); } }; const { promise } = fetchHandlerEvents( { client, handlerId: handler.handler_id, includeInternal: (_a = cfg == null ? void 0 : cfg.includeInternal) != null ? _a : false }, callback ); promise.catch((error) => { if (error.name === "AbortError" || error.name === "TypeError" && error.message.includes("network error")) { return; } set((state) => ({ handlers: chunkNTTWA5KH_js.__spreadProps(chunkNTTWA5KH_js.__spreadValues({}, state.handlers), { [handlerId]: chunkNTTWA5KH_js.__spreadProps(chunkNTTWA5KH_js.__spreadValues({}, state.handlers[handlerId]), { status: "failed", updatedAt: /* @__PURE__ */ new Date() }) }) })); }); }, unsubscribe: (handlerId) => { const handler = get().handlers[handlerId]; if (!handler) return; const streamKey = `handler:${handlerId}`; workflowStreamingManager.closeStream(streamKey); }, isSubscribed: (handlerId) => { const handler = get().handlers[handlerId]; if (!handler) return false; return workflowStreamingManager.isStreamActive( handlerStreamKey(handlerId) ); } })); function handlerStreamKey(handlerId) { return `handler:${handlerId}`; } var globalStore = null; function useHandlerStore(selector) { const client = chunk27UZIVVO_js.useWorkflowsClient(); const store = react.useMemo(() => { if (!globalStore) { globalStore = createHandlerStore(client); } return globalStore; }, [client]); return selector ? store(selector) : store(); } // src/workflows/hooks/use-workflow-run.ts function useWorkflowRun() { const [isCreating, setIsCreating] = react.useState(false); const [error, setError] = react.useState(null); const storeCreateHandler = useHandlerStore((state) => state.createHandler); const runWorkflow = react.useCallback( async (workflowName, input) => { setIsCreating(true); setError(null); try { const handler = await storeCreateHandler(workflowName, input); setIsCreating(false); return handler; } catch (err) { const error2 = err instanceof Error ? err : new Error(String(err)); setError(error2); setIsCreating(false); throw error2; } }, [storeCreateHandler] ); return { runWorkflow, isCreating, error }; } // src/workflows/hooks/utils.ts function filterHandlersByWorkflow(handlers, workflowName) { return handlers.filter((handler) => { if (handler.workflowName) { return handler.workflowName === workflowName; } if (handler.status !== "running") { return false; } return true; }); } // src/workflows/hooks/use-workflow-handler-list.ts function useWorkflowHandlerList(workflowName) { const [loading, setLoading] = react.useState(true); const [error, setError] = react.useState(null); const store = useHandlerStore(); const handlersRecord = store.handlers; const clearCompleted = store.clearCompleted; const sync = store.sync; react.useEffect(() => { async function syncWithServer() { setLoading(true); setError(null); try { await sync(); } catch (err) { setError( err instanceof Error ? err.message : "Failed to sync with server" ); } finally { setLoading(false); } } syncWithServer(); }, [sync]); const filteredHandlers = react.useMemo(() => { return filterHandlersByWorkflow( Object.values(handlersRecord), workflowName ); }, [handlersRecord, workflowName]); return { handlers: filteredHandlers, clearCompleted, loading, error }; } function useWorkflowHandler(handlerId, autoStream = true, { includeInternal = false } = {}) { const client = chunk27UZIVVO_js.useWorkflowsClient(); const handler = useHandlerStore((state) => state.handlers[handlerId] || null); const eventsRecord = useHandlerStore((state) => state.events); const subscribe = useHandlerStore((state) => state.subscribe); const unsubscribe = useHandlerStore((state) => state.unsubscribe); const isSubscribed = useHandlerStore((state) => state.isSubscribed); const clearEvents = useHandlerStore((state) => state.clearEvents); const events = react.useMemo(() => { return eventsRecord[handlerId] || []; }, [eventsRecord, handlerId]); react.useEffect(() => { if (!handler || !autoStream) return; if (handler.status !== "running") return; subscribe(handlerId, { includeInternal }); return () => { if (handler.status !== "running") { unsubscribe(handlerId); } }; }, [handlerId, handler, autoStream, subscribe, unsubscribe, includeInternal]); const stopStreaming = react.useCallback(() => { unsubscribe(handlerId); }, [handlerId, unsubscribe]); const clearHandlerEvents = react.useCallback(() => { clearEvents(handlerId); }, [handlerId, clearEvents]); const sendEvent = react.useCallback( async (event) => { await sendEventToHandler({ client, handlerId, event }); }, [handlerId, client] ); return { handler, events, isStreaming: isSubscribed(handlerId), stopStreaming, clearEvents: clearHandlerEvents, sendEvent }; } function useWorkflowProgress(workflowName) { const store = useHandlerStore(); const handlers = store.handlers; const sync = store.sync; react.useEffect(() => { async function syncWithServer() { try { await sync(); } catch (error) { console.error("Failed to sync with server for progress:", error); } } syncWithServer(); }, [sync]); return react.useMemo(() => { const handlerArray = filterHandlersByWorkflow( Object.values(handlers), workflowName ); const total = handlerArray.length; if (total === 0) { return { current: 0, total: 0, status: "idle" }; } const completedCount = handlerArray.filter( (handler) => handler.status === "complete" ).length; let status; if (handlerArray.some((handler) => handler.status === "failed")) { status = "failed"; } else if (completedCount === total) { status = "complete"; } else if (handlerArray.some((handler) => handler.status === "running")) { status = "running"; } else { status = "idle"; } return { current: completedCount, total, status }; }, [handlers, workflowName]); } var iconPool = [ lucideReact.FileText, lucideReact.Clock, lucideReact.CheckCircle, lucideReact.Cog, lucideReact.Zap, lucideReact.Eye, lucideReact.Search, lucideReact.Download ]; var getRandomIcon = (index) => { return iconPool[index % iconPool.length]; }; function AgentStreamDisplay({ handlerId, title = "Agent Processing", maxEvents = 20, className }) { const { handler, events } = useWorkflowHandler(handlerId, true); const agentEvents = react.useMemo(() => { return events.filter((event) => { return event.type === "AgentStream" && typeof event.data === "object" && event.data !== null && "message" in event.data; }).slice(-maxEvents); }, [events, maxEvents]); if (!handler || agentEvents.length === 0) { return null; } return /* @__PURE__ */ jsxRuntime.jsxs(chunkUAOG2ZNN_js.Card, { className, children: [ /* @__PURE__ */ jsxRuntime.jsx(chunkUAOG2ZNN_js.CardHeader, { className: "pb-3", children: /* @__PURE__ */ jsxRuntime.jsxs(chunkUAOG2ZNN_js.CardTitle, { className: "text-sm font-medium flex items-center gap-2", children: [ /* @__PURE__ */ jsxRuntime.jsx( "div", { className: `h-2 w-2 rounded-full ${handler.status === "running" ? "bg-blue-500 animate-pulse" : handler.status === "complete" ? "bg-green-500" : handler.status === "failed" ? "bg-red-500" : "bg-gray-400"}` } ), title ] }) }), /* @__PURE__ */ jsxRuntime.jsx(chunkUAOG2ZNN_js.CardContent, { className: "pt-0", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "space-y-3 max-h-64 overflow-y-auto", children: agentEvents.map((event, index) => { const Icon = getRandomIcon(index); return /* @__PURE__ */ jsxRuntime.jsxs( "div", { className: "flex items-center gap-3 animate-in fade-in duration-300", children: [ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex h-6 w-6 items-center justify-center rounded-full bg-blue-100 text-blue-600 flex-shrink-0", children: /* @__PURE__ */ jsxRuntime.jsx(Icon, { className: "h-3 w-3" }) }), /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex-1 min-w-0", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-sm font-medium text-blue-900 break-words", children: event.data.message }) }) ] }, `agent-stream-${handlerId}-${index}` ); }) }) }) ] }); } function WorkflowProgressBar({ className, mode = "auto", workflowName }) { const { current, total, status } = useWorkflowProgress(workflowName); const percentage = total > 0 ? current / total * 100 : 0; const shouldShow = () => { switch (mode) { case "always": return true; case "auto": default: return total > 0 || status !== "idle"; } }; if (!shouldShow()) { return null; } const getStatusText = () => { switch (status) { case "running": return "Uploaded files are processing"; case "complete": return "All files processed successfully"; case "failed": return "Error processing files"; case "idle": default: return "Ready to process files"; } }; const getStatusIcon = () => { switch (status) { case "running": return /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Loader, { className: "h-4 w-4 text-gray-600 animate-spin" }); case "complete": return /* @__PURE__ */ jsxRuntime.jsx(lucideReact.CheckCircle, { className: "h-4 w-4 text-green-600" }); case "failed": return /* @__PURE__ */ jsxRuntime.jsx(lucideReact.XCircle, { className: "h-4 w-4 text-red-600" }); case "idle": default: return /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Clock, { className: "h-4 w-4 text-gray-600" }); } }; return /* @__PURE__ */ jsxRuntime.jsxs( "div", { className: chunkHK7TFVDA_js.cn( "w-full flex items-center gap-4 p-3 border border-gray-200 rounded-lg", className ), children: [ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-2 flex-shrink-0", children: [ /* @__PURE__ */ jsxRuntime.jsx(lucideReact.FileText, { className: "h-4 w-4 text-gray-600" }), /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-sm font-medium text-gray-700 whitespace-nowrap", children: getStatusText() }) ] }), /* @__PURE__ */ jsxRuntime.jsx( chunk4FEBFYQ7_js.Progress, { value: percentage, className: "h-2 [&>div]:bg-black [&]:bg-gray-200 flex-1", "aria-valuenow": current, "aria-valuemax": total, "aria-valuemin": 0 } ), /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-2 flex-shrink-0", children: [ /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "text-sm font-medium text-gray-600 whitespace-nowrap", children: [ current, "/", total ] }), getStatusIcon() ] }) ] } ); } function WorkflowTrigger(_a) { var _b = _a, { workflowName, customWorkflowInput, onSuccess, onError, title = "Trigger Workflow", description = "Upload files to start workflow processing" } = _b, fileUploaderProps = chunkNTTWA5KH_js.__objRest(_b, [ "workflowName", "customWorkflowInput", "onSuccess", "onError", "title", "description" ]); const { runWorkflow: createRun, isCreating, error } = useWorkflowRun(); react.useEffect(() => { if (error) { sonner.toast.error(`Failed to create workflow handler: ${error.message}`); } }, [error]); const handleFileUpload = react.useCallback( async (data, fieldValues) => { try { if (customWorkflowInput) { const workflowInput2 = customWorkflowInput(data, fieldValues); const task2 = await createRun(workflowName, workflowInput2); sonner.toast.success("Workflow task created successfully!"); onSuccess == null ? void 0 : onSuccess(task2); return; } const workflowInput = chunkNTTWA5KH_js.__spreadValues({ files: data.map((file) => ({ fileId: file.fileId, url: file.url, name: file.file.name, type: file.file.type })) }, fieldValues); const task = await createRun(workflowName, workflowInput); sonner.toast.success("Workflow task created successfully!"); onSuccess == null ? void 0 : onSuccess(task); } catch (err) { const error2 = err instanceof Error ? err : new Error(String(err)); sonner.toast.error(`Failed to create workflow task: ${error2.message}`); onError == null ? void 0 : onError(error2); throw error2; } }, [workflowName, createRun, onSuccess, onError, customWorkflowInput] ); return /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx( chunk2XLCATQN_js.FileUploader, chunkNTTWA5KH_js.__spreadValues({ title, description, onSuccess: handleFileUpload, isProcessing: isCreating }, fileUploaderProps) ) }); } exports.AgentStreamDisplay = AgentStreamDisplay; exports.WorkflowProgressBar = WorkflowProgressBar; exports.WorkflowTrigger = WorkflowTrigger; exports.createHandlerStore = createHandlerStore; exports.fetchHandlerEvents = fetchHandlerEvents; exports.useHandlerStore = useHandlerStore; exports.useWorkflowHandler = useWorkflowHandler; exports.useWorkflowHandlerList = useWorkflowHandlerList; exports.useWorkflowProgress = useWorkflowProgress; exports.useWorkflowRun = useWorkflowRun; exports.workflowStreamingManager = workflowStreamingManager;