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
|
@@ -40,13 +40,13 @@ import {
|
|
|
40
40
|
resolveRunStorage,
|
|
41
41
|
toAgentRunMessages,
|
|
42
42
|
withIsoTimestamp
|
|
43
|
-
} from "../../chunk-
|
|
43
|
+
} from "../../chunk-STGFILDE.js";
|
|
44
44
|
import "../../chunk-IWOFD643.js";
|
|
45
45
|
import "../../chunk-PXCGFBV5.js";
|
|
46
46
|
import "../../chunk-ETG6PNHQ.js";
|
|
47
47
|
import {
|
|
48
48
|
getBakedProtocol
|
|
49
|
-
} from "../../chunk-
|
|
49
|
+
} from "../../chunk-JD3IL3IC.js";
|
|
50
50
|
import {
|
|
51
51
|
ACTIVATE_SKILL_TOOL_NAME,
|
|
52
52
|
CANCEL_CONVERSATION_RUN_OPERATION,
|
|
@@ -163,7 +163,7 @@ import {
|
|
|
163
163
|
summarizeBody,
|
|
164
164
|
warnLogFailure,
|
|
165
165
|
wrapToolWithHooks
|
|
166
|
-
} from "../../chunk-
|
|
166
|
+
} from "../../chunk-PM2UO433.js";
|
|
167
167
|
import "../../chunk-EAODRPW4.js";
|
|
168
168
|
import "../../chunk-XUFLSZM4.js";
|
|
169
169
|
import "../../chunk-GAYNLDWK.js";
|
|
@@ -7977,6 +7977,7 @@ function observeTool(tool, observation) {
|
|
|
7977
7977
|
eventPrefix: ETelemetryEventPrefix.TOOL_ATTEMPT,
|
|
7978
7978
|
attributes: {
|
|
7979
7979
|
[ETelemetryAttribute.GEN_AI_TOOL_NAME]: tool.modelName ?? tool.name,
|
|
7980
|
+
[ETelemetryAttribute.LINKQUE_TOOL_DISPLAY_NAME]: tool.label ?? tool.name,
|
|
7980
7981
|
[ETelemetryAttribute.GEN_AI_TOOL_CALL_ID]: context?.toolCallId ?? "",
|
|
7981
7982
|
[ETelemetryAttribute.HARNESS_ATTEMPT_ID]: randomUUID(),
|
|
7982
7983
|
[ETelemetryAttribute.HARNESS_ATTEMPT_VISIBILITY]: ETelemetryAttemptVisibility.TOOL_PROVIDER_INVOCATION
|
|
@@ -8020,49 +8021,9 @@ import { randomUUID as randomUUID2 } from "node:crypto";
|
|
|
8020
8021
|
var PiTelemetry = class {
|
|
8021
8022
|
root;
|
|
8022
8023
|
iterationIndex = 0;
|
|
8023
|
-
replyText = "";
|
|
8024
|
-
replyBytes = 0;
|
|
8025
|
-
replyIndex = 0;
|
|
8026
|
-
replyTruncated = false;
|
|
8027
|
-
maxReplyBytes = 512 * 1024;
|
|
8028
|
-
/** 正文分块独立落盘;每条最坏 JSON 编码也低于日志单行 1 MiB 上限。 */
|
|
8029
|
-
recordReplyChunk(final, complete) {
|
|
8030
|
-
this.root.find(ETelemetryAssociation.MODEL)?.record(ETelemetryEventName.CONTENT_RECORDED, {}, {
|
|
8031
|
-
section: ETelemetryContentSection.MODEL_OUTPUT,
|
|
8032
|
-
value: this.replyText,
|
|
8033
|
-
chunkIndex: this.replyIndex++,
|
|
8034
|
-
final,
|
|
8035
|
-
availability: final && complete && !this.replyTruncated ? "available" : "partial"
|
|
8036
|
-
});
|
|
8037
|
-
this.replyText = "";
|
|
8038
|
-
}
|
|
8039
|
-
flushReply(complete) {
|
|
8040
|
-
if (this.replyBytes)
|
|
8041
|
-
this.recordReplyChunk(true, complete);
|
|
8042
|
-
this.replyBytes = 0;
|
|
8043
|
-
this.replyIndex = 0;
|
|
8044
|
-
this.replyTruncated = false;
|
|
8045
|
-
}
|
|
8046
|
-
appendReply(text2) {
|
|
8047
|
-
if (this.replyTruncated)
|
|
8048
|
-
return;
|
|
8049
|
-
for (const character of text2) {
|
|
8050
|
-
const bytes = Buffer.byteLength(character, "utf8");
|
|
8051
|
-
if (this.replyBytes + bytes > this.maxReplyBytes) {
|
|
8052
|
-
this.replyTruncated = true;
|
|
8053
|
-
break;
|
|
8054
|
-
}
|
|
8055
|
-
this.replyText += character;
|
|
8056
|
-
this.replyBytes += bytes;
|
|
8057
|
-
if (this.replyText.length >= 16 * 1024)
|
|
8058
|
-
this.recordReplyChunk(false, false);
|
|
8059
|
-
}
|
|
8060
|
-
}
|
|
8061
8024
|
proposed = /* @__PURE__ */ new Map();
|
|
8062
8025
|
loop;
|
|
8063
8026
|
lastProvider = null;
|
|
8064
|
-
publicTextSeen = false;
|
|
8065
|
-
started = performance.now();
|
|
8066
8027
|
terminal = ETelemetryStreamTermination.EXHAUSTED;
|
|
8067
8028
|
constructor(root) {
|
|
8068
8029
|
this.root = root;
|
|
@@ -8077,6 +8038,9 @@ var PiTelemetry = class {
|
|
|
8077
8038
|
[ETelemetryAttribute.LINKQUE_TELEMETRY_COVERAGE]: ETelemetryCoverage.PI_MODEL_TOOL_HOOK
|
|
8078
8039
|
});
|
|
8079
8040
|
}
|
|
8041
|
+
get currentModel() {
|
|
8042
|
+
return this.root.find(ETelemetryAssociation.MODEL);
|
|
8043
|
+
}
|
|
8080
8044
|
startModel(model) {
|
|
8081
8045
|
const parent = this.root.find(ETelemetryAssociation.ITERATION) ?? this.loop;
|
|
8082
8046
|
return parent.startOperation({
|
|
@@ -8159,7 +8123,6 @@ var PiTelemetry = class {
|
|
|
8159
8123
|
}
|
|
8160
8124
|
case "message_end":
|
|
8161
8125
|
if (event.message.role === "assistant") {
|
|
8162
|
-
this.flushReply(event.message.stopReason !== "error" && event.message.stopReason !== "aborted");
|
|
8163
8126
|
const failed = event.message.stopReason === "error" || event.message.stopReason === "aborted";
|
|
8164
8127
|
this.root.find(ETelemetryAssociation.MODEL)?.finish(event.message.stopReason === "aborted" ? ETelemetryOutcome.CANCELLED : failed ? ETelemetryOutcome.ERROR : ETelemetryOutcome.SUCCESS, {
|
|
8165
8128
|
[ETelemetryAttribute.GEN_AI_RESPONSE_FINISH_REASONS]: [
|
|
@@ -8174,14 +8137,6 @@ var PiTelemetry = class {
|
|
|
8174
8137
|
break;
|
|
8175
8138
|
case "message_update": {
|
|
8176
8139
|
const update = event.assistantMessageEvent;
|
|
8177
|
-
if (update.type === "text_delta")
|
|
8178
|
-
this.appendReply(update.delta);
|
|
8179
|
-
if (update.type === "text_delta" && update.delta && !this.publicTextSeen) {
|
|
8180
|
-
this.publicTextSeen = true;
|
|
8181
|
-
this.loop.record(ETelemetryEventName.LOOP_FIRST_PUBLIC_TEXT, {
|
|
8182
|
-
[ETelemetryAttribute.LINKQUE_LOOP_FIRST_PUBLIC_TEXT_MS]: performance.now() - this.started
|
|
8183
|
-
});
|
|
8184
|
-
}
|
|
8185
8140
|
if (update.type === "error")
|
|
8186
8141
|
this.terminal = update.reason === "aborted" ? ETelemetryStreamTermination.CANCEL : ETelemetryStreamTermination.ERROR;
|
|
8187
8142
|
break;
|
|
@@ -8206,7 +8161,6 @@ var PiTelemetry = class {
|
|
|
8206
8161
|
this.terminal = ETelemetryStreamTermination.ERROR;
|
|
8207
8162
|
}
|
|
8208
8163
|
close(cancelled) {
|
|
8209
|
-
this.flushReply(false);
|
|
8210
8164
|
this.proposed.clear();
|
|
8211
8165
|
this.loop.finish(this.terminal === ETelemetryStreamTermination.ERROR ? ETelemetryOutcome.ERROR : cancelled || this.terminal === ETelemetryStreamTermination.CANCEL ? ETelemetryOutcome.CANCELLED : this.terminal === ETelemetryStreamTermination.COMPLETE ? ETelemetryOutcome.SUCCESS : ETelemetryOutcome.UNKNOWN, {
|
|
8212
8166
|
[ETelemetryAttribute.LINKQUE_STREAM_TERMINATION]: this.terminal === ETelemetryStreamTermination.ERROR ? ETelemetryStreamTermination.ERROR : cancelled ? ETelemetryStreamTermination.CANCEL : this.terminal
|
|
@@ -40542,6 +40496,9 @@ var StreamBridge = class {
|
|
|
40542
40496
|
this.unsubscribe = this.session.subscribe((event) => {
|
|
40543
40497
|
if (this.aborted)
|
|
40544
40498
|
return;
|
|
40499
|
+
if (event.type === "message_end" && event.message.role === "assistant") {
|
|
40500
|
+
this.options.publicOutput?.completeSource(this.telemetry?.currentModel, event.message.stopReason !== "error" && event.message.stopReason !== "aborted");
|
|
40501
|
+
}
|
|
40545
40502
|
this.telemetry?.onEvent(event);
|
|
40546
40503
|
this.logDebug(`[pi-event] ${this.safeStringify(event)}`);
|
|
40547
40504
|
for (const translated of translateEvents(event, this.uiStatusToolNames)) {
|
|
@@ -40550,6 +40507,7 @@ var StreamBridge = class {
|
|
|
40550
40507
|
return;
|
|
40551
40508
|
this.settled = true;
|
|
40552
40509
|
}
|
|
40510
|
+
this.options.publicOutput?.associate(translated, this.telemetry?.currentModel);
|
|
40553
40511
|
this.enqueue(translated);
|
|
40554
40512
|
}
|
|
40555
40513
|
});
|
|
@@ -40761,6 +40719,7 @@ var PiAgentLoop = class {
|
|
|
40761
40719
|
},
|
|
40762
40720
|
...req.debugLog && { debugLog: req.debugLog },
|
|
40763
40721
|
...req.observation && { observation: req.observation },
|
|
40722
|
+
...req.publicOutput && { publicOutput: req.publicOutput },
|
|
40764
40723
|
// agentId 透传:agentService 在 LINKQUE provider 时注入 x-agent-id 请求头,供网关计费归因。
|
|
40765
40724
|
...req.agentId !== void 0 && { agentId: req.agentId },
|
|
40766
40725
|
// runId 透传:注入 x-run-id 请求头,供网关用量上报归因(落库 run_id)。
|
|
@@ -40854,6 +40813,85 @@ function safeStringify(value) {
|
|
|
40854
40813
|
}
|
|
40855
40814
|
}
|
|
40856
40815
|
|
|
40816
|
+
// ../linkque-agent-runtime/dist/esm/core/telemetry/publicOutputObservation.js
|
|
40817
|
+
var PublicOutputObservation = class {
|
|
40818
|
+
root;
|
|
40819
|
+
sources = /* @__PURE__ */ new WeakMap();
|
|
40820
|
+
completedSources = /* @__PURE__ */ new WeakMap();
|
|
40821
|
+
source;
|
|
40822
|
+
text = "";
|
|
40823
|
+
bytes = 0;
|
|
40824
|
+
index = 0;
|
|
40825
|
+
truncated = false;
|
|
40826
|
+
firstText = false;
|
|
40827
|
+
startedAt = performance.now();
|
|
40828
|
+
constructor(root) {
|
|
40829
|
+
this.root = root;
|
|
40830
|
+
}
|
|
40831
|
+
associate(event, source) {
|
|
40832
|
+
if (source)
|
|
40833
|
+
this.sources.set(event, source);
|
|
40834
|
+
}
|
|
40835
|
+
/** 来源终态可能早于队列中的正文到达,不能在此提前刷空缓冲。 */
|
|
40836
|
+
completeSource(source, complete) {
|
|
40837
|
+
if (source)
|
|
40838
|
+
this.completedSources.set(source, complete);
|
|
40839
|
+
}
|
|
40840
|
+
accept(event) {
|
|
40841
|
+
if (event.type === "done" || event.type === "error") {
|
|
40842
|
+
const completed = this.source ? this.completedSources.get(this.source) : void 0;
|
|
40843
|
+
this.finish(completed ?? event.type === "done");
|
|
40844
|
+
return;
|
|
40845
|
+
}
|
|
40846
|
+
if (event.type !== "delta" || !event.content)
|
|
40847
|
+
return;
|
|
40848
|
+
if (!this.firstText) {
|
|
40849
|
+
this.firstText = true;
|
|
40850
|
+
this.root.record(ETelemetryEventName.LOOP_FIRST_PUBLIC_TEXT, {
|
|
40851
|
+
[ETelemetryAttribute.LINKQUE_LOOP_FIRST_PUBLIC_TEXT_MS]: performance.now() - this.startedAt
|
|
40852
|
+
});
|
|
40853
|
+
}
|
|
40854
|
+
const source = this.sources.get(event);
|
|
40855
|
+
if (!source)
|
|
40856
|
+
return;
|
|
40857
|
+
if (source !== this.source) {
|
|
40858
|
+
this.finish(true);
|
|
40859
|
+
this.source = source;
|
|
40860
|
+
}
|
|
40861
|
+
if (this.truncated)
|
|
40862
|
+
return;
|
|
40863
|
+
for (const character of event.content) {
|
|
40864
|
+
const size = Buffer.byteLength(character, "utf8");
|
|
40865
|
+
if (this.bytes + size > 512 * 1024) {
|
|
40866
|
+
this.truncated = true;
|
|
40867
|
+
break;
|
|
40868
|
+
}
|
|
40869
|
+
this.bytes += size;
|
|
40870
|
+
this.text += character;
|
|
40871
|
+
if (this.text.length >= 16 * 1024)
|
|
40872
|
+
this.flush(false, false);
|
|
40873
|
+
}
|
|
40874
|
+
}
|
|
40875
|
+
finish(complete) {
|
|
40876
|
+
if (this.bytes)
|
|
40877
|
+
this.flush(true, complete && (this.source ? this.completedSources.get(this.source) ?? true : true));
|
|
40878
|
+
this.source = void 0;
|
|
40879
|
+
this.bytes = 0;
|
|
40880
|
+
this.index = 0;
|
|
40881
|
+
this.truncated = false;
|
|
40882
|
+
}
|
|
40883
|
+
flush(final, complete) {
|
|
40884
|
+
this.source?.record(ETelemetryEventName.CONTENT_RECORDED, {}, {
|
|
40885
|
+
section: ETelemetryContentSection.MODEL_OUTPUT,
|
|
40886
|
+
value: this.text,
|
|
40887
|
+
chunkIndex: this.index++,
|
|
40888
|
+
final,
|
|
40889
|
+
availability: final && complete && !this.truncated ? "available" : "partial"
|
|
40890
|
+
});
|
|
40891
|
+
this.text = "";
|
|
40892
|
+
}
|
|
40893
|
+
};
|
|
40894
|
+
|
|
40857
40895
|
// ../linkque-agent-runtime/dist/esm/core/telemetry/runtimeErrorBoundary.js
|
|
40858
40896
|
var ERROR_FLUSH_TIMEOUT_MS = 200;
|
|
40859
40897
|
async function* withRuntimeErrorBoundary(telemetry, input, run, signal) {
|
|
@@ -40892,6 +40930,96 @@ async function* withRuntimeErrorBoundary(telemetry, input, run, signal) {
|
|
|
40892
40930
|
}
|
|
40893
40931
|
}
|
|
40894
40932
|
|
|
40933
|
+
// ../linkque-agent-runtime/dist/esm/core/agentRuntimePlugin.js
|
|
40934
|
+
var validatePlugins = (plugins) => {
|
|
40935
|
+
const names = /* @__PURE__ */ new Set();
|
|
40936
|
+
for (const plugin of plugins) {
|
|
40937
|
+
const name = plugin.name.trim();
|
|
40938
|
+
if (!name) {
|
|
40939
|
+
throw new Error("Agent runtime \u63D2\u4EF6 name \u4E0D\u80FD\u4E3A\u7A7A");
|
|
40940
|
+
}
|
|
40941
|
+
if (names.has(name)) {
|
|
40942
|
+
throw new Error(`Agent runtime \u63D2\u4EF6 name \u91CD\u590D: ${name}`);
|
|
40943
|
+
}
|
|
40944
|
+
names.add(name);
|
|
40945
|
+
}
|
|
40946
|
+
return plugins;
|
|
40947
|
+
};
|
|
40948
|
+
function assertAgentConfigRoot(value, pluginName) {
|
|
40949
|
+
if (typeof value !== "object" || value === null || !("agent" in value)) {
|
|
40950
|
+
throw new Error(`Agent runtime \u63D2\u4EF6 ${pluginName} \u7684 modifyAgentConfig \u8FD4\u56DE\u4E86\u65E0\u6548\u914D\u7F6E`);
|
|
40951
|
+
}
|
|
40952
|
+
}
|
|
40953
|
+
var applyAgentRuntimePluginConfig = (agentConfig, plugins = []) => {
|
|
40954
|
+
const validatedPlugins = validatePlugins(plugins);
|
|
40955
|
+
const modifiers = validatedPlugins.filter((plugin) => plugin.modifyAgentConfig !== void 0);
|
|
40956
|
+
if (modifiers.length === 0)
|
|
40957
|
+
return agentConfig;
|
|
40958
|
+
let current = structuredClone(agentConfig);
|
|
40959
|
+
for (const plugin of modifiers) {
|
|
40960
|
+
try {
|
|
40961
|
+
const modified = plugin.modifyAgentConfig?.(current);
|
|
40962
|
+
if (modified !== void 0) {
|
|
40963
|
+
assertAgentConfigRoot(modified, plugin.name);
|
|
40964
|
+
current = modified;
|
|
40965
|
+
}
|
|
40966
|
+
current = structuredClone(current);
|
|
40967
|
+
} catch (error) {
|
|
40968
|
+
throw new Error(`Agent runtime \u63D2\u4EF6 ${plugin.name} \u4FEE\u6539 Agent Config \u5931\u8D25`, { cause: error });
|
|
40969
|
+
}
|
|
40970
|
+
}
|
|
40971
|
+
return current;
|
|
40972
|
+
};
|
|
40973
|
+
var MergedHookExecutorHandler = class {
|
|
40974
|
+
executorByName;
|
|
40975
|
+
constructor(executorByName) {
|
|
40976
|
+
this.executorByName = executorByName;
|
|
40977
|
+
}
|
|
40978
|
+
matches(resource, stage, subject) {
|
|
40979
|
+
const executor = this.executorByName.get(resource.config.executorName);
|
|
40980
|
+
return executor?.matches?.(resource, stage, subject) ?? true;
|
|
40981
|
+
}
|
|
40982
|
+
async execute(resource, context, options) {
|
|
40983
|
+
const executor = this.executorByName.get(resource.config.executorName);
|
|
40984
|
+
if (executor)
|
|
40985
|
+
return executor.execute(resource, context, options);
|
|
40986
|
+
return {
|
|
40987
|
+
ok: true,
|
|
40988
|
+
skipped: true,
|
|
40989
|
+
code: "PLUGIN_EXECUTOR_NOT_FOUND",
|
|
40990
|
+
message: `\u672A\u627E\u5230 name=${resource.config.executorName} \u7684 hook executor`
|
|
40991
|
+
};
|
|
40992
|
+
}
|
|
40993
|
+
};
|
|
40994
|
+
var resolveAgentRuntimeHookExecutor = (plugins = [], portHookExecutorList = [], debugLog) => {
|
|
40995
|
+
const entries = validatePlugins(plugins).flatMap((plugin) => (plugin.hookExecutorList ?? []).map((executor, index2) => ({
|
|
40996
|
+
executor,
|
|
40997
|
+
source: `plugin:${plugin.name}[${index2}]`
|
|
40998
|
+
})));
|
|
40999
|
+
entries.push(...portHookExecutorList.map((executor, index2) => ({
|
|
41000
|
+
executor,
|
|
41001
|
+
source: `ports.hookExecutorList[${index2}]`
|
|
41002
|
+
})));
|
|
41003
|
+
if (entries.length === 0)
|
|
41004
|
+
return void 0;
|
|
41005
|
+
const merged = /* @__PURE__ */ new Map();
|
|
41006
|
+
for (const entry of entries) {
|
|
41007
|
+
const name = entry.executor.name;
|
|
41008
|
+
if (!name.trim())
|
|
41009
|
+
throw new Error(`Hook executor name \u4E0D\u80FD\u4E3A\u7A7A: ${entry.source}`);
|
|
41010
|
+
const previous = merged.get(name);
|
|
41011
|
+
if (previous) {
|
|
41012
|
+
try {
|
|
41013
|
+
debugLog?.(`[hook-executor-merge] name=${name} \u51B2\u7A81: ${previous.source} \u88AB ${entry.source} \u8986\u76D6`, EDebugLogScope.HOOK);
|
|
41014
|
+
} catch {
|
|
41015
|
+
}
|
|
41016
|
+
}
|
|
41017
|
+
merged.set(name, entry);
|
|
41018
|
+
}
|
|
41019
|
+
const executorByName = new Map([...merged].map(([name, entry]) => [name, entry.executor]));
|
|
41020
|
+
return new MergedHookExecutorHandler(executorByName);
|
|
41021
|
+
};
|
|
41022
|
+
|
|
40895
41023
|
// ../linkque-agent-runtime/dist/esm/core/cardSourceResult.js
|
|
40896
41024
|
import { randomUUID as randomUUID3 } from "node:crypto";
|
|
40897
41025
|
var MAX_RECEIPT_BYTES = 1e5;
|
|
@@ -41339,6 +41467,7 @@ var CardRenderMcpServer = class {
|
|
|
41339
41467
|
toolByName = /* @__PURE__ */ new Map();
|
|
41340
41468
|
sourceResultByRef = /* @__PURE__ */ new Map();
|
|
41341
41469
|
activeCardId;
|
|
41470
|
+
deliveries = /* @__PURE__ */ new WeakMap();
|
|
41342
41471
|
closed = false;
|
|
41343
41472
|
invalidCards = [];
|
|
41344
41473
|
/** 只信任本实例实际执行成功的结果,普通 MCP JSON 无权控制文字输出。 */
|
|
@@ -41375,7 +41504,11 @@ var CardRenderMcpServer = class {
|
|
|
41375
41504
|
});
|
|
41376
41505
|
continue;
|
|
41377
41506
|
}
|
|
41378
|
-
const state2 = {
|
|
41507
|
+
const state2 = {
|
|
41508
|
+
selected: false,
|
|
41509
|
+
results: /* @__PURE__ */ new Map(),
|
|
41510
|
+
executionId: void 0
|
|
41511
|
+
};
|
|
41379
41512
|
this.states.set(resource.resourceId, state2);
|
|
41380
41513
|
const finishName = createCardFinishToolName(resource.resourceId);
|
|
41381
41514
|
const readName = createCardSourceReadToolName(resource.resourceId);
|
|
@@ -41391,7 +41524,9 @@ var CardRenderMcpServer = class {
|
|
|
41391
41524
|
properties: {},
|
|
41392
41525
|
additionalProperties: false
|
|
41393
41526
|
},
|
|
41394
|
-
execute: async () => {
|
|
41527
|
+
execute: async (_args, _signal, context) => {
|
|
41528
|
+
state2.executionId = context?.toolCallId;
|
|
41529
|
+
this.observeCard(context, resource, config, "prepare", state2.executionId);
|
|
41395
41530
|
for (const candidate of this.states.values())
|
|
41396
41531
|
candidate.selected = false;
|
|
41397
41532
|
this.activeCardId = resource.resourceId;
|
|
@@ -41429,6 +41564,8 @@ var CardRenderMcpServer = class {
|
|
|
41429
41564
|
inputSchema: normalizeMcpInputSchema(discoveredHandle?.inputSchema),
|
|
41430
41565
|
outputSchema: CARD_SOURCE_RECEIPT_SCHEMA,
|
|
41431
41566
|
execute: async (args, signal, context) => {
|
|
41567
|
+
const executionId = state2.executionId;
|
|
41568
|
+
this.observeCard(context, resource, config, "source", executionId, source.sourceId);
|
|
41432
41569
|
if (!state2.selected || this.activeCardId !== resource.resourceId)
|
|
41433
41570
|
throw new Error(`\u8C03\u7528\u6570\u636E\u6E90\u524D\uFF0C\u8BF7\u5148\u9009\u62E9\u5361\u7247 ${name}`);
|
|
41434
41571
|
const missingDependencies = (source.dependsOn ?? []).filter((dependency) => !state2.results.has(dependency));
|
|
@@ -41472,7 +41609,10 @@ var CardRenderMcpServer = class {
|
|
|
41472
41609
|
signal?.throwIfAborted();
|
|
41473
41610
|
if (this.closed)
|
|
41474
41611
|
throw new Error("\u5361\u7247\u8FD0\u884C\u5DF2\u7ED3\u675F");
|
|
41475
|
-
this.sourceResultByRef.set(cacheEntry.resultRef,
|
|
41612
|
+
this.sourceResultByRef.set(cacheEntry.resultRef, {
|
|
41613
|
+
...cacheEntry,
|
|
41614
|
+
executionId
|
|
41615
|
+
});
|
|
41476
41616
|
this.logMetric(() => `source=${source.sourceId} mcpMs=${projectionStartedAt - mcpStartedAt} projectionMs=${Date.now() - projectionStartedAt} rawBytes=${byteLength(structured)} receiptBytes=${byteLength(receipt)}`);
|
|
41477
41617
|
return receipt;
|
|
41478
41618
|
}
|
|
@@ -41486,17 +41626,18 @@ var CardRenderMcpServer = class {
|
|
|
41486
41626
|
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",
|
|
41487
41627
|
inputSchema: CARD_SOURCE_READ_INPUT_SCHEMA,
|
|
41488
41628
|
outputSchema: CARD_SOURCE_READ_OUTPUT_SCHEMA,
|
|
41489
|
-
execute: async (args) => {
|
|
41629
|
+
execute: async (args, _signal, context) => {
|
|
41490
41630
|
const resultRef = readResultRef(args);
|
|
41631
|
+
const entry = this.sourceResultByRef.get(resultRef);
|
|
41632
|
+
const matchingEntry = entry?.cardId === resource.resourceId ? entry : void 0;
|
|
41633
|
+
this.observeCard(context, resource, config, "read", matchingEntry?.executionId);
|
|
41491
41634
|
if (this.closed)
|
|
41492
41635
|
throw new Error(`\u7F13\u5B58\u5DF2\u5931\u6548: ${resultRef}`);
|
|
41493
|
-
|
|
41494
|
-
if (!entry || entry.cardId !== resource.resourceId) {
|
|
41636
|
+
if (!matchingEntry)
|
|
41495
41637
|
throw new Error(`\u672A\u77E5\u7ED3\u679C\u5F15\u7528: ${resultRef}`);
|
|
41496
|
-
}
|
|
41497
41638
|
const startedAt = Date.now();
|
|
41498
|
-
const receipt = readCardSourceResult(
|
|
41499
|
-
this.logMetric(() => `source=${
|
|
41639
|
+
const receipt = readCardSourceResult(matchingEntry, args);
|
|
41640
|
+
this.logMetric(() => `source=${matchingEntry.sourceId} cacheReadMs=${Date.now() - startedAt} receiptBytes=${byteLength(receipt)}`);
|
|
41500
41641
|
return receipt;
|
|
41501
41642
|
}
|
|
41502
41643
|
});
|
|
@@ -41524,12 +41665,15 @@ ${AFTER_CARD_DESCRIPTION}`,
|
|
|
41524
41665
|
},
|
|
41525
41666
|
additionalProperties: false
|
|
41526
41667
|
},
|
|
41527
|
-
execute: async (args, signal) => {
|
|
41668
|
+
execute: async (args, signal, context) => {
|
|
41669
|
+
this.observeCard(context, resource, config, "finish", state2.executionId);
|
|
41528
41670
|
if (!state2.selected || this.activeCardId !== resource.resourceId)
|
|
41529
41671
|
throw new Error(`\u5B8C\u6210\u5C55\u793A\u524D\uFF0C\u8BF7\u5148\u9009\u62E9\u5361\u7247 ${name}`);
|
|
41530
41672
|
const afterCard = readAfterCard(args);
|
|
41531
41673
|
const finishStartedAt = Date.now();
|
|
41532
41674
|
const result = await executeCardPresentationFromSources(resource, this.runtimeContext, state2.results, signal);
|
|
41675
|
+
if (context?.observation)
|
|
41676
|
+
this.deliveries.set(result.card, context.observation);
|
|
41533
41677
|
if (afterCard !== void 0) {
|
|
41534
41678
|
this.companions.set(result, afterCard);
|
|
41535
41679
|
result.modelText += `
|
|
@@ -41561,7 +41705,11 @@ ${AFTER_CARD_DESCRIPTION}`,
|
|
|
41561
41705
|
throw new Error(`\u672A\u77E5\u5361\u7247\u5DE5\u5177: ${name}`);
|
|
41562
41706
|
return descriptor.execute(args, signal, options?.context);
|
|
41563
41707
|
}
|
|
41564
|
-
|
|
41708
|
+
this.observeCard(options?.context, resource, config, "finish", options?.context?.toolCallId);
|
|
41709
|
+
const result = await executeCardPresentation(resource, this.registry, this.runtimeContext, args, signal, options?.context);
|
|
41710
|
+
if (options?.context?.observation)
|
|
41711
|
+
this.deliveries.set(result.card, options.context.observation);
|
|
41712
|
+
return result;
|
|
41565
41713
|
}
|
|
41566
41714
|
async close() {
|
|
41567
41715
|
this.closed = true;
|
|
@@ -41571,6 +41719,17 @@ ${AFTER_CARD_DESCRIPTION}`,
|
|
|
41571
41719
|
this.toolByName.clear();
|
|
41572
41720
|
this.companions = /* @__PURE__ */ new WeakMap();
|
|
41573
41721
|
}
|
|
41722
|
+
/** 记录执行时配置和显式关联,不从工具名称反推业务身份。 */
|
|
41723
|
+
observeCard(context, resource, config, phase, executionId, sourceId) {
|
|
41724
|
+
context?.observation?.record(ETelemetryEventName.TOOL_CONTEXT, {
|
|
41725
|
+
[ETelemetryAttribute.LINKQUE_CARD_REF]: resource.resourceId,
|
|
41726
|
+
[ETelemetryAttribute.LINKQUE_CARD_REVISION]: config.revision,
|
|
41727
|
+
[ETelemetryAttribute.LINKQUE_CARD_DISPLAY_NAME]: config.displayName,
|
|
41728
|
+
[ETelemetryAttribute.LINKQUE_CARD_PHASE]: phase,
|
|
41729
|
+
...executionId ? { [ETelemetryAttribute.LINKQUE_CARD_EXECUTION_ID]: executionId } : {},
|
|
41730
|
+
...sourceId ? { [ETelemetryAttribute.LINKQUE_CARD_SOURCE_ID]: sourceId } : {}
|
|
41731
|
+
});
|
|
41732
|
+
}
|
|
41574
41733
|
logMetric(message) {
|
|
41575
41734
|
try {
|
|
41576
41735
|
if (!this.debugLog)
|
|
@@ -41580,7 +41739,7 @@ ${AFTER_CARD_DESCRIPTION}`,
|
|
|
41580
41739
|
}
|
|
41581
41740
|
}
|
|
41582
41741
|
/** 卡片与伴随文字的共享输出边界,不参与模型循环或工具调度。 */
|
|
41583
|
-
async *projectConversation(events) {
|
|
41742
|
+
async *projectConversation(events, publicOutput) {
|
|
41584
41743
|
const pending = /* @__PURE__ */ new WeakMap();
|
|
41585
41744
|
let cardOwnsText = false;
|
|
41586
41745
|
for await (const event of events) {
|
|
@@ -41597,13 +41756,24 @@ ${AFTER_CARD_DESCRIPTION}`,
|
|
|
41597
41756
|
if (event.type === "a2ui_card" && pending.has(event)) {
|
|
41598
41757
|
this.logMetric(`phase=card-event-emitted atMs=${Date.now()}`);
|
|
41599
41758
|
}
|
|
41759
|
+
if (event.type === "a2ui_card") {
|
|
41760
|
+
this.deliveries.get(event)?.record(ETelemetryEventName.TOOL_CONTEXT, {
|
|
41761
|
+
[ETelemetryAttribute.LINKQUE_CARD_DELIVERY]: "emitted"
|
|
41762
|
+
});
|
|
41763
|
+
}
|
|
41600
41764
|
yield event;
|
|
41601
41765
|
if (event.type === "a2ui_card" && pending.has(event)) {
|
|
41602
41766
|
const text2 = pending.get(event);
|
|
41603
41767
|
pending.delete(event);
|
|
41604
41768
|
cardOwnsText = true;
|
|
41605
|
-
if (text2)
|
|
41606
|
-
|
|
41769
|
+
if (text2) {
|
|
41770
|
+
const companion = { type: "delta", content: text2 };
|
|
41771
|
+
const source = this.deliveries.get(event);
|
|
41772
|
+
publicOutput?.associate(companion, source);
|
|
41773
|
+
publicOutput?.completeSource(source, true);
|
|
41774
|
+
yield companion;
|
|
41775
|
+
}
|
|
41776
|
+
this.deliveries.delete(event);
|
|
41607
41777
|
}
|
|
41608
41778
|
}
|
|
41609
41779
|
}
|
|
@@ -41746,96 +41916,6 @@ var NoopKnowledgeSearchPort = class {
|
|
|
41746
41916
|
}
|
|
41747
41917
|
};
|
|
41748
41918
|
|
|
41749
|
-
// ../linkque-agent-runtime/dist/esm/core/agentRuntimePlugin.js
|
|
41750
|
-
var validatePlugins = (plugins) => {
|
|
41751
|
-
const names = /* @__PURE__ */ new Set();
|
|
41752
|
-
for (const plugin of plugins) {
|
|
41753
|
-
const name = plugin.name.trim();
|
|
41754
|
-
if (!name) {
|
|
41755
|
-
throw new Error("Agent runtime \u63D2\u4EF6 name \u4E0D\u80FD\u4E3A\u7A7A");
|
|
41756
|
-
}
|
|
41757
|
-
if (names.has(name)) {
|
|
41758
|
-
throw new Error(`Agent runtime \u63D2\u4EF6 name \u91CD\u590D: ${name}`);
|
|
41759
|
-
}
|
|
41760
|
-
names.add(name);
|
|
41761
|
-
}
|
|
41762
|
-
return plugins;
|
|
41763
|
-
};
|
|
41764
|
-
function assertAgentConfigRoot(value, pluginName) {
|
|
41765
|
-
if (typeof value !== "object" || value === null || !("agent" in value)) {
|
|
41766
|
-
throw new Error(`Agent runtime \u63D2\u4EF6 ${pluginName} \u7684 modifyAgentConfig \u8FD4\u56DE\u4E86\u65E0\u6548\u914D\u7F6E`);
|
|
41767
|
-
}
|
|
41768
|
-
}
|
|
41769
|
-
var applyAgentRuntimePluginConfig = (agentConfig, plugins = []) => {
|
|
41770
|
-
const validatedPlugins = validatePlugins(plugins);
|
|
41771
|
-
const modifiers = validatedPlugins.filter((plugin) => plugin.modifyAgentConfig !== void 0);
|
|
41772
|
-
if (modifiers.length === 0)
|
|
41773
|
-
return agentConfig;
|
|
41774
|
-
let current = structuredClone(agentConfig);
|
|
41775
|
-
for (const plugin of modifiers) {
|
|
41776
|
-
try {
|
|
41777
|
-
const modified = plugin.modifyAgentConfig?.(current);
|
|
41778
|
-
if (modified !== void 0) {
|
|
41779
|
-
assertAgentConfigRoot(modified, plugin.name);
|
|
41780
|
-
current = modified;
|
|
41781
|
-
}
|
|
41782
|
-
current = structuredClone(current);
|
|
41783
|
-
} catch (error) {
|
|
41784
|
-
throw new Error(`Agent runtime \u63D2\u4EF6 ${plugin.name} \u4FEE\u6539 Agent Config \u5931\u8D25`, { cause: error });
|
|
41785
|
-
}
|
|
41786
|
-
}
|
|
41787
|
-
return current;
|
|
41788
|
-
};
|
|
41789
|
-
var MergedHookExecutorHandler = class {
|
|
41790
|
-
executorByName;
|
|
41791
|
-
constructor(executorByName) {
|
|
41792
|
-
this.executorByName = executorByName;
|
|
41793
|
-
}
|
|
41794
|
-
matches(resource, stage, subject) {
|
|
41795
|
-
const executor = this.executorByName.get(resource.config.executorName);
|
|
41796
|
-
return executor?.matches?.(resource, stage, subject) ?? true;
|
|
41797
|
-
}
|
|
41798
|
-
async execute(resource, context, options) {
|
|
41799
|
-
const executor = this.executorByName.get(resource.config.executorName);
|
|
41800
|
-
if (executor)
|
|
41801
|
-
return executor.execute(resource, context, options);
|
|
41802
|
-
return {
|
|
41803
|
-
ok: true,
|
|
41804
|
-
skipped: true,
|
|
41805
|
-
code: "PLUGIN_EXECUTOR_NOT_FOUND",
|
|
41806
|
-
message: `\u672A\u627E\u5230 name=${resource.config.executorName} \u7684 hook executor`
|
|
41807
|
-
};
|
|
41808
|
-
}
|
|
41809
|
-
};
|
|
41810
|
-
var resolveAgentRuntimeHookExecutor = (plugins = [], portHookExecutorList = [], debugLog) => {
|
|
41811
|
-
const entries = validatePlugins(plugins).flatMap((plugin) => (plugin.hookExecutorList ?? []).map((executor, index2) => ({
|
|
41812
|
-
executor,
|
|
41813
|
-
source: `plugin:${plugin.name}[${index2}]`
|
|
41814
|
-
})));
|
|
41815
|
-
entries.push(...portHookExecutorList.map((executor, index2) => ({
|
|
41816
|
-
executor,
|
|
41817
|
-
source: `ports.hookExecutorList[${index2}]`
|
|
41818
|
-
})));
|
|
41819
|
-
if (entries.length === 0)
|
|
41820
|
-
return void 0;
|
|
41821
|
-
const merged = /* @__PURE__ */ new Map();
|
|
41822
|
-
for (const entry of entries) {
|
|
41823
|
-
const name = entry.executor.name;
|
|
41824
|
-
if (!name.trim())
|
|
41825
|
-
throw new Error(`Hook executor name \u4E0D\u80FD\u4E3A\u7A7A: ${entry.source}`);
|
|
41826
|
-
const previous = merged.get(name);
|
|
41827
|
-
if (previous) {
|
|
41828
|
-
try {
|
|
41829
|
-
debugLog?.(`[hook-executor-merge] name=${name} \u51B2\u7A81: ${previous.source} \u88AB ${entry.source} \u8986\u76D6`, EDebugLogScope.HOOK);
|
|
41830
|
-
} catch {
|
|
41831
|
-
}
|
|
41832
|
-
}
|
|
41833
|
-
merged.set(name, entry);
|
|
41834
|
-
}
|
|
41835
|
-
const executorByName = new Map([...merged].map(([name, entry]) => [name, entry.executor]));
|
|
41836
|
-
return new MergedHookExecutorHandler(executorByName);
|
|
41837
|
-
};
|
|
41838
|
-
|
|
41839
41919
|
// ../linkque-agent-runtime/dist/esm/core/agentRuntime.js
|
|
41840
41920
|
var DEFAULT_HARNESS_PROMPT = `# Harness \u8FD0\u884C\u89C4\u7EA6
|
|
41841
41921
|
|
|
@@ -42302,8 +42382,11 @@ var AgentRuntime = class _AgentRuntime {
|
|
|
42302
42382
|
...assistantText !== "" && { messageContent: assistantText }
|
|
42303
42383
|
});
|
|
42304
42384
|
};
|
|
42385
|
+
const publicOutput = new PublicOutputObservation(observation);
|
|
42386
|
+
agentReq.publicOutput = publicOutput;
|
|
42305
42387
|
try {
|
|
42306
|
-
for await (const ev of cardServer.projectConversation(this.agentLoop.run(agentReq))) {
|
|
42388
|
+
for await (const ev of cardServer.projectConversation(this.agentLoop.run(agentReq), publicOutput)) {
|
|
42389
|
+
publicOutput.accept(ev);
|
|
42307
42390
|
if (ev.type === "delta")
|
|
42308
42391
|
assistantText += ev.content;
|
|
42309
42392
|
if (ev.type === "tool_end" && !ev.isError) {
|
|
@@ -42365,6 +42448,7 @@ var AgentRuntime = class _AgentRuntime {
|
|
|
42365
42448
|
await dispatchTerminalHook();
|
|
42366
42449
|
yield ev;
|
|
42367
42450
|
}
|
|
42451
|
+
publicOutput.finish(true);
|
|
42368
42452
|
await dispatchTerminalHook();
|
|
42369
42453
|
} catch (error) {
|
|
42370
42454
|
if (!terminalHookDispatched) {
|
|
@@ -42375,6 +42459,8 @@ var AgentRuntime = class _AgentRuntime {
|
|
|
42375
42459
|
await dispatchTerminalHook();
|
|
42376
42460
|
}
|
|
42377
42461
|
throw error;
|
|
42462
|
+
} finally {
|
|
42463
|
+
publicOutput.finish(false);
|
|
42378
42464
|
}
|
|
42379
42465
|
}
|
|
42380
42466
|
};
|
package/vendor/linkque-agent-appwrite-integrate/dist/esm/runtime/handler/clientCapability.js
CHANGED
|
@@ -3,11 +3,11 @@ import {
|
|
|
3
3
|
runClientCapability,
|
|
4
4
|
runClientCapabilityCleanup,
|
|
5
5
|
runClientCapabilityResult
|
|
6
|
-
} from "../../chunk-
|
|
6
|
+
} from "../../chunk-STGFILDE.js";
|
|
7
7
|
import "../../chunk-IWOFD643.js";
|
|
8
8
|
import "../../chunk-PXCGFBV5.js";
|
|
9
9
|
import "../../chunk-ETG6PNHQ.js";
|
|
10
|
-
import "../../chunk-
|
|
10
|
+
import "../../chunk-PM2UO433.js";
|
|
11
11
|
import "../../chunk-EAODRPW4.js";
|
|
12
12
|
import "../../chunk-XUFLSZM4.js";
|
|
13
13
|
import "../../chunk-GAYNLDWK.js";
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import {
|
|
2
2
|
getBakedProtocol,
|
|
3
3
|
setBakedProtocol
|
|
4
|
-
} from "../chunk-
|
|
5
|
-
import "../chunk-
|
|
4
|
+
} from "../chunk-JD3IL3IC.js";
|
|
5
|
+
import "../chunk-PM2UO433.js";
|
|
6
6
|
import "../chunk-EAODRPW4.js";
|
|
7
7
|
import "../chunk-XUFLSZM4.js";
|
|
8
8
|
import "../chunk-GAYNLDWK.js";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"name":"@alipay/linkque-agent-appwrite-integrate","version":"1.4.
|
|
1
|
+
{"name":"@alipay/linkque-agent-appwrite-integrate","version":"1.4.6","type":"module"}
|