@shawnstack/quickforge 1.6.10 → 1.6.12
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/README.md +292 -452
- package/dist/assets/{AgentProfilesPage-BtZpDV-3.js → AgentProfilesPage-CooGLweI.js} +1 -1
- package/dist/assets/ChatPanelHost-TEbv0lnL.js +260 -0
- package/dist/assets/{PluginsPage-CCIj8-Mn.js → PluginsPage-qXTjDrpd.js} +1 -1
- package/dist/assets/{ScheduledTasksPage-DIMewQ3i.js → ScheduledTasksPage-BBor8Yb2.js} +1 -1
- package/dist/assets/{SettingsWorkspacePage-BPD495WT.js → SettingsWorkspacePage-CnFDmGvW.js} +190 -120
- package/dist/assets/{SharedConversationPage-B_oMTp7B.js → SharedConversationPage-CkQ-XwYS.js} +1 -1
- package/dist/assets/{TerminalDock-wgW7kSC4.js → TerminalDock-CvqBBMPg.js} +1 -1
- package/dist/assets/{WorkspaceInspector-CdX45r3u.js → WorkspaceInspector-6JGc6VGb.js} +1 -1
- package/dist/assets/index-DxNzlPmc.js +63 -0
- package/dist/assets/index-HVxfqXfB.css +3 -0
- package/dist/assets/{mcp-servers-dialog-jHlDR9jP.js → mcp-servers-dialog-CsRQxx7A.js} +1 -1
- package/dist/assets/{skills-dialog-DvSnPPzu.js → skills-dialog-CmVLi_h6.js} +1 -1
- package/dist/index.html +4 -4
- package/package.json +1 -1
- package/server/agent-manager.mjs +45 -3
- package/server/approval-store.mjs +4 -0
- package/server/global-memory.mjs +168 -0
- package/server/index.mjs +7 -0
- package/server/project-config.mjs +3 -0
- package/server/routes/memory.mjs +26 -0
- package/server/routes/project.mjs +3 -18
- package/server/routes/tools.mjs +5 -3
- package/server/system-prompt.mjs +22 -0
- package/server/tools/definitions.mjs +14 -0
- package/server/tools/index.mjs +6 -0
- package/server/utils/platform.mjs +20 -3
- package/dist/assets/ChatPanelHost-BF1V-xOV.js +0 -244
- package/dist/assets/index-Bxg5fT2p.css +0 -3
- package/dist/assets/index-DKmdePUP.js +0 -63
package/dist/assets/{SharedConversationPage-B_oMTp7B.js → SharedConversationPage-CkQ-XwYS.js}
RENAMED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{i as e}from"./rolldown-runtime-DWdDZTNf.js";import{Vt as t,ht as n,i as r}from"./icons-C7j5jdKo.js";import{n as i}from"./react-vendor-VqdnQHHS.js";import{S as a,b as o,d as s,f as c,p as l,u}from"./pi-web-ui-DoRGtREc.js";import{U as d}from"./pi-ai-Cr3rpCXT.js";import{t as f}from"./logger-B65Akg8A.js";import{G as p,J as m,K as h,Q as g,S as _,V as v,W as y,X as b,Y as x,c as S,dt as C,ht as w,l as T,s as E,st as D,ut as O}from"./index-DKmdePUP.js";import{ChatPanelHost as k}from"./ChatPanelHost-BF1V-xOV.js";var A=e(t(),1),j=`quickforgeClientMessageId`;function M(e){let t=e?.metadata;return t&&typeof t==`object`&&!Array.isArray(t)?t:void 0}function N(e){let t=M(e)?.[j];return typeof t==`string`&&t?t:void 0}function P(){return`qfcm_${typeof crypto<`u`&&typeof crypto.randomUUID==`function`?crypto.randomUUID():`${Date.now().toString(36)}-${Math.random().toString(36).slice(2)}`}`}function F(e){let t=N(e);if(t)return{message:e,clientMessageId:t};let n=P();return{message:{...e,metadata:{...M(e),[j]:n}},clientMessageId:n}}function I(e){return typeof e==`string`?e:Array.isArray(e)?e.filter(e=>e&&typeof e==`object`&&e.type===`text`).map(e=>e.text).filter(e=>typeof e==`string`).join(``):``}function L(e,t){if(!e||!t||e.role!==t.role)return!1;let n=N(e),r=N(t);return n&&r?n===r:I(e.content)===I(t.content)}async function R(e,t){let n=await fetch(e,{...t,cache:`no-store`,headers:{...t?.body?{"content-type":`application/json`}:void 0,...t?.headers}}),r=await n.json().catch(()=>null);if(!n.ok)throw Error(r?.error||`Request failed: ${n.status}`);return r}var z=class e{state;streamFn=d;getApiKey;sessionId;shareId;permission;listeners=new Set;eventSource=null;disposed=!1;reconnectTimer=null;reconnectDelay=1e3;baseUrl=``;syncingThinkingLevel=!1;planMode=!1;onPlanModeConsumed;constructor(e,t){this.shareId=e,this.sessionId=t.sessionId||t.id||e,this.permission=t.permission??`read`;let n={systemPrompt:t.systemPrompt??``,model:t.model??{provider:`shared`,id:`shared`},thinkingLevel:t.thinkingLevel??`off`,messages:t.messages?.slice()??[],tools:t.tools??[],isStreaming:!!t.isStreaming,streamingMessage:void 0,pendingToolCalls:new Set,errorMessage:t.errorMessage,contextCompaction:t.contextCompaction??null,contextUsage:t.contextUsage??null};this.state=new Proxy(n,{set:(e,t,n)=>{let r=e[t];return e[t]=n,t===`thinkingLevel`&&!this.syncingThinkingLevel&&n!==r&&this.updateThinkingLevel(n).catch(e=>{f.error(`Failed to update shared thinking level:`,e)}),!0}}),this.connectEvents()}subscribe(e){return this.listeners.add(e),()=>{this.listeners.delete(e)}}setNextPromptCapabilities(){}setPlanMode(e,t){this.planMode=e,this.onPlanModeConsumed=e?t:void 0}async prompt(e){if(this.disposed||this.permission!==`operate`)return;let{message:t,clientMessageId:n}=F(this.normalizeInput(e)),r=this.planMode?{type:`plan`}:void 0;if(this.planMode){this.planMode=!1;let e=this.onPlanModeConsumed;this.onPlanModeConsumed=void 0,e?.()}this.state.messages=[...this.state.messages,t],this.emit({type:`message_start`,message:t}),this.state.isStreaming||(this.state.isStreaming=!0,this.state.errorMessage=void 0,this.emit({type:`agent_start`}));try{await R(`/api/shared/${encodeURIComponent(this.shareId)}/message`,{method:`POST`,body:JSON.stringify({message:t,clientMessageId:n,command:r})})}catch(e){let t=e instanceof Error?e.message:String(e);throw this.state.errorMessage=t,this.state.isStreaming=!1,this.emit({type:`error`,error:t}),this.emit({type:`agent_end`,messages:this.state.messages}),e}}async updateModel(e){if(!(this.disposed||this.permission!==`operate`)){this.state.model=e;try{let t=await R(`/api/shared/${encodeURIComponent(this.shareId)}/model`,{method:`POST`,body:JSON.stringify({model:e})});t.model&&(this.state.model=t.model)}catch(e){let t=e instanceof Error?e.message:String(e);throw this.state.errorMessage=t,this.emit({type:`error`,error:t}),e}}}async updateThinkingLevel(e){if(!(this.disposed||this.permission!==`operate`)){!this.syncingThinkingLevel&&this.state.thinkingLevel!==e&&(this.state.thinkingLevel=e);try{let t=await R(`/api/shared/${encodeURIComponent(this.shareId)}/thinking-level`,{method:`POST`,body:JSON.stringify({thinkingLevel:e})});t.thinkingLevel&&(this.state.thinkingLevel=t.thinkingLevel)}catch(e){let t=e instanceof Error?e.message:String(e);throw this.state.errorMessage=t,this.emit({type:`error`,error:t}),e}}}abort(){this.permission===`operate`&&fetch(`/api/shared/${encodeURIComponent(this.shareId)}/abort`,{method:`POST`}).catch(e=>{f.error(`Failed to abort shared conversation:`,e)})}steer(){}followUp(){}reset(){this.state.messages=[],this.state.errorMessage=void 0,this.state.isStreaming=!1,this.state.streamingMessage=void 0,this.state.pendingToolCalls=new Set}async rollback(e){if(this.permission!==`operate`)return;let t=await R(`/api/shared/${encodeURIComponent(this.shareId)}/rollback`,{method:`POST`,body:JSON.stringify({messageIndex:e})});return this.applyState(t.session),this.emit({type:`messages_replaced`,messages:this.state.messages}),t}dispose(){this.disposed=!0,this.reconnectTimer&&clearTimeout(this.reconnectTimer),this.reconnectTimer=null,this.eventSource?.close(),this.eventSource=null,this.listeners.clear()}static async loadState(e){return R(`/api/shared/${encodeURIComponent(e)}/session`)}static async create(t){return new e(t,await e.loadState(t))}normalizeInput(e){return typeof e==`string`?{role:`user`,content:e,timestamp:Date.now()}:Array.isArray(e)?[...e].reverse().find(e=>e.role===`user`||e.role===`user-with-attachments`)??e[e.length-1]:e}connectEvents(){this.disposed||(this.eventSource?.close(),this.baseUrl=``,this.openEventSource())}openEventSource(){if(this.disposed)return;let e=`${this.baseUrl}/api/shared/${encodeURIComponent(this.shareId)}/events`;this.eventSource=new EventSource(e,{withCredentials:!0}),this.eventSource.onopen=()=>{this.reconnectDelay=1e3};let t=[`state`,`agent_start`,`agent_end`,`message_start`,`message_end`,`turn_start`,`turn_end`,`message_update`,`tool_execution_start`,`tool_execution_update`,`tool_execution_end`,`error`,`title_updated`,`messages_replaced`,`auto_compact_completed`],n=e=>t=>{try{let n=JSON.parse(t.data);this.handleEvent(e?{type:e,...n}:n)}catch{}};this.eventSource.onmessage=n();for(let e of t)this.eventSource.addEventListener(e,n(e));this.eventSource.onerror=()=>{this.eventSource?.close(),this.eventSource=null,this.scheduleReconnect()}}scheduleReconnect(){this.disposed||this.reconnectTimer||(this.reconnectTimer=setTimeout(()=>{this.reconnectTimer=null,this.reconnectDelay=Math.min(this.reconnectDelay*2,3e4),this.openEventSource()},this.reconnectDelay))}handleEvent(e){if(e.type){switch(e.type){case`state`:this.applyState(e);break;case`agent_start`:this.state.isStreaming=!0,this.state.errorMessage=void 0;break;case`agent_end`:this.state.isStreaming=!1,this.state.streamingMessage=void 0;break;case`message_start`:if(e.message){let t=this.state.messages.findIndex(t=>L(t,e.message));if(t>=0){let n=this.state.messages.slice();n[t]=e.message,this.state.messages=n}else this.state.messages=[...this.state.messages,e.message];this.state.contextUsage=null}break;case`message_update`:e.message&&(this.state.streamingMessage=e.message);break;case`message_end`:e.message&&(this.state.messages=x(this.state.messages,e.message)),this.state.contextUsage=`contextUsage`in e?e.contextUsage:null,this.state.streamingMessage=void 0;break;case`messages_replaced`:e.messages&&(this.state.messages=e.messages,this.state.streamingMessage=void 0),`contextCompaction`in e&&(this.state.contextCompaction=e.contextCompaction),`contextUsage`in e&&(this.state.contextUsage=e.contextUsage);break;case`auto_compact_completed`:`contextCompaction`in e&&(this.state.contextCompaction=e.contextCompaction),`contextUsage`in e&&(this.state.contextUsage=e.contextUsage);break;case`tool_execution_start`:{let t=e;t.toolCallId&&(this.state.messages=b(this.state.messages,m(t),!0),this.state.pendingToolCalls=new Set([...this.state.pendingToolCalls,t.toolCallId]));break}case`tool_execution_update`:{let t=e;this.state.messages=b(this.state.messages,t,!0),t.toolCallId&&(this.state.pendingToolCalls=new Set([...this.state.pendingToolCalls,t.toolCallId]));break}case`tool_execution_end`:{let t=e;if(this.state.messages=b(this.state.messages,t,!1),t.toolCallId){let e=new Set(this.state.pendingToolCalls);e.delete(t.toolCallId),this.state.pendingToolCalls=e}break}case`error`:this.state.errorMessage=typeof e.error==`string`?e.error:`Unknown error`,this.state.isStreaming=!1;break}this.emit(e)}}applyState(e){this.sessionId=e.sessionId||e.id||this.sessionId,e.messages&&(this.state.messages=e.messages,this.state.contextUsage=e.contextUsage===void 0?null:e.contextUsage),e.systemPrompt!==void 0&&(this.state.systemPrompt=e.systemPrompt),e.model&&(this.state.model=e.model),e.thinkingLevel&&(this.syncingThinkingLevel=!0,this.state.thinkingLevel=e.thinkingLevel,this.syncingThinkingLevel=!1),e.tools&&(this.state.tools=e.tools),e.isStreaming!==void 0&&(this.state.isStreaming=!!e.isStreaming),e.errorMessage!==void 0&&(this.state.errorMessage=e.errorMessage),e.contextCompaction!==void 0&&(this.state.contextCompaction=e.contextCompaction),e.contextUsage!==void 0&&(this.state.contextUsage=e.contextUsage)}emit(e){for(let t of this.listeners)try{t(e)}catch{}}},B=i();function V(e){return{id:`shared-${e.provider}`,name:e.provider,type:e.api,baseUrl:e.baseUrl??``,models:[e]}}async function H(e,t){try{let t=await S(e);if(t.providers?.length)return t.providers}catch{}return t?[V(t)]:[]}function U(e,t){let n=t.model??{provider:`shared`,id:`shared`};return new z(e,{...t,model:n,thinkingLevel:t.thinkingLevel??g(n)})}function W(e,t){let n={settings:new u,providerKeys:new c,sessions:new s,customProviders:new l},r=new D(``,{blockedStores:[`sessions`,`provider-keys`],fakeProviderKeys:t?[t.provider]:void 0,storeOverrides:t?{"custom-providers":{keys:async()=>(await H(e,t)).map(e=>e.name),get:async n=>(await H(e,t)).find(e=>e.name===n)??null,has:async n=>(await H(e,t)).some(e=>e.name===n)}}:void 0});n.settings.setBackend(r),n.providerKeys.setBackend(r),n.sessions.setBackend(r),n.customProviders.setBackend(r),a(new o(n.settings,n.providerKeys,n.sessions,n.customProviders,r))}function G({shareId:e}){let[t,i]=(0,A.useState)(``),[a,o]=(0,A.useState)(null),[s,c]=(0,A.useState)(`read`),[l,u]=(0,A.useState)(`QuickForge 分享对话`),[d,m]=(0,A.useState)(),[g,b]=(0,A.useState)(!1),[x,S]=(0,A.useState)(),D=(0,A.useRef)(!1),j=s===`operate`,M=!!a,N=!!a?.state.tools?.length;(0,A.useEffect)(()=>{W(e,a?.state.model)},[a?.state.model,e]),(0,A.useEffect)(()=>()=>a?.dispose(),[a]);let P=(0,A.useCallback)(async(n=t.trim())=>{m(void 0),b(!0);try{let t=await T(e,n);c(t.permission),u(t.title||t.share.titleSnapshot||`QuickForge 分享对话`);let r=await z.loadState(e);W(e,r.model),o(U(e,r))}catch(e){m(e instanceof Error?e.message:`Failed to unlock shared conversation`)}finally{b(!1)}},[t,e]);(0,A.useEffect)(()=>{if(M||g||D.current)return;D.current=!0;let t=window.setTimeout(()=>{(async()=>{try{(await E(e)).share.hasPassword||await P(``)}catch(e){m(e instanceof Error?e.message:`Failed to load shared conversation`)}})()},0);return()=>window.clearTimeout(t)},[g,e,P,M]);let F=(0,A.useCallback)(async e=>{await y(e)},[]),I=(0,A.useCallback)(async()=>{if(!(!a||a.permission!==`operate`))try{let t=(await H(e,a.state.model)).flatMap(e=>e.models??[]);if(!t.length)return;_(a.state.model,t,t=>{!t.reasoning&&a.state.thinkingLevel!==`off`&&a.updateThinkingLevel(`off`).catch(e=>{f.error(`Failed to update shared thinking level:`,e)}),W(e,t),a.updateModel(t).catch(e=>{m(e instanceof Error?e.message:`Failed to update model`)})},void 0,{thinkingLevel:a.state.thinkingLevel,onThinkingLevelSelect:e=>{a.updateThinkingLevel(e).catch(e=>{f.error(`Failed to update shared thinking level:`,e),m(e instanceof Error?e.message:`Failed to update thinking level`)})}})}catch(e){m(e instanceof Error?e.message:`Failed to load models`)}},[a,e]),L=(0,A.useCallback)(e=>{S(t=>t?.id===e?void 0:t)},[]),R=(0,A.useCallback)(async e=>{if(!a||a.permission!==`operate`)return;if(m(void 0),a.state.isStreaming){v(w(`generationStillRunning`));return}let t=h(a.state.messages,e),n=t>=0?a.state.messages[t]:void 0;if(!n){v(w(`noConversationTurnToRollback`));return}try{await a.rollback(e),S({id:Date.now(),sessionId:a.sessionId,text:p(n),attachments:n.role===`user-with-attachments`?n.attachments:void 0})}catch(e){m(e instanceof Error?e.message:`Failed to roll back`)}},[a]);return M?(0,B.jsxs)(`div`,{className:`flex h-screen min-h-0 flex-col bg-background text-foreground`,children:[(0,B.jsx)(`header`,{className:C(`shrink-0 border-b px-4 py-3`,j?`border-red-300 bg-red-50 text-red-950`:`border-border bg-background`),children:(0,B.jsxs)(`div`,{className:`mx-auto flex max-w-4xl items-start gap-3`,children:[(0,B.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,B.jsx)(`div`,{className:`truncate text-sm font-semibold`,children:l}),(0,B.jsxs)(`div`,{className:`mt-1 flex flex-wrap items-center gap-x-2 gap-y-1 text-xs`,children:[(0,B.jsxs)(`span`,{className:C(`inline-flex items-center gap-1 rounded-full px-2 py-0.5 font-medium`,j?`bg-red-100 text-red-700`:`bg-muted text-muted-foreground`),children:[j?(0,B.jsx)(r,{className:`size-3.5`}):null,j?`高危可操作`:`只读分享`]}),(0,B.jsx)(`span`,{className:C(j?`text-red-800`:`text-muted-foreground`),children:j?`正在操作分享者的原始对话`:`只能查看,不能发送或修改`})]}),j?null:(0,B.jsx)(`div`,{className:`mt-1 text-xs leading-5 text-muted-foreground`,children:`界面与正常对话保持一致`})]}),(0,B.jsxs)(O,{variant:`ghost`,size:`sm`,className:C(`shrink-0`,j?`text-red-700 hover:bg-red-100 hover:text-red-800`:void 0),onClick:()=>void y(window.location.href),"aria-label":j?`复制高危分享链接`:`复制分享链接`,title:j?`复制高危分享链接`:`复制分享链接`,children:[(0,B.jsx)(n,{className:`size-4`}),(0,B.jsx)(`span`,{className:`hidden sm:inline`,children:j?`复制高危链接`:`复制链接`})]})]})}),d?(0,B.jsx)(`div`,{className:`mx-auto w-full max-w-4xl px-4 py-2 text-sm text-destructive`,children:d}):null,(0,B.jsx)(k,{agent:a,revision:0,agentAccessMode:N?`full-access`:`default`,workspaceToolsEnabled:N,onModelSelect:I,onAccessModeChange:()=>void 0,onRollbackFromMessage:R,onRetryFromMessage:()=>void 0,onCopyAnswer:F,onForkFromMessage:()=>void 0,onApproveToolCall:()=>void 0,onRejectToolCall:()=>void 0,disableFork:!0,rollbackConfirmTitle:w(`sharedRollbackConfirmTitle`),rollbackConfirmDescription:w(`sharedRollbackConfirm`),readOnly:!j,restoredDraft:x,onRestoredDraftConsumed:L,bypassClientApiKeyCheck:!0})]}):(0,B.jsx)(`div`,{className:`flex min-h-screen items-center justify-center bg-background p-6 text-foreground`,children:(0,B.jsxs)(`div`,{className:`w-full max-w-md rounded-2xl border border-border bg-background p-6 shadow-quickforge`,children:[(0,B.jsxs)(`div`,{className:`flex items-center gap-2 text-base font-semibold`,children:[(0,B.jsx)(r,{className:`size-5 text-amber-500`}),`QuickForge 局域网对话分享`]}),(0,B.jsx)(`p`,{className:`mt-2 text-sm text-muted-foreground`,children:`如果分享者设置了密码,请输入密码。未设置密码的链接会自动打开。`}),(0,B.jsx)(`input`,{type:`password`,value:t,onChange:e=>i(e.target.value),onKeyDown:e=>{e.key===`Enter`&&P()},className:`mt-5 h-10 w-full rounded-md border border-input bg-background px-3 text-sm outline-none focus:border-primary`,placeholder:`密码`,autoFocus:!0}),d?(0,B.jsx)(`div`,{className:`mt-3 rounded-md border border-destructive/30 bg-destructive/10 px-3 py-2 text-sm text-destructive`,children:d}):null,(0,B.jsx)(O,{className:`mt-5 w-full`,onClick:()=>void P(),disabled:g||!t.trim(),children:g?w(`loading`):`用密码打开分享对话`})]})})}export{G as SharedConversationPage};
|
|
1
|
+
import{i as e}from"./rolldown-runtime-DWdDZTNf.js";import{Vt as t,ht as n,i as r}from"./icons-C7j5jdKo.js";import{n as i}from"./react-vendor-VqdnQHHS.js";import{S as a,b as o,d as s,f as c,p as l,u}from"./pi-web-ui-DoRGtREc.js";import{U as d}from"./pi-ai-Cr3rpCXT.js";import{t as f}from"./logger-B65Akg8A.js";import{G as p,J as m,K as h,Q as g,S as _,V as v,W as y,X as b,Y as x,c as S,dt as C,ht as w,l as T,s as E,st as D,ut as O}from"./index-DxNzlPmc.js";import{ChatPanelHost as k}from"./ChatPanelHost-TEbv0lnL.js";var A=e(t(),1),j=`quickforgeClientMessageId`;function M(e){let t=e?.metadata;return t&&typeof t==`object`&&!Array.isArray(t)?t:void 0}function N(e){let t=M(e)?.[j];return typeof t==`string`&&t?t:void 0}function P(){return`qfcm_${typeof crypto<`u`&&typeof crypto.randomUUID==`function`?crypto.randomUUID():`${Date.now().toString(36)}-${Math.random().toString(36).slice(2)}`}`}function F(e){let t=N(e);if(t)return{message:e,clientMessageId:t};let n=P();return{message:{...e,metadata:{...M(e),[j]:n}},clientMessageId:n}}function I(e){return typeof e==`string`?e:Array.isArray(e)?e.filter(e=>e&&typeof e==`object`&&e.type===`text`).map(e=>e.text).filter(e=>typeof e==`string`).join(``):``}function L(e,t){if(!e||!t||e.role!==t.role)return!1;let n=N(e),r=N(t);return n&&r?n===r:I(e.content)===I(t.content)}async function R(e,t){let n=await fetch(e,{...t,cache:`no-store`,headers:{...t?.body?{"content-type":`application/json`}:void 0,...t?.headers}}),r=await n.json().catch(()=>null);if(!n.ok)throw Error(r?.error||`Request failed: ${n.status}`);return r}var z=class e{state;streamFn=d;getApiKey;sessionId;shareId;permission;listeners=new Set;eventSource=null;disposed=!1;reconnectTimer=null;reconnectDelay=1e3;baseUrl=``;syncingThinkingLevel=!1;planMode=!1;onPlanModeConsumed;constructor(e,t){this.shareId=e,this.sessionId=t.sessionId||t.id||e,this.permission=t.permission??`read`;let n={systemPrompt:t.systemPrompt??``,model:t.model??{provider:`shared`,id:`shared`},thinkingLevel:t.thinkingLevel??`off`,messages:t.messages?.slice()??[],tools:t.tools??[],isStreaming:!!t.isStreaming,streamingMessage:void 0,pendingToolCalls:new Set,errorMessage:t.errorMessage,contextCompaction:t.contextCompaction??null,contextUsage:t.contextUsage??null};this.state=new Proxy(n,{set:(e,t,n)=>{let r=e[t];return e[t]=n,t===`thinkingLevel`&&!this.syncingThinkingLevel&&n!==r&&this.updateThinkingLevel(n).catch(e=>{f.error(`Failed to update shared thinking level:`,e)}),!0}}),this.connectEvents()}subscribe(e){return this.listeners.add(e),()=>{this.listeners.delete(e)}}setNextPromptCapabilities(){}setPlanMode(e,t){this.planMode=e,this.onPlanModeConsumed=e?t:void 0}async prompt(e){if(this.disposed||this.permission!==`operate`)return;let{message:t,clientMessageId:n}=F(this.normalizeInput(e)),r=this.planMode?{type:`plan`}:void 0;if(this.planMode){this.planMode=!1;let e=this.onPlanModeConsumed;this.onPlanModeConsumed=void 0,e?.()}this.state.messages=[...this.state.messages,t],this.emit({type:`message_start`,message:t}),this.state.isStreaming||(this.state.isStreaming=!0,this.state.errorMessage=void 0,this.emit({type:`agent_start`}));try{await R(`/api/shared/${encodeURIComponent(this.shareId)}/message`,{method:`POST`,body:JSON.stringify({message:t,clientMessageId:n,command:r})})}catch(e){let t=e instanceof Error?e.message:String(e);throw this.state.errorMessage=t,this.state.isStreaming=!1,this.emit({type:`error`,error:t}),this.emit({type:`agent_end`,messages:this.state.messages}),e}}async updateModel(e){if(!(this.disposed||this.permission!==`operate`)){this.state.model=e;try{let t=await R(`/api/shared/${encodeURIComponent(this.shareId)}/model`,{method:`POST`,body:JSON.stringify({model:e})});t.model&&(this.state.model=t.model)}catch(e){let t=e instanceof Error?e.message:String(e);throw this.state.errorMessage=t,this.emit({type:`error`,error:t}),e}}}async updateThinkingLevel(e){if(!(this.disposed||this.permission!==`operate`)){!this.syncingThinkingLevel&&this.state.thinkingLevel!==e&&(this.state.thinkingLevel=e);try{let t=await R(`/api/shared/${encodeURIComponent(this.shareId)}/thinking-level`,{method:`POST`,body:JSON.stringify({thinkingLevel:e})});t.thinkingLevel&&(this.state.thinkingLevel=t.thinkingLevel)}catch(e){let t=e instanceof Error?e.message:String(e);throw this.state.errorMessage=t,this.emit({type:`error`,error:t}),e}}}abort(){this.permission===`operate`&&fetch(`/api/shared/${encodeURIComponent(this.shareId)}/abort`,{method:`POST`}).catch(e=>{f.error(`Failed to abort shared conversation:`,e)})}steer(){}followUp(){}reset(){this.state.messages=[],this.state.errorMessage=void 0,this.state.isStreaming=!1,this.state.streamingMessage=void 0,this.state.pendingToolCalls=new Set}async rollback(e){if(this.permission!==`operate`)return;let t=await R(`/api/shared/${encodeURIComponent(this.shareId)}/rollback`,{method:`POST`,body:JSON.stringify({messageIndex:e})});return this.applyState(t.session),this.emit({type:`messages_replaced`,messages:this.state.messages}),t}dispose(){this.disposed=!0,this.reconnectTimer&&clearTimeout(this.reconnectTimer),this.reconnectTimer=null,this.eventSource?.close(),this.eventSource=null,this.listeners.clear()}static async loadState(e){return R(`/api/shared/${encodeURIComponent(e)}/session`)}static async create(t){return new e(t,await e.loadState(t))}normalizeInput(e){return typeof e==`string`?{role:`user`,content:e,timestamp:Date.now()}:Array.isArray(e)?[...e].reverse().find(e=>e.role===`user`||e.role===`user-with-attachments`)??e[e.length-1]:e}connectEvents(){this.disposed||(this.eventSource?.close(),this.baseUrl=``,this.openEventSource())}openEventSource(){if(this.disposed)return;let e=`${this.baseUrl}/api/shared/${encodeURIComponent(this.shareId)}/events`;this.eventSource=new EventSource(e,{withCredentials:!0}),this.eventSource.onopen=()=>{this.reconnectDelay=1e3};let t=[`state`,`agent_start`,`agent_end`,`message_start`,`message_end`,`turn_start`,`turn_end`,`message_update`,`tool_execution_start`,`tool_execution_update`,`tool_execution_end`,`error`,`title_updated`,`messages_replaced`,`auto_compact_completed`],n=e=>t=>{try{let n=JSON.parse(t.data);this.handleEvent(e?{type:e,...n}:n)}catch{}};this.eventSource.onmessage=n();for(let e of t)this.eventSource.addEventListener(e,n(e));this.eventSource.onerror=()=>{this.eventSource?.close(),this.eventSource=null,this.scheduleReconnect()}}scheduleReconnect(){this.disposed||this.reconnectTimer||(this.reconnectTimer=setTimeout(()=>{this.reconnectTimer=null,this.reconnectDelay=Math.min(this.reconnectDelay*2,3e4),this.openEventSource()},this.reconnectDelay))}handleEvent(e){if(e.type){switch(e.type){case`state`:this.applyState(e);break;case`agent_start`:this.state.isStreaming=!0,this.state.errorMessage=void 0;break;case`agent_end`:this.state.isStreaming=!1,this.state.streamingMessage=void 0;break;case`message_start`:if(e.message){let t=this.state.messages.findIndex(t=>L(t,e.message));if(t>=0){let n=this.state.messages.slice();n[t]=e.message,this.state.messages=n}else this.state.messages=[...this.state.messages,e.message];this.state.contextUsage=null}break;case`message_update`:e.message&&(this.state.streamingMessage=e.message);break;case`message_end`:e.message&&(this.state.messages=x(this.state.messages,e.message)),this.state.contextUsage=`contextUsage`in e?e.contextUsage:null,this.state.streamingMessage=void 0;break;case`messages_replaced`:e.messages&&(this.state.messages=e.messages,this.state.streamingMessage=void 0),`contextCompaction`in e&&(this.state.contextCompaction=e.contextCompaction),`contextUsage`in e&&(this.state.contextUsage=e.contextUsage);break;case`auto_compact_completed`:`contextCompaction`in e&&(this.state.contextCompaction=e.contextCompaction),`contextUsage`in e&&(this.state.contextUsage=e.contextUsage);break;case`tool_execution_start`:{let t=e;t.toolCallId&&(this.state.messages=b(this.state.messages,m(t),!0),this.state.pendingToolCalls=new Set([...this.state.pendingToolCalls,t.toolCallId]));break}case`tool_execution_update`:{let t=e;this.state.messages=b(this.state.messages,t,!0),t.toolCallId&&(this.state.pendingToolCalls=new Set([...this.state.pendingToolCalls,t.toolCallId]));break}case`tool_execution_end`:{let t=e;if(this.state.messages=b(this.state.messages,t,!1),t.toolCallId){let e=new Set(this.state.pendingToolCalls);e.delete(t.toolCallId),this.state.pendingToolCalls=e}break}case`error`:this.state.errorMessage=typeof e.error==`string`?e.error:`Unknown error`,this.state.isStreaming=!1;break}this.emit(e)}}applyState(e){this.sessionId=e.sessionId||e.id||this.sessionId,e.messages&&(this.state.messages=e.messages,this.state.contextUsage=e.contextUsage===void 0?null:e.contextUsage),e.systemPrompt!==void 0&&(this.state.systemPrompt=e.systemPrompt),e.model&&(this.state.model=e.model),e.thinkingLevel&&(this.syncingThinkingLevel=!0,this.state.thinkingLevel=e.thinkingLevel,this.syncingThinkingLevel=!1),e.tools&&(this.state.tools=e.tools),e.isStreaming!==void 0&&(this.state.isStreaming=!!e.isStreaming),e.errorMessage!==void 0&&(this.state.errorMessage=e.errorMessage),e.contextCompaction!==void 0&&(this.state.contextCompaction=e.contextCompaction),e.contextUsage!==void 0&&(this.state.contextUsage=e.contextUsage)}emit(e){for(let t of this.listeners)try{t(e)}catch{}}},B=i();function V(e){return{id:`shared-${e.provider}`,name:e.provider,type:e.api,baseUrl:e.baseUrl??``,models:[e]}}async function H(e,t){try{let t=await S(e);if(t.providers?.length)return t.providers}catch{}return t?[V(t)]:[]}function U(e,t){let n=t.model??{provider:`shared`,id:`shared`};return new z(e,{...t,model:n,thinkingLevel:t.thinkingLevel??g(n)})}function W(e,t){let n={settings:new u,providerKeys:new c,sessions:new s,customProviders:new l},r=new D(``,{blockedStores:[`sessions`,`provider-keys`],fakeProviderKeys:t?[t.provider]:void 0,storeOverrides:t?{"custom-providers":{keys:async()=>(await H(e,t)).map(e=>e.name),get:async n=>(await H(e,t)).find(e=>e.name===n)??null,has:async n=>(await H(e,t)).some(e=>e.name===n)}}:void 0});n.settings.setBackend(r),n.providerKeys.setBackend(r),n.sessions.setBackend(r),n.customProviders.setBackend(r),a(new o(n.settings,n.providerKeys,n.sessions,n.customProviders,r))}function G({shareId:e}){let[t,i]=(0,A.useState)(``),[a,o]=(0,A.useState)(null),[s,c]=(0,A.useState)(`read`),[l,u]=(0,A.useState)(`QuickForge 分享对话`),[d,m]=(0,A.useState)(),[g,b]=(0,A.useState)(!1),[x,S]=(0,A.useState)(),D=(0,A.useRef)(!1),j=s===`operate`,M=!!a,N=!!a?.state.tools?.length;(0,A.useEffect)(()=>{W(e,a?.state.model)},[a?.state.model,e]),(0,A.useEffect)(()=>()=>a?.dispose(),[a]);let P=(0,A.useCallback)(async(n=t.trim())=>{m(void 0),b(!0);try{let t=await T(e,n);c(t.permission),u(t.title||t.share.titleSnapshot||`QuickForge 分享对话`);let r=await z.loadState(e);W(e,r.model),o(U(e,r))}catch(e){m(e instanceof Error?e.message:`Failed to unlock shared conversation`)}finally{b(!1)}},[t,e]);(0,A.useEffect)(()=>{if(M||g||D.current)return;D.current=!0;let t=window.setTimeout(()=>{(async()=>{try{(await E(e)).share.hasPassword||await P(``)}catch(e){m(e instanceof Error?e.message:`Failed to load shared conversation`)}})()},0);return()=>window.clearTimeout(t)},[g,e,P,M]);let F=(0,A.useCallback)(async e=>{await y(e)},[]),I=(0,A.useCallback)(async()=>{if(!(!a||a.permission!==`operate`))try{let t=(await H(e,a.state.model)).flatMap(e=>e.models??[]);if(!t.length)return;_(a.state.model,t,t=>{!t.reasoning&&a.state.thinkingLevel!==`off`&&a.updateThinkingLevel(`off`).catch(e=>{f.error(`Failed to update shared thinking level:`,e)}),W(e,t),a.updateModel(t).catch(e=>{m(e instanceof Error?e.message:`Failed to update model`)})},void 0,{thinkingLevel:a.state.thinkingLevel,onThinkingLevelSelect:e=>{a.updateThinkingLevel(e).catch(e=>{f.error(`Failed to update shared thinking level:`,e),m(e instanceof Error?e.message:`Failed to update thinking level`)})}})}catch(e){m(e instanceof Error?e.message:`Failed to load models`)}},[a,e]),L=(0,A.useCallback)(e=>{S(t=>t?.id===e?void 0:t)},[]),R=(0,A.useCallback)(async e=>{if(!a||a.permission!==`operate`)return;if(m(void 0),a.state.isStreaming){v(w(`generationStillRunning`));return}let t=h(a.state.messages,e),n=t>=0?a.state.messages[t]:void 0;if(!n){v(w(`noConversationTurnToRollback`));return}try{await a.rollback(e),S({id:Date.now(),sessionId:a.sessionId,text:p(n),attachments:n.role===`user-with-attachments`?n.attachments:void 0})}catch(e){m(e instanceof Error?e.message:`Failed to roll back`)}},[a]);return M?(0,B.jsxs)(`div`,{className:`flex h-screen min-h-0 flex-col bg-background text-foreground`,children:[(0,B.jsx)(`header`,{className:C(`shrink-0 border-b px-4 py-3`,j?`border-red-300 bg-red-50 text-red-950`:`border-border bg-background`),children:(0,B.jsxs)(`div`,{className:`mx-auto flex max-w-4xl items-start gap-3`,children:[(0,B.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,B.jsx)(`div`,{className:`truncate text-sm font-semibold`,children:l}),(0,B.jsxs)(`div`,{className:`mt-1 flex flex-wrap items-center gap-x-2 gap-y-1 text-xs`,children:[(0,B.jsxs)(`span`,{className:C(`inline-flex items-center gap-1 rounded-full px-2 py-0.5 font-medium`,j?`bg-red-100 text-red-700`:`bg-muted text-muted-foreground`),children:[j?(0,B.jsx)(r,{className:`size-3.5`}):null,j?`高危可操作`:`只读分享`]}),(0,B.jsx)(`span`,{className:C(j?`text-red-800`:`text-muted-foreground`),children:j?`正在操作分享者的原始对话`:`只能查看,不能发送或修改`})]}),j?null:(0,B.jsx)(`div`,{className:`mt-1 text-xs leading-5 text-muted-foreground`,children:`界面与正常对话保持一致`})]}),(0,B.jsxs)(O,{variant:`ghost`,size:`sm`,className:C(`shrink-0`,j?`text-red-700 hover:bg-red-100 hover:text-red-800`:void 0),onClick:()=>void y(window.location.href),"aria-label":j?`复制高危分享链接`:`复制分享链接`,title:j?`复制高危分享链接`:`复制分享链接`,children:[(0,B.jsx)(n,{className:`size-4`}),(0,B.jsx)(`span`,{className:`hidden sm:inline`,children:j?`复制高危链接`:`复制链接`})]})]})}),d?(0,B.jsx)(`div`,{className:`mx-auto w-full max-w-4xl px-4 py-2 text-sm text-destructive`,children:d}):null,(0,B.jsx)(k,{agent:a,revision:0,agentAccessMode:N?`full-access`:`default`,workspaceToolsEnabled:N,onModelSelect:I,onAccessModeChange:()=>void 0,onRollbackFromMessage:R,onRetryFromMessage:()=>void 0,onCopyAnswer:F,onForkFromMessage:()=>void 0,onApproveToolCall:()=>void 0,onRejectToolCall:()=>void 0,disableFork:!0,rollbackConfirmTitle:w(`sharedRollbackConfirmTitle`),rollbackConfirmDescription:w(`sharedRollbackConfirm`),readOnly:!j,restoredDraft:x,onRestoredDraftConsumed:L,bypassClientApiKeyCheck:!0})]}):(0,B.jsx)(`div`,{className:`flex min-h-screen items-center justify-center bg-background p-6 text-foreground`,children:(0,B.jsxs)(`div`,{className:`w-full max-w-md rounded-2xl border border-border bg-background p-6 shadow-quickforge`,children:[(0,B.jsxs)(`div`,{className:`flex items-center gap-2 text-base font-semibold`,children:[(0,B.jsx)(r,{className:`size-5 text-amber-500`}),`QuickForge 局域网对话分享`]}),(0,B.jsx)(`p`,{className:`mt-2 text-sm text-muted-foreground`,children:`如果分享者设置了密码,请输入密码。未设置密码的链接会自动打开。`}),(0,B.jsx)(`input`,{type:`password`,value:t,onChange:e=>i(e.target.value),onKeyDown:e=>{e.key===`Enter`&&P()},className:`mt-5 h-10 w-full rounded-md border border-input bg-background px-3 text-sm outline-none focus:border-primary`,placeholder:`密码`,autoFocus:!0}),d?(0,B.jsx)(`div`,{className:`mt-3 rounded-md border border-destructive/30 bg-destructive/10 px-3 py-2 text-sm text-destructive`,children:d}):null,(0,B.jsx)(O,{className:`mt-5 w-full`,onClick:()=>void P(),disabled:g||!t.trim(),children:g?w(`loading`):`用密码打开分享对话`})]})})}export{G as SharedConversationPage};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{i as e}from"./rolldown-runtime-DWdDZTNf.js";import{At as t,B as n,C as r,N as i,R as a,Vt as o,c as s,n as c}from"./icons-C7j5jdKo.js";import{n as l}from"./react-vendor-VqdnQHHS.js";import{E as u,P as d,dt as f,ht as p,j as m,ut as h}from"./index-
|
|
1
|
+
import{i as e}from"./rolldown-runtime-DWdDZTNf.js";import{At as t,B as n,C as r,N as i,R as a,Vt as o,c as s,n as c}from"./icons-C7j5jdKo.js";import{n as l}from"./react-vendor-VqdnQHHS.js";import{E as u,P as d,dt as f,ht as p,j as m,ut as h}from"./index-DxNzlPmc.js";import{n as ee,t as g}from"./xterm-CGiQzDiR.js";var _=e(o(),1);async function v(e,t){let n=await fetch(e,{cache:`no-store`,...t}),r=await n.json().catch(()=>null);if(!n.ok)throw Error(r?.error||`Request failed: ${n.status}`);return r}function y(){return v(`/api/terminal/capabilities`)}function b(e){return v(`/api/terminal/sessions${e?`?projectId=${encodeURIComponent(e)}`:``}`)}function x(e){return v(`/api/terminal/sessions`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify(e)})}function S(e){return v(`/api/terminal/sessions/${encodeURIComponent(e)}`,{method:`DELETE`})}function C(e,t){return v(`/api/terminal/sessions/${encodeURIComponent(e)}/input`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({data:t})})}function w(){return``}function te(){let e=w();if(e){let t=new URL(e);return t.protocol=t.protocol===`https:`?`wss:`:`ws:`,t.toString().replace(/\/$/,``)}return`${location.protocol===`https:`?`wss:`:`ws:`}//${location.host}`}function T(){let[e,t]=(0,_.useState)(()=>u());return(0,_.useEffect)(()=>{if(typeof document>`u`)return;let e=document.documentElement,n=()=>t(u());n();let r=new MutationObserver(n);return r.observe(e,{attributes:!0,attributeFilter:[`class`]}),()=>r.disconnect()},[]),e}var E=l(),D={light:{background:`#ffffff`,foreground:`#1f2937`,cursor:`#1f2937`,selectionBackground:`#dbeafe`},dark:{background:`#171717`,foreground:`#e5e7eb`,cursor:`#e5e7eb`,selectionBackground:`#3f3f46`}};function ne({session:e,active:t,height:n,onReady:r,onExited:i,onConnectionError:a}){let o=T(),s=D[o],c=(0,_.useRef)(null),l=(0,_.useRef)(null),u=(0,_.useRef)(null),f=(0,_.useRef)(null),h=(0,_.useRef)(null),v=(0,_.useRef)(null);return(0,_.useEffect)(()=>{let t=c.current;if(!t)return;let n=!1,o=!1,_=!1,y=!1,b=t=>{n||_||y||(y=!0,a(e.id,t))},x=d(),S=new ee({cursorBlink:!0,convertEol:!1,fontFamily:getComputedStyle(document.documentElement).getPropertyValue(`--font-mono`).trim()||`ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace`,fontSize:x.fontSize,lineHeight:x.lineHeight,scrollback:5e3,theme:s}),C=new g;S.loadAddon(C),S.open(t),S.writeln(`\x1b[2mConnected to ${e.cwd}\x1b[0m`),l.current=S,u.current=C;let w=()=>{if(t.isConnected)try{C.fit();let{cols:e,rows:t}=S,n=f.current;n?.readyState===WebSocket.OPEN&&n.send(JSON.stringify({type:`resize`,cols:e,rows:t}))}catch{}},T=new WebSocket(`${te()}/api/terminal/sessions/${encodeURIComponent(e.id)}/ws`);f.current=T,T.addEventListener(`open`,()=>{o=!0,y=!1,a(e.id,void 0),h.current=S.onData(e=>{T.readyState===WebSocket.OPEN&&T.send(JSON.stringify({type:`input`,data:e}))}),window.setTimeout(w,0)}),T.addEventListener(`message`,t=>{try{let n=JSON.parse(String(t.data));n.type===`ready`?r(e.id):n.type===`output`?S.write(n.data):n.type===`exit`?(_=!0,S.writeln(``),S.writeln(`\x1b[33m[process exited with code ${n.exitCode??`unknown`}]\x1b[0m`),i(e.id)):n.type===`error`&&S.writeln(`\x1b[31m${n.message}\x1b[0m`)}catch{}}),T.addEventListener(`error`,()=>{b(p(o?`terminalConnectionClosedUnexpectedly`:`terminalConnectionFailed`))}),T.addEventListener(`close`,e=>{h.current?.dispose(),h.current=null,!(n||_)&&(!e.wasClean||e.code!==1e3)&&b(p(o?`terminalConnectionClosedUnexpectedly`:`terminalConnectionFailed`))});let E=new ResizeObserver(()=>w());E.observe(t),v.current=E;let D=()=>{let e=d();S.options.fontSize=e.fontSize,S.options.lineHeight=e.lineHeight,window.setTimeout(w,0)};return window.addEventListener(m,D),window.setTimeout(w,50),()=>{n=!0,window.removeEventListener(m,D),E.disconnect(),v.current=null,h.current?.dispose(),h.current=null,T.close(),f.current=null,S.dispose(),l.current=null,u.current=null}},[o,a,i,r,e.cwd,e.id,s]),(0,_.useEffect)(()=>{if(!t)return;let e=u.current,n=l.current;window.setTimeout(()=>{try{e?.fit(),n?.focus()}catch{}},0)},[t,n]),(0,E.jsx)(`div`,{className:t?`h-full min-h-0 w-full pl-2 md:pl-3`:`hidden`,"aria-hidden":!t,children:(0,E.jsx)(`div`,{ref:c,className:`h-full min-h-0 w-full`})})}var re=180,ie=.7,ae=320;function O(e,t){let n=t?t.name:`Terminal`,r=new Set(e.map(e=>e.name));if(n!==`Terminal`&&!r.has(n))return n;let i=1;for(;r.has(`${n} ${i}`);)i+=1;return`${n} ${i}`}function k(e,t){let n=e?.terminalShellProfiles||[],r=t||e?.defaultTerminalShellProfileId||``;return n.find(e=>e.id===r)||n[0]}function A({project:e,onCollapse:o,pendingCommand:l,onPendingCommandHandled:u,variant:d=`dock`,singleSession:m=!1,panelInstanceId:ee,panelSessionId:g,onPanelSessionReady:v}){let[w,te]=(0,_.useState)(null),[T,D]=(0,_.useState)([]),[A,j]=(0,_.useState)(),[M,oe]=(0,_.useState)(ae),[N,se]=(0,_.useState)(!0),[P,ce]=(0,_.useState)(!1),[le,F]=(0,_.useState)(),[ue,I]=(0,_.useState)({}),[L,R]=(0,_.useState)(!1),[z,de]=(0,_.useState)(!1),B=(0,_.useRef)(!1),V=(0,_.useRef)(!1),H=(0,_.useRef)(new Set),fe=(0,_.useRef)(l),U=(0,_.useRef)(new Set),W=(0,_.useRef)(new Set),G=(0,_.useRef)(new Map),K=(0,_.useRef)(!0),pe=(0,_.useRef)(v),[me,he]=(0,_.useState)(()=>new Set),ge=(0,_.useRef)(null),_e=(0,_.useRef)(null),q=e?.id,J=d===`panel`&&!!ee,Y=(0,_.useMemo)(()=>T.find(e=>e.id===A)??T[0],[A,T]);(0,_.useEffect)(()=>{fe.current=l},[l]),(0,_.useEffect)(()=>{pe.current=v},[v]),(0,_.useEffect)(()=>()=>{K.current=!1},[]);let ve=(0,_.useCallback)(async()=>{let e=await b(q);return D(e.sessions),j(t=>t&&e.sessions.some(e=>e.id===t)?t:e.sessions[0]?.id),e.sessions},[q]),ye=(0,_.useCallback)(async(e,t)=>{if(B.current)return;let n=k(w,t);B.current=!0,ce(!0),F(void 0),I({});try{let t=await x({projectId:q,name:O(e,n),cols:120,rows:30,shellProfileId:n?.id,shellProfileName:n?.name});D(e=>[...e,t]),j(t.id)}catch(e){F(e instanceof Error?e.message:p(`terminalCreateFailed`))}finally{B.current=!1,ce(!1)}},[w,q]);(0,_.useEffect)(()=>{let e=!1;return(async()=>{se(!0),F(void 0);try{let[t,n]=await Promise.all([y(),b(q)]);if(e)return;if(te(t),t.enabled&&J&&g&&n.sessions.some(e=>e.id===g)){V.current=!0,D(n.sessions),j(g);return}if(t.enabled&&J&&!V.current){V.current=!0;let r=k(t);try{let t=await x({projectId:q,name:O(n.sessions,r),cols:120,rows:30,shellProfileId:r?.id,shellProfileName:r?.name});if(e){S(t.id).catch(()=>{});return}D([...n.sessions,t]),j(t.id),pe.current?.(t.id);return}catch(t){e||F(t instanceof Error?t.message:p(`terminalCreateFailed`))}}if(D(n.sessions),j(n.sessions[0]?.id),t.enabled&&n.sessions.length===0&&!fe.current){let n=k(t);x({projectId:q,name:O([],n),cols:120,rows:30,shellProfileId:n?.id,shellProfileName:n?.name}).then(t=>{if(e){S(t.id).catch(()=>{});return}D([t]),j(t.id)}).catch(t=>{e||F(t instanceof Error?t.message:p(`terminalCreateFailed`))})}}catch(t){e||F(t instanceof Error?t.message:p(`terminalUnavailable`))}finally{e||se(!1)}})(),()=>{e=!0}},[J,g,q]),(0,_.useEffect)(()=>{if(!L)return;let e=e=>{_e.current?.contains(e.target)||R(!1)},t=e=>{e.key===`Escape`&&R(!1)};return document.addEventListener(`pointerdown`,e),document.addEventListener(`keydown`,t),()=>{document.removeEventListener(`pointerdown`,e),document.removeEventListener(`keydown`,t)}},[L]),(0,_.useEffect)(()=>{if(!z)return;let e=e=>{e.key===`Escape`&&de(!1)};return document.addEventListener(`keydown`,e),()=>document.removeEventListener(`keydown`,e)},[z]),(0,_.useEffect)(()=>{if(!l||H.current.has(l.id)||G.current.has(l.id)||U.current.has(l.id)||N||P||!w)return;if(!w.enabled){H.current.add(l.id),window.setTimeout(()=>{F(w.reason||p(`terminalUnavailable`)),u?.(l.id)},0);return}let e=Y&&!Y.exited?Y:T.find(e=>!e.exited);if(e){G.current.set(l.id,e.id),window.setTimeout(()=>{K.current&&j(e.id)},0);return}U.current.add(l.id),window.setTimeout(()=>{K.current&&F(void 0)},0);let t=k(w);x({projectId:q,name:O(T,t),cols:120,rows:30,shellProfileId:t?.id,shellProfileName:t?.name}).then(e=>{if(!K.current){S(e.id).catch(()=>{});return}G.current.set(l.id,e.id),D(t=>t.some(t=>t.id===e.id)?t:[...t,e]),j(e.id)}).catch(e=>{K.current&&(F(e instanceof Error?e.message:p(`terminalCommandExecuteFailed`)),H.current.add(l.id),u?.(l.id))}).finally(()=>{U.current.delete(l.id)})},[Y,w,P,N,u,l,q,T]),(0,_.useEffect)(()=>{if(!l||H.current.has(l.id)||W.current.has(l.id))return;let e=G.current.get(l.id),t=e?T.find(t=>t.id===e):Y&&!Y.exited?Y:T.find(e=>!e.exited);!t||t.exited||!me.has(t.id)||(W.current.add(l.id),window.setTimeout(()=>{K.current&&(j(t.id),F(void 0))},0),(async()=>{try{if(l.execute){let e=l.command.split(`
|
|
2
2
|
`),n=e.flatMap((t,n)=>n<e.length-1?[t,`\r`]:[t]);n.push(`\r`),await C(t.id,n.join(``))}else await C(t.id,l.command)}catch(e){K.current&&F(e instanceof Error?e.message:p(`terminalCommandExecuteFailed`))}finally{H.current.add(l.id),W.current.delete(l.id),G.current.delete(l.id),K.current&&u?.(l.id)}})())},[Y,u,l,me,T]);let be=async e=>{F(void 0),I(t=>{if(!t[e])return t;let n={...t};return delete n[e],n});let t=T.filter(t=>t.id!==e);D(t),A===e&&j(t[0]?.id);try{await S(e)}catch(e){F(e instanceof Error?e.message:p(`terminalCloseFailed`)),ve().catch(()=>{})}},xe=(0,_.useCallback)(e=>{D(t=>t.map(t=>t.id===e?{...t,exited:!0}:t)),he(t=>{if(!t.has(e))return t;let n=new Set(t);return n.delete(e),n})},[]),Se=(0,_.useCallback)(e=>{he(t=>{if(t.has(e))return t;let n=new Set(t);return n.add(e),n})},[]),Ce=(0,_.useCallback)((e,t)=>{I(n=>{if(!t){if(!n[e])return n;let t={...n};return delete t[e],t}return n[e]===t?n:{...n,[e]:t}})},[]),we=e=>{ge.current={startY:e.clientY,startHeight:M},e.currentTarget.setPointerCapture(e.pointerId)},Te=e=>{let t=ge.current;if(!t)return;let n=Math.max(re,Math.floor(window.innerHeight*ie));oe(Math.min(n,Math.max(re,t.startHeight+t.startY-e.clientY)))},Ee=e=>{ge.current=null;try{e.currentTarget.releasePointerCapture(e.pointerId)}catch{}},X=w?.terminalShellProfiles||[],De=w?.defaultTerminalShellProfileId||``,Oe=X.find(e=>e.id===De)||X[0],ke=!!(w&&T.length>=w.maxSessions),Ae=P||ke,je=Y?ue[Y.id]:void 0,Me=J&&Y?[Y]:T,Z=le??je,Q=d===`panel`,$=Q&&m,Ne=Q?void 0:z?Z?`calc(100% - 4.25rem)`:`calc(100% - 2.25rem)`:Z?M-72:M-45;return(0,E.jsxs)(`div`,{className:f(Q?`flex min-h-0 flex-1 flex-col bg-background`:`shrink-0 border-t border-border bg-background`,z&&`quickforge-terminal-fullscreen z-40 flex flex-col border-t-0`),style:z||Q?void 0:{height:M},children:[!z&&!Q?(0,E.jsx)(`div`,{className:`h-1 cursor-row-resize bg-transparent hover:bg-border`,onPointerDown:we,onPointerMove:Te,onPointerUp:Ee,onPointerCancel:Ee}):null,(0,E.jsxs)(`div`,{className:`flex h-9 items-center gap-1 border-b border-border px-2`,children:[(0,E.jsx)(s,{className:`size-4 shrink-0 text-muted-foreground/60`}),(0,E.jsx)(`div`,{className:`flex min-w-0 flex-1 items-center gap-1 overflow-x-auto`,children:Me.map(e=>{let t=f(`flex max-w-44 shrink-0 items-center gap-1 rounded-md px-2 py-1 text-xs text-muted-foreground/72`,Y?.id===e.id&&`bg-muted/28 text-foreground/90`);return $?(0,E.jsxs)(`div`,{className:t,title:`${e.name} — ${e.cwd}`,children:[(0,E.jsx)(`span`,{className:f(`size-1.5 rounded-full`,e.exited?`bg-muted-foreground/40`:`bg-emerald-500/80`)}),(0,E.jsx)(`span`,{className:`truncate`,children:e.name})]},e.id):(0,E.jsxs)(`button`,{type:`button`,className:f(t,`hover:bg-muted/20 hover:text-foreground/85`),onClick:()=>j(e.id),title:`${e.name} — ${e.cwd}`,children:[(0,E.jsx)(`span`,{className:f(`size-1.5 rounded-full`,e.exited?`bg-muted-foreground/40`:`bg-emerald-500/80`)}),(0,E.jsx)(`span`,{className:`truncate`,children:e.name}),(0,E.jsx)(`span`,{role:`button`,tabIndex:0,className:`ml-1 rounded-sm p-0.5 opacity-60 hover:bg-background hover:opacity-100`,onClick:t=>{t.stopPropagation(),be(e.id)},onKeyDown:t=>{(t.key===`Enter`||t.key===` `)&&(t.preventDefault(),t.stopPropagation(),be(e.id))},"aria-label":p(`terminalCloseSession`,{name:e.name}),children:(0,E.jsx)(c,{className:`size-3`})})]},e.id)})}),$?null:(0,E.jsxs)(`div`,{className:`relative shrink-0`,ref:_e,children:[(0,E.jsxs)(`div`,{className:`flex items-center overflow-hidden rounded-md border border-border bg-background`,children:[(0,E.jsx)(`button`,{type:`button`,className:`inline-flex h-7 w-7 items-center justify-center text-foreground/85 transition-colors hover:bg-muted/20 disabled:pointer-events-none disabled:opacity-50`,onClick:()=>void ye(T),disabled:Ae,title:Oe?p(`terminalNewWithProfile`,{name:Oe.name}):p(`terminalNew`),"aria-label":p(`terminalNew`),children:P?(0,E.jsx)(n,{className:`size-3.5 animate-spin`}):(0,E.jsx)(r,{className:`size-3.5`})}),X.length>0?(0,E.jsx)(`button`,{type:`button`,className:`inline-flex h-7 w-7 items-center justify-center border-l border-border text-muted-foreground/72 transition-colors hover:bg-muted/20 hover:text-foreground/85 disabled:pointer-events-none disabled:opacity-50`,onClick:()=>R(e=>!e),disabled:Ae,title:p(`terminalSelectShell`),"aria-label":p(`terminalSelectShell`),"aria-expanded":L,children:(0,E.jsx)(t,{className:`size-3.5`})}):null]}),L?(0,E.jsxs)(`div`,{className:f(`absolute right-0 z-30 w-64 overflow-hidden rounded-lg border border-border bg-background p-1.5 shadow-[0_16px_38px_-22px_rgb(15_23_42_/_0.65)]`,Q?`top-9`:`bottom-9`),children:[(0,E.jsx)(`div`,{className:`px-2 pb-1.5 pt-1 text-[11px] font-medium uppercase tracking-wide text-muted-foreground/60`,children:p(`terminalNewWith`)}),X.map(e=>(0,E.jsxs)(`button`,{type:`button`,className:`flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-left text-xs text-muted-foreground/80 hover:bg-muted/20 hover:text-foreground/90`,onClick:()=>{R(!1),ye(T,e.id)},children:[(0,E.jsx)(`span`,{className:`inline-flex size-5 shrink-0 items-center justify-center rounded bg-muted/20 text-[10px] text-muted-foreground/70`,children:e.name.slice(0,1).toUpperCase()}),(0,E.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,E.jsx)(`span`,{className:`block truncate font-medium`,children:e.name}),(0,E.jsx)(`span`,{className:`block truncate font-mono text-[11px] text-muted-foreground/55`,children:e.command})]})]},e.id))]}):null]}),$?null:(0,E.jsx)(h,{variant:`ghost`,size:`icon`,className:`size-7`,onClick:()=>de(e=>!e),title:p(z?`terminalExitFullscreen`:`terminalFullscreen`),"aria-label":p(z?`terminalExitFullscreen`:`terminalFullscreen`),children:z?(0,E.jsx)(i,{className:`size-3.5`}):(0,E.jsx)(a,{className:`size-3.5`})}),(0,E.jsx)(h,{variant:`ghost`,size:`icon`,className:f(`size-7`,Q&&`hidden`),onClick:o,title:p(`terminalCollapse`),"aria-label":p(`terminalCollapse`),children:(0,E.jsx)(t,{className:`size-3.5`})})]}),Z?(0,E.jsx)(`div`,{className:`border-b border-border px-3 py-1.5 text-xs text-destructive`,children:Z}):null,(0,E.jsx)(`div`,{className:f(`min-h-0 bg-background`,Q&&`flex-1`),style:Ne===void 0?void 0:{height:Ne},children:N?(0,E.jsxs)(`div`,{className:`flex h-full items-center justify-center gap-2 text-xs text-muted-foreground/60`,children:[(0,E.jsx)(n,{className:`size-4 animate-spin`}),` `,p(`terminalStarting`)]}):w&&!w.enabled?(0,E.jsx)(`div`,{className:`flex h-full items-center justify-center px-4 text-center text-xs text-muted-foreground/60`,children:w.reason||p(`terminalUnavailable`)}):T.length===0?(0,E.jsx)(`div`,{className:`flex h-full items-center justify-center text-xs text-muted-foreground/60`,children:p(`terminalNoSessions`)}):T.map(e=>(0,E.jsx)(ne,{session:e,active:e.id===Y?.id,height:z?window.innerHeight-36:Q?0:M,onReady:Se,onExited:xe,onConnectionError:Ce},e.id))})]})}export{A as TerminalDock,T as t};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{i as e}from"./rolldown-runtime-DWdDZTNf.js";import{$ as t,At as n,B as r,C as i,Et as a,It as o,K as s,M as c,N as l,Ot as u,P as d,Q as f,R as p,Rt as m,U as h,Vt as g,W as _,Y as v,Z as ee,_ as y,_t as b,at as x,b as te,c as S,ct as C,et as ne,ft as re,gt as ie,ht as ae,jt as oe,lt as w,mt as se,n as ce,nt as le,o as ue,ot as T,pt as de,q as E,rt as fe,st as D,tt as pe,ut as me,v as he,x as ge}from"./icons-C7j5jdKo.js";import{n as _e}from"./react-vendor-VqdnQHHS.js";import{H as ve,N as ye,V as be,_ as xe,a as Se,b as Ce,d as we,dt as O,f as Te,g as Ee,h as De,ht as k,i as Oe,j as ke,lt as Ae,m as je,n as A,o as Me,p as Ne,r as j,t as M,u as Pe,ut as N,v as Fe,y as Ie}from"./index-DKmdePUP.js";import{n as Le,r as Re,t as P}from"./mermaid-renderer-BmbSAmpG.js";import{TerminalDock as ze,t as Be}from"./TerminalDock-wgW7kSC4.js";import{n as F,t as Ve}from"./monaco-CdOyGlWD.js";var I=e(g(),1),L=_e();function He(e){let t=e.trim();if(!t.startsWith(`/api/workspace/preview/`))return!1;try{let e=new URL(t,window.location.origin);return e.origin===window.location.origin&&e.pathname.startsWith(`/api/workspace/preview/`)}catch{return!1}}function Ue(e){let t=e.trim().replace(/\\/g,`/`);return t.startsWith(`/`)||/^[a-zA-Z]:\//.test(t)}function We(e,t){let n=e.trim();if(!t||!He(n))return n;try{let e=new URL(n,window.location.origin),r=`/api/workspace/preview/${encodeURIComponent(t)}/`;return e.pathname.startsWith(r)?e.pathname.slice(r.length).split(`/`).map(e=>decodeURIComponent(e)).join(`/`):n}catch{return n}}function Ge(e,t){let n=e.trim();if(!n)return{url:``,displayUrl:``,error:``};if(He(n)){let e=new URL(n,window.location.origin);return{url:`${e.pathname}${e.search}${e.hash}`,displayUrl:We(n,t),error:``}}if(t&&Ue(n))return{url:Me(t,n),displayUrl:n,error:``};let r=/^https?:\/\//i.test(n)?n:`http://${n}`;try{let e=new URL(r);return e.protocol!==`http:`&&e.protocol!==`https:`?{url:``,displayUrl:n,error:k(`invalidPreviewUrl`)}:{url:e.toString(),displayUrl:e.toString(),error:``}}catch{return{url:``,displayUrl:n,error:k(`invalidPreviewUrl`)}}}function Ke({url:e,onUrlChange:t,projectId:n}){let r=(0,I.useMemo)(()=>Ge(e,n),[n,e]),[a,o]=(0,I.useState)({sourceUrl:e,value:r.displayUrl}),[s,l]=(0,I.useState)(``),[u,d]=(0,I.useState)(0),[f,p]=(0,I.useState)(!1),[h,g]=(0,I.useState)(100),v=(0,I.useRef)(null),ee=(0,I.useRef)(null),y=r.url,b=y.startsWith(`/api/workspace/preview/`)?`allow-scripts allow-same-origin allow-forms`:`allow-scripts allow-same-origin allow-forms allow-popups allow-downloads allow-modals allow-pointer-lock`,x=a.sourceUrl===e?a.value:r.displayUrl;(0,I.useEffect)(()=>{if(!f)return;function e(e){v.current?.contains(e.target)||p(!1)}return document.addEventListener(`pointerdown`,e),()=>document.removeEventListener(`pointerdown`,e)},[f]);function te(){try{ee.current?.contentWindow?.history.back()}catch{}}function S(e=x){let r=Ge(e,n);if(r.error){l(r.error);return}l(``),o({sourceUrl:r.displayUrl,value:r.displayUrl}),t(r.displayUrl),r.url&&d(e=>e+1)}function C(){y&&d(e=>e+1)}function ne(){y&&window.open(y,`_blank`,`noopener,noreferrer`)}return(0,L.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col`,children:[(0,L.jsxs)(`div`,{className:`flex shrink-0 flex-col gap-2 border-b border-border p-3`,children:[(0,L.jsxs)(`form`,{className:`flex items-center gap-2`,onSubmit:e=>{e.preventDefault(),S()},children:[(0,L.jsx)(N,{type:`button`,variant:`ghost`,size:`icon`,onClick:te,disabled:!y,"aria-label":k(`back`),title:k(`back`),children:(0,L.jsx)(m,{className:`size-4`})}),(0,L.jsx)(N,{type:`button`,variant:`ghost`,size:`icon`,onClick:C,disabled:!y,"aria-label":k(`refreshPreview`),title:k(`refreshPreview`),children:(0,L.jsx)(ge,{className:`size-4`})}),(0,L.jsxs)(`label`,{className:`mx-auto flex h-9 min-w-0 max-w-xl flex-1 items-center rounded-full border border-[color-mix(in_oklab,var(--border)_42%,transparent)] bg-muted/30 px-3 text-sm text-muted-foreground/65 focus-within:bg-background focus-within:text-foreground/85`,children:[(0,L.jsx)(`span`,{className:`sr-only`,children:k(`previewUrl`)}),(0,L.jsx)(`input`,{value:x,onChange:t=>{o({sourceUrl:e,value:t.target.value}),s&&l(``)},placeholder:k(`previewUrlPlaceholder`),className:`min-w-0 flex-1 bg-transparent text-center text-sm text-foreground/85 outline-none placeholder:text-muted-foreground/55`})]}),(0,L.jsx)(N,{type:`button`,variant:`ghost`,size:`icon`,onClick:ne,disabled:!y,"aria-label":k(`openInBrowser`),title:k(`openInBrowser`),children:(0,L.jsx)(me,{className:`size-4`})}),(0,L.jsxs)(`div`,{ref:v,className:`relative shrink-0`,children:[(0,L.jsx)(N,{type:`button`,variant:`ghost`,size:`icon`,onClick:()=>p(e=>!e),"aria-label":k(`more`),title:k(`more`),"aria-haspopup":`menu`,"aria-expanded":f,children:(0,L.jsx)(re,{className:`size-4`})}),f?(0,L.jsxs)(`div`,{className:`absolute right-0 top-10 z-30 w-48 rounded-2xl border border-[color-mix(in_oklab,var(--border)_34%,transparent)] bg-popover p-2 shadow-quickforge`,role:`menu`,children:[(0,L.jsx)(`div`,{className:`px-2 py-1.5 text-xs font-medium text-muted-foreground`,children:k(`zoom`)}),(0,L.jsxs)(`div`,{className:`flex items-center justify-between gap-2 rounded-xl px-1 py-1.5`,children:[(0,L.jsx)(N,{type:`button`,variant:`ghost`,size:`icon`,className:`size-8`,onClick:()=>g(e=>Math.max(50,e-10)),"aria-label":k(`zoomOut`),title:k(`zoomOut`),children:(0,L.jsx)(c,{className:`size-4`})}),(0,L.jsxs)(`button`,{type:`button`,className:`min-w-14 rounded-lg px-2 py-1 text-sm font-medium text-foreground/85 hover:bg-muted/50`,onClick:()=>g(100),title:k(`resetZoom`),children:[h,`%`]}),(0,L.jsx)(N,{type:`button`,variant:`ghost`,size:`icon`,className:`size-8`,onClick:()=>g(e=>Math.min(200,e+10)),"aria-label":k(`zoomIn`),title:k(`zoomIn`),children:(0,L.jsx)(i,{className:`size-4`})})]})]}):null]})]}),s?(0,L.jsx)(`div`,{className:`text-xs text-destructive`,children:s}):null]}),(0,L.jsx)(`div`,{className:`min-h-0 flex-1 bg-muted/10`,children:y?(0,L.jsx)(`div`,{className:`h-full w-full overflow-auto bg-background`,children:(0,L.jsx)(`iframe`,{ref:ee,title:k(`webPreview`),src:y,sandbox:b,className:`origin-top-left border-0 bg-background`,style:{width:`${1e4/h}%`,height:`${1e4/h}%`,transform:`scale(${h/100})`}},`${y}:${u}`)}):(0,L.jsxs)(`div`,{className:`flex h-full flex-col items-center justify-center px-8 text-center`,children:[(0,L.jsx)(_,{className:`size-20 stroke-[1.55] text-muted-foreground/75`}),(0,L.jsx)(`div`,{className:`mt-8 text-xl font-semibold tracking-tight text-foreground/88`,children:k(`noPreviewUrlTitle`)}),(0,L.jsx)(`div`,{className:`mt-4 max-w-xs text-base leading-6 text-muted-foreground/82`,children:k(`noPreviewUrlDescription`)})]})})]})}function qe({source:e}){let[t,n]=(0,I.useState)({source:e,value:`preview`}),[r,i]=(0,I.useState)({source:``,dataUrl:``,error:!1});(0,I.useEffect)(()=>{let t=!1;return Re(e).then(n=>{t||i({source:e,dataUrl:P(n),error:!1})}).catch(()=>{t||i({source:e,dataUrl:``,error:!0})}),()=>{t=!0}},[e]);let a=r.source===e?r:{source:e,dataUrl:``,error:!1},o=t.source===e?t.value:`preview`,s=r.source!==e,c=o===`source`||a.error;return(0,L.jsxs)(`figure`,{className:`my-5 overflow-hidden rounded-xl border border-border bg-muted/20`,children:[(0,L.jsxs)(`figcaption`,{className:`flex min-h-9 items-center justify-between gap-3 border-b border-border px-3 py-1.5`,children:[(0,L.jsx)(`span`,{className:`font-mono text-[11px] text-muted-foreground/65`,children:`mermaid`}),(0,L.jsxs)(`span`,{className:`inline-flex items-center gap-1 rounded-md bg-background/70 p-0.5`,children:[(0,L.jsx)(`button`,{type:`button`,className:`rounded px-2 py-1 text-[11px] text-muted-foreground transition-colors hover:text-foreground disabled:cursor-not-allowed disabled:opacity-40`,disabled:!a.dataUrl,"aria-pressed":!c,onClick:()=>n({source:e,value:`preview`}),children:k(`svgPreviewMode`)}),(0,L.jsx)(`button`,{type:`button`,className:`rounded px-2 py-1 text-[11px] text-muted-foreground transition-colors hover:text-foreground`,"aria-pressed":c,onClick:()=>n({source:e,value:`source`}),children:k(`svgSourceMode`)})]})]}),s?(0,L.jsx)(`div`,{className:`flex min-h-28 items-center justify-center px-4 py-8 text-xs text-muted-foreground/70`,role:`status`,children:k(`mermaidRendering`)}):c?(0,L.jsxs)(L.Fragment,{children:[a.error?(0,L.jsx)(`p`,{className:`px-4 pt-3 text-xs text-muted-foreground`,children:k(`mermaidRenderFailed`)}):null,(0,L.jsx)(`pre`,{className:`overflow-auto p-4 text-[12px] leading-5`,children:(0,L.jsx)(`code`,{children:e})})]}):(0,L.jsx)(`div`,{className:`flex min-h-28 justify-center overflow-auto bg-background/45 p-4`,children:(0,L.jsx)(`img`,{className:`h-auto max-w-full object-contain`,src:a.dataUrl,alt:k(`mermaidPreviewLabel`)})})]})}function Je(){let[e,t]=(0,I.useState)(()=>ye());return(0,I.useEffect)(()=>{if(typeof window>`u`)return;let e=()=>t(ye());return window.addEventListener(ke,e),()=>window.removeEventListener(ke,e)},[]),e}function Ye({path:e,content:t,language:n}){let r=Be(),i=Je();return(0,L.jsx)(Ve,{value:t,language:n,theme:r===`dark`?`vs-dark`:`vs`,options:{readOnly:!0,contextmenu:!1,automaticLayout:!0,minimap:{enabled:!1},fontFamily:getComputedStyle(document.documentElement).getPropertyValue(`--font-mono`).trim()||`ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace`,fontSize:i.fontSize,lineHeight:i.lineHeight,lineNumbers:`on`,scrollBeyondLastLine:!1,wordWrap:`off`,renderLineHighlight:`line`,folding:!1,glyphMargin:!1,scrollbar:{horizontal:`visible`,horizontalScrollbarSize:10,verticalScrollbarSize:8}}},e)}function Xe(e){let t=e.trim();if(t&&!/^(javascript|data|vbscript):/i.test(t)&&/^(https?:|mailto:|#|\/|\.\.?\/)/i.test(t))return t}function R(e,t){let n=[],r=/`([^`]+)`|\[([^\]]+)\]\(([^)\s]+)(?:\s+"[^"]*")?\)|\*\*([^*]+)\*\*|__([^_]+)__|\*([^*\n]+)\*|_([^_\n]+)_/g,i=0,a=0,o;for(;o=r.exec(e);){o.index>i&&n.push(e.slice(i,o.index));let s=`${t}-inline-${a++}`;if(o[1])n.push((0,L.jsx)(`code`,{className:`rounded bg-muted/35 px-1 py-0.5 font-mono text-[0.85em] text-foreground/90`,children:o[1]},s));else if(o[2]&&o[3]){let e=Xe(o[3]);n.push(e?(0,L.jsx)(`a`,{className:`text-primary underline-offset-4 hover:underline`,href:e,target:e.startsWith(`http`)?`_blank`:void 0,rel:`noreferrer`,children:o[2]},s):`[${o[2]}](${o[3]})`)}else o[4]||o[5]?n.push((0,L.jsx)(`strong`,{className:`font-semibold text-foreground/95`,children:o[4]||o[5]},s)):(o[6]||o[7])&&n.push((0,L.jsx)(`em`,{className:`italic`,children:o[6]||o[7]},s));i=r.lastIndex}return i<e.length&&n.push(e.slice(i)),n.length?n:[e]}function Ze(e,t){return e.split(`
|
|
1
|
+
import{i as e}from"./rolldown-runtime-DWdDZTNf.js";import{$ as t,At as n,B as r,C as i,Et as a,It as o,K as s,M as c,N as l,Ot as u,P as d,Q as f,R as p,Rt as m,U as h,Vt as g,W as _,Y as v,Z as ee,_ as y,_t as b,at as x,b as te,c as S,ct as C,et as ne,ft as re,gt as ie,ht as ae,jt as oe,lt as w,mt as se,n as ce,nt as le,o as ue,ot as T,pt as de,q as E,rt as fe,st as D,tt as pe,ut as me,v as he,x as ge}from"./icons-C7j5jdKo.js";import{n as _e}from"./react-vendor-VqdnQHHS.js";import{H as ve,N as ye,V as be,_ as xe,a as Se,b as Ce,d as we,dt as O,f as Te,g as Ee,h as De,ht as k,i as Oe,j as ke,lt as Ae,m as je,n as A,o as Me,p as Ne,r as j,t as M,u as Pe,ut as N,v as Fe,y as Ie}from"./index-DxNzlPmc.js";import{n as Le,r as Re,t as P}from"./mermaid-renderer-BmbSAmpG.js";import{TerminalDock as ze,t as Be}from"./TerminalDock-CvqBBMPg.js";import{n as F,t as Ve}from"./monaco-CdOyGlWD.js";var I=e(g(),1),L=_e();function He(e){let t=e.trim();if(!t.startsWith(`/api/workspace/preview/`))return!1;try{let e=new URL(t,window.location.origin);return e.origin===window.location.origin&&e.pathname.startsWith(`/api/workspace/preview/`)}catch{return!1}}function Ue(e){let t=e.trim().replace(/\\/g,`/`);return t.startsWith(`/`)||/^[a-zA-Z]:\//.test(t)}function We(e,t){let n=e.trim();if(!t||!He(n))return n;try{let e=new URL(n,window.location.origin),r=`/api/workspace/preview/${encodeURIComponent(t)}/`;return e.pathname.startsWith(r)?e.pathname.slice(r.length).split(`/`).map(e=>decodeURIComponent(e)).join(`/`):n}catch{return n}}function Ge(e,t){let n=e.trim();if(!n)return{url:``,displayUrl:``,error:``};if(He(n)){let e=new URL(n,window.location.origin);return{url:`${e.pathname}${e.search}${e.hash}`,displayUrl:We(n,t),error:``}}if(t&&Ue(n))return{url:Me(t,n),displayUrl:n,error:``};let r=/^https?:\/\//i.test(n)?n:`http://${n}`;try{let e=new URL(r);return e.protocol!==`http:`&&e.protocol!==`https:`?{url:``,displayUrl:n,error:k(`invalidPreviewUrl`)}:{url:e.toString(),displayUrl:e.toString(),error:``}}catch{return{url:``,displayUrl:n,error:k(`invalidPreviewUrl`)}}}function Ke({url:e,onUrlChange:t,projectId:n}){let r=(0,I.useMemo)(()=>Ge(e,n),[n,e]),[a,o]=(0,I.useState)({sourceUrl:e,value:r.displayUrl}),[s,l]=(0,I.useState)(``),[u,d]=(0,I.useState)(0),[f,p]=(0,I.useState)(!1),[h,g]=(0,I.useState)(100),v=(0,I.useRef)(null),ee=(0,I.useRef)(null),y=r.url,b=y.startsWith(`/api/workspace/preview/`)?`allow-scripts allow-same-origin allow-forms`:`allow-scripts allow-same-origin allow-forms allow-popups allow-downloads allow-modals allow-pointer-lock`,x=a.sourceUrl===e?a.value:r.displayUrl;(0,I.useEffect)(()=>{if(!f)return;function e(e){v.current?.contains(e.target)||p(!1)}return document.addEventListener(`pointerdown`,e),()=>document.removeEventListener(`pointerdown`,e)},[f]);function te(){try{ee.current?.contentWindow?.history.back()}catch{}}function S(e=x){let r=Ge(e,n);if(r.error){l(r.error);return}l(``),o({sourceUrl:r.displayUrl,value:r.displayUrl}),t(r.displayUrl),r.url&&d(e=>e+1)}function C(){y&&d(e=>e+1)}function ne(){y&&window.open(y,`_blank`,`noopener,noreferrer`)}return(0,L.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col`,children:[(0,L.jsxs)(`div`,{className:`flex shrink-0 flex-col gap-2 border-b border-border p-3`,children:[(0,L.jsxs)(`form`,{className:`flex items-center gap-2`,onSubmit:e=>{e.preventDefault(),S()},children:[(0,L.jsx)(N,{type:`button`,variant:`ghost`,size:`icon`,onClick:te,disabled:!y,"aria-label":k(`back`),title:k(`back`),children:(0,L.jsx)(m,{className:`size-4`})}),(0,L.jsx)(N,{type:`button`,variant:`ghost`,size:`icon`,onClick:C,disabled:!y,"aria-label":k(`refreshPreview`),title:k(`refreshPreview`),children:(0,L.jsx)(ge,{className:`size-4`})}),(0,L.jsxs)(`label`,{className:`mx-auto flex h-9 min-w-0 max-w-xl flex-1 items-center rounded-full border border-[color-mix(in_oklab,var(--border)_42%,transparent)] bg-muted/30 px-3 text-sm text-muted-foreground/65 focus-within:bg-background focus-within:text-foreground/85`,children:[(0,L.jsx)(`span`,{className:`sr-only`,children:k(`previewUrl`)}),(0,L.jsx)(`input`,{value:x,onChange:t=>{o({sourceUrl:e,value:t.target.value}),s&&l(``)},placeholder:k(`previewUrlPlaceholder`),className:`min-w-0 flex-1 bg-transparent text-center text-sm text-foreground/85 outline-none placeholder:text-muted-foreground/55`})]}),(0,L.jsx)(N,{type:`button`,variant:`ghost`,size:`icon`,onClick:ne,disabled:!y,"aria-label":k(`openInBrowser`),title:k(`openInBrowser`),children:(0,L.jsx)(me,{className:`size-4`})}),(0,L.jsxs)(`div`,{ref:v,className:`relative shrink-0`,children:[(0,L.jsx)(N,{type:`button`,variant:`ghost`,size:`icon`,onClick:()=>p(e=>!e),"aria-label":k(`more`),title:k(`more`),"aria-haspopup":`menu`,"aria-expanded":f,children:(0,L.jsx)(re,{className:`size-4`})}),f?(0,L.jsxs)(`div`,{className:`absolute right-0 top-10 z-30 w-48 rounded-2xl border border-[color-mix(in_oklab,var(--border)_34%,transparent)] bg-popover p-2 shadow-quickforge`,role:`menu`,children:[(0,L.jsx)(`div`,{className:`px-2 py-1.5 text-xs font-medium text-muted-foreground`,children:k(`zoom`)}),(0,L.jsxs)(`div`,{className:`flex items-center justify-between gap-2 rounded-xl px-1 py-1.5`,children:[(0,L.jsx)(N,{type:`button`,variant:`ghost`,size:`icon`,className:`size-8`,onClick:()=>g(e=>Math.max(50,e-10)),"aria-label":k(`zoomOut`),title:k(`zoomOut`),children:(0,L.jsx)(c,{className:`size-4`})}),(0,L.jsxs)(`button`,{type:`button`,className:`min-w-14 rounded-lg px-2 py-1 text-sm font-medium text-foreground/85 hover:bg-muted/50`,onClick:()=>g(100),title:k(`resetZoom`),children:[h,`%`]}),(0,L.jsx)(N,{type:`button`,variant:`ghost`,size:`icon`,className:`size-8`,onClick:()=>g(e=>Math.min(200,e+10)),"aria-label":k(`zoomIn`),title:k(`zoomIn`),children:(0,L.jsx)(i,{className:`size-4`})})]})]}):null]})]}),s?(0,L.jsx)(`div`,{className:`text-xs text-destructive`,children:s}):null]}),(0,L.jsx)(`div`,{className:`min-h-0 flex-1 bg-muted/10`,children:y?(0,L.jsx)(`div`,{className:`h-full w-full overflow-auto bg-background`,children:(0,L.jsx)(`iframe`,{ref:ee,title:k(`webPreview`),src:y,sandbox:b,className:`origin-top-left border-0 bg-background`,style:{width:`${1e4/h}%`,height:`${1e4/h}%`,transform:`scale(${h/100})`}},`${y}:${u}`)}):(0,L.jsxs)(`div`,{className:`flex h-full flex-col items-center justify-center px-8 text-center`,children:[(0,L.jsx)(_,{className:`size-20 stroke-[1.55] text-muted-foreground/75`}),(0,L.jsx)(`div`,{className:`mt-8 text-xl font-semibold tracking-tight text-foreground/88`,children:k(`noPreviewUrlTitle`)}),(0,L.jsx)(`div`,{className:`mt-4 max-w-xs text-base leading-6 text-muted-foreground/82`,children:k(`noPreviewUrlDescription`)})]})})]})}function qe({source:e}){let[t,n]=(0,I.useState)({source:e,value:`preview`}),[r,i]=(0,I.useState)({source:``,dataUrl:``,error:!1});(0,I.useEffect)(()=>{let t=!1;return Re(e).then(n=>{t||i({source:e,dataUrl:P(n),error:!1})}).catch(()=>{t||i({source:e,dataUrl:``,error:!0})}),()=>{t=!0}},[e]);let a=r.source===e?r:{source:e,dataUrl:``,error:!1},o=t.source===e?t.value:`preview`,s=r.source!==e,c=o===`source`||a.error;return(0,L.jsxs)(`figure`,{className:`my-5 overflow-hidden rounded-xl border border-border bg-muted/20`,children:[(0,L.jsxs)(`figcaption`,{className:`flex min-h-9 items-center justify-between gap-3 border-b border-border px-3 py-1.5`,children:[(0,L.jsx)(`span`,{className:`font-mono text-[11px] text-muted-foreground/65`,children:`mermaid`}),(0,L.jsxs)(`span`,{className:`inline-flex items-center gap-1 rounded-md bg-background/70 p-0.5`,children:[(0,L.jsx)(`button`,{type:`button`,className:`rounded px-2 py-1 text-[11px] text-muted-foreground transition-colors hover:text-foreground disabled:cursor-not-allowed disabled:opacity-40`,disabled:!a.dataUrl,"aria-pressed":!c,onClick:()=>n({source:e,value:`preview`}),children:k(`svgPreviewMode`)}),(0,L.jsx)(`button`,{type:`button`,className:`rounded px-2 py-1 text-[11px] text-muted-foreground transition-colors hover:text-foreground`,"aria-pressed":c,onClick:()=>n({source:e,value:`source`}),children:k(`svgSourceMode`)})]})]}),s?(0,L.jsx)(`div`,{className:`flex min-h-28 items-center justify-center px-4 py-8 text-xs text-muted-foreground/70`,role:`status`,children:k(`mermaidRendering`)}):c?(0,L.jsxs)(L.Fragment,{children:[a.error?(0,L.jsx)(`p`,{className:`px-4 pt-3 text-xs text-muted-foreground`,children:k(`mermaidRenderFailed`)}):null,(0,L.jsx)(`pre`,{className:`overflow-auto p-4 text-[12px] leading-5`,children:(0,L.jsx)(`code`,{children:e})})]}):(0,L.jsx)(`div`,{className:`flex min-h-28 justify-center overflow-auto bg-background/45 p-4`,children:(0,L.jsx)(`img`,{className:`h-auto max-w-full object-contain`,src:a.dataUrl,alt:k(`mermaidPreviewLabel`)})})]})}function Je(){let[e,t]=(0,I.useState)(()=>ye());return(0,I.useEffect)(()=>{if(typeof window>`u`)return;let e=()=>t(ye());return window.addEventListener(ke,e),()=>window.removeEventListener(ke,e)},[]),e}function Ye({path:e,content:t,language:n}){let r=Be(),i=Je();return(0,L.jsx)(Ve,{value:t,language:n,theme:r===`dark`?`vs-dark`:`vs`,options:{readOnly:!0,contextmenu:!1,automaticLayout:!0,minimap:{enabled:!1},fontFamily:getComputedStyle(document.documentElement).getPropertyValue(`--font-mono`).trim()||`ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace`,fontSize:i.fontSize,lineHeight:i.lineHeight,lineNumbers:`on`,scrollBeyondLastLine:!1,wordWrap:`off`,renderLineHighlight:`line`,folding:!1,glyphMargin:!1,scrollbar:{horizontal:`visible`,horizontalScrollbarSize:10,verticalScrollbarSize:8}}},e)}function Xe(e){let t=e.trim();if(t&&!/^(javascript|data|vbscript):/i.test(t)&&/^(https?:|mailto:|#|\/|\.\.?\/)/i.test(t))return t}function R(e,t){let n=[],r=/`([^`]+)`|\[([^\]]+)\]\(([^)\s]+)(?:\s+"[^"]*")?\)|\*\*([^*]+)\*\*|__([^_]+)__|\*([^*\n]+)\*|_([^_\n]+)_/g,i=0,a=0,o;for(;o=r.exec(e);){o.index>i&&n.push(e.slice(i,o.index));let s=`${t}-inline-${a++}`;if(o[1])n.push((0,L.jsx)(`code`,{className:`rounded bg-muted/35 px-1 py-0.5 font-mono text-[0.85em] text-foreground/90`,children:o[1]},s));else if(o[2]&&o[3]){let e=Xe(o[3]);n.push(e?(0,L.jsx)(`a`,{className:`text-primary underline-offset-4 hover:underline`,href:e,target:e.startsWith(`http`)?`_blank`:void 0,rel:`noreferrer`,children:o[2]},s):`[${o[2]}](${o[3]})`)}else o[4]||o[5]?n.push((0,L.jsx)(`strong`,{className:`font-semibold text-foreground/95`,children:o[4]||o[5]},s)):(o[6]||o[7])&&n.push((0,L.jsx)(`em`,{className:`italic`,children:o[6]||o[7]},s));i=r.lastIndex}return i<e.length&&n.push(e.slice(i)),n.length?n:[e]}function Ze(e,t){return e.split(`
|
|
2
2
|
`).flatMap((e,n)=>{let r=R(e,`${t}-line-${n}`);return n===0?r:[(0,L.jsx)(`br`,{},`${t}-br-${n}`),...r]})}function z(e){return/^\s*(```|~~~)/.test(e)}function Qe(e){return/^\s*\|?\s*:?-{3,}:?\s*(\|\s*:?-{3,}:?\s*)+\|?\s*$/.test(e)}function $e(e,t){return!!(e[t]?.includes(`|`)&&e[t+1]&&Qe(e[t+1]))}function et(e,t){let n=e[t]??``;return z(n)||$e(e,t)||/^\s{0,3}#{1,6}\s+/.test(n)||/^\s{0,3}([-*_])(?:\s*\1){2,}\s*$/.test(n)||/^\s{0,3}>\s?/.test(n)||/^\s{0,3}[-*+]\s+/.test(n)||/^\s{0,3}\d+[.)]\s+/.test(n)}function B(e){return e.trim().replace(/^\|/,``).replace(/\|$/,``).split(`|`).map(e=>e.trim())}function tt(e){let t=e.replace(/\r\n?/g,`
|
|
3
3
|
`).split(`
|
|
4
4
|
`),n=[],r=0,i=0;for(;r<t.length;){let e=t[r],a=`markdown-block-${i++}`;if(!e.trim()){r+=1;continue}if(z(e)){let i=e.match(/^\s*(```|~~~)\s*([^`]*)$/),o=i?.[1]??"```",s=i?.[2]?.trim(),c=[];for(r+=1;r<t.length&&!t[r].trimStart().startsWith(o);)c.push(t[r]),r+=1;r<t.length&&(r+=1);let l=c.join(`
|