@openchambery/web 1.18.4-beta.12 → 1.18.4-beta.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/assets/{AssistantView-iWaJ-b44.js → AssistantView-CY4rsyXp.js} +1 -1
- package/dist/assets/{ChatContainer-WUB1qcA1.js → ChatContainer-C5G5Fr2b.js} +4 -4
- package/dist/assets/{DiagramView-DFoSz9Yk.js → DiagramView-CzcoibbD.js} +1 -1
- package/dist/assets/{MarkdownRendererImpl-BYU1488z.js → MarkdownRendererImpl-D2QG5Cyz.js} +1 -1
- package/dist/assets/{MobileDetailNavigation-zVudMYv1.js → MobileDetailNavigation-DsQJ4trf.js} +1 -1
- package/dist/assets/{MobileShareBridge-DClEOdML.js → MobileShareBridge-Bd1-7DML.js} +1 -1
- package/dist/assets/{MobileSurface-sspHXVya.js → MobileSurface-CLyIIwQa.js} +1 -1
- package/dist/assets/{MultiRunWindow-Dm0JbZXh.js → MultiRunWindow-BuyE-Pqt.js} +1 -1
- package/dist/assets/{SettingsView-BCukgMvV.js → SettingsView-CLHUtoGC.js} +11 -11
- package/dist/assets/{SettingsWindow-YPlpHLHC.js → SettingsWindow-jzHzqlrP.js} +1 -1
- package/dist/assets/{TerminalView-D3QjWyII.js → TerminalView-Da9C2w1w.js} +1 -1
- package/dist/assets/{ToolOutputDialog-Cii40jmy.js → ToolOutputDialog-CKHIer6h.js} +1 -1
- package/dist/assets/{appThemeRegistry-CZWWy6CN.js → appThemeRegistry-C7KndtrT.js} +2 -2
- package/dist/assets/{context-menu-PFqbh51b.js → context-menu-BNOtF78w.js} +1 -1
- package/dist/assets/{gitApi-DKlYTEVh.js → gitApi-BAEyohtw.js} +1 -1
- package/dist/assets/{insertionBoundaries-3ou0M-Ug.js → insertionBoundaries-DEVtR-jV.js} +1 -1
- package/dist/assets/{main-CfASwh_M.js → main-Bk1Xkd1S.js} +2 -2
- package/dist/assets/{main-D4FMRffg.js → main-BpPkJxmD.js} +4 -4
- package/dist/assets/{miniChat-CjfMsr6A.js → miniChat-toYPrHwe.js} +2 -2
- package/dist/assets/{mobile-BqSW5dgD.js → mobile-Cbb8zwcX.js} +2 -2
- package/dist/assets/{multirun-CbHBesH1.js → multirun-Yeg_Lc4g.js} +1 -1
- package/dist/assets/{projectMeta-QijljaRK.js → projectMeta-fvbfTReY.js} +1 -1
- package/dist/assets/{radio-OeXamOHM.js → radio-CN_9l3le.js} +1 -1
- package/dist/assets/{renderElectronMiniChatApp-BcYxsfK0.js → renderElectronMiniChatApp-ETMoC_Rd.js} +2 -2
- package/dist/assets/{renderMobileApp-DU7Zs2VF.js → renderMobileApp-BSPouSPr.js} +4 -4
- package/dist/assets/{runtimeConfig-CEH_w4Br.js → runtimeConfig-VyMtYAl_.js} +1 -1
- package/dist/assets/{runtimeEndpointReset-DG0KSwCn.js → runtimeEndpointReset-DYSOSjpp.js} +1 -1
- package/dist/assets/{useAppFontEffects-D2xjUZsx.js → useAppFontEffects-DFXMOIvM.js} +2 -2
- package/dist/assets/{useDesktopWindowControlsLayout-DWw1WjRh.js → useDesktopWindowControlsLayout-CA8kRyzR.js} +1 -1
- package/dist/assets/{useEffectiveDirectory-JorUJ6J8.js → useEffectiveDirectory-Fl_r2Mvz.js} +1 -1
- package/dist/assets/{useMobileNavigationStore-BWUS7XEq.js → useMobileNavigationStore-DyfmQCpj.js} +1 -1
- package/dist/assets/useSessionAutoCleanup-DyqGjW0i.js +1 -0
- package/dist/assets/{useWorkerHighlightedLines-D9wuF7G6.js → useWorkerHighlightedLines-C-c4vn3t.js} +1 -1
- package/dist/index.html +2 -2
- package/dist/mini-chat.html +2 -2
- package/dist/mobile.html +2 -2
- package/package.json +1 -1
- package/server/lib/config-sync/config-sync.test.js +52 -0
- package/server/lib/config-sync/scripts.js +10 -2
- package/server/lib/session-assist/DOCUMENTATION.md +4 -2
- package/server/lib/session-assist/runtime.js +67 -30
- package/server/lib/session-assist/runtime.test.js +114 -0
- package/dist/assets/useSessionAutoCleanup-BLTcsmLE.js +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{o as e}from"./rolldown-runtime-C0FnF6B9.js";import{j as t,t as n}from"./useUIStore-NfqK-HA7.js";import{Kt as r,kn as i,qt as a,u as o}from"./persistence-vZ7H8WKh.js";import{h as s}from"./desktopHosts-Cr3LE55y.js";import{i as c,n as l,r as u}from"./desktopRelayRestore-VfMK9fdk.js";import{nt as d,rt as f}from"./vendor-base-ui-CnHfUmDN.js";import{Nt as p}from"./platform-CTaznShj.js";import{n as m}from"./vendor-react-DLPElpoQ.js";import{n as h}from"./vendor-tanstack-query-core-BWz0ose6.js";import{i as g,r as _}from"./vendor-tanstack-react-query-D7pys_c9.js";import{n as v,t as y}from"./clipboard-BfgFef1i.js";import{i as b,t as ee}from"./store-Z1MxUaP4.js";import{Sr as te,gr as ne,l as x,ua as re,ur as ie,yr as S}from"./useMobileNavigationStore-DyfmQCpj.js";import{t as C}from"./utils-C2P0wcWO.js";import{n as w}from"./Icon-D-X70irR.js";import{t as ae}from"./button-CwLFtUNT.js";import{i as oe,n as se,r as ce,t as le}from"./vendor-simplewebauthn-browser-Dwhcdg_5.js";import{n as ue,r as de}from"./radio-CN_9l3le.js";var T=m(),E=[`desktopHostSwitch`],D=class extends Error{result;host;constructor(e,t){super(e.reason),this.name=`DesktopHostSwitchError`,this.result=e,this.host=t}},fe=(e,t)=>ee(b.getState().dictionary,e,t),pe=async e=>{let{host:n}=e;if(n.id===`local`){let r=(e.localApiOrigin||``).trim();if(!r)throw new D({ok:!1,status:{status:`unreachable`,latencyMs:0},reason:`unreachable`},n);return t({apiBaseUrl:r,clientToken:e.localClientToken||null,runtimeKey:u(n)}),{ok:!0,via:`direct`,status:{status:`ok`,latencyMs:0}}}let r=await c(n,{cachedProbe:e.cachedProbe});if(!r.ok)throw new D(r,n);return r},O=null,me=()=>O||(O=new h(o,{mutationKey:E,mutationFn:pe,onError:(e,t)=>{e instanceof D&&e.result.reason!==`unsupported`&&te.error(fe(`desktopHostSwitcher.toast.instanceUnreachable`,{host:s(t.host.label)}))}}),O.subscribe(()=>void 0),O),he=async e=>{if(l(e.host))return{ok:!0,via:`direct`,status:e.cachedProbe?.status===`ok`?e.cachedProbe:{status:`ok`,latencyMs:0}};if(o.isMutating({mutationKey:E})>0)return{ok:!1,status:{status:`unreachable`,latencyMs:0},reason:`unsupported`};try{return await me().mutate(e)}catch(e){if(e instanceof D)return e.result;throw e}},ge=()=>{let e=(0,T.c)(1),t;return e[0]===Symbol.for(`react.memo_cache_sentinel`)?(t={mutationKey:E},e[0]=t):t=e[0],_(t)>0},_e=()=>{let e=(0,T.c)(1),t;return e[0]===Symbol.for(`react.memo_cache_sentinel`)?(t={filters:{mutationKey:E,status:`pending`},select:ve},e[0]=t):t=e[0],g(t)[0]?.host.id??null};function ve(e){return e.state.variables}var k=e=>typeof e==`object`&&!!e,A=(e,t)=>{let n=e[t];return typeof n==`string`?n:null},j=(e,t)=>{let n=e[t];return typeof n==`number`&&Number.isFinite(n)?n:null},M=(e,t)=>{let n=e[t];return typeof n==`boolean`?n:null},N=e=>Array.isArray(e)?e.filter(e=>typeof e==`string`):[],P=()=>r()?(e,t)=>a(e,t):null,F=e=>{if(!k(e))return;let t=M(e,`enabled`)??!1,n=A(e,`store`)?.toLowerCase()===`settings`?`settings`:`never`,r=A(e,`value`);return{enabled:t,store:n,...r?{value:r}:{}}},ye=e=>e===`remote`||e===`dynamic`?e:`local`,be=e=>{if(!k(e))return null;let t=A(e,`id`);if(!t)return null;let n=M(e,`enabled`)??!0,r=ye(A(e,`type`)),i=A(e,`localHost`)||A(e,`local_host`)||void 0,a=j(e,`localPort`)??j(e,`local_port`)??void 0,o=A(e,`remoteHost`)||A(e,`remote_host`)||void 0,s=j(e,`remotePort`)??j(e,`remote_port`)??void 0;return{id:t,enabled:n,type:r,...i?{localHost:i}:{},...typeof a==`number`?{localPort:a}:{},...o?{remoteHost:o}:{},...typeof s==`number`?{remotePort:s}:{}}},xe=e=>{if(!k(e))return null;let t=A(e,`id`),n=A(e,`sshCommand`)||A(e,`ssh_command`);if(!t||!n)return null;let r=A(e,`nickname`),i=e.sshParsed,a=k(i)?{destination:A(i,`destination`)||``,args:N(i.args)}:void 0,o=k(e.remoteOpenchamber)?e.remoteOpenchamber:k(e.remote_openchamber)?e.remote_openchamber:{},s=k(e.localForward)?e.localForward:k(e.local_forward)?e.local_forward:{},c=k(e.auth)?e.auth:{},l=A(o,`mode`)?.toLowerCase()===`external`?`external`:`managed`,u=A(o,`installMethod`)||A(o,`install_method`),d=u===`npm`||u===`download_release`||u===`upload_bundle`?u:`bun`,f=A(s,`bindHost`)||A(s,`bind_host`)||`127.0.0.1`,p=f===`localhost`||f===`0.0.0.0`?f:`127.0.0.1`,m=(Array.isArray(e.portForwards)?e.portForwards:Array.isArray(e.port_forwards)?e.port_forwards:[]).map(e=>be(e)).filter(e=>!!e),h=j(o,`preferredPort`)??j(o,`preferred_port`),g=j(s,`preferredLocalPort`)??j(s,`preferred_local_port`),_=F(c.sshPassword||c.ssh_password),v=F(c.openchamberPassword||c.openchamber_password);return{id:t,...r?{nickname:r}:{},sshCommand:n,...a&&a.destination?{sshParsed:a}:{},connectionTimeoutSec:j(e,`connectionTimeoutSec`)??j(e,`connection_timeout_sec`)??60,remoteOpenchamber:{mode:l,keepRunning:M(o,`keepRunning`)??M(o,`keep_running`)??!0,relayHost:M(o,`relayHost`)??M(o,`relay_host`)??!0,...h?{preferredPort:h}:{},installMethod:d,uploadBundleOverSsh:M(o,`uploadBundleOverSsh`)??M(o,`upload_bundle_over_ssh`)??!1},localForward:{...g?{preferredLocalPort:g}:{},bindHost:p},auth:{..._?{sshPassword:_}:{},...v?{openchamberPassword:v}:{}},portForwards:m}},Se=e=>{switch(e){case`config_resolved`:case`auth_check`:case`master_connecting`:case`remote_probe`:case`installing`:case`updating`:case`server_detecting`:case`server_starting`:case`forwarding`:case`ready`:case`degraded`:case`error`:return e;default:return`idle`}},I=e=>{if(!k(e))return null;let t=A(e,`id`);return t?{id:t,phase:Se(A(e,`phase`)),...A(e,`detail`)?{detail:A(e,`detail`)||void 0}:{},...A(e,`localUrl`)||A(e,`local_url`)?{localUrl:A(e,`localUrl`)||A(e,`local_url`)||void 0}:{},...typeof(j(e,`localPort`)??j(e,`local_port`))==`number`?{localPort:j(e,`localPort`)??j(e,`local_port`)??void 0}:{},...typeof(j(e,`remotePort`)??j(e,`remote_port`))==`number`?{remotePort:j(e,`remotePort`)??j(e,`remote_port`)??void 0}:{},startedByUs:M(e,`startedByUs`)??M(e,`started_by_us`)??!1,retryAttempt:j(e,`retryAttempt`)??j(e,`retry_attempt`)??0,requiresUserAction:M(e,`requiresUserAction`)??M(e,`requires_user_action`)??!1,...A(e,`errorCode`)||A(e,`error_code`)?{errorCode:A(e,`errorCode`)||A(e,`error_code`)||void 0}:{},updatedAtMs:j(e,`updatedAtMs`)??j(e,`updated_at_ms`)??Date.now()}:null},Ce=e=>{if(!k(e))return null;let t=A(e,`host`),n=A(e,`source`),r=A(e,`sshCommand`)||A(e,`ssh_command`);return!t||!n||!r?null:{host:t,source:n,sshCommand:r,pattern:M(e,`pattern`)??!1}},we=(e,t)=>({id:e,sshCommand:t,connectionTimeoutSec:60,remoteOpenchamber:{mode:`managed`,keepRunning:!0,relayHost:!0,installMethod:`bun`,uploadBundleOverSsh:!1},localForward:{bindHost:`127.0.0.1`},auth:{},portForwards:[]}),Te=async()=>{let e=P();if(!e)return{instances:[]};let t=await e(`desktop_ssh_instances_get`);return k(t)?{instances:(Array.isArray(t.instances)?t.instances:Array.isArray(t.desktopSshInstances)?t.desktopSshInstances:[]).map(e=>xe(e)).filter(e=>!!e)}:{instances:[]}},Ee=async e=>{let t=P();t&&await t(`desktop_ssh_instances_set`,{config:{instances:e.instances}})},De=async()=>{let e=P();if(!e)return[];let t=await e(`desktop_ssh_import_hosts`);return Array.isArray(t)?t.map(e=>Ce(e)).filter(e=>!!e):[]},Oe=async e=>{let t=P();t&&await t(`desktop_ssh_connect`,{id:e})},ke=async e=>{let t=P();t&&await t(`desktop_ssh_disconnect`,{id:e})},Ae=async e=>{let t=P();if(!t)return[];let n=await t(`desktop_ssh_status`,{...e?{id:e}:{}});return Array.isArray(n)?n.map(e=>I(e)).filter(e=>!!e):[]},je=async(e,t)=>{let n=P();if(!n)return[];let r=await n(`desktop_ssh_logs`,{id:e,...typeof t==`number`?{limit:t}:{}});return Array.isArray(r)?r.filter(e=>typeof e==`string`):[]},Me=async e=>{let t=P();t&&await t(`desktop_ssh_logs_clear`,{id:e})},Ne=(e,t)=>{let n=Math.max(0,Math.trunc(Number(e.fileGroups)||0)),r=Math.max(0,Math.trunc(Number(e.singleFiles)||0)),i=Math.max(0,Math.trunc(Number(e.directories)||0));return{fileGroups:Array.from({length:n},()=>!0),singleFiles:Array.from({length:r},()=>!0),directories:Array.from({length:i},()=>!0),agentsRoot:!0,authFile:t?.includeAuthFile===!0}},Pe=e=>{if(!k(e))return null;let t=A(e,`path`),n=j(e,`bytes`);return!t||n===null?null:{path:t,bytes:n}},Fe=e=>{if(!k(e))return null;let t=A(e,`path`),n=j(e,`fileCount`)??j(e,`file_count`),r=j(e,`bytes`);return!t||n===null||r===null?null:{path:t,fileCount:n,bytes:r}},Ie=e=>{if(e==null||!k(e))return null;let t=j(e,`fileCount`)??j(e,`file_count`),n=j(e,`bytes`);return t===null||n===null?null:{fileCount:t,bytes:n}},L=e=>{if(e==null||!k(e))return null;let t=j(e,`bytes`);return t===null?null:{bytes:t}},R=e=>{if(!k(e))return null;let t=Array.isArray(e.files)?e.files:null,n=Array.isArray(e.directories)?e.directories:null,r=N(e.deletes),i=j(e,`totalBytes`)??j(e,`total_bytes`);if(!t||!n||i===null||!(`agentsRoot`in e)&&!(`agents_root`in e))return null;let a=t.map(e=>Pe(e)).filter(e=>!!e),o=n.map(e=>Fe(e)).filter(e=>!!e);if(a.length!==t.length||o.length!==n.length)return null;let s=e.agentsRoot??e.agents_root,c=s==null?null:Ie(s);if(s!=null&&c===null)return null;let l=e.authFile??e.auth_file,u=l==null?null:L(l),d=e.direction===`pull`||e.direction===`push`?e.direction:void 0,f=e.selections,p=k(f)?{fileGroups:Array.isArray(f.fileGroups)?f.fileGroups.map(e=>e!==!1):[],singleFiles:Array.isArray(f.singleFiles)?f.singleFiles.map(e=>e!==!1):[],directories:Array.isArray(f.directories)?f.directories.map(e=>e!==!1):[],agentsRoot:f.agentsRoot!==!1,authFile:f.authFile===!0}:void 0,m=z(e.selectionShape??e.selection_shape);return{files:a,directories:o,agentsRoot:c,authFile:u,deletes:r,totalBytes:i,...d?{direction:d}:{},...p?{selections:p}:{},...m?{selectionShape:m}:{}}},z=e=>{if(!k(e))return null;let t=j(e,`fileGroups`)??j(e,`file_groups`),n=j(e,`singleFiles`)??j(e,`single_files`),r=j(e,`directories`);return t===null||n===null||r===null||t<0||n<0||r<0?null:{fileGroups:t,singleFiles:n,directories:r}},Le=e=>{if(!k(e))return null;let t=R(e.plan);if(!t)return null;let n=z(e.selectionShape??e.selection_shape)??t.selectionShape??null;return{plan:t,remoteExisting:N(e.remoteExisting??e.remote_existing),remoteAgentsRootExists:M(e,`remoteAgentsRootExists`)??M(e,`remote_agents_root_exists`)??!1,remoteAuthFileExists:M(e,`remoteAuthFileExists`)??M(e,`remote_auth_file_exists`)??!1,...typeof e.credentialAuthorized==`boolean`?{credentialAuthorized:e.credentialAuthorized}:{},...n?{selectionShape:n}:{}}},Re=e=>{if(!k(e)||M(e,`ok`)!==!0)return null;let t=j(e,`files`),n=j(e,`directories`),r=j(e,`deletes`),i=j(e,`totalBytes`)??j(e,`total_bytes`);if(t===null||n===null||r===null||i===null||!(`agentsRoot`in e)&&!(`agents_root`in e))return null;let a=e.agentsRoot??e.agents_root,o=null;if(a!=null){if(!k(a))return null;let e=j(a,`fileCount`)??j(a,`file_count`);if(e===null)return null;o={fileCount:e}}let s=e.authFile??e.auth_file,c=s==null?null:L(s);return{ok:!0,files:t,directories:n,deletes:r,totalBytes:i,agentsRoot:o,authFile:c}},ze=async(e={})=>{let t=P();if(!t)return console.error(`[desktopSsh] config sync local scan skipped: desktop IPC bridge is unavailable in this window`),null;let n=await t(`desktop_ssh_sync_opencode_config`,{stage:`local`,...e.direction?{direction:e.direction}:{},...e.selections?{selections:e.selections}:{}});if(!k(n))return console.error(`[desktopSsh] config sync local scan returned a non-object payload`,n),null;let r=R(n.plan);if(!r)return console.error(`[desktopSsh] config sync local scan plan payload was not recognized`,n),null;let i=z(n.selectionShape??n.selection_shape)??r.selectionShape??null;return i?{...r,selectionShape:i}:r},Be=async(e,t={})=>{let n=P();if(!n)return console.error(`[desktopSsh] config sync preview skipped: desktop IPC bridge is unavailable in this window`),null;let r=await n(`desktop_ssh_sync_opencode_config`,{id:e,...t.targetKind?{targetKind:t.targetKind}:{},...t.direction?{direction:t.direction}:{},...t.selections?{selections:t.selections}:{}}),i=Le(r);return i||console.error(`[desktopSsh] config sync preview payload was not recognized`,r),i},Ve=async(e,t={})=>{let n=P();if(!n)return console.error(`[desktopSsh] config sync apply skipped: desktop IPC bridge is unavailable in this window`),null;let r=await n(`desktop_ssh_sync_opencode_config`,{id:e,apply:!0,...t.targetKind?{targetKind:t.targetKind}:{},...t.direction?{direction:t.direction}:{},...t.selections?{selections:t.selections}:{}}),i=Re(r);return i||console.error(`[desktopSsh] config sync apply payload was not recognized`,r),i},He=async(e,t={})=>{let n=P();if(!n)return[];let r=await n(`desktop_ssh_sync_runs_list`,{id:e,...t.targetKind?{targetKind:t.targetKind}:{}});return Array.isArray(r)?r.filter(e=>k(e)&&typeof e.syncRunId==`string`&&typeof e.targetId==`string`):[]},B=e=>{if(!k(e))return null;let t=typeof e.targetId==`string`?e.targetId.trim():``;if(!t)return null;let n=e.authorized===!0,r=typeof e.grantedAt==`string`&&e.grantedAt.trim()?e.grantedAt.trim():void 0,i=typeof e.channel==`string`&&e.channel.trim()?e.channel.trim():void 0;return{targetId:t,authorized:n,...r?{grantedAt:r}:{},...i?{channel:i}:{}}},Ue=async(e,t={})=>{let n=P();return n?B(await n(`desktop_ssh_credential_sync_get`,{id:e,...t.targetKind?{targetKind:t.targetKind}:{}})):null},We=async(e,t={})=>{let n=P();return n?B(await n(`desktop_ssh_credential_sync_grant`,{id:e,...t.targetKind?{targetKind:t.targetKind}:{}})):null},Ge=async(e,t={})=>{let n=P();return n?B(await n(`desktop_ssh_credential_sync_revoke`,{id:e,...t.targetKind?{targetKind:t.targetKind}:{}})):null},Ke=async e=>{if(!r())return async()=>{};let t=window.__OPENCHAMBER_DESKTOP__?.listen;if(typeof t!=`function`)return async()=>{};let n=await t(`openchamber:ssh-instance-status`,t=>{let n=I(t?.payload);n&&e(n)});return async()=>{await n()}},qe=new Set([`nodeRuntimeMissing`,`packageManagerMissing`,`nativeBinding`,`openchamberCliMissing`,`openchamberRegistry`,`openchamberInstall`,`openchamberCliIncompatible`,`opencodeInstall`,`serverStart`,`sshAuth`,`sshUnreachable`,`timeout`,`unknown`]),Je=e=>typeof e==`string`&&qe.has(e),Ye=e=>{let t=String(e||``);return/requires Node\.js \d+|no supported Node runtime/i.test(t)?`nodeRuntimeMissing`:/neither bun nor npm/i.test(t)?`packageManagerMissing`:/better-sqlite3|node_gyp_bins|gyp ERR|failed to prepare better-sqlite3/i.test(t)?`nativeBinding`:/OpenChamber installation completed but the executable is unavailable/i.test(t)?`openchamberCliMissing`:/could not reach the npm registry|ENOTFOUND|ECONNREFUSED|ETIMEDOUT|EAI_AGAIN|CERT_HAS_EXPIRED|UNABLE_TO_GET_ISSUER_CERT|self-signed certificate|registry\.npmjs|npm error code E404|npm ERR! code E404|getaddrinfo/i.test(t)?`openchamberRegistry`:/Failed to install OpenChamber/i.test(t)?`openchamberInstall`:/Unknown option:\s*--relay-host|does not advertise --relay-host|does not support --relay-host/i.test(t)||/Unknown option:/i.test(t)?`openchamberCliIncompatible`:/Failed to install OpenCode|OpenCode CLI/i.test(t)?`opencodeInstall`:/failed to become reachable|Managed OpenChamber server failed/i.test(t)?`serverStart`:/Permission denied|Authentication failed|publickey|keyboard-interactive/i.test(t)?`sshAuth`:/Could not resolve hostname|Connection refused|Connection timed out|ControlMaster connection timed out|SSH master process exited|Network is unreachable/i.test(t)?`sshUnreachable`:/Timed out waiting for SSH|Timed out waiting for forwarded/i.test(t)?`timeout`:`unknown`},V=(e,t)=>Je(e)?e:Ye(t),H=e=>{switch(e){case`nodeRuntimeMissing`:return`desktopHostSwitcher.sshError.nodeRuntimeMissing.title`;case`packageManagerMissing`:return`desktopHostSwitcher.sshError.packageManagerMissing.title`;case`nativeBinding`:return`desktopHostSwitcher.sshError.nativeBinding.title`;case`openchamberCliMissing`:return`desktopHostSwitcher.sshError.openchamberCliMissing.title`;case`openchamberRegistry`:return`desktopHostSwitcher.sshError.openchamberRegistry.title`;case`openchamberInstall`:return`desktopHostSwitcher.sshError.openchamberInstall.title`;case`openchamberCliIncompatible`:return`desktopHostSwitcher.sshError.openchamberCliIncompatible.title`;case`opencodeInstall`:return`desktopHostSwitcher.sshError.opencodeInstall.title`;case`serverStart`:return`desktopHostSwitcher.sshError.serverStart.title`;case`sshAuth`:return`desktopHostSwitcher.sshError.sshAuth.title`;case`sshUnreachable`:return`desktopHostSwitcher.sshError.sshUnreachable.title`;case`timeout`:return`desktopHostSwitcher.sshError.timeout.title`;default:return`desktopHostSwitcher.sshError.unknown.title`}},U=e=>{switch(e){case`nodeRuntimeMissing`:return`desktopHostSwitcher.sshError.nodeRuntimeMissing.guidance`;case`packageManagerMissing`:return`desktopHostSwitcher.sshError.packageManagerMissing.guidance`;case`nativeBinding`:return`desktopHostSwitcher.sshError.nativeBinding.guidance`;case`openchamberCliMissing`:return`desktopHostSwitcher.sshError.openchamberCliMissing.guidance`;case`openchamberRegistry`:return`desktopHostSwitcher.sshError.openchamberRegistry.guidance`;case`openchamberInstall`:return`desktopHostSwitcher.sshError.openchamberInstall.guidance`;case`openchamberCliIncompatible`:return`desktopHostSwitcher.sshError.openchamberCliIncompatible.guidance`;case`opencodeInstall`:return`desktopHostSwitcher.sshError.opencodeInstall.guidance`;case`serverStart`:return`desktopHostSwitcher.sshError.serverStart.guidance`;case`sshAuth`:return`desktopHostSwitcher.sshError.sshAuth.guidance`;case`sshUnreachable`:return`desktopHostSwitcher.sshError.sshUnreachable.guidance`;case`timeout`:return`desktopHostSwitcher.sshError.timeout.guidance`;default:return`desktopHostSwitcher.sshError.unknown.guidance`}},W=e=>e===`unknown`||e===`openchamberCliIncompatible`,Xe=(e,t,n)=>{let r=typeof n==`string`?n.trim():``;return!W(t)||!r||r===e?e:`${e}\n${r}`},G=d();function Ze(e){let t=(0,T.c)(27),{errorCode:n,detail:r,className:i}=e,{t:a}=v(),o,s,c,l,u,d;if(t[0]!==i||t[1]!==r||t[2]!==n||t[3]!==a){let e=V(n,r);o=a(U(e));let f;t[10]===r?f=t[11]:(f=typeof r==`string`?r.trim():``,t[10]=r,t[11]=f),s=f,c=W(e)&&!!s&&s!==o,t[12]===i?d=t[13]:(d=C(`space-y-1`,i),t[12]=i,t[13]=d),l=`typography-ui-label text-[var(--status-error)]`,u=a(H(e)),t[0]=i,t[1]=r,t[2]=n,t[3]=a,t[4]=o,t[5]=s,t[6]=c,t[7]=l,t[8]=u,t[9]=d}else o=t[4],s=t[5],c=t[6],l=t[7],u=t[8],d=t[9];let f;t[14]!==l||t[15]!==u?(f=(0,G.jsx)(`p`,{className:l,children:u}),t[14]=l,t[15]=u,t[16]=f):f=t[16];let p;t[17]===o?p=t[18]:(p=(0,G.jsx)(`p`,{className:`typography-meta text-muted-foreground`,children:o}),t[17]=o,t[18]=p);let m;t[19]!==s||t[20]!==c?(m=c?(0,G.jsx)(`p`,{className:`typography-meta break-words text-muted-foreground`,children:s}):null,t[19]=s,t[20]=c,t[21]=m):m=t[21];let h;return t[22]!==d||t[23]!==f||t[24]!==p||t[25]!==m?(h=(0,G.jsxs)(`div`,{className:d,children:[f,p,m]}),t[22]=d,t[23]=f,t[24]=p,t[25]=m,t[26]=h):h=t[26],h}var Qe=`/auth/passkey/authenticate/options`,$e=`/auth/passkey/authenticate/verify`,et=`/auth/passkey/register/options`,tt=`/auth/passkey/register/verify`,K=`/api/passkeys`,nt=`/auth/passkey/status`,rt=`/api/auth/reset`,q={enabled:!1,hasPasskeys:!1,passkeyCount:0,rpID:null},J=async(e,t)=>i(e,{method:`POST`,credentials:`include`,headers:{"Content-Type":`application/json`,Accept:`application/json`},body:t===void 0?void 0:JSON.stringify(t)}),Y=async(e,t)=>{try{let t=await e.json();if(t&&typeof t.error==`string`&&t.error.trim())return t.error}catch{}return t},it=e=>e instanceof oe&&e.code===`ERROR_CEREMONY_ABORTED`,at=()=>{ce.cancelCeremony()},X=()=>typeof window>`u`?{supported:!1,reason:`Passkeys are unavailable outside the browser.`}:window.isSecureContext?{supported:!0,reason:``}:{supported:!1,reason:`Passkeys require HTTPS or localhost.`},ot=async()=>{let e=X();if(!e.supported)throw Error(e.reason);let t=await J(et,{label:typeof navigator.userAgent==`string`&&navigator.userAgent.trim()?navigator.userAgent:`This device`});if(!t.ok)throw Error(await Y(t,`Could not start passkey setup.`));let{requestId:n,optionsJSON:r}=await t.json(),i=await J(tt,{requestId:n,response:await se({optionsJSON:r})});if(!i.ok)throw Error(await Y(i,`Could not finish passkey setup.`));return i.json().catch(()=>null)},st=async(e,t={})=>{let n=X();if(!n.supported)throw Error(n.reason);let r=await J(Qe);if(!r.ok)throw Error(await Y(r,`Passkey sign-in is not available right now.`));let{requestId:i,optionsJSON:a}=await r.json(),o=await J($e,{requestId:i,response:await le({optionsJSON:a}),trustDevice:e,issueClientToken:t.issueClientToken===!0,clientLabel:t.clientLabel,clientKind:t.clientKind,dedupeKey:t.dedupeKey});if(!o.ok)throw Error(await Y(o,`Passkey sign-in failed.`));return o.json().catch(()=>null)},ct=async()=>{let e=await i(nt,{method:`GET`,credentials:`include`,headers:{Accept:`application/json`}});if(!e.ok)return q;let t=await e.json().catch(()=>null);return{enabled:t?.enabled===!0,hasPasskeys:t?.hasPasskeys===!0,passkeyCount:typeof t?.passkeyCount==`number`?t.passkeyCount:0,rpID:typeof t?.rpID==`string`&&t.rpID?t.rpID:null}},lt=async()=>{let e=await i(K,{method:`GET`,credentials:`include`,headers:{Accept:`application/json`}});if(!e.ok)throw Error(await Y(e,`Could not load passkeys.`));let t=await e.json().catch(()=>null);return Array.isArray(t?.passkeys)?t.passkeys:[]},ut=async e=>{let t=await i(`${K}/${encodeURIComponent(e)}`,{method:`DELETE`,credentials:`include`,headers:{Accept:`application/json`}});if(!t.ok)throw Error(await Y(t,`Could not remove passkey.`));return t.json().catch(()=>null)},dt=async()=>{let e=await J(rt);if(!e.ok)throw Error(await Y(e,`Could not clear saved authentication.`));return e.json().catch(()=>null)},Z=e(f(),1);function ft(e){let t=(0,T.c)(8),n,r;t[0]===e?(n=t[1],r=t[2]):({className:n,...r}=e,t[0]=e,t[1]=n,t[2]=r);let i;t[3]===n?i=t[4]:(i=C(`bg-card text-card-foreground flex flex-col gap-6 rounded-xl border py-6 shadow-none`,n),t[3]=n,t[4]=i);let a;return t[5]!==r||t[6]!==i?(a=(0,G.jsx)(`div`,{"data-slot":`card`,className:i,...r}),t[5]=r,t[6]=i,t[7]=a):a=t[7],a}function pt(e){let t=(0,T.c)(8),n,r;t[0]===e?(n=t[1],r=t[2]):({className:n,...r}=e,t[0]=e,t[1]=n,t[2]=r);let i;t[3]===n?i=t[4]:(i=C(`@container/card-header grid auto-rows-min grid-rows-[auto_auto] items-start gap-1.5 px-6 has-data-[slot=card-action]:grid-cols-[1fr_auto] [.border-b]:pb-6`,n),t[3]=n,t[4]=i);let a;return t[5]!==r||t[6]!==i?(a=(0,G.jsx)(`div`,{"data-slot":`card-header`,className:i,...r}),t[5]=r,t[6]=i,t[7]=a):a=t[7],a}function mt(e){let t=(0,T.c)(8),n,r;t[0]===e?(n=t[1],r=t[2]):({className:n,...r}=e,t[0]=e,t[1]=n,t[2]=r);let i;t[3]===n?i=t[4]:(i=C(`leading-none font-semibold`,n),t[3]=n,t[4]=i);let a;return t[5]!==r||t[6]!==i?(a=(0,G.jsx)(`div`,{"data-slot":`card-title`,className:i,...r}),t[5]=r,t[6]=i,t[7]=a):a=t[7],a}function ht(e){let t=(0,T.c)(8),n,r;t[0]===e?(n=t[1],r=t[2]):({className:n,...r}=e,t[0]=e,t[1]=n,t[2]=r);let i;t[3]===n?i=t[4]:(i=C(`px-6`,n),t[3]=n,t[4]=i);let a;return t[5]!==r||t[6]!==i?(a=(0,G.jsx)(`div`,{"data-slot":`card-content`,className:i,...r}),t[5]=r,t[6]=i,t[7]=a):a=t[7],a}var gt=class extends Z.Component{constructor(e){super(e),this.state={hasError:!1}}static getDerivedStateFromError(e){return{hasError:!0,error:e}}componentDidCatch(e,t){this.setState({error:e,errorInfo:t,copied:!1}),console.error(`Error caught by boundary:`,e,t)}handleReset=()=>{this.setState({hasError:!1,error:void 0,errorInfo:void 0})};handleCopy=async()=>{let{strings:e}=this.props,t=`${this.state.error?String(this.state.error):e.unknownError}${this.state.error?.stack?`\n\nStack:\n${this.state.error.stack}`:``}${this.state.errorInfo?.componentStack?`\n\n${e.componentStackLabel}${this.state.errorInfo.componentStack}`:``}`;(await y(t)).ok&&(this.setState({copied:!0}),window.setTimeout(()=>{this.setState(e=>e.copied?{copied:!1}:null)},1500))};render(){let{strings:e}=this.props;return this.state.hasError?this.props.fallback?this.props.fallback:(0,G.jsx)(`div`,{className:`p-4 flex items-center justify-center min-h-screen`,children:(0,G.jsxs)(ft,{className:`w-full max-w-md`,children:[(0,G.jsx)(pt,{className:`text-center`,children:(0,G.jsxs)(mt,{className:`flex items-center justify-center gap-2 text-destructive`,children:[(0,G.jsx)(w,{name:`error-warning`,className:`h-5 w-5`}),e.title]})}),(0,G.jsxs)(ht,{className:`space-y-4`,children:[(0,G.jsx)(`p`,{className:`text-sm text-muted-foreground text-center`,children:e.description}),this.state.error&&(0,G.jsxs)(`details`,{className:`text-xs font-mono bg-muted p-3 rounded`,children:[(0,G.jsx)(`summary`,{className:`cursor-pointer hover:bg-interactive-hover/80`,children:e.detailsSummary}),(0,G.jsxs)(`pre`,{className:`mt-2 max-h-48 overflow-auto`,children:[this.state.error.toString(),this.state.errorInfo?.componentStack?`\n\n${e.componentStackLabel}${this.state.errorInfo.componentStack}`:``]})]}),(0,G.jsxs)(`div`,{className:`flex gap-2`,children:[(0,G.jsxs)(ae,{onClick:this.handleReset,variant:`outline`,className:`flex-1`,children:[(0,G.jsx)(w,{name:`restart`,className:`h-4 w-4 mr-2`}),e.tryAgain]}),(0,G.jsx)(ae,{onClick:this.handleCopy,variant:`outline`,className:`flex-1`,children:this.state.copied?e.copied:e.copy})]})]})]})}):this.props.children}},_t=e=>{let t=(0,T.c)(29),{children:n,fallback:r}=e,{t:i}=v(),a;t[0]===i?a=t[1]:(a=i(`errorBoundary.state.unknownError`),t[0]=i,t[1]=a);let o;t[2]===i?o=t[3]:(o=i(`errorBoundary.title`),t[2]=i,t[3]=o);let s;t[4]===i?s=t[5]:(s=i(`errorBoundary.description`),t[4]=i,t[5]=s);let c;t[6]===i?c=t[7]:(c=i(`errorBoundary.actions.errorDetails`),t[6]=i,t[7]=c);let l;t[8]===i?l=t[9]:(l=i(`errorBoundary.state.componentStackLabel`),t[8]=i,t[9]=l);let u;t[10]===i?u=t[11]:(u=i(`errorBoundary.actions.tryAgain`),t[10]=i,t[11]=u);let d;t[12]===i?d=t[13]:(d=i(`errorBoundary.actions.copied`),t[12]=i,t[13]=d);let f;t[14]===i?f=t[15]:(f=i(`errorBoundary.actions.copy`),t[14]=i,t[15]=f);let p;t[16]!==a||t[17]!==o||t[18]!==s||t[19]!==c||t[20]!==l||t[21]!==u||t[22]!==d||t[23]!==f?(p={unknownError:a,title:o,description:s,detailsSummary:c,componentStackLabel:l,tryAgain:u,copied:d,copy:f},t[16]=a,t[17]=o,t[18]=s,t[19]=c,t[20]=l,t[21]=u,t[22]=d,t[23]=f,t[24]=p):p=t[24];let m=p,h;return t[25]!==n||t[26]!==r||t[27]!==m?(h=(0,G.jsx)(gt,{fallback:r,strings:m,children:n}),t[25]=n,t[26]=r,t[27]=m,t[28]=h):h=t[28],h},Q=e=>ee(b.getState().dictionary,e),vt=e=>typeof e!=`number`||!Number.isFinite(e)?null:Math.max(0,Math.min(100,Math.round(e))),yt=e=>typeof e!=`number`||!Number.isFinite(e)?`-`:`${Math.round(e)}%`,bt=(e,t)=>e??yt(t),xt=(e,t,n=`auto`)=>{if(!e)return t??``;try{let r=new Date(e);if(!Number.isFinite(r.getTime()))return t??``;let i=new Date;return r.toDateString()===i.toDateString()?de(r,n,{fallback:t??``}):ue(r,n,{month:`short`,day:`numeric`,weekday:`short`,hour:`numeric`,minute:`2-digit`})}catch{return t??``}},St=e=>e===null?`safe`:e>=80?`critical`:e>=50?`warn`:`safe`,Ct=e=>e===`5h`?Q(`quota.window.5h`):e===`7d`?Q(`quota.window.7d`):e===`7d-sonnet`?Q(`quota.window.7dSonnet`):e===`7d-opus`?Q(`quota.window.7dOpus`):e===`weekly`?Q(`quota.window.weekly`):e===`daily`?Q(`quota.window.daily`):e===`monthly`?Q(`quota.window.monthly`):e===`credits`?Q(`quota.window.credits`):e===`credits_balance`?Q(`quota.window.creditsBalance`):e===`billing_cycle`?Q(`quota.window.billingCycle`):e===`auto`?Q(`quota.window.auto`):e===`api`?Q(`quota.window.api`):e===`plan_limit`?Q(`quota.window.planLimit`):e===`on_demand`?Q(`quota.window.onDemand`):e===`session`?Q(`quota.window.session`):e===`premium`?Q(`quota.window.premium`):e===`chat`?Q(`quota.window.chat`):e===`completions`?Q(`quota.window.completions`):e===`premium_interactions`?Q(`quota.window.premiumInteractions`):e,wt=e=>{let t=e.toLowerCase().trim();if(t===`5h`)return 18e3;if(t===`7d`||t===`weekly`||t===`7d-sonnet`||t===`7d-opus`)return 604800;if(t===`monthly`)return 2592e3;if(t===`24h`||t===`daily`)return 86400;if(t===`1h`)return 3600;let n=t.match(/^(\d+)h$/);if(n)return parseInt(n[1],10)*3600;let r=t.match(/^(\d+)d$/);return r?parseInt(r[1],10)*86400:null},Tt=(e,t,n,r)=>{let i=n;if(i===null&&r&&(i=wt(r)),e===null||t===null||i===null||i<=0)return null;let a=Math.max(0,(t-Date.now())/1e3),o=Math.max(0,Math.min(i,i-a)),s=Math.max(0,Math.min(1,o/i)),c=e/100,l=e>=100&&a>0,u;u=s>.01?Math.min(999,c/s*100):e;let d;d=l?`exhausted`:c<=s?`on-track`:u<=130?`slightly-fast`:`too-fast`;let f=i>=432e3,p=f?86400:3600,m=f?`d`:`h`,h=i/p,g=e/Math.max(o/p,h*.01),_=Number.isFinite(g)?`${Math.min(999.9,Math.max(0,g)).toFixed(1)}%/${m}`:`-`,v=u>100?`+${Math.round(u)}%`:`${Math.round(u)}%`,y=null,b=i/86400;return b>=7&&(y=100/b),{elapsedRatio:s,usageRatio:c,predictedFinalPercent:u,remainingSeconds:a,isExhausted:l,elapsedSeconds:o,totalSeconds:i,status:d,paceRateText:_,predictText:v,dailyAllocationPercent:y}},Et=e=>{switch(e){case`exhausted`:case`too-fast`:return`var(--status-error)`;case`slightly-fast`:return`var(--status-warning)`;case`on-track`:return`var(--status-success)`}},Dt=e=>{let t=Math.floor(Math.max(0,Math.floor(e))/60),n=Math.floor(t/60),r=Math.floor(n/24),i=n%24,a=t%60;return r>0?`${r}d ${i}h`:n>0?`${n}h`:t===0?`<1m`:`${a}m`},Ot=e=>Math.min(100,Math.max(0,e*100)),kt=[`standalone`,`minimal-ui`,`fullscreen`,`window-controls-overlay`],At=`openchamber.pwaRecentSessions`,jt=e=>typeof window>`u`||typeof window.matchMedia!=`function`?!1:window.matchMedia(`(display-mode: ${e})`).matches,Mt=()=>typeof window>`u`?`browser`:typeof document<`u`&&document.referrer.startsWith(`android-app://`)?`twa`:window.navigator.standalone?`standalone`:kt.find(e=>jt(e))??`browser`,Nt=864e5,Pt=5,Ft=864e5,$=e=>e.time?.updated??e.time?.created??0,It=({sessions:e,currentSessionId:t,cutoffDays:n,keepRecent:r=Pt,now:i=Date.now()})=>{if(!Array.isArray(e)||n<=0)return[];let a=i-n*Nt,o=[...e].sort((e,t)=>$(t)-$(e)),s=new Set(o.slice(0,r).map(e=>e.id));return o.filter(e=>{if(!e?.id||s.has(e.id)||e.id===t||e.share)return!1;let n=$(e);return n?n<a:!1}).map(e=>e.id)},Lt=e=>{let t=typeof e==`object`?e:void 0,r=t?.autoRun!==!1,i=typeof e==`boolean`?e:t?.enabled??!0,a=x(e=>e.currentSessionId),o=x(e=>e.isLoading),s=S(e=>e.activeSessions),c=S(e=>e.hasLoadedFullCatalog),l=n(e=>e.autoDeleteEnabled),u=n(e=>e.autoDeleteAfterDays),d=n(e=>e.sessionRetentionAction),f=n(e=>e.autoDeleteLastRunAt),m=n(e=>e.setAutoDeleteLastRunAt),[h,g]=Z.useState(!1),_=Z.useRef(!1);Z.useEffect(()=>{if(!i||!r||!l||u<=0)return;let e=window.setTimeout(()=>{ie(re())},8e3);return()=>window.clearTimeout(e)},[u,l,r,i]);let v=Z.useMemo(()=>u<=0?[]:It({sessions:s,currentSessionId:a,cutoffDays:u}),[u,a,s]),y=Z.useCallback(async({force:e=!1}={})=>{if(_.current)return{completedIds:[],failedIds:[],action:d,skippedReason:`running`};if((!l||u<=0)&&!e)return{completedIds:[],failedIds:[],action:d,skippedReason:`disabled`};if(o)return{completedIds:[],failedIds:[],action:d,skippedReason:`loading`};let t=Date.now();if(!e&&f&&t-f<Ft)return{completedIds:[],failedIds:[],action:d,skippedReason:`cooldown`};let{activeSessions:n}=await ie(re());if(n.length===0)return{completedIds:[],failedIds:[],action:d,skippedReason:`no-candidates`};let r=It({sessions:n,currentSessionId:a,cutoffDays:u,now:t});if(r.length===0)return m(t),{completedIds:[],failedIds:[],action:d,skippedReason:`no-candidates`};_.current=!0,g(!0);try{let e=new Map(n.map(e=>[e.id,e])),t=[],i=[];for(let n of r){let r=e.get(n),a=r?ne(r):null;if(!a){i.push(n);continue}try{d===`archive`?await p.updateSession(n,{time:{archived:Date.now()}},a):await p.deleteSession(n,a),t.push(n)}catch{i.push(n)}}return d===`archive`?S.getState().archiveSessions(t):S.getState().removeSessions(t),{completedIds:t,failedIds:i,action:d}}finally{_.current=!1,g(!1),m(Date.now())}},[u,l,f,a,o,d,m]);return Z.useEffect(()=>{i&&r&&(!l||u<=0||o||!c||s.length===0||f&&Date.now()-f<Ft||y())},[u,l,f,r,i,c,s.length,o,y]),{candidates:v,isRunning:h,runCleanup:y,keepRecentCount:Pt,action:d}};export{_e as $,V as A,De as B,X as C,ut as D,dt as E,Oe as F,Ae as G,Ee as H,Ue as I,Be as J,Ve as K,We as L,H as M,Ne as N,Ze as O,we as P,ge as Q,Ge as R,lt as S,ot as T,je as U,Te as V,Me as W,Ke as X,He as Y,he as Z,mt as _,Tt as a,q as b,bt as c,Et as d,St as f,pt as g,ht as h,Ot as i,U as j,Xe as k,Dt as l,ft as m,At as n,vt as o,_t as p,ze as q,Mt as r,xt as s,Lt as t,Ct as u,st as v,it as w,ct as x,at as y,ke as z};
|
package/dist/assets/{useWorkerHighlightedLines-D9wuF7G6.js → useWorkerHighlightedLines-C-c4vn3t.js}
RENAMED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{o as e}from"./rolldown-runtime-C0FnF6B9.js";import{_ as t}from"./useUIStore-NfqK-HA7.js";import{$t as n,kn as r,xn as i}from"./persistence-vZ7H8WKh.js";import{nt as a,rt as o}from"./vendor-base-ui-CnHfUmDN.js";import{n as s}from"./platform-CTaznShj.js";import{a as c,n as l}from"./vendor-aparajita-capacitor-secure-storage-CjQdwfjS.js";import{n as u}from"./vendor-react-DLPElpoQ.js";import{n as d}from"./clipboard-BfgFef1i.js";import{t as f}from"./utils-C2P0wcWO.js";import{n as p}from"./Icon-D-X70irR.js";import{t as m}from"./button-CwLFtUNT.js";import{i as h,n as g,t as _}from"./tooltip-CaCe-GAm.js";import{n as v}from"./useThemeSystem-DMzWVJaW.js";import{c as y,n as b,o as x,r as S,s as C}from"./markdownTheme-Bl0Sy0Lf.js";import{i as w}from"./appThemeRegistry-CZWWy6CN.js";import{d as T,n as E,t as D,u as ee}from"./markdown-worker-N9d_Z-7s.js";import{t as te}from"./vendor-tanstack-react-virtual-tlDgH6PG.js";var O=e(o(),1),k=u(),A=a(),ne=`w-[min(30rem,calc(100cqw-1rem))] min-w-[280px] max-w-full overflow-hidden rounded-xl shadow-[inset_0_1px_0_0_rgba(255,255,255,0.8),inset_0_0_0_1px_rgba(0,0,0,0.04),0_0_0_1px_rgba(0,0,0,0.10),0_1px_2px_-0.5px_rgba(0,0,0,0.08),0_4px_8px_-2px_rgba(0,0,0,0.08),0_12px_20px_-4px_rgba(0,0,0,0.08)] dark:shadow-[inset_0_1px_0_0_rgba(255,255,255,0.12),inset_0_0_0_1px_rgba(255,255,255,0.08),0_0_0_1px_rgba(0,0,0,0.36),0_1px_1px_-0.5px_rgba(0,0,0,0.22),0_3px_3px_-1.5px_rgba(0,0,0,0.20),0_6px_6px_-3px_rgba(0,0,0,0.16)]`,j={maxWidth:`min(28rem, calc(100cqw - 4ch))`,backgroundColor:`var(--surface-elevated)`,color:`var(--surface-elevated-foreground)`},M=`flex items-center justify-between gap-3 border-b border-[var(--surface-subtle)] px-3 py-2.5`,N=`text-xs font-medium leading-4 text-foreground md:text-[0.8125rem] md:leading-5`,re=`text-xs tabular-nums leading-4 text-muted-foreground md:text-[0.8125rem] md:leading-5`,P=`m-0 list-none divide-y divide-[var(--surface-subtle)] p-0`,F=`${P} max-h-[min(22rem,50vh)] overflow-y-auto`,ie=`${P} w-full`,ae={className:`p-0 rounded-none`,maxHeightClass:`max-h-[46vh]`,disableHorizontal:!0},I=`px-2.5 py-1.5 text-xs leading-4 md:py-2 md:text-[0.8125rem] md:leading-5`,oe=`flex min-w-0 items-center gap-1 text-xs leading-4 text-muted-foreground md:gap-1.5 md:text-[0.8125rem] md:leading-5`,se=`min-w-0 truncate text-xs leading-4 text-foreground md:text-[0.8125rem] md:leading-5`,ce=`inline-flex shrink-0 items-center gap-1 text-xs leading-4 tabular-nums text-muted-foreground md:text-[0.8125rem] md:leading-5`,le=`h-3 w-3 shrink-0 md:h-3.5 md:w-3.5`,ue={in_progress:`text-foreground`,pending:`text-foreground`,completed:`text-muted-foreground line-through`,cancelled:`text-muted-foreground line-through`},L={in_progress:`chat.statusRow.todo.status.inProgress`,pending:`chat.statusRow.todo.status.pending`,completed:`chat.statusRow.todo.status.completed`,cancelled:`chat.statusRow.todo.status.cancelled`},R=e=>{let t=(0,k.c)(26),{todo:n,isActive:r,activeRef:i}=e,{t:a}=d(),o=z.has(n.status)?n.status:`pending`,s=L[o],c;t[0]!==a||t[1]!==s?(c=a(s),t[0]=a,t[1]=s,t[2]=c):c=t[2];let l=c,u;t[3]===o?u=t[4]:(u=o===`in_progress`?(0,A.jsx)(p,{name:`record-circle`,className:`h-3.5 w-3.5 text-[var(--status-info)]`,"aria-hidden":`true`}):o===`completed`?(0,A.jsx)(p,{name:`checkbox-circle`,className:`h-3.5 w-3.5 text-[var(--status-success)]`,"aria-hidden":`true`}):(0,A.jsx)(p,{name:`time`,className:`h-3.5 w-3.5 text-muted-foreground`,"aria-hidden":`true`}),t[3]=o,t[4]=u);let m=u,v=r?`step`:void 0,y=r&&`bg-[var(--surface-muted)] before:absolute before:inset-y-2 before:left-0 before:w-0.5 before:rounded-full before:bg-[var(--status-info)]`,b;t[5]===y?b=t[6]:(b=f(`group relative grid min-w-0 grid-cols-[1rem_minmax(0,1fr)] items-start gap-2.5`,I,y),t[5]=y,t[6]=b);let x;t[7]!==m||t[8]!==l?(x=(0,A.jsx)(h,{asChild:!0,children:(0,A.jsx)(`span`,{className:`flex size-4 items-center justify-center`,"aria-label":l,children:m})}),t[7]=m,t[8]=l,t[9]=x):x=t[9];let S;t[10]===l?S=t[11]:(S=(0,A.jsx)(g,{side:`left`,sideOffset:6,children:l}),t[10]=l,t[11]=S);let C;t[12]!==x||t[13]!==S?(C=(0,A.jsxs)(_,{children:[x,S]}),t[12]=x,t[13]=S,t[14]=C):C=t[14];let w=ue[o],T;t[15]===w?T=t[16]:(T=f(`block whitespace-normal break-words`,w),t[15]=w,t[16]=T);let E;t[17]!==T||t[18]!==n.content?(E=(0,A.jsx)(`span`,{className:`min-w-0 flex-1`,children:(0,A.jsx)(`span`,{className:T,children:n.content})}),t[17]=T,t[18]=n.content,t[19]=E):E=t[19];let D;return t[20]!==i||t[21]!==E||t[22]!==v||t[23]!==b||t[24]!==C?(D=(0,A.jsxs)(`li`,{ref:i,"aria-current":v,className:b,children:[C,E]}),t[20]=i,t[21]=E,t[22]=v,t[23]=b,t[24]=C,t[25]=D):D=t[25],D},z=new Set([`in_progress`,`pending`,`completed`,`cancelled`]),B=`image/png`,V=c(`OpenChamberMedia`),H=e=>{let t=e.toLowerCase().split(`;`)[0]?.trim()||B;if(t===`image/jpeg`||t===`image/jpg`)return`jpg`;if(t===`image/webp`)return`webp`;if(t===`image/gif`)return`gif`;if(t===`image/svg+xml`)return`svg`;if(t===`image/png`)return`png`;let n=t.split(`/`)[1];return n&&/^[a-z0-9.+-]+$/i.test(n)?n:`png`},U=(e,t)=>{let n=`image.${H(t)}`,r=(((e||``).trim()||n).split(/[\\/]/).pop()||n).replace(/[^\w.\- ()[\]]+/g,`_`).replace(/^\.+/,``);return r?/\.[a-z0-9]{1,8}$/i.test(r)?r:`${r}.${H(t)}`:n},W=e=>new Promise((t,n)=>{let r=new FileReader;r.onload=()=>{if(typeof r.result==`string`){t(r.result);return}n(Error(`Failed to encode image`))},r.onerror=()=>n(r.error??Error(`Failed to encode image`)),r.readAsDataURL(e)}),de=async e=>{let t=await W(e),n=t.indexOf(`,`);return n>=0?t.slice(n+1):t},fe=(e,t)=>{let n=URL.createObjectURL(e),r=document.createElement(`a`);r.href=n,r.download=t,document.body.appendChild(r),r.click(),document.body.removeChild(r),window.setTimeout(()=>URL.revokeObjectURL(n),1e3)},G=async(e,t)=>{let n=await fetch(e,{signal:t,cache:`no-store`});if(!n.ok)throw Error(`Image fetch failed (${n.status})`);return n.blob()},pe=async(e,t=B)=>{if(!e.naturalWidth||!e.naturalHeight)return null;let n=e.currentSrc||e.src;if(n&&(/^(?:blob:|data:|openchamber-asset:)/i.test(n)||/^https?:/i.test(n)||/^\/api(?=\/|[?#]|$)/.test(n)))try{let e=await G(n);if(e.size>0)return e}catch{}try{let n=document.createElement(`canvas`);n.width=e.naturalWidth,n.height=e.naturalHeight;let r=n.getContext(`2d`);if(!r)return null;r.drawImage(e,0,0);let i=t.startsWith(`image/`)?t:B,a=await new Promise(e=>{n.toBlob(t=>e(t),i===`image/jpg`?`image/jpeg`:i)});return a&&a.size>0?a:null}catch{return null}},me=async(e,t)=>{let n=``;try{return n=await S(e,t??new AbortController().signal),await G(n,t)}finally{n&&C(n)}},he=async(e,t)=>{let n=e.effectiveDirectory??``,i=null;e.prefetchedBlob&&e.prefetchedBlob.size>0&&(i=e.prefetchedBlob);let a=e.displayUrl?.trim();if(!i&&a)try{i=await G(a,t)}catch{i=null}if(!i){let a=e.sourceUrl.trim();if(!a)throw Error(`Image source is empty`);if(/^(?:data|blob):/i.test(a)||/^https?:/i.test(a)||/^\/api(?=\/|[?#]|$)/.test(a))i=await G(a,t);else{let e=y(a,n);if(x(e))try{i=await me(e.path,t)}catch{let n=await r(`/api/fs/raw`,{method:`GET`,cache:`no-store`,query:{path:e.path},signal:t});if(!n.ok)throw Error(`Image source request failed with status ${n.status}`);i=await n.blob()}else i=await G(e.source,t)}}if(!i||i.size<=0)throw Error(`Image is empty`);let o=(e.mimeType||(i.type&&i.type.startsWith(`image/`)?i.type:``)||B).split(`;`)[0].trim()||B;return{blob:i,filename:U(e.filename,o),mimeType:o}},ge=()=>!s()||l===void 0?!1:l.isPluginAvailable(`OpenChamberMedia`),_e=async(e,t)=>{let{blob:r,filename:a,mimeType:o}=await he(e,t);if(ge()){let e=await de(r);return await V.saveImage({dataBase64:e,mimeType:o,filename:a}),`saved`}if(n()){let e=i()?.vscode;if(e?.saveImage){let t=await W(r);return await e.saveImage({fileName:a,dataUrl:t}),`saved`}}return fe(r,a),`downloaded`},ve=e=>e.replace(/&/g,`&`).replace(/</g,`<`).replace(/>/g,`>`).replace(/"/g,`"`).replace(/'/g,`'`),ye=e=>e?Object.entries(e).map(([e,t])=>t==null?``:`${e.startsWith(`--`)?e:e.replace(/[A-Z]/g,e=>`-${e.toLowerCase()}`)}:${typeof t==`number`?`${t}px`:t};`).join(``):``,K=(e,t,n)=>{let r=e.querySelector(`pre`);r&&(r.style.margin=`0`,r.style.background=`transparent`,r.style.whiteSpace=t?`pre-wrap`:`pre`,t&&(r.style.wordBreak=`break-word`,r.style.overflowWrap=`break-word`));let i=e.querySelector(`code`);if(i){let e=ye(n);e&&i.setAttribute(`style`,`${i.getAttribute(`style`)??``}${e}`)}},be=e=>`<pre><code>${ve(e)}</code></pre>`,xe=e=>{let t=(0,k.c)(21),{code:n,language:r,className:i,style:a,codeStyle:o,wrap:s}=e,c=s!==void 0&&s,{currentTheme:l}=v(),u=O.useRef(null),d;t[0]===l?d=t[1]:(d=b(l),t[0]=l,t[1]=d);let p=d,m,h;t[2]!==n||t[3]!==o||t[4]!==c?(m=()=>{let e=u.current;e&&(e.innerHTML=be(n),K(e,c,o))},h=[n,c,o],t[2]=n,t[3]=o,t[4]=c,t[5]=m,t[6]=h):(m=t[5],h=t[6]),O.useLayoutEffect(m,h);let g,_;t[7]!==n||t[8]!==o||t[9]!==r||t[10]!==c?(g=()=>{let e=u.current;if(!e)return;let t=!0,i=new AbortController;return D(n,(r||`text`).toLowerCase(),{signal:i.signal,priority:`visible`}).then(n=>{!t||!e||!n||(e.innerHTML=n,K(e,c,o))}),()=>{t=!1,i.abort()}},_=[n,r,c,o],t[7]=n,t[8]=o,t[9]=r,t[10]=c,t[11]=g,t[12]=_):(g=t[11],_=t[12]),O.useEffect(g,_);let y;t[13]===i?y=t[14]:(y=f(`typography-code`,i),t[13]=i,t[14]=y);let x=p,S;t[15]!==a||t[16]!==x?(S={...x,...a},t[15]=a,t[16]=x,t[17]=S):S=t[17];let C;return t[18]!==y||t[19]!==S?(C=(0,A.jsx)(`div`,{ref:u,className:y,style:S}),t[18]=y,t[19]=S,t[20]=C):C=t[20],C},Se=e=>{let t=e.replace(/^<file>\s*\n?/,``).replace(/\n?<\/file>\s*$/,``);return t=t.replace(/^\s*\d{5}\|\s?/gm,``),t.trim()},Ce=(e,t=``)=>{if(typeof e==`string`)return e;if(e==null)return t;if(typeof e==`number`||typeof e==`boolean`||typeof e==`bigint`)return String(e);try{return JSON.stringify(e)}catch{return t}},we=e=>e?e.includes(`<diagnostics`)||e.includes(`<file_diagnostics>`)||e.includes(`LSP errors detected`)||e.includes(`This file has errors`):!1,Te=e=>e?e.replace(/\n{0,2}LSP errors detected[\s\S]*?<diagnostics[^>]*>[\s\S]*?<\/diagnostics>/g,``).replace(/\n{0,2}This file has errors[\s\S]*?<\/file_diagnostics>/g,``).replace(/<diagnostics[^>]*>[\s\S]*?<\/diagnostics>/g,``).replace(/<file_diagnostics>[\s\S]*?<\/file_diagnostics>/g,``).trim():``,Ee=(e,t)=>!e||typeof e!=`object`?String(e):T(e,t||``),q=e=>{if(typeof e==`string`){let t=e.trim();return t.length>0?t:void 0}if(e&&typeof e==`object`){let t=e.patch;if(typeof t==`string`){let e=t.trim();return e.length>0?e:void 0}}},De=e=>{if(!e||typeof e!=`object`)return;let t=q(e.patch)??q(e.diff);if(t)return t;let n=Array.isArray(e.files)?e.files:[];for(let e of n){if(!e||typeof e!=`object`)continue;let t=q(e.patch)??q(e.diff);if(t)return t}},Oe=e=>{if(!e||typeof e!=`string`)return{data:null,isJson:!1};let t=e.trim();if(!t.startsWith(`{`)&&!t.startsWith(`[`)||!t.endsWith(`}`)&&!t.endsWith(`]`)||t.length<2)return{data:null,isJson:!1};try{let e=JSON.parse(t);return typeof e==`object`&&e?{data:e,isJson:!0}:{data:null,isJson:!1}}catch{return{data:null,isJson:!1}}},ke=(e,t,n)=>{let r=Se(e);if((t===`edit`||t===`multiedit`||t===`write`||t===`apply_patch`)&&we(r)&&(r=Te(r)),(t===`edit`||t===`multiedit`||t===`apply_patch`)&&r.trim().length===0){let e=De(n);if(e)return e}return r},Ae=e=>{let t=e.match(/<type>(file|directory)<\/type>/i)?.[1]?.toLowerCase()??`unknown`,n=(e.match(/<content>([\s\S]*?)<\/content>/i)?.[1]??e).replace(/\r\n/g,`
|
|
1
|
+
import{o as e}from"./rolldown-runtime-C0FnF6B9.js";import{_ as t}from"./useUIStore-NfqK-HA7.js";import{$t as n,kn as r,xn as i}from"./persistence-vZ7H8WKh.js";import{nt as a,rt as o}from"./vendor-base-ui-CnHfUmDN.js";import{n as s}from"./platform-CTaznShj.js";import{a as c,n as l}from"./vendor-aparajita-capacitor-secure-storage-CjQdwfjS.js";import{n as u}from"./vendor-react-DLPElpoQ.js";import{n as d}from"./clipboard-BfgFef1i.js";import{t as f}from"./utils-C2P0wcWO.js";import{n as p}from"./Icon-D-X70irR.js";import{t as m}from"./button-CwLFtUNT.js";import{i as h,n as g,t as _}from"./tooltip-CaCe-GAm.js";import{n as v}from"./useThemeSystem-DMzWVJaW.js";import{c as y,n as b,o as x,r as S,s as C}from"./markdownTheme-Bl0Sy0Lf.js";import{i as w}from"./appThemeRegistry-C7KndtrT.js";import{d as T,n as E,t as D,u as ee}from"./markdown-worker-N9d_Z-7s.js";import{t as te}from"./vendor-tanstack-react-virtual-tlDgH6PG.js";var O=e(o(),1),k=u(),A=a(),ne=`w-[min(30rem,calc(100cqw-1rem))] min-w-[280px] max-w-full overflow-hidden rounded-xl shadow-[inset_0_1px_0_0_rgba(255,255,255,0.8),inset_0_0_0_1px_rgba(0,0,0,0.04),0_0_0_1px_rgba(0,0,0,0.10),0_1px_2px_-0.5px_rgba(0,0,0,0.08),0_4px_8px_-2px_rgba(0,0,0,0.08),0_12px_20px_-4px_rgba(0,0,0,0.08)] dark:shadow-[inset_0_1px_0_0_rgba(255,255,255,0.12),inset_0_0_0_1px_rgba(255,255,255,0.08),0_0_0_1px_rgba(0,0,0,0.36),0_1px_1px_-0.5px_rgba(0,0,0,0.22),0_3px_3px_-1.5px_rgba(0,0,0,0.20),0_6px_6px_-3px_rgba(0,0,0,0.16)]`,j={maxWidth:`min(28rem, calc(100cqw - 4ch))`,backgroundColor:`var(--surface-elevated)`,color:`var(--surface-elevated-foreground)`},M=`flex items-center justify-between gap-3 border-b border-[var(--surface-subtle)] px-3 py-2.5`,N=`text-xs font-medium leading-4 text-foreground md:text-[0.8125rem] md:leading-5`,re=`text-xs tabular-nums leading-4 text-muted-foreground md:text-[0.8125rem] md:leading-5`,P=`m-0 list-none divide-y divide-[var(--surface-subtle)] p-0`,F=`${P} max-h-[min(22rem,50vh)] overflow-y-auto`,ie=`${P} w-full`,ae={className:`p-0 rounded-none`,maxHeightClass:`max-h-[46vh]`,disableHorizontal:!0},I=`px-2.5 py-1.5 text-xs leading-4 md:py-2 md:text-[0.8125rem] md:leading-5`,oe=`flex min-w-0 items-center gap-1 text-xs leading-4 text-muted-foreground md:gap-1.5 md:text-[0.8125rem] md:leading-5`,se=`min-w-0 truncate text-xs leading-4 text-foreground md:text-[0.8125rem] md:leading-5`,ce=`inline-flex shrink-0 items-center gap-1 text-xs leading-4 tabular-nums text-muted-foreground md:text-[0.8125rem] md:leading-5`,le=`h-3 w-3 shrink-0 md:h-3.5 md:w-3.5`,ue={in_progress:`text-foreground`,pending:`text-foreground`,completed:`text-muted-foreground line-through`,cancelled:`text-muted-foreground line-through`},L={in_progress:`chat.statusRow.todo.status.inProgress`,pending:`chat.statusRow.todo.status.pending`,completed:`chat.statusRow.todo.status.completed`,cancelled:`chat.statusRow.todo.status.cancelled`},R=e=>{let t=(0,k.c)(26),{todo:n,isActive:r,activeRef:i}=e,{t:a}=d(),o=z.has(n.status)?n.status:`pending`,s=L[o],c;t[0]!==a||t[1]!==s?(c=a(s),t[0]=a,t[1]=s,t[2]=c):c=t[2];let l=c,u;t[3]===o?u=t[4]:(u=o===`in_progress`?(0,A.jsx)(p,{name:`record-circle`,className:`h-3.5 w-3.5 text-[var(--status-info)]`,"aria-hidden":`true`}):o===`completed`?(0,A.jsx)(p,{name:`checkbox-circle`,className:`h-3.5 w-3.5 text-[var(--status-success)]`,"aria-hidden":`true`}):(0,A.jsx)(p,{name:`time`,className:`h-3.5 w-3.5 text-muted-foreground`,"aria-hidden":`true`}),t[3]=o,t[4]=u);let m=u,v=r?`step`:void 0,y=r&&`bg-[var(--surface-muted)] before:absolute before:inset-y-2 before:left-0 before:w-0.5 before:rounded-full before:bg-[var(--status-info)]`,b;t[5]===y?b=t[6]:(b=f(`group relative grid min-w-0 grid-cols-[1rem_minmax(0,1fr)] items-start gap-2.5`,I,y),t[5]=y,t[6]=b);let x;t[7]!==m||t[8]!==l?(x=(0,A.jsx)(h,{asChild:!0,children:(0,A.jsx)(`span`,{className:`flex size-4 items-center justify-center`,"aria-label":l,children:m})}),t[7]=m,t[8]=l,t[9]=x):x=t[9];let S;t[10]===l?S=t[11]:(S=(0,A.jsx)(g,{side:`left`,sideOffset:6,children:l}),t[10]=l,t[11]=S);let C;t[12]!==x||t[13]!==S?(C=(0,A.jsxs)(_,{children:[x,S]}),t[12]=x,t[13]=S,t[14]=C):C=t[14];let w=ue[o],T;t[15]===w?T=t[16]:(T=f(`block whitespace-normal break-words`,w),t[15]=w,t[16]=T);let E;t[17]!==T||t[18]!==n.content?(E=(0,A.jsx)(`span`,{className:`min-w-0 flex-1`,children:(0,A.jsx)(`span`,{className:T,children:n.content})}),t[17]=T,t[18]=n.content,t[19]=E):E=t[19];let D;return t[20]!==i||t[21]!==E||t[22]!==v||t[23]!==b||t[24]!==C?(D=(0,A.jsxs)(`li`,{ref:i,"aria-current":v,className:b,children:[C,E]}),t[20]=i,t[21]=E,t[22]=v,t[23]=b,t[24]=C,t[25]=D):D=t[25],D},z=new Set([`in_progress`,`pending`,`completed`,`cancelled`]),B=`image/png`,V=c(`OpenChamberMedia`),H=e=>{let t=e.toLowerCase().split(`;`)[0]?.trim()||B;if(t===`image/jpeg`||t===`image/jpg`)return`jpg`;if(t===`image/webp`)return`webp`;if(t===`image/gif`)return`gif`;if(t===`image/svg+xml`)return`svg`;if(t===`image/png`)return`png`;let n=t.split(`/`)[1];return n&&/^[a-z0-9.+-]+$/i.test(n)?n:`png`},U=(e,t)=>{let n=`image.${H(t)}`,r=(((e||``).trim()||n).split(/[\\/]/).pop()||n).replace(/[^\w.\- ()[\]]+/g,`_`).replace(/^\.+/,``);return r?/\.[a-z0-9]{1,8}$/i.test(r)?r:`${r}.${H(t)}`:n},W=e=>new Promise((t,n)=>{let r=new FileReader;r.onload=()=>{if(typeof r.result==`string`){t(r.result);return}n(Error(`Failed to encode image`))},r.onerror=()=>n(r.error??Error(`Failed to encode image`)),r.readAsDataURL(e)}),de=async e=>{let t=await W(e),n=t.indexOf(`,`);return n>=0?t.slice(n+1):t},fe=(e,t)=>{let n=URL.createObjectURL(e),r=document.createElement(`a`);r.href=n,r.download=t,document.body.appendChild(r),r.click(),document.body.removeChild(r),window.setTimeout(()=>URL.revokeObjectURL(n),1e3)},G=async(e,t)=>{let n=await fetch(e,{signal:t,cache:`no-store`});if(!n.ok)throw Error(`Image fetch failed (${n.status})`);return n.blob()},pe=async(e,t=B)=>{if(!e.naturalWidth||!e.naturalHeight)return null;let n=e.currentSrc||e.src;if(n&&(/^(?:blob:|data:|openchamber-asset:)/i.test(n)||/^https?:/i.test(n)||/^\/api(?=\/|[?#]|$)/.test(n)))try{let e=await G(n);if(e.size>0)return e}catch{}try{let n=document.createElement(`canvas`);n.width=e.naturalWidth,n.height=e.naturalHeight;let r=n.getContext(`2d`);if(!r)return null;r.drawImage(e,0,0);let i=t.startsWith(`image/`)?t:B,a=await new Promise(e=>{n.toBlob(t=>e(t),i===`image/jpg`?`image/jpeg`:i)});return a&&a.size>0?a:null}catch{return null}},me=async(e,t)=>{let n=``;try{return n=await S(e,t??new AbortController().signal),await G(n,t)}finally{n&&C(n)}},he=async(e,t)=>{let n=e.effectiveDirectory??``,i=null;e.prefetchedBlob&&e.prefetchedBlob.size>0&&(i=e.prefetchedBlob);let a=e.displayUrl?.trim();if(!i&&a)try{i=await G(a,t)}catch{i=null}if(!i){let a=e.sourceUrl.trim();if(!a)throw Error(`Image source is empty`);if(/^(?:data|blob):/i.test(a)||/^https?:/i.test(a)||/^\/api(?=\/|[?#]|$)/.test(a))i=await G(a,t);else{let e=y(a,n);if(x(e))try{i=await me(e.path,t)}catch{let n=await r(`/api/fs/raw`,{method:`GET`,cache:`no-store`,query:{path:e.path},signal:t});if(!n.ok)throw Error(`Image source request failed with status ${n.status}`);i=await n.blob()}else i=await G(e.source,t)}}if(!i||i.size<=0)throw Error(`Image is empty`);let o=(e.mimeType||(i.type&&i.type.startsWith(`image/`)?i.type:``)||B).split(`;`)[0].trim()||B;return{blob:i,filename:U(e.filename,o),mimeType:o}},ge=()=>!s()||l===void 0?!1:l.isPluginAvailable(`OpenChamberMedia`),_e=async(e,t)=>{let{blob:r,filename:a,mimeType:o}=await he(e,t);if(ge()){let e=await de(r);return await V.saveImage({dataBase64:e,mimeType:o,filename:a}),`saved`}if(n()){let e=i()?.vscode;if(e?.saveImage){let t=await W(r);return await e.saveImage({fileName:a,dataUrl:t}),`saved`}}return fe(r,a),`downloaded`},ve=e=>e.replace(/&/g,`&`).replace(/</g,`<`).replace(/>/g,`>`).replace(/"/g,`"`).replace(/'/g,`'`),ye=e=>e?Object.entries(e).map(([e,t])=>t==null?``:`${e.startsWith(`--`)?e:e.replace(/[A-Z]/g,e=>`-${e.toLowerCase()}`)}:${typeof t==`number`?`${t}px`:t};`).join(``):``,K=(e,t,n)=>{let r=e.querySelector(`pre`);r&&(r.style.margin=`0`,r.style.background=`transparent`,r.style.whiteSpace=t?`pre-wrap`:`pre`,t&&(r.style.wordBreak=`break-word`,r.style.overflowWrap=`break-word`));let i=e.querySelector(`code`);if(i){let e=ye(n);e&&i.setAttribute(`style`,`${i.getAttribute(`style`)??``}${e}`)}},be=e=>`<pre><code>${ve(e)}</code></pre>`,xe=e=>{let t=(0,k.c)(21),{code:n,language:r,className:i,style:a,codeStyle:o,wrap:s}=e,c=s!==void 0&&s,{currentTheme:l}=v(),u=O.useRef(null),d;t[0]===l?d=t[1]:(d=b(l),t[0]=l,t[1]=d);let p=d,m,h;t[2]!==n||t[3]!==o||t[4]!==c?(m=()=>{let e=u.current;e&&(e.innerHTML=be(n),K(e,c,o))},h=[n,c,o],t[2]=n,t[3]=o,t[4]=c,t[5]=m,t[6]=h):(m=t[5],h=t[6]),O.useLayoutEffect(m,h);let g,_;t[7]!==n||t[8]!==o||t[9]!==r||t[10]!==c?(g=()=>{let e=u.current;if(!e)return;let t=!0,i=new AbortController;return D(n,(r||`text`).toLowerCase(),{signal:i.signal,priority:`visible`}).then(n=>{!t||!e||!n||(e.innerHTML=n,K(e,c,o))}),()=>{t=!1,i.abort()}},_=[n,r,c,o],t[7]=n,t[8]=o,t[9]=r,t[10]=c,t[11]=g,t[12]=_):(g=t[11],_=t[12]),O.useEffect(g,_);let y;t[13]===i?y=t[14]:(y=f(`typography-code`,i),t[13]=i,t[14]=y);let x=p,S;t[15]!==a||t[16]!==x?(S={...x,...a},t[15]=a,t[16]=x,t[17]=S):S=t[17];let C;return t[18]!==y||t[19]!==S?(C=(0,A.jsx)(`div`,{ref:u,className:y,style:S}),t[18]=y,t[19]=S,t[20]=C):C=t[20],C},Se=e=>{let t=e.replace(/^<file>\s*\n?/,``).replace(/\n?<\/file>\s*$/,``);return t=t.replace(/^\s*\d{5}\|\s?/gm,``),t.trim()},Ce=(e,t=``)=>{if(typeof e==`string`)return e;if(e==null)return t;if(typeof e==`number`||typeof e==`boolean`||typeof e==`bigint`)return String(e);try{return JSON.stringify(e)}catch{return t}},we=e=>e?e.includes(`<diagnostics`)||e.includes(`<file_diagnostics>`)||e.includes(`LSP errors detected`)||e.includes(`This file has errors`):!1,Te=e=>e?e.replace(/\n{0,2}LSP errors detected[\s\S]*?<diagnostics[^>]*>[\s\S]*?<\/diagnostics>/g,``).replace(/\n{0,2}This file has errors[\s\S]*?<\/file_diagnostics>/g,``).replace(/<diagnostics[^>]*>[\s\S]*?<\/diagnostics>/g,``).replace(/<file_diagnostics>[\s\S]*?<\/file_diagnostics>/g,``).trim():``,Ee=(e,t)=>!e||typeof e!=`object`?String(e):T(e,t||``),q=e=>{if(typeof e==`string`){let t=e.trim();return t.length>0?t:void 0}if(e&&typeof e==`object`){let t=e.patch;if(typeof t==`string`){let e=t.trim();return e.length>0?e:void 0}}},De=e=>{if(!e||typeof e!=`object`)return;let t=q(e.patch)??q(e.diff);if(t)return t;let n=Array.isArray(e.files)?e.files:[];for(let e of n){if(!e||typeof e!=`object`)continue;let t=q(e.patch)??q(e.diff);if(t)return t}},Oe=e=>{if(!e||typeof e!=`string`)return{data:null,isJson:!1};let t=e.trim();if(!t.startsWith(`{`)&&!t.startsWith(`[`)||!t.endsWith(`}`)&&!t.endsWith(`]`)||t.length<2)return{data:null,isJson:!1};try{let e=JSON.parse(t);return typeof e==`object`&&e?{data:e,isJson:!0}:{data:null,isJson:!1}}catch{return{data:null,isJson:!1}}},ke=(e,t,n)=>{let r=Se(e);if((t===`edit`||t===`multiedit`||t===`write`||t===`apply_patch`)&&we(r)&&(r=Te(r)),(t===`edit`||t===`multiedit`||t===`apply_patch`)&&r.trim().length===0){let e=De(n);if(e)return e}return r},Ae=e=>{let t=e.match(/<type>(file|directory)<\/type>/i)?.[1]?.toLowerCase()??`unknown`,n=(e.match(/<content>([\s\S]*?)<\/content>/i)?.[1]??e).replace(/\r\n/g,`
|
|
2
2
|
`).split(`
|
|
3
3
|
`),r=e=>/\(\s*File has more lines\..*offset.*\)/i.test(e.trim());return{type:t,lines:n.map(e=>{let n=e.trim(),i=n.startsWith(`(`)&&n.endsWith(`)`)||r(n);if(t!==`directory`){let t=e.match(/^(\d+):\s?(.*)$/);if(t){let e=t[2],n=e.trim(),i=n.startsWith(`(`)&&n.endsWith(`)`)||r(n);return{lineNumber:i?null:Number(t[1]),text:e,isInfo:i}}}return{lineNumber:null,text:e,isInfo:i}}).filter((e,t,n)=>{if(e.text.trim().length>0)return!0;let r=n[t-1],i=n[t+1],a=!!(r?.isInfo||i?.isInfo),o=e.lineNumber!==null;return!(a&&o)})}},je=(e,n)=>{try{let r=e.trim().split(`
|
|
4
4
|
`).filter(Boolean);if(r.length===0)return null;let i=[];return r.forEach(e=>{let t=e.match(/^(\s*)(.+)$/);if(t){let[,e,n]=t,r=Math.floor(e.length/2),a=!n.endsWith(`/`);i.push({name:n.replace(/\/$/,``),depth:r,isFile:a})}}),(0,A.jsx)(`div`,{className:f(`w-full min-w-0 font-mono space-y-0.5`,n?.unstyled?null:`p-3 bg-muted/20 rounded-xl border border-border/30`),style:t.tool.popup,children:i.map((e,t)=>(0,A.jsx)(`div`,{className:`min-w-0`,style:{paddingLeft:`${e.depth*20}px`},children:e.isFile?(0,A.jsx)(`span`,{className:`text-foreground/90 block truncate`,children:e.name}):(0,A.jsxs)(`span`,{className:`font-semibold text-foreground block truncate`,children:[e.name,`/`]})},t))})}catch{return null}},Me={backgroundColor:`var(--status-info)`,opacity:.6},Ne=(e,n,r)=>{try{let i=e.trim().split(`
|
package/dist/index.html
CHANGED
|
@@ -552,7 +552,7 @@
|
|
|
552
552
|
opacity: 0.72;
|
|
553
553
|
}
|
|
554
554
|
</style>
|
|
555
|
-
<script type="module" crossorigin src="/assets/main-
|
|
555
|
+
<script type="module" crossorigin src="/assets/main-Bk1Xkd1S.js"></script>
|
|
556
556
|
<link rel="modulepreload" crossorigin href="/assets/rolldown-runtime-C0FnF6B9.js">
|
|
557
557
|
<link rel="modulepreload" crossorigin href="/assets/vendor-base-ui-CnHfUmDN.js">
|
|
558
558
|
<link rel="modulepreload" crossorigin href="/assets/vendor-zustand-B4dlGEM2.js">
|
|
@@ -569,7 +569,7 @@
|
|
|
569
569
|
<link rel="modulepreload" crossorigin href="/assets/terminalApi-KDUc5mh2.js">
|
|
570
570
|
<link rel="modulepreload" crossorigin href="/assets/types-BuiqMmh_.js">
|
|
571
571
|
<link rel="modulepreload" crossorigin href="/assets/capgoAdapter-DCowZ2ab.js">
|
|
572
|
-
<link rel="modulepreload" crossorigin href="/assets/runtimeConfig-
|
|
572
|
+
<link rel="modulepreload" crossorigin href="/assets/runtimeConfig-VyMtYAl_.js">
|
|
573
573
|
<link rel="stylesheet" crossorigin href="/assets/src-Dbdlm5x1.css">
|
|
574
574
|
</head>
|
|
575
575
|
<body class="h-full bg-background text-foreground">
|
package/dist/mini-chat.html
CHANGED
|
@@ -74,7 +74,7 @@
|
|
|
74
74
|
}
|
|
75
75
|
</style>
|
|
76
76
|
|
|
77
|
-
<script type="module" crossorigin src="/assets/miniChat-
|
|
77
|
+
<script type="module" crossorigin src="/assets/miniChat-toYPrHwe.js"></script>
|
|
78
78
|
<link rel="modulepreload" crossorigin href="/assets/rolldown-runtime-C0FnF6B9.js">
|
|
79
79
|
<link rel="modulepreload" crossorigin href="/assets/vendor-base-ui-CnHfUmDN.js">
|
|
80
80
|
<link rel="modulepreload" crossorigin href="/assets/vendor-zustand-B4dlGEM2.js">
|
|
@@ -91,7 +91,7 @@
|
|
|
91
91
|
<link rel="modulepreload" crossorigin href="/assets/terminalApi-KDUc5mh2.js">
|
|
92
92
|
<link rel="modulepreload" crossorigin href="/assets/types-BuiqMmh_.js">
|
|
93
93
|
<link rel="modulepreload" crossorigin href="/assets/capgoAdapter-DCowZ2ab.js">
|
|
94
|
-
<link rel="modulepreload" crossorigin href="/assets/runtimeConfig-
|
|
94
|
+
<link rel="modulepreload" crossorigin href="/assets/runtimeConfig-VyMtYAl_.js">
|
|
95
95
|
<link rel="stylesheet" crossorigin href="/assets/src-Dbdlm5x1.css">
|
|
96
96
|
</head>
|
|
97
97
|
<body class="h-full bg-background text-foreground">
|
package/dist/mobile.html
CHANGED
|
@@ -63,7 +63,7 @@
|
|
|
63
63
|
})();
|
|
64
64
|
</script>
|
|
65
65
|
|
|
66
|
-
<script type="module" crossorigin src="/assets/mobile-
|
|
66
|
+
<script type="module" crossorigin src="/assets/mobile-Cbb8zwcX.js"></script>
|
|
67
67
|
<link rel="modulepreload" crossorigin href="/assets/rolldown-runtime-C0FnF6B9.js">
|
|
68
68
|
<link rel="modulepreload" crossorigin href="/assets/vendor-base-ui-CnHfUmDN.js">
|
|
69
69
|
<link rel="modulepreload" crossorigin href="/assets/vendor-zustand-B4dlGEM2.js">
|
|
@@ -80,7 +80,7 @@
|
|
|
80
80
|
<link rel="modulepreload" crossorigin href="/assets/terminalApi-KDUc5mh2.js">
|
|
81
81
|
<link rel="modulepreload" crossorigin href="/assets/types-BuiqMmh_.js">
|
|
82
82
|
<link rel="modulepreload" crossorigin href="/assets/capgoAdapter-DCowZ2ab.js">
|
|
83
|
-
<link rel="modulepreload" crossorigin href="/assets/runtimeConfig-
|
|
83
|
+
<link rel="modulepreload" crossorigin href="/assets/runtimeConfig-VyMtYAl_.js">
|
|
84
84
|
<link rel="stylesheet" crossorigin href="/assets/src-Dbdlm5x1.css">
|
|
85
85
|
</head>
|
|
86
86
|
<body class="h-full bg-background text-foreground">
|
package/package.json
CHANGED
|
@@ -14,6 +14,7 @@ import {
|
|
|
14
14
|
assertTargetCapability,
|
|
15
15
|
buildDefaultSyncSelections,
|
|
16
16
|
buildRemoteSyncFinalizeScript,
|
|
17
|
+
buildRemoteSyncInventoryScript,
|
|
17
18
|
buildRemoteSyncPrepareScript,
|
|
18
19
|
createSshSyncTarget,
|
|
19
20
|
filterPlanBySelections,
|
|
@@ -195,3 +196,54 @@ describe('generational prepare backups', () => {
|
|
|
195
196
|
})).toThrow();
|
|
196
197
|
});
|
|
197
198
|
});
|
|
199
|
+
|
|
200
|
+
describe('remote inventory script', () => {
|
|
201
|
+
it('emits SYNC_INVENTORY as valid JSON with quoted path values (regression: bare quotes broke JSON.parse)', async () => {
|
|
202
|
+
const home = await makeTempDir();
|
|
203
|
+
const configDir = path.join(home, '.config', 'opencode');
|
|
204
|
+
await fsp.mkdir(path.join(configDir, 'agents'), { recursive: true });
|
|
205
|
+
await fsp.writeFile(path.join(configDir, 'opencode.jsonc'), '{"a":1}\n');
|
|
206
|
+
await fsp.writeFile(path.join(configDir, 'AGENTS.md'), '# agents\n');
|
|
207
|
+
await fsp.writeFile(path.join(configDir, 'agents', 'helper.md'), 'x'.repeat(7));
|
|
208
|
+
await fsp.mkdir(path.join(home, '.local', 'share', 'opencode'), { recursive: true });
|
|
209
|
+
await fsp.writeFile(path.join(home, '.local', 'share', 'opencode', 'auth.json'), '{}\n');
|
|
210
|
+
|
|
211
|
+
const stdout = execFileSync('sh', ['-c', buildRemoteSyncInventoryScript()], {
|
|
212
|
+
env: { ...process.env, HOME: home },
|
|
213
|
+
});
|
|
214
|
+
const line = stdout.toString().split(/\r?\n/).find((entry) => entry.startsWith('SYNC_INVENTORY='));
|
|
215
|
+
expect(line).toBeTruthy();
|
|
216
|
+
|
|
217
|
+
// This threw SyntaxError ("Unexpected token") before path values were
|
|
218
|
+
// escaped for the surrounding shell double-quoted string.
|
|
219
|
+
const inventory = JSON.parse(line.slice('SYNC_INVENTORY='.length));
|
|
220
|
+
const files = inventory.files.map((entry) => entry.path);
|
|
221
|
+
expect(files).toContain('opencode.jsonc');
|
|
222
|
+
expect(files).toContain('AGENTS.md');
|
|
223
|
+
const directories = inventory.directories.map((entry) => entry.path);
|
|
224
|
+
expect(directories).toContain('agents');
|
|
225
|
+
expect(inventory.authFile).toEqual({ bytes: 3 });
|
|
226
|
+
for (const entry of inventory.files) {
|
|
227
|
+
expect(typeof entry.path).toBe('string');
|
|
228
|
+
expect(typeof entry.bytes).toBe('number');
|
|
229
|
+
}
|
|
230
|
+
for (const entry of inventory.directories) {
|
|
231
|
+
expect(typeof entry.path).toBe('string');
|
|
232
|
+
expect(typeof entry.fileCount).toBe('number');
|
|
233
|
+
expect(typeof entry.bytes).toBe('number');
|
|
234
|
+
}
|
|
235
|
+
});
|
|
236
|
+
|
|
237
|
+
it('still parses when nothing exists on the remote', async () => {
|
|
238
|
+
const home = await makeTempDir();
|
|
239
|
+
const stdout = execFileSync('sh', ['-c', buildRemoteSyncInventoryScript()], {
|
|
240
|
+
env: { ...process.env, HOME: home },
|
|
241
|
+
});
|
|
242
|
+
const line = stdout.toString().split(/\r?\n/).find((entry) => entry.startsWith('SYNC_INVENTORY='));
|
|
243
|
+
const inventory = JSON.parse(line.slice('SYNC_INVENTORY='.length));
|
|
244
|
+
expect(inventory.files).toEqual([]);
|
|
245
|
+
expect(inventory.directories).toEqual([]);
|
|
246
|
+
expect(inventory.agentsRoot).toBeNull();
|
|
247
|
+
expect(inventory.authFile).toBeNull();
|
|
248
|
+
});
|
|
249
|
+
});
|
|
@@ -12,6 +12,14 @@ import {
|
|
|
12
12
|
|
|
13
13
|
const shellQuote = (value) => `'${String(value).replace(/'/g, `'\\''`)}'`;
|
|
14
14
|
|
|
15
|
+
/**
|
|
16
|
+
* JSON.stringify yields bare double quotes, which terminate the surrounding
|
|
17
|
+
* shell double-quoted string in inventory lines. Escape them so the assembled
|
|
18
|
+
* SYNC_INVENTORY payload stays valid JSON after sh evaluation.
|
|
19
|
+
* @param {string} value
|
|
20
|
+
*/
|
|
21
|
+
const jsonShellEscape = (value) => JSON.stringify(value).replace(/"/g, '\\"');
|
|
22
|
+
|
|
15
23
|
/**
|
|
16
24
|
* Sanitize syncRunId for use as a single path segment under backup roots.
|
|
17
25
|
* @param {string} syncRunId
|
|
@@ -202,7 +210,7 @@ export const buildRemoteSyncInventoryScript = () => {
|
|
|
202
210
|
const quoted = shellQuote(rel);
|
|
203
211
|
lines.push(`if [ -f "$CFG"/${quoted} ]; then`);
|
|
204
212
|
lines.push(` BYTES="$(wc -c < "$CFG"/${quoted} | tr -d ' ')"`);
|
|
205
|
-
lines.push(` FILES="$FILES{\\"path\\":${
|
|
213
|
+
lines.push(` FILES="$FILES{\\"path\\":${jsonShellEscape(rel)},\\"bytes\\":$BYTES},"`);
|
|
206
214
|
lines.push('fi');
|
|
207
215
|
}
|
|
208
216
|
for (const rel of dirPaths) {
|
|
@@ -210,7 +218,7 @@ export const buildRemoteSyncInventoryScript = () => {
|
|
|
210
218
|
lines.push(`if [ -d "$CFG"/${quoted} ]; then`);
|
|
211
219
|
lines.push(` COUNT="$(find "$CFG"/${quoted} -type f ! -path '*/node_modules/*' ! -name '*.backup' 2>/dev/null | wc -l | tr -d ' ')"`);
|
|
212
220
|
lines.push(` BYTES="$(find "$CFG"/${quoted} -type f ! -path '*/node_modules/*' ! -name '*.backup' -exec wc -c {} + 2>/dev/null | awk 'END{print $1+0}')"`);
|
|
213
|
-
lines.push(` DIRS="$DIRS{\\"path\\":${
|
|
221
|
+
lines.push(` DIRS="$DIRS{\\"path\\":${jsonShellEscape(rel)},\\"fileCount\\":$COUNT,\\"bytes\\":$BYTES},"`);
|
|
214
222
|
lines.push('fi');
|
|
215
223
|
}
|
|
216
224
|
lines.push('AGENTS="null"');
|
|
@@ -14,8 +14,10 @@ under `metadata.openchamber.assist`.
|
|
|
14
14
|
`retry` status or a user `message.updated` clears it (the "1 minute of
|
|
15
15
|
quiet" rule).
|
|
16
16
|
3. On fire: fetch the session (skip sub-agent sessions with `parentID`),
|
|
17
|
-
|
|
18
|
-
|
|
17
|
+
then build a trimmed excerpt via `buildAssistTranscript`: the LAST text
|
|
18
|
+
block of the last assistant message (earlier blocks, reasoning, and tool
|
|
19
|
+
output are excluded) plus the latest 3 real user messages (synthetic
|
|
20
|
+
hidden-instruction parts never count). The excerpt is sent to
|
|
19
21
|
`generateSmallModelText` with the
|
|
20
22
|
session's own provider/model taken from the last assistant message — so
|
|
21
23
|
the utility call spends the same subscription as the conversation.
|
|
@@ -33,6 +33,8 @@ const isSessionRecapEnabled = () => {
|
|
|
33
33
|
|
|
34
34
|
const IDLE_QUIET_MS = 60_000;
|
|
35
35
|
const TRANSCRIPT_MESSAGE_LIMIT = 12;
|
|
36
|
+
/** Latest real user messages fed to the recap prompt. */
|
|
37
|
+
const TRANSCRIPT_USER_MESSAGE_LIMIT = 3;
|
|
36
38
|
const TRANSCRIPT_PART_CHAR_LIMIT = 6_000;
|
|
37
39
|
const RECAP_CHAR_LIMIT = 320;
|
|
38
40
|
const FETCH_TIMEOUT_MS = 5_000;
|
|
@@ -92,13 +94,63 @@ const extractUserMessage = (payload) => {
|
|
|
92
94
|
};
|
|
93
95
|
};
|
|
94
96
|
|
|
95
|
-
|
|
97
|
+
/** Real (non-synthetic) text parts of a message — hidden instructions excluded. */
|
|
98
|
+
const realTextParts = (message) => {
|
|
96
99
|
const parts = Array.isArray(message?.parts) ? message.parts : [];
|
|
97
100
|
return parts
|
|
98
|
-
.
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
101
|
+
.filter((part) => part?.type === 'text'
|
|
102
|
+
&& typeof part.text === 'string'
|
|
103
|
+
&& part.text.trim().length > 0
|
|
104
|
+
&& part.synthetic !== true)
|
|
105
|
+
.map((part) => part.text);
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
/** Body text of a message: only its LAST text block, char-clamped. */
|
|
109
|
+
const lastMessageText = (message) => {
|
|
110
|
+
const texts = realTextParts(message);
|
|
111
|
+
return texts.length > 0 ? texts[texts.length - 1].slice(0, TRANSCRIPT_PART_CHAR_LIMIT) : '';
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Build the recap transcript from a bounded recent-message window.
|
|
116
|
+
* - Assistant: only the LAST text block of the last assistant message —
|
|
117
|
+
* earlier blocks, reasoning, and tool output are token waste for a
|
|
118
|
+
* one-line recap.
|
|
119
|
+
* - User: the latest real user messages (default 3), chronological.
|
|
120
|
+
*/
|
|
121
|
+
export const buildAssistTranscript = (
|
|
122
|
+
messages,
|
|
123
|
+
{ userLimit = TRANSCRIPT_USER_MESSAGE_LIMIT } = {},
|
|
124
|
+
) => {
|
|
125
|
+
if (!Array.isArray(messages) || messages.length === 0) {
|
|
126
|
+
return { transcript: '', assistantInfo: null, userTexts: [], assistantText: '' };
|
|
127
|
+
}
|
|
128
|
+
let lastAssistant = null;
|
|
129
|
+
for (let i = messages.length - 1; i >= 0; i -= 1) {
|
|
130
|
+
if (messages[i]?.info?.role === 'assistant') {
|
|
131
|
+
lastAssistant = messages[i];
|
|
132
|
+
break;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
const lastAssistantInfo = lastAssistant?.info ?? null;
|
|
136
|
+
if (!lastAssistantInfo?.id) {
|
|
137
|
+
return { transcript: '', assistantInfo: null, userTexts: [], assistantText: '' };
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
const userTexts = [];
|
|
141
|
+
for (let i = messages.length - 1; i >= 0 && userTexts.length < userLimit; i -= 1) {
|
|
142
|
+
const message = messages[i];
|
|
143
|
+
if (message?.info?.role !== 'user') continue;
|
|
144
|
+
const text = lastMessageText(message);
|
|
145
|
+
if (!text) continue;
|
|
146
|
+
userTexts.unshift(text);
|
|
147
|
+
}
|
|
148
|
+
const assistantText = lastMessageText(lastAssistant);
|
|
149
|
+
const transcript = [
|
|
150
|
+
...userTexts.map((text) => `User:\n${text}`),
|
|
151
|
+
assistantText ? `Assistant:\n${assistantText}` : '',
|
|
152
|
+
].filter(Boolean).join('\n\n');
|
|
153
|
+
return { transcript, assistantInfo: lastAssistantInfo, userTexts, assistantText };
|
|
102
154
|
};
|
|
103
155
|
|
|
104
156
|
export const createSessionAssistRuntime = ({
|
|
@@ -169,36 +221,21 @@ export const createSessionAssistRuntime = ({
|
|
|
169
221
|
return;
|
|
170
222
|
}
|
|
171
223
|
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
lastAssistant = messages[i];
|
|
177
|
-
break;
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
const lastAssistantInfo = lastAssistant?.info;
|
|
224
|
+
// Trimmed extraction for a one-line recap: the last assistant text block
|
|
225
|
+
// plus the latest real user messages. Everything else (earlier blocks,
|
|
226
|
+
// reasoning, tool output, older turns) is token waste.
|
|
227
|
+
const { transcript, assistantInfo: lastAssistantInfo, userTexts, assistantText } = buildAssistTranscript(messages);
|
|
181
228
|
if (!lastAssistantInfo?.id) return;
|
|
182
|
-
|
|
183
|
-
// Only the last exchange: the assistant reply plus the user message it
|
|
184
|
-
// answered (assistant info.parentID → user info.id). Everything else is
|
|
185
|
-
// token waste for a one-line recap.
|
|
186
|
-
const parentUserMessage = typeof lastAssistantInfo.parentID === 'string' && lastAssistantInfo.parentID
|
|
187
|
-
? messages.find((message) => message?.info?.id === lastAssistantInfo.parentID && message?.info?.role === 'user')
|
|
188
|
-
: null;
|
|
189
|
-
const userText = parentUserMessage ? messagePartsToText(parentUserMessage) : '';
|
|
190
|
-
const assistantText = messagePartsToText(lastAssistant);
|
|
191
|
-
const transcript = [
|
|
192
|
-
userText ? `User:\n${userText}` : '',
|
|
193
|
-
assistantText ? `Assistant:\n${assistantText}` : '',
|
|
194
|
-
].filter(Boolean).join('\n\n');
|
|
195
229
|
if (!transcript) return;
|
|
196
230
|
|
|
197
231
|
const { generateSmallModelText } = await getSmallModelService();
|
|
198
232
|
// Instruct the language by example, not by description — account-side
|
|
199
233
|
// personalization (e.g. the ChatGPT backend knowing the user's locale)
|
|
200
234
|
// otherwise leaks a different language into the output.
|
|
201
|
-
const languageSample = (
|
|
235
|
+
const languageSample = (userTexts[userTexts.length - 1] || assistantText)
|
|
236
|
+
.slice(0, 200)
|
|
237
|
+
.replace(/\s+/g, ' ')
|
|
238
|
+
.trim();
|
|
202
239
|
let generated;
|
|
203
240
|
try {
|
|
204
241
|
generated = await generateSmallModelText({
|
|
@@ -206,7 +243,7 @@ export const createSessionAssistRuntime = ({
|
|
|
206
243
|
// session's own provider unless the user explicitly picked a small
|
|
207
244
|
// model (settings override / opencode config).
|
|
208
245
|
restrictToPreferredProvider: true,
|
|
209
|
-
prompt: `The latest
|
|
246
|
+
prompt: `The latest conversation excerpt:\n\n${transcript}\n\nWrite recap in the SAME language as this sample from the conversation: "${languageSample}"`,
|
|
210
247
|
system: ASSIST_SYSTEM_PROMPT,
|
|
211
248
|
directory,
|
|
212
249
|
preferredProviderID: typeof lastAssistantInfo.providerID === 'string' ? lastAssistantInfo.providerID : undefined,
|
|
@@ -228,7 +265,7 @@ export const createSessionAssistRuntime = ({
|
|
|
228
265
|
// no Cyrillic/CJK at all, the output must not either.
|
|
229
266
|
const hasCyrillic = (text) => /[\u0400-\u04FF]/.test(text);
|
|
230
267
|
const hasCjk = (text) => /[\u3040-\u30FF\u4E00-\u9FFF\uAC00-\uD7AF]/.test(text);
|
|
231
|
-
const inputText = `${
|
|
268
|
+
const inputText = `${userTexts.join('\n')}\n${assistantText}`;
|
|
232
269
|
const scriptMismatch = (text) => (hasCyrillic(text) && !hasCyrillic(inputText))
|
|
233
270
|
|| (hasCjk(text) && !hasCjk(inputText));
|
|
234
271
|
if (recap && scriptMismatch(recap)) {
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { describe, expect, test } from 'vitest';
|
|
2
|
+
import { buildAssistTranscript } from './runtime.js';
|
|
3
|
+
|
|
4
|
+
const textPart = (text, { synthetic = false } = {}) => ({
|
|
5
|
+
type: 'text',
|
|
6
|
+
text,
|
|
7
|
+
...(synthetic ? { synthetic: true } : {}),
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
const userMessage = (id, parts) => ({ info: { id, role: 'user' }, parts });
|
|
11
|
+
const assistantMessage = (id, parts) => ({ info: { id, role: 'assistant' }, parts });
|
|
12
|
+
|
|
13
|
+
describe('buildAssistTranscript', () => {
|
|
14
|
+
test('assistant keeps only the LAST text block of the last assistant message', () => {
|
|
15
|
+
const result = buildAssistTranscript([
|
|
16
|
+
userMessage('u1', [textPart('first user message')]),
|
|
17
|
+
assistantMessage('a1', [textPart('old assistant reply')]),
|
|
18
|
+
userMessage('u2', [textPart('second user message')]),
|
|
19
|
+
assistantMessage('a2', [
|
|
20
|
+
textPart('intro before tools'),
|
|
21
|
+
{ type: 'tool', tool: 'bash' },
|
|
22
|
+
textPart('final body text'),
|
|
23
|
+
]),
|
|
24
|
+
]);
|
|
25
|
+
expect(result.assistantInfo.id).toBe('a2');
|
|
26
|
+
expect(result.assistantText).toBe('final body text');
|
|
27
|
+
expect(result.transcript).toBe(
|
|
28
|
+
'User:\nfirst user message\n\nUser:\nsecond user message\n\nAssistant:\nfinal body text',
|
|
29
|
+
);
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
test('reasoning parts never enter the transcript', () => {
|
|
33
|
+
const result = buildAssistTranscript([
|
|
34
|
+
userMessage('u1', [textPart('请帮我看看')]),
|
|
35
|
+
assistantMessage('a1', [
|
|
36
|
+
{ type: 'reasoning', text: 'thinking about the problem' },
|
|
37
|
+
textPart('最终答复'),
|
|
38
|
+
]),
|
|
39
|
+
]);
|
|
40
|
+
expect(result.transcript).toBe('User:\n请帮我看看\n\nAssistant:\n最终答复');
|
|
41
|
+
expect(result.transcript).not.toContain('thinking');
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
test('user side keeps only the latest 3 real user messages, chronologically', () => {
|
|
45
|
+
const result = buildAssistTranscript([
|
|
46
|
+
userMessage('u1', [textPart('question 1')]),
|
|
47
|
+
assistantMessage('a1', [textPart('answer 1')]),
|
|
48
|
+
userMessage('u2', [textPart('question 2')]),
|
|
49
|
+
assistantMessage('a2', [textPart('answer 2')]),
|
|
50
|
+
userMessage('u3', [textPart('question 3')]),
|
|
51
|
+
userMessage('u4', [textPart('question 4')]),
|
|
52
|
+
assistantMessage('a3', [textPart('answer 3')]),
|
|
53
|
+
]);
|
|
54
|
+
expect(result.userTexts).toEqual(['question 2', 'question 3', 'question 4']);
|
|
55
|
+
expect(result.transcript).toBe(
|
|
56
|
+
'User:\nquestion 2\n\nUser:\nquestion 3\n\nUser:\nquestion 4\n\nAssistant:\nanswer 3',
|
|
57
|
+
);
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
test('synthetic-only user messages do not count toward the user window', () => {
|
|
61
|
+
const result = buildAssistTranscript([
|
|
62
|
+
userMessage('u1', [textPart('visible request')]),
|
|
63
|
+
userMessage('u2', [textPart('hidden instruction', { synthetic: true })]),
|
|
64
|
+
userMessage('u3', [textPart('real follow-up')]),
|
|
65
|
+
assistantMessage('a1', [textPart('reply body')]),
|
|
66
|
+
]);
|
|
67
|
+
expect(result.userTexts).toEqual(['visible request', 'real follow-up']);
|
|
68
|
+
expect(result.transcript).not.toContain('hidden instruction');
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
test('synthetic instruction part on a real user message is dropped', () => {
|
|
72
|
+
const result = buildAssistTranscript([
|
|
73
|
+
userMessage('u1', [
|
|
74
|
+
textPart('visible request'),
|
|
75
|
+
textPart('/summary hidden instructions', { synthetic: true }),
|
|
76
|
+
]),
|
|
77
|
+
assistantMessage('a1', [textPart('reply body')]),
|
|
78
|
+
]);
|
|
79
|
+
expect(result.userTexts).toEqual(['visible request']);
|
|
80
|
+
expect(result.transcript).not.toContain('/summary hidden instructions');
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
test('fewer than 3 user messages keeps all of them', () => {
|
|
84
|
+
const result = buildAssistTranscript([
|
|
85
|
+
userMessage('u1', [textPart('only question')]),
|
|
86
|
+
assistantMessage('a1', [textPart('only answer')]),
|
|
87
|
+
]);
|
|
88
|
+
expect(result.userTexts).toEqual(['only question']);
|
|
89
|
+
expect(result.transcript).toBe('User:\nonly question\n\nAssistant:\nonly answer');
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
test('no assistant message yields an empty transcript', () => {
|
|
93
|
+
const result = buildAssistTranscript([
|
|
94
|
+
userMessage('u1', [textPart('unanswered question')]),
|
|
95
|
+
]);
|
|
96
|
+
expect(result.transcript).toBe('');
|
|
97
|
+
expect(result.assistantInfo).toBeNull();
|
|
98
|
+
expect(result.userTexts).toEqual([]);
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
test('assistant with no text parts still summarizes the user side', () => {
|
|
102
|
+
const result = buildAssistTranscript([
|
|
103
|
+
userMessage('u1', [textPart('question')]),
|
|
104
|
+
assistantMessage('a1', [{ type: 'tool', tool: 'bash' }]),
|
|
105
|
+
]);
|
|
106
|
+
expect(result.assistantInfo.id).toBe('a1');
|
|
107
|
+
expect(result.transcript).toBe('User:\nquestion');
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
test('empty input yields an empty transcript', () => {
|
|
111
|
+
expect(buildAssistTranscript([]).transcript).toBe('');
|
|
112
|
+
expect(buildAssistTranscript(null).transcript).toBe('');
|
|
113
|
+
});
|
|
114
|
+
});
|