@frumu/tandem-panel 0.5.5 → 0.5.6

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 (54) hide show
  1. package/dist/assets/{AutomationsPage-6mRHsh9V.js → AutomationsPage-BGqpmilp.js} +12 -12
  2. package/dist/assets/BugMonitorPage-BVzdj9y-.js +4 -0
  3. package/dist/assets/{ChannelsPage-oJ5a717t.js → ChannelsPage-B-InJ4Yh.js} +1 -1
  4. package/dist/assets/{ChatInterfacePanel-3nvwn0cJ.js → ChatInterfacePanel-BrMo4cXg.js} +1 -1
  5. package/dist/assets/{ChatPage-CGKFC9ev.js → ChatPage-Bc-BfOG1.js} +1 -1
  6. package/dist/assets/CodingWorkflowsPage-xgfwLRlt.js +8 -0
  7. package/dist/assets/{ControlPanelDialogs-BBIPHXnw.js → ControlPanelDialogs-yFfCht3Y.js} +1 -1
  8. package/dist/assets/DashboardPage-CrA1itFc.js +1 -0
  9. package/dist/assets/{ExperimentsPage-DuYHzo7d.js → ExperimentsPage-Bkg1_6rw.js} +2 -2
  10. package/dist/assets/FilesPage-DChyHlO_.js +1 -0
  11. package/dist/assets/{IntentPlannerPage-BwlF9wfW.js → IntentPlannerPage-Dti1h8Tm.js} +4 -4
  12. package/dist/assets/MarketplacePage-90fAVNGg.js +1 -0
  13. package/dist/assets/{McpToolAllowlistEditor-B3qCkiFT.js → McpToolAllowlistEditor-BzQ64HrZ.js} +1 -1
  14. package/dist/assets/{MemoryImportDialog-BWT93PW1.js → MemoryImportDialog-DSpS1JF5.js} +1 -1
  15. package/dist/assets/MemoryPage-DRRLgoc0.js +1 -0
  16. package/dist/assets/{OrchestratorPage-HDyjjwF-.js → OrchestratorPage-CYU-ESPI.js} +1 -1
  17. package/dist/assets/PacksPage-dRmjjdKD.js +3 -0
  18. package/dist/assets/PlannerDiagnosticsPanel-C1uIuRIx.js +1 -0
  19. package/dist/assets/RunsPage-DEy8vbRT.js +1 -0
  20. package/dist/assets/SettingsPage-CwH_FzOs.js +5 -0
  21. package/dist/assets/{TeamsPage-CwMnVES9.js → TeamsPage-Dn81V0EB.js} +3 -3
  22. package/dist/assets/{WorkflowStudioPage-CyWDhEEE.js → WorkflowStudioPage-yFhlA4KV.js} +1 -1
  23. package/dist/assets/WorkflowsPage-vmaKHFox.js +2 -0
  24. package/dist/assets/{index-DAWzCKcg.css → index-C8Bjo7hU.css} +1 -1
  25. package/dist/assets/index-TvymvGva.js +3 -0
  26. package/dist/assets/{useEngineStream-ChEkuUVV.js → useEngineStream-Diqri33l.js} +1 -1
  27. package/dist/index.html +3 -5
  28. package/package.json +3 -3
  29. package/dist/assets/BugMonitorPage-B9mcxV8k.js +0 -4
  30. package/dist/assets/CodingWorkflowsPage-DosUtoeO.js +0 -8
  31. package/dist/assets/DashboardPage-Cv9_TUZQ.js +0 -1
  32. package/dist/assets/FilesPage-NAInb3WU.js +0 -1
  33. package/dist/assets/MarketplacePage-Wo7biaBa.js +0 -1
  34. package/dist/assets/MemoryPage-gSBH1OKG.js +0 -1
  35. package/dist/assets/PacksPage-BWnL4dRB.js +0 -3
  36. package/dist/assets/PlannerDiagnosticsPanel-VyacxaCM.js +0 -1
  37. package/dist/assets/RunsPage-B6ttNeUJ.js +0 -1
  38. package/dist/assets/SettingsPage-DhAKDQHw.js +0 -5
  39. package/dist/assets/WorkflowsPage-BWGWH8uD.js +0 -2
  40. package/dist/assets/api-CpR5ozpc.js +0 -1
  41. package/dist/assets/index-picB46b5.js +0 -3
  42. package/dist/assets/ui-CV-Z6sqF.js +0 -1
  43. /package/dist/assets/{LazyJson-DYncL_RR.js → LazyJson-vfWw7G9F.js} +0 -0
  44. /package/dist/assets/{ProviderModelSelector-B_IE0-e7.js → ProviderModelSelector-BdtOpkJR.js} +0 -0
  45. /package/dist/assets/{TaskBoard-DSRrmiyQ.js → TaskBoard-CCY_Qy5S.js} +0 -0
  46. /package/dist/assets/{TimezoneField-DKINpKxU.js → TimezoneField-B5i---lF.js} +0 -0
  47. /package/dist/assets/{chatPageHelpers-D-NhHk4M.js → chatPageHelpers-Dmb4waDk.js} +0 -0
  48. /package/dist/assets/{explorerHandoff-KpFRPNQc.js → explorerHandoff-BPKxMR82.js} +0 -0
  49. /package/dist/assets/{format-CimuGHiH.js → format-DyX5imzJ.js} +0 -0
  50. /package/dist/assets/{markdown-DJurGVIJ.js → markdown-Dwwtq3bu.js} +0 -0
  51. /package/dist/assets/{messages-AWZpX-Rw.js → messages-uD0aB_MZ.js} +0 -0
  52. /package/dist/assets/{plannerShared-1kHFyAp-.js → plannerShared-Dx7-Sxpc.js} +0 -0
  53. /package/dist/assets/{sse-B1wvyjPI.js → sse-B4A2m-Nk.js} +0 -0
  54. /package/dist/assets/{workflowStability-Dsk2DR6F.js → workflowStability-C8USyGOY.js} +0 -0
@@ -0,0 +1 @@
1
+ import{g as e,v as t}from"./fullcalendar-Bn75j0xM.js";import{n}from"./react-query-BIbNygEJ.js";import{i as r}from"./motion-B3ZE8SGR.js";import{S as i,T as a,g as o,h as s,m as c,s as l,w as u,x as d,y as f}from"./index-TvymvGva.js";import{n as p}from"./LazyJson-vfWw7G9F.js";import{t as m}from"./format-DyX5imzJ.js";var h=[{label:`24h`,hours:24},{label:`7d`,hours:168},{label:`30d`,hours:720}],g={missing_required_section:`Missing required section`,weak_markdown_structure:`Weak markdown structure`,missing_optional_evidence:`Missing optional evidence`,artifact_word_count_below_minimum:`Word count below minimum`,missing_nonconsumed_workspace_files:`Workspace files missing`,missing_required_artifact_path:`Missing required artifact path`,validator_kind_specific_soft_check:`Validator soft check`,repair_budget_exhausted:`Repair budget exhausted`};function _(e){return g[e]||e.replace(/_/g,` `)}function v(e){return(Number(e.accepted)||0)+(Number(e.rejected)||0)+(Number(e.re_ran_strict)||0)}function y(e){return v(e)+(Number(e.unmarked)||0)}function b(e){let t=v(e);return t===0?null:(Number(e.accepted)||0)/t}function x(e){return e===null?`—`:`${(e*100).toFixed(1)}%`}function S({client:i,automationId:a,className:o=``}){let[s,c]=t(168),l=n({queryKey:[`graduation`,`summary`,s,a||``],enabled:!!i?.automationsV2?.graduationSummary,queryFn:async()=>i?.automationsV2?.graduationSummary?i.automationsV2.graduationSummary({windowHours:s,automationId:a,limit:200}):null,refetchInterval:6e4,staleTime:3e4}),u=l.data||null,d=u?.summary||{},f=d?.by_class||{},p=e(()=>Object.entries(f).map(([e,t])=>({key:e,counts:t,total:y(t),reviewed:v(t),acceptRate:b(t)})).sort((e,t)=>t.reviewed===e.reviewed?t.total-e.total:t.reviewed-e.reviewed),[f]),m=Number(d?.total_outputs_scanned||0),g=Number(d?.total_relaxed_outputs||0),S=Number(u?.scanned_runs||0);return r(`div`,{className:`grid gap-3 ${o}`,children:[r(`div`,{className:`flex flex-wrap items-center justify-between gap-2`,children:[r(`div`,{children:[r(`div`,{className:`text-sm font-medium text-slate-100`,children:`Graduation summary`}),r(`div`,{className:`tcp-subtle text-xs`,children:[`Per-class accept rate over the last`,` `,h.find(e=>e.hours===s)?.label||`${s}h`,`.`]})]}),r(`div`,{className:`flex flex-wrap gap-1`,children:h.map(e=>r(`button`,{type:`button`,className:s===e.hours?`tcp-btn-primary`:`tcp-btn`,onClick:()=>c(e.hours),disabled:l.isFetching,children:e.label},e.hours))})]}),r(`div`,{className:`grid grid-cols-1 gap-2 sm:grid-cols-3`,children:[r(`div`,{className:`rounded-md border border-slate-800/80 bg-slate-950/30 p-2`,children:[r(`div`,{className:`tcp-subtle text-[11px]`,children:`runs scanned`}),r(`div`,{className:`mt-1 font-medium text-slate-100`,children:S})]}),r(`div`,{className:`rounded-md border border-slate-800/80 bg-slate-950/30 p-2`,children:[r(`div`,{className:`tcp-subtle text-[11px]`,children:`node outputs scanned`}),r(`div`,{className:`mt-1 font-medium text-slate-100`,children:m})]}),r(`div`,{className:`rounded-md border border-amber-700/40 bg-amber-950/20 p-2`,children:[r(`div`,{className:`tcp-subtle text-[11px]`,children:`relaxed outputs`}),r(`div`,{className:`mt-1 font-medium text-amber-200`,children:g})]})]}),l.isError?r(`div`,{className:`rounded-md border border-rose-700/40 bg-rose-950/20 p-2 text-xs text-rose-200`,children:`Failed to load graduation summary.`}):null,p.length===0?r(`div`,{className:`rounded-md border border-slate-800/80 bg-slate-950/30 p-3 text-sm text-slate-300`,children:l.isLoading?`Loading…`:m===0?`No automation runs scanned in this window.`:`No relaxed outputs in this window. Strict-only runs do not show up here.`}):r(`div`,{className:`overflow-hidden rounded-md border border-slate-800/80`,children:r(`table`,{className:`w-full text-left text-xs`,children:[r(`thead`,{className:`bg-slate-900/40 text-[11px] uppercase tracking-wide text-slate-400`,children:r(`tr`,{children:[r(`th`,{className:`px-2 py-1.5`,children:`Validator class`}),r(`th`,{className:`px-2 py-1.5 text-right`,children:`Accepted`}),r(`th`,{className:`px-2 py-1.5 text-right`,children:`Rejected`}),r(`th`,{className:`px-2 py-1.5 text-right`,children:`Re-ran Strict`}),r(`th`,{className:`px-2 py-1.5 text-right`,children:`Unmarked`}),r(`th`,{className:`px-2 py-1.5 text-right`,children:`Accept rate`})]})}),r(`tbody`,{children:p.map(e=>{let t=e.reviewed===0?r(`span`,{className:`tcp-subtle italic`,children:`insufficient signal`}):r(`span`,{className:(e.acceptRate??0)>=.8?`font-semibold text-emerald-300`:(e.acceptRate??0)<=.4?`font-semibold text-rose-300`:`font-semibold text-amber-200`,children:x(e.acceptRate)});return r(`tr`,{className:`border-t border-slate-800/60 text-slate-200`,children:[r(`td`,{className:`px-2 py-1.5`,children:[r(`div`,{className:`font-medium`,children:_(e.key)}),r(`code`,{className:`tcp-subtle text-[10px]`,children:e.key})]}),r(`td`,{className:`px-2 py-1.5 text-right`,children:e.counts.accepted||0}),r(`td`,{className:`px-2 py-1.5 text-right`,children:e.counts.rejected||0}),r(`td`,{className:`px-2 py-1.5 text-right`,children:e.counts.re_ran_strict||0}),r(`td`,{className:`px-2 py-1.5 text-right tcp-subtle`,children:e.counts.unmarked||0}),r(`td`,{className:`px-2 py-1.5 text-right`,children:t})]},e.key)})})]})})]})}function C(e,t){return Array.isArray(e)?e:Array.isArray(e?.[t])?e[t]:[]}function w(e){return String(e||``).trim().replace(/([a-z0-9])([A-Z])/g,`$1_$2`).replace(/[\s-]+/g,`_`).toLowerCase()}function T(e){return e.ready?e.defaultProvider===`openai-codex`?e.defaultProviderManagedBy===`codex-upload`?`Imported auth.json on hosted server`:e.defaultProviderManagedBy===`codex-cli`?`Mirrored from local Codex CLI`:e.defaultProviderAuthKind===`oauth`?`Codex account session active`:``:e.defaultProviderAuthKind===`oauth`?`OAuth session active`:e.defaultProviderSource===`env`?`Env-managed credentials`:e.defaultProviderSource===`persisted`?`Stored credentials`:``:``}function E(h){let{api:g,client:_,navigate:v,providerStatus:y}=h,[b,x]=t(``),[E,D]=t(`day`),O=new Set([`workflow`,`bug_monitor_triage`]),k=n({queryKey:[`dashboard`,`health`],queryFn:()=>g(`/api/system/health`),refetchInterval:15e3}),A=n({queryKey:[`dashboard`,`sessions`],queryFn:()=>_.sessions.list({pageSize:8,source:`chat`}).catch(()=>[]),refetchInterval:15e3}),j=n({queryKey:[`dashboard`,`routines`],queryFn:()=>_.routines.list().catch(()=>({routines:[]})),refetchInterval:2e4}),M=n({queryKey:[`dashboard`,`automation-v2-runs`],queryFn:()=>g(`/api/engine/automations/v2/runs?limit=200`).catch(()=>({runs:[]})),refetchInterval:15e3}),N=n({queryKey:[`dashboard`,`swarm`],queryFn:()=>g(`/api/swarm/status`).catch(()=>({status:`unknown`,activeRuns:0})),refetchInterval:6e3}),P=n({queryKey:[`dashboard`,`workflow-context-runs`],queryFn:()=>g(`/api/engine/context/runs?limit=12`).catch(()=>({runs:[]})),refetchInterval:6e3}),F=n({queryKey:[`dashboard`,`workflow-context-run`,b],enabled:!!b,queryFn:()=>g(`/api/engine/context/runs/${encodeURIComponent(b)}`).catch(()=>({run:null}))}),I=n({queryKey:[`dashboard`,`workflow-context-blackboard`,b],enabled:!!b,queryFn:()=>g(`/api/engine/context/runs/${encodeURIComponent(b)}/blackboard`).catch(()=>({blackboard:null}))}),L=C(A.data,`sessions`),R=C(j.data,`routines`),z=C(M.data,`runs`),B=C(P.data,`runs`).filter(e=>O.has(String(e?.run_type||``).trim().toLowerCase())),V=!!(k.data?.engine?.ready||k.data?.engine?.healthy),H=String(N.data?.status||`unknown`),U=[`planning`,`awaiting_approval`,`running`,`executing`].includes(H.toLowerCase()),W=z.filter(e=>[`queued`,`running`,`pausing`,`awaiting_approval`,`blocked`].includes(w(e?.status))),G=z.filter(e=>Number(e?.total_tokens||0)>0),K=z.reduce((e,t)=>({prompt:e.prompt+Number(t?.prompt_tokens||0),completion:e.completion+Number(t?.completion_tokens||0),total:e.total+Number(t?.total_tokens||0)}),{prompt:0,completion:0,total:0}),q=B.filter(e=>[`queued`,`planning`,`running`,`awaiting_approval`].includes(String(e?.status||``).trim().toLowerCase())),J=T(y),Y=e(()=>{let e=new Map,t=Date.now(),n,r,i,a;E===`day`?(n=336*60*60*1e3,r=14,i=e=>e.toISOString().slice(0,10),a=e=>{let[,t,n]=e.split(`-`);return`${t}/${n}`}):E===`week`?(n=1344*60*60*1e3,r=8,i=e=>{let t=new Date(e);return t.setDate(e.getDate()-(e.getDay()+6)%7),t.toISOString().slice(0,10)},a=e=>{let[,t,n]=e.split(`-`);return`w/${t}/${n}`}):(n=4320*60*60*1e3,r=6,i=e=>e.toISOString().slice(0,7),a=e=>{let[t,n]=e.split(`-`);return`${n}/${t.slice(2)}`});let o=t-n;for(let t of z){let n=Number(t?.created_at_ms||t?.updated_at_ms||0);if(!n||n<o)continue;let r=new Date(n),s=i(r),c=e.get(s)??{label:a(s),runs:0,tokens:0};c.runs+=1,c.tokens+=Number(t?.total_tokens||0),e.set(s,c)}let s=[...e.entries()].sort((e,t)=>e[0].localeCompare(t[0])),c=Math.max(1,...s.map(([,e])=>e.tokens));return{buckets:s.map(([,e])=>e),maxTokens:c,bucketCount:r}},[z,E]),X=e(()=>[{label:`Recent sessions`,value:L.length,tone:`info`,helper:`Latest active conversation surfaces`},{label:`Stored runs`,value:z.length,tone:`ok`,helper:`Persisted automation-v2 history`},{label:`Live runs`,value:W.length,tone:W.length?`warn`:`ghost`,helper:`Queued, running, blocked, awaiting approval`},{label:`Tracked tokens`,value:K.total,tone:K.total?`info`:`ghost`,helper:`${G.length} runs with usage`},{label:`Context runs`,value:B.length,tone:q.length?`warn`:`info`,helper:q.length?`${q.length} active`:`Workflow + triage visibility`}],[q.length,z.length,K.total,W.length,L.length,B.length,G.length]);return r(c,{className:`grid gap-4`,children:[r(d,{className:`overflow-hidden`,children:[r(`div`,{className:`grid gap-5 xl:grid-cols-[minmax(0,1.3fr)_minmax(320px,0.9fr)] xl:items-start`,children:r(`div`,{className:`min-w-0`,children:[r(`div`,{className:`tcp-page-eyebrow`,children:`Overview`}),r(`h1`,{className:`tcp-page-title`,children:`Command center`}),r(`p`,{className:`tcp-subtle mt-2 max-w-3xl`,children:`A higher-signal home screen with animated state and a clearer read on what the system is doing right now.`}),r(`div`,{className:`mt-3 flex flex-wrap gap-2`,children:[r(s,{tone:V?`ok`:`warn`,children:V?`Engine healthy`:`Engine checking`}),r(s,{tone:y.ready?`ok`:`warn`,children:y.ready?y.defaultProvider:`Provider setup required`}),J?r(s,{tone:`info`,children:J}):null,U?r(u,{tone:`live`,text:`Swarm ${H}`}):r(s,{tone:`ghost`,children:[`Swarm `,H]})]})]})}),r(`div`,{className:`mt-5`,children:[r(`div`,{className:`dashboard-kpis`,children:X.map(e=>r(`div`,{children:[r(`div`,{className:`flex items-start justify-between gap-3`,children:[r(`span`,{className:`dashboard-kpi-label`,children:e.label}),r(s,{tone:e.tone,children:e.helper})]}),r(`strong`,{children:r(f,{value:e.value,format:e.format??m})})]},e.label))}),r(`p`,{className:`tcp-subtle mt-3 text-xs`,children:`Usage totals are aggregated from stored automation-v2 run history, so they reflect real executions instead of inferred activity.`}),r(`div`,{className:`mt-4 dashboard-bars`,children:[r(`div`,{className:`dashboard-bar-row`,children:[r(`div`,{className:`dashboard-bar-meta`,children:[r(`span`,{children:`Engine readiness`}),r(`span`,{className:`dashboard-bar-count`,children:V?`100%`:`45%`})]}),r(`div`,{className:`dashboard-bar-track`,children:r(`span`,{className:`dashboard-bar-fill completed`,style:{width:V?`100%`:`45%`}})})]}),r(`div`,{className:`dashboard-bar-row`,children:[r(`div`,{className:`dashboard-bar-meta`,children:[r(`span`,{children:`Provider confidence`}),r(`span`,{className:`dashboard-bar-count`,children:y.ready?`100%`:`30%`})]}),r(`div`,{className:`dashboard-bar-track`,children:r(`span`,{className:`dashboard-bar-fill ${y.ready?`running`:`queued`}`,style:{width:y.ready?`100%`:`30%`}})})]}),r(`div`,{className:`dashboard-bar-row`,children:[r(`div`,{className:`dashboard-bar-meta`,children:[r(`span`,{children:`Automation activity`}),r(`span`,{className:`dashboard-bar-count`,children:[W.length,` live`]})]}),r(`div`,{className:`dashboard-bar-track`,children:r(`span`,{className:`dashboard-bar-fill ${W.length?`running`:`manual`}`,style:{width:`${z.length?Math.min(100,Math.max(12,W.length/z.length*100)):12}%`}})})]})]})]})]}),r(d,{children:[r(`div`,{className:`mb-3 flex flex-wrap items-center justify-between gap-2`,children:[r(`div`,{children:[r(`div`,{className:`tcp-page-eyebrow`,children:`Usage`}),r(`h2`,{className:`font-semibold`,children:`Token usage over time`})]}),r(`div`,{className:`flex gap-1`,children:[`day`,`week`,`month`].map(e=>r(`button`,{type:`button`,className:`tcp-btn h-7 px-2 text-xs capitalize ${E===e?`tcp-btn-active`:``}`,onClick:()=>D(e),children:e},e))})]}),Y.buckets.length===0?r(`p`,{className:`tcp-subtle text-xs`,children:`No token data in this window yet.`}):r(`div`,{className:`grid gap-2`,children:Y.buckets.map(e=>r(`div`,{className:`dashboard-bar-row`,children:[r(`div`,{className:`dashboard-bar-meta`,children:[r(`span`,{className:`font-mono text-xs`,children:e.label}),r(`span`,{className:`dashboard-bar-count`,children:[m(e.tokens),` tok`,` · `,r(`span`,{className:`tcp-subtle`,children:[e.runs,` run`,e.runs===1?``:`s`]})]})]}),r(`div`,{className:`dashboard-bar-track`,children:r(`span`,{className:`dashboard-bar-fill ${e.tokens>0?`running`:`manual`}`,style:{width:`${Math.max(4,e.tokens/Y.maxTokens*100)}%`}})})]},e.label))})]}),r(d,{title:`Graduation review`,subtitle:`Per-class accept rate for relaxed Guided/Lenient outputs.`,children:r(S,{client:_})}),r(i,{main:r(d,{title:`Recent sessions`,subtitle:`Latest conversations, ready to reopen.`,children:r(`div`,{className:`grid gap-2`,children:L.length?L.map(e=>r(`button`,{className:`tcp-list-item text-left`,onClick:()=>v(`chat`),children:[r(`div`,{className:`font-medium inline-flex items-center gap-2`,children:[r(`i`,{"data-lucide":`messages-square`}),String(e.title||e.id||`Session`)]}),r(`div`,{className:`tcp-subtle mt-1 text-xs`,children:String(e.id||e.session_id||``)})]},String(e.id||e.session_id||Math.random()))):r(l,{text:`Start a conversation to populate recent sessions here.`})})}),aside:r(`div`,{className:`grid gap-4`,children:[r(d,{title:`Context visibility`,subtitle:`Recent workflow and failure-triage context runs with their current projection state.`,children:[r(a,{className:`mb-3`,children:[r(s,{tone:q.length?`warn`:`info`,children:[B.length,` recent`]}),r(`button`,{className:`tcp-btn`,onClick:()=>v(`orchestrator`),children:[r(`i`,{"data-lucide":`workflow`}),`Open task board`]})]}),r(`div`,{className:`grid gap-2`,children:B.length?B.slice(0,5).map(e=>r(`button`,{className:`tcp-list-item text-left`,onClick:()=>x(String(e?.run_id||``).trim()),children:[r(`div`,{className:`mb-1 flex items-center justify-between gap-2`,children:[r(`div`,{className:`font-medium`,children:String(e?.objective||e?.run_id||`Context run`)}),r(`div`,{className:`flex flex-wrap items-center gap-2`,children:[r(s,{tone:`ghost`,children:String(e?.run_type||`context`)}),r(s,{tone:[`failed`,`cancelled`].includes(String(e?.status||``).toLowerCase())?`err`:[`running`,`queued`,`planning`].includes(String(e?.status||``).toLowerCase())?`warn`:`ok`,children:String(e?.status||`unknown`)})]})]}),r(`div`,{className:`tcp-subtle text-xs`,children:String(e?.run_id||``)}),r(`div`,{className:`tcp-subtle mt-1 text-xs`,children:[Array.isArray(e?.tasks)?e.tasks.length:0,` tasks ·`,` `,Array.isArray(e?.steps)?e.steps.length:0,` steps`]})]},String(e?.run_id||Math.random()))):r(l,{text:`Workflow and failure-triage context runs will appear here once they execute.`})})]}),r(d,{title:`Automation snapshot`,subtitle:`Schedules and run-ready routines.`,children:[r(a,{className:`mb-3`,children:[r(s,{tone:`info`,children:[R.length,` loaded`]}),r(`button`,{className:`tcp-btn`,onClick:()=>v(`automations`),children:[r(`i`,{"data-lucide":`bot`}),`Manage`]})]}),r(`div`,{className:`grid gap-2`,children:R.length?R.slice(0,4).map(e=>r(`div`,{className:`tcp-list-item`,children:[r(`div`,{className:`font-medium`,children:String(e.name||e.id||`Routine`)}),r(`div`,{className:`tcp-subtle mt-1 text-xs`,children:String(e.schedule||e.status||`manual`)})]},String(e.id||e.routine_id||Math.random()))):r(l,{text:`No routines are configured yet.`})})]}),r(d,{title:`Health notes`,subtitle:`Direct links for the next likely action.`,children:r(`div`,{className:`grid gap-2`,children:[r(`div`,{className:`tcp-list-item`,children:[r(`div`,{className:`font-medium inline-flex items-center gap-2`,children:[r(`i`,{"data-lucide":`activity`}),`Engine endpoint`]}),r(`div`,{className:`tcp-subtle mt-1 text-xs`,children:String(k.data?.engineUrl||`Unavailable`)})]}),r(`div`,{className:`tcp-list-item`,children:[r(`div`,{className:`font-medium inline-flex items-center gap-2`,children:[r(`i`,{"data-lucide":`radio`}),`Swarm`]}),r(`div`,{className:`tcp-subtle mt-1 text-xs`,children:[`Status: `,H]})]}),r(`div`,{className:`tcp-list-item`,children:[r(`div`,{className:`font-medium inline-flex items-center gap-2`,children:[r(`i`,{"data-lucide":`database`}),`Memory & runs`]}),r(`div`,{className:`mt-2 flex flex-wrap gap-2`,children:[r(`button`,{className:`tcp-btn h-8 px-3 text-xs`,onClick:()=>v(`memory`),children:`Open memory`}),r(`button`,{className:`tcp-btn h-8 px-3 text-xs`,onClick:()=>v(`runs`),children:`Open runs`})]})]})]})})]})}),r(o,{open:!!b,onClose:()=>x(``),title:b||`Workflow context run`,children:b?r(`div`,{className:`grid gap-3`,children:[r(`div`,{className:`tcp-list-item`,children:[r(`div`,{className:`mb-1 flex items-center justify-between gap-2`,children:[r(`strong`,{children:String(F.data?.run?.objective||b)}),r(s,{tone:`info`,children:String(F.data?.run?.status||`unknown`)})]}),r(`div`,{className:`tcp-subtle text-xs`,children:[`type: `,String(F.data?.run?.run_type||`workflow`)]})]}),r(`div`,{className:`tcp-list-item`,children:[r(`div`,{className:`font-medium mb-2`,children:`Projected blackboard`}),r(`div`,{className:`tcp-subtle text-xs`,children:[`tasks:`,` `,Array.isArray(I.data?.blackboard?.tasks)?I.data.blackboard.tasks.length:0,` · `,`artifacts:`,` `,Array.isArray(I.data?.blackboard?.artifacts)?I.data.blackboard.artifacts.length:0]})]}),r(p,{value:{run:F.data?.run||null,blackboard:I.data?.blackboard||null},label:`Show run + blackboard`})]}):null})]})}export{E as DashboardPage};
@@ -1,4 +1,4 @@
1
- import{C as e,E as t,g as n,v as r}from"./fullcalendar-Bn75j0xM.js";import{a as i,n as a,t as o}from"./react-query-BIbNygEJ.js";import{t as s}from"./vendor-DSaYtO9f.js";import{i as c}from"./motion-B3ZE8SGR.js";import{l,n as u,t as d,u as f}from"./ui-CV-Z6sqF.js";import{s as p}from"./index-picB46b5.js";import{r as m}from"./plannerShared-1kHFyAp-.js";var h=`kind: extract_format
1
+ import{C as e,E as t,g as n,v as r}from"./fullcalendar-Bn75j0xM.js";import{a as i,n as a,t as o}from"./react-query-BIbNygEJ.js";import{t as s}from"./vendor-DSaYtO9f.js";import{i as c}from"./motion-B3ZE8SGR.js";import{b as l,h as u,m as d,s as f,x as p}from"./index-TvymvGva.js";import{r as m}from"./plannerShared-Dx7-Sxpc.js";var h=`kind: extract_format
2
2
  description: Two-node validator-backed workflow for cheap optimization smoke tests.
3
3
  status: draft
4
4
  schedule:
@@ -81,4 +81,4 @@ flow:
81
81
  retry_policy:
82
82
  max_attempts: 1
83
83
  timeout_ms: 60000
84
- `;function _(e,t){return Array.isArray(e)?e:Array.isArray(e?.[t])?e[t]:[]}function v(e){let t=String(e||``).trim().toLowerCase();return t===`running`?`tcp-badge-warn`:t.includes(`paused`)?`tcp-badge-info`:t===`completed`?`tcp-badge-ok`:t===`failed`?`tcp-badge-err`:t.includes(`approval`)?`tcp-badge-warn`:`tcp-badge-info`}function y(e){let t=Number(e);return Number.isFinite(t)?t.toFixed(3):`n/a`}var b=Object.entries(Object.assign({"./smoke-workflows/extract-format.yaml":h,"./smoke-workflows/summary.yaml":g})).map(([e,t])=>{let n=s.parse(t);if(!n||typeof n!=`object`)throw Error(`Invalid smoke workflow template at `+e+`: expected a YAML object.`);let r=n,i=String(r.kind||``).trim();if(i!==`summary`&&i!==`extract_format`)throw Error(`Invalid smoke workflow template at `+e+`: missing kind.`);return{kind:i,payload:r}}).sort((e,t)=>e.kind.localeCompare(t.kind));function x(e,t){let n=b.find(t=>t.kind===e);if(!n)throw Error(`Unknown smoke workflow kind: `+e);let{kind:r,...i}=structuredClone(n.payload);return i.workspace_root=String(t||``).trim(),i}function S({client:s,toast:l}){let u=i(),[d,f]=r(``),[h,g]=r({name:``,sourceWorkflowId:``,smokeWorkspaceRoot:``,objectiveRef:`objective.md`,evalRef:`eval.yaml`,mutationPolicyRef:`mutation_policy.yaml`,scopeRef:`scope.yaml`,budgetRef:`budget.yaml`,modelProvider:``,modelId:``,startImmediately:!0}),b=a({queryKey:[`optimizations`,`workflows`,`automations-v2`],queryFn:()=>s?.automationsV2?.list?.().catch(()=>({automations:[]}))??Promise.resolve({automations:[]})}),S=a({queryKey:[`optimizations`,`list`],queryFn:()=>s?.optimizations?.list?.().catch(()=>({optimizations:[]}))??Promise.resolve({optimizations:[]})}),C=a({queryKey:[`optimizations`,`health`],queryFn:()=>s.health().catch(()=>({})),refetchInterval:3e4}),w=a({queryKey:[`optimizations`,`providers`,`catalog`],queryFn:()=>s.providers.catalog().catch(()=>({all:[]})),refetchInterval:3e4}),T=a({queryKey:[`optimizations`,`providers`,`config`],queryFn:()=>s.providers.config().catch(()=>({})),refetchInterval:3e4}),E=n(()=>_(S.data,`optimizations`),[S.data]),D=n(()=>m({providerCatalog:w.data,providerConfig:T.data,defaultProvider:String(T.data?.default||``).trim(),defaultModel:String(T.data?.providers?.[String(T.data?.default||``).trim()]?.default_model||T.data?.providers?.[String(T.data?.default||``).trim()]?.defaultModel||``).trim()}),[w.data,T.data]),O=n(()=>{let e=D.find(e=>e.id===String(h.modelProvider||``).trim());return Array.isArray(e?.models)?e.models:[]},[h.modelProvider,D]);e(()=>{let e=String(C.data?.workspaceRoot||C.data?.workspace_root||``).trim();e&&g(t=>String(t.smokeWorkspaceRoot||``).trim()?t:{...t,smokeWorkspaceRoot:`${e}/docs/internal/optimization-smoke-pack`})},[C.data]);let k=d||String(E[0]?.optimization_id||``).trim(),A=a({queryKey:[`optimizations`,`detail`,k],enabled:!!k,queryFn:()=>s.optimizations.get(k)}),j=a({queryKey:[`optimizations`,`experiments`,k],enabled:!!k,queryFn:()=>s.optimizations.listExperiments(k)}),M=o({mutationFn:async()=>{let e=String(h.sourceWorkflowId||``).trim();if(!e)throw Error(`Source workflow is required.`);let t={name:String(h.name||``).trim()||void 0,source_workflow_id:e,artifacts:{objective_ref:String(h.objectiveRef||``).trim(),eval_ref:String(h.evalRef||``).trim(),mutation_policy_ref:String(h.mutationPolicyRef||``).trim(),scope_ref:String(h.scopeRef||``).trim(),budget_ref:String(h.budgetRef||``).trim()},execution_override:String(h.modelProvider||``).trim()&&String(h.modelId||``).trim()?{provider_id:String(h.modelProvider||``).trim(),model_id:String(h.modelId||``).trim()}:void 0},n=await s.optimizations.create(t);if(h.startImmediately){let e=String(n?.optimization?.optimization_id||``).trim();e&&await s.optimizations.action(e,{action:`start`})}return n},onSuccess:async e=>{let t=String(e?.optimization?.optimization_id||``).trim();l(`ok`,`Optimization campaign created.`),t&&f(t),await u.invalidateQueries({queryKey:[`optimizations`]})},onError:e=>l(`err`,e instanceof Error?e.message:String(e))}),N=o({mutationFn:async e=>{let t=String(h.smokeWorkspaceRoot||``).trim();if(!t)throw Error(`Smoke workflow workspace root is required.`);if(!s?.automationsV2?.create)throw Error(`Workflow creation client is unavailable.`);let n=x(e,t);return s.automationsV2.create(n)},onSuccess:async(e,t)=>{let n=String(e?.automation?.automation_id||e?.automation?.automationId||``).trim();g(t=>({...t,sourceWorkflowId:n||t.sourceWorkflowId,name:n&&!String(t.name||``).trim()?`Optimize ${String(e?.automation?.name||n).trim()}`:t.name})),l(`ok`,t===`summary`?`Smoke summary workflow created and selected.`:`Smoke extract-format workflow created and selected.`),await u.invalidateQueries({queryKey:[`optimizations`,`workflows`,`automations-v2`]})},onError:e=>l(`err`,e instanceof Error?e.message:String(e))}),P=o({mutationFn:async({optimizationId:e,action:t,experimentId:n})=>s.optimizations.action(e,{action:t,experiment_id:n}),onSuccess:async()=>{l(`ok`,`Optimization action applied.`),await u.invalidateQueries({queryKey:[`optimizations`]})},onError:e=>l(`err`,e instanceof Error?e.message:String(e))}),F=o({mutationFn:async({optimizationId:e,experimentId:t})=>s.optimizations.applyWinner(e,t),onSuccess:async()=>{l(`ok`,`Approved winner applied to the live workflow.`),await u.invalidateQueries({queryKey:[`optimizations`]}),await u.invalidateQueries({queryKey:[`optimizations`,`detail`,k]}),await u.invalidateQueries({queryKey:[`optimizations`,`experiments`,k]}),await u.invalidateQueries({queryKey:[`optimizations`,`workflows`,`automations-v2`]})},onError:e=>l(`err`,e instanceof Error?e.message:String(e))}),I=_(b.data,`automations`).map(e=>({id:String(e?.automation_id||e?.automationId||e?.id||``).trim(),name:String(e?.name||e?.automation_id||`Workflow`).trim()})),L=A.data?.optimization||null,R=_(j.data,`experiments`),z=L?.baseline_metrics||null;return c(`div`,{className:`grid gap-4 lg:grid-cols-[minmax(320px,380px),minmax(0,1fr)]`,children:[c(`div`,{className:`grid gap-4`,children:[c(`div`,{className:`rounded-xl border border-slate-700/50 bg-slate-950/40 p-4`,children:[c(`div`,{className:`mb-1 text-sm font-semibold text-slate-100`,children:`New Optimization Campaign`}),c(`div`,{className:`tcp-subtle text-xs`,children:`Create a shadow-eval workflow optimization campaign from an existing automation.`}),c(`div`,{className:`mt-1 text-xs text-slate-500`,children:[`Inspired by`,` `,c(`a`,{className:`text-amber-300 hover:text-amber-200`,href:`https://github.com/karpathy/autoresearch`,target:`_blank`,rel:`noreferrer`,children:`karpathy/autoresearch`}),`.`]}),c(`div`,{className:`mt-3 grid gap-3`,children:[c(`label`,{className:`grid gap-1 text-xs text-slate-300`,children:[c(`span`,{children:`Name`}),c(`input`,{className:`rounded-lg border border-slate-700 bg-slate-950 px-3 py-2 text-sm`,value:h.name,onChange:e=>g(t=>({...t,name:e.target.value})),placeholder:`Optimize research brief workflow`})]}),c(`label`,{className:`grid gap-1 text-xs text-slate-300`,children:[c(`span`,{children:`Source workflow`}),c(`select`,{className:`rounded-lg border border-slate-700 bg-slate-950 px-3 py-2 text-sm`,value:h.sourceWorkflowId,onChange:e=>g(t=>({...t,sourceWorkflowId:e.target.value})),children:[c(`option`,{value:``,children:`Select a workflow`}),I.map(e=>c(`option`,{value:e.id,children:e.name},e.id))]})]}),c(`div`,{className:`rounded-lg border border-slate-800 bg-slate-950/50 p-3`,children:[c(`div`,{className:`text-xs font-medium text-slate-200`,children:`Need a cheap target first?`}),c(`div`,{className:`mt-1 text-[11px] text-slate-500`,children:`Create a tiny validator-backed workflow in the smoke-pack workspace, then use it as the optimization source.`}),c(`label`,{className:`mt-3 grid gap-1 text-xs text-slate-300`,children:[c(`span`,{children:`Smoke workspace root`}),c(`input`,{className:`rounded-lg border border-slate-700 bg-slate-950 px-3 py-2 text-sm`,value:h.smokeWorkspaceRoot,onChange:e=>g(t=>({...t,smokeWorkspaceRoot:e.target.value})),placeholder:`/abs/path/to/docs/internal/optimization-smoke-pack`})]}),c(`div`,{className:`mt-3 flex flex-wrap gap-2`,children:[c(`button`,{className:`tcp-btn h-9 px-3 text-xs`,onClick:()=>N.mutate(`summary`),disabled:N.isPending,children:`Create Smoke Summary`}),c(`button`,{className:`tcp-btn h-9 px-3 text-xs`,onClick:()=>N.mutate(`extract_format`),disabled:N.isPending,children:`Create Extract + Format`})]})]}),c(`label`,{className:`grid gap-1 text-xs text-slate-300`,children:[c(`span`,{children:`Model provider`}),c(`select`,{className:`rounded-lg border border-slate-700 bg-slate-950 px-3 py-2 text-sm`,value:h.modelProvider,onChange:e=>g(t=>({...t,modelProvider:e.target.value,modelId:e.target.value&&t.modelProvider!==e.target.value?``:t.modelId})),children:[c(`option`,{value:``,children:`Use workflow/default model`}),D.map(e=>c(`option`,{value:e.id,children:e.id},e.id))]})]}),c(`label`,{className:`grid gap-1 text-xs text-slate-300`,children:[c(`span`,{children:`Model id`}),c(`input`,{className:`rounded-lg border border-slate-700 bg-slate-950 px-3 py-2 text-sm`,value:h.modelId,onChange:e=>g(t=>({...t,modelId:e.target.value})),placeholder:h.modelProvider?`Pick a cheaper model for this campaign`:`Optional`,list:`optimization-model-ids`}),c(`datalist`,{id:`optimization-model-ids`,children:O.map(e=>c(`option`,{value:e},e))}),c(`span`,{className:`tcp-subtle text-[11px]`,children:`Fixed for the whole campaign. Leave blank to use the workflow's existing model settings.`})]}),[[`Objective ref`,`objectiveRef`],[`Eval ref`,`evalRef`],[`Mutation policy ref`,`mutationPolicyRef`],[`Scope ref`,`scopeRef`],[`Budget ref`,`budgetRef`]].map(([e,t])=>c(`label`,{className:`grid gap-1 text-xs text-slate-300`,children:[c(`span`,{children:e}),c(`input`,{className:`rounded-lg border border-slate-700 bg-slate-950 px-3 py-2 text-sm`,value:h[t],onChange:e=>g(n=>({...n,[t]:e.target.value}))})]},t)),c(`label`,{className:`flex items-center gap-2 text-xs text-slate-300`,children:[c(`input`,{type:`checkbox`,checked:h.startImmediately,onChange:e=>g(t=>({...t,startImmediately:e.target.checked}))}),`Start immediately after create`]}),c(`button`,{className:`tcp-btn h-10 px-3 text-sm`,onClick:()=>M.mutate(),disabled:M.isPending,children:M.isPending?`Creating...`:`Create Campaign`})]})]}),c(`div`,{className:`rounded-xl border border-slate-700/50 bg-slate-950/40 p-4`,children:[c(`div`,{className:`mb-2 flex items-center justify-between gap-2`,children:[c(`div`,{className:`text-sm font-semibold text-slate-100`,children:`Campaigns`}),c(`span`,{className:`tcp-badge-info`,children:E.length})]}),c(`div`,{className:`grid gap-2`,children:E.length?E.map(e=>{let t=String(e?.optimization_id||``).trim();return c(`button`,{type:`button`,className:`rounded-xl border px-3 py-3 text-left transition ${k===t?`border-amber-400/60 bg-amber-400/10`:`border-slate-700/50 bg-slate-950/40 hover:border-slate-600`}`,onClick:()=>f(t),children:[c(`div`,{className:`flex items-center justify-between gap-2`,children:[c(`div`,{className:`font-medium text-slate-100`,children:String(e?.name||t||`Optimization`)}),c(`span`,{className:v(e?.status),children:String(e?.status||`draft`)})]}),c(`div`,{className:`mt-1 text-xs text-slate-400`,children:[`workflow:`,` `,String(e?.source_workflow_name||e?.source_workflow_id||`unknown`)]})]},t)}):c(p,{text:`No optimization campaigns yet.`})})]})]}),c(`div`,{className:`grid gap-4`,children:L?c(t,{children:[c(`div`,{className:`rounded-xl border border-slate-700/50 bg-slate-950/40 p-4`,children:[c(`div`,{className:`flex flex-wrap items-start justify-between gap-3`,children:[c(`div`,{children:[c(`div`,{className:`text-lg font-semibold text-slate-100`,children:String(L?.name||L?.optimization_id||`Optimization`)}),c(`div`,{className:`mt-1 text-sm text-slate-400`,children:[`Source workflow:`,` `,String(L?.source_workflow_name||L?.source_workflow_id||`unknown`)]}),c(`div`,{className:`mt-1 text-xs text-slate-500`,children:[`baseline: `,String(L?.baseline_snapshot_hash||``).slice(0,12)]}),L?.execution_override?c(`div`,{className:`mt-1 text-xs text-slate-500`,children:[`model: `,String(L.execution_override.provider_id||``).trim(),`/`,String(L.execution_override.model_id||``).trim()]}):null]}),c(`div`,{className:`flex flex-wrap gap-2`,children:[c(`button`,{className:`tcp-btn h-8 px-3 text-xs`,onClick:()=>P.mutate({optimizationId:k,action:`start`}),disabled:P.isPending,children:`Start`}),c(`button`,{className:`tcp-btn h-8 px-3 text-xs`,onClick:()=>P.mutate({optimizationId:k,action:`pause`}),disabled:P.isPending,children:`Pause`}),c(`button`,{className:`tcp-btn h-8 px-3 text-xs`,onClick:()=>P.mutate({optimizationId:k,action:`resume`}),disabled:P.isPending,children:`Resume`})]})]}),c(`div`,{className:`mt-4 grid gap-3 md:grid-cols-4`,children:[c(`div`,{className:`rounded-lg border border-slate-800 bg-slate-950/60 p-3`,children:[c(`div`,{className:`text-[11px] uppercase tracking-[0.22em] text-slate-500`,children:`Status`}),c(`div`,{className:`mt-1 text-sm text-slate-100`,children:String(L?.status||`draft`)})]}),c(`div`,{className:`rounded-lg border border-slate-800 bg-slate-950/60 p-3`,children:[c(`div`,{className:`text-[11px] uppercase tracking-[0.22em] text-slate-500`,children:`Pass Rate`}),c(`div`,{className:`mt-1 text-sm text-slate-100`,children:z?y(z.artifact_validator_pass_rate):`n/a`})]}),c(`div`,{className:`rounded-lg border border-slate-800 bg-slate-950/60 p-3`,children:[c(`div`,{className:`text-[11px] uppercase tracking-[0.22em] text-slate-500`,children:`Unmet Reqs`}),c(`div`,{className:`mt-1 text-sm text-slate-100`,children:z?y(z.unmet_requirement_count):`n/a`})]}),c(`div`,{className:`rounded-lg border border-slate-800 bg-slate-950/60 p-3`,children:[c(`div`,{className:`text-[11px] uppercase tracking-[0.22em] text-slate-500`,children:`Blocked Rate`}),c(`div`,{className:`mt-1 text-sm text-slate-100`,children:z?y(z.blocked_node_rate):`n/a`})]})]}),L?.last_pause_reason?c(`div`,{className:`mt-3 rounded-lg border border-amber-500/30 bg-amber-500/10 p-3 text-sm text-amber-200`,children:String(L.last_pause_reason)}):null]}),c(`div`,{className:`rounded-xl border border-slate-700/50 bg-slate-950/40 p-4`,children:[c(`div`,{className:`mb-2 flex items-center justify-between gap-2`,children:[c(`div`,{className:`text-sm font-semibold text-slate-100`,children:`Experiments`}),c(`span`,{className:`tcp-badge-info`,children:R.length})]}),R.length?c(`div`,{className:`overflow-x-auto`,children:c(`table`,{className:`min-w-full text-left text-sm`,children:[c(`thead`,{className:`text-xs uppercase tracking-[0.22em] text-slate-500`,children:c(`tr`,{children:[c(`th`,{className:`px-2 py-2`,children:`Experiment`}),c(`th`,{className:`px-2 py-2`,children:`Status`}),c(`th`,{className:`px-2 py-2`,children:`Mutation`}),c(`th`,{className:`px-2 py-2`,children:`Pass`}),c(`th`,{className:`px-2 py-2`,children:`Recommendation`}),c(`th`,{className:`px-2 py-2`,children:`Action`})]})}),c(`tbody`,{children:R.map(e=>{let t=String(e?.experiment_id||``).trim(),n=e?.phase1_metrics||{};return c(`tr`,{className:`border-t border-slate-800`,children:[c(`td`,{className:`px-2 py-3 text-slate-200`,children:t||`unknown`}),c(`td`,{className:`px-2 py-3`,children:c(`span`,{className:v(e?.status),children:String(e?.status||`draft`)})}),c(`td`,{className:`px-2 py-3 text-slate-300`,children:String(e?.mutation_summary||`pending`)}),c(`td`,{className:`px-2 py-3 text-slate-300`,children:n?y(n.artifact_validator_pass_rate):`n/a`}),c(`td`,{className:`px-2 py-3 text-slate-300`,children:String(e?.promotion_recommendation||`n/a`)}),c(`td`,{className:`px-2 py-3`,children:c(`div`,{className:`flex flex-wrap gap-2`,children:[c(`button`,{className:`tcp-btn h-7 px-2 text-xs`,onClick:()=>P.mutate({optimizationId:k,action:`approve_winner`,experimentId:t}),disabled:!t||P.isPending,children:`Approve`}),c(`button`,{className:`tcp-btn h-7 px-2 text-xs`,onClick:()=>P.mutate({optimizationId:k,action:`reject_winner`,experimentId:t}),disabled:!t||P.isPending,children:`Reject`}),c(`button`,{className:`tcp-btn h-7 px-2 text-xs`,onClick:()=>F.mutate({optimizationId:k,experimentId:t}),disabled:!t||F.isPending||String(e?.status||``).trim().toLowerCase()!==`promotion_approved`,children:`Apply`})]})})]},t)})})]})}):c(p,{text:`No experiments recorded for this campaign yet.`})]})]}):c(`div`,{className:`rounded-xl border border-slate-700/50 bg-slate-950/40 p-6`,children:c(p,{text:`Select or create an optimization campaign to inspect it.`})})})]})}function C(e,t){return Array.isArray(e)?e:Array.isArray(e?.[t])?e[t]:[]}function w({client:e,toast:t}){let n=i(),r=a({queryKey:[`automations`,`approvals`],queryFn:()=>e?.agentTeams?.listApprovals?.().catch(()=>({spawnApprovals:[]}))??Promise.resolve({spawnApprovals:[]}),refetchInterval:6e3}),s=a({queryKey:[`automations`,`instances`],queryFn:()=>e?.agentTeams?.listInstances?.().catch(()=>({instances:[]}))??Promise.resolve({instances:[]}),refetchInterval:8e3}),l=o({mutationFn:({requestId:t,decision:n})=>e?.agentTeams?.replyApproval?.(t,n),onSuccess:async()=>{t(`ok`,`Approval updated.`),await n.invalidateQueries({queryKey:[`automations`]})},onError:e=>t(`err`,e instanceof Error?e.message:String(e))}),u=C(r.data,`spawnApprovals`),d=C(s.data,`instances`);return c(`div`,{className:`grid gap-4`,children:[u.length>0?c(`div`,{className:`grid gap-2`,children:[c(`p`,{className:`text-xs font-medium uppercase tracking-wide text-slate-500`,children:`Pending Approvals`}),u.map((e,t)=>{let n=String(e?.request_id||e?.id||`request-${t}`);return c(`div`,{className:`tcp-list-item border-amber-500/40`,children:[c(`div`,{className:`mb-1 font-medium text-amber-300`,children:[`⚠️ `,String(e?.reason||e?.title||`Spawn request`)]}),c(`div`,{className:`tcp-subtle text-xs`,children:n}),c(`div`,{className:`mt-2 flex gap-2`,children:[c(`button`,{className:`tcp-btn-primary h-7 px-2 text-xs`,onClick:()=>l.mutate({requestId:n,decision:`approve`}),children:[c(`i`,{"data-lucide":`badge-check`}),`Approve`]}),c(`button`,{className:`tcp-btn-danger h-7 px-2 text-xs`,onClick:()=>l.mutate({requestId:n,decision:`deny`}),children:[c(`i`,{"data-lucide":`x`}),`Deny`]})]})]},n)})]}):null,d.length>0?c(`div`,{className:`grid gap-2`,children:[c(`p`,{className:`text-xs font-medium uppercase tracking-wide text-slate-500`,children:`Active Teams`}),d.map((e,t)=>c(`div`,{className:`tcp-list-item`,children:[c(`div`,{className:`flex items-center justify-between gap-2`,children:[c(`div`,{className:`flex items-center gap-2`,children:[c(`span`,{children:`👥`}),c(`strong`,{children:String(e?.name||e?.template_id||e?.instance_id||`Instance`)})]}),c(`span`,{className:`tcp-badge-info`,children:String(e?.status||`active`)})]}),c(`div`,{className:`tcp-subtle mt-1 text-xs`,children:[`Mission: `,String(e?.mission_id||`—`)]})]},String(e?.instance_id||e?.id||t)))]}):null,!u.length&&!d.length?c(p,{text:`No active teams or pending approvals right now.`}):null]})}function T({client:e,toast:n,navigate:r}){return c(d,{className:`grid gap-4`,children:[c(l,{eyebrow:`Opt-in surface`,title:`Experiments`,subtitle:`This page stays hidden by default. Turn it on from Settings > Navigation when you want access to the experimental automation surfaces.`,badges:c(t,{children:[c(u,{tone:`warn`,children:`Hidden by default`}),c(u,{tone:`ghost`,children:`Settings required`})]}),actions:c(`button`,{type:`button`,className:`tcp-btn-primary`,onClick:()=>r(`settings`),children:`Open Settings`})}),c(f,{title:`Why this is separate`,subtitle:`These tools are useful, but they are not the main entry point for new users.`,children:c(`div`,{className:`grid gap-3 text-sm text-slate-200`,children:[c(`p`,{children:`Keep the Automations page focused on the core loop: create, schedule, review, and run.`}),c(`p`,{className:`tcp-subtle`,children:`Experiments is where we park the exploratory surfaces until they have a clearer home.`})]})}),c(f,{title:`Optimization campaigns`,subtitle:`Shadow evals, optimization runs, and the related workflow tooling.`,children:c(S,{client:e,toast:n})}),c(f,{title:`Teams and approvals`,subtitle:`Pending spawn approvals and active team instances.`,children:c(w,{client:e,toast:n})})]})}export{T as ExperimentsPage};
84
+ `;function _(e,t){return Array.isArray(e)?e:Array.isArray(e?.[t])?e[t]:[]}function v(e){let t=String(e||``).trim().toLowerCase();return t===`running`?`tcp-badge-warn`:t.includes(`paused`)?`tcp-badge-info`:t===`completed`?`tcp-badge-ok`:t===`failed`?`tcp-badge-err`:t.includes(`approval`)?`tcp-badge-warn`:`tcp-badge-info`}function y(e){let t=Number(e);return Number.isFinite(t)?t.toFixed(3):`n/a`}var b=Object.entries(Object.assign({"./smoke-workflows/extract-format.yaml":h,"./smoke-workflows/summary.yaml":g})).map(([e,t])=>{let n=s.parse(t);if(!n||typeof n!=`object`)throw Error(`Invalid smoke workflow template at `+e+`: expected a YAML object.`);let r=n,i=String(r.kind||``).trim();if(i!==`summary`&&i!==`extract_format`)throw Error(`Invalid smoke workflow template at `+e+`: missing kind.`);return{kind:i,payload:r}}).sort((e,t)=>e.kind.localeCompare(t.kind));function x(e,t){let n=b.find(t=>t.kind===e);if(!n)throw Error(`Unknown smoke workflow kind: `+e);let{kind:r,...i}=structuredClone(n.payload);return i.workspace_root=String(t||``).trim(),i}function S({client:s,toast:l}){let u=i(),[d,p]=r(``),[h,g]=r({name:``,sourceWorkflowId:``,smokeWorkspaceRoot:``,objectiveRef:`objective.md`,evalRef:`eval.yaml`,mutationPolicyRef:`mutation_policy.yaml`,scopeRef:`scope.yaml`,budgetRef:`budget.yaml`,modelProvider:``,modelId:``,startImmediately:!0}),b=a({queryKey:[`optimizations`,`workflows`,`automations-v2`],queryFn:()=>s?.automationsV2?.list?.().catch(()=>({automations:[]}))??Promise.resolve({automations:[]})}),S=a({queryKey:[`optimizations`,`list`],queryFn:()=>s?.optimizations?.list?.().catch(()=>({optimizations:[]}))??Promise.resolve({optimizations:[]})}),C=a({queryKey:[`optimizations`,`health`],queryFn:()=>s.health().catch(()=>({})),refetchInterval:3e4}),w=a({queryKey:[`optimizations`,`providers`,`catalog`],queryFn:()=>s.providers.catalog().catch(()=>({all:[]})),refetchInterval:3e4}),T=a({queryKey:[`optimizations`,`providers`,`config`],queryFn:()=>s.providers.config().catch(()=>({})),refetchInterval:3e4}),E=n(()=>_(S.data,`optimizations`),[S.data]),D=n(()=>m({providerCatalog:w.data,providerConfig:T.data,defaultProvider:String(T.data?.default||``).trim(),defaultModel:String(T.data?.providers?.[String(T.data?.default||``).trim()]?.default_model||T.data?.providers?.[String(T.data?.default||``).trim()]?.defaultModel||``).trim()}),[w.data,T.data]),O=n(()=>{let e=D.find(e=>e.id===String(h.modelProvider||``).trim());return Array.isArray(e?.models)?e.models:[]},[h.modelProvider,D]);e(()=>{let e=String(C.data?.workspaceRoot||C.data?.workspace_root||``).trim();e&&g(t=>String(t.smokeWorkspaceRoot||``).trim()?t:{...t,smokeWorkspaceRoot:`${e}/docs/internal/optimization-smoke-pack`})},[C.data]);let k=d||String(E[0]?.optimization_id||``).trim(),A=a({queryKey:[`optimizations`,`detail`,k],enabled:!!k,queryFn:()=>s.optimizations.get(k)}),j=a({queryKey:[`optimizations`,`experiments`,k],enabled:!!k,queryFn:()=>s.optimizations.listExperiments(k)}),M=o({mutationFn:async()=>{let e=String(h.sourceWorkflowId||``).trim();if(!e)throw Error(`Source workflow is required.`);let t={name:String(h.name||``).trim()||void 0,source_workflow_id:e,artifacts:{objective_ref:String(h.objectiveRef||``).trim(),eval_ref:String(h.evalRef||``).trim(),mutation_policy_ref:String(h.mutationPolicyRef||``).trim(),scope_ref:String(h.scopeRef||``).trim(),budget_ref:String(h.budgetRef||``).trim()},execution_override:String(h.modelProvider||``).trim()&&String(h.modelId||``).trim()?{provider_id:String(h.modelProvider||``).trim(),model_id:String(h.modelId||``).trim()}:void 0},n=await s.optimizations.create(t);if(h.startImmediately){let e=String(n?.optimization?.optimization_id||``).trim();e&&await s.optimizations.action(e,{action:`start`})}return n},onSuccess:async e=>{let t=String(e?.optimization?.optimization_id||``).trim();l(`ok`,`Optimization campaign created.`),t&&p(t),await u.invalidateQueries({queryKey:[`optimizations`]})},onError:e=>l(`err`,e instanceof Error?e.message:String(e))}),N=o({mutationFn:async e=>{let t=String(h.smokeWorkspaceRoot||``).trim();if(!t)throw Error(`Smoke workflow workspace root is required.`);if(!s?.automationsV2?.create)throw Error(`Workflow creation client is unavailable.`);let n=x(e,t);return s.automationsV2.create(n)},onSuccess:async(e,t)=>{let n=String(e?.automation?.automation_id||e?.automation?.automationId||``).trim();g(t=>({...t,sourceWorkflowId:n||t.sourceWorkflowId,name:n&&!String(t.name||``).trim()?`Optimize ${String(e?.automation?.name||n).trim()}`:t.name})),l(`ok`,t===`summary`?`Smoke summary workflow created and selected.`:`Smoke extract-format workflow created and selected.`),await u.invalidateQueries({queryKey:[`optimizations`,`workflows`,`automations-v2`]})},onError:e=>l(`err`,e instanceof Error?e.message:String(e))}),P=o({mutationFn:async({optimizationId:e,action:t,experimentId:n})=>s.optimizations.action(e,{action:t,experiment_id:n}),onSuccess:async()=>{l(`ok`,`Optimization action applied.`),await u.invalidateQueries({queryKey:[`optimizations`]})},onError:e=>l(`err`,e instanceof Error?e.message:String(e))}),F=o({mutationFn:async({optimizationId:e,experimentId:t})=>s.optimizations.applyWinner(e,t),onSuccess:async()=>{l(`ok`,`Approved winner applied to the live workflow.`),await u.invalidateQueries({queryKey:[`optimizations`]}),await u.invalidateQueries({queryKey:[`optimizations`,`detail`,k]}),await u.invalidateQueries({queryKey:[`optimizations`,`experiments`,k]}),await u.invalidateQueries({queryKey:[`optimizations`,`workflows`,`automations-v2`]})},onError:e=>l(`err`,e instanceof Error?e.message:String(e))}),I=_(b.data,`automations`).map(e=>({id:String(e?.automation_id||e?.automationId||e?.id||``).trim(),name:String(e?.name||e?.automation_id||`Workflow`).trim()})),L=A.data?.optimization||null,R=_(j.data,`experiments`),z=L?.baseline_metrics||null;return c(`div`,{className:`grid gap-4 lg:grid-cols-[minmax(320px,380px),minmax(0,1fr)]`,children:[c(`div`,{className:`grid gap-4`,children:[c(`div`,{className:`rounded-xl border border-slate-700/50 bg-slate-950/40 p-4`,children:[c(`div`,{className:`mb-1 text-sm font-semibold text-slate-100`,children:`New Optimization Campaign`}),c(`div`,{className:`tcp-subtle text-xs`,children:`Create a shadow-eval workflow optimization campaign from an existing automation.`}),c(`div`,{className:`mt-1 text-xs text-slate-500`,children:[`Inspired by`,` `,c(`a`,{className:`text-amber-300 hover:text-amber-200`,href:`https://github.com/karpathy/autoresearch`,target:`_blank`,rel:`noreferrer`,children:`karpathy/autoresearch`}),`.`]}),c(`div`,{className:`mt-3 grid gap-3`,children:[c(`label`,{className:`grid gap-1 text-xs text-slate-300`,children:[c(`span`,{children:`Name`}),c(`input`,{className:`rounded-lg border border-slate-700 bg-slate-950 px-3 py-2 text-sm`,value:h.name,onChange:e=>g(t=>({...t,name:e.target.value})),placeholder:`Optimize research brief workflow`})]}),c(`label`,{className:`grid gap-1 text-xs text-slate-300`,children:[c(`span`,{children:`Source workflow`}),c(`select`,{className:`rounded-lg border border-slate-700 bg-slate-950 px-3 py-2 text-sm`,value:h.sourceWorkflowId,onChange:e=>g(t=>({...t,sourceWorkflowId:e.target.value})),children:[c(`option`,{value:``,children:`Select a workflow`}),I.map(e=>c(`option`,{value:e.id,children:e.name},e.id))]})]}),c(`div`,{className:`rounded-lg border border-slate-800 bg-slate-950/50 p-3`,children:[c(`div`,{className:`text-xs font-medium text-slate-200`,children:`Need a cheap target first?`}),c(`div`,{className:`mt-1 text-[11px] text-slate-500`,children:`Create a tiny validator-backed workflow in the smoke-pack workspace, then use it as the optimization source.`}),c(`label`,{className:`mt-3 grid gap-1 text-xs text-slate-300`,children:[c(`span`,{children:`Smoke workspace root`}),c(`input`,{className:`rounded-lg border border-slate-700 bg-slate-950 px-3 py-2 text-sm`,value:h.smokeWorkspaceRoot,onChange:e=>g(t=>({...t,smokeWorkspaceRoot:e.target.value})),placeholder:`/abs/path/to/docs/internal/optimization-smoke-pack`})]}),c(`div`,{className:`mt-3 flex flex-wrap gap-2`,children:[c(`button`,{className:`tcp-btn h-9 px-3 text-xs`,onClick:()=>N.mutate(`summary`),disabled:N.isPending,children:`Create Smoke Summary`}),c(`button`,{className:`tcp-btn h-9 px-3 text-xs`,onClick:()=>N.mutate(`extract_format`),disabled:N.isPending,children:`Create Extract + Format`})]})]}),c(`label`,{className:`grid gap-1 text-xs text-slate-300`,children:[c(`span`,{children:`Model provider`}),c(`select`,{className:`rounded-lg border border-slate-700 bg-slate-950 px-3 py-2 text-sm`,value:h.modelProvider,onChange:e=>g(t=>({...t,modelProvider:e.target.value,modelId:e.target.value&&t.modelProvider!==e.target.value?``:t.modelId})),children:[c(`option`,{value:``,children:`Use workflow/default model`}),D.map(e=>c(`option`,{value:e.id,children:e.id},e.id))]})]}),c(`label`,{className:`grid gap-1 text-xs text-slate-300`,children:[c(`span`,{children:`Model id`}),c(`input`,{className:`rounded-lg border border-slate-700 bg-slate-950 px-3 py-2 text-sm`,value:h.modelId,onChange:e=>g(t=>({...t,modelId:e.target.value})),placeholder:h.modelProvider?`Pick a cheaper model for this campaign`:`Optional`,list:`optimization-model-ids`}),c(`datalist`,{id:`optimization-model-ids`,children:O.map(e=>c(`option`,{value:e},e))}),c(`span`,{className:`tcp-subtle text-[11px]`,children:`Fixed for the whole campaign. Leave blank to use the workflow's existing model settings.`})]}),[[`Objective ref`,`objectiveRef`],[`Eval ref`,`evalRef`],[`Mutation policy ref`,`mutationPolicyRef`],[`Scope ref`,`scopeRef`],[`Budget ref`,`budgetRef`]].map(([e,t])=>c(`label`,{className:`grid gap-1 text-xs text-slate-300`,children:[c(`span`,{children:e}),c(`input`,{className:`rounded-lg border border-slate-700 bg-slate-950 px-3 py-2 text-sm`,value:h[t],onChange:e=>g(n=>({...n,[t]:e.target.value}))})]},t)),c(`label`,{className:`flex items-center gap-2 text-xs text-slate-300`,children:[c(`input`,{type:`checkbox`,checked:h.startImmediately,onChange:e=>g(t=>({...t,startImmediately:e.target.checked}))}),`Start immediately after create`]}),c(`button`,{className:`tcp-btn h-10 px-3 text-sm`,onClick:()=>M.mutate(),disabled:M.isPending,children:M.isPending?`Creating...`:`Create Campaign`})]})]}),c(`div`,{className:`rounded-xl border border-slate-700/50 bg-slate-950/40 p-4`,children:[c(`div`,{className:`mb-2 flex items-center justify-between gap-2`,children:[c(`div`,{className:`text-sm font-semibold text-slate-100`,children:`Campaigns`}),c(`span`,{className:`tcp-badge-info`,children:E.length})]}),c(`div`,{className:`grid gap-2`,children:E.length?E.map(e=>{let t=String(e?.optimization_id||``).trim();return c(`button`,{type:`button`,className:`rounded-xl border px-3 py-3 text-left transition ${k===t?`border-amber-400/60 bg-amber-400/10`:`border-slate-700/50 bg-slate-950/40 hover:border-slate-600`}`,onClick:()=>p(t),children:[c(`div`,{className:`flex items-center justify-between gap-2`,children:[c(`div`,{className:`font-medium text-slate-100`,children:String(e?.name||t||`Optimization`)}),c(`span`,{className:v(e?.status),children:String(e?.status||`draft`)})]}),c(`div`,{className:`mt-1 text-xs text-slate-400`,children:[`workflow:`,` `,String(e?.source_workflow_name||e?.source_workflow_id||`unknown`)]})]},t)}):c(f,{text:`No optimization campaigns yet.`})})]})]}),c(`div`,{className:`grid gap-4`,children:L?c(t,{children:[c(`div`,{className:`rounded-xl border border-slate-700/50 bg-slate-950/40 p-4`,children:[c(`div`,{className:`flex flex-wrap items-start justify-between gap-3`,children:[c(`div`,{children:[c(`div`,{className:`text-lg font-semibold text-slate-100`,children:String(L?.name||L?.optimization_id||`Optimization`)}),c(`div`,{className:`mt-1 text-sm text-slate-400`,children:[`Source workflow:`,` `,String(L?.source_workflow_name||L?.source_workflow_id||`unknown`)]}),c(`div`,{className:`mt-1 text-xs text-slate-500`,children:[`baseline: `,String(L?.baseline_snapshot_hash||``).slice(0,12)]}),L?.execution_override?c(`div`,{className:`mt-1 text-xs text-slate-500`,children:[`model: `,String(L.execution_override.provider_id||``).trim(),`/`,String(L.execution_override.model_id||``).trim()]}):null]}),c(`div`,{className:`flex flex-wrap gap-2`,children:[c(`button`,{className:`tcp-btn h-8 px-3 text-xs`,onClick:()=>P.mutate({optimizationId:k,action:`start`}),disabled:P.isPending,children:`Start`}),c(`button`,{className:`tcp-btn h-8 px-3 text-xs`,onClick:()=>P.mutate({optimizationId:k,action:`pause`}),disabled:P.isPending,children:`Pause`}),c(`button`,{className:`tcp-btn h-8 px-3 text-xs`,onClick:()=>P.mutate({optimizationId:k,action:`resume`}),disabled:P.isPending,children:`Resume`})]})]}),c(`div`,{className:`mt-4 grid gap-3 md:grid-cols-4`,children:[c(`div`,{className:`rounded-lg border border-slate-800 bg-slate-950/60 p-3`,children:[c(`div`,{className:`text-[11px] uppercase tracking-[0.22em] text-slate-500`,children:`Status`}),c(`div`,{className:`mt-1 text-sm text-slate-100`,children:String(L?.status||`draft`)})]}),c(`div`,{className:`rounded-lg border border-slate-800 bg-slate-950/60 p-3`,children:[c(`div`,{className:`text-[11px] uppercase tracking-[0.22em] text-slate-500`,children:`Pass Rate`}),c(`div`,{className:`mt-1 text-sm text-slate-100`,children:z?y(z.artifact_validator_pass_rate):`n/a`})]}),c(`div`,{className:`rounded-lg border border-slate-800 bg-slate-950/60 p-3`,children:[c(`div`,{className:`text-[11px] uppercase tracking-[0.22em] text-slate-500`,children:`Unmet Reqs`}),c(`div`,{className:`mt-1 text-sm text-slate-100`,children:z?y(z.unmet_requirement_count):`n/a`})]}),c(`div`,{className:`rounded-lg border border-slate-800 bg-slate-950/60 p-3`,children:[c(`div`,{className:`text-[11px] uppercase tracking-[0.22em] text-slate-500`,children:`Blocked Rate`}),c(`div`,{className:`mt-1 text-sm text-slate-100`,children:z?y(z.blocked_node_rate):`n/a`})]})]}),L?.last_pause_reason?c(`div`,{className:`mt-3 rounded-lg border border-amber-500/30 bg-amber-500/10 p-3 text-sm text-amber-200`,children:String(L.last_pause_reason)}):null]}),c(`div`,{className:`rounded-xl border border-slate-700/50 bg-slate-950/40 p-4`,children:[c(`div`,{className:`mb-2 flex items-center justify-between gap-2`,children:[c(`div`,{className:`text-sm font-semibold text-slate-100`,children:`Experiments`}),c(`span`,{className:`tcp-badge-info`,children:R.length})]}),R.length?c(`div`,{className:`overflow-x-auto`,children:c(`table`,{className:`min-w-full text-left text-sm`,children:[c(`thead`,{className:`text-xs uppercase tracking-[0.22em] text-slate-500`,children:c(`tr`,{children:[c(`th`,{className:`px-2 py-2`,children:`Experiment`}),c(`th`,{className:`px-2 py-2`,children:`Status`}),c(`th`,{className:`px-2 py-2`,children:`Mutation`}),c(`th`,{className:`px-2 py-2`,children:`Pass`}),c(`th`,{className:`px-2 py-2`,children:`Recommendation`}),c(`th`,{className:`px-2 py-2`,children:`Action`})]})}),c(`tbody`,{children:R.map(e=>{let t=String(e?.experiment_id||``).trim(),n=e?.phase1_metrics||{};return c(`tr`,{className:`border-t border-slate-800`,children:[c(`td`,{className:`px-2 py-3 text-slate-200`,children:t||`unknown`}),c(`td`,{className:`px-2 py-3`,children:c(`span`,{className:v(e?.status),children:String(e?.status||`draft`)})}),c(`td`,{className:`px-2 py-3 text-slate-300`,children:String(e?.mutation_summary||`pending`)}),c(`td`,{className:`px-2 py-3 text-slate-300`,children:n?y(n.artifact_validator_pass_rate):`n/a`}),c(`td`,{className:`px-2 py-3 text-slate-300`,children:String(e?.promotion_recommendation||`n/a`)}),c(`td`,{className:`px-2 py-3`,children:c(`div`,{className:`flex flex-wrap gap-2`,children:[c(`button`,{className:`tcp-btn h-7 px-2 text-xs`,onClick:()=>P.mutate({optimizationId:k,action:`approve_winner`,experimentId:t}),disabled:!t||P.isPending,children:`Approve`}),c(`button`,{className:`tcp-btn h-7 px-2 text-xs`,onClick:()=>P.mutate({optimizationId:k,action:`reject_winner`,experimentId:t}),disabled:!t||P.isPending,children:`Reject`}),c(`button`,{className:`tcp-btn h-7 px-2 text-xs`,onClick:()=>F.mutate({optimizationId:k,experimentId:t}),disabled:!t||F.isPending||String(e?.status||``).trim().toLowerCase()!==`promotion_approved`,children:`Apply`})]})})]},t)})})]})}):c(f,{text:`No experiments recorded for this campaign yet.`})]})]}):c(`div`,{className:`rounded-xl border border-slate-700/50 bg-slate-950/40 p-6`,children:c(f,{text:`Select or create an optimization campaign to inspect it.`})})})]})}function C(e,t){return Array.isArray(e)?e:Array.isArray(e?.[t])?e[t]:[]}function w({client:e,toast:t}){let n=i(),r=a({queryKey:[`automations`,`approvals`],queryFn:()=>e?.agentTeams?.listApprovals?.().catch(()=>({spawnApprovals:[]}))??Promise.resolve({spawnApprovals:[]}),refetchInterval:6e3}),s=a({queryKey:[`automations`,`instances`],queryFn:()=>e?.agentTeams?.listInstances?.().catch(()=>({instances:[]}))??Promise.resolve({instances:[]}),refetchInterval:8e3}),l=o({mutationFn:({requestId:t,decision:n})=>e?.agentTeams?.replyApproval?.(t,n),onSuccess:async()=>{t(`ok`,`Approval updated.`),await n.invalidateQueries({queryKey:[`automations`]})},onError:e=>t(`err`,e instanceof Error?e.message:String(e))}),u=C(r.data,`spawnApprovals`),d=C(s.data,`instances`);return c(`div`,{className:`grid gap-4`,children:[u.length>0?c(`div`,{className:`grid gap-2`,children:[c(`p`,{className:`text-xs font-medium uppercase tracking-wide text-slate-500`,children:`Pending Approvals`}),u.map((e,t)=>{let n=String(e?.request_id||e?.id||`request-${t}`);return c(`div`,{className:`tcp-list-item border-amber-500/40`,children:[c(`div`,{className:`mb-1 font-medium text-amber-300`,children:[`⚠️ `,String(e?.reason||e?.title||`Spawn request`)]}),c(`div`,{className:`tcp-subtle text-xs`,children:n}),c(`div`,{className:`mt-2 flex gap-2`,children:[c(`button`,{className:`tcp-btn-primary h-7 px-2 text-xs`,onClick:()=>l.mutate({requestId:n,decision:`approve`}),children:[c(`i`,{"data-lucide":`badge-check`}),`Approve`]}),c(`button`,{className:`tcp-btn-danger h-7 px-2 text-xs`,onClick:()=>l.mutate({requestId:n,decision:`deny`}),children:[c(`i`,{"data-lucide":`x`}),`Deny`]})]})]},n)})]}):null,d.length>0?c(`div`,{className:`grid gap-2`,children:[c(`p`,{className:`text-xs font-medium uppercase tracking-wide text-slate-500`,children:`Active Teams`}),d.map((e,t)=>c(`div`,{className:`tcp-list-item`,children:[c(`div`,{className:`flex items-center justify-between gap-2`,children:[c(`div`,{className:`flex items-center gap-2`,children:[c(`span`,{children:`👥`}),c(`strong`,{children:String(e?.name||e?.template_id||e?.instance_id||`Instance`)})]}),c(`span`,{className:`tcp-badge-info`,children:String(e?.status||`active`)})]}),c(`div`,{className:`tcp-subtle mt-1 text-xs`,children:[`Mission: `,String(e?.mission_id||`—`)]})]},String(e?.instance_id||e?.id||t)))]}):null,!u.length&&!d.length?c(f,{text:`No active teams or pending approvals right now.`}):null]})}function T({client:e,toast:n,navigate:r}){return c(d,{className:`grid gap-4`,children:[c(l,{eyebrow:`Opt-in surface`,title:`Experiments`,subtitle:`This page stays hidden by default. Turn it on from Settings > Navigation when you want access to the experimental automation surfaces.`,badges:c(t,{children:[c(u,{tone:`warn`,children:`Hidden by default`}),c(u,{tone:`ghost`,children:`Settings required`})]}),actions:c(`button`,{type:`button`,className:`tcp-btn-primary`,onClick:()=>r(`settings`),children:`Open Settings`})}),c(p,{title:`Why this is separate`,subtitle:`These tools are useful, but they are not the main entry point for new users.`,children:c(`div`,{className:`grid gap-3 text-sm text-slate-200`,children:[c(`p`,{children:`Keep the Automations page focused on the core loop: create, schedule, review, and run.`}),c(`p`,{className:`tcp-subtle`,children:`Experiments is where we park the exploratory surfaces until they have a clearer home.`})]})}),c(p,{title:`Optimization campaigns`,subtitle:`Shadow evals, optimization runs, and the related workflow tooling.`,children:c(S,{client:e,toast:n})}),c(p,{title:`Teams and approvals`,subtitle:`Pending spawn approvals and active team instances.`,children:c(w,{client:e,toast:n})})]})}export{T as ExperimentsPage};
@@ -0,0 +1 @@
1
+ import{C as e,E as t,g as n,h as r,v as i}from"./fullcalendar-Bn75j0xM.js";import{a,n as o,t as s}from"./react-query-BIbNygEJ.js";import{i as c,n as ee,r as l}from"./motion-B3ZE8SGR.js";import{T as te,_ as u,a as ne,h as d,m as f,s as p,t as m,u as re,x as ie}from"./index-TvymvGva.js";import{i as h,n as ae,t as oe}from"./explorerHandoff-BPKxMR82.js";import{n as g,t as se}from"./ControlPanelDialogs-yFfCht3Y.js";import{t as _}from"./MemoryImportDialog-DSpS1JF5.js";var v=3,y=`.md,.markdown,.txt,text/plain,text/markdown`,b=[10,25,50,100],ce=25;function le(){return`${Date.now()}-${Math.random().toString(16).slice(2)}`}function ue(e){let t=String(e||``).trim();if(!t)return``;let n=t.split(`/`);return(n[n.length-1]||t).replace(/\.[^.]+$/,``)}function x(e){return Array.isArray(e)?e:Array.isArray(e?.documents)?e.documents:Array.isArray(e?.items)?e.items:e?.document&&typeof e.document==`object`?[e.document]:[]}function S(e){let t=String(e.collection_id||``).trim();if(t)return t;let n=String(e.doc_id||e.id||``).trim(),r=n.indexOf(`/`);return r>0?n.slice(0,r):``}function de(e){let t=S(e),n=String(e.doc_id||e.id||``).trim();return!t||!n?``:`${t}|${n}`}function fe(e){let t=Number(e||0);return t?new Date(t).toLocaleString():`n/a`}function pe(e){let t=Number(e||0);if(!t)return`n/a`;if(t<1024)return`${t} B`;let n=[`KB`,`MB`,`GB`,`TB`],r=t/1024,i=0;for(;r>=1024&&i<n.length-1;)r/=1024,i+=1;return`${r.toFixed(r>=10?0:1)} ${n[i]}`}function me(e){let t=String(e?.content_type||``).toLowerCase(),n=String(e?.title||e?.filename||e?.file_name||``).toLowerCase();return t.includes(`markdown`)||n.endsWith(`.md`)||n.endsWith(`.markdown`)?`markdown`:t.includes(`json`)||n.endsWith(`.json`)?`json`:`text`}function C(e){let t=S(e||{}),n=String(e?.doc_id||e?.id||``).trim();return!t||!n?``:n.startsWith(`${t}/`)?n.slice(t.length+1):n}function w(e,t){return!Number.isFinite(e)||e<1||!Number.isFinite(t)||t<1?1:Math.min(e,t)}function T(e,t,n){if(!n)return`0 of 0`;let r=w(e,Math.max(1,Math.ceil(n/Math.max(1,t)))),i=Math.max(1,t);return`${(r-1)*i+1}-${Math.min(n,r*i)} of ${n}`}function he({api:t,toast:f,defaultCollectionId:p}){let m=a(),h=r(null),ae=r(null),oe=r(null),g=r(new Map),_=r(new Map),he=r(0),[E,D]=i(``),[O,ge]=i(!1),[_e,ve]=i(!1),[ye,be]=i(!1),[xe,Se]=i(``),[k,Ce]=i(``),[we,A]=i(!1),[j,M]=i(!1),[Te,N]=i(``),[Ee,P]=i(``),[F,De]=i(1),[I,Oe]=i(ce),[L,ke]=i(null),[Ae,je]=i([]),[Me,Ne]=i(null),[R,Pe]=i(null),[z,B]=i([]),[Fe,V]=i(!1),H=o({queryKey:[`knowledgebase`,`config`],queryFn:async()=>t(`/api/knowledgebase/config`).catch(()=>({configured:!1})),staleTime:6e4}).data?.configured===!0,Ie=o({queryKey:[`knowledgebase`,`collections`],enabled:H,queryFn:async()=>t(`/api/knowledgebase/collections`).catch(()=>({collections:[]})),staleTime:3e4,refetchInterval:6e4}),Le=Array.isArray(Ie.data?.collections)?Ie.data.collections:[];e(()=>{if(O)return;let e=String(p||``).trim();!E.trim()&&e&&D(e)},[E,O,p]),e(()=>{if(O||E.trim())return;let e=String(Le[0]?.collection_id||``).trim();e&&D(e)},[E,O,Le]),e(()=>{let e=oe.current;e&&(e.setAttribute(`webkitdirectory`,``),e.setAttribute(`directory`,``))},[]);let U=E.trim();e(()=>{De(1),je([]),ke(null),Ce(``),A(!0),M(!1),P(``)},[U]),e(()=>{De(1)},[xe]);let Re=(Math.max(1,F)-1)*Math.max(1,I),W=xe.trim(),ze=o({queryKey:[`knowledgebase`,`documents`,U||`__all__`,W,F,I],enabled:H,queryFn:async()=>{let e=new URLSearchParams;return U&&e.set(`collection_id`,U),e.set(`limit`,String(Math.max(1,I))),e.set(`offset`,String(Math.max(0,Re))),W&&e.set(`query`,W),t(`/api/knowledgebase/documents?${e.toString()}`).catch(()=>({collection_id:U||null,documents:[],total:0,offset:Re,limit:I,has_more:!1}))},staleTime:15e3,refetchInterval:U?3e4:!1}),Be=ze.data||{},G=n(()=>x(Be),[Be]),Ve=Math.max(0,Number(Be.total??G.length??0)),K=Math.max(1,Number(Be.limit??I)||I),q=Math.max(0,Number(Be.offset??Re)||Re),He=Math.max(1,Math.ceil(Math.max(Ve,G.length)/Math.max(1,I))),J=w(F,He),Ue=q,We=G,Ge=T(J,K,Ve);e(()=>{F!==J&&De(J)},[F,J]),e(()=>{k&&A(!0)},[k]);let Ke=Le,qe=n(()=>[...Ke].sort((e,t)=>String(e.collection_id).localeCompare(String(t.collection_id))),[Ke]),Je=n(()=>{let e=new Map,t=t=>{let n=typeof t==`string`?t.trim():String(t?.collection_id||``).trim();!n||e.has(n)||e.set(n,typeof t==`string`?{collection_id:n}:{...t,collection_id:n})};t(p);for(let e of qe)t(e);return t(U),Array.from(e.values()).sort((e,t)=>String(e.collection_id).localeCompare(String(t.collection_id)))},[qe,U,p]),Ye=Je.some(e=>String(e.collection_id||``).trim()===U)?U:`__custom__`,Xe=Ye===`__custom__`,Ze=n(()=>new Set(Ae.map(e=>e.key)),[Ae]),Qe=Ae,$e=Qe.length,Y=n(()=>L||null,[L]),et=String(Y?.slug||``).trim(),X=String(Y?.collection||``).trim(),Z=o({queryKey:[`knowledgebase`,`document`,X,et],enabled:H&&!!X&&!!et,queryFn:async()=>t(`/api/knowledgebase/documents/${encodeURIComponent(X)}/${encodeURIComponent(et)}`),staleTime:3e4}),Q=Z.data?.document||Z.data||null,tt=me(Q||Y),nt=String(Q?.title||Q?.filename||Q?.file_name||Y?.title||Y?.slug||`Document`).trim(),rt=String(Q?.path||Q?.doc_id||(Y?`${Y.collection}/${Y.slug}`:``)||``).trim(),$=String(Q?.content||Q?.excerpt||``),it=Z.error?Z.error instanceof Error?Z.error.message:String(Z.error):``,at=Number(Q?.updated_at||Q?.created_at||0),ot=Number(Q?.size_bytes||0),st=!!(X&&et),ct=Y?c(`div`,{className:`flex min-h-0 flex-col rounded-xl border border-white/10 bg-black/20 p-3`,children:[c(`div`,{className:`flex items-start justify-between gap-3`,children:[c(`div`,{className:`min-w-0`,children:[c(`div`,{className:`truncate text-sm font-semibold text-slate-100`,children:nt}),c(`div`,{className:`tcp-subtle mt-1 truncate text-xs`,children:rt||et||U})]}),c(`div`,{className:`flex flex-col items-end gap-2`,children:[c(d,{tone:`info`,children:X||U}),c(`div`,{className:`flex flex-wrap justify-end gap-2`,children:[c(`button`,{type:`button`,className:`tcp-btn h-7 w-7 justify-center px-0`,title:`Refresh preview`,"aria-label":`Refresh preview`,onClick:()=>void Z.refetch(),disabled:!k,children:[c(`i`,{"data-lucide":`refresh-cw`}),c(`span`,{className:`sr-only`,children:`Refresh preview`})]}),c(`button`,{type:`button`,className:`tcp-btn h-7 w-7 justify-center px-0`,title:`Copy document content`,"aria-label":`Copy document content`,onClick:()=>void vt(),disabled:!$.trim(),children:[c(`i`,{"data-lucide":`copy`}),c(`span`,{className:`sr-only`,children:`Copy document content`})]}),c(`button`,{type:`button`,className:`tcp-btn h-7 w-7 justify-center border-rose-500/30 px-0 text-rose-200 hover:bg-rose-950/20`,title:`Delete document`,"aria-label":`Delete document`,onClick:()=>Ne({collection:X,slug:et,title:nt}),disabled:!st,children:[c(`i`,{"data-lucide":`trash-2`}),c(`span`,{className:`sr-only`,children:`Delete document`})]})]})]})]}),c(`div`,{className:`mt-3 grid grid-cols-3 gap-2 text-xs`,children:[c(`div`,{className:`rounded-lg border border-white/10 bg-black/10 p-2`,children:[c(`div`,{className:`tcp-subtle`,children:`Type`}),c(`div`,{className:`mt-1 font-medium`,children:String(Q?.content_type||tt||`text`)})]}),c(`div`,{className:`rounded-lg border border-white/10 bg-black/10 p-2`,children:[c(`div`,{className:`tcp-subtle`,children:`Updated`}),c(`div`,{className:`mt-1 font-medium`,children:fe(at)})]}),c(`div`,{className:`rounded-lg border border-white/10 bg-black/10 p-2`,children:[c(`div`,{className:`tcp-subtle`,children:`Size`}),c(`div`,{className:`mt-1 font-medium`,children:pe(ot)})]})]}),c(`div`,{className:`mt-3 rounded-xl border border-white/10 bg-black/10 p-3 text-xs`,children:[c(`div`,{className:`tcp-subtle uppercase tracking-wide`,children:`Excerpt`}),c(`div`,{className:`mt-1 whitespace-pre-wrap break-words text-slate-200`,children:String(Q?.excerpt||$.slice(0,600)||`No excerpt returned.`)})]}),Z.isLoading&&!Q?c(`div`,{className:`mt-3 rounded-xl border border-white/10 bg-black/20 p-3 text-sm tcp-subtle`,children:`Loading preview...`}):it?c(`div`,{className:`mt-3`,children:c(u,{title:`Preview unavailable`,text:it})}):j?c(`div`,{className:`mt-3 flex min-h-0 flex-1 flex-col gap-3 rounded-xl border border-sky-500/30 bg-sky-950/10 p-3`,children:[c(`div`,{className:`flex items-center justify-between gap-3`,children:[c(`div`,{className:`tcp-subtle text-xs uppercase tracking-wide`,children:`Edit document in place`}),c(`div`,{className:`flex flex-wrap gap-2`,children:[c(`button`,{type:`button`,className:`tcp-btn h-7 px-2 text-xs`,onClick:()=>{M(!1),P(``),N(String($||``))},children:`Cancel`}),c(`button`,{type:`button`,className:`tcp-btn h-7 px-2 text-xs`,onClick:()=>void yt(),children:[c(`i`,{"data-lucide":`save`}),`Save`]})]})]}),Ee?c(`div`,{className:`rounded-lg border border-rose-500/30 bg-rose-950/20 p-2 text-xs text-rose-200`,children:Ee}):null,c(`textarea`,{className:`tcp-input min-h-[340px] flex-1 resize-none font-mono text-xs leading-6`,value:Te,onChange:e=>N(e.target.value),spellCheck:!1})]}):we?c(`div`,{className:`mt-3 flex min-h-0 flex-1 flex-col gap-3 rounded-xl border border-white/10 bg-black/20 p-3`,children:[c(`div`,{className:`flex items-center justify-between gap-3`,children:[c(`div`,{className:`tcp-subtle text-xs uppercase tracking-wide`,children:`Document content`}),c(`div`,{className:`flex flex-wrap gap-2`,children:[c(`button`,{type:`button`,className:`tcp-btn h-7 w-7 justify-center px-0`,title:`Edit document`,"aria-label":`Edit document`,onClick:()=>{P(``),M(!0),N(String($||``))},disabled:!$.trim(),children:[c(`i`,{"data-lucide":`square-pen`}),c(`span`,{className:`sr-only`,children:`Edit document`})]}),c(`button`,{type:`button`,className:`tcp-btn h-7 w-7 justify-center px-0`,title:`Collapse preview`,"aria-label":`Collapse preview`,onClick:()=>A(!1),children:[c(`i`,{"data-lucide":`chevron-up`}),c(`span`,{className:`sr-only`,children:`Collapse preview`})]})]})]}),c(`div`,{className:`min-h-0 flex-1 overflow-auto rounded-xl border border-white/10 bg-black/20 p-3`,children:$?tt===`markdown`?c(`div`,{className:`tcp-markdown tcp-markdown-ai`,dangerouslySetInnerHTML:{__html:re($)}}):c(`pre`,{className:`tcp-code whitespace-pre-wrap break-words`,children:$}):c(u,{title:`No preview content`,text:`This document did not return preview text from the KB service.`})})]}):c(u,{title:`Preview collapsed`,text:`Open the document content when you want to inspect or edit it. The list stays compact until you expand a file.`,action:c(`div`,{className:`flex flex-wrap gap-2`,children:[c(`button`,{type:`button`,className:`tcp-btn h-8 w-8 justify-center px-0`,title:`Open content`,"aria-label":`Open content`,onClick:()=>A(!0),children:[c(`i`,{"data-lucide":`chevron-down`}),c(`span`,{className:`sr-only`,children:`Open content`})]}),c(`button`,{type:`button`,className:`tcp-btn h-8 w-8 justify-center px-0`,title:`Edit in place`,"aria-label":`Edit in place`,onClick:()=>{A(!0),P(``),M(!0),N(String($||``))},disabled:!$.trim(),children:[c(`i`,{"data-lucide":`square-pen`}),c(`span`,{className:`sr-only`,children:`Edit in place`})]})]})})]}):null;e(()=>{j||N(String($||``))},[j,$,k]);let lt=z.filter(e=>e.status===`done`||e.status===`error`);e(()=>{for(let e of z){if(e.status!==`done`&&e.status!==`error`||g.current.has(e.id))continue;let t=_.current.get(e.id)??he.current++%6;_.current.set(e.id,t);let n=3e3+t*350,r=window.setTimeout(()=>{B(t=>t.filter(t=>t.id!==e.id)),g.current.delete(e.id),_.current.delete(e.id)},n);g.current.set(e.id,r)}let e=new Set(z.map(e=>e.id));for(let[t,n]of g.current.entries())e.has(t)||(window.clearTimeout(n),g.current.delete(t),_.current.delete(t))},[z]),e(()=>()=>{for(let e of g.current.values())window.clearTimeout(e);g.current.clear(),_.current.clear()},[]),e(()=>{h.current&&ne(h.current)},[qe.length,Je.length,z.length,F,I,Ve,q,K,U,Fe,H,G.length,We.length,k,L,$e,xe,Z.data,Z.isFetching,we,j,_e,ye]);let ut=()=>{for(let e of z){if(e.status!==`done`&&e.status!==`error`)continue;let t=g.current.get(e.id);typeof t==`number`&&window.clearTimeout(t),g.current.delete(e.id),_.current.delete(e.id)}B(e=>e.filter(e=>e.status===`queued`||e.status===`uploading`))},dt=s({mutationFn:({file:e,targetCollection:t})=>new Promise((n,r)=>{let i=le();B(t=>[...t,{id:i,name:e.name,progress:0,status:`queued`,error:``}]);let a=new XMLHttpRequest;a.open(`POST`,`/api/knowledgebase/documents`),a.withCredentials=!0,a.responseType=`json`;let o=new FormData;o.set(`collection_id`,t),o.set(`title`,ue(e.name)),o.set(`file`,e,e.name),a.upload.onprogress=e=>{if(!e.lengthComputable)return;let t=e.loaded/e.total*100;B(e=>e.map(e=>e.id===i?{...e,status:`uploading`,progress:t}:e))},a.onerror=()=>{B(e=>e.map(e=>e.id===i?{...e,status:`error`,error:`Network error`,progress:Math.max(e.progress,4)}:e)),r(Error(`KB upload failed: ${e.name}`))},a.onload=()=>{let o=a.response||{};if(a.status<200||a.status>=300||o?.ok===!1){let e=String(o?.error||`Upload failed (${a.status})`);B(t=>t.map(t=>t.id===i?{...t,status:`error`,error:e,progress:Math.max(t.progress,4)}:t)),r(Error(e));return}let s=o?.document&&typeof o.document==`object`?o.document:o?.doc||o?.item||{},c=String(s?.doc_id||s?.id||o?.doc_id||``).trim(),ee=String(s?.collection_id||t).trim(),l=String(s?.title||s?.filename||s?.file_name||ue(e.name)||e.name).trim();B(e=>e.map(e=>e.id===i?{...e,status:`done`,progress:100,error:``,result:{docId:c,collectionId:ee,title:l}}:e)),n(o)},B(e=>e.map(e=>e.id===i?{...e,status:`uploading`}:e)),a.send(o)})}),ft=async e=>{let t=[...e||[]],n=E.trim();if(!H||!t.length)return;if(!n){f(`warn`,`Choose a knowledgebase collection first.`);return}V(!0);let r=0,i=0,a=0;try{let e=Array.from({length:Math.min(v,t.length)},async()=>{for(;;){let e=a;if(a+=1,e>=t.length)return;let o=t[e];try{await dt.mutateAsync({file:o,targetCollection:n}),r+=1}catch{i+=1}}});await Promise.all(e),await m.invalidateQueries({queryKey:[`knowledgebase`,`collections`]}),await m.invalidateQueries({queryKey:[`knowledgebase`,`documents`]}),r&&i?f(`warn`,`Uploaded ${r} file(s) to ${n}; ${i} failed.`):r?f(`ok`,`Uploaded ${r} file(s) to ${n}.`):i&&f(`err`,`All ${i} KB upload(s) failed.`)}finally{V(!1)}},pt=async()=>{try{await t(`/api/knowledgebase/reindex`,{method:`POST`}),f(`ok`,`Knowledgebase reindex requested.`)}catch(e){f(`err`,e instanceof Error?e.message:String(e))}},mt=e=>{let t=String(S(e)||U).trim(),n=C(e),r=de(e);return!t||!n||!r?null:{collection:t,slug:n,title:String(e.title||e.filename||e.file_name||e.doc_id||n).trim(),key:r}},ht=e=>{let t=mt(e);t&&je(e=>e.some(e=>e.key===t.key)?e.filter(e=>e.key!==t.key):[...e,t])},gt=()=>{let e=G.map(e=>mt(e)).filter(e=>!!e);je(t=>{let n=new Map(t.map(e=>[e.key,e]));for(let t of e)n.set(t.key,t);return[...n.values()]})},_t=()=>{je([])},vt=async()=>{let e=String($||``).trim();if(!e){f(`warn`,`No document content is available to copy.`);return}try{await navigator.clipboard.writeText(e),f(`ok`,`Document content copied to clipboard.`)}catch{f(`warn`,`Could not copy the document content.`)}},yt=async()=>{let e=String(X||``).trim(),t=String(et||``).trim();if(!e||!t){f(`warn`,`Pick a document before saving edits.`);return}P(``);try{let n=new FormData;n.set(`title`,String(nt||``).trim()||t),n.set(`content`,Te);let r=await fetch(`/api/knowledgebase/documents/${encodeURIComponent(e)}/${encodeURIComponent(t)}`,{method:`PUT`,credentials:`include`,body:n}),i=await r.text(),a={};if(i)try{a=JSON.parse(i)}catch{a={}}if(!r.ok||a?.ok===!1){let e=String(a?.error||i||`Update failed (${r.status})`);throw Error(e)}M(!1),A(!0),f(`ok`,`Document updated.`),await m.invalidateQueries({queryKey:[`knowledgebase`,`documents`]}),await m.invalidateQueries({queryKey:[`knowledgebase`,`document`]}),await ze.refetch(),await Z.refetch()}catch(e){let t=e instanceof Error?e.message:String(e);P(t),f(`err`,t)}},bt=()=>{if(!Qe.length){f(`warn`,`Select one or more documents first.`);return}Pe({documents:Qe.map(({collection:e,slug:t,title:n,key:r})=>({collection:e,slug:t,title:n,key:r}))})},xt=async()=>{let e=String(Me?.collection||``).trim(),t=String(Me?.slug||``).trim();if(!e||!t){f(`warn`,`Pick a document before deleting it.`);return}try{let n=await fetch(`/api/knowledgebase/documents/${encodeURIComponent(e)}/${encodeURIComponent(t)}`,{method:`DELETE`,credentials:`include`}),r=await n.text(),i={};if(r)try{i=JSON.parse(r)}catch{i={}}if(!n.ok||i?.ok===!1){let e=String(i?.error||r||`Delete failed (${n.status})`);throw Error(e)}let a=L?.key||``;Ce(``),ke(null),je(e=>e.filter(e=>e.key!==a)),A(!1),M(!1),N(``),P(``),Ne(null),f(`ok`,`Document deleted.`),await m.invalidateQueries({queryKey:[`knowledgebase`,`collections`]}),await m.invalidateQueries({queryKey:[`knowledgebase`,`documents`]}),await ze.refetch()}catch(e){f(`err`,e instanceof Error?e.message:String(e))}},St=async()=>{let e=R?.documents||[];if(!e.length){f(`warn`,`Select one or more documents first.`);return}let t=new Map(Ae.map(e=>[e.key,e])),n=0,r=0;try{for(let i of e)try{let e=await fetch(`/api/knowledgebase/documents/${encodeURIComponent(i.collection)}/${encodeURIComponent(i.slug)}`,{method:`DELETE`,credentials:`include`}),r=await e.text(),a={};if(r)try{a=JSON.parse(r)}catch{a={}}if(!e.ok||a?.ok===!1){let t=String(a?.error||r||`Delete failed (${e.status})`);throw Error(t)}n+=1,t.delete(i.key)}catch{r+=1}je([...t.values()]),L?.key&&!t.has(L.key)&&(Ce(``),ke(null),A(!1),M(!1),N(``),P(``)),Pe(null),n&&r?f(`warn`,`Deleted ${n} document(s); ${r} failed.`):n?f(`ok`,`Deleted ${n} document(s).`):f(`err`,`All ${r} selected document deletions failed.`),await m.invalidateQueries({queryKey:[`knowledgebase`,`collections`]}),await m.invalidateQueries({queryKey:[`knowledgebase`,`documents`]}),await ze.refetch()}catch(e){f(`err`,e instanceof Error?e.message:String(e))}};return H?c(ie,{className:`overflow-hidden`,title:`Knowledgebase`,subtitle:`Provisioned-server docs live in KB collections searched through MCP, not in the file buckets below.`,actions:c(te,{className:`justify-start`,children:[c(`button`,{type:`button`,className:`tcp-icon-btn`,title:`Upload documents`,"aria-label":`Upload documents`,onClick:()=>ae.current?.click(),disabled:Fe,children:c(`i`,{"data-lucide":`upload`})}),c(`button`,{type:`button`,className:`tcp-icon-btn`,title:`Upload folder`,"aria-label":`Upload folder`,onClick:()=>oe.current?.click(),disabled:Fe,children:c(`i`,{"data-lucide":`folder-up`})}),c(`button`,{type:`button`,className:`tcp-icon-btn`,title:`Refresh collections`,"aria-label":`Refresh collections`,onClick:()=>void Ie.refetch(),children:c(`i`,{"data-lucide":`refresh-cw`})}),c(`button`,{type:`button`,className:`tcp-icon-btn`,title:`Reindex knowledgebase`,"aria-label":`Reindex knowledgebase`,onClick:pt,children:c(`i`,{"data-lucide":`sparkles`})}),c(`button`,{type:`button`,className:`tcp-icon-btn`,title:_e?`Expand knowledgebase`:`Collapse knowledgebase`,"aria-label":_e?`Expand knowledgebase`:`Collapse knowledgebase`,onClick:()=>ve(e=>!e),children:c(`i`,{"data-lucide":_e?`chevron-down`:`chevron-up`})})]}),children:c(`div`,{ref:h,className:_e?`hidden`:`grid gap-4 p-4`,children:[c(`div`,{className:`grid gap-2`,children:[c(`label`,{className:`tcp-subtle text-xs uppercase tracking-wide`,htmlFor:`kb-collection-select`,children:`Collection`}),c(`div`,{className:`flex flex-col gap-2 lg:flex-row lg:items-center`,children:[c(`div`,{className:`relative min-w-[min(100%,18rem)] flex-1`,children:[c(`select`,{id:`kb-collection-select`,className:`tcp-select h-10 w-full appearance-none pr-10 font-semibold text-slate-100`,value:Ye,onChange:e=>{let t=e.target.value;if(ge(!0),t===`__custom__`){D(``);return}D(t)},children:[Je.length?Je.map(e=>{let t=String(e.collection_id||``).trim();return c(`option`,{value:t,children:[t,typeof e.document_count==`number`?` (${e.document_count})`:``]},t)}):c(`option`,{value:``,children:`No collections yet`}),c(`option`,{value:`__custom__`,children:`Create new collection...`})]}),c(`i`,{"data-lucide":`chevron-down`,className:`pointer-events-none absolute right-3 top-1/2 -translate-y-1/2 text-slate-400`})]}),Xe?c(`input`,{id:`kb-collection-id`,className:`tcp-input h-10 min-w-[min(100%,18rem)] flex-1`,value:E,onChange:e=>{ge(!0),D(e.target.value)},placeholder:`new-customer-collection`,spellCheck:!1}):c(`button`,{type:`button`,className:`tcp-icon-btn h-10 w-10 shrink-0`,title:`Create a new collection`,"aria-label":`Create a new collection`,onClick:()=>{ge(!0),D(``)},children:c(`i`,{"data-lucide":`plus`})}),c(`div`,{className:`flex shrink-0 gap-2`,children:[c(`input`,{ref:ae,type:`file`,multiple:!0,accept:y,className:`hidden`,onChange:e=>{ft(e.target.files),e.currentTarget.value=``}}),c(`input`,{ref:oe,type:`file`,multiple:!0,accept:y,className:`hidden`,onChange:e=>{ft(e.target.files),e.currentTarget.value=``}}),c(`button`,{type:`button`,className:`tcp-icon-btn h-10 w-10`,title:`Select files`,"aria-label":`Select files`,onClick:()=>ae.current?.click(),disabled:!U||Fe,children:c(`i`,{"data-lucide":`files`})}),c(`button`,{type:`button`,className:`tcp-icon-btn h-10 w-10`,onClick:()=>oe.current?.click(),disabled:!U||Fe,title:`Select a local folder and upload all matching docs inside it`,"aria-label":`Select a local folder`,children:c(`i`,{"data-lucide":`folder-open`})})]})]}),c(`div`,{className:`tcp-subtle text-xs`,children:`Pick an existing KB MCP collection, or type a new collection ID before uploading.`})]}),c(`div`,{className:`rounded-xl border border-white/10 bg-black/20 p-3 text-sm`,children:[c(`div`,{className:`font-medium text-slate-100`,children:`How this works`}),c(`div`,{className:`tcp-subtle mt-1`,children:"The KB MCP reads from collections in the hosted knowledgebase service. It does not browse a raw server folder directly, so uploads here will not appear in the managed `Files` buckets below unless you upload them there separately."})]}),z.length?c(`div`,{className:`grid gap-2`,children:[c(`div`,{className:`flex items-center justify-between gap-3`,children:[c(`div`,{className:`tcp-subtle text-xs uppercase tracking-wide`,children:`Upload history`}),lt.length?c(`button`,{type:`button`,className:`tcp-icon-btn h-7 w-7`,title:`Clear finished uploads`,"aria-label":`Clear finished uploads`,onClick:ut,children:c(`i`,{"data-lucide":`x`})}):null]}),c(`div`,{className:`grid gap-2`,children:z.map(e=>c(`div`,{className:`rounded-xl border border-white/10 bg-black/20 p-3 text-xs`,children:[c(`div`,{className:`flex items-center justify-between gap-3`,children:[c(`div`,{className:`min-w-0`,children:[c(`div`,{className:`truncate font-medium`,children:e.name}),c(`div`,{className:`tcp-subtle mt-1 truncate`,children:[e.result?.collectionId||U||`collection`,` •`,` `,e.status]}),e.result?.docId?c(`div`,{className:`tcp-subtle mt-1 truncate text-[11px]`,children:e.result.docId}):null]}),c(d,{tone:e.status===`done`?`ok`:e.status===`error`?`err`:`info`,children:[Math.round(e.progress),`%`]})]}),c(`div`,{className:`mt-2 h-1.5 overflow-hidden rounded-full bg-white/10`,children:c(`div`,{className:`h-full rounded-full ${e.status===`error`?`bg-rose-400`:e.status===`done`?`bg-emerald-400`:`bg-sky-400`}`,style:{width:`${Math.max(4,Math.min(100,e.progress||0))}%`}})}),e.error?c(`div`,{className:`mt-2 text-rose-200`,children:e.error}):null]},e.id))})]}):null,c(`div`,{className:`grid gap-2`,children:[c(`div`,{className:`flex flex-wrap items-start justify-between gap-3`,children:[c(`div`,{children:[c(`div`,{className:`tcp-subtle text-xs uppercase tracking-wide`,children:`Collection documents`}),c(`div`,{className:`tcp-subtle mt-1 text-xs`,children:`Showing what the selected KB collection currently contains.`})]}),c(`div`,{className:`flex flex-wrap items-center gap-2`,children:[c(d,{tone:`ghost`,children:Ve}),c(d,{tone:$e?`info`:`ghost`,children:[$e,` selected`]}),c(`button`,{type:`button`,className:`tcp-icon-btn h-8 w-8`,title:`Refresh documents`,"aria-label":`Refresh documents`,onClick:()=>void ze.refetch(),disabled:!U,children:c(`i`,{"data-lucide":`refresh-cw`})}),c(`button`,{type:`button`,className:`tcp-icon-btn h-8 w-8`,title:ye?`Expand collection documents`:`Collapse collection documents`,"aria-label":ye?`Expand collection documents`:`Collapse collection documents`,onClick:()=>be(e=>!e),children:c(`i`,{"data-lucide":ye?`chevron-down`:`chevron-up`})})]})]}),ye?c(`div`,{className:`rounded-xl border border-white/10 bg-black/20 p-3 text-sm tcp-subtle`,children:`Collection documents are collapsed.`}):U?ze.isFetching&&!G.length?c(`div`,{className:`rounded-xl border border-white/10 bg-black/20 p-3 text-sm tcp-subtle`,children:[`Loading documents from`,` `,c(`span`,{className:`font-medium text-slate-200`,children:U}),`.`]}):G.length?c(`div`,{className:`grid gap-4`,children:c(`div`,{className:`grid min-h-0 gap-3`,children:[c(`div`,{className:`grid gap-2 rounded-xl border border-white/10 bg-black/20 p-3`,children:[c(`div`,{className:`flex flex-wrap items-center gap-2`,children:[c(`input`,{className:`tcp-input h-9 min-w-[220px] flex-1`,value:xe,onChange:e=>Se(e.target.value),placeholder:`Filter documents`,spellCheck:!1}),c(d,{tone:`ghost`,children:Ge})]}),c(`div`,{className:`flex flex-wrap items-center justify-between gap-2`,children:[c(`div`,{className:`flex flex-wrap items-center gap-2`,children:[c(`button`,{type:`button`,className:`tcp-icon-btn h-8 w-8`,title:`Select all visible documents`,"aria-label":`Select all visible documents`,onClick:gt,disabled:!G.length,children:c(`i`,{"data-lucide":`square-check-big`})}),c(`button`,{type:`button`,className:`tcp-icon-btn h-8 w-8`,title:`Clear selected documents`,"aria-label":`Clear selected documents`,onClick:_t,disabled:!$e,children:c(`i`,{"data-lucide":`x`})}),c(`button`,{type:`button`,className:`tcp-icon-btn h-8 w-8 border-rose-500/30 text-rose-100 hover:bg-rose-950/20 disabled:opacity-50`,title:`Delete selected documents`,"aria-label":`Delete selected documents`,onClick:bt,disabled:!$e,children:c(`i`,{"data-lucide":`trash-2`})})]}),c(`div`,{className:`flex flex-wrap items-center gap-2`,children:[c(`label`,{className:`flex items-center gap-2 text-[11px] uppercase tracking-wide text-slate-500`,children:[c(`span`,{children:`Per page`}),c(`select`,{className:`tcp-select h-8 min-w-[5.5rem] px-3 text-center text-sm font-semibold tabular-nums text-slate-100 [text-align-last:center]`,value:I,onChange:e=>{Oe(Number(e.target.value)||ce),De(1)},children:b.map(e=>c(`option`,{value:e,children:e},e))})]}),c(`button`,{type:`button`,className:`tcp-icon-btn h-8 w-8`,title:`Previous page`,"aria-label":`Previous page`,onClick:()=>De(e=>w(e-1,He)),disabled:J<=1,children:c(`i`,{"data-lucide":`chevron-left`})}),c(`button`,{type:`button`,className:`tcp-icon-btn h-8 w-8`,title:`Next page`,"aria-label":`Next page`,onClick:()=>De(e=>w(e+1,He)),disabled:J>=He,children:c(`i`,{"data-lucide":`chevron-right`})})]})]})]}),We.length?c(`div`,{className:`grid gap-2`,children:We.map((e,t)=>{let n=String(e.doc_id||e.id||``).trim(),r=String(e.title||e.filename||e.file_name||n||`Document ${Ue+t+1}`).trim(),i=String(e.collection_id||U).trim(),a=Number(e.updated_at||e.created_at||0),o=de(e),s=!!o,te=s&&Ze.has(o),u=o===k;return c(ee.div,{layout:!0,children:c(`div`,{className:`flex items-start gap-3`,children:[c(`label`,{className:`mt-3 flex h-6 w-6 items-center justify-center rounded border ${s?`border-white/15 bg-black/20 text-slate-200 cursor-pointer hover:border-sky-500/40`:`border-white/10 bg-black/10 text-slate-500`}`,children:c(`input`,{type:`checkbox`,className:`h-4 w-4 accent-sky-400`,checked:te,disabled:!s,onChange:()=>ht(e),"aria-label":`Select ${r}`})}),c(`div`,{className:`min-w-0 flex-1`,children:[c(`button`,{type:`button`,className:`w-full rounded-xl border p-3 text-left text-sm transition ${u?`border-sky-500/50 bg-sky-950/20`:te?`border-emerald-500/40 bg-emerald-950/20 hover:border-emerald-400/50 hover:bg-emerald-950/30`:`border-white/10 bg-black/20 hover:border-white/20 hover:bg-black/30`}`.trim(),onClick:()=>{let t=mt(e);if(u){Ce(``),ke(null),A(!1),M(!1),P(``);return}Ce(o),t&&ke(t),A(!0),M(!1),P(``)},"aria-expanded":u,children:[c(`div`,{className:`flex items-start justify-between gap-3`,children:[c(`div`,{className:`min-w-0`,children:[c(`div`,{className:`truncate font-medium text-slate-100`,children:r}),c(`div`,{className:`tcp-subtle mt-1 truncate text-xs`,children:n||`${i}/${r}`})]}),c(d,{tone:u?`ok`:te?`info`:`ghost`,children:i})]}),c(`div`,{className:`mt-2 flex flex-wrap gap-2 text-xs tcp-subtle`,children:[c(`span`,{children:[`Updated: `,fe(a)]}),e.content_type?c(`span`,{children:e.content_type}):null]})]}),c(l,{initial:!1,children:u?c(ee.div,{initial:{opacity:0,height:0,y:-8},animate:{opacity:1,height:`auto`,y:0},exit:{opacity:0,height:0,y:-8},transition:{duration:.22,ease:`easeOut`},className:`overflow-hidden`,children:c(`div`,{className:`mt-2`,children:ct})},`${k}-expanded`):null})]})]})},n||`${i}-${r}-${t}`)})}):c(u,{title:W?`No documents match your filter`:`No documents found`,text:W?`Try another search term or clear the filter to show the full collection.`:`This collection does not contain any documents yet.`,action:W?c(`button`,{type:`button`,className:`tcp-btn h-8 px-3 text-xs`,onClick:()=>Se(``),children:`Clear filter`}):null})]})}):c(`div`,{className:`rounded-xl border border-white/10 bg-black/20 p-3 text-sm tcp-subtle`,children:[`No visible documents returned for`,` `,c(`span`,{className:`font-medium text-slate-200`,children:U}),`. If you just uploaded a file, refresh docs or reindex and confirm the KB admin service exposes document listing for that collection.`]}):c(`div`,{className:`rounded-xl border border-white/10 bg-black/20 p-3 text-sm tcp-subtle`,children:`Pick or type a collection ID to inspect its documents.`})]}),c(se,{open:!!Me,title:`Delete document`,message:c(`span`,{children:[`This will permanently remove`,` `,c(`strong`,{children:Me?.title||`this document`}),` from`,` `,c(`strong`,{children:Me?.collection||U||`the selected collection`}),`.`]}),confirmLabel:`Delete document`,confirmIcon:`trash-2`,confirmTone:`danger`,onCancel:()=>Ne(null),onConfirm:()=>void xt()}),c(se,{open:!!R,title:`Delete selected documents`,message:c(`span`,{children:[`This will permanently remove`,` `,c(`strong`,{children:[R?.documents.length||0,` selected document(s)`]}),` from`,` `,c(`strong`,{children:U||`the selected collection`}),`.`]}),confirmLabel:`Delete selected`,confirmIcon:`trash-2`,confirmTone:`danger`,widthClassName:`w-[min(42rem,96vw)]`,onCancel:()=>Pe(null),onConfirm:()=>void St(),children:R?.documents.length?c(`div`,{className:`mt-3 grid gap-2 rounded-xl border border-white/10 bg-black/20 p-3 text-left text-xs`,children:[c(`div`,{className:`tcp-subtle uppercase tracking-wide`,children:`Selected documents`}),c(`div`,{className:`max-h-40 overflow-auto`,children:[R.documents.slice(0,12).map(e=>c(`div`,{className:`truncate py-1`,children:[c(`span`,{className:`font-medium text-slate-100`,children:e.title||e.slug}),c(`span`,{className:`tcp-subtle`,children:[` `,`· `,e.collection,`/`,e.slug]})]},`${e.collection}|${e.slug}`)),R.documents.length>12?c(`div`,{className:`pt-1 text-slate-400`,children:[`+`,R.documents.length-12,` more`]}):null]})]}):null})]})}):null}var E=`__global__`;function D(e){return e===`collection`?`Collection override`:e===`global`?`Global override`:`Default`}function O(e){return e===`collection`?`ok`:e===`global`?`info`:`warn`}function ge({api:r,toast:ee}){let l=a(),[u,f]=i(!0),[p,m]=i(E),[re,h]=i({}),[ae,oe]=i({}),[g,_]=i({}),[v,y]=i(null),b=o({queryKey:[`knowledgebase`,`config`],queryFn:async()=>r(`/api/knowledgebase/config`).catch(()=>({configured:!1})),staleTime:6e4}).data?.configured===!0,ce=o({queryKey:[`knowledgebase`,`collections`],enabled:b,queryFn:async()=>r(`/api/knowledgebase/collections`).catch(()=>({collections:[]})),staleTime:3e4}),le=Array.isArray(ce.data?.collections)?ce.data.collections:[],ue=p===E?``:p,x=o({queryKey:[`knowledgebase`,`prompts`,ue||`__global__`],enabled:b&&!u,queryFn:async()=>await r(`/api/knowledgebase/prompts${ue?`?collection_id=${encodeURIComponent(ue)}`:``}`)}),S=x.data?.prompts||[];e(()=>{let e=x.data?.prompts||[];e.length&&h(t=>{let n={...t};for(let t of e)t.key in n||(n[t.key]=p===E?t.global_override??t.default:t.collection_override??t.global_override??t.default);return n})},[x.dataUpdatedAt,p]),e(()=>{h({})},[p]);let de=s({mutationFn:async({key:e,value:t,collection_id:n})=>{let i={value:t};return n&&(i.collection_id=n),r(`/api/knowledgebase/prompts/${encodeURIComponent(e)}`,{method:`PUT`,body:JSON.stringify(i)})},onSuccess:async(e,t)=>{ee(`ok`,`Saved prompt "${t.key}".`),await l.invalidateQueries({queryKey:[`knowledgebase`,`prompts`]}),h(e=>{let n={...e};return delete n[t.key],n})},onError:e=>{ee(`err`,`Save failed: ${e?.message||`Save failed.`}`)}}),fe=s({mutationFn:async({key:e,collection_id:t})=>{let n=t?`?collection_id=${encodeURIComponent(t)}`:``;return r(`/api/knowledgebase/prompts/${encodeURIComponent(e)}${n}`,{method:`DELETE`})},onSuccess:async(e,t)=>{ee(`ok`,t.collection_id?`Reverted "${t.key}" for collection "${t.collection_id}".`:`Reverted global "${t.key}" to default.`),await l.invalidateQueries({queryKey:[`knowledgebase`,`prompts`]}),h(e=>{let n={...e};return delete n[t.key],n})},onError:e=>{ee(`err`,`Reset failed: ${e?.message||`Reset failed.`}`)}}),pe=n(()=>le.map(e=>String(e.collection_id||``).trim()).filter(Boolean).sort(),[le]);return b?c(ie,{title:`Agent prompts`,subtitle:`Edit how the AI agent answers questions from this knowledgebase. Defaults are shipped in code; overrides take effect on the next agent session or answer_question call.`,actions:c(te,{className:`justify-end`,children:c(`button`,{type:`button`,className:`tcp-btn h-8 w-8 justify-center px-0`,title:u?`Expand prompts`:`Collapse prompts`,"aria-label":u?`Expand prompts`:`Collapse prompts`,onClick:()=>f(e=>!e),ref:e=>{e&&ne(e)},children:c(`i`,{"data-lucide":u?`chevron-down`:`chevron-up`,"aria-hidden":`true`})})}),children:[u?null:c(`div`,{className:`flex flex-col gap-4`,children:[c(`div`,{className:`flex flex-wrap items-center gap-3 rounded-lg border border-white/10 bg-black/20 p-3 text-sm`,children:[c(`label`,{className:`flex items-center gap-2`,children:[c(`span`,{className:`tcp-subtle`,children:`Scope:`}),c(`select`,{className:`tcp-input h-8 px-2`,value:p,onChange:e=>m(e.target.value),children:[c(`option`,{value:E,children:`Global (all collections)`}),pe.map(e=>c(`option`,{value:e,children:[`Collection: `,e]},e))]})]}),c(`span`,{className:`tcp-subtle text-xs`,children:p===E?`Global overrides apply to every collection unless a collection-specific override exists.`:`Editing overrides for collection "${p}". Collection overrides take precedence over global ones.`})]}),x.isLoading?c(`div`,{className:`tcp-subtle p-4 text-sm`,children:`Loading prompts…`}):x.isError?c(`div`,{className:`rounded-lg border border-rose-500/30 bg-rose-950/20 p-3 text-sm text-rose-200`,children:[`Failed to load prompts: `,x.error?.message||`Unknown error.`]}):S.length===0?c(`div`,{className:`tcp-subtle p-4 text-sm`,children:`No prompts available.`}):c(`div`,{className:`flex flex-col gap-3`,children:S.map(e=>{let t=!!ae[e.key],n=re[e.key]??e.current,r=p!==E&&!e.supports_collection_override,i=p===E?e.global_override!==null:e.collection_override!==null,a=!!g[e.key],o=n!==(p===E?e.global_override??e.default:e.collection_override??e.global_override??e.default);return c(`div`,{className:`rounded-lg border border-white/10 bg-black/20 p-3`,children:[c(`div`,{className:`flex flex-wrap items-start justify-between gap-2`,children:[c(`div`,{className:`flex flex-col`,children:[c(`div`,{className:`flex flex-wrap items-center gap-2`,children:[c(`span`,{className:`font-mono text-sm`,children:e.key}),c(d,{tone:O(e.scope),children:D(e.scope)}),e.supports_collection_override?null:c(d,{tone:`warn`,children:`Global only`}),e.collection_overrides.length>0?c(`span`,{className:`tcp-subtle text-xs`,children:[e.collection_overrides.length,` collection override`,e.collection_overrides.length===1?``:`s`]}):null]}),c(`div`,{className:`tcp-subtle mt-1 text-xs`,children:e.description})]}),c(te,{className:`justify-end`,children:c(`button`,{type:`button`,className:`tcp-btn h-7 px-2 text-xs`,onClick:()=>oe(t=>({...t,[e.key]:!t[e.key]})),children:t?`Collapse`:`Edit`})})]}),t?c(`div`,{className:`mt-3 flex flex-col gap-2`,children:[r?c(`div`,{className:`rounded border border-amber-500/30 bg-amber-950/20 p-2 text-xs text-amber-200`,children:`This prompt is global only — it is sent before any collection is selected, so per-collection overrides are not supported. Switch scope back to Global to edit it.`}):null,c(`div`,{className:`flex items-center gap-2`,children:[c(`button`,{type:`button`,className:`tcp-btn h-7 px-2 text-xs`,onClick:()=>_(t=>({...t,[e.key]:!t[e.key]})),children:a?`Hide default`:`Show default`}),e.global_override!==null&&p!==E?c(`span`,{className:`tcp-subtle text-xs`,children:`Inherits a global override when no collection override is set.`}):null]}),a?c(`div`,{className:`rounded border border-white/10 bg-black/30 p-2`,children:[c(`div`,{className:`tcp-subtle text-[10px] uppercase tracking-wide`,children:`Built-in default`}),c(`pre`,{className:`whitespace-pre-wrap break-words font-mono text-xs leading-5`,children:e.default})]}):null,c(`textarea`,{className:`tcp-input min-h-[200px] resize-y font-mono text-xs leading-6`,value:n,disabled:r,onChange:t=>h(n=>({...n,[e.key]:t.target.value}))}),c(`div`,{className:`flex flex-wrap items-center gap-2`,children:[c(`button`,{type:`button`,className:`tcp-btn h-8 px-3 text-xs`,disabled:r||!o||!n.trim()||de.isPending,onClick:()=>de.mutate({key:e.key,value:n,collection_id:p===E?void 0:p}),children:[`Save `,p===E?`global`:`collection`,` override`]}),c(`button`,{type:`button`,className:`tcp-btn h-8 px-3 text-xs`,disabled:r||!i||fe.isPending,onClick:()=>y({key:e.key,collectionId:p===E?null:p}),children:[`Reset `,p===E?`global`:`collection`,` to default`]}),o?c(`button`,{type:`button`,className:`tcp-btn h-8 px-3 text-xs`,onClick:()=>h(t=>{let n={...t};return delete n[e.key],n}),children:`Discard changes`}):null]}),e.collection_overrides.length>0?c(`div`,{className:`mt-1 rounded border border-white/10 bg-black/30 p-2 text-xs`,children:[c(`div`,{className:`tcp-subtle uppercase tracking-wide`,children:`Collections with overrides`}),c(`ul`,{className:`mt-1 flex flex-wrap gap-2`,children:e.collection_overrides.map(e=>c(`li`,{children:c(`button`,{type:`button`,className:`tcp-btn h-6 px-2 text-[11px]`,onClick:()=>m(e.collection_id),children:e.collection_id})},e.collection_id))})]}):null]}):null]},e.key)})})]}),c(se,{open:v!==null,title:`Reset prompt to default?`,message:v?c(`span`,{children:v.collectionId?c(t,{children:[`This removes the override for `,c(`code`,{children:v.key}),` on collection`,` `,c(`code`,{children:v.collectionId}),`. The agent will fall back to the global override (if any) or the built-in default for this collection. Other collections are unaffected.`]}):c(t,{children:[`This removes the global override for `,c(`code`,{children:v.key}),`. The agent will fall back to the built-in default. Per-collection overrides for this prompt remain in place.`]})}):``,confirmLabel:`Reset`,confirmIcon:`rotate-ccw`,confirmTone:`danger`,confirmDisabled:fe.isPending,onCancel:()=>y(null),onConfirm:()=>{v&&(fe.mutate({key:v.key,collection_id:v.collectionId??void 0}),y(null))}})]}):null}var _e=[`uploads`,`artifacts`,`exports`],ve=new Set([`text`,`markdown`,`json`,`yaml`]),ye=[10,25,50,100],be=25;function xe(e){let t=Number(e||0);return t<1024?`${t} B`:t<1024*1024?`${(t/1024).toFixed(1)} KB`:`${(t/1024/1024).toFixed(1)} MB`}function Se(e){let t=Number(e||0);return t?new Date(t).toLocaleString():`n/a`}function k(e,t){return Array.isArray(e)?e:Array.isArray(e?.[t])?e[t]:[]}function Ce(e){let t=String(e||``).trim();return t?t.split(`/`).filter(Boolean).length:0}function we(e,t=!0){let n=String(e||``).trim().replace(/\\/g,`/`).replace(/^\/+/,``).replace(/\/+$/,``);if(!n)return t?``:null;if(n.includes(`\0`))return null;let r=n.split(`/`).filter(Boolean);return r.length?r.some(e=>e===`.`||e===`..`)?null:r.join(`/`):t?``:null}function A(e){let t=String(e||``).trim().replace(/\\/g,`/`).replace(/\/+$/g,``);return!t||!t.includes(`/`)?``:t.split(`/`).slice(0,-1).join(`/`)}function j(e,t){return!Number.isFinite(e)||e<1||!Number.isFinite(t)||t<1?1:Math.min(e,t)}function M(e,t,n){if(!n)return`0 of 0`;let r=j(e,Math.max(1,Math.ceil(n/Math.max(1,t)))),i=Math.max(1,t);return`${(r-1)*i+1}-${Math.min(n,r*i)} of ${n}`}function Te({api:l,client:u,toast:v}){let y=a(),b=m(),ce=r(null),le=r(null),ue=r(null),[x,S]=i(`managed`),[de,fe]=i(!1),[pe,me]=i(!1),[C,w]=i(``),[T,E]=i(``),[D,O]=i(null),[Te,N]=i([]),[Ee,P]=i(1),[F,De]=i(be),[I,Oe]=i([]),[L,ke]=i(null),[Ae,je]=i(null);e(()=>{let e=oe();e&&(S(`managed`),e.dir?w(e.dir):e.path&&w(h(e.path)),E(e.path||e.dir||``))},[]);let Me=b.data?.workspace_files_api_available===!0,Ne=Me&&b.data?.workspace_files_available===!0&&!de;e(()=>{Ne&&(x!==`managed`||C||T||S(`workspace`))},[Ne,x,C,T]);let R=x===`workspace`,Pe=R?`/api/workspace/files`:`/api/files`,z=o({queryKey:[`files`,x,C],queryFn:async()=>l(`${Pe}/list?dir=${encodeURIComponent(C)}`).catch(e=>(R&&Number(e?.status||0)===404&&(fe(!0),S(`managed`),w(``)),{dir:C,parent:null,directories:[],files:[]})),refetchInterval:15e3}),B=String(z.data?.dir||``).trim(),Fe=String(z.data?.parent||``).trim(),V=k(z.data,`directories`),H=k(z.data,`files`);e(()=>{let e=new Set(H.map(e=>String(e.path||``).trim()).filter(Boolean));Oe(t=>t.filter(t=>e.has(t)))},[H]),e(()=>{P(1)},[C]);let Ie=n(()=>new Set(I),[I]),Le=n(()=>H.filter(e=>Ie.has(String(e.path||``).trim())),[H,Ie]),U=Le.length,Re=Math.max(1,Math.ceil(H.length/Math.max(1,F))),W=j(Ee,Re),ze=(W-1)*Math.max(1,F),Be=H.slice(ze,ze+Math.max(1,F)),G=M(W,F,H.length);e(()=>{Ee!==W&&P(W)},[Ee,W]);let Ve=n(()=>H.find(e=>String(e?.path||``)===T)||V.find(e=>String(e?.path||``)===T)||null,[z.data,T]),K=!!Ve&&String(Ve?.previewKind||``)===`directory`||!!B&&T===B,q=Ve&&!K?Ve:null,He=String(q?.mime||``).trim(),J=String(q?.previewKind||``).trim(),Ue=q?.downloadUrl||`${Pe}/download?path=${encodeURIComponent(T)}`,We=o({queryKey:[`files`,x,`read`,T],enabled:!!q&&ve.has(J),queryFn:async()=>l(`${Pe}/read?path=${encodeURIComponent(T)}`).catch(e=>({ok:!1,previewable:!1,reason:`unavailable`,error:e instanceof Error?e.message:String(e)}))}),Ge=V.length+H.length,Ke=Ce(B),qe=!!q&&ve.has(J)&&We.data?.previewable!==!1,Je=We.isFetching&&qe;e(()=>{ce.current&&ne(ce.current)},[Ge,V.length,H.length,Ee,F,Be.length,U,T,J,K,Te.length,B,x,pe,We.data?.previewable]);let Ye=s({mutationFn:({file:e,targetDir:t,surface:n,relativePath:r})=>new Promise((i,a)=>{let o=`${Date.now()}-${Math.random().toString(16).slice(2)}`;N(t=>[...t,{id:o,name:e.name,progress:0,error:``}]);let s=new XMLHttpRequest,c=n===`workspace`?`/api/workspace/files/upload`:`/api/files/upload`;s.open(`POST`,`${c}?dir=${encodeURIComponent(t)}`),s.withCredentials=!0,s.responseType=`json`,s.setRequestHeader(`x-file-name`,encodeURIComponent(e.name)),n===`workspace`&&r&&s.setRequestHeader(`x-relative-path`,encodeURIComponent(r)),s.upload.onprogress=e=>{if(!e.lengthComputable)return;let t=e.loaded/e.total*100;N(e=>e.map(e=>e.id===o?{...e,progress:t}:e))},s.onerror=()=>{N(e=>e.map(e=>e.id===o?{...e,error:`Network error`}:e)),window.setTimeout(()=>{N(e=>e.filter(e=>e.id!==o))},1200),a(Error(`Upload failed: ${e.name}`))},s.onload=()=>{let e=s.response||{};if(s.status<200||s.status>=300||e?.ok===!1){let t=String(e?.error||`Upload failed (${s.status})`);N(e=>e.map(e=>e.id===o?{...e,error:t}:e)),window.setTimeout(()=>{N(e=>e.filter(e=>e.id!==o))},1600),a(Error(t));return}N(e=>e.filter(e=>e.id!==o)),i(e)},s.send(e)}),onSuccess:async(e,t)=>{let n=String(e?.path||``).trim();if(n){let e=String(t.targetDir||``).trim()||h(n);t.surface===`managed`&&!C&&e===`uploads`&&w(`uploads`),E(n)}await y.invalidateQueries({queryKey:[`files`]}),v(`ok`,`Uploaded ${String(t.file?.name||`file`)} into ${t.targetDir||(t.surface===`workspace`?`Workspace`:`uploads`)}.`)},onError:e=>v(`err`,e instanceof Error?e.message:String(e))}),Xe=s({mutationFn:async e=>l(`${Pe}/mkdir`,{method:`POST`,body:JSON.stringify({path:e})}),onSuccess:async e=>{let t=String(e?.path||``).trim();t&&(w(t),E(t)),await y.invalidateQueries({queryKey:[`files`]}),v(`ok`,`Created folder ${t||`folder`}.`)},onError:e=>v(`err`,e instanceof Error?e.message:String(e))}),Ze=async e=>{let t=[...e||[]];if(!t.length)return;let n=R?C:C||`uploads`;for(let e of t){let t=R?String(e.webkitRelativePath||e.name):void 0;await Ye.mutateAsync({file:e,targetDir:n,surface:x,relativePath:t}).catch(()=>void 0)}!R&&!C&&w(`uploads`)},Qe=()=>{let e=String(C||``).trim();if(!R&&!e){v(`warn`,`Choose a bucket before creating folders.`);return}O({baseDir:e,value:R?`new-folder`:`knowledgebooks/new-collection`})},$e=async()=>{let e=D;if(!e)return;let t=String(e.value||``).trim().replace(/^\/+|\/+$/g,``).replace(/\/{2,}/g,`/`);if(!t){v(`warn`,`Enter a folder name.`);return}O(null),await Xe.mutateAsync(e.baseDir?`${e.baseDir}/${t}`:t)},Y=e=>{let t=R?we(e,!0):ae(e);t&&(w(t),E(t))},et=()=>{if(!Fe){w(``),E(``);return}w(Fe),E(Fe)},X=()=>{w(``),E(``)},Z=e=>{let t=String(e||``).trim();t&&Oe(e=>e.includes(t)?e.filter(e=>e!==t):[...e,t])},Q=()=>{let e=H.map(e=>String(e.path||``).trim()).filter(Boolean);Oe(Array.from(new Set(e)))},tt=()=>{Oe([])},nt=()=>{if(!Le.length){v(`warn`,`Select one or more files first.`);return}ke({files:Le.map(e=>({path:String(e.path||``).trim(),name:String(e.name||e.path||``).trim()}))})},rt=()=>{let e=``,t=``;K&&T?e=T:U?(e=A(Le[0]?.path||``),t=`Import the containing folder for now.`):q?(e=A(q.path||T),t=`Import the containing folder for now.`):B?e=B:R&&(e=`.`),je({path:e,note:t})},$=async()=>{let e=L?.files||[];if(!e.length){v(`warn`,`Select one or more files first.`);return}let t=new Set(I),n=0,r=0;for(let i of e)try{await l(`${Pe}/delete`,{method:`POST`,body:JSON.stringify({path:i.path})}),n+=1,t.delete(i.path)}catch{r+=1}Oe(Array.from(t)),E(t=>e.some(e=>e.path===t)?``:t),ke(null),await y.invalidateQueries({queryKey:[`files`]}),n&&r?v(`warn`,`Deleted ${n} file(s); ${r} failed.`):n?v(`ok`,`Deleted ${n} file(s).`):v(`err`,`All ${r} selected file deletions failed.`)},it=e=>{e!==x&&(S(e),w(``),E(``),Oe([]),P(1))},at=R?B||`Workspace`:B||`Root`,ot=String(We.data?.reason||``).trim(),st=String(We.data?.text||``).trim(),ct=_e.length,lt=String(b.data?.hosted_deployment_slug||b.data?.hosted_hostname||``).trim(),ut=lt,dt=ut?`project`:`global`;return c(f,{className:`grid h-full min-h-0 gap-4`,children:[c(he,{api:l,toast:v,defaultCollectionId:lt}),c(ge,{api:l,toast:v}),c(ie,{fullHeight:!0,title:`Files`,subtitle:R?`Browse and edit the hosted workspace.`:`Browse managed uploads, published artifacts, and exports.`,actions:c(te,{className:`justify-start`,children:[c(`button`,{type:`button`,className:`tcp-icon-btn`,title:`Upload files`,"aria-label":`Upload files`,onClick:()=>le.current?.click(),disabled:Ye.isPending,children:c(`i`,{"data-lucide":`upload`})}),R?c(`button`,{type:`button`,className:`tcp-icon-btn`,title:`Upload folder`,"aria-label":`Upload folder`,onClick:()=>ue.current?.click(),disabled:Ye.isPending,children:c(`i`,{"data-lucide":`folder-up`})}):null,c(`button`,{type:`button`,className:`tcp-icon-btn`,onClick:Qe,disabled:Xe.isPending||!R&&!C,title:!R&&!C?`Choose a bucket first`:`Create a folder inside the current path`,"aria-label":`Create folder`,children:c(`i`,{"data-lucide":`folder-plus`})}),c(`button`,{type:`button`,className:`tcp-icon-btn`,title:`Import to Memory`,"aria-label":`Import to Memory`,onClick:rt,children:c(`i`,{"data-lucide":`database-zap`})}),c(`button`,{type:`button`,className:`tcp-icon-btn`,title:`Refresh files`,"aria-label":`Refresh files`,onClick:()=>void z.refetch(),children:c(`i`,{"data-lucide":`refresh-cw`})}),c(`button`,{type:`button`,className:`tcp-icon-btn`,title:`Go up one folder`,"aria-label":`Go up one folder`,onClick:et,disabled:!B,children:c(`i`,{"data-lucide":`corner-up-left`})}),c(`button`,{type:`button`,className:`tcp-icon-btn`,title:pe?`Expand files`:`Collapse files`,"aria-label":pe?`Expand files`:`Collapse files`,onClick:()=>me(e=>!e),children:c(`i`,{"data-lucide":pe?`chevron-down`:`chevron-up`})})]}),children:c(`div`,{ref:ce,className:pe?`hidden`:`grid min-h-0 gap-4 xl:grid-cols-[280px_minmax(0,1fr)_360px]`,children:[c(ie,{fullHeight:!0,className:`overflow-hidden`,title:`Locations`,subtitle:R?`Hosted workspace root.`:`Managed file buckets.`,actions:c(d,{tone:`ghost`,children:R?`workspace`:ct}),children:c(`div`,{className:`grid min-h-0 gap-3 p-4`,children:[c(`div`,{className:`grid grid-cols-2 gap-2`,children:[c(`button`,{type:`button`,className:`tcp-btn h-9 justify-center px-2 text-xs ${R?`border-sky-500/40 bg-sky-950/20`:``}`.trim(),onClick:()=>it(`workspace`),disabled:!Ne,title:Ne?`Browse the workspace`:Me?`Workspace root is not configured`:`Workspace file browsing is not available on this deployment`,children:[c(`i`,{"data-lucide":`folder-code`}),`Workspace`]}),c(`button`,{type:`button`,className:`tcp-btn h-9 justify-center px-2 text-xs ${R?``:`border-sky-500/40 bg-sky-950/20`}`.trim(),onClick:()=>it(`managed`),children:[c(`i`,{"data-lucide":`archive`}),`Managed`]})]}),c(`div`,{className:`grid gap-1`,children:[c(`button`,{type:`button`,className:`tcp-list-item w-full text-left ${B?``:`border-sky-500/40 bg-sky-950/20`}`,onClick:X,children:[c(`i`,{"data-lucide":`hard-drive`}),R?`Workspace root`:`Root`]}),R?null:_e.map(e=>c(`button`,{type:`button`,className:`tcp-list-item w-full text-left ${B===e?`border-sky-500/40 bg-sky-950/20`:``}`,onClick:()=>Y(e),children:[c(`i`,{"data-lucide":`folder-open`}),c(`span`,{className:`flex min-w-0 flex-1 items-center justify-between gap-2`,children:[c(`span`,{className:`truncate`,children:e}),c(`span`,{className:`tcp-subtle text-[11px]`,children:e===`uploads`?`managed`:e})]})]},e))]}),c(`div`,{className:`rounded-xl border border-white/10 bg-black/20 p-3`,children:[c(`div`,{className:`tcp-subtle text-xs uppercase tracking-wide`,children:`Path`}),c(`div`,{className:`mt-2 flex flex-wrap gap-2`,children:[c(`button`,{type:`button`,className:`tcp-btn h-7 px-2 text-xs`,onClick:X,children:R?`Workspace`:`Root`}),B.split(`/`).filter(Boolean).reduce((e,t)=>{let n=e.length?`${e[e.length-1]}/${t}`:t;return e.push(n),e},[]).map(e=>c(`button`,{type:`button`,className:`tcp-btn h-7 px-2 text-xs ${e===B?`border-sky-500/40 bg-sky-950/20`:``}`.trim(),onClick:()=>Y(e),children:e.split(`/`).pop()||e},e))]})]}),Te.length?c(`div`,{className:`grid gap-2`,children:[c(`div`,{className:`tcp-subtle text-xs uppercase tracking-wide`,children:`Uploads`}),c(`div`,{className:`grid gap-2`,children:Te.map(e=>c(`div`,{className:`rounded-xl border border-white/10 bg-black/20 p-2 text-xs`,children:[c(`div`,{className:`flex items-center justify-between gap-2`,children:[c(`span`,{className:`truncate`,children:e.name}),c(`span`,{className:`tcp-subtle`,children:[Math.round(e.progress),`%`]})]}),c(`div`,{className:`mt-2 h-1.5 overflow-hidden rounded-full bg-white/10`,children:c(`div`,{className:`h-full rounded-full ${e.error?`bg-rose-400`:`bg-sky-400`}`,style:{width:`${Math.max(4,Math.min(100,e.progress||0))}%`}})}),e.error?c(`div`,{className:`mt-1 text-rose-200`,children:e.error}):null]},e.id))})]}):null]})}),c(ie,{fullHeight:!0,className:`overflow-hidden`,title:at,subtitle:!R&&Ke===0?`Select a bucket to browse its files.`:`${V.length} folder${V.length===1?``:`s`} and ${H.length} file${H.length===1?``:`s`}`,actions:c(`div`,{className:`flex flex-wrap items-center justify-end gap-2`,children:[c(`span`,{className:`tcp-badge tcp-badge-ghost`,children:at}),J?c(d,{tone:`info`,children:J}):null,K?c(d,{tone:`ghost`,children:`folder`}):null]}),children:c(`div`,{className:`flex min-h-0 flex-1 flex-col gap-3 p-4`,children:[c(`div`,{className:`tcp-toolbar`,children:[c(`span`,{className:`tcp-badge-info`,children:[V.length,` folder`,V.length===1?``:`s`]}),c(`span`,{className:`tcp-badge-info`,children:[H.length,` file`,H.length===1?``:`s`]}),c(`span`,{className:C?`tcp-badge-ok`:`tcp-badge tcp-badge-ghost`,children:C?`browsing`:`root`})]}),c(`div`,{className:`grid min-h-0 gap-2 overflow-auto pr-1`,children:!R&&Ke===0?c(p,{text:`Pick a bucket on the left, or upload a file to start browsing.`,title:`No folder selected`}):V.length||H.length?c(t,{children:[V.map(e=>{let t=String(e?.path||``);return c(`button`,{type:`button`,className:`tcp-list-item w-full text-left ${t===T?`border-sky-500/40 bg-sky-950/20`:``}`,onClick:()=>Y(t),children:[c(`i`,{"data-lucide":`folder-open`}),c(`div`,{className:`min-w-0 flex-1`,children:[c(`div`,{className:`flex items-center justify-between gap-2`,children:[c(`strong`,{className:`truncate`,children:String(e?.name||t)}),c(`span`,{className:`tcp-subtle text-xs`,children:`folder`})]}),c(`div`,{className:`mt-1 flex items-center justify-between gap-2 text-xs tcp-subtle`,children:[c(`span`,{className:`truncate`,children:t}),c(`span`,{children:Se(Number(e?.updatedAt||0))})]})]})]},`dir-${t}`)}),c(`div`,{className:`grid gap-2 rounded-xl border border-white/10 bg-black/20 p-3`,children:[c(`div`,{className:`flex flex-wrap items-center justify-between gap-2`,children:[c(`div`,{className:`flex flex-wrap items-center gap-2`,children:[c(d,{tone:`ghost`,children:G}),c(d,{tone:U?`info`:`ghost`,children:[U,` selected`]})]}),c(`div`,{className:`flex flex-wrap items-center gap-2`,children:[c(`button`,{type:`button`,className:`tcp-icon-btn h-8 w-8`,title:`Import selected file folder to memory`,"aria-label":`Import selected file folder to memory`,onClick:rt,disabled:!U,children:c(`i`,{"data-lucide":`database-zap`})}),c(`button`,{type:`button`,className:`tcp-icon-btn h-8 w-8`,title:`Select all visible files`,"aria-label":`Select all visible files`,onClick:Q,disabled:!H.length,children:c(`i`,{"data-lucide":`square-check-big`})}),c(`button`,{type:`button`,className:`tcp-icon-btn h-8 w-8`,title:`Clear selected files`,"aria-label":`Clear selected files`,onClick:tt,disabled:!U,children:c(`i`,{"data-lucide":`x`})}),c(`button`,{type:`button`,className:`tcp-icon-btn h-8 w-8 border-rose-500/30 text-rose-100 hover:bg-rose-950/20 disabled:opacity-50`,title:`Delete selected files`,"aria-label":`Delete selected files`,onClick:nt,disabled:!U,children:c(`i`,{"data-lucide":`trash-2`})}),c(`label`,{className:`flex items-center gap-2 text-[11px] uppercase tracking-wide text-slate-500`,children:[c(`span`,{children:`Per page`}),c(`select`,{className:`tcp-select h-8 min-w-[5.5rem] px-3 text-center text-sm font-semibold tabular-nums text-slate-100 [text-align-last:center]`,value:F,onChange:e=>{De(Number(e.target.value)||be),P(1)},children:ye.map(e=>c(`option`,{value:e,children:e},e))})]}),c(`button`,{type:`button`,className:`tcp-icon-btn h-8 w-8`,title:`Previous page`,"aria-label":`Previous page`,onClick:()=>P(e=>j(e-1,Re)),disabled:W<=1,children:c(`i`,{"data-lucide":`chevron-left`})}),c(`button`,{type:`button`,className:`tcp-icon-btn h-8 w-8`,title:`Next page`,"aria-label":`Next page`,onClick:()=>P(e=>j(e+1,Re)),disabled:W>=Re,children:c(`i`,{"data-lucide":`chevron-right`})})]})]}),c(`div`,{className:`grid gap-2`,children:Be.map(e=>{let t=String(e?.path||``),n=t===T,r=Ie.has(t),i=String(e?.previewKind||`file`);return c(ee.div,{layout:!0,children:c(`div`,{className:`flex items-start gap-3`,children:[c(`label`,{className:`mt-3 flex h-6 w-6 items-center justify-center rounded border ${t?`border-white/15 bg-black/20 text-slate-200 cursor-pointer hover:border-sky-500/40`:`border-white/10 bg-black/10 text-slate-500`}`,children:c(`input`,{type:`checkbox`,className:`h-4 w-4 accent-sky-400`,checked:r,onChange:()=>Z(t),"aria-label":`Select ${e.name||t}`})}),c(`button`,{type:`button`,className:`tcp-list-item min-w-0 flex-1 text-left ${n?`border-sky-500/40 bg-sky-950/20`:``}`,onClick:()=>E(e=>e===t?``:t),children:[c(`i`,{"data-lucide":`file-text`}),c(`div`,{className:`min-w-0 flex-1`,children:[c(`div`,{className:`flex items-center justify-between gap-2`,children:[c(`strong`,{className:`truncate`,children:e.name||t}),c(`span`,{className:`tcp-subtle text-xs`,children:i})]}),c(`div`,{className:`mt-1 flex flex-wrap items-center gap-2 text-xs tcp-subtle`,children:[c(`span`,{className:`truncate`,children:t}),c(`span`,{children:xe(Number(e?.size||0))}),c(`span`,{children:Se(Number(e?.updatedAt||0))})]})]})]})]})},`file-${t}`)})})]})]}):c(p,{text:`This folder does not contain any files yet.`})})]})}),c(ie,{fullHeight:!0,className:`overflow-hidden`,title:`Preview`,subtitle:q?q.path:K?T:`Select a file`,actions:q?c(`a`,{className:`tcp-icon-btn h-8 w-8`,href:Ue,target:`_blank`,rel:`noreferrer`,title:`Download file`,"aria-label":`Download file`,children:c(`i`,{"data-lucide":`download`})}):K?c(`button`,{type:`button`,className:`tcp-icon-btn h-8 w-8`,title:`Open folder`,"aria-label":`Open folder`,onClick:()=>Y(T),children:c(`i`,{"data-lucide":`folder-open`})}):null,children:c(`div`,{className:`flex min-h-0 flex-1 flex-col gap-3 p-4`,children:q?c(t,{children:[c(`div`,{className:`rounded-xl border border-white/10 bg-black/20 p-3`,children:[c(`div`,{className:`flex items-start justify-between gap-3`,children:[c(`div`,{className:`min-w-0`,children:[c(`div`,{className:`truncate text-sm font-semibold`,children:q.name}),c(`div`,{className:`tcp-subtle mt-1 text-xs`,children:q.path})]}),c(`div`,{className:`flex flex-col items-end gap-1`,children:[c(d,{tone:`info`,children:J||`file`}),c(`span`,{className:`tcp-subtle text-xs`,children:He||`application/octet-stream`})]})]}),c(`div`,{className:`mt-3 grid grid-cols-2 gap-2 text-xs`,children:[c(`div`,{className:`rounded-lg border border-white/10 bg-black/10 p-2`,children:[c(`div`,{className:`tcp-subtle`,children:`Size`}),c(`div`,{className:`mt-1 font-medium`,children:xe(Number(q.size||0))})]}),c(`div`,{className:`rounded-lg border border-white/10 bg-black/10 p-2`,children:[c(`div`,{className:`tcp-subtle`,children:`Updated`}),c(`div`,{className:`mt-1 font-medium`,children:Se(Number(q.updatedAt||0))})]})]})]}),J===`image`?c(`div`,{className:`min-h-0 flex-1 overflow-auto rounded-xl border border-white/10 bg-black/20 p-3`,children:c(`img`,{src:Ue,alt:q.name,className:`max-h-full max-w-full rounded-lg object-contain`})}):J===`pdf`?c(`div`,{className:`min-h-0 flex-1 overflow-hidden rounded-xl border border-white/10 bg-black/20`,children:c(`iframe`,{title:q.name,src:Ue,className:`h-full w-full`})}):qe?c(`div`,{className:`min-h-0 flex-1 overflow-auto rounded-xl border border-white/10 bg-black/20 p-3`,children:Je?c(`div`,{className:`tcp-subtle text-sm`,children:`Loading preview...`}):J===`markdown`?c(`div`,{className:`tcp-markdown tcp-markdown-ai`,dangerouslySetInnerHTML:{__html:re(st||` `)}}):c(`pre`,{className:`tcp-code whitespace-pre-wrap break-words`,children:st||` `})}):c(`div`,{className:`grid min-h-0 flex-1 gap-3`,children:[c(p,{title:`Preview unavailable`,text:ot===`too_large`?`This file is larger than ${xe(2*1024*1024)} for inline preview.`:ot===`unavailable`?`The preview request failed or the file is no longer available.`:`This file type is not previewed inline.`}),c(`div`,{className:`rounded-xl border border-white/10 bg-black/20 p-3 text-xs`,children:[c(`div`,{className:`tcp-subtle`,children:`Download URL`}),c(`a`,{className:`mt-1 block truncate text-sky-200`,href:Ue,children:Ue})]})]})]}):K?c(`div`,{className:`grid gap-3`,children:[c(`div`,{className:`rounded-xl border border-white/10 bg-black/20 p-3`,children:[c(`div`,{className:`flex items-start justify-between gap-3`,children:[c(`div`,{children:[c(`div`,{className:`text-sm font-semibold`,children:T||`Folder`}),c(`div`,{className:`tcp-subtle mt-1 text-xs`,children:`Folder preview`})]}),c(d,{tone:`ghost`,children:`folder`})]}),c(`div`,{className:`mt-3 grid grid-cols-2 gap-2 text-xs`,children:[c(`div`,{className:`rounded-lg border border-white/10 bg-black/10 p-2`,children:[c(`div`,{className:`tcp-subtle`,children:`Folders`}),c(`div`,{className:`mt-1 font-medium`,children:V.length})]}),c(`div`,{className:`rounded-lg border border-white/10 bg-black/10 p-2`,children:[c(`div`,{className:`tcp-subtle`,children:`Files`}),c(`div`,{className:`mt-1 font-medium`,children:H.length})]})]})]}),c(`div`,{className:`rounded-xl border border-white/10 bg-black/20 p-3 text-xs`,children:[c(`div`,{className:`tcp-subtle`,children:`Folder path`}),c(`div`,{className:`mt-1 break-all`,children:T})]}),c(`button`,{type:`button`,className:`tcp-btn-primary justify-center`,onClick:rt,children:[c(`i`,{"data-lucide":`database-zap`}),`Import to Memory`]})]}):c(p,{title:`No selection`,text:`Pick a file to preview it here, or select a folder to see its details.`})})})]})}),c(`input`,{ref:le,type:`file`,className:`hidden`,multiple:!0,onChange:e=>{Ze(e.target.files),e.target.value=``}}),c(`input`,{ref:ue,type:`file`,className:`hidden`,multiple:!0,webkitdirectory:``,directory:``,onChange:e=>{Ze(e.target.files),e.target.value=``}}),c(g,{open:!!D,title:`Create folder`,message:c(`span`,{children:[`Create a new folder inside`,` `,c(`strong`,{children:D?.baseDir||(R?`Workspace`:`current path`)}),`.`]}),label:`Folder path`,value:D?.value||``,placeholder:R?`new-folder`:`knowledgebooks/new-collection`,confirmLabel:`Create folder`,confirmIcon:`folder-plus`,confirmDisabled:!String(D?.value||``).trim(),onCancel:()=>O(null),onChange:e=>O(t=>t&&{...t,value:e}),onConfirm:()=>void $e()}),c(se,{open:!!L,title:`Delete selected files`,message:c(`span`,{children:[`This will permanently remove`,` `,c(`strong`,{children:[L?.files.length||0,` selected file(s)`]}),` from`,` `,c(`strong`,{children:at||`the current folder`}),`.`]}),confirmLabel:`Delete selected`,confirmIcon:`trash-2`,confirmTone:`danger`,widthClassName:`w-[min(42rem,96vw)]`,onCancel:()=>ke(null),onConfirm:()=>void $(),children:L?.files.length?c(`div`,{className:`mt-3 grid gap-2 rounded-xl border border-white/10 bg-black/20 p-3 text-left text-xs`,children:[c(`div`,{className:`tcp-subtle uppercase tracking-wide`,children:`Selected files`}),c(`div`,{className:`max-h-40 overflow-auto`,children:[L.files.slice(0,12).map(e=>c(`div`,{className:`truncate py-1`,children:[c(`span`,{className:`font-medium text-slate-100`,children:e.name||e.path}),c(`span`,{className:`tcp-subtle`,children:[` · `,e.path]})]},e.path)),L.files.length>12?c(`div`,{className:`pt-1 text-slate-400`,children:[`+`,L.files.length-12,` more`]}):null]})]}):null}),c(_,{open:!!Ae,client:u,initialPath:Ae?.path||``,initialTier:dt,initialProjectId:ut,note:Ae?.note||``,toast:v,onCancel:()=>je(null),onSuccess:async()=>{await y.invalidateQueries({queryKey:[`memory`]})}})]})}export{Te as FilesPage};