linkque-cli-v2 1.5.0 → 1.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dataTransformWorker.js +1880 -0
- package/emscripten-module.wasm +0 -0
- package/linkquejs.js +1211 -584
- package/package.json +1 -1
- package/vendor/linkque-agent-appwrite-integrate/data-transform/dataTransformWorker.js +1880 -0
- package/vendor/linkque-agent-appwrite-integrate/data-transform/emscripten-module.wasm +0 -0
- package/vendor/linkque-agent-appwrite-integrate/dist/esm/{chunk-EWGNYBVV.js → chunk-3WYLH7P7.js} +1883 -1201
- package/vendor/linkque-agent-appwrite-integrate/dist/esm/{chunk-GQ4TD3EQ.js → chunk-4XAZNSEQ.js} +1 -1
- package/vendor/linkque-agent-appwrite-integrate/dist/esm/{chunk-CBGTFDSE.js → chunk-GPVKBHKR.js} +1 -2
- package/vendor/linkque-agent-appwrite-integrate/dist/esm/{chunk-UIU24A4Z.js → chunk-TSJX2OMA.js} +2 -19
- package/vendor/linkque-agent-appwrite-integrate/dist/esm/{dist-TGBYXSBU.js → dist-ZPLSQEAM.js} +42 -27
- package/vendor/linkque-agent-appwrite-integrate/dist/esm/{google-generative-ai-ENBYCHYT.js → google-generative-ai-OLT56CSV.js} +1 -1
- package/vendor/linkque-agent-appwrite-integrate/dist/esm/{google-vertex-RIGAEYLC.js → google-vertex-4DBBJ7SR.js} +1 -1
- package/vendor/linkque-agent-appwrite-integrate/dist/esm/runtime/handler/chat.js +1153 -624
- package/vendor/linkque-agent-appwrite-integrate/dist/esm/runtime/handler/clientCapability.js +2 -2
- package/vendor/linkque-agent-appwrite-integrate/dist/esm/runtime/protocol.js +2 -2
- package/vendor/linkque-agent-appwrite-integrate/package.json +1 -1
- package/worker.js +3005 -1872
package/vendor/linkque-agent-appwrite-integrate/dist/esm/{chunk-EWGNYBVV.js → chunk-3WYLH7P7.js}
RENAMED
|
@@ -7260,7 +7260,7 @@ var require_jmespath = __commonJS({
|
|
|
7260
7260
|
return false;
|
|
7261
7261
|
}
|
|
7262
7262
|
}
|
|
7263
|
-
function
|
|
7263
|
+
function isObject4(obj) {
|
|
7264
7264
|
if (obj !== null) {
|
|
7265
7265
|
return Object.prototype.toString.call(obj) === "[object Object]";
|
|
7266
7266
|
} else {
|
|
@@ -7286,7 +7286,7 @@ var require_jmespath = __commonJS({
|
|
|
7286
7286
|
}
|
|
7287
7287
|
return true;
|
|
7288
7288
|
}
|
|
7289
|
-
if (
|
|
7289
|
+
if (isObject4(first) === true) {
|
|
7290
7290
|
var keysSeen = {};
|
|
7291
7291
|
for (var key in first) {
|
|
7292
7292
|
if (hasOwnProperty.call(first, key)) {
|
|
@@ -7312,7 +7312,7 @@ var require_jmespath = __commonJS({
|
|
|
7312
7312
|
return true;
|
|
7313
7313
|
} else if (isArray(obj) && obj.length === 0) {
|
|
7314
7314
|
return true;
|
|
7315
|
-
} else if (
|
|
7315
|
+
} else if (isObject4(obj)) {
|
|
7316
7316
|
for (var key in obj) {
|
|
7317
7317
|
if (obj.hasOwnProperty(key)) {
|
|
7318
7318
|
return false;
|
|
@@ -8029,7 +8029,7 @@ var require_jmespath = __commonJS({
|
|
|
8029
8029
|
var matched, current, result, first, second, field, left, right, collected, i;
|
|
8030
8030
|
switch (node.type) {
|
|
8031
8031
|
case "Field":
|
|
8032
|
-
if (value !== null &&
|
|
8032
|
+
if (value !== null && isObject4(value)) {
|
|
8033
8033
|
field = value[node.name];
|
|
8034
8034
|
if (field === void 0) {
|
|
8035
8035
|
return null;
|
|
@@ -8099,7 +8099,7 @@ var require_jmespath = __commonJS({
|
|
|
8099
8099
|
return collected;
|
|
8100
8100
|
case "ValueProjection":
|
|
8101
8101
|
base = this.visit(node.children[0], value);
|
|
8102
|
-
if (!
|
|
8102
|
+
if (!isObject4(base)) {
|
|
8103
8103
|
return null;
|
|
8104
8104
|
}
|
|
8105
8105
|
collected = [];
|
|
@@ -8496,7 +8496,7 @@ var require_jmespath = __commonJS({
|
|
|
8496
8496
|
return Math.floor(resolvedArgs[0]);
|
|
8497
8497
|
},
|
|
8498
8498
|
_functionLength: function(resolvedArgs) {
|
|
8499
|
-
if (!
|
|
8499
|
+
if (!isObject4(resolvedArgs[0])) {
|
|
8500
8500
|
return resolvedArgs[0].length;
|
|
8501
8501
|
} else {
|
|
8502
8502
|
return Object.keys(resolvedArgs[0]).length;
|
|
@@ -12052,7 +12052,7 @@ var require_merge = __commonJS({
|
|
|
12052
12052
|
for (let i = 0, j = two.length; i < j; i++) {
|
|
12053
12053
|
result.push(takeValue(two[i]));
|
|
12054
12054
|
}
|
|
12055
|
-
} else if (
|
|
12055
|
+
} else if (isObject4(two)) {
|
|
12056
12056
|
const keys = Object.keys(two);
|
|
12057
12057
|
for (let i = 0, j = keys.length; i < j; i++) {
|
|
12058
12058
|
const key = keys[i];
|
|
@@ -12062,8 +12062,8 @@ var require_merge = __commonJS({
|
|
|
12062
12062
|
result[key] = takeValue(two[key]);
|
|
12063
12063
|
}
|
|
12064
12064
|
}
|
|
12065
|
-
} else if (
|
|
12066
|
-
if (
|
|
12065
|
+
} else if (isObject4(one)) {
|
|
12066
|
+
if (isObject4(two)) {
|
|
12067
12067
|
if (!shouldMerge(one, two)) {
|
|
12068
12068
|
return two;
|
|
12069
12069
|
}
|
|
@@ -12087,7 +12087,7 @@ var require_merge = __commonJS({
|
|
|
12087
12087
|
if (wasObjectReferenced(one, key, objects) || wasObjectReferenced(two, key, objects)) {
|
|
12088
12088
|
delete result[key];
|
|
12089
12089
|
} else {
|
|
12090
|
-
if (
|
|
12090
|
+
if (isObject4(obj1) && isObject4(obj2)) {
|
|
12091
12091
|
const arr1 = objects.get(obj1) || [];
|
|
12092
12092
|
const arr2 = objects.get(obj2) || [];
|
|
12093
12093
|
arr1.push({ obj: one, key });
|
|
@@ -12121,7 +12121,7 @@ var require_merge = __commonJS({
|
|
|
12121
12121
|
function isFunction(value) {
|
|
12122
12122
|
return typeof value === "function";
|
|
12123
12123
|
}
|
|
12124
|
-
function
|
|
12124
|
+
function isObject4(value) {
|
|
12125
12125
|
return !isPrimitive2(value) && !isArray(value) && !isFunction(value) && typeof value === "object";
|
|
12126
12126
|
}
|
|
12127
12127
|
function isPrimitive2(value) {
|
|
@@ -22819,6 +22819,288 @@ function truncateToEstimatedTokens(text, budget) {
|
|
|
22819
22819
|
return text.slice(0, low).trim();
|
|
22820
22820
|
}
|
|
22821
22821
|
|
|
22822
|
+
// ../linkque-agent-runtime/dist/esm/core/dataTransformExecutor.js
|
|
22823
|
+
import { createHash } from "node:crypto";
|
|
22824
|
+
import { dirname, join } from "node:path";
|
|
22825
|
+
import { createRequire } from "node:module";
|
|
22826
|
+
import { pathToFileURL } from "node:url";
|
|
22827
|
+
import { Worker } from "node:worker_threads";
|
|
22828
|
+
var DATA_TRANSFORM_LIMITS = Object.freeze({
|
|
22829
|
+
sourceBytes: 32 * 1024,
|
|
22830
|
+
inputBytes: 2 * 1024 * 1024,
|
|
22831
|
+
outputBytes: 1024 * 1024,
|
|
22832
|
+
maxDepth: 64,
|
|
22833
|
+
memoryBytes: 32 * 1024 * 1024,
|
|
22834
|
+
stackBytes: 512 * 1024,
|
|
22835
|
+
executionMs: 100,
|
|
22836
|
+
watchdogMs: 500,
|
|
22837
|
+
initializationMs: 5e3,
|
|
22838
|
+
maxConcurrent: 4,
|
|
22839
|
+
maxQueued: 32
|
|
22840
|
+
});
|
|
22841
|
+
var DataTransformError = class extends Error {
|
|
22842
|
+
code;
|
|
22843
|
+
sourceHash;
|
|
22844
|
+
constructor(code, message, sourceHash) {
|
|
22845
|
+
super(message);
|
|
22846
|
+
this.code = code;
|
|
22847
|
+
this.sourceHash = sourceHash;
|
|
22848
|
+
this.name = "DataTransformError";
|
|
22849
|
+
}
|
|
22850
|
+
};
|
|
22851
|
+
var DataTransformExecutor = class {
|
|
22852
|
+
workerUrl;
|
|
22853
|
+
queue = [];
|
|
22854
|
+
slots = [];
|
|
22855
|
+
nextRequestId = 1;
|
|
22856
|
+
disposed = false;
|
|
22857
|
+
constructor(workerUrl = defaultWorkerUrl()) {
|
|
22858
|
+
this.workerUrl = workerUrl;
|
|
22859
|
+
}
|
|
22860
|
+
execute(source, input, signal) {
|
|
22861
|
+
const sourceBytes = Buffer.byteLength(source, "utf8");
|
|
22862
|
+
const sourceHash = createHash("sha256").update(source).digest("hex");
|
|
22863
|
+
if (!source.trim() || sourceBytes > DATA_TRANSFORM_LIMITS.sourceBytes) {
|
|
22864
|
+
return Promise.reject(new DataTransformError("CARD_TRANSFORM_SOURCE_INVALID", `\u6570\u636E\u8F6C\u6362\u6E90\u7801\u4E3A\u7A7A\u6216\u8D85\u8FC7 ${DATA_TRANSFORM_LIMITS.sourceBytes} \u5B57\u8282`, sourceHash));
|
|
22865
|
+
}
|
|
22866
|
+
if (signal?.aborted) {
|
|
22867
|
+
return Promise.reject(signal.reason ?? new Error("\u64CD\u4F5C\u5DF2\u53D6\u6D88"));
|
|
22868
|
+
}
|
|
22869
|
+
let inputJson;
|
|
22870
|
+
try {
|
|
22871
|
+
inputJson = JSON.stringify(input);
|
|
22872
|
+
} catch {
|
|
22873
|
+
return Promise.reject(new DataTransformError("CARD_TRANSFORM_INPUT_TOO_LARGE", "\u6570\u636E\u8F6C\u6362\u8F93\u5165\u65E0\u6CD5\u5E8F\u5217\u5316", sourceHash));
|
|
22874
|
+
}
|
|
22875
|
+
const inputBytes = Buffer.byteLength(inputJson, "utf8");
|
|
22876
|
+
if (inputBytes > DATA_TRANSFORM_LIMITS.inputBytes || jsonDepth(input) > DATA_TRANSFORM_LIMITS.maxDepth) {
|
|
22877
|
+
return Promise.reject(new DataTransformError("CARD_TRANSFORM_INPUT_TOO_LARGE", "\u6570\u636E\u8F6C\u6362\u8F93\u5165\u8D85\u8FC7\u5927\u5C0F\u6216\u6DF1\u5EA6\u9650\u5236", sourceHash));
|
|
22878
|
+
}
|
|
22879
|
+
const active = this.slots.filter((slot) => slot.busy).length;
|
|
22880
|
+
if (active >= DATA_TRANSFORM_LIMITS.maxConcurrent && this.queue.length >= DATA_TRANSFORM_LIMITS.maxQueued) {
|
|
22881
|
+
return Promise.reject(new DataTransformError("CARD_TRANSFORM_BUSY", "\u6570\u636E\u8F6C\u6362\u6267\u884C\u961F\u5217\u5DF2\u6EE1", sourceHash));
|
|
22882
|
+
}
|
|
22883
|
+
if (this.disposed) {
|
|
22884
|
+
return Promise.reject(new DataTransformError("CARD_TRANSFORM_FAILED", "\u6570\u636E\u8F6C\u6362\u6267\u884C\u5668\u5DF2\u5173\u95ED", sourceHash));
|
|
22885
|
+
}
|
|
22886
|
+
return new Promise((resolve, reject) => {
|
|
22887
|
+
this.queue.push({
|
|
22888
|
+
mode: "execute",
|
|
22889
|
+
source,
|
|
22890
|
+
sourceHash,
|
|
22891
|
+
inputJson,
|
|
22892
|
+
inputBytes,
|
|
22893
|
+
signal,
|
|
22894
|
+
resolve,
|
|
22895
|
+
reject
|
|
22896
|
+
});
|
|
22897
|
+
this.drain();
|
|
22898
|
+
});
|
|
22899
|
+
}
|
|
22900
|
+
validateSource(source) {
|
|
22901
|
+
const sourceBytes = Buffer.byteLength(source, "utf8");
|
|
22902
|
+
const sourceHash = createHash("sha256").update(source).digest("hex");
|
|
22903
|
+
if (!source.trim() || sourceBytes > DATA_TRANSFORM_LIMITS.sourceBytes) {
|
|
22904
|
+
return Promise.reject(new DataTransformError("CARD_TRANSFORM_SOURCE_INVALID", `\u6570\u636E\u8F6C\u6362\u6E90\u7801\u4E3A\u7A7A\u6216\u8D85\u8FC7 ${DATA_TRANSFORM_LIMITS.sourceBytes} \u5B57\u8282`, sourceHash));
|
|
22905
|
+
}
|
|
22906
|
+
if (this.disposed) {
|
|
22907
|
+
return Promise.reject(new DataTransformError("CARD_TRANSFORM_FAILED", "\u6570\u636E\u8F6C\u6362\u6267\u884C\u5668\u5DF2\u5173\u95ED", sourceHash));
|
|
22908
|
+
}
|
|
22909
|
+
const active = this.slots.filter((slot) => slot.busy).length;
|
|
22910
|
+
if (active >= DATA_TRANSFORM_LIMITS.maxConcurrent && this.queue.length >= DATA_TRANSFORM_LIMITS.maxQueued) {
|
|
22911
|
+
return Promise.reject(new DataTransformError("CARD_TRANSFORM_BUSY", "\u6570\u636E\u8F6C\u6362\u6267\u884C\u961F\u5217\u5DF2\u6EE1", sourceHash));
|
|
22912
|
+
}
|
|
22913
|
+
return new Promise((resolve, reject) => {
|
|
22914
|
+
this.queue.push({
|
|
22915
|
+
mode: "validate",
|
|
22916
|
+
source,
|
|
22917
|
+
sourceHash,
|
|
22918
|
+
inputJson: "[]",
|
|
22919
|
+
inputBytes: 2,
|
|
22920
|
+
resolve: () => resolve(),
|
|
22921
|
+
reject
|
|
22922
|
+
});
|
|
22923
|
+
this.drain();
|
|
22924
|
+
});
|
|
22925
|
+
}
|
|
22926
|
+
async close() {
|
|
22927
|
+
this.disposed = true;
|
|
22928
|
+
for (const queued of this.queue.splice(0)) {
|
|
22929
|
+
queued.reject(new DataTransformError("CARD_TRANSFORM_FAILED", "\u6570\u636E\u8F6C\u6362\u6267\u884C\u5668\u5DF2\u5173\u95ED", queued.sourceHash));
|
|
22930
|
+
}
|
|
22931
|
+
await Promise.all(this.slots.splice(0).map(async (slot) => {
|
|
22932
|
+
slot.disposed = true;
|
|
22933
|
+
await slot.worker.terminate();
|
|
22934
|
+
}));
|
|
22935
|
+
}
|
|
22936
|
+
drain() {
|
|
22937
|
+
if (this.disposed)
|
|
22938
|
+
return;
|
|
22939
|
+
while (this.queue.length > 0) {
|
|
22940
|
+
let slot = this.slots.find((candidate) => !candidate.busy);
|
|
22941
|
+
if (!slot && this.slots.length < DATA_TRANSFORM_LIMITS.maxConcurrent) {
|
|
22942
|
+
slot = this.createSlot();
|
|
22943
|
+
this.slots.push(slot);
|
|
22944
|
+
}
|
|
22945
|
+
if (!slot)
|
|
22946
|
+
return;
|
|
22947
|
+
const queued = this.queue.shift();
|
|
22948
|
+
if (!queued)
|
|
22949
|
+
return;
|
|
22950
|
+
if (queued.signal?.aborted) {
|
|
22951
|
+
queued.reject(queued.signal.reason ?? new Error("\u64CD\u4F5C\u5DF2\u53D6\u6D88"));
|
|
22952
|
+
continue;
|
|
22953
|
+
}
|
|
22954
|
+
slot.busy = true;
|
|
22955
|
+
void this.run(slot, queued).finally(() => {
|
|
22956
|
+
if (!slot.disposed)
|
|
22957
|
+
slot.busy = false;
|
|
22958
|
+
this.drain();
|
|
22959
|
+
});
|
|
22960
|
+
}
|
|
22961
|
+
}
|
|
22962
|
+
createSlot() {
|
|
22963
|
+
const worker = new Worker(this.workerUrl);
|
|
22964
|
+
const slot = {
|
|
22965
|
+
worker,
|
|
22966
|
+
busy: false,
|
|
22967
|
+
disposed: false,
|
|
22968
|
+
ready: Promise.resolve()
|
|
22969
|
+
};
|
|
22970
|
+
slot.ready = new Promise((resolve, reject) => {
|
|
22971
|
+
const timeout = setTimeout(() => {
|
|
22972
|
+
reject(new DataTransformError("CARD_TRANSFORM_TIMEOUT", "\u6570\u636E\u8F6C\u6362\u5F15\u64CE\u521D\u59CB\u5316\u8D85\u65F6"));
|
|
22973
|
+
this.discardSlot(slot);
|
|
22974
|
+
}, DATA_TRANSFORM_LIMITS.initializationMs);
|
|
22975
|
+
worker.once("message", (message) => {
|
|
22976
|
+
if (message?.type !== "ready")
|
|
22977
|
+
return;
|
|
22978
|
+
clearTimeout(timeout);
|
|
22979
|
+
resolve();
|
|
22980
|
+
});
|
|
22981
|
+
worker.once("error", (error) => {
|
|
22982
|
+
clearTimeout(timeout);
|
|
22983
|
+
reject(error);
|
|
22984
|
+
});
|
|
22985
|
+
});
|
|
22986
|
+
return slot;
|
|
22987
|
+
}
|
|
22988
|
+
async run(slot, queued) {
|
|
22989
|
+
try {
|
|
22990
|
+
await slot.ready;
|
|
22991
|
+
} catch (error) {
|
|
22992
|
+
queued.reject(error instanceof DataTransformError ? error : new DataTransformError("CARD_TRANSFORM_FAILED", error instanceof Error ? error.message : "\u6570\u636E\u8F6C\u6362\u5F15\u64CE\u521D\u59CB\u5316\u5931\u8D25", queued.sourceHash));
|
|
22993
|
+
this.discardSlot(slot);
|
|
22994
|
+
return;
|
|
22995
|
+
}
|
|
22996
|
+
if (queued.signal?.aborted) {
|
|
22997
|
+
queued.reject(queued.signal.reason ?? new Error("\u64CD\u4F5C\u5DF2\u53D6\u6D88"));
|
|
22998
|
+
return;
|
|
22999
|
+
}
|
|
23000
|
+
const requestId = this.nextRequestId++;
|
|
23001
|
+
await new Promise((resolve) => {
|
|
23002
|
+
let settled = false;
|
|
23003
|
+
let watchdog;
|
|
23004
|
+
const finish = (callback) => {
|
|
23005
|
+
if (settled)
|
|
23006
|
+
return;
|
|
23007
|
+
settled = true;
|
|
23008
|
+
clearTimeout(watchdog);
|
|
23009
|
+
queued.signal?.removeEventListener("abort", abort);
|
|
23010
|
+
slot.worker.off("message", onMessage);
|
|
23011
|
+
slot.worker.off("error", onError);
|
|
23012
|
+
callback();
|
|
23013
|
+
resolve();
|
|
23014
|
+
};
|
|
23015
|
+
const abort = () => {
|
|
23016
|
+
finish(() => {
|
|
23017
|
+
queued.reject(queued.signal?.reason ?? new Error("\u64CD\u4F5C\u5DF2\u53D6\u6D88"));
|
|
23018
|
+
this.discardSlot(slot);
|
|
23019
|
+
});
|
|
23020
|
+
};
|
|
23021
|
+
const onError = (error) => {
|
|
23022
|
+
finish(() => {
|
|
23023
|
+
queued.reject(new DataTransformError("CARD_TRANSFORM_FAILED", error.message, queued.sourceHash));
|
|
23024
|
+
this.discardSlot(slot);
|
|
23025
|
+
});
|
|
23026
|
+
};
|
|
23027
|
+
const onMessage = (message) => {
|
|
23028
|
+
if (message?.type !== "result" || message.requestId !== requestId)
|
|
23029
|
+
return;
|
|
23030
|
+
finish(() => this.acceptWorkerResult(queued, message));
|
|
23031
|
+
};
|
|
23032
|
+
watchdog = setTimeout(() => {
|
|
23033
|
+
finish(() => {
|
|
23034
|
+
queued.reject(new DataTransformError("CARD_TRANSFORM_TIMEOUT", "\u6570\u636E\u8F6C\u6362\u8D85\u8FC7\u5BBF\u4E3B\u6267\u884C\u671F\u9650", queued.sourceHash));
|
|
23035
|
+
this.discardSlot(slot);
|
|
23036
|
+
});
|
|
23037
|
+
}, DATA_TRANSFORM_LIMITS.watchdogMs);
|
|
23038
|
+
queued.signal?.addEventListener("abort", abort, { once: true });
|
|
23039
|
+
slot.worker.on("message", onMessage);
|
|
23040
|
+
slot.worker.once("error", onError);
|
|
23041
|
+
slot.worker.postMessage({
|
|
23042
|
+
type: "execute",
|
|
23043
|
+
mode: queued.mode,
|
|
23044
|
+
requestId,
|
|
23045
|
+
source: queued.source,
|
|
23046
|
+
inputJson: queued.inputJson,
|
|
23047
|
+
limits: DATA_TRANSFORM_LIMITS
|
|
23048
|
+
});
|
|
23049
|
+
});
|
|
23050
|
+
}
|
|
23051
|
+
acceptWorkerResult(queued, message) {
|
|
23052
|
+
if (!message.ok || typeof message.resultJson !== "string") {
|
|
23053
|
+
queued.reject(new DataTransformError(message.code ?? "CARD_TRANSFORM_FAILED", message.message ?? "\u6570\u636E\u8F6C\u6362\u6267\u884C\u5931\u8D25", queued.sourceHash));
|
|
23054
|
+
return;
|
|
23055
|
+
}
|
|
23056
|
+
const outputBytes = Buffer.byteLength(message.resultJson, "utf8");
|
|
23057
|
+
if (outputBytes > DATA_TRANSFORM_LIMITS.outputBytes) {
|
|
23058
|
+
queued.reject(new DataTransformError("CARD_TRANSFORM_OUTPUT_TOO_LARGE", "\u6570\u636E\u8F6C\u6362\u7ED3\u679C\u8D85\u8FC7\u5927\u5C0F\u9650\u5236", queued.sourceHash));
|
|
23059
|
+
return;
|
|
23060
|
+
}
|
|
23061
|
+
try {
|
|
23062
|
+
const data = JSON.parse(message.resultJson);
|
|
23063
|
+
if (data !== null && (typeof data !== "object" || Array.isArray(data) || jsonDepth(data) > DATA_TRANSFORM_LIMITS.maxDepth)) {
|
|
23064
|
+
throw new DataTransformError("CARD_TRANSFORM_OUTPUT_INVALID", "\u6570\u636E\u8F6C\u6362\u7ED3\u679C\u5FC5\u987B\u662F JSON \u5BF9\u8C61\u6216 null", queued.sourceHash);
|
|
23065
|
+
}
|
|
23066
|
+
queued.resolve({
|
|
23067
|
+
data,
|
|
23068
|
+
durationMs: message.durationMs ?? 0,
|
|
23069
|
+
inputBytes: queued.inputBytes,
|
|
23070
|
+
outputBytes,
|
|
23071
|
+
sourceHash: queued.sourceHash
|
|
23072
|
+
});
|
|
23073
|
+
} catch (error) {
|
|
23074
|
+
queued.reject(error instanceof DataTransformError ? error : new DataTransformError("CARD_TRANSFORM_OUTPUT_INVALID", "\u6570\u636E\u8F6C\u6362\u7ED3\u679C\u4E0D\u662F\u6709\u6548 JSON", queued.sourceHash));
|
|
23075
|
+
}
|
|
23076
|
+
}
|
|
23077
|
+
discardSlot(slot) {
|
|
23078
|
+
if (slot.disposed)
|
|
23079
|
+
return;
|
|
23080
|
+
slot.disposed = true;
|
|
23081
|
+
const index = this.slots.indexOf(slot);
|
|
23082
|
+
if (index >= 0)
|
|
23083
|
+
this.slots.splice(index, 1);
|
|
23084
|
+
void slot.worker.terminate();
|
|
23085
|
+
}
|
|
23086
|
+
};
|
|
23087
|
+
function defaultWorkerUrl() {
|
|
23088
|
+
if (typeof __dirname === "string") {
|
|
23089
|
+
return pathToFileURL(join(__dirname, "dataTransformWorker.js"));
|
|
23090
|
+
}
|
|
23091
|
+
const resolver = createRequire(pathToFileURL(join(process.cwd(), "__linkque_worker_resolver__.js")).href);
|
|
23092
|
+
const packageJson = resolver.resolve("@alipay/linkque-agent-runtime/package.json");
|
|
23093
|
+
return pathToFileURL(join(dirname(packageJson), "dist/esm/core/dataTransformWorker.js"));
|
|
23094
|
+
}
|
|
23095
|
+
function jsonDepth(value, depth = 0) {
|
|
23096
|
+
if (value === null || typeof value !== "object")
|
|
23097
|
+
return depth;
|
|
23098
|
+
if (depth > DATA_TRANSFORM_LIMITS.maxDepth)
|
|
23099
|
+
return depth;
|
|
23100
|
+
const children = Array.isArray(value) ? value : Object.values(value);
|
|
23101
|
+
return children.reduce((maximum, child) => Math.max(maximum, jsonDepth(child, depth + 1)), depth);
|
|
23102
|
+
}
|
|
23103
|
+
|
|
22822
23104
|
// ../linkque-agent-runtime/dist/esm/core/types.js
|
|
22823
23105
|
var EDebugLogScope;
|
|
22824
23106
|
(function(EDebugLogScope2) {
|
|
@@ -22857,6 +23139,9 @@ var A2UI_CARD_TRANSFORM_PROFILE = "linkque-structural-v1";
|
|
|
22857
23139
|
var A2UI_CARD_EXPRESSION_MAX_LENGTH = 4096;
|
|
22858
23140
|
var A2UI_CARD_EXPRESSION_MAX_AST_NODES = 512;
|
|
22859
23141
|
var A2UI_CARD_EXPRESSION_MAX_AST_DEPTH = 32;
|
|
23142
|
+
var A2UI_CARD_DATA_TRANSFORM_LANGUAGE = "javascript";
|
|
23143
|
+
var A2UI_CARD_DATA_TRANSFORM_PROFILE = "linkque-card-data-transform-v1";
|
|
23144
|
+
var A2UI_CARD_DATA_TRANSFORM_MAX_SOURCE_BYTES = 32 * 1024;
|
|
22860
23145
|
|
|
22861
23146
|
// ../linkque-agent-data-binding-contract/dist/esm/json.js
|
|
22862
23147
|
var BLOCKED_PATH_SEGMENTS = /* @__PURE__ */ new Set([
|
|
@@ -23248,8 +23533,8 @@ function analyzeA2UIBindings(protocol) {
|
|
|
23248
23533
|
visitValue(component, "", context2);
|
|
23249
23534
|
const children = component.children;
|
|
23250
23535
|
if (isPlainRecord(children) && typeof children.path === "string") {
|
|
23251
|
-
const canonicalPath = canonicalizeBindingPath(children.path);
|
|
23252
|
-
if (!canonicalPath || !isSafeJsonPointer(canonicalPath)) {
|
|
23536
|
+
const canonicalPath = canonicalizeBindingPath(children.path, context2.listRoot);
|
|
23537
|
+
if (!canonicalPath || !isSafeJsonPointer(canonicalPath, true)) {
|
|
23253
23538
|
issues.push(issue2(`card.surfaces.${surfaceId}.components.${component.id}.children.path`, "INVALID_BINDING_PATH", `Invalid list path ${children.path}`));
|
|
23254
23539
|
} else {
|
|
23255
23540
|
occurrences.push({
|
|
@@ -23259,6 +23544,7 @@ function analyzeA2UIBindings(protocol) {
|
|
|
23259
23544
|
propertyPath: "children.path",
|
|
23260
23545
|
rawPath: children.path,
|
|
23261
23546
|
canonicalPath,
|
|
23547
|
+
...context2.listRoot ? { listRoot: context2.listRoot } : {},
|
|
23262
23548
|
usage: "list"
|
|
23263
23549
|
});
|
|
23264
23550
|
}
|
|
@@ -23323,6 +23609,7 @@ function addOccurrence(rawPath, propertyPath, usage, context2) {
|
|
|
23323
23609
|
propertyPath,
|
|
23324
23610
|
rawPath,
|
|
23325
23611
|
canonicalPath,
|
|
23612
|
+
...context2.listRoot ? { listRoot: context2.listRoot } : {},
|
|
23326
23613
|
usage
|
|
23327
23614
|
});
|
|
23328
23615
|
}
|
|
@@ -23419,6 +23706,60 @@ function validateJsonSchemaValue2(schema, value, path2 = "$") {
|
|
|
23419
23706
|
validateValue(schema, value, path2, issues);
|
|
23420
23707
|
return issues;
|
|
23421
23708
|
}
|
|
23709
|
+
function normalizeCardDataValue(schema, value, required = true) {
|
|
23710
|
+
if (value === void 0 || value === null)
|
|
23711
|
+
return required ? value : void 0;
|
|
23712
|
+
let normalized = value;
|
|
23713
|
+
if (schema.type === "string" && (typeof value === "boolean" || typeof value === "number" && Number.isFinite(value))) {
|
|
23714
|
+
normalized = String(value);
|
|
23715
|
+
} else if ((schema.type === "number" || schema.type === "integer") && typeof value === "string") {
|
|
23716
|
+
const text = value.trim();
|
|
23717
|
+
if (/^[+-]?(?:\d+(?:\.\d*)?|\.\d+)(?:[eE][+-]?\d+)?$/u.test(text)) {
|
|
23718
|
+
const number2 = Number(text);
|
|
23719
|
+
if (Number.isFinite(number2) && (schema.type !== "integer" || Number.isSafeInteger(number2))) {
|
|
23720
|
+
normalized = number2;
|
|
23721
|
+
}
|
|
23722
|
+
}
|
|
23723
|
+
} else if (schema.type === "object" && isPlainRecord(value)) {
|
|
23724
|
+
const properties = isPlainRecord(schema.properties) ? schema.properties : {};
|
|
23725
|
+
const requiredKeys = new Set(Array.isArray(schema.required) ? schema.required : []);
|
|
23726
|
+
normalized = Object.fromEntries(Object.entries(value).flatMap(([key, child]) => {
|
|
23727
|
+
const childSchema = properties[key];
|
|
23728
|
+
const next = isPlainRecord(childSchema) ? normalizeCardDataValue(childSchema, child, requiredKeys.has(key)) : child;
|
|
23729
|
+
return next === void 0 ? [] : [[key, next]];
|
|
23730
|
+
}));
|
|
23731
|
+
} else if (schema.type === "array" && Array.isArray(value) && isPlainRecord(schema.items)) {
|
|
23732
|
+
normalized = value.map((child) => normalizeCardDataValue(schema.items, child));
|
|
23733
|
+
}
|
|
23734
|
+
return !required && validateJsonSchemaValue2(schema, normalized).length > 0 ? void 0 : normalized;
|
|
23735
|
+
}
|
|
23736
|
+
function getJsonSchemaAtDataPointer(schema, pointer) {
|
|
23737
|
+
if (!isSafeJsonPointer(pointer, true))
|
|
23738
|
+
return void 0;
|
|
23739
|
+
if (pointer === "/")
|
|
23740
|
+
return schema;
|
|
23741
|
+
return getJsonSchemaAtPath(schema, pointer.slice(1).split("/").map(decodePointerSegment));
|
|
23742
|
+
}
|
|
23743
|
+
function getJsonSchemaAtPath(schema, path2) {
|
|
23744
|
+
let current = schema;
|
|
23745
|
+
for (const segment of path2) {
|
|
23746
|
+
if (!current)
|
|
23747
|
+
return void 0;
|
|
23748
|
+
if (segment === "*" || current.type === "array") {
|
|
23749
|
+
if (!isPlainRecord(current.items))
|
|
23750
|
+
return void 0;
|
|
23751
|
+
current = current.items;
|
|
23752
|
+
if (segment === "*")
|
|
23753
|
+
continue;
|
|
23754
|
+
}
|
|
23755
|
+
if (current.type !== "object" || !isPlainRecord(current.properties)) {
|
|
23756
|
+
return void 0;
|
|
23757
|
+
}
|
|
23758
|
+
const child = current.properties[segment];
|
|
23759
|
+
current = isPlainRecord(child) ? child : void 0;
|
|
23760
|
+
}
|
|
23761
|
+
return current;
|
|
23762
|
+
}
|
|
23422
23763
|
function validateSchemaNode(value, path2, issues, options) {
|
|
23423
23764
|
if (!isPlainRecord(value) || !isJsonValue(value)) {
|
|
23424
23765
|
issues.push(issue2(path2, "INVALID_JSON_SCHEMA", `${path2} must be a JSON object`));
|
|
@@ -23749,7 +24090,8 @@ var decoration = {
|
|
|
23749
24090
|
"primary",
|
|
23750
24091
|
"primary-muted",
|
|
23751
24092
|
"accent",
|
|
23752
|
-
"warning"
|
|
24093
|
+
"warning",
|
|
24094
|
+
"transparent"
|
|
23753
24095
|
]
|
|
23754
24096
|
},
|
|
23755
24097
|
border: {
|
|
@@ -23761,6 +24103,7 @@ var decoration = {
|
|
|
23761
24103
|
var typography = {
|
|
23762
24104
|
color: { kind: "string", values: colors },
|
|
23763
24105
|
fontSize: { kind: "string", values: ["xs", "sm", "md", "lg", "xl", "xxl"] },
|
|
24106
|
+
fontFamily: { kind: "string", values: ["digit", "digit-bold"] },
|
|
23764
24107
|
fontWeight: { kind: "string", values: ["normal", "semibold", "bold"] }
|
|
23765
24108
|
};
|
|
23766
24109
|
var container = {
|
|
@@ -23797,6 +24140,7 @@ var A2UI_V4_COMPONENT_CATALOG = Object.freeze({
|
|
|
23797
24140
|
...layoutItem,
|
|
23798
24141
|
...containerSize,
|
|
23799
24142
|
...decoration,
|
|
24143
|
+
verticalAlign: { kind: "string", values: ["top", "center", "bottom"] },
|
|
23800
24144
|
child: { kind: "child", required: true },
|
|
23801
24145
|
action: { kind: "action" },
|
|
23802
24146
|
disabled: { kind: "boolean" }
|
|
@@ -23831,8 +24175,8 @@ var A2UI_V4_COMPONENT_CATALOG = Object.freeze({
|
|
|
23831
24175
|
shrink: { kind: "boolean" },
|
|
23832
24176
|
text: { kind: "binding", required: true },
|
|
23833
24177
|
maxLines: { kind: "number", values: [0, 1, 2, 3, 4, 5, 6] },
|
|
23834
|
-
|
|
23835
|
-
|
|
24178
|
+
textAlign: { kind: "string", values: ["left", "center", "right"] },
|
|
24179
|
+
decoration: { kind: "string", values: ["line-through"] }
|
|
23836
24180
|
}
|
|
23837
24181
|
},
|
|
23838
24182
|
Tag: {
|
|
@@ -23841,6 +24185,7 @@ var A2UI_V4_COMPONENT_CATALOG = Object.freeze({
|
|
|
23841
24185
|
...layoutItem,
|
|
23842
24186
|
text: { kind: "binding", required: true },
|
|
23843
24187
|
icon: { kind: "string", values: iconNames },
|
|
24188
|
+
image: { kind: "binding" },
|
|
23844
24189
|
tone: {
|
|
23845
24190
|
kind: "string",
|
|
23846
24191
|
values: [
|
|
@@ -23896,7 +24241,20 @@ var A2UI_V4_COMPONENT_CATALOG = Object.freeze({
|
|
|
23896
24241
|
height: { kind: "string", values: ["auto", "fill"] },
|
|
23897
24242
|
size: {
|
|
23898
24243
|
kind: "string",
|
|
23899
|
-
values: [
|
|
24244
|
+
values: [
|
|
24245
|
+
"xs",
|
|
24246
|
+
"sm",
|
|
24247
|
+
"md",
|
|
24248
|
+
"lg",
|
|
24249
|
+
"xl",
|
|
24250
|
+
"full",
|
|
24251
|
+
"text-xs",
|
|
24252
|
+
"text-sm",
|
|
24253
|
+
"text-md",
|
|
24254
|
+
"text-lg",
|
|
24255
|
+
"text-xl",
|
|
24256
|
+
"text-xxl"
|
|
24257
|
+
]
|
|
23900
24258
|
}
|
|
23901
24259
|
}
|
|
23902
24260
|
},
|
|
@@ -23940,7 +24298,6 @@ var A2UI_V4_COMPONENT_CATALOG = Object.freeze({
|
|
|
23940
24298
|
"x2-funds"
|
|
23941
24299
|
]
|
|
23942
24300
|
},
|
|
23943
|
-
format: { kind: "string", values: ["date"] },
|
|
23944
24301
|
validationRegexp: { kind: "string" },
|
|
23945
24302
|
"x2-limit": { kind: "number" }
|
|
23946
24303
|
}
|
|
@@ -24051,14 +24408,6 @@ function validateV4Component(component, componentPath, issues) {
|
|
|
24051
24408
|
issues.push(issue2(`${componentPath}.component`, "UNSUPPORTED_COMPONENT", `V4 does not support component ${component.component}`));
|
|
24052
24409
|
return;
|
|
24053
24410
|
}
|
|
24054
|
-
const allowed = /* @__PURE__ */ new Set([
|
|
24055
|
-
"id",
|
|
24056
|
-
"component",
|
|
24057
|
-
...Object.keys(schema.properties)
|
|
24058
|
-
]);
|
|
24059
|
-
for (const key of Object.keys(component))
|
|
24060
|
-
if (!allowed.has(key))
|
|
24061
|
-
issues.push(issue2(`${componentPath}.${key}`, "UNSUPPORTED_COMPONENT_PROP", `${component.component} does not support property ${key}`));
|
|
24062
24411
|
for (const [name, property] of Object.entries(schema.properties)) {
|
|
24063
24412
|
const value = component[name];
|
|
24064
24413
|
if (property.required && value === void 0)
|
|
@@ -24088,8 +24437,8 @@ function validateV4Component(component, componentPath, issues) {
|
|
|
24088
24437
|
}
|
|
24089
24438
|
if (component.checks !== void 0)
|
|
24090
24439
|
validateChecks(component.checks, `${componentPath}.checks`, issues);
|
|
24091
|
-
if (component.
|
|
24092
|
-
|
|
24440
|
+
if (component.component === "Tag" && component.icon !== void 0 && component.image !== void 0)
|
|
24441
|
+
issues.push(issue2(componentPath, "INVALID_COMPONENT_PROP_VALUE", "Tag icon and image cannot be used together"));
|
|
24093
24442
|
if (component.action !== void 0)
|
|
24094
24443
|
validateAction(component.action, `${componentPath}.action`, issues, 0);
|
|
24095
24444
|
}
|
|
@@ -24114,7 +24463,7 @@ function validateComponents(payload, path2, surfaces, issues) {
|
|
|
24114
24463
|
}
|
|
24115
24464
|
function validateProperty(value, schema, path2, issues, propertyName) {
|
|
24116
24465
|
if (schema.kind === "binding") {
|
|
24117
|
-
const stringOnly = propertyName === "label" || propertyName === "src" || propertyName === "alt";
|
|
24466
|
+
const stringOnly = propertyName === "label" || propertyName === "src" || propertyName === "alt" || propertyName === "image";
|
|
24118
24467
|
const literalValid = typeof value === "string" || !stringOnly && typeof value === "number" && Number.isFinite(value);
|
|
24119
24468
|
if (!literalValid && !isDisplayBinding(value, stringOnly))
|
|
24120
24469
|
issues.push(issue2(path2, "INVALID_DISPLAY_VALUE", `display value must be ${stringOnly ? "a string" : "a string or finite number"}, or a compatible display binding`));
|
|
@@ -24137,10 +24486,10 @@ function validateProperty(value, schema, path2, issues, propertyName) {
|
|
|
24137
24486
|
return;
|
|
24138
24487
|
if (schema.kind === "boolean" && typeof value !== "boolean")
|
|
24139
24488
|
issues.push(issue2(path2, "INVALID_COMPONENT_PROP_TYPE", "value must be boolean"));
|
|
24140
|
-
if (schema.kind === "number" &&
|
|
24141
|
-
issues.push(issue2(path2, "INVALID_COMPONENT_PROP_VALUE", "value
|
|
24142
|
-
if (schema.kind === "string" &&
|
|
24143
|
-
issues.push(issue2(path2, "INVALID_COMPONENT_PROP_VALUE", "value
|
|
24489
|
+
if (schema.kind === "number" && !Number.isFinite(value))
|
|
24490
|
+
issues.push(issue2(path2, "INVALID_COMPONENT_PROP_VALUE", "value must be a finite number"));
|
|
24491
|
+
if (schema.kind === "string" && typeof value !== "string")
|
|
24492
|
+
issues.push(issue2(path2, "INVALID_COMPONENT_PROP_VALUE", "value must be a string"));
|
|
24144
24493
|
}
|
|
24145
24494
|
function isDisplayBinding(value, stringOnly = false) {
|
|
24146
24495
|
if (!isPlainRecord(value) || typeof value.path !== "string" || !isSafePath(value.path))
|
|
@@ -24232,51 +24581,8 @@ function validateClientAction(body, path2, issues) {
|
|
|
24232
24581
|
issues.push(issue2(`${path2}.context.url`, "INVALID_PAGE_URL", "ui.page.open URL must use https or the approved Alipay scheme"));
|
|
24233
24582
|
return;
|
|
24234
24583
|
}
|
|
24235
|
-
if (body.name === "payment.trade-pay") {
|
|
24236
|
-
validatePaymentActionContext(body.context, `${path2}.context`, issues);
|
|
24237
|
-
return;
|
|
24238
|
-
}
|
|
24239
24584
|
issues.push(issue2(`${path2}.name`, "UNSUPPORTED_CLIENT_ACTION", `unsupported client action ${String(body.name)}`));
|
|
24240
24585
|
}
|
|
24241
|
-
function validatePaymentActionContext(value, path2, issues) {
|
|
24242
|
-
if (!isPlainRecord(value)) {
|
|
24243
|
-
issues.push(issue2(path2, "INVALID_CLIENT_ACTION_CONTEXT", "payment.trade-pay requires createTrade and onSuccess"));
|
|
24244
|
-
return;
|
|
24245
|
-
}
|
|
24246
|
-
rejectUnknownKeys(value, ["createTrade", "onSuccess"], path2, issues);
|
|
24247
|
-
const createTrade = isPlainRecord(value.createTrade) ? value.createTrade : void 0;
|
|
24248
|
-
if (!createTrade) {
|
|
24249
|
-
issues.push(issue2(`${path2}.createTrade`, "INVALID_PAYMENT_CREATE_TRADE", "createTrade must be an object"));
|
|
24250
|
-
} else {
|
|
24251
|
-
rejectUnknownKeys(createTrade, ["mcpResourceId", "toolName", "input", "tradeNoPath"], `${path2}.createTrade`, issues);
|
|
24252
|
-
if (!isSafeIdentifier(createTrade.mcpResourceId))
|
|
24253
|
-
issues.push(issue2(`${path2}.createTrade.mcpResourceId`, "INVALID_MCP_RESOURCE_ID", "mcpResourceId is invalid"));
|
|
24254
|
-
if (typeof createTrade.toolName !== "string" || !createTrade.toolName.trim())
|
|
24255
|
-
issues.push(issue2(`${path2}.createTrade.toolName`, "INVALID_TOOL_NAME", "toolName is required"));
|
|
24256
|
-
if (!isPlainRecord(createTrade.input))
|
|
24257
|
-
issues.push(issue2(`${path2}.createTrade.input`, "INVALID_PAYMENT_INPUT", "input must be an object"));
|
|
24258
|
-
else
|
|
24259
|
-
validateActionDynamicValue(createTrade.input, `${path2}.createTrade.input`, issues);
|
|
24260
|
-
if (!isSafeJsonPointer(createTrade.tradeNoPath))
|
|
24261
|
-
issues.push(issue2(`${path2}.createTrade.tradeNoPath`, "INVALID_TRADE_NO_PATH", "tradeNoPath must be an absolute JSON Pointer"));
|
|
24262
|
-
}
|
|
24263
|
-
const onSuccess = isPlainRecord(value.onSuccess) ? value.onSuccess : void 0;
|
|
24264
|
-
const event = onSuccess && isPlainRecord(onSuccess.event) ? onSuccess.event : void 0;
|
|
24265
|
-
if (!onSuccess || !event) {
|
|
24266
|
-
issues.push(issue2(`${path2}.onSuccess`, "INVALID_PAYMENT_SUCCESS_EVENT", "onSuccess.event is required"));
|
|
24267
|
-
return;
|
|
24268
|
-
}
|
|
24269
|
-
rejectUnknownKeys(onSuccess, ["event"], `${path2}.onSuccess`, issues);
|
|
24270
|
-
rejectUnknownKeys(event, ["name", "context", "x2-user-message"], `${path2}.onSuccess.event`, issues);
|
|
24271
|
-
if (typeof event.name !== "string" || !/^[a-z][a-z0-9]*(?:[._-][a-z0-9]+)*$/.test(event.name) || event.name.length > 96)
|
|
24272
|
-
issues.push(issue2(`${path2}.onSuccess.event.name`, "INVALID_ACTION_NAME", "event name is invalid"));
|
|
24273
|
-
if (event.context !== void 0 && !isPlainRecord(event.context))
|
|
24274
|
-
issues.push(issue2(`${path2}.onSuccess.event.context`, "INVALID_ACTION_CONTEXT", "event context must be an object"));
|
|
24275
|
-
else if (event.context !== void 0)
|
|
24276
|
-
validateActionDynamicValue(event.context, `${path2}.onSuccess.event.context`, issues);
|
|
24277
|
-
if (typeof event["x2-user-message"] !== "string" || !event["x2-user-message"].trim())
|
|
24278
|
-
issues.push(issue2(`${path2}.onSuccess.event.x2-user-message`, "INVALID_ACTION_CONTEXT", "x2-user-message must be a non-empty string"));
|
|
24279
|
-
}
|
|
24280
24586
|
function validateActionDynamicValue(value, path2, issues) {
|
|
24281
24587
|
if (Array.isArray(value)) {
|
|
24282
24588
|
value.forEach((entry, index) => validateActionDynamicValue(entry, `${path2}[${index}]`, issues));
|
|
@@ -24321,7 +24627,7 @@ function validateTextField(component, path2, issues) {
|
|
|
24321
24627
|
issues.push(issue2(`${path2}.validationRegexp`, "INVALID_VALIDATION_REGEXP", "validationRegexp is too long"));
|
|
24322
24628
|
else
|
|
24323
24629
|
try {
|
|
24324
|
-
|
|
24630
|
+
RegExp(component.validationRegexp);
|
|
24325
24631
|
} catch {
|
|
24326
24632
|
issues.push(issue2(`${path2}.validationRegexp`, "INVALID_VALIDATION_REGEXP", "validationRegexp is invalid"));
|
|
24327
24633
|
}
|
|
@@ -24372,26 +24678,6 @@ function validateOverflow(component, path2, issues) {
|
|
|
24372
24678
|
}
|
|
24373
24679
|
}
|
|
24374
24680
|
}
|
|
24375
|
-
function validateNumberFormat(value, path2, issues) {
|
|
24376
|
-
if (!isPlainRecord(value))
|
|
24377
|
-
return void issues.push(issue2(path2, "INVALID_NUMBER_FORMAT", "format must be an object"));
|
|
24378
|
-
rejectUnknownKeys(value, [
|
|
24379
|
-
"type",
|
|
24380
|
-
"style",
|
|
24381
|
-
"currency",
|
|
24382
|
-
"locale",
|
|
24383
|
-
"minimumFractionDigits",
|
|
24384
|
-
"maximumFractionDigits",
|
|
24385
|
-
"useGrouping",
|
|
24386
|
-
"prefix",
|
|
24387
|
-
"suffix"
|
|
24388
|
-
], path2, issues);
|
|
24389
|
-
const style = value.style ?? "decimal";
|
|
24390
|
-
const digit = (entry) => entry === void 0 || Number.isInteger(entry) && Number(entry) >= 0 && Number(entry) <= 20;
|
|
24391
|
-
if (value.type !== "number" || !["decimal", "currency", "percent"].includes(String(style)) || style === "currency" && (typeof value.currency !== "string" || !/^[A-Z]{3}$/u.test(value.currency)) || value.locale !== void 0 && typeof value.locale !== "string" || !digit(value.minimumFractionDigits) || !digit(value.maximumFractionDigits) || Number.isInteger(value.minimumFractionDigits) && Number.isInteger(value.maximumFractionDigits) && Number(value.minimumFractionDigits) > Number(value.maximumFractionDigits) || value.useGrouping !== void 0 && typeof value.useGrouping !== "boolean" || value.prefix !== void 0 && (typeof value.prefix !== "string" || value.prefix.length > 32) || value.suffix !== void 0 && (typeof value.suffix !== "string" || value.suffix.length > 32)) {
|
|
24392
|
-
issues.push(issue2(path2, "INVALID_NUMBER_FORMAT", "number format options are invalid"));
|
|
24393
|
-
}
|
|
24394
|
-
}
|
|
24395
24681
|
function rejectUnknownKeys(value, allowed, path2, issues) {
|
|
24396
24682
|
const allowedKeys = new Set(allowed);
|
|
24397
24683
|
Object.keys(value).forEach((key) => {
|
|
@@ -24481,20 +24767,20 @@ function hasInteractiveDescendant(id, components, visited) {
|
|
|
24481
24767
|
}
|
|
24482
24768
|
|
|
24483
24769
|
// ../agent-a2ui-card-contract/dist/esm/validation.js
|
|
24484
|
-
var FIELD_TYPES = [
|
|
24770
|
+
var FIELD_TYPES = /* @__PURE__ */ new Set([
|
|
24485
24771
|
"array",
|
|
24486
24772
|
"boolean",
|
|
24487
24773
|
"integer",
|
|
24488
24774
|
"number",
|
|
24489
24775
|
"object",
|
|
24490
24776
|
"string"
|
|
24491
|
-
];
|
|
24492
|
-
var FIELD_SOURCES = [
|
|
24777
|
+
]);
|
|
24778
|
+
var FIELD_SOURCES = /* @__PURE__ */ new Set([
|
|
24493
24779
|
"business",
|
|
24494
24780
|
"invocation",
|
|
24495
24781
|
"runtime-context",
|
|
24496
24782
|
"local"
|
|
24497
|
-
];
|
|
24783
|
+
]);
|
|
24498
24784
|
var RUNTIME_CONTEXT_KEYS = /* @__PURE__ */ new Set([
|
|
24499
24785
|
"agentId",
|
|
24500
24786
|
"tenantId",
|
|
@@ -24539,6 +24825,9 @@ function getA2UICardResourceConfigIssues(value) {
|
|
|
24539
24825
|
];
|
|
24540
24826
|
}
|
|
24541
24827
|
const issues = [];
|
|
24828
|
+
if (value.schemaVersion === "4" && value.dataMode === "pipeline") {
|
|
24829
|
+
return getA2UICardResourceConfigV4PipelineIssues(value);
|
|
24830
|
+
}
|
|
24542
24831
|
if (value.schemaVersion === "3" || value.schemaVersion === "4") {
|
|
24543
24832
|
return getA2UICardResourceConfigV3Issues(value);
|
|
24544
24833
|
}
|
|
@@ -24573,6 +24862,50 @@ function getA2UICardResourceConfigIssues(value) {
|
|
|
24573
24862
|
validateResolverCoverage(fields, resolver, issues, card);
|
|
24574
24863
|
return issues;
|
|
24575
24864
|
}
|
|
24865
|
+
function getA2UICardResourceConfigV4PipelineIssues(value) {
|
|
24866
|
+
const issues = [];
|
|
24867
|
+
exactKeys(value, [
|
|
24868
|
+
"schemaVersion",
|
|
24869
|
+
"dataMode",
|
|
24870
|
+
"revision",
|
|
24871
|
+
"displayName",
|
|
24872
|
+
"description",
|
|
24873
|
+
"whenToUse",
|
|
24874
|
+
"whenNotToUse",
|
|
24875
|
+
"presentationInputSchema",
|
|
24876
|
+
"fields",
|
|
24877
|
+
"dataSources",
|
|
24878
|
+
"dataTransform",
|
|
24879
|
+
"dataModelSchema",
|
|
24880
|
+
"a2uiTemplate"
|
|
24881
|
+
], "config", issues);
|
|
24882
|
+
if (value.schemaVersion !== "4" || value.dataMode !== "pipeline") {
|
|
24883
|
+
issues.push(issue2("config.dataMode", "INVALID_DATA_MODE", "pipeline cards require schemaVersion 4 and dataMode pipeline"));
|
|
24884
|
+
}
|
|
24885
|
+
if (!isSafeIdentifier(value.revision)) {
|
|
24886
|
+
issues.push(issue2("config.revision", "INVALID_CARD_REVISION", "revision must be a stable safe identifier"));
|
|
24887
|
+
}
|
|
24888
|
+
requiredString(value.displayName, "config.displayName", issues);
|
|
24889
|
+
requiredString(value.description, "config.description", issues);
|
|
24890
|
+
requiredString(value.whenToUse, "config.whenToUse", issues);
|
|
24891
|
+
optionalString(value.whenNotToUse, "config.whenNotToUse", issues);
|
|
24892
|
+
validateLooseJsonSchema(value.presentationInputSchema, "config.presentationInputSchema", issues);
|
|
24893
|
+
const fields = validateFields(value.fields, "config.fields", issues);
|
|
24894
|
+
validatePipelineDataSources(value.dataSources, "config.dataSources", issues);
|
|
24895
|
+
validateDataTransform(value.dataTransform, "config.dataTransform", issues);
|
|
24896
|
+
const dataModelSchema = validateLooseJsonSchema(value.dataModelSchema, "config.dataModelSchema", issues);
|
|
24897
|
+
const card = validateTemplate(value.a2uiTemplate, fields, issues);
|
|
24898
|
+
if (card) {
|
|
24899
|
+
issues.push(...getA2UIV4ProtocolIssues(card, "config.a2uiTemplate.content"), ...getPersistedV4ProtocolIssues(card, "config.a2uiTemplate.content"));
|
|
24900
|
+
}
|
|
24901
|
+
if (fields && dataModelSchema) {
|
|
24902
|
+
validatePipelineFieldSchemas(fields, value.dataModelSchema, issues);
|
|
24903
|
+
}
|
|
24904
|
+
if (dataModelSchema && isPlainRecord(value.a2uiTemplate) && stableJsonStringify(value.a2uiTemplate.argsSchema) !== stableJsonStringify(value.dataModelSchema)) {
|
|
24905
|
+
issues.push(issue2("config.a2uiTemplate.argsSchema", "DATA_MODEL_SCHEMA_MISMATCH", "a2uiTemplate.argsSchema must equal dataModelSchema"));
|
|
24906
|
+
}
|
|
24907
|
+
return issues;
|
|
24908
|
+
}
|
|
24576
24909
|
function getA2UICardResourceConfigV3Issues(value) {
|
|
24577
24910
|
const issues = [];
|
|
24578
24911
|
if (value.actionBindings !== void 0) {
|
|
@@ -24684,6 +25017,87 @@ function validateDataSources(value, path2, issues, options = {}) {
|
|
|
24684
25017
|
}
|
|
24685
25018
|
return value;
|
|
24686
25019
|
}
|
|
25020
|
+
function validatePipelineDataSources(value, path2, issues) {
|
|
25021
|
+
if (!Array.isArray(value) || value.length === 0) {
|
|
25022
|
+
issues.push(issue2(path2, "INVALID_DATA_SOURCES", "pipeline dataSources must be a non-empty array"));
|
|
25023
|
+
return void 0;
|
|
25024
|
+
}
|
|
25025
|
+
const ids = /* @__PURE__ */ new Set();
|
|
25026
|
+
value.forEach((candidate, index) => {
|
|
25027
|
+
const itemPath = `${path2}[${index}]`;
|
|
25028
|
+
if (!isPlainRecord(candidate)) {
|
|
25029
|
+
issues.push(issue2(itemPath, "INVALID_DATA_SOURCE", "data source must be an object"));
|
|
25030
|
+
return;
|
|
25031
|
+
}
|
|
25032
|
+
exactKeys(candidate, [
|
|
25033
|
+
"sourceId",
|
|
25034
|
+
"mcpResourceId",
|
|
25035
|
+
"toolName",
|
|
25036
|
+
"purpose",
|
|
25037
|
+
"fixedInput",
|
|
25038
|
+
"inputBindings",
|
|
25039
|
+
"inputSchema",
|
|
25040
|
+
"outputSchema"
|
|
25041
|
+
], itemPath, issues);
|
|
25042
|
+
if (!isSafeIdentifier(candidate.sourceId)) {
|
|
25043
|
+
issues.push(issue2(`${itemPath}.sourceId`, "INVALID_SOURCE_ID", "sourceId is invalid"));
|
|
25044
|
+
} else if (ids.has(candidate.sourceId)) {
|
|
25045
|
+
issues.push(issue2(`${itemPath}.sourceId`, "DUPLICATE_SOURCE_ID", `sourceId ${candidate.sourceId} is duplicated`));
|
|
25046
|
+
} else {
|
|
25047
|
+
ids.add(candidate.sourceId);
|
|
25048
|
+
}
|
|
25049
|
+
if (!isSafeIdentifier(candidate.mcpResourceId)) {
|
|
25050
|
+
issues.push(issue2(`${itemPath}.mcpResourceId`, "INVALID_MCP_RESOURCE_ID", "mcpResourceId is invalid"));
|
|
25051
|
+
}
|
|
25052
|
+
requiredString(candidate.toolName, `${itemPath}.toolName`, issues);
|
|
25053
|
+
requiredString(candidate.purpose, `${itemPath}.purpose`, issues);
|
|
25054
|
+
if (!isPlainRecord(candidate.fixedInput) || !isJsonValue(candidate.fixedInput)) {
|
|
25055
|
+
issues.push(issue2(`${itemPath}.fixedInput`, "INVALID_FIXED_INPUT", "fixedInput must be a JSON object"));
|
|
25056
|
+
}
|
|
25057
|
+
const inputBindings = validateInputBindings(candidate.inputBindings, `${itemPath}.inputBindings`, issues);
|
|
25058
|
+
if (isPlainRecord(candidate.fixedInput) && inputBindings) {
|
|
25059
|
+
for (let bindingIndex = 0; bindingIndex < inputBindings.length; bindingIndex += 1) {
|
|
25060
|
+
const binding = inputBindings[bindingIndex];
|
|
25061
|
+
if (hasOverlappingJsonPointer(candidate.fixedInput, binding.inputPath)) {
|
|
25062
|
+
issues.push(issue2(`${itemPath}.inputBindings[${bindingIndex}].inputPath`, "FIXED_INPUT_OVERRIDE", `dynamic input ${binding.inputPath} overlaps a fixed input and cannot override it`));
|
|
25063
|
+
}
|
|
25064
|
+
}
|
|
25065
|
+
}
|
|
25066
|
+
validateLooseJsonSchema(candidate.inputSchema, `${itemPath}.inputSchema`, issues);
|
|
25067
|
+
validateLooseJsonSchema(candidate.outputSchema, `${itemPath}.outputSchema`, issues);
|
|
25068
|
+
});
|
|
25069
|
+
return value;
|
|
25070
|
+
}
|
|
25071
|
+
function validateDataTransform(value, path2, issues) {
|
|
25072
|
+
if (!isPlainRecord(value)) {
|
|
25073
|
+
issues.push(issue2(path2, "INVALID_DATA_TRANSFORM", "dataTransform must be an object"));
|
|
25074
|
+
return;
|
|
25075
|
+
}
|
|
25076
|
+
exactKeys(value, ["language", "profile", "source"], path2, issues);
|
|
25077
|
+
if (value.language !== A2UI_CARD_DATA_TRANSFORM_LANGUAGE) {
|
|
25078
|
+
issues.push(issue2(`${path2}.language`, "INVALID_DATA_TRANSFORM_LANGUAGE", `language must be ${A2UI_CARD_DATA_TRANSFORM_LANGUAGE}`));
|
|
25079
|
+
}
|
|
25080
|
+
if (value.profile !== A2UI_CARD_DATA_TRANSFORM_PROFILE) {
|
|
25081
|
+
issues.push(issue2(`${path2}.profile`, "INVALID_DATA_TRANSFORM_PROFILE", `profile must be ${A2UI_CARD_DATA_TRANSFORM_PROFILE}`));
|
|
25082
|
+
}
|
|
25083
|
+
if (typeof value.source !== "string" || value.source.trim().length === 0) {
|
|
25084
|
+
issues.push(issue2(`${path2}.source`, "INVALID_DATA_TRANSFORM_SOURCE", "source must be a non-empty string"));
|
|
25085
|
+
} else if (new TextEncoder().encode(value.source).byteLength > A2UI_CARD_DATA_TRANSFORM_MAX_SOURCE_BYTES) {
|
|
25086
|
+
issues.push(issue2(`${path2}.source`, "DATA_TRANSFORM_SOURCE_TOO_LARGE", `source exceeds ${A2UI_CARD_DATA_TRANSFORM_MAX_SOURCE_BYTES} bytes`));
|
|
25087
|
+
} else if (!/^\s*function\s+transform\s*\(\s*input\s*\)\s*\{/u.test(value.source)) {
|
|
25088
|
+
issues.push(issue2(`${path2}.source`, "INVALID_DATA_TRANSFORM_SOURCE", "source must declare function transform(input) { ... }"));
|
|
25089
|
+
}
|
|
25090
|
+
}
|
|
25091
|
+
function validatePipelineFieldSchemas(fields, dataModelSchema, issues) {
|
|
25092
|
+
fields.forEach((field, index) => {
|
|
25093
|
+
if (field.source !== "business")
|
|
25094
|
+
return;
|
|
25095
|
+
const schema = getJsonSchemaAtDataPointer(dataModelSchema, field.path);
|
|
25096
|
+
if (!schema) {
|
|
25097
|
+
issues.push(issue2(`config.fields[${index}].path`, "DATA_MODEL_FIELD_MISSING", `dataModelSchema does not define ${field.path}`));
|
|
25098
|
+
}
|
|
25099
|
+
});
|
|
25100
|
+
}
|
|
24687
25101
|
function validateV3OutputBindings(value, path2, issues) {
|
|
24688
25102
|
if (!Array.isArray(value)) {
|
|
24689
25103
|
issues.push(issue2(path2, "INVALID_OUTPUT_BINDINGS", "bindings must be an array"));
|
|
@@ -24734,6 +25148,23 @@ function validateV3Coverage(fields, dataSources, bindings, issues, options = {})
|
|
|
24734
25148
|
}
|
|
24735
25149
|
}
|
|
24736
25150
|
}
|
|
25151
|
+
function hasOverlappingJsonPointer(fixedInput, inputPath) {
|
|
25152
|
+
const fixedPaths = [];
|
|
25153
|
+
const visit = (value, path2) => {
|
|
25154
|
+
fixedPaths.push(path2);
|
|
25155
|
+
if (!isPlainRecord(value))
|
|
25156
|
+
return;
|
|
25157
|
+
for (const [key, child] of Object.entries(value)) {
|
|
25158
|
+
const escaped = key.replace(/~/gu, "~0").replace(/\//gu, "~1");
|
|
25159
|
+
visit(child, `${path2}/${escaped}`);
|
|
25160
|
+
}
|
|
25161
|
+
};
|
|
25162
|
+
for (const [key, value] of Object.entries(fixedInput)) {
|
|
25163
|
+
const escaped = key.replace(/~/gu, "~0").replace(/\//gu, "~1");
|
|
25164
|
+
visit(value, `/${escaped}`);
|
|
25165
|
+
}
|
|
25166
|
+
return fixedPaths.some((fixedPath) => fixedPath === inputPath || fixedPath.startsWith(`${inputPath}/`) || inputPath.startsWith(`${fixedPath}/`));
|
|
25167
|
+
}
|
|
24737
25168
|
function validateFields(value, path2, issues) {
|
|
24738
25169
|
if (!Array.isArray(value)) {
|
|
24739
25170
|
issues.push(issue2(path2, "INVALID_FIELDS", `${path2} must be an array`));
|
|
@@ -24778,13 +25209,13 @@ function validateFields(value, path2, issues) {
|
|
|
24778
25209
|
paths.add(canonicalPath);
|
|
24779
25210
|
}
|
|
24780
25211
|
requiredString(candidate.label, `${itemPath}.label`, issues);
|
|
24781
|
-
if (!FIELD_TYPES.
|
|
25212
|
+
if (!FIELD_TYPES.has(candidate.type)) {
|
|
24782
25213
|
issues.push(issue2(`${itemPath}.type`, "INVALID_FIELD_TYPE", "field type is invalid"));
|
|
24783
25214
|
}
|
|
24784
25215
|
if (typeof candidate.required !== "boolean") {
|
|
24785
25216
|
issues.push(issue2(`${itemPath}.required`, "INVALID_FIELD_REQUIRED", "required must be a boolean"));
|
|
24786
25217
|
}
|
|
24787
|
-
if (!FIELD_SOURCES.
|
|
25218
|
+
if (!FIELD_SOURCES.has(candidate.source)) {
|
|
24788
25219
|
issues.push(issue2(`${itemPath}.source`, "INVALID_FIELD_SOURCE", "field source is invalid"));
|
|
24789
25220
|
}
|
|
24790
25221
|
const schemaIssues = getJsonSchemaIssues2(candidate.valueSchema, `${itemPath}.valueSchema`, { requireCompleteStructures: true });
|
|
@@ -25232,6 +25663,7 @@ async function executeA2UICardResolver(input) {
|
|
|
25232
25663
|
return viewModel;
|
|
25233
25664
|
}
|
|
25234
25665
|
function normalizeOptionalNulls(value, schema, required) {
|
|
25666
|
+
value = normalizeCardDataValue(schema, value, required);
|
|
25235
25667
|
if (value === null || value === void 0) {
|
|
25236
25668
|
return required ? value : void 0;
|
|
25237
25669
|
}
|
|
@@ -25242,7 +25674,7 @@ function normalizeOptionalNulls(value, schema, required) {
|
|
|
25242
25674
|
return [];
|
|
25243
25675
|
if (!itemSchema)
|
|
25244
25676
|
return [item];
|
|
25245
|
-
const normalized2 = normalizeOptionalNulls(item, itemSchema,
|
|
25677
|
+
const normalized2 = normalizeOptionalNulls(item, itemSchema, true);
|
|
25246
25678
|
return normalized2 === void 0 ? [] : [normalized2];
|
|
25247
25679
|
});
|
|
25248
25680
|
}
|
|
@@ -25291,80 +25723,12 @@ function valueType2(value) {
|
|
|
25291
25723
|
return typeof value === "object" ? "object" : typeof value;
|
|
25292
25724
|
}
|
|
25293
25725
|
|
|
25294
|
-
// ../agent-a2ui-card-contract/dist/esm/payment-action.js
|
|
25295
|
-
var A2UIActionContractError = class extends Error {
|
|
25296
|
-
constructor(issues) {
|
|
25297
|
-
super(issues.join("; "));
|
|
25298
|
-
Object.defineProperty(this, "issues", {
|
|
25299
|
-
enumerable: true,
|
|
25300
|
-
configurable: true,
|
|
25301
|
-
writable: true,
|
|
25302
|
-
value: issues
|
|
25303
|
-
});
|
|
25304
|
-
Object.defineProperty(this, "code", {
|
|
25305
|
-
enumerable: true,
|
|
25306
|
-
configurable: true,
|
|
25307
|
-
writable: true,
|
|
25308
|
-
value: "A2UI_ACTION_CONTRACT_INVALID"
|
|
25309
|
-
});
|
|
25310
|
-
this.name = "A2UIActionContractError";
|
|
25311
|
-
}
|
|
25312
|
-
};
|
|
25313
|
-
function parseA2UIActionExecuteRequest(value) {
|
|
25314
|
-
const issues = getA2UIActionExecuteRequestIssues(value);
|
|
25315
|
-
if (issues.length)
|
|
25316
|
-
throw new A2UIActionContractError(issues);
|
|
25317
|
-
return JSON.parse(JSON.stringify(value));
|
|
25318
|
-
}
|
|
25319
|
-
function getA2UIActionExecuteRequestIssues(value) {
|
|
25320
|
-
if (!isPlainRecord(value))
|
|
25321
|
-
return ["request must be an object"];
|
|
25322
|
-
const issues = [];
|
|
25323
|
-
rejectExtraKeys(value, ["schemaVersion", "agentId", "threadId", "invocationId", "source", "input"], "request", issues);
|
|
25324
|
-
if (value.schemaVersion !== "2")
|
|
25325
|
-
issues.push("schemaVersion must be 2");
|
|
25326
|
-
requiredIdentifier(value.agentId, "agentId", issues);
|
|
25327
|
-
requiredIdentifier(value.threadId, "threadId", issues);
|
|
25328
|
-
requiredIdentifier(value.invocationId, "invocationId", issues);
|
|
25329
|
-
validateSource(value.source, issues);
|
|
25330
|
-
if (!cloneJsonObject(value.input))
|
|
25331
|
-
issues.push("input must be a JSON object");
|
|
25332
|
-
return issues;
|
|
25333
|
-
}
|
|
25334
|
-
function validateSource(value, issues) {
|
|
25335
|
-
if (!isPlainRecord(value)) {
|
|
25336
|
-
issues.push("source must be an object");
|
|
25337
|
-
return;
|
|
25338
|
-
}
|
|
25339
|
-
rejectExtraKeys(value, ["cardRef", "cardRevision", "cardInstanceId", "surfaceId", "componentId"], "source", issues);
|
|
25340
|
-
requiredIdentifier(value.cardRef, "source.cardRef", issues);
|
|
25341
|
-
requiredIdentifier(value.cardRevision, "source.cardRevision", issues);
|
|
25342
|
-
requiredText(value.cardInstanceId, "source.cardInstanceId", issues);
|
|
25343
|
-
requiredIdentifier(value.surfaceId, "source.surfaceId", issues);
|
|
25344
|
-
requiredIdentifier(value.componentId, "source.componentId", issues);
|
|
25345
|
-
}
|
|
25346
|
-
function rejectExtraKeys(value, allowed, path2, issues) {
|
|
25347
|
-
const allowedKeys = new Set(allowed);
|
|
25348
|
-
for (const key of Object.keys(value))
|
|
25349
|
-
if (!allowedKeys.has(key))
|
|
25350
|
-
issues.push(`${path2}.${key} is not allowed`);
|
|
25351
|
-
}
|
|
25352
|
-
function requiredIdentifier(value, path2, issues) {
|
|
25353
|
-
if (!isSafeIdentifier(value))
|
|
25354
|
-
issues.push(`${path2} must be a safe identifier`);
|
|
25355
|
-
}
|
|
25356
|
-
function requiredText(value, path2, issues) {
|
|
25357
|
-
if (typeof value !== "string" || !value.trim() || value.length > 256) {
|
|
25358
|
-
issues.push(`${path2} must be a non-empty string up to 256 characters`);
|
|
25359
|
-
}
|
|
25360
|
-
}
|
|
25361
|
-
|
|
25362
25726
|
// ../agent-a2ui-card-contract/dist/esm/function-action.js
|
|
25363
25727
|
function parseA2UIFunctionMcpExecuteRequest(value) {
|
|
25364
25728
|
const issues = [];
|
|
25365
25729
|
if (!isPlainRecord(value))
|
|
25366
25730
|
throw new Error("request must be an object");
|
|
25367
|
-
|
|
25731
|
+
rejectExtraKeys(value, [
|
|
25368
25732
|
"schemaVersion",
|
|
25369
25733
|
"agentId",
|
|
25370
25734
|
"threadId",
|
|
@@ -25392,15 +25756,15 @@ function parseA2UIFunctionMcpExecuteRequest(value) {
|
|
|
25392
25756
|
if (!isPlainRecord(value.action))
|
|
25393
25757
|
issues.push("action must be an object");
|
|
25394
25758
|
else {
|
|
25395
|
-
|
|
25759
|
+
rejectExtraKeys(value.action, ["ref"], "action", issues);
|
|
25396
25760
|
if (!isFunctionRef(value.action.ref))
|
|
25397
25761
|
issues.push("action.ref is invalid");
|
|
25398
25762
|
}
|
|
25399
|
-
|
|
25763
|
+
validateSource(value.source, issues);
|
|
25400
25764
|
if (!isPlainRecord(value.tool))
|
|
25401
25765
|
issues.push("tool must be an object");
|
|
25402
25766
|
else {
|
|
25403
|
-
|
|
25767
|
+
rejectExtraKeys(value.tool, ["mcpResourceId", "toolName", "input"], "tool", issues);
|
|
25404
25768
|
if (!isSafeIdentifier(value.tool.mcpResourceId))
|
|
25405
25769
|
issues.push("tool.mcpResourceId is invalid");
|
|
25406
25770
|
if (!isSafeIdentifier(value.tool.toolName))
|
|
@@ -25412,10 +25776,10 @@ function parseA2UIFunctionMcpExecuteRequest(value) {
|
|
|
25412
25776
|
throw new Error(issues.join("; "));
|
|
25413
25777
|
return JSON.parse(JSON.stringify(value));
|
|
25414
25778
|
}
|
|
25415
|
-
function
|
|
25779
|
+
function validateSource(value, issues) {
|
|
25416
25780
|
if (!isPlainRecord(value))
|
|
25417
25781
|
return void issues.push("source must be an object");
|
|
25418
|
-
|
|
25782
|
+
rejectExtraKeys(value, ["cardRef", "cardRevision", "cardInstanceId", "surfaceId", "componentId"], "source", issues);
|
|
25419
25783
|
for (const key of [
|
|
25420
25784
|
"cardRef",
|
|
25421
25785
|
"cardRevision",
|
|
@@ -25432,7 +25796,7 @@ function validateSource2(value, issues) {
|
|
|
25432
25796
|
function isFunctionRef(value) {
|
|
25433
25797
|
return typeof value === "string" && value.length <= 128 && /^[a-z][a-z0-9]*(?:[._-][a-z0-9]+)*$/u.test(value);
|
|
25434
25798
|
}
|
|
25435
|
-
function
|
|
25799
|
+
function rejectExtraKeys(value, allowed, path2, issues) {
|
|
25436
25800
|
const keys = new Set(allowed);
|
|
25437
25801
|
for (const key of Object.keys(value)) {
|
|
25438
25802
|
if (!keys.has(key))
|
|
@@ -25557,10 +25921,10 @@ function truncateText(value) {
|
|
|
25557
25921
|
}
|
|
25558
25922
|
|
|
25559
25923
|
// ../linkque-agent-runtime/dist/esm/core/mcpNaming.js
|
|
25560
|
-
import { createHash } from "node:crypto";
|
|
25924
|
+
import { createHash as createHash2 } from "node:crypto";
|
|
25561
25925
|
function stableToolName(prefix, raw) {
|
|
25562
25926
|
const readable = raw.replace(/[^A-Za-z0-9_-]+/gu, "_").replace(/^_+|_+$/gu, "").slice(0, 38) || "resource";
|
|
25563
|
-
const digest =
|
|
25927
|
+
const digest = createHash2("sha256").update(raw).digest("hex").slice(0, 10);
|
|
25564
25928
|
return `${prefix}_${readable}_${digest}`;
|
|
25565
25929
|
}
|
|
25566
25930
|
|
|
@@ -25699,6 +26063,9 @@ async function executeCardPresentationFromSources(resource, runtimeContext, sour
|
|
|
25699
26063
|
if (config.schemaVersion !== "3" && config.schemaVersion !== "4") {
|
|
25700
26064
|
throw new Error("Source-result rendering is only available for schema v3/v4 cards");
|
|
25701
26065
|
}
|
|
26066
|
+
if (config.schemaVersion === "4" && config.dataMode === "pipeline") {
|
|
26067
|
+
throw new Error("Pipeline cards must be executed through the aggregate pipeline tool");
|
|
26068
|
+
}
|
|
25702
26069
|
const missing = config.dataSources.filter((source) => source.required && !sourceResults.has(source.sourceId)).map((source) => source.sourceId);
|
|
25703
26070
|
if (missing.length) {
|
|
25704
26071
|
throw new Error(`Required card data sources are incomplete: ${missing.join(", ")}`);
|
|
@@ -25820,6 +26187,11 @@ function isAgentPresentationToolResult(value) {
|
|
|
25820
26187
|
return false;
|
|
25821
26188
|
return value.type === "linkque.presentation-tool-result" && typeof value.modelText === "string" && isJsonObject(value.card) && value.card.type === "a2ui_card";
|
|
25822
26189
|
}
|
|
26190
|
+
function isAgentPresentationSkippedToolResult(value) {
|
|
26191
|
+
if (!isJsonObject(value) || !isJsonObject(value.receipt))
|
|
26192
|
+
return false;
|
|
26193
|
+
return value.type === "linkque.presentation-skipped-tool-result" && typeof value.modelText === "string" && value.receipt.status === "skipped";
|
|
26194
|
+
}
|
|
25823
26195
|
function injectResolvedViewModel(protocol, viewModel) {
|
|
25824
26196
|
const analysis = analyzeA2UIBindings(protocol);
|
|
25825
26197
|
const declaredSurfaceIds = analysis.surfaceIds;
|
|
@@ -25941,7 +26313,7 @@ function isJsonObject(value) {
|
|
|
25941
26313
|
}
|
|
25942
26314
|
|
|
25943
26315
|
// ../linkque-agent-runtime/dist/esm/core/mcpAggregator.js
|
|
25944
|
-
function aggregateMcpServers(
|
|
26316
|
+
function aggregateMcpServers(mcpResources, mcpToolResources, protocolAgentId) {
|
|
25945
26317
|
const specs = /* @__PURE__ */ new Map();
|
|
25946
26318
|
const touch = (serverName) => {
|
|
25947
26319
|
let spec = specs.get(serverName);
|
|
@@ -25960,7 +26332,7 @@ function aggregateMcpServers(resources, protocolAgentId) {
|
|
|
25960
26332
|
}
|
|
25961
26333
|
return spec;
|
|
25962
26334
|
};
|
|
25963
|
-
|
|
26335
|
+
const collectBase = (resource) => {
|
|
25964
26336
|
const serverName = resource.config.serverName ?? resource.resourceId;
|
|
25965
26337
|
const spec = touch(serverName);
|
|
25966
26338
|
spec.resourceIds.push(resource.resourceId);
|
|
@@ -25969,23 +26341,27 @@ function aggregateMcpServers(resources, protocolAgentId) {
|
|
|
25969
26341
|
}
|
|
25970
26342
|
if (!spec.description)
|
|
25971
26343
|
spec.description = resource.config.description;
|
|
25972
|
-
|
|
25973
|
-
|
|
25974
|
-
|
|
25975
|
-
|
|
25976
|
-
|
|
25977
|
-
|
|
25978
|
-
|
|
25979
|
-
|
|
25980
|
-
|
|
25981
|
-
|
|
25982
|
-
|
|
25983
|
-
|
|
25984
|
-
|
|
25985
|
-
spec.
|
|
26344
|
+
return spec;
|
|
26345
|
+
};
|
|
26346
|
+
for (const resource of mcpResources) {
|
|
26347
|
+
const spec = collectBase(resource);
|
|
26348
|
+
for (const rule of resource.config.argsMappingRules ?? []) {
|
|
26349
|
+
spec.argsMappingRules.push(rule);
|
|
26350
|
+
}
|
|
26351
|
+
const allowed = resource.config.allowedTools;
|
|
26352
|
+
if (allowed && allowed.length > 0) {
|
|
26353
|
+
if (!spec.allowedTools)
|
|
26354
|
+
spec.allowedTools = /* @__PURE__ */ new Set();
|
|
26355
|
+
for (const toolName of allowed) {
|
|
26356
|
+
spec.allowedTools.add(toolName);
|
|
26357
|
+
addToolResourceId(spec.resourceIdsByTool, toolName, resource.resourceId);
|
|
25986
26358
|
}
|
|
25987
|
-
|
|
26359
|
+
} else {
|
|
26360
|
+
spec.allToolResourceIds.push(resource.resourceId);
|
|
25988
26361
|
}
|
|
26362
|
+
}
|
|
26363
|
+
for (const resource of mcpToolResources) {
|
|
26364
|
+
const spec = collectBase(resource);
|
|
25989
26365
|
if (!spec.allowedTools)
|
|
25990
26366
|
spec.allowedTools = /* @__PURE__ */ new Set();
|
|
25991
26367
|
spec.allowedTools.add(resource.config.toolName);
|
|
@@ -26055,6 +26431,22 @@ function resolvePhoneAuthorizationDependency(protocol, resourceIds, toolName) {
|
|
|
26055
26431
|
var CONTENT_VALUE_MAX_LENGTH = 16 * 1024;
|
|
26056
26432
|
var ETelemetryAttribute;
|
|
26057
26433
|
(function(ETelemetryAttribute2) {
|
|
26434
|
+
ETelemetryAttribute2["LINKQUE_REMOTE_TRACE_ID"] = "linkque.remote.trace_id";
|
|
26435
|
+
ETelemetryAttribute2["LINKQUE_REMOTE_TRACE_ID_HEADER"] = "linkque.remote.trace_id_header";
|
|
26436
|
+
ETelemetryAttribute2["HTTP_REQUEST_METHOD"] = "http.request.method";
|
|
26437
|
+
ETelemetryAttribute2["SERVER_ADDRESS"] = "server.address";
|
|
26438
|
+
ETelemetryAttribute2["URL_PATH"] = "url.path";
|
|
26439
|
+
ETelemetryAttribute2["LINKQUE_MCP_PHASE"] = "linkque.mcp.phase";
|
|
26440
|
+
ETelemetryAttribute2["LINKQUE_MCP_SERVER_NAME"] = "linkque.mcp.server_name";
|
|
26441
|
+
ETelemetryAttribute2["LINKQUE_IO_ATTEMPT"] = "linkque.io.attempt";
|
|
26442
|
+
ETelemetryAttribute2["LINKQUE_SKILL_RESOURCE_ID"] = "linkque.skill.resource_id";
|
|
26443
|
+
ETelemetryAttribute2["LINKQUE_SKILL_REQUESTED_COUNT"] = "linkque.skill.requested_count";
|
|
26444
|
+
ETelemetryAttribute2["LINKQUE_SKILL_RESOLVED_COUNT"] = "linkque.skill.resolved_count";
|
|
26445
|
+
ETelemetryAttribute2["LINKQUE_SKILL_LOADED_COUNT"] = "linkque.skill.loaded_count";
|
|
26446
|
+
ETelemetryAttribute2["LINKQUE_SKILL_SKIPPED_COUNT"] = "linkque.skill.skipped_count";
|
|
26447
|
+
ETelemetryAttribute2["LINKQUE_CHUNK_INDEX"] = "linkque.chunk.index";
|
|
26448
|
+
ETelemetryAttribute2["LINKQUE_CHUNK_STATUS"] = "linkque.chunk.status";
|
|
26449
|
+
ETelemetryAttribute2["LINKQUE_CHUNK_LINE_COUNT"] = "linkque.chunk.line_count";
|
|
26058
26450
|
ETelemetryAttribute2["HARNESS_TELEMETRY_SCHEMA_VERSION"] = "harness.telemetry.schema.version";
|
|
26059
26451
|
ETelemetryAttribute2["LINKQUE_TELEMETRY_SCHEMA_VERSION"] = "linkque.telemetry.schema.version";
|
|
26060
26452
|
ETelemetryAttribute2["LINKQUE_TELEMETRY_ADAPTER_VERSION"] = "linkque.telemetry.adapter.version";
|
|
@@ -26087,6 +26479,8 @@ var ETelemetryAttribute;
|
|
|
26087
26479
|
ETelemetryAttribute2["HARNESS_RECORD_ID"] = "harness.record.id";
|
|
26088
26480
|
ETelemetryAttribute2["HARNESS_EVENT_SEQUENCE"] = "harness.event.sequence";
|
|
26089
26481
|
ETelemetryAttribute2["ERROR_TYPE"] = "error.type";
|
|
26482
|
+
ETelemetryAttribute2["LINKQUE_APPBASE_RUN_FAILURE_STAGE"] = "linkque.appbase.run.failure_stage";
|
|
26483
|
+
ETelemetryAttribute2["LINKQUE_APPBASE_RUN_ERROR_MESSAGE"] = "linkque.appbase.run.error_message";
|
|
26090
26484
|
ETelemetryAttribute2["LINKQUE_STREAM_TERMINATION"] = "linkque.stream.termination";
|
|
26091
26485
|
ETelemetryAttribute2["LINKQUE_STREAM_CANCEL_SOURCE"] = "linkque.stream.cancel_source";
|
|
26092
26486
|
ETelemetryAttribute2["LINKQUE_TERMINAL_EVIDENCE"] = "linkque.terminal.evidence";
|
|
@@ -26249,6 +26643,18 @@ var ETelemetryContentSection;
|
|
|
26249
26643
|
})(ETelemetryContentSection || (ETelemetryContentSection = {}));
|
|
26250
26644
|
var ETelemetryOperationName;
|
|
26251
26645
|
(function(ETelemetryOperationName2) {
|
|
26646
|
+
ETelemetryOperationName2["APPBASE_RUN"] = "linkque.appbase.run";
|
|
26647
|
+
ETelemetryOperationName2["RUNS_WRITE"] = "linkque.appbase.runs.write";
|
|
26648
|
+
ETelemetryOperationName2["MCP_DISCOVER"] = "linkque.mcp.discover";
|
|
26649
|
+
ETelemetryOperationName2["MCP_SIGN"] = "linkque.mcp.sign";
|
|
26650
|
+
ETelemetryOperationName2["MCP_OPENGW"] = "linkque.mcp.opengw";
|
|
26651
|
+
ETelemetryOperationName2["MCP_VERIFY"] = "linkque.mcp.verify";
|
|
26652
|
+
ETelemetryOperationName2["KNOWLEDGE_SEARCH"] = "linkque.knowledge.search";
|
|
26653
|
+
ETelemetryOperationName2["WEB_SEARCH"] = "linkque.web_search.search";
|
|
26654
|
+
ETelemetryOperationName2["SKILL_LOAD"] = "linkque.skill.load";
|
|
26655
|
+
ETelemetryOperationName2["SKILL_QUERY"] = "linkque.skill.query";
|
|
26656
|
+
ETelemetryOperationName2["SKILL_RESOURCE_LOAD"] = "linkque.skill.resource.load";
|
|
26657
|
+
ETelemetryOperationName2["SKILL_DOWNLOAD"] = "linkque.skill.download";
|
|
26252
26658
|
ETelemetryOperationName2["OPERATION"] = "linkque.operation";
|
|
26253
26659
|
ETelemetryOperationName2["TOOL_INVOKE"] = "harness.tool.invoke";
|
|
26254
26660
|
ETelemetryOperationName2["ADVANCE"] = "harness.advance";
|
|
@@ -26394,6 +26800,9 @@ var ETelemetryModelPurpose;
|
|
|
26394
26800
|
})(ETelemetryModelPurpose || (ETelemetryModelPurpose = {}));
|
|
26395
26801
|
var ETelemetryErrorType;
|
|
26396
26802
|
(function(ETelemetryErrorType2) {
|
|
26803
|
+
ETelemetryErrorType2["IO_ERROR"] = "io_error";
|
|
26804
|
+
ETelemetryErrorType2["IO_CANCELLED"] = "io_cancelled";
|
|
26805
|
+
ETelemetryErrorType2["IO_TIMEOUT"] = "io_timeout";
|
|
26397
26806
|
ETelemetryErrorType2["PROVIDER_STREAM_ERROR"] = "ProviderStreamError";
|
|
26398
26807
|
ETelemetryErrorType2["TOOL_EXECUTION_ERROR"] = "ToolExecutionError";
|
|
26399
26808
|
ETelemetryErrorType2["HOOK_DISPATCH_ERROR"] = "HookDispatchError";
|
|
@@ -26404,6 +26813,16 @@ var ETelemetrySpanKind;
|
|
|
26404
26813
|
ETelemetrySpanKind2["INTERNAL"] = "internal";
|
|
26405
26814
|
ETelemetrySpanKind2["CLIENT"] = "client";
|
|
26406
26815
|
})(ETelemetrySpanKind || (ETelemetrySpanKind = {}));
|
|
26816
|
+
var ETelemetryMcpPhase;
|
|
26817
|
+
(function(ETelemetryMcpPhase2) {
|
|
26818
|
+
ETelemetryMcpPhase2["SSE_CONNECT"] = "sse_connect";
|
|
26819
|
+
ETelemetryMcpPhase2["INITIALIZE"] = "initialize";
|
|
26820
|
+
ETelemetryMcpPhase2["TOOLS_LIST"] = "tools/list";
|
|
26821
|
+
ETelemetryMcpPhase2["TOOLS_CALL"] = "tools/call";
|
|
26822
|
+
ETelemetryMcpPhase2["INITIALIZED"] = "notifications/initialized";
|
|
26823
|
+
ETelemetryMcpPhase2["CANCELLED"] = "notifications/cancelled";
|
|
26824
|
+
ETelemetryMcpPhase2["HTTP"] = "http";
|
|
26825
|
+
})(ETelemetryMcpPhase || (ETelemetryMcpPhase = {}));
|
|
26407
26826
|
var ETelemetryGenAiOperation;
|
|
26408
26827
|
(function(ETelemetryGenAiOperation2) {
|
|
26409
26828
|
ETelemetryGenAiOperation2["CHAT"] = "chat";
|
|
@@ -26416,6 +26835,306 @@ var ETelemetryVersion;
|
|
|
26416
26835
|
ETelemetryVersion2["V1_0"] = "1.0";
|
|
26417
26836
|
})(ETelemetryVersion || (ETelemetryVersion = {}));
|
|
26418
26837
|
|
|
26838
|
+
// ../linkque-agent-runtime/dist/esm/core/telemetry/noopRuntimeTelemetry.js
|
|
26839
|
+
var NoopRuntimeObservation = class {
|
|
26840
|
+
enabled = false;
|
|
26841
|
+
operationId = "";
|
|
26842
|
+
spanContext = null;
|
|
26843
|
+
captureParent() {
|
|
26844
|
+
return {
|
|
26845
|
+
operationId: "",
|
|
26846
|
+
spanContext: null,
|
|
26847
|
+
startOperation: () => this,
|
|
26848
|
+
release: () => {
|
|
26849
|
+
}
|
|
26850
|
+
};
|
|
26851
|
+
}
|
|
26852
|
+
startOperation(_operation) {
|
|
26853
|
+
return this;
|
|
26854
|
+
}
|
|
26855
|
+
record(_name, _attributes, _body) {
|
|
26856
|
+
}
|
|
26857
|
+
finish(_outcome, _attributes) {
|
|
26858
|
+
}
|
|
26859
|
+
abandon(_reason) {
|
|
26860
|
+
}
|
|
26861
|
+
};
|
|
26862
|
+
var NoopRuntimeTelemetry = class {
|
|
26863
|
+
startOperation() {
|
|
26864
|
+
return new NoopRuntimeObservation();
|
|
26865
|
+
}
|
|
26866
|
+
startAdvance(_input) {
|
|
26867
|
+
return new NoopRuntimeObservation();
|
|
26868
|
+
}
|
|
26869
|
+
async forceFlush(_options) {
|
|
26870
|
+
return { completed: true, pendingCount: 0, sentCount: 0, droppedCount: 0 };
|
|
26871
|
+
}
|
|
26872
|
+
shutdown(options) {
|
|
26873
|
+
return this.forceFlush(options);
|
|
26874
|
+
}
|
|
26875
|
+
};
|
|
26876
|
+
|
|
26877
|
+
// ../linkque-agent-runtime/dist/esm/utils/skipError.js
|
|
26878
|
+
function skipError(fn) {
|
|
26879
|
+
try {
|
|
26880
|
+
return fn();
|
|
26881
|
+
} catch (err2) {
|
|
26882
|
+
console.error("[observeIo] skipped", err2);
|
|
26883
|
+
}
|
|
26884
|
+
}
|
|
26885
|
+
|
|
26886
|
+
// ../linkque-agent-runtime/dist/esm/core/telemetry/runtimeObservation.js
|
|
26887
|
+
var RuntimeObservation = class _RuntimeObservation {
|
|
26888
|
+
sink;
|
|
26889
|
+
associations;
|
|
26890
|
+
key;
|
|
26891
|
+
scope;
|
|
26892
|
+
finished = false;
|
|
26893
|
+
abandoned = false;
|
|
26894
|
+
resultAttributes = {};
|
|
26895
|
+
constructor(sink, associations = /* @__PURE__ */ new Map(), key, scope = {
|
|
26896
|
+
active: /* @__PURE__ */ new Set(),
|
|
26897
|
+
abandoned: false
|
|
26898
|
+
}) {
|
|
26899
|
+
this.sink = sink;
|
|
26900
|
+
this.associations = associations;
|
|
26901
|
+
this.key = key;
|
|
26902
|
+
this.scope = scope;
|
|
26903
|
+
}
|
|
26904
|
+
get enabled() {
|
|
26905
|
+
try {
|
|
26906
|
+
return this.sink.enabled;
|
|
26907
|
+
} catch {
|
|
26908
|
+
return false;
|
|
26909
|
+
}
|
|
26910
|
+
}
|
|
26911
|
+
get operationId() {
|
|
26912
|
+
try {
|
|
26913
|
+
return this.sink.operationId;
|
|
26914
|
+
} catch {
|
|
26915
|
+
return "";
|
|
26916
|
+
}
|
|
26917
|
+
}
|
|
26918
|
+
get spanContext() {
|
|
26919
|
+
try {
|
|
26920
|
+
return this.sink.spanContext;
|
|
26921
|
+
} catch {
|
|
26922
|
+
return null;
|
|
26923
|
+
}
|
|
26924
|
+
}
|
|
26925
|
+
captureParent() {
|
|
26926
|
+
let parent;
|
|
26927
|
+
try {
|
|
26928
|
+
parent = this.sink.captureParent?.();
|
|
26929
|
+
if (parent) {
|
|
26930
|
+
const captured = parent;
|
|
26931
|
+
let released = false;
|
|
26932
|
+
return {
|
|
26933
|
+
operationId: parent.operationId,
|
|
26934
|
+
spanContext: parent.spanContext,
|
|
26935
|
+
startOperation: (operation) => {
|
|
26936
|
+
try {
|
|
26937
|
+
return new _RuntimeObservation(released || this.abandoned || this.scope.abandoned ? new NoopRuntimeObservation() : captured.startOperation(operation));
|
|
26938
|
+
} catch {
|
|
26939
|
+
return new _RuntimeObservation(new NoopRuntimeObservation());
|
|
26940
|
+
}
|
|
26941
|
+
},
|
|
26942
|
+
release: () => {
|
|
26943
|
+
if (released)
|
|
26944
|
+
return;
|
|
26945
|
+
released = true;
|
|
26946
|
+
skipError(() => captured.release());
|
|
26947
|
+
}
|
|
26948
|
+
};
|
|
26949
|
+
}
|
|
26950
|
+
} catch {
|
|
26951
|
+
skipError(() => parent?.release());
|
|
26952
|
+
}
|
|
26953
|
+
return new NoopRuntimeObservation().captureParent();
|
|
26954
|
+
}
|
|
26955
|
+
startOperation(operation, key) {
|
|
26956
|
+
if (this.scope.abandoned) {
|
|
26957
|
+
return new _RuntimeObservation(new NoopRuntimeObservation());
|
|
26958
|
+
}
|
|
26959
|
+
if (this.scope.active.size >= 4096) {
|
|
26960
|
+
this.record(ETelemetryEventName.OPERATION_OBSERVATION_LOST, {
|
|
26961
|
+
[ETelemetryAttribute.LINKQUE_TELEMETRY_LOSS_REASON]: ETelemetryLossReason.ACTIVE_LIMIT
|
|
26962
|
+
});
|
|
26963
|
+
return new _RuntimeObservation(new NoopRuntimeObservation());
|
|
26964
|
+
}
|
|
26965
|
+
let sink = new NoopRuntimeObservation();
|
|
26966
|
+
skipError(() => {
|
|
26967
|
+
if (!this.enabled) {
|
|
26968
|
+
return;
|
|
26969
|
+
}
|
|
26970
|
+
sink = this.sink.startOperation(operation);
|
|
26971
|
+
});
|
|
26972
|
+
const child = new _RuntimeObservation(sink, this.associations, key, this.scope);
|
|
26973
|
+
if (child.enabled)
|
|
26974
|
+
this.scope.active.add(child);
|
|
26975
|
+
if (key && child.enabled && this.associations.size < 4096)
|
|
26976
|
+
this.associations.set(key, child);
|
|
26977
|
+
return child;
|
|
26978
|
+
}
|
|
26979
|
+
find(key) {
|
|
26980
|
+
return this.associations.get(key);
|
|
26981
|
+
}
|
|
26982
|
+
record(name, attributes, body) {
|
|
26983
|
+
if (this.abandoned)
|
|
26984
|
+
return;
|
|
26985
|
+
skipError(() => {
|
|
26986
|
+
if (attributes[ETelemetryAttribute.LINKQUE_TOOL_FAILURE_STAGE]) {
|
|
26987
|
+
this.resultAttributes = {
|
|
26988
|
+
[ETelemetryAttribute.LINKQUE_TOOL_FAILURE_STAGE]: attributes[ETelemetryAttribute.LINKQUE_TOOL_FAILURE_STAGE]
|
|
26989
|
+
};
|
|
26990
|
+
}
|
|
26991
|
+
this.sink.record(name, attributes, body);
|
|
26992
|
+
});
|
|
26993
|
+
}
|
|
26994
|
+
finish(outcome, attributes) {
|
|
26995
|
+
if (this.finished)
|
|
26996
|
+
return;
|
|
26997
|
+
this.finished = true;
|
|
26998
|
+
this.scope.active.delete(this);
|
|
26999
|
+
if (this.key && this.associations.get(this.key) === this)
|
|
27000
|
+
this.associations.delete(this.key);
|
|
27001
|
+
let result = this.resultAttributes;
|
|
27002
|
+
skipError(() => {
|
|
27003
|
+
result = Object.assign({}, result, attributes);
|
|
27004
|
+
});
|
|
27005
|
+
skipError(() => {
|
|
27006
|
+
this.sink.finish(outcome, result);
|
|
27007
|
+
});
|
|
27008
|
+
}
|
|
27009
|
+
abandon(reason) {
|
|
27010
|
+
if (this.finished)
|
|
27011
|
+
return;
|
|
27012
|
+
this.finished = true;
|
|
27013
|
+
this.abandoned = true;
|
|
27014
|
+
this.scope.active.delete(this);
|
|
27015
|
+
if (this.key && this.associations.get(this.key) === this) {
|
|
27016
|
+
this.associations.delete(this.key);
|
|
27017
|
+
}
|
|
27018
|
+
skipError(() => {
|
|
27019
|
+
this.sink.abandon(reason);
|
|
27020
|
+
});
|
|
27021
|
+
}
|
|
27022
|
+
/** 包含无关联键及旁路操作,仅回收本次 advance 的观察资源。 */
|
|
27023
|
+
abandonPending(reason) {
|
|
27024
|
+
this.scope.abandoned = true;
|
|
27025
|
+
for (const operation of this.scope.active)
|
|
27026
|
+
operation.abandon(reason);
|
|
27027
|
+
this.associations.clear();
|
|
27028
|
+
}
|
|
27029
|
+
/** 仅结束仍由本地消费方拥有的观察,旁路任务不注册到此表。 */
|
|
27030
|
+
closePending() {
|
|
27031
|
+
for (const operation of this.associations.values()) {
|
|
27032
|
+
operation.finish(ETelemetryOutcome.UNKNOWN, {
|
|
27033
|
+
[ETelemetryAttribute.LINKQUE_OBSERVATION_BOUNDARY]: ETelemetryObservationBoundary.LOCAL_WAIT,
|
|
27034
|
+
[ETelemetryAttribute.HARNESS_REMOTE_COMPLETION]: ETelemetryRemoteCompletion.UNKNOWN
|
|
27035
|
+
});
|
|
27036
|
+
}
|
|
27037
|
+
this.associations.clear();
|
|
27038
|
+
}
|
|
27039
|
+
};
|
|
27040
|
+
function startRuntimeObservation(telemetry, input) {
|
|
27041
|
+
try {
|
|
27042
|
+
return new RuntimeObservation(telemetry.startAdvance(input));
|
|
27043
|
+
} catch {
|
|
27044
|
+
return new RuntimeObservation(new NoopRuntimeObservation());
|
|
27045
|
+
}
|
|
27046
|
+
}
|
|
27047
|
+
|
|
27048
|
+
// ../linkque-agent-runtime/dist/esm/core/telemetry/ioObservation.js
|
|
27049
|
+
async function observeIo(create, task, classify = () => ETelemetryOutcome.SUCCESS) {
|
|
27050
|
+
let operation;
|
|
27051
|
+
operation = skipError(create);
|
|
27052
|
+
const active = operation ?? {
|
|
27053
|
+
observation: new RuntimeObservation(new NoopRuntimeObservation()),
|
|
27054
|
+
add: () => {
|
|
27055
|
+
}
|
|
27056
|
+
};
|
|
27057
|
+
let outcome = ETelemetryOutcome.SUCCESS;
|
|
27058
|
+
try {
|
|
27059
|
+
const value = await task(active);
|
|
27060
|
+
outcome = skipError(() => classify(value)) ?? ETelemetryOutcome.UNKNOWN;
|
|
27061
|
+
return value;
|
|
27062
|
+
} catch (error) {
|
|
27063
|
+
outcome = ETelemetryOutcome.ERROR;
|
|
27064
|
+
skipError(() => operation?.fail(error));
|
|
27065
|
+
throw error;
|
|
27066
|
+
} finally {
|
|
27067
|
+
skipError(() => operation?.finish(outcome));
|
|
27068
|
+
}
|
|
27069
|
+
}
|
|
27070
|
+
var IoObservation = class {
|
|
27071
|
+
signal;
|
|
27072
|
+
observation;
|
|
27073
|
+
ended = false;
|
|
27074
|
+
attributes = {};
|
|
27075
|
+
onAbort = () => this.fail(this.signal?.reason);
|
|
27076
|
+
constructor(parent, name, attributes = {}, signal, links = []) {
|
|
27077
|
+
this.signal = signal;
|
|
27078
|
+
const sink = skipError(() => parent?.startOperation({
|
|
27079
|
+
name,
|
|
27080
|
+
attributes,
|
|
27081
|
+
eventPrefix: ETelemetryEventPrefix.OPERATION,
|
|
27082
|
+
detached: false,
|
|
27083
|
+
links
|
|
27084
|
+
})) ?? new NoopRuntimeObservation();
|
|
27085
|
+
this.observation = new RuntimeObservation(sink);
|
|
27086
|
+
signal?.addEventListener("abort", this.onAbort, { once: true });
|
|
27087
|
+
if (signal?.aborted) {
|
|
27088
|
+
this.onAbort();
|
|
27089
|
+
}
|
|
27090
|
+
}
|
|
27091
|
+
add(attributes) {
|
|
27092
|
+
if (this.ended) {
|
|
27093
|
+
return;
|
|
27094
|
+
}
|
|
27095
|
+
this.attributes = Object.assign({}, this.attributes, attributes);
|
|
27096
|
+
}
|
|
27097
|
+
finish(outcome = ETelemetryOutcome.SUCCESS) {
|
|
27098
|
+
if (this.ended) {
|
|
27099
|
+
return;
|
|
27100
|
+
}
|
|
27101
|
+
if (outcome === ETelemetryOutcome.ERROR) {
|
|
27102
|
+
const errorType = this.attributes[ETelemetryAttribute.ERROR_TYPE] ?? ETelemetryErrorType.IO_ERROR;
|
|
27103
|
+
this.add({ [ETelemetryAttribute.ERROR_TYPE]: errorType });
|
|
27104
|
+
}
|
|
27105
|
+
this.ended = true;
|
|
27106
|
+
this.signal?.removeEventListener("abort", this.onAbort);
|
|
27107
|
+
this.observation.finish(outcome, this.attributes);
|
|
27108
|
+
}
|
|
27109
|
+
fail(error) {
|
|
27110
|
+
const reason = this.signal?.aborted ? this.signal.reason : error;
|
|
27111
|
+
let timeout = false;
|
|
27112
|
+
let cancelled = this.signal?.aborted ?? false;
|
|
27113
|
+
skipError(() => {
|
|
27114
|
+
const value = reason;
|
|
27115
|
+
timeout = value?.name === "TimeoutError" || typeof value?.code === "string" && value.code.endsWith("_TIMEOUT");
|
|
27116
|
+
cancelled ||= value?.name === "AbortError";
|
|
27117
|
+
});
|
|
27118
|
+
let outcome = ETelemetryOutcome.ERROR;
|
|
27119
|
+
let errorType = ETelemetryErrorType.IO_ERROR;
|
|
27120
|
+
if (timeout) {
|
|
27121
|
+
outcome = ETelemetryOutcome.TIMEOUT;
|
|
27122
|
+
errorType = ETelemetryErrorType.IO_TIMEOUT;
|
|
27123
|
+
} else if (cancelled) {
|
|
27124
|
+
outcome = ETelemetryOutcome.CANCELLED;
|
|
27125
|
+
errorType = ETelemetryErrorType.IO_CANCELLED;
|
|
27126
|
+
}
|
|
27127
|
+
this.add({ [ETelemetryAttribute.ERROR_TYPE]: errorType });
|
|
27128
|
+
if (cancelled || timeout) {
|
|
27129
|
+
this.add({
|
|
27130
|
+
[ETelemetryAttribute.HARNESS_REMOTE_COMPLETION]: ETelemetryRemoteCompletion.UNKNOWN,
|
|
27131
|
+
[ETelemetryAttribute.LINKQUE_OBSERVATION_BOUNDARY]: ETelemetryObservationBoundary.LOCAL_WAIT
|
|
27132
|
+
});
|
|
27133
|
+
}
|
|
27134
|
+
this.finish(outcome);
|
|
27135
|
+
}
|
|
27136
|
+
};
|
|
27137
|
+
|
|
26419
27138
|
// ../linkque-agent-runtime/dist/esm/core/telemetry/contentRecording.js
|
|
26420
27139
|
function recordContentSection(observation, section, value, availability = "available") {
|
|
26421
27140
|
observation?.record(ETelemetryEventName.CONTENT_RECORDED, {}, { section, value, availability });
|
|
@@ -26592,6 +27311,7 @@ var McpProxyTool = class {
|
|
|
26592
27311
|
specByResourceId;
|
|
26593
27312
|
specs;
|
|
26594
27313
|
debugLog;
|
|
27314
|
+
observation;
|
|
26595
27315
|
authorizeCall;
|
|
26596
27316
|
constructor(provider, specs, options = {}) {
|
|
26597
27317
|
this.provider = provider;
|
|
@@ -26604,6 +27324,7 @@ var McpProxyTool = class {
|
|
|
26604
27324
|
this.debugLog = options.debugLog ?? (() => {
|
|
26605
27325
|
});
|
|
26606
27326
|
this.authorizeCall = options.authorizeCall;
|
|
27327
|
+
this.observation = options.observation;
|
|
26607
27328
|
}
|
|
26608
27329
|
/**
|
|
26609
27330
|
* 产单个 `mcp` 代理工具描述符,注入 `agentReq.tools`。
|
|
@@ -26652,7 +27373,7 @@ var McpProxyTool = class {
|
|
|
26652
27373
|
};
|
|
26653
27374
|
}
|
|
26654
27375
|
/** 并发发现所有 server;每个 server 独立限时,失败结果不阻断其他目录。 */
|
|
26655
|
-
async discover(signal) {
|
|
27376
|
+
async discover(signal, observation) {
|
|
26656
27377
|
signal?.throwIfAborted();
|
|
26657
27378
|
const results = await Promise.all(this.specs.map(async (spec) => {
|
|
26658
27379
|
const scope = new CancellationScope({
|
|
@@ -26662,17 +27383,21 @@ var McpProxyTool = class {
|
|
|
26662
27383
|
timeoutReason: new DOMException("MCP \u76EE\u5F55\u9884\u52A0\u8F7D\u8D85\u65F6", "TimeoutError")
|
|
26663
27384
|
});
|
|
26664
27385
|
try {
|
|
26665
|
-
|
|
26666
|
-
|
|
26667
|
-
|
|
26668
|
-
|
|
26669
|
-
|
|
26670
|
-
|
|
26671
|
-
|
|
27386
|
+
return await observeIo(() => new IoObservation(observation, ETelemetryOperationName.MCP_DISCOVER, {
|
|
27387
|
+
[ETelemetryAttribute.LINKQUE_MCP_SERVER_NAME]: spec.serverName
|
|
27388
|
+
}, scope.context.signal), async (discovery) => {
|
|
27389
|
+
const entry = await this.ensureEntry(spec.serverName, scope.context.signal, discovery.observation);
|
|
27390
|
+
const status = entry ? "connected" : "failed";
|
|
27391
|
+
const tools = entry?.tools?.map(({ name, description }) => {
|
|
27392
|
+
const metadata = {
|
|
27393
|
+
name
|
|
27394
|
+
};
|
|
27395
|
+
if (description)
|
|
26672
27396
|
metadata.description = description;
|
|
26673
27397
|
return metadata;
|
|
26674
|
-
})
|
|
26675
|
-
|
|
27398
|
+
}) ?? [];
|
|
27399
|
+
return { serverName: spec.serverName, status, tools };
|
|
27400
|
+
}, (result) => result.status === "connected" ? ETelemetryOutcome.SUCCESS : ETelemetryOutcome.ERROR);
|
|
26676
27401
|
} catch (error) {
|
|
26677
27402
|
if (signal?.aborted || this.lifetime.context.signal.aborted)
|
|
26678
27403
|
throw error;
|
|
@@ -26723,7 +27448,7 @@ var McpProxyTool = class {
|
|
|
26723
27448
|
}
|
|
26724
27449
|
// —— 内部:连接与缓存 ——
|
|
26725
27450
|
/** 确保某 server 已连;返回 connected 条目,依失败返回 null(不抛错)。 */
|
|
26726
|
-
async ensureEntry(serverName, signal) {
|
|
27451
|
+
async ensureEntry(serverName, signal, observation) {
|
|
26727
27452
|
this.lifetime.context.throwIfAborted();
|
|
26728
27453
|
signal?.throwIfAborted();
|
|
26729
27454
|
const existing = this.entries.get(serverName);
|
|
@@ -26733,16 +27458,10 @@ var McpProxyTool = class {
|
|
|
26733
27458
|
let attempt = this.inFlight.get(serverName);
|
|
26734
27459
|
if (!attempt) {
|
|
26735
27460
|
const scope = new CancellationScope({ parent: this.lifetime.context });
|
|
26736
|
-
attempt = {
|
|
26737
|
-
promise: Promise.resolve({}),
|
|
26738
|
-
scope,
|
|
26739
|
-
waiters: 0,
|
|
26740
|
-
settled: false,
|
|
26741
|
-
abandoned: false
|
|
26742
|
-
};
|
|
27461
|
+
attempt = { scope, waiters: 0, settled: false, abandoned: false };
|
|
26743
27462
|
const current = attempt;
|
|
26744
27463
|
this.inFlight.set(serverName, current);
|
|
26745
|
-
current.promise = this.connect(serverName, scope.context.signal, current).finally(() => {
|
|
27464
|
+
current.promise = this.connect(serverName, scope.context.signal, current, observation ?? this.observation).finally(() => {
|
|
26746
27465
|
current.settled = true;
|
|
26747
27466
|
if (this.inFlight.get(serverName) === current)
|
|
26748
27467
|
this.inFlight.delete(serverName);
|
|
@@ -26751,7 +27470,11 @@ var McpProxyTool = class {
|
|
|
26751
27470
|
}
|
|
26752
27471
|
attempt.waiters += 1;
|
|
26753
27472
|
try {
|
|
26754
|
-
const
|
|
27473
|
+
const promise = attempt.promise;
|
|
27474
|
+
if (!promise) {
|
|
27475
|
+
throw new Error("MCP \u5EFA\u8FDE\u72B6\u6001\u7F3A\u5C11 Promise");
|
|
27476
|
+
}
|
|
27477
|
+
const entry = await waitWithSignal(promise, signal);
|
|
26755
27478
|
return entry.status === "connected" ? entry : null;
|
|
26756
27479
|
} finally {
|
|
26757
27480
|
attempt.waiters -= 1;
|
|
@@ -26764,7 +27487,7 @@ var McpProxyTool = class {
|
|
|
26764
27487
|
}
|
|
26765
27488
|
}
|
|
26766
27489
|
/** 连单个 server 并 listTools;按 spec.allowedTools 过滤后缓存;失败记为 failed。 */
|
|
26767
|
-
async connect(serverName, signal, attempt) {
|
|
27490
|
+
async connect(serverName, signal, attempt, observation) {
|
|
26768
27491
|
const isCurrent = () => !attempt.abandoned && this.inFlight.get(serverName) === attempt && !this.lifetime.context.signal.aborted;
|
|
26769
27492
|
const spec = this.specByServerName.get(serverName);
|
|
26770
27493
|
if (!spec) {
|
|
@@ -26798,7 +27521,7 @@ var McpProxyTool = class {
|
|
|
26798
27521
|
argsMappingRules: spec.argsMappingRules
|
|
26799
27522
|
}
|
|
26800
27523
|
};
|
|
26801
|
-
const pending = this.provider.servers([synthetic], signal).then((servers2) => {
|
|
27524
|
+
const pending = this.provider.servers([synthetic], signal, observation).then((servers2) => {
|
|
26802
27525
|
server = servers2[0];
|
|
26803
27526
|
if (signal.aborted) {
|
|
26804
27527
|
for (const item of servers2)
|
|
@@ -26812,7 +27535,7 @@ var McpProxyTool = class {
|
|
|
26812
27535
|
if (!server) {
|
|
26813
27536
|
throw new Error(`provider returned no server for ${spec.serverName}`);
|
|
26814
27537
|
}
|
|
26815
|
-
const all = await waitWithSignal(server.listTools(signal), signal);
|
|
27538
|
+
const all = await waitWithSignal(server.listTools(signal, observation), signal);
|
|
26816
27539
|
signal.throwIfAborted();
|
|
26817
27540
|
const tools = spec.allowedTools ? all.filter((tool) => spec.allowedTools.has(tool.name)) : all;
|
|
26818
27541
|
const entry = { server, tools, status: "connected" };
|
|
@@ -26856,7 +27579,7 @@ var McpProxyTool = class {
|
|
|
26856
27579
|
return this.executeBatchSearch(params.searches, params.server, context2);
|
|
26857
27580
|
}
|
|
26858
27581
|
if (params.search !== void 0) {
|
|
26859
|
-
const result = await this.executeSearch(params.search, params.server);
|
|
27582
|
+
const result = await this.executeSearch(params.search, params.server, context2?.observation);
|
|
26860
27583
|
this.recordAction(context2, "search", result.tools.length ? "matched" : "no_hits", { query: result.query, tools: result.tools });
|
|
26861
27584
|
return result.text;
|
|
26862
27585
|
}
|
|
@@ -26918,7 +27641,7 @@ ${lines.join("\n")}${hint}`.trim();
|
|
|
26918
27641
|
if (previous?.server)
|
|
26919
27642
|
await this.closeServer(previous.server);
|
|
26920
27643
|
}
|
|
26921
|
-
const entry = await this.ensureEntry(spec.serverName, signal);
|
|
27644
|
+
const entry = await this.ensureEntry(spec.serverName, signal, context2?.observation);
|
|
26922
27645
|
if (!entry) {
|
|
26923
27646
|
this.recordAction(context2, "connect", "failed", {
|
|
26924
27647
|
server: spec.serverName
|
|
@@ -26943,7 +27666,7 @@ ${lines.join("\n")}${hint}`.trim();
|
|
|
26943
27666
|
this.recordAction(context2, "list", "not_found", { server });
|
|
26944
27667
|
return `Server "${server}" not found. Use mcp({}) to see available servers.`;
|
|
26945
27668
|
}
|
|
26946
|
-
const entry = await this.ensureEntry(spec.serverName, signal);
|
|
27669
|
+
const entry = await this.ensureEntry(spec.serverName, signal, context2?.observation);
|
|
26947
27670
|
if (!entry) {
|
|
26948
27671
|
this.recordAction(context2, "list", "failed", { server: spec.serverName });
|
|
26949
27672
|
return `Server "${spec.serverName}" is not connected. Use mcp({ connect: "${spec.serverName}" }) to retry.`;
|
|
@@ -26958,13 +27681,13 @@ ${lines.join("\n")}${hint}`.trim();
|
|
|
26958
27681
|
return this.formatToolList(spec.serverName, entry.tools);
|
|
26959
27682
|
}
|
|
26960
27683
|
/** `mcp({ search: "query" })`:空格分词 OR 子串匹配 name/description(跨所有 server)。 */
|
|
26961
|
-
async executeSearch(query, serverHint) {
|
|
27684
|
+
async executeSearch(query, serverHint, observation) {
|
|
26962
27685
|
const terms = query.trim().split(/\s+/u).filter((t) => t.length > 0);
|
|
26963
27686
|
if (terms.length === 0)
|
|
26964
27687
|
return { query, text: "Search query cannot be empty.", tools: [] };
|
|
26965
27688
|
const pattern = new RegExp(terms.map(escapeRegExp).join("|"), "iu");
|
|
26966
27689
|
const specs = serverHint ? this.specsMatching(serverHint) : this.specs;
|
|
26967
|
-
await Promise.all(specs.map((s) => this.ensureEntry(s.serverName)));
|
|
27690
|
+
await Promise.all(specs.map((s) => this.ensureEntry(s.serverName, void 0, observation)));
|
|
26968
27691
|
const matches = [];
|
|
26969
27692
|
for (const spec of specs) {
|
|
26970
27693
|
const entry = this.entries.get(spec.serverName);
|
|
@@ -27010,15 +27733,15 @@ ${formatSchema(tool.inputSchema, " ")}`);
|
|
|
27010
27733
|
return "Batch search requires at least one non-empty query.";
|
|
27011
27734
|
}
|
|
27012
27735
|
const specs = serverHint ? this.specsMatching(serverHint) : this.specs;
|
|
27013
|
-
await Promise.all(specs.map((spec) => this.ensureEntry(spec.serverName)));
|
|
27014
|
-
const results = await Promise.all(normalized.map((query) => this.executeSearch(query, serverHint)));
|
|
27736
|
+
await Promise.all(specs.map((spec) => this.ensureEntry(spec.serverName, void 0, context2?.observation)));
|
|
27737
|
+
const results = await Promise.all(normalized.map((query) => this.executeSearch(query, serverHint, context2?.observation)));
|
|
27015
27738
|
this.recordAction(context2, "search", results.some((result) => result.tools.length) ? "matched" : "no_hits", { results: results.map(({ query, tools }) => ({ query, tools })) });
|
|
27016
27739
|
return results.map((result, index) => `Query ${index + 1}: "${normalized[index]}"
|
|
27017
27740
|
${result.text}`).join("\n\n");
|
|
27018
27741
|
}
|
|
27019
27742
|
/** `mcp({ describe: "tool" })`:输出工具所属 server + 参数 schema。 */
|
|
27020
27743
|
async executeDescribe(toolName, serverHint, signal, context2) {
|
|
27021
|
-
const found = await this.findTool(toolName, serverHint, signal);
|
|
27744
|
+
const found = await this.findTool(toolName, serverHint, signal, context2?.observation);
|
|
27022
27745
|
if (!found) {
|
|
27023
27746
|
this.recordAction(context2, "describe", "not_found", { name: toolName });
|
|
27024
27747
|
return `Tool "${toolName}" not found. Use mcp({ search: "..." }) to search.`;
|
|
@@ -27045,7 +27768,7 @@ ${formatSchema(tool.inputSchema)}`);
|
|
|
27045
27768
|
}
|
|
27046
27769
|
/** `mcp({ tool: "name", args: {...} })`:调用工具,返回序列化结果。 */
|
|
27047
27770
|
async executeCall(toolName, args, serverHint, signal, context2) {
|
|
27048
|
-
const found = await this.findTool(toolName, serverHint, signal);
|
|
27771
|
+
const found = await this.findTool(toolName, serverHint, signal, context2?.observation);
|
|
27049
27772
|
if (!found) {
|
|
27050
27773
|
this.recordAction(context2, "call", "not_found", { name: toolName });
|
|
27051
27774
|
return `Tool "${toolName}" not found. Use mcp({ search: "..." }) to search.`;
|
|
@@ -27076,7 +27799,7 @@ ${formatSchema(tool.inputSchema)}`);
|
|
|
27076
27799
|
}
|
|
27077
27800
|
// —— 辅助 ——
|
|
27078
27801
|
/** 跨(或按 hint)已连 server 查找工具;未连则触发懒连接。 */
|
|
27079
|
-
async findTool(toolName, serverHint, signal) {
|
|
27802
|
+
async findTool(toolName, serverHint, signal, observation) {
|
|
27080
27803
|
const specs = serverHint ? this.specsMatching(serverHint) : this.specs;
|
|
27081
27804
|
for (const spec of specs) {
|
|
27082
27805
|
const entry = this.entries.get(spec.serverName);
|
|
@@ -27087,7 +27810,7 @@ ${formatSchema(tool.inputSchema)}`);
|
|
|
27087
27810
|
return { entry, server: spec.serverName, tool, spec };
|
|
27088
27811
|
}
|
|
27089
27812
|
}
|
|
27090
|
-
await Promise.all(specs.map((s) => this.ensureEntry(s.serverName, signal)));
|
|
27813
|
+
await Promise.all(specs.map((s) => this.ensureEntry(s.serverName, signal, observation)));
|
|
27091
27814
|
for (const spec of specs) {
|
|
27092
27815
|
const entry = this.entries.get(spec.serverName);
|
|
27093
27816
|
if (!entry || entry.status !== "connected")
|
|
@@ -27244,8 +27967,9 @@ async function executeHomeData(input) {
|
|
|
27244
27967
|
if (!input.userId.trim()) {
|
|
27245
27968
|
return failure("AUTH_REQUIRED", "\u9996\u9875\u6570\u636E\u8BF7\u6C42\u7F3A\u5C11\u53EF\u4FE1\u7528\u6237\u8EAB\u4EFD", false);
|
|
27246
27969
|
}
|
|
27247
|
-
const
|
|
27248
|
-
const
|
|
27970
|
+
const mcpResources = input.protocol.agent.resources.filter((resource) => resource.resourceType === EResourceType.MCP);
|
|
27971
|
+
const mcpToolResources = input.protocol.agent.resources.filter((resource) => resource.resourceType === EResourceType.MCP_TOOL);
|
|
27972
|
+
const specs = aggregateMcpServers(mcpResources, mcpToolResources, input.protocol.agentId);
|
|
27249
27973
|
const spec = specs.find((candidate) => candidate.serverName === request.binding.mcpName);
|
|
27250
27974
|
if (!spec) {
|
|
27251
27975
|
return failure("MCP_NOT_BOUND", "\u5F53\u524D Agent \u672A\u7ED1\u5B9A\u8BE5 MCP", false);
|
|
@@ -27329,424 +28053,24 @@ function failure(code, message, retryable) {
|
|
|
27329
28053
|
return { ok: false, error: { code, message, retryable } };
|
|
27330
28054
|
}
|
|
27331
28055
|
|
|
27332
|
-
// ../linkque-agent-runtime/dist/esm/core/cardActionDiagnostics.js
|
|
27333
|
-
var CardActionDiagnostics = class {
|
|
27334
|
-
sink;
|
|
27335
|
-
layer;
|
|
27336
|
-
operation;
|
|
27337
|
-
stage = "validate";
|
|
27338
|
-
context;
|
|
27339
|
-
debugLog;
|
|
27340
|
-
startedAt = performance.now();
|
|
27341
|
-
sensitiveValues = /* @__PURE__ */ new Set();
|
|
27342
|
-
constructor(sink, context2, layer = "runtime", operation = "a2uiAction.execute") {
|
|
27343
|
-
this.sink = sink;
|
|
27344
|
-
this.layer = layer;
|
|
27345
|
-
this.operation = operation;
|
|
27346
|
-
this.context = { ...context2 };
|
|
27347
|
-
if (sink) {
|
|
27348
|
-
this.debugLog = (line, scope) => {
|
|
27349
|
-
this.write("diagnostic", { message: line }, scope);
|
|
27350
|
-
};
|
|
27351
|
-
}
|
|
27352
|
-
}
|
|
27353
|
-
/** 根据绑定路径登记敏感值;解析仅为日志服务,失败不影响业务。 */
|
|
27354
|
-
protect(readValue) {
|
|
27355
|
-
if (!this.sink)
|
|
27356
|
-
return;
|
|
27357
|
-
try {
|
|
27358
|
-
const value = readValue();
|
|
27359
|
-
if (typeof value === "string" && value)
|
|
27360
|
-
this.sensitiveValues.add(value);
|
|
27361
|
-
} catch {
|
|
27362
|
-
}
|
|
27363
|
-
}
|
|
27364
|
-
write(event, fields = {}, scope = EDebugLogScope.A2UI_ACTION) {
|
|
27365
|
-
if (!this.sink)
|
|
27366
|
-
return;
|
|
27367
|
-
try {
|
|
27368
|
-
const record2 = { ...this.context, ...fields };
|
|
27369
|
-
if (record2.message)
|
|
27370
|
-
record2.message = sanitizeDiagnosticText(redactKnownValues(record2.message, this.sensitiveValues));
|
|
27371
|
-
if (record2.errorName)
|
|
27372
|
-
record2.errorName = sanitizeDiagnosticText(redactKnownValues(record2.errorName, this.sensitiveValues));
|
|
27373
|
-
if ("input" in record2)
|
|
27374
|
-
record2.input = sanitizeLogValue(record2.input, this.sensitiveValues);
|
|
27375
|
-
if ("output" in record2)
|
|
27376
|
-
record2.output = sanitizeLogValue(record2.output, this.sensitiveValues);
|
|
27377
|
-
this.sink(JSON.stringify({
|
|
27378
|
-
operation: this.operation,
|
|
27379
|
-
level: "info",
|
|
27380
|
-
layer: this.layer,
|
|
27381
|
-
event,
|
|
27382
|
-
stage: this.stage,
|
|
27383
|
-
...record2,
|
|
27384
|
-
costMs: Math.max(0, Math.round(performance.now() - this.startedAt))
|
|
27385
|
-
}), scope);
|
|
27386
|
-
} catch {
|
|
27387
|
-
}
|
|
27388
|
-
}
|
|
27389
|
-
error(event, error) {
|
|
27390
|
-
if (!this.sink)
|
|
27391
|
-
return;
|
|
27392
|
-
try {
|
|
27393
|
-
this.write(event, {
|
|
27394
|
-
errorName: error instanceof Error ? error.name : typeof error,
|
|
27395
|
-
message: error instanceof Error ? error.message : typeof error === "string" ? error : "\u975E\u6807\u51C6\u5F02\u5E38"
|
|
27396
|
-
});
|
|
27397
|
-
} catch {
|
|
27398
|
-
}
|
|
27399
|
-
}
|
|
27400
|
-
};
|
|
27401
|
-
function sanitizeLogValue(value, sensitiveValues) {
|
|
27402
|
-
const seen = /* @__PURE__ */ new WeakSet();
|
|
27403
|
-
let nodes = 200;
|
|
27404
|
-
let characters = 4e3;
|
|
27405
|
-
const visit = (item, depth, key = "") => {
|
|
27406
|
-
if (/authorization|cookie|token|secret|password|api[_-]?key|access[_-]?key|private[_-]?key|^(?:ak|sk|userId|orderId|tradeNO|phone|mobile|email|idCard)$/iu.test(key)) {
|
|
27407
|
-
if (typeof item === "string" && item)
|
|
27408
|
-
sensitiveValues.add(item);
|
|
27409
|
-
return "<redacted>";
|
|
27410
|
-
}
|
|
27411
|
-
if (--nodes < 0 || depth > 8 || characters <= 0)
|
|
27412
|
-
return "<truncated>";
|
|
27413
|
-
if (item === null || typeof item === "number" || typeof item === "boolean")
|
|
27414
|
-
return item;
|
|
27415
|
-
if (typeof item === "string") {
|
|
27416
|
-
if (/^\s*[{[]/u.test(item)) {
|
|
27417
|
-
if (item.length > 16e3)
|
|
27418
|
-
return "<truncated JSON>";
|
|
27419
|
-
try {
|
|
27420
|
-
return JSON.stringify(visit(JSON.parse(item), depth + 1));
|
|
27421
|
-
} catch {
|
|
27422
|
-
return "<invalid JSON>";
|
|
27423
|
-
}
|
|
27424
|
-
}
|
|
27425
|
-
const text2 = sanitizeDiagnosticText(redactKnownValues(item, sensitiveValues));
|
|
27426
|
-
const result2 = text2.slice(0, Math.min(512, characters));
|
|
27427
|
-
characters -= result2.length;
|
|
27428
|
-
return result2.length < item.length ? `${result2}<truncated>` : result2;
|
|
27429
|
-
}
|
|
27430
|
-
if (typeof item !== "object")
|
|
27431
|
-
return `<${typeof item}>`;
|
|
27432
|
-
if (seen.has(item))
|
|
27433
|
-
return "<circular>";
|
|
27434
|
-
seen.add(item);
|
|
27435
|
-
try {
|
|
27436
|
-
const keys = Object.keys(item);
|
|
27437
|
-
const result2 = /* @__PURE__ */ Object.create(null);
|
|
27438
|
-
for (const name of keys.slice(0, 20)) {
|
|
27439
|
-
const descriptor = Object.getOwnPropertyDescriptor(item, name);
|
|
27440
|
-
if (name === "value" && Object.getOwnPropertyDescriptor(item, "kind")?.value === "literal" && typeof descriptor?.value === "string" && descriptor.value)
|
|
27441
|
-
sensitiveValues.add(descriptor.value);
|
|
27442
|
-
result2[name.slice(0, 100)] = name === "value" && Object.getOwnPropertyDescriptor(item, "kind")?.value === "literal" ? "<redacted>" : descriptor && "value" in descriptor ? visit(descriptor.value, depth + 1, name) : "<accessor>";
|
|
27443
|
-
}
|
|
27444
|
-
if (Array.isArray(item)) {
|
|
27445
|
-
const values = Object.values(result2);
|
|
27446
|
-
if (keys.length > 20)
|
|
27447
|
-
values.push("<truncated>");
|
|
27448
|
-
return values;
|
|
27449
|
-
}
|
|
27450
|
-
if (keys.length > 20)
|
|
27451
|
-
result2["<truncated>"] = true;
|
|
27452
|
-
return result2;
|
|
27453
|
-
} catch {
|
|
27454
|
-
return "<unreadable>";
|
|
27455
|
-
} finally {
|
|
27456
|
-
seen.delete(item);
|
|
27457
|
-
}
|
|
27458
|
-
};
|
|
27459
|
-
const result = visit(value, 0);
|
|
27460
|
-
const text = JSON.stringify(result);
|
|
27461
|
-
return text.length > 6e3 ? { truncated: true, preview: text.slice(0, 2e3) } : result;
|
|
27462
|
-
}
|
|
27463
|
-
function sanitizeDiagnosticText(value) {
|
|
27464
|
-
return value.replace(/\b(?:body|arguments|payload|headers)\s*[:=][\s\S]*/giu, "<payload>").replace(/\{[\s\S]*/gu, "<payload>").replace(/https?:\/\/[^\s]+/giu, "<url>").replace(/\b(?:authorization|cookie|set-cookie)\s*[:=][^\r\n]*/giu, "<redacted>").replace(/\bbearer\s+[^\s,;]+/giu, "Bearer <redacted>").replace(/\b((?:api[_-]?key|access[_-]?key|token|secret|password|ak|sk|tradeNO|userId|orderId)\s*[:=]\s*)(?:"[^"]*"|'[^']*'|[^\s,;]+)/giu, "$1<redacted>").replace(/\s+/gu, " ").slice(0, 300);
|
|
27465
|
-
}
|
|
27466
|
-
function redactKnownValues(text, sensitiveValues) {
|
|
27467
|
-
let result = text;
|
|
27468
|
-
for (const sensitive of sensitiveValues)
|
|
27469
|
-
result = result.replaceAll(sensitive, "<redacted>");
|
|
27470
|
-
return result;
|
|
27471
|
-
}
|
|
27472
|
-
|
|
27473
|
-
// ../linkque-agent-runtime/dist/esm/core/cardActionExecutor.js
|
|
27474
|
-
async function executeCardAction(input) {
|
|
27475
|
-
const diagnostics = new CardActionDiagnostics(input.debugLog, {
|
|
27476
|
-
agentId: input.protocol.agentId,
|
|
27477
|
-
threadId: input.runtimeContext.threadId
|
|
27478
|
-
});
|
|
27479
|
-
diagnostics.protect(() => input.runtimeContext.userId);
|
|
27480
|
-
diagnostics.protect(() => input.runtimeContext.tenantId);
|
|
27481
|
-
diagnostics.write("started", {
|
|
27482
|
-
input: { request: input.request, runtimeContext: input.runtimeContext }
|
|
27483
|
-
});
|
|
27484
|
-
try {
|
|
27485
|
-
const response = await executeCardActionInternal(input, diagnostics);
|
|
27486
|
-
diagnostics.write(response.ok ? "completed" : "failed", response.ok ? { output: response } : {
|
|
27487
|
-
code: response.error.code,
|
|
27488
|
-
retryable: response.error.retryable,
|
|
27489
|
-
output: response
|
|
27490
|
-
});
|
|
27491
|
-
return response;
|
|
27492
|
-
} catch (error) {
|
|
27493
|
-
diagnostics.error("failed", error);
|
|
27494
|
-
throw error;
|
|
27495
|
-
}
|
|
27496
|
-
}
|
|
27497
|
-
async function executeCardActionInternal(input, diagnostics) {
|
|
27498
|
-
let request;
|
|
27499
|
-
try {
|
|
27500
|
-
request = parseA2UIActionExecuteRequest(input.request);
|
|
27501
|
-
} catch (error) {
|
|
27502
|
-
return failure2("INVALID_INPUT", errorMessage(error, "\u652F\u4ED8\u52A8\u4F5C\u8BF7\u6C42\u65E0\u6548"), false);
|
|
27503
|
-
}
|
|
27504
|
-
Object.assign(diagnostics.context, {
|
|
27505
|
-
invocationId: request.invocationId,
|
|
27506
|
-
cardRef: request.source.cardRef,
|
|
27507
|
-
cardRevision: request.source.cardRevision
|
|
27508
|
-
});
|
|
27509
|
-
if (request.agentId !== input.protocol.agentId)
|
|
27510
|
-
return failure2("AGENT_MISMATCH", "\u652F\u4ED8\u52A8\u4F5C\u4E0E\u5F53\u524D Agent \u4E0D\u5339\u914D", false);
|
|
27511
|
-
if (request.threadId !== input.runtimeContext.threadId)
|
|
27512
|
-
return failure2("INVALID_INPUT", "\u652F\u4ED8\u52A8\u4F5C\u4E0E\u5F53\u524D\u4F1A\u8BDD\u4E0D\u5339\u914D", false);
|
|
27513
|
-
if (!input.runtimeContext.userId.trim())
|
|
27514
|
-
return failure2("AUTH_REQUIRED", "\u652F\u4ED8\u52A8\u4F5C\u7F3A\u5C11\u53EF\u4FE1\u7528\u6237\u8EAB\u4EFD", false);
|
|
27515
|
-
diagnostics.write("validated", { output: request });
|
|
27516
|
-
diagnostics.stage = "binding";
|
|
27517
|
-
diagnostics.write("binding_started", { input: { source: request.source } });
|
|
27518
|
-
const resolved = resolvePaymentAction(input.protocol, request.source);
|
|
27519
|
-
if (!resolved.ok) {
|
|
27520
|
-
diagnostics.write("binding_failed", { output: resolved.response });
|
|
27521
|
-
return resolved.response;
|
|
27522
|
-
}
|
|
27523
|
-
const args = materializePaymentInput(resolved.payment.createTrade.input, request.input);
|
|
27524
|
-
if (!args)
|
|
27525
|
-
return failure2("INVALID_INPUT", "\u65E0\u6CD5\u751F\u6210\u521B\u5EFA\u4EA4\u6613 MCP \u5165\u53C2", false);
|
|
27526
|
-
const createTrade = resolved.payment.createTrade;
|
|
27527
|
-
Object.assign(diagnostics.context, {
|
|
27528
|
-
mcpResourceId: createTrade.mcpResourceId,
|
|
27529
|
-
toolName: createTrade.toolName
|
|
27530
|
-
});
|
|
27531
|
-
diagnostics.write("binding_resolved", { output: createTrade });
|
|
27532
|
-
diagnostics.stage = "tool_resolve";
|
|
27533
|
-
const registry = createRegistry(input.protocol, input.mcpServerProvider, diagnostics.debugLog, input.phoneAuthorization);
|
|
27534
|
-
try {
|
|
27535
|
-
diagnostics.write("tool_resolve_started", { input: createTrade });
|
|
27536
|
-
const tool = await registry.resolve(createTrade.mcpResourceId, createTrade.toolName, input.signal);
|
|
27537
|
-
diagnostics.write("tool_resolved", {
|
|
27538
|
-
output: {
|
|
27539
|
-
found: Boolean(tool),
|
|
27540
|
-
inputSchema: tool?.inputSchema,
|
|
27541
|
-
outputSchema: tool?.outputSchema
|
|
27542
|
-
}
|
|
27543
|
-
});
|
|
27544
|
-
if (!tool)
|
|
27545
|
-
return failure2("TOOL_NOT_ALLOWED", "\u521B\u5EFA\u4EA4\u6613 MCP Tool \u4E0D\u5B58\u5728\u6216\u672A\u6388\u6743", false);
|
|
27546
|
-
diagnostics.stage = "tool_input";
|
|
27547
|
-
const inputSchema = cloneJsonObject(tool.inputSchema);
|
|
27548
|
-
if (inputSchema && validateJsonSchemaValue(inputSchema, args).length > 0) {
|
|
27549
|
-
return failure2("INVALID_INPUT", "\u521B\u5EFA\u4EA4\u6613 MCP \u5165\u53C2\u4E0D\u7B26\u5408 Tool Schema", false);
|
|
27550
|
-
}
|
|
27551
|
-
diagnostics.write("tool_input_completed", { output: { args } });
|
|
27552
|
-
let result;
|
|
27553
|
-
diagnostics.stage = "tool_execute";
|
|
27554
|
-
diagnostics.write("tool_started", { input: args });
|
|
27555
|
-
try {
|
|
27556
|
-
result = await tool.execute(args, input.signal);
|
|
27557
|
-
diagnostics.protect(() => readJsonPointer(readStructuredContent3(result), createTrade.tradeNoPath));
|
|
27558
|
-
diagnostics.write("tool_completed", { output: result });
|
|
27559
|
-
} catch (error) {
|
|
27560
|
-
diagnostics.error("tool_failed", error);
|
|
27561
|
-
if (isMcpPhoneAuthorizationError(error))
|
|
27562
|
-
throw error;
|
|
27563
|
-
return failure2("EXECUTION_FAILED", "\u521B\u5EFA\u4EA4\u6613\u5931\u8D25\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5", true);
|
|
27564
|
-
}
|
|
27565
|
-
diagnostics.stage = "tool_output";
|
|
27566
|
-
const structured = readStructuredContent3(result);
|
|
27567
|
-
const tradeNO = readJsonPointer(structured, createTrade.tradeNoPath);
|
|
27568
|
-
diagnostics.write("tool_output_completed", {
|
|
27569
|
-
output: {
|
|
27570
|
-
structured,
|
|
27571
|
-
tradeNO,
|
|
27572
|
-
valid: typeof tradeNO === "string" && Boolean(tradeNO.trim()) && tradeNO.length <= 64
|
|
27573
|
-
}
|
|
27574
|
-
});
|
|
27575
|
-
if (typeof tradeNO !== "string" || !tradeNO.trim() || tradeNO.length > 64)
|
|
27576
|
-
return failure2("INVALID_OUTPUT", "\u521B\u5EFA\u4EA4\u6613 MCP \u672A\u8FD4\u56DE\u6709\u6548 tradeNO", false);
|
|
27577
|
-
return {
|
|
27578
|
-
ok: true,
|
|
27579
|
-
invocationId: request.invocationId,
|
|
27580
|
-
result: { kind: "payment", tradeNO }
|
|
27581
|
-
};
|
|
27582
|
-
} finally {
|
|
27583
|
-
const stage = diagnostics.stage;
|
|
27584
|
-
diagnostics.stage = "cleanup";
|
|
27585
|
-
diagnostics.write("cleanup_started", {
|
|
27586
|
-
input: { mcpResourceId: diagnostics.context.mcpResourceId }
|
|
27587
|
-
});
|
|
27588
|
-
await registry.closeAll();
|
|
27589
|
-
diagnostics.write("cleanup_completed", {
|
|
27590
|
-
output: { closeAttempted: true }
|
|
27591
|
-
});
|
|
27592
|
-
diagnostics.stage = stage;
|
|
27593
|
-
}
|
|
27594
|
-
}
|
|
27595
|
-
function resolvePaymentAction(protocol, source) {
|
|
27596
|
-
const card = protocol.agent.resources.find((resource) => resource.resourceType === EResourceType.CARD && resource.resourceId === source.cardRef);
|
|
27597
|
-
if (!card)
|
|
27598
|
-
return {
|
|
27599
|
-
ok: false,
|
|
27600
|
-
response: failure2("CARD_NOT_FOUND", "\u652F\u4ED8\u5361\u7247\u4E0D\u5B58\u5728", false)
|
|
27601
|
-
};
|
|
27602
|
-
if (card.config.revision !== source.cardRevision) {
|
|
27603
|
-
return {
|
|
27604
|
-
ok: false,
|
|
27605
|
-
response: failure2("CARD_REVISION_MISMATCH", "\u652F\u4ED8\u5361\u7247\u7248\u672C\u5DF2\u53D8\u5316\uFF0C\u8BF7\u5237\u65B0\u540E\u91CD\u8BD5", false)
|
|
27606
|
-
};
|
|
27607
|
-
}
|
|
27608
|
-
if (card.config.schemaVersion !== "4")
|
|
27609
|
-
return {
|
|
27610
|
-
ok: false,
|
|
27611
|
-
response: failure2("ACTION_NOT_FOUND", "\u652F\u4ED8\u52A8\u4F5C\u4E0D\u5B58\u5728", false)
|
|
27612
|
-
};
|
|
27613
|
-
const component = findSavedComponent(card.config.a2uiTemplate.content, source.surfaceId, source.componentId);
|
|
27614
|
-
if (!component)
|
|
27615
|
-
return {
|
|
27616
|
-
ok: false,
|
|
27617
|
-
response: failure2("ACTION_NOT_FOUND", "\u652F\u4ED8\u52A8\u4F5C\u4E0D\u5B58\u5728", false)
|
|
27618
|
-
};
|
|
27619
|
-
const payments = collectPaymentActions(component.action);
|
|
27620
|
-
if (payments.length !== 1)
|
|
27621
|
-
return {
|
|
27622
|
-
ok: false,
|
|
27623
|
-
response: failure2("ACTION_KIND_MISMATCH", "\u7EC4\u4EF6\u5FC5\u987B\u5305\u542B\u552F\u4E00\u652F\u4ED8\u52A8\u4F5C", false)
|
|
27624
|
-
};
|
|
27625
|
-
return { ok: true, payment: payments[0] };
|
|
27626
|
-
}
|
|
27627
|
-
function findSavedComponent(content, surfaceId, componentId) {
|
|
27628
|
-
let parsed;
|
|
27629
|
-
try {
|
|
27630
|
-
parsed = JSON.parse(content);
|
|
27631
|
-
} catch {
|
|
27632
|
-
return void 0;
|
|
27633
|
-
}
|
|
27634
|
-
if (!Array.isArray(parsed))
|
|
27635
|
-
return void 0;
|
|
27636
|
-
const instructions = parsed.flatMap((entry) => {
|
|
27637
|
-
const record2 = cloneJsonObject(entry);
|
|
27638
|
-
return record2 && Array.isArray(record2.datas) ? record2.datas : [entry];
|
|
27639
|
-
});
|
|
27640
|
-
for (const instruction of instructions) {
|
|
27641
|
-
const record2 = cloneJsonObject(instruction);
|
|
27642
|
-
const update = record2 && cloneJsonObject(record2.updateComponents);
|
|
27643
|
-
if (!update || update.surfaceId !== surfaceId || !Array.isArray(update.components))
|
|
27644
|
-
continue;
|
|
27645
|
-
const component = update.components.find((candidate) => {
|
|
27646
|
-
const item = cloneJsonObject(candidate);
|
|
27647
|
-
return item?.id === componentId;
|
|
27648
|
-
});
|
|
27649
|
-
const result = cloneJsonObject(component);
|
|
27650
|
-
if (result)
|
|
27651
|
-
return result;
|
|
27652
|
-
}
|
|
27653
|
-
return void 0;
|
|
27654
|
-
}
|
|
27655
|
-
function collectPaymentActions(value) {
|
|
27656
|
-
const action = cloneJsonObject(value);
|
|
27657
|
-
if (!action)
|
|
27658
|
-
return [];
|
|
27659
|
-
const client = cloneJsonObject(action.client);
|
|
27660
|
-
if (client?.name === "payment.trade-pay") {
|
|
27661
|
-
const context2 = cloneJsonObject(client.context);
|
|
27662
|
-
return context2 ? [context2] : [];
|
|
27663
|
-
}
|
|
27664
|
-
const select = cloneJsonObject(action.select);
|
|
27665
|
-
if (!select)
|
|
27666
|
-
return [];
|
|
27667
|
-
const cases = Array.isArray(select.cases) ? select.cases : [];
|
|
27668
|
-
return [
|
|
27669
|
-
...cases.flatMap((entry) => collectPaymentActions(cloneJsonObject(entry)?.action)),
|
|
27670
|
-
...collectPaymentActions(select.default)
|
|
27671
|
-
];
|
|
27672
|
-
}
|
|
27673
|
-
function materializePaymentInput(definition, supplied) {
|
|
27674
|
-
const materialized = materializeValue(definition, supplied);
|
|
27675
|
-
return cloneJsonObject(materialized);
|
|
27676
|
-
}
|
|
27677
|
-
function materializeValue(definition, supplied) {
|
|
27678
|
-
if (Array.isArray(definition)) {
|
|
27679
|
-
if (!Array.isArray(supplied) || supplied.length !== definition.length)
|
|
27680
|
-
return void 0;
|
|
27681
|
-
const result = definition.map((entry, index) => materializeValue(entry, supplied[index]));
|
|
27682
|
-
return result.some((entry) => entry === void 0) ? void 0 : result;
|
|
27683
|
-
}
|
|
27684
|
-
if (definition && typeof definition === "object") {
|
|
27685
|
-
const keys = Object.keys(definition);
|
|
27686
|
-
if (keys.length === 1 && keys[0] === "path" && typeof definition.path === "string")
|
|
27687
|
-
return supplied;
|
|
27688
|
-
const suppliedObject = cloneJsonObject(supplied);
|
|
27689
|
-
if (!suppliedObject)
|
|
27690
|
-
return void 0;
|
|
27691
|
-
const result = {};
|
|
27692
|
-
for (const [key, entry] of Object.entries(definition)) {
|
|
27693
|
-
const value = materializeValue(entry, suppliedObject[key]);
|
|
27694
|
-
if (value === void 0)
|
|
27695
|
-
return void 0;
|
|
27696
|
-
result[key] = value;
|
|
27697
|
-
}
|
|
27698
|
-
return result;
|
|
27699
|
-
}
|
|
27700
|
-
return definition;
|
|
27701
|
-
}
|
|
27702
|
-
function createRegistry(protocol, provider, debugLog, phoneAuthorization) {
|
|
27703
|
-
const resources = protocol.agent.resources.filter((resource) => resource.resourceType === EResourceType.MCP || resource.resourceType === EResourceType.MCP_TOOL);
|
|
27704
|
-
return new McpProxyTool(provider, aggregateMcpServers(resources, protocol.agentId), {
|
|
27705
|
-
debugLog,
|
|
27706
|
-
authorizeCall: createRequestMcpPhoneAuthorizer(protocol, phoneAuthorization)
|
|
27707
|
-
});
|
|
27708
|
-
}
|
|
27709
|
-
function readStructuredContent3(result) {
|
|
27710
|
-
const object3 = cloneJsonObject(result);
|
|
27711
|
-
if (!object3)
|
|
27712
|
-
return void 0;
|
|
27713
|
-
if (cloneJsonObject(object3.structuredContent))
|
|
27714
|
-
return object3.structuredContent;
|
|
27715
|
-
if (!Array.isArray(object3.content) || object3.content.length !== 1)
|
|
27716
|
-
return void 0;
|
|
27717
|
-
const content = cloneJsonObject(object3.content[0]);
|
|
27718
|
-
if (!content || content.type !== "text" || typeof content.text !== "string")
|
|
27719
|
-
return void 0;
|
|
27720
|
-
try {
|
|
27721
|
-
return JSON.parse(content.text);
|
|
27722
|
-
} catch {
|
|
27723
|
-
return void 0;
|
|
27724
|
-
}
|
|
27725
|
-
}
|
|
27726
|
-
function failure2(code, message, retryable) {
|
|
27727
|
-
return { ok: false, error: { code, message, retryable } };
|
|
27728
|
-
}
|
|
27729
|
-
function errorMessage(error, fallback) {
|
|
27730
|
-
return error instanceof Error && error.message.trim() ? error.message : fallback;
|
|
27731
|
-
}
|
|
27732
|
-
|
|
27733
28056
|
// ../linkque-agent-runtime/dist/esm/core/mcpExecution.js
|
|
27734
28057
|
async function executeAuthorizedMcp(input) {
|
|
27735
28058
|
if (input.agentId !== input.protocol.agentId)
|
|
27736
|
-
return
|
|
28059
|
+
return failure2("AGENT_MISMATCH", "\u8BF7\u6C42\u4E0E\u5F53\u524D Agent \u4E0D\u5339\u914D", false);
|
|
27737
28060
|
if (!input.userId.trim())
|
|
27738
|
-
return
|
|
27739
|
-
const
|
|
27740
|
-
const
|
|
28061
|
+
return failure2("AUTH_REQUIRED", "\u7F3A\u5C11\u53EF\u4FE1\u7528\u6237\u8EAB\u4EFD", false);
|
|
28062
|
+
const mcpResources = input.protocol.agent.resources.filter((resource) => resource.resourceType === EResourceType.MCP);
|
|
28063
|
+
const mcpToolResources = input.protocol.agent.resources.filter((resource) => resource.resourceType === EResourceType.MCP_TOOL);
|
|
28064
|
+
const registry = new McpProxyTool(input.mcpServerProvider, aggregateMcpServers(mcpResources, mcpToolResources, input.protocol.agentId), {
|
|
27741
28065
|
authorizeCall: createRequestMcpPhoneAuthorizer(input.protocol, input.phoneAuthorization)
|
|
27742
28066
|
});
|
|
27743
28067
|
try {
|
|
27744
28068
|
const tool = await registry.resolve(input.tool.mcpResourceId, input.tool.toolName, input.signal);
|
|
27745
28069
|
if (!tool)
|
|
27746
|
-
return
|
|
28070
|
+
return failure2("TOOL_NOT_ALLOWED", "MCP Tool \u4E0D\u5B58\u5728\u6216\u672A\u6388\u6743", false);
|
|
27747
28071
|
const schema = cloneJsonObject(tool.inputSchema);
|
|
27748
28072
|
if (schema && validateJsonSchemaValue(schema, input.tool.input).length > 0) {
|
|
27749
|
-
return
|
|
28073
|
+
return failure2("INVALID_INPUT", "MCP \u5165\u53C2\u4E0D\u7B26\u5408 Tool Schema", false);
|
|
27750
28074
|
}
|
|
27751
28075
|
let result;
|
|
27752
28076
|
try {
|
|
@@ -27754,18 +28078,18 @@ async function executeAuthorizedMcp(input) {
|
|
|
27754
28078
|
} catch (error) {
|
|
27755
28079
|
if (isMcpPhoneAuthorizationError(error))
|
|
27756
28080
|
throw error;
|
|
27757
|
-
return
|
|
28081
|
+
return failure2("EXECUTION_UNCERTAIN", "MCP \u6267\u884C\u7ED3\u679C\u4E0D\u786E\u5B9A\uFF0C\u8BF7\u52FF\u81EA\u52A8\u91CD\u8BD5", false);
|
|
27758
28082
|
}
|
|
27759
|
-
const structured =
|
|
28083
|
+
const structured = readStructuredContent3(result);
|
|
27760
28084
|
if (!isJsonValue2(structured)) {
|
|
27761
|
-
return
|
|
28085
|
+
return failure2("INVALID_OUTPUT", "MCP \u672A\u8FD4\u56DE\u6709\u6548 JSON \u7ED3\u679C", false);
|
|
27762
28086
|
}
|
|
27763
28087
|
return { ok: true, callId: input.callId, result: structured };
|
|
27764
28088
|
} finally {
|
|
27765
28089
|
await registry.closeAll();
|
|
27766
28090
|
}
|
|
27767
28091
|
}
|
|
27768
|
-
function
|
|
28092
|
+
function readStructuredContent3(result) {
|
|
27769
28093
|
const object3 = cloneJsonObject(result);
|
|
27770
28094
|
if (!object3)
|
|
27771
28095
|
return void 0;
|
|
@@ -27792,7 +28116,7 @@ function isJsonValue2(value) {
|
|
|
27792
28116
|
const object3 = cloneJsonObject(value);
|
|
27793
28117
|
return Boolean(object3) && Object.values(object3 ?? {}).every(isJsonValue2);
|
|
27794
28118
|
}
|
|
27795
|
-
function
|
|
28119
|
+
function failure2(code, message, retryable) {
|
|
27796
28120
|
return { ok: false, error: { code, message, retryable } };
|
|
27797
28121
|
}
|
|
27798
28122
|
|
|
@@ -27802,13 +28126,13 @@ async function executeFunctionActionMcp(input) {
|
|
|
27802
28126
|
try {
|
|
27803
28127
|
request = parseA2UIFunctionMcpExecuteRequest(input.request);
|
|
27804
28128
|
} catch (error) {
|
|
27805
|
-
return
|
|
28129
|
+
return failure3("INVALID_INPUT", errorMessage(error, "\u51FD\u6570 MCP \u8BF7\u6C42\u65E0\u6548"), false);
|
|
27806
28130
|
}
|
|
27807
28131
|
if (request.agentId !== input.protocol.agentId) {
|
|
27808
|
-
return
|
|
28132
|
+
return failure3("AGENT_MISMATCH", "\u51FD\u6570\u52A8\u4F5C\u4E0E\u5F53\u524D Agent \u4E0D\u5339\u914D", false);
|
|
27809
28133
|
}
|
|
27810
28134
|
if (request.threadId !== input.runtimeContext.threadId || !input.runtimeContext.userId.trim()) {
|
|
27811
|
-
return
|
|
28135
|
+
return failure3("AUTH_REQUIRED", "\u51FD\u6570\u52A8\u4F5C\u7F3A\u5C11\u53EF\u4FE1\u4F1A\u8BDD\u8EAB\u4EFD", false);
|
|
27812
28136
|
}
|
|
27813
28137
|
return executeAuthorizedMcp({
|
|
27814
28138
|
protocol: input.protocol,
|
|
@@ -27821,10 +28145,10 @@ async function executeFunctionActionMcp(input) {
|
|
|
27821
28145
|
phoneAuthorization: input.phoneAuthorization
|
|
27822
28146
|
});
|
|
27823
28147
|
}
|
|
27824
|
-
function
|
|
28148
|
+
function failure3(code, message, retryable) {
|
|
27825
28149
|
return { ok: false, error: { code, message, retryable } };
|
|
27826
28150
|
}
|
|
27827
|
-
function
|
|
28151
|
+
function errorMessage(error, fallback) {
|
|
27828
28152
|
return error instanceof Error && error.message.trim() ? error.message : fallback;
|
|
27829
28153
|
}
|
|
27830
28154
|
|
|
@@ -27905,19 +28229,95 @@ function buildHookContextBase(resource, stage, commonParams, eventId, timestamp)
|
|
|
27905
28229
|
commonParams
|
|
27906
28230
|
};
|
|
27907
28231
|
}
|
|
27908
|
-
|
|
27909
|
-
// ../linkque-agent-runtime/dist/esm/core/hook/hookRegistry.js
|
|
27910
|
-
var DEFAULT_HOOK_ORDER = 100;
|
|
27911
|
-
var DEFAULT_HOOK_TIMEOUT_MS = 1e3;
|
|
27912
|
-
var MAX_HOOK_TIMEOUT_MS = 6e3;
|
|
27913
|
-
function normalizeHookResources(resources) {
|
|
27914
|
-
return resources.filter((resource) => resource.config.enabled !== false).map((resource) => {
|
|
27915
|
-
const config = Object.assign({}, resource.config, {
|
|
27916
|
-
order: resource.config.order ?? DEFAULT_HOOK_ORDER,
|
|
27917
|
-
timeoutMs: Math.min(Math.max(resource.config.timeoutMs ?? DEFAULT_HOOK_TIMEOUT_MS, 0), MAX_HOOK_TIMEOUT_MS)
|
|
27918
|
-
});
|
|
27919
|
-
return Object.assign({}, resource, { config });
|
|
27920
|
-
}).sort((a, b) => (a.config.order ?? 0) - (b.config.order ?? 0));
|
|
28232
|
+
|
|
28233
|
+
// ../linkque-agent-runtime/dist/esm/core/hook/hookRegistry.js
|
|
28234
|
+
var DEFAULT_HOOK_ORDER = 100;
|
|
28235
|
+
var DEFAULT_HOOK_TIMEOUT_MS = 1e3;
|
|
28236
|
+
var MAX_HOOK_TIMEOUT_MS = 6e3;
|
|
28237
|
+
function normalizeHookResources(resources) {
|
|
28238
|
+
return resources.filter((resource) => resource.config.enabled !== false).map((resource) => {
|
|
28239
|
+
const config = Object.assign({}, resource.config, {
|
|
28240
|
+
order: resource.config.order ?? DEFAULT_HOOK_ORDER,
|
|
28241
|
+
timeoutMs: Math.min(Math.max(resource.config.timeoutMs ?? DEFAULT_HOOK_TIMEOUT_MS, 0), MAX_HOOK_TIMEOUT_MS)
|
|
28242
|
+
});
|
|
28243
|
+
return Object.assign({}, resource, { config });
|
|
28244
|
+
}).sort((a, b) => (a.config.order ?? 0) - (b.config.order ?? 0));
|
|
28245
|
+
}
|
|
28246
|
+
|
|
28247
|
+
// ../linkque-agent-runtime/dist/esm/core/telemetry/observe.js
|
|
28248
|
+
function createObservation(create) {
|
|
28249
|
+
try {
|
|
28250
|
+
const observation = typeof create === "function" ? create() : create.parent?.startOperation(create.operation);
|
|
28251
|
+
if (observation && "find" in observation && "closePending" in observation)
|
|
28252
|
+
return observation;
|
|
28253
|
+
return new RuntimeObservation(observation ?? new NoopRuntimeObservation());
|
|
28254
|
+
} catch {
|
|
28255
|
+
return new RuntimeObservation(new NoopRuntimeObservation());
|
|
28256
|
+
}
|
|
28257
|
+
}
|
|
28258
|
+
function settle(observation, completion, classify) {
|
|
28259
|
+
let result = {
|
|
28260
|
+
outcome: completion.status === "fulfilled" ? ETelemetryOutcome.SUCCESS : completion.status === "returned" ? ETelemetryOutcome.CANCELLED : ETelemetryOutcome.ERROR
|
|
28261
|
+
};
|
|
28262
|
+
try {
|
|
28263
|
+
if (classify) {
|
|
28264
|
+
const classified = classify(completion);
|
|
28265
|
+
result = {
|
|
28266
|
+
outcome: classified.outcome,
|
|
28267
|
+
attributes: classified.attributes
|
|
28268
|
+
};
|
|
28269
|
+
}
|
|
28270
|
+
} catch {
|
|
28271
|
+
}
|
|
28272
|
+
try {
|
|
28273
|
+
observation.finish(result.outcome, result.attributes ?? {});
|
|
28274
|
+
} catch {
|
|
28275
|
+
}
|
|
28276
|
+
}
|
|
28277
|
+
async function observePromise(create, task, classify) {
|
|
28278
|
+
const observation = createObservation(create);
|
|
28279
|
+
let completion = { status: "returned" };
|
|
28280
|
+
try {
|
|
28281
|
+
const value = await task(observation);
|
|
28282
|
+
completion = { status: "fulfilled", value };
|
|
28283
|
+
return value;
|
|
28284
|
+
} catch (error) {
|
|
28285
|
+
completion = { status: "rejected", error };
|
|
28286
|
+
throw error;
|
|
28287
|
+
} finally {
|
|
28288
|
+
settle(observation, completion, classify);
|
|
28289
|
+
}
|
|
28290
|
+
}
|
|
28291
|
+
async function* observeStream(create, source, classify) {
|
|
28292
|
+
const observation = createObservation(create);
|
|
28293
|
+
let completion = { status: "returned" };
|
|
28294
|
+
try {
|
|
28295
|
+
const value = yield* source(observation);
|
|
28296
|
+
completion = { status: "fulfilled", value };
|
|
28297
|
+
return value;
|
|
28298
|
+
} catch (error) {
|
|
28299
|
+
completion = { status: "rejected", error };
|
|
28300
|
+
throw error;
|
|
28301
|
+
} finally {
|
|
28302
|
+
settle(observation, completion, classify);
|
|
28303
|
+
}
|
|
28304
|
+
}
|
|
28305
|
+
function observeEvent(create, subscribe, classify) {
|
|
28306
|
+
return observePromise(create, async (observation) => {
|
|
28307
|
+
const cleanup = {};
|
|
28308
|
+
try {
|
|
28309
|
+
return await new Promise((resolve, reject) => {
|
|
28310
|
+
const unsubscribe = subscribe(observation, resolve, reject);
|
|
28311
|
+
if (unsubscribe)
|
|
28312
|
+
cleanup.unsubscribe = unsubscribe;
|
|
28313
|
+
});
|
|
28314
|
+
} finally {
|
|
28315
|
+
try {
|
|
28316
|
+
cleanup.unsubscribe?.();
|
|
28317
|
+
} catch {
|
|
28318
|
+
}
|
|
28319
|
+
}
|
|
28320
|
+
}, classify);
|
|
27921
28321
|
}
|
|
27922
28322
|
|
|
27923
28323
|
// ../linkque-agent-runtime/dist/esm/core/hook/hookDispatcher.js
|
|
@@ -28077,21 +28477,21 @@ var HookDispatcher = class {
|
|
|
28077
28477
|
* 触发一个 stage:命中 hook 后按序调度。状态型 hook 必须成功;旁路 hook 立即返回。
|
|
28078
28478
|
*/
|
|
28079
28479
|
async dispatch(stage, commonParams, subject = {}, runtimeInput, parent = this.deps.observation) {
|
|
28080
|
-
|
|
28480
|
+
let matched = 0;
|
|
28481
|
+
let scheduled = 0;
|
|
28482
|
+
return observePromise(() => parent?.startOperation({
|
|
28081
28483
|
name: ETelemetryOperationName.HOOK_CHAIN,
|
|
28082
28484
|
eventPrefix: ETelemetryEventPrefix.HOOK_CHAIN,
|
|
28083
28485
|
attributes: { [ETelemetryAttribute.LINKQUE_HOOK_STAGE]: stage },
|
|
28084
28486
|
detached: false,
|
|
28085
28487
|
links: []
|
|
28086
|
-
})
|
|
28087
|
-
let matched = 0;
|
|
28088
|
-
let scheduled = 0;
|
|
28089
|
-
try {
|
|
28488
|
+
}), async (observation) => {
|
|
28090
28489
|
const now = this.deps.now ?? Date.now;
|
|
28091
28490
|
const patches = [];
|
|
28092
28491
|
for (const resource of this.resources) {
|
|
28093
|
-
if (!matchHookResource(resource, stage, subject))
|
|
28492
|
+
if (!matchHookResource(resource, stage, subject)) {
|
|
28094
28493
|
continue;
|
|
28494
|
+
}
|
|
28095
28495
|
if (this.deps.hookExecutor.matches?.(resource, stage, subject) === false) {
|
|
28096
28496
|
continue;
|
|
28097
28497
|
}
|
|
@@ -28119,19 +28519,34 @@ var HookDispatcher = class {
|
|
|
28119
28519
|
this.scheduleDetached(resource, context2, observation);
|
|
28120
28520
|
}
|
|
28121
28521
|
}
|
|
28122
|
-
observation?.finish(ETelemetryOutcome.SUCCESS, {
|
|
28123
|
-
[ETelemetryAttribute.LINKQUE_HOOK_MATCHED_COUNT]: matched,
|
|
28124
|
-
[ETelemetryAttribute.LINKQUE_HOOK_SCHEDULED_COUNT]: scheduled
|
|
28125
|
-
});
|
|
28126
28522
|
return { patches };
|
|
28127
|
-
}
|
|
28128
|
-
|
|
28129
|
-
|
|
28130
|
-
|
|
28131
|
-
|
|
28132
|
-
|
|
28133
|
-
|
|
28134
|
-
|
|
28523
|
+
}, (completion) => {
|
|
28524
|
+
if (completion.status === "fulfilled") {
|
|
28525
|
+
return {
|
|
28526
|
+
outcome: ETelemetryOutcome.SUCCESS,
|
|
28527
|
+
attributes: {
|
|
28528
|
+
[ETelemetryAttribute.LINKQUE_HOOK_MATCHED_COUNT]: matched,
|
|
28529
|
+
[ETelemetryAttribute.LINKQUE_HOOK_SCHEDULED_COUNT]: scheduled
|
|
28530
|
+
}
|
|
28531
|
+
};
|
|
28532
|
+
} else if (completion.status === "rejected") {
|
|
28533
|
+
return {
|
|
28534
|
+
outcome: ETelemetryOutcome.ERROR,
|
|
28535
|
+
attributes: {
|
|
28536
|
+
[ETelemetryAttribute.LINKQUE_HOOK_MATCHED_COUNT]: matched,
|
|
28537
|
+
[ETelemetryAttribute.LINKQUE_HOOK_SCHEDULED_COUNT]: scheduled,
|
|
28538
|
+
[ETelemetryAttribute.ERROR_TYPE]: ETelemetryErrorType.HOOK_DISPATCH_ERROR
|
|
28539
|
+
}
|
|
28540
|
+
};
|
|
28541
|
+
}
|
|
28542
|
+
return {
|
|
28543
|
+
outcome: ETelemetryOutcome.ERROR,
|
|
28544
|
+
attributes: {
|
|
28545
|
+
[ETelemetryAttribute.LINKQUE_HOOK_MATCHED_COUNT]: matched,
|
|
28546
|
+
[ETelemetryAttribute.LINKQUE_HOOK_SCHEDULED_COUNT]: scheduled
|
|
28547
|
+
}
|
|
28548
|
+
};
|
|
28549
|
+
});
|
|
28135
28550
|
}
|
|
28136
28551
|
/** 构造 stage-specific context(discriminated union 分支)。 */
|
|
28137
28552
|
buildContext(resource, stage, commonParams, subject, now) {
|
|
@@ -28305,6 +28720,7 @@ var HookDispatcher = class {
|
|
|
28305
28720
|
try {
|
|
28306
28721
|
const timeoutMs = resource.config.timeoutMs ?? 1e3;
|
|
28307
28722
|
const timeoutReason = new Error(`\u72B6\u6001\u578B Hook ${resource.config.name} \u6267\u884C\u8D85\u65F6(${timeoutMs}ms)`);
|
|
28723
|
+
timeoutReason.name = "TimeoutError";
|
|
28308
28724
|
const scope = new CancellationScope({
|
|
28309
28725
|
signals: runtimeInput?.signal ? [runtimeInput.signal] : [],
|
|
28310
28726
|
timeoutMs,
|
|
@@ -28314,7 +28730,7 @@ var HookDispatcher = class {
|
|
|
28314
28730
|
let onAbort;
|
|
28315
28731
|
try {
|
|
28316
28732
|
scope.context.throwIfAborted();
|
|
28317
|
-
|
|
28733
|
+
const execution = observePromise(() => parent?.startOperation({
|
|
28318
28734
|
name: ETelemetryOperationName.MIDDLEWARE,
|
|
28319
28735
|
eventPrefix: ETelemetryEventPrefix.MIDDLEWARE,
|
|
28320
28736
|
attributes: {
|
|
@@ -28327,43 +28743,55 @@ var HookDispatcher = class {
|
|
|
28327
28743
|
},
|
|
28328
28744
|
detached: false,
|
|
28329
28745
|
links: []
|
|
28330
|
-
})
|
|
28331
|
-
|
|
28332
|
-
|
|
28333
|
-
|
|
28334
|
-
|
|
28335
|
-
|
|
28336
|
-
|
|
28337
|
-
|
|
28338
|
-
|
|
28339
|
-
|
|
28340
|
-
|
|
28341
|
-
|
|
28342
|
-
|
|
28343
|
-
[ETelemetryAttribute.LINKQUE_HOOK_EXECUTOR_SETTLED]: true,
|
|
28344
|
-
[ETelemetryAttribute.LINKQUE_HOOK_RESULT]: value.skipped ? ETelemetryHookResult.SKIPPED : value.ok ? ETelemetryHookResult.SUCCESS : ETelemetryHookResult.ERROR
|
|
28345
|
-
});
|
|
28346
|
-
if (timedOut || cancelled)
|
|
28347
|
-
observation?.finish(timedOut ? ETelemetryOutcome.TIMEOUT : ETelemetryOutcome.CANCELLED, {
|
|
28348
|
-
[ETelemetryAttribute.LINKQUE_OBSERVATION_BOUNDARY]: ETelemetryObservationBoundary.EXECUTOR_SETTLED,
|
|
28349
|
-
[ETelemetryAttribute.LINKQUE_HOOK_EXECUTOR_SETTLED]: true,
|
|
28350
|
-
[ETelemetryAttribute.LINKQUE_HOOK_RESULT]: value.skipped ? ETelemetryHookResult.SKIPPED : value.ok ? ETelemetryHookResult.SUCCESS : ETelemetryHookResult.ERROR
|
|
28746
|
+
}), async (current) => {
|
|
28747
|
+
observation = current;
|
|
28748
|
+
onAbort = () => {
|
|
28749
|
+
timedOut = executorSignal.reason === timeoutReason;
|
|
28750
|
+
cancelled = !timedOut;
|
|
28751
|
+
observation?.record(timedOut ? ETelemetryEventName.HOOK_TIMEOUT_REQUESTED : ETelemetryEventName.HOOK_CANCEL_REQUESTED, {});
|
|
28752
|
+
};
|
|
28753
|
+
executorSignal.addEventListener("abort", onAbort, { once: true });
|
|
28754
|
+
try {
|
|
28755
|
+
return await this.deps.hookExecutor.execute(resource, context2, {
|
|
28756
|
+
observation: current,
|
|
28757
|
+
signal: executorSignal,
|
|
28758
|
+
...runtimeInput === void 0 ? {} : { runtimeInput }
|
|
28351
28759
|
});
|
|
28352
|
-
|
|
28353
|
-
|
|
28354
|
-
|
|
28760
|
+
} finally {
|
|
28761
|
+
settled = true;
|
|
28762
|
+
}
|
|
28763
|
+
}, (completion) => {
|
|
28764
|
+
const value = completion.status === "fulfilled" ? completion.value : void 0;
|
|
28765
|
+
let hookResult = ETelemetryHookResult.ERROR;
|
|
28766
|
+
if (value?.skipped) {
|
|
28767
|
+
hookResult = ETelemetryHookResult.SKIPPED;
|
|
28768
|
+
} else if (value?.ok) {
|
|
28769
|
+
hookResult = ETelemetryHookResult.SUCCESS;
|
|
28770
|
+
}
|
|
28355
28771
|
observation?.record(ETelemetryEventName.HOOK_EXECUTOR_SETTLED, {
|
|
28356
28772
|
[ETelemetryAttribute.LINKQUE_HOOK_EXECUTOR_SETTLED]: true,
|
|
28357
|
-
[ETelemetryAttribute.LINKQUE_HOOK_RESULT]:
|
|
28773
|
+
[ETelemetryAttribute.LINKQUE_HOOK_RESULT]: hookResult
|
|
28358
28774
|
});
|
|
28359
|
-
|
|
28360
|
-
|
|
28361
|
-
|
|
28362
|
-
|
|
28363
|
-
|
|
28364
|
-
|
|
28365
|
-
|
|
28366
|
-
|
|
28775
|
+
let outcome = ETelemetryOutcome.ERROR;
|
|
28776
|
+
if (timedOut) {
|
|
28777
|
+
outcome = ETelemetryOutcome.TIMEOUT;
|
|
28778
|
+
} else if (cancelled) {
|
|
28779
|
+
outcome = ETelemetryOutcome.CANCELLED;
|
|
28780
|
+
} else if (value?.skipped) {
|
|
28781
|
+
outcome = ETelemetryOutcome.UNKNOWN;
|
|
28782
|
+
} else if (value?.ok) {
|
|
28783
|
+
outcome = ETelemetryOutcome.SUCCESS;
|
|
28784
|
+
}
|
|
28785
|
+
const innerAttributes = {
|
|
28786
|
+
[ETelemetryAttribute.LINKQUE_HOOK_EXECUTOR_SETTLED]: true,
|
|
28787
|
+
[ETelemetryAttribute.LINKQUE_HOOK_RESULT]: hookResult
|
|
28788
|
+
};
|
|
28789
|
+
if (timedOut || cancelled || completion.status === "rejected") {
|
|
28790
|
+
innerAttributes[ETelemetryAttribute.LINKQUE_OBSERVATION_BOUNDARY] = ETelemetryObservationBoundary.EXECUTOR_SETTLED;
|
|
28791
|
+
}
|
|
28792
|
+
return { outcome, attributes: innerAttributes };
|
|
28793
|
+
});
|
|
28794
|
+
result = await waitWithSignal(execution, executorSignal);
|
|
28367
28795
|
} finally {
|
|
28368
28796
|
if (onAbort !== void 0)
|
|
28369
28797
|
executorSignal.removeEventListener("abort", onAbort);
|
|
@@ -28375,11 +28803,6 @@ var HookDispatcher = class {
|
|
|
28375
28803
|
[ETelemetryAttribute.LINKQUE_OBSERVATION_BOUNDARY]: ETelemetryObservationBoundary.LOCAL_WAIT,
|
|
28376
28804
|
[ETelemetryAttribute.LINKQUE_HOOK_EXECUTOR_SETTLED]: false
|
|
28377
28805
|
});
|
|
28378
|
-
} else {
|
|
28379
|
-
observation?.finish(timedOut ? ETelemetryOutcome.TIMEOUT : cancelled ? ETelemetryOutcome.CANCELLED : ETelemetryOutcome.ERROR, {
|
|
28380
|
-
[ETelemetryAttribute.LINKQUE_OBSERVATION_BOUNDARY]: ETelemetryObservationBoundary.EXECUTOR_SETTLED,
|
|
28381
|
-
[ETelemetryAttribute.LINKQUE_HOOK_EXECUTOR_SETTLED]: true
|
|
28382
|
-
});
|
|
28383
28806
|
}
|
|
28384
28807
|
writeHookLog(this.deps.debugLog, {
|
|
28385
28808
|
...baseRecord,
|
|
@@ -28395,10 +28818,6 @@ var HookDispatcher = class {
|
|
|
28395
28818
|
}));
|
|
28396
28819
|
throw error;
|
|
28397
28820
|
}
|
|
28398
|
-
observation?.finish(result.skipped ? ETelemetryOutcome.UNKNOWN : result.ok ? ETelemetryOutcome.SUCCESS : ETelemetryOutcome.ERROR, {
|
|
28399
|
-
[ETelemetryAttribute.LINKQUE_HOOK_RESULT]: result.skipped ? ETelemetryHookResult.SKIPPED : result.ok ? ETelemetryHookResult.SUCCESS : ETelemetryHookResult.ERROR,
|
|
28400
|
-
[ETelemetryAttribute.LINKQUE_HOOK_EXECUTOR_SETTLED]: true
|
|
28401
|
-
});
|
|
28402
28821
|
const costMs = now() - startedAt;
|
|
28403
28822
|
if (result.skipped) {
|
|
28404
28823
|
writeHookLog(this.deps.debugLog, {
|
|
@@ -28557,7 +28976,8 @@ var SideEffectRunner = class {
|
|
|
28557
28976
|
/** 执行单个旁路任务:超时/吞错/日志/指标全收口,永不 reject 到外部。 */
|
|
28558
28977
|
async runTask(task, signal, isTimedOut) {
|
|
28559
28978
|
const { resource, context: context2 } = task;
|
|
28560
|
-
|
|
28979
|
+
let startedAt = this.now();
|
|
28980
|
+
const metricResult = await observePromise(() => task.observation?.startOperation({
|
|
28561
28981
|
name: ETelemetryOperationName.MIDDLEWARE,
|
|
28562
28982
|
eventPrefix: ETelemetryEventPrefix.MIDDLEWARE,
|
|
28563
28983
|
detached: true,
|
|
@@ -28575,122 +28995,136 @@ var SideEffectRunner = class {
|
|
|
28575
28995
|
[ETelemetryAttribute.LINKQUE_HOOK_MODE]: ETelemetryHookMode.DETACHED,
|
|
28576
28996
|
[ETelemetryAttribute.LINKQUE_HOOK_TIMEOUT_MS]: task.timeoutMs
|
|
28577
28997
|
}
|
|
28578
|
-
})
|
|
28579
|
-
|
|
28580
|
-
|
|
28581
|
-
|
|
28582
|
-
|
|
28583
|
-
|
|
28584
|
-
|
|
28585
|
-
|
|
28586
|
-
|
|
28587
|
-
|
|
28588
|
-
|
|
28589
|
-
|
|
28590
|
-
|
|
28591
|
-
|
|
28592
|
-
|
|
28593
|
-
|
|
28594
|
-
|
|
28595
|
-
|
|
28596
|
-
|
|
28597
|
-
|
|
28598
|
-
|
|
28599
|
-
userId: context2.commonParams.userId
|
|
28600
|
-
},
|
|
28601
|
-
...context2.commonParams.traceId !== void 0 && {
|
|
28602
|
-
traceId: context2.commonParams.traceId
|
|
28603
|
-
}
|
|
28604
|
-
};
|
|
28605
|
-
writeHookLog(this.debugLog, { ...baseRecord, event: "started" });
|
|
28606
|
-
const startedAt = this.now();
|
|
28607
|
-
let result = "ok";
|
|
28608
|
-
try {
|
|
28609
|
-
const executeResult = await task.execute(signal);
|
|
28610
|
-
const costMs = this.now() - startedAt;
|
|
28611
|
-
if (isTimedOut()) {
|
|
28612
|
-
result = "timeout";
|
|
28613
|
-
writeHookLog(this.debugLog, {
|
|
28614
|
-
...baseRecord,
|
|
28615
|
-
event: "timeout",
|
|
28616
|
-
timeoutMs: task.timeoutMs,
|
|
28617
|
-
costMs,
|
|
28618
|
-
result
|
|
28619
|
-
});
|
|
28620
|
-
} else if (executeResult.skipped) {
|
|
28621
|
-
result = "skipped";
|
|
28622
|
-
writeHookLog(this.debugLog, {
|
|
28623
|
-
...baseRecord,
|
|
28624
|
-
event: "skipped",
|
|
28625
|
-
costMs,
|
|
28626
|
-
result,
|
|
28627
|
-
...executeResult.code !== void 0 && { code: executeResult.code },
|
|
28628
|
-
...executeResult.message !== void 0 && {
|
|
28629
|
-
message: executeResult.message
|
|
28630
|
-
}
|
|
28631
|
-
});
|
|
28632
|
-
} else if (executeResult.ok) {
|
|
28633
|
-
writeHookLog(this.debugLog, {
|
|
28634
|
-
...baseRecord,
|
|
28635
|
-
event: "completed",
|
|
28636
|
-
costMs,
|
|
28637
|
-
result
|
|
28638
|
-
});
|
|
28639
|
-
} else {
|
|
28640
|
-
result = "error";
|
|
28641
|
-
writeHookLog(this.debugLog, {
|
|
28642
|
-
...baseRecord,
|
|
28643
|
-
event: "failed",
|
|
28644
|
-
costMs,
|
|
28645
|
-
result,
|
|
28646
|
-
...executeResult.code !== void 0 && { code: executeResult.code },
|
|
28647
|
-
...executeResult.retryable !== void 0 && {
|
|
28648
|
-
retryable: executeResult.retryable
|
|
28998
|
+
}), async (observation) => {
|
|
28999
|
+
let result = "ok";
|
|
29000
|
+
const onAbort = () => observation?.record(ETelemetryEventName.HOOK_TIMEOUT_REQUESTED, {});
|
|
29001
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
29002
|
+
try {
|
|
29003
|
+
const baseRecord = {
|
|
29004
|
+
tag: "hook",
|
|
29005
|
+
hookId: resource.resourceId,
|
|
29006
|
+
hookName: resource.config.name,
|
|
29007
|
+
stage: context2.stage,
|
|
29008
|
+
providerType: resource.providerType,
|
|
29009
|
+
hasSideEffects: resource.config.hasSideEffects,
|
|
29010
|
+
eventId: context2.eventId,
|
|
29011
|
+
runId: context2.commonParams.runId,
|
|
29012
|
+
conversationId: context2.commonParams.conversationId,
|
|
29013
|
+
...context2.commonParams.runIndex !== void 0 && {
|
|
29014
|
+
runIndex: context2.commonParams.runIndex
|
|
29015
|
+
},
|
|
29016
|
+
agentId: context2.commonParams.agentId,
|
|
29017
|
+
...context2.commonParams.sessionId !== void 0 && {
|
|
29018
|
+
sessionId: context2.commonParams.sessionId
|
|
28649
29019
|
},
|
|
28650
|
-
...
|
|
28651
|
-
|
|
29020
|
+
...context2.commonParams.userId !== void 0 && {
|
|
29021
|
+
userId: context2.commonParams.userId
|
|
29022
|
+
},
|
|
29023
|
+
...context2.commonParams.traceId !== void 0 && {
|
|
29024
|
+
traceId: context2.commonParams.traceId
|
|
28652
29025
|
}
|
|
28653
|
-
}
|
|
28654
|
-
|
|
28655
|
-
|
|
28656
|
-
|
|
28657
|
-
|
|
28658
|
-
|
|
28659
|
-
|
|
28660
|
-
|
|
28661
|
-
|
|
28662
|
-
|
|
28663
|
-
|
|
28664
|
-
|
|
28665
|
-
|
|
28666
|
-
|
|
28667
|
-
|
|
28668
|
-
|
|
28669
|
-
|
|
28670
|
-
|
|
28671
|
-
|
|
28672
|
-
|
|
28673
|
-
|
|
28674
|
-
|
|
28675
|
-
|
|
29026
|
+
};
|
|
29027
|
+
writeHookLog(this.debugLog, { ...baseRecord, event: "started" });
|
|
29028
|
+
startedAt = this.now();
|
|
29029
|
+
try {
|
|
29030
|
+
const executeResult = await task.execute(signal);
|
|
29031
|
+
const costMs = this.now() - startedAt;
|
|
29032
|
+
if (isTimedOut()) {
|
|
29033
|
+
result = "timeout";
|
|
29034
|
+
writeHookLog(this.debugLog, {
|
|
29035
|
+
...baseRecord,
|
|
29036
|
+
event: "timeout",
|
|
29037
|
+
timeoutMs: task.timeoutMs,
|
|
29038
|
+
costMs,
|
|
29039
|
+
result
|
|
29040
|
+
});
|
|
29041
|
+
} else if (executeResult.skipped) {
|
|
29042
|
+
result = "skipped";
|
|
29043
|
+
writeHookLog(this.debugLog, {
|
|
29044
|
+
...baseRecord,
|
|
29045
|
+
event: "skipped",
|
|
29046
|
+
costMs,
|
|
29047
|
+
result,
|
|
29048
|
+
...executeResult.code !== void 0 && {
|
|
29049
|
+
code: executeResult.code
|
|
29050
|
+
},
|
|
29051
|
+
...executeResult.message !== void 0 && {
|
|
29052
|
+
message: executeResult.message
|
|
29053
|
+
}
|
|
29054
|
+
});
|
|
29055
|
+
} else if (executeResult.ok) {
|
|
29056
|
+
writeHookLog(this.debugLog, {
|
|
29057
|
+
...baseRecord,
|
|
29058
|
+
event: "completed",
|
|
29059
|
+
costMs,
|
|
29060
|
+
result
|
|
29061
|
+
});
|
|
29062
|
+
} else {
|
|
29063
|
+
result = "error";
|
|
29064
|
+
writeHookLog(this.debugLog, {
|
|
29065
|
+
...baseRecord,
|
|
29066
|
+
event: "failed",
|
|
29067
|
+
costMs,
|
|
29068
|
+
result,
|
|
29069
|
+
...executeResult.code !== void 0 && {
|
|
29070
|
+
code: executeResult.code
|
|
29071
|
+
},
|
|
29072
|
+
...executeResult.retryable !== void 0 && {
|
|
29073
|
+
retryable: executeResult.retryable
|
|
29074
|
+
},
|
|
29075
|
+
...executeResult.message !== void 0 && {
|
|
29076
|
+
message: executeResult.message
|
|
29077
|
+
}
|
|
29078
|
+
});
|
|
29079
|
+
}
|
|
29080
|
+
} catch (error) {
|
|
29081
|
+
const costMs = this.now() - startedAt;
|
|
29082
|
+
if (isTimedOut()) {
|
|
29083
|
+
result = "timeout";
|
|
29084
|
+
writeHookLog(this.debugLog, {
|
|
29085
|
+
...baseRecord,
|
|
29086
|
+
event: "timeout",
|
|
29087
|
+
timeoutMs: task.timeoutMs,
|
|
29088
|
+
costMs,
|
|
29089
|
+
result
|
|
29090
|
+
});
|
|
29091
|
+
} else {
|
|
29092
|
+
result = "error";
|
|
29093
|
+
writeHookLog(this.debugLog, {
|
|
29094
|
+
...baseRecord,
|
|
29095
|
+
event: "failed",
|
|
29096
|
+
costMs,
|
|
29097
|
+
result,
|
|
29098
|
+
code: "EXECUTOR_THROW",
|
|
29099
|
+
message: error instanceof Error ? error.message : String(error)
|
|
29100
|
+
});
|
|
29101
|
+
}
|
|
29102
|
+
}
|
|
29103
|
+
} finally {
|
|
29104
|
+
signal.removeEventListener("abort", onAbort);
|
|
28676
29105
|
}
|
|
28677
|
-
|
|
28678
|
-
|
|
28679
|
-
|
|
28680
|
-
|
|
28681
|
-
|
|
29106
|
+
return result;
|
|
29107
|
+
}, (completion) => {
|
|
29108
|
+
const result = completion.status === "fulfilled" ? completion.value : "error";
|
|
29109
|
+
return {
|
|
29110
|
+
outcome: completion.status === "rejected" ? ETelemetryOutcome.ERROR : result === ETelemetryHookResult.OK ? ETelemetryOutcome.SUCCESS : result === ETelemetryHookResult.SKIPPED ? ETelemetryOutcome.UNKNOWN : result === ETelemetryHookResult.TIMEOUT ? ETelemetryOutcome.TIMEOUT : ETelemetryOutcome.ERROR,
|
|
29111
|
+
attributes: {
|
|
29112
|
+
[ETelemetryAttribute.LINKQUE_HOOK_RESULT]: result,
|
|
29113
|
+
[ETelemetryAttribute.LINKQUE_HOOK_EXECUTOR_SETTLED]: true
|
|
29114
|
+
}
|
|
29115
|
+
};
|
|
28682
29116
|
});
|
|
28683
29117
|
const labels = hookMetricLabels(resource, context2.commonParams);
|
|
28684
29118
|
this.metricsSink?.increment(HOOK_METRIC.EXECUTE_TOTAL, {
|
|
28685
29119
|
...labels,
|
|
28686
29120
|
sideEffect: 1,
|
|
28687
|
-
result
|
|
29121
|
+
result: metricResult
|
|
28688
29122
|
});
|
|
28689
|
-
this.metricsSink?.histogram(HOOK_METRIC.DURATION_MS, this.now() - startedAt, { ...labels, result });
|
|
28690
|
-
if (
|
|
29123
|
+
this.metricsSink?.histogram(HOOK_METRIC.DURATION_MS, this.now() - startedAt, { ...labels, result: metricResult });
|
|
29124
|
+
if (metricResult === "timeout") {
|
|
28691
29125
|
this.metricsSink?.increment(HOOK_METRIC.TIMEOUT_TOTAL, labels);
|
|
28692
29126
|
}
|
|
28693
|
-
if (
|
|
29127
|
+
if (metricResult === "skipped") {
|
|
28694
29128
|
this.metricsSink?.increment(HOOK_METRIC.SKIPPED_TOTAL, {
|
|
28695
29129
|
...labels,
|
|
28696
29130
|
reason: "executor_skipped"
|
|
@@ -28795,6 +29229,7 @@ var LINKQUE_ENDPOINT_PROD = "https://linkquegw.alipay.com";
|
|
|
28795
29229
|
var RUNTIME_CONFIG_DEFAULTS = Object.freeze({
|
|
28796
29230
|
LINKQUE_BASE_URL: `${LINKQUE_ENDPOINT_PROD}/api/anthropic`,
|
|
28797
29231
|
LINKQUEGW_KNOWLEDGE_BASE_URL: LINKQUE_ENDPOINT_PROD,
|
|
29232
|
+
LINKQUEGW_SKILL_LOADER_BASE_URL: LINKQUE_ENDPOINT_PROD,
|
|
28798
29233
|
LINKQUEGW_WEB_SEARCH_BASE_URL: LINKQUE_ENDPOINT_PROD,
|
|
28799
29234
|
LINKQUEGW_EVENT_BASE_URL: LINKQUE_ENDPOINT_PROD,
|
|
28800
29235
|
LINKQUEGW_MCP_SIGN_ENDPOINT: `${LINKQUE_ENDPOINT_PROD}/api/mcp/signature`,
|
|
@@ -29305,9 +29740,6 @@ function throwIfWebSearchAborted(signal) {
|
|
|
29305
29740
|
if (signal?.aborted)
|
|
29306
29741
|
throw new DOMException("\u5168\u7F51\u641C\u7D22\u5DF2\u53D6\u6D88", "AbortError");
|
|
29307
29742
|
}
|
|
29308
|
-
async function awaitWebSearchOperation(operation, signal) {
|
|
29309
|
-
return waitWithSignal(operation, signal);
|
|
29310
|
-
}
|
|
29311
29743
|
|
|
29312
29744
|
// ../linkque-agent-runtime/dist/esm/core/webSearchResource.js
|
|
29313
29745
|
function resolveWebSearchResource(resources) {
|
|
@@ -29352,7 +29784,7 @@ function createWebSearchTool(resource, searchPort, agentId, debugLog) {
|
|
|
29352
29784
|
annotations: { readOnlyHint: true },
|
|
29353
29785
|
execute: search3
|
|
29354
29786
|
};
|
|
29355
|
-
async function search3(args, signal) {
|
|
29787
|
+
async function search3(args, signal, context2) {
|
|
29356
29788
|
const startedAt = Date.now();
|
|
29357
29789
|
let query = "";
|
|
29358
29790
|
let outcome = "success";
|
|
@@ -29361,7 +29793,7 @@ function createWebSearchTool(resource, searchPort, agentId, debugLog) {
|
|
|
29361
29793
|
throwIfWebSearchAborted(signal);
|
|
29362
29794
|
const parsed = parseWebSearchArgs(args);
|
|
29363
29795
|
query = parsed.query;
|
|
29364
|
-
const result = await
|
|
29796
|
+
const result = await waitWithSignal(() => searchPort.search({ agentId, ...parsed }, signal, context2?.observation), signal);
|
|
29365
29797
|
throwIfWebSearchAborted(signal);
|
|
29366
29798
|
count = result.items.length;
|
|
29367
29799
|
return result;
|
|
@@ -29370,19 +29802,18 @@ function createWebSearchTool(resource, searchPort, agentId, debugLog) {
|
|
|
29370
29802
|
outcome = "cancelled";
|
|
29371
29803
|
throw new DOMException("\u5168\u7F51\u641C\u7D22\u5DF2\u53D6\u6D88", "AbortError");
|
|
29372
29804
|
}
|
|
29373
|
-
const
|
|
29374
|
-
outcome =
|
|
29375
|
-
return { query, items: [], error:
|
|
29805
|
+
const failure4 = toWebSearchFailure(error);
|
|
29806
|
+
outcome = failure4.code;
|
|
29807
|
+
return { query, items: [], error: failure4 };
|
|
29376
29808
|
} finally {
|
|
29377
|
-
|
|
29809
|
+
skipError(() => {
|
|
29378
29810
|
debugLog?.(JSON.stringify({
|
|
29379
29811
|
tag: "web-search-tool",
|
|
29380
29812
|
outcome,
|
|
29381
29813
|
count,
|
|
29382
29814
|
durationMs: Date.now() - startedAt
|
|
29383
29815
|
}), EDebugLogScope.MCP);
|
|
29384
|
-
}
|
|
29385
|
-
}
|
|
29816
|
+
});
|
|
29386
29817
|
}
|
|
29387
29818
|
}
|
|
29388
29819
|
}
|
|
@@ -29501,7 +29932,7 @@ function createKnowledgeTools(resources, searchPort, agentId) {
|
|
|
29501
29932
|
knowledgeBaseId: parsed.knowledgeBaseId,
|
|
29502
29933
|
agentId,
|
|
29503
29934
|
topK: parsed.topK
|
|
29504
|
-
}, signal);
|
|
29935
|
+
}, signal, obs);
|
|
29505
29936
|
recordContentSection(obs, ETelemetryContentSection.KNOWLEDGE_OUTPUT, {
|
|
29506
29937
|
status: result.hits.length ? "matched" : "no_hits",
|
|
29507
29938
|
hits: result.hits
|
|
@@ -29519,174 +29950,61 @@ function createKnowledgeTools(resources, searchPort, agentId) {
|
|
|
29519
29950
|
}
|
|
29520
29951
|
}
|
|
29521
29952
|
async function getKnowledgeBases() {
|
|
29522
|
-
if (!cachedKnowledgeBases) {
|
|
29523
|
-
cachedKnowledgeBases = await searchPort.listKnowledgeBases(resources);
|
|
29524
|
-
}
|
|
29525
|
-
return cachedKnowledgeBases;
|
|
29526
|
-
}
|
|
29527
|
-
}
|
|
29528
|
-
|
|
29529
|
-
// ../linkque-agent-runtime/dist/esm/core/noopWebSearchPort.js
|
|
29530
|
-
var NoopWebSearchPort = class {
|
|
29531
|
-
async search(_input, signal) {
|
|
29532
|
-
throwIfWebSearchAborted(signal);
|
|
29533
|
-
throw new WebSearchError("WEB_SEARCH_UNAVAILABLE");
|
|
29534
|
-
}
|
|
29535
|
-
};
|
|
29536
|
-
|
|
29537
|
-
// ../linkque-agent-runtime/dist/esm/core/telemetry/noopRuntimeTelemetry.js
|
|
29538
|
-
var NoopRuntimeObservation = class {
|
|
29539
|
-
enabled = false;
|
|
29540
|
-
operationId = "";
|
|
29541
|
-
spanContext = null;
|
|
29542
|
-
startOperation(_operation) {
|
|
29543
|
-
return this;
|
|
29544
|
-
}
|
|
29545
|
-
record(_name, _attributes, _body) {
|
|
29546
|
-
}
|
|
29547
|
-
finish(_outcome, _attributes) {
|
|
29548
|
-
}
|
|
29549
|
-
abandon(_reason) {
|
|
29550
|
-
}
|
|
29551
|
-
};
|
|
29552
|
-
var NoopRuntimeTelemetry = class {
|
|
29553
|
-
startAdvance(_input) {
|
|
29554
|
-
return new NoopRuntimeObservation();
|
|
29555
|
-
}
|
|
29556
|
-
async forceFlush(_options) {
|
|
29557
|
-
return { completed: true, pendingCount: 0, sentCount: 0, droppedCount: 0 };
|
|
29558
|
-
}
|
|
29559
|
-
shutdown(options) {
|
|
29560
|
-
return this.forceFlush(options);
|
|
29561
|
-
}
|
|
29562
|
-
};
|
|
29563
|
-
|
|
29564
|
-
// ../linkque-agent-runtime/dist/esm/core/telemetry/runtimeObservation.js
|
|
29565
|
-
var RuntimeObservation = class _RuntimeObservation {
|
|
29566
|
-
sink;
|
|
29567
|
-
associations;
|
|
29568
|
-
key;
|
|
29569
|
-
scope;
|
|
29570
|
-
finished = false;
|
|
29571
|
-
abandoned = false;
|
|
29572
|
-
resultAttributes = {};
|
|
29573
|
-
constructor(sink, associations = /* @__PURE__ */ new Map(), key, scope = {
|
|
29574
|
-
active: /* @__PURE__ */ new Set(),
|
|
29575
|
-
abandoned: false
|
|
29576
|
-
}) {
|
|
29577
|
-
this.sink = sink;
|
|
29578
|
-
this.associations = associations;
|
|
29579
|
-
this.key = key;
|
|
29580
|
-
this.scope = scope;
|
|
29581
|
-
}
|
|
29582
|
-
get enabled() {
|
|
29583
|
-
try {
|
|
29584
|
-
return this.sink.enabled;
|
|
29585
|
-
} catch {
|
|
29586
|
-
return false;
|
|
29587
|
-
}
|
|
29588
|
-
}
|
|
29589
|
-
get operationId() {
|
|
29590
|
-
try {
|
|
29591
|
-
return this.sink.operationId;
|
|
29592
|
-
} catch {
|
|
29593
|
-
return "";
|
|
29594
|
-
}
|
|
29595
|
-
}
|
|
29596
|
-
get spanContext() {
|
|
29597
|
-
try {
|
|
29598
|
-
return this.sink.spanContext;
|
|
29599
|
-
} catch {
|
|
29600
|
-
return null;
|
|
29601
|
-
}
|
|
29602
|
-
}
|
|
29603
|
-
startOperation(operation, key) {
|
|
29604
|
-
if (this.scope.abandoned)
|
|
29605
|
-
return new _RuntimeObservation(new NoopRuntimeObservation());
|
|
29606
|
-
if (this.scope.active.size >= 4096) {
|
|
29607
|
-
this.record(ETelemetryEventName.OPERATION_OBSERVATION_LOST, {
|
|
29608
|
-
[ETelemetryAttribute.LINKQUE_TELEMETRY_LOSS_REASON]: ETelemetryLossReason.ACTIVE_LIMIT
|
|
29609
|
-
});
|
|
29610
|
-
return new _RuntimeObservation(new NoopRuntimeObservation());
|
|
29611
|
-
}
|
|
29612
|
-
let sink = new NoopRuntimeObservation();
|
|
29613
|
-
try {
|
|
29614
|
-
if (this.enabled)
|
|
29615
|
-
sink = this.sink.startOperation(operation);
|
|
29616
|
-
} catch {
|
|
29953
|
+
if (!cachedKnowledgeBases) {
|
|
29954
|
+
cachedKnowledgeBases = await searchPort.listKnowledgeBases(resources);
|
|
29617
29955
|
}
|
|
29618
|
-
|
|
29619
|
-
if (child.enabled)
|
|
29620
|
-
this.scope.active.add(child);
|
|
29621
|
-
if (key && child.enabled && this.associations.size < 4096)
|
|
29622
|
-
this.associations.set(key, child);
|
|
29623
|
-
return child;
|
|
29956
|
+
return cachedKnowledgeBases;
|
|
29624
29957
|
}
|
|
29625
|
-
|
|
29626
|
-
|
|
29958
|
+
}
|
|
29959
|
+
|
|
29960
|
+
// ../linkque-agent-runtime/dist/esm/core/noopWebSearchPort.js
|
|
29961
|
+
var NoopWebSearchPort = class {
|
|
29962
|
+
async search(_input, signal) {
|
|
29963
|
+
throwIfWebSearchAborted(signal);
|
|
29964
|
+
throw new WebSearchError("WEB_SEARCH_UNAVAILABLE");
|
|
29627
29965
|
}
|
|
29628
|
-
|
|
29629
|
-
|
|
29966
|
+
};
|
|
29967
|
+
|
|
29968
|
+
// ../linkque-agent-runtime/dist/esm/core/telemetry/eventObservationRegistry.js
|
|
29969
|
+
var EventObservationRegistry = class {
|
|
29970
|
+
events = /* @__PURE__ */ new WeakMap();
|
|
29971
|
+
parents = /* @__PURE__ */ new Map();
|
|
29972
|
+
closed = false;
|
|
29973
|
+
associate(event, observation) {
|
|
29974
|
+
if (this.closed || !observation)
|
|
29630
29975
|
return;
|
|
29631
|
-
|
|
29632
|
-
|
|
29633
|
-
|
|
29634
|
-
[ETelemetryAttribute.LINKQUE_TOOL_FAILURE_STAGE]: attributes[ETelemetryAttribute.LINKQUE_TOOL_FAILURE_STAGE]
|
|
29635
|
-
};
|
|
29636
|
-
this.sink.record(name, attributes, body);
|
|
29637
|
-
} catch {
|
|
29638
|
-
}
|
|
29639
|
-
}
|
|
29640
|
-
finish(outcome, attributes) {
|
|
29641
|
-
if (this.finished)
|
|
29976
|
+
const safe = new RuntimeObservation(observation);
|
|
29977
|
+
const key = safe.operationId;
|
|
29978
|
+
if (!key)
|
|
29642
29979
|
return;
|
|
29643
|
-
|
|
29644
|
-
this.
|
|
29645
|
-
|
|
29646
|
-
|
|
29647
|
-
|
|
29648
|
-
|
|
29649
|
-
|
|
29980
|
+
let parent = this.parents.get(key);
|
|
29981
|
+
if (!parent && this.parents.size < 4096) {
|
|
29982
|
+
parent = safe.captureParent();
|
|
29983
|
+
if (!parent.spanContext) {
|
|
29984
|
+
parent.release();
|
|
29985
|
+
return;
|
|
29986
|
+
}
|
|
29987
|
+
this.parents.set(key, parent);
|
|
29650
29988
|
}
|
|
29989
|
+
if (parent)
|
|
29990
|
+
this.events.set(event, parent);
|
|
29651
29991
|
}
|
|
29652
|
-
|
|
29653
|
-
|
|
29654
|
-
return;
|
|
29655
|
-
this.finished = true;
|
|
29656
|
-
this.abandoned = true;
|
|
29657
|
-
this.scope.active.delete(this);
|
|
29658
|
-
if (this.key && this.associations.get(this.key) === this)
|
|
29659
|
-
this.associations.delete(this.key);
|
|
29660
|
-
try {
|
|
29661
|
-
this.sink.abandon(reason);
|
|
29662
|
-
} catch {
|
|
29663
|
-
}
|
|
29992
|
+
get(event) {
|
|
29993
|
+
return this.events.get(event);
|
|
29664
29994
|
}
|
|
29665
|
-
|
|
29666
|
-
|
|
29667
|
-
this.
|
|
29668
|
-
|
|
29669
|
-
operation.abandon(reason);
|
|
29670
|
-
this.associations.clear();
|
|
29995
|
+
transfer(from, to) {
|
|
29996
|
+
const parent = this.get(from);
|
|
29997
|
+
if (!this.closed && parent)
|
|
29998
|
+
this.events.set(to, parent);
|
|
29671
29999
|
}
|
|
29672
|
-
|
|
29673
|
-
|
|
29674
|
-
for (const
|
|
29675
|
-
|
|
29676
|
-
|
|
29677
|
-
|
|
29678
|
-
});
|
|
29679
|
-
}
|
|
29680
|
-
this.associations.clear();
|
|
30000
|
+
close() {
|
|
30001
|
+
this.closed = true;
|
|
30002
|
+
for (const parent of this.parents.values())
|
|
30003
|
+
parent.release();
|
|
30004
|
+
this.parents.clear();
|
|
30005
|
+
this.events = /* @__PURE__ */ new WeakMap();
|
|
29681
30006
|
}
|
|
29682
30007
|
};
|
|
29683
|
-
function startRuntimeObservation(telemetry, input) {
|
|
29684
|
-
try {
|
|
29685
|
-
return new RuntimeObservation(telemetry.startAdvance(input));
|
|
29686
|
-
} catch {
|
|
29687
|
-
return new RuntimeObservation(new NoopRuntimeObservation());
|
|
29688
|
-
}
|
|
29689
|
-
}
|
|
29690
30008
|
|
|
29691
30009
|
// ../agent-conversation-contract/dist/esm/version.js
|
|
29692
30010
|
var CONVERSATION_PROTOCOL_VERSION = "1.0";
|
|
@@ -30442,10 +30760,6 @@ function createConversationCustomEvent(name, value, fields = {}) {
|
|
|
30442
30760
|
}
|
|
30443
30761
|
|
|
30444
30762
|
// ../agent-conversation-contract/dist/esm/run.js
|
|
30445
|
-
var CONVERSATION_CLIENT_CAPABILITIES = [
|
|
30446
|
-
"location",
|
|
30447
|
-
"userInfo"
|
|
30448
|
-
];
|
|
30449
30763
|
var ConversationProtocolValidationError = class extends Error {
|
|
30450
30764
|
issues;
|
|
30451
30765
|
code = "CONVERSATION_PROTOCOL_INVALID";
|
|
@@ -30490,8 +30804,8 @@ function getConversationRunRequestIssues(value) {
|
|
|
30490
30804
|
if (value.clientCapabilities !== void 0) {
|
|
30491
30805
|
if (!Array.isArray(value.clientCapabilities)) {
|
|
30492
30806
|
issues.push("clientCapabilities must be an array when provided");
|
|
30493
|
-
} else if (!value.clientCapabilities.every(
|
|
30494
|
-
issues.push("clientCapabilities
|
|
30807
|
+
} else if (!value.clientCapabilities.every(isNonEmptyString2)) {
|
|
30808
|
+
issues.push("clientCapabilities must contain non-empty strings");
|
|
30495
30809
|
}
|
|
30496
30810
|
}
|
|
30497
30811
|
if (value.executionScope !== void 0 && value.executionScope !== "presentation") {
|
|
@@ -32499,8 +32813,8 @@ var Protocol = class {
|
|
|
32499
32813
|
if (queuedMessage.type === "response") {
|
|
32500
32814
|
resolver(message);
|
|
32501
32815
|
} else {
|
|
32502
|
-
const
|
|
32503
|
-
const error = new McpError(
|
|
32816
|
+
const errorMessage2 = message;
|
|
32817
|
+
const error = new McpError(errorMessage2.error.code, errorMessage2.error.message, errorMessage2.error.data);
|
|
32504
32818
|
resolver(error);
|
|
32505
32819
|
}
|
|
32506
32820
|
} else {
|
|
@@ -33786,8 +34100,8 @@ var Client = class extends Protocol {
|
|
|
33786
34100
|
const wrappedHandler = async (request, extra) => {
|
|
33787
34101
|
const validatedRequest = safeParse2(ElicitRequestSchema, request);
|
|
33788
34102
|
if (!validatedRequest.success) {
|
|
33789
|
-
const
|
|
33790
|
-
throw new McpError(ErrorCode.InvalidParams, `Invalid elicitation request: ${
|
|
34103
|
+
const errorMessage2 = validatedRequest.error instanceof Error ? validatedRequest.error.message : String(validatedRequest.error);
|
|
34104
|
+
throw new McpError(ErrorCode.InvalidParams, `Invalid elicitation request: ${errorMessage2}`);
|
|
33791
34105
|
}
|
|
33792
34106
|
const { params } = validatedRequest.data;
|
|
33793
34107
|
params.mode = params.mode ?? "form";
|
|
@@ -33802,15 +34116,15 @@ var Client = class extends Protocol {
|
|
|
33802
34116
|
if (params.task) {
|
|
33803
34117
|
const taskValidationResult = safeParse2(CreateTaskResultSchema, result);
|
|
33804
34118
|
if (!taskValidationResult.success) {
|
|
33805
|
-
const
|
|
33806
|
-
throw new McpError(ErrorCode.InvalidParams, `Invalid task creation result: ${
|
|
34119
|
+
const errorMessage2 = taskValidationResult.error instanceof Error ? taskValidationResult.error.message : String(taskValidationResult.error);
|
|
34120
|
+
throw new McpError(ErrorCode.InvalidParams, `Invalid task creation result: ${errorMessage2}`);
|
|
33807
34121
|
}
|
|
33808
34122
|
return taskValidationResult.data;
|
|
33809
34123
|
}
|
|
33810
34124
|
const validationResult = safeParse2(ElicitResultSchema, result);
|
|
33811
34125
|
if (!validationResult.success) {
|
|
33812
|
-
const
|
|
33813
|
-
throw new McpError(ErrorCode.InvalidParams, `Invalid elicitation result: ${
|
|
34126
|
+
const errorMessage2 = validationResult.error instanceof Error ? validationResult.error.message : String(validationResult.error);
|
|
34127
|
+
throw new McpError(ErrorCode.InvalidParams, `Invalid elicitation result: ${errorMessage2}`);
|
|
33814
34128
|
}
|
|
33815
34129
|
const validatedResult = validationResult.data;
|
|
33816
34130
|
const requestedSchema = params.mode === "form" ? params.requestedSchema : void 0;
|
|
@@ -33830,16 +34144,16 @@ var Client = class extends Protocol {
|
|
|
33830
34144
|
const wrappedHandler = async (request, extra) => {
|
|
33831
34145
|
const validatedRequest = safeParse2(CreateMessageRequestSchema, request);
|
|
33832
34146
|
if (!validatedRequest.success) {
|
|
33833
|
-
const
|
|
33834
|
-
throw new McpError(ErrorCode.InvalidParams, `Invalid sampling request: ${
|
|
34147
|
+
const errorMessage2 = validatedRequest.error instanceof Error ? validatedRequest.error.message : String(validatedRequest.error);
|
|
34148
|
+
throw new McpError(ErrorCode.InvalidParams, `Invalid sampling request: ${errorMessage2}`);
|
|
33835
34149
|
}
|
|
33836
34150
|
const { params } = validatedRequest.data;
|
|
33837
34151
|
const result = await Promise.resolve(handler(request, extra));
|
|
33838
34152
|
if (params.task) {
|
|
33839
34153
|
const taskValidationResult = safeParse2(CreateTaskResultSchema, result);
|
|
33840
34154
|
if (!taskValidationResult.success) {
|
|
33841
|
-
const
|
|
33842
|
-
throw new McpError(ErrorCode.InvalidParams, `Invalid task creation result: ${
|
|
34155
|
+
const errorMessage2 = taskValidationResult.error instanceof Error ? taskValidationResult.error.message : String(taskValidationResult.error);
|
|
34156
|
+
throw new McpError(ErrorCode.InvalidParams, `Invalid task creation result: ${errorMessage2}`);
|
|
33843
34157
|
}
|
|
33844
34158
|
return taskValidationResult.data;
|
|
33845
34159
|
}
|
|
@@ -33847,8 +34161,8 @@ var Client = class extends Protocol {
|
|
|
33847
34161
|
const resultSchema = hasTools ? CreateMessageResultWithToolsSchema : CreateMessageResultSchema;
|
|
33848
34162
|
const validationResult = safeParse2(resultSchema, result);
|
|
33849
34163
|
if (!validationResult.success) {
|
|
33850
|
-
const
|
|
33851
|
-
throw new McpError(ErrorCode.InvalidParams, `Invalid sampling result: ${
|
|
34164
|
+
const errorMessage2 = validationResult.error instanceof Error ? validationResult.error.message : String(validationResult.error);
|
|
34165
|
+
throw new McpError(ErrorCode.InvalidParams, `Invalid sampling result: ${errorMessage2}`);
|
|
33852
34166
|
}
|
|
33853
34167
|
return validationResult.data;
|
|
33854
34168
|
};
|
|
@@ -34198,7 +34512,7 @@ async function connectMcpClientWithRetry(config, factories, signal) {
|
|
|
34198
34512
|
let closing;
|
|
34199
34513
|
const close = () => closing ??= safeClose(transport, client);
|
|
34200
34514
|
try {
|
|
34201
|
-
const connecting = client.connect(transport).then(() => {
|
|
34515
|
+
const connecting = (factories.runConnect ? factories.runConnect(() => client.connect(transport), attempt) : client.connect(transport)).then(() => {
|
|
34202
34516
|
if (signal?.aborted) {
|
|
34203
34517
|
void close();
|
|
34204
34518
|
signal.throwIfAborted();
|
|
@@ -34236,8 +34550,49 @@ async function safeClose(transport, client) {
|
|
|
34236
34550
|
}
|
|
34237
34551
|
}
|
|
34238
34552
|
|
|
34553
|
+
// ../linkque-agent-runtime/dist/esm/impl/httpTelemetry.js
|
|
34554
|
+
function httpTelemetryAttributes(url2, method) {
|
|
34555
|
+
try {
|
|
34556
|
+
const target = new URL(url2);
|
|
34557
|
+
return {
|
|
34558
|
+
[ETelemetryAttribute.HTTP_REQUEST_METHOD]: method.toUpperCase(),
|
|
34559
|
+
[ETelemetryAttribute.SERVER_ADDRESS]: target.hostname,
|
|
34560
|
+
[ETelemetryAttribute.URL_PATH]: target.pathname
|
|
34561
|
+
};
|
|
34562
|
+
} catch {
|
|
34563
|
+
return {};
|
|
34564
|
+
}
|
|
34565
|
+
}
|
|
34566
|
+
function recordHttpResponse(observation, response) {
|
|
34567
|
+
try {
|
|
34568
|
+
const correlation = readResponseCorrelationId(response.headers);
|
|
34569
|
+
observation.add({
|
|
34570
|
+
[ETelemetryAttribute.HTTP_RESPONSE_STATUS_CODE]: response.status,
|
|
34571
|
+
...correlation ? {
|
|
34572
|
+
[ETelemetryAttribute.LINKQUE_REMOTE_TRACE_ID]: correlation.value,
|
|
34573
|
+
[ETelemetryAttribute.LINKQUE_REMOTE_TRACE_ID_HEADER]: correlation.name
|
|
34574
|
+
} : {}
|
|
34575
|
+
});
|
|
34576
|
+
} catch {
|
|
34577
|
+
}
|
|
34578
|
+
}
|
|
34579
|
+
|
|
34239
34580
|
// ../linkque-agent-runtime/dist/esm/impl/mcp/alipay/mcpInvocationContext.js
|
|
34240
34581
|
import { AsyncLocalStorage } from "node:async_hooks";
|
|
34582
|
+
function observeMcpRequest(create) {
|
|
34583
|
+
let operation;
|
|
34584
|
+
let resolve;
|
|
34585
|
+
let reject;
|
|
34586
|
+
const completion = observeIo(create, (current) => {
|
|
34587
|
+
operation = current;
|
|
34588
|
+
return new Promise((accept, fail) => {
|
|
34589
|
+
resolve = accept;
|
|
34590
|
+
reject = fail;
|
|
34591
|
+
});
|
|
34592
|
+
}, (outcome) => outcome);
|
|
34593
|
+
const completed = completion.catch(() => void 0);
|
|
34594
|
+
return { operation, resolve, reject, completed };
|
|
34595
|
+
}
|
|
34241
34596
|
async function waitForMcpOperation(operation, signal) {
|
|
34242
34597
|
return waitWithSignal(operation, signal);
|
|
34243
34598
|
}
|
|
@@ -34246,7 +34601,7 @@ var McpInvocationContext = class {
|
|
|
34246
34601
|
current() {
|
|
34247
34602
|
return this.storage.getStore();
|
|
34248
34603
|
}
|
|
34249
|
-
async run(timeoutMs, signal, operation) {
|
|
34604
|
+
async run(timeoutMs, signal, operation, telemetry = {}) {
|
|
34250
34605
|
if (!Number.isFinite(timeoutMs) || timeoutMs <= 0)
|
|
34251
34606
|
throw new Error("MCP \u8D85\u65F6\u5FC5\u987B\u4E3A\u6709\u9650\u6B63\u6570");
|
|
34252
34607
|
signal?.throwIfAborted();
|
|
@@ -34256,19 +34611,42 @@ var McpInvocationContext = class {
|
|
|
34256
34611
|
timeoutReason: new DOMException("MCP \u8C03\u7528\u603B\u9884\u7B97\u5DF2\u8017\u5C3D", "TimeoutError")
|
|
34257
34612
|
});
|
|
34258
34613
|
const context2 = {
|
|
34614
|
+
...telemetry,
|
|
34615
|
+
active: true,
|
|
34616
|
+
requests: /* @__PURE__ */ new Set(),
|
|
34259
34617
|
signal: scope.context.signal,
|
|
34260
34618
|
deadline: scope.context.deadline
|
|
34261
34619
|
};
|
|
34262
34620
|
try {
|
|
34263
|
-
|
|
34621
|
+
const result = await this.storage.run(context2, () => waitWithSignal(() => operation(context2), context2.signal));
|
|
34622
|
+
const failed = result && typeof result === "object" && "isError" in result && result.isError === true;
|
|
34623
|
+
for (const request of context2.requests)
|
|
34624
|
+
request.resolve(failed ? ETelemetryOutcome.ERROR : ETelemetryOutcome.SUCCESS);
|
|
34625
|
+
return result;
|
|
34264
34626
|
} catch (error) {
|
|
34627
|
+
const observationError = classifyMcpObservationError(error);
|
|
34628
|
+
for (const request of context2.requests)
|
|
34629
|
+
request.reject(observationError);
|
|
34265
34630
|
scope.context.throwIfAborted();
|
|
34266
34631
|
throw error;
|
|
34267
34632
|
} finally {
|
|
34633
|
+
context2.active = false;
|
|
34634
|
+
await Promise.all([...context2.requests].map((request) => request.completed));
|
|
34635
|
+
context2.observation = void 0;
|
|
34636
|
+
context2.requests.clear();
|
|
34268
34637
|
scope.dispose();
|
|
34269
34638
|
}
|
|
34270
34639
|
}
|
|
34271
34640
|
};
|
|
34641
|
+
function classifyMcpObservationError(error) {
|
|
34642
|
+
try {
|
|
34643
|
+
const cause = error instanceof Error ? error.cause : void 0;
|
|
34644
|
+
if ([error, cause].some((value) => value instanceof McpError && value.code === ErrorCode.RequestTimeout))
|
|
34645
|
+
return new DOMException("MCP SDK \u8BF7\u6C42\u7B49\u5F85\u8D85\u65F6", "TimeoutError");
|
|
34646
|
+
} catch {
|
|
34647
|
+
}
|
|
34648
|
+
return error;
|
|
34649
|
+
}
|
|
34272
34650
|
|
|
34273
34651
|
// ../linkque-agent-runtime/dist/esm/impl/mcp/alipay/remoteSignatureSigner.js
|
|
34274
34652
|
var DEFAULT_SIGN_ENDPOINT = RUNTIME_CONFIG_DEFAULTS.LINKQUEGW_MCP_SIGN_ENDPOINT;
|
|
@@ -34311,25 +34689,28 @@ var RemoteSignatureSigner = class {
|
|
|
34311
34689
|
headers.authorization = options.signal ? await waitForMcpOperation(() => this.getAuthorizationHeader(), options.signal) : await this.getAuthorizationHeader();
|
|
34312
34690
|
}
|
|
34313
34691
|
options.signal?.throwIfAborted();
|
|
34314
|
-
|
|
34315
|
-
|
|
34316
|
-
|
|
34317
|
-
|
|
34318
|
-
|
|
34319
|
-
|
|
34320
|
-
|
|
34321
|
-
|
|
34322
|
-
|
|
34323
|
-
|
|
34324
|
-
|
|
34325
|
-
|
|
34326
|
-
|
|
34327
|
-
|
|
34328
|
-
|
|
34329
|
-
|
|
34330
|
-
|
|
34331
|
-
|
|
34332
|
-
|
|
34692
|
+
return observeIo(() => new IoObservation(options.observation, ETelemetryOperationName.MCP_SIGN, httpTelemetryAttributes(this.signEndpoint, "POST"), options.signal), async (operation) => {
|
|
34693
|
+
const resp = await (options.sensitive ? this.rawFetch : this.fetchImpl)(this.signEndpoint, { method: "POST", headers, body, signal: options.signal });
|
|
34694
|
+
recordHttpResponse(operation, resp);
|
|
34695
|
+
options.signal?.throwIfAborted();
|
|
34696
|
+
if (!resp.ok) {
|
|
34697
|
+
const text = options.sensitive ? "" : await safeText(resp);
|
|
34698
|
+
throw new Error(`linkquegw \u7B7E\u540D\u670D\u52A1\u5931\u8D25: status=${resp.status}${text ? ` body=${text}` : ""}`);
|
|
34699
|
+
}
|
|
34700
|
+
const parsed = await resp.json().catch(() => ({}));
|
|
34701
|
+
const payload = isWrappedSignResponse(parsed) ? extractFromWrapped(parsed) : parsed;
|
|
34702
|
+
if (typeof payload.authorization !== "string" || !payload.authorization) {
|
|
34703
|
+
throw new Error("linkquegw \u7B7E\u540D\u670D\u52A1\u54CD\u5E94\u7F3A\u5C11 authorization");
|
|
34704
|
+
}
|
|
34705
|
+
if (typeof payload.signatureContent !== "string") {
|
|
34706
|
+
throw new Error("linkquegw \u7B7E\u540D\u670D\u52A1\u54CD\u5E94\u7F3A\u5C11 signatureContent");
|
|
34707
|
+
}
|
|
34708
|
+
return {
|
|
34709
|
+
authorization: payload.authorization,
|
|
34710
|
+
signatureContent: payload.signatureContent,
|
|
34711
|
+
...optionalUserId(payload.userId)
|
|
34712
|
+
};
|
|
34713
|
+
});
|
|
34333
34714
|
}
|
|
34334
34715
|
};
|
|
34335
34716
|
function isWrappedSignResponse(v) {
|
|
@@ -35238,8 +35619,8 @@ async function parseErrorResponse(input) {
|
|
|
35238
35619
|
const errorClass = OAUTH_ERRORS[error] || ServerError;
|
|
35239
35620
|
return new errorClass(error_description || "", error_uri);
|
|
35240
35621
|
} catch (error) {
|
|
35241
|
-
const
|
|
35242
|
-
return new ServerError(
|
|
35622
|
+
const errorMessage2 = `${statusCode ? `HTTP ${statusCode}: ` : ""}Invalid OAuth error response: ${error}. Raw body: ${body}`;
|
|
35623
|
+
return new ServerError(errorMessage2);
|
|
35243
35624
|
}
|
|
35244
35625
|
}
|
|
35245
35626
|
async function auth(provider, options) {
|
|
@@ -35926,6 +36307,7 @@ function createSigningFetch(signer, baseFetch = globalThis.fetch, onTraceId, deb
|
|
|
35926
36307
|
httpRequestBody: typeof init?.body === "string" ? init.body : ""
|
|
35927
36308
|
};
|
|
35928
36309
|
const { authorization, signatureContent, userId } = await signer.sign(req, {
|
|
36310
|
+
observation: invocation?.observation,
|
|
35929
36311
|
authorizationHeader: invocation?.auth?.authorization,
|
|
35930
36312
|
signal,
|
|
35931
36313
|
sensitive: !!invocation?.auth
|
|
@@ -35950,25 +36332,67 @@ function createSigningFetch(signer, baseFetch = globalThis.fetch, onTraceId, deb
|
|
|
35950
36332
|
else
|
|
35951
36333
|
headers.delete("x-alipay-authcode");
|
|
35952
36334
|
}
|
|
35953
|
-
|
|
35954
|
-
|
|
35955
|
-
|
|
35956
|
-
|
|
35957
|
-
|
|
35958
|
-
|
|
35959
|
-
|
|
35960
|
-
|
|
35961
|
-
|
|
35962
|
-
|
|
35963
|
-
|
|
35964
|
-
|
|
35965
|
-
|
|
35966
|
-
|
|
36335
|
+
let rpcMethod;
|
|
36336
|
+
try {
|
|
36337
|
+
const parsed = JSON.parse(req.httpRequestBody);
|
|
36338
|
+
if (typeof parsed.method === "string" && [
|
|
36339
|
+
ETelemetryMcpPhase.INITIALIZE,
|
|
36340
|
+
ETelemetryMcpPhase.TOOLS_LIST,
|
|
36341
|
+
ETelemetryMcpPhase.TOOLS_CALL,
|
|
36342
|
+
ETelemetryMcpPhase.INITIALIZED,
|
|
36343
|
+
ETelemetryMcpPhase.CANCELLED
|
|
36344
|
+
].some((phase) => phase === parsed.method))
|
|
36345
|
+
rpcMethod = parsed.method;
|
|
36346
|
+
} catch {
|
|
36347
|
+
}
|
|
36348
|
+
const requestObservation = observeMcpRequest(() => new IoObservation(invocation?.observation, ETelemetryOperationName.MCP_OPENGW, {
|
|
36349
|
+
...httpTelemetryAttributes(targetUrl, req.httpMethod),
|
|
36350
|
+
[ETelemetryAttribute.LINKQUE_MCP_PHASE]: rpcMethod ?? (req.httpMethod.toUpperCase() === "GET" ? ETelemetryMcpPhase.SSE_CONNECT : ETelemetryMcpPhase.HTTP),
|
|
36351
|
+
...invocation?.serverName ? {
|
|
36352
|
+
[ETelemetryAttribute.LINKQUE_MCP_SERVER_NAME]: invocation.serverName
|
|
36353
|
+
} : {},
|
|
36354
|
+
...invocation?.attempt ? { [ETelemetryAttribute.LINKQUE_IO_ATTEMPT]: invocation.attempt } : {}
|
|
36355
|
+
}, signal));
|
|
36356
|
+
const operation = requestObservation.operation;
|
|
36357
|
+
const waitForResult = !!invocation?.active && !!rpcMethod && [
|
|
36358
|
+
ETelemetryMcpPhase.INITIALIZE,
|
|
36359
|
+
ETelemetryMcpPhase.TOOLS_LIST,
|
|
36360
|
+
ETelemetryMcpPhase.TOOLS_CALL
|
|
36361
|
+
].includes(rpcMethod);
|
|
36362
|
+
if (waitForResult)
|
|
36363
|
+
invocation.requests.add(requestObservation);
|
|
36364
|
+
try {
|
|
36365
|
+
const resp = await (invocation?.auth ? baseFetch : loggedFetch)(url2, {
|
|
36366
|
+
...init,
|
|
36367
|
+
headers,
|
|
36368
|
+
...signal ? { signal } : {}
|
|
36369
|
+
});
|
|
36370
|
+
recordHttpResponse(operation, resp);
|
|
36371
|
+
if (!resp.ok)
|
|
36372
|
+
requestObservation.resolve(ETelemetryOutcome.ERROR);
|
|
36373
|
+
else if (!waitForResult)
|
|
36374
|
+
requestObservation.resolve(ETelemetryOutcome.SUCCESS);
|
|
36375
|
+
if (onTraceId) {
|
|
36376
|
+
try {
|
|
36377
|
+
const traceId = resp.headers.get("alipay-trace-id");
|
|
36378
|
+
if (traceId) {
|
|
36379
|
+
onTraceId({
|
|
36380
|
+
traceId,
|
|
36381
|
+
httpMethod: req.httpMethod,
|
|
36382
|
+
requestUrl: req.httpRequestUrl
|
|
36383
|
+
});
|
|
36384
|
+
}
|
|
36385
|
+
} catch {
|
|
35967
36386
|
}
|
|
35968
|
-
} catch {
|
|
35969
36387
|
}
|
|
36388
|
+
return resp;
|
|
36389
|
+
} catch (error) {
|
|
36390
|
+
requestObservation.reject(error);
|
|
36391
|
+
throw error;
|
|
36392
|
+
} finally {
|
|
36393
|
+
if (!waitForResult)
|
|
36394
|
+
await requestObservation.completed;
|
|
35970
36395
|
}
|
|
35971
|
-
return resp;
|
|
35972
36396
|
};
|
|
35973
36397
|
}
|
|
35974
36398
|
|
|
@@ -36156,26 +36580,30 @@ var LinkquegwTokenVerifier = class {
|
|
|
36156
36580
|
async verify(input) {
|
|
36157
36581
|
input.signal?.throwIfAborted();
|
|
36158
36582
|
assertMcpUserAuthorization(input.authorization);
|
|
36583
|
+
const endpoint = this.options.endpoint ?? RUNTIME_CONFIG_DEFAULTS.LINKQUEGW_TOKEN_VERIFY_ENDPOINT;
|
|
36159
36584
|
try {
|
|
36160
|
-
|
|
36161
|
-
|
|
36162
|
-
|
|
36163
|
-
|
|
36164
|
-
|
|
36165
|
-
|
|
36166
|
-
|
|
36167
|
-
|
|
36585
|
+
return await observeIo(() => new IoObservation(input.observation, ETelemetryOperationName.MCP_VERIFY, httpTelemetryAttributes(endpoint, "POST"), input.signal), async (operation) => {
|
|
36586
|
+
const response = await (this.options.fetchImpl ?? globalThis.fetch)(this.options.endpoint ?? RUNTIME_CONFIG_DEFAULTS.LINKQUEGW_TOKEN_VERIFY_ENDPOINT, {
|
|
36587
|
+
method: "POST",
|
|
36588
|
+
headers: {
|
|
36589
|
+
authorization: input.authorization,
|
|
36590
|
+
"content-type": "application/json"
|
|
36591
|
+
},
|
|
36592
|
+
body: JSON.stringify({ agentId: input.agentId }),
|
|
36593
|
+
signal: input.signal
|
|
36594
|
+
});
|
|
36595
|
+
recordHttpResponse(operation, response);
|
|
36596
|
+
if (!response.ok)
|
|
36597
|
+
throw new Error("\u6821\u9A8C\u8BF7\u6C42\u5931\u8D25");
|
|
36598
|
+
const result = await response.json();
|
|
36599
|
+
input.signal?.throwIfAborted();
|
|
36600
|
+
if (result?.success !== true || typeof result.data?.userId !== "string" || !result.data.userId.trim() || typeof result.data.agentId !== "string" || !result.data.agentId.trim()) {
|
|
36601
|
+
throw new Error("\u8EAB\u4EFD\u54CD\u5E94\u65E0\u6548");
|
|
36602
|
+
}
|
|
36603
|
+
if (result.data.agentId !== input.agentId)
|
|
36604
|
+
throw new McpInvocationError("MCP_IDENTITY_MISMATCH", "\u7528\u6237\u51ED\u636E\u4E0D\u5C5E\u4E8E\u76EE\u6807 Agent");
|
|
36605
|
+
return { userId: result.data.userId, agentId: result.data.agentId };
|
|
36168
36606
|
});
|
|
36169
|
-
if (!response.ok)
|
|
36170
|
-
throw new Error("\u6821\u9A8C\u8BF7\u6C42\u5931\u8D25");
|
|
36171
|
-
const result = await response.json();
|
|
36172
|
-
input.signal?.throwIfAborted();
|
|
36173
|
-
if (result?.success !== true || typeof result.data?.userId !== "string" || !result.data.userId.trim() || typeof result.data.agentId !== "string" || !result.data.agentId.trim()) {
|
|
36174
|
-
throw new Error("\u8EAB\u4EFD\u54CD\u5E94\u65E0\u6548");
|
|
36175
|
-
}
|
|
36176
|
-
if (result.data.agentId !== input.agentId)
|
|
36177
|
-
throw new McpInvocationError("MCP_IDENTITY_MISMATCH", "\u7528\u6237\u51ED\u636E\u4E0D\u5C5E\u4E8E\u76EE\u6807 Agent");
|
|
36178
|
-
return { userId: result.data.userId, agentId: result.data.agentId };
|
|
36179
36607
|
} catch (error) {
|
|
36180
36608
|
input.signal?.throwIfAborted();
|
|
36181
36609
|
if (error instanceof McpInvocationError)
|
|
@@ -36190,8 +36618,7 @@ var defaultCreateSigner = (config, getAuthorizationHeader, debugLog) => new Remo
|
|
|
36190
36618
|
agentId: config.agentId,
|
|
36191
36619
|
signEndpoint: config.signEndpoint,
|
|
36192
36620
|
getAuthorizationHeader,
|
|
36193
|
-
|
|
36194
|
-
...debugLog ? { debugLog } : {}
|
|
36621
|
+
debugLog
|
|
36195
36622
|
});
|
|
36196
36623
|
var defaultCreateClient = () => new Client({ name: "linkque-agent-runtime-mcp-client", version: "1.0.0" });
|
|
36197
36624
|
var RemoteGatewayMcpServerProvider = class {
|
|
@@ -36205,28 +36632,52 @@ var RemoteGatewayMcpServerProvider = class {
|
|
|
36205
36632
|
debugLog;
|
|
36206
36633
|
constructor(options) {
|
|
36207
36634
|
this.resolveConfig = options.resolveConfig;
|
|
36208
|
-
this.createTokenVerifier = options.createTokenVerifier
|
|
36635
|
+
this.createTokenVerifier = options.createTokenVerifier;
|
|
36209
36636
|
this.getAuthorizationHeader = options.getAuthorizationHeader;
|
|
36210
|
-
this.createSigner = options.createSigner
|
|
36211
|
-
this.createClient = options.createClient
|
|
36637
|
+
this.createSigner = options.createSigner;
|
|
36638
|
+
this.createClient = options.createClient;
|
|
36212
36639
|
this.onTraceId = options.onTraceId;
|
|
36213
36640
|
this.debugLog = options.debugLog;
|
|
36214
36641
|
}
|
|
36215
|
-
|
|
36216
|
-
|
|
36642
|
+
doCreateTokenVerifier(config) {
|
|
36643
|
+
if (this.createTokenVerifier) {
|
|
36644
|
+
return this.createTokenVerifier(config);
|
|
36645
|
+
}
|
|
36646
|
+
return new LinkquegwTokenVerifier({ endpoint: config.verifyTokenEndpoint });
|
|
36647
|
+
}
|
|
36648
|
+
doCreateSigner(config, getAuthorizationHeader) {
|
|
36649
|
+
if (this.createSigner) {
|
|
36650
|
+
return this.createSigner(config, getAuthorizationHeader);
|
|
36651
|
+
}
|
|
36652
|
+
return defaultCreateSigner(config, getAuthorizationHeader, this.debugLog);
|
|
36653
|
+
}
|
|
36654
|
+
doCrateClient() {
|
|
36655
|
+
if (this.createClient) {
|
|
36656
|
+
return this.createClient();
|
|
36657
|
+
}
|
|
36658
|
+
return defaultCreateClient();
|
|
36659
|
+
}
|
|
36660
|
+
async servers(resources, signal, observation) {
|
|
36661
|
+
return Promise.all(resources.map((r) => this.connectOne(r, signal, observation)));
|
|
36217
36662
|
}
|
|
36218
36663
|
/** 连单个远端 server 并包装成 IMcpServer。建连失败有限重试 + 失败清理由 helper 负责。 */
|
|
36219
|
-
async connectOne(resource, connectSignal) {
|
|
36664
|
+
async connectOne(resource, connectSignal, observation) {
|
|
36220
36665
|
const config = await this.resolveConfig(resource);
|
|
36221
36666
|
connectSignal?.throwIfAborted();
|
|
36222
36667
|
const timeoutMs = config.requestTimeoutMs ?? 18e4;
|
|
36223
|
-
if (!Number.isFinite(timeoutMs) || timeoutMs <= 0)
|
|
36668
|
+
if (!Number.isFinite(timeoutMs) || timeoutMs <= 0) {
|
|
36224
36669
|
throw new Error("MCP \u8D85\u65F6\u5FC5\u987B\u4E3A\u6709\u9650\u6B63\u6570");
|
|
36225
|
-
|
|
36670
|
+
}
|
|
36671
|
+
const verifier = this.doCreateTokenVerifier(config);
|
|
36226
36672
|
const callHeaders = new AsyncLocalStorage2();
|
|
36227
36673
|
const { client } = await connectMcpClientWithRetry(config, {
|
|
36228
|
-
createTransport: () => createSseTransport(config, this.
|
|
36229
|
-
createClient: () => this.
|
|
36674
|
+
createTransport: () => createSseTransport(config, this.doCreateSigner(config, this.getAuthorizationHeader), this.onTraceId, this.debugLog, () => callHeaders.getStore(), this.invocationContext),
|
|
36675
|
+
createClient: () => this.doCrateClient(),
|
|
36676
|
+
runConnect: (operation, attempt) => this.invocationContext.run(timeoutMs, connectSignal, operation, {
|
|
36677
|
+
observation,
|
|
36678
|
+
attempt,
|
|
36679
|
+
serverName: resource.config.serverName ?? resource.resourceId
|
|
36680
|
+
})
|
|
36230
36681
|
}, connectSignal);
|
|
36231
36682
|
const serverName = resource.config.serverName ?? resource.resourceId;
|
|
36232
36683
|
const argsMappingRules = resource.config.argsMappingRules ?? [];
|
|
@@ -36264,8 +36715,8 @@ var RemoteGatewayMcpServerProvider = class {
|
|
|
36264
36715
|
callTool: (params, resultSchema, requestOptions) => request("tools/call", params, () => client.callTool(params, resultSchema, requestOptions))
|
|
36265
36716
|
};
|
|
36266
36717
|
const callTool = (name, args, signal, options) => callHeaders.run(options?.headers ?? {}, () => this.invocationContext.run(timeoutMs, signal, async (invocation) => {
|
|
36267
|
-
const
|
|
36268
|
-
recordMcpContentSection(
|
|
36718
|
+
const innerObservation = options?.context?.observation;
|
|
36719
|
+
recordMcpContentSection(innerObservation, ETelemetryContentSection.MCP_REQUESTED_INPUT, args, options?.toolSchema?.inputSchema);
|
|
36269
36720
|
const plan = createArgsMappingPlan(name, args, argsMappingRules);
|
|
36270
36721
|
if (plan.requiresUserId) {
|
|
36271
36722
|
if (config.signEndpoint !== void 0 && config.signEndpoint !== DEFAULT_SIGN_ENDPOINT && !config.verifyTokenEndpoint?.trim())
|
|
@@ -36275,6 +36726,7 @@ var RemoteGatewayMcpServerProvider = class {
|
|
|
36275
36726
|
const authorization = await waitForMcpOperation(() => this.getAuthorizationHeader(), invocation.signal);
|
|
36276
36727
|
assertMcpUserAuthorization(authorization);
|
|
36277
36728
|
const identity = await waitForMcpOperation(() => verifier.verify({
|
|
36729
|
+
observation: innerObservation,
|
|
36278
36730
|
authorization,
|
|
36279
36731
|
agentId: config.agentId,
|
|
36280
36732
|
signal: invocation.signal
|
|
@@ -36288,7 +36740,7 @@ var RemoteGatewayMcpServerProvider = class {
|
|
|
36288
36740
|
};
|
|
36289
36741
|
}
|
|
36290
36742
|
const mapped = resolveArgsMappingPlan(plan, invocation.auth);
|
|
36291
|
-
recordMcpContentSection(
|
|
36743
|
+
recordMcpContentSection(innerObservation, ETelemetryContentSection.MCP_INPUT, mapped, options?.toolSchema?.inputSchema);
|
|
36292
36744
|
invocation.signal.throwIfAborted();
|
|
36293
36745
|
const remaining = Math.max(1, invocation.deadline - performance.now());
|
|
36294
36746
|
try {
|
|
@@ -36298,7 +36750,7 @@ var RemoteGatewayMcpServerProvider = class {
|
|
|
36298
36750
|
maxTotalTimeout: remaining,
|
|
36299
36751
|
resetTimeoutOnProgress: false
|
|
36300
36752
|
});
|
|
36301
|
-
recordMcpContentSection(
|
|
36753
|
+
recordMcpContentSection(innerObservation, ETelemetryContentSection.MCP_OUTPUT, result, options?.toolSchema?.outputSchema);
|
|
36302
36754
|
return result;
|
|
36303
36755
|
} catch (error) {
|
|
36304
36756
|
invocation.signal.throwIfAborted();
|
|
@@ -36306,11 +36758,11 @@ var RemoteGatewayMcpServerProvider = class {
|
|
|
36306
36758
|
throw new Error("MCP \u7528\u6237\u5DE5\u5177\u8C03\u7528\u5931\u8D25", { cause: error });
|
|
36307
36759
|
throw error;
|
|
36308
36760
|
}
|
|
36309
|
-
}));
|
|
36761
|
+
}, { observation: options?.context?.observation, serverName }));
|
|
36310
36762
|
return {
|
|
36311
36763
|
resourceId: resource.resourceId,
|
|
36312
36764
|
serverName,
|
|
36313
|
-
listTools: (signal) => listToolsFromClient(loggedClient, resource.resourceId, callTool, signal),
|
|
36765
|
+
listTools: (signal, parent) => this.invocationContext.run(timeoutMs, signal, (invocation) => listToolsFromClient(loggedClient, resource.resourceId, callTool, invocation.signal), { observation: parent, serverName }),
|
|
36314
36766
|
callTool,
|
|
36315
36767
|
close: async () => {
|
|
36316
36768
|
try {
|
|
@@ -36379,7 +36831,7 @@ var LinkqueKnowledgeSearchPort = class {
|
|
|
36379
36831
|
resourceId: resource.resourceId
|
|
36380
36832
|
}));
|
|
36381
36833
|
}
|
|
36382
|
-
async search(input, signal) {
|
|
36834
|
+
async search(input, signal, observation) {
|
|
36383
36835
|
const url2 = `${this.baseUrl}${KNOWLEDGE_SEARCH_PATH}`;
|
|
36384
36836
|
const body = JSON.stringify({
|
|
36385
36837
|
query: input.query,
|
|
@@ -36396,34 +36848,36 @@ var LinkqueKnowledgeSearchPort = class {
|
|
|
36396
36848
|
signals: signal ? [signal] : [],
|
|
36397
36849
|
timeoutMs: this.timeoutMs
|
|
36398
36850
|
});
|
|
36399
|
-
let resp;
|
|
36400
36851
|
try {
|
|
36401
|
-
|
|
36402
|
-
|
|
36403
|
-
|
|
36404
|
-
|
|
36405
|
-
|
|
36852
|
+
return await observeIo(() => new IoObservation(observation, ETelemetryOperationName.KNOWLEDGE_SEARCH, httpTelemetryAttributes(url2, "POST"), scope.context.signal), async (operation) => {
|
|
36853
|
+
const resp = await this.fetchImpl(url2, {
|
|
36854
|
+
method: "POST",
|
|
36855
|
+
headers,
|
|
36856
|
+
body,
|
|
36857
|
+
signal: scope.context.signal
|
|
36858
|
+
});
|
|
36859
|
+
recordHttpResponse(operation, resp);
|
|
36860
|
+
if (!resp.ok) {
|
|
36861
|
+
const text = await safeText2(resp);
|
|
36862
|
+
throw new Error(`linkquegw \u77E5\u8BC6\u5E93\u68C0\u7D22\u5931\u8D25: status=${resp.status}${text ? ` body=${text}` : ""}`);
|
|
36863
|
+
}
|
|
36864
|
+
const parsed = await resp.json().catch(() => ({}));
|
|
36865
|
+
if (typeof parsed.success === "boolean") {
|
|
36866
|
+
if (!parsed.success) {
|
|
36867
|
+
const code = parsed.errorCode ?? "UNKNOWN";
|
|
36868
|
+
const msg = parsed.errorMessage ?? "linkquegw \u77E5\u8BC6\u5E93\u68C0\u7D22\u8FD4\u56DE\u5931\u8D25";
|
|
36869
|
+
throw new Error(`linkquegw \u77E5\u8BC6\u5E93\u68C0\u7D22\u5931\u8D25: ${code} ${msg}`);
|
|
36870
|
+
}
|
|
36871
|
+
return { hits: normalizeHits(parsed.data?.hits) };
|
|
36872
|
+
}
|
|
36873
|
+
if (parsed.hits !== void 0) {
|
|
36874
|
+
return { hits: normalizeHits(parsed.hits) };
|
|
36875
|
+
}
|
|
36876
|
+
throw new Error("linkquegw \u77E5\u8BC6\u5E93\u68C0\u7D22\u54CD\u5E94\u7F3A\u5C11 success/hits");
|
|
36406
36877
|
});
|
|
36407
36878
|
} finally {
|
|
36408
36879
|
scope.dispose();
|
|
36409
36880
|
}
|
|
36410
|
-
if (!resp.ok) {
|
|
36411
|
-
const text = await safeText2(resp);
|
|
36412
|
-
throw new Error(`linkquegw \u77E5\u8BC6\u5E93\u68C0\u7D22\u5931\u8D25: status=${resp.status}${text ? ` body=${text}` : ""}`);
|
|
36413
|
-
}
|
|
36414
|
-
const parsed = await resp.json().catch(() => ({}));
|
|
36415
|
-
if (typeof parsed.success === "boolean") {
|
|
36416
|
-
if (!parsed.success) {
|
|
36417
|
-
const code = parsed.errorCode ?? "UNKNOWN";
|
|
36418
|
-
const msg = parsed.errorMessage ?? "linkquegw \u77E5\u8BC6\u5E93\u68C0\u7D22\u8FD4\u56DE\u5931\u8D25";
|
|
36419
|
-
throw new Error(`linkquegw \u77E5\u8BC6\u5E93\u68C0\u7D22\u5931\u8D25: ${code} ${msg}`);
|
|
36420
|
-
}
|
|
36421
|
-
return { hits: normalizeHits(parsed.data?.hits) };
|
|
36422
|
-
}
|
|
36423
|
-
if (parsed.hits !== void 0) {
|
|
36424
|
-
return { hits: normalizeHits(parsed.hits) };
|
|
36425
|
-
}
|
|
36426
|
-
throw new Error("linkquegw \u77E5\u8BC6\u5E93\u68C0\u7D22\u54CD\u5E94\u7F3A\u5C11 success/hits");
|
|
36427
36881
|
}
|
|
36428
36882
|
};
|
|
36429
36883
|
function normalizeHits(raw) {
|
|
@@ -36477,7 +36931,7 @@ var LinkqueWebSearchPort = class {
|
|
|
36477
36931
|
if (!Number.isFinite(this.timeoutMs) || this.timeoutMs <= 0)
|
|
36478
36932
|
throw new Error("\u5168\u7F51\u641C\u7D22 timeoutMs \u5FC5\u987B\u4E3A\u6B63\u6570");
|
|
36479
36933
|
}
|
|
36480
|
-
async search(input, signal) {
|
|
36934
|
+
async search(input, signal, observation) {
|
|
36481
36935
|
const startedAt = Date.now();
|
|
36482
36936
|
const scope = new CancellationScope({
|
|
36483
36937
|
signals: signal ? [signal] : [],
|
|
@@ -36496,38 +36950,41 @@ var LinkqueWebSearchPort = class {
|
|
|
36496
36950
|
});
|
|
36497
36951
|
if (typeof input.agentId !== "string" || !input.agentId.trim() || [...input.agentId].length > 128)
|
|
36498
36952
|
throw new WebSearchError("WEB_SEARCH_INVALID_ARGS");
|
|
36499
|
-
const authHeaders = await
|
|
36953
|
+
const authHeaders = await waitWithSignal(() => this.options.getAuthHeaders(), requestSignal);
|
|
36500
36954
|
const authorization = readBearerAuthorization(authHeaders);
|
|
36501
36955
|
const url2 = new URL(this.endpoint);
|
|
36502
36956
|
url2.searchParams.set("agentId", input.agentId);
|
|
36503
36957
|
url2.searchParams.set("query", args.query);
|
|
36504
36958
|
if (args.topK !== void 0)
|
|
36505
36959
|
url2.searchParams.set("topK", String(args.topK));
|
|
36506
|
-
|
|
36507
|
-
|
|
36508
|
-
|
|
36509
|
-
|
|
36510
|
-
|
|
36511
|
-
|
|
36512
|
-
|
|
36513
|
-
|
|
36514
|
-
|
|
36515
|
-
|
|
36516
|
-
|
|
36517
|
-
|
|
36518
|
-
|
|
36519
|
-
|
|
36520
|
-
|
|
36521
|
-
|
|
36522
|
-
|
|
36960
|
+
return await observeIo(() => new IoObservation(observation, ETelemetryOperationName.WEB_SEARCH, httpTelemetryAttributes(url2, "GET"), requestSignal), async (operation) => {
|
|
36961
|
+
const response = await waitWithSignal(() => this.fetchImpl(url2, {
|
|
36962
|
+
method: "GET",
|
|
36963
|
+
headers: { authorization, accept: "application/json" },
|
|
36964
|
+
signal: requestSignal,
|
|
36965
|
+
redirect: "error"
|
|
36966
|
+
}), requestSignal);
|
|
36967
|
+
status = response.status;
|
|
36968
|
+
recordHttpResponse(operation, response);
|
|
36969
|
+
if (!response.ok) {
|
|
36970
|
+
void response.body?.cancel().catch(() => {
|
|
36971
|
+
});
|
|
36972
|
+
throw new WebSearchError(status === 401 || status === 403 ? "WEB_SEARCH_USER_ID_UNAVAILABLE" : status === 429 ? "WEB_SEARCH_RATE_LIMITED" : "WEB_SEARCH_UPSTREAM_ERROR");
|
|
36973
|
+
}
|
|
36974
|
+
const body = await readLimitedJson(response, requestSignal);
|
|
36975
|
+
requestSignal.throwIfAborted();
|
|
36976
|
+
const result = parseResponse(body, args.query, args.topK ?? WEB_SEARCH_TOP_K_DEFAULT);
|
|
36977
|
+
count = result.items.length;
|
|
36978
|
+
return result;
|
|
36979
|
+
});
|
|
36523
36980
|
} catch (error) {
|
|
36524
36981
|
if (signal?.aborted) {
|
|
36525
36982
|
outcome = "cancelled";
|
|
36526
36983
|
throw new DOMException("\u5168\u7F51\u641C\u7D22\u5DF2\u53D6\u6D88", "AbortError");
|
|
36527
36984
|
}
|
|
36528
|
-
const
|
|
36529
|
-
outcome =
|
|
36530
|
-
throw new WebSearchError(
|
|
36985
|
+
const failure4 = toWebSearchFailure(requestSignal.aborted ? requestSignal.reason : error);
|
|
36986
|
+
outcome = failure4.code;
|
|
36987
|
+
throw new WebSearchError(failure4.code);
|
|
36531
36988
|
} finally {
|
|
36532
36989
|
scope.dispose();
|
|
36533
36990
|
try {
|
|
@@ -36567,7 +37024,7 @@ async function readLimitedJson(response, signal) {
|
|
|
36567
37024
|
let completed = false;
|
|
36568
37025
|
try {
|
|
36569
37026
|
while (true) {
|
|
36570
|
-
const { done, value } = await
|
|
37027
|
+
const { done, value } = await waitWithSignal(() => reader.read(), signal);
|
|
36571
37028
|
if (done) {
|
|
36572
37029
|
completed = true;
|
|
36573
37030
|
break;
|
|
@@ -36676,19 +37133,19 @@ import path from "node:path";
|
|
|
36676
37133
|
import { fileURLToPath } from "node:url";
|
|
36677
37134
|
|
|
36678
37135
|
// ../../node_modules/fflate/esm/index.mjs
|
|
36679
|
-
import { createRequire } from "module";
|
|
36680
|
-
var require2 =
|
|
37136
|
+
import { createRequire as createRequire2 } from "module";
|
|
37137
|
+
var require2 = createRequire2("/");
|
|
36681
37138
|
var _a;
|
|
36682
|
-
var
|
|
37139
|
+
var Worker2;
|
|
36683
37140
|
var isMarkedAsUntransferable;
|
|
36684
37141
|
var workerAdd = ";var __w=require('worker_threads');__w.parentPort.on('message',function(m){onmessage({data:m})}),postMessage=function(m,t){__w.parentPort.postMessage(m,t)},close=process.exit;self=global";
|
|
36685
37142
|
try {
|
|
36686
|
-
_a = require2("worker_threads"),
|
|
37143
|
+
_a = require2("worker_threads"), Worker2 = _a.Worker, isMarkedAsUntransferable = _a.isMarkedAsUntransferable;
|
|
36687
37144
|
} catch (e) {
|
|
36688
37145
|
}
|
|
36689
|
-
var wk =
|
|
37146
|
+
var wk = Worker2 ? function(c, _, msg, transfer, cb) {
|
|
36690
37147
|
var done = false;
|
|
36691
|
-
var w = new
|
|
37148
|
+
var w = new Worker2(c + workerAdd, { eval: true }).on("error", function(e) {
|
|
36692
37149
|
return cb(e, null);
|
|
36693
37150
|
}).on("message", function(m) {
|
|
36694
37151
|
return cb(null, m);
|
|
@@ -36703,7 +37160,7 @@ var wk = Worker ? function(c, _, msg, transfer, cb) {
|
|
|
36703
37160
|
w.postMessage(msg, transfer);
|
|
36704
37161
|
w.terminate = function() {
|
|
36705
37162
|
done = true;
|
|
36706
|
-
return
|
|
37163
|
+
return Worker2.prototype.terminate.call(w);
|
|
36707
37164
|
};
|
|
36708
37165
|
return w;
|
|
36709
37166
|
} : function(_, __, ___, ____, cb) {
|
|
@@ -37323,6 +37780,117 @@ function unzip(data, opts, cb) {
|
|
|
37323
37780
|
return tAll;
|
|
37324
37781
|
}
|
|
37325
37782
|
|
|
37783
|
+
// ../linkque-agent-runtime/dist/esm/impl/linkqueSkillResourceResolver.js
|
|
37784
|
+
function isLocalSkillResource(resource) {
|
|
37785
|
+
return /^file:\/\//i.test(resource.config.skillZipUrl?.trim() ?? "");
|
|
37786
|
+
}
|
|
37787
|
+
var LinkqueSkillResourceResolver = class {
|
|
37788
|
+
options;
|
|
37789
|
+
fetchImpl;
|
|
37790
|
+
constructor(options = {}) {
|
|
37791
|
+
this.options = options;
|
|
37792
|
+
const fetchImpl = options.fetchImpl ?? globalThis.fetch;
|
|
37793
|
+
this.fetchImpl = options.debugLog ? createHttpLoggingFetch(options.debugLog, "skill-query", fetchImpl) : fetchImpl;
|
|
37794
|
+
}
|
|
37795
|
+
async resolve(resources, observation) {
|
|
37796
|
+
const invalidSkillResourceIds = [];
|
|
37797
|
+
const skillResourceIds = Array.from(new Set(resources.filter((r) => !isLocalSkillResource(r)).map((r) => r.resourceId))).filter((id) => {
|
|
37798
|
+
const valid = typeof id === "string" && id.trim().length > 0 && id.length <= 128;
|
|
37799
|
+
if (!valid)
|
|
37800
|
+
invalidSkillResourceIds.push(id);
|
|
37801
|
+
return valid;
|
|
37802
|
+
});
|
|
37803
|
+
this.warn(invalidSkillResourceIds, "\u65E0\u6548 resourceId");
|
|
37804
|
+
const urls = await this.queryBatch(skillResourceIds, observation);
|
|
37805
|
+
return resources.flatMap((resource) => {
|
|
37806
|
+
const url2 = isLocalSkillResource(resource) ? resource.config.skillZipUrl.trim() : urls.get(resource.resourceId);
|
|
37807
|
+
return url2 ? [{ ...resource, config: { ...resource.config, skillZipUrl: url2 } }] : [];
|
|
37808
|
+
});
|
|
37809
|
+
}
|
|
37810
|
+
async queryBatch(ids, observation) {
|
|
37811
|
+
const urls = /* @__PURE__ */ new Map();
|
|
37812
|
+
if (ids.length === 0)
|
|
37813
|
+
return urls;
|
|
37814
|
+
const scope = new CancellationScope({
|
|
37815
|
+
timeoutMs: this.options.timeoutMs ?? 3e4
|
|
37816
|
+
});
|
|
37817
|
+
const baseUrl = this.options.baseUrl ?? RUNTIME_CONFIG_DEFAULTS.LINKQUEGW_SKILL_LOADER_BASE_URL;
|
|
37818
|
+
const url2 = `${baseUrl.replace(/\/+$/, "")}/api/skill/batchQuery`;
|
|
37819
|
+
try {
|
|
37820
|
+
await observeIo(() => new IoObservation(observation, ETelemetryOperationName.SKILL_QUERY, {
|
|
37821
|
+
...httpTelemetryAttributes(url2, "POST"),
|
|
37822
|
+
[ETelemetryAttribute.LINKQUE_SKILL_REQUESTED_COUNT]: ids.length
|
|
37823
|
+
}, scope.context.signal), async (operation) => {
|
|
37824
|
+
operation.add({
|
|
37825
|
+
[ETelemetryAttribute.LINKQUE_SKILL_RESOLVED_COUNT]: 0,
|
|
37826
|
+
[ETelemetryAttribute.LINKQUE_SKILL_SKIPPED_COUNT]: ids.length
|
|
37827
|
+
});
|
|
37828
|
+
const headers = new Headers(await this.options.getAuthHeaders?.());
|
|
37829
|
+
if (!headers.get("authorization")?.trim()) {
|
|
37830
|
+
this.warn(ids, "\u7F3A\u5C11\u7F51\u5173\u9274\u6743");
|
|
37831
|
+
return ETelemetryOutcome.ERROR;
|
|
37832
|
+
}
|
|
37833
|
+
headers.set("content-type", "application/json");
|
|
37834
|
+
const response = await this.fetchImpl(url2, {
|
|
37835
|
+
method: "POST",
|
|
37836
|
+
headers,
|
|
37837
|
+
body: JSON.stringify({ abilityCodes: ids }),
|
|
37838
|
+
signal: scope.context.signal
|
|
37839
|
+
});
|
|
37840
|
+
recordHttpResponse(operation, response);
|
|
37841
|
+
if (!response.ok) {
|
|
37842
|
+
throw new Error(`HTTP ${response.status}`);
|
|
37843
|
+
}
|
|
37844
|
+
const body = await response.json();
|
|
37845
|
+
if (!isObject3(body) || body.success !== true || !isObject3(body.data) || !Array.isArray(body.data.skills)) {
|
|
37846
|
+
throw new Error("\u7F51\u5173\u4E1A\u52A1\u5931\u8D25\u6216\u54CD\u5E94\u683C\u5F0F\u65E0\u6548");
|
|
37847
|
+
}
|
|
37848
|
+
for (const item of body.data.skills) {
|
|
37849
|
+
if (!isObject3(item) || typeof item.abilityCode !== "string" || !ids.includes(item.abilityCode)) {
|
|
37850
|
+
continue;
|
|
37851
|
+
}
|
|
37852
|
+
const skillZipUrl = httpUrl(item.skillZipUrl);
|
|
37853
|
+
if (skillZipUrl) {
|
|
37854
|
+
urls.set(item.abilityCode, skillZipUrl);
|
|
37855
|
+
}
|
|
37856
|
+
}
|
|
37857
|
+
const noURLIds = ids.filter((id) => !urls.has(id));
|
|
37858
|
+
if (noURLIds.length > 0) {
|
|
37859
|
+
this.warn(noURLIds, "\u672A\u8FD4\u56DE\u6709\u6548 HTTP(S) skillZipUrl");
|
|
37860
|
+
}
|
|
37861
|
+
operation.add({
|
|
37862
|
+
[ETelemetryAttribute.LINKQUE_SKILL_RESOLVED_COUNT]: urls.size,
|
|
37863
|
+
[ETelemetryAttribute.LINKQUE_SKILL_SKIPPED_COUNT]: noURLIds.length
|
|
37864
|
+
});
|
|
37865
|
+
return noURLIds.length === 0 ? ETelemetryOutcome.SUCCESS : ETelemetryOutcome.ERROR;
|
|
37866
|
+
}, (outcome) => outcome);
|
|
37867
|
+
} catch {
|
|
37868
|
+
const reason = scope.context.signal.aborted ? "\u67E5\u8BE2\u8D85\u65F6" : "\u7F51\u5173\u67E5\u8BE2\u5931\u8D25";
|
|
37869
|
+
this.warn(ids, reason);
|
|
37870
|
+
} finally {
|
|
37871
|
+
scope.dispose();
|
|
37872
|
+
}
|
|
37873
|
+
return urls;
|
|
37874
|
+
}
|
|
37875
|
+
warn(resourceIds, reason) {
|
|
37876
|
+
const ids = Array.isArray(resourceIds) ? resourceIds : [resourceIds];
|
|
37877
|
+
this.options.debugLog?.(`[skill] \u8DF3\u8FC7\u8D44\u6E90 ${ids.join(",")}:${reason}`, EDebugLogScope.SKILL);
|
|
37878
|
+
}
|
|
37879
|
+
};
|
|
37880
|
+
function isObject3(value) {
|
|
37881
|
+
return typeof value === "object" && value !== null;
|
|
37882
|
+
}
|
|
37883
|
+
function httpUrl(value) {
|
|
37884
|
+
if (typeof value !== "string" || !/^https?:\/\//i.test(value.trim()))
|
|
37885
|
+
return void 0;
|
|
37886
|
+
try {
|
|
37887
|
+
const url2 = new URL(value.trim());
|
|
37888
|
+
return url2.protocol === "http:" || url2.protocol === "https:" ? value.trim() : void 0;
|
|
37889
|
+
} catch {
|
|
37890
|
+
return void 0;
|
|
37891
|
+
}
|
|
37892
|
+
}
|
|
37893
|
+
|
|
37326
37894
|
// ../linkque-agent-runtime/dist/esm/impl/webSkillLoader.js
|
|
37327
37895
|
var ESkillUrlScheme;
|
|
37328
37896
|
(function(ESkillUrlScheme2) {
|
|
@@ -37336,12 +37904,17 @@ var DEFAULT_SCHEMES = [
|
|
|
37336
37904
|
ESkillUrlScheme.FILE
|
|
37337
37905
|
];
|
|
37338
37906
|
var WebSkillLoader = class {
|
|
37907
|
+
resourceResolver;
|
|
37339
37908
|
root;
|
|
37340
37909
|
allowedSchemes;
|
|
37341
37910
|
fetchImpl;
|
|
37342
37911
|
/** 缺 description 等被跳过技能的警告 sink(可选);与下载出站日志同源。 */
|
|
37343
37912
|
debugLog;
|
|
37344
37913
|
constructor(options) {
|
|
37914
|
+
this.resourceResolver = new LinkqueSkillResourceResolver({
|
|
37915
|
+
...options.skillQuery,
|
|
37916
|
+
debugLog: options.debugLog ?? options.skillQuery?.debugLog
|
|
37917
|
+
});
|
|
37345
37918
|
this.allowedSchemes = options.allowedSchemes ?? DEFAULT_SCHEMES;
|
|
37346
37919
|
const allowsFile = this.allowedSchemes.includes(ESkillUrlScheme.FILE);
|
|
37347
37920
|
if (allowsFile && (options.root === void 0 || options.root.trim() === "")) {
|
|
@@ -37352,19 +37925,29 @@ var WebSkillLoader = class {
|
|
|
37352
37925
|
const baseFetch = options.fetchImpl ?? globalFetch;
|
|
37353
37926
|
this.fetchImpl = options.debugLog ? (url2) => createHttpLoggingFetch(options.debugLog, "skill", baseFetch)(url2) : baseFetch;
|
|
37354
37927
|
}
|
|
37355
|
-
async load(resources) {
|
|
37928
|
+
async load(resources, observation) {
|
|
37356
37929
|
if (resources.length === 0)
|
|
37357
37930
|
return [];
|
|
37358
|
-
const
|
|
37931
|
+
const resolvedResources = await this.resourceResolver.resolve(resources, observation);
|
|
37932
|
+
const records = await Promise.all(resolvedResources.map((resource) => observeIo(() => new IoObservation(observation, ETelemetryOperationName.SKILL_RESOURCE_LOAD, {
|
|
37933
|
+
[ETelemetryAttribute.LINKQUE_SKILL_RESOURCE_ID]: resource.resourceId
|
|
37934
|
+
}), async (operation) => {
|
|
37935
|
+
const record2 = await this.loadOne(resource, operation.observation);
|
|
37936
|
+
operation.add({
|
|
37937
|
+
[ETelemetryAttribute.LINKQUE_SKILL_LOADED_COUNT]: record2 ? 1 : 0,
|
|
37938
|
+
[ETelemetryAttribute.LINKQUE_SKILL_SKIPPED_COUNT]: record2 ? 0 : 1
|
|
37939
|
+
});
|
|
37940
|
+
return record2;
|
|
37941
|
+
})));
|
|
37359
37942
|
return records.filter((record2, idx) => {
|
|
37360
37943
|
if (record2 !== void 0)
|
|
37361
37944
|
return true;
|
|
37362
|
-
this.debugLog?.(`[skill] \u8DF3\u8FC7\u8D44\u6E90 ${
|
|
37945
|
+
this.debugLog?.(`[skill] \u8DF3\u8FC7\u8D44\u6E90 ${resolvedResources[idx]?.resourceId ?? "?"}:SKILL.md \u7F3A description(\u524D\u7F6E\u65E0\u6548),\u6309 spec \u4E0D\u52A0\u8F7D`, EDebugLogScope.SKILL);
|
|
37363
37946
|
return false;
|
|
37364
37947
|
});
|
|
37365
37948
|
}
|
|
37366
37949
|
/** 加载单个 skill 资源:按 skillZipUrl 协议分发,先校验协议在 allowedSchemes 白名单内。 */
|
|
37367
|
-
async loadOne(resource) {
|
|
37950
|
+
async loadOne(resource, observation) {
|
|
37368
37951
|
const url2 = resource.config.skillZipUrl.trim();
|
|
37369
37952
|
const scheme = detectScheme(url2);
|
|
37370
37953
|
if (scheme === null || !this.allowedSchemes.includes(scheme)) {
|
|
@@ -37372,7 +37955,7 @@ var WebSkillLoader = class {
|
|
|
37372
37955
|
}
|
|
37373
37956
|
let raw;
|
|
37374
37957
|
if (scheme === ESkillUrlScheme.HTTP || scheme === ESkillUrlScheme.HTTPS) {
|
|
37375
|
-
const buf = await this.fetchZip(url2, resource.resourceId);
|
|
37958
|
+
const buf = await this.fetchZip(url2, resource.resourceId, observation);
|
|
37376
37959
|
const files = await unzipBytes(buf, resource.resourceId);
|
|
37377
37960
|
const md = extractSkillMarkdown(files);
|
|
37378
37961
|
if (md === void 0) {
|
|
@@ -37409,18 +37992,24 @@ var WebSkillLoader = class {
|
|
|
37409
37992
|
return readFile(candidate, "utf8");
|
|
37410
37993
|
}
|
|
37411
37994
|
/** fetch zip 字节;非 2xx 或网络失败抛错。 */
|
|
37412
|
-
async fetchZip(url2, resourceId) {
|
|
37413
|
-
|
|
37414
|
-
|
|
37415
|
-
|
|
37416
|
-
}
|
|
37417
|
-
|
|
37418
|
-
|
|
37419
|
-
|
|
37420
|
-
|
|
37421
|
-
|
|
37422
|
-
|
|
37423
|
-
|
|
37995
|
+
async fetchZip(url2, resourceId, observation) {
|
|
37996
|
+
return observeIo(() => new IoObservation(observation, ETelemetryOperationName.SKILL_DOWNLOAD, {
|
|
37997
|
+
...httpTelemetryAttributes(url2, "GET"),
|
|
37998
|
+
[ETelemetryAttribute.LINKQUE_SKILL_RESOURCE_ID]: resourceId
|
|
37999
|
+
}), async (operation) => {
|
|
38000
|
+
let response;
|
|
38001
|
+
try {
|
|
38002
|
+
response = await this.fetchImpl(url2);
|
|
38003
|
+
} catch (cause) {
|
|
38004
|
+
throw new Error(`WebSkillLoader fetch \u5931\u8D25: ${url2} (resourceId=${resourceId}): ${cause instanceof Error ? cause.message : String(cause)}`, { cause });
|
|
38005
|
+
}
|
|
38006
|
+
recordHttpResponse(operation, response);
|
|
38007
|
+
if (!response.ok) {
|
|
38008
|
+
throw new Error(`WebSkillLoader fetch \u975E 2xx: ${response.status} ${url2} (resourceId=${resourceId})`);
|
|
38009
|
+
}
|
|
38010
|
+
const arrayBuffer = await response.arrayBuffer();
|
|
38011
|
+
return new Uint8Array(arrayBuffer);
|
|
38012
|
+
});
|
|
37424
38013
|
}
|
|
37425
38014
|
};
|
|
37426
38015
|
var isZipPath = (p) => /\.zip$/i.test(p);
|
|
@@ -37531,19 +38120,32 @@ function safeStringifyArgs(args) {
|
|
|
37531
38120
|
// ../linkque-agent-runtime/dist/esm/impl/agui/conversationBridge.js
|
|
37532
38121
|
async function* streamToConversationEvents(events, ctx, options = {}) {
|
|
37533
38122
|
const generateId = options.generateId ?? defaultGenerateId;
|
|
38123
|
+
let eventSource;
|
|
38124
|
+
let messageSource;
|
|
38125
|
+
let thinkingSource;
|
|
38126
|
+
const emitAgui = (base, id, source = eventSource) => {
|
|
38127
|
+
const output = createConversationAGUIEvent(base, id);
|
|
38128
|
+
try {
|
|
38129
|
+
if (source)
|
|
38130
|
+
options.eventObservations?.transfer(source, output);
|
|
38131
|
+
} catch {
|
|
38132
|
+
}
|
|
38133
|
+
return output;
|
|
38134
|
+
};
|
|
37534
38135
|
yield createConversationRunAck(ctx.runId, ctx.threadId);
|
|
37535
|
-
yield
|
|
38136
|
+
yield emitAgui({ type: EventType.RUN_STARTED, threadId: ctx.threadId, runId: ctx.runId }, void 0);
|
|
37536
38137
|
let activeMessageId;
|
|
37537
38138
|
let activeThinkingId;
|
|
37538
38139
|
let sawDone = false;
|
|
37539
38140
|
for await (const ev of events) {
|
|
38141
|
+
eventSource = ev;
|
|
37540
38142
|
if (ev.type === "error") {
|
|
37541
38143
|
if (activeMessageId !== void 0) {
|
|
37542
|
-
yield
|
|
38144
|
+
yield emitAgui(emitTextEnd(activeMessageId), void 0, messageSource);
|
|
37543
38145
|
activeMessageId = void 0;
|
|
37544
38146
|
}
|
|
37545
38147
|
if (activeThinkingId !== void 0) {
|
|
37546
|
-
yield
|
|
38148
|
+
yield emitAgui(emitThinkingEnd(activeThinkingId), void 0, thinkingSource);
|
|
37547
38149
|
activeThinkingId = void 0;
|
|
37548
38150
|
}
|
|
37549
38151
|
yield options.signal?.aborted ? createCancelledEvent() : createConversationTransportError({
|
|
@@ -37560,7 +38162,7 @@ async function* streamToConversationEvents(events, ctx, options = {}) {
|
|
|
37560
38162
|
if (ev.type === "thinking") {
|
|
37561
38163
|
if (activeThinkingId === void 0) {
|
|
37562
38164
|
activeThinkingId = generateId();
|
|
37563
|
-
yield
|
|
38165
|
+
yield emitAgui({
|
|
37564
38166
|
type: EventType.THINKING_TEXT_MESSAGE_START,
|
|
37565
38167
|
messageId: activeThinkingId,
|
|
37566
38168
|
role: "assistant"
|
|
@@ -37568,14 +38170,14 @@ async function* streamToConversationEvents(events, ctx, options = {}) {
|
|
|
37568
38170
|
}
|
|
37569
38171
|
} else {
|
|
37570
38172
|
if (activeThinkingId !== void 0) {
|
|
37571
|
-
yield
|
|
38173
|
+
yield emitAgui(emitThinkingEnd(activeThinkingId), void 0, thinkingSource);
|
|
37572
38174
|
activeThinkingId = void 0;
|
|
37573
38175
|
}
|
|
37574
38176
|
}
|
|
37575
38177
|
if (ev.type === "delta") {
|
|
37576
38178
|
if (activeMessageId === void 0) {
|
|
37577
38179
|
activeMessageId = generateId();
|
|
37578
|
-
yield
|
|
38180
|
+
yield emitAgui({
|
|
37579
38181
|
type: EventType.TEXT_MESSAGE_START,
|
|
37580
38182
|
messageId: activeMessageId,
|
|
37581
38183
|
role: "assistant"
|
|
@@ -37583,20 +38185,25 @@ async function* streamToConversationEvents(events, ctx, options = {}) {
|
|
|
37583
38185
|
}
|
|
37584
38186
|
} else if (ev.type !== "thinking") {
|
|
37585
38187
|
if (activeMessageId !== void 0) {
|
|
37586
|
-
yield
|
|
38188
|
+
yield emitAgui(emitTextEnd(activeMessageId), void 0, messageSource);
|
|
37587
38189
|
activeMessageId = void 0;
|
|
37588
38190
|
}
|
|
37589
38191
|
}
|
|
38192
|
+
if (ev.type === "delta")
|
|
38193
|
+
messageSource = ev;
|
|
38194
|
+
if (ev.type === "thinking")
|
|
38195
|
+
thinkingSource = ev;
|
|
37590
38196
|
for (const base of mapAgentEventToBaseEvents(ev, activeMessageId, activeThinkingId)) {
|
|
37591
|
-
yield
|
|
38197
|
+
yield emitAgui(base, void 0);
|
|
37592
38198
|
}
|
|
37593
38199
|
}
|
|
38200
|
+
eventSource = void 0;
|
|
37594
38201
|
if (activeMessageId !== void 0) {
|
|
37595
|
-
yield
|
|
38202
|
+
yield emitAgui(emitTextEnd(activeMessageId), void 0, messageSource);
|
|
37596
38203
|
activeMessageId = void 0;
|
|
37597
38204
|
}
|
|
37598
38205
|
if (activeThinkingId !== void 0) {
|
|
37599
|
-
yield
|
|
38206
|
+
yield emitAgui(emitThinkingEnd(activeThinkingId), void 0, thinkingSource);
|
|
37600
38207
|
activeThinkingId = void 0;
|
|
37601
38208
|
}
|
|
37602
38209
|
if (!sawDone) {
|
|
@@ -37607,7 +38214,7 @@ async function* streamToConversationEvents(events, ctx, options = {}) {
|
|
|
37607
38214
|
});
|
|
37608
38215
|
return;
|
|
37609
38216
|
}
|
|
37610
|
-
yield
|
|
38217
|
+
yield emitAgui({ type: EventType.RUN_FINISHED, threadId: ctx.threadId, runId: ctx.runId }, void 0);
|
|
37611
38218
|
}
|
|
37612
38219
|
function createCancelledEvent() {
|
|
37613
38220
|
return createConversationTransportError({
|
|
@@ -37965,6 +38572,22 @@ var MAX_ATTRIBUTE_COUNT = 64;
|
|
|
37965
38572
|
var MAX_STRING_LENGTH = 256;
|
|
37966
38573
|
var MAX_ARRAY_LENGTH = 16;
|
|
37967
38574
|
var allowedAttributeKeys = /* @__PURE__ */ new Set([
|
|
38575
|
+
ETelemetryAttribute.LINKQUE_REMOTE_TRACE_ID,
|
|
38576
|
+
ETelemetryAttribute.LINKQUE_REMOTE_TRACE_ID_HEADER,
|
|
38577
|
+
ETelemetryAttribute.HTTP_REQUEST_METHOD,
|
|
38578
|
+
ETelemetryAttribute.SERVER_ADDRESS,
|
|
38579
|
+
ETelemetryAttribute.URL_PATH,
|
|
38580
|
+
ETelemetryAttribute.LINKQUE_MCP_PHASE,
|
|
38581
|
+
ETelemetryAttribute.LINKQUE_MCP_SERVER_NAME,
|
|
38582
|
+
ETelemetryAttribute.LINKQUE_IO_ATTEMPT,
|
|
38583
|
+
ETelemetryAttribute.LINKQUE_SKILL_RESOURCE_ID,
|
|
38584
|
+
ETelemetryAttribute.LINKQUE_SKILL_REQUESTED_COUNT,
|
|
38585
|
+
ETelemetryAttribute.LINKQUE_SKILL_LOADED_COUNT,
|
|
38586
|
+
ETelemetryAttribute.LINKQUE_SKILL_RESOLVED_COUNT,
|
|
38587
|
+
ETelemetryAttribute.LINKQUE_SKILL_SKIPPED_COUNT,
|
|
38588
|
+
ETelemetryAttribute.LINKQUE_CHUNK_INDEX,
|
|
38589
|
+
ETelemetryAttribute.LINKQUE_CHUNK_STATUS,
|
|
38590
|
+
ETelemetryAttribute.LINKQUE_CHUNK_LINE_COUNT,
|
|
37968
38591
|
ETelemetryAttribute.HARNESS_TELEMETRY_SCHEMA_VERSION,
|
|
37969
38592
|
ETelemetryAttribute.LINKQUE_TELEMETRY_SCHEMA_VERSION,
|
|
37970
38593
|
ETelemetryAttribute.LINKQUE_TELEMETRY_ADAPTER_VERSION,
|
|
@@ -37986,6 +38609,8 @@ var allowedAttributeKeys = /* @__PURE__ */ new Set([
|
|
|
37986
38609
|
ETelemetryAttribute.HARNESS_INVOCATION_ID,
|
|
37987
38610
|
ETelemetryAttribute.HARNESS_ATTEMPT_ID,
|
|
37988
38611
|
ETelemetryAttribute.HARNESS_ATTEMPT_VISIBILITY,
|
|
38612
|
+
ETelemetryAttribute.LINKQUE_APPBASE_RUN_FAILURE_STAGE,
|
|
38613
|
+
ETelemetryAttribute.LINKQUE_APPBASE_RUN_ERROR_MESSAGE,
|
|
37989
38614
|
ETelemetryAttribute.HARNESS_ADVANCE_OUTCOME,
|
|
37990
38615
|
ETelemetryAttribute.HARNESS_OPERATION_OUTCOME,
|
|
37991
38616
|
ETelemetryAttribute.HARNESS_REMOTE_COMPLETION,
|
|
@@ -38063,6 +38688,7 @@ var allowedAttributeKeys = /* @__PURE__ */ new Set([
|
|
|
38063
38688
|
ETelemetryAttribute.HTTP_RESPONSE_STATUS_CODE
|
|
38064
38689
|
]);
|
|
38065
38690
|
var priorityAttributeKeys = /* @__PURE__ */ new Set([
|
|
38691
|
+
ETelemetryAttribute.ERROR_TYPE,
|
|
38066
38692
|
ETelemetryAttribute.HARNESS_RECORD_ID,
|
|
38067
38693
|
ETelemetryAttribute.HARNESS_EVENT_SEQUENCE,
|
|
38068
38694
|
ETelemetryAttribute.HARNESS_ADVANCE_ID,
|
|
@@ -38072,6 +38698,8 @@ var priorityAttributeKeys = /* @__PURE__ */ new Set([
|
|
|
38072
38698
|
ETelemetryAttribute.LINKQUE_OPERATION_NAME,
|
|
38073
38699
|
ETelemetryAttribute.LINKQUE_OPERATION_DURATION_MS,
|
|
38074
38700
|
ETelemetryAttribute.HARNESS_OPERATION_OUTCOME,
|
|
38701
|
+
ETelemetryAttribute.LINKQUE_APPBASE_RUN_FAILURE_STAGE,
|
|
38702
|
+
ETelemetryAttribute.LINKQUE_APPBASE_RUN_ERROR_MESSAGE,
|
|
38075
38703
|
ETelemetryAttribute.HARNESS_ADVANCE_OUTCOME,
|
|
38076
38704
|
ETelemetryAttribute.HARNESS_CALL_ID,
|
|
38077
38705
|
ETelemetryAttribute.HARNESS_INVOCATION_ID,
|
|
@@ -38215,6 +38843,17 @@ var OtelRuntimeTelemetry = class {
|
|
|
38215
38843
|
}
|
|
38216
38844
|
}
|
|
38217
38845
|
startAdvance(input) {
|
|
38846
|
+
return this.startOperation(input, {
|
|
38847
|
+
name: ETelemetryOperationName.ADVANCE,
|
|
38848
|
+
eventPrefix: ETelemetryEventPrefix.ADVANCE,
|
|
38849
|
+
attributes: {
|
|
38850
|
+
[ETelemetryAttribute.GEN_AI_OPERATION_NAME]: ETelemetryGenAiOperation.INVOKE_AGENT
|
|
38851
|
+
},
|
|
38852
|
+
detached: false,
|
|
38853
|
+
links: []
|
|
38854
|
+
});
|
|
38855
|
+
}
|
|
38856
|
+
startOperation(input, spec) {
|
|
38218
38857
|
if (this.closed || this.outputActive || this.queue.isExporting)
|
|
38219
38858
|
return new NoopRuntimeObservation();
|
|
38220
38859
|
try {
|
|
@@ -38246,15 +38885,7 @@ var OtelRuntimeTelemetry = class {
|
|
|
38246
38885
|
[ETelemetryAttribute.LINKQUE_USER_KEY]: input.context.userKey
|
|
38247
38886
|
})
|
|
38248
38887
|
};
|
|
38249
|
-
return this.createOperation(state,
|
|
38250
|
-
name: ETelemetryOperationName.ADVANCE,
|
|
38251
|
-
eventPrefix: ETelemetryEventPrefix.ADVANCE,
|
|
38252
|
-
attributes: {
|
|
38253
|
-
[ETelemetryAttribute.GEN_AI_OPERATION_NAME]: ETelemetryGenAiOperation.INVOKE_AGENT
|
|
38254
|
-
},
|
|
38255
|
-
detached: false,
|
|
38256
|
-
links: []
|
|
38257
|
-
}, void 0, input.context.parent);
|
|
38888
|
+
return this.createOperation(state, spec, void 0, input.context.parent);
|
|
38258
38889
|
} catch {
|
|
38259
38890
|
this.queue.report(ETelemetryDiagnosticCode.CAPTURE_FAILED);
|
|
38260
38891
|
return new NoopRuntimeObservation();
|
|
@@ -38301,7 +38932,15 @@ var OtelRuntimeTelemetry = class {
|
|
|
38301
38932
|
[ETelemetryAttribute.LINKQUE_SPAN_PARENT_ID]: spec.detached ? "" : parentContext?.spanId ?? ""
|
|
38302
38933
|
});
|
|
38303
38934
|
const span = this.tracerProvider.getTracer(ETelemetryMetadata.SCOPE_NAME, ETelemetryVersion.V1_0).startSpan(spec.name, {
|
|
38304
|
-
kind:
|
|
38935
|
+
kind: [
|
|
38936
|
+
ETelemetryOperationName.MODEL_ATTEMPT,
|
|
38937
|
+
ETelemetryOperationName.RUNS_WRITE,
|
|
38938
|
+
ETelemetryOperationName.MCP_SIGN,
|
|
38939
|
+
ETelemetryOperationName.MCP_OPENGW,
|
|
38940
|
+
ETelemetryOperationName.MCP_VERIFY,
|
|
38941
|
+
ETelemetryOperationName.KNOWLEDGE_SEARCH,
|
|
38942
|
+
ETelemetryOperationName.WEB_SEARCH
|
|
38943
|
+
].includes(spec.name) ? SpanKind.CLIENT : SpanKind.INTERNAL,
|
|
38305
38944
|
attributes,
|
|
38306
38945
|
links: spec.links.filter((link) => validContext(link.context)).slice(0, 16).map((link) => ({
|
|
38307
38946
|
context: {
|
|
@@ -38393,6 +39032,17 @@ var OtelRuntimeTelemetry = class {
|
|
|
38393
39032
|
this.routes.delete(operation.spanContext.spanId);
|
|
38394
39033
|
this.queue.release(operation.state.route);
|
|
38395
39034
|
}
|
|
39035
|
+
/** 快照持有发送分区,直到宿主完成延迟写入后释放。 */
|
|
39036
|
+
retainParent(operation) {
|
|
39037
|
+
this.queue.retain(operation.state.route);
|
|
39038
|
+
let released = false;
|
|
39039
|
+
return () => {
|
|
39040
|
+
if (released)
|
|
39041
|
+
return;
|
|
39042
|
+
released = true;
|
|
39043
|
+
this.queue.release(operation.state.route);
|
|
39044
|
+
};
|
|
39045
|
+
}
|
|
38396
39046
|
forceFlush(options) {
|
|
38397
39047
|
return this.queue.forceFlush(options);
|
|
38398
39048
|
}
|
|
@@ -38452,6 +39102,19 @@ var OtelObservation = class {
|
|
|
38452
39102
|
return new NoopRuntimeObservation();
|
|
38453
39103
|
return this.owner.createOperation(this.state, spec, this);
|
|
38454
39104
|
}
|
|
39105
|
+
captureParent() {
|
|
39106
|
+
const releaseRoute = this.owner.retainParent(this);
|
|
39107
|
+
let released = false;
|
|
39108
|
+
return {
|
|
39109
|
+
operationId: this.operationId,
|
|
39110
|
+
spanContext: this.spanContext,
|
|
39111
|
+
startOperation: (spec) => released || this.lost ? new NoopRuntimeObservation() : this.owner.createOperation(this.state, spec, this),
|
|
39112
|
+
release: () => {
|
|
39113
|
+
released = true;
|
|
39114
|
+
releaseRoute();
|
|
39115
|
+
}
|
|
39116
|
+
};
|
|
39117
|
+
}
|
|
38455
39118
|
record(name, attributes, body) {
|
|
38456
39119
|
if (this.lost || !/^(harness|linkque)\.[a-z0-9_.]{1,128}$/.test(name))
|
|
38457
39120
|
return;
|
|
@@ -38461,20 +39124,23 @@ var OtelObservation = class {
|
|
|
38461
39124
|
finish(outcome, attributes) {
|
|
38462
39125
|
if (this.ended)
|
|
38463
39126
|
return;
|
|
38464
|
-
|
|
38465
|
-
...attributes,
|
|
38466
|
-
[ETelemetryAttribute.HARNESS_OPERATION_OUTCOME]: outcome,
|
|
38467
|
-
[ETelemetryAttribute.LINKQUE_OPERATION_DURATION_MS]: performance.now() - this.started
|
|
38468
|
-
});
|
|
39127
|
+
this.ended = true;
|
|
38469
39128
|
try {
|
|
39129
|
+
const result = sanitizeTelemetryAttributes({
|
|
39130
|
+
...attributes,
|
|
39131
|
+
[ETelemetryAttribute.HARNESS_OPERATION_OUTCOME]: outcome,
|
|
39132
|
+
[ETelemetryAttribute.LINKQUE_OPERATION_DURATION_MS]: performance.now() - this.started
|
|
39133
|
+
});
|
|
38470
39134
|
this.span.setAttributes(result);
|
|
38471
39135
|
if (outcome === ETelemetryOutcome.ERROR || outcome === ETelemetryOutcome.TIMEOUT)
|
|
38472
39136
|
this.span.setStatus({ code: SpanStatusCode.ERROR });
|
|
38473
39137
|
this.record(`${this.spec.eventPrefix}.${ETelemetryEventPhase.FINISHED}`, result);
|
|
38474
|
-
this.span.end();
|
|
38475
39138
|
} finally {
|
|
38476
|
-
|
|
38477
|
-
|
|
39139
|
+
try {
|
|
39140
|
+
this.span.end();
|
|
39141
|
+
} finally {
|
|
39142
|
+
this.owner.release(this);
|
|
39143
|
+
}
|
|
38478
39144
|
}
|
|
38479
39145
|
}
|
|
38480
39146
|
abandon(reason) {
|
|
@@ -38501,6 +39167,7 @@ function validContext(value) {
|
|
|
38501
39167
|
|
|
38502
39168
|
export {
|
|
38503
39169
|
EModelRequestSource,
|
|
39170
|
+
DataTransformExecutor,
|
|
38504
39171
|
EDebugLogScope,
|
|
38505
39172
|
isDebugLoggingEnabled,
|
|
38506
39173
|
createRuntimeDebugLog,
|
|
@@ -38510,18 +39177,24 @@ export {
|
|
|
38510
39177
|
EHookStage,
|
|
38511
39178
|
EHookExecutorName,
|
|
38512
39179
|
isJsonValue,
|
|
39180
|
+
cloneJsonValue,
|
|
39181
|
+
cloneJsonObject,
|
|
38513
39182
|
isSafeJsonPointer,
|
|
38514
39183
|
readJsonPointer,
|
|
39184
|
+
writeJsonPointer,
|
|
39185
|
+
validateJsonSchemaValue2 as validateJsonSchemaValue,
|
|
39186
|
+
normalizeCardDataValue,
|
|
38515
39187
|
executeA2UICardResolver,
|
|
38516
|
-
parseA2UIActionExecuteRequest,
|
|
38517
39188
|
parseA2UIFunctionMcpExecuteRequest,
|
|
38518
39189
|
stableToolName,
|
|
38519
39190
|
createCardPresentationToolName,
|
|
38520
39191
|
executeCardPresentation,
|
|
38521
39192
|
executeCardPresentationFromSources,
|
|
39193
|
+
createPresentationResult,
|
|
38522
39194
|
projectPresentationReceiptForModel,
|
|
38523
39195
|
parseCardConfig,
|
|
38524
39196
|
isAgentPresentationToolResult,
|
|
39197
|
+
isAgentPresentationSkippedToolResult,
|
|
38525
39198
|
createPresentationDescription,
|
|
38526
39199
|
readStructuredContent,
|
|
38527
39200
|
normalizeMcpInputSchema,
|
|
@@ -38557,13 +39230,18 @@ export {
|
|
|
38557
39230
|
ETelemetryModelPurpose,
|
|
38558
39231
|
ETelemetryErrorType,
|
|
38559
39232
|
ETelemetryGenAiOperation,
|
|
39233
|
+
NoopRuntimeObservation,
|
|
39234
|
+
NoopRuntimeTelemetry,
|
|
39235
|
+
skipError,
|
|
39236
|
+
RuntimeObservation,
|
|
39237
|
+
startRuntimeObservation,
|
|
39238
|
+
observeIo,
|
|
39239
|
+
IoObservation,
|
|
38560
39240
|
recordContentSection,
|
|
38561
39241
|
waitWithSignal,
|
|
38562
39242
|
CancellationScope,
|
|
38563
39243
|
McpProxyTool,
|
|
38564
39244
|
executeHomeData,
|
|
38565
|
-
CardActionDiagnostics,
|
|
38566
|
-
executeCardAction,
|
|
38567
39245
|
executeFunctionActionMcp,
|
|
38568
39246
|
FOLLOW_UP_CONTEXT_MAX_HISTORY_RUNS,
|
|
38569
39247
|
prepareFollowUpQuestionContext,
|
|
@@ -38573,6 +39251,9 @@ export {
|
|
|
38573
39251
|
NoopMcpServerProvider,
|
|
38574
39252
|
buildHookCommonParams,
|
|
38575
39253
|
normalizeHookResources,
|
|
39254
|
+
observePromise,
|
|
39255
|
+
observeStream,
|
|
39256
|
+
observeEvent,
|
|
38576
39257
|
warnLogFailure,
|
|
38577
39258
|
HookDispatcher,
|
|
38578
39259
|
DEFAULT_HOOK_DRAIN_BUDGET_MS,
|
|
@@ -38595,12 +39276,13 @@ export {
|
|
|
38595
39276
|
createWebSearchTool,
|
|
38596
39277
|
createKnowledgeTools,
|
|
38597
39278
|
NoopWebSearchPort,
|
|
38598
|
-
|
|
38599
|
-
startRuntimeObservation,
|
|
39279
|
+
EventObservationRegistry,
|
|
38600
39280
|
abortableDelay,
|
|
38601
39281
|
RemoteGatewayMcpServerProvider,
|
|
38602
39282
|
LinkqueKnowledgeSearchPort,
|
|
38603
39283
|
LinkqueWebSearchPort,
|
|
39284
|
+
isLocalSkillResource,
|
|
39285
|
+
LinkqueSkillResourceResolver,
|
|
38604
39286
|
ESkillUrlScheme,
|
|
38605
39287
|
WebSkillLoader,
|
|
38606
39288
|
EventType,
|