openpond 0.0.32 → 0.0.34
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/chunks/{app-layer-CUQQUVJS.js → app-layer-UQQNF5VZ.js} +3 -3
- package/dist/chunks/{apps-TAYMUCWX.js → apps-7NSC56K5.js} +3 -3
- package/dist/chunks/{chunk-W2DJR3FA.js → chunk-2GCNPJMD.js} +1 -1
- package/dist/chunks/{chunk-GYZYZGKS.js → chunk-5MM3P5KY.js} +2 -2
- package/dist/chunks/{chunk-E5RVRUJB.js → chunk-B5CFIWWU.js} +1 -1
- package/dist/chunks/{chunk-FQW3AQVJ.js → chunk-BZPAW4JY.js} +31 -0
- package/dist/chunks/{chunk-5RHZKQRK.js → chunk-E3RLJ5XT.js} +2 -2
- package/dist/chunks/{chunk-3UOLQG6N.js → chunk-EBCLEJRO.js} +1 -1
- package/dist/chunks/{chunk-D264OHTR.js → chunk-F6FFL3AA.js} +2 -2
- package/dist/chunks/{chunk-PJXJ2HRT.js → chunk-G7XOSECC.js} +33 -0
- package/dist/chunks/{chunk-EONKWOLU.js → chunk-HGZ3O4TS.js} +2 -2
- package/dist/chunks/{chunk-DCNAXREU.js → chunk-JVTACGKD.js} +3 -3
- package/dist/chunks/{chunk-Y4F4XD5V.js → chunk-MMDKFTJB.js} +1 -1
- package/dist/chunks/{chunk-4HQURM3N.js → chunk-TF234YN4.js} +1 -1
- package/dist/chunks/{chunk-3ZJIEA5F.js → chunk-U4TUOBXO.js} +1 -1
- package/dist/chunks/{chunk-4M4WAORL.js → chunk-UASXM3RR.js} +4 -4
- package/dist/chunks/{chunk-OXQG773T.js → chunk-V7SHAMUN.js} +33 -33
- package/dist/chunks/{chunk-Q5MZCRJA.js → chunk-ZDEBKTWR.js} +1 -1
- package/dist/chunks/{chunk-XADW35CL.js → chunk-ZRNFOHFH.js} +3 -3
- package/dist/chunks/{cli-WW5BVN5Z.js → cli-4ETE5RS2.js} +4 -4
- package/dist/chunks/{cli-ZOCP7X5M.js → cli-VEDK2B42.js} +6 -6
- package/dist/chunks/{core-commands-SYGK7K57.js → core-commands-J3IQGQOL.js} +4 -4
- package/dist/chunks/{extend-Q5HZ7TMA.js → extend-3F3LLDOF.js} +9 -9
- package/dist/chunks/{harness-ZPBPQVAS.js → harness-JER7P6MJ.js} +3 -3
- package/dist/chunks/{help-3V3TRQNX.js → help-75NFCYJ4.js} +1 -1
- package/dist/chunks/{opchat-OUPMEFE5.js → opchat-UT5V7MR2.js} +5 -5
- package/dist/chunks/{organizations-5CSLBDAW.js → organizations-ERKRLVNQ.js} +4 -4
- package/dist/chunks/{profile-OQYSXHOG.js → profile-A3CUSDIF.js} +7 -7
- package/dist/chunks/{project-agent-TBTWOUJF.js → project-agent-FCV5HPYT.js} +6 -6
- package/dist/chunks/{sandbox-command-HCHPY7KW.js → sandbox-command-L2QPIWZ5.js} +4 -4
- package/dist/chunks/{sandbox-template-PNTOZ6W3.js → sandbox-template-XOIWROEK.js} +5 -5
- package/dist/chunks/{src-C6MXLDYQ.js → src-ENVQ7ARM.js} +2 -2
- package/dist/chunks/{src-GZT4UX6I.js → src-V4FUQNHR.js} +676 -462
- package/dist/chunks/{teams-bot-CQ76XI6T.js → teams-bot-OR3ZJHQ5.js} +3 -3
- package/dist/chunks/{workspaces-DHVVOTVR.js → workspaces-L73SRLPA.js} +2 -2
- package/dist/cli.js +10 -10
- package/dist/web/assets/{AppsView-CF2g-7FH.js → AppsView-CLjjVkjr.js} +1 -1
- package/dist/web/assets/{BrowserSidebar-lUsLUl20.js → BrowserSidebar-CkNO8723.js} +1 -1
- package/dist/web/assets/{CloudWorkView-BnfGW4OV.js → CloudWorkView-Cu_VqkaD.js} +1 -1
- package/dist/web/assets/{CommandMenu-BsS4Bgb6.js → CommandMenu-DWtdkvmq.js} +1 -1
- package/dist/web/assets/{CommunityView-C8qVOwlp.js → CommunityView-f03qOTER.js} +1 -1
- package/dist/web/assets/{ComposerCreateImproveStrip-C_LIpfSq.js → ComposerCreateImproveStrip-CZpiQJsJ.js} +1 -1
- package/dist/web/assets/{GetStartedView-Du533wOh.js → GetStartedView-CLMmryTG.js} +1 -1
- package/dist/web/assets/LabsRoute-BwR2g71k.js +4 -0
- package/dist/web/assets/{NewProjectDialog-DH7wA1z9.js → NewProjectDialog-PrbA4fL6.js} +1 -1
- package/dist/web/assets/{ProfileSettingsSection-D7JvMZdW.js → ProfileSettingsSection-CD_x_V8d.js} +1 -1
- package/dist/web/assets/SettingsView-BMmlKvlB.js +63 -0
- package/dist/web/assets/SettingsView-CAPf81v3.css +1 -0
- package/dist/web/assets/{TeamChatView-D_CE7br9.js → TeamChatView-B5SlhDso.js} +2 -2
- package/dist/web/assets/{TerminalOverlay-CC-VDSlp.js → TerminalOverlay-DaGfEprz.js} +1 -1
- package/dist/web/assets/TrainingComputeDialog-BFY6E0yU.js +1 -0
- package/dist/web/assets/{TrainingCreationPanel-NFCoaBUI.js → TrainingCreationPanel-Cp66gMed.js} +1 -1
- package/dist/web/assets/{TrainingDraftPanel-BWEmVFjM.js → TrainingDraftPanel-BX5CCqlO.js} +1 -1
- package/dist/web/assets/{WorkspaceDiffPanel-SlLlGZM1.js → WorkspaceDiffPanel-D7ZEbryF.js} +3 -3
- package/dist/web/assets/{WorkspaceEnvironmentMenu-BAoMBTVD.js → WorkspaceEnvironmentMenu-D4DmAJaS.js} +1 -1
- package/dist/web/assets/{WorkspaceGitDialogs-CVIFrzyl.js → WorkspaceGitDialogs-DHOfJxbL.js} +1 -1
- package/dist/web/assets/{WorkspaceMonacoEditor-0trp0-TI.js → WorkspaceMonacoEditor-C0fDue2d.js} +3 -3
- package/dist/web/assets/{boxes-CFihgX2z.js → boxes-CXLqRF98.js} +1 -1
- package/dist/web/assets/{create-pipeline-request-AJWLMTyw.js → create-pipeline-request-C26NOc7v.js} +1 -1
- package/dist/web/assets/{cssMode-HvqfCFyP.js → cssMode-DmtwKUVm.js} +1 -1
- package/dist/web/assets/{git-commit-horizontal-C5mUmACv.js → git-commit-horizontal-CDDZl4iA.js} +1 -1
- package/dist/web/assets/{htmlMode-C8btgUt-.js → htmlMode-Box0EOm1.js} +1 -1
- package/dist/web/assets/index-BUyeKpY6.js +1 -0
- package/dist/web/assets/{index-D7Vr3zcV.js → index-CKmte5ok.js} +55 -55
- package/dist/web/assets/{info-D0xuy5IB.js → info-4Iy6BKvT.js} +1 -1
- package/dist/web/assets/{jsonMode-5zVz9G0X.js → jsonMode-g7t_3HFv.js} +1 -1
- package/dist/web/assets/{lspLanguageFeatures-DxlSSL7c.js → lspLanguageFeatures-CwhFOYc9.js} +1 -1
- package/dist/web/assets/{monaco.contribution-BKpVvKK9.js → monaco.contribution-B-QC_ls9.js} +2 -2
- package/dist/web/assets/{monaco.contribution-B1pWWwqT.js → monaco.contribution-CW2ctrTm.js} +2 -2
- package/dist/web/assets/{monaco.contribution-BXdXsSWI.js → monaco.contribution-CwMt3eHi.js} +2 -2
- package/dist/web/assets/{monaco.contribution-CIjjzpUR.js → monaco.contribution-DGZAePHI.js} +2 -2
- package/dist/web/assets/{monitor-B4-9Shtp.js → monitor-DOVjBLkr.js} +1 -1
- package/dist/web/assets/{play-BJdhBqQE.js → play-DLCuESeG.js} +1 -1
- package/dist/web/assets/{python-CEK8J4w_.js → python-DRNmHcYd.js} +1 -1
- package/dist/web/assets/{refresh-cw-DE0u_nmZ.js → refresh-cw-JNUovwk4.js} +1 -1
- package/dist/web/assets/{reply-2MfLJ93n.js → reply-D4QvJyzE.js} +1 -1
- package/dist/web/assets/{save-CBIVKaf8.js → save-BR4O4UDP.js} +1 -1
- package/dist/web/assets/{toggleHighContrast-CC73mtvA.js → toggleHighContrast-CrfdWIsV.js} +1 -1
- package/dist/web/assets/training-DeVTd0m8.css +1 -0
- package/dist/web/assets/{tsMode-Bhn9wr_1.js → tsMode-ZuV9go1B.js} +1 -1
- package/dist/web/assets/useComputeSettings-DUNS6uOl.js +1 -0
- package/dist/web/assets/useComputeSettings-R2Sw621I.css +1 -0
- package/dist/web/assets/{wifi-off-BKTqnqj0.js → wifi-off-XFVqsf4c.js} +1 -1
- package/dist/web/assets/{workers-C_adgrEg.js → workers-CJpO1Wzj.js} +1 -1
- package/dist/web/assets/{yaml-DDRAcADU.js → yaml-AQ4ok5ED.js} +1 -1
- package/dist/web/index.html +1 -1
- package/package.json +1 -1
- package/dist/web/assets/LabsRoute-yk8lNMQc.js +0 -3
- package/dist/web/assets/SettingsView-C9TgCaWG.js +0 -63
- package/dist/web/assets/SettingsView-DwbGu8Kj.css +0 -1
- package/dist/web/assets/index-DUqAiF57.js +0 -1
- package/dist/web/assets/training-BY8siNUK.css +0 -1
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./TrainingComputeDialog-BFY6E0yU.js","./index-CKmte5ok.js","./index-8H-GDlM5.css","./ProfileSettingsSection-CD_x_V8d.js","./git-commit-horizontal-CDDZl4iA.js","./play-DLCuESeG.js","./refresh-cw-JNUovwk4.js","./ProfileSettingsSection-CqnfjiCl.css","./git-dialogs-BZDqS1eT.css","./useComputeSettings-DUNS6uOl.js","./index-BUyeKpY6.js","./useComputeSettings-R2Sw621I.css"])))=>i.map(i=>d[i]);
|
|
2
|
+
import{j as e,N as fe,r as c,b8 as Lt,z as Mn,A as Rn,a4 as An,b9 as ts,S as Ut,D as Ft,ba as Tn,a as Ps,bb as $s,bc as _n,U as Ds,X as Ve,a8 as En,aU as Pn,bd as ft,M as Bs,m as et,be as $n,bf as Dn,h as Ls,v as Kt,P as Bn,bg as Ln,V as Fs,Z as Fn,aI as On,Y as Os,R as zs,aT as qs,bh as zn,bi as qn}from"./index-CKmte5ok.js";import{P as Vn}from"./ProfileSettingsSection-CD_x_V8d.js";import{B as tt}from"./boxes-CXLqRF98.js";import{R as Vs}from"./refresh-cw-JNUovwk4.js";import{c as Un,e as $e,g as Kn,f as vt,s as Gt,d as ss,b as Gn,j as Us}from"./training-model-data-BXUCzS0p.js";import{ComposerCreateImproveStrip as Hn}from"./ComposerCreateImproveStrip-CZpiQJsJ.js";/* empty css */import"./git-commit-horizontal-CDDZl4iA.js";import"./play-DLCuESeG.js";/* empty css */const Mt=8,ns=24,Wn=2;function Jn(t){const s=Yn(t);if(s.length){const a=ns+s.reduce((r,o)=>r+Mt+We(o.content),0),l=s.filter(r=>r.role==="assistant").map(r=>Mt+We(r.content));return{renderedTokens:a,maximumAssistantTargetTokens:Math.max(0,...l),assistantTargetCount:l.length}}const n=Zn(t.input),i=ea(t.expectedOutput);return{renderedTokens:ns+We(n)+We(i),maximumAssistantTargetTokens:Mt+We(i),assistantTargetCount:i?1:0}}function Qn(t,s={}){const n=s.minimum??64,i=s.maximum??4096,a=t.tasks.filter(l=>l.split==="train").reduce((l,r)=>Math.max(l,Jn(r).renderedTokens),0);return a<=n?n:Math.min(i,2**Math.ceil(Math.log2(a)))}function Yn(t){const s=[...as(t.input.messages),...as(t.expectedOutput?.messages)],n=[],i=new Map,a=l=>{const r=typeof l=="string"&&l?l:`missing_${i.size+1}`;return i.has(r)||i.set(r,`call_${i.size+1}`),i.get(r)};for(const l of s){if(!gt(l))continue;const r=l.role,o=l.content;if(r==="tool"){n.push({role:"user",content:jt({content:typeof o=="string"?o:"",tool_call_id:a(l.tool_call_id),type:"tool_result"})});continue}if(r==="assistant"&&Array.isArray(l.tool_calls)&&l.tool_calls.length){for(const u of l.tool_calls)!gt(u)||!gt(u.function)||(n.push({role:"assistant",content:jt({arguments:Xn(u.function.arguments),name:u.function.name??null,type:"tool_call"})}),a(u.id));typeof o=="string"&&o&&n.push({role:"assistant",content:o});continue}(r==="system"||r==="user"||r==="assistant")&&typeof o=="string"&&o&&n.push({role:r,content:o})}return n}function as(t){return Array.isArray(t)?t:[]}function Xn(t){if(typeof t!="string")return{};try{return JSON.parse(t)}catch{return{malformed_arguments:t}}}function jt(t){return JSON.stringify(Ot(t))}function Ot(t){return Array.isArray(t)?t.map(Ot):gt(t)?Object.fromEntries(Object.keys(t).sort().map(s=>[s,Ot(t[s])])):t}function Zn(t){return typeof t.prompt=="string"?t.prompt:jt(t)}function ea(t){return t?typeof t.text=="string"?t.text:jt(t):""}function We(t){return Math.ceil(t.length/Wn)}function gt(t){return!!(t&&typeof t=="object"&&!Array.isArray(t))}function ta({section:t="all",payload:s,connection:n,onPayload:i,onError:a,onToast:l,onSkillCommand:r,overviewContent:o}){return e.jsx("section",{className:"profile-view","aria-label":t==="agents"?"Agents":"Profile",children:e.jsx(Vn,{section:t,payload:s,connection:n,onPayload:i,onError:a,onToast:l,onSkillCommand:r,overviewContent:o})})}function sa({candidates:t,onRescan:s,onSelect:n}){return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"training-dialog-scroll-body",children:[e.jsxs("div",{className:"training-run-step-heading",children:[e.jsx("h3",{children:t.length?"Review repeated workflows":"No repeated workflows found"}),e.jsx("p",{children:t.length?"Choose a candidate to review its supporting chats before anything is disclosed.":"Nothing met the current recurrence and evidence thresholds. No empty model was created."})]}),t.length?e.jsx("div",{className:"training-candidate-options",children:t.map(i=>e.jsxs("button",{type:"button",onClick:()=>n(i),children:[e.jsxs("span",{children:[e.jsx("strong",{children:i.title}),e.jsx("small",{children:i.summary})]}),e.jsxs("dl",{children:[e.jsxs("div",{children:[e.jsx("dt",{children:"Supporting chats"}),e.jsx("dd",{children:i.evidence.length})]}),e.jsxs("div",{children:[e.jsx("dt",{children:"Confidence"}),e.jsxs("dd",{children:[Math.round(i.scorecard.overall*100),"%"]})]}),e.jsxs("div",{children:[e.jsx("dt",{children:"Preliminary"}),e.jsx("dd",{children:i.recommendation.tactic.replaceAll("_"," ")})]})]})]},i.id))}):null]}),e.jsx("div",{className:"training-dialog-actions",children:e.jsx("button",{className:"training-button secondary",type:"button",onClick:s,children:t.length?"Scan again":"Change scan"})})]})}function na({chatPreview:t,chatCount:s,config:n,estimate:i,onConfigChange:a,onCancel:l,onScan:r,run:o,scanning:u}){return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"training-dialog-scroll-body",children:[e.jsxs("div",{className:"training-run-step-heading",children:[e.jsx("h3",{children:"Review chats in scope"}),e.jsx("p",{children:"OpenPond groups repeated work across completed chats on this device. The next step shows candidate workflows and their supporting chats; nothing is sent to an authoring model until you choose a candidate and approve disclosure."})]}),e.jsxs("dl",{className:"training-automatic-scope-summary",children:[e.jsxs("div",{children:[e.jsx("dt",{children:"Chats in scope"}),e.jsx("dd",{children:s})]}),e.jsxs("div",{children:[e.jsx("dt",{children:"Messages"}),e.jsx("dd",{children:i.measuredChats===s?i.messageCount:"Estimating…"})]}),e.jsxs("div",{children:[e.jsx("dt",{children:"Approximate tokens"}),e.jsx("dd",{children:i.measuredChats===s?ia(i.estimatedTokens):"Estimating…"})]})]}),e.jsxs("section",{className:"training-automatic-chat-preview","aria-label":"Recent chats in scope",children:[e.jsxs("div",{children:[e.jsx("h4",{children:"Recent chats"}),e.jsxs("span",{children:["Showing ",t.length," of ",s]})]}),t.length?e.jsx("ul",{children:t.map(h=>e.jsxs("li",{children:[e.jsx("strong",{children:h.title}),e.jsx("time",{dateTime:h.updatedAt,children:la(h.updatedAt)})]},h.id))}):e.jsx("p",{children:"No completed chats are available yet."}),e.jsx("small",{children:"Finding repeated work reads these chats locally. You will review the matching chats before any Taskset is authored."})]}),e.jsxs("details",{className:"training-automatic-options",children:[e.jsx("summary",{children:"Search options"}),e.jsxs("div",{children:[e.jsxs("label",{children:["Look back ",e.jsx("input",{type:"number",min:1,max:365,value:n.observationWindowDays,onChange:h=>a({...n,observationWindowDays:Number(h.target.value)})})," days"]}),e.jsxs("label",{children:["Minimum recurrence ",e.jsx("input",{type:"number",min:2,max:100,value:n.minimumRecurrence,onChange:h=>a({...n,minimumRecurrence:Number(h.target.value)})})]})]})]}),o&&["queued","running","cancelling"].includes(o.status)?e.jsxs("div",{className:"training-miner-progress",role:"status",children:[e.jsxs("div",{children:[e.jsx("strong",{children:aa(o)}),e.jsxs("span",{children:[o.progress.processedSources," of ",o.progress.totalSources||s," chats · ",o.progress.candidatesFound," candidates",o.progress.skippedSources?` · ${o.progress.skippedSources} skipped`:""]})]}),e.jsx("progress",{max:Math.max(1,o.progress.totalSources||s),value:o.progress.processedSources})]}):null,o?.status==="failed"?e.jsxs("p",{className:"training-empty",children:["Scan failed: ",o.error]}):null,o?.status==="cancelled"?e.jsx("p",{className:"training-empty",children:"The scan was cancelled. No candidate was selected."}):null]}),e.jsxs("div",{className:"training-dialog-actions",children:[u?e.jsx("button",{className:"training-button secondary",type:"button",disabled:o?.status==="cancelling",onClick:l,children:o?.status==="cancelling"?"Cancelling…":"Cancel scan"}):null,e.jsxs("button",{className:"training-button",type:"button",disabled:u||s===0,onClick:r,children:[u?e.jsx(fe,{className:"spin",size:14}):null,u?"Finding repeated work…":"Find repeated work"]})]})]})}function aa(t){return t.status==="queued"?"Preparing scan":t.status==="cancelling"?"Cancelling scan":t.progress.stage==="ingesting"?"Preparing local evidence":t.progress.stage==="clustering"?"Clustering repeated work":t.progress.stage==="persisting"?"Saving candidates":"Scanning local evidence"}function ia(t){return t<1e3?String(t):t<1e6?`${(t/1e3).toFixed(t>=1e4?0:1)}K`:`${(t/1e6).toFixed(t>=1e7?0:1)}M`}function la(t){return new Intl.DateTimeFormat(void 0,{month:"short",day:"numeric"}).format(new Date(t))}function ra({busy:t,candidates:s,value:n,onChange:i,onContinue:a,onManage:l,onScan:r}){const o=s.find(d=>d.selectionKey===n&&d.available)??null,u=da(s),h=n??s.find(d=>d.available)?.selectionKey??null;return e.jsxs(e.Fragment,{children:[e.jsxs("div",{"aria-label":"Starting-weight choices",className:"training-dialog-scroll-body training-base-model-scroll",role:"region",tabIndex:0,children:[e.jsxs("div",{className:"training-run-step-heading",children:[e.jsx("h3",{children:"Choose starting weights"}),e.jsx("p",{children:"Choose the model this Model should start from. Compute, provider, export, and spend are confirmed separately for each Version."})]}),e.jsxs("div",{className:"training-inline-actions training-base-model-actions",children:[e.jsxs("button",{className:"training-button secondary",type:"button",onClick:l,children:[e.jsx(tt,{size:14}),"Manage local models"]}),e.jsxs("button",{className:"training-button secondary",type:"button",disabled:t,onClick:r,children:[t?e.jsx(fe,{className:"spin",size:14}):e.jsx(Vs,{size:14}),t?"Scanning":"Scan this machine"]})]}),e.jsx("div",{"aria-label":"Available base models",className:"training-base-model-groups",role:"radiogroup",children:u.map(d=>e.jsxs("section",{className:"training-base-model-group",children:[e.jsxs("div",{className:"training-base-model-group-heading",children:[e.jsx("strong",{children:d.label}),e.jsx("small",{children:d.description})]}),e.jsx("div",{className:"training-method-options training-base-model-options",children:d.candidates.map(j=>e.jsx(oa,{candidate:j,selected:j.selectionKey===n,autofocus:j.selectionKey===h,onChange:i,onContinue:a},j.selectionKey))})]},d.label))}),s.length?null:e.jsx("div",{className:"training-banner",children:"No training base models were found. Scan this machine, or manage local models to configure storage and download supported weights."}),e.jsx("p",{className:"training-start-note",children:"This preference can be overridden for a Version, but OpenPond will not silently switch its base model or provider."})]}),e.jsx("div",{className:"training-dialog-actions",children:e.jsx("button",{className:"training-button",type:"button",disabled:!o,onClick:a,children:"Continue"})})]})}function oa({candidate:t,selected:s,autofocus:n,onChange:i,onContinue:a}){const l=!t.available;return e.jsxs("button",{"aria-checked":s,"aria-disabled":l,className:`${s?"selected":""}${l?" unavailable":""}`,"data-autofocus":!l&&n?!0:void 0,disabled:l,role:"radio",type:"button",onClick:()=>i(t.selectionKey),onDoubleClick:l?void 0:a,children:[e.jsx("span",{className:"training-base-model-icon","aria-hidden":"true",children:e.jsx(tt,{size:18})}),e.jsxs("span",{className:"training-base-model-copy",children:[e.jsx("strong",{children:t.label}),e.jsx("small",{children:t.preference.modelId}),t.preference.revision?e.jsxs("small",{children:["Revision ",ca(t.preference.revision)]}):null,t.available?null:e.jsx("small",{className:"training-base-model-reason",children:t.unavailableReason})]}),e.jsxs("span",{className:"training-base-model-tags","aria-hidden":"true",children:[e.jsx("small",{children:t.sourceLabel}),t.methods.map(r=>e.jsx("small",{children:r==="grpo"?"RFT":r.toUpperCase()},r)),e.jsx("small",{children:"LoRA"}),t.nonProduction?e.jsx("small",{children:"Non-production"}):null,t.available?null:e.jsx("small",{children:"Unavailable"})]}),e.jsx("span",{className:"training-choice-indicator","aria-hidden":"true"})]})}function da(t){const s=t.filter(i=>i.available);return[{label:"Managed",description:"Hosted training catalogs",candidates:s.filter(i=>i.preference.source==="managed")},{label:"This machine",description:"Verified local weights",candidates:s.filter(i=>i.preference.source!=="managed")},{label:"Unavailable",description:"Known choices that cannot run yet",candidates:t.filter(i=>!i.available)}].filter(i=>i.candidates.length>0)}function ca(t){return t.length>18?`${t.slice(0,18)}…`:t}function ua({state:t,selectedTasksetId:s,busy:n,onChange:i,onCreate:a}){const l=ma(t),r=l.find(o=>o.id===s)??null;return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"training-dialog-scroll-body",children:[e.jsxs("div",{className:"training-run-step-heading",children:[e.jsx("h3",{children:"Choose a Dataset"}),e.jsx("p",{children:"Use an approved Dataset as the immutable training and Eval boundary for this Model."})]}),e.jsxs("div",{className:"training-existing-dataset-list",role:"radiogroup","aria-label":"Available Datasets",children:[l.map(o=>{const u=o.id===s;return e.jsxs("button",{"aria-checked":u,className:u?"selected":void 0,role:"radio",type:"button",onClick:()=>i(o.id),children:[e.jsx("span",{className:"training-existing-dataset-icon",children:e.jsx(tt,{size:17})}),e.jsxs("span",{children:[e.jsx("strong",{children:o.name}),e.jsx("small",{children:o.objective})]}),e.jsx(ha,{taskset:o}),e.jsx("span",{className:"training-choice-indicator","aria-hidden":"true"})]},o.id)}),l.length?null:e.jsx("div",{className:"training-empty training-existing-dataset-empty",children:"No reusable Datasets are ready yet. Create a Dataset from the Lab menu, then return here."})]}),r?e.jsx("p",{className:"training-existing-dataset-note",children:"The Dataset remains reusable and unchanged. Creating the Model stores the preferred base Model on the Model draft."}):null]}),e.jsx("div",{className:"training-dialog-actions",children:e.jsx("button",{className:"training-button",disabled:!r||n,type:"button",onClick:a,children:"Create model"})})]})}function ha({taskset:t}){return e.jsxs("span",{className:"training-existing-dataset-splits",children:[e.jsxs("span",{children:[Rt(t,"train")," train"]}),e.jsxs("span",{children:[Rt(t,"validation")," validation"]}),e.jsxs("span",{children:[Rt(t,"frozen_eval")," frozen Eval"]})]})}function Rt(t,s){return t.tasks.filter(n=>n.split===s).length}function ma(t){return t?t.tasksets.filter(s=>s.readiness?.ready).sort((s,n)=>n.updatedAt.localeCompare(s.updatedAt)||s.name.localeCompare(n.name)):[]}function pa({creation:t,resourceIntent:s="workproduct",sources:n,training:i,onCreationChange:a}){const[l,r]=c.useState(""),o=t.proposal,[u,h]=c.useState(o?.name??"");if(c.useEffect(()=>h(o?.name??""),[o?.name]),!o)return null;const d=o.diagnosis,j=s==="dataset"?"dataset":ga(t),x=new Map(n.map(N=>[N.id,N])),m=o.proposedExamples.filter(N=>N.split==="train"),k=o.proposedExamples.filter(N=>N.split!=="train"),g=t.materializedTasksetId?i.payload?.graderAuditReports.find(N=>N.tasksetId===t.materializedTasksetId)??null:null,y=o.trainingPath?.primaryMethod??o.proposedMethod;async function S(){const N=l.trim();if(!N)return;const R=await i.actions.chatCreation(t.id,N);R&&(r(""),a(R))}async function v(){if(!o)return;const N=Lt(u,o.name);if(!N||N===o.name)return;const R=await i.actions.renameCreation(t.id,N);R&&(h(R.proposal?.name??N),a(R))}return e.jsxs("div",{className:"training-recommendation-review",children:[e.jsxs("section",{className:"training-setup-section training-setup-model",children:[e.jsxs("div",{className:"training-setup-section-heading",children:[e.jsx("span",{className:"training-setup-step-number",children:"1"}),e.jsx("strong",{children:j==="dataset"?"Dataset":"Model"}),e.jsxs("small",{children:[xt(j)," · ",xa(d.intervention)]})]}),e.jsxs("label",{className:"training-recommendation-name",children:[e.jsx("span",{children:j==="dataset"?"Dataset name":j==="model"?"Model name":"Workproduct name"}),e.jsx("input",{value:u,maxLength:100,onChange:N=>h(N.target.value),onBlur:()=>{v()},onKeyDown:N=>{N.key==="Enter"&&(N.preventDefault(),v())}}),e.jsx("small",{children:"Five words maximum. The full capability stays in the description."})]}),e.jsx("p",{className:"training-recommendation-objective",children:o.objective}),j==="model"&&t.request.preferredBaseModelId?e.jsxs("p",{className:"training-recommendation-base-model",children:[e.jsx("span",{children:"Preferred base"}),e.jsx("strong",{children:ja(t.request.preferredBaseModelId)})]}):null]}),e.jsxs("details",{className:"training-setup-section",children:[e.jsxs("summary",{children:[e.jsx("span",{className:"training-setup-step-number",children:"2"}),e.jsx("strong",{children:"Dataset & Evals"}),e.jsxs("small",{children:[m.length," train · ",k.length," eval · ",o.proposedGraders.length," grader",o.proposedGraders.length===1?"":"s"]})]}),e.jsxs("div",{className:"training-recommendation-detail-body",children:[e.jsxs("dl",{className:"training-recommendation-facts",children:[e.jsxs("div",{children:[e.jsx("dt",{children:"Chat seeds"}),e.jsx("dd",{children:t.request.sourceIds.length})]}),e.jsxs("div",{children:[e.jsx("dt",{children:"Training examples"}),e.jsx("dd",{children:m.length})]}),e.jsxs("div",{children:[e.jsx("dt",{children:"Evaluation examples"}),e.jsx("dd",{children:k.length})]}),e.jsxs("div",{children:[e.jsx("dt",{children:"Grader"}),e.jsx("dd",{children:g?g.passed?"Passed":"Failed":o.proposedGraders.length?"Runs after creation":"Not proposed"})]})]}),o.proposedExamples.length?e.jsx("div",{className:"training-proposed-examples",children:o.proposedExamples.map(N=>e.jsxs("article",{children:[e.jsxs("div",{children:[e.jsx("strong",{children:N.split==="frozen_eval"?"Evaluation":N.split==="train"?"Training":xt(N.split)}),e.jsx("span",{children:xt(N.origin.replaceAll("_"," "))})]}),e.jsx("p",{children:N.inputPrompt}),e.jsx("small",{children:x.get(N.sourceId)?.title??"Selected chat"})]},N.id))}):e.jsx("p",{children:"No training examples are proposed for this recommendation."}),o.proposedGraders.length?e.jsxs("div",{className:"training-proposed-evaluation",children:[e.jsx("strong",{children:"Grader summary"}),e.jsxs("p",{children:[o.proposedGraders.map(N=>N.label).join(", ")," · ",g?g.passed?"executed successfully":"execution failed":"execution pending Taskset creation"]})]}):null,o.warnings.length&&t.state!=="recommendation_ready"?e.jsx("ul",{className:"training-recommendation-warnings",children:o.warnings.map(N=>e.jsx("li",{children:N},N))}):null]})]}),e.jsxs("details",{className:"training-setup-section",open:!0,children:[e.jsxs("summary",{children:[e.jsx("span",{className:"training-setup-step-number",children:"3"}),e.jsx("strong",{children:"Recommended training"}),e.jsx("small",{children:is(y)})]}),e.jsxs("div",{className:"training-recommendation-detail-body training-path-review",children:[e.jsxs("div",{children:[e.jsxs("strong",{children:["Primary · ",is(y)]}),e.jsx("p",{children:d.rationale.join(" ")||d.summary})]}),o.trainingPath?.bootstrap?e.jsxs("div",{children:[e.jsx("strong",{children:"Optional precursor · Supervised / SFT"}),e.jsxs("p",{children:[o.trainingPath.bootstrap.demonstrationRefs.length," reviewed demonstration",o.trainingPath.bootstrap.demonstrationRefs.length===1?"":"s",". ",o.trainingPath.bootstrap.limitations.join(" ")]})]}):null,e.jsx("p",{className:"training-setup-spend-note",children:"Creating the model saves this Dataset and recommendation locally. Paid provider training starts later from the model’s Training page, where method, budget, and export are reviewed explicitly."})]})]}),e.jsxs("details",{className:"training-setup-section",children:[e.jsxs("summary",{children:[e.jsx("span",{className:"training-setup-step-number",children:"4"}),e.jsx("strong",{children:"Behavior & context"}),e.jsxs("small",{children:[d.stableBehavior.length," stable behavior",d.stableBehavior.length===1?"":"s"]})]}),e.jsxs("div",{className:"training-recommendation-detail-body",children:[e.jsx("h4",{children:"What it should learn"}),d.stableBehavior.length?e.jsx("ul",{children:d.stableBehavior.map(N=>e.jsx("li",{children:N},N))}):e.jsx("p",{children:d.summary}),d.changingKnowledge.length||d.requiredContext.length?e.jsxs(e.Fragment,{children:[e.jsx("h4",{children:"Keep in context"}),e.jsx("ul",{children:[...d.changingKnowledge,...d.requiredContext].map(N=>e.jsx("li",{children:N},N))})]}):null]})]}),e.jsxs("details",{className:"training-setup-section",children:[e.jsxs("summary",{children:[e.jsx("span",{className:"training-setup-step-number",children:"5"}),e.jsx("strong",{children:"Advanced"}),e.jsx("small",{children:"Technical method · revise"})]}),e.jsxs("div",{className:"training-recommendation-detail-body training-recommendation-revision",children:[e.jsxs("p",{children:["Technical method: ",fa(y)]}),t.state==="recommendation_ready"||!d.trainingEligible?e.jsxs("div",{className:"training-recommendation-guidance",children:[e.jsx("strong",{children:"Why this is not ready for a Dataset"}),e.jsx("ul",{children:o.warnings.map(N=>e.jsx("li",{children:N},N))})]}):null,e.jsx("textarea",{value:l,onChange:N=>r(N.target.value),placeholder:"Explain what should change"}),e.jsx("button",{className:"training-button secondary",type:"button",disabled:!l.trim()||!!i.busyAction,onClick:()=>{S()},children:"Revise"})]})]})]})}function ga(t){return t.request.targetIntent.kind?t.request.targetIntent.kind:t.proposal?.diagnosis.trainingEligible?"model":t.proposal?.diagnosis.intervention==="retrieval"?"configuration":"agent"}function xa(t){return{no_training:"No training",prompting:"Prompt or agent instructions",retrieval:"Retrieval",sft:"SFT",preference:"Preference tuning",grpo_rft:"RFT",sdft_opsd:"Distillation",sdpo:"SDPO",agentic_rl:"Agentic RL"}[t]}function xt(t){return t&&`${t[0].toUpperCase()}${t.slice(1)}`}function is(t){return t==="grpo"?"Reinforcement / RFT":t==="sft"?"Supervised / SFT":t==="preference"?"Preference":xt(t.replaceAll("_"," "))}function fa(t){return t==="grpo"?"GRPO optimizer":t==="sft"?"SFT":t.toUpperCase()}function ja(t){return t.split("/").filter(Boolean).at(-1)??t}function ba({busy:t,createLabel:s="Create Taskset",creation:n,editDataLabel:i="Add chats",onAddChats:a,onClose:l,onCreateTaskset:r,onCreationChange:o,resourceIntent:u="workproduct",sources:h,training:d}){const j=n.state==="awaiting_materialization_approval",x=n.state==="recommendation_ready"&&n.proposal?.diagnosis.trainingEligible===!0;return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"training-dialog-scroll-body",children:e.jsx(pa,{creation:n,resourceIntent:u,sources:h,training:d,onCreationChange:o})}),e.jsxs("div",{className:"training-dialog-actions",children:[x?e.jsx("button",{className:"training-button secondary",type:"button",disabled:t,onClick:a,children:i}):null,e.jsx("button",{className:"training-button secondary",type:"button",onClick:l,children:j?"Cancel":"Done"}),j?e.jsxs("button",{className:"training-button",type:"button",disabled:t,onClick:r,children:[t?e.jsx(fe,{className:"spin",size:14}):null,s]}):null]})]})}function va({authoringModel:t,authoringProvider:s,authoringReasoningEffort:n,busy:i,disclosurePending:a,estimatesBySessionId:l,matchingSessionCount:r,mode:o,objective:u,onObjectiveChange:h,onAnalyze:d,onApproveDisclosure:j,onAuthoringModelChange:x,onAuthoringProviderChange:m,onAuthoringReasoningEffortChange:k,onDeclineDisclosure:g,onSearchChange:y,onLoadMore:S,onReturnToRecommendation:v,onToggleSession:N,onToggleVisible:R,providerSettings:T,recommendationAvailable:J,search:L,searchError:f,searchHasMore:_,searchIndexedChats:ce,searchIndexing:$,searchLoading:se,searchTotalChats:Q,selectedEntries:E,selectedEstimate:H,selectedSessionIds:ne,targetLabel:O="model",visibleSessions:ie}){const re=c.useMemo(()=>Mn(T,{enabledOnly:!0}),[T]),W=c.useMemo(()=>Rn(s,T),[s,T]),Y=An(s,t,T),z=ne.size,ae=ie.length>0&&ie.every(D=>ne.has(D.sessionId)),K=ie.filter(D=>!ne.has(D.sessionId)),X=z>0||o==="manual"&&!!u.trim(),V=H.measuredChats===z,oe=z>0&&V&&H.estimatedTokens>ts,ue=O==="dataset",he=O==="model",ee=he||ue,Ce=ue||he?"Build the Dataset":"Review supporting chats",P=o==="automated"?ee?"Confirm the chats that demonstrate this repeated workflow. Only selected chats seed the Dataset.":"Approve the chats that support this repeated workflow.":ee?"Describe the capability, then optionally add successful chats. OpenPond can propose generated training and evaluation examples when no chats are selected.":"Describe the capability, then add successful examples, corrections, reviewer choices, or outcome-bearing runs.";return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"training-dialog-scroll-body",children:[e.jsxs("div",{className:"training-run-step-heading",children:[e.jsx("h3",{children:Ce}),e.jsx("p",{children:P})]}),o==="manual"?e.jsxs("label",{className:"training-objective-field training-dataset-capability",children:[e.jsx("span",{children:"Capability"}),e.jsx("textarea",{"data-autofocus":!0,required:!0,value:u,disabled:i||a,placeholder:`Describe what this ${O} should do reliably`,onChange:D=>h(D.target.value)})]}):u?e.jsxs("div",{className:"training-evidence-objective",children:[e.jsx("span",{children:"Capability"}),e.jsx("strong",{children:u})]}):null,e.jsxs("fieldset",{className:"training-evidence-fields",disabled:i||a,children:[e.jsxs("div",{className:"training-dataset-source-heading",children:[e.jsx("span",{children:ee?"Chat seeds":"Supporting chats"}),o==="manual"&&ee?e.jsx("small",{children:"Optional"}):null]}),e.jsxs("div",{className:"training-source-toolbar",children:[e.jsxs("label",{className:"training-search",children:[e.jsx(Ut,{size:14}),e.jsx("input",{value:L,onChange:D=>y(D.target.value),placeholder:"Search chats"})]}),e.jsx("button",{className:"training-text-button",type:"button",disabled:!ie.length,onClick:R,children:ae?"Clear visible":"Select visible"})]}),e.jsxs("div",{className:"training-source-result-count",children:[e.jsxs("span",{children:["Showing ",ie.length," of ",r," matching chats"]}),$?e.jsxs("span",{children:["Indexing messages ",ce," of ",Q]}):null]}),e.jsxs("div",{className:"training-source-options",onScroll:D=>{const de=D.currentTarget;_&&!se&&de.scrollHeight-de.scrollTop-de.clientHeight<72&&S()},children:[E.length?e.jsx("div",{className:"training-selected-chat-group",children:E.map(D=>e.jsx(ls,{entry:D,checked:!0,estimatesBySessionId:l,onToggleSession:N,showSnippet:!!L.trim()},D.sessionId))}):null,K.map(D=>e.jsx(ls,{entry:D,checked:!1,estimatesBySessionId:l,onToggleSession:N,showSnippet:!!L.trim()},D.sessionId)),se?e.jsxs("div",{className:"training-chat-search-state",children:[e.jsx(fe,{className:"spin",size:15}),e.jsx("span",{children:ie.length?"Loading more chats…":"Searching chats…"})]}):null,f?e.jsx("p",{className:"training-empty",children:f}):null,!se&&!f&&!ie.length?e.jsx("p",{className:"training-empty",children:$?"No matches yet. Message indexing is still running.":"No completed chats match this search."}):null]}),e.jsxs("div",{className:"training-authoring-row",children:[e.jsx("span",{children:"Analyzed with"}),e.jsxs("div",{className:"training-authoring-controls","aria-label":"Analysis model",children:[e.jsx(Ft,{compact:!0,placement:"bottom",label:"Provider",value:s,options:re,disabled:i,onChange:D=>m(D)}),Y?e.jsx(Tn,{disabled:i,model:t,modelOptions:W,placement:"bottom",reasoningEffort:n,onModelChange:x,onReasoningEffortChange:k}):e.jsx(Ft,{compact:!0,placement:"bottom",label:"Model",value:t,options:W,disabled:i,onChange:x})]})]})]}),a?e.jsxs("div",{className:"training-disclosure-review",role:"status",children:[e.jsx("strong",{children:"Approve evidence disclosure"}),e.jsxs("p",{children:[e.jsxs("b",{children:[s," / ",t]})," will receive raw excerpts from ",z," selected chat",z===1?"":"s",", ",H.messageCount," messages, and approximately ",Xe(H.estimatedTokens)," tokens. Unselected local chats and the local search index are not sent."]})]}):null,oe?e.jsxs("div",{className:"training-banner error",role:"alert",children:["Selected evidence is about ",Xe(H.estimatedTokens)," tokens. Hosted Taskset authoring accepts up to ",Xe(ts)," raw-evidence tokens; choose fewer chats or selected turns."]}):null]}),e.jsxs("div",{className:"training-dialog-actions",children:[e.jsx("span",{className:"training-selection-count",children:z===0?"No supporting chats selected":H.measuredChats===z?e.jsxs(e.Fragment,{children:[e.jsxs("span",{children:[z," chat",z===1?"":"s"]}),e.jsxs("span",{children:[H.messageCount," messages"]}),e.jsxs("span",{children:["About ",Xe(H.estimatedTokens)," tokens"]})]}):e.jsxs(e.Fragment,{children:[e.jsxs("span",{children:[z," chat",z===1?"":"s"]}),e.jsx("span",{children:"Estimating…"})]})}),a?e.jsxs(e.Fragment,{children:[e.jsx("button",{className:"training-button secondary",type:"button",disabled:i,onClick:g,children:"Change evidence"}),e.jsxs("button",{className:"training-button",type:"button",disabled:i||!V||oe,onClick:j,children:[i?e.jsx(fe,{className:"spin",size:14}):null,"Approve and analyze"]})]}):J?e.jsxs(e.Fragment,{children:[e.jsx("button",{className:"training-button secondary",type:"button",disabled:i,onClick:d,children:"Reanalyze changes"}),e.jsx("button",{className:"training-button",type:"button",onClick:v,children:"Return to recommendation"})]}):e.jsxs("button",{className:"training-button",type:"button",disabled:!X||i||oe||z>0&&!V,onClick:d,children:[i?e.jsx(fe,{className:"spin",size:14}):null,z>0?"Review data access":ee?"Build Dataset":"Review setup"]})]})]})}function ls({checked:t,entry:s,estimatesBySessionId:n,onToggleSession:i,showSnippet:a}){return e.jsxs("label",{children:[e.jsx("input",{className:"training-chat-checkbox",type:"checkbox",checked:t,onChange:l=>i(s.sessionId,l.target.checked)}),e.jsxs("span",{children:[e.jsx("strong",{children:s.title}),a&&s.snippet?e.jsx("span",{className:"training-chat-search-snippet",children:s.snippet}):null,e.jsxs("small",{children:[new Date(s.updatedAt).toLocaleString(),e.jsx(ya,{estimate:n[s.sessionId]})]})]})]})}function ya({estimate:t}){return t?e.jsxs("span",{className:"training-chat-estimate",children:[e.jsxs("span",{children:[t.messageCount," messages"]}),e.jsxs("span",{children:["About ",Xe(t.estimatedTokens)," tokens"]})]}):e.jsx("span",{className:"training-chat-estimate",children:e.jsx("span",{children:"Estimating…"})})}function Xe(t){return t<1e3?String(t):t<1e6?`${(t/1e3).toFixed(t>=1e4?0:1)}K`:`${(t/1e6).toFixed(t>=1e7?0:1)}M`}const rs=[{id:"automated",title:"Automated",description:"Review repeated work in chats and recommend what, if anything, should be trained.",icon:Ut},{id:"manual",title:"Manual",description:"Start from a capability you already want the model to learn.",icon:Ps},{id:"existing_dataset",title:"Existing Dataset",description:"Create the Model from a reviewed Dataset without changing its tasks, graders, or held-out Evals.",icon:tt}];function Na({mode:t,allowExistingDataset:s=!1,targetLabel:n="model",onChange:i,onContinue:a}){const l=s?rs:rs.filter(r=>r.id!=="existing_dataset");return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"training-run-step-heading",children:[e.jsx("h3",{children:"Choose a setup"}),e.jsx("p",{children:"Start from repeated work or define the capability yourself. OpenPond recommends the training method after reviewing the Dataset."})]}),e.jsx("div",{"aria-label":`How to start a new ${n}`,className:"training-method-options training-start-mode-options",role:"radiogroup",children:l.map(r=>{const o=r.icon,u=r.id===t;return e.jsxs("button",{type:"button",role:"radio","aria-checked":u,className:u?"selected":"",onClick:()=>i(r.id),onDoubleClick:a,children:[e.jsx("span",{className:"training-start-mode-icon","aria-hidden":"true",children:e.jsx(o,{size:18})}),e.jsxs("span",{className:"training-start-mode-copy",children:[e.jsx("strong",{children:r.title}),e.jsx("small",{children:r.description})]}),e.jsx("span",{className:"training-choice-indicator","aria-hidden":"true"})]},r.id)})}),e.jsx("div",{className:"training-dialog-actions",children:e.jsx("button",{className:"training-button",type:"button",disabled:!t,onClick:a,children:"Continue"})})]})}const os=20,ka=c.lazy(()=>Pn(()=>import("./TrainingComputeDialog-BFY6E0yU.js"),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11]),import.meta.url).then(t=>({default:t.TrainingComputeDialog})));function Je({defaultModel:t,initialCreation:s=null,initialObjective:n,initialSessionIds:i=[],onClose:a,onModelCreatedFromTaskset:l,onTasksetCreated:r,preferences:o,providerSettings:u,reasoningEffort:h,resourceIntent:d="workproduct",sessions:j,sources:x,training:m,targetIntent:k={kind:"model",id:null,displayName:null,operation:"create"}}){const g=$s(o,t),y=m.payload?.baseModelCandidates??[],S=x.filter(p=>s?.request.sourceIds.includes(p.id)).map(p=>p.sessionId),[v,N]=c.useState(()=>Sa(s)),[R,T]=c.useState(s?.request.entryMode??null),J=R==="automated"||R==="manual"?R:null,[L,f]=c.useState(s?.request.objective??n??""),[_,ce]=c.useState(()=>ds(y,s?.request.preferredBaseModel??null,s?.request.preferredBaseModelId??null)?.selectionKey??null),[$,se]=c.useState(null),[Q,E]=c.useState(s?.request.candidateId??null),[H,ne]=c.useState(s?.request.analysisModel?.providerId??g.providerId),[O,ie]=c.useState(s?.request.analysisModel?.modelId??g.modelId),[re,W]=c.useState(s?.request.analysisReasoningEffort??h),[Y,z]=c.useState(""),[ae,K]=c.useState([]),[X,V]=c.useState(0),[oe,ue]=c.useState(!1),[he,ee]=c.useState(!1),[Ce,P]=c.useState(null),[D,de]=c.useState(!1),[te,be]=c.useState(0),[Te,I]=c.useState(0),[U,xe]=c.useState(0),pe=c.useRef(0),[ve,ge]=c.useState(()=>new Set([...i,...S])),[w,F]=c.useState({}),[A,q]=c.useState(s),[Ue,Z]=c.useState(!1),[nt,ye]=c.useState(!1),[at,Ne]=c.useState(null),[Oe,Ke]=c.useState(!1),[le,it]=c.useState(!1),[_e,Ge]=c.useState(null),[Ae,Nt]=c.useState([]),[b,G]=c.useState(()=>m.payload?.minerConfig??Ma()),De=c.useRef(null),lt=c.useRef(null),Qt=c.useMemo(()=>new Set(x.filter(p=>{const M=p.metadata.workflowSignature;return p.metadata.frontierBaseline===!0||M==="cross-system-operations"||typeof M=="string"&&M.startsWith("baseline:")||!!p.metadata.crossSystemOperations}).map(p=>p.sessionId)),[x]),Ie=c.useMemo(()=>j.filter(p=>!p.systemKind&&!p.hiddenFromDefaultSidebar&&p.status!=="active"&&!Qt.has(p.id)),[Qt,j]),Yt=c.useMemo(()=>new Map(j.map(p=>[p.id,p])),[j]),kt=c.useMemo(()=>new Map(x.map(p=>[p.sessionId,p])),[x]),rt=c.useMemo(()=>Ie.slice(0,500).map(p=>({sessionId:p.id,title:p.title,updatedAt:p.updatedAt})),[Ie]),St=c.useMemo(()=>[...ve].flatMap(p=>{const M=ae.find(we=>we.sessionId===p);if(M)return[M];const C=Yt.get(p);if(C)return[{sessionId:p,title:C.title,updatedAt:C.updatedAt,snippet:null}];const B=kt.get(p);return B?[{sessionId:p,title:B.title,updatedAt:B.occurredAt,snippet:null}]:[]}),[ae,ve,Yt,kt]),wt=c.useMemo(()=>[...new Set([...St,...ae].map(p=>p.sessionId))].filter(p=>!w[p]).join(`
|
|
3
|
+
`),[w,ae,St]),ze=c.useMemo(()=>m.payload?.minerRuns.find(p=>p.id===_e)??null,[_e,m.payload?.minerRuns]),ln=Oe||!!(ze&&["queued","running","cancelling"].includes(ze.status)),He=nt||Oe||!!m.busyAction,Be=d==="workproduct"&&k.kind==="model",Xt=c.useMemo(()=>y.find(p=>p.selectionKey===_)??null,[y,_]),Ct=Xt?.preference??null;c.useEffect(()=>f(s?.request.objective??n??""),[s?.id,n]),c.useEffect(()=>{if(_||!s)return;const p=ds(y,s.request.preferredBaseModel,s.request.preferredBaseModelId);p&&ce(p.selectionKey)},[y,s,_]),c.useEffect(()=>{if(v!=="automatic_scope"||_e)return;const p=m.payload?.minerRuns.find(M=>["queued","running","cancelling"].includes(M.status));p&&Ge(p.id)},[_e,v,m.payload?.minerRuns]),c.useEffect(()=>{if(!_n(v,ze))return;const p=new Set(ze.candidateIds);Nt(m.payload?.candidates.filter(M=>p.has(M.id))??[]),N("automatic_candidates")},[ze,v,m.payload?.candidates]),c.useEffect(()=>(lt.current=document.activeElement instanceof HTMLElement?document.activeElement:null,()=>lt.current?.focus()),[]),c.useEffect(()=>{const p=window.requestAnimationFrame(()=>{De.current?.querySelector("[data-autofocus], [aria-label^='Back']")?.focus()});return()=>window.cancelAnimationFrame(p)},[v]),c.useEffect(()=>{v==="evidence"&&(K([]),V(0),ue(!1),P(null))},[Y,v]),c.useEffect(()=>{if(v!=="evidence")return;const p=pe.current+1;pe.current=p,ee(!0),P(null);const M=window.setTimeout(()=>{m.actions.searchChats(Y,rt,0,os).then(C=>{pe.current===p&&(K(C.entries),V(C.total),ue(C.hasMore),de(C.indexing),be(C.indexedChats),I(C.totalChats))}).catch(C=>{pe.current===p&&(K([]),V(0),ue(!1),de(!1),P(C instanceof Error?C.message:String(C)))}).finally(()=>{pe.current===p&&ee(!1)})},220);return()=>window.clearTimeout(M)},[rt,Y,U,v,m.actions]),c.useEffect(()=>{if(v!=="evidence"||!Y.trim()||!D)return;const p=window.setTimeout(()=>xe(M=>M+1),1500);return()=>window.clearTimeout(p)},[Y,D,v]);const rn=c.useCallback(async()=>{if(he||!oe)return;const p=pe.current,M=ae.length;ee(!0);try{const C=await m.actions.searchChats(Y,rt,M,os);if(pe.current!==p)return;K(B=>{const we=new Set(B.map(It=>It.sessionId));return[...B,...C.entries.filter(It=>!we.has(It.sessionId))]}),V(C.total),ue(C.hasMore),de(C.indexing),be(C.indexedChats),I(C.totalChats)}catch(C){pe.current===p&&P(C instanceof Error?C.message:String(C))}finally{pe.current===p&&ee(!1)}},[rt,Y,ae.length,oe,he,m.actions]);c.useEffect(()=>{const p=Object.fromEntries(x.flatMap(M=>{const C=typeof M.metadata.messageCount=="number"?M.metadata.messageCount:null,B=typeof M.metadata.estimatedTokens=="number"?M.metadata.estimatedTokens:null;return C===null||B===null?[]:[[M.sessionId,{messageCount:C,estimatedTokens:B}]]}));Object.keys(p).length&&F(M=>({...p,...M}))},[x]),c.useEffect(()=>{if(v!=="evidence"||!wt)return;let p=!1;const M=window.setTimeout(()=>{m.actions.estimateSources(wt.split(`
|
|
4
|
+
`)).then(C=>{p||F(B=>({...B,...Object.fromEntries(C.map(we=>[we.sessionId,{messageCount:we.messageCount,estimatedTokens:we.estimatedTokens}]))}))}).catch(()=>{})},200);return()=>{p=!0,window.clearTimeout(M)}},[v,m.actions,wt]),c.useEffect(()=>{if(v!=="automatic_scope"||!Ie.length)return;const p=Ie.map(C=>C.id).filter(C=>!w[C]);if(!p.length)return;let M=!1;return m.actions.estimateSources(p).then(C=>{M||F(B=>({...B,...Object.fromEntries(C.map(we=>[we.sessionId,{messageCount:we.messageCount,estimatedTokens:we.estimatedTokens}]))}))}).catch(()=>{}),()=>{M=!0}},[Ie,w,v,m.actions]);const on=c.useMemo(()=>hs([...ve],w),[w,ve]),dn=c.useMemo(()=>hs(Ie.map(p=>p.id),w),[Ie,w]);function cn(p){p!==R&&R!==null&&Z(!0),T(p)}function un(){if(Be){N("base_model");return}Zt()}function Zt(){if(!(Be&&!Xt?.available)){if(R==="existing_dataset"){N("existing_dataset");return}J==="automated"&&N("automatic_scope"),J==="manual"&&N("evidence")}}async function hn(){if(!(!$||!l||!Ct)){ye(!0),Ne(null);try{const p=await m.actions.createModelFromTaskset($,Ct);if(!p)throw new Error(m.error??"OpenPond could not create the Model from this Dataset.");const M=m.payload?.tasksets.find(C=>C.id===$);if(!M)throw new Error("The selected Dataset could not be reloaded.");await l(M,p)}catch(p){Ne(p instanceof Error?p.message:String(p))}finally{ye(!1)}}}function mn(p){p!==L&&Z(!0),f(p)}function pn(p){Z(!0),ne(p),ie(M=>En(p,M,u))}function gn(p){Z(!0),ie(p)}function xn(p){Z(!0),W(p)}function fn(){Z(!0),ge(p=>{const M=new Set(p),C=ae.length>0&&ae.every(B=>M.has(B.sessionId));for(const B of ae)C?M.delete(B.sessionId):M.add(B.sessionId);return M})}function jn(p,M){Z(!0),ge(C=>{const B=new Set(C);return M?B.add(p):B.delete(p),B})}async function bn(){const p=[],M=[];for(const C of ve){const B=kt.get(C);B?p.push(B):M.push(C)}if(M.length){const C=await m.actions.addSources(M);if(!C)throw new Error("OpenPond could not attach the selected evidence. Review the training error and try again.");p.push(...C)}if(p.length!==ve.size)throw new Error("Some selected evidence could not be resolved. Reselect the chats before continuing.");return p}async function vn(){Ke(!0);try{const p={...b,enabled:!0},M=await m.actions.runMiner([],Ie.map(C=>C.id),p);M&&Ge(M.id)}finally{Ke(!1)}}async function yn(){_e&&await m.actions.cancelMinerRun(_e)}function Nn(p){const M=new Set(p.evidence.flatMap(B=>B.sourceRefIds)),C=x.filter(B=>M.has(B.id)).map(B=>B.sessionId);ge(new Set(C)),E(p.id),f(p.title),Z(!0),N("evidence")}async function kn(){ye(!0),Ne(null);try{const p=await bn(),M=A?.request.sourceIds.length===0?A.request.createImproveRunId:null;if(A&&!M&&Ue&&!["cancelled","failed","ready"].includes(A.state)){const B=A;await m.actions.cancelCreation(B.id)}const C=await m.actions.startCreation(p.map(B=>B.id),{surface:J==="automated"?"task_candidate":"training_page",mode:"defaults",entryMode:J??"manual",resourceIntent:d,objective:L.trim()||void 0,methodHint:null,preferredBaseModel:Be?Ct:null,candidateId:Q,analysisModel:{providerId:H,modelId:O},analysisReasoningEffort:re,createImproveRunId:M,targetIntent:k});if(!C)throw new Error("OpenPond could not start Taskset authoring.");q(C),Z(!1),C.state!=="awaiting_disclosure_approval"&&N("recommendation")}catch(p){Ne(p instanceof Error?p.message:String(p))}finally{ye(!1)}}async function Sn(){if(!(!A||A.state!=="awaiting_disclosure_approval")){ye(!0);try{const p=await m.actions.approveDisclosure(A.id,!0);if(!p)return;q(p),N("recommendation")}finally{ye(!1)}}}async function wn(){if(!(!A||A.state!=="failed")){ye(!0),Ne(null);try{const p=await m.actions.retryCreation(A.id);if(!p)throw new Error(m.error??"OpenPond could not retry Taskset authoring.");q(p),N("recommendation")}catch(p){Ne(p instanceof Error?p.message:String(p))}finally{ye(!1)}}}async function es(){A?.state==="awaiting_disclosure_approval"&&await m.actions.approveDisclosure(A.id,!1),q(null),Z(!0)}function Cn(){v==="base_model"?N("start"):v==="existing_dataset"?N("base_model"):v==="automatic_scope"?N(Be?"base_model":"start"):v==="automatic_candidates"?N("automatic_scope"):v==="evidence"?(A?.state==="awaiting_disclosure_approval"&&es(),N(J==="automated"?"automatic_candidates":Be?"base_model":"start")):v==="recommendation"&&N("evidence")}async function ot(){const p=A;p&&!["cancelled","failed","ready"].includes(p.state)&&await m.actions.cancelCreation(p.id),a()}async function In(){if(!(!A||A.state!=="awaiting_materialization_approval")){Ne(null);try{const p=await m.actions.materialize(A.id,!0);if(!p)throw new Error("OpenPond could not materialize the approved Taskset.");q(p),p.state==="ready"&&await r(p)}catch(p){Ne(p instanceof Error?p.message:String(p))}}}return e.jsxs("div",{className:"training-dialog-backdrop",role:"presentation",onMouseDown:()=>{ot()},children:[e.jsxs("section",{ref:De,className:`training-dialog training-run-dialog ${v==="start"?"training-run-start-step":"training-run-workflow-step"}`,role:"dialog","aria-modal":"true","aria-label":cs(k,d),onKeyDown:p=>{p.key==="Escape"&&(p.preventDefault(),ot())},onMouseDown:p=>p.stopPropagation(),children:[e.jsxs("div",{className:"training-dialog-header",children:[e.jsxs("div",{className:"training-run-dialog-title",children:[v!=="start"?e.jsx("button",{className:"training-icon-button","data-autofocus":!0,type:"button","aria-label":Ia(v,Be,J),onClick:Cn,children:e.jsx(Ds,{size:16})}):null,e.jsx("h2",{children:v==="recommendation"?Ca(k,d):cs(k,d)})]}),e.jsx("button",{className:"training-icon-button",type:"button","aria-label":"Close",onClick:()=>{ot()},children:e.jsx(Ve,{size:16})})]}),v==="start"?e.jsx(Na,{allowExistingDataset:Be&&!!l,mode:R,targetLabel:us(k,d),onChange:cn,onContinue:un}):v==="base_model"?e.jsx(ra,{busy:m.busyAction==="scan-base-models",candidates:y,value:_,onChange:ce,onContinue:Zt,onManage:()=>it(!0),onScan:()=>{m.actions.scanBaseModels()}}):v==="existing_dataset"?e.jsx(ua,{busy:He,selectedTasksetId:$,state:m.payload,onChange:se,onCreate:()=>{hn()}}):v==="automatic_scope"?e.jsx(na,{chatPreview:Ie.slice(0,6).map(p=>({id:p.id,title:p.title,updatedAt:p.updatedAt})),chatCount:Ie.length,config:b,estimate:dn,onCancel:()=>{yn()},onConfigChange:G,onScan:()=>{vn()},run:ze,scanning:ln}):v==="automatic_candidates"?e.jsx(sa,{candidates:Ae,onRescan:()=>{Ge(null),N("automatic_scope")},onSelect:Nn}):v==="evidence"&&J?e.jsx(va,{authoringModel:O,authoringProvider:H,authoringReasoningEffort:re,busy:He,disclosurePending:A?.state==="awaiting_disclosure_approval",estimatesBySessionId:w,matchingSessionCount:X,mode:J,objective:L,onObjectiveChange:mn,onAnalyze:()=>{kn()},onApproveDisclosure:()=>{Sn()},onAuthoringModelChange:gn,onAuthoringProviderChange:pn,onAuthoringReasoningEffortChange:xn,onDeclineDisclosure:()=>{es()},onSearchChange:z,onLoadMore:()=>{rn()},onReturnToRecommendation:()=>N("recommendation"),onToggleSession:jn,onToggleVisible:fn,providerSettings:u,recommendationAvailable:!!A?.proposal&&!Ue,search:Y,searchError:Ce,searchHasMore:oe,searchIndexedChats:te,searchIndexing:D,searchLoading:he,searchTotalChats:Te,selectedEntries:St,selectedEstimate:on,selectedSessionIds:ve,targetLabel:us(k,d),visibleSessions:ae}):v==="recommendation"&&A?.proposal?e.jsx(ba,{busy:He,creation:A,onAddChats:()=>N("evidence"),onClose:()=>{ot()},onCreateTaskset:()=>{In()},onCreationChange:q,sources:x,training:m,createLabel:d==="dataset"?"Create Dataset":k.kind==="model"?"Create model":void 0,editDataLabel:d==="dataset"?"Edit sources":k.kind==="model"?"Edit Dataset":void 0,resourceIntent:d}):v==="recommendation"&&A?.state==="awaiting_questions"?e.jsxs("div",{className:"training-evidence-required",children:[e.jsx("div",{className:"training-dialog-scroll-body",children:e.jsxs("div",{className:"training-run-step-heading",children:[e.jsx("h3",{children:"More evidence is needed"}),e.jsx("p",{children:A.blockingQuestions[0]?.prompt??A.blockedReason??"Add supporting evidence before authoring continues."})]})}),e.jsx("div",{className:"training-dialog-actions",children:e.jsx("button",{className:"training-button",type:"button",onClick:()=>N("evidence"),children:d==="dataset"?"Edit sources":k.kind==="model"?"Edit Dataset":"Add chats"})})]}):v==="recommendation"&&A?.state==="failed"?e.jsxs("div",{className:"training-evidence-required",children:[e.jsxs("div",{className:"training-dialog-scroll-body",children:[e.jsxs("div",{className:"training-run-step-heading",children:[e.jsx("h3",{children:"Analysis failed"}),e.jsx("p",{children:wa(A.blockedReason)})]}),L?e.jsxs("div",{className:"training-evidence-objective",children:[e.jsx("span",{children:"Capability"}),e.jsx("strong",{children:L})]}):null,e.jsx("p",{className:"training-empty",children:"Retry keeps the exact approved evidence, model, and disclosure receipt. Change evidence starts a new review if the selection is too large or no longer representative."})]}),e.jsxs("div",{className:"training-dialog-actions",children:[e.jsx("button",{className:"training-button secondary",type:"button",disabled:He,onClick:()=>N("evidence"),children:"Change evidence"}),e.jsxs("button",{className:"training-button",type:"button",disabled:He,onClick:()=>{wn()},children:[nt?e.jsx(fe,{className:"spin",size:14}):null,"Retry approved evidence"]})]})]}):e.jsx("div",{className:"training-recommendation-loading",children:A?.state==="failed"?e.jsxs(e.Fragment,{children:[e.jsx("h3",{children:"Analysis failed"}),e.jsx("p",{children:A.blockedReason})]}):e.jsxs(e.Fragment,{children:[e.jsx(fe,{className:"spin",size:18}),e.jsx("p",{children:"Preparing the recommendation…"})]})}),at?e.jsx("div",{className:"training-banner error",role:"alert",children:at}):null]}),le?e.jsx(c.Suspense,{fallback:e.jsx("div",{className:"training-dialog-backdrop training-compute-dialog-backdrop",children:e.jsx("section",{"aria-label":"Loading local model manager","aria-modal":"true",className:"training-dialog",role:"dialog",children:e.jsxs("div",{className:"training-dialog-header",children:[e.jsxs("div",{children:[e.jsx("h2",{children:"Manage local models"}),e.jsx("p",{children:"Loading compute inventory…"})]}),e.jsx(fe,{className:"spin",size:16})]})})}),children:e.jsx(ka,{connection:m.connection,onCandidatesChanged:m.refresh,onClose:()=>it(!1)})}):null]})}function Sa(t){return t?t.state==="awaiting_disclosure_approval"?"evidence":"recommendation":"start"}function ds(t,s,n){if(s){const a=t.find(l=>l.preference.modelId===s.modelId&&l.preference.source===s.source&&l.preference.revision===s.revision&&l.preference.modelAssetId===s.modelAssetId);if(a)return a}const i=s?.modelId??n;return i?t.find(a=>a.preference.modelId===i)??null:null}function wa(t){return t?t.trim().toLowerCase()==="terminated"?"OpenPond Chat closed the Taskset authoring stream before a proposal was returned. No Taskset was created.":t:"The authoring model did not return a proposal."}function cs(t,s){return s==="dataset"?"New Dataset":t.kind==="agent"?t.operation==="improve"?`Improve ${t.displayName??"agent"}`:"New agent":t.kind==="model"?"New model":"New change"}function us(t,s){return s==="dataset"?"dataset":t.kind==="agent"?"agent":t.kind==="model"?"model":"workproduct"}function Ca(t,s){return s==="dataset"?"Review Dataset":t.kind==="model"?"Review model":t.kind==="agent"?t.operation==="improve"?"Review agent change":"Review agent":"Review change"}function hs(t,s){let n=0,i=0,a=0;for(const l of t){const r=s[l];r&&(a+=1,n+=r.messageCount,i+=r.estimatedTokens)}return{messageCount:n,estimatedTokens:i,measuredChats:a}}function Ia(t,s,n){return t==="base_model"?"Back to setup":t==="existing_dataset"?"Back to base model":t==="automatic_scope"?s?"Back to base model":"Back to setup":t==="automatic_candidates"?"Back to scan scope":t==="evidence"?n==="automated"?"Back to repeated workflows":s?"Back to base model":"Back to setup":"Back to Dataset"}function Ma(){return{schemaVersion:"openpond.taskMinerConfig.v1",enabled:!1,localOnly:!0,observationWindowDays:30,minimumRecurrence:3,clustering:"hybrid_deterministic_first",consentRequired:!0}}function Ks({lineage:t,taskset:s,training:n,onChat:i,onClose:a}){const[l,r]=c.useState(!1),u=c.useMemo(()=>(n.payload?.servingSessions??[]).filter(k=>k.modelArtifactLineageId===t.id).sort((k,g)=>g.updatedAt.localeCompare(k.updatedAt)),[t.id,n.payload?.servingSessions])[0]??null,h=u&&["starting","ready","stopping"].includes(u.state)?u:null,d=!!n.busyAction;c.useEffect(()=>{!l||u?.state!=="ready"||(i(ft({modelId:t.id,taskset:s})),a())},[t.id,i,a,u?.state,l,s]);async function j(){r(!0),await n.actions.startModelServing(t.id)||r(!1)}async function x(k){r(!1),await n.actions.stopModelServing(k.id)}function m(){i(ft({modelId:t.id,taskset:s})),a()}return e.jsx("div",{className:"training-dialog-backdrop",role:"presentation",onMouseDown:d?void 0:a,children:e.jsxs("section",{"aria-label":`Use ${s.name}`,"aria-modal":"true",className:"training-dialog training-model-use-dialog",role:"dialog",onMouseDown:k=>k.stopPropagation(),children:[e.jsxs("div",{className:"training-dialog-header",children:[e.jsxs("div",{children:[e.jsx("h2",{children:"Use model"}),e.jsx("p",{children:s.name})]}),e.jsx("button",{"aria-label":"Close model use",disabled:d,type:"button",onClick:a,children:e.jsx(Ve,{size:16})})]}),e.jsxs("div",{className:"training-model-use-summary",children:[e.jsxs("div",{children:[e.jsx("span",{children:"Compute"}),e.jsx("strong",{children:"1× H100"})]}),e.jsxs("div",{children:[e.jsx("span",{children:"Rate"}),e.jsx("strong",{children:"$7.00/hour"})]}),e.jsxs("div",{children:[e.jsx("span",{children:"Idle stop"}),e.jsx("strong",{children:"5 minutes"})]}),e.jsxs("div",{children:[e.jsx("span",{children:"Hard stop"}),e.jsx("strong",{children:"10 minutes · $1.17 max"})]})]}),t.promotable?null:e.jsx("p",{className:"training-model-use-warning",children:"This run did not pass its frozen Eval. Chat is available for inspection, but the model cannot be promoted."}),u?e.jsx(Ra,{session:u}):e.jsx("p",{className:"training-model-use-note",children:"Start a temporary Fireworks deployment, attach this LoRA, then open a chat. OpenPond tears it down on idle, at the hard limit, or when you press Stop."}),n.error?e.jsx("div",{className:"training-banner error",children:n.error}):null,e.jsxs("div",{className:"training-dialog-actions",children:[h?e.jsx("button",{className:"training-button secondary",disabled:d||h.state==="stopping",type:"button",onClick:()=>{x(h)},children:h.state==="stopping"?"Stopping…":"Stop serving"}):e.jsx("button",{className:"training-button secondary",disabled:d,type:"button",onClick:a,children:"Cancel"}),u?.state==="ready"?e.jsxs("button",{className:"training-button",disabled:d,type:"button",onClick:m,children:[e.jsx(Bs,{size:14}),"Chat now"]}):h?.state==="starting"?e.jsxs("button",{className:"training-button",disabled:!0,type:"button",children:[e.jsx(fe,{className:"spin",size:14}),"Starting…"]}):e.jsxs("button",{className:"training-button",disabled:d,type:"button",onClick:()=>{j()},children:[d&&l?e.jsx(fe,{className:"spin",size:14}):null,"Start & chat"]})]})]})})}function Ra({session:t}){const s=t.state==="starting"?"Starting Fireworks serving":t.state==="ready"?"Ready to chat":t.state==="stopping"?"Stopping Fireworks serving":t.state==="stopped"?"Serving stopped":"Serving failed",n=`$${t.estimatedCostUsd.toFixed(4)}`;return e.jsxs("div",{className:`training-model-serving-status ${t.state}`,children:[e.jsxs("div",{children:[e.jsx("strong",{children:s}),e.jsxs("span",{children:["Estimated serving cost ",n]})]}),t.state==="starting"||t.state==="stopping"?e.jsx("div",{className:"training-model-serving-progress","aria-label":s,children:e.jsx("span",{})}):null,t.stoppedAt?e.jsxs("small",{children:["Stopped ",new Date(t.stoppedAt).toLocaleString(),t.stopReason?` · ${Aa(t.stopReason)}`:""]}):null,t.error?e.jsx("small",{className:"error",children:t.error}):null]})}function Aa(t){return t==="idle"?"idle limit":t==="duration"?"10-minute limit":t==="budget"?"cost limit":t==="restart_cleanup"?"app restart cleanup":t==="startup_error"?"startup error":t==="shutdown"?"app shutdown":"stopped by user"}const Ta=new Set(["planning","awaiting_questions","awaiting_plan_approval","paused","applying_source","running_checks","evaluating","awaiting_promotion","opening_pull_request","pull_request_open","reconciling_release","pushing_hosted","running_hosted_checks"]);function _a(t){const{connection:s,profileId:n}=t,[i,a]=c.useState([]),[l,r]=c.useState(!1),[o,u]=c.useState(null),h=c.useRef(null),d=c.useCallback(()=>{if(!s)return Promise.resolve(null);if(h.current)return h.current;r(!0);const x=et.listCreateImproveRuns(s,{profileId:n,limit:500}).then(m=>(a(m.runs),u(null),m.runs)).catch(m=>(u(m instanceof Error?m.message:String(m)),null)).finally(()=>{h.current===x&&(h.current=null),r(!1)});return h.current=x,x},[s,n]);c.useEffect(()=>{if(!s){a([]),u(null);return}d()},[s,n,d]);const j=c.useMemo(()=>i.some(x=>Ta.has(x.state)),[i]);return c.useEffect(()=>{if(!s)return;let x=!0,m=null;const k=async()=>{await d(),x&&(m=window.setTimeout(()=>{k()},j?1e3:15e3))};return m=window.setTimeout(()=>{k()},j?1e3:15e3),()=>{x=!1,m!==null&&window.clearTimeout(m)}},[s,j,d]),{runs:i,loading:l,error:o,refresh:d}}function me({title:t,actions:s,children:n}){return e.jsxs("section",{className:"training-detail-section",children:[e.jsxs("div",{className:"training-detail-section-heading",children:[e.jsx("h2",{children:t}),s?e.jsx("div",{children:s}):null]}),e.jsx("div",{className:"training-detail-section-panel",children:n})]})}const Ea=64,Pa=4096;function At(t,s=Pa){return Qn(t,{minimum:Ea,maximum:s})}const ms=["q_proj","k_proj","v_proj","o_proj","gate_proj","up_proj","down_proj"],$a="accounts/fireworks/models/qwen3-8b",Qe=3,dt=9.99,Tt=32768;function Da({baseModelCandidates:t,connection:s,taskset:n,modelId:i=null,destinations:a,initialMethod:l,preferredBaseModel:r=null,busy:o,onClose:u,onStart:h,onPrepare:d,onConfirmPrepared:j}){const x=n.readiness?.trainingPath??null,m=x?.primaryMethod??La(n),k=x?.bootstrap??null,g=Fa(n),y=l&&g.includes(l)?l:m==="grpo"?"grpo":"sft",S=Oa(t,r),v=S?.executionOptions.find(b=>b.available&&b.methods.includes(y))??null,N=a.find(b=>b.destinationId==="fireworks"&&b.available&&b.methods.includes(y)),R=v?.destinationId??N?.destinationId??a.find(b=>b.destinationId==="local_cpu_fixture"&&b.available)?.destinationId??a.find(b=>b.available&&b.destinationId!=="export")?.destinationId??"local_cpu_fixture",[T,J]=c.useState(R),[L,f]=c.useState(null),_=v?S:za(t,R,y),[ce,$]=c.useState(_?.selectionKey??""),[se,Q]=c.useState("automatic"),[E,H]=c.useState(()=>y==="grpo"?Math.min(10,Math.max(1,n.tasks.filter(b=>b.split==="train").length)):2),[ne,O]=c.useState(()=>At(n,R==="fireworks"?Tt:void 0)),[ie,re]=c.useState(R==="fireworks"?8:2),[W,Y]=c.useState(()=>gs(_?.preference.modelId??"")),[z,ae]=c.useState(!1),[K,X]=c.useState(Qe),[V,oe]=c.useState(7),[ue,he]=c.useState(8),[ee,Ce]=c.useState(4),[P,D]=c.useState(y),[de,te]=c.useState(null),be=a.find(b=>b.destinationId===T)??null,Te=P==="sft"&&m!=="sft"&&k?.method==="sft",I=n.learningSignals.demonstrations.filter(b=>b.approved).length,U=n.tasks.filter(b=>b.split==="frozen_eval").length,xe=c.useMemo(()=>L?.inventory?.devices.filter(b=>b.available)??[],[L?.inventory?.devices]),pe=c.useMemo(()=>L?.inventory?.models.filter(b=>b.trainingCompatible&&b.modelId&&b.revision&&b.tokenizerRevision&&b.chatTemplateHash)??[],[L?.inventory?.models]),ve=c.useMemo(()=>t.filter(b=>b.executionOptions.some(G=>G.destinationId===T&&G.methods.includes(P))),[t,T,P]),ge=ve.find(b=>b.selectionKey===ce)??null,w=ge?.executionOptions.find(b=>b.destinationId===T&&b.methods.includes(P))??null,F=ge?.preference.modelId??"",A=ge?.preference.modelAssetId?pe.find(b=>b.id===ge.preference.modelAssetId)??null:pe.find(b=>b.modelId===F)??null,q=T==="fireworks",Ue=!q||z&&K>=Qe&&K<=dt&&Number.isInteger(V)&&V>=1&&V<=30,Z=P==="sft"||P==="grpo"&&q,nt=n.capabilities.compatibleMethods.includes(P)||k?.method===P,ye=!!(n.readiness?.ready&&Z&&be?.available&&be.methods.includes(P)&&nt&&w?.available&&(ge?.preference.source!=="local"||A)&&Ue),at=n.readiness?.ready?Z?ge?w?.available?ge.preference.source==="local"&&!A?"The selected local model is no longer present in the verified compute inventory. Scan Compute and select it again.":be?.methods.includes(P)?be?.unavailableReason??(q&&!z?"Approve the bounded train-split export before launching Fireworks.":q&&(K<Qe||K>dt)?`Set a Fireworks cap from $${Qe.toFixed(2)} through $${dt.toFixed(2)}.`:q&&(!Number.isInteger(V)||V<1||V>30)?"Choose a provider retention record from 1 through 30 days.":null):`${ct(T)} does not execute ${P.toUpperCase()}.`:w?.unavailableReason??"The selected base model cannot run on this compute destination.":`Choose starting weights compatible with ${ct(T)} and ${P.toUpperCase()}.`:`${P.toUpperCase()} is the primary recommendation but no compatible execution backend is available here.${k?" Choose the optional SFT trajectory bootstrap to run the local precursor.":""}`:"The Taskset must pass environment, grader, and data readiness before training.",Ne=Ba({method:P,taskset:n,destinationId:T,baseModelId:F,maxSteps:E,sequenceLength:ne,rank:ie,learningRate:W,model:A,rolloutGroupSize:ue,rolloutConcurrency:ee}),Oe={exportApproved:q?z:!0,maximumCostUsd:q?K:0,retentionDays:q?V:null,region:null},Ke=JSON.stringify({modelId:i,destinationId:T,recipe:Ne,approval:Oe}),le=de?.configurationKey===Ke?de.value:null;c.useEffect(()=>{if(!s)return;let b=!0;return et.computeState(s).then(G=>{b&&(f(G),Q(G.settings.defaultDeviceIds[0]??"automatic"))}).catch(()=>{}),()=>{b=!1}},[s]);async function it(){if(!ye)return;if(q&&!le){const G=await d(T,Ne,Oe);G&&te({configurationKey:Ke,value:G});return}(q&&le?await j(le,K):await h(T,Ne,Oe))&&u()}function _e(b){if(J(b),$(G=>ps(t,G,b,P)),b==="fireworks"){re(8),P==="grpo"&&H(Math.min(10,Math.max(1,n.tasks.filter(G=>G.split==="train").length))),O(Math.max(512,At(n,Tt)));return}re(2),O(At(n))}function Ge(b){if(D(b),te(null),$(G=>ps(t,G,T,b)),b==="grpo"){H(Math.min(10,Math.max(1,n.tasks.filter(G=>G.split==="train").length)));return}H(2)}const Ae=le?.plan.estimatedCostUsd??null,Nt=o?le?"Launching…":q?"Preparing…":"Starting…":le&&Ae!=null?`Launch $${Ae.toFixed(2)} job`:q?"Prepare exact quote":"Start training";return e.jsx("div",{className:"training-dialog-backdrop",role:"presentation",onMouseDown:o?void 0:u,children:e.jsxs("section",{className:"training-dialog training-start-dialog",role:"dialog","aria-modal":"true","aria-label":"Start training",onMouseDown:b=>b.stopPropagation(),children:[e.jsxs("div",{className:"training-dialog-header",children:[e.jsxs("div",{children:[e.jsx("h2",{children:"Start training"}),e.jsx("p",{children:n.name})]}),e.jsx("button",{type:"button","aria-label":"Close start training",disabled:o,onClick:u,children:e.jsx(Ve,{size:16})})]}),e.jsx("div",{className:"training-method-tabs",role:"tablist","aria-label":"Training method",children:g.map(b=>e.jsxs("button",{"aria-selected":b===P,className:b===P?"active":"",disabled:o,role:"tab",type:"button",onClick:()=>Ge(b),children:[e.jsx("span",{children:Un(b)}),e.jsx("strong",{children:$e(b)})]},b))}),e.jsxs("div",{className:"training-start-fields",children:[e.jsxs("label",{children:[e.jsx("span",{children:"Base model"}),e.jsxs("select",{value:ce,disabled:o,onChange:b=>{const G=b.target.value,De=t.find(lt=>lt.selectionKey===G);$(G),Y(gs(De?.preference.modelId??""))},children:[e.jsx("option",{value:"",disabled:!0,children:"Choose compatible starting weights"}),ve.map(b=>{const G=b.executionOptions.find(De=>De.destinationId===T&&De.methods.includes(P));return e.jsxs("option",{value:b.selectionKey,disabled:!G?.available,children:[b.label," · ",b.sourceLabel,G?.available?"":` — ${G?.unavailableReason??"Unavailable"}`]},b.selectionKey)})]})]}),e.jsxs("label",{children:[e.jsx("span",{children:"Compute"}),e.jsx("select",{value:T,disabled:o,onChange:b=>_e(b.target.value),children:a.filter(b=>!["custom","runpod_byoc","export"].includes(b.destinationId)).map(b=>e.jsxs("option",{value:b.destinationId,disabled:!b.available,children:[ct(b.destinationId),b.available?"":` — ${b.unavailableReason??"Unavailable"}`]},b.destinationId))})]}),e.jsxs("label",{children:[e.jsx("span",{children:"Device"}),e.jsxs("select",{value:se,disabled:o||T!=="local_cpu_fixture",onChange:b=>Q(b.target.value),children:[e.jsx("option",{value:"automatic",children:"Automatic"}),xe.map(b=>e.jsx("option",{value:b.id,children:b.name},b.id))]})]})]}),q?e.jsxs("fieldset",{className:"training-provider-approval",children:[e.jsx("legend",{children:"Provider approval"}),e.jsxs("label",{className:"training-provider-consent",children:[e.jsx("input",{type:"checkbox",checked:z,disabled:o,onChange:b=>ae(b.target.checked)}),e.jsx("span",{children:"Export only the approved train split to Fireworks. Frozen Eval cases and grader secrets stay in OpenPond."})]}),e.jsxs("div",{className:"training-start-fields",children:[e.jsxs("label",{children:[e.jsx("span",{children:"Maximum provider spend (USD)"}),e.jsx("input",{"aria-label":"Maximum provider spend (USD)",type:"number",min:Qe,max:dt,step:.01,value:K,disabled:o,onChange:b=>X(b.target.valueAsNumber)})]}),e.jsxs("label",{children:[e.jsx("span",{children:"Retention record (days)"}),e.jsx("input",{"aria-label":"Retention record (days)",type:"number",min:1,max:30,step:1,value:V,disabled:o,onChange:b=>oe(b.target.valueAsNumber)})]})]}),e.jsx("p",{className:"training-start-note",children:"Approval is bound server-side to the signed-in OpenPond account at launch."}),P==="grpo"?e.jsxs("p",{className:"training-start-note",children:["RFT requires a public HTTPS callback ending in ",e.jsx("code",{children:"/v1/training/fireworks/rft"}),". Launch fails closed before provider upload when it is missing or invalid."]}):null]}):null,e.jsxs("dl",{className:"training-start-summary",children:[e.jsxs("div",{children:[e.jsx("dt",{children:"Training data"}),e.jsx("dd",{children:P==="grpo"?`${n.tasks.filter(b=>b.split==="train").length} approved train prompts`:`${I} approved example${I===1?"":"s"}`})]}),e.jsxs("div",{children:[e.jsx("dt",{children:"Evaluation"}),e.jsxs("dd",{children:[U," test example",U===1?"":"s"]})]}),e.jsxs("div",{children:[e.jsx("dt",{children:Ae==null?"Estimate":"Exact quote"}),e.jsx("dd",{children:T==="local_cpu_fixture"?A?`$0 · ${E} steps × ${ne} tokens · 15-minute hard stop`:"$0 · 2-minute hard stop":q?Ae==null?`Prepare a provider-validated quote · hard cap $${Number.isFinite(K)?K.toFixed(2):"—"}`:`$${Ae.toFixed(2)} · hard cap $${K.toFixed(2)}`:"Provided before approval"})]}),e.jsxs("div",{children:[e.jsx("dt",{children:"Storage"}),e.jsx("dd",{children:q?"Portable output imported into app-managed storage":L?.settings.modelStorePath??"App-managed local storage"})]})]}),le?e.jsxs("section",{className:"training-prepared-confirmation","aria-label":"Confirm paid training launch",children:[e.jsxs("div",{children:[e.jsx("strong",{children:"Ready to launch"}),e.jsx("span",{children:"The quote and prepared data are fixed to this confirmation."})]}),e.jsxs("dl",{className:"training-start-summary",children:[e.jsxs("div",{children:[e.jsx("dt",{children:"Account"}),e.jsx("dd",{children:le.approvalActor??"Local user"})]}),e.jsxs("div",{children:[e.jsx("dt",{children:"Provider"}),e.jsx("dd",{children:ct(le.plan.destinationId)})]}),e.jsxs("div",{children:[e.jsx("dt",{children:"Model"}),e.jsx("dd",{children:qa(le.plan.recipe.method==="sft"||le.plan.recipe.method==="grpo"?le.plan.recipe.baseModel.id:"")})]}),e.jsxs("div",{children:[e.jsx("dt",{children:"Method"}),e.jsxs("dd",{children:[$e(le.plan.recipe.method)," · ",le.plan.recipe.parameterization.toUpperCase()]})]}),e.jsxs("div",{children:[e.jsx("dt",{children:"Quote"}),e.jsx("dd",{children:Ae==null?"Unavailable":`$${Ae.toFixed(2)}`})]}),e.jsxs("div",{children:[e.jsx("dt",{children:"Maximum"}),e.jsxs("dd",{children:["$",K.toFixed(2)]})]}),e.jsxs("div",{children:[e.jsx("dt",{children:"Retention"}),e.jsxs("dd",{children:[le.plan.dataPolicy.retentionDays," days"]})]}),e.jsxs("div",{children:[e.jsx("dt",{children:"Prepared data"}),e.jsxs("dd",{children:[Va(le.bundle.totalSizeBytes)," · verified"]})]})]}),e.jsx("p",{children:"No Fireworks dataset or job exists until you launch."})]}):null,Te&&k?e.jsxs("div",{className:"training-bootstrap-limitations",children:[e.jsx("strong",{children:"Supervised precursor"}),e.jsx("p",{children:"This SFT run teaches the approved tool trajectories. It does not replace reinforcement training."}),e.jsx("ul",{children:k.limitations.map(b=>e.jsx("li",{children:b},b))})]}):null,e.jsxs("details",{className:"training-start-advanced",children:[e.jsx("summary",{children:"Advanced settings"}),e.jsxs("div",{className:"training-start-fields",children:[e.jsxs("label",{children:[e.jsx("span",{children:P==="grpo"?"Prompts per update":"Steps"}),e.jsx("input",{type:"number",min:1,max:1e3,value:E,onChange:b=>H(b.target.valueAsNumber||1)})]}),e.jsxs("label",{children:[e.jsx("span",{children:P==="grpo"?"Prompt length":"Sequence length"}),e.jsx("input",{type:"number",min:16,max:q?Tt:4096,value:ne,onChange:b=>O(b.target.valueAsNumber||64)})]}),e.jsxs("label",{children:[e.jsx("span",{children:"LoRA rank"}),e.jsx("input",{type:"number",min:1,max:256,value:ie,onChange:b=>re(b.target.valueAsNumber||2)})]}),e.jsxs("label",{children:[e.jsx("span",{children:"Learning rate"}),e.jsx("input",{type:"number",min:1e-6,max:.1,step:1e-4,value:W,onChange:b=>{const G=b.target.valueAsNumber;Number.isFinite(G)&&Y(G)}})]}),P==="grpo"?e.jsxs(e.Fragment,{children:[e.jsxs("label",{children:[e.jsx("span",{children:"Rollouts per prompt"}),e.jsx("input",{type:"number",min:2,max:16,value:ue,onChange:b=>he(b.target.valueAsNumber||8)})]}),e.jsxs("label",{children:[e.jsx("span",{children:"Concurrent rollouts"}),e.jsx("input",{type:"number",min:1,max:16,value:ee,onChange:b=>Ce(b.target.valueAsNumber||4)})]})]}):null]})]}),ye?be?.nonProduction?e.jsx("p",{className:"training-start-note",children:"This local worker is an experimental correctness run. It does not claim useful model quality."}):null:e.jsx("div",{className:"training-banner error training-dialog-error",children:at??"This setup is unavailable."}),e.jsxs("div",{className:"training-dialog-actions",children:[e.jsx("button",{className:"training-button secondary",type:"button",disabled:o,onClick:u,children:"Cancel"}),e.jsx("button",{className:"training-button",type:"button",disabled:o||!ye,onClick:()=>{it()},children:Nt})]})]})})}function Ba(t){return t.method==="grpo"&&t.destinationId==="fireworks"?{schemaVersion:"openpond.rftRecipe.v1",method:"grpo",parameterization:"lora",baseModel:{id:t.baseModelId,revision:"fireworks-managed-model-resource-v1",tokenizerRevision:"fireworks-provider-managed",chatTemplateHash:"fireworks-qwen3-chat-v1"},dataset:{trainSplit:"train",validationSplit:"frozen_eval",maxPromptTokens:t.sequenceLength},lora:{rank:t.rank},rollout:{groupSize:t.rolloutGroupSize,concurrency:t.rolloutConcurrency,maxTurns:15,maxOutputTokens:Math.min(2048,t.sequenceLength),temperature:.8,topP:.95,seed:17},optimizer:{learningRate:t.learningRate,maxSteps:t.maxSteps},reward:{graderId:"cross-system-exact-verifier",graderHash:"server-derived-grader-hash",environmentId:"cross-system-operations",environmentVersion:Dn,toolContractHash:$n},resourceLimits:{wallTimeMs:18e4,maxRollouts:Math.max(t.rolloutGroupSize,t.taskset.tasks.filter(s=>s.split==="train").length*t.rolloutGroupSize),maxPayloadBytes:1e6}}:t.destinationId==="fireworks"?{schemaVersion:"openpond.sftRecipe.v1",method:"sft",parameterization:"lora",baseModel:{id:t.baseModelId,revision:"fireworks-managed-model-resource-v1",tokenizerRevision:"fireworks-provider-managed",chatTemplateHash:"fireworks-qwen3-chat-v1"},dataset:{trainSplit:"train",validationSplit:"frozen_eval",completionOnly:!0,maxSequenceLength:t.sequenceLength},lora:{rank:t.rank,alpha:t.rank*2,dropout:.05,targetModules:ms},optimizer:{learningRate:t.learningRate,epochs:1,maxSteps:t.maxSteps,batchSize:1,gradientAccumulationSteps:1,seed:17},resourceLimits:{cpuThreads:1,memoryBytes:1e9,wallTimeMs:36e5}}:!t.model?.modelId||!t.model.revision||!t.model.tokenizerRevision||!t.model.chatTemplateHash?{schemaVersion:"openpond.sftRecipe.v1",method:"sft",parameterization:"lora",baseModel:{id:"openpond/tiny-cpu-gpt2-fixture",revision:"architecture-v2-seed-17-context-512",tokenizerRevision:"wordlevel-v1",chatTemplateHash:"fixture00000000"},dataset:{trainSplit:"train",validationSplit:"frozen_eval",completionOnly:!0,maxSequenceLength:t.sequenceLength},lora:{rank:t.rank,alpha:t.rank*2,dropout:0,targetModules:["c_attn"]},optimizer:{learningRate:t.learningRate,epochs:1,maxSteps:t.maxSteps,batchSize:1,gradientAccumulationSteps:1,seed:17},resourceLimits:{cpuThreads:4,memoryBytes:2e9,wallTimeMs:12e4}}:{schemaVersion:"openpond.sftRecipe.v1",method:"sft",parameterization:"lora",baseModel:{id:t.model.modelId,revision:t.model.revision,tokenizerRevision:t.model.tokenizerRevision,chatTemplateHash:t.model.chatTemplateHash},dataset:{trainSplit:"train",validationSplit:"frozen_eval",completionOnly:!0,maxSequenceLength:t.sequenceLength},lora:{rank:t.rank,alpha:t.rank*2,dropout:.05,targetModules:ms},optimizer:{learningRate:t.learningRate,epochs:1,maxSteps:t.maxSteps,batchSize:1,gradientAccumulationSteps:1,seed:17},resourceLimits:{cpuThreads:4,memoryBytes:8e9,wallTimeMs:9e5}}}function ps(t,s,n,i){return t.find(l=>l.selectionKey===s)?.executionOptions.some(l=>l.destinationId===n&&l.methods.includes(i))?s:""}function gs(t){return t==="openpond/tiny-cpu-gpt2-fixture"?.01:2e-4}function La(t){const s=t.metadata.trainingMethod;return typeof s=="string"&&s!=="none"?s:t.readiness?.recommendedMethod&&t.readiness.recommendedMethod!=="none"?t.readiness.recommendedMethod:"sft"}function Fa(t){const s=new Set;for(const i of t.capabilities.compatibleMethods)(i==="sft"||i==="grpo")&&s.add(i);t.readiness?.trainingPath?.bootstrap?.method==="sft"&&s.add("sft"),t.readiness?.trainingPath?.primaryMethod==="grpo"&&s.add("grpo");const n=[];return s.has("sft")&&n.push("sft"),s.has("grpo")&&n.push("grpo"),n.length?n:["sft"]}function ct(t){return{export:"Export only",local_cpu_fixture:"Local CPU",local_cuda:"Local NVIDIA GPU",local_mlx:"Apple Silicon",ssh_gpu:"SSH GPU",prime_hosted:"Prime hosted",fireworks:"Fireworks",openpond_managed:"OpenPond managed"}[t]??t.replaceAll("_"," ")}function Oa(t,s){return s?t.find(n=>n.preference.modelId===s.modelId&&n.preference.source===s.source&&n.preference.revision===s.revision&&n.preference.modelAssetId===s.modelAssetId)??t.find(n=>n.preference.modelId===s.modelId)??null:null}function za(t,s,n){const i=t.filter(a=>a.executionOptions.some(l=>l.destinationId===s&&l.available&&l.methods.includes(n)));return s==="fireworks"?i.find(a=>a.preference.modelId===$a)??i[0]??null:i[0]??null}function qa(t){return t==="accounts/fireworks/models/qwen3-8b"?"Qwen3 8B · Fireworks managed LoRA":t==="accounts/fireworks/models/qwen3-0p6b"?"Qwen3 0.6B · Fireworks managed LoRA":t.split("/").at(-1)??t}function Va(t){return t==null?"size unknown":t<1024?`${t} B`:t<1024**2?`${(t/1024).toFixed(1)} KB`:`${(t/1024/1024).toFixed(0)} MB`}const Ua=new Set(["released","rejected","ready","ready_local","published_hosted","cancelled"]);function Gs(t){const s=new Map,n=Ka(t.runs,t.training),i=new Date(0).toISOString();for(const a of t.profile?.agents??[]){const l=Ee("agent",a.id);s.set(l,{key:l,kind:"agent",id:a.id,name:a.name||a.id,description:a.enabled?"Enabled Profile Agent":"Disabled Profile Agent",status:a.enabled?"Ready":"Disabled",updatedAt:t.profile?.lastCheck?.checkedAt??i,path:a.path,enabled:a.enabled,runIds:[],conversationId:null,tasksetId:null,frontierBaselineRunId:null,trainingRunCount:0,evaluationStatus:"not_run",useActionId:`${a.id}.chat`})}for(const a of t.profile?.skills??[]){const l=Ee("skill",a.name);s.set(l,{key:l,kind:"skill",id:a.name,name:a.name,description:a.description,status:a.validationStatus==="valid"?"Ready":a.validationStatus,updatedAt:i,path:a.path,enabled:a.enabled,runIds:[],conversationId:null,tasksetId:null,frontierBaselineRunId:null,trainingRunCount:0,evaluationStatus:"not_run",useActionId:null})}for(const a of Kn(t.training)){if(a.taskset.metadata.resourceIntent==="dataset"&&!a.latestPlan&&!a.localModel)continue;const l=t.runs.filter(h=>h.target.kind==="model"&&h.tasksetRef?.id===a.taskset.id).sort((h,d)=>d.updatedAt.localeCompare(h.updatedAt))[0]??null,r=l?.target.kind==="model"?n.get(l.id)??l.target.id??l.id:a.latestPlan?.modelId??a.taskset.id,o=Ee("model",r),u=s.get(o);s.set(o,{key:o,kind:"model",id:r,name:Lt(l?.target.displayName??a.name,"New model"),description:a.taskset.objective,status:a.status,updatedAt:a.updatedAt,path:`tasksets/${a.taskset.id}`,enabled:a.localModel?a.localModel.status==="imported"&&a.localModel.promotable:null,runIds:l?[...new Set([...u?.runIds??[],l.id])]:u?.runIds??[],conversationId:null,tasksetId:a.taskset.id,frontierBaselineRunId:null,trainingRunCount:Math.max(u?.trainingRunCount??0,a.runCount),evaluationStatus:a.latestJob?.metadata.frozenEvaluationComplete===!0?a.latestJob.metadata.frozenEvaluationThresholdPassed===!0?"passed":"failed":"not_run",useActionId:null})}for(const a of t.runs){if(a.target.kind==="configuration"||a.target.kind==="unselected"||a.target.kind==="model"&&!a.tasksetRef&&["cancelled","failed","rejected"].includes(a.state))continue;const l=a.target.kind,r=a.target.kind==="model"?n.get(a.id)??a.target.id??a.id:a.target.id??a.id,o=Ee(l,r),u=s.get(o),h=a.target.displayName??u?.name??Ja(a),d=l==="model"?Lt(h,"New model"):h;s.set(o,{key:o,kind:l,id:r,name:d,description:u?.description??a.objective,status:Qa(a),updatedAt:fs(u?.updatedAt,a.updatedAt),path:u?.path??a.plan?.sourcePlan[0]?.path??null,enabled:u?.enabled??null,runIds:[...new Set([...u?.runIds??[],a.id])],conversationId:a.scope.conversationId??u?.conversationId??null,tasksetId:a.target.kind==="model"?a.tasksetRef?.id??u?.tasksetId??null:null,frontierBaselineRunId:u?.frontierBaselineRunId??null,trainingRunCount:u?.trainingRunCount??0,evaluationStatus:Ya(a)??u?.evaluationStatus??"not_run",useActionId:u?.useActionId??null})}for(const a of t.training?.frontierBaselineRuns??[]){const l=Ha(a,t.runs);if(!l)continue;const r=[...s.values()].find(h=>h.runIds.includes(l));if(!r)continue;const o=r.tasksetId?t.training?.tasksets.find(h=>h.id===r.tasksetId)??null:null;if(o&&!Ga(a,o))continue;const u=r.frontierBaselineRunId?t.training?.frontierBaselineRuns.find(h=>h.id===r.frontierBaselineRunId)??null:null;u&&u.updatedAt>=a.updatedAt||s.set(r.key,{...r,updatedAt:fs(r.updatedAt,a.updatedAt),frontierBaselineRunId:a.id})}return[...s.values()].sort((a,l)=>{const r=Number(xs(a,t.runs))-Number(xs(l,t.runs));return r!==0?-r:l.updatedAt.localeCompare(a.updatedAt)||a.name.localeCompare(l.name)})}function Ka(t,s){const n=new Map,i=s?.plans??[],a=s?.jobs??[],l=s?.models??[],r=new Map(i.map(h=>[h.id,h])),o=new Map(a.map(h=>[h.id,h])),u=new Map;for(const h of t){if(h.target.kind!=="model"||!h.tasksetRef)continue;const d=u.get(h.tasksetRef.id)??[];d.push(h),u.set(h.tasksetRef.id,d)}for(const[h,d]of u){const j=new Set;for(const g of i)g.tasksetId===h&&g.modelId&&j.add(g.modelId);for(const g of l)g.tasksetId===h&&g.modelId&&j.add(g.modelId);if(j.size>1)continue;const x=d.filter(g=>g.target.kind!=="model"?!1:g.target.trainingPlanId||g.target.trainingJobId||g.target.artifactId?!0:i.some(y=>y.tasksetId===h&&y.modelId===(g.target.id??g.id)));if(!x.length)continue;const k=[...j][0]??null??[...x].sort((g,y)=>y.updatedAt.localeCompare(g.updatedAt))[0].target.id??x[0].id;for(const g of x){if(g.target.kind!=="model")continue;const y=(g.target.trainingPlanId?r.get(g.target.trainingPlanId):null)??(g.target.trainingJobId?r.get(o.get(g.target.trainingJobId)?.planId??""):null);y?.modelId&&y.modelId!==k||n.set(g.id,k)}}return n}function Ga(t,s){if(["queued","running","cancelling"].includes(t.status))return!0;const n=new Set(s.sourceRefs.map(i=>i.id));return t.sourceIds.length===n.size&&t.sourceIds.every(i=>n.has(i))}function Ha(t,s){if(t.createImproveRunId&&s.some(i=>i.id===t.createImproveRunId&&i.target.kind==="model"))return t.createImproveRunId;if(t.sourceIds.length===0)return null;const n=new Set(t.sourceIds);return s.find(i=>i.target.kind==="model"&&[...n].every(a=>i.sourceRefs.includes(a)))?.id??null}function Ee(t,s){return`${t}:${s}`}function Wa(t){return t==="agent"?"Agents":t==="skill"?"Skills":t==="extension"?"Extensions":"Models"}function Hs(t,s){const n=new Set(t.runIds);return s.filter(i=>n.has(i.id)).sort((i,a)=>a.updatedAt.localeCompare(i.updatedAt))}function xs(t,s){const n=new Set(t.runIds);return s.some(i=>n.has(i.id)&&!Ua.has(i.state))}function Ja(t){return`${t.operation==="improve"?"Improve":"Create"} ${t.target.kind}`}function Qa(t){return t.state.replaceAll("_"," ")}function Ya(t){const s=t.evaluationReceipts.filter(n=>n.subject==="candidate"||n.subject==="post_release");return s.length?s.some(n=>n.status==="failed"||n.status==="blocked"||n.publishGate==="failed")?"failed":s.every(n=>n.status==="passed"&&n.publishGate!=="failed")?"passed":null:null}function fs(t,s){return t&&t.localeCompare(s)>=0?t:s}function Xa({agentId:t,evals:s,onAttach:n,onCreate:i}){const a=c.useMemo(()=>s.filter(o=>o.agentId===null||o.agentId===t),[t,s]),[l,r]=c.useState(a[0]?.id??"");return c.useEffect(()=>{a.some(o=>o.id===l)||r(a[0]?.id??"")},[a,l]),e.jsxs("div",{className:"labs-eval-actions",children:[e.jsxs("button",{className:"training-button secondary",type:"button",onClick:i,children:[e.jsx(Ls,{size:13}),"Create Eval"]}),a.length?e.jsxs(e.Fragment,{children:[e.jsx(Ft,{compact:!0,searchable:!0,label:"Existing Eval",options:a.map(o=>({value:o.id,label:o.name,shortLabel:o.name,description:o.path})),value:l,onChange:r}),e.jsx("button",{className:"training-button secondary",disabled:!l,type:"button",onClick:()=>n(l),children:"Attach"})]}):null]})}function je({label:t,value:s=t}){return e.jsx("span",{className:`labs-status-badge ${Ws(s)}`,children:t})}function Ws(t){const s=t.trim().toLowerCase().replaceAll("_"," ");return s.includes("ready")||s.includes("passed")||s.includes("succeeded")||s.includes("published")||s.includes("released")||s.includes("merged")||s.includes("imported")?"positive":s.includes("planning")||s.includes("applying")||s.includes("running")||s.includes("evaluating")||s.includes("pushing")?"info":s.includes("awaiting")||s.includes("paused")||s.includes("pr open")||s.includes("blocked")||s.includes("review")||s.includes("dirty")||s.includes("pending")?"warning":s.includes("failed")||s.includes("rejected")||s.includes("closed")||s.includes("error")||s.includes("disabled")?"negative":"neutral"}function zt({decorative:t=!1,label:s,size:n="default",tone:i,value:a=s}){return e.jsx("span",{"aria-hidden":t||void 0,"aria-label":t?void 0:s,className:`labs-status-dot ${i??Ws(a)} ${n}`,role:t?void 0:"status",title:s})}function Za({candidate:t,diff:s,error:n,run:i,onApplyCandidate:a,onOpenFiles:l,onRejectCandidate:r}){const[o,u]=c.useState(null),d=c.useMemo(()=>i.evaluationReceipts.filter(y=>y.candidateId===t.id),[t.id,i.evaluationReceipts]).filter(y=>y.subject==="candidate"),x=d.length>0&&d.every(y=>y.status==="passed"&&y.publishGate!=="failed")&&(i.state==="awaiting_promotion"||i.state==="blocked"&&!!i.localProfileCommit),m=i.state==="reconciling_release",k=s?.filesChanged??t.git?.changedPaths.length??0;async function g(y,S){if(!o){u(y);try{await S()}finally{u(null)}}}return e.jsxs("div",{className:"labs-change-page",children:[e.jsxs("dl",{className:"labs-change-facts",children:[e.jsx(_t,{label:"Base",value:js(t.git?.baseCommit)}),e.jsx(_t,{label:"Change",value:js(t.git?.headCommit)}),e.jsx(_t,{label:"Branch",value:t.git?.branch??"—"})]}),i.blockedReason?e.jsx("div",{className:"labs-change-message negative",children:i.blockedReason}):null,e.jsxs("div",{className:"labs-change-timeline",children:[e.jsx("article",{className:"labs-change-timeline-item",children:e.jsxs("div",{className:"labs-change-card",children:[e.jsx("header",{className:"labs-change-card-header",children:e.jsx("span",{className:"labs-change-timeline-label",children:"Request"})}),e.jsxs("div",{className:"labs-change-card-body",children:[e.jsx("h3",{children:i.objective}),e.jsx("p",{children:"This is the behavior the candidate is trying to improve."})]})]})}),e.jsx("article",{className:"labs-change-timeline-item",children:e.jsxs("div",{className:"labs-change-card",children:[e.jsxs("header",{className:"labs-change-card-header",children:[e.jsx("span",{className:"labs-change-timeline-label",children:"Changes"}),e.jsx("span",{children:qt(k)})]}),e.jsxs("div",{className:"labs-change-card-body",children:[e.jsx("h3",{children:"Drafted candidate"}),e.jsx("p",{children:ei(t,s,n)})]}),e.jsx("footer",{className:"labs-change-card-footer end",children:e.jsx("button",{className:"training-button secondary",disabled:!!n,title:n??void 0,type:"button",onClick:l,children:n?"Files unavailable":`Files${k?` (${k})`:""}`})})]})}),e.jsx("article",{className:"labs-change-timeline-item",children:e.jsxs("div",{className:"labs-change-card",children:[e.jsxs("header",{className:"labs-change-card-header",children:[e.jsx("span",{className:"labs-change-timeline-label",children:"Evals"}),e.jsx("span",{children:ti(d)})]}),e.jsx("div",{className:"labs-change-evals",children:d.length?d.map(y=>e.jsxs("div",{className:"labs-change-eval",children:[e.jsxs("div",{children:[e.jsx("strong",{children:y.summary??"Candidate Evals"}),e.jsxs("span",{children:[y.summaryCounts?`${y.summaryCounts.passed}/${y.summaryCounts.total} passed`:y.status," · ","publish gate ",y.publishGate.replaceAll("_"," ")]})]}),e.jsx(je,{label:y.status,value:y.status})]},y.id)):e.jsx("div",{className:"labs-change-empty",children:"Candidate Evals have not finished yet."})})]})}),e.jsx("article",{className:"labs-change-timeline-item",children:e.jsxs("div",{className:"labs-change-card",children:[e.jsx("header",{className:"labs-change-card-header",children:e.jsx("span",{className:"labs-change-timeline-label",children:"Merge"})}),e.jsxs("div",{className:"labs-change-card-body",children:[e.jsx("h3",{children:"Apply this change to the Profile"}),e.jsx("p",{children:"Merging creates a local Git commit and then runs the active Agent Evals again."})]}),e.jsxs("footer",{className:"labs-change-card-footer",children:[e.jsxs("span",{className:"labs-change-footer-status",children:[e.jsx(zt,{label:bs(i),value:i.state}),bs(i)]}),e.jsxs("div",{className:"labs-change-actions",children:[e.jsx("button",{className:"training-button secondary",disabled:!!o||m||i.state!=="awaiting_promotion",type:"button",onClick:()=>{g("reject",()=>r(i,t.id))},children:o==="reject"?"Rejecting":"Reject"}),e.jsx("button",{className:"training-button",disabled:!x||!!o||m,type:"button",onClick:()=>{g("apply",()=>a(i,t.id))},children:m||o==="apply"?"Merging":i.state==="blocked"?"Re-run Evals":"Merge change"})]})]})]})})]})]})}function _t({label:t,value:s}){return e.jsxs("div",{children:[e.jsx("dt",{children:t}),e.jsx("dd",{title:s,children:s})]})}function js(t){return t?t.slice(0,12):"—"}function qt(t){return`${t} ${t===1?"file":"files"}`}function ei(t,s,n){if(n)return n;const i=s?.filesChanged??t.git?.changedPaths.length??0;return i?s?`${qt(i)} drafted · +${s.additions} −${s.deletions}`:`${qt(i)} drafted in the candidate branch. Open Files to review the diff.`:"The candidate branch is ready, but no file summary is available yet."}function ti(t){if(!t.length)return"Waiting for candidate Evals";const s=t.reduce((i,a)=>({passed:i.passed+(a.summaryCounts?.passed??0),tests:i.tests+(a.summaryCounts?.total??0)}),{passed:0,tests:0});return s.tests>0?`${s.passed}/${s.tests} Evals passed`:`${t.filter(i=>i.status==="passed").length}/${t.length} Eval receipts passed`}function bs(t){return t.state==="awaiting_promotion"?"Ready to merge":t.state==="reconciling_release"?"Merging":t.state==="released"?"Merged":t.state==="rejected"?"Rejected":t.state==="blocked"?t.localProfileCommit?"Needs verification":"Blocked":t.state.replaceAll("_"," ")}function si({runs:t,onReview:s}){return t.length?e.jsx("div",{className:"training-table-wrap",children:e.jsxs("table",{className:"training-data-table labs-agent-change-history",children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{children:"Change"}),e.jsx("th",{children:"Status"}),e.jsx("th",{children:"Evals"}),e.jsx("th",{children:"Updated"})]})}),e.jsx("tbody",{children:t.map(n=>e.jsxs("tr",{children:[e.jsx("td",{children:e.jsxs("button",{type:"button",onClick:()=>s(n),children:[e.jsx("strong",{children:n.objective}),e.jsx("span",{children:ai(n)})]})}),e.jsx("td",{children:e.jsx(je,{label:n.state.replaceAll("_"," "),value:n.state})}),e.jsx("td",{children:ni(n)}),e.jsx("td",{children:vt(n.updatedAt)})]},n.id))})]})}):e.jsx("div",{className:"training-run-placeholder",children:"No changes yet."})}function ni(t){const s=[...t.candidates].reverse().find(a=>a.target.kind===t.target.kind);if(!s)return"—";const n=t.evaluationReceipts.filter(a=>a.candidateId===s.id&&a.subject==="candidate"),i=n.reduce((a,l)=>({passed:a.passed+(l.summaryCounts?.passed??0),tests:a.tests+(l.summaryCounts?.total??0)}),{passed:0,tests:0});return i.tests>0?`${i.passed}/${i.tests} passed`:n[0]?.status??"Not run"}function ai(t){return`${`${t.target.kind[0].toUpperCase()}${t.target.kind.slice(1)}`} ${t.operation==="improve"?"improvement":"creation"}`}function ii({receipts:t}){const[s,n]=c.useState(!1);if(!t.length)return e.jsx("div",{className:"training-run-placeholder",children:"No on-policy rollout receipts were recorded for this run."});const i=[...t].sort((l,r)=>r.updatedAt.localeCompare(l.updatedAt)),a=s?i:i.slice(0,24);return e.jsxs("div",{className:"training-rollout-receipts",children:[t.length>24?e.jsxs("div",{className:"training-rollout-receipt-controls",children:[e.jsx("span",{children:s?`Showing all ${t.length} receipts`:`Showing latest ${a.length} of ${t.length} receipts`}),e.jsx("button",{className:"training-text-button",type:"button",onClick:()=>n(l=>!l),children:s?"Show latest 24":`Show all ${t.length}`})]}):null,a.map(l=>e.jsxs("details",{children:[e.jsxs("summary",{children:[e.jsx("span",{children:li(l.providerTrace.rolloutId)}),e.jsx("strong",{children:l.status}),e.jsx("em",{children:l.reward.eligible&&l.reward.raw!=null?l.reward.raw.toFixed(3):l.failureClass??"not reward eligible"})]}),e.jsxs("dl",{className:"training-configuration-list",children:[e.jsx(Me,{label:"Correlation",value:l.correlationId}),e.jsx(Me,{label:"Task",value:l.taskId}),e.jsx(Me,{label:"Policy",value:l.policy.modelId}),e.jsx(Me,{label:"Checkpoint",value:l.policy.checkpointId??"Provider initial policy"}),e.jsx(Me,{label:"Environment",value:`${l.environment.id}@${l.environment.version}`}),e.jsx(Me,{label:"World",value:`${l.environment.worldId} · ${l.environment.worldHash}`}),e.jsx(Me,{label:"Raw reward",value:l.reward.raw==null?"Not eligible":String(l.reward.raw)}),e.jsx(Me,{label:"Components",value:JSON.stringify(l.reward.components)}),e.jsx(Me,{label:"Outcome",value:l.verifier?.outcome??l.failureClass??"Pending"}),e.jsx(Me,{label:"Trace",value:`${l.providerTrace.experimentId}/${l.providerTrace.rolloutId}`})]})]},l.id))]})}function Me({label:t,value:s}){return e.jsxs("div",{children:[e.jsx("dt",{children:t}),e.jsx("dd",{children:s})]})}function li(t){return t.replace(/^lineage_/,"").slice(0,18)}function ri({detail:t,loading:s}){if(s&&!t)return e.jsx("div",{className:"training-run-placeholder",children:"Loading evaluation results…"});const n=t?.evaluation;return n?e.jsxs("div",{className:"training-run-evaluation",children:[e.jsxs("div",{className:"training-metric-summary",children:[e.jsx(ut,{label:"Base score",value:vs(n.base.meanScore)}),e.jsx(ut,{label:"Trained score",value:vs(n.trained.meanScore)}),e.jsx(ut,{label:"Score change",value:ci(n.meanScoreDelta)}),e.jsx(ut,{label:"Trained pass rate",value:di(n.trained.passRate)})]}),n.base.count===0?e.jsx("p",{className:"training-muted",children:"Base-model scoring was not imported for this earlier run. New runs retain both base and trained evaluations."}):null,n.trained.count>0&&n.trained.scoredCount===0?e.jsx("p",{className:"training-muted",children:"Outputs were captured, but the grader was unavailable, so this run has no evaluation score."}):null,e.jsx("div",{className:"training-table-wrap",children:e.jsxs("table",{className:"training-data-table training-evaluation-table",children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{children:"Test example"}),e.jsx("th",{children:"Base"}),e.jsx("th",{children:"Trained"}),e.jsx("th",{children:"Result"})]})}),e.jsx("tbody",{children:n.examples.map(i=>e.jsxs("tr",{children:[e.jsx("td",{children:e.jsxs("details",{children:[e.jsx("summary",{children:i.taskId}),e.jsx(oi,{input:i.input,baseOutput:i.baseOutput,trainedOutput:i.trainedOutput,baseGrade:i.baseGrade,trainedGrade:i.trainedGrade})]})}),e.jsx("td",{children:ys(i.baseGrade)}),e.jsx("td",{children:ys(i.trainedGrade)}),e.jsx("td",{children:ui(i.baseGrade,i.trainedGrade)})]},i.taskId))})]})})]}):e.jsx("div",{className:"training-run-placeholder",children:"No scored evaluation results are available for this run."})}function oi({input:t,baseOutput:s,trainedOutput:n,baseGrade:i,trainedGrade:a}){const l=[...new Set([...i?.feedback??[],...a?.feedback??[]])];return e.jsxs("div",{className:"training-evaluation-output",children:[e.jsxs("div",{children:[e.jsx("span",{children:"Input"}),e.jsx("pre",{children:JSON.stringify(t,null,2)})]}),s?e.jsxs("div",{children:[e.jsx("span",{children:"Base output"}),e.jsx("pre",{children:JSON.stringify(s,null,2)})]}):null,n?e.jsxs("div",{children:[e.jsx("span",{children:"Trained output"}),e.jsx("pre",{children:JSON.stringify(n,null,2)})]}):null,l.length?e.jsxs("div",{children:[e.jsx("span",{children:"Grader feedback"}),e.jsx("p",{children:l.join(" ")})]}):null]})}function ut({label:t,value:s}){return e.jsxs("div",{children:[e.jsx("span",{children:t}),e.jsx("strong",{children:s})]})}function vs(t){return t==null?"Not recorded":t.toFixed(3)}function di(t){return t==null?"Not recorded":`${Math.round(t*100)}%`}function ci(t){return t==null?"Not comparable":`${t>=0?"+":""}${t.toFixed(3)}`}function ys(t){return t?.status==="unavailable"?"Unavailable":t?.score==null?"Not scored":t.score.toFixed(3)}function ui(t,s){if(!s)return"Not evaluated";if(s.status==="unavailable")return"Unavailable";if(!t||t.score==null||s.score==null)return s.passed?"Passed":"Failed";const n=s.score-t.score;return Math.abs(n)<5e-4?"No change":n>0?`Improved ${n.toFixed(3)}`:`Regressed ${Math.abs(n).toFixed(3)}`}const Ns=[{key:"loss",label:"Loss",format:Re},{key:"reward",label:"Reward",format:Re},{key:"policyLoss",label:"Policy loss",format:Re},{key:"advantageLoss",label:"Advantage loss",format:Re},{key:"learningRate",label:"Learning rate",format:bi},{key:"gradientNorm",label:"Gradient norm",format:Re},{key:"meanTokenAccuracy",label:"Token accuracy",format:vi},{key:"entropy",label:"Entropy",format:Re},{key:"memoryBytes",label:"Memory",format:Js}];function hi({detail:t,loading:s,error:n}){const i=c.useMemo(()=>fi(t?.stepMetrics??[]),[t?.stepMetrics]),a=c.useMemo(()=>Ns.filter(m=>i.some(k=>k[m.key]!=null)),[i]),[l,r]=c.useState("loss"),o=a.find(m=>m.key===l)??a[0]??Ns[0],u=i.flatMap(m=>m[o.key]==null?[]:[{step:m.step,value:m[o.key]}]),h=t?pi(t):{};if(s&&!t)return e.jsx("div",{className:"training-run-placeholder",children:"Loading training metrics…"});if(n&&!t)return e.jsx("div",{className:"training-run-placeholder error",children:n});if(!t)return e.jsx("div",{className:"training-run-placeholder",children:"Select a training run to inspect its metrics."});const d=t.job.metadata.trainingMethod==="grpo",j=i.flatMap(m=>m.reward==null?[]:[m.reward]),x=i.flatMap(m=>m.loss==null?[]:[m.loss]);return e.jsxs("div",{className:"training-run-metrics",children:[e.jsxs("div",{className:"training-metric-summary",children:[e.jsx(Le,{label:d?"Optimizer updates":"Steps",value:d?xi(t,i):h.steps??gi(i)}),d?e.jsxs(e.Fragment,{children:[e.jsx(Le,{label:"Latest reward",value:j.length?Re(j.at(-1)):null}),e.jsx(Le,{label:"Best reward",value:j.length?Re(Math.max(...j)):null}),e.jsx(Le,{label:"Recorded points",value:j.length||null})]}):e.jsxs(e.Fragment,{children:[e.jsx(Le,{label:"Final loss",value:h.trainLoss==null?x.at(-1)==null?null:Re(x.at(-1)):Re(h.trainLoss)}),e.jsx(Le,{label:"Peak memory",value:ji(t.stepMetrics)}),e.jsx(Le,{label:"Adapter parameters",value:h.adapterParameterCount==null?null:h.adapterParameterCount.toLocaleString()})]})]}),a.length?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"training-metric-tabs",role:"tablist","aria-label":"Training metrics",children:a.map(m=>e.jsx("button",{type:"button",role:"tab","aria-selected":m.key===o.key,className:m.key===o.key?"active":"",onClick:()=>r(m.key),children:m.label},m.key))}),e.jsx(mi,{label:o.label,points:u,format:o.format})]}):e.jsx("div",{className:"training-run-placeholder",children:"This earlier run recorded its final result but not per-step Trainer logs."})]})}function mi({label:t,points:s,format:n}){const l={top:20,right:20,bottom:58,left:64},r=s.map(v=>v.value),o=Math.min(...r),u=Math.max(...r),h=u-o||Math.max(Math.abs(u)*.1,1e-9),d=o-h*.08,j=u+h*.08,x=s[0]?.step??0,m=s.at(-1)?.step??x+1,k=Math.max(1,m-x),g=v=>l.left+(v-x)/k*(760-l.left-l.right),y=v=>l.top+(j-v)/(j-d)*(270-l.top-l.bottom),S=s.map((v,N)=>`${N?"L":"M"}${g(v.step).toFixed(2)},${y(v.value).toFixed(2)}`).join(" ");return e.jsx("figure",{className:"training-line-chart","aria-label":`${t} by optimizer step`,children:e.jsxs("svg",{viewBox:"0 0 760 270",role:"img","aria-labelledby":`metric-${t.replaceAll(" ","-")}`,children:[e.jsx("title",{id:`metric-${t.replaceAll(" ","-")}`,children:`${t} by optimizer step`}),[0,.25,.5,.75,1].map(v=>{const N=l.top+v*(270-l.top-l.bottom),R=j-v*(j-d);return e.jsxs("g",{children:[e.jsx("line",{className:"training-chart-grid",x1:l.left,x2:760-l.right,y1:N,y2:N}),e.jsx("text",{className:"training-chart-label",x:l.left-10,y:N+4,textAnchor:"end",children:n(R)})]},v)}),e.jsx("line",{className:"training-chart-axis",x1:l.left,x2:760-l.right,y1:270-l.bottom,y2:270-l.bottom}),e.jsx("path",{className:"training-chart-line",d:S}),s.map(v=>e.jsx("circle",{className:"training-chart-point",cx:g(v.step),cy:y(v.value),r:"3",children:e.jsx("title",{children:`Step ${v.step}: ${n(v.value)}`})},`${v.step}-${v.value}`)),e.jsx("text",{className:"training-chart-label",x:l.left,y:236,textAnchor:"middle",children:x}),e.jsx("text",{className:"training-chart-label",x:760-l.right,y:236,textAnchor:"middle",children:m}),e.jsx("text",{className:"training-chart-label axis-title",x:(l.left+760-l.right)/2,y:261,textAnchor:"middle",children:"Optimizer step"})]})})}function Le({label:t,value:s}){return e.jsxs("div",{children:[e.jsx("span",{children:t}),e.jsx("strong",{children:s??"Not recorded"})]})}function pi(t){const s=[...t.events].reverse().find(n=>n.type==="metric"&&n.payload.metricKind!=="sft_step"&&(typeof n.payload.trainLoss=="number"||typeof n.payload.steps=="number"));return Object.fromEntries(Object.entries(s?.payload??{}).filter(n=>typeof n[1]=="number"))}function gi(t){const s=t.at(-1);return s?`${s.step} of ${s.maxSteps}`:null}function xi(t,s){const n=t.job.metadata.optimizerUpdatesObserved,i=typeof n=="number"&&Number.isFinite(n)?n:0,a=s.at(-1)?.step??0;return Math.max(i,a)||null}function fi(t){const s=new Map;for(const n of t)s.set(n.step,n);return[...s.values()].sort((n,i)=>n.step-i.step)}function ji(t){const s=t.flatMap(n=>n.memoryBytes==null?[]:[n.memoryBytes]);return s.length?Js(Math.max(...s)):null}function Re(t){return new Intl.NumberFormat(void 0,{maximumFractionDigits:4}).format(t)}function bi(t){return t===0?"0":t.toExponential(2)}function vi(t){return`${(t*100).toFixed(1)}%`}function Js(t){return`${(t/1024**3).toFixed(2)} GB`}const yi=new Set(["queued","starting","running","cancelling","reconciling"]);function Ni(t,s,n){const[i,a]=c.useState(null),[l,r]=c.useState(!1),[o,u]=c.useState(null),h=c.useCallback(async()=>{if(!t||!s)return null;r(!0);try{const d=await et.trainingRunDetail(t,s);return a(d),u(null),d}catch(d){return u(d instanceof Error?d.message:String(d)),null}finally{r(!1)}},[t,s]);return c.useEffect(()=>{a(null),u(null),!(!t||!s)&&h()},[t,s,h]),c.useEffect(()=>{if(!t||!s||!n||!yi.has(n))return;const d=window.setInterval(()=>{h()},2e3);return()=>window.clearInterval(d)},[t,s,n,h]),{detail:i,error:o,loading:l,refresh:h}}function st(t,s,n){if(!n)return[];const i=s.filter(r=>r.target.kind==="model"&&r.target.id===t.id),a=new Set(i.flatMap(r=>r.target.kind==="model"&&r.target.trainingPlanId?[r.target.trainingPlanId]:[])),l=new Set(i.flatMap(r=>r.tasksetRef?[r.tasksetRef.id]:[]));return t.tasksetId&&l.add(t.tasksetId),n.plans.filter(r=>r.modelId===t.id||a.has(r.id)||r.modelId===null&&l.has(r.tasksetId)).sort((r,o)=>o.createdAt.localeCompare(r.createdAt))}function Ht(t,s,n){if(!n)return[];const i=new Set(st(t,s,n).map(a=>a.id));return n.jobs.filter(a=>i.has(a.planId)).sort((a,l)=>l.createdAt.localeCompare(a.createdAt))}function ki(t,s,n){if(!n)return[];const i=new Set(st(t,s,n).map(a=>a.tasksetId));for(const a of s)a.target.kind==="model"&&a.target.id===t.id&&a.tasksetRef&&i.add(a.tasksetRef.id);return t.tasksetId&&i.add(t.tasksetId),n.tasksets.filter(a=>i.has(a.id))}function qe(t,s,n){if(!n)return[];const i=st(t,s,n),a=new Map(i.map(d=>[d.id,d])),l=Ht(t,s,n),r=new Map(l.map(d=>[d.id,d])),o=Qs(t,s,n),u=new Set(l.map(d=>d.id));return n.models.filter(d=>d.modelId===t.id||u.has(d.jobId)).sort((d,j)=>d.importedAt.localeCompare(j.importedAt)).map((d,j)=>{const x=r.get(d.jobId)??null;return{lineage:d,number:j+1,job:x,plan:x?a.get(x.planId)??null:null,taskset:n.tasksets.find(m=>m.id===d.tasksetId)??null,current:o?.modelArtifactLineageId===d.id}}).sort((d,j)=>j.number-d.number)}function Qs(t,s,n){if(!n)return null;const i=new Set(s.flatMap(a=>a.target.kind==="model"&&a.target.id===t.id&&a.tasksetRef?[a.tasksetRef.id]:[]));return t.tasksetId&&i.add(t.tasksetId),n.modelBindings.filter(a=>a.status==="active"&&a.role==="chat_manual"&&(a.roleTargetId===t.id||i.has(a.roleTargetId))).sort((a,l)=>l.promotedAt.localeCompare(a.promotedAt))[0]??null}function Si({workproduct:t,runs:s,training:n,onOpenDataset:i,onOpenEntry:a,onToast:l}){const r=n.payload,o=c.useMemo(()=>Ht(t,s,r),[s,r,t]),u=c.useMemo(()=>qe(t,s,r),[s,r,t]),h=c.useMemo(()=>st(t,s,r),[s,r,t]),d=c.useMemo(()=>new Map(h.map(g=>[g.id,g])),[h]),j=c.useMemo(()=>Ys(o,u),[o,u]),x=Qs(t,s,r);async function m(g){const y=u.find(v=>v.lineage.id===g);if(!y?.lineage.promotable||!window.confirm(`Set Version ${y.number} as active for ${t.name}?`))return;const S=await n.actions.bindModel(y.lineage.id,"chat_manual",t.id);l(S?`Version ${y.number} is now active.`:"The active Version could not be changed.",S?"success":"error")}async function k(g,y){const S=await n.actions.setModelPinned(g,y);l(S?y?"Version pinned.":"Version unpinned.":"Version pin could not be changed.",S?"success":"error")}return j.length?e.jsx("section",{className:"labs-model-version-index","aria-label":"Versions",children:e.jsx("div",{className:"training-table-wrap",children:e.jsxs("table",{className:"training-data-table labs-model-versions-table",children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{children:"Version"}),e.jsx("th",{children:"Training"}),e.jsx("th",{children:"Dataset"}),e.jsx("th",{children:"Training status"}),e.jsx("th",{children:"Evaluation"}),e.jsx("th",{children:"Version status"}),e.jsx("th",{children:"Updated"}),e.jsx("th",{children:e.jsx("span",{className:"sr-only",children:"Actions"})})]})}),e.jsx("tbody",{children:j.map(g=>{const y=g.version?.plan??(g.job?d.get(g.job.planId)??null:null),S=g.version?.taskset??r?.tasksets.find(R=>R.id===y?.tasksetId)??null,v=g.version,N=v&&x?.modelArtifactLineageId===v.lineage.id;return e.jsxs("tr",{onClick:()=>a(g.key),children:[e.jsx("td",{children:e.jsxs("button",{className:"labs-version-row-button",type:"button",onClick:()=>a(g.key),children:[e.jsx("strong",{children:v?`Version ${v.number}`:"No output"}),e.jsx("small",{children:Ri(v?.lineage.id??g.job?.id??g.key)})]})}),e.jsx("td",{children:$e(y?.recipe.method)}),e.jsx("td",{children:S?e.jsx("button",{className:"labs-version-dataset-link",type:"button",onClick:R=>{R.stopPropagation(),i(S.id)},children:S.name}):"Unavailable"}),e.jsx("td",{children:e.jsx(je,{label:g.job?Gt(g.job.status):"Imported",value:g.job?.status??"completed"})}),e.jsx("td",{children:e.jsx(Ci,{version:v})}),e.jsx("td",{children:e.jsx(Ii,{version:v})}),e.jsx("td",{children:vt(v?.lineage.importedAt??g.job?.updatedAt??"")}),e.jsx("td",{children:v?e.jsxs("div",{className:"training-table-actions",children:[e.jsx("button",{"aria-pressed":v.lineage.pinned||!!N,className:"labs-version-icon-button",disabled:!!N,title:N?"The active Version stays pinned":v.lineage.pinned?"Unpin Version":"Pin Version",type:"button",onClick:R=>{R.stopPropagation(),k(v.lineage.id,!v.lineage.pinned)},children:e.jsx(Bn,{size:14})}),v.current?null:e.jsx("button",{className:"training-button secondary",disabled:!v.lineage.promotable,type:"button",onClick:R=>{R.stopPropagation(),m(v.lineage.id)},children:"Activate"}),e.jsx("button",{"aria-label":`Download Version ${v.number}`,className:"labs-version-icon-button",type:"button",onClick:R=>{R.stopPropagation(),n.actions.downloadModelPackage(v.lineage.id)},children:e.jsx(Kt,{size:14})})]}):null})]},g.key)})})]})})}):e.jsx("div",{className:"training-run-placeholder",children:"No training attempts yet."})}function wi({connection:t,selectedEntryKey:s,workproduct:n,runs:i,training:a,onBack:l,onOpenDataset:r,onUseVersion:o}){const u=a.payload,h=c.useMemo(()=>Ht(n,i,u),[i,u,n]),d=c.useMemo(()=>qe(n,i,u),[i,u,n]),j=c.useMemo(()=>st(n,i,u),[i,u,n]),x=c.useMemo(()=>new Map(j.map(T=>[T.id,T])),[j]),k=c.useMemo(()=>Ys(h,d),[h,d]).find(T=>T.key===s)??null,g=k?.job??null,y=k?.version??null,S=y?.plan??(g?x.get(g.planId)??null:null),v=y?.taskset??u?.tasksets.find(T=>T.id===S?.tasksetId)??null,N=Ni(t,g?.id??null,g?.status??null),R=g?u?.rolloutReceipts.filter(T=>T.jobId===g.id)??[]:[];return k?e.jsxs("div",{className:"labs-model-version-detail",children:[e.jsx("button",{className:"settings-secondary compact labs-model-version-back",type:"button",onClick:l,children:"Back to versions"}),e.jsxs(me,{title:y?`Version ${y.number}`:`${$e(S?.recipe.method)} attempt`,actions:y?e.jsxs("div",{className:"training-table-actions",children:[v?e.jsxs("button",{className:"training-button secondary",disabled:!y.lineage.promotable,title:y.lineage.promotable?"Chat with this Version":"Chat is unavailable because this Version did not pass evaluation.",type:"button",onClick:()=>o(y.lineage.id),children:[e.jsx(Bs,{size:14}),"Chat"]}):null,e.jsxs("button",{className:"training-button secondary",type:"button",onClick:()=>{a.actions.downloadModelPackage(y.lineage.id)},children:[e.jsx(Kt,{size:14}),"Download LoRA"]})]}):null,children:[e.jsxs("dl",{className:"labs-inline-facts",children:[e.jsx(ke,{label:"Training status",value:g?Gt(g.status):"Imported"}),e.jsx(ke,{label:"Version status",value:y?y.current?"Active":"Available":"Not created"}),e.jsx(ke,{label:"Training",value:$e(S?.recipe.method)}),e.jsx(ke,{label:"Base model",value:Mi(S)}),e.jsx(ke,{label:"Dataset",value:v?.name??"Unavailable"}),e.jsx(ke,{label:"Compute",value:S?ss(S.destinationId):g?ss(g.destinationId):"Not recorded"}),e.jsx(ke,{label:"Duration",value:g?Gn(g.startedAt,g.completedAt):"Not recorded"}),e.jsx(ke,{label:"Output",value:y?`Version ${y.number}`:"No Version"})]}),v?e.jsxs("button",{className:"labs-version-dataset-link labs-version-detail-dataset",type:"button",onClick:()=>r(v.id),children:["Open ",v.name]}):null,g?.error?e.jsx("p",{className:"labs-training-error",children:g.error}):null]}),g?e.jsxs(e.Fragment,{children:[e.jsx(me,{title:S?.recipe.method==="grpo"?"Rollout scores":"Training metrics",children:e.jsx(hi,{detail:N.detail,error:N.error,loading:N.loading})}),e.jsx(me,{title:"Evaluation",children:e.jsx(ri,{detail:N.detail,loading:N.loading})}),S?.recipe.method==="grpo"?e.jsx(me,{title:"Rollout traces",children:e.jsx(ii,{receipts:R})}):null]}):null,e.jsx(me,{title:"Configuration",children:e.jsxs("dl",{className:"training-configuration-list",children:[e.jsx(ke,{label:"Training attempt",value:g?.id??"Provider import"}),e.jsx(ke,{label:"Dataset",value:v?.name??"Unavailable"}),e.jsx(ke,{label:"Prepared data",value:g?.bundleHash??"Provider managed"}),e.jsx(ke,{label:"Version ID",value:y?.lineage.id??"No Version created"})]})})]}):e.jsxs("div",{className:"labs-model-version-detail",children:[e.jsx("button",{className:"settings-secondary compact",type:"button",onClick:l,children:"Back to versions"}),e.jsx("div",{className:"training-run-placeholder",children:"This training attempt is no longer available."})]})}function Ys(t,s){const n=new Map(s.flatMap(l=>l.job?[[l.job.id,l]]:[])),i=t.map(l=>({key:`job:${l.id}`,job:l,version:n.get(l.id)??null})),a=new Set(t.map(l=>l.id));for(const l of s)l.job&&a.has(l.job.id)||i.push({key:`version:${l.lineage.id}`,job:l.job,version:l});return i.sort((l,r)=>ks(r).localeCompare(ks(l)))}function ks(t){return t.version?.lineage.importedAt??t.job?.updatedAt??t.job?.createdAt??""}function Ci({version:t}){const s=t?t.lineage.promotable?"Passed":t.lineage.frozenEvaluationArtifactId?"Failed":"Not run":"No output",n=t?t.lineage.promotable?"passed":t.lineage.frozenEvaluationArtifactId?"failed":"not_run":"not_run";return e.jsx(je,{label:s,value:n})}function Ii({version:t}){return e.jsx(je,{label:t?t.current?"Active":"Available":"Not created",value:t?t.current?"current":"ready":"not_run"})}function Mi(t){return!t||t.recipe.method!=="sft"&&t.recipe.method!=="grpo"?"Not recorded":t.recipe.baseModel.id.split("/").at(-1)??t.recipe.baseModel.id}function Ri(t){return t.replace(/^(?:training_job_|lineage_)(?:fireworks_)?(?:artifact_)?/,"").slice(0,12)}function ke({label:t,value:s}){return e.jsxs("div",{children:[e.jsx("dt",{children:t}),e.jsx("dd",{children:s})]})}function Ai({state:t,initialTasksetId:s,onClose:n,onContinue:i}){const a=c.useMemo(()=>(t?.tasksets??[]).filter(x=>x.readiness?.ready).sort((x,m)=>m.updatedAt.localeCompare(x.updatedAt)),[t?.tasksets]),[l,r]=c.useState(s&&a.some(x=>x.id===s)?s:a[0]?.id??""),o=a.find(x=>x.id===l)??null,u=o?Ss(o):[],[h,d]=c.useState(o?.readiness?.recommendedMethod==="grpo"?"grpo":"sft"),j=u.includes(h)?h:u[0]??"sft";return e.jsx("div",{className:"training-dialog-backdrop",role:"presentation",onMouseDown:n,children:e.jsxs("section",{"aria-label":"New version","aria-modal":"true",className:"training-dialog labs-new-version-dialog",role:"dialog",onMouseDown:x=>x.stopPropagation(),children:[e.jsxs("div",{className:"training-dialog-header",children:[e.jsxs("div",{children:[e.jsx("h2",{children:"New version"}),e.jsx("p",{children:"Choose the immutable Dataset revision and training method."})]}),e.jsx("button",{"aria-label":"Close New version",type:"button",onClick:n,children:e.jsx(Ve,{size:16})})]}),e.jsxs("div",{className:"labs-new-version-step",children:[e.jsx("span",{className:"labs-new-version-step-number",children:"1"}),e.jsxs("div",{children:[e.jsx("strong",{children:"Dataset"}),e.jsx("p",{children:"Every run keeps the exact selected revision and Eval boundary."})]})]}),e.jsxs("label",{className:"labs-new-version-select",children:[e.jsx("span",{children:"Dataset revision"}),e.jsx("select",{value:l,onChange:x=>{const m=x.target.value;r(m);const k=a.find(y=>y.id===m),g=k?Ss(k):[];d(g.includes(j)?j:g[0]??"sft")},children:a.map(x=>e.jsxs("option",{value:x.id,children:[x.name," · revision ",x.revision]},x.id))})]}),o?e.jsxs("dl",{className:"labs-inline-facts labs-new-version-dataset-facts",children:[e.jsx(ht,{label:"Training",value:String(Et(o,"train"))}),e.jsx(ht,{label:"Validation",value:String(Et(o,"validation"))}),e.jsx(ht,{label:"Frozen Eval",value:String(Et(o,"frozen_eval"))}),e.jsx(ht,{label:"Graders",value:String(o.graders.length)})]}):e.jsx("div",{className:"training-run-placeholder",children:"No ready Dataset is available. Create or finish a Dataset first."}),e.jsxs("div",{className:"labs-new-version-step",children:[e.jsx("span",{className:"labs-new-version-step-number",children:"2"}),e.jsxs("div",{children:[e.jsx("strong",{children:"Training method"}),e.jsx("p",{children:"SFT and RFT create Versions of the same Model."})]})]}),e.jsx("div",{"aria-label":"Version training method",className:"labs-method-tabs",role:"tablist",children:u.map(x=>e.jsxs("button",{"aria-selected":x===j,className:x===j?"active":"",role:"tab",type:"button",onClick:()=>d(x),children:[e.jsx("span",{children:x==="grpo"?"Reinforcement":"Supervised"}),e.jsx("strong",{children:$e(x)})]},x))}),e.jsxs("div",{className:"training-dialog-actions",children:[e.jsx("button",{className:"training-button secondary",type:"button",onClick:n,children:"Cancel"}),e.jsx("button",{className:"training-button",disabled:!o||u.length===0,type:"button",onClick:()=>{o&&i({taskset:o,method:j})},children:"Continue"})]})]})})}function Ss(t){const s=new Set;for(const n of t.capabilities.compatibleMethods)(n==="sft"||n==="grpo")&&s.add(n);return t.readiness?.trainingPath?.bootstrap?.method==="sft"&&s.add("sft"),t.readiness?.trainingPath?.primaryMethod==="grpo"&&s.add("grpo"),["sft","grpo"].filter(n=>s.has(n))}function Et(t,s){return t.tasks.filter(n=>n.split===s).length}function ht({label:t,value:s}){return e.jsxs("div",{children:[e.jsx("dt",{children:t}),e.jsx("dd",{children:s})]})}function Ti({run:t,onAnswerQuestion:s,onApplyCandidate:n,onApprove:i,onCancel:a,onOpenPullRequest:l,onPause:r,onOpenConversation:o,onReconcilePullRequest:u,onRejectCandidate:h,onRetry:d,onResume:j,onRevise:x}){const m=t.state==="blocked"?"Review blocker":t.state==="failed"?"Review failure":"View progress",k=t.target.kind==="agent"&&["blocked","failed","cancelled"].includes(t.state);return e.jsxs("div",{className:"labs-run-decision",children:[e.jsx(Hn,{runtime:{run:t,onAnswerQuestion:s,onApplyCandidate:n,onApprove:i,onCancel:a,onOpenPullRequest:l,onPause:r,onReconcilePullRequest:u,onRejectCandidate:h,onResume:j,onRevise:x}}),t.scope.conversationId||k?e.jsxs("div",{className:"labs-run-decision-actions",children:[t.scope.conversationId?e.jsx("button",{className:"training-button secondary",type:"button",onClick:()=>o(t.scope.conversationId),children:m}):null,k?e.jsx("button",{className:"training-button",type:"button",onClick:d,children:"Try again"}):null]}):null]})}function _i({run:t,showOutcomes:s=!0}){const{completedTasks:n,currentTask:i,totalTasks:a}=t.progress,l=i?`${ws(i.family)} · ${i.worldId}`:t.progress.stage==="complete"?"Baseline complete":ws(t.progress.stage);return e.jsxs("div",{className:"labs-training-run-progress-wrap","aria-live":Pi(t)?"polite":"off",children:[e.jsxs("div",{className:"labs-training-run-progress",children:[e.jsxs("progress",{max:Math.max(1,a),value:n,children:[n," of ",a," tasks"]}),e.jsxs("small",{children:[n," / ",a," · ",l]})]}),s?e.jsxs("span",{className:"labs-training-run-verdicts",children:[t.progress.outcomes.correct," exact · ",t.progress.outcomes.incorrect," incorrect ·"," ",t.progress.outcomes.parseFailure," format ·"," ",t.progress.outcomes.infrastructureFailure," infrastructure"]}):null]})}function Ei(t){return t.status==="queued"?"Queued":t.status==="cancelling"?"Cancelling":t.status==="cancelled"?"Cancelled":t.status==="succeeded"?"Baseline ready":t.status==="failed"?"Baseline failed":t.progress.stage==="preparing"?"Preparing baseline":t.progress.stage==="persisting"?"Saving baseline":"Running baseline"}function Pi(t){return["queued","running","cancelling"].includes(t.status)}function ws(t){return t.replaceAll("_"," ").replace(/\b\w/g,s=>s.toUpperCase())}const $i=new Set(["released","rejected","ready","ready_local","published_hosted","blocked","failed","cancelled"]),Xs=new Set(["queued","starting","running","cancelling","reconciling"]);function Zs(t){const s=t.runs[0]??null,n=s?.state==="blocked"&&s.candidates.some(a=>!!a.git?.worktreePath&&["draft","checking"].includes(a.status))?s:null,i=t.runs.find(a=>!$i.has(a.state))??null;if(t.workproduct.kind==="model"&&t.taskset){const a=Us(t.training,t.taskset.id)[0]??null;if(a&&Xs.has(a.status))return Cs({taskset:t.taskset,training:t.training,latestRun:s,fallbackStatus:t.workproduct.status})}if(n)return Pt(n);if(i)return Pt(i);if(t.workproduct.kind==="model"){const a=t.workproduct.frontierBaselineRunId?t.training?.frontierBaselineRuns.find(l=>l.id===t.workproduct.frontierBaselineRunId)??null:null;return a?Di(a):!t.taskset&&s&&["failed","blocked","cancelled"].includes(s.state)?Pt(s):Cs({taskset:t.taskset,training:t.training,latestRun:s,fallbackStatus:t.workproduct.status})}return t.workproduct.kind==="agent"?{statusLabel:t.workproduct.status,statusValue:t.workproduct.status,action:{kind:"start_agent_change",label:"Improve agent"},runId:s?.id??null,conversationId:s?.scope.conversationId??null}:s?.scope.conversationId?{statusLabel:t.workproduct.status,statusValue:t.workproduct.status,action:{kind:"open_conversation",label:"Open chat"},runId:s.id,conversationId:s.scope.conversationId}:{statusLabel:t.workproduct.status,statusValue:t.workproduct.status,action:null,runId:s?.id??null,conversationId:s?.scope.conversationId??null}}function Di(t){return{statusLabel:Ei(t),statusValue:t.status,action:{kind:t.status==="succeeded"?"open_data":"open_evals",label:t.status==="succeeded"?"Review data":"View baseline"},runId:null,conversationId:null}}function Pt(t){const s={statusLabel:Bi(t.state),statusValue:t.state,runId:t.id,conversationId:t.scope.conversationId};if(t.state==="awaiting_questions")return{...s,action:{kind:"review_run",label:"Review questions"}};if(t.state==="awaiting_plan_approval")return{...s,action:{kind:"review_run",label:"Review plan"}};if(t.state==="awaiting_promotion")return{...s,action:{kind:"review_run",label:"Review candidate"}};if(t.state==="pull_request_open")return{...s,action:{kind:"review_run",label:"Review change"}};if(t.state==="paused")return{...s,action:{kind:"resume_run",label:"Resume"}};if(t.state==="blocked"){const n=t.candidates.some(i=>!!i.git?.worktreePath&&["draft","checking"].includes(i.status));return{...s,action:n?{kind:"resume_run",label:"Continue candidate"}:t.target.kind==="agent"?{kind:"start_agent_change",label:"Try again"}:t.scope.conversationId?{kind:"open_conversation",label:"Review blocker"}:null}}return t.state==="failed"?{...s,action:t.scope.conversationId?{kind:"open_conversation",label:"Review failure"}:null}:{...s,action:t.scope.conversationId?{kind:"open_conversation",label:"View progress"}:null}}function Cs(t){const s=t.latestRun?.scope.conversationId??null;if(!t.taskset)return{statusLabel:"Creating data",statusValue:"planning",action:s?{kind:"open_conversation",label:"View progress"}:null,runId:t.latestRun?.id??null,conversationId:s};const i=Us(t.training,t.taskset.id)[0]??null,a=t.training?.models.find(l=>l.tasksetId===t.taskset.id&&l.status==="imported")??null;return i&&Xs.has(i.status)?{statusLabel:Gt(i.status),statusValue:i.status,action:{kind:"open_training",label:"View run"},runId:t.latestRun?.id??null,conversationId:s}:i?.status==="failed"?{statusLabel:"Training failed",statusValue:"failed",action:{kind:"open_training",label:"Review failure"},runId:t.latestRun?.id??null,conversationId:s}:i?.status==="succeeded"?i.metadata.frozenEvaluationComplete===!0&&i.metadata.frozenEvaluationThresholdPassed!==!0?{statusLabel:"Evaluation failed",statusValue:"failed",action:{kind:"open_training",label:"Review results"},runId:t.latestRun?.id??null,conversationId:s}:{statusLabel:a?i.metadata.frozenEvaluationThresholdPassed===!0?"Model ready":"Evaluation pending":"Collecting model",statusValue:a&&i.metadata.frozenEvaluationThresholdPassed===!0?"ready":"running",action:{kind:"open_training",label:"Review results"},runId:t.latestRun?.id??null,conversationId:s}:t.taskset.readiness?.ready?{statusLabel:"Ready to train",statusValue:"ready",action:{kind:"start_training",label:"Start training"},runId:t.latestRun?.id??null,conversationId:s}:{statusLabel:"Needs review",statusValue:"needs_review",action:{kind:"open_data",label:"Review data"},runId:t.latestRun?.id??null,conversationId:s}}function Bi(t){return{planning:"Planning",awaiting_questions:"Needs answers",awaiting_plan_approval:"Plan ready",paused:"Paused",applying_source:"Applying changes",running_checks:"Running checks",evaluating:"Evaluating",awaiting_promotion:"Candidate ready",opening_pull_request:"Opening review",pull_request_open:"Review open",reconciling_release:"Merging change",released:"Released",rejected:"Rejected",ready:"Ready",ready_local:"Ready",pushing_hosted:"Syncing",running_hosted_checks:"Verifying hosted",published_hosted:"Published",blocked:"Blocked",failed:"Failed",cancelled:"Cancelled"}[t]}const Is={chat_manual:"Default chat model",agent:"Agent runtime",extension:"Extension runtime",authoring_optimizer:"Authoring / optimizer"};function Li({lineage:t,state:s,training:n,onToast:i}){const[a,l]=c.useState("chat_manual"),[r,o]=c.useState("default"),[u,h]=c.useState(null),[d,j]=c.useState(""),x=c.useMemo(()=>s?.modelBindings.find(f=>f.status==="active"&&f.role===a&&f.roleTargetId===r.trim())??null,[a,r,s?.modelBindings]),m=x?s?.models.find(f=>f.id===x.modelArtifactLineageId)??null:null,g=(t?.frozenEvaluationArtifactId?s?.artifacts.find(f=>f.id===t.frozenEvaluationArtifactId)??null:null)?.metadata.evaluationComplete===!1;if(!t)return e.jsx("div",{className:"training-run-placeholder",children:"Promotion is available after a verified artifact is imported."});const y=t,S=!!n.busyAction,v=y.status==="imported"&&y.promotable&&!!r.trim(),N=x?.modelArtifactLineageId===y.id;async function R(){const f=await n.actions.bindModel(y.id,a,r.trim());h(null),i(f?"Model binding activated.":"Couldn’t activate Model binding.",f?"success":"error")}async function T(){const f=d.trim();if(!f)return;const _=await n.actions.rejectModel(y.id,f);h(null),i(_?"Model candidate rejected.":"Couldn’t reject Model candidate.",_?"success":"error")}async function J(){const f=await n.actions.evaluateJob(y.jobId);h(null),i(f?"Frozen evaluation completed.":"Couldn’t complete frozen evaluation.",f?"success":"error")}async function L(){if(!x)return;const f=await n.actions.rollbackModelBinding(x.id);i(f?"Model binding rolled back.":"Couldn’t roll back Model binding.",f?"success":"error")}return e.jsxs("div",{className:"training-promotion",children:[e.jsxs("div",{className:"training-promotion-status",children:[e.jsxs("div",{children:[e.jsx("span",{children:"Promotion gate"}),e.jsx("strong",{children:t.promotable?"Passed":"Blocked"})]}),e.jsxs("div",{children:[e.jsx("span",{children:"Selected role"}),e.jsx("strong",{children:m?$t(m.id):"No active binding"})]}),e.jsxs("div",{children:[e.jsx("span",{children:"Rollback target"}),e.jsx("strong",{children:x?.rollbackTargetBindingId?$t(x.rollbackTargetBindingId):"None"})]})]}),e.jsxs("div",{className:"training-promotion-controls",children:[e.jsxs("label",{children:[e.jsx("span",{children:"Role"}),e.jsx("select",{value:a,onChange:f=>{const _=f.target.value;l(_),o(_==="chat_manual"?"default":"")},children:Object.entries(Is).map(([f,_])=>e.jsx("option",{value:f,children:_},f))})]}),e.jsxs("label",{children:[e.jsx("span",{children:"Role target"}),e.jsx("input",{value:r,placeholder:a==="agent"?"agent id":a==="extension"?"extension id":"default",onChange:f=>o(f.target.value)})]}),e.jsxs("div",{className:"training-promotion-actions",children:[g?e.jsx("button",{className:"training-button secondary",type:"button",disabled:S,onClick:()=>h("evaluate"),children:"Run evaluation"}):null,N?e.jsx("button",{className:"training-button secondary",type:"button",disabled:S,onClick:()=>{L()},children:"Roll back"}):e.jsx("button",{className:"training-button",type:"button",disabled:S||!v,onClick:()=>h("bind"),children:x?"Replace binding":"Bind model"}),e.jsx("button",{className:"training-button danger",type:"button",disabled:S||t.status==="rejected"||N,onClick:()=>h("reject"),children:"Reject"})]})]}),t.promotable?null:e.jsx("p",{className:"training-promotion-note",children:g?"The artifact remains inspectable. Its prior evaluation was blocked by provider infrastructure and recorded no quality result.":"The artifact remains inspectable, but it cannot be bound until its frozen-evaluation threshold passes."}),u?e.jsx("div",{className:"training-dialog-backdrop",role:"presentation",onMouseDown:()=>!S&&h(null),children:e.jsxs("section",{className:"training-dialog training-promotion-dialog",role:"dialog","aria-modal":"true","aria-label":u==="bind"?"Confirm Model binding":u==="evaluate"?"Run frozen evaluation":"Reject Model candidate",onMouseDown:f=>f.stopPropagation(),children:[e.jsx("div",{className:"training-dialog-header",children:e.jsxs("div",{children:[e.jsx("h2",{children:u==="bind"?"Activate this Model binding?":u==="evaluate"?"Run frozen evaluation?":"Reject this Model candidate?"}),e.jsx("p",{children:u==="bind"?`${Is[a]} · ${r.trim()}`:u==="evaluate"?"Temporary Fireworks deployments are deleted after the base and trained runs.":"The artifact and evaluation evidence are retained."})]})}),u==="bind"?e.jsx("p",{children:x?`The current binding ${$t(x.modelArtifactLineageId)} becomes the recorded rollback target.`:"This is an explicit activation; training success alone never changes runtime selection."}):u==="reject"?e.jsxs("label",{className:"training-promotion-reason",children:[e.jsx("span",{children:"Reason"}),e.jsx("textarea",{autoFocus:!0,value:d,onChange:f=>j(f.target.value)})]}):e.jsx("p",{children:"OpenPond first validates both deployment shapes without spending, then runs the approved frozen Taskset through the stateful tool harness. Runtime is capped at 10 minutes and the conservative deployment ceiling is $1.17 within the existing training approval."}),e.jsxs("div",{className:"training-dialog-actions",children:[e.jsx("button",{className:"training-button secondary",type:"button",disabled:S,onClick:()=>h(null),children:"Cancel"}),e.jsx("button",{className:`training-button ${u==="reject"?"danger":""}`,type:"button",disabled:S||u==="reject"&&!d.trim(),onClick:()=>{u==="bind"?R():u==="evaluate"?J():T()},children:S?"Applying…":u==="bind"?"Activate binding":u==="evaluate"?"Run evaluation":"Reject candidate"})]})]})}):null]})}function $t(t){return t.replace(/^lineage_/,"").replace(/^model_binding_/,"").slice(0,16)}function Fi(t){for(const s of t){const n=Ln.safeParse(s.metadata.preferredBaseModel);if(n.success)return n.data;const i=s.metadata.preferredBaseModelId;if(typeof i=="string"&&i.trim())return{schemaVersion:"openpond.baseModelPreference.v1",modelId:i.trim(),revision:null,tokenizerRevision:null,chatTemplateHash:null,modelAssetId:null,source:"managed"}}return null}function Oi(t){return[...t.candidates].reverse().find(s=>!!s.git?.headCommit)??null}function zi(t){return t?t.state==="released"?"positive":t.state==="blocked"||t.state==="failed"||t.state==="rejected"?"negative":t.state==="reconciling_release"?"info":"warning":"neutral"}function qi({workproduct:t,profile:s}){if(t.kind==="agent"){const n=s?.agents.find(i=>i.id===t.id)??null;return e.jsx(me,{title:"Agent",children:e.jsxs("dl",{className:"training-configuration-list",children:[e.jsx(Se,{label:"Enabled",value:n?.enabled?"Yes":"No"}),e.jsx(Se,{label:"Source",value:n?.path??t.path??"Draft"}),e.jsx(Se,{label:"Default action",value:`${t.id}.chat`}),e.jsx(Se,{label:"Profile checks",value:s?.lastCheck?.status??"Not run"})]})})}if(t.kind==="skill"){const n=s?.skills.find(i=>i.name===t.id)??null;return e.jsxs(me,{title:"Skill",children:[e.jsxs("dl",{className:"training-configuration-list",children:[e.jsx(Se,{label:"Enabled",value:n?.enabled?"Yes":"No"}),e.jsx(Se,{label:"Validation",value:n?.validationStatus??"Draft"}),e.jsx(Se,{label:"Source hash",value:n?.sourceHash??"Not available"}),e.jsx(Se,{label:"Characters",value:n?String(n.charCount):"Not available"})]}),n?.validationMessages.length?e.jsx("ul",{className:"labs-validation-list",children:n.validationMessages.map(i=>e.jsx("li",{children:i},i))}):null]})}return t.kind==="extension"?e.jsx(me,{title:"Extension",children:e.jsx("div",{className:"training-run-placeholder",children:"Runtime bindings arrive with the Extension phase."})}):null}function Vi({runs:t,selectedRun:s,onSelectedRunIdChange:n}){return e.jsx(me,{title:"Activity",children:t.length?e.jsx("div",{className:"training-table-wrap",children:e.jsxs("table",{className:"training-data-table labs-activity-table",children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{children:"Run"}),e.jsx("th",{children:"Operation"}),e.jsx("th",{children:"State"}),e.jsx("th",{children:"Revision"}),e.jsx("th",{children:"Updated"})]})}),e.jsx("tbody",{children:t.map(i=>e.jsxs("tr",{className:i.id===s?.id?"selected":void 0,onClick:()=>n(i.id),children:[e.jsx("td",{children:yt(i.id)}),e.jsx("td",{children:i.operation}),e.jsx("td",{children:e.jsx(je,{label:i.state.replaceAll("_"," "),value:i.state})}),e.jsx("td",{children:i.revision}),e.jsx("td",{children:vt(i.updatedAt)})]},i.id))})]})}):e.jsx("div",{className:"training-run-placeholder",children:"No Create/Improve activity yet."})})}function Ui({profileEvals:t,run:s,workproduct:n}){const i=s?.evaluationReceipts??[],a=[...new Set([...s?.context.evalRefs??[],...i.flatMap(r=>r.evalRefs)])],l=n.kind==="agent"?t.filter(r=>r.agentId===null||r.agentId===n.id):[];return!i.length&&!l.length&&!a.length?e.jsx("div",{className:"training-run-placeholder",children:"No Eval receipts yet."}):e.jsxs("div",{className:"labs-eval-summary",children:[l.length?e.jsxs("div",{className:"labs-source-evals",children:[e.jsx("strong",{children:"Available Evals"}),e.jsx("ul",{children:l.map(r=>e.jsxs("li",{children:[e.jsx("span",{children:r.name}),e.jsx("code",{children:r.path})]},r.id))})]}):null,a.length?e.jsxs("div",{className:"labs-source-evals",children:[e.jsx("strong",{children:"Used for this change"}),e.jsx("ul",{children:a.map(r=>e.jsx("li",{children:e.jsx("code",{children:r})},r))})]}):null,i.length?e.jsxs("div",{className:"labs-eval-receipts",children:[e.jsx("strong",{children:"Eval receipts"}),e.jsx("div",{className:"training-table-wrap",children:e.jsxs("table",{className:"training-data-table",children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{children:"Receipt"}),e.jsx("th",{children:"Status"}),e.jsx("th",{children:"Evals"}),e.jsx("th",{children:"Summary"})]})}),e.jsx("tbody",{children:i.map(r=>e.jsxs("tr",{children:[e.jsx("td",{children:yt(r.id)}),e.jsx("td",{children:e.jsx(je,{label:r.status})}),e.jsx("td",{children:r.evalRefs.length}),e.jsx("td",{children:r.summary??"No summary"})]},r.id))})]})})]}):null]})}function Ki({runs:t,selectedRun:s,taskset:n,training:i,trainingState:a,onToast:l}){const r=(n?a?.models.filter(d=>d.tasksetId===n.id)??[]:[]).sort((d,j)=>j.importedAt.localeCompare(d.importedAt)),o=new Map(a?.jobs.map(d=>[d.id,d])??[]),u=new Map(a?.plans.map(d=>[d.id,d])??[]),h=new Map(a?.artifacts.map(d=>[d.id,d])??[]);return e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"labs-detail-copy labs-version-storage-copy",children:"OpenPond automatically saves provider weights in app-managed local storage. Download LoRA creates a portable copy for moving or sharing the adapter."}),e.jsxs("dl",{className:"labs-inline-facts",children:[e.jsx(Pe,{label:"Create/Improve runs",value:String(t.length)}),e.jsx(Pe,{label:"Candidates",value:String(s?.candidates.length??0)}),e.jsx(Pe,{label:"Profile commit",value:s?.localProfileCommit??"Not released"}),e.jsx(Pe,{label:"Model artifacts",value:String(r.length)})]}),r.length?e.jsx("div",{className:"training-table-wrap",children:e.jsxs("table",{className:"training-data-table",children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{children:"Version"}),e.jsx("th",{children:"Method"}),e.jsx("th",{children:"Storage"}),e.jsx("th",{children:"Frozen Eval"}),e.jsx("th",{children:"Imported"}),e.jsx("th",{children:e.jsx("span",{className:"sr-only",children:"Download"})})]})}),e.jsx("tbody",{children:r.map((d,j)=>{const x=o.get(d.jobId),m=x?u.get(x.planId):null,k=h.get(d.artifactId)??null,g=k?Gi(k.path):null;return e.jsxs("tr",{children:[e.jsxs("td",{className:"labs-version-name",children:[e.jsx("strong",{children:j===0?"Latest":`Prior ${j}`}),e.jsx("small",{children:yt(d.id)})]}),e.jsx("td",{children:$e(m?.recipe.method)}),e.jsxs("td",{className:"labs-version-storage",children:[e.jsx("strong",{children:g?"Saved locally":"Unavailable"}),g?e.jsx("code",{title:k?.path,children:g}):null]}),e.jsx("td",{children:d.promotable?"Passed":d.frozenEvaluationArtifactId?"Failed":"Not run"}),e.jsx("td",{children:vt(d.importedAt)}),e.jsx("td",{children:e.jsxs("button",{className:"training-button secondary",type:"button",onClick:()=>{i.actions.downloadModelPackage(d.id)},children:[e.jsx(Kt,{size:14}),"Download LoRA"]})})]},d.id)})})]})}):e.jsx("div",{className:"training-run-placeholder",children:"Model versions appear after the first adapter is imported."}),r[0]?e.jsxs("div",{className:"labs-version-promotion",children:[e.jsx("h3",{children:"Promotion & bindings"}),e.jsx(Li,{lineage:r[0],state:a,training:i,onToast:l})]}):null]})}function Gi(t){return t.replace(/[/\\][^/\\]+$/,"").replace(/^\/home\/[^/]+/,"~")}function Pe({label:t,value:s}){return e.jsxs("div",{children:[e.jsx("dt",{children:t}),e.jsx("dd",{children:s})]})}function Se({label:t,value:s}){return e.jsxs("div",{children:[e.jsx("dt",{children:t}),e.jsx("dd",{children:s})]})}function yt(t){return t.replace(/^(create_improve|training_job|agent_candidate|model_candidate)_/,"").slice(0,14)}function en(t){return t&&`${t[0].toUpperCase()}${t.slice(1).replaceAll("_"," ")}`}function Hi(t,s,n){return t==="changes"?s?["Changes",n?`Change ${n.slice(0,8)}`:`Change ${yt(s)}`]:["Changes"]:[en(t)]}function Wi(t,s,n){const i=n.git?.changedPaths??[],a=i[0]??null,l=t.path?.trim().replace(/^\.\/+|\/+$/g,"")??"";if(!l)return{fileRootPath:null,initialPath:a};const r=l.split("/").filter(Boolean);r.at(-1)?.includes(".")&&r.pop();const o=r.join("/");if(!o)return{fileRootPath:null,initialPath:a};const u=o.startsWith("profiles/")?o:`profiles/${s?.activeProfile??"default"}/${o}`,h=i.find(d=>d===u||d.startsWith(`${u}/`))??null;return h?{fileRootPath:u,initialPath:h}:{fileRootPath:null,initialPath:a}}function Ji(t){return t?t.state==="awaiting_promotion"?"Change pending review":t.state==="released"?"Change merged":`Change ${t.state.replaceAll("_"," ")}`:"No change status"}function Qi({workproduct:t,runs:s,profile:n,training:i,connection:a,onOpenConversation:l,onLocationChange:r,onRenameAgent:o,onStartAgentChange:u,onOpenDataset:h,onToast:d,onAnswerQuestion:j,candidateReview:x,onApprove:m,onCancel:k,onChatWithModel:g,onApplyCandidate:y,onCandidateReviewChange:S,onOpenCandidateFiles:v,onOpenPullRequest:N,onPause:R,onReconcilePullRequest:T,onRejectCandidate:J,onResume:L,onRevise:f}){const _=c.useMemo(()=>Hs(t,s),[s,t]),[ce,$]=c.useState(_[0]?.id??""),[se,Q]=c.useState(null),[E,H]=c.useState("overview"),[ne,O]=c.useState(null),[ie,re]=c.useState(!1),[W,Y]=c.useState(null),[z,ae]=c.useState(null),K=_.find(I=>I.id===ce)??_[0]??null,X=se?_.find(I=>I.id===se)??null:null,V=X?Oi(X):null,oe=Wa(t.kind),ue=V?.git?.headCommit??null,he=c.useMemo(()=>t.kind==="model"?ne?["Version details"]:[]:Hi(E,se,ue),[E,ue,se,ne,t.kind]),ee=t.tasksetId?i.payload?.tasksets.find(I=>I.id===t.tasksetId)??null:null,Ce=t.kind==="agent"?n?.agents.some(I=>I.id===t.id)??!1:!1,P=Zs({workproduct:t,runs:_,taskset:ee,training:i.payload}),D=P.runId??_[0]?.id??"",de=_.some(I=>I.id===ce),te=se?_.some(I=>I.id===se):!0,be=[["overview","Overview"],["changes","Changes"],["evals","Evals"],["versions","Versions"],["configuration","Configuration"]];c.useEffect(()=>{S(null),$(D),Q(null),O(null),H("overview")},[t.key]),c.useEffect(()=>{ce&&de||$(D)},[D,de,ce]),c.useEffect(()=>{te||Q(null)},[te]),c.useEffect(()=>{if(E==="changes"&&X&&V){const I=Wi(t,n,V);S({run:X,candidate:V,fileRootPath:I.fileRootPath,initialPath:I.initialPath});return}S(null)},[E,S,n,V,X,t]),c.useEffect(()=>{r({kind:t.kind,kindLabel:oe,workproductLabel:t.name,sectionLabels:he})},[oe,he,r,t.kind,t.name]),c.useEffect(()=>()=>S(null),[S]);function Te(I){const U=qe(t,s,i.payload).find(xe=>xe.lineage.id===I);if(U?.taskset){if(U.job?.destinationId==="fireworks"){Y(I);return}g(ft({modelId:I,taskset:U.taskset}))}}return e.jsxs("div",{className:"training-model-detail labs-workproduct-detail",children:[e.jsxs("header",{className:"training-model-detail-header labs-workproduct-detail-header",children:[e.jsx("div",{children:e.jsxs("div",{className:"labs-workproduct-name-row",children:[e.jsx("h1",{children:t.name}),e.jsx(zt,{label:P.statusLabel,value:P.statusValue})]})}),t.kind==="model"?e.jsx("div",{className:"labs-workproduct-header-actions",children:e.jsx("button",{className:"training-button",type:"button",onClick:()=>re(!0),children:"New version"})}):t.kind==="agent"?e.jsxs("div",{className:"labs-workproduct-header-actions",children:[e.jsx("button",{className:"training-button",type:"button",onClick:()=>u(t.id),children:"Improve agent"}),Ce?e.jsxs("button",{className:"settings-secondary compact",type:"button",onClick:o,children:[e.jsx(Ps,{size:14}),e.jsx("span",{children:"Rename"})]}):null]}):null]}),t.kind!=="model"?e.jsx("div",{className:"training-detail-tabs",role:"tablist","aria-label":"Workproduct detail",children:be.map(([I,U])=>e.jsxs("button",{className:E===I?"active":void 0,"aria-selected":E===I,role:"tab",type:"button",onClick:()=>{H(I),I==="changes"&&Q(null)},children:[U,I==="changes"?e.jsx(zt,{decorative:!0,label:Ji(_[0]??null),size:"small",tone:zi(_[0]??null)}):null]},I))}):null,e.jsx("div",{className:"training-detail-sections",children:t.kind==="model"?ne?e.jsx(wi,{connection:a,runs:s,selectedEntryKey:ne,training:i,workproduct:t,onBack:()=>O(null),onOpenDataset:h,onUseVersion:Te}):e.jsx(Si,{runs:s,training:i,workproduct:t,onOpenDataset:h,onOpenEntry:O,onToast:d}):E==="overview"?e.jsxs(me,{title:"Overview",children:[e.jsxs("dl",{className:"labs-inline-facts",children:[e.jsx(Pe,{label:"Type",value:en(t.kind)}),e.jsx(Pe,{label:"Status",value:P.statusLabel}),e.jsx(Pe,{label:"ID",value:t.id}),e.jsx(Pe,{label:"Path",value:t.path??"Managed artifact"})]}),e.jsx("p",{className:"labs-detail-copy",children:t.description})]}):E==="changes"&&!X?e.jsx("div",{className:"labs-change-index",children:e.jsx(si,{runs:_,onReview:I=>{$(I.id),Q(I.id)}})}):E==="changes"&&X&&V?e.jsx(Za,{candidate:V,diff:x.diff,error:x.error,run:X,onApplyCandidate:(I,U)=>y({run:I},U),onOpenFiles:v,onRejectCandidate:(I,U)=>J({run:I},U)}):E==="changes"&&X?e.jsxs("div",{className:"labs-change-run-detail",children:[e.jsxs("article",{className:"labs-change-card",children:[e.jsxs("header",{className:"labs-change-card-header",children:[e.jsx("span",{className:"labs-change-timeline-label",children:"Request"}),e.jsx(je,{label:X.state.replaceAll("_"," "),value:X.state})]}),e.jsx("div",{className:"labs-change-card-body",children:e.jsx("h3",{children:X.objective})})]}),e.jsx(Ti,{run:X,onAnswerQuestion:j,onApplyCandidate:y,onApprove:m,onCancel:k,onOpenConversation:l,onOpenPullRequest:N,onPause:R,onReconcilePullRequest:T,onRejectCandidate:J,onResume:L,onRetry:()=>u(t.id,X.objective),onRevise:f})]}):E==="evals"?e.jsx(me,{title:"Evals",actions:t.kind==="agent"?e.jsx(Xa,{agentId:t.id,evals:n?.evals??[],onCreate:()=>u(t.id,`Create an Eval for ${t.name}. Describe the behavior this Eval should specify: `),onAttach:I=>u(t.id,`--eval ${JSON.stringify(I)} Improve ${t.name} using this existing Eval: `)}):null,children:e.jsx(Ui,{profileEvals:n?.evals??[],run:K,workproduct:t})}):E==="versions"?e.jsxs(e.Fragment,{children:[e.jsx(me,{title:"Versions",children:e.jsx(Ki,{runs:_,selectedRun:K,taskset:ee,training:i,trainingState:i.payload,onToast:d})}),e.jsx(Vi,{runs:_,selectedRun:K,onSelectedRunIdChange:$})]}):e.jsxs(e.Fragment,{children:[e.jsx(me,{title:"Connections",children:e.jsxs("dl",{className:"training-configuration-list",children:[e.jsx(Se,{label:"Profile",value:n?.activeProfile??"default"}),e.jsx(Se,{label:"Conversation",value:K?.scope.conversationId??"Not linked"}),e.jsx(Se,{label:"Project",value:K?.scope.projectId??"Not linked"}),e.jsx(Se,{label:"Source authority",value:K?.adapter.sourceAuthority??"Profile"})]})}),e.jsx(qi,{workproduct:t,profile:n})]})}),ie?e.jsx(Ai,{initialTasksetId:ee?.id??null,state:i.payload,onClose:()=>re(!1),onContinue:I=>{re(!1),ae(I)}}):null,z?e.jsx(Da,{busy:["prepare-training","start-prepared-training","start-training"].includes(i.busyAction??""),connection:a,baseModelCandidates:i.payload?.baseModelCandidates??[],destinations:i.payload?.destinations??[],initialMethod:z.method,modelId:t.id,preferredBaseModel:Fi(_),taskset:z.taskset,onClose:()=>ae(null),onPrepare:(I,U,xe)=>i.actions.prepareTraining({modelId:t.id,tasksetId:z.taskset.id,destinationId:I,recipe:U,exportApproved:xe.exportApproved,retentionDays:xe.retentionDays,region:xe.region}),onConfirmPrepared:async(I,U)=>!!await i.actions.startPreparedTraining({planId:I.plan.id,bundleId:I.bundle.id,maximumCostUsd:U}),onStart:async(I,U,xe)=>!!await i.actions.startTraining({modelId:t.id,tasksetId:z.taskset.id,destinationId:I,recipe:U,...xe})}):null,W?(()=>{const I=qe(t,s,i.payload).find(U=>U.lineage.id===W);return I?.taskset?e.jsx(Ks,{lineage:I.lineage,taskset:I.taskset,training:i,onChat:g,onClose:()=>Y(null)}):null})():null]})}function Yi({activeTab:t,children:s,suggestionCount:n,showHeader:i=!0,onTabChange:a,onCreateAgent:l,onCreateDataset:r,onCreateModel:o}){const[u,h]=c.useState(!1),d=c.useRef(null);return c.useEffect(()=>{if(!u)return;function j(m){d.current?.contains(m.target)||h(!1)}function x(m){m.key==="Escape"&&h(!1)}return document.addEventListener("pointerdown",j),document.addEventListener("keydown",x),()=>{document.removeEventListener("pointerdown",j),document.removeEventListener("keydown",x)}},[u]),e.jsxs("section",{className:"labs-route","aria-label":"Lab",children:[i?e.jsxs("header",{className:"labs-header",children:[e.jsx("div",{className:"labs-header-navigation",children:e.jsxs("nav",{className:"labs-primary-tabs",role:"tablist","aria-label":"Lab sections",children:[e.jsx("button",{"aria-selected":t==="workproducts",className:t==="workproducts"?"active":void 0,role:"tab",type:"button",onClick:()=>a("workproducts"),children:"Home"}),e.jsx("button",{"aria-selected":t==="datasets",className:t==="datasets"?"active":void 0,role:"tab",type:"button",onClick:()=>a("datasets"),children:"Datasets"}),e.jsxs("button",{"aria-selected":t==="suggestions",className:t==="suggestions"?"active":void 0,role:"tab",type:"button",onClick:()=>a("suggestions"),children:["Suggestions",n>0?e.jsx("span",{children:n}):null]})]})}),e.jsx("div",{className:"labs-header-actions",children:e.jsxs("div",{className:"labs-create-anchor",ref:d,children:[e.jsx("button",{className:"labs-create-button",type:"button","aria-expanded":u,"aria-haspopup":"menu","aria-label":"Create workproduct",title:"Create workproduct",onClick:()=>h(j=>!j),children:e.jsx(Ls,{size:15})}),u?e.jsxs("div",{className:"labs-create-menu",role:"menu",children:[e.jsxs("button",{type:"button",role:"menuitem",onClick:()=>{h(!1),l()},children:[e.jsx(Fs,{size:15}),e.jsxs("span",{children:[e.jsx("strong",{children:"New agent"}),e.jsx("small",{children:"Describe the agent in the shared Create flow."})]})]}),e.jsxs("button",{disabled:!0,type:"button",role:"menuitem",children:[e.jsx(Fn,{size:15}),e.jsxs("span",{children:[e.jsx("strong",{children:"New skill"}),e.jsx("small",{children:"Coming soon"})]})]}),e.jsxs("button",{disabled:!0,type:"button",role:"menuitem",children:[e.jsx(On,{size:15}),e.jsxs("span",{children:[e.jsx("strong",{children:"New extension"}),e.jsx("small",{children:"Coming soon"})]})]}),e.jsxs("button",{type:"button",role:"menuitem",onClick:()=>{h(!1),o()},children:[e.jsx(Os,{size:15}),e.jsxs("span",{children:[e.jsx("strong",{children:"New model"}),e.jsx("small",{children:"Build the data and Evals, then choose training."})]})]}),e.jsxs("button",{type:"button",role:"menuitem",onClick:()=>{h(!1),r()},children:[e.jsx(tt,{size:15}),e.jsxs("span",{children:[e.jsx("strong",{children:"New Dataset"}),e.jsx("small",{children:"Create a reusable Taskset without creating a Model."})]})]})]}):null]})})]}):null,e.jsx("div",{className:"labs-panel",children:s})]})}function Xi({agentId:t,currentName:s,onClose:n,onRename:i}){const[a,l]=c.useState(s),[r,o]=c.useState(!1),[u,h]=c.useState(null),d=a.trim().replace(/\s+/g," "),j=d===s.trim().replace(/\s+/g," ");c.useEffect(()=>{l(s),o(!1),h(null)},[t,s]),c.useEffect(()=>{function m(k){k.key==="Escape"&&!r&&n()}return window.addEventListener("keydown",m),()=>window.removeEventListener("keydown",m)},[r,n]);async function x(m){if(m.preventDefault(),!(!d||j||r)){o(!0),h(null);try{await i(d),n()}catch(k){h(k instanceof Error?k.message:String(k))}finally{o(!1)}}}return e.jsx("div",{className:"labs-rename-backdrop",role:"presentation",onMouseDown:m=>{m.target===m.currentTarget&&!r&&n()},children:e.jsxs("section",{"aria-label":`Rename ${s}`,"aria-modal":"true",className:"labs-rename-dialog",role:"dialog",children:[e.jsxs("header",{children:[e.jsx("span",{className:"labs-rename-dialog-icon",children:e.jsx(Fs,{size:16})}),e.jsxs("div",{children:[e.jsx("h2",{children:"Rename agent"}),e.jsx("p",{children:"Change the display name without changing the stable agent ID."})]}),e.jsx("button",{"aria-label":"Close rename agent",disabled:r,type:"button",onClick:n,children:e.jsx(Ve,{size:16})})]}),e.jsxs("form",{onSubmit:m=>{x(m)},children:[e.jsxs("label",{children:[e.jsx("span",{children:"Display name"}),e.jsx("input",{autoFocus:!0,maxLength:80,value:a,onChange:m=>l(m.currentTarget.value)})]}),e.jsxs("div",{className:"labs-rename-agent-id",children:[e.jsx("span",{children:"Agent ID"}),e.jsx("code",{children:t})]}),u?e.jsx("p",{className:"labs-rename-error",role:"alert",children:u}):null,e.jsxs("footer",{children:[e.jsx("button",{disabled:r,type:"button",onClick:n,children:"Cancel"}),e.jsx("button",{disabled:!d||j||r,type:"submit",children:r?"Renaming…":"Rename"})]})]})]})})}function Zi({taskset:t,busyAction:s,onPreview:n,onApprove:i,onToast:a}){const[l,r]=c.useState(null),[o,u]=c.useState(!1),h=tl(t),d=t.learningSignals.demonstrations.filter(g=>g.approved&&g.metadata.exampleOrigin==="expert_authored").length,j=s==="preview-expert-bootstrap",x=s==="approve-expert-bootstrap";async function m(){u(!0);const g=await n();if(g){r(g);return}u(!1),a("Couldn’t load the expert trajectories.","error")}async function k(){if(!l)return;const g=await i(l.previewHash);if(!g){a("The expert trajectories were not approved.","error");return}u(!1),a(`${g.approval.trajectoryCount} expert trajectories approved by ${g.approval.approvedBy}.`,"success")}return e.jsxs(e.Fragment,{children:[e.jsx(me,{title:"SFT bootstrap data",actions:e.jsx("button",{className:"training-button secondary",disabled:j||x,type:"button",onClick:()=>{m()},children:h?"Review trajectories":j?"Loading…":"Review expert trajectories"}),children:e.jsxs("div",{className:"labs-expert-bootstrap-summary",children:[e.jsxs("div",{children:[e.jsx(je,{label:h?"Approved":"Review required",value:h?"ready":"needs_review"}),e.jsx("p",{children:h?`${d} deterministic train-split trajectories are approved for the optional SFT bootstrap.`:"Five deterministic train-split trajectories are available. Failed model outputs remain excluded."})]}),h?e.jsxs("dl",{className:"labs-inline-facts",children:[e.jsx(Ze,{label:"Approved by",value:h.approvedBy}),e.jsx(Ze,{label:"Taskset revision",value:String(t.revision)})]}):null]})}),o?e.jsx(el,{approving:x,loading:j,preview:l,onApprove:()=>{k()},onClose:()=>{x||u(!1)}}):null]})}function el({preview:t,loading:s,approving:n,onApprove:i,onClose:a}){return e.jsx("div",{className:"training-dialog-backdrop",role:"presentation",onMouseDown:n?void 0:a,children:e.jsxs("section",{"aria-label":"Review expert trajectories","aria-modal":"true",className:"training-dialog labs-expert-bootstrap-dialog",role:"dialog",onMouseDown:l=>l.stopPropagation(),children:[e.jsxs("div",{className:"training-dialog-header",children:[e.jsxs("div",{children:[e.jsx("h2",{children:"Review expert trajectories"}),e.jsx("p",{children:"These examples were executed in the deterministic synthetic environment and passed the exact verifier. Approval is bound to the signed-in OpenPond account."})]}),e.jsx("button",{"aria-label":"Close",disabled:n,type:"button",onClick:a,children:"×"})]}),e.jsx("div",{className:"training-dialog-scroll-body labs-expert-trajectory-list",children:s||!t?e.jsx("div",{className:"training-run-placeholder",children:"Generating and verifying the review set…"}):e.jsxs(e.Fragment,{children:[e.jsxs("dl",{className:"labs-inline-facts labs-expert-preview-facts",children:[e.jsx(Ze,{label:"Taskset revision",value:String(t.tasksetRevision)}),e.jsx(Ze,{label:"Trajectories",value:String(t.tasks.length)}),e.jsx(Ze,{label:"Review state",value:t.status==="approved"?"Approved":"Pending"})]}),t.tasks.map(l=>e.jsxs("details",{className:"labs-expert-trajectory",children:[e.jsxs("summary",{children:[e.jsxs("span",{children:[e.jsx("strong",{children:sl(l.family)}),e.jsxs("small",{children:[l.toolCallCount," tool calls · exact reward ",l.reward.toFixed(3)]})]}),e.jsx("span",{"aria-hidden":"true",children:"›"})]}),e.jsxs("div",{className:"labs-expert-trajectory-body",children:[e.jsxs("section",{children:[e.jsx("h3",{children:"Prompt"}),e.jsx("p",{children:l.prompt})]}),e.jsxs("section",{children:[e.jsx("h3",{children:"Tool sequence"}),e.jsx("div",{className:"training-pills",children:l.toolNames.map((r,o)=>e.jsx("span",{children:r},`${l.trajectoryId}-${r}-${o}`))})]}),e.jsxs("section",{children:[e.jsx("h3",{children:"Verified answer"}),e.jsx("pre",{children:l.finalAnswer})]}),e.jsxs("details",{className:"labs-expert-messages",children:[e.jsxs("summary",{children:["View ",l.messageCount," training messages"]}),e.jsx("pre",{children:JSON.stringify(l.messages,null,2)})]})]})]},l.trajectoryId))]})}),e.jsxs("div",{className:"training-dialog-actions",children:[e.jsx("span",{className:"labs-expert-approval-note",children:"Train split only · failed policy outputs excluded"}),e.jsx("button",{className:"training-button secondary",disabled:n,type:"button",onClick:a,children:"Close"}),t?.status!=="approved"?e.jsx("button",{className:"training-button",disabled:!t||s||n,type:"button",onClick:i,children:n?"Approving…":`Approve ${t?.tasks.length??0} trajectories`}):null]})]})})}function tl(t){const s=Ms(t.metadata.expertBootstrap),n=Ms(s.approval);return n.status!=="approved"||typeof n.approvedBy!="string"||typeof n.approvedAt!="string"||typeof n.previewHash!="string"||typeof n.trajectoryCount!="number"?null:n}function Ze({label:t,value:s}){return e.jsxs("div",{children:[e.jsx("dt",{children:t}),e.jsx("dd",{children:s})]})}function sl(t){return t.split("_").map(s=>`${s.slice(0,1).toUpperCase()}${s.slice(1)}`).join(" ")}function Ms(t){return t&&typeof t=="object"&&!Array.isArray(t)?t:{}}const nl=[{id:"train",label:"Training"},{id:"validation",label:"Validation"},{id:"frozen_eval",label:"Frozen Eval"}],Dt=10;function al({taskset:t,onOpenFiles:s}){const n=c.useMemo(()=>gl(t.tasks.map(g=>g.split)),[t.tasks]),i=n.get("train")?"train":t.tasks[0]?.split??"train",[a,l]=c.useState(i==="test"?"frozen_eval":i),[r,o]=c.useState(!1),u=c.useMemo(()=>new Map(t.sourceRefs.map(g=>[g.id,g])),[t.sourceRefs]),h=t.tasks.filter(g=>g.split===a),d=r?h:h.slice(0,Dt),j=t.sourceRefs.filter(Wt).length,x=t.sourceRefs.filter(g=>g.turnIds.length>0).length,m=t.sourceRefs.filter(g=>g.metadata.containsCustomerData===!0).length,k=t.learningSignals.demonstrations.filter(g=>g.approved).length;return e.jsxs(e.Fragment,{children:[e.jsxs(me,{title:"Dataset",actions:e.jsx("button",{className:"training-button secondary",type:"button",onClick:s,children:"Open files"}),children:[e.jsx("p",{className:"labs-detail-copy labs-dataset-summary",children:ll({syntheticSources:j,chatSources:x,customerSources:m,sourceCount:t.sourceRefs.length})}),e.jsxs("dl",{className:"labs-inline-facts",children:[e.jsx(Fe,{label:"Training",value:String(n.get("train")??0)}),e.jsx(Fe,{label:"Validation",value:String(n.get("validation")??0)}),e.jsx(Fe,{label:"Frozen Eval",value:String(n.get("frozen_eval")??0)}),e.jsx(Fe,{label:"Approved demonstrations",value:String(k)})]})]}),e.jsxs(me,{title:"Examples",children:[e.jsx("div",{className:"labs-method-tabs labs-dataset-tabs",role:"tablist","aria-label":"Dataset splits",children:nl.map(g=>e.jsxs("button",{"aria-selected":a===g.id,className:a===g.id?"active":"",role:"tab",type:"button",onClick:()=>{l(g.id),o(!1)},children:[g.label,e.jsx("span",{children:n.get(g.id)??0})]},g.id))}),e.jsxs("div",{className:"labs-dataset-examples",children:[d.map((g,y)=>e.jsx(il,{index:y,source:g.sourceRefs.map(S=>u.get(S)).find(Boolean)??null,task:g},g.id)),h.length>Dt?e.jsx("button",{className:"training-button secondary labs-dataset-show-all",type:"button",onClick:()=>o(g=>!g),children:r?`Show first ${Dt}`:`Show all ${h.length}`}):null]})]})]})}function il({index:t,source:s,task:n}){const i=rl(n),a=dl(n),l=ol(n),r=s?hl(s):"Source unavailable",o=cl(n,s),u=ul(n,s);return e.jsxs("details",{className:"labs-dataset-example",children:[e.jsxs("summary",{children:[e.jsx("span",{className:"labs-dataset-example-index",children:String(t+1).padStart(2,"0")}),e.jsxs("span",{className:"labs-dataset-example-title",children:[e.jsx("strong",{children:i}),e.jsx("small",{children:[o,u,r].filter(Boolean).join(" · ")})]}),e.jsx(je,{label:pl(n.split),value:n.split})]}),e.jsxs("div",{className:"labs-dataset-example-body",children:[e.jsxs("section",{children:[e.jsx("h3",{children:"Prompt"}),e.jsx("p",{children:i})]}),e.jsxs("section",{children:[e.jsx("h3",{children:n.split==="frozen_eval"?"Expected result":"Approved answer"}),n.split==="frozen_eval"?e.jsx("p",{children:"The answer stays held out and is only opened by the Eval runner."}):e.jsx("pre",{children:l??"No approved answer is attached."})]}),a.length?e.jsxs("section",{children:[e.jsx("h3",{children:"Tool trajectory"}),e.jsx("div",{className:"training-pills",children:a.map((h,d)=>e.jsx("span",{children:h},`${h}:${d}`))})]}):null,e.jsxs("section",{children:[e.jsx("h3",{children:"Source"}),e.jsxs("p",{children:[e.jsx("strong",{children:s?.title??"Source unavailable"})," — ",ml(s)]})]}),e.jsxs("details",{className:"labs-dataset-example-advanced",children:[e.jsx("summary",{children:"Technical details"}),e.jsxs("dl",{className:"training-configuration-list",children:[e.jsx(Fe,{label:"Task",value:n.id}),e.jsx(Fe,{label:"Source",value:s?.id??"Unavailable"}),e.jsx(Fe,{label:"Cluster",value:n.clusterKey})]})]})]})]})}function ll(t){if(t.sourceCount>0&&t.syntheticSources===t.sourceCount&&t.chatSources===0&&t.customerSources===0)return`This dataset contains ${t.sourceCount} generated scenarios. It uses no raw chats or customer data.`;const s=[`${t.sourceCount} source${t.sourceCount===1?"":"s"}`,`${t.chatSources} chat${t.chatSources===1?"":"s"}`,`${t.syntheticSources} generated scenario${t.syntheticSources===1?"":"s"}`];return t.customerSources===0?s.push("no sources marked as customer data"):s.push(`${t.customerSources} source${t.customerSources===1?"":"s"} marked as customer data`),`This dataset contains ${s.join(", ")}.`}function rl(t){return typeof t.input.prompt=="string"?t.input.prompt:"Untitled dataset example"}function ol(t){if(!t.expectedOutput)return null;if(typeof t.expectedOutput.text=="string")return t.expectedOutput.text;const s=Array.isArray(t.expectedOutput.messages)?t.expectedOutput.messages:[];for(const n of[...s].reverse())if(n&&typeof n=="object"&&"content"in n&&typeof n.content=="string")return n.content;return null}function dl(t){if(!t.expectedOutput||!Array.isArray(t.expectedOutput.messages))return[];const s=[];for(const n of t.expectedOutput.messages){if(!n||typeof n!="object"||!("tool_calls"in n))continue;const i=Array.isArray(n.tool_calls)?n.tool_calls:[];for(const a of i){if(!a||typeof a!="object"||!("function"in a))continue;const l=a.function;l&&typeof l=="object"&&"name"in l&&typeof l.name=="string"&&s.push(l.name)}}return s}function cl(t,s){const n=s?.metadata.crossSystemOperations;if(n&&typeof n=="object"&&"taskFamily"in n){const a=n.taskFamily;if(typeof a=="string")return bt(a)}const i=t.tags.find(a=>!["synthetic","structured-tool-trajectory"].includes(a));return i?bt(i):null}function ul(t,s){const n=s?.metadata.crossSystemOperations;if(n&&typeof n=="object"&&"worldDifficulty"in n){const i=n.worldDifficulty;if(typeof i=="string")return bt(i)}return t.clusterKey.match(/_(easy|medium|hard)$/)?.[1]??null}function Wt(t){return t.metadata.syntheticSpecification===!0}function hl(t){return Wt(t)?"Generated scenario":t.turnIds.length>0?"Chat":"Imported source"}function ml(t){return t?Wt(t)&&t.metadata.containsCustomerData===!1?"generated locally from a deterministic specification; no customer content is attached.":t.turnIds.length>0?`${t.turnIds.length} approved chat turn${t.turnIds.length===1?"":"s"} are attached.`:"an approved imported source is attached.":"The referenced source could not be loaded."}function pl(t){return t==="frozen_eval"?"Frozen Eval":bt(t)}function bt(t){return t.replaceAll("-"," ").replaceAll("_"," ").replace(/\b\w/g,s=>s.toUpperCase())}function gl(t){const s=new Map;for(const n of t)s.set(n,(s.get(n)??0)+1);return s}function Fe({label:t,value:s}){return e.jsxs("div",{children:[e.jsx("dt",{children:t}),e.jsx("dd",{children:s})]})}const Vt=10;function xl({state:t,runs:s,selectedId:n,onSelectedIdChange:i,onCreate:a,onOpenFiles:l,training:r,onToast:o}){const[u,h]=c.useState(""),[d,j]=c.useState(1),x=t?.tasksets??[],m=x.find(S=>S.id===n)??null,k=c.useMemo(()=>{const S=u.trim().toLowerCase();return S?x.filter(v=>[v.name,v.objective,v.id].some(N=>N.toLowerCase().includes(S))):x},[u,x]),g=k.slice((d-1)*Vt,d*Vt),y=c.useMemo(()=>{const S=new Map;if(!t)return S;const v=Gs({profile:null,training:t,runs:s}).filter(N=>N.kind==="model");for(const N of v)for(const R of ki(N,s,t))S.set(R.id,(S.get(R.id)??0)+1);return S},[s,t]);return m?e.jsxs("div",{className:"labs-flat-body labs-datasets-page",children:[e.jsxs("div",{className:"labs-dataset-detail-heading",children:[e.jsx("button",{"aria-label":"Back to Datasets",className:"labs-back-button",type:"button",onClick:()=>i(null),children:e.jsx(Ds,{size:15})}),e.jsxs("div",{children:[e.jsx("h1",{children:m.name}),e.jsx("p",{children:m.objective})]}),e.jsx(je,{label:fl(m),value:m.status})]}),e.jsx(al,{taskset:m,onOpenFiles:()=>l(m.id)}),m.metadata.flagship==="cross-system-operations"?e.jsx(Zi,{busyAction:r.busyAction,taskset:m,onApprove:S=>r.actions.approveExpertBootstrap(m.id,S),onPreview:()=>r.actions.previewExpertBootstrap(m.id),onToast:o}):null]}):e.jsxs("div",{className:"labs-flat-body labs-datasets-page",children:[e.jsx("div",{className:"labs-resource-actions",children:e.jsx("button",{className:"training-button",type:"button",onClick:a,children:"Create Dataset"})}),e.jsx("div",{className:"labs-workproduct-toolbar",children:e.jsxs("label",{className:"labs-search",children:[e.jsx(Ut,{size:14}),e.jsx("input",{"aria-label":"Search Datasets",placeholder:"Search Datasets",value:u,onChange:S=>{h(S.target.value),j(1)}})]})}),e.jsx("div",{className:"training-table-wrap",children:e.jsxs("table",{className:"training-data-table labs-datasets-table",children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{children:"Dataset"}),e.jsx("th",{children:"Training"}),e.jsx("th",{children:"Validation"}),e.jsx("th",{children:"Frozen Eval"}),e.jsx("th",{children:"Graders"}),e.jsx("th",{children:"Models"}),e.jsx("th",{children:"Updated"})]})}),e.jsx("tbody",{children:g.map(S=>{const v=y.get(S.id)??0;return e.jsxs("tr",{children:[e.jsx("td",{children:e.jsxs("button",{className:"labs-workproduct-link",type:"button",onClick:()=>i(S.id),children:[e.jsx("strong",{children:S.name}),e.jsx("span",{children:S.objective})]})}),e.jsx("td",{children:Bt(S,"train")}),e.jsx("td",{children:Bt(S,"validation")}),e.jsx("td",{children:Bt(S,"frozen_eval")}),e.jsx("td",{children:S.graders.length}),e.jsx("td",{children:v||"—"}),e.jsx("td",{children:jl(S.updatedAt)})]},S.id)})})]})}),g.length?null:e.jsx("div",{className:"labs-table-empty",children:"No Datasets match this view."}),e.jsx(bl,{page:d,total:k.length,onChange:j})]})}function Bt(t,s){return t.tasks.filter(n=>n.split===s).length}function fl(t){return t.readiness?.ready?"Ready":t.status==="ready"?"Needs Evals":t.status.replaceAll("_"," ").replace(/^./,s=>s.toUpperCase())}function jl(t){const s=new Date(t);return Number.isFinite(s.getTime())?s.toLocaleDateString(void 0,{month:"short",day:"numeric"}):"—"}function bl({page:t,total:s,onChange:n}){const i=Math.max(1,Math.ceil(s/Vt));return i===1?null:e.jsxs("nav",{className:"labs-pagination","aria-label":"Dataset pages",children:[e.jsx("button",{type:"button",disabled:t<=1,onClick:()=>n(t-1),children:"Previous"}),e.jsxs("span",{children:[t," of ",i]}),e.jsx("button",{type:"button",disabled:t>=i,onClick:()=>n(t+1),children:"Next"})]})}function vl({enabled:t,items:s,runs:n,nextScanAt:i,scanRunning:a,scanStartedAt:l,scanning:r,savingEnabled:o,error:u,onEnabledChange:h,onPatchStatus:d,onOpenSession:j}){const[x,m]=c.useState("all"),[k,g]=c.useState("all"),[y,S]=c.useState("all"),[v,N]=c.useState("all"),[R,T]=c.useState("all"),[J,L]=c.useState(()=>Date.now());c.useEffect(()=>{const O=window.setInterval(()=>L(Date.now()),1e3);return()=>window.clearInterval(O)},[]);const f=c.useMemo(()=>s.filter(O=>!(x!=="all"&&O.status!==x||k!=="all"&&O.severity!==k||y!=="all"&&nn(O)!==y)),[s,k,y,x]),_=c.useMemo(()=>n.filter(O=>!(v!=="all"&&O.status!==v||R!=="all"&&O.trigger!==R||y!=="all"&&!O.evidenceSources.includes(y))),[v,R,n,y]),ce=c.useMemo(()=>f.filter(O=>O.status==="active"),[f]),$=c.useMemo(()=>f.filter(O=>O.status!=="active"),[f]),se=x==="all"||x==="active",Q=x==="all"||x!=="active",E=r||a,H=`${x}:${k}:${y}`,ne=`${v}:${R}:${y}`;return e.jsxs("section",{className:"insights-view","aria-label":"Insights",children:[e.jsxs("section",{className:"insights-scan-preference","aria-label":"Observation scanning",children:[e.jsxs("div",{children:[e.jsx("strong",{children:"Observation scanning"}),e.jsx("span",{children:"Periodically review selected work, failures, and corrections for signals. It stays off until you turn it on."})]}),e.jsxs("div",{className:"insights-scan-controls",children:[e.jsxs("span",{className:`insights-scan-countdown ${E?"running":""}`,children:[e.jsx("span",{className:"insights-scan-dot","aria-hidden":"true"}),t?Ml(i,J,E):"Scanning is off"]}),e.jsx("button",{"aria-pressed":t,className:t?"active":void 0,disabled:o||E,type:"button",onClick:()=>{h(!t)},children:o?"Saving":t?"On":"Turn on"})]})]}),e.jsxs("div",{className:"insights-filters","aria-label":"Insight filters",children:[e.jsx(Ye,{label:"Observation status",options:yl,value:x,onChange:m}),e.jsx(Ye,{label:"Severity",options:Nl,value:k,onChange:g}),e.jsx(Ye,{label:"Source",options:kl,value:y,onChange:S}),e.jsx(Ye,{label:"Run status",options:Sl,value:v,onChange:N}),e.jsx(Ye,{label:"Run trigger",options:wl,value:R,onChange:T})]}),E?e.jsxs("div",{className:"insights-active-scan",role:"status",children:[e.jsx("span",{className:"insights-scan-dot","aria-hidden":"true"}),e.jsxs("div",{children:[e.jsx("strong",{children:"Active scan"}),e.jsx("span",{children:l?`Started ${Jt(l)}`:"Scanning insights now"})]})]}):null,u?e.jsx("div",{className:"insights-error",children:u}):null,e.jsx(Cl,{runs:_,paginationKey:ne,onOpenSession:j}),se?e.jsx(Rs,{title:"Active",emptyText:"No active Create/Improve insights match the filters.",items:ce,paginationKey:H,onPatchStatus:d,onOpenSession:j}):null,Q?e.jsx(Rs,{title:"Recent",emptyText:"No resolved or dismissed insights match the filters.",items:$,paginationKey:H,onPatchStatus:d,onOpenSession:j}):null]})}const yl=[{value:"all",label:"All"},{value:"active",label:"Active"},{value:"resolved",label:"Resolved"},{value:"dismissed",label:"Dismissed"}],Nl=[{value:"all",label:"All"},{value:"blocker",label:"Blocker"},{value:"concern",label:"Concern"},{value:"nit",label:"Nit"}],kl=[{value:"all",label:"All"},{value:"create_edit",label:"Create/Improve"},{value:"stuck_turn",label:"Stuck turns"},{value:"tool_failure",label:"Tools"},{value:"abandoned_goal",label:"Goals"},{value:"user_correction",label:"Corrections"},{value:"unresolved_conversation",label:"Unresolved"},{value:"usage_anomaly",label:"Usage"}],Sl=[{value:"all",label:"All"},{value:"running",label:"Running"},{value:"completed",label:"Completed"},{value:"failed",label:"Failed"},{value:"skipped",label:"Skipped"}],wl=[{value:"all",label:"All"},{value:"manual",label:"Manual"},{value:"interval",label:"Interval"},{value:"startup",label:"Startup"},{value:"slash_command",label:"Slash"}];function Ye({label:t,options:s,value:n,onChange:i}){return e.jsxs("label",{className:"insights-filter-group",children:[e.jsx("span",{children:t}),e.jsx("select",{value:n,onChange:a=>i(a.target.value),children:s.map(a=>e.jsx("option",{value:a.value,children:a.label},a.value))})]})}function Rs({title:t,emptyText:s,items:n,paginationKey:i,onPatchStatus:a,onOpenSession:l}){const r=tn(n,i);return e.jsxs("section",{className:"insights-section",children:[e.jsx("h2",{children:t}),n.length===0?e.jsx("p",{className:"insights-empty",children:s}):e.jsxs("div",{className:"insights-table-frame",children:[e.jsx("div",{className:"insights-table-scroll",children:e.jsxs("table",{className:"insights-table insights-observations-table",children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{scope:"col",children:"Severity"}),e.jsx("th",{scope:"col",children:"Status"}),e.jsx("th",{scope:"col",children:"Observation"}),e.jsx("th",{scope:"col",children:"Updated"}),e.jsx("th",{scope:"col",children:"Actions"})]})}),e.jsx("tbody",{children:r.pageItems.map(o=>e.jsxs("tr",{children:[e.jsx("td",{children:e.jsx("span",{className:`insights-severity ${o.severity}`,children:Il(o.severity)})}),e.jsx("td",{children:e.jsxs("div",{className:"insights-status-stack",children:[e.jsx("span",{children:o.status}),e.jsx("small",{children:Tl(nn(o))})]})}),e.jsx("td",{children:e.jsxs("div",{className:"insights-copy",children:[e.jsx("strong",{children:o.title}),e.jsx("span",{children:o.summary})]})}),e.jsx("td",{className:"insights-time",children:Jt(o.updatedAt)}),e.jsx("td",{children:e.jsxs("div",{className:"insights-actions",children:[As(o.payload.sessionId)?e.jsx("button",{type:"button",className:"insights-text-action",onClick:()=>l(As(o.payload.sessionId)),children:"Source"}):null,o.lastRunSessionId?e.jsx("button",{type:"button",className:"insights-text-action",onClick:()=>l(o.lastRunSessionId),children:"Run"}):null,o.status==="active"?e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",title:"Resolve observation","aria-label":"Resolve observation",onClick:()=>{a(o.id,"resolved")},children:e.jsx(zs,{size:15})}),e.jsx("button",{type:"button",title:"Dismiss observation","aria-label":"Dismiss observation",onClick:()=>{a(o.id,"dismissed")},children:e.jsx(Ve,{size:15})})]}):e.jsx("button",{type:"button",title:"Reopen observation","aria-label":"Reopen observation",onClick:()=>{a(o.id,"active")},children:e.jsx(Vs,{size:15})})]})})]},o.id))})]})}),e.jsx(sn,{label:t,...r})]})]})}function Cl({runs:t,paginationKey:s,onOpenSession:n}){const i=tn(t,s);return e.jsxs("section",{className:"insights-section",children:[e.jsx("h2",{children:"Runs"}),t.length===0?e.jsx("p",{className:"insights-empty",children:"No Insights runs yet."}):e.jsxs("div",{className:"insights-table-frame",children:[e.jsx("div",{className:"insights-table-scroll",children:e.jsxs("table",{className:"insights-table insights-runs-table",children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{scope:"col",children:"Trigger"}),e.jsx("th",{scope:"col",children:"Status"}),e.jsx("th",{scope:"col",children:"Model"}),e.jsx("th",{scope:"col",children:"Summary"}),e.jsx("th",{scope:"col",children:"Completed"}),e.jsx("th",{scope:"col",children:"Actions"})]})}),e.jsx("tbody",{children:i.pageItems.map(a=>e.jsxs("tr",{children:[e.jsx("td",{children:Rl(a.trigger)}),e.jsx("td",{className:"insights-status",children:a.status}),e.jsx("td",{className:"insights-status",children:Al(a)}),e.jsx("td",{children:e.jsxs("div",{className:"insights-copy",children:[e.jsx("strong",{children:a.summary??`${a.findingCount} finding${a.findingCount===1?"":"s"}`}),e.jsxs("span",{children:[a.createdCount," new / ",a.updatedCount," updated / ",a.resolvedCount," resolved"]})]})}),e.jsx("td",{className:"insights-time",children:Jt(a.completedAt??a.startedAt)}),e.jsx("td",{children:e.jsx("div",{className:"insights-actions",children:e.jsx("button",{type:"button",className:"insights-text-action",onClick:()=>n(a.sessionId),children:"Open run"})})})]},a.turnId))})]})}),e.jsx(sn,{label:"Runs",...i})]})]})}const mt=10;function tn(t,s){const[n,i]=c.useState(0);c.useEffect(()=>i(0),[s]);const a=Math.max(1,Math.ceil(t.length/mt)),l=Math.min(n,a-1),r=l*mt;return{pageItems:t.slice(r,r+mt),pageIndex:l,pageCount:a,pageStart:r,pageSize:mt,totalItems:t.length,onPageChange:i}}function sn({label:t,pageIndex:s,pageCount:n,pageStart:i,pageSize:a,totalItems:l,onPageChange:r}){return e.jsxs("nav",{className:"insights-pagination","aria-label":`${t} pagination`,children:[e.jsxs("span",{children:[i+1,"–",Math.min(i+a,l)," of ",l]}),e.jsxs("div",{children:[e.jsx("button",{type:"button",disabled:s===0,onClick:()=>r(s-1),children:"Previous"}),e.jsxs("span",{children:["Page ",s+1," of ",n]}),e.jsx("button",{type:"button",disabled:s>=n-1,onClick:()=>r(s+1),children:"Next"})]})]})}function Il(t){return t==="blocker"?"Blocker":t==="concern"?"Concern":"Nit"}function Ml(t,s,n){if(n)return"Scanning now";if(!t)return"Next scan not scheduled";const i=new Date(t).getTime();if(Number.isNaN(i))return"Next scan not scheduled";const a=i-s;if(a<=0)return"Next scan starting soon";const l=Math.ceil(a/6e4);return`${l} minute${l===1?"":"s"} till next scan`}function Rl(t){return t==="slash_command"?"Slash command":t==="startup"?"Startup":t==="interval"?"Interval":"Manual"}function Al(t){return t.modelRef?`${t.modelRef.providerId} / ${t.modelRef.modelId}`:"Default"}function nn(t){const s=t.payload.evidenceSource;return s==="create_edit"||s==="stuck_turn"||s==="tool_failure"||s==="abandoned_goal"||s==="user_correction"||s==="unresolved_conversation"||s==="usage_anomaly"?s:"create_edit"}function Tl(t){return t==="stuck_turn"?"Stuck turn":t==="tool_failure"?"Tool failures":t==="abandoned_goal"?"Abandoned goal":t==="user_correction"?"Corrections":t==="unresolved_conversation"?"Unresolved chat":t==="usage_anomaly"?"Usage":"Create/Improve"}function As(t){return typeof t=="string"&&t.trim()?t:null}function Jt(t){const s=new Date(t);return Number.isNaN(s.getTime())?t:new Intl.DateTimeFormat(void 0,{month:"short",day:"numeric",hour:"numeric",minute:"2-digit"}).format(s)}function _l({training:t,defaultModel:s,preferences:n,reasoningEffort:i,onPlanStarted:a}){const l=t.payload?.candidates??[];return e.jsxs("section",{className:"training-page-body training-suggestions",children:[e.jsxs("div",{children:[e.jsx("h2",{children:"AI suggestions"}),e.jsx("p",{children:"Review repeated work found by the local Task Miner before creating a training plan."})]}),l.length?e.jsx("div",{className:"training-card-grid",children:l.map(r=>e.jsx(El,{candidate:r,candidates:l,training:t,defaultModel:s,preferences:n,reasoningEffort:i,onPlanStarted:a},r.id))}):e.jsx("div",{className:"training-empty training-suggestions-empty",children:"No AI suggestions yet. Start New model with Automated to scan selected chats for repeated, verifiable work."})]})}function El({candidate:t,candidates:s,training:n,defaultModel:i,preferences:a,reasoningEffort:l,onPlanStarted:r}){const[o,u]=c.useState(""),h=s.filter(j=>j.id!==t.id&&j.status!=="retired");async function d(){const j=await n.actions.createCandidate(t.id,a.creationMode,$s(a,i),l);j&&(j.state==="awaiting_disclosure_approval"&&a.autoApproveEvidence&&await n.actions.approveDisclosure(j.id,!0),r())}return e.jsxs("article",{className:"training-card",children:[e.jsxs("div",{className:"training-card-heading",children:[e.jsx("strong",{children:t.title}),e.jsx("span",{className:"training-pill",children:t.recommendation.tactic.replaceAll("_"," ")})]}),e.jsx("p",{children:t.summary}),e.jsxs("dl",{children:[e.jsxs("div",{children:[e.jsx("dt",{children:"Frequency"}),e.jsx("dd",{children:pt(t.scorecard.frequency)})]}),e.jsxs("div",{children:[e.jsx("dt",{children:"Verifiable"}),e.jsx("dd",{children:pt(t.scorecard.verifiability)})]}),e.jsxs("div",{children:[e.jsx("dt",{children:"Signal"}),e.jsx("dd",{children:pt(t.scorecard.signalQuality)})]})]}),e.jsxs("details",{className:"training-evidence",children:[e.jsx("summary",{children:"Evidence and recommendation"}),e.jsx("p",{children:t.recommendation.reasons.join(" ")}),t.recommendation.blockers.map(j=>e.jsx("p",{className:"training-draft-warning",children:j},j)),e.jsx("ul",{children:t.evidence.map(j=>e.jsxs("li",{children:[e.jsx("strong",{children:j.kind.replaceAll("_"," ")})," — ",j.summary," (",pt(j.confidence),")"]},j.id))})]}),e.jsxs("div",{className:"training-inline-actions",children:[e.jsx("button",{className:"training-button",type:"button",disabled:!!n.busyAction,onClick:()=>{d()},children:"Create plan"}),e.jsx("button",{className:"training-text-button",type:"button",onClick:()=>{n.actions.patchCandidate(t.id,{status:"rejected"})},children:"Reject"}),e.jsx("button",{className:"training-text-button",type:"button",onClick:()=>{n.actions.patchCandidate(t.id,{status:"dismissed"})},children:"Dismiss"})]}),h.length?e.jsxs("div",{className:"training-merge-row",children:[e.jsxs("select",{"aria-label":`Merge ${t.title} into`,value:o,onChange:j=>u(j.target.value),children:[e.jsx("option",{value:"",children:"Merge into…"}),h.map(j=>e.jsx("option",{value:j.id,children:j.title},j.id))]}),e.jsx("button",{className:"training-text-button",type:"button",disabled:!o,onClick:()=>{n.actions.patchCandidate(t.id,{mergeIntoId:o})},children:"Merge"})]}):null]})}function pt(t){return`${Math.round(t*100)}%`}const Pl=10,$l=new Date(0).toISOString();function Dl({insights:t,suggestionsView:s,training:n,onSuggestionsViewChange:i,onPlanStarted:a}){return e.jsxs("section",{className:"labs-suggestions-page","aria-label":"Suggestions",children:[e.jsxs("div",{className:"labs-subtabs",role:"tablist","aria-label":"Suggestion types",children:[e.jsxs("button",{"aria-selected":s==="observations",className:s==="observations"?"active":void 0,role:"tab",type:"button",onClick:()=>i("observations"),children:["Observations"," ",e.jsx("span",{children:t.items.filter(l=>l.status==="active").length})]}),e.jsxs("button",{"aria-selected":s==="suggestions",className:s==="suggestions"?"active":void 0,role:"tab",type:"button",onClick:()=>i("suggestions"),children:["AI suggestions"," ",e.jsx("span",{children:n.training.payload?.candidates.length??0})]})]}),e.jsx("div",{className:"labs-suggestions-body",children:s==="observations"?e.jsx(vl,{...t}):e.jsx(_l,{training:n.training,defaultModel:n.defaultModel,preferences:n.preferences,reasoningEffort:n.reasoningEffort,onPlanStarted:a})})]})}function Bl({frontierBaselineRuns:t,items:s,loading:n,progressionByKey:i,showType:a,onSelect:l,onUseAgent:r,onUseModel:o,onUseSkill:u}){if(n)return e.jsxs("div",{className:"labs-table-empty",children:[e.jsx(fe,{className:"spin",size:16})," Loading workproducts…"]});if(!s.length)return e.jsx("div",{className:"labs-table-empty",children:"No workproducts match this view."});const h=new Map(t.map(d=>[d.id,d]));return e.jsx("div",{className:"training-table-wrap",children:e.jsxs("table",{className:`training-data-table labs-workproducts-table${a?"":" models-only"}`,children:[e.jsx("thead",{children:e.jsxs("tr",{children:[a?e.jsx("th",{children:"Type"}):null,e.jsx("th",{children:"Name"}),e.jsx("th",{children:"Status"}),e.jsx("th",{children:"Training"}),e.jsx("th",{children:"Evals"}),e.jsx("th",{children:"Updated"}),e.jsx("th",{children:e.jsx("span",{className:"sr-only",children:"Open"})})]})}),e.jsx("tbody",{children:s.map(d=>{const j=i.get(d.key),x=d.frontierBaselineRunId?h.get(d.frontierBaselineRunId)??null:null;return e.jsxs("tr",{onClick:()=>l(d.key),children:[a?e.jsx("td",{className:"labs-workproduct-type",children:ql(d.kind)}):null,e.jsx("td",{children:e.jsxs("button",{className:x?"labs-workproduct-link labs-training-run-name":"labs-workproduct-link",type:"button",onClick:()=>l(d.key),children:[e.jsx("strong",{children:d.name}),e.jsx("span",{children:d.description}),x?e.jsx(_i,{run:x,showOutcomes:!1}):null]})}),e.jsx("td",{children:e.jsx(je,{label:j?.statusLabel??d.status,value:j?.statusValue??d.status})}),e.jsx("td",{className:"labs-workproduct-training",children:Fl(d)}),e.jsx("td",{className:"labs-workproduct-evals",children:Ol(d)}),e.jsx("td",{className:"labs-workproduct-updated",children:d.updatedAt===$l?"—":an(d.updatedAt)}),e.jsx("td",{children:e.jsxs("div",{className:"labs-workproduct-actions",children:[d.kind==="skill"?e.jsx("button",{className:"settings-secondary compact labs-workproduct-use",type:"button",onClick:m=>{m.stopPropagation(),u(d.name)},children:"Use"}):d.kind==="agent"&&d.useActionId?e.jsx("button",{className:"settings-secondary compact labs-workproduct-use",type:"button",onClick:m=>{m.stopPropagation(),r(d.useActionId)},children:"Use"}):d.kind==="model"&&d.enabled!==null?e.jsx("button",{className:"settings-secondary compact labs-workproduct-use",type:"button",disabled:!d.enabled,title:d.enabled?"Start a bounded chat session with this model":"Chat is available after a version passes frozen evaluation",onClick:m=>{m.stopPropagation(),o(d.id)},children:"Chat"}):null,e.jsx(qs,{size:15})]})})]},d.key)})})]})})}function Ll({items:t,loading:s,runs:n,state:i,onSelect:a,onUseModel:l}){return s?e.jsxs("div",{className:"labs-table-empty",children:[e.jsx(fe,{className:"spin",size:16})," Loading Models…"]}):t.length?e.jsx("div",{className:"training-table-wrap",children:e.jsxs("table",{className:"training-data-table labs-models-table",children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{children:"Model"}),e.jsx("th",{children:"Active"}),e.jsx("th",{children:"Eval"}),e.jsx("th",{children:"Versions"}),e.jsx("th",{children:"Updated"}),e.jsx("th",{children:e.jsx("span",{className:"sr-only",children:"Actions"})})]})}),e.jsx("tbody",{children:t.map(r=>{const o=qe(r,n,i),u=o.find(d=>d.current)??null,h=o[0]??null;return e.jsxs("tr",{onClick:()=>a(r.key),children:[e.jsx("td",{children:e.jsxs("button",{className:"labs-workproduct-link",type:"button",onClick:()=>a(r.key),children:[e.jsx("strong",{children:r.name}),e.jsx("span",{children:r.description})]})}),e.jsx("td",{children:u?`Version ${u.number} · ${$e(u.plan?.recipe.method)}`:"Not selected"}),e.jsx("td",{children:e.jsx(je,{label:h?h.lineage.promotable?"Passed":h.lineage.frozenEvaluationArtifactId?"Failed":"Not run":"Not run",value:h?.lineage.promotable?"passed":h?.lineage.frozenEvaluationArtifactId?"failed":"not_run"})}),e.jsx("td",{children:o.length}),e.jsx("td",{children:an(r.updatedAt)}),e.jsx("td",{children:e.jsxs("div",{className:"labs-workproduct-actions",children:[e.jsx("button",{className:"settings-secondary compact labs-workproduct-use",disabled:!u,title:u?"Chat with the active Version":"Set a passing Version active before Chat",type:"button",onClick:d=>{d.stopPropagation(),l(r.id)},children:"Chat"}),e.jsx(qs,{size:15})]})})]},r.key)})})]})}):e.jsx("div",{className:"labs-table-empty",children:"No Models yet."})}function Fl(t){if(t.kind!=="model")return e.jsx("span",{className:"labs-workproduct-na",title:"Training not applicable",children:"—"});const s=`${t.trainingRunCount} training ${t.trainingRunCount===1?"run":"runs"}`;return e.jsxs("span",{className:`labs-workproduct-indicator${t.trainingRunCount>0?" active":""}`,title:s,children:[e.jsx(Os,{"aria-hidden":"true",size:15}),e.jsx("strong",{"aria-hidden":"true",children:t.trainingRunCount}),e.jsx("span",{className:"sr-only",children:s})]})}function Ol(t){const s=t.evaluationStatus==="passed"?{icon:e.jsx(zs,{"aria-hidden":"true",size:16}),label:"Evals passed",tone:"positive"}:t.evaluationStatus==="failed"?{icon:e.jsx(zn,{"aria-hidden":"true",size:16}),label:"Evals failed",tone:"negative"}:{icon:e.jsx(qn,{"aria-hidden":"true",size:16}),label:"Evals not run",tone:"neutral"};return e.jsxs("span",{className:`labs-workproduct-indicator ${s.tone}`,title:s.label,children:[s.icon,e.jsx("span",{className:"sr-only",children:s.label})]})}function an(t){const s=new Date(t),n=new Date;return s.toDateString()===n.toDateString()?new Intl.DateTimeFormat(void 0,{hour:"numeric",minute:"2-digit"}).format(s):new Intl.DateTimeFormat(void 0,{month:"short",day:"numeric",...s.getFullYear()===n.getFullYear()?{}:{year:"2-digit"}}).format(s)}function zl({page:t,total:s,onChange:n}){const i=Math.max(1,Math.ceil(s/Pl));return i<=1?null:e.jsxs("nav",{className:"labs-pagination","aria-label":"Pagination",children:[e.jsx("button",{type:"button",disabled:t<=1,onClick:()=>n(t-1),children:"Previous"}),e.jsxs("span",{children:[t," of ",i]}),e.jsx("button",{type:"button",disabled:t>=i,onClick:()=>n(t+1),children:"Next"})]})}async function Ts(t,s,n,i){if(s.onLaunchHandled(s.launchRequest?.id??0),!t.materializedTasksetId)return;s.onSelectedTasksetIdChange(t.materializedTasksetId),s.onDetailTasksetIdChange(t.materializedTasksetId);const l=(await n())?.find(r=>r.id===t.request.createImproveRunId);i(Ee("model",l?.target.kind==="model"?l.target.id??l.id:t.materializedTasksetId))}function _s(t,s){return t.request.objective?.trim()||t.proposal?.objective.trim()||t.proposal?.name.trim()||s}function ql(t){return t&&`${t[0].toUpperCase()}${t.slice(1).replaceAll("_"," ")}`}function Vl(t){return t?[...t.jobs.map(s=>`job:${s.id}:${s.status}`),...t.models.map(s=>`model:${s.id}:${s.status}:${s.artifactId}:${s.jobId}`)].sort().join("|"):""}const Es=10;function er({closeDetailKind:t,closeDetailRequestId:s,insights:n,onAnswerQuestion:i,onApplyCandidate:a,onApprove:l,onCancel:r,candidateReview:o,onCandidateReviewChange:u,onCreateAgent:h,onDetailOpenChange:d,onImproveAgent:j,onNewModel:x,onOpenPullRequest:m,onOpenCandidateFiles:k,onOpenRunConversation:g,onPause:y,onReconcilePullRequest:S,onRejectCandidate:v,onResume:N,onRevise:R,onUseAgent:T,openSuggestionsRequestId:J,profileView:L,training:f}){const _=L.payload?.profile??null,ce=_?.activeProfile??"default",$=_a({connection:L.connection,profileId:ce}),se=c.useMemo(()=>Vl(f.training.payload),[f.training.payload]),[Q,E]=c.useState("workproducts"),[H,ne]=c.useState("observations"),[O,ie]=c.useState(1),[re,W]=c.useState(null),[Y,z]=c.useState(null),[ae,K]=c.useState(!1),[X,V]=c.useState(!1),[oe,ue]=c.useState(null),[he,ee]=c.useState(null),[Ce,P]=c.useState(null),[D,de]=c.useState(null),te=c.useMemo(()=>Gs({profile:_,training:f.training.payload,runs:$.runs}),[$.runs,_,f.training.payload]),be=c.useMemo(()=>{const w=new Map((f.training.payload?.tasksets??[]).map(F=>[F.id,F]));return new Map(te.map(F=>[F.key,Zs({workproduct:F,runs:Hs(F,$.runs),taskset:F.tasksetId?w.get(F.tasksetId)??null:null,training:f.training.payload})]))},[$.runs,f.training.payload,te]),Te=c.useMemo(()=>te.filter(w=>w.kind!=="model"),[te]),I=c.useMemo(()=>te.filter(w=>w.kind==="model"),[te]),U=te.find(w=>w.key===re)??null,xe=n.items.filter(w=>w.status==="active").length+(f.training.payload?.candidates.length??0);c.useEffect(()=>{se&&$.refresh()},[$.refresh,se]),c.useEffect(()=>{J<=0||(ne("observations"),E("suggestions"))},[J]),c.useEffect(()=>{re&&!te.some(w=>w.key===re)&&W(null)},[re,te]),c.useEffect(()=>{if(!(s<=0)){if(W(null),t==="dataset"){z(null),E("datasets");return}E("workproducts")}},[t,s]),c.useEffect(()=>{if(Q==="datasets"){d(Y?{kind:"dataset",kindLabel:"Datasets",workproductLabel:f.training.payload?.tasksets.find(w=>w.id===Y)?.name??"Dataset",sectionLabels:[]}:null);return}if(Q!=="workproducts"){d(null);return}U||d(null)},[Q,d,U,Y,f.training.payload?.tasksets]),c.useEffect(()=>()=>d(null),[d]);function pe(w){W(null),ie(1),z(null),E(w)}function ve(w,F=""){const A=te.find(q=>q.kind==="agent"&&q.id===w);de({agentId:w,agentName:A?.name??w,initialObjective:F.trim()})}function ge(w){const F=te.find(Z=>Z.kind==="model"&&Z.id===w);if(!F)return;const A=qe(F,$.runs,f.training.payload),q=A.find(Z=>Z.current)??A.find(Z=>Z.lineage.promotable)??null;if(!q?.taskset)return;if(f.training.payload?.jobs.find(Z=>Z.id===q.lineage.jobId)?.destinationId==="fireworks"){P(q.lineage.id);return}f.onChatWithModel(ft({modelId:q.lineage.id,taskset:q.taskset}))}return e.jsxs(Yi,{activeTab:Q,showHeader:!U&&!Y,suggestionCount:xe,onTabChange:pe,onCreateAgent:()=>K(!0),onCreateDataset:()=>V(!0),onCreateModel:x,children:[Q==="suggestions"?e.jsx(Dl,{insights:n,suggestionsView:H,training:f,onSuggestionsViewChange:ne,onPlanStarted:()=>E("workproducts")}):Q==="datasets"?e.jsx(xl,{runs:$.runs,selectedId:Y,state:f.training.payload,training:f.training,onToast:(w,F)=>L.onToast?.(w,F)??0,onSelectedIdChange:z,onCreate:()=>V(!0),onOpenFiles:w=>{f.onSelectedTasksetIdChange(w),f.onOpenTasksetFiles()}}):U?e.jsx(Qi,{connection:L.connection,profile:_,runs:$.runs,training:f.training,workproduct:U,onAnswerQuestion:i,onApplyCandidate:a,onApprove:l,onCancel:r,candidateReview:o,onCandidateReviewChange:u,onChatWithModel:f.onChatWithModel,onOpenPullRequest:m,onOpenCandidateFiles:k,onOpenConversation:g,onLocationChange:d,onRenameAgent:()=>ue({id:U.id,name:U.name}),onOpenDataset:w=>{W(null),z(w),E("datasets")},onPause:y,onReconcilePullRequest:S,onRejectCandidate:v,onResume:N,onRevise:R,onStartAgentChange:(w,F)=>ve(w,F??""),onToast:f.onToast}):e.jsxs("div",{className:"labs-flat-body",children:[$.error?e.jsx("div",{className:"training-banner error",children:$.error}):null,Q==="workproducts"?e.jsx("div",{className:"labs-home-profile-controls",children:e.jsx(ta,{...L,section:"controls"})}):null,e.jsx(Bl,{frontierBaselineRuns:f.training.payload?.frontierBaselineRuns??[],loading:$.loading&&!te.length,items:Te.slice((O-1)*Es,O*Es),progressionByKey:be,showType:!0,onSelect:W,onUseAgent:T,onUseModel:ge,onUseSkill:w=>L.onSkillCommand?.(`$${w} `)}),e.jsx(zl,{page:O,total:Te.length,onChange:ie}),Q==="workproducts"?e.jsxs("section",{className:"labs-home-models",children:[e.jsx("div",{className:"labs-section-heading",children:e.jsx("h2",{children:"Models"})}),e.jsx(Ll,{loading:!1,items:I.slice(0,10),runs:$.runs,state:f.training.payload,onSelect:W,onUseModel:ge})]}):null]}),f.launchRequest&&f.training.payload?e.jsx(Je,{defaultModel:f.defaultModel,initialObjective:f.launchRequest.objective,initialSessionIds:f.launchRequest.initialSessionIds??[],localProjects:f.localProjects??[],onClose:()=>f.onLaunchHandled(f.launchRequest.id),onModelCreatedFromTaskset:async(w,F)=>{f.onLaunchHandled(f.launchRequest.id),f.onSelectedTasksetIdChange(w.id),f.onDetailTasksetIdChange(w.id),W(Ee("model",F.target.id??F.id)),E("workproducts"),await $.refresh()},onTasksetCreated:async w=>{await Ts(w,f,$.refresh,W),E("workproducts")},preferences:f.preferences,providerSettings:f.providerSettings,reasoningEffort:f.reasoningEffort,sessions:f.sessions,sources:f.training.payload.sources,training:f.training}):null,ae?e.jsx(Je,{defaultModel:f.defaultModel,initialObjective:null,localProjects:f.localProjects??[],onClose:()=>K(!1),onTasksetCreated:async w=>{const F=_s(w,"Create a useful Agent from the approved Taskset."),A=await h(F,w.request.createImproveRunId);await $.refresh(),E("workproducts"),W(Ee("agent",A.target.id??A.id)),K(!1)},preferences:f.preferences,providerSettings:f.providerSettings,reasoningEffort:f.reasoningEffort,sessions:f.sessions,sources:f.training.payload?.sources??[],targetIntent:{kind:"agent",id:null,displayName:null,operation:"create"},training:f.training}):null,X?e.jsx(Je,{defaultModel:f.defaultModel,initialObjective:null,localProjects:f.localProjects??[],onClose:()=>V(!1),onTasksetCreated:async w=>{V(!1),W(null),E("datasets"),z(w.materializedTasksetId),await $.refresh()},preferences:f.preferences,providerSettings:f.providerSettings,reasoningEffort:f.reasoningEffort,resourceIntent:"dataset",sessions:f.sessions,sources:f.training.payload?.sources??[],targetIntent:{kind:null,id:null,displayName:null,operation:"create"},training:f.training}):null,D?e.jsx(Je,{defaultModel:f.defaultModel,initialObjective:D.initialObjective,localProjects:f.localProjects??[],onClose:()=>de(null),onTasksetCreated:async w=>{const F=_s(w,D.initialObjective);await j(D.agentId,F,D.agentName,w.request.createImproveRunId),await $.refresh(),E("workproducts"),W(Ee("agent",D.agentId)),de(null)},preferences:f.preferences,providerSettings:f.providerSettings,reasoningEffort:f.reasoningEffort,sessions:f.sessions,sources:f.training.payload?.sources??[],targetIntent:{kind:"agent",id:D.agentId,displayName:D.agentName,operation:"improve"},training:f.training}):null,he?e.jsx(Je,{defaultModel:f.defaultModel,initialCreation:he,initialObjective:he.request.objective,localProjects:f.localProjects??[],onClose:()=>ee(null),onTasksetCreated:async w=>{await Ts(w,f,$.refresh,W),E("workproducts"),ee(null)},preferences:f.preferences,providerSettings:f.providerSettings,reasoningEffort:f.reasoningEffort,sessions:f.sessions,sources:f.training.payload?.sources??[],targetIntent:he.request.targetIntent,training:f.training}):null,Ce?(()=>{const w=f.training.payload?.models.find(A=>A.id===Ce),F=f.training.payload?.tasksets.find(A=>A.id===w?.tasksetId);return!w||!F?null:e.jsx(Ks,{lineage:w,taskset:F,training:f.training,onChat:f.onChatWithModel,onClose:()=>P(null)})})():null,oe?e.jsx(Xi,{agentId:oe.id,currentName:oe.name,onClose:()=>ue(null),onRename:async w=>{if(!L.connection)throw new Error("Connect OpenPond before renaming an agent.");L.onError(null),await et.profileAgentRename(L.connection,oe.id,{name:w}),L.onPayload(await et.bootstrap(L.connection)),L.onToast?.(`Renamed agent to ${w}.`,"success")}}):null]})}export{er as LabsRoute};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{j as e,X as N,C as b,s as
|
|
1
|
+
import{j as e,X as N,C as b,s as f,af as P}from"./index-CKmte5ok.js";function w({open:d,mode:i="local",name:s,path:r,directory:n,busy:t,onNameChange:c,onPathChange:j,onClose:p,onSubmit:g}){if(!d)return null;const o=i==="cloud",l=i==="existing-local",u=o?b:l?f:P,x=o?"New Cloud Project":l?"Use Existing Folder":"New Local Project",h=o?"Create a hosted project in OpenPond Cloud.":l?"Add an existing local project folder to Projects.":"Create a new local Git project and add it to Projects.",m=t||(l?!r.trim():!s.trim()),C=t?l?"Adding":"Creating":o?"Create Cloud Project":l?"Add project":"Create project";return e.jsx("div",{className:"git-dialog-backdrop",role:"presentation",children:e.jsxs("form",{className:"git-dialog new-project-dialog","aria-label":l?"Add existing project":"Create project",onSubmit:a=>{a.preventDefault(),g()},children:[e.jsx("button",{className:"git-dialog-close",disabled:t,type:"button",onClick:p,children:e.jsx(N,{size:14})}),e.jsx("div",{className:"git-dialog-icon",children:e.jsx(u,{size:18})}),e.jsx("h2",{children:x}),e.jsx("p",{children:h}),l?e.jsxs("label",{className:"git-dialog-field",children:[e.jsx("span",{children:"Folder path"}),e.jsx("input",{autoFocus:!0,disabled:t,placeholder:"/home/user/project",value:r,onChange:a=>j(a.target.value)})]}):e.jsxs(e.Fragment,{children:[e.jsxs("label",{className:"git-dialog-field",children:[e.jsx("span",{children:"Project name"}),e.jsx("input",{autoFocus:!0,disabled:t,placeholder:"New project",value:s,onChange:a=>c(a.target.value)})]}),e.jsxs("div",{className:"git-dialog-row",children:[e.jsx("span",{children:"Location"}),e.jsx("strong",{className:"git-dialog-path",children:o?"OpenPond Cloud":n})]})]}),e.jsx("button",{className:"git-dialog-primary full",disabled:m,type:"submit",children:C})]})})}export{w as NewProjectDialog};
|