@mininglamp-oss/octo-runtime 1.1.0 → 1.1.2
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 +4 -2
- package/apps/cli/README.md +3 -1
- package/apps/cli/dist/build-info.json +2 -2
- package/apps/cli/dist/extras.d.ts +4 -2
- package/apps/cli/dist/extras.js +20 -21
- package/apps/cli/dist/help.js +3 -0
- package/apps/cli/dist/logs.d.ts +10 -0
- package/apps/cli/dist/logs.js +186 -0
- package/apps/cli/dist/main.d.ts +1 -0
- package/apps/cli/dist/main.js +94 -19
- package/apps/cli/dist/{default_adapters.json → manifest.json} +10 -0
- package/apps/cli/dist/module-manifest.d.ts +3 -0
- package/apps/cli/dist/module-manifest.js +11 -0
- package/apps/cli/dist/openclaw.js +30 -6
- package/apps/cli/dist/output.js +3 -0
- package/apps/cli/dist/playboard.js +10 -8
- package/apps/cli/dist/status-output.d.ts +10 -0
- package/apps/cli/dist/status-output.js +65 -0
- package/apps/cli/dist/worker.d.ts +1 -0
- package/apps/cli/dist/worker.js +18 -0
- package/dist/public/host.d.ts +1 -0
- package/node_modules/@mininglamp-oss/octo-runtime-acp-client/package.json +3 -3
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-acp/package.json +4 -4
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-antigravity/package.json +3 -3
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-claude-code/package.json +3 -3
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-codebuddy/package.json +4 -4
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-codex/package.json +3 -3
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-grok-build/dist/adapter.d.ts +54 -0
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-grok-build/dist/adapter.js +399 -0
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-grok-build/dist/client.d.ts +14 -0
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-grok-build/dist/client.js +156 -0
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-grok-build/dist/index.d.ts +29 -0
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-grok-build/dist/index.js +273 -0
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-grok-build/dist/interactions.d.ts +27 -0
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-grok-build/dist/interactions.js +161 -0
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-grok-build/package.json +17 -0
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-hermes/package.json +2 -2
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-kimi-code/package.json +2 -2
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-mcode/package.json +2 -2
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-openclaw/dist/compatibility.d.ts +24 -0
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-openclaw/dist/compatibility.js +181 -0
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-openclaw/dist/gateway.d.ts +9 -0
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-openclaw/dist/gateway.js +24 -8
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-openclaw/dist/index.js +229 -225
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-openclaw/package.json +3 -3
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-opencode/package.json +4 -4
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-qodercli/package.json +2 -2
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-qoderclicn/package.json +2 -2
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-sdk/dist/approval.d.ts +4 -0
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-sdk/dist/approval.js +5 -6
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-sdk/dist/index.d.ts +1 -0
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-sdk/dist/index.js +1 -0
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-sdk/dist/module-manifest.d.ts +33 -0
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-sdk/dist/module-manifest.js +118 -0
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-sdk/dist/runtime-log-worker.js +7 -5
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-sdk/dist/runtime-log.d.ts +3 -0
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-sdk/dist/runtime-log.js +45 -10
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-sdk/dist/service-status.d.ts +11 -0
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-sdk/dist/service-status.js +70 -0
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-sdk/package.json +5 -3
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-zcode-gui/package.json +3 -3
- package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/build-info.json +2 -2
- package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/extras.d.ts +4 -2
- package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/extras.js +20 -21
- package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/help.js +3 -0
- package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/logs.d.ts +10 -0
- package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/logs.js +186 -0
- package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/main.d.ts +1 -0
- package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/main.js +94 -19
- package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/{default_adapters.json → manifest.json} +10 -0
- package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/module-manifest.d.ts +3 -0
- package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/module-manifest.js +11 -0
- package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/openclaw.js +30 -6
- package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/output.js +3 -0
- package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/playboard.js +10 -8
- package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/status-output.d.ts +10 -0
- package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/status-output.js +65 -0
- package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/worker.d.ts +1 -0
- package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/worker.js +18 -0
- package/node_modules/@mininglamp-oss/octo-runtime-cli/package.json +23 -9
- package/node_modules/@mininglamp-oss/octo-runtime-cross-service/package.json +2 -2
- package/node_modules/@mininglamp-oss/octo-runtime-executor-core/dist/model-input.d.ts +1 -1
- package/node_modules/@mininglamp-oss/octo-runtime-executor-core/dist/model-input.js +13 -9
- package/node_modules/@mininglamp-oss/octo-runtime-executor-core/package.json +3 -3
- package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/heartbeat.d.ts +16 -0
- package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/heartbeat.js +59 -0
- package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/invocation-manifest.d.ts +1 -0
- package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/invocation-manifest.js +4 -1
- package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/manifest-adapters.d.ts +6 -0
- package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/manifest-adapters.js +88 -0
- package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/module-specifier.d.ts +1 -2
- package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/module-specifier.js +2 -9
- package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/process.d.ts +7 -2
- package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/process.js +138 -9
- package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/runner.js +3 -92
- package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/serve.js +36 -12
- package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/server.d.ts +4 -1
- package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/server.js +14 -6
- package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/service.js +2 -1
- package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/supervisor.d.ts +2 -2
- package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/supervisor.js +57 -34
- package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/package.json +8 -16
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/config-schema.json +2 -2
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/application/im-channel.js +18 -18
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/contracts.d.ts +1 -0
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/execution/dispatcher.js +24 -0
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/contexts.js +2 -2
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/mentions.d.ts +5 -2
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/mentions.js +19 -5
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/normalize.js +1 -0
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/package.json +6 -6
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-wecom/config-schema.json +2 -2
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-wecom/package.json +5 -5
- package/node_modules/@mininglamp-oss/octo-runtime-extra-webui/config-schema.json +2 -2
- package/node_modules/@mininglamp-oss/octo-runtime-extra-webui/dist/index.js +1 -1
- package/node_modules/@mininglamp-oss/octo-runtime-extra-webui/dist/store.d.ts +4 -1
- package/node_modules/@mininglamp-oss/octo-runtime-extra-webui/dist/store.js +54 -4
- package/node_modules/@mininglamp-oss/octo-runtime-extra-webui/package.json +2 -2
- package/node_modules/@mininglamp-oss/octo-runtime-host-sdk/dist/extra-config.d.ts +8 -1
- package/node_modules/@mininglamp-oss/octo-runtime-host-sdk/dist/extra-config.js +27 -12
- package/node_modules/@mininglamp-oss/octo-runtime-host-sdk/dist/extra-service.js +39 -2
- package/node_modules/@mininglamp-oss/octo-runtime-host-sdk/dist/index.d.ts +1 -0
- package/node_modules/@mininglamp-oss/octo-runtime-host-sdk/package.json +4 -4
- package/node_modules/@mininglamp-oss/octo-runtime-protocol/package.json +1 -1
- package/node_modules/import-meta-resolve/index.d.ts +19 -0
- package/node_modules/import-meta-resolve/index.d.ts.map +1 -0
- package/node_modules/import-meta-resolve/index.js +47 -0
- package/node_modules/import-meta-resolve/lib/errors.d.ts +24 -0
- package/node_modules/import-meta-resolve/lib/errors.d.ts.map +1 -0
- package/node_modules/import-meta-resolve/lib/errors.js +504 -0
- package/node_modules/import-meta-resolve/lib/get-format.d.ts +13 -0
- package/node_modules/import-meta-resolve/lib/get-format.d.ts.map +1 -0
- package/node_modules/import-meta-resolve/lib/get-format.js +159 -0
- package/node_modules/import-meta-resolve/lib/package-json-reader.d.ts +31 -0
- package/node_modules/import-meta-resolve/lib/package-json-reader.d.ts.map +1 -0
- package/node_modules/import-meta-resolve/lib/package-json-reader.js +177 -0
- package/node_modules/import-meta-resolve/lib/resolve.d.ts +29 -0
- package/node_modules/import-meta-resolve/lib/resolve.d.ts.map +1 -0
- package/node_modules/import-meta-resolve/lib/resolve.js +1301 -0
- package/node_modules/import-meta-resolve/lib/utils.d.ts +6 -0
- package/node_modules/import-meta-resolve/lib/utils.d.ts.map +1 -0
- package/node_modules/import-meta-resolve/lib/utils.js +47 -0
- package/node_modules/import-meta-resolve/license +74 -0
- package/node_modules/import-meta-resolve/package.json +78 -0
- package/node_modules/import-meta-resolve/readme.md +252 -0
- package/package.json +30 -26
- package/packages/octo-runtime-extra-channel-gateway/config-schema.json +2 -2
- package/packages/octo-runtime-extra-channel-wecom/config-schema.json +2 -2
- package/packages/octo-runtime-extra-webui/config-schema.json +2 -2
|
@@ -0,0 +1,273 @@
|
|
|
1
|
+
import { GrokBuildRpcError, spawnGrokBuildAcpClient } from "./client.js";
|
|
2
|
+
import { createGrokBuildAcpAdapter } from "./adapter.js";
|
|
3
|
+
import { initialControlInstructions, invocationEnvironment, invocationMcpServers, probeCommand } from "@mininglamp-oss/octo-runtime-adapter-sdk";
|
|
4
|
+
export const GROK_BUILD_TESTED_VERSION = "1.0.67";
|
|
5
|
+
const levels = { low: "low", medium: "medium", high: "high", xhigh: "xhigh" };
|
|
6
|
+
function supportedVersion(version) {
|
|
7
|
+
if (typeof version !== "string")
|
|
8
|
+
return false;
|
|
9
|
+
const match = /^(\d+)\.(\d+)\.(\d+)$/.exec(version);
|
|
10
|
+
return !!match && Number(match[1]) === 1 && (Number(match[2]) > 0 || Number(match[3]) >= 67);
|
|
11
|
+
}
|
|
12
|
+
/** 宿主可指定已安装命令;每次调用拥有独立 ACP 子进程,不连接用户常驻 leader。 */
|
|
13
|
+
export function createGrokBuildAdapter({ command = "grok", acpClientFactory = spawnGrokBuildAcpClient } = {}) {
|
|
14
|
+
const adapter = createGrokBuildAcpAdapter({
|
|
15
|
+
type: "grok-build",
|
|
16
|
+
provider: "grok-build",
|
|
17
|
+
command,
|
|
18
|
+
args: ["--no-auto-update", "agent", "--no-leader", "stdio"],
|
|
19
|
+
controlInstructions: "session",
|
|
20
|
+
reasoningLevels: levels,
|
|
21
|
+
async probe() {
|
|
22
|
+
const result = await probeCommand(command);
|
|
23
|
+
if (!result.available)
|
|
24
|
+
return {
|
|
25
|
+
...result,
|
|
26
|
+
reason: "command_not_found: install Grok Build and put grok on PATH"
|
|
27
|
+
};
|
|
28
|
+
return supportedVersion(result.version)
|
|
29
|
+
? result
|
|
30
|
+
: {
|
|
31
|
+
...result,
|
|
32
|
+
available: false,
|
|
33
|
+
reason: `grok_version_unsupported: install Grok Build ${GROK_BUILD_TESTED_VERSION} or a compatible 1.x release`
|
|
34
|
+
};
|
|
35
|
+
},
|
|
36
|
+
async initialize(client, init, _request, env) {
|
|
37
|
+
const version = record(init._meta).agentVersion ?? (await probeCommand(command, { env })).version;
|
|
38
|
+
if (init.protocolVersion !== 1 || !supportedVersion(version))
|
|
39
|
+
throw new Error(`GROK_VERSION_UNSUPPORTED: expected ACP v1 and Grok Build >= ${GROK_BUILD_TESTED_VERSION}, < 2.0.0`);
|
|
40
|
+
const methods = Array.isArray(init.authMethods)
|
|
41
|
+
? init.authMethods.map((m) => record(m).id)
|
|
42
|
+
: [];
|
|
43
|
+
// 只按 harness 广告顺序协商非交互握手;凭据来源和可用性由 harness 判断。
|
|
44
|
+
const methodId = methods.find((id) => id === "xai.api_key" || id === "cached_token");
|
|
45
|
+
if (!methodId)
|
|
46
|
+
throw new Error("GROK_AUTH_REQUIRED: Grok Build did not advertise a supported non-interactive ACP authentication method; check the harness setup");
|
|
47
|
+
try {
|
|
48
|
+
await client.request("authenticate", { methodId, _meta: { headless: true } }, { timeoutMs: 30_000 });
|
|
49
|
+
}
|
|
50
|
+
catch {
|
|
51
|
+
throw new Error("GROK_AUTH_FAILED: Grok Build rejected ACP authentication; check the harness setup");
|
|
52
|
+
}
|
|
53
|
+
},
|
|
54
|
+
sessionParams(params, request, fresh) {
|
|
55
|
+
// 原生 rules 仅用于新会话;恢复不改系统指令,也不恢复工作区文件快照。
|
|
56
|
+
const rules = initialControlInstructions(request, fresh);
|
|
57
|
+
return {
|
|
58
|
+
...params,
|
|
59
|
+
_meta: {
|
|
60
|
+
yoloMode: request.approvalMode === "full_access",
|
|
61
|
+
autoMode: false,
|
|
62
|
+
...(fresh ? (rules ? { rules } : {}) : { "x.ai/restore_code": false })
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
},
|
|
66
|
+
isMissingSessionError: (error) => error instanceof GrokBuildRpcError &&
|
|
67
|
+
error.code === -32603 &&
|
|
68
|
+
record(error.data).code === "FS_NOT_FOUND",
|
|
69
|
+
selectActmode(_session, sessionId, requested) {
|
|
70
|
+
// 1.0.67 不发布 modes,但实现标准 set_mode(default/plan);成功响应后才发布 applied。
|
|
71
|
+
return {
|
|
72
|
+
method: "session/set_mode",
|
|
73
|
+
params: { sessionId, modeId: requested },
|
|
74
|
+
effective: requested,
|
|
75
|
+
nativeMode: requested,
|
|
76
|
+
unchanged: false
|
|
77
|
+
};
|
|
78
|
+
},
|
|
79
|
+
async *configureSession(client, session, sessionId, request) {
|
|
80
|
+
const requested = request.agentConfig.effort;
|
|
81
|
+
if (requested === undefined)
|
|
82
|
+
return;
|
|
83
|
+
const option = (Array.isArray(session.configOptions) ? session.configOptions : [])
|
|
84
|
+
.map(record)
|
|
85
|
+
.find((value) => value.id === "reasoning_effort");
|
|
86
|
+
const available = (Array.isArray(option?.options) ? option.options : []).map((value) => record(value).value);
|
|
87
|
+
const effective = available.includes(requested)
|
|
88
|
+
? requested
|
|
89
|
+
: requested === "xhigh" && available.includes("high")
|
|
90
|
+
? "high"
|
|
91
|
+
: undefined;
|
|
92
|
+
if (effective === undefined || effective !== requested)
|
|
93
|
+
yield reasoningWarning(request, effective === undefined ? "REASONING_EFFORT_NOT_APPLIED" : "REASONING_EFFORT_DOWNGRADED");
|
|
94
|
+
if (effective !== undefined && option?.currentValue !== effective) {
|
|
95
|
+
const result = record(await client.request("session/set_config_option", {
|
|
96
|
+
sessionId,
|
|
97
|
+
configId: "reasoning_effort",
|
|
98
|
+
value: effective
|
|
99
|
+
}));
|
|
100
|
+
const applied = (Array.isArray(result.configOptions) ? result.configOptions : [])
|
|
101
|
+
.map(record)
|
|
102
|
+
.find((value) => value.id === "reasoning_effort");
|
|
103
|
+
if (applied?.currentValue !== effective)
|
|
104
|
+
throw new Error("GROK_REASONING_UNCONFIRMED: provider did not confirm the requested effort");
|
|
105
|
+
}
|
|
106
|
+
},
|
|
107
|
+
clientOptions(_request, bridge) {
|
|
108
|
+
return {
|
|
109
|
+
requestHandler(method, original) {
|
|
110
|
+
// ACP 扩展仅给方法名加下划线,params 仍为原生请求正文。
|
|
111
|
+
const nativeMethod = method.startsWith("_") ? method.slice(1) : method;
|
|
112
|
+
const params = original;
|
|
113
|
+
if (nativeMethod === "x.ai/ask_user_question") {
|
|
114
|
+
const questions = questionFields(params.questions);
|
|
115
|
+
return bridge.requestQuestion(original, { questions }, (response) => questionResponse(questions, response));
|
|
116
|
+
}
|
|
117
|
+
if (nativeMethod === "x.ai/exit_plan_mode") {
|
|
118
|
+
return bridge.requestQuestion(original, {
|
|
119
|
+
questions: [
|
|
120
|
+
{
|
|
121
|
+
id: "decision",
|
|
122
|
+
question: typeof params.planContent === "string"
|
|
123
|
+
? params.planContent
|
|
124
|
+
: "Review the plan",
|
|
125
|
+
options: [{ label: "Approve" }, { label: "Abandon" }]
|
|
126
|
+
}
|
|
127
|
+
]
|
|
128
|
+
}, (response) => {
|
|
129
|
+
if (response.outcome === "cancelled")
|
|
130
|
+
return { outcome: "cancelled" };
|
|
131
|
+
const answer = answerValues(response, "decision");
|
|
132
|
+
if (answer.length !== 1 || !["Approve", "Abandon"].includes(answer[0]))
|
|
133
|
+
throw new Error("GROK_PLAN_RESPONSE_INVALID");
|
|
134
|
+
return { outcome: answer[0] === "Approve" ? "approved" : "abandoned" };
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
throw new Error("GROK_CLIENT_METHOD_UNSUPPORTED");
|
|
138
|
+
},
|
|
139
|
+
onRequestResponseWritten: (params) => bridge.responseWritten(params),
|
|
140
|
+
onRequestResponseFailed: (params, error) => bridge.responseFailed(params, error)
|
|
141
|
+
};
|
|
142
|
+
},
|
|
143
|
+
validatePromptResult(update) {
|
|
144
|
+
const meta = record(update._meta);
|
|
145
|
+
if (meta.completionKind !== undefined)
|
|
146
|
+
throw new Error("GROK_PROMPT_INCOMPLETE: prompt was removed from the provider queue");
|
|
147
|
+
if (!["end_turn", "cancelled"].includes(String(update.stopReason)))
|
|
148
|
+
throw new Error("GROK_PROMPT_INCOMPLETE: provider did not report end_turn");
|
|
149
|
+
const usage = record(meta.usage);
|
|
150
|
+
const payload = {};
|
|
151
|
+
for (const key of [
|
|
152
|
+
"inputTokens",
|
|
153
|
+
"outputTokens",
|
|
154
|
+
"totalTokens",
|
|
155
|
+
"cachedReadTokens",
|
|
156
|
+
"reasoningTokens"
|
|
157
|
+
]) {
|
|
158
|
+
const value = usage[key] ?? meta[key];
|
|
159
|
+
if (typeof value === "number" && Number.isFinite(value) && value >= 0)
|
|
160
|
+
payload[key] = value;
|
|
161
|
+
}
|
|
162
|
+
if (typeof meta.modelId === "string")
|
|
163
|
+
payload.model = meta.modelId;
|
|
164
|
+
return Object.keys(payload).length
|
|
165
|
+
? [{ protocolVersion: 2, type: "usage.update", payload }]
|
|
166
|
+
: [];
|
|
167
|
+
}
|
|
168
|
+
}, { command, acpClientFactory });
|
|
169
|
+
return Object.freeze({
|
|
170
|
+
...adapter,
|
|
171
|
+
async *invoke(request, context) {
|
|
172
|
+
if (request.agentConfig.sandbox !== undefined)
|
|
173
|
+
throw new Error("SANDBOX_UNSUPPORTED: grok-build ACP has no per-session sandbox override");
|
|
174
|
+
// Grok 的 MCP 配置会展开模板;拒绝不能可靠保留的最终字面量,不改写用户配置。
|
|
175
|
+
const env = invocationEnvironment(request);
|
|
176
|
+
const mcp = invocationMcpServers(request, env);
|
|
177
|
+
if (JSON.stringify(mcp).includes("${"))
|
|
178
|
+
throw new Error("MCP_LITERAL_UNSUPPORTED: grok-build");
|
|
179
|
+
try {
|
|
180
|
+
yield* adapter.invoke(request, context);
|
|
181
|
+
}
|
|
182
|
+
catch (error) {
|
|
183
|
+
throw publicFailure(error, env);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
function publicFailure(error, env) {
|
|
189
|
+
if (record(error).code === "ENOENT")
|
|
190
|
+
return new Error("GROK_START_FAILED: check Grok Build installation, PATH and invocation workdir");
|
|
191
|
+
// 原始 cause/stack 也可能含凭据,公开错误只保留脱敏消息,不挂回原始错误。
|
|
192
|
+
const secrets = Object.entries(env)
|
|
193
|
+
.filter(([key, value]) => value && /token|secret|password|api.?key/i.test(key))
|
|
194
|
+
.map(([, value]) => value)
|
|
195
|
+
.sort((left, right) => right.length - left.length);
|
|
196
|
+
let safe = error instanceof Error ? error.message : "Grok Build ACP invocation failed";
|
|
197
|
+
for (const secret of secrets)
|
|
198
|
+
safe = safe.split(secret).join("[REDACTED]");
|
|
199
|
+
const failure = new Error(safe);
|
|
200
|
+
const details = record(error);
|
|
201
|
+
if (typeof details.code === "string" && /^[A-Z][A-Z0-9_]*$/.test(details.code))
|
|
202
|
+
Object.assign(failure, { code: details.code });
|
|
203
|
+
for (const key of ["boundary", "measuredBytes", "limitBytes", "itemCount", "limitItems"]) {
|
|
204
|
+
const value = details[key];
|
|
205
|
+
if ((key === "boundary" && typeof value === "string" && /^[a-z0-9._-]+$/.test(value)) ||
|
|
206
|
+
(key !== "boundary" && typeof value === "number" && Number.isFinite(value)))
|
|
207
|
+
Object.assign(failure, { [key]: value });
|
|
208
|
+
}
|
|
209
|
+
return failure;
|
|
210
|
+
}
|
|
211
|
+
function reasoningWarning(request, warningCode) {
|
|
212
|
+
return {
|
|
213
|
+
protocolVersion: 2,
|
|
214
|
+
type: "run.notice",
|
|
215
|
+
payload: {
|
|
216
|
+
noticeId: `${request.invocationId}:grok-reasoning`,
|
|
217
|
+
code: "config_warning",
|
|
218
|
+
severity: "warning",
|
|
219
|
+
params: { warningCode }
|
|
220
|
+
}
|
|
221
|
+
};
|
|
222
|
+
}
|
|
223
|
+
function questionFields(value) {
|
|
224
|
+
if (!Array.isArray(value) || value.length === 0 || value.length > 16)
|
|
225
|
+
throw new Error("GROK_QUESTION_INVALID");
|
|
226
|
+
const seen = new Set();
|
|
227
|
+
return value.map((entry, index) => {
|
|
228
|
+
const question = record(entry);
|
|
229
|
+
if (typeof question.question !== "string" || !question.question || seen.has(question.question))
|
|
230
|
+
throw new Error("GROK_QUESTION_INVALID");
|
|
231
|
+
seen.add(question.question);
|
|
232
|
+
return { ...question, id: `q${index}` };
|
|
233
|
+
});
|
|
234
|
+
}
|
|
235
|
+
function answerValues(response, id) {
|
|
236
|
+
if (response.outcome !== "answered")
|
|
237
|
+
throw new Error("GROK_QUESTION_RESPONSE_INVALID");
|
|
238
|
+
const answers = record(record(response.value)[id]).answers;
|
|
239
|
+
if (!Array.isArray(answers) ||
|
|
240
|
+
answers.length === 0 ||
|
|
241
|
+
!answers.every((value) => typeof value === "string" && value.length > 0))
|
|
242
|
+
throw new Error("GROK_QUESTION_RESPONSE_INVALID");
|
|
243
|
+
return answers;
|
|
244
|
+
}
|
|
245
|
+
function questionResponse(questions, response) {
|
|
246
|
+
if (response.outcome === "cancelled")
|
|
247
|
+
return { outcome: "cancelled" };
|
|
248
|
+
const answers = {};
|
|
249
|
+
const annotations = {};
|
|
250
|
+
for (const question of questions) {
|
|
251
|
+
const values = answerValues(response, String(question.id));
|
|
252
|
+
const labels = (Array.isArray(question.options) ? question.options : []).map((option) => record(option).label);
|
|
253
|
+
const selected = values.filter((value) => labels.includes(value));
|
|
254
|
+
const custom = values.filter((value) => !labels.includes(value));
|
|
255
|
+
if (question.multiSelect !== true && values.length !== 1)
|
|
256
|
+
throw new Error("GROK_QUESTION_RESPONSE_INVALID");
|
|
257
|
+
answers[String(question.question)] = custom.length ? [...selected, "Other"] : selected;
|
|
258
|
+
if (custom.length)
|
|
259
|
+
annotations[String(question.question)] = { notes: custom.join("\n") };
|
|
260
|
+
}
|
|
261
|
+
return {
|
|
262
|
+
outcome: "accepted",
|
|
263
|
+
answers,
|
|
264
|
+
...(Object.keys(annotations).length ? { annotations } : {})
|
|
265
|
+
};
|
|
266
|
+
}
|
|
267
|
+
function record(value) {
|
|
268
|
+
return value !== null && typeof value === "object" && !Array.isArray(value)
|
|
269
|
+
? value
|
|
270
|
+
: {};
|
|
271
|
+
}
|
|
272
|
+
export const grokBuildAdapter = createGrokBuildAdapter();
|
|
273
|
+
export default grokBuildAdapter;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { AcpApprovalBridge, type CanonicalEvent, type InvokeRequest } from "@mininglamp-oss/octo-runtime-adapter-sdk";
|
|
2
|
+
import type { InteractionResponse } from "@mininglamp-oss/octo-runtime-protocol";
|
|
3
|
+
type JsonRecord = Record<string, unknown>;
|
|
4
|
+
interface Question {
|
|
5
|
+
params: JsonRecord;
|
|
6
|
+
answer: (response: InteractionResponse) => JsonRecord;
|
|
7
|
+
resolve: (result: JsonRecord) => void;
|
|
8
|
+
reject: (error: Error) => void;
|
|
9
|
+
written: Promise<void>;
|
|
10
|
+
confirm: () => void;
|
|
11
|
+
fail: (error: Error) => void;
|
|
12
|
+
timer: NodeJS.Timeout;
|
|
13
|
+
expiresAt: number;
|
|
14
|
+
responding: boolean;
|
|
15
|
+
}
|
|
16
|
+
/** 标准权限沿用 SDK;原生追问和计划确认只存在于当前 Grok Build 调用。 */
|
|
17
|
+
export declare class GrokBuildInteractionBridge extends AcpApprovalBridge {
|
|
18
|
+
#private;
|
|
19
|
+
constructor(request: InvokeRequest);
|
|
20
|
+
requestQuestion(params: JsonRecord, request: JsonRecord, answer: Question["answer"]): Promise<JsonRecord>;
|
|
21
|
+
respond(response: InteractionResponse): Promise<void>;
|
|
22
|
+
responseWritten(params: JsonRecord): void;
|
|
23
|
+
responseFailed(params: JsonRecord, error: Error): void;
|
|
24
|
+
stream(source: AsyncIterable<CanonicalEvent>): AsyncGenerator<CanonicalEvent>;
|
|
25
|
+
close(reason: string): void;
|
|
26
|
+
}
|
|
27
|
+
export {};
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
import { AcpApprovalBridge, sanitizePublicValue } from "@mininglamp-oss/octo-runtime-adapter-sdk";
|
|
2
|
+
import { randomUUID } from "node:crypto";
|
|
3
|
+
/** 标准权限沿用 SDK;原生追问和计划确认只存在于当前 Grok Build 调用。 */
|
|
4
|
+
export class GrokBuildInteractionBridge extends AcpApprovalBridge {
|
|
5
|
+
#questions = new Map();
|
|
6
|
+
#events = [];
|
|
7
|
+
#wake;
|
|
8
|
+
#error;
|
|
9
|
+
#closed = false;
|
|
10
|
+
constructor(request) {
|
|
11
|
+
super(request);
|
|
12
|
+
}
|
|
13
|
+
requestQuestion(params, request, answer) {
|
|
14
|
+
if (this.#closed || this.request.signal?.aborted || this.#questions.size >= 16)
|
|
15
|
+
return Promise.reject(new Error("APPROVAL_WAIT_UNAVAILABLE"));
|
|
16
|
+
const interactionId = `interaction_${randomUUID()}`;
|
|
17
|
+
const expiresAt = Date.now() + this.timeoutMs;
|
|
18
|
+
let confirm;
|
|
19
|
+
let fail;
|
|
20
|
+
const written = new Promise((resolve, reject) => {
|
|
21
|
+
confirm = resolve;
|
|
22
|
+
fail = reject;
|
|
23
|
+
});
|
|
24
|
+
void written.catch(() => undefined);
|
|
25
|
+
const result = new Promise((resolve, reject) => {
|
|
26
|
+
const timer = setTimeout(() => {
|
|
27
|
+
this.#error = new Error("APPROVAL_EXPIRED");
|
|
28
|
+
this.#questions.delete(interactionId);
|
|
29
|
+
reject(this.#error);
|
|
30
|
+
fail(this.#error);
|
|
31
|
+
this.#resolved(interactionId, "expired", "approval_timeout");
|
|
32
|
+
}, this.timeoutMs);
|
|
33
|
+
timer.unref();
|
|
34
|
+
this.#questions.set(interactionId, {
|
|
35
|
+
params,
|
|
36
|
+
answer,
|
|
37
|
+
resolve,
|
|
38
|
+
reject,
|
|
39
|
+
written,
|
|
40
|
+
confirm,
|
|
41
|
+
fail,
|
|
42
|
+
timer,
|
|
43
|
+
expiresAt,
|
|
44
|
+
responding: false
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
this.#emit({
|
|
48
|
+
protocolVersion: 2,
|
|
49
|
+
type: "interaction.requested",
|
|
50
|
+
payload: {
|
|
51
|
+
interactionId,
|
|
52
|
+
kind: "question",
|
|
53
|
+
executionInstanceId: this.request.invocationId,
|
|
54
|
+
expiresAt: new Date(expiresAt).toISOString(),
|
|
55
|
+
request: sanitizePublicValue(request)
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
return result;
|
|
59
|
+
}
|
|
60
|
+
async respond(response) {
|
|
61
|
+
const pending = this.#questions.get(response.interactionId);
|
|
62
|
+
if (!pending)
|
|
63
|
+
return super.respond(response);
|
|
64
|
+
if (pending.responding || pending.expiresAt <= Date.now() || this.request.signal?.aborted)
|
|
65
|
+
throw new Error("INTERACTION_NOT_ACTIVE");
|
|
66
|
+
const result = pending.answer(response);
|
|
67
|
+
pending.responding = true;
|
|
68
|
+
pending.resolve(result);
|
|
69
|
+
await pending.written;
|
|
70
|
+
if (!this.#questions.has(response.interactionId) || this.#closed)
|
|
71
|
+
throw new Error("INTERACTION_NOT_ACTIVE");
|
|
72
|
+
clearTimeout(pending.timer);
|
|
73
|
+
this.#questions.delete(response.interactionId);
|
|
74
|
+
this.#emit({
|
|
75
|
+
protocolVersion: 2,
|
|
76
|
+
type: "interaction.resolved",
|
|
77
|
+
payload: {
|
|
78
|
+
interactionId: response.interactionId,
|
|
79
|
+
executionInstanceId: this.request.invocationId,
|
|
80
|
+
status: "resolved",
|
|
81
|
+
outcome: response.outcome
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
responseWritten(params) {
|
|
86
|
+
super.responseWritten(params);
|
|
87
|
+
for (const pending of this.#questions.values())
|
|
88
|
+
if (pending.params === params)
|
|
89
|
+
pending.confirm();
|
|
90
|
+
}
|
|
91
|
+
responseFailed(params, error) {
|
|
92
|
+
for (const pending of this.#questions.values())
|
|
93
|
+
if (pending.params === params)
|
|
94
|
+
pending.fail(error);
|
|
95
|
+
this.#error = error;
|
|
96
|
+
super.responseFailed(params, error);
|
|
97
|
+
this.#wake?.();
|
|
98
|
+
}
|
|
99
|
+
async *stream(source) {
|
|
100
|
+
const iterator = super.stream(source);
|
|
101
|
+
let next = iterator.next();
|
|
102
|
+
void next.catch(() => undefined);
|
|
103
|
+
try {
|
|
104
|
+
while (true) {
|
|
105
|
+
while (this.#events.length)
|
|
106
|
+
yield this.#events.shift();
|
|
107
|
+
if (this.#error)
|
|
108
|
+
throw this.#error;
|
|
109
|
+
const wake = new Promise((resolve) => {
|
|
110
|
+
this.#wake = () => resolve(null);
|
|
111
|
+
});
|
|
112
|
+
const result = await Promise.race([next, wake]);
|
|
113
|
+
this.#wake = undefined;
|
|
114
|
+
if (result === null)
|
|
115
|
+
continue;
|
|
116
|
+
while (this.#events.length)
|
|
117
|
+
yield this.#events.shift();
|
|
118
|
+
if (result.done)
|
|
119
|
+
return;
|
|
120
|
+
yield result.value;
|
|
121
|
+
next = iterator.next();
|
|
122
|
+
void next.catch(() => undefined);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
catch (error) {
|
|
126
|
+
this.close("execution_lost");
|
|
127
|
+
while (this.#events.length)
|
|
128
|
+
yield this.#events.shift();
|
|
129
|
+
throw error;
|
|
130
|
+
}
|
|
131
|
+
finally {
|
|
132
|
+
this.close("execution_lost");
|
|
133
|
+
await iterator.return(undefined);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
close(reason) {
|
|
137
|
+
super.close(reason);
|
|
138
|
+
if (this.#closed)
|
|
139
|
+
return;
|
|
140
|
+
this.#closed = true;
|
|
141
|
+
for (const [interactionId, pending] of this.#questions) {
|
|
142
|
+
clearTimeout(pending.timer);
|
|
143
|
+
const error = new Error("INTERACTION_NOT_ACTIVE");
|
|
144
|
+
pending.reject(error);
|
|
145
|
+
pending.fail(error);
|
|
146
|
+
this.#resolved(interactionId, "invalidated", reason);
|
|
147
|
+
}
|
|
148
|
+
this.#questions.clear();
|
|
149
|
+
}
|
|
150
|
+
#resolved(interactionId, status, reasonCode) {
|
|
151
|
+
this.#emit({
|
|
152
|
+
protocolVersion: 2,
|
|
153
|
+
type: "interaction.resolved",
|
|
154
|
+
payload: { interactionId, executionInstanceId: this.request.invocationId, status, reasonCode }
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
#emit(event) {
|
|
158
|
+
this.#events.push(event);
|
|
159
|
+
this.#wake?.();
|
|
160
|
+
}
|
|
161
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@mininglamp-oss/octo-runtime-adapter-grok-build",
|
|
3
|
+
"version": "1.1.2",
|
|
4
|
+
"private": true,
|
|
5
|
+
"type": "module",
|
|
6
|
+
"exports": "./dist/index.js",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"files": [
|
|
9
|
+
"dist"
|
|
10
|
+
],
|
|
11
|
+
"dependencies": {
|
|
12
|
+
"@mininglamp-oss/octo-runtime-acp-client": "1.1.2",
|
|
13
|
+
"@mininglamp-oss/octo-runtime-adapter-acp": "1.1.2",
|
|
14
|
+
"@mininglamp-oss/octo-runtime-adapter-sdk": "1.1.2",
|
|
15
|
+
"@mininglamp-oss/octo-runtime-protocol": "1.1.2"
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mininglamp-oss/octo-runtime-adapter-hermes",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.2",
|
|
4
4
|
"private": true,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": "./dist/index.js",
|
|
@@ -9,6 +9,6 @@
|
|
|
9
9
|
"dist"
|
|
10
10
|
],
|
|
11
11
|
"dependencies": {
|
|
12
|
-
"@mininglamp-oss/octo-runtime-adapter-acp": "1.1.
|
|
12
|
+
"@mininglamp-oss/octo-runtime-adapter-acp": "1.1.2"
|
|
13
13
|
}
|
|
14
14
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mininglamp-oss/octo-runtime-adapter-kimi-code",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.2",
|
|
4
4
|
"private": true,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": "./dist/index.js",
|
|
@@ -9,6 +9,6 @@
|
|
|
9
9
|
"dist"
|
|
10
10
|
],
|
|
11
11
|
"dependencies": {
|
|
12
|
-
"@mininglamp-oss/octo-runtime-adapter-acp": "1.1.
|
|
12
|
+
"@mininglamp-oss/octo-runtime-adapter-acp": "1.1.2"
|
|
13
13
|
}
|
|
14
14
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mininglamp-oss/octo-runtime-adapter-mcode",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.2",
|
|
4
4
|
"private": true,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": "./dist/index.js",
|
|
@@ -9,6 +9,6 @@
|
|
|
9
9
|
"dist"
|
|
10
10
|
],
|
|
11
11
|
"dependencies": {
|
|
12
|
-
"@mininglamp-oss/octo-runtime-adapter-acp": "1.1.
|
|
12
|
+
"@mininglamp-oss/octo-runtime-adapter-acp": "1.1.2"
|
|
13
13
|
}
|
|
14
14
|
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { ApprovalMode } from "@mininglamp-oss/octo-runtime-protocol";
|
|
2
|
+
type JsonRecord = Record<string, unknown>;
|
|
3
|
+
export type GatewayTerminal = "completed" | "failed" | "cancelled";
|
|
4
|
+
export interface GatewayContract {
|
|
5
|
+
version: string;
|
|
6
|
+
family: "legacy" | "session-permissions";
|
|
7
|
+
approvalTransport: boolean;
|
|
8
|
+
scopes?: readonly string[];
|
|
9
|
+
}
|
|
10
|
+
export interface GatewayPermissionPolicy {
|
|
11
|
+
effective: "ask" | "full_access";
|
|
12
|
+
fallbackReason?: string;
|
|
13
|
+
}
|
|
14
|
+
/** 每条连接以真实 hello 选择固定源码核对过的合同;v4 不表示请求字段相同。 */
|
|
15
|
+
export declare function resolveGatewayContract(value: unknown): GatewayContract;
|
|
16
|
+
/** 用户已授权 ask 不可用时向 full 回退;原始请求与 Context 不随 effective 改写。 */
|
|
17
|
+
export declare function resolveGatewayPermission(contract: GatewayContract, requested: ApprovalMode): GatewayPermissionPolicy;
|
|
18
|
+
export declare function gatewayCreateParams(contract: GatewayContract, policy: GatewayPermissionPolicy, params: JsonRecord, requestId: string, thinking: unknown): JsonRecord;
|
|
19
|
+
export declare function gatewayLegacyPermissionParams(key: string): JsonRecord;
|
|
20
|
+
/** 同一执行的中间回执在 RPC 等待、终态归一化和对账中使用同一判定。 */
|
|
21
|
+
export declare function isGatewayRunPending(value: unknown): boolean;
|
|
22
|
+
/** RPC 最终回执、lifecycle 与 agent.wait 共用归一化;超时归因优先于 abort 清理。 */
|
|
23
|
+
export declare function gatewayTerminal(value: unknown, source: "wait" | "final" | "lifecycle"): GatewayTerminal | undefined;
|
|
24
|
+
export {};
|