@round2ai/r2-cli 1.0.11 → 1.0.12
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 +43 -14
- package/dist/README.md +43 -14
- package/dist/pages/login.html +219 -57
- package/dist/pages/xianyu-auth.html +244 -67
- package/dist/r2-cli.js +40 -38
- package/package.json +7 -4
- package/scripts/install-skills.js +28 -19
- package/skills/r2-auth/SKILL.md +31 -45
- package/skills/r2-goods/SKILL.md +104 -163
- package/skills/r2-goods/references/r2-goods-hangup.md +284 -0
- package/skills/r2-goods/references/r2-goods-listing.md +137 -0
- package/skills/r2-goods/references/r2-goods-query.md +63 -0
- package/skills/r2-shared/SKILL.md +117 -0
- package/dist/package.json +0 -61
- package/scripts/build.js +0 -176
- package/scripts/dev.js +0 -22
- package/skills/r2-cli/SKILL.md +0 -70
- /package/skills/{r2-cli → r2-shared}/_meta.json +0 -0
package/dist/r2-cli.js
CHANGED
|
@@ -1,47 +1,49 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
`;process.stdout.write(a)}finally{
|
|
3
|
+
var me=Object.defineProperty;var at=(o,t)=>()=>(o&&(t=o(o=0)),t);var ct=(o,t)=>{for(var e in t)me(o,e,{get:t[e],enumerable:!0})};var ho={};ct(ho,{UserInfoCard:()=>Re});import{Box as H,Text as G}from"ink";import{jsx as J,jsxs as V}from"react/jsx-runtime";function Re({userInfo:o,lastLogin:t,daysSinceLogin:e}){let r=o.mobile?o.mobile.replace(/(\d{3})\d{4}(\d{4})/,"$1****$2"):"-";return V(H,{flexDirection:"column",marginTop:1,borderStyle:"round",borderColor:"gray",paddingX:1,children:[J(G,{bold:!0,color:"cyan",children:"\u7528\u6237\u4FE1\u606F"}),V(H,{flexDirection:"row",marginTop:1,children:[J(H,{width:10,children:J(G,{color:"gray",children:"\u6635\u79F0"})}),J(G,{color:"yellow",children:o.nickname})]}),V(H,{flexDirection:"row",children:[J(H,{width:10,children:J(G,{color:"gray",children:"\u624B\u673A\u53F7"})}),J(G,{color:"yellow",children:r})]}),t&&V(H,{flexDirection:"column",marginTop:1,children:[V(G,{color:"gray",children:["\u6700\u540E\u767B\u5F55: ",t.toLocaleString()]}),e!==void 0&&V(G,{color:"gray",children:[" \u8DDD\u4ECA: ",e," \u5929"]})]})]})}var yo=at(()=>{"use strict"});var pt={};ct(pt,{renderComponent:()=>Bt,renderOnce:()=>wo});import Le from"react";import $t from"chalk";import{render as Oe}from"ink";import{Writable as De}from"node:stream";function wo(o){let t=$t.level;process.env.NO_COLOR||($t.level=3);try{let e=[],r=new De({write(l,w,m){e.push(Buffer.from(l)),m()}});r.isTTY=!0,r.columns=process.stdout.columns||80,r.rows=process.stdout.rows||24,Oe(o,{stdout:r,patchConsole:!1}).unmount();let s=Buffer.concat(e).toString("utf8"),a=(s.split(/\x1B\[2J\x1B\[3J\x1B\[H/).at(-1)||s).replace(/\x1B\[\?[\d;]+[hl]/g,"").trimEnd()+`
|
|
4
|
+
`;process.stdout.write(a)}finally{$t.level=t}}function Bt(o,t){wo(Le.createElement(o,t))}var rt=at(()=>{"use strict"});var Go={};ct(Go,{ShopsTable:()=>He});import{Box as T,Text as N}from"ink";import{jsx as f,jsxs as K}from"react/jsx-runtime";function Fe(o){return o.map(t=>"shopName"in t?{id:t.shopId,name:t.shopName,platform:t.platform,expiresIn:t.expiresIn}:{id:t.id,name:t.name,platform:t.thirdUserId,expiresIn:t.expiresIn})}function ze({hasPlatform:o,fillWidth:t}){return K(T,{flexDirection:"row",paddingBottom:0,children:[o&&f(T,{width:Wt,children:f(N,{bold:!0,color:"white",children:"\u5E73\u53F0"})}),f(T,{width:t,children:f(N,{bold:!0,color:"white",children:"\u5E97\u94FA\u540D"})}),f(T,{width:Ht,children:f(N,{bold:!0,color:"white",children:"ID"})}),f(T,{width:Vt,children:f(N,{bold:!0,color:"white",children:"\u72B6\u6001"})})]})}function We({shop:o,hasPlatform:t,fillWidth:e}){let r=Bo[o.platform]??o.platform;return K(T,{flexDirection:"row",children:[t&&f(T,{width:Wt,children:f(N,{color:"cyan",children:r})}),f(T,{width:e,children:f(N,{bold:!0,children:o.name})}),f(T,{width:Ht,children:f(N,{color:"gray",children:o.id})}),f(T,{width:Vt,children:f(N,{color:"green",children:"\u25CF \u6388\u6743\u4E2D"})})]})}function He({shops:o,platform:t}){let e=Fe(o),r=t==="all",n=t==="all"?"\u6240\u6709\u6388\u6743\u5E97\u94FA":`${Bo[t]??t}\u6388\u6743\u5E97\u94FA`,s=process.stdout.columns||80,i=4,a=Ht+Vt+(r?Wt:0),l=Math.max(s-i-a,20),w=a+l;return K(T,{flexDirection:"column",marginTop:1,borderStyle:"round",borderColor:"gray",paddingX:1,children:[K(T,{flexDirection:"row",children:[f(N,{bold:!0,color:"cyan",children:n}),K(N,{color:"gray",children:[" \xB7 ",e.length," \u5BB6"]})]}),K(T,{flexDirection:"column",marginTop:1,children:[f(ze,{hasPlatform:r,fillWidth:l}),f(N,{color:"gray",children:"\u2500".repeat(w)}),e.map(m=>f(We,{shop:m,hasPlatform:r,fillWidth:l},m.id))]})]})}var Bo,Wt,Ht,Vt,Jo=at(()=>{"use strict";Bo={xianyu:"\u95F2\u9C7C",douyin:"\u6296\u97F3"},Wt=8,Ht=16,Vt=10});var _o={};ct(_o,{StocksTable:()=>Ze});import{Box as I,Text as b}from"ink";import{jsx as u,jsxs as Y}from"react/jsx-runtime";function Ke({fillWidth:o}){return Y(I,{flexDirection:"row",paddingBottom:0,children:[u(I,{width:Kt,children:u(b,{bold:!0,color:"white",children:"ID"})}),u(I,{width:Yt,children:u(b,{bold:!0,color:"white",children:"\u7528\u6237ID"})}),u(I,{width:Zt,children:u(b,{bold:!0,color:"white",children:"\u4ED3\u5E93ID"})}),u(I,{width:o,children:u(b,{bold:!0,color:"white",children:"\u4ED3\u5E93\u540D\u79F0"})}),u(I,{width:to,children:u(b,{bold:!0,color:"white",children:"\u521B\u5EFA\u65F6\u95F4"})})]})}function Ye({stock:o,fillWidth:t}){let e=new Date(o.gmtCreate).toLocaleString("zh-CN");return Y(I,{flexDirection:"row",children:[u(I,{width:Kt,children:u(b,{color:"gray",children:o.id})}),u(I,{width:Yt,children:u(b,{color:"gray",children:o.userId})}),u(I,{width:Zt,children:u(b,{color:"gray",children:o.stockId})}),u(I,{width:t,children:u(b,{bold:!0,children:o.stockName})}),u(I,{width:to,children:u(b,{color:"gray",children:e})})]})}function Ze({stocks:o}){let t=process.stdout.columns||80,e=4,r=Kt+Yt+Zt+to,n=Math.max(t-e-r,20),s=r+n;return Y(I,{flexDirection:"column",marginTop:1,borderStyle:"round",borderColor:"gray",paddingX:1,children:[Y(I,{flexDirection:"row",children:[u(b,{bold:!0,color:"cyan",children:"\u4ED3\u5E93\u5217\u8868"}),Y(b,{color:"gray",children:[" \xB7 ",o.length," \u4E2A"]})]}),Y(I,{flexDirection:"column",marginTop:1,children:[u(Ke,{fillWidth:n}),u(b,{color:"gray",children:"\u2500".repeat(s)}),o.map(i=>u(Ye,{stock:i,fillWidth:n},i.id))]})]})}var Kt,Yt,Zt,to,Qo=at(()=>{"use strict";Kt=6,Yt=10,Zt=10,to=22});import{Command as Lr}from"commander";import ot from"chalk";import"commander";import{Command as bo}from"commander";import x from"chalk";var M=class o extends Error{constructor(e,r,n){super(e);this.code=r;this.details=n;this.name="R2Error",Error.captureStackTrace&&Error.captureStackTrace(this,o)}code;details},A=class extends M{constructor(e,r,n){super(e,"API_ERROR",n);this.status=r;this.response=n;this.name="ApiError"}status;response},$=class extends M{constructor(e,r,n){super(e,"STORAGE_ERROR",{path:r,code:n});this.path=r;this.code=n;this.name="StorageError"}path;code},S=class extends M{constructor(t){super(t,"AUTH_ERROR"),this.name="AuthError"}},U=class extends M{constructor(e,r,n){super(e,"POLLING_ERROR",{attempts:r,timeout:n});this.attempts=r;this.timeout=n;this.name="PollingError"}attempts;timeout};async function ge(o,t,e){let r=new AbortController,n=()=>r.abort();e?.addEventListener("abort",n,{once:!0});let s=setTimeout(()=>r.abort(),t);try{return await o()}catch(i){throw r.signal.aborted&&!e?.aborted?new U("\u5355\u6B21\u8F6E\u8BE2\u8BF7\u6C42\u8D85\u65F6"):i}finally{clearTimeout(s),e?.removeEventListener("abort",n)}}async function F(o,t,e){let{interval:r,timeout:n,condition:s}=t,i=Date.now(),a=0;for(;Date.now()-i<n;){if(e?.aborted)throw new U("\u8F6E\u8BE2\u88AB\u4E2D\u6B62");a++;let l=n-(Date.now()-i),w=await ge(o,l,e);if(s(w,a))return w;await pe(r,e)}throw new U(`\u8F6E\u8BE2\u8D85\u65F6 (\u5DF2\u7B49\u5F85 ${Date.now()-i}ms, \u5171 ${a} \u6B21)`)}function pe(o,t){return new Promise((e,r)=>{if(t?.aborted){r(new U("\u8F6E\u8BE2\u88AB\u4E2D\u6B62"));return}let n=()=>{clearTimeout(s),r(new U("\u8F6E\u8BE2\u88AB\u4E2D\u6B62"))},s=setTimeout(()=>{t?.removeEventListener("abort",n),e()},o);t?.addEventListener("abort",n,{once:!0})})}import ye from"node:fs";import{fileURLToPath as we}from"node:url";import{createRequire as xe}from"node:module";import lo from"node:path";import{exec as Ie}from"node:child_process";import fe from"node:http";var vt=class o{server=null;pages=new Map;port=0;idleTimer=null;static IDLE_TIMEOUT_MS=1e4;async start(){return this.server?this.port:new Promise((t,e)=>{this.server=fe.createServer((r,n)=>this.handleRequest(r,n)),this.server.listen(0,"127.0.0.1",()=>{let r=this.server.address();typeof r=="object"&&r?(this.port=r.port,t(this.port)):e(new Error("Failed to get server address"))}),this.server.on("error",e)})}registerPage(t,e,r,n){let s=this.pages.get(t);if(s){s.qrBuffer=r,s.status="waiting",s.config=n;let i=`data: ${JSON.stringify({status:"waiting"})}
|
|
5
5
|
|
|
6
|
-
`;for(let a of s.sseClients)a.write(i)}else this.pages.set(t,{html:
|
|
6
|
+
`;for(let a of s.sseClients)a.write(i)}else this.pages.set(t,{html:e,qrBuffer:r,status:"waiting",sseClients:[],config:n});this.resetIdleTimer()}unregisterPage(t){let e=this.pages.get(t);if(e){for(let r of e.sseClients)r.end();e.sseClients.length=0,this.pages.delete(t),this.pages.size===0&&this.close()}}setStatus(t,e){let r=this.pages.get(t);if(!r)return;r.status=e;let n=`data: ${JSON.stringify({status:e})}
|
|
7
7
|
|
|
8
|
-
`;for(let s of r.sseClients)s.write(n)}close(){if(this.server){this.idleTimer&&(clearTimeout(this.idleTimer),this.idleTimer=null);for(let t of this.pages.values()){for(let
|
|
8
|
+
`;for(let s of r.sseClients)s.write(n)}close(){if(this.server){this.idleTimer&&(clearTimeout(this.idleTimer),this.idleTimer=null);for(let t of this.pages.values()){for(let e of t.sseClients)e.end();t.sseClients.length=0}this.pages.clear(),this.server.close(),this.server=null,this.port=0,z=null}}resetIdleTimer(){this.idleTimer&&clearTimeout(this.idleTimer),this.idleTimer=setTimeout(()=>{[...this.pages.values()].some(e=>e.sseClients.length>0)||this.close()},o.IDLE_TIMEOUT_MS)}handleRequest(t,e){let r=t.url??"/";for(let[n,s]of this.pages){if(r===n){e.writeHead(302,{Location:n+"/"}),e.end();return}if(r===n+"/"){e.writeHead(200,{"Content-Type":"text/html; charset=utf-8"}),e.end(s.html);return}if(r===n+"/qr.png"){e.writeHead(200,{"Content-Type":"image/png","Content-Length":s.qrBuffer.length}),e.end(s.qrBuffer);return}if(r===n+"/events"){e.writeHead(200,{"Content-Type":"text/event-stream","Cache-Control":"no-cache",Connection:"keep-alive"}),e.write(`data: ${JSON.stringify({status:s.status})}
|
|
9
9
|
|
|
10
|
-
`),s.sseClients.push(
|
|
11
|
-
\u{1F50D} \u5DF2\u626B\u7801: ${l.userInfo?.nickname||"\u672A\u77E5\u7528\u6237"}`)),console.log(
|
|
12
|
-
\u2705 \u7528\u6237\u5DF2\u786E\u8BA4\u767B\u5F55`)),s?.("success"),!0;case"expired":return i||console.log(
|
|
13
|
-
\u23F0 \u4E8C\u7EF4\u7801\u5DF2\u8FC7\u671F`)),s?.("expired"),!0;case"canceled":return i||console.log(
|
|
14
|
-
\u{1F6AB} \u7528\u6237\u5DF2\u53D6\u6D88\u767B\u5F55`)),s?.("expired"),!0;default:return!1}}},n??void 0);if(a.status==="confirmed"&&a.token&&a.userInfo)return await this.storage.saveCredentials(a.token,a.userInfo),{userInfo:a.userInfo,token:a.token};throw a.status==="expired"?new
|
|
15
|
-
\u{1F510} \u6B63\u5728\u542F\u52A8\u626B\u7801\u767B\u5F55...`));let{qrData:
|
|
16
|
-
`)),console.log(
|
|
17
|
-
`)),
|
|
18
|
-
`));let i=Number.parseInt(
|
|
10
|
+
`),s.sseClients.push(e),t.on("close",()=>{let i=s.sseClients.indexOf(e);i>=0&&s.sseClients.splice(i,1)});return}if(r===n+"/config"){e.writeHead(200,{"Content-Type":"application/json"}),e.end(JSON.stringify(s.config??{}));return}}e.writeHead(404,{"Content-Type":"text/plain"}),e.end("Not Found")}},z=null,ao=!1;function lt(){z&&z.close()}function he(){ao||(ao=!0,process.on("exit",lt),process.on("SIGINT",lt),process.on("SIGTERM",lt),setInterval(()=>{process.stdin?.destroyed&<()},3e3).unref())}function co(){return z||(z=new vt,he()),z}var Se=lo.dirname(we(import.meta.url)),Ce="/login",Te="/login-xianyu",Nt=null;async function be(o){return ye.promises.readFile(lo.join(Se,"pages",o),"utf-8")}async function Pe(o){return Nt||(Nt=xe(import.meta.url)),Nt("qrcode").toBuffer(o,{width:300,margin:2})}function B(o){let t=process.platform==="win32"?`start "" "${o}"`:process.platform==="darwin"?`open "${o}"`:`xdg-open "${o}"`;Ie(t)}async function uo(o,t,e,r){let[n,s]=await Promise.all([be(t),Pe(e)]),i=co(),a=await i.start();i.registerPage(o,n,s,r);let l=`http://127.0.0.1:${a}${o}/`;return{url:e,qrUrl:l,setStatus:w=>i.setStatus(o,w),closeServer:()=>i.unregisterPage(o)}}function Rt(o){return uo(Ce,"login.html",o)}function Lt(o,t){return uo(Te,"xianyu-auth.html",o,{authUrl:t})}import{promises as W}from"node:fs";import Ot from"node:path";import Ae from"node:os";var ke=".r2-cli",dt=class{configPath;config;configLoaded=!1;dirEnsured=!1;constructor(){let t=Ae.homedir(),e=Ot.join(t,ke);this.configPath=Ot.join(e,"config.json"),this.config={credentials:null}}getConfigPath(){return this.configPath}async loadConfig(){if(this.configLoaded)return this.config;try{let t=await W.readFile(this.configPath,"utf-8");return this.config=JSON.parse(t),this.configLoaded=!0,this.config}catch{return this.config={credentials:null},this.configLoaded=!0,this.config}}async ensureDir(){if(this.dirEnsured)return;let t=Ot.dirname(this.configPath);try{await W.stat(t)}catch(e){if(e.code==="ENOENT")await W.mkdir(t,{recursive:!0});else throw new $("Failed to create directory",t,e.code)}this.dirEnsured=!0}async saveConfig(t){this.config=t,await this.ensureDir();let e=JSON.stringify(t,null,2),r=this.configPath+".tmp";try{await W.writeFile(r,e,"utf-8"),await W.rename(r,this.configPath),this.configLoaded=!0}catch(n){throw await W.unlink(r).catch(s=>{typeof process.env.DEBUG<"u"&&console.error("[config] cleanup tmp failed:",s)}),new $("Failed to save config",this.configPath,n.code)}}},Dt=null;function Ut(){return Dt||(Dt=new dt),Dt}var Et=300*1e3,ut=class{store=Ut();isTokenExpired(t){return t.expire?Date.now()>=t.expire-Et:!1}async saveCredentials(t,e){let r=Date.now(),n=e.expire?Number.parseInt(e.expire,10):0,s={token:t,userInfo:e,timestamp:r,...n>0&&{expire:r+n}},i=await this.store.loadConfig();i.credentials=s,await this.store.saveConfig(i)}async getCredentials(){let t=await this.store.loadConfig();return!t.credentials||this.isTokenExpired(t.credentials)?null:t.credentials}async clearCredentials(){let t=await this.store.loadConfig();t.credentials=null,await this.store.saveConfig(t)}async getToken(){return(await this.getCredentials())?.token??null}async getUserInfo(){return(await this.getCredentials())?.userInfo??null}async isLoggedIn(){return await this.getCredentials()!==null}},jt=null;function et(){return jt||(jt=new ut),jt}var ve="https://api.puresnake.com",mt=class{config;authStorage=null;cachedToken=null;tokenExpiry=0;constructor(t={}){this.config={baseUrl:t.baseUrl??ve,version:t.version??"v3",debug:t.debug??!1},this.authStorage=t.auth===!1?null:et()}buildUrl(t){let e=t.startsWith("/")?t.slice(1):t;return`${this.config.baseUrl}/${this.config.version}/${e}`}async getAuthToken(){if(!this.authStorage)return;if(this.cachedToken&&Date.now()<this.tokenExpiry)return this.cachedToken;let t=await this.authStorage.getCredentials();if(!t)throw new S("\u8BF7\u5148\u8FD0\u884C r2-cli auth login \u767B\u5F55");return this.cachedToken=t.token,this.tokenExpiry=t.expire?t.expire-Et:Date.now()+1800*1e3,t.token}async requestFull(t,e){let r=this.buildUrl(t),{method:n,headers:s,body:i,timeout:a=3e4}=e,l=await this.getAuthToken(),w={...s,...l?{token:l}:{}},m=new AbortController,P=setTimeout(()=>m.abort(),a),_={method:n,headers:{"Content-Type":"application/json",...w},signal:m.signal};i!==void 0&&(_.body=JSON.stringify(i)),this.config.debug&&console.error(`[API ${n}]`,r,i);try{let d=await fetch(r,_);if(!d.ok){if(d.status===401)throw this.authStorage&&(this.cachedToken=null,await this.authStorage.clearCredentials().catch(Q=>{console.error("[API] \u6E05\u9664\u51ED\u8BC1\u5931\u8D25:",Q instanceof Error?Q.message:String(Q))})),new S("\u767B\u5F55\u5DF2\u8FC7\u671F\uFF0C\u8BF7\u8FD0\u884C r2-cli auth login \u91CD\u65B0\u767B\u5F55");let At=await d.text();throw new A(At||`${d.status} ${d.statusText}`,d.status)}let k=await d.json();if(this.config.debug&&console.error("[API Response]",k),!k.success||k.status!==0)throw new A(k.msg||"\u672A\u77E5\u9519\u8BEF",k.status,k);return k}catch(d){throw d instanceof DOMException&&d.name==="AbortError"?new A(`\u8BF7\u6C42\u8D85\u65F6 (${a}ms)`,408):d}finally{clearTimeout(P)}}async request(t,e){return(await this.requestFull(t,e)).data}async get(t,e,r){let n=e&&e.size>0?`${t}?${e.toString()}`:t;return this.request(n,{method:"GET",headers:r})}async post(t,e,r){return this.request(t,{method:"POST",body:e,headers:r})}async put(t,e,r){return this.request(t,{method:"PUT",body:e,headers:r})}async delete(t,e){return this.request(t,{method:"DELETE",headers:e})}async upload(t,e,r){let n=this.buildUrl(t),s=await this.getAuthToken(),i={...r,...s?{token:s}:{}},a=new AbortController,l=setTimeout(()=>a.abort(),6e4),w={method:"POST",headers:i,body:e,signal:a.signal};this.config.debug&&console.error("[API UPLOAD]",n);try{let m=await fetch(n,w);if(!m.ok){if(m.status===401)throw this.authStorage&&(this.cachedToken=null,await this.authStorage.clearCredentials().catch(()=>{})),new S("\u767B\u5F55\u5DF2\u8FC7\u671F\uFF0C\u8BF7\u8FD0\u884C r2-cli auth login \u91CD\u65B0\u767B\u5F55");let _=await m.text();throw new A(_||`${m.status} ${m.statusText}`,m.status)}let P=await m.json();if(this.config.debug&&console.error("[API Response]",P),!P.success||P.status!==0)throw new A(P.msg||"\u672A\u77E5\u9519\u8BEF",P.status,P);return P.data}catch(m){throw m instanceof DOMException&&m.name==="AbortError"?new A("\u4E0A\u4F20\u8D85\u65F6 (60000ms)",408):m}finally{clearTimeout(l)}}},gt=new mt,mo=new mt({auth:!1});var go=mo;async function po(){return go.post("app/qrcode/generate")}async function fo(o){let t=new URLSearchParams;t.append("qrToken",o);let e=`app/qrcode/status?${t.toString()}`,r=await go.requestFull(e,{method:"GET"});return r.token&&typeof r.data=="object"&&r.data!==null&&(r.data.token=r.token),r.data}async function xo(o,t,e){let{UserInfoCard:r}=await Promise.resolve().then(()=>(yo(),ho)),{renderComponent:n}=await Promise.resolve().then(()=>(rt(),pt)),s=t!=null?{userInfo:o,lastLogin:t,daysSinceLogin:e??0}:{userInfo:o};n(r,s)}var ft=class{storage;constructor(t){this.storage=t??et()}async generateQR(){let t=await po(),e=`https://m.puresnake.com/r2/auth/login?qrToken=${t.qrContent}&from=wechat`,r=await Rt(e);return{qrData:t,...r}}async waitForLogin(t,e,r,n,s,i){let a=await F(()=>fo(t),{interval:r,timeout:e,condition:l=>{switch(l.status){case"scanned":return i||(console.log(x.cyan(`
|
|
11
|
+
\u{1F50D} \u5DF2\u626B\u7801: ${l.userInfo?.nickname||"\u672A\u77E5\u7528\u6237"}`)),console.log(x.yellow("\u8BF7\u5728 APP \u4E0A\u786E\u8BA4\u767B\u5F55"))),s?.("scanning"),!1;case"confirmed":return i||console.log(x.green(`
|
|
12
|
+
\u2705 \u7528\u6237\u5DF2\u786E\u8BA4\u767B\u5F55`)),s?.("success"),!0;case"expired":return i||console.log(x.red(`
|
|
13
|
+
\u23F0 \u4E8C\u7EF4\u7801\u5DF2\u8FC7\u671F`)),s?.("expired"),!0;case"canceled":return i||console.log(x.red(`
|
|
14
|
+
\u{1F6AB} \u7528\u6237\u5DF2\u53D6\u6D88\u767B\u5F55`)),s?.("expired"),!0;default:return!1}}},n??void 0);if(a.status==="confirmed"&&a.token&&a.userInfo)return await this.storage.saveCredentials(a.token,a.userInfo),{userInfo:a.userInfo,token:a.token};throw a.status==="expired"?new S("\u4E8C\u7EF4\u7801\u5DF2\u8FC7\u671F\uFF0C\u8BF7\u91CD\u65B0\u767B\u5F55"):a.status==="canceled"?new S("\u7528\u6237\u5DF2\u53D6\u6D88\u767B\u5F55"):new S("\u767B\u5F55\u5931\u8D25: \u672A\u83B7\u53D6\u5230\u51ED\u8BC1")}async login(t){console.log(x.cyan(`
|
|
15
|
+
\u{1F510} \u6B63\u5728\u542F\u52A8\u626B\u7801\u767B\u5F55...`));let{qrData:e,qrUrl:r,setStatus:n,closeServer:s}=await this.generateQR();console.log(x.green(`\u2705 \u4E8C\u7EF4\u7801\u5DF2\u751F\u6210
|
|
16
|
+
`)),console.log(x.cyan(` \u94FE\u63A5: ${r}
|
|
17
|
+
`)),B(r),console.log(x.yellow(`\u23F3 \u7B49\u5F85\u626B\u7801...
|
|
18
|
+
`));let i=Number.parseInt(e.expireTime,10),a=Number.parseInt(e.pollInterval,10);try{let l=await this.waitForLogin(e.qrToken,i,a,t,n);return console.log(x.green(`
|
|
19
19
|
\u2705 \u767B\u5F55\u6210\u529F\uFF01
|
|
20
|
-
`)),
|
|
20
|
+
`)),xo(l.userInfo),l}catch(l){throw console.log(x.red(`
|
|
21
21
|
\u274C \u767B\u5F55\u5931\u8D25
|
|
22
|
-
`)),l}finally{s()}}async logout(){console.log(
|
|
23
|
-
\u{1F6AA} \u6B63\u5728\u9000\u51FA\u767B\u5F55...`)),await this.storage.clearCredentials(),console.log(
|
|
24
|
-
`))}async status(){if(!await this.storage.isLoggedIn()){console.log(
|
|
25
|
-
`));return}let
|
|
26
|
-
`)),await
|
|
27
|
-
\u2705 \u6388\u6743\u6210\u529F\uFF01\u5E97\u94FA: ${s.shopName} (${s.shopId})`)),n?.("success"),!0):s.status==="expired"?(console.log(
|
|
28
|
-
\u23F0 \u6388\u6743\u94FE\u63A5\u5DF2\u8FC7\u671F`)),n?.("expired"),!0):!1},r)}async function
|
|
29
|
-
\u{1F517} \u6B63\u5728\u83B7\u53D6\u95F2\u9C7C\u6388\u6743\u5730\u5740...`));let{authData:t,qrUrl:
|
|
30
|
-
`)),console.log(
|
|
22
|
+
`)),l}finally{s()}}async logout(){console.log(x.cyan(`
|
|
23
|
+
\u{1F6AA} \u6B63\u5728\u9000\u51FA\u767B\u5F55...`)),await this.storage.clearCredentials(),console.log(x.green(`\u2705 \u5DF2\u9000\u51FA\u767B\u5F55
|
|
24
|
+
`))}async status(){if(!await this.storage.isLoggedIn()){console.log(x.yellow(`\u26A0\uFE0F \u5C1A\u672A\u767B\u5F55\u6216\u51ED\u8BC1\u5DF2\u8FC7\u671F
|
|
25
|
+
`));return}let e=await this.storage.getCredentials(),r=e.userInfo,n=new Date(e.timestamp),s=Math.floor((Date.now()-e.timestamp)/(1e3*60*60*24));console.log(x.green(`\u2705 \u5DF2\u767B\u5F55
|
|
26
|
+
`)),await xo(r,n,s)}},Gt=null;function R(){return Gt||(Gt=new ft),Gt}import q from"chalk";var Io=gt;async function So(){return Io.get("mms/xianyu/auth/url")}async function Co(o){let t=new URLSearchParams({state:o});return Io.get("mms/xianyu/auth/status",t)}async function ht(){let o=await So(),t=await Lt(o.url,o.url);return{authData:o,...t}}async function nt(o,t,e,r,n){return F(()=>Co(o),{interval:e,timeout:t,condition:s=>s.status==="success"?(console.log(q.green(`
|
|
27
|
+
\u2705 \u6388\u6743\u6210\u529F\uFF01\u5E97\u94FA: ${s.shopName} (${s.shopId})`)),n?.("success"),!0):s.status==="expired"?(console.log(q.red(`
|
|
28
|
+
\u23F0 \u6388\u6743\u94FE\u63A5\u5DF2\u8FC7\u671F`)),n?.("expired"),!0):!1},r)}async function Jt(o){console.log(q.cyan(`
|
|
29
|
+
\u{1F517} \u6B63\u5728\u83B7\u53D6\u95F2\u9C7C\u6388\u6743\u5730\u5740...`));let{authData:t,qrUrl:e,setStatus:r,closeServer:n}=await ht();console.log(q.green(`\u2705 \u6388\u6743\u4E8C\u7EF4\u7801\u5DF2\u751F\u6210
|
|
30
|
+
`)),console.log(q.cyan(` \u94FE\u63A5: ${e}`)),console.log(q.gray(` \u6216\u590D\u5236\u94FE\u63A5\u6253\u5F00: ${t.url}`)),B(e),console.log(q.yellow(`
|
|
31
31
|
\u23F3 \u7B49\u5F85\u6388\u6743...
|
|
32
|
-
`));let s=t.expireTime?Number.parseInt(t.expireTime,10):3e5,i=t.pollInterval?Number.parseInt(t.pollInterval,10):1e3;try{let a=await
|
|
33
|
-
\u25B2 ${
|
|
34
|
-
`));else if(
|
|
35
|
-
`));else{let t=e instanceof Error?e.message:String(e);console.error(L.red(`\u25B2 ${t}`))}process.exit(1)}function vt(e){console.log(JSON.stringify({success:!1,error:e})),process.exit(1)}function it(e){return async(...t)=>{try{await e(...t)}catch(o){let r=o instanceof Error?o.message:String(o);vt(r)}}}var no=new Set(["accessToken","refreshExpireIn"]);function re(e){return e.map(t=>{let o={};for(let[r,n]of Object.entries(t))no.has(r)||(o[r]=n);return o})}function bt(){let e=new ne("login");e.description("\u626B\u7801\u767B\u5F55 Round2AI \u8D26\u6237").option("--json","\u8F93\u51FA JSON\uFF08\u4F9B AI Agent \u4F7F\u7528\uFF09");let t=new ne("poll").description("\u8F6E\u8BE2\u767B\u5F55\u72B6\u6001\uFF08\u4F9B AI Agent \u4F7F\u7528\uFF09").requiredOption("--token <qrToken>","\u4E8C\u7EF4\u7801 token").option("--expire <ms>","\u8FC7\u671F\u65F6\u95F4\uFF08\u6BEB\u79D2\uFF09","300000").option("--interval <ms>","\u8F6E\u8BE2\u95F4\u9694\uFF08\u6BEB\u79D2\uFF09","1000").action(it(async o=>{let n=await k().waitForLogin(o.token,Number.parseInt(o.expire,10),Number.parseInt(o.interval,10));console.log(JSON.stringify({success:!0,...n}))}));return e.addCommand(t),e.action(async o=>{try{if(o.json){let r=k(),{qrData:n,qrUrl:s,setStatus:i,closeServer:a}=await r.generateQR(),l=Number.parseInt(n.expireTime,10),d=Number.parseInt(n.pollInterval,10);console.log(JSON.stringify({qrToken:n.qrToken,expireTimeMs:l,pollIntervalMs:d,url:`https://m.puresnake.com/r2/auth/login?qrToken=${n.qrContent}&from=wechat`,qrUrl:s},null,2)),P(s);try{let g=await r.waitForLogin(n.qrToken,l,d,void 0,i,!0);console.log(JSON.stringify({success:!0,userInfo:g.userInfo}))}catch(g){let $=g instanceof Error?g.message:String(g);console.log(JSON.stringify({success:!1,error:$}))}finally{setTimeout(a,1e3)}}else await k().login()}catch(r){if(o.json){let n=r instanceof Error?r.message:String(r);console.log(JSON.stringify({success:!1,error:n})),process.exit(1)}m(r)}}),e}import{Command as so}from"commander";function At(){let e=new so("logout");return e.description("\u9000\u51FA\u767B\u5F55"),e.action(async()=>{try{await k().logout()}catch(t){m(t)}}),e}import{Command as io}from"commander";function Lt(){let e=new io("status");return e.description("\u67E5\u770B\u767B\u5F55\u72B6\u6001"),e.action(async()=>{try{await k().status()}catch(t){m(t)}}),e}import{Command as se}from"commander";function Rt(){let e=new se("xianyu");e.description("\u95F2\u9C7C\u5E97\u94FA\u6388\u6743").option("--json","\u8F93\u51FA JSON\uFF08\u4F9B AI Agent \u4F7F\u7528\uFF09");let t=new se("poll").description("\u8F6E\u8BE2\u95F2\u9C7C\u6388\u6743\u72B6\u6001\uFF08\u4F9B AI Agent \u4F7F\u7528\uFF09").requiredOption("--state <state>","\u6388\u6743\u8F6E\u8BE2 token").option("--expire <ms>","\u8FC7\u671F\u65F6\u95F4\uFF08\u6BEB\u79D2\uFF09","300000").option("--interval <ms>","\u8F6E\u8BE2\u95F4\u9694\uFF08\u6BEB\u79D2\uFF09","1000").action(it(async o=>{let r=await H(o.state,Number.parseInt(o.expire,10),Number.parseInt(o.interval,10));r.status==="success"?console.log(JSON.stringify({success:!0,shopId:r.shopId,shopName:r.shopName})):vt(`\u6388\u6743\u72B6\u6001: ${r.status}`)}));return e.addCommand(t),e.action(async o=>{try{if(o.json){let{authData:r,qrUrl:n,setStatus:s,closeServer:i}=await st(),a=r.expireTime?Number.parseInt(r.expireTime,10):3e5,l=r.pollInterval?Number.parseInt(r.pollInterval,10):1e3;console.log(JSON.stringify({state:r.state,expireTimeMs:a,pollIntervalMs:l,qrUrl:n},null,2)),P(n);try{let d=await H(r.state,a,l,void 0,s);d.status==="success"?console.log(JSON.stringify({success:!0,shopId:d.shopId,shopName:d.shopName})):(console.log(JSON.stringify({success:!1,error:`\u6388\u6743\u72B6\u6001: ${d.status}`})),process.exit(1))}catch(d){let g=d instanceof Error?d.message:String(d);console.log(JSON.stringify({success:!1,error:g})),process.exit(1)}finally{setTimeout(i,1e3)}}else await kt()}catch(r){if(o.json){let n=r instanceof Error?r.message:String(r);console.log(JSON.stringify({success:!1,error:n})),process.exit(1)}m(r)}}),e}import{Command as Lo}from"commander";import{Command as ao}from"commander";import I from"chalk";import{select as Ot,input as co,confirm as lo}from"@inquirer/prompts";var R=new A;function Nt(e){let t=new URLSearchParams;for(let[o,r]of Object.entries(e))r!=null&&r!==""&&t.append(o,String(r));return t}async function Et(e){return R.post("mms/goods/listing/up/xianyu",e)}async function ie(e){return R.get("mms/goods/listing/get",Nt({...e}))}async function ae(e){return R.post("mms/goods/listing/down/xianyu",e)}async function ce(e){return R.post("mms/goods/listing/update/xyPrice",e)}async function le(e){return R.get("mms/goods/listing/list",e?Nt({...e}):void 0)}async function at(){return await R.get("mms/user/shop/list")??[]}async function ct(){return await R.get("mms/user/stock/list")??[]}async function lt(e){let t=e?Nt({...e}):void 0;return R.get("mms/seller/goods/select/list",t)}var mo=2e3,uo=1e4;function po(e){let t=e.status?.toLowerCase()??"";return t===""||t==="init"||t==="pending"||t==="processing"}async function me(e,t,o,r){r||process.stdout.write(I.cyan("\u23F3 \u6B63\u5728\u67E5\u8BE2\u4E0A\u67B6\u8FDB\u5EA6..."));let n=await B(()=>ie({stockGoodsId:e,shopId:t,platform:o}),{interval:mo,timeout:uo,condition:s=>!po(s)});return r||process.stdout.write("\r"+" ".repeat(30)+"\r"),n}function ue(){let e=new ao("up");return e.description("\u4E0A\u67B6\u5546\u54C1\u5230\u95F2\u9C7C"),e.option("--stock-goods-id <id>","\u5E93\u5B58\u5546\u54C1ID\uFF08\u4ECE goods list \u83B7\u53D6\uFF09").option("--shop-id <id>","\u5E97\u94FAID\uFF08\u4ECE goods shops \u83B7\u53D6\uFF09").option("--price <amount>","\u4E0A\u67B6\u4EF7\u683C").option("-p, --platform <platform>","\u5E73\u53F0","xianyu").option("--json","\u8F93\u51FA JSON\uFF08Agent \u7528\uFF09").action(async t=>{try{if(t.stockGoodsId&&t.shopId&&t.price){let c=Number(t.stockGoodsId),S=t.shopId,dt=Number(t.price),j=t.platform,Ee=await Et({stockGoodsId:c,shopId:S,price:dt,platform:j}),pt=await me(c,S,j,t.json);if(t.json)console.log(JSON.stringify({success:!0,data:{submit:Ee,listing:pt}},null,2));else{let Oe=pt.status?.toLowerCase()!=="failed";console.log(Oe?I.green("\u2713 \u4E0A\u67B6\u6210\u529F"):I.red("\u2717 \u4E0A\u67B6\u5931\u8D25")),console.log(JSON.stringify(pt,null,2))}return}let o=await at();if(o.length===0){console.log(I.yellow("\u6CA1\u6709\u5DF2\u6388\u6743\u5E97\u94FA\uFF0C\u8BF7\u5148\u8FD0\u884C r2-cli auth xianyu \u6388\u6743"));return}let r=await Ot({message:"\u9009\u62E9\u5E97\u94FA",choices:o.map(c=>({name:`${c.shopName} (${c.platform})`,value:c.shopId}))}),n=await ct();if(n.length===0){console.log(I.yellow("\u6CA1\u6709\u53EF\u7528\u7684\u4ED3\u5E93"));return}let s=await Ot({message:"\u9009\u62E9\u4ED3\u5E93",choices:n.map(c=>({name:c.stockName,value:c.stockId}))}),i=await lt({stockId:s,size:100});if(!i.items?.length){console.log(I.yellow("\u8BE5\u4ED3\u5E93\u6CA1\u6709\u53EF\u9009\u7684\u5546\u54C1"));return}let a=await Ot({message:"\u9009\u62E9\u5546\u54C1",choices:i.items.map(c=>({name:`${c.goodsName} ${c.size?`| ${c.size}`:""} | \xA5${c.salePrice}`,value:c.stockGoodsId}))}),l=await co({message:"\u8F93\u5165\u4E0A\u67B6\u4EF7\u683C",default:i.items.find(c=>c.stockGoodsId===a)?.salePrice?.toString()??"",validate:c=>Number(c)>0?!0:"\u4EF7\u683C\u5FC5\u987B\u4E3A\u6B63\u6570"});if(!await lo({message:`\u786E\u8BA4\u4E0A\u67B6\uFF1F\u4EF7\u683C \xA5${l}`,default:!0})){console.log(I.gray("\u5DF2\u53D6\u6D88"));return}let g=Number(a);await Et({stockGoodsId:g,shopId:r,price:Number(l),platform:"xianyu"}),console.log(I.green("\u2713 \u4E0A\u67B6\u5DF2\u63D0\u4EA4\uFF0C\u6B63\u5728\u67E5\u8BE2\u8FDB\u5EA6..."));let $=await me(g,r,"xianyu"),K=$.status?.toLowerCase()!=="failed";console.log(K?I.green("\u2713 \u4E0A\u67B6\u6210\u529F"):I.red("\u2717 \u4E0A\u67B6\u5931\u8D25")),console.log(JSON.stringify($,null,2))}catch(o){m(o)}}),e}import{Command as wo}from"commander";import fe from"chalk";function he(){let e=new wo("shops");return e.description("\u67E5\u770B\u6240\u6709\u5DF2\u6388\u6743\u5E97\u94FA\uFF08\u8DE8\u5E73\u53F0\uFF09"),e.option("--json","\u8F93\u51FA JSON\uFF08\u4F9B AI Agent \u4F7F\u7528\uFF09"),e.action(async t=>{try{let o=await at();if(t.json){console.log(JSON.stringify(re(o),null,2));return}if(!o.length){console.log(fe.yellow("\u672A\u627E\u5230\u5DF2\u6388\u6743\u7684\u5E97\u94FA")),console.log(fe.gray(" \u63D0\u793A: \u8BF7\u5148\u5728\u7B2C\u4E8C\u56DE\u5408 APP \u4E2D\u6388\u6743\u5E97\u94FA"));return}let{ShopsTable:r}=await Promise.resolve().then(()=>(ge(),pe)),{renderComponent:n}=await Promise.resolve().then(()=>(rt(),ot));n(r,{shops:o,platform:"all"})}catch(o){m(o)}}),e}import{Command as Io}from"commander";import To from"chalk";function xe(){let e=new Io("stocks");return e.description("\u67E5\u770B\u6240\u6709\u4ED3\u5E93"),e.option("--json","\u8F93\u51FA JSON\uFF08\u4F9B AI Agent \u4F7F\u7528\uFF09"),e.action(async t=>{try{let o=await ct();if(t.json){console.log(JSON.stringify(o,null,2));return}if(!o.length){console.log(To.yellow("\u672A\u627E\u5230\u4ED3\u5E93\u4FE1\u606F"));return}let{StocksTable:r}=await Promise.resolve().then(()=>(we(),ye)),{renderComponent:n}=await Promise.resolve().then(()=>(rt(),ot));n(r,{stocks:o})}catch(o){m(o)}}),e}import{Command as Po}from"commander";import F from"chalk";function Se(){let e=new Po("list");return e.description("\u67E5\u770B\u4ED3\u5E93\u4E2D\u7684\u9009\u54C1\u5546\u54C1"),e.option("--stock-id <id>","\u4ED3\u5E93 ID\uFF08\u4ECE goods stocks \u83B7\u53D6\uFF09").option("--stock-goods-id <id>","\u5E93\u5B58\u5546\u54C1 ID").option("--page <n>","\u9875\u7801","1").option("--size <n>","\u6BCF\u9875\u6570\u91CF","20").option("--json","\u8F93\u51FA JSON\uFF08\u4F9B AI Agent \u4F7F\u7528\uFF09"),e.action(async t=>{try{let r=await lt({stockId:t.stockId||void 0,stockGoodsId:t.stockGoodsId||void 0,page:Number(t.page)||1,size:Number(t.size)||20})??{items:[],total:0};if(t.json){r.items?.length?console.log(JSON.stringify(r,null,2)):console.log(JSON.stringify({...r,hint:"\u9009\u54C1\u5546\u54C1\u4E3A\u7A7A\uFF0C\u8BF7\u5148\u5728\u540E\u53F0\u751F\u6210\u9009\u54C1\u8868\u6570\u636E\u540E\u518D\u8BD5"},null,2));return}if(!r.items?.length){console.log(F.yellow("\u6682\u65E0\u9009\u54C1\u5546\u54C1\uFF0C\u8BF7\u5148\u7ED1\u5B9A\u4ED3\u5E93\u6216\u5728\u540E\u53F0\u751F\u6210\u9009\u54C1\u8868\u6570\u636E"));return}console.log(F.cyan(`
|
|
32
|
+
`));let s=t.expireTime?Number.parseInt(t.expireTime,10):3e5,i=t.pollInterval?Number.parseInt(t.pollInterval,10):1e3;try{let a=await nt(t.state,s,i,o,r);if(a.status==="success")return a;throw new S("\u95F2\u9C7C\u6388\u6743\u5931\u8D25: "+(a.status==="expired"?"\u94FE\u63A5\u5DF2\u8FC7\u671F":"\u672A\u77E5\u72B6\u6001"))}finally{n()}}import j from"chalk";function v(o){if(o instanceof S)console.error(j.red(`
|
|
33
|
+
\u25B2 ${o.message}`)),console.error(j.gray(`\u2192 \u8BF7\u5148\u8FD0\u884C: r2-cli auth login
|
|
34
|
+
`));else if(o instanceof A)console.error(j.red(`\u25B2 \u64CD\u4F5C\u5931\u8D25: ${o.message}`)),o.status&&console.error(j.gray(` \u72B6\u6001\u7801: ${o.status}`));else if(o instanceof $)console.error(j.red(`\u25B2 \u914D\u7F6E\u6587\u4EF6\u5F02\u5E38: ${o.message}`)),o.path&&console.error(j.gray(` \u8DEF\u5F84: ${o.path}`)),console.error(j.gray(`\u2192 \u8BF7\u5C1D\u8BD5\u91CD\u65B0\u767B\u5F55: r2-cli auth login
|
|
35
|
+
`));else{let t=o instanceof Error?o.message:String(o);console.error(j.red(`\u25B2 ${t}`))}process.exit(1)}function qt(o){console.log(JSON.stringify({success:!1,error:o})),process.exit(1)}function g(o){return async t=>{try{await o(t)}catch(e){if(t.json){let r=e instanceof Error?e.message:String(e),n=e instanceof A?e.status:void 0;console.log(JSON.stringify({success:!1,error:r,...n!=null&&{status:n}})),process.exit(1)}v(e)}}}function yt(o){return async(...t)=>{try{await o(...t)}catch(e){let r=e instanceof Error?e.message:String(e);qt(r)}}}var je=new Set(["accessToken","refreshExpireIn"]);function To(o){return o.map(t=>{let e={};for(let[r,n]of Object.entries(t))je.has(r)||(e[r]=n);return e})}async function wt(o){let{qrInfo:t,qrUrl:e,setStatus:r,closeServer:n,waitArgs:s}=await o.generate();console.log(JSON.stringify(t,null,2)),B(e);try{let i=await o.waitResult(s,r);console.log(JSON.stringify(o.formatSuccess(i)))}catch(i){let a=i instanceof Error?i.message:String(i);console.log(JSON.stringify({success:!1,error:a})),process.exit(1)}finally{setTimeout(n,1e3)}}function Xt(){let o=new bo("login");o.description("\u626B\u7801\u767B\u5F55 Round2AI \u8D26\u6237").option("--json","\u8F93\u51FA JSON\uFF08\u4F9B AI Agent \u4F7F\u7528\uFF09");let t=new bo("poll").description("\u8F6E\u8BE2\u767B\u5F55\u72B6\u6001\uFF08\u4F9B AI Agent \u4F7F\u7528\uFF09").requiredOption("--token <qrToken>","\u4E8C\u7EF4\u7801 token").option("--expire <ms>","\u8FC7\u671F\u65F6\u95F4\uFF08\u6BEB\u79D2\uFF09","300000").option("--interval <ms>","\u8F6E\u8BE2\u95F4\u9694\uFF08\u6BEB\u79D2\uFF09","1000").action(yt(async e=>{let n=await R().waitForLogin(e.token,Number.parseInt(e.expire,10),Number.parseInt(e.interval,10));console.log(JSON.stringify({success:!0,...n}))}));return o.addCommand(t),o.action(async e=>{try{e.json?await wt({generate:async()=>{let r=R(),{qrData:n,qrUrl:s,setStatus:i,closeServer:a}=await r.generateQR(),l=Number.parseInt(n.expireTime,10),w=Number.parseInt(n.pollInterval,10);return{qrInfo:{qrToken:n.qrToken,expireTimeMs:l,pollIntervalMs:w,url:`https://m.puresnake.com/r2/auth/login?qrToken=${n.qrContent}&from=wechat`,qrUrl:s},qrUrl:s,setStatus:i,closeServer:a,waitArgs:{qrToken:n.qrToken,expireMs:l,intervalMs:w}}},waitResult:({qrToken:r,expireMs:n,intervalMs:s},i)=>R().waitForLogin(r,n,s,void 0,i,!0),formatSuccess:r=>({success:!0,userInfo:r.userInfo})}):await R().login()}catch(r){if(e.json){let n=r instanceof Error?r.message:String(r);console.log(JSON.stringify({success:!1,error:n})),process.exit(1)}v(r)}}),o}import{Command as Ee}from"commander";function _t(){let o=new Ee("logout");return o.description("\u9000\u51FA\u767B\u5F55"),o.action(async()=>{try{await R().logout()}catch(t){v(t)}}),o}import{Command as $e}from"commander";function Qt(){let o=new $e("status");return o.description("\u67E5\u770B\u767B\u5F55\u72B6\u6001"),o.action(async()=>{try{await R().status()}catch(t){v(t)}}),o}import{Command as Po}from"commander";function Mt(){let o=new Po("xianyu");o.description("\u95F2\u9C7C\u5E97\u94FA\u6388\u6743").option("--json","\u8F93\u51FA JSON\uFF08\u4F9B AI Agent \u4F7F\u7528\uFF09");let t=new Po("poll").description("\u8F6E\u8BE2\u95F2\u9C7C\u6388\u6743\u72B6\u6001\uFF08\u4F9B AI Agent \u4F7F\u7528\uFF09").requiredOption("--state <state>","\u6388\u6743\u8F6E\u8BE2 token").option("--expire <ms>","\u8FC7\u671F\u65F6\u95F4\uFF08\u6BEB\u79D2\uFF09","300000").option("--interval <ms>","\u8F6E\u8BE2\u95F4\u9694\uFF08\u6BEB\u79D2\uFF09","1000").action(yt(async e=>{let r=await nt(e.state,Number.parseInt(e.expire,10),Number.parseInt(e.interval,10));r.status==="success"?console.log(JSON.stringify({success:!0,shopId:r.shopId,shopName:r.shopName})):qt(`\u6388\u6743\u72B6\u6001: ${r.status}`)}));return o.addCommand(t),o.action(async e=>{try{e.json?await wt({generate:async()=>{let{authData:r,qrUrl:n,setStatus:s,closeServer:i}=await ht(),a=r.expireTime?Number.parseInt(r.expireTime,10):3e5,l=r.pollInterval?Number.parseInt(r.pollInterval,10):1e3;return{qrInfo:{state:r.state,expireTimeMs:a,pollIntervalMs:l,qrUrl:n},qrUrl:n,setStatus:s,closeServer:i,waitArgs:{state:r.state,expireMs:a,intervalMs:l}}},waitResult:async({state:r,expireMs:n,intervalMs:s},i)=>{let a=await nt(r,n,s,void 0,i);if(a.status!=="success")throw new Error(`\u6388\u6743\u72B6\u6001: ${a.status}`);return a},formatSuccess:r=>({success:!0,shopId:r.shopId,shopName:r.shopName})}):await Jt()}catch(r){if(e.json){let n=r instanceof Error?r.message:String(r);console.log(JSON.stringify({success:!1,error:n})),process.exit(1)}v(r)}}),o}import{Command as gr}from"commander";import{Command as Je}from"commander";import L from"chalk";import{select as zt,input as qe,confirm as Xe}from"@inquirer/prompts";import{readFileSync as Be}from"node:fs";import{basename as Ge}from"node:path";function X(o){let t=new URLSearchParams;for(let[e,r]of Object.entries(o))r!=null&&r!==""&&t.append(e,String(r));return t}var C=gt;async function Ft(o){return C.post("mms/goods/listing/up/xianyu",o)}async function Ao(o){return C.get("mms/goods/listing/get",X({...o}))}async function ko(o){return C.post("mms/goods/listing/down/xianyu",o)}async function vo(o){return C.post("mms/goods/listing/update/xyPrice",o)}async function No(o){return C.post("mms/goods/listing/update/goodsInfo",o)}async function Ro(o){return C.get("mms/goods/listing/list",o?X({...o}):void 0)}async function xt(){return await C.get("mms/user/shop/list")??[]}async function It(){return await C.get("mms/user/stock/list")??[]}async function St(o){let t=o?X({...o}):void 0;return C.get("mms/seller/goods/select/list",t)}async function Lo(o,t){let e=[];for(let r of t){let n=Be(r),s=Ge(r),i=new FormData;i.append("file",new Blob([n]),s);let a=await C.upload(`platform/xy/media/upload?shopId=${encodeURIComponent(o)}`,i);e.push(a)}return e}async function Oo(o){return C.post("mms/goods/listing/hang/up/xianyu",o)}async function Do(o=16){return await C.get("platform/xy/cat",X({spBizType:o}))??[]}async function Uo(o){return await C.get("platform/xy/props",X({channelCatId:o}))??[]}async function jo(o,t,e){return await C.get("platform/xy/props/value",X({channelCatId:o,propId:t,key:e}))??[]}var _e=2e3,Qe=1e4;function Me(o){let t=o.status?.toLowerCase()??"";return t===""||t==="init"||t==="pending"||t==="processing"}async function Eo(o,t,e,r){r||process.stdout.write(L.cyan("\u23F3 \u6B63\u5728\u67E5\u8BE2\u4E0A\u67B6\u8FDB\u5EA6..."));let n=await F(()=>Ao({stockGoodsId:o,shopId:t,platform:e}),{interval:_e,timeout:Qe,condition:s=>!Me(s)});return r||process.stdout.write("\r"+" ".repeat(30)+"\r"),n}function $o(){let o=new Je("up");return o.description("\u4E0A\u67B6\u5546\u54C1\u5230\u95F2\u9C7C"),o.option("--stock-goods-id <id>","\u5E93\u5B58\u5546\u54C1ID\uFF08\u4ECE goods list \u83B7\u53D6\uFF09").option("--shop-id <id>","\u5E97\u94FAID\uFF08\u4ECE goods shops \u83B7\u53D6\uFF09").option("--price <amount>","\u4E0A\u67B6\u4EF7\u683C").option("-p, --platform <platform>","\u5E73\u53F0","xianyu").option("--json","\u8F93\u51FA JSON\uFF08Agent \u7528\uFF09").action(g(async t=>{if(t.json&&!(t.stockGoodsId&&t.shopId&&t.price)&&(console.log(JSON.stringify({success:!1,error:"Agent \u6A21\u5F0F\u9700\u8981 --stock-goods-id, --shop-id, --price"})),process.exit(1)),t.stockGoodsId&&t.shopId&&t.price){let d=Number(t.stockGoodsId),k=t.shopId,At=Number(t.price),Q=t.platform,de=await Ft({stockGoodsId:d,shopId:k,price:At,platform:Q}),kt=await Eo(d,k,Q,t.json);if(t.json)console.log(JSON.stringify({success:!0,data:{submit:de,listing:kt}},null,2));else{let ue=kt.status?.toLowerCase()!=="failed";console.log(ue?L.green("\u2713 \u4E0A\u67B6\u6210\u529F"):L.red("\u2717 \u4E0A\u67B6\u5931\u8D25")),console.log(JSON.stringify(kt,null,2))}return}let e=await xt();if(e.length===0){console.log(L.yellow("\u6CA1\u6709\u5DF2\u6388\u6743\u5E97\u94FA\uFF0C\u8BF7\u5148\u8FD0\u884C r2-cli auth xianyu \u6388\u6743"));return}let r=await zt({message:"\u9009\u62E9\u5E97\u94FA",choices:e.map(d=>({name:`${d.shopName} (${d.platform})`,value:d.shopId}))}),n=await It();if(n.length===0){console.log(L.yellow("\u6CA1\u6709\u53EF\u7528\u7684\u4ED3\u5E93"));return}let s=await zt({message:"\u9009\u62E9\u4ED3\u5E93",choices:n.map(d=>({name:d.stockName,value:d.stockId}))}),i=await St({stockId:s,size:100});if(!i.items?.length){console.log(L.yellow("\u8BE5\u4ED3\u5E93\u6CA1\u6709\u53EF\u9009\u7684\u5546\u54C1"));return}let a=await zt({message:"\u9009\u62E9\u5546\u54C1",choices:i.items.map(d=>({name:`${d.goodsName} ${d.size?`| ${d.size}`:""} | \xA5${d.salePrice}`,value:d.stockGoodsId}))}),l=await qe({message:"\u8F93\u5165\u4E0A\u67B6\u4EF7\u683C",default:i.items.find(d=>d.stockGoodsId===a)?.salePrice?.toString()??"",validate:d=>Number(d)>0?!0:"\u4EF7\u683C\u5FC5\u987B\u4E3A\u6B63\u6570"});if(!await Xe({message:`\u786E\u8BA4\u4E0A\u67B6\uFF1F\u4EF7\u683C \xA5${l}`,default:!0})){console.log(L.gray("\u5DF2\u53D6\u6D88"));return}let m=Number(a);await Ft({stockGoodsId:m,shopId:r,price:Number(l),platform:"xianyu"}),console.log(L.green("\u2713 \u4E0A\u67B6\u5DF2\u63D0\u4EA4\uFF0C\u6B63\u5728\u67E5\u8BE2\u8FDB\u5EA6..."));let P=await Eo(m,r,"xianyu"),_=P.status?.toLowerCase()!=="failed";console.log(_?L.green("\u2713 \u4E0A\u67B6\u6210\u529F"):L.red("\u2717 \u4E0A\u67B6\u5931\u8D25")),console.log(JSON.stringify(P,null,2))})),o}import{Command as Ve}from"commander";import qo from"chalk";function Xo(){let o=new Ve("shops");return o.description("\u67E5\u770B\u6240\u6709\u5DF2\u6388\u6743\u5E97\u94FA\uFF08\u8DE8\u5E73\u53F0\uFF09"),o.option("--json","\u8F93\u51FA JSON\uFF08\u4F9B AI Agent \u4F7F\u7528\uFF09"),o.action(g(async t=>{let e=await xt();if(t.json){console.log(JSON.stringify(To(e),null,2));return}if(!e.length){console.log(qo.yellow("\u672A\u627E\u5230\u5DF2\u6388\u6743\u7684\u5E97\u94FA")),console.log(qo.gray(" \u63D0\u793A: \u8BF7\u5148\u5728\u7B2C\u4E8C\u56DE\u5408 APP \u4E2D\u6388\u6743\u5E97\u94FA"));return}let{ShopsTable:r}=await Promise.resolve().then(()=>(Jo(),Go)),{renderComponent:n}=await Promise.resolve().then(()=>(rt(),pt));n(r,{shops:e,platform:"all"})})),o}import{Command as tr}from"commander";import or from"chalk";function Mo(){let o=new tr("stocks");return o.description("\u67E5\u770B\u6240\u6709\u4ED3\u5E93"),o.option("--json","\u8F93\u51FA JSON\uFF08\u4F9B AI Agent \u4F7F\u7528\uFF09"),o.action(g(async t=>{let e=await It();if(t.json){console.log(JSON.stringify(e,null,2));return}if(!e.length){console.log(or.yellow("\u672A\u627E\u5230\u4ED3\u5E93\u4FE1\u606F"));return}let{StocksTable:r}=await Promise.resolve().then(()=>(Qo(),_o)),{renderComponent:n}=await Promise.resolve().then(()=>(rt(),pt));n(r,{stocks:e})})),o}import{Command as er}from"commander";import Z from"chalk";function Fo(){let o=new er("list");return o.description("\u67E5\u770B\u4ED3\u5E93\u4E2D\u7684\u9009\u54C1\u5546\u54C1"),o.option("--stock-id <id>","\u4ED3\u5E93 ID\uFF08\u4ECE goods stocks \u83B7\u53D6\uFF09").option("--stock-goods-id <id>","\u5E93\u5B58\u5546\u54C1 ID").option("--page <n>","\u9875\u7801","1").option("--size <n>","\u6BCF\u9875\u6570\u91CF","20").option("--json","\u8F93\u51FA JSON\uFF08\u4F9B AI Agent \u4F7F\u7528\uFF09"),o.action(g(async t=>{let r=await St({stockId:t.stockId||void 0,stockGoodsId:t.stockGoodsId||void 0,page:Number(t.page)||1,size:Number(t.size)||20})??{items:[],total:0};if(t.json){r.items?.length?console.log(JSON.stringify(r,null,2)):console.log(JSON.stringify({...r,hint:"\u9009\u54C1\u5546\u54C1\u4E3A\u7A7A\uFF0C\u8BF7\u5148\u5728\u540E\u53F0\u751F\u6210\u9009\u54C1\u8868\u6570\u636E\u540E\u518D\u8BD5"},null,2));return}if(!r.items?.length){console.log(Z.yellow("\u6682\u65E0\u9009\u54C1\u5546\u54C1\uFF0C\u8BF7\u5148\u7ED1\u5B9A\u4ED3\u5E93\u6216\u5728\u540E\u53F0\u751F\u6210\u9009\u54C1\u8868\u6570\u636E"));return}console.log(Z.cyan(`
|
|
36
36
|
\u9009\u54C1\u5546\u54C1\uFF08\u5171 ${r.total} \u4EF6\uFF0C\u7B2C ${r.page} \u9875\uFF09
|
|
37
|
-
`));for(let n of r.items)console.log(` ${F.bold(n.goodsName)} ${n.size?F.gray(`| ${n.size}`):""}`),console.log(` \u54C1\u724C: ${n.brand} \u5EFA\u8BAE\u552E\u4EF7: \xA5${n.salePrice} stockGoodsId: ${F.green(n.stockGoodsId)}`),console.log(F.gray(` \u5206\u7C7B: ${n.cate1Name} > ${n.cate2Name} > ${n.cate3Name}`)),console.log()}catch(o){if(t.json){let r=o instanceof Error?o.message:String(o);console.log(JSON.stringify({success:!1,error:r})),process.exit(1)}m(o)}}),e}import{Command as ko}from"commander";import Ce from"chalk";var vo={init:"\u5F85\u4E0A\u67B6",up:"\u5DF2\u4E0A\u67B6",down:"\u5DF2\u4E0B\u67B6",fail:"\u5931\u8D25"};function Ie(){let e=new ko("listing");return e.description("\u67E5\u8BE2\u4E0A\u67B6\u5546\u54C1\u5217\u8868"),e.option("--id <id>","\u4E0A\u67B6\u8BB0\u5F55 ID").option("--stock-goods-id <id>","\u5E93\u5B58\u5546\u54C1 ID").option("--shop-id <id>","\u5E97\u94FA ID").option("--stock-id <id>","\u4ED3\u5E93 ID").option("-s, --status <status>","\u72B6\u6001\u8FC7\u6EE4\uFF08init/up/down/fail\uFF09").option("-p, --platform <platform>","\u5E73\u53F0","xianyu").option("--json","\u8F93\u51FA JSON\uFF08\u4F9B AI Agent \u4F7F\u7528\uFF09"),e.action(async t=>{try{let r=await le({id:t.id,stockGoodsId:t.stockGoodsId?Number(t.stockGoodsId):void 0,shopId:t.shopId,stockId:t.stockId,status:t.status,platform:t.platform})??{list:[],total:0};if(t.json){r.list?.length?console.log(JSON.stringify(r,null,2)):console.log(JSON.stringify({...r,hint:"\u6682\u65E0\u4E0A\u67B6\u8BB0\u5F55"},null,2));return}if(!r.list?.length){console.log(Ce.yellow("\u6682\u65E0\u4E0A\u67B6\u8BB0\u5F55"));return}console.log(Ce.green(`\u2705 \u5171 ${r.total} \u6761\u8BB0\u5F55
|
|
38
|
-
`))
|
|
39
|
-
\u26A0\uFE0F \u5373\u5C06\u6267\u884C\u4EE5\u4E0B\u64CD\u4F5C\uFF1A`)),console.log(
|
|
40
|
-
`));let{confirm:t}=await import("@inquirer/prompts");if(!await t({message:"\u786E\u8BA4\u5378\u8F7D\uFF1F",default:!1})){console.log(
|
|
41
|
-
\u2705 ${
|
|
42
|
-
\u26A0\uFE0F npm \u5378\u8F7D\u5931\u8D25 (exit code: ${s})`)),console.log(
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
37
|
+
`));for(let n of r.items)console.log(` ${Z.bold(n.goodsName)} ${n.size?Z.gray(`| ${n.size}`):""}`),console.log(` \u54C1\u724C: ${n.brand} \u5EFA\u8BAE\u552E\u4EF7: \xA5${n.salePrice} stockGoodsId: ${Z.green(n.stockGoodsId)}`),console.log(Z.gray(` \u5206\u7C7B: ${n.cate1Name} > ${n.cate2Name} > ${n.cate3Name}`)),console.log()})),o}import{Command as ar}from"commander";import cr from"chalk";rt();import{Box as p,Text as h}from"ink";import{jsx as c,jsxs as E}from"react/jsx-runtime";var rr={init:{label:"\u5F85\u4E0A\u67B6",color:"yellow"},up:{label:"\u5DF2\u4E0A\u67B6",color:"green"},down:{label:"\u5DF2\u4E0B\u67B6",color:"gray"},fail:{label:"\u5931\u8D25",color:"red"}},oo=4,eo=8,Ct=12,ro=10,no=6,so=8;function zo(o,t){return o.length>t?o.slice(0,t-1)+"\u2026":o}function Wo(o){if(!o)return"-";let t=new Date(o),e=r=>String(r).padStart(2,"0");return`${e(t.getMonth()+1)}/${e(t.getDate())} ${e(t.getHours())}:${e(t.getMinutes())}`}function nr({fillWidth:o}){return E(p,{flexDirection:"row",children:[c(p,{width:oo,children:c(h,{bold:!0,color:"white",children:"ID"})}),c(p,{width:eo,children:c(h,{bold:!0,color:"white",children:"\u72B6\u6001"})}),c(p,{width:Ct,children:c(h,{bold:!0,color:"white",children:"\u54C1\u724C"})}),c(p,{width:o,children:c(h,{bold:!0,color:"white",children:"\u5546\u54C1\u540D\u79F0"})}),c(p,{width:ro,children:c(h,{bold:!0,color:"white",children:"\u4EF7\u683C"})}),c(p,{width:no,children:c(h,{bold:!0,color:"white",children:"\u89C4\u683C"})}),c(p,{width:so,children:c(h,{bold:!0,color:"white",children:"\u5E93\u5B58ID"})})]})}function sr({item:o}){return c(p,{flexDirection:"column",children:c(h,{color:"gray",children:` shopId: ${o.shopId} thirdItemNo: ${o.thirdItemNo||"-"} outItemNo: ${o.outItemNo||"-"} \u8D27\u53F7: ${o.goodsNo||"-"} ${o.type||"-"} ${o.platform} \u521B\u5EFA: ${Wo(o.gmtCreate)} \u4FEE\u6539: ${Wo(o.gmtModified)}`})})}function ir({item:o,fillWidth:t}){let e=rr[o.status]??{label:o.status,color:"white"};return E(p,{flexDirection:"column",children:[E(p,{flexDirection:"row",children:[c(p,{width:oo,children:c(h,{color:"gray",children:o.id})}),c(p,{width:eo,children:c(h,{color:e.color,children:e.label})}),c(p,{width:Ct,children:c(h,{color:"cyan",children:zo(o.brandName||"-",Ct-1)})}),c(p,{width:t,children:c(h,{children:zo(o.goodsName,t-1)})}),c(p,{width:ro,children:E(h,{color:"yellow",children:["\xA5",o.price]})}),c(p,{width:no,children:c(h,{color:"gray",children:o.spec||"-"})}),c(p,{width:so,children:c(h,{color:"gray",children:o.stockGoodsId})})]}),c(sr,{item:o})]})}function Ho({items:o,total:t}){let e=process.stdout.columns||80,r=4,n=oo+eo+Ct+ro+no+so,s=Math.max(e-r-n,20),i=n+s;return E(p,{flexDirection:"column",marginTop:1,borderStyle:"round",borderColor:"gray",paddingX:1,children:[E(p,{flexDirection:"row",children:[c(h,{bold:!0,color:"cyan",children:"\u4E0A\u67B6\u5217\u8868"}),E(h,{color:"gray",children:[" \xB7 \u5171 ",t," \u6761"]})]}),E(p,{flexDirection:"column",marginTop:1,children:[c(nr,{fillWidth:s}),c(h,{color:"gray",children:"\u2500".repeat(i)}),o.map(a=>c(ir,{item:a,fillWidth:s},a.id))]})]})}function Vo(){let o=new ar("listing");return o.description("\u67E5\u8BE2\u4E0A\u67B6\u5546\u54C1\u5217\u8868"),o.option("--id <id>","\u4E0A\u67B6\u8BB0\u5F55 ID").option("--stock-goods-id <id>","\u5E93\u5B58\u5546\u54C1 ID").option("--shop-id <id>","\u5E97\u94FA ID").option("--stock-id <id>","\u4ED3\u5E93 ID").option("-s, --status <status>","\u72B6\u6001\u8FC7\u6EE4\uFF08init/up/down/fail\uFF09").option("-p, --platform <platform>","\u5E73\u53F0","xianyu").option("--json","\u8F93\u51FA JSON\uFF08\u4F9B AI Agent \u4F7F\u7528\uFF09"),o.action(g(async t=>{let r=await Ro({id:t.id,stockGoodsId:t.stockGoodsId?Number(t.stockGoodsId):void 0,shopId:t.shopId,stockId:t.stockId,status:t.status,platform:t.platform})??{items:[],total:0};if(t.json){r.items?.length?console.log(JSON.stringify(r,null,2)):console.log(JSON.stringify({...r,hint:"\u6682\u65E0\u4E0A\u67B6\u8BB0\u5F55"},null,2));return}if(!r.items?.length){console.log(cr.yellow("\u6682\u65E0\u4E0A\u67B6\u8BB0\u5F55"));return}Bt(Ho,{items:r.items,total:r.total})})),o}import{Command as lr}from"commander";import io from"chalk";function Ko(){let o=new lr("down");return o.description("\u4E0B\u67B6\u95F2\u9C7C\u5546\u54C1"),o.option("--id <id>","\u4E0A\u67B6\u8BB0\u5F55 ID").option("--stock-goods-id <id>","\u5E93\u5B58\u5546\u54C1 ID").option("--shop-id <id>","\u5E97\u94FA ID").option("--json","\u8F93\u51FA JSON\uFF08\u4F9B AI Agent \u4F7F\u7528\uFF09"),o.action(g(async t=>{if(!t.id&&!(t.stockGoodsId&&t.shopId)){t.json&&(console.log(JSON.stringify({success:!1,error:"\u8BF7\u6307\u5B9A\u4E0B\u67B6\u6761\u4EF6\uFF1A--id <id> \u6216 --stock-goods-id <id> --shop-id <id>"})),process.exit(1)),console.log(io.yellow("\u8BF7\u6307\u5B9A\u4E0B\u67B6\u6761\u4EF6\uFF1A--id <id> \u6216 --stock-goods-id <id> --shop-id <id>"));return}let e={};t.id&&(e.id=t.id),t.stockGoodsId&&(e.stockGoodsId=Number(t.stockGoodsId)),t.shopId&&(e.shopId=t.shopId),t.json||console.log(io.cyan("\u{1F4E6} \u6B63\u5728\u4E0B\u67B6\u5546\u54C1..."));let r=await ko(e);t.json?console.log(JSON.stringify({success:!0,data:r},null,2)):(console.log(io.green("\u2705 \u4E0B\u67B6\u6210\u529F")),console.log(JSON.stringify(r,null,2)))})),o}import{Command as dr}from"commander";import Tt from"chalk";function Yo(){let o=new dr("price");return o.description("\u4FEE\u6539\u95F2\u9C7C\u4E0A\u67B6\u5546\u54C1\u4EF7\u683C"),o.option("--id <id>","\u4E0A\u67B6\u8BB0\u5F55 ID").option("--stock-goods-id <id>","\u5E93\u5B58\u5546\u54C1 ID").option("--shop-id <id>","\u5E97\u94FA ID").option("--price <amount>","\u65B0\u4EF7\u683C\uFF08\u5FC5\u586B\uFF09").option("--json","\u8F93\u51FA JSON\uFF08\u4F9B AI Agent \u4F7F\u7528\uFF09"),o.action(g(async t=>{if(!t.price){t.json&&(console.log(JSON.stringify({success:!1,error:"--price <amount> \u4E3A\u5FC5\u586B\u53C2\u6570"})),process.exit(1)),console.log(Tt.yellow("--price <amount> \u4E3A\u5FC5\u586B\u53C2\u6570"));return}if(!t.id&&!(t.stockGoodsId&&t.shopId)){t.json&&(console.log(JSON.stringify({success:!1,error:"\u8BF7\u6307\u5B9A\u5546\u54C1\uFF1A--id <id> \u6216 --stock-goods-id <id> --shop-id <id>"})),process.exit(1)),console.log(Tt.yellow("\u8BF7\u6307\u5B9A\u5546\u54C1\uFF1A--id <id> \u6216 --stock-goods-id <id> --shop-id <id>"));return}let e={price:Number(t.price)};t.id&&(e.id=t.id),t.stockGoodsId&&(e.stockGoodsId=Number(t.stockGoodsId)),t.shopId&&(e.shopId=t.shopId),t.json||console.log(Tt.cyan(`\u{1F4B0} \u6B63\u5728\u4FEE\u6539\u4EF7\u683C\u4E3A ${t.price}...`));let r=await vo(e);t.json?console.log(JSON.stringify({success:!0,data:r},null,2)):(console.log(Tt.green("\u2705 \u4EF7\u683C\u4FEE\u6539\u6210\u529F")),console.log(JSON.stringify(r,null,2)))})),o}import{Command as ur}from"commander";import st from"chalk";function Zo(){let o=new ur("edit");return o.description("\u4FEE\u6539\u5DF2\u4E0A\u67B6\u5546\u54C1\u4FE1\u606F\uFF08\u6807\u9898\u3001\u63CF\u8FF0\u3001\u54C1\u724C\u3001\u7C7B\u76EE\u3001\u56FE\u7247\u3001\u5C5E\u6027\u7B49\uFF09"),o.option("--id <id>","\u5546\u54C1\u4E0A\u67B6 ID\uFF08goodsListingId\uFF0C\u63A8\u8350\uFF09").option("--stock-goods-id <id>","\u5E93\u5B58\u5546\u54C1 ID\uFF08\u4E0E --account \u914D\u5408\uFF09").option("--account <shopId>","\u95F2\u9C7C\u7528\u6237\u540D/\u5E97\u94FA ID\uFF08\u4E0E --stock-goods-id \u914D\u5408\uFF09").option("--title <title>","\u5546\u54C1\u6807\u9898").option("--desc <desc>","\u5546\u54C1\u63CF\u8FF0").option("--category-id <id>","\u5546\u54C1\u7C7B\u76EE ID\uFF08\u5927\u5206\u7C7B\uFF0C\u540E\u7AEF\u5FC5\u586B\uFF09").option("--channel-cat-id <id>","\u6E20\u9053\u7C7B\u76EE ID\uFF08\u5C0F\u5206\u7C7B\uFF0C\u540E\u7AEF\u5FC5\u586B\uFF09").option("--image-ids <ids>","\u56FE\u7247 ID \u5217\u8868\uFF08\u9017\u53F7\u5206\u9694\uFF09").option("--item-attrs <json>","\u5546\u54C1\u5C5E\u6027\u5217\u8868\uFF08JSON \u5B57\u7B26\u4E32\uFF09").option("--brand-name <name>","\u54C1\u724C\u540D\u79F0").option("--stuff-status <status>","\u6210\u8272\u7B49\u7EA7\uFF1A100=\u5168\u65B0 -1=\u51C6\u65B0 99=99\u65B0 95=95\u65B0 90=9\u65B0").option("--goods-no <no>","\u8D27\u53F7").option("--original-price <price>","\u539F\u4EF7\uFF08\u5355\u4F4D\uFF1A\u5143\uFF09").option("--size <size>","\u5C3A\u7801").option("--json","\u8F93\u51FA JSON\uFF08\u4F9B AI Agent \u4F7F\u7528\uFF09"),o.action(g(async t=>{if(!t.id&&!(t.stockGoodsId&&t.account)){t.json&&(console.log(JSON.stringify({success:!1,status:400,error:"\u8BF7\u6307\u5B9A\u5546\u54C1\uFF1A--id <goodsListingId> \u6216 --stock-goods-id <id> --account <shopId>"})),process.exit(1)),console.log(st.yellow("\u8BF7\u6307\u5B9A\u5546\u54C1\uFF1A--id <goodsListingId> \u6216 --stock-goods-id <id> --account <shopId>"));return}let e={};if(t.id&&(e.goodsListingId=Number(t.id)),t.stockGoodsId&&(e.stockGoodsId=Number(t.stockGoodsId)),t.account&&(e.account=t.account),t.title&&(e.title=t.title),t.desc&&(e.desc=t.desc),t.categoryId&&(e.categoryId=Number(t.categoryId)),t.channelCatId&&(e.channelCatId=t.channelCatId),t.imageIds&&(e.imageIdList=t.imageIds.split(",").map(s=>s.trim())),t.brandName&&(e.brandName=t.brandName),t.stuffStatus&&(e.stuffStatus=Number(t.stuffStatus)),t.goodsNo&&(e.goodsNo=t.goodsNo),t.originalPrice&&(e.originalPrice=Number(t.originalPrice)),t.size&&(e.size=t.size),t.itemAttrs)try{e.itemAttrList=JSON.parse(t.itemAttrs)}catch{t.json&&(console.log(JSON.stringify({success:!1,status:400,error:"--item-attrs JSON \u89E3\u6790\u5931\u8D25"})),process.exit(1)),console.log(st.yellow("--item-attrs JSON \u89E3\u6790\u5931\u8D25"));return}if(!Object.keys(e).some(s=>!["goodsListingId","stockGoodsId","account"].includes(s))){t.json&&(console.log(JSON.stringify({success:!1,status:400,error:"\u672A\u6307\u5B9A\u9700\u8981\u4FEE\u6539\u7684\u5B57\u6BB5"})),process.exit(1)),console.log(st.yellow("\u672A\u6307\u5B9A\u9700\u8981\u4FEE\u6539\u7684\u5B57\u6BB5"));return}t.json||console.log(st.cyan("\u6B63\u5728\u4FEE\u6539\u5546\u54C1\u4FE1\u606F..."));let n=await No(e);t.json?console.log(JSON.stringify({success:!0,data:n},null,2)):(console.log(st.green("\u2705 \u5546\u54C1\u4FE1\u606F\u4FEE\u6539\u6210\u529F")),console.log(JSON.stringify(n,null,2)))})),o}import{Command as tt}from"commander";import y from"chalk";var mr={100:"\u5168\u65B0",[-1]:"\u51C6\u65B0",99:"99\u65B0",95:"95\u65B0",90:"9\u65B0"};function te(){let o=new tt("hang-up");return o.description("\u95F2\u9C7C\u6302\u552E\u4E0A\u67B6\uFF08\u5B8C\u6574\u5546\u54C1\u4FE1\u606F\u6A21\u5F0F\uFF09"),o.addCommand(new tt("categories").description("\u83B7\u53D6\u95F2\u9C7C\u7C7B\u76EE\u5217\u8868\uFF08\u5927\u5206\u7C7B \u2192 \u5C0F\u5206\u7C7B\uFF09").option("--sp-biz-type <n>","\u4E1A\u52A1\u5206\u7C7B\uFF0C16=\u5962\u54C1","16").option("--json","\u8F93\u51FA JSON\uFF08\u4F9B AI Agent \u4F7F\u7528\uFF09").action(g(async t=>{let e=await Do(Number(t.spBizType));if(t.json){console.log(JSON.stringify(e,null,2));return}let r=new Map;for(let n of e){let s=String(n.catId);r.has(s)||r.set(s,{catName:n.catName,children:[]}),r.get(s).children.push({channel:n.channel,channelCatId:n.channelCatId})}for(let[n,s]of r){console.log(y.bold(`${s.catName} (catId: ${y.green(n)})`));for(let i of s.children)console.log(` ${i.channel} (channelCatId: ${y.green(i.channelCatId)})`)}}))),o.addCommand(new tt("props").description("\u83B7\u53D6\u6307\u5B9A\u7C7B\u76EE\u4E0B\u7684\u5C5E\u6027\u5217\u8868\uFF08\u542B\u53EF\u9009\u503C\uFF09").requiredOption("--channel-cat-id <id>","\u5C0F\u5206\u7C7B ID\uFF08\u4ECE categories \u83B7\u53D6\uFF09").option("--json","\u8F93\u51FA JSON\uFF08\u4F9B AI Agent \u4F7F\u7528\uFF09").action(g(async t=>{let e=await Uo(t.channelCatId);if(t.json){console.log(JSON.stringify(e,null,2));return}for(let r of e)if(console.log(y.bold(`
|
|
38
|
+
${r.propName} (propId: ${r.propId})`)),r.propsValues?.length)for(let n of r.propsValues)console.log(` ${n.valueName} (valueId: ${n.valueId})`);else console.log(y.gray(" \uFF08\u4F7F\u7528 brands \u5B50\u547D\u4EE4\u641C\u7D22\uFF09"))}))),o.addCommand(new tt("brands").description("\u641C\u7D22\u95F2\u9C7C\u54C1\u724C\uFF08\u6309\u5173\u952E\u5B57\u8FC7\u6EE4\uFF09").requiredOption("--channel-cat-id <id>","\u5C0F\u5206\u7C7B ID").requiredOption("--prop-id <id>","\u5C5E\u6027 ID\uFF08\u54C1\u724C\u5C5E\u6027\u7684 propId\uFF09").requiredOption("--key <keyword>","\u641C\u7D22\u5173\u952E\u5B57").option("--json","\u8F93\u51FA JSON\uFF08\u4F9B AI Agent \u4F7F\u7528\uFF09").action(g(async t=>{let e=await jo(t.channelCatId,t.propId,t.key);if(t.json){console.log(JSON.stringify(e,null,2));return}if(!e.length){console.log(y.yellow("\u672A\u627E\u5230\u5339\u914D\u7684\u54C1\u724C"));return}for(let r of e)console.log(` ${r.valueName} (valueId: ${r.valueId})`)}))),o.addCommand(new tt("upload-images").description("\u6279\u91CF\u4E0A\u4F20\u56FE\u7247\u5230\u95F2\u9C7C\uFF08\u6302\u552E\u524D\u5FC5\u987B\u5148\u4E0A\u4F20\u56FE\u7247\uFF09").requiredOption("--shop-id <id>","\u5E97\u94FA ID").requiredOption("--files <paths>","\u56FE\u7247\u6587\u4EF6\u8DEF\u5F84\uFF0C\u9017\u53F7\u5206\u9694").option("--json","\u8F93\u51FA JSON\uFF08\u4F9B AI Agent \u4F7F\u7528\uFF09").action(g(async t=>{let e=t.files.split(",").map(n=>n.trim()).filter(Boolean);if(e.length===0){t.json&&(console.log(JSON.stringify({success:!1,error:"\u8BF7\u63D0\u4F9B\u81F3\u5C11\u4E00\u5F20\u56FE\u7247"})),process.exit(1)),console.log(y.yellow("\u8BF7\u63D0\u4F9B\u81F3\u5C11\u4E00\u5F20\u56FE\u7247"));return}t.json||console.log(y.cyan(`\u6B63\u5728\u4E0A\u4F20 ${e.length} \u5F20\u56FE\u7247...`));let r=await Lo(t.shopId,e);if(t.json)console.log(JSON.stringify({success:!0,images:r},null,2));else{console.log(y.green(`\u4E0A\u4F20\u6210\u529F\uFF0C\u5171 ${r.length} \u5F20`));for(let n of r)console.log(` \u56FE\u7247ID: ${n.value}`)}}))),o.addCommand(new tt("submit").description("\u63D0\u4EA4\u6302\u552E\u4E0A\u67B6").requiredOption("--shop-id <id>","\u5E97\u94FA ID\uFF08\u5373\u95F2\u9C7C\u7528\u6237\u540D account\uFF09").requiredOption("--title <title>","\u5546\u54C1\u6807\u9898").requiredOption("--price <amount>","\u552E\u4EF7").requiredOption("--category-id <id>","\u5927\u5206\u7C7B ID\uFF08\u4ECE categories \u83B7\u53D6\uFF09").requiredOption("--channel-cat-id <id>","\u5C0F\u5206\u7C7B ID\uFF08\u4ECE categories \u83B7\u53D6\uFF09").requiredOption("--image-ids <ids>","\u56FE\u7247 ID \u5217\u8868\uFF0C\u9017\u53F7\u5206\u9694\uFF08\u5148\u901A\u8FC7 upload-images \u83B7\u53D6\uFF09").requiredOption("--stuff-status <n>","\u6210\u8272\uFF1A100 \u5168\u65B0 / -1 \u51C6\u65B0 / 99 99\u65B0 / 95 95\u65B0 / 90 9\u65B0").option("--item-attrs <json>",'\u5546\u54C1\u5C5E\u6027\u5217\u8868 JSON\uFF0C\u683C\u5F0F: [{"propId":"x","valueId":"y","valueName":"z"}]').option("--brand-name <name>","\u54C1\u724C\u540D\u79F0").option("--desc <desc>","\u5546\u54C1\u63CF\u8FF0").option("--size <size>","\u5C3A\u7801").option("--goods-no <no>","\u8D27\u53F7").option("--original-price <amount>","\u539F\u4EF7").option("--trade-type <n>","\u4EA4\u6613\u65B9\u5F0F\uFF1A0 \u4EC5\u5728\u7EBF / 1 \u4EC5\u7EBF\u4E0B / 2 \u7EBF\u4E0A\u6216\u7EBF\u4E0B","0").option("--transport-fee <amount>","\u8FD0\u8D39\uFF08\u9ED8\u8BA4 0 \u5305\u90AE\uFF09","0").option("--yhb","\u662F\u5426\u5F00\u542F\u9A8C\u8D27\u5B9D").requiredOption("--out-item-no <no>","\u5546\u5BB6\u7F16\u7801\uFF08\u540C\u5E97\u94FA\u552F\u4E00\uFF0C\u7528\u6237\u81EA\u5B9A\u4E49\uFF09").option("--division-id <id>","\u884C\u653F\u533A\u5212 ID\uFF08\u5E02\u7EA7 ID\uFF0C\u9ED8\u8BA4\u676D\u5DDE 330100\uFF09","330100").option("--json","\u8F93\u51FA JSON\uFF08\u4F9B AI Agent \u4F7F\u7528\uFF09").action(g(async t=>{let e=t.imageIds.split(",").map(s=>s.trim()),r={account:t.shopId,title:t.title,reservePrice:Number(t.price),categoryId:Number(t.categoryId),channelCatId:t.channelCatId,imageIdList:e,stuffStatus:Number(t.stuffStatus),itemBizType:2,spBizType:"16",tradeType:Number(t.tradeType)||0,transportFee:Number(t.transportFee)||0,yhb:t.yhb??!1,...t.brandName&&{brandName:t.brandName},...t.desc&&{desc:t.desc},...t.size&&{size:t.size},...t.goodsNo&&{goodsNo:t.goodsNo},...t.originalPrice&&{originalPrice:Number(t.originalPrice)},outItemNo:t.outItemNo,divisionId:Number(t.divisionId)||330100,apiAfterSalesDo:{supportFd10msPolicy:!1,supportFd24hsPolicy:!1,supportNfrPolicy:!1,supportSdrPolicy:!1,supportVnrPolicy:!1,supportGpaPolicy:!1,supportFd48hsPolicy:!1},...t.itemAttrs&&{itemAttrList:JSON.parse(t.itemAttrs)}};t.json||(console.log(y.cyan("\u6B63\u5728\u63D0\u4EA4\u6302\u552E...")),console.log(y.gray(` \u6807\u9898: ${r.title}`)),console.log(y.gray(` \u552E\u4EF7: \xA5${r.reservePrice}`)),console.log(y.gray(` \u6210\u8272: ${mr[r.stuffStatus]??r.stuffStatus}`)),console.log(y.gray(` \u56FE\u7247: ${e.length} \u5F20`)),r.itemAttrList?.length&&console.log(y.gray(` \u5C5E\u6027: ${r.itemAttrList.length} \u9879`)));let n=await Oo(r);t.json?console.log(JSON.stringify({success:!0,data:n},null,2)):(console.log(y.green("\u6302\u552E\u63D0\u4EA4\u6210\u529F")),console.log(JSON.stringify(n,null,2)))}))),o}function oe(){let o=new gr("goods");return o.description("\u5546\u54C1\u7BA1\u7406"),o.addCommand(Xo()),o.addCommand(Mo()),o.addCommand(Fo()),o.addCommand(Vo()),o.addCommand(Ko()),o.addCommand(Yo()),o.addCommand(Zo()),o.addCommand($o()),o.addCommand(te()),o}import{Command as pr}from"commander";import O from"chalk";import{promises as fr}from"node:fs";import hr from"node:path";import yr from"node:os";import{spawn as wr}from"node:child_process";var bt="@round2ai/r2-cli";function ee(){let o=new pr("uninstall");return o.description("\u5378\u8F7D R2-CLI \u5E76\u6E05\u9664\u6240\u6709\u914D\u7F6E"),o.action(async()=>{try{console.log(O.yellow(`
|
|
39
|
+
\u26A0\uFE0F \u5373\u5C06\u6267\u884C\u4EE5\u4E0B\u64CD\u4F5C\uFF1A`)),console.log(O.gray(" 1. \u5220\u9664\u914D\u7F6E\u76EE\u5F55 ~/.r2-cli/")),console.log(O.gray(` 2. \u5168\u5C40\u5378\u8F7D ${bt}
|
|
40
|
+
`));let{confirm:t}=await import("@inquirer/prompts");if(!await t({message:"\u786E\u8BA4\u5378\u8F7D\uFF1F",default:!1})){console.log(O.gray("\u5DF2\u53D6\u6D88\u5378\u8F7D"));return}let r=hr.join(yr.homedir(),".r2-cli");try{await fr.rm(r,{recursive:!0,force:!0}),console.log(O.green("\u2705 \u914D\u7F6E\u6587\u4EF6\u5DF2\u6E05\u9664"))}catch{console.log(O.yellow("\u26A0\uFE0F \u914D\u7F6E\u76EE\u5F55\u4E0D\u5B58\u5728\u6216\u65E0\u6CD5\u5220\u9664\uFF08\u53EF\u5FFD\u7565\uFF09"))}console.log(O.cyan(`\u6B63\u5728\u5378\u8F7D ${bt}...`)),wr("npm",["uninstall","-g",bt],{stdio:"inherit",shell:!0}).on("exit",s=>{s===0?console.log(O.green(`
|
|
41
|
+
\u2705 ${bt} \u5DF2\u5378\u8F7D`)):(console.log(O.yellow(`
|
|
42
|
+
\u26A0\uFE0F npm \u5378\u8F7D\u5931\u8D25 (exit code: ${s})`)),console.log(O.gray(" \u5982\u901A\u8FC7 yarn/pnpm \u5B89\u88C5\uFF0C\u8BF7\u624B\u52A8\u5378\u8F7D"))),process.exit(s??1)})}catch(t){v(t)}}),o}import{Command as Sr}from"commander";import it from"chalk";import{spawn as Cr,execSync as Tr}from"node:child_process";import{readFileSync as xr}from"node:fs";import{join as Ir}from"node:path";function Pt(){for(let o of["../package.json","../../package.json"])try{return JSON.parse(xr(Ir(import.meta.dirname,o),"utf-8")).version}catch{}return"0.0.0"}var re="@round2ai/r2-cli";function br(o,t){return new Promise(e=>{let r=Cr(o,t,{stdio:"inherit"});r.on("close",n=>e(n??1)),r.on("error",()=>e(1))})}function ne(){return new Sr("update").description("\u4E00\u952E\u66F4\u65B0 CLI \u548C\u6280\u80FD").action(async()=>{let o=Pt();console.log(it.cyan(`\u5F53\u524D\u7248\u672C: ${o}`)),console.log(it.cyan("\u6B63\u5728\u66F4\u65B0 CLI...")),await br("npm",["install","-g",`${re}@latest`])!==0&&(console.error(it.red(`
|
|
43
|
+
\u2717 update failed \xB7 Try: npm install -g ${re}@latest`)),process.exit(1));let e=o;try{e=Tr("r2-cli --version",{encoding:"utf-8"}).trim()||o}catch{}console.log(it.green(`
|
|
44
|
+
\u2713 \u66F4\u65B0\u5B8C\u6210: ${o} \u2192 ${e}`)),console.log(it.green("\u2713 \u6280\u80FD\u5DF2\u540C\u6B65\u66F4\u65B0"))})}function se(o){let t=o.command("auth").description("\u6388\u6743\u7BA1\u7406");t.addCommand(Xt()),t.addCommand(_t()),t.addCommand(Qt()),t.addCommand(Mt()),o.addCommand(oe()),o.addCommand(ee()),o.addCommand(ne())}import ie from"chalk";var ae="@round2ai/r2-cli",Pr=[`https://registry.npmmirror.com/${encodeURIComponent(ae)}/latest`,`https://registry.npmjs.org/${encodeURIComponent(ae)}/latest`],Ar=5e3;async function kr(o){let t=new AbortController,e=setTimeout(()=>t.abort(),Ar);try{let r=await fetch(o,{signal:t.signal});return r.ok?(await r.json()).version??null:null}catch{return null}finally{clearTimeout(e)}}async function vr(){let o=await Promise.allSettled(Pr.map(kr));for(let t of o)if(t.status==="fulfilled"&&t.value)return t.value;return null}function Nr(o,t){let e=o.split(".").map(Number),r=t.split(".").map(Number);for(let n=0;n<3;n++)if((e[n]??0)!==(r[n]??0))return(e[n]??0)>(r[n]??0);return!1}async function ce(o){let t=await vr();t&&Nr(t,o)&&Rr(o,t)}function Rr(o,t){console.error(ie.yellow(`
|
|
45
|
+
Update available: ${o} \u2192 ${t}`)+ie.gray(`
|
|
46
|
+
Run: r2-cli update
|
|
47
|
+
`))}async function Or(){let{default:o}=await import("figlet");console.log(ot.cyan.bold(o.textSync("R2-CLI",{font:"Standard",horizontalLayout:"full"}))),console.log(ot.gray(` \u5411 AI \u5F00\u653E\u4E8C\u624B\u6F6E\u5962\u4EA4\u6613\u5168\u94FE\u8DEF\u80FD\u529B
|
|
48
|
+
`))}function Dr(){let o=new Lr;o.name("r2-cli").description("R2-CLI\uFF0C\u5411 AI \u5F00\u653E\u4E8C\u624B\u6F6E\u5962\u4EA4\u6613\u5168\u94FE\u8DEF\u80FD\u529B");let t=Pt();t==="0.0.0"&&console.error(ot.yellow("Warning: unable to read version from package.json")),o.version(t,"-v, --version");let e=ce(t);return o.configureOutput({writeErr:r=>{console.error(ot.red(r.replace("error:","").trim()))}}),o.action(async()=>{await Or(),o.help()}),se(o),{program:o,updateCheckPromise:e}}function le(){console.log(ot.gray(`
|
|
49
|
+
\u64CD\u4F5C\u5DF2\u53D6\u6D88`)),process.exit(130)}process.on("SIGINT",le);process.on("SIGTERM",le);var{program:Ur,updateCheckPromise:jr}=Dr();Ur.parse(process.argv);jr.catch(o=>{console.error(ot.gray(`[update-check] ${o instanceof Error?o.message:String(o)}`))});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@round2ai/r2-cli",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.12",
|
|
4
4
|
"description": "R2-CLI,向 AI 开放二手潮奢交易全链路能力",
|
|
5
5
|
"main": "dist/r2-cli.js",
|
|
6
6
|
"type": "module",
|
|
@@ -11,7 +11,9 @@
|
|
|
11
11
|
"postinstall": "node scripts/install-skills.js",
|
|
12
12
|
"build": "cross-env NODE_ENV=development node scripts/build.js",
|
|
13
13
|
"build:prod": "cross-env NODE_ENV=production node scripts/build.js",
|
|
14
|
-
"dev": "node scripts/dev.js"
|
|
14
|
+
"dev": "node scripts/dev.js",
|
|
15
|
+
"test": "vitest run",
|
|
16
|
+
"test:watch": "vitest"
|
|
15
17
|
},
|
|
16
18
|
"keywords": [
|
|
17
19
|
"round2ai",
|
|
@@ -25,7 +27,7 @@
|
|
|
25
27
|
],
|
|
26
28
|
"files": [
|
|
27
29
|
"dist",
|
|
28
|
-
"scripts",
|
|
30
|
+
"scripts/install-skills.js",
|
|
29
31
|
"skills",
|
|
30
32
|
"package.json",
|
|
31
33
|
"README.md"
|
|
@@ -56,6 +58,7 @@
|
|
|
56
58
|
"cross-env": "^10.1.0",
|
|
57
59
|
"dotenv": "^17.4.2",
|
|
58
60
|
"esbuild": "^0.28.0",
|
|
59
|
-
"typescript": "^6.0.2"
|
|
61
|
+
"typescript": "^6.0.2",
|
|
62
|
+
"vitest": "^4.1.5"
|
|
60
63
|
}
|
|
61
64
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* postinstall: 将 skills/ 复制到 ~/.agents/skills/
|
|
2
|
+
* postinstall: 将 skills/ 复制到 ~/.agents/skills/
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
5
|
import fs from "node:fs";
|
|
@@ -10,7 +10,6 @@ import { fileURLToPath } from "node:url";
|
|
|
10
10
|
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
11
11
|
const pkgSkillsDir = path.join(__dirname, "..", "skills");
|
|
12
12
|
const agentsDir = path.join(os.homedir(), ".agents", "skills");
|
|
13
|
-
const claudeDir = path.join(os.homedir(), ".claude", "skills");
|
|
14
13
|
|
|
15
14
|
if (!fs.existsSync(pkgSkillsDir)) process.exit(0);
|
|
16
15
|
|
|
@@ -18,37 +17,47 @@ fs.mkdirSync(agentsDir, { recursive: true });
|
|
|
18
17
|
|
|
19
18
|
for (const name of fs.readdirSync(pkgSkillsDir)) {
|
|
20
19
|
const rawSrc = path.join(pkgSkillsDir, name);
|
|
21
|
-
// npm 包内是真实目录,本地开发可能是 symlink → 解析真实路径
|
|
22
20
|
let src;
|
|
23
21
|
try { src = fs.realpathSync(rawSrc); } catch { continue; }
|
|
24
22
|
if (!fs.statSync(src).isDirectory()) continue;
|
|
25
23
|
|
|
26
24
|
const dest = path.join(agentsDir, name);
|
|
27
|
-
// 清空目标目录中的旧残留文件
|
|
28
25
|
if (fs.existsSync(dest)) {
|
|
29
26
|
for (const old of fs.readdirSync(dest)) {
|
|
30
|
-
|
|
27
|
+
const oldPath = path.join(dest, old);
|
|
28
|
+
fs.statSync(oldPath).isDirectory()
|
|
29
|
+
? fs.rmSync(oldPath, { recursive: true })
|
|
30
|
+
: fs.unlinkSync(oldPath);
|
|
31
31
|
}
|
|
32
32
|
}
|
|
33
33
|
fs.mkdirSync(dest, { recursive: true });
|
|
34
34
|
|
|
35
35
|
for (const file of fs.readdirSync(src)) {
|
|
36
|
-
|
|
36
|
+
const fileSrc = path.join(src, file);
|
|
37
|
+
const fileDest = path.join(dest, file);
|
|
38
|
+
if (fs.statSync(fileSrc).isDirectory()) {
|
|
39
|
+
copyDir(fileSrc, fileDest);
|
|
40
|
+
} else {
|
|
41
|
+
fs.copyFileSync(fileSrc, fileDest);
|
|
42
|
+
}
|
|
37
43
|
}
|
|
44
|
+
}
|
|
38
45
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
} catch {
|
|
47
|
-
// Windows 权限不足时 fallback:直接复制
|
|
48
|
-
fs.mkdirSync(link, { recursive: true });
|
|
49
|
-
for (const file of fs.readdirSync(dest)) {
|
|
50
|
-
fs.copyFileSync(path.join(dest, file), path.join(link, file));
|
|
51
|
-
}
|
|
46
|
+
function copyDir(src, dest) {
|
|
47
|
+
if (fs.existsSync(dest)) {
|
|
48
|
+
for (const old of fs.readdirSync(dest)) {
|
|
49
|
+
const oldPath = path.join(dest, old);
|
|
50
|
+
fs.statSync(oldPath).isDirectory()
|
|
51
|
+
? fs.rmSync(oldPath, { recursive: true })
|
|
52
|
+
: fs.unlinkSync(oldPath);
|
|
52
53
|
}
|
|
53
54
|
}
|
|
55
|
+
fs.mkdirSync(dest, { recursive: true });
|
|
56
|
+
for (const file of fs.readdirSync(src)) {
|
|
57
|
+
const fileSrc = path.join(src, file);
|
|
58
|
+
const fileDest = path.join(dest, file);
|
|
59
|
+
fs.statSync(fileSrc).isDirectory()
|
|
60
|
+
? copyDir(fileSrc, fileDest)
|
|
61
|
+
: fs.copyFileSync(fileSrc, fileDest);
|
|
62
|
+
}
|
|
54
63
|
}
|