@mininglamp-oss/octo-runtime 1.0.0-rc1 → 1.0.1
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/apps/cli/dist/build-info.json +3 -2
- package/apps/cli/dist/help.js +15 -6
- package/apps/cli/dist/state.d.ts +1 -0
- package/node_modules/@mininglamp-oss/octo-runtime-acp-client/dist/index.d.ts +4 -1
- package/node_modules/@mininglamp-oss/octo-runtime-acp-client/dist/index.js +14 -7
- 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 +2 -2
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-acp/dist/index.js +5 -4
- 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 +3 -3
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-antigravity/dist/index.js +5 -1
- 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.js +2 -1
- 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 +3 -3
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-codebuddy/dist/index.js +3 -2
- 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.js +19 -6
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-codex/package.json +3 -3
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-hermes/dist/index.d.ts +1 -1
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-hermes/package.json +2 -2
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-host/dist/host-run-service.d.ts +2 -1
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-host/dist/host-run-service.js +29 -11
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-host/dist/index.js +45 -17
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-host/dist/rpc.d.ts +2 -1
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-host/dist/rpc.js +90 -18
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-host/dist/runtime-configuration.js +32 -1
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-host/dist/socket-server.js +6 -1
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-host/package.json +16 -16
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-kimi-code/dist/index.d.ts +1 -1
- 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 +1 -1
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-mcode/package.json +2 -2
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-openclaw/dist/index.js +2 -0
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-openclaw/package.json +4 -4
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-opencode/dist/index.js +1 -1
- 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 +1 -1
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-qodercli/package.json +2 -2
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-qoderclicn/dist/index.d.ts +1 -1
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-qoderclicn/package.json +2 -2
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-sdk/dist/activity.d.ts +2 -1
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-sdk/dist/index.d.ts +3 -1
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-sdk/dist/index.js +5 -3
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-sdk/dist/line-limit.js +15 -4
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-sdk/dist/native.d.ts +4 -1
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-sdk/dist/native.js +29 -4
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-sdk/package.json +2 -2
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-zcode-gui/dist/app-server.d.ts +1 -1
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-zcode-gui/dist/app-server.js +17 -11
- 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 +3 -2
- package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/help.js +15 -6
- package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/state.d.ts +1 -0
- package/node_modules/@mininglamp-oss/octo-runtime-cli/package.json +8 -8
- package/node_modules/@mininglamp-oss/octo-runtime-core/package.json +2 -2
- package/node_modules/@mininglamp-oss/octo-runtime-cross-service/package.json +1 -1
- package/node_modules/@mininglamp-oss/octo-runtime-daemon/dist/runtime/run-stream.js +29 -12
- package/node_modules/@mininglamp-oss/octo-runtime-daemon/dist/server.js +7 -1
- package/node_modules/@mininglamp-oss/octo-runtime-daemon/package.json +17 -17
- package/node_modules/@mininglamp-oss/octo-runtime-daemon-app/package.json +7 -7
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/application/context-gap.d.ts +34 -0
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/application/context-gap.js +124 -0
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/application/im-channel.js +152 -9
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/application/session-store.d.ts +4 -0
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/application/session-store.js +32 -0
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/contracts.d.ts +16 -0
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/execution/dispatcher.js +54 -4
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/presentation/run-projector.js +4 -1
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/api/conversations.d.ts +5 -0
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/api/conversations.js +8 -2
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/channel.js +49 -2
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/contexts.d.ts +4 -1
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/contexts.js +94 -15
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/normalize.d.ts +1 -0
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/normalize.js +10 -5
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/reasoning-frame.js +5 -1
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/wukong.d.ts +19 -2
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/wukong.js +30 -4
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/package.json +7 -7
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-wecom/dist/application/im-channel.js +3 -2
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-wecom/package.json +6 -6
- package/node_modules/@mininglamp-oss/octo-runtime-extra-webui/dist/web/assets/index-DiPc-ipL.js +74 -0
- package/node_modules/@mininglamp-oss/octo-runtime-extra-webui/dist/web/index.html +1 -1
- package/node_modules/@mininglamp-oss/octo-runtime-extra-webui/package.json +2 -2
- package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/failure.d.ts +4 -0
- package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/failure.js +30 -1
- package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/generated/protocol-types.d.ts +2 -1
- package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/index.d.ts +1 -0
- package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/index.js +1 -0
- package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/invoke-input.d.ts +3 -0
- package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/invoke-size.js +2 -1
- package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/run-protocol.d.ts +1 -1
- package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/run-protocol.js +51 -4
- package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/stream-limits.d.ts +27 -0
- package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/stream-limits.js +56 -0
- package/node_modules/@mininglamp-oss/octo-runtime-protocol/package.json +1 -1
- package/node_modules/ws/lib/websocket.js +17 -3
- package/node_modules/ws/package.json +1 -1
- package/package.json +27 -27
- package/node_modules/@mininglamp-oss/octo-runtime-extra-webui/dist/web/assets/index-B6Yp4xkI.js +0 -76
package/apps/cli/dist/help.js
CHANGED
|
@@ -3,16 +3,25 @@ import { fileURLToPath } from "node:url";
|
|
|
3
3
|
// Read the public release package, rather than the private CLI workspace version.
|
|
4
4
|
const releasePackage = JSON.parse(readFileSync(new URL("../../../package.json", import.meta.url), "utf8"));
|
|
5
5
|
export const cliVersion = releasePackage.version;
|
|
6
|
-
let buildInfo = {
|
|
6
|
+
let buildInfo = {};
|
|
7
7
|
try {
|
|
8
|
-
|
|
8
|
+
const metadata = JSON.parse(readFileSync(new URL("./build-info.json", import.meta.url), "utf8"));
|
|
9
|
+
if (metadata !== null && typeof metadata === "object")
|
|
10
|
+
buildInfo = metadata;
|
|
9
11
|
}
|
|
10
12
|
catch (error) {
|
|
11
|
-
if (error.code !== "ENOENT")
|
|
13
|
+
if (!(error instanceof SyntaxError) && error.code !== "ENOENT")
|
|
12
14
|
throw error;
|
|
13
15
|
}
|
|
14
|
-
const cliCommitInfo = `commit:${buildInfo.commit
|
|
15
|
-
|
|
16
|
+
const cliCommitInfo = `commit:${typeof buildInfo.commit === "string" ? buildInfo.commit.slice(0, 12) : "unknown"}${buildInfo.dirty === true ? " (dirty)" : ""}`;
|
|
17
|
+
const buildTime = buildInfo.buildTime;
|
|
18
|
+
const validBuildTime = typeof buildTime === "string" &&
|
|
19
|
+
/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d{3})?Z$/.test(buildTime) &&
|
|
20
|
+
Number.isFinite(Date.parse(buildTime)) &&
|
|
21
|
+
new Date(buildTime).toISOString() ===
|
|
22
|
+
(buildTime.includes(".") ? buildTime : buildTime.replace("Z", ".000Z"));
|
|
23
|
+
const cliBuildInfo = `build:${validBuildTime ? buildTime : "unknown"}`;
|
|
24
|
+
export const cliVersionInfo = `${cliVersion}\n${cliCommitInfo}\n${cliBuildInfo}`;
|
|
16
25
|
const commands = {
|
|
17
26
|
description: "Manage the local Agent runtime, provider adapters, and background service.\nBuilt-in adapters work by default; no adapter configuration is required.",
|
|
18
27
|
children: {
|
|
@@ -108,7 +117,7 @@ export function helpText(path = []) {
|
|
|
108
117
|
const command = commandAt(path);
|
|
109
118
|
const invocation = ["octo-runtime", ...path].join(" ");
|
|
110
119
|
const sections = [
|
|
111
|
-
...(path.length ? [] : [`Octo Runtime CLI (${cliVersion})\n${cliCommitInfo}`]),
|
|
120
|
+
...(path.length ? [] : [`Octo Runtime CLI (${cliVersion})\n${cliCommitInfo}\n${cliBuildInfo}`]),
|
|
112
121
|
command.description,
|
|
113
122
|
...(command.details ? [command.details] : []),
|
|
114
123
|
`Usage:\n ${invocation}${command.children ? " [command]" : command.usage ? ` ${command.usage}` : ""} [flags]`,
|
package/apps/cli/dist/state.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type StreamLimitPolicy } from "@mininglamp-oss/octo-runtime-protocol";
|
|
1
2
|
import { type ChildProcessWithoutNullStreams } from "node:child_process";
|
|
2
3
|
type JsonRecord = Record<string, unknown>;
|
|
3
4
|
type PermissionHandler = (params: JsonRecord) => unknown;
|
|
@@ -17,6 +18,7 @@ export interface SpawnAcpClientOptions {
|
|
|
17
18
|
permissionHandler?: PermissionHandler;
|
|
18
19
|
onPermissionResponseWritten?: (params: JsonRecord) => void;
|
|
19
20
|
onPermissionResponseFailed?: (params: JsonRecord, error: Error) => void;
|
|
21
|
+
streamLimits?: StreamLimitPolicy;
|
|
20
22
|
}
|
|
21
23
|
export interface AcpRequestOptions {
|
|
22
24
|
timeoutMs?: number;
|
|
@@ -54,12 +56,13 @@ export declare function acpPromptParams(sessionId: string, input: string | reado
|
|
|
54
56
|
*/
|
|
55
57
|
export declare class AcpClient {
|
|
56
58
|
#private;
|
|
57
|
-
constructor({ child, permissionHandler, onPermissionResponseWritten, onPermissionResponseFailed, processGroup }: {
|
|
59
|
+
constructor({ child, permissionHandler, onPermissionResponseWritten, onPermissionResponseFailed, streamLimits, processGroup }: {
|
|
58
60
|
child: ChildProcessWithoutNullStreams;
|
|
59
61
|
processGroup?: boolean;
|
|
60
62
|
permissionHandler?: PermissionHandler;
|
|
61
63
|
onPermissionResponseWritten?: (params: JsonRecord) => void;
|
|
62
64
|
onPermissionResponseFailed?: (params: JsonRecord, error: Error) => void;
|
|
65
|
+
streamLimits?: StreamLimitPolicy;
|
|
63
66
|
});
|
|
64
67
|
/**
|
|
65
68
|
* Allocate the JSON-RPC id that a later request will put on the wire. This
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { DriverQueue, watchLineLimit } from "@mininglamp-oss/octo-runtime-adapter-sdk";
|
|
2
|
-
import { INVOKE_REQUEST_MAX_BYTES } from "@mininglamp-oss/octo-runtime-protocol";
|
|
2
|
+
import { INVOKE_REQUEST_MAX_BYTES, resolveStreamLimitPolicy } from "@mininglamp-oss/octo-runtime-protocol";
|
|
3
3
|
import { createProcessCleanup } from "@mininglamp-oss/octo-runtime-adapter-sdk/process-cleanup";
|
|
4
4
|
import { spawn } from "node:child_process";
|
|
5
5
|
import { createInterface } from "node:readline";
|
|
@@ -46,8 +46,11 @@ export class AcpClient {
|
|
|
46
46
|
#closePromise;
|
|
47
47
|
#reader;
|
|
48
48
|
#removeLineGuard;
|
|
49
|
-
#lineLimit
|
|
50
|
-
|
|
49
|
+
#lineLimit;
|
|
50
|
+
#streamLimits;
|
|
51
|
+
constructor({ child, permissionHandler, onPermissionResponseWritten, onPermissionResponseFailed, streamLimits, processGroup = false }) {
|
|
52
|
+
this.#streamLimits = resolveStreamLimitPolicy(streamLimits);
|
|
53
|
+
this.#lineLimit = this.#streamLimits.rawMessageMaxBytes;
|
|
51
54
|
this.#child = child;
|
|
52
55
|
this.#cleanup = createProcessCleanup(child, { processGroup });
|
|
53
56
|
this.#permission = permissionHandler ?? denyPermission;
|
|
@@ -66,6 +69,7 @@ export class AcpClient {
|
|
|
66
69
|
// S04:在 readline / JSON.parse 前限长;图片输入的原生回显沿整请求上限。
|
|
67
70
|
// .octospec/tasks/pr1-yujiawei-review/assessment.md
|
|
68
71
|
this.#removeLineGuard = watchLineLimit(child.stdout, () => this.#lineLimit, (error) => {
|
|
72
|
+
Object.assign(error, { boundary: "acp.stdout" });
|
|
69
73
|
this.#failAll(error);
|
|
70
74
|
child.stdout.destroy();
|
|
71
75
|
});
|
|
@@ -256,9 +260,11 @@ export class AcpClient {
|
|
|
256
260
|
Array.isArray(params.prompt) &&
|
|
257
261
|
params.prompt.some((part) => isRecord(part) && part.type === "image")
|
|
258
262
|
? INVOKE_REQUEST_MAX_BYTES
|
|
259
|
-
:
|
|
263
|
+
: this.#streamLimits.rawMessageMaxBytes;
|
|
260
264
|
const queue = new DriverQueue({
|
|
261
265
|
discardOnFailure: true,
|
|
266
|
+
limits: this.#streamLimits,
|
|
267
|
+
boundary: "acp.update_queue",
|
|
262
268
|
onFailure: (error) => this.#failAll(error)
|
|
263
269
|
});
|
|
264
270
|
this.#updates.set(sessionId, queue);
|
|
@@ -293,7 +299,7 @@ export class AcpClient {
|
|
|
293
299
|
}
|
|
294
300
|
finally {
|
|
295
301
|
queue.drain();
|
|
296
|
-
this.#lineLimit =
|
|
302
|
+
this.#lineLimit = this.#streamLimits.rawMessageMaxBytes;
|
|
297
303
|
this.#updates.delete(sessionId);
|
|
298
304
|
}
|
|
299
305
|
}
|
|
@@ -317,7 +323,7 @@ export class AcpClient {
|
|
|
317
323
|
* whole tree; aborting `signal` closes the client (and thus the process).
|
|
318
324
|
*/
|
|
319
325
|
export function spawnAcpClient(options) {
|
|
320
|
-
const { command, args = [], cwd, env, signal, permissionHandler, onPermissionResponseWritten, onPermissionResponseFailed } = options;
|
|
326
|
+
const { command, args = [], cwd, env, signal, permissionHandler, onPermissionResponseWritten, onPermissionResponseFailed, streamLimits } = options;
|
|
321
327
|
const child = spawn(command, args, {
|
|
322
328
|
cwd,
|
|
323
329
|
env: { ...process.env, ...env },
|
|
@@ -329,7 +335,8 @@ export function spawnAcpClient(options) {
|
|
|
329
335
|
processGroup: process.platform !== "win32",
|
|
330
336
|
permissionHandler,
|
|
331
337
|
onPermissionResponseWritten,
|
|
332
|
-
onPermissionResponseFailed
|
|
338
|
+
onPermissionResponseFailed,
|
|
339
|
+
streamLimits
|
|
333
340
|
});
|
|
334
341
|
const abort = () => {
|
|
335
342
|
// 异步取消先启动清理;调用方随后 await close 仍取得同一失败。
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mininglamp-oss/octo-runtime-acp-client",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"private": true,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": "./dist/index.js",
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
"dist"
|
|
10
10
|
],
|
|
11
11
|
"dependencies": {
|
|
12
|
-
"@mininglamp-oss/octo-runtime-adapter-sdk": "1.0.
|
|
13
|
-
"@mininglamp-oss/octo-runtime-protocol": "1.0.
|
|
12
|
+
"@mininglamp-oss/octo-runtime-adapter-sdk": "1.0.1",
|
|
13
|
+
"@mininglamp-oss/octo-runtime-protocol": "1.0.1"
|
|
14
14
|
}
|
|
15
15
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { spawnAcpClient, type AcpUpdate } from "@mininglamp-oss/octo-runtime-acp-client";
|
|
2
|
-
import { type CanonicalEvent, type InvokeRequest } from "@mininglamp-oss/octo-runtime-adapter-sdk";
|
|
2
|
+
import { type AdapterInvocationContext, type CanonicalEvent, type InvokeRequest } from "@mininglamp-oss/octo-runtime-adapter-sdk";
|
|
3
3
|
import { type InteractionResponse } from "@mininglamp-oss/octo-runtime-protocol";
|
|
4
4
|
type JsonRecord = Record<string, unknown>;
|
|
5
5
|
export interface AcpAdapterDefinition {
|
|
@@ -50,6 +50,6 @@ export declare function createAcpAdapter(definition: AcpAdapterDefinition, { acp
|
|
|
50
50
|
};
|
|
51
51
|
probe: () => Promise<import("@mininglamp-oss/octo-runtime-adapter-sdk").ProbeResult>;
|
|
52
52
|
respondInteraction(invocationId: string, response: InteractionResponse): Promise<void>;
|
|
53
|
-
invoke(request: InvokeRequest): AsyncGenerator<CanonicalEvent>;
|
|
53
|
+
invoke(request: InvokeRequest, context?: AdapterInvocationContext): AsyncGenerator<CanonicalEvent>;
|
|
54
54
|
}>;
|
|
55
55
|
export {};
|
|
@@ -149,7 +149,7 @@ export function createAcpAdapter(definition, { acpClientFactory = spawnAcpClient
|
|
|
149
149
|
throw new Error("INTERACTION_NOT_ACTIVE");
|
|
150
150
|
await bridge.respond(response);
|
|
151
151
|
},
|
|
152
|
-
async *invoke(request) {
|
|
152
|
+
async *invoke(request, context) {
|
|
153
153
|
if (request.approvalMode !== "ask" && request.approvalMode !== "full_access")
|
|
154
154
|
throw new Error("APPROVAL_MODE_UNSUPPORTED: this ACP adapter has no assisted policy");
|
|
155
155
|
if (responders.has(request.invocationId))
|
|
@@ -157,7 +157,7 @@ export function createAcpAdapter(definition, { acpClientFactory = spawnAcpClient
|
|
|
157
157
|
const bridge = new AcpApprovalBridge(request);
|
|
158
158
|
responders.set(request.invocationId, bridge);
|
|
159
159
|
try {
|
|
160
|
-
yield* bridge.stream(execute(request, bridge));
|
|
160
|
+
yield* bridge.stream(execute(request, bridge, context));
|
|
161
161
|
}
|
|
162
162
|
finally {
|
|
163
163
|
bridge.close("execution_lost");
|
|
@@ -165,7 +165,7 @@ export function createAcpAdapter(definition, { acpClientFactory = spawnAcpClient
|
|
|
165
165
|
}
|
|
166
166
|
}
|
|
167
167
|
}, null); // ACP transports currently have no implemented reasoning setter.
|
|
168
|
-
async function* execute(request, bridge) {
|
|
168
|
+
async function* execute(request, bridge, context) {
|
|
169
169
|
const args = typeof definition.args === "function"
|
|
170
170
|
? definition.args(request)
|
|
171
171
|
: (definition.args ?? ["acp"]);
|
|
@@ -192,7 +192,8 @@ export function createAcpAdapter(definition, { acpClientFactory = spawnAcpClient
|
|
|
192
192
|
cwd: request.workdir,
|
|
193
193
|
permissionHandler: (params) => bridge.requestPermission(params),
|
|
194
194
|
onPermissionResponseWritten: (params) => bridge.responseWritten(params),
|
|
195
|
-
onPermissionResponseFailed: (params, error) => bridge.responseFailed(params, error)
|
|
195
|
+
onPermissionResponseFailed: (params, error) => bridge.responseFailed(params, error),
|
|
196
|
+
...(context?.streamLimits ? { streamLimits: context.streamLimits } : {})
|
|
196
197
|
});
|
|
197
198
|
bridge.bindTransport(() => client.close());
|
|
198
199
|
let sessionId;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mininglamp-oss/octo-runtime-adapter-acp",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"private": true,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": "./dist/index.js",
|
|
@@ -9,8 +9,8 @@
|
|
|
9
9
|
"dist"
|
|
10
10
|
],
|
|
11
11
|
"dependencies": {
|
|
12
|
-
"@mininglamp-oss/octo-runtime-protocol": "1.0.
|
|
13
|
-
"@mininglamp-oss/octo-runtime-acp-client": "1.0.
|
|
14
|
-
"@mininglamp-oss/octo-runtime-adapter-sdk": "1.0.
|
|
12
|
+
"@mininglamp-oss/octo-runtime-protocol": "1.0.1",
|
|
13
|
+
"@mininglamp-oss/octo-runtime-acp-client": "1.0.1",
|
|
14
|
+
"@mininglamp-oss/octo-runtime-adapter-sdk": "1.0.1"
|
|
15
15
|
}
|
|
16
16
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type CanonicalEvent, type CommandSpec, type InvokeRequest } from "@mininglamp-oss/octo-runtime-adapter-sdk";
|
|
1
|
+
import { type CanonicalEvent, type CommandSpec, type AdapterInvocationContext, type InvokeRequest } from "@mininglamp-oss/octo-runtime-adapter-sdk";
|
|
2
2
|
interface NativeUsage {
|
|
3
3
|
input_tokens?: number;
|
|
4
4
|
output_tokens?: number;
|
|
@@ -54,7 +54,7 @@ export declare function createAntigravityAdapter({ command, commandArgsPrefix }?
|
|
|
54
54
|
transport: string;
|
|
55
55
|
};
|
|
56
56
|
probe: () => Promise<import("@mininglamp-oss/octo-runtime-adapter-sdk").ProbeResult>;
|
|
57
|
-
invoke(request: InvokeRequest): AsyncGenerator<CanonicalEvent>;
|
|
57
|
+
invoke(request: InvokeRequest, context?: AdapterInvocationContext): AsyncGenerator<CanonicalEvent>;
|
|
58
58
|
}>;
|
|
59
59
|
export declare const antigravityAdapter: Readonly<{
|
|
60
60
|
metadata: {
|
|
@@ -64,6 +64,6 @@ export declare const antigravityAdapter: Readonly<{
|
|
|
64
64
|
transport: string;
|
|
65
65
|
};
|
|
66
66
|
probe: () => Promise<import("@mininglamp-oss/octo-runtime-adapter-sdk").ProbeResult>;
|
|
67
|
-
invoke(request: InvokeRequest): AsyncGenerator<CanonicalEvent>;
|
|
67
|
+
invoke(request: InvokeRequest, context?: AdapterInvocationContext): AsyncGenerator<CanonicalEvent>;
|
|
68
68
|
}>;
|
|
69
69
|
export default antigravityAdapter;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { initialControlInstructions, defineAdapter, hasImageInput, invocationEnvironment, mapReasoningEffort, parseJsonLine, probeCommand, providerInputText, spawnJsonLines } from "@mininglamp-oss/octo-runtime-adapter-sdk";
|
|
2
|
+
import { isStreamCapacityReason } from "@mininglamp-oss/octo-runtime-protocol";
|
|
2
3
|
import { mkdtemp, readFile, rm } from "node:fs/promises";
|
|
3
4
|
import { tmpdir } from "node:os";
|
|
4
5
|
import { join } from "node:path";
|
|
@@ -340,7 +341,7 @@ export function createAntigravityAdapter({ command = "agy", commandArgsPrefix =
|
|
|
340
341
|
return { ...result, available: false, reason: "provider_version_unsupported" };
|
|
341
342
|
return result;
|
|
342
343
|
},
|
|
343
|
-
async *invoke(request) {
|
|
344
|
+
async *invoke(request, context) {
|
|
344
345
|
buildAntigravityCommand(request, command, commandArgsPrefix);
|
|
345
346
|
const directory = await mkdtemp(join(tmpdir(), "octo-runtime-antigravity-"));
|
|
346
347
|
const logPath = join(directory, "cli.log");
|
|
@@ -386,6 +387,7 @@ export function createAntigravityAdapter({ command = "agy", commandArgsPrefix =
|
|
|
386
387
|
...spec,
|
|
387
388
|
env: invocationEnvironment(request, spec.env),
|
|
388
389
|
signal: controller.signal,
|
|
390
|
+
rawMessageMaxBytes: context?.streamLimits?.rawMessageMaxBytes,
|
|
389
391
|
parseLine: (line) => {
|
|
390
392
|
if (!line.trim())
|
|
391
393
|
return null;
|
|
@@ -403,6 +405,8 @@ export function createAntigravityAdapter({ command = "agy", commandArgsPrefix =
|
|
|
403
405
|
}
|
|
404
406
|
}
|
|
405
407
|
catch (error) {
|
|
408
|
+
if (error instanceof Error && isStreamCapacityReason(Reflect.get(error, "code")))
|
|
409
|
+
throw error;
|
|
406
410
|
providerError ??= error instanceof Error ? error : new Error(String(error));
|
|
407
411
|
}
|
|
408
412
|
finally {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mininglamp-oss/octo-runtime-adapter-antigravity",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"private": true,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": "./dist/index.js",
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
"README.md"
|
|
11
11
|
],
|
|
12
12
|
"dependencies": {
|
|
13
|
-
"@mininglamp-oss/octo-runtime-adapter-sdk": "1.0.
|
|
14
|
-
"@mininglamp-oss/octo-runtime-protocol": "1.0.
|
|
13
|
+
"@mininglamp-oss/octo-runtime-adapter-sdk": "1.0.1",
|
|
14
|
+
"@mininglamp-oss/octo-runtime-protocol": "1.0.1"
|
|
15
15
|
}
|
|
16
16
|
}
|
|
@@ -571,7 +571,7 @@ export function createClaudeCodeAdapter({ command = "claude", commandArgsPrefix
|
|
|
571
571
|
if (context?.protocolMode === "native") {
|
|
572
572
|
if (nativeResponders.has(request.invocationId))
|
|
573
573
|
throw new Error("INVOCATION_ALREADY_ACTIVE");
|
|
574
|
-
const bridge = new NativeInteractionBridge();
|
|
574
|
+
const bridge = new NativeInteractionBridge(context?.streamLimits);
|
|
575
575
|
nativeResponders.set(request.invocationId, bridge);
|
|
576
576
|
try {
|
|
577
577
|
yield* bridge.stream(execute(request, bridge, context));
|
|
@@ -620,6 +620,7 @@ export function createClaudeCodeAdapter({ command = "claude", commandArgsPrefix
|
|
|
620
620
|
cwd: request.workdir,
|
|
621
621
|
env: invocationEnvironment(request),
|
|
622
622
|
signal: request.signal,
|
|
623
|
+
rawMessageMaxBytes: context?.streamLimits?.rawMessageMaxBytes,
|
|
623
624
|
onSpawn: (close) => permissions.bindTransport(close),
|
|
624
625
|
endInputWhen: (native) => native.type === "result",
|
|
625
626
|
controlHandler: async (native, write) => {
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mininglamp-oss/octo-runtime-adapter-claude-code",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"private": true,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": "./dist/index.js",
|
|
7
7
|
"dependencies": {
|
|
8
|
-
"@mininglamp-oss/octo-runtime-protocol": "1.0.
|
|
9
|
-
"@mininglamp-oss/octo-runtime-adapter-sdk": "1.0.
|
|
8
|
+
"@mininglamp-oss/octo-runtime-protocol": "1.0.1",
|
|
9
|
+
"@mininglamp-oss/octo-runtime-adapter-sdk": "1.0.1"
|
|
10
10
|
},
|
|
11
11
|
"types": "./dist/index.d.ts",
|
|
12
12
|
"files": [
|
|
@@ -6,7 +6,7 @@ import { type InteractionResponse } from "@mininglamp-oss/octo-runtime-protocol"
|
|
|
6
6
|
*/
|
|
7
7
|
import type { AcpUpdate } from "@mininglamp-oss/octo-runtime-acp-client";
|
|
8
8
|
import { spawnAcpClient } from "@mininglamp-oss/octo-runtime-acp-client";
|
|
9
|
-
import { type CanonicalEvent, type InvokeRequest } from "@mininglamp-oss/octo-runtime-adapter-sdk";
|
|
9
|
+
import { type AdapterInvocationContext, type CanonicalEvent, type InvokeRequest } from "@mininglamp-oss/octo-runtime-adapter-sdk";
|
|
10
10
|
/** One ACP `session/update` notification; fields are optional because their presence depends on `sessionUpdate`. */
|
|
11
11
|
interface CodeBuddyUpdate extends AcpUpdate {
|
|
12
12
|
sessionUpdate?: string;
|
|
@@ -38,7 +38,7 @@ export declare function createCodeBuddyAdapter({ acpClientFactory, command }?: {
|
|
|
38
38
|
};
|
|
39
39
|
probe: () => Promise<import("@mininglamp-oss/octo-runtime-adapter-sdk").ProbeResult>;
|
|
40
40
|
respondInteraction(invocationId: string, response: InteractionResponse): Promise<void>;
|
|
41
|
-
invoke(req: InvokeRequest): AsyncGenerator<CanonicalEvent>;
|
|
41
|
+
invoke(req: InvokeRequest, context?: AdapterInvocationContext): AsyncGenerator<CanonicalEvent>;
|
|
42
42
|
}>;
|
|
43
43
|
export declare function codeBuddyPermissionMode(mode: InvokeRequest["approvalMode"]): string;
|
|
44
44
|
export declare const codebuddyAdapter: Readonly<{
|
|
@@ -48,6 +48,6 @@ export declare const codebuddyAdapter: Readonly<{
|
|
|
48
48
|
};
|
|
49
49
|
probe: () => Promise<import("@mininglamp-oss/octo-runtime-adapter-sdk").ProbeResult>;
|
|
50
50
|
respondInteraction(invocationId: string, response: InteractionResponse): Promise<void>;
|
|
51
|
-
invoke(req: InvokeRequest): AsyncGenerator<CanonicalEvent>;
|
|
51
|
+
invoke(req: InvokeRequest, context?: AdapterInvocationContext): AsyncGenerator<CanonicalEvent>;
|
|
52
52
|
}>;
|
|
53
53
|
export default codebuddyAdapter;
|
|
@@ -88,7 +88,7 @@ export function createCodeBuddyAdapter({ acpClientFactory = spawnAcpClient, comm
|
|
|
88
88
|
throw new Error("INTERACTION_NOT_ACTIVE");
|
|
89
89
|
await bridge.respond(response);
|
|
90
90
|
},
|
|
91
|
-
async *invoke(req) {
|
|
91
|
+
async *invoke(req, context) {
|
|
92
92
|
if (hasImageInput(req))
|
|
93
93
|
throw new Error("UNSUPPORTED_INPUT_MODALITY: codebuddy does not encode image input");
|
|
94
94
|
if (responders.has(req.invocationId))
|
|
@@ -104,7 +104,8 @@ export function createCodeBuddyAdapter({ acpClientFactory = spawnAcpClient, comm
|
|
|
104
104
|
signal: req.signal,
|
|
105
105
|
permissionHandler: (params) => permissions.requestPermission(params),
|
|
106
106
|
onPermissionResponseWritten: (params) => permissions.responseWritten(params),
|
|
107
|
-
onPermissionResponseFailed: (params, error) => permissions.responseFailed(params, error)
|
|
107
|
+
onPermissionResponseFailed: (params, error) => permissions.responseFailed(params, error),
|
|
108
|
+
...(context?.streamLimits ? { streamLimits: context.streamLimits } : {})
|
|
108
109
|
}));
|
|
109
110
|
permissions.bindTransport(() => client.close());
|
|
110
111
|
try {
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mininglamp-oss/octo-runtime-adapter-codebuddy",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"private": true,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": "./dist/index.js",
|
|
7
7
|
"dependencies": {
|
|
8
|
-
"@mininglamp-oss/octo-runtime-protocol": "1.0.
|
|
9
|
-
"@mininglamp-oss/octo-runtime-acp-client": "1.0.
|
|
10
|
-
"@mininglamp-oss/octo-runtime-adapter-sdk": "1.0.
|
|
8
|
+
"@mininglamp-oss/octo-runtime-protocol": "1.0.1",
|
|
9
|
+
"@mininglamp-oss/octo-runtime-acp-client": "1.0.1",
|
|
10
|
+
"@mininglamp-oss/octo-runtime-adapter-sdk": "1.0.1"
|
|
11
11
|
},
|
|
12
12
|
"types": "./dist/index.d.ts",
|
|
13
13
|
"files": [
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { actmodeEvidence, invocationEnvs, mapReasoningEffort } from "@mininglamp-oss/octo-runtime-adapter-sdk";
|
|
2
|
-
import { canonicalTerminalStatus, classifyFailure, contextHash, contextActmode, assertJsonByteLimit, INVOKE_REQUEST_MAX_BYTES, hasImageInput, providerInputParts, PROVIDER_DIAGNOSTIC_MAX_BYTES } from "@mininglamp-oss/octo-runtime-protocol";
|
|
2
|
+
import { canonicalTerminalStatus, classifyFailure, contextHash, contextActmode, assertJsonByteLimit, INVOKE_REQUEST_MAX_BYTES, hasImageInput, providerInputParts, PROVIDER_DIAGNOSTIC_MAX_BYTES, resolveStreamLimitPolicy, streamCapacityError } from "@mininglamp-oss/octo-runtime-protocol";
|
|
3
3
|
import { codexEnvironmentConfig } from "./environment.js";
|
|
4
4
|
import { createProcessCleanup } from "@mininglamp-oss/octo-runtime-adapter-sdk/process-cleanup";
|
|
5
5
|
/**
|
|
@@ -996,7 +996,8 @@ class CodexAppServerClient {
|
|
|
996
996
|
#closePromise;
|
|
997
997
|
#reader;
|
|
998
998
|
#removeLineGuard;
|
|
999
|
-
#queue
|
|
999
|
+
#queue;
|
|
1000
|
+
#streamLimits;
|
|
1000
1001
|
#normalizer;
|
|
1001
1002
|
#native;
|
|
1002
1003
|
#pending = new Map();
|
|
@@ -1146,6 +1147,11 @@ class CodexAppServerClient {
|
|
|
1146
1147
|
constructor(spec, spawnFn, requestTimeoutMs, interactive, invocation, context) {
|
|
1147
1148
|
this.invocation = invocation;
|
|
1148
1149
|
this.context = context;
|
|
1150
|
+
this.#streamLimits = resolveStreamLimitPolicy(context?.streamLimits);
|
|
1151
|
+
this.#queue = new DriverQueue({
|
|
1152
|
+
limits: this.#streamLimits,
|
|
1153
|
+
boundary: "codex.event_queue"
|
|
1154
|
+
});
|
|
1149
1155
|
this.#native = context?.protocolMode === "native";
|
|
1150
1156
|
if (!this.#native)
|
|
1151
1157
|
this.#normalizer = new CodexEventNormalizer();
|
|
@@ -1162,7 +1168,9 @@ class CodexAppServerClient {
|
|
|
1162
1168
|
processGroup: isolatedProcessGroups.has(this.#child)
|
|
1163
1169
|
});
|
|
1164
1170
|
// The app-server protocol requires one JSON-RPC frame per line; readline handles chunk boundaries.
|
|
1165
|
-
const transportLimit = !this.#native && hasImageInput(invocation)
|
|
1171
|
+
const transportLimit = !this.#native && hasImageInput(invocation)
|
|
1172
|
+
? INVOKE_REQUEST_MAX_BYTES
|
|
1173
|
+
: this.#streamLimits.rawMessageMaxBytes;
|
|
1166
1174
|
this.#removeLineGuard = watchLineLimit(this.#child.stdout, transportLimit, (error) => {
|
|
1167
1175
|
this.#reader.close();
|
|
1168
1176
|
this.#child.stdout.destroy();
|
|
@@ -1418,8 +1426,13 @@ class CodexAppServerClient {
|
|
|
1418
1426
|
/** Dispatch one stdout frame. Ordering of the checks matters: a response may also lack a method. */
|
|
1419
1427
|
#handleLine(line) {
|
|
1420
1428
|
const message = parseRecord(line);
|
|
1421
|
-
|
|
1422
|
-
|
|
1429
|
+
const bytes = Buffer.byteLength(line);
|
|
1430
|
+
if (bytes > this.#streamLimits.rawMessageMaxBytes && !this.#isBoundedInputEcho(message)) {
|
|
1431
|
+
const error = streamCapacityError("PROVIDER_MESSAGE_TOO_LARGE", {
|
|
1432
|
+
boundary: "codex.stdout",
|
|
1433
|
+
measuredBytes: bytes,
|
|
1434
|
+
limitBytes: this.#streamLimits.rawMessageMaxBytes
|
|
1435
|
+
});
|
|
1423
1436
|
this.#rejectPending(error);
|
|
1424
1437
|
this.#queue.fail(error);
|
|
1425
1438
|
signalProcessTree(this.#child, "SIGTERM");
|
|
@@ -1528,7 +1541,7 @@ class CodexAppServerClient {
|
|
|
1528
1541
|
return value;
|
|
1529
1542
|
};
|
|
1530
1543
|
try {
|
|
1531
|
-
assertJsonByteLimit(withoutEcho(message),
|
|
1544
|
+
assertJsonByteLimit(withoutEcho(message), this.#streamLimits.rawMessageMaxBytes, "PROVIDER_MESSAGE_TOO_LARGE");
|
|
1532
1545
|
return matched;
|
|
1533
1546
|
}
|
|
1534
1547
|
catch {
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mininglamp-oss/octo-runtime-adapter-codex",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"private": true,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": "./dist/index.js",
|
|
7
7
|
"dependencies": {
|
|
8
|
-
"@mininglamp-oss/octo-runtime-protocol": "1.0.
|
|
9
|
-
"@mininglamp-oss/octo-runtime-adapter-sdk": "1.0.
|
|
8
|
+
"@mininglamp-oss/octo-runtime-protocol": "1.0.1",
|
|
9
|
+
"@mininglamp-oss/octo-runtime-adapter-sdk": "1.0.1"
|
|
10
10
|
},
|
|
11
11
|
"types": "./dist/index.d.ts",
|
|
12
12
|
"files": [
|
|
@@ -6,6 +6,6 @@ export declare const hermesAdapter: Readonly<{
|
|
|
6
6
|
};
|
|
7
7
|
probe: () => Promise<import("@mininglamp-oss/octo-runtime-adapter-sdk").ProbeResult>;
|
|
8
8
|
respondInteraction(invocationId: string, response: import("@mininglamp-oss/octo-runtime-protocol").InteractionResponse): Promise<void>;
|
|
9
|
-
invoke(request: import("@mininglamp-oss/octo-runtime-protocol").InvokeRequest): AsyncGenerator<import("@mininglamp-oss/octo-runtime-protocol").CanonicalEvent>;
|
|
9
|
+
invoke(request: import("@mininglamp-oss/octo-runtime-protocol").InvokeRequest, context?: import("@mininglamp-oss/octo-runtime-adapter-sdk").AdapterInvocationContext): AsyncGenerator<import("@mininglamp-oss/octo-runtime-protocol").CanonicalEvent>;
|
|
10
10
|
}>;
|
|
11
11
|
export default hermesAdapter;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mininglamp-oss/octo-runtime-adapter-hermes",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1",
|
|
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.0.
|
|
12
|
+
"@mininglamp-oss/octo-runtime-adapter-acp": "1.0.1"
|
|
13
13
|
}
|
|
14
14
|
}
|
|
@@ -10,8 +10,9 @@ export interface SourceEvent {
|
|
|
10
10
|
export declare class HostRunService implements AdapterHostRpc {
|
|
11
11
|
#private;
|
|
12
12
|
readonly transport: AdapterHostRpc;
|
|
13
|
+
private readonly resolveStreamLimits?;
|
|
13
14
|
readonly invoke: import("@mininglamp-oss/octo-runtime-protocol").InputInvoke;
|
|
14
|
-
constructor(transport: AdapterHostRpc);
|
|
15
|
+
constructor(transport: AdapterHostRpc, resolveStreamLimits?: ((input: InvokeInput) => InvokeEnvironment["streamLimits"]) | undefined);
|
|
15
16
|
get status(): {
|
|
16
17
|
draining: boolean;
|
|
17
18
|
activeRuns: number;
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { createInputInvoke, assertInvokeRequestSize, identifyInvokeInput, assertHostFrameIdentity, isHostTerminal } from "@mininglamp-oss/octo-runtime-protocol";
|
|
2
|
-
const TTL = 120_000
|
|
1
|
+
import { createInputInvoke, assertInvokeRequestSize, identifyInvokeInput, assertHostFrameIdentity, isHostTerminal, isStreamCapacityReason, resolveStreamLimitPolicy, streamCapacityError } from "@mininglamp-oss/octo-runtime-protocol";
|
|
2
|
+
const TTL = 120_000;
|
|
3
3
|
/** One process-local event authority around the existing adapter-host IPC client. */
|
|
4
4
|
export class HostRunService {
|
|
5
5
|
transport;
|
|
6
|
+
resolveStreamLimits;
|
|
6
7
|
invoke = createInputInvoke((input, environment) => this.invokeFrames(input, environment));
|
|
7
8
|
#runs = new Map();
|
|
8
9
|
#bytes = 0;
|
|
@@ -11,8 +12,9 @@ export class HostRunService {
|
|
|
11
12
|
#tasks = new Set();
|
|
12
13
|
#starting = new Set();
|
|
13
14
|
#cleanup;
|
|
14
|
-
constructor(transport) {
|
|
15
|
+
constructor(transport, resolveStreamLimits) {
|
|
15
16
|
this.transport = transport;
|
|
17
|
+
this.resolveStreamLimits = resolveStreamLimits;
|
|
16
18
|
this.#cleanup = setInterval(() => this.#prune(), 10_000);
|
|
17
19
|
this.#cleanup.unref();
|
|
18
20
|
}
|
|
@@ -39,7 +41,9 @@ export class HostRunService {
|
|
|
39
41
|
return this.transport.respondNative(invocationId, response);
|
|
40
42
|
}
|
|
41
43
|
async #begin(input, environment) {
|
|
42
|
-
|
|
44
|
+
const streamLimits = resolveStreamLimitPolicy(this.resolveStreamLimits ? this.resolveStreamLimits(input) : environment.streamLimits);
|
|
45
|
+
const frozenEnvironment = { ...environment, streamLimits };
|
|
46
|
+
assertInvokeRequestSize(input, frozenEnvironment);
|
|
43
47
|
this.#prune();
|
|
44
48
|
if (this.#draining)
|
|
45
49
|
throw new Error("DAEMON_DRAINING");
|
|
@@ -47,7 +51,7 @@ export class HostRunService {
|
|
|
47
51
|
throw new Error("RUN_ALREADY_ACCEPTED");
|
|
48
52
|
if (this.#runs.size + this.#starting.size >= 128)
|
|
49
53
|
throw new Error("RUN_CAPACITY_EXHAUSTED");
|
|
50
|
-
const source = this.transport.invokeFrames(input,
|
|
54
|
+
const source = this.transport.invokeFrames(input, frozenEnvironment);
|
|
51
55
|
this.#starting.add(input.runId);
|
|
52
56
|
let first;
|
|
53
57
|
try {
|
|
@@ -86,7 +90,8 @@ export class HostRunService {
|
|
|
86
90
|
next: 1,
|
|
87
91
|
bytes: 0,
|
|
88
92
|
updated: Date.now(),
|
|
89
|
-
events: []
|
|
93
|
+
events: [],
|
|
94
|
+
streamLimits
|
|
90
95
|
};
|
|
91
96
|
this.#runs.set(input.runId, run);
|
|
92
97
|
return run;
|
|
@@ -114,7 +119,7 @@ export class HostRunService {
|
|
|
114
119
|
kind: "control",
|
|
115
120
|
control: {
|
|
116
121
|
type: "error",
|
|
117
|
-
code: "HOST_EXECUTION_FAILED",
|
|
122
|
+
code: streamErrorCode(error) ?? "HOST_EXECUTION_FAILED",
|
|
118
123
|
message: "Host execution failed"
|
|
119
124
|
}
|
|
120
125
|
});
|
|
@@ -161,8 +166,12 @@ export class HostRunService {
|
|
|
161
166
|
throw new Error("STREAM_GAP");
|
|
162
167
|
// Consumers own persistence and presentation filtering; replay retains the complete event.
|
|
163
168
|
const safe = structuredClone(event), bytes = Buffer.byteLength(JSON.stringify(safe));
|
|
164
|
-
if (bytes >
|
|
165
|
-
throw
|
|
169
|
+
if (bytes > run.streamLimits.hostFrameMaxBytes)
|
|
170
|
+
throw streamCapacityError("HOST_FRAME_TOO_LARGE", {
|
|
171
|
+
boundary: "host_run.replay_frame",
|
|
172
|
+
measuredBytes: bytes,
|
|
173
|
+
limitBytes: run.streamLimits.hostFrameMaxBytes
|
|
174
|
+
});
|
|
166
175
|
const now = Date.now();
|
|
167
176
|
run.updated = now;
|
|
168
177
|
run.events.push({ seq: run.next++, event: safe, bytes, at: now });
|
|
@@ -170,9 +179,12 @@ export class HostRunService {
|
|
|
170
179
|
this.#bytes += bytes;
|
|
171
180
|
if (isHostTerminal(safe))
|
|
172
181
|
run.terminal = safe;
|
|
173
|
-
while (run.bytes >
|
|
182
|
+
while (run.bytes > run.streamLimits.replayRunMaxBytes ||
|
|
183
|
+
run.events.length > run.streamLimits.replayRunMaxItems)
|
|
174
184
|
this.#drop(run);
|
|
175
|
-
|
|
185
|
+
// A stricter per-adapter override must not evict replay retained for another active adapter.
|
|
186
|
+
const globalMaxBytes = Math.max(...[...this.#runs.values()].map((value) => value.streamLimits.replayGlobalMaxBytes));
|
|
187
|
+
while (this.#bytes > globalMaxBytes) {
|
|
176
188
|
const oldest = [...this.#runs.values()]
|
|
177
189
|
.filter((value) => value.events.length)
|
|
178
190
|
.sort((a, b) => a.events[0].at - b.events[0].at)[0];
|
|
@@ -291,3 +303,9 @@ export class HostRunService {
|
|
|
291
303
|
this.#bytes = 0;
|
|
292
304
|
}
|
|
293
305
|
}
|
|
306
|
+
function streamErrorCode(error) {
|
|
307
|
+
if (!error || typeof error !== "object" || !("code" in error))
|
|
308
|
+
return undefined;
|
|
309
|
+
const code = error.code;
|
|
310
|
+
return isStreamCapacityReason(code) ? code : undefined;
|
|
311
|
+
}
|