@coze/cli 0.0.4 → 0.1.0-alpha.0f8b9e
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/{LICENSE → LICENSE.md} +1 -1
- package/README.md +479 -16
- package/bin/main +21 -0
- package/lib/cli.js +41613 -0
- package/lib/index-SwtgDxQR.js +25171 -0
- package/lib/send-message.worker.js +52 -0
- package/package.json +65 -51
- package/bin.mjs +0 -2
- package/dist/cli.d.ts +0 -1
- package/dist/cli.mjs +0 -1
- package/dist/commands/base.d.ts +0 -15
- package/dist/commands/login.d.ts +0 -6
- package/dist/commands/logout.d.ts +0 -8
- package/dist/helpers/constants.d.ts +0 -10
- package/dist/helpers/logger.d.ts +0 -7
- package/dist/helpers/package.d.ts +0 -8
- package/dist/helpers/request.d.ts +0 -3
- package/dist/helpers/types.d.ts +0 -16
- package/dist/index.d.ts +0 -1
- package/dist/index.mjs +0 -1
- package/dist/npm.d.ts +0 -28
- package/dist/oauth.d.ts +0 -9
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const process = require('process');
|
|
4
|
+
const index = require('./index-SwtgDxQR.js');
|
|
5
|
+
require('mitt');
|
|
6
|
+
require('crypto');
|
|
7
|
+
require('form-data');
|
|
8
|
+
require('url');
|
|
9
|
+
require('http');
|
|
10
|
+
require('https');
|
|
11
|
+
require('http2');
|
|
12
|
+
require('util');
|
|
13
|
+
require('stream');
|
|
14
|
+
require('assert');
|
|
15
|
+
require('tty');
|
|
16
|
+
require('os');
|
|
17
|
+
require('zlib');
|
|
18
|
+
require('events');
|
|
19
|
+
require('child_process');
|
|
20
|
+
require('node:path');
|
|
21
|
+
require('fs');
|
|
22
|
+
require('path');
|
|
23
|
+
require('fs/promises');
|
|
24
|
+
require('lodash');
|
|
25
|
+
require('undici');
|
|
26
|
+
|
|
27
|
+
async function main() {
|
|
28
|
+
try {
|
|
29
|
+
const payloadStr = process.argv[2];
|
|
30
|
+
if (!payloadStr) {
|
|
31
|
+
throw new Error('No payload provided');
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const payload = index.safeJsonParse(
|
|
35
|
+
payloadStr,
|
|
36
|
+
undefined,
|
|
37
|
+
);
|
|
38
|
+
|
|
39
|
+
if (!payload) {
|
|
40
|
+
throw new Error('Invalid payload');
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
await index.sendProjectChatMessage(payload);
|
|
44
|
+
|
|
45
|
+
process.exit(0);
|
|
46
|
+
} catch (err) {
|
|
47
|
+
console.error('❌ Worker error:', err);
|
|
48
|
+
process.exit(1);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
main();
|
package/package.json
CHANGED
|
@@ -1,68 +1,82 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@coze/cli",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
"coze",
|
|
7
|
-
"@coze/cli",
|
|
8
|
-
"cli"
|
|
9
|
-
],
|
|
3
|
+
"version": "0.1.0-alpha.0f8b9e",
|
|
4
|
+
"private": false,
|
|
5
|
+
"description": "tmp",
|
|
10
6
|
"license": "MIT",
|
|
11
|
-
"author": "
|
|
12
|
-
"
|
|
13
|
-
"types": "dist/index.d.ts",
|
|
7
|
+
"author": "fanwenjie.fe@bytedance.com",
|
|
8
|
+
"maintainers": [],
|
|
14
9
|
"bin": {
|
|
15
|
-
"coze": "
|
|
10
|
+
"coze": "bin/main"
|
|
16
11
|
},
|
|
17
12
|
"files": [
|
|
18
|
-
"
|
|
19
|
-
"
|
|
13
|
+
"lib",
|
|
14
|
+
"bin",
|
|
20
15
|
"README.md",
|
|
21
|
-
"
|
|
22
|
-
"
|
|
23
|
-
"
|
|
24
|
-
"!**/*.map",
|
|
25
|
-
"!**/*.tsbuildinfo"
|
|
16
|
+
"LICENSE.md",
|
|
17
|
+
"!**/*.tsbuildinfo",
|
|
18
|
+
"!**/*.map"
|
|
26
19
|
],
|
|
27
20
|
"scripts": {
|
|
28
|
-
"
|
|
21
|
+
"audit:post": "pack-audit post",
|
|
22
|
+
"audit:pre": "pack-audit pre",
|
|
23
|
+
"prebuild": "tsx scripts/prebuild.ts",
|
|
24
|
+
"build": "tsx scripts/build.ts",
|
|
29
25
|
"lint": "eslint ./ --cache",
|
|
30
|
-
"release": "
|
|
31
|
-
"
|
|
26
|
+
"pre-release": "tsx scripts/pre-release.ts",
|
|
27
|
+
"prepublishOnly": "npm run pre-release",
|
|
32
28
|
"test": "vitest --run --passWithNoTests",
|
|
33
|
-
"test:
|
|
29
|
+
"test:all": "bash scripts/test-coverage.sh",
|
|
30
|
+
"test:cov": "vitest --run --passWithNoTests --coverage",
|
|
31
|
+
"test:e2e": "NODE_ENV=test bash scripts/e2e.sh"
|
|
34
32
|
},
|
|
35
33
|
"dependencies": {
|
|
36
|
-
"
|
|
37
|
-
"
|
|
38
|
-
"@npmcli/config": "~8.3.4",
|
|
39
|
-
"@rsbuild/core": "^1.0.11",
|
|
40
|
-
"@rsbuild/plugin-less": "^1.0.3",
|
|
41
|
-
"@rsbuild/plugin-react": "^1.0.3",
|
|
42
|
-
"@rslib/core": "^0.1.2",
|
|
43
|
-
"axios": "^1.7.7",
|
|
44
|
-
"chokidar": "^4.0.1",
|
|
34
|
+
"ahooks": "~3.9.6",
|
|
35
|
+
"chalk": "^4.1.2",
|
|
45
36
|
"commander": "~12.1.0",
|
|
46
|
-
"
|
|
47
|
-
"
|
|
48
|
-
"
|
|
49
|
-
"lodash": "^4.17.
|
|
50
|
-
"
|
|
51
|
-
"
|
|
52
|
-
"
|
|
53
|
-
"
|
|
54
|
-
"
|
|
37
|
+
"form-data": "^4.0.0",
|
|
38
|
+
"http-proxy-agent": "~8.0.0",
|
|
39
|
+
"https-proxy-agent": "~8.0.0",
|
|
40
|
+
"lodash": "^4.17.22",
|
|
41
|
+
"marked": "^15.0.7",
|
|
42
|
+
"marked-terminal": "~7.3.0",
|
|
43
|
+
"mitt": "~3.0.1",
|
|
44
|
+
"omelette": "~0.4.17",
|
|
45
|
+
"react": "~18.3.1",
|
|
46
|
+
"shelljs": "^0.10.0",
|
|
47
|
+
"undici": "~7.24.5",
|
|
48
|
+
"ws": "^8.18.0"
|
|
55
49
|
},
|
|
56
50
|
"devDependencies": {
|
|
57
|
-
"@
|
|
58
|
-
"@
|
|
59
|
-
"@
|
|
60
|
-
"@
|
|
61
|
-
"@
|
|
62
|
-
"
|
|
63
|
-
"
|
|
64
|
-
"
|
|
65
|
-
"
|
|
66
|
-
"
|
|
51
|
+
"@coze-arch/api-schema": "workspace:*",
|
|
52
|
+
"@coze-arch/eslint-config": "workspace:*",
|
|
53
|
+
"@coze-arch/pack-audit": "workspace:*",
|
|
54
|
+
"@coze-arch/request": "workspace:*",
|
|
55
|
+
"@coze-arch/ts-config": "workspace:*",
|
|
56
|
+
"@coze-arch/vitest-config": "workspace:*",
|
|
57
|
+
"@coze-chat/chat-area-utils": "workspace:*",
|
|
58
|
+
"@coze-chat/chat-core": "workspace:*",
|
|
59
|
+
"@coze-chat/chat-core-typings": "workspace:*",
|
|
60
|
+
"@coze-coding/env": "workspace:*",
|
|
61
|
+
"@coze-coding/lambda": "workspace:*",
|
|
62
|
+
"@rollup/plugin-commonjs": "^28.0.2",
|
|
63
|
+
"@rollup/plugin-json": "~6.0.0",
|
|
64
|
+
"@rollup/plugin-node-resolve": "^15.3.0",
|
|
65
|
+
"@rollup/plugin-sucrase": "^5.0.2",
|
|
66
|
+
"@types/lodash": "~4.17.24",
|
|
67
|
+
"@types/marked-terminal": "~6.1.1",
|
|
68
|
+
"@types/node": "^24",
|
|
69
|
+
"@types/react": "18.3.27",
|
|
70
|
+
"@types/shelljs": "^0.10.0",
|
|
71
|
+
"@types/ws": "^8.5.13",
|
|
72
|
+
"@vitest/coverage-v8": "~4.0.18",
|
|
73
|
+
"rollup": "^4.41.1",
|
|
74
|
+
"sucrase": "^3.35.0",
|
|
75
|
+
"tsx": "^4.20.6",
|
|
76
|
+
"vitest": "~4.0.18"
|
|
77
|
+
},
|
|
78
|
+
"publishConfig": {
|
|
79
|
+
"access": "public",
|
|
80
|
+
"registry": "https://registry.npmjs.org"
|
|
67
81
|
}
|
|
68
|
-
}
|
|
82
|
+
}
|
package/bin.mjs
DELETED
package/dist/cli.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/dist/cli.mjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import*as e from"commander";import*as t from"openid-client";import*as o from"picocolors";import*as i from"@npmcli/config/lib/definitions/index.js";import*as r from"@npmcli/config";let s={info(...e){console.log(o.default.blue("[INFO]"),...e)},success(...e){console.log(o.default.green("[SUCCESS]"),...e)},warning(...e){console.log(o.default.yellow("[WARNING]"),...e)},error(...e){console.error(o.default.red("[ERROR]"),...e)},debug(...e){process.env.DEBUG&&console.log(o.default.magenta("[DEBUG]"),...e)}};var n,a=((n={}).CN="cn",n);let c={cn:"npm-hub.coze.cn"},h={cn:"13474932957575400683007237571476.app.coze"},l={cn:"https://api.coze.cn"},p=Object.values(a),g=()=>!1;class u{constructor(e="cn"){let o=new t.Issuer({issuer:l[e],device_authorization_endpoint:`${l[e]}/api/permission/oauth2/device/code`,token_endpoint:`${l[e]}/api/permission/oauth2/token`,revocation_endpoint:`${l[e]}/api/permission/oauth2/revoke`,scope:"createMessage"});this.client=new o.Client({client_id:h[e],token_endpoint_auth_method:"none"})}async activate(e){let{refreshToken:t}=await e.loadConfig();if(t)try{let o=await this.client.refresh(t);await e.storeToken(o)}catch(t){s.error("refresh failed: ",t),await this.auth(e)}else await this.auth(e)}async deactivate(e){let{refreshToken:t}=await e.loadConfig();await this.client.revoke(t),await e.clearToken()}async auth(e){let t=await this.client.deviceAuthorization({duration_seconds:86399}),o=`${t.verification_uri}?user_code=${t.user_code}`,i=await import("open").then(e=>e.default);await i(o);let r=null;for(;!r;)try{r=await t.poll(),s.success("authenticated"),await e.storeToken(r)}catch(e){throw s.error("poll failed:",e),e}}}let{shorthands:f,definitions:d,flatten:y}=i.default,m="user";class w{constructor({projectDir:e,scope:t,region:o,source:i}={}){this.config={scope:t??"coze-kit",authToken:"",refreshToken:"",registryUrl:"",region:o,source:i??"coze"};let s=e??process.cwd();this.proxy=new r.default({npmPath:s,definitions:d,shorthands:f,flatten:y,cwd:s})}get registryScope(){return`@${this.config.scope}:registry`}get registryUrl(){let e=c[this.region];return g(this.region)?`http://${e}/`:`https://${e}/`}get registryAuthUrl(){let e=c[this.region];return`//${e}/:_authToken`}get refreshKey(){return`${this.config.source}_refresh_token`}get region(){if(this.config.region)return this.config.region;let e=this.proxy.get(this.registryScope);if(!e)return"cn";let t=new URL(e).host;for(let[e,o]of Object.entries(c))if(t===o)return e;return"cn"}async loadConfig(){if(this.proxy.loaded)return this.config;await this.proxy.load();let e=this.proxy.get(this.registryAuthUrl,m)??"";return Object.assign(this.config,{region:this.region,registryUrl:this.proxy.get(this.registryScope)||this.registryUrl,authToken:e,refreshToken:this.proxy.get(this.refreshKey,m)||""}),this.config}async storeToken(e){for(let[e]of Object.entries(c))e!==this.region&&this.proxy.delete(this.registryScope,m);this.proxy.set(this.registryScope,this.registryUrl,m),this.proxy.set(this.registryAuthUrl,`${this.config.source}:${e.access_token||""}`,m),this.proxy.set(this.refreshKey,e.refresh_token||"",m),await this.proxy.save(m),Object.assign(this.config,{authToken:e.access_token,refreshToken:e.refresh_token}),s.success(`token saved for registry: ${this.registryUrl}`)}async clearToken(){this.proxy.delete(this.registryScope,m),this.proxy.delete(this.registryAuthUrl,m),this.proxy.delete(this.refreshKey,m),await this.proxy.save(m),Object.assign(this.config,{authToken:"",refreshToken:""}),s.success(`token cleared for registry: ${this.registryUrl}`)}getProxy(){return this.proxy}}let k={name:"logout",description:"log out of the hub",action:async function e({region:e,scope:t,source:o}){let i=new w({region:e,scope:t,source:o}),r=new u(e);await r.deactivate(i)},options:[new e.Option("-r, --region <name>","the region of hub").choices(p),new e.Option("-s, --scope <name>","the scope of package"),new e.Option("-b, --source <name>","the business source")]},v={name:"login",description:"log in to the hub",action:async function e({region:e}){let t=new w({region:e}),o=new u(e);await o.activate(t)},options:[new e.Option("-r, --region <name>","the region of hub").choices(p)]},x=new e.Command;x.name("coze").version("0.0.4").description("A command-line tool for component development");[v,k].forEach(e=>{!function e({program:t,spec:o,runAuth:i}){let r=t.command(o.name);r.description(o.description),(o.arguments??[]).forEach(e=>{r.addArgument(e)}),(o.options??[]).forEach(e=>{r.addOption(e)}),o.action&&r.action(async(...e)=>{o.auth&&i&&await i(),await o.action?.(...e)}),(o.subCommands??[]).forEach(t=>{e({program:r,spec:t,runAuth:i})})}({spec:e,program:x,runAuth:async()=>{let e=new w,{region:t,registryUrl:o,scope:i}=await e.loadConfig(),r=new u(t);await r.activate(e),process.env.REGION=t,process.env.REGISTRY=o,process.env.SCOPE=i}})}),x.parse(process.argv);
|
package/dist/commands/base.d.ts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { type Argument, type Option, type Command } from 'commander';
|
|
2
|
-
export interface CommandSpec {
|
|
3
|
-
name: string;
|
|
4
|
-
description: string;
|
|
5
|
-
action?: (...args: any[]) => Promise<void> | void;
|
|
6
|
-
subCommands?: CommandSpec[];
|
|
7
|
-
options?: Option[];
|
|
8
|
-
arguments?: Argument[];
|
|
9
|
-
auth?: boolean;
|
|
10
|
-
}
|
|
11
|
-
export declare function addCommand({ program, spec, runAuth, }: {
|
|
12
|
-
program: Command;
|
|
13
|
-
spec: CommandSpec;
|
|
14
|
-
runAuth?: () => Promise<void>;
|
|
15
|
-
}): void;
|
package/dist/commands/login.d.ts
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { type Region } from '../helpers/constants';
|
|
2
|
-
import { type CommandSpec } from './base';
|
|
3
|
-
export declare function logoutAction({ region, scope, source, }: {
|
|
4
|
-
region?: Region;
|
|
5
|
-
scope?: string;
|
|
6
|
-
source?: string;
|
|
7
|
-
}): Promise<void>;
|
|
8
|
-
export declare const logoutSpec: CommandSpec;
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
export declare enum Region {
|
|
2
|
-
CN = "cn"
|
|
3
|
-
}
|
|
4
|
-
declare let REGISTRY_HOST: Record<string, string>;
|
|
5
|
-
declare let CLIENT_ID_MAP: Record<string, string>;
|
|
6
|
-
declare let ISSUER_MAP: Record<string, string>;
|
|
7
|
-
declare let REGION_VALUES: string[];
|
|
8
|
-
declare let isLocalDev: (region: string) => boolean;
|
|
9
|
-
export declare const DEFAULT_REGION = Region.CN;
|
|
10
|
-
export { REGION_VALUES, isLocalDev, REGISTRY_HOST, CLIENT_ID_MAP, ISSUER_MAP };
|
package/dist/helpers/logger.d.ts
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
export declare function resolvePackageJson(projectDir: string): Record<string, any>;
|
|
2
|
-
export declare function resolvePackageDir(dir?: string): string;
|
|
3
|
-
/**
|
|
4
|
-
* @coze/a-b -> __coze__a_b
|
|
5
|
-
* @coze-ui/a-b -> __coze_ui__a_b
|
|
6
|
-
* a-b -> a_b
|
|
7
|
-
*/
|
|
8
|
-
export declare function pkgName2RemoteName(pkgName: string): string;
|
package/dist/helpers/types.d.ts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { type TokenSetParameters } from 'openid-client';
|
|
2
|
-
export interface BaseConfigData {
|
|
3
|
-
authToken: string;
|
|
4
|
-
refreshToken: string;
|
|
5
|
-
registryUrl: string;
|
|
6
|
-
scope?: string;
|
|
7
|
-
}
|
|
8
|
-
export interface INpmConfig<T extends BaseConfigData = BaseConfigData> {
|
|
9
|
-
loadConfig: () => Promise<T>;
|
|
10
|
-
storeToken: (token: TokenSetParameters) => Promise<void>;
|
|
11
|
-
clearToken: () => Promise<void>;
|
|
12
|
-
}
|
|
13
|
-
export interface IAuthClient {
|
|
14
|
-
activate: (npmConfig: INpmConfig) => Promise<void>;
|
|
15
|
-
deactivate: (npmConfig: INpmConfig) => Promise<void>;
|
|
16
|
-
}
|
package/dist/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { addCommand, type CommandSpec } from './commands/base';
|
package/dist/index.mjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
function a({program:o,spec:n,runAuth:t}){let c=o.command(n.name);c.description(n.description),(n.arguments??[]).forEach(a=>{c.addArgument(a)}),(n.options??[]).forEach(a=>{c.addOption(a)}),n.action&&c.action(async(...a)=>{n.auth&&t&&await t(),await n.action?.(...a)}),(n.subCommands??[]).forEach(o=>{a({program:c,spec:o,runAuth:t})})}export{a as addCommand};
|
package/dist/npm.d.ts
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { type TokenSetParameters } from 'openid-client';
|
|
2
|
-
import Config from '@npmcli/config';
|
|
3
|
-
import { type INpmConfig, type BaseConfigData } from './helpers/types';
|
|
4
|
-
import { type Region } from './helpers/constants';
|
|
5
|
-
export interface NpmConfigOptions {
|
|
6
|
-
projectDir?: string;
|
|
7
|
-
scope?: string;
|
|
8
|
-
region?: Region;
|
|
9
|
-
source?: string;
|
|
10
|
-
}
|
|
11
|
-
export interface ConfigData extends BaseConfigData {
|
|
12
|
-
region?: Region;
|
|
13
|
-
source?: string;
|
|
14
|
-
}
|
|
15
|
-
export declare class NpmConfig implements INpmConfig<ConfigData> {
|
|
16
|
-
private proxy;
|
|
17
|
-
private config;
|
|
18
|
-
constructor({ projectDir, scope, region, source }?: NpmConfigOptions);
|
|
19
|
-
get registryScope(): string;
|
|
20
|
-
get registryUrl(): string;
|
|
21
|
-
get registryAuthUrl(): string;
|
|
22
|
-
get refreshKey(): string;
|
|
23
|
-
get region(): string;
|
|
24
|
-
loadConfig(): Promise<ConfigData>;
|
|
25
|
-
storeToken(tokenSet: TokenSetParameters): Promise<void>;
|
|
26
|
-
clearToken(): Promise<void>;
|
|
27
|
-
getProxy(): Config;
|
|
28
|
-
}
|
package/dist/oauth.d.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { type INpmConfig, type IAuthClient } from './helpers/types';
|
|
2
|
-
import { type Region } from './helpers/constants';
|
|
3
|
-
export declare class OauthClient implements IAuthClient {
|
|
4
|
-
private client;
|
|
5
|
-
constructor(region?: Region);
|
|
6
|
-
activate(npmConfig: INpmConfig): Promise<void>;
|
|
7
|
-
deactivate(npmConfig: INpmConfig): Promise<void>;
|
|
8
|
-
private auth;
|
|
9
|
-
}
|