linkque-cli-v2 1.3.6 → 1.3.8-beta.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 +1106 -324
- package/package.json +1 -1
- package/vendor/linkque-agent-appwrite-integrate/dist/esm/{chunk-RHFHCJYP.js → chunk-7MJID6LL.js} +15253 -393
- package/vendor/linkque-agent-appwrite-integrate/dist/esm/{chunk-NHRW2KQW.js → chunk-BU3S4JYG.js} +1 -1
- package/vendor/linkque-agent-appwrite-integrate/dist/esm/{chunk-HM7KNEG3.js → chunk-DNTEEBEH.js} +5 -0
- package/vendor/linkque-agent-appwrite-integrate/dist/esm/chunk-EAODRPW4.js +518 -0
- package/vendor/linkque-agent-appwrite-integrate/dist/esm/{chunk-7SF3H2GM.js → chunk-EFUO43CY.js} +6 -1
- package/vendor/linkque-agent-appwrite-integrate/dist/esm/{getMachineId-bsd-H2ZLZRGB.js → getMachineId-bsd-JGCLGHFY.js} +1 -1
- package/vendor/linkque-agent-appwrite-integrate/dist/esm/{getMachineId-darwin-HUKYR46U.js → getMachineId-darwin-COHLFNXH.js} +1 -1
- package/vendor/linkque-agent-appwrite-integrate/dist/esm/{getMachineId-linux-M5ZADHBA.js → getMachineId-linux-XV3Z5FQG.js} +1 -1
- package/vendor/linkque-agent-appwrite-integrate/dist/esm/{getMachineId-unsupported-BM5RZZVM.js → getMachineId-unsupported-FCRKLIZL.js} +1 -1
- package/vendor/linkque-agent-appwrite-integrate/dist/esm/{getMachineId-win-BQPUF5TW.js → getMachineId-win-A4WRNVV6.js} +1 -1
- package/vendor/linkque-agent-appwrite-integrate/dist/esm/{mistral-conversations-TQA2MPJJ.js → mistral-conversations-5RZTVEO2.js} +1 -1
- package/vendor/linkque-agent-appwrite-integrate/dist/esm/{otel-RXJWJ2TU.js → otel-WGS5CC2J.js} +250 -267
- package/vendor/linkque-agent-appwrite-integrate/dist/esm/runtime/handler/chat.js +134 -19
- package/vendor/linkque-agent-appwrite-integrate/dist/esm/runtime/handler/clientCapability.js +4 -3
- package/vendor/linkque-agent-appwrite-integrate/dist/esm/runtime/protocol.js +4 -3
- package/vendor/linkque-agent-appwrite-integrate/package.json +1 -1
- package/worker.js +418 -68
package/worker.js
CHANGED
|
@@ -80,6 +80,7 @@ var init_agentProtocol = __esm({
|
|
|
80
80
|
(function(EArgsMappingValueType2) {
|
|
81
81
|
EArgsMappingValueType2["DEFAULT"] = "DEFAULT";
|
|
82
82
|
EArgsMappingValueType2["CONST"] = "CONST";
|
|
83
|
+
EArgsMappingValueType2["SYSTEM_VARIABLE"] = "SYSTEM_VARIABLE";
|
|
83
84
|
})(EArgsMappingValueType || (EArgsMappingValueType = {}));
|
|
84
85
|
(function(EHookStage2) {
|
|
85
86
|
EHookStage2["PREPARE_AGENT_LOOP"] = "PREPARE_AGENT_LOOP";
|
|
@@ -4360,13 +4361,14 @@ var require_fast_uri = __commonJS({
|
|
|
4360
4361
|
if (!malformedIPLiteral) {
|
|
4361
4362
|
malformedHost = canonicalizeHost(parsed, options, schemeHandler, isIP2);
|
|
4362
4363
|
}
|
|
4363
|
-
if (
|
|
4364
|
-
|
|
4365
|
-
|
|
4366
|
-
|
|
4367
|
-
parsed.host = reescapeHostDelimiters(host, isIP2);
|
|
4368
|
-
}
|
|
4364
|
+
if (uri.indexOf("%") !== -1 && parsed.host !== void 0 && !malformedIPLiteral) {
|
|
4365
|
+
let host = isIP2 ? parsed.host : normalizePercentEncoding(parsed.host, true);
|
|
4366
|
+
if (!isIP2) {
|
|
4367
|
+
host = normalizePercentEncoding(host.toLowerCase());
|
|
4369
4368
|
}
|
|
4369
|
+
parsed.host = reescapeHostDelimiters(host, isIP2);
|
|
4370
|
+
}
|
|
4371
|
+
if (!schemeHandler || schemeHandler && !schemeHandler.skipNormalize) {
|
|
4370
4372
|
if (parsed.path) {
|
|
4371
4373
|
parsed.path = normalizePathEncoding(parsed.path);
|
|
4372
4374
|
}
|
|
@@ -12626,7 +12628,7 @@ var init_hookRegistry = __esm({
|
|
|
12626
12628
|
});
|
|
12627
12629
|
|
|
12628
12630
|
// ../linkque-agent-protocol/dist/esm/telemetry/telemetryEnums.js
|
|
12629
|
-
var ETelemetryAttribute, ETelemetryEventPrefix, ETelemetryEventPhase, ETelemetryEventName, ETelemetryOperationName, ETelemetryOutcome, ETelemetrySignal, ETelemetryLossReason, ETelemetryAdvanceOutcome, ETelemetryStreamTermination, ETelemetryCancelSource, ETelemetryObservationBoundary, ETelemetryRemoteCompletion, ETelemetryCommitStatus, ETelemetryHookMode, ETelemetryHookResult, ETelemetrySource, ETelemetryEvidence, ETelemetryCompleteness, ETelemetryCoverage, ETelemetryUsageSource, ETelemetryAttemptVisibility, ETelemetryLinkRelation, ETelemetryToolFailureStage, ETelemetryTerminalEvidence, ETelemetryTerminalSource, ETelemetryModelPurpose, ETelemetryErrorType, ETelemetrySpanKind, ETelemetryGenAiOperation, ETelemetryVersion;
|
|
12631
|
+
var ETelemetryAttribute, ETelemetryEventPrefix, ETelemetryEventPhase, ETelemetryEventName, ETelemetryContentSection, ETelemetryOperationName, ETelemetryOutcome, ETelemetrySignal, ETelemetryLossReason, ETelemetryAdvanceOutcome, ETelemetryStreamTermination, ETelemetryCancelSource, ETelemetryObservationBoundary, ETelemetryRemoteCompletion, ETelemetryCommitStatus, ETelemetryHookMode, ETelemetryHookResult, ETelemetrySource, ETelemetryEvidence, ETelemetryCompleteness, ETelemetryCoverage, ETelemetryUsageSource, ETelemetryAttemptVisibility, ETelemetryLinkRelation, ETelemetryToolFailureStage, ETelemetryTerminalEvidence, ETelemetryTerminalSource, ETelemetryModelPurpose, ETelemetryErrorType, ETelemetrySpanKind, ETelemetryGenAiOperation, ETelemetryVersion;
|
|
12630
12632
|
var init_telemetryEnums = __esm({
|
|
12631
12633
|
"../linkque-agent-protocol/dist/esm/telemetry/telemetryEnums.js"() {
|
|
12632
12634
|
"use strict";
|
|
@@ -12785,7 +12787,20 @@ var init_telemetryEnums = __esm({
|
|
|
12785
12787
|
ETelemetryEventName2["HISTORY_APPEND_FINISHED"] = "linkque.history.append.finished";
|
|
12786
12788
|
ETelemetryEventName2["HOOK_DRAIN_STARTED"] = "linkque.hook.drain.started";
|
|
12787
12789
|
ETelemetryEventName2["HOOK_DRAIN_FINISHED"] = "linkque.hook.drain.finished";
|
|
12790
|
+
ETelemetryEventName2["DEBUG_CONTENT_RECORDED"] = "linkque.debug.content.recorded";
|
|
12788
12791
|
})(ETelemetryEventName || (ETelemetryEventName = {}));
|
|
12792
|
+
(function(ETelemetryContentSection2) {
|
|
12793
|
+
ETelemetryContentSection2["QUERY_INPUT"] = "query.input";
|
|
12794
|
+
ETelemetryContentSection2["TOOL_INPUT"] = "tool.input";
|
|
12795
|
+
ETelemetryContentSection2["TOOL_OUTPUT"] = "tool.output";
|
|
12796
|
+
ETelemetryContentSection2["MCP_REQUESTED_INPUT"] = "mcp.requested_input";
|
|
12797
|
+
ETelemetryContentSection2["MCP_INPUT"] = "mcp.input";
|
|
12798
|
+
ETelemetryContentSection2["MCP_OUTPUT"] = "mcp.output";
|
|
12799
|
+
ETelemetryContentSection2["SKILL_INPUT"] = "skill.input";
|
|
12800
|
+
ETelemetryContentSection2["SKILL_OUTPUT"] = "skill.output";
|
|
12801
|
+
ETelemetryContentSection2["KNOWLEDGE_INPUT"] = "knowledge.input";
|
|
12802
|
+
ETelemetryContentSection2["KNOWLEDGE_OUTPUT"] = "knowledge.output";
|
|
12803
|
+
})(ETelemetryContentSection || (ETelemetryContentSection = {}));
|
|
12789
12804
|
(function(ETelemetryOperationName2) {
|
|
12790
12805
|
ETelemetryOperationName2["OPERATION"] = "linkque.operation";
|
|
12791
12806
|
ETelemetryOperationName2["TOOL_INVOKE"] = "harness.tool.invoke";
|
|
@@ -13868,7 +13883,8 @@ var init_runtimeConfigProvider = __esm({
|
|
|
13868
13883
|
LINKQUEGW_KNOWLEDGE_BASE_URL: LINKQUE_ENDPOINT_PROD,
|
|
13869
13884
|
LINKQUEGW_WEB_SEARCH_BASE_URL: LINKQUE_ENDPOINT_PROD,
|
|
13870
13885
|
LINKQUEGW_EVENT_BASE_URL: LINKQUE_ENDPOINT_PROD,
|
|
13871
|
-
LINKQUEGW_MCP_SIGN_ENDPOINT: `${LINKQUE_ENDPOINT_PROD}/api/mcp/signature
|
|
13886
|
+
LINKQUEGW_MCP_SIGN_ENDPOINT: `${LINKQUE_ENDPOINT_PROD}/api/mcp/signature`,
|
|
13887
|
+
LINKQUEGW_TOKEN_VERIFY_ENDPOINT: `${LINKQUE_ENDPOINT_PROD}/api/auth/verify`
|
|
13872
13888
|
});
|
|
13873
13889
|
RuntimeConfigProvider = class {
|
|
13874
13890
|
defaults;
|
|
@@ -14182,6 +14198,17 @@ var init_linkquegwEventHookExecutor = __esm({
|
|
|
14182
14198
|
}
|
|
14183
14199
|
});
|
|
14184
14200
|
|
|
14201
|
+
// ../linkque-agent-runtime/dist/esm/core/telemetry/contentRecording.js
|
|
14202
|
+
function recordContentSection(observation, section, value, availability = "available") {
|
|
14203
|
+
observation?.record(ETelemetryEventName.DEBUG_CONTENT_RECORDED, {}, { section, value, availability });
|
|
14204
|
+
}
|
|
14205
|
+
var init_contentRecording = __esm({
|
|
14206
|
+
"../linkque-agent-runtime/dist/esm/core/telemetry/contentRecording.js"() {
|
|
14207
|
+
"use strict";
|
|
14208
|
+
init_telemetry();
|
|
14209
|
+
}
|
|
14210
|
+
});
|
|
14211
|
+
|
|
14185
14212
|
// ../linkque-agent-runtime/dist/esm/core/skillTools.js
|
|
14186
14213
|
function parseSkillFile(raw, fallbackName) {
|
|
14187
14214
|
const parsed = splitFrontmatter(raw);
|
|
@@ -14250,18 +14277,43 @@ function createActivateSkillTool(records) {
|
|
|
14250
14277
|
required: ["name"],
|
|
14251
14278
|
additionalProperties: false
|
|
14252
14279
|
},
|
|
14253
|
-
execute: async (args) => {
|
|
14280
|
+
execute: async (args, _signal, context2) => {
|
|
14254
14281
|
const name = extractName(args);
|
|
14255
|
-
|
|
14282
|
+
const startedAt = Date.now();
|
|
14283
|
+
const obs = context2?.observation;
|
|
14284
|
+
recordContentSection(obs, ETelemetryContentSection.SKILL_INPUT, { name: name ?? null });
|
|
14285
|
+
if (!name) {
|
|
14286
|
+
recordContentSection(obs, ETelemetryContentSection.SKILL_OUTPUT, {
|
|
14287
|
+
status: "failed",
|
|
14288
|
+
error: "\u7F3A\u5C11 name \u53C2\u6570",
|
|
14289
|
+
durationMs: Date.now() - startedAt
|
|
14290
|
+
});
|
|
14256
14291
|
return "\u6FC0\u6D3B\u6280\u80FD\u5931\u8D25:\u7F3A\u5C11 name \u53C2\u6570\u3002";
|
|
14292
|
+
}
|
|
14257
14293
|
if (!bodyByName.has(name)) {
|
|
14294
|
+
recordContentSection(obs, ETelemetryContentSection.SKILL_OUTPUT, {
|
|
14295
|
+
name,
|
|
14296
|
+
status: "failed",
|
|
14297
|
+
error: `\u672A\u627E\u5230\u6280\u80FD "${name}"`,
|
|
14298
|
+
durationMs: Date.now() - startedAt
|
|
14299
|
+
});
|
|
14258
14300
|
return `\u6FC0\u6D3B\u6280\u80FD\u5931\u8D25:\u672A\u627E\u5230\u6280\u80FD "${name}"\u3002\u53EF\u7528:${[...bodyByName.keys()].join(", ")}`;
|
|
14259
14301
|
}
|
|
14260
14302
|
if (activated.has(name)) {
|
|
14303
|
+
recordContentSection(obs, ETelemetryContentSection.SKILL_OUTPUT, {
|
|
14304
|
+
name,
|
|
14305
|
+
status: "already_loaded",
|
|
14306
|
+
durationMs: Date.now() - startedAt
|
|
14307
|
+
});
|
|
14261
14308
|
return `\u6280\u80FD "${name}" \u5DF2\u5728\u672C\u8F6E\u52A0\u8F7D,\u65E0\u9700\u91CD\u590D\u6FC0\u6D3B\u3002`;
|
|
14262
14309
|
}
|
|
14263
14310
|
activated.add(name);
|
|
14264
14311
|
const body = bodyByName.get(name) ?? "";
|
|
14312
|
+
recordContentSection(obs, ETelemetryContentSection.SKILL_OUTPUT, {
|
|
14313
|
+
name,
|
|
14314
|
+
status: "loaded",
|
|
14315
|
+
durationMs: Date.now() - startedAt
|
|
14316
|
+
});
|
|
14265
14317
|
return `<skill name="${escapeXml(name)}">
|
|
14266
14318
|
${body}
|
|
14267
14319
|
</skill>`;
|
|
@@ -14319,6 +14371,8 @@ var ACTIVATE_SKILL_TOOL_NAME, AVAILABLE_SKILLS_OPEN, AVAILABLE_SKILLS_CLOSE;
|
|
|
14319
14371
|
var init_skillTools = __esm({
|
|
14320
14372
|
"../linkque-agent-runtime/dist/esm/core/skillTools.js"() {
|
|
14321
14373
|
"use strict";
|
|
14374
|
+
init_telemetry();
|
|
14375
|
+
init_contentRecording();
|
|
14322
14376
|
ACTIVATE_SKILL_TOOL_NAME = "activate_skill";
|
|
14323
14377
|
AVAILABLE_SKILLS_OPEN = "<available_skills>";
|
|
14324
14378
|
AVAILABLE_SKILLS_CLOSE = "</available_skills>";
|
|
@@ -14546,7 +14600,7 @@ function createKnowledgeTools(resources, searchPort, agentId) {
|
|
|
14546
14600
|
additionalProperties: false
|
|
14547
14601
|
},
|
|
14548
14602
|
annotations: { readOnlyHint: true },
|
|
14549
|
-
execute: () => listKnowledge()
|
|
14603
|
+
execute: (_args, _signal, context2) => listKnowledge(context2)
|
|
14550
14604
|
},
|
|
14551
14605
|
{
|
|
14552
14606
|
name: KNOWLEDGE_RECALL_TOOL_NAME,
|
|
@@ -14573,24 +14627,46 @@ function createKnowledgeTools(resources, searchPort, agentId) {
|
|
|
14573
14627
|
additionalProperties: false
|
|
14574
14628
|
},
|
|
14575
14629
|
annotations: { readOnlyHint: true },
|
|
14576
|
-
execute: (args, signal) => recallKnowledge(args, signal)
|
|
14630
|
+
execute: (args, signal, context2) => recallKnowledge(args, signal, context2)
|
|
14577
14631
|
}
|
|
14578
14632
|
];
|
|
14579
|
-
async function listKnowledge() {
|
|
14580
|
-
|
|
14633
|
+
async function listKnowledge(context2) {
|
|
14634
|
+
const result = { knowledgeBases: await getKnowledgeBases() };
|
|
14635
|
+
recordContentSection(context2?.observation, ETelemetryContentSection.KNOWLEDGE_OUTPUT, {
|
|
14636
|
+
knowledgeBases: result.knowledgeBases.map((kb) => ({
|
|
14637
|
+
knowledgeBaseId: kb.knowledgeBaseId,
|
|
14638
|
+
knowledgeDesc: kb.knowledgeDesc
|
|
14639
|
+
}))
|
|
14640
|
+
});
|
|
14641
|
+
return result;
|
|
14581
14642
|
}
|
|
14582
|
-
async function recallKnowledge(args, signal) {
|
|
14643
|
+
async function recallKnowledge(args, signal, context2) {
|
|
14583
14644
|
const parsed = parseRecallArgs(args);
|
|
14645
|
+
const obs = context2?.observation;
|
|
14584
14646
|
if ("error" in parsed) {
|
|
14647
|
+
recordContentSection(obs, ETelemetryContentSection.KNOWLEDGE_INPUT, {
|
|
14648
|
+
error: parsed.error
|
|
14649
|
+
});
|
|
14650
|
+
recordContentSection(obs, ETelemetryContentSection.KNOWLEDGE_OUTPUT, {
|
|
14651
|
+
hits: [],
|
|
14652
|
+
error: parsed.error
|
|
14653
|
+
});
|
|
14585
14654
|
return { hits: [], error: parsed.error };
|
|
14586
14655
|
}
|
|
14656
|
+
recordContentSection(obs, ETelemetryContentSection.KNOWLEDGE_INPUT, {
|
|
14657
|
+
knowledgeBaseId: parsed.knowledgeBaseId,
|
|
14658
|
+
query: parsed.query,
|
|
14659
|
+
topK: parsed.topK
|
|
14660
|
+
});
|
|
14587
14661
|
const knowledgeBases = await getKnowledgeBases();
|
|
14588
14662
|
const bound = knowledgeBases.some((info) => info.knowledgeBaseId === parsed.knowledgeBaseId);
|
|
14589
14663
|
if (!bound) {
|
|
14590
|
-
|
|
14664
|
+
const error40 = `knowledgeBaseId \u672A\u7ED1\u5B9A: ${parsed.knowledgeBaseId}\u3002\u8BF7\u5148\u8C03\u7528 knowledge_list \u67E5\u770B\u53EF\u7528\u77E5\u8BC6\u5E93\u3002`;
|
|
14665
|
+
recordContentSection(obs, ETelemetryContentSection.KNOWLEDGE_OUTPUT, {
|
|
14591
14666
|
hits: [],
|
|
14592
|
-
error:
|
|
14593
|
-
};
|
|
14667
|
+
error: error40
|
|
14668
|
+
});
|
|
14669
|
+
return { hits: [], error: error40 };
|
|
14594
14670
|
}
|
|
14595
14671
|
try {
|
|
14596
14672
|
const result = await searchPort.search({
|
|
@@ -14599,10 +14675,18 @@ function createKnowledgeTools(resources, searchPort, agentId) {
|
|
|
14599
14675
|
agentId,
|
|
14600
14676
|
topK: parsed.topK
|
|
14601
14677
|
}, signal);
|
|
14678
|
+
recordContentSection(obs, ETelemetryContentSection.KNOWLEDGE_OUTPUT, {
|
|
14679
|
+
hits: result.hits
|
|
14680
|
+
});
|
|
14602
14681
|
return { hits: result.hits };
|
|
14603
14682
|
} catch (e2) {
|
|
14604
14683
|
const msg = e2 instanceof Error ? e2.message : String(e2);
|
|
14605
|
-
|
|
14684
|
+
const error40 = `\u77E5\u8BC6\u5E93\u68C0\u7D22\u5931\u8D25: ${msg}`;
|
|
14685
|
+
recordContentSection(obs, ETelemetryContentSection.KNOWLEDGE_OUTPUT, {
|
|
14686
|
+
hits: [],
|
|
14687
|
+
error: error40
|
|
14688
|
+
});
|
|
14689
|
+
return { hits: [], error: error40 };
|
|
14606
14690
|
}
|
|
14607
14691
|
}
|
|
14608
14692
|
async function getKnowledgeBases() {
|
|
@@ -14616,6 +14700,8 @@ var init_createKnowledgeTools = __esm({
|
|
|
14616
14700
|
"../linkque-agent-runtime/dist/esm/core/createKnowledgeTools.js"() {
|
|
14617
14701
|
"use strict";
|
|
14618
14702
|
init_knowledgeTools();
|
|
14703
|
+
init_telemetry();
|
|
14704
|
+
init_contentRecording();
|
|
14619
14705
|
}
|
|
14620
14706
|
});
|
|
14621
14707
|
|
|
@@ -14646,7 +14732,7 @@ var init_noopRuntimeTelemetry = __esm({
|
|
|
14646
14732
|
startOperation(_operation) {
|
|
14647
14733
|
return this;
|
|
14648
14734
|
}
|
|
14649
|
-
record(_name, _attributes) {
|
|
14735
|
+
record(_name, _attributes, _body) {
|
|
14650
14736
|
}
|
|
14651
14737
|
finish(_outcome, _attributes) {
|
|
14652
14738
|
}
|
|
@@ -14744,7 +14830,7 @@ var init_runtimeObservation = __esm({
|
|
|
14744
14830
|
find(key) {
|
|
14745
14831
|
return this.associations.get(key);
|
|
14746
14832
|
}
|
|
14747
|
-
record(name, attributes) {
|
|
14833
|
+
record(name, attributes, body) {
|
|
14748
14834
|
if (this.abandoned)
|
|
14749
14835
|
return;
|
|
14750
14836
|
try {
|
|
@@ -14752,7 +14838,7 @@ var init_runtimeObservation = __esm({
|
|
|
14752
14838
|
this.resultAttributes = {
|
|
14753
14839
|
[ETelemetryAttribute.LINKQUE_TOOL_FAILURE_STAGE]: attributes[ETelemetryAttribute.LINKQUE_TOOL_FAILURE_STAGE]
|
|
14754
14840
|
};
|
|
14755
|
-
this.sink.record(name, attributes);
|
|
14841
|
+
this.sink.record(name, attributes, body);
|
|
14756
14842
|
} catch {
|
|
14757
14843
|
}
|
|
14758
14844
|
}
|
|
@@ -49052,8 +49138,19 @@ function observeTool(tool, observation) {
|
|
|
49052
49138
|
detached: false,
|
|
49053
49139
|
links: []
|
|
49054
49140
|
});
|
|
49141
|
+
const captureBody = !isSkillTool(tool);
|
|
49055
49142
|
try {
|
|
49056
|
-
|
|
49143
|
+
if (captureBody) {
|
|
49144
|
+
recordContentSection(operation, ETelemetryContentSection.TOOL_INPUT, args);
|
|
49145
|
+
}
|
|
49146
|
+
const execContext = {
|
|
49147
|
+
...context2 ?? { toolCallId: "", emit: () => void 0 },
|
|
49148
|
+
observation: operation
|
|
49149
|
+
};
|
|
49150
|
+
const result = await tool.execute(args, signal, execContext);
|
|
49151
|
+
if (captureBody) {
|
|
49152
|
+
recordContentSection(operation, ETelemetryContentSection.TOOL_OUTPUT, result);
|
|
49153
|
+
}
|
|
49057
49154
|
operation.finish(toolResultOutcome(result), {
|
|
49058
49155
|
[ETelemetryAttribute.HARNESS_TOOL_RESULT_STATUS]: toolResultOutcome(result)
|
|
49059
49156
|
});
|
|
@@ -49071,13 +49168,16 @@ function observeTool(tool, observation) {
|
|
|
49071
49168
|
}
|
|
49072
49169
|
};
|
|
49073
49170
|
}
|
|
49074
|
-
var import_node_crypto6;
|
|
49171
|
+
var import_node_crypto6, isSkillTool;
|
|
49075
49172
|
var init_toolObservation = __esm({
|
|
49076
49173
|
"../linkque-agent-runtime/dist/esm/core/telemetry/toolObservation.js"() {
|
|
49077
49174
|
"use strict";
|
|
49078
49175
|
init_telemetry();
|
|
49079
49176
|
init_telemetryEnums2();
|
|
49177
|
+
init_skillTools();
|
|
49080
49178
|
import_node_crypto6 = require("node:crypto");
|
|
49179
|
+
init_contentRecording();
|
|
49180
|
+
isSkillTool = (tool) => (tool.modelName ?? tool.name) === ACTIVATE_SKILL_TOOL_NAME;
|
|
49081
49181
|
}
|
|
49082
49182
|
});
|
|
49083
49183
|
|
|
@@ -207316,11 +207416,32 @@ var init_agentRuntime = __esm({
|
|
|
207316
207416
|
}
|
|
207317
207417
|
}, (observation) => this.runObservedAdvance(request, auth2, options, observation), options.signal);
|
|
207318
207418
|
}
|
|
207419
|
+
/**
|
|
207420
|
+
* 记录本次用户输入(RFC §4.1):取进入 Runtime 的本次新消息中最后一条 user message
|
|
207421
|
+
* 的 content,作为 `linkque.debug.content.recorded` 的 body 走 record 链路落入
|
|
207422
|
+
* OTLP logs(body 含 section/value/availability)。不以模型 messages 上下文为输入;
|
|
207423
|
+
* 无 user 文本(卡片交互等)时按可用性如实标记,不伪造自然语言 Query。
|
|
207424
|
+
*/
|
|
207425
|
+
recordCurrentQuery(observation, request) {
|
|
207426
|
+
let lastUser;
|
|
207427
|
+
for (const message of request.messages) {
|
|
207428
|
+
if (message.role === "user")
|
|
207429
|
+
lastUser = message;
|
|
207430
|
+
}
|
|
207431
|
+
const text2 = typeof lastUser?.content === "string" ? lastUser.content : "";
|
|
207432
|
+
const body = {
|
|
207433
|
+
section: ETelemetryContentSection.QUERY_INPUT,
|
|
207434
|
+
value: text2,
|
|
207435
|
+
availability: text2 ? "available" : "not_recorded"
|
|
207436
|
+
};
|
|
207437
|
+
observation.record(ETelemetryEventName.DEBUG_CONTENT_RECORDED, {}, body);
|
|
207438
|
+
}
|
|
207319
207439
|
async *runObservedAdvance(request, auth2, options, observation) {
|
|
207320
207440
|
observation.record(ETelemetryEventName.TELEMETRY_COVERAGE, {
|
|
207321
207441
|
[ETelemetryAttribute.LINKQUE_TELEMETRY_COVERAGE]: this.agentLoop instanceof PiAgentLoop ? ETelemetryCoverage.PI_MODEL_TOOL_HOOK : ETelemetryCoverage.CORE_ONLY,
|
|
207322
207442
|
[ETelemetryAttribute.HARNESS_TELEMETRY_COMPLETENESS]: this.agentLoop instanceof PiAgentLoop ? ETelemetryCompleteness.COMPLETE : ETelemetryCompleteness.PARTIAL
|
|
207323
207443
|
});
|
|
207444
|
+
this.recordCurrentQuery(observation, request);
|
|
207324
207445
|
const cleanup = [];
|
|
207325
207446
|
let termination = ETelemetryStreamTermination.CANCEL;
|
|
207326
207447
|
let failed = false;
|
|
@@ -212491,6 +212612,53 @@ function sleep(ms) {
|
|
|
212491
212612
|
});
|
|
212492
212613
|
}
|
|
212493
212614
|
|
|
212615
|
+
// ../linkque-agent-runtime/dist/esm/impl/mcp/alipay/mcpInvocationContext.js
|
|
212616
|
+
var import_node_async_hooks = require("node:async_hooks");
|
|
212617
|
+
async function waitForMcpOperation(operation, signal) {
|
|
212618
|
+
signal.throwIfAborted();
|
|
212619
|
+
let onAbort = () => {
|
|
212620
|
+
};
|
|
212621
|
+
try {
|
|
212622
|
+
return await Promise.race([
|
|
212623
|
+
new Promise((_, reject) => {
|
|
212624
|
+
onAbort = () => reject(signal.reason);
|
|
212625
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
212626
|
+
}),
|
|
212627
|
+
Promise.resolve().then(() => {
|
|
212628
|
+
signal.throwIfAborted();
|
|
212629
|
+
return operation();
|
|
212630
|
+
})
|
|
212631
|
+
]);
|
|
212632
|
+
} finally {
|
|
212633
|
+
signal.removeEventListener("abort", onAbort);
|
|
212634
|
+
}
|
|
212635
|
+
}
|
|
212636
|
+
var McpInvocationContext = class {
|
|
212637
|
+
storage = new import_node_async_hooks.AsyncLocalStorage();
|
|
212638
|
+
current() {
|
|
212639
|
+
return this.storage.getStore();
|
|
212640
|
+
}
|
|
212641
|
+
async run(timeoutMs, signal, operation) {
|
|
212642
|
+
if (!Number.isFinite(timeoutMs) || timeoutMs <= 0)
|
|
212643
|
+
throw new Error("MCP \u8D85\u65F6\u5FC5\u987B\u4E3A\u6709\u9650\u6B63\u6570");
|
|
212644
|
+
signal?.throwIfAborted();
|
|
212645
|
+
const controller = new AbortController();
|
|
212646
|
+
const context2 = {
|
|
212647
|
+
signal: signal ? AbortSignal.any([signal, controller.signal]) : controller.signal,
|
|
212648
|
+
deadline: performance.now() + timeoutMs
|
|
212649
|
+
};
|
|
212650
|
+
const timer = setTimeout(() => controller.abort(new DOMException("MCP \u8C03\u7528\u603B\u9884\u7B97\u5DF2\u8017\u5C3D", "TimeoutError")), Math.min(timeoutMs, 2147483647));
|
|
212651
|
+
try {
|
|
212652
|
+
return await this.storage.run(context2, () => waitForMcpOperation(() => operation(context2), context2.signal));
|
|
212653
|
+
} catch (error40) {
|
|
212654
|
+
context2.signal.throwIfAborted();
|
|
212655
|
+
throw error40;
|
|
212656
|
+
} finally {
|
|
212657
|
+
clearTimeout(timer);
|
|
212658
|
+
}
|
|
212659
|
+
}
|
|
212660
|
+
};
|
|
212661
|
+
|
|
212494
212662
|
// ../linkque-agent-runtime/dist/esm/impl/mcp/alipay/remoteSignatureSigner.js
|
|
212495
212663
|
init_config();
|
|
212496
212664
|
init_httpLoggingFetch();
|
|
@@ -212499,11 +212667,13 @@ var RemoteSignatureSigner = class {
|
|
|
212499
212667
|
agentId;
|
|
212500
212668
|
signEndpoint;
|
|
212501
212669
|
fetchImpl;
|
|
212670
|
+
rawFetch;
|
|
212502
212671
|
getAuthorizationHeader;
|
|
212503
212672
|
constructor(options) {
|
|
212504
212673
|
this.agentId = options.agentId;
|
|
212505
212674
|
this.signEndpoint = options.signEndpoint ?? DEFAULT_SIGN_ENDPOINT;
|
|
212506
212675
|
const baseFetch = options.fetchImpl ?? globalThis.fetch;
|
|
212676
|
+
this.rawFetch = baseFetch;
|
|
212507
212677
|
this.fetchImpl = options.debugLog ? createHttpLoggingFetch(options.debugLog, "mcp-sign", baseFetch) : baseFetch;
|
|
212508
212678
|
this.getAuthorizationHeader = options.getAuthorizationHeader;
|
|
212509
212679
|
}
|
|
@@ -212514,7 +212684,8 @@ var RemoteSignatureSigner = class {
|
|
|
212514
212684
|
* @returns `{authorization, signatureContent, userId?}`
|
|
212515
212685
|
* @throws 签名服务非 2xx / 鉴权头获取失败 / 响应缺字段时抛错(由 signingFetch 转 transport-error)。
|
|
212516
212686
|
*/
|
|
212517
|
-
async sign(req) {
|
|
212687
|
+
async sign(req, options = {}) {
|
|
212688
|
+
options.signal?.throwIfAborted();
|
|
212518
212689
|
const body = JSON.stringify({
|
|
212519
212690
|
agentId: this.agentId,
|
|
212520
212691
|
httpMethod: req.httpMethod,
|
|
@@ -212525,16 +212696,16 @@ var RemoteSignatureSigner = class {
|
|
|
212525
212696
|
"content-type": "application/json",
|
|
212526
212697
|
"x-linkque-agent-id": this.agentId
|
|
212527
212698
|
};
|
|
212528
|
-
if (
|
|
212529
|
-
headers.authorization =
|
|
212699
|
+
if (options.authorizationHeader !== void 0) {
|
|
212700
|
+
headers.authorization = options.authorizationHeader;
|
|
212701
|
+
} else if (this.getAuthorizationHeader) {
|
|
212702
|
+
headers.authorization = options.signal ? await waitForMcpOperation(() => this.getAuthorizationHeader(), options.signal) : await this.getAuthorizationHeader();
|
|
212530
212703
|
}
|
|
212531
|
-
|
|
212532
|
-
|
|
212533
|
-
|
|
212534
|
-
body
|
|
212535
|
-
});
|
|
212704
|
+
options.signal?.throwIfAborted();
|
|
212705
|
+
const resp = await (options.sensitive ? this.rawFetch : this.fetchImpl)(this.signEndpoint, { method: "POST", headers, body, signal: options.signal });
|
|
212706
|
+
options.signal?.throwIfAborted();
|
|
212536
212707
|
if (!resp.ok) {
|
|
212537
|
-
const text2 = await safeText(resp);
|
|
212708
|
+
const text2 = options.sensitive ? "" : await safeText(resp);
|
|
212538
212709
|
throw new Error(`linkquegw \u7B7E\u540D\u670D\u52A1\u5931\u8D25: status=${resp.status}${text2 ? ` body=${text2}` : ""}`);
|
|
212539
212710
|
}
|
|
212540
212711
|
const parsed = await resp.json().catch(() => ({}));
|
|
@@ -212575,7 +212746,7 @@ function extractFromWrapped(wrapped) {
|
|
|
212575
212746
|
};
|
|
212576
212747
|
}
|
|
212577
212748
|
function optionalUserId(value) {
|
|
212578
|
-
return typeof value === "string" && value.trim() ? { userId: value
|
|
212749
|
+
return typeof value === "string" && value.trim() ? { userId: value } : {};
|
|
212579
212750
|
}
|
|
212580
212751
|
async function safeText(resp) {
|
|
212581
212752
|
try {
|
|
@@ -214120,20 +214291,42 @@ var SSEClientTransport = class {
|
|
|
214120
214291
|
}
|
|
214121
214292
|
};
|
|
214122
214293
|
|
|
214294
|
+
// ../linkque-agent-runtime/dist/esm/impl/mcp/alipay/mcpInvocationError.js
|
|
214295
|
+
var McpInvocationError = class extends Error {
|
|
214296
|
+
code;
|
|
214297
|
+
constructor(code, message) {
|
|
214298
|
+
super(`${code}: ${message}`);
|
|
214299
|
+
this.code = code;
|
|
214300
|
+
this.name = "McpInvocationError";
|
|
214301
|
+
}
|
|
214302
|
+
};
|
|
214303
|
+
|
|
214123
214304
|
// ../linkque-agent-runtime/dist/esm/impl/mcp/alipay/signingFetch.js
|
|
214124
214305
|
init_httpLoggingFetch();
|
|
214125
214306
|
var ALIPAY_SDK_VERSION = "@alipay/open-mcp-server-2.0.4";
|
|
214126
214307
|
var OAGW_ALIPAY_UID_HEADER = "x-oagw-alipay-uid";
|
|
214127
|
-
function createSigningFetch(signer, baseFetch = globalThis.fetch, onTraceId, debugLog, getCallHeaders) {
|
|
214308
|
+
function createSigningFetch(signer, baseFetch = globalThis.fetch, onTraceId, debugLog, getCallHeaders, invocationContext) {
|
|
214128
214309
|
const loggedFetch = debugLog ? createHttpLoggingFetch(debugLog, "mcp-call", baseFetch) : baseFetch;
|
|
214129
214310
|
return async (url2, init) => {
|
|
214311
|
+
const invocation = invocationContext?.current();
|
|
214312
|
+
const signals = [init?.signal, invocation?.signal].filter((signal2) => !!signal2);
|
|
214313
|
+
const signal = signals.length ? AbortSignal.any(signals) : void 0;
|
|
214314
|
+
signal?.throwIfAborted();
|
|
214130
214315
|
const targetUrl = url2 instanceof URL ? url2 : new URL(typeof url2 === "string" ? url2 : url2.url);
|
|
214131
214316
|
const req = {
|
|
214132
214317
|
httpMethod: init?.method ?? "GET",
|
|
214133
214318
|
httpRequestUrl: targetUrl.pathname + targetUrl.search,
|
|
214134
214319
|
httpRequestBody: typeof init?.body === "string" ? init.body : ""
|
|
214135
214320
|
};
|
|
214136
|
-
const { authorization, signatureContent, userId } = await signer.sign(req
|
|
214321
|
+
const { authorization, signatureContent, userId } = await signer.sign(req, {
|
|
214322
|
+
authorizationHeader: invocation?.auth?.authorization,
|
|
214323
|
+
signal,
|
|
214324
|
+
sensitive: !!invocation?.auth
|
|
214325
|
+
});
|
|
214326
|
+
signal?.throwIfAborted();
|
|
214327
|
+
if (invocation?.auth && userId !== invocation.auth.userId) {
|
|
214328
|
+
throw new McpInvocationError("MCP_IDENTITY_MISMATCH", "\u7B7E\u540D\u8EAB\u4EFD\u4E0E\u6821\u9A8C\u8EAB\u4EFD\u4E0D\u4E00\u81F4");
|
|
214329
|
+
}
|
|
214137
214330
|
const headers = new Headers(init?.headers);
|
|
214138
214331
|
headers.set("Authorization", authorization);
|
|
214139
214332
|
headers.set("X-Signature-Content", Buffer.from(signatureContent).toString("base64"));
|
|
@@ -214150,7 +214343,11 @@ function createSigningFetch(signer, baseFetch = globalThis.fetch, onTraceId, deb
|
|
|
214150
214343
|
else
|
|
214151
214344
|
headers.delete("x-alipay-authcode");
|
|
214152
214345
|
}
|
|
214153
|
-
const resp = await loggedFetch(url2, {
|
|
214346
|
+
const resp = await (invocation?.auth ? baseFetch : loggedFetch)(url2, {
|
|
214347
|
+
...init,
|
|
214348
|
+
headers,
|
|
214349
|
+
...signal ? { signal } : {}
|
|
214350
|
+
});
|
|
214154
214351
|
if (onTraceId) {
|
|
214155
214352
|
try {
|
|
214156
214353
|
const traceId = resp.headers.get("alipay-trace-id");
|
|
@@ -214178,10 +214375,10 @@ function withTimeout(fetch3, timeoutMs) {
|
|
|
214178
214375
|
return fetch3(url2, { ...init, signal });
|
|
214179
214376
|
};
|
|
214180
214377
|
}
|
|
214181
|
-
function createSseTransport(config2, signer, onTraceId, debugLog, getCallHeaders) {
|
|
214378
|
+
function createSseTransport(config2, signer, onTraceId, debugLog, getCallHeaders, invocationContext) {
|
|
214182
214379
|
const url2 = new URL(config2.sseEndpoint, config2.remoteBaseUrl);
|
|
214183
214380
|
const timeoutMs = config2.requestTimeoutMs ?? 18e4;
|
|
214184
|
-
const signingFetch = withTimeout(createSigningFetch(signer, void 0, onTraceId, debugLog, getCallHeaders), timeoutMs);
|
|
214381
|
+
const signingFetch = withTimeout(createSigningFetch(signer, void 0, onTraceId, debugLog, getCallHeaders, invocationContext), timeoutMs);
|
|
214185
214382
|
return new SSEClientTransport(url2, {
|
|
214186
214383
|
// SSE 建连(EventSource)的 GET fetch:SDK 先包默认头再调这里。
|
|
214187
214384
|
eventSourceInit: { fetch: signingFetch },
|
|
@@ -214192,6 +214389,17 @@ function createSseTransport(config2, signer, onTraceId, debugLog, getCallHeaders
|
|
|
214192
214389
|
|
|
214193
214390
|
// ../linkque-agent-runtime/dist/esm/impl/mcp/alipay/argsMapper.js
|
|
214194
214391
|
init_esm();
|
|
214392
|
+
var USER_ID = Symbol("\u7CFB\u7EDF\u53D8\u91CF\u7528\u6237\u6807\u8BC6");
|
|
214393
|
+
function assertSafePath(segments) {
|
|
214394
|
+
if (segments.some((s2) => ["__proto__", "constructor", "prototype"].includes(String(s2)))) {
|
|
214395
|
+
throw new McpInvocationError("MCP_SYSTEM_VARIABLE_INVALID", "\u6620\u5C04\u8DEF\u5F84\u7981\u6B62\u8BBF\u95EE\u539F\u578B");
|
|
214396
|
+
}
|
|
214397
|
+
}
|
|
214398
|
+
function assertContainer(value) {
|
|
214399
|
+
if (value === null || typeof value !== "object") {
|
|
214400
|
+
throw new McpInvocationError("MCP_SYSTEM_VARIABLE_INVALID", "\u6620\u5C04\u8DEF\u5F84\u4E0D\u53EF\u5199");
|
|
214401
|
+
}
|
|
214402
|
+
}
|
|
214195
214403
|
function parsePath(path9) {
|
|
214196
214404
|
if (path9 === "")
|
|
214197
214405
|
return [];
|
|
@@ -214216,50 +214424,60 @@ function parsePath(path9) {
|
|
|
214216
214424
|
return segments;
|
|
214217
214425
|
}
|
|
214218
214426
|
function getByPath(obj, segments) {
|
|
214427
|
+
assertSafePath(segments);
|
|
214219
214428
|
let cur = obj;
|
|
214220
214429
|
for (const seg of segments) {
|
|
214221
214430
|
if (cur === null || cur === void 0)
|
|
214222
214431
|
return void 0;
|
|
214223
|
-
cur = cur[seg];
|
|
214432
|
+
cur = Object.hasOwn(Object(cur), seg) ? cur[seg] : void 0;
|
|
214224
214433
|
}
|
|
214225
214434
|
return cur;
|
|
214226
214435
|
}
|
|
214227
214436
|
function setByPath(obj, segments, value) {
|
|
214437
|
+
assertSafePath(segments);
|
|
214228
214438
|
if (segments.length === 0)
|
|
214229
214439
|
return;
|
|
214230
214440
|
let cur = obj;
|
|
214231
214441
|
for (let i2 = 0; i2 < segments.length - 1; i2 += 1) {
|
|
214232
214442
|
const seg = segments[i2];
|
|
214233
214443
|
const next = segments[i2 + 1];
|
|
214234
|
-
|
|
214444
|
+
assertContainer(cur);
|
|
214445
|
+
const existing = Object.hasOwn(cur, seg) ? cur[seg] : void 0;
|
|
214235
214446
|
if (existing === null || existing === void 0) {
|
|
214236
214447
|
cur[seg] = typeof next === "number" ? [] : {};
|
|
214237
214448
|
}
|
|
214238
214449
|
cur = cur[seg];
|
|
214239
214450
|
}
|
|
214240
214451
|
const last = segments[segments.length - 1];
|
|
214241
|
-
cur
|
|
214452
|
+
assertContainer(cur);
|
|
214453
|
+
Object.defineProperty(cur, last, {
|
|
214454
|
+
value,
|
|
214455
|
+
enumerable: true,
|
|
214456
|
+
writable: true,
|
|
214457
|
+
configurable: true
|
|
214458
|
+
});
|
|
214242
214459
|
}
|
|
214243
214460
|
function unsetByPath(obj, segments) {
|
|
214461
|
+
assertSafePath(segments);
|
|
214244
214462
|
if (segments.length === 0)
|
|
214245
214463
|
return;
|
|
214246
214464
|
let cur = obj;
|
|
214247
214465
|
for (let i2 = 0; i2 < segments.length - 1; i2 += 1) {
|
|
214248
214466
|
const seg = segments[i2];
|
|
214249
|
-
cur
|
|
214467
|
+
assertContainer(cur);
|
|
214468
|
+
cur = Object.hasOwn(cur, seg) ? cur[seg] : void 0;
|
|
214250
214469
|
if (cur === null || cur === void 0)
|
|
214251
214470
|
return;
|
|
214252
214471
|
}
|
|
214253
214472
|
const last = segments[segments.length - 1];
|
|
214254
214473
|
if (cur !== void 0) {
|
|
214474
|
+
assertContainer(cur);
|
|
214255
214475
|
delete cur[last];
|
|
214256
214476
|
}
|
|
214257
214477
|
}
|
|
214258
|
-
function
|
|
214478
|
+
function createArgsMappingPlan(toolName, args, rules) {
|
|
214259
214479
|
const out = args ? JSON.parse(JSON.stringify(args)) : {};
|
|
214260
|
-
|
|
214261
|
-
return out;
|
|
214262
|
-
for (const rule of rules) {
|
|
214480
|
+
for (const rule of rules ?? []) {
|
|
214263
214481
|
if (rule.mcpToolName !== toolName)
|
|
214264
214482
|
continue;
|
|
214265
214483
|
const segments = parsePath(rule.argJsonPath);
|
|
@@ -214267,6 +214485,13 @@ function applyArgsMappingRules(toolName, args, rules) {
|
|
|
214267
214485
|
unsetByPath(out, segments);
|
|
214268
214486
|
continue;
|
|
214269
214487
|
}
|
|
214488
|
+
if (rule.valueType === EArgsMappingValueType.SYSTEM_VARIABLE) {
|
|
214489
|
+
if (rule.value !== "${userId}" || segments.length === 0) {
|
|
214490
|
+
throw new McpInvocationError("MCP_SYSTEM_VARIABLE_INVALID", "\u7CFB\u7EDF\u53D8\u91CF\u914D\u7F6E\u65E0\u6548");
|
|
214491
|
+
}
|
|
214492
|
+
setByPath(out, segments, USER_ID);
|
|
214493
|
+
continue;
|
|
214494
|
+
}
|
|
214270
214495
|
if (rule.valueType === EArgsMappingValueType.CONST) {
|
|
214271
214496
|
setByPath(out, segments, rule.value);
|
|
214272
214497
|
continue;
|
|
@@ -214278,14 +214503,85 @@ function applyArgsMappingRules(toolName, args, rules) {
|
|
|
214278
214503
|
continue;
|
|
214279
214504
|
}
|
|
214280
214505
|
}
|
|
214281
|
-
|
|
214506
|
+
const contains = (value) => value === USER_ID || value !== null && typeof value === "object" && Object.values(value).some(contains);
|
|
214507
|
+
const requiresUserId = contains(out);
|
|
214508
|
+
return {
|
|
214509
|
+
requiresUserId,
|
|
214510
|
+
resolve(identity) {
|
|
214511
|
+
if (requiresUserId && !identity?.userId?.trim()) {
|
|
214512
|
+
throw new McpInvocationError("MCP_USER_AUTH_REQUIRED", "\u7CFB\u7EDF\u53D8\u91CF\u9700\u8981\u53EF\u4FE1\u7528\u6237\u8EAB\u4EFD");
|
|
214513
|
+
}
|
|
214514
|
+
const visit = (value) => {
|
|
214515
|
+
if (value === USER_ID)
|
|
214516
|
+
return identity.userId;
|
|
214517
|
+
if (Array.isArray(value))
|
|
214518
|
+
return value.map(visit);
|
|
214519
|
+
if (value !== null && typeof value === "object") {
|
|
214520
|
+
return Object.fromEntries(Object.entries(value).map(([key, item]) => [key, visit(item)]));
|
|
214521
|
+
}
|
|
214522
|
+
return value;
|
|
214523
|
+
};
|
|
214524
|
+
return visit(out);
|
|
214525
|
+
}
|
|
214526
|
+
};
|
|
214527
|
+
}
|
|
214528
|
+
function resolveArgsMappingPlan(plan, identity) {
|
|
214529
|
+
return plan.resolve(identity);
|
|
214282
214530
|
}
|
|
214283
214531
|
|
|
214284
214532
|
// ../linkque-agent-runtime/dist/esm/impl/mcp/alipay/index.js
|
|
214285
214533
|
init_esm();
|
|
214286
214534
|
|
|
214287
214535
|
// ../linkque-agent-runtime/dist/esm/impl/mcp/alipay/remoteGatewayMcpServer.js
|
|
214288
|
-
var
|
|
214536
|
+
var import_node_async_hooks2 = require("node:async_hooks");
|
|
214537
|
+
|
|
214538
|
+
// ../linkque-agent-runtime/dist/esm/impl/mcp/alipay/linkquegwTokenVerifier.js
|
|
214539
|
+
init_config();
|
|
214540
|
+
function assertMcpUserAuthorization(authorization) {
|
|
214541
|
+
if (!/^Bearer\s+\S+$/i.test(authorization.trim())) {
|
|
214542
|
+
throw new McpInvocationError("MCP_USER_AUTH_REQUIRED", "\u7CFB\u7EDF\u53D8\u91CF\u9700\u8981\u7528\u6237 Bearer \u51ED\u636E");
|
|
214543
|
+
}
|
|
214544
|
+
}
|
|
214545
|
+
var LinkquegwTokenVerifier = class {
|
|
214546
|
+
options;
|
|
214547
|
+
constructor(options = {}) {
|
|
214548
|
+
this.options = options;
|
|
214549
|
+
}
|
|
214550
|
+
async verify(input) {
|
|
214551
|
+
input.signal?.throwIfAborted();
|
|
214552
|
+
assertMcpUserAuthorization(input.authorization);
|
|
214553
|
+
try {
|
|
214554
|
+
const response = await (this.options.fetchImpl ?? globalThis.fetch)(this.options.endpoint ?? RUNTIME_CONFIG_DEFAULTS.LINKQUEGW_TOKEN_VERIFY_ENDPOINT, {
|
|
214555
|
+
method: "POST",
|
|
214556
|
+
headers: {
|
|
214557
|
+
authorization: input.authorization,
|
|
214558
|
+
"content-type": "application/json"
|
|
214559
|
+
},
|
|
214560
|
+
body: JSON.stringify({ agentId: input.agentId }),
|
|
214561
|
+
signal: input.signal
|
|
214562
|
+
});
|
|
214563
|
+
if (!response.ok)
|
|
214564
|
+
throw new Error("\u6821\u9A8C\u8BF7\u6C42\u5931\u8D25");
|
|
214565
|
+
const result = await response.json();
|
|
214566
|
+
input.signal?.throwIfAborted();
|
|
214567
|
+
if (result?.success !== true || typeof result.data?.userId !== "string" || !result.data.userId.trim() || typeof result.data.agentId !== "string" || !result.data.agentId.trim()) {
|
|
214568
|
+
throw new Error("\u8EAB\u4EFD\u54CD\u5E94\u65E0\u6548");
|
|
214569
|
+
}
|
|
214570
|
+
if (result.data.agentId !== input.agentId)
|
|
214571
|
+
throw new McpInvocationError("MCP_IDENTITY_MISMATCH", "\u7528\u6237\u51ED\u636E\u4E0D\u5C5E\u4E8E\u76EE\u6807 Agent");
|
|
214572
|
+
return { userId: result.data.userId, agentId: result.data.agentId };
|
|
214573
|
+
} catch (error40) {
|
|
214574
|
+
input.signal?.throwIfAborted();
|
|
214575
|
+
if (error40 instanceof McpInvocationError)
|
|
214576
|
+
throw error40;
|
|
214577
|
+
throw new McpInvocationError("MCP_TOKEN_VERIFY_FAILED", "\u7528\u6237\u51ED\u636E\u6821\u9A8C\u5931\u8D25");
|
|
214578
|
+
}
|
|
214579
|
+
}
|
|
214580
|
+
};
|
|
214581
|
+
|
|
214582
|
+
// ../linkque-agent-runtime/dist/esm/impl/mcp/alipay/remoteGatewayMcpServer.js
|
|
214583
|
+
init_telemetry();
|
|
214584
|
+
init_contentRecording();
|
|
214289
214585
|
init_types();
|
|
214290
214586
|
init_logFailure();
|
|
214291
214587
|
var defaultCreateSigner = (config2, getAuthorizationHeader, debugLog) => new RemoteSignatureSigner({
|
|
@@ -214297,6 +214593,8 @@ var defaultCreateSigner = (config2, getAuthorizationHeader, debugLog) => new Rem
|
|
|
214297
214593
|
});
|
|
214298
214594
|
var defaultCreateClient = () => new Client({ name: "linkque-agent-runtime-mcp-client", version: "1.0.0" });
|
|
214299
214595
|
var RemoteGatewayMcpServerProvider = class {
|
|
214596
|
+
invocationContext = new McpInvocationContext();
|
|
214597
|
+
createTokenVerifier;
|
|
214300
214598
|
resolveConfig;
|
|
214301
214599
|
getAuthorizationHeader;
|
|
214302
214600
|
createSigner;
|
|
@@ -214305,6 +214603,7 @@ var RemoteGatewayMcpServerProvider = class {
|
|
|
214305
214603
|
debugLog;
|
|
214306
214604
|
constructor(options) {
|
|
214307
214605
|
this.resolveConfig = options.resolveConfig;
|
|
214606
|
+
this.createTokenVerifier = options.createTokenVerifier ?? ((config2) => new LinkquegwTokenVerifier({ endpoint: config2.verifyTokenEndpoint }));
|
|
214308
214607
|
this.getAuthorizationHeader = options.getAuthorizationHeader;
|
|
214309
214608
|
this.createSigner = options.createSigner ?? ((config2, getAuthorizationHeader) => defaultCreateSigner(config2, getAuthorizationHeader, this.debugLog));
|
|
214310
214609
|
this.createClient = options.createClient ?? defaultCreateClient;
|
|
@@ -214317,9 +214616,13 @@ var RemoteGatewayMcpServerProvider = class {
|
|
|
214317
214616
|
/** 连单个远端 server 并包装成 IMcpServer。建连失败有限重试 + 失败清理由 helper 负责。 */
|
|
214318
214617
|
async connectOne(resource) {
|
|
214319
214618
|
const config2 = await this.resolveConfig(resource);
|
|
214320
|
-
const
|
|
214619
|
+
const timeoutMs = config2.requestTimeoutMs ?? 18e4;
|
|
214620
|
+
if (!Number.isFinite(timeoutMs) || timeoutMs <= 0)
|
|
214621
|
+
throw new Error("MCP \u8D85\u65F6\u5FC5\u987B\u4E3A\u6709\u9650\u6B63\u6570");
|
|
214622
|
+
const verifier = this.createTokenVerifier(config2);
|
|
214623
|
+
const callHeaders = new import_node_async_hooks2.AsyncLocalStorage();
|
|
214321
214624
|
const { client } = await connectMcpClientWithRetry(config2, {
|
|
214322
|
-
createTransport: () => createSseTransport(config2, this.createSigner(config2, this.getAuthorizationHeader), this.onTraceId, this.debugLog, () => callHeaders.getStore()),
|
|
214625
|
+
createTransport: () => createSseTransport(config2, this.createSigner(config2, this.getAuthorizationHeader), this.onTraceId, this.debugLog, () => callHeaders.getStore(), this.invocationContext),
|
|
214323
214626
|
createClient: () => this.createClient()
|
|
214324
214627
|
});
|
|
214325
214628
|
const serverName = resource.config.serverName ?? resource.resourceId;
|
|
@@ -214331,7 +214634,7 @@ var RemoteGatewayMcpServerProvider = class {
|
|
|
214331
214634
|
if (!this.debugLog)
|
|
214332
214635
|
return;
|
|
214333
214636
|
try {
|
|
214334
|
-
this.debugLog(`[mcp-client] ${JSON.stringify({ serverName, resourceId: resource.resourceId, requestId, method, phase, payload })}`, EDebugLogScope.MCP);
|
|
214637
|
+
this.debugLog(`[mcp-client] ${JSON.stringify({ serverName, resourceId: resource.resourceId, requestId, method, phase, payload: this.invocationContext.current()?.auth ? { redacted: true } : payload })}`, EDebugLogScope.MCP);
|
|
214335
214638
|
} catch (error40) {
|
|
214336
214639
|
warnLogFailure("remoteGatewayMcpServer.log", error40);
|
|
214337
214640
|
}
|
|
@@ -214348,16 +214651,57 @@ var RemoteGatewayMcpServerProvider = class {
|
|
|
214348
214651
|
};
|
|
214349
214652
|
const loggedClient = {
|
|
214350
214653
|
listTools: () => request("tools/list", {}, () => client.listTools()),
|
|
214351
|
-
callTool: (params) => request("tools/call", params, () => client.callTool(params))
|
|
214352
|
-
};
|
|
214654
|
+
callTool: (params, resultSchema, requestOptions) => request("tools/call", params, () => client.callTool(params, resultSchema, requestOptions))
|
|
214655
|
+
};
|
|
214656
|
+
const callTool = (name, args, signal, options) => callHeaders.run(options?.headers ?? {}, () => this.invocationContext.run(timeoutMs, signal, async (invocation) => {
|
|
214657
|
+
const observation = options?.context?.observation;
|
|
214658
|
+
recordContentSection(observation, ETelemetryContentSection.MCP_REQUESTED_INPUT, args);
|
|
214659
|
+
const plan = createArgsMappingPlan(name, args, argsMappingRules);
|
|
214660
|
+
if (plan.requiresUserId) {
|
|
214661
|
+
if (config2.signEndpoint !== void 0 && config2.signEndpoint !== DEFAULT_SIGN_ENDPOINT && !config2.verifyTokenEndpoint?.trim())
|
|
214662
|
+
throw new McpInvocationError("MCP_CONFIG_INVALID", "\u81EA\u5B9A\u4E49\u7B7E\u540D\u7AEF\u70B9\u5FC5\u987B\u540C\u65F6\u914D\u7F6E\u7528\u6237\u51ED\u636E\u6821\u9A8C\u7AEF\u70B9");
|
|
214663
|
+
if (!this.getAuthorizationHeader)
|
|
214664
|
+
throw new McpInvocationError("MCP_USER_AUTH_REQUIRED", "\u7CFB\u7EDF\u53D8\u91CF\u9700\u8981\u7528\u6237\u51ED\u636E");
|
|
214665
|
+
const authorization = await waitForMcpOperation(() => this.getAuthorizationHeader(), invocation.signal);
|
|
214666
|
+
assertMcpUserAuthorization(authorization);
|
|
214667
|
+
const identity = await waitForMcpOperation(() => verifier.verify({
|
|
214668
|
+
authorization,
|
|
214669
|
+
agentId: config2.agentId,
|
|
214670
|
+
signal: invocation.signal
|
|
214671
|
+
}), invocation.signal);
|
|
214672
|
+
if (!identity.userId?.trim() || identity.agentId !== config2.agentId)
|
|
214673
|
+
throw new McpInvocationError("MCP_IDENTITY_MISMATCH", "\u6821\u9A8C\u8EAB\u4EFD\u65E0\u6548");
|
|
214674
|
+
invocation.auth = {
|
|
214675
|
+
authorization,
|
|
214676
|
+
userId: identity.userId,
|
|
214677
|
+
agentId: identity.agentId
|
|
214678
|
+
};
|
|
214679
|
+
}
|
|
214680
|
+
const mapped = resolveArgsMappingPlan(plan, invocation.auth);
|
|
214681
|
+
recordContentSection(observation, ETelemetryContentSection.MCP_INPUT, mapped);
|
|
214682
|
+
invocation.signal.throwIfAborted();
|
|
214683
|
+
const remaining = Math.max(1, invocation.deadline - performance.now());
|
|
214684
|
+
try {
|
|
214685
|
+
const result = await loggedClient.callTool({ name, arguments: mapped }, void 0, {
|
|
214686
|
+
signal: invocation.signal,
|
|
214687
|
+
timeout: remaining,
|
|
214688
|
+
maxTotalTimeout: remaining,
|
|
214689
|
+
resetTimeoutOnProgress: false
|
|
214690
|
+
});
|
|
214691
|
+
recordContentSection(observation, ETelemetryContentSection.MCP_OUTPUT, result);
|
|
214692
|
+
return result;
|
|
214693
|
+
} catch (error40) {
|
|
214694
|
+
invocation.signal.throwIfAborted();
|
|
214695
|
+
if (invocation.auth && !(error40 instanceof McpInvocationError))
|
|
214696
|
+
throw new Error("MCP \u7528\u6237\u5DE5\u5177\u8C03\u7528\u5931\u8D25");
|
|
214697
|
+
throw error40;
|
|
214698
|
+
}
|
|
214699
|
+
}));
|
|
214353
214700
|
return {
|
|
214354
214701
|
resourceId: resource.resourceId,
|
|
214355
214702
|
serverName,
|
|
214356
|
-
listTools: () => listToolsFromClient(loggedClient, resource.resourceId),
|
|
214357
|
-
callTool
|
|
214358
|
-
const mapped = applyArgsMappingRules(name, args, argsMappingRules);
|
|
214359
|
-
return callHeaders.run(options?.headers ?? {}, () => loggedClient.callTool({ name, arguments: mapped ?? {} }));
|
|
214360
|
-
},
|
|
214703
|
+
listTools: () => listToolsFromClient(loggedClient, resource.resourceId, callTool),
|
|
214704
|
+
callTool,
|
|
214361
214705
|
close: async () => {
|
|
214362
214706
|
try {
|
|
214363
214707
|
await client.close();
|
|
@@ -214367,14 +214711,14 @@ var RemoteGatewayMcpServerProvider = class {
|
|
|
214367
214711
|
};
|
|
214368
214712
|
}
|
|
214369
214713
|
};
|
|
214370
|
-
async function listToolsFromClient(client, resourceId) {
|
|
214714
|
+
async function listToolsFromClient(client, resourceId, callTool) {
|
|
214371
214715
|
const result = await client.listTools();
|
|
214372
214716
|
const tools = result.tools ?? [];
|
|
214373
214717
|
return tools.map((tool) => {
|
|
214374
214718
|
const descriptor = {
|
|
214375
214719
|
name: tool.name,
|
|
214376
214720
|
resourceId,
|
|
214377
|
-
execute: (args) =>
|
|
214721
|
+
execute: (args, signal, context2) => callTool(tool.name, args, signal, { context: context2 })
|
|
214378
214722
|
};
|
|
214379
214723
|
if (tool.description !== void 0)
|
|
214380
214724
|
descriptor.description = tool.description;
|
|
@@ -214753,7 +215097,7 @@ var LocalHttpMcpServerProvider = class {
|
|
|
214753
215097
|
}
|
|
214754
215098
|
return body.tools.map((value) => this.createDescriptor(resource.resourceId, value));
|
|
214755
215099
|
},
|
|
214756
|
-
callTool: (name, args, signal) => this.callTool(resource.resourceId, name, args, signal)
|
|
215100
|
+
callTool: (name, args, signal, _options) => this.callTool(resource.resourceId, name, args, signal)
|
|
214757
215101
|
};
|
|
214758
215102
|
}
|
|
214759
215103
|
createDescriptor(resourceId, value) {
|
|
@@ -215610,7 +215954,7 @@ init_noopRuntimeTelemetry();
|
|
|
215610
215954
|
// ../linkque-agent-runtime/dist/esm/impl/telemetry/identityQueue.js
|
|
215611
215955
|
init_telemetry();
|
|
215612
215956
|
init_telemetryEnums2();
|
|
215613
|
-
var
|
|
215957
|
+
var import_node_async_hooks3 = require("node:async_hooks");
|
|
215614
215958
|
init_esm6();
|
|
215615
215959
|
var import_core11 = __toESM(require_src(), 1);
|
|
215616
215960
|
function authorizationKey(auth2) {
|
|
@@ -215624,7 +215968,7 @@ function authorizationKey(auth2) {
|
|
|
215624
215968
|
}
|
|
215625
215969
|
var IdentityQueue = class {
|
|
215626
215970
|
options;
|
|
215627
|
-
exportContext = new
|
|
215971
|
+
exportContext = new import_node_async_hooks3.AsyncLocalStorage();
|
|
215628
215972
|
get isExporting() {
|
|
215629
215973
|
return this.exportContext.getStore() === true;
|
|
215630
215974
|
}
|
|
@@ -216298,7 +216642,7 @@ var OtelRuntimeTelemetry = class {
|
|
|
216298
216642
|
operation.record(`${spec.eventPrefix}.${ETelemetryEventPhase.STARTED}`, {});
|
|
216299
216643
|
return operation;
|
|
216300
216644
|
}
|
|
216301
|
-
emit(operation, name, attributes, critical) {
|
|
216645
|
+
emit(operation, name, attributes, critical, body) {
|
|
216302
216646
|
if (this.disposed || this.queue.isExporting)
|
|
216303
216647
|
return;
|
|
216304
216648
|
const contextAttributes = operation.attributes;
|
|
@@ -216337,6 +216681,7 @@ var OtelRuntimeTelemetry = class {
|
|
|
216337
216681
|
eventName: name,
|
|
216338
216682
|
timestamp: time3,
|
|
216339
216683
|
observedTimestamp: time3,
|
|
216684
|
+
...body !== void 0 ? { body } : {},
|
|
216340
216685
|
severityNumber: record4[ETelemetryAttribute.HARNESS_OPERATION_OUTCOME] === ETelemetryOutcome.ERROR || record4[ETelemetryAttribute.HARNESS_OPERATION_OUTCOME] === ETelemetryOutcome.TIMEOUT ? import_api_logs.SeverityNumber.ERROR : import_api_logs.SeverityNumber.INFO,
|
|
216341
216686
|
severityText: record4[ETelemetryAttribute.HARNESS_OPERATION_OUTCOME] === ETelemetryOutcome.ERROR || record4[ETelemetryAttribute.HARNESS_OPERATION_OUTCOME] === ETelemetryOutcome.TIMEOUT ? import_api_logs.SeverityNumber[import_api_logs.SeverityNumber.ERROR] : import_api_logs.SeverityNumber[import_api_logs.SeverityNumber.INFO],
|
|
216342
216687
|
attributes: record4,
|
|
@@ -216407,10 +216752,11 @@ var OtelObservation = class {
|
|
|
216407
216752
|
return new NoopRuntimeObservation();
|
|
216408
216753
|
return this.owner.createOperation(this.state, spec, this);
|
|
216409
216754
|
}
|
|
216410
|
-
record(name, attributes) {
|
|
216755
|
+
record(name, attributes, body) {
|
|
216411
216756
|
if (this.lost || !/^(harness|linkque)\.[a-z0-9_.]{1,128}$/.test(name))
|
|
216412
216757
|
return;
|
|
216413
|
-
|
|
216758
|
+
const critical = name.endsWith(`.${ETelemetryEventPhase.FINISHED}`) || name === ETelemetryEventName.MODEL_USAGE_RECORDED || name === ETelemetryEventName.RUNTIME_UNCAUGHT_ERROR || name.endsWith(`.${ETelemetryEventPhase.OBSERVATION_LOST}`);
|
|
216759
|
+
this.owner.emit(this, name, attributes, critical, body);
|
|
216414
216760
|
}
|
|
216415
216761
|
finish(outcome, attributes) {
|
|
216416
216762
|
if (this.ended)
|
|
@@ -217001,6 +217347,7 @@ function createMcpConfigResolver(options) {
|
|
|
217001
217347
|
sseEndpoint: `api/v1/open/mcps/${resolveServerName(resource.config)}/sse`,
|
|
217002
217348
|
agentId: options.agentId,
|
|
217003
217349
|
...options.signEndpoint ? { signEndpoint: options.signEndpoint } : {},
|
|
217350
|
+
...options.verifyTokenEndpoint ? { verifyTokenEndpoint: options.verifyTokenEndpoint } : {},
|
|
217004
217351
|
...options.requestTimeoutMs ? { requestTimeoutMs: options.requestTimeoutMs } : {}
|
|
217005
217352
|
});
|
|
217006
217353
|
}
|
|
@@ -217096,6 +217443,7 @@ var AGENT_ENV_SNAPSHOT = [
|
|
|
217096
217443
|
["LINKQUE_BASE_URL", false],
|
|
217097
217444
|
["LINKQUE_OPEN_MCP_BASE_URL", false],
|
|
217098
217445
|
["LINKQUE_MCP_SIGN_ENDPOINT", false],
|
|
217446
|
+
["LINKQUEGW_TOKEN_VERIFY_ENDPOINT", false],
|
|
217099
217447
|
["LINKQUE_AGENT_MCP_FIXTURE_URL", false]
|
|
217100
217448
|
];
|
|
217101
217449
|
var formatEnvSnapshot = (env2) => {
|
|
@@ -217405,7 +217753,9 @@ var main = async () => {
|
|
|
217405
217753
|
const resolveConfig = createMcpConfigResolver({
|
|
217406
217754
|
agentId: protocol.agentId,
|
|
217407
217755
|
remoteBaseUrl: config2.get("LINKQUE_OPEN_MCP_BASE_URL"),
|
|
217408
|
-
signEndpoint: config2.get("LINKQUE_MCP_SIGN_ENDPOINT")
|
|
217756
|
+
signEndpoint: config2.get("LINKQUE_MCP_SIGN_ENDPOINT"),
|
|
217757
|
+
// 保留未显式配置的状态,由运行时检查自定义环境配置是否完整。
|
|
217758
|
+
verifyTokenEndpoint: config2.getRaw("LINKQUEGW_TOKEN_VERIFY_ENDPOINT")?.trim() || void 0
|
|
217409
217759
|
});
|
|
217410
217760
|
return new RemoteGatewayMcpServerProvider({
|
|
217411
217761
|
resolveConfig,
|