blade-code 0.10.5 → 0.10.6

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.
Files changed (90) hide show
  1. package/dist/blade.js +2 -2
  2. package/dist/{chunk-rh7v814a.js → chunk-0rp2ck29.js} +2 -2
  3. package/dist/chunk-10k6egwk.js +1 -0
  4. package/dist/chunk-17xtw88g.js +1 -0
  5. package/dist/chunk-1cvr3qtd.js +1482 -0
  6. package/dist/chunk-1kg9r8xp.js +2 -0
  7. package/dist/{chunk-51wtvmzn.js → chunk-383vbwmt.js} +1 -1
  8. package/dist/chunk-3kk3bk11.js +1 -0
  9. package/dist/{chunk-6tx8k249.js → chunk-45dcfkwe.js} +2 -2
  10. package/dist/chunk-47dsd91k.js +99 -0
  11. package/dist/chunk-4kaygjqv.js +10 -0
  12. package/dist/{chunk-35yktzm1.js → chunk-4y28hykg.js} +1 -1
  13. package/dist/chunk-50fq7r0h.js +22 -0
  14. package/dist/chunk-59eje513.js +1 -0
  15. package/dist/{chunk-qda309d9.js → chunk-6cv4gddv.js} +2 -2
  16. package/dist/{chunk-hh85pk77.js → chunk-710bvht9.js} +47 -47
  17. package/dist/{chunk-xv0maezy.js → chunk-76d7p64v.js} +1 -1
  18. package/dist/{chunk-bexgcc2d.js → chunk-7xm3vjkz.js} +1 -1
  19. package/dist/{chunk-19kg7yvw.js → chunk-9sfmrb1j.js} +2 -2
  20. package/dist/chunk-a9pbpgkg.js +9 -0
  21. package/dist/{chunk-gxmrakrk.js → chunk-b4n34hrn.js} +1 -1
  22. package/dist/{chunk-v93hcxe7.js → chunk-bn0ge244.js} +1 -1
  23. package/dist/{chunk-fvhc1yj8.js → chunk-bnrce0hg.js} +1 -1
  24. package/dist/{chunk-9ffr01c3.js → chunk-c2rhwxyn.js} +1 -1
  25. package/dist/chunk-c8rky275.js +6 -0
  26. package/dist/{chunk-epj56s0n.js → chunk-c9tzf9r5.js} +1 -1
  27. package/dist/{chunk-njyvrtje.js → chunk-dcvvxsa1.js} +2 -2
  28. package/dist/{chunk-5twefby5.js → chunk-evaht3v4.js} +1 -1
  29. package/dist/{chunk-0n97186m.js → chunk-frcg8gea.js} +2 -2
  30. package/dist/{chunk-drrdzmaa.js → chunk-g4q26d9a.js} +2 -2
  31. package/dist/{chunk-s645azsm.js → chunk-g9n211y4.js} +2 -2
  32. package/dist/{chunk-vntzy7bc.js → chunk-gb4n3hwj.js} +2 -2
  33. package/dist/{chunk-ea7wsges.js → chunk-hjsm6ejs.js} +2 -2
  34. package/dist/chunk-j1sd03h7.js +1 -0
  35. package/dist/chunk-jqyvnmfr.js +187 -0
  36. package/dist/chunk-jrh5tzc4.js +1 -0
  37. package/dist/{chunk-an96c54z.js → chunk-k0p9ecgc.js} +7 -7
  38. package/dist/{chunk-z906d5tb.js → chunk-kcs3xa8f.js} +2 -2
  39. package/dist/{chunk-63ysxybd.js → chunk-kcwq1e7h.js} +1 -1
  40. package/dist/chunk-kj1ah6kn.js +1 -0
  41. package/dist/{chunk-am8dtvff.js → chunk-m4htdpr9.js} +2 -2
  42. package/dist/chunk-n34z4c47.js +1 -0
  43. package/dist/{chunk-6eragc74.js → chunk-n5m2p0bq.js} +2 -2
  44. package/dist/{chunk-gxzbv67r.js → chunk-n9khyme2.js} +2 -2
  45. package/dist/{chunk-1vx4sf1y.js → chunk-nfmsn652.js} +2 -2
  46. package/dist/{chunk-ydtcvxsm.js → chunk-p196e4rq.js} +1 -1
  47. package/dist/{chunk-qm11hjd3.js → chunk-p4j4aawd.js} +1 -1
  48. package/dist/chunk-qvabd0vg.js +1 -0
  49. package/dist/{chunk-sanhjqpd.js → chunk-r083b7vn.js} +2 -2
  50. package/dist/{chunk-gb54hc78.js → chunk-rag8zchg.js} +1 -1
  51. package/dist/{chunk-ygx03mdh.js → chunk-rw6gv740.js} +1 -1
  52. package/dist/{chunk-jza1rsan.js → chunk-sf9pe2n6.js} +1 -1
  53. package/dist/chunk-t75wspk3.js +1 -0
  54. package/dist/{chunk-vpj0sv73.js → chunk-thvwt4kc.js} +3 -3
  55. package/dist/{chunk-yc53wz4r.js → chunk-v1p80wvh.js} +2 -2
  56. package/dist/chunk-vddqv6fv.js +1 -0
  57. package/dist/{chunk-948qe2pp.js → chunk-vvbd9fb5.js} +1 -1
  58. package/dist/{chunk-15d49qty.js → chunk-w154jyby.js} +1 -1
  59. package/dist/{chunk-dqvcgwhe.js → chunk-w4zvftrw.js} +2 -2
  60. package/dist/chunk-wa7v7akz.js +3 -0
  61. package/dist/chunk-wxwqz67n.js +1 -0
  62. package/dist/chunk-x9hm3p3a.js +1 -0
  63. package/dist/chunk-xd2g4zjx.js +1 -0
  64. package/dist/{chunk-tq52pbde.js → chunk-xkp4ph6v.js} +1 -1
  65. package/dist/{chunk-fz1vyc15.js → chunk-xsmtpkjm.js} +1 -1
  66. package/dist/{chunk-g6h6h8xr.js → chunk-yt39kfc6.js} +1 -1
  67. package/package.json +1 -1
  68. package/dist/chunk-069zpw09.js +0 -6
  69. package/dist/chunk-1m5r6mp2.js +0 -180
  70. package/dist/chunk-1q21sxhx.js +0 -1
  71. package/dist/chunk-1r6szcrj.js +0 -1
  72. package/dist/chunk-1x4fpe47.js +0 -1
  73. package/dist/chunk-2nkd1kjx.js +0 -1
  74. package/dist/chunk-417wefq7.js +0 -99
  75. package/dist/chunk-4ncbd4k0.js +0 -1
  76. package/dist/chunk-62881c2s.js +0 -1484
  77. package/dist/chunk-7443b95r.js +0 -1
  78. package/dist/chunk-79s052sw.js +0 -2
  79. package/dist/chunk-7jy60gnx.js +0 -1
  80. package/dist/chunk-c5tds5v0.js +0 -9
  81. package/dist/chunk-ccwskwb3.js +0 -1
  82. package/dist/chunk-f6mszdsd.js +0 -1
  83. package/dist/chunk-nz78b5c5.js +0 -10
  84. package/dist/chunk-r1764q6f.js +0 -1
  85. package/dist/chunk-r6mwyg3h.js +0 -3
  86. package/dist/chunk-rzzt21ef.js +0 -22
  87. package/dist/chunk-t8x2qpe2.js +0 -1
  88. package/dist/chunk-tjnfhm9v.js +0 -1
  89. package/dist/chunk-v0ygsjry.js +0 -1
  90. package/dist/chunk-zyz82mcd.js +0 -1
package/dist/blade.js CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import{Rb as W}from"./chunk-vntzy7bc.js";import{Ub as F,Vb as M}from"./chunk-drrdzmaa.js";import"./chunk-sanhjqpd.js";import"./chunk-g6h6h8xr.js";import"./chunk-fvhc1yj8.js";import"./chunk-vpj0sv73.js";import"./chunk-qm11hjd3.js";import{md as T}from"./chunk-qda309d9.js";import"./chunk-rh7v814a.js";import"./chunk-tq52pbde.js";import"./chunk-79s052sw.js";import{qe as N,re as B}from"./chunk-epj56s0n.js";import"./chunk-gxzbv67r.js";import"./chunk-bexgcc2d.js";import"./chunk-1vx4sf1y.js";import"./chunk-z906d5tb.js";import"./chunk-948qe2pp.js";import"./chunk-0n97186m.js";import{Ve as K}from"./chunk-9ffr01c3.js";import C from"node:path";var E=process.argv.slice(2),I=p(E),v=I!==null;if(I!==null)T.setGlobalDebug(I);function p(Q){for(let Y=0;Y<Q.length;Y+=1){let U=Q[Y];if(U==="--debug"||U==="-d"){let X=Q[Y+1];return X&&!X.startsWith("-")?X:!0}if(U.startsWith("--debug="))return U.slice(8)||!0}return null}function u(Q){return Q.length===1&&(Q[0]==="--version"||Q[0]==="-V")}function q(Q,...Y){return Q.some((U)=>Y.some((X)=>U===X||U.startsWith(`${X}=`)))}function c(Q,...Y){let U=[];for(let X=0;X<Q.length;X+=1){let G=Q[X],z=Y.find(($)=>G.startsWith(`${$}=`));if(z){let $=G.slice(z.length+1);if($)U.push($);continue}if(Y.includes(G)){let $=Q[X+1];if($&&!$.startsWith("-"))U.push($),X+=1}}return U}async function m(){if(u(E)){let{getVersion:J}=await import("./chunk-1r6szcrj.js");console.log(J());return}let Q=process.cwd(),Y=F(Q);M(Y),N(B());let U=c(E,"--plugin-dir","--pluginDir");if(U.length>0){let{configureInvocationPluginDirs:J}=await import("./chunk-tjnfhm9v.js");J(U.map((Z)=>C.resolve(Q,Z)))}if(q(E,"--trust-workspace","--trustWorkspace")){let{WorkspaceTrustService:J}=await import("./chunk-ccwskwb3.js");await J.getInstance().trust(B())}if(process.getuid&&process.getuid()===0){let J=!!process.env.SUDO_USER,Z=!!process.env.BLADE_ALLOW_ROOT;if(J&&!Z)console.error(""),console.error("Error: 请不要使用 sudo 运行 blade"),console.error(""),console.error("原因:"),console.error(" 使用 sudo 会创建属于 root 的配置文件,"),console.error(" 导致普通用户无法访问。"),console.error(""),console.error("正确用法:"),console.error(" blade # 直接运行,不要加 sudo"),console.error(""),console.error("如果遇到权限错误,请运行:"),console.error(" sudo chown -R $USER:$USER ~/.blade/"),console.error(""),console.error("如果你确实需要以 root 运行(容器/CI),设置环境变量:"),console.error(" BLADE_ALLOW_ROOT=1 blade"),console.error(""),process.exit(1)}if(q(E,"--headless")){let{handleHeadlessMode:J}=await import("./chunk-069zpw09.js");if(await J())return}if(W(),q(E,"--print","-p")){let{handlePrintMode:J}=await import("./chunk-c5tds5v0.js");if(await J())return}if(E.includes("--acp")){let{runAcpIntegration:J}=await import("./chunk-rzzt21ef.js");await J();return}let[{default:X},{hideBin:G},{cliConfig:z,globalOptions:$},{loadConfiguration:_,validateOutput:D,validatePermissions:R},{doctorCommands:S},{installCommands:k},{mcpCommands:O},{projectsCommands:y},{serveCommand:b},{updateCommands:V},{webCommand:P}]=await Promise.all([import("yargs"),import("yargs/helpers"),import("./chunk-r1764q6f.js"),import("./chunk-1q21sxhx.js"),import("./chunk-njyvrtje.js"),import("./chunk-gb54hc78.js"),import("./chunk-fz1vyc15.js"),import("./chunk-v93hcxe7.js"),import("./chunk-2nkd1kjx.js"),import("./chunk-5twefby5.js"),import("./chunk-nz78b5c5.js")]),x=X(G(process.argv)).scriptName(z.scriptName).usage(z.usage).version(z.version).locale(z.locale).showHelpOnFail(z.showHelpOnFail).demandCommand(0,"").recommendCommands().strict(z.strict).parserConfiguration({"populate--":!0}).options($).middleware([_,R,D]).command(O).command(y).command(S).command(V).command(k).command(P).command(b).completion("completion",!1).help("help","Show help").alias("help","h").alias("version","V").fail((J,Z,L)=>{if(Z){if(console.error("An error occurred:"),console.error(Z.message),v&&Z.stack)console.error(`
2
+ import{Wb as W}from"./chunk-gb4n3hwj.js";import{Zb as F,_b as M}from"./chunk-g4q26d9a.js";import"./chunk-r083b7vn.js";import"./chunk-yt39kfc6.js";import"./chunk-bnrce0hg.js";import"./chunk-thvwt4kc.js";import"./chunk-p4j4aawd.js";import{rd as T}from"./chunk-6cv4gddv.js";import"./chunk-0rp2ck29.js";import"./chunk-xkp4ph6v.js";import"./chunk-1kg9r8xp.js";import{ve as N,we as B}from"./chunk-c9tzf9r5.js";import"./chunk-n9khyme2.js";import"./chunk-7xm3vjkz.js";import"./chunk-nfmsn652.js";import"./chunk-kcs3xa8f.js";import"./chunk-vvbd9fb5.js";import"./chunk-frcg8gea.js";import{_e as K}from"./chunk-c2rhwxyn.js";import C from"node:path";var E=process.argv.slice(2),I=p(E),v=I!==null;if(I!==null)T.setGlobalDebug(I);function p(Q){for(let Y=0;Y<Q.length;Y+=1){let U=Q[Y];if(U==="--debug"||U==="-d"){let X=Q[Y+1];return X&&!X.startsWith("-")?X:!0}if(U.startsWith("--debug="))return U.slice(8)||!0}return null}function u(Q){return Q.length===1&&(Q[0]==="--version"||Q[0]==="-V")}function q(Q,...Y){return Q.some((U)=>Y.some((X)=>U===X||U.startsWith(`${X}=`)))}function c(Q,...Y){let U=[];for(let X=0;X<Q.length;X+=1){let G=Q[X],z=Y.find(($)=>G.startsWith(`${$}=`));if(z){let $=G.slice(z.length+1);if($)U.push($);continue}if(Y.includes(G)){let $=Q[X+1];if($&&!$.startsWith("-"))U.push($),X+=1}}return U}async function m(){if(u(E)){let{getVersion:J}=await import("./chunk-qvabd0vg.js");console.log(J());return}let Q=process.cwd(),Y=F(Q);M(Y),N(B());let U=c(E,"--plugin-dir","--pluginDir");if(U.length>0){let{configureInvocationPluginDirs:J}=await import("./chunk-wxwqz67n.js");J(U.map((Z)=>C.resolve(Q,Z)))}if(q(E,"--trust-workspace","--trustWorkspace")){let{WorkspaceTrustService:J}=await import("./chunk-kj1ah6kn.js");await J.getInstance().trust(B())}if(process.getuid&&process.getuid()===0){let J=!!process.env.SUDO_USER,Z=!!process.env.BLADE_ALLOW_ROOT;if(J&&!Z)console.error(""),console.error("Error: 请不要使用 sudo 运行 blade"),console.error(""),console.error("原因:"),console.error(" 使用 sudo 会创建属于 root 的配置文件,"),console.error(" 导致普通用户无法访问。"),console.error(""),console.error("正确用法:"),console.error(" blade # 直接运行,不要加 sudo"),console.error(""),console.error("如果遇到权限错误,请运行:"),console.error(" sudo chown -R $USER:$USER ~/.blade/"),console.error(""),console.error("如果你确实需要以 root 运行(容器/CI),设置环境变量:"),console.error(" BLADE_ALLOW_ROOT=1 blade"),console.error(""),process.exit(1)}if(q(E,"--headless")){let{handleHeadlessMode:J}=await import("./chunk-c8rky275.js");if(await J())return}if(W(),q(E,"--print","-p")){let{handlePrintMode:J}=await import("./chunk-a9pbpgkg.js");if(await J())return}if(E.includes("--acp")){let{runAcpIntegration:J}=await import("./chunk-50fq7r0h.js");await J();return}let[{default:X},{hideBin:G},{cliConfig:z,globalOptions:$},{loadConfiguration:_,validateOutput:D,validatePermissions:R},{doctorCommands:S},{installCommands:k},{mcpCommands:O},{projectsCommands:y},{serveCommand:b},{updateCommands:V},{webCommand:P}]=await Promise.all([import("yargs"),import("yargs/helpers"),import("./chunk-17xtw88g.js"),import("./chunk-59eje513.js"),import("./chunk-dcvvxsa1.js"),import("./chunk-rag8zchg.js"),import("./chunk-xsmtpkjm.js"),import("./chunk-bn0ge244.js"),import("./chunk-vddqv6fv.js"),import("./chunk-evaht3v4.js"),import("./chunk-4kaygjqv.js")]),x=X(G(process.argv)).scriptName(z.scriptName).usage(z.usage).version(z.version).locale(z.locale).showHelpOnFail(z.showHelpOnFail).demandCommand(0,"").recommendCommands().strict(z.strict).parserConfiguration({"populate--":!0}).options($).middleware([_,R,D]).command(O).command(y).command(S).command(V).command(k).command(P).command(b).completion("completion",!1).help("help","Show help").alias("help","h").alias("version","V").fail((J,Z,L)=>{if(Z){if(console.error("An error occurred:"),console.error(Z.message),v&&Z.stack)console.error(`
3
3
  Stack trace:`),console.error(Z.stack);else console.error(`
4
4
  Run with --debug to show the stack trace.`);process.exit(1)}if(J)console.error("Error: Invalid arguments:"),console.error(J),console.error(`
5
- Hint: Did you mean:`),L.showHelp(),process.exit(1)}).command("$0",!1,()=>{},async(J)=>{let Z=J._.slice(1),L=Z.length>0?Z.join(" "):void 0,h=import("./chunk-4ncbd4k0.js").then(({checkVersionOnStartup:j})=>j()),[{render:A},{createElement:w},{AppWrapper:f}]=await Promise.all([import("ink"),import("react"),import("./chunk-hh85pk77.js")]),H={...J,initialMessage:L,debug:J.debug,print:Boolean(J.print),versionCheckPromise:h};delete H._,delete H.$0,delete H.message,A(w(f,H),{patchConsole:!0,exitOnCtrlC:!1,alternateBuffer:!1})});try{await x.parse()}catch(J){console.error("Error: Parse error:",J),process.exit(1)}}if(K.main==K.module)m().catch(console.error);export{m as main};
5
+ Hint: Did you mean:`),L.showHelp(),process.exit(1)}).command("$0",!1,()=>{},async(J)=>{let Z=J._.slice(1),L=Z.length>0?Z.join(" "):void 0,h=import("./chunk-j1sd03h7.js").then(({checkVersionOnStartup:j})=>j()),[{render:A},{createElement:w},{AppWrapper:f}]=await Promise.all([import("ink"),import("react"),import("./chunk-710bvht9.js")]),H={...J,initialMessage:L,debug:J.debug,print:Boolean(J.print),versionCheckPromise:h};delete H._,delete H.$0,delete H.message,A(w(f,H),{patchConsole:!0,exitOnCtrlC:!1,alternateBuffer:!1})});try{await x.parse()}catch(J){console.error("Error: Parse error:",J),process.exit(1)}}if(K.main==K.module)m().catch(console.error);export{m as main};
@@ -1,4 +1,4 @@
1
- import{ce as rn,de as D,ee as m,je as Zn,ke as Jn}from"./chunk-tq52pbde.js";import{le as pn,me as Nn}from"./chunk-79s052sw.js";import{re as b}from"./chunk-epj56s0n.js";import{te as Dn,we as H}from"./chunk-gxzbv67r.js";import{Ee as fn,Fe as En}from"./chunk-1vx4sf1y.js";import{Je as P}from"./chunk-z906d5tb.js";import{Te as un}from"./chunk-0n97186m.js";var Qn=/^[\x21\x23-\x5b\x5d-\x7e]+$/;function Wn(n){return n==="127.0.0.1"||n==="[::1]"||n.toLowerCase()==="localhost"}function I(n,t="MCP OAuth URL"){let e=new URL(n);if(e.username||e.password)throw Error(`${t} must not contain credentials`);if(e.protocol!=="https:"&&!(e.protocol==="http:"&&Wn(e.hostname)))throw Error(`${t} requires HTTPS; HTTP is allowed only for loopback servers`);return e}var B=async(n,t)=>{I(n,"MCP OAuth request URL");let e=await fetch(n,{...t,redirect:"manual"});if(e.status>=300&&e.status<400)throw await e.body?.cancel(),Error("MCP OAuth network requests must not follow redirects");return e};function q(n){let t=n.oauth;if(!t)return;let e=t;for(let _ of["clientSecret","authorizationUrl","tokenUrl","redirectUri"])if(e[_]!==void 0)throw Error(`MCP OAuth "${_}" is not supported; use standards-based discovery`);if(t.enabled!==!0)return{enabled:!1};if(n.type!=="http"&&n.type!=="sse")throw Error("MCP OAuth is supported only for HTTP and SSE transports");if(!n.url)throw Error("MCP OAuth requires an MCP server URL");if(I(n.url,"MCP OAuth server URL"),Object.keys(n.headers??{}).find((_)=>_.toLowerCase()==="authorization"))throw Error("MCP OAuth cannot be combined with a configured Authorization header");let u=t.clientId?.trim();if(u&&u.length>4096)throw Error("MCP OAuth clientId exceeds 4096 characters");let M=t.scopes?.map((_)=>_.trim());if(M){if(M.length>32)throw Error("MCP OAuth supports at most 32 scopes");if(M.some((_)=>!_||_.length>128||!Qn.test(_)))throw Error("MCP OAuth scopes contain an invalid value");if(new Set(M).size!==M.length)throw Error("MCP OAuth scopes must not contain duplicates")}let o=t.callbackPort;if(o!==void 0&&(!Number.isInteger(o)||o<1024||o>65535))throw Error("MCP OAuth callbackPort must be between 1024 and 65535");return{enabled:!0,...u?{clientId:u}:{},...M?.length?{scopes:M}:{},...o!==void 0?{callbackPort:o}:{}}}import{randomUUID as J}from"node:crypto";import st from"node:http";import{auth as _n}from"@modelcontextprotocol/sdk/client/auth.js";import St from"open";import{createHash as jn,randomUUID as Fn}from"node:crypto";import{constants as O,promises as A}from"node:fs";import Y from"node:path";import{Mutex as vn}from"async-mutex";import nt from"write-file-atomic";var Mn=1,tt=1048576,et=5000,ut=50,rt=/^[a-f0-9]{64}$/,Mt=m.Object({client_id:m.String({minLength:1,maxLength:4096})},{additionalProperties:!0}),ot=m.Object({access_token:m.String({minLength:1,maxLength:65536}),token_type:m.String({minLength:1,maxLength:64}),expires_in:m.Optional(m.Number({minimum:0})),refresh_token:m.Optional(m.String({minLength:1,maxLength:65536})),scope:m.Optional(m.String({maxLength:16384})),id_token:m.Optional(m.String({minLength:1,maxLength:262144}))},{additionalProperties:!1}),_t=m.Unsafe({type:"object",properties:{authorizationServerUrl:m.String({format:"uri"}),resourceMetadataUrl:m.Optional(m.String({format:"uri"})),resourceMetadata:m.Optional(m.Unknown()),authorizationServerMetadata:m.Optional(m.Unknown())},required:["authorizationServerUrl"],additionalProperties:!1}),on=m.Object({serverUrl:m.String({format:"uri"}),clientId:m.Optional(m.String({minLength:1,maxLength:4096})),clientInformation:m.Optional(Mt),tokens:m.Optional(ot),tokenExpiresAt:m.Optional(m.Number({minimum:0})),discoveryState:m.Optional(_t),updatedAt:m.String({format:"date-time"})},{additionalProperties:!1}),tn=m.Object({version:m.Literal(Mn),credentials:m.Record(m.String(),on)},{additionalProperties:!1});function l(n,t){return n instanceof Error&&"code"in n&&n.code===t}function it(n){if(!Number.isInteger(n)||n<=0)return!1;try{return process.kill(n,0),!0}catch(t){return l(t,"EPERM")}}function V(n){return structuredClone(n)}function en(n){if(Object.keys(n.credentials).some((t)=>!rt.test(t)))throw Error("MCP OAuth credential store contains an invalid identity")}function y(n){let t=new URL(n);return t.hash="",t.toString()}function Z(n,t,e=[]){return jn("sha256").update(JSON.stringify({serverUrl:y(n),clientId:t?.trim()||null,scopes:[...e].sort()})).digest("hex")}class x{static mutexes=new Map;stateRoot;tokenFilePath;mutex;constructor(n=un()){this.stateRoot=Y.join(n,"mcp"),this.tokenFilePath=Y.join(this.stateRoot,"oauth-credentials.json");let t=x.mutexes.get(this.tokenFilePath);if(!t)t=new vn,x.mutexes.set(this.tokenFilePath,t);this.mutex=t}async getCredential(n){return this.mutex.runExclusive(async()=>{let e=(await this.readStore()).credentials[n];return e?V(e):null})}async updateCredential(n,t){return this.runMutation(async(e)=>{let r=e.credentials[n],u=await t(r?V(r):null);if(u)e.credentials[n]=D(on,u);else delete e.credentials[n];return u?V(e.credentials[n]):null})}async deleteCredential(n){await this.updateCredential(n,()=>null)}async listCredentialIds(){return this.mutex.runExclusive(async()=>Object.keys((await this.readStore()).credentials).sort())}async runMutation(n){return this.mutex.runExclusive(async()=>{let t=await this.acquireStoreLock();try{let e=await this.readStore(),r=await n(e);return await this.writeStore(e),r}finally{await t()}})}async ensureStateRoot(){await A.mkdir(this.stateRoot,{recursive:!0,mode:448});let n=await A.lstat(this.stateRoot);if(!n.isDirectory()||n.isSymbolicLink())throw Error("MCP OAuth credential root must be a regular directory");if(process.getuid&&n.uid!==process.getuid())throw Error("MCP OAuth credential root must be owned by the current user");if((n.mode&63)!==0)throw Error("MCP OAuth credential root permissions must not allow group access")}async readStore(){try{let n=await A.lstat(this.tokenFilePath);if(!n.isFile()||n.isSymbolicLink())throw Error("MCP OAuth credential store must be a regular file");if(process.getuid&&n.uid!==process.getuid())throw Error("MCP OAuth credential store must be owned by the current user");if((n.mode&511)!==384)throw Error("MCP OAuth credential store permissions must be 0600");if(n.size>tt)throw Error("MCP OAuth credential store exceeds the 1 MiB limit");let t=JSON.parse(await A.readFile(this.tokenFilePath,"utf8")),e=rn(tn,t);if(!e.success)throw Error("MCP OAuth credential store has an invalid schema");return en(e.data),e.data}catch(n){if(l(n,"ENOENT"))return{version:Mn,credentials:{}};throw n}}async writeStore(n){await this.ensureStateRoot();let t=D(tn,n);en(t),await nt(this.tokenFilePath,`${JSON.stringify(t,null,2)}
1
+ import{he as rn,ie as D,je as m,oe as Zn,pe as Jn}from"./chunk-xkp4ph6v.js";import{qe as pn,re as Nn}from"./chunk-1kg9r8xp.js";import{we as b}from"./chunk-c9tzf9r5.js";import{Be as H,ye as Dn}from"./chunk-n9khyme2.js";import{Je as fn,Ke as En}from"./chunk-nfmsn652.js";import{Oe as P}from"./chunk-kcs3xa8f.js";import{Ye as un}from"./chunk-frcg8gea.js";var Qn=/^[\x21\x23-\x5b\x5d-\x7e]+$/;function Wn(n){return n==="127.0.0.1"||n==="[::1]"||n.toLowerCase()==="localhost"}function I(n,t="MCP OAuth URL"){let e=new URL(n);if(e.username||e.password)throw Error(`${t} must not contain credentials`);if(e.protocol!=="https:"&&!(e.protocol==="http:"&&Wn(e.hostname)))throw Error(`${t} requires HTTPS; HTTP is allowed only for loopback servers`);return e}var B=async(n,t)=>{I(n,"MCP OAuth request URL");let e=await fetch(n,{...t,redirect:"manual"});if(e.status>=300&&e.status<400)throw await e.body?.cancel(),Error("MCP OAuth network requests must not follow redirects");return e};function q(n){let t=n.oauth;if(!t)return;let e=t;for(let _ of["clientSecret","authorizationUrl","tokenUrl","redirectUri"])if(e[_]!==void 0)throw Error(`MCP OAuth "${_}" is not supported; use standards-based discovery`);if(t.enabled!==!0)return{enabled:!1};if(n.type!=="http"&&n.type!=="sse")throw Error("MCP OAuth is supported only for HTTP and SSE transports");if(!n.url)throw Error("MCP OAuth requires an MCP server URL");if(I(n.url,"MCP OAuth server URL"),Object.keys(n.headers??{}).find((_)=>_.toLowerCase()==="authorization"))throw Error("MCP OAuth cannot be combined with a configured Authorization header");let u=t.clientId?.trim();if(u&&u.length>4096)throw Error("MCP OAuth clientId exceeds 4096 characters");let M=t.scopes?.map((_)=>_.trim());if(M){if(M.length>32)throw Error("MCP OAuth supports at most 32 scopes");if(M.some((_)=>!_||_.length>128||!Qn.test(_)))throw Error("MCP OAuth scopes contain an invalid value");if(new Set(M).size!==M.length)throw Error("MCP OAuth scopes must not contain duplicates")}let o=t.callbackPort;if(o!==void 0&&(!Number.isInteger(o)||o<1024||o>65535))throw Error("MCP OAuth callbackPort must be between 1024 and 65535");return{enabled:!0,...u?{clientId:u}:{},...M?.length?{scopes:M}:{},...o!==void 0?{callbackPort:o}:{}}}import{randomUUID as J}from"node:crypto";import st from"node:http";import{auth as _n}from"@modelcontextprotocol/sdk/client/auth.js";import St from"open";import{createHash as jn,randomUUID as Fn}from"node:crypto";import{constants as O,promises as A}from"node:fs";import Y from"node:path";import{Mutex as vn}from"async-mutex";import nt from"write-file-atomic";var Mn=1,tt=1048576,et=5000,ut=50,rt=/^[a-f0-9]{64}$/,Mt=m.Object({client_id:m.String({minLength:1,maxLength:4096})},{additionalProperties:!0}),ot=m.Object({access_token:m.String({minLength:1,maxLength:65536}),token_type:m.String({minLength:1,maxLength:64}),expires_in:m.Optional(m.Number({minimum:0})),refresh_token:m.Optional(m.String({minLength:1,maxLength:65536})),scope:m.Optional(m.String({maxLength:16384})),id_token:m.Optional(m.String({minLength:1,maxLength:262144}))},{additionalProperties:!1}),_t=m.Unsafe({type:"object",properties:{authorizationServerUrl:m.String({format:"uri"}),resourceMetadataUrl:m.Optional(m.String({format:"uri"})),resourceMetadata:m.Optional(m.Unknown()),authorizationServerMetadata:m.Optional(m.Unknown())},required:["authorizationServerUrl"],additionalProperties:!1}),on=m.Object({serverUrl:m.String({format:"uri"}),clientId:m.Optional(m.String({minLength:1,maxLength:4096})),clientInformation:m.Optional(Mt),tokens:m.Optional(ot),tokenExpiresAt:m.Optional(m.Number({minimum:0})),discoveryState:m.Optional(_t),updatedAt:m.String({format:"date-time"})},{additionalProperties:!1}),tn=m.Object({version:m.Literal(Mn),credentials:m.Record(m.String(),on)},{additionalProperties:!1});function l(n,t){return n instanceof Error&&"code"in n&&n.code===t}function it(n){if(!Number.isInteger(n)||n<=0)return!1;try{return process.kill(n,0),!0}catch(t){return l(t,"EPERM")}}function V(n){return structuredClone(n)}function en(n){if(Object.keys(n.credentials).some((t)=>!rt.test(t)))throw Error("MCP OAuth credential store contains an invalid identity")}function y(n){let t=new URL(n);return t.hash="",t.toString()}function Z(n,t,e=[]){return jn("sha256").update(JSON.stringify({serverUrl:y(n),clientId:t?.trim()||null,scopes:[...e].sort()})).digest("hex")}class x{static mutexes=new Map;stateRoot;tokenFilePath;mutex;constructor(n=un()){this.stateRoot=Y.join(n,"mcp"),this.tokenFilePath=Y.join(this.stateRoot,"oauth-credentials.json");let t=x.mutexes.get(this.tokenFilePath);if(!t)t=new vn,x.mutexes.set(this.tokenFilePath,t);this.mutex=t}async getCredential(n){return this.mutex.runExclusive(async()=>{let e=(await this.readStore()).credentials[n];return e?V(e):null})}async updateCredential(n,t){return this.runMutation(async(e)=>{let r=e.credentials[n],u=await t(r?V(r):null);if(u)e.credentials[n]=D(on,u);else delete e.credentials[n];return u?V(e.credentials[n]):null})}async deleteCredential(n){await this.updateCredential(n,()=>null)}async listCredentialIds(){return this.mutex.runExclusive(async()=>Object.keys((await this.readStore()).credentials).sort())}async runMutation(n){return this.mutex.runExclusive(async()=>{let t=await this.acquireStoreLock();try{let e=await this.readStore(),r=await n(e);return await this.writeStore(e),r}finally{await t()}})}async ensureStateRoot(){await A.mkdir(this.stateRoot,{recursive:!0,mode:448});let n=await A.lstat(this.stateRoot);if(!n.isDirectory()||n.isSymbolicLink())throw Error("MCP OAuth credential root must be a regular directory");if(process.getuid&&n.uid!==process.getuid())throw Error("MCP OAuth credential root must be owned by the current user");if((n.mode&63)!==0)throw Error("MCP OAuth credential root permissions must not allow group access")}async readStore(){try{let n=await A.lstat(this.tokenFilePath);if(!n.isFile()||n.isSymbolicLink())throw Error("MCP OAuth credential store must be a regular file");if(process.getuid&&n.uid!==process.getuid())throw Error("MCP OAuth credential store must be owned by the current user");if((n.mode&511)!==384)throw Error("MCP OAuth credential store permissions must be 0600");if(n.size>tt)throw Error("MCP OAuth credential store exceeds the 1 MiB limit");let t=JSON.parse(await A.readFile(this.tokenFilePath,"utf8")),e=rn(tn,t);if(!e.success)throw Error("MCP OAuth credential store has an invalid schema");return en(e.data),e.data}catch(n){if(l(n,"ENOENT"))return{version:Mn,credentials:{}};throw n}}async writeStore(n){await this.ensureStateRoot();let t=D(tn,n);en(t),await nt(this.tokenFilePath,`${JSON.stringify(t,null,2)}
2
2
  `,{mode:384,encoding:"utf8"}),await A.chmod(this.tokenFilePath,384)}async acquireStoreLock(){await this.ensureStateRoot();let n=Y.join(this.stateRoot,".oauth-credentials.lock"),t=Fn(),e=Date.now()+et;while(Date.now()<e)try{let r=await A.open(n,O.O_CREAT|O.O_EXCL|O.O_WRONLY,384);return await r.writeFile(`${JSON.stringify({version:1,pid:process.pid,token:t,createdAt:new Date().toISOString()})}
3
3
  `,"utf8"),await r.close(),async()=>{try{if(JSON.parse(await A.readFile(n,"utf8")).token===t)await A.unlink(n)}catch(u){if(!l(u,"ENOENT"))throw u}}}catch(r){if(!l(r,"EEXIST"))throw r;await this.removeDeadLock(n),await new Promise((u)=>setTimeout(u,ut))}throw Error("MCP OAuth credential store is busy; retry the operation")}async removeDeadLock(n){let t=await A.lstat(n);if(!t.isFile()||t.isSymbolicLink())throw Error("MCP OAuth credential lock must be a regular file");if(process.getuid&&t.uid!==process.getuid()||(t.mode&511)!==384)throw Error("MCP OAuth credential lock ownership or permissions are invalid");let e=JSON.parse(await A.readFile(n,"utf8"));if(typeof e.pid!=="number"||!Number.isInteger(e.pid)||e.pid<=0)throw Error("MCP OAuth credential lock owner is invalid");if(!it(e.pid))await A.unlink(n)}}var sn="127.0.0.1",Sn=7777,mn="/oauth/callback",mt=300000;class Q extends Error{constructor(n){super(`MCP server "${n}" requires OAuth authorization; run "blade mcp login ${n}" or use the Web MCP panel`);this.name="McpOAuthAuthorizationRequiredError"}}class cn extends Error{constructor(n){super(`MCP OAuth credentials are unavailable in this runtime for server "${n}"`);this.name="McpOAuthUnavailableError"}}function ft(n){let t=n?"Authentication complete":"Authentication failed";return`<!doctype html>
4
4
  <html lang="en">
@@ -41,4 +41,4 @@ ${e.map((r)=>` - ${r}`).join(`
41
41
  ]
42
42
  }
43
43
  `)}}function Mu(n,t={}){let e={...n};if(t.debug!==void 0)e.debug=t.debug===""?!0:t.debug;if(t.model){if(!n.models.some((u)=>u.id===t.model))throw Error(`模型配置未找到: ${t.model}`);e.currentModelId=t.model}if(t.yolo===!0)e.permissionMode="yolo";else if(t.permissionMode!==void 0)e.permissionMode=t.permissionMode;if(t.maxTurns!==void 0)e.maxTurns=t.maxTurns;if(t.maxConcurrentTasks!==void 0)e.maxConcurrentTasks=t.maxConcurrentTasks;if(t.maxQueuedTasks!==void 0)e.maxQueuedTasks=t.maxQueuedTasks;return e.systemPrompt=t.systemPrompt,e.appendSystemPrompt=t.appendSystemPrompt,e.model=t.model,e.resumeSessionId=t.sessionId,e.forkSession=t.forkSession,e.allowedTools=t.allowedTools,e.disallowedTools=t.disallowedTools,e.mcpConfigPaths=t.mcpConfig,e.strictMcpConfig=t.strictMcpConfig,e.addDirs=t.addDir,e.outputFormat=t.outputFormat,e.inputFormat=t.inputFormat,e.print=t.print,e.includePartialMessages=t.includePartialMessages,e.replayUserMessages=t.replayUserMessages,e.agentsConfig=t.agents,e.settingSources=t.settingSources,e}
44
- export{B as pd,q as qd,x as rd,Q as sd,cn as td,L as ud,Tn as vd,se as wd,K as xd,fe as yd,Ee as zd,ce as Ad,wn as Bd,dt as Cd,ae as Dd,xt as Ed,Te as Fd,Rn as Gd,be as Hd,Pe as Id,de as Jd,xe as Kd,Le as Ld,ln as Md,he as Nd,Ce as Od,$e as Pd,Ie as Qd,f as Rd,w as Sd,N as Td,G as Ud,zn as Vd,Gn as Wd,Hn as Xd,qn as Yd,On as Zd,Yn as _d,C as $d,Mu as ae};
44
+ export{B as ud,q as vd,x as wd,Q as xd,cn as yd,L as zd,Tn as Ad,se as Bd,K as Cd,fe as Dd,Ee as Ed,ce as Fd,wn as Gd,dt as Hd,ae as Id,xt as Jd,Te as Kd,Rn as Ld,be as Md,Pe as Nd,de as Od,xe as Pd,Le as Qd,ln as Rd,he as Sd,Ce as Td,$e as Ud,Ie as Vd,f as Wd,w as Xd,N as Yd,G as Zd,zn as _d,Gn as $d,Hn as ae,qn as be,On as ce,Yn as de,C as ee,Mu as fe};
@@ -0,0 +1 @@
1
+ import{Hc as a,Ic as b,Jc as c}from"./chunk-hjsm6ejs.js";import"./chunk-b4n34hrn.js";import"./chunk-n9khyme2.js";import"./chunk-7xm3vjkz.js";import"./chunk-frcg8gea.js";import"./chunk-c2rhwxyn.js";export{b as resolveModelConfig,c as getModelDisplayName,a as getModelApiKeyEnvironmentVariable};
@@ -0,0 +1 @@
1
+ import{Ob as a,Pb as b}from"./chunk-n5m2p0bq.js";import"./chunk-nfmsn652.js";import"./chunk-c2rhwxyn.js";export{a as globalOptions,b as cliConfig};