@myagentroam/node 0.9.62 → 0.9.65
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/LICENSE +202 -0
- package/NOTICE +4 -0
- package/dist/capabilities.js +110 -2
- package/dist/claude-agent-sdk.js +330 -2
- package/dist/claude-channel.js +44 -2
- package/dist/codex-app-server.js +510 -2
- package/dist/config.js +106 -2
- package/dist/connector/node-connector-options.js +1 -2
- package/dist/connector/node-operation-router.js +22 -2
- package/dist/connector.js +1736 -2
- package/dist/control-outbound-scheduler.js +153 -2
- package/dist/database.js +639 -2
- package/dist/fake-runner.js +129 -2
- package/dist/git-askpass.js +12 -0
- package/dist/git-execution-helper.js +266 -0
- package/dist/health.js +3 -2
- package/dist/main.js +57 -2
- package/dist/mcp-installation-model.js +1 -2
- package/dist/migrations/v004.js +55 -3
- package/dist/migrations/v005.js +13 -3
- package/dist/migrations/v006.js +90 -3
- package/dist/migrations/v007.js +22 -3
- package/dist/migrations/v008.js +18 -3
- package/dist/migrations/v009.js +70 -4
- package/dist/migrations/v010.js +43 -3
- package/dist/migrations/v011.js +20 -3
- package/dist/migrations/v012.js +8 -0
- package/dist/native-jsonl-reader.js +186 -2
- package/dist/native-session-history.js +1143 -2
- package/dist/opencode-runtime.js +80 -2
- package/dist/opencode-server.js +259 -2
- package/dist/operational.js +122 -2
- package/dist/process-tree.js +18 -2
- package/dist/ripgrep-binary.js +31 -2
- package/dist/rotating-log.js +67 -2
- package/dist/runner/abstract-runner.js +260 -2
- package/dist/runner/claude/managed-run-controller.js +355 -2
- package/dist/runner/claude/tool-normalizer.js +120 -2
- package/dist/runner/claude-code-runner.js +303 -2
- package/dist/runner/codex/composer-image-markers.js +8 -2
- package/dist/runner/codex/conversation-parser.js +913 -2
- package/dist/runner/codex/managed-run-controller.js +494 -2
- package/dist/runner/codex/tool-normalizer.js +214 -2
- package/dist/runner/codex-runner.js +585 -2
- package/dist/runner/fake-test-runner.js +47 -2
- package/dist/runner/mar-agent/conversation-normalizer.js +644 -2
- package/dist/runner/mar-agent/executor-stdio-client-transport.js +139 -2
- package/dist/runner/mar-agent/generated-images.js +41 -2
- package/dist/runner/mar-agent/history-projection.js +106 -2
- package/dist/runner/mar-agent/hosted-conversation-runtime.js +446 -2
- package/dist/runner/mar-agent/managed-run-controller.js +785 -2
- package/dist/runner/mar-agent/mcp-client-pool.js +233 -2
- package/dist/runner/mar-agent/runtime-model-factory.js +326 -2
- package/dist/runner/mar-agent-runner.js +458 -2
- package/dist/runner/opencode/conversation-parser.js +221 -2
- package/dist/runner/opencode/managed-run-controller.js +588 -2
- package/dist/runner/opencode/tool-normalizer.js +80 -2
- package/dist/runner/opencode-runner.js +426 -2
- package/dist/runner/runner-registry.js +87 -2
- package/dist/runner-command-engine.js +71 -2
- package/dist/runner-profiles.js +323 -2
- package/dist/runner-usage.js +190 -2
- package/dist/runtime-command-detector.js +73 -2
- package/dist/runtime-model.js +1 -2
- package/dist/runtime-state.js +1509 -2
- package/dist/service/attachment-domain-state.js +7 -2
- package/dist/service/bubblewrap-sandbox-executor.js +543 -2
- package/dist/service/continuous-run-coordinator.js +425 -2
- package/dist/service/conversation-history-service.js +552 -2
- package/dist/service/conversation-hosting-capability-service.js +61 -2
- package/dist/service/conversation-hosting-enablement-service.js +91 -2
- package/dist/service/conversation-hosting-maintenance-service.js +174 -2
- package/dist/service/conversation-segment-service.js +162 -2
- package/dist/service/conversation-template-node-service.js +992 -2
- package/dist/service/external-session-resume-service.js +152 -2
- package/dist/service/fake-managed-run-service.js +60 -2
- package/dist/service/git-execution-service.js +418 -0
- package/dist/service/git-operation-service.js +57 -0
- package/dist/service/hosted-conversation-node-service.js +1982 -2
- package/dist/service/hosted-conversation-store.js +1405 -2
- package/dist/service/managed-runner-session-service.js +35 -2
- package/dist/service/mar-agent-model-transport-test-service.js +88 -2
- package/dist/service/mcp-installation-verifier.js +87 -2
- package/dist/service/mcp-node-operation-service.js +90 -2
- package/dist/service/mission-mcp-server.js +124 -2
- package/dist/service/mission-mcp-stdio.js +40 -2
- package/dist/service/mission-runtime.js +142 -2
- package/dist/service/native-session-projection-service.js +274 -2
- package/dist/service/native-session-watch-service.js +683 -2
- package/dist/service/node-connection-lifecycle-service.js +88 -2
- package/dist/service/node-control-channel.js +85 -2
- package/dist/service/node-control-message-service.js +109 -2
- package/dist/service/node-request-service.js +62 -2
- package/dist/service/node-run-event-bridge.js +88 -2
- package/dist/service/node-terminal-channel.js +202 -2
- package/dist/service/node-upgrade-coordinator.js +137 -2
- package/dist/service/node-workspace-coordinator.js +97 -2
- package/dist/service/recent-run-projection-service.js +99 -2
- package/dist/service/run-attachment-service.js +321 -2
- package/dist/service/run-domain-state.js +4 -2
- package/dist/service/run-event-service.js +246 -2
- package/dist/service/run-ownership-policy.js +22 -2
- package/dist/service/run-workbench-service.js +120 -2
- package/dist/service/runner-channel-message-service.js +20 -2
- package/dist/service/runner-interaction-service.js +243 -2
- package/dist/service/runner-service.js +69 -2
- package/dist/service/runtime-credential-control-service.js +95 -2
- package/dist/service/session-catalog-service.js +404 -2
- package/dist/service/session-command-service.js +125 -2
- package/dist/service/session-context-service.js +128 -2
- package/dist/service/session-domain-state.js +9 -2
- package/dist/service/session-identity-service.js +86 -2
- package/dist/service/session-lifecycle-service.js +248 -2
- package/dist/service/session-message-service.js +270 -2
- package/dist/service/session-presentation-service.js +43 -2
- package/dist/service/session-query-service.js +82 -2
- package/dist/service/session-watch-slot-coordinator.js +21 -2
- package/dist/service/skill-directory-service.js +238 -2
- package/dist/service/skill-install-service.js +434 -2
- package/dist/service/skill-node-operation-service.js +206 -2
- package/dist/service/terminal-relay-state.js +3 -2
- package/dist/service/terminal-service.js +90 -2
- package/dist/service/web-search-error.js +40 -2
- package/dist/service/workbench-event-service.js +21 -2
- package/dist/service/workbench-manifest-service.js +69 -2
- package/dist/service/workspace-change-service.js +290 -2
- package/dist/service/workspace-content-search-service.js +457 -2
- package/dist/service/workspace-domain-state.js +41 -2
- package/dist/service/workspace-file-service.js +150 -2
- package/dist/service/workspace-git-exclude-service.js +119 -2
- package/dist/service/workspace-queue-workbench-service.js +176 -2
- package/dist/service/workspace-service.js +92 -2
- package/dist/service/workspace-session-service.js +154 -2
- package/dist/service/workspace-upload-service.js +262 -2
- package/dist/service/workspace-watch-controller.js +68 -2
- package/dist/service/workspace-watch-service.js +170 -2
- package/dist/service/workspace-watch-snapshot-service.js +218 -2
- package/dist/service/workspace-workbench-service.js +239 -2
- package/dist/service.js +91 -2
- package/dist/storage.js +32 -2
- package/dist/supervisor.js +136 -2
- package/dist/terminal.js +496 -2
- package/dist/util/git-credential-client.js +32 -0
- package/dist/util/node-operation-data.js +9 -2
- package/dist/util/node-operation-parsers.js +382 -2
- package/dist/util/personal-instructions.js +34 -2
- package/dist/util/runner-error.js +70 -2
- package/dist/util/runner-native-session-parsers.js +510 -2
- package/dist/util/safe-error.js +8 -2
- package/dist/util/secret-environment.js +25 -2
- package/dist/workspace.js +1793 -2
- package/package.json +11 -8
- package/vendor/ripgrep/darwin-arm64/rg +0 -0
- package/vendor/ripgrep/darwin-x64/rg +0 -0
- package/vendor/ripgrep/manifest.json +12 -0
- package/README.md +0 -42
- package/dist/event-buffer.js +0 -2
- package/dist/migrations/v001.js +0 -107
- package/dist/migrations/v002.js +0 -2
- package/dist/migrations/v003.js +0 -2
- package/dist/service/mcp-package-installer.js +0 -2
|
@@ -1,2 +1,88 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { saveNodeConfig } from '../config.js';
|
|
2
|
+
/** Owns registration completion, heartbeat and background capability refresh timers. */
|
|
3
|
+
export class NodeConnectionLifecycleService {
|
|
4
|
+
options;
|
|
5
|
+
heartbeat;
|
|
6
|
+
refreshTimer;
|
|
7
|
+
refreshing = false;
|
|
8
|
+
constructor(options) {
|
|
9
|
+
this.options = options;
|
|
10
|
+
}
|
|
11
|
+
start() {
|
|
12
|
+
this.startCapabilityRefresh();
|
|
13
|
+
}
|
|
14
|
+
startCapabilityRefresh() {
|
|
15
|
+
if (this.refreshTimer !== undefined)
|
|
16
|
+
clearInterval(this.refreshTimer);
|
|
17
|
+
if (!this.options.capabilitiesProvided)
|
|
18
|
+
void this.refreshCapabilities();
|
|
19
|
+
this.refreshTimer = setInterval(() => void this.refreshCapabilities(), this.options.refreshMs);
|
|
20
|
+
}
|
|
21
|
+
stop() {
|
|
22
|
+
if (this.heartbeat !== undefined)
|
|
23
|
+
clearInterval(this.heartbeat);
|
|
24
|
+
if (this.refreshTimer !== undefined)
|
|
25
|
+
clearInterval(this.refreshTimer);
|
|
26
|
+
this.heartbeat = undefined;
|
|
27
|
+
this.refreshTimer = undefined;
|
|
28
|
+
}
|
|
29
|
+
async register(nodeId, credential) {
|
|
30
|
+
const config = this.options.config();
|
|
31
|
+
if (config === undefined)
|
|
32
|
+
return;
|
|
33
|
+
const registered = {
|
|
34
|
+
serverUrl: config.serverUrl,
|
|
35
|
+
allowedRoots: config.allowedRoots,
|
|
36
|
+
...(config.dataDirectory === undefined ? {} : { dataDirectory: config.dataDirectory }),
|
|
37
|
+
...(config.conversationHosting === undefined
|
|
38
|
+
? {}
|
|
39
|
+
: { conversationHosting: config.conversationHosting }),
|
|
40
|
+
nodeId,
|
|
41
|
+
credential
|
|
42
|
+
};
|
|
43
|
+
this.options.setConfig(registered);
|
|
44
|
+
await saveNodeConfig(registered, this.options.configPath);
|
|
45
|
+
await this.options.onRegistered?.();
|
|
46
|
+
this.connected();
|
|
47
|
+
}
|
|
48
|
+
connected() {
|
|
49
|
+
if (this.heartbeat !== undefined)
|
|
50
|
+
clearInterval(this.heartbeat);
|
|
51
|
+
this.options.control.send('capabilities', this.options.capabilities());
|
|
52
|
+
this.options.terminal.connect();
|
|
53
|
+
this.options.control.send('heartbeat', {});
|
|
54
|
+
this.options.onConnected?.();
|
|
55
|
+
this.options.metrics.heartbeatSent();
|
|
56
|
+
this.heartbeat = setInterval(() => {
|
|
57
|
+
this.options.metrics.heartbeatSent();
|
|
58
|
+
this.options.control.send('heartbeat', {});
|
|
59
|
+
}, this.options.heartbeatMs);
|
|
60
|
+
}
|
|
61
|
+
async refreshCapabilities() {
|
|
62
|
+
if (this.options.stopped() || this.refreshing)
|
|
63
|
+
return;
|
|
64
|
+
this.refreshing = true;
|
|
65
|
+
try {
|
|
66
|
+
let next;
|
|
67
|
+
try {
|
|
68
|
+
next = await this.options.detectCapabilities();
|
|
69
|
+
}
|
|
70
|
+
catch {
|
|
71
|
+
next = {
|
|
72
|
+
...this.options.capabilities(),
|
|
73
|
+
codex: { available: false },
|
|
74
|
+
claudeCode: { available: false },
|
|
75
|
+
openCode: { available: false }
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
if (this.options.stopped() ||
|
|
79
|
+
JSON.stringify(next) === JSON.stringify(this.options.capabilities()))
|
|
80
|
+
return;
|
|
81
|
+
this.options.setCapabilities(next);
|
|
82
|
+
this.options.control.send('capabilities', next);
|
|
83
|
+
}
|
|
84
|
+
finally {
|
|
85
|
+
this.refreshing = false;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
@@ -1,2 +1,85 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import WebSocket from 'ws';
|
|
2
|
+
import { createEnvelope } from '@myagentroam/protocol';
|
|
3
|
+
import { ControlOutboundScheduler } from '../control-outbound-scheduler.js';
|
|
4
|
+
import { nodeConnectEndpoint } from '../runner/codex/conversation-parser.js';
|
|
5
|
+
export class NodeControlChannel {
|
|
6
|
+
options;
|
|
7
|
+
socket;
|
|
8
|
+
outbound = new ControlOutboundScheduler(() => this.socket, () => this.socket?.close(1013, 'NODE_CONTROL_BACKPRESSURE_TIMEOUT'));
|
|
9
|
+
reconnectTimer;
|
|
10
|
+
attempts = 0;
|
|
11
|
+
constructor(options) {
|
|
12
|
+
this.options = options;
|
|
13
|
+
}
|
|
14
|
+
connect() {
|
|
15
|
+
const config = this.options.config();
|
|
16
|
+
if (config === undefined ||
|
|
17
|
+
this.options.stopped() ||
|
|
18
|
+
(this.socket !== undefined &&
|
|
19
|
+
(this.socket.readyState === WebSocket.OPEN ||
|
|
20
|
+
this.socket.readyState === WebSocket.CONNECTING)))
|
|
21
|
+
return;
|
|
22
|
+
this.options.onConnecting(this.attempts);
|
|
23
|
+
const socket = new WebSocket(nodeConnectEndpoint(config.serverUrl));
|
|
24
|
+
this.socket = socket;
|
|
25
|
+
socket.once('open', () => {
|
|
26
|
+
this.attempts = 0;
|
|
27
|
+
if (config.nodeId !== undefined && config.credential !== undefined)
|
|
28
|
+
this.send('authenticate', { nodeId: config.nodeId, credential: config.credential });
|
|
29
|
+
else if (config.registrationToken !== undefined)
|
|
30
|
+
this.send('register', {
|
|
31
|
+
registrationToken: config.registrationToken,
|
|
32
|
+
capabilities: this.options.capabilities()
|
|
33
|
+
});
|
|
34
|
+
else
|
|
35
|
+
socket.close(4000, 'NODE_CREDENTIAL_MISSING');
|
|
36
|
+
});
|
|
37
|
+
socket.on('message', (raw) => this.options.onMessage(raw.toString()));
|
|
38
|
+
socket.once('close', (code, reason) => {
|
|
39
|
+
if (this.socket !== socket)
|
|
40
|
+
return;
|
|
41
|
+
this.socket = undefined;
|
|
42
|
+
this.outbound.reset();
|
|
43
|
+
const reasonText = reason.toString();
|
|
44
|
+
this.options.onClose(code, reasonText);
|
|
45
|
+
if (!(code === 4000 && reasonText === 'NODE_CONNECTION_REPLACED'))
|
|
46
|
+
this.scheduleReconnect();
|
|
47
|
+
});
|
|
48
|
+
socket.once('error', () => undefined);
|
|
49
|
+
}
|
|
50
|
+
connected() {
|
|
51
|
+
return this.socket?.readyState === WebSocket.OPEN;
|
|
52
|
+
}
|
|
53
|
+
/** Keeps transport injection at the transport boundary for contract tests. */
|
|
54
|
+
replaceSocketForTesting(socket) {
|
|
55
|
+
this.socket = socket;
|
|
56
|
+
}
|
|
57
|
+
close(code, reason) {
|
|
58
|
+
this.socket?.close(code, reason);
|
|
59
|
+
}
|
|
60
|
+
stop() {
|
|
61
|
+
if (this.reconnectTimer !== undefined)
|
|
62
|
+
clearTimeout(this.reconnectTimer);
|
|
63
|
+
this.reconnectTimer = undefined;
|
|
64
|
+
this.outbound.reset();
|
|
65
|
+
this.socket?.close();
|
|
66
|
+
this.socket = undefined;
|
|
67
|
+
}
|
|
68
|
+
send(type, payload, replyTo) {
|
|
69
|
+
this.sendEnvelope(createEnvelope(type, payload, { ...(replyTo === undefined ? {} : { replyTo }) }));
|
|
70
|
+
}
|
|
71
|
+
sendEnvelope(envelope) {
|
|
72
|
+
if (!this.connected())
|
|
73
|
+
return;
|
|
74
|
+
this.outbound.enqueue(envelope, envelope.type === 'workbench.event' ? 'normal' : 'high');
|
|
75
|
+
}
|
|
76
|
+
scheduleReconnect() {
|
|
77
|
+
if (this.options.stopped() || !this.options.reconnect || this.reconnectTimer !== undefined)
|
|
78
|
+
return;
|
|
79
|
+
this.options.onReconnectScheduled();
|
|
80
|
+
this.reconnectTimer = setTimeout(() => {
|
|
81
|
+
this.reconnectTimer = undefined;
|
|
82
|
+
this.connect();
|
|
83
|
+
}, this.options.reconnectDelay(this.attempts++));
|
|
84
|
+
}
|
|
85
|
+
}
|
|
@@ -1,2 +1,109 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { nodeEnvelopeSchema } from '@myagentroam/protocol';
|
|
2
|
+
/** Owns parsing and dispatch of the closed Node control-message protocol. */
|
|
3
|
+
export class NodeControlMessageService {
|
|
4
|
+
options;
|
|
5
|
+
constructor(options) {
|
|
6
|
+
this.options = options;
|
|
7
|
+
}
|
|
8
|
+
handle(raw) {
|
|
9
|
+
let envelope;
|
|
10
|
+
try {
|
|
11
|
+
envelope = nodeEnvelopeSchema.parse(JSON.parse(raw));
|
|
12
|
+
}
|
|
13
|
+
catch {
|
|
14
|
+
this.options.close(4002, 'MESSAGE_INVALID');
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
this.dispatch(envelope);
|
|
18
|
+
}
|
|
19
|
+
dispatch(envelope) {
|
|
20
|
+
if (envelope.type === 'registered') {
|
|
21
|
+
this.register(envelope);
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
if (envelope.type === 'authenticated') {
|
|
25
|
+
this.options.connected();
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
if (envelope.type === 'workspace.inspect') {
|
|
29
|
+
void this.options.inspectWorkspace(envelope);
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
if (envelope.type === 'node.request') {
|
|
33
|
+
void this.options.handleNodeRequest(envelope);
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
if (this.options.handleRuntimeCredentialResponse(envelope))
|
|
37
|
+
return;
|
|
38
|
+
if (envelope.type === 'ack')
|
|
39
|
+
return;
|
|
40
|
+
if (envelope.type === 'runs.reconcile') {
|
|
41
|
+
this.options.reconcileRuns(envelope);
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
if (envelope.type === 'run.approval.decision') {
|
|
45
|
+
this.decideApproval(envelope);
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
if (envelope.type === 'run.start') {
|
|
49
|
+
this.options.send('ack', { type: envelope.type }, envelope.id);
|
|
50
|
+
try {
|
|
51
|
+
this.options.runners.startManagedRun(envelope);
|
|
52
|
+
}
|
|
53
|
+
catch (error) {
|
|
54
|
+
// A delayed internal start may arrive after the terminal projection was removed.
|
|
55
|
+
if (!(error instanceof Error) || error.message !== 'RUN_TERMINAL')
|
|
56
|
+
throw error;
|
|
57
|
+
}
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
if (envelope.type === 'session.channel.message') {
|
|
61
|
+
this.options.deliverSessionChannelMessage(envelope);
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
if (envelope.type === 'run.cancel' || envelope.type === 'run.interrupt') {
|
|
65
|
+
this.cancelRun(envelope);
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
if (envelope.type === 'session.resume' || envelope.type === 'lease.reconcile') {
|
|
69
|
+
this.options.send('ack', { type: envelope.type }, envelope.id);
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
if (envelope.type !== 'error')
|
|
73
|
+
this.options.send('error', { code: 'MESSAGE_TYPE_UNKNOWN' }, envelope.id);
|
|
74
|
+
}
|
|
75
|
+
register(envelope) {
|
|
76
|
+
const payload = envelope.payload;
|
|
77
|
+
if (typeof payload.nodeId !== 'string' ||
|
|
78
|
+
typeof payload.credential !== 'string' ||
|
|
79
|
+
this.options.config() === undefined) {
|
|
80
|
+
this.options.close(4002, 'MESSAGE_INVALID');
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
void this.options.register(payload.nodeId, payload.credential);
|
|
84
|
+
}
|
|
85
|
+
decideApproval(envelope) {
|
|
86
|
+
const payload = envelope.payload;
|
|
87
|
+
if (typeof payload.runId !== 'string' ||
|
|
88
|
+
typeof payload.approvalId !== 'string' ||
|
|
89
|
+
(payload.decision !== 'APPROVED' && payload.decision !== 'REJECTED')) {
|
|
90
|
+
this.options.send('error', { code: 'MESSAGE_INVALID' }, envelope.id);
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
this.options.runners.decideApproval({
|
|
94
|
+
runId: payload.runId,
|
|
95
|
+
approvalId: payload.approvalId,
|
|
96
|
+
decision: payload.decision
|
|
97
|
+
});
|
|
98
|
+
this.options.send('ack', { type: envelope.type }, envelope.id);
|
|
99
|
+
}
|
|
100
|
+
cancelRun(envelope) {
|
|
101
|
+
const payload = envelope.payload;
|
|
102
|
+
if (typeof payload.runId === 'string') {
|
|
103
|
+
const handled = this.options.runners.cancelManagedRun(payload.runId, envelope.type === 'run.cancel' ? 'CANCEL' : 'INTERRUPT');
|
|
104
|
+
if (!handled)
|
|
105
|
+
this.options.completeUncontrolledCancellation(payload.runId);
|
|
106
|
+
}
|
|
107
|
+
this.options.send('ack', { type: envelope.type }, envelope.id);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
@@ -1,2 +1,62 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { nodeLog } from '../operational.js';
|
|
2
|
+
import { validUserAuthorization } from '../runner/codex/conversation-parser.js';
|
|
3
|
+
import { safePublicError } from '../util/safe-error.js';
|
|
4
|
+
/** Validates and executes the closed Admin-facing Node operation envelope. */
|
|
5
|
+
export class NodeRequestService {
|
|
6
|
+
options;
|
|
7
|
+
constructor(options) {
|
|
8
|
+
this.options = options;
|
|
9
|
+
}
|
|
10
|
+
async handle(envelope) {
|
|
11
|
+
const payload = envelope.payload;
|
|
12
|
+
if (typeof payload.operation !== 'string' || !this.options.databaseAvailable()) {
|
|
13
|
+
this.sendError(envelope.id, new Error('MESSAGE_INVALID'), 'MESSAGE_INVALID');
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
if (!validUserAuthorization(payload.userAuthorization, envelope, payload.operation, this.options.nodeId())) {
|
|
17
|
+
this.sendError(envelope.id, new Error('USER_AUTHORIZATION_REQUIRED'), 'USER_AUTHORIZATION_REQUIRED');
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
const startedAt = performance.now();
|
|
21
|
+
try {
|
|
22
|
+
const data = payload.data !== null && typeof payload.data === 'object'
|
|
23
|
+
? {
|
|
24
|
+
...payload.data,
|
|
25
|
+
__workspaceWatchSessionHash: payload.userAuthorization
|
|
26
|
+
.sessionHash,
|
|
27
|
+
__requestUserId: payload.userAuthorization.userId
|
|
28
|
+
}
|
|
29
|
+
: payload.data;
|
|
30
|
+
const result = await this.options.execute(payload.operation, data);
|
|
31
|
+
this.options.send('node.response', { result }, envelope.id);
|
|
32
|
+
const durationMs = Math.round(performance.now() - startedAt);
|
|
33
|
+
if (durationMs >= 250)
|
|
34
|
+
nodeLog('node.operation.completed', {
|
|
35
|
+
nodeId: this.options.nodeId(),
|
|
36
|
+
operation: payload.operation,
|
|
37
|
+
requestId: envelope.id,
|
|
38
|
+
durationMs
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
catch (error) {
|
|
42
|
+
const failure = safePublicError(error, 'INTERNAL_ERROR');
|
|
43
|
+
nodeLog('node.operation.failed', {
|
|
44
|
+
nodeId: this.options.nodeId(),
|
|
45
|
+
operation: payload.operation,
|
|
46
|
+
requestId: envelope.id,
|
|
47
|
+
durationMs: Math.round(performance.now() - startedAt),
|
|
48
|
+
error: failure.code,
|
|
49
|
+
...(failure.details === undefined ? {} : { errorDetails: failure.details })
|
|
50
|
+
});
|
|
51
|
+
this.options.send('node.response', nodeResponseFailure(failure), envelope.id);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
sendError(replyTo, error, fallback) {
|
|
55
|
+
const failure = safePublicError(error, fallback);
|
|
56
|
+
this.options.send('node.response', nodeResponseFailure(failure), replyTo);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
function nodeResponseFailure(failure) {
|
|
60
|
+
const { code, ...metadata } = failure;
|
|
61
|
+
return { error: code, ...metadata };
|
|
62
|
+
}
|
|
@@ -1,2 +1,88 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { isNodeAgentRun, isNodeConversationTurn, isPlainRecord } from '../runner/codex/conversation-parser.js';
|
|
2
|
+
export function workbenchPayloadSessionId(runtime, category, payload) {
|
|
3
|
+
if (!isPlainRecord(payload))
|
|
4
|
+
return undefined;
|
|
5
|
+
if (category === 'session') {
|
|
6
|
+
if (isPlainRecord(payload.session)) {
|
|
7
|
+
const id = payload.session.id;
|
|
8
|
+
if (typeof id === 'string')
|
|
9
|
+
return id;
|
|
10
|
+
}
|
|
11
|
+
return typeof payload.sessionId === 'string' ? payload.sessionId : undefined;
|
|
12
|
+
}
|
|
13
|
+
if (category === 'run' && isNodeAgentRun(payload.run))
|
|
14
|
+
return payload.run.sessionId;
|
|
15
|
+
if (category === 'conversation') {
|
|
16
|
+
if (isNodeConversationTurn(payload.turn))
|
|
17
|
+
return payload.turn.sessionId;
|
|
18
|
+
if (typeof payload.sessionId === 'string')
|
|
19
|
+
return payload.sessionId;
|
|
20
|
+
if (isPlainRecord(payload.event)) {
|
|
21
|
+
const runId = payload.event.runId;
|
|
22
|
+
return typeof runId === 'string' ? runtime.getRun(runId)?.sessionId : undefined;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
if (category === 'queue') {
|
|
26
|
+
const id = payload.sessionId;
|
|
27
|
+
return typeof id === 'string' ? id : undefined;
|
|
28
|
+
}
|
|
29
|
+
return undefined;
|
|
30
|
+
}
|
|
31
|
+
/** Bridges process-local Run state to normalized control and Workbench events. */
|
|
32
|
+
export class NodeRunEventBridge {
|
|
33
|
+
options;
|
|
34
|
+
constructor(options) {
|
|
35
|
+
this.options = options;
|
|
36
|
+
}
|
|
37
|
+
publishApproval(input) {
|
|
38
|
+
this.options.send('approval.request', input);
|
|
39
|
+
this.emitRun(input.runId, 'approval.request', input);
|
|
40
|
+
}
|
|
41
|
+
emitRun(runId, eventType, payload, status) {
|
|
42
|
+
this.options.events.emit(runId, eventType, payload, status);
|
|
43
|
+
}
|
|
44
|
+
emitQueue(workspaceId, sessionId) {
|
|
45
|
+
this.options.emitWorkbench('queue', {
|
|
46
|
+
workspaceId,
|
|
47
|
+
sessionId,
|
|
48
|
+
queue: this.options.queues.present(workspaceId, sessionId)
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
migrateRunnerSessionIdentity(sessionId, nativeSessionId) {
|
|
52
|
+
for (const [turnId, managed] of this.options.codex.execution.managedTurns) {
|
|
53
|
+
if (managed.sessionId === sessionId)
|
|
54
|
+
this.options.codex.execution.managedTurns.set(turnId, {
|
|
55
|
+
...managed,
|
|
56
|
+
sessionId: nativeSessionId
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
for (const [runId, managed] of this.options.codex.execution.runs) {
|
|
60
|
+
if (managed.sessionId === sessionId)
|
|
61
|
+
this.options.codex.execution.runs.set(runId, { ...managed, sessionId: nativeSessionId });
|
|
62
|
+
}
|
|
63
|
+
for (const [runId, managed] of this.options.claude.execution.runs) {
|
|
64
|
+
if (managed.marSessionId === sessionId)
|
|
65
|
+
this.options.claude.execution.runs.set(runId, {
|
|
66
|
+
...managed,
|
|
67
|
+
marSessionId: nativeSessionId
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
for (const [runId, managed] of this.options.openCode.execution) {
|
|
71
|
+
if (managed.sessionId === sessionId)
|
|
72
|
+
this.options.openCode.execution.set(runId, { ...managed, sessionId: nativeSessionId });
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
reconcile(envelope) {
|
|
76
|
+
const payload = envelope.payload;
|
|
77
|
+
if (!Array.isArray(payload.runIds) || payload.runIds.some((id) => typeof id !== 'string')) {
|
|
78
|
+
this.options.send('error', { code: 'MESSAGE_INVALID' }, envelope.id);
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
for (const runId of payload.runIds) {
|
|
82
|
+
const known = this.options.state.active.has(runId);
|
|
83
|
+
this.options.runtime.reconcileRun(runId, known);
|
|
84
|
+
this.options.send('lease.reconcile', { runId, known });
|
|
85
|
+
}
|
|
86
|
+
this.options.send('ack', { type: 'runs.reconcile' }, envelope.id);
|
|
87
|
+
}
|
|
88
|
+
}
|