bailian-cli-runtime 1.6.0 → 1.7.0
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/dist/index.d.mts +158 -98
- package/dist/index.mjs +34 -32
- package/package.json +3 -7
- package/dist/chunk-POvHkJ8y.mjs +0 -1
- package/dist/dist-DgvkrLd1.mjs +0 -36
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { AnyCommand, ApiKeyCredential, AuthStore, Client, Command, ConfigStore, FlagDef, FlagsDef, Identity, OutputFormat, ParsedFlags, ResolutionSources, Settings, UsageError } from "bailian-cli-core";
|
|
2
2
|
|
|
3
3
|
//#region src/create-cli.d.ts
|
|
4
4
|
/** Per-product identity injected by each CLI entrypoint (bl / rag / …). */
|
|
@@ -7,38 +7,63 @@ interface CliOptions {
|
|
|
7
7
|
binName: string;
|
|
8
8
|
/** Product version for `--version` output, telemetry and update checks. */
|
|
9
9
|
version: string;
|
|
10
|
-
/**
|
|
11
|
-
clientName
|
|
10
|
+
/** User-Agent / telemetry client name (e.g. "bailian-cli", "rag-cli")。必填,无默认。 */
|
|
11
|
+
clientName: string;
|
|
12
12
|
/** npm package name for self-update (e.g. "bailian-cli", "bailian-cli-rag"). */
|
|
13
13
|
npmPackage: string;
|
|
14
|
+
/** Root-help suggestions shown after credentials are configured. */
|
|
15
|
+
quickStartTasks?: readonly string[];
|
|
14
16
|
}
|
|
15
17
|
interface Cli {
|
|
16
18
|
run(argv?: string[]): Promise<void>;
|
|
17
19
|
}
|
|
18
20
|
/**
|
|
19
|
-
* Build a CLI from an injected command set
|
|
20
|
-
*
|
|
21
|
-
*
|
|
21
|
+
* Build a CLI from an injected command set — each product (bl / rag / …) passes
|
|
22
|
+
* its own commands + identity. `run` resolves argv into a {@link Resolution},
|
|
23
|
+
* then dispatches it.
|
|
22
24
|
*/
|
|
23
|
-
declare function createCli(commands: Record<string,
|
|
25
|
+
declare function createCli(commands: Record<string, AnyCommand>, opts: CliOptions): Cli;
|
|
24
26
|
//#endregion
|
|
25
27
|
//#region src/registry.d.ts
|
|
28
|
+
/**
|
|
29
|
+
* What a command path resolves to in the registry. The single judgement that
|
|
30
|
+
* feeds `resolve()` — no scattered `isGroupPath` + throwing `resolve`.
|
|
31
|
+
* - leaf: landed *exactly* on an executable command (no leftover tokens).
|
|
32
|
+
* - group: landed on a command group with no executable of its own (incl. root []).
|
|
33
|
+
* - unknown: the path doesn't exist, or a valid command had unexpected trailing
|
|
34
|
+
* tokens (no positionals); `error` carries the message + hint.
|
|
35
|
+
*/
|
|
36
|
+
type LocateResult = {
|
|
37
|
+
kind: "leaf";
|
|
38
|
+
command: AnyCommand;
|
|
39
|
+
matched: string[];
|
|
40
|
+
} | {
|
|
41
|
+
kind: "group";
|
|
42
|
+
matched: string[];
|
|
43
|
+
} | {
|
|
44
|
+
kind: "unknown";
|
|
45
|
+
error: UsageError;
|
|
46
|
+
};
|
|
26
47
|
declare class CommandRegistry {
|
|
27
48
|
private root;
|
|
28
49
|
/** Binary name shown in usage/help/error strings (e.g. "bl", "rag"). */
|
|
29
50
|
private readonly cliName;
|
|
30
|
-
|
|
51
|
+
private readonly authRequirements;
|
|
52
|
+
constructor(commands: Record<string, AnyCommand>, cliName: string);
|
|
31
53
|
private register;
|
|
32
|
-
getAllCommands():
|
|
54
|
+
getAllCommands(): AnyCommand[];
|
|
33
55
|
/** First registered command path, for the "Getting Help" example (e.g. "knowledge retrieve"). */
|
|
34
56
|
private helpExample;
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
57
|
+
/**
|
|
58
|
+
* Resolve a command path to a leaf / group / unknown outcome. Pure: walks the
|
|
59
|
+
* trie taking the longest registered prefix as the command. There are no
|
|
60
|
+
* positionals, so a valid command followed by leftover tokens is `unknown`
|
|
61
|
+
* (unexpected argument). Never throws — unknown paths return a carried UsageError.
|
|
62
|
+
*/
|
|
63
|
+
locate(commandPath: string[]): LocateResult;
|
|
40
64
|
private buildResourceLines;
|
|
41
|
-
private
|
|
65
|
+
private buildFlagLines;
|
|
66
|
+
private buildAuthFlagSection;
|
|
42
67
|
private bold;
|
|
43
68
|
private accent;
|
|
44
69
|
private dim;
|
|
@@ -49,21 +74,89 @@ declare class CommandRegistry {
|
|
|
49
74
|
private printChildren;
|
|
50
75
|
}
|
|
51
76
|
//#endregion
|
|
77
|
+
//#region src/resolve.d.ts
|
|
78
|
+
/**
|
|
79
|
+
* What an invocation resolves to — "what to do" expressed as data, not control
|
|
80
|
+
* flow. A single pure function (`resolve`) produces one of these; `createCli`'s
|
|
81
|
+
* dispatch switches on it. No scattered `argv.includes(...)` + `process.exit`.
|
|
82
|
+
* - version: print the version and stop.
|
|
83
|
+
* - help: print help for `path` (root [] / a group / an explicit --help). Terminal.
|
|
84
|
+
* - run: execute `command`; `rest` is the flag region for parseFlags.
|
|
85
|
+
* - usageError: the path doesn't exist (or has unexpected args); render and stop.
|
|
86
|
+
*/
|
|
87
|
+
type Resolution = {
|
|
88
|
+
kind: "version";
|
|
89
|
+
} | {
|
|
90
|
+
kind: "help";
|
|
91
|
+
path: string[];
|
|
92
|
+
} | {
|
|
93
|
+
kind: "run";
|
|
94
|
+
path: string[];
|
|
95
|
+
command: AnyCommand;
|
|
96
|
+
rest: string[];
|
|
97
|
+
} | {
|
|
98
|
+
kind: "usageError";
|
|
99
|
+
error: UsageError;
|
|
100
|
+
};
|
|
101
|
+
/**
|
|
102
|
+
* Classify argv into a {@link Resolution}. Pure over (argv, registry): one
|
|
103
|
+
* `parsePath` scan for the command path + flag region, one `registry.locate`
|
|
104
|
+
* for the routing decision. Never throws. Trivially unit-testable.
|
|
105
|
+
*/
|
|
106
|
+
declare function resolve(argv: string[], registry: CommandRegistry): Resolution;
|
|
107
|
+
//#endregion
|
|
108
|
+
//#region src/middleware.d.ts
|
|
109
|
+
/**
|
|
110
|
+
* What each middleware stage gets for the invocation in flight: the matched
|
|
111
|
+
* `command` with its `path`/`settings`/`flags`, and the `client` (populated by
|
|
112
|
+
* {@link authStage}). A stage reads these and may augment them before `next()`.
|
|
113
|
+
*/
|
|
114
|
+
interface RunContext {
|
|
115
|
+
/** 静态产品身份(binName/version/npmPackage/clientName)。 */
|
|
116
|
+
readonly identity: Identity;
|
|
117
|
+
/** The matched command path, e.g. ["speech","recognize"]. */
|
|
118
|
+
readonly path: string[];
|
|
119
|
+
readonly command: AnyCommand;
|
|
120
|
+
/** 只含本命令声明的 flag(分流后);全局 flag 在 sources/settings。 */
|
|
121
|
+
flags: ParsedFlags<FlagsDef>;
|
|
122
|
+
/** 解析后的有效配置面(命令的新读取面;双轨迁移期与 config 并存)。 */
|
|
123
|
+
settings: Settings;
|
|
124
|
+
/** 解析源:provider/访问器用;业务命令不可见(窄视图类型不含此字段)。 */
|
|
125
|
+
sources: ResolutionSources;
|
|
126
|
+
/** 惰性访问器,lint 限定 commands/config/** 使用。 */
|
|
127
|
+
configStore(): ConfigStore;
|
|
128
|
+
/** 惰性访问器,lint 限定 commands/auth/** 使用。 */
|
|
129
|
+
authStore(): AuthStore;
|
|
130
|
+
/** Network surface with the credential baked in — set by {@link authStage}. */
|
|
131
|
+
client: Client;
|
|
132
|
+
}
|
|
133
|
+
/** Koa-style onion middleware: do work, call `next()`, do work after it returns. */
|
|
134
|
+
type Middleware = (ctx: RunContext, next: () => Promise<void>) => Promise<void>;
|
|
135
|
+
/** Fold a middleware list into a single runnable function. */
|
|
136
|
+
declare function compose(stack: Middleware[]): (ctx: RunContext) => Promise<void>;
|
|
137
|
+
//#endregion
|
|
52
138
|
//#region src/args.d.ts
|
|
139
|
+
interface ParsePathResult {
|
|
140
|
+
/** Command path: the leading run of bare tokens, e.g. ["speech", "recognize"]. */
|
|
141
|
+
path: string[];
|
|
142
|
+
/** Everything from the first flag onward — handed to parseFlags later. */
|
|
143
|
+
rest: string[];
|
|
144
|
+
hasHelpFlag: boolean;
|
|
145
|
+
hasVersionFlag: boolean;
|
|
146
|
+
}
|
|
53
147
|
/**
|
|
54
|
-
*
|
|
55
|
-
*
|
|
56
|
-
*
|
|
148
|
+
* First pass — routing only. The command path is the leading run of bare
|
|
149
|
+
* (non-`-`) tokens; the first flag ends it ("command path first, then flags",
|
|
150
|
+
* oclif-style). There are no positionals, so nothing bare can legitimately
|
|
151
|
+
* follow a flag — and no flags precede the path, so this needs no schema.
|
|
57
152
|
*/
|
|
58
|
-
declare function
|
|
153
|
+
declare function parsePath(argv: string[]): ParsePathResult;
|
|
59
154
|
/**
|
|
60
|
-
*
|
|
61
|
-
*
|
|
62
|
-
*
|
|
63
|
-
* - array: type: 'array' (repeatable via multiple --flag occurrences)
|
|
64
|
-
* - default: string
|
|
155
|
+
* Second pass — parse the flag region into typed values, driven entirely by the
|
|
156
|
+
* keyed FlagsDef (key = camelCase flag name). Pure: returns typed flags or
|
|
157
|
+
* throws UsageError — never prints/exits. The error boundary decides rendering.
|
|
65
158
|
*/
|
|
66
|
-
declare function parseFlags(
|
|
159
|
+
declare function parseFlags<F extends FlagsDef>(rest: string[], defs: F): ParsedFlags<F>;
|
|
67
160
|
//#endregion
|
|
68
161
|
//#region src/proxy.d.ts
|
|
69
162
|
declare function setupProxyFromEnv(): void;
|
|
@@ -94,13 +187,8 @@ declare const VOICE_TTS_PAGE = "https://help.aliyun.com/zh/model-studio/cosyvoic
|
|
|
94
187
|
//#region src/output/output.d.ts
|
|
95
188
|
/**
|
|
96
189
|
* Emit the primary result of a command.
|
|
97
|
-
*
|
|
98
|
-
*
|
|
99
|
-
* stdout → structured data only (JSON when piped, text when TTY)
|
|
100
|
-
* stderr → human info (progress, logs, tips) — handled elsewhere
|
|
101
|
-
*
|
|
102
|
-
* This ensures `bl cmd ... | jq .` always receives clean JSON,
|
|
103
|
-
* while interactive users see human-readable text.
|
|
190
|
+
* stdout → result (text by default; JSON with --output json)
|
|
191
|
+
* stderr → human info (progress, logs, tips) — handled elsewhere
|
|
104
192
|
*/
|
|
105
193
|
declare function emitResult(data: unknown, format: OutputFormat): void;
|
|
106
194
|
/**
|
|
@@ -123,50 +211,6 @@ declare function formatTable(headers: string[], rows: string[][], {
|
|
|
123
211
|
gap?: number;
|
|
124
212
|
}): string[];
|
|
125
213
|
//#endregion
|
|
126
|
-
//#region src/output/prompt.d.ts
|
|
127
|
-
/**
|
|
128
|
-
* Build a command-usage string for the running command: `<binName> <path> <args>`.
|
|
129
|
-
* Both the product binary name and the command path come from the runtime, so
|
|
130
|
-
* callers never hardcode "bl" or their own path — the same code renders as
|
|
131
|
-
* `bl knowledge retrieve …` under bl and `rag retrieve …` under rag.
|
|
132
|
-
*/
|
|
133
|
-
declare function cmdUsage(config: Config, args?: string): string;
|
|
134
|
-
/**
|
|
135
|
-
* Prompt the user for a text value.
|
|
136
|
-
* Only call this when isInteractive() is true; otherwise the function returns
|
|
137
|
-
* undefined immediately so the caller can fail fast.
|
|
138
|
-
*/
|
|
139
|
-
declare function promptText(options: {
|
|
140
|
-
message: string;
|
|
141
|
-
defaultValue?: string;
|
|
142
|
-
}): Promise<string | undefined>;
|
|
143
|
-
/**
|
|
144
|
-
* Like promptText but confirms with y/N before proceeding.
|
|
145
|
-
*/
|
|
146
|
-
declare function promptConfirm(options: {
|
|
147
|
-
message: string;
|
|
148
|
-
initialValue?: boolean;
|
|
149
|
-
}): Promise<boolean | undefined>;
|
|
150
|
-
/**
|
|
151
|
-
* Prompt the user to select one value from a list.
|
|
152
|
-
* Only call this when isInteractive() is true; otherwise the function returns
|
|
153
|
-
* undefined immediately so the caller can fail fast.
|
|
154
|
-
*/
|
|
155
|
-
declare function promptSelect(options: {
|
|
156
|
-
message: string;
|
|
157
|
-
choices: Array<{
|
|
158
|
-
value: string;
|
|
159
|
-
label: string;
|
|
160
|
-
hint?: string;
|
|
161
|
-
}>;
|
|
162
|
-
defaultValue?: string;
|
|
163
|
-
}): Promise<string | undefined>;
|
|
164
|
-
/**
|
|
165
|
-
* Fail fast with a user-friendly error when a required option is missing
|
|
166
|
-
* in non-interactive (agent / CI) mode.
|
|
167
|
-
*/
|
|
168
|
-
declare function failIfMissing(flagName: string, context: string): never;
|
|
169
|
-
//#endregion
|
|
170
214
|
//#region src/output/progress.d.ts
|
|
171
215
|
interface Spinner {
|
|
172
216
|
start(): void;
|
|
@@ -182,17 +226,41 @@ declare function createProgressBar(total: number, label?: string): ProgressBar;
|
|
|
182
226
|
//#endregion
|
|
183
227
|
//#region src/output/banner.d.ts
|
|
184
228
|
declare function printWelcomeBanner(cliName: string): void;
|
|
185
|
-
declare function printQuickStart(): void;
|
|
229
|
+
declare function printQuickStart(tasks: readonly string[]): void;
|
|
186
230
|
//#endregion
|
|
187
231
|
//#region src/output/status-bar.d.ts
|
|
188
|
-
declare function maybeShowStatusBar(
|
|
232
|
+
declare function maybeShowStatusBar(settings: Settings, token: string, resolved: ApiKeyCredential): void;
|
|
189
233
|
//#endregion
|
|
190
234
|
//#region src/output/cjk-width.d.ts
|
|
191
235
|
declare function displayWidth(text: string): number;
|
|
192
236
|
declare function padEnd(text: string, targetWidth: number): string;
|
|
193
237
|
//#endregion
|
|
238
|
+
//#region src/output/color.d.ts
|
|
239
|
+
type TextStyle = (text: string) => string;
|
|
240
|
+
interface AnsiStyles {
|
|
241
|
+
bold: TextStyle;
|
|
242
|
+
dim: TextStyle;
|
|
243
|
+
green: TextStyle;
|
|
244
|
+
yellow: TextStyle;
|
|
245
|
+
red: TextStyle;
|
|
246
|
+
cyan: TextStyle;
|
|
247
|
+
blue: TextStyle;
|
|
248
|
+
magenta: TextStyle;
|
|
249
|
+
white: TextStyle;
|
|
250
|
+
accent: TextStyle;
|
|
251
|
+
logo: TextStyle;
|
|
252
|
+
purple: TextStyle;
|
|
253
|
+
brandBlue: TextStyle;
|
|
254
|
+
keyPink: TextStyle;
|
|
255
|
+
reset: string;
|
|
256
|
+
}
|
|
257
|
+
declare function isTerminal(out: NodeJS.WriteStream): boolean;
|
|
258
|
+
declare function supportsColor(out: NodeJS.WriteStream): boolean;
|
|
259
|
+
declare function ansi(out: NodeJS.WriteStream): AnsiStyles;
|
|
260
|
+
//#endregion
|
|
194
261
|
//#region src/utils/polling.d.ts
|
|
195
262
|
interface PollOptions {
|
|
263
|
+
/** Absolute task URL (Client passes absolute URLs through as-is). */
|
|
196
264
|
url: string;
|
|
197
265
|
intervalSec: number;
|
|
198
266
|
timeoutSec: number;
|
|
@@ -201,7 +269,7 @@ interface PollOptions {
|
|
|
201
269
|
getStatus?: (data: unknown) => string;
|
|
202
270
|
getErrorMessage?: (data: unknown) => string | undefined;
|
|
203
271
|
}
|
|
204
|
-
declare function poll<T>(
|
|
272
|
+
declare function poll<T>(client: Client, settings: Settings, opts: PollOptions): Promise<T>;
|
|
205
273
|
//#endregion
|
|
206
274
|
//#region src/utils/download.d.ts
|
|
207
275
|
declare function downloadFile(url: string, destPath: string, opts?: {
|
|
@@ -212,19 +280,21 @@ declare function downloadFile(url: string, destPath: string, opts?: {
|
|
|
212
280
|
declare function formatBytes(bytes: number): string;
|
|
213
281
|
//#endregion
|
|
214
282
|
//#region src/utils/concurrent.d.ts
|
|
215
|
-
/** Resolve concurrency from flags
|
|
216
|
-
declare function getConcurrency(flags:
|
|
283
|
+
/** Resolve concurrency from parsed command flags(`--concurrent`,defaults to 1). */
|
|
284
|
+
declare function getConcurrency(flags: {
|
|
285
|
+
concurrent?: number;
|
|
286
|
+
}): number;
|
|
217
287
|
/**
|
|
218
288
|
* Run an async task N times concurrently.
|
|
219
289
|
* Returns all resolved results in order.
|
|
220
290
|
* If any single task fails, the error propagates (Promise.all semantics).
|
|
221
291
|
*
|
|
222
|
-
* @param n
|
|
223
|
-
* @param
|
|
224
|
-
* @param task
|
|
225
|
-
* @param label
|
|
292
|
+
* @param n Number of concurrent executions
|
|
293
|
+
* @param settings Resolved settings (for logging)
|
|
294
|
+
* @param task Async factory to execute
|
|
295
|
+
* @param label Optional label for status output (e.g. "requests", "tasks")
|
|
226
296
|
*/
|
|
227
|
-
declare function runConcurrent<T>(n: number,
|
|
297
|
+
declare function runConcurrent<T>(n: number, settings: Settings, task: (index: number) => Promise<T>, label?: string): Promise<T[]>;
|
|
228
298
|
/**
|
|
229
299
|
* Parallel download helper — downloads multiple URLs concurrently.
|
|
230
300
|
*
|
|
@@ -247,16 +317,6 @@ declare function downloadParallel(items: Array<{
|
|
|
247
317
|
declare function resolveImageSize(input: string, useSync: boolean): string;
|
|
248
318
|
declare function resolveImageSize(input: string | undefined, useSync: boolean): string | undefined;
|
|
249
319
|
//#endregion
|
|
250
|
-
//#region src/utils/ensure-key.d.ts
|
|
251
|
-
declare function ensureApiKey(config: Config): Promise<void>;
|
|
252
|
-
//#endregion
|
|
253
|
-
//#region src/utils/command-help.d.ts
|
|
254
|
-
declare function setExecutingCommandPath(path: string[]): void;
|
|
255
|
-
declare function getExecutingCommandPath(): string[];
|
|
256
|
-
declare function registerCommandHelpPrinter(fn: (commandPath: string[], out: NodeJS.WriteStream) => void): void;
|
|
257
|
-
/** Print help for the command currently being executed (must call `setExecutingCommandPath` first). */
|
|
258
|
-
declare function printCurrentCommandHelp(out?: NodeJS.WriteStream): void;
|
|
259
|
-
//#endregion
|
|
260
320
|
//#region src/utils/update-checker.d.ts
|
|
261
321
|
declare const NPM_REGISTRY = "https://registry.npmjs.org";
|
|
262
322
|
/** Default npm package; products override per-call via the `npmPackage` argument. */
|
|
@@ -547,7 +607,7 @@ interface StepContext {
|
|
|
547
607
|
timeoutSeconds?: number;
|
|
548
608
|
blRequestTimeoutSeconds?: number;
|
|
549
609
|
emitEvent?: (event: Record<string, unknown>) => void | Promise<void>;
|
|
550
|
-
|
|
610
|
+
blEnv?: unknown;
|
|
551
611
|
}
|
|
552
612
|
//#endregion
|
|
553
613
|
//#region src/pipeline/dispatcher.d.ts
|
|
@@ -576,4 +636,4 @@ declare function collectPipelineHints(pipeline: PipelineDefinition, dispatcher?:
|
|
|
576
636
|
declare function executePipeline(pipeline: PipelineDefinition, runtimeInput?: Record<string, unknown>, options?: ExecutePipelineOptions): Promise<PipelineExecutionReport>;
|
|
577
637
|
declare function streamPipelineEvents(pipeline: PipelineDefinition, runtimeInput?: Record<string, unknown>, options?: Pick<ExecutePipelineOptions, "concurrency" | "basePath" | "dryRun" | "signal" | "timeoutSeconds" | "blRequestTimeoutSeconds" | "stepDispatcher">): AsyncGenerator<PipelineLifecycleEvent>;
|
|
578
638
|
//#endregion
|
|
579
|
-
export { API_KEY_PAGE, BAILIAN_CONSOLE, BAILIAN_CONSOLE_ROOT, BOOL_FLAG_PROMPT_EXTEND_API_DEFAULT, BOOL_FLAG_PROMPT_EXTEND_CLI_TRUE, BOOL_FLAG_PROMPT_EXTEND_IMAGE_GENERATE, BOOL_FLAG_WATERMARK, CLI_VERSION, type Cli, type CliOptions, type Command, CommandRegistry, NPM_PACKAGE, NPM_REGISTRY, type
|
|
639
|
+
export { API_KEY_PAGE, type AnsiStyles, BAILIAN_CONSOLE, BAILIAN_CONSOLE_ROOT, BOOL_FLAG_PROMPT_EXTEND_API_DEFAULT, BOOL_FLAG_PROMPT_EXTEND_CLI_TRUE, BOOL_FLAG_PROMPT_EXTEND_IMAGE_GENERATE, BOOL_FLAG_WATERMARK, CLI_VERSION, type Cli, type CliOptions, type Command, CommandRegistry, type FlagDef, type LocateResult, type Middleware, NPM_PACKAGE, NPM_REGISTRY, type ParsePathResult, type PipelineDefinition, type PipelineLifecycleEvent, type Resolution, type RunContext, type TextStyle, VOICE_TTS_PAGE, ansi, checkForUpdate, collectPipelineHints, collectPipelineIssues, compose, createCli, createProgressBar, createSpinner, displayWidth, downloadFile, downloadParallel, emitBare, emitResult, executePipeline, fetchLatestVersion, formatBytes, formatTable, getConcurrency, getPendingUpdateNotification, handleError, initPipelineSteps, isTerminal, maybeShowStatusBar, padEnd, parseFlags, parsePath, poll, printQuickStart, printWelcomeBanner, resolve, resolveImageSize, runConcurrent, setupProxyFromEnv, streamPipelineEvents, supportsColor };
|