@masons/runtime-broker 0.1.0
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 +21 -0
- package/README.md +35 -0
- package/dist/broker/broker-daemon.d.ts +71 -0
- package/dist/broker/broker-daemon.d.ts.map +1 -0
- package/dist/broker/broker-daemon.js +837 -0
- package/dist/broker/claude-code-spawn-driver.d.ts +14 -0
- package/dist/broker/claude-code-spawn-driver.d.ts.map +1 -0
- package/dist/broker/claude-code-spawn-driver.js +39 -0
- package/dist/broker/closed-endpoint-lookup.d.ts +25 -0
- package/dist/broker/closed-endpoint-lookup.d.ts.map +1 -0
- package/dist/broker/closed-endpoint-lookup.js +59 -0
- package/dist/broker/codex-spawn-driver-stub.d.ts +7 -0
- package/dist/broker/codex-spawn-driver-stub.d.ts.map +1 -0
- package/dist/broker/codex-spawn-driver-stub.js +13 -0
- package/dist/broker/connector-ws.d.ts +47 -0
- package/dist/broker/connector-ws.d.ts.map +1 -0
- package/dist/broker/connector-ws.js +60 -0
- package/dist/broker/control-event-dispatcher.d.ts +21 -0
- package/dist/broker/control-event-dispatcher.d.ts.map +1 -0
- package/dist/broker/control-event-dispatcher.js +45 -0
- package/dist/broker/control-event-types.d.ts +28 -0
- package/dist/broker/control-event-types.d.ts.map +1 -0
- package/dist/broker/control-event-types.js +1 -0
- package/dist/broker/correlation-ring.d.ts +10 -0
- package/dist/broker/correlation-ring.d.ts.map +1 -0
- package/dist/broker/correlation-ring.js +32 -0
- package/dist/broker/discovery-file.d.ts +12 -0
- package/dist/broker/discovery-file.d.ts.map +1 -0
- package/dist/broker/discovery-file.js +77 -0
- package/dist/broker/endpoint-registry.d.ts +53 -0
- package/dist/broker/endpoint-registry.d.ts.map +1 -0
- package/dist/broker/endpoint-registry.js +83 -0
- package/dist/broker/endpoint-state-machine.d.ts +40 -0
- package/dist/broker/endpoint-state-machine.d.ts.map +1 -0
- package/dist/broker/endpoint-state-machine.js +92 -0
- package/dist/broker/entry.d.ts +13 -0
- package/dist/broker/entry.d.ts.map +1 -0
- package/dist/broker/entry.js +235 -0
- package/dist/broker/grace-timer.d.ts +9 -0
- package/dist/broker/grace-timer.d.ts.map +1 -0
- package/dist/broker/grace-timer.js +34 -0
- package/dist/broker/ipc-server.d.ts +79 -0
- package/dist/broker/ipc-server.d.ts.map +1 -0
- package/dist/broker/ipc-server.js +263 -0
- package/dist/broker/logger.d.ts +10 -0
- package/dist/broker/logger.d.ts.map +1 -0
- package/dist/broker/logger.js +34 -0
- package/dist/broker/network-presence-changed-event-types.d.ts +8 -0
- package/dist/broker/network-presence-changed-event-types.d.ts.map +1 -0
- package/dist/broker/network-presence-changed-event-types.js +1 -0
- package/dist/broker/network-presence-emitter.d.ts +22 -0
- package/dist/broker/network-presence-emitter.d.ts.map +1 -0
- package/dist/broker/network-presence-emitter.js +150 -0
- package/dist/broker/network-presence.d.ts +31 -0
- package/dist/broker/network-presence.d.ts.map +1 -0
- package/dist/broker/network-presence.js +109 -0
- package/dist/broker/paths.d.ts +11 -0
- package/dist/broker/paths.d.ts.map +1 -0
- package/dist/broker/paths.js +30 -0
- package/dist/broker/plugin-liveness.d.ts +2 -0
- package/dist/broker/plugin-liveness.d.ts.map +1 -0
- package/dist/broker/plugin-liveness.js +15 -0
- package/dist/broker/received-message-correlation-cache.d.ts +23 -0
- package/dist/broker/received-message-correlation-cache.d.ts.map +1 -0
- package/dist/broker/received-message-correlation-cache.js +114 -0
- package/dist/broker/reconnecting-buffer.d.ts +23 -0
- package/dist/broker/reconnecting-buffer.d.ts.map +1 -0
- package/dist/broker/reconnecting-buffer.js +107 -0
- package/dist/broker/routing-table.d.ts +22 -0
- package/dist/broker/routing-table.d.ts.map +1 -0
- package/dist/broker/routing-table.js +35 -0
- package/dist/broker/runtime-endpoint-port.d.ts +20 -0
- package/dist/broker/runtime-endpoint-port.d.ts.map +1 -0
- package/dist/broker/runtime-endpoint-port.js +1 -0
- package/dist/broker/services-event-client.d.ts +21 -0
- package/dist/broker/services-event-client.d.ts.map +1 -0
- package/dist/broker/services-event-client.js +221 -0
- package/dist/broker/spawn-correlation.d.ts +28 -0
- package/dist/broker/spawn-correlation.d.ts.map +1 -0
- package/dist/broker/spawn-correlation.js +77 -0
- package/dist/broker/spawn-driver.d.ts +27 -0
- package/dist/broker/spawn-driver.d.ts.map +1 -0
- package/dist/broker/spawn-driver.js +15 -0
- package/dist/broker/task-hint-handler.d.ts +21 -0
- package/dist/broker/task-hint-handler.d.ts.map +1 -0
- package/dist/broker/task-hint-handler.js +33 -0
- package/dist/broker/transition-state-retry-queue.d.ts +20 -0
- package/dist/broker/transition-state-retry-queue.d.ts.map +1 -0
- package/dist/broker/transition-state-retry-queue.js +48 -0
- package/dist/broker/undispatched-changed-event-types.d.ts +29 -0
- package/dist/broker/undispatched-changed-event-types.d.ts.map +1 -0
- package/dist/broker/undispatched-changed-event-types.js +14 -0
- package/dist/broker/undispatched-emitter.d.ts +22 -0
- package/dist/broker/undispatched-emitter.d.ts.map +1 -0
- package/dist/broker/undispatched-emitter.js +149 -0
- package/dist/broker/undispatched-inbox.d.ts +26 -0
- package/dist/broker/undispatched-inbox.d.ts.map +1 -0
- package/dist/broker/undispatched-inbox.js +53 -0
- package/dist/broker/version-handshake.d.ts +30 -0
- package/dist/broker/version-handshake.d.ts.map +1 -0
- package/dist/broker/version-handshake.js +47 -0
- package/dist/broker-client/broker-client.d.ts +65 -0
- package/dist/broker-client/broker-client.d.ts.map +1 -0
- package/dist/broker-client/broker-client.js +165 -0
- package/dist/broker-client/lazy-spawn.d.ts +18 -0
- package/dist/broker-client/lazy-spawn.d.ts.map +1 -0
- package/dist/broker-client/lazy-spawn.js +61 -0
- package/dist/config-fs.d.ts +4 -0
- package/dist/config-fs.d.ts.map +1 -0
- package/dist/config-fs.js +23 -0
- package/dist/connector-client.d.ts +65 -0
- package/dist/connector-client.d.ts.map +1 -0
- package/dist/connector-client.js +364 -0
- package/dist/environment-context.d.ts +21 -0
- package/dist/environment-context.d.ts.map +1 -0
- package/dist/environment-context.js +39 -0
- package/dist/platform-client.d.ts +84 -0
- package/dist/platform-client.d.ts.map +1 -0
- package/dist/platform-client.js +94 -0
- package/dist/runtime-endpoint-client.d.ts +74 -0
- package/dist/runtime-endpoint-client.d.ts.map +1 -0
- package/dist/runtime-endpoint-client.js +163 -0
- package/dist/types.d.ts +90 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +38 -0
- package/dist/version.d.ts +2 -0
- package/dist/version.d.ts.map +1 -0
- package/dist/version.js +1 -0
- package/package.json +60 -0
|
@@ -0,0 +1,364 @@
|
|
|
1
|
+
import { randomUUID } from "node:crypto";
|
|
2
|
+
import { EventEmitter } from "node:events";
|
|
3
|
+
import createDebug from "debug";
|
|
4
|
+
import WebSocket from "ws";
|
|
5
|
+
import { setEnvironmentContext } from "./environment-context.js";
|
|
6
|
+
import { CURRENT_PROTOCOL_VERSION, isAddressedMessage, isDeliveryPending, isDeliveryStatus, isRegisterAck, isSendAck, isStructuredError, REGISTER_ACK_TIMEOUT_MS, SEND_ACK_TIMEOUT_MS, } from "./types.js";
|
|
7
|
+
import { PLUGIN_VERSION } from "./version.js";
|
|
8
|
+
const dbg = createDebug("agent-network:connector");
|
|
9
|
+
const dbgMsg = createDebug("agent-network:connector:msg");
|
|
10
|
+
const BACKOFF_INITIAL_MS = 1_000;
|
|
11
|
+
const BACKOFF_MAX_MS = 30_000;
|
|
12
|
+
const ALREADY_CONNECTED_RETRY_MS = 2_000;
|
|
13
|
+
const ALREADY_CONNECTED_MAX_RETRIES = 30;
|
|
14
|
+
const REPLACED_BY_NEW_RUNTIME_REASON = "Replaced by new Runtime";
|
|
15
|
+
const REPLACED_BY_NEW_RUNTIME_CODE = 4001;
|
|
16
|
+
export class ConnectorError extends Error {
|
|
17
|
+
code;
|
|
18
|
+
to;
|
|
19
|
+
constructor(message, code, to) {
|
|
20
|
+
super(message);
|
|
21
|
+
this.name = "ConnectorError";
|
|
22
|
+
this.code = code;
|
|
23
|
+
this.to = to;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
export class ConnectorClient extends EventEmitter {
|
|
27
|
+
url;
|
|
28
|
+
token;
|
|
29
|
+
ws = null;
|
|
30
|
+
intentionalClose = false;
|
|
31
|
+
backoffMs = BACKOFF_INITIAL_MS;
|
|
32
|
+
alreadyConnectedRetries = 0;
|
|
33
|
+
reconnectTimer = null;
|
|
34
|
+
registerResolve = null;
|
|
35
|
+
registerReject = null;
|
|
36
|
+
registerTimer = null;
|
|
37
|
+
lastKnownSeq;
|
|
38
|
+
pendingSends = new Map();
|
|
39
|
+
constructor(url, token) {
|
|
40
|
+
super();
|
|
41
|
+
this.url = url;
|
|
42
|
+
this.token = token;
|
|
43
|
+
}
|
|
44
|
+
connect() {
|
|
45
|
+
if (this.ws) {
|
|
46
|
+
return Promise.reject(new Error("Already connecting or connected"));
|
|
47
|
+
}
|
|
48
|
+
dbg("connecting to %s", this.url);
|
|
49
|
+
this.intentionalClose = false;
|
|
50
|
+
return this.doConnect();
|
|
51
|
+
}
|
|
52
|
+
disconnect() {
|
|
53
|
+
dbg("intentional disconnect");
|
|
54
|
+
this.intentionalClose = true;
|
|
55
|
+
this.clearReconnectTimer();
|
|
56
|
+
const wsToClose = this.ws;
|
|
57
|
+
this.cleanupConnection();
|
|
58
|
+
if (wsToClose &&
|
|
59
|
+
(wsToClose.readyState === WebSocket.OPEN ||
|
|
60
|
+
wsToClose.readyState === WebSocket.CONNECTING)) {
|
|
61
|
+
wsToClose.close(1000, "Client disconnect");
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
send(to, content, contentType = "text", metadata) {
|
|
65
|
+
const messageId = randomUUID();
|
|
66
|
+
const event = {
|
|
67
|
+
event: "SEND_MESSAGE",
|
|
68
|
+
messageId,
|
|
69
|
+
to,
|
|
70
|
+
content,
|
|
71
|
+
contentType,
|
|
72
|
+
metadata,
|
|
73
|
+
};
|
|
74
|
+
return new Promise((resolve, reject) => {
|
|
75
|
+
const timer = setTimeout(() => {
|
|
76
|
+
this.pendingSends.delete(messageId);
|
|
77
|
+
reject(new Error("SEND_ACK timeout"));
|
|
78
|
+
}, SEND_ACK_TIMEOUT_MS);
|
|
79
|
+
this.pendingSends.set(messageId, { resolve, reject, timer });
|
|
80
|
+
const sent = this.sendEvent(event);
|
|
81
|
+
if (!sent) {
|
|
82
|
+
clearTimeout(timer);
|
|
83
|
+
this.pendingSends.delete(messageId);
|
|
84
|
+
reject(new Error("WebSocket not connected"));
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
sendTyping(to, isTyping) {
|
|
89
|
+
const event = { event: "TYPING", to, isTyping };
|
|
90
|
+
const sent = this.sendEvent(event);
|
|
91
|
+
dbg("sendTyping to=%s isTyping=%s sent=%s", to, isTyping, sent);
|
|
92
|
+
return sent;
|
|
93
|
+
}
|
|
94
|
+
ackDelivery(upTo) {
|
|
95
|
+
const event = { event: "DELIVERY_ACK", upTo };
|
|
96
|
+
const sent = this.sendEvent(event);
|
|
97
|
+
dbg("ackDelivery upTo=%s sent=%s", upTo, sent);
|
|
98
|
+
return sent;
|
|
99
|
+
}
|
|
100
|
+
on(event, listener) {
|
|
101
|
+
return super.on(event, listener);
|
|
102
|
+
}
|
|
103
|
+
once(event, listener) {
|
|
104
|
+
return super.once(event, listener);
|
|
105
|
+
}
|
|
106
|
+
off(event, listener) {
|
|
107
|
+
return super.off(event, listener);
|
|
108
|
+
}
|
|
109
|
+
emit(event, ...args) {
|
|
110
|
+
return super.emit(event, ...args);
|
|
111
|
+
}
|
|
112
|
+
doConnect() {
|
|
113
|
+
return new Promise((resolve, reject) => {
|
|
114
|
+
this.registerResolve = resolve;
|
|
115
|
+
this.registerReject = reject;
|
|
116
|
+
const ws = new WebSocket(this.url, { handshakeTimeout: 10_000 });
|
|
117
|
+
this.ws = ws;
|
|
118
|
+
ws.on("open", () => {
|
|
119
|
+
this.sendRegister();
|
|
120
|
+
this.startRegisterTimeout();
|
|
121
|
+
});
|
|
122
|
+
ws.on("message", this.handleMessage);
|
|
123
|
+
ws.on("close", this.handleClose);
|
|
124
|
+
ws.on("error", this.handleError);
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
sendRegister() {
|
|
128
|
+
const event = {
|
|
129
|
+
event: "REGISTER",
|
|
130
|
+
token: this.token,
|
|
131
|
+
protocolVersion: CURRENT_PROTOCOL_VERSION,
|
|
132
|
+
clientVersion: PLUGIN_VERSION,
|
|
133
|
+
...(this.lastKnownSeq !== undefined
|
|
134
|
+
? { lastKnownSeq: this.lastKnownSeq }
|
|
135
|
+
: {}),
|
|
136
|
+
};
|
|
137
|
+
dbg("REGISTER lastKnownSeq=%s", this.lastKnownSeq ?? "none");
|
|
138
|
+
this.sendEvent(event);
|
|
139
|
+
}
|
|
140
|
+
startRegisterTimeout() {
|
|
141
|
+
this.registerTimer = setTimeout(() => {
|
|
142
|
+
this.rejectRegister(new Error("REGISTER_ACK timeout"));
|
|
143
|
+
this.ws?.close(4000, "Register timeout");
|
|
144
|
+
}, REGISTER_ACK_TIMEOUT_MS);
|
|
145
|
+
}
|
|
146
|
+
resolveRegister() {
|
|
147
|
+
if (this.registerTimer) {
|
|
148
|
+
clearTimeout(this.registerTimer);
|
|
149
|
+
this.registerTimer = null;
|
|
150
|
+
}
|
|
151
|
+
if (this.registerResolve) {
|
|
152
|
+
this.registerResolve();
|
|
153
|
+
this.registerResolve = null;
|
|
154
|
+
this.registerReject = null;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
rejectRegister(err) {
|
|
158
|
+
if (this.registerTimer) {
|
|
159
|
+
clearTimeout(this.registerTimer);
|
|
160
|
+
this.registerTimer = null;
|
|
161
|
+
}
|
|
162
|
+
if (this.registerReject) {
|
|
163
|
+
this.registerReject(err);
|
|
164
|
+
this.registerResolve = null;
|
|
165
|
+
this.registerReject = null;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
handleMessage = (data) => {
|
|
169
|
+
let parsed;
|
|
170
|
+
try {
|
|
171
|
+
parsed = JSON.parse(data.toString());
|
|
172
|
+
}
|
|
173
|
+
catch {
|
|
174
|
+
this.emit("error", new Error("Received non-JSON message from Connector"));
|
|
175
|
+
return;
|
|
176
|
+
}
|
|
177
|
+
if (isRegisterAck(parsed)) {
|
|
178
|
+
this.handleRegisterAck(parsed);
|
|
179
|
+
return;
|
|
180
|
+
}
|
|
181
|
+
this.dispatchAddressed(parsed);
|
|
182
|
+
};
|
|
183
|
+
dispatchAddressed(parsed) {
|
|
184
|
+
if (isSendAck(parsed)) {
|
|
185
|
+
dbg("SEND_ACK messageId=%s status=%s", parsed.messageId, parsed.status);
|
|
186
|
+
this.handleSendAck(parsed);
|
|
187
|
+
return;
|
|
188
|
+
}
|
|
189
|
+
if (isAddressedMessage(parsed)) {
|
|
190
|
+
dbgMsg("MESSAGE_RECEIVED from=%s contentLength=%d seq=%s", parsed.from, parsed.content.length, parsed.seq ?? "none");
|
|
191
|
+
if (typeof parsed.seq === "number" &&
|
|
192
|
+
(this.lastKnownSeq === undefined || parsed.seq > this.lastKnownSeq)) {
|
|
193
|
+
this.lastKnownSeq = parsed.seq;
|
|
194
|
+
}
|
|
195
|
+
this.emit("message_received", parsed);
|
|
196
|
+
return;
|
|
197
|
+
}
|
|
198
|
+
if (isDeliveryPending(parsed)) {
|
|
199
|
+
dbg("DELIVERY_PENDING count=%d upTo=%s", parsed.count, parsed.upTo);
|
|
200
|
+
this.emit("delivery_pending", parsed);
|
|
201
|
+
return;
|
|
202
|
+
}
|
|
203
|
+
if (isDeliveryStatus(parsed)) {
|
|
204
|
+
dbg("DELIVERY_STATUS messageId=%s status=%s", parsed.messageId, parsed.status);
|
|
205
|
+
this.emit("delivery_status", parsed);
|
|
206
|
+
return;
|
|
207
|
+
}
|
|
208
|
+
if (isStructuredError(parsed)) {
|
|
209
|
+
dbg("ERROR code=%s message=%s", parsed.code, parsed.message);
|
|
210
|
+
this.handleStructuredError(parsed);
|
|
211
|
+
return;
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
handleRegisterAck(ack) {
|
|
215
|
+
dbg("REGISTER_ACK status=%s protocolVersion=%d", ack.status, ack.protocolVersion);
|
|
216
|
+
if (ack.status === "ok") {
|
|
217
|
+
if (ack.protocolVersion !== CURRENT_PROTOCOL_VERSION) {
|
|
218
|
+
dbg("WARN: server negotiated protocolVersion=%d, expected=%d", ack.protocolVersion, CURRENT_PROTOCOL_VERSION);
|
|
219
|
+
}
|
|
220
|
+
setEnvironmentContext(ack.agent, ack.owner);
|
|
221
|
+
if (typeof ack.deliverySeq === "number" &&
|
|
222
|
+
this.lastKnownSeq === undefined) {
|
|
223
|
+
this.lastKnownSeq = ack.deliverySeq;
|
|
224
|
+
dbg("delivery cursor initialized: %d", ack.deliverySeq);
|
|
225
|
+
}
|
|
226
|
+
this.backoffMs = BACKOFF_INITIAL_MS;
|
|
227
|
+
this.alreadyConnectedRetries = 0;
|
|
228
|
+
this.resolveRegister();
|
|
229
|
+
this.emit("connected");
|
|
230
|
+
}
|
|
231
|
+
else {
|
|
232
|
+
const reason = ack.reason ?? "Unknown registration error";
|
|
233
|
+
if (reason === "Unsupported protocol version") {
|
|
234
|
+
this.intentionalClose = true;
|
|
235
|
+
this.rejectRegister(new Error(reason));
|
|
236
|
+
this.emit("error", new Error(reason));
|
|
237
|
+
this.ws?.close(4001, reason);
|
|
238
|
+
return;
|
|
239
|
+
}
|
|
240
|
+
if (reason === "Already connected") {
|
|
241
|
+
this.alreadyConnectedRetries++;
|
|
242
|
+
}
|
|
243
|
+
this.rejectRegister(new Error(reason));
|
|
244
|
+
this.ws?.close(4001, reason);
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
handleSendAck(ack) {
|
|
248
|
+
this.emit("send_ack", ack);
|
|
249
|
+
const pending = this.pendingSends.get(ack.messageId);
|
|
250
|
+
if (pending) {
|
|
251
|
+
clearTimeout(pending.timer);
|
|
252
|
+
this.pendingSends.delete(ack.messageId);
|
|
253
|
+
pending.resolve(ack);
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
handleStructuredError(event) {
|
|
257
|
+
this.emit("structured_error", event);
|
|
258
|
+
if (event.messageId) {
|
|
259
|
+
const pending = this.pendingSends.get(event.messageId);
|
|
260
|
+
if (pending) {
|
|
261
|
+
clearTimeout(pending.timer);
|
|
262
|
+
this.pendingSends.delete(event.messageId);
|
|
263
|
+
pending.reject(new ConnectorError(event.message, event.code, event.to));
|
|
264
|
+
return;
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
this.emit("error", new Error(`[${event.code}] ${event.message}`));
|
|
268
|
+
}
|
|
269
|
+
handleClose = (code, reason) => {
|
|
270
|
+
const reasonStr = reason
|
|
271
|
+
? typeof reason === "string"
|
|
272
|
+
? reason
|
|
273
|
+
: reason.toString()
|
|
274
|
+
: "";
|
|
275
|
+
dbg("connection closed code=%s reason=%s intentional=%s", code ?? "?", reasonStr, this.intentionalClose);
|
|
276
|
+
const wasRegistering = this.registerReject !== null;
|
|
277
|
+
this.cleanupConnection();
|
|
278
|
+
const replacedByNewRuntime = code === REPLACED_BY_NEW_RUNTIME_CODE &&
|
|
279
|
+
reasonStr === REPLACED_BY_NEW_RUNTIME_REASON;
|
|
280
|
+
if (replacedByNewRuntime) {
|
|
281
|
+
this.intentionalClose = true;
|
|
282
|
+
const msg = "This agent was claimed by another Runtime " +
|
|
283
|
+
"(this Runtime disconnected). " +
|
|
284
|
+
"Re-run `openclaw channels login --channel agent-network` " +
|
|
285
|
+
"to drive this agent from here again.";
|
|
286
|
+
this.emit("error", new Error(msg));
|
|
287
|
+
if (wasRegistering) {
|
|
288
|
+
this.rejectRegister(new Error(msg));
|
|
289
|
+
}
|
|
290
|
+
this.emit("disconnected");
|
|
291
|
+
return;
|
|
292
|
+
}
|
|
293
|
+
if (wasRegistering) {
|
|
294
|
+
if (this.registerReject) {
|
|
295
|
+
this.rejectRegister(new Error("Connection closed during registration"));
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
this.emit("disconnected");
|
|
299
|
+
if (!this.intentionalClose) {
|
|
300
|
+
this.scheduleReconnect();
|
|
301
|
+
}
|
|
302
|
+
};
|
|
303
|
+
handleError = (err) => {
|
|
304
|
+
dbg("websocket error: %s", err.message);
|
|
305
|
+
this.emit("error", err);
|
|
306
|
+
};
|
|
307
|
+
scheduleReconnect() {
|
|
308
|
+
this.clearReconnectTimer();
|
|
309
|
+
const delay = this.calculateBackoff();
|
|
310
|
+
dbg("reconnecting in %dms", Math.round(delay));
|
|
311
|
+
this.reconnectTimer = setTimeout(() => {
|
|
312
|
+
this.reconnectTimer = null;
|
|
313
|
+
this.doConnect().catch(() => {
|
|
314
|
+
});
|
|
315
|
+
}, delay);
|
|
316
|
+
}
|
|
317
|
+
calculateBackoff() {
|
|
318
|
+
if (this.alreadyConnectedRetries > 0) {
|
|
319
|
+
if (this.alreadyConnectedRetries >= ALREADY_CONNECTED_MAX_RETRIES) {
|
|
320
|
+
this.alreadyConnectedRetries = 0;
|
|
321
|
+
return this.nextExponentialBackoff();
|
|
322
|
+
}
|
|
323
|
+
return ALREADY_CONNECTED_RETRY_MS;
|
|
324
|
+
}
|
|
325
|
+
return this.nextExponentialBackoff();
|
|
326
|
+
}
|
|
327
|
+
nextExponentialBackoff() {
|
|
328
|
+
const jitter = 1 + Math.random() * 0.3;
|
|
329
|
+
const delay = Math.min(this.backoffMs * jitter, BACKOFF_MAX_MS);
|
|
330
|
+
this.backoffMs = Math.min(this.backoffMs * 2, BACKOFF_MAX_MS);
|
|
331
|
+
return delay;
|
|
332
|
+
}
|
|
333
|
+
clearReconnectTimer() {
|
|
334
|
+
if (this.reconnectTimer) {
|
|
335
|
+
clearTimeout(this.reconnectTimer);
|
|
336
|
+
this.reconnectTimer = null;
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
cleanupConnection() {
|
|
340
|
+
if (this.ws) {
|
|
341
|
+
this.ws.off("message", this.handleMessage);
|
|
342
|
+
this.ws.off("close", this.handleClose);
|
|
343
|
+
this.ws.off("error", this.handleError);
|
|
344
|
+
this.ws = null;
|
|
345
|
+
}
|
|
346
|
+
if (this.registerTimer) {
|
|
347
|
+
clearTimeout(this.registerTimer);
|
|
348
|
+
this.registerTimer = null;
|
|
349
|
+
}
|
|
350
|
+
for (const [, pending] of this.pendingSends) {
|
|
351
|
+
clearTimeout(pending.timer);
|
|
352
|
+
pending.reject(new Error("Connection closed"));
|
|
353
|
+
}
|
|
354
|
+
this.pendingSends.clear();
|
|
355
|
+
}
|
|
356
|
+
sendEvent(event) {
|
|
357
|
+
if (this.ws?.readyState === WebSocket.OPEN) {
|
|
358
|
+
this.ws.send(JSON.stringify(event));
|
|
359
|
+
return true;
|
|
360
|
+
}
|
|
361
|
+
dbg("send failed: ws not open event=%s", event.event);
|
|
362
|
+
return false;
|
|
363
|
+
}
|
|
364
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export interface AgentIdentity {
|
|
2
|
+
handle: string;
|
|
3
|
+
name?: string;
|
|
4
|
+
}
|
|
5
|
+
export interface OwnerIdentity {
|
|
6
|
+
handle: string;
|
|
7
|
+
displayName?: string;
|
|
8
|
+
}
|
|
9
|
+
export declare function setEnvironmentContext(agent?: {
|
|
10
|
+
handle: string;
|
|
11
|
+
name?: string;
|
|
12
|
+
}, owner?: {
|
|
13
|
+
handle: string;
|
|
14
|
+
displayName?: string;
|
|
15
|
+
}): void;
|
|
16
|
+
export declare function getAgentIdentity(): AgentIdentity | null;
|
|
17
|
+
export declare function getOwnerIdentity(): OwnerIdentity | null;
|
|
18
|
+
export declare function getOwnerHandle(): string | null;
|
|
19
|
+
export declare function clearEnvironmentContext(): void;
|
|
20
|
+
export declare function _resetForTesting(): void;
|
|
21
|
+
//# sourceMappingURL=environment-context.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"environment-context.d.ts","sourceRoot":"","sources":["../src/environment-context.ts"],"names":[],"mappings":"AAoBA,MAAM,WAAW,aAAa;IAC5B,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,aAAa;IAC5B,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAmBD,wBAAgB,qBAAqB,CACnC,KAAK,CAAC,EAAE;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,IAAI,CAAC,EAAE,MAAM,CAAA;CAAE,EACzC,KAAK,CAAC,EAAE;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,WAAW,CAAC,EAAE,MAAM,CAAA;CAAE,GAC/C,IAAI,CAkBN;AAMD,wBAAgB,gBAAgB,IAAI,aAAa,GAAG,IAAI,CAEvD;AAED,wBAAgB,gBAAgB,IAAI,aAAa,GAAG,IAAI,CAEvD;AAGD,wBAAgB,cAAc,IAAI,MAAM,GAAG,IAAI,CAE9C;AAOD,wBAAgB,uBAAuB,IAAI,IAAI,CAG9C;AAOD,wBAAgB,gBAAgB,IAAI,IAAI,CAGvC"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
let agentIdentity = null;
|
|
2
|
+
let ownerIdentity = null;
|
|
3
|
+
export function setEnvironmentContext(agent, owner) {
|
|
4
|
+
if (agent && typeof agent.handle === "string") {
|
|
5
|
+
const identity = { handle: agent.handle };
|
|
6
|
+
if (agent.name)
|
|
7
|
+
identity.name = agent.name;
|
|
8
|
+
agentIdentity = identity;
|
|
9
|
+
}
|
|
10
|
+
else {
|
|
11
|
+
agentIdentity = null;
|
|
12
|
+
}
|
|
13
|
+
if (owner && typeof owner.handle === "string") {
|
|
14
|
+
const identity = { handle: owner.handle };
|
|
15
|
+
if (owner.displayName)
|
|
16
|
+
identity.displayName = owner.displayName;
|
|
17
|
+
ownerIdentity = identity;
|
|
18
|
+
}
|
|
19
|
+
else {
|
|
20
|
+
ownerIdentity = null;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
export function getAgentIdentity() {
|
|
24
|
+
return agentIdentity;
|
|
25
|
+
}
|
|
26
|
+
export function getOwnerIdentity() {
|
|
27
|
+
return ownerIdentity;
|
|
28
|
+
}
|
|
29
|
+
export function getOwnerHandle() {
|
|
30
|
+
return ownerIdentity?.handle ?? null;
|
|
31
|
+
}
|
|
32
|
+
export function clearEnvironmentContext() {
|
|
33
|
+
agentIdentity = null;
|
|
34
|
+
ownerIdentity = null;
|
|
35
|
+
}
|
|
36
|
+
export function _resetForTesting() {
|
|
37
|
+
agentIdentity = null;
|
|
38
|
+
ownerIdentity = null;
|
|
39
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
export declare const DEFAULT_API_HOST = "preview-api.masons.ai";
|
|
2
|
+
export declare const DEFAULT_CONNECTOR_URL = "wss://preview-connectorapi.masons.ai/gateway";
|
|
3
|
+
export interface PlatformClientConfig {
|
|
4
|
+
apiHost: string;
|
|
5
|
+
}
|
|
6
|
+
export declare class PlatformApiError extends Error {
|
|
7
|
+
readonly status: number;
|
|
8
|
+
readonly code: string;
|
|
9
|
+
constructor(status: number, code: string, message: string);
|
|
10
|
+
}
|
|
11
|
+
export interface RequestConnectionResponse {
|
|
12
|
+
requestIds: string[];
|
|
13
|
+
status: string;
|
|
14
|
+
}
|
|
15
|
+
export interface ConnectionNodeRef {
|
|
16
|
+
kind: string;
|
|
17
|
+
mstpAddress: string;
|
|
18
|
+
handle?: string;
|
|
19
|
+
displayName?: string;
|
|
20
|
+
avatarUrl?: string;
|
|
21
|
+
}
|
|
22
|
+
export interface ListRequestsItem {
|
|
23
|
+
id: string;
|
|
24
|
+
direction: "incoming" | "outgoing";
|
|
25
|
+
fromNode?: ConnectionNodeRef | null;
|
|
26
|
+
toNode?: ConnectionNodeRef | null;
|
|
27
|
+
variant: string;
|
|
28
|
+
status: string;
|
|
29
|
+
matchmaking: {
|
|
30
|
+
title: string | null;
|
|
31
|
+
benefit: string | null;
|
|
32
|
+
scenario: string | null;
|
|
33
|
+
};
|
|
34
|
+
createdAt: string;
|
|
35
|
+
}
|
|
36
|
+
export interface ListRequestsResponse {
|
|
37
|
+
total: number;
|
|
38
|
+
items: ListRequestsItem[];
|
|
39
|
+
}
|
|
40
|
+
export interface AcceptRequestResponse {
|
|
41
|
+
status: "accepted";
|
|
42
|
+
counterparty: ConnectionNodeRef | null;
|
|
43
|
+
}
|
|
44
|
+
export interface DeclineRequestResponse {
|
|
45
|
+
status: "declined";
|
|
46
|
+
}
|
|
47
|
+
export interface UpdateProfileParams {
|
|
48
|
+
name?: string;
|
|
49
|
+
scope?: string;
|
|
50
|
+
about?: string;
|
|
51
|
+
audience?: string;
|
|
52
|
+
}
|
|
53
|
+
export interface UpdateProfileResponse {
|
|
54
|
+
status: "updated";
|
|
55
|
+
profile?: {
|
|
56
|
+
name: string;
|
|
57
|
+
scope: string;
|
|
58
|
+
about: string;
|
|
59
|
+
audience: string;
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
export interface ListConnectionsResponse {
|
|
63
|
+
total: number;
|
|
64
|
+
connections: Array<{
|
|
65
|
+
counterparty: ConnectionNodeRef;
|
|
66
|
+
access: "mutual" | "outbound" | "inbound" | string;
|
|
67
|
+
createdAt: string | null;
|
|
68
|
+
}>;
|
|
69
|
+
}
|
|
70
|
+
export declare function requestConnection(cfg: PlatformClientConfig, runtimeKey: string, params: {
|
|
71
|
+
targetHandle: string;
|
|
72
|
+
variants: ("distribute" | "receive")[];
|
|
73
|
+
}): Promise<RequestConnectionResponse>;
|
|
74
|
+
export declare function listRequests(cfg: PlatformClientConfig, runtimeKey: string, params?: {
|
|
75
|
+
status?: string;
|
|
76
|
+
direction?: string;
|
|
77
|
+
page?: number;
|
|
78
|
+
limit?: number;
|
|
79
|
+
}): Promise<ListRequestsResponse>;
|
|
80
|
+
export declare function acceptRequest(cfg: PlatformClientConfig, runtimeKey: string, requestId: string): Promise<AcceptRequestResponse>;
|
|
81
|
+
export declare function declineRequest(cfg: PlatformClientConfig, runtimeKey: string, requestId: string): Promise<DeclineRequestResponse>;
|
|
82
|
+
export declare function updateProfile(cfg: PlatformClientConfig, runtimeKey: string, params: UpdateProfileParams): Promise<UpdateProfileResponse>;
|
|
83
|
+
export declare function listConnections(cfg: PlatformClientConfig, runtimeKey: string): Promise<ListConnectionsResponse>;
|
|
84
|
+
//# sourceMappingURL=platform-client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"platform-client.d.ts","sourceRoot":"","sources":["../src/platform-client.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
export const DEFAULT_API_HOST = "preview-api.masons.ai";
|
|
2
|
+
export const DEFAULT_CONNECTOR_URL = "wss://preview-connectorapi.masons.ai/gateway";
|
|
3
|
+
export class PlatformApiError extends Error {
|
|
4
|
+
status;
|
|
5
|
+
code;
|
|
6
|
+
constructor(status, code, message) {
|
|
7
|
+
super(message);
|
|
8
|
+
this.status = status;
|
|
9
|
+
this.code = code;
|
|
10
|
+
this.name = "PlatformApiError";
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
function baseUrl(cfg) {
|
|
14
|
+
const trimmed = cfg.apiHost.replace(/\/+$/, "");
|
|
15
|
+
const origin = /^https?:\/\//.test(trimmed) ? trimmed : `https://${trimmed}`;
|
|
16
|
+
return `${origin}/v1`;
|
|
17
|
+
}
|
|
18
|
+
async function handleError(res) {
|
|
19
|
+
const body = (await res.json().catch(() => ({})));
|
|
20
|
+
const code = typeof body.error === "string" ? body.error : "unknown";
|
|
21
|
+
const message = typeof body.message === "string" ? body.message : res.statusText;
|
|
22
|
+
throw new PlatformApiError(res.status, code, message);
|
|
23
|
+
}
|
|
24
|
+
export async function requestConnection(cfg, runtimeKey, params) {
|
|
25
|
+
const res = await fetch(`${baseUrl(cfg)}/me/connections/requests`, {
|
|
26
|
+
method: "POST",
|
|
27
|
+
headers: {
|
|
28
|
+
"Content-Type": "application/json",
|
|
29
|
+
Authorization: `Bearer ${runtimeKey}`,
|
|
30
|
+
},
|
|
31
|
+
body: JSON.stringify(params),
|
|
32
|
+
});
|
|
33
|
+
if (!res.ok)
|
|
34
|
+
return handleError(res);
|
|
35
|
+
return (await res.json());
|
|
36
|
+
}
|
|
37
|
+
export async function listRequests(cfg, runtimeKey, params) {
|
|
38
|
+
const query = new URLSearchParams();
|
|
39
|
+
if (params?.status != null)
|
|
40
|
+
query.set("status", params.status);
|
|
41
|
+
if (params?.direction != null)
|
|
42
|
+
query.set("direction", params.direction);
|
|
43
|
+
if (params?.page != null)
|
|
44
|
+
query.set("page", String(params.page));
|
|
45
|
+
if (params?.limit != null)
|
|
46
|
+
query.set("limit", String(params.limit));
|
|
47
|
+
const qs = query.toString();
|
|
48
|
+
const url = `${baseUrl(cfg)}/me/connections/requests${qs ? `?${qs}` : ""}`;
|
|
49
|
+
const res = await fetch(url, {
|
|
50
|
+
headers: { Authorization: `Bearer ${runtimeKey}` },
|
|
51
|
+
});
|
|
52
|
+
if (!res.ok)
|
|
53
|
+
return handleError(res);
|
|
54
|
+
return (await res.json());
|
|
55
|
+
}
|
|
56
|
+
export async function acceptRequest(cfg, runtimeKey, requestId) {
|
|
57
|
+
const res = await fetch(`${baseUrl(cfg)}/me/connections/requests/${encodeURIComponent(requestId)}/accept`, {
|
|
58
|
+
method: "POST",
|
|
59
|
+
headers: { Authorization: `Bearer ${runtimeKey}` },
|
|
60
|
+
});
|
|
61
|
+
if (!res.ok)
|
|
62
|
+
return handleError(res);
|
|
63
|
+
return (await res.json());
|
|
64
|
+
}
|
|
65
|
+
export async function declineRequest(cfg, runtimeKey, requestId) {
|
|
66
|
+
const res = await fetch(`${baseUrl(cfg)}/me/connections/requests/${encodeURIComponent(requestId)}/decline`, {
|
|
67
|
+
method: "POST",
|
|
68
|
+
headers: { Authorization: `Bearer ${runtimeKey}` },
|
|
69
|
+
});
|
|
70
|
+
if (!res.ok)
|
|
71
|
+
return handleError(res);
|
|
72
|
+
return (await res.json());
|
|
73
|
+
}
|
|
74
|
+
export async function updateProfile(cfg, runtimeKey, params) {
|
|
75
|
+
const res = await fetch(`${baseUrl(cfg)}/me/profile`, {
|
|
76
|
+
method: "PATCH",
|
|
77
|
+
headers: {
|
|
78
|
+
"Content-Type": "application/json",
|
|
79
|
+
Authorization: `Bearer ${runtimeKey}`,
|
|
80
|
+
},
|
|
81
|
+
body: JSON.stringify(params),
|
|
82
|
+
});
|
|
83
|
+
if (!res.ok)
|
|
84
|
+
return handleError(res);
|
|
85
|
+
return (await res.json());
|
|
86
|
+
}
|
|
87
|
+
export async function listConnections(cfg, runtimeKey) {
|
|
88
|
+
const res = await fetch(`${baseUrl(cfg)}/me/connections`, {
|
|
89
|
+
headers: { Authorization: `Bearer ${runtimeKey}` },
|
|
90
|
+
});
|
|
91
|
+
if (!res.ok)
|
|
92
|
+
return handleError(res);
|
|
93
|
+
return (await res.json());
|
|
94
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { PlatformApiError, type PlatformClientConfig } from "./platform-client.js";
|
|
2
|
+
export { PlatformApiError, type PlatformClientConfig };
|
|
3
|
+
export type RuntimeKind = "claude-code" | "openclaw" | "codex" | "passport" | "custom" | (string & {});
|
|
4
|
+
export interface WorkspaceMetadata {
|
|
5
|
+
root: string;
|
|
6
|
+
cwd: string;
|
|
7
|
+
remote?: string;
|
|
8
|
+
branch?: string;
|
|
9
|
+
}
|
|
10
|
+
export type ShareWithPeerField = "workspace" | "tracking_ref" | "runtime_session_id" | "fingerprint" | (string & {});
|
|
11
|
+
export interface RegisterRuntimeEndpointParams {
|
|
12
|
+
as?: string;
|
|
13
|
+
runtime_kind: RuntimeKind;
|
|
14
|
+
runtime_session_id?: string;
|
|
15
|
+
endpoint_nonce: string;
|
|
16
|
+
display_label: string;
|
|
17
|
+
workspace?: WorkspaceMetadata;
|
|
18
|
+
tracking_ref?: string;
|
|
19
|
+
share_with_peer?: ShareWithPeerField[];
|
|
20
|
+
}
|
|
21
|
+
export interface RegisterRuntimeEndpointResponse {
|
|
22
|
+
endpoint_id: string;
|
|
23
|
+
node_id: string;
|
|
24
|
+
display_label: string;
|
|
25
|
+
heartbeat_after_seconds: number;
|
|
26
|
+
lease_ttl_seconds: number;
|
|
27
|
+
soft_retention_seconds: number;
|
|
28
|
+
registered_at: string;
|
|
29
|
+
}
|
|
30
|
+
export interface OwnedRuntimeEndpointView {
|
|
31
|
+
endpoint_id: string;
|
|
32
|
+
node_id: string;
|
|
33
|
+
node_handle?: string;
|
|
34
|
+
runtime_kind: RuntimeKind;
|
|
35
|
+
runtime_session_id?: string;
|
|
36
|
+
display_label: string;
|
|
37
|
+
workspace?: WorkspaceMetadata;
|
|
38
|
+
tracking_ref?: string;
|
|
39
|
+
fingerprint?: {
|
|
40
|
+
workspace_hash_per_peer?: Record<string, string>;
|
|
41
|
+
};
|
|
42
|
+
registered_at: string;
|
|
43
|
+
retired_at?: string;
|
|
44
|
+
is_self: boolean;
|
|
45
|
+
}
|
|
46
|
+
export interface ListOwnedRuntimeEndpointsResponse {
|
|
47
|
+
total: number;
|
|
48
|
+
items: OwnedRuntimeEndpointView[];
|
|
49
|
+
}
|
|
50
|
+
export type HeartbeatRuntimeEndpointResponse = Record<string, unknown>;
|
|
51
|
+
export type UnregisterRuntimeEndpointResponse = Record<string, unknown>;
|
|
52
|
+
export interface TransitionRuntimeEndpointStateParams {
|
|
53
|
+
state: "active" | "reconnecting" | "closed";
|
|
54
|
+
reason: string;
|
|
55
|
+
ts: string;
|
|
56
|
+
}
|
|
57
|
+
export type TransitionRuntimeEndpointStateResponse = Record<string, unknown>;
|
|
58
|
+
export declare function registerRuntimeEndpoint(cfg: PlatformClientConfig, runtimeKey: string, params: RegisterRuntimeEndpointParams): Promise<RegisterRuntimeEndpointResponse>;
|
|
59
|
+
export declare function heartbeatRuntimeEndpoint(cfg: PlatformClientConfig, runtimeKey: string, endpointId: string): Promise<HeartbeatRuntimeEndpointResponse>;
|
|
60
|
+
export declare function transitionRuntimeEndpointState(cfg: PlatformClientConfig, runtimeKey: string, endpointId: string, params: TransitionRuntimeEndpointStateParams): Promise<TransitionRuntimeEndpointStateResponse>;
|
|
61
|
+
export declare function unregisterRuntimeEndpoint(cfg: PlatformClientConfig, runtimeKey: string, endpointId: string, asNodeId?: string): Promise<UnregisterRuntimeEndpointResponse>;
|
|
62
|
+
export declare function listOwnedRuntimeEndpoints(cfg: PlatformClientConfig, runtimeKey: string, asNodeId: string): Promise<ListOwnedRuntimeEndpointsResponse>;
|
|
63
|
+
export declare function getOwnedRuntimeEndpoint(cfg: PlatformClientConfig, runtimeKey: string, endpointId: string, asNodeId: string): Promise<OwnedRuntimeEndpointView>;
|
|
64
|
+
export declare function emitRuntimeUndispatchedChanged(cfg: PlatformClientConfig, runtimeKey: string, event: Readonly<Record<string, unknown>>): Promise<EmitUndispatchedChangedOutcome>;
|
|
65
|
+
export type EmitUndispatchedChangedOutcome = {
|
|
66
|
+
ok: true;
|
|
67
|
+
} | {
|
|
68
|
+
ok: false;
|
|
69
|
+
terminal: boolean;
|
|
70
|
+
status?: number;
|
|
71
|
+
detail?: string;
|
|
72
|
+
};
|
|
73
|
+
export declare function emitRuntimeNetworkPresenceChanged(cfg: PlatformClientConfig, runtimeKey: string, event: Readonly<Record<string, unknown>>): Promise<EmitUndispatchedChangedOutcome>;
|
|
74
|
+
//# sourceMappingURL=runtime-endpoint-client.d.ts.map
|