linkque-cli-v2 1.4.5 → 1.4.6
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 +153 -50
- package/package.json +1 -1
- package/vendor/linkque-agent-appwrite-integrate/dist/esm/{chunk-NFVKWQGM.js → chunk-JD3IL3IC.js} +1 -1
- package/vendor/linkque-agent-appwrite-integrate/dist/esm/{chunk-CLYLJ5MD.js → chunk-PM2UO433.js} +60 -13
- package/vendor/linkque-agent-appwrite-integrate/dist/esm/{chunk-S75HFRLD.js → chunk-STGFILDE.js} +1 -1
- package/vendor/linkque-agent-appwrite-integrate/dist/esm/runtime/handler/chat.js +244 -158
- package/vendor/linkque-agent-appwrite-integrate/dist/esm/runtime/handler/clientCapability.js +2 -2
- package/vendor/linkque-agent-appwrite-integrate/dist/esm/runtime/protocol.js +2 -2
- package/vendor/linkque-agent-appwrite-integrate/package.json +1 -1
- package/worker.js +331 -189
package/worker.js
CHANGED
|
@@ -11961,6 +11961,14 @@ var init_telemetryEnums = __esm({
|
|
|
11961
11961
|
ETelemetryAttribute2["HARNESS_MODEL_PURPOSE"] = "harness.model.purpose";
|
|
11962
11962
|
ETelemetryAttribute2["HARNESS_MODEL_INVOCATION_COUNT"] = "harness.model.invocation_count";
|
|
11963
11963
|
ETelemetryAttribute2["GEN_AI_TOOL_NAME"] = "gen_ai.tool.name";
|
|
11964
|
+
ETelemetryAttribute2["LINKQUE_TOOL_DISPLAY_NAME"] = "linkque.tool.display_name";
|
|
11965
|
+
ETelemetryAttribute2["LINKQUE_CARD_EXECUTION_ID"] = "linkque.card.execution_id";
|
|
11966
|
+
ETelemetryAttribute2["LINKQUE_CARD_REF"] = "linkque.card.ref";
|
|
11967
|
+
ETelemetryAttribute2["LINKQUE_CARD_REVISION"] = "linkque.card.revision";
|
|
11968
|
+
ETelemetryAttribute2["LINKQUE_CARD_DISPLAY_NAME"] = "linkque.card.display_name";
|
|
11969
|
+
ETelemetryAttribute2["LINKQUE_CARD_PHASE"] = "linkque.card.phase";
|
|
11970
|
+
ETelemetryAttribute2["LINKQUE_CARD_SOURCE_ID"] = "linkque.card.source_id";
|
|
11971
|
+
ETelemetryAttribute2["LINKQUE_CARD_DELIVERY"] = "linkque.card.delivery";
|
|
11964
11972
|
ETelemetryAttribute2["GEN_AI_TOOL_CALL_ID"] = "gen_ai.tool.call.id";
|
|
11965
11973
|
ETelemetryAttribute2["HARNESS_TOOL_RESULT_STATUS"] = "harness.tool.result.status";
|
|
11966
11974
|
ETelemetryAttribute2["LINKQUE_TOOL_FAILURE_STAGE"] = "linkque.tool.failure_stage";
|
|
@@ -12051,6 +12059,7 @@ var init_telemetryEnums = __esm({
|
|
|
12051
12059
|
ETelemetryEventName2["HOOK_DRAIN_STARTED"] = "linkque.hook.drain.started";
|
|
12052
12060
|
ETelemetryEventName2["HOOK_DRAIN_FINISHED"] = "linkque.hook.drain.finished";
|
|
12053
12061
|
ETelemetryEventName2["CONTENT_RECORDED"] = "linkque.content.recorded";
|
|
12062
|
+
ETelemetryEventName2["TOOL_CONTEXT"] = "linkque.tool.context";
|
|
12054
12063
|
})(ETelemetryEventName || (ETelemetryEventName = {}));
|
|
12055
12064
|
(function(ETelemetryContentSection2) {
|
|
12056
12065
|
ETelemetryContentSection2["QUERY_INPUT"] = "query.input";
|
|
@@ -12500,18 +12509,14 @@ var init_mcpProxyTool = __esm({
|
|
|
12500
12509
|
if (params.server !== void 0) {
|
|
12501
12510
|
return this.executeList(params.server, signal, context2);
|
|
12502
12511
|
}
|
|
12503
|
-
return this.executeStatus();
|
|
12512
|
+
return this.executeStatus(context2);
|
|
12504
12513
|
}
|
|
12505
12514
|
/** 保留代理动作事实,不改变供模型消费的原始返回值。 */
|
|
12506
12515
|
recordAction(context2, action, status, data = {}) {
|
|
12507
|
-
recordContentSection(context2?.observation, ETelemetryContentSection.MCP_ACTION_OUTPUT, {
|
|
12508
|
-
action,
|
|
12509
|
-
status,
|
|
12510
|
-
...data
|
|
12511
|
-
});
|
|
12516
|
+
recordContentSection(context2?.observation, ETelemetryContentSection.MCP_ACTION_OUTPUT, { action, status, ...data });
|
|
12512
12517
|
}
|
|
12513
12518
|
/** `mcp({})` / `mcp({ status: true })`:列各 server 连接状态 + 工具数。 */
|
|
12514
|
-
executeStatus() {
|
|
12519
|
+
executeStatus(context2) {
|
|
12515
12520
|
const lines = [];
|
|
12516
12521
|
let connected = 0;
|
|
12517
12522
|
let totalTools = 0;
|
|
@@ -12530,6 +12535,13 @@ var init_mcpProxyTool = __esm({
|
|
|
12530
12535
|
lines.push(`\u2717 ${label} (failed${entry.error ? ": " + entry.error : ""})`);
|
|
12531
12536
|
}
|
|
12532
12537
|
}
|
|
12538
|
+
this.recordAction(context2, "status", "completed", {
|
|
12539
|
+
servers: this.specs.map((spec) => ({
|
|
12540
|
+
name: spec.serverName,
|
|
12541
|
+
status: this.entries.get(spec.serverName)?.status ?? "not_connected",
|
|
12542
|
+
toolCount: this.entries.get(spec.serverName)?.tools.length ?? 0
|
|
12543
|
+
}))
|
|
12544
|
+
});
|
|
12533
12545
|
const header = `MCP: ${connected}/${this.specs.length} servers, ${totalTools} tools`;
|
|
12534
12546
|
const hint = this.specs.length > 0 ? '\nmcp({ server: "name" }) to list tools, mcp({ search: "..." }) to search, mcp({ tool: "...", args: {...} }) to call' : "\n(no MCP resources configured)";
|
|
12535
12547
|
return `${header}
|
|
@@ -12546,12 +12558,20 @@ ${lines.join("\n")}${hint}`.trim();
|
|
|
12546
12558
|
this.entries.delete(spec.serverName);
|
|
12547
12559
|
const entry = await this.ensureEntry(spec.serverName, signal);
|
|
12548
12560
|
if (!entry) {
|
|
12549
|
-
this.recordAction(context2, "connect", "failed", {
|
|
12561
|
+
this.recordAction(context2, "connect", "failed", {
|
|
12562
|
+
server: spec.serverName
|
|
12563
|
+
});
|
|
12550
12564
|
const failed = this.entries.get(spec.serverName);
|
|
12551
12565
|
const detail = failed?.error ? `: ${failed.error}` : "";
|
|
12552
12566
|
return `Failed to connect to "${spec.serverName}"${detail}.`;
|
|
12553
12567
|
}
|
|
12554
|
-
this.recordAction(context2, "connect", "matched", {
|
|
12568
|
+
this.recordAction(context2, "connect", "matched", {
|
|
12569
|
+
server: spec.serverName,
|
|
12570
|
+
tools: entry.tools.map((tool) => ({
|
|
12571
|
+
name: tool.name,
|
|
12572
|
+
description: tool.description
|
|
12573
|
+
}))
|
|
12574
|
+
});
|
|
12555
12575
|
return this.formatToolList(spec.serverName, entry.tools);
|
|
12556
12576
|
}
|
|
12557
12577
|
/** `mcp({ server: "name" })`:列该 server 工具名 + 截断 description。 */
|
|
@@ -12566,7 +12586,13 @@ ${lines.join("\n")}${hint}`.trim();
|
|
|
12566
12586
|
this.recordAction(context2, "list", "failed", { server: spec.serverName });
|
|
12567
12587
|
return `Server "${spec.serverName}" is not connected. Use mcp({ connect: "${spec.serverName}" }) to retry.`;
|
|
12568
12588
|
}
|
|
12569
|
-
this.recordAction(context2, "list", "matched", {
|
|
12589
|
+
this.recordAction(context2, "list", "matched", {
|
|
12590
|
+
server: spec.serverName,
|
|
12591
|
+
tools: entry.tools.map((tool) => ({
|
|
12592
|
+
name: tool.name,
|
|
12593
|
+
description: tool.description
|
|
12594
|
+
}))
|
|
12595
|
+
});
|
|
12570
12596
|
return this.formatToolList(spec.serverName, entry.tools);
|
|
12571
12597
|
}
|
|
12572
12598
|
/** `mcp({ search: "query" })`:空格分词 OR 子串匹配 name/description(跨所有 server)。 */
|
|
@@ -12588,9 +12614,18 @@ ${lines.join("\n")}${hint}`.trim();
|
|
|
12588
12614
|
}
|
|
12589
12615
|
}
|
|
12590
12616
|
}
|
|
12591
|
-
const tools = matches.map(({ server, tool }) => ({
|
|
12617
|
+
const tools = matches.map(({ server, tool }) => ({
|
|
12618
|
+
server,
|
|
12619
|
+
name: tool.name,
|
|
12620
|
+
description: tool.description,
|
|
12621
|
+
inputSchema: tool.inputSchema
|
|
12622
|
+
}));
|
|
12592
12623
|
if (matches.length === 0) {
|
|
12593
|
-
return {
|
|
12624
|
+
return {
|
|
12625
|
+
query,
|
|
12626
|
+
tools,
|
|
12627
|
+
text: serverHint ? `No tools matching "${query}" in "${serverHint}"` : `No tools matching "${query}"`
|
|
12628
|
+
};
|
|
12594
12629
|
}
|
|
12595
12630
|
const lines = [`Found ${matches.length} tool(s) matching "${query}":`, ""];
|
|
12596
12631
|
for (const { server, tool } of matches) {
|
|
@@ -12627,7 +12662,11 @@ ${result.text}`).join("\n\n");
|
|
|
12627
12662
|
return `Tool "${toolName}" not found. Use mcp({ search: "..." }) to search.`;
|
|
12628
12663
|
}
|
|
12629
12664
|
const { server, tool } = found;
|
|
12630
|
-
this.recordAction(context2, "describe", "matched", {
|
|
12665
|
+
this.recordAction(context2, "describe", "matched", {
|
|
12666
|
+
server,
|
|
12667
|
+
name: tool.name,
|
|
12668
|
+
inputSchema: tool.inputSchema
|
|
12669
|
+
});
|
|
12631
12670
|
const lines = [
|
|
12632
12671
|
`${tool.name}`,
|
|
12633
12672
|
`Server: ${server}`,
|
|
@@ -49230,6 +49269,7 @@ function observeTool(tool, observation) {
|
|
|
49230
49269
|
eventPrefix: ETelemetryEventPrefix.TOOL_ATTEMPT,
|
|
49231
49270
|
attributes: {
|
|
49232
49271
|
[ETelemetryAttribute.GEN_AI_TOOL_NAME]: tool.modelName ?? tool.name,
|
|
49272
|
+
[ETelemetryAttribute.LINKQUE_TOOL_DISPLAY_NAME]: tool.label ?? tool.name,
|
|
49233
49273
|
[ETelemetryAttribute.GEN_AI_TOOL_CALL_ID]: context2?.toolCallId ?? "",
|
|
49234
49274
|
[ETelemetryAttribute.HARNESS_ATTEMPT_ID]: (0, import_node_crypto6.randomUUID)(),
|
|
49235
49275
|
[ETelemetryAttribute.HARNESS_ATTEMPT_VISIBILITY]: ETelemetryAttemptVisibility.TOOL_PROVIDER_INVOCATION
|
|
@@ -49381,49 +49421,9 @@ var init_piTelemetry = __esm({
|
|
|
49381
49421
|
PiTelemetry = class {
|
|
49382
49422
|
root;
|
|
49383
49423
|
iterationIndex = 0;
|
|
49384
|
-
replyText = "";
|
|
49385
|
-
replyBytes = 0;
|
|
49386
|
-
replyIndex = 0;
|
|
49387
|
-
replyTruncated = false;
|
|
49388
|
-
maxReplyBytes = 512 * 1024;
|
|
49389
|
-
/** 正文分块独立落盘;每条最坏 JSON 编码也低于日志单行 1 MiB 上限。 */
|
|
49390
|
-
recordReplyChunk(final, complete) {
|
|
49391
|
-
this.root.find(ETelemetryAssociation.MODEL)?.record(ETelemetryEventName.CONTENT_RECORDED, {}, {
|
|
49392
|
-
section: ETelemetryContentSection.MODEL_OUTPUT,
|
|
49393
|
-
value: this.replyText,
|
|
49394
|
-
chunkIndex: this.replyIndex++,
|
|
49395
|
-
final,
|
|
49396
|
-
availability: final && complete && !this.replyTruncated ? "available" : "partial"
|
|
49397
|
-
});
|
|
49398
|
-
this.replyText = "";
|
|
49399
|
-
}
|
|
49400
|
-
flushReply(complete) {
|
|
49401
|
-
if (this.replyBytes)
|
|
49402
|
-
this.recordReplyChunk(true, complete);
|
|
49403
|
-
this.replyBytes = 0;
|
|
49404
|
-
this.replyIndex = 0;
|
|
49405
|
-
this.replyTruncated = false;
|
|
49406
|
-
}
|
|
49407
|
-
appendReply(text2) {
|
|
49408
|
-
if (this.replyTruncated)
|
|
49409
|
-
return;
|
|
49410
|
-
for (const character of text2) {
|
|
49411
|
-
const bytes2 = Buffer.byteLength(character, "utf8");
|
|
49412
|
-
if (this.replyBytes + bytes2 > this.maxReplyBytes) {
|
|
49413
|
-
this.replyTruncated = true;
|
|
49414
|
-
break;
|
|
49415
|
-
}
|
|
49416
|
-
this.replyText += character;
|
|
49417
|
-
this.replyBytes += bytes2;
|
|
49418
|
-
if (this.replyText.length >= 16 * 1024)
|
|
49419
|
-
this.recordReplyChunk(false, false);
|
|
49420
|
-
}
|
|
49421
|
-
}
|
|
49422
49424
|
proposed = /* @__PURE__ */ new Map();
|
|
49423
49425
|
loop;
|
|
49424
49426
|
lastProvider = null;
|
|
49425
|
-
publicTextSeen = false;
|
|
49426
|
-
started = performance.now();
|
|
49427
49427
|
terminal = ETelemetryStreamTermination.EXHAUSTED;
|
|
49428
49428
|
constructor(root) {
|
|
49429
49429
|
this.root = root;
|
|
@@ -49438,6 +49438,9 @@ var init_piTelemetry = __esm({
|
|
|
49438
49438
|
[ETelemetryAttribute.LINKQUE_TELEMETRY_COVERAGE]: ETelemetryCoverage.PI_MODEL_TOOL_HOOK
|
|
49439
49439
|
});
|
|
49440
49440
|
}
|
|
49441
|
+
get currentModel() {
|
|
49442
|
+
return this.root.find(ETelemetryAssociation.MODEL);
|
|
49443
|
+
}
|
|
49441
49444
|
startModel(model) {
|
|
49442
49445
|
const parent = this.root.find(ETelemetryAssociation.ITERATION) ?? this.loop;
|
|
49443
49446
|
return parent.startOperation({
|
|
@@ -49520,7 +49523,6 @@ var init_piTelemetry = __esm({
|
|
|
49520
49523
|
}
|
|
49521
49524
|
case "message_end":
|
|
49522
49525
|
if (event.message.role === "assistant") {
|
|
49523
|
-
this.flushReply(event.message.stopReason !== "error" && event.message.stopReason !== "aborted");
|
|
49524
49526
|
const failed = event.message.stopReason === "error" || event.message.stopReason === "aborted";
|
|
49525
49527
|
this.root.find(ETelemetryAssociation.MODEL)?.finish(event.message.stopReason === "aborted" ? ETelemetryOutcome.CANCELLED : failed ? ETelemetryOutcome.ERROR : ETelemetryOutcome.SUCCESS, {
|
|
49526
49528
|
[ETelemetryAttribute.GEN_AI_RESPONSE_FINISH_REASONS]: [
|
|
@@ -49535,14 +49537,6 @@ var init_piTelemetry = __esm({
|
|
|
49535
49537
|
break;
|
|
49536
49538
|
case "message_update": {
|
|
49537
49539
|
const update = event.assistantMessageEvent;
|
|
49538
|
-
if (update.type === "text_delta")
|
|
49539
|
-
this.appendReply(update.delta);
|
|
49540
|
-
if (update.type === "text_delta" && update.delta && !this.publicTextSeen) {
|
|
49541
|
-
this.publicTextSeen = true;
|
|
49542
|
-
this.loop.record(ETelemetryEventName.LOOP_FIRST_PUBLIC_TEXT, {
|
|
49543
|
-
[ETelemetryAttribute.LINKQUE_LOOP_FIRST_PUBLIC_TEXT_MS]: performance.now() - this.started
|
|
49544
|
-
});
|
|
49545
|
-
}
|
|
49546
49540
|
if (update.type === "error")
|
|
49547
49541
|
this.terminal = update.reason === "aborted" ? ETelemetryStreamTermination.CANCEL : ETelemetryStreamTermination.ERROR;
|
|
49548
49542
|
break;
|
|
@@ -49567,7 +49561,6 @@ var init_piTelemetry = __esm({
|
|
|
49567
49561
|
this.terminal = ETelemetryStreamTermination.ERROR;
|
|
49568
49562
|
}
|
|
49569
49563
|
close(cancelled) {
|
|
49570
|
-
this.flushReply(false);
|
|
49571
49564
|
this.proposed.clear();
|
|
49572
49565
|
this.loop.finish(this.terminal === ETelemetryStreamTermination.ERROR ? ETelemetryOutcome.ERROR : cancelled || this.terminal === ETelemetryStreamTermination.CANCEL ? ETelemetryOutcome.CANCELLED : this.terminal === ETelemetryStreamTermination.COMPLETE ? ETelemetryOutcome.SUCCESS : ETelemetryOutcome.UNKNOWN, {
|
|
49573
49566
|
[ETelemetryAttribute.LINKQUE_STREAM_TERMINATION]: this.terminal === ETelemetryStreamTermination.ERROR ? ETelemetryStreamTermination.ERROR : cancelled ? ETelemetryStreamTermination.CANCEL : this.terminal
|
|
@@ -206035,6 +206028,9 @@ var init_agentService = __esm({
|
|
|
206035
206028
|
this.unsubscribe = this.session.subscribe((event) => {
|
|
206036
206029
|
if (this.aborted)
|
|
206037
206030
|
return;
|
|
206031
|
+
if (event.type === "message_end" && event.message.role === "assistant") {
|
|
206032
|
+
this.options.publicOutput?.completeSource(this.telemetry?.currentModel, event.message.stopReason !== "error" && event.message.stopReason !== "aborted");
|
|
206033
|
+
}
|
|
206038
206034
|
this.telemetry?.onEvent(event);
|
|
206039
206035
|
this.logDebug(`[pi-event] ${this.safeStringify(event)}`);
|
|
206040
206036
|
for (const translated of translateEvents(event, this.uiStatusToolNames)) {
|
|
@@ -206043,6 +206039,7 @@ var init_agentService = __esm({
|
|
|
206043
206039
|
return;
|
|
206044
206040
|
this.settled = true;
|
|
206045
206041
|
}
|
|
206042
|
+
this.options.publicOutput?.associate(translated, this.telemetry?.currentModel);
|
|
206046
206043
|
this.enqueue(translated);
|
|
206047
206044
|
}
|
|
206048
206045
|
});
|
|
@@ -206350,6 +206347,7 @@ var init_piAgentLoop = __esm({
|
|
|
206350
206347
|
},
|
|
206351
206348
|
...req.debugLog && { debugLog: req.debugLog },
|
|
206352
206349
|
...req.observation && { observation: req.observation },
|
|
206350
|
+
...req.publicOutput && { publicOutput: req.publicOutput },
|
|
206353
206351
|
// agentId 透传:agentService 在 LINKQUE provider 时注入 x-agent-id 请求头,供网关计费归因。
|
|
206354
206352
|
...req.agentId !== void 0 && { agentId: req.agentId },
|
|
206355
206353
|
// runId 透传:注入 x-run-id 请求头,供网关用量上报归因(落库 run_id)。
|
|
@@ -206381,6 +206379,92 @@ var init_pi = __esm({
|
|
|
206381
206379
|
}
|
|
206382
206380
|
});
|
|
206383
206381
|
|
|
206382
|
+
// ../linkque-agent-runtime/dist/esm/core/telemetry/publicOutputObservation.js
|
|
206383
|
+
var PublicOutputObservation;
|
|
206384
|
+
var init_publicOutputObservation = __esm({
|
|
206385
|
+
"../linkque-agent-runtime/dist/esm/core/telemetry/publicOutputObservation.js"() {
|
|
206386
|
+
"use strict";
|
|
206387
|
+
init_telemetry();
|
|
206388
|
+
PublicOutputObservation = class {
|
|
206389
|
+
root;
|
|
206390
|
+
sources = /* @__PURE__ */ new WeakMap();
|
|
206391
|
+
completedSources = /* @__PURE__ */ new WeakMap();
|
|
206392
|
+
source;
|
|
206393
|
+
text = "";
|
|
206394
|
+
bytes = 0;
|
|
206395
|
+
index = 0;
|
|
206396
|
+
truncated = false;
|
|
206397
|
+
firstText = false;
|
|
206398
|
+
startedAt = performance.now();
|
|
206399
|
+
constructor(root) {
|
|
206400
|
+
this.root = root;
|
|
206401
|
+
}
|
|
206402
|
+
associate(event, source) {
|
|
206403
|
+
if (source)
|
|
206404
|
+
this.sources.set(event, source);
|
|
206405
|
+
}
|
|
206406
|
+
/** 来源终态可能早于队列中的正文到达,不能在此提前刷空缓冲。 */
|
|
206407
|
+
completeSource(source, complete) {
|
|
206408
|
+
if (source)
|
|
206409
|
+
this.completedSources.set(source, complete);
|
|
206410
|
+
}
|
|
206411
|
+
accept(event) {
|
|
206412
|
+
if (event.type === "done" || event.type === "error") {
|
|
206413
|
+
const completed = this.source ? this.completedSources.get(this.source) : void 0;
|
|
206414
|
+
this.finish(completed ?? event.type === "done");
|
|
206415
|
+
return;
|
|
206416
|
+
}
|
|
206417
|
+
if (event.type !== "delta" || !event.content)
|
|
206418
|
+
return;
|
|
206419
|
+
if (!this.firstText) {
|
|
206420
|
+
this.firstText = true;
|
|
206421
|
+
this.root.record(ETelemetryEventName.LOOP_FIRST_PUBLIC_TEXT, {
|
|
206422
|
+
[ETelemetryAttribute.LINKQUE_LOOP_FIRST_PUBLIC_TEXT_MS]: performance.now() - this.startedAt
|
|
206423
|
+
});
|
|
206424
|
+
}
|
|
206425
|
+
const source = this.sources.get(event);
|
|
206426
|
+
if (!source)
|
|
206427
|
+
return;
|
|
206428
|
+
if (source !== this.source) {
|
|
206429
|
+
this.finish(true);
|
|
206430
|
+
this.source = source;
|
|
206431
|
+
}
|
|
206432
|
+
if (this.truncated)
|
|
206433
|
+
return;
|
|
206434
|
+
for (const character of event.content) {
|
|
206435
|
+
const size = Buffer.byteLength(character, "utf8");
|
|
206436
|
+
if (this.bytes + size > 512 * 1024) {
|
|
206437
|
+
this.truncated = true;
|
|
206438
|
+
break;
|
|
206439
|
+
}
|
|
206440
|
+
this.bytes += size;
|
|
206441
|
+
this.text += character;
|
|
206442
|
+
if (this.text.length >= 16 * 1024)
|
|
206443
|
+
this.flush(false, false);
|
|
206444
|
+
}
|
|
206445
|
+
}
|
|
206446
|
+
finish(complete) {
|
|
206447
|
+
if (this.bytes)
|
|
206448
|
+
this.flush(true, complete && (this.source ? this.completedSources.get(this.source) ?? true : true));
|
|
206449
|
+
this.source = void 0;
|
|
206450
|
+
this.bytes = 0;
|
|
206451
|
+
this.index = 0;
|
|
206452
|
+
this.truncated = false;
|
|
206453
|
+
}
|
|
206454
|
+
flush(final, complete) {
|
|
206455
|
+
this.source?.record(ETelemetryEventName.CONTENT_RECORDED, {}, {
|
|
206456
|
+
section: ETelemetryContentSection.MODEL_OUTPUT,
|
|
206457
|
+
value: this.text,
|
|
206458
|
+
chunkIndex: this.index++,
|
|
206459
|
+
final,
|
|
206460
|
+
availability: final && complete && !this.truncated ? "available" : "partial"
|
|
206461
|
+
});
|
|
206462
|
+
this.text = "";
|
|
206463
|
+
}
|
|
206464
|
+
};
|
|
206465
|
+
}
|
|
206466
|
+
});
|
|
206467
|
+
|
|
206384
206468
|
// ../linkque-agent-runtime/dist/esm/core/telemetry/runtimeErrorBoundary.js
|
|
206385
206469
|
async function* withRuntimeErrorBoundary(telemetry, input, run, signal) {
|
|
206386
206470
|
const observation = startRuntimeObservation(telemetry, input);
|
|
@@ -206427,6 +206511,103 @@ var init_runtimeErrorBoundary = __esm({
|
|
|
206427
206511
|
}
|
|
206428
206512
|
});
|
|
206429
206513
|
|
|
206514
|
+
// ../linkque-agent-runtime/dist/esm/core/agentRuntimePlugin.js
|
|
206515
|
+
function assertAgentConfigRoot(value, pluginName) {
|
|
206516
|
+
if (typeof value !== "object" || value === null || !("agent" in value)) {
|
|
206517
|
+
throw new Error(`Agent runtime \u63D2\u4EF6 ${pluginName} \u7684 modifyAgentConfig \u8FD4\u56DE\u4E86\u65E0\u6548\u914D\u7F6E`);
|
|
206518
|
+
}
|
|
206519
|
+
}
|
|
206520
|
+
var validatePlugins, applyAgentRuntimePluginConfig, MergedHookExecutorHandler, resolveAgentRuntimeHookExecutor;
|
|
206521
|
+
var init_agentRuntimePlugin = __esm({
|
|
206522
|
+
"../linkque-agent-runtime/dist/esm/core/agentRuntimePlugin.js"() {
|
|
206523
|
+
"use strict";
|
|
206524
|
+
init_types();
|
|
206525
|
+
validatePlugins = (plugins) => {
|
|
206526
|
+
const names = /* @__PURE__ */ new Set();
|
|
206527
|
+
for (const plugin of plugins) {
|
|
206528
|
+
const name = plugin.name.trim();
|
|
206529
|
+
if (!name) {
|
|
206530
|
+
throw new Error("Agent runtime \u63D2\u4EF6 name \u4E0D\u80FD\u4E3A\u7A7A");
|
|
206531
|
+
}
|
|
206532
|
+
if (names.has(name)) {
|
|
206533
|
+
throw new Error(`Agent runtime \u63D2\u4EF6 name \u91CD\u590D: ${name}`);
|
|
206534
|
+
}
|
|
206535
|
+
names.add(name);
|
|
206536
|
+
}
|
|
206537
|
+
return plugins;
|
|
206538
|
+
};
|
|
206539
|
+
applyAgentRuntimePluginConfig = (agentConfig, plugins = []) => {
|
|
206540
|
+
const validatedPlugins = validatePlugins(plugins);
|
|
206541
|
+
const modifiers = validatedPlugins.filter((plugin) => plugin.modifyAgentConfig !== void 0);
|
|
206542
|
+
if (modifiers.length === 0)
|
|
206543
|
+
return agentConfig;
|
|
206544
|
+
let current = structuredClone(agentConfig);
|
|
206545
|
+
for (const plugin of modifiers) {
|
|
206546
|
+
try {
|
|
206547
|
+
const modified = plugin.modifyAgentConfig?.(current);
|
|
206548
|
+
if (modified !== void 0) {
|
|
206549
|
+
assertAgentConfigRoot(modified, plugin.name);
|
|
206550
|
+
current = modified;
|
|
206551
|
+
}
|
|
206552
|
+
current = structuredClone(current);
|
|
206553
|
+
} catch (error40) {
|
|
206554
|
+
throw new Error(`Agent runtime \u63D2\u4EF6 ${plugin.name} \u4FEE\u6539 Agent Config \u5931\u8D25`, { cause: error40 });
|
|
206555
|
+
}
|
|
206556
|
+
}
|
|
206557
|
+
return current;
|
|
206558
|
+
};
|
|
206559
|
+
MergedHookExecutorHandler = class {
|
|
206560
|
+
executorByName;
|
|
206561
|
+
constructor(executorByName) {
|
|
206562
|
+
this.executorByName = executorByName;
|
|
206563
|
+
}
|
|
206564
|
+
matches(resource, stage, subject) {
|
|
206565
|
+
const executor = this.executorByName.get(resource.config.executorName);
|
|
206566
|
+
return executor?.matches?.(resource, stage, subject) ?? true;
|
|
206567
|
+
}
|
|
206568
|
+
async execute(resource, context2, options) {
|
|
206569
|
+
const executor = this.executorByName.get(resource.config.executorName);
|
|
206570
|
+
if (executor)
|
|
206571
|
+
return executor.execute(resource, context2, options);
|
|
206572
|
+
return {
|
|
206573
|
+
ok: true,
|
|
206574
|
+
skipped: true,
|
|
206575
|
+
code: "PLUGIN_EXECUTOR_NOT_FOUND",
|
|
206576
|
+
message: `\u672A\u627E\u5230 name=${resource.config.executorName} \u7684 hook executor`
|
|
206577
|
+
};
|
|
206578
|
+
}
|
|
206579
|
+
};
|
|
206580
|
+
resolveAgentRuntimeHookExecutor = (plugins = [], portHookExecutorList = [], debugLog) => {
|
|
206581
|
+
const entries = validatePlugins(plugins).flatMap((plugin) => (plugin.hookExecutorList ?? []).map((executor, index2) => ({
|
|
206582
|
+
executor,
|
|
206583
|
+
source: `plugin:${plugin.name}[${index2}]`
|
|
206584
|
+
})));
|
|
206585
|
+
entries.push(...portHookExecutorList.map((executor, index2) => ({
|
|
206586
|
+
executor,
|
|
206587
|
+
source: `ports.hookExecutorList[${index2}]`
|
|
206588
|
+
})));
|
|
206589
|
+
if (entries.length === 0)
|
|
206590
|
+
return void 0;
|
|
206591
|
+
const merged = /* @__PURE__ */ new Map();
|
|
206592
|
+
for (const entry of entries) {
|
|
206593
|
+
const name = entry.executor.name;
|
|
206594
|
+
if (!name.trim())
|
|
206595
|
+
throw new Error(`Hook executor name \u4E0D\u80FD\u4E3A\u7A7A: ${entry.source}`);
|
|
206596
|
+
const previous = merged.get(name);
|
|
206597
|
+
if (previous) {
|
|
206598
|
+
try {
|
|
206599
|
+
debugLog?.(`[hook-executor-merge] name=${name} \u51B2\u7A81: ${previous.source} \u88AB ${entry.source} \u8986\u76D6`, EDebugLogScope.HOOK);
|
|
206600
|
+
} catch {
|
|
206601
|
+
}
|
|
206602
|
+
}
|
|
206603
|
+
merged.set(name, entry);
|
|
206604
|
+
}
|
|
206605
|
+
const executorByName = new Map([...merged].map(([name, entry]) => [name, entry.executor]));
|
|
206606
|
+
return new MergedHookExecutorHandler(executorByName);
|
|
206607
|
+
};
|
|
206608
|
+
}
|
|
206609
|
+
});
|
|
206610
|
+
|
|
206430
206611
|
// ../linkque-agent-runtime/dist/esm/core/cardSourceResult.js
|
|
206431
206612
|
async function createCardSourceReceipt(input) {
|
|
206432
206613
|
const resultRef = `card-source-result-${(0, import_node_crypto8.randomUUID)()}`;
|
|
@@ -206893,6 +207074,7 @@ var CARD_SEQUENCE, AFTER_CARD_DESCRIPTION, RESPONSE_MODE_DESCRIPTION, CardRender
|
|
|
206893
207074
|
var init_cardRenderMcpServer = __esm({
|
|
206894
207075
|
"../linkque-agent-runtime/dist/esm/core/cardRenderMcpServer.js"() {
|
|
206895
207076
|
"use strict";
|
|
207077
|
+
init_telemetry();
|
|
206896
207078
|
init_cardSourceResult();
|
|
206897
207079
|
init_cardTools();
|
|
206898
207080
|
init_mcpNaming();
|
|
@@ -206923,6 +207105,7 @@ var init_cardRenderMcpServer = __esm({
|
|
|
206923
207105
|
toolByName = /* @__PURE__ */ new Map();
|
|
206924
207106
|
sourceResultByRef = /* @__PURE__ */ new Map();
|
|
206925
207107
|
activeCardId;
|
|
207108
|
+
deliveries = /* @__PURE__ */ new WeakMap();
|
|
206926
207109
|
closed = false;
|
|
206927
207110
|
invalidCards = [];
|
|
206928
207111
|
/** 只信任本实例实际执行成功的结果,普通 MCP JSON 无权控制文字输出。 */
|
|
@@ -206959,7 +207142,11 @@ var init_cardRenderMcpServer = __esm({
|
|
|
206959
207142
|
});
|
|
206960
207143
|
continue;
|
|
206961
207144
|
}
|
|
206962
|
-
const state2 = {
|
|
207145
|
+
const state2 = {
|
|
207146
|
+
selected: false,
|
|
207147
|
+
results: /* @__PURE__ */ new Map(),
|
|
207148
|
+
executionId: void 0
|
|
207149
|
+
};
|
|
206963
207150
|
this.states.set(resource.resourceId, state2);
|
|
206964
207151
|
const finishName = createCardFinishToolName(resource.resourceId);
|
|
206965
207152
|
const readName = createCardSourceReadToolName(resource.resourceId);
|
|
@@ -206975,7 +207162,9 @@ var init_cardRenderMcpServer = __esm({
|
|
|
206975
207162
|
properties: {},
|
|
206976
207163
|
additionalProperties: false
|
|
206977
207164
|
},
|
|
206978
|
-
execute: async () => {
|
|
207165
|
+
execute: async (_args, _signal, context2) => {
|
|
207166
|
+
state2.executionId = context2?.toolCallId;
|
|
207167
|
+
this.observeCard(context2, resource, config2, "prepare", state2.executionId);
|
|
206979
207168
|
for (const candidate of this.states.values())
|
|
206980
207169
|
candidate.selected = false;
|
|
206981
207170
|
this.activeCardId = resource.resourceId;
|
|
@@ -207013,6 +207202,8 @@ var init_cardRenderMcpServer = __esm({
|
|
|
207013
207202
|
inputSchema: normalizeMcpInputSchema(discoveredHandle?.inputSchema),
|
|
207014
207203
|
outputSchema: CARD_SOURCE_RECEIPT_SCHEMA,
|
|
207015
207204
|
execute: async (args, signal, context2) => {
|
|
207205
|
+
const executionId = state2.executionId;
|
|
207206
|
+
this.observeCard(context2, resource, config2, "source", executionId, source.sourceId);
|
|
207016
207207
|
if (!state2.selected || this.activeCardId !== resource.resourceId)
|
|
207017
207208
|
throw new Error(`\u8C03\u7528\u6570\u636E\u6E90\u524D\uFF0C\u8BF7\u5148\u9009\u62E9\u5361\u7247 ${name}`);
|
|
207018
207209
|
const missingDependencies = (source.dependsOn ?? []).filter((dependency) => !state2.results.has(dependency));
|
|
@@ -207056,7 +207247,10 @@ var init_cardRenderMcpServer = __esm({
|
|
|
207056
207247
|
signal?.throwIfAborted();
|
|
207057
207248
|
if (this.closed)
|
|
207058
207249
|
throw new Error("\u5361\u7247\u8FD0\u884C\u5DF2\u7ED3\u675F");
|
|
207059
|
-
this.sourceResultByRef.set(cacheEntry.resultRef,
|
|
207250
|
+
this.sourceResultByRef.set(cacheEntry.resultRef, {
|
|
207251
|
+
...cacheEntry,
|
|
207252
|
+
executionId
|
|
207253
|
+
});
|
|
207060
207254
|
this.logMetric(() => `source=${source.sourceId} mcpMs=${projectionStartedAt - mcpStartedAt} projectionMs=${Date.now() - projectionStartedAt} rawBytes=${byteLength(structured)} receiptBytes=${byteLength(receipt)}`);
|
|
207061
207255
|
return receipt;
|
|
207062
207256
|
}
|
|
@@ -207070,17 +207264,18 @@ var init_cardRenderMcpServer = __esm({
|
|
|
207070
207264
|
description: "\u8BFB\u53D6\u672C\u8F6E\u5DF2\u6210\u529F\u6267\u884C\u7684\u6570\u636E\u6E90\u7F13\u5B58\uFF0C\u4E0D\u4F1A\u518D\u6B21\u8C03\u7528 MCP\u3002\u4EC5\u5F53\u6570\u636E\u6E90\u56DE\u6267\u7F3A\u5C11\u51B3\u7B56\u6240\u9700\u5B57\u6BB5\u3001\u6807\u8BB0\u4E3A\u4E0D\u5B8C\u6574\uFF0C\u6216\u540E\u7EED\u5DE5\u5177\u9700\u8981\u672A\u7ED1\u5B9A\u5B57\u6BB5\u65F6\u8C03\u7528\u3002\u4F18\u5148\u8BFB\u53D6 bound \u89C6\u56FE\uFF1B\u8BFB\u53D6\u96C6\u5408\u540E\u7EED\u6761\u76EE\u65F6\uFF0C\u628A\u56DE\u6267 fields.path \u4F5C\u4E3A path \u5E76\u8BBE\u7F6E offset/limit\uFF1B\u53EA\u6709\u672A\u7ED1\u5B9A\u5B57\u6BB5\u624D\u4F7F\u7528 raw\u3002\u4E0D\u8981\u628A\u5206\u9875\u6216\u622A\u65AD\u7ED3\u679C\u5F53\u4F5C\u5168\u96C6\u3002",
|
|
207071
207265
|
inputSchema: CARD_SOURCE_READ_INPUT_SCHEMA,
|
|
207072
207266
|
outputSchema: CARD_SOURCE_READ_OUTPUT_SCHEMA,
|
|
207073
|
-
execute: async (args) => {
|
|
207267
|
+
execute: async (args, _signal, context2) => {
|
|
207074
207268
|
const resultRef = readResultRef(args);
|
|
207269
|
+
const entry = this.sourceResultByRef.get(resultRef);
|
|
207270
|
+
const matchingEntry = entry?.cardId === resource.resourceId ? entry : void 0;
|
|
207271
|
+
this.observeCard(context2, resource, config2, "read", matchingEntry?.executionId);
|
|
207075
207272
|
if (this.closed)
|
|
207076
207273
|
throw new Error(`\u7F13\u5B58\u5DF2\u5931\u6548: ${resultRef}`);
|
|
207077
|
-
|
|
207078
|
-
if (!entry || entry.cardId !== resource.resourceId) {
|
|
207274
|
+
if (!matchingEntry)
|
|
207079
207275
|
throw new Error(`\u672A\u77E5\u7ED3\u679C\u5F15\u7528: ${resultRef}`);
|
|
207080
|
-
}
|
|
207081
207276
|
const startedAt = Date.now();
|
|
207082
|
-
const receipt = readCardSourceResult(
|
|
207083
|
-
this.logMetric(() => `source=${
|
|
207277
|
+
const receipt = readCardSourceResult(matchingEntry, args);
|
|
207278
|
+
this.logMetric(() => `source=${matchingEntry.sourceId} cacheReadMs=${Date.now() - startedAt} receiptBytes=${byteLength(receipt)}`);
|
|
207084
207279
|
return receipt;
|
|
207085
207280
|
}
|
|
207086
207281
|
});
|
|
@@ -207108,12 +207303,15 @@ ${AFTER_CARD_DESCRIPTION}`,
|
|
|
207108
207303
|
},
|
|
207109
207304
|
additionalProperties: false
|
|
207110
207305
|
},
|
|
207111
|
-
execute: async (args, signal) => {
|
|
207306
|
+
execute: async (args, signal, context2) => {
|
|
207307
|
+
this.observeCard(context2, resource, config2, "finish", state2.executionId);
|
|
207112
207308
|
if (!state2.selected || this.activeCardId !== resource.resourceId)
|
|
207113
207309
|
throw new Error(`\u5B8C\u6210\u5C55\u793A\u524D\uFF0C\u8BF7\u5148\u9009\u62E9\u5361\u7247 ${name}`);
|
|
207114
207310
|
const afterCard = readAfterCard(args);
|
|
207115
207311
|
const finishStartedAt = Date.now();
|
|
207116
207312
|
const result = await executeCardPresentationFromSources(resource, this.runtimeContext, state2.results, signal);
|
|
207313
|
+
if (context2?.observation)
|
|
207314
|
+
this.deliveries.set(result.card, context2.observation);
|
|
207117
207315
|
if (afterCard !== void 0) {
|
|
207118
207316
|
this.companions.set(result, afterCard);
|
|
207119
207317
|
result.modelText += `
|
|
@@ -207145,7 +207343,11 @@ ${AFTER_CARD_DESCRIPTION}`,
|
|
|
207145
207343
|
throw new Error(`\u672A\u77E5\u5361\u7247\u5DE5\u5177: ${name}`);
|
|
207146
207344
|
return descriptor.execute(args, signal, options?.context);
|
|
207147
207345
|
}
|
|
207148
|
-
|
|
207346
|
+
this.observeCard(options?.context, resource, config2, "finish", options?.context?.toolCallId);
|
|
207347
|
+
const result = await executeCardPresentation(resource, this.registry, this.runtimeContext, args, signal, options?.context);
|
|
207348
|
+
if (options?.context?.observation)
|
|
207349
|
+
this.deliveries.set(result.card, options.context.observation);
|
|
207350
|
+
return result;
|
|
207149
207351
|
}
|
|
207150
207352
|
async close() {
|
|
207151
207353
|
this.closed = true;
|
|
@@ -207155,6 +207357,17 @@ ${AFTER_CARD_DESCRIPTION}`,
|
|
|
207155
207357
|
this.toolByName.clear();
|
|
207156
207358
|
this.companions = /* @__PURE__ */ new WeakMap();
|
|
207157
207359
|
}
|
|
207360
|
+
/** 记录执行时配置和显式关联,不从工具名称反推业务身份。 */
|
|
207361
|
+
observeCard(context2, resource, config2, phase, executionId, sourceId) {
|
|
207362
|
+
context2?.observation?.record(ETelemetryEventName.TOOL_CONTEXT, {
|
|
207363
|
+
[ETelemetryAttribute.LINKQUE_CARD_REF]: resource.resourceId,
|
|
207364
|
+
[ETelemetryAttribute.LINKQUE_CARD_REVISION]: config2.revision,
|
|
207365
|
+
[ETelemetryAttribute.LINKQUE_CARD_DISPLAY_NAME]: config2.displayName,
|
|
207366
|
+
[ETelemetryAttribute.LINKQUE_CARD_PHASE]: phase,
|
|
207367
|
+
...executionId ? { [ETelemetryAttribute.LINKQUE_CARD_EXECUTION_ID]: executionId } : {},
|
|
207368
|
+
...sourceId ? { [ETelemetryAttribute.LINKQUE_CARD_SOURCE_ID]: sourceId } : {}
|
|
207369
|
+
});
|
|
207370
|
+
}
|
|
207158
207371
|
logMetric(message) {
|
|
207159
207372
|
try {
|
|
207160
207373
|
if (!this.debugLog)
|
|
@@ -207164,7 +207377,7 @@ ${AFTER_CARD_DESCRIPTION}`,
|
|
|
207164
207377
|
}
|
|
207165
207378
|
}
|
|
207166
207379
|
/** 卡片与伴随文字的共享输出边界,不参与模型循环或工具调度。 */
|
|
207167
|
-
async *projectConversation(events) {
|
|
207380
|
+
async *projectConversation(events, publicOutput) {
|
|
207168
207381
|
const pending = /* @__PURE__ */ new WeakMap();
|
|
207169
207382
|
let cardOwnsText = false;
|
|
207170
207383
|
for await (const event of events) {
|
|
@@ -207181,13 +207394,24 @@ ${AFTER_CARD_DESCRIPTION}`,
|
|
|
207181
207394
|
if (event.type === "a2ui_card" && pending.has(event)) {
|
|
207182
207395
|
this.logMetric(`phase=card-event-emitted atMs=${Date.now()}`);
|
|
207183
207396
|
}
|
|
207397
|
+
if (event.type === "a2ui_card") {
|
|
207398
|
+
this.deliveries.get(event)?.record(ETelemetryEventName.TOOL_CONTEXT, {
|
|
207399
|
+
[ETelemetryAttribute.LINKQUE_CARD_DELIVERY]: "emitted"
|
|
207400
|
+
});
|
|
207401
|
+
}
|
|
207184
207402
|
yield event;
|
|
207185
207403
|
if (event.type === "a2ui_card" && pending.has(event)) {
|
|
207186
207404
|
const text2 = pending.get(event);
|
|
207187
207405
|
pending.delete(event);
|
|
207188
207406
|
cardOwnsText = true;
|
|
207189
|
-
if (text2)
|
|
207190
|
-
|
|
207407
|
+
if (text2) {
|
|
207408
|
+
const companion = { type: "delta", content: text2 };
|
|
207409
|
+
const source = this.deliveries.get(event);
|
|
207410
|
+
publicOutput?.associate(companion, source);
|
|
207411
|
+
publicOutput?.completeSource(source, true);
|
|
207412
|
+
yield companion;
|
|
207413
|
+
}
|
|
207414
|
+
this.deliveries.delete(event);
|
|
207191
207415
|
}
|
|
207192
207416
|
}
|
|
207193
207417
|
}
|
|
@@ -207310,103 +207534,6 @@ var init_noopKnowledgeSearchPort = __esm({
|
|
|
207310
207534
|
}
|
|
207311
207535
|
});
|
|
207312
207536
|
|
|
207313
|
-
// ../linkque-agent-runtime/dist/esm/core/agentRuntimePlugin.js
|
|
207314
|
-
function assertAgentConfigRoot(value, pluginName) {
|
|
207315
|
-
if (typeof value !== "object" || value === null || !("agent" in value)) {
|
|
207316
|
-
throw new Error(`Agent runtime \u63D2\u4EF6 ${pluginName} \u7684 modifyAgentConfig \u8FD4\u56DE\u4E86\u65E0\u6548\u914D\u7F6E`);
|
|
207317
|
-
}
|
|
207318
|
-
}
|
|
207319
|
-
var validatePlugins, applyAgentRuntimePluginConfig, MergedHookExecutorHandler, resolveAgentRuntimeHookExecutor;
|
|
207320
|
-
var init_agentRuntimePlugin = __esm({
|
|
207321
|
-
"../linkque-agent-runtime/dist/esm/core/agentRuntimePlugin.js"() {
|
|
207322
|
-
"use strict";
|
|
207323
|
-
init_types();
|
|
207324
|
-
validatePlugins = (plugins) => {
|
|
207325
|
-
const names = /* @__PURE__ */ new Set();
|
|
207326
|
-
for (const plugin of plugins) {
|
|
207327
|
-
const name = plugin.name.trim();
|
|
207328
|
-
if (!name) {
|
|
207329
|
-
throw new Error("Agent runtime \u63D2\u4EF6 name \u4E0D\u80FD\u4E3A\u7A7A");
|
|
207330
|
-
}
|
|
207331
|
-
if (names.has(name)) {
|
|
207332
|
-
throw new Error(`Agent runtime \u63D2\u4EF6 name \u91CD\u590D: ${name}`);
|
|
207333
|
-
}
|
|
207334
|
-
names.add(name);
|
|
207335
|
-
}
|
|
207336
|
-
return plugins;
|
|
207337
|
-
};
|
|
207338
|
-
applyAgentRuntimePluginConfig = (agentConfig, plugins = []) => {
|
|
207339
|
-
const validatedPlugins = validatePlugins(plugins);
|
|
207340
|
-
const modifiers = validatedPlugins.filter((plugin) => plugin.modifyAgentConfig !== void 0);
|
|
207341
|
-
if (modifiers.length === 0)
|
|
207342
|
-
return agentConfig;
|
|
207343
|
-
let current = structuredClone(agentConfig);
|
|
207344
|
-
for (const plugin of modifiers) {
|
|
207345
|
-
try {
|
|
207346
|
-
const modified = plugin.modifyAgentConfig?.(current);
|
|
207347
|
-
if (modified !== void 0) {
|
|
207348
|
-
assertAgentConfigRoot(modified, plugin.name);
|
|
207349
|
-
current = modified;
|
|
207350
|
-
}
|
|
207351
|
-
current = structuredClone(current);
|
|
207352
|
-
} catch (error40) {
|
|
207353
|
-
throw new Error(`Agent runtime \u63D2\u4EF6 ${plugin.name} \u4FEE\u6539 Agent Config \u5931\u8D25`, { cause: error40 });
|
|
207354
|
-
}
|
|
207355
|
-
}
|
|
207356
|
-
return current;
|
|
207357
|
-
};
|
|
207358
|
-
MergedHookExecutorHandler = class {
|
|
207359
|
-
executorByName;
|
|
207360
|
-
constructor(executorByName) {
|
|
207361
|
-
this.executorByName = executorByName;
|
|
207362
|
-
}
|
|
207363
|
-
matches(resource, stage, subject) {
|
|
207364
|
-
const executor = this.executorByName.get(resource.config.executorName);
|
|
207365
|
-
return executor?.matches?.(resource, stage, subject) ?? true;
|
|
207366
|
-
}
|
|
207367
|
-
async execute(resource, context2, options) {
|
|
207368
|
-
const executor = this.executorByName.get(resource.config.executorName);
|
|
207369
|
-
if (executor)
|
|
207370
|
-
return executor.execute(resource, context2, options);
|
|
207371
|
-
return {
|
|
207372
|
-
ok: true,
|
|
207373
|
-
skipped: true,
|
|
207374
|
-
code: "PLUGIN_EXECUTOR_NOT_FOUND",
|
|
207375
|
-
message: `\u672A\u627E\u5230 name=${resource.config.executorName} \u7684 hook executor`
|
|
207376
|
-
};
|
|
207377
|
-
}
|
|
207378
|
-
};
|
|
207379
|
-
resolveAgentRuntimeHookExecutor = (plugins = [], portHookExecutorList = [], debugLog) => {
|
|
207380
|
-
const entries = validatePlugins(plugins).flatMap((plugin) => (plugin.hookExecutorList ?? []).map((executor, index2) => ({
|
|
207381
|
-
executor,
|
|
207382
|
-
source: `plugin:${plugin.name}[${index2}]`
|
|
207383
|
-
})));
|
|
207384
|
-
entries.push(...portHookExecutorList.map((executor, index2) => ({
|
|
207385
|
-
executor,
|
|
207386
|
-
source: `ports.hookExecutorList[${index2}]`
|
|
207387
|
-
})));
|
|
207388
|
-
if (entries.length === 0)
|
|
207389
|
-
return void 0;
|
|
207390
|
-
const merged = /* @__PURE__ */ new Map();
|
|
207391
|
-
for (const entry of entries) {
|
|
207392
|
-
const name = entry.executor.name;
|
|
207393
|
-
if (!name.trim())
|
|
207394
|
-
throw new Error(`Hook executor name \u4E0D\u80FD\u4E3A\u7A7A: ${entry.source}`);
|
|
207395
|
-
const previous = merged.get(name);
|
|
207396
|
-
if (previous) {
|
|
207397
|
-
try {
|
|
207398
|
-
debugLog?.(`[hook-executor-merge] name=${name} \u51B2\u7A81: ${previous.source} \u88AB ${entry.source} \u8986\u76D6`, EDebugLogScope.HOOK);
|
|
207399
|
-
} catch {
|
|
207400
|
-
}
|
|
207401
|
-
}
|
|
207402
|
-
merged.set(name, entry);
|
|
207403
|
-
}
|
|
207404
|
-
const executorByName = new Map([...merged].map(([name, entry]) => [name, entry.executor]));
|
|
207405
|
-
return new MergedHookExecutorHandler(executorByName);
|
|
207406
|
-
};
|
|
207407
|
-
}
|
|
207408
|
-
});
|
|
207409
|
-
|
|
207410
207537
|
// ../linkque-agent-runtime/dist/esm/core/agentRuntime.js
|
|
207411
207538
|
function composeSystemPrompt(harnessPrompt, systemPrompt, skillcatalog = "", runtimePatchSuffix = "") {
|
|
207412
207539
|
const parts = [];
|
|
@@ -207443,34 +207570,35 @@ var init_agentRuntime = __esm({
|
|
|
207443
207570
|
"use strict";
|
|
207444
207571
|
init_telemetry();
|
|
207445
207572
|
init_noopRuntimeTelemetry();
|
|
207573
|
+
init_publicOutputObservation();
|
|
207446
207574
|
init_runtimeErrorBoundary();
|
|
207447
207575
|
init_toolObservation();
|
|
207448
|
-
init_types();
|
|
207449
207576
|
init_esm();
|
|
207450
|
-
|
|
207577
|
+
init_types();
|
|
207451
207578
|
init_followUpQuestionGenerator();
|
|
207452
|
-
|
|
207453
|
-
|
|
207454
|
-
init_noopMcpServerProvider();
|
|
207455
|
-
init_mcpProxyTool();
|
|
207456
|
-
init_mcpAggregator();
|
|
207579
|
+
init_piAgentLoop();
|
|
207580
|
+
init_agentRuntimePlugin();
|
|
207457
207581
|
init_cardRenderMcpServer();
|
|
207458
|
-
init_cardTools();
|
|
207459
207582
|
init_cardRenderMcpServerProvider();
|
|
207583
|
+
init_cardTools();
|
|
207460
207584
|
init_createKnowledgeTools();
|
|
207461
|
-
init_noopKnowledgeSearchPort();
|
|
207462
207585
|
init_createWebSearchTool();
|
|
207463
|
-
init_noopWebSearchPort();
|
|
207464
|
-
init_webSearchResource();
|
|
207465
|
-
init_skillTools();
|
|
207466
207586
|
init_followUpQuestions();
|
|
207467
207587
|
init_hookContext();
|
|
207468
207588
|
init_hookDispatcher();
|
|
207469
207589
|
init_hookRegistry();
|
|
207590
|
+
init_hookToolWrapper();
|
|
207470
207591
|
init_noopHookExecutor();
|
|
207471
207592
|
init_sideEffectRunner();
|
|
207472
|
-
|
|
207473
|
-
|
|
207593
|
+
init_inMemorySessionManager();
|
|
207594
|
+
init_mcpAggregator();
|
|
207595
|
+
init_mcpProxyTool();
|
|
207596
|
+
init_noopKnowledgeSearchPort();
|
|
207597
|
+
init_noopMcpServerProvider();
|
|
207598
|
+
init_noopSkillLoader();
|
|
207599
|
+
init_noopWebSearchPort();
|
|
207600
|
+
init_skillTools();
|
|
207601
|
+
init_webSearchResource();
|
|
207474
207602
|
DEFAULT_HARNESS_PROMPT = `# Harness \u8FD0\u884C\u89C4\u7EA6
|
|
207475
207603
|
|
|
207476
207604
|
\u4F60\u662F\u8FD0\u884C\u5728 LinkQue harness \u4E4B\u4E0B\u7684\u667A\u80FD\u4F53\u3002\u8BF7\u9075\u5B88\u4EE5\u4E0B\u7A33\u5B9A\u8FD0\u884C\u89C4\u7EA6:
|
|
@@ -207936,8 +208064,11 @@ var init_agentRuntime = __esm({
|
|
|
207936
208064
|
...assistantText !== "" && { messageContent: assistantText }
|
|
207937
208065
|
});
|
|
207938
208066
|
};
|
|
208067
|
+
const publicOutput = new PublicOutputObservation(observation);
|
|
208068
|
+
agentReq.publicOutput = publicOutput;
|
|
207939
208069
|
try {
|
|
207940
|
-
for await (const ev of cardServer.projectConversation(this.agentLoop.run(agentReq))) {
|
|
208070
|
+
for await (const ev of cardServer.projectConversation(this.agentLoop.run(agentReq), publicOutput)) {
|
|
208071
|
+
publicOutput.accept(ev);
|
|
207941
208072
|
if (ev.type === "delta")
|
|
207942
208073
|
assistantText += ev.content;
|
|
207943
208074
|
if (ev.type === "tool_end" && !ev.isError) {
|
|
@@ -207999,6 +208130,7 @@ var init_agentRuntime = __esm({
|
|
|
207999
208130
|
await dispatchTerminalHook();
|
|
208000
208131
|
yield ev;
|
|
208001
208132
|
}
|
|
208133
|
+
publicOutput.finish(true);
|
|
208002
208134
|
await dispatchTerminalHook();
|
|
208003
208135
|
} catch (error40) {
|
|
208004
208136
|
if (!terminalHookDispatched) {
|
|
@@ -208009,6 +208141,8 @@ var init_agentRuntime = __esm({
|
|
|
208009
208141
|
await dispatchTerminalHook();
|
|
208010
208142
|
}
|
|
208011
208143
|
throw error40;
|
|
208144
|
+
} finally {
|
|
208145
|
+
publicOutput.finish(false);
|
|
208012
208146
|
}
|
|
208013
208147
|
}
|
|
208014
208148
|
};
|
|
@@ -216625,6 +216759,14 @@ var allowedAttributeKeys = /* @__PURE__ */ new Set([
|
|
|
216625
216759
|
ETelemetryAttribute.HARNESS_MODEL_PURPOSE,
|
|
216626
216760
|
ETelemetryAttribute.HARNESS_MODEL_INVOCATION_COUNT,
|
|
216627
216761
|
ETelemetryAttribute.GEN_AI_TOOL_NAME,
|
|
216762
|
+
ETelemetryAttribute.LINKQUE_TOOL_DISPLAY_NAME,
|
|
216763
|
+
ETelemetryAttribute.LINKQUE_CARD_EXECUTION_ID,
|
|
216764
|
+
ETelemetryAttribute.LINKQUE_CARD_REF,
|
|
216765
|
+
ETelemetryAttribute.LINKQUE_CARD_REVISION,
|
|
216766
|
+
ETelemetryAttribute.LINKQUE_CARD_DISPLAY_NAME,
|
|
216767
|
+
ETelemetryAttribute.LINKQUE_CARD_PHASE,
|
|
216768
|
+
ETelemetryAttribute.LINKQUE_CARD_SOURCE_ID,
|
|
216769
|
+
ETelemetryAttribute.LINKQUE_CARD_DELIVERY,
|
|
216628
216770
|
ETelemetryAttribute.GEN_AI_TOOL_CALL_ID,
|
|
216629
216771
|
ETelemetryAttribute.HARNESS_TOOL_RESULT_STATUS,
|
|
216630
216772
|
ETelemetryAttribute.LINKQUE_TOOL_FAILURE_STAGE,
|