best-geo-test 0.3.2 → 0.3.4

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.
@@ -3168,6 +3168,37 @@
3168
3168
  "additionalProperties": false
3169
3169
  }
3170
3170
  },
3171
+ {
3172
+ "name": "prompts.duplicate",
3173
+ "mode": "write",
3174
+ "guide": "article",
3175
+ "requiresPlan": true,
3176
+ "description": "把一条提示词复制到一家或多家公司,每家得到一份独立副本。**系统内置的公共模板要改,就先用这条复制一份**——公共模板本身改不了。副本和原来同名,要区分就复制完再用 prompts.update 改名。不扣费。",
3177
+ "inputSchema": {
3178
+ "type": "object",
3179
+ "properties": {
3180
+ "promptId": {
3181
+ "type": "integer",
3182
+ "minimum": 1,
3183
+ "description": "复制哪一条。公共模板也可以,但只能是文章正文/标题两类"
3184
+ },
3185
+ "companyIds": {
3186
+ "type": "array",
3187
+ "items": {
3188
+ "type": "integer",
3189
+ "minimum": 1
3190
+ },
3191
+ "minItems": 1,
3192
+ "description": "复制到哪几家公司,每家一份。只能是当前密钥授权的公司"
3193
+ }
3194
+ },
3195
+ "required": [
3196
+ "promptId",
3197
+ "companyIds"
3198
+ ],
3199
+ "additionalProperties": false
3200
+ }
3201
+ },
3171
3202
  {
3172
3203
  "name": "articles.copy",
3173
3204
  "mode": "write",
@@ -3383,7 +3414,7 @@
3383
3414
  "mode": "read",
3384
3415
  "guide": "publication",
3385
3416
  "requiresPlan": false,
3386
- "description": "媒体投稿记录:订单状态、失败原因、发布链接、退款状态。投稿是异步的,提交完要过一阵才出结果,用这条查进展。**status 和 refundStatus 是两件事**——status 说稿子发出去没有,refundStatus 说钱退没退;被拒稿的记录要把两个都念给用户。",
3417
+ "description": "媒体投稿记录:订单状态、失败原因、发布链接、退款状态、实际扣款。投稿是异步的,提交完要过一阵才出结果,用这条查进展。**status 和 refundStatus 是两件事**——status 说稿子发出去没有,refundStatus 说钱退没退;被拒稿的记录要把两个都念给用户。报「这笔花了多少」用 chargedAmount(元,来自账本的真实扣款);currentPrice 是这家媒体**现在**的挂牌价,只能用来估算再投一次的花费,媒体调过价的话它和当时扣的不是一个数。chargedAmount 为 null 表示账本里查不到这笔扣费,就说查不到,别拿 currentPrice 顶替。",
3387
3418
  "inputSchema": {
3388
3419
  "type": "object",
3389
3420
  "properties": {
package/dist/index.cjs CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
- "use strict";var bt=Object.defineProperty;var At=(e,t,n)=>t in e?bt(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;var Z=(e,t,n)=>At(e,typeof t!="symbol"?t+"":t,n);var ee="https://nbgeo.aimusiclj.com",he="best-geo-test",Ie="best-geo-test",ke="bg-test-cli-",be="0.3.2";var D=1,E=be,O=Ie,l=he,Ae="dev",B=xt(St());function St(){var e;return(e=process.env.BEST_GEO_API_BASE)!=null?e:ee}var j=ke,Se=300*1e3,xe=30*1e3,_e=300*1e3;function xt(e){return e.replace(/\/+$/,"")}var Ve=require("node:child_process");var Oe=require("node:crypto"),G=require("node:os");var p=require("node:fs"),ve=require("node:os"),L=require("node:path");var we=require("node:crypto");var A=class extends Error{constructor(n,r,i){super(i);Z(this,"reason",n);Z(this,"path",r);this.name="LocalConfigError"}},_t={schemaVersion:1,device:null,activeCredential:null,pendingCredential:null};function U(){var e;return(e=process.env.BEST_GEO_CONFIG_DIR)!=null?e:(0,L.join)((0,ve.homedir)(),`.${l}`)}function w(){return(0,L.join)(U(),"config.json")}function x(){var n,r,i;let e=w(),t;try{if(!(0,p.existsSync)(e))return null;wt(e),t=(0,p.readFileSync)(e,"utf8")}catch(s){throw s instanceof A?s:Ce(s,e)}try{let s=JSON.parse(t);if(typeof s!="object"||s==null||s.schemaVersion!==1)throw new Error("unexpected shape");return{schemaVersion:1,device:(n=s.device)!=null?n:null,activeCredential:(r=s.activeCredential)!=null?r:null,pendingCredential:(i=s.pendingCredential)!=null?i:null}}catch{throw new A("corrupted",e,`\u672C\u673A\u914D\u7F6E\u6587\u4EF6\u5185\u5BB9\u4E0D\u5B8C\u6574\u6216\u683C\u5F0F\u4E0D\u5BF9\uFF1A${e}`)}}function vt(e){let t=U(),n=w(),r=(0,L.join)(t,`.config.json.${(0,we.randomBytes)(6).toString("hex")}.tmp`);try{(0,p.existsSync)(t)||(0,p.mkdirSync)(t,{recursive:!0,mode:448});let i=(0,p.openSync)(r,"wx",384);try{(0,p.writeSync)(i,`${JSON.stringify(e,null,2)}
3
- `),(0,p.fsyncSync)(i)}finally{(0,p.closeSync)(i)}(0,p.renameSync)(r,n)}catch(i){if((0,p.existsSync)(r))try{(0,p.unlinkSync)(r)}catch{}throw Ce(i,n)}}function _(e){var n;let t=e((n=x())!=null?n:{..._t});return vt(t),t}function wt(e){var r;if(process.platform==="win32")return;let t=(0,p.statSync)(e),n=(r=process.getuid)==null?void 0:r.call(process);if(n!=null&&t.uid!==n)throw new A("not_owner",e,`\u672C\u673A\u914D\u7F6E\u6587\u4EF6\u4E0D\u5C5E\u4E8E\u5F53\u524D\u7528\u6237\uFF1A${e}`);if((t.mode&63)!==0)throw new A("permissions_too_open",e,`\u672C\u673A\u914D\u7F6E\u6587\u4EF6\u6743\u9650\u8FC7\u5BBD\uFF08\u540C\u673A\u5176\u4ED6\u7528\u6237\u53EF\u8BFB\uFF09\uFF1A${e}`)}function Ce(e,t){let n=e==null?void 0:e.code;return n==="EACCES"||n==="EPERM"||n==="EROFS"?new A("denied",t,`\u6CA1\u6709\u6743\u9650\u8BFB\u5199\u672C\u673A\u914D\u7F6E\uFF1A${t}`):e instanceof Error?e:new Error(String(e))}var Ct=3600*1e3;function Re(){return(0,L.join)(U(),"pending-uploads.json")}function M(){let e=Re();if(!(0,p.existsSync)(e))return{};try{let t=JSON.parse((0,p.readFileSync)(e,"utf8")),n=Date.now();return Object.fromEntries(Object.entries(t).filter(([,r])=>{var i;return n-((i=r==null?void 0:r.createdAt)!=null?i:0)<Ct}))}catch{return{}}}function te(e){(0,p.mkdirSync)(U(),{recursive:!0,mode:448}),(0,p.writeFileSync)(Re(),JSON.stringify(e),{mode:384})}function $e(){var t,n;let e=(t=x())==null?void 0:t.device;return(n=e==null?void 0:e.deviceId)!=null&&n.startsWith(j)?e.deviceId:null}function H(){var r,i;let e={deviceName:(0,G.hostname)().slice(0,50),platform:`${(0,G.platform)()}-${process.arch}`},t=(r=x())==null?void 0:r.device;if((i=t==null?void 0:t.deviceId)!=null&&i.startsWith(j))return t.deviceName===e.deviceName&&t.platform===e.platform?t:_(s=>({...s,device:{...t,...e}})).device;let n={deviceId:`${j}${(0,Oe.randomUUID)()}`,...e};return _(s=>({...s,device:n})).device}function Ne(){return`cli_${Date.now().toString(36)}${Math.random().toString(36).slice(2,8)}`}function h(e,t=Ne()){return{ok:!0,code:"OK",requestId:t,data:e}}function c(e,t,n={}){var r;return{ok:!1,code:e,message:t,requestId:(r=n.requestId)!=null?r:Ne(),...n.data==null?{}:{data:n.data},...n.nextAction==null?{}:{nextAction:n.nextAction}}}function a(e){process.stdout.write(`${JSON.stringify(e)}
4
- `),e.ok||(process.exitCode=1)}async function y(e,t={}){var s,o;let n=new URL(`${B}/v1/agent-cli${e}`);for(let[d,m]of Object.entries((s=t.query)!=null?s:{}))if(m!=null)for(let u of Array.isArray(m)?m:[m])n.searchParams.append(d,String(u));let r={"X-GEO-CLI-Version":E,"X-GEO-Protocol-Version":String(D),"X-GEO-CLI-Package":O},i=null;try{i=$e()}catch{}i&&(r["X-Device-ID"]=i),t.apiKey&&(r.Authorization=`Bearer ${t.apiKey}`),t.body!=null&&(r["Content-Type"]="application/json");try{let d=await fetch(n,{method:(o=t.method)!=null?o:"GET",headers:r,body:t.body==null?void 0:JSON.stringify(t.body),signal:AbortSignal.timeout(t.isWrite?_e:xe)}),m=await d.text();try{let u=JSON.parse(m);return Rt(u)?u:c("SERVER_ERROR",`\u670D\u52A1\u7AEF\u8FD4\u56DE\u4E86\u975E\u9884\u671F\u5185\u5BB9\uFF08HTTP ${d.status}\uFF09`,{data:{transportFailure:!0}})}catch{return c("SERVER_ERROR",`\u670D\u52A1\u7AEF\u8FD4\u56DE\u4E86\u975E\u9884\u671F\u5185\u5BB9\uFF08HTTP ${d.status}\uFF09`,{data:{transportFailure:!0}})}}catch(d){return d instanceof Error&&(d.name==="TimeoutError"||d.name==="AbortError")?c("SERVER_ERROR",t.isWrite?"\u670D\u52A1\u7AEF\u5904\u7406\u8D85\u65F6,\u8FD9\u6B21\u5199\u5165\u7ED3\u679C\u672A\u77E5":"\u670D\u52A1\u7AEF\u54CD\u5E94\u8D85\u65F6",{data:{transportFailure:!0},nextAction:t.isWrite?{type:"ask_user",message:"\u8D85\u65F6\u4E0D\u4EE3\u8868\u6CA1\u5199\u8FDB\u53BB \u2014\u2014 \u670D\u52A1\u7AEF\u53EF\u80FD\u8FD8\u5728\u5904\u7406\u3002**\u5148\u7528\u5BF9\u5E94\u7684\u67E5\u8BE2\u80FD\u529B\u786E\u8BA4\u4E00\u904D**,\u786E\u5B9E\u6CA1\u6709\u518D\u91CD\u65B0 plan;\u76F4\u63A5\u91CD\u8BD5\u4F1A\u5EFA\u51FA\u91CD\u590D\u7684\u4E00\u4EFD,\u800C\u4E14\u4F1A\u518D\u6263\u4E00\u6B21\u8D39\u3002"}:{type:"ask_user",message:"\u670D\u52A1\u7AEF\u54CD\u5E94\u592A\u6162\u3002\u7A0D\u540E\u91CD\u8BD5\u540C\u4E00\u6761\u547D\u4EE4\u5373\u53EF,\u67E5\u8BE2\u4E0D\u4F1A\u4EA7\u751F\u4EFB\u4F55\u5199\u5165"}}):c("SERVER_ERROR",`\u65E0\u6CD5\u8FDE\u63A5\u670D\u52A1\u7AEF\uFF1A${d instanceof Error?d.message:String(d)}`,{data:{transportFailure:!0},nextAction:{type:"ask_user",message:"\u8BF7\u786E\u8BA4\u7F51\u7EDC\u53EF\u7528\uFF0C\u4EE5\u53CA\u670D\u52A1\u7AEF\u5730\u5740\u914D\u7F6E\u6B63\u786E"}})}}function Rt(e){if(typeof e!="object"||e===null)return!1;let t=e;return typeof t.ok=="boolean"&&typeof t.code=="string"}function Ot(e){var t;return!e.ok&&((t=e.data)==null?void 0:t.transportFailure)===!0}function ne(e){return e.ok||Ot(e)?!1:["AUTH_EXPIRED","DEVICE_MISMATCH","ACCESS_DENIED","AUTH_REQUIRED","VALIDATION_FAILED"].includes(e.code)}function $(){var e,t,n;return(n=(t=(e=x())==null?void 0:e.activeCredential)==null?void 0:t.apiKey)!=null?n:null}function J(){var e,t;return(t=(e=x())==null?void 0:e.activeCredential)!=null?t:null}function Te(){var e,t;return(t=(e=x())==null?void 0:e.pendingCredential)!=null?t:null}function Pe(e){_(t=>({...t,pendingCredential:{apiKey:e,startedAt:new Date().toISOString()}}))}function re(){_(e=>({...e,pendingCredential:null}))}function ie(e){return _(t=>{let n=t.pendingCredential;return n?{...t,activeCredential:{apiKey:n.apiKey,...e},pendingCredential:null}:t}).activeCredential}function De(){_(e=>({...e,activeCredential:null,pendingCredential:null}))}var v=require("node:crypto"),Ue=require("node:http");function Le(e){let t=`
2
+ "use strict";var bt=Object.defineProperty;var At=(e,t,n)=>t in e?bt(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;var Z=(e,t,n)=>At(e,typeof t!="symbol"?t+"":t,n);var ee="https://nbgeo.aimusiclj.com",Ee="best-geo-test",Ie="best-geo-test",ke="bg-test-cli-",be="0.3.4";var D=1,h=be,O=Ie,l=Ee,Ae="dev",B=xt(St());function St(){var e;return(e=process.env.BEST_GEO_API_BASE)!=null?e:ee}var j=ke,Se=300*1e3,xe=30*1e3,_e=300*1e3;function xt(e){return e.replace(/\/+$/,"")}var Ve=require("node:child_process");var Oe=require("node:crypto"),G=require("node:os");var p=require("node:fs"),we=require("node:os"),L=require("node:path");var Ce=require("node:crypto");var A=class extends Error{constructor(n,r,i){super(i);Z(this,"reason",n);Z(this,"path",r);this.name="LocalConfigError"}},_t={schemaVersion:1,device:null,activeCredential:null,pendingCredential:null};function U(){var e;return(e=process.env.BEST_GEO_CONFIG_DIR)!=null?e:(0,L.join)((0,we.homedir)(),`.${l}`)}function C(){return(0,L.join)(U(),"config.json")}function x(){var n,r,i;let e=C(),t;try{if(!(0,p.existsSync)(e))return null;Ct(e),t=(0,p.readFileSync)(e,"utf8")}catch(s){throw s instanceof A?s:ve(s,e)}try{let s=JSON.parse(t);if(typeof s!="object"||s==null||s.schemaVersion!==1)throw new Error("unexpected shape");return{schemaVersion:1,device:(n=s.device)!=null?n:null,activeCredential:(r=s.activeCredential)!=null?r:null,pendingCredential:(i=s.pendingCredential)!=null?i:null}}catch{throw new A("corrupted",e,`\u672C\u673A\u914D\u7F6E\u6587\u4EF6\u5185\u5BB9\u4E0D\u5B8C\u6574\u6216\u683C\u5F0F\u4E0D\u5BF9\uFF1A${e}`)}}function wt(e){let t=U(),n=C(),r=(0,L.join)(t,`.config.json.${(0,Ce.randomBytes)(6).toString("hex")}.tmp`);try{(0,p.existsSync)(t)||(0,p.mkdirSync)(t,{recursive:!0,mode:448});let i=(0,p.openSync)(r,"wx",384);try{(0,p.writeSync)(i,`${JSON.stringify(e,null,2)}
3
+ `),(0,p.fsyncSync)(i)}finally{(0,p.closeSync)(i)}(0,p.renameSync)(r,n)}catch(i){if((0,p.existsSync)(r))try{(0,p.unlinkSync)(r)}catch{}throw ve(i,n)}}function _(e){var n;let t=e((n=x())!=null?n:{..._t});return wt(t),t}function Ct(e){var r;if(process.platform==="win32")return;let t=(0,p.statSync)(e),n=(r=process.getuid)==null?void 0:r.call(process);if(n!=null&&t.uid!==n)throw new A("not_owner",e,`\u672C\u673A\u914D\u7F6E\u6587\u4EF6\u4E0D\u5C5E\u4E8E\u5F53\u524D\u7528\u6237\uFF1A${e}`);if((t.mode&63)!==0)throw new A("permissions_too_open",e,`\u672C\u673A\u914D\u7F6E\u6587\u4EF6\u6743\u9650\u8FC7\u5BBD\uFF08\u540C\u673A\u5176\u4ED6\u7528\u6237\u53EF\u8BFB\uFF09\uFF1A${e}`)}function ve(e,t){let n=e==null?void 0:e.code;return n==="EACCES"||n==="EPERM"||n==="EROFS"?new A("denied",t,`\u6CA1\u6709\u6743\u9650\u8BFB\u5199\u672C\u673A\u914D\u7F6E\uFF1A${t}`):e instanceof Error?e:new Error(String(e))}var vt=3600*1e3;function Re(){return(0,L.join)(U(),"pending-uploads.json")}function M(){let e=Re();if(!(0,p.existsSync)(e))return{};try{let t=JSON.parse((0,p.readFileSync)(e,"utf8")),n=Date.now();return Object.fromEntries(Object.entries(t).filter(([,r])=>{var i;return n-((i=r==null?void 0:r.createdAt)!=null?i:0)<vt}))}catch{return{}}}function te(e){(0,p.mkdirSync)(U(),{recursive:!0,mode:448}),(0,p.writeFileSync)(Re(),JSON.stringify(e),{mode:384})}function $e(){var t,n;let e=(t=x())==null?void 0:t.device;return(n=e==null?void 0:e.deviceId)!=null&&n.startsWith(j)?e.deviceId:null}function H(){var r,i;let e={deviceName:(0,G.hostname)().slice(0,50),platform:`${(0,G.platform)()}-${process.arch}`},t=(r=x())==null?void 0:r.device;if((i=t==null?void 0:t.deviceId)!=null&&i.startsWith(j))return t.deviceName===e.deviceName&&t.platform===e.platform?t:_(s=>({...s,device:{...t,...e}})).device;let n={deviceId:`${j}${(0,Oe.randomUUID)()}`,...e};return _(s=>({...s,device:n})).device}function Ne(){return`cli_${Date.now().toString(36)}${Math.random().toString(36).slice(2,8)}`}function E(e,t=Ne()){return{ok:!0,code:"OK",requestId:t,data:e}}function c(e,t,n={}){var r;return{ok:!1,code:e,message:t,requestId:(r=n.requestId)!=null?r:Ne(),...n.data==null?{}:{data:n.data},...n.nextAction==null?{}:{nextAction:n.nextAction}}}function a(e){process.stdout.write(`${JSON.stringify(e)}
4
+ `),e.ok||(process.exitCode=1)}async function y(e,t={}){var s,o;let n=new URL(`${B}/v1/agent-cli${e}`);for(let[d,m]of Object.entries((s=t.query)!=null?s:{}))if(m!=null)for(let u of Array.isArray(m)?m:[m])n.searchParams.append(d,String(u));let r={"X-GEO-CLI-Version":h,"X-GEO-Protocol-Version":String(D),"X-GEO-CLI-Package":O},i=null;try{i=$e()}catch{}i&&(r["X-Device-ID"]=i),t.apiKey&&(r.Authorization=`Bearer ${t.apiKey}`),t.body!=null&&(r["Content-Type"]="application/json");try{let d=await fetch(n,{method:(o=t.method)!=null?o:"GET",headers:r,body:t.body==null?void 0:JSON.stringify(t.body),signal:AbortSignal.timeout(t.isWrite?_e:xe)}),m=await d.text();try{let u=JSON.parse(m);return Rt(u)?u:c("SERVER_ERROR",`\u670D\u52A1\u7AEF\u8FD4\u56DE\u4E86\u975E\u9884\u671F\u5185\u5BB9\uFF08HTTP ${d.status}\uFF09`,{data:{transportFailure:!0}})}catch{return c("SERVER_ERROR",`\u670D\u52A1\u7AEF\u8FD4\u56DE\u4E86\u975E\u9884\u671F\u5185\u5BB9\uFF08HTTP ${d.status}\uFF09`,{data:{transportFailure:!0}})}}catch(d){return d instanceof Error&&(d.name==="TimeoutError"||d.name==="AbortError")?c("SERVER_ERROR",t.isWrite?"\u670D\u52A1\u7AEF\u5904\u7406\u8D85\u65F6,\u8FD9\u6B21\u5199\u5165\u7ED3\u679C\u672A\u77E5":"\u670D\u52A1\u7AEF\u54CD\u5E94\u8D85\u65F6",{data:{transportFailure:!0},nextAction:t.isWrite?{type:"ask_user",message:"\u8D85\u65F6\u4E0D\u4EE3\u8868\u6CA1\u5199\u8FDB\u53BB \u2014\u2014 \u670D\u52A1\u7AEF\u53EF\u80FD\u8FD8\u5728\u5904\u7406\u3002**\u5148\u7528\u5BF9\u5E94\u7684\u67E5\u8BE2\u80FD\u529B\u786E\u8BA4\u4E00\u904D**,\u786E\u5B9E\u6CA1\u6709\u518D\u91CD\u65B0 plan;\u76F4\u63A5\u91CD\u8BD5\u4F1A\u5EFA\u51FA\u91CD\u590D\u7684\u4E00\u4EFD,\u800C\u4E14\u4F1A\u518D\u6263\u4E00\u6B21\u8D39\u3002"}:{type:"ask_user",message:"\u670D\u52A1\u7AEF\u54CD\u5E94\u592A\u6162\u3002\u7A0D\u540E\u91CD\u8BD5\u540C\u4E00\u6761\u547D\u4EE4\u5373\u53EF,\u67E5\u8BE2\u4E0D\u4F1A\u4EA7\u751F\u4EFB\u4F55\u5199\u5165"}}):c("SERVER_ERROR",`\u65E0\u6CD5\u8FDE\u63A5\u670D\u52A1\u7AEF\uFF1A${d instanceof Error?d.message:String(d)}`,{data:{transportFailure:!0},nextAction:{type:"ask_user",message:"\u8BF7\u786E\u8BA4\u7F51\u7EDC\u53EF\u7528\uFF0C\u4EE5\u53CA\u670D\u52A1\u7AEF\u5730\u5740\u914D\u7F6E\u6B63\u786E"}})}}function Rt(e){if(typeof e!="object"||e===null)return!1;let t=e;return typeof t.ok=="boolean"&&typeof t.code=="string"}function Ot(e){var t;return!e.ok&&((t=e.data)==null?void 0:t.transportFailure)===!0}function ne(e){return e.ok||Ot(e)?!1:["AUTH_EXPIRED","DEVICE_MISMATCH","ACCESS_DENIED","AUTH_REQUIRED","VALIDATION_FAILED"].includes(e.code)}function $(){var e,t,n;return(n=(t=(e=x())==null?void 0:e.activeCredential)==null?void 0:t.apiKey)!=null?n:null}function J(){var e,t;return(t=(e=x())==null?void 0:e.activeCredential)!=null?t:null}function Te(){var e,t;return(t=(e=x())==null?void 0:e.pendingCredential)!=null?t:null}function Pe(e){_(t=>({...t,pendingCredential:{apiKey:e,startedAt:new Date().toISOString()}}))}function re(){_(e=>({...e,pendingCredential:null}))}function ie(e){return _(t=>{let n=t.pendingCredential;return n?{...t,activeCredential:{apiKey:n.apiKey,...e},pendingCredential:null}:t}).activeCredential}function De(){_(e=>({...e,activeCredential:null,pendingCredential:null}))}var w=require("node:crypto"),Ue=require("node:http");function Le(e){let t=`
5
5
  (function () {
6
6
  var form = document.getElementById('f');
7
7
  var input = document.getElementById('k');
@@ -84,7 +84,7 @@ button:disabled { opacity: .6; cursor: default; }
84
84
  </div>
85
85
  <script>${t}</script>
86
86
  </body>
87
- </html>`,scriptHash:t}}var $t=256,Nt=4*1024;async function Me(){let e=(0,v.randomBytes)(16).toString("hex"),t=(0,v.randomBytes)(16).toString("hex"),n=(0,v.randomBytes)(16).toString("hex"),{html:r,scriptHash:i}=Le(t),s=(0,v.createHash)("sha256").update(i).digest("base64"),o=null,d=new Promise((g,f)=>{o={resolve:g,reject:f}});d.catch(()=>{});let m=!1,u=(0,Ue.createServer)((g,f)=>{b(g,f).catch(()=>{f.writeHead(500,{"Content-Type":"application/json"}),f.end(JSON.stringify({ok:!1,message:"internal error"}))})});async function b(g,f){var pe,me,fe,ge,ye;let Y=new URL((pe=g.url)!=null?pe:"/","http://127.0.0.1");if(g.method==="GET"&&Y.pathname==="/"){if(Y.searchParams.get("state")!==e){f.writeHead(404).end();return}f.writeHead(200,{"Content-Type":"text/html; charset=utf-8","Content-Security-Policy":["default-src 'none'",`script-src 'sha256-${s}'`,"style-src 'unsafe-inline'","connect-src 'self'","form-action 'none'","base-uri 'none'","frame-ancestors 'none'"].join("; "),"Set-Cookie":`bg_session=${n}; HttpOnly; SameSite=Strict; Path=/`,"Cache-Control":"no-store","Referrer-Policy":"no-referrer"}),f.end(r);return}if(g.method==="POST"&&Y.pathname==="/submit"){let It=g.headers.origin,kt=`http://127.0.0.1:${u.address().port}`;if(It!==kt){S(f,403,{ok:!1,message:"origin rejected"});return}if(!Pt(String((me=g.headers["x-csrf-token"])!=null?me:""),t)){S(f,403,{ok:!1,message:"csrf rejected"});return}if(!String((fe=g.headers.cookie)!=null?fe:"").includes(`bg_session=${n}`)){S(f,403,{ok:!1,message:"session rejected"});return}if(!String((ge=g.headers["content-type"])!=null?ge:"").includes("application/json")){S(f,415,{ok:!1,message:"content-type rejected"});return}if(m){S(f,409,{ok:!1,message:"already submitted"});return}let Ee=await Tt(g);if(Ee==null){S(f,413,{ok:!1,message:"body too large"});return}let K="";try{K=String((ye=JSON.parse(Ee).key)!=null?ye:"").trim()}catch{S(f,400,{ok:!1,message:"invalid json"});return}if(!K||K.length>$t){S(f,400,{ok:!1,message:"invalid key"});return}m=!0,S(f,200,{ok:!0}),o==null||o.resolve(K),setTimeout(()=>W(),200).unref();return}f.writeHead(404).end()}if(process.env.BEST_GEO_TEST_FORCE_LISTEN_ERROR==="1")throw Object.assign(new Error("listen EACCES: permission denied 127.0.0.1"),{code:"EACCES"});u.on("error",g=>{o==null||o.reject(g)}),await new Promise((g,f)=>{u.once("error",f),u.listen(0,"127.0.0.1",()=>{u.removeListener("error",f),g()})});let k=u.address().port,de=setTimeout(()=>{o==null||o.reject(new Error("LOCAL_INTAKE_TIMEOUT")),W()},Se);de.unref();let le=!1;function W(){var g;le||(le=!0,clearTimeout(de),(g=u.closeAllConnections)==null||g.call(u),u.close())}return{url:`http://127.0.0.1:${k}/?state=${e}`,waitForKey:d,close:W}}function S(e,t,n){e.writeHead(t,{"Content-Type":"application/json","Cache-Control":"no-store"}),e.end(JSON.stringify(n))}async function Tt(e){let t=[],n=0;for await(let r of e){if(n+=r.length,n>Nt)return null;t.push(r)}return Buffer.concat(t).toString("utf8")}function Pt(e,t){let n=Buffer.from(e),r=Buffer.from(t);return n.length===r.length&&(0,v.timingSafeEqual)(n,r)}async function V(){let e=Te();if(!e)return null;let t=await je(e.apiKey);return t.ok?(ie({userId:t.data.user.id,agentId:t.data.agentId,companyIds:t.data.companyIds}),null):ne(t)?(re(),null):c("SERVER_ERROR",`\u672C\u673A\u6709\u4E00\u4EFD\u5F85\u786E\u8BA4\u7684\u6388\u6743\uFF0C\u6682\u65F6\u65E0\u6CD5\u4E0E\u670D\u52A1\u7AEF\u786E\u8BA4\uFF1A${t.message}`,{requestId:t.requestId,nextAction:{type:"ask_user",message:"\u7F51\u7EDC\u6062\u590D\u540E\u91CD\u8BD5\u540C\u4E00\u6761\u547D\u4EE4\u5373\u53EF\u81EA\u52A8\u6536\u655B\uFF1B\u5728\u6B64\u4E4B\u524D\u4E0D\u8981\u91CD\u65B0\u767B\u5F55\uFF0C\u4E5F\u4E0D\u8981\u5220\u9664\u672C\u673A\u914D\u7F6E\u6587\u4EF6\u3002"}})}async function qe(){var m;let e=H(),t=await V();if(t){a(t);return}let n=$(),r;try{r=await Me()}catch(u){a(c("HOST_PERMISSION_REQUIRED",`\u65E0\u6CD5\u5728\u672C\u673A\u542F\u52A8\u5F55\u5165\u670D\u52A1\uFF1A${Lt(u)}`,{nextAction:{type:"request_host_approval",message:"Best GEO \u9700\u8981\u5728 127.0.0.1 \u4E0A\u76D1\u542C\u4E00\u4E2A\u968F\u673A\u7AEF\u53E3\u6765\u63A5\u6536\u7528\u6237\u7C98\u8D34\u7684\u5BC6\u94A5\uFF08\u4E0D\u5BF9\u5916\u66B4\u9732\uFF09\u3002\u8BF7\u7528\u5F53\u524D\u5DE5\u5177\u7684\u6743\u9650\u786E\u8BA4\u673A\u5236\u6388\u6743\u672C\u673A\u56DE\u73AF\u7AEF\u53E3\u76D1\u542C\u540E\u91CD\u8BD5\u540C\u4E00\u6761\u547D\u4EE4\u3002",capability:"loopback_port",command:`${l} auth login`}}));return}Dt(r.url);let i=`[${l}]`;process.stderr.write(`${i} auth login \u5DF2\u542F\u52A8\u672C\u673A\u5F55\u5165\u670D\u52A1\uFF0C\u4F1A\u963B\u585E\u7B49\u5F85\u7528\u6237\u7C98\u8D34\u5BC6\u94A5\uFF0C\u6700\u957F 5 \u5206\u949F\u3002
87
+ </html>`,scriptHash:t}}var $t=256,Nt=4*1024;async function Me(){let e=(0,w.randomBytes)(16).toString("hex"),t=(0,w.randomBytes)(16).toString("hex"),n=(0,w.randomBytes)(16).toString("hex"),{html:r,scriptHash:i}=Le(t),s=(0,w.createHash)("sha256").update(i).digest("base64"),o=null,d=new Promise((g,f)=>{o={resolve:g,reject:f}});d.catch(()=>{});let m=!1,u=(0,Ue.createServer)((g,f)=>{b(g,f).catch(()=>{f.writeHead(500,{"Content-Type":"application/json"}),f.end(JSON.stringify({ok:!1,message:"internal error"}))})});async function b(g,f){var pe,me,fe,ge,ye;let Y=new URL((pe=g.url)!=null?pe:"/","http://127.0.0.1");if(g.method==="GET"&&Y.pathname==="/"){if(Y.searchParams.get("state")!==e){f.writeHead(404).end();return}f.writeHead(200,{"Content-Type":"text/html; charset=utf-8","Content-Security-Policy":["default-src 'none'",`script-src 'sha256-${s}'`,"style-src 'unsafe-inline'","connect-src 'self'","form-action 'none'","base-uri 'none'","frame-ancestors 'none'"].join("; "),"Set-Cookie":`bg_session=${n}; HttpOnly; SameSite=Strict; Path=/`,"Cache-Control":"no-store","Referrer-Policy":"no-referrer"}),f.end(r);return}if(g.method==="POST"&&Y.pathname==="/submit"){let It=g.headers.origin,kt=`http://127.0.0.1:${u.address().port}`;if(It!==kt){S(f,403,{ok:!1,message:"origin rejected"});return}if(!Pt(String((me=g.headers["x-csrf-token"])!=null?me:""),t)){S(f,403,{ok:!1,message:"csrf rejected"});return}if(!String((fe=g.headers.cookie)!=null?fe:"").includes(`bg_session=${n}`)){S(f,403,{ok:!1,message:"session rejected"});return}if(!String((ge=g.headers["content-type"])!=null?ge:"").includes("application/json")){S(f,415,{ok:!1,message:"content-type rejected"});return}if(m){S(f,409,{ok:!1,message:"already submitted"});return}let he=await Tt(g);if(he==null){S(f,413,{ok:!1,message:"body too large"});return}let K="";try{K=String((ye=JSON.parse(he).key)!=null?ye:"").trim()}catch{S(f,400,{ok:!1,message:"invalid json"});return}if(!K||K.length>$t){S(f,400,{ok:!1,message:"invalid key"});return}m=!0,S(f,200,{ok:!0}),o==null||o.resolve(K),setTimeout(()=>W(),200).unref();return}f.writeHead(404).end()}if(process.env.BEST_GEO_TEST_FORCE_LISTEN_ERROR==="1")throw Object.assign(new Error("listen EACCES: permission denied 127.0.0.1"),{code:"EACCES"});u.on("error",g=>{o==null||o.reject(g)}),await new Promise((g,f)=>{u.once("error",f),u.listen(0,"127.0.0.1",()=>{u.removeListener("error",f),g()})});let k=u.address().port,de=setTimeout(()=>{o==null||o.reject(new Error("LOCAL_INTAKE_TIMEOUT")),W()},Se);de.unref();let le=!1;function W(){var g;le||(le=!0,clearTimeout(de),(g=u.closeAllConnections)==null||g.call(u),u.close())}return{url:`http://127.0.0.1:${k}/?state=${e}`,waitForKey:d,close:W}}function S(e,t,n){e.writeHead(t,{"Content-Type":"application/json","Cache-Control":"no-store"}),e.end(JSON.stringify(n))}async function Tt(e){let t=[],n=0;for await(let r of e){if(n+=r.length,n>Nt)return null;t.push(r)}return Buffer.concat(t).toString("utf8")}function Pt(e,t){let n=Buffer.from(e),r=Buffer.from(t);return n.length===r.length&&(0,w.timingSafeEqual)(n,r)}async function V(){let e=Te();if(!e)return null;let t=await je(e.apiKey);return t.ok?(ie({userId:t.data.user.id,agentId:t.data.agentId,companyIds:t.data.companyIds}),null):ne(t)?(re(),null):c("SERVER_ERROR",`\u672C\u673A\u6709\u4E00\u4EFD\u5F85\u786E\u8BA4\u7684\u6388\u6743\uFF0C\u6682\u65F6\u65E0\u6CD5\u4E0E\u670D\u52A1\u7AEF\u786E\u8BA4\uFF1A${t.message}`,{requestId:t.requestId,nextAction:{type:"ask_user",message:"\u7F51\u7EDC\u6062\u590D\u540E\u91CD\u8BD5\u540C\u4E00\u6761\u547D\u4EE4\u5373\u53EF\u81EA\u52A8\u6536\u655B\uFF1B\u5728\u6B64\u4E4B\u524D\u4E0D\u8981\u91CD\u65B0\u767B\u5F55\uFF0C\u4E5F\u4E0D\u8981\u5220\u9664\u672C\u673A\u914D\u7F6E\u6587\u4EF6\u3002"}})}async function qe(){var m;let e=H(),t=await V();if(t){a(t);return}let n=$(),r;try{r=await Me()}catch(u){a(c("HOST_PERMISSION_REQUIRED",`\u65E0\u6CD5\u5728\u672C\u673A\u542F\u52A8\u5F55\u5165\u670D\u52A1\uFF1A${Lt(u)}`,{nextAction:{type:"request_host_approval",message:"Best GEO \u9700\u8981\u5728 127.0.0.1 \u4E0A\u76D1\u542C\u4E00\u4E2A\u968F\u673A\u7AEF\u53E3\u6765\u63A5\u6536\u7528\u6237\u7C98\u8D34\u7684\u5BC6\u94A5\uFF08\u4E0D\u5BF9\u5916\u66B4\u9732\uFF09\u3002\u8BF7\u7528\u5F53\u524D\u5DE5\u5177\u7684\u6743\u9650\u786E\u8BA4\u673A\u5236\u6388\u6743\u672C\u673A\u56DE\u73AF\u7AEF\u53E3\u76D1\u542C\u540E\u91CD\u8BD5\u540C\u4E00\u6761\u547D\u4EE4\u3002",capability:"loopback_port",command:`${l} auth login`}}));return}Dt(r.url);let i=`[${l}]`;process.stderr.write(`${i} auth login \u5DF2\u542F\u52A8\u672C\u673A\u5F55\u5165\u670D\u52A1\uFF0C\u4F1A\u963B\u585E\u7B49\u5F85\u7528\u6237\u7C98\u8D34\u5BC6\u94A5\uFF0C\u6700\u957F 5 \u5206\u949F\u3002
88
88
  ${i} \u8C03\u7528\u65B9\u8BF7\u4FDD\u6301\u672C\u8FDB\u7A0B\u8FD0\u884C\u76F4\u5230\u5B83\u81EA\u884C\u9000\u51FA\uFF0C\u4E0D\u8981\u4E2D\u65AD\u3001\u4E0D\u8981\u8F6C\u4EA4\u7ED9\u7528\u6237\u5728\u522B\u5904\u6267\u884C\uFF1B
89
89
  ${i} \u8FDB\u7A0B\u9000\u51FA\u65F6 stdout \u4F1A\u7ED9\u51FA\u552F\u4E00\u4E00\u4E2A JSON \u7ED3\u679C\uFF0C\u90A3\u65F6\u518D\u5411\u7528\u6237\u6C47\u62A5\u6210\u8D25\u3002
90
90
  ${i} \u73B0\u5728\u8BF7\u628A\u4E0B\u9762\u8FD9\u4E2A\u5730\u5740\u8F6C\u8FBE\u7ED9\u7528\u6237\uFF0C\u8BA9\u4ED6\u5728\u6D4F\u89C8\u5668\u91CC\u6253\u5F00\u5E76\u7C98\u8D34\u5BC6\u94A5\uFF08\u5BC6\u94A5\u4E0D\u8981\u7ECF\u8FC7\u4F60\uFF09\uFF1A
@@ -92,4 +92,4 @@ ${i} \u73B0\u5728\u8BF7\u628A\u4E0B\u9762\u8FD9\u4E2A\u5730\u5740\u8F6C\u8FBE\u7
92
92
  `),n&&process.stderr.write(`${i} \u672C\u673A\u5DF2\u6709\u4E00\u4EFD\u6388\u6743\uFF0C\u5F55\u5165\u65B0\u5BC6\u94A5\u4F1A\u66FF\u6362\u5B83\u3002
93
93
  `);let s;try{s=await r.waitForKey}catch{r.close(),a(c("AUTH_REQUIRED","\u672C\u5730\u5F55\u5165\u8D85\u65F6\u6216\u88AB\u53D6\u6D88",{nextAction:{type:"auth_login",message:"\u7528\u6237\u5728 5 \u5206\u949F\u5185\u6CA1\u6709\u5B8C\u6210\u7C98\u8D34\u3002\u5148\u95EE\u6E05\u4ED6\u662F\u5426\u5DF2\u7ECF\u62FF\u5230\u5BC6\u94A5\uFF0C\u518D\u7531\u4F60\u91CD\u65B0\u6267\u884C command\uFF0C\u5E76\u628A\u65B0\u7684\u672C\u5730\u9875\u9762\u5730\u5740\u8F6C\u8FBE\u7ED9\u4ED6\u3002",command:`${l} auth login`}}));return}process.stderr.write(`${i} \u5DF2\u6536\u5230\u5BC6\u94A5\uFF0C\u672C\u673A\u5F55\u5165\u670D\u52A1\u5DF2\u5173\u95ED\uFF0C\u6B63\u5728\u5411\u670D\u52A1\u7AEF\u6821\u9A8C\u5E76\u7ED1\u5B9A\u672C\u673A\uFF0C\u8BF7\u7EE7\u7EED\u7B49\u5F85\u672C\u8FDB\u7A0B\u9000\u51FA\u3002
94
94
  `),Pe(s);let o=await je(s);if(!o.ok){ne(o)?re():process.stderr.write(`${i} \u672A\u80FD\u786E\u8BA4\u7ED1\u5B9A\u7ED3\u679C\uFF0C\u5DF2\u4FDD\u7559\u8FD9\u628A\u5F85\u786E\u8BA4\u7684\u5BC6\u94A5\u3002\u7F51\u7EDC\u6062\u590D\u540E\u6267\u884C\u4EFB\u610F ${l} \u547D\u4EE4\u5373\u53EF\u81EA\u52A8\u6536\u655B\u3002
95
- `),a(o);return}let d=ie({userId:o.data.user.id,agentId:o.data.agentId,companyIds:o.data.companyIds});a(h({user:o.data.user,device:o.data.device,companyIds:(m=d==null?void 0:d.companyIds)!=null?m:o.data.companyIds,replacedPreviousAuthorization:o.data.replacedPreviousAuthorization,configPath:w()},o.requestId))}async function Ke(){let e=await V();if(e){a(e);return}let t=$();if(!t){a(Be());return}let n=await y("/companies",{apiKey:t,query:{page:1,limit:100}});if(!n.ok){a(n);return}let r=H();a(h({loggedIn:!0,device:{deviceId:r.deviceId,deviceName:r.deviceName,platform:r.platform},user:J()?{id:J().userId,agentId:J().agentId}:null,companies:n.data.data.map(i=>({id:i.id,name:i.name})),configPath:w()},n.requestId))}async function Fe(){let e=await V();if(e){a(e);return}let t=$();if(!t){a(Be());return}let n=await y("/auth/logout",{method:"POST",apiKey:t});if(!n.ok){a(n);return}De(),a(h({loggedOut:!0,revoked:n.data,note:"\u670D\u52A1\u7AEF\u5BC6\u94A5\u5DF2\u64A4\u9500\uFF0C\u672C\u673A\u51ED\u636E\u5DF2\u6E05\u9664\u3002\u8BBE\u5907\u8EAB\u4EFD\u4FDD\u7559\uFF0C\u91CD\u65B0\u767B\u5F55\u4F1A\u590D\u7528\u540C\u4E00\u53F0\u8BBE\u5907\u3002"},n.requestId))}function Be(){return c("AUTH_REQUIRED","\u672C\u673A\u8FD8\u6CA1\u6709\u53EF\u7528\u7684\u6388\u6743",{nextAction:{type:"auth_login",message:"\u5148\u8BA9\u7528\u6237\u5230\u6240\u5C5E SaaS \u7F51\u9875\u7684\u5BC6\u94A5\u7BA1\u7406\u91CC\u521B\u5EFA\u300CAI \u52A9\u624B\u5BC6\u94A5\u300D\u5E76\u9009\u597D\u6388\u6743\u516C\u53F8\uFF1B\u7136\u540E\u7531\u4F60\u76F4\u63A5\u6267\u884C command\uFF0C\u5B83\u4F1A\u963B\u585E\u6700\u957F 5 \u5206\u949F\u7B49\u5F85\u7528\u6237\u5728\u672C\u673A\u9875\u9762\u7C98\u8D34\u5BC6\u94A5\u3002\u6267\u884C\u671F\u95F4\u628A stderr \u91CC\u7684\u672C\u5730\u9875\u9762\u5730\u5740\u8F6C\u8FBE\u7ED9\u7528\u6237\uFF0C\u4FDD\u6301\u8FDB\u7A0B\u8FD0\u884C\u76F4\u5230\u5B83\u81EA\u884C\u9000\u51FA\uFF0C\u4E0D\u8981\u4E2D\u65AD\uFF0C\u4E5F\u4E0D\u8981\u8BA9\u7528\u6237\u5728\u522B\u5904\u6267\u884C\u3002",command:`${l} auth login`}})}function je(e){let t=H();return y("/auth/claim",{method:"POST",apiKey:e,body:{...t,cliVersion:E}})}function Dt(e){if(process.env.BEST_GEO_NO_BROWSER==="1")return;let t=process.platform==="darwin"?"open":process.platform==="win32"?"cmd":"xdg-open",n=process.platform==="win32"?["/c","start","",e]:[e];(0,Ve.execFile)(t,n,()=>{})}function Lt(e){return e instanceof Error?e.message:String(e)}async function q(){let e=await V();if(e)return{ok:!1,envelope:e};let t=$();return t?{ok:!0,apiKey:t}:{ok:!1,envelope:c("AUTH_REQUIRED","\u672C\u673A\u8FD8\u6CA1\u6709\u53EF\u7528\u7684\u6388\u6743",{nextAction:{type:"auth_login",message:"\u5148\u8BA9\u7528\u6237\u5230\u6240\u5C5E SaaS \u7F51\u9875\u7684\u5BC6\u94A5\u7BA1\u7406\u91CC\u521B\u5EFA\u300CAI \u52A9\u624B\u5BC6\u94A5\u300D\u5E76\u9009\u597D\u6388\u6743\u516C\u53F8\uFF1B\u7136\u540E\u7531\u4F60\u76F4\u63A5\u6267\u884C command\uFF0C\u5B83\u4F1A\u963B\u585E\u6700\u957F 5 \u5206\u949F\u7B49\u5F85\u7528\u6237\u5728\u672C\u673A\u9875\u9762\u7C98\u8D34\u5BC6\u94A5\u3002",command:`${l} auth login`}})}}var He=require("node:fs"),N=require("node:path"),Je=require("node:url");function Ut(e){if(e.cjsDir)return(0,N.join)(e.cjsDir,"..");if(!e.moduleUrl)throw new Error("\u7F3A\u5C11 CLI \u8FD0\u884C\u4F4D\u7F6E");return(0,N.join)((0,N.dirname)((0,Je.fileURLToPath)(e.moduleUrl)),"..","..","..")}function Mt(){return Ut({cjsDir:typeof __dirname=="string"?__dirname:void 0,moduleUrl:void 0})}function T(...e){return(0,He.readFileSync)((0,N.join)(Mt(),...e),"utf8")}function ze(){a(h({package:O,version:E,protocolVersion:D,commands:[{command:`${l} version --check`,description:"\u68C0\u67E5\u7248\u672C\u662F\u5426\u9700\u8981\u5347\u7EA7"},{command:`${l} capabilities`,description:"\u5217\u51FA\u53EF\u7528\u80FD\u529B\u53CA\u5176\u8F93\u5165 schema"},{command:`${l} skill get --raw > <\u4F60\u7684 skill \u76EE\u5F55>/best-geo/SKILL.md`,description:"\u76F4\u63A5\u628A Skill \u5199\u6210\u6587\u4EF6\uFF08\u63A8\u8350\uFF1B--raw \u8F93\u51FA markdown \u539F\u6587\uFF0C\u4E0D\u662F JSON\uFF09"},{command:`${l} skill get`,description:"\u4EE5 JSON \u4FE1\u5C01\u8FD4\u56DE Skill \u5185\u5BB9\u548C revision"},{command:`${l} guide list`,description:"\u5217\u51FA\u4E1A\u52A1\u6307\u5357"},{command:`${l} guide get <name>`,description:"\u8BFB\u53D6\u4E00\u4EFD\u4E1A\u52A1\u6307\u5357"},{command:`${l} auth login`,description:"\u6253\u5F00\u672C\u5730\u9875\u9762\u5F55\u5165\u5BC6\u94A5\u5E76\u7ED1\u5B9A\u672C\u673A"},{command:`${l} auth status`,description:"\u67E5\u770B\u5F53\u524D\u6388\u6743\u72B6\u6001"},{command:`${l} auth logout`,description:"\u64A4\u9500\u670D\u52A1\u7AEF\u5BC6\u94A5\u5E76\u6E05\u9664\u672C\u673A\u51ED\u636E"},{command:`${l} call <capability> --input '<JSON>'`,description:"\u8C03\u7528\u4E00\u4E2A\u67E5\u8BE2\u80FD\u529B"},{command:`${l} plan <operation> --input '<JSON>'`,description:"\u751F\u6210\u5199\u64CD\u4F5C\u8BA1\u5212\uFF0C\u8FD4\u56DE\u7ED9\u7528\u6237\u770B\u7684\u53D8\u66F4\u6458\u8981\uFF08\u4E0D\u5199\u6570\u636E\uFF09"},{command:`${l} apply <planId>`,description:"\u6267\u884C\u8BA1\u5212\u3002\u5FC5\u987B\u5148\u628A plan \u7684\u6458\u8981\u7ED9\u7528\u6237\u770B\u8FC7\u5E76\u5F97\u5230\u540C\u610F"}],nextAction:{type:"install_skill",command:`${l} skill get --raw`,message:"\u6309\u5F53\u524D AI \u5DE5\u5177\u7684 Skill \u673A\u5236\u9009\u4E00\u4E2A\u5B89\u88C5\u76EE\u5F55\uFF0C\u7528 best-geo skill get --raw \u628A\u5185\u5BB9\u76F4\u63A5\u91CD\u5B9A\u5411\u6210 SKILL.md\uFF0C\u7136\u540E\u52A0\u8F7D\u5B83"}}))}async function Qe(e){if(!e){a(h({package:O,version:E,protocolVersion:D,env:Ae,apiBase:B}));return}let t=await y("/meta");if(!t.ok){a(t);return}if(Ge(E,t.data.minimumCliVersion)<0){a(c("CLI_UPDATE_REQUIRED",`\u5F53\u524D\u7248\u672C ${E} \u4F4E\u4E8E\u6700\u4F4E\u8981\u6C42 ${t.data.minimumCliVersion}`,{requestId:t.requestId,data:{current:E,...t.data},nextAction:{type:"upgrade",message:"\u5347\u7EA7\u540E\u91CD\u8BD5",command:`npm install -g ${O}@latest`}}));return}a(h({current:E,...t.data,updateAvailable:Ge(E,t.data.latestCliVersion)<0},t.requestId))}function Xe(){a(h(JSON.parse(T("capabilities","capabilities.json"))))}function We(e){let t=et(T("skills","best-geo","SKILL.md"));if(e){process.stdout.write(t);return}a(h({name:l,revision:1,content:t}))}var oe=["company","product","question","article","knowledge","material","question-task","article-task","scheduled-monitor","publication"];function Ye(){a(h({guides:oe.map(e=>{let t=JSON.parse(T("guides",`${e}.json`));return{name:t.name,title:t.title,whenToUse:t.whenToUse}})}))}function Ze(e){if(!oe.includes(e)){a(c("GUIDE_NOT_FOUND",`\u6CA1\u6709\u540D\u4E3A ${e} \u7684\u6307\u5357`,{data:{available:oe}}));return}a(h(JSON.parse(et(T("guides",`${e}.json`)))))}function Ge(e,t){var i,s;let n=e.split(".").map(o=>Number.parseInt(o,10)||0),r=t.split(".").map(o=>Number.parseInt(o,10)||0);for(let o=0;o<Math.max(n.length,r.length);o+=1){let d=((i=n[o])!=null?i:0)-((s=r[o])!=null?s:0);if(d!==0)return d<0?-1:1}return 0}function et(e){return l==="best-geo"?e:e.replace(/\bbest-geo\b(?!-)/g,l)}var se=null,ae=null;function tt(){return se===null&&(se=JSON.parse(T("capabilities","capabilities.json")).capabilities),se}function Vt(){return ae===null&&(ae=new Map(tt().filter(e=>e.inputSchema!==void 0).map(e=>[e.name,e.inputSchema]))),ae}function nt(){return tt().filter(e=>e.mode==="write").map(e=>e.name)}function z(e,t){let n=Vt().get(e);return n===void 0?[]:ue(t,n,"")}function ue(e,t,n){if(t.type==="object"||t.properties!==void 0)return qt(e,t,n);let r=rt(e,t,n);if(r!==null)return[r];let i=[];return typeof e=="string"&&t.maxLength!==void 0&&e.length>t.maxLength&&i.push(`${n} \u6700\u591A ${t.maxLength} \u4E2A\u5B57\u7B26\uFF0C\u5F53\u524D ${e.length} \u4E2A`),typeof e=="number"&&(t.maximum!==void 0&&e>t.maximum&&i.push(`${n} \u4E0D\u80FD\u5927\u4E8E ${t.maximum}`),t.minimum!==void 0&&e<t.minimum&&i.push(`${n} \u4E0D\u80FD\u5C0F\u4E8E ${t.minimum}`)),t.enum!==void 0&&!t.enum.includes(e)&&i.push(`${n} \u53EA\u80FD\u662F ${t.enum.join(" / ")} \u4E4B\u4E00\uFF0C\u6536\u5230 ${C(e)}`),Array.isArray(e)&&(t.minItems!==void 0&&e.length<t.minItems&&i.push(`${n} \u81F3\u5C11\u8981 ${t.minItems} \u9879\uFF0C\u5F53\u524D ${e.length} \u9879`),t.maxItems!==void 0&&e.length>t.maxItems&&i.push(`${n} \u6700\u591A ${t.maxItems} \u9879\uFF0C\u5F53\u524D ${e.length} \u9879`),t.items!==void 0&&e.forEach((s,o)=>{i.push(...ue(s,t.items,`${n}[${o}]`))})),i}function qt(e,t,n){var d,m;if(typeof e!="object"||e===null||Array.isArray(e))return[`${n||"\u5165\u53C2"} \u5FC5\u987B\u662F\u5BF9\u8C61`];let r=e,i=(d=t.properties)!=null?d:{},s=(m=t.required)!=null?m:[],o=[];for(let u of s)(r[u]===void 0||r[u]===null)&&o.push(`\u7F3A\u5C11\u5FC5\u586B\u5B57\u6BB5 ${ce(n,u)}`);if(t.additionalProperties===!1){let u=Object.keys(i);for(let b of Object.keys(r))u.includes(b)||o.push(`\u4E0D\u8BA4\u8BC6\u7684\u5B57\u6BB5 ${ce(n,b)}\uFF0C\u53EF\u7528\u5B57\u6BB5\uFF1A${u.join("\u3001")}`)}for(let[u,b]of Object.entries(i)){let k=r[u];k===void 0||k===null&&s.includes(u)||o.push(...ue(k,b,ce(n,u)))}return o}function rt(e,t,n){if(Array.isArray(t.type)){let r=t.type.map(i=>rt(e,{...t,type:i},n));return r.some(i=>i===null)?null:r[0]}switch(t.type){case"null":return e===null?null:`${n} \u5FC5\u987B\u662F null\uFF0C\u6536\u5230 ${C(e)}`;case"string":return typeof e=="string"?null:`${n} \u5FC5\u987B\u662F\u5B57\u7B26\u4E32\uFF0C\u6536\u5230 ${C(e)}`;case"number":return typeof e=="number"&&Number.isFinite(e)?null:`${n} \u5FC5\u987B\u662F\u6570\u5B57\uFF0C\u6536\u5230 ${C(e)}`;case"integer":return typeof e=="number"&&Number.isInteger(e)?null:`${n} \u5FC5\u987B\u662F\u6574\u6570\uFF0C\u6536\u5230 ${C(e)}`;case"boolean":return typeof e=="boolean"?null:`${n} \u5FC5\u987B\u662F true \u6216 false\uFF0C\u6536\u5230 ${C(e)}`;case"array":return Array.isArray(e)?null:`${n} \u5FC5\u987B\u662F\u6570\u7EC4\uFF0C\u6536\u5230 ${C(e)}`;default:return null}}function ce(e,t){return e===""?t:`${e}.${t}`}function C(e){if(e===null)return"null";if(Array.isArray(e))return"\u6570\u7EC4";if(typeof e=="object")return"\u5BF9\u8C61";let t=String(e);return typeof e=="string"?`\u5B57\u7B26\u4E32 "${Kt(t)}"`:t}function Kt(e){return e.length>20?`${e.slice(0,20)}\u2026`:e}function Q(e,t){return c("VALIDATION_FAILED",`\u5165\u53C2\u4E0D\u5408\u6CD5\uFF1A${t.join("\uFF1B")}`,{data:{name:e,errors:t},nextAction:{type:"ask_user",message:"\u6309 capabilities \u91CC\u7684 inputSchema \u4FEE\u6B63\u53C2\u6570\u540E\u91CD\u8BD5\uFF1B\u7F3A\u7684\u4FE1\u606F\u95EE\u7528\u6237"}})}var it={"companies.list":e=>({path:"/companies",query:e}),"companies.get":e=>({path:`/companies/${Number(e.id)}`}),"products.list":e=>({path:"/products",query:e}),"products.get":e=>({path:`/products/${Number(e.id)}`}),"questions.list":e=>({path:"/questions",query:e}),"questions.get":e=>({path:`/questions/${Number(e.id)}`}),"articles.list":e=>({path:"/articles",query:e}),"articles.get":e=>({path:`/articles/${Number(e.id)}`,query:e.withContent===!0?{withContent:"true"}:void 0}),"knowledge.list":e=>({path:"/knowledge",query:e}),"knowledge.get":e=>({path:`/knowledge/${Number(e.id)}`}),"images.list":e=>({path:"/images",query:e}),"images.get":e=>({path:`/images/${Number(e.id)}`}),"videos.list":e=>({path:"/videos",query:e}),"videos.get":e=>({path:`/videos/${Number(e.id)}`}),"prompts.list":e=>({path:"/prompts",query:e}),"models.list":e=>({path:"/models",query:e}),"questionTasks.list":e=>({path:"/question-tasks",query:e}),"questionTasks.get":e=>({path:`/question-tasks/${Number(e.taskId)}`}),"articleTasks.list":e=>({path:"/article-tasks",query:e}),"articleTasks.get":e=>({path:`/article-tasks/${Number(e.taskId)}`}),"keywordTasks.list":e=>({path:"/keyword-tasks",query:e}),"keywordTasks.get":e=>({path:`/keyword-tasks/${Number(e.taskId)}`}),"tags.list":e=>({path:"/tags",query:e}),"folders.list":e=>({path:"/article-folders",query:e}),"publicationPlatforms.list":e=>({path:"/publication-platforms",query:e}),"publicationAccounts.list":e=>({path:"/publication-accounts",query:e}),"publicationTasks.list":e=>({path:"/publication-tasks",query:e}),"publicationRecords.list":e=>({path:"/publication-records",query:e}),"mediaPlatforms.list":e=>({path:"/media-platforms",query:e}),"mediaPlatforms.get":e=>({path:`/media-platforms/${Number(e.mediaId)}`}),"mediaPublications.list":e=>({path:"/media-publications",query:e}),"mediaPublications.summary":e=>({path:"/media-publications/summary",query:e}),"articleTasks.reuseConfig":e=>({path:`/article-tasks/${Number(e.taskId)}/reuse-config`}),"scheduledSentiment.generateQuestions":e=>({path:"/scheduled-sentiment/generate-questions",method:"POST",body:e}),"indexing.suggestCompetitors":e=>({path:"/suggest-competitors",method:"POST",body:e}),"indexingPlatforms.list":()=>({path:"/indexing-platforms"}),"scheduledIndexing.list":e=>({path:"/scheduled-indexing",query:e}),"scheduledIndexing.get":e=>({path:`/scheduled-indexing/${Number(e.planId)}`}),"scheduledIndexing.runs":e=>({path:`/scheduled-indexing/${Number(e.planId)}/runs`,query:I(e)}),"scheduledIndexing.metrics":e=>({path:`/scheduled-indexing/${Number(e.planId)}/metrics`,query:I(e)}),"scheduledSentiment.list":e=>({path:"/scheduled-sentiment",query:e}),"scheduledSentiment.get":e=>({path:`/scheduled-sentiment/${Number(e.planId)}`}),"scheduledSentiment.runs":e=>({path:`/scheduled-sentiment/${Number(e.planId)}/runs`,query:I(e)}),"scheduledSentiment.metrics":e=>({path:`/scheduled-sentiment/${Number(e.planId)}/metrics`,query:I(e)}),"scheduledIndexing.answers":e=>({path:`/scheduled-indexing/${Number(e.planId)}/answers`,query:I(e)}),"scheduledIndexing.citations":e=>({path:`/scheduled-indexing/${Number(e.planId)}/citations`,query:I(e)}),"scheduledIndexing.topicStats":e=>({path:`/scheduled-indexing/${Number(e.planId)}/topic-stats`,query:I(e)}),"scheduledIndexing.topicPlatformMatrix":e=>({path:`/scheduled-indexing/${Number(e.planId)}/topic-platform-matrix`,query:I(e)}),"scheduledSentiment.answers":e=>({path:`/scheduled-sentiment/${Number(e.planId)}/answers`,query:I(e)}),"scheduledSentiment.citations":e=>({path:`/scheduled-sentiment/${Number(e.planId)}/citations`,query:I(e)}),"scheduledSentiment.topicStats":e=>({path:`/scheduled-sentiment/${Number(e.planId)}/topic-stats`,query:I(e)})};function I(e){let{planId:t,...n}=e;return n}function Ft(){return Object.keys(it)}async function ot(e,t){let n=it[e];if(!n){a(c("VALIDATION_FAILED",`\u672A\u77E5\u80FD\u529B\uFF1A${e}`,{data:{available:Ft()},nextAction:{type:"ask_user",message:"\u5148\u6267\u884C best-geo capabilities \u67E5\u770B\u53EF\u7528\u80FD\u529B"}}));return}let r={};if(t)try{r=JSON.parse(t)}catch{a(c("VALIDATION_FAILED","--input \u4E0D\u662F\u5408\u6CD5 JSON"));return}let i=z(e,r);if(i.length>0){a(Q(e,i));return}let s=await q();if(!s.ok){a(s.envelope);return}let{path:o,query:d,method:m,body:u}=n(r);a(await y(o,{apiKey:s.apiKey,query:d,method:m,body:u}))}var R=require("node:fs"),P=require("node:path");var Bt={image:{maxBytes:2*1024*1024,extensions:[".png",".jpg",".jpeg"],label:"\u56FE\u7247"},video:{maxBytes:200*1024*1024,extensions:[".mp4"],label:"\u89C6\u9891"},thumbnail:{maxBytes:5*1024*1024,extensions:[".png",".jpg",".jpeg"],label:"\u5C01\u9762\u56FE"}},jt={".png":"image/png",".jpg":"image/jpeg",".jpeg":"image/jpeg",".mp4":"video/mp4"},st={"images.create":[{pathKey:"filePath",metaKey:"file",uploadField:"fileUrl",kind:"image"}],"videos.create":[{pathKey:"videoPath",metaKey:"video",uploadField:"videoUrl",kind:"video"},{pathKey:"thumbnailPath",metaKey:"thumbnail",uploadField:"thumbnail",kind:"thumbnail"}]},Gt=900*1e3;function at(e){return st[e]!==void 0}function ct(e){return M()[e]!==void 0}function ut(e,t){var s;let n=(s=st[e])!=null?s:[],r={...t},i={};for(let o of n){let d=t[o.pathKey];if(typeof d!="string"||!d.trim())return{ok:!1,envelope:zt(o)};let m=(0,P.resolve)(d.trim()),u=Jt(m,o);if(!u.ok)return{ok:!1,envelope:u.envelope};delete r[o.pathKey],r[o.metaKey]={name:(0,P.basename)(m),size:u.size},i[o.uploadField]=m}return{ok:!0,input:r,paths:i}}function dt(e,t){te({...M(),[e]:{paths:t,createdAt:Date.now()}})}async function lt(e,t){let n=M()[e];if(!n)return{ok:!1,envelope:c("VALIDATION_FAILED","\u672C\u673A\u6CA1\u6709\u8FD9\u4E2A\u8BA1\u5212\u7684\u5F85\u4F20\u6587\u4EF6\u8BB0\u5F55",{nextAction:{type:"ask_user",message:"\u91CD\u65B0\u6267\u884C best-geo plan \u751F\u6210\u8BA1\u5212\uFF0C\u628A\u6458\u8981\u7ED9\u7528\u6237\u786E\u8BA4\u540E\u518D apply\u2014\u2014\u8BA1\u5212\u548C\u5F85\u4F20\u6587\u4EF6\u662F\u4E00\u8D77\u751F\u6210\u7684"}})};let r={};for(let[i,s]of Object.entries(n.paths)){if(!(0,R.existsSync)(s))return{ok:!1,envelope:c("VALIDATION_FAILED",`\u6587\u4EF6\u5DF2\u7ECF\u4E0D\u5728\u4E86\uFF1A${s}`)};let o=await y(`/plans/${encodeURIComponent(e)}/uploads/presign`,{method:"POST",apiKey:t,body:{field:i,fileName:(0,P.basename)(s)}});if(!o.ok)return{ok:!1,envelope:o};let d=await Ht(o.data,s);if(!d.ok)return{ok:!1,envelope:d.envelope};r[i]=o.data.uploadUrl}return{ok:!0,uploads:r}}function pt(e){let t=M();delete t[e],te(t)}async function Ht(e,t){let n=jt[mt(t)];if(!n)return{ok:!1,envelope:c("UPLOAD_FAILED",`${t} \u7684\u6587\u4EF6\u7C7B\u578B\u6CA1\u6709\u767B\u8BB0 MIME\uFF0C\u4F20\u4E0D\u4E86`)};let r=new FormData;r.append("key",e.key),r.append("policy",e.policy),r.append("OSSAccessKeyId",e.OSSAccessKeyId),r.append("signature",e.signature),r.append("callback",e.callback),r.append("Content-Disposition",e["Content-Disposition"]),r.append("success_action_status","200"),r.append("file",await(0,R.openAsBlob)(t,{type:n}),(0,P.basename)(t));try{let i=await fetch(e.host,{method:"POST",body:r,signal:AbortSignal.timeout(Gt)}),s=(await i.text().catch(()=>"")).slice(0,300);if(!i.ok)return{ok:!1,envelope:c("UPLOAD_FAILED",`\u4E0A\u4F20\u5931\u8D25\uFF08HTTP ${i.status}\uFF09\uFF1A${s}`,{nextAction:{type:"ask_user",message:"\u628A\u8FD9\u4E2A\u60C5\u51B5\u544A\u8BC9\u7528\u6237\uFF0C\u7A0D\u540E\u91CD\u65B0\u6267\u884C\u4E00\u6B21 plan \u518D\u8BD5"}})};let o=Qt(s);return o?{ok:!1,envelope:c("UPLOAD_FAILED",`\u6587\u4EF6\u5DF2\u4E0A\u4F20\uFF0C\u4F46\u767B\u8BB0\u5931\u8D25\uFF1A${o}`,{nextAction:{type:"ask_user",message:"\u628A\u8FD9\u53E5\u62A5\u9519\u539F\u6837\u544A\u8BC9\u7528\u6237\uFF0C\u8BA9\u4ED6\u8054\u7CFB\u670D\u52A1\u5546\u3002\u91CD\u8BD5\u591A\u534A\u4E0D\u4F1A\u597D\u3002"}})}:{ok:!0}}catch(i){return{ok:!1,envelope:c("UPLOAD_FAILED",`\u4E0A\u4F20\u4E2D\u65AD\uFF1A${i instanceof Error?i.message:String(i)}`,{nextAction:{type:"ask_user",message:"\u4E0A\u4F20\u6CA1\u80FD\u5B8C\u6210\uFF0C\u539F\u56E0\u89C1\u4E0A\u9762\u7684\u62A5\u9519\u539F\u6587\u3002\u544A\u8BC9\u7528\u6237\uFF0C\u7A0D\u540E\u91CD\u65B0\u8D70\u4E00\u904D"}})}}}function Jt(e,t){let n=Bt[t.kind];if(!(0,R.existsSync)(e))return{ok:!1,envelope:c("VALIDATION_FAILED",`\u627E\u4E0D\u5230\u6587\u4EF6\uFF1A${e}`,{nextAction:{type:"ask_user",message:"\u8BA9\u7528\u6237\u786E\u8BA4\u6587\u4EF6\u8DEF\u5F84\u3002\u76F8\u5BF9\u8DEF\u5F84\u662F\u76F8\u5BF9\u4F60\u5F53\u524D\u7684\u5DE5\u4F5C\u76EE\u5F55\u7B97\u7684"}})};let r=(0,R.statSync)(e);if(!r.isFile())return{ok:!1,envelope:c("VALIDATION_FAILED",`${e} \u4E0D\u662F\u4E00\u4E2A\u6587\u4EF6`)};let i=mt(e);return n.extensions.includes(i)?r.size>n.maxBytes?{ok:!1,envelope:c("VALIDATION_FAILED",`${n.label}\u6700\u5927 ${X(n.maxBytes)}\uFF0C\u5F53\u524D ${X(r.size)}\uFF0C\u8D85\u51FA ${X(r.size-n.maxBytes)}`,{nextAction:{type:"ask_user",message:`\u544A\u8BC9\u7528\u6237\u8FD9\u4E2A\u6587\u4EF6\u8D85\u4E86\u591A\u5C11\uFF0C\u5E76\u95EE\u4ED6\u8981\u4E0D\u8981\u4F60\u5148\u628A\u5B83\u538B\u5230 ${X(n.maxBytes)} \u4EE5\u5185\u518D\u4F20\u3002\u4F60\u53EF\u4EE5\u7528\u7528\u6237\u673A\u5668\u4E0A\u73B0\u6210\u7684\u5DE5\u5177\u5904\u7406\uFF08macOS \u81EA\u5E26 sips\uFF0C\u591A\u6570\u673A\u5668\u6709 ffmpeg\uFF09\uFF0C\u5904\u7406\u5B8C\u7528\u65B0\u6587\u4EF6\u91CD\u65B0 plan\u3002`}})}:{ok:!0,size:r.size}:{ok:!1,envelope:c("VALIDATION_FAILED",`${n.label}\u53EA\u652F\u6301 ${n.extensions.join(" / ")}\uFF0C\u5F53\u524D\u662F ${i||"(\u6CA1\u6709\u6269\u5C55\u540D)"}`,{nextAction:{type:"ask_user",message:`\u628A\u8FD9\u4E2A\u9650\u5236\u544A\u8BC9\u7528\u6237\uFF0C\u95EE\u4ED6\u8981\u4E0D\u8981\u4F60\u5148\u628A\u6587\u4EF6\u8F6C\u6210 ${n.extensions[0]} \u518D\u4F20`}})}}function zt(e){return c("VALIDATION_FAILED",`\u7F3A\u5C11 ${e.pathKey}`,{nextAction:{type:"ask_user",message:`${e.pathKey} \u8981\u7ED9\u4E00\u4E2A\u672C\u673A\u6587\u4EF6\u8DEF\u5F84\u3002\u95EE\u7528\u6237\u6587\u4EF6\u653E\u5728\u54EA\uFF0C\u4E0D\u8981\u81EA\u5DF1\u7F16\u4E00\u4E2A\u8DEF\u5F84\u3002`}})}function X(e){return e>=1024*1024?`${(e/1024/1024).toFixed(1)}MB`:`${Math.max(1,Math.round(e/1024))}KB`}function Qt(e){try{let t=JSON.parse(e),n=Number(t.statusCode);if(Number.isFinite(n)&&n!==0&&n!==200)return typeof t.message=="string"?t.message:`statusCode ${n}`}catch{}return null}function mt(e){let t=e.lastIndexOf(".");return t===-1?"":e.toLowerCase().slice(t)}async function ft(e,t,n){var b;let r=nt();if(!e||!r.includes(e)){a(c("VALIDATION_FAILED",`\u672A\u77E5\u7684\u5199\u64CD\u4F5C\uFF1A${e!=null?e:"(\u7A7A)"}`,{data:{available:r},nextAction:{type:"ask_user",message:"\u5148\u6267\u884C best-geo capabilities \u67E5\u770B\u53EF\u7528\u80FD\u529B\u548C\u5B83\u4EEC\u7684\u5165\u53C2"}}));return}if(!t&&(n!=null&&n.trim().startsWith("{"))){a(c("VALIDATION_FAILED","\u5165\u53C2\u8981\u653E\u5728 --input \u540E\u9762",{nextAction:{type:"ask_user",message:`\u6B63\u786E\u5199\u6CD5\uFF1Abest-geo plan ${e} --input '<JSON>'`}}));return}let i;try{i=t?JSON.parse(t):{}}catch{a(c("VALIDATION_FAILED","--input \u4E0D\u662F\u5408\u6CD5 JSON"));return}let s=z(e,i);if(s.length>0){a(Q(e,s));return}let o=i,d=null;if(at(e)){let k=ut(e,i);if(!k.ok){a(k.envelope);return}o=k.input,d=k.paths}let m=await q();if(!m.ok){a(m.envelope);return}let u=await y("/plans",{method:"POST",apiKey:m.apiKey,body:{operation:e,input:o}});u.ok&&d&&((b=u.data)!=null&&b.planId)&&dt(u.data.planId,d),a(u)}async function gt(e){if(!e){a(c("VALIDATION_FAILED","\u7F3A\u5C11 planId",{nextAction:{type:"ask_user",message:"\u5148\u6267\u884C best-geo plan <operation> \u751F\u6210\u8BA1\u5212\uFF0C\u628A\u6458\u8981\u7ED9\u7528\u6237\u786E\u8BA4\u540E\u518D\u6267\u884C"}}));return}let t=await q();if(!t.ok){a(t.envelope);return}let n;if(ct(e)){let i=await lt(e,t.apiKey);if(!i.ok){a(i.envelope);return}n=i.uploads}let r=await y(`/plans/${encodeURIComponent(e)}/apply`,{method:"POST",apiKey:t.apiKey,body:n?{uploads:n}:{},isWrite:!0});r.ok&&pt(e),a(r)}function yt(e){let t={};for(let n=0;n<e.length;n+=1){let r=e[n];if(!r.startsWith("--"))continue;let i=r.slice(2),s=e[n+1];s&&!s.startsWith("--")?(t[i]=s,n+=1):t[i]=!0}return t}function Et(e,t){let n=w();if(e.reason==="denied")return c("HOST_PERMISSION_REQUIRED",`\u6CA1\u6709\u6743\u9650\u8BFB\u5199\u672C\u673A\u914D\u7F6E\u6587\u4EF6\uFF1A${n}`,{nextAction:{type:"request_host_approval",message:`Best GEO \u9700\u8981\u8BFB\u5199 ${n} \u6765\u4FDD\u5B58\u672C\u673A\u7684\u8BBE\u5907\u8EAB\u4EFD\u548C\u6388\u6743\u3002\u8BF7\u7528\u5F53\u524D\u5DE5\u5177\u81EA\u5E26\u7684\u6743\u9650\u786E\u8BA4\u673A\u5236\u7533\u8BF7\u5BF9\u8BE5\u6587\u4EF6\u7684\u8BFB\u5199\u6743\u9650\u540E\u91CD\u8BD5\u540C\u4E00\u6761\u547D\u4EE4\uFF0C\u4E0D\u8981\u5173\u95ED\u6574\u4E2A\u6C99\u7BB1\uFF0C\u4E5F\u4E0D\u8981\u8BA9\u7528\u6237\u628A\u5BC6\u94A5\u8D34\u8FDB\u5BF9\u8BDD\u3002`,capability:t.capability,...t.retryCommand?{command:t.retryCommand}:{}}});if(e.reason==="permissions_too_open"||e.reason==="not_owner"){let r=e.reason==="not_owner"?"\u8BE5\u6587\u4EF6\u4E0D\u5C5E\u4E8E\u5F53\u524D\u7CFB\u7EDF\u7528\u6237\uFF0C\u8BF7\u8BA9\u7528\u6237\u786E\u8BA4\u540E\u5220\u9664\u6216\u4FEE\u6B63\u5C5E\u4E3B":`\u8BF7\u8BA9\u7528\u6237\u6267\u884C\uFF1Achmod 600 ${n}`;return c("HOST_PERMISSION_REQUIRED",`\u672C\u673A\u914D\u7F6E\u6587\u4EF6\u6743\u9650\u4E0D\u5B89\u5168\uFF1A${n}`,{nextAction:{type:"ask_user",message:`${e.message}\u3002${r}\uFF0C\u7136\u540E\u91CD\u8BD5\u3002`}})}return c("HOST_PERMISSION_REQUIRED",`\u672C\u673A\u914D\u7F6E\u6587\u4EF6\u5DF2\u635F\u574F\uFF1A${n}`,{nextAction:{type:"ask_user",message:`\u8BF7\u8BA9\u7528\u6237\u5220\u9664 ${n} \u540E\u91CD\u65B0\u6267\u884C\u767B\u5F55\u3002\u8BE5\u6587\u4EF6\u91CC\u53EA\u6709\u672C\u673A\u8BBE\u5907\u8EAB\u4EFD\u548C\u6388\u6743\uFF0C\u5220\u9664\u4E0D\u4F1A\u5F71\u54CD\u670D\u52A1\u7AEF\u6570\u636E\u3002`,command:`${l} auth login`}})}function ht(e){return e instanceof A}async function Xt(){let[e,...t]=process.argv.slice(2),n=yt(t);switch(e){case void 0:case"help":ze();return;case"version":await Qe(n.check===!0);return;case"capabilities":Xe();return;case"skill":if(t[0]==="get"){We(n.raw===!0);return}break;case"guide":if(t[0]==="list"){Ye();return}if(t[0]==="get"&&t[1]){Ze(t[1]);return}break;case"auth":if(t[0]==="login")return qe();if(t[0]==="status")return Ke();if(t[0]==="logout")return Fe();break;case"plan":await ft(t[0],typeof n.input=="string"?n.input:void 0,t[1]);return;case"apply":await gt(t[0]);return;case"call":if(t[0]){await ot(t[0],typeof n.input=="string"?n.input:void 0);return}break;default:break}a(c("VALIDATION_FAILED",`\u65E0\u6CD5\u8BC6\u522B\u7684\u547D\u4EE4\uFF1A${[e,...t].filter(Boolean).join(" ")}`,{nextAction:{type:"ask_user",message:"\u6267\u884C best-geo help \u67E5\u770B\u53EF\u7528\u547D\u4EE4"}})),process.exitCode=1}Xt().catch(e=>{if(ht(e)){a(Et(e,{capability:e.reason==="denied"?"config_write":"config_read",retryCommand:Wt()})),process.exitCode=1;return}a(c("SERVER_ERROR",e instanceof Error?e.message:String(e))),process.exitCode=1});function Wt(){let[e,t]=process.argv.slice(2);if(e==="auth"&&(t==="login"||t==="status"||t==="logout"))return`${l} auth ${t}`}
95
+ `),a(o);return}let d=ie({userId:o.data.user.id,agentId:o.data.agentId,companyIds:o.data.companyIds});a(E({user:o.data.user,device:o.data.device,companyIds:(m=d==null?void 0:d.companyIds)!=null?m:o.data.companyIds,replacedPreviousAuthorization:o.data.replacedPreviousAuthorization,configPath:C()},o.requestId))}async function Ke(){let e=await V();if(e){a(e);return}let t=$();if(!t){a(Be());return}let n=await y("/companies",{apiKey:t,query:{page:1,limit:100}});if(!n.ok){a(n);return}let r=H();a(E({loggedIn:!0,device:{deviceId:r.deviceId,deviceName:r.deviceName,platform:r.platform},user:J()?{id:J().userId,agentId:J().agentId}:null,companies:n.data.data.map(i=>({id:i.id,name:i.name})),configPath:C()},n.requestId))}async function Fe(){let e=await V();if(e){a(e);return}let t=$();if(!t){a(Be());return}let n=await y("/auth/logout",{method:"POST",apiKey:t});if(!n.ok){a(n);return}De(),a(E({loggedOut:!0,revoked:n.data,note:"\u670D\u52A1\u7AEF\u5BC6\u94A5\u5DF2\u64A4\u9500\uFF0C\u672C\u673A\u51ED\u636E\u5DF2\u6E05\u9664\u3002\u8BBE\u5907\u8EAB\u4EFD\u4FDD\u7559\uFF0C\u91CD\u65B0\u767B\u5F55\u4F1A\u590D\u7528\u540C\u4E00\u53F0\u8BBE\u5907\u3002"},n.requestId))}function Be(){return c("AUTH_REQUIRED","\u672C\u673A\u8FD8\u6CA1\u6709\u53EF\u7528\u7684\u6388\u6743",{nextAction:{type:"auth_login",message:"\u5148\u8BA9\u7528\u6237\u5230\u6240\u5C5E SaaS \u7F51\u9875\u7684\u5BC6\u94A5\u7BA1\u7406\u91CC\u521B\u5EFA\u300CAI \u52A9\u624B\u5BC6\u94A5\u300D\u5E76\u9009\u597D\u6388\u6743\u516C\u53F8\uFF1B\u7136\u540E\u7531\u4F60\u76F4\u63A5\u6267\u884C command\uFF0C\u5B83\u4F1A\u963B\u585E\u6700\u957F 5 \u5206\u949F\u7B49\u5F85\u7528\u6237\u5728\u672C\u673A\u9875\u9762\u7C98\u8D34\u5BC6\u94A5\u3002\u6267\u884C\u671F\u95F4\u628A stderr \u91CC\u7684\u672C\u5730\u9875\u9762\u5730\u5740\u8F6C\u8FBE\u7ED9\u7528\u6237\uFF0C\u4FDD\u6301\u8FDB\u7A0B\u8FD0\u884C\u76F4\u5230\u5B83\u81EA\u884C\u9000\u51FA\uFF0C\u4E0D\u8981\u4E2D\u65AD\uFF0C\u4E5F\u4E0D\u8981\u8BA9\u7528\u6237\u5728\u522B\u5904\u6267\u884C\u3002",command:`${l} auth login`}})}function je(e){let t=H();return y("/auth/claim",{method:"POST",apiKey:e,body:{...t,cliVersion:h}})}function Dt(e){if(process.env.BEST_GEO_NO_BROWSER==="1")return;let t=process.platform==="darwin"?"open":process.platform==="win32"?"cmd":"xdg-open",n=process.platform==="win32"?["/c","start","",e]:[e];(0,Ve.execFile)(t,n,()=>{})}function Lt(e){return e instanceof Error?e.message:String(e)}async function q(){let e=await V();if(e)return{ok:!1,envelope:e};let t=$();return t?{ok:!0,apiKey:t}:{ok:!1,envelope:c("AUTH_REQUIRED","\u672C\u673A\u8FD8\u6CA1\u6709\u53EF\u7528\u7684\u6388\u6743",{nextAction:{type:"auth_login",message:"\u5148\u8BA9\u7528\u6237\u5230\u6240\u5C5E SaaS \u7F51\u9875\u7684\u5BC6\u94A5\u7BA1\u7406\u91CC\u521B\u5EFA\u300CAI \u52A9\u624B\u5BC6\u94A5\u300D\u5E76\u9009\u597D\u6388\u6743\u516C\u53F8\uFF1B\u7136\u540E\u7531\u4F60\u76F4\u63A5\u6267\u884C command\uFF0C\u5B83\u4F1A\u963B\u585E\u6700\u957F 5 \u5206\u949F\u7B49\u5F85\u7528\u6237\u5728\u672C\u673A\u9875\u9762\u7C98\u8D34\u5BC6\u94A5\u3002",command:`${l} auth login`}})}}var He=require("node:fs"),N=require("node:path"),Je=require("node:url");function Ut(e){if(e.cjsDir)return(0,N.join)(e.cjsDir,"..");if(!e.moduleUrl)throw new Error("\u7F3A\u5C11 CLI \u8FD0\u884C\u4F4D\u7F6E");return(0,N.join)((0,N.dirname)((0,Je.fileURLToPath)(e.moduleUrl)),"..","..","..")}function Mt(){return Ut({cjsDir:typeof __dirname=="string"?__dirname:void 0,moduleUrl:void 0})}function T(...e){return(0,He.readFileSync)((0,N.join)(Mt(),...e),"utf8")}function ze(){a(E({package:O,version:h,protocolVersion:D,commands:[{command:`${l} version --check`,description:"\u68C0\u67E5\u7248\u672C\u662F\u5426\u9700\u8981\u5347\u7EA7"},{command:`${l} capabilities`,description:"\u5217\u51FA\u53EF\u7528\u80FD\u529B\u53CA\u5176\u8F93\u5165 schema"},{command:`${l} skill get --raw > <\u4F60\u7684 skill \u76EE\u5F55>/best-geo/SKILL.md`,description:"\u76F4\u63A5\u628A Skill \u5199\u6210\u6587\u4EF6\uFF08\u63A8\u8350\uFF1B--raw \u8F93\u51FA markdown \u539F\u6587\uFF0C\u4E0D\u662F JSON\uFF09"},{command:`${l} skill get`,description:"\u4EE5 JSON \u4FE1\u5C01\u8FD4\u56DE Skill \u5185\u5BB9\u548C revision"},{command:`${l} guide list`,description:"\u5217\u51FA\u4E1A\u52A1\u6307\u5357"},{command:`${l} guide get <name>`,description:"\u8BFB\u53D6\u4E00\u4EFD\u4E1A\u52A1\u6307\u5357"},{command:`${l} auth login`,description:"\u6253\u5F00\u672C\u5730\u9875\u9762\u5F55\u5165\u5BC6\u94A5\u5E76\u7ED1\u5B9A\u672C\u673A"},{command:`${l} auth status`,description:"\u67E5\u770B\u5F53\u524D\u6388\u6743\u72B6\u6001"},{command:`${l} auth logout`,description:"\u64A4\u9500\u670D\u52A1\u7AEF\u5BC6\u94A5\u5E76\u6E05\u9664\u672C\u673A\u51ED\u636E"},{command:`${l} call <capability> --input '<JSON>'`,description:"\u8C03\u7528\u4E00\u4E2A\u67E5\u8BE2\u80FD\u529B"},{command:`${l} plan <operation> --input '<JSON>'`,description:"\u751F\u6210\u5199\u64CD\u4F5C\u8BA1\u5212\uFF0C\u8FD4\u56DE\u7ED9\u7528\u6237\u770B\u7684\u53D8\u66F4\u6458\u8981\uFF08\u4E0D\u5199\u6570\u636E\uFF09"},{command:`${l} apply <planId>`,description:"\u6267\u884C\u8BA1\u5212\u3002\u5FC5\u987B\u5148\u628A plan \u7684\u6458\u8981\u7ED9\u7528\u6237\u770B\u8FC7\u5E76\u5F97\u5230\u540C\u610F"}],nextAction:{type:"install_skill",command:`${l} skill get --raw`,message:"\u6309\u5F53\u524D AI \u5DE5\u5177\u7684 Skill \u673A\u5236\u9009\u4E00\u4E2A\u5B89\u88C5\u76EE\u5F55\uFF0C\u7528 best-geo skill get --raw \u628A\u5185\u5BB9\u76F4\u63A5\u91CD\u5B9A\u5411\u6210 SKILL.md\uFF0C\u7136\u540E\u52A0\u8F7D\u5B83"}}))}async function Qe(e){if(!e){a(E({package:O,version:h,protocolVersion:D,env:Ae,apiBase:B}));return}let t=await y("/meta");if(!t.ok){a(t);return}if(Ge(h,t.data.minimumCliVersion)<0){a(c("CLI_UPDATE_REQUIRED",`\u5F53\u524D\u7248\u672C ${h} \u4F4E\u4E8E\u6700\u4F4E\u8981\u6C42 ${t.data.minimumCliVersion}`,{requestId:t.requestId,data:{current:h,...t.data},nextAction:{type:"upgrade",message:"\u5347\u7EA7\u540E\u91CD\u8BD5",command:`npm install -g ${O}@latest`}}));return}a(E({current:h,...t.data,updateAvailable:Ge(h,t.data.latestCliVersion)<0},t.requestId))}function Xe(){a(E(JSON.parse(T("capabilities","capabilities.json"))))}function We(e){let t=et(T("skills","best-geo","SKILL.md"));if(e){process.stdout.write(t);return}a(E({name:l,revision:1,content:t}))}var oe=["company","product","question","article","knowledge","material","question-task","article-task","scheduled-monitor","publication"];function Ye(){a(E({guides:oe.map(e=>{let t=JSON.parse(T("guides",`${e}.json`));return{name:t.name,title:t.title,whenToUse:t.whenToUse}})}))}function Ze(e){if(!oe.includes(e)){a(c("GUIDE_NOT_FOUND",`\u6CA1\u6709\u540D\u4E3A ${e} \u7684\u6307\u5357`,{data:{available:oe}}));return}a(E(JSON.parse(et(T("guides",`${e}.json`)))))}function Ge(e,t){var i,s;let n=e.split(".").map(o=>Number.parseInt(o,10)||0),r=t.split(".").map(o=>Number.parseInt(o,10)||0);for(let o=0;o<Math.max(n.length,r.length);o+=1){let d=((i=n[o])!=null?i:0)-((s=r[o])!=null?s:0);if(d!==0)return d<0?-1:1}return 0}function et(e){return l==="best-geo"?e:e.replace(/\bbest-geo\b(?!-)/g,l)}var se=null,ae=null;function tt(){return se===null&&(se=JSON.parse(T("capabilities","capabilities.json")).capabilities),se}function Vt(){return ae===null&&(ae=new Map(tt().filter(e=>e.inputSchema!==void 0).map(e=>[e.name,e.inputSchema]))),ae}function nt(){return tt().filter(e=>e.mode==="write").map(e=>e.name)}function z(e,t){let n=Vt().get(e);return n===void 0?[]:ue(t,n,"")}function ue(e,t,n){if(t.type==="object"||t.properties!==void 0)return qt(e,t,n);let r=rt(e,t,n);if(r!==null)return[r];let i=[];return typeof e=="string"&&t.minLength!==void 0&&e.length<t.minLength&&i.push(t.minLength===1?`${n} \u4E0D\u80FD\u662F\u7A7A\u5B57\u7B26\u4E32`:`${n} \u81F3\u5C11 ${t.minLength} \u4E2A\u5B57\u7B26\uFF0C\u5F53\u524D ${e.length} \u4E2A`),typeof e=="string"&&t.maxLength!==void 0&&e.length>t.maxLength&&i.push(`${n} \u6700\u591A ${t.maxLength} \u4E2A\u5B57\u7B26\uFF0C\u5F53\u524D ${e.length} \u4E2A`),typeof e=="number"&&(t.maximum!==void 0&&e>t.maximum&&i.push(`${n} \u4E0D\u80FD\u5927\u4E8E ${t.maximum}`),t.minimum!==void 0&&e<t.minimum&&i.push(`${n} \u4E0D\u80FD\u5C0F\u4E8E ${t.minimum}`)),t.enum!==void 0&&!t.enum.includes(e)&&i.push(`${n} \u53EA\u80FD\u662F ${t.enum.join(" / ")} \u4E4B\u4E00\uFF0C\u6536\u5230 ${v(e)}`),Array.isArray(e)&&(t.minItems!==void 0&&e.length<t.minItems&&i.push(`${n} \u81F3\u5C11\u8981 ${t.minItems} \u9879\uFF0C\u5F53\u524D ${e.length} \u9879`),t.maxItems!==void 0&&e.length>t.maxItems&&i.push(`${n} \u6700\u591A ${t.maxItems} \u9879\uFF0C\u5F53\u524D ${e.length} \u9879`),t.items!==void 0&&e.forEach((s,o)=>{i.push(...ue(s,t.items,`${n}[${o}]`))})),i}function qt(e,t,n){var d,m;if(typeof e!="object"||e===null||Array.isArray(e))return[`${n||"\u5165\u53C2"} \u5FC5\u987B\u662F\u5BF9\u8C61`];let r=e,i=(d=t.properties)!=null?d:{},s=(m=t.required)!=null?m:[],o=[];for(let u of s)(r[u]===void 0||r[u]===null)&&o.push(`\u7F3A\u5C11\u5FC5\u586B\u5B57\u6BB5 ${ce(n,u)}`);if(t.additionalProperties===!1){let u=Object.keys(i);for(let b of Object.keys(r))u.includes(b)||o.push(`\u4E0D\u8BA4\u8BC6\u7684\u5B57\u6BB5 ${ce(n,b)}\uFF0C\u53EF\u7528\u5B57\u6BB5\uFF1A${u.join("\u3001")}`)}for(let[u,b]of Object.entries(i)){let k=r[u];k===void 0||k===null&&s.includes(u)||o.push(...ue(k,b,ce(n,u)))}return o}function rt(e,t,n){if(Array.isArray(t.type)){let r=t.type.map(i=>rt(e,{...t,type:i},n));return r.some(i=>i===null)?null:r[0]}switch(t.type){case"null":return e===null?null:`${n} \u5FC5\u987B\u662F null\uFF0C\u6536\u5230 ${v(e)}`;case"string":return typeof e=="string"?null:`${n} \u5FC5\u987B\u662F\u5B57\u7B26\u4E32\uFF0C\u6536\u5230 ${v(e)}`;case"number":return typeof e=="number"&&Number.isFinite(e)?null:`${n} \u5FC5\u987B\u662F\u6570\u5B57\uFF0C\u6536\u5230 ${v(e)}`;case"integer":return typeof e=="number"&&Number.isInteger(e)?null:`${n} \u5FC5\u987B\u662F\u6574\u6570\uFF0C\u6536\u5230 ${v(e)}`;case"boolean":return typeof e=="boolean"?null:`${n} \u5FC5\u987B\u662F true \u6216 false\uFF0C\u6536\u5230 ${v(e)}`;case"array":return Array.isArray(e)?null:`${n} \u5FC5\u987B\u662F\u6570\u7EC4\uFF0C\u6536\u5230 ${v(e)}`;default:return null}}function ce(e,t){return e===""?t:`${e}.${t}`}function v(e){if(e===null)return"null";if(Array.isArray(e))return"\u6570\u7EC4";if(typeof e=="object")return"\u5BF9\u8C61";let t=String(e);return typeof e=="string"?`\u5B57\u7B26\u4E32 "${Kt(t)}"`:t}function Kt(e){return e.length>20?`${e.slice(0,20)}\u2026`:e}function Q(e,t){return c("VALIDATION_FAILED",`\u5165\u53C2\u4E0D\u5408\u6CD5\uFF1A${t.join("\uFF1B")}`,{data:{name:e,errors:t},nextAction:{type:"ask_user",message:"\u6309 capabilities \u91CC\u7684 inputSchema \u4FEE\u6B63\u53C2\u6570\u540E\u91CD\u8BD5\uFF1B\u7F3A\u7684\u4FE1\u606F\u95EE\u7528\u6237"}})}var it={"companies.list":e=>({path:"/companies",query:e}),"companies.get":e=>({path:`/companies/${Number(e.id)}`}),"products.list":e=>({path:"/products",query:e}),"products.get":e=>({path:`/products/${Number(e.id)}`}),"questions.list":e=>({path:"/questions",query:e}),"questions.get":e=>({path:`/questions/${Number(e.id)}`}),"articles.list":e=>({path:"/articles",query:e}),"articles.get":e=>({path:`/articles/${Number(e.id)}`,query:e.withContent===!0?{withContent:"true"}:void 0}),"knowledge.list":e=>({path:"/knowledge",query:e}),"knowledge.get":e=>({path:`/knowledge/${Number(e.id)}`}),"images.list":e=>({path:"/images",query:e}),"images.get":e=>({path:`/images/${Number(e.id)}`}),"videos.list":e=>({path:"/videos",query:e}),"videos.get":e=>({path:`/videos/${Number(e.id)}`}),"prompts.list":e=>({path:"/prompts",query:e}),"models.list":e=>({path:"/models",query:e}),"questionTasks.list":e=>({path:"/question-tasks",query:e}),"questionTasks.get":e=>({path:`/question-tasks/${Number(e.taskId)}`}),"articleTasks.list":e=>({path:"/article-tasks",query:e}),"articleTasks.get":e=>({path:`/article-tasks/${Number(e.taskId)}`}),"keywordTasks.list":e=>({path:"/keyword-tasks",query:e}),"keywordTasks.get":e=>({path:`/keyword-tasks/${Number(e.taskId)}`}),"tags.list":e=>({path:"/tags",query:e}),"folders.list":e=>({path:"/article-folders",query:e}),"publicationPlatforms.list":e=>({path:"/publication-platforms",query:e}),"publicationAccounts.list":e=>({path:"/publication-accounts",query:e}),"publicationTasks.list":e=>({path:"/publication-tasks",query:e}),"publicationRecords.list":e=>({path:"/publication-records",query:e}),"mediaPlatforms.list":e=>({path:"/media-platforms",query:e}),"mediaPlatforms.get":e=>({path:`/media-platforms/${Number(e.mediaId)}`}),"mediaPublications.list":e=>({path:"/media-publications",query:e}),"mediaPublications.summary":e=>({path:"/media-publications/summary",query:e}),"articleTasks.reuseConfig":e=>({path:`/article-tasks/${Number(e.taskId)}/reuse-config`}),"scheduledSentiment.generateQuestions":e=>({path:"/scheduled-sentiment/generate-questions",method:"POST",body:e}),"indexing.suggestCompetitors":e=>({path:"/suggest-competitors",method:"POST",body:e}),"indexingPlatforms.list":()=>({path:"/indexing-platforms"}),"scheduledIndexing.list":e=>({path:"/scheduled-indexing",query:e}),"scheduledIndexing.get":e=>({path:`/scheduled-indexing/${Number(e.planId)}`}),"scheduledIndexing.runs":e=>({path:`/scheduled-indexing/${Number(e.planId)}/runs`,query:I(e)}),"scheduledIndexing.metrics":e=>({path:`/scheduled-indexing/${Number(e.planId)}/metrics`,query:I(e)}),"scheduledSentiment.list":e=>({path:"/scheduled-sentiment",query:e}),"scheduledSentiment.get":e=>({path:`/scheduled-sentiment/${Number(e.planId)}`}),"scheduledSentiment.runs":e=>({path:`/scheduled-sentiment/${Number(e.planId)}/runs`,query:I(e)}),"scheduledSentiment.metrics":e=>({path:`/scheduled-sentiment/${Number(e.planId)}/metrics`,query:I(e)}),"scheduledIndexing.answers":e=>({path:`/scheduled-indexing/${Number(e.planId)}/answers`,query:I(e)}),"scheduledIndexing.citations":e=>({path:`/scheduled-indexing/${Number(e.planId)}/citations`,query:I(e)}),"scheduledIndexing.topicStats":e=>({path:`/scheduled-indexing/${Number(e.planId)}/topic-stats`,query:I(e)}),"scheduledIndexing.topicPlatformMatrix":e=>({path:`/scheduled-indexing/${Number(e.planId)}/topic-platform-matrix`,query:I(e)}),"scheduledSentiment.answers":e=>({path:`/scheduled-sentiment/${Number(e.planId)}/answers`,query:I(e)}),"scheduledSentiment.citations":e=>({path:`/scheduled-sentiment/${Number(e.planId)}/citations`,query:I(e)}),"scheduledSentiment.topicStats":e=>({path:`/scheduled-sentiment/${Number(e.planId)}/topic-stats`,query:I(e)})};function I(e){let{planId:t,...n}=e;return n}function Ft(){return Object.keys(it)}async function ot(e,t){let n=it[e];if(!n){a(c("VALIDATION_FAILED",`\u672A\u77E5\u80FD\u529B\uFF1A${e}`,{data:{available:Ft()},nextAction:{type:"ask_user",message:"\u5148\u6267\u884C best-geo capabilities \u67E5\u770B\u53EF\u7528\u80FD\u529B"}}));return}let r={};if(t)try{r=JSON.parse(t)}catch{a(c("VALIDATION_FAILED","--input \u4E0D\u662F\u5408\u6CD5 JSON"));return}let i=z(e,r);if(i.length>0){a(Q(e,i));return}let s=await q();if(!s.ok){a(s.envelope);return}let{path:o,query:d,method:m,body:u}=n(r);a(await y(o,{apiKey:s.apiKey,query:d,method:m,body:u}))}var R=require("node:fs"),P=require("node:path");var Bt={image:{maxBytes:2*1024*1024,extensions:[".png",".jpg",".jpeg"],label:"\u56FE\u7247"},video:{maxBytes:200*1024*1024,extensions:[".mp4"],label:"\u89C6\u9891"},thumbnail:{maxBytes:5*1024*1024,extensions:[".png",".jpg",".jpeg"],label:"\u5C01\u9762\u56FE"}},jt={".png":"image/png",".jpg":"image/jpeg",".jpeg":"image/jpeg",".mp4":"video/mp4"},st={"images.create":[{pathKey:"filePath",metaKey:"file",uploadField:"fileUrl",kind:"image"}],"videos.create":[{pathKey:"videoPath",metaKey:"video",uploadField:"videoUrl",kind:"video"},{pathKey:"thumbnailPath",metaKey:"thumbnail",uploadField:"thumbnail",kind:"thumbnail"}]},Gt=900*1e3;function at(e){return st[e]!==void 0}function ct(e){return M()[e]!==void 0}function ut(e,t){var s;let n=(s=st[e])!=null?s:[],r={...t},i={};for(let o of n){let d=t[o.pathKey];if(typeof d!="string"||!d.trim())return{ok:!1,envelope:zt(o)};let m=(0,P.resolve)(d.trim()),u=Jt(m,o);if(!u.ok)return{ok:!1,envelope:u.envelope};delete r[o.pathKey],r[o.metaKey]={name:(0,P.basename)(m),size:u.size},i[o.uploadField]=m}return{ok:!0,input:r,paths:i}}function dt(e,t){te({...M(),[e]:{paths:t,createdAt:Date.now()}})}async function lt(e,t){let n=M()[e];if(!n)return{ok:!1,envelope:c("VALIDATION_FAILED","\u672C\u673A\u6CA1\u6709\u8FD9\u4E2A\u8BA1\u5212\u7684\u5F85\u4F20\u6587\u4EF6\u8BB0\u5F55",{nextAction:{type:"ask_user",message:"\u91CD\u65B0\u6267\u884C best-geo plan \u751F\u6210\u8BA1\u5212\uFF0C\u628A\u6458\u8981\u7ED9\u7528\u6237\u786E\u8BA4\u540E\u518D apply\u2014\u2014\u8BA1\u5212\u548C\u5F85\u4F20\u6587\u4EF6\u662F\u4E00\u8D77\u751F\u6210\u7684"}})};let r={};for(let[i,s]of Object.entries(n.paths)){if(!(0,R.existsSync)(s))return{ok:!1,envelope:c("VALIDATION_FAILED",`\u6587\u4EF6\u5DF2\u7ECF\u4E0D\u5728\u4E86\uFF1A${s}`)};let o=await y(`/plans/${encodeURIComponent(e)}/uploads/presign`,{method:"POST",apiKey:t,body:{field:i,fileName:(0,P.basename)(s)}});if(!o.ok)return{ok:!1,envelope:o};let d=await Ht(o.data,s);if(!d.ok)return{ok:!1,envelope:d.envelope};r[i]=o.data.uploadUrl}return{ok:!0,uploads:r}}function pt(e){let t=M();delete t[e],te(t)}async function Ht(e,t){let n=jt[mt(t)];if(!n)return{ok:!1,envelope:c("UPLOAD_FAILED",`${t} \u7684\u6587\u4EF6\u7C7B\u578B\u6CA1\u6709\u767B\u8BB0 MIME\uFF0C\u4F20\u4E0D\u4E86`)};let r=new FormData;r.append("key",e.key),r.append("policy",e.policy),r.append("OSSAccessKeyId",e.OSSAccessKeyId),r.append("signature",e.signature),r.append("callback",e.callback),r.append("Content-Disposition",e["Content-Disposition"]),r.append("success_action_status","200"),r.append("file",await(0,R.openAsBlob)(t,{type:n}),(0,P.basename)(t));try{let i=await fetch(e.host,{method:"POST",body:r,signal:AbortSignal.timeout(Gt)}),s=(await i.text().catch(()=>"")).slice(0,300);if(!i.ok)return{ok:!1,envelope:c("UPLOAD_FAILED",`\u4E0A\u4F20\u5931\u8D25\uFF08HTTP ${i.status}\uFF09\uFF1A${s}`,{nextAction:{type:"ask_user",message:"\u628A\u8FD9\u4E2A\u60C5\u51B5\u544A\u8BC9\u7528\u6237\uFF0C\u7A0D\u540E\u91CD\u65B0\u6267\u884C\u4E00\u6B21 plan \u518D\u8BD5"}})};let o=Qt(s);return o?{ok:!1,envelope:c("UPLOAD_FAILED",`\u6587\u4EF6\u5DF2\u4E0A\u4F20\uFF0C\u4F46\u767B\u8BB0\u5931\u8D25\uFF1A${o}`,{nextAction:{type:"ask_user",message:"\u628A\u8FD9\u53E5\u62A5\u9519\u539F\u6837\u544A\u8BC9\u7528\u6237\uFF0C\u8BA9\u4ED6\u8054\u7CFB\u670D\u52A1\u5546\u3002\u91CD\u8BD5\u591A\u534A\u4E0D\u4F1A\u597D\u3002"}})}:{ok:!0}}catch(i){return{ok:!1,envelope:c("UPLOAD_FAILED",`\u4E0A\u4F20\u4E2D\u65AD\uFF1A${i instanceof Error?i.message:String(i)}`,{nextAction:{type:"ask_user",message:"\u4E0A\u4F20\u6CA1\u80FD\u5B8C\u6210\uFF0C\u539F\u56E0\u89C1\u4E0A\u9762\u7684\u62A5\u9519\u539F\u6587\u3002\u544A\u8BC9\u7528\u6237\uFF0C\u7A0D\u540E\u91CD\u65B0\u8D70\u4E00\u904D"}})}}}function Jt(e,t){let n=Bt[t.kind];if(!(0,R.existsSync)(e))return{ok:!1,envelope:c("VALIDATION_FAILED",`\u627E\u4E0D\u5230\u6587\u4EF6\uFF1A${e}`,{nextAction:{type:"ask_user",message:"\u8BA9\u7528\u6237\u786E\u8BA4\u6587\u4EF6\u8DEF\u5F84\u3002\u76F8\u5BF9\u8DEF\u5F84\u662F\u76F8\u5BF9\u4F60\u5F53\u524D\u7684\u5DE5\u4F5C\u76EE\u5F55\u7B97\u7684"}})};let r=(0,R.statSync)(e);if(!r.isFile())return{ok:!1,envelope:c("VALIDATION_FAILED",`${e} \u4E0D\u662F\u4E00\u4E2A\u6587\u4EF6`)};let i=mt(e);return n.extensions.includes(i)?r.size>n.maxBytes?{ok:!1,envelope:c("VALIDATION_FAILED",`${n.label}\u6700\u5927 ${X(n.maxBytes)}\uFF0C\u5F53\u524D ${X(r.size)}\uFF0C\u8D85\u51FA ${X(r.size-n.maxBytes)}`,{nextAction:{type:"ask_user",message:`\u544A\u8BC9\u7528\u6237\u8FD9\u4E2A\u6587\u4EF6\u8D85\u4E86\u591A\u5C11\uFF0C\u5E76\u95EE\u4ED6\u8981\u4E0D\u8981\u4F60\u5148\u628A\u5B83\u538B\u5230 ${X(n.maxBytes)} \u4EE5\u5185\u518D\u4F20\u3002\u4F60\u53EF\u4EE5\u7528\u7528\u6237\u673A\u5668\u4E0A\u73B0\u6210\u7684\u5DE5\u5177\u5904\u7406\uFF08macOS \u81EA\u5E26 sips\uFF0C\u591A\u6570\u673A\u5668\u6709 ffmpeg\uFF09\uFF0C\u5904\u7406\u5B8C\u7528\u65B0\u6587\u4EF6\u91CD\u65B0 plan\u3002`}})}:{ok:!0,size:r.size}:{ok:!1,envelope:c("VALIDATION_FAILED",`${n.label}\u53EA\u652F\u6301 ${n.extensions.join(" / ")}\uFF0C\u5F53\u524D\u662F ${i||"(\u6CA1\u6709\u6269\u5C55\u540D)"}`,{nextAction:{type:"ask_user",message:`\u628A\u8FD9\u4E2A\u9650\u5236\u544A\u8BC9\u7528\u6237\uFF0C\u95EE\u4ED6\u8981\u4E0D\u8981\u4F60\u5148\u628A\u6587\u4EF6\u8F6C\u6210 ${n.extensions[0]} \u518D\u4F20`}})}}function zt(e){return c("VALIDATION_FAILED",`\u7F3A\u5C11 ${e.pathKey}`,{nextAction:{type:"ask_user",message:`${e.pathKey} \u8981\u7ED9\u4E00\u4E2A\u672C\u673A\u6587\u4EF6\u8DEF\u5F84\u3002\u95EE\u7528\u6237\u6587\u4EF6\u653E\u5728\u54EA\uFF0C\u4E0D\u8981\u81EA\u5DF1\u7F16\u4E00\u4E2A\u8DEF\u5F84\u3002`}})}function X(e){return e>=1024*1024?`${(e/1024/1024).toFixed(1)}MB`:`${Math.max(1,Math.round(e/1024))}KB`}function Qt(e){try{let t=JSON.parse(e),n=Number(t.statusCode);if(Number.isFinite(n)&&n!==0&&n!==200)return typeof t.message=="string"?t.message:`statusCode ${n}`}catch{}return null}function mt(e){let t=e.lastIndexOf(".");return t===-1?"":e.toLowerCase().slice(t)}async function ft(e,t,n){var b;let r=nt();if(!e||!r.includes(e)){a(c("VALIDATION_FAILED",`\u672A\u77E5\u7684\u5199\u64CD\u4F5C\uFF1A${e!=null?e:"(\u7A7A)"}`,{data:{available:r},nextAction:{type:"ask_user",message:"\u5148\u6267\u884C best-geo capabilities \u67E5\u770B\u53EF\u7528\u80FD\u529B\u548C\u5B83\u4EEC\u7684\u5165\u53C2"}}));return}if(!t&&(n!=null&&n.trim().startsWith("{"))){a(c("VALIDATION_FAILED","\u5165\u53C2\u8981\u653E\u5728 --input \u540E\u9762",{nextAction:{type:"ask_user",message:`\u6B63\u786E\u5199\u6CD5\uFF1Abest-geo plan ${e} --input '<JSON>'`}}));return}let i;try{i=t?JSON.parse(t):{}}catch{a(c("VALIDATION_FAILED","--input \u4E0D\u662F\u5408\u6CD5 JSON"));return}let s=z(e,i);if(s.length>0){a(Q(e,s));return}let o=i,d=null;if(at(e)){let k=ut(e,i);if(!k.ok){a(k.envelope);return}o=k.input,d=k.paths}let m=await q();if(!m.ok){a(m.envelope);return}let u=await y("/plans",{method:"POST",apiKey:m.apiKey,body:{operation:e,input:o}});u.ok&&d&&((b=u.data)!=null&&b.planId)&&dt(u.data.planId,d),a(u)}async function gt(e){if(!e){a(c("VALIDATION_FAILED","\u7F3A\u5C11 planId",{nextAction:{type:"ask_user",message:"\u5148\u6267\u884C best-geo plan <operation> \u751F\u6210\u8BA1\u5212\uFF0C\u628A\u6458\u8981\u7ED9\u7528\u6237\u786E\u8BA4\u540E\u518D\u6267\u884C"}}));return}let t=await q();if(!t.ok){a(t.envelope);return}let n;if(ct(e)){let i=await lt(e,t.apiKey);if(!i.ok){a(i.envelope);return}n=i.uploads}let r=await y(`/plans/${encodeURIComponent(e)}/apply`,{method:"POST",apiKey:t.apiKey,body:n?{uploads:n}:{},isWrite:!0});r.ok&&pt(e),a(r)}function yt(e){let t={};for(let n=0;n<e.length;n+=1){let r=e[n];if(!r.startsWith("--"))continue;let i=r.slice(2),s=e[n+1];s&&!s.startsWith("--")?(t[i]=s,n+=1):t[i]=!0}return t}function ht(e,t){let n=C();if(e.reason==="denied")return c("HOST_PERMISSION_REQUIRED",`\u6CA1\u6709\u6743\u9650\u8BFB\u5199\u672C\u673A\u914D\u7F6E\u6587\u4EF6\uFF1A${n}`,{nextAction:{type:"request_host_approval",message:`Best GEO \u9700\u8981\u8BFB\u5199 ${n} \u6765\u4FDD\u5B58\u672C\u673A\u7684\u8BBE\u5907\u8EAB\u4EFD\u548C\u6388\u6743\u3002\u8BF7\u7528\u5F53\u524D\u5DE5\u5177\u81EA\u5E26\u7684\u6743\u9650\u786E\u8BA4\u673A\u5236\u7533\u8BF7\u5BF9\u8BE5\u6587\u4EF6\u7684\u8BFB\u5199\u6743\u9650\u540E\u91CD\u8BD5\u540C\u4E00\u6761\u547D\u4EE4\uFF0C\u4E0D\u8981\u5173\u95ED\u6574\u4E2A\u6C99\u7BB1\uFF0C\u4E5F\u4E0D\u8981\u8BA9\u7528\u6237\u628A\u5BC6\u94A5\u8D34\u8FDB\u5BF9\u8BDD\u3002`,capability:t.capability,...t.retryCommand?{command:t.retryCommand}:{}}});if(e.reason==="permissions_too_open"||e.reason==="not_owner"){let r=e.reason==="not_owner"?"\u8BE5\u6587\u4EF6\u4E0D\u5C5E\u4E8E\u5F53\u524D\u7CFB\u7EDF\u7528\u6237\uFF0C\u8BF7\u8BA9\u7528\u6237\u786E\u8BA4\u540E\u5220\u9664\u6216\u4FEE\u6B63\u5C5E\u4E3B":`\u8BF7\u8BA9\u7528\u6237\u6267\u884C\uFF1Achmod 600 ${n}`;return c("HOST_PERMISSION_REQUIRED",`\u672C\u673A\u914D\u7F6E\u6587\u4EF6\u6743\u9650\u4E0D\u5B89\u5168\uFF1A${n}`,{nextAction:{type:"ask_user",message:`${e.message}\u3002${r}\uFF0C\u7136\u540E\u91CD\u8BD5\u3002`}})}return c("HOST_PERMISSION_REQUIRED",`\u672C\u673A\u914D\u7F6E\u6587\u4EF6\u5DF2\u635F\u574F\uFF1A${n}`,{nextAction:{type:"ask_user",message:`\u8BF7\u8BA9\u7528\u6237\u5220\u9664 ${n} \u540E\u91CD\u65B0\u6267\u884C\u767B\u5F55\u3002\u8BE5\u6587\u4EF6\u91CC\u53EA\u6709\u672C\u673A\u8BBE\u5907\u8EAB\u4EFD\u548C\u6388\u6743\uFF0C\u5220\u9664\u4E0D\u4F1A\u5F71\u54CD\u670D\u52A1\u7AEF\u6570\u636E\u3002`,command:`${l} auth login`}})}function Et(e){return e instanceof A}async function Xt(){let[e,...t]=process.argv.slice(2),n=yt(t);switch(e){case void 0:case"help":ze();return;case"version":await Qe(n.check===!0);return;case"capabilities":Xe();return;case"skill":if(t[0]==="get"){We(n.raw===!0);return}break;case"guide":if(t[0]==="list"){Ye();return}if(t[0]==="get"&&t[1]){Ze(t[1]);return}break;case"auth":if(t[0]==="login")return qe();if(t[0]==="status")return Ke();if(t[0]==="logout")return Fe();break;case"plan":await ft(t[0],typeof n.input=="string"?n.input:void 0,t[1]);return;case"apply":await gt(t[0]);return;case"call":if(t[0]){await ot(t[0],typeof n.input=="string"?n.input:void 0);return}break;default:break}a(c("VALIDATION_FAILED",`\u65E0\u6CD5\u8BC6\u522B\u7684\u547D\u4EE4\uFF1A${[e,...t].filter(Boolean).join(" ")}`,{nextAction:{type:"ask_user",message:"\u6267\u884C best-geo help \u67E5\u770B\u53EF\u7528\u547D\u4EE4"}})),process.exitCode=1}Xt().catch(e=>{if(Et(e)){a(ht(e,{capability:e.reason==="denied"?"config_write":"config_read",retryCommand:Wt()})),process.exitCode=1;return}a(c("SERVER_ERROR",e instanceof Error?e.message:String(e))),process.exitCode=1});function Wt(){let[e,t]=process.argv.slice(2);if(e==="auth"&&(t==="login"||t==="status"||t==="logout"))return`${l} auth ${t}`}
@@ -19,7 +19,7 @@
19
19
  "step": 2,
20
20
  "action": "用 prompts.list 查写作方向,念给用户选",
21
21
  "capability": "prompts.list",
22
- "note": "type=1 是写作方向(必选),type=2 是标题风格(可以不选,不选就让模型按问题自拟标题)。这两样在任务跑起来之后就改不了了。"
22
+ "note": "type=1 是写作方向(必选),type=2 是标题风格(可以不选,不选就让模型按问题自拟标题)。这两样在任务跑起来之后就改不了了。用户想改某条公共模板时,公共模板本身改不了——用 prompts.duplicate 复制一份到他的公司,再改副本。"
23
23
  },
24
24
  {
25
25
  "step": 3,
@@ -46,7 +46,7 @@
46
46
  "step": 7,
47
47
  "action": "要停下来用 publicationTasks.pause,改主意了用 delete",
48
48
  "capability": "publicationTasks.pause",
49
- "note": "两个都只对**还没发出去**的记录有效。已经发成功的稿子留在平台上,CLI 撤不回来——用户要撤那些,只能去各平台自己删,这一点必须说明白,别让他以为暂停就等于撤回。"
49
+ "note": "两个都只对**还没发出去**的记录有效(删除会连暂停中的一起删掉)。已经发成功的稿子留在平台上,CLI 撤不回来——用户要撤那些,只能去各平台自己删,这一点必须说明白,别让他以为暂停就等于撤回。另外建任务时费用就按记录条数扣过了,删除不改变这笔扣费,用户点删除前得知道。"
50
50
  },
51
51
  {
52
52
  "step": 8,
@@ -81,6 +81,7 @@
81
81
  "不要用列表里的媒体价格给用户报价,必须用 mediaPlatforms.get 的实时价",
82
82
  "不要给自媒体发布的失败编造原因,也不要去读 errorMessage——那个字段不存在",
83
83
  "不要把 refund_pending 说成「已退款」——那笔钱现在还在用户账外,说错了他就不会再追",
84
+ "不要拿 currentPrice 当这笔的花费念——那是媒体现在的挂牌价,实际扣了多少看 chargedAmount",
84
85
  "不要把 status 数值念给用户,用 statusLabel",
85
86
  "不要说「暂停」或「删除任务」能撤回已经发出去的稿子——撤不了",
86
87
  "不要拿未审核或没封面的文章去发布/投稿,会被拒。挑文章时就用 status=1 + mustHaveCover=true 筛掉"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "best-geo-test",
3
- "version": "0.3.2",
3
+ "version": "0.3.4",
4
4
  "description": "Best GEO CLI — 给本地 AI 助手调用的 GEO 命令行工具",
5
5
  "bin": {
6
6
  "best-geo-test": "dist/index.cjs"