@skillbuilder/minitool-core 0.0.0-beta-20261027053041051

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.
Files changed (61) hide show
  1. package/README.md +74 -0
  2. package/lib/di/index.js +21 -0
  3. package/lib/di/modules.js +23 -0
  4. package/lib/di/tokens.js +12 -0
  5. package/lib/index.js +29 -0
  6. package/lib/runtime.js +42 -0
  7. package/lib/services/index.js +19 -0
  8. package/lib/services/minitool-api.js +125 -0
  9. package/lib/services/minitool-contract.js +76 -0
  10. package/lib/services/minitool-service.js +161 -0
  11. package/lib/services/upload-service.js +183 -0
  12. package/lib/utils/config-merger.js +63 -0
  13. package/lib/utils/cos-uploader.js +120 -0
  14. package/lib/utils/env-helper.js +4 -0
  15. package/lib/utils/helper.js +46 -0
  16. package/lib/utils/loading.js +52 -0
  17. package/lib/utils/logger.js +83 -0
  18. package/lib/utils/open-browser.js +32 -0
  19. package/lib/utils/openChrome.applescript +78 -0
  20. package/lib/utils/output.js +19 -0
  21. package/lib/utils/port-finder.js +43 -0
  22. package/lib/utils/project-validator.js +233 -0
  23. package/lib/utils/request.js +73 -0
  24. package/lib/utils/table.js +29 -0
  25. package/lib/utils/to-hump.js +5 -0
  26. package/lib/utils/tracker/ai-apm.js +119 -0
  27. package/lib/utils/tracker/apm.js +73 -0
  28. package/lib/utils/tracker/cli-apm.js +188 -0
  29. package/lib/utils/tracker/device.js +30 -0
  30. package/lib/utils/tracker/index.js +21 -0
  31. package/lib/utils/tracker/tracker.js +2 -0
  32. package/package.json +32 -0
  33. package/types/di/index.d.ts +3 -0
  34. package/types/di/modules.d.ts +9 -0
  35. package/types/di/tokens.d.ts +9 -0
  36. package/types/index.d.ts +14 -0
  37. package/types/runtime.d.ts +24 -0
  38. package/types/services/index.d.ts +3 -0
  39. package/types/services/minitool-api.d.ts +30 -0
  40. package/types/services/minitool-contract.d.ts +103 -0
  41. package/types/services/minitool-service.d.ts +29 -0
  42. package/types/services/upload-service.d.ts +48 -0
  43. package/types/utils/config-merger.d.ts +6 -0
  44. package/types/utils/cos-uploader.d.ts +45 -0
  45. package/types/utils/env-helper.d.ts +1 -0
  46. package/types/utils/helper.d.ts +8 -0
  47. package/types/utils/loading.d.ts +15 -0
  48. package/types/utils/logger.d.ts +27 -0
  49. package/types/utils/open-browser.d.ts +2 -0
  50. package/types/utils/output.d.ts +7 -0
  51. package/types/utils/port-finder.d.ts +2 -0
  52. package/types/utils/project-validator.d.ts +25 -0
  53. package/types/utils/request.d.ts +26 -0
  54. package/types/utils/table.d.ts +9 -0
  55. package/types/utils/to-hump.d.ts +1 -0
  56. package/types/utils/tracker/ai-apm.d.ts +68 -0
  57. package/types/utils/tracker/apm.d.ts +21 -0
  58. package/types/utils/tracker/cli-apm.d.ts +47 -0
  59. package/types/utils/tracker/device.d.ts +8 -0
  60. package/types/utils/tracker/index.d.ts +5 -0
  61. package/types/utils/tracker/tracker.d.ts +22 -0
@@ -0,0 +1,27 @@
1
+ import ora, { type Ora } from "ora";
2
+ export declare class Logger {
3
+ c: {
4
+ _times: Map<any, any>;
5
+ log(a: string, ...args: string[]): void;
6
+ };
7
+ verboseEnabled: boolean;
8
+ constructor(options?: {
9
+ verbose?: boolean;
10
+ });
11
+ breakLine(): void;
12
+ log(...args: any): void;
13
+ info(msg: string): void;
14
+ success(msg: string): void;
15
+ warn(msg: string): void;
16
+ error(msg: string): void;
17
+ verbose(...args: any): void;
18
+ /**
19
+ * alias for verbose
20
+ */
21
+ debug(...args: any): void;
22
+ genClickableLink(link: string): string;
23
+ printClickableLink(link: string): void;
24
+ time(label: string, fn: Promise<any> | (() => Promise<any>)): Promise<any>;
25
+ spinner(text: string, color?: ora.Color): Ora;
26
+ }
27
+ export declare const logger: Logger;
@@ -0,0 +1,2 @@
1
+ /** 打开本地预览页。参数通过 execFileSync 的 argv 传递,不经过 shell。 */
2
+ export declare function openBrowser(host: string, port: number): Promise<boolean>;
@@ -0,0 +1,7 @@
1
+ export interface HelpCommand {
2
+ name: string;
3
+ description: string;
4
+ }
5
+ /** 通用 CLI 帮助格式化器;不再写死旧 rcb agent/fun/env 命令。 */
6
+ export declare function formatHelpInfo(title: string, commands: HelpCommand[]): string;
7
+ export declare function outputHelpInfo(title: string, commands: HelpCommand[]): void;
@@ -0,0 +1,2 @@
1
+ export declare function findAvailablePort(startPort: number): Promise<number>;
2
+ export declare function isPortAvailable(port: number): Promise<boolean>;
@@ -0,0 +1,25 @@
1
+ /** 小工具产物校验;旧 Agent 云函数项目结构与上传预检不再适用。 */
2
+ export declare function validateMiniToolArtifact(inputPath: string): {
3
+ filePath: string;
4
+ size: number;
5
+ };
6
+ /** 与旧校验器保持相同的 validate() 结果形态,校验目标改为小工具 ZIP。 */
7
+ export declare class ProjectValidator {
8
+ private readonly artifactPath;
9
+ constructor(artifactPath: string);
10
+ validate(): Promise<{
11
+ valid: boolean;
12
+ errors: string[];
13
+ }>;
14
+ }
15
+ export interface InspectedMiniToolFile {
16
+ filePath: string;
17
+ type: "pkg" | "image";
18
+ format: string;
19
+ size: number;
20
+ md5: string;
21
+ sha256: string;
22
+ bytes: Buffer;
23
+ }
24
+ /** 先限制大小,再校验压缩目录与 CRC;返回与校验内容一致的上传快照。 */
25
+ export declare function inspectMiniToolFile(inputPath: string, type: "pkg" | "image"): Promise<InspectedMiniToolFile>;
@@ -0,0 +1,26 @@
1
+ export interface RequestOptions {
2
+ method?: "GET" | "POST" | "PUT" | "DELETE";
3
+ url: string;
4
+ data?: {
5
+ params?: Record<string, unknown>;
6
+ body?: unknown;
7
+ query?: Record<string, unknown>;
8
+ };
9
+ headers?: Record<string, string>;
10
+ }
11
+ export interface RequestResponse<T> {
12
+ status: number;
13
+ data: T;
14
+ headers: Headers;
15
+ }
16
+ export declare class Request {
17
+ private readonly request;
18
+ constructor(request?: typeof fetch);
19
+ fetch<T = unknown>(options: RequestOptions): Promise<RequestResponse<T>>;
20
+ handleHttpStatus<T>(response: RequestResponse<T>): T;
21
+ handleCode<T extends {
22
+ code: number;
23
+ msg: string;
24
+ }>(data: T): T;
25
+ }
26
+ export declare const request: Request;
@@ -0,0 +1,9 @@
1
+ import { type TableOptions } from "cli-table3";
2
+ /**
3
+ * 打印水平方向的表格
4
+ *
5
+ * @param head 表头
6
+ * @param data 行数据,每行是一个数组
7
+ * @param options 透传给 cli-table3 的配置
8
+ */
9
+ export declare function printHorizontalTable(head: string[], data?: (string | number)[][], options?: TableOptions): void;
@@ -0,0 +1 @@
1
+ export declare const toHump: (str: string) => string;
@@ -0,0 +1,68 @@
1
+ /**
2
+ * AI 助手服务统一点位:
3
+ * measurement_name 固定为 redminitool_ai_tool_usage,
4
+ * 通过 measurement_data.event 区分事件类型:
5
+ * - session_run : AI 对话请求开始(= 出码服务使用次数)
6
+ * - turn_code_generated : 每轮 AI 出码行数统计
7
+ * - session_complete : 整次对话完成汇总
8
+ * - code_change_applied : 用户接受单个 AI 代码变更(接受率分子)
9
+ * - code_change_rejected : 用户拒绝单个 AI 代码变更(接受率分母)
10
+ * - bulk_resolve : 用户批量接受/拒绝所有变更
11
+ * - message_sent : 前端用户发送消息(来自浏览器端 APM 代理)
12
+ */
13
+ export declare const AI_MEASUREMENT_NAME = "redminitool_ai_tool_usage";
14
+ export type AiSessionStatus = "success" | "fail" | "aborted";
15
+ export interface InitAiApmOptions {
16
+ userId?: string;
17
+ }
18
+ export declare function initAiApm(options?: InitAiApmOptions): void;
19
+ export interface AiSessionRunMeta {
20
+ session_id: string;
21
+ model?: string;
22
+ dev_mode?: string;
23
+ /** 1 = 新 session,0 = 复用已有 session */
24
+ is_new_session?: 0 | 1;
25
+ message_length?: number;
26
+ }
27
+ export declare function reportAiSessionRun(meta: AiSessionRunMeta): void;
28
+ export interface AiTurnCodeGeneratedMeta {
29
+ session_id?: string;
30
+ model?: string;
31
+ dev_mode?: string;
32
+ files_changed?: number;
33
+ lines_added?: number;
34
+ lines_removed?: number;
35
+ }
36
+ export declare function reportAiTurnCodeGenerated(meta: AiTurnCodeGeneratedMeta): void;
37
+ export interface AiSessionCompleteMeta {
38
+ session_id: string;
39
+ model?: string;
40
+ dev_mode?: string;
41
+ duration_ms: number;
42
+ status: AiSessionStatus;
43
+ total_files_changed?: number;
44
+ total_lines_added?: number;
45
+ total_lines_removed?: number;
46
+ error_type?: string;
47
+ }
48
+ export declare function reportAiSessionComplete(meta: AiSessionCompleteMeta): void;
49
+ export interface AiCodeChangeMeta {
50
+ session_id?: string;
51
+ /** "write" | "edit" */
52
+ tool_name?: string;
53
+ }
54
+ export declare function reportAiCodeChangeApplied(meta: AiCodeChangeMeta): void;
55
+ export declare function reportAiCodeChangeRejected(meta: AiCodeChangeMeta): void;
56
+ export interface AiBulkResolveMeta {
57
+ session_id?: string;
58
+ action: "accept" | "reject";
59
+ files_count?: number;
60
+ }
61
+ export declare function reportAiBulkResolve(meta: AiBulkResolveMeta): void;
62
+ export interface AiMessageSentMeta {
63
+ session_id?: string;
64
+ mode?: string;
65
+ model?: string;
66
+ message_length?: number;
67
+ }
68
+ export declare function reportAiMessageSent(meta: AiMessageSentMeta): void;
@@ -0,0 +1,21 @@
1
+ import type { IBase } from "./tracker";
2
+ export interface ApmOptions {
3
+ endpoint?: string;
4
+ /** 测试或平台适配器可自行提供传输;默认仅在配置 endpoint 时发送。 */
5
+ transport?: (payload: Record<string, unknown>[]) => Promise<void>;
6
+ }
7
+ /** 通用 APM 传输,不自动获取设备 ID、登录态或凭据。 */
8
+ export declare class APM {
9
+ private readonly sessionId;
10
+ private sequence;
11
+ private appVersion;
12
+ private userId;
13
+ private base;
14
+ private readonly transport?;
15
+ private readonly pending;
16
+ constructor(options?: ApmOptions);
17
+ setContext(userId: string, base?: IBase): void;
18
+ setAppVersion(version: string): void;
19
+ report(measurement_name: string, measurement_data?: Record<string, unknown>): void;
20
+ flush(): Promise<void>;
21
+ }
@@ -0,0 +1,47 @@
1
+ /** CLI 通用埋点;不依赖小工具业务服务,也不读取本地凭据。 */
2
+ export declare const CLI_MEASUREMENT_NAME = "redminitool_cli_usage";
3
+ export type CliApmCommandStatus = 0 | 1;
4
+ export type CliApmExceptionSource = "uncaughtException" | "unhandledRejection";
5
+ export type CliApmErrorType = "auth" | "http" | "validation" | "biz" | "unknown";
6
+ export interface CliApmEvent {
7
+ context_nameTracker: "nodeT";
8
+ context_platform: string;
9
+ context_appVersion: string;
10
+ context_matchedPath: "cli";
11
+ context_sdkSessionId: string;
12
+ context_sdkSeqId: number;
13
+ clientTime: number;
14
+ measurement_name: typeof CLI_MEASUREMENT_NAME;
15
+ measurement_data: Record<string, string | number | undefined>;
16
+ }
17
+ export interface CliApmTransport {
18
+ report(event: CliApmEvent): Promise<void> | void;
19
+ }
20
+ export interface InitCliApmOptions {
21
+ cliVersion?: string;
22
+ /** 未配置 endpoint/transport 时不发送;正式启用前由产品和服务端确认上报地址。 */
23
+ endpoint?: string;
24
+ /** 方便注入平台上报适配器和测试替身。 */
25
+ transport?: CliApmTransport;
26
+ }
27
+ export interface CliCommandMeta {
28
+ cmd_path: string;
29
+ cmd_root?: string;
30
+ params_count?: number;
31
+ options_keys?: string[];
32
+ }
33
+ export interface CliHttpErrorMeta {
34
+ method?: string;
35
+ url?: string;
36
+ status_code?: number;
37
+ }
38
+ export declare function initCliApm(options?: InitCliApmOptions): void;
39
+ export declare function setCliApmCurrentCommand(cmdPath?: string): void;
40
+ export declare function createCliCommandTracker(meta: CliCommandMeta): {
41
+ reportSuccess(durationMs: number): void;
42
+ reportFail(durationMs: number, err: unknown): void;
43
+ };
44
+ export declare function reportCliException(source: CliApmExceptionSource, err: unknown): void;
45
+ export declare function reportCliHttpError(meta: CliHttpErrorMeta, err?: unknown): void;
46
+ /** CLI 退出前最多等待一小段时间,超时后取消请求;上报失败永不影响命令结果。 */
47
+ export declare function flushCliApm(timeoutMs?: number): Promise<void>;
@@ -0,0 +1,8 @@
1
+ import type { IDeviceInfo, IDeviceUA } from "./tracker";
2
+ /** 本地诊断信息;CLI APM 不会自动采集或发送这些字段。 */
3
+ export declare function getDeviceInfo(): IDeviceInfo;
4
+ export declare function deviceUA(): IDeviceUA;
5
+ /**
6
+ * 旧版会读取硬件 UUID 并写 ~/.rcb/.device.json;该持久设备标识未获隐私评审,不再生成。
7
+ */
8
+ export declare function machineId(): never;
@@ -0,0 +1,5 @@
1
+ export * from "./apm";
2
+ export * from "./ai-apm";
3
+ export * from "./cli-apm";
4
+ export * from "./device";
5
+ export * from "./tracker";
@@ -0,0 +1,22 @@
1
+ export interface IDeviceInfo {
2
+ os_platform: string;
3
+ os_arch: string;
4
+ cpu_speed: number;
5
+ cpu_model: string;
6
+ machine_memory: number;
7
+ os_version: string;
8
+ }
9
+ export interface IDeviceUA {
10
+ login_user?: string;
11
+ node_version: string;
12
+ }
13
+ export interface IBase {
14
+ app_id?: string;
15
+ app_name?: string;
16
+ third_name?: string;
17
+ page_key?: string;
18
+ base_version?: string;
19
+ app_env?: number;
20
+ app_type?: number;
21
+ bundle_version?: string;
22
+ }