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/package.json
CHANGED
package/vendor/linkque-agent-appwrite-integrate/dist/esm/{chunk-DCQYAWC6.js → chunk-P5YTVR76.js}
RENAMED
|
@@ -8846,6 +8846,7 @@ var EHookStage;
|
|
|
8846
8846
|
EHookStage2["RUN_FAILED"] = "RUN_FAILED";
|
|
8847
8847
|
EHookStage2["RUN_READ"] = "RUN_READ";
|
|
8848
8848
|
EHookStage2["AFTER_MODEL_CALL"] = "AFTER_MODEL_CALL";
|
|
8849
|
+
EHookStage2["MODEL_RESPONSE_RECEIVED"] = "MODEL_RESPONSE_RECEIVED";
|
|
8849
8850
|
EHookStage2["BEFORE_TOOL_CALL"] = "BEFORE_TOOL_CALL";
|
|
8850
8851
|
EHookStage2["AFTER_TOOL_CALL"] = "AFTER_TOOL_CALL";
|
|
8851
8852
|
EHookStage2["TOOL_CALL_FAILED"] = "TOOL_CALL_FAILED";
|
|
@@ -11669,6 +11670,7 @@ function aggregateMcpServers(resources, protocolAgentId) {
|
|
|
11669
11670
|
// ../linkque-agent-runtime/dist/esm/core/types.js
|
|
11670
11671
|
var EDebugLogScope;
|
|
11671
11672
|
(function(EDebugLogScope2) {
|
|
11673
|
+
EDebugLogScope2["A2UI_ACTION"] = "A2UI_ACTION";
|
|
11672
11674
|
EDebugLogScope2["CONFIG"] = "CONFIG";
|
|
11673
11675
|
EDebugLogScope2["LLM"] = "LLM";
|
|
11674
11676
|
EDebugLogScope2["PI_EVENT"] = "PI_EVENT";
|
|
@@ -11736,7 +11738,11 @@ var McpProxyTool = class {
|
|
|
11736
11738
|
return;
|
|
11737
11739
|
try {
|
|
11738
11740
|
await entry.server.close?.();
|
|
11739
|
-
} catch {
|
|
11741
|
+
} catch (error) {
|
|
11742
|
+
try {
|
|
11743
|
+
this.debugLog(`[mcp] server ${entry.server.serverName} close failed: ${error instanceof Error ? error.message : "unknown error"}`, EDebugLogScope.MCP);
|
|
11744
|
+
} catch {
|
|
11745
|
+
}
|
|
11740
11746
|
}
|
|
11741
11747
|
}));
|
|
11742
11748
|
}
|
|
@@ -12114,14 +12120,89 @@ var MCP_PROXY_INPUT_SCHEMA = {
|
|
|
12114
12120
|
}
|
|
12115
12121
|
};
|
|
12116
12122
|
|
|
12123
|
+
// ../linkque-agent-runtime/dist/esm/core/cardActionDiagnostics.js
|
|
12124
|
+
var CardActionDiagnostics = class {
|
|
12125
|
+
sink;
|
|
12126
|
+
layer;
|
|
12127
|
+
stage = "validate";
|
|
12128
|
+
context;
|
|
12129
|
+
debugLog;
|
|
12130
|
+
startedAt = performance.now();
|
|
12131
|
+
constructor(sink, context, layer = "runtime") {
|
|
12132
|
+
this.sink = sink;
|
|
12133
|
+
this.layer = layer;
|
|
12134
|
+
this.context = { ...context };
|
|
12135
|
+
if (sink) {
|
|
12136
|
+
this.debugLog = (line, scope) => {
|
|
12137
|
+
this.write("diagnostic", { message: line }, scope);
|
|
12138
|
+
};
|
|
12139
|
+
}
|
|
12140
|
+
}
|
|
12141
|
+
write(event, fields = {}, scope = EDebugLogScope.A2UI_ACTION) {
|
|
12142
|
+
if (!this.sink)
|
|
12143
|
+
return;
|
|
12144
|
+
try {
|
|
12145
|
+
const record2 = { ...this.context, ...fields };
|
|
12146
|
+
if (record2.message)
|
|
12147
|
+
record2.message = sanitizeDiagnosticText(record2.message);
|
|
12148
|
+
if (record2.errorName)
|
|
12149
|
+
record2.errorName = sanitizeDiagnosticText(record2.errorName);
|
|
12150
|
+
this.sink(JSON.stringify({
|
|
12151
|
+
operation: "a2uiAction.execute",
|
|
12152
|
+
layer: this.layer,
|
|
12153
|
+
event,
|
|
12154
|
+
stage: this.stage,
|
|
12155
|
+
...record2,
|
|
12156
|
+
costMs: Math.max(0, Math.round(performance.now() - this.startedAt))
|
|
12157
|
+
}), scope);
|
|
12158
|
+
} catch {
|
|
12159
|
+
}
|
|
12160
|
+
}
|
|
12161
|
+
error(event, error) {
|
|
12162
|
+
if (!this.sink)
|
|
12163
|
+
return;
|
|
12164
|
+
try {
|
|
12165
|
+
this.write(event, {
|
|
12166
|
+
errorName: error instanceof Error ? error.name : typeof error,
|
|
12167
|
+
message: error instanceof Error ? error.message : typeof error === "string" ? error : "\u975E\u6807\u51C6\u5F02\u5E38"
|
|
12168
|
+
});
|
|
12169
|
+
} catch {
|
|
12170
|
+
}
|
|
12171
|
+
}
|
|
12172
|
+
};
|
|
12173
|
+
function sanitizeDiagnosticText(value) {
|
|
12174
|
+
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);
|
|
12175
|
+
}
|
|
12176
|
+
|
|
12117
12177
|
// ../linkque-agent-runtime/dist/esm/core/cardActionExecutor.js
|
|
12118
12178
|
async function executeCardAction(input) {
|
|
12179
|
+
const diagnostics = new CardActionDiagnostics(input.debugLog, {
|
|
12180
|
+
agentId: input.protocol.agentId,
|
|
12181
|
+
threadId: input.runtimeContext.threadId
|
|
12182
|
+
});
|
|
12183
|
+
diagnostics.write("started");
|
|
12184
|
+
try {
|
|
12185
|
+
const response = await executeCardActionInternal(input, diagnostics);
|
|
12186
|
+
diagnostics.write(response.ok ? "completed" : "failed", response.ok ? {} : { code: response.error.code, retryable: response.error.retryable });
|
|
12187
|
+
return response;
|
|
12188
|
+
} catch (error) {
|
|
12189
|
+
diagnostics.error("failed", error);
|
|
12190
|
+
throw error;
|
|
12191
|
+
}
|
|
12192
|
+
}
|
|
12193
|
+
async function executeCardActionInternal(input, diagnostics) {
|
|
12119
12194
|
let request;
|
|
12120
12195
|
try {
|
|
12121
12196
|
request = parseA2UIActionExecuteRequest(input.request);
|
|
12122
12197
|
} catch (error) {
|
|
12123
12198
|
return failure("INVALID_INPUT", errorMessage(error, "\u652F\u4ED8\u52A8\u4F5C\u8BF7\u6C42\u65E0\u6548"), false);
|
|
12124
12199
|
}
|
|
12200
|
+
Object.assign(diagnostics.context, {
|
|
12201
|
+
invocationId: request.invocationId,
|
|
12202
|
+
actionId: request.actionId,
|
|
12203
|
+
cardRef: request.source.cardRef,
|
|
12204
|
+
cardRevision: request.source.cardRevision
|
|
12205
|
+
});
|
|
12125
12206
|
if (request.agentId !== input.protocol.agentId) {
|
|
12126
12207
|
return failure("AGENT_MISMATCH", "\u652F\u4ED8\u52A8\u4F5C\u4E0E\u5F53\u524D Agent \u4E0D\u5339\u914D", false);
|
|
12127
12208
|
}
|
|
@@ -12131,24 +12212,38 @@ async function executeCardAction(input) {
|
|
|
12131
12212
|
if (!input.runtimeContext.userId.trim()) {
|
|
12132
12213
|
return failure("AUTH_REQUIRED", "\u652F\u4ED8\u52A8\u4F5C\u7F3A\u5C11\u53EF\u4FE1\u7528\u6237\u8EAB\u4EFD", false);
|
|
12133
12214
|
}
|
|
12215
|
+
diagnostics.write("validated");
|
|
12216
|
+
diagnostics.stage = "binding";
|
|
12134
12217
|
const resolved = resolvePaymentBinding(input.protocol, request.source, request.actionId);
|
|
12135
12218
|
if (!resolved.ok)
|
|
12136
12219
|
return resolved.response;
|
|
12137
|
-
|
|
12220
|
+
Object.assign(diagnostics.context, {
|
|
12221
|
+
mcpResourceId: resolved.binding.createTrade.mcpResourceId,
|
|
12222
|
+
toolName: resolved.binding.createTrade.toolName
|
|
12223
|
+
});
|
|
12224
|
+
diagnostics.write("binding_resolved");
|
|
12225
|
+
diagnostics.stage = "tool_resolve";
|
|
12226
|
+
const registry = createRegistry(input.protocol, input.mcpServerProvider, diagnostics.debugLog);
|
|
12138
12227
|
try {
|
|
12139
12228
|
const tool = await registry.resolve(resolved.binding.createTrade.mcpResourceId, resolved.binding.createTrade.toolName, input.signal);
|
|
12140
12229
|
if (!tool) {
|
|
12141
12230
|
return failure("TOOL_NOT_ALLOWED", "\u521B\u5EFA\u4EA4\u6613 MCP Tool \u4E0D\u5B58\u5728\u6216\u672A\u6388\u6743", false);
|
|
12142
12231
|
}
|
|
12232
|
+
diagnostics.stage = "tool_input";
|
|
12143
12233
|
const args = createToolInput(resolved.binding.createTrade.inputBindings, request.actionContext, input.runtimeContext);
|
|
12144
12234
|
if (!args)
|
|
12145
12235
|
return failure("INVALID_INPUT", "\u65E0\u6CD5\u751F\u6210\u521B\u5EFA\u4EA4\u6613 MCP \u5165\u53C2", false);
|
|
12146
12236
|
let result;
|
|
12237
|
+
diagnostics.stage = "tool_execute";
|
|
12238
|
+
diagnostics.write("tool_started");
|
|
12147
12239
|
try {
|
|
12148
12240
|
result = await tool.execute(args, input.signal);
|
|
12149
|
-
|
|
12241
|
+
diagnostics.write("tool_completed");
|
|
12242
|
+
} catch (error) {
|
|
12243
|
+
diagnostics.error("tool_failed", error);
|
|
12150
12244
|
return failure("EXECUTION_FAILED", "\u521B\u5EFA\u4EA4\u6613\u5931\u8D25\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5", true);
|
|
12151
12245
|
}
|
|
12246
|
+
diagnostics.stage = "tool_output";
|
|
12152
12247
|
const structured = readStructuredContent(result);
|
|
12153
12248
|
const tradeNO = readJsonPointer(structured, resolved.binding.createTrade.tradeNoPath);
|
|
12154
12249
|
if (typeof tradeNO !== "string" || !tradeNO.trim() || tradeNO.length > 64) {
|
|
@@ -12160,7 +12255,10 @@ async function executeCardAction(input) {
|
|
|
12160
12255
|
result: { kind: "payment", tradeNO }
|
|
12161
12256
|
};
|
|
12162
12257
|
} finally {
|
|
12258
|
+
const stage = diagnostics.stage;
|
|
12259
|
+
diagnostics.stage = "cleanup";
|
|
12163
12260
|
await registry.closeAll();
|
|
12261
|
+
diagnostics.stage = stage;
|
|
12164
12262
|
}
|
|
12165
12263
|
}
|
|
12166
12264
|
async function verifyPaymentResult(input) {
|
|
@@ -12223,9 +12321,9 @@ function resolvePaymentBinding(protocol, source, actionId) {
|
|
|
12223
12321
|
}
|
|
12224
12322
|
return { ok: true, binding };
|
|
12225
12323
|
}
|
|
12226
|
-
function createRegistry(protocol, provider) {
|
|
12324
|
+
function createRegistry(protocol, provider, debugLog) {
|
|
12227
12325
|
const resources = protocol.agent.resources.filter((resource) => resource.resourceType === EResourceType.MCP || resource.resourceType === EResourceType.MCP_TOOL);
|
|
12228
|
-
return new McpProxyTool(provider, aggregateMcpServers(resources, protocol.agentId));
|
|
12326
|
+
return new McpProxyTool(provider, aggregateMcpServers(resources, protocol.agentId), { debugLog });
|
|
12229
12327
|
}
|
|
12230
12328
|
function createToolInput(bindings, actionContext, runtimeContext, tradeNO, callback) {
|
|
12231
12329
|
const result = {};
|
|
@@ -12425,6 +12523,90 @@ function stableToolName(prefix, raw) {
|
|
|
12425
12523
|
return `${prefix}_${readable}_${digest}`;
|
|
12426
12524
|
}
|
|
12427
12525
|
|
|
12526
|
+
// ../linkque-agent-runtime/dist/esm/core/cardSemanticSnapshot.js
|
|
12527
|
+
var MAX_BYTES = 6e3;
|
|
12528
|
+
var MAX_LABEL = 160;
|
|
12529
|
+
function createCardSemanticSnapshot(receipt, fields) {
|
|
12530
|
+
const groups = receipt.coverage.map((coverage) => {
|
|
12531
|
+
const field = fields.find((f) => f.fieldId === coverage.fieldId);
|
|
12532
|
+
const entities = receipt.entities.filter((e) => e.fieldId === coverage.fieldId);
|
|
12533
|
+
const echo = field?.presentation?.visibility === "echo";
|
|
12534
|
+
const attributes = echo ? [...new Set(entities.flatMap((e) => Object.keys(e.attributes ?? {})))] : [];
|
|
12535
|
+
const hasValue = echo && entities.some((e) => Object.hasOwn(e, "value"));
|
|
12536
|
+
const hasLabel = echo && entities.some((e) => !Object.hasOwn(e, "value"));
|
|
12537
|
+
const columns = [
|
|
12538
|
+
"\u6761\u76EE\u5F15\u7528",
|
|
12539
|
+
...hasLabel ? [columnLabel(field, field?.presentation?.labelPath, "\u540D\u79F0")] : [],
|
|
12540
|
+
...hasValue ? [short(coverage.label)] : [],
|
|
12541
|
+
...attributes.map((path2) => columnLabel(field, path2, path2))
|
|
12542
|
+
];
|
|
12543
|
+
const rows = entities.map((e) => [
|
|
12544
|
+
e.ref,
|
|
12545
|
+
...hasLabel ? [e.label] : [],
|
|
12546
|
+
...hasValue ? [e.value ?? null] : [],
|
|
12547
|
+
...attributes.map((path2) => e.attributes?.[path2] ?? null)
|
|
12548
|
+
]);
|
|
12549
|
+
const total = coverage.itemCount ?? (coverage.present ? 1 : 0);
|
|
12550
|
+
return {
|
|
12551
|
+
field: coverage.fieldId,
|
|
12552
|
+
label: short(coverage.label),
|
|
12553
|
+
present: coverage.present,
|
|
12554
|
+
total,
|
|
12555
|
+
included: rows.length,
|
|
12556
|
+
complete: echo && coverage.present && rows.length === total && !entities.some((e) => e.truncated) && !receipt.omissions.some((o) => o.fieldId === coverage.fieldId),
|
|
12557
|
+
columns,
|
|
12558
|
+
rows
|
|
12559
|
+
};
|
|
12560
|
+
});
|
|
12561
|
+
const snapshot = {
|
|
12562
|
+
version: 1,
|
|
12563
|
+
groups,
|
|
12564
|
+
omissions: receipt.omissions.map((o) => ({ ...o }))
|
|
12565
|
+
};
|
|
12566
|
+
while (bytes(snapshot) > MAX_BYTES) {
|
|
12567
|
+
let group;
|
|
12568
|
+
for (let i = groups.length - 1; i >= 0; i--) {
|
|
12569
|
+
if (groups[i].rows.length > 0) {
|
|
12570
|
+
group = groups[i];
|
|
12571
|
+
break;
|
|
12572
|
+
}
|
|
12573
|
+
}
|
|
12574
|
+
snapshot.truncated = true;
|
|
12575
|
+
if (group) {
|
|
12576
|
+
group.rows.pop();
|
|
12577
|
+
group.included = group.rows.length;
|
|
12578
|
+
group.complete = false;
|
|
12579
|
+
} else if (groups.length) {
|
|
12580
|
+
groups.pop();
|
|
12581
|
+
} else if (snapshot.omissions.length) {
|
|
12582
|
+
snapshot.omissions.pop();
|
|
12583
|
+
} else
|
|
12584
|
+
break;
|
|
12585
|
+
}
|
|
12586
|
+
return snapshot;
|
|
12587
|
+
}
|
|
12588
|
+
function bytes(value) {
|
|
12589
|
+
return Buffer.byteLength(JSON.stringify(value));
|
|
12590
|
+
}
|
|
12591
|
+
function short(value) {
|
|
12592
|
+
return value.length > MAX_LABEL ? `${value.slice(0, MAX_LABEL - 1)}\u2026` : value;
|
|
12593
|
+
}
|
|
12594
|
+
function columnLabel(field, path2, fallback) {
|
|
12595
|
+
if (!field || !path2)
|
|
12596
|
+
return short(fallback);
|
|
12597
|
+
let schema = field.type === "array" ? field.valueSchema.items : field.valueSchema;
|
|
12598
|
+
for (const token of path2.slice(1).split("/").map((t) => t.replaceAll("~1", "/").replaceAll("~0", "~"))) {
|
|
12599
|
+
if (!schema || typeof schema !== "object" || Array.isArray(schema))
|
|
12600
|
+
return short(fallback);
|
|
12601
|
+
const properties = schema.properties;
|
|
12602
|
+
if (!properties || typeof properties !== "object" || Array.isArray(properties) || !Object.hasOwn(properties, token))
|
|
12603
|
+
return short(fallback);
|
|
12604
|
+
schema = properties[token];
|
|
12605
|
+
}
|
|
12606
|
+
const title = schema && typeof schema === "object" && !Array.isArray(schema) ? schema.title : void 0;
|
|
12607
|
+
return short(typeof title === "string" && title ? title : fallback);
|
|
12608
|
+
}
|
|
12609
|
+
|
|
12428
12610
|
// ../linkque-agent-runtime/dist/esm/core/cardTools.js
|
|
12429
12611
|
var FALLBACK_OBJECT_SCHEMA = {
|
|
12430
12612
|
type: "object",
|
|
@@ -12548,6 +12730,7 @@ function createPresentationResult(resource, config, viewModel) {
|
|
|
12548
12730
|
...createA2UICardPresentationReceiptContent(config.fields, viewModel),
|
|
12549
12731
|
responsePolicy: { verbatimEcho: "forbidden", hint: "acknowledge" }
|
|
12550
12732
|
};
|
|
12733
|
+
receipt.semanticSnapshot = createCardSemanticSnapshot(receipt, config.fields);
|
|
12551
12734
|
return {
|
|
12552
12735
|
type: "linkque.presentation-tool-result",
|
|
12553
12736
|
modelText: formatPresentationReceiptForModel(receipt),
|
|
@@ -12567,11 +12750,23 @@ function createPresentationResult(resource, config, viewModel) {
|
|
|
12567
12750
|
function formatPresentationReceiptForModel(receipt) {
|
|
12568
12751
|
return [
|
|
12569
12752
|
"<a2ui-presentation-receipt>",
|
|
12570
|
-
JSON.stringify(receipt),
|
|
12753
|
+
JSON.stringify(projectPresentationReceiptForModel(receipt)),
|
|
12571
12754
|
"</a2ui-presentation-receipt>",
|
|
12572
|
-
"
|
|
12755
|
+
"\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"
|
|
12573
12756
|
].join("\n");
|
|
12574
12757
|
}
|
|
12758
|
+
function projectPresentationReceiptForModel(receipt) {
|
|
12759
|
+
if (!receipt.semanticSnapshot)
|
|
12760
|
+
return receipt;
|
|
12761
|
+
return {
|
|
12762
|
+
version: receipt.version,
|
|
12763
|
+
cardRef: receipt.cardRef,
|
|
12764
|
+
cardRevision: receipt.cardRevision,
|
|
12765
|
+
cardInstanceId: receipt.cardInstanceId,
|
|
12766
|
+
status: receipt.status,
|
|
12767
|
+
semanticSnapshot: receipt.semanticSnapshot
|
|
12768
|
+
};
|
|
12769
|
+
}
|
|
12575
12770
|
function parseCardConfig(resource) {
|
|
12576
12771
|
const parsed = parseA2UICardResourceConfig(resource.config);
|
|
12577
12772
|
if (!parsed.success) {
|
|
@@ -12625,9 +12820,9 @@ function collectA2UISurfaceIdsForLegacyContract(protocol) {
|
|
|
12625
12820
|
function createPresentationDescription(config) {
|
|
12626
12821
|
return [
|
|
12627
12822
|
config.description,
|
|
12628
|
-
|
|
12629
|
-
...config.whenNotToUse ? [
|
|
12630
|
-
"
|
|
12823
|
+
`\u9002\u7528\u573A\u666F\uFF1A${config.whenToUse}`,
|
|
12824
|
+
...config.whenNotToUse ? [`\u4E0D\u9002\u7528\u573A\u666F\uFF1A${config.whenNotToUse}`] : [],
|
|
12825
|
+
"\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"
|
|
12631
12826
|
].join("\n");
|
|
12632
12827
|
}
|
|
12633
12828
|
function cloneJsonObject2(value, label) {
|
|
@@ -12891,6 +13086,12 @@ function normalizeHookResources(resources) {
|
|
|
12891
13086
|
}).sort((a, b) => (a.config.order ?? 0) - (b.config.order ?? 0));
|
|
12892
13087
|
}
|
|
12893
13088
|
|
|
13089
|
+
// ../linkque-agent-runtime/dist/esm/core/logFailure.js
|
|
13090
|
+
import { emitWarning } from "node:process";
|
|
13091
|
+
function warnLogFailure(stage, error) {
|
|
13092
|
+
emitWarning(`[${stage}] errorType=${error instanceof Error ? error.name : typeof error}`, { code: "LINKQUE_RUNTIME_DIAGNOSTIC_FAILURE" });
|
|
13093
|
+
}
|
|
13094
|
+
|
|
12894
13095
|
// ../linkque-agent-runtime/dist/esm/core/hook/hookLog.js
|
|
12895
13096
|
var HOOK_LOG_MESSAGE_MAX_LENGTH = 200;
|
|
12896
13097
|
function writeHookLog(debugLog, record2) {
|
|
@@ -12898,7 +13099,8 @@ function writeHookLog(debugLog, record2) {
|
|
|
12898
13099
|
return;
|
|
12899
13100
|
try {
|
|
12900
13101
|
debugLog(JSON.stringify(redactHookLogRecord(record2)), EDebugLogScope.HOOK);
|
|
12901
|
-
} catch {
|
|
13102
|
+
} catch (error) {
|
|
13103
|
+
warnLogFailure("writeHookLog", error);
|
|
12902
13104
|
}
|
|
12903
13105
|
}
|
|
12904
13106
|
function redactHookLogRecord(record2) {
|
|
@@ -13097,6 +13299,15 @@ var HookDispatcher = class {
|
|
|
13097
13299
|
stage: EHookStage.RUN_READ,
|
|
13098
13300
|
read: { readAt: subject.readAt ?? now() }
|
|
13099
13301
|
};
|
|
13302
|
+
case EHookStage.MODEL_RESPONSE_RECEIVED: {
|
|
13303
|
+
if (!subject.model)
|
|
13304
|
+
throw new Error("MODEL_RESPONSE_RECEIVED Hook \u7F3A\u5C11\u54CD\u5E94\u4E0A\u4E0B\u6587");
|
|
13305
|
+
return {
|
|
13306
|
+
...base,
|
|
13307
|
+
stage: EHookStage.MODEL_RESPONSE_RECEIVED,
|
|
13308
|
+
model: subject.model
|
|
13309
|
+
};
|
|
13310
|
+
}
|
|
13100
13311
|
case EHookStage.AFTER_MODEL_CALL: {
|
|
13101
13312
|
if (!subject.model || subject.model.messageContent === void 0) {
|
|
13102
13313
|
throw new Error("AFTER_MODEL_CALL Hook \u7F3A\u5C11\u5B8C\u6574 model context");
|
|
@@ -13645,7 +13856,8 @@ function redactHeaders(headers) {
|
|
|
13645
13856
|
pairs.push(`${key}=${redactHeader(key, value)}`);
|
|
13646
13857
|
}
|
|
13647
13858
|
}
|
|
13648
|
-
} catch {
|
|
13859
|
+
} catch (error) {
|
|
13860
|
+
warnLogFailure("httpLoggingFetch.redactHeaders", error);
|
|
13649
13861
|
}
|
|
13650
13862
|
return pairs.join(",");
|
|
13651
13863
|
}
|
|
@@ -13682,7 +13894,8 @@ function createHttpLoggingFetch(debugLog, tag, baseFetch = globalThis.fetch) {
|
|
|
13682
13894
|
const cl = resp.headers.get("content-length");
|
|
13683
13895
|
if (cl)
|
|
13684
13896
|
len = cl;
|
|
13685
|
-
} catch {
|
|
13897
|
+
} catch (error) {
|
|
13898
|
+
warnLogFailure("httpLoggingFetch.contentLength", error);
|
|
13686
13899
|
}
|
|
13687
13900
|
const correlation = readResponseCorrelationId(resp.headers);
|
|
13688
13901
|
const correlationField = correlation ? ` traceId=${correlation.value} traceHeader=${correlation.name}` : "";
|
|
@@ -13711,14 +13924,16 @@ function readResponseCorrelationId(headers) {
|
|
|
13711
13924
|
};
|
|
13712
13925
|
});
|
|
13713
13926
|
return matched;
|
|
13714
|
-
} catch {
|
|
13927
|
+
} catch (error) {
|
|
13928
|
+
warnLogFailure("httpLoggingFetch.responseCorrelationId", error);
|
|
13715
13929
|
}
|
|
13716
13930
|
return void 0;
|
|
13717
13931
|
}
|
|
13718
13932
|
function safeLog(debugLog, line) {
|
|
13719
13933
|
try {
|
|
13720
13934
|
debugLog(line, EDebugLogScope.HTTP);
|
|
13721
|
-
} catch {
|
|
13935
|
+
} catch (error) {
|
|
13936
|
+
warnLogFailure("httpLoggingFetch.safeLog", error);
|
|
13722
13937
|
}
|
|
13723
13938
|
}
|
|
13724
13939
|
function nowMs() {
|
|
@@ -20316,13 +20531,42 @@ var RemoteGatewayMcpServerProvider = class {
|
|
|
20316
20531
|
});
|
|
20317
20532
|
const serverName = resource.config.serverName ?? resource.resourceId;
|
|
20318
20533
|
const argsMappingRules = resource.config.argsMappingRules ?? [];
|
|
20534
|
+
let requestSequence = 0;
|
|
20535
|
+
const request = async (method, params, invoke) => {
|
|
20536
|
+
const requestId = ++requestSequence;
|
|
20537
|
+
const log = (phase, payload) => {
|
|
20538
|
+
if (!this.debugLog)
|
|
20539
|
+
return;
|
|
20540
|
+
try {
|
|
20541
|
+
this.debugLog(`[mcp-client] ${JSON.stringify({ serverName, resourceId: resource.resourceId, requestId, method, phase, payload })}`, EDebugLogScope.MCP);
|
|
20542
|
+
} catch (error) {
|
|
20543
|
+
warnLogFailure("remoteGatewayMcpServer.log", error);
|
|
20544
|
+
}
|
|
20545
|
+
};
|
|
20546
|
+
log("request", params);
|
|
20547
|
+
try {
|
|
20548
|
+
const result = await invoke();
|
|
20549
|
+
log("response", result);
|
|
20550
|
+
return result;
|
|
20551
|
+
} catch (error) {
|
|
20552
|
+
log("error", error instanceof Error ? { name: error.name, message: error.message } : error);
|
|
20553
|
+
throw error;
|
|
20554
|
+
}
|
|
20555
|
+
};
|
|
20556
|
+
const loggedClient = {
|
|
20557
|
+
listTools: () => request("tools/list", {}, () => client.listTools()),
|
|
20558
|
+
callTool: (params) => request("tools/call", params, () => client.callTool(params))
|
|
20559
|
+
};
|
|
20319
20560
|
return {
|
|
20320
20561
|
resourceId: resource.resourceId,
|
|
20321
20562
|
serverName,
|
|
20322
|
-
listTools: () => listToolsFromClient(
|
|
20563
|
+
listTools: () => listToolsFromClient(loggedClient, resource.resourceId),
|
|
20323
20564
|
callTool: (name, args) => {
|
|
20324
20565
|
const mapped = applyArgsMappingRules(name, args, argsMappingRules);
|
|
20325
|
-
return
|
|
20566
|
+
return loggedClient.callTool({
|
|
20567
|
+
name,
|
|
20568
|
+
arguments: mapped ?? {}
|
|
20569
|
+
});
|
|
20326
20570
|
},
|
|
20327
20571
|
close: async () => {
|
|
20328
20572
|
try {
|
|
@@ -21196,8 +21440,8 @@ var WebSkillLoader = class {
|
|
|
21196
21440
|
return readFile(path.join(candidate, "SKILL.md"), "utf8");
|
|
21197
21441
|
}
|
|
21198
21442
|
if (isZipPath(candidate)) {
|
|
21199
|
-
const
|
|
21200
|
-
const files = await unzipBytes(
|
|
21443
|
+
const bytes2 = new Uint8Array(await readFile(candidate));
|
|
21444
|
+
const files = await unzipBytes(bytes2, resourceId);
|
|
21201
21445
|
const body = extractSkillMarkdown(files);
|
|
21202
21446
|
if (body === void 0) {
|
|
21203
21447
|
throw new Error(`WebSkillLoader \u5728\u672C\u5730 zip \u5185\u672A\u627E\u5230 SKILL.md(\u6216\u56DE\u9000 .md)\u6B63\u6587: ${url2} (resourceId=${resourceId})`);
|
|
@@ -21240,7 +21484,7 @@ var extractSkillMarkdown = (files) => {
|
|
|
21240
21484
|
const rootMd = paths.find((p) => p.endsWith(".md") && !p.includes("/"));
|
|
21241
21485
|
return rootMd === void 0 ? void 0 : decodeUtf8(files[rootMd]);
|
|
21242
21486
|
};
|
|
21243
|
-
var decodeUtf8 = (
|
|
21487
|
+
var decodeUtf8 = (bytes2) => new TextDecoder("utf-8", { fatal: true }).decode(bytes2);
|
|
21244
21488
|
var globalFetch = (url2) => fetch(url2);
|
|
21245
21489
|
var detectScheme = (url2) => {
|
|
21246
21490
|
if (/^https:\/\//i.test(url2))
|
|
@@ -21447,6 +21691,7 @@ export {
|
|
|
21447
21691
|
createCardPresentationToolName,
|
|
21448
21692
|
executeCardPresentation,
|
|
21449
21693
|
executeCardPresentationFromSources,
|
|
21694
|
+
projectPresentationReceiptForModel,
|
|
21450
21695
|
parseCardConfig,
|
|
21451
21696
|
isAgentPresentationToolResult,
|
|
21452
21697
|
createPresentationDescription,
|
|
@@ -21456,6 +21701,7 @@ export {
|
|
|
21456
21701
|
aggregateMcpServers,
|
|
21457
21702
|
McpProxyTool,
|
|
21458
21703
|
executeHomeData,
|
|
21704
|
+
CardActionDiagnostics,
|
|
21459
21705
|
executeCardAction,
|
|
21460
21706
|
verifyPaymentResult,
|
|
21461
21707
|
FOLLOW_UP_CONTEXT_MAX_HISTORY_RUNS,
|
|
@@ -21466,6 +21712,7 @@ export {
|
|
|
21466
21712
|
NoopMcpServerProvider,
|
|
21467
21713
|
buildHookCommonParams,
|
|
21468
21714
|
normalizeHookResources,
|
|
21715
|
+
warnLogFailure,
|
|
21469
21716
|
HookDispatcher,
|
|
21470
21717
|
DEFAULT_HOOK_DRAIN_BUDGET_MS,
|
|
21471
21718
|
SideEffectRunner,
|