@mininglamp-oss/octo-runtime 1.1.12 → 1.1.13
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 +153 -23
- 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 +1 -1
- 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 +15 -14
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-acp/dist/index.js +24 -28
- 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 +22 -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/index.d.ts +14 -68
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-claude-code/dist/index.js +60 -43
- 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 +29 -18
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-codebuddy/package.json +4 -4
- 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 +32 -26
- 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 +104 -216
- 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/index.d.ts +4 -2
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-dsh/dist/index.js +12 -14
- 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 -14
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-grok-build/dist/adapter.js +23 -30
- 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 +48 -26
- 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 +16 -14
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-hermes/dist/index.js +15 -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 +16 -14
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-kimi-code/dist/index.js +14 -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 +16 -14
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-mcode/dist/index.js +15 -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 -3
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-openclaw/dist/index.js +27 -29
- 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 +109 -178
- 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 +16 -14
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-qodercli/dist/index.js +15 -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 +16 -14
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-qoderclicn/dist/index.js +15 -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 +49 -0
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-sdk/dist/agent-env.js +256 -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 -12
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-sdk/dist/index.js +116 -58
- 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 +153 -23
- 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 +173 -1295
- 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 +26 -54
- 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/watchdog.d.ts +3 -1
- package/node_modules/@mininglamp-oss/octo-runtime-executor-core/dist/watchdog.js +5 -0
- 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/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 -5
- 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 -2
- package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/context.js +3 -267
- 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 +17 -3
- package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/generated/protocol-types.d.ts +102 -396
- 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 +6 -15
- package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/index.js +33 -178
- 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 -28
- 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 +173 -1295
- 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-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/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-client/{schema → fixtures}/kernel-ipc-fixtures.json +0 -0
- /package/packages/octo-runtime-protocol/{schema → test/fixtures}/kernel-ipc-fixtures.json +0 -0
|
@@ -18,7 +18,7 @@ export interface OpenClawGatewayInvocation {
|
|
|
18
18
|
createParams: JsonRecord;
|
|
19
19
|
agentParams: JsonRecord;
|
|
20
20
|
}
|
|
21
|
-
/**
|
|
21
|
+
/** 应用在调用前组装正文;Adapter 不添加原生 system prompt 或业务前缀。 */
|
|
22
22
|
export declare function composeOpenClawPrompt(req: InvokeRequest): string;
|
|
23
23
|
export declare function buildOpenClawGatewayInvocation(req: InvokeRequest): OpenClawGatewayInvocation;
|
|
24
24
|
export interface OpenClawGatewayClientLike {
|
|
@@ -37,6 +37,7 @@ export declare function createOpenClawAdapter({ clientFactory, log }?: {
|
|
|
37
37
|
clientFactory?: GatewayClientFactory;
|
|
38
38
|
log?: RuntimeLog;
|
|
39
39
|
}): Readonly<Omit<{
|
|
40
|
+
defaultAgentEnv: import("@mininglamp-oss/octo-runtime-protocol").ContextEnvelope;
|
|
40
41
|
metadata: {
|
|
41
42
|
type: string;
|
|
42
43
|
workspace: false;
|
|
@@ -55,7 +56,8 @@ export declare function createOpenClawAdapter({ clientFactory, log }?: {
|
|
|
55
56
|
}>;
|
|
56
57
|
respondInteraction(invocationId: string, response: InteractionResponse): Promise<void>;
|
|
57
58
|
invoke(req: InvokeRequest, context?: AdapterInvocationContext): AsyncGenerator<CanonicalEvent>;
|
|
58
|
-
}, "metadata"> & {
|
|
59
|
+
}, "metadata" | "defaultAgentEnv"> & {
|
|
60
|
+
readonly defaultAgentEnv: import("@mininglamp-oss/octo-runtime-protocol").AgentEnv;
|
|
59
61
|
metadata: Omit<{
|
|
60
62
|
type: string;
|
|
61
63
|
workspace: false;
|
|
@@ -70,6 +72,7 @@ export { loadLocalOpenClawGateway, configureOpenClawConnection, readOpenClawConn
|
|
|
70
72
|
export { OpenClawGatewayClient, createOpenClawDeviceIdentity, type OpenClawDeviceIdentity, type OpenClawGatewayEvent, type OpenClawGatewayOptions } from "./gateway.js";
|
|
71
73
|
export { OpenClawTranscriptNormalizer, normalizeOpenClawFrame, tryParseOpenClawEvent, tryParseOpenClawFinalBlob, tryParseOpenClawTranscriptLine } from "./parser.js";
|
|
72
74
|
export declare const openclawAdapter: Readonly<Omit<{
|
|
75
|
+
defaultAgentEnv: import("@mininglamp-oss/octo-runtime-protocol").ContextEnvelope;
|
|
73
76
|
metadata: {
|
|
74
77
|
type: string;
|
|
75
78
|
workspace: false;
|
|
@@ -88,7 +91,8 @@ export declare const openclawAdapter: Readonly<Omit<{
|
|
|
88
91
|
}>;
|
|
89
92
|
respondInteraction(invocationId: string, response: InteractionResponse): Promise<void>;
|
|
90
93
|
invoke(req: InvokeRequest, context?: AdapterInvocationContext): AsyncGenerator<CanonicalEvent>;
|
|
91
|
-
}, "metadata"> & {
|
|
94
|
+
}, "metadata" | "defaultAgentEnv"> & {
|
|
95
|
+
readonly defaultAgentEnv: import("@mininglamp-oss/octo-runtime-protocol").AgentEnv;
|
|
92
96
|
metadata: Omit<{
|
|
93
97
|
type: string;
|
|
94
98
|
workspace: false;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { invocationProviderOptions, invocationTimeoutSeconds, invocationModel, invocationEffort, invocationApprovalMode, bindInvocationConnection, defaultAgentEnv, withAgentEnvItems } from "@mininglamp-oss/octo-runtime-adapter-sdk";
|
|
2
|
+
import { hasImageInput, AcpApprovalBridge, DriverQueue, defineAdapter, invocationEnvs, mapReasoningEffort, providerInputText } from "@mininglamp-oss/octo-runtime-adapter-sdk";
|
|
2
3
|
import { canonicalTerminalStatus } from "@mininglamp-oss/octo-runtime-protocol";
|
|
3
4
|
import { randomUUID } from "node:crypto";
|
|
4
5
|
import { OpenClawGatewayClient } from "./gateway.js";
|
|
@@ -23,7 +24,7 @@ function finiteNumber(value) {
|
|
|
23
24
|
return typeof value === "number" && Number.isFinite(value) ? value : undefined;
|
|
24
25
|
}
|
|
25
26
|
function option(req, key) {
|
|
26
|
-
return nonEmptyString(req
|
|
27
|
+
return nonEmptyString(invocationProviderOptions(req, "openclaw")?.[key]);
|
|
27
28
|
}
|
|
28
29
|
function requiredOption(req, key) {
|
|
29
30
|
const value = option(req, key);
|
|
@@ -31,7 +32,7 @@ function requiredOption(req, key) {
|
|
|
31
32
|
throw new Error(`OpenClaw adapter is not configured: missing ${key}`);
|
|
32
33
|
return value;
|
|
33
34
|
}
|
|
34
|
-
/**
|
|
35
|
+
/** 应用在调用前组装正文;Adapter 不添加原生 system prompt 或业务前缀。 */
|
|
35
36
|
export function composeOpenClawPrompt(req) {
|
|
36
37
|
return providerInputText(req);
|
|
37
38
|
}
|
|
@@ -48,9 +49,9 @@ export function buildOpenClawGatewayInvocation(req) {
|
|
|
48
49
|
publicKey: requiredOption(req, OPENCLAW_PROVIDER_OPTIONS.publicKey),
|
|
49
50
|
privateKey: requiredOption(req, OPENCLAW_PROVIDER_OPTIONS.privateKey)
|
|
50
51
|
};
|
|
51
|
-
const agentId = req.
|
|
52
|
-
if (
|
|
53
|
-
throw new
|
|
52
|
+
const agentId = invocationProviderOptions(req, "openclaw").agentId ?? "main";
|
|
53
|
+
if (typeof agentId !== "string" || !/^[a-z0-9_][a-z0-9_-]{0,63}$/.test(agentId))
|
|
54
|
+
throw new TypeError("OPENCLAW_AGENT_ID_INVALID");
|
|
54
55
|
const resumedKey = req.providerSession?.sessionId;
|
|
55
56
|
if (resumedKey &&
|
|
56
57
|
(!resumedKey.startsWith(`agent:${agentId}:`) ||
|
|
@@ -61,9 +62,9 @@ export function buildOpenClawGatewayInvocation(req) {
|
|
|
61
62
|
`agent:${agentId}:${req.sessionName ? `${encodeURIComponent(req.sessionName)}-` : ""}${randomUUID()}`;
|
|
62
63
|
const requestId = `octo-runtime-${req.runId}-${randomUUID()}`;
|
|
63
64
|
const message = composeOpenClawPrompt(req);
|
|
64
|
-
const timeout = finiteNumber(req
|
|
65
|
-
const model = nonEmptyString(req
|
|
66
|
-
const thinking = mapReasoningEffort("openclaw", req
|
|
65
|
+
const timeout = finiteNumber(invocationTimeoutSeconds(req, "openclaw"));
|
|
66
|
+
const model = nonEmptyString(invocationModel(req));
|
|
67
|
+
const thinking = mapReasoningEffort("openclaw", invocationEffort(req));
|
|
67
68
|
const timeoutMilliseconds = timeout && timeout > 0 ? timeout * 1_000 : 30 * 60_000;
|
|
68
69
|
const reconciliationGraceMilliseconds = Math.min(30_000, timeoutMilliseconds * 0.1);
|
|
69
70
|
const createParams = {
|
|
@@ -77,9 +78,6 @@ export function buildOpenClawGatewayInvocation(req) {
|
|
|
77
78
|
sessionKey,
|
|
78
79
|
deliver: false,
|
|
79
80
|
idempotencyKey: requestId,
|
|
80
|
-
...(initialControlInstructions(req)
|
|
81
|
-
? { extraSystemPrompt: initialControlInstructions(req) }
|
|
82
|
-
: {}),
|
|
83
81
|
...(model ? { model } : {}),
|
|
84
82
|
...(thinking ? { thinking } : {}),
|
|
85
83
|
...(timeout === undefined ? {} : { timeout: Math.max(0, Math.floor(timeout)) })
|
|
@@ -891,7 +889,7 @@ async function* invokeOpenClawGateway(req, invocation, context, clientFactory, p
|
|
|
891
889
|
try {
|
|
892
890
|
const hello = await client.connect();
|
|
893
891
|
const contract = resolveGatewayContract(hello);
|
|
894
|
-
const policy = resolveGatewayPermission(contract, req
|
|
892
|
+
const policy = resolveGatewayPermission(contract, invocationApprovalMode(req));
|
|
895
893
|
permissions.options.effectiveApprovalMode = policy.effective;
|
|
896
894
|
// 参数在真实握手之后生成;probe 的版本快照不作为本次执行依据。
|
|
897
895
|
const createParams = gatewayCreateParams(contract, policy, invocation.createParams, invocation.requestId, invocation.agentParams.thinking);
|
|
@@ -1203,6 +1201,9 @@ export function createOpenClawAdapter({ clientFactory = (options) => new OpenCla
|
|
|
1203
1201
|
}
|
|
1204
1202
|
};
|
|
1205
1203
|
return defineAdapter({
|
|
1204
|
+
defaultAgentEnv: withAgentEnvItems(defaultAgentEnv("openclaw", "preset"), [
|
|
1205
|
+
{ namespace: "adapter.openclaw", name: "options", payload: { agentId: "main" } }
|
|
1206
|
+
]),
|
|
1206
1207
|
metadata: {
|
|
1207
1208
|
type: "openclaw",
|
|
1208
1209
|
workspace: false,
|
|
@@ -1220,25 +1221,22 @@ export function createOpenClawAdapter({ clientFactory = (options) => new OpenCla
|
|
|
1220
1221
|
async *invoke(req, context) {
|
|
1221
1222
|
if (hasImageInput(req))
|
|
1222
1223
|
throw new Error("UNSUPPORTED_INPUT_MODALITY: openclaw does not encode image input");
|
|
1223
|
-
if (req
|
|
1224
|
+
if (invocationApprovalMode(req) === "assisted")
|
|
1224
1225
|
throw new Error("APPROVAL_MODE_UNSUPPORTED: OpenClaw has no qualified assisted policy");
|
|
1225
1226
|
if (responders.has(req.invocationId))
|
|
1226
1227
|
throw new Error("INVOCATION_ALREADY_ACTIVE");
|
|
1227
|
-
const
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
}
|
|
1240
|
-
}
|
|
1241
|
-
};
|
|
1228
|
+
const connectionOptions = invocationProviderOptions(req, "openclaw");
|
|
1229
|
+
// 本次连接解析独占请求包装;复用调用方请求时不共享私有连接绑定。
|
|
1230
|
+
req = { ...req };
|
|
1231
|
+
const gateway = await resolveOpenClawGateway(connectionOptions);
|
|
1232
|
+
bindInvocationConnection(req, {
|
|
1233
|
+
...Object.fromEntries(Object.entries(connectionOptions).filter((entry) => typeof entry[1] === "string")),
|
|
1234
|
+
[OPENCLAW_PROVIDER_OPTIONS.url]: gateway.url,
|
|
1235
|
+
[OPENCLAW_PROVIDER_OPTIONS.token]: gateway.token,
|
|
1236
|
+
[OPENCLAW_PROVIDER_OPTIONS.deviceId]: gateway.device.deviceId,
|
|
1237
|
+
[OPENCLAW_PROVIDER_OPTIONS.publicKey]: gateway.device.publicKey,
|
|
1238
|
+
[OPENCLAW_PROVIDER_OPTIONS.privateKey]: gateway.device.privateKey
|
|
1239
|
+
});
|
|
1242
1240
|
const invocation = buildOpenClawGatewayInvocation(req);
|
|
1243
1241
|
// 本轮及其对账/取消恢复连接共用本轮 sink;probe 则只使用工厂 sink。
|
|
1244
1242
|
invocation.gateway.log = context?.log ?? log;
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mininglamp-oss/octo-runtime-adapter-openclaw",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.13",
|
|
4
4
|
"private": true,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": "./dist/index.js",
|
|
7
7
|
"dependencies": {
|
|
8
|
-
"@mininglamp-oss/octo-runtime-protocol": "1.1.
|
|
9
|
-
"@mininglamp-oss/octo-runtime-adapter-sdk": "1.1.
|
|
8
|
+
"@mininglamp-oss/octo-runtime-protocol": "1.1.13",
|
|
9
|
+
"@mininglamp-oss/octo-runtime-adapter-sdk": "1.1.13",
|
|
10
10
|
"ws": "8.22.1"
|
|
11
11
|
},
|
|
12
12
|
"types": "./dist/index.d.ts",
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
+
import type { AdapterMetadata } from "@mininglamp-oss/octo-runtime-adapter-sdk";
|
|
2
|
+
export declare const openCodeMetadata: AdapterMetadata;
|
|
1
3
|
import { type AdapterInvocationContext, type CanonicalEvent, type InvokeRequest, type ProbeResult } from "@mininglamp-oss/octo-runtime-adapter-sdk";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
export declare function probeOpenCode(command?: string, env?: NodeJS.ProcessEnv, cwd?: string): Promise<ProbeResult>;
|
|
4
|
+
/** 只展示宿主绑定目标的可选版本,不按版本号准入;协议可用性由实际执行结果确定。 */
|
|
5
|
+
export declare function probeOpenCode(command: string, env?: NodeJS.ProcessEnv, cwd?: string, args?: readonly string[]): Promise<ProbeResult>;
|
|
5
6
|
/** A single OpenCode stream part; tool lifecycle is carried in `state.status` (running -> completed/error). */
|
|
6
7
|
interface OpenCodePart {
|
|
7
8
|
sessionID?: string;
|
|
@@ -44,15 +45,10 @@ interface OpenCodeNativeEvent extends OpenCodePart {
|
|
|
44
45
|
};
|
|
45
46
|
}
|
|
46
47
|
/**
|
|
47
|
-
*
|
|
48
|
-
*
|
|
49
|
-
* Runtime context is injected as an extra entry in OpenCode's `instructions`
|
|
50
|
-
* config (a temp markdown file) delivered through OPENCODE_CONFIG_CONTENT,
|
|
51
|
-
* merged onto any inline config so the user's existing OpenCode config is not
|
|
52
|
-
* overwritten. Returns a `cleanup` that removes the temp directory.
|
|
53
|
-
*
|
|
48
|
+
* 构造本轮 OpenCode 命令、普通输入和执行配置;原生 inline config 保持,
|
|
49
|
+
* 仅合并本轮 MCP 设置,不生成应用指令文件或追加系统提示词。
|
|
54
50
|
*/
|
|
55
|
-
export declare function buildOpenCodeCommand(req: InvokeRequest, command?: string): Promise<{
|
|
51
|
+
export declare function buildOpenCodeCommand(req: InvokeRequest, command?: string, inherited?: NodeJS.ProcessEnv): Promise<{
|
|
56
52
|
command: string;
|
|
57
53
|
args: string[];
|
|
58
54
|
input: string;
|
|
@@ -63,7 +59,7 @@ export declare function buildOpenCodeCommand(req: InvokeRequest, command?: strin
|
|
|
63
59
|
};
|
|
64
60
|
rpcMethod: string;
|
|
65
61
|
providerSessionId: string | undefined;
|
|
66
|
-
cleanup: () =>
|
|
62
|
+
cleanup: () => undefined;
|
|
67
63
|
}>;
|
|
68
64
|
/** Translate one OpenCode native event/part into canonical events; unrelated events yield an empty list. */
|
|
69
65
|
export declare function normalizeOpenCodeEvent(native: OpenCodeNativeEvent): CanonicalEvent[];
|
|
@@ -76,24 +72,19 @@ export declare class OpenCodeEventNormalizer {
|
|
|
76
72
|
#private;
|
|
77
73
|
normalize(native: OpenCodeNativeEvent): CanonicalEvent[];
|
|
78
74
|
}
|
|
79
|
-
export declare function createOpenCodeAdapter({ command }
|
|
80
|
-
command
|
|
75
|
+
export declare function createOpenCodeAdapter({ command, commandArgsPrefix, env }: {
|
|
76
|
+
command: string;
|
|
77
|
+
commandArgsPrefix?: readonly string[];
|
|
78
|
+
env?: NodeJS.ProcessEnv;
|
|
81
79
|
}): {
|
|
80
|
+
defaultAgentEnv: import("@mininglamp-oss/octo-runtime-protocol").ContextEnvelope;
|
|
82
81
|
respondInteraction(invocationId: string, response: import("@mininglamp-oss/octo-runtime-protocol").InteractionResponse): Promise<void>;
|
|
83
82
|
invoke(request: InvokeRequest, context?: AdapterInvocationContext): AsyncGenerator<CanonicalEvent>;
|
|
84
83
|
probe?: (options?: import("@mininglamp-oss/octo-runtime-adapter-sdk").AdapterProbeOptions) => Promise<ProbeResult>;
|
|
84
|
+
respondNative?: ((invocationId: string, response: import("@mininglamp-oss/octo-runtime-protocol").NativeInteractionResponse) => Promise<void>) | undefined;
|
|
85
85
|
createExecutionScope?: import("@mininglamp-oss/octo-runtime-adapter-sdk").CreateAdapterExecutionScope;
|
|
86
|
-
metadata: Omit<
|
|
87
|
-
protocolSupport: import("@mininglamp-oss/octo-runtime-protocol").AdapterProtocolSupport;
|
|
88
|
-
};
|
|
89
|
-
};
|
|
90
|
-
export declare const opencodeAdapter: {
|
|
91
|
-
respondInteraction(invocationId: string, response: import("@mininglamp-oss/octo-runtime-protocol").InteractionResponse): Promise<void>;
|
|
92
|
-
invoke(request: InvokeRequest, context?: AdapterInvocationContext): AsyncGenerator<CanonicalEvent>;
|
|
93
|
-
probe?: (options?: import("@mininglamp-oss/octo-runtime-adapter-sdk").AdapterProbeOptions) => Promise<ProbeResult>;
|
|
94
|
-
createExecutionScope?: import("@mininglamp-oss/octo-runtime-adapter-sdk").CreateAdapterExecutionScope;
|
|
95
|
-
metadata: Omit<import("@mininglamp-oss/octo-runtime-adapter-sdk").AdapterMetadata, "protocolSupport"> & {
|
|
86
|
+
metadata: Omit<AdapterMetadata, "protocolSupport"> & {
|
|
96
87
|
protocolSupport: import("@mininglamp-oss/octo-runtime-protocol").AdapterProtocolSupport;
|
|
97
88
|
};
|
|
98
89
|
};
|
|
99
|
-
export
|
|
90
|
+
export {};
|
|
@@ -1,4 +1,10 @@
|
|
|
1
|
-
|
|
1
|
+
export const openCodeMetadata = {
|
|
2
|
+
mcp: true,
|
|
3
|
+
type: "opencode",
|
|
4
|
+
agentSources: ["provisioned"]
|
|
5
|
+
};
|
|
6
|
+
import { assertAdapterAgentEnv, assertAdapterWorkdir, runAdapterPreparation, invocationEffort, invocationModel, invocationRuntimeLimits, invocationApprovalMode, invocationWorkdir } from "@mininglamp-oss/octo-runtime-adapter-sdk";
|
|
7
|
+
import { hasImageInput, mapReasoningEffort, invocationEnvironment, processEnvironmentValue, invocationMcpServers, assertMcpOptions } from "@mininglamp-oss/octo-runtime-adapter-sdk";
|
|
2
8
|
import { canonicalTerminalStatus } from "@mininglamp-oss/octo-runtime-protocol";
|
|
3
9
|
/**
|
|
4
10
|
* OpenCode adapter: wraps the OpenCode CLI (`opencode run --format json
|
|
@@ -6,63 +12,15 @@ import { canonicalTerminalStatus } from "@mininglamp-oss/octo-runtime-protocol";
|
|
|
6
12
|
* Both transports normalize provider output into canonical events.
|
|
7
13
|
*/
|
|
8
14
|
import { AcpInvocationError, createAcpAdapter } from "@mininglamp-oss/octo-runtime-adapter-acp";
|
|
9
|
-
import { createJsonCliAdapter, probeCommand, providerInputText, ProviderProcessError } from "@mininglamp-oss/octo-runtime-adapter-sdk";
|
|
10
|
-
import { mkdtemp, rm, writeFile } from "node:fs/promises";
|
|
11
|
-
import { tmpdir } from "node:os";
|
|
12
|
-
import { delimiter, join, parse, resolve } from "node:path";
|
|
13
|
-
export const MINIMUM_OPENCODE_VERSION = "2.1.3";
|
|
15
|
+
import { createJsonCliAdapter, probeCommand, snapshotProviderLaunch, providerInputText, ProviderProcessError } from "@mininglamp-oss/octo-runtime-adapter-sdk";
|
|
14
16
|
class OpenCodeInputError extends Error {
|
|
15
17
|
}
|
|
16
|
-
/**
|
|
17
|
-
export async function probeOpenCode(command
|
|
18
|
-
|
|
19
|
-
// 本机 path 规则保留绝对路径;Windows 根相对和盘符相对路径也绑定本轮 cwd。
|
|
20
|
-
const selected = qualified ? resolve(cwd, command) : command;
|
|
21
|
-
const probeEnv = { ...env };
|
|
22
|
-
if (process.platform === "win32") {
|
|
23
|
-
// 普通对象的键区分大小写;与 Node 子进程一致,重复别名取字典序首项。
|
|
24
|
-
for (const name of ["PATH", "PATHEXT"]) {
|
|
25
|
-
const aliases = Object.keys(env)
|
|
26
|
-
.filter((key) => key.toUpperCase() === name)
|
|
27
|
-
.sort();
|
|
28
|
-
const value = aliases.length ? env[aliases[0]] : undefined;
|
|
29
|
-
for (const alias of aliases)
|
|
30
|
-
delete probeEnv[alias];
|
|
31
|
-
if (value !== undefined)
|
|
32
|
-
probeEnv[name] = value;
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
// 空项和相对项按子进程 cwd 查找;绝对项按本机规则保留原有含义。
|
|
36
|
-
probeEnv.PATH = (probeEnv.PATH ?? "")
|
|
37
|
-
.split(delimiter)
|
|
38
|
-
.map((entry) => resolve(cwd, entry))
|
|
39
|
-
.join(delimiter);
|
|
40
|
-
const result = await probeCommand(selected, {
|
|
41
|
-
cwd,
|
|
42
|
-
env: probeEnv
|
|
43
|
-
});
|
|
44
|
-
if (!result.available)
|
|
45
|
-
return result;
|
|
46
|
-
if (!result.version)
|
|
47
|
-
return {
|
|
48
|
-
...result,
|
|
49
|
-
available: false,
|
|
50
|
-
reason: "OPENCODE_VERSION_DETECTION_FAILED: could not determine OpenCode version (--version failed, timed out, or returned invalid output)"
|
|
51
|
-
};
|
|
52
|
-
const match = /^(\d+)\.(\d+)\.(\d+)$/.exec(result.version);
|
|
53
|
-
if (!match ||
|
|
54
|
-
Number(match[1]) !== 2 ||
|
|
55
|
-
Number(match[2]) < 1 ||
|
|
56
|
-
(Number(match[2]) === 1 && Number(match[3]) < 3))
|
|
57
|
-
return {
|
|
58
|
-
...result,
|
|
59
|
-
available: false,
|
|
60
|
-
reason: `OPENCODE_VERSION_UNSUPPORTED: detected ${result.version}. ${result.version.startsWith("1.") ? "OpenCode 1 is no longer supported. " : ""}Install OpenCode >= ${MINIMUM_OPENCODE_VERSION} < 3 and retry.`
|
|
61
|
-
};
|
|
62
|
-
return result;
|
|
18
|
+
/** 只展示宿主绑定目标的可选版本,不按版本号准入;协议可用性由实际执行结果确定。 */
|
|
19
|
+
export async function probeOpenCode(command, env = {}, cwd, args = []) {
|
|
20
|
+
return probeCommand(command, { cwd, env, args });
|
|
63
21
|
}
|
|
64
|
-
function inlineConfig(request) {
|
|
65
|
-
const content = processEnvironmentValue(invocationEnvironment(request), "OPENCODE_CONFIG_CONTENT");
|
|
22
|
+
function inlineConfig(request, inherited = {}) {
|
|
23
|
+
const content = processEnvironmentValue(invocationEnvironment(request, {}, inherited), "OPENCODE_CONFIG_CONTENT");
|
|
66
24
|
if (!content)
|
|
67
25
|
return {};
|
|
68
26
|
let parsed;
|
|
@@ -77,92 +35,68 @@ function inlineConfig(request) {
|
|
|
77
35
|
return parsed;
|
|
78
36
|
}
|
|
79
37
|
/**
|
|
80
|
-
*
|
|
81
|
-
*
|
|
82
|
-
* Runtime context is injected as an extra entry in OpenCode's `instructions`
|
|
83
|
-
* config (a temp markdown file) delivered through OPENCODE_CONFIG_CONTENT,
|
|
84
|
-
* merged onto any inline config so the user's existing OpenCode config is not
|
|
85
|
-
* overwritten. Returns a `cleanup` that removes the temp directory.
|
|
86
|
-
*
|
|
38
|
+
* 构造本轮 OpenCode 命令、普通输入和执行配置;原生 inline config 保持,
|
|
39
|
+
* 仅合并本轮 MCP 设置,不生成应用指令文件或追加系统提示词。
|
|
87
40
|
*/
|
|
88
|
-
export
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
}
|
|
123
|
-
};
|
|
124
|
-
}
|
|
125
|
-
// Reasoning output and non-interactive tool approval are mandatory parts of
|
|
126
|
-
// this adapter's provider contract.
|
|
127
|
-
const args = ["run", "--format", "json", "--thinking", "--auto", "--standalone"];
|
|
128
|
-
if (req.providerSession?.sessionId)
|
|
129
|
-
args.push("--session", req.providerSession.sessionId);
|
|
130
|
-
const variant = mapReasoningEffort("opencode", req.agentConfig?.effort);
|
|
131
|
-
if (req.agentConfig?.model) {
|
|
132
|
-
const model = req.agentConfig.model;
|
|
133
|
-
args.push("--model", variant ? `${model.split("#")[0]}#${variant}` : model);
|
|
134
|
-
}
|
|
135
|
-
// 先校验和转换,再创建资源;写入失败由本层回收,返回后交给 CLI helper。
|
|
136
|
-
let directory;
|
|
137
|
-
try {
|
|
138
|
-
if (initialControlInstructions(req)) {
|
|
139
|
-
directory = await mkdtemp(join(tmpdir(), "octo-runtime-opencode-"));
|
|
140
|
-
const instructions = join(directory, "instructions.md");
|
|
141
|
-
await writeFile(instructions, initialControlInstructions(req), { mode: 0o600 });
|
|
142
|
-
inline.instructions = [...configuredInstructions, instructions];
|
|
41
|
+
export function buildOpenCodeCommand(req, command = "opencode", inherited = {}) {
|
|
42
|
+
return Promise.resolve().then(() => {
|
|
43
|
+
if (hasImageInput(req))
|
|
44
|
+
throw new Error("UNSUPPORTED_INPUT_MODALITY: opencode does not encode image input");
|
|
45
|
+
if (invocationApprovalMode(req) !== "full_access")
|
|
46
|
+
throw new Error("APPROVAL_MODE_UNSUPPORTED: opencode permission transport is not qualified");
|
|
47
|
+
const runEnv = invocationEnvironment(req, {}, inherited);
|
|
48
|
+
const servers = invocationMcpServers(req, runEnv);
|
|
49
|
+
assertMcpOptions(servers, "opencode", ["toolTimeoutMs"]);
|
|
50
|
+
const inline = inlineConfig(req, inherited);
|
|
51
|
+
if (Object.keys(servers).length) {
|
|
52
|
+
const existing = isRecord(inline.mcp) ? inline.mcp : {};
|
|
53
|
+
inline.mcp = {
|
|
54
|
+
...existing,
|
|
55
|
+
servers: {
|
|
56
|
+
...(isRecord(existing.servers) ? existing.servers : {}),
|
|
57
|
+
...Object.fromEntries(Object.entries(servers).map(([name, server]) => [
|
|
58
|
+
name,
|
|
59
|
+
{
|
|
60
|
+
...(server.type === "stdio"
|
|
61
|
+
? {
|
|
62
|
+
type: "local",
|
|
63
|
+
command: [server.command, ...(server.args ?? [])],
|
|
64
|
+
environment: server.env ?? {}
|
|
65
|
+
}
|
|
66
|
+
: { type: "remote", url: server.url, headers: server.headers ?? {} }),
|
|
67
|
+
disabled: false,
|
|
68
|
+
...(server.toolTimeoutMs !== undefined
|
|
69
|
+
? { timeout: { execution: server.toolTimeoutMs } }
|
|
70
|
+
: {})
|
|
71
|
+
}
|
|
72
|
+
]))
|
|
73
|
+
}
|
|
74
|
+
};
|
|
143
75
|
}
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
input: providerInputText(req),
|
|
154
|
-
env: {
|
|
155
|
-
OPENCODE_CONFIG_CONTENT: JSON.stringify(inline),
|
|
156
|
-
OPENCODE_CLIENT: "octo-runtime",
|
|
157
|
-
PWD: req.workdir
|
|
158
|
-
},
|
|
159
|
-
rpcMethod: "process.stdin",
|
|
160
|
-
providerSessionId: req.providerSession?.sessionId,
|
|
161
|
-
cleanup: async () => {
|
|
162
|
-
if (directory)
|
|
163
|
-
await rm(directory, { recursive: true, force: true });
|
|
76
|
+
// Reasoning output and non-interactive tool approval are mandatory parts of
|
|
77
|
+
// this adapter's provider contract.
|
|
78
|
+
const args = ["run", "--format", "json", "--thinking", "--auto", "--standalone"];
|
|
79
|
+
if (req.providerSession?.sessionId)
|
|
80
|
+
args.push("--session", req.providerSession.sessionId);
|
|
81
|
+
const variant = mapReasoningEffort("opencode", invocationEffort(req));
|
|
82
|
+
const model = invocationModel(req);
|
|
83
|
+
if (model) {
|
|
84
|
+
args.push("--model", variant ? `${model.split("#")[0]}#${variant}` : model);
|
|
164
85
|
}
|
|
165
|
-
|
|
86
|
+
return {
|
|
87
|
+
command,
|
|
88
|
+
args,
|
|
89
|
+
input: providerInputText(req),
|
|
90
|
+
env: {
|
|
91
|
+
OPENCODE_CONFIG_CONTENT: JSON.stringify(inline),
|
|
92
|
+
OPENCODE_CLIENT: "octo-runtime",
|
|
93
|
+
PWD: invocationWorkdir(req)
|
|
94
|
+
},
|
|
95
|
+
rpcMethod: "process.stdin",
|
|
96
|
+
providerSessionId: req.providerSession?.sessionId,
|
|
97
|
+
cleanup: () => undefined
|
|
98
|
+
};
|
|
99
|
+
});
|
|
166
100
|
}
|
|
167
101
|
/** Translate one OpenCode native event/part into canonical events; unrelated events yield an empty list. */
|
|
168
102
|
export function normalizeOpenCodeEvent(native) {
|
|
@@ -363,28 +297,33 @@ export class OpenCodeEventNormalizer {
|
|
|
363
297
|
});
|
|
364
298
|
}
|
|
365
299
|
}
|
|
366
|
-
export function createOpenCodeAdapter({ command =
|
|
300
|
+
export function createOpenCodeAdapter({ command, commandArgsPrefix = [], env = {} }) {
|
|
301
|
+
const launch = snapshotProviderLaunch({ command, args: commandArgsPrefix, env });
|
|
302
|
+
const buildCommand = async (req) => {
|
|
303
|
+
const spec = await buildOpenCodeCommand(req, launch.command, launch.env);
|
|
304
|
+
return {
|
|
305
|
+
...spec,
|
|
306
|
+
args: [...launch.args, ...spec.args],
|
|
307
|
+
env: invocationEnvironment(req, spec.env, launch.env)
|
|
308
|
+
};
|
|
309
|
+
};
|
|
367
310
|
const interactiveAdapters = new Map();
|
|
368
|
-
const createInteractive = (
|
|
311
|
+
const createInteractive = () => createAcpAdapter({
|
|
369
312
|
type: "opencode",
|
|
370
313
|
provider: "opencode",
|
|
371
|
-
command:
|
|
314
|
+
command: launch.command,
|
|
372
315
|
args: ["acp"],
|
|
373
316
|
// ACP 原生权限策略决定何时请求审批;桥接层逐次处理,不覆盖用户的 deny。
|
|
374
317
|
env: (request) => ({
|
|
375
318
|
OPENCODE_CLIENT: "octo-runtime",
|
|
376
|
-
PWD: request
|
|
377
|
-
OPENCODE_CONFIG_CONTENT: JSON.stringify(inlineConfig(request))
|
|
319
|
+
PWD: invocationWorkdir(request),
|
|
320
|
+
OPENCODE_CONFIG_CONTENT: JSON.stringify(inlineConfig(request, launch.env))
|
|
378
321
|
})
|
|
379
|
-
});
|
|
322
|
+
}, { command: launch.command, commandArgsPrefix: launch.args, env: launch.env });
|
|
380
323
|
const options = {
|
|
381
|
-
metadata:
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
agentSources: ["provisioned"]
|
|
385
|
-
},
|
|
386
|
-
probe: () => probeOpenCode(command),
|
|
387
|
-
buildCommand: (req) => buildOpenCodeCommand(req, command),
|
|
324
|
+
metadata: openCodeMetadata,
|
|
325
|
+
probe: () => probeOpenCode(launch.command, launch.env, undefined, launch.args),
|
|
326
|
+
buildCommand,
|
|
388
327
|
normalize: normalizeOpenCodeEvent,
|
|
389
328
|
onSuccess: () => [
|
|
390
329
|
{
|
|
@@ -398,6 +337,9 @@ export function createOpenCodeAdapter({ command = "opencode" } = {}) {
|
|
|
398
337
|
const adapter = createJsonCliAdapter(options);
|
|
399
338
|
return {
|
|
400
339
|
...adapter,
|
|
340
|
+
get defaultAgentEnv() {
|
|
341
|
+
return adapter.defaultAgentEnv;
|
|
342
|
+
},
|
|
401
343
|
async respondInteraction(...args) {
|
|
402
344
|
const interactive = interactiveAdapters.get(args[0]);
|
|
403
345
|
if (!interactive)
|
|
@@ -405,32 +347,23 @@ export function createOpenCodeAdapter({ command = "opencode" } = {}) {
|
|
|
405
347
|
await interactive.respondInteraction(...args);
|
|
406
348
|
},
|
|
407
349
|
async *invoke(request, context) {
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
350
|
+
await runAdapterPreparation(context, async () => {
|
|
351
|
+
assertAdapterAgentEnv(request);
|
|
352
|
+
// 两种传输共用本轮预算;内层再次配置同值不会重置 Core 的计时起点。
|
|
353
|
+
context?.configureRuntimeLimits?.(invocationRuntimeLimits(request));
|
|
354
|
+
await assertAdapterWorkdir(request);
|
|
355
|
+
if (hasImageInput(request))
|
|
356
|
+
throw new Error("UNSUPPORTED_INPUT_MODALITY: opencode does not encode image input");
|
|
357
|
+
if (invocationApprovalMode(request) === "assisted")
|
|
358
|
+
throw new Error("APPROVAL_MODE_UNSUPPORTED: opencode has no qualified assisted policy");
|
|
359
|
+
// 启动前只做目录与纯配置检查;实际协议失败按执行结果报告,不以版本号拦截。
|
|
360
|
+
inlineConfig(request, launch.env);
|
|
361
|
+
});
|
|
412
362
|
request.signal?.throwIfAborted();
|
|
413
|
-
|
|
414
|
-
if (!selected.available)
|
|
415
|
-
throw new Error(selected.reason ?? "OpenCode is unavailable");
|
|
416
|
-
request.signal?.throwIfAborted();
|
|
417
|
-
try {
|
|
418
|
-
inlineConfig(request);
|
|
419
|
-
}
|
|
420
|
-
catch (error) {
|
|
421
|
-
if (!(error instanceof OpenCodeInputError))
|
|
422
|
-
throw error;
|
|
423
|
-
yield {
|
|
424
|
-
protocolVersion: 2,
|
|
425
|
-
type: "run.failed",
|
|
426
|
-
payload: { code: "OPENCODE_CONFIG_INVALID", message: error.message }
|
|
427
|
-
};
|
|
428
|
-
return;
|
|
429
|
-
}
|
|
430
|
-
if (request.approvalMode === "ask") {
|
|
363
|
+
if (invocationApprovalMode(request) === "ask") {
|
|
431
364
|
if (interactiveAdapters.has(request.invocationId))
|
|
432
365
|
throw new Error("INVOCATION_ALREADY_ACTIVE");
|
|
433
|
-
const interactive = createInteractive(
|
|
366
|
+
const interactive = createInteractive();
|
|
434
367
|
interactiveAdapters.set(request.invocationId, interactive);
|
|
435
368
|
try {
|
|
436
369
|
yield* interactive.invoke(request, context);
|
|
@@ -451,8 +384,8 @@ export function createOpenCodeAdapter({ command = "opencode" } = {}) {
|
|
|
451
384
|
try {
|
|
452
385
|
yield* createJsonCliAdapter({
|
|
453
386
|
...options,
|
|
454
|
-
reasoningLevels: request
|
|
455
|
-
buildCommand
|
|
387
|
+
reasoningLevels: invocationModel(request) ? undefined : null,
|
|
388
|
+
buildCommand,
|
|
456
389
|
normalize: (native) => {
|
|
457
390
|
const part = native.part ?? native;
|
|
458
391
|
if (native.type === "step_start" || part.type === "step-start")
|
|
@@ -493,5 +426,3 @@ export function createOpenCodeAdapter({ command = "opencode" } = {}) {
|
|
|
493
426
|
}
|
|
494
427
|
};
|
|
495
428
|
}
|
|
496
|
-
export const opencodeAdapter = createOpenCodeAdapter();
|
|
497
|
-
export default opencodeAdapter;
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mininglamp-oss/octo-runtime-adapter-opencode",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.13",
|
|
4
4
|
"private": true,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": "./dist/index.js",
|
|
7
7
|
"dependencies": {
|
|
8
|
-
"@mininglamp-oss/octo-runtime-protocol": "1.1.
|
|
9
|
-
"@mininglamp-oss/octo-runtime-adapter-acp": "1.1.
|
|
10
|
-
"@mininglamp-oss/octo-runtime-adapter-sdk": "1.1.
|
|
8
|
+
"@mininglamp-oss/octo-runtime-protocol": "1.1.13",
|
|
9
|
+
"@mininglamp-oss/octo-runtime-adapter-acp": "1.1.13",
|
|
10
|
+
"@mininglamp-oss/octo-runtime-adapter-sdk": "1.1.13"
|
|
11
11
|
},
|
|
12
12
|
"types": "./dist/index.d.ts",
|
|
13
13
|
"files": [
|