coremind-runtime 0.7.0 → 0.8.0
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/README.md +3 -3
- package/dist/active-run-binding.d.ts.map +1 -1
- package/dist/active-run-binding.js +4 -0
- package/dist/active-run-binding.js.map +1 -1
- package/dist/agent-factory.d.ts.map +1 -1
- package/dist/agent-factory.js +24 -3
- package/dist/agent-factory.js.map +1 -1
- package/dist/budget.d.ts +3 -0
- package/dist/budget.d.ts.map +1 -1
- package/dist/budget.js +11 -0
- package/dist/budget.js.map +1 -1
- package/dist/chat-session.d.ts.map +1 -1
- package/dist/chat-session.js +3 -0
- package/dist/chat-session.js.map +1 -1
- package/dist/checkpoint.d.ts +1 -0
- package/dist/checkpoint.d.ts.map +1 -1
- package/dist/checkpoint.js +14 -0
- package/dist/checkpoint.js.map +1 -1
- package/dist/control-inbox.d.ts +14 -0
- package/dist/control-inbox.d.ts.map +1 -1
- package/dist/control-inbox.js +27 -3
- package/dist/control-inbox.js.map +1 -1
- package/dist/execution-security.d.ts.map +1 -1
- package/dist/execution-security.js +5 -0
- package/dist/execution-security.js.map +1 -1
- package/dist/host-verification.d.ts +45 -0
- package/dist/host-verification.d.ts.map +1 -0
- package/dist/host-verification.js +150 -0
- package/dist/host-verification.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/internal.d.ts +1 -0
- package/dist/internal.d.ts.map +1 -1
- package/dist/internal.js +1 -0
- package/dist/internal.js.map +1 -1
- package/dist/loop-runner.d.ts +9 -0
- package/dist/loop-runner.d.ts.map +1 -1
- package/dist/loop-runner.js +27 -0
- package/dist/loop-runner.js.map +1 -1
- package/dist/projection.js +11 -2
- package/dist/projection.js.map +1 -1
- package/dist/run-state.d.ts +7 -2
- package/dist/run-state.d.ts.map +1 -1
- package/dist/run-state.js +106 -8
- package/dist/run-state.js.map +1 -1
- package/dist/runtime.d.ts +13 -0
- package/dist/runtime.d.ts.map +1 -1
- package/dist/runtime.js +154 -7
- package/dist/runtime.js.map +1 -1
- package/dist/session.js +6 -1
- package/dist/session.js.map +1 -1
- package/dist/tool-policy.d.ts.map +1 -1
- package/dist/tool-policy.js +7 -0
- package/dist/tool-policy.js.map +1 -1
- package/package.json +5 -5
package/dist/runtime.d.ts
CHANGED
|
@@ -5,6 +5,7 @@ import { type ChildRunContinuationGate, ChildRunCoordinator, type ChildRunCoordi
|
|
|
5
5
|
import { type CoreMindChildRunAdapter } from "./child-runtime-adapter.js";
|
|
6
6
|
import { type ControlApplyResult, type ControlReceipt, type RunControlCommand } from "./control-inbox.js";
|
|
7
7
|
import { type CoreMindEvent } from "./events.js";
|
|
8
|
+
import { type HostVerificationRequest } from "./host-verification.js";
|
|
8
9
|
import { type LifecycleExtensionPolicy, type LifecycleExtensionReceipt } from "./lifecycle-extension.js";
|
|
9
10
|
import { type LocalObservabilityProjection, type TelemetryConsentFact, type TelemetryEgressControllerOptions } from "./observability.js";
|
|
10
11
|
import { type DurableOperationSnapshot } from "./operation-state.js";
|
|
@@ -19,6 +20,8 @@ import { type RunSnapshot } from "./snapshot.js";
|
|
|
19
20
|
import { type ApprovalDecision, type ToolApprovalRequest } from "./tool-policy.js";
|
|
20
21
|
import { type CoreMindTraceEvent } from "./trace.js";
|
|
21
22
|
export interface CoreMindRuntimeOptions {
|
|
23
|
+
/** 宿主模式的持久验证请求通知;通过 acceptControl 回复,返回值不代表通过。 */
|
|
24
|
+
onVerification?: (request: HostVerificationRequest) => void;
|
|
22
25
|
/** 已校验的配置 */
|
|
23
26
|
config: CoreMindConfig;
|
|
24
27
|
/** 配置文件所在目录(脚本工具相对路径、会话目录基准) */
|
|
@@ -84,6 +87,14 @@ export interface ProtocolStartIdentity {
|
|
|
84
87
|
definitionFingerprint: string;
|
|
85
88
|
}>;
|
|
86
89
|
}
|
|
90
|
+
export interface ProtocolToolResultFact {
|
|
91
|
+
schemaVersion: 1;
|
|
92
|
+
resultId: string;
|
|
93
|
+
runId: string;
|
|
94
|
+
callId: string;
|
|
95
|
+
registrationId: string;
|
|
96
|
+
requestFingerprint: string;
|
|
97
|
+
}
|
|
87
98
|
export interface RunResult {
|
|
88
99
|
runId: string;
|
|
89
100
|
/** 通用 durable operation 的权威外围状态;Workflow/Loop 细节仍由各自快照负责。 */
|
|
@@ -216,6 +227,8 @@ export declare class CoreMindRuntime {
|
|
|
216
227
|
/** 会话配置开启时,把主 agent 本轮新增消息追加落盘(返回会话文件路径) */
|
|
217
228
|
persistSession(): Promise<string | undefined>;
|
|
218
229
|
}
|
|
230
|
+
/** 仅供同仓库 ProtocolHost:结果已写入 Runtime 的同一 journal 后才确认 accepted。 */
|
|
231
|
+
export declare function prepareProtocolToolResultFact(runtime: CoreMindRuntime, fact: ProtocolToolResultFact): Promise<void>;
|
|
219
232
|
/** 便捷入口:加载配置 → 构建运行时 */
|
|
220
233
|
export declare function buildAgentFromConfig(options: CoreMindRuntimeOptions): Promise<CoreMindRuntime>;
|
|
221
234
|
/** Provider 仍使用完整认证环境;Child 工具只取得平台运行必需变量。 */
|
package/dist/runtime.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runtime.d.ts","sourceRoot":"","sources":["../src/runtime.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAEV,cAAc,EAGf,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EACL,KAAK,cAAc,EAQpB,MAAM,gBAAgB,CAAC;AAsBxB,OAAO,EACL,KAAK,cAAc,EAEnB,KAAK,gBAAgB,EAGtB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAGL,KAAK,wBAAwB,EAC7B,mBAAmB,EACnB,KAAK,0BAA0B,EAC/B,KAAK,yBAAyB,EAC9B,KAAK,sBAAsB,EAC3B,KAAK,cAAc,EAKpB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EACL,KAAK,uBAAuB,EAG7B,MAAM,4BAA4B,CAAC;AAkB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,oDAAoD;YACtC,kCAAkC;IA4EhD,oCAAoC;IACpC,OAAO,CAAC,+BAA+B;IAcvC,iDAAiD;IACjD,OAAO,CAAC,0BAA0B;IAqClC,iCAAiC;YACnB,cAAc;YAk6Dd,YAAY;YAkDZ,eAAe;IAkE7B,OAAO,CAAC,QAAQ;YAOF,eAAe;IA4C7B,OAAO,CAAC,eAAe;IAIvB;;;;;OAKG;IACG,iBAAiB,CAAC,SAAS,GAAE,MAAsC,GAAG,OAAO,CAAC,OAAO,CAAC;IAa5F,4CAA4C;IACtC,cAAc,IAAI,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC;CA+BpD;AAoBD,kEAAkE;AAClE,wBAAgB,6BAA6B,CAC3C,OAAO,EAAE,eAAe,EACxB,IAAI,EAAE,sBAAsB,GAC3B,OAAO,CAAC,IAAI,CAAC,CAkCf;AA+BD,wBAAwB;AACxB,wBAAsB,oBAAoB,CACxC,OAAO,EAAE,sBAAsB,GAC9B,OAAO,CAAC,eAAe,CAAC,CAE1B;AAqCD,8CAA8C;AAC9C,wBAAgB,wBAAwB,CAAC,GAAG,EAAE,MAAM,CAAC,UAAU,GAAG,MAAM,CAAC,UAAU,CAIlF;AAYD,8CAA8C;AAC9C,wBAAsB,wCAAwC,CAC5D,SAAS,EACL,IAAI,CAAC,mBAAmB,EAAE,4BAA4B,GAAG,kBAAkB,CAAC,GAC5E,SAAS,EACb,aAAa,EAAE,OAAO,GACrB,OAAO,CAAC,wBAAwB,GAAG,SAAS,CAAC,CAc/C"}
|
package/dist/runtime.js
CHANGED
|
@@ -21,6 +21,7 @@ import { CoreMindError, isErrorCode } from "./errors.js";
|
|
|
21
21
|
import { extractAgentError, extractText } from "./events.js";
|
|
22
22
|
import { normalizeExecutionError } from "./execution-error.js";
|
|
23
23
|
import { enforceExecutionSecurity } from "./execution-security.js";
|
|
24
|
+
import { HostVerificationGate } from "./host-verification.js";
|
|
24
25
|
import { receiptId } from "./ids.js";
|
|
25
26
|
import { claimInput, completeInput, createInputReceipt, discardInput, inputFingerprint, newInputId, receiptStatusOf, } from "./input-receipt.js";
|
|
26
27
|
import { LifecycleExtensionHost, } from "./lifecycle-extension.js";
|
|
@@ -306,7 +307,7 @@ export class CoreMindRuntime {
|
|
|
306
307
|
? configuredOptions
|
|
307
308
|
: {
|
|
308
309
|
...configuredOptions,
|
|
309
|
-
maxTokens: Math.min(configuredOptions?.maxTokens ??
|
|
310
|
+
maxTokens: Math.min(configuredOptions?.maxTokens ?? model.maxTokens, tokenLimit),
|
|
310
311
|
};
|
|
311
312
|
return {
|
|
312
313
|
providerId: model.provider,
|
|
@@ -347,6 +348,12 @@ export class CoreMindRuntime {
|
|
|
347
348
|
* 因此 chat/TUI 与无头 run 共用预算、权限、checkpoint、Trace 和失败语义。
|
|
348
349
|
*/
|
|
349
350
|
async runAgentTurn(agentName, message, history, events, signal) {
|
|
351
|
+
if (this.config.loop?.verify.mode === "host") {
|
|
352
|
+
throw new CoreMindError("loop_config_invalid", "宿主验收模式须通过 run() 与绑定该 Run 的控制接口执行");
|
|
353
|
+
}
|
|
354
|
+
if (executionSlotFor(this).running) {
|
|
355
|
+
throw new CoreMindError("concurrent_run", "同一 Runtime 不支持并发 run() 与交互 Turn");
|
|
356
|
+
}
|
|
350
357
|
if (!this.agentConfigs.has(agentName)) {
|
|
351
358
|
throw new CoreMindError("unknown_agent", `配置中没有可用的 agent:${agentName}`);
|
|
352
359
|
}
|
|
@@ -391,8 +398,22 @@ export class CoreMindRuntime {
|
|
|
391
398
|
/** 执行:有 workflow 走编排,否则单 agent 直答。返回结果含质量摘要 */
|
|
392
399
|
async run() {
|
|
393
400
|
const slot = executionSlotFor(this);
|
|
401
|
+
if (slot.running || boundDelegationExecutor(this)) {
|
|
402
|
+
throw new CoreMindError("concurrent_run", "同一 Runtime 不支持并发执行");
|
|
403
|
+
}
|
|
404
|
+
slot.running = true;
|
|
394
405
|
slot.kernel ??= new RunKernel({ execute: (context) => this.executeRunBody(context) });
|
|
395
|
-
|
|
406
|
+
try {
|
|
407
|
+
return await slot.kernel.run();
|
|
408
|
+
}
|
|
409
|
+
finally {
|
|
410
|
+
try {
|
|
411
|
+
await settleProtocolToolResultFacts(this);
|
|
412
|
+
}
|
|
413
|
+
finally {
|
|
414
|
+
slot.running = false;
|
|
415
|
+
}
|
|
416
|
+
}
|
|
396
417
|
}
|
|
397
418
|
/** 在活动父 Run 上创建类型化 Child Run;未配置或尚未启动时失败关闭。 */
|
|
398
419
|
async delegateChildRun(request) {
|
|
@@ -449,6 +470,9 @@ export class CoreMindRuntime {
|
|
|
449
470
|
}
|
|
450
471
|
/** 接收已类型化控制;ACK 只由当前 Run 的持久 ControlInbox 产生。 */
|
|
451
472
|
async acceptControl(command) {
|
|
473
|
+
if (command.type === "verification" && !this.currentControlInbox()) {
|
|
474
|
+
throw new CoreMindError("control_unavailable", "当前没有可接收宿主验收回复的 Run");
|
|
475
|
+
}
|
|
452
476
|
for (let attempt = 0; attempt < 5_000; attempt++) {
|
|
453
477
|
const inbox = this.currentControlInbox();
|
|
454
478
|
if (inbox)
|
|
@@ -860,18 +884,61 @@ export class CoreMindRuntime {
|
|
|
860
884
|
throw new CoreMindError("operation_not_resumable", `操作 ${operation.snapshot().operationId} 处于 ${operation.snapshot().state},不能继续执行`);
|
|
861
885
|
}
|
|
862
886
|
await journal.flush();
|
|
887
|
+
const hostVerification = this.config.loop?.verify.mode === "host"
|
|
888
|
+
? new HostVerificationGate({
|
|
889
|
+
runId,
|
|
890
|
+
journal,
|
|
891
|
+
records: await runStore.read(runId),
|
|
892
|
+
timeoutMs: this.config.loop.verify.timeoutMs ?? 60_000,
|
|
893
|
+
notify: this.options.onVerification,
|
|
894
|
+
applyPending: () => context.currentControlInbox().applyPending("verification"),
|
|
895
|
+
})
|
|
896
|
+
: undefined;
|
|
863
897
|
context.attachControlInbox(new ControlInbox({
|
|
864
898
|
runId,
|
|
865
899
|
journal,
|
|
866
900
|
records: await runStore.read(runId),
|
|
867
|
-
apply: (command) =>
|
|
901
|
+
apply: (command) => {
|
|
902
|
+
if (command.type === "verification") {
|
|
903
|
+
return Promise.resolve(hostVerification?.apply(command) ?? {
|
|
904
|
+
status: "rejected",
|
|
905
|
+
reason: "当前 Run 未启用宿主验证",
|
|
906
|
+
});
|
|
907
|
+
}
|
|
908
|
+
if (hostVerification?.waiting &&
|
|
909
|
+
(command.type === "steering" || command.type === "follow_up")) {
|
|
910
|
+
return Promise.resolve({ status: "rejected", reason: "宿主验收期间不能改变候选输入" });
|
|
911
|
+
}
|
|
912
|
+
return this.applyRunControl(command, context, deferredTerminalError);
|
|
913
|
+
},
|
|
868
914
|
}));
|
|
869
915
|
const capabilityByCallId = new Map();
|
|
870
916
|
const trace = new TraceRecorder(runId, (entry) => {
|
|
871
|
-
|
|
917
|
+
const toolResultCallId = entry.event.type === "tool_result" ? entry.event.callId : undefined;
|
|
918
|
+
const pendingProtocolToolResult = toolResultCallId
|
|
919
|
+
? executionSlotFor(this).protocolToolResultFacts?.get(protocolToolResultKey(entry.runId, toolResultCallId))
|
|
920
|
+
: undefined;
|
|
921
|
+
const payload = pendingProtocolToolResult
|
|
922
|
+
? {
|
|
923
|
+
...entry,
|
|
924
|
+
protocolToolResult: structuredClone(pendingProtocolToolResult.fact),
|
|
925
|
+
}
|
|
926
|
+
: entry;
|
|
927
|
+
const persisted = journal.appendFact("event", payload, {
|
|
872
928
|
durability: traceFactDurability(entry.event, capabilityByCallId),
|
|
873
929
|
eventId: entry.eventId,
|
|
874
930
|
});
|
|
931
|
+
if (pendingProtocolToolResult) {
|
|
932
|
+
pendingProtocolToolResult.appendStarted = true;
|
|
933
|
+
void persisted
|
|
934
|
+
.then(() => pendingProtocolToolResult.resolve(), (error) => pendingProtocolToolResult.reject(error))
|
|
935
|
+
.finally(() => {
|
|
936
|
+
const facts = executionSlotFor(this).protocolToolResultFacts;
|
|
937
|
+
const key = protocolToolResultKey(entry.runId, toolResultCallId);
|
|
938
|
+
if (facts?.get(key) === pendingProtocolToolResult)
|
|
939
|
+
facts.delete(key);
|
|
940
|
+
});
|
|
941
|
+
}
|
|
875
942
|
this.options.trace?.(entry);
|
|
876
943
|
}, resumePlan?.previousTrace);
|
|
877
944
|
const collected = resumePlan?.previousTrace.map((entry) => entry.event) ?? [];
|
|
@@ -1245,6 +1312,7 @@ export class CoreMindRuntime {
|
|
|
1245
1312
|
beforeModelRequest: () => {
|
|
1246
1313
|
throwIfContextFailed();
|
|
1247
1314
|
throwIfDelegationBlocksModel();
|
|
1315
|
+
budget.beforeModelRequest();
|
|
1248
1316
|
},
|
|
1249
1317
|
onModelRequestDispatched: ({ providerId, modelId, messages }) => {
|
|
1250
1318
|
const contract = contextContracts.get(agentName);
|
|
@@ -1928,6 +1996,7 @@ export class CoreMindRuntime {
|
|
|
1928
1996
|
throw deferredTerminalError;
|
|
1929
1997
|
}
|
|
1930
1998
|
if (loop) {
|
|
1999
|
+
const engineeringEvidence = loop.verify.mode === "host" ? undefined : loop.verify.evidence;
|
|
1931
2000
|
let retryCount = resumePlan?.previousTrace.filter((entry) => entry.event.type === "retry" && entry.event.scope === "provider").length ?? 0;
|
|
1932
2001
|
const runner = new LoopRunner({
|
|
1933
2002
|
runId,
|
|
@@ -1942,9 +2011,20 @@ export class CoreMindRuntime {
|
|
|
1942
2011
|
journal.loop(snapshot);
|
|
1943
2012
|
await journal.flush();
|
|
1944
2013
|
},
|
|
1945
|
-
|
|
2014
|
+
verifyHost: hostVerification
|
|
2015
|
+
? async (request) => {
|
|
2016
|
+
if (journal.isAborted())
|
|
2017
|
+
throw new CoreMindError("aborted", "验收前 Run 已中止");
|
|
2018
|
+
await journal.flush("critical");
|
|
2019
|
+
const decision = await hostVerification.verify(request);
|
|
2020
|
+
if (journal.isAborted())
|
|
2021
|
+
throw new CoreMindError("aborted", "验收期间 Run 已中止");
|
|
2022
|
+
return decision;
|
|
2023
|
+
}
|
|
2024
|
+
: undefined,
|
|
2025
|
+
verifyEvidence: engineeringEvidence
|
|
1946
2026
|
? ({ stepId, textPassed }) => {
|
|
1947
|
-
const report = assessRuntimeEngineeringEvidence(collected,
|
|
2027
|
+
const report = assessRuntimeEngineeringEvidence(collected, engineeringEvidence, stepId);
|
|
1948
2028
|
emit({ type: "engineering_evidence", stepId, textPassed, ...report });
|
|
1949
2029
|
return report.passed;
|
|
1950
2030
|
}
|
|
@@ -2014,7 +2094,10 @@ export class CoreMindRuntime {
|
|
|
2014
2094
|
}
|
|
2015
2095
|
transcript = extractText(messages.slice(messageCursor));
|
|
2016
2096
|
return { outputs: new Map(), transcript };
|
|
2017
|
-
}, (error) =>
|
|
2097
|
+
}, (error) => {
|
|
2098
|
+
hostVerification?.interrupt(error);
|
|
2099
|
+
return activeLoopRunner?.interrupt(error);
|
|
2100
|
+
}));
|
|
2018
2101
|
if (delegationDispositionFailure)
|
|
2019
2102
|
throw delegationDispositionFailure;
|
|
2020
2103
|
if (delegationPolicyFailure)
|
|
@@ -2067,6 +2150,7 @@ export class CoreMindRuntime {
|
|
|
2067
2150
|
}
|
|
2068
2151
|
}
|
|
2069
2152
|
finally {
|
|
2153
|
+
hostVerification?.interrupt(new CoreMindError("run_already_finished", "Run 已结束验收等待"));
|
|
2070
2154
|
context.setHarnessFactory(undefined);
|
|
2071
2155
|
}
|
|
2072
2156
|
while (lifecycleFinalizers.size > 0) {
|
|
@@ -2542,6 +2626,58 @@ function executionSlotFor(runtime) {
|
|
|
2542
2626
|
runtimeExecutionSlots.set(runtime, created);
|
|
2543
2627
|
return created;
|
|
2544
2628
|
}
|
|
2629
|
+
/** 仅供同仓库 ProtocolHost:结果已写入 Runtime 的同一 journal 后才确认 accepted。 */
|
|
2630
|
+
export function prepareProtocolToolResultFact(runtime, fact) {
|
|
2631
|
+
const slot = executionSlotFor(runtime);
|
|
2632
|
+
const runId = slot.kernel?.currentContext()?.currentRunId();
|
|
2633
|
+
if (!runId || runId !== fact.runId) {
|
|
2634
|
+
throw new CoreMindError("run_state_failed", "Protocol v2 工具结果没有匹配的活动 Run");
|
|
2635
|
+
}
|
|
2636
|
+
const validated = validateProtocolToolResultFact(fact, fact.runId, fact.callId);
|
|
2637
|
+
const key = protocolToolResultKey(fact.runId, fact.callId);
|
|
2638
|
+
slot.protocolToolResultFacts ??= new Map();
|
|
2639
|
+
const facts = slot.protocolToolResultFacts;
|
|
2640
|
+
const fingerprint = fingerprintEffectReceiptValue(validated);
|
|
2641
|
+
const existing = facts.get(key);
|
|
2642
|
+
if (existing) {
|
|
2643
|
+
if (existing.fingerprint !== fingerprint) {
|
|
2644
|
+
throw new CoreMindError("run_state_conflict", "Protocol v2 工具结果身份冲突");
|
|
2645
|
+
}
|
|
2646
|
+
return existing.promise;
|
|
2647
|
+
}
|
|
2648
|
+
let resolve;
|
|
2649
|
+
let reject;
|
|
2650
|
+
const promise = new Promise((onResolve, onReject) => {
|
|
2651
|
+
resolve = onResolve;
|
|
2652
|
+
reject = onReject;
|
|
2653
|
+
});
|
|
2654
|
+
void promise.catch(() => undefined);
|
|
2655
|
+
facts.set(key, {
|
|
2656
|
+
fact: validated,
|
|
2657
|
+
fingerprint,
|
|
2658
|
+
promise,
|
|
2659
|
+
resolve,
|
|
2660
|
+
reject,
|
|
2661
|
+
appendStarted: false,
|
|
2662
|
+
});
|
|
2663
|
+
return promise;
|
|
2664
|
+
}
|
|
2665
|
+
async function settleProtocolToolResultFacts(runtime) {
|
|
2666
|
+
const facts = executionSlotFor(runtime).protocolToolResultFacts;
|
|
2667
|
+
if (!facts || facts.size === 0)
|
|
2668
|
+
return;
|
|
2669
|
+
const unfinished = [...facts.values()];
|
|
2670
|
+
for (const pending of unfinished) {
|
|
2671
|
+
if (!pending.appendStarted) {
|
|
2672
|
+
pending.reject(new CoreMindError("run_state_failed", "Run 结束前未持久化 Protocol v2 工具结果 Fact"));
|
|
2673
|
+
}
|
|
2674
|
+
}
|
|
2675
|
+
await Promise.allSettled(unfinished.filter((pending) => pending.appendStarted).map((p) => p.promise));
|
|
2676
|
+
facts.clear();
|
|
2677
|
+
}
|
|
2678
|
+
function protocolToolResultKey(runId, callId) {
|
|
2679
|
+
return `${runId}\u0000${callId}`;
|
|
2680
|
+
}
|
|
2545
2681
|
function runContextFor(runtime) {
|
|
2546
2682
|
const slot = executionSlotFor(runtime);
|
|
2547
2683
|
const kernelContext = slot.kernel?.currentContext();
|
|
@@ -2747,6 +2883,17 @@ function resumedInputId(events) {
|
|
|
2747
2883
|
function toolCallIdentity(agent, stepId, callId) {
|
|
2748
2884
|
return { agent, callId, ...(stepId ? { stepId } : {}) };
|
|
2749
2885
|
}
|
|
2886
|
+
function validateProtocolToolResultFact(fact, runId, callId) {
|
|
2887
|
+
if (fact.schemaVersion !== 1 ||
|
|
2888
|
+
fact.runId !== runId ||
|
|
2889
|
+
fact.callId !== callId ||
|
|
2890
|
+
fact.resultId.trim().length === 0 ||
|
|
2891
|
+
fact.registrationId.trim().length === 0 ||
|
|
2892
|
+
!/^[0-9a-f]{64}$/u.test(fact.requestFingerprint)) {
|
|
2893
|
+
throw new CoreMindError("run_state_failed", "Protocol v2 工具结果 Fact 身份非法");
|
|
2894
|
+
}
|
|
2895
|
+
return structuredClone(fact);
|
|
2896
|
+
}
|
|
2750
2897
|
/** 分界前已启动的活动集合(R3 判定用):从已收集事件的 turnId 提取 */
|
|
2751
2898
|
function knownTurnIdsFrom(collected) {
|
|
2752
2899
|
return new Set(collected.flatMap((event) => {
|