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