UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

2 lines • 2.27 kB
//!extensions/anthropic/cli-runtime-args.ts const PROTOCOL_FLAGS=/* @__PURE__ */ new Set([`-p`,`--print`,`--verbose`,`--include-partial-messages`,`--replay-user-messages`,`--dangerously-skip-permissions`,`--allow-dangerously-skip-permissions`]);const PROTOCOL_VALUE_FLAGS=/* @__PURE__ */ new Set([`--output-format`,`--input-format`,`--permission-prompt-tool`,`--permission-mode`,`--model`,`--session-id`,`--resume`,`-r`,`--append-system-prompt-file`,`--append-system-prompt`,`--system-prompt-file`,`--system-prompt`]);const TOOL_FLAGS=/* @__PURE__ */ new Set([`--tools`,`--allowedTools`,`--allowed-tools`]);function prepareClaudeCliTransportArgs(e){const t=[];const n=[];let r;let i=`user`;let a=false;for(let o=0;o<e.args.length;o+=1){const s=e.args[o];const c=s.indexOf(`=`);const l=c<0?s:s.slice(0,c);if(PROTOCOL_FLAGS.has(l))continue;if(l===`--exclude-dynamic-system-prompt-sections`){a=true;continue}if(!PROTOCOL_VALUE_FLAGS.has(l)&&!TOOL_FLAGS.has(l)&&l!==`--setting-sources`){t.push(s);continue}const u=c<0?e.args[++o]:s.slice(c+1);if(u===void 0)throw new Error(`Claude CLI cannot preserve ${l} without its value.`);if(PROTOCOL_VALUE_FLAGS.has(l))continue;if(l===`--setting-sources`){if(u!==``&&u!==`user`)throw new Error(`Claude CLI settings must be limited to user settings.`);i=u;continue}const d=[u];if(c<0)while(o+1<e.args.length&&!e.args[o+1]?.startsWith(`-`))d.push(e.args[++o]);const f=d.flatMap(e=>e.split(`,`).map(e=>e.trim()).filter(Boolean));if(l===`--tools`)r=f;else n.push(...f.filter(e=>e.startsWith(`mcp__openclaw__`)))}let o=[...new Set(n)];if(e.toolAvailability){r=[...e.toolAvailability.native,...e.toolAvailability.discovery??[]];o=e.toolAvailability.openClaw.map(e=>`mcp__openclaw__${e}`).filter(e=>n.includes(e)||n.includes(`mcp__openclaw__*`))}t.push(`--print`,`--input-format`,`stream-json`,`--output-format`,`stream-json`,`--verbose`,`--include-partial-messages`,`--replay-user-messages`,`--permission-prompt-tool`,`stdio`,`--permission-mode`,`default`,`--setting-sources`,i,`--model`,e.modelId);if(r)t.push(`--tools`,r.join(`,`));if(o.length)t.push(`--allowedTools`,o.join(`,`));if(e.sessionId)t.push(e.useResume?`--resume`:`--session-id`,e.sessionId);return{args:t,excludeDynamicSections:a}}export{prepareClaudeCliTransportArgs as t};