@myagentroam/node 0.11.37 → 0.11.38

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.
@@ -8,7 +8,6 @@ const nodeAppVersion = typeof nodePackage.version === 'string' ? nodePackage.ver
8
8
  const runtimeCredentialCapability = () => ({
9
9
  apiVersion: 1,
10
10
  websocket: true,
11
- fastMode: true,
12
11
  serviceTiers: ['auto', 'default', 'flex', 'priority', 'fast', 'ultrafast'],
13
12
  namespacedTools: true,
14
13
  responsesOptionalParameters: true,
package/dist/connector.js CHANGED
@@ -1214,9 +1214,9 @@ export class NodeConnector {
1214
1214
  },
1215
1215
  connected: (payload) => {
1216
1216
  this.usageOutbox?.connected(payload);
1217
+ this.connectionLifecycle.connected();
1217
1218
  for (const change of this.pendingSessionGroups.values())
1218
1219
  this.send('session.group.changed', change);
1219
- this.connectionLifecycle.connected();
1220
1220
  this.mailNotificationControl.setFeatures(payload);
1221
1221
  },
1222
1222
  close: (code, reason) => this.controlChannel.close(code, reason),
@@ -42,6 +42,9 @@ export class ControlOutboundScheduler {
42
42
  this.scheduleExpiry();
43
43
  this.schedule();
44
44
  }
45
+ resume() {
46
+ this.schedule();
47
+ }
45
48
  reset() {
46
49
  this.high.length = 0;
47
50
  this.normal.length = 0;
@@ -936,7 +936,7 @@ function modelSummary(model, index) {
936
936
  defaultReasoningEffort: resolveMarAgentDefaultReasoningEffort(model.defaultReasoningEffort, model.reasoningEfforts),
937
937
  titleGeneration: model.titleGeneration,
938
938
  codeMode: model.codeMode,
939
- ...(model.fastMode === true ? { fastMode: true } : {}),
939
+ ...(model.serviceTier === undefined ? {} : { serviceTier: model.serviceTier }),
940
940
  hostedWebSearch: model.hostedWebSearch,
941
941
  ...(model.responsesTransport === undefined
942
942
  ? {}
@@ -68,9 +68,6 @@ export class MarAgentRuntimeModelFactory {
68
68
  ...(configuration.serviceTier === undefined
69
69
  ? {}
70
70
  : { serviceTier: configuration.serviceTier }),
71
- ...(configuration.serviceTier === undefined && configuration.fastMode === true
72
- ? { fastMode: true }
73
- : {}),
74
71
  hostedWebSearch: configuration.hostedWebSearch,
75
72
  useResourceUrl: configuration.useResourceUrl,
76
73
  ...(imageGeneration === undefined ? {} : { imageGeneration }),
@@ -30,6 +30,7 @@ export class NodeConnectionLifecycleService {
30
30
  const config = this.options.config();
31
31
  if (config === undefined)
32
32
  return;
33
+ const connection = this.options.control.connection();
33
34
  const registered = {
34
35
  serverUrl: config.serverUrl,
35
36
  allowedRoots: config.allowedRoots,
@@ -45,12 +46,14 @@ export class NodeConnectionLifecycleService {
45
46
  this.options.setConfig(registered);
46
47
  await saveNodeConfig(registered, this.options.configPath);
47
48
  await this.options.onRegistered?.();
48
- this.connected();
49
+ if (connection !== undefined)
50
+ this.connected(connection);
49
51
  }
50
- connected() {
52
+ connected(connection) {
53
+ if (!this.options.control.ready(this.options.capabilities(), connection))
54
+ return;
51
55
  if (this.heartbeat !== undefined)
52
56
  clearInterval(this.heartbeat);
53
- this.options.control.send('capabilities', this.options.capabilities());
54
57
  this.options.terminal.connect();
55
58
  this.options.control.send('heartbeat', {});
56
59
  this.options.onConnected?.();
@@ -2,10 +2,15 @@ import WebSocket from 'ws';
2
2
  import { createEnvelope } from '@myagentroam/protocol';
3
3
  import { ControlOutboundScheduler } from '../control-outbound-scheduler.js';
4
4
  import { nodeConnectEndpoint } from '../connection/endpoints.js';
5
+ const MAX_PREAUTH_FRAMES = 1024;
6
+ const MAX_PREAUTH_BYTES = 8 * 1024 * 1024;
5
7
  export class NodeControlChannel {
6
8
  options;
7
9
  socket;
8
- outbound = new ControlOutboundScheduler(() => this.socket, () => this.socket?.close(1013, 'NODE_CONTROL_BACKPRESSURE_TIMEOUT'));
10
+ authenticated = false;
11
+ preauthFrames = 0;
12
+ preauthBytes = 0;
13
+ outbound = new ControlOutboundScheduler(() => (this.authenticated ? this.socket : undefined), () => this.socket?.close(1013, 'NODE_CONTROL_BACKPRESSURE_TIMEOUT'));
9
14
  reconnectTimer;
10
15
  attempts = 0;
11
16
  constructor(options) {
@@ -25,20 +30,26 @@ export class NodeControlChannel {
25
30
  socket.once('open', () => {
26
31
  this.attempts = 0;
27
32
  if (config.nodeId !== undefined && config.credential !== undefined)
28
- this.send('authenticate', { nodeId: config.nodeId, credential: config.credential });
33
+ socket.send(JSON.stringify(createEnvelope('authenticate', { nodeId: config.nodeId, credential: config.credential })));
29
34
  else if (config.registrationToken !== undefined)
30
- this.send('register', {
35
+ socket.send(JSON.stringify(createEnvelope('register', {
31
36
  registrationToken: config.registrationToken,
32
37
  capabilities: this.options.capabilities()
33
- });
38
+ })));
34
39
  else
35
40
  socket.close(4000, 'NODE_CREDENTIAL_MISSING');
36
41
  });
37
- socket.on('message', (raw) => this.options.onMessage(raw.toString()));
42
+ socket.on('message', (raw) => {
43
+ if (this.socket === socket)
44
+ this.options.onMessage(raw.toString());
45
+ });
38
46
  socket.once('close', (code, reason) => {
39
47
  if (this.socket !== socket)
40
48
  return;
41
49
  this.socket = undefined;
50
+ this.authenticated = false;
51
+ this.preauthFrames = 0;
52
+ this.preauthBytes = 0;
42
53
  this.outbound.reset();
43
54
  const reasonText = reason.toString();
44
55
  this.options.onClose(code, reasonText);
@@ -48,7 +59,22 @@ export class NodeControlChannel {
48
59
  socket.once('error', () => undefined);
49
60
  }
50
61
  connected() {
51
- return this.socket?.readyState === WebSocket.OPEN;
62
+ return this.authenticated && this.socket?.readyState === WebSocket.OPEN;
63
+ }
64
+ connection() {
65
+ return this.socket;
66
+ }
67
+ ready(capabilities, connection = this.socket) {
68
+ if (connection === undefined ||
69
+ connection !== this.socket ||
70
+ this.socket?.readyState !== WebSocket.OPEN)
71
+ return false;
72
+ this.socket.send(JSON.stringify(createEnvelope('capabilities', capabilities)));
73
+ this.authenticated = true;
74
+ this.preauthFrames = 0;
75
+ this.preauthBytes = 0;
76
+ this.outbound.resume();
77
+ return true;
52
78
  }
53
79
  close(code, reason) {
54
80
  this.socket?.close(code, reason);
@@ -60,13 +86,28 @@ export class NodeControlChannel {
60
86
  this.outbound.reset();
61
87
  this.socket?.close();
62
88
  this.socket = undefined;
89
+ this.authenticated = false;
90
+ this.preauthFrames = 0;
91
+ this.preauthBytes = 0;
63
92
  }
64
93
  send(type, payload, replyTo) {
65
94
  this.sendEnvelope(createEnvelope(type, payload, { ...(replyTo === undefined ? {} : { replyTo }) }));
66
95
  }
67
96
  sendEnvelope(envelope) {
68
- if (!this.connected())
97
+ if (this.socket?.readyState !== WebSocket.OPEN)
69
98
  return;
99
+ if (!this.authenticated) {
100
+ // ready() sends the latest capability snapshot; an older queued snapshot
101
+ // must not overwrite it after authentication.
102
+ if (envelope.type === 'capabilities')
103
+ return;
104
+ this.preauthFrames++;
105
+ this.preauthBytes += Buffer.byteLength(JSON.stringify(envelope));
106
+ if (this.preauthFrames > MAX_PREAUTH_FRAMES || this.preauthBytes > MAX_PREAUTH_BYTES) {
107
+ this.socket.close(1013, 'NODE_CONTROL_PREAUTH_BACKPRESSURE');
108
+ return;
109
+ }
110
+ }
70
111
  this.outbound.enqueue(envelope, envelope.type === 'workbench.event' ? 'normal' : 'high');
71
112
  }
72
113
  scheduleReconnect() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@myagentroam/node",
3
- "version": "0.11.37",
3
+ "version": "0.11.38",
4
4
  "description": "MyAgentRoam Node runtime CLI.",
5
5
  "license": "Apache-2.0 AND GPL-2.0-or-later",
6
6
  "type": "module",
@@ -38,10 +38,10 @@
38
38
  "sharp": "0.35.5",
39
39
  "ws": "^8.21.3",
40
40
  "zod": "4.4.3",
41
- "@myagentroam/agent": "0.11.37",
42
- "@myagentroam/protocol": "0.11.37",
43
- "@myagentroam/code-navigation": "0.11.0",
44
- "@myagentroam/marctl": "0.11.3"
41
+ "@myagentroam/agent": "0.11.38",
42
+ "@myagentroam/code-navigation": "0.11.1",
43
+ "@myagentroam/marctl": "0.11.3",
44
+ "@myagentroam/protocol": "0.11.38"
45
45
  },
46
46
  "devDependencies": {
47
47
  "@types/ws": "^8.18.1"