@searchfe/openclaw-baiduapp 0.1.9 → 0.1.11
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 +19 -30
- package/dist/index.js +821 -621
- package/dist/index.js.map +1 -1
- package/openclaw.plugin.json +1 -10
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import os, { tmpdir } from 'os';
|
|
1
3
|
import path2 from 'path';
|
|
4
|
+
import readline from 'readline';
|
|
2
5
|
import { fileURLToPath } from 'url';
|
|
3
|
-
import
|
|
6
|
+
import crypto from 'crypto';
|
|
4
7
|
import { createRequire } from 'module';
|
|
5
8
|
import { lookup } from 'dns/promises';
|
|
6
9
|
import fs2 from 'fs/promises';
|
|
7
10
|
import net from 'net';
|
|
8
|
-
import fs from 'fs';
|
|
9
|
-
import { tmpdir } from 'os';
|
|
10
11
|
|
|
11
12
|
var __create = Object.create;
|
|
12
13
|
var __defProp = Object.defineProperty;
|
|
@@ -1357,20 +1358,20 @@ var require_package = __commonJS({
|
|
|
1357
1358
|
// node_modules/.pnpm/@baiducloud+sdk@1.0.7/node_modules/@baiducloud/sdk/src/crypto.js
|
|
1358
1359
|
var require_crypto = __commonJS({
|
|
1359
1360
|
"node_modules/.pnpm/@baiducloud+sdk@1.0.7/node_modules/@baiducloud/sdk/src/crypto.js"(exports$1) {
|
|
1360
|
-
var
|
|
1361
|
-
var
|
|
1361
|
+
var fs4 = __require("fs");
|
|
1362
|
+
var crypto3 = __require("crypto");
|
|
1362
1363
|
var Q = require_q();
|
|
1363
1364
|
exports$1.md5sum = function(data, enc, digest) {
|
|
1364
1365
|
if (!Buffer.isBuffer(data)) {
|
|
1365
1366
|
data = new Buffer(data, enc || "UTF-8");
|
|
1366
1367
|
}
|
|
1367
|
-
var md5 =
|
|
1368
|
+
var md5 = crypto3.createHash("md5");
|
|
1368
1369
|
md5.update(data);
|
|
1369
1370
|
return md5.digest(digest || "base64");
|
|
1370
1371
|
};
|
|
1371
1372
|
exports$1.md5stream = function(stream, digest) {
|
|
1372
1373
|
var deferred = Q.defer();
|
|
1373
|
-
var md5 =
|
|
1374
|
+
var md5 = crypto3.createHash("md5");
|
|
1374
1375
|
stream.on("data", function(chunk2) {
|
|
1375
1376
|
md5.update(chunk2);
|
|
1376
1377
|
});
|
|
@@ -1383,7 +1384,7 @@ var require_crypto = __commonJS({
|
|
|
1383
1384
|
return deferred.promise;
|
|
1384
1385
|
};
|
|
1385
1386
|
exports$1.md5file = function(filename, digest) {
|
|
1386
|
-
return exports$1.md5stream(
|
|
1387
|
+
return exports$1.md5stream(fs4.createReadStream(filename), digest);
|
|
1387
1388
|
};
|
|
1388
1389
|
exports$1.md5blob = function(blob, digest) {
|
|
1389
1390
|
var deferred = Q.defer();
|
|
@@ -2312,8 +2313,8 @@ var init_tap = __esm({
|
|
|
2312
2313
|
});
|
|
2313
2314
|
|
|
2314
2315
|
// node_modules/.pnpm/underscore@1.13.8/node_modules/underscore/modules/toPath.js
|
|
2315
|
-
function toPath(
|
|
2316
|
-
return isArray_default(
|
|
2316
|
+
function toPath(path5) {
|
|
2317
|
+
return isArray_default(path5) ? path5 : [path5];
|
|
2317
2318
|
}
|
|
2318
2319
|
var init_toPath = __esm({
|
|
2319
2320
|
"node_modules/.pnpm/underscore@1.13.8/node_modules/underscore/modules/toPath.js"() {
|
|
@@ -2324,8 +2325,8 @@ var init_toPath = __esm({
|
|
|
2324
2325
|
});
|
|
2325
2326
|
|
|
2326
2327
|
// node_modules/.pnpm/underscore@1.13.8/node_modules/underscore/modules/_toPath.js
|
|
2327
|
-
function toPath2(
|
|
2328
|
-
return _.toPath(
|
|
2328
|
+
function toPath2(path5) {
|
|
2329
|
+
return _.toPath(path5);
|
|
2329
2330
|
}
|
|
2330
2331
|
var init_toPath2 = __esm({
|
|
2331
2332
|
"node_modules/.pnpm/underscore@1.13.8/node_modules/underscore/modules/_toPath.js"() {
|
|
@@ -2335,11 +2336,11 @@ var init_toPath2 = __esm({
|
|
|
2335
2336
|
});
|
|
2336
2337
|
|
|
2337
2338
|
// node_modules/.pnpm/underscore@1.13.8/node_modules/underscore/modules/_deepGet.js
|
|
2338
|
-
function deepGet(obj,
|
|
2339
|
-
var length =
|
|
2339
|
+
function deepGet(obj, path5) {
|
|
2340
|
+
var length = path5.length;
|
|
2340
2341
|
for (var i = 0; i < length; i++) {
|
|
2341
2342
|
if (obj == null) return void 0;
|
|
2342
|
-
obj = obj[
|
|
2343
|
+
obj = obj[path5[i]];
|
|
2343
2344
|
}
|
|
2344
2345
|
return length ? obj : void 0;
|
|
2345
2346
|
}
|
|
@@ -2349,8 +2350,8 @@ var init_deepGet = __esm({
|
|
|
2349
2350
|
});
|
|
2350
2351
|
|
|
2351
2352
|
// node_modules/.pnpm/underscore@1.13.8/node_modules/underscore/modules/get.js
|
|
2352
|
-
function get(object2,
|
|
2353
|
-
var value = deepGet(object2, toPath2(
|
|
2353
|
+
function get(object2, path5, defaultValue) {
|
|
2354
|
+
var value = deepGet(object2, toPath2(path5));
|
|
2354
2355
|
return isUndefined(value) ? defaultValue : value;
|
|
2355
2356
|
}
|
|
2356
2357
|
var init_get = __esm({
|
|
@@ -2362,11 +2363,11 @@ var init_get = __esm({
|
|
|
2362
2363
|
});
|
|
2363
2364
|
|
|
2364
2365
|
// node_modules/.pnpm/underscore@1.13.8/node_modules/underscore/modules/has.js
|
|
2365
|
-
function has2(obj,
|
|
2366
|
-
|
|
2367
|
-
var length =
|
|
2366
|
+
function has2(obj, path5) {
|
|
2367
|
+
path5 = toPath2(path5);
|
|
2368
|
+
var length = path5.length;
|
|
2368
2369
|
for (var i = 0; i < length; i++) {
|
|
2369
|
-
var key =
|
|
2370
|
+
var key = path5[i];
|
|
2370
2371
|
if (!has(obj, key)) return false;
|
|
2371
2372
|
obj = obj[key];
|
|
2372
2373
|
}
|
|
@@ -2403,10 +2404,10 @@ var init_matcher = __esm({
|
|
|
2403
2404
|
});
|
|
2404
2405
|
|
|
2405
2406
|
// node_modules/.pnpm/underscore@1.13.8/node_modules/underscore/modules/property.js
|
|
2406
|
-
function property(
|
|
2407
|
-
|
|
2407
|
+
function property(path5) {
|
|
2408
|
+
path5 = toPath2(path5);
|
|
2408
2409
|
return function(obj) {
|
|
2409
|
-
return deepGet(obj,
|
|
2410
|
+
return deepGet(obj, path5);
|
|
2410
2411
|
};
|
|
2411
2412
|
}
|
|
2412
2413
|
var init_property = __esm({
|
|
@@ -2515,8 +2516,8 @@ var init_noop = __esm({
|
|
|
2515
2516
|
// node_modules/.pnpm/underscore@1.13.8/node_modules/underscore/modules/propertyOf.js
|
|
2516
2517
|
function propertyOf(obj) {
|
|
2517
2518
|
if (obj == null) return noop;
|
|
2518
|
-
return function(
|
|
2519
|
-
return get(obj,
|
|
2519
|
+
return function(path5) {
|
|
2520
|
+
return get(obj, path5);
|
|
2520
2521
|
};
|
|
2521
2522
|
}
|
|
2522
2523
|
var init_propertyOf = __esm({
|
|
@@ -2710,14 +2711,14 @@ var init_template = __esm({
|
|
|
2710
2711
|
});
|
|
2711
2712
|
|
|
2712
2713
|
// node_modules/.pnpm/underscore@1.13.8/node_modules/underscore/modules/result.js
|
|
2713
|
-
function result(obj,
|
|
2714
|
-
|
|
2715
|
-
var length =
|
|
2714
|
+
function result(obj, path5, fallback2) {
|
|
2715
|
+
path5 = toPath2(path5);
|
|
2716
|
+
var length = path5.length;
|
|
2716
2717
|
if (!length) {
|
|
2717
2718
|
return isFunction_default(fallback2) ? fallback2.call(obj) : fallback2;
|
|
2718
2719
|
}
|
|
2719
2720
|
for (var i = 0; i < length; i++) {
|
|
2720
|
-
var prop = obj == null ? void 0 : obj[
|
|
2721
|
+
var prop = obj == null ? void 0 : obj[path5[i]];
|
|
2721
2722
|
if (prop === void 0) {
|
|
2722
2723
|
prop = fallback2;
|
|
2723
2724
|
i = length;
|
|
@@ -3400,14 +3401,14 @@ var init_invoke = __esm({
|
|
|
3400
3401
|
init_map();
|
|
3401
3402
|
init_deepGet();
|
|
3402
3403
|
init_toPath2();
|
|
3403
|
-
invoke_default = restArguments(function(obj,
|
|
3404
|
+
invoke_default = restArguments(function(obj, path5, args) {
|
|
3404
3405
|
var contextPath, func;
|
|
3405
|
-
if (isFunction_default(
|
|
3406
|
-
func =
|
|
3406
|
+
if (isFunction_default(path5)) {
|
|
3407
|
+
func = path5;
|
|
3407
3408
|
} else {
|
|
3408
|
-
|
|
3409
|
-
contextPath =
|
|
3410
|
-
|
|
3409
|
+
path5 = toPath2(path5);
|
|
3410
|
+
contextPath = path5.slice(0, -1);
|
|
3411
|
+
path5 = path5[path5.length - 1];
|
|
3411
3412
|
}
|
|
3412
3413
|
return map(obj, function(context) {
|
|
3413
3414
|
var method = func;
|
|
@@ -3416,7 +3417,7 @@ var init_invoke = __esm({
|
|
|
3416
3417
|
context = deepGet(context, contextPath);
|
|
3417
3418
|
}
|
|
3418
3419
|
if (context == null) return void 0;
|
|
3419
|
-
method = context[
|
|
3420
|
+
method = context[path5];
|
|
3420
3421
|
}
|
|
3421
3422
|
return method == null ? method : method.apply(context, args);
|
|
3422
3423
|
});
|
|
@@ -5129,8 +5130,8 @@ var require_auth = __commonJS({
|
|
|
5129
5130
|
return [canonicalHeaders.join("\n"), signedHeaders];
|
|
5130
5131
|
};
|
|
5131
5132
|
Auth.prototype.hash = function(data, key) {
|
|
5132
|
-
var
|
|
5133
|
-
var sha256Hmac =
|
|
5133
|
+
var crypto3 = __require("crypto");
|
|
5134
|
+
var sha256Hmac = crypto3.createHmac("sha256", key);
|
|
5134
5135
|
sha256Hmac.update(data);
|
|
5135
5136
|
return sha256Hmac.digest("hex");
|
|
5136
5137
|
};
|
|
@@ -6365,8 +6366,8 @@ var require_http_client = __commonJS({
|
|
|
6365
6366
|
this._req = null;
|
|
6366
6367
|
}
|
|
6367
6368
|
util2.inherits(HttpClient, EventEmitter);
|
|
6368
|
-
HttpClient.prototype.updateConfigByPath = function(
|
|
6369
|
-
const pathArr =
|
|
6369
|
+
HttpClient.prototype.updateConfigByPath = function(path5, value) {
|
|
6370
|
+
const pathArr = path5.split(".");
|
|
6370
6371
|
function traverseAndUpdate(currentObj, index2) {
|
|
6371
6372
|
if (index2 >= pathArr.length - 1) {
|
|
6372
6373
|
currentObj[pathArr[index2]] = value;
|
|
@@ -6380,9 +6381,9 @@ var require_http_client = __commonJS({
|
|
|
6380
6381
|
traverseAndUpdate(this.config, 0);
|
|
6381
6382
|
return this.config;
|
|
6382
6383
|
};
|
|
6383
|
-
HttpClient.prototype.sendRequest = function(httpMethod,
|
|
6384
|
+
HttpClient.prototype.sendRequest = function(httpMethod, path5, body, headers, params, signFunction, outputStream) {
|
|
6384
6385
|
httpMethod = httpMethod.toUpperCase();
|
|
6385
|
-
var requestUrl = this._getRequestUrl(
|
|
6386
|
+
var requestUrl = this._getRequestUrl(path5, params);
|
|
6386
6387
|
var options = __require("url").parse(requestUrl);
|
|
6387
6388
|
debug("httpMethod = %s, requestUrl = %s, options = %j", httpMethod, requestUrl, options);
|
|
6388
6389
|
var defaultHeaders = {};
|
|
@@ -6429,7 +6430,7 @@ var require_http_client = __commonJS({
|
|
|
6429
6430
|
}
|
|
6430
6431
|
}
|
|
6431
6432
|
if (typeof signFunction === "function") {
|
|
6432
|
-
var promise = signFunction(this.config.credentials, httpMethod,
|
|
6433
|
+
var promise = signFunction(this.config.credentials, httpMethod, path5, params, headers, this);
|
|
6433
6434
|
if (isPromise(promise)) {
|
|
6434
6435
|
return promise.then(function(authorization, xbceDate) {
|
|
6435
6436
|
headers[H.AUTHORIZATION] = authorization;
|
|
@@ -6445,14 +6446,14 @@ var require_http_client = __commonJS({
|
|
|
6445
6446
|
throw new Error("Invalid signature = (" + promise + ")");
|
|
6446
6447
|
}
|
|
6447
6448
|
} else {
|
|
6448
|
-
headers[H.AUTHORIZATION] = createSignature(this.config.credentials, httpMethod,
|
|
6449
|
+
headers[H.AUTHORIZATION] = createSignature(this.config.credentials, httpMethod, path5, params, headers);
|
|
6449
6450
|
}
|
|
6450
6451
|
debug("options = %j", options);
|
|
6451
6452
|
return client._doRequest(options, body, outputStream);
|
|
6452
6453
|
};
|
|
6453
|
-
function createSignature(credentials, httpMethod,
|
|
6454
|
+
function createSignature(credentials, httpMethod, path5, params, headers) {
|
|
6454
6455
|
var auth = new Auth(credentials.ak, credentials.sk);
|
|
6455
|
-
return auth.generateAuthorization(httpMethod,
|
|
6456
|
+
return auth.generateAuthorization(httpMethod, path5, params, headers);
|
|
6456
6457
|
}
|
|
6457
6458
|
function isPromise(obj) {
|
|
6458
6459
|
return obj && (typeof obj === "object" || typeof obj === "function") && typeof obj.then === "function";
|
|
@@ -6634,8 +6635,8 @@ var require_http_client = __commonJS({
|
|
|
6634
6635
|
return "%" + char.charCodeAt().toString(16);
|
|
6635
6636
|
});
|
|
6636
6637
|
};
|
|
6637
|
-
HttpClient.prototype._getRequestUrl = function(
|
|
6638
|
-
var uri =
|
|
6638
|
+
HttpClient.prototype._getRequestUrl = function(path5, params) {
|
|
6639
|
+
var uri = path5;
|
|
6639
6640
|
var qs = this.buildQueryString(params);
|
|
6640
6641
|
if (qs) {
|
|
6641
6642
|
uri += "?" + qs;
|
|
@@ -6717,12 +6718,12 @@ var require_bce_base_client = __commonJS({
|
|
|
6717
6718
|
config.DEFAULT_SERVICE_DOMAIN
|
|
6718
6719
|
);
|
|
6719
6720
|
};
|
|
6720
|
-
BceBaseClient.prototype.createSignature = function(credentials, httpMethod,
|
|
6721
|
+
BceBaseClient.prototype.createSignature = function(credentials, httpMethod, path5, params, headers) {
|
|
6721
6722
|
var revisionTimestamp = Date.now() + (this.timeOffset || 0);
|
|
6722
6723
|
headers[H.X_BCE_DATE] = new Date(revisionTimestamp).toISOString().replace(/\.\d+Z$/, "Z");
|
|
6723
6724
|
return Q.fcall(function() {
|
|
6724
6725
|
var auth = new Auth(credentials.ak, credentials.sk);
|
|
6725
|
-
return auth.generateAuthorization(httpMethod,
|
|
6726
|
+
return auth.generateAuthorization(httpMethod, path5, params, headers, revisionTimestamp / 1e3);
|
|
6726
6727
|
});
|
|
6727
6728
|
};
|
|
6728
6729
|
BceBaseClient.prototype.sendRequest = function(httpMethod, resource, varArgs) {
|
|
@@ -9772,7 +9773,7 @@ var init_async = __esm({
|
|
|
9772
9773
|
// node_modules/.pnpm/@baiducloud+sdk@1.0.7/node_modules/@baiducloud/sdk/src/helper.js
|
|
9773
9774
|
var require_helper = __commonJS({
|
|
9774
9775
|
"node_modules/.pnpm/@baiducloud+sdk@1.0.7/node_modules/@baiducloud/sdk/src/helper.js"(exports$1) {
|
|
9775
|
-
var
|
|
9776
|
+
var fs4 = __require("fs");
|
|
9776
9777
|
var stream = __require("stream");
|
|
9777
9778
|
var async = (init_async(), __toCommonJS(async_exports));
|
|
9778
9779
|
var u = (init_index_all(), __toCommonJS(index_all_exports));
|
|
@@ -9796,7 +9797,7 @@ var require_helper = __commonJS({
|
|
|
9796
9797
|
var contentLength = 0;
|
|
9797
9798
|
var dataType = -1;
|
|
9798
9799
|
if (typeof data === "string") {
|
|
9799
|
-
contentLength =
|
|
9800
|
+
contentLength = fs4.lstatSync(data).size;
|
|
9800
9801
|
dataType = DATA_TYPE_FILE;
|
|
9801
9802
|
} else if (Buffer.isBuffer(data)) {
|
|
9802
9803
|
contentLength = data.length;
|
|
@@ -10900,11 +10901,11 @@ var require_baseGet = __commonJS({
|
|
|
10900
10901
|
"node_modules/.pnpm/lodash@4.17.23/node_modules/lodash/_baseGet.js"(exports$1, module) {
|
|
10901
10902
|
var castPath = require_castPath();
|
|
10902
10903
|
var toKey = require_toKey();
|
|
10903
|
-
function baseGet(object2,
|
|
10904
|
-
|
|
10905
|
-
var index2 = 0, length =
|
|
10904
|
+
function baseGet(object2, path5) {
|
|
10905
|
+
path5 = castPath(path5, object2);
|
|
10906
|
+
var index2 = 0, length = path5.length;
|
|
10906
10907
|
while (object2 != null && index2 < length) {
|
|
10907
|
-
object2 = object2[toKey(
|
|
10908
|
+
object2 = object2[toKey(path5[index2++])];
|
|
10908
10909
|
}
|
|
10909
10910
|
return index2 && index2 == length ? object2 : void 0;
|
|
10910
10911
|
}
|
|
@@ -11887,8 +11888,8 @@ var require_baseMatches = __commonJS({
|
|
|
11887
11888
|
var require_get = __commonJS({
|
|
11888
11889
|
"node_modules/.pnpm/lodash@4.17.23/node_modules/lodash/get.js"(exports$1, module) {
|
|
11889
11890
|
var baseGet = require_baseGet();
|
|
11890
|
-
function get2(object2,
|
|
11891
|
-
var result2 = object2 == null ? void 0 : baseGet(object2,
|
|
11891
|
+
function get2(object2, path5, defaultValue) {
|
|
11892
|
+
var result2 = object2 == null ? void 0 : baseGet(object2, path5);
|
|
11892
11893
|
return result2 === void 0 ? defaultValue : result2;
|
|
11893
11894
|
}
|
|
11894
11895
|
module.exports = get2;
|
|
@@ -11914,11 +11915,11 @@ var require_hasPath = __commonJS({
|
|
|
11914
11915
|
var isIndex = require_isIndex();
|
|
11915
11916
|
var isLength = require_isLength();
|
|
11916
11917
|
var toKey = require_toKey();
|
|
11917
|
-
function hasPath(object2,
|
|
11918
|
-
|
|
11919
|
-
var index2 = -1, length =
|
|
11918
|
+
function hasPath(object2, path5, hasFunc) {
|
|
11919
|
+
path5 = castPath(path5, object2);
|
|
11920
|
+
var index2 = -1, length = path5.length, result2 = false;
|
|
11920
11921
|
while (++index2 < length) {
|
|
11921
|
-
var key = toKey(
|
|
11922
|
+
var key = toKey(path5[index2]);
|
|
11922
11923
|
if (!(result2 = object2 != null && hasFunc(object2, key))) {
|
|
11923
11924
|
break;
|
|
11924
11925
|
}
|
|
@@ -11939,8 +11940,8 @@ var require_hasIn = __commonJS({
|
|
|
11939
11940
|
"node_modules/.pnpm/lodash@4.17.23/node_modules/lodash/hasIn.js"(exports$1, module) {
|
|
11940
11941
|
var baseHasIn = require_baseHasIn();
|
|
11941
11942
|
var hasPath = require_hasPath();
|
|
11942
|
-
function hasIn(object2,
|
|
11943
|
-
return object2 != null && hasPath(object2,
|
|
11943
|
+
function hasIn(object2, path5) {
|
|
11944
|
+
return object2 != null && hasPath(object2, path5, baseHasIn);
|
|
11944
11945
|
}
|
|
11945
11946
|
module.exports = hasIn;
|
|
11946
11947
|
}
|
|
@@ -11958,13 +11959,13 @@ var require_baseMatchesProperty = __commonJS({
|
|
|
11958
11959
|
var toKey = require_toKey();
|
|
11959
11960
|
var COMPARE_PARTIAL_FLAG = 1;
|
|
11960
11961
|
var COMPARE_UNORDERED_FLAG = 2;
|
|
11961
|
-
function baseMatchesProperty(
|
|
11962
|
-
if (isKey(
|
|
11963
|
-
return matchesStrictComparable(toKey(
|
|
11962
|
+
function baseMatchesProperty(path5, srcValue) {
|
|
11963
|
+
if (isKey(path5) && isStrictComparable(srcValue)) {
|
|
11964
|
+
return matchesStrictComparable(toKey(path5), srcValue);
|
|
11964
11965
|
}
|
|
11965
11966
|
return function(object2) {
|
|
11966
|
-
var objValue = get2(object2,
|
|
11967
|
-
return objValue === void 0 && objValue === srcValue ? hasIn(object2,
|
|
11967
|
+
var objValue = get2(object2, path5);
|
|
11968
|
+
return objValue === void 0 && objValue === srcValue ? hasIn(object2, path5) : baseIsEqual(srcValue, objValue, COMPARE_PARTIAL_FLAG | COMPARE_UNORDERED_FLAG);
|
|
11968
11969
|
};
|
|
11969
11970
|
}
|
|
11970
11971
|
module.exports = baseMatchesProperty;
|
|
@@ -11997,9 +11998,9 @@ var require_baseProperty = __commonJS({
|
|
|
11997
11998
|
var require_basePropertyDeep = __commonJS({
|
|
11998
11999
|
"node_modules/.pnpm/lodash@4.17.23/node_modules/lodash/_basePropertyDeep.js"(exports$1, module) {
|
|
11999
12000
|
var baseGet = require_baseGet();
|
|
12000
|
-
function basePropertyDeep(
|
|
12001
|
+
function basePropertyDeep(path5) {
|
|
12001
12002
|
return function(object2) {
|
|
12002
|
-
return baseGet(object2,
|
|
12003
|
+
return baseGet(object2, path5);
|
|
12003
12004
|
};
|
|
12004
12005
|
}
|
|
12005
12006
|
module.exports = basePropertyDeep;
|
|
@@ -12013,8 +12014,8 @@ var require_property = __commonJS({
|
|
|
12013
12014
|
var basePropertyDeep = require_basePropertyDeep();
|
|
12014
12015
|
var isKey = require_isKey();
|
|
12015
12016
|
var toKey = require_toKey();
|
|
12016
|
-
function property2(
|
|
12017
|
-
return isKey(
|
|
12017
|
+
function property2(path5) {
|
|
12018
|
+
return isKey(path5) ? baseProperty(toKey(path5)) : basePropertyDeep(path5);
|
|
12018
12019
|
}
|
|
12019
12020
|
module.exports = property2;
|
|
12020
12021
|
}
|
|
@@ -13069,8 +13070,8 @@ var require_parent = __commonJS({
|
|
|
13069
13070
|
"node_modules/.pnpm/lodash@4.17.23/node_modules/lodash/_parent.js"(exports$1, module) {
|
|
13070
13071
|
var baseGet = require_baseGet();
|
|
13071
13072
|
var baseSlice = require_baseSlice();
|
|
13072
|
-
function parent2(object2,
|
|
13073
|
-
return
|
|
13073
|
+
function parent2(object2, path5) {
|
|
13074
|
+
return path5.length < 2 ? object2 : baseGet(object2, baseSlice(path5, 0, -1));
|
|
13074
13075
|
}
|
|
13075
13076
|
module.exports = parent2;
|
|
13076
13077
|
}
|
|
@@ -13085,30 +13086,30 @@ var require_baseUnset = __commonJS({
|
|
|
13085
13086
|
var toKey = require_toKey();
|
|
13086
13087
|
var objectProto = Object.prototype;
|
|
13087
13088
|
var hasOwnProperty2 = objectProto.hasOwnProperty;
|
|
13088
|
-
function baseUnset(object2,
|
|
13089
|
-
|
|
13090
|
-
var index2 = -1, length =
|
|
13089
|
+
function baseUnset(object2, path5) {
|
|
13090
|
+
path5 = castPath(path5, object2);
|
|
13091
|
+
var index2 = -1, length = path5.length;
|
|
13091
13092
|
if (!length) {
|
|
13092
13093
|
return true;
|
|
13093
13094
|
}
|
|
13094
13095
|
var isRootPrimitive = object2 == null || typeof object2 !== "object" && typeof object2 !== "function";
|
|
13095
13096
|
while (++index2 < length) {
|
|
13096
|
-
var key =
|
|
13097
|
+
var key = path5[index2];
|
|
13097
13098
|
if (typeof key !== "string") {
|
|
13098
13099
|
continue;
|
|
13099
13100
|
}
|
|
13100
13101
|
if (key === "__proto__" && !hasOwnProperty2.call(object2, "__proto__")) {
|
|
13101
13102
|
return false;
|
|
13102
13103
|
}
|
|
13103
|
-
if (key === "constructor" && index2 + 1 < length && typeof
|
|
13104
|
+
if (key === "constructor" && index2 + 1 < length && typeof path5[index2 + 1] === "string" && path5[index2 + 1] === "prototype") {
|
|
13104
13105
|
if (isRootPrimitive && index2 === 0) {
|
|
13105
13106
|
continue;
|
|
13106
13107
|
}
|
|
13107
13108
|
return false;
|
|
13108
13109
|
}
|
|
13109
13110
|
}
|
|
13110
|
-
var obj = parent2(object2,
|
|
13111
|
-
return obj == null || delete obj[toKey(last2(
|
|
13111
|
+
var obj = parent2(object2, path5);
|
|
13112
|
+
return obj == null || delete obj[toKey(last2(path5))];
|
|
13112
13113
|
}
|
|
13113
13114
|
module.exports = baseUnset;
|
|
13114
13115
|
}
|
|
@@ -13197,10 +13198,10 @@ var require_omit = __commonJS({
|
|
|
13197
13198
|
return result2;
|
|
13198
13199
|
}
|
|
13199
13200
|
var isDeep = false;
|
|
13200
|
-
paths = arrayMap(paths, function(
|
|
13201
|
-
|
|
13202
|
-
isDeep || (isDeep =
|
|
13203
|
-
return
|
|
13201
|
+
paths = arrayMap(paths, function(path5) {
|
|
13202
|
+
path5 = castPath(path5, object2);
|
|
13203
|
+
isDeep || (isDeep = path5.length > 1);
|
|
13204
|
+
return path5;
|
|
13204
13205
|
});
|
|
13205
13206
|
copyObject(object2, getAllKeysIn(object2), result2);
|
|
13206
13207
|
if (isDeep) {
|
|
@@ -14389,15 +14390,15 @@ var require_super_upload = __commonJS({
|
|
|
14389
14390
|
var require_bos_client = __commonJS({
|
|
14390
14391
|
"node_modules/.pnpm/@baiducloud+sdk@1.0.7/node_modules/@baiducloud/sdk/src/bos_client.js"(exports$1, module) {
|
|
14391
14392
|
var util2 = __require("util");
|
|
14392
|
-
var
|
|
14393
|
-
var
|
|
14393
|
+
var path5 = __require("path");
|
|
14394
|
+
var fs4 = __require("fs");
|
|
14394
14395
|
var qs = __require("querystring");
|
|
14395
14396
|
var u = (init_index_all(), __toCommonJS(index_all_exports));
|
|
14396
14397
|
var Q = require_q();
|
|
14397
14398
|
var H = require_headers();
|
|
14398
14399
|
var strings = require_strings();
|
|
14399
14400
|
var Auth = require_auth();
|
|
14400
|
-
var
|
|
14401
|
+
var crypto3 = require_crypto();
|
|
14401
14402
|
var HttpClient = require_http_client();
|
|
14402
14403
|
var BceBaseClient = require_bce_base_client();
|
|
14403
14404
|
var MimeType = require_mime_types();
|
|
@@ -14457,8 +14458,8 @@ var require_bos_client = __commonJS({
|
|
|
14457
14458
|
customGenerateUrl: config.customGenerateUrl
|
|
14458
14459
|
});
|
|
14459
14460
|
params = params || {};
|
|
14460
|
-
var resource =
|
|
14461
|
-
|
|
14461
|
+
var resource = path5.normalize(
|
|
14462
|
+
path5.join(
|
|
14462
14463
|
config.removeVersionPrefix ? "/" : "/v1",
|
|
14463
14464
|
!pathStyleEnable ? "" : strings.normalize(bucketName || ""),
|
|
14464
14465
|
strings.normalize(key || "", false)
|
|
@@ -14486,8 +14487,8 @@ var require_bos_client = __commonJS({
|
|
|
14486
14487
|
BosClient.prototype.generateUrl = function(bucketName, key, pipeline, cdn, config) {
|
|
14487
14488
|
config = u.extend({}, this.config, config);
|
|
14488
14489
|
bucketName = config.cname_enabled ? "" : bucketName;
|
|
14489
|
-
var resource =
|
|
14490
|
-
|
|
14490
|
+
var resource = path5.normalize(
|
|
14491
|
+
path5.join(
|
|
14491
14492
|
config.removeVersionPrefix ? "/" : "/v1",
|
|
14492
14493
|
strings.normalize(bucketName || ""),
|
|
14493
14494
|
strings.normalize(key || "", false)
|
|
@@ -14511,9 +14512,9 @@ var require_bos_client = __commonJS({
|
|
|
14511
14512
|
}
|
|
14512
14513
|
if (command) {
|
|
14513
14514
|
if (cdn) {
|
|
14514
|
-
return util2.format("http://%s/%s%s", cdn,
|
|
14515
|
+
return util2.format("http://%s/%s%s", cdn, path5.normalize(key), command);
|
|
14515
14516
|
}
|
|
14516
|
-
return util2.format("http://%s.%s/%s%s",
|
|
14517
|
+
return util2.format("http://%s.%s/%s%s", path5.normalize(bucketName), IMAGE_DOMAIN, path5.normalize(key), command);
|
|
14517
14518
|
}
|
|
14518
14519
|
return util2.format("%s%s%s", this.config.endpoint, resource, command);
|
|
14519
14520
|
};
|
|
@@ -15013,21 +15014,21 @@ var require_bos_client = __commonJS({
|
|
|
15013
15014
|
options = options || {};
|
|
15014
15015
|
var headers = {};
|
|
15015
15016
|
headers[H.CONTENT_LENGTH] = Buffer.byteLength(data);
|
|
15016
|
-
headers[H.CONTENT_TYPE] = options[H.CONTENT_TYPE] || MimeType.guess(
|
|
15017
|
-
headers[H.CONTENT_MD5] =
|
|
15017
|
+
headers[H.CONTENT_TYPE] = options[H.CONTENT_TYPE] || MimeType.guess(path5.extname(key));
|
|
15018
|
+
headers[H.CONTENT_MD5] = crypto3.md5sum(data);
|
|
15018
15019
|
options = u.extend(headers, options);
|
|
15019
15020
|
return this.putObject(bucketName, key, data, options);
|
|
15020
15021
|
};
|
|
15021
15022
|
BosClient.prototype.putObjectFromFile = function(bucketName, key, filename, options) {
|
|
15022
15023
|
options = options || {};
|
|
15023
15024
|
var headers = {};
|
|
15024
|
-
var fileSize =
|
|
15025
|
+
var fileSize = fs4.statSync(filename).size;
|
|
15025
15026
|
var contentLength = u.has(options, H.CONTENT_LENGTH) ? options[H.CONTENT_LENGTH] : fileSize;
|
|
15026
15027
|
if (contentLength > fileSize) {
|
|
15027
15028
|
throw new Error("options['Content-Length'] should less than " + fileSize);
|
|
15028
15029
|
}
|
|
15029
15030
|
headers[H.CONTENT_LENGTH] = contentLength;
|
|
15030
|
-
headers[H.CONTENT_TYPE] = options[H.CONTENT_TYPE] || MimeType.guess(
|
|
15031
|
+
headers[H.CONTENT_TYPE] = options[H.CONTENT_TYPE] || MimeType.guess(path5.extname(filename));
|
|
15031
15032
|
options = u.extend(headers, options);
|
|
15032
15033
|
var streamOptions = {
|
|
15033
15034
|
start: 0,
|
|
@@ -15035,7 +15036,7 @@ var require_bos_client = __commonJS({
|
|
|
15035
15036
|
};
|
|
15036
15037
|
var me = this;
|
|
15037
15038
|
function putObjectWithRetry(lastRetryTimes) {
|
|
15038
|
-
return me.putObject(bucketName, key,
|
|
15039
|
+
return me.putObject(bucketName, key, fs4.createReadStream(filename, streamOptions), options).catch(function(err) {
|
|
15039
15040
|
var serverTimestamp = new Date(err[H.X_BCE_DATE]).getTime();
|
|
15040
15041
|
BceBaseClient.prototype.timeOffset = serverTimestamp - Date.now();
|
|
15041
15042
|
if (err[H.X_STATUS_CODE] === 400 && err[H.X_CODE] === "Http400" && lastRetryTimes > 0) {
|
|
@@ -15045,8 +15046,8 @@ var require_bos_client = __commonJS({
|
|
|
15045
15046
|
});
|
|
15046
15047
|
}
|
|
15047
15048
|
if (!u.has(options, H.CONTENT_MD5)) {
|
|
15048
|
-
var fp2 =
|
|
15049
|
-
return
|
|
15049
|
+
var fp2 = fs4.createReadStream(filename, streamOptions);
|
|
15050
|
+
return crypto3.md5stream(fp2).then(function(md5sum) {
|
|
15050
15051
|
options[H.CONTENT_MD5] = md5sum;
|
|
15051
15052
|
return putObjectWithRetry(options.retryCount || MAX_RETRY_COUNT);
|
|
15052
15053
|
});
|
|
@@ -15124,7 +15125,7 @@ var require_bos_client = __commonJS({
|
|
|
15124
15125
|
Range: range3 ? util2.format("bytes=%s", range3) : ""
|
|
15125
15126
|
},
|
|
15126
15127
|
config: options.config,
|
|
15127
|
-
outputStream:
|
|
15128
|
+
outputStream: fs4.createWriteStream(filename)
|
|
15128
15129
|
});
|
|
15129
15130
|
};
|
|
15130
15131
|
BosClient.prototype.copyObject = function(sourceBucketName, sourceKey, targetBucketName, targetKey, options) {
|
|
@@ -15166,7 +15167,7 @@ var require_bos_client = __commonJS({
|
|
|
15166
15167
|
BosClient.prototype.initiateMultipartUpload = function(bucketName, key, options) {
|
|
15167
15168
|
options = options || {};
|
|
15168
15169
|
var headers = {};
|
|
15169
|
-
headers[H.CONTENT_TYPE] = MimeType.guess(
|
|
15170
|
+
headers[H.CONTENT_TYPE] = MimeType.guess(path5.extname(key));
|
|
15170
15171
|
options = this._checkOptions(u.extend(headers, options));
|
|
15171
15172
|
return this.sendRequest("POST", {
|
|
15172
15173
|
bucketName,
|
|
@@ -15201,7 +15202,7 @@ var require_bos_client = __commonJS({
|
|
|
15201
15202
|
BosClient.prototype.uploadPartFromFile = function(bucketName, key, uploadId, partNumber, partSize, filename, offset, options) {
|
|
15202
15203
|
var start = offset;
|
|
15203
15204
|
var end = offset + partSize - 1;
|
|
15204
|
-
var partFp =
|
|
15205
|
+
var partFp = fs4.createReadStream(filename, {
|
|
15205
15206
|
start,
|
|
15206
15207
|
end
|
|
15207
15208
|
});
|
|
@@ -15266,7 +15267,7 @@ var require_bos_client = __commonJS({
|
|
|
15266
15267
|
);
|
|
15267
15268
|
}
|
|
15268
15269
|
var client = this;
|
|
15269
|
-
var clonedPartFp =
|
|
15270
|
+
var clonedPartFp = fs4.createReadStream(partFp.path, {
|
|
15270
15271
|
start: partFp.start,
|
|
15271
15272
|
end: partFp.end
|
|
15272
15273
|
});
|
|
@@ -15380,8 +15381,8 @@ var require_bos_client = __commonJS({
|
|
|
15380
15381
|
options = options || {};
|
|
15381
15382
|
var headers = {};
|
|
15382
15383
|
headers[H.CONTENT_LENGTH] = Buffer.byteLength(data);
|
|
15383
|
-
headers[H.CONTENT_TYPE] = options[H.CONTENT_TYPE] || MimeType.guess(
|
|
15384
|
-
headers[H.CONTENT_MD5] =
|
|
15384
|
+
headers[H.CONTENT_TYPE] = options[H.CONTENT_TYPE] || MimeType.guess(path5.extname(key));
|
|
15385
|
+
headers[H.CONTENT_MD5] = crypto3.md5sum(data);
|
|
15385
15386
|
options = u.extend(headers, options);
|
|
15386
15387
|
return this.appendObject(bucketName, key, data, offset, options);
|
|
15387
15388
|
};
|
|
@@ -15391,22 +15392,22 @@ var require_bos_client = __commonJS({
|
|
|
15391
15392
|
return this.appendObjectFromString(bucketName, key, "", offset, options);
|
|
15392
15393
|
}
|
|
15393
15394
|
var headers = {};
|
|
15394
|
-
var fileSize =
|
|
15395
|
+
var fileSize = fs4.statSync(filename).size;
|
|
15395
15396
|
if (size2 + offset > fileSize) {
|
|
15396
15397
|
throw new Error("Can't read the content beyond the end of file.");
|
|
15397
15398
|
}
|
|
15398
15399
|
headers[H.CONTENT_LENGTH] = size2;
|
|
15399
|
-
headers[H.CONTENT_TYPE] = options[H.CONTENT_TYPE] || MimeType.guess(
|
|
15400
|
+
headers[H.CONTENT_TYPE] = options[H.CONTENT_TYPE] || MimeType.guess(path5.extname(filename));
|
|
15400
15401
|
options = u.extend(headers, options);
|
|
15401
15402
|
var streamOptions = {
|
|
15402
15403
|
start: offset || 0,
|
|
15403
15404
|
end: (offset || 0) + size2 - 1
|
|
15404
15405
|
};
|
|
15405
|
-
var fp =
|
|
15406
|
+
var fp = fs4.createReadStream(filename, streamOptions);
|
|
15406
15407
|
if (!u.has(options, H.CONTENT_MD5)) {
|
|
15407
15408
|
var me = this;
|
|
15408
|
-
var fp2 =
|
|
15409
|
-
return
|
|
15409
|
+
var fp2 = fs4.createReadStream(filename, streamOptions);
|
|
15410
|
+
return crypto3.md5stream(fp2).then(function(md5sum) {
|
|
15410
15411
|
options[H.CONTENT_MD5] = md5sum;
|
|
15411
15412
|
return me.appendObject(bucketName, key, fp, offset, options);
|
|
15412
15413
|
});
|
|
@@ -15427,7 +15428,7 @@ var require_bos_client = __commonJS({
|
|
|
15427
15428
|
var boundary = "MM8964" + (Math.random() * Math.pow(2, 63)).toString(36);
|
|
15428
15429
|
var contentType = "multipart/form-data; boundary=" + boundary;
|
|
15429
15430
|
if (u.isString(data)) {
|
|
15430
|
-
data =
|
|
15431
|
+
data = fs4.readFileSync(data);
|
|
15431
15432
|
} else if (!Buffer.isBuffer(data)) {
|
|
15432
15433
|
throw new Error("Invalid data type.");
|
|
15433
15434
|
}
|
|
@@ -15634,7 +15635,7 @@ var require_bos_client = __commonJS({
|
|
|
15634
15635
|
var pathStyleEnable = !!domainUtils.isIpHost(endpoint) || this.config.pathStyleEnable;
|
|
15635
15636
|
if (typeof customGenerateUrl === "function") {
|
|
15636
15637
|
endpoint = customGenerateUrl(bucketName, region);
|
|
15637
|
-
var resource = requestUrl ||
|
|
15638
|
+
var resource = requestUrl || path5.normalize(path5.join(versionPrefix, strings.normalize(varArgs.key || "", false))).replace(/\\/g, "/");
|
|
15638
15639
|
} else {
|
|
15639
15640
|
endpoint = domainUtils.handleEndpoint({
|
|
15640
15641
|
bucketName,
|
|
@@ -15644,8 +15645,8 @@ var require_bos_client = __commonJS({
|
|
|
15644
15645
|
cname_enabled: this.config.cname_enabled,
|
|
15645
15646
|
pathStyleEnable
|
|
15646
15647
|
});
|
|
15647
|
-
var resource = requestUrl ||
|
|
15648
|
-
|
|
15648
|
+
var resource = requestUrl || path5.normalize(
|
|
15649
|
+
path5.join(
|
|
15649
15650
|
"/" ,
|
|
15650
15651
|
// if pathStyleEnable is true
|
|
15651
15652
|
!pathStyleEnable ? "" : strings.normalize(varArgs.bucketName || ""),
|
|
@@ -15851,11 +15852,11 @@ var require_bos_client = __commonJS({
|
|
|
15851
15852
|
params = params || {};
|
|
15852
15853
|
const { objectName, data } = params;
|
|
15853
15854
|
const MAX_UPLOAD_FILE_SIZE = 48.8 * 1024 ** 4;
|
|
15854
|
-
const ContentType = params.ContentType || MimeType.guess(
|
|
15855
|
+
const ContentType = params.ContentType || MimeType.guess(path5.extname(objectName));
|
|
15855
15856
|
let ContentLength = params.ContentLength;
|
|
15856
15857
|
let dataType = "";
|
|
15857
15858
|
if (typeof data === "string") {
|
|
15858
|
-
ContentLength =
|
|
15859
|
+
ContentLength = fs4.lstatSync(data).size;
|
|
15859
15860
|
dataType = "File";
|
|
15860
15861
|
} else if (Buffer.isBuffer(data)) {
|
|
15861
15862
|
ContentLength = data.length;
|
|
@@ -15987,10 +15988,10 @@ var require_bos_client = __commonJS({
|
|
|
15987
15988
|
// node_modules/.pnpm/@baiducloud+sdk@1.0.7/node_modules/@baiducloud/sdk/src/bcs_client.js
|
|
15988
15989
|
var require_bcs_client = __commonJS({
|
|
15989
15990
|
"node_modules/.pnpm/@baiducloud+sdk@1.0.7/node_modules/@baiducloud/sdk/src/bcs_client.js"(exports$1, module) {
|
|
15990
|
-
var
|
|
15991
|
+
var crypto3 = __require("crypto");
|
|
15991
15992
|
var util2 = __require("util");
|
|
15992
|
-
var
|
|
15993
|
-
var
|
|
15993
|
+
var path5 = __require("path");
|
|
15994
|
+
var fs4 = __require("fs");
|
|
15994
15995
|
var u = (init_index_all(), __toCommonJS(index_all_exports));
|
|
15995
15996
|
var H = require_headers();
|
|
15996
15997
|
var HttpClient = require_http_client();
|
|
@@ -16105,10 +16106,10 @@ var require_bcs_client = __commonJS({
|
|
|
16105
16106
|
BcsClient.prototype.putObjectFromFile = function(bucketName, key, filename, options) {
|
|
16106
16107
|
options = options || {};
|
|
16107
16108
|
var headers = {};
|
|
16108
|
-
headers[H.CONTENT_LENGTH] =
|
|
16109
|
-
headers[H.CONTENT_TYPE] = options[H.CONTENT_TYPE] || MimeType.guess(
|
|
16109
|
+
headers[H.CONTENT_LENGTH] = fs4.statSync(filename).size;
|
|
16110
|
+
headers[H.CONTENT_TYPE] = options[H.CONTENT_TYPE] || MimeType.guess(path5.extname(filename));
|
|
16110
16111
|
options = u.extend(headers, options);
|
|
16111
|
-
var fp =
|
|
16112
|
+
var fp = fs4.createReadStream(filename);
|
|
16112
16113
|
if (!u.has(options, H.CONTENT_MD5)) {
|
|
16113
16114
|
var me = this;
|
|
16114
16115
|
return require_crypto().md5file(filename, "hex").then(function(md5sum) {
|
|
@@ -16126,7 +16127,7 @@ var require_bcs_client = __commonJS({
|
|
|
16126
16127
|
"Object=" + objectName
|
|
16127
16128
|
].join("\n");
|
|
16128
16129
|
var content = flag + "\n" + body + "\n";
|
|
16129
|
-
var hmac =
|
|
16130
|
+
var hmac = crypto3.createHmac("sha1", credentials.sk);
|
|
16130
16131
|
hmac.update(new Buffer(content, "utf-8"));
|
|
16131
16132
|
var digest = encodeURIComponent(hmac.digest("base64")).replace(/%2F/g, "/");
|
|
16132
16133
|
return [flag, credentials.ak, digest].join(":");
|
|
@@ -16356,8 +16357,8 @@ var require_bcc_client = __commonJS({
|
|
|
16356
16357
|
// node_modules/.pnpm/@baiducloud+sdk@1.0.7/node_modules/@baiducloud/sdk/src/ses_client.js
|
|
16357
16358
|
var require_ses_client = __commonJS({
|
|
16358
16359
|
"node_modules/.pnpm/@baiducloud+sdk@1.0.7/node_modules/@baiducloud/sdk/src/ses_client.js"(exports$1, module) {
|
|
16359
|
-
var
|
|
16360
|
-
var
|
|
16360
|
+
var fs4 = __require("fs");
|
|
16361
|
+
var path5 = __require("path");
|
|
16361
16362
|
var util2 = __require("util");
|
|
16362
16363
|
var BceBaseClient = require_bce_base_client();
|
|
16363
16364
|
function SesClient(config) {
|
|
@@ -16423,9 +16424,9 @@ var require_ses_client = __commonJS({
|
|
|
16423
16424
|
if (typeof item === "string") {
|
|
16424
16425
|
return {
|
|
16425
16426
|
/* eslint-disable */
|
|
16426
|
-
file_name:
|
|
16427
|
+
file_name: path5.basename(item),
|
|
16427
16428
|
file_data: {
|
|
16428
|
-
data:
|
|
16429
|
+
data: fs4.readFileSync(item).toString("base64")
|
|
16429
16430
|
}
|
|
16430
16431
|
/* eslint-enable */
|
|
16431
16432
|
};
|
|
@@ -17444,10 +17445,10 @@ var require_media_client = __commonJS({
|
|
|
17444
17445
|
var url = "/v3/statistic/job/realtime";
|
|
17445
17446
|
return this.sendRequest("GET", url);
|
|
17446
17447
|
};
|
|
17447
|
-
MediaClient.prototype.createSignature = function(credentials, httpMethod,
|
|
17448
|
+
MediaClient.prototype.createSignature = function(credentials, httpMethod, path5, params, headers) {
|
|
17448
17449
|
var auth = new Auth(credentials.ak, credentials.sk);
|
|
17449
17450
|
var headersToSign = ["host"];
|
|
17450
|
-
return auth.generateAuthorization(httpMethod,
|
|
17451
|
+
return auth.generateAuthorization(httpMethod, path5, params, headers, 0, 0, headersToSign);
|
|
17451
17452
|
};
|
|
17452
17453
|
MediaClient.prototype.sendRequest = function(httpMethod, resource, varArgs) {
|
|
17453
17454
|
var defaultArgs = {
|
|
@@ -17957,8 +17958,8 @@ var require_vod_client = __commonJS({
|
|
|
17957
17958
|
// node_modules/.pnpm/@baiducloud+sdk@1.0.7/node_modules/@baiducloud/sdk/src/doc_client.js
|
|
17958
17959
|
var require_doc_client = __commonJS({
|
|
17959
17960
|
"node_modules/.pnpm/@baiducloud+sdk@1.0.7/node_modules/@baiducloud/sdk/src/doc_client.js"(exports$1) {
|
|
17960
|
-
var
|
|
17961
|
-
var
|
|
17961
|
+
var fs4 = __require("fs");
|
|
17962
|
+
var path5 = __require("path");
|
|
17962
17963
|
var util2 = __require("util");
|
|
17963
17964
|
var builtinUrl = __require("url");
|
|
17964
17965
|
var Q = require_q();
|
|
@@ -17967,7 +17968,7 @@ var require_doc_client = __commonJS({
|
|
|
17967
17968
|
var BosClient = require_bos_client();
|
|
17968
17969
|
var BceBaseClient = require_bce_base_client();
|
|
17969
17970
|
var UploadHelper = require_helper();
|
|
17970
|
-
var
|
|
17971
|
+
var crypto3 = require_crypto();
|
|
17971
17972
|
var DATA_TYPE_FILE = 1;
|
|
17972
17973
|
var DATA_TYPE_BUFFER = 2;
|
|
17973
17974
|
var DATA_TYPE_BLOB = 4;
|
|
@@ -18002,8 +18003,8 @@ var require_doc_client = __commonJS({
|
|
|
18002
18003
|
var bucket = parsed.host;
|
|
18003
18004
|
var object2 = parsed.pathname.substr(1);
|
|
18004
18005
|
options = u.extend(options, parsed.query);
|
|
18005
|
-
var title = options.title ||
|
|
18006
|
-
var format = options.format ||
|
|
18006
|
+
var title = options.title || path5.basename(object2);
|
|
18007
|
+
var format = options.format || path5.extname(object2).substr(1);
|
|
18007
18008
|
var notification = options.notification;
|
|
18008
18009
|
return this.createFromBos(
|
|
18009
18010
|
bucket,
|
|
@@ -18017,8 +18018,8 @@ var require_doc_client = __commonJS({
|
|
|
18017
18018
|
}
|
|
18018
18019
|
}
|
|
18019
18020
|
dataType = DATA_TYPE_FILE;
|
|
18020
|
-
options.format = options.format ||
|
|
18021
|
-
options.title = options.title ||
|
|
18021
|
+
options.format = options.format || path5.extname(data).substr(1);
|
|
18022
|
+
options.title = options.title || path5.basename(data, path5.extname(data));
|
|
18022
18023
|
} else if (Buffer.isBuffer(data)) {
|
|
18023
18024
|
if (options.format == null || options.title == null) {
|
|
18024
18025
|
return Q.reject(new Error("buffer type required options.format and options.title"));
|
|
@@ -18026,8 +18027,8 @@ var require_doc_client = __commonJS({
|
|
|
18026
18027
|
dataType = DATA_TYPE_BUFFER;
|
|
18027
18028
|
} else if (typeof Blob !== "undefined" && data instanceof Blob) {
|
|
18028
18029
|
dataType = DATA_TYPE_BLOB;
|
|
18029
|
-
options.format = options.format ||
|
|
18030
|
-
options.title = options.title ||
|
|
18030
|
+
options.format = options.format || path5.extname(data.name).substr(1);
|
|
18031
|
+
options.title = options.title || path5.basename(data.name, path5.extname(data.name));
|
|
18031
18032
|
} else {
|
|
18032
18033
|
return Q.reject(new Error("Unsupported dataType."));
|
|
18033
18034
|
}
|
|
@@ -18039,12 +18040,12 @@ var require_doc_client = __commonJS({
|
|
|
18039
18040
|
}
|
|
18040
18041
|
var self2 = this;
|
|
18041
18042
|
if (dataType === DATA_TYPE_FILE) {
|
|
18042
|
-
return
|
|
18043
|
+
return crypto3.md5stream(fs4.createReadStream(data), "hex").then(function(md5) {
|
|
18043
18044
|
options.meta.md5 = md5;
|
|
18044
18045
|
return self2._doCreate(data, options);
|
|
18045
18046
|
});
|
|
18046
18047
|
} else if (dataType === DATA_TYPE_BLOB) {
|
|
18047
|
-
return
|
|
18048
|
+
return crypto3.md5blob(data, "hex").then(function(md5) {
|
|
18048
18049
|
options.meta.md5 = md5;
|
|
18049
18050
|
return self2._doCreate(data, options);
|
|
18050
18051
|
});
|
|
@@ -18122,7 +18123,7 @@ var require_doc_client = __commonJS({
|
|
|
18122
18123
|
object: object2,
|
|
18123
18124
|
title
|
|
18124
18125
|
};
|
|
18125
|
-
var format = opt_format ||
|
|
18126
|
+
var format = opt_format || path5.extname(object2).substr(1);
|
|
18126
18127
|
if (!format) {
|
|
18127
18128
|
throw new Error("Document format parameter required");
|
|
18128
18129
|
}
|
|
@@ -18362,10 +18363,10 @@ var require_tsdb_data_client = __commonJS({
|
|
|
18362
18363
|
params.authorization = authorization;
|
|
18363
18364
|
return util2.format("%s%s?%s", config.endpoint, resource, qs.encode(params));
|
|
18364
18365
|
};
|
|
18365
|
-
TsdbDataClient.prototype.createSignature = function(credentials, httpMethod,
|
|
18366
|
+
TsdbDataClient.prototype.createSignature = function(credentials, httpMethod, path5, params, headers) {
|
|
18366
18367
|
var auth = new Auth(credentials.ak, credentials.sk);
|
|
18367
18368
|
var headersToSign = ["host"];
|
|
18368
|
-
return auth.generateAuthorization(httpMethod,
|
|
18369
|
+
return auth.generateAuthorization(httpMethod, path5, params, headers, 0, 0, headersToSign);
|
|
18369
18370
|
};
|
|
18370
18371
|
TsdbDataClient.prototype.sendRequest = function(httpMethod, resource, varArgs) {
|
|
18371
18372
|
var defaultArgs = {
|
|
@@ -22686,7 +22687,7 @@ var require_bts_client = __commonJS({
|
|
|
22686
22687
|
var require_iot_client = __commonJS({
|
|
22687
22688
|
"node_modules/.pnpm/@baiducloud+sdk@1.0.7/node_modules/@baiducloud/sdk/src/iot_client.js"(exports$1, module) {
|
|
22688
22689
|
var util2 = __require("util");
|
|
22689
|
-
var
|
|
22690
|
+
var path5 = __require("path");
|
|
22690
22691
|
var u = (init_index_all(), __toCommonJS(index_all_exports));
|
|
22691
22692
|
var strings = require_strings();
|
|
22692
22693
|
var BceBaseClient = require_bce_base_client();
|
|
@@ -22748,7 +22749,7 @@ var require_iot_client = __commonJS({
|
|
|
22748
22749
|
};
|
|
22749
22750
|
IoTClient.prototype._buildUrl = function() {
|
|
22750
22751
|
var extraPaths = u.toArray(arguments);
|
|
22751
|
-
return
|
|
22752
|
+
return path5.normalize(extraPaths.join("/")).replace(/\\/g, "/");
|
|
22752
22753
|
};
|
|
22753
22754
|
module.exports = IoTClient;
|
|
22754
22755
|
}
|
|
@@ -22787,6 +22788,156 @@ var require_sdk = __commonJS({
|
|
|
22787
22788
|
}
|
|
22788
22789
|
});
|
|
22789
22790
|
|
|
22791
|
+
// src/auth/login.ts
|
|
22792
|
+
var login_exports = {};
|
|
22793
|
+
__export(login_exports, {
|
|
22794
|
+
loginBaiduApp: () => loginBaiduApp
|
|
22795
|
+
});
|
|
22796
|
+
function createTerminalPrompter() {
|
|
22797
|
+
const rl = readline.createInterface({
|
|
22798
|
+
input: process.stdin,
|
|
22799
|
+
output: process.stdout
|
|
22800
|
+
});
|
|
22801
|
+
const question = (message) => new Promise((resolve) => {
|
|
22802
|
+
rl.question(message, (answer) => resolve(answer));
|
|
22803
|
+
});
|
|
22804
|
+
return {
|
|
22805
|
+
select: async (message, choices) => {
|
|
22806
|
+
while (true) {
|
|
22807
|
+
process.stdout.write(`${message}
|
|
22808
|
+
`);
|
|
22809
|
+
for (const [index2, choice] of choices.entries()) {
|
|
22810
|
+
process.stdout.write(`${index2 + 1}. ${choice}
|
|
22811
|
+
`);
|
|
22812
|
+
}
|
|
22813
|
+
const answer = (await question("\u8BF7\u9009\u62E9\u5E8F\u53F7: ")).trim();
|
|
22814
|
+
const choiceIndex = Number(answer);
|
|
22815
|
+
if (Number.isInteger(choiceIndex) && choiceIndex >= 1 && choiceIndex <= choices.length) {
|
|
22816
|
+
return choices[choiceIndex - 1];
|
|
22817
|
+
}
|
|
22818
|
+
process.stdout.write(`\u8BF7\u8F93\u5165 1-${choices.length} \u4E4B\u95F4\u7684\u5E8F\u53F7\u3002
|
|
22819
|
+
`);
|
|
22820
|
+
}
|
|
22821
|
+
},
|
|
22822
|
+
text: async (message, opts) => {
|
|
22823
|
+
while (true) {
|
|
22824
|
+
const answer = (await question(`${message}: `)).trim();
|
|
22825
|
+
if (!opts?.required || answer) {
|
|
22826
|
+
return answer;
|
|
22827
|
+
}
|
|
22828
|
+
process.stdout.write("\u8BE5\u9879\u4E3A\u5FC5\u586B\uFF0C\u8BF7\u91CD\u65B0\u8F93\u5165\u3002\n");
|
|
22829
|
+
}
|
|
22830
|
+
},
|
|
22831
|
+
close: () => {
|
|
22832
|
+
rl.close();
|
|
22833
|
+
}
|
|
22834
|
+
};
|
|
22835
|
+
}
|
|
22836
|
+
function redactValue(value, opts) {
|
|
22837
|
+
if (!value) {
|
|
22838
|
+
return "(empty)";
|
|
22839
|
+
}
|
|
22840
|
+
const keepStart = opts?.keepStart ?? 2;
|
|
22841
|
+
const keepEnd = opts?.keepEnd ?? 2;
|
|
22842
|
+
if (value.length <= keepStart + keepEnd) {
|
|
22843
|
+
return "*".repeat(value.length);
|
|
22844
|
+
}
|
|
22845
|
+
return `${value.slice(0, keepStart)}***${value.slice(-keepEnd)}`;
|
|
22846
|
+
}
|
|
22847
|
+
function resolveOpenclawConfigPath() {
|
|
22848
|
+
const override = process.env["OPENCLAW_CONFIG_PATH"]?.trim();
|
|
22849
|
+
if (override) {
|
|
22850
|
+
return override;
|
|
22851
|
+
}
|
|
22852
|
+
const stateDir = process.env["OPENCLAW_STATE_DIR"]?.trim() ?? path2.join(os.homedir(), ".openclaw");
|
|
22853
|
+
return path2.join(stateDir, "openclaw.json");
|
|
22854
|
+
}
|
|
22855
|
+
function readOpenclawConfig(configPath) {
|
|
22856
|
+
try {
|
|
22857
|
+
const raw = fs.readFileSync(configPath, "utf8");
|
|
22858
|
+
const parsed = JSON.parse(raw);
|
|
22859
|
+
if (parsed !== null && typeof parsed === "object" && !Array.isArray(parsed)) {
|
|
22860
|
+
return parsed;
|
|
22861
|
+
}
|
|
22862
|
+
return {};
|
|
22863
|
+
} catch (err) {
|
|
22864
|
+
if (err instanceof Error && "code" in err && err.code === "ENOENT") {
|
|
22865
|
+
return {};
|
|
22866
|
+
}
|
|
22867
|
+
throw err;
|
|
22868
|
+
}
|
|
22869
|
+
}
|
|
22870
|
+
function writeOpenclawConfig(configPath, config) {
|
|
22871
|
+
const dir2 = path2.dirname(configPath);
|
|
22872
|
+
fs.mkdirSync(dir2, { recursive: true });
|
|
22873
|
+
const tmpPath = `${configPath}.tmp.${process.pid}`;
|
|
22874
|
+
const content = `${JSON.stringify(config, null, 2)}
|
|
22875
|
+
`;
|
|
22876
|
+
fs.writeFileSync(tmpPath, content, "utf8");
|
|
22877
|
+
fs.renameSync(tmpPath, configPath);
|
|
22878
|
+
}
|
|
22879
|
+
function setAccountConfig(params) {
|
|
22880
|
+
const config = readOpenclawConfig(params.configPath);
|
|
22881
|
+
const channels = config["channels"] !== null && typeof config["channels"] === "object" && !Array.isArray(config["channels"]) ? config["channels"] : {};
|
|
22882
|
+
const channelKey = "openclaw-baiduapp";
|
|
22883
|
+
const channelConfig = channels[channelKey] !== null && typeof channels[channelKey] === "object" && !Array.isArray(channels[channelKey]) ? channels[channelKey] : {};
|
|
22884
|
+
const accounts = channelConfig["accounts"] !== null && typeof channelConfig["accounts"] === "object" && !Array.isArray(channelConfig["accounts"]) ? channelConfig["accounts"] : {};
|
|
22885
|
+
const existingAccount = accounts[params.accountId] !== null && typeof accounts[params.accountId] === "object" && !Array.isArray(accounts[params.accountId]) ? accounts[params.accountId] : {};
|
|
22886
|
+
writeOpenclawConfig(params.configPath, {
|
|
22887
|
+
...config,
|
|
22888
|
+
channels: {
|
|
22889
|
+
...channels,
|
|
22890
|
+
[channelKey]: {
|
|
22891
|
+
...channelConfig,
|
|
22892
|
+
accounts: {
|
|
22893
|
+
...accounts,
|
|
22894
|
+
[params.accountId]: {
|
|
22895
|
+
...existingAccount,
|
|
22896
|
+
appKey: params.appKey,
|
|
22897
|
+
appSecret: params.appSecret,
|
|
22898
|
+
enabled: true
|
|
22899
|
+
}
|
|
22900
|
+
}
|
|
22901
|
+
}
|
|
22902
|
+
}
|
|
22903
|
+
});
|
|
22904
|
+
}
|
|
22905
|
+
async function loginBaiduApp(params) {
|
|
22906
|
+
void params.cfg;
|
|
22907
|
+
void params.verbose;
|
|
22908
|
+
const agentId = params.accountId?.trim() || "main";
|
|
22909
|
+
const prompter = createTerminalPrompter();
|
|
22910
|
+
try {
|
|
22911
|
+
const mode = await prompter.select("\u8BF7\u9009\u62E9\u767E\u5EA6 App \u914D\u7F6E\u65B9\u5F0F", [
|
|
22912
|
+
"\u624B\u52A8\u586B\u5199",
|
|
22913
|
+
"\u626B\u7801\u914D\u7F6E\uFF08\u5373\u5C06\u652F\u6301\uFF09"
|
|
22914
|
+
]);
|
|
22915
|
+
if (mode === "\u626B\u7801\u914D\u7F6E\uFF08\u5373\u5C06\u652F\u6301\uFF09") {
|
|
22916
|
+
params.runtime.log("\u23F3 \u626B\u7801\u914D\u7F6E\u529F\u80FD\u6B63\u5728\u5F00\u53D1\u4E2D\uFF0C\u656C\u8BF7\u671F\u5F85...");
|
|
22917
|
+
params.runtime.log("\u8BF7\u5148\u4F7F\u7528\u624B\u52A8\u586B\u5199\u65B9\u5F0F\u5B8C\u6210\u914D\u7F6E\u3002");
|
|
22918
|
+
return;
|
|
22919
|
+
}
|
|
22920
|
+
const appKey = await prompter.text("App Key", { required: true });
|
|
22921
|
+
const appSecret = await prompter.text("App Secret", { required: true });
|
|
22922
|
+
const configPath = resolveOpenclawConfigPath();
|
|
22923
|
+
setAccountConfig({ configPath, accountId: agentId, appKey, appSecret });
|
|
22924
|
+
params.runtime.log(`\u2705 openclaw-baiduapp \u5DF2\u5B8C\u6210\u914D\u7F6E\uFF08account: ${agentId}\uFF09`);
|
|
22925
|
+
params.runtime.log(`- appKey: ${redactValue(appKey, { keepStart: 3, keepEnd: 3 })}`);
|
|
22926
|
+
params.runtime.log(`- appSecret: ${redactValue(appSecret, { keepStart: 3, keepEnd: 3 })}`);
|
|
22927
|
+
params.runtime.log(`- \u914D\u7F6E\u5DF2\u5199\u5165: ${configPath}`);
|
|
22928
|
+
} catch (error) {
|
|
22929
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
22930
|
+
params.runtime.error(`openclaw-baiduapp \u767B\u5F55\u914D\u7F6E\u5931\u8D25\uFF1A${message}`);
|
|
22931
|
+
throw error;
|
|
22932
|
+
} finally {
|
|
22933
|
+
prompter.close();
|
|
22934
|
+
}
|
|
22935
|
+
}
|
|
22936
|
+
var init_login = __esm({
|
|
22937
|
+
"src/auth/login.ts"() {
|
|
22938
|
+
}
|
|
22939
|
+
});
|
|
22940
|
+
|
|
22790
22941
|
// node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/external.js
|
|
22791
22942
|
var external_exports = {};
|
|
22792
22943
|
__export(external_exports, {
|
|
@@ -23265,8 +23416,8 @@ function getErrorMap() {
|
|
|
23265
23416
|
|
|
23266
23417
|
// node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/helpers/parseUtil.js
|
|
23267
23418
|
var makeIssue = (params) => {
|
|
23268
|
-
const { data, path:
|
|
23269
|
-
const fullPath = [...
|
|
23419
|
+
const { data, path: path5, errorMaps, issueData } = params;
|
|
23420
|
+
const fullPath = [...path5, ...issueData.path || []];
|
|
23270
23421
|
const fullIssue = {
|
|
23271
23422
|
...issueData,
|
|
23272
23423
|
path: fullPath
|
|
@@ -23382,11 +23533,11 @@ var errorUtil;
|
|
|
23382
23533
|
|
|
23383
23534
|
// node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/types.js
|
|
23384
23535
|
var ParseInputLazyPath = class {
|
|
23385
|
-
constructor(parent2, value,
|
|
23536
|
+
constructor(parent2, value, path5, key) {
|
|
23386
23537
|
this._cachedPath = [];
|
|
23387
23538
|
this.parent = parent2;
|
|
23388
23539
|
this.data = value;
|
|
23389
|
-
this._path =
|
|
23540
|
+
this._path = path5;
|
|
23390
23541
|
this._key = key;
|
|
23391
23542
|
}
|
|
23392
23543
|
get path() {
|
|
@@ -26829,14 +26980,12 @@ var NEVER = INVALID;
|
|
|
26829
26980
|
|
|
26830
26981
|
// src/config.ts
|
|
26831
26982
|
var DEFAULT_ACCOUNT_ID = "default";
|
|
26983
|
+
var DEFAULT_AGENT_ID = "main";
|
|
26832
26984
|
var DEFAULT_API_BASE = "https://claw.baidu.com";
|
|
26833
26985
|
var BaiduAppAccountSchema = external_exports.object({
|
|
26834
26986
|
name: external_exports.string().optional(),
|
|
26835
26987
|
enabled: external_exports.boolean().optional(),
|
|
26836
|
-
pollingEnabled: external_exports.boolean().optional(),
|
|
26837
26988
|
webhookPath: external_exports.string().optional(),
|
|
26838
|
-
token: external_exports.string().optional(),
|
|
26839
|
-
encodingAESKey: external_exports.string().optional(),
|
|
26840
26989
|
appKey: external_exports.string().optional(),
|
|
26841
26990
|
appSecret: external_exports.string().optional(),
|
|
26842
26991
|
apiBase: external_exports.string().optional(),
|
|
@@ -26853,10 +27002,7 @@ var BaiduAppConfigJsonSchema = {
|
|
|
26853
27002
|
properties: {
|
|
26854
27003
|
name: { type: "string" },
|
|
26855
27004
|
enabled: { type: "boolean" },
|
|
26856
|
-
pollingEnabled: { type: "boolean" },
|
|
26857
27005
|
webhookPath: { type: "string" },
|
|
26858
|
-
token: { type: "string" },
|
|
26859
|
-
encodingAESKey: { type: "string" },
|
|
26860
27006
|
appKey: { type: "string" },
|
|
26861
27007
|
appSecret: { type: "string" },
|
|
26862
27008
|
apiBase: { type: "string" },
|
|
@@ -26870,10 +27016,7 @@ var BaiduAppConfigJsonSchema = {
|
|
|
26870
27016
|
properties: {
|
|
26871
27017
|
name: { type: "string" },
|
|
26872
27018
|
enabled: { type: "boolean" },
|
|
26873
|
-
pollingEnabled: { type: "boolean" },
|
|
26874
27019
|
webhookPath: { type: "string" },
|
|
26875
|
-
token: { type: "string" },
|
|
26876
|
-
encodingAESKey: { type: "string" },
|
|
26877
27020
|
appKey: { type: "string" },
|
|
26878
27021
|
appSecret: { type: "string" },
|
|
26879
27022
|
apiBase: { type: "string" },
|
|
@@ -26888,6 +27031,10 @@ function normalizeAccountId(raw) {
|
|
|
26888
27031
|
const trimmed = String(raw ?? "").trim();
|
|
26889
27032
|
return trimmed || DEFAULT_ACCOUNT_ID;
|
|
26890
27033
|
}
|
|
27034
|
+
function extractAgentId(msg) {
|
|
27035
|
+
const raw = msg.agentid ?? "";
|
|
27036
|
+
return raw.trim() || DEFAULT_AGENT_ID;
|
|
27037
|
+
}
|
|
26891
27038
|
function listConfiguredAccountIds(cfg) {
|
|
26892
27039
|
const accounts = cfg.channels?.["openclaw-baiduapp"]?.accounts;
|
|
26893
27040
|
if (!accounts || typeof accounts !== "object") {
|
|
@@ -26935,12 +27082,10 @@ function resolveBaiduAppAccount(params) {
|
|
|
26935
27082
|
const merged = mergeBaiduAppAccountConfig(params.cfg, accountId);
|
|
26936
27083
|
const enabled = baseEnabled && merged.enabled !== false;
|
|
26937
27084
|
const isDefaultAccount = accountId === DEFAULT_ACCOUNT_ID;
|
|
26938
|
-
const token = merged.token?.trim() || (isDefaultAccount ? process.env.BAIDU_APP_TOKEN?.trim() : void 0) || void 0;
|
|
26939
|
-
const encodingAESKey = merged.encodingAESKey?.trim() || (isDefaultAccount ? process.env.BAIDU_APP_ENCODING_AES_KEY?.trim() : void 0) || void 0;
|
|
26940
27085
|
const appKey = merged.appKey?.trim() || (isDefaultAccount ? process.env.BAIDU_APP_KEY?.trim() : void 0) || void 0;
|
|
26941
27086
|
const appSecret = merged.appSecret?.trim() || (isDefaultAccount ? process.env.BAIDU_APP_SECRET?.trim() : void 0) || void 0;
|
|
26942
|
-
const configured = Boolean(
|
|
26943
|
-
const canSendActive = Boolean(appKey && appSecret
|
|
27087
|
+
const configured = Boolean(appKey && appSecret);
|
|
27088
|
+
const canSendActive = Boolean(appKey && appSecret);
|
|
26944
27089
|
const rawApiBase = merged.apiBase?.trim() || (isDefaultAccount ? process.env.BAIDU_API_BASE?.trim() : void 0) || void 0;
|
|
26945
27090
|
const apiBase = (rawApiBase || DEFAULT_API_BASE).replace(/\/+$/, "");
|
|
26946
27091
|
return {
|
|
@@ -26948,8 +27093,6 @@ function resolveBaiduAppAccount(params) {
|
|
|
26948
27093
|
name: merged.name?.trim() || void 0,
|
|
26949
27094
|
enabled,
|
|
26950
27095
|
configured,
|
|
26951
|
-
token,
|
|
26952
|
-
encodingAESKey,
|
|
26953
27096
|
appKey,
|
|
26954
27097
|
appSecret,
|
|
26955
27098
|
apiBase,
|
|
@@ -26957,6 +27100,37 @@ function resolveBaiduAppAccount(params) {
|
|
|
26957
27100
|
config: merged
|
|
26958
27101
|
};
|
|
26959
27102
|
}
|
|
27103
|
+
function resolveAgentField(agentCfg, mainCfg, baseAccount, field) {
|
|
27104
|
+
return agentCfg?.[field]?.trim() || mainCfg?.[field]?.trim() || baseAccount[field];
|
|
27105
|
+
}
|
|
27106
|
+
function resolveAgentAccount(params) {
|
|
27107
|
+
const { baseAccount, cfg, agentId } = params;
|
|
27108
|
+
if (agentId === baseAccount.accountId) {
|
|
27109
|
+
return baseAccount;
|
|
27110
|
+
}
|
|
27111
|
+
const accounts = cfg.channels?.["openclaw-baiduapp"]?.accounts;
|
|
27112
|
+
const agentCfg = accounts?.[agentId] && typeof accounts[agentId] === "object" ? accounts[agentId] : void 0;
|
|
27113
|
+
const mainCfg = agentId !== DEFAULT_AGENT_ID && accounts?.[DEFAULT_AGENT_ID] && typeof accounts[DEFAULT_AGENT_ID] === "object" ? accounts[DEFAULT_AGENT_ID] : void 0;
|
|
27114
|
+
const appKey = resolveAgentField(agentCfg, mainCfg, baseAccount, "appKey");
|
|
27115
|
+
const appSecret = resolveAgentField(agentCfg, mainCfg, baseAccount, "appSecret");
|
|
27116
|
+
const apiBase = baseAccount.apiBase;
|
|
27117
|
+
const name = resolveAgentField(agentCfg, mainCfg, baseAccount, "name");
|
|
27118
|
+
const configured = Boolean(appKey && appSecret);
|
|
27119
|
+
const canSendActive = Boolean(appKey && appSecret);
|
|
27120
|
+
const agentEnabled = agentCfg?.enabled !== false;
|
|
27121
|
+
return {
|
|
27122
|
+
...baseAccount,
|
|
27123
|
+
accountId: agentId,
|
|
27124
|
+
name: name || baseAccount.name,
|
|
27125
|
+
enabled: agentEnabled && baseAccount.enabled,
|
|
27126
|
+
configured,
|
|
27127
|
+
appKey,
|
|
27128
|
+
appSecret,
|
|
27129
|
+
apiBase,
|
|
27130
|
+
canSendActive,
|
|
27131
|
+
config: { ...baseAccount.config, ...mainCfg ?? {}, ...agentCfg ?? {} }
|
|
27132
|
+
};
|
|
27133
|
+
}
|
|
26960
27134
|
|
|
26961
27135
|
// src/shared/logger.ts
|
|
26962
27136
|
function createLogger(prefix, opts) {
|
|
@@ -26969,135 +27143,85 @@ function createLogger(prefix, opts) {
|
|
|
26969
27143
|
error: (msg) => errorFn(`[${prefix}] [ERROR] ${msg}`)
|
|
26970
27144
|
};
|
|
26971
27145
|
}
|
|
26972
|
-
function decodeEncodingAESKey(encodingAESKey) {
|
|
26973
|
-
const trimmed = encodingAESKey.trim();
|
|
26974
|
-
if (!trimmed) {
|
|
26975
|
-
throw new Error("encodingAESKey missing");
|
|
26976
|
-
}
|
|
26977
|
-
const withPadding = trimmed.endsWith("=") ? trimmed : `${trimmed}=`;
|
|
26978
|
-
const key = Buffer.from(withPadding, "base64");
|
|
26979
|
-
if (key.length !== 32) {
|
|
26980
|
-
throw new Error(`invalid encodingAESKey (expected 32 bytes after base64 decode, got ${key.length})`);
|
|
26981
|
-
}
|
|
26982
|
-
return key;
|
|
26983
|
-
}
|
|
26984
|
-
var PKCS7_BLOCK_SIZE = 32;
|
|
26985
|
-
function pkcs7Pad(buf, blockSize) {
|
|
26986
|
-
const mod = buf.length % blockSize;
|
|
26987
|
-
const pad = mod === 0 ? blockSize : blockSize - mod;
|
|
26988
|
-
return Buffer.concat([buf, Buffer.alloc(pad, pad)]);
|
|
26989
|
-
}
|
|
26990
|
-
function pkcs7Unpad(buf, blockSize) {
|
|
26991
|
-
if (buf.length === 0) {
|
|
26992
|
-
throw new Error("invalid pkcs7 payload");
|
|
26993
|
-
}
|
|
26994
|
-
const pad = buf[buf.length - 1];
|
|
26995
|
-
if (!pad || pad < 1 || pad > blockSize || pad > buf.length) {
|
|
26996
|
-
throw new Error("invalid pkcs7 padding");
|
|
26997
|
-
}
|
|
26998
|
-
for (let i = 1; i <= pad; i += 1) {
|
|
26999
|
-
if (buf[buf.length - i] !== pad) {
|
|
27000
|
-
throw new Error("invalid pkcs7 padding");
|
|
27001
|
-
}
|
|
27002
|
-
}
|
|
27003
|
-
return buf.subarray(0, buf.length - pad);
|
|
27004
|
-
}
|
|
27005
27146
|
function sha1Hex(input) {
|
|
27006
|
-
return
|
|
27147
|
+
return crypto.createHash("sha1").update(input).digest("hex");
|
|
27007
27148
|
}
|
|
27008
|
-
function
|
|
27009
|
-
|
|
27010
|
-
return sha1Hex(parts.join(""));
|
|
27149
|
+
function computeAKSKBearerToken(params) {
|
|
27150
|
+
return sha1Hex(params.ak + params.sk + params.timestamp + params.nonce);
|
|
27011
27151
|
}
|
|
27012
|
-
function
|
|
27013
|
-
const expected =
|
|
27014
|
-
|
|
27152
|
+
function verifyAKSKBearerToken(params) {
|
|
27153
|
+
const expected = computeAKSKBearerToken({
|
|
27154
|
+
ak: params.ak,
|
|
27155
|
+
sk: params.sk,
|
|
27015
27156
|
timestamp: params.timestamp,
|
|
27016
|
-
nonce: params.nonce
|
|
27017
|
-
encrypt: params.encrypt
|
|
27157
|
+
nonce: params.nonce
|
|
27018
27158
|
});
|
|
27019
|
-
return expected === params.
|
|
27020
|
-
}
|
|
27021
|
-
function
|
|
27022
|
-
|
|
27023
|
-
const iv = aesKey.subarray(0, 16);
|
|
27024
|
-
const decipher = crypto3.createDecipheriv("aes-256-cbc", aesKey, iv);
|
|
27025
|
-
decipher.setAutoPadding(false);
|
|
27026
|
-
const decryptedPadded = Buffer.concat([decipher.update(Buffer.from(params.encrypt, "base64")), decipher.final()]);
|
|
27027
|
-
const decrypted = pkcs7Unpad(decryptedPadded, PKCS7_BLOCK_SIZE);
|
|
27028
|
-
if (decrypted.length < 20) {
|
|
27029
|
-
throw new Error(`invalid decrypted payload (expected at least 20 bytes, got ${decrypted.length})`);
|
|
27030
|
-
}
|
|
27031
|
-
const msgLen = decrypted.readUInt32BE(16);
|
|
27032
|
-
const msgStart = 20;
|
|
27033
|
-
const msgEnd = msgStart + msgLen;
|
|
27034
|
-
if (msgEnd > decrypted.length) {
|
|
27035
|
-
throw new Error(`invalid decrypted msg length (msgEnd=${msgEnd}, payloadLength=${decrypted.length})`);
|
|
27036
|
-
}
|
|
27037
|
-
return decrypted.subarray(msgStart, msgEnd).toString("utf8");
|
|
27038
|
-
}
|
|
27039
|
-
function encryptBaiduAppPlaintext(params) {
|
|
27040
|
-
const aesKey = decodeEncodingAESKey(params.encodingAESKey);
|
|
27041
|
-
const iv = aesKey.subarray(0, 16);
|
|
27042
|
-
const random16 = crypto3.randomBytes(16);
|
|
27043
|
-
const msg = Buffer.from(params.plaintext ?? "", "utf8");
|
|
27044
|
-
const msgLen = Buffer.alloc(4);
|
|
27045
|
-
msgLen.writeUInt32BE(msg.length, 0);
|
|
27046
|
-
const raw = Buffer.concat([random16, msgLen, msg]);
|
|
27047
|
-
const padded = pkcs7Pad(raw, PKCS7_BLOCK_SIZE);
|
|
27048
|
-
const cipher = crypto3.createCipheriv("aes-256-cbc", aesKey, iv);
|
|
27049
|
-
cipher.setAutoPadding(false);
|
|
27050
|
-
const encrypted = Buffer.concat([cipher.update(padded), cipher.final()]);
|
|
27051
|
-
return encrypted.toString("base64");
|
|
27159
|
+
return expected === params.token;
|
|
27160
|
+
}
|
|
27161
|
+
function generateNonce() {
|
|
27162
|
+
return crypto.randomBytes(8).toString("hex");
|
|
27052
27163
|
}
|
|
27164
|
+
function buildAuthorizationHeader(params) {
|
|
27165
|
+
const token = computeAKSKBearerToken(params);
|
|
27166
|
+
return `Bearer ${token}`;
|
|
27167
|
+
}
|
|
27168
|
+
|
|
27169
|
+
// src/types.ts
|
|
27170
|
+
var DEFAULT_BAIDU_APP_SESSION_ID = "agent:main:main";
|
|
27053
27171
|
var require2 = createRequire(import.meta.url);
|
|
27054
27172
|
var pkg = require2("../package.json");
|
|
27055
27173
|
var PLUGIN_VERSION = pkg.version;
|
|
27056
27174
|
|
|
27057
27175
|
// src/api.ts
|
|
27058
27176
|
var logger = createLogger("openclaw-baiduapp");
|
|
27177
|
+
var DEFAULT_sessionId = DEFAULT_BAIDU_APP_SESSION_ID;
|
|
27059
27178
|
async function sendBaiduAppMessage(account, message, options) {
|
|
27060
27179
|
if (!account.canSendActive) {
|
|
27061
|
-
logger.error("Account not configured for active sending (missing appKey
|
|
27180
|
+
logger.error("Account not configured for active sending (missing appKey or appSecret)");
|
|
27062
27181
|
return {
|
|
27063
27182
|
ok: false,
|
|
27064
27183
|
errcode: -1,
|
|
27065
|
-
errmsg: "Account not configured for active sending (missing appKey
|
|
27184
|
+
errmsg: "Account not configured for active sending (missing appKey or appSecret)"
|
|
27066
27185
|
};
|
|
27067
27186
|
}
|
|
27068
27187
|
const normalizedPayload = typeof message === "string" ? {
|
|
27069
|
-
|
|
27070
|
-
|
|
27188
|
+
list: [{
|
|
27189
|
+
type: "text",
|
|
27190
|
+
data: {
|
|
27191
|
+
text: { content: message }
|
|
27192
|
+
}
|
|
27193
|
+
}]
|
|
27071
27194
|
} : message;
|
|
27072
|
-
const
|
|
27073
|
-
|
|
27195
|
+
const sessionId = options?.sessionId ?? DEFAULT_sessionId;
|
|
27196
|
+
const callbackBody = {
|
|
27197
|
+
sessionId,
|
|
27198
|
+
list: normalizedPayload.list,
|
|
27074
27199
|
version: PLUGIN_VERSION,
|
|
27075
|
-
|
|
27076
|
-
...options?.
|
|
27077
|
-
...options?.chunkKey != null ? { chunkKey: options.chunkKey } : {}
|
|
27200
|
+
isActive: options?.isActive || false,
|
|
27201
|
+
...options?.agentid ? { agentid: options.agentid } : {},
|
|
27202
|
+
...options?.chunkKey != null ? { chunkKey: options.chunkKey } : {},
|
|
27203
|
+
...options?.replyToMsgId ? { replyToMsgId: options.replyToMsgId } : {}
|
|
27078
27204
|
};
|
|
27079
|
-
const plaintext = JSON.stringify(payload);
|
|
27080
|
-
const encrypt = encryptBaiduAppPlaintext({
|
|
27081
|
-
encodingAESKey: account.encodingAESKey ?? "",
|
|
27082
|
-
plaintext
|
|
27083
|
-
});
|
|
27084
27205
|
const timestamp = String(Math.floor(Date.now() / 1e3));
|
|
27085
|
-
const nonce =
|
|
27086
|
-
const
|
|
27087
|
-
|
|
27206
|
+
const nonce = generateNonce();
|
|
27207
|
+
const authorization = buildAuthorizationHeader({
|
|
27208
|
+
ak: account.appKey ?? "",
|
|
27209
|
+
sk: account.appSecret ?? "",
|
|
27088
27210
|
timestamp,
|
|
27089
|
-
nonce
|
|
27090
|
-
encrypt
|
|
27211
|
+
nonce
|
|
27091
27212
|
});
|
|
27092
|
-
const sendMessageUrl = `${account.apiBase}/
|
|
27093
|
-
const url = `${sendMessageUrl}?timestamp=${encodeURIComponent(timestamp)}&ak=${encodeURIComponent(account.appKey ?? "")}&nonce=${encodeURIComponent(nonce)}
|
|
27094
|
-
const body = JSON.stringify(
|
|
27213
|
+
const sendMessageUrl = `${account.apiBase}/channel/msg/callback`;
|
|
27214
|
+
const url = `${sendMessageUrl}?timestamp=${encodeURIComponent(timestamp)}&ak=${encodeURIComponent(account.appKey ?? "")}&nonce=${encodeURIComponent(nonce)}`;
|
|
27215
|
+
const body = JSON.stringify(callbackBody);
|
|
27095
27216
|
logger.info(`POST ${url}`);
|
|
27096
27217
|
logger.debug(`request body: ${body}`);
|
|
27097
27218
|
const resp = await fetch(url, {
|
|
27098
27219
|
method: "POST",
|
|
27099
27220
|
body,
|
|
27100
|
-
headers: {
|
|
27221
|
+
headers: {
|
|
27222
|
+
"Authorization": authorization,
|
|
27223
|
+
"Content-Type": "application/json"
|
|
27224
|
+
}
|
|
27101
27225
|
});
|
|
27102
27226
|
const text = await resp.text();
|
|
27103
27227
|
if (!text) {
|
|
@@ -27113,6 +27237,15 @@ async function sendBaiduAppMessage(account, message, options) {
|
|
|
27113
27237
|
logger.error(`request failed: ${errmsg}`);
|
|
27114
27238
|
return { ok: false, errcode: resp.status, errmsg };
|
|
27115
27239
|
}
|
|
27240
|
+
if (data.code !== 0) {
|
|
27241
|
+
const errmsg = data.msg ?? `channel callback failed with code ${String(data.code)}`;
|
|
27242
|
+
logger.error(`request failed: ${errmsg}`);
|
|
27243
|
+
return {
|
|
27244
|
+
ok: false,
|
|
27245
|
+
errcode: data.code,
|
|
27246
|
+
errmsg
|
|
27247
|
+
};
|
|
27248
|
+
}
|
|
27116
27249
|
const result2 = {
|
|
27117
27250
|
ok: true
|
|
27118
27251
|
};
|
|
@@ -27138,21 +27271,21 @@ function buildMediaPayload(mediaList, opts) {
|
|
|
27138
27271
|
|
|
27139
27272
|
// src/bot.ts
|
|
27140
27273
|
function extractBaiduAppTextContent(msg) {
|
|
27141
|
-
const msgtype = String(msg.msgtype ??
|
|
27274
|
+
const msgtype = String(msg.msgtype ?? "").toLowerCase();
|
|
27142
27275
|
if (msgtype === "text") {
|
|
27143
|
-
const content = msg.text?.content
|
|
27276
|
+
const content = msg.text?.content;
|
|
27144
27277
|
return typeof content === "string" ? content : "";
|
|
27145
27278
|
}
|
|
27146
27279
|
if (msgtype === "event") {
|
|
27147
27280
|
const eventtype = String(
|
|
27148
|
-
msg.event?.eventtype ??
|
|
27281
|
+
msg.event?.eventtype ?? ""
|
|
27149
27282
|
).trim();
|
|
27150
27283
|
return eventtype ? `[event] ${eventtype}` : "[event]";
|
|
27151
27284
|
}
|
|
27152
27285
|
return msgtype ? `[${msgtype}]` : "";
|
|
27153
27286
|
}
|
|
27154
27287
|
function canDispatchBaiduAppInboundMessage(msg) {
|
|
27155
|
-
const msgtype = String(msg.msgtype ??
|
|
27288
|
+
const msgtype = String(msg.msgtype ?? "").toLowerCase();
|
|
27156
27289
|
if (msgtype === "text") {
|
|
27157
27290
|
if (extractBaiduAppTextContent(msg)) {
|
|
27158
27291
|
return true;
|
|
@@ -27222,7 +27355,7 @@ async function dispatchBaiduAppMessage(params) {
|
|
|
27222
27355
|
cfg: safeCfg,
|
|
27223
27356
|
channel: "openclaw-baiduapp",
|
|
27224
27357
|
accountId: account.accountId,
|
|
27225
|
-
peer: { kind: "dm", id:
|
|
27358
|
+
peer: { kind: "dm", id: account.accountId || DEFAULT_AGENT_ID }
|
|
27226
27359
|
});
|
|
27227
27360
|
logger3.info(`SessionKey: ${route.sessionKey}`);
|
|
27228
27361
|
logger3.info(
|
|
@@ -27252,7 +27385,7 @@ async function dispatchBaiduAppMessage(params) {
|
|
|
27252
27385
|
envelope: envelopeOptions,
|
|
27253
27386
|
body: rawBody
|
|
27254
27387
|
}) : rawBody;
|
|
27255
|
-
const msgid = msg.msgid ??
|
|
27388
|
+
const msgid = msg.msgid ?? void 0;
|
|
27256
27389
|
const ctxPayload = channel.reply?.finalizeInboundContext ? channel.reply.finalizeInboundContext({
|
|
27257
27390
|
Body: body,
|
|
27258
27391
|
RawBody: rawBody,
|
|
@@ -27459,92 +27592,122 @@ var DEFAULT_DOWNLOAD_MAX_BYTES = 20 * 1024 * 1024;
|
|
|
27459
27592
|
path2.join("openclaw-baiduapp", "media");
|
|
27460
27593
|
var DefaultBosClient = import_sdk.default.BosClient;
|
|
27461
27594
|
var MAX_DOWNLOAD_REDIRECTS = 5;
|
|
27462
|
-
|
|
27463
|
-
|
|
27464
|
-
|
|
27465
|
-
|
|
27466
|
-
|
|
27467
|
-
|
|
27468
|
-
|
|
27469
|
-
|
|
27470
|
-
|
|
27471
|
-
|
|
27472
|
-
|
|
27473
|
-
|
|
27474
|
-
|
|
27475
|
-
|
|
27476
|
-
const
|
|
27477
|
-
const
|
|
27478
|
-
if (!
|
|
27479
|
-
throw new Error(
|
|
27480
|
-
}
|
|
27481
|
-
let payload;
|
|
27482
|
-
try {
|
|
27483
|
-
payload = await response.json();
|
|
27484
|
-
} catch (error) {
|
|
27485
|
-
throw new Error(`SKS response is not valid JSON: ${formatError(error)}`, { cause: error });
|
|
27486
|
-
}
|
|
27487
|
-
return parseSksCredentialsFromPayload(payload);
|
|
27488
|
-
}
|
|
27489
|
-
function parseSksCredentialsFromPayload(payload) {
|
|
27490
|
-
const parsed = parseSksResponse(payload);
|
|
27491
|
-
if (parsed.status !== 0) {
|
|
27492
|
-
throw new Error(`SKS request failed with status ${parsed.status}`);
|
|
27595
|
+
async function fetchFileUploadSts(options, deps = {}) {
|
|
27596
|
+
assertAccountCanUseChannelApi(options.account);
|
|
27597
|
+
const responsePayload = await postAuthenticatedChannelJson(
|
|
27598
|
+
options.account,
|
|
27599
|
+
"/channel/file/sts",
|
|
27600
|
+
{
|
|
27601
|
+
sessionId: options.sessionId ?? DEFAULT_BAIDU_APP_SESSION_ID,
|
|
27602
|
+
filename: requireSafeDisplayFileName(options.filename),
|
|
27603
|
+
fileSize: options.fileSize,
|
|
27604
|
+
fileType: normalizeOutboundFileType(options.fileType),
|
|
27605
|
+
...options.md5 ? { md5: options.md5 } : {}
|
|
27606
|
+
},
|
|
27607
|
+
deps
|
|
27608
|
+
);
|
|
27609
|
+
const envelope = parseChannelEnvelope(responsePayload, "file STS");
|
|
27610
|
+
const data = envelope.data;
|
|
27611
|
+
if (!data) {
|
|
27612
|
+
throw new Error("file STS response missing data");
|
|
27493
27613
|
}
|
|
27494
|
-
|
|
27495
|
-
|
|
27614
|
+
const fileId = requireNonEmptyString(data.fileId, "file STS data.fileId");
|
|
27615
|
+
const reuse = requireBoolean(data.reuse, "file STS data.reuse");
|
|
27616
|
+
if (reuse) {
|
|
27617
|
+
return { fileId, reuse };
|
|
27496
27618
|
}
|
|
27497
27619
|
return {
|
|
27498
|
-
|
|
27499
|
-
|
|
27500
|
-
|
|
27501
|
-
|
|
27502
|
-
|
|
27503
|
-
|
|
27620
|
+
fileId,
|
|
27621
|
+
reuse,
|
|
27622
|
+
sts: parseFileUploadStsCredentials(data.sts),
|
|
27623
|
+
bceUrl: requireNonEmptyString(data.bceUrl, "file STS data.bceUrl"),
|
|
27624
|
+
bucket: requireNonEmptyString(data.bucket, "file STS data.bucket"),
|
|
27625
|
+
bosName: requireNonEmptyString(data.bosName, "file STS data.bosName")
|
|
27504
27626
|
};
|
|
27505
27627
|
}
|
|
27506
|
-
function
|
|
27507
|
-
|
|
27508
|
-
|
|
27509
|
-
|
|
27510
|
-
|
|
27511
|
-
|
|
27628
|
+
async function notifyFileUploadComplete(options, deps = {}) {
|
|
27629
|
+
assertAccountCanUseChannelApi(options.account);
|
|
27630
|
+
if (options.fileIds.length === 0) {
|
|
27631
|
+
throw new Error("file complete requires at least one fileId");
|
|
27632
|
+
}
|
|
27633
|
+
const responsePayload = await postAuthenticatedChannelJson(
|
|
27634
|
+
options.account,
|
|
27635
|
+
"/channel/file/complete",
|
|
27636
|
+
{
|
|
27637
|
+
sessionId: options.sessionId ?? DEFAULT_BAIDU_APP_SESSION_ID,
|
|
27638
|
+
fileIds: options.fileIds
|
|
27639
|
+
},
|
|
27640
|
+
deps
|
|
27641
|
+
);
|
|
27642
|
+
const envelope = parseChannelEnvelope(responsePayload, "file complete");
|
|
27643
|
+
const files = extractCompleteFiles(envelope.data);
|
|
27644
|
+
const fileIds = new Set(options.fileIds);
|
|
27645
|
+
for (const file of files) {
|
|
27646
|
+
if (!fileIds.has(file.fileId)) {
|
|
27647
|
+
continue;
|
|
27648
|
+
}
|
|
27649
|
+
if (file.status === -1) {
|
|
27650
|
+
throw new Error(`file complete failed for fileId ${file.fileId}`);
|
|
27651
|
+
}
|
|
27652
|
+
}
|
|
27653
|
+
return { files };
|
|
27512
27654
|
}
|
|
27513
|
-
function createBosClient(
|
|
27655
|
+
function createBosClient(fileSts, deps = {}) {
|
|
27656
|
+
if (!fileSts.sts || !fileSts.bceUrl) {
|
|
27657
|
+
throw new Error("Cannot create BOS client without STS credentials");
|
|
27658
|
+
}
|
|
27514
27659
|
const BosClientCtor = deps.bosClientCtor ?? DefaultBosClient;
|
|
27515
27660
|
return new BosClientCtor({
|
|
27516
|
-
endpoint:
|
|
27517
|
-
sessionToken:
|
|
27661
|
+
endpoint: fileSts.bceUrl,
|
|
27662
|
+
sessionToken: fileSts.sts.token,
|
|
27518
27663
|
credentials: {
|
|
27519
|
-
ak:
|
|
27520
|
-
sk:
|
|
27664
|
+
ak: fileSts.sts.ak,
|
|
27665
|
+
sk: fileSts.sts.sk
|
|
27521
27666
|
}
|
|
27522
27667
|
});
|
|
27523
27668
|
}
|
|
27524
27669
|
async function uploadLocalFileToBos(options, deps = {}) {
|
|
27525
27670
|
const localFile = await assertUploadableLocalFile(options.filePath);
|
|
27526
|
-
const credentials = await fetchSksCredentials(options.account, deps);
|
|
27527
|
-
const client = createBosClient(credentials, deps);
|
|
27528
27671
|
const sourceName = options.fileName ?? path2.basename(localFile);
|
|
27529
|
-
const
|
|
27530
|
-
const
|
|
27531
|
-
|
|
27532
|
-
|
|
27533
|
-
|
|
27534
|
-
|
|
27535
|
-
|
|
27536
|
-
|
|
27537
|
-
|
|
27538
|
-
|
|
27539
|
-
|
|
27540
|
-
|
|
27541
|
-
|
|
27672
|
+
const fileName = requireSafeDisplayFileName(sourceName);
|
|
27673
|
+
const [fileBuffer, fileStat] = await Promise.all([fs2.readFile(localFile), fs2.stat(localFile)]);
|
|
27674
|
+
const md5 = crypto.createHash("md5").update(fileBuffer).digest("hex");
|
|
27675
|
+
const fileType = inferOutboundFileType(fileName);
|
|
27676
|
+
const fileSts = await fetchFileUploadSts(
|
|
27677
|
+
{
|
|
27678
|
+
account: options.account,
|
|
27679
|
+
sessionId: options.sessionId,
|
|
27680
|
+
filename: fileName,
|
|
27681
|
+
fileSize: fileStat.size,
|
|
27682
|
+
fileType,
|
|
27683
|
+
md5
|
|
27684
|
+
},
|
|
27685
|
+
deps
|
|
27686
|
+
);
|
|
27687
|
+
if (!fileSts.reuse) {
|
|
27688
|
+
const bucketName = requireNonEmptyString(fileSts.bucket, "file STS bucket");
|
|
27689
|
+
const key = requireNonEmptyString(fileSts.bosName, "file STS bosName");
|
|
27690
|
+
const client = createBosClient(fileSts, deps);
|
|
27691
|
+
const uploadOptions = options.contentType?.trim() ? {
|
|
27692
|
+
"Content-Type": options.contentType.trim()
|
|
27693
|
+
} : void 0;
|
|
27694
|
+
await client.putObjectFromFile(bucketName, key, localFile, uploadOptions);
|
|
27695
|
+
}
|
|
27696
|
+
await notifyFileUploadComplete(
|
|
27697
|
+
{
|
|
27698
|
+
account: options.account,
|
|
27699
|
+
sessionId: options.sessionId,
|
|
27700
|
+
fileIds: [fileSts.fileId]
|
|
27701
|
+
},
|
|
27702
|
+
deps
|
|
27703
|
+
);
|
|
27542
27704
|
return {
|
|
27543
|
-
|
|
27544
|
-
|
|
27545
|
-
|
|
27546
|
-
fileName
|
|
27547
|
-
fileSize: fileStat.size
|
|
27705
|
+
fileId: fileSts.fileId,
|
|
27706
|
+
bucketName: fileSts.bucket,
|
|
27707
|
+
key: fileSts.bosName,
|
|
27708
|
+
fileName,
|
|
27709
|
+
fileSize: fileStat.size,
|
|
27710
|
+
reuse: fileSts.reuse
|
|
27548
27711
|
};
|
|
27549
27712
|
}
|
|
27550
27713
|
async function downloadInboundFileToTemp(options, deps = {}) {
|
|
@@ -27642,38 +27805,93 @@ async function pruneExpiredTempFiles(deps = {}) {
|
|
|
27642
27805
|
await walk(tempDir);
|
|
27643
27806
|
return { deletedFiles };
|
|
27644
27807
|
}
|
|
27645
|
-
function
|
|
27808
|
+
async function postAuthenticatedChannelJson(account, pathname, bodyPayload, deps) {
|
|
27809
|
+
const fetchImpl = deps.fetchImpl ?? fetch;
|
|
27810
|
+
const now = deps.now?.() ?? /* @__PURE__ */ new Date();
|
|
27811
|
+
const timestamp = String(Math.floor(now.getTime() / 1e3));
|
|
27812
|
+
const nonce = (deps.generateNonceImpl ?? generateNonce)();
|
|
27813
|
+
const authorization = buildAuthorizationHeader({
|
|
27814
|
+
ak: account.appKey ?? "",
|
|
27815
|
+
sk: account.appSecret ?? "",
|
|
27816
|
+
timestamp,
|
|
27817
|
+
nonce
|
|
27818
|
+
});
|
|
27819
|
+
const url = new URL(`${account.apiBase.replace(/\/+$/, "")}${pathname}`);
|
|
27820
|
+
url.searchParams.set("ak", account.appKey ?? "");
|
|
27821
|
+
url.searchParams.set("timestamp", timestamp);
|
|
27822
|
+
url.searchParams.set("nonce", nonce);
|
|
27823
|
+
const response = await fetchImpl(url.toString(), {
|
|
27824
|
+
method: "POST",
|
|
27825
|
+
headers: {
|
|
27826
|
+
"Authorization": authorization,
|
|
27827
|
+
"Content-Type": "application/json"
|
|
27828
|
+
},
|
|
27829
|
+
body: JSON.stringify(bodyPayload)
|
|
27830
|
+
});
|
|
27831
|
+
if (!response.ok) {
|
|
27832
|
+
throw new Error(`channel request failed with HTTP ${response.status}`);
|
|
27833
|
+
}
|
|
27834
|
+
try {
|
|
27835
|
+
return await response.json();
|
|
27836
|
+
} catch (error) {
|
|
27837
|
+
throw new Error(`channel response is not valid JSON: ${formatError(error)}`, { cause: error });
|
|
27838
|
+
}
|
|
27839
|
+
}
|
|
27840
|
+
function parseChannelEnvelope(payload, label) {
|
|
27646
27841
|
if (!payload || typeof payload !== "object") {
|
|
27647
|
-
throw new Error(
|
|
27842
|
+
throw new Error(`${label} response must be an object`);
|
|
27648
27843
|
}
|
|
27649
27844
|
const record = payload;
|
|
27650
|
-
const
|
|
27845
|
+
const code = record.code;
|
|
27846
|
+
if (typeof code !== "number") {
|
|
27847
|
+
throw new Error(`${label} response missing numeric code`);
|
|
27848
|
+
}
|
|
27849
|
+
if (code !== 0) {
|
|
27850
|
+
const msg = typeof record.msg === "string" ? record.msg : "unknown error";
|
|
27851
|
+
throw new Error(`${label} request failed with code ${code}: ${msg}`);
|
|
27852
|
+
}
|
|
27651
27853
|
const data = record.data;
|
|
27652
27854
|
return {
|
|
27653
|
-
|
|
27654
|
-
|
|
27655
|
-
|
|
27656
|
-
sk: data.sk,
|
|
27657
|
-
token: data.token,
|
|
27658
|
-
bucketName: data.bucketName,
|
|
27659
|
-
preFixPath: data.preFixPath,
|
|
27660
|
-
bceUrl: data.bceUrl
|
|
27661
|
-
} : void 0
|
|
27855
|
+
code,
|
|
27856
|
+
msg: typeof record.msg === "string" ? record.msg : void 0,
|
|
27857
|
+
data: data && typeof data === "object" ? data : void 0
|
|
27662
27858
|
};
|
|
27663
27859
|
}
|
|
27664
|
-
function
|
|
27665
|
-
|
|
27860
|
+
function parseFileUploadStsCredentials(payload) {
|
|
27861
|
+
if (!payload || typeof payload !== "object") {
|
|
27862
|
+
throw new Error("file STS data.sts is required");
|
|
27863
|
+
}
|
|
27864
|
+
const record = payload;
|
|
27865
|
+
return {
|
|
27866
|
+
ak: requireNonEmptyString(record.ak, "file STS data.sts.ak"),
|
|
27867
|
+
sk: requireNonEmptyString(record.sk, "file STS data.sts.sk"),
|
|
27868
|
+
token: requireNonEmptyString(record.token, "file STS data.sts.token"),
|
|
27869
|
+
expireAt: requireNumber(record.expireAt, "file STS data.sts.expireAt")
|
|
27870
|
+
};
|
|
27666
27871
|
}
|
|
27667
|
-
function
|
|
27668
|
-
const
|
|
27669
|
-
|
|
27670
|
-
|
|
27671
|
-
|
|
27672
|
-
|
|
27872
|
+
function extractCompleteFiles(payload) {
|
|
27873
|
+
const files = payload?.files;
|
|
27874
|
+
if (!Array.isArray(files)) {
|
|
27875
|
+
return [];
|
|
27876
|
+
}
|
|
27877
|
+
return files.map((file, index2) => {
|
|
27878
|
+
if (!file || typeof file !== "object") {
|
|
27879
|
+
throw new Error(`file complete data.files[${index2}] must be an object`);
|
|
27673
27880
|
}
|
|
27674
|
-
|
|
27881
|
+
const record = file;
|
|
27882
|
+
return {
|
|
27883
|
+
fileId: requireNonEmptyString(record.fileId, `file complete data.files[${index2}].fileId`),
|
|
27884
|
+
status: requireNumber(record.status, `file complete data.files[${index2}].status`)
|
|
27885
|
+
};
|
|
27675
27886
|
});
|
|
27676
|
-
|
|
27887
|
+
}
|
|
27888
|
+
function assertAccountCanUseChannelApi(account) {
|
|
27889
|
+
if (!account.appKey?.trim()) {
|
|
27890
|
+
throw new Error("Cannot call channel API without account.appKey");
|
|
27891
|
+
}
|
|
27892
|
+
if (!account.appSecret?.trim()) {
|
|
27893
|
+
throw new Error("Cannot call channel API without account.appSecret");
|
|
27894
|
+
}
|
|
27677
27895
|
}
|
|
27678
27896
|
function requireNonEmptyString(value, label) {
|
|
27679
27897
|
if (typeof value !== "string" || !value.trim()) {
|
|
@@ -27681,36 +27899,19 @@ function requireNonEmptyString(value, label) {
|
|
|
27681
27899
|
}
|
|
27682
27900
|
return value.trim();
|
|
27683
27901
|
}
|
|
27684
|
-
function
|
|
27685
|
-
|
|
27686
|
-
|
|
27687
|
-
if (segments.length === 0) {
|
|
27688
|
-
throw new Error("SKS data.preFixPath must contain at least one safe path segment");
|
|
27902
|
+
function requireBoolean(value, label) {
|
|
27903
|
+
if (typeof value !== "boolean") {
|
|
27904
|
+
throw new Error(`${label} must be a boolean`);
|
|
27689
27905
|
}
|
|
27690
|
-
|
|
27691
|
-
if (segment === "." || segment === "..") {
|
|
27692
|
-
throw new Error("SKS data.preFixPath contains path traversal");
|
|
27693
|
-
}
|
|
27694
|
-
return sanitizeObjectKeySegment(segment);
|
|
27695
|
-
});
|
|
27696
|
-
return safeSegments.join("/");
|
|
27906
|
+
return value;
|
|
27697
27907
|
}
|
|
27698
|
-
function
|
|
27699
|
-
|
|
27700
|
-
|
|
27701
|
-
throw new Error(`Object key segment is not safe: ${segment}`);
|
|
27908
|
+
function requireNumber(value, label) {
|
|
27909
|
+
if (typeof value !== "number" || !Number.isFinite(value)) {
|
|
27910
|
+
throw new Error(`${label} must be a finite number`);
|
|
27702
27911
|
}
|
|
27703
|
-
return
|
|
27704
|
-
}
|
|
27705
|
-
function sanitizeFileName(fileName) {
|
|
27706
|
-
assertSafeUntrustedFileName(fileName);
|
|
27707
|
-
const parsed = path2.parse(fileName.trim());
|
|
27708
|
-
const safeBase = parsed.name.replace(/[^a-zA-Z0-9._-]+/g, "-").replace(/-+/g, "-").replace(/^-|-$/g, "");
|
|
27709
|
-
const safeExt = parsed.ext.replace(/[^a-zA-Z0-9.]+/g, "").slice(0, 16);
|
|
27710
|
-
const baseName = safeBase || "file";
|
|
27711
|
-
return `${baseName.slice(0, 80)}${safeExt}`;
|
|
27912
|
+
return value;
|
|
27712
27913
|
}
|
|
27713
|
-
function
|
|
27914
|
+
function requireSafeDisplayFileName(fileName) {
|
|
27714
27915
|
const trimmed = fileName.trim();
|
|
27715
27916
|
if (!trimmed) {
|
|
27716
27917
|
throw new Error("Filename cannot be empty");
|
|
@@ -27721,14 +27922,18 @@ function assertSafeUntrustedFileName(fileName) {
|
|
|
27721
27922
|
if (trimmed === "." || trimmed === "..") {
|
|
27722
27923
|
throw new Error(`Filename is not safe: ${fileName}`);
|
|
27723
27924
|
}
|
|
27925
|
+
return trimmed;
|
|
27724
27926
|
}
|
|
27725
|
-
function
|
|
27726
|
-
const
|
|
27727
|
-
|
|
27728
|
-
|
|
27927
|
+
function normalizeOutboundFileType(fileType) {
|
|
27928
|
+
const normalized = fileType.trim().replace(/^\.+/, "").toLowerCase();
|
|
27929
|
+
if (!normalized) {
|
|
27930
|
+
throw new Error("fileType is required");
|
|
27931
|
+
}
|
|
27932
|
+
return normalized;
|
|
27729
27933
|
}
|
|
27730
|
-
function
|
|
27731
|
-
|
|
27934
|
+
function inferOutboundFileType(fileName) {
|
|
27935
|
+
const extension = path2.extname(fileName).replace(/^\./, "").toLowerCase();
|
|
27936
|
+
return extension || "bin";
|
|
27732
27937
|
}
|
|
27733
27938
|
async function assertUploadableLocalFile(filePath) {
|
|
27734
27939
|
const resolvedPath = path2.resolve(filePath);
|
|
@@ -27853,11 +28058,11 @@ function parseContentDispositionFileName(contentDisposition) {
|
|
|
27853
28058
|
}
|
|
27854
28059
|
function resolveDownloadFileName(params) {
|
|
27855
28060
|
const candidate = params.explicitFileName ?? params.headerFileName ?? params.urlFileName ?? "file.bin";
|
|
27856
|
-
return
|
|
28061
|
+
return requireSafeDisplayFileName(candidate);
|
|
27857
28062
|
}
|
|
27858
28063
|
function buildTempFilePath(params) {
|
|
27859
28064
|
const timestamp = (params.now?.() ?? /* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "-");
|
|
27860
|
-
return path2.join(params.tempDir, `${timestamp}-${
|
|
28065
|
+
return path2.join(params.tempDir, `${timestamp}-${crypto.randomUUID()}-${params.fileName}`);
|
|
27861
28066
|
}
|
|
27862
28067
|
async function ensurePluginTempDir(resolveTmpDir) {
|
|
27863
28068
|
const baseTmpDir = resolveTmpDir?.() ?? resolvePreferredOpenClawTmpDir();
|
|
@@ -27918,12 +28123,12 @@ function normalizeWebhookPath(raw) {
|
|
|
27918
28123
|
function jsonOk(res, body) {
|
|
27919
28124
|
res.statusCode = 200;
|
|
27920
28125
|
res.setHeader("Content-Type", "application/json; charset=utf-8");
|
|
27921
|
-
res.end(JSON.stringify({
|
|
28126
|
+
res.end(JSON.stringify({ code: 0, msg: "success", data: body }));
|
|
27922
28127
|
}
|
|
27923
28128
|
function jsonError(res, message, statusCode = 200) {
|
|
27924
28129
|
res.statusCode = statusCode;
|
|
27925
28130
|
res.setHeader("Content-Type", "application/json; charset=utf-8");
|
|
27926
|
-
res.end(JSON.stringify({
|
|
28131
|
+
res.end(JSON.stringify({ code: -1, msg: message, data: {} }));
|
|
27927
28132
|
}
|
|
27928
28133
|
async function readRawBody(req, maxBytes) {
|
|
27929
28134
|
const chunks = [];
|
|
@@ -27955,47 +28160,6 @@ async function readRawBody(req, maxBytes) {
|
|
|
27955
28160
|
});
|
|
27956
28161
|
});
|
|
27957
28162
|
}
|
|
27958
|
-
function parseXmlBody(xml) {
|
|
27959
|
-
const result2 = {};
|
|
27960
|
-
const cdataRegex = /<(\w+)><!\[CDATA\[([\s\S]*?)\]\]><\/\1>/g;
|
|
27961
|
-
let match;
|
|
27962
|
-
while ((match = cdataRegex.exec(xml)) !== null) {
|
|
27963
|
-
const [, key = "", value = ""] = match;
|
|
27964
|
-
result2[key] = value;
|
|
27965
|
-
}
|
|
27966
|
-
const simpleRegex = /<(\w+)>([^<]*)<\/\1>/g;
|
|
27967
|
-
while ((match = simpleRegex.exec(xml)) !== null) {
|
|
27968
|
-
const [, key = "", value = ""] = match;
|
|
27969
|
-
if (!result2[key]) {
|
|
27970
|
-
result2[key] = value;
|
|
27971
|
-
}
|
|
27972
|
-
}
|
|
27973
|
-
return result2;
|
|
27974
|
-
}
|
|
27975
|
-
function isXmlFormat(raw) {
|
|
27976
|
-
const trimmed = raw.trim();
|
|
27977
|
-
return trimmed.startsWith("<") && trimmed.endsWith(">");
|
|
27978
|
-
}
|
|
27979
|
-
function buildEncryptedJsonReply(params) {
|
|
27980
|
-
const base = params.plaintextJson != null && typeof params.plaintextJson === "object" ? params.plaintextJson : {};
|
|
27981
|
-
const plaintext = JSON.stringify({ ...base, version: PLUGIN_VERSION });
|
|
27982
|
-
const encrypt = encryptBaiduAppPlaintext({
|
|
27983
|
-
encodingAESKey: params.account.encodingAESKey ?? "",
|
|
27984
|
-
plaintext
|
|
27985
|
-
});
|
|
27986
|
-
const msgsignature = computeBaiduAppMsgSignature({
|
|
27987
|
-
token: params.account.token ?? "",
|
|
27988
|
-
timestamp: params.timestamp,
|
|
27989
|
-
nonce: params.nonce,
|
|
27990
|
-
encrypt
|
|
27991
|
-
});
|
|
27992
|
-
return {
|
|
27993
|
-
encrypt,
|
|
27994
|
-
msgsignature,
|
|
27995
|
-
timestamp: params.timestamp,
|
|
27996
|
-
nonce: params.nonce
|
|
27997
|
-
};
|
|
27998
|
-
}
|
|
27999
28163
|
function resolveQueryParams(req) {
|
|
28000
28164
|
const url = new URL(req.url ?? "/", "http://localhost");
|
|
28001
28165
|
return url.searchParams;
|
|
@@ -28004,8 +28168,16 @@ function resolvePath(req) {
|
|
|
28004
28168
|
const url = new URL(req.url ?? "/", "http://localhost");
|
|
28005
28169
|
return normalizeWebhookPath(url.pathname || "/");
|
|
28006
28170
|
}
|
|
28007
|
-
function
|
|
28008
|
-
|
|
28171
|
+
function resolveBearerToken(req) {
|
|
28172
|
+
const authorization = req.headers.authorization ?? req.headers.Authorization;
|
|
28173
|
+
if (Array.isArray(authorization)) {
|
|
28174
|
+
return "";
|
|
28175
|
+
}
|
|
28176
|
+
const value = typeof authorization === "string" ? authorization.trim() : "";
|
|
28177
|
+
if (!value.toLowerCase().startsWith("bearer ")) {
|
|
28178
|
+
return "";
|
|
28179
|
+
}
|
|
28180
|
+
return value.slice(7).trim();
|
|
28009
28181
|
}
|
|
28010
28182
|
function buildLogger(target) {
|
|
28011
28183
|
return createLogger("openclaw-baiduapp", {
|
|
@@ -28073,50 +28245,49 @@ async function downloadInboundFiles(params) {
|
|
|
28073
28245
|
}
|
|
28074
28246
|
};
|
|
28075
28247
|
}
|
|
28076
|
-
function
|
|
28077
|
-
const
|
|
28078
|
-
|
|
28079
|
-
|
|
28080
|
-
|
|
28081
|
-
|
|
28082
|
-
|
|
28083
|
-
|
|
28084
|
-
|
|
28085
|
-
|
|
28086
|
-
|
|
28087
|
-
|
|
28088
|
-
|
|
28089
|
-
|
|
28090
|
-
|
|
28091
|
-
|
|
28092
|
-
|
|
28093
|
-
|
|
28248
|
+
function parseV2MsgToInbound(inner, outer) {
|
|
28249
|
+
const list = Array.isArray(inner.list) ? inner.list : [];
|
|
28250
|
+
const textItem = list.find(
|
|
28251
|
+
(item) => item && typeof item === "object" && item.type === "text"
|
|
28252
|
+
);
|
|
28253
|
+
const fileItems = list.filter(
|
|
28254
|
+
(item) => item && typeof item === "object" && item.type === "file"
|
|
28255
|
+
);
|
|
28256
|
+
const textContent = textItem?.data?.text?.content ?? "";
|
|
28257
|
+
const files = fileItems.map((f) => ({ url: f.data.fileId, fileType: "file" }));
|
|
28258
|
+
return {
|
|
28259
|
+
msgtype: "text",
|
|
28260
|
+
msgid: typeof outer.msgid === "string" ? outer.msgid : void 0,
|
|
28261
|
+
agentid: typeof outer.agentid === "string" ? outer.agentid : void 0,
|
|
28262
|
+
text: textContent ? { content: textContent } : void 0,
|
|
28263
|
+
...files.length > 0 ? { files } : {}
|
|
28264
|
+
};
|
|
28265
|
+
}
|
|
28266
|
+
function parseBaiduAppCandidates(params) {
|
|
28267
|
+
const results = [];
|
|
28268
|
+
let outer = {};
|
|
28094
28269
|
try {
|
|
28095
|
-
const parsed = JSON.parse(
|
|
28096
|
-
if (
|
|
28097
|
-
|
|
28270
|
+
const parsed = JSON.parse(params.raw);
|
|
28271
|
+
if (parsed && typeof parsed === "object") {
|
|
28272
|
+
outer = parsed;
|
|
28098
28273
|
}
|
|
28099
|
-
return parsed;
|
|
28100
28274
|
} catch {
|
|
28101
|
-
|
|
28275
|
+
outer = {};
|
|
28102
28276
|
}
|
|
28103
|
-
}
|
|
28104
|
-
|
|
28105
|
-
const results = [];
|
|
28106
|
-
for (const candidate of params.candidates) {
|
|
28107
|
-
if (!candidate.account.encodingAESKey) {
|
|
28108
|
-
continue;
|
|
28109
|
-
}
|
|
28277
|
+
let inner = {};
|
|
28278
|
+
if (typeof outer.msg === "string") {
|
|
28110
28279
|
try {
|
|
28111
|
-
const
|
|
28112
|
-
|
|
28113
|
-
|
|
28114
|
-
}
|
|
28115
|
-
const msg = parseBaiduAppPlainMessage(plaintext);
|
|
28116
|
-
results.push({ target: candidate, plaintext, msg });
|
|
28280
|
+
const parsedInner = JSON.parse(outer.msg);
|
|
28281
|
+
if (parsedInner && typeof parsedInner === "object") {
|
|
28282
|
+
inner = parsedInner;
|
|
28283
|
+
}
|
|
28117
28284
|
} catch {
|
|
28285
|
+
inner = {};
|
|
28118
28286
|
}
|
|
28119
28287
|
}
|
|
28288
|
+
for (const candidate of params.candidates) {
|
|
28289
|
+
results.push({ target: candidate, msg: parseV2MsgToInbound(inner, outer) });
|
|
28290
|
+
}
|
|
28120
28291
|
return results;
|
|
28121
28292
|
}
|
|
28122
28293
|
function selectDecryptedTarget(params) {
|
|
@@ -28133,8 +28304,9 @@ async function processBaiduAppInboundMessage(params) {
|
|
|
28133
28304
|
const { target, msg } = params;
|
|
28134
28305
|
const logger3 = buildLogger(target);
|
|
28135
28306
|
target.statusSink?.({ lastInboundAt: Date.now() });
|
|
28136
|
-
const msgtype = String(msg.msgtype ??
|
|
28137
|
-
const msgid = msg.msgid
|
|
28307
|
+
const msgtype = String(msg.msgtype ?? "").toLowerCase();
|
|
28308
|
+
const msgid = msg.msgid ? String(msg.msgid) : void 0;
|
|
28309
|
+
const agentId = extractAgentId(msg);
|
|
28138
28310
|
logger3.info(`inbound: type=${msgtype || "unknown"} msgid=${msgid ?? "none"} account=${target.account.accountId}`);
|
|
28139
28311
|
if (!canDispatchBaiduAppInboundMessage(msg)) {
|
|
28140
28312
|
logger3.warn(`inbound message skipped: type=${msgtype || "unknown"} reason=no-dispatchable-content`);
|
|
@@ -28142,6 +28314,11 @@ async function processBaiduAppInboundMessage(params) {
|
|
|
28142
28314
|
}
|
|
28143
28315
|
const inboundFileResult = msgtype === "text" ? await downloadInboundFiles({ msg, logger: logger3, runtime: target.runtime }) : { localFiles: [], diagnostic: {} };
|
|
28144
28316
|
const inboundMediaFiles = inboundFileResult.localFiles;
|
|
28317
|
+
const agentAccount = resolveAgentAccount({
|
|
28318
|
+
baseAccount: target.account,
|
|
28319
|
+
cfg: target.config,
|
|
28320
|
+
agentId
|
|
28321
|
+
});
|
|
28145
28322
|
const core = tryGetBaiduAppRuntime();
|
|
28146
28323
|
if (core) {
|
|
28147
28324
|
logger3.info(`agent dispatch started: canSendActive=${target.account.canSendActive}`);
|
|
@@ -28154,8 +28331,9 @@ async function processBaiduAppInboundMessage(params) {
|
|
|
28154
28331
|
);
|
|
28155
28332
|
target.statusSink?.({ lastOutboundAt: Date.now() });
|
|
28156
28333
|
if (target.account.canSendActive) {
|
|
28157
|
-
sendBaiduAppMessage(
|
|
28158
|
-
msgid,
|
|
28334
|
+
sendBaiduAppMessage(agentAccount, text, {
|
|
28335
|
+
replyToMsgId: msgid,
|
|
28336
|
+
agentid: agentId,
|
|
28159
28337
|
chunkKey: currentChunkKey
|
|
28160
28338
|
}).then((result2) => {
|
|
28161
28339
|
if (!result2.ok) {
|
|
@@ -28178,7 +28356,7 @@ async function processBaiduAppInboundMessage(params) {
|
|
|
28178
28356
|
};
|
|
28179
28357
|
dispatchBaiduAppMessage({
|
|
28180
28358
|
cfg: target.config,
|
|
28181
|
-
account:
|
|
28359
|
+
account: agentAccount,
|
|
28182
28360
|
msg,
|
|
28183
28361
|
core,
|
|
28184
28362
|
hooks,
|
|
@@ -28212,61 +28390,51 @@ function registerBaiduAppWebhookTarget(target) {
|
|
|
28212
28390
|
};
|
|
28213
28391
|
}
|
|
28214
28392
|
async function handleBaiduAppWebhookRequest(req, res) {
|
|
28215
|
-
const
|
|
28216
|
-
const targets = webhookTargets.get(
|
|
28393
|
+
const path5 = resolvePath(req);
|
|
28394
|
+
const targets = webhookTargets.get(path5);
|
|
28217
28395
|
if (!targets || targets.length === 0) {
|
|
28218
28396
|
return false;
|
|
28219
28397
|
}
|
|
28220
28398
|
const query = resolveQueryParams(req);
|
|
28221
28399
|
const timestamp = query.get("timestamp") ?? "";
|
|
28222
28400
|
const nonce = query.get("nonce") ?? "";
|
|
28223
|
-
const
|
|
28401
|
+
const ak = query.get("ak") ?? "";
|
|
28402
|
+
const token = resolveBearerToken(req);
|
|
28224
28403
|
const primary = targets[0];
|
|
28225
28404
|
const logger3 = buildLogger(primary);
|
|
28226
28405
|
if (req.method === "GET") {
|
|
28227
28406
|
const echostr = query.get("echostr") ?? "";
|
|
28228
|
-
if (!timestamp || !nonce || !
|
|
28407
|
+
if (!ak || !timestamp || !nonce || !token || !echostr) {
|
|
28229
28408
|
jsonError(res, "missing query params", 400);
|
|
28230
28409
|
return true;
|
|
28231
28410
|
}
|
|
28232
|
-
const
|
|
28233
|
-
if (!candidate.account.
|
|
28411
|
+
const tokenMatched2 = targets.filter((candidate) => {
|
|
28412
|
+
if (!candidate.account.appKey || !candidate.account.appSecret) {
|
|
28234
28413
|
return false;
|
|
28235
28414
|
}
|
|
28236
|
-
|
|
28237
|
-
|
|
28415
|
+
if (candidate.account.appKey !== ak) {
|
|
28416
|
+
return false;
|
|
28417
|
+
}
|
|
28418
|
+
return verifyAKSKBearerToken({
|
|
28419
|
+
ak: candidate.account.appKey,
|
|
28420
|
+
sk: candidate.account.appSecret,
|
|
28238
28421
|
timestamp,
|
|
28239
28422
|
nonce,
|
|
28240
|
-
|
|
28241
|
-
signature
|
|
28423
|
+
token
|
|
28242
28424
|
});
|
|
28243
28425
|
});
|
|
28244
|
-
if (
|
|
28245
|
-
jsonError(res, "unauthorized");
|
|
28246
|
-
return true;
|
|
28247
|
-
}
|
|
28248
|
-
const decryptable2 = signatureMatched2.filter((candidate) => Boolean(candidate.account.encodingAESKey));
|
|
28249
|
-
if (decryptable2.length === 0) {
|
|
28426
|
+
if (tokenMatched2.length === 0) {
|
|
28250
28427
|
jsonError(res, "unauthorized");
|
|
28251
28428
|
return true;
|
|
28252
28429
|
}
|
|
28253
|
-
|
|
28254
|
-
candidates: decryptable2,
|
|
28255
|
-
encrypt: echostr
|
|
28256
|
-
});
|
|
28257
|
-
if (decryptedCandidates2.length === 0) {
|
|
28258
|
-
jsonError(res, "decrypt failed");
|
|
28259
|
-
return true;
|
|
28260
|
-
}
|
|
28261
|
-
const selected2 = selectDecryptedTarget({ candidates: decryptedCandidates2, logger: logger3 });
|
|
28262
|
-
jsonOk(res, selected2.plaintext);
|
|
28430
|
+
jsonOk(res, echostr);
|
|
28263
28431
|
return true;
|
|
28264
28432
|
}
|
|
28265
28433
|
if (req.method !== "POST") {
|
|
28266
28434
|
jsonError(res, "Method Not Allowed", 405);
|
|
28267
28435
|
return true;
|
|
28268
28436
|
}
|
|
28269
|
-
if (!timestamp || !nonce || !
|
|
28437
|
+
if (!ak || !timestamp || !nonce || !token) {
|
|
28270
28438
|
jsonError(res, "missing query params");
|
|
28271
28439
|
return true;
|
|
28272
28440
|
}
|
|
@@ -28276,90 +28444,56 @@ async function handleBaiduAppWebhookRequest(req, res) {
|
|
|
28276
28444
|
return true;
|
|
28277
28445
|
}
|
|
28278
28446
|
const rawBody = body.raw;
|
|
28279
|
-
|
|
28280
|
-
|
|
28281
|
-
|
|
28282
|
-
|
|
28283
|
-
|
|
28284
|
-
|
|
28285
|
-
encrypt = xmlData.Encrypt ?? "";
|
|
28286
|
-
msgSignature = xmlData.MsgSignature ?? signature;
|
|
28287
|
-
msgTimestamp = xmlData.TimeStamp ?? timestamp;
|
|
28288
|
-
msgNonce = xmlData.Nonce ?? nonce;
|
|
28289
|
-
logger3.info(`inbound xml parsed: hasEncrypt=${Boolean(encrypt)}, msg_signature=${msgSignature ? "yes" : "no"}`);
|
|
28290
|
-
} else {
|
|
28291
|
-
try {
|
|
28292
|
-
const record = JSON.parse(rawBody);
|
|
28293
|
-
encrypt = String(record.encrypt ?? record.Encrypt ?? "");
|
|
28294
|
-
logger3.info(`inbound json parsed: hasEncrypt=${Boolean(encrypt)}`);
|
|
28295
|
-
} catch {
|
|
28296
|
-
logger3.warn(`inbound payload parse failed: not valid xml or json`);
|
|
28297
|
-
jsonError(res, "invalid payload format");
|
|
28298
|
-
return true;
|
|
28299
|
-
}
|
|
28300
|
-
}
|
|
28301
|
-
if (!encrypt) {
|
|
28302
|
-
jsonError(res, "missing encrypt");
|
|
28447
|
+
try {
|
|
28448
|
+
JSON.parse(rawBody);
|
|
28449
|
+
logger3.info("inbound json parsed");
|
|
28450
|
+
} catch {
|
|
28451
|
+
logger3.warn("inbound payload parse failed: not valid json");
|
|
28452
|
+
jsonError(res, "invalid payload format");
|
|
28303
28453
|
return true;
|
|
28304
28454
|
}
|
|
28305
|
-
const
|
|
28306
|
-
if (!candidate.account.
|
|
28455
|
+
const tokenMatched = targets.filter((candidate) => {
|
|
28456
|
+
if (!candidate.account.appKey || !candidate.account.appSecret) {
|
|
28307
28457
|
return false;
|
|
28308
28458
|
}
|
|
28309
|
-
|
|
28310
|
-
|
|
28311
|
-
|
|
28312
|
-
|
|
28313
|
-
|
|
28314
|
-
|
|
28459
|
+
if (candidate.account.appKey !== ak) {
|
|
28460
|
+
return false;
|
|
28461
|
+
}
|
|
28462
|
+
return verifyAKSKBearerToken({
|
|
28463
|
+
ak: candidate.account.appKey,
|
|
28464
|
+
sk: candidate.account.appSecret,
|
|
28465
|
+
timestamp,
|
|
28466
|
+
nonce,
|
|
28467
|
+
token
|
|
28315
28468
|
});
|
|
28316
28469
|
});
|
|
28317
|
-
if (
|
|
28318
|
-
logger3.warn(`
|
|
28470
|
+
if (tokenMatched.length === 0) {
|
|
28471
|
+
logger3.warn(`bearer token verification failed: checked ${targets.length} account(s), none matched`);
|
|
28319
28472
|
jsonError(res, "unauthorized");
|
|
28320
28473
|
return true;
|
|
28321
28474
|
}
|
|
28322
|
-
logger3.debug(`
|
|
28323
|
-
const
|
|
28324
|
-
|
|
28325
|
-
|
|
28326
|
-
jsonError(res, "openclaw-baiduapp not configured");
|
|
28327
|
-
return true;
|
|
28328
|
-
}
|
|
28329
|
-
const decryptedCandidates = decryptBaiduAppCandidates({
|
|
28330
|
-
candidates: decryptable,
|
|
28331
|
-
encrypt
|
|
28475
|
+
logger3.debug(`bearer token verified: ${tokenMatched.length} account(s) matched`);
|
|
28476
|
+
const decryptedCandidates = parseBaiduAppCandidates({
|
|
28477
|
+
candidates: tokenMatched,
|
|
28478
|
+
raw: rawBody
|
|
28332
28479
|
});
|
|
28333
|
-
if (decryptedCandidates.length === 0) {
|
|
28334
|
-
logger3.warn(`decrypt failed for all ${decryptable.length} candidate account(s)`);
|
|
28335
|
-
jsonError(res, "decrypt failed");
|
|
28336
|
-
return true;
|
|
28337
|
-
}
|
|
28338
28480
|
const selected = selectDecryptedTarget({ candidates: decryptedCandidates, logger: logger3 });
|
|
28339
28481
|
const target = selected.target;
|
|
28340
|
-
if (!target.account.configured || !target.account.
|
|
28482
|
+
if (!target.account.configured || !target.account.appKey || !target.account.appSecret) {
|
|
28341
28483
|
logger3.warn(`selected account ${target.account.accountId} not fully configured`);
|
|
28342
28484
|
jsonError(res, "openclaw-baiduapp not configured");
|
|
28343
28485
|
return true;
|
|
28344
28486
|
}
|
|
28345
|
-
|
|
28487
|
+
await processBaiduAppInboundMessage({
|
|
28346
28488
|
target,
|
|
28347
28489
|
msg: selected.msg
|
|
28348
28490
|
});
|
|
28349
|
-
jsonOk(
|
|
28350
|
-
res,
|
|
28351
|
-
buildEncryptedJsonReply({
|
|
28352
|
-
account: target.account,
|
|
28353
|
-
plaintextJson: reply,
|
|
28354
|
-
nonce: msgNonce,
|
|
28355
|
-
timestamp: msgTimestamp
|
|
28356
|
-
})
|
|
28357
|
-
);
|
|
28491
|
+
jsonOk(res, {});
|
|
28358
28492
|
return true;
|
|
28359
28493
|
}
|
|
28360
28494
|
|
|
28361
28495
|
// src/poller.ts
|
|
28362
|
-
var DEFAULT_POLL_INTERVAL_MS =
|
|
28496
|
+
var DEFAULT_POLL_INTERVAL_MS = 3e3;
|
|
28363
28497
|
var DEFAULT_POLL_REQUEST_TIMEOUT_MS = 1e4;
|
|
28364
28498
|
var accountPollers = /* @__PURE__ */ new Map();
|
|
28365
28499
|
function buildPollingTextInboundMessage(content) {
|
|
@@ -28370,21 +28504,34 @@ function buildPollingTextInboundMessage(content) {
|
|
|
28370
28504
|
}
|
|
28371
28505
|
};
|
|
28372
28506
|
}
|
|
28507
|
+
function parseTextAndFilesFromList(list) {
|
|
28508
|
+
const textItem = list.find((entry) => entry.type === "text");
|
|
28509
|
+
const fileItems = list.filter((entry) => entry.type === "file");
|
|
28510
|
+
const content = textItem?.type === "text" ? textItem.data.text.content : void 0;
|
|
28511
|
+
const files = fileItems.map((file) => {
|
|
28512
|
+
const fileId = file.data.file.fileId;
|
|
28513
|
+
return typeof fileId === "string" && fileId.trim() ? { url: fileId, fileType: "file" } : null;
|
|
28514
|
+
}).filter((file) => file != null);
|
|
28515
|
+
return { content, files };
|
|
28516
|
+
}
|
|
28373
28517
|
async function dispatchPendingPollingMessages(data, target) {
|
|
28374
28518
|
if (!target || data.length === 0) {
|
|
28375
28519
|
return;
|
|
28376
28520
|
}
|
|
28377
28521
|
for (const item of data) {
|
|
28378
|
-
|
|
28379
|
-
|
|
28380
|
-
|
|
28381
|
-
const content = item.data?.content;
|
|
28382
|
-
if (typeof content !== "string" || content.length === 0) {
|
|
28522
|
+
const list = Array.isArray(item.list) ? item.list : [];
|
|
28523
|
+
const { content, files } = parseTextAndFilesFromList(list);
|
|
28524
|
+
if (typeof content !== "string" && files.length === 0) {
|
|
28383
28525
|
continue;
|
|
28384
28526
|
}
|
|
28385
28527
|
await processBaiduAppInboundMessage({
|
|
28386
28528
|
target,
|
|
28387
|
-
msg:
|
|
28529
|
+
msg: {
|
|
28530
|
+
...buildPollingTextInboundMessage(typeof content === "string" ? content : ""),
|
|
28531
|
+
msgid: typeof item.msgId === "string" ? item.msgId : void 0,
|
|
28532
|
+
agentid: typeof item.agentId === "string" ? item.agentId : void 0,
|
|
28533
|
+
...files.length > 0 ? { files } : {}
|
|
28534
|
+
}
|
|
28388
28535
|
});
|
|
28389
28536
|
}
|
|
28390
28537
|
}
|
|
@@ -28439,12 +28586,28 @@ function createAbortSignalController(params) {
|
|
|
28439
28586
|
};
|
|
28440
28587
|
}
|
|
28441
28588
|
async function pollBaiduAppChatlistOnce(account, loggerOptions, requestOptions) {
|
|
28442
|
-
const endpoint = `${account.apiBase}/
|
|
28589
|
+
const endpoint = `${account.apiBase}/channel/msg/poll`;
|
|
28590
|
+
const logger3 = createLogger("openclaw-baiduapp:poller", loggerOptions);
|
|
28591
|
+
const timestamp = String(Math.floor(Date.now() / 1e3));
|
|
28592
|
+
const nonce = generateNonce();
|
|
28593
|
+
const authorization = buildAuthorizationHeader({
|
|
28594
|
+
ak: account.appKey ?? "",
|
|
28595
|
+
sk: account.appSecret ?? "",
|
|
28596
|
+
timestamp,
|
|
28597
|
+
nonce
|
|
28598
|
+
});
|
|
28443
28599
|
const query = new URLSearchParams({
|
|
28444
28600
|
ak: account.appKey ?? "",
|
|
28445
|
-
|
|
28601
|
+
timestamp,
|
|
28602
|
+
nonce
|
|
28446
28603
|
});
|
|
28447
28604
|
const url = `${endpoint}?${query.toString()}`;
|
|
28605
|
+
const payload = {
|
|
28606
|
+
sessionId: "agent:main:main",
|
|
28607
|
+
num: 5,
|
|
28608
|
+
version: PLUGIN_VERSION
|
|
28609
|
+
};
|
|
28610
|
+
const body = JSON.stringify(payload);
|
|
28448
28611
|
const requestSignal = createAbortSignalController({
|
|
28449
28612
|
signal: requestOptions?.signal,
|
|
28450
28613
|
timeoutMs: requestOptions?.timeoutMs
|
|
@@ -28452,8 +28615,13 @@ async function pollBaiduAppChatlistOnce(account, loggerOptions, requestOptions)
|
|
|
28452
28615
|
let response;
|
|
28453
28616
|
try {
|
|
28454
28617
|
response = await (requestOptions?.fetchImpl ?? fetch)(url, {
|
|
28455
|
-
method: "
|
|
28456
|
-
|
|
28618
|
+
method: "POST",
|
|
28619
|
+
body,
|
|
28620
|
+
signal: requestSignal.signal,
|
|
28621
|
+
headers: {
|
|
28622
|
+
"Authorization": authorization,
|
|
28623
|
+
"Content-Type": "application/json"
|
|
28624
|
+
}
|
|
28457
28625
|
});
|
|
28458
28626
|
} catch (error) {
|
|
28459
28627
|
requestSignal.cleanup();
|
|
@@ -28506,10 +28674,13 @@ async function pollBaiduAppChatlistOnce(account, loggerOptions, requestOptions)
|
|
|
28506
28674
|
}
|
|
28507
28675
|
});
|
|
28508
28676
|
}
|
|
28509
|
-
|
|
28677
|
+
if (parsed.code !== 0) {
|
|
28678
|
+
logger3.debug(`Baidu poll returned non-zero code=${String(parsed.code)}, message=${parsed.message}`);
|
|
28679
|
+
}
|
|
28680
|
+
const msgList = Array.isArray(parsed.data?.msgList) ? parsed.data.msgList : [];
|
|
28510
28681
|
return buildPollResult({
|
|
28511
28682
|
ok: true,
|
|
28512
|
-
data
|
|
28683
|
+
data: msgList
|
|
28513
28684
|
});
|
|
28514
28685
|
}
|
|
28515
28686
|
function scheduleNextPoll(account, state) {
|
|
@@ -28625,16 +28796,33 @@ function resolveOutboundLocalMediaPath(mediaUrl) {
|
|
|
28625
28796
|
}
|
|
28626
28797
|
return trimmed;
|
|
28627
28798
|
}
|
|
28628
|
-
function inferBaiduOutboundFileType(params) {
|
|
28629
|
-
const ext = path2.extname(params.mediaPath).toLowerCase();
|
|
28630
|
-
return ext.startsWith(".") ? ext.slice(1) : ext || "bin";
|
|
28631
|
-
}
|
|
28632
28799
|
function buildOutboundMediaPayload(params) {
|
|
28633
28800
|
const caption = params.caption?.trim();
|
|
28801
|
+
const mediaItem = params.externalUrl ? {
|
|
28802
|
+
type: "external_url",
|
|
28803
|
+
data: {
|
|
28804
|
+
externalUrl: {
|
|
28805
|
+
url: params.externalUrl
|
|
28806
|
+
}
|
|
28807
|
+
}
|
|
28808
|
+
} : {
|
|
28809
|
+
type: "file",
|
|
28810
|
+
data: {
|
|
28811
|
+
file: {
|
|
28812
|
+
fileId: params.fileId ?? ""
|
|
28813
|
+
}
|
|
28814
|
+
}
|
|
28815
|
+
};
|
|
28634
28816
|
return {
|
|
28635
|
-
|
|
28636
|
-
|
|
28637
|
-
|
|
28817
|
+
list: [
|
|
28818
|
+
...caption ? [{
|
|
28819
|
+
type: "text",
|
|
28820
|
+
data: {
|
|
28821
|
+
text: { content: caption }
|
|
28822
|
+
}
|
|
28823
|
+
}] : [],
|
|
28824
|
+
mediaItem
|
|
28825
|
+
]
|
|
28638
28826
|
};
|
|
28639
28827
|
}
|
|
28640
28828
|
function resolveDirectOutboundFiles(files) {
|
|
@@ -28871,7 +29059,10 @@ var baiduAppPlugin = {
|
|
|
28871
29059
|
};
|
|
28872
29060
|
}
|
|
28873
29061
|
try {
|
|
28874
|
-
const result2 = await sendBaiduAppMessage(account, params.text
|
|
29062
|
+
const result2 = await sendBaiduAppMessage(account, params.text, {
|
|
29063
|
+
agentid: account.accountId,
|
|
29064
|
+
isActive: true
|
|
29065
|
+
});
|
|
28875
29066
|
return {
|
|
28876
29067
|
channel: "openclaw-baiduapp",
|
|
28877
29068
|
ok: result2.ok,
|
|
@@ -28914,14 +29105,15 @@ var baiduAppPlugin = {
|
|
|
28914
29105
|
account,
|
|
28915
29106
|
buildOutboundMediaPayload({
|
|
28916
29107
|
caption: params.text,
|
|
28917
|
-
|
|
28918
|
-
|
|
28919
|
-
}
|
|
29108
|
+
externalUrl: remoteUrl
|
|
29109
|
+
}),
|
|
29110
|
+
{ agentid: account.accountId, isActive: true }
|
|
28920
29111
|
);
|
|
28921
29112
|
return {
|
|
28922
29113
|
channel: "openclaw-baiduapp",
|
|
28923
|
-
ok:
|
|
28924
|
-
messageId: result2.msgid ?? ""
|
|
29114
|
+
ok: result2.ok,
|
|
29115
|
+
messageId: result2.msgid ?? "",
|
|
29116
|
+
error: result2.ok ? void 0 : new Error(result2.errmsg ?? "send failed")
|
|
28925
29117
|
};
|
|
28926
29118
|
} catch (err) {
|
|
28927
29119
|
return {
|
|
@@ -28954,11 +29146,9 @@ var baiduAppPlugin = {
|
|
|
28954
29146
|
account,
|
|
28955
29147
|
buildOutboundMediaPayload({
|
|
28956
29148
|
caption: params.text,
|
|
28957
|
-
|
|
28958
|
-
|
|
28959
|
-
|
|
28960
|
-
})
|
|
28961
|
-
})
|
|
29149
|
+
fileId: uploaded.fileId
|
|
29150
|
+
}),
|
|
29151
|
+
{ agentid: account.accountId, isActive: true }
|
|
28962
29152
|
);
|
|
28963
29153
|
return {
|
|
28964
29154
|
channel: "openclaw-baiduapp",
|
|
@@ -28980,6 +29170,18 @@ var baiduAppPlugin = {
|
|
|
28980
29170
|
}
|
|
28981
29171
|
}
|
|
28982
29172
|
},
|
|
29173
|
+
auth: {
|
|
29174
|
+
login: async (params) => {
|
|
29175
|
+
void params.channelInput;
|
|
29176
|
+
const { loginBaiduApp: loginBaiduApp2 } = await Promise.resolve().then(() => (init_login(), login_exports));
|
|
29177
|
+
await loginBaiduApp2({
|
|
29178
|
+
cfg: params.cfg,
|
|
29179
|
+
accountId: params.accountId,
|
|
29180
|
+
runtime: params.runtime,
|
|
29181
|
+
verbose: params.verbose
|
|
29182
|
+
});
|
|
29183
|
+
}
|
|
29184
|
+
},
|
|
28983
29185
|
gateway: {
|
|
28984
29186
|
startAccount: async (ctx) => {
|
|
28985
29187
|
ctx.setStatus?.({ accountId: ctx.accountId });
|
|
@@ -28995,7 +29197,7 @@ var baiduAppPlugin = {
|
|
|
28995
29197
|
ctx.setStatus?.({ accountId: ctx.accountId, running: false, configured: false });
|
|
28996
29198
|
return;
|
|
28997
29199
|
}
|
|
28998
|
-
const
|
|
29200
|
+
const path5 = (account.config.webhookPath ?? "/openclaw-baiduapp").trim();
|
|
28999
29201
|
const runtime2 = {
|
|
29000
29202
|
log: ctx.log?.info ?? console.log,
|
|
29001
29203
|
error: ctx.log?.error ?? console.error
|
|
@@ -29004,7 +29206,7 @@ var baiduAppPlugin = {
|
|
|
29004
29206
|
account,
|
|
29005
29207
|
config: ctx.cfg ?? {},
|
|
29006
29208
|
runtime: runtime2,
|
|
29007
|
-
path:
|
|
29209
|
+
path: path5,
|
|
29008
29210
|
statusSink: (patch) => ctx.setStatus?.({ accountId: ctx.accountId, ...patch })
|
|
29009
29211
|
});
|
|
29010
29212
|
try {
|
|
@@ -29017,30 +29219,28 @@ var baiduAppPlugin = {
|
|
|
29017
29219
|
existing();
|
|
29018
29220
|
}
|
|
29019
29221
|
unregisterHooks.set(ctx.accountId, unregister);
|
|
29020
|
-
|
|
29021
|
-
|
|
29222
|
+
startAccountPolling({
|
|
29223
|
+
account,
|
|
29224
|
+
dispatchTarget: {
|
|
29022
29225
|
account,
|
|
29023
|
-
|
|
29024
|
-
|
|
29025
|
-
|
|
29026
|
-
|
|
29027
|
-
|
|
29028
|
-
|
|
29029
|
-
|
|
29030
|
-
|
|
29031
|
-
|
|
29032
|
-
}
|
|
29033
|
-
});
|
|
29034
|
-
}
|
|
29226
|
+
config: ctx.cfg ?? {},
|
|
29227
|
+
runtime: runtime2,
|
|
29228
|
+
statusSink: (patch) => ctx.setStatus?.({ accountId: ctx.accountId, ...patch })
|
|
29229
|
+
},
|
|
29230
|
+
onError: (error) => {
|
|
29231
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
29232
|
+
ctx.log?.error(`[openclaw-baiduapp] polling failed for account ${ctx.accountId}: ${message}`);
|
|
29233
|
+
}
|
|
29234
|
+
});
|
|
29035
29235
|
ctx.log?.info(
|
|
29036
|
-
`[openclaw-baiduapp] webhook registered at ${
|
|
29236
|
+
`[openclaw-baiduapp] webhook registered at ${path5} for account ${ctx.accountId} (canSendActive=${account.canSendActive})`
|
|
29037
29237
|
);
|
|
29038
29238
|
ctx.setStatus?.({
|
|
29039
29239
|
accountId: ctx.accountId,
|
|
29040
29240
|
running: true,
|
|
29041
29241
|
configured: true,
|
|
29042
29242
|
canSendActive: account.canSendActive,
|
|
29043
|
-
webhookPath:
|
|
29243
|
+
webhookPath: path5,
|
|
29044
29244
|
lastStartAt: Date.now()
|
|
29045
29245
|
});
|
|
29046
29246
|
if (ctx.abortSignal) {
|
|
@@ -29083,7 +29283,7 @@ async function sendMessage(account, options) {
|
|
|
29083
29283
|
};
|
|
29084
29284
|
}
|
|
29085
29285
|
try {
|
|
29086
|
-
const textResult = await sendBaiduAppMessage(account, options.text);
|
|
29286
|
+
const textResult = await sendBaiduAppMessage(account, options.text, { isActive: true });
|
|
29087
29287
|
return {
|
|
29088
29288
|
ok: textResult.ok,
|
|
29089
29289
|
msgid: textResult.msgid,
|