@flexkit/studio 0.2.3 → 0.2.4
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/activity-nav-button-AESIPODJ.js +2 -0
- package/dist/{activity-nav-button-Z6M3FURW.js.map → activity-nav-button-AESIPODJ.js.map} +1 -1
- package/dist/{chat-page-J7I5V6G4.js → chat-page-S2YGOKO5.js} +3 -3
- package/dist/{chat-page-J7I5V6G4.js.map → chat-page-S2YGOKO5.js.map} +1 -1
- package/dist/{chunk-BP27UNNR.js → chunk-2AHDTE5T.js} +2 -2
- package/dist/{chunk-BP27UNNR.js.map → chunk-2AHDTE5T.js.map} +1 -1
- package/dist/chunk-3TGCCDOR.js +2 -0
- package/dist/chunk-3TGCCDOR.js.map +1 -0
- package/dist/{chunk-QJDD73JR.js → chunk-6RDPFMLK.js} +2 -2
- package/dist/{chunk-QJDD73JR.js.map → chunk-6RDPFMLK.js.map} +1 -1
- package/dist/{chunk-MM356YIK.js → chunk-CKNFYN3O.js} +3 -3
- package/dist/chunk-CKNFYN3O.js.map +1 -0
- package/dist/chunk-J2G4C6I5.js +2 -0
- package/dist/chunk-J2G4C6I5.js.map +1 -0
- package/dist/{chunk-G74PT7Z7.js → chunk-KWS3NAYS.js} +3 -3
- package/dist/{chunk-G74PT7Z7.js.map → chunk-KWS3NAYS.js.map} +1 -1
- package/dist/{chunk-76CL7HSO.js → chunk-LN55VJ35.js} +3 -3
- package/dist/{chunk-76CL7HSO.js.map → chunk-LN55VJ35.js.map} +1 -1
- package/dist/{chunk-IAA4CEBW.js → chunk-NOFQHWES.js} +2 -2
- package/dist/{chunk-IAA4CEBW.js.map → chunk-NOFQHWES.js.map} +1 -1
- package/dist/{chunk-MPLNRUP3.js → chunk-NYKATVPZ.js} +3 -3
- package/dist/{chunk-MPLNRUP3.js.map → chunk-NYKATVPZ.js.map} +1 -1
- package/dist/{chunk-QDXGSL5B.js → chunk-PWQPA2QL.js} +2 -2
- package/dist/{chunk-QDXGSL5B.js.map → chunk-PWQPA2QL.js.map} +1 -1
- package/dist/chunk-SVZY7ZZD.js +8 -0
- package/dist/chunk-SVZY7ZZD.js.map +1 -0
- package/dist/index.css +19 -0
- package/dist/index.d.ts +11 -1
- package/dist/index.js +1 -1
- package/dist/{list-IBUZ2LXU.js → list-PNKQAYUK.js} +2 -2
- package/dist/{list-IBUZ2LXU.js.map → list-PNKQAYUK.js.map} +1 -1
- package/dist/pages-KHFSZ3PH.js +3 -0
- package/dist/pages-KHFSZ3PH.js.map +1 -0
- package/dist/{plugin-pages-HQPZQSZT.js → plugin-pages-SE52XFFW.js} +2 -2
- package/dist/{plugin-pages-HQPZQSZT.js.map → plugin-pages-SE52XFFW.js.map} +1 -1
- package/dist/{root-XGNAKO5P.js → root-44ZJLA4E.js} +2 -2
- package/dist/{root-XGNAKO5P.js.map → root-44ZJLA4E.js.map} +1 -1
- package/dist/{root-ZY2HGDBT.js → root-BH3PQS2H.js} +3 -3
- package/dist/{root-ZY2HGDBT.js.map → root-BH3PQS2H.js.map} +1 -1
- package/dist/{root-4UVGZZRU.js → root-LFQA2VSE.js} +2 -2
- package/dist/{root-4UVGZZRU.js.map → root-LFQA2VSE.js.map} +1 -1
- package/dist/{root-HUJPHUHL.js → root-X5NDURAN.js} +3 -3
- package/dist/{root-HUJPHUHL.js.map → root-X5NDURAN.js.map} +1 -1
- package/dist/{search-N7G6BVN6.js → search-Q65IC67C.js} +2 -2
- package/dist/{search-N7G6BVN6.js.map → search-Q65IC67C.js.map} +1 -1
- package/dist/{skills-pages-VP32HFUN.js → skills-pages-TWOIIU5J.js} +2 -2
- package/dist/{skills-pages-VP32HFUN.js.map → skills-pages-TWOIIU5J.js.map} +1 -1
- package/package.json +3 -3
- package/dist/activity-nav-button-Z6M3FURW.js +0 -2
- package/dist/chunk-72TZUR4Q.js +0 -2
- package/dist/chunk-72TZUR4Q.js.map +0 -1
- package/dist/chunk-AN4APNXO.js +0 -2
- package/dist/chunk-AN4APNXO.js.map +0 -1
- package/dist/chunk-K7FD54PW.js +0 -6
- package/dist/chunk-K7FD54PW.js.map +0 -1
- package/dist/chunk-MM356YIK.js.map +0 -1
- package/dist/pages-ZKDDV5T3.js +0 -3
- package/dist/pages-ZKDDV5T3.js.map +0 -1
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/apps/ai/agent/dictation.ts","../src/apps/ai/api.ts"],"names":["appendDictatedText","existing","transcript","dictated","convertRecordedAudioToPcm","blob","AudioContextCtor","arrayBuffer","audioContext","audioBuffer","mono","mixToMono","resampled","resample","pcm","floatToPcm16","durationSeconds","buffer","length","channelCount","index","sum","channel","samples","sourceRate","targetRate","ratio","outputLength","output","sourceIndex","left","right","fraction","leftSample","rightSample","view","sample","AgentUploadError","status","message","code","getApiRootDomain","hostname","getPlatformOrigin","getWebhookTriggerUrl","projectId","token","createApiClient","projectBasePath","automationsBasePath","skillsBasePath","agentChatsBasePath","request","url","init","response","data","error","input","id","runId","chatId","workflowRunId","title","attachments","content","modelId","messageId","audio","signal","formData","file","tokenResponse","tokenData","put","approvalId","ids","itemId","state","automationId","skillId","artifactId","options","suffix","provider","connectionId","FetcherError","fetcher","paths","basePath","filter","limit","offset","params","since","query","enabled","search","visibility","value","trimmedSearch","scope"],"mappings":"0DAIO,SAASA,CAAAA,CAAmBC,CAAAA,CAAkBC,CAAAA,CAA4B,CAC/E,IAAMC,CAAAA,CAAWD,CAAAA,CAAW,IAAA,EAAK,CAEjC,OAAKC,CAAAA,CAIAF,CAAAA,CAAS,IAAA,GAIV,KAAA,CAAM,IAAA,CAAKA,CAAQ,CAAA,EAAK,WAAA,CAAY,IAAA,CAAKE,CAAQ,CAAA,CAC5C,CAAA,EAAGF,CAAQ,CAAA,EAAGE,CAAQ,CAAA,CAAA,CAGxB,CAAA,EAAGF,CAAQ,CAAA,CAAA,EAAIE,CAAQ,CAAA,CAAA,CAPrBF,CAAAA,CAAS,MAAA,GAAW,CAAA,CAAIE,CAAAA,C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AAA,EAAI,kBAAA,CAAmB8B,CAAO,CAAC,CAAA,CAAA,CACpE,MAAA,CAAQ,CAACE,CAAAA,CAAU,EAAC,GAAM,CACxB,GAAM,CAAE,KAAA,CAAAS,EAAQ,EAAA,CAAI,MAAA,CAAAC,CAAAA,CAAS,CAAA,CAAG,MAAA,CAAAK,CAAAA,CAAQ,UAAA,CAAAC,CAAW,CAAA,CAAIhB,CAAAA,CACjDW,CAAAA,CAAS,IAAI,eAAA,CAAgB,CACjC,MAAOF,CAAAA,CAAM,QAAA,EAAS,CACtB,MAAA,CAAQC,CAAAA,CAAO,QAAA,EACjB,CAAC,CAAA,CAEGM,CAAAA,EAAcA,CAAAA,CAAW,MAAA,CAAS,CAAA,EACpCL,CAAAA,CAAO,IAAI,YAAA,CAAcK,CAAAA,CAAW,IAAA,CAAK,GAAG,CAAC,CAAA,CAG/C,IAAME,CAAAA,CAAgBH,CAAAA,EAAQ,IAAA,EAAK,CAEnC,OAAIG,CAAAA,EACFP,CAAAA,CAAO,IAAI,GAAA,CAAKO,CAAa,CAAA,CAGxB,CAAA,EAAGlD,CAAc,CAAA,CAAA,EAAI2C,CAAAA,CAAO,QAAA,EAAU,CAAA,CAC/C,CAAA,CACA,MAAA,CAAQ,CAAA,aAAA,EAAgBhD,CAAS,CAAA,OAAA,CAAA,CACjC,KAAA,CAAQkC,CAAAA,EACNA,CAAAA,CAAe,CAAA,EAAGU,CAAQ,CAAA,CAAA,EAAI,kBAAA,CAAmBV,CAAY,CAAC,CAAA,MAAA,CAAA,CAAW,CAAA,EAAGU,CAAQ,CAAA,MAAA,CACxF,CACF","file":"chunk-MM356YIK.js","sourcesContent":["export const DICTATION_SAMPLE_RATE = 24_000;\nexport const DICTATION_MAX_DURATION_SECONDS = 60;\nexport const DICTATION_MIN_DURATION_SECONDS = 0.25;\n\nexport function appendDictatedText(existing: string, transcript: string): string {\n const dictated = transcript.trim();\n\n if (!dictated) {\n return existing;\n }\n\n if (!existing.trim()) {\n return existing.length === 0 ? dictated : `${existing}${dictated}`;\n }\n\n if (/\\s$/.test(existing) || /^[.,!?;:]/.test(dictated)) {\n return `${existing}${dictated}`;\n }\n\n return `${existing} ${dictated}`;\n}\n\nexport async function convertRecordedAudioToPcm(blob: Blob): Promise<{ durationSeconds: number; pcm: Blob }> {\n if (typeof window === 'undefined') {\n throw new Error('Dictation is only available in the browser.');\n }\n\n const AudioContextCtor = window.AudioContext ?? window.webkitAudioContext;\n\n if (!AudioContextCtor) {\n throw new Error('This browser cannot decode recorded audio.');\n }\n\n const arrayBuffer = await blob.arrayBuffer();\n const audioContext = new AudioContextCtor();\n\n try {\n const audioBuffer = await audioContext.decodeAudioData(arrayBuffer.slice(0));\n const mono = mixToMono(audioBuffer);\n const resampled = resample(mono, audioBuffer.sampleRate, DICTATION_SAMPLE_RATE);\n const pcm = floatToPcm16(resampled);\n const durationSeconds = resampled.length / DICTATION_SAMPLE_RATE;\n\n if (durationSeconds < DICTATION_MIN_DURATION_SECONDS) {\n throw new Error('No speech was captured. Try again.');\n }\n\n if (durationSeconds > DICTATION_MAX_DURATION_SECONDS) {\n throw new Error(`Dictation is limited to ${String(DICTATION_MAX_DURATION_SECONDS)} seconds.`);\n }\n\n return {\n durationSeconds,\n pcm: new Blob([pcm], { type: 'audio/pcm' }),\n };\n } finally {\n await audioContext.close();\n }\n}\n\nfunction mixToMono(buffer: AudioBuffer): Float32Array {\n const { length, numberOfChannels: channelCount } = buffer;\n\n if (channelCount === 1) {\n return buffer.getChannelData(0).slice();\n }\n\n const mono = new Float32Array(length);\n\n for (let index = 0; index < length; index += 1) {\n let sum = 0;\n\n for (let channel = 0; channel < channelCount; channel += 1) {\n sum += buffer.getChannelData(channel)[index] ?? 0;\n }\n\n mono[index] = sum / channelCount;\n }\n\n return mono;\n}\n\nfunction resample(samples: Float32Array, sourceRate: number, targetRate: number): Float32Array {\n if (sourceRate === targetRate) {\n return samples;\n }\n\n const ratio = sourceRate / targetRate;\n const outputLength = Math.max(1, Math.round(samples.length / ratio));\n const output = new Float32Array(outputLength);\n\n for (let index = 0; index < outputLength; index += 1) {\n const sourceIndex = index * ratio;\n const left = Math.floor(sourceIndex);\n const right = Math.min(left + 1, samples.length - 1);\n const fraction = sourceIndex - left;\n const leftSample = samples[left] ?? 0;\n const rightSample = samples[right] ?? 0;\n output[index] = leftSample + (rightSample - leftSample) * fraction;\n }\n\n return output;\n}\n\nfunction floatToPcm16(samples: Float32Array): ArrayBuffer {\n const buffer = new ArrayBuffer(samples.length * 2);\n const view = new DataView(buffer);\n\n for (let index = 0; index < samples.length; index += 1) {\n const sample = Math.max(-1, Math.min(1, samples[index] ?? 0));\n view.setInt16(index * 2, sample < 0 ? sample * 0x8000 : sample * 0x7fff, true);\n }\n\n return buffer;\n}\n\ndeclare global {\n interface Window {\n webkitAudioContext?: typeof AudioContext;\n }\n}\n","import type { PluginConnection, PluginScope, PluginTools } from './plugin-types';\nimport { put } from '@vercel/blob/client';\nimport { convertRecordedAudioToPcm } from './agent/dictation';\nimport type {\n ActivityItem,\n ActivityItemState,\n AgentChat,\n AgentChatAttachment,\n AgentChatFollowUpResult,\n AgentChatMessage,\n AgentChatTurn,\n Automation,\n AutomationApproval,\n AutomationApprovalStatus,\n AutomationArtifact,\n AutomationInput,\n AutomationToolChannel,\n AutomationToolProvider,\n AutomationVisibility,\n MutationResult,\n Skill,\n SkillInput,\n} from './types';\n\nexport interface DecideApprovalInput {\n /** Approve and always allow this plugin tool for the automation. */\n remember?: boolean;\n approved: boolean;\n force?: boolean;\n reason?: string;\n}\n\nexport interface SendAgentChatMessageInput {\n attachments?: AgentChatAttachment[];\n content: string;\n modelId?: string | null;\n}\n\n/** A new chat and its first turn, started by one request. */\nexport interface StartAgentChatResult {\n chat: AgentChat;\n turn: AgentChatTurn;\n}\n\n/** Thrown when the API refuses an upload; `code` lets the UI tailor the message. */\nexport class AgentUploadError extends Error {\n code: string | null;\n status: number;\n\n constructor(status: number, message: string, code: string | null = null) {\n super(message);\n this.name = 'AgentUploadError';\n this.code = code;\n this.status = status;\n }\n}\n\nexport interface ApiClient {\n /** Starts OAuth for a new account, or for `connectionId` to reconnect that specific account. */\n connectPlugins: (_input: {\n pluginId: string;\n scope: PluginScope;\n studioOrigin: string;\n connectionId?: string;\n }) => Promise<{ transactionId: string; authorizeUrl: string; completionOrigin: string; launchTicket: string }>;\n /** Renames (label null resets to the provider name) or makes a connection primary. */\n updatePluginConnection: (\n _id: string,\n _input: { label?: string | null; primary?: true }\n ) => Promise<{ connection: PluginConnection }>;\n pluginOAuthStatus: (_id: string) => Promise<{ id: string; status: 'pending' | 'exchanging' | 'complete' | 'failed'; expires_at: string }>;\n disconnectPlugin: (_id: string) => Promise<{ success: boolean }>;\n installPlugin: (_id: string) => Promise<unknown>;\n setPluginPolicy: (_id: string, _input: { enabled: boolean; allowPersonal: boolean }) => Promise<{ success: boolean }>;\n refreshPluginTools: (_id: string) => Promise<PluginTools>;\n\n cancelRun: (_runId: string) => Promise<MutationResult>;\n createAgentChat: (_input?: { modelId?: string | null }) => Promise<{ chat: AgentChat }>;\n deleteAgentChat: (_chatId: string) => Promise<{ success: boolean }>;\n getAgentChatStreamUrl: (_chatId: string, _workflowRunId: string) => string;\n renameAgentChat: (_chatId: string, _title: string) => Promise<{ chat: AgentChat }>;\n sendAgentChatMessage: (_chatId: string, _input: SendAgentChatMessageInput) => Promise<AgentChatTurn>;\n /**\n * Sends a message while the chat's turn is running. The platform decides\n * whether it steers that turn or waits as the next one; if the turn has\n * meanwhile ended, the message starts the next turn.\n */\n sendAgentChatFollowUp: (_chatId: string, _input: SendAgentChatMessageInput) => Promise<AgentChatFollowUpResult>;\n /** Creates a chat and sends its first message in one request. */\n startAgentChat: (_input: SendAgentChatMessageInput) => Promise<StartAgentChatResult>;\n /** Starts the next turn from a queued follow-up once the previous turn has ended. */\n startQueuedAgentChatMessage: (_chatId: string, _messageId: string) => Promise<AgentChatTurn>;\n stopAgentChat: (_chatId: string) => Promise<{ message: AgentChatMessage }>;\n transcribeAgentAudio: (_audio: Blob, _signal?: AbortSignal) => Promise<{ text: string }>;\n /** Uploads a chat attachment straight to the platform file store. */\n uploadAgentChatAttachment: (_file: File, _signal?: AbortSignal) => Promise<AgentChatAttachment>;\n decideApproval: (\n _approvalId: string,\n _input: DecideApprovalInput\n ) => Promise<MutationResult & { approval?: AutomationApproval }>;\n createAutomation: (_input: AutomationInput) => Promise<MutationResult & { automation?: Automation }>;\n createSkill: (_input: SkillInput) => Promise<MutationResult & { skill?: Skill }>;\n deleteAutomation: (_automationId: string) => Promise<MutationResult>;\n deleteSkill: (_skillId: string) => Promise<MutationResult>;\n getArtifactUrl: (_artifactId: string, _options?: { download?: boolean }) => string;\n getRunArtifacts: (_workflowRunId: string) => Promise<AutomationArtifact[]>;\n getStreamUrl: (_workflowRunId: string) => string;\n /** JSON transcript of a finished run (owners and developers). */\n getTranscriptUrl: (_runId: string) => string;\n /** Lists delivery channels of `connectionId`, or of the provider's primary project account when omitted. */\n listChannels: (_provider: AutomationToolProvider, _connectionId?: string | null) => Promise<{\n channels: AutomationToolChannel[];\n errorMessage?: string;\n success: boolean;\n }>;\n runAutomation: (_automationId: string) => Promise<MutationResult & { runId?: string }>;\n updateAutomation: (\n _automationId: string,\n _input: AutomationInput\n ) => Promise<MutationResult & { automation?: Automation }>;\n updateSkill: (_skillId: string, _input: SkillInput) => Promise<MutationResult & { skill?: Skill }>;\n /** Marks the caller's Activity items read; `'all'` marks every unread item. */\n markActivityRead: (_ids: string[] | 'all') => Promise<{ success: boolean }>;\n setActivityItemState: (\n _itemId: string,\n _state: Extract<ActivityItemState, 'unread' | 'read' | 'dismissed'>\n ) => Promise<{ item: ActivityItem }>;\n}\n\n\nfunction getApiRootDomain(): string {\n if (typeof window === 'undefined') {\n return 'flexkit.io';\n }\n\n const { hostname } = window.location;\n const isDevHost =\n hostname === 'localhost' ||\n hostname === '127.0.0.1' ||\n hostname === 'flexkit.test' ||\n hostname.endsWith('.flexkit.test');\n\n return isDevHost ? 'flexkit.test' : 'flexkit.io';\n}\n\n/** Origin that hosts plugin OAuth start and completion. */\nexport function getPlatformOrigin(): string {\n return `https://${getApiRootDomain()}`;\n}\n\n/** Public URL an external system calls to fire a webhook trigger. */\nexport function getWebhookTriggerUrl(projectId: string, token: string): string {\n return `https://${projectId}.api.${getApiRootDomain()}/automations/webhook/${encodeURIComponent(token)}`;\n}\n\nexport function createApiClient(projectId: string): ApiClient {\n const projectBasePath = `/api/flexkit/${projectId}`;\n const automationsBasePath = `${projectBasePath}/automations`;\n const skillsBasePath = `${projectBasePath}/skills`;\n const agentChatsBasePath = `${projectBasePath}/agent/chats`;\n\n async function request<T>(url: string, init?: RequestInit): Promise<T> {\n const response = await fetch(url, {\n credentials: 'include',\n headers: {\n 'Content-Type': 'application/json',\n ...(init?.headers ?? {}),\n },\n ...init,\n });\n const data = (await response.json()) as T;\n\n if (!response.ok) {\n const error = data && typeof data === 'object' && 'error' in data ? String(data.error) : 'Request failed';\n\n throw new Error(error);\n }\n\n return data;\n }\n\n return {\n connectPlugins: (input) => request(`${projectBasePath}/plugins/connect`, { method: 'POST', body: JSON.stringify(input) }),\n pluginOAuthStatus: (id) => request(`${projectBasePath}/plugins/oauth-transactions/${encodeURIComponent(id)}`),\n updatePluginConnection: (id, input) =>\n request(`${projectBasePath}/plugin-connections/${encodeURIComponent(id)}`, { method: 'PATCH', body: JSON.stringify(input) }),\n disconnectPlugin: (id) => request(`${projectBasePath}/plugin-connections/${encodeURIComponent(id)}`, { method: 'DELETE' }),\n installPlugin: (id) => request(`${projectBasePath}/plugins/${encodeURIComponent(id)}/installation`, { method: 'PUT', body: JSON.stringify({}) }),\n setPluginPolicy: (id, input) => request(`${projectBasePath}/plugins/${encodeURIComponent(id)}/policy`, { method: 'PATCH', body: JSON.stringify(input) }),\n refreshPluginTools: (id) => request(`${projectBasePath}/plugin-connections/${encodeURIComponent(id)}/tools/refresh`, { method: 'POST' }),\n cancelRun: async (runId) =>\n request<MutationResult>(`${automationsBasePath}/runs/${encodeURIComponent(runId)}/cancel`, { method: 'POST' }),\n createAgentChat: async (input) =>\n request<{ chat: AgentChat }>(agentChatsBasePath, {\n body: JSON.stringify({ modelId: input?.modelId ?? null }),\n method: 'POST',\n }),\n deleteAgentChat: async (chatId) =>\n request<{ success: boolean }>(`${agentChatsBasePath}/${encodeURIComponent(chatId)}`, { method: 'DELETE' }),\n getAgentChatStreamUrl: (chatId, workflowRunId) =>\n `${agentChatsBasePath}/${encodeURIComponent(chatId)}/stream?workflowRunId=${encodeURIComponent(workflowRunId)}`,\n renameAgentChat: async (chatId, title) =>\n request<{ chat: AgentChat }>(`${agentChatsBasePath}/${encodeURIComponent(chatId)}`, {\n body: JSON.stringify({ title }),\n method: 'PATCH',\n }),\n sendAgentChatMessage: async (chatId, input) =>\n request<AgentChatTurn>(`${agentChatsBasePath}/${encodeURIComponent(chatId)}/messages`, {\n body: JSON.stringify(input),\n method: 'POST',\n }),\n sendAgentChatFollowUp: async (chatId, input) =>\n request<AgentChatFollowUpResult>(`${agentChatsBasePath}/${encodeURIComponent(chatId)}/follow-ups`, {\n body: JSON.stringify(input),\n method: 'POST',\n }),\n startAgentChat: async ({ attachments, content, modelId }) =>\n request<StartAgentChatResult>(agentChatsBasePath, {\n body: JSON.stringify({ message: { attachments, content }, modelId: modelId ?? null }),\n method: 'POST',\n }),\n startQueuedAgentChatMessage: async (chatId, messageId) =>\n request<AgentChatTurn>(\n `${agentChatsBasePath}/${encodeURIComponent(chatId)}/follow-ups/${encodeURIComponent(messageId)}/start`,\n { method: 'POST' }\n ),\n stopAgentChat: async (chatId) =>\n request<{ message: AgentChatMessage }>(`${agentChatsBasePath}/${encodeURIComponent(chatId)}/stop`, {\n method: 'POST',\n }),\n transcribeAgentAudio: async (audio, signal) => {\n const { durationSeconds, pcm } = await convertRecordedAudioToPcm(audio);\n const formData = new FormData();\n formData.append('file', pcm, 'audio.pcm');\n formData.append('durationSeconds', String(durationSeconds));\n\n const response = await fetch(`${projectBasePath}/agent/transcribe`, {\n body: formData,\n credentials: 'include',\n method: 'POST',\n signal,\n });\n const data = (await response.json()) as { error?: string; text?: string };\n\n if (!response.ok) {\n const error = data && typeof data === 'object' && data.error ? String(data.error) : 'Request failed';\n\n throw new Error(error);\n }\n\n if (!data.text?.trim()) {\n throw new Error('No speech was recognized. Try again.');\n }\n\n return { text: data.text };\n },\n uploadAgentChatAttachment: async (file, signal) => {\n // The platform issues a token scoped to one pathname, type and size; the\n // browser then writes the bytes to the store directly, so large files\n // never pass through the API function body limit.\n const tokenResponse = await fetch(`${projectBasePath}/agent/uploads`, {\n body: JSON.stringify({ filename: file.name, mediaType: file.type || null, sizeBytes: file.size }),\n credentials: 'include',\n headers: { 'Content-Type': 'application/json' },\n method: 'POST',\n signal,\n });\n const tokenData = (await tokenResponse.json()) as {\n code?: string;\n error?: string;\n mediaType?: string;\n pathname?: string;\n token?: string;\n };\n\n if (!tokenResponse.ok || !tokenData.pathname || !tokenData.token || !tokenData.mediaType) {\n throw new AgentUploadError(\n tokenResponse.status,\n tokenData.error ? String(tokenData.error) : 'The file could not be uploaded.',\n tokenData.code ?? null\n );\n }\n\n const blob = await put(tokenData.pathname, file, {\n abortSignal: signal,\n access: 'public',\n contentType: tokenData.mediaType,\n token: tokenData.token,\n });\n\n return {\n filename: file.name,\n mediaType: tokenData.mediaType,\n sizeBytes: file.size,\n url: blob.url,\n };\n },\n decideApproval: async (approvalId, input) => {\n const response = await fetch(`${automationsBasePath}/approvals/${encodeURIComponent(approvalId)}/decide`, {\n body: JSON.stringify(input),\n credentials: 'include',\n headers: {\n 'Content-Type': 'application/json',\n },\n method: 'POST',\n });\n const data = (await response.json()) as MutationResult & { approval?: AutomationApproval; error?: string };\n\n // Business errors (stale_preview, already_decided) come back as 400\n // with a structured body the caller must be able to inspect.\n if (!response.ok && typeof data.success !== 'boolean') {\n throw new Error(data.error ? String(data.error) : 'Request failed');\n }\n\n return data;\n },\n markActivityRead: async (ids) =>\n request<{ success: boolean }>(`${projectBasePath}/activity/read`, {\n body: JSON.stringify(ids === 'all' ? { all: true } : { ids }),\n method: 'POST',\n }),\n setActivityItemState: async (itemId, state) =>\n request<{ item: ActivityItem }>(`${projectBasePath}/activity/${encodeURIComponent(itemId)}`, {\n body: JSON.stringify({ state }),\n method: 'PATCH',\n }),\n createAutomation: async (input) =>\n request<MutationResult & { automation?: Automation }>(automationsBasePath, {\n body: JSON.stringify(input),\n method: 'POST',\n }),\n createSkill: async (input) =>\n request<MutationResult & { skill?: Skill }>(skillsBasePath, {\n body: JSON.stringify(input),\n method: 'POST',\n }),\n deleteAutomation: async (automationId) =>\n request<MutationResult>(`${automationsBasePath}/${encodeURIComponent(automationId)}`, { method: 'DELETE' }),\n deleteSkill: async (skillId) =>\n request<MutationResult>(`${skillsBasePath}/${encodeURIComponent(skillId)}`, { method: 'DELETE' }),\n getArtifactUrl: (artifactId, options) => {\n const suffix = options?.download ? '?download=1' : '';\n\n return `${automationsBasePath}/artifacts/${encodeURIComponent(artifactId)}/content${suffix}`;\n },\n getRunArtifacts: async (workflowRunId) =>\n request<{ artifacts: AutomationArtifact[] }>(\n `${automationsBasePath}/runs/${encodeURIComponent(workflowRunId)}/artifacts`\n ).then((response) => response.artifacts),\n getStreamUrl: (workflowRunId) => `${automationsBasePath}/runs/${encodeURIComponent(workflowRunId)}/stream`,\n getTranscriptUrl: (runId) => `${automationsBasePath}/runs/${encodeURIComponent(runId)}/transcript`,\n listChannels: async (provider, connectionId) => {\n const url = connectionId\n ? `${projectBasePath}/plugin-connections/${encodeURIComponent(connectionId)}/channels`\n : `${projectBasePath}/plugins/${provider}/channels`;\n const response = await fetch(url, {\n credentials: 'include',\n headers: {\n 'Content-Type': 'application/json',\n },\n });\n const data = (await response.json()) as {\n channels?: AutomationToolChannel[];\n error?: string;\n errorMessage?: string;\n success?: boolean;\n };\n\n if (response.ok) {\n return {\n channels: data.channels ?? [],\n errorMessage: data.errorMessage,\n success: data.success ?? true,\n };\n }\n\n if (data.success === false) {\n return {\n channels: data.channels ?? [],\n errorMessage: data.errorMessage ?? `Failed to load ${provider === 'slack' ? 'Slack' : 'Teams'} channels.`,\n success: false,\n };\n }\n\n const error = data.error ? String(data.error) : 'Request failed';\n\n throw new Error(error);\n },\n runAutomation: async (automationId) =>\n request<MutationResult & { runId?: string }>(`${automationsBasePath}/${encodeURIComponent(automationId)}/runs`, {\n method: 'POST',\n }),\n updateAutomation: async (automationId, input) =>\n request<MutationResult & { automation?: Automation }>(\n `${automationsBasePath}/${encodeURIComponent(automationId)}`,\n {\n body: JSON.stringify(input),\n method: 'PATCH',\n }\n ),\n updateSkill: async (skillId, input) =>\n request<MutationResult & { skill?: Skill }>(`${skillsBasePath}/${encodeURIComponent(skillId)}`, {\n body: JSON.stringify(input),\n method: 'PATCH',\n }),\n };\n}\n\nexport class FetcherError extends Error {\n status: number;\n\n constructor(status: number, message = 'Request failed') {\n super(message);\n this.name = 'FetcherError';\n this.status = status;\n }\n}\n\nexport const fetcher = async <T>(url: string): Promise<T> => {\n const response = await fetch(url, { credentials: 'include' });\n\n if (!response.ok) {\n throw new FetcherError(response.status);\n }\n\n return (await response.json()) as T;\n};\n\nexport function paths(projectId: string): {\n activity: (_options?: { filter?: 'all' | 'needs_action'; limit?: number; offset?: number }) => string;\n activityItem: (_itemId: string) => string;\n /** Badge counts; with `since`, also the unread items created after it. */\n activitySummary: (_since?: string | null) => string;\n agentChat: (_chatId: string) => string;\n agentChatSearch: (_query: string) => string;\n agentChats: (_offset?: number) => string;\n agentProfile: () => string;\n approval: (_approvalId: string) => string;\n approvals: (_options?: {\n limit?: number;\n offset?: number;\n runId?: string;\n status?: AutomationApprovalStatus;\n }) => string;\n approvalsCount: string;\n automation: (_automationId: string) => string;\n automationRuns: (_automationId: string, _offset?: number, _limit?: number) => string;\n automations: (_options?: {\n enabled?: boolean[];\n limit?: number;\n offset?: number;\n search?: string;\n visibility?: AutomationVisibility[];\n }) => string;\n creditBalance: string;\n entities: string;\n run: (_runId: string) => string;\n runHistory: (_scope: 'mine' | 'team', _offset?: number, _limit?: number) => string;\n skill: (_skillId: string) => string;\n skills: (_options?: { limit?: number; offset?: number; search?: string; visibility?: AutomationVisibility[] }) => string;\n spaces: string;\n tools: (_automationId?: string) => string;\n} {\n const basePath = `/api/flexkit/${projectId}/automations`;\n const skillsBasePath = `/api/flexkit/${projectId}/skills`;\n const agentChatsBasePath = `/api/flexkit/${projectId}/agent/chats`;\n\n return {\n activity: (options = {}) => {\n const { filter = 'all', limit = 25, offset = 0 } = options;\n const params = new URLSearchParams({ filter, limit: limit.toString(), offset: offset.toString() });\n\n return `/api/flexkit/${projectId}/activity?${params.toString()}`;\n },\n activityItem: (itemId) => `/api/flexkit/${projectId}/activity/${encodeURIComponent(itemId)}`,\n activitySummary: (since) =>\n since\n ? `/api/flexkit/${projectId}/activity/summary?since=${encodeURIComponent(since)}`\n : `/api/flexkit/${projectId}/activity/summary`,\n agentChat: (chatId) => `${agentChatsBasePath}/${encodeURIComponent(chatId)}`,\n agentChatSearch: (query) => `${agentChatsBasePath}/search?q=${encodeURIComponent(query)}`,\n agentChats: (offset = 0) => `${agentChatsBasePath}?offset=${offset.toString()}`,\n agentProfile: () => `/api/flexkit/${projectId}/agent/profile`,\n approval: (approvalId) => `${basePath}/approvals/${encodeURIComponent(approvalId)}`,\n approvals: (options = {}) => {\n const { limit = 25, offset = 0, runId, status } = options;\n const params = new URLSearchParams({\n limit: limit.toString(),\n offset: offset.toString(),\n });\n\n if (status) {\n params.set('status', status);\n }\n\n if (runId) {\n params.set('runId', runId);\n }\n\n return `${basePath}/approvals?${params.toString()}`;\n },\n approvalsCount: `${basePath}/approvals?limit=1`,\n automation: (automationId) => `${basePath}/${encodeURIComponent(automationId)}`,\n automationRuns: (automationId, offset = 0, limit = 25) =>\n `${basePath}/${encodeURIComponent(automationId)}/runs?offset=${offset.toString()}&limit=${limit.toString()}`,\n automations: (options = {}) => {\n const { enabled, limit = 25, offset = 0, search, visibility } = options;\n const params = new URLSearchParams({\n limit: limit.toString(),\n offset: offset.toString(),\n });\n\n if (enabled && enabled.length > 0) {\n params.set('enabled', enabled.map((value) => (value ? 'true' : 'false')).join(','));\n }\n\n if (visibility && visibility.length > 0) {\n params.set('visibility', visibility.join(','));\n }\n\n const trimmedSearch = search?.trim();\n\n if (trimmedSearch) {\n params.set('q', trimmedSearch);\n }\n\n return `${basePath}?${params.toString()}`;\n },\n creditBalance: `${basePath}/credits`,\n entities: `${basePath}/entities`,\n run: (runId) => `${basePath}/runs/${encodeURIComponent(runId)}`,\n runHistory: (scope, offset = 0, limit = 25) =>\n `${basePath}/runs?scope=${scope}&offset=${offset.toString()}&limit=${limit.toString()}`,\n skill: (skillId) => `${skillsBasePath}/${encodeURIComponent(skillId)}`,\n skills: (options = {}) => {\n const { limit = 25, offset = 0, search, visibility } = options;\n const params = new URLSearchParams({\n limit: limit.toString(),\n offset: offset.toString(),\n });\n\n if (visibility && visibility.length > 0) {\n params.set('visibility', visibility.join(','));\n }\n\n const trimmedSearch = search?.trim();\n\n if (trimmedSearch) {\n params.set('q', trimmedSearch);\n }\n\n return `${skillsBasePath}?${params.toString()}`;\n },\n spaces: `/api/flexkit/${projectId}/spaces`,\n tools: (automationId) =>\n automationId ? `${basePath}/${encodeURIComponent(automationId)}/tools` : `${basePath}/tools`,\n };\n}\n"]}
|
package/dist/pages-ZKDDV5T3.js
DELETED
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
import'./index.css';import {f as f$4,b as b$6,c as c$3,d as d$2,e as e$4,g as g$3}from'./chunk-CSUHZFEP.js';import {q,a,b as b$4,d,c as c$2,r,v as v$1,w as w$1,u,g as g$2,h as h$1,i,f as f$3,s,B,x,A,e as e$3,y}from'./chunk-K7FD54PW.js';import {a as a$3,b as b$7}from'./chunk-72TZUR4Q.js';import {b as b$5,e as e$2,c as c$1,d as d$1,f as f$2}from'./chunk-AN4APNXO.js';import {f,g,e as e$7,c as c$5,d as d$4}from'./chunk-MM356YIK.js';import {a as a$1}from'./chunk-3C2EG3SI.js';import {b}from'./chunk-7SK5YPHT.js';import'./chunk-76CL7HSO.js';import {h as h$2}from'./chunk-NNA4MLFC.js';import {_,$,ca,da,aa as aa$1,ea,N,f as f$1,ma,ga,ha,ia,_a,$a as $a$1,bb,oa as oa$1,s as s$1,e as e$5,Z,ka,t as t$1,u as u$1,v as v$2}from'./chunk-YCCFUGWJ.js';import {b as b$1,v,w,x as x$1,m,o as o$1,p,q as q$2,r as r$2,t as t$2}from'./chunk-32ZU4MLE.js';import {a as a$2,d as d$3,c as c$4,e as e$6,g as g$4}from'./chunk-HDOIOXMP.js';import {e,g as g$1,h,j,o,t,q as q$1,r as r$1,s as s$2,k}from'./chunk-SZEGGBOC.js';import'./chunk-U45E5X3H.js';import {b as b$3,c,e as e$1}from'./chunk-USNXQOMJ.js';import {b as b$2}from'./chunk-6NRQMG26.js';import'./chunk-O2QMYUPS.js';import {useState,useRef,useMemo,useCallback,useEffect,useTransition,Fragment as Fragment$1}from'react';import {formatDistance,format}from'date-fns';import {Ellipsis,Pencil,Trash2,Plus,ArrowLeft,LoaderCircle,Play,XIcon,TriangleAlertIcon,ZapIcon,BotIcon,Search,X,CoinsIcon,BrainIcon,Trash2Icon,LoaderCircleIcon,GraduationCapIcon,WrenchIcon,BellIcon,ClockIcon,WebhookIcon,DatabaseZapIcon,PlusIcon,ChevronsUpDownIcon,CheckIcon,RefreshCwIcon,ChevronDownIcon,LockIcon,CopyIcon,KeyRoundIcon}from'lucide-react';import {useNavigate,Link,useParams}from'react-router-dom';import {useReactTable,getCoreRowModel}from'@tanstack/react-table';import De,{useSWRConfig}from'swr';import bt from'swr/infinite';import {jsx,jsxs,Fragment}from'react/jsx-runtime';import {CronExpressionParser}from'cron-parser';var xa=[{label:"Enabled",value:"enabled"},{label:"Disabled",value:"disabled"}],Na=[{label:"Project",value:"project"},{label:"Space",value:"space"},{label:"Personal",value:"personal"}];function Ta(t,n=300){let o,i=function(...l){o!==void 0&&clearTimeout(o),o=setTimeout(()=>{o=void 0,t.apply(this,l);},n);};return i.cancel=()=>{o!==void 0&&(clearTimeout(o),o=void 0);},i}function To({actions:t,isSearchLoading:n=false,onSearchChange:o,search:i,searchPlaceholder:l="Search automations...",table:g}){let d=g.getState().columnFilters.length>0||i.trim().length>0,k=g.getAllColumns().find(R=>R.id==="status"),r=g.getAllColumns().find(R=>R.id==="visibility"),[m,u]=useState(i),T=m.trim(),I=i.trim(),C=T.length>0&&(n||T!==I),$=useRef(o);$.current=o;let A=useMemo(()=>Ta(R=>{$.current(R);},300),[]);useEffect(()=>{u(i);},[i]),useEffect(()=>()=>{A.cancel();},[A]);function y(){A.cancel(),u(""),o("");}function h(){g.resetColumnFilters(),y();}return jsx("div",{className:"fk:flex fk:w-full fk:min-w-0",children:jsxs(w,{className:"fk:w-0 fk:min-w-0 fk:flex-1 fk:whitespace-nowrap fk:-ml-0.75",children:[jsxs("div",{className:"fk:flex fk:w-full fk:items-center fk:justify-between fk:gap-3 fk:p-0.75 fk:pb-2.5",children:[jsxs("div",{className:"fk:flex fk:shrink-0 fk:items-center fk:gap-2",children:[jsxs("div",{className:"fk:relative",children:[C?jsx(LoaderCircle,{className:"fk:absolute fk:left-2 fk:top-2 fk:h-4 fk:w-4 fk:shrink-0 fk:opacity-50 fk:animate-spin"}):jsx(Search,{className:"fk:absolute fk:left-2 fk:top-2 fk:h-4 fk:w-4 fk:shrink-0 fk:opacity-50"}),jsx(s$1,{className:"fk:h-8 fk:w-37.5 fk:lg:w-70 fk:px-7 fk:text-sm",name:"search-automations",placeholder:l,value:m,onChange:R=>{let{value:F}=R.target;if(u(F),F.trim().length===0){A.cancel(),o("");return}A(F.trim());}}),m?jsx(b$2,{"aria-label":"Clear search",className:"fk:absolute fk:right-1 fk:top-1 fk:h-6 fk:w-6 fk:text-muted-foreground fk:hover:text-foreground fk:hover:bg-foreground/10 fk:cursor-pointer fk:rounded-full fk:bg-transparent fk:corner-squircle",onClick:y,type:"button",children:jsx(X,{className:"fk:h-4 fk:w-4"})}):null]}),k?jsx(a$1,{column:k,options:xa,title:"Status"}):null,r?jsx(a$1,{column:r,options:Na,title:"Visibility"}):null,d?jsxs(b$2,{className:"fk:h-8 fk:px-2 fk:lg:px-3",onClick:h,variant:"ghost",children:["Reset",jsx(X,{className:"fk:ml-2 fk:h-4 fk:w-4"})]}):null]}),t?jsx("div",{className:"fk:ml-auto fk:flex fk:shrink-0 fk:items-center fk:gap-3",children:t}):null]}),jsx(x$1,{orientation:"horizontal"})]})})}function kn(t,n,o){return (o??[]).some(i=>i.toLowerCase().includes(n.trim().toLowerCase()))?1:0}function pn({disabled:t,emptyText:n,footer:o,items:i,searchPlaceholder:l,onToggle:g}){let[d,k]=useState(false),r=useRef(null);return jsxs(t$1,{open:d,onOpenChange:k,children:[jsx(u$1,{asChild:true,children:jsxs(b$2,{disabled:t,size:"sm",type:"button",variant:"outline",children:["Attach",jsx(ChevronDownIcon,{className:"fk:ml-1 fk:size-4"})]})}),jsx(v$2,{align:"end",className:"fk:w-72 fk:p-0",onOpenAutoFocus:m=>{m.preventDefault(),r.current?.focus({preventScroll:true});},children:jsxs(m,{filter:kn,children:[jsx(o$1,{placeholder:l,ref:r}),jsxs(p,{className:"fk:max-h-72",children:[jsx(q$2,{children:n}),jsx(r$2,{children:i.map(m=>jsxs(t$2,{disabled:!!m.lockedHint,title:m.lockedHint,value:m.id,keywords:[m.label],onSelect:()=>g(m.id,!m.attached),children:[m.lockedHint?jsx(LockIcon,{className:"fk:size-4"}):jsx(CheckIcon,{className:m.attached?"fk:size-4":"fk:size-4 fk:opacity-0"}),jsx("span",{className:"fk:truncate",children:m.label}),m.badge?jsx(b$1,{className:"fk:ml-auto fk:py-0 fk:text-[10px]",variant:"secondary",children:m.badge}):null]},m.id))})]}),o]})})]})}function wo(t){return t==="project"?"Project":"Personal"}function kt(t,n){return t.connections.filter(o=>o.scope===n&&o.status==="connected")}function hn(t,n){if(!n)return null;let o=kt(t,n.connectionMode);return n.connectionId?o.find(i=>i.id===n.connectionId)??null:o.find(i=>i.isPrimary)??null}function mt(t){return t?t.connectionId?`account:${t.connectionId}`:`primary:${t.connectionMode}`:""}function bn({ariaLabel:t,disabled:n,plugin:o,scopes:i,value:l,onChange:g}){let d=[];for(let r of i){let m=kt(o,r),u=m.find(I=>I.isPrimary),[T]=m;if(m.length===1&&T){let I=l?.connectionMode===r&&l.connectionId===T.id;d.push({choice:{connectionMode:r,connectionId:I||!T.isPrimary?T.id:null},label:`${wo(r)} \xB7 ${T.displayName}`});continue}u&&d.push({choice:{connectionMode:r,connectionId:null},label:`Primary ${r} account (${u.displayName})`});for(let I of m)d.push({choice:{connectionMode:r,connectionId:I.id},label:`${wo(r)} \xB7 ${I.displayName}`});}let k=mt(l);return jsxs(a$2,{disabled:n,value:d.some(r=>mt(r.choice)===k)?k:"",onValueChange:r=>{let m=d.find(u=>mt(u.choice)===r);m&&g(m.choice);},children:[jsx(d$3,{"aria-label":t,className:"fk:w-fit fk:max-w-full",size:"sm",children:jsx(c$4,{placeholder:"Select account"})}),jsx(e$6,{children:d.map(r=>jsx(g$4,{value:mt(r.choice),children:r.label},mt(r.choice)))})]})}var gn=2;function Io(t){return t.scopes.filter(n=>n==="project"||t.allowPersonal)}function La(t){let n=Io(t),o=n.includes("personal")&&(!n.includes("project")||kt(t,"project").length===0&&kt(t,"personal").length>0);return {pluginId:t.id,enabled:true,connectionMode:o?"personal":"project",connectionId:null,allTools:true,selectedTools:[],deliveryEnabled:false,channels:[]}}function za(t,n){return `${encodeURIComponent(t)}:${encodeURIComponent(n)}`}function Fa(t){return decodeURIComponent(t.slice(t.indexOf(":")+1))}function Ba(t){let n=t.map(Fa),o=n.slice(0,gn).join(", ");return n.length>gn?`${o} +${n.length-gn} more`:o}function $a({canManage:t,disabled:n,plugin:o$1,projectId:i,usage:l,onChange:g,onRemove:d}){let k=Io(o$1),r=k.some(x=>kt(o$1,x).length>0),m=k.includes(l.connectionMode)?{connectionMode:l.connectionMode,connectionId:l.connectionId}:null,u=hn(o$1,m),{data:T,error:I}=De(u?`/api/flexkit/${i}/plugin-connections/${u.id}/tools`:null,f),C=(T?.servers??[]).flatMap(x=>x.tools.map(X=>({key:za(x.name,X.name),entry:X}))),$=(T?.servers??[]).flatMap(x=>x.error?[x.error]:[]),A=l.allTools!==false,y=n||!o$1.enabled,h$1=x=>g({...l,allTools:false,selectedTools:x,enabled:x.length>0}),R=()=>g({...l,allTools:true,selectedTools:[],enabled:true}),F=x=>({...l,connectionMode:x.connectionMode,connectionId:x.connectionId,selectedTools:[],enabled:A}),{mutate:w}=useSWRConfig(),[S,E]=useState(false),M=async x=>{E(true);try{await a$3(d$4(i),o$1.id,x),await w(`/api/flexkit/${i}/plugins`),g(F({connectionMode:x,connectionId:null}));}catch(X){oa$1.error(X instanceof Error?X.message:`Unable to connect ${o$1.name}.`);}finally{E(false);}},_=null;return o$1.enabled?r?m?u?I||$.length?_={text:$[0]??"Unable to load tools. Reconnect or try again.",tone:"warning"}:A?_={text:"All tools",tone:"muted"}:l.selectedTools.length===0?_={text:"No tools selected, so the agent cannot use this plugin yet.",tone:"warning"}:_={text:Ba(l.selectedTools),tone:"muted"}:_={text:m.connectionId?"The selected account is no longer connected.":`The primary ${m.connectionMode} account needs reconnecting.`,tone:"warning"}:_={text:"Select an account.",tone:"warning"}:_={text:`Connect ${o$1.name} to use its tools.`,tone:"warning"}:_={text:"Disabled by project policy.",tone:"warning"},jsxs(Fragment,{children:[jsxs("div",{className:"fk:m-1.5 fk:flex fk:flex-wrap fk:items-center fk:justify-between fk:gap-x-3 fk:gap-y-2 fk:rounded-md fk:px-1.25 fk:py-1.5 fk:hover:bg-muted fk:corner-squircle",children:[jsxs("div",{className:"fk:flex fk:min-w-0 fk:flex-1 fk:items-center fk:gap-2.5",children:[jsx("img",{src:o$1.logoUrl,alt:"",className:"fk:size-5 fk:shrink-0 fk:rounded fk:corner-squircle fk:self-start"}),jsxs("div",{className:"fk:min-w-0",children:[jsx("div",{className:"fk:text-sm fk:font-medium",children:o$1.name}),jsx("p",{className:_.tone==="warning"?"fk:truncate fk:text-xs fk:text-warning":"fk:truncate fk:text-xs fk:text-muted-foreground",children:_.text}),l.connectionMode==="personal"&&l.enabled?jsx("p",{className:"fk:text-xs fk:text-muted-foreground",children:"Using your account makes this automation personal."}):null]})]}),jsxs("div",{className:"fk:flex fk:flex-wrap fk:items-center fk:gap-1.5",children:[r?jsxs(Fragment,{children:[jsx(bn,{ariaLabel:`${o$1.name} account`,disabled:y,plugin:o$1,scopes:k,value:m,onChange:x=>{x.connectionMode===l.connectionMode&&x.connectionId===l.connectionId||g(F(x));}}),jsxs(e,{children:[jsx(g$1,{asChild:true,children:jsxs(b$2,{disabled:y||!u||!T,size:"sm",type:"button",variant:"outline",children:[A?"All tools":l.selectedTools.length?`Tools (${l.selectedTools.length})`:"Select tools",jsx(ChevronDownIcon,{className:"fk:ml-1 fk:size-4"})]})}),jsxs(h,{align:"end",className:"fk:max-h-80 fk:w-80 fk:overflow-y-auto",children:[jsxs(j,{className:"fk:items-start",onSelect:x=>{x.preventDefault(),A?h$1(C.map(X=>X.key)):R();},children:[jsx(CheckIcon,{className:A?"fk:mt-0.5 fk:size-4":"fk:mt-0.5 fk:size-4 fk:opacity-0"}),jsxs("span",{className:"fk:min-w-0",children:[jsx("span",{className:"fk:block",children:"All tools (recommended)"}),jsx("span",{className:"fk:text-xs fk:text-muted-foreground",children:"Includes tools added later. Uncheck to pick specific ones."})]})]}),jsx(o,{}),C.map(({key:x,entry:X})=>{let W=A||l.selectedTools.includes(x);return jsxs(j,{className:"fk:items-start",onSelect:me=>{me.preventDefault();let G=A?C.map(he=>he.key):l.selectedTools;h$1(W?G.filter(he=>he!==x):[...G,x]);},children:[jsx(CheckIcon,{className:W?"fk:mt-0.5 fk:size-4":"fk:mt-0.5 fk:size-4 fk:opacity-0"}),jsxs("span",{className:"fk:min-w-0",children:[jsx("span",{className:"fk:block",children:X.name}),X.description?jsx("span",{className:"fk:line-clamp-2 fk:text-xs fk:text-muted-foreground",children:X.description}):null]})]},x)}),T&&C.length===0?jsx(j,{disabled:true,children:"This account exposes no tools."}):null]})]})]}):jsx(b$7,{busy:S||n,canManage:t,plugin:o$1,onConnect:x=>{M(x);}}),jsx(b$2,{"aria-label":`Remove ${o$1.name} from automation`,disabled:n,size:"icon",type:"button",variant:"ghost",onClick:d,children:jsx(Trash2Icon,{className:"fk:size-4"})})]})]}),jsx(v,{})]})}function ja({disabled:t,plugins:n,onAdd:o}){let[i,l]=useState(false),g=useRef(null);return jsxs(t$1,{open:i,onOpenChange:l,children:[jsx(u$1,{asChild:true,children:jsxs("button",{className:"fk:m-1.5 fk:flex fk:w-[calc(100%-0.75rem)] fk:cursor-pointer fk:items-center fk:gap-2.5 fk:rounded-md fk:px-1.25 fk:py-1.5 fk:text-left fk:text-sm fk:text-muted-foreground fk:hover:bg-muted fk:hover:text-foreground disabled:fk:cursor-not-allowed disabled:fk:opacity-50 fk:corner-squircle",disabled:t||n.length===0,type:"button",children:[jsx(PlusIcon,{className:"fk:size-5"}),"Plugin tools"]})}),jsx(v$2,{align:"start",className:"fk:w-72 fk:p-0",onOpenAutoFocus:d=>{d.preventDefault(),g.current?.focus({preventScroll:true});},children:jsxs(m,{filter:kn,children:[jsx(o$1,{placeholder:"Search plugins\u2026",ref:g}),jsxs(p,{children:[jsx(q$2,{children:"No plugins found."}),jsx(r$2,{children:n.map(d=>jsxs(t$2,{value:d.id,keywords:[d.name],onSelect:()=>{o(d),l(false);},children:[jsx("img",{src:d.logoUrl,alt:"",className:"fk:size-5 fk:shrink-0 fk:rounded fk:corner-squircle"}),jsx("span",{className:"fk:truncate",children:d.name}),d.connections.some(k=>k.status==="connected")?null:jsx("span",{className:"fk:ml-auto fk:text-xs fk:text-muted-foreground",children:"Not connected"})]},d.id))})]})]})})]})}function Po({projectId:t,value:n,disabled:o,onChange:i}){let{data:l,error:g}=De(`/api/flexkit/${t}/plugins`,f),d=(l?.plugins??[]).filter(m=>m.capabilities.agentTools),k=new Map(d.map(m=>[m.id,m])),r=d.filter(m=>m.enabled&&!n.some(u=>u.pluginId===m.id));return jsxs(Fragment,{children:[n.map(m=>{let u=k.get(m.pluginId);return u?jsx($a,{disabled:o,canManage:l?.canManage??false,plugin:u,projectId:t,usage:m,onChange:T=>i(n.map(I=>I.pluginId===u.id?T:I)),onRemove:()=>i(n.filter(T=>T.pluginId!==u.id))},m.pluginId):null}),g?jsx("p",{className:"fk:mx-3 fk:text-xs fk:text-warning",role:"alert",children:"Unable to load plugins. Your existing selections are preserved."}):null,jsx(ja,{disabled:o||!l,plugins:r,onAdd:m=>i([...n,La(m)])})]})}var jt=["slack","teams"],Lo=["create","update","delete"],qo="0 * * * *",Wa="0 9 * * *",Ga="0 9 * * 1",Za="0 9 1 * *",Ya=[{label:"Monday",value:1},{label:"Tuesday",value:2},{label:"Wednesday",value:3},{label:"Thursday",value:4},{label:"Friday",value:5},{label:"Saturday",value:6},{label:"Sunday",value:0}],Qa=Array.from({length:24},(t,n)=>({label:`${n.toString().padStart(2,"0")}:00`,value:n}));function es(t){return !t.instructions&&!t.model&&!t.name&&!t.plugins&&!t.space&&Object.keys(t.toolErrors).length===0&&Object.keys(t.triggerErrors).length===0}function zo(t){return t.some(n=>n.enabled&&n.connectionMode==="personal")}function Xe({id:t,message:n}){return n?jsxs("p",{className:"fk:flex fk:items-start fk:text-sm fk:text-warning fk:gap-1",id:t,role:"alert",children:[jsx(TriangleAlertIcon,{className:"fk:size-4 fk:shrink-0 fk:mt-0.5"}),n]}):null}function Vt(){return crypto.randomUUID()}function ts(t){return (t?.triggers??[]).map(n=>({...n,key:n.id??Vt()}))}function ns(t){return t.connected&&t.connectionLabel?`While your local runtime (${t.connectionLabel}) is connected, manually running this automation uses its custom tools so you can test them.`:t.connected?"While `flexkit dev` is connected, manually running this automation uses the custom tools from your local runtime so you can test them.":t.origin?`Using ${t.origin}`:t.tools.length===0?"":"Registered in this project"}function os(){return Intl.DateTimeFormat().resolvedOptions().timeZone||"UTC"}function as(){let t=crypto.getRandomValues(new Uint8Array(24));return Array.from(t,n=>n.toString(16).padStart(2,"0")).join("")}function ss(t){if(t===qo)return {kind:"hourly"};let n=/^0 (\d{1,2}) \* \* \*$/.exec(t);if(n)return {hour:Number(n[1]),kind:"daily"};let o=/^0 (\d{1,2}) \* \* ([0-6])$/.exec(t);return o?{day:Number(o[2]),hour:Number(o[1]),kind:"weekly"}:{kind:"custom"}}function Xo(t,n,o){try{let i=CronExpressionParser.parse(t,{tz:n});return Array.from({length:o},()=>i.next().toDate())}catch{return []}}function Oo(t,n){return new Intl.DateTimeFormat("en-US",{day:"numeric",hour:"numeric",minute:"2-digit",month:"short",timeZone:n,weekday:"short"}).format(t)}function Jo(t,n){let o=t.trim();if(!o)return "Cron expression is required";let i=o.split(/\s+/).length;if(i<5||i>6)return `Expected 5 fields (min hour day month weekday), got ${i.toString()}`;try{return CronExpressionParser.parse(o,{tz:n}),null}catch{return "Invalid cron expression"}}function is(t,n,o){let i=t.filter(g=>!g.deprecated);if(n!=="edit"||!o)return i;let l=c$3(t,o);return l?.deprecated?[l,...i.filter(g=>b$6(g)!==o)]:l?i:[{deprecated:true,effort:null,efforts:[],id:o,kind:"model",name:o},...i]}function Nn(t){return `${t.teamId??""}:${t.id}`}function ls(t,n){let o={};for(let i of [...t,...n])o[Nn(i)]=i;return Object.values(o)}function Fo(t,n){return {...t,availableChannels:t.channels,channelsLoaded:!t.connected,enabled:t.connected&&n==="edit"&&t.enabled,loadingChannels:false}}function rs(t,n){return {slack:Fo(t.providers.slack,n),teams:Fo(t.providers.teams,n)}}function cs({channels:t,disabled:n,loading:o,onChange:i,onRefresh:l,provider:g,value:d}){let[k,r]=useState(false),[m,u]=useState(""),T=useRef(null),I=new Set(d.map(h=>h.id)),C=g==="slack"?"Slack":"Teams",$=t.filter(h=>h.name.toLowerCase().includes(m.toLowerCase()));useEffect(()=>{if(!k)return;function h(F){let{target:w}=F;!(w instanceof Node)||T.current?.contains(w)||r(false);}function R(F){F.key==="Escape"&&r(false);}return document.addEventListener("pointerdown",h),document.addEventListener("keydown",R),()=>{document.removeEventListener("pointerdown",h),document.removeEventListener("keydown",R);}},[k]);function A(h){if(I.has(h.id)){i(d.filter(R=>R.id!==h.id));return}i([...d,h]);}function y(h){i(d.filter(R=>R.id!==h));}return jsxs("div",{className:"fk:relative",ref:T,children:[jsxs(b$2,{"aria-expanded":k,className:"fk:h-auto fk:min-h-8 fk:w-full fk:max-w-100 fk:justify-between fk:bg-muted/60 fk:px-3 fk:py-1 hover:fk:border-secondary fk:dark:bg-muted/30",disabled:n,role:"combobox",type:"button",variant:"outline",onClick:()=>r(h=>!h),children:[jsx("div",{className:"fk:flex fk:flex-1 fk:flex-wrap fk:gap-1",children:d.length===0?jsx("span",{className:"fk:text-muted-foreground",children:o?`Loading ${C} channels...`:`Select ${C} channels`}):d.map(h=>jsxs(b$1,{className:"fk:rounded-sm fk:bg-accent fk:text-xs fk:corner-squircle",variant:"secondary",onClick:R=>{R.stopPropagation(),y(h.id);},children:[h.name,jsx(XIcon,{className:"fk:ml-1 fk:size-3 fk:cursor-pointer"})]},Nn(h)))}),jsx(ChevronsUpDownIcon,{className:"fk:size-4 fk:shrink-0 fk:opacity-50"})]}),k?jsxs("div",{className:"fk:absolute fk:z-50 fk:mt-1 fk:w-full fk:max-w-100 fk:rounded-md fk:border fk:bg-popover fk:p-0 fk:text-popover-foreground fk:shadow-md fk:corner-squircle",children:[jsx("div",{className:"fk:border-b fk:p-2",children:jsx(s$1,{className:"fk:h-8",placeholder:`Search ${C} channels...`,value:m,onChange:h=>u(h.target.value)})}),jsx("div",{className:"fk:max-h-56 fk:overflow-auto fk:p-1",children:$.length>0?$.map(h=>jsxs(b$2,{className:"fk:h-auto fk:w-full fk:justify-start fk:rounded-sm fk:px-2 fk:py-1.5 fk:font-normal fk:corner-squircle",type:"button",variant:"ghost",onClick:()=>A(h),children:[jsx(CheckIcon,{className:`fk:mr-2 fk:size-4 ${I.has(h.id)?"fk:opacity-100":"fk:opacity-0"}`}),h.name]},Nn(h))):jsx("div",{className:"fk:px-2 fk:py-6 fk:text-center fk:text-sm fk:text-muted-foreground",children:o?"Loading channels...":"No channels found."})}),jsx("div",{className:"fk:border-t fk:border-border fk:p-2",children:jsx(b$2,{className:"fk:h-8 fk:w-full fk:justify-start fk:text-xs",disabled:o,type:"button",variant:"ghost",onClick:l,children:o?jsxs(Fragment,{children:[jsx(LoaderCircleIcon,{className:"fk:mr-2 fk:size-3 fk:animate-spin"}),"Refreshing channels..."]}):jsxs(Fragment,{children:[jsx(RefreshCwIcon,{className:"fk:mr-2 fk:size-3"}),"Refresh channels"]})})})]}):null]})}function _t({cron:t,timezone:n}){let[o]=Xo(t,n,1);return o?jsxs("span",{className:"fk:text-sm fk:text-muted-foreground",children:["Next run ",Oo(o,n)]}):null}function Bo({onChange:t,value:n}){return jsxs(a$2,{value:n.toString(),onValueChange:o=>t(Number(o)),children:[jsx(d$3,{"aria-label":"Hour",className:"fk:h-7 fk:w-fit fk:gap-1 fk:border-transparent fk:bg-background/90 fk:px-2 fk:py-0 fk:text-sm fk:shadow-sm hover:fk:border-border",size:"sm",children:jsx(c$4,{})}),jsx(e$6,{children:Qa.map(o=>jsx(g$4,{value:o.value.toString(),children:o.label},o.value))})]})}function fs({onChange:t,value:n}){return jsxs(a$2,{value:n.toString(),onValueChange:o=>t(Number(o)),children:[jsx(d$3,{"aria-label":"Day of week",className:"fk:h-7 fk:w-fit fk:gap-1 fk:border-transparent fk:bg-background/90 fk:px-2 fk:py-0 fk:text-sm fk:shadow-sm hover:fk:border-border",size:"sm",children:jsx(c$4,{})}),jsx(e$6,{children:Ya.map(o=>jsx(g$4,{value:o.value.toString(),children:o.label},o.value))})]})}function us({onChange:t,timezone:n,value:o}){let[i,l]=useState(false),g=useRef(null),d=Jo(o,n),k=d?[]:Xo(o,n,3);return useEffect(()=>{if(!i)return;function r(u){let{target:T}=u;!(T instanceof Node)||g.current?.contains(T)||l(false);}function m(u){u.key==="Escape"&&l(false);}return document.addEventListener("pointerdown",r),document.addEventListener("keydown",m),()=>{document.removeEventListener("pointerdown",r),document.removeEventListener("keydown",m);}},[i]),jsxs("div",{className:"fk:relative",ref:g,children:[jsxs(b$2,{className:"fk:h-auto fk:gap-1.5 fk:bg-background/90 fk:px-2 fk:py-1 fk:font-mono fk:font-normal fk:shadow-sm hover:fk:bg-accent",type:"button",variant:"ghost",onClick:()=>l(r=>!r),children:[o||"Set cron",jsx(ChevronDownIcon,{className:"fk:size-3.5 fk:opacity-50"})]}),i?jsxs("div",{className:"fk:absolute fk:z-50 fk:mt-1 fk:w-72 fk:rounded-md fk:border fk:bg-popover fk:p-3 fk:text-popover-foreground fk:shadow-md fk:corner-squircle",children:[jsxs("div",{className:"fk:mb-2 fk:text-xs fk:text-muted-foreground",children:["Cron expression (",n,")"]}),jsx(s$1,{className:`fk:h-8 fk:font-mono ${d?"fk:border-destructive focus-visible:fk:ring-destructive":""}`,value:o,onChange:r=>t(r.target.value)}),d?jsx("p",{className:"fk:mt-2 fk:text-xs fk:text-destructive",children:d}):jsxs("div",{className:"fk:mt-2 fk:space-y-0.5 fk:text-xs fk:text-muted-foreground",children:[jsx("p",{className:"fk:mb-1",children:"5 fields: min hour day month weekday"}),k.map(r=>jsx("p",{children:Oo(r,n)},r.toISOString()))]})]}):null]})}function ds({onChange:t,trigger:n}){let o=ss(n.cron);return o.kind==="hourly"?jsxs("div",{className:"fk:flex fk:flex-1 fk:flex-wrap fk:items-center fk:gap-2 fk:text-sm",children:[jsx("span",{children:"Every hour"}),jsx(_t,{cron:n.cron,timezone:n.timezone})]}):o.kind==="daily"?jsxs("div",{className:"fk:flex fk:flex-1 fk:flex-wrap fk:items-center fk:gap-2 fk:text-sm",children:[jsx("span",{children:"Every day at"}),jsx(Bo,{value:o.hour,onChange:i=>t({...n,cron:`0 ${i.toString()} * * *`})}),jsx("span",{className:"fk:text-muted-foreground",children:n.timezone}),jsx(_t,{cron:n.cron,timezone:n.timezone})]}):o.kind==="weekly"?jsxs("div",{className:"fk:flex fk:flex-1 fk:flex-wrap fk:items-center fk:gap-2 fk:text-sm",children:[jsx("span",{children:"Every week on"}),jsx(fs,{value:o.day,onChange:i=>t({...n,cron:`0 ${o.hour.toString()} * * ${i.toString()}`})}),jsx("span",{children:"at"}),jsx(Bo,{value:o.hour,onChange:i=>t({...n,cron:`0 ${i.toString()} * * ${o.day.toString()}`})}),jsx("span",{className:"fk:text-muted-foreground",children:n.timezone}),jsx(_t,{cron:n.cron,timezone:n.timezone})]}):jsxs("div",{className:"fk:flex fk:flex-1 fk:flex-wrap fk:items-center fk:gap-2 fk:text-sm",children:[jsx("span",{children:"Custom schedule"}),jsx(us,{timezone:n.timezone,value:n.cron,onChange:i=>t({...n,cron:i})}),jsx("span",{className:"fk:text-muted-foreground",children:n.timezone}),jsx(_t,{cron:n.cron,timezone:n.timezone})]})}function ms({onChange:t,projectId:n,trigger:o}){let[i,l]=useState(false),[g,d]=useState(false),k=o.url??c$5(n,o.token);function r(m,u){navigator.clipboard.writeText(m).then(()=>{u(true),window.setTimeout(()=>u(false),1500);});}return jsxs("div",{className:"fk:flex fk:flex-1 fk:flex-wrap fk:items-center fk:gap-2 fk:text-sm",children:[jsx("span",{children:"Webhook triggered"}),jsxs(b$3,{children:[jsx(c,{asChild:true,children:jsxs(b$2,{className:"fk:h-auto fk:min-w-0 fk:max-w-60 fk:gap-1.5 fk:bg-background/90 fk:px-2 fk:py-1 fk:text-xs fk:font-normal fk:shadow-sm hover:fk:bg-accent",type:"button",variant:"ghost",onClick:()=>r(k,l),children:[jsx("span",{className:"fk:truncate",children:k}),i?jsx(CheckIcon,{className:"fk:size-3.5 fk:shrink-0"}):jsx(CopyIcon,{className:"fk:size-3.5 fk:shrink-0 fk:opacity-60"})]})}),jsx(e$1,{className:"fk:max-w-96 fk:break-all",children:k})]}),o.secret?jsxs(b$2,{className:"fk:h-7 fk:px-2.5 fk:text-xs",size:"sm",type:"button",variant:"outline",onClick:()=>r(`Bearer ${o.secret??""}`,d),children:[g?jsx(CheckIcon,{className:"fk:size-3.5"}):jsx(KeyRoundIcon,{className:"fk:size-3.5"}),"Copy auth header"]}):jsxs(b$2,{className:"fk:h-7 fk:px-2.5 fk:text-xs",size:"sm",type:"button",variant:"outline",onClick:()=>t({...o,secret:as()}),children:[jsx(KeyRoundIcon,{className:"fk:size-3.5"}),"Generate auth header"]})]})}function ks({entities:t,onChange:n,trigger:o}){function i(d){let k=o.events.includes(d)?o.events.filter(r=>r!==d):[...o.events,d];n({...o,events:Lo.filter(r=>k.includes(r))});}function l(d){let k=o.entities.includes(d)?o.entities.filter(r=>r!==d):[...o.entities,d];n({...o,entities:k});}let g=o.entities.length>0?o.entities.join(", "):"All entities";return jsxs("div",{className:"fk:flex fk:flex-1 fk:flex-wrap fk:items-center fk:gap-2 fk:text-sm",children:[jsx("span",{children:"On"}),jsx("div",{className:"fk:flex fk:items-center fk:gap-1",children:Lo.map(d=>jsxs(b$2,{className:"fk:h-7 fk:px-2.5 fk:text-xs fk:capitalize",size:"sm",type:"button",variant:o.events.includes(d)?"secondary":"ghost",onClick:()=>i(d),children:[o.events.includes(d)?jsx(CheckIcon,{className:"fk:size-3"}):null,d]},d))}),jsx("span",{children:"of"}),jsxs(e,{children:[jsx(g$1,{asChild:true,children:jsxs(b$2,{className:"fk:h-7 fk:max-w-60 fk:px-2.5 fk:text-xs",size:"sm",type:"button",variant:"outline",children:[jsx("span",{className:"fk:truncate",children:g}),jsx(ChevronDownIcon,{className:"fk:size-3.5 fk:opacity-50"})]})}),jsx(h,{align:"start",className:"fk:max-h-64 fk:w-56 fk:overflow-auto",children:t.length===0?jsx(j,{disabled:true,children:"No entities found in the project schema"}):t.map(d=>jsx(k,{checked:o.entities.includes(d),onCheckedChange:()=>l(d),onSelect:k=>k.preventDefault(),children:d},d))})]})]})}function ps({entities:t,errors:n,onChange:o,projectId:i,triggers:l}){let g=l.some(u=>u.type==="webhook");function d(u){o([...l,u]);}function k(u){d({cron:u,key:Vt(),timezone:os(),type:"schedule"});}function r(u){o(l.map(T=>T.key===u.key?u:T));}function m(u){o(l.filter(T=>T.key!==u));}return jsxs("div",{className:"fk:rounded-lg fk:border fk:bg-muted/60 fk:dark:bg-muted/30 fk:corner-squircle",children:[l.map(u=>jsxs(Fragment$1,{children:[jsxs("div",{className:"fk:group fk:rounded-md fk:m-1.5 fk:p-1.5 fk:hover:bg-muted fk:corner-squircle",children:[jsxs("div",{className:"fk:flex fk:items-center fk:gap-3",children:[u.type==="schedule"?jsx(ClockIcon,{className:"fk:size-4 fk:shrink-0 fk:text-muted-foreground"}):null,u.type==="webhook"?jsx(WebhookIcon,{className:"fk:size-4 fk:shrink-0 fk:text-muted-foreground"}):null,u.type==="entity"?jsx(DatabaseZapIcon,{className:"fk:size-4 fk:shrink-0 fk:text-muted-foreground"}):null,u.type==="schedule"?jsx(ds,{trigger:u,onChange:r}):null,u.type==="webhook"?jsx(ms,{projectId:i,trigger:u,onChange:r}):null,u.type==="entity"?jsx(ks,{entities:t,trigger:u,onChange:r}):null,jsx(b$2,{"aria-label":"Remove trigger",className:"fk:opacity-0 fk:group-hover:opacity-100",size:"icon",type:"button",variant:"ghost",onClick:()=>m(u.key),children:jsx(Trash2Icon,{className:"fk:size-4 fk:text-muted-foreground"})})]}),n[u.key]?jsx("div",{className:"fk:mt-1 fk:pl-7",children:jsx(Xe,{message:n[u.key]})}):null]},u.key),jsx(v,{className:"fk:h-4"})]},u.key)),jsxs(e,{children:[jsx(g$1,{asChild:true,children:jsxs(b$2,{className:`fk:h-auto fk:w-full fk:justify-start fk:gap-3 fk:px-3 fk:py-3 fk:text-muted-foreground hover:fk:bg-muted hover:fk:text-foreground ${l.length===0?"fk:rounded-lg fk:corner-squircle":"fk:rounded-none fk:rounded-b-lg fk:corner-squircle"}`,type:"button",variant:"ghost",children:[jsx(PlusIcon,{className:"fk:size-4"}),"Add Trigger"]})}),jsxs(h,{align:"start",className:"fk:w-56",children:[jsxs(q$1,{children:[jsxs(r$1,{children:[jsx(ClockIcon,{className:"fk:mr-2 fk:size-4 fk:text-muted-foreground"}),"Scheduled"]}),jsxs(s$2,{children:[jsx(j,{onClick:()=>k(qo),children:"Hourly"}),jsx(j,{onClick:()=>k(Wa),children:"Daily"}),jsx(j,{onClick:()=>k(Ga),children:"Weekly"}),jsx(j,{onClick:()=>k(Za),children:"Custom (cron)"})]})]}),jsxs(j,{disabled:g,onClick:()=>d({key:Vt(),secret:null,token:crypto.randomUUID(),type:"webhook"}),children:[jsx(WebhookIcon,{className:"fk:mr-2 fk:size-4 fk:text-muted-foreground"}),"Webhook Triggered"]}),jsxs(j,{onClick:()=>d({entities:[],events:["create"],key:Vt(),type:"entity"}),children:[jsx(DatabaseZapIcon,{className:"fk:mr-2 fk:size-4 fk:text-muted-foreground"}),"Entity Events"]})]})]})]})}function gs(){return jsxs("svg",{"aria-label":"Slack",className:"fk:mt-1 fk:size-3.5 fk:text-muted-foreground",fill:"currentColor",role:"img",viewBox:"0 0 127 127",xmlns:"http://www.w3.org/2000/svg",children:[jsx("path",{d:"M27.2 80c0 7.3-5.9 13.2-13.2 13.2C6.7 93.2.8 87.3.8 80c0-7.3 5.9-13.2 13.2-13.2h13.2V80zm6.6 0c0-7.3 5.9-13.2 13.2-13.2 7.3 0 13.2 5.9 13.2 13.2v33c0 7.3-5.9 13.2-13.2 13.2-7.3 0-13.2-5.9-13.2-13.2V80z"}),jsx("path",{d:"M47 27c-7.3 0-13.2-5.9-13.2-13.2C33.8 6.5 39.7.6 47 .6c7.3 0 13.2 5.9 13.2 13.2V27H47zm0 6.7c7.3 0 13.2 5.9 13.2 13.2 0 7.3-5.9 13.2-13.2 13.2H13.9C6.6 60.1.7 54.2.7 46.9c0-7.3 5.9-13.2 13.2-13.2H47z"}),jsx("path",{d:"M99.9 46.9c0-7.3 5.9-13.2 13.2-13.2 7.3 0 13.2 5.9 13.2 13.2 0 7.3-5.9 13.2-13.2 13.2H99.9V46.9zm-6.6 0c0 7.3-5.9 13.2-13.2 13.2-7.3 0-13.2-5.9-13.2-13.2V13.8C66.9 6.5 72.8.6 80.1.6c7.3 0 13.2 5.9 13.2 13.2v33.1z"}),jsx("path",{d:"M80.1 99.8c7.3 0 13.2 5.9 13.2 13.2 0 7.3-5.9 13.2-13.2 13.2-7.3 0-13.2-5.9-13.2-13.2V99.8h13.2zm0-6.6c-7.3 0-13.2-5.9-13.2-13.2 0-7.3 5.9-13.2 13.2-13.2h33.1c7.3 0 13.2 5.9 13.2 13.2 0 7.3-5.9 13.2-13.2 13.2H80.1z"})]})}function vs(){return jsxs("svg",{"aria-label":"Microsoft Teams",className:"fk:mt-1 fk:size-3.5 fk:text-muted-foreground",fill:"currentColor",role:"img",viewBox:"0 0 24 24",xmlns:"http://www.w3.org/2000/svg",children:[jsx("path",{clipRule:"evenodd",d:"M15.5 5A3 3 0 0 1 14 7.599V7.5a2 2 0 0 0-2-2H9.541A3 3 0 1 1 15.5 5Zm6.25 1a2 2 0 1 1-4 0 2 2 0 0 1 4 0Zm-3.294 11.732A3.25 3.25 0 0 0 23 14.75v-4.361a.889.889 0 0 0-.889-.889h-3.879c.17.294.268.636.268 1V17c0 .248-.015.492-.044.732ZM8.169 19.5A5 5 0 0 0 17.5 17v-6.5a1 1 0 0 0-1-1H14v8a2 2 0 0 1-2 2H8.169Z",fillRule:"evenodd"}),jsx("path",{clipRule:"evenodd",d:"M1 17.5v-10a1 1 0 0 1 1-1h10a1 1 0 0 1 1 1v10a1 1 0 0 1-1 1H2a1 1 0 0 1-1-1Zm6.75-6.75H9.5v-1.5h-5v1.5h1.75v4.75h1.5v-4.75Z",fillRule:"evenodd"})]})}function Ht(t,n,o){return t.visibility==="space"?n==="space"&&o!==null&&t.spaceId===o:t.visibility==="personal"?n==="personal":true}function hs(t,n,o){return t.visibility==="space"&&!Ht(t,n,o)}function bs(t,n){let o=t.spaceId?n[t.spaceId]:void 0;return o?`Only available on ${o} automations`:"Only available on space automations"}async function ys(t,n){try{return (await f(g(t).skill(n))).skill}catch(o){if(o instanceof e$7&&o.status===404)return null;throw o}}function Tn({api:t,automation:n,mode:o,onSaved:i,projectId:l}){let[g$1,d]=useState((n?.toolConfigs??[]).filter(a=>!["slack","teams"].includes(a.pluginId))),[k,r]=useState(n?.name??""),[m,u]=useState(n?.instructions??""),[T,I]=useState(n?.enabled??false),[C,$]=useState(null),[A,y]=useState(null),[h,R]=useState(n?.mutationPolicy??"require_approval"),[F,w]=useState(n?.toolAllowRules),[S,E]=useState(n?.visibility??"project"),[M,_]=useState(n?.spaceId??null),[x,X]=useState(n?.skillIds??[]),[W,me]=useState(n?.customToolNames??[]),[G,he]=useState(()=>ts(n)),[it,Fe]=useState(false),[Ie,Be]=useState(""),[Le,be]=useState({instructions:false,name:false}),[ie,Pe]=useState(null),[Je,Ke]=useState(null),{mutate:D}=useSWRConfig(),[b$3,j]=useState(()=>({slack:n?.toolConfigs?.find(a=>a.pluginId==="slack")?.connectionId??null,teams:n?.toolConfigs?.find(a=>a.pluginId==="teams")?.connectionId??null})),ue=useRef({}),yt=useRef(null),{data:Me,error:An}=De(`/api/flexkit/${l}/plugins`,f),In=!!(Me||An),sa=g(l).tools(n?.id),{data:$e,error:ia}=De(sa,f),{data:la}=De(g(l).entities,f),{data:Wt}=De(g(l).spaces,f),{data:Z$1}=De(g(l).skills({limit:100}),f),[,ra]=h$2(),le=b(),ca=ra.user?.spaces??[],Pn=(Wt?.spaces??[]).filter(a=>ca.includes(a.code)),xt=$e?.tools.models,Mn=useMemo(()=>{let a=n?.modelId??"";return a?f$4(a,xt??[])??{effort:null,modelKey:a}:null},[n?.modelId,xt]),Gt=C??Mn?.modelKey??"",lt=useMemo(()=>is(xt??[],o,Gt),[o,xt,Gt]),Nt=Gt||(lt[0]?b$6(lt[0]):""),Rn=c$3(lt,Nt),Zt=d$2(Rn,A??(C===null?Mn?.effort??null:null)),En=e$4(Rn),Yt=Nt?g$3({effort:Zt,modelKey:Nt},lt):"",Dn=useMemo(()=>new Set((Z$1?.skills??[]).map(a=>a.id)),[Z$1?.skills]),We=useMemo(()=>Z$1?x.filter(a=>!Dn.has(a)).sort():[],[Dn,x,Z$1]),fa=We.length>0?[l,"attached-skills",...We]:null,{data:Tt}=De(fa,()=>Promise.all(We.map(a=>ys(l,a)))),Ge=useMemo(()=>{let a={};for(let p of Z$1?.skills??[])a[p.id]=p;for(let p of Tt??[])p&&(a[p.id]=p);return a},[Tt,Z$1?.skills]),Qt=useMemo(()=>{let a=(Z$1?.skills??[]).filter(N=>Ht(N,S,M)),p=new Set(a.map(N=>N.id));return [...x.map(N=>Ge[N]).filter(N=>!N||p.has(N.id)?false:Ht(N,S,M)),...a]},[x,Ge,Z$1?.skills,M,S]),ua=useMemo(()=>{let a={};for(let p of Wt?.spaces??[])a[p.id]=p.label;return a},[Wt?.spaces]),en=useMemo(()=>(Z$1?.skills??[]).filter(a=>hs(a,S,M)),[Z$1?.skills,M,S]),ze=$e?.tools.customTools,tn=useMemo(()=>{let a={};for(let p of ze?.tools??[])a[p.name]=p;return a},[ze?.tools]),nn=useMemo(()=>{let a=ze?.tools??[],p=new Set(a.map(N=>N.name));return [...W.filter(N=>!p.has(N)).map(N=>tn[N]??{description:"",name:N}),...a]},[W,tn,ze?.tools]),Ln=ze?ns(ze):"";useEffect(()=>{if(!Z$1)return;let a=We.length>0&&Tt===void 0,p=new Set(a?[]:We.filter(v=>!Ge[v]));X(v=>{let N=v.filter(B=>{if(p.has(B))return false;let Re=Ge[B];return Re?Ht(Re,S,M):true});return N.length===v.length?v:N});},[Tt,Ge,Z$1,M,We,S]);let Ze=zo(g$1),te=useMemo(()=>{let a={};for(let v of G){if(v.type==="schedule"){let N=Jo(v.cron,v.timezone);N&&(a[v.key]=N);}v.type==="entity"&&v.events.length===0&&(a[v.key]="Select at least one event (create, update or delete)");}let p={};for(let v of jt){let N=ie?.[v];N?.enabled&&N.channels.length===0&&(p[v]=`Select at least one ${v==="slack"?"Slack":"Teams"} channel or remove the tool`);}return {instructions:m.trim()?"":"Instructions are required",model:Yt?"":"Select a model",name:k.trim()?"":"Name is required",plugins:Ze&&S!=="personal"?"Personal plugin connections can only be used by a personal automation.":"",space:S==="space"&&!M?"Select a space":"",toolErrors:p,triggerErrors:a}},[Yt,m,k,Ze,M,ie,G,S]),on=es(te),Ct=Le.name&&!!te.name,rt=Le.instructions&&!!te.instructions;useEffect(()=>{let a=`${n?.id??""}:${o}`;!$e?.tools||yt.current===a||(yt.current=a,Pe(rs($e.tools,o)));},[n?.id,o,$e?.tools]);let wt=useMemo(()=>({slack:Me?.plugins.find(a=>a.id==="slack")??null,teams:Me?.plugins.find(a=>a.id==="teams")??null}),[Me]),an=useMemo(()=>{let a=p=>{let v=wt[p];return v?hn(v,{connectionMode:"project",connectionId:b$3[p]})?.id??null:null};return {slack:a("slack"),teams:a("teams")}},[b$3,wt]),sn=useCallback(async(a,p)=>{ue.current[a]=p,Pe(v=>v&&{...v,[a]:{...v[a],channelsLoadError:void 0,loadingChannels:true}});try{let v=await t.listChannels(a,p);if(ue.current[a]!==p)return;let N=v.success?void 0:v.errorMessage??`Failed to load ${a==="slack"?"Slack":"Teams"} channels.`;Pe(B=>B&&{...B,[a]:{...B[a],availableChannels:ls(B[a].channels,v.channels),channelsLoadError:N,channelsLoaded:!0,loadingChannels:!1}});}catch(v){if(ue.current[a]!==p)return;let N=v instanceof Error?v.message:"Failed to load integration channels.";Pe(B=>B&&{...B,[a]:{...B[a],channelsLoadError:N,channelsLoaded:true,loadingChannels:false}});}},[t]);useEffect(()=>{if(!(!ie||!le||!In))for(let a of jt){let p=ie[a];p.connected&&!p.channelsLoaded&&!p.loadingChannels&&sn(a,an[a]);}},[le,sn,In,an,ie]);async function da(a){let p=wt[a];if(p){Ke(a);try{await a$3(t,p.id,"project");let N=(await D(`/api/flexkit/${l}/plugins`))?.plugins.find(B=>B.id===p.id)?.connections.find(B=>B.scope==="project"&&B.isPrimary&&B.status==="connected");j(B=>({...B,[a]:null})),zn(a,{connected:!0,enabled:!0,workspaceName:N?.displayName??null});}catch(v){oa$1.error(v instanceof Error?v.message:`Unable to connect ${p.name}.`);}finally{Ke(null);}}}function St(a,p){Pe(v=>v&&{...v,[a]:{...v[a],...p}});}function ma$1(a,p){b$3[a]!==p&&(j(v=>({...v,[a]:p})),zn(a));}function zn(a,p={}){ue.current[a]=void 0,St(a,{...p,availableChannels:[],channels:[],channelsLoaded:false,channelsLoadError:void 0,loadingChannels:false});}function ka$1(a){St(a,{channels:[],enabled:false});}function Fn(a,p){X(v=>p?v.includes(a)?v:[...v,a]:v.filter(N=>N!==a));}function Bn(a,p){me(v=>p?v.includes(a)?v:[...v,a]:v.filter(N=>N!==a));}async function pa(a){if(a.preventDefault(),!le)return;if(!on){be({instructions:true,name:true});return}Fe(true),Be("");let p=jt.map(N=>{let B=ie?.[N]??$e?.tools.providers[N];return {channels:B?.channels??[],enabled:B?.enabled??false,pluginId:N,connectionMode:"project",connectionId:b$3[N],selectedTools:[],deliveryEnabled:B?.enabled??false}}),v={customToolNames:W,enabled:T,instructions:m,modelId:Yt,mutationPolicy:h,name:k,skillIds:x,...F!==void 0?{toolAllowRules:F}:{},spaceId:S==="space"?M:null,toolConfigs:[...p,...g$1],triggers:G.map(({key:N,...B})=>B),visibility:S};try{let N=o==="create"||!n?await t.createAutomation(v):await t.updateAutomation(n.id,v);if(!N.success){Be(Array.isArray(N.errorMessage)?N.errorMessage.join(", "):N.errorMessage);return}oa$1.success(o==="create"||!n?"Automation created.":"Automation saved."),i(N.automation);}catch(N){Be(N instanceof Error?N.message:"Failed to save automation.");}finally{Fe(false);}}return jsxs("form",{className:"fk:max-w-4xl fk:space-y-8 fk:px-1 fk:mx-auto",onSubmit:a=>{pa(a);},children:[Ie?jsx("div",{className:"fk:rounded-md fk:border fk:border-destructive/30 fk:bg-destructive/5 fk:p-3 fk:text-sm fk:text-destructive fk:corner-squircle",children:Ie}):null,jsxs("div",{className:"fk:space-y-3",children:[jsx(e$5,{className:"fk:mb-1",children:"Status"}),jsx("p",{className:"fk:text-xs fk:text-muted-foreground fk:mb-1",children:"Disabling an automation stops its schedules and ignores webhook calls and entity events"}),jsxs("div",{className:"fk:flex fk:h-10 fk:items-center fk:gap-2",children:[jsx(Z,{checked:T,id:"automation-enabled",onCheckedChange:I}),jsx(e$5,{className:"fk:font-normal",htmlFor:"automation-enabled",children:T?"Active":"Inactive"})]})]}),jsxs("div",{className:"fk:space-y-3",children:[jsx(e$5,{className:"fk:mb-1",htmlFor:"automation-name",children:"Name"}),jsx("p",{className:"fk:text-xs fk:text-muted-foreground fk:mb-2",children:"Identifying label for this automation"}),jsx(s$1,{"aria-describedby":Ct?"automation-name-error":void 0,"aria-invalid":Ct,className:Ct?"fk:border-destructive focus-visible:fk:ring-destructive":"",id:"automation-name",value:k,onBlur:()=>be(a=>({...a,name:true})),onChange:a=>r(a.target.value)}),Ct?jsx(Xe,{id:"automation-name-error",message:te.name}):null]}),jsxs("div",{className:"fk:space-y-3",children:[jsx(e$5,{className:"fk:mb-1",htmlFor:"automation-visibility",children:"Visibility"}),jsx("p",{className:"fk:text-xs fk:text-muted-foreground fk:mb-2",children:"Who can see and manage this automation. Space automations are only visible to members of the selected space; personal automations are private to you."}),jsxs("div",{className:"fk:flex fk:items-center fk:gap-2",children:[jsxs(a$2,{value:S,onValueChange:a=>{Ze&&a!=="personal"||(E(a==="space"||a==="personal"?a:"project"),a!=="space"&&_(null));},children:[jsx(d$3,{"aria-label":"Visibility",className:"fk:w-fit",id:"automation-visibility",children:jsx(c$4,{})}),jsxs(e$6,{align:"start",children:[jsx(g$4,{disabled:Ze,value:"project",children:"Project"}),jsx(g$4,{disabled:Ze||Pn.length===0,value:"space",children:"Space"}),jsx(g$4,{value:"personal",children:"Personal"})]})]}),S==="space"?jsxs(a$2,{value:M??"",onValueChange:a=>{_(a||null);},children:[jsx(d$3,{"aria-label":"Space",className:"fk:w-fit",children:jsx(c$4,{placeholder:"Select a space"})}),jsx(e$6,{align:"start",children:Pn.map(a=>jsx(g$4,{value:a.id,children:a.label},a.id))})]}):null]}),Ze?jsx("p",{className:"fk:text-xs fk:text-muted-foreground",children:"This automation uses a personal plugin connection, so project and space visibility are unavailable."}):null,te.plugins?jsx(Xe,{message:te.plugins}):null,S==="space"&&te.space?jsx(Xe,{message:te.space}):null]}),jsxs("div",{className:"fk:space-y-3",children:[jsx(e$5,{className:"fk:mb-1",children:"Triggers"}),jsx("p",{className:"fk:text-xs fk:text-muted-foreground fk:mb-2",children:"When this automation should run. Schedules run in your timezone; webhooks run when their URL is called."}),jsx(ps,{entities:la?.entities??[],errors:te.triggerErrors,projectId:l,triggers:G,onChange:he})]}),jsxs("div",{className:"fk:space-y-3",children:[jsx(e$5,{className:"fk:mb-1",htmlFor:"automation-instructions",children:"Agent instructions"}),jsx("p",{className:"fk:text-xs fk:text-muted-foreground fk:mb-2",children:"Natural-language instructions the agent follows on every run. Be specific about entities, conditions, and the expected outcome."}),jsxs("div",{children:[jsx("div",{className:`fk:rounded-t-md fk:border-x fk:border-t fk:bg-muted/60 fk:ring-offset-background focus-within:fk:ring-2 focus-within:fk:ring-ring focus-within:fk:ring-offset-2 fk:dark:bg-muted/30 ${rt?"fk:border-destructive":"fk:border-input"} fk:corner-squircle`,children:jsx(ka,{"aria-describedby":rt?"automation-instructions-error":void 0,"aria-invalid":rt,className:"fk:flex fk:min-h-[160px] fk:max-h-[320px] fk:w-full fk:rounded-none fk:border-0 fk:bg-transparent fk:dark:bg-transparent fk:pb-11 fk:shadow-none focus-visible:fk:ring-0 focus-visible:fk:ring-offset-0 fk:mask-[linear-gradient(to_bottom,black_calc(100%-2.75rem),#0009_calc(100%-1.25rem),#0003_calc(100%-0.5rem),transparent)] fk:corner-squircle",id:"automation-instructions",placeholder:"Describe what the agent should do on each run, e.g. 'When a new Review is created, translate the text to English, run a sentiment analysis and store the result in the sentiment attribute...'",rows:8,value:m,onBlur:()=>be(a=>({...a,instructions:true})),onChange:a=>u(a.target.value)})}),jsx("div",{className:`fk:rounded-b-md fk:border-x fk:border-b fk:bg-muted/60 fk:dark:bg-muted/30 fk:px-2 fk:py-2 ${rt?"fk:border-destructive":"fk:border-input"} fk:corner-squircle`,children:jsxs("div",{className:"fk:flex fk:flex-wrap fk:items-center fk:gap-2",children:[jsxs(a$2,{value:Nt,onValueChange:a=>{$(a),y(null);},children:[jsx(d$3,{"aria-label":"Model",className:"fk:w-fit fk:border-transparent fk:bg-background/90 fk:px-2.5 fk:py-0 fk:text-xs fk:shadow-sm hover:fk:border-border",size:"sm",children:jsx(c$4,{placeholder:"Select a model"})}),jsx(e$6,{align:"start",children:lt.map(a=>jsxs(g$4,{value:b$6(a),children:[a.name,a.deprecated?" (Legacy)":""]},b$6(a)))})]}),En.length>1&&Zt?jsxs(a$2,{value:Zt,onValueChange:y,children:[jsx(d$3,{"aria-label":"Reasoning effort",className:"fk:w-fit fk:border-transparent fk:bg-background/90 fk:px-2.5 fk:py-0 fk:text-xs fk:shadow-sm hover:fk:border-border",size:"sm",children:jsx(c$4,{placeholder:"Effort"})}),jsx(e$6,{align:"start",children:En.map(a=>jsx(g$4,{value:a.value,children:a.label},a.value))})]}):null]})})]}),rt?jsx(Xe,{id:"automation-instructions-error",message:te.instructions}):null,$e&&te.model?jsx(Xe,{message:te.model}):null]}),jsxs("div",{className:"fk:space-y-3",children:[jsx(e$5,{className:"fk:mb-1",htmlFor:"automation-mutation-policy",children:"Mutations"}),jsx("p",{className:"fk:text-xs fk:text-muted-foreground fk:mb-2",children:"How data changes proposed by the agent are handled. With approval required, runs pause until a project member reviews a before/after preview in the Approvals inbox."}),jsxs(a$2,{value:h,onValueChange:a=>{R(a==="auto_approve"?"auto_approve":"require_approval");},children:[jsx(d$3,{"aria-label":"Mutation policy",className:"fk:w-fit",id:"automation-mutation-policy",children:jsx(c$4,{})}),jsxs(e$6,{align:"start",children:[jsx(g$4,{value:"require_approval",children:"Require approval (recommended)"}),jsx(g$4,{value:"auto_approve",children:"Auto-approve"})]})]}),h==="auto_approve"&&g$1.some(a=>a.enabled)?jsxs("p",{className:"fk:flex fk:items-start fk:gap-1 fk:text-xs fk:text-warning",role:"status",children:[jsx(TriangleAlertIcon,{className:"fk:mt-px fk:size-3.5 fk:shrink-0"}),"Plugin tools will run without review. Content the agent reads, such as emails or documents, could lead it to act on your connected accounts."]}):null,h==="require_approval"&&F&&F.length>0?jsxs("div",{className:"fk:space-y-2",children:[jsx("p",{className:"fk:text-xs fk:text-muted-foreground",children:"Always allowed plugin tools (approved with \u201Calways allow\u201D from the Approvals inbox):"}),jsx("ul",{className:"fk:space-y-1",children:F.map(a=>jsxs("li",{className:"fk:flex fk:items-center fk:justify-between fk:gap-2 fk:rounded-md fk:border fk:border-border fk:px-2.5 fk:py-1.5 fk:text-xs fk:corner-squircle",children:[jsxs("code",{children:[a.pluginId,": ",a.tool]}),jsx(b$2,{"aria-label":`Remove allow rule for ${a.pluginId} ${a.tool}`,size:"sm",type:"button",variant:"ghost",onClick:()=>w(p=>(p??[]).filter(v=>v!==a)),children:"Remove"})]},`${a.pluginId}/${a.server}/${a.tool}`))})]}):null]}),jsxs("div",{className:"fk:space-y-4",children:[jsxs("div",{children:[jsx(e$5,{className:"fk:text-sm fk:font-medium",children:"Tools"}),jsx("p",{className:"fk:mb-3 fk:text-xs fk:text-muted-foreground",children:"Configure additional destinations and built-in capabilities for this automation."})]}),jsxs("div",{className:"fk:rounded-lg fk:border fk:bg-muted/60 fk:dark:bg-muted/30 fk:corner-squircle",children:[jsx("div",{className:"fk:rounded-t-lg fk:corner-squircle",children:jsxs("div",{className:"fk:m-1.5 fk:flex fk:items-start fk:justify-between fk:gap-3 fk:rounded-md fk:p-1.5 fk:hover:bg-muted fk:corner-squircle",children:[jsxs("div",{className:"fk:flex fk:gap-3 fk:pb-0.5",children:[jsx(BrainIcon,{className:"fk:mt-1 fk:size-3.5 fk:text-muted-foreground"}),jsxs("div",{children:[jsx("div",{className:"fk:text-sm fk:font-medium",children:"Memories"}),jsx("p",{className:"fk:text-xs fk:text-muted-foreground",children:"Builds memory across runs to make automations smarter over time"})]})]}),jsx(b$1,{className:"fk:mt-1.5 fk:py-0 fk:text-[10px] fk:font-light fk:tracking-wide",variant:"secondary",children:"Always on"})]})}),jsx(v,{}),ie?jt.map(a=>{let p=ie[a],v$1=a==="slack"?"Send to Slack":"Send to Microsoft Teams",N=a==="slack"?gs:vs,B=wt[a];return jsxs(Fragment$1,{children:[jsxs("div",{className:"fk:m-1.5 fk:space-y-2 fk:rounded-md fk:p-1.5 fk:hover:bg-muted fk:corner-squircle",children:[jsxs("div",{className:"fk:flex fk:items-center fk:justify-between fk:gap-3",children:[jsxs("div",{className:"fk:flex fk:gap-3",children:[jsx(N,{}),jsxs("div",{children:[jsx("div",{className:"fk:text-sm fk:font-medium",children:v$1}),p.connected&&p.workspaceName?jsxs("p",{className:"fk:text-xs fk:text-muted-foreground",children:["Connected to ",p.workspaceName]}):null,p.connected?null:jsx("p",{className:"fk:text-xs fk:text-muted-foreground",children:Me?.canManage===false?"Not connected. Ask a project owner or developer to connect it.":"Not connected"})]})]}),p.connected?p.enabled?jsx(b$2,{"aria-label":`Remove ${a==="slack"?"Slack":"Microsoft Teams"} from automation`,size:"icon",type:"button",variant:"ghost",onClick:()=>ka$1(a),children:jsx(Trash2Icon,{className:"fk:size-4 fk:text-muted-foreground"})}):jsx(b$2,{size:"sm",type:"button",variant:"outline",onClick:()=>St(a,{enabled:true}),children:"Add"}):jsx(b$2,{disabled:!le||!B?.enabled||!Me?.canManage||Je!==null,size:"sm",type:"button",variant:"outline",onClick:()=>{da(a);},children:Je===a?"Connecting\u2026":"Connect"})]}),p.connected&&p.enabled?jsxs("div",{className:"fk:space-y-2 fk:pl-7",children:[B&&B.connections.filter(Re=>Re.scope==="project"&&Re.status==="connected").length>1?jsxs("div",{className:"fk:flex fk:flex-wrap fk:items-center fk:gap-3",children:[jsx(e$5,{className:"fk:text-xs fk:font-medium",children:"Workspace"}),jsx(bn,{ariaLabel:`${a==="slack"?"Slack":"Microsoft Teams"} workspace`,disabled:!le,plugin:B,scopes:["project"],value:{connectionMode:"project",connectionId:b$3[a]},onChange:Re=>ma$1(a,Re.connectionId)})]}):null,jsx(e$5,{className:"fk:mr-3 fk:text-xs fk:font-medium",children:"Channels"}),jsx(cs,{channels:p.availableChannels,disabled:p.loadingChannels||!le,loading:p.loadingChannels,provider:a,value:p.channels,onChange:Re=>St(a,{channels:Re}),onRefresh:()=>{sn(a,an[a]);}}),p.channelsLoadError?jsxs("p",{className:"fk:flex fk:items-start fk:text-sm fk:text-warning fk:gap-1",children:[jsx(TriangleAlertIcon,{className:"fk:size-4 fk:shrink-0 fk:mt-0.5"}),p.channelsLoadError]}):null,!p.channelsLoadError&&te.toolErrors[a]?jsx(Xe,{message:te.toolErrors[a]}):null]}):null]}),jsx(v,{})]},a)}):ia?jsx("p",{className:"fk:m-1.5 fk:p-1.5 fk:text-xs fk:text-warning",role:"alert",children:"Unable to load Slack and Microsoft Teams delivery. Reload the page to try again."}):jsxs("div",{className:"fk:flex fk:items-center fk:justify-center fk:gap-2 fk:p-4 fk:text-sm fk:text-muted-foreground",children:[jsx(LoaderCircleIcon,{className:"fk:size-4 fk:animate-spin"}),"Loading tools..."]}),jsxs("div",{className:"fk:m-1.5 fk:space-y-2 fk:rounded-md fk:px-1.25 fk:py-1.5 fk:hover:bg-muted fk:corner-squircle",children:[jsxs("div",{className:"fk:flex fk:items-center fk:justify-between fk:gap-3",children:[jsxs("div",{className:"fk:flex fk:gap-2.5",children:[jsx(GraduationCapIcon,{className:"fk:mt-px fk:size-5 fk:text-muted-foreground"}),jsxs("div",{children:[jsx("div",{className:"fk:text-sm fk:font-medium",children:"Skills"}),jsx("p",{className:"fk:text-xs fk:text-muted-foreground",children:"Attached skills are always loaded into the agent context. All other skills you can see stay discoverable by the agent when relevant."})]})]}),jsx(pn,{disabled:!le||Qt.length===0&&en.length===0,emptyText:"No skills match.",items:[...Qt.map(a=>({id:a.id,label:a.name,attached:x.includes(a.id),badge:a.source==="code"?"Code":void 0})),...en.map(a=>({id:a.id,label:a.name,attached:false,badge:a.source==="code"?"Code":void 0,lockedHint:bs(a,ua)}))],searchPlaceholder:"Search skills\u2026",onToggle:Fn})]}),Z$1&&Qt.length===0&&en.length===0?jsx("p",{className:"fk:pl-7 fk:text-xs fk:text-muted-foreground",children:"No attachable skills yet. Create them on the Skills tab."}):null,Z$1?.hasMore?jsxs("p",{className:"fk:pl-7 fk:text-xs fk:text-muted-foreground",children:["Showing the ",Z$1.skills.length," most recently updated skills. Attached skills outside this list are kept when you save."]}):null,x.length>0?jsx("div",{className:"fk:flex fk:flex-wrap fk:gap-1.5 fk:pl-7",children:x.map(a=>{let p=Ge[a],v=p?.name??"Loading skill\u2026";return jsxs(b$1,{className:"fk:gap-1 fk:pr-1 fk:font-normal",variant:"secondary",children:[v,p?.source==="code"?jsx("span",{className:"fk:text-[10px] fk:uppercase",children:"Code"}):null,jsx("button",{"aria-label":p?`Detach ${p.name}`:"Detach skill",className:"fk:cursor-pointer fk:rounded-sm fk:text-muted-foreground fk:hover:text-foreground disabled:fk:cursor-not-allowed fk:corner-squircle",disabled:!le,type:"button",onClick:()=>Fn(a,false),children:jsx(XIcon,{className:"fk:size-3"})})]},a)})}):null]}),jsx(v,{}),jsxs("div",{className:"fk:m-1.5 fk:space-y-2 fk:rounded-md fk:px-1.25 fk:py-1.5 fk:hover:bg-muted fk:corner-squircle",children:[jsxs("div",{className:"fk:flex fk:items-center fk:justify-between fk:gap-3",children:[jsxs("div",{className:"fk:flex fk:gap-2.5",children:[jsx(WrenchIcon,{className:"fk:mt-px fk:size-5 fk:text-muted-foreground"}),jsxs("div",{children:[jsx("div",{className:"fk:text-sm fk:font-medium",children:"Custom tools"}),jsx("p",{className:"fk:text-xs fk:text-muted-foreground",children:"Attached custom tools can be called during a run. Tools you do not attach stay unavailable to this automation."}),Ln?jsx("p",{className:ze?.connected?"fk:mt-1 fk:text-xs fk:text-warning":"fk:mt-1 fk:text-xs fk:text-muted-foreground",children:Ln}):null]})]}),jsx(pn,{disabled:!le||nn.length===0,emptyText:"No custom tools match.",items:nn.map(a=>({id:a.name,label:a.name,attached:W.includes(a.name)})),searchPlaceholder:"Search custom tools\u2026",onToggle:Bn})]}),ze&&nn.length===0?jsx("p",{className:"fk:pl-7 fk:text-xs fk:text-muted-foreground",children:"No custom tools registered yet. Define them in flexkit.tools.ts, run `flexkit dev` or sync them from the Dashboard, then attach the ones this automation needs."}):null,W.length>0?jsx("div",{className:"fk:flex fk:flex-wrap fk:gap-1.5 fk:pl-7",children:W.map(a=>{let v=tn[a]?.name??a;return jsxs(b$1,{className:"fk:gap-1 fk:pr-1 fk:font-normal",variant:"secondary",children:[v,jsx("button",{"aria-label":`Detach ${v}`,className:"fk:cursor-pointer fk:rounded-sm fk:text-muted-foreground fk:hover:text-foreground disabled:fk:cursor-not-allowed fk:corner-squircle",disabled:!le,type:"button",onClick:()=>Bn(a,false),children:jsx(XIcon,{className:"fk:size-3"})})]},a)})}):null]}),jsx(v,{}),jsx(Po,{projectId:l,value:g$1,disabled:!le,onChange:a=>{d(a),zo(a)&&(E("personal"),_(null));}})]})]}),jsxs("div",{className:"fk:flex fk:items-center fk:justify-end fk:gap-3",children:[on?null:jsx("span",{className:"fk:text-xs fk:text-muted-foreground",children:"Complete the required fields to save"}),jsx(ma,{disabled:!le,children:jsx(b$2,{disabled:it||!on||!le,type:"submit",children:it?"Saving...":o==="create"?"Create automation":"Update automation"})})]})]})}var Go=25;function Ds(t){return Math.max(600,t)}function Ls(t){return t==="mine"||t==="team"}function J({children:t}){return jsx("div",{className:"fk:rounded-md fk:border fk:border-dashed fk:p-8 fk:text-center fk:text-sm fk:text-muted-foreground fk:corner-squircle",children:t})}function zs(t){return t==="success"?"fk:bg-success/20 fk:text-success":t==="awaiting_approval"?"fk:bg-amber-500/20 fk:text-amber-600":t==="skipped"?"fk:bg-orange-500/20 fk:text-orange-700":"fk:bg-secondary fk:text-secondary-foreground"}function ta({status:t}){return jsx(b$1,{className:`fk:border-none fk:h-4.75 fk:text-[0.6875rem] fk:leading-4.5 fk:tracking-wide ${zs(t)}`,variant:t==="success"?"default":"secondary",children:t==="awaiting_approval"?"awaiting approval":t})}function Fs(t){if(t==="0 * * * *")return "Every hour";let n=/^0 (\d{1,2}) \* \* \*$/.exec(t);if(n)return `Every day at ${n[1].padStart(2,"0")}:00`;let o=/^0 (\d{1,2}) \* \* ([0-6])$/.exec(t);return o?`Every ${["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"][Number(o[2])]??"week"} at ${o[1].padStart(2,"0")}:00`:t}function Bs(t){let n=t.triggers.map(o=>{if(o.type==="schedule")return Fs(o.cron);if(o.type==="webhook")return "Webhook";let i=o.entities.length>0?o.entities.join(", "):"all entities";return `On ${o.events.join("/")} of ${i}`});return n.length===0?"Manual only":n.join(" \xB7 ")}function na(t){return t?!!(t.name.trim()&&t.instructions.trim()&&t.modelId.trim()):false}function $s({projectId:t}){let{data:n}=De(g(t).creditBalance,f),o=n?.creditBalance;return o?jsx(b$2,{asChild:true,size:"sm",variant:"secondary",children:jsxs("a",{href:o.billingUrl,rel:"noopener noreferrer",target:"_blank",children:[jsx(CoinsIcon,{className:"fk:mr-2 fk:size-4"}),o.display," Credit"]})}):null}function js(t,n){let o=t.visibility??"project";return o==="space"?(t.spaceId?n.get(t.spaceId):void 0)??"Space":o==="personal"?"Personal":"Project"}var oa="fk:sticky fk:top-0 fk:z-10 fk:[&_th]:sticky fk:[&_th]:top-0 fk:[&_th]:bg-muted";function _s(){return jsxs(_,{children:[jsx($,{className:oa,children:jsxs(ca,{children:[jsx(da,{children:"Automation"}),jsx(da,{children:"Triggers"}),jsx(da,{children:"Last run"}),jsx(da,{className:"fk:text-center",children:"Runs"}),jsx(da,{children:"Visibility"}),jsx(da,{className:"fk:text-center",children:"Status"}),jsx(da,{})]})}),jsx(aa$1,{children:Array.from({length:5},(t$1,n)=>jsxs(ca,{children:[jsx(ea,{children:jsx(t,{className:"fk:h-4 fk:w-36"})}),jsx(ea,{children:jsx(t,{className:"fk:h-4 fk:w-48"})}),jsx(ea,{children:jsx(t,{className:"fk:h-4 fk:w-24"})}),jsx(ea,{className:"fk:text-center",children:jsx(t,{className:"fk:mx-auto fk:h-4 fk:w-8"})}),jsx(ea,{children:jsx(t,{className:"fk:h-4.75 fk:w-16"})}),jsx(ea,{className:"fk:text-center",children:jsx(t,{className:"fk:mx-auto fk:h-4.75 fk:w-16"})}),jsx(ea,{className:"fk:text-right",children:jsx(t,{className:"fk:ml-auto fk:size-8"})})]},n))})]})}function Zo(t,n){let i=t.find(l=>l.id===n)?.value;return Array.isArray(i)?i.filter(l=>typeof l=="string"):[]}function Vs(t){if(t.length===0)return;let n=t.map(o=>o==="enabled"?true:o==="disabled"?false:null).filter(o=>o!==null);if(n.length!==0)return n}function Hs(t){if(t.length===0)return;let n=t.filter(o=>o==="project"||o==="space"||o==="personal");if(n.length!==0)return n}function Ki(){let{api:t,projectId:n}=q(),o$1=useNavigate(),[i,l]=useState([]),[g$2,d]=useState(""),[k,r]=useState(""),m=b(),u=useRef(null),T=Zo(i,"status"),I=Zo(i,"visibility"),C=Vs(T),$$1=Hs(I),A=i.length>0||g$2.trim().length>0,y=JSON.stringify({enabledFilter:C,search:g$2,visibilityFilter:$$1}),h$1=(b,j)=>!n||j&&j.hasMore===false?null:g(n).automations({enabled:C,limit:Go,offset:b*Go,search:g$2.trim()||void 0,visibility:$$1}),{data:R,isLoading:F,mutate:w,setSize:S,size:E}=bt(h$1,f),{data:M}=De(n?g(n).spaces:null,f),_$1=useMemo(()=>new Map((M?.spaces??[]).map(b=>[b.id,b.label])),[M?.spaces]),x=R?.flatMap(b=>b.automations)??[],W=R?.[R.length-1]?.hasMore??false,me=R!==void 0&&E>R.length,G=R?.[0]?.count,he=F&&x.length===0,it=useMemo(()=>[{id:"status",accessorKey:"enabled"},{id:"visibility",accessorKey:"visibility"}],[]),Fe=useReactTable({columns:it,data:x,getCoreRowModel:getCoreRowModel(),manualFiltering:true,onColumnFiltersChange:b=>{S(1),l(b);},state:{columnFilters:i}}),Ie=useRef(()=>{S(b=>b+1);}),Be=useRef(W),Le=useRef(me);Ie.current=()=>{S(b=>b+1);},Be.current=W,Le.current=me;let be=useCallback(b=>{if(!Ie.current||!Be.current||Le.current)return;let j=b??u.current;if(!j)return;let{scrollHeight:ue,scrollTop:yt,clientHeight:Me}=j;ue-yt-Me>=Ds(Me)||(Le.current=true,Ie.current());},[]);useEffect(()=>{be();},[be,x.length,W,me,y]),useEffect(()=>{u.current?.scrollTo({top:0});},[y]);let ie=useRef(g$2);ie.current=g$2;let Pe=useCallback(b=>{b!==ie.current&&(S(1),d(b));},[S]);if(!n||!t)return jsx(J,{children:"Select a project to view automations."});async function Je(b){if(r(""),!t)return;let j=await t.deleteAutomation(b.id);if(!j.success){r(Array.isArray(j.errorMessage)?j.errorMessage.join(", "):j.errorMessage);return}await w();}function Ke(b){be(b.currentTarget);}let D;return F&&x.length===0?D=jsx(_s,{}):x.length===0?D=jsx(J,{children:A?"No results.":"No automations yet."}):D=jsxs(_,{children:[jsx($,{className:oa,children:jsxs(ca,{children:[jsx(da,{children:"Automation"}),jsx(da,{children:"Triggers"}),jsx(da,{children:"Last run"}),jsx(da,{className:"fk:text-center",children:"Runs"}),jsx(da,{children:"Visibility"}),jsx(da,{className:"fk:text-center",children:"Status"}),jsx(da,{})]})}),jsx(aa$1,{children:x.map(b=>jsxs(ca,{className:"fk:cursor-pointer",onClick:()=>o$1(b.id),children:[jsx(ea,{children:jsx("span",{className:"fk:font-medium",children:b.name})}),jsx(ea,{className:"fk:text-muted-foreground",children:Bs(b)}),jsx(ea,{children:b.lastRunAt?formatDistance(new Date(b.lastRunAt),new Date,{addSuffix:true}):"Never"}),jsx(ea,{className:"fk:text-center",children:b.totalRuns}),jsx(ea,{children:jsx(b$1,{className:"fk:h-4.75 fk:text-[0.6875rem] fk:leading-4.5 fk:tracking-wide",variant:b.visibility==="personal"?"secondary":"outline",children:js(b,_$1)})}),jsx(ea,{className:"fk:text-center",children:jsx(b$1,{className:`fk:border-none fk:h-4.75 fk:text-[0.6875rem] fk:leading-4.5 fk:tracking-wide ${b.enabled?"fk:bg-success/20 fk:text-success":"fk:bg-secondary fk:text-secondary-foreground"}`,variant:b.enabled?"default":"secondary",children:b.enabled?"Enabled":"Disabled"})}),jsx(ea,{className:"fk:text-right",children:jsxs(e,{children:[jsx(g$1,{asChild:true,children:jsx(b$2,{"aria-label":`Actions for ${b.name}`,size:"icon",type:"button",variant:"ghost",onClick:j=>{j.stopPropagation();},children:jsx(Ellipsis,{className:"fk:size-4"})})}),jsxs(h,{align:"end",className:"fk:w-40",children:[jsxs(j,{onClick:j=>{j.stopPropagation(),o$1(b.id);},children:[jsx(Pencil,{}),"Edit"]}),jsx(o,{}),jsxs(j,{disabled:!m,variant:"destructive",onClick:j=>{j.stopPropagation(),Je(b);},children:[jsx(Trash2,{}),"Delete"]})]})]})})]},b.id))})]}),jsxs("div",{className:"fk:flex fk:h-full fk:min-h-0 fk:min-w-0 fk:flex-col fk:gap-4 fk:pr-4",children:[jsxs("div",{className:"fk:flex fk:shrink-0 fk:items-start fk:gap-2",children:[jsxs(b$3,{children:[jsx(c,{asChild:true,children:jsx(N,{className:"fk:-ml-1 fk:h-4 fk:w-4"})}),jsx(e$1,{children:"Toggle Sidebar"})]}),jsx(v,{orientation:"vertical",className:"fk:mt-1 fk:h-4"}),jsxs("div",{className:"fk:min-w-0 fk:flex-1",children:[jsxs("div",{className:"fk:flex fk:items-center fk:gap-2",children:[jsx("h1",{className:"fk:text-lg fk:font-semibold fk:leading-none fk:tracking-tight",children:"Automations"}),!he&&G!==void 0?jsxs("span",{className:"fk:ml-auto fk:text-sm fk:font-normal fk:text-muted-foreground",children:[G.toLocaleString()," ",G===1?"automation":"automations"]}):null]}),jsxs("p",{className:"fk:mt-1 fk:text-sm fk:text-muted-foreground",children:["Agent-powered tasks that run on a schedule or when your data changes.",jsx(f$1,{href:"https://flexkit.io/docs/automations",children:"Learn more"})]})]})]}),k?jsx("div",{className:"fk:text-sm fk:text-destructive",children:k}):null,jsx(To,{actions:jsxs(Fragment,{children:[jsx($s,{projectId:n}),m?jsx(b$2,{asChild:true,className:"fk:h-8",size:"sm",children:jsxs(Link,{to:"new",children:[jsx(Plus,{className:"fk:mr-2 fk:size-4"}),"New Automation"]})}):jsx(ma,{disabled:true,children:jsxs(b$2,{className:"fk:h-8",disabled:true,size:"sm",children:[jsx(Plus,{className:"fk:mr-2 fk:size-4"}),"New Automation"]})})]}),isSearchLoading:F&&g$2.trim().length>0,search:g$2,table:Fe,onSearchChange:Pe}),jsxs("div",{className:"fk:relative fk:min-h-0 fk:min-w-0 fk:flex-1",children:[me?jsx("div",{"aria-hidden":true,className:"fk:pointer-events-none fk:absolute fk:top-0 fk:right-px fk:left-px fk:z-20 fk:h-0.5 fk:overflow-hidden fk:opacity-40",children:jsx("div",{className:"fk:animate-progress fk:h-full fk:w-full fk:bg-foreground"})}):null,jsx("div",{className:"fk:h-full fk:overflow-auto",onScroll:Ke,ref:u,children:D})]})]})}function Wi(){let{api:t,projectId:n}=q(),o=useNavigate();return !n||!t?jsx(J,{children:"Select a project to create automations."}):jsxs("div",{className:"fk:flex fk:h-full fk:min-h-0 fk:flex-col fk:gap-2",children:[jsxs("div",{className:"fk:mb-4 fk:flex fk:shrink-0 fk:items-start fk:gap-2",children:[jsxs(b$3,{children:[jsx(c,{asChild:true,children:jsx(N,{className:"fk:-ml-1 fk:h-4 fk:w-4"})}),jsx(e$1,{children:"Toggle Sidebar"})]}),jsx(v,{orientation:"vertical",className:"fk:mt-1 fk:h-4"}),jsx("div",{className:"fk:flex-1",children:jsx("h1",{className:"fk:text-lg fk:font-semibold fk:leading-none fk:tracking-tight",children:"New Automation"})})]}),jsx(b$2,{asChild:true,className:"fk:shrink-0 fk:w-fit",size:"sm",variant:"ghost",children:jsxs(Link,{relative:"path",to:"..",children:[jsx(ArrowLeft,{className:"fk:mr-2 fk:size-4"}),"Automations"]})}),jsx(w,{className:"fk:h-0 fk:min-h-0 fk:flex-1",children:jsx("div",{className:"fk:pb-6 fk:pr-4",children:jsx(Tn,{api:t,mode:"create",projectId:n,onSaved:()=>o("..",{relative:"path"})})})})]})}function Gi(){let{api:t,projectId:n}=q(),{automationId:o}=useParams(),i=useNavigate(),[l,g$1]=useTransition(),d=b(),{data:k,mutate:r}=De(n&&o?g(n).automation(o):null,f);if(!n||!t||!o)return jsx(J,{children:"Select an automation."});if(!k?.automation)return jsx(J,{children:"Loading automation..."});let m=t,u=na(k.automation)&&d,T=o;function I(){u&&g$1(async()=>{let C=await m.runAutomation(T);if(C.success&&C.runId){i(`runs/${C.runId}`);return}await r();});}return jsxs("div",{className:"fk:flex fk:h-full fk:min-h-0 fk:flex-col fk:gap-2",children:[jsxs("div",{className:"fk:mb-4 fk:flex fk:shrink-0 fk:items-start fk:gap-2",children:[jsxs(b$3,{children:[jsx(c,{asChild:true,children:jsx(N,{className:"fk:-ml-1 fk:h-4 fk:w-4"})}),jsx(e$1,{children:"Toggle Sidebar"})]}),jsx(v,{orientation:"vertical",className:"fk:mt-1 fk:h-4"}),jsx("div",{className:"fk:flex-1",children:jsx("h1",{className:"fk:text-lg fk:font-semibold fk:leading-none fk:tracking-tight",children:k.automation.name})})]}),jsxs("div",{className:"fk:flex fk:shrink-0 fk:flex-wrap fk:items-center fk:justify-between fk:gap-3 fk:pr-4",children:[jsx(b$2,{asChild:true,size:"sm",variant:"ghost",children:jsxs(Link,{to:"../automations",children:[jsx(ArrowLeft,{className:"fk:mr-2 fk:size-4"}),"Automations"]})}),jsx(ga,{value:"settings",children:jsxs(ha,{children:[jsx(ia,{className:"text-xs",value:"settings",children:"Settings"}),jsx(ia,{className:"text-xs",value:"runs",children:jsx(Link,{to:"runs",children:"Runs"})})]})}),jsx(ma,{disabled:!d,children:jsxs(b$2,{disabled:l||!u,size:"sm",onClick:I,children:[l?jsx(LoaderCircle,{className:"fk:mr-2 fk:size-4 fk:animate-spin"}):jsx(Play,{className:"fk:mr-2 fk:size-4"}),"Run now"]})})]}),jsx(w,{className:"fk:h-0 fk:min-h-0 fk:flex-1",children:jsx("div",{className:"fk:pb-6 fk:pr-4",children:jsx(Tn,{api:t,automation:k.automation,mode:"edit",projectId:n,onSaved:C=>{C?r({automation:C},{revalidate:false}):r();}})})})]})}var Ot=25;function Zi(){let{api:t,projectId:n}=q(),{automationId:o}=useParams(),i=useNavigate(),[l,g$1]=useTransition(),{data:d}=De(n&&o?g(n).automation(o):null,f),k=(M,_)=>!n||!o||_&&_.hasMore===false?null:g(n).automationRuns(o,M*Ot,Ot),{data:r,isLoading:m,mutate:u,setSize:T,size:I}=bt(k,f),C=b();if(!n||!t||!o)return jsx(J,{children:"Select an automation to view runs."});let $=t,A=na(d?.automation)&&C,y=o;function h(){A&&g$1(async()=>{let M=await $.runAutomation(y);if(M.success&&M.runId){i(M.runId);return}await u();});}let R=r?.flatMap(M=>M.runs)??[],w$1=r?.[r.length-1]?.hasMore??false,S=r!==void 0&&I>r.length;function E(){T(M=>M+1);}return jsxs("div",{className:"fk:flex fk:h-full fk:min-h-0 fk:flex-col fk:gap-2",children:[jsxs("div",{className:"fk:mb-4 fk:flex fk:shrink-0 fk:items-start fk:gap-2",children:[jsxs(b$3,{children:[jsx(c,{asChild:true,children:jsx(N,{className:"fk:-ml-1 fk:h-4 fk:w-4"})}),jsx(e$1,{children:"Toggle Sidebar"})]}),jsx(v,{orientation:"vertical",className:"fk:mt-1 fk:h-4"}),jsx("div",{className:"fk:flex-1",children:jsx("h1",{className:"fk:text-lg fk:font-semibold fk:leading-none fk:tracking-tight",children:d?.automation.name??"Automation"})})]}),jsxs("div",{className:"fk:flex fk:shrink-0 fk:flex-wrap fk:items-center fk:justify-between fk:gap-3 fk:pr-4",children:[jsx(b$2,{asChild:true,size:"sm",variant:"ghost",children:jsxs(Link,{to:"../automations",children:[jsx(ArrowLeft,{className:"fk:mr-2 fk:size-4"}),"Automations"]})}),jsx(ga,{value:"runs",children:jsxs(ha,{children:[jsx(ia,{className:"text-xs",value:"settings",children:jsx(Link,{relative:"path",to:"..",children:"Settings"})}),jsx(ia,{className:"text-xs",value:"runs",children:"Runs"})]})}),jsx(ma,{disabled:!C,children:jsxs(b$2,{disabled:l||!A,size:"sm",onClick:h,children:[l?jsx(LoaderCircle,{className:"fk:mr-2 fk:size-4 fk:animate-spin"}):jsx(Play,{className:"fk:mr-2 fk:size-4"}),"Run now"]})})]}),jsx(w,{className:"fk:h-0 fk:min-h-0 fk:flex-1",children:jsxs("div",{className:"fk:pb-6 fk:pr-4",children:[jsx(aa,{basePath:".",isLoading:m,runs:R}),w$1&&!S?jsx(Kt,{onVisible:E}):null,S?jsxs("div",{className:"fk:flex fk:items-center fk:justify-center fk:gap-2 fk:py-4 fk:text-sm fk:text-muted-foreground",children:[jsx(LoaderCircle,{className:"fk:size-4 fk:animate-spin"}),jsx("span",{children:"Loading more runs..."})]}):null]})})]})}function Kt({onVisible:t}){let n=useRef(null),o=useRef(t);return o.current=t,useEffect(()=>{let i=n.current;if(!i)return;let l=new IntersectionObserver(g=>{g.some(d=>d.isIntersecting)&&o.current();});return l.observe(i),()=>{l.disconnect();}},[]),jsx("div",{className:"fk:h-px",ref:n})}function Sn(){return jsx(_,{children:jsx(aa$1,{children:Array.from({length:5},(t$1,n)=>jsxs(ca,{children:[jsx(ea,{className:"fk:py-2",children:jsx(t,{className:"fk:h-4 fk:w-28"})}),jsx(ea,{children:jsx(t,{className:"fk:h-4 fk:w-20"})}),jsx(ea,{children:jsx(t,{className:"fk:h-4.75 fk:w-16"})}),jsx(ea,{children:jsx(t,{className:"fk:h-4 fk:w-full fk:max-w-md"})})]},n))})})}function aa({basePath:t,isLoading:n=false,runs:o}){return n?jsx(Sn,{}):o.length===0?jsx(J,{children:"No runs found."}):jsx(_,{children:jsx(aa$1,{children:o.map(i=>jsxs(ca,{children:[jsx(ea,{className:"fk:py-2",children:jsx(Link,{className:"fk:font-medium hover:fk:underline",to:`${t}/${i.id}`,children:formatDistance(new Date(i.startedAt),new Date,{addSuffix:true})})}),jsx(ea,{className:"fk:text-muted-foreground",children:i.triggerType}),jsx(ea,{children:jsx(ta,{status:i.status})}),jsx(ea,{className:"fk:max-w-md fk:truncate fk:text-muted-foreground",children:i.summary??""})]},i.id))})})}function Yi(){let{projectId:t$1}=q(),[n,o]=useState("team"),i=(y,h)=>!t$1||h&&!h.history.hasMore?null:g(t$1).runHistory(n,y*Ot,Ot),{data:l,isLoading:g$1,setSize:d,size:k}=bt(i,f),r=l?.[0]?.history.metrics,m=l?.flatMap(y=>y.history.runs)??[],T=l?.[l.length-1]?.history.hasMore??false,I=l!==void 0&&k>l.length;if(!t$1)return jsx(J,{children:"Select a project to view run history."});function C(){d(y=>y+1);}function $(y){!Ls(y)||y===n||o(y);}let A=null;return g$1?A=jsx("div",{className:"fk:mb-6 fk:grid fk:shrink-0 fk:gap-3 fk:grid-cols-4 fk:pr-4",children:Array.from({length:4},(y,h)=>jsxs("div",{className:"fk:rounded-md fk:bg-muted/60 fk:p-4 fk:corner-squircle",children:[jsx(t,{className:"fk:h-4 fk:w-24"}),jsx(t,{className:"fk:mt-2 fk:h-8 fk:w-12"})]},h))}):r&&(A=jsxs("div",{className:"fk:mb-6 fk:grid fk:shrink-0 fk:gap-3 fk:grid-cols-4 fk:pr-4",children:[jsx(Xt,{title:"Successful 24h",value:r.successful24h}),jsx(Xt,{title:"Failed 24h",value:r.failed24h}),jsx(Xt,{title:"Successful 7d",value:r.successful7d}),jsx(Xt,{title:"Failed 7d",value:r.failed7d})]})),jsxs("div",{className:"fk:flex fk:h-full fk:min-h-0 fk:flex-col",children:[jsxs("div",{className:"fk:mb-2 fk:flex fk:shrink-0 fk:items-center fk:gap-2",children:[jsxs(b$3,{children:[jsx(c,{asChild:true,children:jsx(N,{className:"fk:-ml-1 fk:h-4 fk:w-4"})}),jsx(e$1,{children:"Toggle Sidebar"})]}),jsx(ga,{value:n,onValueChange:$,children:jsxs(ha,{children:[jsx(ia,{value:"team",children:"Team"}),jsx(ia,{value:"mine",children:"Mine"})]})})]}),A,jsx(w,{className:"fk:h-0 fk:min-h-0 fk:flex-1",children:jsxs("div",{className:"fk:pb-6 fk:pr-4",children:[jsx(aa,{basePath:"../automations",isLoading:g$1,runs:m.map(y=>({...y,id:`${y.automationId}/runs/${y.id}`}))}),T&&!I?jsx(Kt,{onVisible:C}):null,I?jsxs("div",{className:"fk:flex fk:items-center fk:justify-center fk:gap-2 fk:py-4 fk:text-sm fk:text-muted-foreground",children:[jsx(LoaderCircle,{className:"fk:size-4 fk:animate-spin"}),jsx("span",{children:"Loading more runs..."})]}):null]})})]})}var Yo=25;function Us(t){return t==="pending"||t==="all"}function Qi(){let{api:t,projectId:n}=q(),[o,i]=useState("pending"),[l,g$1]=useState(null),d$1=(E,M)=>!n||M&&!M.hasMore?null:g(n).approvals({limit:Yo,offset:E*Yo,status:o==="pending"?"pending":void 0}),{data:k,isLoading:r,mutate:m,setSize:u,size:T}=bt(d$1,f,{refreshInterval:3e4}),I=k?.flatMap(E=>E.approvals)??[],C=k?.[0]?.pendingCount??0,$=k?.[0],A=a();useEffect(()=>{$&&A($);},[$,A]);let h=k?.[k.length-1]?.hasMore??false,R=k!==void 0&&T>k.length,F=I.find(E=>E.id===l)??null;if(useEffect(()=>{l===null||F!==null||r||k===void 0||g$1(null);},[k,r,F,l]),!n||!t)return jsx(J,{children:"Select a project to view approvals."});function w$1(){u(E=>E+1);}function S(E){!Us(E)||E===o||(u(1),i(E));}return jsxs("div",{className:"fk:flex fk:h-full fk:min-h-0 fk:flex-col",children:[jsxs("div",{className:"fk:mb-2 fk:flex fk:shrink-0 fk:items-center fk:gap-2",children:[jsxs(b$3,{children:[jsx(c,{asChild:true,children:jsx(N,{className:"fk:-ml-1 fk:h-4 fk:w-4"})}),jsx(e$1,{children:"Toggle Sidebar"})]}),jsx(ga,{value:o,onValueChange:S,children:jsxs(ha,{children:[jsxs(ia,{value:"pending",children:["Pending",C>0?` (${C.toString()})`:""]}),jsx(ia,{value:"all",children:"All"})]})})]}),jsx(w,{className:"fk:h-0 fk:min-h-0 fk:flex-1",children:jsxs("div",{className:"fk:pb-6 fk:pr-4",children:[r?jsx(Sn,{}):I.length===0?jsx(J,{children:o==="pending"?"No proposals are waiting for approval.":"No approvals found."}):jsx(_,{children:jsx(aa$1,{children:I.map(E=>jsxs(ca,{className:"fk:cursor-pointer",onClick:()=>g$1(E.id),children:[jsx(ea,{children:jsx(b$4,{status:E.status})}),jsx(ea,{className:"fk:font-medium",children:E.operationsSummary}),jsx(ea,{className:"fk:text-muted-foreground",children:E.automationName}),jsx(ea,{className:"fk:text-muted-foreground",children:formatDistance(new Date(E.requestedAt),new Date,{addSuffix:true})}),jsx(ea,{onClick:M=>M.stopPropagation(),children:E.chatId?jsx(Link,{className:"fk:text-xs fk:text-muted-foreground hover:fk:underline",to:`../agent/chats/${E.chatId}`,children:"View chat"}):E.automationId&&E.runId?jsx(Link,{className:"fk:text-xs fk:text-muted-foreground hover:fk:underline",to:`../automations/${E.automationId}/runs/${E.runId}`,children:"View run"}):null})]},E.id))})}),h&&!R?jsx(Kt,{onVisible:w$1}):null,R?jsxs("div",{className:"fk:flex fk:items-center fk:justify-center fk:gap-2 fk:py-4 fk:text-sm fk:text-muted-foreground",children:[jsx(LoaderCircle,{className:"fk:size-4 fk:animate-spin"}),jsx("span",{children:"Loading more approvals..."})]}):null]})}),F?jsx(d,{api:t,approval:F,onClose:()=>g$1(null),onDecided:()=>{m();}},`${F.id}-${F.status}`):null]})}var Qo=25;function qs(t){return t==="needs_action"||t==="all"}function Xs(){let[t,n]=useState(()=>typeof Notification>"u"?"unsupported":Notification.permission);return t!=="default"?null:jsxs("div",{className:"fk:mb-3 fk:flex fk:items-center fk:gap-3 fk:rounded-md fk:border fk:p-3 fk:text-sm fk:corner-squircle",children:[jsx(BellIcon,{className:"fk:size-4 fk:shrink-0 fk:text-muted-foreground"}),jsx("span",{className:"fk:flex-1",children:"Get a desktop notification when something needs you while Studio is in the background."}),jsx(b$2,{size:"sm",variant:"outline",onClick:()=>{Notification.requestPermission().then(n);},children:"Turn on"})]})}function el(){let{api:t,projectId:n}=q(),o=useNavigate(),i=b$5(),[l,g$1]=useState("needs_action"),[d,k]=useState(()=>new Set),r=a(),m=(w,S)=>!n||S&&!S.hasMore?null:g(n).activity({filter:l,limit:Qo,offset:w*Qo}),{data:u,isLoading:T,mutate:I,setSize:C,size:$}=bt(m,f,{refreshInterval:3e4}),A=useMemo(()=>u?.flatMap(w=>w.items)??[],[u]),y=u?.[u.length-1]?.hasMore??false,h=u!==void 0&&$>u.length;if(useEffect(()=>{let w=A.filter(S=>S.state==="unread").map(S=>S.id);!t||!i||w.length===0||(k(S=>new Set([...S,...w])),t.markActivityRead(w).then(()=>r()));},[t,i,A,r]),!n||!t)return jsx(J,{children:"Select a project to view activity."});function R(w){!qs(w)||w===l||(C(1),g$1(w));}function F(w){t&&t.setActivityItemState(w.id,"dismissed").catch(S=>{oa$1.error(S instanceof Error?S.message:"Unable to dismiss this item.");}).finally(()=>{I();});}return jsxs("div",{className:"fk:flex fk:h-full fk:min-h-0 fk:flex-col",children:[jsxs("div",{className:"fk:mb-2 fk:flex fk:shrink-0 fk:items-center fk:gap-2",children:[jsxs(b$3,{children:[jsx(c,{asChild:true,children:jsx(N,{className:"fk:-ml-1 fk:h-4 fk:w-4"})}),jsx(e$1,{children:"Toggle Sidebar"})]}),jsx(ga,{value:l,onValueChange:R,children:jsxs(ha,{children:[jsx(ia,{value:"needs_action",children:"Needs attention"}),jsx(ia,{value:"all",children:"All"})]})})]}),jsx(Xs,{}),jsx(w,{className:"fk:h-0 fk:min-h-0 fk:flex-1",children:jsxs("div",{className:"fk:pb-6 fk:pr-4",children:[T?jsx(Sn,{}):A.length===0?jsx(J,{children:l==="needs_action"?"Nothing needs your attention.":"No activity yet."}):jsx(_,{children:jsx(aa$1,{children:A.map(w=>{let S=e$2(w),E=c$1(w),M=d$1(w),_=f$2(w);return jsxs(ca,{className:"fk:cursor-pointer",onClick:()=>o(w.id),children:[jsx(ea,{className:"fk:w-4 fk:pr-0",children:d.has(w.id)||w.state==="unread"?jsx("span",{"aria-label":"Unread",className:"fk:block fk:size-2 fk:rounded-full fk:bg-primary"}):null}),jsxs(ea,{children:[jsx("div",{className:"fk:font-medium",children:w.title}),w.body?jsx("div",{className:"fk:text-xs fk:text-muted-foreground",children:w.body}):null]}),jsx(ea,{children:S?jsx(b$1,{className:_?"fk:border-none fk:bg-amber-500/20 fk:text-amber-600 fk:corner-squircle":"fk:corner-squircle",variant:_?"default":"outline",children:S}):null}),jsx(ea,{className:"fk:whitespace-nowrap fk:text-muted-foreground",children:formatDistance(new Date(w.createdAt),new Date,{addSuffix:true})}),jsx(ea,{className:"fk:whitespace-nowrap",onClick:x=>x.stopPropagation(),children:E&&M?jsx(Link,{className:"fk:text-xs fk:text-muted-foreground hover:fk:underline",to:`../${E}`,children:M}):null}),jsx(ea,{className:"fk:w-8",onClick:x=>x.stopPropagation(),children:_?null:jsxs(b$3,{children:[jsx(c,{asChild:true,children:jsx(b$2,{"aria-label":"Dismiss",size:"icon",variant:"ghost",onClick:()=>F(w),children:jsx(XIcon,{className:"fk:size-4"})})}),jsx(e$1,{children:"Dismiss"})]})})]},w.id)})})}),y&&!h?jsx(Kt,{onVisible:()=>{C(w=>w+1);}}):null,h?jsxs("div",{className:"fk:flex fk:items-center fk:justify-center fk:gap-2 fk:py-4 fk:text-sm fk:text-muted-foreground",children:[jsx(LoaderCircle,{className:"fk:size-4 fk:animate-spin"}),jsx("span",{children:"Loading more activity..."})]}):null]})})]})}function tl(){let{api:t$1,projectId:n}=q(),{itemId:o=""}=useParams(),i=a(),{data:l,error:g$1,isLoading:d,mutate:k}=De(n&&o?g(n).activityItem(o):null,f),r=l?.item,m=r?.approvalId??null,{data:u,mutate:T}=De(n&&m?g(n).approval(m):null,f),I=r?.state==="unread",C=b$5();if(useEffect(()=>{!t$1||!I||!C||t$1.markActivityRead([o]).then(()=>{k(),i();});},[t$1,I,C,o,k,i]),!n||!t$1)return jsx(J,{children:"Select a project to view activity."});let $=r?c$1(r):null,A=r?d$1(r):null,y;return g$1?y=jsx(J,{children:"This activity item no longer exists."}):d||!r?y=jsxs("div",{className:"fk:flex fk:flex-col fk:gap-3",children:[jsx(t,{className:"fk:h-4 fk:w-64"}),jsx(t,{className:"fk:h-32 fk:w-full"})]}):y=jsxs("div",{className:"fk:flex fk:flex-col fk:gap-6",children:[jsxs("div",{className:"fk:text-sm fk:text-muted-foreground",children:[r.body?`${r.body} \xB7 `:"",formatDistance(new Date(r.createdAt),new Date,{addSuffix:true})]}),u?jsx(c$2,{api:t$1,approval:u.approval,chat:u.approval.chatId!==null,onDecided:()=>{k(),T(),i();}},`${u.approval.id}-${u.approval.status}`):m?jsx(t,{className:"fk:h-32 fk:w-full"}):null]}),jsxs("div",{className:"fk:flex fk:h-full fk:min-h-0 fk:flex-col fk:gap-2",children:[jsxs("div",{className:"fk:mb-4 fk:flex fk:shrink-0 fk:items-start fk:gap-2",children:[jsxs(b$3,{children:[jsx(c,{asChild:true,children:jsx(N,{className:"fk:-ml-1 fk:h-4 fk:w-4"})}),jsx(e$1,{children:"Toggle Sidebar"})]}),jsx(v,{orientation:"vertical",className:"fk:mt-1 fk:h-4"}),jsx("div",{className:"fk:flex-1",children:jsx("h1",{className:"fk:text-lg fk:font-semibold fk:leading-none fk:tracking-tight",children:r?.title??"Activity"})})]}),jsxs("div",{className:"fk:flex fk:shrink-0 fk:items-center fk:justify-between fk:gap-3 fk:pr-4",children:[jsxs(b$3,{children:[jsx(c,{asChild:true,children:jsx(b$2,{asChild:true,"aria-label":"Back to Activity",size:"icon",variant:"ghost",children:jsx(Link,{relative:"path",to:"..",children:jsx(ArrowLeft,{className:"fk:size-4"})})})}),jsx(e$1,{children:"Back to Activity"})]}),$&&A?jsx(b$2,{asChild:true,size:"sm",variant:"outline",children:jsx(Link,{to:`../${$}`,children:A})}):null]}),jsx(w,{className:"fk:h-0 fk:min-h-0 fk:flex-1",children:jsx("div",{className:"fk:pb-6 fk:pr-4",children:y})})]})}function Xt({title:t,value:n}){return jsxs("div",{className:"fk:rounded-md fk:bg-muted/60 fk:p-4 fk:corner-squircle",children:[jsx("div",{className:"fk:text-sm fk:text-muted-foreground",children:t}),jsx("div",{className:"fk:mt-1 fk:text-2xl fk:font-medium",children:n.toLocaleString()})]})}function nl(){let{api:t,projectId:n}=q(),{automationId:o,runId:i}=useParams(),{data:l,mutate:g$1}=De(n&&i?g(n).run(i):null,f,{refreshInterval:R=>!R?.run||v$1(R.run.status)?0:r}),{data:d}=De(n&&o?g(n).automation(o):null,f),[k,r$1]=useTransition(),[m,u]=useState(false);if(useEffect(()=>{u(false);},[i]),!n||!t||!o||!i)return jsx(J,{children:"Select a run."});let T=t,I=i,C=l?.run,$=C?.status==="running"&&!m;function A(){r$1(async()=>{await T.cancelRun(I),await g$1();});}function y(){u(true),g$1();}function h(){g$1();}return jsxs("div",{className:"fk:flex fk:h-full fk:min-h-0 fk:flex-col fk:gap-2",children:[jsxs("div",{className:"fk:mb-4 fk:flex fk:shrink-0 fk:items-start fk:gap-2",children:[jsxs(b$3,{children:[jsx(c,{asChild:true,children:jsx(N,{className:"fk:-ml-1 fk:h-4 fk:w-4"})}),jsx(e$1,{children:"Toggle Sidebar"})]}),jsx(v,{orientation:"vertical",className:"fk:mt-1 fk:h-4"}),jsx("div",{className:"fk:flex-1",children:jsx("h1",{className:"fk:text-lg fk:font-semibold fk:leading-none fk:tracking-tight",children:d?.automation.name??"Automation"})})]}),jsxs("div",{className:"fk:flex fk:shrink-0 fk:flex-wrap fk:items-start fk:justify-between fk:gap-3 fk:pr-4",children:[jsxs("div",{children:[jsx(b$2,{asChild:true,size:"sm",variant:"ghost",children:jsxs(Link,{relative:"path",to:"..",children:[jsx(ArrowLeft,{className:"fk:mr-2 fk:size-4"}),"Runs"]})}),jsxs("div",{className:"fk:mt-4 fk:flex fk:flex-wrap fk:items-center fk:gap-2",children:[jsx("h2",{className:"fk:text-sm fk:font-medium",children:C?`Run from ${format(new Date(C.startedAt),"PPpp")}`:"Loading run..."}),C?jsx(ta,{status:C.status}):null]})]}),jsxs("div",{className:"fk:flex fk:items-center fk:gap-2",children:[C&&v$1(C.status)?jsx(b$2,{asChild:true,size:"sm",variant:"outline",children:jsx("a",{href:T.getTranscriptUrl(I),rel:"noreferrer",target:"_blank",children:"Transcript"})}):null,$?jsx(b$2,{disabled:k,size:"sm",variant:"destructive",onClick:A,children:k?"Cancelling...":"Cancel run"}):null]})]}),jsxs(_a,{className:"fk:h-0 fk:min-h-0 fk:flex-1",children:[jsx($a$1,{className:"fk:gap-0 fk:p-0",children:jsx("div",{className:"fk:mx-auto fk:w-full fk:max-w-5xl fk:pb-6 fk:pr-4",children:C?jsx(Js,{api:t,run:C,onRunUpdated:h,onStreamFinished:y}):jsx(J,{children:"Loading run..."})})}),jsx(bb,{})]})]})}function Os(t){return t==="unavailable"?"No replay events were recorded.":t==="error"?"Unable to load run replay.":"Loading run replay..."}function Js({api:t,onRunUpdated:n,onStreamFinished:o,run:i$1}){let{projectId:l}=q(),{workflowRunId:g$1}=i$1,d=g$1?t.getStreamUrl(g$1):"",[k,r$1]=useState(0),[m,u$1]=useState(false),[T,I]=useState([]),[C,$]=useState({}),A$1=useRef(null),{message:y,status:h}=w$1(d,{decidedApprovals:C,recordStatus:i$1.status,resumeToken:k,suppressApprovalPause:m}),R=useMemo(()=>y?[y]:[],[y]),F=u(R),w=useRef(n);w.current=n;let S=useRef(o);S.current=o;let E=useMemo(()=>({onApprovalDecided:(D,b)=>{D&&b&&b!=="pending"&&$(j=>({...j,[D]:b})),!(D&&A$1.current===D)&&(D&&(A$1.current=D),u$1(true),r$1(j=>j+1),w.current?.());}}),[]),M=!m&&i$1.status!=="running"&&!v$1(i$1.status)&&(h==="paused"||i$1.status==="awaiting_approval"||g$2(y)),_=a(),x$1=v$1(i$1.status);useEffect(()=>{(M||x$1)&&_();},[M,_,x$1]);let X=g$2(y),W=M&&!X&&l!=null,{data:me}=De(W&&l?g(l).approvals({limit:25,offset:0,runId:i$1.id,status:"pending"}):null,f,{refreshInterval:r}),G=useMemo(()=>new Set(h$1(y)),[y]),he=T.filter(D=>!G.has(D.id)),Fe=!v$1(i$1.status)&&(h==="streaming"||h==="paused"),Ie=F.length>0||he.length>0||Fe;if(useEffect(()=>{r$1(0),u$1(false),A$1.current=null,I([]),$({});},[i$1.id]),useEffect(()=>{let D=me?.approvals;D?.length&&I(b=>{let j=new Map(b.map(ue=>[ue.id,ue]));for(let ue of D)j.set(ue.id,ue);return [...j.values()]});},[me]),useEffect(()=>{I(D=>{if(D.length===0)return D;let b=D.filter(j=>!G.has(j.id));return b.length===D.length?D:b});},[G]),useEffect(()=>{if(!m)return;if(i$1.status==="running"){u$1(false);return}if(i$1.status!=="awaiting_approval")return;let D=i(y),b=A$1.current;D.length===0||b===null||D.every(j=>j!==b)&&u$1(false);},[y,i$1.status,m]),useEffect(()=>{h==="finished"&&S.current?.();},[h]),useEffect(()=>{h==="paused"&&w.current?.();},[h]),useEffect(()=>{if(i$1.status!=="awaiting_approval")return;let D=window.setInterval(()=>{w.current?.();},r);return ()=>{window.clearInterval(D);}},[i$1.status]),!g$1)return jsx(J,{children:"The run has not started streaming yet."});let Le=Fe||M&&h!=="finished"&&h!=="error",be=y?.parts[y.parts.length-1],ie=be?.type==="text"&&be.state==="streaming",Pe=M?"Awaiting approval":f$3(y)??"Thinking",Je=M||!ie,Ke=Os(h);return jsx(s.Provider,{value:E,children:jsxs("div",{className:"fk:space-y-4",children:[i$1.status==="failed"&&i$1.error?jsx("div",{className:"fk:rounded-md fk:border fk:border-destructive/30 fk:bg-destructive/5 fk:p-4 fk:text-sm fk:corner-squircle",children:i$1.summary??i$1.error}):null,h==="unavailable"?jsx("div",{className:"fk:rounded-md fk:border fk:border-amber-500/30 fk:bg-amber-500/5 fk:p-4 fk:text-sm fk:corner-squircle",children:"The workflow replay is no longer available. Generated artifacts may still be available below."}):null,h==="error"&&!Ie?jsx("div",{className:"fk:rounded-md fk:border fk:border-destructive/30 fk:bg-destructive/5 fk:p-4 fk:text-sm fk:corner-squircle",children:"Failed to load the run stream. Try reloading the page."}):null,Ie?jsxs("div",{className:"fk:space-y-5 fk:rounded-md fk:bg-background fk:corner-squircle",children:[F.map(D=>jsx(Ks,{api:t,message:D},D.id)),he.map(D=>jsx(B,{api:t,message:x(D)},D.id)),Le?jsx(A,{label:Pe,visible:Je}):null]}):jsxs("div",{className:"fk:flex fk:items-center fk:justify-center fk:gap-2 fk:rounded-md fk:border fk:border-dashed fk:p-8 fk:font-mono fk:text-sm fk:text-muted-foreground fk:corner-squircle",children:[h==="unavailable"||h==="error"?jsx(TriangleAlertIcon,{className:"fk:size-4"}):jsx(LoaderCircle,{className:"fk:size-4 fk:animate-spin"}),jsx("span",{children:Ke})]})]})})}function Ks({api:t,message:n}){let o=n.role==="user",i=n.parts.filter(l=>!e$3(l));return i.length===0?null:jsxs("div",{className:o?"fk:ml-auto fk:w-full fk:max-w-[70%]":"fk:w-full fk:min-w-0",children:[jsx("div",{className:"fk:mb-2 fk:flex fk:items-center fk:gap-2 fk:font-mono fk:text-sm fk:font-medium fk:text-primary",children:o?jsxs(Fragment,{children:[jsx(ZapIcon,{className:"fk:ml-auto fk:size-4"}),jsx("span",{children:"Trigger"})]}):jsxs(Fragment,{children:[jsx(BotIcon,{className:"fk:size-4"}),jsxs("span",{children:["Agent",n.metadata?.model?` (${n.metadata.model})`:""]})]})}),jsx("div",{className:"fk:space-y-8 fk:min-w-0",children:i.map((l,g)=>jsx(y,{api:t,part:l,partIndex:g,parts:i},g))})]})}
|
|
2
|
-
export{tl as ActivityItemPage,el as ActivityPage,Qi as ApprovalsPage,Gi as AutomationDetailPage,Ki as AutomationsPage,Wi as CreateAutomationPage,nl as RunDetailPage,Yi as RunHistoryPage,Zi as RunsPage};//# sourceMappingURL=pages-ZKDDV5T3.js.map
|
|
3
|
-
//# sourceMappingURL=pages-ZKDDV5T3.js.map
|