@masons/runtime-broker 0.2.8 → 0.2.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/dist/broker/broker-daemon.d.ts +1 -0
- package/dist/broker/broker-daemon.d.ts.map +1 -1
- package/dist/broker/broker-daemon.js +441 -15
- package/dist/broker/endpoint-registry.d.ts +4 -0
- package/dist/broker/endpoint-registry.d.ts.map +1 -1
- package/dist/broker/endpoint-registry.js +2 -0
- package/dist/broker/entry.d.ts +1 -0
- package/dist/broker/entry.d.ts.map +1 -1
- package/dist/broker/entry.js +49 -2
- package/dist/broker/ipc-server.d.ts +27 -1
- package/dist/broker/ipc-server.d.ts.map +1 -1
- package/dist/broker/ipc-server.js +39 -2
- package/dist/broker/runtime-endpoint-port.d.ts +3 -1
- package/dist/broker/runtime-endpoint-port.d.ts.map +1 -1
- package/dist/broker/version-handshake.d.ts +3 -1
- package/dist/broker/version-handshake.d.ts.map +1 -1
- package/dist/broker/version-handshake.js +3 -1
- package/dist/broker-client/broker-client.d.ts +32 -0
- package/dist/broker-client/broker-client.d.ts.map +1 -1
- package/dist/broker-client/broker-client.js +122 -2
- package/dist/runtime-endpoint-client.d.ts +45 -0
- package/dist/runtime-endpoint-client.d.ts.map +1 -1
- package/dist/runtime-endpoint-client.js +170 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.d.ts.map +1 -1
- package/dist/version.js +1 -1
- package/package.json +1 -1
|
@@ -30,12 +30,18 @@ function safeJsonParse(text) {
|
|
|
30
30
|
export class BrokerClient extends EventEmitter {
|
|
31
31
|
handle;
|
|
32
32
|
ws = null;
|
|
33
|
+
heartbeatInterval = null;
|
|
34
|
+
heartbeatTimeout = null;
|
|
35
|
+
heartbeatMisses = 0;
|
|
36
|
+
heartbeatTimeoutMs = 5_000;
|
|
37
|
+
heartbeatMissesBeforeDisconnect = 2;
|
|
33
38
|
pluginPid = null;
|
|
34
39
|
_sessionId = null;
|
|
35
40
|
_networkPresence = null;
|
|
36
41
|
_serverCapabilities = {};
|
|
37
42
|
_clientKind = null;
|
|
38
43
|
_clientVersion = null;
|
|
44
|
+
endpointOwnerTokens = new Map();
|
|
39
45
|
constructor(handle) {
|
|
40
46
|
super();
|
|
41
47
|
this.handle = handle;
|
|
@@ -81,11 +87,22 @@ export class BrokerClient extends EventEmitter {
|
|
|
81
87
|
this.pluginPid = opts.pluginPid;
|
|
82
88
|
this._clientKind = opts.clientKind;
|
|
83
89
|
this._clientVersion = opts.clientVersion;
|
|
90
|
+
this.heartbeatTimeoutMs = opts.heartbeatTimeoutMs ?? 5_000;
|
|
91
|
+
this.heartbeatMissesBeforeDisconnect =
|
|
92
|
+
opts.heartbeatMissesBeforeDisconnect ?? 2;
|
|
93
|
+
const clientCapabilities = {
|
|
94
|
+
endpoint_metadata_v1: true,
|
|
95
|
+
push_receipt_ack_v1: true,
|
|
96
|
+
};
|
|
97
|
+
const clientCapabilityHeader = Object.entries(clientCapabilities)
|
|
98
|
+
.filter(([, enabled]) => enabled === true)
|
|
99
|
+
.map(([name]) => name)
|
|
100
|
+
.join(",");
|
|
84
101
|
const initRes = await this.httpJson("POST", "/v1/initialize", {
|
|
85
102
|
client_protocol_version: IPC_PROTOCOL_VERSION,
|
|
86
103
|
client_kind: opts.clientKind,
|
|
87
104
|
client_version: opts.clientVersion,
|
|
88
|
-
capabilities:
|
|
105
|
+
capabilities: clientCapabilities,
|
|
89
106
|
});
|
|
90
107
|
this._sessionId = initRes.session_id;
|
|
91
108
|
this._serverCapabilities = initRes.server_capabilities;
|
|
@@ -95,6 +112,7 @@ export class BrokerClient extends EventEmitter {
|
|
|
95
112
|
headers: {
|
|
96
113
|
Authorization: `Bearer ${this.handle.record.bearerToken}`,
|
|
97
114
|
"x-plugin-pid": String(opts.pluginPid),
|
|
115
|
+
"x-masons-ipc-capabilities": clientCapabilityHeader,
|
|
98
116
|
},
|
|
99
117
|
});
|
|
100
118
|
this.ws = ws;
|
|
@@ -111,18 +129,21 @@ export class BrokerClient extends EventEmitter {
|
|
|
111
129
|
ws.once("error", onError);
|
|
112
130
|
});
|
|
113
131
|
ws.on("message", (data) => this.handleFrame(data.toString()));
|
|
132
|
+
ws.on("pong", () => this.markHeartbeatAlive());
|
|
114
133
|
ws.on("close", () => {
|
|
134
|
+
this.clearHeartbeat();
|
|
115
135
|
this.ws = null;
|
|
116
136
|
this.emit("disconnected");
|
|
117
137
|
});
|
|
118
138
|
ws.on("error", (err) => this.emit("error", err));
|
|
139
|
+
this.startHeartbeat(opts.heartbeatIntervalMs ?? 30_000);
|
|
119
140
|
return initRes;
|
|
120
141
|
}
|
|
121
142
|
async registerEndpoint(args) {
|
|
122
143
|
if (this.pluginPid === null) {
|
|
123
144
|
throw new Error("BrokerClient.connect must be called before registerEndpoint");
|
|
124
145
|
}
|
|
125
|
-
|
|
146
|
+
const outcome = await this.httpJson("POST", "/v1/endpoint/register", {
|
|
126
147
|
agent_id: args.agentId,
|
|
127
148
|
plugin_pid: this.pluginPid,
|
|
128
149
|
kind: args.kind,
|
|
@@ -138,6 +159,10 @@ export class BrokerClient extends EventEmitter {
|
|
|
138
159
|
background_exchange_mode: args.backgroundExchangeMode,
|
|
139
160
|
spawn_token: args.spawnToken,
|
|
140
161
|
});
|
|
162
|
+
if (typeof outcome.endpoint_owner_token === "string") {
|
|
163
|
+
this.endpointOwnerTokens.set(outcome.endpoint_id, outcome.endpoint_owner_token);
|
|
164
|
+
}
|
|
165
|
+
return outcome;
|
|
141
166
|
}
|
|
142
167
|
async send(endpointId, to, content, contentType = "text", metadata) {
|
|
143
168
|
return this.httpJson("POST", "/v1/send", {
|
|
@@ -155,6 +180,7 @@ export class BrokerClient extends EventEmitter {
|
|
|
155
180
|
return this.httpJson("POST", "/v1/runtime/assignment-reply", {
|
|
156
181
|
endpoint_id: args.endpointId,
|
|
157
182
|
plugin_pid: this.pluginPid,
|
|
183
|
+
endpoint_owner_token: this.requireEndpointOwnerToken(args.endpointId),
|
|
158
184
|
source_message_id: args.sourceMessageId,
|
|
159
185
|
assignment_id: args.assignmentId,
|
|
160
186
|
reply_request_id: args.replyRequestId,
|
|
@@ -162,6 +188,18 @@ export class BrokerClient extends EventEmitter {
|
|
|
162
188
|
contentType: args.contentType,
|
|
163
189
|
});
|
|
164
190
|
}
|
|
191
|
+
async claimRuntimeAssignment(args) {
|
|
192
|
+
if (this.pluginPid === null) {
|
|
193
|
+
throw new Error("BrokerClient.connect must be called before claimRuntimeAssignment");
|
|
194
|
+
}
|
|
195
|
+
return this.httpJson("POST", "/v1/runtime/assignment-claim", {
|
|
196
|
+
endpoint_id: args.endpointId,
|
|
197
|
+
plugin_pid: this.pluginPid,
|
|
198
|
+
endpoint_owner_token: this.requireEndpointOwnerToken(args.endpointId),
|
|
199
|
+
undispatched_id: args.undispatchedId,
|
|
200
|
+
...(args.recoverExisting === true && { recover_existing: true }),
|
|
201
|
+
});
|
|
202
|
+
}
|
|
165
203
|
async reportRuntimeProcessingState(args) {
|
|
166
204
|
if (this.pluginPid === null) {
|
|
167
205
|
throw new Error("BrokerClient.connect must be called before reportRuntimeProcessingState");
|
|
@@ -169,6 +207,7 @@ export class BrokerClient extends EventEmitter {
|
|
|
169
207
|
await this.httpJson("POST", "/v1/runtime/processing-state", {
|
|
170
208
|
endpoint_id: args.endpointId,
|
|
171
209
|
plugin_pid: this.pluginPid,
|
|
210
|
+
endpoint_owner_token: this.requireEndpointOwnerToken(args.endpointId),
|
|
172
211
|
source_message_id: args.sourceMessageId,
|
|
173
212
|
assignment_id: args.assignmentId,
|
|
174
213
|
state_event_id: args.stateEventId,
|
|
@@ -196,6 +235,7 @@ export class BrokerClient extends EventEmitter {
|
|
|
196
235
|
this.ws.readyState === WebSocket.CONNECTING)) {
|
|
197
236
|
this.ws.close(1000, "client_close");
|
|
198
237
|
}
|
|
238
|
+
this.clearHeartbeat();
|
|
199
239
|
this.ws = null;
|
|
200
240
|
}
|
|
201
241
|
on(event, listener) {
|
|
@@ -215,6 +255,9 @@ export class BrokerClient extends EventEmitter {
|
|
|
215
255
|
method,
|
|
216
256
|
headers: {
|
|
217
257
|
Authorization: `Bearer ${this.handle.record.bearerToken}`,
|
|
258
|
+
...(this.pluginPid !== null
|
|
259
|
+
? { "x-plugin-pid": String(this.pluginPid) }
|
|
260
|
+
: {}),
|
|
218
261
|
...(body ? { "Content-Type": "application/json" } : {}),
|
|
219
262
|
},
|
|
220
263
|
body: body ? JSON.stringify(body) : undefined,
|
|
@@ -247,6 +290,13 @@ export class BrokerClient extends EventEmitter {
|
|
|
247
290
|
}
|
|
248
291
|
return (await res.json());
|
|
249
292
|
}
|
|
293
|
+
requireEndpointOwnerToken(endpointId) {
|
|
294
|
+
const token = this.endpointOwnerTokens.get(endpointId);
|
|
295
|
+
if (!token) {
|
|
296
|
+
throw new Error("endpoint_owner_token missing; endpoint must be registered through this BrokerClient before endpoint-scoped operations");
|
|
297
|
+
}
|
|
298
|
+
return token;
|
|
299
|
+
}
|
|
250
300
|
handleFrame(raw) {
|
|
251
301
|
let parsed;
|
|
252
302
|
try {
|
|
@@ -258,6 +308,11 @@ export class BrokerClient extends EventEmitter {
|
|
|
258
308
|
}
|
|
259
309
|
if (!parsed || typeof parsed !== "object" || !("event" in parsed))
|
|
260
310
|
return;
|
|
311
|
+
const pushId = parsed.push_id;
|
|
312
|
+
if (typeof pushId === "string" &&
|
|
313
|
+
this._serverCapabilities.push_receipt_ack_v1 === true) {
|
|
314
|
+
this.sendPushAck(pushId);
|
|
315
|
+
}
|
|
261
316
|
const event = parsed.event;
|
|
262
317
|
if (event === "message_received") {
|
|
263
318
|
const msg = parsed;
|
|
@@ -291,4 +346,69 @@ export class BrokerClient extends EventEmitter {
|
|
|
291
346
|
return;
|
|
292
347
|
}
|
|
293
348
|
}
|
|
349
|
+
sendPushAck(pushId) {
|
|
350
|
+
const ws = this.ws;
|
|
351
|
+
if (!ws || ws.readyState !== WebSocket.OPEN)
|
|
352
|
+
return;
|
|
353
|
+
try {
|
|
354
|
+
ws.send(JSON.stringify({ event: "push_ack", push_id: pushId }));
|
|
355
|
+
}
|
|
356
|
+
catch (err) {
|
|
357
|
+
this.emit("error", err instanceof Error ? err : new Error(String(err)));
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
startHeartbeat(intervalMs) {
|
|
361
|
+
this.clearHeartbeat();
|
|
362
|
+
if (!Number.isFinite(intervalMs) || intervalMs <= 0)
|
|
363
|
+
return;
|
|
364
|
+
const timer = setInterval(() => this.sendHeartbeatProbe(), intervalMs);
|
|
365
|
+
const maybeUnref = timer;
|
|
366
|
+
if (typeof maybeUnref.unref === "function")
|
|
367
|
+
maybeUnref.unref();
|
|
368
|
+
this.heartbeatInterval = timer;
|
|
369
|
+
}
|
|
370
|
+
sendHeartbeatProbe() {
|
|
371
|
+
const ws = this.ws;
|
|
372
|
+
if (!ws || ws.readyState !== WebSocket.OPEN)
|
|
373
|
+
return;
|
|
374
|
+
if (this.heartbeatTimeout)
|
|
375
|
+
return;
|
|
376
|
+
try {
|
|
377
|
+
ws.ping();
|
|
378
|
+
}
|
|
379
|
+
catch (err) {
|
|
380
|
+
this.emit("error", err instanceof Error ? err : new Error(String(err)));
|
|
381
|
+
ws.terminate();
|
|
382
|
+
return;
|
|
383
|
+
}
|
|
384
|
+
const timeout = setTimeout(() => {
|
|
385
|
+
this.heartbeatTimeout = null;
|
|
386
|
+
this.heartbeatMisses += 1;
|
|
387
|
+
if (this.heartbeatMisses >= this.heartbeatMissesBeforeDisconnect) {
|
|
388
|
+
ws.terminate();
|
|
389
|
+
}
|
|
390
|
+
}, this.heartbeatTimeoutMs);
|
|
391
|
+
const maybeUnref = timeout;
|
|
392
|
+
if (typeof maybeUnref.unref === "function")
|
|
393
|
+
maybeUnref.unref();
|
|
394
|
+
this.heartbeatTimeout = timeout;
|
|
395
|
+
}
|
|
396
|
+
markHeartbeatAlive() {
|
|
397
|
+
this.heartbeatMisses = 0;
|
|
398
|
+
if (this.heartbeatTimeout) {
|
|
399
|
+
clearTimeout(this.heartbeatTimeout);
|
|
400
|
+
this.heartbeatTimeout = null;
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
clearHeartbeat() {
|
|
404
|
+
if (this.heartbeatInterval) {
|
|
405
|
+
clearInterval(this.heartbeatInterval);
|
|
406
|
+
this.heartbeatInterval = null;
|
|
407
|
+
}
|
|
408
|
+
if (this.heartbeatTimeout) {
|
|
409
|
+
clearTimeout(this.heartbeatTimeout);
|
|
410
|
+
this.heartbeatTimeout = null;
|
|
411
|
+
}
|
|
412
|
+
this.heartbeatMisses = 0;
|
|
413
|
+
}
|
|
294
414
|
}
|
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
import { PlatformApiError, type PlatformClientConfig } from "./platform-client.js";
|
|
2
|
+
type PartialRuntimeSelfClaimResponse = Omit<Partial<RuntimeSelfClaimResponse>, "target_ref"> & {
|
|
3
|
+
target_ref?: RuntimeWorkTargetRef;
|
|
4
|
+
};
|
|
2
5
|
export { PlatformApiError, type PlatformClientConfig };
|
|
3
6
|
export type RuntimeKind = "claude-code" | "openclaw" | "codex" | "passport" | "custom" | (string & {});
|
|
4
7
|
export type RuntimeEndpointCapability = "remote_spawn_v1" | "background_exchange_v1" | "foreground_channel_v1" | (string & {});
|
|
@@ -84,6 +87,36 @@ export interface UpdateRuntimeEndpointDisplayMetadataParams {
|
|
|
84
87
|
session_name?: string;
|
|
85
88
|
task_hint?: string;
|
|
86
89
|
}
|
|
90
|
+
export interface RuntimeSelfClaimParams {
|
|
91
|
+
undispatched_id: string;
|
|
92
|
+
target_endpoint_id: string;
|
|
93
|
+
endpoint_nonce: string;
|
|
94
|
+
recover_existing?: boolean;
|
|
95
|
+
}
|
|
96
|
+
export interface RuntimeSelfClaimResponse {
|
|
97
|
+
assignment_id: string;
|
|
98
|
+
undispatched_id: string;
|
|
99
|
+
source_message_id: string;
|
|
100
|
+
target_ref: RuntimeWorkTargetRef;
|
|
101
|
+
broker_projection_token: string;
|
|
102
|
+
assigned_at: number;
|
|
103
|
+
claimed: boolean;
|
|
104
|
+
message: {
|
|
105
|
+
from: string;
|
|
106
|
+
content: string;
|
|
107
|
+
contentType: string;
|
|
108
|
+
metadata?: Record<string, unknown>;
|
|
109
|
+
sourceMessageId: string;
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
export interface RuntimeSelfClaimReleaseParams {
|
|
113
|
+
undispatched_id: string;
|
|
114
|
+
source_message_id: string;
|
|
115
|
+
assignment_id: string;
|
|
116
|
+
target_ref: RuntimeWorkTargetRef;
|
|
117
|
+
endpoint_nonce: string;
|
|
118
|
+
broker_projection_token: string;
|
|
119
|
+
}
|
|
87
120
|
export declare function registerRuntimeEndpoint(cfg: PlatformClientConfig, runtimeKey: string, params: RegisterRuntimeEndpointParams): Promise<RegisterRuntimeEndpointResponse>;
|
|
88
121
|
export declare function heartbeatRuntimeEndpoint(cfg: PlatformClientConfig, runtimeKey: string, endpointId: string): Promise<HeartbeatRuntimeEndpointResponse>;
|
|
89
122
|
export declare function transitionRuntimeEndpointState(cfg: PlatformClientConfig, runtimeKey: string, endpointId: string, params: TransitionRuntimeEndpointStateParams): Promise<TransitionRuntimeEndpointStateResponse>;
|
|
@@ -109,8 +142,20 @@ export type RuntimeInboundRouteClaimOutcome = {
|
|
|
109
142
|
status?: number;
|
|
110
143
|
detail?: string;
|
|
111
144
|
};
|
|
145
|
+
export type RuntimeSelfClaimOutcome = {
|
|
146
|
+
ok: true;
|
|
147
|
+
claim: RuntimeSelfClaimResponse;
|
|
148
|
+
} | {
|
|
149
|
+
ok: false;
|
|
150
|
+
terminal: boolean;
|
|
151
|
+
status?: number;
|
|
152
|
+
detail?: string;
|
|
153
|
+
postCasInvalidClaim?: PartialRuntimeSelfClaimResponse;
|
|
154
|
+
};
|
|
112
155
|
export declare function emitRuntimeNetworkPresenceChanged(cfg: PlatformClientConfig, runtimeKey: string, event: Readonly<Record<string, unknown>>): Promise<EmitUndispatchedChangedOutcome>;
|
|
113
156
|
export declare function claimRuntimeInboundRoute(cfg: PlatformClientConfig, runtimeKey: string, event: Readonly<Record<string, unknown>>): Promise<RuntimeInboundRouteClaimOutcome>;
|
|
157
|
+
export declare function claimRuntimeSelfAssignment(cfg: PlatformClientConfig, runtimeKey: string, params: RuntimeSelfClaimParams): Promise<RuntimeSelfClaimOutcome>;
|
|
158
|
+
export declare function releaseRuntimeSelfAssignment(cfg: PlatformClientConfig, runtimeKey: string, params: RuntimeSelfClaimReleaseParams): Promise<EmitUndispatchedChangedOutcome>;
|
|
114
159
|
export declare function emitRuntimeInboundRouted(cfg: PlatformClientConfig, runtimeKey: string, event: Readonly<Record<string, unknown>>): Promise<EmitUndispatchedChangedOutcome>;
|
|
115
160
|
export declare function emitRuntimeProcessingState(cfg: PlatformClientConfig, runtimeKey: string, event: Readonly<Record<string, unknown>>): Promise<EmitUndispatchedChangedOutcome>;
|
|
116
161
|
//# sourceMappingURL=runtime-endpoint-client.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runtime-endpoint-client.d.ts","sourceRoot":"","sources":["../src/runtime-endpoint-client.ts"],"names":[],"mappings":"AAuBA,OAAO,EACL,gBAAgB,EAChB,KAAK,oBAAoB,EAC1B,MAAM,sBAAsB,CAAC;
|
|
1
|
+
{"version":3,"file":"runtime-endpoint-client.d.ts","sourceRoot":"","sources":["../src/runtime-endpoint-client.ts"],"names":[],"mappings":"AAuBA,OAAO,EACL,gBAAgB,EAChB,KAAK,oBAAoB,EAC1B,MAAM,sBAAsB,CAAC;AAE9B,KAAK,+BAA+B,GAAG,IAAI,CACzC,OAAO,CAAC,wBAAwB,CAAC,EACjC,YAAY,CACb,GAAG;IACF,UAAU,CAAC,EAAE,oBAAoB,CAAC;CACnC,CAAC;AAMF,OAAO,EAAE,gBAAgB,EAAE,KAAK,oBAAoB,EAAE,CAAC;AAmBvD,MAAM,MAAM,WAAW,GACnB,aAAa,GACb,UAAU,GACV,OAAO,GACP,UAAU,GACV,QAAQ,GACR,CAAC,MAAM,GAAG,EAAE,CAA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B,CAC5C,GAAG,EAAE,oBAAoB,EACzB,UAAU,EAAE,MAAM,EAClB,KAAK,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,GACvC,OAAO,CAAC,+BAA+B,CAAC,CA2C1C;AAMD,wBAAsB,0BAA0B,CAC9C,GAAG,EAAE,oBAAoB,EACzB,UAAU,EAAE,MAAM,EAClB,MAAM,EAAE,sBAAsB,GAC7B,OAAO,CAAC,uBAAuB,CAAC,CA4GlC;AAMD,wBAAsB,4BAA4B,CAChD,GAAG,EAAE,oBAAoB,EACzB,UAAU,EAAE,MAAM,EAClB,MAAM,EAAE,6BAA6B,GACpC,OAAO,CAAC,8BAA8B,CAAC,CAoCzC;AAOD,wBAAsB,wBAAwB,CAC5C,GAAG,EAAE,oBAAoB,EACzB,UAAU,EAAE,MAAM,EAClB,KAAK,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,GACvC,OAAO,CAAC,8BAA8B,CAAC,CA8BzC;AAMD,wBAAsB,0BAA0B,CAC9C,GAAG,EAAE,oBAAoB,EACzB,UAAU,EAAE,MAAM,EAClB,KAAK,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,GACvC,OAAO,CAAC,8BAA8B,CAAC,CAmCzC"}
|
|
@@ -20,6 +20,35 @@ function jsonHeaders(runtimeKey) {
|
|
|
20
20
|
"Content-Type": "application/json",
|
|
21
21
|
};
|
|
22
22
|
}
|
|
23
|
+
function readRuntimeWorkTargetRef(value) {
|
|
24
|
+
if (!value || typeof value !== "object")
|
|
25
|
+
return null;
|
|
26
|
+
const raw = value;
|
|
27
|
+
if (raw.kind !== "projection_endpoint" ||
|
|
28
|
+
typeof raw.projection_endpoint_id !== "string") {
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
31
|
+
if (raw.background_exchange_mode === "resident_endpoint") {
|
|
32
|
+
if (raw.runtime_session_id !== undefined)
|
|
33
|
+
return null;
|
|
34
|
+
return {
|
|
35
|
+
kind: "projection_endpoint",
|
|
36
|
+
projection_endpoint_id: raw.projection_endpoint_id,
|
|
37
|
+
background_exchange_mode: "resident_endpoint",
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
if (raw.background_exchange_mode === "adapter_managed_turn" &&
|
|
41
|
+
typeof raw.runtime_session_id === "string" &&
|
|
42
|
+
raw.runtime_session_id.trim().length > 0) {
|
|
43
|
+
return {
|
|
44
|
+
kind: "projection_endpoint",
|
|
45
|
+
projection_endpoint_id: raw.projection_endpoint_id,
|
|
46
|
+
runtime_session_id: raw.runtime_session_id,
|
|
47
|
+
background_exchange_mode: "adapter_managed_turn",
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
return null;
|
|
51
|
+
}
|
|
23
52
|
export async function registerRuntimeEndpoint(cfg, runtimeKey, params) {
|
|
24
53
|
const res = await fetch(`${baseUrl(cfg)}/runtime-endpoints`, {
|
|
25
54
|
method: "POST",
|
|
@@ -200,6 +229,147 @@ export async function claimRuntimeInboundRoute(cfg, runtimeKey, event) {
|
|
|
200
229
|
detail: await readErrorDetail(res),
|
|
201
230
|
};
|
|
202
231
|
}
|
|
232
|
+
export async function claimRuntimeSelfAssignment(cfg, runtimeKey, params) {
|
|
233
|
+
let res;
|
|
234
|
+
try {
|
|
235
|
+
res = await fetch(`${baseUrl(cfg)}/runtime/self-claim`, {
|
|
236
|
+
method: "POST",
|
|
237
|
+
headers: jsonHeaders(runtimeKey),
|
|
238
|
+
body: JSON.stringify(params),
|
|
239
|
+
});
|
|
240
|
+
}
|
|
241
|
+
catch (err) {
|
|
242
|
+
return {
|
|
243
|
+
ok: false,
|
|
244
|
+
terminal: false,
|
|
245
|
+
detail: err instanceof Error ? err.message : String(err),
|
|
246
|
+
};
|
|
247
|
+
}
|
|
248
|
+
if (res.status === 200 || res.status === 201) {
|
|
249
|
+
const rawBody = (await res.json().catch(() => null));
|
|
250
|
+
const body = rawBody !== null && typeof rawBody === "object" && !Array.isArray(rawBody)
|
|
251
|
+
? rawBody
|
|
252
|
+
: null;
|
|
253
|
+
const targetRef = readRuntimeWorkTargetRef(body?.target_ref);
|
|
254
|
+
const assignmentId = body?.assignment_id;
|
|
255
|
+
const undispatchedId = body?.undispatched_id;
|
|
256
|
+
const sourceMessageId = body?.source_message_id;
|
|
257
|
+
const brokerProjectionToken = body?.broker_projection_token;
|
|
258
|
+
const assignedAt = body?.assigned_at;
|
|
259
|
+
const claimed = body?.claimed;
|
|
260
|
+
const message = body?.message;
|
|
261
|
+
if (targetRef !== null &&
|
|
262
|
+
typeof assignmentId === "string" &&
|
|
263
|
+
typeof undispatchedId === "string" &&
|
|
264
|
+
typeof sourceMessageId === "string" &&
|
|
265
|
+
typeof brokerProjectionToken === "string" &&
|
|
266
|
+
typeof assignedAt === "number" &&
|
|
267
|
+
typeof claimed === "boolean" &&
|
|
268
|
+
typeof message === "object" &&
|
|
269
|
+
message !== null &&
|
|
270
|
+
typeof message.from === "string" &&
|
|
271
|
+
typeof message.content === "string" &&
|
|
272
|
+
typeof message.contentType === "string" &&
|
|
273
|
+
typeof message.sourceMessageId === "string" &&
|
|
274
|
+
message.sourceMessageId === sourceMessageId &&
|
|
275
|
+
undispatchedId === params.undispatched_id &&
|
|
276
|
+
(message.metadata === undefined ||
|
|
277
|
+
(typeof message.metadata === "object" &&
|
|
278
|
+
message.metadata !== null &&
|
|
279
|
+
!Array.isArray(message.metadata)))) {
|
|
280
|
+
const claim = {
|
|
281
|
+
assignment_id: assignmentId,
|
|
282
|
+
undispatched_id: undispatchedId,
|
|
283
|
+
source_message_id: sourceMessageId,
|
|
284
|
+
target_ref: targetRef,
|
|
285
|
+
broker_projection_token: brokerProjectionToken,
|
|
286
|
+
assigned_at: assignedAt,
|
|
287
|
+
claimed,
|
|
288
|
+
message: {
|
|
289
|
+
from: message.from,
|
|
290
|
+
content: message.content,
|
|
291
|
+
contentType: message.contentType,
|
|
292
|
+
...(message.metadata !== undefined && {
|
|
293
|
+
metadata: message.metadata,
|
|
294
|
+
}),
|
|
295
|
+
sourceMessageId: message.sourceMessageId,
|
|
296
|
+
},
|
|
297
|
+
};
|
|
298
|
+
return {
|
|
299
|
+
ok: true,
|
|
300
|
+
claim,
|
|
301
|
+
};
|
|
302
|
+
}
|
|
303
|
+
const postCasInvalidClaim = body
|
|
304
|
+
? {
|
|
305
|
+
...body,
|
|
306
|
+
...(targetRef !== null && { target_ref: targetRef }),
|
|
307
|
+
}
|
|
308
|
+
: undefined;
|
|
309
|
+
return {
|
|
310
|
+
ok: false,
|
|
311
|
+
terminal: true,
|
|
312
|
+
status: res.status,
|
|
313
|
+
detail: "invalid self-claim response",
|
|
314
|
+
...(postCasInvalidClaim !== undefined && { postCasInvalidClaim }),
|
|
315
|
+
};
|
|
316
|
+
}
|
|
317
|
+
if (res.status === 401 ||
|
|
318
|
+
res.status === 403 ||
|
|
319
|
+
res.status === 404 ||
|
|
320
|
+
res.status === 409 ||
|
|
321
|
+
res.status === 422) {
|
|
322
|
+
return {
|
|
323
|
+
ok: false,
|
|
324
|
+
terminal: true,
|
|
325
|
+
status: res.status,
|
|
326
|
+
detail: await readErrorDetail(res),
|
|
327
|
+
};
|
|
328
|
+
}
|
|
329
|
+
return {
|
|
330
|
+
ok: false,
|
|
331
|
+
terminal: false,
|
|
332
|
+
status: res.status,
|
|
333
|
+
detail: await readErrorDetail(res),
|
|
334
|
+
};
|
|
335
|
+
}
|
|
336
|
+
export async function releaseRuntimeSelfAssignment(cfg, runtimeKey, params) {
|
|
337
|
+
let res;
|
|
338
|
+
try {
|
|
339
|
+
res = await fetch(`${baseUrl(cfg)}/runtime/self-claim/release`, {
|
|
340
|
+
method: "POST",
|
|
341
|
+
headers: jsonHeaders(runtimeKey),
|
|
342
|
+
body: JSON.stringify(params),
|
|
343
|
+
});
|
|
344
|
+
}
|
|
345
|
+
catch (err) {
|
|
346
|
+
return {
|
|
347
|
+
ok: false,
|
|
348
|
+
terminal: false,
|
|
349
|
+
detail: err instanceof Error ? err.message : String(err),
|
|
350
|
+
};
|
|
351
|
+
}
|
|
352
|
+
if (res.status === 204)
|
|
353
|
+
return { ok: true };
|
|
354
|
+
if (res.status === 401 ||
|
|
355
|
+
res.status === 403 ||
|
|
356
|
+
res.status === 404 ||
|
|
357
|
+
res.status === 409 ||
|
|
358
|
+
res.status === 422) {
|
|
359
|
+
return {
|
|
360
|
+
ok: false,
|
|
361
|
+
terminal: true,
|
|
362
|
+
status: res.status,
|
|
363
|
+
detail: await readErrorDetail(res),
|
|
364
|
+
};
|
|
365
|
+
}
|
|
366
|
+
return {
|
|
367
|
+
ok: false,
|
|
368
|
+
terminal: false,
|
|
369
|
+
status: res.status,
|
|
370
|
+
detail: await readErrorDetail(res),
|
|
371
|
+
};
|
|
372
|
+
}
|
|
203
373
|
export async function emitRuntimeInboundRouted(cfg, runtimeKey, event) {
|
|
204
374
|
let res;
|
|
205
375
|
try {
|
package/dist/version.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const PLUGIN_VERSION = "0.2.
|
|
1
|
+
export declare const PLUGIN_VERSION = "0.2.10";
|
|
2
2
|
//# sourceMappingURL=version.d.ts.map
|
package/dist/version.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../src/version.ts"],"names":[],"mappings":"AACA,eAAO,MAAM,cAAc,
|
|
1
|
+
{"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../src/version.ts"],"names":[],"mappings":"AACA,eAAO,MAAM,cAAc,WAAW,CAAC"}
|
package/dist/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const PLUGIN_VERSION = "0.2.
|
|
1
|
+
export const PLUGIN_VERSION = "0.2.10";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@masons/runtime-broker",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.10",
|
|
4
4
|
"description": "MASONS Runtime Broker — local daemon and BrokerClient SDK for multi-session agent runtime coordination.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "MASONS.ai <hello@masons.ai> (https://masons.ai)",
|