linkque-cli-v2 1.3.0 → 1.3.1
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/linkquejs.js +1497 -1295
- package/package.json +1 -1
- package/vendor/linkque-agent-appwrite-integrate/dist/esm/{chunk-LVUJW2KB.js → chunk-CITJWG2O.js} +1 -1
- package/vendor/linkque-agent-appwrite-integrate/dist/esm/{chunk-EG3MWFEG.js → chunk-KTFQX5XN.js} +1 -1
- package/vendor/linkque-agent-appwrite-integrate/dist/esm/{chunk-DCQYAWC6.js → chunk-P5YTVR76.js} +267 -20
- package/vendor/linkque-agent-appwrite-integrate/dist/esm/runtime/handler/chat.js +418 -116
- 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/worker.js +419 -70
package/worker.js
CHANGED
|
@@ -39,6 +39,7 @@ var init_types = __esm({
|
|
|
39
39
|
"../linkque-agent-runtime/dist/esm/core/types.js"() {
|
|
40
40
|
"use strict";
|
|
41
41
|
(function(EDebugLogScope2) {
|
|
42
|
+
EDebugLogScope2["A2UI_ACTION"] = "A2UI_ACTION";
|
|
42
43
|
EDebugLogScope2["CONFIG"] = "CONFIG";
|
|
43
44
|
EDebugLogScope2["LLM"] = "LLM";
|
|
44
45
|
EDebugLogScope2["PI_EVENT"] = "PI_EVENT";
|
|
@@ -85,6 +86,7 @@ var init_agentProtocol = __esm({
|
|
|
85
86
|
EHookStage2["RUN_FAILED"] = "RUN_FAILED";
|
|
86
87
|
EHookStage2["RUN_READ"] = "RUN_READ";
|
|
87
88
|
EHookStage2["AFTER_MODEL_CALL"] = "AFTER_MODEL_CALL";
|
|
89
|
+
EHookStage2["MODEL_RESPONSE_RECEIVED"] = "MODEL_RESPONSE_RECEIVED";
|
|
88
90
|
EHookStage2["BEFORE_TOOL_CALL"] = "BEFORE_TOOL_CALL";
|
|
89
91
|
EHookStage2["AFTER_TOOL_CALL"] = "AFTER_TOOL_CALL";
|
|
90
92
|
EHookStage2["TOOL_CALL_FAILED"] = "TOOL_CALL_FAILED";
|
|
@@ -11424,6 +11426,96 @@ var init_mcpNaming = __esm({
|
|
|
11424
11426
|
}
|
|
11425
11427
|
});
|
|
11426
11428
|
|
|
11429
|
+
// ../linkque-agent-runtime/dist/esm/core/cardSemanticSnapshot.js
|
|
11430
|
+
function createCardSemanticSnapshot(receipt, fields) {
|
|
11431
|
+
const groups = receipt.coverage.map((coverage) => {
|
|
11432
|
+
const field = fields.find((f3) => f3.fieldId === coverage.fieldId);
|
|
11433
|
+
const entities = receipt.entities.filter((e2) => e2.fieldId === coverage.fieldId);
|
|
11434
|
+
const echo = field?.presentation?.visibility === "echo";
|
|
11435
|
+
const attributes = echo ? [...new Set(entities.flatMap((e2) => Object.keys(e2.attributes ?? {})))] : [];
|
|
11436
|
+
const hasValue = echo && entities.some((e2) => Object.hasOwn(e2, "value"));
|
|
11437
|
+
const hasLabel = echo && entities.some((e2) => !Object.hasOwn(e2, "value"));
|
|
11438
|
+
const columns = [
|
|
11439
|
+
"\u6761\u76EE\u5F15\u7528",
|
|
11440
|
+
...hasLabel ? [columnLabel(field, field?.presentation?.labelPath, "\u540D\u79F0")] : [],
|
|
11441
|
+
...hasValue ? [short(coverage.label)] : [],
|
|
11442
|
+
...attributes.map((path6) => columnLabel(field, path6, path6))
|
|
11443
|
+
];
|
|
11444
|
+
const rows = entities.map((e2) => [
|
|
11445
|
+
e2.ref,
|
|
11446
|
+
...hasLabel ? [e2.label] : [],
|
|
11447
|
+
...hasValue ? [e2.value ?? null] : [],
|
|
11448
|
+
...attributes.map((path6) => e2.attributes?.[path6] ?? null)
|
|
11449
|
+
]);
|
|
11450
|
+
const total = coverage.itemCount ?? (coverage.present ? 1 : 0);
|
|
11451
|
+
return {
|
|
11452
|
+
field: coverage.fieldId,
|
|
11453
|
+
label: short(coverage.label),
|
|
11454
|
+
present: coverage.present,
|
|
11455
|
+
total,
|
|
11456
|
+
included: rows.length,
|
|
11457
|
+
complete: echo && coverage.present && rows.length === total && !entities.some((e2) => e2.truncated) && !receipt.omissions.some((o) => o.fieldId === coverage.fieldId),
|
|
11458
|
+
columns,
|
|
11459
|
+
rows
|
|
11460
|
+
};
|
|
11461
|
+
});
|
|
11462
|
+
const snapshot = {
|
|
11463
|
+
version: 1,
|
|
11464
|
+
groups,
|
|
11465
|
+
omissions: receipt.omissions.map((o) => ({ ...o }))
|
|
11466
|
+
};
|
|
11467
|
+
while (bytes(snapshot) > MAX_BYTES) {
|
|
11468
|
+
let group;
|
|
11469
|
+
for (let i2 = groups.length - 1; i2 >= 0; i2--) {
|
|
11470
|
+
if (groups[i2].rows.length > 0) {
|
|
11471
|
+
group = groups[i2];
|
|
11472
|
+
break;
|
|
11473
|
+
}
|
|
11474
|
+
}
|
|
11475
|
+
snapshot.truncated = true;
|
|
11476
|
+
if (group) {
|
|
11477
|
+
group.rows.pop();
|
|
11478
|
+
group.included = group.rows.length;
|
|
11479
|
+
group.complete = false;
|
|
11480
|
+
} else if (groups.length) {
|
|
11481
|
+
groups.pop();
|
|
11482
|
+
} else if (snapshot.omissions.length) {
|
|
11483
|
+
snapshot.omissions.pop();
|
|
11484
|
+
} else
|
|
11485
|
+
break;
|
|
11486
|
+
}
|
|
11487
|
+
return snapshot;
|
|
11488
|
+
}
|
|
11489
|
+
function bytes(value) {
|
|
11490
|
+
return Buffer.byteLength(JSON.stringify(value));
|
|
11491
|
+
}
|
|
11492
|
+
function short(value) {
|
|
11493
|
+
return value.length > MAX_LABEL ? `${value.slice(0, MAX_LABEL - 1)}\u2026` : value;
|
|
11494
|
+
}
|
|
11495
|
+
function columnLabel(field, path6, fallback) {
|
|
11496
|
+
if (!field || !path6)
|
|
11497
|
+
return short(fallback);
|
|
11498
|
+
let schema = field.type === "array" ? field.valueSchema.items : field.valueSchema;
|
|
11499
|
+
for (const token of path6.slice(1).split("/").map((t2) => t2.replaceAll("~1", "/").replaceAll("~0", "~"))) {
|
|
11500
|
+
if (!schema || typeof schema !== "object" || Array.isArray(schema))
|
|
11501
|
+
return short(fallback);
|
|
11502
|
+
const properties = schema.properties;
|
|
11503
|
+
if (!properties || typeof properties !== "object" || Array.isArray(properties) || !Object.hasOwn(properties, token))
|
|
11504
|
+
return short(fallback);
|
|
11505
|
+
schema = properties[token];
|
|
11506
|
+
}
|
|
11507
|
+
const title = schema && typeof schema === "object" && !Array.isArray(schema) ? schema.title : void 0;
|
|
11508
|
+
return short(typeof title === "string" && title ? title : fallback);
|
|
11509
|
+
}
|
|
11510
|
+
var MAX_BYTES, MAX_LABEL;
|
|
11511
|
+
var init_cardSemanticSnapshot = __esm({
|
|
11512
|
+
"../linkque-agent-runtime/dist/esm/core/cardSemanticSnapshot.js"() {
|
|
11513
|
+
"use strict";
|
|
11514
|
+
MAX_BYTES = 6e3;
|
|
11515
|
+
MAX_LABEL = 160;
|
|
11516
|
+
}
|
|
11517
|
+
});
|
|
11518
|
+
|
|
11427
11519
|
// ../linkque-agent-runtime/dist/esm/core/cardTools.js
|
|
11428
11520
|
function createCardPresentationToolName(resourceId) {
|
|
11429
11521
|
return stableToolName("a2ui_card", resourceId);
|
|
@@ -11543,6 +11635,7 @@ function createPresentationResult(resource, config2, viewModel) {
|
|
|
11543
11635
|
...createA2UICardPresentationReceiptContent(config2.fields, viewModel),
|
|
11544
11636
|
responsePolicy: { verbatimEcho: "forbidden", hint: "acknowledge" }
|
|
11545
11637
|
};
|
|
11638
|
+
receipt.semanticSnapshot = createCardSemanticSnapshot(receipt, config2.fields);
|
|
11546
11639
|
return {
|
|
11547
11640
|
type: "linkque.presentation-tool-result",
|
|
11548
11641
|
modelText: formatPresentationReceiptForModel(receipt),
|
|
@@ -11562,11 +11655,23 @@ function createPresentationResult(resource, config2, viewModel) {
|
|
|
11562
11655
|
function formatPresentationReceiptForModel(receipt) {
|
|
11563
11656
|
return [
|
|
11564
11657
|
"<a2ui-presentation-receipt>",
|
|
11565
|
-
JSON.stringify(receipt),
|
|
11658
|
+
JSON.stringify(projectPresentationReceiptForModel(receipt)),
|
|
11566
11659
|
"</a2ui-presentation-receipt>",
|
|
11567
|
-
"
|
|
11660
|
+
"\u5361\u7247\u5DF2\u53D1\u51FA\uFF08\u4E0D\u4EE3\u8868\u5BA2\u6237\u7AEF\u5DF2\u6E32\u67D3\uFF09\u3002\u8BED\u4E49\u5FEB\u7167\u6765\u81EA\u6388\u6743\u7684\u6700\u7EC8\u5361\u7247\u6570\u636E\uFF1Bcolumns \u4E0E rows \u6309\u4F4D\u7F6E\u5BF9\u5E94\uFF0Cnull \u8868\u793A\u7F3A\u5931\u6216\u7A7A\u503C\uFF0Ccomplete=false \u65F6\u4E0D\u5F97\u628A\u91C7\u6837\u5F53\u4F5C\u5168\u96C6\u3002\u4E0D\u8981\u7528 Markdown \u91CD\u590D\u5217\u51FA\u6216\u6539\u5199\u5361\u7247\u4E2D\u7684\u6761\u76EE\uFF1B\u53EA\u8865\u5145\u7528\u6237\u5C1A\u672A\u5F97\u5230\u7684\u6BD4\u8F83\u3001\u89E3\u91CA\u6216\u5FC5\u8981\u8FFD\u95EE\uFF0C\u7528\u6237\u660E\u786E\u8981\u6C42\u6587\u5B57\u8868\u683C\u65F6\u53EF\u4EE5\u63D0\u4F9B\u3002\u5FEB\u7167\u672A\u5305\u542B\u7684\u4FE1\u606F\u4FDD\u6301\u672A\u77E5\uFF0C\u6E90\u5DE5\u5177\u7684\u989D\u5916\u4FE1\u606F\u4E0D\u80FD\u79F0\u4E3A\u5361\u7247\u5DF2\u5C55\u793A\u5185\u5BB9\u3002"
|
|
11568
11661
|
].join("\n");
|
|
11569
11662
|
}
|
|
11663
|
+
function projectPresentationReceiptForModel(receipt) {
|
|
11664
|
+
if (!receipt.semanticSnapshot)
|
|
11665
|
+
return receipt;
|
|
11666
|
+
return {
|
|
11667
|
+
version: receipt.version,
|
|
11668
|
+
cardRef: receipt.cardRef,
|
|
11669
|
+
cardRevision: receipt.cardRevision,
|
|
11670
|
+
cardInstanceId: receipt.cardInstanceId,
|
|
11671
|
+
status: receipt.status,
|
|
11672
|
+
semanticSnapshot: receipt.semanticSnapshot
|
|
11673
|
+
};
|
|
11674
|
+
}
|
|
11570
11675
|
function parseCardConfig(resource) {
|
|
11571
11676
|
const parsed = parseA2UICardResourceConfig(resource.config);
|
|
11572
11677
|
if (!parsed.success) {
|
|
@@ -11620,9 +11725,9 @@ function collectA2UISurfaceIdsForLegacyContract(protocol) {
|
|
|
11620
11725
|
function createPresentationDescription(config2) {
|
|
11621
11726
|
return [
|
|
11622
11727
|
config2.description,
|
|
11623
|
-
|
|
11624
|
-
...config2.whenNotToUse ? [
|
|
11625
|
-
"
|
|
11728
|
+
`\u9002\u7528\u573A\u666F\uFF1A${config2.whenToUse}`,
|
|
11729
|
+
...config2.whenNotToUse ? [`\u4E0D\u9002\u7528\u573A\u666F\uFF1A${config2.whenNotToUse}`] : [],
|
|
11730
|
+
"\u53EA\u63D0\u4F9B\u5DF2\u58F0\u660E\u7684\u6807\u8BC6\u6216\u7B5B\u9009\u53C2\u6570\u3002\u6743\u5A01\u4E1A\u52A1\u6570\u636E\u7531\u5E73\u53F0\u89E3\u6790\u83B7\u53D6\u3002"
|
|
11626
11731
|
].join("\n");
|
|
11627
11732
|
}
|
|
11628
11733
|
function cloneJsonObject2(value, label) {
|
|
@@ -11696,6 +11801,7 @@ var init_cardTools = __esm({
|
|
|
11696
11801
|
import_node_crypto2 = require("node:crypto");
|
|
11697
11802
|
init_esm3();
|
|
11698
11803
|
init_mcpNaming();
|
|
11804
|
+
init_cardSemanticSnapshot();
|
|
11699
11805
|
FALLBACK_OBJECT_SCHEMA = {
|
|
11700
11806
|
type: "object",
|
|
11701
11807
|
additionalProperties: true
|
|
@@ -11896,7 +12002,11 @@ var init_mcpProxyTool = __esm({
|
|
|
11896
12002
|
return;
|
|
11897
12003
|
try {
|
|
11898
12004
|
await entry.server.close?.();
|
|
11899
|
-
} catch {
|
|
12005
|
+
} catch (error40) {
|
|
12006
|
+
try {
|
|
12007
|
+
this.debugLog(`[mcp] server ${entry.server.serverName} close failed: ${error40 instanceof Error ? error40.message : "unknown error"}`, EDebugLogScope.MCP);
|
|
12008
|
+
} catch {
|
|
12009
|
+
}
|
|
11900
12010
|
}
|
|
11901
12011
|
}));
|
|
11902
12012
|
}
|
|
@@ -12481,13 +12591,26 @@ var init_hookRegistry = __esm({
|
|
|
12481
12591
|
}
|
|
12482
12592
|
});
|
|
12483
12593
|
|
|
12594
|
+
// ../linkque-agent-runtime/dist/esm/core/logFailure.js
|
|
12595
|
+
function warnLogFailure(stage, error40) {
|
|
12596
|
+
(0, import_node_process.emitWarning)(`[${stage}] errorType=${error40 instanceof Error ? error40.name : typeof error40}`, { code: "LINKQUE_RUNTIME_DIAGNOSTIC_FAILURE" });
|
|
12597
|
+
}
|
|
12598
|
+
var import_node_process;
|
|
12599
|
+
var init_logFailure = __esm({
|
|
12600
|
+
"../linkque-agent-runtime/dist/esm/core/logFailure.js"() {
|
|
12601
|
+
"use strict";
|
|
12602
|
+
import_node_process = require("node:process");
|
|
12603
|
+
}
|
|
12604
|
+
});
|
|
12605
|
+
|
|
12484
12606
|
// ../linkque-agent-runtime/dist/esm/core/hook/hookLog.js
|
|
12485
12607
|
function writeHookLog(debugLog, record3) {
|
|
12486
12608
|
if (!debugLog)
|
|
12487
12609
|
return;
|
|
12488
12610
|
try {
|
|
12489
12611
|
debugLog(JSON.stringify(redactHookLogRecord(record3)), EDebugLogScope.HOOK);
|
|
12490
|
-
} catch {
|
|
12612
|
+
} catch (error40) {
|
|
12613
|
+
warnLogFailure("writeHookLog", error40);
|
|
12491
12614
|
}
|
|
12492
12615
|
}
|
|
12493
12616
|
function redactHookLogRecord(record3) {
|
|
@@ -12507,6 +12630,7 @@ var HOOK_LOG_MESSAGE_MAX_LENGTH;
|
|
|
12507
12630
|
var init_hookLog = __esm({
|
|
12508
12631
|
"../linkque-agent-runtime/dist/esm/core/hook/hookLog.js"() {
|
|
12509
12632
|
"use strict";
|
|
12633
|
+
init_logFailure();
|
|
12510
12634
|
init_types();
|
|
12511
12635
|
HOOK_LOG_MESSAGE_MAX_LENGTH = 200;
|
|
12512
12636
|
}
|
|
@@ -12708,6 +12832,15 @@ var init_hookDispatcher = __esm({
|
|
|
12708
12832
|
stage: EHookStage.RUN_READ,
|
|
12709
12833
|
read: { readAt: subject.readAt ?? now() }
|
|
12710
12834
|
};
|
|
12835
|
+
case EHookStage.MODEL_RESPONSE_RECEIVED: {
|
|
12836
|
+
if (!subject.model)
|
|
12837
|
+
throw new Error("MODEL_RESPONSE_RECEIVED Hook \u7F3A\u5C11\u54CD\u5E94\u4E0A\u4E0B\u6587");
|
|
12838
|
+
return {
|
|
12839
|
+
...base,
|
|
12840
|
+
stage: EHookStage.MODEL_RESPONSE_RECEIVED,
|
|
12841
|
+
model: subject.model
|
|
12842
|
+
};
|
|
12843
|
+
}
|
|
12711
12844
|
case EHookStage.AFTER_MODEL_CALL: {
|
|
12712
12845
|
if (!subject.model || subject.model.messageContent === void 0) {
|
|
12713
12846
|
throw new Error("AFTER_MODEL_CALL Hook \u7F3A\u5C11\u5B8C\u6574 model context");
|
|
@@ -13272,7 +13405,8 @@ function redactHeaders(headers) {
|
|
|
13272
13405
|
pairs.push(`${key}=${redactHeader(key, value)}`);
|
|
13273
13406
|
}
|
|
13274
13407
|
}
|
|
13275
|
-
} catch {
|
|
13408
|
+
} catch (error40) {
|
|
13409
|
+
warnLogFailure("httpLoggingFetch.redactHeaders", error40);
|
|
13276
13410
|
}
|
|
13277
13411
|
return pairs.join(",");
|
|
13278
13412
|
}
|
|
@@ -13309,7 +13443,8 @@ function createHttpLoggingFetch(debugLog, tag, baseFetch = globalThis.fetch) {
|
|
|
13309
13443
|
const cl = resp.headers.get("content-length");
|
|
13310
13444
|
if (cl)
|
|
13311
13445
|
len = cl;
|
|
13312
|
-
} catch {
|
|
13446
|
+
} catch (error40) {
|
|
13447
|
+
warnLogFailure("httpLoggingFetch.contentLength", error40);
|
|
13313
13448
|
}
|
|
13314
13449
|
const correlation = readResponseCorrelationId(resp.headers);
|
|
13315
13450
|
const correlationField = correlation ? ` traceId=${correlation.value} traceHeader=${correlation.name}` : "";
|
|
@@ -13338,14 +13473,16 @@ function readResponseCorrelationId(headers) {
|
|
|
13338
13473
|
};
|
|
13339
13474
|
});
|
|
13340
13475
|
return matched;
|
|
13341
|
-
} catch {
|
|
13476
|
+
} catch (error40) {
|
|
13477
|
+
warnLogFailure("httpLoggingFetch.responseCorrelationId", error40);
|
|
13342
13478
|
}
|
|
13343
13479
|
return void 0;
|
|
13344
13480
|
}
|
|
13345
13481
|
function safeLog(debugLog, line) {
|
|
13346
13482
|
try {
|
|
13347
13483
|
debugLog(line, EDebugLogScope.HTTP);
|
|
13348
|
-
} catch {
|
|
13484
|
+
} catch (error40) {
|
|
13485
|
+
warnLogFailure("httpLoggingFetch.safeLog", error40);
|
|
13349
13486
|
}
|
|
13350
13487
|
}
|
|
13351
13488
|
function nowMs() {
|
|
@@ -13360,6 +13497,7 @@ var init_httpLoggingFetch = __esm({
|
|
|
13360
13497
|
"../linkque-agent-runtime/dist/esm/impl/httpLoggingFetch.js"() {
|
|
13361
13498
|
"use strict";
|
|
13362
13499
|
init_types();
|
|
13500
|
+
init_logFailure();
|
|
13363
13501
|
MAX_BODY_SUMMARY_LEN = 2e3;
|
|
13364
13502
|
REDACTED_HEADER_NAMES = /* @__PURE__ */ new Set([
|
|
13365
13503
|
"authorization",
|
|
@@ -32940,9 +33078,9 @@ function encodeUTF8(str2) {
|
|
|
32940
33078
|
let encoder2;
|
|
32941
33079
|
return (encodeUTF8_ ?? (encoder2 = new globalThis.TextEncoder(), encodeUTF8_ = encoder2.encode.bind(encoder2)))(str2);
|
|
32942
33080
|
}
|
|
32943
|
-
function decodeUTF8(
|
|
33081
|
+
function decodeUTF8(bytes2) {
|
|
32944
33082
|
let decoder;
|
|
32945
|
-
return (decodeUTF8_ ?? (decoder = new globalThis.TextDecoder(), decodeUTF8_ = decoder.decode.bind(decoder)))(
|
|
33083
|
+
return (decodeUTF8_ ?? (decoder = new globalThis.TextDecoder(), decodeUTF8_ = decoder.decode.bind(decoder)))(bytes2);
|
|
32946
33084
|
}
|
|
32947
33085
|
var encodeUTF8_, decodeUTF8_;
|
|
32948
33086
|
var init_bytes = __esm({
|
|
@@ -33322,8 +33460,8 @@ var init_streaming = __esm({
|
|
|
33322
33460
|
const { value, done } = await iter.next();
|
|
33323
33461
|
if (done)
|
|
33324
33462
|
return ctrl.close();
|
|
33325
|
-
const
|
|
33326
|
-
ctrl.enqueue(
|
|
33463
|
+
const bytes2 = encodeUTF8(JSON.stringify(value) + "\n");
|
|
33464
|
+
ctrl.enqueue(bytes2);
|
|
33327
33465
|
} catch (err3) {
|
|
33328
33466
|
ctrl.error(err3);
|
|
33329
33467
|
}
|
|
@@ -42371,9 +42509,9 @@ function encodeUTF82(str2) {
|
|
|
42371
42509
|
let encoder2;
|
|
42372
42510
|
return (encodeUTF8_2 ?? (encoder2 = new globalThis.TextEncoder(), encodeUTF8_2 = encoder2.encode.bind(encoder2)))(str2);
|
|
42373
42511
|
}
|
|
42374
|
-
function decodeUTF82(
|
|
42512
|
+
function decodeUTF82(bytes2) {
|
|
42375
42513
|
let decoder;
|
|
42376
|
-
return (decodeUTF8_2 ?? (decoder = new globalThis.TextDecoder(), decodeUTF8_2 = decoder.decode.bind(decoder)))(
|
|
42514
|
+
return (decodeUTF8_2 ?? (decoder = new globalThis.TextDecoder(), decodeUTF8_2 = decoder.decode.bind(decoder)))(bytes2);
|
|
42377
42515
|
}
|
|
42378
42516
|
var encodeUTF8_2, decodeUTF8_2;
|
|
42379
42517
|
var init_bytes2 = __esm({
|
|
@@ -42759,8 +42897,8 @@ var init_streaming3 = __esm({
|
|
|
42759
42897
|
const { value, done } = await iter.next();
|
|
42760
42898
|
if (done)
|
|
42761
42899
|
return ctrl.close();
|
|
42762
|
-
const
|
|
42763
|
-
ctrl.enqueue(
|
|
42900
|
+
const bytes2 = encodeUTF82(JSON.stringify(value) + "\n");
|
|
42901
|
+
ctrl.enqueue(bytes2);
|
|
42764
42902
|
} catch (err3) {
|
|
42765
42903
|
ctrl.error(err3);
|
|
42766
42904
|
}
|
|
@@ -45477,11 +45615,11 @@ var init_base64 = __esm({
|
|
|
45477
45615
|
} else {
|
|
45478
45616
|
const binaryStr = atob(base64Str);
|
|
45479
45617
|
const len = binaryStr.length;
|
|
45480
|
-
const
|
|
45618
|
+
const bytes2 = new Uint8Array(len);
|
|
45481
45619
|
for (let i2 = 0; i2 < len; i2++) {
|
|
45482
|
-
|
|
45620
|
+
bytes2[i2] = binaryStr.charCodeAt(i2);
|
|
45483
45621
|
}
|
|
45484
|
-
return Array.from(new Float32Array(
|
|
45622
|
+
return Array.from(new Float32Array(bytes2.buffer));
|
|
45485
45623
|
}
|
|
45486
45624
|
};
|
|
45487
45625
|
}
|
|
@@ -56695,14 +56833,14 @@ var require_streams = __commonJS({
|
|
|
56695
56833
|
if (!globalThis.ReadableStream) {
|
|
56696
56834
|
try {
|
|
56697
56835
|
const process2 = require("node:process");
|
|
56698
|
-
const { emitWarning } = process2;
|
|
56836
|
+
const { emitWarning: emitWarning2 } = process2;
|
|
56699
56837
|
try {
|
|
56700
56838
|
process2.emitWarning = () => {
|
|
56701
56839
|
};
|
|
56702
56840
|
Object.assign(globalThis, require("node:stream/web"));
|
|
56703
|
-
process2.emitWarning =
|
|
56841
|
+
process2.emitWarning = emitWarning2;
|
|
56704
56842
|
} catch (error40) {
|
|
56705
|
-
process2.emitWarning =
|
|
56843
|
+
process2.emitWarning = emitWarning2;
|
|
56706
56844
|
throw error40;
|
|
56707
56845
|
}
|
|
56708
56846
|
} catch (error40) {
|
|
@@ -82258,9 +82396,9 @@ function encodeUTF83(str2) {
|
|
|
82258
82396
|
let encoder2;
|
|
82259
82397
|
return (encodeUTF8_3 !== null && encodeUTF8_3 !== void 0 ? encodeUTF8_3 : (encoder2 = new globalThis.TextEncoder(), encodeUTF8_3 = encoder2.encode.bind(encoder2)))(str2);
|
|
82260
82398
|
}
|
|
82261
|
-
function decodeUTF83(
|
|
82399
|
+
function decodeUTF83(bytes2) {
|
|
82262
82400
|
let decoder;
|
|
82263
|
-
return (decodeUTF8_3 !== null && decodeUTF8_3 !== void 0 ? decodeUTF8_3 : (decoder = new globalThis.TextDecoder(), decodeUTF8_3 = decoder.decode.bind(decoder)))(
|
|
82401
|
+
return (decodeUTF8_3 !== null && decodeUTF8_3 !== void 0 ? decodeUTF8_3 : (decoder = new globalThis.TextDecoder(), decodeUTF8_3 = decoder.decode.bind(decoder)))(bytes2);
|
|
82264
82402
|
}
|
|
82265
82403
|
function findNewlineIndex3(buffer, startIndex) {
|
|
82266
82404
|
const newline = 10;
|
|
@@ -89420,8 +89558,8 @@ ${underline}`);
|
|
|
89420
89558
|
const { value, done } = await iter.next();
|
|
89421
89559
|
if (done)
|
|
89422
89560
|
return ctrl.close();
|
|
89423
|
-
const
|
|
89424
|
-
ctrl.enqueue(
|
|
89561
|
+
const bytes2 = encodeUTF83(JSON.stringify(value) + "\n");
|
|
89562
|
+
ctrl.enqueue(bytes2);
|
|
89425
89563
|
} catch (err3) {
|
|
89426
89564
|
ctrl.error(err3);
|
|
89427
89565
|
}
|
|
@@ -189374,7 +189512,8 @@ async function createAgentSession(options) {
|
|
|
189374
189512
|
onDelay: (delayMs) => {
|
|
189375
189513
|
try {
|
|
189376
189514
|
options.debugLog?.(`[llm-throttle] wait ${delayMs}ms before next request`, EDebugLogScope.LLM);
|
|
189377
|
-
} catch {
|
|
189515
|
+
} catch (error40) {
|
|
189516
|
+
warnLogFailure("createAgentSession.throttleLog", error40);
|
|
189378
189517
|
}
|
|
189379
189518
|
}
|
|
189380
189519
|
});
|
|
@@ -189407,7 +189546,8 @@ async function createAgentSession(options) {
|
|
|
189407
189546
|
await prevOnPayload?.(payload, m2);
|
|
189408
189547
|
try {
|
|
189409
189548
|
logSink(formatHttpLogLine("llm", "req", `POST ${baseUrl} model=${m2.id} payload=${summarizeBody(safeStringifyPayload(payload))}`), EDebugLogScope.LLM);
|
|
189410
|
-
} catch {
|
|
189549
|
+
} catch (error40) {
|
|
189550
|
+
warnLogFailure("createAgentSession.requestLog", error40);
|
|
189411
189551
|
}
|
|
189412
189552
|
};
|
|
189413
189553
|
}
|
|
@@ -189424,6 +189564,7 @@ async function createAgentSession(options) {
|
|
|
189424
189564
|
responseHeaders: response.headers
|
|
189425
189565
|
}
|
|
189426
189566
|
};
|
|
189567
|
+
await options.hookRuntime.dispatcher.dispatch(EHookStage.MODEL_RESPONSE_RECEIVED, options.hookRuntime.commonParams, subject);
|
|
189427
189568
|
if (options.hookRuntime.dispatcher.hasMatchingResource(EHookStage.AFTER_MODEL_CALL, subject)) {
|
|
189428
189569
|
gateState = { subject };
|
|
189429
189570
|
}
|
|
@@ -189432,7 +189573,8 @@ async function createAgentSession(options) {
|
|
|
189432
189573
|
try {
|
|
189433
189574
|
const baseUrl = model.baseUrl ?? "<unknown>";
|
|
189434
189575
|
logSink(formatHttpLogLine("llm", "resp", `POST ${baseUrl} model=${m2.id} ${response.status} headers=${redactHeaders(response.headers)}`), EDebugLogScope.LLM);
|
|
189435
|
-
} catch {
|
|
189576
|
+
} catch (error40) {
|
|
189577
|
+
warnLogFailure("createAgentSession.responseLog", error40);
|
|
189436
189578
|
}
|
|
189437
189579
|
}
|
|
189438
189580
|
};
|
|
@@ -189459,7 +189601,8 @@ async function createAgentSession(options) {
|
|
|
189459
189601
|
try {
|
|
189460
189602
|
agent.abort();
|
|
189461
189603
|
agent.reset();
|
|
189462
|
-
} catch {
|
|
189604
|
+
} catch (error40) {
|
|
189605
|
+
warnLogFailure("createAgentSession.dispose", error40);
|
|
189463
189606
|
}
|
|
189464
189607
|
}
|
|
189465
189608
|
}
|
|
@@ -189512,7 +189655,8 @@ function serializeToolResult2(value) {
|
|
|
189512
189655
|
try {
|
|
189513
189656
|
const serialized = JSON.stringify(value);
|
|
189514
189657
|
return serialized === void 0 ? "\u5DE5\u5177\u6267\u884C\u5B8C\u6210\u3002" : serialized;
|
|
189515
|
-
} catch {
|
|
189658
|
+
} catch (error40) {
|
|
189659
|
+
warnLogFailure("createAgentSession.toolResultSerialization", error40);
|
|
189516
189660
|
return "\u5DE5\u5177\u6267\u884C\u5B8C\u6210\u3002";
|
|
189517
189661
|
}
|
|
189518
189662
|
}
|
|
@@ -189523,13 +189667,15 @@ function safeStringifyPayload(payload) {
|
|
|
189523
189667
|
return payload;
|
|
189524
189668
|
try {
|
|
189525
189669
|
return JSON.stringify(payload) ?? "";
|
|
189526
|
-
} catch {
|
|
189670
|
+
} catch (error40) {
|
|
189671
|
+
warnLogFailure("createAgentSession.payloadSerialization", error40);
|
|
189527
189672
|
return "<unserializable>";
|
|
189528
189673
|
}
|
|
189529
189674
|
}
|
|
189530
189675
|
var init_createAgentSession = __esm({
|
|
189531
189676
|
"../linkque-agent-runtime/dist/esm/impl/agent/pi/createAgentSession.js"() {
|
|
189532
189677
|
"use strict";
|
|
189678
|
+
init_logFailure();
|
|
189533
189679
|
init_dist4();
|
|
189534
189680
|
init_dist3();
|
|
189535
189681
|
init_esm();
|
|
@@ -190126,6 +190272,10 @@ var init_followUpQuestionGenerator = __esm({
|
|
|
190126
190272
|
FOLLOW_UP_QUESTION_TOOL_NAME = "submit_follow_up_questions";
|
|
190127
190273
|
FOLLOW_UP_QUESTION_TIMEOUT_MS = 4500;
|
|
190128
190274
|
SYSTEM_PROMPT = `\u6839\u636E\u5BF9\u8BDD\u8C03\u7528 submit_follow_up_questions\uFF0C\u63D0\u4EA4\u7528\u6237\u63A5\u4E0B\u6765\u53EF\u80FD\u63D0\u51FA\u7684\u8FFD\u95EE\uFF1A
|
|
190275
|
+
- \u8FD9\u4E9B\u5EFA\u8BAE\u70B9\u51FB\u540E\u4F1A\u76F4\u63A5\u4F5C\u4E3A\u4E0B\u4E00\u6761\u7528\u6237\u6D88\u606F\u53D1\u9001\u3002\u7AD9\u5728\u5F53\u524D\u6D88\u8D39\u8005/\u670D\u52A1\u4F7F\u7528\u8005\u7684\u89C6\u89D2\u5411\u52A9\u624B\u63D0\u95EE\uFF0C\u4E0D\u8981\u66FF\u5546\u6237\u3001\u5BA2\u670D\u6216\u52A9\u624B\u5411\u7528\u6237\u53D1\u95EE\u3002
|
|
190276
|
+
- \u4FDD\u6301\u5F53\u524D\u7528\u6237\u7684\u8EAB\u4EFD\u548C\u610F\u56FE\uFF1B\u53EA\u6709\u7528\u6237\u660E\u786E\u4EE5\u5546\u6237\u8EAB\u4EFD\u54A8\u8BE2\u7ECF\u8425\u95EE\u9898\u65F6\uFF0C\u624D\u6CBF\u7528\u8BE5\u8EAB\u4EFD\u3002\u4E0D\u8981\u56E0\u4E3A\u52A9\u624B\u7684\u63AA\u8F9E\u6539\u53D8\u7528\u6237\u89D2\u8272\u3002
|
|
190277
|
+
- \u4F8B\u5982\u8D2D\u7968\u573A\u666F\u53EF\u95EE\u201C\u53EF\u4EE5\u9884\u7EA6\u8BB2\u89E3\u670D\u52A1\u5417\uFF1F\u201D\u6216\u201C\u513F\u7AE5\u7968\u600E\u4E48\u4E70\uFF1F\u201D\uFF0C\u4E0D\u8981\u5199\u201C\u9700\u8981\u9884\u7EA6\u8BB2\u89E3\u670D\u52A1\u5417\uFF1F\u201D\u201C\u8BF7\u63D0\u4F9B\u6BCF\u4F4D\u5165\u56ED\u4EBA\u7684\u8EAB\u4EFD\u8BC1\u4FE1\u606F\u201D\u3002
|
|
190278
|
+
- \u52A9\u624B\u6B63\u5728\u8BE2\u95EE\u4EBA\u6570\u3001\u65E5\u671F\u3001\u9884\u7B97\u7B49\u4FE1\u606F\u65F6\uFF0C\u4E0D\u8981\u91CD\u590D\u5B83\u7684\u53CD\u95EE\uFF0C\u4E0D\u8981\u7F16\u9020\u7528\u6237\u5C1A\u672A\u63D0\u4F9B\u7684\u7B54\u6848\u6216\u66FF\u7528\u6237\u627F\u8BFA\u4E0B\u5355\u3001\u652F\u4ED8\uFF1B\u53EF\u5EFA\u8BAE\u76F8\u5173\u89C4\u5219\u95EE\u9898\uFF0C\u6CA1\u6709\u5408\u9002\u95EE\u9898\u5C31\u7559\u7A7A\u3002
|
|
190129
190279
|
- 0\uFF5E3 \u6761\uFF0C\u81EA\u7136\u3001\u76F8\u5173\u3001\u4E0D\u91CD\u590D\uFF1B\u6CA1\u6709\u5408\u9002\u8FFD\u95EE\u65F6\u63D0\u4EA4\u7A7A\u6570\u7EC4\u3002
|
|
190130
190280
|
- \u8DDF\u968F\u6700\u540E\u4E00\u6761\u7528\u6237\u6D88\u606F\u7684\u8BED\u8A00\uFF0C\u6BCF\u6761 JavaScript \u5B57\u7B26\u4E32\u957F\u5EA6\u4E3A 1\uFF5E20\u3002
|
|
190131
190281
|
- \u5386\u53F2\u8FFD\u95EE\u662F\u7CFB\u7EDF\u66FE\u751F\u6210\u7684\u5EFA\u8BAE\uFF0C\u4E0D\u662F\u7528\u6237\u8BF4\u8FC7\u7684\u8BDD\uFF1B\u4EC5\u7528\u4E8E\u7406\u89E3\u8BDD\u9898\u548C\u907F\u514D\u91CD\u590D\u3002
|
|
@@ -190164,8 +190314,10 @@ var init_followUpQuestionGenerator = __esm({
|
|
|
190164
190314
|
tools: [
|
|
190165
190315
|
{
|
|
190166
190316
|
name: FOLLOW_UP_QUESTION_TOOL_NAME,
|
|
190167
|
-
description: "\u63D0\u4EA4\
|
|
190168
|
-
parameters: typebox_exports.Object({
|
|
190317
|
+
description: "\u63D0\u4EA4\u5F53\u524D\u7528\u6237\u63A5\u4E0B\u6765\u5411\u52A9\u624B\u63D0\u51FA\u7684\u95EE\u9898\uFF0C\u9ED8\u8BA4\u91C7\u7528\u6D88\u8D39\u8005\u89C6\u89D2\uFF1B\u70B9\u51FB\u540E\u4F5C\u4E3A\u7528\u6237\u6D88\u606F\u53D1\u9001\uFF0C\u4E0D\u80FD\u662F\u5BA2\u670D\u5411\u6D88\u8D39\u8005\u7684\u53CD\u95EE\u6216\u8D44\u6599\u7D22\u53D6\u3002",
|
|
190318
|
+
parameters: typebox_exports.Object({
|
|
190319
|
+
questions: typebox_exports.Array(typebox_exports.String({ minLength: 1, maxLength: 20 }), { maxItems: 3 })
|
|
190320
|
+
}, { additionalProperties: false })
|
|
190169
190321
|
}
|
|
190170
190322
|
]
|
|
190171
190323
|
};
|
|
@@ -190341,18 +190493,39 @@ var init_pi = __esm({
|
|
|
190341
190493
|
});
|
|
190342
190494
|
|
|
190343
190495
|
// ../linkque-agent-runtime/dist/esm/core/cardRenderMcpServer.js
|
|
190496
|
+
function readAfterCard(args) {
|
|
190497
|
+
if (!args || typeof args !== "object")
|
|
190498
|
+
return void 0;
|
|
190499
|
+
const mode = args.responseMode;
|
|
190500
|
+
if (Object.hasOwn(args, "responseMode") && !["card_only", "supplement", "user_requested_text"].includes(mode))
|
|
190501
|
+
throw new Error("responseMode \u65E0\u6548\uFF0C\u8BF7\u9009\u62E9\u5DF2\u58F0\u660E\u7684\u6A21\u5F0F");
|
|
190502
|
+
if (!Object.hasOwn(args, "afterCard")) {
|
|
190503
|
+
if (mode !== void 0)
|
|
190504
|
+
throw new Error("\u6307\u5B9A responseMode \u65F6\u5FC5\u987B\u63D0\u4F9B afterCard");
|
|
190505
|
+
return void 0;
|
|
190506
|
+
}
|
|
190507
|
+
const value = args.afterCard;
|
|
190508
|
+
if (typeof value !== "string" || value.length > 16e3)
|
|
190509
|
+
throw new Error("afterCard \u5FC5\u987B\u662F\u5B57\u7B26\u4E32\uFF0C\u957F\u5EA6\u4E0D\u80FD\u8D85\u8FC7 16000");
|
|
190510
|
+
if (mode === "card_only" && value.trim() !== "")
|
|
190511
|
+
throw new Error("card_only \u6A21\u5F0F\u4E0B afterCard \u5FC5\u987B\u4E3A\u7A7A\u5B57\u7B26\u4E32\uFF1B\u5361\u7247\u5DF2\u7ECF\u56DE\u7B54\u4E86\u67E5\u8BE2");
|
|
190512
|
+
return value.trim();
|
|
190513
|
+
}
|
|
190344
190514
|
function createCardSourceToolName(resourceId, sourceId) {
|
|
190345
190515
|
return stableToolName("card_source", `${resourceId}_${sourceId}`);
|
|
190346
190516
|
}
|
|
190347
190517
|
function createCardFinishToolName(resourceId) {
|
|
190348
190518
|
return stableToolName("card_finish", resourceId);
|
|
190349
190519
|
}
|
|
190350
|
-
var CardRenderMcpServer;
|
|
190520
|
+
var CARD_SEQUENCE, AFTER_CARD_DESCRIPTION, RESPONSE_MODE_DESCRIPTION, CardRenderMcpServer;
|
|
190351
190521
|
var init_cardRenderMcpServer = __esm({
|
|
190352
190522
|
"../linkque-agent-runtime/dist/esm/core/cardRenderMcpServer.js"() {
|
|
190353
190523
|
"use strict";
|
|
190354
190524
|
init_cardTools();
|
|
190355
190525
|
init_mcpNaming();
|
|
190526
|
+
CARD_SEQUENCE = "\u540C\u4E00\u65F6\u95F4\u53EA\u80FD\u5236\u4F5C\u4E00\u5F20\u5361\u7247\uFF1A\u5148\u5B8C\u6210\u5F53\u524D\u5361\u7247\u7684\u9009\u62E9 \u2192 \u6570\u636E\u6E90\u8C03\u7528 \u2192 \u5C55\u793A\uFF0C\u518D\u9009\u62E9\u4E0B\u4E00\u5F20\u5361\u7247\u3002\u4E0D\u8981\u4EA4\u53C9\u8C03\u7528\u4E0D\u540C\u672A\u5B8C\u6210\u5361\u7247\u7684\u5DE5\u5177\u3002";
|
|
190527
|
+
AFTER_CARD_DESCRIPTION = "\u968F\u5361\u7247\u4E00\u8D77\u5C55\u793A\u7684\u6587\u5B57\u3002card_only \u5FC5\u987B\u4E3A\u7A7A\u5B57\u7B26\u4E32\u3002supplement \u53EA\u5B8C\u6210\u5269\u4F59\u95EE\u9898\uFF0C\u76F4\u63A5\u7ED9\u7ED3\u8BBA\uFF0C\u4E0D\u5148\u6982\u8FF0\u5404\u4E2A\u5019\u9009\uFF1A\u4EF7\u683C\u603B\u7ED3\u5E94\u8BF4\u8303\u56F4/\u96C6\u4E2D\u533A\u95F4/\u53D6\u820D\uFF0C\u4E0D\u6309\u9152\u5E97\u5206\u522B\u5199\u8BC4\u4EF7\uFF1B\u8FFD\u95EE\u53EA\u95EE\u6240\u9700\u6761\u4EF6\uFF0C\u4E0D\u5148\u4ECB\u7ECD\u5168\u90E8\u9152\u5E97\uFF1B\u9009\u4E00\u5BB6\u53EA\u7ED9\u8BE5\u9879\u53CA\u7406\u7531\u3002\u5141\u8BB8\u5FC5\u8981\u5F15\u7528\u4E2A\u522B\u540D\u79F0\u6570\u503C\u3002\u4E0D\u8981\u4ECE\u8BC4\u5206\u63A8\u65AD\u536B\u751F\u3001\u4ECE\u8FD1\u5730\u94C1\u63A8\u65AD\u7279\u5B9A\u666F\u70B9\u4FBF\u5229\u6027\uFF0C\u672A\u77E5\u4FDD\u6301\u672A\u77E5\u3002user_requested_text \u53EF\u63D0\u4F9B\u7528\u6237\u660E\u786E\u8981\u6C42\u7684\u5B8C\u6574\u6587\u5B57/\u8868\u683C\u3002\u591A\u5361\u7247\u65F6\u586B\u5199\u7D27\u63A5\u5F53\u524D\u5361\u7247\u7684\u8BF4\u660E\uFF0C\u7136\u540E\u7EE7\u7EED\u8C03\u7528\u4E0B\u4E00\u5F20\u5361\u7247\u5DE5\u5177\u3002\u6B64\u5904\u6587\u5B57\u4F1A\u76F4\u63A5\u5C55\u793A\uFF0Cfinish \u6210\u529F\u540E\u4E0D\u8981\u53E6\u5199\u4E00\u904D\uFF1B\u5361\u7247\u5931\u8D25\u65F6\u4ECD\u53EF\u6B63\u5E38\u6587\u5B57\u56DE\u7B54\u3002";
|
|
190528
|
+
RESPONSE_MODE_DESCRIPTION = "\u6309\u7528\u6237\u4EFB\u52A1\u9009\u62E9\uFF1Acard_only=\u67E5\u8BE2/\u5C55\u793A\u7ED3\u679C/\u6CDB\u6CDB\u63A8\u8350\u5019\u9009\uFF0C\u5361\u7247\u5DF2\u7ECF\u5B8C\u6210\u4EFB\u52A1\uFF0C\u4E0D\u4E3B\u52A8\u65B0\u589E\u89E3\u91CA\u6216\u8FFD\u95EE\uFF1Bsupplement=\u7528\u6237\u8FD8\u8981\u6C42\u9009\u4E00\u5BB6\u53CA\u7406\u7531\u3001\u603B\u7ED3\u53D6\u820D\u3001\u8865\u5145\u653F\u7B56\u3001\u9884\u8BA2\u6240\u9700\u4FE1\u606F\uFF0C\u6216\u67E5\u8BE2\u4E3A\u7A7A\u9700\u8BF4\u660E\uFF1Buser_requested_text=\u7528\u6237\u660E\u786E\u8981\u6C42\u53E6\u7ED9\u6587\u5B57/\u53EF\u590D\u5236\u8868\u683C\u3002\u793A\u4F8B\uFF1A\u201C\u63A8\u8350\u676D\u5DDE\u9152\u5E97\u201D\u2192card_only\uFF1B\u201C\u63A8\u8350\u676D\u5DDE\u9152\u5E97\uFF0C\u9009\u4E00\u5BB6\u9002\u5408\u5E26\u5B69\u5B50\u7684\u201D\u2192supplement\uFF1B\u201C\u65E2\u8981\u5361\u7247\u4E5F\u8981\u5B8C\u6574\u8868\u683C\u201D\u2192user_requested_text\u3002";
|
|
190356
190529
|
CardRenderMcpServer = class {
|
|
190357
190530
|
resources;
|
|
190358
190531
|
registry;
|
|
@@ -190374,6 +190547,8 @@ var init_cardRenderMcpServer = __esm({
|
|
|
190374
190547
|
toolByName = /* @__PURE__ */ new Map();
|
|
190375
190548
|
activeCardId;
|
|
190376
190549
|
invalidCards = [];
|
|
190550
|
+
/** 只信任本实例实际执行成功的结果,普通 MCP JSON 无权控制文字输出。 */
|
|
190551
|
+
companions = /* @__PURE__ */ new WeakMap();
|
|
190377
190552
|
/** 本轮被隔离的坏卡,仅供宿主诊断,不影响其它卡片注册。 */
|
|
190378
190553
|
getInvalidCards() {
|
|
190379
190554
|
return this.invalidCards;
|
|
@@ -190414,7 +190589,7 @@ var init_cardRenderMcpServer = __esm({
|
|
|
190414
190589
|
resourceId: resource.resourceId,
|
|
190415
190590
|
label: config2.displayName,
|
|
190416
190591
|
description: `${createPresentationDescription(config2)}
|
|
190417
|
-
|
|
190592
|
+
\u5148\u9009\u62E9\u6B64\u5361\u7247\uFF0C\u518D\u4F9D\u6B21\u8C03\u7528\u5B83\u7684 card_source \u6570\u636E\u6E90\u5DE5\u5177\u548C card_finish \u5C55\u793A\u5DE5\u5177\u3002${CARD_SEQUENCE}`,
|
|
190418
190593
|
inputSchema: {
|
|
190419
190594
|
type: "object",
|
|
190420
190595
|
properties: {},
|
|
@@ -190453,18 +190628,18 @@ Select this card first, then call its card_source tools and card_finish tool.`,
|
|
|
190453
190628
|
modelName: sourceToolName,
|
|
190454
190629
|
resourceId: resource.resourceId,
|
|
190455
190630
|
label: source.purpose,
|
|
190456
|
-
description:
|
|
190631
|
+
description: `\u9009\u62E9 ${name} \u540E\u4F7F\u7528\u3002${source.purpose}\u3002\u6839\u636E\u5BF9\u8BDD\u548C\u5DF2\u6709\u6570\u636E\u6E90\u7ED3\u679C\u786E\u5B9A\u6240\u6709 MCP \u53C2\u6570\u3002${CARD_SEQUENCE}`,
|
|
190457
190632
|
inputSchema: normalizeMcpInputSchema(discoveredHandle?.inputSchema),
|
|
190458
190633
|
outputSchema: discoveredHandle?.outputSchema ?? source.outputSchema,
|
|
190459
190634
|
execute: async (args, signal) => {
|
|
190460
190635
|
if (!state2.selected || this.activeCardId !== resource.resourceId)
|
|
190461
|
-
throw new Error(
|
|
190636
|
+
throw new Error(`\u8C03\u7528\u6570\u636E\u6E90\u524D\uFF0C\u8BF7\u5148\u9009\u62E9\u5361\u7247 ${name}`);
|
|
190462
190637
|
const missingDependencies = (source.dependsOn ?? []).filter((dependency) => !state2.results.has(dependency));
|
|
190463
190638
|
if (missingDependencies.length)
|
|
190464
|
-
throw new Error(
|
|
190639
|
+
throw new Error(`\u6570\u636E\u6E90 ${source.sourceId} \u9700\u8981\u5148\u5B8C\u6210\u4EE5\u4E0B\u4F9D\u8D56\uFF1A${missingDependencies.join(", ")}`);
|
|
190465
190640
|
const handle = discoveredHandle ?? await this.registry.resolve(source.mcpResourceId, source.toolName, signal);
|
|
190466
190641
|
if (!handle)
|
|
190467
|
-
throw new Error(`MCP
|
|
190642
|
+
throw new Error(`MCP \u5DE5\u5177 ${source.mcpResourceId}/${source.toolName} \u5F53\u524D\u4E0D\u53EF\u7528`);
|
|
190468
190643
|
const result = await handle.execute(args, signal);
|
|
190469
190644
|
const structured = readStructuredContent(result);
|
|
190470
190645
|
if (structured === void 0) {
|
|
@@ -190491,16 +190666,36 @@ Select this card first, then call its card_source tools and card_finish tool.`,
|
|
|
190491
190666
|
modelName: finishName,
|
|
190492
190667
|
resourceId: resource.resourceId,
|
|
190493
190668
|
label: `\u5C55\u793A${config2.displayName}`,
|
|
190494
|
-
description:
|
|
190669
|
+
description: `\u6240\u6709\u5FC5\u9700\u7684 card_source \u6570\u636E\u6E90\u5DE5\u5177\u6210\u529F\u540E\uFF0C\u5B8C\u6210\u5E76\u5C55\u793A${config2.displayName}\u3002${CARD_SEQUENCE}
|
|
190670
|
+
${AFTER_CARD_DESCRIPTION}`,
|
|
190495
190671
|
inputSchema: {
|
|
190496
190672
|
type: "object",
|
|
190497
|
-
|
|
190673
|
+
required: ["responseMode", "afterCard"],
|
|
190674
|
+
properties: {
|
|
190675
|
+
responseMode: {
|
|
190676
|
+
type: "string",
|
|
190677
|
+
enum: ["card_only", "supplement", "user_requested_text"],
|
|
190678
|
+
description: RESPONSE_MODE_DESCRIPTION
|
|
190679
|
+
},
|
|
190680
|
+
afterCard: {
|
|
190681
|
+
type: "string",
|
|
190682
|
+
maxLength: 16e3,
|
|
190683
|
+
description: AFTER_CARD_DESCRIPTION
|
|
190684
|
+
}
|
|
190685
|
+
},
|
|
190498
190686
|
additionalProperties: false
|
|
190499
190687
|
},
|
|
190500
|
-
execute: async (
|
|
190688
|
+
execute: async (args, signal) => {
|
|
190501
190689
|
if (!state2.selected || this.activeCardId !== resource.resourceId)
|
|
190502
|
-
throw new Error(
|
|
190690
|
+
throw new Error(`\u5B8C\u6210\u5C55\u793A\u524D\uFF0C\u8BF7\u5148\u9009\u62E9\u5361\u7247 ${name}`);
|
|
190691
|
+
const afterCard = readAfterCard(args);
|
|
190503
190692
|
const result = await executeCardPresentationFromSources(resource, this.runtimeContext, state2.results, signal);
|
|
190693
|
+
if (afterCard !== void 0) {
|
|
190694
|
+
this.companions.set(result, afterCard);
|
|
190695
|
+
result.modelText += `
|
|
190696
|
+
<a2ui-companion-delivery>${JSON.stringify({ afterCard })}</a2ui-companion-delivery>
|
|
190697
|
+
\u5361\u7247\u548C\u4E0A\u8FF0\u4F34\u968F\u6587\u5B57\u5DF2\u4F5C\u4E3A\u56DE\u7B54\u53D1\u51FA\u3002\u65E0\u9700\u518D\u6B21\u8F93\u51FA\u6587\u5B57\uFF1B\u82E5\u8FD8\u6709\u5176\u4ED6\u4EFB\u52A1\uFF0C\u7EE7\u7EED\u8C03\u7528\u5DE5\u5177\u3002`;
|
|
190698
|
+
}
|
|
190504
190699
|
state2.selected = false;
|
|
190505
190700
|
this.activeCardId = void 0;
|
|
190506
190701
|
return result;
|
|
@@ -190531,6 +190726,32 @@ Select this card first, then call its card_source tools and card_finish tool.`,
|
|
|
190531
190726
|
this.activeCardId = void 0;
|
|
190532
190727
|
this.states.clear();
|
|
190533
190728
|
this.toolByName.clear();
|
|
190729
|
+
this.companions = /* @__PURE__ */ new WeakMap();
|
|
190730
|
+
}
|
|
190731
|
+
/** 卡片与伴随文字的共享输出边界,不参与模型循环或工具调度。 */
|
|
190732
|
+
async *projectConversation(events) {
|
|
190733
|
+
const pending = /* @__PURE__ */ new WeakMap();
|
|
190734
|
+
let cardOwnsText = false;
|
|
190735
|
+
for await (const event of events) {
|
|
190736
|
+
if (event.type === "tool_start" || event.type === "error" || event.type === "done")
|
|
190737
|
+
cardOwnsText = false;
|
|
190738
|
+
if (event.type === "tool_end" && !event.isError) {
|
|
190739
|
+
const details = event.result && typeof event.result === "object" && "details" in event.result ? event.result.details : void 0;
|
|
190740
|
+
if (details && this.companions.has(details)) {
|
|
190741
|
+
pending.set(details.card, this.companions.get(details));
|
|
190742
|
+
}
|
|
190743
|
+
}
|
|
190744
|
+
if (event.type === "delta" && cardOwnsText)
|
|
190745
|
+
continue;
|
|
190746
|
+
yield event;
|
|
190747
|
+
if (event.type === "a2ui_card" && pending.has(event)) {
|
|
190748
|
+
const text2 = pending.get(event);
|
|
190749
|
+
pending.delete(event);
|
|
190750
|
+
cardOwnsText = true;
|
|
190751
|
+
if (text2)
|
|
190752
|
+
yield { type: "delta", content: text2 };
|
|
190753
|
+
}
|
|
190754
|
+
}
|
|
190534
190755
|
}
|
|
190535
190756
|
};
|
|
190536
190757
|
}
|
|
@@ -191176,7 +191397,7 @@ var init_agentRuntime = __esm({
|
|
|
191176
191397
|
});
|
|
191177
191398
|
};
|
|
191178
191399
|
try {
|
|
191179
|
-
for await (const ev of this.agentLoop.run(agentReq)) {
|
|
191400
|
+
for await (const ev of cardServer.projectConversation(this.agentLoop.run(agentReq))) {
|
|
191180
191401
|
if (ev.type === "delta")
|
|
191181
191402
|
assistantText += ev.content;
|
|
191182
191403
|
if (ev.type === "tool_end" && !ev.isError) {
|
|
@@ -191196,7 +191417,10 @@ var init_agentRuntime = __esm({
|
|
|
191196
191417
|
...presentationReceipts.map((receipt) => ({
|
|
191197
191418
|
role: "tool",
|
|
191198
191419
|
name: "a2ui_presentation_receipt",
|
|
191199
|
-
content: {
|
|
191420
|
+
content: {
|
|
191421
|
+
type: "a2ui.presentation-receipt",
|
|
191422
|
+
receipt: projectPresentationReceiptForModel(receipt)
|
|
191423
|
+
}
|
|
191200
191424
|
})),
|
|
191201
191425
|
{ role: "assistant", content: assistantText }
|
|
191202
191426
|
];
|
|
@@ -191401,16 +191625,16 @@ async function boundedBody(response, max2) {
|
|
|
191401
191625
|
}
|
|
191402
191626
|
}
|
|
191403
191627
|
function validate(data, mediaType) {
|
|
191404
|
-
if (data.length > Math.ceil(
|
|
191628
|
+
if (data.length > Math.ceil(MAX_BYTES2 / 3) * 4)
|
|
191405
191629
|
imageError("IMAGE_TOO_LARGE");
|
|
191406
191630
|
if (!/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/.test(data))
|
|
191407
191631
|
imageError("IMAGE_DATA_INVALID");
|
|
191408
|
-
const
|
|
191409
|
-
if (
|
|
191632
|
+
const bytes2 = Buffer.from(data, "base64");
|
|
191633
|
+
if (bytes2.length > MAX_BYTES2)
|
|
191410
191634
|
imageError("IMAGE_TOO_LARGE");
|
|
191411
|
-
if (
|
|
191635
|
+
if (bytes2.toString("base64") !== data || !bytes2.length)
|
|
191412
191636
|
imageError("IMAGE_DATA_INVALID");
|
|
191413
|
-
const magic = mediaType === "image/png" ?
|
|
191637
|
+
const magic = mediaType === "image/png" ? bytes2.subarray(0, 8).equals(Buffer.from([137, 80, 78, 71, 13, 10, 26, 10])) : mediaType === "image/jpeg" ? bytes2[0] === 255 && bytes2[1] === 216 && bytes2[2] === 255 : mediaType === "image/webp" && bytes2.subarray(0, 4).toString() === "RIFF" && bytes2.subarray(8, 12).toString() === "WEBP";
|
|
191414
191638
|
if (!magic)
|
|
191415
191639
|
imageError("IMAGE_MEDIA_INVALID");
|
|
191416
191640
|
return { mediaType, data };
|
|
@@ -191418,7 +191642,7 @@ function validate(data, mediaType) {
|
|
|
191418
191642
|
async function resolveImage(image, fetchImpl, rules, signal) {
|
|
191419
191643
|
signal.throwIfAborted();
|
|
191420
191644
|
if (image.dataUrl) {
|
|
191421
|
-
if (image.dataUrl.length > Math.ceil(
|
|
191645
|
+
if (image.dataUrl.length > Math.ceil(MAX_BYTES2 / 3) * 4 + 32)
|
|
191422
191646
|
imageError("IMAGE_TOO_LARGE");
|
|
191423
191647
|
const match2 = /^data:(image\/(?:png|jpeg|webp));base64,([A-Za-z0-9+/=]+)$/.exec(image.dataUrl);
|
|
191424
191648
|
if (!match2 || match2[1] !== image.mimeType)
|
|
@@ -191447,9 +191671,9 @@ async function resolveImage(image, fetchImpl, rules, signal) {
|
|
|
191447
191671
|
await response.body?.cancel();
|
|
191448
191672
|
imageError("IMAGE_MEDIA_INVALID");
|
|
191449
191673
|
}
|
|
191450
|
-
return validate(Buffer.from(await boundedBody(response,
|
|
191674
|
+
return validate(Buffer.from(await boundedBody(response, MAX_BYTES2)).toString("base64"), mediaType);
|
|
191451
191675
|
}
|
|
191452
|
-
var DEFAULT_IMAGE_URL_RULES,
|
|
191676
|
+
var DEFAULT_IMAGE_URL_RULES, MAX_BYTES2;
|
|
191453
191677
|
var init_io = __esm({
|
|
191454
191678
|
"../linkque-agent-runtime/dist/esm/impl/plugin/imageUnderstanding/io.js"() {
|
|
191455
191679
|
"use strict";
|
|
@@ -191458,7 +191682,7 @@ var init_io = __esm({
|
|
|
191458
191682
|
{ host: "masspre.alipay.com", pathPrefix: "/linkque/afts/img/" },
|
|
191459
191683
|
{ host: "mdn.alipayobjects.com", pathPrefix: "/linkque/afts/img/" }
|
|
191460
191684
|
];
|
|
191461
|
-
|
|
191685
|
+
MAX_BYTES2 = 2 * 1024 * 1024;
|
|
191462
191686
|
}
|
|
191463
191687
|
});
|
|
191464
191688
|
|
|
@@ -192039,6 +192263,61 @@ function failure(code, message, retryable) {
|
|
|
192039
192263
|
return { ok: false, error: { code, message, retryable } };
|
|
192040
192264
|
}
|
|
192041
192265
|
|
|
192266
|
+
// ../linkque-agent-runtime/dist/esm/core/cardActionDiagnostics.js
|
|
192267
|
+
init_types();
|
|
192268
|
+
var CardActionDiagnostics = class {
|
|
192269
|
+
sink;
|
|
192270
|
+
layer;
|
|
192271
|
+
stage = "validate";
|
|
192272
|
+
context;
|
|
192273
|
+
debugLog;
|
|
192274
|
+
startedAt = performance.now();
|
|
192275
|
+
constructor(sink, context2, layer = "runtime") {
|
|
192276
|
+
this.sink = sink;
|
|
192277
|
+
this.layer = layer;
|
|
192278
|
+
this.context = { ...context2 };
|
|
192279
|
+
if (sink) {
|
|
192280
|
+
this.debugLog = (line, scope) => {
|
|
192281
|
+
this.write("diagnostic", { message: line }, scope);
|
|
192282
|
+
};
|
|
192283
|
+
}
|
|
192284
|
+
}
|
|
192285
|
+
write(event, fields = {}, scope = EDebugLogScope.A2UI_ACTION) {
|
|
192286
|
+
if (!this.sink)
|
|
192287
|
+
return;
|
|
192288
|
+
try {
|
|
192289
|
+
const record3 = { ...this.context, ...fields };
|
|
192290
|
+
if (record3.message)
|
|
192291
|
+
record3.message = sanitizeDiagnosticText(record3.message);
|
|
192292
|
+
if (record3.errorName)
|
|
192293
|
+
record3.errorName = sanitizeDiagnosticText(record3.errorName);
|
|
192294
|
+
this.sink(JSON.stringify({
|
|
192295
|
+
operation: "a2uiAction.execute",
|
|
192296
|
+
layer: this.layer,
|
|
192297
|
+
event,
|
|
192298
|
+
stage: this.stage,
|
|
192299
|
+
...record3,
|
|
192300
|
+
costMs: Math.max(0, Math.round(performance.now() - this.startedAt))
|
|
192301
|
+
}), scope);
|
|
192302
|
+
} catch {
|
|
192303
|
+
}
|
|
192304
|
+
}
|
|
192305
|
+
error(event, error40) {
|
|
192306
|
+
if (!this.sink)
|
|
192307
|
+
return;
|
|
192308
|
+
try {
|
|
192309
|
+
this.write(event, {
|
|
192310
|
+
errorName: error40 instanceof Error ? error40.name : typeof error40,
|
|
192311
|
+
message: error40 instanceof Error ? error40.message : typeof error40 === "string" ? error40 : "\u975E\u6807\u51C6\u5F02\u5E38"
|
|
192312
|
+
});
|
|
192313
|
+
} catch {
|
|
192314
|
+
}
|
|
192315
|
+
}
|
|
192316
|
+
};
|
|
192317
|
+
function sanitizeDiagnosticText(value) {
|
|
192318
|
+
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);
|
|
192319
|
+
}
|
|
192320
|
+
|
|
192042
192321
|
// ../linkque-agent-runtime/dist/esm/core/cardActionExecutor.js
|
|
192043
192322
|
init_esm3();
|
|
192044
192323
|
init_esm2();
|
|
@@ -192046,12 +192325,33 @@ init_esm();
|
|
|
192046
192325
|
init_mcpAggregator();
|
|
192047
192326
|
init_mcpProxyTool();
|
|
192048
192327
|
async function executeCardAction(input) {
|
|
192328
|
+
const diagnostics = new CardActionDiagnostics(input.debugLog, {
|
|
192329
|
+
agentId: input.protocol.agentId,
|
|
192330
|
+
threadId: input.runtimeContext.threadId
|
|
192331
|
+
});
|
|
192332
|
+
diagnostics.write("started");
|
|
192333
|
+
try {
|
|
192334
|
+
const response = await executeCardActionInternal(input, diagnostics);
|
|
192335
|
+
diagnostics.write(response.ok ? "completed" : "failed", response.ok ? {} : { code: response.error.code, retryable: response.error.retryable });
|
|
192336
|
+
return response;
|
|
192337
|
+
} catch (error40) {
|
|
192338
|
+
diagnostics.error("failed", error40);
|
|
192339
|
+
throw error40;
|
|
192340
|
+
}
|
|
192341
|
+
}
|
|
192342
|
+
async function executeCardActionInternal(input, diagnostics) {
|
|
192049
192343
|
let request;
|
|
192050
192344
|
try {
|
|
192051
192345
|
request = parseA2UIActionExecuteRequest(input.request);
|
|
192052
192346
|
} catch (error40) {
|
|
192053
192347
|
return failure2("INVALID_INPUT", errorMessage(error40, "\u652F\u4ED8\u52A8\u4F5C\u8BF7\u6C42\u65E0\u6548"), false);
|
|
192054
192348
|
}
|
|
192349
|
+
Object.assign(diagnostics.context, {
|
|
192350
|
+
invocationId: request.invocationId,
|
|
192351
|
+
actionId: request.actionId,
|
|
192352
|
+
cardRef: request.source.cardRef,
|
|
192353
|
+
cardRevision: request.source.cardRevision
|
|
192354
|
+
});
|
|
192055
192355
|
if (request.agentId !== input.protocol.agentId) {
|
|
192056
192356
|
return failure2("AGENT_MISMATCH", "\u652F\u4ED8\u52A8\u4F5C\u4E0E\u5F53\u524D Agent \u4E0D\u5339\u914D", false);
|
|
192057
192357
|
}
|
|
@@ -192061,24 +192361,38 @@ async function executeCardAction(input) {
|
|
|
192061
192361
|
if (!input.runtimeContext.userId.trim()) {
|
|
192062
192362
|
return failure2("AUTH_REQUIRED", "\u652F\u4ED8\u52A8\u4F5C\u7F3A\u5C11\u53EF\u4FE1\u7528\u6237\u8EAB\u4EFD", false);
|
|
192063
192363
|
}
|
|
192364
|
+
diagnostics.write("validated");
|
|
192365
|
+
diagnostics.stage = "binding";
|
|
192064
192366
|
const resolved = resolvePaymentBinding(input.protocol, request.source, request.actionId);
|
|
192065
192367
|
if (!resolved.ok)
|
|
192066
192368
|
return resolved.response;
|
|
192067
|
-
|
|
192369
|
+
Object.assign(diagnostics.context, {
|
|
192370
|
+
mcpResourceId: resolved.binding.createTrade.mcpResourceId,
|
|
192371
|
+
toolName: resolved.binding.createTrade.toolName
|
|
192372
|
+
});
|
|
192373
|
+
diagnostics.write("binding_resolved");
|
|
192374
|
+
diagnostics.stage = "tool_resolve";
|
|
192375
|
+
const registry2 = createRegistry(input.protocol, input.mcpServerProvider, diagnostics.debugLog);
|
|
192068
192376
|
try {
|
|
192069
192377
|
const tool = await registry2.resolve(resolved.binding.createTrade.mcpResourceId, resolved.binding.createTrade.toolName, input.signal);
|
|
192070
192378
|
if (!tool) {
|
|
192071
192379
|
return failure2("TOOL_NOT_ALLOWED", "\u521B\u5EFA\u4EA4\u6613 MCP Tool \u4E0D\u5B58\u5728\u6216\u672A\u6388\u6743", false);
|
|
192072
192380
|
}
|
|
192381
|
+
diagnostics.stage = "tool_input";
|
|
192073
192382
|
const args = createToolInput(resolved.binding.createTrade.inputBindings, request.actionContext, input.runtimeContext);
|
|
192074
192383
|
if (!args)
|
|
192075
192384
|
return failure2("INVALID_INPUT", "\u65E0\u6CD5\u751F\u6210\u521B\u5EFA\u4EA4\u6613 MCP \u5165\u53C2", false);
|
|
192076
192385
|
let result;
|
|
192386
|
+
diagnostics.stage = "tool_execute";
|
|
192387
|
+
diagnostics.write("tool_started");
|
|
192077
192388
|
try {
|
|
192078
192389
|
result = await tool.execute(args, input.signal);
|
|
192079
|
-
|
|
192390
|
+
diagnostics.write("tool_completed");
|
|
192391
|
+
} catch (error40) {
|
|
192392
|
+
diagnostics.error("tool_failed", error40);
|
|
192080
192393
|
return failure2("EXECUTION_FAILED", "\u521B\u5EFA\u4EA4\u6613\u5931\u8D25\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5", true);
|
|
192081
192394
|
}
|
|
192395
|
+
diagnostics.stage = "tool_output";
|
|
192082
192396
|
const structured = readStructuredContent3(result);
|
|
192083
192397
|
const tradeNO = readJsonPointer(structured, resolved.binding.createTrade.tradeNoPath);
|
|
192084
192398
|
if (typeof tradeNO !== "string" || !tradeNO.trim() || tradeNO.length > 64) {
|
|
@@ -192090,7 +192404,10 @@ async function executeCardAction(input) {
|
|
|
192090
192404
|
result: { kind: "payment", tradeNO }
|
|
192091
192405
|
};
|
|
192092
192406
|
} finally {
|
|
192407
|
+
const stage = diagnostics.stage;
|
|
192408
|
+
diagnostics.stage = "cleanup";
|
|
192093
192409
|
await registry2.closeAll();
|
|
192410
|
+
diagnostics.stage = stage;
|
|
192094
192411
|
}
|
|
192095
192412
|
}
|
|
192096
192413
|
function resolvePaymentBinding(protocol, source, actionId) {
|
|
@@ -192120,9 +192437,9 @@ function resolvePaymentBinding(protocol, source, actionId) {
|
|
|
192120
192437
|
}
|
|
192121
192438
|
return { ok: true, binding };
|
|
192122
192439
|
}
|
|
192123
|
-
function createRegistry(protocol, provider) {
|
|
192440
|
+
function createRegistry(protocol, provider, debugLog) {
|
|
192124
192441
|
const resources = protocol.agent.resources.filter((resource) => resource.resourceType === EResourceType.MCP || resource.resourceType === EResourceType.MCP_TOOL);
|
|
192125
|
-
return new McpProxyTool(provider, aggregateMcpServers(resources, protocol.agentId));
|
|
192442
|
+
return new McpProxyTool(provider, aggregateMcpServers(resources, protocol.agentId), { debugLog });
|
|
192126
192443
|
}
|
|
192127
192444
|
function createToolInput(bindings, actionContext, runtimeContext, tradeNO, callback) {
|
|
192128
192445
|
const result = {};
|
|
@@ -197363,6 +197680,8 @@ function applyArgsMappingRules(toolName, args, rules) {
|
|
|
197363
197680
|
init_esm();
|
|
197364
197681
|
|
|
197365
197682
|
// ../linkque-agent-runtime/dist/esm/impl/mcp/alipay/remoteGatewayMcpServer.js
|
|
197683
|
+
init_types();
|
|
197684
|
+
init_logFailure();
|
|
197366
197685
|
var defaultCreateSigner = (config2, getAuthorizationHeader, debugLog) => new RemoteSignatureSigner({
|
|
197367
197686
|
agentId: config2.agentId,
|
|
197368
197687
|
signEndpoint: config2.signEndpoint,
|
|
@@ -197398,13 +197717,42 @@ var RemoteGatewayMcpServerProvider = class {
|
|
|
197398
197717
|
});
|
|
197399
197718
|
const serverName = resource.config.serverName ?? resource.resourceId;
|
|
197400
197719
|
const argsMappingRules = resource.config.argsMappingRules ?? [];
|
|
197720
|
+
let requestSequence = 0;
|
|
197721
|
+
const request = async (method, params, invoke) => {
|
|
197722
|
+
const requestId = ++requestSequence;
|
|
197723
|
+
const log = (phase, payload) => {
|
|
197724
|
+
if (!this.debugLog)
|
|
197725
|
+
return;
|
|
197726
|
+
try {
|
|
197727
|
+
this.debugLog(`[mcp-client] ${JSON.stringify({ serverName, resourceId: resource.resourceId, requestId, method, phase, payload })}`, EDebugLogScope.MCP);
|
|
197728
|
+
} catch (error40) {
|
|
197729
|
+
warnLogFailure("remoteGatewayMcpServer.log", error40);
|
|
197730
|
+
}
|
|
197731
|
+
};
|
|
197732
|
+
log("request", params);
|
|
197733
|
+
try {
|
|
197734
|
+
const result = await invoke();
|
|
197735
|
+
log("response", result);
|
|
197736
|
+
return result;
|
|
197737
|
+
} catch (error40) {
|
|
197738
|
+
log("error", error40 instanceof Error ? { name: error40.name, message: error40.message } : error40);
|
|
197739
|
+
throw error40;
|
|
197740
|
+
}
|
|
197741
|
+
};
|
|
197742
|
+
const loggedClient = {
|
|
197743
|
+
listTools: () => request("tools/list", {}, () => client.listTools()),
|
|
197744
|
+
callTool: (params) => request("tools/call", params, () => client.callTool(params))
|
|
197745
|
+
};
|
|
197401
197746
|
return {
|
|
197402
197747
|
resourceId: resource.resourceId,
|
|
197403
197748
|
serverName,
|
|
197404
|
-
listTools: () => listToolsFromClient(
|
|
197749
|
+
listTools: () => listToolsFromClient(loggedClient, resource.resourceId),
|
|
197405
197750
|
callTool: (name, args) => {
|
|
197406
197751
|
const mapped = applyArgsMappingRules(name, args, argsMappingRules);
|
|
197407
|
-
return
|
|
197752
|
+
return loggedClient.callTool({
|
|
197753
|
+
name,
|
|
197754
|
+
arguments: mapped ?? {}
|
|
197755
|
+
});
|
|
197408
197756
|
},
|
|
197409
197757
|
close: async () => {
|
|
197410
197758
|
try {
|
|
@@ -198360,8 +198708,8 @@ var WebSkillLoader = class {
|
|
|
198360
198708
|
return (0, import_promises.readFile)(import_node_path.default.join(candidate, "SKILL.md"), "utf8");
|
|
198361
198709
|
}
|
|
198362
198710
|
if (isZipPath(candidate)) {
|
|
198363
|
-
const
|
|
198364
|
-
const files = await unzipBytes(
|
|
198711
|
+
const bytes2 = new Uint8Array(await (0, import_promises.readFile)(candidate));
|
|
198712
|
+
const files = await unzipBytes(bytes2, resourceId);
|
|
198365
198713
|
const body = extractSkillMarkdown(files);
|
|
198366
198714
|
if (body === void 0) {
|
|
198367
198715
|
throw new Error(`WebSkillLoader \u5728\u672C\u5730 zip \u5185\u672A\u627E\u5230 SKILL.md(\u6216\u56DE\u9000 .md)\u6B63\u6587: ${url2} (resourceId=${resourceId})`);
|
|
@@ -198404,7 +198752,7 @@ var extractSkillMarkdown = (files) => {
|
|
|
198404
198752
|
const rootMd = paths.find((p) => p.endsWith(".md") && !p.includes("/"));
|
|
198405
198753
|
return rootMd === void 0 ? void 0 : decodeUtf8(files[rootMd]);
|
|
198406
198754
|
};
|
|
198407
|
-
var decodeUtf8 = (
|
|
198755
|
+
var decodeUtf8 = (bytes2) => new TextDecoder("utf-8", { fatal: true }).decode(bytes2);
|
|
198408
198756
|
var globalFetch = (url2) => fetch(url2);
|
|
198409
198757
|
var detectScheme = (url2) => {
|
|
198410
198758
|
if (/^https:\/\//i.test(url2))
|
|
@@ -198908,7 +199256,7 @@ var handleHomeData = async (req, res, input) => {
|
|
|
198908
199256
|
);
|
|
198909
199257
|
}
|
|
198910
199258
|
};
|
|
198911
|
-
var handleA2UIAction = async (req, res, input) => {
|
|
199259
|
+
var handleA2UIAction = async (req, res, input, debugLog) => {
|
|
198912
199260
|
if (!executeCardAction2 || !createMcpServerProvider) {
|
|
198913
199261
|
writeJsonError2(res, 500, "AGENTDEV_NOT_READY", "agent runtime not loaded");
|
|
198914
199262
|
return;
|
|
@@ -198932,7 +199280,8 @@ var handleA2UIAction = async (req, res, input) => {
|
|
|
198932
199280
|
userId: proxyInput.userId,
|
|
198933
199281
|
...proxyInput.tenantId ? { tenantId: proxyInput.tenantId } : {}
|
|
198934
199282
|
},
|
|
198935
|
-
mcpServerProvider: createMcpServerProvider(protocol)
|
|
199283
|
+
mcpServerProvider: createMcpServerProvider(protocol),
|
|
199284
|
+
debugLog
|
|
198936
199285
|
});
|
|
198937
199286
|
res.writeHead(200, { "content-type": "application/json; charset=utf-8" });
|
|
198938
199287
|
res.end(JSON.stringify(result));
|
|
@@ -199110,7 +199459,7 @@ var main = async () => {
|
|
|
199110
199459
|
return;
|
|
199111
199460
|
}
|
|
199112
199461
|
if (req.method === "POST" && pathname === input.a2uiActionPath) {
|
|
199113
|
-
void handleA2UIAction(req, res, input);
|
|
199462
|
+
void handleA2UIAction(req, res, input, debugLog);
|
|
199114
199463
|
return;
|
|
199115
199464
|
}
|
|
199116
199465
|
const cancelMatch = pathname.match(
|