@fastagent/cli 0.2.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +13 -0
- package/cli.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -103,6 +103,19 @@ export FASTAGENT_BASE_URL=https://api.openai.com/v1
|
|
|
103
103
|
export FASTAGENT_USER_AGENT=your-app-name
|
|
104
104
|
```
|
|
105
105
|
|
|
106
|
+
`FASTAGENT_API_TYPE` 当前支持这些值:
|
|
107
|
+
|
|
108
|
+
- `anthropic-messages`
|
|
109
|
+
- `openai-completions`
|
|
110
|
+
- `openai-responses`
|
|
111
|
+
- `google-generative-ai`
|
|
112
|
+
|
|
113
|
+
如果不显式设置,会按 `FASTAGENT_PROVIDER` 推断:
|
|
114
|
+
|
|
115
|
+
- `anthropic` -> `anthropic-messages`
|
|
116
|
+
- `google` / `gemini` / `google-ai-studio` -> `google-generative-ai`
|
|
117
|
+
- 其他 provider 默认回落到 `openai-completions`
|
|
118
|
+
|
|
106
119
|
### 启动微信服务
|
|
107
120
|
|
|
108
121
|
```bash
|
package/cli.js
CHANGED
|
@@ -622,7 +622,7 @@ Options:
|
|
|
622
622
|
`;class x4 extends Error{constructor($){super($);this.name="CliParseError"}}var oM$=new Set(["--channel","--output","--sandbox","--sandbox-url","--workspace-id","--workspace","--provider","--model","--api-type","--base-url","--user-agent","--api-key","--max-turns","--auto-compaction","--compaction-threshold"]);function ML($){let J=$[0]==="--"?$.slice(1):$;if(J.length===0)return{kind:"public-root",help:!1,output:"text",version:!1,sandbox:{mode:"disabled"}};let[X,...Q]=J;if(X==="help")return{kind:"public-root",help:!0,output:"text",version:!1,sandbox:{mode:"disabled"}};if(X==="config")return ap("public-config",Q);if(X==="doctor")return ap("public-doctor",Q);if(X==="skills")return aM$(Q);if(X==="internal")return $L$(Q);return eM$(J)}function ap($,J){if(J.length===0)return{kind:$,help:!1};if(J.length===1&&SJ(J[0]))return{kind:$,help:!0};throw new x4(`unexpected arguments for '${$==="public-config"?"config":"doctor"}'`)}function aM$($){if($.length===0||$.length===1&&($[0]==="help"||SJ($[0])))return{kind:"public-skills-root",help:!0};let[J,...X]=$;if(J==="add")return sM$(X);if(J==="list")return tM$(X);throw new x4(`unknown skills command: ${J}`)}function sM$($){let J=!1,X,Q,Y="user",G=!1,H=!1;for(let W=0;W<$.length;W+=1){let V=$[W];if(SJ(V)){J=!0;continue}if(V==="--list"){G=!0;continue}if(V==="--full-depth"){H=!0;continue}let K=x0($,W,"--skill");if(K){Q=K.value,W=K.nextIndex;continue}let Z=x0($,W,"--scope");if(Z){Y=tp(Z.value),W=Z.nextIndex;continue}if(V.startsWith("-"))throw new x4(`unexpected argument: ${V}`);if(X)throw new x4(`unexpected argument: ${V}`);X=V}if(!J&&!X)throw new x4("skills add requires a source argument");return{kind:"public-skills-add",help:J,source:X,skill:Q,scope:Y,listOnly:G,fullDepth:H}}function tM$($){let J=!1,X="all";for(let Q=0;Q<$.length;Q+=1){let Y=$[Q];if(SJ(Y)){J=!0;continue}let G=x0($,Q,"--scope");if(G){X=tp(G.value),Q=G.nextIndex;continue}throw new x4(`unexpected argument: ${Y}`)}return{kind:"public-skills-list",help:J,scope:X}}function eM$($){let J=LL($,{allowOutput:!0,allowVersion:!0,requireChannel:!1});if(J.channel)return{kind:"public-im-start",help:J.help,channel:J.channel,output:J.output,sandbox:J.sandbox};return{kind:"public-root",help:J.help,output:J.output,version:J.version,sandbox:J.sandbox}}function $L$($){if($.length===0||$.length===1&&($[0]==="help"||SJ($[0])))return{kind:"internal-root",help:!0};let[J,...X]=$;if(J==="acp")return JL$(X);if(J==="im")return XL$(X);throw new x4(`unknown internal command: ${J}`)}function JL$($){let[J,...X]=$;if(J!=="start")throw new x4("internal acp only supports the start subcommand");let Q=LL(X,{allowOutput:!1,allowVersion:!1,requireChannel:!1});return{kind:"internal-acp-start",help:Q.help,sandbox:Q.sandbox,options:Q.acpOptions}}function XL$($){let[J,...X]=$;if(J!=="start")throw new x4("internal im only supports the start subcommand");let Q=LL(X,{allowOutput:!0,allowVersion:!1,requireChannel:!0});if(Q.help)return{kind:"internal-im-start",help:!0,channel:Q.channel,output:Q.output,sandbox:Q.sandbox};return{kind:"internal-im-start",help:!1,channel:WL$(Q.channel),output:Q.output,sandbox:Q.sandbox}}function LL($,J){let X=!1,Q=!1,Y,G="text",H="disabled",W,V={};for(let K=0;K<$.length;K+=1){let Z=$[K];if(SJ(Z)){X=!0;continue}if(ep(Z)){if(!J.allowVersion)throw new x4(`unexpected argument: ${Z}`);Q=!0;continue}let U=x0($,K,"--channel");if(U){Y=U.value,K=U.nextIndex;continue}let N=x0($,K,"--output");if(N){if(!J.allowOutput)throw new x4("unexpected argument: --output");let h=N.value;if(h!=="text"&&h!=="jsonl")throw new x4(`invalid value for '--output': ${h}`);G=h,K=N.nextIndex;continue}let z=x0($,K,"--sandbox");if(z){let h=z.value;if(h!=="local"&&h!=="remote")throw new x4(`invalid value for '--sandbox': ${h}`);H=h,K=z.nextIndex;continue}let D=x0($,K,"--sandbox-url");if(D){W=D.value,K=D.nextIndex;continue}let w=x0($,K,"--workspace-id");if(w){V.workspaceId=w.value,K=w.nextIndex;continue}let A=x0($,K,"--workspace");if(A){V.workspacePath=A.value,K=A.nextIndex;continue}let L=x0($,K,"--provider");if(L){V.provider=L.value,K=L.nextIndex;continue}let j=x0($,K,"--model");if(j){V.model=j.value,K=j.nextIndex;continue}let R=x0($,K,"--api-type");if(R){V.apiType=GL$(R.value,"--api-type"),K=R.nextIndex;continue}let _=x0($,K,"--base-url");if(_){V.baseUrl=_.value,K=_.nextIndex;continue}let E=x0($,K,"--user-agent");if(E){V.userAgent=E.value,K=E.nextIndex;continue}let C=x0($,K,"--api-key");if(C){V.apiKey=C.value,K=C.nextIndex;continue}let k=x0($,K,"--max-turns");if(k){V.maxTurns=sp(k.value,"--max-turns"),K=k.nextIndex;continue}let I=x0($,K,"--auto-compaction");if(I){V.autoCompaction=YL$(I.value,"--auto-compaction"),K=I.nextIndex;continue}let b=x0($,K,"--compaction-threshold");if(b){V.compactionThreshold=sp(b.value,"--compaction-threshold"),K=b.nextIndex;continue}throw new x4(`unexpected argument: ${Z}`)}if(J.requireChannel&&!X&&!Y)throw new x4("'--channel' is required");if(H==="remote"){if(!W)throw new x4("'--sandbox-url' is required when '--sandbox remote' is set");return{help:X,version:Q,channel:Y,output:G,sandbox:{mode:"remote",url:W},acpOptions:V}}if(W)throw new x4("'--sandbox-url' requires '--sandbox remote'");if(H==="local")return{help:X,version:Q,channel:Y,output:G,sandbox:{mode:"local"},acpOptions:V};return{help:X,version:Q,channel:Y,output:G,sandbox:{mode:"disabled"},acpOptions:V}}function QL$($,J,X){let Q=$[J+1];if(!Q||HL$(Q))throw new x4(`missing value for '${X}'`);return Q}function x0($,J,X){let Q=$[J];if(Q===X)return{value:QL$($,J,X),nextIndex:J+1};let Y=`${X}=`;if(!Q.startsWith(Y))return;let G=Q.slice(Y.length);if(!G)throw new x4(`missing value for '${X}'`);return{value:G,nextIndex:J}}function sp($,J){let X=Number($);if(!Number.isInteger(X)||X<=0)throw new x4(`invalid value for '${J}': ${$}`);return X}function YL$($,J){let X=$.trim().toLowerCase();if(X==="true"||X==="1")return!0;if(X==="false"||X==="0")return!1;throw new x4(`invalid value for '${J}': ${$}`)}function tp($){if($==="project"||$==="user")return $;throw new x4(`invalid value for '--scope': ${$}`)}function GL$($,J){if($==="anthropic-messages"||$==="openai-completions"||$==="openai-responses"||$==="google-generative-ai")return $;throw new x4(`invalid value for '${J}': ${$}`)}function SJ($){return $==="--help"||$==="-h"}function ep($){return $==="--version"||$==="-V"}function HL$($){if(SJ($)||ep($))return!0;return oM$.has($)}function WL$($){if(!$)throw new x4("'--channel' is required");return $}async function gB($,J){let X=J.getEnv();if($.mode==="disabled")return PL(X);if($.mode==="remote")return PL({...X,SANDBOX_URL:$.url});let Q=await J.startLocalSandboxSupervisor(X);return PL({...X,...Q.runtimeEnv},async()=>{await Q.stop()})}function PL($,J=async()=>{}){let X=!1;return{env:$,dispose:async()=>{if(X)return;X=!0,await J()}}}async function $i($,J){if($.help)return J.writeStdout(gp),0;let X=await gB($.sandbox,J.dependencies);J.registerShutdownHook(async()=>{await X.dispose()});try{let Q={...$.options,env:X.env},Y=await J.dependencies.startAcpServer(Q);J.registerShutdownHook(async()=>{await Y.dispose()}),await Y.closed}finally{await X.dispose()}return 0}function Ji($,J){$(`${JSON.stringify(J)}
|
|
623
623
|
`)}function Xi($){return(J)=>{if($.mode==="jsonl"){Ji($.writeStdout,VL$(J,$));return}let X=KL$(J);if(X)$.writeStdout(X)}}function VL$($,J){let X={type:$.type,timestamp:(J.now??UL$)().toISOString(),pid:J.pid??process.pid,message:ZL$($),data:$.data};if(J.agentId)X.agentId=J.agentId;return X}function KL$($){switch($.type){case"qr_code":return`Weixin QR Code: ${$.data.qrCodeUrl}
|
|
624
624
|
`;default:return null}}function ZL$($){switch($.type){case"process_started":return"IM runtime process started";case"qr_code":return"Weixin QR code ready";case"login_confirmed":return"Weixin login confirmed";case"running":return"IM runtime entered steady state";case"account_invalid":return"Weixin account invalidated";case"runtime_error":return"IM runtime failed";case"stopping":return"IM runtime stopping";case"stopped":return"IM runtime stopped";default:return BL$($)}}function UL$(){return new Date}function BL$($){throw Error(`Unhandled IM runtime event: ${JSON.stringify($)}`)}async function mB($,J){let X=J.dependencies.getEnv(),Q=Xi({agentId:X.IM_GATEWAY_AGENT_ID,mode:$.output,writeStdout:J.writeStdout}),Y=0,G,H,W="completed",V=!1,K=!1,Z=async(z)=>{if(K)return;if(K=!0,W=z,!G)return;Q({type:"stopping",data:{reason:z}}),await G.stop()},U=(z)=>{if(Y=1,W="runtime_error",V)return;V=!0;let D=qL$(z);if(Q({type:"runtime_error",data:{error:D}}),$.output==="text")J.writeStderr(`error: ${D}
|
|
625
|
-
`)},N=async(z)=>{try{await Z(z)}catch(D){if(Y===0)U(D)}};try{H=await gB($.sandbox,J.dependencies),J.registerShutdownHook(async()=>{await H?.dispose()}),Q({type:"process_started",data:{channel:$.channel}}),G=await J.dependencies.startImGateway({channel:$.channel,env:H.env,onAccountInvalid:(z)=>{Q({type:"account_invalid",data:z})},onLoginConfirmed:(z)=>{Q({type:"login_confirmed",data:z})},onQrCode:(z)=>{Q({type:"qr_code",data:{qrCodeUrl:z.qrCodeUrl}})},onRunning:(z)=>{Q({type:"running",data:z})}}),J.registerShutdownHook(async()=>{await N("signal")}),await G.running}catch(z){U(z),await N("runtime_error")}finally{if(Y===0)await N(W);if(H)try{await H.dispose()}catch(z){if(Y===0)U(z)}}return Q({type:"stopped",data:{exitCode:Y,reason:W}}),Y}function qL$($){if($ instanceof Error)return $.message;return String($)}async function Qi($,J){if($.help)return J.writeStdout(mp),0;return mB($,J)}async function Yi($,J){if($.help)return J.writeStdout(lp),0;return J.writeStdout(rp),0}async function Gi($,J){if($.help)return J.writeStdout(hB),0;return mB($,J)}async function Hi($,J){if($.help)return J.writeStdout(dp),0;return J.writeStdout(op),0}import{readFileSync as FL$}from"node:fs";function NL$($){let J=$.buildVersion??$.readPackageVersion();if(typeof J!=="string"||J.trim().length===0)throw Error("CLI version is missing or invalid");return J}function Wi(){return NL$({buildVersion:zL$(),readPackageVersion:OL$})}function zL$(){return"0.2.
|
|
625
|
+
`)},N=async(z)=>{try{await Z(z)}catch(D){if(Y===0)U(D)}};try{H=await gB($.sandbox,J.dependencies),J.registerShutdownHook(async()=>{await H?.dispose()}),Q({type:"process_started",data:{channel:$.channel}}),G=await J.dependencies.startImGateway({channel:$.channel,env:H.env,onAccountInvalid:(z)=>{Q({type:"account_invalid",data:z})},onLoginConfirmed:(z)=>{Q({type:"login_confirmed",data:z})},onQrCode:(z)=>{Q({type:"qr_code",data:{qrCodeUrl:z.qrCodeUrl}})},onRunning:(z)=>{Q({type:"running",data:z})}}),J.registerShutdownHook(async()=>{await N("signal")}),await G.running}catch(z){U(z),await N("runtime_error")}finally{if(Y===0)await N(W);if(H)try{await H.dispose()}catch(z){if(Y===0)U(z)}}return Q({type:"stopped",data:{exitCode:Y,reason:W}}),Y}function qL$($){if($ instanceof Error)return $.message;return String($)}async function Qi($,J){if($.help)return J.writeStdout(mp),0;return mB($,J)}async function Yi($,J){if($.help)return J.writeStdout(lp),0;return J.writeStdout(rp),0}async function Gi($,J){if($.help)return J.writeStdout(hB),0;return mB($,J)}async function Hi($,J){if($.help)return J.writeStdout(dp),0;return J.writeStdout(op),0}import{readFileSync as FL$}from"node:fs";function NL$($){let J=$.buildVersion??$.readPackageVersion();if(typeof J!=="string"||J.trim().length===0)throw Error("CLI version is missing or invalid");return J}function Wi(){return NL$({buildVersion:zL$(),readPackageVersion:OL$})}function zL$(){return"0.2.1"}function OL$(){let $=JSON.parse(FL$(new URL("../package.json",import.meta.url),"utf8"));return typeof $.version==="string"?$.version:""}async function Vi($,J){if($.version)return J.writeStdout(`${Wi()}
|
|
626
626
|
`),0;if($.sandbox.mode!=="disabled")return J.writeStderr(up),1;if($.output!=="text")return J.writeStderr(cp),1;return J.writeStdout(hB),0}L3();async function VJ$($,J){if($.kind==="public-skills-root")return J.writeStdout(pp),0;if($.kind==="public-skills-list"){if($.help)return J.writeStdout(np),0;try{let X=process.cwd();if($.scope==="all"){let[Y,G]=await Promise.all([dW({scope:"project",workspaceDir:X,globalDataDir:void 0}),dW({scope:"user",workspaceDir:X,globalDataDir:void 0})]);return J.writeStdout(K94(Y,G)),0}let Q=await dW({scope:$.scope,workspaceDir:X,globalDataDir:void 0});return J.writeStdout(V94(Q)),0}catch(X){return J.writeStderr(`${WJ$(X)}
|
|
627
627
|
`),1}}if($.help)return J.writeStdout(ip),0;if(!$.source)return J.writeStderr(`skills add requires a source argument
|
|
628
628
|
`),1;try{let X=process.cwd(),Q=await cW({source:$.source,workspaceDir:X,fullDepth:$.fullDepth});if($.listOnly)return J.writeStdout(HJ$(Q)),0;if(!$.skill&&Q.length>1)return J.writeStdout(HJ$(Q)),J.writeStderr(`multiple skills found; re-run with --skill <NAME>
|