@mininglamp-oss/octo-runtime 1.1.8 → 1.1.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/apps/cli/README.md +3 -1
- package/{node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/runtime-configuration.d.ts → apps/cli/dist/adapter-configuration.d.ts} +1 -0
- package/{node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/runtime-configuration.js → apps/cli/dist/adapter-configuration.js} +1 -0
- package/apps/cli/dist/adapter-configurations.d.ts +1 -1
- package/apps/cli/dist/adapter-configurations.js +1 -1
- package/apps/cli/dist/adapters.d.ts +7 -0
- package/apps/cli/dist/adapters.js +51 -0
- package/apps/cli/dist/build-info.json +2 -2
- package/apps/cli/dist/command-tree.js +3 -1
- package/apps/cli/dist/help.js +1 -1
- package/apps/cli/dist/index.js +4 -0
- package/apps/cli/dist/main.d.ts +2 -0
- package/apps/cli/dist/main.js +10 -12
- package/apps/cli/dist/manifest.json +0 -5
- package/apps/cli/dist/output.js +7 -9
- package/apps/cli/dist/playboard-interrupt.d.ts +6 -0
- package/apps/cli/dist/playboard-interrupt.js +86 -0
- package/apps/cli/dist/playboard.d.ts +2 -0
- package/apps/cli/dist/playboard.js +20 -12
- package/dist/public/executor-kernel.d.ts +2 -3
- package/dist/public/executor-kernel.js +1 -2
- package/dist/public/protocol.d.ts +1 -1
- package/dist/public/protocol.js +1 -1
- 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/dist/app-server.d.ts +1 -0
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-codex/dist/app-server.js +200 -106
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-codex/dist/async-questions.d.ts +27 -0
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-codex/dist/async-questions.js +205 -0
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-codex/dist/stdin-writer.d.ts +30 -0
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-codex/dist/stdin-writer.js +223 -0
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-codex/package.json +3 -3
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-dsh/dist/{chunk-V5W6ZTYC.js → chunk-FGFEM7JP.js} +1 -1
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-dsh/dist/{chunk-CFKMMCO6.js → chunk-R3PDZLX5.js} +3 -3
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-dsh/dist/{chunk-LO34KB7D.js → chunk-TSRZVLIG.js} +1 -1
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-dsh/dist/dsh-sdk-NOTICE.txt +2 -2
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-dsh/dist/errors.js +1 -1
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-dsh/dist/index.js +5 -5
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-dsh/dist/launch.js +2 -2
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-dsh/dist/trajectory.js +2 -2
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-dsh/package.json +3 -3
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-grok-build/package.json +5 -5
- 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/gateway.d.ts +3 -0
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-openclaw/dist/gateway.js +57 -13
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-openclaw/dist/index.d.ts +3 -2
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-openclaw/dist/index.js +4 -2
- 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.js +2 -0
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-sdk/dist/reasoning.js +1 -2
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-sdk/dist/service-status.d.ts +1 -1
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-sdk/dist/service-status.js +12 -30
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-sdk/package.json +2 -2
- package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/adapter-configuration.d.ts +3 -0
- package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/adapter-configuration.js +125 -0
- package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/adapter-configurations.d.ts +1 -1
- package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/adapter-configurations.js +1 -1
- package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/adapters.d.ts +7 -0
- package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/adapters.js +51 -0
- package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/build-info.json +2 -2
- package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/command-tree.js +3 -1
- package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/help.js +1 -1
- package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/index.js +4 -0
- package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/main.d.ts +2 -0
- package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/main.js +10 -12
- package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/manifest.json +0 -5
- package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/output.js +7 -9
- package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/playboard-interrupt.d.ts +6 -0
- package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/playboard-interrupt.js +86 -0
- package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/playboard.d.ts +2 -0
- package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/playboard.js +20 -12
- package/node_modules/@mininglamp-oss/octo-runtime-cli/package.json +23 -24
- package/node_modules/@mininglamp-oss/octo-runtime-cross-service/dist/launchd.d.ts +2 -2
- package/node_modules/@mininglamp-oss/octo-runtime-cross-service/dist/launchd.js +12 -11
- package/node_modules/@mininglamp-oss/octo-runtime-cross-service/package.json +1 -1
- package/node_modules/@mininglamp-oss/octo-runtime-executor-core/dist/experience.js +2 -1
- package/node_modules/@mininglamp-oss/octo-runtime-executor-core/dist/index.d.ts +8 -7
- package/node_modules/@mininglamp-oss/octo-runtime-executor-core/dist/index.js +33 -11
- package/node_modules/@mininglamp-oss/octo-runtime-executor-core/dist/invoke-input.js +9 -2
- package/node_modules/@mininglamp-oss/octo-runtime-executor-core/dist/watchdog.js +6 -3
- package/node_modules/@mininglamp-oss/octo-runtime-executor-core/package.json +3 -3
- package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/async-question-reply.d.ts +30 -0
- package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/async-question-reply.js +199 -0
- package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/client.d.ts +2 -0
- package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/client.js +2 -0
- package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/execution-source.d.ts +17 -0
- package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/execution-source.js +21 -0
- package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/host-run-service.d.ts +9 -9
- package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/host-run-service.js +3 -3
- package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/index.d.ts +2 -6
- package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/index.js +3 -6
- package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/invocation-manifest.d.ts +14 -13
- package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/invocation-manifest.js +84 -187
- package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/server.d.ts +5 -8
- package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/server.js +77 -53
- package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/service.d.ts +5 -1
- package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/service.js +15 -3
- package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/package.json +4 -12
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/application/im-channel.js +6 -2
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/contracts.d.ts +2 -0
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/execution/task.js +14 -0
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/channel.js +4 -0
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/interaction-card.js +2 -1
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/session-command.d.ts +9 -0
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/session-command.js +71 -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/dist/application/im-channel.js +14 -0
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-wecom/package.json +5 -5
- package/node_modules/@mininglamp-oss/octo-runtime-extra-webui/dist/web/assets/{index-B127MhT-.js → index-BLMf2Etg.js} +2 -4
- 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-host-sdk/dist/context-loader.js +1 -1
- 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 +1 -0
- package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/browser.js +1 -0
- package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/context.d.ts +2 -0
- package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/context.js +4 -1
- package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/failure.d.ts +3 -0
- package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/failure.js +63 -12
- package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/generated/protocol-types.d.ts +110 -20
- package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/index.d.ts +7 -4
- package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/index.js +28 -6
- package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/invoke-input.js +2 -0
- package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/questions.d.ts +9 -0
- package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/questions.js +84 -0
- 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 +11 -5
- package/node_modules/@mininglamp-oss/octo-runtime-protocol/package.json +1 -1
- package/package.json +26 -28
- package/packages/octo-runtime-protocol/schema/protocol.schema.json +157 -41
- package/apps/cli/dist/worker.d.ts +0 -1
- package/apps/cli/dist/worker.js +0 -18
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-zcode-gui/dist/app-server.d.ts +0 -63
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-zcode-gui/dist/app-server.js +0 -846
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-zcode-gui/dist/index.d.ts +0 -54
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-zcode-gui/dist/index.js +0 -154
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-zcode-gui/package.json +0 -15
- package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/worker.d.ts +0 -1
- package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/worker.js +0 -18
- package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/heartbeat.d.ts +0 -16
- package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/heartbeat.js +0 -59
- package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/manifest-adapters.d.ts +0 -6
- package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/manifest-adapters.js +0 -88
- package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/module-specifier.d.ts +0 -1
- package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/module-specifier.js +0 -2
- package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/process.d.ts +0 -42
- package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/process.js +0 -292
- package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/rpc.d.ts +0 -62
- package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/rpc.js +0 -661
- package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/runner.d.ts +0 -2
- package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/runner.js +0 -5
- package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/serve.d.ts +0 -10
- package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/serve.js +0 -96
- package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/supervisor.d.ts +0 -15
- package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/supervisor.js +0 -279
|
@@ -1,661 +0,0 @@
|
|
|
1
|
-
import { createInterface } from "node:readline";
|
|
2
|
-
import { randomUUID } from "node:crypto";
|
|
3
|
-
import { watchLineLimit, readBoundedLines } from "@mininglamp-oss/octo-runtime-adapter-sdk";
|
|
4
|
-
import { createInputInvoke, HOST_RPC_MAX_LINE_BYTES, INVOKE_REQUEST_MAX_BYTES, resolveStreamLimitPolicy, streamCapacityError, assertJsonByteLimit, assertHostFrame, assertHostRunReceipt, assertHostFrameIdentity, isHostTerminal } from "@mininglamp-oss/octo-runtime-protocol";
|
|
5
|
-
/** A single-consumer async queue: producers `push`, one consumer iterates, and `close` ends the stream (optionally with an error). */
|
|
6
|
-
class AsyncQueue {
|
|
7
|
-
limits;
|
|
8
|
-
#items = [];
|
|
9
|
-
#bytes = 0;
|
|
10
|
-
#waiters = [];
|
|
11
|
-
#closed = false;
|
|
12
|
-
#error;
|
|
13
|
-
constructor(limits) {
|
|
14
|
-
this.limits = limits;
|
|
15
|
-
}
|
|
16
|
-
push(value) {
|
|
17
|
-
if (this.#closed)
|
|
18
|
-
return;
|
|
19
|
-
const bytes = Buffer.byteLength(JSON.stringify(value));
|
|
20
|
-
if (bytes > this.limits.itemMaxBytes) {
|
|
21
|
-
this.close(streamCapacityError("STREAM_QUEUE_ITEM_TOO_LARGE", {
|
|
22
|
-
boundary: this.limits.boundary,
|
|
23
|
-
measuredBytes: bytes,
|
|
24
|
-
limitBytes: this.limits.itemMaxBytes
|
|
25
|
-
}));
|
|
26
|
-
return;
|
|
27
|
-
}
|
|
28
|
-
if (this.#items.length >= this.limits.maxItems) {
|
|
29
|
-
this.close(streamCapacityError("STREAM_QUEUE_ITEMS_EXCEEDED", {
|
|
30
|
-
boundary: this.limits.boundary,
|
|
31
|
-
itemCount: this.#items.length + 1,
|
|
32
|
-
limitItems: this.limits.maxItems
|
|
33
|
-
}));
|
|
34
|
-
return;
|
|
35
|
-
}
|
|
36
|
-
if (this.#bytes + bytes > this.limits.maxBytes) {
|
|
37
|
-
this.close(streamCapacityError("STREAM_QUEUE_BYTES_EXCEEDED", {
|
|
38
|
-
boundary: this.limits.boundary,
|
|
39
|
-
measuredBytes: this.#bytes + bytes,
|
|
40
|
-
limitBytes: this.limits.maxBytes
|
|
41
|
-
}));
|
|
42
|
-
return;
|
|
43
|
-
}
|
|
44
|
-
const waiter = this.#waiters.shift();
|
|
45
|
-
if (waiter)
|
|
46
|
-
waiter.resolve({ value, done: false });
|
|
47
|
-
else {
|
|
48
|
-
this.#items.push({ value, bytes });
|
|
49
|
-
this.#bytes += bytes;
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
close(error) {
|
|
53
|
-
if (this.#closed)
|
|
54
|
-
return;
|
|
55
|
-
this.#closed = true;
|
|
56
|
-
this.#error = error;
|
|
57
|
-
for (const waiter of this.#waiters.splice(0)) {
|
|
58
|
-
if (error)
|
|
59
|
-
waiter.reject(error);
|
|
60
|
-
else
|
|
61
|
-
waiter.resolve({ value: undefined, done: true });
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
next() {
|
|
65
|
-
const item = this.#items.shift();
|
|
66
|
-
if (item !== undefined) {
|
|
67
|
-
this.#bytes -= item.bytes;
|
|
68
|
-
return Promise.resolve({ value: item.value, done: false });
|
|
69
|
-
}
|
|
70
|
-
if (this.#error)
|
|
71
|
-
return Promise.reject(this.#error);
|
|
72
|
-
if (this.#closed)
|
|
73
|
-
return Promise.resolve({ value: undefined, done: true });
|
|
74
|
-
return new Promise((resolve, reject) => this.#waiters.push({ resolve, reject }));
|
|
75
|
-
}
|
|
76
|
-
[Symbol.asyncIterator]() {
|
|
77
|
-
return this;
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
function writer(output, trace, onError) {
|
|
81
|
-
return (value) => {
|
|
82
|
-
try {
|
|
83
|
-
const frame = JSON.stringify(value);
|
|
84
|
-
trace?.("send", traceFrame(value, frame));
|
|
85
|
-
output.write(`${frame}\n`, (error) => {
|
|
86
|
-
if (error)
|
|
87
|
-
onError?.(error);
|
|
88
|
-
});
|
|
89
|
-
}
|
|
90
|
-
catch (error) {
|
|
91
|
-
if (!onError)
|
|
92
|
-
throw error;
|
|
93
|
-
onError(error instanceof Error ? error : new Error(errorMessage(error)));
|
|
94
|
-
}
|
|
95
|
-
};
|
|
96
|
-
}
|
|
97
|
-
/**
|
|
98
|
-
* 在 worker 中将唯一 AgentExecutor 暴露为 stdio NDJSON JSON-RPC 服务。
|
|
99
|
-
* 普通方法是一问一答;invoke 先返回接纳凭据,再发送通知流,不与 Kernel 对外 socket 协议混用。
|
|
100
|
-
*/
|
|
101
|
-
export class WorkerRpcServer {
|
|
102
|
-
#log;
|
|
103
|
-
#controllers = new Map();
|
|
104
|
-
#host;
|
|
105
|
-
#send;
|
|
106
|
-
#trace;
|
|
107
|
-
#output;
|
|
108
|
-
#closed = false;
|
|
109
|
-
constructor({ host, output, trace, log }) {
|
|
110
|
-
this.#log = (level, event, data) => {
|
|
111
|
-
try {
|
|
112
|
-
log?.(level, event, data);
|
|
113
|
-
}
|
|
114
|
-
catch {
|
|
115
|
-
/* 诊断不能破坏协议流。 */
|
|
116
|
-
}
|
|
117
|
-
};
|
|
118
|
-
this.#host = host;
|
|
119
|
-
this.#output = output;
|
|
120
|
-
const send = writer(output, trace, (error) => this.#close(error));
|
|
121
|
-
this.#send = (value) => {
|
|
122
|
-
if (!this.#closed)
|
|
123
|
-
send(value);
|
|
124
|
-
};
|
|
125
|
-
this.#trace = trace;
|
|
126
|
-
output.on("error", (error) => this.#close(error));
|
|
127
|
-
}
|
|
128
|
-
/** Start consuming the input stream; each line must be one complete JSON-RPC object. */
|
|
129
|
-
listen(input) {
|
|
130
|
-
readBoundedLines(input, INVOKE_REQUEST_MAX_BYTES, {
|
|
131
|
-
onTooLarge: () => this.#send({
|
|
132
|
-
jsonrpc: "2.0",
|
|
133
|
-
id: null,
|
|
134
|
-
error: {
|
|
135
|
-
code: -32000,
|
|
136
|
-
message: "INVOKE_REQUEST_TOO_LARGE",
|
|
137
|
-
data: { code: "INVOKE_REQUEST_TOO_LARGE" }
|
|
138
|
-
}
|
|
139
|
-
}),
|
|
140
|
-
onError: (error) => this.#close(error),
|
|
141
|
-
onClose: () => this.#close(new Error("adapter-host parent connection closed")),
|
|
142
|
-
onLine: (line) => {
|
|
143
|
-
if (this.#closed)
|
|
144
|
-
return;
|
|
145
|
-
try {
|
|
146
|
-
const message = asRpcMessage(JSON.parse(line));
|
|
147
|
-
if (message.method !== "invoke" &&
|
|
148
|
-
message.method !== "invoke.with-environment" &&
|
|
149
|
-
Buffer.byteLength(line) > 512 * 1024) {
|
|
150
|
-
this.#send({
|
|
151
|
-
jsonrpc: "2.0",
|
|
152
|
-
id: message.id ?? null,
|
|
153
|
-
error: { code: -32000, message: "RPC_REQUEST_TOO_LARGE" }
|
|
154
|
-
});
|
|
155
|
-
return;
|
|
156
|
-
}
|
|
157
|
-
this.#trace?.("receive", traceFrame(message, line));
|
|
158
|
-
void this.#dispatch(message);
|
|
159
|
-
}
|
|
160
|
-
catch (error) {
|
|
161
|
-
this.#send({
|
|
162
|
-
jsonrpc: "2.0",
|
|
163
|
-
error: { code: -32700, message: errorMessage(error) },
|
|
164
|
-
id: null
|
|
165
|
-
});
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
});
|
|
169
|
-
}
|
|
170
|
-
async #dispatch(message) {
|
|
171
|
-
if (this.#closed)
|
|
172
|
-
return;
|
|
173
|
-
const { id = null, method, params = {} } = message;
|
|
174
|
-
try {
|
|
175
|
-
if (method === "list") {
|
|
176
|
-
this.#send({
|
|
177
|
-
jsonrpc: "2.0",
|
|
178
|
-
id,
|
|
179
|
-
result: await this.#host.describe(probeConfigurations(params.configurations))
|
|
180
|
-
});
|
|
181
|
-
return;
|
|
182
|
-
}
|
|
183
|
-
if (method === "probe") {
|
|
184
|
-
this.#send({
|
|
185
|
-
jsonrpc: "2.0",
|
|
186
|
-
id,
|
|
187
|
-
result: await this.#host.probe(requiredString(params.adapterType, "adapterType"), probeOptions(params.options))
|
|
188
|
-
});
|
|
189
|
-
return;
|
|
190
|
-
}
|
|
191
|
-
if (method === "cancel") {
|
|
192
|
-
const invocationId = requiredString(params.invocationId, "invocationId");
|
|
193
|
-
const reason = typeof params.reason === "string" ? params.reason : undefined;
|
|
194
|
-
const controller = this.#controllers.get(invocationId);
|
|
195
|
-
controller?.abort(new Error(reason ?? "cancelled"));
|
|
196
|
-
this.#send({
|
|
197
|
-
jsonrpc: "2.0",
|
|
198
|
-
id,
|
|
199
|
-
result: {
|
|
200
|
-
cancelled: this.#host.cancel(invocationId, reason) || !!controller
|
|
201
|
-
}
|
|
202
|
-
});
|
|
203
|
-
return;
|
|
204
|
-
}
|
|
205
|
-
if (method === "interaction.respond") {
|
|
206
|
-
await this.#host.respondInteraction(requiredString(params.invocationId, "invocationId"), params.response);
|
|
207
|
-
this.#send({ jsonrpc: "2.0", id, result: {} });
|
|
208
|
-
return;
|
|
209
|
-
}
|
|
210
|
-
if (method === "native.respond") {
|
|
211
|
-
await this.#host.respondNative(requiredString(params.invocationId, "invocationId"), params.response);
|
|
212
|
-
this.#send({ jsonrpc: "2.0", id, result: {} });
|
|
213
|
-
return;
|
|
214
|
-
}
|
|
215
|
-
if (method === "invoke" || method === "invoke.with-environment") {
|
|
216
|
-
const input = params.input;
|
|
217
|
-
this.#log("info", "rpc.invoke_received", {
|
|
218
|
-
invocation_id: input?.invocationId,
|
|
219
|
-
run_id: input?.runId,
|
|
220
|
-
session_id: input?.sessionId
|
|
221
|
-
});
|
|
222
|
-
const invocationId = requiredString(input?.invocationId, "invocationId");
|
|
223
|
-
if (this.#controllers.has(invocationId))
|
|
224
|
-
throw new Error("EXECUTION_IDENTITY_CONFLICT");
|
|
225
|
-
const controller = new AbortController();
|
|
226
|
-
const source = this.#host.invokeFrames(input, {
|
|
227
|
-
signal: controller.signal,
|
|
228
|
-
...(method === "invoke.with-environment"
|
|
229
|
-
? {
|
|
230
|
-
executionEnvOverrides: params.executionEnvOverrides,
|
|
231
|
-
streamLimits: resolveStreamLimitPolicy(params.streamLimits)
|
|
232
|
-
}
|
|
233
|
-
: {})
|
|
234
|
-
});
|
|
235
|
-
this.#controllers.set(invocationId, controller);
|
|
236
|
-
let first;
|
|
237
|
-
try {
|
|
238
|
-
first = await source.next();
|
|
239
|
-
}
|
|
240
|
-
catch (error) {
|
|
241
|
-
this.#controllers.delete(invocationId);
|
|
242
|
-
throw error;
|
|
243
|
-
}
|
|
244
|
-
if (first.done) {
|
|
245
|
-
this.#controllers.delete(invocationId);
|
|
246
|
-
throw new Error("HOST_ENDED_WITHOUT_RECEIPT");
|
|
247
|
-
}
|
|
248
|
-
const { run_id, invocation_id, stream_id, agent_session_id, session_generation, protocol_mode, protocol } = first.value;
|
|
249
|
-
const receipt = {
|
|
250
|
-
run_id,
|
|
251
|
-
invocation_id,
|
|
252
|
-
stream_id,
|
|
253
|
-
agent_session_id,
|
|
254
|
-
session_generation,
|
|
255
|
-
protocol_mode,
|
|
256
|
-
protocol
|
|
257
|
-
};
|
|
258
|
-
this.#send({ jsonrpc: "2.0", id, result: receipt });
|
|
259
|
-
void this.#streamInvoke(invocationId, (async function* () {
|
|
260
|
-
yield first.value;
|
|
261
|
-
yield* source;
|
|
262
|
-
})());
|
|
263
|
-
return;
|
|
264
|
-
}
|
|
265
|
-
throw Object.assign(new Error(`unknown method: ${method}`), { code: -32601 });
|
|
266
|
-
}
|
|
267
|
-
catch (error) {
|
|
268
|
-
this.#send({
|
|
269
|
-
jsonrpc: "2.0",
|
|
270
|
-
id,
|
|
271
|
-
error: {
|
|
272
|
-
code: errorCode(error),
|
|
273
|
-
message: errorMessage(error),
|
|
274
|
-
...(isRecord(error) && typeof error.code === "string"
|
|
275
|
-
? { data: { code: error.code } }
|
|
276
|
-
: {})
|
|
277
|
-
}
|
|
278
|
-
});
|
|
279
|
-
}
|
|
280
|
-
}
|
|
281
|
-
async #streamInvoke(invocationId, source) {
|
|
282
|
-
if (this.#closed)
|
|
283
|
-
return;
|
|
284
|
-
const started = Date.now();
|
|
285
|
-
let failed = false;
|
|
286
|
-
try {
|
|
287
|
-
for await (const event of source) {
|
|
288
|
-
if (this.#closed)
|
|
289
|
-
break;
|
|
290
|
-
this.#send({
|
|
291
|
-
jsonrpc: "2.0",
|
|
292
|
-
method: "invoke.event",
|
|
293
|
-
params: { invocationId, event }
|
|
294
|
-
});
|
|
295
|
-
if (this.#output.writableNeedDrain)
|
|
296
|
-
await this.#waitForDrain();
|
|
297
|
-
}
|
|
298
|
-
this.#send({
|
|
299
|
-
jsonrpc: "2.0",
|
|
300
|
-
method: "invoke.done",
|
|
301
|
-
params: { invocationId }
|
|
302
|
-
});
|
|
303
|
-
}
|
|
304
|
-
catch (error) {
|
|
305
|
-
failed = true;
|
|
306
|
-
this.#send({
|
|
307
|
-
jsonrpc: "2.0",
|
|
308
|
-
method: "invoke.done",
|
|
309
|
-
params: {
|
|
310
|
-
invocationId,
|
|
311
|
-
error: { message: errorMessage(error), ...safeStreamErrorDetails(error) }
|
|
312
|
-
}
|
|
313
|
-
});
|
|
314
|
-
}
|
|
315
|
-
finally {
|
|
316
|
-
this.#log(failed ? "error" : "info", "rpc.stream_closed", {
|
|
317
|
-
invocation_id: invocationId,
|
|
318
|
-
duration_ms: Date.now() - started,
|
|
319
|
-
status: failed || this.#closed ? "unknown" : "ended"
|
|
320
|
-
});
|
|
321
|
-
this.#controllers.delete(invocationId);
|
|
322
|
-
}
|
|
323
|
-
}
|
|
324
|
-
#close(error) {
|
|
325
|
-
if (this.#closed)
|
|
326
|
-
return;
|
|
327
|
-
this.#closed = true;
|
|
328
|
-
for (const controller of this.#controllers.values())
|
|
329
|
-
controller.abort(error);
|
|
330
|
-
this.#controllers.clear();
|
|
331
|
-
void this.#host
|
|
332
|
-
.shutdown(error.message)
|
|
333
|
-
.then((result) => {
|
|
334
|
-
if (result.cleanup === "incomplete")
|
|
335
|
-
this.#log("error", "rpc.cleanup_incomplete", {
|
|
336
|
-
code: "EXECUTOR_CLEANUP_INCOMPLETE",
|
|
337
|
-
unresolved_count: result.unresolvedInvocationIds.length
|
|
338
|
-
});
|
|
339
|
-
})
|
|
340
|
-
.catch(() => undefined);
|
|
341
|
-
}
|
|
342
|
-
#waitForDrain() {
|
|
343
|
-
return new Promise((resolve, reject) => {
|
|
344
|
-
const cleanup = () => {
|
|
345
|
-
clearTimeout(timer);
|
|
346
|
-
this.#output.off("drain", drain);
|
|
347
|
-
this.#output.off("error", fail);
|
|
348
|
-
this.#output.off("close", closed);
|
|
349
|
-
};
|
|
350
|
-
const drain = () => {
|
|
351
|
-
cleanup();
|
|
352
|
-
resolve();
|
|
353
|
-
};
|
|
354
|
-
const fail = (error) => {
|
|
355
|
-
cleanup();
|
|
356
|
-
reject(error);
|
|
357
|
-
};
|
|
358
|
-
const closed = () => fail(new Error("adapter-host output closed"));
|
|
359
|
-
const timer = setTimeout(() => fail(new Error("STREAM_BACKPRESSURE_TIMEOUT")), 5000);
|
|
360
|
-
this.#output.once("drain", drain);
|
|
361
|
-
this.#output.once("error", fail);
|
|
362
|
-
this.#output.once("close", closed);
|
|
363
|
-
});
|
|
364
|
-
}
|
|
365
|
-
}
|
|
366
|
-
/**
|
|
367
|
-
* Kernel 持有的 worker RPC 客户端,将按身份校验的通知还原为有界异步流。
|
|
368
|
-
* 这里只管理逻辑请求与流;进程存活、心跳和回收由 WorkerSupervisor/WorkerProcess 负责。
|
|
369
|
-
*/
|
|
370
|
-
export class WorkerRpcClient {
|
|
371
|
-
invoke = createInputInvoke((input, environment) => this.invokeFrames(input, environment));
|
|
372
|
-
#send;
|
|
373
|
-
#pending = new Map();
|
|
374
|
-
#invocations = new Map();
|
|
375
|
-
#closedError;
|
|
376
|
-
constructor({ input, output, trace, maximumInputBytes = HOST_RPC_MAX_LINE_BYTES }) {
|
|
377
|
-
this.#send = writer(output, trace, (error) => this.close(error));
|
|
378
|
-
const removeGuard = watchLineLimit(input, maximumInputBytes, (error) => {
|
|
379
|
-
const measuredBytes = "measuredBytes" in error && typeof error.measuredBytes === "number"
|
|
380
|
-
? error.measuredBytes
|
|
381
|
-
: undefined;
|
|
382
|
-
const failure = streamCapacityError("HOST_FRAME_TOO_LARGE", {
|
|
383
|
-
boundary: "host.rpc_transport",
|
|
384
|
-
limitBytes: maximumInputBytes,
|
|
385
|
-
...(measuredBytes === undefined ? {} : { measuredBytes })
|
|
386
|
-
});
|
|
387
|
-
failure.cause = error;
|
|
388
|
-
this.close(failure);
|
|
389
|
-
input.destroy(failure);
|
|
390
|
-
});
|
|
391
|
-
const lines = createInterface({ input });
|
|
392
|
-
lines.once("close", removeGuard);
|
|
393
|
-
lines.on("line", (line) => {
|
|
394
|
-
try {
|
|
395
|
-
const message = asRpcMessage(JSON.parse(line));
|
|
396
|
-
trace?.("receive", traceFrame(message, line));
|
|
397
|
-
this.#receive(message);
|
|
398
|
-
}
|
|
399
|
-
catch (error) {
|
|
400
|
-
this.close(new Error(`invalid adapter-host RPC: ${errorMessage(error)}`));
|
|
401
|
-
}
|
|
402
|
-
});
|
|
403
|
-
lines.on("close", () => this.close(new Error("adapter-host connection closed")));
|
|
404
|
-
lines.on("error", (error) => this.close(error));
|
|
405
|
-
input.on("error", (error) => this.close(error));
|
|
406
|
-
output.on("error", (error) => this.close(error));
|
|
407
|
-
}
|
|
408
|
-
#receive(message) {
|
|
409
|
-
if (message.method === "invoke.event") {
|
|
410
|
-
const params = message.params ?? {};
|
|
411
|
-
const invocationId = requiredString(params.invocationId, "invocationId");
|
|
412
|
-
assertHostFrame(params.event);
|
|
413
|
-
this.#invocations.get(invocationId)?.push(params.event);
|
|
414
|
-
return;
|
|
415
|
-
}
|
|
416
|
-
if (message.method === "invoke.done") {
|
|
417
|
-
const params = message.params ?? {};
|
|
418
|
-
const invocationId = requiredString(params.invocationId, "invocationId");
|
|
419
|
-
const queue = this.#invocations.get(invocationId);
|
|
420
|
-
const detail = isRecord(params.error) ? params.error : undefined;
|
|
421
|
-
const rpcError = detail
|
|
422
|
-
? Object.assign(new Error(errorMessage(detail)), safeStreamErrorDetails(detail))
|
|
423
|
-
: undefined;
|
|
424
|
-
queue?.close(rpcError);
|
|
425
|
-
this.#invocations.delete(invocationId);
|
|
426
|
-
return;
|
|
427
|
-
}
|
|
428
|
-
if (typeof message.id !== "string")
|
|
429
|
-
return;
|
|
430
|
-
const pending = this.#pending.get(message.id);
|
|
431
|
-
if (!pending)
|
|
432
|
-
return;
|
|
433
|
-
this.#pending.delete(message.id);
|
|
434
|
-
if (message.error)
|
|
435
|
-
pending.reject(Object.assign(new Error(message.error.message), {
|
|
436
|
-
code: message.error.data?.code ?? message.error.code
|
|
437
|
-
}));
|
|
438
|
-
else
|
|
439
|
-
pending.resolve(message.result);
|
|
440
|
-
}
|
|
441
|
-
/** Send an ordinary JSON-RPC request and await the matching response by random ID. */
|
|
442
|
-
request(method, params = {}, signal) {
|
|
443
|
-
if (this.#closedError)
|
|
444
|
-
return Promise.reject(this.#closedError);
|
|
445
|
-
if (signal?.aborted)
|
|
446
|
-
return Promise.reject(abortError(signal));
|
|
447
|
-
signal = AbortSignal.any([...(signal ? [signal] : []), AbortSignal.timeout(30_000)]);
|
|
448
|
-
const id = randomUUID();
|
|
449
|
-
const message = { jsonrpc: "2.0", id, method, params };
|
|
450
|
-
try {
|
|
451
|
-
assertJsonByteLimit(message, method === "invoke" || method === "invoke.with-environment"
|
|
452
|
-
? INVOKE_REQUEST_MAX_BYTES
|
|
453
|
-
: 512 * 1024, method === "invoke" || method === "invoke.with-environment"
|
|
454
|
-
? "INVOKE_REQUEST_TOO_LARGE"
|
|
455
|
-
: "RPC_REQUEST_TOO_LARGE");
|
|
456
|
-
}
|
|
457
|
-
catch (error) {
|
|
458
|
-
return Promise.reject(error instanceof Error ? error : new Error("RPC_REQUEST_INVALID"));
|
|
459
|
-
}
|
|
460
|
-
const promise = new Promise((resolve, reject) => {
|
|
461
|
-
const cleanup = () => {
|
|
462
|
-
signal?.removeEventListener("abort", onAbort);
|
|
463
|
-
this.#pending.delete(id);
|
|
464
|
-
};
|
|
465
|
-
const onAbort = () => {
|
|
466
|
-
cleanup();
|
|
467
|
-
reject(abortError(signal));
|
|
468
|
-
};
|
|
469
|
-
this.#pending.set(id, {
|
|
470
|
-
resolve: (value) => {
|
|
471
|
-
cleanup();
|
|
472
|
-
resolve(value);
|
|
473
|
-
},
|
|
474
|
-
reject: (error) => {
|
|
475
|
-
cleanup();
|
|
476
|
-
reject(error);
|
|
477
|
-
}
|
|
478
|
-
});
|
|
479
|
-
signal?.addEventListener("abort", onAbort, { once: true });
|
|
480
|
-
});
|
|
481
|
-
this.#send(message);
|
|
482
|
-
return promise;
|
|
483
|
-
}
|
|
484
|
-
/** 用同一故障结束所有逻辑请求/流;不终止进程,owner 仍须调用 WorkerProcess.close。 */
|
|
485
|
-
close(error = new Error("adapter-host client closed")) {
|
|
486
|
-
if (this.#closedError)
|
|
487
|
-
return;
|
|
488
|
-
this.#closedError = error;
|
|
489
|
-
for (const pending of this.#pending.values())
|
|
490
|
-
pending.reject(error);
|
|
491
|
-
this.#pending.clear();
|
|
492
|
-
for (const queue of this.#invocations.values())
|
|
493
|
-
queue.close(error);
|
|
494
|
-
this.#invocations.clear();
|
|
495
|
-
}
|
|
496
|
-
list(configurations) {
|
|
497
|
-
return this.request("list", { configurations });
|
|
498
|
-
}
|
|
499
|
-
probe(adapterType, options) {
|
|
500
|
-
return this.request("probe", { adapterType, options });
|
|
501
|
-
}
|
|
502
|
-
cancel(invocationId, reason) {
|
|
503
|
-
return this.request("cancel", { invocationId, reason });
|
|
504
|
-
}
|
|
505
|
-
async respondInteraction(invocationId, response) {
|
|
506
|
-
await this.request("interaction.respond", { invocationId, response });
|
|
507
|
-
}
|
|
508
|
-
async respondNative(invocationId, response) {
|
|
509
|
-
await this.request("native.respond", { invocationId, response });
|
|
510
|
-
}
|
|
511
|
-
/** Await the invoke ACK first, then keep yielding this invocation's event notifications until done. */
|
|
512
|
-
async *invokeFrames(input, environment = {}) {
|
|
513
|
-
const { signal, executionEnvOverrides } = environment;
|
|
514
|
-
const streamLimits = resolveStreamLimitPolicy(environment.streamLimits);
|
|
515
|
-
const invocationId = input.invocationId ?? randomUUID();
|
|
516
|
-
const wireInput = { ...input, invocationId };
|
|
517
|
-
if (signal?.aborted)
|
|
518
|
-
throw abortError(signal);
|
|
519
|
-
if (this.#invocations.has(invocationId))
|
|
520
|
-
throw new Error("EXECUTION_IDENTITY_CONFLICT");
|
|
521
|
-
const queue = new AsyncQueue({
|
|
522
|
-
itemMaxBytes: streamLimits.hostFrameMaxBytes,
|
|
523
|
-
maxBytes: streamLimits.rpcQueueMaxBytes,
|
|
524
|
-
maxItems: streamLimits.rpcQueueMaxItems,
|
|
525
|
-
boundary: "host.rpc_queue"
|
|
526
|
-
});
|
|
527
|
-
let terminal = false;
|
|
528
|
-
let accepted = false;
|
|
529
|
-
this.#invocations.set(invocationId, queue);
|
|
530
|
-
// AbortSignal 只留在本进程;跨进程发送明确的 cancel RPC,不能序列化成空对象。
|
|
531
|
-
const onAbort = () => {
|
|
532
|
-
queue.close(abortError(signal));
|
|
533
|
-
void this.request("cancel", { invocationId, reason: "caller_aborted" }, AbortSignal.timeout(2000)).catch(() => undefined);
|
|
534
|
-
};
|
|
535
|
-
signal?.addEventListener("abort", onAbort, { once: true });
|
|
536
|
-
try {
|
|
537
|
-
const receipt = await this.request(executionEnvOverrides?.env_variables.length || environment.streamLimits
|
|
538
|
-
? "invoke.with-environment"
|
|
539
|
-
: "invoke", {
|
|
540
|
-
input: wireInput,
|
|
541
|
-
...(executionEnvOverrides ? { executionEnvOverrides } : {}),
|
|
542
|
-
...(environment.streamLimits ? { streamLimits } : {})
|
|
543
|
-
}, signal);
|
|
544
|
-
assertHostRunReceipt(receipt);
|
|
545
|
-
accepted = true;
|
|
546
|
-
assertReceiptInput(receipt, wireInput);
|
|
547
|
-
let seq = 0;
|
|
548
|
-
for await (const event of queue) {
|
|
549
|
-
if (signal?.aborted)
|
|
550
|
-
throw abortError(signal);
|
|
551
|
-
assertHostFrameIdentity(event, receipt);
|
|
552
|
-
if (event.seq !== ++seq)
|
|
553
|
-
throw new Error("STREAM_GAP");
|
|
554
|
-
if (terminal)
|
|
555
|
-
throw new Error("HOST_FRAME_AFTER_TERMINAL");
|
|
556
|
-
terminal = isHostTerminal(event);
|
|
557
|
-
yield event;
|
|
558
|
-
}
|
|
559
|
-
if (!terminal)
|
|
560
|
-
throw new Error("HOST_ENDED_WITHOUT_TERMINAL");
|
|
561
|
-
}
|
|
562
|
-
finally {
|
|
563
|
-
signal?.removeEventListener("abort", onAbort);
|
|
564
|
-
this.#invocations.delete(invocationId);
|
|
565
|
-
queue.close();
|
|
566
|
-
if (accepted && !terminal && !signal?.aborted)
|
|
567
|
-
await this.request("cancel", { invocationId, reason: "consumer_closed" }, AbortSignal.timeout(2000)).catch(() => undefined);
|
|
568
|
-
}
|
|
569
|
-
}
|
|
570
|
-
}
|
|
571
|
-
function assertReceiptInput(receipt, input) {
|
|
572
|
-
if ((input.runId !== undefined && receipt.run_id !== input.runId) ||
|
|
573
|
-
receipt.invocation_id !== input.invocationId ||
|
|
574
|
-
(input.sessionId !== undefined && receipt.agent_session_id !== input.sessionId) ||
|
|
575
|
-
receipt.session_generation !== (input.sessionGeneration ?? 0) ||
|
|
576
|
-
receipt.protocol_mode !== (input.protocol_mode ?? "native"))
|
|
577
|
-
throw new Error("EXECUTION_IDENTITY_CONFLICT");
|
|
578
|
-
}
|
|
579
|
-
function asRpcMessage(value) {
|
|
580
|
-
if (!isRecord(value) || value.jsonrpc !== "2.0")
|
|
581
|
-
throw new TypeError("expected a JSON-RPC 2.0 object");
|
|
582
|
-
return value;
|
|
583
|
-
}
|
|
584
|
-
function isRecord(value) {
|
|
585
|
-
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
586
|
-
}
|
|
587
|
-
function safeStreamErrorDetails(value) {
|
|
588
|
-
if (!isRecord(value))
|
|
589
|
-
return {};
|
|
590
|
-
const result = {};
|
|
591
|
-
if (typeof value.code === "string" && /^[A-Z][A-Z0-9_]{0,127}$/.test(value.code))
|
|
592
|
-
result.code = value.code;
|
|
593
|
-
if (typeof value.boundary === "string" && /^[a-z0-9][a-z0-9._-]{0,127}$/i.test(value.boundary))
|
|
594
|
-
result.boundary = value.boundary;
|
|
595
|
-
for (const key of ["measuredBytes", "limitBytes", "itemCount", "limitItems"]) {
|
|
596
|
-
const entry = value[key];
|
|
597
|
-
if (typeof entry === "number" && Number.isSafeInteger(entry) && entry >= 0)
|
|
598
|
-
result[key] = entry;
|
|
599
|
-
}
|
|
600
|
-
return result;
|
|
601
|
-
}
|
|
602
|
-
function requiredString(value, name) {
|
|
603
|
-
if (typeof value !== "string" || value.length === 0)
|
|
604
|
-
throw new TypeError(`${name} must be a non-empty string`);
|
|
605
|
-
return value;
|
|
606
|
-
}
|
|
607
|
-
function errorMessage(error) {
|
|
608
|
-
if (error instanceof Error)
|
|
609
|
-
return error.message;
|
|
610
|
-
if (isRecord(error) && typeof error.message === "string")
|
|
611
|
-
return error.message;
|
|
612
|
-
return String(error);
|
|
613
|
-
}
|
|
614
|
-
function errorCode(error) {
|
|
615
|
-
return isRecord(error) && typeof error.code === "number" ? error.code : -32000;
|
|
616
|
-
}
|
|
617
|
-
function abortError(signal) {
|
|
618
|
-
return signal.reason instanceof Error ? signal.reason : new Error("adapter invocation aborted");
|
|
619
|
-
}
|
|
620
|
-
function traceFrame(message, raw) {
|
|
621
|
-
const params = message.params ?? {};
|
|
622
|
-
const event = isRecord(params.event) ? params.event : {};
|
|
623
|
-
const input = isRecord(params.input) ? params.input : {};
|
|
624
|
-
const canonical = isRecord(event.event) ? event.event : {};
|
|
625
|
-
return JSON.stringify({
|
|
626
|
-
jsonrpc: message.jsonrpc,
|
|
627
|
-
id: message.id,
|
|
628
|
-
method: message.method,
|
|
629
|
-
invocationId: params.invocationId ?? input.invocationId,
|
|
630
|
-
protocolMode: event.protocol_mode ?? input.protocol_mode,
|
|
631
|
-
eventType: canonical.type,
|
|
632
|
-
frameKind: event.kind,
|
|
633
|
-
bytes: Buffer.byteLength(raw)
|
|
634
|
-
});
|
|
635
|
-
}
|
|
636
|
-
function probeOptions(value) {
|
|
637
|
-
if (value === undefined)
|
|
638
|
-
return undefined;
|
|
639
|
-
if (!value || typeof value !== "object" || Array.isArray(value))
|
|
640
|
-
throw new TypeError("invalid probe options");
|
|
641
|
-
const options = value;
|
|
642
|
-
if (options.providerOptions !== undefined &&
|
|
643
|
-
(!options.providerOptions ||
|
|
644
|
-
typeof options.providerOptions !== "object" ||
|
|
645
|
-
Array.isArray(options.providerOptions) ||
|
|
646
|
-
Object.values(options.providerOptions).some((v) => typeof v !== "string")))
|
|
647
|
-
throw new TypeError("invalid probe provider options");
|
|
648
|
-
return {
|
|
649
|
-
...options,
|
|
650
|
-
...(options.streamLimits === undefined
|
|
651
|
-
? {}
|
|
652
|
-
: { streamLimits: resolveStreamLimitPolicy(options.streamLimits) })
|
|
653
|
-
};
|
|
654
|
-
}
|
|
655
|
-
function probeConfigurations(value) {
|
|
656
|
-
if (value === undefined)
|
|
657
|
-
return undefined;
|
|
658
|
-
if (!value || typeof value !== "object" || Array.isArray(value))
|
|
659
|
-
throw new TypeError("invalid probe configurations");
|
|
660
|
-
return Object.fromEntries(Object.entries(value).map(([type, options]) => [type, probeOptions(options) ?? {}]));
|
|
661
|
-
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { type HostedAdapter } from "@mininglamp-oss/octo-runtime-executor-core";
|
|
2
|
-
import { type RuntimeLoggingOptions } from "@mininglamp-oss/octo-runtime-adapter-sdk";
|
|
3
|
-
/**
|
|
4
|
-
* 在当前独立 worker 子进程中提供 Core 执行服务。调用方已经决定加载集合:
|
|
5
|
-
* CLI 可从自己的 JSON 动态加载,SDK 可直接 import;这里不扫描或补齐任何 Adapter。
|
|
6
|
-
* 该函数只在 worker 入口调用;宿主 App 和 Kernel 监督进程通过客户端接入,不直接调用。
|
|
7
|
-
*/
|
|
8
|
-
export declare function serveWorker(adapters: readonly HostedAdapter[], options?: {
|
|
9
|
-
logging?: RuntimeLoggingOptions;
|
|
10
|
-
}): void;
|