@coze/cli 0.0.4 → 0.1.0-alpha.2b156a

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.
@@ -0,0 +1,52 @@
1
+ 'use strict';
2
+
3
+ const process = require('process');
4
+ const index = require('./index-lMSqm5Bi.js');
5
+ require('mitt');
6
+ require('crypto');
7
+ require('lodash-es');
8
+ require('form-data');
9
+ require('url');
10
+ require('http');
11
+ require('https');
12
+ require('http2');
13
+ require('util');
14
+ require('stream');
15
+ require('assert');
16
+ require('tty');
17
+ require('os');
18
+ require('zlib');
19
+ require('events');
20
+ require('child_process');
21
+ require('node:path');
22
+ require('fs');
23
+ require('path');
24
+ require('fs/promises');
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,77 @@
1
1
  {
2
2
  "name": "@coze/cli",
3
- "version": "0.0.4",
4
- "description": "command-line tool for component development",
5
- "keywords": [
6
- "coze",
7
- "@coze/cli",
8
- "cli"
9
- ],
3
+ "version": "0.1.0-alpha.2b156a",
4
+ "private": false,
5
+ "description": "tmp",
10
6
  "license": "MIT",
11
- "author": "Coze Team <coze@feedback.com>",
12
- "main": "dist/index.mjs",
13
- "types": "dist/index.d.ts",
7
+ "author": "fanwenjie.fe@bytedance.com",
8
+ "maintainers": [],
14
9
  "bin": {
15
- "coze": "./bin.mjs"
10
+ "coze": "bin/main"
16
11
  },
17
12
  "files": [
18
- "LICENSE",
19
- "dist",
13
+ "lib",
14
+ "bin",
20
15
  "README.md",
21
- "package.json",
22
- "bin.mjs",
23
- "!dist/commands/ui",
24
- "!**/*.map",
25
- "!**/*.tsbuildinfo"
16
+ "!**/*.tsbuildinfo",
17
+ "!**/*.map"
26
18
  ],
27
19
  "scripts": {
28
- "build": "rslib build",
20
+ "prebuild": "tsx scripts/prebuild.ts",
21
+ "build": "tsx scripts/build.ts",
29
22
  "lint": "eslint ./ --cache",
30
- "release": "node scripts/release.js",
31
- "start": "node bin.mjs",
32
23
  "test": "vitest --run --passWithNoTests",
33
- "test:cov": "npm run test -- --coverage"
24
+ "test:all": "bash scripts/test-coverage.sh",
25
+ "test:cov": "vitest --run --passWithNoTests --coverage",
26
+ "test:e2e": "NODE_ENV=test bash scripts/e2e.sh"
34
27
  },
35
28
  "dependencies": {
36
- "@inquirer/prompts": "^3.2.0",
37
- "@module-federation/rsbuild-plugin": "^0.6.12",
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",
29
+ "ahooks": "~3.9.6",
30
+ "chalk": "^4.1.2",
45
31
  "commander": "~12.1.0",
46
- "cross-spawn": "^7.0.3",
47
- "express": "^4.21.1",
48
- "form-data": "^4.0.1",
49
- "lodash": "^4.17.21",
50
- "open": "~10.1.0",
51
- "openid-client": "~5.7.0",
52
- "picocolors": "^1.0.0",
53
- "prettier": "^2",
54
- "semver": "^7.3.7"
32
+ "form-data": "^4.0.0",
33
+ "http-proxy-agent": "~8.0.0",
34
+ "https-proxy-agent": "~8.0.0",
35
+ "lodash-es": "^4.17.22",
36
+ "marked": "^15.0.7",
37
+ "marked-terminal": "~7.3.0",
38
+ "mitt": "~3.0.1",
39
+ "omelette": "~0.4.17",
40
+ "react": "~18.3.1",
41
+ "shelljs": "^0.10.0",
42
+ "undici": "~7.24.5",
43
+ "ws": "^8.18.0"
55
44
  },
56
45
  "devDependencies": {
57
- "@module-federation/sdk": "*",
58
- "@types/node": "^18",
59
- "@types/npmcli__config": "~6.0.3",
60
- "@types/open": "~6.2.1",
61
- "@vitest/coverage-v8": "~1.4.0",
62
- "mock-fs": "~5.3.0",
63
- "msw": "~2.0.11",
64
- "sucrase": "^3.32.0",
65
- "typescript": "~5.0.4",
66
- "vitest": "~1.4.0"
46
+ "@coze-arch/api-schema": "workspace:*",
47
+ "@coze-arch/cli-logger": "workspace:*",
48
+ "@coze-arch/eslint-config": "workspace:*",
49
+ "@coze-arch/request": "workspace:*",
50
+ "@coze-arch/ts-config": "workspace:*",
51
+ "@coze-arch/vitest-config": "workspace:*",
52
+ "@coze-chat/chat-area-utils": "workspace:*",
53
+ "@coze-chat/chat-core": "workspace:*",
54
+ "@coze-chat/chat-core-typings": "workspace:*",
55
+ "@coze-coding/env": "workspace:*",
56
+ "@coze-coding/lambda": "workspace:*",
57
+ "@rollup/plugin-commonjs": "^28.0.2",
58
+ "@rollup/plugin-json": "~6.0.0",
59
+ "@rollup/plugin-node-resolve": "^15.3.0",
60
+ "@rollup/plugin-sucrase": "^5.0.2",
61
+ "@types/lodash-es": "^4.17.12",
62
+ "@types/marked-terminal": "~6.1.1",
63
+ "@types/node": "^24",
64
+ "@types/react": "18.3.27",
65
+ "@types/shelljs": "^0.10.0",
66
+ "@types/ws": "^8.5.13",
67
+ "@vitest/coverage-v8": "~4.0.18",
68
+ "rollup": "^4.41.1",
69
+ "sucrase": "^3.35.0",
70
+ "tsx": "^4.20.6",
71
+ "vitest": "~4.0.18"
72
+ },
73
+ "publishConfig": {
74
+ "access": "public",
75
+ "registry": "https://registry.npmjs.org"
67
76
  }
68
- }
77
+ }
package/LICENSE DELETED
@@ -1,21 +0,0 @@
1
- MIT License
2
-
3
- Copyright (c) 2023 Spring (SG) Pte. Ltd.
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
package/bin.mjs DELETED
@@ -1,2 +0,0 @@
1
- #!/usr/bin/env node
2
- import './dist/cli.mjs';
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);
@@ -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;
@@ -1,6 +0,0 @@
1
- import { type Region } from '../helpers/constants';
2
- import { type CommandSpec } from './base';
3
- export declare function loginAction({ region }: {
4
- region?: Region;
5
- }): Promise<void>;
6
- export declare const loginSpec: CommandSpec;
@@ -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 };
@@ -1,7 +0,0 @@
1
- export declare const logger: {
2
- info(...messages: unknown[]): void;
3
- success(...messages: unknown[]): void;
4
- warning(...messages: unknown[]): void;
5
- error(...messages: unknown[]): void;
6
- debug(...messages: unknown[]): void;
7
- };
@@ -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;
@@ -1,3 +0,0 @@
1
- import { type AxiosRequestConfig } from 'axios';
2
- export type RequestConfig = (url: string, options: AxiosRequestConfig) => Promise<AxiosRequestConfig>;
3
- export declare function loadRequestConfig(): Promise<RequestConfig | undefined>;
@@ -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
- }