@masons/runtime-broker 0.1.0 → 0.1.1
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.map +1 -1
- package/dist/broker/broker-daemon.js +79 -2
- package/dist/broker/entry.d.ts +7 -0
- package/dist/broker/entry.d.ts.map +1 -1
- package/dist/broker/entry.js +38 -3
- package/dist/broker/runtime-endpoint-port.d.ts +2 -1
- package/dist/broker/runtime-endpoint-port.d.ts.map +1 -1
- package/dist/runtime-endpoint-client.d.ts +7 -0
- package/dist/runtime-endpoint-client.d.ts.map +1 -1
- package/dist/runtime-endpoint-client.js +9 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"broker-daemon.d.ts","sourceRoot":"","sources":["../../src/broker/broker-daemon.ts"],"names":[],"mappings":"AA2BA,OAAO,EAAqB,KAAK,IAAI,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAE5E,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"broker-daemon.d.ts","sourceRoot":"","sources":["../../src/broker/broker-daemon.ts"],"names":[],"mappings":"AA2BA,OAAO,EAAqB,KAAK,IAAI,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAE5E,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAGjD,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,6BAA6B,CAAC;AACxE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AACrD,OAAO,EACL,KAAK,sBAAsB,EAE5B,MAAM,+BAA+B,CAAC;AACvC,OAAO,KAAK,EACV,UAAU,EAIX,MAAM,0BAA0B,CAAC;AAOlC,OAAO,EAEL,KAAK,aAAa,EAEnB,MAAM,6BAA6B,CAAC;AAcrC,OAAO,KAAK,EAAE,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MAAM,CAAC;IAGzB,yBAAyB,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,CAAC;IAGvD,4BAA4B,IAAI,MAAM,CAAC;IAGvC,+BAA+B,IAAI,MAAM,CAAC;CAC3C;AAED,wBAAsB,iBAAiB,CACrC,IAAI,EAAE,mBAAmB,GACxB,OAAO,CAAC,aAAa,CAAC,CAwvCxB;AAGD,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,eAAe,GAAG,MAAM,GAAG,IAAI,CAMvE;AAED,YAAY,EAAE,eAAe,EAAE,CAAC"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { spawn as spawnChild } from "node:child_process";
|
|
2
2
|
import { randomUUID } from "node:crypto";
|
|
3
|
+
import { basename } from "node:path";
|
|
3
4
|
import { createControlEventDispatcher, } from "./control-event-dispatcher.js";
|
|
4
5
|
import { deleteDiscoveryFile, mintBearerToken, writeDiscoveryFile, } from "./discovery-file.js";
|
|
5
6
|
import { EndpointRegistry } from "./endpoint-registry.js";
|
|
@@ -18,6 +19,19 @@ import { createTransitionStateRetryQueue } from "./transition-state-retry-queue.
|
|
|
18
19
|
import { CONTENT_PREVIEW_MAX_CODEPOINTS, truncateContentPreview, } from "./undispatched-changed-event-types.js";
|
|
19
20
|
import { createUndispatchedChangedEmitter, postUndispatchedChangedViaPort, } from "./undispatched-emitter.js";
|
|
20
21
|
import { createUndispatchedInbox, } from "./undispatched-inbox.js";
|
|
22
|
+
function derivePublicDisplayLabel(body) {
|
|
23
|
+
const parts = [
|
|
24
|
+
body.kind,
|
|
25
|
+
body.workspace ? basename(body.workspace) || body.workspace : null,
|
|
26
|
+
body.tracking_ref ?? null,
|
|
27
|
+
].flatMap((part) => {
|
|
28
|
+
const value = part?.trim();
|
|
29
|
+
return value ? [value] : [];
|
|
30
|
+
});
|
|
31
|
+
return parts.length > 0
|
|
32
|
+
? parts.join(" · ")
|
|
33
|
+
: `${body.kind}-${String(body.plugin_pid).slice(-4)}`;
|
|
34
|
+
}
|
|
21
35
|
export async function startBrokerDaemon(opts) {
|
|
22
36
|
const { paths, asNodeId: _asNodeIdReservedForA3, connector, apiPort, logger, closedEndpointLookup, livenessProbe = defaultIsPluginAlive, spawnDriverRegistry, spawnFn = spawnChild, servicesEventClientFactory, } = opts;
|
|
23
37
|
const graceMs = opts.graceMs ?? DEFAULT_GRACE_MS;
|
|
@@ -154,7 +168,53 @@ export async function startBrokerDaemon(opts) {
|
|
|
154
168
|
});
|
|
155
169
|
const channels = new Map();
|
|
156
170
|
const wsEndpoints = new WeakMap();
|
|
171
|
+
const heartbeatTimers = new Map();
|
|
157
172
|
const displacedWs = new WeakSet();
|
|
173
|
+
const clearHeartbeat = (endpoint_id) => {
|
|
174
|
+
const timer = heartbeatTimers.get(endpoint_id);
|
|
175
|
+
if (!timer)
|
|
176
|
+
return;
|
|
177
|
+
clearTimeout(timer);
|
|
178
|
+
heartbeatTimers.delete(endpoint_id);
|
|
179
|
+
};
|
|
180
|
+
const clearAllHeartbeats = () => {
|
|
181
|
+
for (const endpoint_id of heartbeatTimers.keys()) {
|
|
182
|
+
clearHeartbeat(endpoint_id);
|
|
183
|
+
}
|
|
184
|
+
};
|
|
185
|
+
const scheduleHeartbeat = (endpoint_id, heartbeatAfterSeconds) => {
|
|
186
|
+
clearHeartbeat(endpoint_id);
|
|
187
|
+
if (!Number.isFinite(heartbeatAfterSeconds) || heartbeatAfterSeconds <= 0) {
|
|
188
|
+
logger.warn("endpoint_heartbeat_not_scheduled", {
|
|
189
|
+
endpoint_id,
|
|
190
|
+
heartbeat_after_seconds: heartbeatAfterSeconds,
|
|
191
|
+
});
|
|
192
|
+
return;
|
|
193
|
+
}
|
|
194
|
+
const delayMs = Math.max(1, Math.floor(heartbeatAfterSeconds * 1000));
|
|
195
|
+
const timer = setTimeout(() => {
|
|
196
|
+
heartbeatTimers.delete(endpoint_id);
|
|
197
|
+
if (!registry.get(endpoint_id))
|
|
198
|
+
return;
|
|
199
|
+
void apiPort
|
|
200
|
+
.heartbeat(endpoint_id)
|
|
201
|
+
.catch((err) => {
|
|
202
|
+
logger.warn("endpoint_heartbeat_failed", {
|
|
203
|
+
endpoint_id,
|
|
204
|
+
err: err instanceof Error ? err.message : String(err),
|
|
205
|
+
});
|
|
206
|
+
})
|
|
207
|
+
.finally(() => {
|
|
208
|
+
if (registry.get(endpoint_id)) {
|
|
209
|
+
scheduleHeartbeat(endpoint_id, heartbeatAfterSeconds);
|
|
210
|
+
}
|
|
211
|
+
});
|
|
212
|
+
}, delayMs);
|
|
213
|
+
const maybeUnref = timer;
|
|
214
|
+
if (typeof maybeUnref.unref === "function")
|
|
215
|
+
maybeUnref.unref();
|
|
216
|
+
heartbeatTimers.set(endpoint_id, timer);
|
|
217
|
+
};
|
|
158
218
|
const emitTransition = (endpoint_id, state, reason) => {
|
|
159
219
|
const params = {
|
|
160
220
|
state,
|
|
@@ -225,6 +285,7 @@ export async function startBrokerDaemon(opts) {
|
|
|
225
285
|
reconnectingBuffers.cleanup(endpoint_id);
|
|
226
286
|
break;
|
|
227
287
|
case "remove_from_registry":
|
|
288
|
+
clearHeartbeat(endpoint_id);
|
|
228
289
|
registry.unregister(endpoint_id);
|
|
229
290
|
replyCorrelationCache.forgetEndpoint(endpoint_id);
|
|
230
291
|
void apiPort.unregister(endpoint_id).catch(() => {
|
|
@@ -394,12 +455,13 @@ export async function startBrokerDaemon(opts) {
|
|
|
394
455
|
const apiResp = await apiPort.register({
|
|
395
456
|
runtime_kind: body.kind,
|
|
396
457
|
endpoint_nonce: randomUUID(),
|
|
397
|
-
display_label: body
|
|
398
|
-
`${body.kind}-${String(body.plugin_pid).slice(-4)}`,
|
|
458
|
+
display_label: derivePublicDisplayLabel(body),
|
|
399
459
|
workspace: body.workspace
|
|
400
460
|
? { root: body.workspace, cwd: body.workspace }
|
|
401
461
|
: undefined,
|
|
402
462
|
tracking_ref: body.tracking_ref,
|
|
463
|
+
session_name: body.session_name,
|
|
464
|
+
task_hint: body.task_hint,
|
|
403
465
|
});
|
|
404
466
|
registry.register({
|
|
405
467
|
endpoint_id: apiResp.endpoint_id,
|
|
@@ -422,6 +484,7 @@ export async function startBrokerDaemon(opts) {
|
|
|
422
484
|
}
|
|
423
485
|
bound.add(apiResp.endpoint_id);
|
|
424
486
|
emitTransition(apiResp.endpoint_id, "active", "register");
|
|
487
|
+
scheduleHeartbeat(apiResp.endpoint_id, apiResp.heartbeat_after_seconds);
|
|
425
488
|
if (typeof body.spawn_token === "string") {
|
|
426
489
|
const pending = spawnCorrelation.consume(body.spawn_token);
|
|
427
490
|
if (pending) {
|
|
@@ -589,6 +652,19 @@ export async function startBrokerDaemon(opts) {
|
|
|
589
652
|
length: result.effective.length,
|
|
590
653
|
max: TASK_HINT_MAX_LENGTH,
|
|
591
654
|
});
|
|
655
|
+
if (apiPort.updateDisplayMetadata) {
|
|
656
|
+
try {
|
|
657
|
+
await apiPort.updateDisplayMetadata(body.endpoint_id, {
|
|
658
|
+
task_hint: result.effective,
|
|
659
|
+
});
|
|
660
|
+
}
|
|
661
|
+
catch (err) {
|
|
662
|
+
logger.warn("task_hint_projection_failed", {
|
|
663
|
+
endpoint_id: body.endpoint_id,
|
|
664
|
+
err: err instanceof Error ? err.message : String(err),
|
|
665
|
+
});
|
|
666
|
+
}
|
|
667
|
+
}
|
|
592
668
|
},
|
|
593
669
|
};
|
|
594
670
|
const bearerToken = mintBearerToken();
|
|
@@ -762,6 +838,7 @@ export async function startBrokerDaemon(opts) {
|
|
|
762
838
|
}
|
|
763
839
|
}
|
|
764
840
|
graceTimers.cancelAll();
|
|
841
|
+
clearAllHeartbeats();
|
|
765
842
|
spawnCorrelation.cancelAll();
|
|
766
843
|
if (presenceGraceTimer) {
|
|
767
844
|
clearTimeout(presenceGraceTimer);
|
package/dist/broker/entry.d.ts
CHANGED
|
@@ -6,7 +6,14 @@ interface ResolvedCredentials {
|
|
|
6
6
|
token: string;
|
|
7
7
|
apiHost: string;
|
|
8
8
|
}
|
|
9
|
+
interface RuntimePrincipal {
|
|
10
|
+
ownerUserId?: string;
|
|
11
|
+
subjectType: string;
|
|
12
|
+
subjectId: string;
|
|
13
|
+
carrier?: string;
|
|
14
|
+
}
|
|
9
15
|
export declare function resolveCredentialsFromFile(filePath: string, accountId: string, envApiHost: string | undefined): Promise<ResolvedCredentials>;
|
|
16
|
+
export declare function resolveRuntimePrincipal(apiHost: string, runtimeKey: string, fetchImpl?: typeof globalThis.fetch): Promise<RuntimePrincipal>;
|
|
10
17
|
export declare function buildApiPort(apiHost: string, runtimeKey: string, logger: BrokerLogger): RuntimeEndpointPort;
|
|
11
18
|
export declare function main(): Promise<void>;
|
|
12
19
|
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"entry.d.ts","sourceRoot":"","sources":["../../src/broker/entry.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"entry.d.ts","sourceRoot":"","sources":["../../src/broker/entry.ts"],"names":[],"mappings":"AAgFA,OAAO,EAAE,KAAK,YAAY,EAAsB,MAAM,aAAa,CAAC;AAEpE,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AAMtE,UAAU,mBAAmB;IAC3B,SAAS,EAAE,MAAM,CAAC;IAClB,YAAY,EAAE,MAAM,CAAC;IACrB,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,UAAU,gBAAgB;IACxB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAUD,wBAAsB,0BAA0B,CAC9C,QAAQ,EAAE,MAAM,EAChB,SAAS,EAAE,MAAM,EACjB,UAAU,EAAE,MAAM,GAAG,SAAS,GAC7B,OAAO,CAAC,mBAAmB,CAAC,CA8F9B;AA2DD,wBAAsB,uBAAuB,CAC3C,OAAO,EAAE,MAAM,EACf,UAAU,EAAE,MAAM,EAClB,SAAS,GAAE,OAAO,UAAU,CAAC,KAAwB,GACpD,OAAO,CAAC,gBAAgB,CAAC,CA4B3B;AAaD,wBAAgB,YAAY,CAC1B,OAAO,EAAE,MAAM,EACf,UAAU,EAAE,MAAM,EAClB,MAAM,EAAE,YAAY,GACnB,mBAAmB,CAgHrB;AAYD,wBAAsB,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC,CAgG1C"}
|
package/dist/broker/entry.js
CHANGED
|
@@ -2,7 +2,7 @@ import { readFile } from "node:fs/promises";
|
|
|
2
2
|
import { pathToFileURL } from "node:url";
|
|
3
3
|
import { readConfig } from "../config-fs.js";
|
|
4
4
|
import { DEFAULT_API_HOST } from "../platform-client.js";
|
|
5
|
-
import { emitRuntimeNetworkPresenceChanged, emitRuntimeUndispatchedChanged, heartbeatRuntimeEndpoint, registerRuntimeEndpoint, transitionRuntimeEndpointState, unregisterRuntimeEndpoint, } from "../runtime-endpoint-client.js";
|
|
5
|
+
import { emitRuntimeNetworkPresenceChanged, emitRuntimeUndispatchedChanged, heartbeatRuntimeEndpoint, registerRuntimeEndpoint, transitionRuntimeEndpointState, unregisterRuntimeEndpoint, updateRuntimeEndpointDisplayMetadata, } from "../runtime-endpoint-client.js";
|
|
6
6
|
import { startBrokerDaemon } from "./broker-daemon.js";
|
|
7
7
|
import { ClaudeCodeSpawnDriver } from "./claude-code-spawn-driver.js";
|
|
8
8
|
import { CodexSpawnDriverStub } from "./codex-spawn-driver-stub.js";
|
|
@@ -92,6 +92,36 @@ async function resolveCredentials(accountId, envApiHost) {
|
|
|
92
92
|
}
|
|
93
93
|
return resolveCredentialsFromOpenClawConfig(accountId, envApiHost);
|
|
94
94
|
}
|
|
95
|
+
function apiBaseUrl(apiHost) {
|
|
96
|
+
const trimmed = apiHost.replace(/\/+$/, "");
|
|
97
|
+
const origin = /^https?:\/\//.test(trimmed) ? trimmed : `https://${trimmed}`;
|
|
98
|
+
return `${origin}/v1`;
|
|
99
|
+
}
|
|
100
|
+
export async function resolveRuntimePrincipal(apiHost, runtimeKey, fetchImpl = globalThis.fetch) {
|
|
101
|
+
const res = await fetchImpl(`${apiBaseUrl(apiHost)}/whoami`, {
|
|
102
|
+
headers: { Authorization: `Bearer ${runtimeKey}` },
|
|
103
|
+
});
|
|
104
|
+
if (!res.ok) {
|
|
105
|
+
throw new Error(`whoami failed: ${res.status}`);
|
|
106
|
+
}
|
|
107
|
+
const raw = (await res.json());
|
|
108
|
+
const subjectId = raw.subjectId;
|
|
109
|
+
const subjectType = raw.subjectType;
|
|
110
|
+
if (typeof subjectId !== "string" || subjectId.length === 0) {
|
|
111
|
+
throw new Error("whoami response missing subjectId");
|
|
112
|
+
}
|
|
113
|
+
if (subjectType !== "agent-runtime") {
|
|
114
|
+
throw new Error(`runtime broker requires agent-runtime credentials; got ${String(subjectType)}`);
|
|
115
|
+
}
|
|
116
|
+
return {
|
|
117
|
+
...(typeof raw.ownerUserId === "string" && {
|
|
118
|
+
ownerUserId: raw.ownerUserId,
|
|
119
|
+
}),
|
|
120
|
+
subjectType,
|
|
121
|
+
subjectId,
|
|
122
|
+
...(typeof raw.carrier === "string" && { carrier: raw.carrier }),
|
|
123
|
+
};
|
|
124
|
+
}
|
|
95
125
|
export function buildApiPort(apiHost, runtimeKey, logger) {
|
|
96
126
|
return {
|
|
97
127
|
async register(params) {
|
|
@@ -132,6 +162,9 @@ export function buildApiPort(apiHost, runtimeKey, logger) {
|
|
|
132
162
|
}
|
|
133
163
|
}
|
|
134
164
|
},
|
|
165
|
+
async updateDisplayMetadata(endpointId, params) {
|
|
166
|
+
await updateRuntimeEndpointDisplayMetadata({ apiHost }, runtimeKey, endpointId, params);
|
|
167
|
+
},
|
|
135
168
|
async emitUndispatchedChanged(event) {
|
|
136
169
|
return emitRuntimeUndispatchedChanged({ apiHost }, runtimeKey, event);
|
|
137
170
|
},
|
|
@@ -158,12 +191,14 @@ export async function main() {
|
|
|
158
191
|
userDataDir: userDataOverride,
|
|
159
192
|
});
|
|
160
193
|
const logger = createBrokerLogger(paths.logDir);
|
|
194
|
+
const principal = await resolveRuntimePrincipal(creds.apiHost, creds.token);
|
|
161
195
|
logger.info("broker_entry_starting", {
|
|
162
196
|
accountId: creds.accountId,
|
|
197
|
+
subjectId: principal.subjectId,
|
|
163
198
|
apiHost: creds.apiHost,
|
|
164
199
|
pid: process.pid,
|
|
165
200
|
});
|
|
166
|
-
const asNodeId =
|
|
201
|
+
const asNodeId = principal.subjectId;
|
|
167
202
|
const connector = new ConnectorWS({
|
|
168
203
|
url: creds.connectorUrl,
|
|
169
204
|
token: creds.token,
|
|
@@ -208,7 +243,7 @@ export async function main() {
|
|
|
208
243
|
servicesEventClientFactory: ({ dispatcher, logger: clientLogger }) => createServicesEventClient({
|
|
209
244
|
apiHost: creds.apiHost,
|
|
210
245
|
runtimeKey: creds.token,
|
|
211
|
-
agentId:
|
|
246
|
+
agentId: principal.subjectId,
|
|
212
247
|
dispatcher,
|
|
213
248
|
logger: clientLogger,
|
|
214
249
|
}),
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { RegisterRuntimeEndpointParams, RegisterRuntimeEndpointResponse, TransitionRuntimeEndpointStateParams } from "../runtime-endpoint-client.js";
|
|
1
|
+
import type { RegisterRuntimeEndpointParams, RegisterRuntimeEndpointResponse, TransitionRuntimeEndpointStateParams, UpdateRuntimeEndpointDisplayMetadataParams } from "../runtime-endpoint-client.js";
|
|
2
2
|
import type { NetworkPresenceChangedEvent } from "./network-presence-changed-event-types.js";
|
|
3
3
|
import type { UndispatchedChangedEvent } from "./undispatched-changed-event-types.js";
|
|
4
4
|
export type EmitOutcome = {
|
|
@@ -14,6 +14,7 @@ export interface RuntimeEndpointPort {
|
|
|
14
14
|
heartbeat(endpointId: string): Promise<void>;
|
|
15
15
|
unregister(endpointId: string, asNodeId?: string): Promise<void>;
|
|
16
16
|
transitionState(endpointId: string, params: TransitionRuntimeEndpointStateParams): Promise<void>;
|
|
17
|
+
updateDisplayMetadata?(endpointId: string, params: UpdateRuntimeEndpointDisplayMetadataParams): Promise<void>;
|
|
17
18
|
emitUndispatchedChanged?(event: UndispatchedChangedEvent): Promise<EmitOutcome>;
|
|
18
19
|
emitNetworkPresenceChanged?(event: NetworkPresenceChangedEvent): Promise<EmitOutcome>;
|
|
19
20
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runtime-endpoint-port.d.ts","sourceRoot":"","sources":["../../src/broker/runtime-endpoint-port.ts"],"names":[],"mappings":"AAoBA,OAAO,KAAK,EACV,6BAA6B,EAC7B,+BAA+B,EAC/B,oCAAoC,
|
|
1
|
+
{"version":3,"file":"runtime-endpoint-port.d.ts","sourceRoot":"","sources":["../../src/broker/runtime-endpoint-port.ts"],"names":[],"mappings":"AAoBA,OAAO,KAAK,EACV,6BAA6B,EAC7B,+BAA+B,EAC/B,oCAAoC,EACpC,0CAA0C,EAC3C,MAAM,+BAA+B,CAAC;AACvC,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,2CAA2C,CAAC;AAC7F,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,uCAAuC,CAAC;AAWtF,MAAM,MAAM,WAAW,GACnB;IAAE,EAAE,EAAE,IAAI,CAAA;CAAE,GACZ;IAAE,EAAE,EAAE,KAAK,CAAC;IAAC,QAAQ,EAAE,OAAO,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC;AAEvE,MAAM,WAAW,mBAAmB;IAClC,QAAQ,CACN,MAAM,EAAE,6BAA6B,GACpC,OAAO,CAAC,+BAA+B,CAAC,CAAC;IAC5C,SAAS,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAO7C,UAAU,CAAC,UAAU,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAQjE,eAAe,CACb,UAAU,EAAE,MAAM,EAClB,MAAM,EAAE,oCAAoC,GAC3C,OAAO,CAAC,IAAI,CAAC,CAAC;IAKjB,qBAAqB,CAAC,CACpB,UAAU,EAAE,MAAM,EAClB,MAAM,EAAE,0CAA0C,GACjD,OAAO,CAAC,IAAI,CAAC,CAAC;IAqBjB,uBAAuB,CAAC,CACtB,KAAK,EAAE,wBAAwB,GAC9B,OAAO,CAAC,WAAW,CAAC,CAAC;IAYxB,0BAA0B,CAAC,CACzB,KAAK,EAAE,2BAA2B,GACjC,OAAO,CAAC,WAAW,CAAC,CAAC;CACzB"}
|
|
@@ -14,6 +14,8 @@ export interface RegisterRuntimeEndpointParams {
|
|
|
14
14
|
runtime_session_id?: string;
|
|
15
15
|
endpoint_nonce: string;
|
|
16
16
|
display_label: string;
|
|
17
|
+
session_name?: string;
|
|
18
|
+
task_hint?: string;
|
|
17
19
|
workspace?: WorkspaceMetadata;
|
|
18
20
|
tracking_ref?: string;
|
|
19
21
|
share_with_peer?: ShareWithPeerField[];
|
|
@@ -55,9 +57,14 @@ export interface TransitionRuntimeEndpointStateParams {
|
|
|
55
57
|
ts: string;
|
|
56
58
|
}
|
|
57
59
|
export type TransitionRuntimeEndpointStateResponse = Record<string, unknown>;
|
|
60
|
+
export interface UpdateRuntimeEndpointDisplayMetadataParams {
|
|
61
|
+
session_name?: string;
|
|
62
|
+
task_hint?: string;
|
|
63
|
+
}
|
|
58
64
|
export declare function registerRuntimeEndpoint(cfg: PlatformClientConfig, runtimeKey: string, params: RegisterRuntimeEndpointParams): Promise<RegisterRuntimeEndpointResponse>;
|
|
59
65
|
export declare function heartbeatRuntimeEndpoint(cfg: PlatformClientConfig, runtimeKey: string, endpointId: string): Promise<HeartbeatRuntimeEndpointResponse>;
|
|
60
66
|
export declare function transitionRuntimeEndpointState(cfg: PlatformClientConfig, runtimeKey: string, endpointId: string, params: TransitionRuntimeEndpointStateParams): Promise<TransitionRuntimeEndpointStateResponse>;
|
|
67
|
+
export declare function updateRuntimeEndpointDisplayMetadata(cfg: PlatformClientConfig, runtimeKey: string, endpointId: string, params: UpdateRuntimeEndpointDisplayMetadataParams): Promise<void>;
|
|
61
68
|
export declare function unregisterRuntimeEndpoint(cfg: PlatformClientConfig, runtimeKey: string, endpointId: string, asNodeId?: string): Promise<UnregisterRuntimeEndpointResponse>;
|
|
62
69
|
export declare function listOwnedRuntimeEndpoints(cfg: PlatformClientConfig, runtimeKey: string, asNodeId: string): Promise<ListOwnedRuntimeEndpointsResponse>;
|
|
63
70
|
export declare function getOwnedRuntimeEndpoint(cfg: PlatformClientConfig, runtimeKey: string, endpointId: string, asNodeId: string): Promise<OwnedRuntimeEndpointView>;
|
|
@@ -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;AAM9B,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,CAAC,CAAC;AAalB,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAeD,MAAM,MAAM,kBAAkB,GAC1B,WAAW,GACX,cAAc,GACd,oBAAoB,GACpB,aAAa,GACb,CAAC,MAAM,GAAG,EAAE,CAAC,CAAC;AAUlB,MAAM,WAAW,6BAA6B;IAQ5C,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,YAAY,EAAE,WAAW,CAAC;IAO1B,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAE5B,cAAc,EAAE,MAAM,CAAC;IAEvB,aAAa,EAAE,M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,EAAE,EAAE,IAAI,CAAA;CAAE,GACZ;IAAE,EAAE,EAAE,KAAK,CAAC;IAAC,QAAQ,EAAE,OAAO,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC;AAqBvE,wBAAsB,iCAAiC,CACrD,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"}
|
|
@@ -51,6 +51,15 @@ export async function transitionRuntimeEndpointState(cfg, runtimeKey, endpointId
|
|
|
51
51
|
return ((await res.json().catch(() => ({}))) ??
|
|
52
52
|
{});
|
|
53
53
|
}
|
|
54
|
+
export async function updateRuntimeEndpointDisplayMetadata(cfg, runtimeKey, endpointId, params) {
|
|
55
|
+
const res = await fetch(`${baseUrl(cfg)}/runtime-endpoints/${encodeURIComponent(endpointId)}/display-metadata`, {
|
|
56
|
+
method: "POST",
|
|
57
|
+
headers: jsonHeaders(runtimeKey),
|
|
58
|
+
body: JSON.stringify(params),
|
|
59
|
+
});
|
|
60
|
+
if (!res.ok)
|
|
61
|
+
return handleError(res);
|
|
62
|
+
}
|
|
54
63
|
export async function unregisterRuntimeEndpoint(cfg, runtimeKey, endpointId, asNodeId) {
|
|
55
64
|
const query = asNodeId
|
|
56
65
|
? `?${new URLSearchParams({ as: asNodeId }).toString()}`
|
package/dist/version.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const PLUGIN_VERSION = "0.1.
|
|
1
|
+
export declare const PLUGIN_VERSION = "0.1.1";
|
|
2
2
|
//# sourceMappingURL=version.d.ts.map
|
package/dist/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const PLUGIN_VERSION = "0.1.
|
|
1
|
+
export const PLUGIN_VERSION = "0.1.1";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@masons/runtime-broker",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1",
|
|
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)",
|