bailian-cli-core 1.0.0 → 1.0.2
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/README.md +14 -0
- package/dist/index.d.mts +27 -11
- package/dist/index.mjs +920 -70
- package/package.json +1 -11
- package/dist/chunk-e9Ob2GDo.mjs +0 -26
- package/dist/index-node-C01JPicH.mjs +0 -38910
- package/dist/index-node-Ce966wQ9.mjs +0 -83
package/dist/index.mjs
CHANGED
|
@@ -1,9 +1,33 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { createRequire } from "node:module";
|
|
2
2
|
import { appendFileSync, existsSync, mkdirSync, readFileSync, renameSync, statSync, unlinkSync, writeFileSync } from "fs";
|
|
3
3
|
import { homedir } from "os";
|
|
4
4
|
import { basename, join } from "path";
|
|
5
5
|
import { stringify } from "yaml";
|
|
6
6
|
import { createHash, createHmac, randomUUID } from "crypto";
|
|
7
|
+
//#region \0rolldown/runtime.js
|
|
8
|
+
var __create = Object.create;
|
|
9
|
+
var __defProp = Object.defineProperty;
|
|
10
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
11
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
12
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
13
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
14
|
+
var __commonJSMin = (cb, mod) => () => (mod || (cb((mod = { exports: {} }).exports, mod), cb = null), mod.exports);
|
|
15
|
+
var __copyProps = (to, from, except, desc) => {
|
|
16
|
+
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
17
|
+
key = keys[i];
|
|
18
|
+
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
19
|
+
get: ((k) => from[k]).bind(null, key),
|
|
20
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
return to;
|
|
24
|
+
};
|
|
25
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
26
|
+
value: mod,
|
|
27
|
+
enumerable: true
|
|
28
|
+
}) : target, mod));
|
|
29
|
+
var __require = /* @__PURE__ */ createRequire(import.meta.url);
|
|
30
|
+
//#endregion
|
|
7
31
|
//#region src/errors/codes.ts
|
|
8
32
|
const ExitCode = {
|
|
9
33
|
SUCCESS: 0,
|
|
@@ -134,42 +158,7 @@ async function ensureConfigDir() {
|
|
|
134
158
|
//#endregion
|
|
135
159
|
//#region src/output/text.ts
|
|
136
160
|
function formatText(data) {
|
|
137
|
-
|
|
138
|
-
if (typeof data === "string") return data;
|
|
139
|
-
if (typeof data === "number" || typeof data === "boolean") return String(data);
|
|
140
|
-
if (Array.isArray(data)) {
|
|
141
|
-
if (data.length === 0) return "(empty)";
|
|
142
|
-
if (typeof data[0] === "object" && data[0] !== null) return formatTable(data);
|
|
143
|
-
return data.map(String).join("\n");
|
|
144
|
-
}
|
|
145
|
-
if (typeof data === "object") return formatKeyValue(data);
|
|
146
|
-
return String(data);
|
|
147
|
-
}
|
|
148
|
-
function formatKeyValue(obj, indent = 0) {
|
|
149
|
-
const prefix = " ".repeat(indent);
|
|
150
|
-
const lines = [];
|
|
151
|
-
for (const [key, value] of Object.entries(obj)) {
|
|
152
|
-
if (value === null || value === void 0) continue;
|
|
153
|
-
if (Array.isArray(value)) {
|
|
154
|
-
lines.push(`${prefix}${key}:`);
|
|
155
|
-
for (const item of value) if (typeof item === "object" && item !== null) lines.push(`${prefix} - ${formatKeyValue(item, indent + 4).trimStart()}`);
|
|
156
|
-
else lines.push(`${prefix} - ${String(item)}`);
|
|
157
|
-
} else if (typeof value === "object") {
|
|
158
|
-
lines.push(`${prefix}${key}:`);
|
|
159
|
-
lines.push(formatKeyValue(value, indent + 2));
|
|
160
|
-
} else lines.push(`${prefix}${key}: ${String(value)}`);
|
|
161
|
-
}
|
|
162
|
-
return lines.join("\n");
|
|
163
|
-
}
|
|
164
|
-
function formatTable(rows) {
|
|
165
|
-
if (rows.length === 0) return "(empty)";
|
|
166
|
-
const keys = Object.keys(rows[0]);
|
|
167
|
-
const widths = keys.map((k) => Math.max(k.length, ...rows.map((r) => String(r[k] ?? "").length)));
|
|
168
|
-
return [
|
|
169
|
-
keys.map((k, i) => k.toUpperCase().padEnd(widths[i])).join(" "),
|
|
170
|
-
widths.map((w) => "-".repeat(w)).join(" "),
|
|
171
|
-
...rows.map((r) => keys.map((k, i) => String(r[k] ?? "").padEnd(widths[i])).join(" "))
|
|
172
|
-
].join("\n");
|
|
161
|
+
return stringify(data).replace(/\n$/, "");
|
|
173
162
|
}
|
|
174
163
|
//#endregion
|
|
175
164
|
//#region src/output/json.ts
|
|
@@ -184,21 +173,15 @@ function formatErrorJson(code, message, hint) {
|
|
|
184
173
|
} }, null, 2);
|
|
185
174
|
}
|
|
186
175
|
//#endregion
|
|
187
|
-
//#region src/output/yaml.ts
|
|
188
|
-
function formatYaml(data) {
|
|
189
|
-
return stringify(data).replace(/\n$/, "");
|
|
190
|
-
}
|
|
191
|
-
//#endregion
|
|
192
176
|
//#region src/output/formatter.ts
|
|
193
177
|
function detectOutputFormat(flagValue) {
|
|
194
|
-
if (flagValue === "json" || flagValue === "text"
|
|
178
|
+
if (flagValue === "json" || flagValue === "text") return flagValue;
|
|
195
179
|
if (!process.stdout.isTTY) return "json";
|
|
196
180
|
return "text";
|
|
197
181
|
}
|
|
198
182
|
function formatOutput(data, format) {
|
|
199
183
|
switch (format) {
|
|
200
184
|
case "json": return formatJson(data);
|
|
201
|
-
case "yaml": return formatYaml(data);
|
|
202
185
|
case "text": return formatText(data);
|
|
203
186
|
}
|
|
204
187
|
}
|
|
@@ -336,6 +319,26 @@ async function resolveCredential(config) {
|
|
|
336
319
|
};
|
|
337
320
|
throw new BailianError("No credentials found.", ExitCode.AUTH, "Set DASHSCOPE_API_KEY environment variable, pass --api-key, or configure a key.");
|
|
338
321
|
}
|
|
322
|
+
/**
|
|
323
|
+
* Credential for Bailian **console** CLI gateway only (`callConsoleGateway`).
|
|
324
|
+
* DashScope API keys are not valid Bearer tokens for this gateway — use env/file
|
|
325
|
+
* `access_token` even when `api_key` is also present in config.
|
|
326
|
+
*/
|
|
327
|
+
/** Thrown when `callConsoleGateway` has no usable console session token. */
|
|
328
|
+
const CONSOLE_GATEWAY_NO_TOKEN_MESSAGE = "No console access token found.";
|
|
329
|
+
async function resolveConsoleGatewayCredential(config) {
|
|
330
|
+
if (config.accessTokenEnv) return {
|
|
331
|
+
token: config.accessTokenEnv,
|
|
332
|
+
method: "access-token",
|
|
333
|
+
source: "DASHSCOPE_ACCESS_TOKEN"
|
|
334
|
+
};
|
|
335
|
+
if (config.fileAccessToken) return {
|
|
336
|
+
token: config.fileAccessToken,
|
|
337
|
+
method: "access-token",
|
|
338
|
+
source: "config.json"
|
|
339
|
+
};
|
|
340
|
+
throw new BailianError(CONSOLE_GATEWAY_NO_TOKEN_MESSAGE, ExitCode.AUTH, "Run `bl auth login --console` or set DASHSCOPE_ACCESS_TOKEN.");
|
|
341
|
+
}
|
|
339
342
|
//#endregion
|
|
340
343
|
//#region src/client/ak-sign.ts
|
|
341
344
|
/**
|
|
@@ -815,7 +818,7 @@ function defineCommand(spec) {
|
|
|
815
818
|
options: spec.options,
|
|
816
819
|
examples: spec.examples,
|
|
817
820
|
apiDocs: spec.apiDocs,
|
|
818
|
-
execute: spec.run
|
|
821
|
+
execute: (config, flags) => spec.run(config, flags)
|
|
819
822
|
};
|
|
820
823
|
}
|
|
821
824
|
/** Global flags shared by all commands — drives the parser's type resolution. */
|
|
@@ -834,7 +837,7 @@ const GLOBAL_OPTIONS = [
|
|
|
834
837
|
},
|
|
835
838
|
{
|
|
836
839
|
flag: "--output <format>",
|
|
837
|
-
description: "Output format: text, json
|
|
840
|
+
description: "Output format: text, json"
|
|
838
841
|
},
|
|
839
842
|
{
|
|
840
843
|
flag: "--timeout <seconds>",
|
|
@@ -1026,27 +1029,877 @@ function createTrackingEvent(opts) {
|
|
|
1026
1029
|
};
|
|
1027
1030
|
if (opts.authMethod) event.authMethod = opts.authMethod;
|
|
1028
1031
|
if (!opts.success && opts.error) {
|
|
1029
|
-
if (opts.error.code !== void 0) event.errorCode = opts.error.code;
|
|
1030
1032
|
if (opts.error.message) event.errorMessage = opts.error.message;
|
|
1033
|
+
if (opts.error.httpStatus !== void 0) event.httpStatus = opts.error.httpStatus;
|
|
1034
|
+
if (opts.error.requestId) event.requestId = opts.error.requestId;
|
|
1031
1035
|
}
|
|
1032
1036
|
if (opts.params && Object.keys(opts.params).length > 0) event.params = opts.params;
|
|
1033
1037
|
return event;
|
|
1034
1038
|
}
|
|
1039
|
+
const AEM_TEXT_MAX = 500;
|
|
1040
|
+
function aemText(value) {
|
|
1041
|
+
if (value === void 0 || value === null) return void 0;
|
|
1042
|
+
const s = typeof value === "string" ? value : JSON.stringify(value);
|
|
1043
|
+
return s.length <= AEM_TEXT_MAX ? s : s.slice(0, AEM_TEXT_MAX);
|
|
1044
|
+
}
|
|
1045
|
+
function buildRemoteAemOptions(event) {
|
|
1046
|
+
const { command: _command, params, ...extFields } = event;
|
|
1047
|
+
const opts = {
|
|
1048
|
+
et: "EXP",
|
|
1049
|
+
ext: extFields,
|
|
1050
|
+
c1: params,
|
|
1051
|
+
c2: event.success ? "success" : "failure"
|
|
1052
|
+
};
|
|
1053
|
+
if (event.httpStatus !== void 0) opts.c3 = String(event.httpStatus);
|
|
1054
|
+
if (event.errorMessage) opts.c4 = aemText(event.errorMessage);
|
|
1055
|
+
if (event.requestId) opts.c5 = event.requestId;
|
|
1056
|
+
return opts;
|
|
1057
|
+
}
|
|
1058
|
+
//#endregion
|
|
1059
|
+
//#region src/telemetry/env.ts
|
|
1060
|
+
/**
|
|
1061
|
+
* 判断当前运行环境。任一条件为真即视为 dev,默认 prod。
|
|
1062
|
+
*
|
|
1063
|
+
* 1. NODE_ENV=development — Node 圈通用约定,测试同学/CI 可显式声明
|
|
1064
|
+
* 2. 当前模块文件路径不在 node_modules 里 — 自动识别从源码运行(pnpm dev /
|
|
1065
|
+
* npm link / 直接 node packages/cli/src/main.ts),避免开发者忘记设环境变量
|
|
1066
|
+
* 时仍把数据打到 prod
|
|
1067
|
+
*
|
|
1068
|
+
* 缓存结果,模块加载期算一次就行。
|
|
1069
|
+
*/
|
|
1070
|
+
let cachedEnv;
|
|
1071
|
+
function detectEnv() {
|
|
1072
|
+
if (cachedEnv) return cachedEnv;
|
|
1073
|
+
if (process.env.NODE_ENV === "development") {
|
|
1074
|
+
cachedEnv = "dev";
|
|
1075
|
+
return cachedEnv;
|
|
1076
|
+
}
|
|
1077
|
+
cachedEnv = import.meta.url.includes("/node_modules/") ? "prod" : "dev";
|
|
1078
|
+
return cachedEnv;
|
|
1079
|
+
}
|
|
1080
|
+
//#endregion
|
|
1081
|
+
//#region lib/remote-telemetry/tracker.js
|
|
1082
|
+
var require_tracker = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
1083
|
+
module.exports = (function(e) {
|
|
1084
|
+
var t = {};
|
|
1085
|
+
function n(r) {
|
|
1086
|
+
if (t[r]) return t[r].exports;
|
|
1087
|
+
var o = t[r] = {
|
|
1088
|
+
i: r,
|
|
1089
|
+
l: !1,
|
|
1090
|
+
exports: {}
|
|
1091
|
+
};
|
|
1092
|
+
return e[r].call(o.exports, o, o.exports, n), o.l = !0, o.exports;
|
|
1093
|
+
}
|
|
1094
|
+
return n.m = e, n.c = t, n.d = function(e, t, r) {
|
|
1095
|
+
n.o(e, t) || Object.defineProperty(e, t, {
|
|
1096
|
+
enumerable: !0,
|
|
1097
|
+
get: r
|
|
1098
|
+
});
|
|
1099
|
+
}, n.r = function(e) {
|
|
1100
|
+
"undefined" != typeof Symbol && Symbol.toStringTag && Object.defineProperty(e, Symbol.toStringTag, { value: "Module" }), Object.defineProperty(e, "__esModule", { value: !0 });
|
|
1101
|
+
}, n.t = function(e, t) {
|
|
1102
|
+
if (1 & t && (e = n(e)), 8 & t) return e;
|
|
1103
|
+
if (4 & t && "object" == typeof e && e && e.__esModule) return e;
|
|
1104
|
+
var r = Object.create(null);
|
|
1105
|
+
if (n.r(r), Object.defineProperty(r, "default", {
|
|
1106
|
+
enumerable: !0,
|
|
1107
|
+
value: e
|
|
1108
|
+
}), 2 & t && "string" != typeof e) for (var o in e) n.d(r, o, function(t) {
|
|
1109
|
+
return e[t];
|
|
1110
|
+
}.bind(null, o));
|
|
1111
|
+
return r;
|
|
1112
|
+
}, n.n = function(e) {
|
|
1113
|
+
var t = e && e.__esModule ? function() {
|
|
1114
|
+
return e.default;
|
|
1115
|
+
} : function() {
|
|
1116
|
+
return e;
|
|
1117
|
+
};
|
|
1118
|
+
return n.d(t, "a", t), t;
|
|
1119
|
+
}, n.o = function(e, t) {
|
|
1120
|
+
return Object.prototype.hasOwnProperty.call(e, t);
|
|
1121
|
+
}, n.p = "", n(n.s = 8);
|
|
1122
|
+
})([
|
|
1123
|
+
function(e, t) {
|
|
1124
|
+
e.exports = __require("os");
|
|
1125
|
+
},
|
|
1126
|
+
function(e, t) {
|
|
1127
|
+
e.exports = globalThis.fetch;
|
|
1128
|
+
},
|
|
1129
|
+
function(e, t, n) {
|
|
1130
|
+
"use strict";
|
|
1131
|
+
e.exports = n(6);
|
|
1132
|
+
},
|
|
1133
|
+
function(e, t) {
|
|
1134
|
+
e.exports = __require("dns");
|
|
1135
|
+
},
|
|
1136
|
+
function(e, t) {
|
|
1137
|
+
e.exports = __require("util");
|
|
1138
|
+
},
|
|
1139
|
+
function(e, t) {
|
|
1140
|
+
e.exports = __require("crypto");
|
|
1141
|
+
},
|
|
1142
|
+
function(e, t, n) {
|
|
1143
|
+
Object.defineProperty(t, Symbol.toStringTag, { value: "Module" });
|
|
1144
|
+
const r = n(7), o = (e, t) => {
|
|
1145
|
+
t.appName = "BaiduSpider", t.appVersion = e.value, t.deviceBrand = "Baidu", t.deviceType = "bot", t.platform = "other";
|
|
1146
|
+
}, i = (e, t) => {
|
|
1147
|
+
t.appName = "360 Spider", t.appVersion = e.value, t.deviceBrand = "360", t.deviceType = "bot", t.platform = "other";
|
|
1148
|
+
}, a = (e, t) => {
|
|
1149
|
+
t.appName = "BingBot", t.appVersion = e.value, t.deviceBrand = "Microsoft", t.deviceType = "bot", t.platform = "other";
|
|
1150
|
+
}, u = (e, t) => {
|
|
1151
|
+
t.appName = "Googlebot", t.appVersion = e.value, t.deviceBrand = "Google", t.deviceType = "bot", t.platform = "other";
|
|
1152
|
+
}, p = (e, t) => {
|
|
1153
|
+
t.appName = "YandexBot", t.appVersion = e.value, t.deviceBrand = "Yandex", t.deviceType = "bot", t.platform = "other";
|
|
1154
|
+
}, l = (e, t) => {
|
|
1155
|
+
"Sogou web spider" === e.getPreviousNTokens(3) && (t.deviceBrand = "Sogou.com", t.appName = "SogouSpider"), t.appVersion = e.value, t.deviceType = "bot";
|
|
1156
|
+
}, s = (e, t) => {
|
|
1157
|
+
t.appName = "DataproviderBot", t.appVersion = e.value, t.deviceBrand = "Dataprovider.com", t.deviceType = "bot", t.platform = "other";
|
|
1158
|
+
}, c = (e, t) => {
|
|
1159
|
+
t.appName = "AhrefsBot", t.appVersion = e.value, t.deviceBrand = "Ahrefs", t.deviceType = "bot", t.platform = "other";
|
|
1160
|
+
}, d = (e, t) => {
|
|
1161
|
+
t.appName = "BitSightBot", t.appVersion = e.value, t.deviceBrand = "Bitsight", t.deviceType = "bot", t.platform = "other";
|
|
1162
|
+
}, f = (e, t) => {
|
|
1163
|
+
t.appName = "oBot", t.appVersion = e.value, t.deviceBrand = "IBM", t.deviceType = "bot", t.platform = "other";
|
|
1164
|
+
}, v = (e, t) => {
|
|
1165
|
+
t.appName = "Cincraw", t.appVersion = e.value, t.deviceBrand = "CINC", t.deviceType = "bot", t.platform = "other";
|
|
1166
|
+
}, g = (e, t) => {
|
|
1167
|
+
t.appName = "DingTalkBot", t.appVersion = e.value, t.deviceBrand = "Alibaba", t.deviceType = "bot", t.platform = "other";
|
|
1168
|
+
}, h = (e, t) => {
|
|
1169
|
+
t.appName = "YisouSpider", t.appVersion = e.value, t.deviceBrand = "Alibaba", t.deviceType = "bot", t.platform = "other";
|
|
1170
|
+
}, m = (e, t) => {
|
|
1171
|
+
t.appName = "ByteSpider", t.appVersion = e.value, t.deviceBrand = "ByteDance", t.deviceType = "bot", t.platform = "other";
|
|
1172
|
+
}, b = (e, t) => {
|
|
1173
|
+
t.appName = "HeadlineCrawler", t.appVersion = e.value, t.deviceBrand = "Headline.com", t.deviceType = "bot", t.platform = "other";
|
|
1174
|
+
}, y = (e, t) => {
|
|
1175
|
+
t.appName = "BitDiscoveryBot", t.appVersion = e.value, t.deviceBrand = "Tenable", t.deviceType = "bot", t.platform = "other";
|
|
1176
|
+
}, _ = (e, t) => {
|
|
1177
|
+
"Screaming Frog SEO Spider" === e.getPreviousNTokens(4) && (t.deviceBrand = "Screaming Frog", t.appName = "Screaming Frog"), t.appVersion = e.value, t.deviceType = "bot";
|
|
1178
|
+
}, B = (e, t) => {
|
|
1179
|
+
t.appName = "Ai2Bot", t.appVersion = e.value, t.deviceBrand = "Ai2", t.deviceType = "bot", t.platform = "other";
|
|
1180
|
+
}, S = (e, t) => {
|
|
1181
|
+
t.appName = "DianjingAdSpider", t.appVersion = e.value, t.deviceBrand = "Dianjing", t.deviceType = "bot", t.platform = "other";
|
|
1182
|
+
}, T = (e, t) => {
|
|
1183
|
+
t.appName = "BaiduSpider", t.appVersion = e.value, t.deviceBrand = "Baidu", t.deviceType = "bot", t.platform = "other";
|
|
1184
|
+
}, j = (e, t) => {
|
|
1185
|
+
t.appName = "360 Spider", t.appVersion = e.value, t.deviceBrand = "360", t.deviceType = "bot", t.platform = "other";
|
|
1186
|
+
}, N = (e, t) => {
|
|
1187
|
+
t.appName = "BingBot", t.appVersion = e.value, t.deviceBrand = "Microsoft", t.deviceType = "bot", t.platform = "other";
|
|
1188
|
+
}, w = (e, t) => {
|
|
1189
|
+
t.appName = "Googlebot", t.appVersion = e.value, t.deviceBrand = "Google", t.deviceType = "bot", t.platform = "other";
|
|
1190
|
+
}, O = (e, t) => {
|
|
1191
|
+
t.appName = "YandexBot", t.appVersion = e.value, t.deviceBrand = "Yandex", t.deviceType = "bot", t.platform = "other";
|
|
1192
|
+
}, V = (e, t) => {
|
|
1193
|
+
"Sogou web spider" === e.getPreviousNTokens(3) && (t.deviceBrand = "Sogou.com", t.appName = "SogouSpider"), t.appVersion = e.value, t.deviceType = "bot";
|
|
1194
|
+
}, A = (e, t) => {
|
|
1195
|
+
t.appName = "DataproviderBot", t.appVersion = e.value, t.deviceBrand = "Dataprovider.com", t.deviceType = "bot", t.platform = "other";
|
|
1196
|
+
}, D = (e, t) => {
|
|
1197
|
+
t.appName = "AhrefsBot", t.appVersion = e.value, t.deviceBrand = "Ahrefs", t.deviceType = "bot", t.platform = "other";
|
|
1198
|
+
}, k = (e, t) => {
|
|
1199
|
+
t.appName = "BitSightBot", t.appVersion = e.value, t.deviceBrand = "Bitsight", t.deviceType = "bot", t.platform = "other";
|
|
1200
|
+
}, P = (e, t) => {
|
|
1201
|
+
t.appName = "oBot", t.appVersion = e.value, t.deviceBrand = "IBM", t.deviceType = "bot", t.platform = "other";
|
|
1202
|
+
}, C = (e, t) => {
|
|
1203
|
+
t.appName = "Cincraw", t.appVersion = e.value, t.deviceBrand = "CINC", t.deviceType = "bot", t.platform = "other";
|
|
1204
|
+
}, E = (e, t) => {
|
|
1205
|
+
t.appName = "DingTalkBot", t.appVersion = e.value, t.deviceBrand = "Alibaba", t.deviceType = "bot", t.platform = "other";
|
|
1206
|
+
}, x = (e, t) => {
|
|
1207
|
+
t.appName = "YisouSpider", t.appVersion = e.value, t.deviceBrand = "Alibaba", t.deviceType = "bot", t.platform = "other";
|
|
1208
|
+
}, M = (e, t) => {
|
|
1209
|
+
t.appName = "ByteSpider", t.appVersion = e.value, t.deviceBrand = "ByteDance", t.deviceType = "bot", t.platform = "other";
|
|
1210
|
+
}, q = (e, t) => {
|
|
1211
|
+
t.appName = "HeadlineCrawler", t.appVersion = e.value, t.deviceBrand = "Headline.com", t.deviceType = "bot", t.platform = "other";
|
|
1212
|
+
}, I = (e, t) => {
|
|
1213
|
+
t.appName = "BitDiscoveryBot", t.appVersion = e.value, t.deviceBrand = "Tenable", t.deviceType = "bot", t.platform = "other";
|
|
1214
|
+
}, H = (e, t) => {
|
|
1215
|
+
"Screaming Frog SEO Spider" === e.getPreviousNTokens(4) && (t.deviceBrand = "Screaming Frog", t.appName = "Screaming Frog"), t.appVersion = e.value, t.deviceType = "bot";
|
|
1216
|
+
}, U = (e, t) => {
|
|
1217
|
+
t.appName = "Ai2Bot", t.appVersion = e.value, t.deviceBrand = "Ai2", t.deviceType = "bot", t.platform = "other";
|
|
1218
|
+
}, L = (e, t) => {
|
|
1219
|
+
t.appName = "DianjingAdSpider", t.appVersion = e.value, t.deviceBrand = "Dianjing", t.deviceType = "bot", t.platform = "other";
|
|
1220
|
+
}, Q = /* @__PURE__ */ new Map(), R = /* @__PURE__ */ new Map();
|
|
1221
|
+
Q.set("Baiduspider-render", o), Q.set("Baiduspider+", o), Q.set("Baiduspider-image+", o), Q.set("360Spider", i), Q.set("360Spider-Image", i), Q.set("bingbot", a), Q.set("Googlebot", u), Q.set("YandexRenderResourcesBot", p), Q.set("spider", l), Q.set("Dataprovider.com", s), Q.set("AhrefsBot", c), Q.set("BitSightBot", d), Q.set("oBot", f), Q.set("Cincraw", v), Q.set("DingTalkBot-LinkService", g), Q.set("YisouSpider", h), Q.set("Bytespider", m), Q.set("ev-crawler", b), Q.set("bitdiscovery", y), Q.set("Spider", _), Q.set("Ai2Bot-Dolma", B), Q.set("dianjing_ad_spider", S), R.set("Baiduspider-render", T), R.set("Baiduspider+", T), R.set("Baiduspider-image+", T), R.set("360Spider", j), R.set("360Spider-Image", j), R.set("bingbot", N), R.set("Googlebot", w), R.set("YandexRenderResourcesBot", O), R.set("spider", V), R.set("Dataprovider.com", A), R.set("AhrefsBot", D), R.set("BitSightBot", k), R.set("oBot", P), R.set("Cincraw", C), R.set("DingTalkBot-LinkService", E), R.set("YisouSpider", x), R.set("Bytespider", M), R.set("ev-crawler", q), R.set("bitdiscovery", I), R.set("Spider", H), R.set("Ai2Bot-Dolma", U), R.set("dianjing_ad_spider", L);
|
|
1222
|
+
const F = {
|
|
1223
|
+
productHandlerMap: Q,
|
|
1224
|
+
commentHandlerMap: R,
|
|
1225
|
+
getSpecialProductHandler: () => null,
|
|
1226
|
+
getSpecialCommentHandler: () => null,
|
|
1227
|
+
getDefaultModelHandler: () => null
|
|
1228
|
+
};
|
|
1229
|
+
t.isBot = function(e) {
|
|
1230
|
+
const t = r.createUAInfo();
|
|
1231
|
+
return r.runTask(e, t, F), "bot" === t.deviceType;
|
|
1232
|
+
};
|
|
1233
|
+
},
|
|
1234
|
+
function(e, t) {
|
|
1235
|
+
function n(e) {
|
|
1236
|
+
const t = [], n = {
|
|
1237
|
+
parent: e,
|
|
1238
|
+
tokens: t,
|
|
1239
|
+
get firstToken() {
|
|
1240
|
+
return 0 === t.length ? null : t[0];
|
|
1241
|
+
},
|
|
1242
|
+
getNewToken(r) {
|
|
1243
|
+
const o = (function() {
|
|
1244
|
+
const e = [], t = [], n = [];
|
|
1245
|
+
let r = null, o = null, i = null, a = !0, u = !0, p = !0, l = null;
|
|
1246
|
+
const s = {
|
|
1247
|
+
get key() {
|
|
1248
|
+
return a && (r = e.join(""), a = !1), r;
|
|
1249
|
+
},
|
|
1250
|
+
get value() {
|
|
1251
|
+
return u && (o = t.join(""), u = !1), o;
|
|
1252
|
+
},
|
|
1253
|
+
get originValue() {
|
|
1254
|
+
return p && (i = n.join(""), p = !1), i;
|
|
1255
|
+
},
|
|
1256
|
+
previousToken: null,
|
|
1257
|
+
properties: null,
|
|
1258
|
+
appendKey(t) {
|
|
1259
|
+
e.push(t), a = !0;
|
|
1260
|
+
},
|
|
1261
|
+
appendValue(e) {
|
|
1262
|
+
t.push("_" === e ? "." : e), n.push(e), u = !0, p = !0, l = null;
|
|
1263
|
+
},
|
|
1264
|
+
getSplitValue(e) {
|
|
1265
|
+
if (null === l) {
|
|
1266
|
+
const e = s.value;
|
|
1267
|
+
l = "" === e ? [] : e.split("/");
|
|
1268
|
+
}
|
|
1269
|
+
return e >= 0 && e < l.length ? l[e] : null;
|
|
1270
|
+
},
|
|
1271
|
+
getPreviousNTokens(e) {
|
|
1272
|
+
const t = [];
|
|
1273
|
+
let n = s;
|
|
1274
|
+
for (let r = 0; r < e; r++) {
|
|
1275
|
+
if (null == n) return null;
|
|
1276
|
+
t.unshift(n.key), n = n.previousToken;
|
|
1277
|
+
}
|
|
1278
|
+
return t.join(" ");
|
|
1279
|
+
}
|
|
1280
|
+
};
|
|
1281
|
+
return s;
|
|
1282
|
+
})();
|
|
1283
|
+
return t.push(o), o.previousToken = void 0 !== r ? r : t.length > 1 ? t[t.length - 2] : null, e && (e.properties = n), o;
|
|
1284
|
+
},
|
|
1285
|
+
getLastToken: () => 0 === t.length ? null : t[t.length - 1],
|
|
1286
|
+
getFirstToken: () => 0 === t.length ? null : t[0],
|
|
1287
|
+
isEmpty: () => 0 === t.length
|
|
1288
|
+
};
|
|
1289
|
+
return n;
|
|
1290
|
+
}
|
|
1291
|
+
function r() {
|
|
1292
|
+
return {
|
|
1293
|
+
appName: null,
|
|
1294
|
+
appVersion: null,
|
|
1295
|
+
browserName: null,
|
|
1296
|
+
browserVersion: null,
|
|
1297
|
+
engineName: null,
|
|
1298
|
+
engineVersion: null,
|
|
1299
|
+
deviceBrand: null,
|
|
1300
|
+
deviceModel: null,
|
|
1301
|
+
deviceType: "mobile",
|
|
1302
|
+
osName: null,
|
|
1303
|
+
osVersion: null,
|
|
1304
|
+
platform: "web",
|
|
1305
|
+
tokenGroup: n(null)
|
|
1306
|
+
};
|
|
1307
|
+
}
|
|
1308
|
+
const o = new Set(" ;,\"'".split("")), i = new Set("/=:".split("")), a = new Set([
|
|
1309
|
+
"Mozilla",
|
|
1310
|
+
"AppleWebKit",
|
|
1311
|
+
"Safari",
|
|
1312
|
+
"Opera",
|
|
1313
|
+
"Dalvik",
|
|
1314
|
+
"com.ss.android.ugc.aweme"
|
|
1315
|
+
]);
|
|
1316
|
+
function u(e) {
|
|
1317
|
+
return 1 === e.length && o.has(e);
|
|
1318
|
+
}
|
|
1319
|
+
function p(e) {
|
|
1320
|
+
return 1 === e.length && i.has(e);
|
|
1321
|
+
}
|
|
1322
|
+
function l(e, t, n, r) {
|
|
1323
|
+
if (null == e) return;
|
|
1324
|
+
const o = t.parent, i = e.key;
|
|
1325
|
+
let u = null;
|
|
1326
|
+
if (null != o) {
|
|
1327
|
+
const e = o.key;
|
|
1328
|
+
var p, l;
|
|
1329
|
+
if (a.has(e)) u = null !== (p = r.commentHandlerMap.get(i)) && void 0 !== p ? p : null, u ??= r.getSpecialCommentHandler(i), null == u && i.endsWith(" Build") && (u = r.getDefaultModelHandler());
|
|
1330
|
+
else u = null !== (l = r.productHandlerMap.get(i)) && void 0 !== l ? l : r.getSpecialProductHandler(i);
|
|
1331
|
+
} else {
|
|
1332
|
+
var s;
|
|
1333
|
+
u = null !== (s = r.productHandlerMap.get(i)) && void 0 !== s ? s : r.getSpecialProductHandler(i);
|
|
1334
|
+
}
|
|
1335
|
+
if (null != u) try {
|
|
1336
|
+
u(e, n);
|
|
1337
|
+
} catch (e) {}
|
|
1338
|
+
}
|
|
1339
|
+
function s(e, t, r) {
|
|
1340
|
+
if (null == e) throw new Error("input can not be null");
|
|
1341
|
+
return (function e(t, r, o, i, a) {
|
|
1342
|
+
let s, c = null, d = null, f = !1;
|
|
1343
|
+
const v = t.length;
|
|
1344
|
+
let g = r > 0 ? t[r - 1] : "\0";
|
|
1345
|
+
for (s = r; s < v; s++) {
|
|
1346
|
+
const h = t[s];
|
|
1347
|
+
if (u(h)) {
|
|
1348
|
+
const e = "\0" !== g && u(g);
|
|
1349
|
+
if (!f && r > 0 && " " === h && !e) {
|
|
1350
|
+
const e = s + 1;
|
|
1351
|
+
if (e < v) {
|
|
1352
|
+
const n = t[e];
|
|
1353
|
+
/\d/.test(n) || "-" === n ? f = !0 : d?.appendKey(h);
|
|
1354
|
+
} else d?.appendKey(h);
|
|
1355
|
+
} else null != d && (c = d, d = null);
|
|
1356
|
+
g = h;
|
|
1357
|
+
} else if ("(" === h) {
|
|
1358
|
+
if ("(" === g) {
|
|
1359
|
+
g = h;
|
|
1360
|
+
continue;
|
|
1361
|
+
}
|
|
1362
|
+
const r = s;
|
|
1363
|
+
s = e(t, s + 1, n(o.getLastToken()), i, a), null != d && (c = d, d = null), g = t[r];
|
|
1364
|
+
} else {
|
|
1365
|
+
if (")" === h) {
|
|
1366
|
+
if (0 === r) {
|
|
1367
|
+
g = h;
|
|
1368
|
+
continue;
|
|
1369
|
+
}
|
|
1370
|
+
break;
|
|
1371
|
+
}
|
|
1372
|
+
d ?? (l(o.getLastToken(), o, i, a), d = o.getNewToken(c), f = !1), p(h) ? (f && d.appendValue(h), f = !0) : f ? d.appendValue(h) : d.appendKey(h), g = h;
|
|
1373
|
+
}
|
|
1374
|
+
}
|
|
1375
|
+
return l(o.getLastToken(), o, i, a), s;
|
|
1376
|
+
})(e, 0, t.tokenGroup, t, r), t;
|
|
1377
|
+
}
|
|
1378
|
+
Object.defineProperty(t, "DEFAULT_MODEL_HANDLER_KEY", {
|
|
1379
|
+
enumerable: !0,
|
|
1380
|
+
get: function() {
|
|
1381
|
+
return "DEFAULT_MODEL_HANDLER";
|
|
1382
|
+
}
|
|
1383
|
+
}), Object.defineProperty(t, "createUAInfo", {
|
|
1384
|
+
enumerable: !0,
|
|
1385
|
+
get: function() {
|
|
1386
|
+
return r;
|
|
1387
|
+
}
|
|
1388
|
+
}), Object.defineProperty(t, "runTask", {
|
|
1389
|
+
enumerable: !0,
|
|
1390
|
+
get: function() {
|
|
1391
|
+
return s;
|
|
1392
|
+
}
|
|
1393
|
+
});
|
|
1394
|
+
},
|
|
1395
|
+
function(e, t, n) {
|
|
1396
|
+
"use strict";
|
|
1397
|
+
n.r(t);
|
|
1398
|
+
var r = n(0), o = n.n(r), i = n(1), a = n.n(i);
|
|
1399
|
+
n(2);
|
|
1400
|
+
function u() {
|
|
1401
|
+
var e = arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : 20, t = arguments.length > 1 ? arguments[1] : void 0;
|
|
1402
|
+
return t = t || "", e ? u(--e, "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz".charAt(Math.floor(60 * Math.random())) + t) : t;
|
|
1403
|
+
}
|
|
1404
|
+
function p(e, t) {
|
|
1405
|
+
for (var n in t) e[n] = t[n];
|
|
1406
|
+
return e;
|
|
1407
|
+
}
|
|
1408
|
+
function l(e) {
|
|
1409
|
+
return "[object Object]" === Object.prototype.toString.call(e);
|
|
1410
|
+
}
|
|
1411
|
+
function s(e) {
|
|
1412
|
+
return "undefined" != typeof Promise && e instanceof Promise;
|
|
1413
|
+
}
|
|
1414
|
+
var c = Object.freeze({ __aesBeforeSkip: 1 }), d = function(e) {
|
|
1415
|
+
var t = Object.prototype.toString.call(e);
|
|
1416
|
+
if ("[object String]" === t && e || "[object Number]" === t || "[object Boolean]" === t) return e;
|
|
1417
|
+
if ("[object Object]" === t || "[object Array]" === t) try {
|
|
1418
|
+
return JSON.stringify(e);
|
|
1419
|
+
} catch (e) {}
|
|
1420
|
+
}, f = function(e) {
|
|
1421
|
+
var t = {};
|
|
1422
|
+
for (var n in e) {
|
|
1423
|
+
var r = e[n];
|
|
1424
|
+
void 0 !== r && (t[n] = d(r));
|
|
1425
|
+
}
|
|
1426
|
+
return t;
|
|
1427
|
+
}, v = function(e) {
|
|
1428
|
+
var t = [];
|
|
1429
|
+
for (var n in e) {
|
|
1430
|
+
var r = d(e[n]);
|
|
1431
|
+
void 0 !== r && t.push("".concat(n, "=").concat(encodeURIComponent(r)));
|
|
1432
|
+
}
|
|
1433
|
+
return t.join("&");
|
|
1434
|
+
};
|
|
1435
|
+
function g(e) {
|
|
1436
|
+
return (e.requiredFields || []).concat(["pid"]).some(function(t) {
|
|
1437
|
+
return void 0 === e[t];
|
|
1438
|
+
});
|
|
1439
|
+
}
|
|
1440
|
+
function h() {
|
|
1441
|
+
var e = arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : "", t = arguments.length > 1 ? arguments[1] : void 0;
|
|
1442
|
+
"undefined" != typeof console && console.warn("日志解析报错,埋点将被丢弃 => ".concat(e), t);
|
|
1443
|
+
}
|
|
1444
|
+
var m = "AEM_TRACKER_UNIQUE_PVID", b = "undefined" != typeof globalThis && globalThis ? globalThis : "undefined" != typeof window && window ? window : "undefined" != typeof global && global ? global : "undefined" != typeof self && self ? self : (console.error("Unable to locate global object in current environment"), {});
|
|
1445
|
+
function y(e) {
|
|
1446
|
+
this._queue = [], this._reqQueue = [], this._plugins = {}, this._subscribers = { onConfigUpdated: [] }, this._timeout = 0, this._config = {
|
|
1447
|
+
sdk_version: "3.3.18",
|
|
1448
|
+
set pv_id(e) {
|
|
1449
|
+
b[m] = e;
|
|
1450
|
+
},
|
|
1451
|
+
get pv_id() {
|
|
1452
|
+
return b[m] || (b[m] = u()), b[m];
|
|
1453
|
+
},
|
|
1454
|
+
timezone_offset: (/* @__PURE__ */ new Date()).getTimezoneOffset()
|
|
1455
|
+
}, e && (this._config = p(this._config, e));
|
|
1456
|
+
}
|
|
1457
|
+
y.prototype = {
|
|
1458
|
+
constructor: y,
|
|
1459
|
+
_sendAll: function() {
|
|
1460
|
+
if (this._timeout && (clearTimeout(this._timeout), this._timeout = 0), this._queue.length) {
|
|
1461
|
+
var e, t = this._config.maxUrlLength || 3e4, n = this._getSendConfig();
|
|
1462
|
+
try {
|
|
1463
|
+
e = this._processData(this._queue, n);
|
|
1464
|
+
} catch (e) {}
|
|
1465
|
+
if (e && e.length < t) return this._queue = [], void this.send(e);
|
|
1466
|
+
for (var r, o = []; this._queue.length;) {
|
|
1467
|
+
o.push(this._queue.shift());
|
|
1468
|
+
try {
|
|
1469
|
+
r = this._processData(o, n);
|
|
1470
|
+
} catch (e) {
|
|
1471
|
+
var i = o.pop();
|
|
1472
|
+
h(e.message, i);
|
|
1473
|
+
continue;
|
|
1474
|
+
}
|
|
1475
|
+
if (r.length > t) {
|
|
1476
|
+
o.length > 1 && (this._queue.unshift(o.pop()), r = this._processData(o, n));
|
|
1477
|
+
break;
|
|
1478
|
+
}
|
|
1479
|
+
}
|
|
1480
|
+
r && this.send(r), this._queue.length && this._sendAll();
|
|
1481
|
+
}
|
|
1482
|
+
},
|
|
1483
|
+
_send: function(e, t) {
|
|
1484
|
+
var n = this;
|
|
1485
|
+
if (!1 === t) {
|
|
1486
|
+
var r;
|
|
1487
|
+
try {
|
|
1488
|
+
r = this._processData([e]);
|
|
1489
|
+
} catch (t) {
|
|
1490
|
+
h(t.message, e);
|
|
1491
|
+
}
|
|
1492
|
+
r && this.send(r);
|
|
1493
|
+
} else {
|
|
1494
|
+
this._queue.push(e);
|
|
1495
|
+
var o = this._config.mergeRequestInterval || 500;
|
|
1496
|
+
this._timeout || (this._timeout = setTimeout(function() {
|
|
1497
|
+
n._sendAll();
|
|
1498
|
+
}, o));
|
|
1499
|
+
}
|
|
1500
|
+
},
|
|
1501
|
+
_getSendConfig: function() {
|
|
1502
|
+
var e = {}, t = this._config;
|
|
1503
|
+
for (var n in t) "requiredFields" !== n && "maxUrlLength" !== n && "queueGlobalName" !== n && "debug" !== n && "excludeCrawlers" !== n && "collectClientHints" !== n && 0 !== n.indexOf("plugin") && "" !== t[n] && null !== t[n] && void 0 !== t[n] && (e[n] = d(t[n]));
|
|
1504
|
+
return e;
|
|
1505
|
+
},
|
|
1506
|
+
_processData: function(e, t) {
|
|
1507
|
+
t = t || this._getSendConfig();
|
|
1508
|
+
var n = v(t);
|
|
1509
|
+
return n += "&msg=" + encodeURIComponent(e.map(function(e) {
|
|
1510
|
+
return v(e);
|
|
1511
|
+
}).join("|"));
|
|
1512
|
+
},
|
|
1513
|
+
setConfig: function(e, t) {
|
|
1514
|
+
var n = this, r = {};
|
|
1515
|
+
void 0 !== t ? r[e] = t : r = e;
|
|
1516
|
+
var o = !(function e(t, n) {
|
|
1517
|
+
if (void 0 === t || void 0 === n) return !1;
|
|
1518
|
+
if (!l(t) || !l(n)) return !1;
|
|
1519
|
+
for (var r in t) if (l(t[r])) {
|
|
1520
|
+
if (!e(t[r], n[r])) return !1;
|
|
1521
|
+
} else if (t[r] !== n[r]) return !1;
|
|
1522
|
+
return !0;
|
|
1523
|
+
})(r, this._config), i = function() {
|
|
1524
|
+
if (o) {
|
|
1525
|
+
for (var e in r) l(r[e]) ? n._config[e] = p(n._config[e] || {}, r[e]) : n._config[e] = r[e];
|
|
1526
|
+
n._execSubscribe("onConfigUpdated", [r, n._config]);
|
|
1527
|
+
}
|
|
1528
|
+
};
|
|
1529
|
+
this._reqQueue.length ? (i(), g(this._config) || (this._reqQueue.forEach(function(e) {
|
|
1530
|
+
n._send.apply(n, e);
|
|
1531
|
+
}), this._reqQueue = [])) : (o && this._sendAll(), i());
|
|
1532
|
+
},
|
|
1533
|
+
getConfig: function(e) {
|
|
1534
|
+
return e ? this._config[e] : this._config;
|
|
1535
|
+
},
|
|
1536
|
+
updatePVID: (function(e, t) {
|
|
1537
|
+
if ("function" != typeof e) throw new TypeError("Expected a function");
|
|
1538
|
+
t = "number" == typeof t && t >= 0 ? t : 100;
|
|
1539
|
+
var n = null;
|
|
1540
|
+
return function() {
|
|
1541
|
+
if (null === n) {
|
|
1542
|
+
var r = this, o = Array.prototype.slice.call(arguments);
|
|
1543
|
+
n = setTimeout(function() {
|
|
1544
|
+
n = null;
|
|
1545
|
+
}, t), e.apply(r, o);
|
|
1546
|
+
}
|
|
1547
|
+
};
|
|
1548
|
+
})(function() {
|
|
1549
|
+
b[m] = u();
|
|
1550
|
+
}, 200),
|
|
1551
|
+
log: function(e) {
|
|
1552
|
+
var t = arguments.length > 1 && void 0 !== arguments[1] ? arguments[1] : {}, n = arguments.length > 2 && void 0 !== arguments[2] ? arguments[2] : {};
|
|
1553
|
+
e && (t.ts = t.ts || (/* @__PURE__ */ new Date()).getTime(), t.type = e, this._print("log", e, t), t = f(t), g(this._config) ? this._reqQueue.length < 1e3 && this._reqQueue.push([t, n.combo]) : this._send(t, n.combo));
|
|
1554
|
+
},
|
|
1555
|
+
before: function(e, t) {
|
|
1556
|
+
var n = this;
|
|
1557
|
+
return function() {
|
|
1558
|
+
var r = arguments, o = t.apply(n, r);
|
|
1559
|
+
o !== c && (s(o) ? o.then(function(t) {
|
|
1560
|
+
t !== c && e.apply(n, t || r);
|
|
1561
|
+
}) : e.apply(n, o || r));
|
|
1562
|
+
};
|
|
1563
|
+
},
|
|
1564
|
+
after: function(e, t) {
|
|
1565
|
+
var n = this;
|
|
1566
|
+
return function() {
|
|
1567
|
+
var r = arguments;
|
|
1568
|
+
e.apply(n, r), t.apply(n, r);
|
|
1569
|
+
};
|
|
1570
|
+
},
|
|
1571
|
+
use: function(e, t) {
|
|
1572
|
+
var n = this;
|
|
1573
|
+
return "[object Array]" === Object.prototype.toString.call(e) ? e.map(function(e) {
|
|
1574
|
+
if ("[object Array]" === Object.prototype.toString.call(e)) {
|
|
1575
|
+
var t = e[0], r = e[1];
|
|
1576
|
+
return n._plugins[t] || (n._plugins[t] = new t(n, r));
|
|
1577
|
+
}
|
|
1578
|
+
return n._plugins[e] || (n._plugins[e] = new e(n));
|
|
1579
|
+
}) : this._plugins[e] || (this._plugins[e] = new e(this, t));
|
|
1580
|
+
},
|
|
1581
|
+
_print: function() {
|
|
1582
|
+
this._config.debug && "undefined" != typeof console && console.log.apply(console, arguments);
|
|
1583
|
+
},
|
|
1584
|
+
onConfigUpdated: function(e) {
|
|
1585
|
+
this._subscribers.onConfigUpdated && this._subscribers.onConfigUpdated.push(e);
|
|
1586
|
+
},
|
|
1587
|
+
_execSubscribe: function(e, t) {
|
|
1588
|
+
this._subscribers[e] && this._subscribers[e].forEach(function(e) {
|
|
1589
|
+
e.apply(this, t);
|
|
1590
|
+
});
|
|
1591
|
+
}
|
|
1592
|
+
};
|
|
1593
|
+
var _ = y, B = n(3), S = n.n(B), T = n(4), j = n(5), N = n.n(j);
|
|
1594
|
+
function w(e) {
|
|
1595
|
+
return (w = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(e) {
|
|
1596
|
+
return typeof e;
|
|
1597
|
+
} : function(e) {
|
|
1598
|
+
return e && "function" == typeof Symbol && e.constructor === Symbol && e !== Symbol.prototype ? "symbol" : typeof e;
|
|
1599
|
+
})(e);
|
|
1600
|
+
}
|
|
1601
|
+
function O(e, t) {
|
|
1602
|
+
var n = Object.keys(e);
|
|
1603
|
+
if (Object.getOwnPropertySymbols) {
|
|
1604
|
+
var r = Object.getOwnPropertySymbols(e);
|
|
1605
|
+
t && (r = r.filter(function(t) {
|
|
1606
|
+
return Object.getOwnPropertyDescriptor(e, t).enumerable;
|
|
1607
|
+
})), n.push.apply(n, r);
|
|
1608
|
+
}
|
|
1609
|
+
return n;
|
|
1610
|
+
}
|
|
1611
|
+
function V(e) {
|
|
1612
|
+
for (var t = 1; t < arguments.length; t++) {
|
|
1613
|
+
var n = null != arguments[t] ? arguments[t] : {};
|
|
1614
|
+
t % 2 ? O(Object(n), !0).forEach(function(t) {
|
|
1615
|
+
A(e, t, n[t]);
|
|
1616
|
+
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(n)) : O(Object(n)).forEach(function(t) {
|
|
1617
|
+
Object.defineProperty(e, t, Object.getOwnPropertyDescriptor(n, t));
|
|
1618
|
+
});
|
|
1619
|
+
}
|
|
1620
|
+
return e;
|
|
1621
|
+
}
|
|
1622
|
+
function A(e, t, n) {
|
|
1623
|
+
return (t = (function(e) {
|
|
1624
|
+
var t = (function(e, t) {
|
|
1625
|
+
if ("object" != w(e) || !e) return e;
|
|
1626
|
+
var n = e[Symbol.toPrimitive];
|
|
1627
|
+
if (void 0 !== n) {
|
|
1628
|
+
var r = n.call(e, t || "default");
|
|
1629
|
+
if ("object" != w(r)) return r;
|
|
1630
|
+
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
1631
|
+
}
|
|
1632
|
+
return ("string" === t ? String : Number)(e);
|
|
1633
|
+
})(e, "string");
|
|
1634
|
+
return "symbol" == w(t) ? t : t + "";
|
|
1635
|
+
})(t)) in e ? Object.defineProperty(e, t, {
|
|
1636
|
+
value: n,
|
|
1637
|
+
enumerable: !0,
|
|
1638
|
+
configurable: !0,
|
|
1639
|
+
writable: !0
|
|
1640
|
+
}) : e[t] = n, e;
|
|
1641
|
+
}
|
|
1642
|
+
function D(e, t) {
|
|
1643
|
+
var n = "undefined" != typeof Symbol && e[Symbol.iterator] || e["@@iterator"];
|
|
1644
|
+
if (!n) {
|
|
1645
|
+
if (Array.isArray(e) || (n = P(e)) || t && e && "number" == typeof e.length) {
|
|
1646
|
+
n && (e = n);
|
|
1647
|
+
var r = 0, o = function() {};
|
|
1648
|
+
return {
|
|
1649
|
+
s: o,
|
|
1650
|
+
n: function() {
|
|
1651
|
+
return r >= e.length ? { done: !0 } : {
|
|
1652
|
+
done: !1,
|
|
1653
|
+
value: e[r++]
|
|
1654
|
+
};
|
|
1655
|
+
},
|
|
1656
|
+
e: function(e) {
|
|
1657
|
+
throw e;
|
|
1658
|
+
},
|
|
1659
|
+
f: o
|
|
1660
|
+
};
|
|
1661
|
+
}
|
|
1662
|
+
throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
1663
|
+
}
|
|
1664
|
+
var i, a = !0, u = !1;
|
|
1665
|
+
return {
|
|
1666
|
+
s: function() {
|
|
1667
|
+
n = n.call(e);
|
|
1668
|
+
},
|
|
1669
|
+
n: function() {
|
|
1670
|
+
var e = n.next();
|
|
1671
|
+
return a = e.done, e;
|
|
1672
|
+
},
|
|
1673
|
+
e: function(e) {
|
|
1674
|
+
u = !0, i = e;
|
|
1675
|
+
},
|
|
1676
|
+
f: function() {
|
|
1677
|
+
try {
|
|
1678
|
+
a || null == n.return || n.return();
|
|
1679
|
+
} finally {
|
|
1680
|
+
if (u) throw i;
|
|
1681
|
+
}
|
|
1682
|
+
}
|
|
1683
|
+
};
|
|
1684
|
+
}
|
|
1685
|
+
function k(e, t) {
|
|
1686
|
+
return (function(e) {
|
|
1687
|
+
if (Array.isArray(e)) return e;
|
|
1688
|
+
})(e) || (function(e, t) {
|
|
1689
|
+
var n = null == e ? null : "undefined" != typeof Symbol && e[Symbol.iterator] || e["@@iterator"];
|
|
1690
|
+
if (null != n) {
|
|
1691
|
+
var r, o, i, a, u = [], p = !0, l = !1;
|
|
1692
|
+
try {
|
|
1693
|
+
if (i = (n = n.call(e)).next, 0 === t) {
|
|
1694
|
+
if (Object(n) !== n) return;
|
|
1695
|
+
p = !1;
|
|
1696
|
+
} else for (; !(p = (r = i.call(n)).done) && (u.push(r.value), u.length !== t); p = !0);
|
|
1697
|
+
} catch (e) {
|
|
1698
|
+
l = !0, o = e;
|
|
1699
|
+
} finally {
|
|
1700
|
+
try {
|
|
1701
|
+
if (!p && null != n.return && (a = n.return(), Object(a) !== a)) return;
|
|
1702
|
+
} finally {
|
|
1703
|
+
if (l) throw o;
|
|
1704
|
+
}
|
|
1705
|
+
}
|
|
1706
|
+
return u;
|
|
1707
|
+
}
|
|
1708
|
+
})(e, t) || P(e, t) || (function() {
|
|
1709
|
+
throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
1710
|
+
})();
|
|
1711
|
+
}
|
|
1712
|
+
function P(e, t) {
|
|
1713
|
+
if (e) {
|
|
1714
|
+
if ("string" == typeof e) return C(e, t);
|
|
1715
|
+
var n = {}.toString.call(e).slice(8, -1);
|
|
1716
|
+
return "Object" === n && e.constructor && (n = e.constructor.name), "Map" === n || "Set" === n ? Array.from(e) : "Arguments" === n || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n) ? C(e, t) : void 0;
|
|
1717
|
+
}
|
|
1718
|
+
}
|
|
1719
|
+
function C(e, t) {
|
|
1720
|
+
(null == t || t > e.length) && (t = e.length);
|
|
1721
|
+
for (var n = 0, r = Array(t); n < t; n++) r[n] = e[n];
|
|
1722
|
+
return r;
|
|
1723
|
+
}
|
|
1724
|
+
function E() {
|
|
1725
|
+
for (var e = /(?:[0]{1,2}[:-]){5}[0]{1,2}/, t = o.a.networkInterfaces(), n = 0, r = Object.entries(t); n < r.length; n++) {
|
|
1726
|
+
var i = k(r[n], 2), a = (i[0], i[1]);
|
|
1727
|
+
if (a) {
|
|
1728
|
+
var u, p = D(a);
|
|
1729
|
+
try {
|
|
1730
|
+
for (p.s(); !(u = p.n()).done;) {
|
|
1731
|
+
var l = u.value;
|
|
1732
|
+
if (!1 === e.test(l.mac)) return l.mac;
|
|
1733
|
+
}
|
|
1734
|
+
} catch (e) {
|
|
1735
|
+
p.e(e);
|
|
1736
|
+
} finally {
|
|
1737
|
+
p.f();
|
|
1738
|
+
}
|
|
1739
|
+
}
|
|
1740
|
+
}
|
|
1741
|
+
return "00:00:00:00:00:00";
|
|
1742
|
+
}
|
|
1743
|
+
var x, M, q = (x = process.version, {
|
|
1744
|
+
os: o.a.type(),
|
|
1745
|
+
os_version: o.a.release(),
|
|
1746
|
+
app_name: "node",
|
|
1747
|
+
app_version: x,
|
|
1748
|
+
device_id: N.a.createHash("md5").update(E()).digest("hex"),
|
|
1749
|
+
platform: "node"
|
|
1750
|
+
}), I = Object(T.promisify)(S.a.resolve);
|
|
1751
|
+
function H(e) {
|
|
1752
|
+
this._offlineQueue = [], e.endpoint = e.endpoint || "gm.mmstat.com", _.call(this, V(V({}, q), e)), this._config.endpoint_url = "https://".concat(this._config.endpoint).concat("/aes.1.1");
|
|
1753
|
+
}
|
|
1754
|
+
H.prototype = ((M = function() {}).prototype = _.prototype, new M()), H.prototype.constructor = H, H.prototype.send = function(e) {
|
|
1755
|
+
var t, n = this;
|
|
1756
|
+
return (t = this._config.endpoint, I(t)).then(function(t) {
|
|
1757
|
+
return n._offlineQueue.forEach(function(e) {
|
|
1758
|
+
n.send(e);
|
|
1759
|
+
}), n._offlineQueue = [], n._print("send", e), a()(n._config.endpoint_url, {
|
|
1760
|
+
method: "POST",
|
|
1761
|
+
keepalive: true,
|
|
1762
|
+
body: JSON.stringify({
|
|
1763
|
+
gokey: encodeURIComponent(e),
|
|
1764
|
+
gmkey: "EXP"
|
|
1765
|
+
})
|
|
1766
|
+
}).catch(function(e) {
|
|
1767
|
+
console.warn("send fail", e);
|
|
1768
|
+
});
|
|
1769
|
+
}).catch(function(t) {
|
|
1770
|
+
n._offlineQueue.length > 500 && n._offlineQueue.shift(), n._offlineQueue.push(e);
|
|
1771
|
+
});
|
|
1772
|
+
};
|
|
1773
|
+
t.default = H;
|
|
1774
|
+
}
|
|
1775
|
+
]).default;
|
|
1776
|
+
}));
|
|
1777
|
+
//#endregion
|
|
1778
|
+
//#region lib/remote-telemetry/event-plugin.js
|
|
1779
|
+
var require_event_plugin = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
1780
|
+
module.exports = (function(e) {
|
|
1781
|
+
var t = {};
|
|
1782
|
+
function n(r) {
|
|
1783
|
+
if (t[r]) return t[r].exports;
|
|
1784
|
+
var o = t[r] = {
|
|
1785
|
+
i: r,
|
|
1786
|
+
l: !1,
|
|
1787
|
+
exports: {}
|
|
1788
|
+
};
|
|
1789
|
+
return e[r].call(o.exports, o, o.exports, n), o.l = !0, o.exports;
|
|
1790
|
+
}
|
|
1791
|
+
return n.m = e, n.c = t, n.d = function(e, t, r) {
|
|
1792
|
+
n.o(e, t) || Object.defineProperty(e, t, {
|
|
1793
|
+
enumerable: !0,
|
|
1794
|
+
get: r
|
|
1795
|
+
});
|
|
1796
|
+
}, n.r = function(e) {
|
|
1797
|
+
"undefined" != typeof Symbol && Symbol.toStringTag && Object.defineProperty(e, Symbol.toStringTag, { value: "Module" }), Object.defineProperty(e, "__esModule", { value: !0 });
|
|
1798
|
+
}, n.t = function(e, t) {
|
|
1799
|
+
if (1 & t && (e = n(e)), 8 & t) return e;
|
|
1800
|
+
if (4 & t && "object" == typeof e && e && e.__esModule) return e;
|
|
1801
|
+
var r = Object.create(null);
|
|
1802
|
+
if (n.r(r), Object.defineProperty(r, "default", {
|
|
1803
|
+
enumerable: !0,
|
|
1804
|
+
value: e
|
|
1805
|
+
}), 2 & t && "string" != typeof e) for (var o in e) n.d(r, o, function(t) {
|
|
1806
|
+
return e[t];
|
|
1807
|
+
}.bind(null, o));
|
|
1808
|
+
return r;
|
|
1809
|
+
}, n.n = function(e) {
|
|
1810
|
+
var t = e && e.__esModule ? function() {
|
|
1811
|
+
return e.default;
|
|
1812
|
+
} : function() {
|
|
1813
|
+
return e;
|
|
1814
|
+
};
|
|
1815
|
+
return n.d(t, "a", t), t;
|
|
1816
|
+
}, n.o = function(e, t) {
|
|
1817
|
+
return Object.prototype.hasOwnProperty.call(e, t);
|
|
1818
|
+
}, n.p = "", n(n.s = 0);
|
|
1819
|
+
})([function(e, t, n) {
|
|
1820
|
+
"use strict";
|
|
1821
|
+
n.r(t);
|
|
1822
|
+
var r = [
|
|
1823
|
+
"ec",
|
|
1824
|
+
"ea",
|
|
1825
|
+
"el",
|
|
1826
|
+
"et"
|
|
1827
|
+
];
|
|
1828
|
+
var o = function(e, t) {
|
|
1829
|
+
var n = function(e) {
|
|
1830
|
+
var n = e.ec, r = e.ea, o = e.el, l = e.et, u = void 0 === l ? "CLK" : l, a = e.xpath;
|
|
1831
|
+
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;
|
|
1832
|
+
try {
|
|
1833
|
+
t.log("event", e);
|
|
1834
|
+
} catch (e) {}
|
|
1835
|
+
};
|
|
1836
|
+
return function() {
|
|
1837
|
+
var t = arguments, o = {};
|
|
1838
|
+
if (0 !== t.length) {
|
|
1839
|
+
for (var l = 0; l < t.length; l++) {
|
|
1840
|
+
var u, a, i = t[l];
|
|
1841
|
+
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, "Only the last argument can be object type"));
|
|
1842
|
+
if ("string" == typeof i || "number" == typeof i) o[r[l]] = i;
|
|
1843
|
+
else if ("object" == typeof i && l === t.length - 1) for (var c in i) i.hasOwnProperty(c) && (o[c] = i[c]);
|
|
1844
|
+
}
|
|
1845
|
+
n(o);
|
|
1846
|
+
} else {
|
|
1847
|
+
var f, p;
|
|
1848
|
+
null === (f = e.console) || void 0 === f || null === (p = f.warn) || void 0 === p || p.call(f, "At lease one augument");
|
|
1849
|
+
}
|
|
1850
|
+
};
|
|
1851
|
+
};
|
|
1852
|
+
t.default = function(e, t) {
|
|
1853
|
+
return o(global, e);
|
|
1854
|
+
};
|
|
1855
|
+
}]).default;
|
|
1856
|
+
}));
|
|
1035
1857
|
//#endregion
|
|
1036
1858
|
//#region src/telemetry/sink.ts
|
|
1859
|
+
var import_tracker = /* @__PURE__ */ __toESM(require_tracker(), 1);
|
|
1860
|
+
var import_event_plugin = /* @__PURE__ */ __toESM(require_event_plugin(), 1);
|
|
1037
1861
|
const TELEMETRY_FILE = () => join(getConfigDir(), "telemetry.jsonl");
|
|
1038
1862
|
const MAX_FILE_SIZE = 5 * 1024 * 1024;
|
|
1039
|
-
let
|
|
1040
|
-
|
|
1041
|
-
|
|
1863
|
+
let remoteSendEvent;
|
|
1864
|
+
const inflightSends = /* @__PURE__ */ new Set();
|
|
1865
|
+
let remoteClient = void 0;
|
|
1866
|
+
try {
|
|
1867
|
+
const client = new import_tracker.default({
|
|
1868
|
+
pid: "bailian-cli-node",
|
|
1869
|
+
env: detectEnv()
|
|
1870
|
+
});
|
|
1871
|
+
const originalSend = client.send.bind(client);
|
|
1872
|
+
client.send = function(payload) {
|
|
1873
|
+
const result = originalSend(payload);
|
|
1874
|
+
if (result && typeof result.then === "function") {
|
|
1875
|
+
const p = result;
|
|
1876
|
+
inflightSends.add(p);
|
|
1877
|
+
p.finally(() => inflightSends.delete(p));
|
|
1878
|
+
}
|
|
1879
|
+
return result;
|
|
1880
|
+
};
|
|
1881
|
+
remoteClient = client;
|
|
1882
|
+
remoteSendEvent = client.use(import_event_plugin.default);
|
|
1883
|
+
} catch {}
|
|
1884
|
+
/**
|
|
1885
|
+
* 尽力等待所有在途的埋点发送完成(best-effort)。
|
|
1886
|
+
*
|
|
1887
|
+
* 1. 先调用 `_sendAll` 排空 tracker 内部的去抖队列,把还卡在 500ms 合并窗口里
|
|
1888
|
+
* 的事件立刻推上网络。
|
|
1889
|
+
* 2. 然后用硬超时 race 所有已追踪的 fetch promise。
|
|
1890
|
+
*
|
|
1891
|
+
* 埋点永远不应阻塞 CLI:调用方应传入较短的超时(例如 1000ms),并始终与超时
|
|
1892
|
+
* race。错误与超时一律静默吞掉。
|
|
1893
|
+
*/
|
|
1894
|
+
async function flushTelemetry(timeoutMs = 1e3) {
|
|
1042
1895
|
try {
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
return
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
}
|
|
1896
|
+
if (remoteClient) try {
|
|
1897
|
+
if (typeof remoteClient._sendAll === "function") remoteClient._sendAll();
|
|
1898
|
+
} catch {}
|
|
1899
|
+
if (inflightSends.size === 0) return;
|
|
1900
|
+
const pending = [...inflightSends].map((p) => p.catch(() => void 0));
|
|
1901
|
+
await Promise.race([Promise.allSettled(pending), new Promise((resolve) => setTimeout(resolve, timeoutMs).unref?.())]);
|
|
1902
|
+
} catch {}
|
|
1050
1903
|
}
|
|
1051
1904
|
async function localSink(event) {
|
|
1052
1905
|
try {
|
|
@@ -1060,14 +1913,8 @@ async function localSink(event) {
|
|
|
1060
1913
|
}
|
|
1061
1914
|
async function remoteSink(event) {
|
|
1062
1915
|
try {
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
const { command, params, ...ext } = event;
|
|
1066
|
-
send(command, {
|
|
1067
|
-
et: "EXP",
|
|
1068
|
-
ext,
|
|
1069
|
-
c1: params
|
|
1070
|
-
});
|
|
1916
|
+
if (!remoteSendEvent) return;
|
|
1917
|
+
remoteSendEvent(event.command, buildRemoteAemOptions(event));
|
|
1071
1918
|
} catch {}
|
|
1072
1919
|
}
|
|
1073
1920
|
//#endregion
|
|
@@ -1154,15 +2001,17 @@ async function trackCommandExecution(config, commandPath, flags, fn) {
|
|
|
1154
2001
|
}
|
|
1155
2002
|
const start = performance.now();
|
|
1156
2003
|
let success = true;
|
|
1157
|
-
let errorCode;
|
|
1158
2004
|
let errorMessage;
|
|
2005
|
+
let httpStatus;
|
|
2006
|
+
let requestId;
|
|
1159
2007
|
try {
|
|
1160
2008
|
await fn();
|
|
1161
2009
|
} catch (err) {
|
|
1162
2010
|
success = false;
|
|
1163
2011
|
if (err instanceof BailianError) {
|
|
1164
|
-
errorCode = err.exitCode;
|
|
1165
2012
|
errorMessage = err.message;
|
|
2013
|
+
httpStatus = err.api?.httpStatus;
|
|
2014
|
+
requestId = err.api?.requestId;
|
|
1166
2015
|
} else if (err instanceof Error) errorMessage = err.message;
|
|
1167
2016
|
throw err;
|
|
1168
2017
|
} finally {
|
|
@@ -1176,8 +2025,9 @@ async function trackCommandExecution(config, commandPath, flags, fn) {
|
|
|
1176
2025
|
durationMs,
|
|
1177
2026
|
success,
|
|
1178
2027
|
error: success ? void 0 : {
|
|
1179
|
-
|
|
1180
|
-
|
|
2028
|
+
message: errorMessage,
|
|
2029
|
+
httpStatus,
|
|
2030
|
+
requestId
|
|
1181
2031
|
},
|
|
1182
2032
|
cliVersion: config.clientVersion ?? "unknown",
|
|
1183
2033
|
region: config.region,
|
|
@@ -1189,4 +2039,4 @@ async function trackCommandExecution(config, commandPath, flags, fn) {
|
|
|
1189
2039
|
}
|
|
1190
2040
|
}
|
|
1191
2041
|
//#endregion
|
|
1192
|
-
export { BAILIAN_HOST, BailianError, CHANNEL, DOCS_HOSTS, ExitCode, GLOBAL_OPTIONS, McpClient, REGIONS, SOURCE_CONFIG, TAGS, appCompletionEndpoint, callConsoleGateway, chatEndpoint, clearApiKey, createTrackingEvent, defineCommand, detectOutputFormat, ensureConfigDir, formatErrorJson, formatJson,
|
|
2042
|
+
export { BAILIAN_HOST, BailianError, CHANNEL, CONSOLE_GATEWAY_NO_TOKEN_MESSAGE, DOCS_HOSTS, ExitCode, GLOBAL_OPTIONS, McpClient, REGIONS, SOURCE_CONFIG, TAGS, appCompletionEndpoint, 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 };
|