bailian-cli-core 1.0.0-beta.0 → 1.0.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,83 @@
1
+ import { t as __commonJSMin } from "./chunk-e9Ob2GDo.mjs";
2
+ //#region ../../node_modules/.pnpm/@ali+aes-tracker-plugin-event@3.0.3/node_modules/@ali/aes-tracker-plugin-event/index-node.js
3
+ var require_index_node = /* @__PURE__ */ __commonJSMin(((exports, module) => {
4
+ module.exports = function(e) {
5
+ var t = {};
6
+ function n(r) {
7
+ if (t[r]) return t[r].exports;
8
+ var o = t[r] = {
9
+ i: r,
10
+ l: !1,
11
+ exports: {}
12
+ };
13
+ return e[r].call(o.exports, o, o.exports, n), o.l = !0, o.exports;
14
+ }
15
+ return n.m = e, n.c = t, n.d = function(e, t, r) {
16
+ n.o(e, t) || Object.defineProperty(e, t, {
17
+ enumerable: !0,
18
+ get: r
19
+ });
20
+ }, n.r = function(e) {
21
+ "undefined" != typeof Symbol && Symbol.toStringTag && Object.defineProperty(e, Symbol.toStringTag, { value: "Module" }), Object.defineProperty(e, "__esModule", { value: !0 });
22
+ }, n.t = function(e, t) {
23
+ if (1 & t && (e = n(e)), 8 & t) return e;
24
+ if (4 & t && "object" == typeof e && e && e.__esModule) return e;
25
+ var r = Object.create(null);
26
+ if (n.r(r), Object.defineProperty(r, "default", {
27
+ enumerable: !0,
28
+ value: e
29
+ }), 2 & t && "string" != typeof e) for (var o in e) n.d(r, o, function(t) {
30
+ return e[t];
31
+ }.bind(null, o));
32
+ return r;
33
+ }, n.n = function(e) {
34
+ var t = e && e.__esModule ? function() {
35
+ return e.default;
36
+ } : function() {
37
+ return e;
38
+ };
39
+ return n.d(t, "a", t), t;
40
+ }, n.o = function(e, t) {
41
+ return Object.prototype.hasOwnProperty.call(e, t);
42
+ }, n.p = "", n(n.s = 0);
43
+ }([function(e, t, n) {
44
+ "use strict";
45
+ n.r(t);
46
+ var r = [
47
+ "ec",
48
+ "ea",
49
+ "el",
50
+ "et"
51
+ ];
52
+ var o = function(e, t) {
53
+ var n = function(e) {
54
+ var n = e.ec, r = e.ea, o = e.el, l = e.et, u = void 0 === l ? "CLK" : l, a = e.xpath;
55
+ delete e.ec, delete e.ea, delete e.el, delete e.et, delete e.xpath, e.p1 = n, e.p2 = r, e.p3 = o, e.p4 = u, e.p5 = a;
56
+ try {
57
+ t.log("event", e);
58
+ } catch (e) {}
59
+ };
60
+ return function() {
61
+ var t = arguments, o = {};
62
+ if (0 !== t.length) {
63
+ for (var l = 0; l < t.length; l++) {
64
+ var u, a, i = t[l];
65
+ if (0 !== l && "object" == typeof i && l !== t.length - 1) return void (null == e || null === (u = e.console) || void 0 === u || null === (a = u.warn) || void 0 === a || a.call(u, "[AES tracker-plugin-event]", "Only the last argument can be object type"));
66
+ if ("string" == typeof i || "number" == typeof i) o[r[l]] = i;
67
+ else if ("object" == typeof i && l === t.length - 1) for (var c in i) i.hasOwnProperty(c) && (o[c] = i[c]);
68
+ }
69
+ n(o);
70
+ } else {
71
+ var f, p;
72
+ null === (f = e.console) || void 0 === f || null === (p = f.warn) || void 0 === p || p.call(f, "[AES tracker-plugin-event]", "At lease one augument");
73
+ }
74
+ };
75
+ };
76
+ t.default = function(e, t) {
77
+ return o(global, e);
78
+ };
79
+ }]).default;
80
+ }));
81
+ //#endregion
82
+ export default require_index_node();
83
+ export {};
package/dist/index.d.mts CHANGED
@@ -12,22 +12,29 @@ declare const ExitCode: {
12
12
  type ExitCode = (typeof ExitCode)[keyof typeof ExitCode];
13
13
  //#endregion
14
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
- */
15
+ interface ApiErrorContext {
16
+ httpStatus?: number;
17
+ apiCode?: string;
18
+ requestId?: string;
19
+ }
20
+ interface BailianErrorOptions {
21
+ cause?: unknown;
22
+ api?: ApiErrorContext;
23
+ }
22
24
  declare class BailianError extends Error {
23
25
  readonly exitCode: ExitCode;
24
26
  readonly hint?: string;
25
- constructor(message: string, exitCode?: ExitCode, hint?: string);
27
+ readonly api?: ApiErrorContext;
28
+ constructor(message: string, exitCode?: ExitCode, hint?: string, options?: BailianErrorOptions);
26
29
  toJSON(): {
27
30
  error: {
28
31
  code: ExitCode;
29
32
  message: string;
30
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;
31
38
  };
32
39
  };
33
40
  }
@@ -566,9 +573,11 @@ declare const BAILIAN_HOST = "https://bailian.cn-beijing.aliyuncs.com";
566
573
  type Region = keyof typeof REGIONS;
567
574
  interface ConfigFile {
568
575
  api_key?: string;
576
+ /** OAuth-style token from `bl auth login --console` callback; sent as `Authorization: Bearer …` */
577
+ access_token?: string;
569
578
  region?: Region;
570
579
  base_url?: string;
571
- output?: "text" | "json";
580
+ output?: "text" | "json" | "yaml";
572
581
  output_dir?: string;
573
582
  timeout?: number;
574
583
  default_text_model?: string;
@@ -579,18 +588,24 @@ interface ConfigFile {
579
588
  access_key_id?: string;
580
589
  access_key_secret?: string;
581
590
  workspace_id?: string;
591
+ console_gateway_url?: string;
592
+ telemetry?: boolean;
582
593
  }
583
594
  declare function parseConfigFile(raw: unknown): ConfigFile;
584
595
  interface Config {
585
596
  clientName?: string;
586
597
  clientVersion?: string;
587
598
  apiKey?: string;
599
+ /** `DASHSCOPE_ACCESS_TOKEN` env (explicit override). */
600
+ accessTokenEnv?: string;
601
+ /** `access_token` in config file (console login). */
602
+ fileAccessToken?: string;
588
603
  fileApiKey?: string;
589
604
  fileRegion?: Region;
590
605
  configPath?: string;
591
606
  region: Region;
592
607
  baseUrl: string;
593
- output: "text" | "json";
608
+ output: "text" | "json" | "yaml";
594
609
  outputDir?: string;
595
610
  timeout: number;
596
611
  defaultTextModel?: string;
@@ -601,6 +616,7 @@ interface Config {
601
616
  accessKeyId?: string;
602
617
  accessKeySecret?: string;
603
618
  workspaceId?: string;
619
+ consoleGatewayUrl: string;
604
620
  verbose: boolean;
605
621
  quiet: boolean;
606
622
  noColor: boolean;
@@ -608,10 +624,11 @@ interface Config {
608
624
  dryRun: boolean;
609
625
  nonInteractive: boolean;
610
626
  async: boolean;
627
+ telemetry: boolean;
611
628
  }
612
629
  //#endregion
613
630
  //#region src/auth/types.d.ts
614
- type AuthMethod = "api-key";
631
+ type AuthMethod = "api-key" | "access-token";
615
632
  interface ResolvedCredential {
616
633
  token: string;
617
634
  method: AuthMethod;
@@ -737,6 +754,24 @@ interface ServerSentEvent {
737
754
  }
738
755
  declare function parseSSE(response: Response): AsyncGenerator<ServerSentEvent>;
739
756
  //#endregion
757
+ //#region src/console/gateway.d.ts
758
+ interface ConsoleGatewayRequest {
759
+ /** Console API name, e.g. zeldaEasy.broadscope-bailian.freeTrial.queryFreeTierQuota */
760
+ api: string;
761
+ data: Record<string, unknown>;
762
+ /** Console region (default: cn-beijing), distinct from DashScope `config.region`. */
763
+ region?: string;
764
+ }
765
+ /**
766
+ * Invoke a Bailian **console** OpenAPI via the CLI gateway (`/cli/api.json`).
767
+ * Requires a console `access_token` (from `bl auth login --console`), not a DashScope API key.
768
+ */
769
+ declare function callConsoleGateway(config: Config, token: string, {
770
+ api,
771
+ data,
772
+ region
773
+ }: ConsoleGatewayRequest): Promise<unknown>;
774
+ //#endregion
740
775
  //#region src/types/flags.d.ts
741
776
  interface GlobalFlags {
742
777
  apiKey?: string;
@@ -766,7 +801,7 @@ declare function getCredentialsPath(): string;
766
801
  declare function ensureConfigDir(): Promise<void>;
767
802
  //#endregion
768
803
  //#region src/output/formatter.d.ts
769
- type OutputFormat = "text" | "json";
804
+ type OutputFormat = "text" | "json" | "yaml";
770
805
  declare function detectOutputFormat(flagValue?: string): OutputFormat;
771
806
  declare function formatOutput(data: unknown, format: OutputFormat): string;
772
807
  //#endregion
@@ -779,6 +814,9 @@ declare function formatText(data: unknown): string;
779
814
  declare function formatKeyValue(obj: Record<string, unknown>, indent?: number): string;
780
815
  declare function formatTable(rows: Record<string, unknown>[]): string;
781
816
  //#endregion
817
+ //#region src/output/yaml.d.ts
818
+ declare function formatYaml(data: unknown): string;
819
+ //#endregion
782
820
  //#region src/files/upload.d.ts
783
821
  interface UploadOptions {
784
822
  apiKey: string;
@@ -897,4 +935,40 @@ declare function isCI(): boolean;
897
935
  */
898
936
  declare function stripUndefined<T extends Record<string, unknown>>(obj: T): T;
899
937
  //#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 };
938
+ //#region src/telemetry/event.d.ts
939
+ interface TrackingEvent {
940
+ command: string;
941
+ timestamp: string;
942
+ durationMs: number;
943
+ success: boolean;
944
+ errorCode?: number;
945
+ errorMessage?: string;
946
+ cliVersion: string;
947
+ region: string;
948
+ nodeVersion: string;
949
+ os: string;
950
+ authMethod?: string;
951
+ params?: Record<string, unknown>;
952
+ }
953
+ declare function createTrackingEvent(opts: {
954
+ command: string;
955
+ durationMs: number;
956
+ success: boolean;
957
+ error?: {
958
+ code?: number;
959
+ message?: string;
960
+ };
961
+ cliVersion: string;
962
+ region: string;
963
+ authMethod?: string;
964
+ params?: Record<string, unknown>;
965
+ }): TrackingEvent;
966
+ //#endregion
967
+ //#region src/telemetry/sink.d.ts
968
+ declare function localSink(event: TrackingEvent): Promise<void>;
969
+ declare function remoteSink(event: TrackingEvent): Promise<void>;
970
+ //#endregion
971
+ //#region src/telemetry/tracker.d.ts
972
+ declare function trackCommandExecution(config: Config, commandPath: string[], flags: GlobalFlags, fn: () => Promise<void>): Promise<void>;
973
+ //#endregion
974
+ export { AkSignConfig, type ApiErrorBody, AppCompletionRequest, AppCompletionResponse, AppStreamChunk, AuthMethod, BAILIAN_HOST, BailianError, CHANNEL, 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, callConsoleGateway, chatEndpoint, clearApiKey, createTrackingEvent, defineCommand, detectOutputFormat, ensureConfigDir, formatErrorJson, formatJson, formatKeyValue, formatOutput, formatTable, formatText, formatYaml, 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, resolveCredential, resolveFileUrl, resolveOutputDir, saveApiKeyToConfig, signRequest, speechRecognizeEndpoint, speechSynthesizeEndpoint, stripUndefined, taskEndpoint, trackCommandExecution, trackingHeaders, uploadFile, userProfileEndpoint, videoGenerateEndpoint, writeConfigFile };