@moltzap/client 2026.922.3 → 2026.1001.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/README.md +23 -7
- package/dist/client-runtime.d.ts.map +1 -1
- package/dist/client-runtime.js +28 -11
- package/dist/client-runtime.js.map +1 -1
- package/dist/contract.d.ts +440 -57
- package/dist/contract.d.ts.map +1 -1
- package/dist/contract.js +256 -18
- package/dist/contract.js.map +1 -1
- package/dist/contract.types-check.d.ts +109 -13
- package/dist/contract.types-check.d.ts.map +1 -1
- package/dist/contract.types-check.js +11 -3
- package/dist/contract.types-check.js.map +1 -1
- package/dist/daemon/configuration.d.ts +18 -6
- package/dist/daemon/configuration.d.ts.map +1 -1
- package/dist/daemon/configuration.js +15 -9
- package/dist/daemon/configuration.js.map +1 -1
- package/dist/daemon/management.d.ts.map +1 -1
- package/dist/daemon/management.js +2 -0
- package/dist/daemon/management.js.map +1 -1
- package/dist/daemon/registration.d.ts +18 -3
- package/dist/daemon/registration.d.ts.map +1 -1
- package/dist/daemon/registration.js +17 -2
- package/dist/daemon/registration.js.map +1 -1
- package/dist/daemon/runtime/activation.d.ts +1 -1
- package/dist/daemon/runtime/activation.d.ts.map +1 -1
- package/dist/daemon/runtime/controller.d.ts +1 -1
- package/dist/daemon/runtime/controller.d.ts.map +1 -1
- package/dist/daemon/runtime/controller.js +44 -10
- package/dist/daemon/runtime/controller.js.map +1 -1
- package/dist/daemon/runtime/history-export.d.ts +11 -1
- package/dist/daemon/runtime/history-export.d.ts.map +1 -1
- package/dist/daemon/runtime/history-export.js +4 -0
- package/dist/daemon/runtime/history-export.js.map +1 -1
- package/dist/daemon/runtime/index.d.ts.map +1 -1
- package/dist/daemon/runtime/index.js +1 -2
- package/dist/daemon/runtime/index.js.map +1 -1
- package/dist/daemon/runtime/pending-delivery.d.ts +49 -0
- package/dist/daemon/runtime/pending-delivery.d.ts.map +1 -0
- package/dist/daemon/runtime/pending-delivery.js +115 -0
- package/dist/daemon/runtime/pending-delivery.js.map +1 -0
- package/dist/daemon/runtime/protocol.d.ts +20 -5
- package/dist/daemon/runtime/protocol.d.ts.map +1 -1
- package/dist/daemon/runtime/protocol.js +58 -24
- package/dist/daemon/runtime/protocol.js.map +1 -1
- package/dist/endpoint/addressing/index.d.ts +22 -1
- package/dist/endpoint/addressing/index.d.ts.map +1 -1
- package/dist/endpoint/addressing/index.js +50 -26
- package/dist/endpoint/addressing/index.js.map +1 -1
- package/dist/endpoint/collective/operation.d.ts +123 -0
- package/dist/endpoint/collective/operation.d.ts.map +1 -0
- package/dist/endpoint/collective/operation.js +784 -0
- package/dist/endpoint/collective/operation.js.map +1 -0
- package/dist/endpoint/collective/shared-answers.d.ts +78 -0
- package/dist/endpoint/collective/shared-answers.d.ts.map +1 -0
- package/dist/endpoint/collective/shared-answers.js +62 -0
- package/dist/endpoint/collective/shared-answers.js.map +1 -0
- package/dist/endpoint/collective/validation.d.ts +49 -0
- package/dist/endpoint/collective/validation.d.ts.map +1 -0
- package/dist/endpoint/collective/validation.js +99 -0
- package/dist/endpoint/collective/validation.js.map +1 -0
- package/dist/endpoint/collective/wire.d.ts +176 -0
- package/dist/endpoint/collective/wire.d.ts.map +1 -0
- package/dist/endpoint/collective/wire.js +181 -0
- package/dist/endpoint/collective/wire.js.map +1 -0
- package/dist/endpoint/engine-durability.d.ts +3 -17
- package/dist/endpoint/engine-durability.d.ts.map +1 -1
- package/dist/endpoint/engine-durability.js +3 -14
- package/dist/endpoint/engine-durability.js.map +1 -1
- package/dist/endpoint/engine-send.d.ts +14 -16
- package/dist/endpoint/engine-send.d.ts.map +1 -1
- package/dist/endpoint/engine-send.js +16 -20
- package/dist/endpoint/engine-send.js.map +1 -1
- package/dist/endpoint/engine-types.d.ts +32 -15
- package/dist/endpoint/engine-types.d.ts.map +1 -1
- package/dist/endpoint/engine-types.js +1 -5
- package/dist/endpoint/engine-types.js.map +1 -1
- package/dist/endpoint/engine.d.ts +1 -1
- package/dist/endpoint/engine.d.ts.map +1 -1
- package/dist/endpoint/engine.js +44 -27
- package/dist/endpoint/engine.js.map +1 -1
- package/dist/endpoint/protocol/index.d.ts.map +1 -1
- package/dist/endpoint/protocol/index.js +5 -8
- package/dist/endpoint/protocol/index.js.map +1 -1
- package/dist/endpoint/recovery/index.d.ts +5 -0
- package/dist/endpoint/recovery/index.d.ts.map +1 -1
- package/dist/endpoint/recovery/index.js +40 -39
- package/dist/endpoint/recovery/index.js.map +1 -1
- package/dist/endpoint/recovery/reanchor/empty.js +1 -1
- package/dist/endpoint/recovery/reanchor/empty.js.map +1 -1
- package/dist/endpoint/recovery/reanchor/index.js +26 -5
- package/dist/endpoint/recovery/reanchor/index.js.map +1 -1
- package/dist/endpoint/recovery/state.d.ts +7 -1
- package/dist/endpoint/recovery/state.d.ts.map +1 -1
- package/dist/endpoint/recovery/state.js +3 -1
- package/dist/endpoint/recovery/state.js.map +1 -1
- package/dist/endpoint/recovery/store.d.ts +9 -2
- package/dist/endpoint/recovery/store.d.ts.map +1 -1
- package/dist/endpoint/recovery/store.js +27 -5
- package/dist/endpoint/recovery/store.js.map +1 -1
- package/dist/endpoint/representation-schemas.d.ts +2 -0
- package/dist/endpoint/representation-schemas.d.ts.map +1 -1
- package/dist/endpoint/representation-schemas.js +2 -2
- package/dist/endpoint/representation-schemas.js.map +1 -1
- package/dist/endpoint/representation.d.ts +1 -1
- package/dist/endpoint/representation.d.ts.map +1 -1
- package/dist/endpoint/representation.js +1 -1
- package/dist/endpoint/representation.js.map +1 -1
- package/dist/harness-mcp-contract.d.ts +189 -57
- package/dist/harness-mcp-contract.d.ts.map +1 -1
- package/dist/harness-mcp-contract.js +61 -9
- package/dist/harness-mcp-contract.js.map +1 -1
- package/dist/harness-mcp-wire.d.ts +3 -3
- package/dist/harness-mcp-wire.d.ts.map +1 -1
- package/dist/harness-mcp-wire.js +38 -28
- package/dist/harness-mcp-wire.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/dist/server.d.ts +2 -0
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +18 -0
- package/dist/server.js.map +1 -1
- package/package.json +3 -3
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"history-export.js","sourceRoot":"","sources":["../../../src/daemon/runtime/history-export.ts"],"names":[],"mappings":"AAAA,sEAAsE;AAEtE,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;
|
|
1
|
+
{"version":3,"file":"history-export.js","sourceRoot":"","sources":["../../../src/daemon/runtime/history-export.ts"],"names":[],"mappings":"AAAA,sEAAsE;AAEtE,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAClD,OAAO,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AAExD,kNAAkN;AAElN,MAAM,UAAU,GAAG,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,SAAS,CAAC,mBAAmB,CAAC,CAAC,CAAC;AAWxE,6EAA6E;AAC7E,MAAM,CAAC,MAAM,eAAe,GAAsB,MAAM,CAAC,MAAM,CAAC;IAC9D,MAAM,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,IAAI;CAC1B,CAAC,CAAC;AAEH;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,UAAU,iBAAiB,CAC/B,IAAY;IAEZ,OAAO,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC;QACzB,MAAM,UAAU,GAAG,KAAK,CAAC,CAAC,UAAU,CAAC,UAAU,CAAC;QAChD,MAAM,IAAI,GAAG,KAAK,CAAC,CAAC,MAAM,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC;QAC5C,IAAI,OAAO,GAAG,IAA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":"","sources":["../../../src/daemon/runtime/index.ts"],"names":[],"mappings":"AAAA,8EAA8E;AAG9E,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,4BAA4B,CAAC;AAC3D,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAE9C,OAAO,EAAE,MAAM,EAAE,KAAK,KAAK,EAAE,MAAM,QAAQ,CAAC;AAC5C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAC7D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/daemon/runtime/index.ts"],"names":[],"mappings":"AAAA,8EAA8E;AAG9E,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,4BAA4B,CAAC;AAC3D,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAE9C,OAAO,EAAE,MAAM,EAAE,KAAK,KAAK,EAAE,MAAM,QAAQ,CAAC;AAC5C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAC7D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAM3D,OAAO,EACL,KAAK,yBAAyB,EAC9B,kBAAkB,EAEnB,MAAM,iBAAiB,CAAC;AAuBzB,qDAAqD;AACrD,OAAO,EAAE,kBAAkB,EAAE,CAAC;AAC9B,iEAAiE;AACjE,YAAY,EAAE,yBAAyB,EAAE,CAAC;AAE1C;;;;;;;GAOG;AACH,eAAO,MAAM,gBAAgB,UACpB;IACL,QAAQ,CAAC,KAAK,EAAE,aAAa,CAAC;IAC9B,QAAQ,CAAC,SAAS,EAAE,eAAe,CAAC;CACrC,iBACa,yBAAyB,KACtC,MAAM,CAAC,MAAM,CAAC,KAAK,EAAE,kBAAkB,EAAE,QAAQ,GAAG,MAAM,GAAG,KAAK,CAAC,KAAK,CA+B7B,CAAC"}
|
|
@@ -2,14 +2,13 @@
|
|
|
2
2
|
import { NodeFileSystem } from "@effect/platform-node";
|
|
3
3
|
import { Effect } from "effect";
|
|
4
4
|
import packageJson from "../../../package.json" with { type: "json" };
|
|
5
|
-
import { noHistoryExport } from "../../endpoint/engine-types.js";
|
|
6
5
|
import { makeEndpointEngine } from "../../endpoint/engine.js";
|
|
7
6
|
import { makeRouterWorker } from "../../endpoint/router-worker/index.js";
|
|
8
7
|
import { acquireHarnessMcpHttpServer } from "../../harness-mcp-http.js";
|
|
9
8
|
import { makeHarnessMcpHttpHandler } from "../../harness-mcp-wire.js";
|
|
10
9
|
import { DaemonRuntimeError, prepareDaemonActivation, } from "./activation.js";
|
|
11
10
|
import { makeDaemonController } from "./controller.js";
|
|
12
|
-
import { makeHistoryExport } from "./history-export.js";
|
|
11
|
+
import { makeHistoryExport, noHistoryExport } from "./history-export.js";
|
|
13
12
|
const DAEMON_IMPLEMENTATION = {
|
|
14
13
|
name: "moltzapd",
|
|
15
14
|
version: packageJson.version,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/daemon/runtime/index.ts"],"names":[],"mappings":"AAAA,8EAA8E;AAK9E,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAE,MAAM,EAAc,MAAM,QAAQ,CAAC;AAG5C,OAAO,WAAW,MAAM,uBAAuB,CAAC,OAAO,IAAI,EAAE,MAAM,EAAE,CAAC;AACtE,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/daemon/runtime/index.ts"],"names":[],"mappings":"AAAA,8EAA8E;AAK9E,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAE,MAAM,EAAc,MAAM,QAAQ,CAAC;AAG5C,OAAO,WAAW,MAAM,uBAAuB,CAAC,OAAO,IAAI,EAAE,MAAM,EAAE,CAAC;AACtE,OAAO,EAAE,kBAAkB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C,CAAC,CAAC;IAC3D,OAAO,KAAK,CAAC,CAAC,UAAU,CAAC,YAAY,CAAC;AACxC,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,kBAAkB,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file One pass over pending deliveries: the collective layer classifies
|
|
3
|
+
* each durable delivery, consumed ones are acknowledged, and the remaining
|
|
4
|
+
* items and the layer's own are published in order while a subscriber takes
|
|
5
|
+
* them.
|
|
6
|
+
*/
|
|
7
|
+
import { Effect } from "effect";
|
|
8
|
+
import type { InboundItem } from "../../contract.js";
|
|
9
|
+
import type { CollectiveOperations } from "../../endpoint/collective/operation.js";
|
|
10
|
+
import type { EndpointEngine, EnginePendingMessage } from "../../endpoint/engine.js";
|
|
11
|
+
import type { HarnessMessageReadyEvent } from "../../harness-mcp-contract.js";
|
|
12
|
+
import type { HistoryExportPort } from "./history-export.js";
|
|
13
|
+
import { DeliveryToken } from "../../endpoint/store.js";
|
|
14
|
+
/** The subscriber's publish edge; false means it refused the event. */
|
|
15
|
+
interface Subscriber {
|
|
16
|
+
readonly publish: (event: HarnessMessageReadyEvent) => boolean;
|
|
17
|
+
}
|
|
18
|
+
/** What one pass over pending deliveries reads and changes. */
|
|
19
|
+
export interface PendingOffer {
|
|
20
|
+
readonly engine: Pick<EndpointEngine, "acknowledgeMessage">;
|
|
21
|
+
readonly classify: CollectiveOperations["classify"];
|
|
22
|
+
/** The attached subscriber, absent while none is attached. */
|
|
23
|
+
readonly handler?: Subscriber;
|
|
24
|
+
readonly historyExport: HistoryExportPort;
|
|
25
|
+
readonly publishedDeliveries: Set<string>;
|
|
26
|
+
readonly exportedDeliveries: Set<string>;
|
|
27
|
+
/**
|
|
28
|
+
* The item each unacknowledged durable delivery classified into, so a
|
|
29
|
+
* delivery is decoded and classified once rather than on every pass.
|
|
30
|
+
*/
|
|
31
|
+
readonly classifiedItems: Map<string, InboundItem>;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Offer pending deliveries in order, then the collective layer's own items.
|
|
35
|
+
* Every durable delivery is classified: the layer consumes protocol posts,
|
|
36
|
+
* which are acknowledged here whether or not a subscriber is attached, so
|
|
37
|
+
* answers are recorded and deadlines complete with nobody listening. Items
|
|
38
|
+
* are published while a subscriber accepts them; after the first refusal,
|
|
39
|
+
* or with no subscriber, they stay pending for a later pass.
|
|
40
|
+
* @param offer The engine, classifier, subscriber and delivery bookkeeping.
|
|
41
|
+
* @param messages Pending durable deliveries in order.
|
|
42
|
+
* @param localItems Items the collective layer emitted, in order.
|
|
43
|
+
* @returns Completion after every delivery is consumed or offered.
|
|
44
|
+
*/
|
|
45
|
+
export declare const offerPendingMessages: (offer: PendingOffer, messages: readonly EnginePendingMessage[], localItems: ReadonlyMap<DeliveryToken, InboundItem>) => Effect.Effect<void>;
|
|
46
|
+
/** A delivery token for an item the collective layer emitted, held in memory. */
|
|
47
|
+
export declare const mintLocalDeliveryToken: Effect.Effect<string & import("effect/Brand").Brand<"DeliveryToken">, never, never>;
|
|
48
|
+
export {};
|
|
49
|
+
//# sourceMappingURL=pending-delivery.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pending-delivery.d.ts","sourceRoot":"","sources":["../../../src/daemon/runtime/pending-delivery.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAY,MAAM,EAAkB,MAAM,QAAQ,CAAC;AAE1D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AACrD,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,wCAAwC,CAAC;AACnF,OAAO,KAAK,EACV,cAAc,EACd,oBAAoB,EACrB,MAAM,0BAA0B,CAAC;AAClC,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,+BAA+B,CAAC;AAC9E,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAC7D,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAExD,uEAAuE;AACvE,UAAU,UAAU;IAClB,QAAQ,CAAC,OAAO,EAAE,CAAC,KAAK,EAAE,wBAAwB,KAAK,OAAO,CAAC;CAChE;AAED,+DAA+D;AAC/D,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,MAAM,EAAE,IAAI,CAAC,cAAc,EAAE,oBAAoB,CAAC,CAAC;IAC5D,QAAQ,CAAC,QAAQ,EAAE,oBAAoB,CAAC,UAAU,CAAC,CAAC;IACpD,8DAA8D;IAC9D,QAAQ,CAAC,OAAO,CAAC,EAAE,UAAU,CAAC;IAC9B,QAAQ,CAAC,aAAa,EAAE,iBAAiB,CAAC;IAC1C,QAAQ,CAAC,mBAAmB,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;IAC1C,QAAQ,CAAC,kBAAkB,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;IACzC;;;OAGG;IACH,QAAQ,CAAC,eAAe,EAAE,GAAG,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC;CACpD;AAmHD;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,oBAAoB,UACxB,YAAY,YACT,SAAS,oBAAoB,EAAE,cAC7B,WAAW,CAAC,aAAa,EAAE,WAAW,CAAC,KAClD,MAAM,CAAC,MAAM,CAAC,IAAI,CAkB6B,CAAC;AAEnD,iFAAiF;AACjF,eAAO,MAAM,sBAAsB,qFAIlC,CAAC"}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file One pass over pending deliveries: the collective layer classifies
|
|
3
|
+
* each durable delivery, consumed ones are acknowledged, and the remaining
|
|
4
|
+
* items and the layer's own are published in order while a subscriber takes
|
|
5
|
+
* them.
|
|
6
|
+
*/
|
|
7
|
+
import { DateTime, Effect, Option, Schema } from "effect";
|
|
8
|
+
import { randomBytes } from "node:crypto";
|
|
9
|
+
import { DeliveryToken } from "../../endpoint/store.js";
|
|
10
|
+
/**
|
|
11
|
+
* Acknowledge a delivery the collective layer consumed. A failed
|
|
12
|
+
* acknowledgment is logged and the delivery stays pending: the next pass
|
|
13
|
+
* classifies it again, which records nothing twice because the requester
|
|
14
|
+
* and every all_gather member keep only a member's first answer and a member
|
|
15
|
+
* applies a close once, and acknowledges it again. It does
|
|
16
|
+
* not end the daemon, whose store failures surface through the pending read
|
|
17
|
+
* that starts every pass.
|
|
18
|
+
*/
|
|
19
|
+
const acknowledgeConsumed = (offer, pending) => offer.engine
|
|
20
|
+
.acknowledgeMessage(pending.deliveryToken)
|
|
21
|
+
.pipe(Effect.catchAll((error) => Effect.logWarning(`consumed delivery stays pending: ${error.message}`)));
|
|
22
|
+
/**
|
|
23
|
+
* Record an item in the history export the first time it is offered, then
|
|
24
|
+
* offer it to the subscriber, yielding whether the subscriber took it. The
|
|
25
|
+
* line lands before the item is visible, for the reason `makeHistoryExport`
|
|
26
|
+
* gives.
|
|
27
|
+
*
|
|
28
|
+
* The append runs inside the pass, under the delivery gate. It cannot
|
|
29
|
+
* deadlock: the export's own gate is taken only inside `record`, which takes
|
|
30
|
+
* no other lock, and a send records its outbound line without the delivery
|
|
31
|
+
* gate. Its cost is one append per item on first offer, only when an operator
|
|
32
|
+
* configured the export, and an acknowledgment waits for the pass that holds
|
|
33
|
+
* the gate.
|
|
34
|
+
*/
|
|
35
|
+
const publishItem = (offer, handler, event) => Effect.gen(function* () {
|
|
36
|
+
if (!offer.exportedDeliveries.has(event.deliveryToken)) {
|
|
37
|
+
const at = yield* DateTime.now;
|
|
38
|
+
yield* offer.historyExport.record({
|
|
39
|
+
kind: "inbound",
|
|
40
|
+
item: event.item,
|
|
41
|
+
at,
|
|
42
|
+
});
|
|
43
|
+
offer.exportedDeliveries.add(event.deliveryToken);
|
|
44
|
+
}
|
|
45
|
+
if (!handler.publish(event)) {
|
|
46
|
+
return false;
|
|
47
|
+
}
|
|
48
|
+
offer.publishedDeliveries.add(event.deliveryToken);
|
|
49
|
+
return true;
|
|
50
|
+
});
|
|
51
|
+
const classifyOnce = (offer, pending) => offer.classify(pending).pipe(Effect.flatMap(Option.match({
|
|
52
|
+
onNone: () => acknowledgeConsumed(offer, pending).pipe(Effect.as(Option.none())),
|
|
53
|
+
onSome: (item) => Effect.sync(() => {
|
|
54
|
+
offer.classifiedItems.set(pending.deliveryToken, item);
|
|
55
|
+
return Option.some({
|
|
56
|
+
deliveryToken: pending.deliveryToken,
|
|
57
|
+
item,
|
|
58
|
+
});
|
|
59
|
+
}),
|
|
60
|
+
})));
|
|
61
|
+
/**
|
|
62
|
+
* Classify one durable delivery not yet published: acknowledge it when the
|
|
63
|
+
* collective layer consumes it, otherwise return its event, reusing the item
|
|
64
|
+
* an earlier pass classified.
|
|
65
|
+
*/
|
|
66
|
+
const classifyPending = (offer, pending) => {
|
|
67
|
+
const { deliveryToken } = pending;
|
|
68
|
+
if (offer.publishedDeliveries.has(deliveryToken)) {
|
|
69
|
+
return Effect.succeed(Option.none());
|
|
70
|
+
}
|
|
71
|
+
const classified = offer.classifiedItems.get(deliveryToken);
|
|
72
|
+
return classified === undefined
|
|
73
|
+
? classifyOnce(offer, pending)
|
|
74
|
+
: Effect.succeed(Option.some({ deliveryToken, item: classified }));
|
|
75
|
+
};
|
|
76
|
+
/** Publish events in order, skipping published ones, until one is refused. */
|
|
77
|
+
const publishInOrder = (offer, handler, events) => Effect.gen(function* () {
|
|
78
|
+
for (const event of events) {
|
|
79
|
+
if (offer.publishedDeliveries.has(event.deliveryToken)) {
|
|
80
|
+
continue;
|
|
81
|
+
}
|
|
82
|
+
if (!(yield* publishItem(offer, handler, event))) {
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
/**
|
|
88
|
+
* Offer pending deliveries in order, then the collective layer's own items.
|
|
89
|
+
* Every durable delivery is classified: the layer consumes protocol posts,
|
|
90
|
+
* which are acknowledged here whether or not a subscriber is attached, so
|
|
91
|
+
* answers are recorded and deadlines complete with nobody listening. Items
|
|
92
|
+
* are published while a subscriber accepts them; after the first refusal,
|
|
93
|
+
* or with no subscriber, they stay pending for a later pass.
|
|
94
|
+
* @param offer The engine, classifier, subscriber and delivery bookkeeping.
|
|
95
|
+
* @param messages Pending durable deliveries in order.
|
|
96
|
+
* @param localItems Items the collective layer emitted, in order.
|
|
97
|
+
* @returns Completion after every delivery is consumed or offered.
|
|
98
|
+
*/
|
|
99
|
+
export const offerPendingMessages = (offer, messages, localItems) => Effect.gen(function* () {
|
|
100
|
+
const classified = yield* Effect.forEach(messages, (pending) => classifyPending(offer, pending), { concurrency: 1 });
|
|
101
|
+
const handler = offer.handler;
|
|
102
|
+
if (handler === undefined) {
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
yield* publishInOrder(offer, handler, [
|
|
106
|
+
...classified.flatMap((event) => Option.toArray(event)),
|
|
107
|
+
...[...localItems].map(([deliveryToken, item]) => ({
|
|
108
|
+
deliveryToken,
|
|
109
|
+
item,
|
|
110
|
+
})),
|
|
111
|
+
]);
|
|
112
|
+
}).pipe(Effect.withSpan("offerPendingMessages"));
|
|
113
|
+
/** A delivery token for an item the collective layer emitted, held in memory. */
|
|
114
|
+
export const mintLocalDeliveryToken = Effect.sync(() => Schema.decodeUnknownSync(DeliveryToken)(`dlv_${randomBytes(32).toString("base64url")}`));
|
|
115
|
+
//# sourceMappingURL=pending-delivery.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pending-delivery.js","sourceRoot":"","sources":["../../../src/daemon/runtime/pending-delivery.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAC1D,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAS1C,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAuBxD;;;;;;;;GAQG;AACH,MAAM,mBAA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E,CACrD,MAAM,CAAC,iBAAiB,CAAC,aAAa,CAAC,CACrC,OAAO,WAAW,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,WAAW,CAAC,EAAE,CAC/C,CACF,CAAC"}
|
|
@@ -3,19 +3,22 @@ import type { VerifiedAgentCard } from "@moltzap/identity";
|
|
|
3
3
|
import { Registry } from "@moltzap/identity/registry";
|
|
4
4
|
import { Router } from "@moltzap/router";
|
|
5
5
|
import { Cause, type Context, Deferred, Effect, Scope } from "effect";
|
|
6
|
-
import type { HistoryExportPort } from "../../endpoint/engine-types.js";
|
|
7
6
|
import type { EndpointEngine } from "../../endpoint/engine.js";
|
|
8
|
-
import type { EndpointStore } from "../../endpoint/store.js";
|
|
7
|
+
import type { DeliveryToken, EndpointStore } from "../../endpoint/store.js";
|
|
9
8
|
import type { DaemonBootstrap } from "../configuration.js";
|
|
9
|
+
import type { HistoryExportPort } from "./history-export.js";
|
|
10
|
+
import { type InboundItem } from "../../contract.js";
|
|
11
|
+
import { type CollectiveOperations } from "../../endpoint/collective/operation.js";
|
|
10
12
|
import { type RouterWorker } from "../../endpoint/router-worker/index.js";
|
|
11
13
|
import { DaemonActivationError, type DaemonRuntimeDependencies, DaemonRuntimeError } from "./activation.js";
|
|
12
14
|
/** Subscription publisher installed after the MCP handler is acquired. */
|
|
13
15
|
export type RuntimeSubscriptionHandler = Effect.Effect.Success<ReturnType<DaemonRuntimeDependencies["makeHandler"]>>;
|
|
14
|
-
/** Engine
|
|
16
|
+
/** Engine, Router worker and collective layer active for the daemon's identity. */
|
|
15
17
|
interface ActiveProtocol {
|
|
16
18
|
readonly agentCard: VerifiedAgentCard;
|
|
17
19
|
readonly worker: RouterWorker;
|
|
18
20
|
readonly engine: EndpointEngine;
|
|
21
|
+
readonly collectives: CollectiveOperations;
|
|
19
22
|
}
|
|
20
23
|
/** Mutable controller state shared with supervised protocol resources. */
|
|
21
24
|
export interface ProtocolState {
|
|
@@ -23,6 +26,16 @@ export interface ProtocolState {
|
|
|
23
26
|
subscriptionActive: boolean;
|
|
24
27
|
handler?: RuntimeSubscriptionHandler;
|
|
25
28
|
readonly publishedDeliveries: Set<string>;
|
|
29
|
+
/**
|
|
30
|
+
* Items the collective layer emitted, in emission order, each under a
|
|
31
|
+
* daemon-minted delivery token until the subscriber acknowledges it. They
|
|
32
|
+
* live in memory like the gather state they come from.
|
|
33
|
+
*/
|
|
34
|
+
readonly localItems: Map<DeliveryToken, InboundItem>;
|
|
35
|
+
/** Deliveries whose item the history export already recorded. */
|
|
36
|
+
readonly exportedDeliveries: Set<string>;
|
|
37
|
+
/** The item each unacknowledged durable delivery classified into. */
|
|
38
|
+
readonly classifiedItems: Map<string, InboundItem>;
|
|
26
39
|
}
|
|
27
40
|
/** Dependencies and owned resources available to one protocol lifecycle. */
|
|
28
41
|
export interface ProtocolEnvironment {
|
|
@@ -37,10 +50,12 @@ export interface ProtocolEnvironment {
|
|
|
37
50
|
readonly state: ProtocolState;
|
|
38
51
|
}
|
|
39
52
|
/**
|
|
40
|
-
*
|
|
53
|
+
* Classify newly durable deliveries and publish what a subscriber can take.
|
|
54
|
+
* The pass runs with or without a subscriber, so the collective layer
|
|
55
|
+
* consumes protocol posts even while no host is attached.
|
|
41
56
|
* @param environment Protocol resources and controller-owned delivery state.
|
|
42
57
|
* @param deliveryGate Serializes pending reads with subscription changes.
|
|
43
|
-
* @returns Completion after every
|
|
58
|
+
* @returns Completion after every current delivery is consumed or offered.
|
|
44
59
|
*/
|
|
45
60
|
export declare const publishPendingMessages: (environment: ProtocolEnvironment, deliveryGate: Effect.Semaphore) => Effect.Effect<void>;
|
|
46
61
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"protocol.d.ts","sourceRoot":"","sources":["../../../src/daemon/runtime/protocol.ts"],"names":[],"mappings":"AAAA,oFAAoF;AAEpF,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAC3D,OAAO,EAAE,QAAQ,EAAE,MAA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;;;;;GAOG;AACH,eAAO,MAAM,sBAAsB,gBACpB,mBAAmB,gBAClB,MAAM,CAAC,SAAS,KAC7B,MAAM,CAAC,MAAM,CAAC,IAAI,CAsBlB,CAAC;AAsBJ;;;;;GAKG;AACH,eAAO,MAAM,uBAAuB,GAAI,CAAC,SAChC,QAAQ,CAAC,QAAQ,CAAC,KAAK,EAAE,kBAAkB,CAAC,SAC5C,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,KACpB,MAAM,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,CAOxB,CAAC;AAgJF;;;;;;;GAOG;AACH,eAAO,MAAM,kBAAkB,gBAChB,mBAAmB,kBAChB,MAAM,CAAC,SAAS,cACpB,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,aACpB,iBAAiB,KAC3B,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,qBAAqB,CA2CI,CAAC"}
|
|
@@ -1,42 +1,58 @@
|
|
|
1
1
|
/** @file Protocol acquisition, supervision, and pending-delivery reconciliation. */
|
|
2
2
|
import { Registry } from "@moltzap/identity/registry";
|
|
3
3
|
import { Router } from "@moltzap/router";
|
|
4
|
-
import { Cause, Deferred, Effect, Scope } from "effect";
|
|
4
|
+
import { Cause, Deferred, Effect, Schema, Scope } from "effect";
|
|
5
|
+
import { AgentAddress } from "../../contract.js";
|
|
6
|
+
import { makeCollectiveOperations, } from "../../endpoint/collective/operation.js";
|
|
5
7
|
import { decodeOuterBody } from "../../endpoint/representation.js";
|
|
6
8
|
import { RouterWorkerPayloadInvalidError, } from "../../endpoint/router-worker/index.js";
|
|
7
9
|
import { DaemonActivationError, DaemonRuntimeError, recoverPinnedSenderCards, } from "./activation.js";
|
|
10
|
+
import { mintLocalDeliveryToken, offerPendingMessages, } from "./pending-delivery.js";
|
|
8
11
|
const signStructurallyValidAction = () => Effect.succeed("sign");
|
|
9
12
|
const activationFailure = (reason) => new DaemonActivationError({ reason });
|
|
10
13
|
const runtimeFailure = (phase) => new DaemonRuntimeError({ phase });
|
|
11
14
|
const mapWorkerInitializationError = (error) => activationFailure(error._tag === "RouterWorkerTransportError" ? "upstream" : "representation");
|
|
12
15
|
/**
|
|
13
|
-
*
|
|
16
|
+
* What one pass reads and changes, from the active protocol and the
|
|
17
|
+
* controller's delivery state. Items are offered only to an attached
|
|
18
|
+
* subscriber.
|
|
19
|
+
*/
|
|
20
|
+
const pendingOffer = (environment, protocol) => {
|
|
21
|
+
const { state } = environment;
|
|
22
|
+
const handler = state.subscriptionActive ? state.handler : undefined;
|
|
23
|
+
return {
|
|
24
|
+
engine: protocol.engine,
|
|
25
|
+
classify: protocol.collectives.classify,
|
|
26
|
+
...(handler === undefined ? {} : { handler }),
|
|
27
|
+
historyExport: environment.historyExport,
|
|
28
|
+
publishedDeliveries: state.publishedDeliveries,
|
|
29
|
+
exportedDeliveries: state.exportedDeliveries,
|
|
30
|
+
classifiedItems: state.classifiedItems,
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* Classify newly durable deliveries and publish what a subscriber can take.
|
|
35
|
+
* The pass runs with or without a subscriber, so the collective layer
|
|
36
|
+
* consumes protocol posts even while no host is attached.
|
|
14
37
|
* @param environment Protocol resources and controller-owned delivery state.
|
|
15
38
|
* @param deliveryGate Serializes pending reads with subscription changes.
|
|
16
|
-
* @returns Completion after every
|
|
39
|
+
* @returns Completion after every current delivery is consumed or offered.
|
|
17
40
|
*/
|
|
18
41
|
export const publishPendingMessages = (environment, deliveryGate) => deliveryGate.withPermits(1)(Effect.suspend(() => {
|
|
19
42
|
const protocol = environment.state.activeProtocol;
|
|
20
|
-
if (
|
|
43
|
+
if (protocol === undefined) {
|
|
21
44
|
return Effect.void;
|
|
22
45
|
}
|
|
23
|
-
return protocol.engine.readPendingMessages().pipe(Effect.flatMap((messages) => Effect.
|
|
24
|
-
const handler = environment.state.handler;
|
|
25
|
-
if (handler === undefined) {
|
|
26
|
-
return;
|
|
27
|
-
}
|
|
28
|
-
for (const pending of messages) {
|
|
29
|
-
if (environment.state.publishedDeliveries.has(pending.deliveryToken)) {
|
|
30
|
-
continue;
|
|
31
|
-
}
|
|
32
|
-
const event = pending;
|
|
33
|
-
if (!handler.publish(event)) {
|
|
34
|
-
return;
|
|
35
|
-
}
|
|
36
|
-
environment.state.publishedDeliveries.add(pending.deliveryToken);
|
|
37
|
-
}
|
|
38
|
-
})), Effect.catchAll(() => Deferred.fail(environment.fatal, runtimeFailure("storage")).pipe(Effect.asVoid)));
|
|
46
|
+
return protocol.engine.readPendingMessages().pipe(Effect.flatMap((messages) => offerPendingMessages(pendingOffer(environment, protocol), messages, environment.state.localItems)), Effect.catchAll(() => Deferred.fail(environment.fatal, runtimeFailure("storage")).pipe(Effect.asVoid)));
|
|
39
47
|
}));
|
|
48
|
+
/**
|
|
49
|
+
* Queue an item the collective layer emitted and start a publication pass.
|
|
50
|
+
* The pass is forked because the layer can emit from inside one, which holds
|
|
51
|
+
* the delivery gate.
|
|
52
|
+
*/
|
|
53
|
+
const emitLocalItem = (environment, reconciler, item) => mintLocalDeliveryToken.pipe(Effect.tap((deliveryToken) => Effect.sync(() => {
|
|
54
|
+
environment.state.localItems.set(deliveryToken, item);
|
|
55
|
+
})), Effect.zipRight(Effect.forkIn(reconciler, environment.daemonScope)), Effect.asVoid);
|
|
40
56
|
/**
|
|
41
57
|
* Propagate interruption and convert other background failures to daemon failure.
|
|
42
58
|
* @param fatal Process-wide failure signal.
|
|
@@ -78,7 +94,6 @@ const acquireProtocolEngine = (environment, agentCard, worker) => environment.de
|
|
|
78
94
|
store: environment.store,
|
|
79
95
|
routerWorker: worker,
|
|
80
96
|
actionPolicy: signStructurallyValidAction,
|
|
81
|
-
historyExport: environment.historyExport,
|
|
82
97
|
})
|
|
83
98
|
.pipe(Scope.extend(environment.daemonScope), Effect.mapError(mapEngineInitializationError));
|
|
84
99
|
const checkExistingProtocol = (agentCard, activeProtocol) => {
|
|
@@ -91,8 +106,23 @@ const checkExistingProtocol = (agentCard, activeProtocol) => {
|
|
|
91
106
|
}
|
|
92
107
|
return Effect.succeed(true);
|
|
93
108
|
};
|
|
94
|
-
|
|
95
|
-
|
|
109
|
+
/**
|
|
110
|
+
* The collective layer for the active identity: it certifies posts through
|
|
111
|
+
* the engine and queues the items it emits for the next publication pass.
|
|
112
|
+
*/
|
|
113
|
+
const makeProtocolCollectives = (environment, reconciler, agentCard, engine) => makeCollectiveOperations({
|
|
114
|
+
self: Schema.decodeUnknownSync(AgentAddress)(`agent:${agentCard.agentName}`),
|
|
115
|
+
lookupMember: (member) => engine.resolveAddress(member),
|
|
116
|
+
sendPost: (input) => engine.send(input),
|
|
117
|
+
emit: (item) => emitLocalItem(environment, reconciler, item),
|
|
118
|
+
scope: environment.daemonScope,
|
|
119
|
+
});
|
|
120
|
+
/** Hold the active protocol with its collective layer for later operations. */
|
|
121
|
+
const retainActiveProtocol = (environment, reconciler, protocol) => {
|
|
122
|
+
environment.state.activeProtocol = {
|
|
123
|
+
...protocol,
|
|
124
|
+
collectives: makeProtocolCollectives(environment, reconciler, protocol.agentCard, protocol.engine),
|
|
125
|
+
};
|
|
96
126
|
};
|
|
97
127
|
/**
|
|
98
128
|
* Acquire and supervise the protocol resources for one immutable daemon identity.
|
|
@@ -123,7 +153,11 @@ export const initializeProtocol = (environment, activationGate, reconciler, agen
|
|
|
123
153
|
publishPending: reconciler,
|
|
124
154
|
});
|
|
125
155
|
const engine = yield* acquireProtocolEngine(environment, agentCard, worker);
|
|
126
|
-
retainActiveProtocol(environment
|
|
156
|
+
retainActiveProtocol(environment, reconciler, {
|
|
157
|
+
agentCard,
|
|
158
|
+
worker,
|
|
159
|
+
engine,
|
|
160
|
+
});
|
|
127
161
|
yield* Deferred.succeed(engineReady, engine);
|
|
128
162
|
yield* superviseBackground(environment, worker.run);
|
|
129
163
|
yield* superviseBackground(environment, engine.runOutbound);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"protocol.js","sourceRoot":"","sources":["../../../src/daemon/runtime/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C,CAAC;IAChD,MAAM,MAAM,GAAG,KAAK,CAAC,CAAC,qBAAqB,CAAC;QAC1C,WAAW;QACX,SAAS;QACT,iBAAiB;QACjB,WAAW;QACX,cAAc,EAAE,UAAU;KAC3B,CAAC,CAAC;IACH,MAAM,MAAM,GAAG,KAAK,CAAC,CAAC,qBAAqB,CACzC,WAAW,EACX,SAAS,EACT,MAAM,CACP,CAAC;IACF,oBAAoB,CAAC,WAAW,EAAE,UAAU,EAAE;QAC5C,SAAS;QACT,MAAM;QACN,MAAM;KACP,CAAC,CAAC;IACH,KAAK,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,WAAW,EAAE,MAAM,CAAC,CAAC;IAC7C,KAAK,CAAC,CAAC,mBAAmB,CAAC,WAAW,EAAE,MAAM,CAAC,GAAG,CAAC,CAAC;IACpD,KAAK,CAAC,CAAC,mBAAmB,CAAC,WAAW,EAAE,MAAM,CAAC,WAAW,CAAC,CAAC;IAC5D,KAAK,CAAC,CAAC,UAAU,CAAC,IAAI,CACpB,MAAM,CAAC,QAAQ,CAAC,GAAG,EAAE,CAAC,iBAAiB,CAAC,UAAU,CAAC,CAAC,CACrD,CAAC;AACJ,CAAC,CAAC,CACH;KACA,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,oBAAoB,CAAC,CAAC,CAAC"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/** @file Private address resolution from runtime names to immutable cards. */
|
|
2
2
|
import type { Registry } from "@moltzap/identity/registry";
|
|
3
|
-
import { type VerifiedAgentCard } from "@moltzap/identity";
|
|
3
|
+
import { AgentName, type VerifiedAgentCard } from "@moltzap/identity";
|
|
4
4
|
import { type Context, Effect } from "effect";
|
|
5
5
|
import { AgentAddress, GroupAddress, type MessageAddressInput, SendError } from "../../contract.js";
|
|
6
6
|
/** Minimal Registry capability required by address resolution. */
|
|
@@ -35,5 +35,26 @@ interface ResolveMessageAddressInput {
|
|
|
35
35
|
* @returns The canonical runtime address and AgentId-ordered verified cards.
|
|
36
36
|
*/
|
|
37
37
|
export declare function resolveMessageAddress(input: ResolveMessageAddressInput): Effect.Effect<ResolvedMessageAddress, SendError>;
|
|
38
|
+
/** A destination in canonical form, before any Registry lookup. */
|
|
39
|
+
export type CanonicalMessageAddress = {
|
|
40
|
+
readonly kind: "direct";
|
|
41
|
+
readonly address: AgentAddress;
|
|
42
|
+
readonly remoteName: AgentName;
|
|
43
|
+
} | {
|
|
44
|
+
readonly kind: "group";
|
|
45
|
+
readonly address: GroupAddress;
|
|
46
|
+
readonly memberNames: readonly AgentName[];
|
|
47
|
+
};
|
|
48
|
+
/**
|
|
49
|
+
* Put one destination in canonical form, the rule every send shares. An
|
|
50
|
+
* `agent:` address names one other agent. A `group:` address names each agent
|
|
51
|
+
* once; the local agent is added when absent, and the complete group has 3 to
|
|
52
|
+
* 32 members in unsigned ASCII name order.
|
|
53
|
+
* @param to The validated destination input.
|
|
54
|
+
* @param localAgentName The local agent's Registry name.
|
|
55
|
+
* @returns The canonical address with its names, local agent included for a
|
|
56
|
+
* group, or `invalid-address` or `membership-invalid`.
|
|
57
|
+
*/
|
|
58
|
+
export declare function canonicalMessageAddress(to: MessageAddressInput, localAgentName: string): Effect.Effect<CanonicalMessageAddress, SendError>;
|
|
38
59
|
export {};
|
|
39
60
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/endpoint/addressing/index.ts"],"names":[],"mappings":"AAAA,8EAA8E;AAE9E,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,4BAA4B,CAAC;AAC3D,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/endpoint/addressing/index.ts"],"names":[],"mappings":"AAAA,8EAA8E;AAE9E,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,4BAA4B,CAAC;AAC3D,OAAO,EAAE,SAAS,EAAE,KAAK,iBAAiB,EAAE,MAAM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IACxB,QAAQ,CAAC,OAAO,EAAE,YAAY,CAAC;IAC/B,QAAQ,CAAC,UAAU,EAAE,SAAS,CAAC;CAChC,GACD;IACE,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;IACvB,QAAQ,CAAC,OAAO,EAAE,YAAY,CAAC;IAC/B,QAAQ,CAAC,WAAW,EAAE,SAAS,SAAS,EAAE,CAAC;CAC5C,CAAC;AAEN;;;;;;;;;GASG;AACH,wBAAgB,uBAAuB,CACrC,EAAE,EAAE,mBAAmB,EACvB,cAAc,EAAE,MAAM,GACrB,MAAM,CAAC,MAAM,CAAC,uBAAuB,EAAE,SAAS,CAAC,CAInD"}
|
|
@@ -12,9 +12,24 @@ const MAXIMUM_GROUP_MEMBERS = 32;
|
|
|
12
12
|
* @returns The canonical runtime address and AgentId-ordered verified cards.
|
|
13
13
|
*/
|
|
14
14
|
export function resolveMessageAddress(input) {
|
|
15
|
-
return input.to.
|
|
16
|
-
? resolveDirect(input)
|
|
17
|
-
: resolveGroup(input);
|
|
15
|
+
return canonicalMessageAddress(input.to, input.localAgentCard.agentName).pipe(Effect.flatMap((canonical) => canonical.kind === "direct"
|
|
16
|
+
? resolveDirect(input, canonical)
|
|
17
|
+
: resolveGroup(input, canonical)));
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Put one destination in canonical form, the rule every send shares. An
|
|
21
|
+
* `agent:` address names one other agent. A `group:` address names each agent
|
|
22
|
+
* once; the local agent is added when absent, and the complete group has 3 to
|
|
23
|
+
* 32 members in unsigned ASCII name order.
|
|
24
|
+
* @param to The validated destination input.
|
|
25
|
+
* @param localAgentName The local agent's Registry name.
|
|
26
|
+
* @returns The canonical address with its names, local agent included for a
|
|
27
|
+
* group, or `invalid-address` or `membership-invalid`.
|
|
28
|
+
*/
|
|
29
|
+
export function canonicalMessageAddress(to, localAgentName) {
|
|
30
|
+
return to.startsWith(AGENT_ADDRESS_PREFIX)
|
|
31
|
+
? canonicalDirect(to, localAgentName)
|
|
32
|
+
: canonicalGroup(to, localAgentName);
|
|
18
33
|
}
|
|
19
34
|
function invalidAddress() {
|
|
20
35
|
return new SendError({ reason: "invalid-address" });
|
|
@@ -57,41 +72,53 @@ function lookupCard(registry, agentName) {
|
|
|
57
72
|
: Effect.fail(new SendError({ reason: "unknown-agent" }));
|
|
58
73
|
}));
|
|
59
74
|
}
|
|
60
|
-
function
|
|
75
|
+
function canonicalDirect(to, localAgentName) {
|
|
76
|
+
return Effect.gen(function* () {
|
|
77
|
+
const remoteName = yield* decodeAgentName(to.slice(AGENT_ADDRESS_PREFIX.length));
|
|
78
|
+
if (remoteName === localAgentName) {
|
|
79
|
+
return yield* invalidMembership();
|
|
80
|
+
}
|
|
81
|
+
const address = yield* Schema.decodeUnknown(AgentAddress)(to).pipe(Effect.mapError(invalidAddress));
|
|
82
|
+
return { kind: "direct", address, remoteName };
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
function canonicalGroup(to, localAgentName) {
|
|
61
86
|
return Effect.gen(function* () {
|
|
62
|
-
const
|
|
63
|
-
if (
|
|
87
|
+
const explicitNames = yield* Effect.forEach(to.slice(GROUP_ADDRESS_PREFIX.length).split(","), decodeAgentName, { concurrency: 1 });
|
|
88
|
+
if (new Set(explicitNames).size !== explicitNames.length) {
|
|
64
89
|
return yield* invalidMembership();
|
|
65
90
|
}
|
|
66
|
-
const
|
|
91
|
+
const localName = yield* decodeAgentName(localAgentName);
|
|
92
|
+
const memberNames = explicitNames.includes(localName)
|
|
93
|
+
? explicitNames.slice()
|
|
94
|
+
: [...explicitNames, localName];
|
|
95
|
+
if (memberNames.length < 3 || memberNames.length > MAXIMUM_GROUP_MEMBERS) {
|
|
96
|
+
return yield* invalidMembership();
|
|
97
|
+
}
|
|
98
|
+
memberNames.sort(compareAscii);
|
|
99
|
+
const address = yield* Schema.decodeUnknown(GroupAddress)(`${GROUP_ADDRESS_PREFIX}${memberNames.join(",")}`).pipe(Effect.mapError(invalidAddress));
|
|
100
|
+
return { kind: "group", address, memberNames };
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
function resolveDirect(input, canonical) {
|
|
104
|
+
return Effect.gen(function* () {
|
|
105
|
+
const remoteCard = yield* lookupCard(input.registry, canonical.remoteName);
|
|
67
106
|
const ordered = orderMemberCards([input.localAgentCard, remoteCard]);
|
|
68
107
|
const first = ordered[0];
|
|
69
108
|
const second = ordered[1];
|
|
70
109
|
if (first === undefined || second === undefined) {
|
|
71
110
|
return yield* Effect.dieMessage("direct membership lost a member");
|
|
72
111
|
}
|
|
73
|
-
const address = yield* Schema.decodeUnknown(AgentAddress)(input.to).pipe(Effect.mapError(invalidAddress));
|
|
74
112
|
return {
|
|
75
113
|
kind: "direct",
|
|
76
|
-
address,
|
|
114
|
+
address: canonical.address,
|
|
77
115
|
memberCards: [first, second],
|
|
78
116
|
};
|
|
79
117
|
});
|
|
80
118
|
}
|
|
81
|
-
function resolveGroup(input) {
|
|
119
|
+
function resolveGroup(input, canonical) {
|
|
82
120
|
return Effect.gen(function* () {
|
|
83
|
-
const
|
|
84
|
-
if (new Set(explicitNames).size !== explicitNames.length) {
|
|
85
|
-
return yield* invalidMembership();
|
|
86
|
-
}
|
|
87
|
-
const completeNames = explicitNames.includes(input.localAgentCard.agentName)
|
|
88
|
-
? explicitNames
|
|
89
|
-
: [...explicitNames, input.localAgentCard.agentName];
|
|
90
|
-
if (completeNames.length < 3 ||
|
|
91
|
-
completeNames.length > MAXIMUM_GROUP_MEMBERS) {
|
|
92
|
-
return yield* invalidMembership();
|
|
93
|
-
}
|
|
94
|
-
const resolved = yield* Effect.forEach(completeNames, (agentName) => agentName === input.localAgentCard.agentName
|
|
121
|
+
const resolved = yield* Effect.forEach(canonical.memberNames, (agentName) => agentName === input.localAgentCard.agentName
|
|
95
122
|
? Effect.succeed(input.localAgentCard)
|
|
96
123
|
: lookupCard(input.registry, agentName), { concurrency: 1 });
|
|
97
124
|
const ordered = orderMemberCards(resolved);
|
|
@@ -101,12 +128,9 @@ function resolveGroup(input) {
|
|
|
101
128
|
if (first === undefined || second === undefined || third === undefined) {
|
|
102
129
|
return yield* Effect.dieMessage("group membership lost a member");
|
|
103
130
|
}
|
|
104
|
-
const canonicalNames = completeNames.slice();
|
|
105
|
-
canonicalNames.sort(compareAscii);
|
|
106
|
-
const address = yield* Schema.decodeUnknown(GroupAddress)(`${GROUP_ADDRESS_PREFIX}${canonicalNames.join(",")}`).pipe(Effect.mapError(invalidAddress));
|
|
107
131
|
return {
|
|
108
132
|
kind: "group",
|
|
109
|
-
address,
|
|
133
|
+
address: canonical.address,
|
|
110
134
|
memberCards: [first, second, third, ...ordered.slice(3)],
|
|
111
135
|
};
|
|
112
136
|
});
|