@springbrand/agent-runtime 0.2.0-alpha.72 → 0.3.0-alpha.10
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/package.json +7 -7
- package/src/{agent-tool-runtime.ts → adapter/cloudflare/agent-tool.ts} +1 -1
- package/src/adapter/cloudflare/agent.ts +1682 -0
- package/src/{db/index.ts → adapter/cloudflare/database.ts} +18 -55
- package/src/{runtime-agent.ts → adapter/cloudflare/define-agent.ts} +37 -42
- package/src/adapter/cloudflare/dynamic-worker-observability.ts +1 -1
- package/src/adapter/cloudflare/index.ts +18 -0
- package/src/adapter/cloudflare/resources/runtime-resources.ts +4 -4
- package/src/adapter/cloudflare/sandbox/adapter.ts +1 -1
- package/src/adapter/cloudflare/scheduling/schedule-rule.ts +322 -0
- package/src/adapter/cloudflare/scheduling/zoned-cron.ts +11 -6
- package/src/{db → adapter/cloudflare}/schema.ts +28 -80
- package/src/adapter/cloudflare/subagent/definition.ts +63 -33
- package/src/adapter/cloudflare/subagent/runner.ts +174 -120
- package/src/adapter/cloudflare/subagent/tools.ts +13 -14
- package/src/adapter/cloudflare/universal-agent/preparation.ts +7 -7
- package/src/adapter/cloudflare/universal-agent/tools.ts +10 -12
- package/src/adapter/cloudflare/workspace/git-fs.ts +1 -1
- package/src/adapter/cloudflare/workspace/scoped-workspace.ts +1 -1
- package/src/adapter/cloudflare/workspace/version-control.ts +2 -2
- package/src/config/activation.ts +140 -0
- package/src/{runtime-agent-context.ts → config/agent-context.ts} +3 -3
- package/src/{runtime-assembler.ts → config/assembler.ts} +45 -46
- package/src/{kernel/runtime-assembly.ts → config/assembly-projection.ts} +4 -4
- package/src/{pi/assembly/snapshot.ts → config/assembly-snapshot.ts} +6 -6
- package/src/{runtime-definition.ts → config/definition.ts} +13 -13
- package/src/config/harness-runtime.ts +190 -0
- package/src/config/index.ts +14 -0
- package/src/config/model-guidance.ts +21 -0
- package/src/{pi/runtime-adapter/assembly.ts → config/pinning.ts} +60 -19
- package/src/{kernel/bindings.ts → config/ports.ts} +32 -16
- package/src/{kernel → config}/profile.ts +7 -0
- package/src/{kernel → config}/public-contracts.ts +6 -6
- package/src/{kernel → config}/runtime-load.ts +1 -1
- package/src/{pi/assembly/context.ts → context/assembly.ts} +5 -207
- package/src/{pi/assembly/extensions.ts → context/extension/assembly.ts} +5 -5
- package/src/context/extension/index.ts +3 -0
- package/src/context/index.ts +6 -0
- package/src/{layers/context → context/memory}/budget/gate.ts +21 -5
- package/src/conversation/harness-resume.ts +288 -0
- package/src/conversation/harness-stream.ts +99 -0
- package/src/{pi/runtime-adapter/transcript.ts → conversation/history.ts} +206 -233
- package/src/conversation/index.ts +6 -0
- package/src/{pi → conversation}/message/contract.ts +3 -0
- package/src/{pi → conversation}/message/conversion.ts +75 -0
- package/src/{pi → conversation}/message/index.ts +1 -0
- package/src/{pi → conversation}/message/model-input.ts +1 -1
- package/src/{pi → conversation}/message/projection.ts +113 -30
- package/src/{db/message-ui.repo.ts → conversation/repository.ts} +4 -0
- package/src/conversation/state.ts +196 -0
- package/src/harness/index.ts +7 -0
- package/src/harness/session-harness.ts +562 -0
- package/src/harness/submission-operation.ts +49 -0
- package/src/index.ts +38 -43
- package/src/lib/artifacts.ts +18 -0
- package/src/lib/execution-level.ts +13 -0
- package/src/lib/mcp.ts +1 -1
- package/src/lib/prompt.ts +7 -6
- package/src/lib/token-estimate.ts +8 -0
- package/src/{pi/runtime-adapter/models.ts → models/index.ts} +64 -17
- package/src/{pi/turn/tool-recovery.ts → session/cloudflare/legacy-tool-recovery.ts} +33 -525
- package/src/{pi/session → session/cloudflare}/migration.ts +404 -14
- package/src/{pi/session → session/cloudflare}/storage.ts +8 -36
- package/src/session/index.ts +39 -0
- package/src/skills/springbrand-worker-website/index.ts +1 -1
- package/src/submission/admission.ts +286 -0
- package/src/{kernel/receipts.ts → submission/contracts.ts} +56 -2
- package/src/submission/delivery.ts +212 -0
- package/src/submission/finalization.ts +111 -0
- package/src/submission/index.ts +9 -0
- package/src/{kernel/submission-lifecycle.ts → submission/lifecycle.ts} +41 -28
- package/src/{db/submission.repo.ts → submission/repository.ts} +117 -114
- package/src/submission/steer-delivery.ts +167 -0
- package/src/{db/steer.repo.ts → submission/steer-repository.ts} +27 -5
- package/src/submission/unattended.ts +40 -0
- package/src/telemetry/contract.ts +12 -0
- package/src/telemetry/coordinator.ts +65 -0
- package/src/telemetry/delivery.ts +2 -2
- package/src/telemetry/index.ts +5 -0
- package/src/{model-usage.ts → telemetry/model-usage.ts} +1 -1
- package/src/telemetry/recorder.ts +1 -1
- package/src/telemetry/runtime-telemetry.ts +12 -0
- package/src/{kernel/durable-lifecycle.ts → telemetry/subagent-lifecycle.ts} +1 -1
- package/src/telemetry/turn-events.ts +279 -0
- package/src/tools/README.md +44 -0
- package/src/{pi/tool/ai-adapter.ts → tools/adapters/ai-to-pi.ts} +6 -9
- package/src/{pi/tool → tools/adapters}/declared.ts +6 -2
- package/src/{pi/tool/nested-tools.ts → tools/adapters/pi-to-ai.ts} +2 -2
- package/src/tools/assistant/ask-user.ts +317 -0
- package/src/tools/assistant/candidate.ts +15 -0
- package/src/tools/assistant/followups.ts +34 -0
- package/src/tools/assistant/index.ts +19 -0
- package/src/tools/assistant/memory.ts +73 -0
- package/src/tools/assistant/plan.ts +98 -0
- package/src/{pi/tool → tools/assistant}/time.ts +1 -1
- package/src/{pi/tool/core-host.ts → tools/codemode/adapter.ts} +50 -49
- package/src/{pi/tool/core.ts → tools/codemode/index.ts} +35 -91
- package/src/tools/codemode/workspace-connector.ts +198 -0
- package/src/tools/extension/index.ts +42 -0
- package/src/tools/index.ts +32 -0
- package/src/{pi/tool → tools/mcp}/gateway.ts +19 -19
- package/src/{pi/tool/mcp.ts → tools/mcp/index.ts} +5 -5
- package/src/tools/runtime/approval/index.ts +1 -0
- package/src/{db/approval.repo.ts → tools/runtime/approval/repository.ts} +22 -41
- package/src/tools/runtime/compiler.ts +264 -0
- package/src/tools/runtime/contracts.ts +117 -0
- package/src/tools/runtime/decision-gate.ts +337 -0
- package/src/tools/runtime/human-decisions.ts +127 -0
- package/src/tools/runtime/interaction/index.ts +1 -0
- package/src/{db/interaction.repo.ts → tools/runtime/interaction/repository.ts} +1 -7
- package/src/tools/runtime/result.ts +22 -0
- package/src/tools/runtime/unattended-error.ts +4 -0
- package/src/tools/sandbox/index.ts +228 -0
- package/src/tools/schedule/index.ts +301 -0
- package/src/tools/skill/contracts.ts +20 -0
- package/src/tools/skill/index.ts +99 -0
- package/src/tools/skill/resources.ts +322 -0
- package/src/tools/skill/scripts.ts +168 -0
- package/src/{kernel/submission-authority.ts → tools/subagent/authority.ts} +31 -31
- package/src/{pi/tool/subagent.ts → tools/subagent/index.ts} +33 -36
- package/src/{db/agent-tool.repo.ts → tools/subagent/repository.ts} +1 -1
- package/src/{kernel/subagent-runtime.ts → tools/subagent/runtime.ts} +1 -1
- package/src/tools/subagent/temporary/approvals.ts +123 -0
- package/src/{layers/orchestration/temporary-agent/core.ts → tools/subagent/temporary/coordinator.ts} +41 -49
- package/src/tools/subagent/temporary/core.ts +53 -0
- package/src/{layers/orchestration/temporary-agent → tools/subagent/temporary}/runner.ts +1 -1
- package/src/{layers/orchestration/temporary-agent → tools/subagent/temporary}/workspace.ts +1 -4
- package/src/{pi/tool/web-fetch.ts → tools/web/fetch.ts} +4 -13
- package/src/tools/web/index.ts +2 -0
- package/src/tools/web/search/api.ts +1320 -0
- package/src/tools/web/search/index.ts +2 -0
- package/src/{pi/tool/web-search/web-search.ts → tools/web/search/search.ts} +5 -7
- package/src/{pi/tool/workspace-sandbox.ts → tools/workspace/index.ts} +12 -272
- package/src/{pi/tool/workspace-revision.ts → tools/workspace/revision.ts} +2 -2
- package/src/db/milestone.repo.ts +0 -104
- package/src/db/settlement.repo.ts +0 -104
- package/src/kernel/approval-lifecycle.ts +0 -638
- package/src/kernel/interaction-lifecycle.ts +0 -433
- package/src/kernel/recoverable-chat-agent.ts +0 -1020
- package/src/kernel/state.ts +0 -91
- package/src/pi/assembly/index.ts +0 -19
- package/src/pi/runtime-adapter/execution.ts +0 -1163
- package/src/pi/runtime-adapter/index.ts +0 -293
- package/src/pi/runtime-adapter/recovery.ts +0 -982
- package/src/pi/session/index.ts +0 -24
- package/src/pi/tool/base.ts +0 -550
- package/src/pi/tool/compiler.ts +0 -483
- package/src/pi/tool/index.ts +0 -38
- package/src/pi/tool/schedule.ts +0 -261
- package/src/pi/tool/skill.ts +0 -565
- package/src/pi/tool/web-search/api.ts +0 -1318
- package/src/pi/tool/web-search/index.ts +0 -2
- package/src/pi/tool/workspace-state-connector.ts +0 -146
- package/src/pi/turn/approval.ts +0 -181
- package/src/pi/turn/index.ts +0 -82
- package/src/pi/turn/interaction.ts +0 -181
- package/src/runtime.ts +0 -4760
- package/src/{kernel/runtime-assembly-view.ts → config/assembly-view.ts} +0 -0
- package/src/{kernel → config}/degradation.ts +0 -0
- package/src/{kernel → config}/runtime-config.ts +0 -0
- package/src/{kernel/extensions.ts → context/extension/contracts.ts} +0 -0
- package/src/{db/ext-context.repo.ts → context/extension/repository.ts} +0 -0
- package/src/{pi/runtime-adapter/openrouter-messages.ts → models/openrouter/messages.ts} +0 -0
- package/src/{pi/runtime-adapter → models/openrouter}/test-fixtures/openrouter-tool-search.sse +0 -0
- package/src/{db/submission-admission.repo.ts → submission/admission-repository.ts} +0 -0
- package/src/{db/telemetry-outbox.repo.ts → telemetry/repository.ts} +0 -0
- package/src/{db/runtime-event-outbox.repo.ts → telemetry/runtime-event-repository.ts} +0 -0
- package/src/{layers/orchestration/subagents/agent-types → tools/subagent/types}/contract.ts +0 -0
- package/src/{layers/orchestration/subagents/agent-types → tools/subagent/types}/extract/index.ts +0 -0
- package/src/{layers/orchestration/subagents/agent-types → tools/subagent/types}/fanout/index.ts +0 -0
- package/src/{layers/orchestration/subagents/agent-types → tools/subagent/types}/registry.ts +1 -1
- /package/src/{workspace-versioning.ts → tools/workspace/versioning.ts} +0 -0
|
@@ -3,12 +3,12 @@ import type {
|
|
|
3
3
|
ChatCapableAgentClass,
|
|
4
4
|
RunAgentToolOptions,
|
|
5
5
|
} from "agents";
|
|
6
|
-
import type { ExecutionLevel } from "
|
|
7
|
-
import type { RuntimeConfigUpdateResult } from "./
|
|
6
|
+
import type { ExecutionLevel } from "../lib/execution-level";
|
|
7
|
+
import type { RuntimeConfigUpdateResult } from "./runtime-config";
|
|
8
8
|
import type {
|
|
9
9
|
TemporaryAgentRequest,
|
|
10
10
|
TemporaryAgentRunContext,
|
|
11
|
-
} from "
|
|
11
|
+
} from "../tools/subagent/temporary/core";
|
|
12
12
|
|
|
13
13
|
/**
|
|
14
14
|
* 描述 Agent 寻址路径中的一级父子节点。
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { schedulePiToolCandidates } from "../tools/schedule";
|
|
1
2
|
import type { SkillSource } from "agents/skills";
|
|
2
3
|
import type {
|
|
3
4
|
RuntimeGatewayPort,
|
|
@@ -14,7 +15,7 @@ import type {
|
|
|
14
15
|
RuntimeBindings,
|
|
15
16
|
RuntimeSkillScriptPolicy,
|
|
16
17
|
WorkspacePort,
|
|
17
|
-
} from "./
|
|
18
|
+
} from "./ports";
|
|
18
19
|
import {
|
|
19
20
|
freezeRuntimeProfile,
|
|
20
21
|
type RuntimeDenyPolicy,
|
|
@@ -22,24 +23,21 @@ import {
|
|
|
22
23
|
type RuntimeMemoryProfile,
|
|
23
24
|
type RuntimeProfile,
|
|
24
25
|
type ThinkingEffort,
|
|
25
|
-
} from "./
|
|
26
|
-
import type { RuntimeExtensionConfig } from "
|
|
27
|
-
import type { RuntimeDegradation } from "./
|
|
26
|
+
} from "./profile";
|
|
27
|
+
import type { RuntimeExtensionConfig } from "../context/extension/contracts";
|
|
28
|
+
import type { RuntimeDegradation } from "./degradation";
|
|
28
29
|
import {
|
|
29
30
|
EXECUTION_LEVELS,
|
|
30
31
|
type ExecutionLevel,
|
|
31
|
-
} from "
|
|
32
|
+
} from "../lib/execution-level";
|
|
32
33
|
import {
|
|
33
34
|
createPiRuntimeAssembly,
|
|
34
35
|
type FinalizedPiToolSurface,
|
|
35
36
|
type PiToolSurface,
|
|
36
37
|
type PiRuntimeAssembly,
|
|
37
|
-
} from "./
|
|
38
|
+
} from "./assembly-snapshot";
|
|
38
39
|
import type { AgentTool } from "@earendil-works/pi-agent-core";
|
|
39
|
-
import type {
|
|
40
|
-
PiToolCandidate,
|
|
41
|
-
ToolExposureMode,
|
|
42
|
-
} from "./pi/tool/compiler";
|
|
40
|
+
import type { PiToolCandidate, ToolExposureMode } from "../tools/runtime/contracts";
|
|
43
41
|
import type {
|
|
44
42
|
AssembleRuntimeSnapshotInput,
|
|
45
43
|
RuntimeSettings,
|
|
@@ -48,36 +46,30 @@ import type {
|
|
|
48
46
|
RuntimeSkillBodyTransform,
|
|
49
47
|
RuntimeSkillContribution,
|
|
50
48
|
RuntimeToolSurfacePolicy,
|
|
51
|
-
} from "./
|
|
52
|
-
import type { RuntimeCodeExecutionFactory } from "./
|
|
53
|
-
import {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
} from "
|
|
57
|
-
import {
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
codeExecutionPiToolCandidate,
|
|
61
|
-
} from "./pi/tool/core";
|
|
62
|
-
import { skillPiToolCandidates } from "./pi/tool/skill";
|
|
63
|
-
import { createWebSearch, WEB_SEARCH_MODEL } from "./pi/tool/web-search";
|
|
64
|
-
import { subagentPiToolCandidates } from "./pi/tool/subagent";
|
|
65
|
-
import { resolvePiModel } from "./pi/runtime-adapter/models";
|
|
49
|
+
} from "./definition";
|
|
50
|
+
import type { RuntimeCodeExecutionFactory } from "./ports";
|
|
51
|
+
import { basePiToolCandidates } from "../tools/assistant";
|
|
52
|
+
import { memoryPiToolCandidate } from "../tools/assistant/memory";
|
|
53
|
+
import { BROWSER_EXECUTE_TOOL_NAME, browserExecutionPiToolCandidate, codeExecutionPiToolCandidate } from "../tools/codemode";
|
|
54
|
+
import { skillPiToolCandidates } from "../tools/skill";
|
|
55
|
+
import { createWebSearch, WEB_SEARCH_MODEL } from "../tools/web/search";
|
|
56
|
+
import { subagentPiToolCandidates } from "../tools/subagent";
|
|
57
|
+
import { resolvePiModel } from "../models";
|
|
66
58
|
import {
|
|
67
59
|
normalizeAgentTelemetryBinding,
|
|
68
60
|
type AgentTelemetryBinding,
|
|
69
|
-
} from "
|
|
70
|
-
import { BUILT_IN_RUNTIME_SKILLS } from "
|
|
61
|
+
} from "../telemetry/contract";
|
|
62
|
+
import { BUILT_IN_RUNTIME_SKILLS } from "../skills";
|
|
71
63
|
|
|
72
64
|
/** Runtime Assembler:校验一份扁平输入并生成可原子提交的 Snapshot。 */
|
|
73
65
|
|
|
74
|
-
export type { RuntimeDegradation } from "./
|
|
66
|
+
export type { RuntimeDegradation } from "./degradation";
|
|
75
67
|
export type {
|
|
76
68
|
RuntimeExtensionContribution,
|
|
77
69
|
RuntimeProfileContribution,
|
|
78
70
|
RuntimeSkillContribution,
|
|
79
71
|
RuntimeToolSurfacePolicy,
|
|
80
|
-
} from "./
|
|
72
|
+
} from "./definition";
|
|
81
73
|
|
|
82
74
|
/** Host Planner 与 Runtime Assembler 之间的一次性内部 seam。 */
|
|
83
75
|
export interface RuntimeAssemblyInput {
|
|
@@ -127,6 +119,7 @@ export interface RuntimeSnapshot {
|
|
|
127
119
|
*/
|
|
128
120
|
export interface RuntimeCandidate {
|
|
129
121
|
readonly snapshot: RuntimeSnapshot;
|
|
122
|
+
readonly runtimeKey?: string;
|
|
130
123
|
readonly commitGuards: readonly (() => Promise<void>)[];
|
|
131
124
|
readonly admission?: RuntimeSubmissionAdmissionHook;
|
|
132
125
|
readonly telemetry?: AgentTelemetryBinding;
|
|
@@ -263,6 +256,16 @@ async function createToolSurface(
|
|
|
263
256
|
if (!EXECUTION_LEVELS.includes(candidate.requiredExecutionLevel)) {
|
|
264
257
|
throw new Error(`SpringBrand Tool ${name} execution level is invalid`);
|
|
265
258
|
}
|
|
259
|
+
if (candidate.unattendedExecution) {
|
|
260
|
+
requiredName(
|
|
261
|
+
candidate.unattendedExecution.capability,
|
|
262
|
+
`SpringBrand Tool ${name} unattended capability`,
|
|
263
|
+
);
|
|
264
|
+
requiredName(
|
|
265
|
+
candidate.unattendedExecution.operation,
|
|
266
|
+
`SpringBrand Tool ${name} unattended operation`,
|
|
267
|
+
);
|
|
268
|
+
}
|
|
266
269
|
if (tools.has(name)) {
|
|
267
270
|
throw new Error(`Duplicate Runtime SpringBrand Tool: ${name}`);
|
|
268
271
|
}
|
|
@@ -293,17 +296,12 @@ async function createToolSurface(
|
|
|
293
296
|
typeof candidate.tool.execute === "function",
|
|
294
297
|
);
|
|
295
298
|
const codeExecutionCandidates = Object.freeze([...mergeable]);
|
|
296
|
-
const codeExecutionToolNames = new Set(
|
|
297
|
-
codeExecutionCandidates.map(({ tool }) => tool.name),
|
|
298
|
-
);
|
|
299
299
|
const codeExecution = input.codeExecution.create(
|
|
300
300
|
codeExecutionCandidates,
|
|
301
301
|
);
|
|
302
|
-
const
|
|
303
|
-
({ tool }) => !codeExecutionToolNames.has(tool.name),
|
|
304
|
-
);
|
|
302
|
+
const directToolNames = new Set(directVisible.map(({ tool }) => tool.name));
|
|
305
303
|
const routeList = (deferred: boolean) => {
|
|
306
|
-
const matches =
|
|
304
|
+
const matches = directVisible.filter((candidate) =>
|
|
307
305
|
(defersTool?.(candidate.tool.name) === true) === deferred
|
|
308
306
|
);
|
|
309
307
|
return matches.length > 0
|
|
@@ -315,8 +313,9 @@ async function createToolSurface(
|
|
|
315
313
|
};
|
|
316
314
|
const routeGuidance = [
|
|
317
315
|
"## Tool routing",
|
|
318
|
-
"
|
|
316
|
+
"For top-level deferred Tools, use Provider Tool Search with their exact name, then call them directly.",
|
|
319
317
|
"Top-level immediate Tools are already available outside execute; call them directly.",
|
|
318
|
+
"Only Code Mode Tools listed below are callable inside execute through tools.<name>. Tools marked execute-only are not registered as top-level Tools.",
|
|
320
319
|
"",
|
|
321
320
|
"## Top-level deferred Tools",
|
|
322
321
|
routeList(true),
|
|
@@ -324,21 +323,20 @@ async function createToolSurface(
|
|
|
324
323
|
"## Top-level immediate Tools",
|
|
325
324
|
routeList(false),
|
|
326
325
|
"",
|
|
326
|
+
"## Code Mode Tools",
|
|
327
|
+
codeExecutionCandidates.length > 0
|
|
328
|
+
? codeExecutionCandidates.map(({ tool }) =>
|
|
329
|
+
`- \`tools.${tool.name}\` — ${directToolNames.has(tool.name) ? "also available as a top-level Tool" : "execute-only"}`
|
|
330
|
+
).join("\n")
|
|
331
|
+
: "- None.",
|
|
332
|
+
"",
|
|
327
333
|
].join("\n");
|
|
328
|
-
const materializeGuidance = codeExecutionCandidates.some(
|
|
329
|
-
({ tool }) => tool.name === "materialize_skill_resource",
|
|
330
|
-
)
|
|
331
|
-
? "Skill resource copying is available only inside execute through " +
|
|
332
|
-
"`tools.materialize_skill_resource({ name, path, destination })`; " +
|
|
333
|
-
"no Direct Tool is registered for it. " +
|
|
334
|
-
"Copy multiple resources sequentially in one execute so durable replay preserves call order.\n\n"
|
|
335
|
-
: "";
|
|
336
334
|
return Object.freeze({
|
|
337
335
|
candidates: Object.freeze([
|
|
338
336
|
classify(codeExecutionPiToolCandidate({
|
|
339
337
|
...codeExecution,
|
|
340
338
|
description:
|
|
341
|
-
routeGuidance + "\n" +
|
|
339
|
+
routeGuidance + "\n" + codeExecution.description,
|
|
342
340
|
})),
|
|
343
341
|
...directVisible.map(classify),
|
|
344
342
|
]),
|
|
@@ -631,6 +629,7 @@ class RuntimeBuilder {
|
|
|
631
629
|
: {}),
|
|
632
630
|
hostTools: [
|
|
633
631
|
...this.hostTools,
|
|
632
|
+
...(this.schedule ? schedulePiToolCandidates(this.schedule) : []),
|
|
634
633
|
...subagentPiToolCandidates(
|
|
635
634
|
this.subagents,
|
|
636
635
|
[...this.enabledSubagents],
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type { RuntimeSnapshot } from "
|
|
2
|
-
import type { PreparedPiRuntime } from "
|
|
3
|
-
import type { RuntimeAssemblyView } from "./
|
|
4
|
-
export type * from "./
|
|
1
|
+
import type { RuntimeSnapshot } from "./assembler";
|
|
2
|
+
import type { PreparedPiRuntime } from "./harness-runtime";
|
|
3
|
+
import type { RuntimeAssemblyView } from "./assembly-view";
|
|
4
|
+
export type * from "./assembly-view";
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Serializable view of the Runtime Snapshot currently installed on a Session facet.
|
|
@@ -11,14 +11,14 @@ import type {
|
|
|
11
11
|
RuntimeMcpServer,
|
|
12
12
|
RuntimeProfile,
|
|
13
13
|
ThinkingEffort,
|
|
14
|
-
} from "
|
|
14
|
+
} from "./profile";
|
|
15
15
|
import type {
|
|
16
16
|
RuntimeExtensionConfig,
|
|
17
|
-
} from "
|
|
18
|
-
import type { RuntimeProviderPort } from "
|
|
19
|
-
import { assembleSystemPrompt } from "
|
|
20
|
-
import { resolvePiModel } from "../
|
|
21
|
-
import type { PiToolCandidate } from "../
|
|
17
|
+
} from "../context/extension/contracts";
|
|
18
|
+
import type { RuntimeProviderPort } from "./ports";
|
|
19
|
+
import { assembleSystemPrompt } from "../lib/prompt";
|
|
20
|
+
import { resolvePiModel } from "../models";
|
|
21
|
+
import type { PiToolCandidate } from "../tools/runtime/contracts";
|
|
22
22
|
|
|
23
23
|
/**
|
|
24
24
|
* 收集完动态 Extension/MCP 候选后,一次性生成最终 Tool Surface。
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { SkillSource } from "agents/skills";
|
|
2
|
-
import type { ExecutionLevel } from "
|
|
2
|
+
import type { ExecutionLevel } from "../lib/execution-level";
|
|
3
3
|
import type {
|
|
4
4
|
RuntimeGatewayPort,
|
|
5
5
|
RuntimeMcpHost,
|
|
@@ -8,21 +8,21 @@ import type {
|
|
|
8
8
|
RuntimeSkillScriptPolicy,
|
|
9
9
|
RuntimeSubmissionAdmissionHook,
|
|
10
10
|
RuntimeTurnEventsPort,
|
|
11
|
-
} from "./
|
|
11
|
+
} from "./ports";
|
|
12
12
|
import type {
|
|
13
13
|
RuntimeDenyPolicy,
|
|
14
14
|
RuntimeMcpServer,
|
|
15
15
|
RuntimeMemoryProfile,
|
|
16
16
|
ThinkingEffort,
|
|
17
|
-
} from "./
|
|
18
|
-
import type { RuntimeExtensionConfig } from "
|
|
19
|
-
import type { RuntimeDegradation } from "./
|
|
20
|
-
import type { PiToolCandidate } from "
|
|
17
|
+
} from "./profile";
|
|
18
|
+
import type { RuntimeExtensionConfig } from "../context/extension/contracts";
|
|
19
|
+
import type { RuntimeDegradation } from "./degradation";
|
|
20
|
+
import type { PiToolCandidate } from "../tools/runtime/contracts";
|
|
21
21
|
import type {
|
|
22
22
|
RuntimeAgentContext,
|
|
23
23
|
RuntimeAgentPlanningContext,
|
|
24
|
-
} from "./
|
|
25
|
-
import type { AgentTelemetryBinding } from "
|
|
24
|
+
} from "./agent-context";
|
|
25
|
+
import type { AgentTelemetryBinding } from "../telemetry/contract";
|
|
26
26
|
|
|
27
27
|
/** Tool Surface 筛选策略(不含 Manifest deny 列表)。 */
|
|
28
28
|
export interface ToolSurfaceSelectionPolicy {
|
|
@@ -33,10 +33,10 @@ export interface ToolSurfaceSelectionPolicy {
|
|
|
33
33
|
|
|
34
34
|
/** Kernel 绑定仍需要的执行后端;不出现在 Definition 公开类型里。 */
|
|
35
35
|
export interface RuntimeToolBindings {
|
|
36
|
-
readonly workspace?: import("./
|
|
37
|
-
readonly codeExecution?: import("./
|
|
38
|
-
readonly memory?: import("./
|
|
39
|
-
readonly subagents?: import("./
|
|
36
|
+
readonly workspace?: import("./ports").WorkspacePort;
|
|
37
|
+
readonly codeExecution?: import("./ports").RuntimeCodeExecutionFactory;
|
|
38
|
+
readonly memory?: import("./ports").RuntimeMemoryPort;
|
|
39
|
+
readonly subagents?: import("./ports").RuntimeSubagentPort;
|
|
40
40
|
}
|
|
41
41
|
|
|
42
42
|
/** Host 一次装配原子提交的 Tool candidates 与 Runtime 绑定。 */
|
|
@@ -75,7 +75,7 @@ export interface RuntimeToolSurfacePolicy extends ToolSurfaceSelectionPolicy {
|
|
|
75
75
|
readonly denyPolicy?: RuntimeDenyPolicy;
|
|
76
76
|
}
|
|
77
77
|
|
|
78
|
-
export type { RuntimeAgentContext, RuntimeAssemblyContext } from "./
|
|
78
|
+
export type { RuntimeAgentContext, RuntimeAssemblyContext } from "./agent-context";
|
|
79
79
|
|
|
80
80
|
export interface ResolvedConnectors {
|
|
81
81
|
readonly servers: readonly RuntimeMcpServer[];
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createModels,
|
|
3
|
+
lazyStream,
|
|
4
|
+
type MutableModels,
|
|
5
|
+
} from "@earendil-works/pi-ai";
|
|
6
|
+
import {
|
|
7
|
+
configurePiModels,
|
|
8
|
+
createPiModels,
|
|
9
|
+
withProviderBoundary,
|
|
10
|
+
type PiGenerationLifecycleObserver,
|
|
11
|
+
} from "../models";
|
|
12
|
+
export {
|
|
13
|
+
MODEL_STREAM_STALL_TIMEOUT_MS,
|
|
14
|
+
modelRequestUrl,
|
|
15
|
+
readModelStreamStallDetails,
|
|
16
|
+
} from "../models";
|
|
17
|
+
import {
|
|
18
|
+
pinPiRuntime,
|
|
19
|
+
preparePiRuntime,
|
|
20
|
+
readPinnedPiRuntime,
|
|
21
|
+
readPreparedPiRuntime,
|
|
22
|
+
type PinPiRuntimeOptions,
|
|
23
|
+
type PinnedPiRuntime,
|
|
24
|
+
type PreparePiRuntimeOptions,
|
|
25
|
+
type PreparedPiRuntime,
|
|
26
|
+
} from "./pinning";
|
|
27
|
+
import { refreshModelGuidance } from "./model-guidance";
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Runtime 通过这个配置入口准备、固定并读取 Harness 的模型、提示和工具输入。
|
|
31
|
+
*
|
|
32
|
+
* @remarks
|
|
33
|
+
* Runtime、Pi、Turn、Tool Candidate 和 canonical transcript 等核心术语见包入口 `../../index.ts`。
|
|
34
|
+
* 本适配器只补充以下局部术语。
|
|
35
|
+
*
|
|
36
|
+
* - Prepared Runtime 是配置加载期产生的不透明句柄。
|
|
37
|
+
* 它包含已加载 Extension、Tool candidate 和快照,但 Runtime 只能读取 revision descriptor 与 degradation。
|
|
38
|
+
* - revision descriptor 是影响执行行为的已排序 JSON 描述。
|
|
39
|
+
* Runtime 会对它取哈希,用来识别当前 Prepared Runtime 的基础版本。
|
|
40
|
+
* - Pinned Runtime 是 Submission 准入时固定的描述符。
|
|
41
|
+
* 它在 Prepared Runtime 基础上加入动态 system context、approval mode 和 base revision。
|
|
42
|
+
* 调用方:`AgentRuntimeKernel` 在配置加载、请求准入与打开 SessionHarness 前调用这些粗粒度能力。
|
|
43
|
+
*
|
|
44
|
+
* 执行位置仍由 `SessionHarness` 拥有,消息读写和投影由 `ConversationHistory` 拥有。
|
|
45
|
+
*/
|
|
46
|
+
export class HarnessRuntimeConfig {
|
|
47
|
+
private readonly owner = {};
|
|
48
|
+
private readonly models: MutableModels;
|
|
49
|
+
private readonly managesModels: boolean;
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* 创建一个持有独立 Pi 模型目录的 Runtime 适配器。
|
|
53
|
+
*
|
|
54
|
+
* @remarks
|
|
55
|
+
* 调用方:生产 Runtime 使用零参数构造,测试或专用宿主可以注入已经配置好的模型目录。
|
|
56
|
+
*
|
|
57
|
+
* 实现理由:适配器只管理自己创建的目录;注入目录的生命周期和配置权仍属于注入方。
|
|
58
|
+
* 不要让 `activate()` 重配注入目录,否则会覆盖调用方准备的 provider 和模型替身。
|
|
59
|
+
*/
|
|
60
|
+
constructor(options: { models?: MutableModels } = {}) {
|
|
61
|
+
this.models = options.models ?? createModels();
|
|
62
|
+
this.managesModels = !options.models;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* 加载并预检一份可供后续准入使用的 Prepared Runtime。
|
|
67
|
+
*
|
|
68
|
+
* @remarks
|
|
69
|
+
* 调用方:Runtime 的 `initConfig()` 在取得新快照后调用,再用返回的 revision descriptor 判断是否可以切换配置。
|
|
70
|
+
*
|
|
71
|
+
* 实现理由:Extension 加载、Tool candidate 汇总和 Tool 编译预检在配置切换前一次完成。
|
|
72
|
+
* 返回值绑定当前 Adapter 的 owner,不能交给另一个 Adapter 创建 Turn。
|
|
73
|
+
*/
|
|
74
|
+
prepare(
|
|
75
|
+
options: PreparePiRuntimeOptions,
|
|
76
|
+
): Promise<PreparedPiRuntime> {
|
|
77
|
+
if (this.managesModels) {
|
|
78
|
+
createPiModels(options.snapshot.bindings.provider);
|
|
79
|
+
}
|
|
80
|
+
return preparePiRuntime(options, this.owner);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
hasTool(prepared: PreparedPiRuntime, name: string): boolean {
|
|
84
|
+
return readPreparedPiRuntime(prepared, this.owner).candidates.some(
|
|
85
|
+
(candidate) => candidate.tool.name === name,
|
|
86
|
+
);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/** Read the immutable inputs consumed by the Session AgentHarness. */
|
|
90
|
+
harnessInputs(
|
|
91
|
+
prepared: PreparedPiRuntime,
|
|
92
|
+
pinnedDescriptor: string,
|
|
93
|
+
request: {
|
|
94
|
+
readonly modelSessionId?: string;
|
|
95
|
+
readonly onGeneration?: PiGenerationLifecycleObserver;
|
|
96
|
+
} = {},
|
|
97
|
+
) {
|
|
98
|
+
const { state, descriptor } = readPinnedPiRuntime(
|
|
99
|
+
prepared,
|
|
100
|
+
this.owner,
|
|
101
|
+
pinnedDescriptor,
|
|
102
|
+
);
|
|
103
|
+
const pinnedModel = state.snapshot.pi.model;
|
|
104
|
+
let models!: MutableModels;
|
|
105
|
+
models = new Proxy(this.models, {
|
|
106
|
+
get: (target, property) => {
|
|
107
|
+
if (property === "getModel") {
|
|
108
|
+
return (provider: string, modelId: string) =>
|
|
109
|
+
provider === pinnedModel.provider && modelId === pinnedModel.id
|
|
110
|
+
? pinnedModel
|
|
111
|
+
: target.getModel(provider, modelId);
|
|
112
|
+
}
|
|
113
|
+
if (property === "streamSimple") {
|
|
114
|
+
const stream = withProviderBoundary(
|
|
115
|
+
target.streamSimple.bind(target),
|
|
116
|
+
request.modelSessionId,
|
|
117
|
+
request.onGeneration,
|
|
118
|
+
);
|
|
119
|
+
return ((model, context, options) => lazyStream(model, async () => {
|
|
120
|
+
options?.signal?.throwIfAborted();
|
|
121
|
+
const refreshed = await refreshModelGuidance(state.candidates, context);
|
|
122
|
+
options?.signal?.throwIfAborted();
|
|
123
|
+
return stream(model, refreshed, options);
|
|
124
|
+
})) satisfies typeof stream;
|
|
125
|
+
}
|
|
126
|
+
if (property === "completeSimple") {
|
|
127
|
+
return target.completeSimple.bind(models);
|
|
128
|
+
}
|
|
129
|
+
const value = Reflect.get(target, property, target);
|
|
130
|
+
return typeof value === "function" ? value.bind(target) : value;
|
|
131
|
+
},
|
|
132
|
+
});
|
|
133
|
+
return {
|
|
134
|
+
models,
|
|
135
|
+
model: state.snapshot.pi.model,
|
|
136
|
+
thinkingLevel: state.snapshot.pi.thinkingLevel,
|
|
137
|
+
systemPrompt: descriptor.systemPrompt,
|
|
138
|
+
candidates: state.candidates,
|
|
139
|
+
workspace: state.snapshot.bindings.workspace,
|
|
140
|
+
platform: state.snapshot.bindings.platform,
|
|
141
|
+
compaction: {
|
|
142
|
+
enabled: true,
|
|
143
|
+
// Pi compacts above contextWindow - reserveTokens. Keep the same
|
|
144
|
+
// 15% headroom within the available input budget as the pre-Harness runtime.
|
|
145
|
+
reserveTokens: Math.ceil(state.snapshot.pi.model.contextWindow -
|
|
146
|
+
(state.snapshot.pi.model.contextWindow - state.snapshot.pi.model.maxTokens) * 0.85),
|
|
147
|
+
keepRecentTokens: Math.min(
|
|
148
|
+
20_000,
|
|
149
|
+
Math.floor(state.snapshot.pi.model.contextWindow * 0.15),
|
|
150
|
+
),
|
|
151
|
+
},
|
|
152
|
+
} as const;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* 用已经通过加载检查的快照启用当前部署声明的模型目录。
|
|
157
|
+
*
|
|
158
|
+
* @remarks
|
|
159
|
+
* 调用方:Runtime 的 `initConfig()` 在 Prepared Runtime 和 revision 检查成功后、发布新快照前调用。
|
|
160
|
+
*
|
|
161
|
+
* 实现理由:`prepare()` 已校验所有 endpoint 模型,这里只把同一份部署目录切换到长期 Models 实例。
|
|
162
|
+
* 注入模型目录时跳过此步骤,以保留调用方对目录的配置权。
|
|
163
|
+
*/
|
|
164
|
+
activate(snapshot: PreparePiRuntimeOptions["snapshot"]): void {
|
|
165
|
+
if (this.managesModels) {
|
|
166
|
+
configurePiModels(this.models, snapshot.bindings.provider);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* 在接受 Submission 前固定本次执行使用的动态上下文和审批模式。
|
|
172
|
+
*
|
|
173
|
+
* @remarks
|
|
174
|
+
* 调用方:Runtime 的准入流程为每个新 Submission 调用,并把 descriptor 与其哈希一起持久化。
|
|
175
|
+
*
|
|
176
|
+
* 实现理由:memory、workspace 和 Extension context 可能随时间变化,所以把准入时的 Turn 字段保存在 descriptor 中。
|
|
177
|
+
* 不要把 pin 推迟到 Turn 启动后,否则已持久化的 Submission 将失去可验证的执行基线。
|
|
178
|
+
*/
|
|
179
|
+
pin(options: PinPiRuntimeOptions): Promise<PinnedPiRuntime> {
|
|
180
|
+
return pinPiRuntime(options, this.owner);
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
export type {
|
|
186
|
+
PinPiRuntimeOptions,
|
|
187
|
+
PinnedPiRuntime,
|
|
188
|
+
PreparePiRuntimeOptions,
|
|
189
|
+
PreparedPiRuntime,
|
|
190
|
+
} from "./pinning";
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export * from "./activation";
|
|
2
|
+
export * from "./agent-context";
|
|
3
|
+
export * from "./assembler";
|
|
4
|
+
export * from "./assembly-projection";
|
|
5
|
+
export * from "./assembly-snapshot";
|
|
6
|
+
export * from "./assembly-view";
|
|
7
|
+
export * from "./definition";
|
|
8
|
+
export * from "./degradation";
|
|
9
|
+
export * from "./harness-runtime";
|
|
10
|
+
export * from "./pinning";
|
|
11
|
+
export * from "./ports";
|
|
12
|
+
export * from "./profile";
|
|
13
|
+
export * from "./runtime-config";
|
|
14
|
+
export * from "./runtime-load";
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { Context } from "@earendil-works/pi-ai";
|
|
2
|
+
import type { PiToolCandidate } from "../tools/runtime/contracts";
|
|
3
|
+
|
|
4
|
+
/** Only descriptions and guidance may vary inside a pinned Submission. */
|
|
5
|
+
export async function refreshModelGuidance(
|
|
6
|
+
candidates: readonly PiToolCandidate[],
|
|
7
|
+
context: Context,
|
|
8
|
+
): Promise<Context> {
|
|
9
|
+
const guidance = new Map(await Promise.all(candidates
|
|
10
|
+
.filter(candidate => candidate.modelGuidance && context.tools?.some(tool => tool.name === candidate.tool.name))
|
|
11
|
+
.map(async candidate => [candidate.tool.name, await candidate.modelGuidance!()] as const)));
|
|
12
|
+
if (!guidance.size) return context;
|
|
13
|
+
return {
|
|
14
|
+
...context,
|
|
15
|
+
systemPrompt: [context.systemPrompt, ...new Set([...guidance.values()].map(item => item.systemPrompt).filter(Boolean))].filter(Boolean).join("\n\n"),
|
|
16
|
+
tools: context.tools?.map(tool => {
|
|
17
|
+
const prompt = guidance.get(tool.name);
|
|
18
|
+
return prompt ? { ...tool, description: prompt.description } : tool;
|
|
19
|
+
}),
|
|
20
|
+
};
|
|
21
|
+
}
|