@mininglamp-oss/octo-runtime 1.1.12 → 1.1.14
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 +1 -1
- package/apps/cli/dist/adapters.d.ts +19 -1
- package/apps/cli/dist/adapters.js +154 -28
- package/apps/cli/dist/build-info.json +2 -2
- package/apps/cli/dist/codex.d.ts +5 -0
- package/apps/cli/dist/codex.js +36 -0
- package/apps/cli/dist/kernel.d.ts +4 -0
- package/apps/cli/dist/kernel.js +84 -0
- package/apps/cli/dist/main.js +8 -7
- package/apps/cli/dist/manifest.json +33 -22
- package/apps/cli/dist/output.d.ts +1 -0
- package/apps/cli/dist/output.js +8 -4
- package/apps/cli/dist/playboard.js +21 -12
- package/apps/cli/dist/provider-launch.d.ts +28 -0
- package/apps/cli/dist/provider-launch.js +52 -0
- package/apps/cli/dist/providers.d.ts +182 -0
- package/apps/cli/dist/providers.js +34 -0
- package/dist/public/adapter-sdk.d.ts +2 -0
- package/dist/public/adapter-sdk.js +2 -0
- package/dist/public/protocol.d.ts +2 -2
- package/dist/public/protocol.js +1 -1
- package/node_modules/@mininglamp-oss/octo-runtime-acp-client/dist/index.js +4 -4
- package/node_modules/@mininglamp-oss/octo-runtime-acp-client/package.json +3 -3
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-acp/dist/index.d.ts +26 -10
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-acp/dist/index.js +44 -53
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-acp/package.json +4 -4
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-antigravity/dist/index.d.ts +10 -35
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-antigravity/dist/index.js +21 -29
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-antigravity/package.json +3 -3
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-claude-code/dist/agent-env.d.ts +3 -0
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-claude-code/dist/agent-env.js +10 -0
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-claude-code/dist/index.d.ts +14 -68
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-claude-code/dist/index.js +77 -61
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-claude-code/package.json +3 -3
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-codebuddy/dist/index.d.ts +19 -31
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-codebuddy/dist/index.js +28 -18
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-codebuddy/package.json +4 -4
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-codex/dist/agent-env.d.ts +3 -0
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-codex/dist/agent-env.js +10 -0
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-codex/dist/app-server.d.ts +6 -5
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-codex/dist/app-server.js +55 -54
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-codex/dist/engine.d.ts +54 -0
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-codex/dist/engine.js +147 -0
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-codex/dist/environment.js +4 -8
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-codex/dist/index.d.ts +20 -92
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-codex/dist/index.js +103 -217
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-codex/dist/mcp.d.ts +2 -2
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-codex/dist/mcp.js +4 -11
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-codex/dist/service.d.ts +9 -5
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-codex/dist/service.js +77 -81
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-codex/package.json +3 -3
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-dsh/dist/{chunk-SMTJTIN7.js → chunk-AE3OJBDS.js} +1 -1
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-dsh/dist/{chunk-H3S6WM37.js → chunk-NGR74QLF.js} +0 -1
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-dsh/dist/{chunk-RISQ6NGV.js → chunk-XIUZ6GXG.js} +1 -1
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-dsh/dist/errors.d.ts +0 -1
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-dsh/dist/errors.js +1 -1
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-dsh/dist/index.d.ts +6 -8
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-dsh/dist/index.js +16 -21
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-dsh/dist/launch.js +2 -2
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-dsh/dist/trajectory.js +2 -2
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-dsh/package.json +3 -3
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-grok-build/dist/adapter.d.ts +14 -16
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-grok-build/dist/adapter.js +29 -46
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-grok-build/dist/agent-env.d.ts +3 -0
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-grok-build/dist/agent-env.js +10 -0
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-grok-build/dist/client.js +4 -7
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-grok-build/dist/index.d.ts +13 -21
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-grok-build/dist/index.js +47 -36
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-grok-build/package.json +5 -5
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-hermes/dist/index.d.ts +24 -8
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-hermes/dist/index.js +14 -7
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-hermes/package.json +2 -2
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-kimi-code/dist/index.d.ts +24 -8
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-kimi-code/dist/index.js +13 -6
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-kimi-code/package.json +2 -2
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-mcode/dist/index.d.ts +24 -8
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-mcode/dist/index.js +14 -7
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-mcode/package.json +2 -2
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-openclaw/dist/index.d.ts +7 -7
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-openclaw/dist/index.js +28 -31
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-openclaw/package.json +3 -3
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-opencode/dist/index.d.ts +16 -25
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-opencode/dist/index.js +113 -179
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-opencode/package.json +4 -4
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-qodercli/dist/index.d.ts +24 -8
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-qodercli/dist/index.js +14 -6
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-qodercli/package.json +3 -2
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-qoderclicn/dist/index.d.ts +24 -8
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-qoderclicn/dist/index.js +14 -6
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-qoderclicn/package.json +3 -2
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-sdk/dist/activity.d.ts +5 -1
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-sdk/dist/agent-env.d.ts +48 -0
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-sdk/dist/agent-env.js +234 -0
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-sdk/dist/approval.js +7 -2
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-sdk/dist/environment.js +1 -1
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-sdk/dist/execution-scope.d.ts +5 -1
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-sdk/dist/index.d.ts +25 -14
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-sdk/dist/index.js +112 -59
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-sdk/dist/mcp.js +1 -1
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-sdk/dist/process-launch.d.ts +11 -1
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-sdk/dist/process-launch.js +89 -8
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-sdk/dist/provider-launch.d.ts +10 -0
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-sdk/dist/provider-launch.js +25 -0
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-sdk/dist/public-display.js +10 -3
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-sdk/package.json +2 -2
- package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/adapters.d.ts +19 -1
- package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/adapters.js +154 -28
- package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/build-info.json +2 -2
- package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/codex.d.ts +5 -0
- package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/codex.js +36 -0
- package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/kernel.d.ts +4 -0
- package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/kernel.js +84 -0
- package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/main.js +8 -7
- package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/manifest.json +33 -22
- package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/output.d.ts +1 -0
- package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/output.js +8 -4
- package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/playboard.js +21 -12
- package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/provider-launch.d.ts +28 -0
- package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/provider-launch.js +52 -0
- package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/providers.d.ts +182 -0
- package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/providers.js +34 -0
- package/node_modules/@mininglamp-oss/octo-runtime-cli/package.json +20 -20
- package/node_modules/@mininglamp-oss/octo-runtime-client/build-info.json +2 -2
- package/node_modules/@mininglamp-oss/octo-runtime-client/dist/client.js +2 -2
- package/node_modules/@mininglamp-oss/octo-runtime-client/package.json +5 -5
- package/node_modules/@mininglamp-oss/octo-runtime-client/schema/kernel-ipc.schema.json +3 -104
- package/node_modules/@mininglamp-oss/octo-runtime-client/schema/protocol.schema.json +166 -1870
- package/node_modules/@mininglamp-oss/octo-runtime-cross-service/package.json +1 -1
- package/node_modules/@mininglamp-oss/octo-runtime-executor-core/dist/index.d.ts +0 -2
- package/node_modules/@mininglamp-oss/octo-runtime-executor-core/dist/index.js +122 -65
- package/node_modules/@mininglamp-oss/octo-runtime-executor-core/dist/invoke-input.d.ts +2 -2
- package/node_modules/@mininglamp-oss/octo-runtime-executor-core/dist/invoke-input.js +13 -85
- package/node_modules/@mininglamp-oss/octo-runtime-executor-core/dist/model-output-silence.d.ts +21 -0
- package/node_modules/@mininglamp-oss/octo-runtime-executor-core/dist/model-output-silence.js +176 -0
- package/node_modules/@mininglamp-oss/octo-runtime-executor-core/dist/watchdog.d.ts +3 -2
- package/node_modules/@mininglamp-oss/octo-runtime-executor-core/dist/watchdog.js +8 -4
- package/node_modules/@mininglamp-oss/octo-runtime-executor-core/package.json +3 -3
- package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/index.d.ts +1 -1
- package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/index.js +1 -1
- package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/server.d.ts +5 -0
- package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/server.js +17 -20
- package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/package.json +5 -5
- package/node_modules/@mininglamp-oss/octo-runtime-host-sdk/package.json +4 -4
- package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/adapter-metadata.d.ts +1 -1
- package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/browser.d.ts +0 -2
- package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/browser.js +0 -2
- package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/context-catalog.d.ts +0 -1
- package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/context-catalog.js +3 -9
- package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/context-configuration.js +1 -8
- package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/context.d.ts +1 -5
- package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/context.js +3 -292
- package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/experience.js +7 -0
- package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/failure.d.ts +2 -0
- package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/failure.js +18 -13
- package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/generated/protocol-types.d.ts +90 -608
- package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/generated/protocol-types.js +32 -1
- package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/index.d.ts +7 -18
- package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/index.js +34 -189
- package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/invoke-input.d.ts +11 -22
- package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/invoke-input.js +38 -78
- package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/multimodal.js +6 -0
- package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/run-protocol.d.ts +2 -1
- package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/run-protocol.js +5 -40
- package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/service-processes.js +2 -1
- package/node_modules/@mininglamp-oss/octo-runtime-protocol/package.json +1 -1
- package/package.json +34 -37
- package/packages/octo-runtime-protocol/schema/kernel-ipc.schema.json +3 -104
- package/packages/octo-runtime-protocol/schema/protocol.schema.json +166 -1870
- package/dist/public/codex.d.ts +0 -1
- package/dist/public/codex.js +0 -1
- package/dist/public/dsh.d.ts +0 -2
- package/dist/public/dsh.js +0 -1
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-sdk/dist/actmode.d.ts +0 -5
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-sdk/dist/actmode.js +0 -8
- package/node_modules/@mininglamp-oss/octo-runtime-client/schema/context-configuration-fixtures.json +0 -1219
- package/node_modules/@mininglamp-oss/octo-runtime-client/schema/context-fixtures.json +0 -5988
- package/node_modules/@mininglamp-oss/octo-runtime-client/schema/kernel-client.behavior.json +0 -56
- package/node_modules/@mininglamp-oss/octo-runtime-client/schema/native-invoke-fixtures.json +0 -116
- package/node_modules/@mininglamp-oss/octo-runtime-client/schema/run-protocol-fixtures.json +0 -761
- package/node_modules/@mininglamp-oss/octo-runtime-client/schema/runtime-selection-fixtures.json +0 -663
- package/node_modules/@mininglamp-oss/octo-runtime-client/schema/session-name-fixtures.json +0 -191
- package/node_modules/@mininglamp-oss/octo-runtime-executor-core/dist/context.d.ts +0 -12
- package/node_modules/@mininglamp-oss/octo-runtime-executor-core/dist/context.js +0 -89
- package/node_modules/@mininglamp-oss/octo-runtime-executor-core/dist/execution-preparation.d.ts +0 -33
- package/node_modules/@mininglamp-oss/octo-runtime-executor-core/dist/execution-preparation.js +0 -93
- package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/actmode.d.ts +0 -4
- package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/actmode.js +0 -36
- package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/execution-plan.d.ts +0 -3
- package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/execution-plan.js +0 -80
- package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/model-context.d.ts +0 -3
- package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/model-context.js +0 -9
- package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/runtime-selection.d.ts +0 -3
- package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/runtime-selection.js +0 -68
- /package/node_modules/@mininglamp-oss/octo-runtime-client/{schema → fixtures}/kernel-ipc-fixtures.json +0 -0
- /package/packages/octo-runtime-protocol/{schema → test/fixtures}/kernel-ipc-fixtures.json +0 -0
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
import { constants } from "node:fs";
|
|
2
|
+
import { access, stat } from "node:fs/promises";
|
|
3
|
+
import { isAbsolute } from "node:path";
|
|
4
|
+
import { assertAgentEnv, assertApprovalMode, assertContextEnvs, assertContextMcp, assertRuntimeLimits, contextItem, CONTEXT_SCHEMA, DEFAULT_RUN_TIMEOUT_MS } from "@mininglamp-oss/octo-runtime-protocol";
|
|
5
|
+
/**
|
|
6
|
+
* 在 Adapter 消费本轮 AgentEnv 时,按 namespace/name 精确读取 bean 的 payload;不存在则返回 undefined。
|
|
7
|
+
* 公共与私有 bean 都可读取。私有名称、字段和类型由宿主与对应 Adapter 约定,无须公共 schema 注册。
|
|
8
|
+
* T 仅提供编译期类型提示,不做运行时校验;必填检查、默认值及 Provider 原生映射由消费方负责。
|
|
9
|
+
* 返回原 payload 引用,不复制或修改信封;调用方应只读使用,不写回默认值或跨调用保存配置。
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* const options = agentEnvItem<{ agentId: string }>(req.agentEnv, "adapter.my-adapter", "options");
|
|
13
|
+
* if (!options || typeof options.agentId !== "string" || !options.agentId.trim())
|
|
14
|
+
* throw new TypeError("MY_ADAPTER_AGENT_ID_REQUIRED");
|
|
15
|
+
*
|
|
16
|
+
* @see https://github.com/Mininglamp-OSS/octo-runtime/blob/main/docs/zh-CN/getting-started/sdk.md
|
|
17
|
+
* @see https://github.com/Mininglamp-OSS/octo-runtime/blob/main/docs/en/getting-started/sdk.md
|
|
18
|
+
*/
|
|
19
|
+
export function agentEnvItem(env, namespace, name) {
|
|
20
|
+
return contextItem(env, namespace, name)?.payload;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Adapter 读取公共 octo.execution/model bean 的 selection.id,取得本轮显式选择的 Provider 模型标识。
|
|
24
|
+
* 条目或 id 缺失时返回 undefined;不补默认模型、不查询模型目录,也不读取私有 options 中的同名字段。
|
|
25
|
+
* 本函数只读不改写 AgentEnv;字段类型、可用性检查及 Provider 原生参数映射仍由 Adapter 负责。
|
|
26
|
+
* 私有配置使用 agentEnvItem<T>(request.agentEnv, namespace, name),不扩展公共 model bean。
|
|
27
|
+
*
|
|
28
|
+
* @see https://github.com/Mininglamp-OSS/octo-runtime/blob/main/docs/zh-CN/getting-started/sdk.md
|
|
29
|
+
* @see https://github.com/Mininglamp-OSS/octo-runtime/blob/main/docs/en/getting-started/sdk.md
|
|
30
|
+
*/
|
|
31
|
+
export function invocationModel(request) {
|
|
32
|
+
return agentEnvItem(request.agentEnv, "octo.execution", "model")
|
|
33
|
+
?.selection?.id;
|
|
34
|
+
}
|
|
35
|
+
export function invocationEffort(request) {
|
|
36
|
+
return agentEnvItem(request.agentEnv, "octo.execution", "model")?.reasoning?.effort;
|
|
37
|
+
}
|
|
38
|
+
export function invocationWorkdir(request) {
|
|
39
|
+
return (agentEnvItem(request.agentEnv, "octo.execution", "workspace")?.path ?? "");
|
|
40
|
+
}
|
|
41
|
+
export function invocationApprovalMode(request) {
|
|
42
|
+
const mode = agentEnvItem(request.agentEnv, "octo.security", "approval_policy")
|
|
43
|
+
?.mode ?? "ask";
|
|
44
|
+
assertApprovalMode(mode);
|
|
45
|
+
return mode;
|
|
46
|
+
}
|
|
47
|
+
/** Harness 私有选项仍是原始 payload;不生成公共配置副本。 */
|
|
48
|
+
export function invocationOptions(request, adapterType) {
|
|
49
|
+
const type = adapterType ??
|
|
50
|
+
agentEnvItem(request.agentEnv, "octo.execution", "adapter")?.type;
|
|
51
|
+
return agentEnvItem(request.agentEnv, `adapter.${type}`, "options") ?? {};
|
|
52
|
+
}
|
|
53
|
+
const connections = new WeakMap();
|
|
54
|
+
/** 可信连接选项只绑定本次 Adapter 调用,不写回调用方信封。 */
|
|
55
|
+
export function bindInvocationConnection(request, options) {
|
|
56
|
+
if (options)
|
|
57
|
+
connections.set(request, { ...options });
|
|
58
|
+
else
|
|
59
|
+
connections.delete(request);
|
|
60
|
+
}
|
|
61
|
+
export function invocationProviderOptions(request, adapterType) {
|
|
62
|
+
return { ...invocationOptions(request, adapterType), ...connections.get(request) };
|
|
63
|
+
}
|
|
64
|
+
export function invocationOption(request, key, adapterType) {
|
|
65
|
+
const value = invocationProviderOptions(request, adapterType)[key];
|
|
66
|
+
if (value !== undefined && typeof value !== "string")
|
|
67
|
+
throw new TypeError(`ADAPTER_OPTION_INVALID: ${key}`);
|
|
68
|
+
return value;
|
|
69
|
+
}
|
|
70
|
+
export function invocationTimeoutSeconds(request, adapterType) {
|
|
71
|
+
const value = invocationOptions(request, adapterType).timeoutSeconds;
|
|
72
|
+
if (value !== undefined && (typeof value !== "number" || !Number.isFinite(value) || value <= 0))
|
|
73
|
+
throw new TypeError("ADAPTER_OPTION_INVALID: timeoutSeconds");
|
|
74
|
+
return value;
|
|
75
|
+
}
|
|
76
|
+
const LIMIT_NAMES = {
|
|
77
|
+
first_frame_timeout_ms: "firstFrameTimeoutMs",
|
|
78
|
+
model_idle_timeout_ms: "modelIdleTimeoutMs",
|
|
79
|
+
model_idle_warning_ms: "modelIdleWarningMs",
|
|
80
|
+
model_idle_policy: "modelIdlePolicy",
|
|
81
|
+
tool_timeout_ms: "toolTimeoutMs",
|
|
82
|
+
tool_wall_timeout_ms: "toolWallTimeoutMs",
|
|
83
|
+
run_timeout_ms: "runTimeoutMs",
|
|
84
|
+
cancel_grace_ms: "cancelGraceMs"
|
|
85
|
+
};
|
|
86
|
+
/** Adapter 解释预算,Core 仅按本地回调执行计时,不解析配置条目。 */
|
|
87
|
+
export function invocationRuntimeLimits(request) {
|
|
88
|
+
const payload = agentEnvItem(request.agentEnv, "octo.execution", "limits");
|
|
89
|
+
if (!payload)
|
|
90
|
+
return undefined;
|
|
91
|
+
const result = {};
|
|
92
|
+
for (const [key, value] of Object.entries(payload)) {
|
|
93
|
+
if (!Object.hasOwn(LIMIT_NAMES, key))
|
|
94
|
+
throw new TypeError("ADAPTER_LIMIT_UNSUPPORTED");
|
|
95
|
+
result[LIMIT_NAMES[key]] = value;
|
|
96
|
+
}
|
|
97
|
+
assertRuntimeLimits(result);
|
|
98
|
+
return result;
|
|
99
|
+
}
|
|
100
|
+
/** 每个 Harness 拥有自己的默认信封;不包含隐式 cwd、模型或业务材料。 */
|
|
101
|
+
export function defaultAgentEnv(type) {
|
|
102
|
+
return {
|
|
103
|
+
schema: CONTEXT_SCHEMA,
|
|
104
|
+
items: [
|
|
105
|
+
{ namespace: "octo.execution", name: "adapter", payload: { type } },
|
|
106
|
+
{ namespace: "octo.security", name: "approval_policy", payload: { mode: "ask" } },
|
|
107
|
+
{
|
|
108
|
+
namespace: "octo.execution",
|
|
109
|
+
name: "limits",
|
|
110
|
+
payload: { run_timeout_ms: DEFAULT_RUN_TIMEOUT_MS }
|
|
111
|
+
}
|
|
112
|
+
]
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
/** 调用方显式补缺省条目,保留已提交条目的顺序和值,返回独立副本。 */
|
|
116
|
+
export function withAgentEnvDefaults(submitted, defaults) {
|
|
117
|
+
assertAgentEnv(submitted);
|
|
118
|
+
assertAgentEnv(defaults);
|
|
119
|
+
const keys = new Set(submitted.items.map((item) => `${item.namespace}/${item.name}`));
|
|
120
|
+
const result = structuredClone({
|
|
121
|
+
schema: submitted.schema,
|
|
122
|
+
items: [
|
|
123
|
+
...submitted.items,
|
|
124
|
+
...defaults.items.filter((item) => !keys.has(`${item.namespace}/${item.name}`))
|
|
125
|
+
]
|
|
126
|
+
});
|
|
127
|
+
assertAgentEnv(result);
|
|
128
|
+
return result;
|
|
129
|
+
}
|
|
130
|
+
/** 调用方显式替换同名 bean;不解释 payload,不改变其他条目的相对顺序。 */
|
|
131
|
+
export function withAgentEnvItems(env, items) {
|
|
132
|
+
const base = env ?? { schema: CONTEXT_SCHEMA, items: [] };
|
|
133
|
+
assertAgentEnv(base);
|
|
134
|
+
// 先校验覆盖信封,避免 Map 将调用方重复键静默折叠。
|
|
135
|
+
assertAgentEnv({ schema: CONTEXT_SCHEMA, items });
|
|
136
|
+
const overrides = new Map(items.map((item) => [`${item.namespace}/${item.name}`, item]));
|
|
137
|
+
const merged = base.items.map((item) => {
|
|
138
|
+
const key = `${item.namespace}/${item.name}`;
|
|
139
|
+
const next = overrides.get(key) ?? item;
|
|
140
|
+
overrides.delete(key);
|
|
141
|
+
return next;
|
|
142
|
+
});
|
|
143
|
+
const result = structuredClone({
|
|
144
|
+
schema: CONTEXT_SCHEMA,
|
|
145
|
+
items: [...merged, ...overrides.values()]
|
|
146
|
+
});
|
|
147
|
+
assertAgentEnv(result);
|
|
148
|
+
return result;
|
|
149
|
+
}
|
|
150
|
+
/** 公共 bean 的消费校验;未消费的私有扩展不参与,也不需要中央注册。 */
|
|
151
|
+
export function assertAdapterAgentEnv(request) {
|
|
152
|
+
assertAgentEnv(request.agentEnv);
|
|
153
|
+
invocationApprovalMode(request);
|
|
154
|
+
invocationRuntimeLimits(request);
|
|
155
|
+
for (const item of request.agentEnv.items) {
|
|
156
|
+
if (item.namespace === "octo.security" && item.name === "approval_policy") {
|
|
157
|
+
assertFields(item.payload, ["mode"]);
|
|
158
|
+
assertApprovalMode(item.payload.mode);
|
|
159
|
+
}
|
|
160
|
+
if (item.namespace !== "octo.execution")
|
|
161
|
+
continue;
|
|
162
|
+
const value = item.payload;
|
|
163
|
+
if (item.name === "adapter") {
|
|
164
|
+
assertFields(value, ["type"]);
|
|
165
|
+
if (typeof value.type !== "string" || !value.type)
|
|
166
|
+
throw new TypeError("ADAPTER_TYPE_INVALID");
|
|
167
|
+
}
|
|
168
|
+
if (item.name === "workspace" &&
|
|
169
|
+
(Object.keys(value).some((k) => k !== "path") || typeof value.path !== "string"))
|
|
170
|
+
throw new TypeError("WORKDIR_INVALID");
|
|
171
|
+
if (item.name === "model") {
|
|
172
|
+
assertFields(value, ["selection", "reasoning"]);
|
|
173
|
+
if (!Object.keys(value).length)
|
|
174
|
+
throw new TypeError("CONTEXT_SCHEMA_INVALID: model");
|
|
175
|
+
for (const [field, property] of [
|
|
176
|
+
["selection", "id"],
|
|
177
|
+
["reasoning", "effort"]
|
|
178
|
+
]) {
|
|
179
|
+
const bean = value[field];
|
|
180
|
+
if (bean === undefined)
|
|
181
|
+
continue;
|
|
182
|
+
if (!bean || typeof bean !== "object" || Array.isArray(bean))
|
|
183
|
+
throw new TypeError("CONTEXT_SCHEMA_INVALID: model");
|
|
184
|
+
const setting = bean;
|
|
185
|
+
assertFields(setting, [property]);
|
|
186
|
+
if (typeof setting[property] !== "string" || !setting[property])
|
|
187
|
+
throw new TypeError("CONTEXT_SCHEMA_INVALID: model");
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
if (item.name === "envs")
|
|
191
|
+
assertContextEnvs(value);
|
|
192
|
+
if (item.name === "mcp")
|
|
193
|
+
assertContextMcp(value);
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
function assertFields(value, allowed) {
|
|
197
|
+
if (Object.keys(value).some((key) => !allowed.includes(key)))
|
|
198
|
+
throw new TypeError("CONTEXT_SCHEMA_INVALID");
|
|
199
|
+
}
|
|
200
|
+
/** 调用方准备目录;Adapter 在启动 Provider 前检查,不创建或替换路径。 */
|
|
201
|
+
export async function assertAdapterWorkdir(request, workspace = true) {
|
|
202
|
+
const path = invocationWorkdir(request);
|
|
203
|
+
if (!workspace)
|
|
204
|
+
return;
|
|
205
|
+
const messages = {
|
|
206
|
+
WORKDIR_REQUIRED: "A prepared working directory is required; create it and provide its absolute path.",
|
|
207
|
+
WORKDIR_INVALID: "Working directory must be an absolute path without NUL characters.",
|
|
208
|
+
WORKDIR_NOT_FOUND: "Working directory does not exist; create it before invoking Runtime.",
|
|
209
|
+
WORKDIR_NOT_DIRECTORY: "Working directory must point to an existing directory.",
|
|
210
|
+
WORKDIR_UNAVAILABLE: "Working directory is not accessible; check directory access permissions."
|
|
211
|
+
};
|
|
212
|
+
const fail = (code) => {
|
|
213
|
+
throw Object.assign(new TypeError(messages[code]), { code });
|
|
214
|
+
};
|
|
215
|
+
if (!path)
|
|
216
|
+
fail("WORKDIR_REQUIRED");
|
|
217
|
+
if (!isAbsolute(path) || path.includes("\0"))
|
|
218
|
+
fail("WORKDIR_INVALID");
|
|
219
|
+
try {
|
|
220
|
+
if (!(await stat(path)).isDirectory())
|
|
221
|
+
fail("WORKDIR_NOT_DIRECTORY");
|
|
222
|
+
await access(path, constants.X_OK);
|
|
223
|
+
}
|
|
224
|
+
catch (error) {
|
|
225
|
+
const code = error && typeof error === "object" && "code" in error ? String(error.code) : "";
|
|
226
|
+
if (code.startsWith("WORKDIR_"))
|
|
227
|
+
throw error;
|
|
228
|
+
fail(code === "ENOENT"
|
|
229
|
+
? "WORKDIR_NOT_FOUND"
|
|
230
|
+
: code === "ENOTDIR"
|
|
231
|
+
? "WORKDIR_NOT_DIRECTORY"
|
|
232
|
+
: "WORKDIR_UNAVAILABLE");
|
|
233
|
+
}
|
|
234
|
+
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { invocationApprovalMode } from "./agent-env.js";
|
|
1
2
|
import { randomUUID } from "node:crypto";
|
|
2
3
|
import { sanitizePublicValue } from "./public-display.js";
|
|
3
4
|
import { contextHash } from "@mininglamp-oss/octo-runtime-protocol";
|
|
@@ -24,7 +25,8 @@ export class AcpApprovalBridge {
|
|
|
24
25
|
requestPermission(params, providerExpiresAt) {
|
|
25
26
|
if (this.#closed || this.request.signal?.aborted)
|
|
26
27
|
return Promise.reject(new Error("APPROVAL_WAIT_UNAVAILABLE"));
|
|
27
|
-
const automatic = (this.options.effectiveApprovalMode ?? this.request
|
|
28
|
+
const automatic = (this.options.effectiveApprovalMode ?? invocationApprovalMode(this.request)) ===
|
|
29
|
+
"full_access";
|
|
28
30
|
const options = Array.isArray(params.options) ? params.options.filter(isObject) : [];
|
|
29
31
|
const option = (kind) => {
|
|
30
32
|
const candidate = options.find((value) => value.kind === kind);
|
|
@@ -118,7 +120,10 @@ export class AcpApprovalBridge {
|
|
|
118
120
|
expiresAt: new Date(expiresAt).toISOString(),
|
|
119
121
|
request: {
|
|
120
122
|
schema: "octo.approval-request/v1",
|
|
121
|
-
policy: {
|
|
123
|
+
policy: {
|
|
124
|
+
mode: invocationApprovalMode(this.request),
|
|
125
|
+
hash: contextHash(this.request.agentEnv)
|
|
126
|
+
},
|
|
122
127
|
operation: {
|
|
123
128
|
kind: "tool_execution",
|
|
124
129
|
summary: typeof tool.title === "string" && tool.title
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { assertContextEnvs, contextItem } from "@mininglamp-oss/octo-runtime-protocol";
|
|
2
2
|
/** Read only the frozen execution context; never expose its values as model input. */
|
|
3
3
|
export function invocationEnvs(request) {
|
|
4
|
-
const envs = contextItem(request.
|
|
4
|
+
const envs = contextItem(request.agentEnv, "octo.execution", "envs")?.payload ?? {
|
|
5
5
|
env_variables: []
|
|
6
6
|
};
|
|
7
7
|
assertContextEnvs(envs);
|
|
@@ -9,7 +9,11 @@ export interface AdapterScopeCleanup {
|
|
|
9
9
|
unresolvedServiceIds: readonly string[];
|
|
10
10
|
failedCleanupServiceIds: readonly string[];
|
|
11
11
|
}
|
|
12
|
-
/**
|
|
12
|
+
/**
|
|
13
|
+
* Core 每次注册独占本地调用作用域;构造不得启动进程,关闭后不再接纳。
|
|
14
|
+
* close 回收本 scope 的调用/订阅/租约,不隐含获得宿主注入 Engine 或共享连接的销毁权。
|
|
15
|
+
* Adapter 构造方法和参数由实现者决定;统一的是注册后的执行合同。
|
|
16
|
+
*/
|
|
13
17
|
export interface AdapterExecutionScope {
|
|
14
18
|
invoke(request: InvokeRequest, context?: AdapterInvocationContext): AsyncIterable<AdapterOutput>;
|
|
15
19
|
respondInteraction?(invocationId: string, response: InteractionResponse): Promise<void>;
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import type { AdapterInvocationContext } from "./activity.js";
|
|
2
2
|
import type { CreateAdapterExecutionScope } from "./execution-scope.js";
|
|
3
3
|
export type { AdapterExecutionScope, AdapterScopeCleanup, CreateAdapterExecutionScope, ServiceProcessSnapshot } from "./execution-scope.js";
|
|
4
|
+
export * from "./agent-env.js";
|
|
5
|
+
export { snapshotProviderLaunch, assertProviderCommand, type ProviderLaunch } from "./provider-launch.js";
|
|
4
6
|
import { type ReasoningLevelMap } from "./reasoning.js";
|
|
5
7
|
export type { AdapterInvocationContext, ProviderActivity } from "./activity.js";
|
|
6
8
|
export { invocationEnvironment, invocationEnvs, mergeProcessEnvironment, processEnvironmentValue } from "./environment.js";
|
|
7
9
|
export { invocationMcpServers, expandMcpValue, assertMcpOptions } from "./mcp.js";
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
export { freshFallbackInputText, initialControlInstructions, hasImageInput, providerInputParts, providerInputText } from "@mininglamp-oss/octo-runtime-protocol";
|
|
10
|
+
import { type CanonicalEvent, type AdapterProtocolSupport, type HostControl, type NativeHostFrame, type InvokeRequest, type AgentEnv, type InteractionResponse, type NativeInteractionResponse, type StreamLimitPolicy } from "@mininglamp-oss/octo-runtime-protocol";
|
|
11
|
+
export { freshFallbackInputText, hasImageInput, providerInputParts, providerInputText } from "@mininglamp-oss/octo-runtime-protocol";
|
|
11
12
|
export type { CanonicalEvent, InvokeRequest, MessageChannel, MessageExposure, MessageProvenance } from "@mininglamp-oss/octo-runtime-protocol";
|
|
12
13
|
export { acpToolTerminalStatus, normalizeAcpToolUpdate } from "./acp-tool.js";
|
|
13
14
|
export { AcpTurnNormalizer } from "./acp-turn.js";
|
|
@@ -29,7 +30,6 @@ export interface AdapterMetadata {
|
|
|
29
30
|
/** 仅编写输入可省略;这是执行时消费的协议描述,不能作为业务能力标签。 */
|
|
30
31
|
protocolSupport?: AdapterProtocolSupport;
|
|
31
32
|
type: string;
|
|
32
|
-
agentSources: ("preset" | "provisioned")[];
|
|
33
33
|
processModel?: string;
|
|
34
34
|
transport?: string;
|
|
35
35
|
}
|
|
@@ -47,14 +47,16 @@ export interface ProbeResult {
|
|
|
47
47
|
/** 工厂的编写输入;直接交给 Core 注册时须满足完整的 HostedAdapter 合同。 */
|
|
48
48
|
export interface Adapter<TOutput extends AdapterOutput = AdapterOutput> {
|
|
49
49
|
metadata: AdapterMetadata;
|
|
50
|
+
defaultAgentEnv?: AgentEnv;
|
|
51
|
+
respondInteraction?(invocationId: string, response: InteractionResponse): Promise<void>;
|
|
52
|
+
respondNative?(invocationId: string, response: NativeInteractionResponse): Promise<void>;
|
|
50
53
|
createExecutionScope?: CreateAdapterExecutionScope;
|
|
51
54
|
probe?: (options?: AdapterProbeOptions) => Promise<ProbeResult>;
|
|
52
55
|
/**
|
|
53
|
-
*
|
|
54
|
-
*
|
|
55
|
-
* Core
|
|
56
|
-
*
|
|
57
|
-
* should yield a failure terminal after confirmed cleanup for expected execution failures.
|
|
56
|
+
* 消费本轮请求并输出 Provider 事件,可通过 context 报告 watchdog 进度。
|
|
57
|
+
* Core 在受理前核对传输模式,配置校验由 Adapter 负责,拒绝时迭代可抛错。
|
|
58
|
+
* 受理后 Core 将异常转换为失败事件,并独立核实资源回收;预期执行失败应在
|
|
59
|
+
* Adapter 确认清理完成后输出失败终态,不能把执行终态当成清理完成的证明。
|
|
58
60
|
*/
|
|
59
61
|
invoke(request: InvokeRequest, context?: AdapterInvocationContext): AsyncIterable<TOutput>;
|
|
60
62
|
}
|
|
@@ -62,7 +64,8 @@ export interface Adapter<TOutput extends AdapterOutput = AdapterOutput> {
|
|
|
62
64
|
* 工厂输出必须表达已补齐的协议声明,供宿主直接注册;保留作者扩展的字段和方法。
|
|
63
65
|
* 禁止与允许省略字段的编写输入混用,否则会把注册前的类型错误推迟到运行时。
|
|
64
66
|
*/
|
|
65
|
-
export type DefinedAdapter<TAdapter extends Adapter = Adapter> = Readonly<Omit<TAdapter, "metadata"> & {
|
|
67
|
+
export type DefinedAdapter<TAdapter extends Adapter = Adapter> = Readonly<Omit<TAdapter, "metadata" | "defaultAgentEnv"> & {
|
|
68
|
+
readonly defaultAgentEnv: AgentEnv;
|
|
66
69
|
metadata: Omit<TAdapter["metadata"], "protocolSupport"> & {
|
|
67
70
|
protocolSupport: AdapterProtocolSupport;
|
|
68
71
|
};
|
|
@@ -73,6 +76,13 @@ export type DriverFrame = Pick<NativeHostFrame, "kind" | "messageKind" | "payloa
|
|
|
73
76
|
control: HostControl;
|
|
74
77
|
};
|
|
75
78
|
export type AdapterOutput = CanonicalEvent | DriverFrame;
|
|
79
|
+
/**
|
|
80
|
+
* 执行尚未启动 Provider 的纯配置/目录校验;返回后才能开始探针或执行。
|
|
81
|
+
* 回调不得创建 Provider 资源。失败证据只绑定本次 context,供 Core 核对清理责任。
|
|
82
|
+
*/
|
|
83
|
+
export declare function runAdapterPreparation(context: AdapterInvocationContext | undefined, prepare: () => void | Promise<void>): Promise<void>;
|
|
84
|
+
/** SDK 尚未调用 Provider 的准备失败;Core 可确认此路径没有 Provider 资源待回收。 */
|
|
85
|
+
export declare function isAdapterPreparationFailure(error: unknown, context: AdapterInvocationContext): boolean;
|
|
76
86
|
/** The fully materialized subprocess contract produced immediately before spawn. */
|
|
77
87
|
export interface CommandSpec {
|
|
78
88
|
command: string;
|
|
@@ -141,11 +151,12 @@ export declare function parseJsonLine(line: string): Record<string, unknown> | n
|
|
|
141
151
|
*/
|
|
142
152
|
export declare function createJsonCliAdapter<TNative = Record<string, unknown>>(options: JsonCliAdapterOptions<TNative>): DefinedAdapter<Adapter<CanonicalEvent>>;
|
|
143
153
|
/**
|
|
144
|
-
*
|
|
145
|
-
*
|
|
146
|
-
*
|
|
154
|
+
* 探测宿主已绑定的绝对启动链;不搜索安装,版本参数接在宿主前缀参数之后。
|
|
155
|
+
* 返回目标可执行性和可选版本;版本命令失败不等于目标不可用,版本门禁由 Provider 决定。
|
|
156
|
+
* 文件缺失与权限不足分别报告,失败不选择其他安装,也不解释前缀参数中的入口。
|
|
147
157
|
*/
|
|
148
|
-
export declare function probeCommand(command: string, { env, cwd }?: {
|
|
158
|
+
export declare function probeCommand(command: string, { env, cwd, args }?: {
|
|
149
159
|
env?: NodeJS.ProcessEnv;
|
|
150
160
|
cwd?: string;
|
|
161
|
+
args?: readonly string[];
|
|
151
162
|
}): Promise<ProbeResult>;
|
|
@@ -1,19 +1,22 @@
|
|
|
1
|
+
import { invocationEffort, invocationWorkdir } from "./agent-env.js";
|
|
1
2
|
import { execFile, spawn } from "node:child_process";
|
|
2
3
|
import { constants } from "node:fs";
|
|
3
4
|
import { access, stat } from "node:fs/promises";
|
|
4
|
-
import {
|
|
5
|
+
import { resolve } from "node:path";
|
|
5
6
|
import { createInterface } from "node:readline";
|
|
6
7
|
import { promisify } from "node:util";
|
|
7
|
-
import { invocationEnvironment, mergeProcessEnvironment
|
|
8
|
+
import { invocationEnvironment, mergeProcessEnvironment } from "./environment.js";
|
|
8
9
|
import { createProcessCleanup } from "./process-cleanup.js";
|
|
9
|
-
import {
|
|
10
|
+
import { defaultAgentEnv, assertAdapterAgentEnv, assertAdapterWorkdir, bindInvocationConnection, invocationApprovalMode, invocationRuntimeLimits } from "./agent-env.js";
|
|
11
|
+
export * from "./agent-env.js";
|
|
12
|
+
import { assertProviderCommand } from "./provider-launch.js";
|
|
13
|
+
export { snapshotProviderLaunch, assertProviderCommand } from "./provider-launch.js";
|
|
10
14
|
import { watchLineLimit } from "./line-limit.js";
|
|
11
15
|
import { mapReasoningEffort, reasoningLevelMap } from "./reasoning.js";
|
|
12
16
|
export { invocationEnvironment, invocationEnvs, mergeProcessEnvironment, processEnvironmentValue } from "./environment.js";
|
|
13
17
|
export { invocationMcpServers, expandMcpValue, assertMcpOptions } from "./mcp.js";
|
|
14
|
-
export { actmodeEvidence } from "./actmode.js";
|
|
15
18
|
import { DEFAULT_STREAM_LIMIT_POLICY, isTerminal, assertProtocolSupport } from "@mininglamp-oss/octo-runtime-protocol";
|
|
16
|
-
export { freshFallbackInputText,
|
|
19
|
+
export { freshFallbackInputText, hasImageInput, providerInputParts, providerInputText } from "@mininglamp-oss/octo-runtime-protocol";
|
|
17
20
|
export { acpToolTerminalStatus, normalizeAcpToolUpdate } from "./acp-tool.js";
|
|
18
21
|
export { AcpTurnNormalizer } from "./acp-turn.js";
|
|
19
22
|
export { AcpApprovalBridge } from "./approval.js";
|
|
@@ -25,6 +28,34 @@ export { RuntimeLogging, assertRuntimeLogging, noopRuntimeLog } from "./runtime-
|
|
|
25
28
|
export { kernelStatusRecord } from "./service-status.js";
|
|
26
29
|
export { sanitizePublicValue, sanitizeDiagnosticBody } from "./public-display.js";
|
|
27
30
|
export { DEFAULT_REASONING_LEVEL_MAPS, OMNI_REASONING_LEVELS, mapReasoningEffort, reasoningLevelMap } from "./reasoning.js";
|
|
31
|
+
const preparationFailures = new WeakMap();
|
|
32
|
+
/**
|
|
33
|
+
* 执行尚未启动 Provider 的纯配置/目录校验;返回后才能开始探针或执行。
|
|
34
|
+
* 回调不得创建 Provider 资源。失败证据只绑定本次 context,供 Core 核对清理责任。
|
|
35
|
+
*/
|
|
36
|
+
export async function runAdapterPreparation(context, prepare) {
|
|
37
|
+
try {
|
|
38
|
+
await prepare();
|
|
39
|
+
}
|
|
40
|
+
catch (error) {
|
|
41
|
+
if (context && error !== null && typeof error === "object") {
|
|
42
|
+
const contexts = preparationFailures.get(error) ?? new WeakSet();
|
|
43
|
+
contexts.add(context);
|
|
44
|
+
preparationFailures.set(error, contexts);
|
|
45
|
+
}
|
|
46
|
+
throw error;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
/** SDK 尚未调用 Provider 的准备失败;Core 可确认此路径没有 Provider 资源待回收。 */
|
|
50
|
+
export function isAdapterPreparationFailure(error, context) {
|
|
51
|
+
if (error === null || typeof error !== "object")
|
|
52
|
+
return false;
|
|
53
|
+
const contexts = preparationFailures.get(error);
|
|
54
|
+
if (!contexts?.has(context))
|
|
55
|
+
return false;
|
|
56
|
+
contexts.delete(context);
|
|
57
|
+
return true;
|
|
58
|
+
}
|
|
28
59
|
/**
|
|
29
60
|
* 接收编写输入并返回可注册的 Adapter,省略协议时仅补 canonical-only 声明。
|
|
30
61
|
* 返回类型必须保留字段必有的保证;不得根据缺省声明推断 native 支持。
|
|
@@ -42,21 +73,41 @@ export function defineAdapter(adapter, levels = reasoningLevelMap(adapter.metada
|
|
|
42
73
|
modes: ["canonical"],
|
|
43
74
|
nativeMethods: []
|
|
44
75
|
};
|
|
76
|
+
const defaults = structuredClone(adapter.defaultAgentEnv ?? defaultAgentEnv(metadata.type));
|
|
45
77
|
return Object.freeze({
|
|
46
78
|
...adapter,
|
|
79
|
+
get defaultAgentEnv() {
|
|
80
|
+
return structuredClone(defaults);
|
|
81
|
+
},
|
|
47
82
|
metadata: {
|
|
48
83
|
...metadata,
|
|
49
84
|
protocolSupport
|
|
50
85
|
},
|
|
51
86
|
async *invoke(request, context) {
|
|
52
|
-
|
|
53
|
-
|
|
87
|
+
// 可信连接归本次调用;同一低层请求被并发复用时也不能相互覆盖。
|
|
88
|
+
if (context?.providerOptions)
|
|
89
|
+
request = { ...request };
|
|
90
|
+
bindInvocationConnection(request, context?.providerOptions);
|
|
91
|
+
let requested;
|
|
92
|
+
let native;
|
|
93
|
+
await runAdapterPreparation(context, async () => {
|
|
94
|
+
assertAdapterAgentEnv(request);
|
|
95
|
+
context?.configureRuntimeLimits?.(invocationRuntimeLimits(request));
|
|
96
|
+
if (invocationApprovalMode(request) !== "full_access" &&
|
|
97
|
+
(context?.protocolMode === "native"
|
|
98
|
+
? !adapter.respondNative
|
|
99
|
+
: !adapter.respondInteraction))
|
|
100
|
+
throw new Error(`APPROVAL_MODE_UNSUPPORTED: ${metadata.type} does not implement execution-time approval responses`);
|
|
101
|
+
await assertAdapterWorkdir(request, metadata.workspace !== false);
|
|
102
|
+
assertProtocolSupport(protocolSupport, {
|
|
103
|
+
protocolMode: context?.protocolMode ?? "canonical"
|
|
104
|
+
});
|
|
105
|
+
const mcp = request.agentEnv.items.find((item) => item.namespace === "octo.execution" && item.name === "mcp");
|
|
106
|
+
if (mcp && Object.keys(mcp.payload.mcpServers).length && !adapter.metadata.mcp)
|
|
107
|
+
throw new Error(`MCP_UNSUPPORTED: ${adapter.metadata.type}`);
|
|
108
|
+
requested = invocationEffort(request);
|
|
109
|
+
native = mapReasoningEffort(adapter.metadata.type, requested, levels);
|
|
54
110
|
});
|
|
55
|
-
const mcp = request.context.items.find((item) => item.namespace === "octo.execution" && item.name === "mcp");
|
|
56
|
-
if (mcp && Object.keys(mcp.payload.mcpServers).length && !adapter.metadata.mcp)
|
|
57
|
-
throw new Error(`MCP_UNSUPPORTED: ${adapter.metadata.type}`);
|
|
58
|
-
const requested = request.agentConfig.effort;
|
|
59
|
-
const native = mapReasoningEffort(adapter.metadata.type, requested, levels);
|
|
60
111
|
if (requested !== undefined && context?.protocolMode !== "native") {
|
|
61
112
|
if (native === undefined || native !== requested)
|
|
62
113
|
yield {
|
|
@@ -92,9 +143,9 @@ export function defineAdapter(adapter, levels = reasoningLevelMap(adapter.metada
|
|
|
92
143
|
*/
|
|
93
144
|
export async function* spawnJsonLines(options) {
|
|
94
145
|
const { command, args = [], cwd, env, input, signal, parseLine, onInputWritten } = options;
|
|
95
|
-
|
|
96
|
-
const
|
|
97
|
-
const child = spawn(
|
|
146
|
+
assertProviderCommand(command);
|
|
147
|
+
const processEnv = mergeProcessEnvironment(env ?? {});
|
|
148
|
+
const child = spawn(command, args, {
|
|
98
149
|
cwd,
|
|
99
150
|
env: processEnv,
|
|
100
151
|
stdio: ["pipe", "pipe", "pipe"],
|
|
@@ -241,8 +292,8 @@ export function createJsonCliAdapter(options) {
|
|
|
241
292
|
};
|
|
242
293
|
for await (const native of spawnJsonLines({
|
|
243
294
|
...spec,
|
|
244
|
-
cwd: spec.cwd ?? request
|
|
245
|
-
env: invocationEnvironment(request, spec.env),
|
|
295
|
+
cwd: spec.cwd ?? invocationWorkdir(request),
|
|
296
|
+
env: invocationEnvironment(request, spec.env, {}),
|
|
246
297
|
signal: request.signal,
|
|
247
298
|
rawMessageMaxBytes: context?.streamLimits?.rawMessageMaxBytes,
|
|
248
299
|
parseLine: parseJsonLine
|
|
@@ -271,51 +322,53 @@ export function createJsonCliAdapter(options) {
|
|
|
271
322
|
}, options.reasoningLevels);
|
|
272
323
|
}
|
|
273
324
|
/**
|
|
274
|
-
*
|
|
275
|
-
*
|
|
276
|
-
*
|
|
325
|
+
* 探测宿主已绑定的绝对启动链;不搜索安装,版本参数接在宿主前缀参数之后。
|
|
326
|
+
* 返回目标可执行性和可选版本;版本命令失败不等于目标不可用,版本门禁由 Provider 决定。
|
|
327
|
+
* 文件缺失与权限不足分别报告,失败不选择其他安装,也不解释前缀参数中的入口。
|
|
277
328
|
*/
|
|
278
|
-
export async function probeCommand(command, { env =
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
]
|
|
287
|
-
: [""];
|
|
288
|
-
return extensions.map((extension) => resolve(directory, command + extension));
|
|
289
|
-
});
|
|
290
|
-
for (const candidate of candidates) {
|
|
329
|
+
export async function probeCommand(command, { env = {}, cwd, args = [] } = {}) {
|
|
330
|
+
assertProviderCommand(command);
|
|
331
|
+
const candidate = command;
|
|
332
|
+
try {
|
|
333
|
+
await access(candidate, constants.X_OK);
|
|
334
|
+
if (!(await stat(candidate)).isFile())
|
|
335
|
+
return { available: false, command, reason: "invalid_executable" };
|
|
336
|
+
let version = null;
|
|
291
337
|
try {
|
|
292
|
-
await
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
windowsHide: true
|
|
304
|
-
});
|
|
305
|
-
const output = stdout.trim();
|
|
306
|
-
// Keep a version label, not arbitrary CLI banners or diagnostics.
|
|
307
|
-
version =
|
|
308
|
-
output.match(/(?:^|\s)v?(\d+\.\d+(?:\.\d+)?(?:[-+][A-Za-z0-9.-]+)?)(?=\s|$)/)?.[1] ??
|
|
309
|
-
null;
|
|
310
|
-
}
|
|
311
|
-
catch {
|
|
312
|
-
// Executable availability does not imply support for --version.
|
|
313
|
-
}
|
|
314
|
-
return { available: true, command: resolve(candidate), version };
|
|
338
|
+
const { stdout } = await promisify(execFile)(candidate, [...args, "--version"], {
|
|
339
|
+
env,
|
|
340
|
+
cwd,
|
|
341
|
+
timeout: 2_000,
|
|
342
|
+
maxBuffer: 4096,
|
|
343
|
+
windowsHide: true
|
|
344
|
+
});
|
|
345
|
+
const output = stdout.trim();
|
|
346
|
+
// Keep a version label, not arbitrary CLI banners or diagnostics.
|
|
347
|
+
version =
|
|
348
|
+
output.match(/(?:^|\s)v?(\d+\.\d+(?:\.\d+)?(?:[-+][A-Za-z0-9.-]+)?)(?=\s|$)/)?.[1] ?? null;
|
|
315
349
|
}
|
|
316
|
-
catch {
|
|
317
|
-
|
|
350
|
+
catch (error) {
|
|
351
|
+
const { code, syscall } = error;
|
|
352
|
+
// spawn 的系统错误表明目标不能启动;非零退出、超时或输出过大只使版本未知。
|
|
353
|
+
if (syscall?.startsWith("spawn"))
|
|
354
|
+
return {
|
|
355
|
+
available: false,
|
|
356
|
+
command,
|
|
357
|
+
reason: code === "EACCES" || code === "EPERM"
|
|
358
|
+
? "permission_denied"
|
|
359
|
+
: code === "ENOENT" || code === "ENOTDIR"
|
|
360
|
+
? "command_not_found"
|
|
361
|
+
: "command_launch_failed"
|
|
362
|
+
};
|
|
318
363
|
}
|
|
364
|
+
return { available: true, command: resolve(candidate), version };
|
|
365
|
+
}
|
|
366
|
+
catch (error) {
|
|
367
|
+
const code = error.code;
|
|
368
|
+
return {
|
|
369
|
+
available: false,
|
|
370
|
+
command,
|
|
371
|
+
reason: code === "EACCES" || code === "EPERM" ? "permission_denied" : "command_not_found"
|
|
372
|
+
};
|
|
319
373
|
}
|
|
320
|
-
return { available: false, command, reason: "command_not_found" };
|
|
321
374
|
}
|
|
@@ -12,7 +12,7 @@ export function expandMcpValue(value, env, path) {
|
|
|
12
12
|
});
|
|
13
13
|
}
|
|
14
14
|
export function invocationMcpServers(request, env = invocationEnvironment(request)) {
|
|
15
|
-
const payload = contextItem(request.
|
|
15
|
+
const payload = contextItem(request.agentEnv, "octo.execution", "mcp")?.payload ?? {
|
|
16
16
|
mcpServers: {}
|
|
17
17
|
};
|
|
18
18
|
assertContextMcp(payload);
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import { type ProviderLaunch } from "./provider-launch.js";
|
|
1
2
|
/**
|
|
2
|
-
*
|
|
3
|
+
* 仅由宿主在装配时解析 Windows npm 包装器;Adapter 和 transport 不调用此函数。
|
|
3
4
|
* JS 入口交给 Node,原生入口直接执行;argv 独立传递,未知 batch 沿原路径报错。
|
|
4
5
|
* 返回启动命令和参数;ChildProcess、管道及清理仍由调用方负责。
|
|
5
6
|
*/
|
|
@@ -10,3 +11,12 @@ export declare function resolveProcessLaunch(command: string, args: readonly str
|
|
|
10
11
|
command: string;
|
|
11
12
|
args: readonly string[];
|
|
12
13
|
};
|
|
14
|
+
/**
|
|
15
|
+
* 仅供宿主装配调用:选择一个安装并解析 npm/Node 启动链,返回可注入快照。
|
|
16
|
+
* 首个已有候选损坏时立即失败,不换安装;不校验协议版本、不安装或启动程序。
|
|
17
|
+
*/
|
|
18
|
+
export declare function resolveHostProviderLaunch(command: string, { env, cwd, args }: {
|
|
19
|
+
env: NodeJS.ProcessEnv;
|
|
20
|
+
cwd: string;
|
|
21
|
+
args?: readonly string[];
|
|
22
|
+
}): Required<ProviderLaunch>;
|