diff --git a/extensions/workflows/sandbox-child.cjs b/extensions/workflows/sandbox-child.cjs index 467ca2aa5..501d1af66 100644 --- a/extensions/workflows/sandbox-child.cjs +++ b/extensions/workflows/sandbox-child.cjs @@ -433,3 +433,18 @@ function run(source, argsJson, maxConcurrency, initSeq) { fail(error); } } + +function announceListening() { + // No token yet. The parent arms the sync watchdog only after this message, + // so process startup is not charged against the script deadline. + sendIpc?.({ kind: "listening" }); +} + +const startDelay = Number(process.env.OPENPI_SANDBOX_START_DELAY_MS); +if (Number.isFinite(startDelay) && startDelay > 0) { + // Keep the timer referenced. IPC also holds the process, but an unref'd + // delay must not be the reason a child exits before it can listen. + setTimeout(announceListening, startDelay); +} else { + announceListening(); +} diff --git a/extensions/workflows/sandbox.ts b/extensions/workflows/sandbox.ts index 81f242ee5..e89748e0b 100644 --- a/extensions/workflows/sandbox.ts +++ b/extensions/workflows/sandbox.ts @@ -75,6 +75,12 @@ export interface RunWorkflowSandboxOptions { * mid-run — losing the aggregate that resuming exists to preserve. */ extraAgentRequests?: number; + /** + * Delay before the child announces it is listening. Process startup stays + * outside the synchronous-execution watchdog. Tests use this to show a slow + * spawn is not reported as a script timeout. + */ + startDelayMs?: number; } function byteLength(value: string) { @@ -192,6 +198,15 @@ export function runWorkflowSandbox(options: RunWorkflowSandboxOptions) { env: { PATH: process.env.PATH ?? "", NODE_NO_WARNINGS: "1", + ...(typeof options.startDelayMs === "number" && + Number.isFinite(options.startDelayMs) && + options.startDelayMs > 0 + ? { + OPENPI_SANDBOX_START_DELAY_MS: String( + Math.floor(options.startDelayMs), + ), + } + : {}), }, stdio: ["ignore", "ignore", "ignore", "ipc"], }, @@ -201,6 +216,7 @@ export function runWorkflowSandbox(options: RunWorkflowSandboxOptions) { const activeAgentRequests = new Map(); let requestCount = 0; let finished = false; + let scriptStarted = false; let executionSeq = 0; let executionWatchdog: NodeJS.Timeout | undefined; @@ -272,12 +288,40 @@ export function runWorkflowSandbox(options: RunWorkflowSandboxOptions) { ); } }); + const beginExecution = () => { + if (finished || scriptStarted) return; + scriptStarted = true; + // The 1s budget covers non-yielding script after the child is listening. + // Spawn and module load are a precondition, not part of that deadline. + const initSeq = armWatchdog(); + child.send( + { + kind: "init", + token, + source: options.source, + argsJson, + maxConcurrency: options.maxConcurrency, + usageJson: usageJson(), + seq: initSeq, + }, + (error) => { + if (error) finish(error); + }, + ); + }; + child.on("message", (raw: unknown) => { - if ( - !isRecord(raw) || - raw.token !== token || - typeof raw.kind !== "string" - ) { + if (!isRecord(raw) || typeof raw.kind !== "string") { + finish(new Error("Workflow sandbox sent an invalid IPC message")); + return; + } + // The child has no token yet. A later listening message is ignored so it + // cannot fall through and kill a run that already started. + if (raw.kind === "listening") { + beginExecution(); + return; + } + if (raw.token !== token) { finish(new Error("Workflow sandbox sent an invalid IPC message")); return; } @@ -437,24 +481,5 @@ export function runWorkflowSandbox(options: RunWorkflowSandboxOptions) { } finish(new Error("Workflow sandbox sent an unknown IPC message")); }); - - // Arm the synchronous execution watchdog for the initial script invocation - // (covers non-yielding code before and after initial microtask yields). - const initSeq = armWatchdog(); - - child.send( - { - kind: "init", - token, - source: options.source, - argsJson, - maxConcurrency: options.maxConcurrency, - usageJson: usageJson(), - seq: initSeq, - }, - (error) => { - if (error) finish(error); - }, - ); }); } diff --git a/tests/extensions/workflows/sandbox.test.ts b/tests/extensions/workflows/sandbox.test.ts index 049bb971f..67b2faf42 100644 --- a/tests/extensions/workflows/sandbox.test.ts +++ b/tests/extensions/workflows/sandbox.test.ts @@ -55,6 +55,19 @@ async function runWithTimeout( } } +test("a slow sandbox start is outside the synchronous execution deadline", async () => { + const started = Date.now(); + assert.equal(await run("return 1;", { startDelayMs: 1_500 }), 1); + assert.ok(Date.now() - started >= 1_500); +}); + +test("a delayed start still stops a non-yielding script at the sync deadline", async () => { + await assert.rejects( + runWithTimeout("while (true) {}", { startDelayMs: 1_500 }, 8_000), + /Script execution timed out/, + ); +}); + test("sandbox exposes only workflow capabilities and validates results", async () => { const phases: string[] = []; let active = 0; diff --git a/tests/web/composer-context-navigation.spec.ts b/tests/web/composer-context-navigation.spec.ts index 4c8948f90..c1f5bc409 100644 --- a/tests/web/composer-context-navigation.spec.ts +++ b/tests/web/composer-context-navigation.spec.ts @@ -160,7 +160,7 @@ async function openFileReference( return reference; } -it("opens source picking without replacing the draft and rejects another session path", async () => { +it("opens source picking without replacing the draft and rejects another session path", () => { const { input, update, sendPrompt } = setup(); fireEvent.change(input, { target: { value: "keep this draft" } }); update({ @@ -180,8 +180,11 @@ it("opens source picking without replacing the draft and rejects another session revision: 2, }, }); + // The matching request opens the menu in the same flushed render. Polling + // here spends the suite timeout when timers stall, without protecting a + // later readiness condition. expect( - await screen.findByRole("menuitem", { name: /Reference workspace file/u }), + screen.getByRole("menuitem", { name: /Reference workspace file/u }), ).toBeTruthy(); expect(input.value).toBe("keep this draft"); expect(sendPrompt).not.toHaveBeenCalled(); diff --git a/tests/web/session-sidebar.spec.ts b/tests/web/session-sidebar.spec.ts index d2c4b57e4..ab53367d0 100644 --- a/tests/web/session-sidebar.spec.ts +++ b/tests/web/session-sidebar.spec.ts @@ -253,6 +253,9 @@ it("offers an empty pin drop area during a project drag and suppresses the trail expect(within(pinned).getByText(i18n.t("sidebarDropPin"))).toBeTruthy(); dragPointer(pinned, "dragover"); dragPointer(pinned, "drop"); + // Longer than the old 250ms suppression window. A trailing click still must + // not toggle the workspace after a slow post-drop render. + await new Promise((resolve) => setTimeout(resolve, 300)); await waitFor(() => expect(pin).toHaveBeenCalledWith( { kind: "workspace", path: "/project-1" }, diff --git a/web/dist/app.js b/web/dist/app.js index 1eec5bd17..8c1bb9e2e 100644 --- a/web/dist/app.js +++ b/web/dist/app.js @@ -96,7 +96,7 @@ In order to be iterable, non-array objects must have a [Symbol.iterator]() metho `:``}${o}`;if(!xe({prompt:l,caret:l.length}))return;F(null),O(!0),queueMicrotask(()=>{c.current.key===b&&(pe.current?.focus(),pe.current?.setSelectionRange(l.length,l.length))});return}H.current?.focus(),F(`files`)}},[e.addSourcesRequest,We,n?.id,n?.path,b,t,xe]),(0,_.useEffect)(()=>{We||(_e.current=!1,N(!1))},[We]);let Ke=async e=>{if(!We||c.current.key!==b)return;let n=[...e];if(n.length===0)return;let r=ge.current;if(f.current.images.length+(f.current.files?.length??0)+(r?.files.length??0)+n.length>8){ie(t(`fileAttachmentCount`,{count:8}));return}if(r){r.files.push(...n);return}let i={ownerKey:c.current.key,files:n,staged:[],stagedFiles:[],controller:new AbortController};ge.current=i,ne(!0),ie(null);try{for(let e of i.files){let n=/^image\/(?:png|jpeg|gif|webp)$/iu.test(e.type);try{if(n||=!!of(new Uint8Array(await e.slice(0,12).arrayBuffer())),!n){let t=await dM(e,i.controller.signal);if(ge.current!==i||c.current.key!==i.ownerKey)return;if([...f.current.files??[],...i.stagedFiles].reduce((e,t)=>e+t.size,t.size)>52428800)throw Error(`file-total-size`);i.stagedFiles.push(t);continue}if(f.current.images.length+i.staged.length>=8)throw Error(`image-count`);let t=await cf(e);if(ge.current!==i||c.current.key!==i.ownerKey)return;if([...f.current.images,...i.staged].reduce((e,t)=>e+t.size,t.size)>33554432)throw Error(`image-total-size`);i.staged.push(t)}catch(r){if(ge.current!==i)return;let a=r instanceof Error?r.message:`image-type`,o=a===`file-size`||a===`file-total-size`?t(`fileAttachmentTooLarge`):a===`image-count`?t(`imageAttachmentCount`,{count:8}):t(n?a===`image-size`?`imageAttachmentTooLarge`:a===`image-total-size`?`imageAttachmentTotalTooLarge`:a===`image-read`?`imageAttachmentReadFailed`:`imageAttachmentUnsupported`:`fileAttachmentReadFailed`);ie(`${e.name||t(`attachedImage`)}: ${o}`)}}(i.staged.length>0||i.stagedFiles.length>0)&&xe({images:[...f.current.images,...i.staged],files:[...f.current.files??[],...i.stagedFiles]},i.ownerKey)}finally{ge.current===i&&(ge.current=null,ne(!1),he.current&&(he.current.value=``))}};(0,_.useEffect)(()=>{let t=Le&&!be.current;be.current=Le,!(!Le||e.workspaceDraft||!Re||Fe.status!==`idle`&&!(t&&Fe.status===`error`))&&e.actions.discoverCommands()},[Fe.status,Le,e.actions,e.workspaceDraft,Re]),(0,_.useEffect)(()=>{let e=Ve.findIndex(e=>e.availability===`available`);j(e)},[Ve]),(0,_.useEffect)(()=>{let n=e.promptAdmissionRecovery??e.restoredPromptDraft;if(!n||ye.current===n.commandId)return;ye.current=n.commandId,S.current=null;let r=JSON.stringify([`session`,n.sessionId,n.sessionPath]),i=x.current.get(r),a=n.images??[];if(i?.content.trim()===n.content&&i.images.length===a.length&&i.images.every((e,t)=>e.data===a[t]?.data&&e.mimeType===a[t]?.mimeType&&e.name===a[t]?.name)){S.current={commandId:n.commandId,key:r,revision:i.revision};return}let s=c.current.key===r?f.current:o.read(r);if(s.prompt||s.images.length>0||s.files?.length)return;let l=(n.images??[]).map(e=>({...e,id:globalThis.crypto?.randomUUID?.()??`${n.commandId}-${e.name}`,name:e.name??t(`attachedImage`),size:atob(e.data).length,previewUrl:`data:${e.mimeType};base64,${e.data}`})),u=o.edit(r,s,{prompt:n.content,images:l,caret:n.content.length});if(!u){c.current.key===r&&ie(t(`draftLimit`));return}S.current={commandId:n.commandId,key:r,revision:u.revision},c.current.key===r&&(f.current=u,d(u)),e.restoredPromptDraft?.commandId===n.commandId&&e.actions.acknowledgeRestoredPromptDraft(n.commandId)},[o,e.actions,e.promptAdmissionRecovery,e.restoredPromptDraft,t]),(0,_.useEffect)(()=>{let t=e.promptAdmissionResolution;if(!t)return;let n=S.current,r=JSON.stringify([`session`,t.sessionId,t.sessionPath]),i=x.current.get(r),a=t.images??[],s=i?.content.trim()===t.content&&i.images.length===a.length&&i.images.every((e,t)=>e.data===a[t]?.data&&e.mimeType===a[t]?.mimeType&&e.name===a[t]?.name),l=n?.key===r&&n.commandId===t.commandId?n.revision:s?i.revision:void 0;if(l!==void 0){let e=o.clear(r,l);e&&c.current.key===r&&(f.current=e,d(e))}n?.commandId===t.commandId&&(S.current=null),e.actions.acknowledgePromptAdmissionResolution(t.commandId)},[o,e.actions,e.promptAdmissionResolution]);let qe=async(n,r=!1,i,a)=>{if(x.current.get(c.current.key)?.pending||ge.current||e.planSelectionPending)return;if(!e.selectedWorkspace){await e.actions.chooseWorkspace();return}if(b!==c.current.key)return;let s=f.current,l={revision:s.revision,owner:c.current,pending:!0,content:s.prompt,images:s.images};x.current.set(l.owner.key,l);let u=!1,p=!1;try{let m=s.prompt,h=null;if(Te&&!Ce&&(h=await e.actions.prepareSession(),!h||l.owner.kind!==`session`||h.sessionId!==l.owner.sessionId||h.sessionPath!==l.owner.sessionPath||c.current.key!==l.owner.key))return;if(s.files?.length){if(p=!0,ne(!0),ie(null),h??=await e.actions.prepareSession(),!h?.sessionPath)return;let n=await V.uploadPromptFiles(h.sessionId,h.sessionPath,s.files.map(({name:e,data:t,mimeType:n,text:r})=>({name:e,data:t,mimeType:n,...r===void 0?{}:{text:r}})));if(n.sessionId!==h.sessionId||n.sessionPath!==h.sessionPath||c.current.key!==l.owner.key||n.files.length!==s.files.length||n.files.some((e,t)=>e.name!==s.files?.[t]?.name||e.size!==s.files?.[t]?.size))return;let r=n.files.map((e,n)=>`${JSON.stringify(e.name)}: ${YM(e.path,e.path)}${e.textPath?`\n ${t(`fileAttachmentExtractedContent`)}${s.files?.[n]?.extraction===`truncated`?` (${t(`fileAttachmentTextTruncated`)})`:``}: ${YM(e.textPath,e.textPath)}`:``}`).join(` `);if(m=`${m.trim()}${m.trim()?` -`:``}${t(`fileAttachmentPromptLabel`)}\n${r}`,m.length>12e3){ie(t(`fileAttachmentPromptTooLong`));return}l.content=m}if(u=h?await n(m,s.images,i,a,h):a?await n(m,s.images,i,a):i?await n(m,s.images.length>0||r?s.images:void 0,i):r||s.images.length>0?await n(m,s.images):await n(m),u){a?.streamingBehavior===`steer`&&W(null),i===me.current&&(me.current=null);let e=o.clear(l.owner.key,l.revision);e&&c.current.key===l.owner.key&&(f.current=e,d(e),ie(null))}}catch(e){c.current.key===l.owner.key&&ie(e instanceof Error?e.message:t(`fileAttachmentReadFailed`))}finally{p&&c.current.key===l.owner.key&&!ge.current&&ne(!1),l.pending=!1;let e=o.read(l.owner.key);(u||!e.prompt&&e.images.length===0&&!e.files?.length)&&x.current.get(l.owner.key)===l&&x.current.delete(l.owner.key)}},Je=async n=>{if(n?.preventDefault(),!G||e.sessionSwitching||e.modelSelectionPending||e.planSelectionPending||e.thinkingPendingLevel!==null||e.promptAdmissionPending||e.promptAdmissionRecovery||e.promptAdmissionResolution||y||!p.trim()&&m.length===0&&h.length===0||ge.current)return;if(Ne&&(!je||Ae?.commandId!==Ne.expectedTurnCommandId||me.current)){U(t(`steerStaleTurn`));return}let r=/^\/([^\s/]+)/u.exec(p.trim())?.[1],i=Fe.commands.find(e=>e.name===r);if(i?.availability===`unsupported`){U(`/${i.name}: ${t(`commandUnavailable_${i.unavailableReason??`not_integrated`}`)}`);return}if(i?.action){if(p.trim()!==`/${i.name}`||m.length>0||h.length>0){U(t(`commandPanelArguments`));return}if(e.onCommandAction?.(i.action)!==!0){U(t(`commandPanelUnavailable`));return}xe({prompt:``,caret:0}),U(null);return}U(null),await qe(e.actions.sendPrompt,!1,me.current??void 0,Ne?{streamingBehavior:`steer`,expectedTurnCommandId:Ne.expectedTurnCommandId}:void 0)},Ye=()=>{if(!(!Ce||e.sessionSwitching||e.modelSelectionPending||e.thinkingPendingLevel!==null||y))return qe(e.actions.sendPromptAsNew,!0)},Xe=e=>{if(e.availability!==`available`)return;let t=`/${e.name} `;xe({prompt:t,caret:t.length})&&(U(null),O(!0),queueMicrotask(()=>{c.current.key===b&&(pe.current?.focus(),pe.current?.setSelectionRange(t.length,t.length))}))},Ze=e=>{if(!Ve.length)return;let t=A;for(let n=0;n{let n=ve.current,r=f.current;if(!n||n.ownerKey!==b||n.ownerKey!==c.current.key||n.revision!==r.revision)return t(`fileReferenceDraftChanged`);let i=r.prompt.slice(0,n.start),a=r.prompt.slice(n.end),o=YM(e),s=i&&!/\s$/u.test(i)?` `:``,l=`${i}${s}${o}${a&&!/^\s/u.test(a)?` `:``}${a}`,u=i.length+s.length+o.length;if(!xe({prompt:l,caret:u}))return t(`draftLimit`);_e.current=!0},et=()=>{let e=f.current,t=pe.current,n=Math.min(Math.max(t?.selectionStart??e.caret,0),e.prompt.length);ve.current={ownerKey:b,revision:e.revision,start:n,end:Math.min(Math.max(t?.selectionEnd??n,n),e.prompt.length)},N(!0)},tt=[...(e.snapshot?.workspaces??[]).map(t=>({id:t.path,label:t.name,icon:(0,K.jsx)(De,{}),endContent:t.path===e.selectedWorkspace?(0,K.jsx)(I,{}):void 0,onClick:()=>e.actions.setWorkspace(t.path)})),{type:`divider`},{id:`add`,label:t(`addWorkspaceMenu`),icon:(0,K.jsx)(lt,{}),onClick:()=>void e.actions.chooseWorkspace()}],nt=e.draftModel??e.snapshot?.models.find(e=>e.current),rt=e.snapshot?.workspaces.find(t=>t.path===e.selectedWorkspace)?.name??(e.selectedWorkspace?QA(e.selectedWorkspace):t(`selectWorkspace`)),it=e.snapshot?.sessions.find(e=>e.path===i),at=Ce?ZA(it??{},n?.id??t(`untitledSession`)):we?t(`newSession`):n?ZA(it??{},n.id):t(`newSession`),ot=e.sessionSwitching?t(`switchingSession`):e.selectedWorkspace?Ce&&e.snapshot?.runtime.planHasPrompt&&[`planning`,`ready`].includes(e.snapshot.runtime.plan??``)?t(`promptPlanMessage`):e.landing?t(`promptTask`):t(Te?`promptMessage`:`promptReadonly`):t(`promptStart`),st=e.snapshot?.thinking,ct=st?.level??null,ut=e.thinkingPendingLevel??null,dt=st?.supported??!1,ft=!!e.selectedWorkspace&&!Ce&&(we||!n),pt=st?!st.available.includes(ct??``):!1,mt=st?!dt&&!ft?`thinkingUnsupportedHint`:!Ce&&!ft?`thinkingInactiveHint`:Oe?`thinkingLockedRunning`:e.modelSelectionPending?`thinkingModelPendingHint`:null:null,ht=e.snapshot?.selectedExecution,gt=n&&ht&&ht.sessionId===n.id&&ht.sessionPath===n.path?ht.pendingFollowUps:void 0,_t=gt??(Ce?e.pendingFollowUpsReceipt:null),vt=n&&ht?.sessionId===n.id&&ht.sessionPath===n.path?ht.pendingSteering:void 0,yt=vt??(Ce?e.pendingSteeringReceipt:null),bt=vt===void 0?[]:ht?.steeringMessages??[],xt=!e.workspaceDraft&&!e.sessionSwitching&&bt.length>0,St=gt===void 0?[]:ht?.queuedMessages??[],Ct=new Map,wt=St.map(e=>{let t=Ct.get(e)??0;return Ct.set(e,t+1),{message:e,key:`${e}:${t}`}}),Tt=!e.workspaceDraft&&!e.sessionSwitching&>!==void 0&&St.length>0,Dt=Ee?t(`compactionDraftHelp`):e.promptAdmissionPending&&!ke?t(`promptPending`):e.modelSelectionPending?t(`thinkingModelPendingHint`):e.thinkingPendingLevel===null?e.workspaceDraft?t(`enterHint`):e.turnCancellationPending?t(`stoppingTurn`):e.turnTerminalStatus===`cancelled`?t(`stoppedTurn`):!xt&&(yt??0)>0?t(`pendingSteeringHint`,{count:yt}):!Tt&&(Ce&&e.pendingFollowUpsReceipt!==null||(_t??0)>0)?(_t??0)>0?t(`pendingFollowUpsHint`,{count:_t??0}):t(`acceptedHint`):t(G?Oe?Ne?`steeringHint`:`queuedHint`:`enterHint`:`activeOnlyHint`):t(`thinkingPendingHint`),kt=G&&(Ee||e.promptAdmissionPending&&!ke||e.modelSelectionPending||e.thinkingPendingLevel!==null||e.turnCancellationPending||e.turnTerminalStatus===`cancelled`||!Tt&&Ce&&e.pendingFollowUpsReceipt!==null||!Tt&&(_t??0)>0||!xt&&(yt??0)>0||Oe&&!!(p.trim()||m.length||h.length)),At=L===b,jt=(e=!1)=>{F(null),e&&H.current?.focus()},Mt=e=>()=>{F(null),e()},Nt=async r=>{if(!(!Ce||!n||At||e.sessionSwitching)){R(b);try{r===`compact`?await V.compactSession(n.id,n.path):await V.updatePromptQueue(n.id,n.path,r),await e.actions.refreshSnapshot()}catch(e){c.current.key===b&&U(e instanceof Error?e.message:t(`commandPanelUnavailable`))}finally{R(e=>e===b?null:e)}}},Pt=P===`files`?[{id:`back`,section:t(`composerAdd`),label:t(`composerBack`),icon:(0,K.jsx)(de,{}),onClick:()=>F(`main`)},{id:`file-upload`,section:t(`composerAdd`),label:t(`addFiles`),description:t(`fileAttachmentDescription`),icon:(0,K.jsx)(Se,{}),disabled:te||m.length+h.length>=8,onClick:Mt(()=>{he.current&&(he.current.accept=``,he.current.click())})},{id:`image`,section:t(`composerAdd`),label:t(`addImages`),description:t(`imageAttachmentDescription`),icon:(0,K.jsx)(Me,{}),disabled:te||m.length>=8,onClick:Mt(()=>{he.current&&(he.current.accept=`image/png,image/jpeg,image/gif,image/webp`,he.current.click())})},{id:`workspace-file`,section:t(`composerAdd`),label:t(`fileReference`),icon:(0,K.jsx)(Se,{}),onClick:Mt(et)}]:[{id:`file`,section:t(`composerAdd`),label:t(`composerFile`),alias:`file`,icon:(0,K.jsx)(Se,{}),onClick:()=>F(`files`)},{id:`goal`,section:t(`composerAdd`),label:t(`composerGoal`),alias:`goal`,description:t(`composerGoalDescription`),icon:(0,K.jsx)(Ot,{}),disabled:!Ue,onClick:Mt(()=>{xe({prompt:`/goal `,caret:6})&&(O(!0),queueMicrotask(()=>pe.current?.focus()))})},{id:`plan`,section:t(`composerAdd`),label:t(`composerPlan`),alias:`plan`,description:t(`composerPlanDescription`),icon:(0,K.jsx)(ze,{}),disabled:!Ce||Oe||e.planSelectionPending||e.promptAdmissionPending,onClick:Mt(()=>void e.actions.selectPlanMode(e.snapshot?.runtime.plan===`inactive`))},{id:`compact`,section:t(`composerCommands`),label:t(`composerCompact`),alias:`compact`,description:t(`composerCompactDescription`),icon:(0,K.jsx)(Qe,{}),disabled:!Ce||Oe||At||e.promptAdmissionPending||(_t??0)>0,onClick:Mt(()=>void Nt(`compact`))},{id:`model`,section:t(`composerCommands`),label:t(`composerModel`),alias:`model`,description:t(`composerModelDescription`),icon:(0,K.jsx)(fe,{}),disabled:!Ce&&!we||Oe||e.modelSelectionPending,onClick:Mt(()=>B(e=>e+1))}];return(0,K.jsxs)(`div`,{className:`composer-dock`,children:[Ce&&e.snapshot?.runtime.plan===`ready`&&!e.sessionSwitching&&(0,K.jsx)(`div`,{className:`plan-mode-bar`,children:(0,K.jsx)(`button`,{type:`button`,disabled:Oe||te||!!ge.current||e.planSelectionPending||e.promptAdmissionPending||!!e.promptAdmissionRecovery,onClick:()=>{if((p.trim()||m.length>0||h.length>0)&&!window.confirm(t(`planImplementationReplaceDraft`)))return;let n=f.current.revision,r=c.current.key;e.actions.preparePlanImplementation().then(e=>{!e||f.current.revision!==n||c.current.key!==r||xe({prompt:e.prompt,images:[],caret:e.prompt.length},r)&&(me.current={sessionId:e.sessionId,sessionPath:e.sessionPath,planRevision:e.planRevision},ie(null),pe.current?.focus())})},children:t(`planModeImplement`)})}),!Ce&&!e.workspaceDraft&&!e.sessionSwitching&&n&&r===n.path&&(0,K.jsxs)(`div`,{className:`composer-session-notice`,children:[(0,K.jsx)(`span`,{children:t(`activateViewedSessionHint`)}),(0,K.jsx)(`button`,{type:`button`,className:`secondary`,onClick:()=>void e.actions.selectSession(n.path),children:t(`activateViewedSession`)})]}),Ce&&(0,K.jsx)(lj,{snapshot:e.snapshot,observed:e.activityObserved,onInspectTerminal:e.onInspect,onInspectSubagent:e.onInspectSubagent}),e.accessory,e.landing&&(0,K.jsx)(`div`,{className:`workspace-picker-row`,children:(0,K.jsx)(jA,{className:`workspace-picker-menu`,button:{label:e.selectedWorkspace?QA(e.selectedWorkspace):t(`selectWorkspace`),icon:(0,K.jsx)(De,{}),size:`md`,variant:`ghost`,className:`workspace-picker`},items:tt,menuWidth:240,placement:`above`,alignment:`start`,hasChevron:!0})}),e.promptAdmissionRecovery&&(0,K.jsxs)(`section`,{className:`prompt-recovery`,role:`alert`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`strong`,{children:t(`promptAdmissionUnknown`)}),(0,K.jsx)(`span`,{children:e.promptAdmissionRecovery.phase===`checking`?t(`promptAdmissionCheckingDetail`):e.promptAdmissionRecovery.phase===`verification-failed`?t(`promptAdmissionVerificationFailedDetail`):t(`promptAdmissionUnknownDetail`)})]}),(0,K.jsxs)(`div`,{className:`prompt-recovery-actions`,children:[(0,K.jsx)(`button`,{type:`button`,disabled:e.promptAdmissionRecovery.phase===`submitting`,onClick:e.actions.abandonPromptAdmission,children:t(`abandonAdmission`)}),e.promptAdmissionRecovery.phase===`verification-failed`&&(0,K.jsx)(`button`,{type:`button`,onClick:()=>void e.actions.checkPromptAdmissionRecovery(),children:t(`retryAdmissionCheck`)}),e.promptAdmissionRecovery.retryable&&(0,K.jsx)(`button`,{type:`button`,disabled:!Ce||e.sessionSwitching||e.modelSelectionPending||e.thinkingPendingLevel!==null||e.promptAdmissionRecovery.phase!==`ready`,onClick:()=>void e.actions.retryPromptAdmission(),children:t(`retryOriginalAdmission`)}),(0,K.jsx)(`button`,{type:`button`,className:`primary`,disabled:te||!Ce||e.sessionSwitching||e.modelSelectionPending||e.thinkingPendingLevel!==null||y||e.promptAdmissionRecovery.phase!==`ready`||!p.trim()&&m.length===0&&h.length===0,onClick:()=>void Ye(),children:e.promptAdmissionRecovery.phase===`submitting`?t(`sendingAsNew`):t(`sendAsNew`)})]})]}),Tt&&(0,K.jsxs)(`section`,{className:`composer-queue`,"aria-label":t(`pendingFollowUpsHint`,{count:gt}),children:[(0,K.jsxs)(`div`,{className:`composer-queue-status`,role:`status`,children:[(0,K.jsx)(`span`,{children:t(ht?.promptQueueBlocked?`compactionQueueBlocked`:Ee?`compactionQueueWaiting`:`queuedHint`)}),Ce&&(0,K.jsxs)(`span`,{children:[ht?.promptQueueBlocked&&(0,K.jsx)(`button`,{type:`button`,disabled:At||Ee,onClick:()=>void Nt(`retry`),children:t(`retryPrompt`)}),(0,K.jsx)(`button`,{type:`button`,disabled:At,onClick:()=>void Nt(`clear`),children:t(`clearPromptQueue`)})]})]}),(0,K.jsx)(`ul`,{children:wt.map(({message:e,key:r})=>{let i=`${n?.id}\0${n?.path}\0${r}`,a=ce===i,o=e||t(`queuedImage`),s=t(a?`queuedMessageCollapse`:`queuedMessageExpand`);return(0,K.jsx)(`li`,{children:(0,K.jsxs)(`button`,{type:`button`,className:`composer-queue-row ${a?`expanded`:``}`,"aria-expanded":a,"aria-label":`${s}: ${a?o:ej(o,80)}`,title:s,onClick:()=>le(a?null:i),children:[(0,K.jsx)(de,{"aria-hidden":`true`}),(0,K.jsx)(`span`,{children:o})]})},r)})}),gt>St.length&&(0,K.jsx)(`small`,{children:t(`queuedMore`,{count:gt-St.length})})]}),xt&&(0,K.jsxs)(`section`,{className:`composer-queue`,"aria-label":t(`steeringMessagesTitle`),children:[(0,K.jsxs)(`div`,{className:`composer-queue-status`,role:`status`,children:[(0,K.jsx)(`span`,{children:t(`pendingSteeringHint`,{count:yt})}),Ce&&(0,K.jsx)(`button`,{type:`button`,disabled:At,onClick:()=>void Nt(`clear`),children:t(`clearPromptQueue`)})]}),(0,K.jsx)(`ul`,{children:bt.map((e,r)=>{let i=`${n?.id}\0${n?.path}\0steer:${r}:${e}`,a=ce===i,o=e||t(`queuedImage`),s=t(a?`queuedMessageCollapse`:`queuedMessageExpand`);return(0,K.jsx)(`li`,{children:(0,K.jsxs)(`button`,{type:`button`,className:`composer-queue-row ${a?`expanded`:``}`,"aria-expanded":a,"aria-label":`${s}: ${a?o:ej(o,80)}`,title:s,onClick:()=>le(a?null:i),children:[(0,K.jsx)(de,{"aria-hidden":`true`}),(0,K.jsx)(`span`,{children:o})]})},i)})}),(yt??0)>bt.length&&(0,K.jsx)(`small`,{children:t(`queuedMore`,{count:(yt??0)-bt.length})})]}),(0,K.jsxs)(`form`,{className:`composer composer-m02 ${e.selectedWorkspace?``:`dormant`} ${oe?`is-dragging`:``}`,onSubmit:e=>void Je(e),onDragEnter:e=>{e.dataTransfer.types.includes(`Files`)&&(e.preventDefault(),We&&se(!0))},onDragOver:e=>{e.dataTransfer.types.includes(`Files`)&&(e.preventDefault(),We&&(e.dataTransfer.dropEffect=`copy`,se(!0)))},onDragLeave:e=>{let t=e.relatedTarget;t instanceof Node&&e.currentTarget.contains(t)||se(!1)},onDrop:e=>{se(!1),e.dataTransfer.files.length!==0&&(e.preventDefault(),We&&Ke(e.dataTransfer.files))},children:[P&&(0,K.jsx)(ZM,{items:Pt,onClose:jt},P),!e.selectedWorkspace&&(0,K.jsxs)(`div`,{className:`composer-dormant-cta`,"aria-hidden":`true`,children:[(0,K.jsx)(De,{}),(0,K.jsx)(`span`,{children:ot})]}),!e.selectedWorkspace&&(0,K.jsx)(`button`,{className:`dormant-overlay`,type:`button`,"aria-label":t(`selectWorkspace`),onClick:()=>void e.actions.chooseWorkspace()}),(0,K.jsx)(`input`,{ref:he,className:`sr-only`,type:`file`,multiple:!0,tabIndex:-1,"aria-hidden":`true`,onChange:e=>{e.currentTarget.files&&Ke(e.currentTarget.files)}}),(0,K.jsx)(iM,{ownerKey:b,images:m,onRemove:e=>{xe({images:f.current.images.filter(t=>t.id!==e)})&&ie(null)}}),(0,K.jsx)(aM,{ownerKey:b,files:h,onRemove:e=>{xe({files:(f.current.files??[]).filter(t=>t.id!==e)})&&ie(null)}}),re&&(0,K.jsx)(`p`,{className:`composer-attachment-error`,role:`alert`,children:re}),s.status===`failed`&&(0,K.jsxs)(`p`,{className:`composer-attachment-error`,role:`status`,children:[t(`draftStorageUnavailable`),` `,(0,K.jsx)(`button`,{type:`button`,onClick:()=>{o.retryStorage().then(()=>{let e=o.read(c.current.key);f.current=e,C.current=!0,d(e)})},children:t(`draftStorageRetry`)})]}),s.invalid&&(0,K.jsx)(`p`,{className:`composer-attachment-error`,role:`status`,children:t(`draftStorageInvalid`)}),te&&(0,K.jsx)(`p`,{role:`status`,children:t(`imageAttachmentsLoading`)}),ae&&(0,K.jsx)(`p`,{className:`composer-attachment-error`,role:`alert`,children:ae}),y&&(0,K.jsx)(`p`,{id:`composer-prompt-length-error`,className:`composer-attachment-error`,role:`alert`,children:t(`promptTooLong`,{count:v,limit:12e3})}),oe&&(0,K.jsxs)(`div`,{className:`composer-drop-overlay`,"aria-hidden":`true`,children:[(0,K.jsx)(Me,{}),(0,K.jsx)(`span`,{children:t(`dropImagesHere`)})]}),(0,K.jsx)(`textarea`,{ref:pe,value:p,rows:1,disabled:Pe,readOnly:!e.selectedWorkspace,"aria-label":t(`describeTask`),"aria-invalid":y||void 0,"aria-describedby":y?`composer-prompt-length-error`:void 0,"aria-autocomplete":`list`,"aria-controls":He?jN:void 0,"aria-activedescendant":He&&Ve[A]?MN(A):void 0,placeholder:ot,onChange:e=>{xe({prompt:e.target.value,caret:e.target.selectionStart})&&(U(null),O(!1))},onClick:e=>xe({caret:e.currentTarget.selectionStart}),onSelect:e=>xe({caret:e.currentTarget.selectionStart}),onFocus:()=>{E(!0),O(!1)},onBlur:()=>E(!1),onPaste:e=>{if(!We)return;let t=Array.from(e.clipboardData.files);if(t.length===0)for(let n of Array.from(e.clipboardData.items??[])){let e=n.kind===`file`?n.getAsFile():null;e&&t.push(e)}t.length!==0&&(e.clipboardData.getData(`text/plain`)||e.preventDefault(),Ke(t))},onKeyDown:e=>{if(!e.nativeEvent.isComposing){if(Le){if(e.key===`ArrowDown`||e.key===`ArrowUp`){e.preventDefault(),Ze(e.key===`ArrowDown`?1:-1);return}if(e.key===`Escape`){e.preventDefault(),O(!0);return}if(e.key===`Tab`){let t=Ve[A];!e.shiftKey&&!e.ctrlKey&&!e.altKey&&!e.metaKey&&t?.availability===`available`&&(e.preventDefault(),Xe(t));return}if(e.key===`Enter`&&!e.shiftKey){let t=Ve[A];if(t){e.preventDefault(),Xe(t);return}if(Ve.length>0){e.preventDefault();return}}}e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),Je())}}}),Le&&(0,K.jsx)(FN,{activeIndex:A,commandDiscovery:Fe,commands:Ve,draft:!!e.workspaceDraft,preferBelow:e.landing,onComplete:Xe,onSelect:j}),(0,K.jsxs)(`div`,{className:`composer-toolbar`,children:[(0,K.jsxs)(`div`,{className:`composer-toolbar-context`,children:[We&&(0,K.jsx)(`button`,{ref:H,type:`button`,className:`composer-context-trigger icon-button`,"aria-label":t(`addContext`),"aria-haspopup":`menu`,"aria-expanded":P!==null,"aria-controls":P?`composer-action-menu`:void 0,onClick:()=>{O(!0),F(P?null:`main`)},children:(0,K.jsx)(lt,{})}),!e.landing&&(0,K.jsxs)(`span`,{className:`composer-workspace-label`,title:`${rt} / ${at}`,children:[(0,K.jsx)(De,{}),rt]}),Ce&&e.snapshot?.runtime.plan&&e.snapshot.runtime.plan!==`inactive`&&(0,K.jsx)(`span`,{className:`composer-plan-chip`,children:t(`planMode_${e.snapshot.runtime.plan}`)})]}),(0,K.jsxs)(`div`,{className:`composer-toolbar-controls`,children:[(je||Ne)&&(0,K.jsx)(jA,{button:{label:t(Ne?`steerCurrentTurn`:`sendNextTurn`),variant:`ghost`,size:`sm`,isDisabled:e.promptAdmissionPending||!!e.promptAdmissionRecovery},items:[{id:`followUp`,label:t(`sendNextTurn`),onClick:()=>{W(null),U(null)}},{id:`steer`,label:t(`steerCurrentTurn`),isDisabled:!je,onClick:()=>{!je||!Ae||(W({ownerKey:b,expectedTurnCommandId:Ae.commandId}),U(null))}}],placement:`above`,alignment:`end`,hasChevron:!0}),(0,K.jsx)(`div`,{className:`model-picker-wrap`,hidden:!!(n&&!Ce&&!e.workspaceDraft),title:mt?t(mt):void 0,"data-level":ct??`none`,"data-pending":ut!==null,"data-warning":pt,children:(0,K.jsx)(AN,{snapshot:e.snapshot,openRequest:z,currentModel:nt,draftModel:e.draftModel,modelSearch:w,modelSelectionPending:!!e.modelSelectionPending,promptAdmissionPending:e.promptAdmissionPending,sessionSwitching:e.sessionSwitching,liveRunning:Oe,workspaceDraft:!!e.workspaceDraft,thinkingPendingLevel:ut,thinkingNeedsSession:ft,thinkingDisabledReason:mt,onOpenProviders:e.onOpenProviders,actions:e.actions})}),ke&&(0,K.jsx)(Cd,{content:t(`stopTurn`),placement:`above`,children:(0,K.jsx)(`button`,{className:`send-button`,type:`button`,"aria-label":t(`stopTurn`),disabled:e.turnCancellationPending||e.sessionSwitching,onClick:()=>void e.actions.cancelActiveTurn(),children:(0,K.jsx)(Et,{})})}),(!ke||!!(p.trim()||m.length||h.length))&&(0,K.jsx)(Cd,{content:t(Ee?`compactionDraftHelp`:`send`),placement:`above`,children:(0,K.jsx)(`button`,{className:`send-button`,type:`submit`,"aria-label":t(`send`),disabled:te||e.sessionSwitching||e.modelSelectionPending||e.thinkingPendingLevel!==null||!G||!e.selectedWorkspace||e.promptAdmissionPending||y||e.planSelectionPending||!!e.promptAdmissionRecovery||!!e.promptAdmissionResolution||!p.trim()&&m.length===0&&h.length===0,children:(0,K.jsx)(k,{})})})]})]}),(0,K.jsx)(`div`,{className:`composer-hint`,"data-visible":kt,"aria-live":`polite`,children:G?Dt:null})]}),(0,K.jsx)(JM,{open:M,sessionId:Ce?n?.id:void 0,onClose:()=>N(!1),onInsert:$e})]})}function zN({target:e,onClose:t,onOpenProviders:n}){let{t:r}=cr(),i=(0,_.useMemo)(()=>new rf,[]),[a,o]=(0,_.useState)(0),[s,c]=(0,_.useState)(null),[l,u]=(0,_.useState)(null),[d,f]=(0,_.useState)(null),p=e=>{f(null),wd(e).then(e=>f(e?`copied`:`failed`))};(0,_.useEffect)(()=>{let t=new AbortController;return c(null),u(null),f(null),(async()=>{let n={errors:[]};if(e.terminalId)try{let a=await i.terminalDetail(e.sessionId,e.terminalId,t.signal);if(a.sessionId!==e.sessionId||a.detail.id!==e.terminalId)throw Error(r(`inspectionChanged`));n.terminal=a.detail}catch(e){n.errors.push(e instanceof Error?e.message:r(`inspectionUnavailable`))}else{let[a,o]=await Promise.allSettled([i.thinking(e.sessionId,t.signal),i.trust(e.sessionId,t.signal)]);a.status===`fulfilled`&&a.value.sessionId===e.sessionId?n.thinking=a.value:n.errors.push(r(`thinkingUnavailable`)),o.status===`fulfilled`&&(o.value.workspace===void 0||o.value.workspace===e.cwd)?n.trust=o.value:n.errors.push(r(`trustUnavailable`))}t.signal.aborted||(c(n),u(new Date().toLocaleTimeString()))})(),()=>t.abort()},[i,e,a,r]);let m=e.terminalId?r(`terminalDetails`):r(`runtimeStatus`),h=s?.terminal;return(0,K.jsx)($j,{isOpen:!0,onOpenChange:e=>!e&&t(),width:640,"aria-label":m,children:(0,K.jsxs)(`section`,{className:`inspection-panel`,children:[(0,K.jsxs)(`header`,{className:`inspection-heading`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`h2`,{children:m}),(0,K.jsx)(`p`,{className:`inspection-subtitle`,children:e.cwd})]}),(0,K.jsxs)(`div`,{className:`inspection-actions`,children:[(0,K.jsx)(`button`,{type:`button`,className:`icon-button`,"aria-label":r(`refreshStatus`),disabled:!s,onClick:()=>o(e=>e+1),children:(0,K.jsx)(dt,{})}),(0,K.jsx)(`button`,{type:`button`,className:`icon-button`,"aria-label":r(`close`),onClick:t,children:(0,K.jsx)(Lt,{})})]})]}),d&&(0,K.jsx)(`p`,{role:`status`,children:r(d===`copied`?`copiedMessage`:`copyFailed`)}),s?(0,K.jsxs)(K.Fragment,{children:[s.errors.map(e=>(0,K.jsx)(`p`,{className:`inspection-warning`,role:`alert`,children:e},e)),h?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsxs)(`div`,{className:`inspection-section`,children:[(0,K.jsx)(`h3`,{children:h.title||h.id}),(0,K.jsxs)(`dl`,{children:[(0,K.jsx)(`dt`,{children:r(`executionState`)}),(0,K.jsx)(`dd`,{children:r(`execution_${h.status}`,{defaultValue:h.status})}),(0,K.jsx)(`dt`,{children:r(`terminalCommand`)}),(0,K.jsxs)(`dd`,{children:[(0,K.jsx)(`code`,{children:h.command}),(0,K.jsx)(`button`,{type:`button`,className:`inspection-copy`,"aria-label":r(`copyTerminalCommand`),title:r(`copyTerminalCommand`),onClick:()=>p(h.command),children:(0,K.jsx)(oe,{"aria-hidden":`true`})})]}),(0,K.jsx)(`dt`,{children:r(`terminalDirectory`)}),(0,K.jsx)(`dd`,{children:h.cwd}),(0,K.jsx)(`dt`,{children:r(`startedAt`)}),(0,K.jsx)(`dd`,{children:new Date(h.createdAt).toLocaleString()}),h.status!==`running`&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`dt`,{children:r(`exitCode`)}),(0,K.jsx)(`dd`,{children:h.exitCode??r(`unknownState`)})]})]}),h.errorText&&(0,K.jsx)(`p`,{className:`inspection-warning`,children:h.errorText}),h.truncated&&(0,K.jsx)(`p`,{className:`inspection-note`,children:r(`detailTruncated`)})]}),[`stdout`,`stderr`].map(e=>(0,K.jsxs)(`section`,{className:`inspection-section`,children:[(0,K.jsxs)(`div`,{className:`inspection-stream-heading`,children:[(0,K.jsx)(`h3`,{children:r(e===`stdout`?`standardOutput`:`standardError`)}),(0,K.jsx)(`button`,{type:`button`,className:`inspection-copy`,disabled:!h[e].text,"aria-label":r(`copyVisibleOutput`,{stream:r(e===`stdout`?`standardOutput`:`standardError`)}),title:r(`copyVisibleOutput`,{stream:r(e===`stdout`?`standardOutput`:`standardError`)}),onClick:()=>p(h[e].text),children:(0,K.jsx)(oe,{"aria-hidden":`true`})})]}),(0,K.jsx)(`section`,{className:`terminal-evidence`,tabIndex:0,"aria-label":r(e===`stdout`?`standardOutput`:`standardError`),children:(0,K.jsx)(`pre`,{children:h[e].text||r(`noOutput`)})}),h[e].truncated&&(0,K.jsx)(`p`,{className:`inspection-note`,children:r(`outputTruncated`,{count:h[e].omittedBytes})}),h[e].recoveryAvailable&&(0,K.jsx)(`p`,{className:`inspection-note`,children:r(`outputRecovery`)})]},e))]}):!e.terminalId&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsxs)(`section`,{className:`inspection-section`,children:[(0,K.jsx)(`h3`,{children:r(`modelAndThinking`)}),(0,K.jsxs)(`dl`,{children:[(0,K.jsx)(`dt`,{children:r(`selectedModel`)}),(0,K.jsx)(`dd`,{children:e.model||r(`noModels`)}),(0,K.jsx)(`dt`,{children:r(`thinkingLevel`)}),(0,K.jsx)(`dd`,{children:s.thinking?.supported===!1?r(`thinkingUnsupported`):s.thinking?.level??r(`unknownState`)}),!!s.thinking?.available.length&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`dt`,{children:r(`availableThinking`)}),(0,K.jsx)(`dd`,{children:s.thinking?.available.join(` · `)})]})]}),s.thinking?.supported===!1&&(0,K.jsx)(`p`,{className:`inspection-note`,children:r(`thinkingUnsupportedHint`)}),s.thinking&&s.thinking.supported!==!1&&!s.thinking.available.includes(s.thinking.level)&&(0,K.jsx)(`p`,{className:`inspection-warning`,role:`status`,children:r(`thinkingLevelMismatch`)})]}),(0,K.jsxs)(`section`,{className:`inspection-section`,children:[(0,K.jsx)(`h3`,{children:r(`projectTrust`)}),(0,K.jsx)(`p`,{children:r(`trust_${s.trust?.state??`unknown`}`)}),(0,K.jsxs)(`dl`,{children:[(0,K.jsx)(`dt`,{children:r(`savedTrustDecision`)}),(0,K.jsx)(`dd`,{children:r(`trustDecision_${s.trust?.decision??`unknown`}`)}),(0,K.jsx)(`dt`,{children:r(`activeSessionTrust`)}),(0,K.jsx)(`dd`,{children:s.trust?.sessionTrusted===!0?r(`trustActiveYes`):s.trust?.sessionTrusted===!1?r(`trustActiveNo`):r(`unknownState`)})]}),s.trust?.refreshRequired===!0&&(0,K.jsx)(`p`,{className:`inspection-warning`,children:r(`trustRefreshNeeded`)})]}),n&&(0,K.jsxs)(`button`,{type:`button`,className:`inspection-provider-link`,"aria-label":r(`openProviderSettings`),onClick:n,children:[(0,K.jsxs)(`span`,{children:[(0,K.jsx)(`strong`,{children:r(`providerAvailability`)}),(0,K.jsx)(`small`,{children:r(`authNotVerified`)})]}),r(`openProviderSettings`)]}),(0,K.jsxs)(`div`,{className:`inspection-setup`,children:[(0,K.jsx)(`p`,{className:`inspection-note`,children:r(`configurationViaPi`)}),(0,K.jsx)(`code`,{children:`/openpi-setup`}),(0,K.jsx)(`button`,{type:`button`,className:`inspection-copy`,"aria-label":r(`copySetupCommand`),title:r(`copySetupCommand`),onClick:()=>p(`/openpi-setup`),children:(0,K.jsx)(oe,{"aria-hidden":`true`})})]})]}),(0,K.jsx)(`p`,{className:`inspection-updated`,children:r(`statusCaptured`,{time:l})})]}):(0,K.jsx)(`p`,{role:`status`,children:r(`inspectionLoading`)})]})})}var BN=32,VN=1048576;function HN(e){return e.drafts.reduce((e,t)=>e+Od(t.custom)+Object.values(t.notes).reduce((e,t)=>e+Od(t),0),0)}function UN(e,t,n){if(!(n.submission||n.drafts.some(e=>e.choice!==null||e.custom||Object.values(e.notes).some(Boolean))))return e.delete(t),!0;let r=e.get(t);if(!r&&e.size>=BN)return!1;let i=r?HN(r):0,a=HN(n),o=Array.from(e.values()).reduce((e,t)=>e+HN(t),0);return a>i&&o-i+a>VN?!1:(e.set(t,n),!0)}function WN(e,t,n,r){for(let[i,a]of e)a.sessionId===t&&a.sessionPath===n&&a.requestId!==r&&e.delete(i)}function GN({request:e,answer:t,onSettled:n,connected:r=!0,sessionPath:i=``,workingCache:a}){let{t:o}=cr(),s=(0,_.useId)(),c=(0,_.useMemo)(()=>new Map,[]),l=a??c,u=JSON.stringify([e.sessionId,i,e.requestId]),[d,f]=(0,_.useState)(()=>l.get(u)??{sessionId:e.sessionId,sessionPath:i,requestId:e.requestId,drafts:e.questions.map(()=>({choice:null,custom:``,notes:{}})),index:0,review:!1,submission:null}),p=(0,_.useRef)(d),{drafts:m,index:h,review:g,submission:v}=d,[y,b]=(0,_.useState)(!!d.submission),[x,S]=(0,_.useState)(!1),[C,w]=(0,_.useState)(!1),D=(0,_.useRef)(!1),O=!!v,k=(0,_.useRef)(null),A=(0,_.useRef)(null),j=e.questions[h],M=m[h],N=C||O||!r,P=m.some(e=>e.choice===`custom`?!kd(e.custom):typeof e.choice==`number`&&!kd(e.notes[e.choice]??``)),F=m.every(e=>e.choice!==null)&&!P,L=(t,n)=>e.handoff?o(n===0?`handoffDone`:`handoffUnable`):t;(0,_.useEffect)(()=>()=>k.current?.abort(),[]);let R=e=>UN(l,u,e)?(p.current=e,f(e),S(!1),!0):(S(!0),!1),z=(e,t=!1)=>{R({...p.current,index:e,review:t}),requestAnimationFrame(()=>A.current?.focus())},B=e=>{let t=p.current;R({...t,drafts:t.drafts.map((n,r)=>r===t.index?{...n,...e}:n)})},V=()=>e.questions.map((e,t)=>{let n=m[t];if(n.choice===`custom`)return n.custom.trim()?{id:e.id,custom:n.custom}:{id:e.id,rephrase:!0};let r=typeof n.choice==`number`?e.options[n.choice]?.label:void 0;return{id:e.id,selected:r,...typeof n.choice==`number`&&n.notes[n.choice]?.trim()?{note:n.notes[n.choice]}:{}}}),H=async(i=!1)=>{if(D.current||!r||!i&&!O&&!F)return;let a=p.current.submission??{answers:i?null:V()};if(!R({...p.current,submission:a}))return;D.current=!0,w(!0),b(!1);let o=new AbortController;k.current=o;try{let r=await t(e,a.answers,o.signal);o.signal.aborted||(l.delete(u),n(r))}catch{o.signal.aborted||b(!0)}finally{o.signal.aborted||(D.current=!1,w(!1))}};return(0,K.jsxs)(`section`,{className:`question-card`,"aria-labelledby":`${s}-title`,"aria-busy":C,children:[(0,K.jsxs)(`header`,{className:`question-card-header`,children:[(0,K.jsxs)(`span`,{className:`question-eyebrow`,children:[(0,K.jsx)(Je,{"aria-hidden":`true`}),o(e.handoff?`handoffWaiting`:`questionWaiting`)]}),(0,K.jsx)(`span`,{className:`question-count`,children:g?o(e.handoff?`handoffReview`:`questionReview`):o(`questionProgress`,{current:h+1,total:e.questions.length})}),(0,K.jsx)(`button`,{type:`button`,className:`question-icon`,"aria-label":o(`questionDismiss`),title:o(`questionDismiss`),disabled:N,onClick:()=>void H(!0),children:(0,K.jsx)(Lt,{})})]}),(0,K.jsxs)(`div`,{className:`question-card-body`,children:[(0,K.jsx)(`h2`,{id:`${s}-title`,ref:A,tabIndex:-1,children:g?o(`questionReviewTitle`):j.question}),e.handoff&&(0,K.jsxs)(`div`,{className:`handoff-instructions`,children:[(0,K.jsx)(`p`,{children:e.handoff.instructions}),(0,K.jsxs)(`p`,{className:`question-help`,children:[o(`handoffSignal`),` `,e.handoff.completionSignal]}),(0,K.jsx)(`p`,{className:`question-help`,children:o(`handoffVerify`)})]}),g?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`p`,{className:`question-help`,children:o(`questionReviewHelp`)}),(0,K.jsx)(`ol`,{className:`question-review-list`,children:e.questions.map((e,t)=>{let n=m[t];return(0,K.jsxs)(`li`,{children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`span`,{className:`question-review-label`,children:e.header}),(0,K.jsx)(`p`,{children:typeof n.choice==`number`?L(e.options[n.choice]?.label,n.choice):n.custom.trim()||o(`questionRephrase`)}),typeof n.choice==`number`&&n.notes[n.choice]?.trim()&&(0,K.jsx)(`p`,{className:`question-help`,children:n.notes[n.choice]})]}),(0,K.jsx)(`button`,{type:`button`,className:`question-icon`,"aria-label":o(`questionEdit`,{question:e.header}),disabled:N,onClick:()=>z(t),children:(0,K.jsx)(at,{})})]},e.id)})})]}):(0,K.jsxs)(K.Fragment,{children:[(0,K.jsxs)(`fieldset`,{disabled:N,className:`question-choices`,children:[(0,K.jsx)(`legend`,{className:`sr-only`,children:j.header}),j.options.map((t,n)=>(0,K.jsxs)(`label`,{className:`question-choice ${M.choice===n?`is-selected`:``}`,children:[(0,K.jsx)(`input`,{className:`question-radio`,type:`radio`,name:`${s}-${j.id}`,checked:M.choice===n,onChange:()=>B({choice:n})}),(0,K.jsx)(`span`,{className:`question-choice-number`,"aria-hidden":`true`,children:n+1}),(0,K.jsxs)(`span`,{className:`question-choice-copy`,children:[(0,K.jsx)(`strong`,{children:L(t.label,n)}),(0,K.jsx)(`span`,{children:e.handoff?o(n===0?`handoffDoneHelp`:`handoffUnableHelp`):t.description})]})]},t.label))]}),typeof M.choice==`number`&&(0,K.jsxs)(`div`,{className:`question-extras`,children:[(0,K.jsxs)(`button`,{type:`button`,className:`question-note-toggle`,disabled:N,"aria-expanded":!!M.notesExpanded,"aria-controls":M.notesExpanded?`${s}-notes`:void 0,onClick:()=>B({notesExpanded:!M.notesExpanded}),children:[(0,K.jsx)(at,{"aria-hidden":`true`}),o(`questionNotes`)]}),typeof M.choice==`number`&&j.options[M.choice]?.preview&&(0,K.jsxs)(`details`,{className:`question-preview-disclosure`,children:[(0,K.jsx)(`summary`,{children:o(`questionPreview`)}),(0,K.jsx)(`pre`,{className:`question-preview`,children:j.options[M.choice].preview})]},`${j.id}-${M.choice}`)]}),(M.choice===`custom`||typeof M.choice==`number`&&M.notesExpanded)&&(0,K.jsxs)(`label`,{className:`question-notes`,id:`${s}-notes`,children:[(0,K.jsx)(`span`,{className:`sr-only`,id:`${s}-answer-label`,children:M.choice===`custom`?o(`questionYourAnswer`):o(`questionNotes`)}),(0,K.jsx)(`textarea`,{rows:1,disabled:N,value:M.choice===`custom`?M.custom:M.notes[M.choice]??``,onChange:e=>M.choice===`custom`?B({custom:e.target.value}):typeof M.choice==`number`&&B({notes:{...M.notes,[M.choice]:e.target.value}}),"aria-invalid":P,"aria-labelledby":`${s}-answer-label`,"aria-describedby":[P?`${s}-limit`:``,M.choice===`custom`?`${s}-custom-help`:``].filter(Boolean).join(` `)||void 0,placeholder:M.choice===`custom`?o(`questionCustomPlaceholder`):o(`questionNotesPlaceholder`)}),M.choice===`custom`&&(0,K.jsx)(`span`,{className:`question-help`,id:`${s}-custom-help`,children:o(`questionCustomHelp`)})]})]}),P&&(0,K.jsx)(`p`,{className:`question-error`,id:`${s}-limit`,role:`alert`,children:o(`questionLimit`,{count:8e3})}),x&&(0,K.jsx)(`p`,{className:`question-error`,role:`alert`,children:o(`questionDraftLimit`)}),!r&&(0,K.jsx)(`p`,{className:`question-help`,role:`status`,children:o(`questionDisconnected`)}),y&&(0,K.jsx)(`p`,{className:`question-error`,role:`alert`,children:o(`questionUncertain`)})]}),(0,K.jsxs)(`footer`,{className:`question-card-footer`,children:[!g&&!e.handoff&&(0,K.jsxs)(`label`,{className:`question-custom ${M.choice===`custom`?`is-selected`:``} ${N?`is-disabled`:``}`,children:[(0,K.jsx)(`input`,{className:`question-radio`,type:`radio`,name:`${s}-${j.id}`,checked:M.choice===`custom`,disabled:N,onChange:()=>B({choice:`custom`})}),(0,K.jsx)(`span`,{className:`question-choice-number`,"aria-hidden":`true`,children:(0,K.jsx)(at,{})}),(0,K.jsx)(`span`,{children:o(`questionCustom`)})]}),(0,K.jsxs)(`div`,{className:`question-actions`,children:[(g||h>0)&&(0,K.jsxs)(`button`,{type:`button`,className:`question-secondary`,disabled:N||!g&&h===0,onClick:()=>z(g?e.questions.length-1:h-1),children:[(0,K.jsx)(T,{}),o(`questionBack`)]}),!O&&(0,K.jsx)(`button`,{type:`button`,className:`question-secondary question-skip`,disabled:N,title:o(`questionDismiss`),onClick:()=>void H(!0),children:o(`questionSkip`)}),O?(0,K.jsxs)(`button`,{type:`button`,className:`question-primary`,disabled:C||!r,onClick:()=>void H(),children:[(0,K.jsx)(ft,{}),o(C?`questionSubmitting`:`questionRetry`)]}):g?(0,K.jsxs)(`button`,{type:`button`,className:`question-primary`,disabled:N||!F,onClick:()=>void H(),children:[(0,K.jsx)(I,{}),o(e.handoff?`handoffSubmit`:`questionSubmit`)]}):(0,K.jsxs)(`button`,{type:`button`,className:`question-primary`,disabled:N||M.choice===null||P,onClick:()=>z(hnew rf,[]),s=(0,_.useMemo)(()=>new Map,[]),c=i??s,[l,u]=(0,_.useState)(null),[d,f]=(0,_.useState)(null),[p,m]=(0,_.useState)(!1),[h,g]=(0,_.useState)(0),v=(0,_.useRef)(null),y=(0,_.useRef)(null);return(0,_.useEffect)(()=>{let t=new AbortController;return o.pendingQuestions(e,t.signal).then(({pending:n})=>{if(t.signal.aborted)return;let i=n?.requestId===v.current?null:n;y.current=i?.requestId??null,m(!1),WN(c,e,r,n?.requestId),u(i),n&&n.requestId!==v.current&&f(null)},()=>{t.signal.aborted||m(!0)}),()=>t.abort()},[o,e,r,c,t,h]),!l&&!d&&!p?null:(0,K.jsx)(`div`,{className:`question-panel`,children:l?(0,K.jsx)(GN,{request:l,connected:n,sessionPath:r,workingCache:c,answer:(e,t,n)=>o.answerQuestions(e,t,n),onSettled:e=>{y.current===l.requestId&&(y.current=null,v.current=l.requestId,u(null),f(e.state===`answered`?null:e),g(e=>e+1))}},l.requestId):d?(0,K.jsxs)(`div`,{className:`question-receipt`,role:`status`,children:[(0,K.jsx)(I,{"aria-hidden":`true`}),(0,K.jsx)(`span`,{children:a(`questionState_${d.state}`)}),(0,K.jsx)(`button`,{type:`button`,className:`question-icon`,"aria-label":a(`questionCloseReceipt`),onClick:()=>f(null),children:(0,K.jsx)(Lt,{})})]}):(0,K.jsxs)(`div`,{className:`question-receipt`,role:`alert`,children:[(0,K.jsx)(`span`,{children:a(`questionLoadFailed`)}),(0,K.jsx)(`button`,{type:`button`,className:`question-secondary`,onClick:()=>g(e=>e+1),children:a(`questionRetryLoad`)})]})})}function qN(e,t,{active:n=!0,running:r=!1,initialSource:i=`unstaged`,initialBaseRef:a}={}){let{t:o}=cr(),s=(0,_.useMemo)(()=>new rf,[]),c=(0,_.useRef)(null),l=(0,_.useRef)(null),u=(0,_.useRef)(!1),d=(0,_.useRef)({active:n,running:r});d.current={active:n,running:r};let[f,p]=(0,_.useState)(null),[m,h]=(0,_.useState)(!1),[g,v]=(0,_.useState)(null),y=e?.id,b=e?.path,[x,S]=(0,_.useState)({sessionId:y,sessionPath:b,source:i,baseRef:a}),C=x.sessionId===y&&x.sessionPath===b?x.source:i,w=x.sessionId===y&&x.sessionPath===b?x.baseRef:a,T=(0,_.useCallback)(e=>{S({sessionId:y,sessionPath:b,source:e,baseRef:w})},[y,b,w]),E=(0,_.useCallback)(e=>{S({sessionId:y,sessionPath:b,source:`branch`,baseRef:e})},[y,b]);(0,_.useLayoutEffect)(()=>{p(null),v(null),h(!!y)},[y,b,C,w]);let D=(0,_.useCallback)(async()=>{if(!y||!b||document.visibilityState===`hidden`)return;if(c.current){u.current=!0;return}let e=new AbortController;c.current=e,h(!0),v(null);try{let t=await s.gitReview(y,b,e.signal,{source:C,offset:`0`,...C===`branch`&&w?{baseRef:w}:{}});e.signal.aborted||(t.ok||v(o(t.reason===`not_git_repository`?`gitReviewNotRepository`:t.reason===`baseline_unavailable`?`gitReviewBaselineUnavailable`:t.reason===`base_branch_unavailable`?`gitReviewBaseUnavailable`:t.reason===`invalid_base_branch`?`gitReviewBaseInvalid`:`gitReviewFailed`)),p(e=>!t.ok&&e?.ok?t.branches?{...e,branches:t.branches}:e:t.ok&&e?.ok&&t.snapshot.revision===e.snapshot.revision?JSON.stringify(t.branches)===JSON.stringify(e.branches)?e:{...e,branches:t.branches}:t))}catch(t){e.signal.aborted||v(t instanceof Error?t.message:`Git review unavailable`)}finally{if(!e.signal.aborted&&(c.current=null,h(!1),u.current)){u.current=!1;let e=d.current;(e.active||!e.running)&&l.current===null&&(l.current=window.setTimeout(()=>{l.current=null,D()},e.active?200:2e3))}}},[s,y,b,C,w,o]),O=(0,_.useCallback)(async()=>{if(!y||!b||!f?.ok||f.snapshot.nextOffset===void 0||c.current)return;let e=f.snapshot,t=new AbortController;c.current=t,h(!0),v(null);try{let n=await s.gitReview(y,b,t.signal,{source:C,offset:String(e.nextOffset),revision:e.revision,...C===`branch`&&w?{baseRef:w}:{}});if(t.signal.aborted)return;if(!n.ok||n.snapshot.revision!==e.revision)throw Error(o(!n.ok&&n.reason===`revision_changed`?`gitReviewChanged`:`gitReviewFailed`));p({...n,snapshot:{...n.snapshot,files:[...e.files,...n.snapshot.files],additions:e.additions+n.snapshot.additions,deletions:e.deletions+n.snapshot.deletions}})}catch(e){t.signal.aborted||v(e instanceof Error?e.message:o(`gitReviewFailed`))}finally{t.signal.aborted||(c.current=null,h(!1))}},[s,y,b,C,w,f,o]),k=(0,_.useCallback)(async(e,t,n)=>{if(!y||!b)return;let r=await s.gitReview(y,b,t,{source:C,file:e,revision:n,...C===`branch`&&w?{baseRef:w}:{}});if(!r.ok||r.summaryRevision!==n)throw(r.ok||r.reason===`revision_changed`)&&!t.aborted&&D(),Error(o(!r.ok&&r.reason!==`revision_changed`?`gitReviewFailed`:`gitReviewChanged`));return r.snapshot.files.find(t=>t.path===e)},[s,y,b,C,w,D,o]);return(0,_.useEffect)(()=>{if(y)return l.current=window.setTimeout(()=>{l.current=null,D()},200),()=>{l.current!==null&&window.clearTimeout(l.current),l.current=null,u.current=!1,c.current?.abort(),c.current=null}},[D,y]),(0,_.useEffect)(()=>{n&&l.current!==null&&(window.clearTimeout(l.current),l.current=null)},[n]),(0,_.useEffect)(()=>{if(!n&&r){l.current!==null&&window.clearTimeout(l.current),l.current=null,u.current=!1;return}!y||l.current!==null||(l.current=window.setTimeout(()=>{l.current=null,D()},n?200:2e3))},[D,t,n,r,y]),(0,_.useEffect)(()=>{if(!y)return;let e=()=>{let e=d.current;(e.active||!e.running)&&D()};return window.addEventListener(`focus`,e),document.addEventListener(`visibilitychange`,e),()=>{window.removeEventListener(`focus`,e),document.removeEventListener(`visibilitychange`,e)}},[D,y]),(0,_.useMemo)(()=>({result:f,loading:m,error:g,refresh:D,source:C,setSource:T,baseRef:w,setBaseRef:E,readFile:k,loadMore:O}),[f,m,g,D,C,T,w,E,k,O])}function JN({notice:e,actions:t}){let{t:n}=cr(),r=(0,_.useRef)(!1),[i,a]=(0,_.useState)(null),[o,s]=(0,_.useState)(!1),c=()=>t.dismissArchiveNotice(e.key),l=async n=>{if(!r.current){r.current=!0,a(n),s(!1);try{(n===`undo`?await t.unarchiveSession(e.path):await t.selectSession(e.path,e.sessionId))===!1?s(!0):c()}catch{s(!0)}finally{r.current=!1,a(null)}}};return(0,K.jsx)(`div`,{className:`archive-notification`,"data-session-path":e.path,children:(0,K.jsx)(Zu,{type:`info`,body:n(`archiveNoticeTitle`),isAutoHide:!i&&!o,autoHideDuration:8e3,onDismiss:c,renderContent:()=>(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(C,{className:`archive-notification-icon`,"aria-hidden":`true`}),(0,K.jsxs)(`div`,{className:`archive-notification-copy`,children:[(0,K.jsx)(`strong`,{children:n(`archiveNoticeTitle`)}),(0,K.jsx)(`span`,{title:e.title,children:e.title}),o&&(0,K.jsx)(`span`,{className:`archive-notification-error`,role:`alert`,children:n(`archiveNoticeFailed`)})]}),(0,K.jsx)(`button`,{type:`button`,disabled:i!==null,onClick:()=>void l(`view`),children:n(`archiveNoticeView`)}),(0,K.jsxs)(`button`,{type:`button`,className:`archive-notification-undo`,disabled:i!==null,onClick:()=>void l(`undo`),children:[i===`undo`&&(0,K.jsx)(He,{className:`archive-notification-spinner`,"aria-hidden":`true`}),n(`archiveNoticeUndo`)]}),(0,K.jsx)(`button`,{type:`button`,className:`archive-notification-close`,"aria-label":n(`close`),onClick:c,children:(0,K.jsx)(Lt,{"aria-hidden":`true`})})]})})})}function YN({notices:e,actions:t}){return e.length?(0,K.jsx)(`div`,{className:`archive-notifications`,children:e.map(e=>(0,K.jsx)(JN,{notice:e,actions:t},e.key))}):null}function XN(e){let t=e?.closest(`.session-row, .workspace-group`),n=e?.closest(`.session-sidebar`),r=t?.dataset.sessionKey,i=Array.from(n?.querySelectorAll(`.session, .workspace-label, .workspace-heading-label`)??[]),a=i.findIndex(e=>t?.contains(e)),o=a<0?i:[...i.slice(a+1),...i.slice(0,a).reverse()];return()=>requestAnimationFrame(()=>{!n?.isConnected||document.querySelector(`dialog[open]`)||[e,r==null?null:Array.from(n.querySelectorAll(`.session-row`)).find(e=>e.dataset.sessionKey===r)?.querySelector(`.menu-action-button`),...o,n.querySelector(`.new-session-button`)].find(e=>e?.isConnected&&!e.closest(`[hidden], [inert]`)&&e.checkVisibility?.()!==!1)?.focus({preventScroll:!0})})}function ZN({session:e,archived:t,connected:n,pinSaving:r,restoring:i,movementItems:a,client:o,actions:s,onRename:c,onPin:l,onRead:u,onArchive:d,onNotice:f}){let{t:p}=cr(),m=(0,_.useRef)(null),h=(0,_.useRef)(!0),g=(0,_.useRef)(0),v=(0,_.useRef)(!1),[y,b]=(0,_.useState)(!1),[x,w]=(0,_.useState)(null),[T,E]=(0,_.useState)(!1),[D,k]=(0,_.useState)(!1),[A,j]=(0,_.useState)(null),[M,N]=(0,_.useState)(!1),[P,F]=(0,_.useState)(null),[I,L]=(0,_.useState)(!1),[R,z]=(0,_.useState)(!1),B=e.execution?.status===`running`||e.execution?.waitingForInput,V=(e.execution?.pendingFollowUps??0)+(e.execution?.pendingSteering??0)>0,H=n?B||V?p(`sidebarActionRunning`):void 0:p(`sidebarActionDisconnected`),ee=t?p(`sidebarForkArchived`):n?A?.local===!1?p(`sidebarForkUnavailable`):void 0:p(`sidebarActionDisconnected`),te=P!==null&&(P.path!==e.path||P.id!==e.id),ne=e.pinOrder!==void 0,re=()=>XN(m.current?.querySelector(`button`)??null),ie=()=>{let t=new URL(`/`,window.location.origin);return t.searchParams.set(`sessionPath`,e.path),t.searchParams.set(`sessionId`,e.id),t.href};(0,_.useEffect)(()=>(h.current=!0,()=>{h.current=!1,g.current++}),[]);let ae=(0,_.useRef)({id:e.id,path:e.path});(0,_.useEffect)(()=>{(ae.current.id!==e.id||ae.current.path!==e.path)&&(ae.current={id:e.id,path:e.path},b(!1),w(null),j(null))},[e.id,e.path]),(0,_.useEffect)(()=>{if(!y||!e.cwd||!n)return;let t=++g.current;return w(null),E(!1),o.sessionOpenTargets(e.path,e.id).then(e=>{h.current&&g.current===t&&w(e.targets)}).catch(()=>{h.current&&g.current===t&&E(!0)}),()=>{g.current++}},[o,n,y,e.cwd,e.id,e.path]),(0,_.useEffect)(()=>{if(!y||t||!n)return;let r=!1;return j(null),N(!1),Promise.resolve().then(()=>o.sessionForkOptions(e.path,e.id)).then(e=>{r||j(e)}).catch(()=>{r||N(!0)}),()=>{r=!0}},[t,o,n,y,e.id,e.path]);let U=()=>{b(!1),queueMicrotask(c)},oe=()=>{let e=re();l().then(e,e)},se=()=>{let e=re();d().then(e,e)},ce=async t=>{try{let n=await wd(t===`link`?ie():t===`cwd`?e.cwd:(await o.sessionMarkdown(e.path,e.id)).markdown);f(p(n?`sidebarCopied`:`sidebarCopyFailed`),!n)}catch{f(p(`sidebarCopyFailed`),!0)}},le=async(t=`local`)=>{if(!(D||ee)&&!(t===`worktree`&&!A?.worktree)){k(!0);try{t===`worktree`?await s.forkConversation(e.path,e.id,t):await s.forkConversation(e.path,e.id)}catch{f(p(`sidebarForkFailed`),!0)}finally{h.current&&k(!1)}}},de=()=>{if(v.current)return;let e=P?.restoreFocus;F(null),e?.()},fe=async()=>{if(!(!P||v.current||H||te)){v.current=!0,L(!0),z(!1);try{await s.deleteSession(P.path,P.id,P.commandId)?(h.current&&F(null),P.restoreFocus()):h.current&&z(!0)}catch{h.current&&z(!0)}finally{v.current=!1,h.current&&L(!1)}}},W=[{id:`rename`,label:p(`sidebarRename`),icon:(0,K.jsx)(at,{}),isDisabled:!n,onClick:U},...t?[]:[{id:`pin`,label:p(ne?`sidebarUnpin`:`sidebarPin`),icon:ne?(0,K.jsx)(ot,{}):(0,K.jsx)(st,{}),isDisabled:r||!n,onClick:oe},{id:`read`,label:p(e.unread?`markConversationRead`:`markConversationUnread`),icon:(0,K.jsx)(_e,{}),isDisabled:!e.readRevision||!n,onClick:()=>void u()}],...a.length?[{type:`divider`},...a]:[],...t?[]:[{type:`divider`},{id:`fork`,label:ee?(0,K.jsxs)(`span`,{className:`sidebar-menu-unavailable`,children:[(0,K.jsx)(`span`,{children:p(`sidebarFork`)}),(0,K.jsx)(`small`,{children:ee})]}):p(`sidebarFork`),icon:(0,K.jsx)(Ae,{}),isDisabled:!!ee||D,items:[{id:`fork-local`,label:p(D?`forkSessionPending`:e.worktree?`sidebarForkSameWorktree`:`sidebarForkLocal`),icon:(0,K.jsx)(et,{}),onClick:()=>void le()},...A?.worktree?[{id:`fork-worktree`,label:p(`sidebarForkWorktree`),icon:(0,K.jsx)(jt,{className:`sidebar-worktree-icon`}),onClick:()=>void le(`worktree`)}]:A===null?[{id:`fork-worktree-loading`,label:p(M?`sidebarForkOptionsFailed`:`sidebarForkOptionsLoading`),isDisabled:!0}]:[]]}],{type:`divider`},{id:`copy`,label:p(`sidebarCopy`),icon:(0,K.jsx)(ue,{}),items:[{id:`copy-link`,label:p(`sidebarCopyLink`),onClick:()=>void ce(`link`)},{id:`copy-markdown`,label:p(`sidebarCopyMarkdown`),isDisabled:!n,onClick:()=>void ce(`markdown`)},{id:`copy-cwd`,label:p(`sidebarCopyCwd`),isDisabled:!e.cwd,onClick:()=>void ce(`cwd`)}]},{type:`divider`},{id:`new-window`,label:p(`sidebarNewWindow`),icon:(0,K.jsx)(Ct,{}),onClick:()=>{window.open(ie(),`_blank`,`noopener,noreferrer`)}},...e.cwd&&n&&(x==null||x.length>0)?[{id:`open-in`,label:p(`sidebarOpenIn`),icon:(0,K.jsx)(O,{}),items:x?.map(t=>({id:t.id,label:t.label,onClick:()=>{o.openSessionIn(e.path,e.id,t.id).catch(()=>f(p(`sidebarOpenFailed`),!0))}}))??[{id:`open-in-loading`,label:p(T?`sidebarAppsFailed`:`sidebarAppsLoading`),isDisabled:!0}]}]:[],{type:`divider`},{id:t?`restore`:`archive`,label:p(i?`restoringConversation`:t?`sidebarRestore`:`sidebarArchive`),icon:t?(0,K.jsx)(S,{}):(0,K.jsx)(C,{}),isDisabled:i||!!H,description:H,onClick:se},{id:`delete`,label:p(`sidebarDelete`),icon:(0,K.jsx)(kt,{}),isDisabled:!!H,description:H,onClick:()=>{let t=re();queueMicrotask(()=>{h.current&&(z(!1),F({commandId:crypto.randomUUID(),path:e.path,id:e.id,name:ZA(e,p(`untitledSession`)),restoreFocus:t}))})}}];return(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`span`,{className:`astryx-menu-trigger`,ref:m,children:(0,K.jsx)(jA,{className:`sidebar-action-menu sidebar-conversation-menu`,button:{label:p(`conversationOptions`),icon:(0,K.jsx)(me,{}),isIconOnly:!0,size:`sm`,variant:`ghost`,className:`menu-action-button`},items:y?W:[],menuWidth:248,placement:`below`,alignment:`start`,hasChevron:!1,isMenuOpen:y,onOpenChange:b})}),P&&(0,K.jsx)($j,{isOpen:P!==null,onOpenChange:e=>{e||de()},purpose:`form`,width:420,"aria-label":p(`sidebarDeleteTitle`),children:(0,K.jsxs)(`form`,{className:`openpi-dialog sidebar-delete-dialog`,onSubmit:e=>{e.preventDefault(),fe()},children:[(0,K.jsx)(`strong`,{children:p(`sidebarDeleteTitle`)}),(0,K.jsx)(`p`,{children:p(`sidebarDeleteDescription`,{name:P?.name})}),(R||te)&&(0,K.jsx)(`p`,{className:`sidebar-dialog-error`,role:`alert`,children:p(te?`sessionLinkUnavailable`:`sidebarDeleteFailed`)}),(0,K.jsxs)(`div`,{className:`dialog-actions`,children:[(0,K.jsx)(`button`,{type:`button`,"data-autofocus":!0,disabled:I,onClick:de,children:p(`cancel`)}),(0,K.jsx)(`button`,{type:`submit`,className:`danger`,disabled:I||!!H||te,children:p(I?`sidebarDeleting`:`sidebarDeleteConfirm`)})]})]})})]})}var QN=e=>JSON.stringify([`session`,e.id,e.path]),$N=e=>JSON.stringify([`message`,e.sessionId,e.sessionPath,e.messageId,e.source,e.lineOffset]);function eP({open:e,initialQuery:t,initialIncludeArchived:n,sessions:r,workspaces:i,onClose:a,onCreateSession:o,onOpenSession:s,onOpenMessage:c}){let{t:l}=cr(),u=(0,_.useMemo)(()=>new rf,[]),[d,f]=(0,_.useState)(t),p=n,[m,h]=(0,_.useState)(null),[g,v]=(0,_.useState)(!1),[y,b]=(0,_.useState)(0),[x,S]=(0,_.useState)(!1),[C,w]=(0,_.useState)(null),[T,E]=(0,_.useState)(null),[D,O]=(0,_.useState)(null),k=(0,_.useRef)(null),A=(0,_.useId)(),j=(0,_.useRef)(null);(0,_.useEffect)(()=>(e&&(f(t),h(null),S(!1),w(null),E(null)),()=>{j.current?.abort(),j.current=null}),[e,t]);let M=d.trim(),N=(0,_.useMemo)(()=>new Map(i?.map(e=>[e.path,e.name])),[i]),P=(0,_.useMemo)(()=>{if(!e||!s)return[];let t=M.toLocaleLowerCase();return(r??[]).filter(e=>e.archived&&!p?!1:!t||`${ZA(e,l(`untitledSession`))} ${e.cwd} ${N.get(e.cwd)??``}`.toLocaleLowerCase().includes(t)).sort((e,t)=>t.modified.localeCompare(e.modified)||e.path.localeCompare(t.path))},[e,r,N,M,p,s,l]),F=M?[{name:`transcriptSearchSessions`,sessions:P.slice(0,9)}]:[{name:`pinnedConversations`,sessions:P.filter(e=>e.pinOrder!==void 0).sort((e,t)=>(e.pinOrder??0)-(t.pinOrder??0))},{name:`transcriptSearchRecent`,sessions:P.filter(e=>e.pinOrder===void 0).slice(0,10)}];(0,_.useLayoutEffect)(()=>{j.current?.abort(),j.current=null,E(null),w(null),O(null)},[e,M,p,y]),(0,_.useEffect)(()=>{if(!e||!M){v(!1),S(!1);return}let t=new AbortController;v(!0),S(!1);let n=window.setTimeout(()=>{u.searchTranscripts(M,{includeArchived:p,signal:t.signal}).then(e=>{t.signal.aborted||h({query:M,revision:y,includeArchived:p,response:e})}).catch(()=>{t.signal.aborted||S(!0)}).finally(()=>{t.signal.aborted||v(!1)})},250);return()=>{window.clearTimeout(n),t.abort()}},[u,e,M,p,y]);let I=m?.query===M&&m.revision===y&&m.includeArchived===p?m.response:null,L=[...F.flatMap(e=>e.sessions.map(QN)),...M?I?.matches.map($N)??[]:[]],R=D!==null&&L.includes(D)?D:L[0],z=e=>`${A}-${encodeURIComponent(e)}`,B=R?z(R):void 0;(0,_.useLayoutEffect)(()=>{e&&B&&document.getElementById(B)?.scrollIntoView?.({block:`nearest`})},[e,B]);let V=async(e,t,n)=>{if(j.current)return;O(e),k.current?.focus({preventScroll:!0});let r=new AbortController;j.current=r,E(e),w(null);try{let e=await t(r.signal);if(r.signal.aborted)return;e===!1?w(n):a()}catch{r.signal.aborted||w(n)}finally{j.current===r&&(j.current=null,E(null))}};return(0,K.jsx)($j,{isOpen:e,onOpenChange:e=>!e&&a(),purpose:`info`,width:`min(520px, 92vw)`,maxHeight:`calc(var(--transcript-search-list-height) + 64px)`,padding:0,className:`transcript-search-modal`,"aria-label":l(`transcriptSearch`),children:e&&(0,K.jsxs)(`div`,{className:`transcript-search-dialog`,children:[(0,K.jsx)(`h2`,{className:`transcript-search-sr-only`,children:l(`transcriptSearch`)}),(0,K.jsx)(`input`,{ref:k,className:`transcript-search-input`,"data-autofocus":!0,type:`search`,maxLength:200,value:d,"aria-label":l(`transcriptSearch`),"aria-autocomplete":`list`,"aria-controls":A,"aria-activedescendant":B,placeholder:l(`transcriptSearchPlaceholder`),autoComplete:`off`,autoCorrect:`off`,spellCheck:!1,onChange:e=>f(e.target.value),onKeyDown:e=>{if(e.nativeEvent.isComposing||e.nativeEvent.keyCode===229||![`ArrowDown`,`ArrowUp`,`Home`,`End`,`Enter`].includes(e.key)||T!==null)return;if(!R||!B){e.key===`Enter`&&!M&&o&&(e.preventDefault(),a(),o());return}e.preventDefault();let t=L.indexOf(R);if(e.key===`Enter`){document.getElementById(B)?.click();return}let n=e.key===`Home`?0:e.key===`End`?L.length-1:e.key===`ArrowDown`?Math.min(t+1,L.length-1):Math.max(t-1,0);O(L[n]??null)}}),(0,K.jsx)(`span`,{className:`transcript-search-sr-only`,role:`status`,children:g?l(`transcriptSearching`):null}),(0,K.jsxs)(`div`,{className:`transcript-search-groups`,children:[(0,K.jsx)(`div`,{id:A,role:`listbox`,"aria-label":l(`transcriptSearch`),children:F.filter(e=>e.sessions.length>0||M&&I?.matches.length).map(e=>(0,K.jsxs)(`fieldset`,{"aria-label":l(e.name),children:[(0,K.jsxs)(`h3`,{children:[l(e.name),g&&(0,K.jsx)(He,{className:`is-spinning`,"aria-hidden":`true`})]}),(0,K.jsxs)(`ul`,{className:`transcript-search-results`,role:`presentation`,children:[s&&e.sessions.map(e=>{let t=ZA(e,l(`untitledSession`)),n=QN(e),r=e.ungrouped?l(`ungrouped`):N.get(e.cwd)||QA(e.cwd);return(0,K.jsx)(`li`,{role:`presentation`,children:(0,K.jsxs)(`button`,{id:z(n),role:`option`,"aria-selected":n===R,tabIndex:-1,type:`button`,disabled:T!==null,"aria-label":l(`transcriptSearchSessionResult`,{session:t}),onPointerMove:()=>O(n),onMouseDown:e=>e.preventDefault(),onClick:()=>void V(n,t=>s(e.path,t),`transcriptSearchSessionOpenFailed`),children:[(0,K.jsx)(`span`,{className:`transcript-search-accessory`,"aria-hidden":`true`,children:T===n?(0,K.jsx)(He,{className:`is-spinning`}):e.unread?(0,K.jsx)(ae,{className:`transcript-search-unread`}):null}),(0,K.jsx)(`span`,{className:`transcript-search-result-body`,children:(0,K.jsxs)(`span`,{className:`transcript-search-result-line`,children:[(0,K.jsx)(`span`,{className:`transcript-search-title`,title:t,children:t}),(0,K.jsx)(`span`,{className:`transcript-search-project`,title:e.cwd,children:r})]})})]})},n)}),M&&I?.matches.map(e=>{let t=e.sessionName||l(`untitledSession`),n=l(`transcriptSearchSource_${e.source}`),r=$N(e);return(0,K.jsx)(`li`,{role:`presentation`,children:(0,K.jsxs)(`button`,{id:z(r),role:`option`,"aria-selected":r===R,tabIndex:-1,type:`button`,disabled:T!==null,"aria-label":l(`transcriptSearchResult`,{session:t,source:n}),onPointerMove:()=>O(r),onMouseDown:e=>e.preventDefault(),onClick:()=>void V(r,t=>c({sessionId:e.sessionId,sessionPath:e.sessionPath,entryId:e.messageId},t),`transcriptSearchOpenFailed`),children:[(0,K.jsx)(`span`,{className:`transcript-search-accessory`,"aria-hidden":`true`,children:T===r&&(0,K.jsx)(He,{className:`is-spinning`})}),(0,K.jsxs)(`span`,{className:`transcript-search-result-body`,children:[(0,K.jsxs)(`span`,{className:`transcript-search-result-line`,children:[(0,K.jsx)(`span`,{className:`transcript-search-title`,title:t,children:t}),(0,K.jsx)(`span`,{className:`transcript-search-project`,title:e.workspace??n,children:e.workspace?N.get(e.workspace)||QA(e.workspace):n})]}),(0,K.jsx)(`span`,{className:`transcript-search-snippet`,children:e.snippet})]})]})},r)})]})]},e.name))}),!M&&!P.length&&(0,K.jsxs)(`div`,{className:`transcript-search-empty-history`,children:[(0,K.jsx)(`p`,{children:l(`noConversations`)}),o&&(0,K.jsx)(`button`,{className:`transcript-search-create`,type:`button`,onClick:()=>{a(),o()},children:l(`newSession`)})]}),M&&!P.length&&!I?.matches.length&&(g?(0,K.jsx)(`div`,{className:`transcript-search-feedback`,"aria-hidden":`true`,children:(0,K.jsx)(He,{className:`is-spinning`})}):I&&!x?(0,K.jsx)(`div`,{className:`transcript-search-feedback`,role:`status`,children:l(`transcriptSearchEmpty`)}):null),x&&(0,K.jsxs)(`p`,{className:`transcript-search-error`,role:`alert`,children:[l(`transcriptSearchFailed`),(0,K.jsx)(`button`,{type:`button`,onClick:()=>b(e=>e+1),children:l(`transcriptSearchRetry`)})]}),C&&(0,K.jsx)(`p`,{className:`transcript-search-error`,role:`alert`,children:l(C)}),I?.partial&&(0,K.jsx)(`p`,{className:`transcript-search-partial`,children:l(`transcriptSearchPartial`)})]})]})})}function tP({workspace:e,client:t,actions:n,connected:r,onClose:i}){let{t:a}=cr(),[o,s]=(0,_.useState)([]),[c,l]=(0,_.useState)(),[u,d]=(0,_.useState)(!1),[f,p]=(0,_.useState)(null),[m,h]=(0,_.useState)(0),[g,v]=(0,_.useState)(null),[y,b]=(0,_.useState)(null),[x,S]=(0,_.useState)(!1),[C,w]=(0,_.useState)(!1),T=(0,_.useRef)(0),E=(0,_.useRef)(null),D=(0,_.useRef)(!1),O=(0,_.useRef)(!0),k=(0,_.useCallback)(async n=>{let r=++T.current;d(!0),p(null);try{let i=await t.workspaceWorktrees(e,n);if(!O.current||r!==T.current)return;if(i.truncated&&!i.nextCursor)throw Error(`Missing worktree continuation`);s(e=>{let t=n?[...e]:[];for(let e of i.worktrees)t.some(t=>t.worktreePath===e.worktreePath&&t.sessionId===e.sessionId&&t.sessionPath===e.sessionPath)||t.push(e);return t}),l(i.nextCursor),h(e=>(n?e:0)+i.unavailable)}catch(e){O.current&&r===T.current&&p(e instanceof tf&&e.code===`WORKTREE_LIST_CHANGED`?`changed`:`failed`)}finally{O.current&&r===T.current&&d(!1)}},[t,e]);(0,_.useEffect)(()=>(O.current=!0,k(),()=>{O.current=!1,T.current++}),[k]);let A=async()=>{if(!(!g||D.current||!r)){D.current=!0,w(!0);try{let e=await n.releaseSessionWorktree(g);if(!O.current)return;b(e),S(!1),e.state===`removed`&&s(e=>e.filter(e=>e.worktreePath!==g.worktreePath||e.sessionId!==g.sessionId||e.sessionPath!==g.sessionPath))}catch{O.current&&(S(!0),b(null))}finally{D.current=!1,O.current&&w(!1)}}};(0,_.useEffect)(()=>{g&&!C&&E.current?.focus()},[g,C]);let j=()=>{D.current||i()};return(0,K.jsx)($j,{isOpen:!0,onOpenChange:e=>{e||j()},purpose:`form`,width:560,"aria-label":a(`managedWorktrees`),children:(0,K.jsxs)(`div`,{className:`openpi-dialog`,children:[(0,K.jsx)(`strong`,{children:a(`managedWorktrees`)}),(0,K.jsx)(`p`,{className:`sidebar-dialog-path`,children:e}),(0,K.jsx)(`p`,{children:a(`managedWorktreesDescription`)}),g?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`p`,{className:`sidebar-dialog-path`,children:g.worktreePath}),(0,K.jsx)(`p`,{children:a(`managedWorktreeConfirm`)}),(y||x)&&(0,K.jsxs)(`p`,{role:`status`,className:y?.state===`removed`?void 0:`sidebar-dialog-error`,children:[a(y?.state===`removed`?`managedWorktreeRemoved`:y?.state===`preserved`?`managedWorktreePreserved`:y?.state===`uncertain`?`managedWorktreeUncertainTerminal`:`managedWorktreeUncertain`),y?.reason&&(0,K.jsxs)(K.Fragment,{children:[` `,y.reason]})]}),(0,K.jsxs)(`div`,{className:`dialog-actions`,children:[(0,K.jsx)(`button`,{type:`button`,"data-autofocus":!0,ref:E,disabled:C,onClick:()=>{v(null),b(null),S(!1)},children:a(`managedWorktreesBack`)}),y?.state!==`removed`&&y?.state!==`uncertain`&&(0,K.jsx)(`button`,{type:`button`,className:`danger`,disabled:C||!r,onClick:()=>void A(),children:a(C?`managedWorktreeRemoving`:y||x?`managedWorktreesRetry`:`managedWorktreeRemove`)})]})]}):(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`div`,{className:`managed-worktrees-list`,children:o.map(e=>(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`sidebar-dialog-path`,children:e.worktreePath}),(0,K.jsx)(`button`,{type:`button`,disabled:!r||u||!!f,onClick:()=>{v(e),b(null),S(!1)},children:a(`managedWorktreeReview`)})]},JSON.stringify([e.worktreePath,e.sessionId,e.sessionPath])))}),!u&&!f&&!o.length&&(0,K.jsx)(`p`,{children:a(`managedWorktreesEmpty`)}),m>0&&(0,K.jsx)(`p`,{children:a(`managedWorktreesUnavailable`,{count:m})}),f&&(0,K.jsx)(`p`,{role:`alert`,children:a(f===`changed`?`managedWorktreesChanged`:`managedWorktreesLoadFailed`)}),(0,K.jsxs)(`div`,{className:`dialog-actions`,children:[(0,K.jsx)(`button`,{type:`button`,"data-autofocus":!0,onClick:j,children:a(`close`)}),f&&(0,K.jsx)(`button`,{type:`button`,disabled:u||!r,onClick:()=>void k(f===`changed`?void 0:c),children:a(f===`changed`?`managedWorktreesRefresh`:`managedWorktreesRetry`)}),c&&!f&&(0,K.jsx)(`button`,{type:`button`,disabled:u||!r,onClick:()=>void k(c),children:a(`managedWorktreesMore`)}),u&&(0,K.jsx)(`span`,{role:`status`,children:a(`loading`)})]})]})]})})}function nP(e){return e.workspacePath??e.cwd}function rP(e,t,n){return e[t+(n?2:-1)]??null}function iP(e,t,n){return e[t+ +!!n]??null}function aP(e,t){return e>t.top+t.height/2}function oP(e){let t=e.execution?.lastTurn;return JSON.stringify(t?[e.path,e.id,t.commandId,t.finishedAt]:[e.path,e.id])}function sP(e){return e.firstUnread?.type===`turn`?e.firstUnread.finishedAt:e.execution?.lastTurn?.finishedAt??Date.parse(e.modified)}function cP(e){return JSON.stringify([e.path,e.id])}function lP(e,t=!0){return t&&e.execution?.waitingForInput?0:e.unread?1:t&&e.execution?.status===`running`?2:3}function uP({items:e,label:t,alignment:n=`start`}){return(0,K.jsx)(`span`,{className:`astryx-menu-trigger`,children:(0,K.jsx)(jA,{className:`sidebar-action-menu`,button:{label:t,icon:(0,K.jsx)(me,{}),isIconOnly:!0,size:`sm`,variant:`ghost`,className:`menu-action-button`},items:e,menuWidth:240,placement:`below`,alignment:n,hasChevron:!1})})}function dP(e){let{t}=cr(),n=(0,_.useRef)(null),[r,i]=(0,_.useState)(null),[a,o]=(0,_.useState)(null),[s,c]=(0,_.useState)(!1),[l,u]=(0,_.useState)(!1),[d,f]=(0,_.useState)(10),[p,m]=(0,_.useState)(!0),[h,g]=(0,_.useState)(new Set),v=(0,_.useRef)(null),[y,b]=(0,_.useState)(!1),[x,S]=(0,_.useState)(!1),[E,D]=(0,_.useState)(!1),[O,j]=(0,_.useState)(new Set),[M,P]=(0,_.useState)(10),[F,R]=(0,_.useState)(!1),[z,B]=(0,_.useState)(null),[V,ee]=(0,_.useState)(!1),te=(0,_.useRef)(new Set),ne=(0,_.useRef)(null),[re,ie]=(0,_.useState)(null),[U,oe]=(0,_.useState)(``),[se,ce]=(0,_.useState)(!1),le=(0,_.useRef)(null),ue=(0,_.useRef)(null),de=(0,_.useRef)(null),fe=(0,_.useRef)(null),W=(0,_.useRef)(null),pe=(0,_.useRef)(null);(0,_.useEffect)(()=>{if(!z)return;let e=window.setTimeout(()=>B(null),5e3);return()=>window.clearTimeout(e)},[z]);let me=e.snapshot,he=me?.selectedSession?.path===e.selectedPath?e.selectedPath:null,ge=me?.sessions.find(e=>e.path===me.selectedSession?.path&&e.id===me.selectedSession?.id),_e=oP(ge??{id:``,path:``});(0,_.useEffect)(()=>{e.selectedPath,ne.current=null},[_e,e.selectedPath]),(0,_.useEffect)(()=>{if(!e.sessionViewVisible||!ge||e.selectedPath!==ge.path||ne.current===_e||e.connected===!1)return;let t=!0,n=()=>{document.visibilityState!==`visible`||!document.hasFocus()||document.querySelector(`dialog[open]`)||ne.current!==_e&&(ne.current=_e,!(!ge.unread||!ge.readRevision)&&e.actions.setSessionRead(ge.path,ge.id,!0,ge.readRevision).catch(()=>{t&&R(!0)}))};return n(),document.addEventListener(`visibilitychange`,n),window.addEventListener(`focus`,n),document.addEventListener(`close`,n,!0),()=>{t=!1,document.removeEventListener(`visibilitychange`,n),window.removeEventListener(`focus`,n),document.removeEventListener(`close`,n,!0)}},[_e,ge,e.sessionViewVisible,e.selectedPath,e.connected,e.actions]);let ve=(0,_.useMemo)(()=>new rf,[]),[ye,be]=(0,_.useState)(!1),[xe,Se]=(0,_.useState)(!1),[Ce,we]=(0,_.useState)(!1),Te=(0,_.useRef)(!1),Ee=(0,_.useRef)(null),Oe=(0,_.useRef)(0),[ke,Ae]=(0,_.useState)(!1),je=(0,_.useRef)(null),[Me,Ne]=(0,_.useState)(null),[Pe,Fe]=(0,_.useState)(null),[Ie,Le]=(0,_.useState)(!1),[Re,ze]=(0,_.useState)(!1),Ve=me?.preferences.pinnedSort??`manual`,We=me?.preferences.sidebarGrouping??`project`,Ge=me?.preferences.chatsSort??`updated`,Ke=(me?.sessions??[]).filter(e=>e.pinOrder!==void 0&&!e.archived).sort((e,t)=>(Ve===`updated`?t.modified.localeCompare(e.modified):0)||e.pinOrder-t.pinOrder).filter(n=>{let r=me?.workspaces.find(e=>e.path===nP(n));return`${ZA(n,t(`untitledSession`))} ${n.cwd} ${r?.name??``}`.toLowerCase().includes(e.query.trim().toLowerCase())}),qe=async e=>{if(!Te.current){Te.current=!0,we(!0),ze(!1);try{await e()}catch{ze(!0)}finally{Te.current=!1,we(!1)}}},Je=(t,n,r)=>qe(()=>e.actions.setSessionPin(t.path,t.id,n,r)),Ye=(t,n,r)=>qe(()=>e.actions.setSidebarPin(t,n,r)),Xe=t=>qe(async()=>{await ve.savePreferences(t),await e.actions.refreshSnapshot()}),Ze=async(t,n)=>{if(!t.readRevision)return;let r=oP(t);if(!te.current.has(r)){t.path===e.selectedPath&&(ne.current=r),te.current.add(r),R(!1);try{await e.actions.setSessionRead(t.path,t.id,n,t.readRevision)}catch{R(!0)}finally{te.current.delete(r)}}},Qe=e.query.trim(),$e=JSON.stringify([ye,Qe]),et=(0,_.useRef)({key:$e});et.current.key!==$e&&(et.current={key:$e});let nt=(0,_.useRef)(!1),[rt,it]=(0,_.useState)(null),[at,ot]=(0,_.useState)(!1),[ct,ut]=(0,_.useState)(null),ft=(0,_.useRef)(null),pt=rt?.query===Qe?rt:null,mt=ct?.query===Qe?ct:null,gt=(0,_.useCallback)(async(e,t)=>{if(!ye)return;ft.current?.abort();let n=new AbortController;ft.current=n,ot(!0),ut(null);try{let r=await ve.listArchivedSessions({query:Qe,...e?{cursor:e}:{},limit:25},n.signal);if(n.signal.aborted||ft.current!==n)return;let i=[...r.sessions];for(;!e&&t!==void 0&&i.length!i.some(t=>t.path===e.path));if(i.push(...e),!e.length)break}it(t=>({...r,query:Qe,sessions:e&&t?.query===Qe?[...t.sessions,...i.filter(e=>!t.sessions.some(t=>t.path===e.path))]:i}))}catch(r){!n.signal.aborted&&ft.current===n&&ut({query:Qe,kind:r instanceof tf&&r.code===`ARCHIVED_SESSION_CURSOR_STALE`?`stale`:`failed`,...e?{cursor:e}:{},...t===void 0?{}:{retainedCount:t}})}finally{ft.current===n&&(ft.current=null,ot(!1))}},[Qe,ye,ve]),[_t,yt]=(0,_.useState)(new Set),[bt,xt]=(0,_.useState)(new Set),St=(0,_.useRef)(new Set),[Ct,Tt]=(0,_.useState)(!1),[Et,Dt]=(0,_.useState)(!1),Ot=(0,_.useRef)(!1),[At,jt]=(0,_.useState)(!1),Mt=(0,_.useRef)(!1),[Nt,Pt]=(0,_.useState)(!1),[Ft,It]=(0,_.useState)(!1),Rt=(0,_.useRef)(!1),zt=async t=>{if(St.current.has(t))return;St.current.add(t),xt(new Set(St.current)),Tt(!1);let n=et.current;try{let r=await e.actions.unarchiveSession(t);if(!nt.current||et.current!==n)return;r?(it(e=>e?{...e,sessions:e.sessions.filter(e=>e.path!==t)}:null),await gt()):Tt(!0)}finally{St.current.delete(t),nt.current&&xt(new Set(St.current))}};(0,_.useEffect)(()=>(nt.current=!0,()=>{nt.current=!1}),[]),(0,_.useEffect)(()=>(Tt(!1),ut(null),ye&&(it(e=>e?.query===Qe?e:null),gt()),()=>{ft.current?.abort(),ft.current=null}),[Qe,ye,gt]),(0,_.useEffect)(()=>{if(e.searchOpen)return le.current?.focus(),()=>ue.current?.focus()},[e.searchOpen]),(0,_.useEffect)(()=>{if(e.mobileOpen)return W.current?.focus(),()=>{let t=e.returnFocusRef?.current;t?.checkVisibility()&&t.focus()}},[e.mobileOpen,e.returnFocusRef]),(0,_.useEffect)(()=>{e.mobileOpen&&document.activeElement===document.body&&!document.querySelector(`dialog:modal`)&&W.current?.focus()}),(0,_.useEffect)(()=>{a&&(de.current?.focus(),de.current?.select())},[a]);let Bt=(0,_.useMemo)(()=>{let n=e.query.trim().toLowerCase(),r=ye?pt?.sessions??[]:me?.sessions??[],i=(e,i)=>r.filter(r=>!!r.archived===ye&&(ye||r.pinOrder===void 0)&&(e===`__ungrouped__`?r.ungrouped:nP(r)===e&&!r.ungrouped)&&(!n||ye||i||`${ZA(r,t(`untitledSession`))} ${r.cwd}`.toLowerCase().includes(n))),a=[...me?.workspaces??[]];for(let e of r)!e.ungrouped&&!a.some(t=>t.path===nP(e))&&a.push({path:nP(e),name:nP(e),current:!1});return[...a.map(e=>{let t=!!n&&`${e.name} ${e.path}`.toLowerCase().includes(n);return{...e,showPath:a.some(t=>t.path!==e.path&&t.name===e.name),sessions:i(e.path,t),ungrouped:!1,matches:t}}),{path:`__ungrouped__`,name:t(`ungrouped`),current:!1,sessions:i(`__ungrouped__`,!1),ungrouped:!0,pinOrder:void 0,showPath:!1,matches:!1}].filter(e=>e.sessions.length>0||!ye&&!e.ungrouped&&(!n||e.matches))},[ye,e.query,pt,me,t]),Vt=e=>[...e].sort((e,t)=>(Ge===`manual`?(e.order??2**53-1)-(t.order??2**53-1):0)||t.modified.localeCompare(e.modified)||e.path.localeCompare(t.path)),Ht=(e,t)=>{if(e.length<=t+1)return e;let n=e.slice(0,t),r=e.find(e=>e.path===he&&e.id===me?.selectedSession?.id);return r&&!n.includes(r)&&n.push(r),n},Ut=Bt.filter(e=>!e.ungrouped),Wt=Ut.filter(e=>e.pinOrder!==void 0),Gt=[...Ke.map(e=>({kind:`session`,session:e,pinOrder:e.pinOrder})),...Wt.map(e=>({kind:`workspace`,project:e,pinOrder:e.pinOrder}))].sort((e,t)=>{let n=e=>e.kind===`session`?e.session.modified:e.project.sessions.reduce((e,t)=>t.modified>e?t.modified:e,``);return(Ve===`updated`?n(t).localeCompare(n(e)):0)||e.pinOrder-t.pinOrder}),Kt=e=>e.kind===`session`?{kind:`session`,path:e.session.path,id:e.session.id}:{kind:`workspace`,path:e.project.path},qt=Ut.filter(e=>e.pinOrder===void 0),Jt=y||e.query.trim()||ye||qt.length<=6?qt:qt.slice(0,5),Yt=qt.find(e=>ge?.path===he&&e.path===(ge?nP(ge):void 0));Yt&&!Jt.includes(Yt)&&Jt.push(Yt);let Xt=Vt((me?.sessions??[]).filter(n=>!n.archived&&n.pinOrder===void 0&&!me?.workspaces.some(e=>e.pinOrder!==void 0&&e.path===nP(n))&&(We===`list`||me?.preferences.projectsInRecents!==!1||n.ungrouped||!Ut.some(e=>e.path===nP(n)))&&(!e.query.trim()||`${ZA(n,t(`untitledSession`))} ${n.cwd} ${me?.workspaces.find(e=>e.path===nP(n))?.name??``}`.toLowerCase().includes(e.query.trim().toLowerCase())))),Zt=e.query.trim()?Xt:Ht(Xt,M),Qt=t=>lP(t,e.connected)<3,$t=new Date;$t.setHours(0,0,0,0),$t.setDate($t.getDate()-6);let en=(me?.sessions??[]).filter(e=>!e.archived&&(Qt(e)||h.has(cP(e))||[`completed`,`failed`].includes(e.execution?.lastTurn?.outcome??``)&&(e.execution?.lastTurn?.finishedAt??0)>=$t.getTime())),tn=new Map([...h].map((e,t)=>[e,t])),nn=en.filter(e=>Qt(e)||h.has(cP(e))).sort((t,n)=>(tn.get(cP(t))??1/0)-(tn.get(cP(n))??1/0)||lP(t,e.connected)-lP(n,e.connected)||n.modified.localeCompare(t.modified)),rn=new Set(nn.map(e=>e.path)),an=en.filter(e=>!p||!rn.has(e.path)).sort((e,t)=>sP(t)-sP(e)),on=p?nn.slice(0,d):[],sn=an.slice(0,Math.max(0,d-on.length)),cn=en.length>on.length+sn.length;(0,_.useEffect)(()=>{let e=pe.current;if(!l||!cn||!e||typeof IntersectionObserver>`u`)return;let t=new IntersectionObserver(([e])=>{e?.isIntersecting&&(t.disconnect(),f(d+10))},{root:e.closest(`.sidebar-navigation`)});return t.observe(e),()=>t.disconnect()},[l,cn,d]),(0,_.useEffect)(()=>{if(!l){v.current=null,g(e=>e.size?new Set:e),f(10);return}let t=v.current??{openedAt:Date.now(),sessions:new Set((me?.sessions??[]).map(cP))},n=(me?.sessions??[]).filter(t=>!t.archived&&lP(t,e.connected)<3).sort((t,n)=>lP(t,e.connected)-lP(n,e.connected)||n.modified.localeCompare(t.modified)),r=n.filter(e=>!t.sessions.has(cP(e))&&Date.parse(e.created)>=t.openedAt);for(let e of me?.sessions??[])t.sessions.add(cP(e));v.current=t,g(e=>{let t=new Set([...r.map(cP),...e,...n.map(cP)]);return t.size===e.size?e:t})},[l,me?.sessions,e.connected]);let ln=(me?.sessions??[]).filter(e=>!e.archived&&e.unread),un=ln.filter(e=>e.readRevision),dn=p?nn.filter(e=>e.unread&&e.readRevision):[],fn=async e=>{if(!V){ee(!0);try{await Promise.all(e.map(e=>Ze(e,!0)))}finally{ee(!1)}}},pn=he?ge?nP(ge):me?.selectedSession?.cwd:null,mn=!!(me?.truncation.sessionsOmitted||me?.truncation.workspacesOmitted),hn=e=>{Ot.current||(oe(e.name),ce(!1),o(e))},gn=async()=>{let t=U.trim();if(!a||!t||t===a.name||Ot.current)return;let n=a,r=et.current,i=pt?.sessions.length??25;Ot.current=!0,Dt(!0),ce(!1);try{if(n.kind===`workspace`?await e.actions.renameWorkspace(n.path,t):await e.actions.renameSession(n.path,t),!nt.current)return;o(null),n.kind===`session`&&ye&&et.current===r&>(void 0,i)}catch{nt.current&&ce(!0)}finally{Ot.current=!1,nt.current&&Dt(!1)}},_n=async()=>{if(!re||Mt.current)return;let t=re;Mt.current=!0,jt(!0),Pt(!1);try{let n=await e.actions.removeWorkspace(t.path);if(!nt.current)return;n?ie(null):Pt(!0)}catch{nt.current&&Pt(!0)}finally{Mt.current=!1,nt.current&&jt(!1)}},vn=async t=>{if(Rt.current)return;let n=et.current;Rt.current=!0,It(!0);try{if(!t){await e.actions.chooseWorkspace();return}let r=await e.actions.createSession(t);if(!nt.current||et.current!==n||!r?.sessionId||!r.sessionPath||r.workspacePath!==t)return;be(!1),u(!1),e.actions.setQuery(``)}catch{}finally{Rt.current=!1,nt.current&&It(!1)}},yn=(0,_.useCallback)(()=>{(Ee.current||je.current)&&(Oe.current=Date.now()+250),Ee.current=null,je.current=null,Ae(!1),Fe(null),Ne(null)},[]);(0,_.useEffect)(()=>{let e=e=>{e.key!==`Escape`||!Ee.current&&!je.current||(e.preventDefault(),yn())},t=()=>{(Ee.current||je.current)&&yn()};return window.addEventListener(`keydown`,e,!0),window.addEventListener(`blur`,t),()=>{window.removeEventListener(`keydown`,e,!0),window.removeEventListener(`blur`,t)}},[yn]);let bn=(e,t)=>{let n=Gt[e];if(!n)return;let r=rP(Gt,e,t);Ye(Kt(n),!0,r?Kt(r):null)},xn=e=>Ve===`manual`?[{id:`move-up`,label:t(`movePinUp`),icon:(0,K.jsx)(k,{}),isDisabled:Ce||e<=0,onClick:()=>bn(e,!1)},{id:`move-down`,label:t(`movePinDown`),icon:(0,K.jsx)(w,{}),isDisabled:Ce||e===Gt.length-1,onClick:()=>bn(e,!0)}]:[],Sn=[{id:`updated`,label:t(`pinnedRecentlyUpdated`),endContent:Ge===`updated`?(0,K.jsx)(I,{size:16}):void 0,isDisabled:Ce,onClick:()=>void Xe({chatsSort:`updated`})},{id:`manual`,label:t(`pinnedManualOrder`),endContent:Ge===`manual`?(0,K.jsx)(I,{size:16}):void 0,isDisabled:Ce,onClick:()=>void Xe({chatsSort:`manual`})}],Cn=[{id:`updated`,label:t(`pinnedRecentlyUpdated`),endContent:Ve===`updated`?(0,K.jsx)(I,{size:16}):void 0,isDisabled:Ce,onClick:()=>void Xe({pinnedSort:`updated`})},{id:`manual`,label:t(`pinnedManualOrder`),endContent:Ve===`manual`?(0,K.jsx)(I,{size:16}):void 0,isDisabled:Ce,onClick:()=>void Xe({pinnedSort:`manual`})}],wn=[{label:t(`sidebarGroupBy`),items:[{label:t(`sidebarByProject`),endContent:We===`project`?(0,K.jsx)(I,{size:16}):void 0,isDisabled:Ce,onClick:()=>void Xe({sidebarGrouping:`project`})},{label:t(`sidebarFlatList`),endContent:We===`list`?(0,K.jsx)(I,{size:16}):void 0,isDisabled:Ce,onClick:()=>void Xe({sidebarGrouping:`list`})}]},{label:t(`sidebarChatSort`),items:Sn}],Tn=[...wn,...We===`project`?[{label:t(`sidebarShow`),items:[{label:t(`sidebarProjectsInRecents`),endContent:me?.preferences.projectsInRecents===!1?void 0:(0,K.jsx)(I,{size:16}),isDisabled:Ce,onClick:()=>void Xe({projectsInRecents:me?.preferences.projectsInRecents===!1})}]}]:[]],En=(0,K.jsxs)(`div`,{className:`sidebar-section-actions is-always-visible`,children:[(0,K.jsx)(uP,{label:t(`sidebarActivityOptions`),items:[{type:`section`,title:t(`sidebarShow`),items:[{label:t(`sidebarPriority`),endContent:p?(0,K.jsx)(I,{size:16}):void 0,onClick:()=>m(e=>!e)}]},{type:`divider`},{label:t(`sidebarMarkAllRead`),icon:(0,K.jsx)(Ue,{}),isDisabled:V||!dn.length,onClick:()=>void fn(dn)}]}),p&&nn.some(e=>!Qt(e))&&(0,K.jsx)(Cd,{content:t(`sidebarClearRead`),children:(0,K.jsx)(`button`,{className:`icon-button`,type:`button`,"aria-label":t(`sidebarClearRead`),onClick:()=>g(new Set(nn.filter(Qt).map(cP))),children:(0,K.jsx)(N,{"aria-hidden":`true`})})})]}),Dn=(n,r=!1,i)=>{let a=Gt.findIndex(e=>e.kind===`session`&&e.session.path===n.path&&e.session.id===n.id),o={kind:`session`,path:n.path,id:n.id},s=n.pinOrder!==void 0,c=e.connected!==!1&&n.execution?.status===`running`,u=e.connected!==!1&&n.execution?.waitingForInput,d=n.firstUnread?.type===`turn`?n.firstUnread.outcome:n.execution?.lastTurn?.outcome,f=u?`attention`:c?`running`:n.unread?d===`failed`?`attention`:d===`completed`?`completed`:`unread`:void 0,p=f===`running`?He:f===`attention`?H:ae,m=e.connected===!1?0:n.execution?.pendingFollowUps??0,h=n.path===he&&n.id===me?.selectedSession?.id,g=f===`attention`?u?`waiting`:`failed`:f===`running`&&n.execution?.compacting?`compacting`:f,_=[...g?[t(`sidebarState_`+g)]:[],...m>0?[t(`pendingFollowUpsHint`,{count:m})]:[]].join(` · `),v=i?.sessions.findIndex(e=>e.path===n.path&&e.id===n.id)??-1,y=!ye&&!r&&Ge===`manual`&&!!i,b=t=>qe(()=>e.actions.setSessionOrder(n.path,n.id,t?{path:t.path,id:t.id}:null)),x=r?xn(a):y&&i?[{id:`move-up`,label:t(`movePinUp`),icon:(0,K.jsx)(k,{}),isDisabled:Ce||v<=0,onClick:()=>void b(rP(i.sessions,v,!1))},{id:`move-down`,label:t(`movePinDown`),icon:(0,K.jsx)(w,{}),isDisabled:Ce||v===i.sessions.length-1,onClick:()=>void b(rP(i.sessions,v,!0))}]:[];return(0,K.jsxs)(`li`,{className:`session-row `+(n.unread?`is-unread `:``)+(Pe===n.path?Ie?`is-pin-drop-after`:`is-pin-drop-target`:``),"aria-label":ZA(n,t(`untitledSession`)),"data-session-key":JSON.stringify([n.path,n.id]),draggable:!Ce&&!e.query.trim()&&(r?Ve===`manual`:y),onDragStart:e=>{if(e.stopPropagation(),r&&Ve===`manual`)Ee.current=o;else if(y&&i)je.current={path:n.path,id:n.id,scope:i.key};else{e.preventDefault();return}Ae(!0),Oe.current=1/0,e.dataTransfer.effectAllowed=`move`,e.dataTransfer.setData(`text/plain`,n.id)},onDragOver:e=>{if(!(r&&Ve===`manual`&&Ee.current)&&!(y&&je.current?.scope===i?.key))return;e.preventDefault(),e.stopPropagation(),e.dataTransfer.dropEffect=`move`,Fe(n.path),Ne(null);let t=e.currentTarget.getBoundingClientRect();Le(aP(e.clientY,t))},onDragEnd:yn,onDrop:t=>{let n=t.currentTarget.getBoundingClientRect(),s=aP(t.clientY,n);if(r&&Ve===`manual`&&Ee.current){t.preventDefault(),t.stopPropagation();let e=Gt[a+1];Ye(Ee.current,!0,s?e?Kt(e):null:o)}else if(y&&i&&je.current?.scope===i.key){t.preventDefault(),t.stopPropagation();let n=je.current,r=iP(i.sessions,v,s);qe(()=>e.actions.setSessionOrder(n.path,n.id,r?{path:r.path,id:r.id}:null))}else return;yn()},children:[(0,K.jsxs)(`button`,{className:`session `+(h?`active`:``),type:`button`,"aria-current":h?`page`:void 0,"aria-label":[ZA(n,t(`untitledSession`)),n.path,_].filter(Boolean).join(` · `),onClick:()=>{h&&n.unread&&e.sessionViewVisible&&e.connected!==!1&&Ze(n,!0),e.actions.selectSession(n.path)},onDoubleClick:r=>{h&&e.connected!==!1&&r.target instanceof Element&&r.target.closest(`.session-title`)&&hn({kind:`session`,path:n.path,name:ZA(n,t(`untitledSession`))})},children:[(0,K.jsxs)(`span`,{className:`session-copy`,children:[(0,K.jsx)(`span`,{className:`session-title`,title:ZA(n,t(`untitledSession`)),children:ZA(n,t(`untitledSession`))}),l&&(0,K.jsxs)(`span`,{className:`session-project`,children:[(0,K.jsx)(De,{"aria-hidden":`true`}),me?.workspaces.find(e=>e.path===nP(n))?.name??$A(nP(n))]})]}),_&&(0,K.jsx)(Cd,{content:_,children:(0,K.jsxs)(`span`,{className:`session-status`,"aria-hidden":`true`,children:[f&&(0,K.jsx)(p,{className:`session-state session-state-`+f}),m>0&&(0,K.jsxs)(`span`,{className:`session-queue`,children:[(0,K.jsx)(Be,{}),(0,K.jsx)(`span`,{children:m>99?`99+`:m})]})]})})]}),!ye&&(0,K.jsx)(Cd,{content:t(s?`unpinConversation`:`pinConversation`),children:(0,K.jsx)(`button`,{type:`button`,className:`session-pin-button`,"aria-label":t(s?`unpinConversation`:`pinConversation`),disabled:Ce,onClick:e=>{let t=XN(e.currentTarget);Je(n,!s).finally(t)},children:(0,K.jsx)(st,{"aria-hidden":`true`,fill:s?`currentColor`:`none`})})}),(0,K.jsx)(ZN,{session:n,archived:ye,connected:e.connected!==!1,pinSaving:Ce,restoring:bt.has(n.path),movementItems:x,client:ve,actions:e.actions,onRename:()=>hn({kind:`session`,path:n.path,name:ZA(n,t(`untitledSession`))}),onPin:()=>Je(n,!s),onRead:()=>Ze(n,!!n.unread),onArchive:()=>ye?zt(n.path):e.actions.archiveSession(n.path),onNotice:(e,t=!1)=>B({message:e,error:t})})]},n.path)},On=(r,a=!1)=>{let o=(ye?_t:e.collapsed).has(r.path)&&!e.query.trim(),s=!r.ungrouped&&pn===r.path,c=Gt.findIndex(e=>e.kind===`workspace`&&e.project.path===r.path),l=qt.findIndex(e=>e.path===r.path),u=!ye&&!r.ungrouped&&!Ce&&!e.query.trim(),d=t=>qe(()=>e.actions.setWorkspaceOrder(r.path,rP(qt,l,t)?.path??null)),f={kind:`workspace`,path:r.path},p=Vt(r.sessions),m=un.filter(e=>!e.ungrouped&&nP(e)===r.path),h=ye||!!e.query.trim()||O.has(r.path)||p.length<=6,g=[...ye?[]:[{id:`pin`,label:t(a?`unpinWorkspace`:`pinWorkspace`),icon:(0,K.jsx)(st,{}),isDisabled:Ce,onClick:()=>void Ye(f,!a)},{id:`mark-read`,label:t(`sidebarMarkAllRead`),icon:(0,K.jsx)(Ue,{}),isDisabled:V||!m.length,onClick:()=>void fn(m)}],...a?xn(c):ye?[]:[{id:`move-up`,label:t(`movePinUp`),icon:(0,K.jsx)(k,{}),isDisabled:!u||l<=0,onClick:()=>void d(!1)},{id:`move-down`,label:t(`movePinDown`),icon:(0,K.jsx)(w,{}),isDisabled:!u||l===qt.length-1,onClick:()=>void d(!0)}],...r.ungrouped?[]:[{id:`managed-worktrees`,label:t(`managedWorktrees`),icon:(0,K.jsx)(De,{}),isDisabled:e.connected===!1,onClick:()=>{let e=Array.from(fe.current?.querySelectorAll(`.workspace-group`)??[]).find(e=>e.dataset.workspaceKey===r.path);n.current=XN(e?.querySelector(`.workspace-row-actions .menu-action-button`)??null),queueMicrotask(()=>i(r.path))}}],{id:`rename`,label:t(`renameWorkspace`),icon:(0,K.jsx)(wt,{}),onClick:()=>hn({kind:`workspace`,path:r.path,name:r.name})},{id:`remove`,label:t(`removeWorkspace`),icon:(0,K.jsx)(kt,{}),variant:`destructive`,onClick:()=>{Pt(!1),ie({path:r.path,name:r.name})}}];return(0,K.jsxs)(`section`,{className:`workspace-group `+(o?`collapsed `:``)+(s?`is-active-workspace `:``)+(Me===r.path?Ie?`is-pin-drop-after`:`is-pin-drop-target`:``),"data-workspace-key":r.path,"aria-label":r.name,onDragOver:e=>{if(!u||!Ee.current||(a?Ve!==`manual`:Ee.current.kind!==`workspace`))return;e.preventDefault(),e.stopPropagation(),e.dataTransfer.dropEffect=`move`,Ne(r.path),Fe(null);let t=e.currentTarget.getBoundingClientRect();Le(aP(e.clientY,t))},onDragEnd:yn,onDragLeave:e=>{(!(e.relatedTarget instanceof Node)||!e.currentTarget.contains(e.relatedTarget))&&Ne(null)},onDrop:t=>{if(!u||!Ee.current||(a?Ve!==`manual`:Ee.current.kind!==`workspace`))return;t.preventDefault(),t.stopPropagation();let n=t.currentTarget.getBoundingClientRect(),i=aP(t.clientY,n),o=Ee.current;if(o.kind!==`workspace`||o.path!==r.path)if(a){let e=Gt[c+1];Ye(o,!0,i?e?Kt(e):null:f)}else qe(()=>e.actions.setWorkspaceOrder(o.path,i?qt[l+1]?.path??null:r.path));yn()},children:[(0,K.jsxs)(`div`,{className:`workspace-button`,draggable:u&&(!a||Ve===`manual`),onDragStart:e=>{if(!u||a&&Ve!==`manual`||e.target instanceof Element&&e.target.closest(`.workspace-row-actions`)){e.preventDefault();return}Ee.current=f,requestAnimationFrame(()=>{nt.current&&Ee.current===f&&Ae(!0)}),Oe.current=1/0,e.dataTransfer.effectAllowed=`move`,e.dataTransfer.setData(`text/plain`,r.path)},children:[(0,K.jsxs)(`button`,{className:`workspace-label`,type:`button`,"aria-expanded":!o,"aria-current":s?`location`:void 0,disabled:!!e.query.trim(),title:r.ungrouped?void 0:r.path,onClick:()=>{ye?yt(e=>{let t=new Set(e);return t.has(r.path)?t.delete(r.path):t.add(r.path),t}):e.actions.toggleWorkspace(r.path)},children:[(0,K.jsx)(`span`,{className:`workspace-toggle`,"aria-hidden":`true`,children:o?(0,K.jsx)(De,{className:`workspace-folder`}):(0,K.jsx)(G,{className:`workspace-folder`})}),(0,K.jsxs)(`span`,{className:`workspace-identity`,children:[(0,K.jsx)(`strong`,{children:r.name}),r.showPath&&(0,K.jsx)(`small`,{children:$A(r.path)})]})]}),!r.ungrouped&&(0,K.jsxs)(`span`,{className:`workspace-row-actions`,children:[(0,K.jsx)(uP,{label:t(`workspaceOptions`),items:g}),(0,K.jsx)(Cd,{content:t(`newSession`),children:(0,K.jsx)(`button`,{className:`workspace-action`,type:`button`,"aria-label":t(`newSession`)+` `+r.name,disabled:Ft,"aria-busy":Ft||void 0,onClick:()=>void vn(r.path),children:(0,K.jsx)(wt,{})})})]})]}),!o&&!p.length&&!ye&&!e.query.trim()&&!mn&&(0,K.jsx)(`p`,{className:`workspace-empty`,children:t(`noConversations`)}),!o&&p.length>0&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`ul`,{className:`workspace-sessions`,children:(h?p:Ht(p,5)).map(e=>Dn(e,!1,{key:r.path,sessions:p}))}),!ye&&!e.query.trim()&&p.length>6&&(0,K.jsx)(`button`,{className:`sidebar-show-more is-indented`,type:`button`,"aria-expanded":O.has(r.path),onClick:()=>j(e=>{let t=new Set(e);return t.has(r.path)?t.delete(r.path):t.add(r.path),t}),children:t(O.has(r.path)?`sidebarShowLess`:`sidebarShowMore`)})]})]},r.path)},kn=new Map,An=new Date,jn=new Date(An);jn.setDate(An.getDate()-1);for(let e of sn){let n=new Date(sP(e)),r=n.toDateString()===An.toDateString()?t(`sidebarToday`):n.toDateString()===jn.toDateString()?t(`sidebarYesterday`):Number.isFinite(n.getTime())?n.toLocaleDateString(void 0,{weekday:`long`}):t(`sidebarEarlier`);kn.set(r,[...kn.get(r)??[],e])}return(0,K.jsxs)(`div`,{ref:fe,id:`session-sidebar`,className:`session-sidebar`,role:e.mobileOpen?`dialog`:`complementary`,"aria-modal":e.mobileOpen||void 0,"aria-label":`Session navigation`,tabIndex:e.mobileOpen?-1:void 0,onPointerDownCapture:()=>{!Ee.current&&!je.current&&(Oe.current=0)},onClickCapture:e=>{e.detail!==0&&Date.now(){if(!e.mobileOpen||t.defaultPrevented||t.target instanceof Element&&(t.target.closest(`dialog`)||t.key!==`Tab`&&t.target.closest(`[role="menu"]`))||t.key===`Escape`&&fe.current?.querySelector(`[aria-haspopup="menu"][aria-expanded="true"]`)||(t.key===`Escape`&&!t.nativeEvent.isComposing&&(t.preventDefault(),e.actions.closeMobileSidebar()),t.key!==`Tab`))return;let n=Array.from(fe.current?.querySelectorAll(`button, input, select, textarea, a[href], [tabindex]`)??[]).filter(e=>e.tabIndex>=0&&!e.matches(`:disabled`)&&e.checkVisibility({visibilityProperty:!0})),r=t.shiftKey?n.at(-1):n[0],i=t.shiftKey?n[0]:n.at(-1);(document.activeElement===fe.current||document.activeElement===i)&&(t.preventDefault(),r?.focus())},children:[(0,K.jsxs)(`div`,{className:`sidebar-brand`,children:[(0,K.jsx)(`span`,{className:`sidebar-brand-title`,children:`OpenPI`}),(0,K.jsxs)(`div`,{className:`sidebar-header-actions`,children:[(0,K.jsx)(Cd,{content:t(l?`sidebarViewChats`:`sidebarViewActivity`),children:(0,K.jsxs)(`button`,{className:`icon-button sidebar-activity-toggle`,type:`button`,"aria-label":t(l?`sidebarViewChats`:`sidebarViewActivity`),"aria-pressed":l,onClick:()=>{be(!1),u(e=>!e)},children:[(0,K.jsx)(A,{"aria-hidden":`true`}),ln.length>0&&(0,K.jsx)(`span`,{className:`sidebar-unread-dot`})]})}),(0,K.jsx)(Cd,{content:t(`searchConversations`),children:(0,K.jsx)(`button`,{ref:ue,className:`icon-button`,type:`button`,"aria-label":t(`searchConversations`),onClick:()=>c(!0),children:(0,K.jsx)(ht,{"aria-hidden":`true`})})}),(0,K.jsx)(Cd,{content:t(`collapseSidebar`),placement:`end`,children:(0,K.jsx)(`button`,{ref:W,className:`collapse-button sidebar-mobile-close`,type:`button`,"aria-label":t(`collapseSidebar`),onClick:()=>e.mobileOpen?e.actions.closeMobileSidebar():e.actions.toggleSidebar(!1),children:(0,K.jsx)(tt,{})})})]})]}),(0,K.jsxs)(`button`,{className:`new-session-button`,type:`button`,"aria-label":t(`newSession`),title:t(`newSession`),disabled:Ft,"aria-busy":Ft||void 0,onClick:()=>void vn(e.selectedWorkspace),children:[(0,K.jsx)(wt,{}),(0,K.jsx)(`span`,{children:t(`newSession`)})]}),(0,K.jsx)(eP,{open:s,initialQuery:e.query,initialIncludeArchived:ye,sessions:me?.sessions??[],workspaces:me?.workspaces??[],onClose:()=>c(!1),onOpenMessage:e.actions.navigateToMessage,onOpenSession:t=>e.actions.selectSession(t),onCreateSession:()=>void vn(e.selectedWorkspace)}),(0,K.jsxs)(`div`,{className:`sidebar-navigation`,children:[z&&(0,K.jsx)(`p`,{className:`sidebar-scope-note sidebar-action-feedback`,role:z.error?`alert`:`status`,children:z.message}),Re&&(0,K.jsx)(`p`,{className:`sidebar-scope-note`,role:`alert`,children:t(`sidebarSaveFailed`)}),F&&(0,K.jsx)(`p`,{className:`sidebar-scope-note`,role:`alert`,children:t(`sidebarReadFailed`)}),l?(0,K.jsxs)(`section`,{className:`sidebar-activity`,"aria-label":t(`sidebarActivity`),children:[p&&(0,K.jsxs)(`section`,{"aria-label":t(`sidebarPriority`),children:[(0,K.jsxs)(`div`,{className:`sidebar-section-heading`,children:[(0,K.jsx)(`h2`,{className:`sidebar-section-label`,children:t(`sidebarPriority`)}),En]}),(0,K.jsx)(`ul`,{className:`sidebar-activity-sessions`,children:on.map(e=>Dn(e))}),!on.length&&(0,K.jsx)(`p`,{className:`sidebar-activity-empty`,children:t(`sidebarActivityEmpty`)})]}),[...kn].map(([e,t],n)=>(0,K.jsxs)(`section`,{"aria-label":e,children:[(0,K.jsxs)(`div`,{className:`sidebar-section-heading`,children:[(0,K.jsx)(`h2`,{className:`sidebar-section-label`,children:e}),!p&&n===0&&En]}),(0,K.jsx)(`ul`,{className:`sidebar-activity-sessions`,children:t.map(e=>Dn(e))})]},e)),!p&&!kn.size&&(0,K.jsxs)(`section`,{"aria-label":t(`sidebarToday`),children:[(0,K.jsxs)(`div`,{className:`sidebar-section-heading`,children:[(0,K.jsx)(`h2`,{className:`sidebar-section-label`,children:t(`sidebarToday`)}),En]}),(0,K.jsx)(`p`,{className:`sidebar-activity-empty`,children:t(`sidebarActivityEmpty`)})]}),cn&&(0,K.jsx)(`div`,{ref:pe,className:`sidebar-activity-tail`,role:`status`,"aria-label":t(`loading`),children:(0,K.jsx)(He,{"aria-hidden":`true`})})]}):(0,K.jsxs)(K.Fragment,{children:[!ye&&(Gt.length>0||ke&&Ee.current&&Ve===`manual`)&&(0,K.jsxs)(`section`,{className:`pinned-section `+(Me===`pinned-tail`?`is-pin-drop-after`:``),"aria-label":t(`pinnedConversations`),onDragOver:t=>{Ce||Ve!==`manual`||!Ee.current||e.query.trim()||(t.preventDefault(),t.dataTransfer.dropEffect=`move`,Ne(`pinned-tail`),Fe(null))},onDragLeave:e=>{(!(e.relatedTarget instanceof Node)||!e.currentTarget.contains(e.relatedTarget))&&Ne(null)},onDrop:t=>{Ce||Ve!==`manual`||!Ee.current||e.query.trim()||(t.preventDefault(),t.stopPropagation(),Ye(Ee.current,!0,null),yn())},children:[(0,K.jsxs)(`div`,{className:`sidebar-section-heading`,children:[(0,K.jsxs)(`button`,{type:`button`,className:`workspace-heading-label`,"aria-expanded":!xe||!!e.query.trim(),onClick:()=>Se(e=>!e),children:[t(`pinnedConversations`),(0,K.jsx)(L,{className:xe&&!e.query.trim()?`is-collapsed`:``,"aria-hidden":`true`})]}),(0,K.jsx)(`div`,{className:`sidebar-section-actions`,children:(0,K.jsx)(uP,{label:t(`pinnedOptions`),items:Cn,alignment:`end`})})]}),ke&&Ve===`manual`&&(Gt.length===0||xe)&&(0,K.jsx)(`p`,{className:`sidebar-drop-hint`,children:t(`sidebarDropPin`)}),(!xe||!!e.query.trim())&&(0,K.jsx)(`ul`,{className:`pinned-sessions`,children:Gt.map(e=>e.kind===`session`?Dn(e.session,!0):(0,K.jsx)(`li`,{className:`pinned-workspace`,children:On(e.project,!0)},e.project.path))})]}),(ye||We===`project`||e.searchOpen)&&(0,K.jsxs)(`div`,{className:`workspace-heading sidebar-section-heading `+(e.searchOpen?`is-searching`:``),children:[(0,K.jsxs)(`button`,{type:`button`,className:`workspace-heading-label`,"aria-label":t(ye?`currentConversations`:`sidebarProjects`),"aria-expanded":ye?void 0:!x||!!e.query.trim(),onClick:()=>ye?be(!1):S(e=>!e),children:[ye&&(0,K.jsx)(T,{"aria-hidden":`true`}),t(ye?`archivedConversations`:`sidebarProjects`),!ye&&(0,K.jsx)(L,{className:x&&!e.query.trim()?`is-collapsed`:``,"aria-hidden":`true`})]}),(0,K.jsxs)(`div`,{className:`session-search`,children:[(0,K.jsx)(ht,{}),(0,K.jsx)(`input`,{ref:le,type:`search`,value:e.query,placeholder:t(`searchPlaceholder`),maxLength:ye?160:void 0,"aria-label":t(`searchConversations`),onChange:t=>e.actions.setQuery(t.target.value)}),(0,K.jsx)(`button`,{type:`button`,"aria-label":t(`closeSearch`),onClick:()=>e.actions.setSearchOpen(!1),children:(0,K.jsx)(Lt,{})})]}),(0,K.jsxs)(`div`,{className:`workspace-actions sidebar-section-actions`,children:[!ye&&(0,K.jsx)(uP,{label:t(`sidebarProjectOptions`),items:wn}),ye&&(0,K.jsx)(Cd,{content:t(`sidebarFilterList`),children:(0,K.jsx)(`button`,{className:`icon-button`,type:`button`,"aria-label":t(`sidebarFilterList`),onClick:()=>e.actions.setSearchOpen(!0),children:(0,K.jsx)(ht,{})})}),!ye&&(0,K.jsx)(Cd,{content:t(`addWorkspace`),children:(0,K.jsx)(`button`,{className:`icon-button`,type:`button`,"aria-label":t(`addWorkspace`),onClick:()=>void e.actions.chooseWorkspace(),children:(0,K.jsx)(lt,{})})})]})]}),e.searchOpen&&(0,K.jsxs)(`button`,{type:`button`,className:`sidebar-content-search`,onClick:()=>c(!0),children:[(0,K.jsx)(ht,{"aria-hidden":`true`}),t(`transcriptSearch`)]}),ye&&(0,K.jsxs)(`div`,{className:`sidebar-archive-actions`,children:[(0,K.jsx)(`button`,{type:`button`,className:`icon-button`,"aria-label":t(`refreshArchives`),title:t(`refreshArchives`),disabled:at,onClick:()=>void gt(),children:(0,K.jsx)(dt,{"aria-hidden":`true`})}),at&&(0,K.jsx)(`span`,{role:`status`,children:t(`loadingArchives`)})]}),ye&&mt&&(0,K.jsxs)(`div`,{className:`sidebar-scope-note`,role:`alert`,children:[(0,K.jsx)(`p`,{children:t(mt.kind===`stale`?`archiveCursorStale`:`archiveLoadFailed`)}),(0,K.jsx)(`button`,{type:`button`,disabled:at,onClick:()=>void gt(mt.kind===`stale`?void 0:mt.cursor,mt.retainedCount),children:t(mt.kind===`stale`?`refreshArchives`:`retryArchives`)})]}),ye&&!!pt?.truncation.recordsUnscanned&&(0,K.jsx)(`p`,{className:`sidebar-scope-note`,children:t(`archiveScanBounded`,{count:pt?.truncation.recordsUnscanned})}),!ye&&mn&&(0,K.jsx)(`p`,{className:`sidebar-scope-note`,children:t(`loadedHistoryBounded`,{sessions:me?.truncation.sessionsOmitted,workspaces:me?.truncation.workspacesOmitted})}),ye&&Ct&&(0,K.jsx)(`p`,{className:`sidebar-scope-note`,role:`alert`,children:t(`restoreFailed`)}),(0,K.jsxs)(`div`,{className:`workspace-tree`,children:[(ye?Bt:We===`project`&&(!x||e.query.trim())?Jt:[]).map(e=>On(e)),!ye&&We===`project`&&ke&&Ee.current?.kind===`workspace`&&!e.query.trim()&&(0,K.jsx)(`section`,{className:`sidebar-project-tail `+(Me===`project-tail`?`is-pin-drop-target`:``),"aria-label":t(`sidebarDropProjectLast`),onDragOver:e=>{Ce||Ee.current?.kind!==`workspace`||(e.preventDefault(),e.dataTransfer.dropEffect=`move`,Ne(`project-tail`),Fe(null))},onDragLeave:e=>{(!(e.relatedTarget instanceof Node)||!e.currentTarget.contains(e.relatedTarget))&&Ne(null)},onDrop:t=>{if(Ce||Ee.current?.kind!==`workspace`)return;t.preventDefault();let n=Ee.current;qe(()=>e.actions.setWorkspaceOrder(n.path,null)),yn()},children:t(`sidebarDropProjectLast`)}),!ye&&We===`project`&&!x&&!e.query.trim()&&qt.length>6&&(0,K.jsx)(`button`,{className:`sidebar-show-more`,type:`button`,"aria-expanded":y,onClick:()=>b(e=>!e),children:t(y?`sidebarShowLess`:`sidebarShowMore`)}),!ye&&(0,K.jsxs)(`section`,{className:`sidebar-recents`,"aria-label":t(`sidebarRecent`),children:[(0,K.jsxs)(`div`,{className:`sidebar-section-heading`,children:[(0,K.jsxs)(`button`,{type:`button`,className:`workspace-heading-label`,"aria-expanded":!E||!!e.query.trim(),onClick:()=>D(e=>!e),children:[t(`sidebarRecent`),(0,K.jsx)(L,{className:E&&!e.query.trim()?`is-collapsed`:``,"aria-hidden":`true`})]}),(0,K.jsx)(`div`,{className:`sidebar-section-actions`,children:(0,K.jsx)(uP,{label:t(`sidebarRecentOptions`),items:Tn})})]}),(!E||!!e.query.trim())&&(0,K.jsx)(`ul`,{className:`recent-sessions`,children:Zt.map(e=>Dn(e,!1,{key:`recent`,sessions:Xt}))}),!E&&Zt.lengthP(e=>e+10),children:t(`sidebarShowMore`)})]}),(ye?!Bt.length:!Gt.length&&!Xt.length&&(We===`list`||!qt.length))&&(0,K.jsx)(`div`,{className:`empty`,hidden:ye&&(at||!!mt),children:e.query.trim()?t(ye&&pt?.truncation.recordsUnscanned?`noMatchingScannedArchives`:!ye&&mn?`noMatchingLoaded`:`noMatching`):t(ye?pt?.truncation.recordsUnscanned?`noScannedArchives`:`noArchivedSessions`:`noSessions`)}),ye&&pt?.nextCursor&&mt?.kind!==`stale`&&(0,K.jsx)(`button`,{type:`button`,className:`sidebar-archive-more`,disabled:at,onClick:()=>void gt(pt.nextCursor),children:t(`moreArchives`)})]})]})]}),(0,K.jsxs)(`div`,{className:`sidebar-footer`,children:[(0,K.jsxs)(`button`,{className:`sidebar-settings-button sidebar-archive-toggle`,type:`button`,"aria-label":t(`archivedConversations`),"aria-pressed":ye,title:t(`archivedConversations`),onClick:()=>{u(!1),be(e=>!e)},children:[(0,K.jsx)(C,{"aria-hidden":`true`}),(0,K.jsx)(`span`,{children:t(`archivedConversations`)})]}),(0,K.jsxs)(`button`,{className:`sidebar-settings-button`,type:`button`,"aria-label":t(`settings`),title:t(`settings`),"data-provider-settings-trigger":!0,disabled:e.settingsDisabled,onClick:e.onOpenSettings,children:[(0,K.jsx)(vt,{"aria-hidden":`true`}),(0,K.jsx)(`span`,{children:t(`settings`)})]})]}),(0,K.jsx)($j,{isOpen:!!a,onOpenChange:e=>!e&&!Ot.current&&o(null),purpose:`form`,width:400,"aria-label":a?.kind===`workspace`?t(`renameWorkspace`):t(`renameConversation`),children:(0,K.jsxs)(`form`,{className:`openpi-dialog`,onSubmit:e=>{e.preventDefault(),gn()},children:[(0,K.jsx)(`strong`,{children:a?.kind===`workspace`?t(`renameWorkspace`):t(`renameConversation`)}),(0,K.jsx)(`input`,{ref:de,value:U,maxLength:80,disabled:Et,"aria-label":a?.kind===`workspace`?t(`workspaceName`):t(`conversationName`),onChange:e=>oe(e.target.value)}),se&&(0,K.jsx)(`p`,{className:`sidebar-dialog-error`,role:`alert`,children:t(`renameFailed`)}),(0,K.jsxs)(`div`,{className:`dialog-actions`,children:[(0,K.jsx)(`button`,{type:`button`,disabled:Et,onClick:()=>{Ot.current||o(null)},children:t(`cancel`)}),(0,K.jsx)(`button`,{type:`submit`,className:`primary`,disabled:Et||!U.trim()||U.trim()===a?.name,children:t(Et?`savingName`:`save`)})]})]})}),r&&(0,K.jsx)(tP,{workspace:r,client:ve,actions:e.actions,connected:e.connected!==!1,onClose:()=>{i(null),n.current?.()}},r),(0,K.jsx)($j,{isOpen:!!re,onOpenChange:e=>!e&&!Mt.current&&ie(null),purpose:`form`,width:440,"aria-label":t(`removeWorkspace`),children:(0,K.jsxs)(`div`,{className:`openpi-dialog`,children:[(0,K.jsx)(`strong`,{children:t(`removeWorkspace`)}),(0,K.jsx)(`p`,{className:`sidebar-dialog-path`,children:re?.path}),(0,K.jsxs)(`p`,{children:[re?.name,`:`,t(`workspaceDeleteConfirm`)]}),Nt&&(0,K.jsx)(`p`,{className:`sidebar-dialog-error`,role:`alert`,children:t(`workspaceRemoveFailed`)}),(0,K.jsxs)(`div`,{className:`dialog-actions`,children:[(0,K.jsx)(`button`,{type:`button`,disabled:At,onClick:()=>{Mt.current||ie(null)},children:t(`cancel`)}),(0,K.jsx)(`button`,{type:`button`,className:`danger`,disabled:At,onClick:()=>void _n(),children:t(At?`removingWorkspace`:`removeWorkspace`)})]})]})})]})}var fP=(0,_.createContext)(null);fP.displayName=`LayoutAreaContext`;var pP=(0,_.createContext)({hasHeader:!1,hasFooter:!1,hasStart:!1,hasEnd:!1});pP.displayName=`LayoutSlotsContext`;var mP={center:{kGNEyG:`x6s0dn4`,$$css:!0},end:{kGNEyG:`xuk3077`,$$css:!0},start:{kGNEyG:`x1cy8zhl`,$$css:!0},stretch:{kGNEyG:`x1qjc9v5`,$$css:!0}},hP={start:{kjj79g:`x1nhvcw1`,$$css:!0},center:{kjj79g:`xl56j7k`,$$css:!0},end:{kjj79g:`x13a6bvl`,$$css:!0},between:{kjj79g:`x1qughib`,$$css:!0},around:{kjj79g:`x1l1ennw`,$$css:!0},evenly:{kjj79g:`xaw8158`,$$css:!0}},gP={horizontal:{kXwgrk:`x1q0g3np`,$$css:!0},vertical:{kXwgrk:`xdt5ytf`,$$css:!0}},_P={nowrap:{kwnvtZ:`xozqiw3`,$$css:!0},wrap:{kwnvtZ:`x1a02dak`,$$css:!0},"wrap-reverse":{kwnvtZ:`x8hhl5t`,$$css:!0}},vP={stack:{k1xSpc:`x78zum5`,$$css:!0}},yP={0:{k1C7PZ:`x1o57wo1`,khm7nJ:`x6yxi7o`,$$css:!0},1:{k1C7PZ:`x1lfs0n9`,khm7nJ:`x1ngg2t4`,$$css:!0},2:{k1C7PZ:`xak3so`,khm7nJ:`x1x7z4sm`,$$css:!0},3:{k1C7PZ:`xewh9hi`,khm7nJ:`x4olc9o`,$$css:!0},4:{k1C7PZ:`xty4p9g`,khm7nJ:`xtx9w7w`,$$css:!0},5:{k1C7PZ:`x1eqhezk`,khm7nJ:`x1iu6piu`,$$css:!0},6:{k1C7PZ:`x3qlgwd`,khm7nJ:`xczp1bk`,$$css:!0},8:{k1C7PZ:`xicv188`,khm7nJ:`xgx0vcf`,$$css:!0},10:{k1C7PZ:`x1p37tyl`,khm7nJ:`x1xpicb7`,$$css:!0},"0.5":{k1C7PZ:`x1kihgfc`,khm7nJ:`x1tw44j4`,$$css:!0},"1.5":{k1C7PZ:`x1thn6ci`,khm7nJ:`xhq53yo`,$$css:!0}};function bP({crossAlign:e,direction:t,gap:n,mainAlign:r,wrap:i}){return[vP.stack,gP[t],n!=null&&yP[n],e!=null&&mP[e],r!=null&&hP[r],i!=null&&_P[i]]}var xP={reset:{kAzted:`x2lwn1j`,k7Eaqz:`xeuugli`,$$css:!0}},SP={center:{kSGwAc:`xamitd3`,$$css:!0},end:{kSGwAc:`xpvyfi4`,$$css:!0},start:{kSGwAc:`xqcrz7y`,$$css:!0},stretch:{kSGwAc:`xkh2ocl`,$$css:!0}},CP={fill:{kzQI83:`x1iyjqo2`,$$css:!0},static:{kzQI83:`x1c4vz4f`,kmuXW:`x2lah0s`,$$css:!0}};function wP({crossAlignSelf:e,size:t}={}){return[xP.reset,CP[t??`static`],e!=null&&SP[e]]}var TP={layoutOuter:{keTefX:`xojxgvx`,k71WvV:`x1fcf3bl`,keoZOQ:`x1sa9bsh`,k1K539:`x6h7pi7`,$$css:!0},layoutInner:{"--container-padding-inline-start":`xrhngw9`,"--container-padding-inline-end":`xjsfl84`,"--container-padding-block-start":`x1047aw6`,"--container-padding-block-end":`xax9j7h`,$$css:!0},fill:{kZKoxP:`x12qplqi`,kskxy:`xenllk4`,$$css:!0},auto:{kAzted:`x1us19tq`,$$css:!0},middle:{kUk6DE:`x98rzlu`,kAzted:`x2lwn1j`,$$css:!0},fullBleed:{"--layout-padding-outer-x":`x1wbjvqu`,"--layout-padding-outer-y":`xzxxx64`,$$css:!0}},EP={kzqmXN:`xh8yej3`,kUOVxO:`xvueqy4`,$$css:!0},DP={contentWidthVar:e=>[{"--layout-content-width":(typeof e==`number`?`${e}px`:e)==null?typeof e==`number`?`${e}px`:e:`x4906uf`,$$css:!0},{"--x---layout-content-width":(typeof e==`number`?`${e}px`:e)==null?void 0:typeof e==`number`?`${e}px`:e}],contentWidth:e=>[EP,{ks0D6T:(typeof e==`number`?`${e}px`:e)==null?typeof e==`number`?`${e}px`:e:`xf68679`,$$css:!0},{"--x-maxWidth":(e=>typeof e==`number`?e+`px`:e??void 0)(typeof e==`number`?`${e}px`:e)}]};function OP({area:e,children:t}){return t==null?null:(0,K.jsx)(fP,{value:e,children:t})}var kP={"x-default-marker":`x-default-marker`,$$css:!0};function AP({children:e,content:t,contentWidth:n,defaultHasDividers:r,end:i,footer:a,header:o,height:s=`fill`,padding:c,ref:l,start:u,xstyle:d,className:f,style:p}){let m=s===`fill`,h=t??e,g=(0,_.useMemo)(()=>r==null?null:{defaultHasDividers:r},[r]),v=o!=null,y=a!=null,b=u!=null,x=i!=null,S=(0,_.useMemo)(()=>({hasHeader:v,hasFooter:y,hasStart:b,hasEnd:x}),[v,y,b,x]),C=(0,K.jsx)(pP,{value:S,children:(0,K.jsx)(`div`,{ref:l,...oa(ba(`layout`,{height:s}),Sr(TP.layoutOuter,m?TP.fill:TP.auto,d),f,p),children:(0,K.jsxs)(`div`,{...Sr(kP,TP.layoutInner,...bP({direction:`vertical`}),m?TP.fill:TP.auto,c===0&&TP.fullBleed,c!=null&&oi[c],c!=null&&si[c],n!=null&&DP.contentWidthVar(n)),children:[(0,K.jsx)(OP,{area:`header`,children:o}),(0,K.jsxs)(`div`,{...Sr(...bP({direction:`horizontal`}),TP.middle,n!=null&&DP.contentWidth(n)),children:[(0,K.jsx)(OP,{area:`start`,children:u}),(0,K.jsx)(`div`,{...Sr(...wP({size:`fill`})),children:(0,K.jsx)(OP,{area:`content`,children:h})}),(0,K.jsx)(OP,{area:`end`,children:i})]}),(0,K.jsx)(OP,{area:`footer`,children:a})]})})});return g==null?C:(0,K.jsx)(eM,{value:g,children:C})}AP.displayName=`Layout`;var jP={content:{kB7OPa:`x9f619`,kZKoxP:`x5yr21d`,kUk6DE:`x98rzlu`,kAzted:`x2lwn1j`,kVQacm:`x7giv3`,kZCmMZ:`xwjyata`,kwRFfy:`x1peupej`,kLKAdn:`xqty4a x1ioh5az`,kGO01o:`xg476vw xsg11nj`,"--container-padding-inline-start":`x408pgh`,"--container-padding-inline-end":`xikqloz`,"--container-padding-block-start":`xjmgx01`,"--container-padding-block-end":`xi9ns85`,$$css:!0},noStart:{kZCmMZ:`x139j0dd`,"--container-padding-inline-start":`xdvaxxn`,"--container-padding-inline-end":`xqpvj4r`,$$css:!0},noEnd:{kwRFfy:`xpc6k2p`,$$css:!0},noHeader:{kLKAdn:`x81pis9`,"--container-padding-block-start":`xzz8v79`,$$css:!0},noFooter:{kGO01o:`xon7vh3`,"--container-padding-block-end":`x1xjq73n`,$$css:!0},scrollable:{kVQacm:`xysyzu8`,$$css:!0},fullBleed:{kZCmMZ:`x1c1uobl`,kwRFfy:`xyri2b`,kLKAdn:`xexx8yu`,kGO01o:`x18d9i69`,"--container-padding-inline-start":`xrhngw9`,"--container-padding-inline-end":`xjsfl84`,"--container-padding-block-start":`x1047aw6`,"--container-padding-block-end":`xax9j7h`,$$css:!0}};function MP({children:e,isScrollable:t=!0,padding:n,label:r,role:i,xstyle:a,className:o,style:s,ref:c,...l}){let{hasHeader:u,hasFooter:d,hasStart:f,hasEnd:p}=(0,_.use)(pP),m=n===0;return(0,K.jsx)(`div`,{ref:c,role:i,"aria-label":r,...oa(ba(`layout-content`),Sr(jP.content,!f&&!m&&n==null&&jP.noStart,!p&&!m&&n==null&&jP.noEnd,!u&&!m&&n==null&&jP.noHeader,!d&&!m&&n==null&&jP.noFooter,t&&jP.scrollable,m&&jP.fullBleed,n!=null&&ni[n],n!=null&&ri[n],n!=null&&ii[n],n!=null&&ai[n],a),o,s),...l,children:e})}MP.displayName=`LayoutContent`;var NP={footer:{kmuXW:`x2lah0s`,$$css:!0},inner:{kB7OPa:`x9f619`,ks0D6T:`xjl2t3p`,kUOVxO:`xvueqy4`,kZCmMZ:`x139j0dd`,kwRFfy:`xpc6k2p`,kLKAdn:`xqty4a`,kGO01o:`xon7vh3`,"--container-padding-inline-start":`xdvaxxn`,"--container-padding-inline-end":`xqpvj4r`,"--container-padding-block-start":`xjmgx01`,"--container-padding-block-end":`x1xjq73n`,$$css:!0},fullBleed:{kZCmMZ:`x1c1uobl`,kwRFfy:`xyri2b`,kLKAdn:`xexx8yu`,kGO01o:`x18d9i69`,"--container-padding-inline-start":`xrhngw9`,"--container-padding-inline-end":`xjsfl84`,"--container-padding-block-start":`x1047aw6`,"--container-padding-block-end":`xax9j7h`,$$css:!0},divider:{kEafiO:`x178xt8z`,kPef9Z:`x13fuv20`,kLZC3w:`x1pc3f07`,$$css:!0}},PP={sizing:e=>[{kZKoxP:e==null?e:`x16ye13r`,$$css:!0},{"--x-height":(e=>typeof e==`number`?e+`px`:e??void 0)(e)}]};function FP({children:e,hasDivider:t,height:n,label:r,padding:i,role:a,xstyle:o,className:s,style:c,ref:l,...u}){let d=(0,_.use)(eM),f=t??d?.defaultHasDividers??!1,p=i===0;return(0,K.jsx)(`div`,{ref:l,role:a,"aria-label":r,"data-divider":f||void 0,...oa(ba(`layout-footer`),Sr(NP.footer,PP.sizing(n??null),f&&NP.divider,o),s,c),...u,children:(0,K.jsx)(`div`,{...Sr(NP.inner,p&&NP.fullBleed,i!=null&&ni[i],i!=null&&ri[i],i!=null&&ii[i],i!=null&&ai[i]),children:e})})}FP.displayName=`LayoutFooter`;var IP={scrollable:{kVQacm:`xysyzu8`,$$css:!0}};function LP({direction:e=`vertical`,hAlign:t,vAlign:n,justify:r,align:i,gap:a,padding:o,paddingInline:s,paddingInlineStart:c,paddingInlineEnd:l,paddingBlock:u,paddingBlockStart:d,paddingBlockEnd:f,isScrollable:p,width:m,height:h,maxWidth:g,minHeight:v,wrap:y,as:b=`div`,xstyle:x,className:S,style:C,children:w,ref:T,...E}){let D=t??(e===`horizontal`?r:i),O=n??(e===`horizontal`?i:r),k=e===`horizontal`?D:O,A=e===`horizontal`?O:D,j=c??s??o,M=l??s??o,N=d??u??o,P=f??u??o,F=Sr(...bP({direction:e,crossAlign:A,mainAlign:k,gap:a,wrap:y}),j!=null&&ci[j],M!=null&&li[M],N!=null&&ui[N],P!=null&&di[P],p&&IP.scrollable,x),I={...m!=null&&{width:typeof m==`number`?`${m}px`:m},...h!=null&&{height:typeof h==`number`?`${h}px`:h},...g!=null&&{maxWidth:typeof g==`number`?`${g}px`:g},...v!=null&&{minHeight:typeof v==`number`?`${v}px`:v}};return(0,_.createElement)(b,{ref:T,...oa(ba(`stack`,{direction:e,gap:a,wrap:y}),F,S,{...C,...I}),...E},w)}LP.displayName=`Stack`;function RP({ref:e,justify:t,align:n,hAlign:r,vAlign:i,...a}){return(0,K.jsx)(LP,{...a,direction:`horizontal`,hAlign:r??t,vAlign:i??n,ref:e})}RP.displayName=`HStack`;function zP({ref:e,justify:t,align:n,hAlign:r,vAlign:i,...a}){return(0,K.jsx)(LP,{...a,direction:`vertical`,hAlign:r??n,vAlign:i??t,ref:e})}zP.displayName=`VStack`;var BP=`(max-width: 640px)`,VP={action:{ks0D6T:`x193iq5w`,k7Eaqz:`xeuugli`,$$css:!0},stackedAction:{kzqmXN:`xh8yej3`,$$css:!0}};function HP({ref:e,isOpen:t,isInline:n,onOpenChange:r,title:i,description:a,cancelLabel:o,actionLabel:s,actionVariant:c=`destructive`,isActionLoading:l,onAction:u,width:d=400,xstyle:f,className:p,style:m,"data-testid":h,...g}){let v=Rc(),y=o??v(`@astryx.alertDialog.cancel`),b=(0,_.useId)(),x=(0,_.useId)(),S=Wl(BP),C=(0,_.useCallback)(()=>{r(!1)},[r]),w=[VP.action,S&&VP.stackedAction],T=(0,K.jsx)(qc,{variant:`ghost`,label:y,onClick:C,xstyle:w,"data-autofocus":!0},`cancel`),E=(0,K.jsx)(qc,{variant:c,label:s,onClick:u,isLoading:l,xstyle:w},`action`);return(0,K.jsx)($j,{...g,ref:e,isOpen:t,isInline:n,onOpenChange:r,width:d,purpose:`form`,role:n?`group`:`alertdialog`,"aria-labelledby":b,"aria-describedby":x,...oa(ba(`alert-dialog`),{className:p,style:m}),xstyle:f,"data-testid":h,children:(0,K.jsx)(AP,{content:(0,K.jsxs)(MP,{children:[(0,K.jsx)(rM,{level:2,id:b,children:i}),(0,K.jsx)(zo,{type:`body`,color:`secondary`,id:x,children:a})]}),footer:(0,K.jsx)(FP,{children:(0,K.jsx)(LP,{direction:S?`vertical`:`horizontal`,gap:2,hAlign:S?`stretch`:`end`,wrap:S?`nowrap`:`wrap`,children:S?[E,T]:[T,E]})})})})}HP.displayName=`AlertDialog`;var UP={x1iwu4tg:`x1iwu4tg`,$$css:!0},WP={sm:{kzqmXN:`x1td3qas`,kZKoxP:`x1qx5ct2`,$$css:!0},md:{kzqmXN:`x100vrsf`,kZKoxP:`xxk0z11`,$$css:!0}},GP={sm:{kzqmXN:`x1td3qas`,kZKoxP:`x1qx5ct2`,$$css:!0},md:{kzqmXN:`x100vrsf`,kZKoxP:`xxk0z11`,$$css:!0}},KP={sm:{kzqmXN:`x1td3qas`,kZKoxP:`x1qx5ct2`,kmVPX3:`x1i3ajwb`,$$css:!0},md:{kzqmXN:`x100vrsf`,kZKoxP:`xxk0z11`,kmVPX3:`xfawy5m`,$$css:!0}},qP={sm:{kzqmXN:`x6jxa94`,kZKoxP:`x1v9usgg`,k3aq6I:`xbryuvx`,$$css:!0},md:{kzqmXN:`x1kky2od`,kZKoxP:`xlup9mm`,k3aq6I:`xbryuvx`,$$css:!0}},JP={sm:{kzqmXN:`x1kky2od`,kZKoxP:`xlup9mm`,k3aq6I:`xv5t66b xi9aj42`,$$css:!0},md:{kzqmXN:`xw4jnvo`,kZKoxP:`x1qx5ct2`,k3aq6I:`x15481yp x12xz5k6`,$$css:!0}},YP={sm:{kAzted:`xisnujt`,$$css:!0},md:{kAzted:`xjwf9q1`,$$css:!0}},XP={container:{k1xSpc:`x78zum5`,kGNEyG:`x6s0dn4`,kOIVth:`x1txdalj`,$$css:!0},containerLabelHidden:{kOIVth:`xxhr3t`,$$css:!0},containerSpread:{kjj79g:`x1qughib`,kzqmXN:`xh8yej3`,$$css:!0},statusGap:{keoZOQ:`xtbrsbv`,$$css:!0},switchWrapper:{kVAEAm:`x1n2onr6`,k1xSpc:`x78zum5`,kGNEyG:`x6s0dn4`,kmuXW:`x2lah0s`,kHBbk8:`xc8icb0`,$$css:!0},input:{kVAEAm:`x10l6tqk`,kogj98:`x1ghz6dp`,kmVPX3:`x1717udv`,kSiTet:`xg01cxk`,kkrTdU:`x1ypdohk x16khyan`,kY2c9j:`x1vjfegm`,k7Eaqz:`xkagaj0`,kAzted:`x80b3aj`,k87sOh:`xijlfn0`,kLqNvP:`x1hsn8va`,k3aq6I:`x8i4i9p`,$$css:!0},inputDisabled:{kkrTdU:`xt0e3qv`,$$css:!0},inputBusy:{kfzvcC:`x47corl`,$$css:!0},track:{k1xSpc:`x78zum5`,kGNEyG:`x6s0dn4`,kaIpWk:`xjspbzw`,k1ekBW:`x15406qy`,kIyJzY:`xuedmi6 x12w9bfk`,kAMwcw:`xlr8y92`,kB7OPa:`x9f619`,kMzoRj:`xc342km x13rsnn2`,ksu8eU:`xng3xce xx61lck`,kVAM5u:`x1w1tqly`,$$css:!0},trackFocus:{kI3sdo:`x1a2a7pz xafswnp`,kInvED:`xwz5zln`,$$css:!0},trackOff:{kWkggS:`xspzpui x1a8ae7b x9yvj25`,$$css:!0},trackOn:{kWkggS:`x1ewilqj xcgwt1n x1jzqe4`,$$css:!0},trackDisabled:{kSiTet:`xbyyjgo`,kVAM5u:`xmnqt3w`,$$css:!0},trackDisabledOff:{kWkggS:`xspzpui`,$$css:!0},thumb:{k1xSpc:`x78zum5`,kGNEyG:`x6s0dn4`,kjj79g:`xl56j7k`,kaIpWk:`xjspbzw`,k1ekBW:`xh3q6i0`,kIyJzY:`xuedmi6 x12w9bfk`,kAMwcw:`xlr8y92`,$$css:!0},thumbOff:{kWkggS:`x10xzikg xwvh9j7`,$$css:!0},thumbOn:{kWkggS:`x10xzikg x1sir5s4`,$$css:!0},labelWrapper:{k1xSpc:`x78zum5`,kXwgrk:`xdt5ytf`,kOIVth:`x1lsbc85`,kjj79g:`xl56j7k`,$$css:!0}},ZP={width:e=>[{kzqmXN:e==null?e:`x5lhr3w`,$$css:!0},{"--x-width":(e=>typeof e==`number`?e+`px`:e??void 0)(e)}]};function QP({label:e,isLabelHidden:t=!1,description:n,onChange:r,changeAction:i,isLoading:a=!1,value:o,isDisabled:s=!1,htmlName:c,disabledMessage:l,isOptional:u=!1,isRequired:d=!1,onFocus:f,onBlur:p,labelIcon:m,labelTooltip:h,labelPosition:g=`end`,labelSpacing:v=`hug`,status:y,size:b=`md`,width:x,xstyle:S,className:C,style:w,ref:T,...E}){let D=(0,_.useId)(),O=(0,_.useId)(),k=(0,_.useId)(),A=HM({isRequired:d,isOptional:u}),[,j]=(0,_.useTransition)(),[M,N]=(0,_.useOptimistic)(o),P=a||M!==o,F=M===!0,I=s&&!!l,L=po({placement:`above`,focusTrigger:`always`,isEnabled:I}),R=[];n&&R.push(O),y?.message&&R.push(k),I&&R.push(L.describedBy);let z=R.length>0?R.join(` `):void 0,B=(0,K.jsxs)(`div`,{...Sr(XP.switchWrapper,WP[b]),children:[(0,K.jsx)(`input`,{ref:Ao(T,L.positionRef),id:D,type:`checkbox`,role:`switch`,name:s?void 0:c,checked:F,disabled:s&&!I,"aria-disabled":I?`true`:void 0,form:I?``:void 0,required:d,"aria-required":A?`true`:void 0,onChange:e=>{if(s||P)return;let t=e.target.checked;r?.(t,e),i&&!e.defaultPrevented&&j(async()=>{N(t),await i(t,e)})},onFocus:f,onBlur:p,"aria-describedby":z,"aria-invalid":y?.type===`error`||void 0,"aria-busy":P||void 0,...Sr(XP.input,GP[b],s&&XP.inputDisabled,P&&XP.inputBusy)}),(0,K.jsx)(`div`,{"aria-hidden":`true`,...oa(ba(`switch`,{checked:F?`checked`:null,disabled:s?`disabled`:null,size:b}),Sr(XP.track,KP[b],F?XP.trackOn:XP.trackOff,!s&&XP.trackFocus,s&&XP.trackDisabled,s&&!F&&XP.trackDisabledOff)),children:(0,K.jsx)(`div`,{...oa(ba(`switch-thumb`,{checked:F?`checked`:null,size:b}),Sr(XP.thumb,F?JP[b]:qP[b],F?XP.thumbOn:XP.thumbOff)),children:P&&(0,K.jsx)($o,{size:`sm`})})}),P&&(0,K.jsx)(es,{role:`status`,children:`Loading`})]}),V=(0,K.jsx)(`div`,{...Sr(XP.labelWrapper,YP[b]),children:(0,K.jsx)(TM,{...ba(`switch-label`),label:e,inputID:D,isLabelHidden:t,isDisabled:s,isOptional:u,isRequired:d,labelIcon:m,labelTooltip:h,description:n,descriptionID:O})});return(0,K.jsxs)(`div`,{...oa(ba(`switch-field`,{labelPosition:g===`end`?void 0:g,labelSpacing:v===`hug`?void 0:v}),Sr(x!=null&&ZP.width(x),S),C,w),...E,children:[(0,K.jsxs)(`div`,{ref:e=>{L.interactionRef(e)},...Sr(XP.container,t&&XP.containerLabelHidden,v===`spread`&&XP.containerSpread,!s&&UP),children:[` `,g===`start`?(0,K.jsxs)(K.Fragment,{children:[V,B]}):(0,K.jsxs)(K.Fragment,{children:[B,V]})]}),y?.message&&(0,K.jsx)(kM,{type:y.type,message:y.message,id:k,variant:`detached`,xstyle:XP.statusGap}),I&&L.renderTooltip(l)]})}QP.displayName=`Switch`;var $P=[`chrome`,`edge`,`brave`,`chromium`,`safari`,`firefox`],eF=[`embedded`,...$P],tF=e=>$P.some(t=>t===e);function nF(){let[e,t]=(0,_.useState)(),n=(0,_.useRef)(void 0),r=(0,_.useRef)(!1),i=(0,_.useRef)(!0),a=(0,_.useRef)(void 0),o=(0,_.useCallback)(()=>{a.current?.(),a.current=void 0,n.current?.close(),n.current=void 0,i.current&&t(void 0)},[]);return(0,_.useEffect)(()=>(i.current=!0,window.addEventListener(`pagehide`,o),()=>{i.current=!1,window.removeEventListener(`pagehide`,o),o()}),[o]),{container:e,open:async()=>{if(n.current&&!n.current.closed)return n.current.focus(),!0;if(r.current)return!1;r.current=!0;try{let e=window.documentPictureInPicture,r=e?await e.requestWindow({width:460,height:740}):window.open(`about:blank`,`_blank`,`popup,width=460,height=740`);if(!r)return!1;if(!i.current)return r.close(),!1;n.current=r,r.document.title=`OpenPI Browser Bridge`;let o=()=>{r.document.documentElement.lang=document.documentElement.lang,r.document.documentElement.dataset.theme=document.documentElement.dataset.theme,r.document.documentElement.style.cssText=document.documentElement.style.cssText};o(),r.document.documentElement.classList.add(`browser-guide-window`);for(let e of document.styleSheets)try{let t=r.document.createElement(`style`);t.textContent=[...e.cssRules].map(e=>e.cssText).join(` +`:``}${t(`fileAttachmentPromptLabel`)}\n${r}`,m.length>12e3){ie(t(`fileAttachmentPromptTooLong`));return}l.content=m}if(u=h?await n(m,s.images,i,a,h):a?await n(m,s.images,i,a):i?await n(m,s.images.length>0||r?s.images:void 0,i):r||s.images.length>0?await n(m,s.images):await n(m),u){a?.streamingBehavior===`steer`&&W(null),i===me.current&&(me.current=null);let e=o.clear(l.owner.key,l.revision);e&&c.current.key===l.owner.key&&(f.current=e,d(e),ie(null))}}catch(e){c.current.key===l.owner.key&&ie(e instanceof Error?e.message:t(`fileAttachmentReadFailed`))}finally{p&&c.current.key===l.owner.key&&!ge.current&&ne(!1),l.pending=!1;let e=o.read(l.owner.key);(u||!e.prompt&&e.images.length===0&&!e.files?.length)&&x.current.get(l.owner.key)===l&&x.current.delete(l.owner.key)}},Je=async n=>{if(n?.preventDefault(),!G||e.sessionSwitching||e.modelSelectionPending||e.planSelectionPending||e.thinkingPendingLevel!==null||e.promptAdmissionPending||e.promptAdmissionRecovery||e.promptAdmissionResolution||y||!p.trim()&&m.length===0&&h.length===0||ge.current)return;if(Ne&&(!je||Ae?.commandId!==Ne.expectedTurnCommandId||me.current)){U(t(`steerStaleTurn`));return}let r=/^\/([^\s/]+)/u.exec(p.trim())?.[1],i=Fe.commands.find(e=>e.name===r);if(i?.availability===`unsupported`){U(`/${i.name}: ${t(`commandUnavailable_${i.unavailableReason??`not_integrated`}`)}`);return}if(i?.action){if(p.trim()!==`/${i.name}`||m.length>0||h.length>0){U(t(`commandPanelArguments`));return}if(e.onCommandAction?.(i.action)!==!0){U(t(`commandPanelUnavailable`));return}xe({prompt:``,caret:0}),U(null);return}U(null),await qe(e.actions.sendPrompt,!1,me.current??void 0,Ne?{streamingBehavior:`steer`,expectedTurnCommandId:Ne.expectedTurnCommandId}:void 0)},Ye=()=>{if(!(!Ce||e.sessionSwitching||e.modelSelectionPending||e.thinkingPendingLevel!==null||y))return qe(e.actions.sendPromptAsNew,!0)},Xe=e=>{if(e.availability!==`available`)return;let t=`/${e.name} `;xe({prompt:t,caret:t.length})&&(U(null),O(!0),queueMicrotask(()=>{c.current.key===b&&(pe.current?.focus(),pe.current?.setSelectionRange(t.length,t.length))}))},Ze=e=>{if(!Ve.length)return;let t=A;for(let n=0;n{let n=ve.current,r=f.current;if(!n||n.ownerKey!==b||n.ownerKey!==c.current.key||n.revision!==r.revision)return t(`fileReferenceDraftChanged`);let i=r.prompt.slice(0,n.start),a=r.prompt.slice(n.end),o=YM(e),s=i&&!/\s$/u.test(i)?` `:``,l=`${i}${s}${o}${a&&!/^\s/u.test(a)?` `:``}${a}`,u=i.length+s.length+o.length;if(!xe({prompt:l,caret:u}))return t(`draftLimit`);_e.current=!0},et=()=>{let e=f.current,t=pe.current,n=Math.min(Math.max(t?.selectionStart??e.caret,0),e.prompt.length);ve.current={ownerKey:b,revision:e.revision,start:n,end:Math.min(Math.max(t?.selectionEnd??n,n),e.prompt.length)},N(!0)},tt=[...(e.snapshot?.workspaces??[]).map(t=>({id:t.path,label:t.name,icon:(0,K.jsx)(De,{}),endContent:t.path===e.selectedWorkspace?(0,K.jsx)(I,{}):void 0,onClick:()=>e.actions.setWorkspace(t.path)})),{type:`divider`},{id:`add`,label:t(`addWorkspaceMenu`),icon:(0,K.jsx)(lt,{}),onClick:()=>void e.actions.chooseWorkspace()}],nt=e.draftModel??e.snapshot?.models.find(e=>e.current),rt=e.snapshot?.workspaces.find(t=>t.path===e.selectedWorkspace)?.name??(e.selectedWorkspace?QA(e.selectedWorkspace):t(`selectWorkspace`)),it=e.snapshot?.sessions.find(e=>e.path===i),at=Ce?ZA(it??{},n?.id??t(`untitledSession`)):we?t(`newSession`):n?ZA(it??{},n.id):t(`newSession`),ot=e.sessionSwitching?t(`switchingSession`):e.selectedWorkspace?Ce&&e.snapshot?.runtime.planHasPrompt&&[`planning`,`ready`].includes(e.snapshot.runtime.plan??``)?t(`promptPlanMessage`):e.landing?t(`promptTask`):t(Te?`promptMessage`:`promptReadonly`):t(`promptStart`),st=e.snapshot?.thinking,ct=st?.level??null,ut=e.thinkingPendingLevel??null,dt=st?.supported??!1,ft=!!e.selectedWorkspace&&!Ce&&(we||!n),pt=st?!st.available.includes(ct??``):!1,mt=st?!dt&&!ft?`thinkingUnsupportedHint`:!Ce&&!ft?`thinkingInactiveHint`:Oe?`thinkingLockedRunning`:e.modelSelectionPending?`thinkingModelPendingHint`:null:null,ht=e.snapshot?.selectedExecution,gt=n&&ht&&ht.sessionId===n.id&&ht.sessionPath===n.path?ht.pendingFollowUps:void 0,_t=gt??(Ce?e.pendingFollowUpsReceipt:null),vt=n&&ht?.sessionId===n.id&&ht.sessionPath===n.path?ht.pendingSteering:void 0,yt=vt??(Ce?e.pendingSteeringReceipt:null),bt=vt===void 0?[]:ht?.steeringMessages??[],xt=!e.workspaceDraft&&!e.sessionSwitching&&bt.length>0,St=gt===void 0?[]:ht?.queuedMessages??[],Ct=new Map,wt=St.map(e=>{let t=Ct.get(e)??0;return Ct.set(e,t+1),{message:e,key:`${e}:${t}`}}),Tt=!e.workspaceDraft&&!e.sessionSwitching&>!==void 0&&St.length>0,Dt=Ee?t(`compactionDraftHelp`):e.promptAdmissionPending&&!ke?t(`promptPending`):e.modelSelectionPending?t(`thinkingModelPendingHint`):e.thinkingPendingLevel===null?e.workspaceDraft?t(`enterHint`):e.turnCancellationPending?t(`stoppingTurn`):e.turnTerminalStatus===`cancelled`?t(`stoppedTurn`):!xt&&(yt??0)>0?t(`pendingSteeringHint`,{count:yt}):!Tt&&(Ce&&e.pendingFollowUpsReceipt!==null||(_t??0)>0)?(_t??0)>0?t(`pendingFollowUpsHint`,{count:_t??0}):t(`acceptedHint`):t(G?Oe?Ne?`steeringHint`:`queuedHint`:`enterHint`:`activeOnlyHint`):t(`thinkingPendingHint`),kt=G&&(Ee||e.promptAdmissionPending&&!ke||e.modelSelectionPending||e.thinkingPendingLevel!==null||e.turnCancellationPending||e.turnTerminalStatus===`cancelled`||!Tt&&Ce&&e.pendingFollowUpsReceipt!==null||!Tt&&(_t??0)>0||!xt&&(yt??0)>0||Oe&&!!(p.trim()||m.length||h.length)),At=L===b,jt=(e=!1)=>{F(null),e&&H.current?.focus()},Mt=e=>()=>{F(null),e()},Nt=async r=>{if(!(!Ce||!n||At||e.sessionSwitching)){R(b);try{r===`compact`?await V.compactSession(n.id,n.path):await V.updatePromptQueue(n.id,n.path,r),await e.actions.refreshSnapshot()}catch(e){c.current.key===b&&U(e instanceof Error?e.message:t(`commandPanelUnavailable`))}finally{R(e=>e===b?null:e)}}},Pt=P===`files`?[{id:`back`,section:t(`composerAdd`),label:t(`composerBack`),icon:(0,K.jsx)(de,{}),onClick:()=>F(`main`)},{id:`file-upload`,section:t(`composerAdd`),label:t(`addFiles`),description:t(`fileAttachmentDescription`),icon:(0,K.jsx)(Se,{}),disabled:te||m.length+h.length>=8,onClick:Mt(()=>{he.current&&(he.current.accept=``,he.current.click())})},{id:`image`,section:t(`composerAdd`),label:t(`addImages`),description:t(`imageAttachmentDescription`),icon:(0,K.jsx)(Me,{}),disabled:te||m.length>=8,onClick:Mt(()=>{he.current&&(he.current.accept=`image/png,image/jpeg,image/gif,image/webp`,he.current.click())})},{id:`workspace-file`,section:t(`composerAdd`),label:t(`fileReference`),icon:(0,K.jsx)(Se,{}),onClick:Mt(et)}]:[{id:`file`,section:t(`composerAdd`),label:t(`composerFile`),alias:`file`,icon:(0,K.jsx)(Se,{}),onClick:()=>F(`files`)},{id:`goal`,section:t(`composerAdd`),label:t(`composerGoal`),alias:`goal`,description:t(`composerGoalDescription`),icon:(0,K.jsx)(Ot,{}),disabled:!Ue,onClick:Mt(()=>{xe({prompt:`/goal `,caret:6})&&(O(!0),queueMicrotask(()=>pe.current?.focus()))})},{id:`plan`,section:t(`composerAdd`),label:t(`composerPlan`),alias:`plan`,description:t(`composerPlanDescription`),icon:(0,K.jsx)(ze,{}),disabled:!Ce||Oe||e.planSelectionPending||e.promptAdmissionPending,onClick:Mt(()=>void e.actions.selectPlanMode(e.snapshot?.runtime.plan===`inactive`))},{id:`compact`,section:t(`composerCommands`),label:t(`composerCompact`),alias:`compact`,description:t(`composerCompactDescription`),icon:(0,K.jsx)(Qe,{}),disabled:!Ce||Oe||At||e.promptAdmissionPending||(_t??0)>0,onClick:Mt(()=>void Nt(`compact`))},{id:`model`,section:t(`composerCommands`),label:t(`composerModel`),alias:`model`,description:t(`composerModelDescription`),icon:(0,K.jsx)(fe,{}),disabled:!Ce&&!we||Oe||e.modelSelectionPending,onClick:Mt(()=>B(e=>e+1))}];return(0,K.jsxs)(`div`,{className:`composer-dock`,children:[Ce&&e.snapshot?.runtime.plan===`ready`&&!e.sessionSwitching&&(0,K.jsx)(`div`,{className:`plan-mode-bar`,children:(0,K.jsx)(`button`,{type:`button`,disabled:Oe||te||!!ge.current||e.planSelectionPending||e.promptAdmissionPending||!!e.promptAdmissionRecovery,onClick:()=>{if((p.trim()||m.length>0||h.length>0)&&!window.confirm(t(`planImplementationReplaceDraft`)))return;let n=f.current.revision,r=c.current.key;e.actions.preparePlanImplementation().then(e=>{!e||f.current.revision!==n||c.current.key!==r||xe({prompt:e.prompt,images:[],caret:e.prompt.length},r)&&(me.current={sessionId:e.sessionId,sessionPath:e.sessionPath,planRevision:e.planRevision},ie(null),pe.current?.focus())})},children:t(`planModeImplement`)})}),!Ce&&!e.workspaceDraft&&!e.sessionSwitching&&n&&r===n.path&&(0,K.jsxs)(`div`,{className:`composer-session-notice`,children:[(0,K.jsx)(`span`,{children:t(`activateViewedSessionHint`)}),(0,K.jsx)(`button`,{type:`button`,className:`secondary`,onClick:()=>void e.actions.selectSession(n.path),children:t(`activateViewedSession`)})]}),Ce&&(0,K.jsx)(lj,{snapshot:e.snapshot,observed:e.activityObserved,onInspectTerminal:e.onInspect,onInspectSubagent:e.onInspectSubagent}),e.accessory,e.landing&&(0,K.jsx)(`div`,{className:`workspace-picker-row`,children:(0,K.jsx)(jA,{className:`workspace-picker-menu`,button:{label:e.selectedWorkspace?QA(e.selectedWorkspace):t(`selectWorkspace`),icon:(0,K.jsx)(De,{}),size:`md`,variant:`ghost`,className:`workspace-picker`},items:tt,menuWidth:240,placement:`above`,alignment:`start`,hasChevron:!0})}),e.promptAdmissionRecovery&&(0,K.jsxs)(`section`,{className:`prompt-recovery`,role:`alert`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`strong`,{children:t(`promptAdmissionUnknown`)}),(0,K.jsx)(`span`,{children:e.promptAdmissionRecovery.phase===`checking`?t(`promptAdmissionCheckingDetail`):e.promptAdmissionRecovery.phase===`verification-failed`?t(`promptAdmissionVerificationFailedDetail`):t(`promptAdmissionUnknownDetail`)})]}),(0,K.jsxs)(`div`,{className:`prompt-recovery-actions`,children:[(0,K.jsx)(`button`,{type:`button`,disabled:e.promptAdmissionRecovery.phase===`submitting`,onClick:e.actions.abandonPromptAdmission,children:t(`abandonAdmission`)}),e.promptAdmissionRecovery.phase===`verification-failed`&&(0,K.jsx)(`button`,{type:`button`,onClick:()=>void e.actions.checkPromptAdmissionRecovery(),children:t(`retryAdmissionCheck`)}),e.promptAdmissionRecovery.retryable&&(0,K.jsx)(`button`,{type:`button`,disabled:!Ce||e.sessionSwitching||e.modelSelectionPending||e.thinkingPendingLevel!==null||e.promptAdmissionRecovery.phase!==`ready`,onClick:()=>void e.actions.retryPromptAdmission(),children:t(`retryOriginalAdmission`)}),(0,K.jsx)(`button`,{type:`button`,className:`primary`,disabled:te||!Ce||e.sessionSwitching||e.modelSelectionPending||e.thinkingPendingLevel!==null||y||e.promptAdmissionRecovery.phase!==`ready`||!p.trim()&&m.length===0&&h.length===0,onClick:()=>void Ye(),children:e.promptAdmissionRecovery.phase===`submitting`?t(`sendingAsNew`):t(`sendAsNew`)})]})]}),Tt&&(0,K.jsxs)(`section`,{className:`composer-queue`,"aria-label":t(`pendingFollowUpsHint`,{count:gt}),children:[(0,K.jsxs)(`div`,{className:`composer-queue-status`,role:`status`,children:[(0,K.jsx)(`span`,{children:t(ht?.promptQueueBlocked?`compactionQueueBlocked`:Ee?`compactionQueueWaiting`:`queuedHint`)}),Ce&&(0,K.jsxs)(`span`,{children:[ht?.promptQueueBlocked&&(0,K.jsx)(`button`,{type:`button`,disabled:At||Ee,onClick:()=>void Nt(`retry`),children:t(`retryPrompt`)}),(0,K.jsx)(`button`,{type:`button`,disabled:At,onClick:()=>void Nt(`clear`),children:t(`clearPromptQueue`)})]})]}),(0,K.jsx)(`ul`,{children:wt.map(({message:e,key:r})=>{let i=`${n?.id}\0${n?.path}\0${r}`,a=ce===i,o=e||t(`queuedImage`),s=t(a?`queuedMessageCollapse`:`queuedMessageExpand`);return(0,K.jsx)(`li`,{children:(0,K.jsxs)(`button`,{type:`button`,className:`composer-queue-row ${a?`expanded`:``}`,"aria-expanded":a,"aria-label":`${s}: ${a?o:ej(o,80)}`,title:s,onClick:()=>le(a?null:i),children:[(0,K.jsx)(de,{"aria-hidden":`true`}),(0,K.jsx)(`span`,{children:o})]})},r)})}),gt>St.length&&(0,K.jsx)(`small`,{children:t(`queuedMore`,{count:gt-St.length})})]}),xt&&(0,K.jsxs)(`section`,{className:`composer-queue`,"aria-label":t(`steeringMessagesTitle`),children:[(0,K.jsxs)(`div`,{className:`composer-queue-status`,role:`status`,children:[(0,K.jsx)(`span`,{children:t(`pendingSteeringHint`,{count:yt})}),Ce&&(0,K.jsx)(`button`,{type:`button`,disabled:At,onClick:()=>void Nt(`clear`),children:t(`clearPromptQueue`)})]}),(0,K.jsx)(`ul`,{children:bt.map((e,r)=>{let i=`${n?.id}\0${n?.path}\0steer:${r}:${e}`,a=ce===i,o=e||t(`queuedImage`),s=t(a?`queuedMessageCollapse`:`queuedMessageExpand`);return(0,K.jsx)(`li`,{children:(0,K.jsxs)(`button`,{type:`button`,className:`composer-queue-row ${a?`expanded`:``}`,"aria-expanded":a,"aria-label":`${s}: ${a?o:ej(o,80)}`,title:s,onClick:()=>le(a?null:i),children:[(0,K.jsx)(de,{"aria-hidden":`true`}),(0,K.jsx)(`span`,{children:o})]})},i)})}),(yt??0)>bt.length&&(0,K.jsx)(`small`,{children:t(`queuedMore`,{count:(yt??0)-bt.length})})]}),(0,K.jsxs)(`form`,{className:`composer composer-m02 ${e.selectedWorkspace?``:`dormant`} ${oe?`is-dragging`:``}`,onSubmit:e=>void Je(e),onDragEnter:e=>{e.dataTransfer.types.includes(`Files`)&&(e.preventDefault(),We&&se(!0))},onDragOver:e=>{e.dataTransfer.types.includes(`Files`)&&(e.preventDefault(),We&&(e.dataTransfer.dropEffect=`copy`,se(!0)))},onDragLeave:e=>{let t=e.relatedTarget;t instanceof Node&&e.currentTarget.contains(t)||se(!1)},onDrop:e=>{se(!1),e.dataTransfer.files.length!==0&&(e.preventDefault(),We&&Ke(e.dataTransfer.files))},children:[P&&(0,K.jsx)(ZM,{items:Pt,onClose:jt},P),!e.selectedWorkspace&&(0,K.jsxs)(`div`,{className:`composer-dormant-cta`,"aria-hidden":`true`,children:[(0,K.jsx)(De,{}),(0,K.jsx)(`span`,{children:ot})]}),!e.selectedWorkspace&&(0,K.jsx)(`button`,{className:`dormant-overlay`,type:`button`,"aria-label":t(`selectWorkspace`),onClick:()=>void e.actions.chooseWorkspace()}),(0,K.jsx)(`input`,{ref:he,className:`sr-only`,type:`file`,multiple:!0,tabIndex:-1,"aria-hidden":`true`,onChange:e=>{e.currentTarget.files&&Ke(e.currentTarget.files)}}),(0,K.jsx)(iM,{ownerKey:b,images:m,onRemove:e=>{xe({images:f.current.images.filter(t=>t.id!==e)})&&ie(null)}}),(0,K.jsx)(aM,{ownerKey:b,files:h,onRemove:e=>{xe({files:(f.current.files??[]).filter(t=>t.id!==e)})&&ie(null)}}),re&&(0,K.jsx)(`p`,{className:`composer-attachment-error`,role:`alert`,children:re}),s.status===`failed`&&(0,K.jsxs)(`p`,{className:`composer-attachment-error`,role:`status`,children:[t(`draftStorageUnavailable`),` `,(0,K.jsx)(`button`,{type:`button`,onClick:()=>{o.retryStorage().then(()=>{let e=o.read(c.current.key);f.current=e,C.current=!0,d(e)})},children:t(`draftStorageRetry`)})]}),s.invalid&&(0,K.jsx)(`p`,{className:`composer-attachment-error`,role:`status`,children:t(`draftStorageInvalid`)}),te&&(0,K.jsx)(`p`,{role:`status`,children:t(`imageAttachmentsLoading`)}),ae&&(0,K.jsx)(`p`,{className:`composer-attachment-error`,role:`alert`,children:ae}),y&&(0,K.jsx)(`p`,{id:`composer-prompt-length-error`,className:`composer-attachment-error`,role:`alert`,children:t(`promptTooLong`,{count:v,limit:12e3})}),oe&&(0,K.jsxs)(`div`,{className:`composer-drop-overlay`,"aria-hidden":`true`,children:[(0,K.jsx)(Me,{}),(0,K.jsx)(`span`,{children:t(`dropImagesHere`)})]}),(0,K.jsx)(`textarea`,{ref:pe,value:p,rows:1,disabled:Pe,readOnly:!e.selectedWorkspace,"aria-label":t(`describeTask`),"aria-invalid":y||void 0,"aria-describedby":y?`composer-prompt-length-error`:void 0,"aria-autocomplete":`list`,"aria-controls":He?jN:void 0,"aria-activedescendant":He&&Ve[A]?MN(A):void 0,placeholder:ot,onChange:e=>{xe({prompt:e.target.value,caret:e.target.selectionStart})&&(U(null),O(!1))},onClick:e=>xe({caret:e.currentTarget.selectionStart}),onSelect:e=>xe({caret:e.currentTarget.selectionStart}),onFocus:()=>{E(!0),O(!1)},onBlur:()=>E(!1),onPaste:e=>{if(!We)return;let t=Array.from(e.clipboardData.files);if(t.length===0)for(let n of Array.from(e.clipboardData.items??[])){let e=n.kind===`file`?n.getAsFile():null;e&&t.push(e)}t.length!==0&&(e.clipboardData.getData(`text/plain`)||e.preventDefault(),Ke(t))},onKeyDown:e=>{if(!e.nativeEvent.isComposing){if(Le){if(e.key===`ArrowDown`||e.key===`ArrowUp`){e.preventDefault(),Ze(e.key===`ArrowDown`?1:-1);return}if(e.key===`Escape`){e.preventDefault(),O(!0);return}if(e.key===`Tab`){let t=Ve[A];!e.shiftKey&&!e.ctrlKey&&!e.altKey&&!e.metaKey&&t?.availability===`available`&&(e.preventDefault(),Xe(t));return}if(e.key===`Enter`&&!e.shiftKey){let t=Ve[A];if(t){e.preventDefault(),Xe(t);return}if(Ve.length>0){e.preventDefault();return}}}e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),Je())}}}),Le&&(0,K.jsx)(FN,{activeIndex:A,commandDiscovery:Fe,commands:Ve,draft:!!e.workspaceDraft,preferBelow:e.landing,onComplete:Xe,onSelect:j}),(0,K.jsxs)(`div`,{className:`composer-toolbar`,children:[(0,K.jsxs)(`div`,{className:`composer-toolbar-context`,children:[We&&(0,K.jsx)(`button`,{ref:H,type:`button`,className:`composer-context-trigger icon-button`,"aria-label":t(`addContext`),"aria-haspopup":`menu`,"aria-expanded":P!==null,"aria-controls":P?`composer-action-menu`:void 0,onClick:()=>{O(!0),F(P?null:`main`)},children:(0,K.jsx)(lt,{})}),!e.landing&&(0,K.jsxs)(`span`,{className:`composer-workspace-label`,title:`${rt} / ${at}`,children:[(0,K.jsx)(De,{}),rt]}),Ce&&e.snapshot?.runtime.plan&&e.snapshot.runtime.plan!==`inactive`&&(0,K.jsx)(`span`,{className:`composer-plan-chip`,children:t(`planMode_${e.snapshot.runtime.plan}`)})]}),(0,K.jsxs)(`div`,{className:`composer-toolbar-controls`,children:[(je||Ne)&&(0,K.jsx)(jA,{button:{label:t(Ne?`steerCurrentTurn`:`sendNextTurn`),variant:`ghost`,size:`sm`,isDisabled:e.promptAdmissionPending||!!e.promptAdmissionRecovery},items:[{id:`followUp`,label:t(`sendNextTurn`),onClick:()=>{W(null),U(null)}},{id:`steer`,label:t(`steerCurrentTurn`),isDisabled:!je,onClick:()=>{!je||!Ae||(W({ownerKey:b,expectedTurnCommandId:Ae.commandId}),U(null))}}],placement:`above`,alignment:`end`,hasChevron:!0}),(0,K.jsx)(`div`,{className:`model-picker-wrap`,hidden:!!(n&&!Ce&&!e.workspaceDraft),title:mt?t(mt):void 0,"data-level":ct??`none`,"data-pending":ut!==null,"data-warning":pt,children:(0,K.jsx)(AN,{snapshot:e.snapshot,openRequest:z,currentModel:nt,draftModel:e.draftModel,modelSearch:w,modelSelectionPending:!!e.modelSelectionPending,promptAdmissionPending:e.promptAdmissionPending,sessionSwitching:e.sessionSwitching,liveRunning:Oe,workspaceDraft:!!e.workspaceDraft,thinkingPendingLevel:ut,thinkingNeedsSession:ft,thinkingDisabledReason:mt,onOpenProviders:e.onOpenProviders,actions:e.actions})}),ke&&(0,K.jsx)(Cd,{content:t(`stopTurn`),placement:`above`,children:(0,K.jsx)(`button`,{className:`send-button`,type:`button`,"aria-label":t(`stopTurn`),disabled:e.turnCancellationPending||e.sessionSwitching,onClick:()=>void e.actions.cancelActiveTurn(),children:(0,K.jsx)(Et,{})})}),(!ke||!!(p.trim()||m.length||h.length))&&(0,K.jsx)(Cd,{content:t(Ee?`compactionDraftHelp`:`send`),placement:`above`,children:(0,K.jsx)(`button`,{className:`send-button`,type:`submit`,"aria-label":t(`send`),disabled:te||e.sessionSwitching||e.modelSelectionPending||e.thinkingPendingLevel!==null||!G||!e.selectedWorkspace||e.promptAdmissionPending||y||e.planSelectionPending||!!e.promptAdmissionRecovery||!!e.promptAdmissionResolution||!p.trim()&&m.length===0&&h.length===0,children:(0,K.jsx)(k,{})})})]})]}),(0,K.jsx)(`div`,{className:`composer-hint`,"data-visible":kt,"aria-live":`polite`,children:G?Dt:null})]}),(0,K.jsx)(JM,{open:M,sessionId:Ce?n?.id:void 0,onClose:()=>N(!1),onInsert:$e})]})}function zN({target:e,onClose:t,onOpenProviders:n}){let{t:r}=cr(),i=(0,_.useMemo)(()=>new rf,[]),[a,o]=(0,_.useState)(0),[s,c]=(0,_.useState)(null),[l,u]=(0,_.useState)(null),[d,f]=(0,_.useState)(null),p=e=>{f(null),wd(e).then(e=>f(e?`copied`:`failed`))};(0,_.useEffect)(()=>{let t=new AbortController;return c(null),u(null),f(null),(async()=>{let n={errors:[]};if(e.terminalId)try{let a=await i.terminalDetail(e.sessionId,e.terminalId,t.signal);if(a.sessionId!==e.sessionId||a.detail.id!==e.terminalId)throw Error(r(`inspectionChanged`));n.terminal=a.detail}catch(e){n.errors.push(e instanceof Error?e.message:r(`inspectionUnavailable`))}else{let[a,o]=await Promise.allSettled([i.thinking(e.sessionId,t.signal),i.trust(e.sessionId,t.signal)]);a.status===`fulfilled`&&a.value.sessionId===e.sessionId?n.thinking=a.value:n.errors.push(r(`thinkingUnavailable`)),o.status===`fulfilled`&&(o.value.workspace===void 0||o.value.workspace===e.cwd)?n.trust=o.value:n.errors.push(r(`trustUnavailable`))}t.signal.aborted||(c(n),u(new Date().toLocaleTimeString()))})(),()=>t.abort()},[i,e,a,r]);let m=e.terminalId?r(`terminalDetails`):r(`runtimeStatus`),h=s?.terminal;return(0,K.jsx)($j,{isOpen:!0,onOpenChange:e=>!e&&t(),width:640,"aria-label":m,children:(0,K.jsxs)(`section`,{className:`inspection-panel`,children:[(0,K.jsxs)(`header`,{className:`inspection-heading`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`h2`,{children:m}),(0,K.jsx)(`p`,{className:`inspection-subtitle`,children:e.cwd})]}),(0,K.jsxs)(`div`,{className:`inspection-actions`,children:[(0,K.jsx)(`button`,{type:`button`,className:`icon-button`,"aria-label":r(`refreshStatus`),disabled:!s,onClick:()=>o(e=>e+1),children:(0,K.jsx)(dt,{})}),(0,K.jsx)(`button`,{type:`button`,className:`icon-button`,"aria-label":r(`close`),onClick:t,children:(0,K.jsx)(Lt,{})})]})]}),d&&(0,K.jsx)(`p`,{role:`status`,children:r(d===`copied`?`copiedMessage`:`copyFailed`)}),s?(0,K.jsxs)(K.Fragment,{children:[s.errors.map(e=>(0,K.jsx)(`p`,{className:`inspection-warning`,role:`alert`,children:e},e)),h?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsxs)(`div`,{className:`inspection-section`,children:[(0,K.jsx)(`h3`,{children:h.title||h.id}),(0,K.jsxs)(`dl`,{children:[(0,K.jsx)(`dt`,{children:r(`executionState`)}),(0,K.jsx)(`dd`,{children:r(`execution_${h.status}`,{defaultValue:h.status})}),(0,K.jsx)(`dt`,{children:r(`terminalCommand`)}),(0,K.jsxs)(`dd`,{children:[(0,K.jsx)(`code`,{children:h.command}),(0,K.jsx)(`button`,{type:`button`,className:`inspection-copy`,"aria-label":r(`copyTerminalCommand`),title:r(`copyTerminalCommand`),onClick:()=>p(h.command),children:(0,K.jsx)(oe,{"aria-hidden":`true`})})]}),(0,K.jsx)(`dt`,{children:r(`terminalDirectory`)}),(0,K.jsx)(`dd`,{children:h.cwd}),(0,K.jsx)(`dt`,{children:r(`startedAt`)}),(0,K.jsx)(`dd`,{children:new Date(h.createdAt).toLocaleString()}),h.status!==`running`&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`dt`,{children:r(`exitCode`)}),(0,K.jsx)(`dd`,{children:h.exitCode??r(`unknownState`)})]})]}),h.errorText&&(0,K.jsx)(`p`,{className:`inspection-warning`,children:h.errorText}),h.truncated&&(0,K.jsx)(`p`,{className:`inspection-note`,children:r(`detailTruncated`)})]}),[`stdout`,`stderr`].map(e=>(0,K.jsxs)(`section`,{className:`inspection-section`,children:[(0,K.jsxs)(`div`,{className:`inspection-stream-heading`,children:[(0,K.jsx)(`h3`,{children:r(e===`stdout`?`standardOutput`:`standardError`)}),(0,K.jsx)(`button`,{type:`button`,className:`inspection-copy`,disabled:!h[e].text,"aria-label":r(`copyVisibleOutput`,{stream:r(e===`stdout`?`standardOutput`:`standardError`)}),title:r(`copyVisibleOutput`,{stream:r(e===`stdout`?`standardOutput`:`standardError`)}),onClick:()=>p(h[e].text),children:(0,K.jsx)(oe,{"aria-hidden":`true`})})]}),(0,K.jsx)(`section`,{className:`terminal-evidence`,tabIndex:0,"aria-label":r(e===`stdout`?`standardOutput`:`standardError`),children:(0,K.jsx)(`pre`,{children:h[e].text||r(`noOutput`)})}),h[e].truncated&&(0,K.jsx)(`p`,{className:`inspection-note`,children:r(`outputTruncated`,{count:h[e].omittedBytes})}),h[e].recoveryAvailable&&(0,K.jsx)(`p`,{className:`inspection-note`,children:r(`outputRecovery`)})]},e))]}):!e.terminalId&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsxs)(`section`,{className:`inspection-section`,children:[(0,K.jsx)(`h3`,{children:r(`modelAndThinking`)}),(0,K.jsxs)(`dl`,{children:[(0,K.jsx)(`dt`,{children:r(`selectedModel`)}),(0,K.jsx)(`dd`,{children:e.model||r(`noModels`)}),(0,K.jsx)(`dt`,{children:r(`thinkingLevel`)}),(0,K.jsx)(`dd`,{children:s.thinking?.supported===!1?r(`thinkingUnsupported`):s.thinking?.level??r(`unknownState`)}),!!s.thinking?.available.length&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`dt`,{children:r(`availableThinking`)}),(0,K.jsx)(`dd`,{children:s.thinking?.available.join(` · `)})]})]}),s.thinking?.supported===!1&&(0,K.jsx)(`p`,{className:`inspection-note`,children:r(`thinkingUnsupportedHint`)}),s.thinking&&s.thinking.supported!==!1&&!s.thinking.available.includes(s.thinking.level)&&(0,K.jsx)(`p`,{className:`inspection-warning`,role:`status`,children:r(`thinkingLevelMismatch`)})]}),(0,K.jsxs)(`section`,{className:`inspection-section`,children:[(0,K.jsx)(`h3`,{children:r(`projectTrust`)}),(0,K.jsx)(`p`,{children:r(`trust_${s.trust?.state??`unknown`}`)}),(0,K.jsxs)(`dl`,{children:[(0,K.jsx)(`dt`,{children:r(`savedTrustDecision`)}),(0,K.jsx)(`dd`,{children:r(`trustDecision_${s.trust?.decision??`unknown`}`)}),(0,K.jsx)(`dt`,{children:r(`activeSessionTrust`)}),(0,K.jsx)(`dd`,{children:s.trust?.sessionTrusted===!0?r(`trustActiveYes`):s.trust?.sessionTrusted===!1?r(`trustActiveNo`):r(`unknownState`)})]}),s.trust?.refreshRequired===!0&&(0,K.jsx)(`p`,{className:`inspection-warning`,children:r(`trustRefreshNeeded`)})]}),n&&(0,K.jsxs)(`button`,{type:`button`,className:`inspection-provider-link`,"aria-label":r(`openProviderSettings`),onClick:n,children:[(0,K.jsxs)(`span`,{children:[(0,K.jsx)(`strong`,{children:r(`providerAvailability`)}),(0,K.jsx)(`small`,{children:r(`authNotVerified`)})]}),r(`openProviderSettings`)]}),(0,K.jsxs)(`div`,{className:`inspection-setup`,children:[(0,K.jsx)(`p`,{className:`inspection-note`,children:r(`configurationViaPi`)}),(0,K.jsx)(`code`,{children:`/openpi-setup`}),(0,K.jsx)(`button`,{type:`button`,className:`inspection-copy`,"aria-label":r(`copySetupCommand`),title:r(`copySetupCommand`),onClick:()=>p(`/openpi-setup`),children:(0,K.jsx)(oe,{"aria-hidden":`true`})})]})]}),(0,K.jsx)(`p`,{className:`inspection-updated`,children:r(`statusCaptured`,{time:l})})]}):(0,K.jsx)(`p`,{role:`status`,children:r(`inspectionLoading`)})]})})}var BN=32,VN=1048576;function HN(e){return e.drafts.reduce((e,t)=>e+Od(t.custom)+Object.values(t.notes).reduce((e,t)=>e+Od(t),0),0)}function UN(e,t,n){if(!(n.submission||n.drafts.some(e=>e.choice!==null||e.custom||Object.values(e.notes).some(Boolean))))return e.delete(t),!0;let r=e.get(t);if(!r&&e.size>=BN)return!1;let i=r?HN(r):0,a=HN(n),o=Array.from(e.values()).reduce((e,t)=>e+HN(t),0);return a>i&&o-i+a>VN?!1:(e.set(t,n),!0)}function WN(e,t,n,r){for(let[i,a]of e)a.sessionId===t&&a.sessionPath===n&&a.requestId!==r&&e.delete(i)}function GN({request:e,answer:t,onSettled:n,connected:r=!0,sessionPath:i=``,workingCache:a}){let{t:o}=cr(),s=(0,_.useId)(),c=(0,_.useMemo)(()=>new Map,[]),l=a??c,u=JSON.stringify([e.sessionId,i,e.requestId]),[d,f]=(0,_.useState)(()=>l.get(u)??{sessionId:e.sessionId,sessionPath:i,requestId:e.requestId,drafts:e.questions.map(()=>({choice:null,custom:``,notes:{}})),index:0,review:!1,submission:null}),p=(0,_.useRef)(d),{drafts:m,index:h,review:g,submission:v}=d,[y,b]=(0,_.useState)(!!d.submission),[x,S]=(0,_.useState)(!1),[C,w]=(0,_.useState)(!1),D=(0,_.useRef)(!1),O=!!v,k=(0,_.useRef)(null),A=(0,_.useRef)(null),j=e.questions[h],M=m[h],N=C||O||!r,P=m.some(e=>e.choice===`custom`?!kd(e.custom):typeof e.choice==`number`&&!kd(e.notes[e.choice]??``)),F=m.every(e=>e.choice!==null)&&!P,L=(t,n)=>e.handoff?o(n===0?`handoffDone`:`handoffUnable`):t;(0,_.useEffect)(()=>()=>k.current?.abort(),[]);let R=e=>UN(l,u,e)?(p.current=e,f(e),S(!1),!0):(S(!0),!1),z=(e,t=!1)=>{R({...p.current,index:e,review:t}),requestAnimationFrame(()=>A.current?.focus())},B=e=>{let t=p.current;R({...t,drafts:t.drafts.map((n,r)=>r===t.index?{...n,...e}:n)})},V=()=>e.questions.map((e,t)=>{let n=m[t];if(n.choice===`custom`)return n.custom.trim()?{id:e.id,custom:n.custom}:{id:e.id,rephrase:!0};let r=typeof n.choice==`number`?e.options[n.choice]?.label:void 0;return{id:e.id,selected:r,...typeof n.choice==`number`&&n.notes[n.choice]?.trim()?{note:n.notes[n.choice]}:{}}}),H=async(i=!1)=>{if(D.current||!r||!i&&!O&&!F)return;let a=p.current.submission??{answers:i?null:V()};if(!R({...p.current,submission:a}))return;D.current=!0,w(!0),b(!1);let o=new AbortController;k.current=o;try{let r=await t(e,a.answers,o.signal);o.signal.aborted||(l.delete(u),n(r))}catch{o.signal.aborted||b(!0)}finally{o.signal.aborted||(D.current=!1,w(!1))}};return(0,K.jsxs)(`section`,{className:`question-card`,"aria-labelledby":`${s}-title`,"aria-busy":C,children:[(0,K.jsxs)(`header`,{className:`question-card-header`,children:[(0,K.jsxs)(`span`,{className:`question-eyebrow`,children:[(0,K.jsx)(Je,{"aria-hidden":`true`}),o(e.handoff?`handoffWaiting`:`questionWaiting`)]}),(0,K.jsx)(`span`,{className:`question-count`,children:g?o(e.handoff?`handoffReview`:`questionReview`):o(`questionProgress`,{current:h+1,total:e.questions.length})}),(0,K.jsx)(`button`,{type:`button`,className:`question-icon`,"aria-label":o(`questionDismiss`),title:o(`questionDismiss`),disabled:N,onClick:()=>void H(!0),children:(0,K.jsx)(Lt,{})})]}),(0,K.jsxs)(`div`,{className:`question-card-body`,children:[(0,K.jsx)(`h2`,{id:`${s}-title`,ref:A,tabIndex:-1,children:g?o(`questionReviewTitle`):j.question}),e.handoff&&(0,K.jsxs)(`div`,{className:`handoff-instructions`,children:[(0,K.jsx)(`p`,{children:e.handoff.instructions}),(0,K.jsxs)(`p`,{className:`question-help`,children:[o(`handoffSignal`),` `,e.handoff.completionSignal]}),(0,K.jsx)(`p`,{className:`question-help`,children:o(`handoffVerify`)})]}),g?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`p`,{className:`question-help`,children:o(`questionReviewHelp`)}),(0,K.jsx)(`ol`,{className:`question-review-list`,children:e.questions.map((e,t)=>{let n=m[t];return(0,K.jsxs)(`li`,{children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`span`,{className:`question-review-label`,children:e.header}),(0,K.jsx)(`p`,{children:typeof n.choice==`number`?L(e.options[n.choice]?.label,n.choice):n.custom.trim()||o(`questionRephrase`)}),typeof n.choice==`number`&&n.notes[n.choice]?.trim()&&(0,K.jsx)(`p`,{className:`question-help`,children:n.notes[n.choice]})]}),(0,K.jsx)(`button`,{type:`button`,className:`question-icon`,"aria-label":o(`questionEdit`,{question:e.header}),disabled:N,onClick:()=>z(t),children:(0,K.jsx)(at,{})})]},e.id)})})]}):(0,K.jsxs)(K.Fragment,{children:[(0,K.jsxs)(`fieldset`,{disabled:N,className:`question-choices`,children:[(0,K.jsx)(`legend`,{className:`sr-only`,children:j.header}),j.options.map((t,n)=>(0,K.jsxs)(`label`,{className:`question-choice ${M.choice===n?`is-selected`:``}`,children:[(0,K.jsx)(`input`,{className:`question-radio`,type:`radio`,name:`${s}-${j.id}`,checked:M.choice===n,onChange:()=>B({choice:n})}),(0,K.jsx)(`span`,{className:`question-choice-number`,"aria-hidden":`true`,children:n+1}),(0,K.jsxs)(`span`,{className:`question-choice-copy`,children:[(0,K.jsx)(`strong`,{children:L(t.label,n)}),(0,K.jsx)(`span`,{children:e.handoff?o(n===0?`handoffDoneHelp`:`handoffUnableHelp`):t.description})]})]},t.label))]}),typeof M.choice==`number`&&(0,K.jsxs)(`div`,{className:`question-extras`,children:[(0,K.jsxs)(`button`,{type:`button`,className:`question-note-toggle`,disabled:N,"aria-expanded":!!M.notesExpanded,"aria-controls":M.notesExpanded?`${s}-notes`:void 0,onClick:()=>B({notesExpanded:!M.notesExpanded}),children:[(0,K.jsx)(at,{"aria-hidden":`true`}),o(`questionNotes`)]}),typeof M.choice==`number`&&j.options[M.choice]?.preview&&(0,K.jsxs)(`details`,{className:`question-preview-disclosure`,children:[(0,K.jsx)(`summary`,{children:o(`questionPreview`)}),(0,K.jsx)(`pre`,{className:`question-preview`,children:j.options[M.choice].preview})]},`${j.id}-${M.choice}`)]}),(M.choice===`custom`||typeof M.choice==`number`&&M.notesExpanded)&&(0,K.jsxs)(`label`,{className:`question-notes`,id:`${s}-notes`,children:[(0,K.jsx)(`span`,{className:`sr-only`,id:`${s}-answer-label`,children:M.choice===`custom`?o(`questionYourAnswer`):o(`questionNotes`)}),(0,K.jsx)(`textarea`,{rows:1,disabled:N,value:M.choice===`custom`?M.custom:M.notes[M.choice]??``,onChange:e=>M.choice===`custom`?B({custom:e.target.value}):typeof M.choice==`number`&&B({notes:{...M.notes,[M.choice]:e.target.value}}),"aria-invalid":P,"aria-labelledby":`${s}-answer-label`,"aria-describedby":[P?`${s}-limit`:``,M.choice===`custom`?`${s}-custom-help`:``].filter(Boolean).join(` `)||void 0,placeholder:M.choice===`custom`?o(`questionCustomPlaceholder`):o(`questionNotesPlaceholder`)}),M.choice===`custom`&&(0,K.jsx)(`span`,{className:`question-help`,id:`${s}-custom-help`,children:o(`questionCustomHelp`)})]})]}),P&&(0,K.jsx)(`p`,{className:`question-error`,id:`${s}-limit`,role:`alert`,children:o(`questionLimit`,{count:8e3})}),x&&(0,K.jsx)(`p`,{className:`question-error`,role:`alert`,children:o(`questionDraftLimit`)}),!r&&(0,K.jsx)(`p`,{className:`question-help`,role:`status`,children:o(`questionDisconnected`)}),y&&(0,K.jsx)(`p`,{className:`question-error`,role:`alert`,children:o(`questionUncertain`)})]}),(0,K.jsxs)(`footer`,{className:`question-card-footer`,children:[!g&&!e.handoff&&(0,K.jsxs)(`label`,{className:`question-custom ${M.choice===`custom`?`is-selected`:``} ${N?`is-disabled`:``}`,children:[(0,K.jsx)(`input`,{className:`question-radio`,type:`radio`,name:`${s}-${j.id}`,checked:M.choice===`custom`,disabled:N,onChange:()=>B({choice:`custom`})}),(0,K.jsx)(`span`,{className:`question-choice-number`,"aria-hidden":`true`,children:(0,K.jsx)(at,{})}),(0,K.jsx)(`span`,{children:o(`questionCustom`)})]}),(0,K.jsxs)(`div`,{className:`question-actions`,children:[(g||h>0)&&(0,K.jsxs)(`button`,{type:`button`,className:`question-secondary`,disabled:N||!g&&h===0,onClick:()=>z(g?e.questions.length-1:h-1),children:[(0,K.jsx)(T,{}),o(`questionBack`)]}),!O&&(0,K.jsx)(`button`,{type:`button`,className:`question-secondary question-skip`,disabled:N,title:o(`questionDismiss`),onClick:()=>void H(!0),children:o(`questionSkip`)}),O?(0,K.jsxs)(`button`,{type:`button`,className:`question-primary`,disabled:C||!r,onClick:()=>void H(),children:[(0,K.jsx)(ft,{}),o(C?`questionSubmitting`:`questionRetry`)]}):g?(0,K.jsxs)(`button`,{type:`button`,className:`question-primary`,disabled:N||!F,onClick:()=>void H(),children:[(0,K.jsx)(I,{}),o(e.handoff?`handoffSubmit`:`questionSubmit`)]}):(0,K.jsxs)(`button`,{type:`button`,className:`question-primary`,disabled:N||M.choice===null||P,onClick:()=>z(hnew rf,[]),s=(0,_.useMemo)(()=>new Map,[]),c=i??s,[l,u]=(0,_.useState)(null),[d,f]=(0,_.useState)(null),[p,m]=(0,_.useState)(!1),[h,g]=(0,_.useState)(0),v=(0,_.useRef)(null),y=(0,_.useRef)(null);return(0,_.useEffect)(()=>{let t=new AbortController;return o.pendingQuestions(e,t.signal).then(({pending:n})=>{if(t.signal.aborted)return;let i=n?.requestId===v.current?null:n;y.current=i?.requestId??null,m(!1),WN(c,e,r,n?.requestId),u(i),n&&n.requestId!==v.current&&f(null)},()=>{t.signal.aborted||m(!0)}),()=>t.abort()},[o,e,r,c,t,h]),!l&&!d&&!p?null:(0,K.jsx)(`div`,{className:`question-panel`,children:l?(0,K.jsx)(GN,{request:l,connected:n,sessionPath:r,workingCache:c,answer:(e,t,n)=>o.answerQuestions(e,t,n),onSettled:e=>{y.current===l.requestId&&(y.current=null,v.current=l.requestId,u(null),f(e.state===`answered`?null:e),g(e=>e+1))}},l.requestId):d?(0,K.jsxs)(`div`,{className:`question-receipt`,role:`status`,children:[(0,K.jsx)(I,{"aria-hidden":`true`}),(0,K.jsx)(`span`,{children:a(`questionState_${d.state}`)}),(0,K.jsx)(`button`,{type:`button`,className:`question-icon`,"aria-label":a(`questionCloseReceipt`),onClick:()=>f(null),children:(0,K.jsx)(Lt,{})})]}):(0,K.jsxs)(`div`,{className:`question-receipt`,role:`alert`,children:[(0,K.jsx)(`span`,{children:a(`questionLoadFailed`)}),(0,K.jsx)(`button`,{type:`button`,className:`question-secondary`,onClick:()=>g(e=>e+1),children:a(`questionRetryLoad`)})]})})}function qN(e,t,{active:n=!0,running:r=!1,initialSource:i=`unstaged`,initialBaseRef:a}={}){let{t:o}=cr(),s=(0,_.useMemo)(()=>new rf,[]),c=(0,_.useRef)(null),l=(0,_.useRef)(null),u=(0,_.useRef)(!1),d=(0,_.useRef)({active:n,running:r});d.current={active:n,running:r};let[f,p]=(0,_.useState)(null),[m,h]=(0,_.useState)(!1),[g,v]=(0,_.useState)(null),y=e?.id,b=e?.path,[x,S]=(0,_.useState)({sessionId:y,sessionPath:b,source:i,baseRef:a}),C=x.sessionId===y&&x.sessionPath===b?x.source:i,w=x.sessionId===y&&x.sessionPath===b?x.baseRef:a,T=(0,_.useCallback)(e=>{S({sessionId:y,sessionPath:b,source:e,baseRef:w})},[y,b,w]),E=(0,_.useCallback)(e=>{S({sessionId:y,sessionPath:b,source:`branch`,baseRef:e})},[y,b]);(0,_.useLayoutEffect)(()=>{p(null),v(null),h(!!y)},[y,b,C,w]);let D=(0,_.useCallback)(async()=>{if(!y||!b||document.visibilityState===`hidden`)return;if(c.current){u.current=!0;return}let e=new AbortController;c.current=e,h(!0),v(null);try{let t=await s.gitReview(y,b,e.signal,{source:C,offset:`0`,...C===`branch`&&w?{baseRef:w}:{}});e.signal.aborted||(t.ok||v(o(t.reason===`not_git_repository`?`gitReviewNotRepository`:t.reason===`baseline_unavailable`?`gitReviewBaselineUnavailable`:t.reason===`base_branch_unavailable`?`gitReviewBaseUnavailable`:t.reason===`invalid_base_branch`?`gitReviewBaseInvalid`:`gitReviewFailed`)),p(e=>!t.ok&&e?.ok?t.branches?{...e,branches:t.branches}:e:t.ok&&e?.ok&&t.snapshot.revision===e.snapshot.revision?JSON.stringify(t.branches)===JSON.stringify(e.branches)?e:{...e,branches:t.branches}:t))}catch(t){e.signal.aborted||v(t instanceof Error?t.message:`Git review unavailable`)}finally{if(!e.signal.aborted&&(c.current=null,h(!1),u.current)){u.current=!1;let e=d.current;(e.active||!e.running)&&l.current===null&&(l.current=window.setTimeout(()=>{l.current=null,D()},e.active?200:2e3))}}},[s,y,b,C,w,o]),O=(0,_.useCallback)(async()=>{if(!y||!b||!f?.ok||f.snapshot.nextOffset===void 0||c.current)return;let e=f.snapshot,t=new AbortController;c.current=t,h(!0),v(null);try{let n=await s.gitReview(y,b,t.signal,{source:C,offset:String(e.nextOffset),revision:e.revision,...C===`branch`&&w?{baseRef:w}:{}});if(t.signal.aborted)return;if(!n.ok||n.snapshot.revision!==e.revision)throw Error(o(!n.ok&&n.reason===`revision_changed`?`gitReviewChanged`:`gitReviewFailed`));p({...n,snapshot:{...n.snapshot,files:[...e.files,...n.snapshot.files],additions:e.additions+n.snapshot.additions,deletions:e.deletions+n.snapshot.deletions}})}catch(e){t.signal.aborted||v(e instanceof Error?e.message:o(`gitReviewFailed`))}finally{t.signal.aborted||(c.current=null,h(!1))}},[s,y,b,C,w,f,o]),k=(0,_.useCallback)(async(e,t,n)=>{if(!y||!b)return;let r=await s.gitReview(y,b,t,{source:C,file:e,revision:n,...C===`branch`&&w?{baseRef:w}:{}});if(!r.ok||r.summaryRevision!==n)throw(r.ok||r.reason===`revision_changed`)&&!t.aborted&&D(),Error(o(!r.ok&&r.reason!==`revision_changed`?`gitReviewFailed`:`gitReviewChanged`));return r.snapshot.files.find(t=>t.path===e)},[s,y,b,C,w,D,o]);return(0,_.useEffect)(()=>{if(y)return l.current=window.setTimeout(()=>{l.current=null,D()},200),()=>{l.current!==null&&window.clearTimeout(l.current),l.current=null,u.current=!1,c.current?.abort(),c.current=null}},[D,y]),(0,_.useEffect)(()=>{n&&l.current!==null&&(window.clearTimeout(l.current),l.current=null)},[n]),(0,_.useEffect)(()=>{if(!n&&r){l.current!==null&&window.clearTimeout(l.current),l.current=null,u.current=!1;return}!y||l.current!==null||(l.current=window.setTimeout(()=>{l.current=null,D()},n?200:2e3))},[D,t,n,r,y]),(0,_.useEffect)(()=>{if(!y)return;let e=()=>{let e=d.current;(e.active||!e.running)&&D()};return window.addEventListener(`focus`,e),document.addEventListener(`visibilitychange`,e),()=>{window.removeEventListener(`focus`,e),document.removeEventListener(`visibilitychange`,e)}},[D,y]),(0,_.useMemo)(()=>({result:f,loading:m,error:g,refresh:D,source:C,setSource:T,baseRef:w,setBaseRef:E,readFile:k,loadMore:O}),[f,m,g,D,C,T,w,E,k,O])}function JN({notice:e,actions:t}){let{t:n}=cr(),r=(0,_.useRef)(!1),[i,a]=(0,_.useState)(null),[o,s]=(0,_.useState)(!1),c=()=>t.dismissArchiveNotice(e.key),l=async n=>{if(!r.current){r.current=!0,a(n),s(!1);try{(n===`undo`?await t.unarchiveSession(e.path):await t.selectSession(e.path,e.sessionId))===!1?s(!0):c()}catch{s(!0)}finally{r.current=!1,a(null)}}};return(0,K.jsx)(`div`,{className:`archive-notification`,"data-session-path":e.path,children:(0,K.jsx)(Zu,{type:`info`,body:n(`archiveNoticeTitle`),isAutoHide:!i&&!o,autoHideDuration:8e3,onDismiss:c,renderContent:()=>(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(C,{className:`archive-notification-icon`,"aria-hidden":`true`}),(0,K.jsxs)(`div`,{className:`archive-notification-copy`,children:[(0,K.jsx)(`strong`,{children:n(`archiveNoticeTitle`)}),(0,K.jsx)(`span`,{title:e.title,children:e.title}),o&&(0,K.jsx)(`span`,{className:`archive-notification-error`,role:`alert`,children:n(`archiveNoticeFailed`)})]}),(0,K.jsx)(`button`,{type:`button`,disabled:i!==null,onClick:()=>void l(`view`),children:n(`archiveNoticeView`)}),(0,K.jsxs)(`button`,{type:`button`,className:`archive-notification-undo`,disabled:i!==null,onClick:()=>void l(`undo`),children:[i===`undo`&&(0,K.jsx)(He,{className:`archive-notification-spinner`,"aria-hidden":`true`}),n(`archiveNoticeUndo`)]}),(0,K.jsx)(`button`,{type:`button`,className:`archive-notification-close`,"aria-label":n(`close`),onClick:c,children:(0,K.jsx)(Lt,{"aria-hidden":`true`})})]})})})}function YN({notices:e,actions:t}){return e.length?(0,K.jsx)(`div`,{className:`archive-notifications`,children:e.map(e=>(0,K.jsx)(JN,{notice:e,actions:t},e.key))}):null}function XN(e){let t=e?.closest(`.session-row, .workspace-group`),n=e?.closest(`.session-sidebar`),r=t?.dataset.sessionKey,i=Array.from(n?.querySelectorAll(`.session, .workspace-label, .workspace-heading-label`)??[]),a=i.findIndex(e=>t?.contains(e)),o=a<0?i:[...i.slice(a+1),...i.slice(0,a).reverse()];return()=>requestAnimationFrame(()=>{!n?.isConnected||document.querySelector(`dialog[open]`)||[e,r==null?null:Array.from(n.querySelectorAll(`.session-row`)).find(e=>e.dataset.sessionKey===r)?.querySelector(`.menu-action-button`),...o,n.querySelector(`.new-session-button`)].find(e=>e?.isConnected&&!e.closest(`[hidden], [inert]`)&&e.checkVisibility?.()!==!1)?.focus({preventScroll:!0})})}function ZN({session:e,archived:t,connected:n,pinSaving:r,restoring:i,movementItems:a,client:o,actions:s,onRename:c,onPin:l,onRead:u,onArchive:d,onNotice:f}){let{t:p}=cr(),m=(0,_.useRef)(null),h=(0,_.useRef)(!0),g=(0,_.useRef)(0),v=(0,_.useRef)(!1),[y,b]=(0,_.useState)(!1),[x,w]=(0,_.useState)(null),[T,E]=(0,_.useState)(!1),[D,k]=(0,_.useState)(!1),[A,j]=(0,_.useState)(null),[M,N]=(0,_.useState)(!1),[P,F]=(0,_.useState)(null),[I,L]=(0,_.useState)(!1),[R,z]=(0,_.useState)(!1),B=e.execution?.status===`running`||e.execution?.waitingForInput,V=(e.execution?.pendingFollowUps??0)+(e.execution?.pendingSteering??0)>0,H=n?B||V?p(`sidebarActionRunning`):void 0:p(`sidebarActionDisconnected`),ee=t?p(`sidebarForkArchived`):n?A?.local===!1?p(`sidebarForkUnavailable`):void 0:p(`sidebarActionDisconnected`),te=P!==null&&(P.path!==e.path||P.id!==e.id),ne=e.pinOrder!==void 0,re=()=>XN(m.current?.querySelector(`button`)??null),ie=()=>{let t=new URL(`/`,window.location.origin);return t.searchParams.set(`sessionPath`,e.path),t.searchParams.set(`sessionId`,e.id),t.href};(0,_.useEffect)(()=>(h.current=!0,()=>{h.current=!1,g.current++}),[]);let ae=(0,_.useRef)({id:e.id,path:e.path});(0,_.useEffect)(()=>{(ae.current.id!==e.id||ae.current.path!==e.path)&&(ae.current={id:e.id,path:e.path},b(!1),w(null),j(null))},[e.id,e.path]),(0,_.useEffect)(()=>{if(!y||!e.cwd||!n)return;let t=++g.current;return w(null),E(!1),o.sessionOpenTargets(e.path,e.id).then(e=>{h.current&&g.current===t&&w(e.targets)}).catch(()=>{h.current&&g.current===t&&E(!0)}),()=>{g.current++}},[o,n,y,e.cwd,e.id,e.path]),(0,_.useEffect)(()=>{if(!y||t||!n)return;let r=!1;return j(null),N(!1),Promise.resolve().then(()=>o.sessionForkOptions(e.path,e.id)).then(e=>{r||j(e)}).catch(()=>{r||N(!0)}),()=>{r=!0}},[t,o,n,y,e.id,e.path]);let U=()=>{b(!1),queueMicrotask(c)},oe=()=>{let e=re();l().then(e,e)},se=()=>{let e=re();d().then(e,e)},ce=async t=>{try{let n=await wd(t===`link`?ie():t===`cwd`?e.cwd:(await o.sessionMarkdown(e.path,e.id)).markdown);f(p(n?`sidebarCopied`:`sidebarCopyFailed`),!n)}catch{f(p(`sidebarCopyFailed`),!0)}},le=async(t=`local`)=>{if(!(D||ee)&&!(t===`worktree`&&!A?.worktree)){k(!0);try{t===`worktree`?await s.forkConversation(e.path,e.id,t):await s.forkConversation(e.path,e.id)}catch{f(p(`sidebarForkFailed`),!0)}finally{h.current&&k(!1)}}},de=()=>{if(v.current)return;let e=P?.restoreFocus;F(null),e?.()},fe=async()=>{if(!(!P||v.current||H||te)){v.current=!0,L(!0),z(!1);try{await s.deleteSession(P.path,P.id,P.commandId)?(h.current&&F(null),P.restoreFocus()):h.current&&z(!0)}catch{h.current&&z(!0)}finally{v.current=!1,h.current&&L(!1)}}},W=[{id:`rename`,label:p(`sidebarRename`),icon:(0,K.jsx)(at,{}),isDisabled:!n,onClick:U},...t?[]:[{id:`pin`,label:p(ne?`sidebarUnpin`:`sidebarPin`),icon:ne?(0,K.jsx)(ot,{}):(0,K.jsx)(st,{}),isDisabled:r||!n,onClick:oe},{id:`read`,label:p(e.unread?`markConversationRead`:`markConversationUnread`),icon:(0,K.jsx)(_e,{}),isDisabled:!e.readRevision||!n,onClick:()=>void u()}],...a.length?[{type:`divider`},...a]:[],...t?[]:[{type:`divider`},{id:`fork`,label:ee?(0,K.jsxs)(`span`,{className:`sidebar-menu-unavailable`,children:[(0,K.jsx)(`span`,{children:p(`sidebarFork`)}),(0,K.jsx)(`small`,{children:ee})]}):p(`sidebarFork`),icon:(0,K.jsx)(Ae,{}),isDisabled:!!ee||D,items:[{id:`fork-local`,label:p(D?`forkSessionPending`:e.worktree?`sidebarForkSameWorktree`:`sidebarForkLocal`),icon:(0,K.jsx)(et,{}),onClick:()=>void le()},...A?.worktree?[{id:`fork-worktree`,label:p(`sidebarForkWorktree`),icon:(0,K.jsx)(jt,{className:`sidebar-worktree-icon`}),onClick:()=>void le(`worktree`)}]:A===null?[{id:`fork-worktree-loading`,label:p(M?`sidebarForkOptionsFailed`:`sidebarForkOptionsLoading`),isDisabled:!0}]:[]]}],{type:`divider`},{id:`copy`,label:p(`sidebarCopy`),icon:(0,K.jsx)(ue,{}),items:[{id:`copy-link`,label:p(`sidebarCopyLink`),onClick:()=>void ce(`link`)},{id:`copy-markdown`,label:p(`sidebarCopyMarkdown`),isDisabled:!n,onClick:()=>void ce(`markdown`)},{id:`copy-cwd`,label:p(`sidebarCopyCwd`),isDisabled:!e.cwd,onClick:()=>void ce(`cwd`)}]},{type:`divider`},{id:`new-window`,label:p(`sidebarNewWindow`),icon:(0,K.jsx)(Ct,{}),onClick:()=>{window.open(ie(),`_blank`,`noopener,noreferrer`)}},...e.cwd&&n&&(x==null||x.length>0)?[{id:`open-in`,label:p(`sidebarOpenIn`),icon:(0,K.jsx)(O,{}),items:x?.map(t=>({id:t.id,label:t.label,onClick:()=>{o.openSessionIn(e.path,e.id,t.id).catch(()=>f(p(`sidebarOpenFailed`),!0))}}))??[{id:`open-in-loading`,label:p(T?`sidebarAppsFailed`:`sidebarAppsLoading`),isDisabled:!0}]}]:[],{type:`divider`},{id:t?`restore`:`archive`,label:p(i?`restoringConversation`:t?`sidebarRestore`:`sidebarArchive`),icon:t?(0,K.jsx)(S,{}):(0,K.jsx)(C,{}),isDisabled:i||!!H,description:H,onClick:se},{id:`delete`,label:p(`sidebarDelete`),icon:(0,K.jsx)(kt,{}),isDisabled:!!H,description:H,onClick:()=>{let t=re();queueMicrotask(()=>{h.current&&(z(!1),F({commandId:crypto.randomUUID(),path:e.path,id:e.id,name:ZA(e,p(`untitledSession`)),restoreFocus:t}))})}}];return(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`span`,{className:`astryx-menu-trigger`,ref:m,children:(0,K.jsx)(jA,{className:`sidebar-action-menu sidebar-conversation-menu`,button:{label:p(`conversationOptions`),icon:(0,K.jsx)(me,{}),isIconOnly:!0,size:`sm`,variant:`ghost`,className:`menu-action-button`},items:y?W:[],menuWidth:248,placement:`below`,alignment:`start`,hasChevron:!1,isMenuOpen:y,onOpenChange:b})}),P&&(0,K.jsx)($j,{isOpen:P!==null,onOpenChange:e=>{e||de()},purpose:`form`,width:420,"aria-label":p(`sidebarDeleteTitle`),children:(0,K.jsxs)(`form`,{className:`openpi-dialog sidebar-delete-dialog`,onSubmit:e=>{e.preventDefault(),fe()},children:[(0,K.jsx)(`strong`,{children:p(`sidebarDeleteTitle`)}),(0,K.jsx)(`p`,{children:p(`sidebarDeleteDescription`,{name:P?.name})}),(R||te)&&(0,K.jsx)(`p`,{className:`sidebar-dialog-error`,role:`alert`,children:p(te?`sessionLinkUnavailable`:`sidebarDeleteFailed`)}),(0,K.jsxs)(`div`,{className:`dialog-actions`,children:[(0,K.jsx)(`button`,{type:`button`,"data-autofocus":!0,disabled:I,onClick:de,children:p(`cancel`)}),(0,K.jsx)(`button`,{type:`submit`,className:`danger`,disabled:I||!!H||te,children:p(I?`sidebarDeleting`:`sidebarDeleteConfirm`)})]})]})})]})}var QN=e=>JSON.stringify([`session`,e.id,e.path]),$N=e=>JSON.stringify([`message`,e.sessionId,e.sessionPath,e.messageId,e.source,e.lineOffset]);function eP({open:e,initialQuery:t,initialIncludeArchived:n,sessions:r,workspaces:i,onClose:a,onCreateSession:o,onOpenSession:s,onOpenMessage:c}){let{t:l}=cr(),u=(0,_.useMemo)(()=>new rf,[]),[d,f]=(0,_.useState)(t),p=n,[m,h]=(0,_.useState)(null),[g,v]=(0,_.useState)(!1),[y,b]=(0,_.useState)(0),[x,S]=(0,_.useState)(!1),[C,w]=(0,_.useState)(null),[T,E]=(0,_.useState)(null),[D,O]=(0,_.useState)(null),k=(0,_.useRef)(null),A=(0,_.useId)(),j=(0,_.useRef)(null);(0,_.useEffect)(()=>(e&&(f(t),h(null),S(!1),w(null),E(null)),()=>{j.current?.abort(),j.current=null}),[e,t]);let M=d.trim(),N=(0,_.useMemo)(()=>new Map(i?.map(e=>[e.path,e.name])),[i]),P=(0,_.useMemo)(()=>{if(!e||!s)return[];let t=M.toLocaleLowerCase();return(r??[]).filter(e=>e.archived&&!p?!1:!t||`${ZA(e,l(`untitledSession`))} ${e.cwd} ${N.get(e.cwd)??``}`.toLocaleLowerCase().includes(t)).sort((e,t)=>t.modified.localeCompare(e.modified)||e.path.localeCompare(t.path))},[e,r,N,M,p,s,l]),F=M?[{name:`transcriptSearchSessions`,sessions:P.slice(0,9)}]:[{name:`pinnedConversations`,sessions:P.filter(e=>e.pinOrder!==void 0).sort((e,t)=>(e.pinOrder??0)-(t.pinOrder??0))},{name:`transcriptSearchRecent`,sessions:P.filter(e=>e.pinOrder===void 0).slice(0,10)}];(0,_.useLayoutEffect)(()=>{j.current?.abort(),j.current=null,E(null),w(null),O(null)},[e,M,p,y]),(0,_.useEffect)(()=>{if(!e||!M){v(!1),S(!1);return}let t=new AbortController;v(!0),S(!1);let n=window.setTimeout(()=>{u.searchTranscripts(M,{includeArchived:p,signal:t.signal}).then(e=>{t.signal.aborted||h({query:M,revision:y,includeArchived:p,response:e})}).catch(()=>{t.signal.aborted||S(!0)}).finally(()=>{t.signal.aborted||v(!1)})},250);return()=>{window.clearTimeout(n),t.abort()}},[u,e,M,p,y]);let I=m?.query===M&&m.revision===y&&m.includeArchived===p?m.response:null,L=[...F.flatMap(e=>e.sessions.map(QN)),...M?I?.matches.map($N)??[]:[]],R=D!==null&&L.includes(D)?D:L[0],z=e=>`${A}-${encodeURIComponent(e)}`,B=R?z(R):void 0;(0,_.useLayoutEffect)(()=>{e&&B&&document.getElementById(B)?.scrollIntoView?.({block:`nearest`})},[e,B]);let V=async(e,t,n)=>{if(j.current)return;O(e),k.current?.focus({preventScroll:!0});let r=new AbortController;j.current=r,E(e),w(null);try{let e=await t(r.signal);if(r.signal.aborted)return;e===!1?w(n):a()}catch{r.signal.aborted||w(n)}finally{j.current===r&&(j.current=null,E(null))}};return(0,K.jsx)($j,{isOpen:e,onOpenChange:e=>!e&&a(),purpose:`info`,width:`min(520px, 92vw)`,maxHeight:`calc(var(--transcript-search-list-height) + 64px)`,padding:0,className:`transcript-search-modal`,"aria-label":l(`transcriptSearch`),children:e&&(0,K.jsxs)(`div`,{className:`transcript-search-dialog`,children:[(0,K.jsx)(`h2`,{className:`transcript-search-sr-only`,children:l(`transcriptSearch`)}),(0,K.jsx)(`input`,{ref:k,className:`transcript-search-input`,"data-autofocus":!0,type:`search`,maxLength:200,value:d,"aria-label":l(`transcriptSearch`),"aria-autocomplete":`list`,"aria-controls":A,"aria-activedescendant":B,placeholder:l(`transcriptSearchPlaceholder`),autoComplete:`off`,autoCorrect:`off`,spellCheck:!1,onChange:e=>f(e.target.value),onKeyDown:e=>{if(e.nativeEvent.isComposing||e.nativeEvent.keyCode===229||![`ArrowDown`,`ArrowUp`,`Home`,`End`,`Enter`].includes(e.key)||T!==null)return;if(!R||!B){e.key===`Enter`&&!M&&o&&(e.preventDefault(),a(),o());return}e.preventDefault();let t=L.indexOf(R);if(e.key===`Enter`){document.getElementById(B)?.click();return}let n=e.key===`Home`?0:e.key===`End`?L.length-1:e.key===`ArrowDown`?Math.min(t+1,L.length-1):Math.max(t-1,0);O(L[n]??null)}}),(0,K.jsx)(`span`,{className:`transcript-search-sr-only`,role:`status`,children:g?l(`transcriptSearching`):null}),(0,K.jsxs)(`div`,{className:`transcript-search-groups`,children:[(0,K.jsx)(`div`,{id:A,role:`listbox`,"aria-label":l(`transcriptSearch`),children:F.filter(e=>e.sessions.length>0||M&&I?.matches.length).map(e=>(0,K.jsxs)(`fieldset`,{"aria-label":l(e.name),children:[(0,K.jsxs)(`h3`,{children:[l(e.name),g&&(0,K.jsx)(He,{className:`is-spinning`,"aria-hidden":`true`})]}),(0,K.jsxs)(`ul`,{className:`transcript-search-results`,role:`presentation`,children:[s&&e.sessions.map(e=>{let t=ZA(e,l(`untitledSession`)),n=QN(e),r=e.ungrouped?l(`ungrouped`):N.get(e.cwd)||QA(e.cwd);return(0,K.jsx)(`li`,{role:`presentation`,children:(0,K.jsxs)(`button`,{id:z(n),role:`option`,"aria-selected":n===R,tabIndex:-1,type:`button`,disabled:T!==null,"aria-label":l(`transcriptSearchSessionResult`,{session:t}),onPointerMove:()=>O(n),onMouseDown:e=>e.preventDefault(),onClick:()=>void V(n,t=>s(e.path,t),`transcriptSearchSessionOpenFailed`),children:[(0,K.jsx)(`span`,{className:`transcript-search-accessory`,"aria-hidden":`true`,children:T===n?(0,K.jsx)(He,{className:`is-spinning`}):e.unread?(0,K.jsx)(ae,{className:`transcript-search-unread`}):null}),(0,K.jsx)(`span`,{className:`transcript-search-result-body`,children:(0,K.jsxs)(`span`,{className:`transcript-search-result-line`,children:[(0,K.jsx)(`span`,{className:`transcript-search-title`,title:t,children:t}),(0,K.jsx)(`span`,{className:`transcript-search-project`,title:e.cwd,children:r})]})})]})},n)}),M&&I?.matches.map(e=>{let t=e.sessionName||l(`untitledSession`),n=l(`transcriptSearchSource_${e.source}`),r=$N(e);return(0,K.jsx)(`li`,{role:`presentation`,children:(0,K.jsxs)(`button`,{id:z(r),role:`option`,"aria-selected":r===R,tabIndex:-1,type:`button`,disabled:T!==null,"aria-label":l(`transcriptSearchResult`,{session:t,source:n}),onPointerMove:()=>O(r),onMouseDown:e=>e.preventDefault(),onClick:()=>void V(r,t=>c({sessionId:e.sessionId,sessionPath:e.sessionPath,entryId:e.messageId},t),`transcriptSearchOpenFailed`),children:[(0,K.jsx)(`span`,{className:`transcript-search-accessory`,"aria-hidden":`true`,children:T===r&&(0,K.jsx)(He,{className:`is-spinning`})}),(0,K.jsxs)(`span`,{className:`transcript-search-result-body`,children:[(0,K.jsxs)(`span`,{className:`transcript-search-result-line`,children:[(0,K.jsx)(`span`,{className:`transcript-search-title`,title:t,children:t}),(0,K.jsx)(`span`,{className:`transcript-search-project`,title:e.workspace??n,children:e.workspace?N.get(e.workspace)||QA(e.workspace):n})]}),(0,K.jsx)(`span`,{className:`transcript-search-snippet`,children:e.snippet})]})]})},r)})]})]},e.name))}),!M&&!P.length&&(0,K.jsxs)(`div`,{className:`transcript-search-empty-history`,children:[(0,K.jsx)(`p`,{children:l(`noConversations`)}),o&&(0,K.jsx)(`button`,{className:`transcript-search-create`,type:`button`,onClick:()=>{a(),o()},children:l(`newSession`)})]}),M&&!P.length&&!I?.matches.length&&(g?(0,K.jsx)(`div`,{className:`transcript-search-feedback`,"aria-hidden":`true`,children:(0,K.jsx)(He,{className:`is-spinning`})}):I&&!x?(0,K.jsx)(`div`,{className:`transcript-search-feedback`,role:`status`,children:l(`transcriptSearchEmpty`)}):null),x&&(0,K.jsxs)(`p`,{className:`transcript-search-error`,role:`alert`,children:[l(`transcriptSearchFailed`),(0,K.jsx)(`button`,{type:`button`,onClick:()=>b(e=>e+1),children:l(`transcriptSearchRetry`)})]}),C&&(0,K.jsx)(`p`,{className:`transcript-search-error`,role:`alert`,children:l(C)}),I?.partial&&(0,K.jsx)(`p`,{className:`transcript-search-partial`,children:l(`transcriptSearchPartial`)})]})]})})}function tP({workspace:e,client:t,actions:n,connected:r,onClose:i}){let{t:a}=cr(),[o,s]=(0,_.useState)([]),[c,l]=(0,_.useState)(),[u,d]=(0,_.useState)(!1),[f,p]=(0,_.useState)(null),[m,h]=(0,_.useState)(0),[g,v]=(0,_.useState)(null),[y,b]=(0,_.useState)(null),[x,S]=(0,_.useState)(!1),[C,w]=(0,_.useState)(!1),T=(0,_.useRef)(0),E=(0,_.useRef)(null),D=(0,_.useRef)(!1),O=(0,_.useRef)(!0),k=(0,_.useCallback)(async n=>{let r=++T.current;d(!0),p(null);try{let i=await t.workspaceWorktrees(e,n);if(!O.current||r!==T.current)return;if(i.truncated&&!i.nextCursor)throw Error(`Missing worktree continuation`);s(e=>{let t=n?[...e]:[];for(let e of i.worktrees)t.some(t=>t.worktreePath===e.worktreePath&&t.sessionId===e.sessionId&&t.sessionPath===e.sessionPath)||t.push(e);return t}),l(i.nextCursor),h(e=>(n?e:0)+i.unavailable)}catch(e){O.current&&r===T.current&&p(e instanceof tf&&e.code===`WORKTREE_LIST_CHANGED`?`changed`:`failed`)}finally{O.current&&r===T.current&&d(!1)}},[t,e]);(0,_.useEffect)(()=>(O.current=!0,k(),()=>{O.current=!1,T.current++}),[k]);let A=async()=>{if(!(!g||D.current||!r)){D.current=!0,w(!0);try{let e=await n.releaseSessionWorktree(g);if(!O.current)return;b(e),S(!1),e.state===`removed`&&s(e=>e.filter(e=>e.worktreePath!==g.worktreePath||e.sessionId!==g.sessionId||e.sessionPath!==g.sessionPath))}catch{O.current&&(S(!0),b(null))}finally{D.current=!1,O.current&&w(!1)}}};(0,_.useEffect)(()=>{g&&!C&&E.current?.focus()},[g,C]);let j=()=>{D.current||i()};return(0,K.jsx)($j,{isOpen:!0,onOpenChange:e=>{e||j()},purpose:`form`,width:560,"aria-label":a(`managedWorktrees`),children:(0,K.jsxs)(`div`,{className:`openpi-dialog`,children:[(0,K.jsx)(`strong`,{children:a(`managedWorktrees`)}),(0,K.jsx)(`p`,{className:`sidebar-dialog-path`,children:e}),(0,K.jsx)(`p`,{children:a(`managedWorktreesDescription`)}),g?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`p`,{className:`sidebar-dialog-path`,children:g.worktreePath}),(0,K.jsx)(`p`,{children:a(`managedWorktreeConfirm`)}),(y||x)&&(0,K.jsxs)(`p`,{role:`status`,className:y?.state===`removed`?void 0:`sidebar-dialog-error`,children:[a(y?.state===`removed`?`managedWorktreeRemoved`:y?.state===`preserved`?`managedWorktreePreserved`:y?.state===`uncertain`?`managedWorktreeUncertainTerminal`:`managedWorktreeUncertain`),y?.reason&&(0,K.jsxs)(K.Fragment,{children:[` `,y.reason]})]}),(0,K.jsxs)(`div`,{className:`dialog-actions`,children:[(0,K.jsx)(`button`,{type:`button`,"data-autofocus":!0,ref:E,disabled:C,onClick:()=>{v(null),b(null),S(!1)},children:a(`managedWorktreesBack`)}),y?.state!==`removed`&&y?.state!==`uncertain`&&(0,K.jsx)(`button`,{type:`button`,className:`danger`,disabled:C||!r,onClick:()=>void A(),children:a(C?`managedWorktreeRemoving`:y||x?`managedWorktreesRetry`:`managedWorktreeRemove`)})]})]}):(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`div`,{className:`managed-worktrees-list`,children:o.map(e=>(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`sidebar-dialog-path`,children:e.worktreePath}),(0,K.jsx)(`button`,{type:`button`,disabled:!r||u||!!f,onClick:()=>{v(e),b(null),S(!1)},children:a(`managedWorktreeReview`)})]},JSON.stringify([e.worktreePath,e.sessionId,e.sessionPath])))}),!u&&!f&&!o.length&&(0,K.jsx)(`p`,{children:a(`managedWorktreesEmpty`)}),m>0&&(0,K.jsx)(`p`,{children:a(`managedWorktreesUnavailable`,{count:m})}),f&&(0,K.jsx)(`p`,{role:`alert`,children:a(f===`changed`?`managedWorktreesChanged`:`managedWorktreesLoadFailed`)}),(0,K.jsxs)(`div`,{className:`dialog-actions`,children:[(0,K.jsx)(`button`,{type:`button`,"data-autofocus":!0,onClick:j,children:a(`close`)}),f&&(0,K.jsx)(`button`,{type:`button`,disabled:u||!r,onClick:()=>void k(f===`changed`?void 0:c),children:a(f===`changed`?`managedWorktreesRefresh`:`managedWorktreesRetry`)}),c&&!f&&(0,K.jsx)(`button`,{type:`button`,disabled:u||!r,onClick:()=>void k(c),children:a(`managedWorktreesMore`)}),u&&(0,K.jsx)(`span`,{role:`status`,children:a(`loading`)})]})]})]})})}function nP(e){return e.workspacePath??e.cwd}function rP(e,t,n){return e[t+(n?2:-1)]??null}function iP(e,t,n){return e[t+ +!!n]??null}function aP(e,t){return e>t.top+t.height/2}function oP(e){let t=e.execution?.lastTurn;return JSON.stringify(t?[e.path,e.id,t.commandId,t.finishedAt]:[e.path,e.id])}function sP(e){return e.firstUnread?.type===`turn`?e.firstUnread.finishedAt:e.execution?.lastTurn?.finishedAt??Date.parse(e.modified)}function cP(e){return JSON.stringify([e.path,e.id])}function lP(e,t=!0){return t&&e.execution?.waitingForInput?0:e.unread?1:t&&e.execution?.status===`running`?2:3}function uP({items:e,label:t,alignment:n=`start`}){return(0,K.jsx)(`span`,{className:`astryx-menu-trigger`,children:(0,K.jsx)(jA,{className:`sidebar-action-menu`,button:{label:t,icon:(0,K.jsx)(me,{}),isIconOnly:!0,size:`sm`,variant:`ghost`,className:`menu-action-button`},items:e,menuWidth:240,placement:`below`,alignment:n,hasChevron:!1})})}function dP(e){let{t}=cr(),n=(0,_.useRef)(null),[r,i]=(0,_.useState)(null),[a,o]=(0,_.useState)(null),[s,c]=(0,_.useState)(!1),[l,u]=(0,_.useState)(!1),[d,f]=(0,_.useState)(10),[p,m]=(0,_.useState)(!0),[h,g]=(0,_.useState)(new Set),v=(0,_.useRef)(null),[y,b]=(0,_.useState)(!1),[x,S]=(0,_.useState)(!1),[E,D]=(0,_.useState)(!1),[O,j]=(0,_.useState)(new Set),[M,P]=(0,_.useState)(10),[F,R]=(0,_.useState)(!1),[z,B]=(0,_.useState)(null),[V,ee]=(0,_.useState)(!1),te=(0,_.useRef)(new Set),ne=(0,_.useRef)(null),[re,ie]=(0,_.useState)(null),[U,oe]=(0,_.useState)(``),[se,ce]=(0,_.useState)(!1),le=(0,_.useRef)(null),ue=(0,_.useRef)(null),de=(0,_.useRef)(null),fe=(0,_.useRef)(null),W=(0,_.useRef)(null),pe=(0,_.useRef)(null);(0,_.useEffect)(()=>{if(!z)return;let e=window.setTimeout(()=>B(null),5e3);return()=>window.clearTimeout(e)},[z]);let me=e.snapshot,he=me?.selectedSession?.path===e.selectedPath?e.selectedPath:null,ge=me?.sessions.find(e=>e.path===me.selectedSession?.path&&e.id===me.selectedSession?.id),_e=oP(ge??{id:``,path:``});(0,_.useEffect)(()=>{e.selectedPath,ne.current=null},[_e,e.selectedPath]),(0,_.useEffect)(()=>{if(!e.sessionViewVisible||!ge||e.selectedPath!==ge.path||ne.current===_e||e.connected===!1)return;let t=!0,n=()=>{document.visibilityState!==`visible`||!document.hasFocus()||document.querySelector(`dialog[open]`)||ne.current!==_e&&(ne.current=_e,!(!ge.unread||!ge.readRevision)&&e.actions.setSessionRead(ge.path,ge.id,!0,ge.readRevision).catch(()=>{t&&R(!0)}))};return n(),document.addEventListener(`visibilitychange`,n),window.addEventListener(`focus`,n),document.addEventListener(`close`,n,!0),()=>{t=!1,document.removeEventListener(`visibilitychange`,n),window.removeEventListener(`focus`,n),document.removeEventListener(`close`,n,!0)}},[_e,ge,e.sessionViewVisible,e.selectedPath,e.connected,e.actions]);let ve=(0,_.useMemo)(()=>new rf,[]),[ye,be]=(0,_.useState)(!1),[xe,Se]=(0,_.useState)(!1),[Ce,we]=(0,_.useState)(!1),Te=(0,_.useRef)(!1),Ee=(0,_.useRef)(null),Oe=(0,_.useRef)(!1),[ke,Ae]=(0,_.useState)(!1),je=(0,_.useRef)(null),[Me,Ne]=(0,_.useState)(null),[Pe,Fe]=(0,_.useState)(null),[Ie,Le]=(0,_.useState)(!1),[Re,ze]=(0,_.useState)(!1),Ve=me?.preferences.pinnedSort??`manual`,We=me?.preferences.sidebarGrouping??`project`,Ge=me?.preferences.chatsSort??`updated`,Ke=(me?.sessions??[]).filter(e=>e.pinOrder!==void 0&&!e.archived).sort((e,t)=>(Ve===`updated`?t.modified.localeCompare(e.modified):0)||e.pinOrder-t.pinOrder).filter(n=>{let r=me?.workspaces.find(e=>e.path===nP(n));return`${ZA(n,t(`untitledSession`))} ${n.cwd} ${r?.name??``}`.toLowerCase().includes(e.query.trim().toLowerCase())}),qe=async e=>{if(!Te.current){Te.current=!0,we(!0),ze(!1);try{await e()}catch{ze(!0)}finally{Te.current=!1,we(!1)}}},Je=(t,n,r)=>qe(()=>e.actions.setSessionPin(t.path,t.id,n,r)),Ye=(t,n,r)=>qe(()=>e.actions.setSidebarPin(t,n,r)),Xe=t=>qe(async()=>{await ve.savePreferences(t),await e.actions.refreshSnapshot()}),Ze=async(t,n)=>{if(!t.readRevision)return;let r=oP(t);if(!te.current.has(r)){t.path===e.selectedPath&&(ne.current=r),te.current.add(r),R(!1);try{await e.actions.setSessionRead(t.path,t.id,n,t.readRevision)}catch{R(!0)}finally{te.current.delete(r)}}},Qe=e.query.trim(),$e=JSON.stringify([ye,Qe]),et=(0,_.useRef)({key:$e});et.current.key!==$e&&(et.current={key:$e});let nt=(0,_.useRef)(!1),[rt,it]=(0,_.useState)(null),[at,ot]=(0,_.useState)(!1),[ct,ut]=(0,_.useState)(null),ft=(0,_.useRef)(null),pt=rt?.query===Qe?rt:null,mt=ct?.query===Qe?ct:null,gt=(0,_.useCallback)(async(e,t)=>{if(!ye)return;ft.current?.abort();let n=new AbortController;ft.current=n,ot(!0),ut(null);try{let r=await ve.listArchivedSessions({query:Qe,...e?{cursor:e}:{},limit:25},n.signal);if(n.signal.aborted||ft.current!==n)return;let i=[...r.sessions];for(;!e&&t!==void 0&&i.length!i.some(t=>t.path===e.path));if(i.push(...e),!e.length)break}it(t=>({...r,query:Qe,sessions:e&&t?.query===Qe?[...t.sessions,...i.filter(e=>!t.sessions.some(t=>t.path===e.path))]:i}))}catch(r){!n.signal.aborted&&ft.current===n&&ut({query:Qe,kind:r instanceof tf&&r.code===`ARCHIVED_SESSION_CURSOR_STALE`?`stale`:`failed`,...e?{cursor:e}:{},...t===void 0?{}:{retainedCount:t}})}finally{ft.current===n&&(ft.current=null,ot(!1))}},[Qe,ye,ve]),[_t,yt]=(0,_.useState)(new Set),[bt,xt]=(0,_.useState)(new Set),St=(0,_.useRef)(new Set),[Ct,Tt]=(0,_.useState)(!1),[Et,Dt]=(0,_.useState)(!1),Ot=(0,_.useRef)(!1),[At,jt]=(0,_.useState)(!1),Mt=(0,_.useRef)(!1),[Nt,Pt]=(0,_.useState)(!1),[Ft,It]=(0,_.useState)(!1),Rt=(0,_.useRef)(!1),zt=async t=>{if(St.current.has(t))return;St.current.add(t),xt(new Set(St.current)),Tt(!1);let n=et.current;try{let r=await e.actions.unarchiveSession(t);if(!nt.current||et.current!==n)return;r?(it(e=>e?{...e,sessions:e.sessions.filter(e=>e.path!==t)}:null),await gt()):Tt(!0)}finally{St.current.delete(t),nt.current&&xt(new Set(St.current))}};(0,_.useEffect)(()=>(nt.current=!0,()=>{nt.current=!1}),[]),(0,_.useEffect)(()=>(Tt(!1),ut(null),ye&&(it(e=>e?.query===Qe?e:null),gt()),()=>{ft.current?.abort(),ft.current=null}),[Qe,ye,gt]),(0,_.useEffect)(()=>{if(e.searchOpen)return le.current?.focus(),()=>ue.current?.focus()},[e.searchOpen]),(0,_.useEffect)(()=>{if(e.mobileOpen)return W.current?.focus(),()=>{let t=e.returnFocusRef?.current;t?.checkVisibility()&&t.focus()}},[e.mobileOpen,e.returnFocusRef]),(0,_.useEffect)(()=>{e.mobileOpen&&document.activeElement===document.body&&!document.querySelector(`dialog:modal`)&&W.current?.focus()}),(0,_.useEffect)(()=>{a&&(de.current?.focus(),de.current?.select())},[a]);let Bt=(0,_.useMemo)(()=>{let n=e.query.trim().toLowerCase(),r=ye?pt?.sessions??[]:me?.sessions??[],i=(e,i)=>r.filter(r=>!!r.archived===ye&&(ye||r.pinOrder===void 0)&&(e===`__ungrouped__`?r.ungrouped:nP(r)===e&&!r.ungrouped)&&(!n||ye||i||`${ZA(r,t(`untitledSession`))} ${r.cwd}`.toLowerCase().includes(n))),a=[...me?.workspaces??[]];for(let e of r)!e.ungrouped&&!a.some(t=>t.path===nP(e))&&a.push({path:nP(e),name:nP(e),current:!1});return[...a.map(e=>{let t=!!n&&`${e.name} ${e.path}`.toLowerCase().includes(n);return{...e,showPath:a.some(t=>t.path!==e.path&&t.name===e.name),sessions:i(e.path,t),ungrouped:!1,matches:t}}),{path:`__ungrouped__`,name:t(`ungrouped`),current:!1,sessions:i(`__ungrouped__`,!1),ungrouped:!0,pinOrder:void 0,showPath:!1,matches:!1}].filter(e=>e.sessions.length>0||!ye&&!e.ungrouped&&(!n||e.matches))},[ye,e.query,pt,me,t]),Vt=e=>[...e].sort((e,t)=>(Ge===`manual`?(e.order??2**53-1)-(t.order??2**53-1):0)||t.modified.localeCompare(e.modified)||e.path.localeCompare(t.path)),Ht=(e,t)=>{if(e.length<=t+1)return e;let n=e.slice(0,t),r=e.find(e=>e.path===he&&e.id===me?.selectedSession?.id);return r&&!n.includes(r)&&n.push(r),n},Ut=Bt.filter(e=>!e.ungrouped),Wt=Ut.filter(e=>e.pinOrder!==void 0),Gt=[...Ke.map(e=>({kind:`session`,session:e,pinOrder:e.pinOrder})),...Wt.map(e=>({kind:`workspace`,project:e,pinOrder:e.pinOrder}))].sort((e,t)=>{let n=e=>e.kind===`session`?e.session.modified:e.project.sessions.reduce((e,t)=>t.modified>e?t.modified:e,``);return(Ve===`updated`?n(t).localeCompare(n(e)):0)||e.pinOrder-t.pinOrder}),Kt=e=>e.kind===`session`?{kind:`session`,path:e.session.path,id:e.session.id}:{kind:`workspace`,path:e.project.path},qt=Ut.filter(e=>e.pinOrder===void 0),Jt=y||e.query.trim()||ye||qt.length<=6?qt:qt.slice(0,5),Yt=qt.find(e=>ge?.path===he&&e.path===(ge?nP(ge):void 0));Yt&&!Jt.includes(Yt)&&Jt.push(Yt);let Xt=Vt((me?.sessions??[]).filter(n=>!n.archived&&n.pinOrder===void 0&&!me?.workspaces.some(e=>e.pinOrder!==void 0&&e.path===nP(n))&&(We===`list`||me?.preferences.projectsInRecents!==!1||n.ungrouped||!Ut.some(e=>e.path===nP(n)))&&(!e.query.trim()||`${ZA(n,t(`untitledSession`))} ${n.cwd} ${me?.workspaces.find(e=>e.path===nP(n))?.name??``}`.toLowerCase().includes(e.query.trim().toLowerCase())))),Zt=e.query.trim()?Xt:Ht(Xt,M),Qt=t=>lP(t,e.connected)<3,$t=new Date;$t.setHours(0,0,0,0),$t.setDate($t.getDate()-6);let en=(me?.sessions??[]).filter(e=>!e.archived&&(Qt(e)||h.has(cP(e))||[`completed`,`failed`].includes(e.execution?.lastTurn?.outcome??``)&&(e.execution?.lastTurn?.finishedAt??0)>=$t.getTime())),tn=new Map([...h].map((e,t)=>[e,t])),nn=en.filter(e=>Qt(e)||h.has(cP(e))).sort((t,n)=>(tn.get(cP(t))??1/0)-(tn.get(cP(n))??1/0)||lP(t,e.connected)-lP(n,e.connected)||n.modified.localeCompare(t.modified)),rn=new Set(nn.map(e=>e.path)),an=en.filter(e=>!p||!rn.has(e.path)).sort((e,t)=>sP(t)-sP(e)),on=p?nn.slice(0,d):[],sn=an.slice(0,Math.max(0,d-on.length)),cn=en.length>on.length+sn.length;(0,_.useEffect)(()=>{let e=pe.current;if(!l||!cn||!e||typeof IntersectionObserver>`u`)return;let t=new IntersectionObserver(([e])=>{e?.isIntersecting&&(t.disconnect(),f(d+10))},{root:e.closest(`.sidebar-navigation`)});return t.observe(e),()=>t.disconnect()},[l,cn,d]),(0,_.useEffect)(()=>{if(!l){v.current=null,g(e=>e.size?new Set:e),f(10);return}let t=v.current??{openedAt:Date.now(),sessions:new Set((me?.sessions??[]).map(cP))},n=(me?.sessions??[]).filter(t=>!t.archived&&lP(t,e.connected)<3).sort((t,n)=>lP(t,e.connected)-lP(n,e.connected)||n.modified.localeCompare(t.modified)),r=n.filter(e=>!t.sessions.has(cP(e))&&Date.parse(e.created)>=t.openedAt);for(let e of me?.sessions??[])t.sessions.add(cP(e));v.current=t,g(e=>{let t=new Set([...r.map(cP),...e,...n.map(cP)]);return t.size===e.size?e:t})},[l,me?.sessions,e.connected]);let ln=(me?.sessions??[]).filter(e=>!e.archived&&e.unread),un=ln.filter(e=>e.readRevision),dn=p?nn.filter(e=>e.unread&&e.readRevision):[],fn=async e=>{if(!V){ee(!0);try{await Promise.all(e.map(e=>Ze(e,!0)))}finally{ee(!1)}}},pn=he?ge?nP(ge):me?.selectedSession?.cwd:null,mn=!!(me?.truncation.sessionsOmitted||me?.truncation.workspacesOmitted),hn=e=>{Ot.current||(oe(e.name),ce(!1),o(e))},gn=async()=>{let t=U.trim();if(!a||!t||t===a.name||Ot.current)return;let n=a,r=et.current,i=pt?.sessions.length??25;Ot.current=!0,Dt(!0),ce(!1);try{if(n.kind===`workspace`?await e.actions.renameWorkspace(n.path,t):await e.actions.renameSession(n.path,t),!nt.current)return;o(null),n.kind===`session`&&ye&&et.current===r&>(void 0,i)}catch{nt.current&&ce(!0)}finally{Ot.current=!1,nt.current&&Dt(!1)}},_n=async()=>{if(!re||Mt.current)return;let t=re;Mt.current=!0,jt(!0),Pt(!1);try{let n=await e.actions.removeWorkspace(t.path);if(!nt.current)return;n?ie(null):Pt(!0)}catch{nt.current&&Pt(!0)}finally{Mt.current=!1,nt.current&&jt(!1)}},vn=async t=>{if(Rt.current)return;let n=et.current;Rt.current=!0,It(!0);try{if(!t){await e.actions.chooseWorkspace();return}let r=await e.actions.createSession(t);if(!nt.current||et.current!==n||!r?.sessionId||!r.sessionPath||r.workspacePath!==t)return;be(!1),u(!1),e.actions.setQuery(``)}catch{}finally{Rt.current=!1,nt.current&&It(!1)}},yn=(0,_.useCallback)(()=>{(Ee.current||je.current)&&(Oe.current=!0),Ee.current=null,je.current=null,Ae(!1),Fe(null),Ne(null)},[]);(0,_.useEffect)(()=>{let e=e=>{e.key!==`Escape`||!Ee.current&&!je.current||(e.preventDefault(),yn())},t=()=>{(Ee.current||je.current)&&yn()};return window.addEventListener(`keydown`,e,!0),window.addEventListener(`blur`,t),()=>{window.removeEventListener(`keydown`,e,!0),window.removeEventListener(`blur`,t)}},[yn]);let bn=(e,t)=>{let n=Gt[e];if(!n)return;let r=rP(Gt,e,t);Ye(Kt(n),!0,r?Kt(r):null)},xn=e=>Ve===`manual`?[{id:`move-up`,label:t(`movePinUp`),icon:(0,K.jsx)(k,{}),isDisabled:Ce||e<=0,onClick:()=>bn(e,!1)},{id:`move-down`,label:t(`movePinDown`),icon:(0,K.jsx)(w,{}),isDisabled:Ce||e===Gt.length-1,onClick:()=>bn(e,!0)}]:[],Sn=[{id:`updated`,label:t(`pinnedRecentlyUpdated`),endContent:Ge===`updated`?(0,K.jsx)(I,{size:16}):void 0,isDisabled:Ce,onClick:()=>void Xe({chatsSort:`updated`})},{id:`manual`,label:t(`pinnedManualOrder`),endContent:Ge===`manual`?(0,K.jsx)(I,{size:16}):void 0,isDisabled:Ce,onClick:()=>void Xe({chatsSort:`manual`})}],Cn=[{id:`updated`,label:t(`pinnedRecentlyUpdated`),endContent:Ve===`updated`?(0,K.jsx)(I,{size:16}):void 0,isDisabled:Ce,onClick:()=>void Xe({pinnedSort:`updated`})},{id:`manual`,label:t(`pinnedManualOrder`),endContent:Ve===`manual`?(0,K.jsx)(I,{size:16}):void 0,isDisabled:Ce,onClick:()=>void Xe({pinnedSort:`manual`})}],wn=[{label:t(`sidebarGroupBy`),items:[{label:t(`sidebarByProject`),endContent:We===`project`?(0,K.jsx)(I,{size:16}):void 0,isDisabled:Ce,onClick:()=>void Xe({sidebarGrouping:`project`})},{label:t(`sidebarFlatList`),endContent:We===`list`?(0,K.jsx)(I,{size:16}):void 0,isDisabled:Ce,onClick:()=>void Xe({sidebarGrouping:`list`})}]},{label:t(`sidebarChatSort`),items:Sn}],Tn=[...wn,...We===`project`?[{label:t(`sidebarShow`),items:[{label:t(`sidebarProjectsInRecents`),endContent:me?.preferences.projectsInRecents===!1?void 0:(0,K.jsx)(I,{size:16}),isDisabled:Ce,onClick:()=>void Xe({projectsInRecents:me?.preferences.projectsInRecents===!1})}]}]:[]],En=(0,K.jsxs)(`div`,{className:`sidebar-section-actions is-always-visible`,children:[(0,K.jsx)(uP,{label:t(`sidebarActivityOptions`),items:[{type:`section`,title:t(`sidebarShow`),items:[{label:t(`sidebarPriority`),endContent:p?(0,K.jsx)(I,{size:16}):void 0,onClick:()=>m(e=>!e)}]},{type:`divider`},{label:t(`sidebarMarkAllRead`),icon:(0,K.jsx)(Ue,{}),isDisabled:V||!dn.length,onClick:()=>void fn(dn)}]}),p&&nn.some(e=>!Qt(e))&&(0,K.jsx)(Cd,{content:t(`sidebarClearRead`),children:(0,K.jsx)(`button`,{className:`icon-button`,type:`button`,"aria-label":t(`sidebarClearRead`),onClick:()=>g(new Set(nn.filter(Qt).map(cP))),children:(0,K.jsx)(N,{"aria-hidden":`true`})})})]}),Dn=(n,r=!1,i)=>{let a=Gt.findIndex(e=>e.kind===`session`&&e.session.path===n.path&&e.session.id===n.id),o={kind:`session`,path:n.path,id:n.id},s=n.pinOrder!==void 0,c=e.connected!==!1&&n.execution?.status===`running`,u=e.connected!==!1&&n.execution?.waitingForInput,d=n.firstUnread?.type===`turn`?n.firstUnread.outcome:n.execution?.lastTurn?.outcome,f=u?`attention`:c?`running`:n.unread?d===`failed`?`attention`:d===`completed`?`completed`:`unread`:void 0,p=f===`running`?He:f===`attention`?H:ae,m=e.connected===!1?0:n.execution?.pendingFollowUps??0,h=n.path===he&&n.id===me?.selectedSession?.id,g=f===`attention`?u?`waiting`:`failed`:f===`running`&&n.execution?.compacting?`compacting`:f,_=[...g?[t(`sidebarState_`+g)]:[],...m>0?[t(`pendingFollowUpsHint`,{count:m})]:[]].join(` · `),v=i?.sessions.findIndex(e=>e.path===n.path&&e.id===n.id)??-1,y=!ye&&!r&&Ge===`manual`&&!!i,b=t=>qe(()=>e.actions.setSessionOrder(n.path,n.id,t?{path:t.path,id:t.id}:null)),x=r?xn(a):y&&i?[{id:`move-up`,label:t(`movePinUp`),icon:(0,K.jsx)(k,{}),isDisabled:Ce||v<=0,onClick:()=>void b(rP(i.sessions,v,!1))},{id:`move-down`,label:t(`movePinDown`),icon:(0,K.jsx)(w,{}),isDisabled:Ce||v===i.sessions.length-1,onClick:()=>void b(rP(i.sessions,v,!0))}]:[];return(0,K.jsxs)(`li`,{className:`session-row `+(n.unread?`is-unread `:``)+(Pe===n.path?Ie?`is-pin-drop-after`:`is-pin-drop-target`:``),"aria-label":ZA(n,t(`untitledSession`)),"data-session-key":JSON.stringify([n.path,n.id]),draggable:!Ce&&!e.query.trim()&&(r?Ve===`manual`:y),onDragStart:e=>{if(e.stopPropagation(),r&&Ve===`manual`)Ee.current=o;else if(y&&i)je.current={path:n.path,id:n.id,scope:i.key};else{e.preventDefault();return}Ae(!0),Oe.current=!0,e.dataTransfer.effectAllowed=`move`,e.dataTransfer.setData(`text/plain`,n.id)},onDragOver:e=>{if(!(r&&Ve===`manual`&&Ee.current)&&!(y&&je.current?.scope===i?.key))return;e.preventDefault(),e.stopPropagation(),e.dataTransfer.dropEffect=`move`,Fe(n.path),Ne(null);let t=e.currentTarget.getBoundingClientRect();Le(aP(e.clientY,t))},onDragEnd:yn,onDrop:t=>{let n=t.currentTarget.getBoundingClientRect(),s=aP(t.clientY,n);if(r&&Ve===`manual`&&Ee.current){t.preventDefault(),t.stopPropagation();let e=Gt[a+1];Ye(Ee.current,!0,s?e?Kt(e):null:o)}else if(y&&i&&je.current?.scope===i.key){t.preventDefault(),t.stopPropagation();let n=je.current,r=iP(i.sessions,v,s);qe(()=>e.actions.setSessionOrder(n.path,n.id,r?{path:r.path,id:r.id}:null))}else return;yn()},children:[(0,K.jsxs)(`button`,{className:`session `+(h?`active`:``),type:`button`,"aria-current":h?`page`:void 0,"aria-label":[ZA(n,t(`untitledSession`)),n.path,_].filter(Boolean).join(` · `),onClick:()=>{h&&n.unread&&e.sessionViewVisible&&e.connected!==!1&&Ze(n,!0),e.actions.selectSession(n.path)},onDoubleClick:r=>{h&&e.connected!==!1&&r.target instanceof Element&&r.target.closest(`.session-title`)&&hn({kind:`session`,path:n.path,name:ZA(n,t(`untitledSession`))})},children:[(0,K.jsxs)(`span`,{className:`session-copy`,children:[(0,K.jsx)(`span`,{className:`session-title`,title:ZA(n,t(`untitledSession`)),children:ZA(n,t(`untitledSession`))}),l&&(0,K.jsxs)(`span`,{className:`session-project`,children:[(0,K.jsx)(De,{"aria-hidden":`true`}),me?.workspaces.find(e=>e.path===nP(n))?.name??$A(nP(n))]})]}),_&&(0,K.jsx)(Cd,{content:_,children:(0,K.jsxs)(`span`,{className:`session-status`,"aria-hidden":`true`,children:[f&&(0,K.jsx)(p,{className:`session-state session-state-`+f}),m>0&&(0,K.jsxs)(`span`,{className:`session-queue`,children:[(0,K.jsx)(Be,{}),(0,K.jsx)(`span`,{children:m>99?`99+`:m})]})]})})]}),!ye&&(0,K.jsx)(Cd,{content:t(s?`unpinConversation`:`pinConversation`),children:(0,K.jsx)(`button`,{type:`button`,className:`session-pin-button`,"aria-label":t(s?`unpinConversation`:`pinConversation`),disabled:Ce,onClick:e=>{let t=XN(e.currentTarget);Je(n,!s).finally(t)},children:(0,K.jsx)(st,{"aria-hidden":`true`,fill:s?`currentColor`:`none`})})}),(0,K.jsx)(ZN,{session:n,archived:ye,connected:e.connected!==!1,pinSaving:Ce,restoring:bt.has(n.path),movementItems:x,client:ve,actions:e.actions,onRename:()=>hn({kind:`session`,path:n.path,name:ZA(n,t(`untitledSession`))}),onPin:()=>Je(n,!s),onRead:()=>Ze(n,!!n.unread),onArchive:()=>ye?zt(n.path):e.actions.archiveSession(n.path),onNotice:(e,t=!1)=>B({message:e,error:t})})]},n.path)},On=(r,a=!1)=>{let o=(ye?_t:e.collapsed).has(r.path)&&!e.query.trim(),s=!r.ungrouped&&pn===r.path,c=Gt.findIndex(e=>e.kind===`workspace`&&e.project.path===r.path),l=qt.findIndex(e=>e.path===r.path),u=!ye&&!r.ungrouped&&!Ce&&!e.query.trim(),d=t=>qe(()=>e.actions.setWorkspaceOrder(r.path,rP(qt,l,t)?.path??null)),f={kind:`workspace`,path:r.path},p=Vt(r.sessions),m=un.filter(e=>!e.ungrouped&&nP(e)===r.path),h=ye||!!e.query.trim()||O.has(r.path)||p.length<=6,g=[...ye?[]:[{id:`pin`,label:t(a?`unpinWorkspace`:`pinWorkspace`),icon:(0,K.jsx)(st,{}),isDisabled:Ce,onClick:()=>void Ye(f,!a)},{id:`mark-read`,label:t(`sidebarMarkAllRead`),icon:(0,K.jsx)(Ue,{}),isDisabled:V||!m.length,onClick:()=>void fn(m)}],...a?xn(c):ye?[]:[{id:`move-up`,label:t(`movePinUp`),icon:(0,K.jsx)(k,{}),isDisabled:!u||l<=0,onClick:()=>void d(!1)},{id:`move-down`,label:t(`movePinDown`),icon:(0,K.jsx)(w,{}),isDisabled:!u||l===qt.length-1,onClick:()=>void d(!0)}],...r.ungrouped?[]:[{id:`managed-worktrees`,label:t(`managedWorktrees`),icon:(0,K.jsx)(De,{}),isDisabled:e.connected===!1,onClick:()=>{let e=Array.from(fe.current?.querySelectorAll(`.workspace-group`)??[]).find(e=>e.dataset.workspaceKey===r.path);n.current=XN(e?.querySelector(`.workspace-row-actions .menu-action-button`)??null),queueMicrotask(()=>i(r.path))}}],{id:`rename`,label:t(`renameWorkspace`),icon:(0,K.jsx)(wt,{}),onClick:()=>hn({kind:`workspace`,path:r.path,name:r.name})},{id:`remove`,label:t(`removeWorkspace`),icon:(0,K.jsx)(kt,{}),variant:`destructive`,onClick:()=>{Pt(!1),ie({path:r.path,name:r.name})}}];return(0,K.jsxs)(`section`,{className:`workspace-group `+(o?`collapsed `:``)+(s?`is-active-workspace `:``)+(Me===r.path?Ie?`is-pin-drop-after`:`is-pin-drop-target`:``),"data-workspace-key":r.path,"aria-label":r.name,onDragOver:e=>{if(!u||!Ee.current||(a?Ve!==`manual`:Ee.current.kind!==`workspace`))return;e.preventDefault(),e.stopPropagation(),e.dataTransfer.dropEffect=`move`,Ne(r.path),Fe(null);let t=e.currentTarget.getBoundingClientRect();Le(aP(e.clientY,t))},onDragEnd:yn,onDragLeave:e=>{(!(e.relatedTarget instanceof Node)||!e.currentTarget.contains(e.relatedTarget))&&Ne(null)},onDrop:t=>{if(!u||!Ee.current||(a?Ve!==`manual`:Ee.current.kind!==`workspace`))return;t.preventDefault(),t.stopPropagation();let n=t.currentTarget.getBoundingClientRect(),i=aP(t.clientY,n),o=Ee.current;if(o.kind!==`workspace`||o.path!==r.path)if(a){let e=Gt[c+1];Ye(o,!0,i?e?Kt(e):null:f)}else qe(()=>e.actions.setWorkspaceOrder(o.path,i?qt[l+1]?.path??null:r.path));yn()},children:[(0,K.jsxs)(`div`,{className:`workspace-button`,draggable:u&&(!a||Ve===`manual`),onDragStart:e=>{if(!u||a&&Ve!==`manual`||e.target instanceof Element&&e.target.closest(`.workspace-row-actions`)){e.preventDefault();return}Ee.current=f,requestAnimationFrame(()=>{nt.current&&Ee.current===f&&Ae(!0)}),Oe.current=!0,e.dataTransfer.effectAllowed=`move`,e.dataTransfer.setData(`text/plain`,r.path)},children:[(0,K.jsxs)(`button`,{className:`workspace-label`,type:`button`,"aria-expanded":!o,"aria-current":s?`location`:void 0,disabled:!!e.query.trim(),title:r.ungrouped?void 0:r.path,onClick:()=>{ye?yt(e=>{let t=new Set(e);return t.has(r.path)?t.delete(r.path):t.add(r.path),t}):e.actions.toggleWorkspace(r.path)},children:[(0,K.jsx)(`span`,{className:`workspace-toggle`,"aria-hidden":`true`,children:o?(0,K.jsx)(De,{className:`workspace-folder`}):(0,K.jsx)(G,{className:`workspace-folder`})}),(0,K.jsxs)(`span`,{className:`workspace-identity`,children:[(0,K.jsx)(`strong`,{children:r.name}),r.showPath&&(0,K.jsx)(`small`,{children:$A(r.path)})]})]}),!r.ungrouped&&(0,K.jsxs)(`span`,{className:`workspace-row-actions`,children:[(0,K.jsx)(uP,{label:t(`workspaceOptions`),items:g}),(0,K.jsx)(Cd,{content:t(`newSession`),children:(0,K.jsx)(`button`,{className:`workspace-action`,type:`button`,"aria-label":t(`newSession`)+` `+r.name,disabled:Ft,"aria-busy":Ft||void 0,onClick:()=>void vn(r.path),children:(0,K.jsx)(wt,{})})})]})]}),!o&&!p.length&&!ye&&!e.query.trim()&&!mn&&(0,K.jsx)(`p`,{className:`workspace-empty`,children:t(`noConversations`)}),!o&&p.length>0&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`ul`,{className:`workspace-sessions`,children:(h?p:Ht(p,5)).map(e=>Dn(e,!1,{key:r.path,sessions:p}))}),!ye&&!e.query.trim()&&p.length>6&&(0,K.jsx)(`button`,{className:`sidebar-show-more is-indented`,type:`button`,"aria-expanded":O.has(r.path),onClick:()=>j(e=>{let t=new Set(e);return t.has(r.path)?t.delete(r.path):t.add(r.path),t}),children:t(O.has(r.path)?`sidebarShowLess`:`sidebarShowMore`)})]})]},r.path)},kn=new Map,An=new Date,jn=new Date(An);jn.setDate(An.getDate()-1);for(let e of sn){let n=new Date(sP(e)),r=n.toDateString()===An.toDateString()?t(`sidebarToday`):n.toDateString()===jn.toDateString()?t(`sidebarYesterday`):Number.isFinite(n.getTime())?n.toLocaleDateString(void 0,{weekday:`long`}):t(`sidebarEarlier`);kn.set(r,[...kn.get(r)??[],e])}return(0,K.jsxs)(`div`,{ref:fe,id:`session-sidebar`,className:`session-sidebar`,role:e.mobileOpen?`dialog`:`complementary`,"aria-modal":e.mobileOpen||void 0,"aria-label":`Session navigation`,tabIndex:e.mobileOpen?-1:void 0,onPointerDownCapture:()=>{!Ee.current&&!je.current&&(Oe.current=!1)},onClickCapture:e=>{e.detail!==0&&Oe.current&&(e.preventDefault(),e.stopPropagation(),Oe.current=!1)},onKeyDown:t=>{if(!e.mobileOpen||t.defaultPrevented||t.target instanceof Element&&(t.target.closest(`dialog`)||t.key!==`Tab`&&t.target.closest(`[role="menu"]`))||t.key===`Escape`&&fe.current?.querySelector(`[aria-haspopup="menu"][aria-expanded="true"]`)||(t.key===`Escape`&&!t.nativeEvent.isComposing&&(t.preventDefault(),e.actions.closeMobileSidebar()),t.key!==`Tab`))return;let n=Array.from(fe.current?.querySelectorAll(`button, input, select, textarea, a[href], [tabindex]`)??[]).filter(e=>e.tabIndex>=0&&!e.matches(`:disabled`)&&e.checkVisibility({visibilityProperty:!0})),r=t.shiftKey?n.at(-1):n[0],i=t.shiftKey?n[0]:n.at(-1);(document.activeElement===fe.current||document.activeElement===i)&&(t.preventDefault(),r?.focus())},children:[(0,K.jsxs)(`div`,{className:`sidebar-brand`,children:[(0,K.jsx)(`span`,{className:`sidebar-brand-title`,children:`OpenPI`}),(0,K.jsxs)(`div`,{className:`sidebar-header-actions`,children:[(0,K.jsx)(Cd,{content:t(l?`sidebarViewChats`:`sidebarViewActivity`),children:(0,K.jsxs)(`button`,{className:`icon-button sidebar-activity-toggle`,type:`button`,"aria-label":t(l?`sidebarViewChats`:`sidebarViewActivity`),"aria-pressed":l,onClick:()=>{be(!1),u(e=>!e)},children:[(0,K.jsx)(A,{"aria-hidden":`true`}),ln.length>0&&(0,K.jsx)(`span`,{className:`sidebar-unread-dot`})]})}),(0,K.jsx)(Cd,{content:t(`searchConversations`),children:(0,K.jsx)(`button`,{ref:ue,className:`icon-button`,type:`button`,"aria-label":t(`searchConversations`),onClick:()=>c(!0),children:(0,K.jsx)(ht,{"aria-hidden":`true`})})}),(0,K.jsx)(Cd,{content:t(`collapseSidebar`),placement:`end`,children:(0,K.jsx)(`button`,{ref:W,className:`collapse-button sidebar-mobile-close`,type:`button`,"aria-label":t(`collapseSidebar`),onClick:()=>e.mobileOpen?e.actions.closeMobileSidebar():e.actions.toggleSidebar(!1),children:(0,K.jsx)(tt,{})})})]})]}),(0,K.jsxs)(`button`,{className:`new-session-button`,type:`button`,"aria-label":t(`newSession`),title:t(`newSession`),disabled:Ft,"aria-busy":Ft||void 0,onClick:()=>void vn(e.selectedWorkspace),children:[(0,K.jsx)(wt,{}),(0,K.jsx)(`span`,{children:t(`newSession`)})]}),(0,K.jsx)(eP,{open:s,initialQuery:e.query,initialIncludeArchived:ye,sessions:me?.sessions??[],workspaces:me?.workspaces??[],onClose:()=>c(!1),onOpenMessage:e.actions.navigateToMessage,onOpenSession:t=>e.actions.selectSession(t),onCreateSession:()=>void vn(e.selectedWorkspace)}),(0,K.jsxs)(`div`,{className:`sidebar-navigation`,children:[z&&(0,K.jsx)(`p`,{className:`sidebar-scope-note sidebar-action-feedback`,role:z.error?`alert`:`status`,children:z.message}),Re&&(0,K.jsx)(`p`,{className:`sidebar-scope-note`,role:`alert`,children:t(`sidebarSaveFailed`)}),F&&(0,K.jsx)(`p`,{className:`sidebar-scope-note`,role:`alert`,children:t(`sidebarReadFailed`)}),l?(0,K.jsxs)(`section`,{className:`sidebar-activity`,"aria-label":t(`sidebarActivity`),children:[p&&(0,K.jsxs)(`section`,{"aria-label":t(`sidebarPriority`),children:[(0,K.jsxs)(`div`,{className:`sidebar-section-heading`,children:[(0,K.jsx)(`h2`,{className:`sidebar-section-label`,children:t(`sidebarPriority`)}),En]}),(0,K.jsx)(`ul`,{className:`sidebar-activity-sessions`,children:on.map(e=>Dn(e))}),!on.length&&(0,K.jsx)(`p`,{className:`sidebar-activity-empty`,children:t(`sidebarActivityEmpty`)})]}),[...kn].map(([e,t],n)=>(0,K.jsxs)(`section`,{"aria-label":e,children:[(0,K.jsxs)(`div`,{className:`sidebar-section-heading`,children:[(0,K.jsx)(`h2`,{className:`sidebar-section-label`,children:e}),!p&&n===0&&En]}),(0,K.jsx)(`ul`,{className:`sidebar-activity-sessions`,children:t.map(e=>Dn(e))})]},e)),!p&&!kn.size&&(0,K.jsxs)(`section`,{"aria-label":t(`sidebarToday`),children:[(0,K.jsxs)(`div`,{className:`sidebar-section-heading`,children:[(0,K.jsx)(`h2`,{className:`sidebar-section-label`,children:t(`sidebarToday`)}),En]}),(0,K.jsx)(`p`,{className:`sidebar-activity-empty`,children:t(`sidebarActivityEmpty`)})]}),cn&&(0,K.jsx)(`div`,{ref:pe,className:`sidebar-activity-tail`,role:`status`,"aria-label":t(`loading`),children:(0,K.jsx)(He,{"aria-hidden":`true`})})]}):(0,K.jsxs)(K.Fragment,{children:[!ye&&(Gt.length>0||ke&&Ee.current&&Ve===`manual`)&&(0,K.jsxs)(`section`,{className:`pinned-section `+(Me===`pinned-tail`?`is-pin-drop-after`:``),"aria-label":t(`pinnedConversations`),onDragOver:t=>{Ce||Ve!==`manual`||!Ee.current||e.query.trim()||(t.preventDefault(),t.dataTransfer.dropEffect=`move`,Ne(`pinned-tail`),Fe(null))},onDragLeave:e=>{(!(e.relatedTarget instanceof Node)||!e.currentTarget.contains(e.relatedTarget))&&Ne(null)},onDrop:t=>{Ce||Ve!==`manual`||!Ee.current||e.query.trim()||(t.preventDefault(),t.stopPropagation(),Ye(Ee.current,!0,null),yn())},children:[(0,K.jsxs)(`div`,{className:`sidebar-section-heading`,children:[(0,K.jsxs)(`button`,{type:`button`,className:`workspace-heading-label`,"aria-expanded":!xe||!!e.query.trim(),onClick:()=>Se(e=>!e),children:[t(`pinnedConversations`),(0,K.jsx)(L,{className:xe&&!e.query.trim()?`is-collapsed`:``,"aria-hidden":`true`})]}),(0,K.jsx)(`div`,{className:`sidebar-section-actions`,children:(0,K.jsx)(uP,{label:t(`pinnedOptions`),items:Cn,alignment:`end`})})]}),ke&&Ve===`manual`&&(Gt.length===0||xe)&&(0,K.jsx)(`p`,{className:`sidebar-drop-hint`,children:t(`sidebarDropPin`)}),(!xe||!!e.query.trim())&&(0,K.jsx)(`ul`,{className:`pinned-sessions`,children:Gt.map(e=>e.kind===`session`?Dn(e.session,!0):(0,K.jsx)(`li`,{className:`pinned-workspace`,children:On(e.project,!0)},e.project.path))})]}),(ye||We===`project`||e.searchOpen)&&(0,K.jsxs)(`div`,{className:`workspace-heading sidebar-section-heading `+(e.searchOpen?`is-searching`:``),children:[(0,K.jsxs)(`button`,{type:`button`,className:`workspace-heading-label`,"aria-label":t(ye?`currentConversations`:`sidebarProjects`),"aria-expanded":ye?void 0:!x||!!e.query.trim(),onClick:()=>ye?be(!1):S(e=>!e),children:[ye&&(0,K.jsx)(T,{"aria-hidden":`true`}),t(ye?`archivedConversations`:`sidebarProjects`),!ye&&(0,K.jsx)(L,{className:x&&!e.query.trim()?`is-collapsed`:``,"aria-hidden":`true`})]}),(0,K.jsxs)(`div`,{className:`session-search`,children:[(0,K.jsx)(ht,{}),(0,K.jsx)(`input`,{ref:le,type:`search`,value:e.query,placeholder:t(`searchPlaceholder`),maxLength:ye?160:void 0,"aria-label":t(`searchConversations`),onChange:t=>e.actions.setQuery(t.target.value)}),(0,K.jsx)(`button`,{type:`button`,"aria-label":t(`closeSearch`),onClick:()=>e.actions.setSearchOpen(!1),children:(0,K.jsx)(Lt,{})})]}),(0,K.jsxs)(`div`,{className:`workspace-actions sidebar-section-actions`,children:[!ye&&(0,K.jsx)(uP,{label:t(`sidebarProjectOptions`),items:wn}),ye&&(0,K.jsx)(Cd,{content:t(`sidebarFilterList`),children:(0,K.jsx)(`button`,{className:`icon-button`,type:`button`,"aria-label":t(`sidebarFilterList`),onClick:()=>e.actions.setSearchOpen(!0),children:(0,K.jsx)(ht,{})})}),!ye&&(0,K.jsx)(Cd,{content:t(`addWorkspace`),children:(0,K.jsx)(`button`,{className:`icon-button`,type:`button`,"aria-label":t(`addWorkspace`),onClick:()=>void e.actions.chooseWorkspace(),children:(0,K.jsx)(lt,{})})})]})]}),e.searchOpen&&(0,K.jsxs)(`button`,{type:`button`,className:`sidebar-content-search`,onClick:()=>c(!0),children:[(0,K.jsx)(ht,{"aria-hidden":`true`}),t(`transcriptSearch`)]}),ye&&(0,K.jsxs)(`div`,{className:`sidebar-archive-actions`,children:[(0,K.jsx)(`button`,{type:`button`,className:`icon-button`,"aria-label":t(`refreshArchives`),title:t(`refreshArchives`),disabled:at,onClick:()=>void gt(),children:(0,K.jsx)(dt,{"aria-hidden":`true`})}),at&&(0,K.jsx)(`span`,{role:`status`,children:t(`loadingArchives`)})]}),ye&&mt&&(0,K.jsxs)(`div`,{className:`sidebar-scope-note`,role:`alert`,children:[(0,K.jsx)(`p`,{children:t(mt.kind===`stale`?`archiveCursorStale`:`archiveLoadFailed`)}),(0,K.jsx)(`button`,{type:`button`,disabled:at,onClick:()=>void gt(mt.kind===`stale`?void 0:mt.cursor,mt.retainedCount),children:t(mt.kind===`stale`?`refreshArchives`:`retryArchives`)})]}),ye&&!!pt?.truncation.recordsUnscanned&&(0,K.jsx)(`p`,{className:`sidebar-scope-note`,children:t(`archiveScanBounded`,{count:pt?.truncation.recordsUnscanned})}),!ye&&mn&&(0,K.jsx)(`p`,{className:`sidebar-scope-note`,children:t(`loadedHistoryBounded`,{sessions:me?.truncation.sessionsOmitted,workspaces:me?.truncation.workspacesOmitted})}),ye&&Ct&&(0,K.jsx)(`p`,{className:`sidebar-scope-note`,role:`alert`,children:t(`restoreFailed`)}),(0,K.jsxs)(`div`,{className:`workspace-tree`,children:[(ye?Bt:We===`project`&&(!x||e.query.trim())?Jt:[]).map(e=>On(e)),!ye&&We===`project`&&ke&&Ee.current?.kind===`workspace`&&!e.query.trim()&&(0,K.jsx)(`section`,{className:`sidebar-project-tail `+(Me===`project-tail`?`is-pin-drop-target`:``),"aria-label":t(`sidebarDropProjectLast`),onDragOver:e=>{Ce||Ee.current?.kind!==`workspace`||(e.preventDefault(),e.dataTransfer.dropEffect=`move`,Ne(`project-tail`),Fe(null))},onDragLeave:e=>{(!(e.relatedTarget instanceof Node)||!e.currentTarget.contains(e.relatedTarget))&&Ne(null)},onDrop:t=>{if(Ce||Ee.current?.kind!==`workspace`)return;t.preventDefault();let n=Ee.current;qe(()=>e.actions.setWorkspaceOrder(n.path,null)),yn()},children:t(`sidebarDropProjectLast`)}),!ye&&We===`project`&&!x&&!e.query.trim()&&qt.length>6&&(0,K.jsx)(`button`,{className:`sidebar-show-more`,type:`button`,"aria-expanded":y,onClick:()=>b(e=>!e),children:t(y?`sidebarShowLess`:`sidebarShowMore`)}),!ye&&(0,K.jsxs)(`section`,{className:`sidebar-recents`,"aria-label":t(`sidebarRecent`),children:[(0,K.jsxs)(`div`,{className:`sidebar-section-heading`,children:[(0,K.jsxs)(`button`,{type:`button`,className:`workspace-heading-label`,"aria-expanded":!E||!!e.query.trim(),onClick:()=>D(e=>!e),children:[t(`sidebarRecent`),(0,K.jsx)(L,{className:E&&!e.query.trim()?`is-collapsed`:``,"aria-hidden":`true`})]}),(0,K.jsx)(`div`,{className:`sidebar-section-actions`,children:(0,K.jsx)(uP,{label:t(`sidebarRecentOptions`),items:Tn})})]}),(!E||!!e.query.trim())&&(0,K.jsx)(`ul`,{className:`recent-sessions`,children:Zt.map(e=>Dn(e,!1,{key:`recent`,sessions:Xt}))}),!E&&Zt.lengthP(e=>e+10),children:t(`sidebarShowMore`)})]}),(ye?!Bt.length:!Gt.length&&!Xt.length&&(We===`list`||!qt.length))&&(0,K.jsx)(`div`,{className:`empty`,hidden:ye&&(at||!!mt),children:e.query.trim()?t(ye&&pt?.truncation.recordsUnscanned?`noMatchingScannedArchives`:!ye&&mn?`noMatchingLoaded`:`noMatching`):t(ye?pt?.truncation.recordsUnscanned?`noScannedArchives`:`noArchivedSessions`:`noSessions`)}),ye&&pt?.nextCursor&&mt?.kind!==`stale`&&(0,K.jsx)(`button`,{type:`button`,className:`sidebar-archive-more`,disabled:at,onClick:()=>void gt(pt.nextCursor),children:t(`moreArchives`)})]})]})]}),(0,K.jsxs)(`div`,{className:`sidebar-footer`,children:[(0,K.jsxs)(`button`,{className:`sidebar-settings-button sidebar-archive-toggle`,type:`button`,"aria-label":t(`archivedConversations`),"aria-pressed":ye,title:t(`archivedConversations`),onClick:()=>{u(!1),be(e=>!e)},children:[(0,K.jsx)(C,{"aria-hidden":`true`}),(0,K.jsx)(`span`,{children:t(`archivedConversations`)})]}),(0,K.jsxs)(`button`,{className:`sidebar-settings-button`,type:`button`,"aria-label":t(`settings`),title:t(`settings`),"data-provider-settings-trigger":!0,disabled:e.settingsDisabled,onClick:e.onOpenSettings,children:[(0,K.jsx)(vt,{"aria-hidden":`true`}),(0,K.jsx)(`span`,{children:t(`settings`)})]})]}),(0,K.jsx)($j,{isOpen:!!a,onOpenChange:e=>!e&&!Ot.current&&o(null),purpose:`form`,width:400,"aria-label":a?.kind===`workspace`?t(`renameWorkspace`):t(`renameConversation`),children:(0,K.jsxs)(`form`,{className:`openpi-dialog`,onSubmit:e=>{e.preventDefault(),gn()},children:[(0,K.jsx)(`strong`,{children:a?.kind===`workspace`?t(`renameWorkspace`):t(`renameConversation`)}),(0,K.jsx)(`input`,{ref:de,value:U,maxLength:80,disabled:Et,"aria-label":a?.kind===`workspace`?t(`workspaceName`):t(`conversationName`),onChange:e=>oe(e.target.value)}),se&&(0,K.jsx)(`p`,{className:`sidebar-dialog-error`,role:`alert`,children:t(`renameFailed`)}),(0,K.jsxs)(`div`,{className:`dialog-actions`,children:[(0,K.jsx)(`button`,{type:`button`,disabled:Et,onClick:()=>{Ot.current||o(null)},children:t(`cancel`)}),(0,K.jsx)(`button`,{type:`submit`,className:`primary`,disabled:Et||!U.trim()||U.trim()===a?.name,children:t(Et?`savingName`:`save`)})]})]})}),r&&(0,K.jsx)(tP,{workspace:r,client:ve,actions:e.actions,connected:e.connected!==!1,onClose:()=>{i(null),n.current?.()}},r),(0,K.jsx)($j,{isOpen:!!re,onOpenChange:e=>!e&&!Mt.current&&ie(null),purpose:`form`,width:440,"aria-label":t(`removeWorkspace`),children:(0,K.jsxs)(`div`,{className:`openpi-dialog`,children:[(0,K.jsx)(`strong`,{children:t(`removeWorkspace`)}),(0,K.jsx)(`p`,{className:`sidebar-dialog-path`,children:re?.path}),(0,K.jsxs)(`p`,{children:[re?.name,`:`,t(`workspaceDeleteConfirm`)]}),Nt&&(0,K.jsx)(`p`,{className:`sidebar-dialog-error`,role:`alert`,children:t(`workspaceRemoveFailed`)}),(0,K.jsxs)(`div`,{className:`dialog-actions`,children:[(0,K.jsx)(`button`,{type:`button`,disabled:At,onClick:()=>{Mt.current||ie(null)},children:t(`cancel`)}),(0,K.jsx)(`button`,{type:`button`,className:`danger`,disabled:At,onClick:()=>void _n(),children:t(At?`removingWorkspace`:`removeWorkspace`)})]})]})})]})}var fP=(0,_.createContext)(null);fP.displayName=`LayoutAreaContext`;var pP=(0,_.createContext)({hasHeader:!1,hasFooter:!1,hasStart:!1,hasEnd:!1});pP.displayName=`LayoutSlotsContext`;var mP={center:{kGNEyG:`x6s0dn4`,$$css:!0},end:{kGNEyG:`xuk3077`,$$css:!0},start:{kGNEyG:`x1cy8zhl`,$$css:!0},stretch:{kGNEyG:`x1qjc9v5`,$$css:!0}},hP={start:{kjj79g:`x1nhvcw1`,$$css:!0},center:{kjj79g:`xl56j7k`,$$css:!0},end:{kjj79g:`x13a6bvl`,$$css:!0},between:{kjj79g:`x1qughib`,$$css:!0},around:{kjj79g:`x1l1ennw`,$$css:!0},evenly:{kjj79g:`xaw8158`,$$css:!0}},gP={horizontal:{kXwgrk:`x1q0g3np`,$$css:!0},vertical:{kXwgrk:`xdt5ytf`,$$css:!0}},_P={nowrap:{kwnvtZ:`xozqiw3`,$$css:!0},wrap:{kwnvtZ:`x1a02dak`,$$css:!0},"wrap-reverse":{kwnvtZ:`x8hhl5t`,$$css:!0}},vP={stack:{k1xSpc:`x78zum5`,$$css:!0}},yP={0:{k1C7PZ:`x1o57wo1`,khm7nJ:`x6yxi7o`,$$css:!0},1:{k1C7PZ:`x1lfs0n9`,khm7nJ:`x1ngg2t4`,$$css:!0},2:{k1C7PZ:`xak3so`,khm7nJ:`x1x7z4sm`,$$css:!0},3:{k1C7PZ:`xewh9hi`,khm7nJ:`x4olc9o`,$$css:!0},4:{k1C7PZ:`xty4p9g`,khm7nJ:`xtx9w7w`,$$css:!0},5:{k1C7PZ:`x1eqhezk`,khm7nJ:`x1iu6piu`,$$css:!0},6:{k1C7PZ:`x3qlgwd`,khm7nJ:`xczp1bk`,$$css:!0},8:{k1C7PZ:`xicv188`,khm7nJ:`xgx0vcf`,$$css:!0},10:{k1C7PZ:`x1p37tyl`,khm7nJ:`x1xpicb7`,$$css:!0},"0.5":{k1C7PZ:`x1kihgfc`,khm7nJ:`x1tw44j4`,$$css:!0},"1.5":{k1C7PZ:`x1thn6ci`,khm7nJ:`xhq53yo`,$$css:!0}};function bP({crossAlign:e,direction:t,gap:n,mainAlign:r,wrap:i}){return[vP.stack,gP[t],n!=null&&yP[n],e!=null&&mP[e],r!=null&&hP[r],i!=null&&_P[i]]}var xP={reset:{kAzted:`x2lwn1j`,k7Eaqz:`xeuugli`,$$css:!0}},SP={center:{kSGwAc:`xamitd3`,$$css:!0},end:{kSGwAc:`xpvyfi4`,$$css:!0},start:{kSGwAc:`xqcrz7y`,$$css:!0},stretch:{kSGwAc:`xkh2ocl`,$$css:!0}},CP={fill:{kzQI83:`x1iyjqo2`,$$css:!0},static:{kzQI83:`x1c4vz4f`,kmuXW:`x2lah0s`,$$css:!0}};function wP({crossAlignSelf:e,size:t}={}){return[xP.reset,CP[t??`static`],e!=null&&SP[e]]}var TP={layoutOuter:{keTefX:`xojxgvx`,k71WvV:`x1fcf3bl`,keoZOQ:`x1sa9bsh`,k1K539:`x6h7pi7`,$$css:!0},layoutInner:{"--container-padding-inline-start":`xrhngw9`,"--container-padding-inline-end":`xjsfl84`,"--container-padding-block-start":`x1047aw6`,"--container-padding-block-end":`xax9j7h`,$$css:!0},fill:{kZKoxP:`x12qplqi`,kskxy:`xenllk4`,$$css:!0},auto:{kAzted:`x1us19tq`,$$css:!0},middle:{kUk6DE:`x98rzlu`,kAzted:`x2lwn1j`,$$css:!0},fullBleed:{"--layout-padding-outer-x":`x1wbjvqu`,"--layout-padding-outer-y":`xzxxx64`,$$css:!0}},EP={kzqmXN:`xh8yej3`,kUOVxO:`xvueqy4`,$$css:!0},DP={contentWidthVar:e=>[{"--layout-content-width":(typeof e==`number`?`${e}px`:e)==null?typeof e==`number`?`${e}px`:e:`x4906uf`,$$css:!0},{"--x---layout-content-width":(typeof e==`number`?`${e}px`:e)==null?void 0:typeof e==`number`?`${e}px`:e}],contentWidth:e=>[EP,{ks0D6T:(typeof e==`number`?`${e}px`:e)==null?typeof e==`number`?`${e}px`:e:`xf68679`,$$css:!0},{"--x-maxWidth":(e=>typeof e==`number`?e+`px`:e??void 0)(typeof e==`number`?`${e}px`:e)}]};function OP({area:e,children:t}){return t==null?null:(0,K.jsx)(fP,{value:e,children:t})}var kP={"x-default-marker":`x-default-marker`,$$css:!0};function AP({children:e,content:t,contentWidth:n,defaultHasDividers:r,end:i,footer:a,header:o,height:s=`fill`,padding:c,ref:l,start:u,xstyle:d,className:f,style:p}){let m=s===`fill`,h=t??e,g=(0,_.useMemo)(()=>r==null?null:{defaultHasDividers:r},[r]),v=o!=null,y=a!=null,b=u!=null,x=i!=null,S=(0,_.useMemo)(()=>({hasHeader:v,hasFooter:y,hasStart:b,hasEnd:x}),[v,y,b,x]),C=(0,K.jsx)(pP,{value:S,children:(0,K.jsx)(`div`,{ref:l,...oa(ba(`layout`,{height:s}),Sr(TP.layoutOuter,m?TP.fill:TP.auto,d),f,p),children:(0,K.jsxs)(`div`,{...Sr(kP,TP.layoutInner,...bP({direction:`vertical`}),m?TP.fill:TP.auto,c===0&&TP.fullBleed,c!=null&&oi[c],c!=null&&si[c],n!=null&&DP.contentWidthVar(n)),children:[(0,K.jsx)(OP,{area:`header`,children:o}),(0,K.jsxs)(`div`,{...Sr(...bP({direction:`horizontal`}),TP.middle,n!=null&&DP.contentWidth(n)),children:[(0,K.jsx)(OP,{area:`start`,children:u}),(0,K.jsx)(`div`,{...Sr(...wP({size:`fill`})),children:(0,K.jsx)(OP,{area:`content`,children:h})}),(0,K.jsx)(OP,{area:`end`,children:i})]}),(0,K.jsx)(OP,{area:`footer`,children:a})]})})});return g==null?C:(0,K.jsx)(eM,{value:g,children:C})}AP.displayName=`Layout`;var jP={content:{kB7OPa:`x9f619`,kZKoxP:`x5yr21d`,kUk6DE:`x98rzlu`,kAzted:`x2lwn1j`,kVQacm:`x7giv3`,kZCmMZ:`xwjyata`,kwRFfy:`x1peupej`,kLKAdn:`xqty4a x1ioh5az`,kGO01o:`xg476vw xsg11nj`,"--container-padding-inline-start":`x408pgh`,"--container-padding-inline-end":`xikqloz`,"--container-padding-block-start":`xjmgx01`,"--container-padding-block-end":`xi9ns85`,$$css:!0},noStart:{kZCmMZ:`x139j0dd`,"--container-padding-inline-start":`xdvaxxn`,"--container-padding-inline-end":`xqpvj4r`,$$css:!0},noEnd:{kwRFfy:`xpc6k2p`,$$css:!0},noHeader:{kLKAdn:`x81pis9`,"--container-padding-block-start":`xzz8v79`,$$css:!0},noFooter:{kGO01o:`xon7vh3`,"--container-padding-block-end":`x1xjq73n`,$$css:!0},scrollable:{kVQacm:`xysyzu8`,$$css:!0},fullBleed:{kZCmMZ:`x1c1uobl`,kwRFfy:`xyri2b`,kLKAdn:`xexx8yu`,kGO01o:`x18d9i69`,"--container-padding-inline-start":`xrhngw9`,"--container-padding-inline-end":`xjsfl84`,"--container-padding-block-start":`x1047aw6`,"--container-padding-block-end":`xax9j7h`,$$css:!0}};function MP({children:e,isScrollable:t=!0,padding:n,label:r,role:i,xstyle:a,className:o,style:s,ref:c,...l}){let{hasHeader:u,hasFooter:d,hasStart:f,hasEnd:p}=(0,_.use)(pP),m=n===0;return(0,K.jsx)(`div`,{ref:c,role:i,"aria-label":r,...oa(ba(`layout-content`),Sr(jP.content,!f&&!m&&n==null&&jP.noStart,!p&&!m&&n==null&&jP.noEnd,!u&&!m&&n==null&&jP.noHeader,!d&&!m&&n==null&&jP.noFooter,t&&jP.scrollable,m&&jP.fullBleed,n!=null&&ni[n],n!=null&&ri[n],n!=null&&ii[n],n!=null&&ai[n],a),o,s),...l,children:e})}MP.displayName=`LayoutContent`;var NP={footer:{kmuXW:`x2lah0s`,$$css:!0},inner:{kB7OPa:`x9f619`,ks0D6T:`xjl2t3p`,kUOVxO:`xvueqy4`,kZCmMZ:`x139j0dd`,kwRFfy:`xpc6k2p`,kLKAdn:`xqty4a`,kGO01o:`xon7vh3`,"--container-padding-inline-start":`xdvaxxn`,"--container-padding-inline-end":`xqpvj4r`,"--container-padding-block-start":`xjmgx01`,"--container-padding-block-end":`x1xjq73n`,$$css:!0},fullBleed:{kZCmMZ:`x1c1uobl`,kwRFfy:`xyri2b`,kLKAdn:`xexx8yu`,kGO01o:`x18d9i69`,"--container-padding-inline-start":`xrhngw9`,"--container-padding-inline-end":`xjsfl84`,"--container-padding-block-start":`x1047aw6`,"--container-padding-block-end":`xax9j7h`,$$css:!0},divider:{kEafiO:`x178xt8z`,kPef9Z:`x13fuv20`,kLZC3w:`x1pc3f07`,$$css:!0}},PP={sizing:e=>[{kZKoxP:e==null?e:`x16ye13r`,$$css:!0},{"--x-height":(e=>typeof e==`number`?e+`px`:e??void 0)(e)}]};function FP({children:e,hasDivider:t,height:n,label:r,padding:i,role:a,xstyle:o,className:s,style:c,ref:l,...u}){let d=(0,_.use)(eM),f=t??d?.defaultHasDividers??!1,p=i===0;return(0,K.jsx)(`div`,{ref:l,role:a,"aria-label":r,"data-divider":f||void 0,...oa(ba(`layout-footer`),Sr(NP.footer,PP.sizing(n??null),f&&NP.divider,o),s,c),...u,children:(0,K.jsx)(`div`,{...Sr(NP.inner,p&&NP.fullBleed,i!=null&&ni[i],i!=null&&ri[i],i!=null&&ii[i],i!=null&&ai[i]),children:e})})}FP.displayName=`LayoutFooter`;var IP={scrollable:{kVQacm:`xysyzu8`,$$css:!0}};function LP({direction:e=`vertical`,hAlign:t,vAlign:n,justify:r,align:i,gap:a,padding:o,paddingInline:s,paddingInlineStart:c,paddingInlineEnd:l,paddingBlock:u,paddingBlockStart:d,paddingBlockEnd:f,isScrollable:p,width:m,height:h,maxWidth:g,minHeight:v,wrap:y,as:b=`div`,xstyle:x,className:S,style:C,children:w,ref:T,...E}){let D=t??(e===`horizontal`?r:i),O=n??(e===`horizontal`?i:r),k=e===`horizontal`?D:O,A=e===`horizontal`?O:D,j=c??s??o,M=l??s??o,N=d??u??o,P=f??u??o,F=Sr(...bP({direction:e,crossAlign:A,mainAlign:k,gap:a,wrap:y}),j!=null&&ci[j],M!=null&&li[M],N!=null&&ui[N],P!=null&&di[P],p&&IP.scrollable,x),I={...m!=null&&{width:typeof m==`number`?`${m}px`:m},...h!=null&&{height:typeof h==`number`?`${h}px`:h},...g!=null&&{maxWidth:typeof g==`number`?`${g}px`:g},...v!=null&&{minHeight:typeof v==`number`?`${v}px`:v}};return(0,_.createElement)(b,{ref:T,...oa(ba(`stack`,{direction:e,gap:a,wrap:y}),F,S,{...C,...I}),...E},w)}LP.displayName=`Stack`;function RP({ref:e,justify:t,align:n,hAlign:r,vAlign:i,...a}){return(0,K.jsx)(LP,{...a,direction:`horizontal`,hAlign:r??t,vAlign:i??n,ref:e})}RP.displayName=`HStack`;function zP({ref:e,justify:t,align:n,hAlign:r,vAlign:i,...a}){return(0,K.jsx)(LP,{...a,direction:`vertical`,hAlign:r??n,vAlign:i??t,ref:e})}zP.displayName=`VStack`;var BP=`(max-width: 640px)`,VP={action:{ks0D6T:`x193iq5w`,k7Eaqz:`xeuugli`,$$css:!0},stackedAction:{kzqmXN:`xh8yej3`,$$css:!0}};function HP({ref:e,isOpen:t,isInline:n,onOpenChange:r,title:i,description:a,cancelLabel:o,actionLabel:s,actionVariant:c=`destructive`,isActionLoading:l,onAction:u,width:d=400,xstyle:f,className:p,style:m,"data-testid":h,...g}){let v=Rc(),y=o??v(`@astryx.alertDialog.cancel`),b=(0,_.useId)(),x=(0,_.useId)(),S=Wl(BP),C=(0,_.useCallback)(()=>{r(!1)},[r]),w=[VP.action,S&&VP.stackedAction],T=(0,K.jsx)(qc,{variant:`ghost`,label:y,onClick:C,xstyle:w,"data-autofocus":!0},`cancel`),E=(0,K.jsx)(qc,{variant:c,label:s,onClick:u,isLoading:l,xstyle:w},`action`);return(0,K.jsx)($j,{...g,ref:e,isOpen:t,isInline:n,onOpenChange:r,width:d,purpose:`form`,role:n?`group`:`alertdialog`,"aria-labelledby":b,"aria-describedby":x,...oa(ba(`alert-dialog`),{className:p,style:m}),xstyle:f,"data-testid":h,children:(0,K.jsx)(AP,{content:(0,K.jsxs)(MP,{children:[(0,K.jsx)(rM,{level:2,id:b,children:i}),(0,K.jsx)(zo,{type:`body`,color:`secondary`,id:x,children:a})]}),footer:(0,K.jsx)(FP,{children:(0,K.jsx)(LP,{direction:S?`vertical`:`horizontal`,gap:2,hAlign:S?`stretch`:`end`,wrap:S?`nowrap`:`wrap`,children:S?[E,T]:[T,E]})})})})}HP.displayName=`AlertDialog`;var UP={x1iwu4tg:`x1iwu4tg`,$$css:!0},WP={sm:{kzqmXN:`x1td3qas`,kZKoxP:`x1qx5ct2`,$$css:!0},md:{kzqmXN:`x100vrsf`,kZKoxP:`xxk0z11`,$$css:!0}},GP={sm:{kzqmXN:`x1td3qas`,kZKoxP:`x1qx5ct2`,$$css:!0},md:{kzqmXN:`x100vrsf`,kZKoxP:`xxk0z11`,$$css:!0}},KP={sm:{kzqmXN:`x1td3qas`,kZKoxP:`x1qx5ct2`,kmVPX3:`x1i3ajwb`,$$css:!0},md:{kzqmXN:`x100vrsf`,kZKoxP:`xxk0z11`,kmVPX3:`xfawy5m`,$$css:!0}},qP={sm:{kzqmXN:`x6jxa94`,kZKoxP:`x1v9usgg`,k3aq6I:`xbryuvx`,$$css:!0},md:{kzqmXN:`x1kky2od`,kZKoxP:`xlup9mm`,k3aq6I:`xbryuvx`,$$css:!0}},JP={sm:{kzqmXN:`x1kky2od`,kZKoxP:`xlup9mm`,k3aq6I:`xv5t66b xi9aj42`,$$css:!0},md:{kzqmXN:`xw4jnvo`,kZKoxP:`x1qx5ct2`,k3aq6I:`x15481yp x12xz5k6`,$$css:!0}},YP={sm:{kAzted:`xisnujt`,$$css:!0},md:{kAzted:`xjwf9q1`,$$css:!0}},XP={container:{k1xSpc:`x78zum5`,kGNEyG:`x6s0dn4`,kOIVth:`x1txdalj`,$$css:!0},containerLabelHidden:{kOIVth:`xxhr3t`,$$css:!0},containerSpread:{kjj79g:`x1qughib`,kzqmXN:`xh8yej3`,$$css:!0},statusGap:{keoZOQ:`xtbrsbv`,$$css:!0},switchWrapper:{kVAEAm:`x1n2onr6`,k1xSpc:`x78zum5`,kGNEyG:`x6s0dn4`,kmuXW:`x2lah0s`,kHBbk8:`xc8icb0`,$$css:!0},input:{kVAEAm:`x10l6tqk`,kogj98:`x1ghz6dp`,kmVPX3:`x1717udv`,kSiTet:`xg01cxk`,kkrTdU:`x1ypdohk x16khyan`,kY2c9j:`x1vjfegm`,k7Eaqz:`xkagaj0`,kAzted:`x80b3aj`,k87sOh:`xijlfn0`,kLqNvP:`x1hsn8va`,k3aq6I:`x8i4i9p`,$$css:!0},inputDisabled:{kkrTdU:`xt0e3qv`,$$css:!0},inputBusy:{kfzvcC:`x47corl`,$$css:!0},track:{k1xSpc:`x78zum5`,kGNEyG:`x6s0dn4`,kaIpWk:`xjspbzw`,k1ekBW:`x15406qy`,kIyJzY:`xuedmi6 x12w9bfk`,kAMwcw:`xlr8y92`,kB7OPa:`x9f619`,kMzoRj:`xc342km x13rsnn2`,ksu8eU:`xng3xce xx61lck`,kVAM5u:`x1w1tqly`,$$css:!0},trackFocus:{kI3sdo:`x1a2a7pz xafswnp`,kInvED:`xwz5zln`,$$css:!0},trackOff:{kWkggS:`xspzpui x1a8ae7b x9yvj25`,$$css:!0},trackOn:{kWkggS:`x1ewilqj xcgwt1n x1jzqe4`,$$css:!0},trackDisabled:{kSiTet:`xbyyjgo`,kVAM5u:`xmnqt3w`,$$css:!0},trackDisabledOff:{kWkggS:`xspzpui`,$$css:!0},thumb:{k1xSpc:`x78zum5`,kGNEyG:`x6s0dn4`,kjj79g:`xl56j7k`,kaIpWk:`xjspbzw`,k1ekBW:`xh3q6i0`,kIyJzY:`xuedmi6 x12w9bfk`,kAMwcw:`xlr8y92`,$$css:!0},thumbOff:{kWkggS:`x10xzikg xwvh9j7`,$$css:!0},thumbOn:{kWkggS:`x10xzikg x1sir5s4`,$$css:!0},labelWrapper:{k1xSpc:`x78zum5`,kXwgrk:`xdt5ytf`,kOIVth:`x1lsbc85`,kjj79g:`xl56j7k`,$$css:!0}},ZP={width:e=>[{kzqmXN:e==null?e:`x5lhr3w`,$$css:!0},{"--x-width":(e=>typeof e==`number`?e+`px`:e??void 0)(e)}]};function QP({label:e,isLabelHidden:t=!1,description:n,onChange:r,changeAction:i,isLoading:a=!1,value:o,isDisabled:s=!1,htmlName:c,disabledMessage:l,isOptional:u=!1,isRequired:d=!1,onFocus:f,onBlur:p,labelIcon:m,labelTooltip:h,labelPosition:g=`end`,labelSpacing:v=`hug`,status:y,size:b=`md`,width:x,xstyle:S,className:C,style:w,ref:T,...E}){let D=(0,_.useId)(),O=(0,_.useId)(),k=(0,_.useId)(),A=HM({isRequired:d,isOptional:u}),[,j]=(0,_.useTransition)(),[M,N]=(0,_.useOptimistic)(o),P=a||M!==o,F=M===!0,I=s&&!!l,L=po({placement:`above`,focusTrigger:`always`,isEnabled:I}),R=[];n&&R.push(O),y?.message&&R.push(k),I&&R.push(L.describedBy);let z=R.length>0?R.join(` `):void 0,B=(0,K.jsxs)(`div`,{...Sr(XP.switchWrapper,WP[b]),children:[(0,K.jsx)(`input`,{ref:Ao(T,L.positionRef),id:D,type:`checkbox`,role:`switch`,name:s?void 0:c,checked:F,disabled:s&&!I,"aria-disabled":I?`true`:void 0,form:I?``:void 0,required:d,"aria-required":A?`true`:void 0,onChange:e=>{if(s||P)return;let t=e.target.checked;r?.(t,e),i&&!e.defaultPrevented&&j(async()=>{N(t),await i(t,e)})},onFocus:f,onBlur:p,"aria-describedby":z,"aria-invalid":y?.type===`error`||void 0,"aria-busy":P||void 0,...Sr(XP.input,GP[b],s&&XP.inputDisabled,P&&XP.inputBusy)}),(0,K.jsx)(`div`,{"aria-hidden":`true`,...oa(ba(`switch`,{checked:F?`checked`:null,disabled:s?`disabled`:null,size:b}),Sr(XP.track,KP[b],F?XP.trackOn:XP.trackOff,!s&&XP.trackFocus,s&&XP.trackDisabled,s&&!F&&XP.trackDisabledOff)),children:(0,K.jsx)(`div`,{...oa(ba(`switch-thumb`,{checked:F?`checked`:null,size:b}),Sr(XP.thumb,F?JP[b]:qP[b],F?XP.thumbOn:XP.thumbOff)),children:P&&(0,K.jsx)($o,{size:`sm`})})}),P&&(0,K.jsx)(es,{role:`status`,children:`Loading`})]}),V=(0,K.jsx)(`div`,{...Sr(XP.labelWrapper,YP[b]),children:(0,K.jsx)(TM,{...ba(`switch-label`),label:e,inputID:D,isLabelHidden:t,isDisabled:s,isOptional:u,isRequired:d,labelIcon:m,labelTooltip:h,description:n,descriptionID:O})});return(0,K.jsxs)(`div`,{...oa(ba(`switch-field`,{labelPosition:g===`end`?void 0:g,labelSpacing:v===`hug`?void 0:v}),Sr(x!=null&&ZP.width(x),S),C,w),...E,children:[(0,K.jsxs)(`div`,{ref:e=>{L.interactionRef(e)},...Sr(XP.container,t&&XP.containerLabelHidden,v===`spread`&&XP.containerSpread,!s&&UP),children:[` `,g===`start`?(0,K.jsxs)(K.Fragment,{children:[V,B]}):(0,K.jsxs)(K.Fragment,{children:[B,V]})]}),y?.message&&(0,K.jsx)(kM,{type:y.type,message:y.message,id:k,variant:`detached`,xstyle:XP.statusGap}),I&&L.renderTooltip(l)]})}QP.displayName=`Switch`;var $P=[`chrome`,`edge`,`brave`,`chromium`,`safari`,`firefox`],eF=[`embedded`,...$P],tF=e=>$P.some(t=>t===e);function nF(){let[e,t]=(0,_.useState)(),n=(0,_.useRef)(void 0),r=(0,_.useRef)(!1),i=(0,_.useRef)(!0),a=(0,_.useRef)(void 0),o=(0,_.useCallback)(()=>{a.current?.(),a.current=void 0,n.current?.close(),n.current=void 0,i.current&&t(void 0)},[]);return(0,_.useEffect)(()=>(i.current=!0,window.addEventListener(`pagehide`,o),()=>{i.current=!1,window.removeEventListener(`pagehide`,o),o()}),[o]),{container:e,open:async()=>{if(n.current&&!n.current.closed)return n.current.focus(),!0;if(r.current)return!1;r.current=!0;try{let e=window.documentPictureInPicture,r=e?await e.requestWindow({width:460,height:740}):window.open(`about:blank`,`_blank`,`popup,width=460,height=740`);if(!r)return!1;if(!i.current)return r.close(),!1;n.current=r,r.document.title=`OpenPI Browser Bridge`;let o=()=>{r.document.documentElement.lang=document.documentElement.lang,r.document.documentElement.dataset.theme=document.documentElement.dataset.theme,r.document.documentElement.style.cssText=document.documentElement.style.cssText};o(),r.document.documentElement.classList.add(`browser-guide-window`);for(let e of document.styleSheets)try{let t=r.document.createElement(`style`);t.textContent=[...e.cssRules].map(e=>e.cssText).join(` `),r.document.head.append(t)}catch{if(!e.href)continue;let t=r.document.createElement(`link`);t.rel=`stylesheet`,t.href=e.href,r.document.head.append(t)}let s=r.document.createElement(`main`);s.className=`browser-settings browser-settings-detached`,r.document.body.append(s);let c=new MutationObserver(o);c.observe(document.documentElement,{attributes:!0,attributeFilter:[`data-theme`,`style`,`lang`]});let l=()=>{c.disconnect(),n.current===r&&(n.current=void 0,a.current=void 0,i.current&&t(void 0))};return r.addEventListener(`pagehide`,l,{once:!0}),a.current=()=>{c.disconnect(),r.removeEventListener(`pagehide`,l)},t(s),!0}catch{return o(),!1}finally{r.current=!1}},close:o,isOpen:()=>!!(n.current&&!n.current.closed)}}var rF={chrome:`Chrome`,edge:`Microsoft Edge`,brave:`Brave`,chromium:`Chromium`,safari:`Safari`,firefox:`Firefox`};function iF({browser:e}){return(0,K.jsx)(`span`,{className:`browser-settings-mark ${e}`,"aria-hidden":`true`,children:e===`chrome`||e===`chromium`?(0,K.jsx)(`i`,{}):(0,K.jsx)(pe,{})})}function aF({onConfigure:e,setupPending:t=!1}){let{t:n}=cr(),r=nF(),i=(0,_.useRef)(r.isOpen);i.current=r.isOpen;let[a,o]=(0,_.useState)(),[s,c]=(0,_.useState)(),[l,u]=(0,_.useState)(!1),d=l||t,[f,p]=(0,_.useState)(!1),[m,h]=(0,_.useState)(),[g,v]=(0,_.useState)(`chrome`),[y,b]=(0,_.useState)(1),[x,S]=(0,_.useState)(!1),[C,w]=(0,_.useState)(),D=(0,_.useRef)(0),O=(0,_.useRef)(null),k=(0,_.useRef)(null),A=(0,_.useRef)(!0);(0,_.useEffect)(()=>{m&&(O.current?.scrollIntoView?.({block:`nearest`}),k.current?.focus({preventScroll:!0}))},[m,y,r.container]);let j=(0,_.useCallback)(async()=>{let e=++D.current;try{let t=await new rf().request(`/api/settings/browser`);return A.current&&e===D.current&&(o(t),c(void 0)),t}catch(t){A.current&&e===D.current&&c(t instanceof Error?t.message:String(t));return}},[]);(0,_.useEffect)(()=>{A.current=!0,j();let e=setInterval(()=>{(document.visibilityState===`visible`||i.current())&&j()},3e3),t=()=>void j();return window.addEventListener(`focus`,t),()=>{A.current=!1,clearInterval(e),window.removeEventListener(`focus`,t)}},[j]);let M=async t=>{u(!0),c(void 0),w(void 0),++D.current;try{let r=await e(`Configure browser access: ${[t.control===void 0?void 0:`browser_control=${t.control}`,t.embedded===void 0?void 0:`browser_embedded=${t.embedded}`,t.defaultBrowser===void 0?void 0:`browser_default=${JSON.stringify(t.defaultBrowser)}`,t.externalBrowsers===void 0?void 0:`browser_external=${JSON.stringify(t.externalBrowsers)}`].filter(e=>e!==void 0).join(`, `)}. Preserve all other settings.`);if(!A.current)return;if(!r)throw Error(n(`setupRequestFailed`));w(n(`setupRequestAccepted`))}catch(e){await j(),A.current&&c(e instanceof Error?e.message:String(e))}finally{A.current&&u(!1)}},N=async(e,t)=>{u(!0),c(void 0),w(void 0);try{if(await new rf().request(`/api/settings/browser/action`,{method:`POST`,body:JSON.stringify({browser:e,action:t})}),A.current)return t===`folder`&&w(n(`browserFolderOpened`)),!0}catch(e){A.current&&c(e instanceof Error?e.message:String(e))}finally{A.current&&u(!1)}return!1},P=e=>e===`embedded`?n(`browserEmbedded`):rF[e];if(!a)return(0,K.jsxs)(`div`,{className:`browser-settings-load`,role:s?`alert`:`status`,children:[(0,K.jsx)(pe,{}),(0,K.jsx)(`p`,{children:s||n(`browserLoading`)}),s&&(0,K.jsx)(`button`,{type:`button`,onClick:()=>void j(),children:n(`browserCheck`)})]});let{config:F}=a,R=a.profiles.find(e=>e.current&&e.connected&&e.version===a.extensionVersion),B=e=>a.profiles.filter(t=>t.connected&&t.version===a.extensionVersion&&(e===`embedded`?t.current&&![`safari`,`firefox`].includes(t.browser):t.browser===e)),V=e=>e===`embedded`?F.embedded:F.externalBrowsers.includes(e),H=(e,t)=>e===`embedded`?{embedded:t}:{externalBrowsers:t?[...new Set([...F.externalBrowsers,e])]:F.externalBrowsers.filter(t=>t!==e)},ee=e=>{h(e),b(1),w(void 0),S(!1),v(e===`embedded`?R&&![`safari`,`firefox`].includes(R.browser)?R.browser:`chrome`:e)},ne=e=>{let t=B(e).length>0,r=e===`embedded`||a.browsers.some(t=>t.id===e&&t.installed),i=a.profiles.some(t=>t.connected&&t.version!==a.extensionVersion&&(e===`embedded`?t.current&&![`safari`,`firefox`].includes(t.browser):t.browser===e));return(0,K.jsxs)(`div`,{className:`browser-settings-row`,children:[(0,K.jsx)(iF,{browser:e}),(0,K.jsxs)(`div`,{className:`browser-settings-description`,children:[(0,K.jsx)(`strong`,{children:P(e)}),(0,K.jsx)(`span`,{className:t?`connected`:``,children:t?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`i`,{}),n(`browserConnected`)]}):n(i?`browserUpdateNeeded`:r?`browserNeedsSetup`:`browserNotFound`)})]}),(0,K.jsx)(`button`,{className:`browser-settings-button`,type:`button`,disabled:l,"aria-label":n(t?`browserManageNamed`:`browserSetupNamed`,{browser:P(e)}),onClick:()=>ee(e),children:n(t?`browserManage`:`browserSetUp`)}),(0,K.jsx)(QP,{label:n(`browserAllowNamed`,{browser:P(e)}),isLabelHidden:!0,size:`sm`,value:V(e),isDisabled:d,onChange:t=>void M(H(e,t))})]},e)},re=m!==void 0&&B(m).length>0,ie=a.browsers.some(e=>e.id===g&&e.installed),ae=g===`safari`||g===`firefox`,U=ae?a.portableExtensionPath??a.extensionPath:a.extensionPath,oe=g===`firefox`?`${U.replace(/[\\/]+$/,``)}/manifest.json`:U,se=g===`safari`?n(`browserSafariSettings`):g===`firefox`?`about:debugging#/runtime/this-firefox`:`${g===`edge`?`edge`:g===`brave`?`brave`:`chrome`}://extensions/`,ce=n(g===`safari`?`browserSafariDeveloper`:g===`firefox`?`browserFirefoxThis`:`browserDeveloperMode`),le=n(g===`safari`?`browserSafariTemporary`:g===`firefox`?`browserFirefoxTemporary`:`browserLoadUnpacked`),de=[n(`browserStepOpen`),ce,n(`browserStepAdd`),n(`browserStepConnect`)];return(0,K.jsxs)(`div`,{className:`browser-settings`,children:[(0,K.jsxs)(`header`,{className:`browser-settings-heading`,children:[(0,K.jsx)(`h2`,{children:n(`browserSettings`)}),(0,K.jsx)(`p`,{children:n(`browserSettingsIntro`)})]}),(0,K.jsxs)(`div`,{className:`browser-settings-card browser-settings-main-card`,children:[(0,K.jsxs)(`div`,{className:`browser-settings-control`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`strong`,{children:n(`browserControl`)}),(0,K.jsx)(`p`,{children:n(`browserControlHint`)})]}),(0,K.jsx)(QP,{label:n(`browserControl`),isLabelHidden:!0,size:`sm`,value:F.control,isDisabled:d,onChange:e=>void M({control:e})})]}),(0,K.jsxs)(`div`,{className:`browser-settings-default`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{htmlFor:`browser-default`,children:n(`browserDefault`)}),(0,K.jsx)(`p`,{children:n(`browserDefaultHint`)})]}),(0,K.jsx)(`select`,{id:`browser-default`,value:F.defaultBrowser,disabled:d,onChange:e=>void M({defaultBrowser:e.target.value}),children:eF.map(e=>(0,K.jsxs)(`option`,{value:e,disabled:!V(e),children:[P(e),V(e)?``:` · ${n(`browserBlocked`)}`]},e))})]})]}),!V(F.defaultBrowser)&&(0,K.jsx)(`p`,{className:`browser-settings-warning`,role:`status`,children:n(`browserDefaultBlocked`)}),(0,K.jsxs)(`div`,{className:`browser-settings-section-heading`,children:[(0,K.jsx)(`h3`,{children:n(`browserAllowedTitle`)}),(0,K.jsx)(`span`,{children:!F.control&&n(`browserOffHint`)})]}),(0,K.jsxs)(`div`,{className:`browser-settings-card`,children:[ne(`embedded`),ne(`chrome`),(0,K.jsxs)(`details`,{className:`browser-settings-more`,children:[(0,K.jsxs)(`summary`,{children:[(0,K.jsx)(z,{}),n(`browserMore`)]}),$P.filter(e=>e!==`chrome`).map(ne)]})]}),(0,K.jsx)(`p`,{className:`browser-settings-example`,children:n(`browserSpeakHint`)}),r.container&&(0,K.jsxs)(`div`,{className:`browser-settings-guide-placeholder`,role:`status`,children:[(0,K.jsx)(`p`,{children:n(`browserGuideDetached`)}),(0,K.jsx)(`button`,{type:`button`,className:`browser-settings-button`,onClick:()=>void r.open(),children:n(`browserShowGuide`)}),(0,K.jsx)(`button`,{type:`button`,className:`browser-settings-text-button`,onClick:r.close,children:n(`browserGuideInline`)})]}),m!==void 0&&(e=>r.container?(0,Rt.createPortal)(e,r.container):e)((0,K.jsxs)(`section`,{ref:O,className:`browser-settings-guide`,"aria-label":n(`browserGuideTitle`,{browser:P(m)}),children:[(0,K.jsxs)(`div`,{className:`browser-settings-guide-heading`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`span`,{children:n(re?`browserConnectionTitle`:`browserGuideEyebrow`)}),(0,K.jsx)(`h3`,{children:n(`browserGuideTitle`,{browser:P(m)})})]}),(0,K.jsx)(`button`,{type:`button`,className:`icon-button`,disabled:l,"aria-label":n(`browserCloseGuide`),onClick:()=>{r.close(),h(void 0)},children:(0,K.jsx)(Lt,{})})]}),!r.container&&!re&&(0,K.jsxs)(`button`,{type:`button`,className:`browser-settings-text-button`,onClick:async()=>{await r.open()||w(n(`browserGuideBlocked`))},children:[(0,K.jsx)(he,{}),n(`browserGuidePopout`)]}),re?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsxs)(`p`,{className:`browser-settings-ready`,children:[(0,K.jsx)(te,{}),n(`browserConnectionReady`)]}),(0,K.jsx)(`p`,{children:m===`embedded`?n(`browserEmbeddedDetail`):n(`browserExternalDetail`,{browser:P(m)})}),(0,K.jsxs)(`div`,{className:`browser-settings-guide-actions`,children:[(0,K.jsxs)(`button`,{type:`button`,className:`browser-settings-button`,disabled:l,onClick:()=>void N(m===`embedded`?R.browser:m,`manage`),children:[n(`browserManageExtension`),(0,K.jsx)(he,{})]}),(!V(m)||!F.control)&&(0,K.jsx)(`button`,{type:`button`,className:`browser-settings-primary`,disabled:d,onClick:()=>void M({control:!0,...H(m,!0)}),children:n(`browserAllowUse`)}),V(m)&&F.defaultBrowser!==m&&(0,K.jsx)(`button`,{type:`button`,className:`browser-settings-button`,disabled:d,onClick:()=>void M({defaultBrowser:m}),children:n(`browserMakeDefault`)})]})]}):(0,K.jsxs)(K.Fragment,{children:[m===`embedded`&&(0,K.jsxs)(`label`,{className:`browser-settings-install-browser`,children:[n(`browserInstallIn`),(0,K.jsx)(`select`,{value:g,disabled:l,onChange:e=>{v(e.target.value),b(1),S(!1),w(void 0)},children:$P.filter(e=>![`safari`,`firefox`].includes(e)).map(e=>(0,K.jsx)(`option`,{value:e,children:rF[e]},e))})]}),(0,K.jsx)(`ol`,{className:`browser-settings-progress`,"aria-label":n(`browserSetupSteps`),children:de.map((e,t)=>(0,K.jsx)(`li`,{children:(0,K.jsxs)(`button`,{type:`button`,"aria-current":y===t+1?`step`:void 0,"aria-label":n(`browserStepLabel`,{step:t+1,label:e}),disabled:l,onClick:()=>{b(t+1),w(void 0)},children:[(0,K.jsx)(`span`,{children:t+1}),e]})},e))}),(0,K.jsxs)(`div`,{className:`browser-settings-wizard`,"aria-live":`polite`,children:[(0,K.jsx)(`span`,{className:`browser-settings-step-count`,children:n(`browserStepCount`,{step:y,total:de.length})}),(0,K.jsx)(`h4`,{ref:k,tabIndex:-1,children:n(y===1?`browserOpenManagerTitle`:y===2?g===`safari`?`browserSafariDeveloperTitle`:g===`firefox`?`browserFirefoxDeveloperTitle`:`browserDeveloperTitle`:y===3?`browserInstallTitle`:`browserConnectTitle`,{browser:rF[g]})}),(0,K.jsx)(`p`,{children:n(y===1?g===`safari`?`browserSafariOpenHint`:`browserOpenManagerHint`:y===2?g===`safari`?`browserSafariDeveloperHint`:g===`firefox`?`browserFirefoxDeveloperHint`:`browserDeveloperHint`:y===3?g===`safari`?`browserSafariLoadHint`:g===`firefox`?`browserFirefoxLoadHint`:`browserLoadHint`:`browserConnectHint`,{browser:rF[g]})}),y===1&&(0,K.jsxs)(`div`,{className:`browser-settings-address`,children:[(0,K.jsx)(iF,{browser:g}),(0,K.jsx)(`code`,{children:se})]}),(y===2||y===3)&&(0,K.jsxs)(`figure`,{className:`browser-settings-illustration ${g}`,children:[(0,K.jsx)(`figcaption`,{children:n(`browserIllustration`,{browser:rF[g]})}),(0,K.jsxs)(`div`,{className:`browser-settings-demo`,"aria-hidden":`true`,children:[(0,K.jsxs)(`div`,{className:`browser-settings-demo-bar`,children:[(0,K.jsx)(`i`,{}),(0,K.jsx)(`i`,{}),(0,K.jsx)(`i`,{}),(0,K.jsx)(`code`,{children:se})]}),(0,K.jsxs)(`div`,{className:`browser-settings-demo-heading`,children:[(0,K.jsx)(`span`,{children:n(`browserExtensions`)}),(0,K.jsxs)(`span`,{className:`browser-settings-demo-toggle ${y===2?`highlight`:``}`,children:[y===2&&(0,K.jsx)(`b`,{className:`browser-settings-target-number`,children:`2`}),ce,g!==`firefox`&&(0,K.jsx)(`i`,{})]})]}),(0,K.jsxs)(`div`,{className:`browser-settings-demo-toolbar`,children:[(0,K.jsxs)(`span`,{className:y===3?`highlight`:``,children:[y===3&&(0,K.jsx)(`b`,{className:`browser-settings-target-number`,children:`3`}),le]}),(0,K.jsx)(`i`,{}),(0,K.jsx)(`i`,{})]})]})]}),y===3&&(0,K.jsxs)(`div`,{className:`browser-settings-folder`,children:[(0,K.jsxs)(`div`,{className:`browser-settings-folder-heading`,children:[(0,K.jsx)(G,{}),(0,K.jsx)(`strong`,{children:ae?`browser-extension-portable`:`browser-extension`}),(0,K.jsx)(`span`,{children:n(`browserFolderBundled`)})]}),(0,K.jsx)(`div`,{className:`browser-settings-path`,children:(0,K.jsx)(`code`,{children:oe})}),(0,K.jsxs)(`div`,{className:`browser-settings-guide-actions`,children:[(0,K.jsxs)(`button`,{type:`button`,className:`browser-settings-button`,onClick:async e=>{let t=await wd(oe,e.currentTarget.ownerDocument);S(t),t||w(n(`browserCopyFailed`))},children:[x?(0,K.jsx)(I,{}):(0,K.jsx)(ue,{}),n(x?`browserPathCopied`:`browserCopyPath`)]}),(0,K.jsxs)(`button`,{type:`button`,className:`browser-settings-button`,disabled:l,onClick:()=>void N(g,`folder`),children:[(0,K.jsx)(G,{}),n(`browserOpenFolder`)]})]}),(0,K.jsx)(`p`,{children:n(navigator.userAgent.includes(`Mac`)?`browserChooseFolderMac`:`browserChooseFolderOther`)})]}),y===4&&(0,K.jsxs)(`div`,{className:`browser-settings-waiting`,role:`status`,children:[(0,K.jsx)(dt,{}),(0,K.jsx)(`span`,{children:n(`browserWaiting`)})]}),!ie&&(0,K.jsx)(`p`,{className:`browser-settings-warning`,children:n(`browserInstallBrowserFirst`,{browser:rF[g]})}),(0,K.jsxs)(`div`,{className:`browser-settings-wizard-actions`,children:[y>1&&(0,K.jsxs)(`button`,{type:`button`,className:`browser-settings-button`,disabled:l,onClick:()=>{b(y-1),w(void 0)},children:[(0,K.jsx)(T,{}),n(`browserPreviousStep`)]}),y===1&&(0,K.jsx)(`button`,{type:`button`,className:`browser-settings-text-button`,disabled:l,onClick:()=>b(4),children:n(`browserAlreadyInstalled`)}),y<4?(0,K.jsxs)(`button`,{type:`button`,className:`browser-settings-primary`,disabled:l||!ie,onClick:async()=>{y===1&&!r.isOpen()&&(await r.open()||w(n(`browserGuideBlocked`))),(y===2||await N(g,y===1?`manage`:`connect`))&&b(y+1)},children:[n(y===1?`browserOpenManager`:y===2?g===`firefox`?`browserFirefoxDone`:`browserDeveloperDone`:`browserInstalledConnect`,{browser:rF[g]}),y===2?(0,K.jsx)(E,{}):(0,K.jsx)(he,{})]}):(0,K.jsxs)(`button`,{type:`button`,className:`browser-settings-primary`,disabled:l||f,onClick:async()=>{p(!0);let e=await j();if(A.current){p(!1);let t=e?.profiles.some(t=>t.connected&&t.version===e.extensionVersion&&(m===`embedded`?t.current&&![`safari`,`firefox`].includes(t.browser):t.browser===m));w(n(t?`browserConnectionReady`:`browserNotConnectedYet`))}},children:[(0,K.jsx)(dt,{className:f?`settings-spin`:``}),n(`browserCheck`)]})]}),y===4?(0,K.jsxs)(`div`,{className:`browser-settings-connect-help`,children:[(0,K.jsx)(`p`,{children:n(`browserAllowHint`)}),(0,K.jsxs)(`button`,{type:`button`,className:`browser-settings-text-button`,disabled:l||!ie,onClick:()=>void N(g,`connect`),children:[n(`browserOpenIn`,{browser:rF[g]}),(0,K.jsx)(he,{})]})]}):y>1&&(0,K.jsxs)(`button`,{type:`button`,className:`browser-settings-text-button`,disabled:l||!ie,onClick:()=>void N(g,`manage`),children:[n(`browserReopenManager`),(0,K.jsx)(he,{})]})]})]}),(0,K.jsxs)(`details`,{className:`browser-settings-help`,children:[(0,K.jsxs)(`summary`,{children:[(0,K.jsx)(L,{}),n(`browserHelp`)]}),(0,K.jsx)(`p`,{children:n(`browserReloadHint`)}),(0,K.jsx)(`p`,{children:n(`browserSupportedHint`)})]}),s&&(0,K.jsx)(`div`,{className:`browser-settings-error`,role:`alert`,children:s}),(0,K.jsx)(`div`,{className:`browser-settings-feedback`,role:`status`,"aria-live":`polite`,children:l?n(`browserSaving`):C})]})),!m&&s&&(0,K.jsxs)(`div`,{className:`browser-settings-error`,role:`alert`,children:[s,(0,K.jsx)(`button`,{type:`button`,onClick:()=>void j(),children:n(`browserCheck`)})]}),(0,K.jsx)(`div`,{className:`browser-settings-feedback`,role:`status`,"aria-live":`polite`,children:!m&&(l?n(`browserSaving`):C)})]})}function oF({label:e,value:t,options:n,disabled:r,onChange:i}){return(0,K.jsx)(jA,{button:{label:n.find(e=>e.value===t)?.label??t,"aria-label":e,variant:`secondary`,size:`sm`,className:`configuration-menu-trigger`,isDisabled:r},className:`configuration-menu`,menuWidth:`min(360px, calc(100vw - 32px))`,alignment:`end`,items:n.map(e=>({id:e.value,label:e.label,isDisabled:r,description:e.description?(0,K.jsx)(`span`,{className:`configuration-option-description`,children:e.description}):void 0,endContent:t===e.value?(0,K.jsx)(I,{"aria-hidden":`true`}):void 0,onClick:()=>{e.value!==t&&i(e.value)}}))})}function sF({catalog:e,error:t,pending:n,preferencePending:r,onConfigure:i,onUpdatePreferences:a,onRefresh:o,onOpenRuntimeStatus:s}){let{t:c}=cr(),l=e?.setupWritable===!1||!!e?.resources.diagnostics.settingsErrors,u=n||r||!!t||!!e?.resources.diagnostics.settingsErrors,d=e?.setup.ui.webHiddenThinkingLevels??[],f=(e?.thinking?.available??[]).filter(e=>[`off`,`minimal`,`low`,`medium`,`high`,`xhigh`,`max`].includes(e)),p=e?.setup.response?.verbosity??`default`,m=e?.setup.response?.reasoningSummary??`default`;return(0,K.jsxs)(`section`,{className:`settings-configuration-panel`,children:[(0,K.jsxs)(`header`,{className:`settings-page-heading`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`h1`,{children:c(`configurationSettings`)}),(0,K.jsx)(`p`,{children:c(`configurationIntro`)})]}),(0,K.jsx)(`button`,{type:`button`,"aria-label":c(`refreshStatus`),onClick:o,children:(0,K.jsx)(dt,{"aria-hidden":`true`})})]}),t&&(0,K.jsx)(`p`,{className:`inspection-warning`,role:`alert`,children:t}),!e&&!t&&(0,K.jsx)(`p`,{role:`status`,children:c(`settingsCatalogLoading`)}),l&&(0,K.jsxs)(`p`,{className:`inspection-warning`,role:`alert`,children:[c(`configurationReadFailure`),e?.setupDiagnostics?.map(e=>(0,K.jsxs)(`span`,{children:[e.path,`: `,e.message]},`${e.path}:${e.message}`))]}),e&&!l&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsxs)(`div`,{className:`configuration-scope`,children:[(0,K.jsxs)(`span`,{className:`configuration-scope-label`,children:[(0,K.jsx)(Nt,{"aria-hidden":`true`}),c(`configurationUserScope`)]}),(0,K.jsx)(`span`,{children:c(`configurationSetupHint`)})]}),(0,K.jsxs)(`div`,{className:`configuration-group`,children:[(0,K.jsxs)(`div`,{className:`configuration-row`,children:[(0,K.jsxs)(`div`,{className:`configuration-copy`,children:[(0,K.jsx)(`strong`,{children:c(`configurationApproval`)}),(0,K.jsx)(`p`,{children:c(`configurationApprovalDetail`)})]}),(0,K.jsx)(`span`,{className:`configuration-readonly`,children:c(`configurationPiPermissions`)})]}),(0,K.jsxs)(`div`,{className:`configuration-row`,children:[(0,K.jsxs)(`div`,{className:`configuration-copy`,children:[(0,K.jsx)(`strong`,{children:c(`configurationSandbox`)}),(0,K.jsx)(`p`,{children:c(`configurationSandboxDetail`)})]}),(0,K.jsx)(`span`,{className:`configuration-readonly`,children:c(`configurationSandboxUnavailable`)})]}),(0,K.jsxs)(`div`,{className:`configuration-row`,children:[(0,K.jsxs)(`div`,{className:`configuration-copy`,children:[(0,K.jsx)(`strong`,{children:c(`webSearchSettings`)}),(0,K.jsx)(`p`,{children:c(`configurationSearchDetail`)}),e.webSearch?.available!==!0&&(0,K.jsx)(`p`,{children:c(`webSearchUnsupported`)})]}),(0,K.jsx)(`div`,{className:`configuration-control`,children:(0,K.jsx)(oF,{label:c(`webSearchSettings`),value:e.setup.webSearch?.enabled===!0?`on`:`off`,options:[{value:`off`,label:c(`disabled`),description:c(`configurationSearchOff`)},{value:`on`,label:c(`enabled`),description:c(`configurationSearchOn`)}],disabled:u,onChange:e=>{i(c(e===`on`?`webSearchNativeRequest`:`webSearchDisableRequest`))}})})]}),(0,K.jsxs)(`div`,{className:`configuration-row`,children:[(0,K.jsxs)(`div`,{className:`configuration-copy`,children:[(0,K.jsx)(`strong`,{children:c(`configurationVerbosity`)}),(0,K.jsx)(`p`,{children:c(`configurationVerbosityDetail`)}),e.responseSupport?.verbosity!==!0&&(0,K.jsx)(`p`,{children:c(`configurationResponsesUnavailable`)})]}),(0,K.jsx)(`div`,{className:`configuration-control`,children:(0,K.jsx)(oF,{label:c(`configurationVerbosity`),value:p,options:[`default`,`low`,`medium`,`high`].map(e=>({value:e,label:c(`configurationVerbosity_${e}`),description:e==="default"?void 0:c(`configurationVerbosityHelp_${e}`)})),disabled:u||e.responseSupport?.verbosity!==!0,onChange:e=>{i(c(`configurationVerbosityRequest`,{value:e}))}})})]}),(0,K.jsxs)(`div`,{className:`configuration-row`,children:[(0,K.jsxs)(`div`,{className:`configuration-copy`,children:[(0,K.jsx)(`strong`,{children:c(`configurationSummary`)}),(0,K.jsx)(`p`,{children:c(`configurationSummaryDetail`)}),e.responseSupport?.reasoningSummary!==!0&&(0,K.jsx)(`p`,{children:c(`configurationSummaryUnavailable`)})]}),(0,K.jsx)(`div`,{className:`configuration-control`,children:(0,K.jsx)(oF,{label:c(`configurationSummary`),value:m,options:[`default`,`auto`,`concise`,`detailed`,`none`].map(e=>({value:e,label:c(`configurationSummary_${e}`),description:e==="default"?void 0:c(`configurationSummaryHelp_${e}`)})),disabled:u||e.responseSupport?.reasoningSummary!==!0,onChange:e=>{i(c(`configurationSummaryRequest`,{value:e}))}})})]})]}),(0,K.jsxs)(`section`,{className:`configuration-section`,children:[(0,K.jsx)(`h2`,{children:c(`configurationModelFeatures`)}),(0,K.jsx)(`div`,{className:`configuration-group`,children:(0,K.jsxs)(`div`,{className:`configuration-row`,children:[(0,K.jsxs)(`div`,{className:`configuration-copy`,children:[(0,K.jsx)(`strong`,{children:c(`configurationReasoningLevels`)}),(0,K.jsx)(`p`,{children:c(`configurationReasoningDetail`)})]}),(0,K.jsx)(`div`,{className:`configuration-control`,children:(0,K.jsx)(jA,{button:{label:c(`configurationReasoningCount`,{count:f.filter(e=>!d.includes(e)).length}),"aria-label":c(`configurationReasoningLevels`),variant:`secondary`,size:`sm`,className:`configuration-menu-trigger`,isDisabled:u||f.length===0},className:`configuration-level-menu`,menuWidth:`min(240px, calc(100vw - 32px))`,alignment:`end`,children:f.map(e=>(0,K.jsx)(XA,{label:e,value:!d.includes(e),isDisabled:u,endContent:(0,K.jsx)(`span`,{className:`configuration-check`,children:!d.includes(e)&&(0,K.jsx)(I,{"aria-hidden":`true`})}),onChange:t=>{a({thinkingLevelVisibility:{level:e,visible:t}})}},e))})})]})})]}),(0,K.jsxs)(`section`,{className:`configuration-section`,children:[(0,K.jsx)(`h2`,{children:c(`configurationDependencies`)}),(0,K.jsx)(`div`,{className:`configuration-group`,children:(0,K.jsxs)(`div`,{className:`configuration-row`,children:[(0,K.jsxs)(`div`,{className:`configuration-copy`,children:[(0,K.jsx)(`strong`,{children:c(`configurationEnvironment`)}),(0,K.jsx)(`p`,{children:c(`configurationEnvironmentDetail`)})]}),(0,K.jsxs)(`button`,{type:`button`,className:`configuration-runtime-button`,onClick:s,children:[c(`configurationRuntimeStatus`),(0,K.jsx)(O,{"aria-hidden":`true`})]})]})})]})]})]})}function cF({catalog:e,error:t,pending:n,onConfigure:r,onRefresh:i}){let{t:a}=cr(),o=e?.setup.webSearch?.enabled===!0,s=e?.webSearch?.available===!0,c=n||!e||!!t||!!e?.resources.diagnostics.settingsErrors;return(0,K.jsxs)(`section`,{className:`settings-general-panel settings-web-search-panel`,children:[(0,K.jsxs)(`header`,{className:`settings-page-heading`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`h1`,{children:a(`webSearchSettings`)}),(0,K.jsx)(`p`,{children:a(`webSearchIntro`)})]}),(0,K.jsx)(`button`,{type:`button`,"aria-label":a(`refreshStatus`),onClick:i,children:(0,K.jsx)(dt,{"aria-hidden":`true`})})]}),t&&(0,K.jsx)(`p`,{className:`inspection-warning`,role:`alert`,children:t}),!e&&!t&&(0,K.jsx)(`p`,{role:`status`,children:a(`settingsCatalogLoading`)}),(0,K.jsxs)(`section`,{className:`settings-section-block`,children:[(0,K.jsxs)(`div`,{className:`settings-detail-heading`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`h2`,{children:[(0,K.jsx)(ht,{"aria-hidden":`true`}),a(`webSearchCurrentModel`)]}),(0,K.jsx)(`p`,{children:a(`webSearchNativeDetail`)})]}),(0,K.jsx)(`span`,{className:`settings-status-badge`,children:a(o?`enabled`:`disabled`)})]}),(0,K.jsxs)(`dl`,{className:`settings-detail-metadata`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`dt`,{children:a(`source`)}),(0,K.jsx)(`dd`,{children:a(`webSearchCurrentModel`)})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`dt`,{children:a(`model`)}),(0,K.jsx)(`dd`,{children:e?.webSearch?.model?`${e.webSearch.provider} / ${e.webSearch.model}`:a(`unavailable`)})]})]}),(0,K.jsx)(`p`,{className:`settings-resource-caption`,children:a(`webSearchDefaultOff`)}),(0,K.jsx)(`p`,{role:`status`,className:`settings-resource-caption`,children:a(s?`webSearchSupported`:`webSearchUnsupported`)})]}),(0,K.jsx)(`section`,{className:`settings-section-block settings-chat-controls`,children:(0,K.jsx)(qc,{label:a(o?`webSearchDisable`:`webSearchEnable`),variant:`secondary`,size:`sm`,isDisabled:c,isLoading:n,onClick:()=>void r(a(o?`webSearchDisableRequest`:`webSearchNativeRequest`))})})]})}var lF={wrapper:{k8WAf4:`xu0wf1k`,kg3NbH:`x7a5moj`,$$css:!0},icon:{k1xSpc:`x78zum5`,kGNEyG:`x6s0dn4`,kmuXW:`x2lah0s`,$$css:!0}};function uF({ref:e,label:t,clearLabel:n,placeholder:r,value:i,onValueChange:a,onKeyDown:o,onFocus:s,onBlur:c,onContainerKeyDown:l,xstyle:u,className:d,style:f,...p}){let[m,h]=(0,_.useState)(!1);(0,_.useEffect)(()=>{Zi()},[]);let g=(0,_.useCallback)(e=>{h(Qi()===`keyboard`),s?.(e)},[s]),v=(0,_.useCallback)(e=>{h(!1),c?.(e)},[c]),y=(0,_.useCallback)(()=>{a(``),typeof e==`object`&&e?.current&&e.current.focus()},[a,e]);return(0,K.jsx)(`div`,{onKeyDown:l,...oa(Sr(lF.wrapper,u),d,f),children:(0,K.jsxs)(`div`,{"data-keyboard-focus":m?`true`:void 0,...{0:{className:`x9f619 x78zum5 x6s0dn4 x1txdalj xh8yej3 x1vofgu7 xf314gf xh6dtrn xkdsq27 xuedmi6 x12w9bfk xlr8y92`},1:{className:`x9f619 x78zum5 x6s0dn4 x1txdalj xh8yej3 x1vofgu7 xf314gf xh6dtrn xkdsq27 xuedmi6 x12w9bfk xlr8y92 x1gnnqk1 x1btxeh5`}}[!!m<<0],children:[(0,K.jsx)(xu,{icon:`search`,size:`sm`,color:`secondary`,xstyle:lF.icon}),(0,K.jsx)(`input`,{ref:e,type:`text`,"aria-label":t,placeholder:r,value:i,onChange:e=>a(e.target.value),onKeyDown:o,onFocus:g,onBlur:v,className:`x1iyjqo2 xs83m0k xeuugli x1717udv x1ghz6dp xc342km xng3xce xjbqb8w x1tgivj0 x9ynric xcr08ib xdk3u5w x1kq96og x1a2a7pz xeyghm5`,...p}),i!==``&&(0,K.jsx)(zM,{label:n,onClick:y})]})})}uF.displayName=`PanelSearchInput`;function dF(e){return typeof e==`string`||!(`type`in e)}function fF(e){return typeof e==`object`&&`type`in e&&e.type===`divider`}function pF(e){return typeof e==`object`&&`type`in e&&e.type===`section`}function mF(e){return typeof e==`string`?{value:e,label:e}:{...e,label:e.label??e.value}}function hF(e){let t=[];for(let n of e)if(dF(n))t.push(mF(n));else if(pF(n))for(let e of n.options)t.push(mF(e));return t}var gF=1;function _F(e){let t=0,n=e;for(;n;)t+=n.offsetTop,n=n.offsetParent;return t}function vF({isOpen:e,selectedItemIndex:t,listboxId:n,listboxRef:r,anchorRef:i}){let[a,o]=(0,_.useState)(0),[s,c]=(0,_.useState)(!1),l=(0,_.useCallback)((e,t)=>{o(e),c(t)},[]);return wu(()=>{if(!e){l(0,!1);return}if(!r.current||!i.current){l(0,!0);return}let a=`${n}-item-${t>=0?t:0}`,o=document.getElementById(a);if(!o){l(0,!0);return}let s=r.current,c=i.current.getBoundingClientRect(),u=s.offsetHeight;if(u<=0){l(0,!0);return}let d=_F(o)-_F(s)-s.scrollTop+o.offsetHeight/2,f=c.top+c.height/2-d-gF,p=window.innerHeight,m=Math.max(0,p-u),h=Math.min(Math.max(f,0),m),g=Math.max(0,c.bottom-h);l(g,!0)},[e,t,n,r,i,l]),{offset:a,isPositioned:s}}function yF({selectableItems:e,value:t,isDisabled:n=!1,isOpen:r,hasSearch:i=!1,onOpen:a,onClose:o,onSelect:s,onClear:c,onSearchSeed:l,wasJustDismissed:u,listboxId:d}){let[f,p]=(0,_.useState)(-1),m=(0,_.useCallback)(e=>`${d}-item-${e}`,[d]),h=(0,_.useCallback)(()=>e.map((e,t)=>e.disabled?-1:t).filter(e=>e>=0),[e]),g=(0,_.useCallback)(()=>e.findIndex(e=>e.value===t),[e,t]),v=(0,_.useCallback)(()=>{p(-1),o()},[o]),y=(0,_.useCallback)(e=>{e.disabled||(s?.(e.value),v())},[s,v]),b=(0,_.useCallback)(()=>{if(!(n||u?.())){if(r)v();else if(a(),!i){let e=g();p(e>=0?e:0)}}},[n,u,r,a,v,g,i]),x=(0,_.useCallback)((e,t)=>{e.disabled||p(t)},[]);return{highlightedIndex:f,setHighlightedIndex:p,getItemId:m,onTriggerClick:b,onKeyDown:(0,_.useCallback)(o=>{if(n)return;let s=h();switch(o.key){case`ArrowDown`:if(o.preventDefault(),!r)a(),p(0);else{let e=s.indexOf(f),t=Math.min(e+1,s.length-1);p(s[t]??f)}break;case`ArrowUp`:if(o.preventDefault(),!r)a(),p(e.length-1);else{let e=s.indexOf(f),t=Math.max(e-1,0);p(s[t]??f)}break;case` `:if(i)break;case`Enter`:if(o.preventDefault(),r&&f>=0){let t=e[f];t&&!t.disabled&&y(t)}else if(!r&&(a(),!i)){let e=g();p(e>=0?e:0)}break;case`Escape`:r&&(o.preventDefault(),v());break;case`Tab`:r&&v();break;case`Home`:o.preventDefault(),r&&s.length>0&&p(s[0]);break;case`End`:o.preventDefault(),r&&s.length>0&&p(s[s.length-1]);break;case`PageUp`:o.preventDefault(),r&&s.length>0&&p(s[0]);break;case`PageDown`:o.preventDefault(),r&&s.length>0&&p(s[s.length-1]);break;case`Delete`:case`Backspace`:!i&&!r&&c!=null&&t!=null&&(o.preventDefault(),c());break;default:i&&l&&o.key.length===1&&!o.ctrlKey&&!o.metaKey&&(r||a(),l(o.key))}},[n,r,a,v,e,f,y,g,h,i,c,l,t]),onItemSelect:y,onItemMouseEnter:x}}var bF=(0,_.createContext)(`stacked`);bF.displayName=`SelectorRowLayoutContext`;function xF(){return(0,_.use)(bF)}var SF={root:{k8WAf4:`xt970qd`,kg3NbH:`xnjsko4`,kaIpWk:`x2u8bby`,$$css:!0}};function CF({icon:e,label:t,description:n,layout:r,endContent:i,xstyle:a,className:o,style:s}){let c=xF();return(0,K.jsx)(qk,{startContent:e?Cu(e,{size:`sm`,color:`secondary`}):void 0,label:t,description:n,layout:c===`inline`?`inline`:r,endContent:i,xstyle:[SF.root,a],...oa(ba(`selector-option`),{className:o,style:s})})}CF.displayName=`SelectorOption`;var wF={triggerContainer:{kVAEAm:`x1n2onr6`,k1xSpc:`x78zum5`,kGNEyG:`x6s0dn4`,kjj79g:`x1qughib`,kOIVth:`x1txdalj`,kzqmXN:`xh8yej3`,k8WAf4:`xce4md1`,kg3NbH:`xrrkdod`,kMv6JI:`x9ynric`,kGuDYH:`xcr08ib xdk3u5w`,kLWn49:`x7acx1w`,kMwMTN:`x1tgivj0`,kkrTdU:`x1ypdohk x16khyan`,$$css:!0},triggerPlaceholder:{kMwMTN:`xv1l7n4`,$$css:!0},triggerInGroup:{kAzted:`x2lwn1j`,k8WAf4:`xt970qd`,$$css:!0},triggerIcon:{kmuXW:`x2lah0s`,$$css:!0},triggerIconRotation:{k1ekBW:`x11xpdln`,kIyJzY:`xuedmi6`,kAMwcw:`xlr8y92`,k3nNDw:`x1g0ag68`,$$css:!0},triggerIconOpen:{k3aq6I:`x19jd1h0`,$$css:!0},triggerGhost:{kzqmXN:`x14atkfc`,kMzoRj:`xc342km`,kWkggS:`xjbqb8w`,kGVxlE:`x1gnnqk1 x1s17dad x15ysqaf`,k63SB2:`x1e4wzip`,k1ekBW:`xrafxwg`,k3aq6I:`x3oybdh xk4oym4`,$$css:!0},triggerGhostDisabled:{kKwaWg:`x18o3ruo`,k3aq6I:`x1c071of x1pdlv7q`,$$css:!0},statusButton:{k1xSpc:`x78zum5`,kGNEyG:`x6s0dn4`,kjj79g:`xl56j7k`,kmVPX3:`x1717udv`,kogj98:`x1ghz6dp`,kMzoRj:`xc342km`,ksu8eU:`xng3xce`,kWkggS:`xjbqb8w`,kMwMTN:`x1heor9g`,kkrTdU:`x1ypdohk x16khyan`,kaIpWk:`xh6dtrn`,$$css:!0},searchRowInput:{kg3NbH:`x2hg6jq`,$$css:!0},popover:{k7Eaqz:`xrzjruh`,$$css:!0},divider:{kqGvvJ:`xsq74q5`,$$css:!0},item:{kB7OPa:`x9f619`,k1xSpc:`x78zum5`,kGNEyG:`x6s0dn4`,kjj79g:`x1qughib`,kOIVth:`x1txdalj`,kzqmXN:`xh8yej3`,kmVPX3:`xlsj2fj`,kaIpWk:`xh6dtrn`,kMv6JI:`x9ynric`,kGuDYH:`xcr08ib`,kMwMTN:`x1tgivj0`,kWkggS:`xjbqb8w`,kkrTdU:`x1ypdohk x16khyan`,k9WMMc:`x1yc453h`,kI3sdo:`x1a2a7pz`,$$css:!0},itemHighlighted:{kWkggS:`x1lmrjuc`,$$css:!0},itemSelected:{k63SB2:`x1e4wzip`,$$css:!0},itemDisabled:{kSiTet:`xbyyjgo`,kkrTdU:`xt0e3qv`,$$css:!0}},TF={sm:{kAzted:`x1gdqauq`,k8WAf4:`x1ecmfrv`,$$css:!0},md:{kAzted:`x1uogy3y`,k8WAf4:`x1ioay2v`,$$css:!0},lg:{kAzted:`x1xf4nls`,k8WAf4:`x1vn5h1t`,$$css:!0}},EF={sm:{k8WAf4:`xu0wf1k`,kg3NbH:`xf314gf`,$$css:!0},md:{k8WAf4:`x1vofgu7`,$$css:!0},lg:{$$css:!0}},DF={warning:`warning`,error:`error`,success:`success`},OF={warning:`warning`,error:`error`,success:`success`},kF={warning:`@astryx.input.statusButton.warning`,error:`@astryx.input.statusButton.error`,success:`@astryx.input.statusButton.success`};function AF({option:e}){return(0,K.jsx)(CF,{icon:e.icon,label:e.label??e.value,description:e.description})}function jF(e,t){return!t||(e.label??e.value).toLowerCase().includes(t.toLowerCase())}function MF(e,t){return t?e.filter(e=>jF(e,t)):e}function NF(e){let t=Rc(),{label:n,isLabelHidden:r=!1,description:i,isOptional:a=!1,isRequired:o=!1,isDisabled:s=!1,disabledMessage:c,options:l,value:u,onChange:d,changeAction:f,isLoading:p=!1,placeholder:m,size:h,variant:g=`input`,status:v,statusVariant:y=`attached`,labelTooltip:b,startIcon:x,htmlName:S,renderOption:C,renderValue:w,indicatorPosition:T=`end`,hasSearch:E=!1,searchPlaceholder:D,emptyText:O,emptySearchText:k,placement:A,isDefaultOpen:j=!1,"data-testid":M,width:N,xstyle:P,className:F,style:I,hasClear:L,id:R,...z}=e,B=HM({isRequired:o,isOptional:a}),V=m??t(`@astryx.selector.placeholder`),H=D??t(`@astryx.selector.searchPlaceholder`),ee=O??t(`@astryx.selector.empty`),te=k??t(`@astryx.selector.emptySearchResults`),ne=L===!0,re=as(h,`md`),ie=g===`ghost`&&y===`attached`?`detached`:y,ae=u===null?void 0:u,U=(0,_.useId)(),oe=R??U,se=(0,_.useId)(),ce=(0,_.useId)(),le=(0,_.useId)(),ue=(0,_.useId)(),de=(0,_.useId)(),fe=(0,_.useRef)(null),W=(0,_.useRef)(null),pe=(0,_.useRef)(null),me=WM(),[he,ge]=(0,_.useState)(``),_e=(0,_.useRef)(``),ve=he.length>0,[,ye]=(0,_.useTransition)(),[be,xe]=(0,_.useOptimistic)(ae),Se=p||be!==ae,Ce=so(),we=typeof ee==`string`?ee:t(`@astryx.selector.empty`),Te=typeof te==`string`?te:t(`@astryx.selector.emptySearchResults`),G=s&&!!c,Ee=po({placement:`above`,focusTrigger:`always`,isEnabled:G}),De=po({placement:`above`,isEnabled:ie===`tooltip`&&!!v?.message}),{ariaLabelledBy:Oe,ariaDescribedBy:ke}=Oa(ue,[i?ce:null,!me&&ie!==`tooltip`&&v?.message?le:null,ie===`tooltip`&&v?.message?De.describedBy:null,G?Ee.describedBy:null],me),Ae=(0,_.useMemo)(()=>hF(l),[l]),je=(0,_.useMemo)(()=>MF(Ae,he),[Ae,he]),Me=(0,_.useMemo)(()=>Ae.findIndex(e=>e.value===be),[Ae,be]),Ne=(0,_.useMemo)(()=>Me>=0?Ae[Me]:void 0,[Ae,Me]),Pe=(0,_.useRef)(null),Fe=(0,_.useRef)(()=>{}),Ie=dd({onHide:(0,_.useCallback)(()=>{ge(``),_e.current=``,Fe.current(),Ce(``),W.current?.focus()},[Ce]),hasLightDismiss:!0,hasCloseButton:!1,hasAutoFocus:!1,role:`none`,surfaceTarget:`selector-popup`}),Le=yi(Ie.id,Ie.isOpen);(0,_.useEffect)(()=>{j&&Ie.show()},[]);let Re=(0,_.useCallback)(e=>{if(e.length===0){Ce(``);return}if(p){Ce(``);return}let n=MF(Ae,e).length;Ce(n===0?Te:t(`@astryx.selector.resultCount`,{count:n}))},[Ce,p,Ae,Te,t]),ze=(0,_.useCallback)(e=>{ge(e),_e.current=e,Re(e)},[Re]),Be=(0,_.useRef)(null);(0,_.useEffect)(()=>{if(!(Ie.isOpen&&!p&&he===``&&Ae.length===0)){Be.current=null;return}Be.current!==we&&(Be.current=we,Ce(we))},[Ie.isOpen,p,he,Ae.length,we,Ce]);let Ve=A==null&&!E,{offset:He,isPositioned:Ue}=vF({isOpen:Ie.isOpen&&Ve,selectedItemIndex:Me,listboxId:se,listboxRef:Pe,anchorRef:fe}),We=Ve?He:0,Ge=!Ve||Ue,Ke=A??`below`,qe=We>0?{marginBlockStart:`-${We}px`}:void 0,Je=(0,_.useCallback)(()=>{Fe.current(),d?.(null),f&&ye(async()=>{xe(void 0),await f(null)})},[d,f,ye,xe]),Ye=(0,_.useCallback)(e=>{let t=_e.current+e;_e.current=t,ge(t),Re(t)},[Re]),Xe=(0,_.useCallback)(e=>{d?.(e),f&&ye(async()=>{xe(e),await f(e)})},[d,f,ye,xe]),{highlightedIndex:Ze,setHighlightedIndex:Qe,getItemId:$e,onTriggerClick:et,onKeyDown:tt,onItemSelect:nt,onItemMouseEnter:rt}=yF({selectableItems:je,wasJustDismissed:Ie.wasJustDismissed,value:be,isDisabled:s,isOpen:Ie.isOpen,hasSearch:E,onOpen:(0,_.useCallback)(()=>{Ie.show(),E&&requestAnimationFrame(()=>{let e=pe.current;e&&(e.focus(),e.setSelectionRange(e.value.length,e.value.length))})},[Ie,E]),onClose:Ie.hide,onSelect:Xe,onClear:ne?Je:void 0,onSearchSeed:Ye,listboxId:se}),it=_A({getItemLabels:()=>Ae.map(e=>e.label??e.value),isDisabled:e=>Ae[e]?.disabled===!0,getCurrentIndex:()=>Ie.isOpen?Ze:Me,onMatch:e=>{let t=Ae[e];Ie.isOpen?Qe(e):t.value!==be&&(Xe(t.value),Ce(t.label??t.value))}});Fe.current=it.reset;let at=(0,_.useCallback)(e=>{if(!s&&!E&&it.onKeyDown(e)){e.preventDefault();return}tt(e)},[s,E,it,tt]);(0,_.useEffect)(()=>{!Ie.isOpen||Ze<0||document.getElementById($e(Ze))?.scrollIntoView?.({block:`nearest`})},[Ie.isOpen,Ze,$e]);let ot=(0,_.useCallback)(e=>{e.stopPropagation(),Je()},[Je]),st=(0,_.useCallback)(()=>E?(0,K.jsx)(uF,{ref:pe,id:de,label:t(`@astryx.selector.searchOptions`),clearLabel:t(`@astryx.textInput.clearLabel`,{label:t(`@astryx.selector.searchOptions`)}),...ba(`selector-search`),xstyle:g!==`ghost`&&wF.searchRowInput,role:`combobox`,"aria-expanded":Ie.isOpen,"aria-controls":se,"aria-autocomplete":`list`,"aria-activedescendant":Ie.isOpen&&Ze>=0?$e(Ze):void 0,value:he,onValueChange:ze,onContainerKeyDown:e=>{e.target!==pe.current&&e.key===`Tab`&&!e.shiftKey&&tt(e)},onKeyDown:e=>{if(!Di(e.nativeEvent)){if(e.key===`ArrowDown`||e.key===`ArrowUp`||e.key===`PageUp`||e.key===`PageDown`||e.key===`Enter`||e.key===`Escape`){tt(e);return}e.key===`Tab`&&(e.shiftKey||!ve)&&tt(e)}},placeholder:H}):null,[E,de,se,he,ve,H,ze,tt,Ie.isOpen,Ze,$e,g,t]),ct=JA(`check`),lt=(0,_.useCallback)((e,t)=>{let n=t===Ze,r=e.value===ae,i=(0,K.jsx)(`span`,{className:`x3nfvp2 x6s0dn4 xl56j7k x2lah0s xgomdpo`,children:(0,K.jsx)(ct,{state:r?`checked`:`unchecked`,size:`sm`,isDisabled:e.disabled??!1,...ba(`selector-check`)})}),a=(0,K.jsx)(`span`,{className:`x78zum5 x6s0dn4 x1txdalj x98rzlu xeuugli`,children:C?C(e):(0,K.jsx)(AF,{option:e})}),o=T===`start`?(0,K.jsxs)(K.Fragment,{children:[i,a]}):(0,K.jsxs)(K.Fragment,{children:[a,i]});return(0,K.jsx)(`div`,{id:$e(t),role:`option`,"aria-selected":r,"aria-disabled":e.disabled,onClick:()=>nt(e),onMouseEnter:()=>rt(e,t),...oa(ba(`selector-option-row`,{size:re,selected:r?`selected`:null,disabled:e.disabled?`disabled`:null}),Sr(wF.item,EF[re],n&&wF.itemHighlighted,r&&wF.itemSelected,e.disabled&&wF.itemDisabled)),children:o},e.value)},[C,T,Ze,re,ae,$e,nt,rt,ct]),ut=(0,_.useCallback)(()=>{let e=E&&!!he;if(je.length===0&&!p)return[(0,K.jsx)(`div`,{role:`presentation`,...oa(ba(`selector-empty-state`),{className:`x1b2ylru x2b8uid xv1l7n4 x9ynric xcr08ib`}),children:e?te:ee},`empty`)];let t=0,n=[];for(let r=0;r{fe.current=e,Ie.triggerRef(e),Ee.ref(e)},onClick:et,"data-testid":M,...oa(ba(`selector`,{variant:g,size:re,status:v?.type??null,disabled:s?`disabled`:null}),Sr(NM.base,wF.triggerContainer,TF[re],g===`ghost`&&wF.triggerGhost,g===`ghost`&&ds.backgroundImage,g===`ghost`&&Ha.focusWithin,s&&NM.disabled,g===`ghost`&&s&&wF.triggerGhostDisabled,!Ne&&wF.triggerPlaceholder,g!==`ghost`&&v&&PM[v.type],g!==`ghost`&&v&&!s&&FM[v.type],g!==`ghost`&&me&&VM.inGroup,me&&wF.triggerInGroup,P),F,I),children:[x&&Cu(x,{size:`sm`,color:`secondary`}),me&&(0,K.jsx)(es,{id:ue,children:n}),(0,K.jsx)(`button`,{ref:W,id:oe,type:`button`,role:E?void 0:`combobox`,...z,"aria-haspopup":`listbox`,"aria-expanded":Ie.isOpen,"aria-controls":se,"aria-activedescendant":!E&&Ie.isOpen&&Ze>=0?$e(Ze):void 0,"aria-describedby":ke,"aria-labelledby":Oe,"aria-required":B?`true`:void 0,"aria-invalid":v?.type===`error`?`true`:void 0,"aria-busy":Se||void 0,disabled:s&&!G,"aria-disabled":G?`true`:void 0,onKeyDown:at,tabIndex:s&&!G?-1:0,...{0:{className:`x78zum5 x6s0dn4 x1qughib x1txdalj x1iyjqo2 xs83m0k x1r8uery xeuugli x1717udv x1ghz6dp xc342km xng3xce xjbqb8w xjb2p0i x1qlqyl8 x15bjb6t x1heor9g x1ypdohk x16khyan x1a2a7pz`},1:{className:`x78zum5 x6s0dn4 x1qughib x1txdalj x1iyjqo2 xs83m0k x1r8uery xeuugli x1717udv x1ghz6dp xc342km xng3xce xjbqb8w xjb2p0i x1qlqyl8 x15bjb6t x1heor9g x1ypdohk x16khyan x1a2a7pz xkh2ocl`}}[!!me<<0],children:pt}),S!=null&&(0,K.jsx)(`input`,{type:`hidden`,name:S,value:u??``,disabled:s}),Se&&(0,K.jsx)($o,{size:`sm`}),ne&&u!=null&&!s&&(0,K.jsx)(BM,{...Le,label:t(`@astryx.selector.clearLabel`,{label:n}),onClick:ot,iconClassName:pa(`selector-clear-icon`)}),dt?ft?(0,K.jsx)(`button`,{ref:De.ref,type:`button`,"aria-label":t(kF[v.type]),"aria-describedby":De.describedBy,...Le,onClick:e=>e.stopPropagation(),...Sr(Ha.focusVisible,wF.statusButton),children:(0,K.jsx)(xu,{icon:DF[v.type],size:`sm`,color:OF[v.type],xstyle:wF.triggerIcon})}):(0,K.jsx)(xu,{icon:DF[v.type],size:`sm`,color:OF[v.type],xstyle:wF.triggerIcon}):(0,K.jsx)(xu,{icon:`chevronDown`,size:`sm`,color:`secondary`,xstyle:[wF.triggerIcon,wF.triggerIconRotation,Ie.isOpen&&wF.triggerIconOpen],...ba(`selector-indicator-icon`,{state:Ie.isOpen?`expanded`:`collapsed`})})]}),Ie.render(E?(0,K.jsxs)(`div`,{children:[st(),(0,K.jsx)(iA,{}),(0,K.jsx)(`div`,{ref:Pe,id:se,role:`listbox`,"aria-labelledby":oe,...{0:{className:`x9f619 xuyqlj2 x1odjw0f xu0wf1k x7a5moj x1hc1fzr x1ey1afo`},1:{className:`x9f619 xuyqlj2 x1odjw0f xu0wf1k x1hc1fzr x1ey1afo x2hg6jq`}}[(g!==`ghost`)<<0],children:ut()})]}):(0,K.jsx)(`div`,{ref:Pe,id:se,role:`listbox`,"aria-labelledby":oe,...{0:{className:`x9f619 xuyqlj2 x1odjw0f xu0wf1k x7a5moj x1hc1fzr x1ey1afo`},2:{className:`x9f619 xuyqlj2 x1odjw0f xu0wf1k x1hc1fzr x1ey1afo x2hg6jq`},1:{className:`x9f619 xuyqlj2 x1odjw0f xu0wf1k x7a5moj xg01cxk xq2gx43`},3:{className:`x9f619 xuyqlj2 x1odjw0f xu0wf1k x2hg6jq xg01cxk xq2gx43`}}[(g!==`ghost`)<<1|!Ge<<0],children:ut()}),{placement:Ke,alignment:`start`,offset:Ve?void 0:Br[`--spacing-1`],xstyle:[wF.popover,co[Ke]],style:qe}),ft&&De.renderTooltip(v?.message??``),G&&Ee.renderTooltip(c)]});return me?mt:(0,K.jsx)(MM,{label:n,isLabelHidden:r,description:i,inputID:oe,descriptionID:i?ce:void 0,isOptional:a,isRequired:o,isDisabled:s,status:v?{type:v.type,message:v.message,messageID:v.message?le:void 0}:void 0,statusVariant:ie,labelTooltip:b,width:N,children:mt})}NF.displayName=`Selector`;function PF(e){return e?.status===`running`||e?.status===`cancelling`}function FF({sessionId:e,auth:t,busy:n,onSaving:r,onAuthenticated:i,onReload:a}){let{t:o}=cr(),[s,c]=(0,_.useState)(null),[l,u]=(0,_.useState)(!1),[d,f]=(0,_.useState)(!1),[p,m]=(0,_.useState)(!1),[h,g]=(0,_.useState)(0),[v,y]=(0,_.useState)(``),[b,x]=(0,_.useState)(!1),[S,C]=(0,_.useState)(!1),[w,T]=(0,_.useState)(!1),E=(0,_.useRef)(!1),D=(0,_.useRef)(null),k=(0,_.useRef)(!1),A=(0,_.useRef)(null),j=(0,_.useRef)({onSaving:r,onAuthenticated:i});j.current={onSaving:r,onAuthenticated:i};let M=PF(s),N=t.id,P=`${e}:${N}`,F=(0,_.useRef)({key:P});F.current.key!==P&&(F.current={key:P});let L=F.current,R=(0,_.useCallback)((t,n)=>{if(t&&(t.sessionId!==e||t.provider!==N||n&&t.id!==n))throw Error(`Login ownership changed`);if(n&&!t)throw Error(`Login status unavailable`);if(!E.current||F.current!==L){t&&PF(t)&&new rf().cancelProviderLogin(e,t.id).catch(()=>void 0);return}D.current=t,c(t),m(!1),t?.status===`succeeded`&&!t.refreshRequired&&A.current!==t.id&&(A.current=t.id,j.current.onAuthenticated())},[e,N,L]);(0,_.useEffect)(()=>{E.current=!0,D.current=null,k.current=!1,A.current=null,c(null),u(!1),f(!1),m(!1),x(!1),T(!1);let t=new AbortController;return new rf().providerLogin(e,void 0,t.signal).then(e=>{!t.signal.aborted&&e?.provider===N&&PF(e)&&R(e)}).catch(()=>void 0),()=>{E.current=!1,t.abort();let n=D.current;n&&PF(n)&&new rf().cancelProviderLogin(e,n.id).catch(()=>void 0),j.current.onSaving(!1)}},[e,N,R]),(0,_.useEffect)(()=>{j.current.onSaving(M||l)},[M,l]);let z=s?.prompt?.id;(0,_.useEffect)(()=>{y(``)},[z]);let B=s?.id;(0,_.useEffect)(()=>{x(!1)},[B]),(0,_.useEffect)(()=>{if(!M||!B)return;let t=new AbortController,n=0,r=async()=>{try{let i=await new rf().providerLogin(e,B,t.signal);if(t.signal.aborted)return;R(i,B),PF(i)&&(n=window.setTimeout(()=>void r(),900))}catch{t.signal.aborted||m(!0)}};return r(),()=>{t.abort(),clearTimeout(n)}},[e,R,B,M,h]);let V=async e=>{if(!k.current){k.current=!0,u(!0),f(!1);try{R(await e())}catch{E.current&&F.current===L&&f(!0)}finally{F.current===L&&(k.current=!1,E.current&&u(!1))}}},H=()=>{n||M||V(()=>new rf().startProviderLogin(e,N))},ee=t=>{let n=s?.prompt;if(!s||!n)return;let r=s.id;V(()=>new rf().respondProviderLogin(e,r,n.id,t))},te=async()=>{try{let t=await new rf().providerLogin(e,s?.id);R(t,s?.id),E.current&&F.current===L&&(f(!1),g(e=>e+1))}catch{E.current&&F.current===L&&f(!0)}},ne=s?.prompt,re=s?.auth||s?.device,ie=ne&&ne.type!==`select`&&(0,K.jsxs)(`div`,{className:`models-login-input`,children:[(0,K.jsxs)(`label`,{className:`models-field`,children:[ne.type===`manual_code`?o(`accountLoginPaste`):ne.message,(0,K.jsx)(`input`,{type:ne.type===`secret`||ne.type===`manual_code`?`password`:`text`,autoComplete:`off`,spellCheck:!1,value:v,maxLength:8192,placeholder:ne.placeholder,disabled:l||s.status!==`running`,onChange:e=>y(e.target.value),onKeyDown:e=>{e.key!==`Enter`||e.nativeEvent.isComposing||(e.preventDefault(),(ne.type===`text`||v.trim())&&ee(v))}})]}),(0,K.jsx)(`button`,{type:`button`,className:`models-button primary`,disabled:l||ne.type!==`text`&&!v.trim()||s.status!==`running`,onClick:()=>ee(v),children:o(`accountLoginContinue`)})]});return(0,K.jsxs)(`div`,{className:`models-account-login`,children:[!M&&!w&&(!s||[`failed`,`expired`,`cancelled`].includes(s.status))&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`div`,{className:`models-login-intro`,children:(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`strong`,{children:N===`openai`?o(`accountLoginChatGPT`):N===`anthropic`?o(`accountLoginClaude`):t.loginLabel||t.name}),(0,K.jsx)(`p`,{className:`models-hint`,children:o(t.subscription?`accountLoginExisting`:`accountLoginIntro`)})]})}),(0,K.jsxs)(`div`,{className:`models-login-actions`,children:[(0,K.jsx)(`button`,{type:`button`,className:`models-button primary`,disabled:n||l||d,onClick:H,children:o(t.subscription?`accountLoginAgain`:`accountLoginStart`)}),t.subscription&&(0,K.jsx)(`button`,{type:`button`,className:`models-link`,disabled:n||l,onClick:()=>C(!0),children:o(`accountLogout`)})]})]}),M&&(0,K.jsxs)(`div`,{className:`models-login-flow`,children:[(0,K.jsxs)(`div`,{className:`models-login-status`,role:`status`,children:[(0,K.jsx)(He,{"aria-hidden":`true`}),(0,K.jsx)(`span`,{children:o(s?.status===`cancelling`?`accountLoginCancelling`:re?`accountLoginWaiting`:ne?`accountLoginChoose`:`accountLoginStarting`)})]}),re&&(0,K.jsx)(`p`,{className:`models-hint`,children:o(s?.device?`accountLoginDeviceHelp`:`accountLoginBrowserHelp`)}),s?.device&&(0,K.jsxs)(`div`,{className:`models-device-code`,children:[(0,K.jsx)(`code`,{children:s.device.code}),(0,K.jsx)(`button`,{type:`button`,className:`models-icon`,"aria-label":o(`accountLoginCopyCode`),onClick:()=>{s.device&&navigator.clipboard.writeText(s.device.code).then(()=>{E.current&&F.current===L&&x(!0)}).catch(()=>{E.current&&F.current===L&&x(!1)})},children:b?(0,K.jsx)(I,{}):(0,K.jsx)(ue,{})})]}),re&&(0,K.jsxs)(`a`,{className:`models-button primary models-login-open`,href:s?.device?.url||s?.auth?.url,target:`_blank`,rel:`noopener noreferrer`,children:[o(`accountLoginOpen`),(0,K.jsx)(O,{"aria-hidden":`true`})]}),ne?.type===`select`&&(0,K.jsx)(`fieldset`,{className:`models-login-options`,"aria-label":ne.message,children:ne.options?.map(e=>{let t=[`openai`,`openai-codex`].includes(N)&&[`browser`,`device_code`].includes(e.id);return(0,K.jsxs)(`button`,{type:`button`,className:`models-login-option`,disabled:l||s?.status!==`running`,onClick:()=>ee(e.id),children:[(0,K.jsx)(`strong`,{children:t?o(e.id===`browser`?`accountLoginBrowser`:`accountLoginDevice`):e.label}),(t||e.description)&&(0,K.jsx)(`span`,{children:t?o(e.id===`browser`?`accountLoginBrowserOption`:`accountLoginDeviceOption`):e.description})]},e.id)})}),ne?.type===`manual_code`&&re?(0,K.jsxs)(`details`,{className:`models-login-fallback`,children:[(0,K.jsx)(`summary`,{children:o(`accountLoginFallback`)}),(0,K.jsx)(`p`,{className:`models-hint`,children:o(`accountLoginRemoteHelp`)}),ie]}):ie,s?.messages.map(e=>(0,K.jsxs)(`div`,{className:`models-hint`,children:[(0,K.jsx)(`p`,{children:e.message}),e.links?.map(e=>(0,K.jsxs)(`a`,{href:e.url,target:`_blank`,rel:`noopener noreferrer`,children:[e.label,(0,K.jsx)(O,{"aria-hidden":`true`})]},e.url))]},e.id)),(0,K.jsx)(`button`,{type:`button`,className:`models-link models-login-cancel`,disabled:l||s?.status===`cancelling`,onClick:()=>{s&&V(()=>new rf().cancelProviderLogin(e,s.id))},children:o(`accountLoginCancel`)})]}),s?.status===`succeeded`&&s.refreshRequired&&(0,K.jsxs)(`p`,{className:`models-hint`,role:`status`,children:[o(`accountLoginRefreshRequired`),` `,(0,K.jsx)(`button`,{type:`button`,className:`models-link`,onClick:a,children:o(`refreshStatus`)})]}),w&&(0,K.jsxs)(`p`,{className:`models-hint`,role:`status`,children:[o(`accountLogoutRefreshRequired`),` `,(0,K.jsx)(`button`,{type:`button`,className:`models-link`,onClick:a,children:o(`refreshStatus`)})]}),s&&[`failed`,`expired`,`cancelled`].includes(s.status)&&(0,K.jsx)(`p`,{className:s.status===`failed`?`models-error`:`models-hint`,role:`status`,children:o(`accountLogin_${s.status}`)}),d&&(0,K.jsxs)(`p`,{className:`models-error`,role:`alert`,children:[o(`accountLoginRequestFailed`),(0,K.jsx)(`button`,{type:`button`,className:`models-link`,onClick:()=>void te(),children:o(`refreshStatus`)})]}),p&&(0,K.jsxs)(`p`,{className:`models-error`,role:`alert`,children:[o(`accountLoginStatusUnknown`),(0,K.jsx)(`button`,{type:`button`,className:`models-link`,onClick:()=>g(e=>e+1),children:o(`refreshStatus`)})]}),S&&(0,K.jsx)(HP,{isOpen:!0,title:o(`accountLogoutTitle`,{provider:t.name}),description:o(`accountLogoutDetail`),cancelLabel:o(`cancel`),actionLabel:o(`accountLogout`),isActionLoading:l,onOpenChange:e=>{!e&&!l&&C(!1)},onAction:()=>{k.current||n||(k.current=!0,u(!0),f(!1),new rf().logoutProvider(e,N).then(e=>{!E.current||F.current!==L||(C(!1),e.refreshRequired?T(!0):a())}).catch(()=>{E.current&&F.current===L&&(C(!1),f(!0))}).finally(()=>{F.current===L&&(k.current=!1,E.current&&u(!1))}))}})]})}function IF({sessionId:e,template:t,existingIds:n,apiKey:r,onClose:i,onAdd:a}){let{t:o}=cr(),[s,c]=(0,_.useState)([]),[l,u]=(0,_.useState)(new Set),[d,f]=(0,_.useState)(``),[p,m]=(0,_.useState)(!0),[h,g]=(0,_.useState)(!1),[v,y]=(0,_.useState)(!1),[b,x]=(0,_.useState)(0),S=(0,_.useRef)({template:t,apiKey:r,existingIds:n}),C=new Set(n),w=Math.max(0,100-C.size),T=s.filter(e=>`${e.id} ${e.name}`.toLowerCase().includes(d.trim().toLowerCase())),E=T.filter(e=>!C.has(e.id)),D=E.length>0&&E.every(e=>l.has(e.id));return(0,_.useEffect)(()=>{let t=new AbortController,{template:n,apiKey:r,existingIds:i}=S.current;return m(!0),y(!1),new rf().discoverProviderModels(e,{provider:n.provider,baseUrl:n.baseUrl,api:n.api,...r.trim()?{apiKey:r.trim()}:{}},t.signal).then(e=>{t.signal.aborted||(c(e.models),g(e.truncated),m(!1),u(new Set(e.models.filter(e=>!i.includes(e.id)).slice(0,Math.max(0,100-i.length)).map(e=>e.id))))},()=>{t.signal.aborted||(y(!0),m(!1))}),()=>t.abort()},[e,b]),(0,K.jsx)($j,{isOpen:!0,width:380,padding:0,className:`models-picker-dialog`,"aria-label":o(`providerPickerTitle`),onOpenChange:e=>!e&&i(),children:(0,K.jsxs)(`div`,{className:`models-picker`,children:[(0,K.jsxs)(`header`,{children:[(0,K.jsx)(`h2`,{children:o(`providerPickerTitle`)}),(0,K.jsx)(`button`,{type:`button`,className:`models-icon`,"aria-label":o(`close`),onClick:i,children:(0,K.jsx)(Lt,{})})]}),(0,K.jsx)(`p`,{children:o(`providerPickerIntro`)}),(0,K.jsxs)(`div`,{className:`models-picker-toolbar`,children:[(0,K.jsx)(`input`,{"data-autofocus":!0,type:`search`,"aria-label":o(`providerPickerSearch`),placeholder:o(`providerPickerSearch`),value:d,onKeyDown:e=>{e.key===`Enter`&&e.preventDefault()},onChange:e=>f(e.target.value)}),(0,K.jsx)(`button`,{type:`button`,className:`models-link`,disabled:p||!E.length,onClick:()=>u(e=>{let t=new Set(e);for(let e of E)D?t.delete(e.id):t.size(0,K.jsxs)(`label`,{className:`models-picker-row`,children:[(0,K.jsx)(`input`,{type:`checkbox`,checked:C.has(e.id)||l.has(e.id),disabled:C.has(e.id)||!l.has(e.id)&&l.size>=w,onChange:t=>u(n=>{let r=new Set(n);return t.target.checked?r.add(e.id):r.delete(e.id),r})}),(0,K.jsx)(`span`,{title:e.name,children:e.id}),C.has(e.id)&&(0,K.jsx)(`small`,{children:o(`providerPickerAdded`)})]},e.id)),!p&&!v&&!T.length&&(0,K.jsx)(`p`,{className:`models-picker-empty`,children:o(d?`providerPickerNoMatch`:`providerPickerEmpty`)}),v&&(0,K.jsxs)(`div`,{className:`models-error`,role:`alert`,children:[(0,K.jsx)(`p`,{children:o(`providerPickerError_load`)}),(0,K.jsx)(`button`,{type:`button`,className:`models-button`,onClick:()=>x(e=>e+1),children:o(`retryAdmissionCheck`)})]})]}),h&&(0,K.jsx)(`p`,{className:`models-hint`,children:o(`providerPickerBounded`)}),(0,K.jsxs)(`footer`,{children:[(0,K.jsx)(`span`,{className:`models-hint`,"aria-live":`polite`,children:l.size>0&&o(`providerPickerSelected`,{count:l.size})}),(0,K.jsx)(`button`,{type:`button`,className:`models-button`,onClick:i,children:o(`cancel`)}),(0,K.jsx)(`button`,{type:`button`,className:`models-button`,disabled:!l.size||p||v,onClick:()=>a(s.filter(e=>l.has(e.id))),children:o(`providerPickerSave`)})]})]})})}function LF(e){let t=e.trim();if(!t)return;let n=/^(\d+(?:\.\d+)?)([km])?$/i.exec(t);if(!n)return NaN;let r=n[2]?.toLowerCase()===`m`?1e6:n[2]?.toLowerCase()===`k`?1e3:1,i=Number(n[1])*r,a=Math.round(i),o=Math.abs(i-a)<1e-6?a:i;return Number.isSafeInteger(o)&&o>0&&o<=1e8?o:NaN}function RF(e){if(e===void 0)return``;if(Number.isInteger(e)&&e>0){if(e%1e6==0)return`${e/1e6}M`;if(e%1e3==0)return`${e/1e3}K`}return String(e)}function zF({sessionId:e,providerId:t,configuration:n,auth:r,isNew:i,custom:a,taken:o,currentModel:s,availableModels:c,busy:l,onDirty:u,onSaving:d,onClose:f,onReload:p}){let{t:m}=cr(),[h]=(0,_.useState)(()=>{let e=n.providers?.find(e=>e.provider===t),i=n.models.filter(e=>e.provider===t).map(e=>({...e,rowKey:crypto.randomUUID()}));return{provider:t,name:e?.name||r?.name||t,baseUrl:e?.baseUrl||i[0]?.baseUrl||r?.baseUrl||``,api:e?.api||i[0]?.api||r?.api||`openai-completions`,models:i}}),[g]=(0,_.useState)(n.revision),[v,y]=(0,_.useState)(h),[b,x]=(0,_.useState)(``),S=!i&&!!r?.authMethods.includes(`oauth`),C=a||!!r?.authMethods.includes(`api_key`),[w,T]=(0,_.useState)(S&&(!r?.configured||r?.subscription||!C)?`oauth`:`api_key`),[E,D]=(0,_.useState)(!1),[O,k]=(0,_.useState)(!1),A=(0,_.useRef)(null),j=(0,_.useRef)(!1),[M,N]=(0,_.useState)(new Set),[P,F]=(0,_.useState)({}),[I,L]=(0,_.useState)(!1),[R,B]=(0,_.useState)(null),[V,H]=(0,_.useState)(!1),ee=(0,_.useRef)(null),te=(0,_.useRef)({onDirty:u,onSaving:d});te.current={onDirty:u,onSaving:d};let ne=JSON.stringify(v)!==JSON.stringify(h),re=ne||b.length>0;(0,_.useEffect)(()=>{te.current.onDirty(re)},[re]),(0,_.useEffect)(()=>{te.current.onSaving(I||E)},[I,E]),(0,_.useEffect)(()=>{O?j.current=!0:j.current&&(j.current=!1,A.current?.focus({preventScroll:!0}))},[O]),(0,_.useEffect)(()=>()=>{ee.current?.abort(),te.current.onSaving(!1),te.current.onDirty(!1)},[]);let ie=n.providers?.find(e=>e.provider===t)?.editable!==!1,ae=l||I||E,U=ae||V||!ie,oe=!/^[a-zA-Z0-9._-]+$/.test(v.provider)||[`__proto__`,`constructor`,`prototype`].includes(v.provider)||i&&a&&o.includes(v.provider),se=v.models.findIndex(e=>!e.id.trim()||[e.contextWindow,e.maxTokens].some(e=>e!==void 0&&!Number.isFinite(e))||v.models.some(t=>t.rowKey!==e.rowKey&&t.id.trim()===e.id.trim())),ce=se!==-1,le=i&&a||ne,ue=!oe&&!/[\r\n\u0000]/u.test(b)&&(V||!le||(!a||v.models.length>0)&&!ce&&!!v.baseUrl)&&(le||b.trim().length>0),de=e=>{y(t=>({...t,...e})),R!==`conflict`&&B(null)},fe=(e,t)=>de({models:v.models.map((n,r)=>r===e?{...n,...t}:n)}),W={id:``,name:``,reasoning:!1,provider:v.provider,baseUrl:v.baseUrl,api:v.api},pe=async()=>{if(ae||O||!ue||R===`conflict`)return;let t=new AbortController;ee.current=t,L(!0),B(null);let n=V,r=new rf;try{if(le&&!n){if(await r.changeProviderConfiguration(e,g,{action:`save`,configuration:{...v,name:v.name.trim()||v.provider,models:v.models.map(({rowKey:e,...t})=>({...t,id:t.id.trim(),name:t.name.trim()||t.id.trim(),provider:v.provider,baseUrl:v.baseUrl===h.baseUrl&&t.baseUrl||v.baseUrl,api:v.api===h.api?t.api:v.api}))}},t.signal),t.signal.aborted)return;n=!0,H(!0)}if(b.trim()&&await r.saveProviderKey(e,v.provider,b.trim(),t.signal),t.signal.aborted)return;x(``),te.current.onDirty(!1),f(v.name||v.provider,v.provider)}catch(e){t.signal.aborted||B(e instanceof tf&&e.code===`MODEL_CONFIGURATION_CONFLICT`?`conflict`:e instanceof tf&&e.code===`MODEL_NOT_AVAILABLE`?`current`:n?`key`:`failed`)}finally{t.signal.aborted||L(!1)}},me=e=>(0,K.jsxs)(`label`,{className:`models-field`,children:[m(e===`name`?`providerDisplayName`:`modelConfig_${e}`),(0,K.jsx)(`input`,{type:e===`baseUrl`?`url`:`text`,value:v[e],maxLength:e===`baseUrl`?2048:160,autoComplete:`off`,disabled:U,required:e===`provider`||e===`baseUrl`&&le,"aria-invalid":e===`provider`&&v.provider.length>0&&oe,placeholder:e===`provider`?`my-provider`:e===`name`?v.provider:`https://api.example.com/v1`,onChange:t=>de({[e]:t.target.value})})]}),he=(0,K.jsxs)(`label`,{className:`models-field`,children:[m(`modelConfig_api`),(0,K.jsxs)(`select`,{value:v.api,disabled:U,onChange:e=>{let t=e.target.value;(t===`openai-responses`||t===`openai-completions`||t===`anthropic-messages`)&&de({api:t})},children:[(0,K.jsx)(`option`,{value:`openai-completions`,children:`OpenAI Chat Completions`}),(0,K.jsx)(`option`,{value:`openai-responses`,children:`OpenAI Responses`}),(0,K.jsx)(`option`,{value:`anthropic-messages`,children:`Anthropic Messages`})]})]}),ge=(0,K.jsxs)(`div`,{className:`models-catalog`,children:[(0,K.jsxs)(`div`,{className:`models-list-head`,children:[(0,K.jsx)(`span`,{children:m(`modelSettings`)}),(0,K.jsx)(`button`,{type:`button`,ref:A,className:`models-link`,disabled:U||oe||!v.baseUrl,onClick:()=>k(!0),children:m(`providerFetchModels`)})]}),!ie&&(0,K.jsx)(`p`,{className:`models-hint`,children:m(`providerModelsReadOnly`)}),v.models.length===0&&(0,K.jsx)(`p`,{className:`models-empty`,children:m(a?`providerModelsEmpty`:`providerModelsInherited`,{count:c.length})}),(0,K.jsx)(`div`,{className:`models-entry-list`,children:v.models.map((e,t)=>(0,K.jsxs)(`div`,{className:`models-entry`,children:[(0,K.jsxs)(`div`,{className:`models-entry-row`,children:[(0,K.jsx)(`input`,{"aria-label":m(`providerModelId`,{number:t+1}),placeholder:m(`modelConfig_id`),value:e.id,maxLength:256,required:!0,disabled:U||s?.provider===v.provider&&s.id===e.id,onChange:e=>fe(t,{id:e.target.value})}),(0,K.jsx)(`input`,{"aria-label":m(`providerModelName`,{number:t+1}),placeholder:m(`modelConfig_name`),value:e.name,maxLength:256,disabled:U,onChange:e=>fe(t,{name:e.target.value})}),(0,K.jsx)(`button`,{type:`button`,className:`models-icon`,"aria-label":m(`providerModelDetails`,{model:e.name||e.id||t+1}),"aria-expanded":M.has(e.rowKey),title:m(`providerModelOptions`),onClick:()=>N(t=>{let n=new Set(t);return n.delete(e.rowKey)||n.add(e.rowKey),n}),children:(0,K.jsx)(z,{})}),(0,K.jsx)(`button`,{type:`button`,className:`models-icon danger`,"aria-label":m(`providerRemoveModel`,{model:e.name||e.id||t+1}),disabled:U||s?.provider===v.provider&&s.id===e.id,title:s?.provider===v.provider&&s.id===e.id?m(`providerCurrentRemoval`):m(`providerRemoveModel`,{model:e.name||e.id||t+1}),onClick:()=>{de({models:v.models.filter((e,n)=>n!==t)}),N(t=>new Set([...t].filter(t=>t!==e.rowKey))),F(t=>Object.fromEntries(Object.entries(t).filter(([t])=>t!==e.rowKey)))},children:(0,K.jsx)(kt,{})})]}),M.has(e.rowKey)&&(0,K.jsxs)(`div`,{className:`models-entry-details`,children:[[`contextWindow`,`maxTokens`].map(n=>(0,K.jsxs)(`label`,{className:`models-field models-capacity`,children:[m(`modelConfig_${n}`),(0,K.jsx)(`input`,{type:`text`,inputMode:`numeric`,autoComplete:`off`,spellCheck:!1,"aria-label":m(`providerCapacityLabel`,{field:m(`modelConfig_${n}`),number:t+1}),"aria-invalid":e[n]!==void 0&&!Number.isFinite(e[n]),placeholder:n===`contextWindow`?`256K`:`32K`,value:P[e.rowKey]?.[n]??RF(e[n]),disabled:U,onChange:r=>{let i=r.target.value;F(t=>({...t,[e.rowKey]:{...t[e.rowKey],[n]:i}})),fe(t,{[n]:LF(i)})}})]},n)),(0,K.jsxs)(`fieldset`,{className:`models-input-types`,"aria-label":m(`providerCapacityLabel`,{field:m(`providerInputTypes`),number:t+1}),children:[(0,K.jsx)(`legend`,{children:m(`providerInputTypes`)}),(0,K.jsx)(`div`,{children:[`text`,`image`].map(n=>{let r=e.input??[`text`];return(0,K.jsxs)(`label`,{className:`models-checkbox`,children:[(0,K.jsx)(`input`,{type:`checkbox`,checked:r.includes(n),disabled:U||r.length===1&&r.includes(n),onChange:e=>fe(t,{input:[`text`,`image`].filter(t=>t===n?e.target.checked:r.includes(t))})}),m(n===`text`?`providerInputText`:`providerInputImage`)]},n)})})]}),(0,K.jsx)(`p`,{className:`models-hint models-capability-hint`,children:m(`providerImageHint`)}),(0,K.jsxs)(`label`,{className:`models-checkbox models-reasoning`,children:[(0,K.jsx)(`input`,{type:`checkbox`,checked:e.reasoning,disabled:U,onChange:e=>fe(t,{reasoning:e.target.checked})}),m(`modelConfig_reasoning`)]}),(0,K.jsx)(`p`,{className:`models-hint models-capability-hint`,children:m(`providerReasoningHint`)})]})]},e.rowKey))}),(0,K.jsxs)(`button`,{type:`button`,className:`models-button models-add-model`,disabled:U||v.models.length>=100,onClick:()=>{de({models:[...v.models,{...W,rowKey:crypto.randomUUID()}]})},children:[(0,K.jsx)(lt,{"aria-hidden":`true`}),m(`addModel`)]}),ce&&(0,K.jsx)(`p`,{className:`models-error`,role:`alert`,children:m(`providerModelInvalid`,{number:se+1})})]});return(0,K.jsxs)(`form`,{className:`models-editor`,onSubmit:e=>{e.preventDefault(),pe()},children:[!i&&a&&(0,K.jsxs)(`div`,{className:`models-editor-heading`,children:[(0,K.jsx)(`span`,{children:v.name||v.provider}),v.name!==v.provider&&(0,K.jsx)(`small`,{children:v.provider})]}),i&&a&&(0,K.jsxs)(K.Fragment,{children:[me(`provider`),v.provider&&oe&&(0,K.jsx)(`p`,{className:`models-error`,children:m(`providerIdInvalid`)}),me(`name`),me(`baseUrl`),he]}),S&&C&&(0,K.jsxs)(`fieldset`,{className:`models-add-modes`,"aria-label":m(`accountLoginMethod`),children:[(0,K.jsx)(`button`,{type:`button`,"aria-pressed":w===`oauth`,disabled:ae,onClick:()=>T(`oauth`),children:m(`accountLoginTab`)}),(0,K.jsx)(`button`,{type:`button`,"aria-pressed":w===`api_key`,disabled:ae,onClick:()=>T(`api_key`),children:m(`accountLoginKeyTab`)})]}),S&&w===`oauth`&&r&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(FF,{sessionId:e,auth:r,busy:l||I||re,onSaving:D,onAuthenticated:()=>f(v.name||v.provider,v.provider),onReload:p}),re&&(0,K.jsx)(`p`,{className:`models-hint`,children:m(`accountLoginUnsaved`)})]}),C&&w===`api_key`?(0,K.jsxs)(`label`,{className:`models-field`,children:[m(`providerApiKey`),(0,K.jsx)(`input`,{type:`password`,autoComplete:`new-password`,spellCheck:!1,maxLength:8192,value:b,placeholder:m(r?.configured?`providerKeyKeep`:`providerKeyOptional`),disabled:ae,onChange:e=>{x(e.target.value),R!==`conflict`&&B(null)}})]}):S?null:(0,K.jsx)(`p`,{className:`models-hint`,children:m(`providerNativeAuth`)}),i&&a?ge:(0,K.jsxs)(`details`,{className:`models-customized`,children:[(0,K.jsx)(`summary`,{children:m(`providerCustomSettings`)}),(0,K.jsxs)(`div`,{children:[a&&me(`name`),me(`baseUrl`),a&&he,ge]})]}),R&&(0,K.jsx)(`p`,{className:`models-error`,role:`alert`,children:m(R===`conflict`?`modelConfigurationConflict`:R===`key`?`providerProfileSavedKeyFailed`:R===`current`?`providerCurrentRemoval`:`providerConfigurationFailed`)}),R===`conflict`&&(0,K.jsx)(`button`,{type:`button`,className:`models-button`,onClick:p,children:m(`providerReload`)}),!E&&(0,K.jsxs)(`div`,{className:`models-editor-actions`,children:[(0,K.jsx)(`button`,{type:`button`,className:`models-button`,disabled:I,onClick:()=>V?p():f(),children:m(`cancel`)}),(w===`api_key`||ne)&&(0,K.jsx)(`button`,{type:`submit`,className:`models-button primary`,disabled:ae||!ue||R===`conflict`,"aria-busy":I,children:m(I?`savingSettings`:`providerSave`)})]}),O&&(0,K.jsx)(IF,{sessionId:e,template:W,existingIds:v.models.map(e=>e.id),apiKey:b,onClose:()=>k(!1),onAdd:e=>{de({models:[...v.models,...e.map(e=>({...W,...e,rowKey:crypto.randomUUID()}))]}),k(!1)}})]})}function BF({sessionId:e,sessionPath:t,provider:n,purpose:r,initialModel:i,busy:a,onSelectModel:o,onDefaultSaved:s,onSaving:c,onClose:l}){let{t:u}=cr(),[d,f]=(0,_.useState)(``),[p,m]=(0,_.useState)([]),[h,g]=(0,_.useState)(i?`${i.provider}/${i.id}`:``),[v,y]=(0,_.useState)(!0),[b,x]=(0,_.useState)(!1),[S,C]=(0,_.useState)(0),[w,T]=(0,_.useState)(0),[E,D]=(0,_.useState)(!1),[O,k]=(0,_.useState)(!1),[A,j]=(0,_.useState)(null);(0,_.useEffect)(()=>{let t=new AbortController;y(!0),x(!1);let r=window.setTimeout(()=>{new rf().searchModels(d.trim(),e,t.signal,n).then(e=>{t.signal.aborted||(m(e.models),C(e.truncation.matchesOmitted),y(!1))},()=>{t.signal.aborted||(x(!0),y(!1))})},d?200:0);return()=>{t.abort(),window.clearTimeout(r)}},[e,n,d,w]);let M=p.find(e=>`${e.provider}/${e.id}`===h)??p[0],N=new Map;for(let e of p){let t=N.get(e.provider);t?t.push(e):N.set(e.provider,[e])}let P=async()=>{if(!M||v||O||a||!t)return;k(!0),c(!0),j(null);let n=!1;try{if(r===`use`){if(!await o(`${M.provider}/${M.id}`))throw Error(`selection failed`);n=!0}(r==="default"||E)&&s(await new rf().saveModelDefault(M.provider,M.id,e,t)),l()}catch{j(n?`modelDefaultPartial`:r==="default"?`modelDefaultSaveFailed`:`modelConnectionUseFailed`)}finally{k(!1),c(!1)}};return(0,K.jsxs)(`div`,{className:`models-connection-choice`,children:[(0,K.jsx)(`p`,{className:`models-hint`,children:u(r==="default"?`modelDefaultHint`:`modelConnectionNextHint`)}),(p.length>8||S>0||d)&&(0,K.jsx)(`input`,{type:`search`,"aria-label":u(`modelConnectionSearch`),placeholder:u(`modelConnectionSearch`),maxLength:200,value:d,disabled:O,onChange:e=>f(e.target.value)}),b?(0,K.jsxs)(`p`,{className:`models-error`,role:`alert`,children:[u(`modelConnectionLoadFailed`),` `,(0,K.jsx)(`button`,{type:`button`,className:`models-link`,onClick:()=>T(e=>e+1),children:u(`retryAdmissionCheck`)})]}):v?(0,K.jsx)(`p`,{className:`models-hint`,role:`status`,children:u(`loadingModels`)}):p.length?(0,K.jsx)(NF,{label:u(`selectModel`),className:`models-provider-picker`,placement:`below`,value:M?`${M.provider}/${M.id}`:``,isDisabled:O,options:[...N].map(([e,t])=>({type:`section`,title:e,options:t.map(e=>({value:`${e.provider}/${e.id}`,label:e.name||e.id,description:`${e.provider} · ${e.id}`,icon:(0,K.jsx)(ON,{id:e.provider})}))})),onChange:e=>g(e)}):(0,K.jsx)(`p`,{className:`models-hint`,children:u(d?`modelConnectionNoMatch`:`modelConnectionNoModels`)}),S>0&&!v&&(0,K.jsx)(`p`,{className:`models-hint`,children:u(`modelConnectionMore`,{count:S})}),r===`use`&&(0,K.jsxs)(`label`,{className:`models-checkbox`,children:[(0,K.jsx)(`input`,{type:`checkbox`,checked:E,disabled:O,onChange:e=>D(e.target.checked)}),u(`modelMakeDefault`)]}),A&&(0,K.jsx)(`p`,{className:`models-error`,role:`alert`,children:u(A)}),(0,K.jsxs)(`div`,{className:`models-editor-actions`,children:[(0,K.jsx)(`button`,{type:`button`,className:`models-button`,disabled:O,onClick:l,children:u(`cancel`)}),(0,K.jsx)(`button`,{type:`button`,className:`models-button primary`,disabled:O||a||v||b||!M||!t,onClick:()=>void P(),children:u(O?`providerSaving`:r==="default"?`modelDefaultSave`:`modelConnectionUse`)})]})]})}function VF({sessionId:e,sessionPath:t,models:n,currentModel:r,busy:i,focusCredentials:a,onSaved:o,onSelectModel:s,onDraftChange:c,onSavingChange:l}){let{t:u}=cr(),[d,f]=(0,_.useState)(null),[p,m]=(0,_.useState)(0),[h,g]=(0,_.useState)(!0),[v,y]=(0,_.useState)(!1),[b,x]=(0,_.useState)(null),[S,C]=(0,_.useState)([]),[w,T]=(0,_.useState)(!1),[E,D]=(0,_.useState)(`account`),[O,k]=(0,_.useState)(``),[A,j]=(0,_.useState)(``),[M,N]=(0,_.useState)({}),[P,F]=(0,_.useState)(!1),[I,L]=(0,_.useState)({}),[R,z]=(0,_.useState)(!1),B=P||R||Object.values(I).some(Boolean),[V,H]=(0,_.useState)(null),[ee,te]=(0,_.useState)(!1),[ne,re]=(0,_.useState)(null),[ie,ae]=(0,_.useState)(null),[U,oe]=(0,_.useState)(null),[se,ce]=(0,_.useState)(null),le=(0,_.useRef)(null),ue=(0,_.useRef)(a),de=(0,_.useRef)(null),fe=(0,_.useRef)(new Map),W=(0,_.useRef)(null),pe=(0,_.useRef)(null),me=(0,_.useRef)({onDraftChange:c,onSavingChange:l});me.current={onDraftChange:c,onSavingChange:l},(0,_.useEffect)(()=>{c(Object.values(M).some(Boolean))},[M,c]),(0,_.useEffect)(()=>{l(B)},[B,l]),(0,_.useEffect)(()=>{!ne&&!B&&pe.current&&(pe.current.focus({preventScroll:!0}),pe.current=null)},[ne,B]),(0,_.useEffect)(()=>{if(!de.current)return;let e=de.current;de.current=null,(fe.current.get(e)??W.current)?.focus({preventScroll:!0})}),(0,_.useEffect)(()=>()=>{le.current?.abort(),me.current.onDraftChange(!1),me.current.onSavingChange(!1)},[]),(0,_.useEffect)(()=>{let t=new AbortController;g(!0),y(!1);let n=new rf;return Promise.all([n.modelConfigurations(e,t.signal),n.providerAuth(e,t.signal)]).then(([e,n])=>{if(!t.signal.aborted&&(f({configuration:e,auth:n}),g(!1),ue.current)){ue.current=!1;let e=r?.provider||n.providers.find(e=>e.configured)?.id;e&&(x(e),C([e]))}},()=>{t.signal.aborted||(y(!0),g(!1))}),()=>t.abort()},[e,p,r?.provider]),(0,_.useEffect)(()=>{let t=new AbortController;return te(!1),new rf().modelDefaults(e,t.signal).then(e=>{t.signal.aborted||H(e)},()=>{t.signal.aborted||te(!0)}),()=>t.abort()},[e,p]);let he=d?.configuration,ge=new Set([...he?.providers?.map(e=>e.provider)??[],...he?.models.map(e=>e.provider)??[]]),_e=new Set([...ge,...d?.auth.providers.filter(e=>e.configured).map(e=>e.id)??[],...n.map(e=>e.provider),...S.filter(e=>!e.startsWith(`add:`))]),ve=[..._e].map(e=>{let t=d?.auth.providers.find(t=>t.id===e);return{id:e,name:he?.providers?.find(t=>t.provider===e)?.name||t?.name||e,auth:t}}),ye=d?.auth.providers.filter(e=>e.authMethods.includes(`api_key`)&&!_e.has(e.id))??[],be=d?.auth.providers.filter(e=>e.authMethods.includes(`oauth`)&&!e.subscription)??[],xe=be.find(e=>e.id===O)??be[0],Se=ye.find(e=>e.id===A)??ye[0],Ce=[{id:`account`,label:`accountLoginTab`,hint:`providerAccountHint`,available:be.length>0},{id:`catalog`,label:`providerAddCatalog`,hint:`providerCatalogHint`,available:ye.length>0},{id:`custom`,label:`providerAddCustom`,hint:`providerCustomHint`,available:!0}],we=e=>{D(e);let t=e===`custom`?`add:custom`:e===`account`?xe&&`add:account:${xe.id}`:Se&&`add:${Se.id}`;t&&C(e=>e.includes(t)?e:[...e,t])},Te=e=>{pe.current=null,re(null),ae(null),T(!1),x(b===e?null:e),C(t=>t.includes(e)?t:[...t,e])},G=(e,t,n)=>{pe.current=null,de.current=e;let r=t=>e.startsWith(`add:`)?t.startsWith(`add:`):t===e;C(e=>e.filter(e=>!r(e))),N(e=>Object.fromEntries(Object.entries(e).filter(([e])=>!r(e)))),e.startsWith(`add:`)?T(!1):x(null),t&&(ae(t),re({purpose:`use`,provider:n??e}),m(e=>e+1),o().catch(()=>!1))},Ee=(t,a,s,c)=>{if(!he)return null;let l=d?.auth.providers.find(e=>e.id===a),f=e=>L(n=>n[t]===e?n:{...n,[t]:e}),p=()=>{G(t),m(e=>e+1),o().catch(()=>!1)};return t.startsWith(`add:account:`)?l&&(0,K.jsxs)(`div`,{className:`models-editor`,children:[(0,K.jsx)(FF,{sessionId:e,auth:l,busy:i,onSaving:f,onAuthenticated:()=>G(t,l.name||l.id,l.id),onReload:p}),!I[t]&&(0,K.jsx)(`div`,{className:`models-editor-actions`,children:(0,K.jsx)(`button`,{type:`button`,className:`models-button`,onClick:()=>G(t),children:u(`cancel`)})})]}):(0,K.jsx)(zF,{sessionId:e,providerId:a,configuration:he,auth:l,isNew:s,custom:c,taken:[...d?.auth.providers.map(e=>e.id)??[],...ge],currentModel:r,availableModels:n.filter(e=>e.provider===a),busy:i,onDirty:e=>N(n=>n[t]===e?n:{...n,[t]:e}),onSaving:f,onClose:(e,n)=>G(t,e,n),onReload:p},t)},De=e=>ve.find(t=>t.id===e)?.name??e,Oe=e=>n.find(t=>t.provider===e.provider&&t.id===e.id)?.name||e.id,ke=(e,t,n)=>{pe.current=t,re({purpose:e,provider:n}),x(null),T(!1)},Ae=(n,a)=>(0,K.jsx)(BF,{sessionId:e,sessionPath:t,provider:a,purpose:n,initialModel:n==="default"?V?.model:r,busy:i,onSelectModel:s,onDefaultSaved:e=>{H(e),te(!1),o().catch(()=>!1)},onSaving:z,onClose:()=>{re(null)}},`${n}:${a??`all`}`);return(0,K.jsxs)(`div`,{className:`models-page`,children:[(0,K.jsxs)(`div`,{className:`models-section`,children:[(0,K.jsx)(`h2`,{children:u(`modelSettings`)}),(0,K.jsx)(`p`,{className:`models-intro`,children:u(`modelsIntro`)}),ie&&(0,K.jsx)(`p`,{className:`models-saved`,role:`status`,children:u(`providerSaved`,{provider:ie})}),v&&(0,K.jsxs)(`div`,{className:`models-error`,role:`alert`,children:[u(`providerLoadFailed`),` `,(0,K.jsx)(`button`,{type:`button`,className:`models-button`,disabled:h,onClick:()=>m(e=>e+1),children:u(`retryAdmissionCheck`)})]}),se&&!U&&(0,K.jsxs)(`div`,{className:`models-error`,role:`alert`,children:[se,` `,(0,K.jsx)(`button`,{type:`button`,className:`models-button`,disabled:h,onClick:()=>{ce(null),m(e=>e+1)},children:u(`refreshStatus`)})]}),!d&&h&&(0,K.jsx)(`p`,{className:`models-hint`,role:`status`,children:u(`providerLoading`)}),(0,K.jsxs)(`div`,{className:`models-default-card`,children:[(0,K.jsxs)(`div`,{className:`models-default-row`,children:[(0,K.jsxs)(`div`,{className:`models-default-copy`,children:[(0,K.jsx)(`span`,{className:`models-default-title`,children:u(`modelDefaultTitle`)}),ee?(0,K.jsx)(`span`,{className:`models-hint`,children:u(`modelDefaultReadFailed`)}):V?.model?(0,K.jsxs)(`span`,{className:`models-default-value`,children:[(0,K.jsx)(ON,{id:V.model.provider}),(0,K.jsxs)(`span`,{children:[Oe(V.model),(0,K.jsx)(`small`,{children:De(V.model.provider)})]})]}):(0,K.jsx)(`span`,{className:`models-hint`,children:u(V?`modelDefaultNotSet`:`loadingModels`)})]}),(0,K.jsx)(`button`,{type:`button`,className:`models-button`,disabled:B||i||Object.values(M).some(Boolean)||!t,"aria-expanded":ne?.purpose==="default",onClick:e=>ee?m(e=>e+1):ne?.purpose==="default"?re(null):ke(`default`,e.currentTarget),children:u(ee?`refreshStatus`:`modelDefaultChoose`)})]}),V?.projectOverride&&(0,K.jsx)(`p`,{className:`models-hint`,children:u(`modelDefaultProjectOverride`,{model:`${De(V.projectOverride.provider)} / ${Oe(V.projectOverride)}`})}),ne?.purpose==="default"&&Ae(`default`)]}),(0,K.jsx)(`ul`,{className:`models-provider-list`,children:ve.map(e=>{let n=!w&&b===e.id,a=e.auth?.custom??ge.has(e.id);return(0,K.jsxs)(`li`,{className:`models-provider-card`,children:[(0,K.jsxs)(`div`,{className:`models-provider-head`,children:[(0,K.jsxs)(`div`,{className:`models-provider-identity`,children:[(0,K.jsx)(`span`,{className:`models-provider-avatar`,"aria-hidden":`true`,children:(0,K.jsx)(ON,{id:e.id})}),(0,K.jsxs)(`div`,{className:`models-provider-label`,children:[(0,K.jsx)(`span`,{className:`models-provider-name`,children:e.name}),a&&(0,K.jsx)(`span`,{className:`models-provider-tag`,children:u(`providerCustomTag`)}),V?.model?.provider===e.id&&(0,K.jsx)(`span`,{className:`models-provider-tag`,children:u(`modelDefaultBadge`)}),r?.provider===e.id&&(0,K.jsx)(`span`,{className:`models-provider-tag`,children:u(`modelCurrentBadge`)}),e.auth&&(0,K.jsxs)(`span`,{className:`models-provider-status`,children:[(0,K.jsx)(`span`,{className:`models-credential-dot ${e.auth.configured?`configured`:`missing`}`,role:`img`,"aria-label":u(e.auth.configured?`credentialConfigured`:`credentialMissing`),title:u(e.auth.configured?`credentialConfigured`:`credentialMissing`)}),u(e.auth.subscription?`accountLoginConfigured`:e.auth.configured?`credentialConfigured`:`credentialMissing`)]})]})]}),(0,K.jsxs)(`div`,{className:`models-provider-actions`,children:[e.auth?.configured&&(0,K.jsx)(`button`,{type:`button`,className:`models-button`,disabled:B||i||Object.values(M).some(Boolean)||!t,"aria-label":u(`modelConnectionChooseProvider`,{provider:e.name}),"aria-expanded":ne?.purpose===`use`&&ne.provider===e.id,onClick:t=>ne?.purpose===`use`&&ne.provider===e.id?re(null):ke(`use`,t.currentTarget,e.id),children:u(`selectModel`)}),(0,K.jsx)(`button`,{type:`button`,className:`models-button`,"aria-label":u(`editProvider`,{provider:e.name}),ref:t=>{t?fe.current.set(e.id,t):fe.current.delete(e.id)},"aria-expanded":n,disabled:B,onClick:()=>Te(e.id),children:u(e.auth?.authMethods.includes(`oauth`)&&!e.auth.configured?`accountLoginStart`:`providerEdit`)}),ge.has(e.id)&&(0,K.jsx)(`button`,{type:`button`,className:`models-button danger`,"aria-label":u(`removeProvider`,{provider:e.name}),disabled:B||i||r?.provider===e.id,title:r?.provider===e.id?u(`providerCurrentRemoval`):void 0,onClick:()=>{oe(e.id),ce(null)},children:u(`providerRemove`)})]})]}),ne?.purpose===`use`&&ne.provider===e.id&&Ae(`use`,e.id),S.includes(e.id)&&(0,K.jsx)(`div`,{hidden:!n,children:Ee(e.id,e.id,!1,a)})]},e.id)})}),he&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsxs)(`div`,{hidden:!w,className:`models-add-card`,children:[(0,K.jsx)(`fieldset`,{className:`models-add-modes`,"aria-label":u(`providerAddMode`),onKeyDown:e=>{if(B||![`ArrowLeft`,`ArrowRight`,`Home`,`End`].includes(e.key))return;e.preventDefault();let t=Ce.filter(e=>e.available),n=t.findIndex(e=>e.id===E),r=t[e.key===`Home`?0:e.key===`End`?t.length-1:(n+(e.key===`ArrowRight`?1:-1)+t.length)%t.length].id;we(r),e.currentTarget.querySelectorAll(`button`)[Ce.findIndex(e=>e.id===r)]?.focus()},children:Ce.map(e=>(0,K.jsx)(`button`,{type:`button`,"aria-pressed":E===e.id,disabled:B||!e.available,onClick:()=>we(e.id),children:u(e.label)},e.id))}),(0,K.jsx)(`p`,{className:`models-hint`,children:u(Ce.find(e=>e.id===E)?.hint??`providerCustomHint`)}),(0,K.jsxs)(`div`,{hidden:E!==`account`,children:[xe&&(0,K.jsx)(`div`,{className:`models-provider-select`,children:(0,K.jsx)(NF,{label:u(`provider`),className:`models-provider-picker`,options:be.map(e=>({value:e.id,label:e.name||e.id,icon:(0,K.jsx)(ON,{id:e.id})})),value:xe.id,isDisabled:B,placement:`below`,onChange:e=>{k(e);let t=`add:account:${e}`;C(e=>e.includes(t)?e:[...e,t])}})}),S.filter(e=>e.startsWith(`add:account:`)).map(e=>(0,K.jsx)(`div`,{hidden:e!==`add:account:${xe?.id}`,children:Ee(e,e.slice(12),!0,!1)},e))]}),(0,K.jsxs)(`div`,{hidden:E!==`catalog`,children:[Se&&(0,K.jsx)(`div`,{className:`models-provider-select`,children:(0,K.jsx)(NF,{label:u(`provider`),className:`models-provider-picker`,options:ye.map(e=>({value:e.id,label:e.name||e.id,icon:(0,K.jsx)(ON,{id:e.id})})),value:Se.id,isDisabled:B,placement:`below`,onChange:e=>{j(e);let t=`add:${e}`;C(e=>e.includes(t)?e:[...e,t])}})}),S.filter(e=>e.startsWith(`add:`)&&e!==`add:custom`&&!e.startsWith(`add:account:`)).map(e=>(0,K.jsx)(`div`,{hidden:e!==`add:${Se?.id}`,children:Ee(e,e.slice(4),!0,!1)},e))]}),S.includes(`add:custom`)&&(0,K.jsx)(`div`,{hidden:E!==`custom`,children:Ee(`add:custom`,``,!0,!0)})]}),!w&&(0,K.jsxs)(`button`,{type:`button`,className:`models-add-button`,ref:W,disabled:B,onClick:()=>{pe.current=null,re(null),T(!0),x(null),ae(null),we(Ce.find(e=>e.id===E)?.available?E:Ce.find(e=>e.available).id)},children:[(0,K.jsx)(lt,{"aria-hidden":`true`}),u(`providerAdd`)]})]}),i&&(0,K.jsx)(`p`,{className:`models-hint`,role:`status`,children:u(`modelSelectionBusy`)})]}),U&&(0,K.jsx)(HP,{isOpen:!0,title:u(`removeProvider`,{provider:ve.find(e=>e.id===U)?.name||U}),description:se||u(`providerRemoveDetail`),isActionLoading:B,cancelLabel:u(`cancel`),actionLabel:u(B?`savingSettings`:`providerRemove`),onOpenChange:e=>{!e&&!B&&oe(null)},onAction:()=>{if(B||i||!he)return;let t=new AbortController;le.current=t,F(!0),ce(null),new rf().changeProviderConfiguration(e,he.revision,{action:`remove`,provider:U},t.signal).then(()=>{t.signal.aborted||(G(U),oe(null),m(e=>e+1),o().catch(()=>!1))},e=>{t.signal.aborted||ce(u(e instanceof tf&&e.code===`MODEL_CONFIGURATION_CONFLICT`?`modelConfigurationConflict`:`providerConfigurationFailed`))}).finally(()=>{t.signal.aborted||F(!1)})}})]})}var HF=20,UF={track:{kVAEAm:`x10l6tqk`,kWkggS:`xdsb6cv`,kaIpWk:`xjspbzw`,$$css:!0},trackHorizontal:{kLqNvP:`x1o0tod`,kt4wiu:`xtijo5x`,kZKoxP:`xqu0tyb`,k87sOh:`xwa60dl`,k3aq6I:`x1cb1t30`,$$css:!0},trackVertical:{k87sOh:`x13vifvy`,krVfgx:`x1ey2m1c`,kzqmXN:`x51ohtg`,$$css:!0},filledTrack:{kVAEAm:`x10l6tqk`,kWkggS:`x1ewilqj`,kaIpWk:`xjspbzw`,$$css:!0},filledTrackHorizontal:{kZKoxP:`xqu0tyb`,k87sOh:`xwa60dl`,k3aq6I:`x1cb1t30`,$$css:!0},filledTrackVertical:{kzqmXN:`x51ohtg`,$$css:!0},thumb:{kVAEAm:`x10l6tqk`,kzqmXN:`xw4jnvo`,kZKoxP:`x1qx5ct2`,kaIpWk:`xjspbzw`,kWkggS:`x1ewilqj`,k3aq6I:`x11lhmoz`,k1ekBW:`x106061f`,kIyJzY:`xuedmi6 x12w9bfk`,kAMwcw:`xlr8y92`,kI3sdo:`x1a2a7pz`,kkrTdU:`x1jm3nie x16khyan`,kY2c9j:`x1vjfegm`,$$css:!0},thumbHorizontal:{k87sOh:`xwa60dl`,k3aq6I:`x11lhmoz xoffwj3`,$$css:!0},thumbHover:{kWkggS:`x1ewilqj xvxo0qp`,$$css:!0},thumbDisabled:{kWkggS:`xwmxj5m`,kkrTdU:`xt0e3qv`,$$css:!0}};function WF(e,t,n){return Math.min(Math.max(e,t),n)}function GF(e){if(Math.abs(e)<1){let t=e.toExponential().split(`e-`);if(t.length===2)return(t[0].split(`.`)[1]?.length??0)+parseInt(t[1],10)}let t=String(e).split(`.`)[1];return t?t.length:0}function KF(e,t,n){if(n<=0)return e;let r=t+Math.round((e-t)/n)*n,i=Math.min(Math.max(GF(t),GF(n)),20);return Number(r.toFixed(i))}function qF(e,t,n){return n===t?0:(e-t)/(n-t)*100}var JF=HF/2;function YF(e){return QF(e,JF-e/100*HF)}function XF(e,t){let n=t-e;return QF(n,-(n/100)*HF)}function ZF(e,t){let n=t-HF;return n>0?(e-JF)/n:t>0?e/t:0}function QF(e,t){let n=e=>Number(e.toFixed(3));return`calc(${n(e)}% ${t<0?`-`:`+`} ${Math.abs(n(t))}px)`}function $F({ref:e,...t}){let{label:n,isLabelHidden:r=!1,description:i,isDisabled:a=!1,disabledMessage:o,isOptional:s=!1,isRequired:c=!1,status:l,labelTooltip:u,min:d=0,max:f=100,step:p=1,orientation:m=`horizontal`,formatValue:h,htmlName:g,valueDisplay:v=`tooltip`,marks:y,width:b,xstyle:x,className:S,style:C,"data-testid":w,value:T,onChange:E,onChangeEnd:D}=t,O=Array.isArray(T),k=O&&`minStepsBetweenThumbs`in t?t.minStepsBetweenThumbs??0:0,A=m===`horizontal`,j=(0,_.useId)(),M=(0,_.useId)(),N=(0,_.useId)(),P=(0,_.useId)(),F=(0,_.useId)(),I=(0,_.useRef)(null),L=(0,_.useRef)(null),[R,z]=(0,_.useState)(null),[B,V]=(0,_.useState)(null);(0,_.useEffect)(()=>{Zi()},[]);let H=(0,_.useCallback)((e,t)=>{V(!a&&Qi()===`keyboard`?e:null)},[a]),ee=(0,_.useCallback)(e=>{V(null)},[]),te=a&&!!o,ne=po({placement:`above`,focusTrigger:`always`,isEnabled:te}),re=c&&!s,ie=[];i&&ie.push(N),l?.message&&ie.push(P),re&&ie.push(F),te&&ie.push(ne.describedBy);let ae=ie.length>0?ie.join(` `):void 0,U=(0,_.useMemo)(()=>(Array.isArray(T)?T:[T??d]).map(e=>WF(e,d,f)),[T,d,f]),oe=(0,_.useRef)(U);oe.current=U;let se=(0,_.useCallback)((e,t)=>{let n=I.current;if(!n)return d;let r=n.getBoundingClientRect(),i;return i=A?ZF(cA(n)?r.right-e:e-r.left,r.width):1-ZF(t-r.top,r.height),i=WF(i,0,1),WF(KF(d+i*(f-d),d,p),d,f)},[d,f,p,A]),ce=(0,_.useCallback)(e=>{if(!O)return 0;let[t,n]=U;return Math.abs(e-t)<=Math.abs(e-n)?0:1},[O,U]),le=(0,_.useCallback)((e,t)=>{if(a)return;let n=WF(KF(t,d,p),d,f);if(O){let t=[...U];t[e]=n;let r=k*p;e===0?t[0]=Math.min(t[0],t[1]-r):t[1]=Math.max(t[1],t[0]+r),t[0]=WF(t[0],d,f),t[1]=WF(t[1],d,f),E?.(t)}else E?.(n)},[a,O,U,d,f,p,k,E]),ue=(0,_.useRef)(D);ue.current=D;let de=(0,_.useCallback)(e=>{let t=e??oe.current,n=ue.current;O?n?.(t):n?.(t[0])},[O]),fe=(0,_.useCallback)(e=>{if(a)return;e.preventDefault();let t=e.target.closest(`[data-mark-value]`),n=t?Number(t.dataset.markValue):se(e.clientX,e.clientY),r=ce(n);L.current=r,z(r),le(r,n);let i=I.current;i&&i.querySelectorAll(`[role="slider"]`)[r]?.focus(),V(null),typeof e.currentTarget.setPointerCapture==`function`&&e.currentTarget.setPointerCapture(e.pointerId)},[a,se,ce,le]),W=(0,_.useCallback)(e=>{if(L.current===null||a)return;let t=se(e.clientX,e.clientY);le(L.current,t)},[a,se,le]),pe=(0,_.useCallback)(e=>{L.current!==null&&(L.current=null,z(null),de())},[de]),me=(0,_.useCallback)((e,t)=>{if(a)return;Qi()===`keyboard`&&V(e);let n=U[e],r;switch(t.key){case`ArrowRight`:case`ArrowUp`:r=n+p;break;case`ArrowLeft`:case`ArrowDown`:r=n-p;break;case`PageUp`:r=n+p*10;break;case`PageDown`:r=n-p*10;break;case`Home`:r=d;break;case`End`:r=f;break;default:return}t.preventDefault();let i=WF(KF(r,d,p),d,f);if(le(e,r),O){let t=[...U];t[e]=i;let n=k*p;e===0?t[0]=Math.min(t[0],t[1]-n):t[1]=Math.max(t[1],t[0]+n),t[0]=WF(t[0],d,f),t[1]=WF(t[1],d,f),de(t)}else de([i])},[a,O,U,p,d,f,k,le,de]),he=e=>h?h(e):String(e),ge=e=>{let t=U[e],n=qF(t,d,f),r=A?{insetInlineStart:YF(n)}:{bottom:YF(n),left:`50%`},i=O?e===0?`Minimum value`:`Maximum value`:void 0,o=k*p,s=O&&e===1?WF(U[0]+o,d,f):d,c=O&&e===0?WF(U[1]-o,d,f):f,u=v===`tooltip`&&!te,g=A?`above`:`start`,_=(0,K.jsx)(`div`,{id:O?void 0:j,role:`slider`,tabIndex:a&&!te?-1:0,"aria-valuemin":s,"aria-valuemax":c,"aria-valuenow":t,"aria-valuetext":h?h(t):void 0,"aria-orientation":m,"aria-disabled":a||void 0,"aria-invalid":l?.type===`error`||void 0,"aria-label":i,"aria-labelledby":O?void 0:M,"aria-describedby":ae,onKeyDown:t=>me(e,t),onFocus:t=>H(e,t),onBlur:ee,...oa(ba(`slider-thumb`,{orientation:m,disabled:a?`disabled`:null}),Sr(UF.thumb,A?UF.thumbHorizontal:Ra.centerInline(`50%`),!a&&UF.thumbHover,!a&&B===e&&Ha.focusVisible,a&&UF.thumbDisabled),void 0,r)},e);return u?(0,K.jsx)(Cd,{content:he(t),placement:g,delay:0,focusTrigger:`always`,isOpen:R===e||void 0,children:_},e):_},_e=(()=>{if(O){let[e,t]=U,n=qF(e,d,f),r=qF(t,d,f);return A?{insetInlineStart:YF(n),width:XF(n,r)}:{bottom:YF(n),height:XF(n,r)}}let e=qF(U[0],d,f);return A?{insetInlineStart:`0%`,width:YF(e)}:{bottom:`0%`,height:YF(e)}})(),ve=v===`text`?(0,K.jsx)(`span`,{className:`x9ynric xcr08ib x1tgivj0 xuxw1ft x2lah0s`,children:O?`${he(U[0])} – ${he(U[1])}`:he(U[0])}):null;return(0,K.jsxs)(MM,{"data-testid":w,label:n,isLabelHidden:r,description:i,inputID:j,labelID:M,isGroupLabel:!0,descriptionID:i?N:void 0,isOptional:s,isRequired:c,isDisabled:a,status:l?{type:l.type,message:l.message,messageID:l.message?P:void 0}:void 0,labelTooltip:u,statusVariant:`detached`,width:b,xstyle:x,className:S,style:C,children:[(0,K.jsxs)(`div`,{...oa(ba(`slider`,{orientation:m,disabled:a?`disabled`:null}),{className:`x78zum5 x6s0dn4 x1txdalj`}),children:[g!=null&&U.map((e,t)=>(0,K.jsx)(`input`,{type:`hidden`,name:g,value:String(e),disabled:a},t===0?`start`:`end`)),(0,K.jsxs)(`div`,{ref:Ao(e,I,ne.ref),...O?{role:`group`,"aria-labelledby":M}:void 0,onPointerDown:fe,onPointerMove:W,onPointerUp:pe,onPointerCancel:pe,...{0:{className:`x1n2onr6 x78zum5 x6s0dn4 x1iyjqo2 x5ve5x3 x87ps6o xc8icb0 xw4jnvo x1ymw6g xkagaj0 xdt5ytf xl56j7k x1ypdohk x16khyan`},2:{className:`x1n2onr6 x78zum5 x6s0dn4 x1iyjqo2 x5ve5x3 x87ps6o xc8icb0 x1qx5ct2 x80b3aj xh8yej3 x1ypdohk x16khyan`},1:{className:`x1n2onr6 x78zum5 x6s0dn4 x1iyjqo2 x5ve5x3 x87ps6o xc8icb0 xw4jnvo x1ymw6g xkagaj0 xdt5ytf xl56j7k xbyyjgo xt0e3qv`},3:{className:`x1n2onr6 x78zum5 x6s0dn4 x1iyjqo2 x5ve5x3 x87ps6o xc8icb0 x1qx5ct2 x80b3aj xh8yej3 xbyyjgo xt0e3qv`}}[!!A<<1|!!a<<0],children:[(0,K.jsx)(`div`,{"aria-hidden":`true`,...oa(ba(`slider-track`,{orientation:m}),Sr(UF.track,A?UF.trackHorizontal:[UF.trackVertical,Ra.centerInline(`0px`)]))}),(0,K.jsx)(`div`,{"aria-hidden":`true`,...oa(Sr(UF.filledTrack,A?UF.filledTrackHorizontal:[UF.filledTrackVertical,Ra.centerInline(`0px`)]),{style:_e})}),y&&(0,K.jsx)(`div`,{"aria-hidden":`true`,...{0:{className:`x10l6tqk x13vifvy x1ey2m1c xbudbmw`},1:{className:`x10l6tqk x1o0tod xtijo5x xwa60dl`}}[!!A<<0],children:y.map(e=>{let t=qF(e.value,d,f),n=A?{insetInlineStart:YF(t)}:{bottom:YF(t)};return(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`div`,{"data-testid":`slider-mark`,"data-mark-value":e.value,...oa({0:{className:`x10l6tqk x7njt3n xjspbzw x36qwtl x1xc55vz x1m9mm8y`},1:{className:`x10l6tqk x7njt3n xjspbzw xfo62xy xdk7pt x11lhmoz xoffwj3`}}[!!A<<0],{style:n})}),e.label&&(0,K.jsx)(`span`,{"data-testid":`slider-mark-label`,"data-mark-value":e.value,...oa({0:{className:`x10l6tqk x9ynric x141an7d xv1l7n4 xuxw1ft x131p8rn x9p6ekw`},1:{className:`x10l6tqk x9ynric x141an7d xv1l7n4 xuxw1ft xuuh30 x1nyx83j xuivejd`}}[!!A<<0],{style:n}),children:e.label})]},e.value)})}),U.map((e,t)=>ge(t))]}),ve]}),re&&(0,K.jsx)(es,{id:F,children:`Required`}),te&&ne.renderTooltip(o)]})}$F.displayName=`Slider`;var eI=[`explorer`,`implementer`,`reviewer`,`advisor`];function tI({catalog:e,error:t,onRefresh:n}){let{t:r}=cr();return!t&&!e?(0,K.jsxs)(`div`,{className:`settings-load-state`,role:`status`,children:[(0,K.jsx)(dt,{className:`settings-spin`,"aria-hidden":`true`}),(0,K.jsx)(`span`,{children:r(`settingsCatalogLoading`)})]}):t?(0,K.jsxs)(`div`,{className:`settings-load-state error`,role:`alert`,children:[(0,K.jsx)(`strong`,{children:r(`settingsCatalogFailed`)}),(0,K.jsx)(`span`,{children:t}),(0,K.jsx)(`button`,{type:`button`,onClick:n,children:r(`retryAdmissionCheck`)})]}):null}function nI({isPending:e,isBlocked:t=!1,onConfigure:n,request:r,label:i}){return(0,K.jsx)(qc,{label:i,variant:`secondary`,size:`sm`,icon:(0,K.jsx)(It,{"aria-hidden":`true`}),isDisabled:e||t,isLoading:e,onClick:()=>void n(r)})}function rI({pending:e,onConfigure:t,placeholder:n}){let{t:r}=cr(),[i,a]=(0,_.useState)(``);return(0,K.jsxs)(`form`,{className:`settings-edit-form`,onSubmit:n=>{n.preventDefault(),!e&&i.trim()&&t(i.trim())},children:[(0,K.jsxs)(`label`,{className:`settings-form-field`,children:[r(`setupConfigurationRequest`),(0,K.jsx)(`textarea`,{required:!0,maxLength:2e3,value:i,disabled:e,placeholder:n,onChange:e=>a(e.target.value)})]}),(0,K.jsx)(`button`,{type:`submit`,disabled:e||!i.trim(),children:r(`configureViaSetup`)}),(0,K.jsx)(`small`,{children:r(`setupFormDetail`)})]})}function iI({catalog:e,error:t,currentModel:n,thinkingLevel:r,cwd:i,setupPending:a,setupBlocked:o=!1,preferencePending:s,setupBusy:c,setupBlockedReason:l,onConfigure:u,onUpdatePreferences:d,onOpenRuntimeStatus:f,onRefresh:p}){let{t:m}=cr(),h=e?.setup,g=h?.workflows.concurrency??0,v=h?.workflows.maxAgentCalls??0,[y,b]=(0,_.useState)(g),[x,S]=(0,_.useState)(v);return(0,_.useEffect)(()=>b(g),[g]),(0,_.useEffect)(()=>S(v),[v]),(0,K.jsxs)(`section`,{className:`settings-general-panel`,children:[(0,K.jsxs)(`div`,{className:`settings-page-heading`,children:[(0,K.jsx)(`div`,{children:(0,K.jsx)(`h1`,{children:m(`generalSettings`)})}),(0,K.jsx)(nI,{isPending:a,isBlocked:o,onConfigure:u,request:m(`setupRequestReviewAll`),label:m(`configureOpenPi`)})]}),c&&(0,K.jsx)(`p`,{className:`settings-pending-hint`,role:`status`,children:l||m(`settingsSetupBusyHint`)}),(0,K.jsx)(tI,{catalog:e,error:t,onRefresh:p}),h&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsxs)(`section`,{className:`settings-section-block`,children:[(0,K.jsx)(`h2`,{children:m(`agentBehavior`)}),(0,K.jsxs)(`div`,{className:`settings-chat-controls`,children:[(0,K.jsxs)(`label`,{className:`settings-inline-control`,children:[(0,K.jsx)(St,{"aria-hidden":`true`}),(0,K.jsx)(`span`,{children:m(`capabilityDiscovery`)}),(0,K.jsx)(`select`,{value:h.capabilities.discovery,disabled:a||o,onChange:e=>void u(m(`setupRequestDiscovery`,{mode:e.target.value})),children:[`explicit`,`adaptive`].map(e=>(0,K.jsx)(`option`,{value:e,children:m(`capabilityDiscovery_${e}`)},e))})]}),(0,K.jsxs)(`form`,{className:`settings-limits-control`,onSubmit:e=>{e.preventDefault(),!a&&!o&&u(m(`setupRequestLimits`,{concurrency:y,calls:x}))},children:[(0,K.jsxs)(`span`,{children:[(0,K.jsx)(ke,{"aria-hidden":`true`}),m(`workflowLimits`)]}),(0,K.jsx)(`small`,{children:m(`workflowLimitsValue`,{concurrency:h.workflows.concurrency,calls:h.workflows.maxAgentCalls})}),(0,K.jsxs)(`label`,{children:[m(`workflowConcurrency`),(0,K.jsx)(`input`,{type:`number`,min:1,value:y,disabled:a||o,onChange:e=>b(Number(e.target.value)),required:!0})]}),(0,K.jsxs)(`label`,{children:[m(`workflowCalls`),(0,K.jsx)(`input`,{type:`number`,min:1,value:x,disabled:a||o,onChange:e=>S(Number(e.target.value)),required:!0})]}),(0,K.jsx)(`button`,{type:`submit`,disabled:a||o||y===h.workflows.concurrency&&x===h.workflows.maxAgentCalls,children:m(`configureViaSetup`)})]}),(0,K.jsx)(QP,{label:m(`nextActionSuggestions`),value:h.suggestions.enabled,size:`sm`,width:`100%`,labelPosition:`start`,labelSpacing:`spread`,isDisabled:a||o,isLoading:a,onChange:e=>void u(m(e?`setupRequestEnableSuggestions`:`setupRequestDisableSuggestions`))}),h.suggestions.model&&(0,K.jsx)(`small`,{children:`${h.suggestions.model.provider}/${h.suggestions.model.model} · ${h.suggestions.model.reasoning}`}),(0,K.jsxs)(`div`,{className:`settings-inline-control`,children:[(0,K.jsx)(ce,{"aria-hidden":`true`}),(0,K.jsxs)(`span`,{children:[m(`postEditCommand`),` ·`,` `,m(h.postEditConfigured?`configured`:`disabled`)]}),(0,K.jsx)(nI,{isPending:a,isBlocked:o,onConfigure:u,request:m(`setupRequestPostEdit`),label:m(`configurePostEdit`)})]}),(0,K.jsx)(`small`,{children:m(`agentSettingsSetupHint`)})]})]}),(0,K.jsxs)(`section`,{className:`settings-section-block`,children:[(0,K.jsx)(`h2`,{children:m(`resultDisplay`)}),(0,K.jsxs)(`div`,{className:`settings-chat-controls`,children:[[[`subagentResultDisplay`,`subagentResults`],[`bashToolDisplay`,`bashOperations`],[`fileMutationDisplay`,`fileMutations`]].map(([e,t])=>(0,K.jsxs)(`label`,{className:`settings-inline-control`,children:[(0,K.jsx)(`span`,{children:m(t)}),(0,K.jsxs)(`select`,{value:h.ui[e],disabled:s,onChange:t=>{let n=t.target.value;(n===`full`||n===`compact`)&&d({[e]:n})},children:[(0,K.jsx)(`option`,{value:`compact`,children:m(`detailDisplay_compact`)}),(0,K.jsx)(`option`,{value:`full`,children:m(`detailDisplay_full`)})]})]},e)),(0,K.jsx)(QP,{label:m(`terminalFooter`),value:h.ui.customFooter,size:`sm`,width:`100%`,labelPosition:`start`,labelSpacing:`spread`,isDisabled:s,isLoading:s,onChange:e=>void d({customFooter:e})}),(0,K.jsxs)(`label`,{className:`settings-inline-control`,children:[(0,K.jsx)(`span`,{children:m(`terminalFooterStyle`)}),(0,K.jsxs)(`select`,{value:h.ui.footerStyle,disabled:s||!h.ui.customFooter,onChange:e=>{let t=e.target.value;(t===`plain`||t===`powerline`||t===`powerline-mono`)&&d({footerStyle:t})},children:[(0,K.jsx)(`option`,{value:`plain`,children:`Plain`}),(0,K.jsx)(`option`,{value:`powerline`,children:`Powerline`}),(0,K.jsx)(`option`,{value:`powerline-mono`,children:`Powerline Mono`})]})]}),(0,K.jsx)(`small`,{children:m(`terminalFooterHint`)})]})]})]}),(0,K.jsxs)(`section`,{className:`settings-section-block`,children:[(0,K.jsx)(`h2`,{children:m(`sessionSettings`)}),(0,K.jsxs)(`dl`,{className:`settings-summary-list`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`dt`,{children:m(`selectedModel`)}),(0,K.jsx)(`dd`,{children:n?.label??m(`noModels`)})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`dt`,{children:m(`thinkingLevel`)}),(0,K.jsx)(`dd`,{children:r})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`dt`,{children:m(`currentWorkspace`)}),(0,K.jsx)(`dd`,{title:i,children:i})]})]}),(0,K.jsx)(qc,{label:m(`openRuntimeDetails`),variant:`secondary`,size:`sm`,icon:(0,K.jsx)(we,{"aria-hidden":`true`}),className:`settings-runtime-action`,onClick:f})]})]})}function aI(e){return e.split(/[\\/]/u).filter(Boolean).at(-1)||e}function oI({kind:e,query:t,scope:n,onQuery:r,onScope:i,onAdd:a}){let{t:o}=cr();return(0,K.jsxs)(`div`,{className:`settings-resource-toolbar`,children:[(0,K.jsxs)(`div`,{className:`settings-resource-toolbar-heading`,children:[(0,K.jsx)(`strong`,{children:o(e===`skills`?`skillsSettings`:`pluginsSettings`)}),(0,K.jsx)(qc,{label:o(e===`skills`?`addSkill`:`addPlugin`),variant:`secondary`,size:`sm`,icon:(0,K.jsx)(lt,{"aria-hidden":`true`}),onClick:a})]}),(0,K.jsxs)(`label`,{className:`settings-resource-search`,children:[(0,K.jsx)(ht,{"aria-hidden":`true`}),(0,K.jsx)(`input`,{type:`search`,"aria-label":o(`searchResources`),placeholder:o(`searchResources`),value:t,onChange:e=>r(e.target.value)})]}),(0,K.jsxs)(`select`,{"aria-label":o(`filterResourceScope`),value:n,onChange:e=>i(e.target.value),children:[(0,K.jsx)(`option`,{value:`all`,children:o(`allResourceScopes`)}),[`project`,`user`,`temporary`].map(e=>(0,K.jsx)(`option`,{value:e,children:o(`resourceScope_${e}`)},e))]})]})}function sI({kind:e,pending:t,onConfigure:n,onCancel:r}){let{t:i}=cr(),[a,o]=(0,_.useState)(``),[s,c]=(0,_.useState)(`user`);return(0,K.jsxs)(`section`,{className:`settings-resource-install`,children:[(0,K.jsx)(`header`,{className:`settings-detail-heading`,children:(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`span`,{children:i(`resourceManagement`)}),(0,K.jsx)(`h1`,{children:i(e===`skills`?`addSkill`:`addPlugin`)}),(0,K.jsx)(`p`,{children:i(`resourceInstallIntro`)})]})}),(0,K.jsxs)(`form`,{className:`settings-edit-form`,onSubmit:r=>{r.preventDefault(),!t&&a.trim()&&n(i(`setupResourceInstallRequest`,{kind:i(e===`skills`?`skillsSettings`:`pluginsSettings`),source:JSON.stringify(a.trim()),scope:s}))},children:[(0,K.jsxs)(`label`,{className:`settings-form-field`,children:[i(`resourcePackageSource`),(0,K.jsx)(`input`,{required:!0,maxLength:1e3,value:a,placeholder:i(`resourcePackageSourcePlaceholder`),disabled:t,onChange:e=>{o(e.target.value)}})]}),(0,K.jsxs)(`label`,{className:`settings-form-field`,children:[i(`scope`),(0,K.jsxs)(`select`,{value:s,disabled:t,onChange:e=>{c(e.target.value)},children:[(0,K.jsx)(`option`,{value:`user`,children:i(`resourceScope_user`)}),(0,K.jsx)(`option`,{value:`project`,children:i(`resourceScope_project`)})]})]}),(0,K.jsxs)(`div`,{className:`settings-resource-actions`,children:[(0,K.jsx)(qc,{type:`submit`,label:i(`configureViaSetup`),variant:`secondary`,size:`sm`,isDisabled:t||!a.trim()}),(0,K.jsx)(qc,{label:i(`cancel`),variant:`ghost`,size:`sm`,onClick:r})]}),(0,K.jsx)(`small`,{children:i(`resourceInstallReview`)})]}),e===`skills`&&(0,K.jsxs)(`a`,{className:`settings-resource-link`,href:`https://skills.sh`,target:`_blank`,rel:`noreferrer`,children:[i(`browseSkills`),(0,K.jsx)(he,{"aria-hidden":`true`})]})]})}function cI({catalog:e,pending:t,onReload:n,kind:r,onConfigure:i,children:a}){let{t:o}=cr(),[s,c]=(0,_.useState)(!1),[l,u]=(0,_.useState)(!1),[d,f]=(0,_.useState)(null);return(0,K.jsxs)(`section`,{className:`settings-resource-management`,children:[a&&(0,K.jsx)(`div`,{className:`settings-resource-actions`,children:a}),(0,K.jsxs)(`div`,{className:`settings-resource-reload`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`strong`,{children:o(`resourceSessionState`)}),(0,K.jsx)(`p`,{children:o(`resourcesReloadNote`)})]}),(0,K.jsx)(qc,{label:o(`reloadResources`),variant:`secondary`,size:`sm`,icon:(0,K.jsx)(dt,{"aria-hidden":`true`}),isDisabled:t||l||!e?.sessionPath||!n,isLoading:l,onClick:()=>c(!0)})]}),d&&(0,K.jsx)(`p`,{className:`settings-resource-notice`,role:`status`,children:d}),(0,K.jsxs)(`details`,{className:`settings-resource-advanced`,children:[(0,K.jsx)(`summary`,{children:o(`advancedResourceConfiguration`)}),(0,K.jsx)(rI,{pending:t,onConfigure:i,placeholder:o(r===`skills`?`setupSkillsPlaceholder`:`setupPluginsPlaceholder`)})]}),s&&(0,K.jsx)(HP,{isOpen:!0,onOpenChange:c,title:o(`reloadResources`),description:o(`resourceReloadReview`),cancelLabel:o(`cancel`),actionLabel:o(`reloadResources`),onAction:()=>{c(!1),u(!0),f(null),n?.().then(()=>f(o(`resourceReloaded`)),e=>f(e instanceof Error?e.message:o(`resourceReloadFailed`))).finally(()=>u(!1))}})]})}function lI({catalog:e}){let{t}=cr();if(!e)return null;let{diagnostics:n,truncation:r}=e.resources;return!n.settingsErrors&&!n.extensionErrors&&!n.skillErrors&&!r.truncated?null:(0,K.jsxs)(`p`,{className:`settings-resource-notice`,role:`status`,children:[t(`resourceDiagnostics`,n),n.settingsErrors?` ${t(`resourceConfigurationDiagnostics`,{count:n.settingsErrors})}`:``,r.truncated&&` ${t(`resourceCatalogTruncated`)}`]})}function uI({catalog:e,error:t,onRefresh:n,setupPending:r,onConfigure:i,onReload:a}){let{t:o}=cr(),s=e?.resources.skills??[],[c,l]=(0,_.useState)(``),[u,d]=(0,_.useState)(`all`),[f,p]=(0,_.useState)(!1),m=(0,_.useMemo)(()=>s.filter(e=>(u===`all`||e.scope===u)&&`${e.name} ${e.description} ${e.source}`.toLocaleLowerCase().includes(c.trim().toLocaleLowerCase())),[s,c,u]),h=(0,_.useMemo)(()=>[`project`,`user`,`temporary`].map(e=>({scope:e,skills:m.filter(t=>t.scope===e)})).filter(e=>e.skills.length>0),[m]),[g,v]=(0,_.useState)(``),[y,b]=(0,_.useState)(null),x=m.find(e=>e.id===g)??m[0],S=m.filter(e=>e.canManage!==!1),C=JSON.stringify(S.map(e=>e.filePath)),w=new TextEncoder().encode(C).length>12e3;(0,_.useEffect)(()=>{s.length&&!s.some(e=>e.id===g)&&v(s[0].id)},[g,s]);let T=e=>{b(null),wd(`/skill:${e.name} `).then(e=>b(e?`copied`:`failed`))};return(0,K.jsxs)(`section`,{className:`settings-split-panel settings-managed-panel`,children:[(0,K.jsxs)(`aside`,{className:`settings-resource-sidebar`,children:[(0,K.jsx)(oI,{kind:`skills`,query:c,scope:u,onQuery:l,onScope:d,onAdd:()=>p(!0)}),(0,K.jsxs)(`div`,{className:`settings-resource-list`,children:[h.map(e=>(0,K.jsxs)(`section`,{className:`settings-resource-group`,children:[(0,K.jsx)(`span`,{className:`settings-sidebar-label`,children:o(`resourceScope_${e.scope}`)}),e.skills.map(e=>(0,K.jsxs)(`button`,{type:`button`,className:`settings-resource-item`,"aria-current":e.id===x?.id?`page`:void 0,onClick:()=>{v(e.id),b(null),p(!1)},children:[(0,K.jsx)(St,{"aria-hidden":`true`}),(0,K.jsxs)(`span`,{children:[(0,K.jsx)(`strong`,{children:e.name}),(0,K.jsx)(`small`,{children:o(e.disableModelInvocation?`explicitOnly`:`availableToModel`)})]})]},e.id))]},e.scope)),!e&&!t&&(0,K.jsx)(tI,{catalog:e,error:t,onRefresh:n}),e&&!m.length&&(0,K.jsx)(`p`,{className:`settings-resource-empty`,children:o(s.length?`noMatchingResources`:`noSkillsFound`)})]}),(0,K.jsxs)(`div`,{className:`settings-sidebar-footer`,children:[(0,K.jsx)(`span`,{children:o(`skillCount`,{count:s.length})}),(0,K.jsx)(`button`,{type:`button`,"aria-label":o(`refreshStatus`),onClick:n,children:(0,K.jsx)(dt,{"aria-hidden":`true`})})]})]}),(0,K.jsxs)(`div`,{className:`settings-resource-detail`,children:[(0,K.jsx)(lI,{catalog:e}),f?(0,K.jsx)(sI,{kind:`skills`,pending:r,onConfigure:i,onCancel:()=>p(!1)}):t?(0,K.jsx)(tI,{catalog:e,error:t,onRefresh:n}):x?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsxs)(`header`,{className:`settings-detail-heading`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`span`,{children:[o(`resourceScope_${x.scope}`),` · `,o(`skill`)]}),(0,K.jsx)(`h1`,{children:x.name}),(0,K.jsx)(`p`,{children:x.description})]}),(0,K.jsx)(qc,{label:o(y===`copied`?`copiedMessage`:`copySkillInvocation`),variant:`secondary`,size:`sm`,icon:y===`copied`?(0,K.jsx)(I,{}):(0,K.jsx)(oe,{}),onClick:()=>T(x)})]}),(0,K.jsxs)(`dl`,{className:`settings-detail-metadata`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`dt`,{children:o(`source`)}),(0,K.jsx)(`dd`,{children:x.source===`auto`?o(`resourceSourceAuto`):x.source===`local`?o(`resourceSourceLocal`):x.source===`builtin`?o(`builtIn`):x.source})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`dt`,{children:o(`scope`)}),(0,K.jsx)(`dd`,{children:o(`resourceScope_${x.scope}`)})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`dt`,{children:o(`invocation`)}),(0,K.jsx)(`dd`,{children:(0,K.jsx)(`code`,{children:`/skill:${x.name}`})})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`dt`,{children:o(`modelInvocation`)}),(0,K.jsx)(`dd`,{children:o(x.disableModelInvocation?`explicitOnly`:`availableToModel`)})]})]}),(0,K.jsxs)(`section`,{className:`settings-path-block`,children:[(0,K.jsx)(Se,{"aria-hidden":`true`}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`strong`,{children:o(`skillFile`)}),(0,K.jsx)(`code`,{children:x.filePath})]})]}),(0,K.jsxs)(`div`,{className:`settings-resource-actions`,children:[(0,K.jsx)(nI,{isPending:r,isBlocked:x.canManage===!1,onConfigure:i,label:o(x.disableModelInvocation?`enableSkillInvocation`:`disableSkillInvocation`),request:o(`setupSkillInvocationRequest`,{path:x.filePath,disabled:!x.disableModelInvocation})}),(0,K.jsx)(nI,{isPending:r,isBlocked:x.canManage===!1,onConfigure:i,label:o(`updateResource`),request:o(`setupSkillManageRequest`,{action:`update`,path:JSON.stringify(x.filePath),source:JSON.stringify(x.source),scope:x.scope})}),(0,K.jsx)(nI,{isPending:r,isBlocked:x.canManage===!1,onConfigure:i,label:o(`removeResource`),request:o(`setupSkillManageRequest`,{action:`remove`,path:JSON.stringify(x.filePath),source:JSON.stringify(x.source),scope:x.scope})})]}),x.canManage===!1&&(0,K.jsx)(`p`,{className:`settings-resource-notice`,children:o(`resourceTargetTruncated`)}),y===`failed`&&(0,K.jsx)(`p`,{className:`inspection-warning`,children:o(`copyFailed`)})]}):(0,K.jsxs)(`div`,{className:`settings-empty-detail`,children:[(0,K.jsx)(St,{"aria-hidden":`true`}),(0,K.jsx)(`h1`,{children:o(s.length?`noMatchingResources`:`skillsEmptyTitle`)}),(0,K.jsx)(`p`,{children:o(`skillsEmptyIntro`)}),(0,K.jsx)(qc,{label:o(`addSkill`),variant:`secondary`,size:`sm`,icon:(0,K.jsx)(lt,{"aria-hidden":`true`}),onClick:()=>p(!0)})]}),!f&&(0,K.jsxs)(cI,{catalog:e,pending:r,onReload:a,kind:`skills`,onConfigure:i,children:[S.length>1&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(nI,{isPending:r,isBlocked:w,onConfigure:i,label:o(`enableVisibleSkills`,{count:S.length}),request:o(`setupSkillsBulkRequest`,{paths:C,disabled:!1})}),(0,K.jsx)(nI,{isPending:r,isBlocked:w,onConfigure:i,label:o(`disableVisibleSkills`,{count:S.length}),request:o(`setupSkillsBulkRequest`,{paths:C,disabled:!0})})]}),w&&(0,K.jsx)(`p`,{className:`settings-resource-caption`,children:o(`resourceBulkTooLarge`)})]})]})]})}function dI({catalog:e,error:t,currentModel:n,models:r,activity:i,setupPending:a,setupBlocked:o=!1,onConfigure:s,onRefresh:c}){let{t:l}=cr(),[u,d]=(0,_.useState)(`explorer`),f=e?.setup.subagents.roleModels[u],[p,m]=(0,_.useState)(``),[h,g]=(0,_.useState)(1);(0,_.useEffect)(()=>{let t=e?.setup.subagents.roleModels[u];m(t?`${t.provider}/${t.model}`:``),g(e?.setup.workflows.concurrency??1)},[u,e]);let v=i?.items.filter(e=>e.status===`running`).length??0,y=i?.items.filter(e=>e.status!==`running`).length??0;return(0,K.jsxs)(`section`,{className:`settings-subagents-panel`,children:[(0,K.jsxs)(`header`,{className:`settings-subagent-summary`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`strong`,{children:l(`subagentConfiguration`)}),(0,K.jsx)(`span`,{children:l(`subagentConfigurationIntro`)})]}),e&&(0,K.jsxs)(`div`,{className:`settings-subagent-metrics`,children:[(0,K.jsx)(`span`,{children:l(`subagentActiveCount`,{count:v})}),(0,K.jsx)(`span`,{children:l(`subagentCompletedCount`,{count:y})}),(0,K.jsx)(`span`,{children:l(`subagentConcurrency`,{count:e.setup.workflows.concurrency})})]})]}),(0,K.jsxs)(`div`,{className:`settings-split-panel settings-subagent-split`,children:[(0,K.jsxs)(`aside`,{className:`settings-resource-sidebar`,children:[(0,K.jsxs)(`div`,{className:`settings-resource-list`,children:[(0,K.jsx)(`span`,{className:`settings-sidebar-label`,children:l(`builtInRoles`)}),eI.map(e=>(0,K.jsxs)(`button`,{type:`button`,className:`settings-resource-item`,"aria-current":e===u?`page`:void 0,onClick:()=>d(e),children:[(0,K.jsx)(M,{"aria-hidden":`true`}),(0,K.jsxs)(`span`,{children:[(0,K.jsx)(`strong`,{children:l(`subagentRole_${e}`)}),(0,K.jsx)(`small`,{children:l(`subagentRoleShort_${e}`)})]})]},e))]}),(0,K.jsx)(`div`,{className:`settings-sidebar-footer settings-sidebar-footer-action`,children:(0,K.jsx)(nI,{isPending:a,isBlocked:o,onConfigure:s,request:l(`setupRequestSubagents`),label:l(`configureRoles`)})})]}),(0,K.jsxs)(`div`,{className:`settings-resource-detail`,children:[(0,K.jsx)(tI,{catalog:e,error:t,onRefresh:c}),e&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsxs)(`header`,{className:`settings-detail-heading`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`span`,{children:l(`builtInRole`)}),(0,K.jsx)(`h1`,{children:l(`subagentRole_${u}`)}),(0,K.jsx)(`p`,{children:l(`subagentRoleDescription_${u}`)})]}),(0,K.jsx)(`span`,{className:`settings-status-badge`,children:l(`builtIn`)})]}),(0,K.jsxs)(`dl`,{className:`settings-detail-metadata settings-detail-metadata-wide`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`dt`,{children:l(`modelAssignment`)}),(0,K.jsx)(`dd`,{children:f?`${f.provider}/${f.model}`:l(`inheritParentModel`)})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`dt`,{children:l(`effectiveModel`)}),(0,K.jsx)(`dd`,{children:f?`${f.provider}/${f.model}`:n?.label??l(`unknownState`)})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`dt`,{children:l(`workflowConcurrencyLabel`)}),(0,K.jsx)(`dd`,{children:e.setup.workflows.concurrency})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`dt`,{children:l(`workflowCallLimit`)}),(0,K.jsx)(`dd`,{children:e.setup.workflows.maxAgentCalls})]})]}),(0,K.jsxs)(`section`,{className:`settings-role-principles`,children:[(0,K.jsxs)(`form`,{className:`settings-edit-form`,onSubmit:e=>{e.preventDefault(),!a&&s(l(`setupRoleFormRequest`,{role:u,model:p||l(`inheritParentModel`),concurrency:h}))},children:[(0,K.jsxs)(`label`,{className:`settings-form-field`,children:[l(`modelAssignment`),(0,K.jsxs)(`select`,{value:p,disabled:a,onChange:e=>m(e.target.value),children:[(0,K.jsx)(`option`,{value:``,children:l(`inheritParentModel`)}),p&&!r.some(e=>`${e.provider}/${e.id}`===p)&&(0,K.jsx)(`option`,{value:p,children:p}),r.map(e=>(0,K.jsx)(`option`,{value:`${e.provider}/${e.id}`,children:e.label},`${e.provider}/${e.id}`))]})]}),(0,K.jsxs)(`label`,{className:`settings-form-field`,children:[l(`workflowConcurrencyLabel`),(0,K.jsx)(`input`,{type:`number`,min:1,max:64,required:!0,value:h,disabled:a,onChange:e=>g(Number(e.target.value))})]}),(0,K.jsx)(`button`,{type:`submit`,disabled:a,children:l(`configureViaSetup`)}),(0,K.jsx)(`small`,{children:l(`setupFormDetail`)})]}),(0,K.jsx)(`h2`,{children:l(`runtimeBoundaries`)}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(Fe,{"aria-hidden":`true`}),(0,K.jsx)(`p`,{children:l(`subagentAuthorityNote`)})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(fe,{"aria-hidden":`true`}),(0,K.jsx)(`p`,{children:l(`subagentModelNote`)})]})]})]})]})]})]})}function fI(e){return e.extensions.length+e.skills.length+e.prompts.length+e.themes.length}function pI(e){return e.enabled===!1?`disabled`:e.configured&&!e.installed?`missing`:e.diagnostics?.length?`error`:fI(e)?`loaded`:e.installed?`installed`:`notLoaded`}function mI({catalog:e,error:t,onRefresh:n,setupPending:r,onConfigure:i,onReload:a}){let{t:o}=cr(),s=e?.resources.plugins??[],[c,l]=(0,_.useState)(``),[u,d]=(0,_.useState)(`all`),[f,p]=(0,_.useState)(!1),m=(0,_.useMemo)(()=>s.filter(e=>(u===`all`||e.scope===u)&&`${e.name??``} ${e.source}`.toLocaleLowerCase().includes(c.trim().toLocaleLowerCase())),[s,c,u]),[h,g]=(0,_.useState)(``),v=m.find(e=>e.id===h)??m[0],y=m.filter(e=>e.configured&&e.canManage!==!1),b=e=>e.name??(e.source===`auto`?o(`resourceSourceAuto`):e.source===`builtin`?o(`builtIn`):aI(e.source)),x=JSON.stringify(y.map(({source:e,scope:t,baseDir:n})=>({source:e,scope:t,path:n}))),S=new TextEncoder().encode(x).length>12e3;return(0,_.useEffect)(()=>{s.length&&!s.some(e=>e.id===h)&&g(s[0].id)},[s,h]),(0,K.jsxs)(`section`,{className:`settings-split-panel settings-managed-panel`,children:[(0,K.jsxs)(`aside`,{className:`settings-resource-sidebar`,children:[(0,K.jsx)(oI,{kind:`plugins`,query:c,scope:u,onQuery:l,onScope:d,onAdd:()=>p(!0)}),(0,K.jsxs)(`div`,{className:`settings-resource-list`,children:[m.map(e=>(0,K.jsxs)(`button`,{type:`button`,className:`settings-resource-item`,"aria-current":e.id===v?.id?`page`:void 0,onClick:()=>{g(e.id),p(!1)},children:[(0,K.jsx)(ct,{"aria-hidden":`true`}),(0,K.jsxs)(`span`,{children:[(0,K.jsx)(`strong`,{children:b(e)}),(0,K.jsxs)(`small`,{children:[o(`resourceScope_${e.scope}`),` ·`,` `,o(`pluginState_${pI(e)}`)]})]})]},e.id)),!e&&!t&&(0,K.jsx)(tI,{catalog:e,error:t,onRefresh:n}),e&&!m.length&&(0,K.jsx)(`p`,{className:`settings-resource-empty`,children:o(s.length?`noMatchingResources`:`noPluginsFound`)})]}),(0,K.jsxs)(`div`,{className:`settings-sidebar-footer`,children:[(0,K.jsx)(`span`,{children:e?o(`pluginCount`,{count:s.length}):o(`settingsCatalogLoading`)}),(0,K.jsx)(`button`,{type:`button`,"aria-label":o(`refreshStatus`),onClick:n,children:(0,K.jsx)(dt,{"aria-hidden":`true`})})]})]}),(0,K.jsxs)(`div`,{className:`settings-resource-detail`,children:[(0,K.jsx)(lI,{catalog:e}),f?(0,K.jsx)(sI,{kind:`plugins`,pending:r,onConfigure:i,onCancel:()=>p(!1)}):t?(0,K.jsx)(tI,{catalog:e,error:t,onRefresh:n}):v?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsxs)(`header`,{className:`settings-detail-heading`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`span`,{children:o(`resourceScope_${v.scope}`)}),(0,K.jsx)(`h1`,{children:b(v)}),(0,K.jsx)(`code`,{children:v.source})]}),(0,K.jsx)(`span`,{className:`settings-status-badge ${pI(v)===`loaded`?`healthy`:``}`,children:o(`pluginState_${pI(v)}`)})]}),(0,K.jsxs)(`dl`,{className:`settings-detail-metadata settings-detail-metadata-wide`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`dt`,{children:o(`scope`)}),(0,K.jsx)(`dd`,{children:o(`resourceScope_${v.scope}`)})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`dt`,{children:o(`resourceOrigin`)}),(0,K.jsx)(`dd`,{children:o(`resourceOrigin_${v.origin}`)})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`dt`,{children:o(`installedVersion`)}),(0,K.jsx)(`dd`,{children:v.installedVersion??o(`notReported`)})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`dt`,{children:o(`configuredVersion`)}),(0,K.jsx)(`dd`,{children:v.configuredVersion??o(`resourceVersionUnpinned`)})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`dt`,{children:o(`resources`)}),(0,K.jsx)(`dd`,{children:o(`pluginResourceSummary`,{extensions:v.extensions.length,skills:v.skills.length,prompts:v.prompts.length,themes:v.themes.length})})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`dt`,{children:o(`baseDirectory`)}),(0,K.jsx)(`dd`,{title:v.baseDir,children:v.baseDir??o(`notReported`)})]})]}),[...new Set(v.diagnostics)].map(e=>(0,K.jsx)(`p`,{className:`settings-resource-notice`,role:`status`,children:e},e)),v.canManage===!1&&(0,K.jsx)(`p`,{className:`settings-resource-notice`,children:o(`resourceTargetTruncated`)}),v.configured&&v.canManage!==!1&&(0,K.jsx)(`div`,{className:`settings-resource-actions settings-resource-primary-actions`,children:[v.enabled===!1?`enable`:`disable`,`update`,`remove`].map(e=>(0,K.jsx)(nI,{isPending:r,onConfigure:i,label:o(`pluginAction_${e}`),request:o(`setupPluginOperationRequest`,{action:e,source:JSON.stringify(v.source),path:JSON.stringify(v.baseDir??null),scope:v.scope})},e))}),(0,K.jsx)(`p`,{className:`settings-resource-caption`,children:o(`pluginLoadedResources`,{count:fI(v)})}),(0,K.jsxs)(`section`,{className:`settings-resource-groups`,children:[v.extensions.length>0&&(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`h2`,{children:o(`extensions`)}),(0,K.jsx)(`ul`,{children:v.extensions.map(e=>(0,K.jsxs)(`li`,{children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`strong`,{children:e.name}),(0,K.jsx)(`code`,{children:e.path})]}),(0,K.jsx)(`span`,{children:o(`extensionSurfaceCount`,{tools:e.toolCount,commands:e.commandCount})})]},e.path))})]}),v.skills.length>0&&(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`h2`,{children:o(`skillsSettings`)}),(0,K.jsx)(`p`,{children:v.skills.join(` · `)})]}),v.prompts.length>0&&(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`h2`,{children:o(`prompts`)}),(0,K.jsx)(`p`,{children:v.prompts.join(` · `)})]}),v.themes.length>0&&(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`h2`,{children:o(`themes`)}),(0,K.jsx)(`p`,{children:v.themes.join(` · `)})]})]})]}):(0,K.jsxs)(`div`,{className:`settings-empty-detail`,children:[(0,K.jsx)(ct,{"aria-hidden":`true`}),(0,K.jsx)(`h1`,{children:o(s.length?`noMatchingResources`:`pluginsEmptyTitle`)}),(0,K.jsx)(`p`,{children:o(`pluginsEmptyIntro`)}),(0,K.jsx)(qc,{label:o(`addPlugin`),variant:`secondary`,size:`sm`,icon:(0,K.jsx)(lt,{"aria-hidden":`true`}),onClick:()=>p(!0)})]}),!f&&(0,K.jsxs)(cI,{catalog:e,pending:r,onReload:a,kind:`plugins`,onConfigure:i,children:[y.length>1&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(nI,{isPending:r,isBlocked:S,onConfigure:i,label:o(`enableVisiblePlugins`,{count:y.length}),request:o(`setupPluginsBulkRequest`,{packages:x,disabled:!1})}),(0,K.jsx)(nI,{isPending:r,isBlocked:S,onConfigure:i,label:o(`disableVisiblePlugins`,{count:y.length}),request:o(`setupPluginsBulkRequest`,{packages:x,disabled:!0})})]}),S&&(0,K.jsx)(`p`,{className:`settings-resource-caption`,children:o(`resourceBulkTooLarge`)})]})]})]})}function hI(e,t=``,n){let r=(0,_.useMemo)(()=>new rf,[]),[i,a]=(0,_.useState)(0),o=JSON.stringify([e,t]),s=(0,_.useRef)(o);s.current=o;let c=(0,_.useRef)(0),[l,u]=(0,_.useState)(null),d=(0,_.useCallback)(()=>a(e=>e+1),[]);return(0,_.useEffect)(()=>{let t=new AbortController,n=++c.current;return u(e=>({owner:o,catalog:e?.owner===o?e.catalog:null,error:null})),r.settingsCatalog(e,t.signal).then(e=>{!t.signal.aborted&&c.current===n&&u({owner:o,catalog:e,error:null})},e=>{!t.signal.aborted&&c.current===n&&u(t=>({owner:o,catalog:t?.owner===o?t.catalog:null,error:e instanceof Error?e.message:String(e)}))}),()=>t.abort()},[r,i,e,o,n]),{catalog:l?.owner===o?l.catalog:null,error:l?.owner===o?l.error:null,refresh:d,updateSetup:e=>{s.current===o&&(c.current++,u(t=>t?.owner===o&&t.catalog?{...t,catalog:{...t.catalog,setup:e}}:t))}}}var gI=[`default`,`mist`,`rose`,`pine`],_I=[`codex`,`sans`,`serif`,`mono`],vI=[`system`,`light`,`dark`],yI={palette:`default`,accent:``,background:``,foreground:``,font:`codex`};function bI(e){return e===`pine`?`dark`:e===`mist`||e===`rose`?`light`:e}function xI(e,t){return e===`mist`||e===`rose`||e===`pine`?e:t.palette}function SI(e,t){switch(e){case`mist`:return t?{background:`#182126`,foreground:`#EDF3F5`}:{background:`#F8FBFC`,foreground:`#253239`};case`rose`:return t?{background:`#251C20`,foreground:`#F5EDF0`}:{background:`#FFFAFB`,foreground:`#392B2F`};case`pine`:return t?{background:`#16201C`,foreground:`#EDF3EF`}:{background:`#F5FAF7`,foreground:`#24382D`};default:return t?{background:`#17191C`,foreground:`#EDF0F2`}:{background:`#FFFFFF`,foreground:`#1A1C1F`}}}function CI(e){if(e.length>2e3)return null;try{let t=JSON.parse(e);if(!t||typeof t!=`object`||Array.isArray(t))return null;let n=t;if(Object.keys(n).sort().join(`,`)!==`appearance,theme,version`||n.version!==1)return null;let r=vI.find(e=>e===n.theme);if(!r||!n.appearance||typeof n.appearance!=`object`||Array.isArray(n.appearance))return null;let i=n.appearance;if(Object.keys(i).sort().join(`,`)!==`accent,background,font,foreground,palette`)return null;let a=gI.find(e=>e===i.palette),o=i.font===`system`?`codex`:_I.find(e=>e===i.font),{accent:s,background:c,foreground:l}=i;return!a||!o||typeof s!=`string`||typeof c!=`string`||typeof l!=`string`||![s,c,l].every(e=>e===``||/^#[0-9a-f]{6}$/iu.test(e))?null:{theme:r,appearance:{palette:a,font:o,accent:s,background:c,foreground:l}}}catch{return null}}var wI=[``,`#2563EB`,`#7C3AED`,`#DB2777`,`#D97706`,`#16A34A`];function TI({label:e,value:t,options:n,disabled:r,onSelect:i}){let a=n.find(e=>e.id===t);return(0,K.jsx)(jA,{button:{label:a?.label??t,"aria-label":e,variant:`secondary`,size:`sm`,className:`appearance-menu-trigger`,isDisabled:r,...a?.color?{icon:(0,K.jsx)(`span`,{className:`appearance-color-dot`,style:{background:a.color}})}:{}},menuWidth:200,alignment:`end`,items:n.map(e=>({id:e.id||`default`,label:e.label,isDisabled:r,...e.color?{icon:(0,K.jsx)(`span`,{className:`appearance-color-dot`,style:{background:e.color}})}:{},endContent:t===e.id?(0,K.jsx)(I,{"aria-hidden":`true`}):void 0,onClick:()=>i(e.id)}))})}function EI({label:e,value:t,fallback:n,disabled:r,onSave:i}){let a=(t||n).toUpperCase(),[o,s]=(0,_.useState)(a);(0,_.useEffect)(()=>s(a),[a]);let c=e=>{s(e),e!==a&&/^#[0-9a-f]{6}$/iu.test(e)&&i(e).then(e=>{e||s(a)})};return(0,K.jsxs)(`div`,{className:`appearance-color-input`,children:[(0,K.jsxs)(`label`,{className:`appearance-color-picker`,children:[(0,K.jsx)(`span`,{className:`appearance-color-dot`,style:{background:a}}),(0,K.jsx)(`input`,{"aria-label":`${e} — ${a}`,type:`color`,value:a,disabled:r,onChange:e=>c(e.target.value.toUpperCase())})]}),(0,K.jsx)(`input`,{className:`appearance-color-hex`,type:`text`,"aria-label":e,value:o,maxLength:7,spellCheck:!1,disabled:r,onChange:e=>c(e.target.value.toUpperCase()),onBlur:()=>s(a)})]})}function DI({catalog:e,theme:t,pending:n,error:r,onRefresh:i,onUpdatePreferences:a}){let{t:o}=cr(),{mode:s}=lu(),c=e?.setup,l=c?.ui.webTheme??t,u=c?.ui.webAppearance??yI,d=xI(l,u),f=bI(l),[p,m]=(0,_.useState)(!1),[h,g]=(0,_.useState)(!1),[v,y]=(0,_.useState)(``),[b,x]=(0,_.useState)(!1),[S,C]=(0,_.useState)(null),[w,T]=(0,_.useState)(c?.ui.webChatWidth??820),[E,D]=(0,_.useState)(c?.ui.webChatFontSize??14);(0,_.useEffect)(()=>{c&&(T(c.ui.webChatWidth),D(c.ui.webChatFontSize))},[c]);let O=e?.setupWritable===!1||!!e?.resources.diagnostics.settingsErrors,k=n||!c||!!r||O,A=CI(v),j=e=>a({appearance:e}),M=()=>{n||(g(!1),y(``),x(!1))},N=SI(d,f===`dark`||f===`system`&&s===`dark`);return(0,K.jsxs)(`section`,{className:`settings-content-page settings-appearance-panel`,children:[(0,K.jsx)(`h1`,{children:o(`appearance`)}),(!c||r||O)&&(0,K.jsxs)(`div`,{className:`settings-load-state`,role:r||O?`alert`:`status`,children:[(0,K.jsx)(dt,{"aria-hidden":`true`}),(0,K.jsx)(`span`,{children:o(O?`configurationReadFailure`:r?`settingsCatalogFailed`:`settingsCatalogLoading`)}),(r||O)&&(0,K.jsx)(`button`,{type:`button`,onClick:i,children:o(`retryAdmissionCheck`)})]}),(0,K.jsxs)(`section`,{className:`appearance-section`,"aria-labelledby":`appearance-visual-title`,children:[(0,K.jsx)(`h2`,{id:`appearance-visual-title`,children:o(`appearanceVisualStyle`)}),(0,K.jsxs)(`div`,{className:`appearance-card appearance-mode-row`,children:[(0,K.jsx)(`span`,{children:o(`appearanceMode`)}),(0,K.jsx)(`div`,{role:`radiogroup`,"aria-label":o(`appearanceMode`),className:`appearance-mode-options`,children:vI.map(e=>(0,K.jsx)(Cd,{content:o(e===`system`?`themeSystem`:e===`light`?`themeLight`:`themeDark`),children:(0,K.jsxs)(`label`,{className:`appearance-mode-option`,children:[(0,K.jsx)(`input`,{type:`radio`,name:`openpi-appearance-mode`,"aria-label":o(e===`system`?`themeSystem`:e===`light`?`themeLight`:`themeDark`),checked:f===e,disabled:k,onChange:()=>void a({theme:e})}),(0,K.jsxs)(`span`,{"aria-hidden":`true`,className:`appearance-mode-preview`,"data-mode":e,"data-selected":f===e,children:[(0,K.jsxs)(`span`,{className:`appearance-mini-window`,children:[(0,K.jsx)(`span`,{className:`appearance-mini-sidebar`}),(0,K.jsxs)(`span`,{className:`appearance-mini-chat`,children:[(0,K.jsx)(`i`,{}),(0,K.jsx)(`i`,{}),(0,K.jsx)(`b`,{}),(0,K.jsx)(`i`,{}),(0,K.jsx)(`b`,{}),(0,K.jsx)(`em`,{})]})]}),e===`system`&&(0,K.jsxs)(`span`,{className:`appearance-mini-window appearance-mini-dark`,children:[(0,K.jsx)(`span`,{className:`appearance-mini-sidebar`}),(0,K.jsxs)(`span`,{className:`appearance-mini-chat`,children:[(0,K.jsx)(`i`,{}),(0,K.jsx)(`i`,{}),(0,K.jsx)(`b`,{}),(0,K.jsx)(`i`,{}),(0,K.jsx)(`b`,{}),(0,K.jsx)(`em`,{})]})]})]})]})},e))})]}),(0,K.jsxs)(`div`,{className:`appearance-card`,children:[(0,K.jsxs)(`div`,{className:`appearance-row appearance-theme-row`,children:[(0,K.jsx)(`span`,{children:o(`appearanceTheme`)}),(0,K.jsxs)(`div`,{className:`appearance-theme-actions`,children:[(0,K.jsx)(Cd,{content:o(`appearanceImport`),children:(0,K.jsx)(`button`,{type:`button`,className:`icon-button`,"aria-label":o(`appearanceImport`),disabled:k,onClick:()=>{x(!1),g(!0)},children:(0,K.jsx)(W,{"aria-hidden":`true`})})}),(0,K.jsx)(Cd,{content:o(`appearanceCopy`),children:(0,K.jsx)(`button`,{type:`button`,className:`icon-button`,"aria-label":o(`appearanceCopy`),disabled:k,onClick:()=>{wd(JSON.stringify({version:1,theme:f,appearance:{...u,palette:d}})).then(e=>C(e?`saved`:`failed`))},children:(0,K.jsx)(ue,{"aria-hidden":`true`})})}),(0,K.jsx)(TI,{label:o(`appearanceTheme`),value:d,options:gI.map(e=>({id:e,label:e==="default"?`OpenPI`:o(`theme${e[0].toUpperCase()}${e.slice(1)}`)})),disabled:k,onSelect:e=>{let t=gI.find(t=>t===e);t&&j({palette:t})}})]})]}),(0,K.jsxs)(`div`,{className:`appearance-row`,children:[(0,K.jsx)(`span`,{children:o(`appearanceAccent`)}),(0,K.jsxs)(`div`,{className:`appearance-accent-controls`,children:[(0,K.jsx)(TI,{label:o(`appearanceAccent`),value:u.accent,options:wI.map((e,t)=>({id:e,label:o(`appearanceAccent${t}`),color:e||`var(--text)`})),disabled:k,onSelect:e=>void j({accent:e})}),(0,K.jsx)(EI,{label:o(`appearanceCustomAccent`),value:u.accent,fallback:`#2563EB`,disabled:k,onSave:e=>j({accent:e})})]})]}),(0,K.jsxs)(`div`,{className:`appearance-row`,children:[(0,K.jsx)(`span`,{children:o(`appearanceBackground`)}),(0,K.jsx)(EI,{label:o(`appearanceBackground`),value:u.background,fallback:N.background,disabled:k,onSave:e=>j({background:e})})]}),(0,K.jsxs)(`div`,{className:`appearance-row`,children:[(0,K.jsx)(`span`,{children:o(`appearanceForeground`)}),(0,K.jsx)(EI,{label:o(`appearanceForeground`),value:u.foreground,fallback:N.foreground,disabled:k,onSave:e=>j({foreground:e})})]}),(0,K.jsxs)(`div`,{className:`appearance-row`,children:[(0,K.jsx)(`span`,{children:o(`appearanceFont`)}),(0,K.jsx)(TI,{label:o(`appearanceFont`),value:u.font===`system`?`codex`:u.font,options:_I.map(e=>({id:e,label:o(`appearanceFont_${e}`)})),disabled:k,onSelect:e=>{let t=_I.find(t=>t===e);t&&j({font:t})}})]})]}),S&&(0,K.jsx)(`p`,{role:S===`failed`?`alert`:`status`,className:`appearance-share-status`,children:o(S===`saved`?`appearanceCopied`:`appearanceCopyFailed`)})]}),(0,K.jsxs)(`section`,{className:`appearance-section`,children:[(0,K.jsxs)(`button`,{type:`button`,className:`appearance-advanced-toggle`,"aria-expanded":p,"aria-controls":`appearance-advanced`,onClick:()=>m(!p),children:[o(`appearanceAdvanced`),p?(0,K.jsx)(L,{"aria-hidden":`true`}):(0,K.jsx)(z,{"aria-hidden":`true`})]}),p&&c&&(0,K.jsxs)(`div`,{id:`appearance-advanced`,className:`appearance-card appearance-advanced-content`,children:[(0,K.jsxs)(`div`,{className:`appearance-row`,children:[(0,K.jsx)(`span`,{children:o(`expandThinkingByDefault`)}),(0,K.jsx)(QP,{label:o(`expandThinkingByDefault`),isLabelHidden:!0,value:c.ui.webExpandThinking,size:`sm`,isDisabled:k,onChange:e=>void a({expandThinking:e})})]}),(0,K.jsxs)(`div`,{className:`appearance-slider-row`,children:[(0,K.jsxs)(`div`,{className:`settings-slider-heading`,children:[(0,K.jsx)(`span`,{children:o(`chatContentWidth`)}),(0,K.jsxs)(`output`,{children:[w,`px`]}),(0,K.jsx)(`button`,{type:`button`,className:`settings-reset-button`,"aria-label":o(`resetChatContentWidth`),disabled:k||w===820,onClick:()=>{T(820),a({chatWidth:820}).then(e=>{e||T(c.ui.webChatWidth)})},children:(0,K.jsx)(ft,{"aria-hidden":`true`})})]}),(0,K.jsx)($F,{label:o(`chatContentWidth`),isLabelHidden:!0,value:w,min:820,max:2e3,step:10,width:`100%`,valueDisplay:`none`,isDisabled:k,onChange:e=>T(e),onChangeEnd:e=>{e!==c.ui.webChatWidth&&a({chatWidth:e}).then(e=>{e||T(c.ui.webChatWidth)})}})]}),(0,K.jsxs)(`div`,{className:`appearance-slider-row`,children:[(0,K.jsxs)(`div`,{className:`settings-slider-heading`,children:[(0,K.jsx)(`span`,{children:o(`chatFontSize`)}),(0,K.jsxs)(`output`,{children:[E,`px`]}),(0,K.jsx)(`button`,{type:`button`,className:`settings-reset-button`,"aria-label":o(`resetChatFontSize`),disabled:k||E===14,onClick:()=>{D(14),a({chatFontSize:14}).then(e=>{e||D(c.ui.webChatFontSize)})},children:(0,K.jsx)(ft,{"aria-hidden":`true`})})]}),(0,K.jsx)($F,{label:o(`chatFontSize`),isLabelHidden:!0,value:E,min:12,max:24,step:1,width:`100%`,valueDisplay:`none`,isDisabled:k,onChange:e=>D(e),onChangeEnd:e=>{e!==c.ui.webChatFontSize&&a({chatFontSize:e}).then(e=>{e||D(c.ui.webChatFontSize)})}})]}),(0,K.jsxs)(`div`,{className:`appearance-row`,children:[(0,K.jsx)(`span`,{children:o(`appearanceReset`)}),(0,K.jsxs)(`button`,{type:`button`,className:`appearance-reset`,disabled:k,onClick:()=>void a({theme:`system`,appearance:yI,chatWidth:820,chatFontSize:14,expandThinking:!1}),children:[(0,K.jsx)(ft,{"aria-hidden":`true`}),o(`appearanceResetAction`)]})]})]})]}),(0,K.jsxs)($j,{isOpen:h,onOpenChange:e=>{e||M()},"aria-label":o(`appearanceImport`),width:480,className:`appearance-import-dialog`,children:[(0,K.jsx)(`h2`,{className:`appearance-import-title`,children:o(`appearanceImport`)}),(0,K.jsxs)(`form`,{className:`appearance-import-form`,onSubmit:e=>{e.preventDefault(),!(!A||k)&&(x(!1),a(A).then(e=>{e?(g(!1),y(``)):x(!0)}))},children:[(0,K.jsxs)(`label`,{children:[o(`appearanceThemeValue`),(0,K.jsx)(`textarea`,{maxLength:2e3,value:v,disabled:n,placeholder:o(`appearanceImportPlaceholder`),onChange:e=>{x(!1),y(e.target.value)}})]}),v&&!A&&(0,K.jsx)(`p`,{role:`alert`,children:o(`appearanceImportInvalid`)}),b&&(0,K.jsx)(`p`,{role:`alert`,children:o(`settingsPreferencesSaveFailed`)}),(0,K.jsxs)(`div`,{className:`appearance-import-actions`,children:[(0,K.jsx)(`button`,{type:`button`,disabled:n,onClick:M,children:o(`cancel`)}),(0,K.jsx)(`button`,{type:`submit`,disabled:k||!A,children:o(n?`savingSettings`:`appearanceImportAction`)})]})]})]})]})}function OI({workspaces:e,onRestore:t}){let{t:n,i18n:r}=cr(),i=(0,_.useMemo)(()=>new rf,[]),[a,o]=(0,_.useState)(``),[s,c]=(0,_.useState)(``),[l,u]=(0,_.useState)(`updated`),[d,f]=(0,_.useState)(new Set),[p,m]=(0,_.useState)(null),[h,g]=(0,_.useState)(!1),[v,y]=(0,_.useState)(null),[b,x]=(0,_.useState)(null),[w,T]=(0,_.useState)(new Set),E=(0,_.useRef)(new Set),D=(0,_.useRef)(null),O=(0,_.useRef)(!1),k=JSON.stringify([a.trim(),s,l]),A=(0,_.useRef)({key:k});A.current.key!==k&&(A.current={key:k});let j=p?.scope===k?p:null,M=v?.scope===k?v:null,N=(0,_.useCallback)(async(e,t=0)=>{D.current?.abort();let n=new AbortController;D.current=n,g(!0),y(null);let r={query:a.trim(),sort:l,...s?{cwd:s}:{},limit:25};try{let a=await i.listArchivedSessions({...r,...e?{cursor:e}:{}},n.signal);if(n.signal.aborted||D.current!==n)return;let o=[...a.sessions];for(;!e&&o.length!o.some(t=>t.path===e.path));if(o.push(...e),!e.length)break}m(t=>({...a,scope:k,sessions:e&&t?.scope===k?[...t.sessions,...o.filter(e=>!t.sessions.some(t=>t.path===e.path))]:o}))}catch(t){!n.signal.aborted&&D.current===n&&y({scope:k,stale:t instanceof tf&&t.code===`ARCHIVED_SESSION_CURSOR_STALE`,...e?{cursor:e}:{}})}finally{D.current===n&&(D.current=null,g(!1))}},[i,s,a,k,l]);(0,_.useEffect)(()=>(O.current=!0,()=>{O.current=!1}),[]),(0,_.useEffect)(()=>(x(null),N(),()=>{D.current?.abort(),D.current=null}),[N]);let P=async e=>{if(E.current.has(e))return;E.current.add(e),T(new Set(E.current)),x(null);let n=A.current;try{let r=await t(e);if(!O.current||A.current!==n)return;if(!r){x(e);return}let i=j?.sessions.length??0;m(t=>t?{...t,sessions:t.sessions.filter(t=>t.path!==e)}:null),await N(void 0,i)}catch{O.current&&A.current===n&&x(e)}finally{E.current.delete(e),O.current&&T(new Set(E.current))}},F=new Map;for(let e of j?.sessions??[]){let t=e.workspacePath??e.cwd,n=F.get(t)??[];n.push(e),F.set(t,n)}let I=t=>e.find(e=>e.path===t)?.name??t.split(/[\\/]/u).filter(Boolean).at(-1)??t,R=[...new Set([...e.map(e=>e.path),...F.keys(),...s?[s]:[]])];return(0,K.jsxs)(`section`,{className:`settings-content-page settings-archive-panel`,children:[(0,K.jsx)(`h1`,{children:n(`settingsArchivedChats`)}),(0,K.jsxs)(`div`,{className:`settings-archive-toolbar`,children:[(0,K.jsxs)(`label`,{className:`settings-archive-search`,children:[(0,K.jsx)(ht,{"aria-hidden":`true`}),(0,K.jsx)(`input`,{type:`search`,"aria-label":n(`searchArchivedChats`),placeholder:n(`searchArchivedChats`),maxLength:160,value:a,onChange:e=>o(e.target.value)}),a&&(0,K.jsx)(`button`,{type:`button`,"aria-label":n(`settingsClearSearch`),onClick:()=>o(``),children:(0,K.jsx)(Lt,{"aria-hidden":`true`})})]}),(0,K.jsxs)(`select`,{"aria-label":n(`archiveProjectFilter`),value:s,onChange:e=>c(e.target.value),children:[(0,K.jsx)(`option`,{value:``,children:n(`archiveAllProjects`)}),R.map(e=>(0,K.jsx)(`option`,{value:e,children:I(e)},e))]}),(0,K.jsxs)(`select`,{"aria-label":n(`archiveSort`),value:l,onChange:e=>u(e.target.value===`created`?`created`:`updated`),children:[(0,K.jsx)(`option`,{value:`updated`,children:n(`archiveSortUpdated`)}),(0,K.jsx)(`option`,{value:`created`,children:n(`archiveSortCreated`)})]}),(0,K.jsx)(`button`,{type:`button`,className:`icon-button`,"aria-label":n(`refreshArchives`),disabled:h,onClick:()=>void N(void 0,j?.sessions.length),children:(0,K.jsx)(dt,{"aria-hidden":`true`})})]}),M&&(0,K.jsxs)(`div`,{className:`settings-archive-error`,role:`alert`,children:[(0,K.jsx)(`span`,{children:n(M.stale?`archiveCursorStale`:`archiveLoadFailed`)}),(0,K.jsx)(`button`,{type:`button`,disabled:h,onClick:()=>void N(M.stale?void 0:M.cursor),children:n(`retryAdmissionCheck`)})]}),b&&(0,K.jsx)(`div`,{className:`settings-archive-error`,role:`alert`,children:n(`restoreFailed`)}),h&&(0,K.jsx)(`p`,{role:`status`,className:`settings-archive-status`,children:n(`loadingArchives`)}),!h&&!M&&j?.sessions.length===0&&(0,K.jsxs)(`div`,{className:`settings-archive-empty`,children:[(0,K.jsx)(C,{"aria-hidden":`true`}),(0,K.jsx)(`p`,{children:n(a.trim()||s?`noMatchingScannedArchives`:j.truncation.truncated?`noScannedArchives`:`noArchivedSessions`)})]}),(0,K.jsx)(`div`,{className:`settings-archive-groups`,children:[...F].map(([e,t])=>(0,K.jsxs)(`section`,{className:`settings-archive-group`,children:[(0,K.jsxs)(`button`,{type:`button`,className:`settings-archive-group-heading`,"aria-label":n(`archiveProjectGroup`,{project:I(e),count:t.length}),"aria-expanded":!d.has(e),"aria-controls":`archive-group-${encodeURIComponent(e)}`,onClick:()=>f(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n}),children:[d.has(e)?(0,K.jsx)(z,{"aria-hidden":`true`}):(0,K.jsx)(L,{"aria-hidden":`true`}),(0,K.jsx)(De,{"aria-hidden":`true`}),(0,K.jsx)(`span`,{title:e,children:I(e)}),(0,K.jsx)(`small`,{children:t.length})]}),!d.has(e)&&(0,K.jsx)(`ul`,{id:`archive-group-${encodeURIComponent(e)}`,className:`settings-archive-list`,children:t.map(e=>{let t=e.name||e.firstMessage||n(`untitledSession`),i=new Date(l===`created`?e.created:e.modified);return(0,K.jsxs)(`li`,{className:`settings-archive-row`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`span`,{className:`settings-archive-chat-title`,title:t,children:t}),(0,K.jsx)(`time`,{dateTime:Number.isNaN(i.getTime())?void 0:i.toISOString(),children:Number.isNaN(i.getTime())?n(`unknownState`):new Intl.DateTimeFormat(r.language,{dateStyle:`medium`}).format(i)})]}),(0,K.jsxs)(`button`,{type:`button`,"aria-label":n(`restoreArchivedChat`,{title:t}),disabled:w.has(e.path),onClick:()=>void P(e.path),children:[(0,K.jsx)(S,{"aria-hidden":`true`}),(0,K.jsx)(`span`,{children:n(w.has(e.path)?`restoringConversation`:`restoreConversation`)})]})]},e.path)})})]},e))}),!!j?.truncation.recordsUnscanned&&(0,K.jsx)(`p`,{className:`settings-archive-status`,children:n(`archiveScanBounded`,{count:j.truncation.recordsUnscanned})}),j?.nextCursor&&(0,K.jsx)(`button`,{type:`button`,className:`settings-archive-more`,disabled:h,onClick:()=>void N(j.nextCursor),children:n(`moreArchives`)})]})}var kI=[{id:`general`,group:`settingsPersonal`,label:`generalSettings`,Icon:xt,terms:[`agentBehavior`,`resultDisplay`,`workflowLimits`]},{id:`appearance`,group:`settingsPersonal`,label:`appearance`,Icon:Dt,terms:[`appearanceTheme`,`appearanceAccent`,`appearanceFont`,`chatContentWidth`,`chatFontSize`]},{id:`archived-chats`,group:`settingsPersonal`,label:`settingsArchivedChats`,Icon:C,terms:[`restoreConversation`]},{id:`configuration`,group:`settingsPersonal`,label:`configurationSettings`,Icon:bt,terms:[`configurationApproval`,`configurationSandbox`,`configurationVerbosity`,`configurationSummary`,`configurationReasoningLevels`,`configurationDependencies`]},{id:`models`,group:`settingsAgent`,label:`modelSettings`,Icon:fe,terms:[`modelDefaultTitle`]},{id:`subagents`,group:`settingsAgent`,label:`subagentsSettings`,Icon:M,terms:[]},{id:`web-search`,group:`settingsAgent`,label:`webSearchSettings`,Icon:ht,terms:[]},{id:`skills`,group:`settingsIntegrations`,label:`skillsSettings`,Icon:Ie,terms:[]},{id:`plugins`,group:`settingsIntegrations`,label:`pluginsSettings`,Icon:ct,terms:[]},{id:`browser`,group:`settingsIntegrations`,label:`browserSettings`,Icon:pe,terms:[]}];function AI(e){return kI.find(({id:t})=>t===e)?.id}function jI({sessionId:e,sessionPath:t,cwd:n,entry:r=`general`,models:i,currentModel:a,thinkingLevel:o,theme:s,preferences:c,workspaces:l=[],onRestoreSession:u,capabilities:d,setupBusy:f,setupBlockedReason:p,plan:m,planSelectionPending:h=!1,onExitPlan:g,setupOutcome:v,onConfigureOpenPi:y,interaction:b,onPreferencesChanged:x,onSelectModel:S,onOpenRuntimeStatus:C,onClose:w}){let{t:T}=cr(),E=f||!!p,D=(0,_.useRef)(null),O=(0,_.useRef)(null),[k,A]=(0,_.useState)(``),[j,M]=(0,_.useState)(r===`credentials`?`models`:r),[N,P]=(0,_.useState)(r===`credentials`||r===`models`),[F,I]=(0,_.useState)(!1),[L,R]=(0,_.useState)(!1),[z,B]=(0,_.useState)(`general`),V=(0,_.useRef)(!1),H=(0,_.useRef)(!1),ee=(0,_.useRef)(0),[te,ne]=(0,_.useState)(!1),re=(0,_.useRef)(!1),[ie,ae]=(0,_.useState)(!1),[U,oe]=(0,_.useState)(null),[se,ce]=(0,_.useState)(!1),[le,ue]=(0,_.useState)(!1),[de,fe]=(0,_.useState)(null),W=le,pe=(0,_.useRef)(void 0),me=m!==void 0&&m!==`inactive`,he=F||E||me||h,ge=L&&z!==j||!L&&(j===`skills`||j===`plugins`||j===`web-search`)?void 0:!L||v?.requestId!==pe.current?v:void 0,{catalog:_e,error:ve,refresh:ye,updateSetup:be}=hI(e,a?`${a.provider}/${a.id}`:``,JSON.stringify(c)),xe=ge!==void 0&&[`failed`,`cancelled`,`unconfirmed`].includes(ge.status);(0,_.useEffect)(()=>{D.current?.focus()},[]),(0,_.useEffect)(()=>{if(L){if(ge&&ge.status!==`pending`&&V.current){V.current=!1,H.current=!1,window.clearTimeout(ee.current),ye(),x();return}if(E){H.current=!0;return}!H.current||!V.current||(V.current=!1,H.current=!1,window.clearTimeout(ee.current),ye(),x())}},[x,ye,E,L,ge]),(0,_.useEffect)(()=>()=>window.clearTimeout(ee.current),[]);let Se=async e=>{if(ae(!1),he)return!1;pe.current=v?.requestId,B(j),I(!0),R(!1),V.current=!1,H.current=!1,window.clearTimeout(ee.current),oe(null);try{let t=await y(e);return t?(R(!0),V.current=!0,ee.current=window.setTimeout(()=>{!V.current||H.current||(V.current=!1,H.current=!1,ye(),x())},2e3)):oe(T(`setupRequestFailed`)),t}catch(e){return I(!1),oe(e instanceof Error?e.message:T(`setupRequestFailed`)),!1}finally{I(!1)}},Ce=async()=>{if(he||!_e?.sessionPath)throw Error(T(`resourceReloadFailed`));I(!0);try{await new rf().reloadSettingsResources(e,_e.sessionPath),ye(),x()}finally{I(!1)}},we=async e=>{if(re.current||!_e)return!1;re.current=!0,ne(!0),ae(!1),oe(null);try{let t=await new rf().savePreferences(e);return be(t.setup),ae(!0),x(),!0}catch{return oe(T(`settingsPreferencesSaveFailed`)),!1}finally{re.current=!1,ne(!1)}},Te=e=>{W||(M(e),A(``),e===`models`&&P(!0),oe(null))};(0,_.useEffect)(()=>{let e=new URL(window.location.href);e.searchParams.set(`settings`,j),window.history.replaceState(window.history.state,``,e)},[j]);let G=kI.filter(({label:e,terms:t})=>[e,...t].some(e=>T(e).normalize(`NFKC`).toLocaleLowerCase().includes(k.trim().normalize(`NFKC`).toLocaleLowerCase()))),Ee=(e,t=!1)=>{if(!W){if(se&&!t){fe(e);return}fe(null),e.kind===`runtime`?C():w()}};return(0,K.jsxs)($j,{isOpen:!0,purpose:`info`,padding:0,width:`calc(100vw - 32px)`,maxHeight:`calc(100dvh - 16px)`,className:`provider-settings-dialog`,"aria-label":T(`settings`),onOpenChange:e=>{!e&&!de&&Ee({kind:`close`})},children:[(0,K.jsxs)(`section`,{className:`provider-settings-surface`,children:[(0,K.jsxs)(`aside`,{className:`provider-settings-sidebar`,children:[(0,K.jsxs)(`header`,{className:`provider-settings-header`,children:[(0,K.jsx)(`strong`,{className:`provider-settings-title`,children:T(`settings`)}),(0,K.jsx)(`select`,{className:`provider-settings-mobile-picker`,"aria-label":T(`settingsNavigation`),disabled:W,value:j,onChange:e=>{let t=kI.find(({id:t})=>t===e.target.value);t&&Te(t.id)},children:kI.map(({id:e,label:t})=>(0,K.jsx)(`option`,{value:e,children:T(t)},e))})]}),(0,K.jsxs)(`label`,{className:`provider-settings-search`,children:[(0,K.jsx)(ht,{"aria-hidden":`true`}),(0,K.jsx)(`input`,{type:`search`,"aria-label":T(`settingsSearch`),placeholder:T(`settingsSearch`),value:k,onChange:e=>A(e.target.value),disabled:W}),k&&(0,K.jsx)(`button`,{type:`button`,"aria-label":T(`settingsClearSearch`),onClick:()=>A(``),children:(0,K.jsx)(Lt,{"aria-hidden":`true`})})]}),(0,K.jsxs)(`div`,{className:`provider-settings-navigation`,ref:O,"aria-label":T(`settingsNavigation`),role:`tablist`,"aria-orientation":`vertical`,children:[[`settingsPersonal`,`settingsAgent`,`settingsIntegrations`].map(e=>(0,K.jsxs)(`div`,{className:`provider-settings-nav-group`,children:[G.some(t=>t.group===e)&&(0,K.jsx)(`p`,{children:T(e)}),G.filter(t=>t.group===e).map(({id:e,label:t,Icon:n})=>(0,K.jsxs)(`button`,{type:`button`,role:`tab`,disabled:W,id:`settings-tab-${e}`,tabIndex:j===e||!G.some(e=>e.id===j)&&G[0]?.id===e?0:-1,"aria-selected":j===e,"aria-controls":`settings-panel-${e}`,className:`provider-settings-tab`,title:T(t),onClick:()=>Te(e),onKeyDown:t=>{if(t.altKey||t.ctrlKey||t.metaKey||t.nativeEvent.isComposing)return;let n=G.findIndex(t=>t.id===e),r=t.key===`Home`?0:t.key===`End`?G.length-1:t.key===`ArrowDown`||t.key===`ArrowRight`?(n+1)%G.length:t.key===`ArrowUp`||t.key===`ArrowLeft`?(n+G.length-1)%G.length:void 0;if(r===void 0)return;t.preventDefault();let i=G[r].id;Te(i),O.current?.querySelector(`#settings-tab-${i}`)?.focus()},children:[(0,K.jsx)(n,{"aria-hidden":`true`}),(0,K.jsx)(`span`,{children:T(t)})]},e))]},e)),G.length===0&&(0,K.jsx)(`p`,{className:`provider-settings-no-results`,role:`status`,children:T(`settingsNoResults`)})]}),(0,K.jsx)(`button`,{ref:D,type:`button`,className:`icon-button provider-settings-close`,"aria-label":T(`close`),disabled:W,title:T(W?`savingSettings`:`close`),onClick:()=>Ee({kind:`close`}),children:(0,K.jsx)(Lt,{})})]}),(0,K.jsxs)(`div`,{className:`provider-settings-body`,children:[me&&j!==`browser`&&(0,K.jsxs)(`div`,{className:`settings-plan-notice`,role:`status`,children:[(0,K.jsx)(`span`,{children:T(E?`setupPlanBusy`:`setupPlanBlocked`)}),(0,K.jsx)(qc,{label:T(`planModeExit`),variant:`secondary`,size:`sm`,isDisabled:E||h||!g,onClick:()=>void g?.()})]}),(0,K.jsxs)(`div`,{className:`provider-settings-main`,children:[(0,K.jsx)(`div`,{id:`settings-panel-configuration`,"aria-labelledby":`settings-tab-configuration`,"aria-label":T(`configurationSettings`),role:`tabpanel`,hidden:j!==`configuration`,children:j===`configuration`&&(0,K.jsx)(sF,{catalog:_e,error:ve,pending:he||L&&z===`configuration`&&(!ge||ge.status===`pending`),preferencePending:te,onConfigure:Se,onUpdatePreferences:we,onRefresh:ye,onOpenRuntimeStatus:()=>Ee({kind:`runtime`})})}),(0,K.jsx)(`div`,{id:`settings-panel-appearance`,"aria-labelledby":`settings-tab-appearance`,"aria-label":T(`appearance`),role:`tabpanel`,hidden:j!==`appearance`,children:(0,K.jsx)(DI,{catalog:_e,theme:s,pending:te,error:ve,onRefresh:ye,onUpdatePreferences:we})}),(0,K.jsx)(`div`,{id:`settings-panel-archived-chats`,"aria-labelledby":`settings-tab-archived-chats`,"aria-label":T(`settingsArchivedChats`),role:`tabpanel`,hidden:j!==`archived-chats`,children:j===`archived-chats`&&(0,K.jsx)(OI,{workspaces:l,onRestore:u??(async()=>!1)})}),(0,K.jsx)(`div`,{id:`settings-panel-web-search`,"aria-labelledby":`settings-tab-web-search`,"aria-label":T(`webSearchSettings`),role:`tabpanel`,hidden:j!==`web-search`,children:j===`web-search`&&(0,K.jsx)(cF,{catalog:_e,error:ve,pending:he,onConfigure:Se,onRefresh:ye})}),(0,K.jsx)(`div`,{id:`settings-panel-browser`,"aria-labelledby":`settings-tab-browser`,"aria-label":T(`browserSettings`),role:`tabpanel`,hidden:j!==`browser`,children:j===`browser`&&(0,K.jsx)(aF,{onConfigure:Se,setupPending:he})}),(0,K.jsx)(`div`,{id:`settings-panel-general`,"aria-labelledby":`settings-tab-general`,"aria-label":T(`generalSettings`),role:`tabpanel`,hidden:j!==`general`,children:(0,K.jsx)(iI,{catalog:_e,error:ve,currentModel:a,thinkingLevel:o,cwd:n,setupPending:F||E,preferencePending:te||!_e,setupBusy:E,setupBlockedReason:p,setupBlocked:me||h,onConfigure:Se,onUpdatePreferences:we,onOpenRuntimeStatus:()=>Ee({kind:`runtime`}),onRefresh:ye})}),(0,K.jsx)(`section`,{id:`settings-panel-models`,"aria-labelledby":`settings-tab-models`,"aria-label":T(`modelSettings`),className:`settings-models`,role:`tabpanel`,hidden:j!==`models`,children:N&&(0,K.jsx)(VF,{sessionId:e,sessionPath:t,models:i,currentModel:a,busy:E,focusCredentials:r===`credentials`,onSaved:async()=>(ye(),x()),onSelectModel:S,onDraftChange:ce,onSavingChange:ue},e)}),(0,K.jsx)(`div`,{id:`settings-panel-skills`,"aria-labelledby":`settings-tab-skills`,"aria-label":T(`skillsSettings`),role:`tabpanel`,hidden:j!==`skills`,children:(0,K.jsx)(uI,{catalog:_e,error:ve,onRefresh:ye,setupPending:he,onConfigure:Se,onReload:Ce},e)}),(0,K.jsx)(`div`,{id:`settings-panel-subagents`,"aria-labelledby":`settings-tab-subagents`,"aria-label":T(`subagentsSettings`),role:`tabpanel`,hidden:j!==`subagents`,children:(0,K.jsx)(dI,{catalog:_e,error:ve,currentModel:a,models:i,activity:d?.subagents,setupPending:F||E,setupBlocked:me||h,onConfigure:Se,onRefresh:ye})}),(0,K.jsx)(`div`,{id:`settings-panel-plugins`,"aria-labelledby":`settings-tab-plugins`,"aria-label":T(`pluginsSettings`),role:`tabpanel`,hidden:j!==`plugins`,children:(0,K.jsx)(mI,{catalog:_e,error:ve,onRefresh:ye,setupPending:he,onConfigure:Se,onReload:Ce},e)})]}),b,U&&(0,K.jsx)(`div`,{className:`settings-global-error`,role:`alert`,children:U}),(te||ie)&&!U&&!xe&&(0,K.jsx)(`div`,{className:`settings-global-status`,role:`status`,children:T(te?`savingSettings`:`settingsPreferencesSaved`)}),!te&&(!ie||xe)&&(L&&z===j||ge)&&!U&&(0,K.jsxs)(`div`,{className:ge?.status===`failed`?`settings-global-error`:`settings-global-status`,role:ge?.status===`failed`?`alert`:`status`,children:[T(ge?(j===`skills`||j===`plugins`||j===`web-search`)&&[`unconfirmed`,`saved`,`unchanged`].includes(ge.status)?`resourceRequestFinished`:`setupOutcome_${ge.status}`:E?`setupRequestRunning`:j===`skills`||j===`plugins`||j===`web-search`?`resourceRequestSubmitted`:`setupRequestAccepted`),ge?.error&&(0,K.jsx)(`p`,{children:ge.error})]})]})]}),de&&(0,K.jsx)(HP,{isOpen:!0,onOpenChange:e=>{e||fe(null)},title:T(`unsavedSettingsTitle`),description:T(`unsavedSettingsDetail`),cancelLabel:T(`keepEditing`),actionLabel:T(`discardAndContinue`),onAction:()=>Ee(de,!0)})]})}function MI({identity:e}){let t=0;for(let n of e)t=t*31+n.charCodeAt(0)>>>0;let n=t%6;return(0,K.jsx)(`span`,{className:`subagent-avatar tone-${n}`,"aria-hidden":`true`,children:(0,K.jsx)(`svg`,{"aria-hidden":`true`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.3`,children:[(0,K.jsxs)(`g`,{children:[(0,K.jsx)(`circle`,{cx:`12`,cy:`12`,r:`9`}),(0,K.jsx)(`ellipse`,{cx:`12`,cy:`12`,rx:`4`,ry:`9`}),(0,K.jsx)(`path`,{d:`M3 12h18M5 6.5c4 3 10 3 14 0M5 17.5c4-3 10-3 14 0`})]},`sphere`),(0,K.jsx)(`g`,{children:(0,K.jsx)(`path`,{d:`M4 20V4a16 16 0 0 1 16 16H4ZM4 4l16 16M4 9l11 11M4 14l6 6M10 5l-6 15M16 10L4 20`})},`fan`),(0,K.jsxs)(`g`,{children:[(0,K.jsx)(`path`,{d:`m12 2 3 6 7-1-4 5 4 5-7-1-3 6-3-6-7 1 4-5-4-5 7 1Z`}),(0,K.jsx)(`circle`,{cx:`12`,cy:`12`,r:`4`})]},`rosette`),(0,K.jsxs)(`g`,{children:[(0,K.jsx)(`circle`,{cx:`12`,cy:`12`,r:`9`}),(0,K.jsx)(`path`,{d:`M3 12h18M12 3a9 9 0 0 0 0 18M12 6a6 6 0 0 0 0 12M12 9a3 3 0 0 0 0 6M12 3v18`})]},`arcs`),(0,K.jsx)(`g`,{children:(0,K.jsx)(`path`,{d:`m12 2 9 5v10l-9 5-9-5V7Zm0 0v20M3 7l18 10M21 7 3 17M3 7l9 5 9-5M3 17l9-5 9 5`})},`prism`),(0,K.jsxs)(`g`,{children:[(0,K.jsx)(`path`,{d:`M12 12V2c6 0 10 4 10 10H12Zm0 0v10C6 22 2 18 2 12h10ZM12 12H2C2 6 6 2 12 2v10Zm0 0h10c0 6-4 10-10 10V12Z`}),(0,K.jsx)(`circle`,{cx:`12`,cy:`12`,r:`2`,fill:`currentColor`})]},`windmill`)][n]})})}function NI(e,t,n,r){let i=(0,_.useMemo)(()=>new rf,[]),[a,o]=(0,_.useState)(null),[s,c]=(0,_.useState)(!1),[l,u]=(0,_.useState)(!1),[d,f]=(0,_.useState)(0),p=(0,_.useRef)(null);return(0,_.useEffect)(()=>{if(!n)return;let r=new AbortController;return p.current=r,c(!0),u(!1),i.sessionSources(e,t,r.signal).then(n=>{!r.signal.aborted&&n.sessionId===e&&n.path===t&&o(n)}).catch(()=>{r.signal.aborted||u(!0)}).finally(()=>{r.signal.aborted||(c(!1),p.current=null)}),()=>{r.abort(),p.current?.abort(),p.current=null}},[i,e,t,n,r,d]),{page:a?.sessionId===e&&a.path===t?a:null,loading:s,error:l,loadMore:async()=>{if(p.current||!a||a.nextOffset===void 0)return;let n=new AbortController;p.current=n,c(!0),u(!1);try{let r=await i.sessionSources(e,t,n.signal,a.nextOffset,a.revision);!n.signal.aborted&&r.sessionId===e&&r.path===t&&r.revision===a.revision&&o({...r,sources:[...a.sources,...r.sources]})}catch{n.signal.aborted||u(!0)}finally{n.signal.aborted||(c(!1),p.current=null)}},refresh:()=>f(e=>e+1)}}function PI({sessionId:e,path:t,source:n,thumbnail:r=!1,active:i=!0}){let{t:a}=cr(),o=(0,_.useRef)(null),[s,c]=(0,_.useState)(!1),l=JSON.stringify([e,t,n.entryId,n.partIndex]),[u,d]=(0,_.useState)(null);(0,_.useEffect)(()=>{if(!r||!o.current||typeof IntersectionObserver>`u`)return;let e=new IntersectionObserver(([e])=>c(!!e?.isIntersecting));return e.observe(o.current),()=>e.disconnect()},[r]),(0,_.useEffect)(()=>{if(!i||r&&!s){d(null);return}let a=new AbortController,o;return d({identity:l}),new rf().sourceImage(e,t,n.entryId,n.partIndex,a.signal).then(e=>{if(a.signal.aborted)return;if(![`image/png`,`image/jpeg`,`image/gif`,`image/webp`].includes(e.mimeType)||e.data.length>Ud)throw Error(`Invalid image`);let t=atob(e.data);if(t.length>10485760||btoa(t)!==e.data)throw Error(`Invalid image`);let n=Uint8Array.from(t,e=>e.charCodeAt(0));o=URL.createObjectURL(new Blob([n],{type:e.mimeType})),d({identity:l,url:o})}).catch(()=>{a.signal.aborted||d({identity:l,failed:!0})}),()=>{a.abort(),o&&URL.revokeObjectURL(o)}},[e,t,n.entryId,n.partIndex,l,i,r,s]);let f=i&&(!r||s)&&u?.identity===l?u:null;return(0,K.jsx)(`span`,{ref:o,className:`session-source-image`,"data-thumbnail":r||void 0,children:f?.url&&!f.failed?(0,K.jsx)(`img`,{src:f.url,alt:r?``:n.name||a(`attachedImage`),onError:()=>d({identity:l,failed:!0})}):r?(0,K.jsx)(Ne,{"aria-hidden":`true`}):(0,K.jsx)(`p`,{role:f?.failed?`alert`:`status`,children:a(f?.failed?`imagePreviewFailed`:`readingFile`)})})}function FI({source:e,sessionId:t,path:n,onOpen:r,thumbnail:i=!0}){let{t:a}=cr();return(0,K.jsxs)(`button`,{type:`button`,className:`session-overview-row session-source-row`,title:e.reference||e.name||a(`attachedImage`),onClick:r,children:[(0,K.jsx)(`span`,{className:`session-source-icon`,children:e.kind===`image`?i?(0,K.jsx)(PI,{sessionId:t,path:n,source:e,thumbnail:!0}):(0,K.jsx)(Ne,{"aria-hidden":`true`}):(0,K.jsx)(Se,{"aria-hidden":`true`})}),(0,K.jsx)(`span`,{children:e.name||a(`attachedImage`)})]})}function II({sessionId:e,path:t,open:n,source:r,data:i,onSelect:a,onClose:o}){let{t:s}=cr(),[c,l]=(0,_.useState)(!1);return(0,_.useEffect)(()=>{r?.id,l(!1)},[e,t,r?.id]),(0,K.jsx)($j,{isOpen:n,onOpenChange:e=>!e&&o(),purpose:`info`,width:800,maxHeight:`calc(100dvh - 32px)`,padding:0,"aria-label":s(`sessionSources`),children:(0,K.jsxs)(`div`,{className:`session-sources-dialog draft-image-preview`,children:[(0,K.jsxs)(`header`,{children:[r&&i&&(0,K.jsx)(`button`,{type:`button`,"aria-label":s(`sourcesBack`),onClick:()=>a(null),children:(0,K.jsx)(T,{})}),(0,K.jsx)(`strong`,{title:r?.name,children:r?r.name||s(`attachedImage`):s(`sessionSources`)}),r&&(0,K.jsx)(`button`,{type:`button`,"aria-pressed":c,onClick:()=>l(e=>!e),children:s(c?`fitImage`:`originalImageSize`)}),(0,K.jsx)(`button`,{type:`button`,"data-autofocus":!0,"aria-label":s(`close`),onClick:o,children:(0,K.jsx)(Lt,{})})]}),r?(0,K.jsx)(`section`,{className:`draft-image-preview-body`,"data-mode":c?`original`:`fit`,"aria-label":s(`imageViewMode`),tabIndex:c?0:void 0,children:(0,K.jsx)(PI,{sessionId:e,path:t,source:r,active:n},JSON.stringify([e,t,r.id]))}):(0,K.jsxs)(`div`,{className:`session-sources-list`,children:[!i?.loading&&!i?.error&&!i?.page?.sources.length&&(0,K.jsx)(`p`,{children:s(`sourcesEmpty`)}),i?.page?.sources.map(n=>(0,K.jsx)(FI,{source:n,sessionId:e,path:t,onOpen:()=>a(n),thumbnail:!1},n.id)),i?.error&&(0,K.jsxs)(`p`,{role:`alert`,children:[s(`sourcesFailed`),` `,(0,K.jsx)(`button`,{type:`button`,onClick:i.refresh,children:s(`gitReviewRetry`)})]}),i?.loading&&(0,K.jsx)(`p`,{role:`status`,children:s(`readingFile`)}),i?.page?.nextOffset!==void 0&&(0,K.jsx)(`button`,{className:`sources-load-more`,type:`button`,disabled:i.loading,onClick:()=>void i.loadMore(),children:s(`sourcesLoadMore`)}),i?.page?.truncated&&(0,K.jsx)(`p`,{children:s(`sourcesPartial`)})]})]})})}function LI({sessionId:e,workspace:t,agents:n,omitted:r,review:i,onSubagents:a,onReview:o,sessionPath:s,revision:c,onAddSources:l,reviewLoading:u=!1,reviewError:d}){let{t:f}=cr(),[p,m]=(0,_.useState)(!1),h=(0,_.useRef)(null),[g,v]=(0,_.useState)(!1),[y,b]=(0,_.useState)(null),x=NI(e,s??``,!!(s&&(p||g)),c),S=(0,_.useContext)(fk),C=i?.ok?i.snapshot.totals:void 0,w=e=>{e?.kind===`file`&&e.reference?(v(!1),A(()=>S?.open(e.reference,void 0,h.current??void 0))):A(()=>{b(e),v(!0)})},T=n.filter(e=>e.state===`running`),E=n.filter(e=>e.state===`done`),D=n.length-T.length-E.length,O=[...T,...n.filter(e=>e.state!==`running`)].slice(0,4),k=[T.length?f(`subagentSummaryRunning`,{count:T.length}):``,E.length?f(`subagentSummaryDone`,{count:E.length}):``,D?f(`subagentSummaryOther`,{count:D}):``].filter(Boolean).join(` · `)||f(`subagentNoneYet`),A=e=>{m(!1),h.current?.focus(),e()};return(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(gd,{isOpen:p,onOpenChange:m,placement:`below`,alignment:`end`,width:`min(340px, calc(100vw - 24px))`,label:f(`sessionOverview`),closeButtonLabel:f(`close`),isModal:!1,content:(0,K.jsxs)(`div`,{className:`session-overview`,children:[(0,K.jsx)(`p`,{className:`session-overview-title`,children:t}),(0,K.jsxs)(`button`,{type:`button`,className:`session-overview-row`,title:f(`sessionOverviewChanges`),onClick:()=>A(o),children:[(0,K.jsx)(ye,{"aria-hidden":`true`}),(0,K.jsx)(`span`,{children:f(`overviewChanges`)}),C&&!d?(0,K.jsxs)(`span`,{className:`session-overview-diff`,title:f(C.complete?`overviewLineTotals`:`overviewPartialTotals`),children:[(0,K.jsxs)(`span`,{className:`review-additions`,children:[`+`,C.additions.toLocaleString()]}),(0,K.jsxs)(`span`,{className:`review-deletions`,children:[`−`,C.deletions.toLocaleString()]}),!C.complete&&(0,K.jsx)(`span`,{className:`session-overview-note`,children:f(`gitReviewPartialLabel`)})]}):(0,K.jsx)(`span`,{className:`session-overview-note`,children:f(u?`overviewCounting`:i?.ok?`overviewCountsUnknown`:`overviewReviewUnavailable`)})]}),(0,K.jsxs)(`div`,{className:`session-overview-section`,children:[(0,K.jsx)(`p`,{children:f(`subagentDetails`)}),(0,K.jsxs)(`button`,{type:`button`,className:`session-overview-row session-overview-agents`,onClick:()=>A(a),"aria-label":`${f(`subagentDetails`)}: ${k}`,children:[O.length>0&&(0,K.jsx)(`span`,{className:`subagent-avatar-stack`,children:O.map(t=>(0,K.jsx)(MI,{identity:`${e}:${t.id}`},t.id))}),(0,K.jsx)(`span`,{className:`session-overview-agent-counts`,children:k.split(` · `).map(e=>(0,K.jsx)(`span`,{children:e},e))}),(0,K.jsx)(z,{"aria-hidden":`true`})]}),r>0&&(0,K.jsx)(`small`,{children:f(`subagentListTruncated`,{count:r})})]}),s&&(0,K.jsxs)(`div`,{className:`session-overview-section`,children:[(0,K.jsxs)(`div`,{className:`session-overview-section-heading`,children:[(0,K.jsx)(`span`,{children:f(`sessionSources`)}),l&&(0,K.jsx)(`button`,{type:`button`,"aria-label":f(`sourcesAdd`),title:f(`sourcesAdd`),onClick:()=>A(l),children:(0,K.jsx)(lt,{})})]}),x.page?.sources.slice(0,3).map(t=>(0,K.jsx)(FI,{source:t,sessionId:e,path:s,onOpen:()=>w(t)},t.id)),x.error?(0,K.jsxs)(`p`,{role:`alert`,children:[f(`sourcesFailed`),` `,(0,K.jsx)(`button`,{type:`button`,onClick:x.refresh,children:f(`gitReviewRetry`)})]}):!x.page?.sources.length&&(0,K.jsx)(`p`,{children:f(x.loading?`readingFile`:`sourcesEmpty`)}),!!(x.page&&(x.page.sources.length>3||x.page.nextOffset!==void 0))&&(0,K.jsxs)(`button`,{type:`button`,className:`session-overview-row sources-view-all`,onClick:()=>w(null),children:[(0,K.jsx)(Re,{}),(0,K.jsx)(`span`,{children:f(`sourcesViewAll`)}),(0,K.jsx)(z,{})]})]})]}),children:e=>(0,K.jsx)(`button`,{...e,ref:t=>{e.ref(t),h.current=t},type:`button`,className:`task-tools-trigger`,title:f(`sessionOverview`),"aria-label":f(`sessionOverview`),children:(0,K.jsxs)(`svg`,{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.8`,strokeLinecap:`round`,"aria-hidden":`true`,children:[(0,K.jsx)(`circle`,{cx:`5.5`,cy:`7`,r:`2.8`}),(0,K.jsx)(`circle`,{cx:`5.5`,cy:`17`,r:`2.8`}),(0,K.jsx)(`path`,{d:`M12 7h8M12 17h8`})]})})}),s&&(0,K.jsx)(II,{sessionId:e,path:s,open:g,source:y,data:x,onSelect:w,onClose:()=>{v(!1),b(null)}})]})}var RI=(0,_.createContext)(null);RI.displayName=`ListContext`;var zI={list:{kogj98:`x1ghz6dp`,kZCmMZ:`x1c1uobl`,kH6xsr:`x3ct3a4`,k1xSpc:`x78zum5`,kXwgrk:`xdt5ytf`,kOIVth:`x1lsbc85`,$$css:!0},withDividers:{kOIVth:`xxhr3t`,$$css:!0},withCounter:{kt6KFK:`xif0320`,$$css:!0}},BI={kt6KFK:`x1khind5`,$$css:!0},VI={counterStart:e=>[BI,{"--x-counterReset":`astryx-list ${e}`==null?void 0:`astryx-list ${e}`}]};function HI({children:e,density:t=`balanced`,hasDividers:n=!1,header:r,listStyle:i=`none`,start:a,xstyle:o,className:s,style:c,"data-testid":l,ref:u,...d}){let f=(0,_.useId)(),p=i===`decimal`,m=p?`ol`:`ul`,h=(0,_.useMemo)(()=>({density:t,hasDividers:n,listStyle:i}),[t,n,i]),g=(0,K.jsx)(m,{ref:u,...d,"data-testid":l,...r==null?null:{"aria-labelledby":f},...p&&a!=null&&a!==1?{start:a}:{},role:`list`,...oa(ba(`list`,{density:t,listStyle:i}),Sr(zI.list,n&&zI.withDividers,i!==`none`&&(a!=null&&a!==1?VI.counterStart(a-1):zI.withCounter),o),s,c),children:e});return r==null?(0,K.jsx)(RI,{value:h,children:g}):(0,K.jsx)(RI,{value:h,children:(0,K.jsxs)(`div`,{className:`x78zum5 xdt5ytf`,children:[(0,K.jsx)(`div`,{id:f,className:`x1p37lm5`,children:r}),g]})})}HI.displayName=`List`;var UI={withCounter:{kAmcRD:`xfrknyr`,$$css:!0},withDivider:{kt9PQ7:`x92x3c3`,kfdmCh:`x1q0q8m5`,kL6WhQ:`xw8gpjh`,$$css:!0}},WI={noRadius:{kaIpWk:`x2u8bby`,$$css:!0}};function GI({label:e,description:t,startContent:n,endContent:r,onClick:i,interactiveRef:a,href:o,target:s,rel:c,isDisabled:l=!1,isSelected:u=!1,xstyle:d,className:f,style:p,ref:m,...h}){let g=(0,_.use)(RI),v=g?.density??`balanced`,y=g?.hasDividers??!1,b=g?.listStyle??`none`;return(0,K.jsx)(qk,{as:`li`,ref:m,marker:b===`disc`?(0,K.jsx)(`span`,{className:`xoi2r2e x9f619 x78zum5 x6s0dn4 xl56j7k x2lah0s x12xnipv x1233pnv`,children:(0,K.jsx)(`span`,{className:`x1v4s8kt xols6we x16rqkct x19aspcf`})}):b===`circle`?(0,K.jsx)(`span`,{className:`xoi2r2e x9f619 x78zum5 x6s0dn4 xl56j7k x2lah0s x12xnipv x1233pnv`,children:(0,K.jsx)(`span`,{className:`x1v4s8kt xols6we x16rqkct xmkeg23 x1y0btm7 xqcx1ss xjbqb8w`})}):b===`decimal`?(0,K.jsx)(`span`,{className:`xoi2r2e x2lah0s x1tgivj0 xjm74w1 xw6l6zx x12xnipv xc2ndz5`}):null,startContent:n,label:e,description:t,endContent:r,onClick:i,interactiveRef:a,href:o,target:s,rel:c,isDisabled:l,isSelected:u,density:v,xstyle:[b!==`none`&&UI.withCounter,y&&UI.withDivider,y&&WI.noRadius,d],...oa(ba(`list-item`),{className:f,style:p}),...h})}GI.displayName=`ListItem`;function KI(e){let t=new Map;return e.map(e=>{let n=JSON.stringify(e),r=t.get(n)??0;return t.set(n,r+1),{item:e,key:`${n}:${r}`}})}function qI({name:e,args:t,output:n,state:r}){let{t:i}=cr();return(0,K.jsxs)(`details`,{className:`subagent-tool ${r}`,"data-status":r,children:[(0,K.jsxs)(`summary`,{children:[(0,K.jsx)(`code`,{children:e}),(0,K.jsx)(`span`,{className:`subagent-state ${r}`,children:i(`subagentTool_${r}`)})]}),t&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`strong`,{className:`subagent-tool-label`,children:i(`trajectoryArguments`)}),(0,K.jsx)(`pre`,{children:t})]}),n&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`strong`,{className:`subagent-tool-label`,children:i(`trajectoryOutput`)}),(0,K.jsx)(`pre`,{children:n})]})]})}function JI({sessionId:e,id:t,kind:n=`subagents`,activity:r,client:i,saved:a,liveAvailable:o,fullView:s,readOnlyNote:c=!0,active:l=!0,refreshRevision:u=0,onDetail:d}){let{t:f}=cr(),[p,m]=(0,_.useState)(null),[h,g]=(0,_.useState)(null),[v,y]=(0,_.useState)(!0),[b,x]=(0,_.useState)(0),[S,C]=(0,_.useState)(null),w=(0,_.useRef)(null),T=(0,_.useRef)(!0),E=(0,_.useRef)(d);E.current=d,(0,_.useEffect)(()=>{if(!l)return;if(!o){y(!1),g(f(`subagentUnavailable`));return}let a=new AbortController,s,c=!1,u=async()=>{if(c||a.signal.aborted||document.visibilityState===`hidden`)return;c=!0;let o=r?.status===`running`;try{let r=await(n===`workflows`?i.workflowAgentDetail(e,t,a.signal):i.subagentDetail(e,t,a.signal));if(a.signal.aborted)return;if(r.sessionId!==e||r.detail.kind!==n||r.detail.id!==t)throw m(null),o=!1,Error(f(`inspectionChanged`));o=r.detail.status===`running`,m(r.detail),r.detail.kind===`subagents`&&E.current?.(r.detail),g(null),C(new Date().toLocaleTimeString())}catch(e){if(a.signal.aborted)return;g(e instanceof tf&&[404,501].includes(e.status)?f(`subagentUnavailable`):e instanceof Error?e.message:f(`inspectionUnavailable`))}finally{c=!1,a.signal.aborted||(y(!1),o&&(s=setTimeout(()=>void u(),1e3)))}},d=()=>{document.visibilityState===`visible`&&(clearTimeout(s),u())};return document.addEventListener(`visibilitychange`,d),u(),()=>{a.abort(),clearTimeout(s),document.removeEventListener(`visibilitychange`,d)}},[l,i,e,t,n,r?.status,b,u,o,f]),(0,_.useLayoutEffect)(()=>{let e=w.current;e&&T.current&&(e.scrollTop=e.scrollHeight)},[p]);let D=new Map(p?.transcript.flatMap(e=>e.kind===`toolResult`?[[e.toolId,e]]:[])),O=new Set(p?.transcript.flatMap(e=>e.kind===`assistant`?e.parts.flatMap(e=>e.type===`toolCall`?[e.toolId]:[]):[])),k=p?.outcome===`interrupted`?`interrupted`:p?.status,A=p?.transcript.some(e=>e.kind===`assistant`&&e.parts.flatMap(e=>e.type===`text`?[e.text]:[]).join(` `).trim()===p.finalText.trim()),j=s?`h2`:`h3`;return(0,K.jsxs)(`section`,{className:`subagent-detail`,"aria-label":f(`subagentDetails`),hidden:!l,children:[(0,K.jsxs)(`header`,{className:`subagent-detail-heading`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`span`,{className:`subagent-state ${k??`unknown`}`,children:k?f(`subagentState_${k}`):a?.state?`${f(`subagentRecordedState`)}: ${f(`subagentState_${a.state}`)}`:f(`unknownState`)}),p&&(0,K.jsx)(`span`,{className:`subagent-duration`,children:nj(p.createdAt,p.settledAt)})]}),(0,K.jsx)(`button`,{type:`button`,className:`icon-button`,"aria-label":f(`refreshStatus`),disabled:v||!o,onClick:()=>{y(!0),x(e=>e+1)},children:(0,K.jsx)(dt,{})})]}),v&&!p&&(0,K.jsx)(`p`,{role:`status`,children:f(`inspectionLoading`)}),h&&(0,K.jsxs)(`div`,{className:`inspection-warning`,role:`alert`,children:[(0,K.jsx)(`p`,{children:f(p?`subagentStale`:`subagentUnavailable`)}),h!==f(`subagentUnavailable`)&&(0,K.jsx)(`small`,{children:h})]}),p&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsxs)(`div`,{className:`subagent-metadata`,children:[(0,K.jsx)(`code`,{children:p.id}),p.model&&(0,K.jsx)(`span`,{children:p.model}),(0,K.jsx)(`span`,{title:p.cwd,children:p.cwd})]}),(0,K.jsxs)(`details`,{className:`subagent-task`,children:[(0,K.jsx)(`summary`,{children:f(`subagentTask`)}),(0,K.jsx)(`pre`,{children:p.prompt})]}),p.errorText&&(0,K.jsx)(`p`,{className:`inspection-warning`,role:`alert`,children:p.errorText}),p.truncated&&(0,K.jsx)(`p`,{className:`inspection-note`,children:f(`subagentTruncated`,{count:p.omittedEntries})}),p.kind===`workflows`&&p.transcriptUnavailable&&(0,K.jsx)(`p`,{className:`inspection-note`,children:f(`subagentTranscriptUnavailable`)}),(0,K.jsxs)(`div`,{className:`subagent-transcript`,ref:w,role:`log`,"aria-label":f(`subagentTranscript`),onScroll:e=>{let t=e.currentTarget;T.current=t.scrollHeight-t.clientHeight-t.scrollTop<48},children:[KI(p.transcript).map(({item:e,key:t})=>(0,K.jsx)(`div`,{className:`subagent-message ${e.kind}`,"data-role":e.kind,children:e.kind===`user`?(0,K.jsx)(`p`,{className:`subagent-user-message`,children:e.text}):e.kind===`toolResult`?O.has(e.toolId)?null:(0,K.jsx)(qI,{name:e.name,output:e.outputPreview,state:e.isError?`error`:`done`}):KI(e.parts).map(({item:e,key:t})=>e.type===`text`?(0,K.jsx)(Sk,{children:e.text},t):e.type===`thinking`?(0,K.jsxs)(`details`,{className:`subagent-thinking done`,"data-status":`done`,children:[(0,K.jsx)(`summary`,{children:f(`thinkingDone`)}),(0,K.jsx)(`pre`,{children:e.redacted?f(`subagentThinkingRedacted`):e.text})]},t):(0,K.jsx)(qI,{name:e.name,args:e.argsPreview,output:D.get(e.toolId)?.outputPreview??p.liveTools.find(t=>t.toolId===e.toolId)?.outputPreview,state:D.has(e.toolId)?D.get(e.toolId).isError?`error`:`done`:p.liveTools.some(t=>t.toolId===e.toolId&&!t.done)?`running`:`unknown`},e.toolId))},t)),p.liveAssistant?.thinking&&(0,K.jsxs)(`details`,{className:`subagent-thinking running`,"data-status":`running`,children:[(0,K.jsx)(`summary`,{children:f(`thinkingActive`)}),(0,K.jsx)(`pre`,{children:p.liveAssistant.thinking})]}),p.liveAssistant?.text&&(0,K.jsx)(`div`,{className:`subagent-message assistant live`,"data-role":`assistant`,children:(0,K.jsx)(Sk,{children:p.liveAssistant.text})}),p.liveTools.filter(e=>!O.has(e.toolId)).map(e=>(0,K.jsx)(qI,{name:e.name,args:e.argsPreview,output:e.outputPreview,state:e.done?e.isError?`error`:`done`:`running`},e.toolId)),p.finalText&&!A&&(0,K.jsxs)(`section`,{className:`subagent-final`,children:[(0,K.jsx)(j,{children:f(`subagentResult`)}),(0,K.jsx)(Sk,{children:p.finalText})]}),p.status===`running`&&(0,K.jsx)(`p`,{className:`subagent-live`,role:`status`,children:f(`subagentLive`)}),!p.transcript.length&&!p.liveAssistant?.text&&!(p.kind===`workflows`&&p.transcriptUnavailable)&&!p.finalText&&(0,K.jsx)(`p`,{children:f(`subagentNoMessages`)})]}),(c||S)&&(0,K.jsxs)(`p`,{className:`subagent-footnote`,children:[c&&f(`subagentReadOnly`),c&&S&&` · `,S]})]}),!p&&!v&&a&&(0,K.jsxs)(`section`,{className:`subagent-transcript`,"aria-label":f(`subagentSaved`),children:[(0,K.jsx)(j,{children:f(`subagentSaved`)}),(0,K.jsx)(`p`,{className:`inspection-note`,children:f(`subagentSavedHint`)}),a.state&&(0,K.jsxs)(`p`,{children:[f(`subagentRecordedState`),`: `,f(`subagentState_${a.state}`)]}),a.result&&(0,K.jsx)(Sk,{children:a.result}),a.receipt&&(0,K.jsxs)(`details`,{className:`subagent-task`,children:[(0,K.jsx)(`summary`,{children:f(`subagentSpawnReceipt`)}),(0,K.jsx)(`pre`,{children:a.receipt})]})]})]})}function YI({sessionId:e,initialId:t,initialKind:n=`subagents`,activity:r,workflows:i,observed:a=!0,records:o=[],liveAvailable:s=!0,onClose:c}){let{t:l,i18n:u}=cr(),[d,f]=(0,_.useState)([]),p=(0,_.useRef)(null),m=(0,_.useRef)(0),[h,g]=(0,_.useState)(t?{id:t,kind:n}:null),[v,y]=(0,_.useState)(h),b=h?.id;(0,_.useLayoutEffect)(()=>{!b&&p.current&&(p.current.scrollTop=m.current)},[b]);let x=(e,t=`subagents`)=>{let n=e?{id:e,kind:t}:null;n&&y(n),g(n)},[S,C]=(0,_.useState)(()=>window.matchMedia?.(`(max-width: 1100px)`).matches??!1);(0,_.useEffect)(()=>{let e=window.matchMedia?.(`(max-width: 1100px)`);if(!e)return;let t=()=>C(e.matches);return t(),e.addEventListener(`change`,t),()=>e.removeEventListener(`change`,t)},[]);let w=(0,_.useMemo)(()=>new rf,[]),E=s?r?.items??[]:[],D=s?i?.items??[]:[],O=oj(E,o,D,a),k=(r?.omitted??0)+D.reduce((e,t)=>e+(t.children?.omitted??0),0),A=O.find(e=>e.id===b&&e.kind===h?.kind),j=h?.kind===`subagents`?o.find(e=>e.id===b):void 0,N=(0,_.useRef)(null),P=(0,_.useRef)(document.activeElement);(0,_.useEffect)(()=>{N.current?.focus()},[h]),(0,_.useEffect)(()=>()=>{queueMicrotask(()=>{!document.querySelector(`.subagent-panel`)&&P.current instanceof HTMLElement&&P.current.isConnected&&P.current.focus()})},[]);let F=[{key:`active`,label:`subagentActiveGroup`,items:O.filter(e=>e.state===`running`),empty:`subagentNoneRunning`},{key:`done`,label:`subagentFinishedGroup`,items:O.filter(e=>e.state===`done`),empty:`subagentNoneFinished`},{key:`attention`,label:`subagentOtherGroup`,items:O.filter(e=>e.state===`error`||e.state===`interrupted`)},{key:`saved`,label:`subagentUnconfirmedGroup`,items:O.filter(e=>!e.state)}],I=e=>{let t=Math.max(0,Date.now()-e),n=t<36e5?`minute`:t<864e5?`hour`:`day`,r=n===`minute`?6e4:n===`hour`?36e5:864e5;return new Intl.RelativeTimeFormat(u.language,{numeric:`auto`}).format(-Math.floor(t/r),n)},L=S?`main`:`aside`,R=S?`h1`:`h2`,z=S?`h2`:`h3`;return(0,K.jsxs)(L,{className:`subagent-panel`,"aria-label":l(`subagentDetails`),onKeyDown:e=>{e.key===`Escape`&&!e.nativeEvent.isComposing&&!e.defaultPrevented&&(e.preventDefault(),b?x(null):c())},children:[(0,K.jsxs)(`header`,{className:`subagent-panel-heading`,children:[(0,K.jsxs)(`div`,{className:`subagent-breadcrumb`,children:[b&&(0,K.jsx)(`button`,{ref:N,type:`button`,className:`icon-button`,"aria-label":l(`backToSubagents`),onClick:()=>x(null),children:(0,K.jsx)(T,{})}),b?(0,K.jsx)(MI,{identity:`${e}:${b}`}):(0,K.jsx)(M,{"aria-hidden":`true`}),(0,K.jsx)(R,{children:b?A?.title||j?.title||b:l(`subagentDetails`)})]}),(0,K.jsx)(`button`,{ref:b?void 0:N,type:`button`,className:`icon-button`,"aria-label":l(`close`),onClick:c,children:(0,K.jsx)(Lt,{})})]}),v&&(0,K.jsx)(JI,{sessionId:e,id:v.id,kind:v.kind,activity:v.kind===`subagents`?E.find(e=>e.id===v.id):D.flatMap(e=>e.children?.items??[]).find(e=>e.id===v.id),client:w,saved:v.kind===`subagents`?o.find(e=>e.id===v.id):void 0,liveAvailable:s,fullView:S,active:!!b},`${e}:${v.kind}:${v.id}`),!b&&(0,K.jsxs)(`nav`,{className:`subagent-list`,"aria-label":l(`subagentTasks`),ref:p,onScroll:e=>{m.current=e.currentTarget.scrollTop},children:[F.map(t=>{if(!t.items.length&&!t.empty)return null;let n=d.includes(t.key)?t.items:t.items.slice(0,t.key===`active`?4:10);return(0,K.jsxs)(`section`,{className:`subagent-list-group`,children:[(0,K.jsxs)(z,{children:[l(t.label),(0,K.jsx)(`span`,{"aria-hidden":`true`,children:`·`}),(0,K.jsx)(`span`,{children:t.items.length})]}),!t.items.length&&t.empty&&(0,K.jsx)(`p`,{children:l(t.empty)}),(0,K.jsx)(HI,{density:`compact`,children:n.map(t=>(0,K.jsx)(GI,{className:`subagent-task-row`,onClick:()=>x(t.id,t.kind),label:(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`span`,{className:`subagent-task-title`,title:t.title||t.id,children:t.title||t.id}),(0,K.jsx)(`span`,{className:`sr-only`,children:` · ${l(`subagentState_${t.state??`unknown`}`)}`})]}),description:t.saved?l(`subagentSaved`):t.state===`error`||t.state===`interrupted`?l(`subagentState_${t.state}`):void 0,startContent:(0,K.jsx)(MI,{identity:`${e}:${t.id}`}),endContent:(0,K.jsx)(`span`,{className:`subagent-task-end`,children:t.state===`running`?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(He,{className:`subagent-running-icon`,"aria-hidden":`true`}),(0,K.jsx)(`span`,{className:`sr-only`,children:l(`subagentState_running`)})]}):t.timestamp?(0,K.jsx)(`time`,{dateTime:new Date(t.timestamp).toISOString(),title:new Date(t.timestamp).toLocaleString(u.language),children:I(t.timestamp)}):null})},`${t.kind}:${t.id}`))}),n.lengthf(e=>[...e,t.key]),children:l(`subagentShowMore`,{count:t.items.length-n.length})})]},t.key)}),k>0&&(0,K.jsx)(`p`,{children:l(`subagentListTruncated`,{count:k})}),!!i?.omitted&&(0,K.jsx)(`p`,{children:l(`subagentWorkflowsTruncated`,{count:i?.omitted})})]})]})}var XI=`openpi:subagent-panel:v1`;function ZI(){try{let e=JSON.parse(sessionStorage.getItem(XI)??`null`);if(!e||typeof e!=`object`)return null;let{sessionId:t,sessionPath:n}=e;return typeof t!=`string`||!t||t.length>160||typeof n!=`string`||!n||n.length>4096?null:{sessionId:t,sessionPath:n,navigation:0}}catch{return null}}function QI(e){try{e?sessionStorage.setItem(XI,JSON.stringify({sessionId:e.sessionId,sessionPath:e.sessionPath})):sessionStorage.removeItem(XI)}catch{}}function $I(e){switch(e.toLowerCase()){case`read`:return{action:`read`,Icon:j};case`write`:return{action:`write`,Icon:at};case`edit`:return{action:`edit`,Icon:at};case`bash`:return{action:`command`,Icon:Tt};case`grep`:case`rg`:case`find`:case`fd`:case`glob`:case`tool_search`:return{action:`search`,Icon:ht};case`ls`:return{action:`list`,Icon:De};case`webfetch`:case`websearch`:case`web_fetch`:case`web_search`:return{action:`web`,Icon:je};case`plan_ready`:return{action:`plan`,Icon:U};case`tasks_add`:case`tasks_update`:case`tasks_list`:return{action:`task`,Icon:ze};case`get_goal`:case`create_goal`:case`update_goal`:return{action:`goal`,Icon:Ot};case`git_show`:case`git_diff`:case`git_log`:return{action:`git`,Icon:Ae};default:return e.startsWith(`bg_`)?{action:`command`,Icon:Tt}:e.startsWith(`subagent`)?{action:`agent`,Icon:M}:e.startsWith(`workflow`)?{action:`workflow`,Icon:Ft}:{action:`call`,Icon:It}}}function eL(e,t,n){let{action:r}=$I(t);return n===`returned`?e(`toolActionDone_${r}`):e(`toolActivity_${[`running`,`failed`,`cancelled`,`timed_out`].includes(n)?n:`unknown`}`,{action:e(`toolAction_${r}`)})}function tL(e){let{action:t}=$I(e);return t===`command`?`run`:t===`workflow`?`flow`:t===`call`?e:t}function nL(e,t){let{action:n}=$I(e),r=n===`search`?t.pattern??t.query??t.path:n===`web`?t.url??t.query:t.path??t.command??t.url??t.query??t.id??t.runId;return typeof r==`string`?r:``}function rL(e){for(let t=e.length-1;t>=0;t--){let n=e[t];if(n&&(n.kind!==`event`||n.message||n.input!==void 0||n.result))return n}return e.at(-1)}function iL(e){let t=[];for(let n of e){(n.kind===`user`||!t.length)&&t.push({key:n.key,...n.kind===`user`?{prompt:n}:{},runs:[]});let e=t.at(-1),r=e.runs.at(-1);n.kind===`event`&&r?.[0]?.kind===`event`?r.push(n):e.runs.push([n])}return t}function aL(e){let t=new Map(e.map((e,t)=>[e.id,t])),n=new Map,r=new Map,i=new Map;for(let a of e){let e=`message`in a?a.message:void 0;for(let t of e?.parts??[])t.type===`toolCall`&&t.id&&r.set(t.id,(r.get(t.id)??0)+1);if(e?.role===`toolResult`&&e.toolCallId){let r=i.get(e.toolCallId)??[];r.push(e),n.set(e,t.get(a.id)??-1),i.set(e.toolCallId,r)}}let a=new Set,o=[];for(let s of e){let e=`message`in s?s.message:void 0;if(!e){o.push({key:s.id,kind:`event`,title:s.type,timestamp:s.timestamp});continue}if(e.role!==`toolResult`){(e.role!==`assistant`||e.content||!e.parts?.length||e.parts?.some(e=>e.type!==`toolCall`))&&o.push({key:s.id,kind:e.role===`user`?`user`:e.role===`assistant`?`assistant`:`event`,title:e.customType||e.role||s.type,timestamp:s.timestamp,message:e});for(let[c,l]of(e.parts??[]).entries()){if(l.type!==`toolCall`)continue;let u=l.id?i.get(l.id):void 0,d=l.id&&r.get(l.id)===1&&u?.length===1&&u[0]?.toolName===l.name&&!l.id.includes(`[truncated]`)&&(n.get(u[0])??-1)>(t.get(s.id)??-1)?u[0]:void 0;d&&a.add(d),o.push({key:`${s.id}:call:${c}`,kind:`call`,title:l.name,timestamp:s.timestamp,callId:l.id,input:l.arguments,message:e,result:d,outcome:d?.isError===!0?`error`:d?.isError===!1?`returned`:`unknown`})}}}let s=new Map(o.map(e=>[e.key,t.get(e.key)??-1]));for(let n of e){let e=`message`in n?n.message:void 0;e?.role===`toolResult`&&!a.has(e)&&(o.push({key:n.id,kind:`result`,title:e.toolName||`toolResult`,timestamp:n.timestamp,callId:e.toolCallId,result:e,outcome:e.isError===!0?`error`:e.isError===!1?`returned`:`unknown`}),s.set(n.id,t.get(n.id)??0));for(let[r,i]of(e?.parts??[]).entries())i.type===`toolCall`&&s.set(`${n.id}:call:${r}`,t.get(n.id)??0)}return o.sort((e,t)=>(s.get(e.key)??0)-(s.get(t.key)??0)),o}var oL=[];function sL(e){return e.kind===`call`||e.kind===`result`?``:(e.message?.parts??[]).filter(e=>e.type===`thinking`).map(e=>e.text).join(` diff --git a/web/ui/src/features/sessions/SessionSidebar.tsx b/web/ui/src/features/sessions/SessionSidebar.tsx index 14e277340..3a432064a 100644 --- a/web/ui/src/features/sessions/SessionSidebar.tsx +++ b/web/ui/src/features/sessions/SessionSidebar.tsx @@ -265,7 +265,10 @@ export function SessionSidebar(props: SessionSidebarProps) { const [pinSaving, setPinSaving] = useState(false); const pinInFlight = useRef(false); const draggedPin = useRef(null); - const suppressDragClickUntil = useRef(0); + // One trailing click after a drag. Cleared by that click or by a later + // pointerdown. A wall-clock window drops the click when the post-drop render + // is slower than the window. + const suppressDragClick = useRef(false); const [draggingSidebar, setDraggingSidebar] = useState(false); const draggedChat = useRef<{ path: string; @@ -927,7 +930,7 @@ export function SessionSidebar(props: SessionSidebarProps) { const endDrag = useCallback(() => { if (draggedPin.current || draggedChat.current) - suppressDragClickUntil.current = Date.now() + 250; + suppressDragClick.current = true; draggedPin.current = null; draggedChat.current = null; setDraggingSidebar(false); @@ -1243,7 +1246,7 @@ export function SessionSidebar(props: SessionSidebarProps) { return; } setDraggingSidebar(true); - suppressDragClickUntil.current = Number.POSITIVE_INFINITY; + suppressDragClick.current = true; event.dataTransfer.effectAllowed = "move"; event.dataTransfer.setData("text/plain", session.id); }} @@ -1630,7 +1633,7 @@ export function SessionSidebar(props: SessionSidebarProps) { if (mounted.current && draggedPin.current === target) setDraggingSidebar(true); }); - suppressDragClickUntil.current = Number.POSITIVE_INFINITY; + suppressDragClick.current = true; event.dataTransfer.effectAllowed = "move"; event.dataTransfer.setData("text/plain", group.path); }} @@ -1756,12 +1759,13 @@ export function SessionSidebar(props: SessionSidebarProps) { onPointerDownCapture={() => { // A new gesture is intentional; only suppress the drag's trailing click. if (!draggedPin.current && !draggedChat.current) - suppressDragClickUntil.current = 0; + suppressDragClick.current = false; }} onClickCapture={(event) => { - if (event.detail !== 0 && Date.now() < suppressDragClickUntil.current) { + if (event.detail !== 0 && suppressDragClick.current) { event.preventDefault(); event.stopPropagation(); + suppressDragClick.current = false; } }} onKeyDown={(event) => {