@masons/runtime-broker 0.2.6 → 0.2.7
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 +11 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +1 -1
- package/dist/broker/background-assignment-ledger.d.ts +0 -27
- package/dist/broker/background-assignment-ledger.d.ts.map +0 -1
- package/dist/broker/background-assignment-ledger.js +0 -125
|
@@ -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;AAQjD,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;
|
|
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;AAQjD,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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M,CAAC;IAEtC,oCAAoC,CAAC,EAAE,MAAM,CAAC;IAE9C,gCAAgC,CAAC,EAAE,MAAM,CAAC;IAE1C,8BAA8B,CAAC,EAAE,MAAM,CAAC;IAExC,oCAAoC,CAAC,EAAE,MAAM,CAAC;CAC/C;AAgBD,MAAM,WAAW,aAAa;IAC5B,WAAW,EAAE,MAAM,CAAC;IACpB,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAExC,YAAY,IAAI,MAAM,CAAC;IAGvB,KAAK,CAAC,WAAW,EAAE,MAAM,GAAG,aAAa,GAAG,SAAS,CAAC;IAEtD,iBAAiB,EAAE,iBAAiB,CAAC;IAErC,sBAAsB,EAAE,sBAAsB,CAAC;IAE/C,eAAe,IAAI,eAAe,CAAC;IAEnC,iBAAiB,IAAI,MAAM,CAAC;IAE5B,cAAc,IAAI,MAAM,CAAC;IAGzB,yBAAyB,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,CAAC;IAGvD,4BAA4B,IAAI,MAAM,CAAC;IAGvC,+BAA+B,IAAI,MAAM,CAAC;IAE1C,6BAA6B,IAAI,MAAM,CAAC;CACzC;AAED,wBAAsB,iBAAiB,CACrC,IAAI,EAAE,mBAAmB,GACxB,OAAO,CAAC,aAAa,CAAC,CAkjFxB;AAGD,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,eAAe,GAAG,MAAM,GAAG,IAAI,CAMvE;AAED,YAAY,EAAE,eAAe,EAAE,CAAC"}
|
|
@@ -5,7 +5,7 @@ import { ConnectorClientUnavailableError, ConnectorSendAckTimeoutError, } from "
|
|
|
5
5
|
import { createControlEventDispatcher, } from "./control-event-dispatcher.js";
|
|
6
6
|
import { readDeliveryCursorFile, writeDeliveryCursorFile, } from "./delivery-cursor-file.js";
|
|
7
7
|
import { deleteDiscoveryFile, mintBearerToken, writeDiscoveryFile, } from "./discovery-file.js";
|
|
8
|
-
import { EndpointRegistry } from "./endpoint-registry.js";
|
|
8
|
+
import { EndpointRegistry, } from "./endpoint-registry.js";
|
|
9
9
|
import { DEFAULT_GRACE_MS, transition, } from "./endpoint-state-machine.js";
|
|
10
10
|
import { createGraceTimerManager } from "./grace-timer.js";
|
|
11
11
|
import { BrokerHttpError, pushToPlugin, startIPCServer, } from "./ipc-server.js";
|
|
@@ -170,6 +170,9 @@ export async function startBrokerDaemon(opts) {
|
|
|
170
170
|
const endpointCorrelationKey = (endpointId, correlationId) => `${endpointId}\u0000${correlationId}`;
|
|
171
171
|
const isBackgroundExchangeTarget = (entry) => Boolean(entry.runtime_capabilities?.includes("background_exchange_v1") &&
|
|
172
172
|
isBackgroundExchangeMode(entry.background_exchange_mode));
|
|
173
|
+
const requiresForegroundChannel = (entry) => entry.execution_surface !== "headless";
|
|
174
|
+
const canAcceptRuntimeMailboxDispatch = (entry) => !requiresForegroundChannel(entry) ||
|
|
175
|
+
Boolean(entry.runtime_capabilities?.includes("foreground_channel_v1"));
|
|
173
176
|
const rememberRuntimeAssignmentCorrelation = (endpointId, correlationId, assignmentKey) => {
|
|
174
177
|
if (typeof correlationId !== "string" || correlationId.length === 0) {
|
|
175
178
|
return;
|
|
@@ -772,6 +775,13 @@ export async function startBrokerDaemon(opts) {
|
|
|
772
775
|
detail: `target endpoint not found: ${targetEndpointId}`,
|
|
773
776
|
};
|
|
774
777
|
}
|
|
778
|
+
if (!canAcceptRuntimeMailboxDispatch(target)) {
|
|
779
|
+
undispatchedInbox.tryAdd(taken);
|
|
780
|
+
return {
|
|
781
|
+
ok: false,
|
|
782
|
+
detail: `target endpoint is not foreground-channel capable: ${targetEndpointId}`,
|
|
783
|
+
};
|
|
784
|
+
}
|
|
775
785
|
let targetRef = event.target_ref;
|
|
776
786
|
if (!targetRef) {
|
|
777
787
|
if (target.background_exchange_mode === "resident_endpoint") {
|
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.7";
|
|
2
2
|
//# sourceMappingURL=version.d.ts.map
|
package/dist/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const PLUGIN_VERSION = "0.2.
|
|
1
|
+
export const PLUGIN_VERSION = "0.2.7";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@masons/runtime-broker",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.7",
|
|
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)",
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import type { UndispatchedMessage } from "./undispatched-inbox.js";
|
|
2
|
-
export type DurableBackgroundAssignmentState = "assigned" | "committing" | "committed";
|
|
3
|
-
export type DurableBackgroundAssignmentKind = "mailbox_dispatch" | "broker_route";
|
|
4
|
-
export interface DurableBackgroundAssignment {
|
|
5
|
-
kind: DurableBackgroundAssignmentKind;
|
|
6
|
-
state: DurableBackgroundAssignmentState;
|
|
7
|
-
assignmentId: string;
|
|
8
|
-
sourceMessageId: string;
|
|
9
|
-
endpointId: string;
|
|
10
|
-
message: UndispatchedMessage;
|
|
11
|
-
assignedAt: number;
|
|
12
|
-
acceptedAt?: number;
|
|
13
|
-
committedAt?: number;
|
|
14
|
-
deliverySeq?: number;
|
|
15
|
-
routeKind?: "active_endpoint" | "reconnecting_endpoint";
|
|
16
|
-
}
|
|
17
|
-
export interface BackgroundAssignmentLedger {
|
|
18
|
-
get(sourceMessageId: string): DurableBackgroundAssignment | undefined;
|
|
19
|
-
upsert(record: DurableBackgroundAssignment): boolean;
|
|
20
|
-
delete(sourceMessageId: string): boolean;
|
|
21
|
-
list(): DurableBackgroundAssignment[];
|
|
22
|
-
}
|
|
23
|
-
export interface BackgroundAssignmentLedgerOptions {
|
|
24
|
-
persistFile?: string;
|
|
25
|
-
}
|
|
26
|
-
export declare function createBackgroundAssignmentLedger(opts?: BackgroundAssignmentLedgerOptions): BackgroundAssignmentLedger;
|
|
27
|
-
//# sourceMappingURL=background-assignment-ledger.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"background-assignment-ledger.d.ts","sourceRoot":"","sources":["../../src/broker/background-assignment-ledger.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AAEnE,MAAM,MAAM,gCAAgC,GACxC,UAAU,GACV,YAAY,GACZ,WAAW,CAAC;AAEhB,MAAM,MAAM,+BAA+B,GACvC,kBAAkB,GAClB,cAAc,CAAC;AAEnB,MAAM,WAAW,2BAA2B;IAC1C,IAAI,EAAE,+BAA+B,CAAC;IACtC,KAAK,EAAE,gCAAgC,CAAC;IACxC,YAAY,EAAE,MAAM,CAAC;IACrB,eAAe,EAAE,MAAM,CAAC;IACxB,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,EAAE,mBAAmB,CAAC;IAC7B,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,SAAS,CAAC,EAAE,iBAAiB,GAAG,uBAAuB,CAAC;CACzD;AAED,MAAM,WAAW,0BAA0B;IACzC,GAAG,CAAC,eAAe,EAAE,MAAM,GAAG,2BAA2B,GAAG,SAAS,CAAC;IACtE,MAAM,CAAC,MAAM,EAAE,2BAA2B,GAAG,OAAO,CAAC;IACrD,MAAM,CAAC,eAAe,EAAE,MAAM,GAAG,OAAO,CAAC;IACzC,IAAI,IAAI,2BAA2B,EAAE,CAAC;CACvC;AAED,MAAM,WAAW,iCAAiC;IAChD,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,wBAAgB,gCAAgC,CAC9C,IAAI,GAAE,iCAAsC,GAC3C,0BAA0B,CAkF5B"}
|
|
@@ -1,125 +0,0 @@
|
|
|
1
|
-
import { closeSync, fdatasyncSync, mkdirSync, openSync, readFileSync, renameSync, writeSync, } from "node:fs";
|
|
2
|
-
import { dirname } from "node:path";
|
|
3
|
-
export function createBackgroundAssignmentLedger(opts = {}) {
|
|
4
|
-
const persistFile = opts.persistFile;
|
|
5
|
-
const bySourceMessageId = new Map();
|
|
6
|
-
const snapshot = () => [
|
|
7
|
-
...bySourceMessageId.values(),
|
|
8
|
-
];
|
|
9
|
-
const persist = () => {
|
|
10
|
-
if (!persistFile)
|
|
11
|
-
return;
|
|
12
|
-
mkdirSync(dirname(persistFile), { recursive: true, mode: 0o700 });
|
|
13
|
-
const tmp = `${persistFile}.tmp`;
|
|
14
|
-
const fd = openSync(tmp, "w", 0o600);
|
|
15
|
-
try {
|
|
16
|
-
writeSync(fd, `${JSON.stringify({ version: 1, assignments: snapshot() })}\n`);
|
|
17
|
-
fdatasyncSync(fd);
|
|
18
|
-
}
|
|
19
|
-
finally {
|
|
20
|
-
closeSync(fd);
|
|
21
|
-
}
|
|
22
|
-
renameSync(tmp, persistFile);
|
|
23
|
-
};
|
|
24
|
-
if (persistFile) {
|
|
25
|
-
try {
|
|
26
|
-
const raw = readFileSync(persistFile, "utf8").trim();
|
|
27
|
-
if (raw.length > 0) {
|
|
28
|
-
const parsed = JSON.parse(raw);
|
|
29
|
-
if (parsed.version !== 1 || !Array.isArray(parsed.assignments)) {
|
|
30
|
-
throw new Error("invalid persisted background assignment ledger");
|
|
31
|
-
}
|
|
32
|
-
for (const assignment of parsed.assignments) {
|
|
33
|
-
if (!isDurableBackgroundAssignment(assignment)) {
|
|
34
|
-
throw new Error("invalid persisted background assignment ledger record");
|
|
35
|
-
}
|
|
36
|
-
bySourceMessageId.set(assignment.sourceMessageId, assignment);
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
catch (err) {
|
|
41
|
-
if (!isNodeErr(err, "ENOENT"))
|
|
42
|
-
throw err;
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
return {
|
|
46
|
-
get(sourceMessageId) {
|
|
47
|
-
return bySourceMessageId.get(sourceMessageId);
|
|
48
|
-
},
|
|
49
|
-
upsert(record) {
|
|
50
|
-
const prior = bySourceMessageId.get(record.sourceMessageId);
|
|
51
|
-
bySourceMessageId.set(record.sourceMessageId, record);
|
|
52
|
-
try {
|
|
53
|
-
persist();
|
|
54
|
-
return true;
|
|
55
|
-
}
|
|
56
|
-
catch {
|
|
57
|
-
if (prior)
|
|
58
|
-
bySourceMessageId.set(record.sourceMessageId, prior);
|
|
59
|
-
else
|
|
60
|
-
bySourceMessageId.delete(record.sourceMessageId);
|
|
61
|
-
return false;
|
|
62
|
-
}
|
|
63
|
-
},
|
|
64
|
-
delete(sourceMessageId) {
|
|
65
|
-
const prior = bySourceMessageId.get(sourceMessageId);
|
|
66
|
-
if (!prior)
|
|
67
|
-
return true;
|
|
68
|
-
bySourceMessageId.delete(sourceMessageId);
|
|
69
|
-
try {
|
|
70
|
-
persist();
|
|
71
|
-
return true;
|
|
72
|
-
}
|
|
73
|
-
catch {
|
|
74
|
-
bySourceMessageId.set(sourceMessageId, prior);
|
|
75
|
-
return false;
|
|
76
|
-
}
|
|
77
|
-
},
|
|
78
|
-
list() {
|
|
79
|
-
return snapshot();
|
|
80
|
-
},
|
|
81
|
-
};
|
|
82
|
-
}
|
|
83
|
-
function isDurableBackgroundAssignment(value) {
|
|
84
|
-
if (!value || typeof value !== "object")
|
|
85
|
-
return false;
|
|
86
|
-
const record = value;
|
|
87
|
-
return ((record.kind === "mailbox_dispatch" || record.kind === "broker_route") &&
|
|
88
|
-
(record.state === "assigned" ||
|
|
89
|
-
record.state === "committing" ||
|
|
90
|
-
record.state === "committed") &&
|
|
91
|
-
typeof record.assignmentId === "string" &&
|
|
92
|
-
typeof record.sourceMessageId === "string" &&
|
|
93
|
-
typeof record.endpointId === "string" &&
|
|
94
|
-
typeof record.assignedAt === "number" &&
|
|
95
|
-
isUndispatchedMessageShape(record.message) &&
|
|
96
|
-
(record.acceptedAt === undefined ||
|
|
97
|
-
typeof record.acceptedAt === "number") &&
|
|
98
|
-
(record.committedAt === undefined ||
|
|
99
|
-
typeof record.committedAt === "number") &&
|
|
100
|
-
(record.deliverySeq === undefined ||
|
|
101
|
-
typeof record.deliverySeq === "number") &&
|
|
102
|
-
(record.routeKind === undefined ||
|
|
103
|
-
record.routeKind === "active_endpoint" ||
|
|
104
|
-
record.routeKind === "reconnecting_endpoint"));
|
|
105
|
-
}
|
|
106
|
-
function isUndispatchedMessageShape(value) {
|
|
107
|
-
if (!value || typeof value !== "object")
|
|
108
|
-
return false;
|
|
109
|
-
const record = value;
|
|
110
|
-
return (typeof record.id === "string" &&
|
|
111
|
-
typeof record.arrived_at === "string" &&
|
|
112
|
-
typeof record.sender_address === "string" &&
|
|
113
|
-
typeof record.content === "string" &&
|
|
114
|
-
typeof record.content_type === "string" &&
|
|
115
|
-
!!record.metadata &&
|
|
116
|
-
typeof record.metadata === "object" &&
|
|
117
|
-
(record.reason === "unaddressed" ||
|
|
118
|
-
record.reason === "closed_session_continuation"));
|
|
119
|
-
}
|
|
120
|
-
function isNodeErr(err, code) {
|
|
121
|
-
return (typeof err === "object" &&
|
|
122
|
-
err !== null &&
|
|
123
|
-
"code" in err &&
|
|
124
|
-
err.code === code);
|
|
125
|
-
}
|