dal-code 1.0.26 → 1.0.27
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/CHANGELOG.md +13 -0
- package/dal-docs/settings.md +18 -2
- package/dist/core/agent-session.d.ts +13 -0
- package/dist/core/agent-session.js +9 -9
- package/dist/core/background-processes.js +4 -4
- package/dist/core/extensions/loader.js +1 -1
- package/dist/core/extensions/permission-surface.js +1 -1
- package/dist/core/extensions/runner.js +1 -1
- package/dist/core/extensions/types.d.ts +3 -0
- package/dist/core/sandbox/availability.d.ts +6 -1
- package/dist/core/sandbox/availability.js +1 -1
- package/dist/core/sandbox/denial.js +3 -3
- package/dist/core/sandbox/runtime.d.ts +10 -0
- package/dist/core/sandbox/runtime.js +1 -1
- package/dist/core/sandbox/shell-sandbox.d.ts +6 -0
- package/dist/core/sandbox/shell-sandbox.js +5 -5
- package/dist/core/sandbox/windows.d.ts +122 -0
- package/dist/core/sandbox/windows.js +5 -0
- package/dist/core/tools/bash.d.ts +1 -0
- package/dist/core/tools/bash.js +6 -6
- package/dist/core/tools/powershell.js +2 -2
- package/dist/modes/rpc/environment-update.js +1 -0
- package/dist/modes/rpc/rpc-client.d.ts +14 -0
- package/dist/modes/rpc/rpc-client.js +3 -3
- package/dist/modes/rpc/rpc-mode.d.ts +1 -0
- package/dist/modes/rpc/rpc-mode.js +1 -1
- package/dist/modes/rpc/rpc-types.d.ts +13 -0
- package/dist/node_modules/@dalcode/dal-bridge/package.json +2 -2
- package/dist/node_modules/@dalcode/dal-bridge/src/index.js +1 -1
- package/dist/node_modules/@dalcode/dal-gateway/package.json +2 -2
- package/dist/node_modules/@dalcode/dal-guard/package.json +4 -4
- package/dist/node_modules/@dalcode/dal-halo/package.json +1 -1
- package/dist/node_modules/@dalcode/dal-interactive/package.json +2 -2
- package/dist/node_modules/@dalcode/dal-lang/package.json +3 -3
- package/dist/node_modules/@dalcode/dal-lsp/package.json +3 -3
- package/dist/node_modules/@dalcode/dal-mcp/package.json +5 -5
- package/dist/node_modules/@dalcode/dal-mcp/src/add-wizard.js +1 -1
- package/dist/node_modules/@dalcode/dal-mcp/src/config.d.ts +1 -1
- package/dist/node_modules/@dalcode/dal-mcp/src/config.js +1 -1
- package/dist/node_modules/@dalcode/dal-mcp/src/index.js +18 -18
- package/dist/node_modules/@dalcode/dal-mcp/src/proxy.js +6 -6
- package/dist/node_modules/@dalcode/dal-mcp/src/report.js +1 -1
- package/dist/node_modules/@dalcode/dal-mcp/src/types.d.ts +1 -1
- package/dist/node_modules/@dalcode/dal-office/package.json +2 -2
- package/dist/node_modules/@dalcode/dal-pi-kit/dist/i18n.js +1 -1
- package/dist/node_modules/@dalcode/dal-pi-kit/package.json +1 -1
- package/dist/node_modules/@dalcode/dal-pi-kit/src/i18n.js +1 -1
- package/dist/node_modules/@dalcode/dal-plugins/package.json +2 -2
- package/dist/node_modules/@dalcode/dal-review/package.json +3 -3
- package/dist/node_modules/@dalcode/dal-rewind/package.json +2 -2
- package/dist/node_modules/@dalcode/dal-router/package.json +4 -4
- package/dist/node_modules/@dalcode/dal-skills/package.json +3 -3
- package/dist/node_modules/@dalcode/dal-subagent/package.json +5 -5
- package/dist/node_modules/@dalcode/dal-telemetry/package.json +2 -2
- package/dist/node_modules/@dalcode/dal-terminal/package.json +2 -2
- package/dist/node_modules/@dalcode/dal-tool-catalog/package.json +2 -2
- package/dist/node_modules/@dalcode/dal-web/package.json +3 -3
- package/dist/node_modules/@dalcode/dal-workflow/package.json +2 -2
- package/dist/node_modules/@dalcode/deepailab/package.json +3 -3
- package/dist/node_modules/@earendil-works/chord/package.json +1 -1
- package/dist/node_modules/@earendil-works/pi-agent-core/package.json +4 -4
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/.manifest.json +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/amazon-bedrock.json +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/anthropic.json +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/cloudflare-ai-gateway.json +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/cloudflare-workers-ai.json +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/mistral.json +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/opencode.json +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/openrouter.json +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/radius.json +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/together.json +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/vercel-ai-gateway.json +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/package.json +2 -2
- package/dist/node_modules/@earendil-works/pi-client/package.json +3 -3
- package/dist/node_modules/@earendil-works/pi-coding-agent/package.json +1 -1
- package/dist/node_modules/@earendil-works/pi-protocol/package.json +2 -2
- package/dist/node_modules/@earendil-works/pi-server/package.json +5 -5
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/package.json +3 -3
- package/dist/node_modules/@earendil-works/pi-telemetry/package.json +1 -1
- package/dist/node_modules/@earendil-works/pi-tui/package.json +1 -1
- package/examples/extensions/custom-provider-anthropic/package-lock.json +2 -2
- package/examples/extensions/custom-provider-anthropic/package.json +1 -1
- package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
- package/examples/extensions/gondolin/package-lock.json +2 -2
- package/examples/extensions/gondolin/package.json +1 -1
- package/examples/extensions/sandbox/package-lock.json +2 -2
- package/examples/extensions/sandbox/package.json +1 -1
- package/examples/extensions/with-deps/package-lock.json +2 -2
- package/examples/extensions/with-deps/package.json +1 -1
- package/npm-shrinkwrap.json +10 -2
- package/package.json +9 -1
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import type { AgentMessage, ThinkingLevel } from "@earendil-works/pi-agent-core";
|
|
2
2
|
import type { ImageContent } from "@earendil-works/pi-ai";
|
|
3
3
|
import type { SessionStats } from "../../core/agent-session.ts";
|
|
4
|
+
import type { BackgroundProcessInfo } from "../../core/background-processes.ts";
|
|
4
5
|
import type { BashResult } from "../../core/bash-executor.ts";
|
|
5
6
|
import type { CompactionResult } from "../../core/compaction/index.ts";
|
|
6
7
|
import type { HostCapability } from "../../core/host-capabilities.ts";
|
|
8
|
+
import type { SandboxStatus } from "../../core/sandbox/shell-sandbox.ts";
|
|
7
9
|
import type { SessionEntry, SessionTreeNode } from "../../core/session-manager.ts";
|
|
8
10
|
import type { JsonAgentSessionEvent } from "../json-event.ts";
|
|
9
11
|
import type { RpcExtensionUIRequest, RpcExtensionUIResponse, RpcHostRequest, RpcSessionState, RpcSlashCommand } from "./rpc-types.ts";
|
|
@@ -96,6 +98,18 @@ export declare class RpcClient {
|
|
|
96
98
|
abortRetry(): Promise<void>;
|
|
97
99
|
bash(command: string): Promise<BashResult>;
|
|
98
100
|
abortBash(): Promise<void>;
|
|
101
|
+
getSandboxStatus(): Promise<SandboxStatus | null>;
|
|
102
|
+
listBackgroundProcesses(): Promise<BackgroundProcessInfo[]>;
|
|
103
|
+
readBackgroundProcess(processId: string, tail?: number): Promise<{
|
|
104
|
+
text: string;
|
|
105
|
+
truncated: boolean;
|
|
106
|
+
process: BackgroundProcessInfo;
|
|
107
|
+
}>;
|
|
108
|
+
stopBackgroundProcess(processId: string): Promise<BackgroundProcessInfo>;
|
|
109
|
+
setEnvironment(update: {
|
|
110
|
+
set?: Record<string, string>;
|
|
111
|
+
unset?: string[];
|
|
112
|
+
}): Promise<string[]>;
|
|
99
113
|
getSessionStats(): Promise<SessionStats>;
|
|
100
114
|
exportHtml(outputPath?: string): Promise<{
|
|
101
115
|
path: string;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var y=Object.defineProperty;var h=(d,t)=>y(d,"name",{value:t,configurable:!0});import{spawn as w}from"node:child_process";import{attachJsonlLineReader as
|
|
2
|
-
`);return e.length>l?e.slice(-l):e}h(
|
|
1
|
+
var y=Object.defineProperty;var h=(d,t)=>y(d,"name",{value:t,configurable:!0});import{spawn as w}from"node:child_process";import{attachJsonlLineReader as _,serializeJsonLine as p}from"./jsonl.js";const f=20,l=2e3;function m(d){const e=d.split(/\r?\n/u).filter(s=>s.trim().length>0).slice(-f).join(`
|
|
2
|
+
`);return e.length>l?e.slice(-l):e}h(m,"rpcStderrTail");const E=new Set(["select","confirm","input","editor","requestInput","requestChoice"]);class S{static{h(this,"RpcClient")}process=null;stopReadingStdout=null;eventListeners=[];pendingRequests=new Map;requestId=0;extensionUIHandler=null;hostRequestHandler=null;stderr="";exitError=null;options;exitListeners=new Set;exitInfo;stopping=!1;turnInFlight=!1;constructor(t={}){this.options=t}async start(){if(this.process)throw new Error("Client already started");this.exitError=null,this.exitInfo=void 0,this.stopping=!1,this.turnInFlight=!1;const t=this.options.cliPath??"dist/cli.js",e=["--mode","rpc"];this.options.provider&&e.push("--provider",this.options.provider),this.options.model&&e.push("--model",this.options.model),this.options.args&&e.push(...this.options.args);const s=w(process.execPath,[t,...e],{cwd:this.options.cwd,env:{...this.options.inheritEnv===!1?{}:process.env,...this.options.env},stdio:["pipe","pipe","pipe"]});if(this.process=s,s.stderr?.on("data",r=>{this.stderr+=r.toString(),process.stderr.write(r)}),s.once("exit",(r,n)=>{if(this.process!==s)return;this.reportExit({code:r,signal:n});const i=this.createProcessExitError(r,n);this.exitError=i,this.rejectPendingRequests(i)}),s.once("error",r=>{if(this.process!==s)return;const n=new Error(`Agent process error: ${r.message}. Stderr: ${this.stderr}`);s.exitCode===null&&s.signalCode===null&&this.reportExit({code:null,signal:null,error:r.message}),this.exitError=n,this.rejectPendingRequests(n)}),s.stdin?.on("error",r=>{if(this.process!==s)return;const n=this.exitError??new Error(`Agent process stdin error: ${r.message}. Stderr: ${this.stderr}`);this.exitError=n,this.rejectPendingRequests(n)}),this.stopReadingStdout=_(s.stdout,r=>{this.handleLine(r)}),await new Promise(r=>setTimeout(r,100)),this.process.exitCode!==null){const r=this.exitError??this.createProcessExitError(this.process.exitCode,this.process.signalCode);throw this.exitError=r,r}}async stop(){this.process&&(this.stopReadingStdout?.(),this.stopReadingStdout=null,this.stopping=!0,this.process.kill("SIGTERM"),await new Promise(t=>{const e=setTimeout(()=>{this.process?.kill("SIGKILL"),t()},1e3);this.process?.on("exit",()=>{clearTimeout(e),t()})}),this.process=null,this.pendingRequests.clear())}onExit(t){const e=this.exitInfo;return e?(queueMicrotask(()=>t(e)),()=>{}):(this.exitListeners.add(t),()=>{this.exitListeners.delete(t)})}getExit(){return this.exitInfo}onEvent(t){return this.eventListeners.push(t),()=>{const e=this.eventListeners.indexOf(t);e!==-1&&this.eventListeners.splice(e,1)}}setExtensionUIHandler(t){this.extensionUIHandler=t}getStderr(){return this.stderr}async prompt(t,e){(await this.send({type:"prompt",message:t,images:e})).success&&(this.turnInFlight=!0)}async steer(t,e){await this.send({type:"steer",message:t,images:e})}async followUp(t,e){await this.send({type:"follow_up",message:t,images:e})}async abort(){await this.send({type:"abort"})}async clearQueue(){const t=await this.send({type:"clear_queue"});return this.getData(t)}async newSession(t){const e=await this.send({type:"new_session",parentSession:t});return this.getData(e)}async getState(){const t=await this.send({type:"get_state"});return this.getData(t)}async setModel(t,e){const s=await this.send({type:"set_model",provider:t,modelId:e});return this.getData(s)}async cycleModel(){const t=await this.send({type:"cycle_model"});return this.getData(t)}async getAvailableModels(){const t=await this.send({type:"get_available_models"});return this.getData(t).models}async setThinkingLevel(t){await this.send({type:"set_thinking_level",level:t})}async cycleThinkingLevel(){const t=await this.send({type:"cycle_thinking_level"});return this.getData(t)}async getAvailableThinkingLevels(){const t=await this.send({type:"get_available_thinking_levels"});return this.getData(t).levels}async setSteeringMode(t){await this.send({type:"set_steering_mode",mode:t})}async setFollowUpMode(t){await this.send({type:"set_follow_up_mode",mode:t})}async compact(t){const e=await this.send({type:"compact",customInstructions:t});return this.getData(e)}async setAutoCompaction(t){await this.send({type:"set_auto_compaction",enabled:t})}async setAutoRetry(t){await this.send({type:"set_auto_retry",enabled:t})}async abortRetry(){await this.send({type:"abort_retry"})}async bash(t){const e=await this.send({type:"bash",command:t});return this.getData(e)}async abortBash(){await this.send({type:"abort_bash"})}async getSandboxStatus(){const t=await this.send({type:"get_sandbox_status"});return this.getData(t)}async listBackgroundProcesses(){const t=await this.send({type:"list_background_processes"});return this.getData(t).processes}async readBackgroundProcess(t,e){const s=await this.send({type:"read_background_process",processId:t,...e!==void 0?{tail:e}:{}});return this.getData(s)}async stopBackgroundProcess(t){const e=await this.send({type:"stop_background_process",processId:t});return this.getData(e).process}async setEnvironment(t){const e=await this.send({type:"set_environment",...t});return this.getData(e).changed}async getSessionStats(){const t=await this.send({type:"get_session_stats"});return this.getData(t)}async exportHtml(t){const e=await this.send({type:"export_html",outputPath:t});return this.getData(e)}async switchSession(t){const e=await this.send({type:"switch_session",sessionPath:t});return this.getData(e)}async fork(t){const e=await this.send({type:"fork",entryId:t});return this.getData(e)}async clone(){const t=await this.send({type:"clone"});return this.getData(t)}async getForkMessages(){const t=await this.send({type:"get_fork_messages"});return this.getData(t).messages}async getEntries(t){const e=await this.send({type:"get_entries",since:t});return this.getData(e)}async getTree(){const t=await this.send({type:"get_tree"});return this.getData(t)}async getLastAssistantText(){const t=await this.send({type:"get_last_assistant_text"});return this.getData(t).text}async setSessionName(t){await this.send({type:"set_session_name",name:t})}async getMessages(){const t=await this.send({type:"get_messages"});return this.getData(t).messages}async getCommands(){const t=await this.send({type:"get_commands"});return this.getData(t).commands}async setHostCapabilities(t,e){this.hostRequestHandler=e;const s=await this.send({type:"set_host_capabilities",capabilities:t});return this.getData(s).capabilities}waitForIdle(t=6e4){return new Promise((e,s)=>{const r=setTimeout(()=>{n(),i(),s(new Error(`Timeout waiting for agent to become idle. Stderr: ${this.stderr}`))},t),n=this.onEvent(o=>{o.type==="agent_settled"&&(clearTimeout(r),n(),i(),e())}),i=this.onExit(o=>{clearTimeout(r),n(),s(this.createExitWhileWaitingError(o))})})}collectEvents(t=6e4){return new Promise((e,s)=>{const r=[],n=setTimeout(()=>{i(),o(),s(new Error(`Timeout collecting events. Stderr: ${this.stderr}`))},t),i=this.onEvent(a=>{r.push(a),a.type==="agent_settled"&&(clearTimeout(n),i(),o(),e(r))}),o=this.onExit(a=>{clearTimeout(n),i(),s(this.createExitWhileWaitingError(a))})})}async promptAndWait(t,e,s=6e4){const r=this.collectEvents(s);return await this.prompt(t,e),r}handleLine(t){try{const e=JSON.parse(t);if(e.type==="agent_start"?this.turnInFlight=!0:e.type==="agent_settled"&&(this.turnInFlight=!1),e.type==="response"&&e.id&&this.pendingRequests.has(e.id)){const s=this.pendingRequests.get(e.id);this.pendingRequests.delete(e.id),s.resolve(e);return}if(e.type==="extension_ui_request"&&E.has(e.method)&&this.answerExtensionUIRequest(e),e.type==="host_request"){this.answerHostRequest(e);return}for(const s of this.eventListeners)s(e)}catch{}}async answerExtensionUIRequest(t){const e={type:"extension_ui_response",id:t.id,cancelled:!0};let s=e;if(this.extensionUIHandler)try{s=await this.extensionUIHandler(t)??e}catch{s=e}const r=this.process?.stdin;if(!(!r||r.destroyed||!r.writable))try{r.write(p({...s,id:t.id}))}catch{}}async answerHostRequest(t){let e;if(!this.hostRequestHandler)e={type:"host_response",id:t.id,error:"host has no handler for host requests"};else try{const r=await this.hostRequestHandler(t);e={type:"host_response",id:t.id,result:r??null}}catch(r){e={type:"host_response",id:t.id,error:r instanceof Error?r.message:String(r)}}const s=this.process?.stdin;if(!(!s||s.destroyed||!s.writable))try{s.write(p(e))}catch{}}reportExit(t){if(this.exitInfo)return;const e={code:t.code,signal:t.signal,stderrTail:m(this.stderr),expected:this.stopping,turnInFlight:this.turnInFlight,...t.error?{error:t.error}:{}};this.exitInfo=e,this.turnInFlight=!1;const s=[...this.exitListeners];this.exitListeners.clear();for(const r of s)try{r(e)}catch{}}createExitWhileWaitingError(t){const e=t.signal?`signal ${t.signal}`:`code ${t.code??"unknown"}`,s=t.stderrTail?`
|
|
3
3
|
Last stderr output:
|
|
4
|
-
${t.stderrTail}`:"";return new Error(`Agent process exited (${e}) before the turn finished.${s}`)}createProcessExitError(t,e){return new Error(`Agent process exited (code=${t} signal=${e}). Stderr: ${this.stderr}`)}rejectPendingRequests(t){for(const e of this.pendingRequests.values())e.reject(t);this.pendingRequests.clear()}async send(t){const e=this.process,s=e?.stdin;if(!e||!s)throw new Error("Client not started");if(this.exitError)throw this.exitError;if(e.exitCode!==null){const
|
|
4
|
+
${t.stderrTail}`:"";return new Error(`Agent process exited (${e}) before the turn finished.${s}`)}createProcessExitError(t,e){return new Error(`Agent process exited (code=${t} signal=${e}). Stderr: ${this.stderr}`)}rejectPendingRequests(t){for(const e of this.pendingRequests.values())e.reject(t);this.pendingRequests.clear()}async send(t){const e=this.process,s=e?.stdin;if(!e||!s)throw new Error("Client not started");if(this.exitError)throw this.exitError;if(e.exitCode!==null){const i=this.createProcessExitError(e.exitCode,e.signalCode);throw this.exitError=i,i}if(s.destroyed||!s.writable){const i=new Error(`Agent process stdin is not writable. Stderr: ${this.stderr}`);throw this.exitError=i,i}const r=`req_${++this.requestId}`,n={...t,id:r};return new Promise((i,o)=>{const a=setTimeout(()=>{this.pendingRequests.delete(r),o(new Error(`Timeout waiting for response to ${t.type}. Stderr: ${this.stderr}`))},3e4);this.pendingRequests.set(r,{resolve:h(c=>{clearTimeout(a),i(c)},"resolve"),reject:h(c=>{clearTimeout(a),o(c)},"reject")});try{s.write(p(n))}catch(c){const u=c instanceof Error?c:new Error(String(c)),g=this.pendingRequests.get(r);this.pendingRequests.delete(r),g?.reject(u)}})}getData(t){if(!t.success){const s=t;throw new Error(s.error)}return t.data}}export{S as RpcClient,m as rpcStderrTail};
|
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
import type { AgentSessionRuntime } from "../../core/agent-session-runtime.ts";
|
|
2
2
|
export type { RpcCommand, RpcExtensionUIRequest, RpcExtensionUIResponse, RpcResponse, RpcSessionState, } from "./rpc-types.ts";
|
|
3
|
+
export declare const PROMPT_ABORTED_BEFORE_START = "Prompt aborted before it started";
|
|
3
4
|
export declare function runRpcMode(runtimeHost: AgentSessionRuntime): Promise<never>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
var N=Object.defineProperty;var i=(u,o)=>N(u,"name",{value:o,configurable:!0});import*as d from"node:crypto";import{resolveExtensionNotify as $}from"../../core/extensions/index.js";import{DEFAULT_HOST_CALL_TIMEOUT_MS as J,getHostCapabilities as P,HostCallError as x,parseHostCapabilities as W}from"../../core/host-capabilities.js";import{flushRawStdout as j,takeOverStdout as G,waitForRawStdoutBackpressure as I,writeRawStdout as H}from"../../core/output-guard.js";import{killTrackedDetachedChildren as O}from"../../utils/shell.js";import{theme as z}from"../interactive/theme/theme.js";import{toJsonEvent as K}from"../json-event.js";import{attachJsonlLineReader as Q,serializeJsonLine as X}from"./jsonl.js";async function re(u){G();let o=u.session,k,S;const c=i(e=>{H(X(e))},"output"),r=i((e,t,s)=>s===void 0?{id:e,type:"response",command:t,success:!0}:{id:e,type:"response",command:t,success:!0,data:s},"success"),p=i((e,t,s)=>({id:e,type:"response",command:t,success:!1,error:s}),"error"),m=new Map,b=new Map,q=i((e,t)=>{const s=d.randomUUID();return new Promise((n,a)=>{const l=i(()=>{clearTimeout(w),t.signal?.removeEventListener("abort",f),b.delete(s)},"cleanup"),y=i(g=>{l(),c({type:"host_request_cancelled",id:s}),a(g)},"giveUp"),f=i(()=>y(new x("aborted","host call aborted")),"onAbort"),w=setTimeout(()=>y(new x("timeout","host did not answer in time")),t.timeoutMs??J);t.signal?.addEventListener("abort",f,{once:!0}),b.set(s,{resolve:i(g=>{l(),n(g)},"resolve"),reject:i(g=>{l(),a(g)},"reject")});const v={type:"host_request",id:s,capability:e.capability,method:e.method,params:e.params};c(v)})},"rpcHostTransport");let C=!1,E=!1;const U=[];function h(e,t,s,n){if(e?.signal?.aborted)return Promise.resolve(t);const a=d.randomUUID();return new Promise((l,y)=>{let f;const w=i(()=>{f&&clearTimeout(f),e?.signal?.removeEventListener("abort",v),m.delete(a)},"cleanup"),v=i(()=>{w(),l(t)},"onAbort");e?.signal?.addEventListener("abort",v,{once:!0}),e?.timeout&&(f=setTimeout(()=>{w(),l(t)},e.timeout)),m.set(a,{resolve:i(g=>{w(),l(n(g))},"resolve"),reject:y}),c({type:"extension_ui_request",id:a,...s})})}i(h,"createDialogPromise");const F=i(()=>({select:i((e,t,s)=>h(s,void 0,{method:"select",title:e,options:t,timeout:s?.timeout},n=>"cancelled"in n&&n.cancelled?void 0:"value"in n?n.value:void 0),"select"),confirm:i((e,t,s)=>h(s,!1,{method:"confirm",title:e,message:t,timeout:s?.timeout},n=>"cancelled"in n&&n.cancelled?!1:"confirmed"in n?n.confirmed:!1),"confirm"),input:i((e,t,s)=>h(s,void 0,{method:"input",title:e,placeholder:t,timeout:s?.timeout},n=>"cancelled"in n&&n.cancelled?void 0:"value"in n?n.value:void 0),"input"),notify(e,t){const s=$(e,t);c({type:"extension_ui_request",id:d.randomUUID(),method:"notify",message:s.message,notifyType:s.type})},setPanel(e,t){c({type:"extension_ui_request",id:d.randomUUID(),method:"setPanel",panelId:e,panel:t})},requestInput:i(e=>h(e,void 0,{method:"requestInput",title:e.title,placeholder:e.placeholder,timeout:e.timeout},t=>"cancelled"in t&&t.cancelled?void 0:"value"in t?t.value:void 0),"requestInput"),requestChoice:i(e=>h(e,void 0,{method:"requestChoice",title:e.title,items:e.items,timeout:e.timeout},t=>"cancelled"in t&&t.cancelled?void 0:"value"in t?t.value:void 0),"requestChoice"),onTerminalInput(){return()=>{}},setStatus(e,t){c({type:"extension_ui_request",id:d.randomUUID(),method:"setStatus",statusKey:e,statusText:t})},setWorkingMessage(e){},setWorkingVisible(e){},setWorkingIndicator(e){},setHiddenThinkingLabel(e){},setWidget(e,t,s){(t===void 0||Array.isArray(t))&&c({type:"extension_ui_request",id:d.randomUUID(),method:"setWidget",widgetKey:e,widgetLines:t,widgetPlacement:s?.placement})},setFooter(e){},setHeader(e){},setTitle(e){c({type:"extension_ui_request",id:d.randomUUID(),method:"setTitle",title:e})},async custom(){},pasteToEditor(e){this.setEditorText(e)},setEditorText(e){c({type:"extension_ui_request",id:d.randomUUID(),method:"set_editor_text",text:e})},getEditorText(){return""},async editor(e,t){const s=d.randomUUID();return new Promise((n,a)=>{m.set(s,{resolve:i(l=>{"cancelled"in l&&l.cancelled?n(void 0):"value"in l?n(l.value):n(void 0)},"resolve"),reject:a}),c({type:"extension_ui_request",id:s,method:"editor",title:e,prefill:t})})},addAutocompleteProvider(){},setEditorComponent(){},getEditorComponent(){},get theme(){return z},getAllThemes(){return[]},getTheme(e){},setTheme(e){return{success:!1,error:"Theme switching not supported in RPC mode"}},getToolsExpanded(){return!1},setToolsExpanded(e){}}),"createExtensionUIContext");u.setRebindSession(async()=>{await _()});const _=i(async()=>{o=u.session,await o.bindExtensions({uiContext:F(),mode:"rpc",commandContextActions:{waitForIdle:i(()=>o.waitForIdle(),"waitForIdle"),newSession:i(async e=>u.newSession(e),"newSession"),fork:i(async(e,t)=>({cancelled:(await u.fork(e,t)).cancelled}),"fork"),navigateTree:i(async(e,t)=>({cancelled:(await o.navigateTree(e,{summarize:t?.summarize,customInstructions:t?.customInstructions,replaceInstructions:t?.replaceInstructions,label:t?.label})).cancelled}),"navigateTree"),switchSession:i(async(e,t)=>u.switchSession(e,t),"switchSession"),reload:i(async()=>{await o.reload()},"reload")},shutdownHandler:i(()=>{C=!0},"shutdownHandler"),onError:i(e=>{c({type:"extension_error",extensionPath:e.extensionPath,event:e.event,error:e.error})},"onError")}),k?.(),S?.(),k=o.subscribe(e=>{c(K(e)),e.type==="agent_settled"&&R()}),S=o.agent.subscribe(async()=>{await I()})},"rebindSession"),A=i(()=>{const e=["SIGTERM"];process.platform!=="win32"&&e.push("SIGHUP");for(const t of e){const s=i(()=>{O(),T(t==="SIGHUP"?129:143,t)},"handler");process.on(t,s),U.push(()=>process.off(t,s))}},"registerSignalHandlers");await _(),A();const D=i(async e=>{const t=e.id;switch(e.type){case"prompt":{let s=!1;o.prompt(e.message,{images:e.images,streamingBehavior:e.streamingBehavior,source:"rpc",preflightResult:i(n=>{n&&(s=!0,c(r(t,"prompt")))},"preflightResult")}).catch(n=>{s||c(p(t,"prompt",n.message))});return}case"steer":return await o.steer(e.message,e.images,{source:"rpc"}),r(t,"steer");case"follow_up":return await o.followUp(e.message,e.images,{source:"rpc"}),r(t,"follow_up");case"abort":return await o.abort(),r(t,"abort");case"clear_queue":return r(t,"clear_queue",o.clearQueue());case"new_session":{const s=e.parentSession?{parentSession:e.parentSession}:void 0,n=await u.newSession(s);return n.cancelled||await _(),r(t,"new_session",n)}case"get_state":{const s={model:o.model,thinkingLevel:o.thinkingLevel,isStreaming:o.isStreaming,isCompacting:o.isCompacting,steeringMode:o.steeringMode,followUpMode:o.followUpMode,sessionFile:o.sessionFile,sessionId:o.sessionId,sessionName:o.sessionName,autoCompactionEnabled:o.autoCompactionEnabled,messageCount:o.messages.length,pendingMessageCount:o.pendingMessageCount};return r(t,"get_state",s)}case"set_model":{const n=o.modelRuntime.getAvailableSnapshot().find(a=>a.provider===e.provider&&a.id===e.modelId);return n?(await o.setModel(n),r(t,"set_model",n)):p(t,"set_model",`Model not found: ${e.provider}/${e.modelId}`)}case"cycle_model":{const s=await o.cycleModel();return s?r(t,"cycle_model",s):r(t,"cycle_model",null)}case"get_available_models":{const s=o.modelRuntime.getAvailableSnapshot();return r(t,"get_available_models",{models:s})}case"set_thinking_level":return o.setThinkingLevel(e.level),r(t,"set_thinking_level");case"cycle_thinking_level":{const s=o.cycleThinkingLevel();return s?r(t,"cycle_thinking_level",{level:s}):r(t,"cycle_thinking_level",null)}case"get_available_thinking_levels":{const s=o.getAvailableThinkingLevels();return r(t,"get_available_thinking_levels",{levels:s})}case"set_steering_mode":return o.setSteeringMode(e.mode),r(t,"set_steering_mode");case"set_follow_up_mode":return o.setFollowUpMode(e.mode),r(t,"set_follow_up_mode");case"compact":{const s=await o.compact(e.customInstructions);return r(t,"compact",s)}case"set_auto_compaction":return o.setAutoCompactionEnabled(e.enabled),r(t,"set_auto_compaction");case"set_auto_retry":return o.setAutoRetryEnabled(e.enabled),r(t,"set_auto_retry");case"abort_retry":return o.abortRetry(),r(t,"abort_retry");case"bash":{const s=await o.extensionRunner.emitUserBash({type:"user_bash",command:e.command,excludeFromContext:e.excludeFromContext??!1,cwd:o.sessionManager.getCwd()});if(s?.result)return o.recordBashResult(e.command,s.result,{excludeFromContext:e.excludeFromContext}),r(t,"bash",s.result);const n=await o.executeBash(e.command,void 0,{excludeFromContext:e.excludeFromContext,id:t,operations:s?.operations});return r(t,"bash",n)}case"abort_bash":return o.abortBash(),r(t,"abort_bash");case"get_sandbox_status":return r(t,"get_sandbox_status",o.getSandboxStatus()??null);case"list_background_processes":return r(t,"list_background_processes",{processes:o.backgroundProcesses.list()});case"read_background_process":{const{text:s,truncated:n,info:a}=o.backgroundProcesses.read(e.processId,e.tail!==void 0?{tail:e.tail}:{tail:200});return r(t,"read_background_process",{text:s,truncated:n,process:a})}case"stop_background_process":{const s=await o.backgroundProcesses.stop(e.processId);return r(t,"stop_background_process",{process:s})}case"get_session_stats":{const s=o.getSessionStats();return r(t,"get_session_stats",s)}case"export_html":{const s=await o.exportToHtml(e.outputPath);return r(t,"export_html",{path:s})}case"switch_session":{const s=await u.switchSession(e.sessionPath);return s.cancelled||await _(),r(t,"switch_session",s)}case"fork":{const s=await u.fork(e.entryId);return s.cancelled||await _(),r(t,"fork",{text:s.selectedText,cancelled:s.cancelled})}case"clone":{const s=o.sessionManager.getLeafId();if(!s)return p(t,"clone","Cannot clone session: no current entry selected");const n=await u.fork(s,{position:"at"});return n.cancelled||await _(),r(t,"clone",{cancelled:n.cancelled})}case"get_fork_messages":{const s=o.getUserMessagesForForking();return r(t,"get_fork_messages",{messages:s})}case"get_entries":{const s=o.sessionManager;let n=s.getEntries();if(e.since!==void 0){const a=n.findIndex(l=>l.id===e.since);if(a===-1)return p(t,"get_entries",`Entry not found: ${e.since}`);n=n.slice(a+1)}return r(t,"get_entries",{entries:n,leafId:s.getLeafId()})}case"get_tree":{const s=o.sessionManager;return r(t,"get_tree",{tree:s.getTree(),leafId:s.getLeafId()})}case"get_last_assistant_text":{const s=o.getLastAssistantText();return r(t,"get_last_assistant_text",{text:s})}case"set_session_name":{const s=e.name.trim();return s?(o.setSessionName(s),r(t,"set_session_name")):p(t,"set_session_name","Session name cannot be empty")}case"get_messages":return r(t,"get_messages",{messages:o.messages});case"get_commands":{const s=[];for(const n of o.extensionRunner.getRegisteredCommands())s.push({name:n.invocationName,description:n.description,source:"extension",sourceInfo:n.sourceInfo});for(const n of o.promptTemplates)s.push({name:n.name,description:n.description,source:"prompt",sourceInfo:n.sourceInfo});for(const n of o.resourceLoader.getSkills().skills)s.push({name:`skill:${n.name}`,description:n.description,source:"skill",sourceInfo:n.sourceInfo});return r(t,"get_commands",{commands:s})}case"set_host_capabilities":{const s=P();return s.set("rpc",W(e.capabilities),q),r(t,"set_host_capabilities",{capabilities:s.list()})}default:{const s=e;return p(t,s.type,`Unknown command: ${s.type}`)}}},"handleCommand");let M=i(()=>{},"detachInput");async function T(e=0,t){E&&process.exit(e),E=!0;for(const s of U)s();k?.(),S?.(),P().clear("rpc");for(const s of b.values())s.reject(new x("unavailable","RPC host disconnected"));await u.dispose(),M(),process.stdin.pause(),t!=="SIGTERM"&&await j(),process.exit(e)}i(T,"shutdown");async function R(){C&&await T()}i(R,"checkShutdownRequested");const B=i(async e=>{let t;try{t=JSON.parse(e)}catch(n){c(p(void 0,"parse",`Failed to parse command: ${n instanceof Error?n.message:String(n)}`)),await I();return}if(typeof t=="object"&&t!==null&&"type"in t&&t.type==="extension_ui_response"){const n=t,a=m.get(n.id);a&&(m.delete(n.id),a.resolve(n));return}if(typeof t=="object"&&t!==null&&"type"in t&&t.type==="host_response"){const n=t,a=b.get(n.id);a&&("error"in n?a.reject(new x("host_error",String(n.error))):a.resolve(n.result));return}const s=t;try{const n=await D(s);n&&(c(n),await I()),await R()}catch(n){c(p(s.id,s.type,n instanceof Error?n.message:String(n))),await I()}},"handleInputLine"),L=i(()=>{T()},"onInputEnd");return process.stdin.on("end",L),M=(()=>{const e=Q(process.stdin,t=>{B(t)});return()=>{e(),process.stdin.off("end",L)}})(),new Promise(()=>{})}i(re,"runRpcMode");export{re as runRpcMode};
|
|
1
|
+
var O=Object.defineProperty;var i=(u,r)=>O(u,"name",{value:r,configurable:!0});import*as p from"node:crypto";import{resolveExtensionNotify as N}from"../../core/extensions/index.js";import{DEFAULT_HOST_CALL_TIMEOUT_MS as $,getHostCapabilities as L,HostCallError as x,parseHostCapabilities as J}from"../../core/host-capabilities.js";import{flushRawStdout as W,takeOverStdout as j,waitForRawStdoutBackpressure as I,writeRawStdout as G}from"../../core/output-guard.js";import{killTrackedDetachedChildren as H}from"../../utils/shell.js";import{theme as z}from"../interactive/theme/theme.js";import{toJsonEvent as K}from"../json-event.js";import{applyEnvironmentUpdate as Q}from"./environment-update.js";import{attachJsonlLineReader as X,serializeJsonLine as Y}from"./jsonl.js";const Z="Prompt aborted before it started";async function ce(u){j();let r=u.session,k,S;const c=i(e=>{G(Y(e))},"output"),o=i((e,t,s)=>s===void 0?{id:e,type:"response",command:t,success:!0}:{id:e,type:"response",command:t,success:!0,data:s},"success"),d=i((e,t,s)=>({id:e,type:"response",command:t,success:!1,error:s}),"error"),m=new Map,b=new Map,q=i((e,t)=>{const s=p.randomUUID();return new Promise((n,a)=>{const l=i(()=>{clearTimeout(w),t.signal?.removeEventListener("abort",f),b.delete(s)},"cleanup"),y=i(g=>{l(),c({type:"host_request_cancelled",id:s}),a(g)},"giveUp"),f=i(()=>y(new x("aborted","host call aborted")),"onAbort"),w=setTimeout(()=>y(new x("timeout","host did not answer in time")),t.timeoutMs??$);t.signal?.addEventListener("abort",f,{once:!0}),b.set(s,{resolve:i(g=>{l(),n(g)},"resolve"),reject:i(g=>{l(),a(g)},"reject")});const v={type:"host_request",id:s,capability:e.capability,method:e.method,params:e.params};c(v)})},"rpcHostTransport");let E=!1,C=!1;const U=[];function h(e,t,s,n){if(e?.signal?.aborted)return Promise.resolve(t);const a=p.randomUUID();return new Promise((l,y)=>{let f;const w=i(()=>{f&&clearTimeout(f),e?.signal?.removeEventListener("abort",v),m.delete(a)},"cleanup"),v=i(()=>{w(),l(t)},"onAbort");e?.signal?.addEventListener("abort",v,{once:!0}),e?.timeout&&(f=setTimeout(()=>{w(),l(t)},e.timeout)),m.set(a,{resolve:i(g=>{w(),l(n(g))},"resolve"),reject:y}),c({type:"extension_ui_request",id:a,...s})})}i(h,"createDialogPromise");const F=i(()=>({select:i((e,t,s)=>h(s,void 0,{method:"select",title:e,options:t,timeout:s?.timeout},n=>"cancelled"in n&&n.cancelled?void 0:"value"in n?n.value:void 0),"select"),confirm:i((e,t,s)=>h(s,!1,{method:"confirm",title:e,message:t,timeout:s?.timeout},n=>"cancelled"in n&&n.cancelled?!1:"confirmed"in n?n.confirmed:!1),"confirm"),input:i((e,t,s)=>h(s,void 0,{method:"input",title:e,placeholder:t,timeout:s?.timeout},n=>"cancelled"in n&&n.cancelled?void 0:"value"in n?n.value:void 0),"input"),notify(e,t){const s=N(e,t);c({type:"extension_ui_request",id:p.randomUUID(),method:"notify",message:s.message,notifyType:s.type})},setPanel(e,t){c({type:"extension_ui_request",id:p.randomUUID(),method:"setPanel",panelId:e,panel:t})},requestInput:i(e=>h(e,void 0,{method:"requestInput",title:e.title,placeholder:e.placeholder,timeout:e.timeout},t=>"cancelled"in t&&t.cancelled?void 0:"value"in t?t.value:void 0),"requestInput"),requestChoice:i(e=>h(e,void 0,{method:"requestChoice",title:e.title,items:e.items,timeout:e.timeout},t=>"cancelled"in t&&t.cancelled?void 0:"value"in t?t.value:void 0),"requestChoice"),onTerminalInput(){return()=>{}},setStatus(e,t){c({type:"extension_ui_request",id:p.randomUUID(),method:"setStatus",statusKey:e,statusText:t})},setWorkingMessage(e){},setWorkingVisible(e){},setWorkingIndicator(e){},setHiddenThinkingLabel(e){},setWidget(e,t,s){(t===void 0||Array.isArray(t))&&c({type:"extension_ui_request",id:p.randomUUID(),method:"setWidget",widgetKey:e,widgetLines:t,widgetPlacement:s?.placement})},setFooter(e){},setHeader(e){},setTitle(e){c({type:"extension_ui_request",id:p.randomUUID(),method:"setTitle",title:e})},async custom(){},pasteToEditor(e){this.setEditorText(e)},setEditorText(e){c({type:"extension_ui_request",id:p.randomUUID(),method:"set_editor_text",text:e})},getEditorText(){return""},async editor(e,t){const s=p.randomUUID();return new Promise((n,a)=>{m.set(s,{resolve:i(l=>{"cancelled"in l&&l.cancelled?n(void 0):"value"in l?n(l.value):n(void 0)},"resolve"),reject:a}),c({type:"extension_ui_request",id:s,method:"editor",title:e,prefill:t})})},addAutocompleteProvider(){},setEditorComponent(){},getEditorComponent(){},get theme(){return z},getAllThemes(){return[]},getTheme(e){},setTheme(e){return{success:!1,error:"Theme switching not supported in RPC mode"}},getToolsExpanded(){return!1},setToolsExpanded(e){}}),"createExtensionUIContext");u.setRebindSession(async()=>{await _()});const _=i(async()=>{r=u.session,k?.(),S?.(),k=r.subscribe(e=>{c(K(e)),e.type==="agent_settled"&&R()}),S=r.agent.subscribe(async()=>{await I()}),await r.bindExtensions({uiContext:F(),mode:"rpc",commandContextActions:{waitForIdle:i(()=>r.waitForIdle(),"waitForIdle"),newSession:i(async e=>u.newSession(e),"newSession"),fork:i(async(e,t)=>({cancelled:(await u.fork(e,t)).cancelled}),"fork"),navigateTree:i(async(e,t)=>({cancelled:(await r.navigateTree(e,{summarize:t?.summarize,customInstructions:t?.customInstructions,replaceInstructions:t?.replaceInstructions,label:t?.label})).cancelled}),"navigateTree"),switchSession:i(async(e,t)=>u.switchSession(e,t),"switchSession"),reload:i(async()=>{await r.reload()},"reload")},shutdownHandler:i(()=>{E=!0},"shutdownHandler"),onError:i(e=>{c({type:"extension_error",extensionPath:e.extensionPath,event:e.event,error:e.error})},"onError")})},"rebindSession"),A=i(()=>{const e=["SIGTERM"];process.platform!=="win32"&&e.push("SIGHUP");for(const t of e){const s=i(()=>{H(),T(t==="SIGHUP"?129:143,t)},"handler");process.on(t,s),U.push(()=>process.off(t,s))}},"registerSignalHandlers");await _(),A();const D=i(async e=>{const t=e.id;switch(e.type){case"prompt":{let s=!1,n=!1;r.prompt(e.message,{images:e.images,streamingBehavior:e.streamingBehavior,source:"rpc",preflightResult:i(a=>{a?(s=!0,c(o(t,"prompt"))):n=!0},"preflightResult")}).then(()=>{n&&!s&&c(d(t,"prompt",Z))},a=>{s||c(d(t,"prompt",a.message))});return}case"steer":return await r.steer(e.message,e.images,{source:"rpc"}),o(t,"steer");case"follow_up":return await r.followUp(e.message,e.images,{source:"rpc"}),o(t,"follow_up");case"abort":return await r.abort(),o(t,"abort");case"clear_queue":return o(t,"clear_queue",r.clearQueue());case"new_session":{const s=e.parentSession?{parentSession:e.parentSession}:void 0,n=await u.newSession(s);return n.cancelled||await _(),o(t,"new_session",n)}case"get_state":{const s={model:r.model,thinkingLevel:r.thinkingLevel,isStreaming:r.isStreaming,isCompacting:r.isCompacting,steeringMode:r.steeringMode,followUpMode:r.followUpMode,sessionFile:r.sessionFile,sessionId:r.sessionId,sessionName:r.sessionName,autoCompactionEnabled:r.autoCompactionEnabled,messageCount:r.messages.length,pendingMessageCount:r.pendingMessageCount};return o(t,"get_state",s)}case"set_model":{const n=r.modelRuntime.getAvailableSnapshot().find(a=>a.provider===e.provider&&a.id===e.modelId);return n?(await r.setModel(n),o(t,"set_model",n)):d(t,"set_model",`Model not found: ${e.provider}/${e.modelId}`)}case"cycle_model":{const s=await r.cycleModel();return s?o(t,"cycle_model",s):o(t,"cycle_model",null)}case"get_available_models":{const s=r.modelRuntime.getAvailableSnapshot();return o(t,"get_available_models",{models:s})}case"set_thinking_level":return r.setThinkingLevel(e.level),o(t,"set_thinking_level");case"cycle_thinking_level":{const s=r.cycleThinkingLevel();return s?o(t,"cycle_thinking_level",{level:s}):o(t,"cycle_thinking_level",null)}case"get_available_thinking_levels":{const s=r.getAvailableThinkingLevels();return o(t,"get_available_thinking_levels",{levels:s})}case"set_steering_mode":return r.setSteeringMode(e.mode),o(t,"set_steering_mode");case"set_follow_up_mode":return r.setFollowUpMode(e.mode),o(t,"set_follow_up_mode");case"compact":{const s=await r.compact(e.customInstructions);return o(t,"compact",s)}case"set_auto_compaction":return r.setAutoCompactionEnabled(e.enabled),o(t,"set_auto_compaction");case"set_auto_retry":return r.setAutoRetryEnabled(e.enabled),o(t,"set_auto_retry");case"abort_retry":return r.abortRetry(),o(t,"abort_retry");case"bash":{const s=await r.extensionRunner.emitUserBash({type:"user_bash",command:e.command,excludeFromContext:e.excludeFromContext??!1,cwd:r.sessionManager.getCwd()});if(s?.result)return r.recordBashResult(e.command,s.result,{excludeFromContext:e.excludeFromContext}),o(t,"bash",s.result);const n=await r.executeBash(e.command,void 0,{excludeFromContext:e.excludeFromContext,id:t,operations:s?.operations});return o(t,"bash",n)}case"abort_bash":return r.abortBash(),o(t,"abort_bash");case"get_sandbox_status":return o(t,"get_sandbox_status",r.getSandboxStatus()??null);case"list_background_processes":return o(t,"list_background_processes",{processes:r.backgroundProcesses.list()});case"read_background_process":{const{text:s,truncated:n,info:a}=r.backgroundProcesses.read(e.processId,e.tail!==void 0?{tail:e.tail}:{tail:200});return o(t,"read_background_process",{text:s,truncated:n,process:a})}case"stop_background_process":{const s=await r.backgroundProcesses.stop(e.processId);return o(t,"stop_background_process",{process:s})}case"get_session_stats":{const s=r.getSessionStats();return o(t,"get_session_stats",s)}case"export_html":{const s=await r.exportToHtml(e.outputPath);return o(t,"export_html",{path:s})}case"switch_session":{const s=await u.switchSession(e.sessionPath);return s.cancelled||await _(),o(t,"switch_session",s)}case"fork":{const s=await u.fork(e.entryId);return s.cancelled||await _(),o(t,"fork",{text:s.selectedText,cancelled:s.cancelled})}case"clone":{const s=r.sessionManager.getLeafId();if(!s)return d(t,"clone","Cannot clone session: no current entry selected");const n=await u.fork(s,{position:"at"});return n.cancelled||await _(),o(t,"clone",{cancelled:n.cancelled})}case"get_fork_messages":{const s=r.getUserMessagesForForking();return o(t,"get_fork_messages",{messages:s})}case"get_entries":{const s=r.sessionManager;let n=s.getEntries();if(e.since!==void 0){const a=n.findIndex(l=>l.id===e.since);if(a===-1)return d(t,"get_entries",`Entry not found: ${e.since}`);n=n.slice(a+1)}return o(t,"get_entries",{entries:n,leafId:s.getLeafId()})}case"get_tree":{const s=r.sessionManager;return o(t,"get_tree",{tree:s.getTree(),leafId:s.getLeafId()})}case"get_last_assistant_text":{const s=r.getLastAssistantText();return o(t,"get_last_assistant_text",{text:s})}case"set_session_name":{const s=e.name.trim();return s?(r.setSessionName(s),o(t,"set_session_name")):d(t,"set_session_name","Session name cannot be empty")}case"get_messages":return o(t,"get_messages",{messages:r.messages});case"get_commands":{const s=[];for(const n of r.extensionRunner.getRegisteredCommands())s.push({name:n.invocationName,description:n.description,source:"extension",sourceInfo:n.sourceInfo});for(const n of r.promptTemplates)s.push({name:n.name,description:n.description,source:"prompt",sourceInfo:n.sourceInfo});for(const n of r.resourceLoader.getSkills().skills)s.push({name:`skill:${n.name}`,description:n.description,source:"skill",sourceInfo:n.sourceInfo});return o(t,"get_commands",{commands:s})}case"set_host_capabilities":{const s=L();return s.set("rpc",J(e.capabilities),q),o(t,"set_host_capabilities",{capabilities:s.list()})}case"set_environment":{const s=Q({set:e.set,unset:e.unset});return o(t,"set_environment",{changed:s})}default:{const s=e;return d(t,s.type,`Unknown command: ${s.type}`)}}},"handleCommand");let M=i(()=>{},"detachInput");async function T(e=0,t){C&&process.exit(e),C=!0;for(const s of U)s();k?.(),S?.(),L().clear("rpc");for(const s of b.values())s.reject(new x("unavailable","RPC host disconnected"));await u.dispose(),M(),process.stdin.pause(),t!=="SIGTERM"&&await W(),process.exit(e)}i(T,"shutdown");async function R(){E&&await T()}i(R,"checkShutdownRequested");const B=i(async e=>{let t;try{t=JSON.parse(e)}catch(n){c(d(void 0,"parse",`Failed to parse command: ${n instanceof Error?n.message:String(n)}`)),await I();return}if(typeof t=="object"&&t!==null&&"type"in t&&t.type==="extension_ui_response"){const n=t,a=m.get(n.id);a&&(m.delete(n.id),a.resolve(n));return}if(typeof t=="object"&&t!==null&&"type"in t&&t.type==="host_response"){const n=t,a=b.get(n.id);a&&("error"in n?a.reject(new x("host_error",String(n.error))):a.resolve(n.result));return}const s=t;try{const n=await D(s);n&&(c(n),await I()),await R()}catch(n){c(d(s.id,s.type,n instanceof Error?n.message:String(n))),await I()}},"handleInputLine"),P=i(()=>{T()},"onInputEnd");return process.stdin.on("end",P),M=(()=>{const e=X(process.stdin,t=>{B(t)});return()=>{e(),process.stdin.off("end",P)}})(),new Promise(()=>{})}i(ce,"runRpcMode");export{Z as PROMPT_ABORTED_BEFORE_START,ce as runRpcMode};
|
|
@@ -149,6 +149,11 @@ export type RpcCommand = {
|
|
|
149
149
|
id?: string;
|
|
150
150
|
type: "set_host_capabilities";
|
|
151
151
|
capabilities: HostCapability[];
|
|
152
|
+
} | {
|
|
153
|
+
id?: string;
|
|
154
|
+
type: "set_environment";
|
|
155
|
+
set?: Record<string, string>;
|
|
156
|
+
unset?: string[];
|
|
152
157
|
};
|
|
153
158
|
export interface RpcSlashCommand {
|
|
154
159
|
name: string;
|
|
@@ -437,6 +442,14 @@ export type RpcResponse = {
|
|
|
437
442
|
data: {
|
|
438
443
|
capabilities: HostCapability[];
|
|
439
444
|
};
|
|
445
|
+
} | {
|
|
446
|
+
id?: string;
|
|
447
|
+
type: "response";
|
|
448
|
+
command: "set_environment";
|
|
449
|
+
success: true;
|
|
450
|
+
data: {
|
|
451
|
+
changed: string[];
|
|
452
|
+
};
|
|
440
453
|
} | {
|
|
441
454
|
id?: string;
|
|
442
455
|
type: "response";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dalcode/dal-bridge",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.27",
|
|
4
4
|
"private": true,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./src/index.js",
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
]
|
|
19
19
|
},
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@dalcode/dal-pi-kit": "1.0.
|
|
21
|
+
"@dalcode/dal-pi-kit": "1.0.27",
|
|
22
22
|
"typebox": "1.3.7"
|
|
23
23
|
},
|
|
24
24
|
"peerDependencies": {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
var
|
|
1
|
+
var M=Object.defineProperty;var D=(r,c)=>M(r,"name",{value:c,configurable:!0});var $=Object.defineProperty,i=D((r,c)=>$(r,"name",{value:c,configurable:!0}),"d");import{t}from"@dalcode/dal-pi-kit";import{registerPermissionAskHandler as H,registerSandboxEscalationHandler as R}from"@earendil-works/pi-coding-agent";import{Type as l}from"typebox";import{AskUserInputError as q,askUserSchema as j,buildAskUserRequest as V,describeAnswers as G,THUMBNAIL_CHANNEL as z}from"./ask-user.js";import{askUserTimeoutMs as J,BridgeClient as K,planTimeoutMs as Q,readBridgeConfig as W,readSubagentAttribution as X}from"./client.js";const Y=l.Object({goal:l.String({description:t("\u8FD9\u4E2A\u8BA1\u5212\u8981\u8FBE\u6210\u4EC0\u4E48\uFF0C\u4E00\u53E5\u8BDD\u8BF4\u660E")}),reasoning:l.Optional(l.String({description:t("\u4E3A\u4EC0\u4E48\u9009\u8FD9\u4E2A\u65B9\u6848")})),steps:l.Array(l.Object({title:l.String({description:t("\u8FD9\u4E00\u6B65\u505A\u4EC0\u4E48")}),description:l.Optional(l.String({description:t("\u8FD9\u4E00\u6B65\u7684\u7EC6\u8282")}))}),{description:t("\u6309\u987A\u5E8F\u6392\u5217\u7684\u6267\u884C\u6B65\u9AA4")})}),Z=new Set(["read","grep","ripgrep","find","fd","ls","glob","todo_read","todo","lsp","terminal_read","review_report"]),uu=new Set(["read","grep","ripgrep","find","fd","ls","glob","lsp"]),I="DALCODE_BRIDGE_EVALUATE_READ_TOOLS",eu="submit_plan",h="ask_user";function _(r){return r.scope==="session"?"session":"once"}D(_,"R"),i(_,"escalationScope");function k(r){const c=r.input;for(const C of["command","file_path","path","filePath"]){const F=c[C];if(typeof F=="string"&&F.length>0)return F}}D(k,"T"),i(k,"ruleContentFor");let B,x=!1,g,T=!1;function N(r,c){const C=W();if(!C)return;const F=new K(C,c),d=X();function A(u){const e=u.sessionManager.getSessionId();return d?{sessionId:d.parentSessionId,subagent:{id:d.subagentId,sessionId:e,...d.parentTaskId?{parentTaskId:d.parentTaskId}:{},...d.parentSubagentId?{parentSubagentId:d.parentSubagentId}:{},...d.label?{label:d.label}:{}}}:{sessionId:e}}D(A,"f"),i(A,"caller");let p,b=0;function f(u){const e=u.model;return{provider:e?.provider??"unknown",model:e?.id??e?.name??"unknown"}}D(f,"w"),i(f,"describeModel");const v=new Map,m=new Set,P=process.env[I]==="1";r.on("tool_call",async(u,e)=>{const o=uu.has(u.toolName);if((o?!P:Z.has(u.toolName))||u.toolName===eu||u.toolName===h)return;const s=u.input.sandbox_escalation,a=await F.post("/api/internal/pi-bridge/permission",{...A(e),toolName:u.toolName,toolInput:u.input,ruleContent:k(u),...s?{category:"sandbox_escalation"}:{},...o?{readOnly:!0}:{}});if(!a)return{block:!0,reason:t("dal-bridge\uFF1A\u65E0\u6CD5\u8054\u7CFB DAL Code \u53D6\u5F97\u6388\u6743\uFF0C\u5DF2\u62D2\u7EDD\u6267\u884C\u3002")};if(a.decision==="deny")return{block:!0,reason:a.message??t("dal-bridge\uFF1A\u7528\u6237\u5DF2\u62D2\u7EDD\u8BE5\u64CD\u4F5C\u3002")};s&&v.set(u.toolCallId,_(a)),m.add(u.toolCallId),m.size>1e3&&m.delete(m.values().next().value)});const y=i(async(u,e)=>{if(m.delete(u.toolCallId))return{approved:!0};const o=await F.post("/api/internal/pi-bridge/permission",{...A(e),toolName:u.toolName,toolInput:u.input,ruleContent:k({input:u.input}),category:"permission_rule",rule:u.rule,ruleSource:u.source});return o?o.decision==="allow"?{approved:!0}:{approved:!1,message:o.message??t("dal-bridge\uFF1A\u7528\u6237\u5DF2\u62D2\u7EDD\u8BE5\u64CD\u4F5C\u3002")}:{approved:!1,message:t("dal-bridge\uFF1A\u65E0\u6CD5\u8054\u7CFB DAL Code \u53D6\u5F97\u6388\u6743\uFF0C\u5DF2\u62D2\u7EDD\u6267\u884C\u3002")}},"approveRule");g=y,T||(H((u,e)=>g?.(u,e)),T=!0);const S=i(async(u,e)=>{const o=v.get(u.toolCallId);if(o)return v.delete(u.toolCallId),{approved:!0,scope:o};if(!e)return;const s=await F.post("/api/internal/pi-bridge/permission",{...A(e),toolName:u.toolName,toolInput:{command:u.command},ruleContent:u.command,category:"sandbox_escalation",sandboxEscalation:u});return s?s.decision==="allow"?{approved:!0,scope:_(s)}:{approved:!1,message:s.message??t("dal-bridge\uFF1A\u7528\u6237\u5DF2\u62D2\u7EDD\u8BE5\u64CD\u4F5C\u3002")}:{approved:!1,message:t("dal-bridge\uFF1A\u65E0\u6CD5\u8054\u7CFB DAL Code \u53D6\u5F97\u6388\u6743\uFF0C\u5DF2\u62D2\u7EDD\u6267\u884C\u3002")}},"approveEscalation");B=S,x||(R((u,e)=>B?.(u,e)),x=!0),r.on("session_shutdown",()=>{B===S&&(B=void 0),g===y&&(g=void 0)}),r.on("after_provider_response",(u,e)=>{u.status>=400?p={...f(e),reason:`HTTP ${u.status}`}:(p=void 0,b=0)}),r.on("before_provider_request",async(u,e)=>{if(!p)return;const o=f(e);if(o.provider===p.provider&&o.model===p.model)return;b+=1;const s={provider:p.provider,model:p.model},a=p.reason;p=void 0,await F.post("/api/internal/pi-bridge/provider-fallback",{...A(e),from:s,to:o,reason:a,attempt:b,blocked:!0});const n=new Error(t("dal-bridge\uFF1A\u8BF7\u6C42\u5931\u8D25\u540E\u4E0D\u5141\u8BB8\u81EA\u52A8\u6362\u6A21\u578B\u3002")+` ${s.provider}/${s.model} \u2192 ${o.provider}/${o.model} (${a})`);throw n.name="ProviderSwapAborted",n}),r.registerTool({name:"submit_plan",label:t("\u63D0\u4EA4\u8BA1\u5212\u5F85\u5BA1\u6279"),description:t(t("\u5728\u52A8\u624B\u6539\u52A8\u4E4B\u524D\uFF0C\u628A\u8BA1\u5212\u63D0\u4EA4\u7ED9\u7528\u6237\u5BA1\u6279\u3002\u8FD4\u56DE\u662F\u5426\u7EE7\u7EED\u6267\u884C\uFF0C\u4EE5\u53CA\u7528\u6237\u7ED9\u51FA\u7684\u53CD\u9988\u3002")+t("\u5F53\u4EFB\u52A1\u662F\u591A\u6B65\u9AA4\u7684\u3001\u6216\u4F1A\u6539\u52A8\u591A\u4E2A\u6587\u4EF6\u65F6\u4F7F\u7528\u3002")),promptSnippet:t("submit_plan - \u591A\u6B65\u9AA4\u4EFB\u52A1\u52A8\u624B\u524D\u5148\u63D0\u4EA4\u8BA1\u5212\u5F85\u7528\u6237\u5BA1\u6279"),parameters:Y,execute:i(async(u,e,o,s,a)=>{const n=await F.post("/api/internal/pi-bridge/plan",{...A(a),goal:e.goal,reasoning:e.reasoning,steps:e.steps},{timeoutMs:Q()});return!n||n.decision==="cancel"?{content:[{type:"text",text:n?.feedback?`Plan not approved. User feedback: ${n.feedback}`:"Plan not approved. Stop and wait for further instructions."}],details:{approved:!1,...n?.feedback?{feedback:n.feedback}:{}}}:{content:[{type:"text",text:"Plan approved. Proceed with the steps."}],details:{approved:!0}}},"execute")});const L=i((u,e)=>{let o;return r.events.emit(z,{ref:u,...e!==void 0?{title:e}:{},reply:i(s=>{o=s},"reply")}),o},"resolveThumbnail");r.registerTool({name:h,label:t("\u8BE2\u95EE\u7528\u6237"),description:t("\u52A8\u624B\u505A PPT\u3001\u6587\u6863\u3001\u8868\u683C\u3001\u9875\u9762\u4E4B\u524D\uFF0C\u7528\u4E00\u5F20\u5361\u7247\u5411\u7528\u6237\u786E\u8BA4\u4F1A\u6539\u53D8\u4EA7\u51FA\u7684\u5173\u952E\u51B3\u5B9A\uFF08\u6700\u591A 3 \u9898\uFF09\u3002\u9898\u578B\uFF1Achoice \u9009\u9879\uFF08\u53EF\u5E26\u7F29\u7565\u56FE\uFF09\u3001swatch \u914D\u8272\u3001outline \u53EF\u6392\u5E8F\u5927\u7EB2\u3001slider \u6570\u503C\u3001text \u81EA\u7531\u6587\u672C\u3002\u6BCF\u9898\u90FD\u8981\u6709\u63A8\u8350\u9879\u3002"),promptSnippet:t("ask_user - \u5F00\u5DE5\u524D\u7528\u4E00\u5F20\u5361\u7247\u786E\u8BA4\u5173\u952E\u51B3\u5B9A\uFF08\u6700\u591A 3 \u9898\uFF0C\u6BCF\u9898\u6709\u63A8\u8350\u9879\uFF09"),promptGuidelines:[t("ask_user \u53EA\u5728\u5F00\u5DE5\u524D\u95EE\u4E00\u6B21\uFF0C\u4E00\u8F6E\u6700\u591A 3 \u9898\uFF1B\u540C\u4E00\u4EFB\u52A1\u4E4B\u540E\u4E0D\u518D\u8FFD\u95EE\uFF0C\u9664\u975E\u7528\u6237\u4E3B\u52A8\u8981\u6C42\u3002"),t("\u53EA\u95EE\u4F1A\u6539\u53D8\u4EA7\u51FA\u7684\u51B3\u5B9A\uFF08\u53D7\u4F17/\u7528\u9014\u3001\u98CE\u683C\u6216\u4E3B\u9898\u3001\u7BC7\u5E45\u3001\u5927\u7EB2\u987A\u5E8F\uFF09\uFF1B\u80FD\u4ECE\u7528\u6237\u539F\u8BDD\u3001\u9644\u4EF6\u6216\u9879\u76EE\u6587\u4EF6\u63A8\u65AD\u51FA\u7684\u4E0D\u95EE\u3002"),t("\u7528\u6237\u8BF4\u4E86\u300C\u76F4\u63A5\u505A / \u4F60\u51B3\u5B9A / \u5FEB\u901F\u51FA\u4E00\u7248\u300D\uFF0C\u6216\u662F\u5728\u4FEE\u6539\u5DF2\u6709\u6587\u4EF6\uFF08\u5E26\u5B9A\u4F4D\u3001\u300C\u628A\u7B2C 3 \u9875\u6539\u6210\u2026\u300D\uFF09\u65F6\uFF0C\u4E0D\u8981\u8C03\u7528 ask_user\u3002"),t("\u6BCF\u9898\u90FD\u6807\u51FA\u63A8\u8350\u9879\uFF08recommended\uFF09\uFF1B\u98CE\u683C\u9898\u4F18\u5148\u7528 thumbnail \u7F29\u7565\u56FE\uFF08theme:\u2026 / page:\u2026 / doc:\u2026\uFF09\uFF0C\u914D\u8272\u7528 swatch\u3002"),t("\u7528\u6237\u8DF3\u8FC7\u65F6\u6309\u63A8\u8350\u9879\u7EE7\u7EED\uFF0C\u5E76\u5728\u56DE\u590D\u91CC\u7528\u4E00\u53E5\u8BDD\u8BF4\u660E\u7528\u4E86\u54EA\u4E9B\u63A8\u8350\u9879\u3002")],parameters:j,execute:i(async(u,e,o,s,a)=>{let n;try{n=V(e,a.cwd,L)}catch(w){throw w instanceof q?new Error(`ask_user: ${w.message}`):w}const E=await F.post("/api/internal/pi-bridge/ask-user",{...A(a),...n},{timeoutMs:J()});if(!E||E.cancelled)return{content:[{type:"text",text:"User did not answer. Stop and wait for further instructions."}],details:{answered:!1,request:n}};const{text:O,skipped:U}=G(n,E);return{content:[{type:"text",text:O}],details:{answered:!0,answers:E.answers??{},...E.structured?{structured:E.structured}:{},...E.summary?{summary:E.summary}:{},skipped:U,request:n}}},"execute")})}D(N,"q"),i(N,"default");export{I as EVALUATE_READS_ENV,N as default};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dalcode/dal-gateway",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.27",
|
|
4
4
|
"private": true,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./src/index.js",
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
]
|
|
18
18
|
},
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"@dalcode/deepailab": "1.0.
|
|
20
|
+
"@dalcode/deepailab": "1.0.27"
|
|
21
21
|
},
|
|
22
22
|
"peerDependencies": {
|
|
23
23
|
"@earendil-works/pi-coding-agent": "^1.0.9"
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dalcode/dal-guard",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.27",
|
|
4
4
|
"private": true,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./src/index.js",
|
|
@@ -18,9 +18,9 @@
|
|
|
18
18
|
]
|
|
19
19
|
},
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@dalcode/dal-pi-kit": "1.0.
|
|
22
|
-
"@dalcode/dal-bridge": "1.0.
|
|
23
|
-
"@dalcode/dal-halo": "1.0.
|
|
21
|
+
"@dalcode/dal-pi-kit": "1.0.27",
|
|
22
|
+
"@dalcode/dal-bridge": "1.0.27",
|
|
23
|
+
"@dalcode/dal-halo": "1.0.27"
|
|
24
24
|
},
|
|
25
25
|
"peerDependencies": {
|
|
26
26
|
"@earendil-works/pi-coding-agent": "^1.0.9"
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dalcode/dal-interactive",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.27",
|
|
4
4
|
"private": true,
|
|
5
5
|
"description": "Terminal-UI conveniences adopted from pi's example extensions: the questionnaire tool (the model asks you questions), /handoff (carry context into a new session) and interactive ! commands (vim, git rebase -i, htop). Active only in the TUI; stands down under DAL Code.",
|
|
6
6
|
"license": "MIT",
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
]
|
|
20
20
|
},
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@dalcode/dal-pi-kit": "1.0.
|
|
22
|
+
"@dalcode/dal-pi-kit": "1.0.27",
|
|
23
23
|
"typebox": "1.3.7"
|
|
24
24
|
},
|
|
25
25
|
"peerDependencies": {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dalcode/dal-lang",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.27",
|
|
4
4
|
"private": true,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./src/index.js",
|
|
@@ -17,8 +17,8 @@
|
|
|
17
17
|
]
|
|
18
18
|
},
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"@dalcode/dal-pi-kit": "1.0.
|
|
21
|
-
"@dalcode/dal-bridge": "1.0.
|
|
20
|
+
"@dalcode/dal-pi-kit": "1.0.27",
|
|
21
|
+
"@dalcode/dal-bridge": "1.0.27"
|
|
22
22
|
},
|
|
23
23
|
"peerDependencies": {
|
|
24
24
|
"@earendil-works/pi-coding-agent": "^1.0.9"
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dalcode/dal-lsp",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.27",
|
|
4
4
|
"private": true,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./src/index.js",
|
|
@@ -19,8 +19,8 @@
|
|
|
19
19
|
]
|
|
20
20
|
},
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@dalcode/dal-bridge": "1.0.
|
|
23
|
-
"@dalcode/dal-pi-kit": "1.0.
|
|
22
|
+
"@dalcode/dal-bridge": "1.0.27",
|
|
23
|
+
"@dalcode/dal-pi-kit": "1.0.27",
|
|
24
24
|
"cross-spawn": "7.0.6",
|
|
25
25
|
"typebox": "1.3.7"
|
|
26
26
|
},
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dalcode/dal-mcp",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.27",
|
|
4
4
|
"private": true,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./src/index.js",
|
|
@@ -26,10 +26,10 @@
|
|
|
26
26
|
]
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@dalcode/dal-bridge": "1.0.
|
|
30
|
-
"@dalcode/dal-guard": "1.0.
|
|
31
|
-
"@dalcode/dal-pi-kit": "1.0.
|
|
32
|
-
"@dalcode/deepailab": "1.0.
|
|
29
|
+
"@dalcode/dal-bridge": "1.0.27",
|
|
30
|
+
"@dalcode/dal-guard": "1.0.27",
|
|
31
|
+
"@dalcode/dal-pi-kit": "1.0.27",
|
|
32
|
+
"@dalcode/deepailab": "1.0.27",
|
|
33
33
|
"cross-spawn": "7.0.6"
|
|
34
34
|
},
|
|
35
35
|
"peerDependencies": {
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var w=Object.defineProperty;var c=(u,n)=>w(u,"name",{value:n,configurable:!0});var L=Object.defineProperty,E=c((u,n)=>L(u,"name",{value:n,configurable:!0}),"u");import{t as r}from"@dalcode/dal-pi-kit";import{assertValidName as j,tokenizeCommandArgs as
|
|
1
|
+
var w=Object.defineProperty;var c=(u,n)=>w(u,"name",{value:n,configurable:!0});var L=Object.defineProperty,E=c((u,n)=>L(u,"name",{value:n,configurable:!0}),"u");import{t as r}from"@dalcode/dal-pi-kit";import{assertValidName as j,tokenizeCommandArgs as C}from"./command-parser.js";const U=r("stdio\uFF08\u672C\u5730\u547D\u4EE4\uFF09"),v=r("http\uFF08\u8FDC\u7A0B URL\uFF09"),O=r("\u7528\u6237\u7EA7 ~/.dal/agent/mcp.json\uFF08\u672C\u673A\u6240\u6709\u9879\u76EE\u53EF\u7528\uFF09"),D=r("\u9879\u76EE\u7EA7 .dal/mcp.json\uFF08\u4EC5\u5F53\u524D\u9879\u76EE\uFF0C\u9700\u5DF2\u4FE1\u4EFB\uFF09");async function m(u,n,i){for(;;){const t=await u.input(n);if(t===void 0)return;const F=i(t);if(F===void 0)return t;u.notify(F,"error")}}c(m,"m"),E(m,"askValid");function y(u){const n={};for(const i of u.split(/[,,]/)){const t=i.trim();if(!t)continue;const F=t.indexOf("=");if(F===-1||!t.slice(0,F).trim())return{ok:!1,error:`${r("\u65E0\u6548\u7684\u73AF\u5883\u53D8\u91CF\u683C\u5F0F\uFF08KEY=VALUE\uFF09\uFF1A")}${t}`};n[t.slice(0,F).trim()]=t.slice(F+1).trim()}return{ok:!0,value:n}}c(y,"U"),E(y,"parseEnvList");function B(u){const n={};for(const i of u.split(/[,,]/)){const t=i.trim();if(!t)continue;const F=t.indexOf(":");if(F===-1||!t.slice(0,F).trim())return{ok:!1,error:`${r("\u65E0\u6548\u7684\u8BF7\u6C42\u5934\u683C\u5F0F\uFF08Key: Value\uFF09\uFF1A")}${t}`};n[t.slice(0,F).trim()]=t.slice(F+1).trim()}return{ok:!0,value:n}}c(B,"$"),E(B,"parseHeaderList");async function g(u,n){const i=await u.select(r("\u8981\u6DFB\u52A0\u7684 MCP \u670D\u52A1\u5668\u7C7B\u578B\uFF1A"),[U,v]);if(i===void 0)return;const t=i===v,F=await m(u,r("\u670D\u52A1\u5668\u540D\u79F0\uFF08\u4EC5\u5B57\u6BCD\u3001\u6570\u5B57\u3001-\u3001_\uFF09\uFF1A"),s=>{try{j(s.trim());return}catch(o){return o instanceof Error?o.message:String(o)}});if(F===void 0)return;let l;if(t){const s=await m(u,r("\u670D\u52A1\u5668 URL\uFF08http(s)://\u2026\uFF09\uFF1A"),e=>{let f;try{f=new URL(e.trim())}catch{return`${r("URL \u65E0\u6548\uFF1A")}${e.trim()}`}if(f.protocol!=="http:"&&f.protocol!=="https:")return`${r("URL \u4EC5\u652F\u6301 http(s)\uFF1A")}${e.trim()}`});if(s===void 0)return;const o=await u.input(r("\u8BF7\u6C42\u5934\uFF08\u53EF\u9009\uFF0C\u9017\u53F7\u5206\u9694 Key: Value\uFF09\uFF1A"));if(o===void 0)return;const a=B(o);if(!a.ok){u.notify(a.error,"error");return}l={url:s.trim(),...Object.keys(a.value).length>0?{headers:a.value}:{}}}else{const s=await m(u,r("\u542F\u52A8\u547D\u4EE4\uFF08\u542B\u53C2\u6570\uFF0C\u5199\u660E\u7248\u672C\u53F7\uFF0C\u5982 npx -y some-mcp-server@1.2.3\uFF09\uFF1A"),k=>C(k).length>0?void 0:r("\u547D\u4EE4\u4E0D\u80FD\u4E3A\u7A7A\u3002"));if(s===void 0)return;const o=C(s),a=await u.input(r("\u73AF\u5883\u53D8\u91CF\uFF08\u53EF\u9009\uFF0C\u9017\u53F7\u5206\u9694 KEY=VALUE\uFF09\uFF1A"));if(a===void 0)return;const e=y(a);if(!e.ok){u.notify(e.error,"error");return}const[f,...p]=o;l={command:f,...p.length>0?{args:p}:{},...Object.keys(e.value).length>0?{env:e.value}:{}}}const h=[O,D],A=await u.select(r("\u4FDD\u5B58\u4F4D\u7F6E\uFF1A"),h);if(A===void 0)return;const d=A===D?"project":"user",$=d==="user"?"~/.dal/agent/mcp.json":`${n}/.dal/mcp.json`;if(await u.confirm(r("\u786E\u8BA4\u4FDD\u5B58\u8BE5 MCP \u670D\u52A1\u5668\uFF1F"),`${F.trim()} \u2192 ${$}
|
|
2
2
|
${JSON.stringify(l,null,2)}`))return{name:F.trim(),scope:d,config:l}}c(g,"j"),E(g,"runAddWizard");export{g as runAddWizard};
|
|
@@ -4,6 +4,6 @@ export interface LoadMcpServerConfigsOptions {
|
|
|
4
4
|
projectTrusted?: boolean;
|
|
5
5
|
accountServers?: Record<string, McpServerConfig>;
|
|
6
6
|
}
|
|
7
|
-
export declare const DEFAULT_MCP_SERVERS: Record<string, McpServerConfig
|
|
7
|
+
export declare const DEFAULT_MCP_SERVERS: Readonly<Record<string, McpServerConfig>>;
|
|
8
8
|
export declare function takeMcpConfigProblems(): string[];
|
|
9
9
|
export declare function loadMcpServerConfigs(cwd: string, opts?: LoadMcpServerConfigsOptions): Record<string, McpServerConfig>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
var
|
|
1
|
+
var j=Object.defineProperty;var t=(r,e)=>j(r,"name",{value:e,configurable:!0});var A=Object.defineProperty,s=t((r,e)=>A(r,"name",{value:e,configurable:!0}),"o");import{existsSync as D,readFileSync as O}from"node:fs";import{join as p}from"node:path";import{CONFIG_DIR_NAME as h,getAgentDir as C}from"@earendil-works/pi-coding-agent";const m=Object.freeze({});function i(r){return!r||typeof r!="object"||Array.isArray(r)?!1:Object.values(r).every(e=>typeof e=="string")}t(i,"d"),s(i,"isStringRecord");function y(r){return!r||typeof r!="object"||Array.isArray(r)?!1:r.disabled===!0}t(y,"C"),s(y,"isDisabled");function g(r){if(!r||typeof r!="object"||Array.isArray(r))return;const e=r;if(typeof e.url=="string"&&e.url.length>0)return{url:e.url,...i(e.headers)?{headers:e.headers}:{}};if(typeof e.command=="string"&&e.command.length>0)return{command:e.command,...Array.isArray(e.args)&&e.args.every(n=>typeof n=="string")?{args:e.args}:{},...i(e.env)?{env:e.env}:{},...typeof e.cwd=="string"?{cwd:e.cwd}:{}}}t(g,"b"),s(g,"parseServer");function a(){return{servers:{},names:new Set,disabled:new Set}}t(a,"i"),s(a,"emptyLayer");function u(r){if(!D(r))return a();try{const e=JSON.parse(O(r,"utf8")),n=a();for(const[o,d]of Object.entries(e.mcpServers??{})){if(y(d)){n.names.add(o),n.disabled.add(o);continue}const l=g(d);if(!l){c.push(`${r}: \u670D\u52A1\u5668 "${o}" \u7F3A\u5C11 command \u6216 url\uFF0C\u5DF2\u5FFD\u7565`);continue}n.names.add(o),n.servers[o]=l}return n}catch(e){return c.push(`${r}: ${e instanceof Error?e.message:String(e)}`),a()}}t(u,"g"),s(u,"readServersFile");const c=[];function v(){return c.splice(0,c.length)}t(v,"O"),s(v,"takeMcpConfigProblems");function f(r,e){for(const n of e.names)delete r[n];Object.assign(r,e.servers);for(const n of e.disabled)delete r[n]}t(f,"u"),s(f,"applyLayer");function b(r){return r?.includeDefaults!==void 0?r.includeDefaults:!!process.env.DALCODE_BRIDGE_URL}t(b,"M"),s(b,"shouldIncludeDefaults");function S(r,e){const n={};return b(e)&&Object.assign(n,m),e?.accountServers&&Object.assign(n,e.accountServers),f(n,u(p(C(),"mcp.json"))),e?.projectTrusted&&f(n,u(p(r,h,"mcp.json"))),n}t(S,"w"),s(S,"loadMcpServerConfigs");export{m as DEFAULT_MCP_SERVERS,S as loadMcpServerConfigs,v as takeMcpConfigProblems};
|