bailian-cli-core 0.0.0-beta-ca77c77-20260605

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,994 @@
1
+ //#region src/errors/codes.d.ts
2
+ declare const ExitCode: {
3
+ readonly SUCCESS: 0;
4
+ readonly GENERAL: 1;
5
+ readonly USAGE: 2;
6
+ readonly AUTH: 3;
7
+ readonly QUOTA: 4;
8
+ readonly TIMEOUT: 5;
9
+ readonly NETWORK: 6;
10
+ readonly CONTENT_FILTER: 10;
11
+ };
12
+ type ExitCode = (typeof ExitCode)[keyof typeof ExitCode];
13
+ //#endregion
14
+ //#region src/errors/base.d.ts
15
+ interface ApiErrorContext {
16
+ httpStatus?: number;
17
+ apiCode?: string;
18
+ requestId?: string;
19
+ }
20
+ interface BailianErrorOptions {
21
+ cause?: unknown;
22
+ api?: ApiErrorContext;
23
+ }
24
+ declare class BailianError extends Error {
25
+ readonly exitCode: ExitCode;
26
+ readonly hint?: string;
27
+ readonly api?: ApiErrorContext;
28
+ constructor(message: string, exitCode?: ExitCode, hint?: string, options?: BailianErrorOptions);
29
+ toJSON(): {
30
+ error: {
31
+ code: ExitCode;
32
+ message: string;
33
+ hint?: string | undefined;
34
+ http_status?: number | undefined;
35
+ api_code?: string | undefined;
36
+ request_id?: string | undefined;
37
+ cause?: Record<string, unknown> | undefined;
38
+ };
39
+ };
40
+ }
41
+ //#endregion
42
+ //#region src/errors/api.d.ts
43
+ interface ApiErrorBody {
44
+ error?: {
45
+ message?: string;
46
+ type?: string;
47
+ code?: number | string;
48
+ };
49
+ code?: string;
50
+ message?: string;
51
+ request_id?: string;
52
+ }
53
+ declare function mapApiError(status: number, body: ApiErrorBody, _url?: string): BailianError;
54
+ //#endregion
55
+ //#region src/types/api.d.ts
56
+ interface ChatMessage {
57
+ role: "system" | "user" | "assistant";
58
+ content: string | ChatMessageContent[];
59
+ }
60
+ type ChatMessageContent = {
61
+ type: "text";
62
+ text: string;
63
+ } | {
64
+ type: "image_url";
65
+ image_url: {
66
+ url: string;
67
+ };
68
+ } | {
69
+ type: "input_audio";
70
+ input_audio: {
71
+ data: string;
72
+ format?: string;
73
+ };
74
+ } | {
75
+ type: "audio_url";
76
+ audio_url: {
77
+ url: string;
78
+ };
79
+ } | {
80
+ type: "video";
81
+ video: string[];
82
+ } | {
83
+ type: "video_url";
84
+ video_url: {
85
+ url: string;
86
+ };
87
+ };
88
+ interface ChatTool {
89
+ type: "function";
90
+ function: {
91
+ name: string;
92
+ description?: string;
93
+ parameters: Record<string, unknown>;
94
+ };
95
+ }
96
+ interface ChatRequest {
97
+ model: string;
98
+ messages: ChatMessage[];
99
+ max_tokens?: number;
100
+ temperature?: number;
101
+ top_p?: number;
102
+ stream?: boolean;
103
+ tools?: ChatTool[];
104
+ tool_choice?: "auto" | "none" | {
105
+ type: "function";
106
+ function: {
107
+ name: string;
108
+ };
109
+ };
110
+ enable_thinking?: boolean;
111
+ thinking_budget?: number;
112
+ modalities?: string[];
113
+ audio?: {
114
+ voice: string;
115
+ format?: string;
116
+ };
117
+ stream_options?: {
118
+ include_usage?: boolean;
119
+ };
120
+ }
121
+ interface ChatChoice {
122
+ index: number;
123
+ message: {
124
+ role: "assistant";
125
+ content: string | null;
126
+ reasoning_content?: string | null;
127
+ tool_calls?: Array<{
128
+ id: string;
129
+ type: "function";
130
+ function: {
131
+ name: string;
132
+ arguments: string;
133
+ };
134
+ }>;
135
+ };
136
+ finish_reason: string;
137
+ }
138
+ interface ChatResponse {
139
+ id: string;
140
+ object: "chat.completion";
141
+ created: number;
142
+ model: string;
143
+ choices: ChatChoice[];
144
+ usage: {
145
+ prompt_tokens: number;
146
+ completion_tokens: number;
147
+ total_tokens: number;
148
+ };
149
+ }
150
+ interface StreamChoice {
151
+ index: number;
152
+ delta: {
153
+ role?: string;
154
+ content?: string | null;
155
+ reasoning_content?: string | null;
156
+ audio?: {
157
+ data?: string;
158
+ id?: string;
159
+ expires_at?: number;
160
+ };
161
+ tool_calls?: Array<{
162
+ index: number;
163
+ id?: string;
164
+ type?: "function";
165
+ function?: {
166
+ name?: string;
167
+ arguments?: string;
168
+ };
169
+ }>;
170
+ };
171
+ finish_reason: string | null;
172
+ }
173
+ interface StreamChunk {
174
+ id: string;
175
+ object: "chat.completion.chunk";
176
+ created: number;
177
+ model: string;
178
+ choices: StreamChoice[];
179
+ usage?: {
180
+ prompt_tokens: number;
181
+ completion_tokens: number;
182
+ total_tokens: number;
183
+ };
184
+ }
185
+ interface DashScopeImageRequest {
186
+ model: string;
187
+ input: {
188
+ messages: Array<{
189
+ role: "user";
190
+ content: Array<{
191
+ text?: string;
192
+ image?: string;
193
+ }>;
194
+ }>;
195
+ };
196
+ parameters?: {
197
+ size?: string;
198
+ n?: number;
199
+ seed?: number;
200
+ prompt_extend?: boolean;
201
+ watermark?: boolean;
202
+ negative_prompt?: string;
203
+ };
204
+ }
205
+ interface DashScopeImageSyncResponse {
206
+ output: {
207
+ choices: Array<{
208
+ finish_reason: string;
209
+ message: {
210
+ role: "assistant";
211
+ content: Array<{
212
+ image: string;
213
+ type: "image";
214
+ }>;
215
+ };
216
+ }>;
217
+ finished: boolean;
218
+ };
219
+ usage: {
220
+ image_count: number;
221
+ };
222
+ request_id: string;
223
+ }
224
+ interface DashScopeVideoRequest {
225
+ model: string;
226
+ input: {
227
+ prompt: string;
228
+ negative_prompt?: string;
229
+ img_url?: string;
230
+ media?: Array<{
231
+ type: "image" | "video" | "first_frame" | "last_frame" | "driving_audio" | "first_clip";
232
+ url: string;
233
+ }>;
234
+ };
235
+ parameters?: {
236
+ resolution?: string;
237
+ ratio?: string;
238
+ duration?: number;
239
+ prompt_extend?: boolean;
240
+ watermark?: boolean;
241
+ seed?: number;
242
+ };
243
+ }
244
+ interface DashScopeVideoRefRequest {
245
+ model: string;
246
+ input: {
247
+ prompt: string;
248
+ media: Array<{
249
+ type: "reference_image" | "reference_video";
250
+ url: string;
251
+ reference_voice?: string;
252
+ }>;
253
+ };
254
+ parameters?: {
255
+ resolution?: string;
256
+ ratio?: string;
257
+ duration?: number;
258
+ prompt_extend?: boolean;
259
+ watermark?: boolean;
260
+ seed?: number;
261
+ };
262
+ }
263
+ interface DashScopeVideoEditRequest {
264
+ model: string;
265
+ input: {
266
+ prompt?: string;
267
+ negative_prompt?: string;
268
+ media: Array<{
269
+ type: "video" | "reference_image";
270
+ url: string;
271
+ }>;
272
+ };
273
+ parameters?: {
274
+ resolution?: string;
275
+ ratio?: string;
276
+ duration?: number;
277
+ audio_setting?: "auto" | "origin";
278
+ prompt_extend?: boolean;
279
+ watermark?: boolean;
280
+ seed?: number;
281
+ };
282
+ }
283
+ interface AppCompletionRequest {
284
+ input: {
285
+ prompt?: string;
286
+ session_id?: string;
287
+ image_list?: string[];
288
+ file_ids?: string[];
289
+ biz_params?: Record<string, unknown>;
290
+ };
291
+ parameters?: {
292
+ has_thoughts?: boolean;
293
+ incremental_output?: boolean;
294
+ rag_options?: {
295
+ pipeline_ids?: string[];
296
+ knowledge_base_ids?: string[];
297
+ };
298
+ memory_id?: string;
299
+ };
300
+ debug?: Record<string, unknown>;
301
+ }
302
+ interface AppCompletionResponse {
303
+ output: {
304
+ text: string;
305
+ finish_reason: string;
306
+ session_id: string;
307
+ thoughts?: Array<{
308
+ thought: string;
309
+ action_type: string;
310
+ action_name: string;
311
+ action: string;
312
+ action_input_stream: string;
313
+ action_input: string;
314
+ response: string;
315
+ observation: string;
316
+ }>;
317
+ doc_references?: Array<{
318
+ index_id: string;
319
+ title: string;
320
+ doc_id: string;
321
+ doc_name: string;
322
+ text: string;
323
+ images?: string[];
324
+ }>;
325
+ };
326
+ usage: {
327
+ models: Array<{
328
+ model_id: string;
329
+ input_tokens: number;
330
+ output_tokens: number;
331
+ }>;
332
+ };
333
+ request_id: string;
334
+ }
335
+ interface AppStreamChunk {
336
+ output: {
337
+ text: string;
338
+ finish_reason: string;
339
+ session_id: string;
340
+ thoughts?: AppCompletionResponse["output"]["thoughts"];
341
+ doc_references?: AppCompletionResponse["output"]["doc_references"];
342
+ };
343
+ usage?: AppCompletionResponse["usage"];
344
+ request_id: string;
345
+ }
346
+ interface MemoryMessage {
347
+ role: "user" | "assistant";
348
+ content: string;
349
+ }
350
+ interface MemoryAddRequest {
351
+ user_id: string;
352
+ messages?: MemoryMessage[];
353
+ custom_content?: string;
354
+ profile_schema?: string;
355
+ memory_library_id?: string;
356
+ }
357
+ interface MemoryAddResponse {
358
+ request_id: string;
359
+ memory_ids?: string[];
360
+ }
361
+ interface MemorySearchRequest {
362
+ user_id: string;
363
+ messages?: MemoryMessage[];
364
+ query?: string;
365
+ top_k?: number;
366
+ memory_library_id?: string;
367
+ }
368
+ interface MemoryNode {
369
+ memory_node_id: string;
370
+ content: string;
371
+ user_id?: string;
372
+ meta_data?: Record<string, unknown>;
373
+ created_at?: string;
374
+ updated_at?: string;
375
+ }
376
+ interface MemorySearchResponse {
377
+ request_id: string;
378
+ memory_nodes: MemoryNode[];
379
+ }
380
+ interface MemoryNodeListResponse {
381
+ request_id: string;
382
+ memory_nodes: MemoryNode[];
383
+ total?: number;
384
+ page_num?: number;
385
+ page_size?: number;
386
+ }
387
+ interface MemoryNodeUpdateRequest {
388
+ user_id: string;
389
+ custom_content: string;
390
+ /** 非默认记忆库时必填(与控制台记忆库 ID 一致) */
391
+ memory_library_id?: string;
392
+ }
393
+ interface ProfileAttribute {
394
+ name: string;
395
+ description: string;
396
+ value?: string;
397
+ }
398
+ interface ProfileSchemaCreateRequest {
399
+ name: string;
400
+ description?: string;
401
+ attributes: ProfileAttribute[];
402
+ }
403
+ interface ProfileSchemaCreateResponse {
404
+ request_id: string;
405
+ profile_schema_id: string;
406
+ }
407
+ interface UserProfileResponse {
408
+ request_id: string;
409
+ profile: {
410
+ schema_id: string;
411
+ user_id: string;
412
+ attributes: ProfileAttribute[];
413
+ };
414
+ }
415
+ interface KnowledgeRetrieveRequest {
416
+ IndexId: string;
417
+ Query: string;
418
+ DenseSimilarityTopK?: number;
419
+ SparseSimilarityTopK?: number;
420
+ EnableReranking?: boolean;
421
+ EnableRewrite?: boolean;
422
+ RerankTopN?: number;
423
+ TopK?: number;
424
+ Rerank?: boolean;
425
+ RerankTopN_legacy?: number;
426
+ SearchFilters?: Array<{
427
+ Key: string;
428
+ Value: string;
429
+ Operator: string;
430
+ }>;
431
+ }
432
+ interface KnowledgeRetrieveResponse {
433
+ Success: boolean;
434
+ RequestId: string;
435
+ Data: {
436
+ Nodes: Array<{
437
+ Text: string;
438
+ Score: number;
439
+ Metadata: Record<string, unknown>;
440
+ }>;
441
+ };
442
+ }
443
+ interface DashScopeTTSRequest {
444
+ model: string;
445
+ input: {
446
+ text: string;
447
+ voice?: string;
448
+ format?: "mp3" | "pcm" | "wav" | "opus";
449
+ sample_rate?: number;
450
+ volume?: number;
451
+ rate?: number;
452
+ pitch?: number;
453
+ seed?: number;
454
+ language_hints?: string[];
455
+ instruction?: string;
456
+ enable_ssml?: boolean;
457
+ };
458
+ }
459
+ interface DashScopeTTSResponse {
460
+ output: {
461
+ audio: {
462
+ url: string;
463
+ expires_at?: string;
464
+ };
465
+ finish_reason?: string;
466
+ };
467
+ usage?: Record<string, unknown>;
468
+ request_id: string;
469
+ }
470
+ interface DashScopeTTSStreamChunk {
471
+ output: {
472
+ audio: {
473
+ data?: string;
474
+ url?: string;
475
+ expires_at?: string;
476
+ };
477
+ finish_reason?: string;
478
+ };
479
+ usage?: Record<string, unknown>;
480
+ request_id?: string;
481
+ }
482
+ interface DashScopeASRRequest {
483
+ model: string;
484
+ input: {
485
+ file_urls: string[];
486
+ };
487
+ parameters?: {
488
+ channel_id?: number[];
489
+ language_hints?: string[];
490
+ diarization_enabled?: boolean;
491
+ speaker_count?: number;
492
+ vocabulary_id?: string;
493
+ };
494
+ }
495
+ interface DashScopeASRTaskResult {
496
+ output: {
497
+ task_id: string;
498
+ task_status: "PENDING" | "RUNNING" | "SUCCEEDED" | "FAILED" | "UNKNOWN";
499
+ results?: Array<{
500
+ file_url?: string;
501
+ transcription_url?: string;
502
+ subtask_status?: string;
503
+ code?: string;
504
+ message?: string;
505
+ }>;
506
+ task_metrics?: {
507
+ TOTAL: number;
508
+ SUCCEEDED: number;
509
+ FAILED: number;
510
+ };
511
+ };
512
+ usage?: Record<string, unknown>;
513
+ request_id: string;
514
+ }
515
+ interface DashScopeAsyncResponse {
516
+ output: {
517
+ task_id: string;
518
+ task_status: string;
519
+ };
520
+ request_id: string;
521
+ }
522
+ interface DashScopeTaskResponse {
523
+ output: {
524
+ task_id: string;
525
+ task_status: "PENDING" | "RUNNING" | "SUCCEEDED" | "FAILED" | "UNKNOWN";
526
+ finished?: boolean;
527
+ task_metrics?: {
528
+ TOTAL?: number;
529
+ SUCCEEDED?: number;
530
+ FAILED?: number;
531
+ };
532
+ choices?: Array<{
533
+ finish_reason: string;
534
+ message: {
535
+ role: "assistant";
536
+ content: Array<{
537
+ image: string;
538
+ type: "image";
539
+ }>;
540
+ };
541
+ }>;
542
+ results?: Array<{
543
+ url: string;
544
+ }>;
545
+ video_url?: string;
546
+ submit_time?: string;
547
+ scheduled_time?: string;
548
+ end_time?: string;
549
+ code?: string;
550
+ message?: string;
551
+ };
552
+ usage?: Record<string, unknown>;
553
+ request_id: string;
554
+ }
555
+ //#endregion
556
+ //#region src/auth/credentials.d.ts
557
+ declare function loadApiKeyFromConfig(): string | null;
558
+ declare function saveApiKeyToConfig(apiKey: string): Promise<void>;
559
+ declare function clearApiKey(): Promise<void>;
560
+ //#endregion
561
+ //#region src/config/schema.d.ts
562
+ declare const REGIONS: {
563
+ readonly cn: "https://dashscope.aliyuncs.com";
564
+ readonly us: "https://dashscope-us.aliyuncs.com";
565
+ readonly intl: "https://dashscope-intl.aliyuncs.com";
566
+ };
567
+ declare const DOCS_HOSTS: {
568
+ readonly cn: "https://help.aliyun.com/zh/model-studio";
569
+ readonly us: "https://help.aliyun.com/zh/model-studio";
570
+ readonly intl: "https://help.aliyun.com/zh/model-studio";
571
+ };
572
+ declare const BAILIAN_HOST = "https://bailian.cn-beijing.aliyuncs.com";
573
+ type Region = keyof typeof REGIONS;
574
+ interface ConfigFile {
575
+ api_key?: string;
576
+ /** OAuth-style token from `bl auth login --console` callback; sent as `Authorization: Bearer …` */
577
+ access_token?: string;
578
+ region?: Region;
579
+ base_url?: string;
580
+ output?: "text" | "json";
581
+ output_dir?: string;
582
+ timeout?: number;
583
+ default_text_model?: string;
584
+ default_video_model?: string;
585
+ default_image_model?: string;
586
+ default_speech_model?: string;
587
+ default_omni_model?: string;
588
+ access_key_id?: string;
589
+ access_key_secret?: string;
590
+ workspace_id?: string;
591
+ console_gateway_url?: string;
592
+ telemetry?: boolean;
593
+ }
594
+ declare function parseConfigFile(raw: unknown): ConfigFile;
595
+ interface Config {
596
+ clientName?: string;
597
+ clientVersion?: string;
598
+ apiKey?: string;
599
+ /** `DASHSCOPE_ACCESS_TOKEN` env (explicit override). */
600
+ accessTokenEnv?: string;
601
+ /** `access_token` in config file (console login). */
602
+ fileAccessToken?: string;
603
+ fileApiKey?: string;
604
+ fileRegion?: Region;
605
+ configPath?: string;
606
+ region: Region;
607
+ baseUrl: string;
608
+ output: "text" | "json";
609
+ outputDir?: string;
610
+ timeout: number;
611
+ defaultTextModel?: string;
612
+ defaultVideoModel?: string;
613
+ defaultImageModel?: string;
614
+ defaultSpeechModel?: string;
615
+ defaultOmniModel?: string;
616
+ accessKeyId?: string;
617
+ accessKeySecret?: string;
618
+ workspaceId?: string;
619
+ consoleGatewayUrl: string;
620
+ verbose: boolean;
621
+ quiet: boolean;
622
+ noColor: boolean;
623
+ yes: boolean;
624
+ dryRun: boolean;
625
+ nonInteractive: boolean;
626
+ async: boolean;
627
+ telemetry: boolean;
628
+ }
629
+ //#endregion
630
+ //#region src/auth/types.d.ts
631
+ type AuthMethod = "api-key" | "access-token";
632
+ interface ResolvedCredential {
633
+ token: string;
634
+ method: AuthMethod;
635
+ source: string;
636
+ }
637
+ //#endregion
638
+ //#region src/auth/resolver.d.ts
639
+ declare function resolveCredential(config: Config): Promise<ResolvedCredential>;
640
+ /**
641
+ * Credential for Bailian **console** CLI gateway only (`callConsoleGateway`).
642
+ * DashScope API keys are not valid Bearer tokens for this gateway — use env/file
643
+ * `access_token` even when `api_key` is also present in config.
644
+ */
645
+ /** Thrown when `callConsoleGateway` has no usable console session token. */
646
+ declare const CONSOLE_GATEWAY_NO_TOKEN_MESSAGE = "No console access token found.";
647
+ declare function resolveConsoleGatewayCredential(config: Config): Promise<ResolvedCredential>;
648
+ //#endregion
649
+ //#region src/client/ak-sign.d.ts
650
+ /**
651
+ * Alibaba Cloud V3 Signature (ROA style) for Bailian Cloud API.
652
+ *
653
+ * Used by Knowledge Base Retrieve API which requires AK/SK authentication
654
+ * instead of Bearer token.
655
+ *
656
+ * Reference: https://help.aliyun.com/document_detail/2712195.html
657
+ */
658
+ interface AkSignConfig {
659
+ accessKeyId: string;
660
+ accessKeySecret: string;
661
+ action: string;
662
+ version: string;
663
+ body: string;
664
+ host: string;
665
+ pathname: string;
666
+ method?: string;
667
+ }
668
+ declare function signRequest(cfg: AkSignConfig): Record<string, string>;
669
+ //#endregion
670
+ //#region src/client/endpoints.d.ts
671
+ declare function chatEndpoint(baseUrl: string): string;
672
+ declare function imageEndpoint(baseUrl: string): string;
673
+ declare function imageSyncEndpoint(baseUrl: string): string;
674
+ declare function videoGenerateEndpoint(baseUrl: string): string;
675
+ declare function taskEndpoint(baseUrl: string, taskId: string): string;
676
+ declare function appCompletionEndpoint(baseUrl: string, appId: string): string;
677
+ declare function memoryAddEndpoint(baseUrl: string): string;
678
+ declare function memorySearchEndpoint(baseUrl: string): string;
679
+ declare function memoryListEndpoint(baseUrl: string): string;
680
+ declare function memoryNodeEndpoint(baseUrl: string, nodeId: string): string;
681
+ declare function speechSynthesizeEndpoint(baseUrl: string): string;
682
+ declare function speechRecognizeEndpoint(baseUrl: string): string;
683
+ declare function profileSchemaEndpoint(baseUrl: string): string;
684
+ declare function userProfileEndpoint(baseUrl: string, schemaId: string): string;
685
+ declare function mcpWebSearchEndpoint(baseUrl: string): string;
686
+ //#endregion
687
+ //#region src/client/headers.d.ts
688
+ /**
689
+ * Shared HTTP request headers for all outgoing requests.
690
+ *
691
+ * Centralises the `x-dashscope-source-config` header so every fetch call
692
+ * (both via the central http client and the bypass paths) uses the
693
+ * same values from a single source of truth.
694
+ */
695
+ declare const CHANNEL = "bailian-cli";
696
+ declare const TAGS: {
697
+ t1: string;
698
+ t2: string;
699
+ };
700
+ declare const SOURCE_CONFIG: string;
701
+ /** Standard tracking headers required on every outbound request. */
702
+ declare function trackingHeaders(): Record<string, string>;
703
+ //#endregion
704
+ //#region src/client/http.d.ts
705
+ interface RequestOpts {
706
+ url: string;
707
+ method?: string;
708
+ body?: unknown;
709
+ headers?: Record<string, string>;
710
+ timeout?: number;
711
+ stream?: boolean;
712
+ noAuth?: boolean;
713
+ async?: boolean;
714
+ signal?: AbortSignal;
715
+ }
716
+ declare function request(config: Config, opts: RequestOpts): Promise<Response>;
717
+ declare function requestJson<T>(config: Config, opts: RequestOpts): Promise<T>;
718
+ //#endregion
719
+ //#region src/client/mcp.d.ts
720
+ interface McpTool {
721
+ name: string;
722
+ description?: string;
723
+ inputSchema?: Record<string, unknown>;
724
+ }
725
+ interface McpToolResult {
726
+ content: Array<{
727
+ type: string;
728
+ text?: string;
729
+ data?: string;
730
+ mimeType?: string;
731
+ }>;
732
+ isError?: boolean;
733
+ }
734
+ /**
735
+ * Compose the streamable-HTTP MCP endpoint for a Bailian MCP server.
736
+ * The path is `/api/v1/mcps/<serverCode>/mcp`; the `serverCode` is taken
737
+ * verbatim from `bl mcp list` (e.g. `WebSearch`, `market-cmapi00073529`).
738
+ */
739
+ declare function bailianMcpUrl(baseUrl: string, serverCode: string): string;
740
+ declare class McpClient {
741
+ private url;
742
+ private sessionId;
743
+ private nextId;
744
+ private config;
745
+ private authToken;
746
+ constructor(config: Config, url: string);
747
+ /** Initialize the MCP session. Must be called before any other method. */
748
+ initialize(): Promise<void>;
749
+ listTools(): Promise<McpTool[]>;
750
+ callTool(name: string, args: Record<string, unknown>): Promise<McpToolResult>;
751
+ private rpc;
752
+ private notify;
753
+ private send;
754
+ }
755
+ //#endregion
756
+ //#region src/client/stream.d.ts
757
+ interface ServerSentEvent {
758
+ event?: string;
759
+ data: string;
760
+ id?: string;
761
+ }
762
+ declare function parseSSE(response: Response): AsyncGenerator<ServerSentEvent>;
763
+ //#endregion
764
+ //#region src/console/gateway.d.ts
765
+ interface ConsoleGatewayRequest {
766
+ /** Console API name, e.g. zeldaEasy.broadscope-bailian.freeTrial.queryFreeTierQuota */
767
+ api: string;
768
+ data: Record<string, unknown>;
769
+ /** Console region (default: cn-beijing), distinct from DashScope `config.region`. */
770
+ region?: string;
771
+ }
772
+ /**
773
+ * Invoke a Bailian **console** OpenAPI via the CLI gateway (`/cli/api.json`).
774
+ * `token` is the console `access_token` (from `bl auth login --console`); when
775
+ * omitted the request is sent without an Authorization header, which works for
776
+ * public console APIs that don't require a login session.
777
+ */
778
+ declare function callConsoleGateway(config: Config, token: string | undefined, {
779
+ api,
780
+ data,
781
+ region
782
+ }: ConsoleGatewayRequest): Promise<unknown>;
783
+ //#endregion
784
+ //#region src/types/flags.d.ts
785
+ interface GlobalFlags {
786
+ apiKey?: string;
787
+ baseUrl?: string;
788
+ output?: string;
789
+ quiet: boolean;
790
+ verbose: boolean;
791
+ timeout?: number;
792
+ noColor: boolean;
793
+ yes: boolean;
794
+ dryRun: boolean;
795
+ help: boolean;
796
+ nonInteractive: boolean;
797
+ async: boolean;
798
+ [key: string]: unknown;
799
+ }
800
+ //#endregion
801
+ //#region src/config/loader.d.ts
802
+ declare function readConfigFile(): ConfigFile;
803
+ declare function writeConfigFile(data: Record<string, unknown>): Promise<void>;
804
+ declare function loadConfig(flags: GlobalFlags): Config;
805
+ //#endregion
806
+ //#region src/config/paths.d.ts
807
+ declare function getConfigDir(): string;
808
+ declare function getConfigPath(): string;
809
+ declare function getCredentialsPath(): string;
810
+ declare function ensureConfigDir(): Promise<void>;
811
+ //#endregion
812
+ //#region src/output/formatter.d.ts
813
+ type OutputFormat = "text" | "json";
814
+ declare function detectOutputFormat(flagValue?: string): OutputFormat;
815
+ declare function formatOutput(data: unknown, format: OutputFormat): string;
816
+ //#endregion
817
+ //#region src/output/json.d.ts
818
+ declare function formatJson(data: unknown): string;
819
+ declare function formatErrorJson(code: number, message: string, hint?: string): string;
820
+ //#endregion
821
+ //#region src/output/text.d.ts
822
+ declare function formatText(data: unknown): string;
823
+ //#endregion
824
+ //#region src/files/upload.d.ts
825
+ interface UploadOptions {
826
+ apiKey: string;
827
+ model: string;
828
+ filePath: string;
829
+ signal?: AbortSignal;
830
+ }
831
+ /**
832
+ * Upload a local file to DashScope temporary storage and return the oss:// URL.
833
+ * The URL is valid for 48 hours.
834
+ */
835
+ declare function uploadFile(opts: UploadOptions): Promise<string>;
836
+ /**
837
+ * Check if a string looks like a local file path (not a URL).
838
+ */
839
+ declare function isLocalFile(input: string): boolean;
840
+ /**
841
+ * Resolve a file argument: if it's a local path, upload it and return the oss:// URL.
842
+ * If it's already a URL, return as-is.
843
+ */
844
+ declare function resolveFileUrl(input: string, apiKey: string, model: string, opts?: {
845
+ signal?: AbortSignal;
846
+ }): Promise<string>;
847
+ //#endregion
848
+ //#region src/types/command.d.ts
849
+ interface OptionDef {
850
+ flag: string;
851
+ description: string;
852
+ type?: "string" | "number" | "boolean" | "array";
853
+ required?: boolean;
854
+ }
855
+ interface Command {
856
+ name: string;
857
+ description: string;
858
+ usage?: string;
859
+ options?: OptionDef[];
860
+ examples?: string[];
861
+ apiDocs?: string;
862
+ execute: (config: Config, flags: GlobalFlags) => Promise<void>;
863
+ }
864
+ interface CommandSpec {
865
+ name: string;
866
+ description: string;
867
+ usage?: string;
868
+ options?: OptionDef[];
869
+ examples?: string[];
870
+ apiDocs?: string;
871
+ run: (config: Config, flags: GlobalFlags) => Promise<void>;
872
+ }
873
+ declare function defineCommand(spec: CommandSpec): Command;
874
+ /** Global flags shared by all commands — drives the parser's type resolution. */
875
+ declare const GLOBAL_OPTIONS: OptionDef[];
876
+ //#endregion
877
+ //#region src/utils/filename.d.ts
878
+ declare function generateFilename(prefix: string, prompt: string): string;
879
+ //#endregion
880
+ //#region src/utils/output-dir.d.ts
881
+ /**
882
+ * Resolve the output directory for generated files.
883
+ *
884
+ * Priority:
885
+ * 1. User-specified dir (e.g. --out-dir flag)
886
+ * 2. Config file output_dir
887
+ * 3. Default: ~/bailian-output/
888
+ *
889
+ * Optionally appends a subdirectory (e.g. 'images', 'videos', 'speech').
890
+ * Creates the directory if it doesn't exist.
891
+ */
892
+ declare function resolveOutputDir(config: Config, options?: {
893
+ flagDir?: string;
894
+ subDir?: string;
895
+ }): string;
896
+ //#endregion
897
+ //#region src/utils/schema.d.ts
898
+ declare function generateToolSchema(cmd: Command): Record<string, unknown>;
899
+ //#endregion
900
+ //#region src/utils/token.d.ts
901
+ declare function maskToken(token: string): string;
902
+ //#endregion
903
+ //#region src/utils/env.d.ts
904
+ /**
905
+ * Environment detection utilities for bailian-cli.
906
+ *
907
+ * Used to determine whether the CLI is running in an interactive terminal
908
+ * (human user) or in a non-interactive environment (CI, agent, pipe, etc.),
909
+ * so commands can adjust their behavior accordingly.
910
+ */
911
+ /**
912
+ * Detects whether the current environment is interactive.
913
+ *
914
+ * Returns false when:
915
+ * - stdout or stdin is not a TTY
916
+ * - The --non-interactive flag was explicitly set
917
+ * - The process is running in a known CI environment (CI env var present)
918
+ *
919
+ * Returns true when stdout and stdin are both TTYs and --non-interactive
920
+ * was not passed.
921
+ */
922
+ declare function isInteractive(options?: {
923
+ nonInteractive?: boolean;
924
+ }): boolean;
925
+ /**
926
+ * Detects whether the current process is running in a CI environment.
927
+ */
928
+ declare function isCI(): boolean;
929
+ //#endregion
930
+ //#region src/utils/object.d.ts
931
+ /**
932
+ * Generic object-cleaning utilities.
933
+ */
934
+ /**
935
+ * Remove all keys whose value is `undefined` from a plain object (in-place).
936
+ * Returns the same reference for chaining convenience.
937
+ *
938
+ * ```ts
939
+ * const params = { a: 1, b: undefined };
940
+ * stripUndefined(params); // { a: 1 }
941
+ * ```
942
+ */
943
+ declare function stripUndefined<T extends Record<string, unknown>>(obj: T): T;
944
+ //#endregion
945
+ //#region src/telemetry/event.d.ts
946
+ interface TrackingEvent {
947
+ command: string;
948
+ timestamp: string;
949
+ durationMs: number;
950
+ success: boolean;
951
+ errorMessage?: string;
952
+ httpStatus?: number;
953
+ requestId?: string;
954
+ cliVersion: string;
955
+ region: string;
956
+ nodeVersion: string;
957
+ os: string;
958
+ authMethod?: string;
959
+ params?: Record<string, unknown>;
960
+ }
961
+ declare function createTrackingEvent(opts: {
962
+ command: string;
963
+ durationMs: number;
964
+ success: boolean;
965
+ error?: {
966
+ message?: string;
967
+ httpStatus?: number;
968
+ requestId?: string;
969
+ };
970
+ cliVersion: string;
971
+ region: string;
972
+ authMethod?: string;
973
+ params?: Record<string, unknown>;
974
+ }): TrackingEvent;
975
+ //#endregion
976
+ //#region src/telemetry/sink.d.ts
977
+ /**
978
+ * 尽力等待所有在途的埋点发送完成(best-effort)。
979
+ *
980
+ * 1. 先调用 `_sendAll` 排空 tracker 内部的去抖队列,把还卡在 500ms 合并窗口里
981
+ * 的事件立刻推上网络。
982
+ * 2. 然后用硬超时 race 所有已追踪的 fetch promise。
983
+ *
984
+ * 埋点永远不应阻塞 CLI:调用方应传入较短的超时(例如 1000ms),并始终与超时
985
+ * race。错误与超时一律静默吞掉。
986
+ */
987
+ declare function flushTelemetry(timeoutMs?: number): Promise<void>;
988
+ declare function localSink(event: TrackingEvent): Promise<void>;
989
+ declare function remoteSink(event: TrackingEvent): Promise<void>;
990
+ //#endregion
991
+ //#region src/telemetry/tracker.d.ts
992
+ declare function trackCommandExecution(config: Config, commandPath: string[], flags: GlobalFlags, fn: () => Promise<void>): Promise<void>;
993
+ //#endregion
994
+ export { AkSignConfig, type ApiErrorBody, AppCompletionRequest, AppCompletionResponse, AppStreamChunk, AuthMethod, BAILIAN_HOST, BailianError, CHANNEL, CONSOLE_GATEWAY_NO_TOKEN_MESSAGE, ChatChoice, ChatMessage, ChatMessageContent, ChatRequest, ChatResponse, ChatTool, Command, CommandSpec, Config, ConfigFile, ConsoleGatewayRequest, DOCS_HOSTS, DashScopeASRRequest, DashScopeASRTaskResult, DashScopeAsyncResponse, DashScopeImageRequest, DashScopeImageSyncResponse, DashScopeTTSRequest, DashScopeTTSResponse, DashScopeTTSStreamChunk, DashScopeTaskResponse, DashScopeVideoEditRequest, DashScopeVideoRefRequest, DashScopeVideoRequest, ExitCode, GLOBAL_OPTIONS, GlobalFlags, KnowledgeRetrieveRequest, KnowledgeRetrieveResponse, McpClient, McpTool, McpToolResult, MemoryAddRequest, MemoryAddResponse, MemoryMessage, MemoryNode, MemoryNodeListResponse, MemoryNodeUpdateRequest, MemorySearchRequest, MemorySearchResponse, OptionDef, OutputFormat, ProfileAttribute, ProfileSchemaCreateRequest, ProfileSchemaCreateResponse, REGIONS, Region, RequestOpts, ResolvedCredential, SOURCE_CONFIG, ServerSentEvent, StreamChoice, StreamChunk, TAGS, TrackingEvent, UserProfileResponse, appCompletionEndpoint, bailianMcpUrl, callConsoleGateway, chatEndpoint, clearApiKey, createTrackingEvent, defineCommand, detectOutputFormat, ensureConfigDir, flushTelemetry, formatErrorJson, formatJson, formatOutput, formatText, generateFilename, generateToolSchema, getConfigDir, getConfigPath, getCredentialsPath, imageEndpoint, imageSyncEndpoint, isCI, isInteractive, isLocalFile, loadApiKeyFromConfig, loadConfig, localSink, mapApiError, maskToken, mcpWebSearchEndpoint, memoryAddEndpoint, memoryListEndpoint, memoryNodeEndpoint, memorySearchEndpoint, parseConfigFile, parseSSE, profileSchemaEndpoint, readConfigFile, remoteSink, request, requestJson, resolveConsoleGatewayCredential, resolveCredential, resolveFileUrl, resolveOutputDir, saveApiKeyToConfig, signRequest, speechRecognizeEndpoint, speechSynthesizeEndpoint, stripUndefined, taskEndpoint, trackCommandExecution, trackingHeaders, uploadFile, userProfileEndpoint, videoGenerateEndpoint, writeConfigFile };