@flexkit/studio 0.2.10 → 0.2.11

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.
Files changed (60) hide show
  1. package/dist/activity-nav-button-LZESIQL2.js +2 -0
  2. package/dist/{activity-nav-button-EP6GYASE.js.map → activity-nav-button-LZESIQL2.js.map} +1 -1
  3. package/dist/chat-page-3YSJP7FC.js +4 -0
  4. package/dist/chat-page-3YSJP7FC.js.map +1 -0
  5. package/dist/{chunk-6SAZGEAA.js → chunk-22DXYOXX.js} +2 -2
  6. package/dist/{chunk-6SAZGEAA.js.map → chunk-22DXYOXX.js.map} +1 -1
  7. package/dist/chunk-2HSIWUH3.js +3 -0
  8. package/dist/chunk-2HSIWUH3.js.map +1 -0
  9. package/dist/chunk-7JSGAY3E.js +2 -0
  10. package/dist/chunk-7JSGAY3E.js.map +1 -0
  11. package/dist/chunk-B4WSTNZ3.js +8 -0
  12. package/dist/chunk-B4WSTNZ3.js.map +1 -0
  13. package/dist/{chunk-YLZV43AR.js → chunk-GDTOP4MU.js} +3 -3
  14. package/dist/{chunk-YLZV43AR.js.map → chunk-GDTOP4MU.js.map} +1 -1
  15. package/dist/{chunk-WQUCLXMU.js → chunk-HYSTMQD7.js} +2 -2
  16. package/dist/{chunk-WQUCLXMU.js.map → chunk-HYSTMQD7.js.map} +1 -1
  17. package/dist/chunk-KXAGLQ2B.js +2 -0
  18. package/dist/chunk-KXAGLQ2B.js.map +1 -0
  19. package/dist/{chunk-IPLOSXZS.js → chunk-OI6GA6PE.js} +3 -3
  20. package/dist/{chunk-IPLOSXZS.js.map → chunk-OI6GA6PE.js.map} +1 -1
  21. package/dist/{chunk-SV5KK5K6.js → chunk-TPLL535V.js} +3 -3
  22. package/dist/{chunk-SV5KK5K6.js.map → chunk-TPLL535V.js.map} +1 -1
  23. package/dist/{chunk-AMEYKXZV.js → chunk-YODWX4WT.js} +2 -2
  24. package/dist/{chunk-AMEYKXZV.js.map → chunk-YODWX4WT.js.map} +1 -1
  25. package/dist/{chunk-RXP6EQNE.js → chunk-YSMRXGVX.js} +2 -2
  26. package/dist/{chunk-RXP6EQNE.js.map → chunk-YSMRXGVX.js.map} +1 -1
  27. package/dist/index.css +13 -0
  28. package/dist/index.js +1 -1
  29. package/dist/{list-AJ76FKMO.js → list-N5WCJSJC.js} +2 -2
  30. package/dist/{list-AJ76FKMO.js.map → list-N5WCJSJC.js.map} +1 -1
  31. package/dist/pages-65QNO7ME.js +5 -0
  32. package/dist/{pages-LZKWC2H3.js.map → pages-65QNO7ME.js.map} +1 -1
  33. package/dist/plugin-pages-F5K745MZ.js +2 -0
  34. package/dist/{plugin-pages-YJFH66UO.js.map → plugin-pages-F5K745MZ.js.map} +1 -1
  35. package/dist/{root-GD6WNTP5.js → root-4E3YUTQU.js} +3 -3
  36. package/dist/{root-GD6WNTP5.js.map → root-4E3YUTQU.js.map} +1 -1
  37. package/dist/root-DK5C7DYH.js +2 -0
  38. package/dist/{root-VJPSB2DG.js.map → root-DK5C7DYH.js.map} +1 -1
  39. package/dist/{root-2UU3C6EP.js → root-MMAJEVBH.js} +3 -3
  40. package/dist/{root-2UU3C6EP.js.map → root-MMAJEVBH.js.map} +1 -1
  41. package/dist/{root-APTYXHHX.js → root-WYRLSQPK.js} +2 -2
  42. package/dist/{root-APTYXHHX.js.map → root-WYRLSQPK.js.map} +1 -1
  43. package/dist/{search-5X4N4M3X.js → search-EK4XBDGL.js} +2 -2
  44. package/dist/{search-5X4N4M3X.js.map → search-EK4XBDGL.js.map} +1 -1
  45. package/dist/skills-pages-O35YZMMC.js +2 -0
  46. package/dist/{skills-pages-V4BILOOI.js.map → skills-pages-O35YZMMC.js.map} +1 -1
  47. package/package.json +3 -3
  48. package/dist/activity-nav-button-EP6GYASE.js +0 -2
  49. package/dist/chat-page-N2PGTH56.js +0 -4
  50. package/dist/chat-page-N2PGTH56.js.map +0 -1
  51. package/dist/chunk-HZJNNJOK.js +0 -2
  52. package/dist/chunk-HZJNNJOK.js.map +0 -1
  53. package/dist/chunk-L66FPBO7.js +0 -8
  54. package/dist/chunk-L66FPBO7.js.map +0 -1
  55. package/dist/chunk-ROCYIGFD.js +0 -3
  56. package/dist/chunk-ROCYIGFD.js.map +0 -1
  57. package/dist/pages-LZKWC2H3.js +0 -5
  58. package/dist/plugin-pages-YJFH66UO.js +0 -2
  59. package/dist/root-VJPSB2DG.js +0 -2
  60. package/dist/skills-pages-V4BILOOI.js +0 -2
@@ -1,3 +0,0 @@
1
- import'./index.css';import {put}from'@vercel/blob/client';function S(s,o){let l=o.trim();return l?s.trim()?/\s$/.test(s)||/^[.,!?;:]/.test(l)?`${s}${l}`:`${s} ${l}`:s.length===0?l:`${s}${l}`:s}async function h(s){if(typeof window>"u")throw new Error("Dictation is only available in the browser.");let o=window.AudioContext??window.webkitAudioContext;if(!o)throw new Error("This browser cannot decode recorded audio.");let l=await s.arrayBuffer(),u=new o;try{let n=await u.decodeAudioData(l.slice(0)),i=C(n),t=y(i,n.sampleRate,24e3),e=$(t),a=t.length/24e3;if(a<.25)throw new Error("No speech was captured. Try again.");if(a>60)throw new Error(`Dictation is limited to ${String(60)} seconds.`);return {durationSeconds:a,pcm:new Blob([e],{type:"audio/pcm"})}}finally{await u.close();}}function C(s){let{length:o,numberOfChannels:l}=s;if(l===1)return s.getChannelData(0).slice();let u=new Float32Array(o);for(let n=0;n<o;n+=1){let i=0;for(let t=0;t<l;t+=1)i+=s.getChannelData(t)[n]??0;u[n]=i/l;}return u}function y(s,o,l){if(o===l)return s;let u=o/l,n=Math.max(1,Math.round(s.length/u)),i=new Float32Array(n);for(let t=0;t<n;t+=1){let e=t*u,a=Math.floor(e),r=Math.min(a+1,s.length-1),c=e-a,g=s[a]??0,m=s[r]??0;i[t]=g+(m-g)*c;}return i}function $(s){let o=new ArrayBuffer(s.length*2),l=new DataView(o);for(let u=0;u<s.length;u+=1){let n=Math.max(-1,Math.min(1,s[u]??0));l.setInt16(u*2,n<0?n*32768:n*32767,true);}return o}var d=class extends Error{code;status;constructor(o,l,u=null){super(l),this.name="AgentUploadError",this.code=u,this.status=o;}};function f(){if(typeof window>"u")return "flexkit.io";let{hostname:s}=window.location;return s==="localhost"||s==="127.0.0.1"||s==="flexkit.test"||s.endsWith(".flexkit.test")?"flexkit.test":"flexkit.io"}function T(){return `https://${f()}`}function _(s,o){return `https://${s}.api.${f()}/automations/webhook/${encodeURIComponent(o)}`}function w(s){let o=`/api/flexkit/${s}`,l=`${o}/automations`,u=`${o}/skills`,n=`${o}/agent/chats`;async function i(t,e){let a=await fetch(t,{credentials:"include",headers:{"Content-Type":"application/json",...e?.headers??{}},...e}),r=await a.json();if(!a.ok){let c=r&&typeof r=="object"&&"error"in r?String(r.error):"Request failed";throw new Error(c)}return r}return {connectPlugins:t=>i(`${o}/plugins/connect`,{method:"POST",body:JSON.stringify(t)}),pluginOAuthStatus:t=>i(`${o}/plugins/oauth-transactions/${encodeURIComponent(t)}`),updatePluginConnection:(t,e)=>i(`${o}/plugin-connections/${encodeURIComponent(t)}`,{method:"PATCH",body:JSON.stringify(e)}),disconnectPlugin:t=>i(`${o}/plugin-connections/${encodeURIComponent(t)}`,{method:"DELETE"}),installPlugin:t=>i(`${o}/plugins/${encodeURIComponent(t)}/installation`,{method:"PUT",body:JSON.stringify({})}),setPluginPolicy:(t,e)=>i(`${o}/plugins/${encodeURIComponent(t)}/policy`,{method:"PATCH",body:JSON.stringify(e)}),refreshPluginTools:t=>i(`${o}/plugin-connections/${encodeURIComponent(t)}/tools/refresh`,{method:"POST"}),cancelRun:async t=>i(`${l}/runs/${encodeURIComponent(t)}/cancel`,{method:"POST"}),createAgentChat:async t=>i(n,{body:JSON.stringify({modelId:t?.modelId??null}),method:"POST"}),deleteAgentChat:async t=>i(`${n}/${encodeURIComponent(t)}`,{method:"DELETE"}),getAgentChatStreamUrl:(t,e)=>`${n}/${encodeURIComponent(t)}/stream?workflowRunId=${encodeURIComponent(e)}`,renameAgentChat:async(t,e)=>i(`${n}/${encodeURIComponent(t)}`,{body:JSON.stringify({title:e}),method:"PATCH"}),sendAgentChatMessage:async(t,e)=>i(`${n}/${encodeURIComponent(t)}/messages`,{body:JSON.stringify(e),method:"POST"}),sendAgentChatFollowUp:async(t,e)=>i(`${n}/${encodeURIComponent(t)}/follow-ups`,{body:JSON.stringify(e),method:"POST"}),answerAgentChatQuestion:async(t,e,a)=>{let r=await fetch(`${n}/${encodeURIComponent(t)}/questions/${encodeURIComponent(e)}/answer`,{body:JSON.stringify(a),credentials:"include",headers:{"Content-Type":"application/json"},method:"POST"}),c=await r.json();if(!r.ok&&!c.question)throw new Error(c.errorMessage??c.error??"Request failed");return {errorMessage:r.ok?void 0:c.errorMessage,question:c.question}},startAgentChat:async({attachments:t,content:e,modelId:a})=>i(n,{body:JSON.stringify({message:{attachments:t,content:e},modelId:a??null}),method:"POST"}),startQueuedAgentChatMessage:async(t,e)=>i(`${n}/${encodeURIComponent(t)}/follow-ups/${encodeURIComponent(e)}/start`,{method:"POST"}),stopAgentChat:async t=>i(`${n}/${encodeURIComponent(t)}/stop`,{method:"POST"}),stopAgentChatMonitor:async(t,e)=>i(`${n}/${encodeURIComponent(t)}/monitors/${encodeURIComponent(e)}/stop`,{method:"POST"}),transcribeAgentAudio:async(t,e)=>{let{durationSeconds:a,pcm:r}=await h(t),c=new FormData;c.append("file",r,"audio.pcm"),c.append("durationSeconds",String(a));let g=await fetch(`${o}/agent/transcribe`,{body:c,credentials:"include",method:"POST",signal:e}),m=await g.json();if(!g.ok){let A=m&&typeof m=="object"&&m.error?String(m.error):"Request failed";throw new Error(A)}if(!m.text?.trim())throw new Error("No speech was recognized. Try again.");return {text:m.text}},uploadAgentChatAttachment:async(t,e)=>{let a=await fetch(`${o}/agent/uploads`,{body:JSON.stringify({filename:t.name,mediaType:t.type||null,sizeBytes:t.size}),credentials:"include",headers:{"Content-Type":"application/json"},method:"POST",signal:e}),r=await a.json();if(!a.ok||!r.pathname||!r.token||!r.mediaType)throw new d(a.status,r.error?String(r.error):"The file could not be uploaded.",r.code??null);let c=await put(r.pathname,t,{abortSignal:e,access:"public",contentType:r.mediaType,token:r.token});return {filename:t.name,mediaType:r.mediaType,sizeBytes:t.size,url:c.url}},decideApproval:async(t,e)=>{let a=await fetch(`${l}/approvals/${encodeURIComponent(t)}/decide`,{body:JSON.stringify(e),credentials:"include",headers:{"Content-Type":"application/json"},method:"POST"}),r=await a.json();if(!a.ok&&typeof r.success!="boolean")throw new Error(r.error?String(r.error):"Request failed");return r},markActivityRead:async t=>i(`${o}/activity/read`,{body:JSON.stringify(t==="all"?{all:true}:{ids:t}),method:"POST"}),setActivityItemState:async(t,e)=>i(`${o}/activity/${encodeURIComponent(t)}`,{body:JSON.stringify({state:e}),method:"PATCH"}),createAutomation:async t=>i(l,{body:JSON.stringify(t),method:"POST"}),createSkill:async t=>i(u,{body:JSON.stringify(t),method:"POST"}),deleteAutomation:async t=>i(`${l}/${encodeURIComponent(t)}`,{method:"DELETE"}),deleteSkill:async t=>i(`${u}/${encodeURIComponent(t)}`,{method:"DELETE"}),getArtifactUrl:(t,e)=>{let a=e?.download?"?download=1":"";return `${l}/artifacts/${encodeURIComponent(t)}/content${a}`},getRunArtifacts:async t=>i(`${l}/runs/${encodeURIComponent(t)}/artifacts`).then(e=>e.artifacts),getStreamUrl:t=>`${l}/runs/${encodeURIComponent(t)}/stream`,getTranscriptUrl:t=>`${l}/runs/${encodeURIComponent(t)}/transcript`,listChannels:async(t,e)=>{let a=e?`${o}/plugin-connections/${encodeURIComponent(e)}/channels`:`${o}/plugins/${t}/channels`,r=await fetch(a,{credentials:"include",headers:{"Content-Type":"application/json"}}),c=await r.json();if(r.ok)return {channels:c.channels??[],errorMessage:c.errorMessage,success:c.success??true};if(c.success===false)return {channels:c.channels??[],errorMessage:c.errorMessage??`Failed to load ${t==="slack"?"Slack":"Teams"} channels.`,success:false};let g=c.error?String(c.error):"Request failed";throw new Error(g)},runAutomation:async t=>i(`${l}/${encodeURIComponent(t)}/runs`,{method:"POST"}),updateAutomation:async(t,e)=>i(`${l}/${encodeURIComponent(t)}`,{body:JSON.stringify(e),method:"PATCH"}),updateSkill:async(t,e)=>i(`${u}/${encodeURIComponent(t)}`,{body:JSON.stringify(e),method:"PATCH"})}}var p=class extends Error{status;constructor(o,l="Request failed"){super(l),this.name="FetcherError",this.status=o;}},k=async s=>{let o=await fetch(s,{credentials:"include"});if(!o.ok)throw new p(o.status);return await o.json()};function U(s){let o=`/api/flexkit/${s}/automations`,l=`/api/flexkit/${s}/skills`,u=`/api/flexkit/${s}/agent/chats`;return {activity:(n={})=>{let{filter:i="all",limit:t=25,offset:e=0}=n,a=new URLSearchParams({filter:i,limit:t.toString(),offset:e.toString()});return `/api/flexkit/${s}/activity?${a.toString()}`},activityItem:n=>`/api/flexkit/${s}/activity/${encodeURIComponent(n)}`,activitySummary:n=>n?`/api/flexkit/${s}/activity/summary?since=${encodeURIComponent(n)}`:`/api/flexkit/${s}/activity/summary`,agentChat:n=>`${u}/${encodeURIComponent(n)}`,agentChatSearch:n=>`${u}/search?q=${encodeURIComponent(n)}`,agentChats:(n=0)=>`${u}?offset=${n.toString()}`,agentProfile:()=>`/api/flexkit/${s}/agent/profile`,approval:n=>`${o}/approvals/${encodeURIComponent(n)}`,approvals:(n={})=>{let{limit:i=25,offset:t=0,runId:e,status:a}=n,r=new URLSearchParams({limit:i.toString(),offset:t.toString()});return a&&r.set("status",a),e&&r.set("runId",e),`${o}/approvals?${r.toString()}`},approvalsCount:`${o}/approvals?limit=1`,automation:n=>`${o}/${encodeURIComponent(n)}`,automationRuns:(n,i=0,t=25)=>`${o}/${encodeURIComponent(n)}/runs?offset=${i.toString()}&limit=${t.toString()}`,automations:(n={})=>{let{enabled:i,limit:t=25,offset:e=0,search:a,visibility:r}=n,c=new URLSearchParams({limit:t.toString(),offset:e.toString()});i&&i.length>0&&c.set("enabled",i.map(m=>m?"true":"false").join(",")),r&&r.length>0&&c.set("visibility",r.join(","));let g=a?.trim();return g&&c.set("q",g),`${o}?${c.toString()}`},creditBalance:`${o}/credits`,entities:`${o}/entities`,run:n=>`${o}/runs/${encodeURIComponent(n)}`,runHistory:(n,i=0,t=25)=>`${o}/runs?scope=${n}&offset=${i.toString()}&limit=${t.toString()}`,skill:n=>`${l}/${encodeURIComponent(n)}`,skills:(n={})=>{let{limit:i=25,offset:t=0,search:e,visibility:a}=n,r=new URLSearchParams({limit:i.toString(),offset:t.toString()});a&&a.length>0&&r.set("visibility",a.join(","));let c=e?.trim();return c&&r.set("q",c),`${l}?${r.toString()}`},spaces:`/api/flexkit/${s}/spaces`,members:n=>n?`/api/flexkit/${s}/members?spaceId=${encodeURIComponent(n)}`:`/api/flexkit/${s}/members`,tools:n=>n?`${o}/${encodeURIComponent(n)}/tools`:`${o}/tools`}}
2
- export{S as a,T as b,_ as c,w as d,p as e,k as f,U as g};//# sourceMappingURL=chunk-ROCYIGFD.js.map
3
- //# sourceMappingURL=chunk-ROCYIGFD.js.map
@@ -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","questionId","result","attachments","content","modelId","messageId","monitorId","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","spaceId"],"mappings":"0DAIO,SAAS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AQ,IAAA,EAAK,CAEnC,OAAIG,CAAAA,EACFP,CAAAA,CAAO,GAAA,CAAI,GAAA,CAAKO,CAAa,CAAA,CAGxB,CAAA,EAAGrD,CAAc,CAAA,CAAA,EAAI8C,CAAAA,CAAO,QAAA,EAAU,CAAA,CAC/C,CAAA,CACA,MAAA,CAAQ,CAAA,aAAA,EAAgBnD,CAAS,CAAA,OAAA,CAAA,CACjC,OAAA,CAAU4D,CAAAA,EACRA,CAAAA,CACI,CAAA,aAAA,EAAgB5D,CAAS,CAAA,iBAAA,EAAoB,kBAAA,CAAmB4D,CAAO,CAAC,CAAA,CAAA,CACxE,CAAA,aAAA,EAAgB5D,CAAS,CAAA,QAAA,CAAA,CAC/B,KAAA,CAAQqC,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-ROCYIGFD.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 AgentChatMonitor,\n AgentChatQuestion,\n AgentChatQuestionResponse,\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 /** For a proposed automation: the approver's edited instructions and whether to run it once now. */\n automationEdits?: { instructions?: string; runOnce?: 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 /** Answers (or dismisses) the questions a chat turn waits on; a settled question comes back with an error. */\n answerAgentChatQuestion: (\n _chatId: string,\n _questionId: string,\n _response: AgentChatQuestionResponse\n ) => Promise<{ errorMessage?: string; question?: AgentChatQuestion }>;\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 stopAgentChatMonitor: (_chatId: string, _monitorId: string) => Promise<{ monitor: AgentChatMonitor }>;\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 answerAgentChatQuestion: async (chatId, questionId, response) => {\n const result = await fetch(\n `${agentChatsBasePath}/${encodeURIComponent(chatId)}/questions/${encodeURIComponent(questionId)}/answer`,\n {\n body: JSON.stringify(response),\n credentials: 'include',\n headers: { 'Content-Type': 'application/json' },\n method: 'POST',\n }\n );\n const data = (await result.json()) as { errorMessage?: string; error?: string; question?: AgentChatQuestion };\n\n // A question settled elsewhere (409) comes back with its final state for the card to show.\n if (!result.ok && !data.question) {\n throw new Error(data.errorMessage ?? data.error ?? 'Request failed');\n }\n\n return { errorMessage: result.ok ? undefined : data.errorMessage, question: data.question };\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 stopAgentChatMonitor: async (chatId, monitorId) =>\n request<{ monitor: AgentChatMonitor }>(\n `${agentChatsBasePath}/${encodeURIComponent(chatId)}/monitors/${encodeURIComponent(monitorId)}/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 /** Members for pickers; with a space id, only members who can see that space. */\n members: (_spaceId?: string | null) => 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 members: (spaceId) =>\n spaceId\n ? `/api/flexkit/${projectId}/members?spaceId=${encodeURIComponent(spaceId)}`\n : `/api/flexkit/${projectId}/members`,\n tools: (automationId) =>\n automationId ? `${basePath}/${encodeURIComponent(automationId)}/tools` : `${basePath}/tools`,\n };\n}\n"]}
@@ -1,5 +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$4}from'./chunk-CSUHZFEP.js';import {u,a,b as b$4,d,c as c$2,v as v$1,z,A,y,g as g$3,h as h$1,i,f as f$3,w as w$1,F,B,E,e as e$3,C}from'./chunk-L66FPBO7.js';import {a as a$3,b as b$7}from'./chunk-HZJNNJOK.js';import {b as b$5,e as e$2,c as c$1,d as d$1,g as g$2,f as f$2,i as i$1,k,j as j$1}from'./chunk-ACS3TGGP.js';import {f,g,e as e$7,c as c$5,d as d$4}from'./chunk-ROCYIGFD.js';import {a as a$1}from'./chunk-3C2EG3SI.js';import {b}from'./chunk-V64P56OA.js';import {f as f$5}from'./chunk-SV5KK5K6.js';import {h as h$2}from'./chunk-TYDYAOQ7.js';import {_,$,ca,da as da$1,aa as aa$1,ea as ea$1,N,f as f$1,ma as ma$1,ga as ga$1,ha,ia,_a,$a,bb,oa as oa$1,s,e as e$5,Z as Z$1,ka as ka$1,t as t$1,u as u$1,v as v$2}from'./chunk-YCCFUGWJ.js';import {b as b$1,v,w,x,m,o as o$1,p,q as q$1,r as r$1,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$5}from'./chunk-HDOIOXMP.js';import {e,g as g$1,h,j,o,t,q,r,s as s$1,k as k$1}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,useId}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,Settings2Icon,BellIcon,ClockIcon,WebhookIcon,DatabaseZapIcon,CircleCheckBigIcon,RefreshCwIcon,PlusIcon,ChevronDownIcon,LockIcon,CheckIcon,ChevronsUpDownIcon,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 It from'swr/infinite';import {jsx,jsxs,Fragment}from'react/jsx-runtime';import {CronExpressionParser}from'cron-parser';var qa=[{kind:"approval_request",label:"Approval requests"},{kind:"automation_failure",label:"Automation failures"},{kind:"automation_result",label:"Automation results"},{kind:"monitor_event",label:"Chat monitors"},{kind:"question",label:"Agent questions"}];function Bo({checked:t,disabled:n,label:o,onCheckedChange:i}){let l=useId();return jsxs("div",{className:"fk:flex fk:items-center fk:justify-between fk:gap-3",children:[jsx("label",{className:"fk:text-sm",htmlFor:l,children:o}),jsx(Z$1,{checked:t,disabled:n,id:l,onCheckedChange:i})]})}function jo(){let{mode:t}=f$5(),{isLoaded:n,mutate:o,preferences:i}=i$1(),[l,k]=useState(false);async function f(c){k(true);try{await o(j$1(c),{optimisticData:{preferences:c},rollbackOnError:!0});}catch{oa$1.error("Unable to save your notification settings.");}finally{k(false);}}function g(c,p){let d=new Set(i.desktopMutedKinds);p?d.delete(c):d.add(c),f({...i,desktopMutedKinds:[...d]});}return jsxs(t$1,{children:[jsx(u$1,{asChild:true,children:jsx(b$2,{"aria-label":"Notification settings",className:"fk:ml-auto",size:"icon",variant:"ghost",children:jsx(Settings2Icon,{className:"fk:size-4"})})}),jsxs(v$2,{align:"end",className:"fk:w-80 fk:space-y-4",children:[jsxs("div",{className:"fk:space-y-2",children:[jsx("p",{className:"fk:text-sm fk:font-medium",children:"Desktop notifications"}),jsxs("p",{className:"fk:text-xs fk:text-muted-foreground",children:[t==="hosted"?"Shown while Studio is in the background, and while your browser runs with no Studio tab open.":"Shown while Studio is open in the background."," ","Activity always keeps every item."]}),qa.map(({kind:c,label:p})=>jsx(Bo,{checked:!i.desktopMutedKinds.includes(c),disabled:l||!n,label:p,onCheckedChange:d=>g(c,d)},c))]}),jsxs("div",{className:"fk:space-y-2",children:[jsx("p",{className:"fk:text-sm fk:font-medium",children:"Email"}),jsx(Bo,{checked:i.approvalEmail,disabled:l||!n,label:"Approval requests I haven\u2019t read",onCheckedChange:c=>{f({...i,approvalEmail:c});}})]}),jsx("p",{className:"fk:text-xs fk:text-muted-foreground",children:"These settings apply to every project you open."})]})]})}var Wa=[{label:"Enabled",value:"enabled"},{label:"Disabled",value:"disabled"}],Ga=[{label:"Project",value:"project"},{label:"Space",value:"space"},{label:"Personal",value:"personal"}];function Za(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 Oo({actions:t,isSearchLoading:n=false,onSearchChange:o,search:i,searchPlaceholder:l="Search automations...",table:k}){let f=k.getState().columnFilters.length>0||i.trim().length>0,g=k.getAllColumns().find(P=>P.id==="status"),c=k.getAllColumns().find(P=>P.id==="visibility"),[p,d]=useState(i),v=p.trim(),C=i.trim(),T=v.length>0&&(n||v!==C),j=useRef(o);j.current=o;let A=useMemo(()=>Za(P=>{j.current(P);},300),[]);useEffect(()=>{d(i);},[i]),useEffect(()=>()=>{A.cancel();},[A]);function x$1(){A.cancel(),d(""),o("");}function b(){k.resetColumnFilters(),x$1();}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:[T?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,{className:"fk:h-8 fk:w-37.5 fk:lg:w-70 fk:px-7 fk:text-sm",name:"search-automations",placeholder:l,value:p,onChange:P=>{let{value:F}=P.target;if(d(F),F.trim().length===0){A.cancel(),o("");return}A(F.trim());}}),p?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:x$1,type:"button",children:jsx(X,{className:"fk:h-4 fk:w-4"})}):null]}),g?jsx(a$1,{column:g,options:Wa,title:"Status"}):null,c?jsx(a$1,{column:c,options:Ga,title:"Visibility"}):null,f?jsxs(b$2,{className:"fk:h-8 fk:px-2 fk:lg:px-3",onClick:b,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,{orientation:"horizontal"})]})})}function Sn(t,n,o){return (o??[]).some(i=>i.toLowerCase().includes(n.trim().toLowerCase()))?1:0}function Kt({disabled:t,emptyText:n,footer:o,items:i,searchPlaceholder:l,triggerLabel:k="Attach",onToggle:f}){let[g,c]=useState(false),p$1=useRef(null);return jsxs(t$1,{open:g,onOpenChange:c,children:[jsx(u$1,{asChild:true,children:jsxs(b$2,{disabled:t,size:"sm",type:"button",variant:"outline",children:[k,jsx(ChevronDownIcon,{className:"fk:ml-1 fk:size-4"})]})}),jsx(v$2,{align:"end",className:"fk:w-72 fk:p-0",onOpenAutoFocus:d=>{d.preventDefault(),p$1.current?.focus({preventScroll:true});},children:jsxs(m,{filter:Sn,children:[jsx(o$1,{placeholder:l,ref:p$1}),jsxs(p,{className:"fk:max-h-72",children:[jsx(q$1,{children:n}),jsx(r$1,{children:i.map(d=>jsxs(t$2,{disabled:!!d.lockedHint,title:d.lockedHint,value:d.id,keywords:[d.label],onSelect:()=>f(d.id,!d.attached),children:[d.lockedHint?jsx(LockIcon,{className:"fk:size-4"}):jsx(CheckIcon,{className:d.attached?"fk:size-4":"fk:size-4 fk:opacity-0"}),jsx("span",{className:"fk:truncate",children:d.label}),d.badge?jsx(b$1,{className:"fk:ml-auto fk:py-0 fk:text-[10px]",variant:"secondary",children:d.badge}):null]},d.id))})]}),o]})})]})}function Jo(t){return t==="project"?"Project":"Personal"}function Tt(t,n){return t.connections.filter(o=>o.scope===n&&o.status==="connected")}function In(t,n){if(!n)return null;let o=Tt(t,n.connectionMode);return n.connectionId?o.find(i=>i.id===n.connectionId)??null:o.find(i=>i.isPrimary)??null}function Nt(t){return t?t.connectionId?`account:${t.connectionId}`:`primary:${t.connectionMode}`:""}function Pn({ariaLabel:t,disabled:n,plugin:o,scopes:i,value:l,onChange:k}){let f=[];for(let c of i){let p=Tt(o,c),d=p.find(C=>C.isPrimary),[v]=p;if(p.length===1&&v){let C=l?.connectionMode===c&&l.connectionId===v.id;f.push({choice:{connectionMode:c,connectionId:C||!v.isPrimary?v.id:null},label:`${Jo(c)} \xB7 ${v.displayName}`});continue}d&&f.push({choice:{connectionMode:c,connectionId:null},label:`Primary ${c} account (${d.displayName})`});for(let C of p)f.push({choice:{connectionMode:c,connectionId:C.id},label:`${Jo(c)} \xB7 ${C.displayName}`});}let g=Nt(l);return jsxs(a$2,{disabled:n,value:f.some(c=>Nt(c.choice)===g)?g:"",onValueChange:c=>{let p=f.find(d=>Nt(d.choice)===c);p&&k(p.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:f.map(c=>jsx(g$5,{value:Nt(c.choice),children:c.label},Nt(c.choice)))})]})}var wn=2;function Xo(t){return t.scopes.filter(n=>n==="project"||t.allowPersonal)}function rs(t){let n=Xo(t),o=n.includes("personal")&&(!n.includes("project")||Tt(t,"project").length===0&&Tt(t,"personal").length>0);return {pluginId:t.id,enabled:true,connectionMode:o?"personal":"project",connectionId:null,allTools:true,selectedTools:[],deliveryEnabled:false,channels:[]}}function cs(t,n){return `${encodeURIComponent(t)}:${encodeURIComponent(n)}`}function fs(t){return decodeURIComponent(t.slice(t.indexOf(":")+1))}function us(t){let n=t.map(fs),o=n.slice(0,wn).join(", ");return n.length>wn?`${o} +${n.length-wn} more`:o}function ds({canManage:t,disabled:n,plugin:o$1,projectId:i,usage:l,onChange:k,onRemove:f$1}){let g=Xo(o$1),c=g.some(w=>Tt(o$1,w).length>0),p=g.includes(l.connectionMode)?{connectionMode:l.connectionMode,connectionId:l.connectionId}:null,d=In(o$1,p),{data:v$1,error:C}=De(d?`/api/flexkit/${i}/plugin-connections/${d.id}/tools`:null,f),T=(v$1?.servers??[]).flatMap(w=>w.tools.map(H=>({key:cs(w.name,H.name),entry:H}))),j$1=(v$1?.servers??[]).flatMap(w=>w.error?[w.error]:[]),A=l.allTools!==false,x=n||!o$1.enabled,b=w=>k({...l,allTools:false,selectedTools:w,enabled:w.length>0}),P=()=>k({...l,allTools:true,selectedTools:[],enabled:true}),F=w=>({...l,connectionMode:w.connectionMode,connectionId:w.connectionId,selectedTools:[],enabled:A}),{mutate:S}=useSWRConfig(),[_,M]=useState(false),B=async w=>{M(true);try{await a$3(d$4(i),o$1.id,w),await S(`/api/flexkit/${i}/plugins`),k(F({connectionMode:w,connectionId:null}));}catch(H){oa$1.error(H instanceof Error?H.message:`Unable to connect ${o$1.name}.`);}finally{M(false);}},U=null;return o$1.enabled?c?p?d?C||j$1.length?U={text:j$1[0]??"Unable to load tools. Reconnect or try again.",tone:"warning"}:A?U={text:"All tools",tone:"muted"}:l.selectedTools.length===0?U={text:"No tools selected, so the agent cannot use this plugin yet.",tone:"warning"}:U={text:us(l.selectedTools),tone:"muted"}:U={text:p.connectionId?"The selected account is no longer connected.":`The primary ${p.connectionMode} account needs reconnecting.`,tone:"warning"}:U={text:"Select an account.",tone:"warning"}:U={text:`Connect ${o$1.name} to use its tools.`,tone:"warning"}:U={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:U.tone==="warning"?"fk:truncate fk:text-xs fk:text-warning":"fk:truncate fk:text-xs fk:text-muted-foreground",children:U.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:[c?jsxs(Fragment,{children:[jsx(Pn,{ariaLabel:`${o$1.name} account`,disabled:x,plugin:o$1,scopes:g,value:p,onChange:w=>{w.connectionMode===l.connectionMode&&w.connectionId===l.connectionId||k(F(w));}}),jsxs(e,{children:[jsx(g$1,{asChild:true,children:jsxs(b$2,{disabled:x||!d||!v$1,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:w=>{w.preventDefault(),A?b(T.map(H=>H.key)):P();},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,{}),T.map(({key:w,entry:H})=>{let $=A||l.selectedTools.includes(w);return jsxs(j,{className:"fk:items-start",onSelect:he=>{he.preventDefault();let q=A?T.map(be=>be.key):l.selectedTools;b($?q.filter(be=>be!==w):[...q,w]);},children:[jsx(CheckIcon,{className:$?"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:H.name}),H.description?jsx("span",{className:"fk:line-clamp-2 fk:text-xs fk:text-muted-foreground",children:H.description}):null]})]},w)}),v$1&&T.length===0?jsx(j,{disabled:true,children:"This account exposes no tools."}):null]})]})]}):jsx(b$7,{busy:_||n,canManage:t,plugin:o$1,onConnect:w=>{B(w);}}),jsx(b$2,{"aria-label":`Remove ${o$1.name} from automation`,disabled:n,size:"icon",type:"button",variant:"ghost",onClick:f$1,children:jsx(Trash2Icon,{className:"fk:size-4"})})]})]}),jsx(v,{})]})}function ms({disabled:t,plugins:n,onAdd:o}){let[i,l]=useState(false),k=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:f=>{f.preventDefault(),k.current?.focus({preventScroll:true});},children:jsxs(m,{filter:Sn,children:[jsx(o$1,{placeholder:"Search plugins\u2026",ref:k}),jsxs(p,{children:[jsx(q$1,{children:"No plugins found."}),jsx(r$1,{children:n.map(f=>jsxs(t$2,{value:f.id,keywords:[f.name],onSelect:()=>{o(f),l(false);},children:[jsx("img",{src:f.logoUrl,alt:"",className:"fk:size-5 fk:shrink-0 fk:rounded fk:corner-squircle"}),jsx("span",{className:"fk:truncate",children:f.name}),f.connections.some(g=>g.status==="connected")?null:jsx("span",{className:"fk:ml-auto fk:text-xs fk:text-muted-foreground",children:"Not connected"})]},f.id))})]})]})})]})}function Ko({projectId:t,value:n,disabled:o,onChange:i}){let{data:l,error:k}=De(`/api/flexkit/${t}/plugins`,f),f$1=(l?.plugins??[]).filter(p=>p.capabilities.agentTools),g=new Map(f$1.map(p=>[p.id,p])),c=f$1.filter(p=>p.enabled&&!n.some(d=>d.pluginId===p.id));return jsxs(Fragment,{children:[n.map(p=>{let d=g.get(p.pluginId);return d?jsx(ds,{disabled:o,canManage:l?.canManage??false,plugin:d,projectId:t,usage:p,onChange:v=>i(n.map(C=>C.pluginId===d.id?v:C)),onRemove:()=>i(n.filter(v=>v.pluginId!==d.id))},p.pluginId):null}),k?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(ms,{disabled:o||!l,plugins:c,onAdd:p=>i([...n,rs(p)])})]})}var Wt=["slack","teams"],ea=["create","update","delete"],da="0 * * * *",Ts="0 9 * * *",Cs="0 9 * * 1",Ss="0 9 1 * *",ws=[{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}],As=Array.from({length:24},(t,n)=>({label:`${n.toString().padStart(2,"0")}:00`,value:n})),ta={automation_run:"a run of",bulk_action:"a bulk action of",schema_deploy:"a schema deployment"},na={any:"finishes",failed:"fails",succeeded:"succeeds"},Is=[{label:"=",value:"eq"},{label:"\u2260",value:"neq"},{label:">",value:"gt"},{label:"\u2265",value:"gte"},{label:"<",value:"lt"},{label:"\u2264",value:"lte"},{label:"contains",value:"contains"},{label:"exists",value:"exists"}],Ln=5,Dn=1440,Ps=15,Mn="__any__";function Ms(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 oa(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 ft(){return crypto.randomUUID()}function Rs(t){return (t?.triggers??[]).map(n=>({...n,key:n.id??ft()}))}function Es(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 Ls(){return Intl.DateTimeFormat().resolvedOptions().timeZone||"UTC"}function Ds(){let t=crypto.getRandomValues(new Uint8Array(24));return Array.from(t,n=>n.toString(16).padStart(2,"0")).join("")}function zs(t){if(t===da)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 ma(t,n,o){try{let i=CronExpressionParser.parse(t,{tz:n});return Array.from({length:o},()=>i.next().toDate())}catch{return []}}function ka(t,n){return new Intl.DateTimeFormat("en-US",{day:"numeric",hour:"numeric",minute:"2-digit",month:"short",timeZone:n,weekday:"short"}).format(t)}function pa(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 Fs(t,n,o){let i=t.filter(k=>!k.deprecated);if(n!=="edit"||!o)return i;let l=c$3(t,o);return l?.deprecated?[l,...i.filter(k=>b$6(k)!==o)]:l?i:[{deprecated:true,effort:null,efforts:[],id:o,kind:"model",name:o},...i]}function zn(t){return `${t.teamId??""}:${t.id}`}function _s(t,n){let o={};for(let i of [...t,...n])o[zn(i)]=i;return Object.values(o)}function aa(t,n){return {...t,availableChannels:t.channels,channelsLoaded:!t.connected,enabled:t.connected&&n==="edit"&&t.enabled,loadingChannels:false}}function Bs(t,n){return {slack:aa(t.providers.slack,n),teams:aa(t.providers.teams,n)}}function js({channels:t,disabled:n,loading:o,onChange:i,onRefresh:l,provider:k,value:f}){let[g,c]=useState(false),[p,d]=useState(""),v=useRef(null),C=new Set(f.map(b=>b.id)),T=k==="slack"?"Slack":"Teams",j=t.filter(b=>b.name.toLowerCase().includes(p.toLowerCase()));useEffect(()=>{if(!g)return;function b(F){let{target:S}=F;!(S instanceof Node)||v.current?.contains(S)||c(false);}function P(F){F.key==="Escape"&&c(false);}return document.addEventListener("pointerdown",b),document.addEventListener("keydown",P),()=>{document.removeEventListener("pointerdown",b),document.removeEventListener("keydown",P);}},[g]);function A(b){if(C.has(b.id)){i(f.filter(P=>P.id!==b.id));return}i([...f,b]);}function x(b){i(f.filter(P=>P.id!==b));}return jsxs("div",{className:"fk:relative",ref:v,children:[jsxs(b$2,{"aria-expanded":g,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:()=>c(b=>!b),children:[jsx("div",{className:"fk:flex fk:flex-1 fk:flex-wrap fk:gap-1",children:f.length===0?jsx("span",{className:"fk:text-muted-foreground",children:o?`Loading ${T} channels...`:`Select ${T} channels`}):f.map(b=>jsxs(b$1,{className:"fk:rounded-sm fk:bg-accent fk:text-xs fk:corner-squircle",variant:"secondary",onClick:P=>{P.stopPropagation(),x(b.id);},children:[b.name,jsx(XIcon,{className:"fk:ml-1 fk:size-3 fk:cursor-pointer"})]},zn(b)))}),jsx(ChevronsUpDownIcon,{className:"fk:size-4 fk:shrink-0 fk:opacity-50"})]}),g?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,{className:"fk:h-8",placeholder:`Search ${T} channels...`,value:p,onChange:b=>d(b.target.value)})}),jsx("div",{className:"fk:max-h-56 fk:overflow-auto fk:p-1",children:j.length>0?j.map(b=>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(b),children:[jsx(CheckIcon,{className:`fk:mr-2 fk:size-4 ${C.has(b.id)?"fk:opacity-100":"fk:opacity-0"}`}),b.name]},zn(b))):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 Gt({cron:t,timezone:n}){let[o]=ma(t,n,1);return o?jsxs("span",{className:"fk:text-sm fk:text-muted-foreground",children:["Next run ",ka(o,n)]}):null}function sa({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:As.map(o=>jsx(g$5,{value:o.value.toString(),children:o.label},o.value))})]})}function $s({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:ws.map(o=>jsx(g$5,{value:o.value.toString(),children:o.label},o.value))})]})}function Vs({onChange:t,timezone:n,value:o}){let[i,l]=useState(false),k=useRef(null),f=pa(o,n),g=f?[]:ma(o,n,3);return useEffect(()=>{if(!i)return;function c(d){let{target:v}=d;!(v instanceof Node)||k.current?.contains(v)||l(false);}function p(d){d.key==="Escape"&&l(false);}return document.addEventListener("pointerdown",c),document.addEventListener("keydown",p),()=>{document.removeEventListener("pointerdown",c),document.removeEventListener("keydown",p);}},[i]),jsxs("div",{className:"fk:relative",ref:k,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(c=>!c),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,{className:`fk:h-8 fk:font-mono ${f?"fk:border-destructive focus-visible:fk:ring-destructive":""}`,value:o,onChange:c=>t(c.target.value)}),f?jsx("p",{className:"fk:mt-2 fk:text-xs fk:text-destructive",children:f}):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"}),g.map(c=>jsx("p",{children:ka(c,n)},c.toISOString()))]})]}):null]})}function Os({onChange:t,trigger:n}){let o=zs(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(Gt,{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(sa,{value:o.hour,onChange:i=>t({...n,cron:`0 ${i.toString()} * * *`})}),jsx("span",{className:"fk:text-muted-foreground",children:n.timezone}),jsx(Gt,{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($s,{value:o.day,onChange:i=>t({...n,cron:`0 ${o.hour.toString()} * * ${i.toString()}`})}),jsx("span",{children:"at"}),jsx(sa,{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(Gt,{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(Vs,{timezone:n.timezone,value:n.cron,onChange:i=>t({...n,cron:i})}),jsx("span",{className:"fk:text-muted-foreground",children:n.timezone}),jsx(Gt,{cron:n.cron,timezone:n.timezone})]})}function qs({onChange:t,projectId:n,trigger:o}){let[i,l]=useState(false),[k,f]=useState(false),g=o.url??c$5(n,o.token);function c$1(p,d){navigator.clipboard.writeText(p).then(()=>{d(true),window.setTimeout(()=>d(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:()=>c$1(g,l),children:[jsx("span",{className:"fk:truncate",children:g}),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:g})]}),o.secret?jsxs(b$2,{className:"fk:h-7 fk:px-2.5 fk:text-xs",size:"sm",type:"button",variant:"outline",onClick:()=>c$1(`Bearer ${o.secret??""}`,f),children:[k?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:Ds()}),children:[jsx(KeyRoundIcon,{className:"fk:size-3.5"}),"Generate auth header"]})]})}function Js({entities:t,onChange:n,trigger:o}){function i(f){let g=o.events.includes(f)?o.events.filter(c=>c!==f):[...o.events,f];n({...o,events:ea.filter(c=>g.includes(c))});}function l(f){let g=o.entities.includes(f)?o.entities.filter(c=>c!==f):[...o.entities,f];n({...o,entities:g});}let k=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:ea.map(f=>jsxs(b$2,{className:"fk:h-7 fk:px-2.5 fk:text-xs fk:capitalize",size:"sm",type:"button",variant:o.events.includes(f)?"secondary":"ghost",onClick:()=>i(f),children:[o.events.includes(f)?jsx(CheckIcon,{className:"fk:size-3"}):null,f]},f))}),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:k}),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(f=>jsx(k$1,{checked:o.entities.includes(f),onCheckedChange:()=>l(f),onSelect:g=>g.preventDefault(),children:f},f))})]})]})}function Us({automationId:t,onChange:n,projectId:o,trigger:i}){let{data:l}=De(i.job==="schema_deploy"?null:g(o).automations({limit:100}),f),k=(l?.automations??[]).filter(f=>f.id!==t);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:"When"}),jsxs(a$2,{value:i.job,onValueChange:f=>n({...i,automationId:f==="schema_deploy"?null:i.automationId,job:f}),children:[jsx(d$3,{className:"fk:h-7 fk:w-auto fk:text-xs",children:jsx(c$4,{})}),jsx(e$6,{children:Object.keys(ta).map(f=>jsx(g$5,{value:f,children:ta[f]},f))})]}),i.job==="schema_deploy"?null:jsxs(a$2,{value:i.automationId??(i.job==="bulk_action"?Mn:""),onValueChange:f=>n({...i,automationId:f===Mn?null:f}),children:[jsx(d$3,{className:"fk:h-7 fk:w-auto fk:max-w-60 fk:text-xs",children:jsx(c$4,{placeholder:"Choose an automation"})}),jsxs(e$6,{children:[i.job==="bulk_action"?jsx(g$5,{value:Mn,children:"any automation"}):null,k.map(f=>jsx(g$5,{value:f.id,children:f.name},f.id))]})]}),jsxs(a$2,{value:i.outcome,onValueChange:f=>n({...i,outcome:f}),children:[jsx(d$3,{className:"fk:h-7 fk:w-auto fk:text-xs",children:jsx(c$4,{})}),jsx(e$6,{children:Object.keys(na).map(f=>jsx(g$5,{value:f,children:na[f]},f))})]})]})}function Hs(t){let n=t.trim();return n==="true"||n==="false"?n==="true":n==="null"?null:n!==""&&Number.isFinite(Number(n))?Number(n):t}function Xs(t){return t===void 0?"":String(t)}function Ks({onChange:t,value:n}){let[o,i]=useState(()=>Xs(n));return jsx(s,{"aria-label":"Value",className:"fk:h-7 fk:w-32 fk:text-xs",placeholder:"10",value:o,onChange:l=>{i(l.target.value),t(Hs(l.target.value));}})}function Ws({onChange:t,trigger:n}){let o=useId(),{condition:i}=n;return jsxs("div",{className:"fk:flex fk:min-w-0 fk:flex-1 fk:flex-col fk:gap-2 fk:text-sm",children:[jsxs("div",{className:"fk:flex fk:flex-wrap fk:items-center fk:gap-2",children:[jsx("span",{children:"Every"}),jsx(s,{"aria-label":"Minutes between checks",className:"fk:h-7 fk:w-16 fk:text-xs",max:Dn,min:Ln,type:"number",value:Number.isFinite(n.intervalMinutes)?n.intervalMinutes:"",onChange:l=>t({...n,intervalMinutes:Number.parseInt(l.target.value,10)})}),jsx("span",{children:"minutes, run when"}),jsxs(a$2,{value:i?"condition":"changed",onValueChange:l=>t({...n,condition:l==="changed"?null:{op:"gte",path:"",value:""}}),children:[jsx(d$3,{className:"fk:h-7 fk:w-auto fk:text-xs",children:jsx(c$4,{})}),jsxs(e$6,{children:[jsx(g$5,{value:"condition",children:"a value meets a condition"}),jsx(g$5,{value:"changed",children:"the result changes"})]})]})]}),i?jsxs("div",{className:"fk:flex fk:flex-wrap fk:items-center fk:gap-2",children:[jsx(s,{"aria-label":"Path in the result",className:"fk:h-7 fk:w-78 fk:font-mono fk:text-xs",placeholder:"data.ordersConnection.totalCount",value:i.path,onChange:l=>t({...n,condition:{...i,path:l.target.value}})}),jsxs(a$2,{value:i.op,onValueChange:l=>t({...n,condition:l==="exists"?{op:"exists",path:i.path}:{...i,op:l}}),children:[jsx(d$3,{className:"fk:h-7 fk:w-auto fk:text-xs",children:jsx(c$4,{})}),jsx(e$6,{children:Is.map(l=>jsx(g$5,{value:l.value,children:l.label},l.value))})]}),i.op==="exists"?null:jsx(Ks,{value:i.value,onChange:l=>t({...n,condition:{...i,value:l}})})]}):null,jsx(e$5,{className:"fk:sr-only",htmlFor:o,children:"Read-only GraphQL query"}),jsx(ka$1,{className:"fk:min-h-20 fk:font-mono fk:text-xs",id:o,placeholder:`query {
2
- ordersConnection(where: { status: { eq: "pending" } }) { totalCount }
3
- }`,value:n.query,onChange:l=>t({...n,query:l.target.value})})]})}function Gs({automationId:t,entities:n,errors:o,onChange:i,projectId:l,triggers:k}){let f=k.some(v=>v.type==="webhook");function g(v){i([...k,v]);}function c(v){g({cron:v,key:ft(),timezone:Ls(),type:"schedule"});}function p(v){i(k.map(C=>C.key===v.key?v:C));}function d(v){i(k.filter(C=>C.key!==v));}return jsxs("div",{className:"fk:rounded-lg fk:border fk:bg-muted/60 fk:dark:bg-muted/30 fk:corner-squircle",children:[k.map(v$1=>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:[v$1.type==="schedule"?jsx(ClockIcon,{className:"fk:size-4 fk:shrink-0 fk:text-muted-foreground"}):null,v$1.type==="webhook"?jsx(WebhookIcon,{className:"fk:size-4 fk:shrink-0 fk:text-muted-foreground"}):null,v$1.type==="entity"?jsx(DatabaseZapIcon,{className:"fk:size-4 fk:shrink-0 fk:text-muted-foreground"}):null,v$1.type==="job"?jsx(CircleCheckBigIcon,{className:"fk:size-4 fk:shrink-0 fk:text-muted-foreground"}):null,v$1.type==="poll"?jsx(RefreshCwIcon,{className:"fk:size-4 fk:shrink-0 fk:self-start fk:mt-2.5 fk:text-muted-foreground"}):null,v$1.type==="schedule"?jsx(Os,{trigger:v$1,onChange:p}):null,v$1.type==="webhook"?jsx(qs,{projectId:l,trigger:v$1,onChange:p}):null,v$1.type==="entity"?jsx(Js,{entities:n,trigger:v$1,onChange:p}):null,v$1.type==="job"?jsx(Us,{automationId:t,projectId:l,trigger:v$1,onChange:p}):null,v$1.type==="poll"?jsx(Ws,{trigger:v$1,onChange:p}):null,jsx(b$2,{"aria-label":"Remove trigger",className:"fk:opacity-0 fk:group-hover:opacity-100",size:"icon",type:"button",variant:"ghost",onClick:()=>d(v$1.key),children:jsx(Trash2Icon,{className:"fk:size-4 fk:text-muted-foreground"})})]}),o[v$1.key]?jsx("div",{className:"fk:mt-1 fk:pl-7",children:jsx(Xe,{message:o[v$1.key]})}):null]},v$1.key),jsx(v,{className:"fk:h-4"})]},v$1.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 ${k.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,{children:[jsxs(r,{children:[jsx(ClockIcon,{className:"fk:mr-2 fk:size-4 fk:text-muted-foreground"}),"Scheduled"]}),jsxs(s$1,{children:[jsx(j,{onClick:()=>c(da),children:"Hourly"}),jsx(j,{onClick:()=>c(Ts),children:"Daily"}),jsx(j,{onClick:()=>c(Cs),children:"Weekly"}),jsx(j,{onClick:()=>c(Ss),children:"Custom (cron)"})]})]}),jsxs(j,{disabled:f,onClick:()=>g({key:ft(),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:()=>g({entities:[],events:["create"],key:ft(),type:"entity"}),children:[jsx(DatabaseZapIcon,{className:"fk:mr-2 fk:size-4 fk:text-muted-foreground"}),"Entity Events"]}),jsxs(j,{onClick:()=>g({automationId:null,job:"schema_deploy",key:ft(),outcome:"succeeded",type:"job"}),children:[jsx(CircleCheckBigIcon,{className:"fk:mr-2 fk:size-4 fk:text-muted-foreground"}),"Job Finished"]}),jsxs(j,{onClick:()=>g({condition:{op:"gte",path:"",value:""},intervalMinutes:Ps,key:ft(),query:"",type:"poll",variables:null}),children:[jsx(RefreshCwIcon,{className:"fk:mr-2 fk:size-4 fk:text-muted-foreground"}),"Poll Condition"]})]})]})]})}function Zs(){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 Ys(){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 Yt(t,n,o){return t.visibility==="space"?n==="space"&&o!==null&&t.spaceId===o:t.visibility==="personal"?n==="personal":true}function Qs(t,n,o){return t.visibility==="space"&&!Yt(t,n,o)}function ei(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 ti(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}}var ga=[{label:"Results that need attention (recommended)",value:"when_flagged"},{label:"Every finished run",value:"always"},{label:"Failures only",value:"failures"},{label:"Never",value:"never"}];function ni(t){return ga.some(n=>n.value===t)}function Fn({api:t,automation:n,mode:o,onSaved:i,projectId:l}){let[k,f$1]=useState((n?.toolConfigs??[]).filter(s=>!["slack","teams"].includes(s.pluginId))),[g$1,c]=useState(n?.name??""),[p,d]=useState(n?.instructions??""),[v$1,C]=useState(n?.enabled??false),[T,j]=useState(null),[A,x]=useState(null),[b$3,P]=useState(n?.mutationPolicy??"require_approval"),[F,S]=useState(n?.toolAllowRules),[_,M]=useState(n?.notifyRule??"when_flagged"),[B,U]=useState(n?.notifyCreator??true),[w,H]=useState(n?.subscriberIds??[]),[$,he]=useState(n?.visibility??"project"),[q,be]=useState(n?.spaceId??null),[ye,Be]=useState(n?.skillIds??[]),[me,dt]=useState(n?.customToolNames??[]),[Ce,ze]=useState(()=>Rs(n)),[je,We]=useState(false),[Ge,$e]=useState(""),[R,N]=useState({instructions:false,name:false}),[E,ke]=useState(null),[Pt,mt]=useState(null),{mutate:$n}=useSWRConfig(),[kt,Vn]=useState(()=>({slack:n?.toolConfigs?.find(s=>s.pluginId==="slack")?.connectionId??null,teams:n?.toolConfigs?.find(s=>s.pluginId==="teams")?.connectionId??null})),Mt=useRef({}),On=useRef(null),{data:Ze,error:Ia}=De(`/api/flexkit/${l}/plugins`,f),qn=!!(Ze||Ia),Pa=g(l).tools(n?.id),{data:Ve,error:Ma}=De(Pa,f),{data:Ra}=De(g(l).entities,f),{data:sn}=De(g(l).spaces,f),{data:Rt}=De($==="personal"?null:g(l).members($==="space"?q:null),f),{data:oe}=De(g(l).skills({limit:100}),f),[,Ea]=h$2(),ae=b(),La=Ea.user?.spaces??[],Jn=(sn?.spaces??[]).filter(s=>La.includes(s.code)),Et=Ve?.tools.models,Un=useMemo(()=>{let s=n?.modelId??"";return s?f$4(s,Et??[])??{effort:null,modelKey:s}:null},[n?.modelId,Et]),ln=T??Un?.modelKey??"",pt=useMemo(()=>Fs(Et??[],o,ln),[o,Et,ln]),Lt=ln||(pt[0]?b$6(pt[0]):""),Hn=c$3(pt,Lt),rn=d$2(Hn,A??(T===null?Un?.effort??null:null)),Xn=e$4(Hn),cn=Lt?g$4({effort:rn,modelKey:Lt},pt):"",Kn=useMemo(()=>new Set((oe?.skills??[]).map(s=>s.id)),[oe?.skills]),Ye=useMemo(()=>oe?ye.filter(s=>!Kn.has(s)).sort():[],[Kn,ye,oe]),Da=Ye.length>0?[l,"attached-skills",...Ye]:null,{data:Dt}=De(Da,()=>Promise.all(Ye.map(s=>ti(l,s)))),Qe=useMemo(()=>{let s={};for(let h of oe?.skills??[])s[h.id]=h;for(let h of Dt??[])h&&(s[h.id]=h);return s},[Dt,oe?.skills]),fn=useMemo(()=>{let s=(oe?.skills??[]).filter(y=>Yt(y,$,q)),h=new Set(s.map(y=>y.id));return [...ye.map(y=>Qe[y]).filter(y=>!y||h.has(y.id)?false:Yt(y,$,q)),...s]},[ye,Qe,oe?.skills,q,$]),za=useMemo(()=>{let s={};for(let h of sn?.spaces??[])s[h.id]=h.label;return s},[sn?.spaces]),un=useMemo(()=>(oe?.skills??[]).filter(s=>Qs(s,$,q)),[oe?.skills,q,$]),Fe=Ve?.tools.customTools,dn=useMemo(()=>{let s={};for(let h of Fe?.tools??[])s[h.name]=h;return s},[Fe?.tools]),mn=useMemo(()=>{let s=Fe?.tools??[],h=new Set(s.map(y=>y.name));return [...me.filter(y=>!h.has(y)).map(y=>dn[y]??{description:"",name:y}),...s]},[me,dn,Fe?.tools]),Wn=Fe?Es(Fe):"";useEffect(()=>{if(!oe)return;let s=Ye.length>0&&Dt===void 0,h=new Set(s?[]:Ye.filter(m=>!Qe[m]));Be(m=>{let y=m.filter(D=>{if(h.has(D))return false;let Me=Qe[D];return Me?Yt(Me,$,q):true});return y.length===m.length?m:y});},[Dt,Qe,oe,q,Ye,$]);let et=oa(k),le=useMemo(()=>{let s={};for(let m of Ce){if(m.type==="schedule"){let y=pa(m.cron,m.timezone);y&&(s[m.key]=y);}m.type==="entity"&&m.events.length===0&&(s[m.key]="Select at least one event (create, update or delete)"),m.type==="job"&&m.job==="automation_run"&&!m.automationId&&(s[m.key]="Choose the automation whose runs start this one"),m.type==="poll"&&(!Number.isInteger(m.intervalMinutes)||m.intervalMinutes<Ln||m.intervalMinutes>Dn?s[m.key]=`Check every ${Ln.toString()} to ${Dn.toString()} minutes`:m.query.trim()?m.condition&&!m.condition.path.trim()&&(s[m.key]="Enter the path of the value to compare, e.g. data.ordersConnection.totalCount"):s[m.key]="Enter the read-only GraphQL query to check");}let h={};for(let m of Wt){let y=E?.[m];y?.enabled&&y.channels.length===0&&(h[m]=`Select at least one ${m==="slack"?"Slack":"Teams"} channel or remove the tool`);}return {instructions:p.trim()?"":"Instructions are required",model:cn?"":"Select a model",name:g$1.trim()?"":"Name is required",plugins:et&&$!=="personal"?"Personal plugin connections can only be used by a personal automation.":"",space:$==="space"&&!q?"Select a space":"",toolErrors:h,triggerErrors:s}},[cn,p,g$1,et,q,E,Ce,$]),kn=Ms(le),zt=R.name&&!!le.name,gt=R.instructions&&!!le.instructions;useEffect(()=>{let s=`${n?.id??""}:${o}`;!Ve?.tools||On.current===s||(On.current=s,ke(Bs(Ve.tools,o)));},[n?.id,o,Ve?.tools]);let Ft=useMemo(()=>({slack:Ze?.plugins.find(s=>s.id==="slack")??null,teams:Ze?.plugins.find(s=>s.id==="teams")??null}),[Ze]),pn=useMemo(()=>{let s=h=>{let m=Ft[h];return m?In(m,{connectionMode:"project",connectionId:kt[h]})?.id??null:null};return {slack:s("slack"),teams:s("teams")}},[kt,Ft]),gn=useCallback(async(s,h)=>{Mt.current[s]=h,ke(m=>m&&{...m,[s]:{...m[s],channelsLoadError:void 0,loadingChannels:true}});try{let m=await t.listChannels(s,h);if(Mt.current[s]!==h)return;let y=m.success?void 0:m.errorMessage??`Failed to load ${s==="slack"?"Slack":"Teams"} channels.`;ke(D=>D&&{...D,[s]:{...D[s],availableChannels:_s(D[s].channels,m.channels),channelsLoadError:y,channelsLoaded:!0,loadingChannels:!1}});}catch(m){if(Mt.current[s]!==h)return;let y=m instanceof Error?m.message:"Failed to load integration channels.";ke(D=>D&&{...D,[s]:{...D[s],channelsLoadError:y,channelsLoaded:true,loadingChannels:false}});}},[t]);useEffect(()=>{if(!(!E||!ae||!qn))for(let s of Wt){let h=E[s];h.connected&&!h.channelsLoaded&&!h.loadingChannels&&gn(s,pn[s]);}},[ae,gn,qn,pn,E]);async function Fa(s){let h=Ft[s];if(h){mt(s);try{await a$3(t,h.id,"project");let y=(await $n(`/api/flexkit/${l}/plugins`))?.plugins.find(D=>D.id===h.id)?.connections.find(D=>D.scope==="project"&&D.isPrimary&&D.status==="connected");Vn(D=>({...D,[s]:null})),Gn(s,{connected:!0,enabled:!0,workspaceName:y?.displayName??null});}catch(m){oa$1.error(m instanceof Error?m.message:`Unable to connect ${h.name}.`);}finally{mt(null);}}}function _t(s,h){ke(m=>m&&{...m,[s]:{...m[s],...h}});}function _a(s,h){kt[s]!==h&&(Vn(m=>({...m,[s]:h})),Gn(s));}function Gn(s,h={}){Mt.current[s]=void 0,_t(s,{...h,availableChannels:[],channels:[],channelsLoaded:false,channelsLoadError:void 0,loadingChannels:false});}function Ba(s){_t(s,{channels:[],enabled:false});}function Zn(s,h){Be(m=>h?m.includes(s)?m:[...m,s]:m.filter(y=>y!==s));}function Yn(s,h){dt(m=>h?m.includes(s)?m:[...m,s]:m.filter(y=>y!==s));}async function ja(s){if(s.preventDefault(),!ae)return;if(!kn){N({instructions:true,name:true});return}We(true),$e("");let h=Wt.map(y=>{let D=E?.[y]??Ve?.tools.providers[y];return {channels:D?.channels??[],enabled:D?.enabled??false,pluginId:y,connectionMode:"project",connectionId:kt[y],selectedTools:[],deliveryEnabled:D?.enabled??false}}),m={customToolNames:me,enabled:v$1,instructions:p,modelId:cn,mutationPolicy:b$3,name:g$1,notifyCreator:B,notifyRule:_,skillIds:ye,subscriberIds:$==="personal"?[]:w,...F!==void 0?{toolAllowRules:F}:{},spaceId:$==="space"?q:null,toolConfigs:[...h,...k],triggers:Ce.map(({key:y,...D})=>D),visibility:$};try{let y=o==="create"||!n?await t.createAutomation(m):await t.updateAutomation(n.id,m);if(!y.success){$e(Array.isArray(y.errorMessage)?y.errorMessage.join(", "):y.errorMessage);return}oa$1.success(o==="create"||!n?"Automation created.":"Automation saved."),i(y.automation);}catch(y){$e(y instanceof Error?y.message:"Failed to save automation.");}finally{We(false);}}return jsxs("form",{className:"fk:max-w-4xl fk:space-y-8 fk:px-1 fk:mx-auto",onSubmit:s=>{ja(s);},children:[Ge?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:Ge}):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$1,{checked:v$1,id:"automation-enabled",onCheckedChange:C}),jsx(e$5,{className:"fk:font-normal",htmlFor:"automation-enabled",children:v$1?"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,{"aria-describedby":zt?"automation-name-error":void 0,"aria-invalid":zt,className:zt?"fk:border-destructive focus-visible:fk:ring-destructive":"",id:"automation-name",value:g$1,onBlur:()=>N(s=>({...s,name:true})),onChange:s=>c(s.target.value)}),zt?jsx(Xe,{id:"automation-name-error",message:le.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:$,onValueChange:s=>{et&&s!=="personal"||(he(s==="space"||s==="personal"?s:"project"),s!=="space"&&be(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$5,{disabled:et,value:"project",children:"Project"}),jsx(g$5,{disabled:et||Jn.length===0,value:"space",children:"Space"}),jsx(g$5,{value:"personal",children:"Personal"})]})]}),$==="space"?jsxs(a$2,{value:q??"",onValueChange:s=>{be(s||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:Jn.map(s=>jsx(g$5,{value:s.id,children:s.label},s.id))})]}):null]}),et?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,le.plugins?jsx(Xe,{message:le.plugins}):null,$==="space"&&le.space?jsx(Xe,{message:le.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(Gs,{automationId:n?.id,entities:Ra?.entities??[],errors:le.triggerErrors,projectId:l,triggers:Ce,onChange:ze})]}),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 ${gt?"fk:border-destructive":"fk:border-input"} fk:corner-squircle`,children:jsx(ka$1,{"aria-describedby":gt?"automation-instructions-error":void 0,"aria-invalid":gt,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:p,onBlur:()=>N(s=>({...s,instructions:true})),onChange:s=>d(s.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 ${gt?"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:Lt,onValueChange:s=>{j(s),x(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:pt.map(s=>jsxs(g$5,{value:b$6(s),children:[s.name,s.deprecated?" (Legacy)":""]},b$6(s)))})]}),Xn.length>1&&rn?jsxs(a$2,{value:rn,onValueChange:x,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:Xn.map(s=>jsx(g$5,{value:s.value,children:s.label},s.value))})]}):null]})})]}),gt?jsx(Xe,{id:"automation-instructions-error",message:le.instructions}):null,Ve&&le.model?jsx(Xe,{message:le.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:b$3,onValueChange:s=>{P(s==="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$5,{value:"require_approval",children:"Require approval (recommended)"}),jsx(g$5,{value:"auto_approve",children:"Auto-approve"})]})]}),b$3==="auto_approve"&&k.some(s=>s.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,b$3==="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(s=>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:[s.pluginId,": ",s.tool]}),jsx(b$2,{"aria-label":`Remove allow rule for ${s.pluginId} ${s.tool}`,size:"sm",type:"button",variant:"ghost",onClick:()=>S(h=>(h??[]).filter(m=>m!==s)),children:"Remove"})]},`${s.pluginId}/${s.server}/${s.tool}`))})]}):null]}),jsxs("div",{className:"fk:space-y-3",children:[jsx(e$5,{className:"fk:mb-1",htmlFor:"automation-notify-rule",children:"Notifications"}),jsx("p",{className:"fk:text-xs fk:text-muted-foreground fk:mb-2",children:"Approval requests and run results appear in Activity in Studio. Failures are always reported unless set to Never."}),jsxs(a$2,{value:_,onValueChange:s=>{ni(s)&&M(s);},children:[jsx(d$3,{"aria-label":"Notify about runs",className:"fk:w-fit",id:"automation-notify-rule",children:jsx(c$4,{})}),jsx(e$6,{align:"start",children:ga.map(s=>jsx(g$5,{value:s.value,children:s.label},s.value))})]}),jsxs("div",{className:"fk:flex fk:h-8 fk:items-center fk:gap-2",children:[jsx(Z$1,{checked:B,id:"automation-notify-creator",onCheckedChange:U}),jsx(e$5,{className:"fk:font-normal",htmlFor:"automation-notify-creator",children:"Notify the creator"})]}),$==="personal"?null:jsxs("div",{className:"fk:space-y-2",children:[jsxs("div",{className:"fk:flex fk:items-center fk:justify-between fk:gap-2",children:[jsxs("div",{children:[jsx("p",{className:"fk:text-sm",children:"Subscribers"}),jsx("p",{className:"fk:text-xs fk:text-muted-foreground",children:"Members who also get its notifications. Only owners and developers receive approval requests."})]}),jsx(Kt,{disabled:!ae||!Rt,emptyText:"No members match.",items:(Rt?.members??[]).map(s=>({attached:w.includes(s.id),id:s.id,label:s.displayName})),searchPlaceholder:"Search members\u2026",triggerLabel:"Add",onToggle:(s,h)=>H(m=>h?[...new Set([...m,s])]:m.filter(y=>y!==s))})]}),w.length>0?jsx("div",{className:"fk:flex fk:flex-wrap fk:gap-1.5",children:w.map(s=>{let m=Rt?.members.find(y=>y.id===s)?.displayName??(Rt?"No longer has access":"Loading\u2026");return jsxs(b$1,{className:"fk:gap-1 fk:pr-1 fk:font-normal",variant:"secondary",children:[m,jsx("button",{"aria-label":`Remove subscriber ${m}`,className:"fk:cursor-pointer fk:rounded-sm fk:text-muted-foreground fk:hover:text-foreground disabled:fk:cursor-not-allowed fk:corner-squircle",disabled:!ae,type:"button",onClick:()=>H(y=>y.filter(D=>D!==s)),children:jsx(XIcon,{className:"fk:size-3"})})]},s)})}):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,{}),E?Wt.map(s=>{let h=E[s],m=s==="slack"?"Send to Slack":"Send to Microsoft Teams",y=s==="slack"?Zs:Ys,D=Ft[s];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(y,{}),jsxs("div",{children:[jsx("div",{className:"fk:text-sm fk:font-medium",children:m}),h.connected&&h.workspaceName?jsxs("p",{className:"fk:text-xs fk:text-muted-foreground",children:["Connected to ",h.workspaceName]}):null,h.connected?null:jsx("p",{className:"fk:text-xs fk:text-muted-foreground",children:Ze?.canManage===false?"Not connected. Ask a project owner or developer to connect it.":"Not connected"})]})]}),h.connected?h.enabled?jsx(b$2,{"aria-label":`Remove ${s==="slack"?"Slack":"Microsoft Teams"} from automation`,size:"icon",type:"button",variant:"ghost",onClick:()=>Ba(s),children:jsx(Trash2Icon,{className:"fk:size-4 fk:text-muted-foreground"})}):jsx(b$2,{size:"sm",type:"button",variant:"outline",onClick:()=>_t(s,{enabled:true}),children:"Add"}):jsx(b$2,{disabled:!ae||!D?.enabled||!Ze?.canManage||Pt!==null,size:"sm",type:"button",variant:"outline",onClick:()=>{Fa(s);},children:Pt===s?"Connecting\u2026":"Connect"})]}),h.connected&&h.enabled?jsxs("div",{className:"fk:space-y-2 fk:pl-7",children:[D&&D.connections.filter(Me=>Me.scope==="project"&&Me.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(Pn,{ariaLabel:`${s==="slack"?"Slack":"Microsoft Teams"} workspace`,disabled:!ae,plugin:D,scopes:["project"],value:{connectionMode:"project",connectionId:kt[s]},onChange:Me=>_a(s,Me.connectionId)})]}):null,jsx(e$5,{className:"fk:mr-3 fk:text-xs fk:font-medium",children:"Channels"}),jsx(js,{channels:h.availableChannels,disabled:h.loadingChannels||!ae,loading:h.loadingChannels,provider:s,value:h.channels,onChange:Me=>_t(s,{channels:Me}),onRefresh:()=>{gn(s,pn[s]);}}),h.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"}),h.channelsLoadError]}):null,!h.channelsLoadError&&le.toolErrors[s]?jsx(Xe,{message:le.toolErrors[s]}):null]}):null]}),jsx(v,{})]},s)}):Ma?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(Kt,{disabled:!ae||fn.length===0&&un.length===0,emptyText:"No skills match.",items:[...fn.map(s=>({id:s.id,label:s.name,attached:ye.includes(s.id),badge:s.source==="code"?"Code":void 0})),...un.map(s=>({id:s.id,label:s.name,attached:false,badge:s.source==="code"?"Code":void 0,lockedHint:ei(s,za)}))],searchPlaceholder:"Search skills\u2026",onToggle:Zn})]}),oe&&fn.length===0&&un.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,oe?.hasMore?jsxs("p",{className:"fk:pl-7 fk:text-xs fk:text-muted-foreground",children:["Showing the ",oe.skills.length," most recently updated skills. Attached skills outside this list are kept when you save."]}):null,ye.length>0?jsx("div",{className:"fk:flex fk:flex-wrap fk:gap-1.5 fk:pl-7",children:ye.map(s=>{let h=Qe[s],m=h?.name??"Loading skill\u2026";return jsxs(b$1,{className:"fk:gap-1 fk:pr-1 fk:font-normal",variant:"secondary",children:[m,h?.source==="code"?jsx("span",{className:"fk:text-[10px] fk:uppercase",children:"Code"}):null,jsx("button",{"aria-label":h?`Detach ${h.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:!ae,type:"button",onClick:()=>Zn(s,false),children:jsx(XIcon,{className:"fk:size-3"})})]},s)})}):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."}),Wn?jsx("p",{className:Fe?.connected?"fk:mt-1 fk:text-xs fk:text-warning":"fk:mt-1 fk:text-xs fk:text-muted-foreground",children:Wn}):null]})]}),jsx(Kt,{disabled:!ae||mn.length===0,emptyText:"No custom tools match.",items:mn.map(s=>({id:s.name,label:s.name,attached:me.includes(s.name)})),searchPlaceholder:"Search custom tools\u2026",onToggle:Yn})]}),Fe&&mn.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,me.length>0?jsx("div",{className:"fk:flex fk:flex-wrap fk:gap-1.5 fk:pl-7",children:me.map(s=>{let m=dn[s]?.name??s;return jsxs(b$1,{className:"fk:gap-1 fk:pr-1 fk:font-normal",variant:"secondary",children:[m,jsx("button",{"aria-label":`Detach ${m}`,className:"fk:cursor-pointer fk:rounded-sm fk:text-muted-foreground fk:hover:text-foreground disabled:fk:cursor-not-allowed fk:corner-squircle",disabled:!ae,type:"button",onClick:()=>Yn(s,false),children:jsx(XIcon,{className:"fk:size-3"})})]},s)})}):null]}),jsx(v,{}),jsx(Ko,{projectId:l,value:k,disabled:!ae,onChange:s=>{f$1(s),oa(s)&&(he("personal"),be(null));}})]})]}),jsxs("div",{className:"fk:flex fk:items-center fk:justify-end fk:gap-3",children:[kn?null:jsx("span",{className:"fk:text-xs fk:text-muted-foreground",children:"Complete the required fields to save"}),jsx(ma$1,{disabled:!ae,children:jsx(b$2,{disabled:je||!kn||!ae,type:"submit",children:je?"Saving...":o==="create"?"Create automation":"Update automation"})})]})]})}var ba=25;function pi(t){return Math.max(600,t)}function gi(t){return t==="mine"||t==="team"}function Z({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 vi(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 Ca({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 ${vi(t)}`,variant:t==="success"?"default":"secondary",children:t==="awaiting_approval"?"awaiting approval":t})}function hi(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 bi(t){let n=t.triggers.map(o=>{if(o.type==="schedule")return hi(o.cron);if(o.type==="webhook")return "Webhook";if(o.type==="job")return o.job==="schema_deploy"?"After a deployment":o.job==="automation_run"?"After another automation":"After a bulk action";if(o.type==="poll")return `Poll every ${o.intervalMinutes.toString()} min`;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 Sa(t){return t?!!(t.name.trim()&&t.instructions.trim()&&t.modelId.trim()):false}function yi({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 xi(t,n){let o=t.visibility??"project";return o==="space"?(t.spaceId?n.get(t.spaceId):void 0)??"Space":o==="personal"?"Personal":"Project"}var wa="fk:sticky fk:top-0 fk:z-10 fk:[&_th]:sticky fk:[&_th]:top-0 fk:[&_th]:bg-muted";function Ni(){return jsxs(_,{children:[jsx($,{className:wa,children:jsxs(ca,{children:[jsx(da$1,{children:"Automation"}),jsx(da$1,{children:"Triggers"}),jsx(da$1,{children:"Last run"}),jsx(da$1,{className:"fk:text-center",children:"Runs"}),jsx(da$1,{children:"Visibility"}),jsx(da$1,{className:"fk:text-center",children:"Status"}),jsx(da$1,{})]})}),jsx(aa$1,{children:Array.from({length:5},(t$1,n)=>jsxs(ca,{children:[jsx(ea$1,{children:jsx(t,{className:"fk:h-4 fk:w-36"})}),jsx(ea$1,{children:jsx(t,{className:"fk:h-4 fk:w-48"})}),jsx(ea$1,{children:jsx(t,{className:"fk:h-4 fk:w-24"})}),jsx(ea$1,{className:"fk:text-center",children:jsx(t,{className:"fk:mx-auto fk:h-4 fk:w-8"})}),jsx(ea$1,{children:jsx(t,{className:"fk:h-4.75 fk:w-16"})}),jsx(ea$1,{className:"fk:text-center",children:jsx(t,{className:"fk:mx-auto fk:h-4.75 fk:w-16"})}),jsx(ea$1,{className:"fk:text-right",children:jsx(t,{className:"fk:ml-auto fk:size-8"})})]},n))})]})}function ya(t,n){let i=t.find(l=>l.id===n)?.value;return Array.isArray(i)?i.filter(l=>typeof l=="string"):[]}function Ti(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 Ci(t){if(t.length===0)return;let n=t.filter(o=>o==="project"||o==="space"||o==="personal");if(n.length!==0)return n}function Vl(){let{api:t,projectId:n}=u(),o$1=useNavigate(),[i,l]=useState([]),[k,f$2]=useState(""),[g$2,c$1]=useState(""),p=b(),d=useRef(null),v$1=ya(i,"status"),C=ya(i,"visibility"),T=Ti(v$1),j$1=Ci(C),A=i.length>0||k.trim().length>0,x=JSON.stringify({enabledFilter:T,search:k,visibilityFilter:j$1}),b$4=(N,E)=>!n||E&&E.hasMore===false?null:g(n).automations({enabled:T,limit:ba,offset:N*ba,search:k.trim()||void 0,visibility:j$1}),{data:P,isLoading:F,mutate:S,setSize:_$1,size:M}=It(b$4,f),{data:B}=De(n?g(n).spaces:null,f),U=useMemo(()=>new Map((B?.spaces??[]).map(N=>[N.id,N.label])),[B?.spaces]),w=P?.flatMap(N=>N.automations)??[],$$1=P?.[P.length-1]?.hasMore??false,he=P!==void 0&&M>P.length,q=P?.[0]?.count,be=F&&w.length===0,ye=useMemo(()=>[{id:"status",accessorKey:"enabled"},{id:"visibility",accessorKey:"visibility"}],[]),Be=useReactTable({columns:ye,data:w,getCoreRowModel:getCoreRowModel(),manualFiltering:true,onColumnFiltersChange:N=>{_$1(1),l(N);},state:{columnFilters:i}}),me=useRef(()=>{_$1(N=>N+1);}),dt=useRef($$1),Ce=useRef(he);me.current=()=>{_$1(N=>N+1);},dt.current=$$1,Ce.current=he;let ze=useCallback(N=>{if(!me.current||!dt.current||Ce.current)return;let E=N??d.current;if(!E)return;let{scrollHeight:ke,scrollTop:Pt,clientHeight:mt}=E;ke-Pt-mt>=pi(mt)||(Ce.current=true,me.current());},[]);useEffect(()=>{ze();},[ze,w.length,$$1,he,x]),useEffect(()=>{d.current?.scrollTo({top:0});},[x]);let je=useRef(k);je.current=k;let We=useCallback(N=>{N!==je.current&&(_$1(1),f$2(N));},[_$1]);if(!n||!t)return jsx(Z,{children:"Select a project to view automations."});async function Ge(N){if(c$1(""),!t)return;let E=await t.deleteAutomation(N.id);if(!E.success){c$1(Array.isArray(E.errorMessage)?E.errorMessage.join(", "):E.errorMessage);return}await S();}function $e(N){ze(N.currentTarget);}let R;return F&&w.length===0?R=jsx(Ni,{}):w.length===0?R=jsx(Z,{children:A?"No results.":"No automations yet."}):R=jsxs(_,{children:[jsx($,{className:wa,children:jsxs(ca,{children:[jsx(da$1,{children:"Automation"}),jsx(da$1,{children:"Triggers"}),jsx(da$1,{children:"Last run"}),jsx(da$1,{className:"fk:text-center",children:"Runs"}),jsx(da$1,{children:"Visibility"}),jsx(da$1,{className:"fk:text-center",children:"Status"}),jsx(da$1,{})]})}),jsx(aa$1,{children:w.map(N=>jsxs(ca,{className:"fk:cursor-pointer",onClick:()=>o$1(N.id),children:[jsx(ea$1,{children:jsx("span",{className:"fk:font-medium",children:N.name})}),jsx(ea$1,{className:"fk:text-muted-foreground",children:bi(N)}),jsx(ea$1,{children:N.lastRunAt?formatDistance(new Date(N.lastRunAt),new Date,{addSuffix:true}):"Never"}),jsx(ea$1,{className:"fk:text-center",children:N.totalRuns}),jsx(ea$1,{children:jsx(b$1,{className:"fk:h-4.75 fk:text-[0.6875rem] fk:leading-4.5 fk:tracking-wide",variant:N.visibility==="personal"?"secondary":"outline",children:xi(N,U)})}),jsx(ea$1,{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 ${N.enabled?"fk:bg-success/20 fk:text-success":"fk:bg-secondary fk:text-secondary-foreground"}`,variant:N.enabled?"default":"secondary",children:N.enabled?"Enabled":"Disabled"})}),jsx(ea$1,{className:"fk:text-right",children:jsxs(e,{children:[jsx(g$1,{asChild:true,children:jsx(b$2,{"aria-label":`Actions for ${N.name}`,size:"icon",type:"button",variant:"ghost",onClick:E=>{E.stopPropagation();},children:jsx(Ellipsis,{className:"fk:size-4"})})}),jsxs(h,{align:"end",className:"fk:w-40",children:[jsxs(j,{onClick:E=>{E.stopPropagation(),o$1(N.id);},children:[jsx(Pencil,{}),"Edit"]}),jsx(o,{}),jsxs(j,{disabled:!p,variant:"destructive",onClick:E=>{E.stopPropagation(),Ge(N);},children:[jsx(Trash2,{}),"Delete"]})]})]})})]},N.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"}),!be&&q!==void 0?jsxs("span",{className:"fk:ml-auto fk:text-sm fk:font-normal fk:text-muted-foreground",children:[q.toLocaleString()," ",q===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"})]})]})]}),g$2?jsx("div",{className:"fk:text-sm fk:text-destructive",children:g$2}):null,jsx(Oo,{actions:jsxs(Fragment,{children:[jsx(yi,{projectId:n}),p?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$1,{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&&k.trim().length>0,search:k,table:Be,onSearchChange:We}),jsxs("div",{className:"fk:relative fk:min-h-0 fk:min-w-0 fk:flex-1",children:[he?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:$e,ref:d,children:R})]})]})}function Ol(){let{api:t,projectId:n}=u(),o=useNavigate();return !n||!t?jsx(Z,{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(Fn,{api:t,mode:"create",projectId:n,onSaved:()=>o("..",{relative:"path"})})})})]})}function ql(){let{api:t,projectId:n}=u(),{automationId:o}=useParams(),i=useNavigate(),[l,k]=useTransition(),f$1=b(),{data:g$1,mutate:c$1}=De(n&&o?g(n).automation(o):null,f);if(!n||!t||!o)return jsx(Z,{children:"Select an automation."});if(!g$1?.automation)return jsx(Z,{children:"Loading automation..."});let p=t,d=Sa(g$1.automation)&&f$1,v$1=o;function C(){d&&k(async()=>{let T=await p.runAutomation(v$1);if(T.success&&T.runId){i(`runs/${T.runId}`);return}await c$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:g$1.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$1,{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$1,{disabled:!f$1,children:jsxs(b$2,{disabled:l||!d,size:"sm",onClick:C,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(Fn,{api:t,automation:g$1.automation,mode:"edit",projectId:n,onSaved:T=>{T?c$1({automation:T},{revalidate:false}):c$1();}})})})]})}var nn=25;function Jl(){let{api:t,projectId:n}=u(),{automationId:o}=useParams(),i=useNavigate(),[l,k]=useTransition(),{data:f$1}=De(n&&o?g(n).automation(o):null,f),g$1=(B,U)=>!n||!o||U&&U.hasMore===false?null:g(n).automationRuns(o,B*nn,nn),{data:c$1,isLoading:p,mutate:d,setSize:v$1,size:C}=It(g$1,f),T=b();if(!n||!t||!o)return jsx(Z,{children:"Select an automation to view runs."});let j=t,A=Sa(f$1?.automation)&&T,x=o;function b$1(){A&&k(async()=>{let B=await j.runAutomation(x);if(B.success&&B.runId){i(B.runId);return}await d();});}let P=c$1?.flatMap(B=>B.runs)??[],S=c$1?.[c$1.length-1]?.hasMore??false,_=c$1!==void 0&&C>c$1.length;function M(){v$1(B=>B+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:f$1?.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$1,{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$1,{disabled:!T,children:jsxs(b$2,{disabled:l||!A,size:"sm",onClick:b$1,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:p,runs:P}),S&&!_?jsx(an,{onVisible:M}):null,_?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 an({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(k=>{k.some(f=>f.isIntersecting)&&o.current();});return l.observe(i),()=>{l.disconnect();}},[]),jsx("div",{className:"fk:h-px",ref:n})}function jn(){return jsx(_,{children:jsx(aa$1,{children:Array.from({length:5},(t$1,n)=>jsxs(ca,{children:[jsx(ea$1,{className:"fk:py-2",children:jsx(t,{className:"fk:h-4 fk:w-28"})}),jsx(ea$1,{children:jsx(t,{className:"fk:h-4 fk:w-20"})}),jsx(ea$1,{children:jsx(t,{className:"fk:h-4.75 fk:w-16"})}),jsx(ea$1,{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(jn,{}):o.length===0?jsx(Z,{children:"No runs found."}):jsx(_,{children:jsx(aa$1,{children:o.map(i=>jsxs(ca,{children:[jsx(ea$1,{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$1,{className:"fk:text-muted-foreground",children:i.triggerType}),jsx(ea$1,{children:jsx(Ca,{status:i.status})}),jsx(ea$1,{className:"fk:max-w-md fk:truncate fk:text-muted-foreground",children:i.summary??""})]},i.id))})})}function Ul(){let{projectId:t$1}=u(),[n,o]=useState("team"),i=(x,b)=>!t$1||b&&!b.history.hasMore?null:g(t$1).runHistory(n,x*nn,nn),{data:l,isLoading:k,setSize:f$1,size:g$1}=It(i,f),c$1=l?.[0]?.history.metrics,p=l?.flatMap(x=>x.history.runs)??[],v=l?.[l.length-1]?.history.hasMore??false,C=l!==void 0&&g$1>l.length;if(!t$1)return jsx(Z,{children:"Select a project to view run history."});function T(){f$1(x=>x+1);}function j(x){!gi(x)||x===n||o(x);}let A=null;return k?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},(x,b)=>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"})]},b))}):c$1&&(A=jsxs("div",{className:"fk:mb-6 fk:grid fk:shrink-0 fk:gap-3 fk:grid-cols-4 fk:pr-4",children:[jsx(tn,{title:"Successful 24h",value:c$1.successful24h}),jsx(tn,{title:"Failed 24h",value:c$1.failed24h}),jsx(tn,{title:"Successful 7d",value:c$1.successful7d}),jsx(tn,{title:"Failed 7d",value:c$1.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$1,{value:n,onValueChange:j,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:k,runs:p.map(x=>({...x,id:`${x.automationId}/runs/${x.id}`}))}),v&&!C?jsx(an,{onVisible:T}):null,C?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 xa=25;function Si(t){return t==="pending"||t==="all"}function Hl(){let{api:t,projectId:n}=u(),[o,i]=useState("pending"),[l,k]=useState(null),f$1=(M,B)=>!n||B&&!B.hasMore?null:g(n).approvals({limit:xa,offset:M*xa,status:o==="pending"?"pending":void 0}),{data:g$1,isLoading:c$1,mutate:p,setSize:d$1,size:v}=It(f$1,f,{refreshInterval:3e4}),C=g$1?.flatMap(M=>M.approvals)??[],T=g$1?.[0]?.pendingCount??0,j=g$1?.[0],A=a();useEffect(()=>{j&&A(j);},[j,A]);let b=g$1?.[g$1.length-1]?.hasMore??false,P=g$1!==void 0&&v>g$1.length,F=C.find(M=>M.id===l)??null;if(useEffect(()=>{l===null||F!==null||c$1||g$1===void 0||k(null);},[g$1,c$1,F,l]),!n||!t)return jsx(Z,{children:"Select a project to view approvals."});function S(){d$1(M=>M+1);}function _$1(M){!Si(M)||M===o||(d$1(1),i(M));}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$1,{value:o,onValueChange:_$1,children:jsxs(ha,{children:[jsxs(ia,{value:"pending",children:["Pending",T>0?` (${T.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:[c$1?jsx(jn,{}):C.length===0?jsx(Z,{children:o==="pending"?"No proposals are waiting for approval.":"No approvals found."}):jsx(_,{children:jsx(aa$1,{children:C.map(M=>jsxs(ca,{className:"fk:cursor-pointer",onClick:()=>k(M.id),children:[jsx(ea$1,{children:jsx(b$4,{status:M.status})}),jsx(ea$1,{className:"fk:font-medium",children:M.operationsSummary}),jsx(ea$1,{className:"fk:text-muted-foreground",children:M.automationName}),jsx(ea$1,{className:"fk:text-muted-foreground",children:formatDistance(new Date(M.requestedAt),new Date,{addSuffix:true})}),jsx(ea$1,{onClick:B=>B.stopPropagation(),children:M.chatId?jsx(Link,{className:"fk:text-xs fk:text-muted-foreground hover:fk:underline",to:`../agent/chats/${M.chatId}`,children:"View chat"}):M.automationId&&M.runId?jsx(Link,{className:"fk:text-xs fk:text-muted-foreground hover:fk:underline",to:`../automations/${M.automationId}/runs/${M.runId}`,children:"View run"}):null})]},M.id))})}),b&&!P?jsx(an,{onVisible:S}):null,P?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:()=>k(null),onDecided:()=>{p();}},`${F.id}-${F.status}`):null]})}var Na=25,wi={attention:"fk:border-none fk:bg-amber-500/20 fk:text-amber-600 fk:corner-squircle",failure:"fk:border-none fk:bg-destructive/15 fk:text-destructive fk:corner-squircle",neutral:"fk:corner-squircle"};function Ai(t){return t==="needs_action"||t==="all"}function Ii(){let{mode:t}=f$5(),[n,o]=useState(()=>typeof Notification>"u"?"unsupported":Notification.permission);return n!=="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(i=>{o(i),i==="granted"&&t==="hosted"&&k().catch(()=>{});});},children:"Turn on"})]})}function Xl(){let{api:t,projectId:n}=u(),o=useNavigate(),i=b$5(),[l,k]=useState("needs_action"),[f$1,g$1]=useState(()=>new Set),c$2=a(),p=(S,_)=>!n||_&&!_.hasMore?null:g(n).activity({filter:l,limit:Na,offset:S*Na}),{data:d,isLoading:v,mutate:C,setSize:T,size:j}=It(p,f,{refreshInterval:3e4}),A=useMemo(()=>d?.flatMap(S=>S.items)??[],[d]),x=d?.[d.length-1]?.hasMore??false,b=d!==void 0&&j>d.length;if(useEffect(()=>{let S=A.filter(_=>_.state==="unread").map(_=>_.id);!t||!i||S.length===0||(g$1(_=>new Set([..._,...S])),t.markActivityRead(S).then(()=>c$2()));},[t,i,A,c$2]),!n||!t)return jsx(Z,{children:"Select a project to view activity."});function P(S){!Ai(S)||S===l||(T(1),k(S));}function F(S){t&&t.setActivityItemState(S.id,"dismissed").catch(_=>{oa$1.error(_ instanceof Error?_.message:"Unable to dismiss this item.");}).finally(()=>{C();});}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$1,{value:l,onValueChange:P,children:jsxs(ha,{children:[jsx(ia,{value:"needs_action",children:"Needs attention"}),jsx(ia,{value:"all",children:"All"})]})}),jsx(jo,{})]}),jsx(Ii,{}),jsx(w,{className:"fk:h-0 fk:min-h-0 fk:flex-1",children:jsxs("div",{className:"fk:pb-6 fk:pr-4",children:[v?jsx(jn,{}):A.length===0?jsx(Z,{children:l==="needs_action"?"Nothing needs your attention.":"No activity yet."}):jsx(_,{children:jsx(aa$1,{children:A.map(S=>{let _=e$2(S),M=c$1(S),B=d$1(S),U=g$2(S),w=f$2(S);return jsxs(ca,{className:"fk:cursor-pointer",onClick:()=>o(S.id),children:[jsx(ea$1,{className:"fk:w-4 fk:pr-0",children:f$1.has(S.id)||S.state==="unread"?jsx("span",{"aria-label":"Unread",className:"fk:block fk:size-2 fk:rounded-full fk:bg-primary"}):null}),jsxs(ea$1,{children:[jsx("div",{className:"fk:font-medium",children:S.title}),S.body?jsx("div",{className:"fk:text-xs fk:text-muted-foreground",children:S.body}):null]}),jsx(ea$1,{children:_?jsx(b$1,{className:wi[w],variant:w==="neutral"?"outline":"default",children:_}):null}),jsx(ea$1,{className:"fk:whitespace-nowrap fk:text-muted-foreground",children:formatDistance(new Date(S.createdAt),new Date,{addSuffix:true})}),jsx(ea$1,{className:"fk:whitespace-nowrap",onClick:H=>H.stopPropagation(),children:M&&B?jsx(Link,{className:"fk:text-xs fk:text-muted-foreground hover:fk:underline",to:`../${M}`,children:B}):null}),jsx(ea$1,{className:"fk:w-8",onClick:H=>H.stopPropagation(),children:U?null:jsxs(b$3,{children:[jsx(c,{asChild:true,children:jsx(b$2,{"aria-label":"Dismiss",size:"icon",variant:"ghost",onClick:()=>F(S),children:jsx(XIcon,{className:"fk:size-4"})})}),jsx(e$1,{children:"Dismiss"})]})})]},S.id)})})}),x&&!b?jsx(an,{onVisible:()=>{T(S=>S+1);}}):null,b?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 Kl(){let{api:t$1,projectId:n}=u(),{itemId:o=""}=useParams(),i=a(),{data:l,error:k,isLoading:f$1,mutate:g$1}=De(n&&o?g(n).activityItem(o):null,f),c$3=l?.item,p=c$3?.approvalId??null,{data:d,mutate:v$1}=De(n&&p?g(n).approval(p):null,f),C=c$3?.state==="unread",T=b$5();if(useEffect(()=>{!t$1||!C||!T||t$1.markActivityRead([o]).then(()=>{g$1(),i();});},[t$1,C,T,o,g$1,i]),!n||!t$1)return jsx(Z,{children:"Select a project to view activity."});let j=c$3?c$1(c$3):null,A=c$3?d$1(c$3):null,x;return k?x=jsx(Z,{children:"This activity item no longer exists."}):f$1||!c$3?x=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"})]}):x=jsxs("div",{className:"fk:flex fk:flex-col fk:gap-6",children:[jsxs("div",{className:"fk:text-sm fk:text-muted-foreground",children:[c$3.body?`${c$3.body} \xB7 `:"",formatDistance(new Date(c$3.createdAt),new Date,{addSuffix:true})]}),d?jsx(c$2,{api:t$1,approval:d.approval,chat:d.approval.chatId!==null,onDecided:()=>{g$1(),v$1(),i();}},`${d.approval.id}-${d.approval.status}`):p?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:c$3?.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"})]}),j&&A?jsx(b$2,{asChild:true,size:"sm",variant:"outline",children:jsx(Link,{to:`../${j}`,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:x})})]})}function tn({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 Wl(){let{api:t,projectId:n}=u(),{automationId:o,runId:i}=useParams(),{data:l,mutate:k}=De(n&&i?g(n).run(i):null,f,{refreshInterval:P=>!P?.run||z(P.run.status)?0:v$1}),{data:f$1}=De(n&&o?g(n).automation(o):null,f),[g$1,c$1]=useTransition(),[p,d]=useState(false);if(useEffect(()=>{d(false);},[i]),!n||!t||!o||!i)return jsx(Z,{children:"Select a run."});let v$2=t,C=i,T=l?.run,j=T?.status==="running"&&!p;function A(){c$1(async()=>{await v$2.cancelRun(C),await k();});}function x(){d(true),k();}function b(){k();}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:f$1?.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:T?`Run from ${format(new Date(T.startedAt),"PPpp")}`:"Loading run..."}),T?jsx(Ca,{status:T.status}):null]})]}),jsxs("div",{className:"fk:flex fk:items-center fk:gap-2",children:[T&&z(T.status)?jsx(b$2,{asChild:true,size:"sm",variant:"outline",children:jsx("a",{href:v$2.getTranscriptUrl(C),rel:"noreferrer",target:"_blank",children:"Transcript"})}):null,j?jsx(b$2,{disabled:g$1,size:"sm",variant:"destructive",onClick:A,children:g$1?"Cancelling...":"Cancel run"}):null]})]}),jsxs(_a,{className:"fk:h-0 fk:min-h-0 fk:flex-1",children:[jsx($a,{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:T?jsx(Mi,{api:t,run:T,onRunUpdated:b,onStreamFinished:x}):jsx(Z,{children:"Loading run..."})})}),jsx(bb,{})]})]})}function Pi(t){return t==="unavailable"?"No replay events were recorded.":t==="error"?"Unable to load run replay.":"Loading run replay..."}function Mi({api:t,onRunUpdated:n,onStreamFinished:o,run:i$1}){let{projectId:l}=u(),{workflowRunId:k}=i$1,f$1=k?t.getStreamUrl(k):"",[g$1,c]=useState(0),[p,d]=useState(false),[v,C]=useState([]),[T,j]=useState({}),A$1=useRef(null),{message:x,status:b}=A(f$1,{decidedApprovals:T,recordStatus:i$1.status,resumeToken:g$1,suppressApprovalPause:p}),P=useMemo(()=>x?[x]:[],[x]),F$1=y(P),S=useRef(n);S.current=n;let _=useRef(o);_.current=o;let M=useMemo(()=>({onApprovalDecided:(R,N)=>{R&&N&&N!=="pending"&&j(E=>({...E,[R]:N})),!(R&&A$1.current===R)&&(R&&(A$1.current=R),d(true),c(E=>E+1),S.current?.());}}),[]),B$1=!p&&i$1.status!=="running"&&!z(i$1.status)&&(b==="paused"||i$1.status==="awaiting_approval"||g$3(x)),U=a(),w=z(i$1.status);useEffect(()=>{(B$1||w)&&U();},[B$1,U,w]);let H=g$3(x),$=B$1&&!H&&l!=null,{data:he}=De($&&l?g(l).approvals({limit:25,offset:0,runId:i$1.id,status:"pending"}):null,f,{refreshInterval:v$1}),q=useMemo(()=>new Set(h$1(x)),[x]),be=v.filter(R=>!q.has(R.id)),Be=!z(i$1.status)&&(b==="streaming"||b==="paused"),me=F$1.length>0||be.length>0||Be;if(useEffect(()=>{c(0),d(false),A$1.current=null,C([]),j({});},[i$1.id]),useEffect(()=>{let R=he?.approvals;R?.length&&C(N=>{let E=new Map(N.map(ke=>[ke.id,ke]));for(let ke of R)E.set(ke.id,ke);return [...E.values()]});},[he]),useEffect(()=>{C(R=>{if(R.length===0)return R;let N=R.filter(E=>!q.has(E.id));return N.length===R.length?R:N});},[q]),useEffect(()=>{if(!p)return;if(i$1.status==="running"){d(false);return}if(i$1.status!=="awaiting_approval")return;let R=i(x),N=A$1.current;R.length===0||N===null||R.every(E=>E!==N)&&d(false);},[x,i$1.status,p]),useEffect(()=>{b==="finished"&&_.current?.();},[b]),useEffect(()=>{b==="paused"&&S.current?.();},[b]),useEffect(()=>{if(i$1.status!=="awaiting_approval")return;let R=window.setInterval(()=>{S.current?.();},v$1);return ()=>{window.clearInterval(R);}},[i$1.status]),!k)return jsx(Z,{children:"The run has not started streaming yet."});let Ce=Be||B$1&&b!=="finished"&&b!=="error",ze=x?.parts[x.parts.length-1],je=ze?.type==="text"&&ze.state==="streaming",We=B$1?"Awaiting approval":f$3(x)??"Thinking",Ge=B$1||!je,$e=Pi(b);return jsx(w$1.Provider,{value:M,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,b==="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,b==="error"&&!me?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,me?jsxs("div",{className:"fk:space-y-5 fk:rounded-md fk:bg-background fk:corner-squircle",children:[F$1.map(R=>jsx(Ri,{api:t,message:R},R.id)),be.map(R=>jsx(F,{api:t,message:B(R)},R.id)),Ce?jsx(E,{label:We,visible:Ge}):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:[b==="unavailable"||b==="error"?jsx(TriangleAlertIcon,{className:"fk:size-4"}):jsx(LoaderCircle,{className:"fk:size-4 fk:animate-spin"}),jsx("span",{children:$e})]})]})})}function Ri({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,k)=>jsx(C,{api:t,part:l,partIndex:k,parts:i},k))})]})}
4
- export{Kl as ActivityItemPage,Xl as ActivityPage,Hl as ApprovalsPage,ql as AutomationDetailPage,Vl as AutomationsPage,Ol as CreateAutomationPage,Wl as RunDetailPage,Ul as RunHistoryPage,Jl as RunsPage};//# sourceMappingURL=pages-LZKWC2H3.js.map
5
- //# sourceMappingURL=pages-LZKWC2H3.js.map
@@ -1,2 +0,0 @@
1
- import'./index.css';export{c as CatalogHeader,e as InstalledPluginsPage,b as PluginConnectControl,f as PluginDetailPage,d as PluginsPage}from'./chunk-HZJNNJOK.js';import'./chunk-ROCYIGFD.js';import'./chunk-SV5KK5K6.js';import'./chunk-TYDYAOQ7.js';import'./chunk-YCCFUGWJ.js';import'./chunk-32ZU4MLE.js';import'./chunk-HDOIOXMP.js';import'./chunk-SZEGGBOC.js';import'./chunk-U45E5X3H.js';import'./chunk-USNXQOMJ.js';import'./chunk-6NRQMG26.js';import'./chunk-O2QMYUPS.js';//# sourceMappingURL=plugin-pages-YJFH66UO.js.map
2
- //# sourceMappingURL=plugin-pages-YJFH66UO.js.map
@@ -1,2 +0,0 @@
1
- import'./index.css';import {a}from'./chunk-WQUCLXMU.js';import {b,c}from'./chunk-6SAZGEAA.js';import'./chunk-L66FPBO7.js';import {g,f as f$1}from'./chunk-ROCYIGFD.js';import {f}from'./chunk-SV5KK5K6.js';import'./chunk-TYDYAOQ7.js';import {L,P,M,R,T as T$1,s as s$1,Q,U as U$1,V,W,O}from'./chunk-YCCFUGWJ.js';import {b as b$1}from'./chunk-32ZU4MLE.js';import'./chunk-HDOIOXMP.js';import'./chunk-SZEGGBOC.js';import'./chunk-U45E5X3H.js';import'./chunk-USNXQOMJ.js';import'./chunk-6NRQMG26.js';import'./chunk-O2QMYUPS.js';import {Outlet,useLocation,NavLink}from'react-router-dom';import {useState}from'react';import {SearchIcon,XIcon,SquarePenIcon,BellIcon,BotIcon,HistoryIcon,InboxIcon,PlugIcon}from'lucide-react';import Q$1 from'swr';import {jsxs,jsx}from'react/jsx-runtime';var K=300,s=NavLink;function T(){let{currentProjectId:a}=f(),{data:e}=Q$1(a?g(a).approvalsCount:null,f$1,{refreshInterval:3e4}),o=e?.pendingCount??0;return o===0?null:jsx(b$1,{className:"fk:ml-auto fk:h-5 fk:min-w-5 fk:justify-center fk:rounded-full fk:bg-amber-500/20 fk:px-1.5 fk:text-[0.6875rem] fk:text-amber-600 fk:border-none fk:corner-squircle",children:o>99?"99+":o.toString()})}function U(){let{currentProjectId:a$1}=f(),e=a(a$1),o=e?.needsActionCount??0,f$1=o>0?o:e?.unreadCount??0;return f$1===0?null:jsx(b$1,{className:`fk:ml-auto fk:h-5 fk:min-w-5 fk:justify-center fk:rounded-full fk:px-1.5 fk:text-[0.6875rem] fk:border-none fk:corner-squircle ${o>0?"fk:bg-amber-500/20 fk:text-amber-600":"fk:bg-muted fk:text-muted-foreground"}`,children:f$1>99?"99+":f$1.toString()})}function B(){let e=useLocation().pathname.replace(/\/$/,""),o=e.endsWith("/ai/agent"),f=e.endsWith("/ai/runs"),w=e.endsWith("/ai/approvals"),P=e.endsWith("/ai/activity")||e.includes("/ai/activity/"),R$1=e.includes("/ai/plugins")||e.includes("/ai/skills"),W$1=e.includes("/ai/automations"),[d,k]=useState(""),E=b(d.trim(),K);return jsxs(M,{collapsible:"icon",variant:"inset",children:[jsx(R,{className:"fk:shrink-0 fk:pb-1.5 fk:group-data-[collapsible=icon]:hidden",children:jsxs(T$1,{className:"fk:relative",children:[jsx(SearchIcon,{className:"fk:absolute fk:left-2 fk:top-1/2 fk:size-3.5 fk:-translate-y-1/2 fk:text-muted-foreground"}),jsx(s$1,{className:"fk:h-8 fk:bg-background fk:pl-7 fk:pr-7 fk:text-sm",placeholder:"Search chats...",value:d,onChange:L=>k(L.target.value)}),d?jsx("button",{"aria-label":"Clear search",className:"fk:absolute fk:right-2 fk:top-1/2 fk:-translate-y-1/2 fk:cursor-pointer fk:text-muted-foreground fk:hover:text-foreground",type:"button",onClick:()=>k(""),children:jsx(XIcon,{className:"fk:size-3.5"})}):null]})}),jsxs(Q,{children:[jsx(R,{children:jsxs(U$1,{children:[jsx(V,{children:jsx(W,{asChild:true,isActive:o,tooltip:"New chat",children:jsxs(s,{to:"agent",children:[jsx(SquarePenIcon,{className:"fk:h-4 fk:w-4",strokeWidth:2}),jsx("span",{children:"New chat"})]})})}),jsx(V,{children:jsx(W,{asChild:true,isActive:P,tooltip:"Activity",children:jsxs(s,{to:"activity",children:[jsx(BellIcon,{className:"fk:h-4 fk:w-4",strokeWidth:2}),jsx("span",{children:"Activity"}),jsx(U,{})]})})}),jsx(V,{children:jsx(W,{asChild:true,isActive:W$1,tooltip:"Automations",children:jsxs(s,{to:"automations",children:[jsx(BotIcon,{className:"fk:h-4 fk:w-4",strokeWidth:2}),jsx("span",{children:"Automations"})]})})}),jsx(V,{children:jsx(W,{asChild:true,isActive:f,tooltip:"Run History",children:jsxs(s,{to:"runs",children:[jsx(HistoryIcon,{className:"fk:h-4 fk:w-4",strokeWidth:2}),jsx("span",{children:"Run History"})]})})}),jsx(V,{children:jsx(W,{asChild:true,isActive:w,tooltip:"Approvals",children:jsxs(s,{to:"approvals",children:[jsx(InboxIcon,{className:"fk:h-4 fk:w-4",strokeWidth:2}),jsx("span",{children:"Approvals"}),jsx(T,{})]})})}),jsx(V,{children:jsx(W,{asChild:true,isActive:R$1,tooltip:"Plugins",children:jsxs(s,{to:"plugins",children:[jsx(PlugIcon,{className:"fk:size-4"}),jsx("span",{children:"Plugins"})]})})})]})}),jsx(R,{className:"fk:mt-4 fk:group-data-[collapsible=icon]:hidden",children:jsx(T$1,{children:jsx(c,{query:E})})})]}),jsx(O,{})]})}var F="flexkit:sidebar:state";function pt(){let{currentProjectId:a}=f(),e=document.cookie.split("; ").find(o=>o.startsWith(`${F}=`))?.split("=")[1]!=="false";return a?jsxs(L,{className:"fk:h-full",defaultOpen:e,children:[jsx(B,{}),jsx(P,{className:"fk:min-w-0",children:jsx("div",{className:"fk:flex fk:h-full fk:min-h-0 fk:min-w-0 fk:flex-col fk:overflow-hidden fk:pl-4 fk:pt-3",children:jsx("div",{className:"fk:flex fk:min-h-0 fk:min-w-0 fk:flex-1 fk:flex-col",children:jsx(Outlet,{})})})})]}):jsx("main",{className:"fk:flex fk:h-full fk:flex-1 fk:items-center fk:justify-center fk:p-8 fk:text-sm fk:text-muted-foreground",children:"Select a project to manage automations and skills."})}export{pt as Root};//# sourceMappingURL=root-VJPSB2DG.js.map
2
- //# sourceMappingURL=root-VJPSB2DG.js.map
@@ -1,2 +0,0 @@
1
- import'./index.css';import {c}from'./chunk-HZJNNJOK.js';import {f,g,d as d$1}from'./chunk-ROCYIGFD.js';import {b}from'./chunk-V64P56OA.js';import {f as f$1}from'./chunk-SV5KK5K6.js';import {h}from'./chunk-TYDYAOQ7.js';import {Rc,Tc,s,ma,oa,N,e as e$2,ga,ha,ia}from'./chunk-YCCFUGWJ.js';import {v,w,b as b$3}from'./chunk-32ZU4MLE.js';import {a,d,c as c$1,e,g as g$1}from'./chunk-HDOIOXMP.js';import {t}from'./chunk-SZEGGBOC.js';import'./chunk-U45E5X3H.js';import {b as b$2,c as c$2,e as e$1}from'./chunk-USNXQOMJ.js';import {b as b$1}from'./chunk-6NRQMG26.js';import'./chunk-O2QMYUPS.js';import {useState,useRef,useMemo,useEffect}from'react';import {Plus,LoaderCircle,Trash2,GraduationCapIcon,ArrowLeft,Info,PenLine,Eye}from'lucide-react';import Pt from'react-markdown';import {useNavigate,Link,useParams}from'react-router-dom';import ve from'swr';import At from'swr/infinite';import {history,defaultKeymap,historyKeymap,indentWithTab}from'@codemirror/commands';import {markdown}from'@codemirror/lang-markdown';import {languages}from'@codemirror/language-data';import {foldGutter,indentOnInput,bracketMatching,foldKeymap}from'@codemirror/language';import {highlightSelectionMatches,searchKeymap}from'@codemirror/search';import {Compartment,EditorState,Prec}from'@codemirror/state';import {EditorView,lineNumbers,highlightActiveLineGutter,highlightSpecialChars,drawSelection,dropCursor,highlightActiveLine,keymap,placeholder}from'@codemirror/view';import {tags}from'@lezer/highlight';import {createTheme}from'@uiw/codemirror-themes';import {jsx,jsxs,Fragment}from'react/jsx-runtime';var je="var(--font-geist-mono), ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace",Q="#212121",Y="#fafafa";function ze(t,i,o){return [t,EditorView.theme({"&":{backgroundColor:i},".cm-scroller":{backgroundColor:i},".cm-gutters":{backgroundColor:o}})]}var ce=ze(createTheme({settings:{background:Q,caret:"#f8f8f0",fontFamily:je,foreground:"#f8f8f2",gutterBackground:Q,gutterBorder:"transparent",gutterForeground:"#6d8a88",lineHighlight:"rgba(255, 255, 255, 0.1)",selection:"rgba(255, 255, 255, 0.1)",selectionMatch:"rgba(255, 255, 255, 0.2)"},styles:[{color:"#6272a4",tag:[tags.comment,tags.quote,tags.strikethrough]},{color:"#6272a4",tag:[tags.meta,tags.processingInstruction]},{color:"#f1fa8c",tag:tags.string},{color:"#f91f6f",tag:[tags.atom,tags.bool,tags.number,tags.heading]},{color:"#ff79c6",tag:[tags.keyword,tags.operator,tags.tagName]},{color:"#8be9fd",tag:[tags.typeName,tags.link,tags.url]},{color:"#009fb8",tag:[tags.className,tags.attributeName,tags.monospace]},{color:"#66d9ef",tag:[tags.propertyName,tags.function(tags.propertyName)]},{color:"#009fb8",tag:[tags.definition(tags.variableName),tags.function(tags.variableName)]},{color:"#0072f5",tag:[tags.strong,tags.emphasis]},{color:"#ff5555",tag:tags.invalid}],theme:"dark"}),Q,Q),de=ze(createTheme({settings:{background:Y,caret:"#526fff",fontFamily:je,foreground:"#383a42",gutterBackground:Y,gutterBorder:"transparent",gutterForeground:"#9d9d9f",lineHighlight:"#383a420c",selection:"#e5e5e6",selectionMatch:"#e5e5e6"},styles:[{color:"#a0a1a7",tag:[tags.comment,tags.quote,tags.strikethrough]},{color:"#a0a1a7",tag:[tags.meta,tags.processingInstruction]},{color:"#50a14f",tag:tags.string},{color:"#986801",tag:[tags.attributeName]},{color:"#a626a4",tag:tags.keyword},{color:"#0072f5",tag:[tags.operator,tags.strong,tags.emphasis]},{color:"#f91f6f",tag:[tags.atom,tags.bool,tags.number,tags.heading]},{color:"#c18401",tag:[tags.typeName,tags.className]},{color:"#009fb8",tag:[tags.tagName,tags.propertyName,tags.monospace]},{color:"#4078f2",tag:[tags.link,tags.url,tags.function(tags.variableName),tags.definition(tags.variableName)]},{color:"#f91f6f",tag:tags.invalid}],theme:"light"}),Y,Y);function me(){let t=document.documentElement;return t.getAttribute("data-theme")==="dark"||t.classList.contains("dark")||t.style.colorScheme==="dark"}var xt=EditorView.theme({"&":{fontSize:"13px",height:"100%",maxHeight:"100%",maxWidth:"100%",minHeight:"0",minWidth:"0",width:"100%"},"&.cm-focused":{outline:"none"},".cm-scroller":{height:"100%",lineHeight:"1.6",minHeight:"0",minWidth:"0",overflow:"auto",width:"100%"},".cm-content":{fontSize:"13px",fontStyle:"normal",fontWeight:"400",minWidth:"0 !important",padding:"12px 0"},".cm-line, .cm-line span":{fontSize:"inherit",fontStyle:"inherit",fontWeight:"inherit",lineHeight:"inherit"},".cm-gutters":{borderRight:"1px solid transparent"},".cm-foldPlaceholder":{backgroundColor:"transparent",border:"none"}});function ue(t){return [t?ce:de,xt]}function He(t){return [EditorState.readOnly.of(t),EditorView.editable.of(!t)]}function Oe(t){let i={"aria-multiline":"true",role:"textbox"};return t.ariaLabel&&(i["aria-label"]=t.ariaLabel),t.ariaLabelledBy&&(i["aria-labelledby"]=t.ariaLabelledBy),t.ariaDescribedBy&&(i["aria-describedby"]=t.ariaDescribedBy),t.ariaInvalid&&(i["aria-invalid"]="true"),t.readOnly&&(i["aria-readonly"]="true"),i}function Xe({ariaDescribedBy:t,ariaInvalid:i,ariaLabel:o,ariaLabelledBy:l,className:f,onBlur:d,onChange:k,onSave:u,placeholder:m,readOnly:c=false,value:p}){let h=useRef(null),y=useRef(null),L=useRef(new Compartment),P=useRef(new Compartment),N=useRef(new Compartment),C=useRef(d),w=useRef(k),I=useRef(u),v=useRef(p);return C.current=d,w.current=k,I.current=u,v.current=p,useEffect(()=>{let s=h.current;if(!s)return;let g=new EditorView({parent:s,state:EditorState.create({doc:v.current,extensions:[lineNumbers(),highlightActiveLineGutter(),highlightSpecialChars(),history(),foldGutter(),drawSelection(),dropCursor(),EditorState.allowMultipleSelections.of(true),indentOnInput(),bracketMatching(),highlightActiveLine(),highlightSelectionMatches(),EditorView.lineWrapping,markdown({codeLanguages:languages}),keymap.of([...defaultKeymap,...historyKeymap,...searchKeymap,...foldKeymap,indentWithTab]),Prec.highest(keymap.of([{key:"Mod-s",run:()=>(I.current?.(),true)}])),EditorView.updateListener.of(B=>{B.docChanged&&w.current?.(B.state.doc.toString()),B.focusChanged&&!B.view.hasFocus&&C.current?.();}),L.current.of(ue(me())),P.current.of(He(c)),N.current.of(EditorView.contentAttributes.of(Oe({ariaDescribedBy:t,ariaInvalid:i,ariaLabel:o,ariaLabelledBy:l,readOnly:c}))),...m?[placeholder(m)]:[]]})});y.current=g;let K=new ResizeObserver(()=>{g.requestMeasure();});K.observe(s);let G=new MutationObserver(()=>{g.dispatch({effects:L.current.reconfigure(ue(me()))});});return G.observe(document.documentElement,{attributeFilter:["class","data-theme","style"],attributes:true}),()=>{K.disconnect(),G.disconnect(),g.destroy(),y.current=null;}},[]),useEffect(()=>{let s=y.current;s&&s.dispatch({effects:L.current.reconfigure(ue(me()))});},[de,ce]),useEffect(()=>{let s=y.current;if(!s)return;let g=s.state.doc.toString();g!==p&&s.dispatch({changes:{from:0,to:g.length,insert:p}});},[p]),useEffect(()=>{let s=y.current;s&&s.dispatch({effects:[P.current.reconfigure(He(c)),N.current.reconfigure(EditorView.contentAttributes.of(Oe({ariaDescribedBy:t,ariaInvalid:i,ariaLabel:o,ariaLabelledBy:l,readOnly:c})))]});},[t,i,o,l,c]),jsx("div",{className:f??"fk:h-full fk:min-h-0 fk:min-w-0 fk:w-full fk:overflow-hidden",ref:h})}var Je=25,Bt=[{descriptionWidth:"fk:w-44",id:"skill-a",nameWidth:"fk:w-28"},{descriptionWidth:"fk:w-52",id:"skill-b",nameWidth:"fk:w-20"},{descriptionWidth:"fk:w-40",id:"skill-c",nameWidth:"fk:w-36"},{descriptionWidth:"fk:w-48",id:"skill-d",nameWidth:"fk:w-24"},{descriptionWidth:"fk:w-36",id:"skill-e",nameWidth:"fk:w-32"},{descriptionWidth:"fk:w-56",id:"skill-f",nameWidth:"fk:w-16"}];function Wt(){return jsxs("div",{"aria-busy":"true",className:"fk:grid fk:grid-cols-1 fk:gap-x-16 fk:gap-y-1 fk:lg:grid-cols-2",children:[jsx("span",{className:"fk:sr-only",children:"Loading skills"}),Bt.map(t$1=>jsxs("div",{className:"fk:-mx-3 fk:flex fk:min-w-0 fk:items-center fk:gap-3 fk:px-3 fk:py-2",children:[jsx(t,{className:"fk:size-10 fk:shrink-0 fk:rounded-lg"}),jsxs("span",{className:"fk:flex fk:min-w-0 fk:flex-1 fk:flex-col fk:gap-1.5",children:[jsx(t,{className:`fk:h-4 ${t$1.nameWidth}`}),jsx(t,{className:`fk:h-4 ${t$1.descriptionWidth}`})]})]},t$1.id))]})}var Rt={code({children:t,className:i,node:o,...l}){return typeof i=="string"&&i.split(" ").some(d=>d.startsWith("language-"))?jsx("code",{className:i,...l,children:t}):jsx("code",{className:"fk:rounded fk:bg-muted fk:px-1.5 fk:py-0.5 fk:font-mono fk:text-[0.875em] fk:font-medium fk:before:content-none fk:after:content-none fk:corner-squircle",...l,children:t})}};function be(){let{currentProjectId:t}=f$1();return {api:useMemo(()=>t?d$1(t):null,[t]),projectId:t}}function ie({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 jt({onVisible:t}){let i=useRef(null),o=useRef(t);return o.current=t,useEffect(()=>{let l=i.current;if(!l)return;let f=new IntersectionObserver(d=>{d.some(k=>k.isIntersecting)&&o.current();});return f.observe(l),()=>{f.disconnect();}},[]),jsx("div",{"aria-hidden":true,className:"fk:h-px",ref:i})}function zt(t,i){return t.visibility==="space"?(t.spaceId?i.get(t.spaceId):void 0)??"Space":t.visibility==="personal"?"Personal":"Project"}function Dt({skill:t}){return t.logoUrl?jsx("img",{alt:"",className:"fk:size-10 fk:shrink-0 fk:rounded-lg fk:corner-squircle",src:t.logoUrl}):jsx("span",{className:"fk:flex fk:size-10 fk:shrink-0 fk:items-center fk:justify-center fk:rounded-lg fk:bg-muted fk:text-muted-foreground fk:corner-squircle",children:jsx(GraduationCapIcon,{className:"fk:size-5"})})}function hi(){let{api:t,projectId:i}=be(),o=useNavigate(),[l,f$1]=useState(""),d=b(),k=l.trim().length>0,u=(s,g$1)=>!i||g$1&&!g$1.hasMore?null:g(i).skills({limit:Je,offset:s*Je,search:l.trim()||void 0}),{data:m,isLoading:c$1,setSize:p,size:h}=At(u,f),y=m?.flatMap(s=>s.skills)??[],P=m?.[m.length-1]?.hasMore??false,N=m!==void 0&&h>m.length,C=c$1&&y.length===0;if(!i||!t)return jsx(ie,{children:"Select a project to view skills."});function w(){p(s=>s+1);}let I="No skills yet.";k&&(I="No skills match your search.");let v=jsx("div",{className:"fk:grid fk:grid-cols-1 fk:gap-x-16 fk:gap-y-1 fk:lg:grid-cols-2",children:y.map(s=>jsxs("button",{type:"button",onClick:()=>o(s.id),className:"fk:-mx-3 fk:flex fk:min-w-0 fk:items-center fk:gap-3 fk:rounded-lg fk:px-3 fk:py-2 fk:text-left fk:transition-colors fk:hover:bg-accent fk:focus-visible:bg-accent fk:focus-visible:outline-none fk:corner-squircle",children:[jsx(Dt,{skill:s}),jsxs("span",{className:"fk:min-w-0 fk:flex-1",children:[jsx("span",{className:"fk:block fk:truncate fk:text-sm fk:font-medium",children:s.name}),jsx("span",{className:"fk:block fk:truncate fk:text-sm fk:text-muted-foreground",children:s.description})]})]},s.id))});return C?v=jsx(Wt,{}):y.length===0&&(v=jsx(Rc,{children:jsx(Tc,{children:I})})),jsxs("main",{className:"fk:flex fk:min-h-0 fk:flex-1 fk:flex-col",children:[jsx(c,{}),jsx("div",{className:"fk:min-h-0 fk:flex-1 fk:overflow-auto",children:jsxs("div",{className:"fk:mx-auto fk:flex fk:w-full fk:max-w-4xl fk:flex-col fk:gap-8 fk:py-6 fk:pl-4 fk:pr-6",children:[jsxs("div",{children:[jsx("h2",{className:"fk:text-2xl fk:font-semibold",children:"Skills for your agents"}),jsx("p",{className:"fk:mt-2 fk:text-muted-foreground",children:"Reusable Markdown instructions that agents load when relevant, or always when attached to an automation."})]}),jsxs("div",{className:"fk:flex fk:flex-wrap fk:items-center fk:gap-3",children:[jsx(s,{"aria-label":"Search skills",className:"fk:w-full fk:max-w-xs",placeholder:"Search skills\u2026",value:l,onChange:s=>{p(1),f$1(s.target.value);}}),d?jsx(b$1,{asChild:true,className:"fk:ml-auto",size:"sm",children:jsxs(Link,{to:"new",children:[jsx(Plus,{}),"New Skill"]})}):jsx(ma,{disabled:true,children:jsxs(b$1,{className:"fk:ml-auto",disabled:true,size:"sm",children:[jsx(Plus,{}),"New Skill"]})})]}),v,P&&!N?jsx(jt,{onVisible:w}):null,N?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 skills..."})]}):null]})})]})}function te({className:t,id:i,message:o}){return jsx("p",{className:`fk:text-sm fk:text-destructive ${t??""}`,id:i,children:o})}function D({children:t,hint:i,htmlFor:o,id:l}){return jsxs("div",{className:"fk:mb-1.5 fk:pl-2.5 fk:flex fk:items-center fk:gap-1",children:[jsx(e$2,{htmlFor:o,id:l,children:t}),jsxs(b$2,{children:[jsx(c$2,{asChild:true,children:jsx("button",{"aria-label":`About ${t.toLowerCase()}`,className:"fk:rounded-sm fk:text-muted-foreground hover:fk:text-foreground fk:corner-squircle",type:"button",children:jsx(Info,{className:"fk:size-3.5"})})}),jsx(e$1,{className:"fk:max-w-xs",children:i})]})]})}function Se({actions:t,title:i}){return jsxs(Fragment,{children:[jsxs("div",{className:"fk:flex fk:shrink-0 fk:items-center fk:gap-2 fk:pr-4",children:[jsxs(b$2,{children:[jsx(c$2,{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:h-4"}),jsx("h1",{className:"fk:min-w-0 fk:flex-1 fk:truncate fk:text-lg fk:font-semibold fk:leading-none fk:tracking-tight",children:i}),t]}),jsx(b$1,{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"}),"Skills"]})})]})}function Ht(){return jsxs("div",{"aria-busy":"true",className:"fk:flex fk:h-full fk:min-h-0 fk:min-w-0 fk:flex-col fk:gap-3 fk:overflow-hidden fk:pb-3",children:[jsx("span",{className:"fk:sr-only",children:"Loading skill"}),jsx(Se,{actions:jsx(t,{className:"fk:h-8 fk:w-24"}),title:jsx(t,{className:"fk:h-5 fk:w-40"})}),jsxs("div",{className:"fk:m-auto fk:flex fk:min-h-0 fk:w-full fk:max-w-6xl fk:flex-1 fk:flex-col fk:gap-8 fk:px-6",children:[jsxs("div",{className:"fk:grid fk:shrink-0 fk:gap-3 fk:lg:grid-cols-[minmax(0,1fr)_minmax(0,1.6fr)_auto]",children:[["name","description"].map(t$1=>jsxs("div",{className:"fk:flex fk:flex-col fk:gap-2",children:[jsx(t,{className:"fk:h-4 fk:w-20"}),jsx(t,{className:"fk:h-9 fk:w-full"})]},t$1)),jsxs("div",{className:"fk:flex fk:flex-col fk:gap-2",children:[jsx(t,{className:"fk:h-4 fk:w-20"}),jsx(t,{className:"fk:h-9 fk:w-32"})]})]}),jsxs("div",{className:"fk:flex fk:min-h-0 fk:flex-1 fk:flex-col fk:gap-1.5",children:[jsx(t,{className:"fk:h-4 fk:w-16"}),jsx(t,{className:"fk:min-h-48 fk:flex-1 fk:rounded-md"})]})]})]})}function Ke({content:t,onBlur:i,onChange:o,onSave:l,readOnly:f=false,showContentError:d,validationMessage:k}){let[u,m]=useState("write"),c=t.length>5e4,p;return t.trim()?p=jsx(Pt,{components:Rt,children:t}):p=jsx("p",{className:"fk:text-muted-foreground",children:"Nothing to preview."}),jsxs("div",{className:"fk:flex fk:min-h-0 fk:min-w-0 fk:flex-1 fk:flex-col fk:gap-1.5",children:[jsxs("div",{className:"fk:pl-3.25 fk:flex fk:shrink-0 fk:items-center fk:gap-1",children:[jsx(e$2,{htmlFor:"skill-content",id:"skill-content-label",children:"Content"}),jsxs(b$2,{children:[jsx(c$2,{asChild:true,children:jsx("button",{"aria-label":"About skill content",className:"fk:rounded-sm fk:text-muted-foreground hover:fk:text-foreground fk:corner-squircle",type:"button",children:jsx(Info,{className:"fk:size-3.5"})})}),jsx(e$1,{className:"fk:max-w-sm",children:"The skill itself, in Markdown. Write it like instructions for a capable colleague: procedures, rules, examples, and edge cases. Attached skills are always loaded; other visible skills are loaded on demand."})]})]}),jsxs("div",{className:`fk:flex fk:min-h-0 fk:min-w-0 fk:flex-1 fk:flex-col fk:ml-0.75 fk:overflow-hidden fk:rounded-md fk:border ${d?"fk:border-destructive":""} fk:corner-squircle`,children:[jsxs("div",{className:"fk:flex fk:shrink-0 fk:items-center fk:justify-between fk:gap-2 fk:border-b fk:px-2.5 fk:py-1",children:[jsx(ga,{value:u,onValueChange:h=>{m(h==="preview"?"preview":"write");},children:jsxs(ha,{children:[jsxs(b$2,{children:[jsx(c$2,{asChild:true,children:jsx("span",{className:"fk:inline-flex",children:jsx(ia,{"aria-label":"Write",className:"fk:px-2.5",value:"write",children:jsx(PenLine,{className:"fk:size-3.5"})})})}),jsx(e$1,{children:"Write"})]}),jsxs(b$2,{children:[jsx(c$2,{asChild:true,children:jsx("span",{className:"fk:inline-flex",children:jsx(ia,{"aria-label":"Preview",className:"fk:px-2.5",value:"preview",children:jsx(Eye,{className:"fk:size-3.5"})})})}),jsx(e$1,{children:"Preview"})]})]})}),jsxs("span",{className:c?"fk:text-xs fk:text-destructive":"fk:text-xs fk:text-muted-foreground",children:[t.length.toLocaleString()," / ",5e4.toLocaleString()]})]}),jsx("div",{className:"fk:min-h-0 fk:min-w-0 fk:flex-1 fk:overflow-hidden",hidden:u!=="write",children:jsx(Xe,{ariaDescribedBy:d?"skill-content-error":void 0,ariaInvalid:d,ariaLabelledBy:"skill-content-label",className:"fk:h-full fk:min-h-0 fk:min-w-0 fk:w-full fk:overflow-hidden",readOnly:f,value:t,onBlur:i,onChange:o,onSave:l})}),u==="preview"?jsx(w,{className:"fk:min-h-0 fk:flex-1",children:jsx("div",{className:"fk:prose fk:prose-sm fk:dark:prose-invert fk:max-w-none fk:px-4 fk:py-3",children:p})}):null,d&&k?jsx(te,{className:"fk:border-t fk:px-3 fk:py-2",id:"skill-content-error",message:k}):null]})]})}function Ge({api:t,mode:i,onSaved:o,projectId:l,skill:f$1}){let[d$1,k]=useState(f$1?.name??""),[u,m]=useState(f$1?.description??""),[c,p]=useState(f$1?.content??""),[h$1,y]=useState(f$1?.visibility??"project"),[L,P]=useState(f$1?.spaceId??null),[N,C]=useState(false),w=useRef(false),[I,v]=useState(""),[s$1,g$2]=useState({content:false,description:false,name:false}),K=useNavigate(),{data:G}=ve(g(l).spaces,f),[,B]=h(),H=b(),$e=B.user?.spaces??[],xe=(G?.spaces??[]).filter(a=>$e.includes(a.code)),ne="";c.trim()?c.length>5e4&&(ne=`Content must be at most ${String(5e4)} characters`):ne="Content is required";let b$2={content:ne,description:u.trim()?"":"Description is required",name:d$1.trim()?"":"Name is required",space:h$1==="space"&&!L?"Select a space":""},ae=!b$2.content&&!b$2.description&&!b$2.name&&!b$2.space,$=s$1.name&&!!b$2.name,U=s$1.description&&!!b$2.description,Ue=s$1.content&&!!b$2.content,Ze=i==="create"?"New Skill":f$1?.name??"Skill",se="Update skill";N?se="Saving...":i==="create"&&(se="Create skill");async function ye(){if(!H||w.current)return;if(!ae){g$2({content:true,description:true,name:true});return}w.current=true,C(true),v("");let a={content:c,description:u,name:d$1,spaceId:h$1==="space"?L:null,visibility:h$1};try{let M=i==="create"||!f$1?await t.createSkill(a):await t.updateSkill(f$1.id,a);if(!M.success){v(Array.isArray(M.errorMessage)?M.errorMessage.join(", "):M.errorMessage);return}oa.success(i==="create"||!f$1?"Skill created.":"Skill saved."),o(M.skill);}catch(M){v(M instanceof Error?M.message:"Failed to save skill.");}finally{w.current=false,C(false);}}async function Qe(a){a.preventDefault(),await ye();}async function Ye(){if(!(!f$1||!H||w.current)){w.current=true,C(true),v("");try{let a=await t.deleteSkill(f$1.id);if(!a.success){v(Array.isArray(a.errorMessage)?a.errorMessage.join(", "):a.errorMessage);return}K("..",{relative:"path"});}catch(a){v(a instanceof Error?a.message:"Failed to delete skill.");}finally{w.current=false,C(false);}}}return jsxs("div",{className:"fk:flex fk:h-full fk:min-h-0 fk:min-w-0 fk:flex-col fk:gap-3 fk:pb-3",children:[jsx(Se,{actions:jsxs("div",{className:"fk:flex fk:items-center fk:gap-3",children:[ae?null:jsx("span",{className:"fk:text-xs fk:text-muted-foreground",children:"Complete the required fields to save"}),i==="edit"&&f$1?jsxs(b$1,{disabled:N||!H,size:"sm",type:"button",variant:"outline",onClick:()=>{Ye();},children:[jsx(Trash2,{}),"Delete"]}):null,jsx(ma,{disabled:!H,children:jsx(b$1,{disabled:N||!ae||!H,form:"skill-editor-form",size:"sm",type:"submit",children:se})})]}),title:Ze}),I?jsx("div",{className:"fk:shrink-0 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:I}):null,jsxs("form",{className:"fk:flex fk:min-h-0 fk:min-w-0 fk:flex-1 fk:flex-col fk:gap-6 fk:w-full fk:max-w-6xl fk:m-auto fk:gap-8 fk:px-4",id:"skill-editor-form",onSubmit:a=>{Qe(a);},children:[jsxs("div",{className:"fk:grid fk:min-w-0 fk:shrink-0 fk:gap-3 fk:px-0.75 fk:lg:grid-cols-[minmax(0,1fr)_minmax(0,1.6fr)_auto]",children:[jsxs("div",{children:[jsx(D,{hint:"Identifying label for this skill",htmlFor:"skill-name",children:"Name"}),jsx(s,{"aria-describedby":$?"skill-name-error":void 0,"aria-invalid":$,className:$?"fk:border-destructive focus-visible:fk:ring-destructive":"",id:"skill-name",value:d$1,onBlur:()=>g$2(a=>({...a,name:true})),onChange:a=>k(a.target.value)}),$?jsx(te,{id:"skill-name-error",message:b$2.name}):null]}),jsxs("div",{children:[jsx(D,{hint:"One or two sentences describing when to use this skill. Agents rely on it to decide whether the skill applies to their current task.",htmlFor:"skill-description",children:"Description"}),jsx(s,{"aria-describedby":U?"skill-description-error":void 0,"aria-invalid":U,className:U?"fk:border-destructive focus-visible:fk:ring-destructive":"",id:"skill-description",placeholder:"e.g. Rules for writing product descriptions in our brand voice",value:u,onBlur:()=>g$2(a=>({...a,description:true})),onChange:a=>m(a.target.value)}),U?jsx(te,{id:"skill-description-error",message:b$2.description}):null]}),jsxs("div",{children:[jsx(D,{hint:"Who can see and use this skill. Space skills are only visible to members of the selected space and only usable by automations in that space; personal skills are private to you.",htmlFor:"skill-visibility",children:"Visibility"}),jsxs("div",{className:"fk:flex fk:items-center fk:gap-2",children:[jsxs(a,{value:h$1,onValueChange:a=>{y(a==="space"||a==="personal"?a:"project"),a!=="space"&&P(null);},children:[jsx(d,{"aria-label":"Visibility",className:"fk:w-fit fk:min-w-26",id:"skill-visibility",children:jsx(c$1,{})}),jsxs(e,{align:"start",children:[jsx(g$1,{value:"project",children:"Project"}),jsx(g$1,{disabled:xe.length===0,value:"space",children:"Space"}),jsx(g$1,{value:"personal",children:"Personal"})]})]}),h$1==="space"?jsxs(a,{value:L??"",onValueChange:a=>{P(a||null);},children:[jsx(d,{"aria-label":"Space",className:"fk:w-fit fk:min-w-34",children:jsx(c$1,{placeholder:"Select a space"})}),jsx(e,{align:"start",children:xe.map(a=>jsx(g$1,{value:a.id,children:a.label},a.id))})]}):null]}),h$1==="space"&&b$2.space?jsx(te,{message:b$2.space}):null]})]}),jsx(Ke,{content:c,showContentError:Ue,validationMessage:b$2.content,onBlur:()=>g$2(a=>({...a,content:true})),onChange:p,onSave:()=>{ye();}})]})]})}function Ot({projectId:t,skill:i,spaceLabelById:o}){let l=b(),f=useNavigate(),[d$1,k]=useState(false),[u,m]=useState("");async function c(){k(true),m("");let p;try{p=await fetch(`/api/flexkit/${t}/skills/${i.id}/fork`,{method:"POST",credentials:"include"});}catch{m("Unable to create a copy. Try again."),k(false);return}if(k(false),!p.ok){m("Unable to create a copy. Check your permissions.");return}f("..",{relative:"path"});}return jsxs("div",{className:"fk:flex fk:h-full fk:min-h-0 fk:min-w-0 fk:flex-col fk:gap-3 fk:pb-3",children:[jsx(Se,{actions:jsxs("div",{className:"fk:flex fk:items-center fk:gap-2",children:[jsx(b$3,{variant:"secondary",children:i.source==="plugin"?"Plugin":"Code"}),i.source==="plugin"&&jsx(b$1,{type:"button",disabled:d$1||!l,onClick:()=>{c();},size:"sm",children:"Edit a copy"})]}),title:i.name}),jsxs("div",{className:"fk:flex fk:flex-col fk:h-full fk:px-4 fk:gap-3 fk:max-w-6xl fk:m-auto",children:[jsxs("div",{className:"fk:shrink-0 fk:rounded-md fk:border fk:bg-muted/30 fk:px-3 fk:py-2 fk:corner-squircle",children:[jsx("p",{className:"fk:text-sm fk:font-medium",children:"Version-controlled skill"}),jsx("p",{className:"fk:text-sm fk:text-muted-foreground",children:i.source==="plugin"?"This skill is managed by its plugin. Edit a copy to create a personal Studio skill.":"Edit this skill in your repository and re-sync it from the Custom Tools settings."})]}),jsxs("div",{className:"fk:grid fk:min-w-0 fk:shrink-0 fk:gap-3 fk:lg:grid-cols-[minmax(0,1fr)_minmax(0,1.6fr)_auto]",children:[jsxs("div",{children:[jsx(D,{hint:"Identifying label for this skill",htmlFor:"skill-name",children:"Name"}),jsx(s,{className:"fk:opacity-100!",disabled:true,id:"skill-name",value:i.name})]}),jsxs("div",{children:[jsx(D,{hint:"One or two sentences describing when to use this skill. Agents rely on it to decide whether the skill applies to their current task.",htmlFor:"skill-description",children:"Description"}),jsx(s,{className:"fk:opacity-100!",disabled:true,id:"skill-description",placeholder:"e.g. Rules for writing product descriptions in our brand voice",value:i.description})]}),jsxs("div",{children:[jsx(D,{hint:"Who can see and use this skill. Space skills are only visible to members of the selected space and only usable by automations in that space; personal skills are private to you.",htmlFor:"skill-visibility",children:"Visibility"}),jsxs("div",{className:"fk:flex fk:items-center fk:gap-2",children:[jsxs(a,{disabled:true,value:i.visibility,children:[jsx(d,{"aria-label":"Visibility",className:"fk:w-fit fk:min-w-26 fk:opacity-100!",id:"skill-visibility",children:jsx(c$1,{})}),jsxs(e,{align:"start",children:[jsx(g$1,{value:"project",children:"Project"}),jsx(g$1,{disabled:!i.spaceId,value:"space",children:"Space"}),jsx(g$1,{value:"personal",children:"Personal"})]})]}),i.visibility==="space"?jsxs(a,{disabled:true,value:i.spaceId??"",children:[jsx(d,{"aria-label":"Space",className:"fk:w-fit fk:min-w-34 fk:opacity-100!",children:jsx(c$1,{placeholder:"Select a space"})}),jsx(e,{align:"start",children:jsx(g$1,{value:i.spaceId??"",children:zt(i,o)})})]}):null]})]})]}),u&&jsx("p",{role:"alert",children:u}),jsx(Ke,{content:i.content,readOnly:true})]})]})}function vi(){let{api:t,projectId:i}=be(),o=useNavigate();return !i||!t?jsx(ie,{children:"Select a project to create skills."}):jsx(Ge,{api:t,mode:"create",projectId:i,onSaved:()=>o("..",{relative:"path"})})}function bi(){let{api:t,projectId:i}=be(),{skillId:o}=useParams(),{data:l,error:f$1,isLoading:d,mutate:k}=ve(i&&o?g(i).skill(o):null,f),{data:u}=ve(i?g(i).spaces:null,f);if(!i||!t||!o)return jsx(ie,{children:"Select a skill."});if(f$1)return jsx(ie,{children:"Failed to load skill."});if(d||!l?.skill)return jsx(Ht,{});let m=new Map((u?.spaces??[]).map(c=>[c.id,c.label]));return l.skill.source!=="studio"?jsx(Ot,{projectId:i,skill:l.skill,spaceLabelById:m}):jsx(Ge,{api:t,mode:"edit",projectId:i,skill:l.skill,onSaved:c=>{c?k({skill:c},{revalidate:false}):k();}})}export{vi as CreateSkillPage,bi as SkillDetailPage,Ge as SkillForm,hi as SkillsPage};//# sourceMappingURL=skills-pages-V4BILOOI.js.map
2
- //# sourceMappingURL=skills-pages-V4BILOOI.js.map