@yielded/agent-storage-cloudflare 0.1.0-beta.166

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.
Files changed (77) hide show
  1. package/LICENSE +21 -0
  2. package/dist/DoMemoryStore.d.mts +30 -0
  3. package/dist/DoMemoryStore.mjs +66 -0
  4. package/dist/DoMemoryStore.mjs.map +1 -0
  5. package/dist/DoMessageDeliveryStore.d.mts +17 -0
  6. package/dist/DoMessageDeliveryStore.mjs +30 -0
  7. package/dist/DoMessageDeliveryStore.mjs.map +1 -0
  8. package/dist/DoScheduleStore.d.mts +36 -0
  9. package/dist/DoScheduleStore.mjs +388 -0
  10. package/dist/DoScheduleStore.mjs.map +1 -0
  11. package/dist/DoStorageConfig.d.mts +45 -0
  12. package/dist/DoStorageConfig.mjs +52 -0
  13. package/dist/DoStorageConfig.mjs.map +1 -0
  14. package/dist/DoStorageError-CGuAfSwF.d.mts +101 -0
  15. package/dist/DoStorageError.d.mts +2 -0
  16. package/dist/DoStorageError.mjs +167 -0
  17. package/dist/DoStorageError.mjs.map +1 -0
  18. package/dist/DoStorageFailpoint.d.mts +17 -0
  19. package/dist/DoStorageFailpoint.mjs +14 -0
  20. package/dist/DoStorageFailpoint.mjs.map +1 -0
  21. package/dist/DoStorageFailpointTesting.d.mts +24 -0
  22. package/dist/DoStorageFailpointTesting.mjs +22 -0
  23. package/dist/DoStorageFailpointTesting.mjs.map +1 -0
  24. package/dist/DoStorageVersion-iNSyi3cJ.d.mts +12 -0
  25. package/dist/DoStorageVersion.d.mts +2 -0
  26. package/dist/DoStorageVersion.mjs +8 -0
  27. package/dist/DoStorageVersion.mjs.map +1 -0
  28. package/dist/DoSubmissionLedger.d.mts +23 -0
  29. package/dist/DoSubmissionLedger.mjs +1979 -0
  30. package/dist/DoSubmissionLedger.mjs.map +1 -0
  31. package/dist/DoSubscriptionStore.d.mts +25 -0
  32. package/dist/DoSubscriptionStore.mjs +186 -0
  33. package/dist/DoSubscriptionStore.mjs.map +1 -0
  34. package/dist/DoThreadStore-D_83OjCH.d.mts +72 -0
  35. package/dist/DoThreadStore.d.mts +2 -0
  36. package/dist/DoThreadStore.mjs +529 -0
  37. package/dist/DoThreadStore.mjs.map +1 -0
  38. package/dist/MemoryProtocol.d.mts +38160 -0
  39. package/dist/MemoryProtocol.mjs +219 -0
  40. package/dist/MemoryProtocol.mjs.map +1 -0
  41. package/dist/PortProtocol.d.mts +7726 -0
  42. package/dist/PortProtocol.mjs +234 -0
  43. package/dist/PortProtocol.mjs.map +1 -0
  44. package/dist/PortRouting.d.mts +97 -0
  45. package/dist/PortRouting.mjs +544 -0
  46. package/dist/PortRouting.mjs.map +1 -0
  47. package/dist/do-journal-DUhjZkOf.mjs +1352 -0
  48. package/dist/do-journal-DUhjZkOf.mjs.map +1 -0
  49. package/dist/index.d.mts +14 -0
  50. package/dist/index.mjs +14 -0
  51. package/dist/migrations-DtKz_Gxr.mjs +306 -0
  52. package/dist/migrations-DtKz_Gxr.mjs.map +1 -0
  53. package/dist/owned-state-DHm2aRXx.mjs +119 -0
  54. package/dist/owned-state-DHm2aRXx.mjs.map +1 -0
  55. package/dist/rolldown-runtime-D7D4PA-g.mjs +13 -0
  56. package/package.json +1 -0
  57. package/src/DoMemoryStore.ts +73 -0
  58. package/src/DoMessageDeliveryStore.ts +39 -0
  59. package/src/DoScheduleStore.ts +622 -0
  60. package/src/DoStorageConfig.ts +53 -0
  61. package/src/DoStorageError.ts +180 -0
  62. package/src/DoStorageFailpoint.ts +20 -0
  63. package/src/DoStorageFailpointTesting.ts +41 -0
  64. package/src/DoStorageVersion.ts +2 -0
  65. package/src/DoSubmissionLedger.ts +4027 -0
  66. package/src/DoSubscriptionStore.ts +327 -0
  67. package/src/DoThreadStore.ts +1121 -0
  68. package/src/MemoryProtocol.ts +355 -0
  69. package/src/PortProtocol.ts +436 -0
  70. package/src/PortRouting.ts +1464 -0
  71. package/src/index.ts +13 -0
  72. package/src/internal/do-journal.ts +2282 -0
  73. package/src/internal/message-delivery-schema.ts +24 -0
  74. package/src/internal/migrations.ts +304 -0
  75. package/src/internal/owned-state.ts +228 -0
  76. package/src/internal/recovery-checkpoint-schema.ts +17 -0
  77. package/src/internal/storage-span.ts +44 -0
@@ -0,0 +1,544 @@
1
+ import { t as __exportAll } from "./rolldown-runtime-D7D4PA-g.mjs";
2
+ import { LedgerAdmitCall, LedgerAdmitResult, LedgerInspectWorkerCall, LedgerInspectWorkerResult, LedgerLookupCall, LedgerLookupResult, LedgerMarkReadyCall, LedgerMarkReadyResult, LedgerRecordChildSettledCall, LedgerRecordChildSettledResult, LedgerRequestAbortCall, LedgerRequestAbortResult, LedgerResolveAdmissionCall, LedgerResolveAdmissionResult, LedgerStopWorkerCall, LedgerStopWorkerResult, MessageDeliveryCompleteCall, MessageDeliveryCompleteResult, MessageDeliveryListCall, MessageDeliveryListResult, PortFailed, PortProtocolError, PortSucceeded, StoreAppendCall, StoreAppendResult, StoreCountPeerMessagesCall, StoreCountPeerMessagesResult, StoreExportCall, StoreExportResult, StoreInspectTailCall, StoreInspectTailResult, StoreMaterializeCall, StoreMaterializeResult, StoreReadIdentityCall, StoreReadIdentityResult, StoreReadPageCall, StoreReadPageResult, WorkerAdmitCall, WorkerAdmitResult, boundPortDiagnostic, decodePortRequest, decodePortResponse, encodePortRequest, encodePortResponse } from "./PortProtocol.mjs";
3
+ import { MessageDeliveryError, MessageDeliveryStore } from "@yielded/agent/message-delivery";
4
+ import { Cause, Clock, Context, Effect, Layer, Option, Predicate, Schema, Stream } from "effect";
5
+ import { LifecyclePublicationError } from "@yielded/agent/lifecycle-publication";
6
+ import { AppendConflict, FenceRejected, ThreadMaterialization, ThreadNotMaterialized, ThreadStore, ThreadStoreError } from "@yielded/agent/thread-store";
7
+ import { AdmissionConflict, AdmissionIndeterminate, AdmissionPolicyError, ChildAttachmentSnapshot, JoinedToHost, LedgerError, RecoverySnapshot, SettlementConflict, SubmissionLedger, SubmissionLookupById } from "@yielded/agent/submission-ledger";
8
+ import { WorkerAdmissionFailure, WorkerAdmissionPort, admitWorker } from "@yielded/agent/worker-admission";
9
+ //#region src/PortRouting.ts
10
+ var PortRouting_exports = /* @__PURE__ */ __exportAll({
11
+ PortTransportError: () => PortTransportError,
12
+ ThreadPortTransport: () => ThreadPortTransport,
13
+ executePortRequest: () => executePortRequest,
14
+ handleEncodedPortRequest: () => handleEncodedPortRequest,
15
+ makeLocalSubmissionLookup: () => makeLocalSubmissionLookup,
16
+ portTransportFailure: () => portTransportFailure,
17
+ routedMessageDeliveryStoreLayer: () => routedMessageDeliveryStoreLayer,
18
+ routedSubmissionLedgerLayer: () => routedSubmissionLedgerLayer,
19
+ routedThreadStoreLayer: () => routedThreadStoreLayer,
20
+ routedWorkerAdmissionLayer: () => routedWorkerAdmissionLayer
21
+ });
22
+ const ThreadIdSchema = ThreadMaterialization.fields.threadId;
23
+ const decodeThreadId = Schema.decodeUnknownEffect(ThreadIdSchema);
24
+ /**
25
+ * The ledger row bound routable Submission identities must respect (mirrors the local
26
+ * facet's `MAX_IDENTIFIER_LENGTH`; the minting side already refuses longer identities typed
27
+ * at admission, so a longer identity presented here cannot name any stored row).
28
+ */
29
+ const MAX_ROUTABLE_SUBMISSION_ID_LENGTH = 1024;
30
+ /** The `{uuidv7}` head of a DC-minted routable Submission identity. */
31
+ const UUID_HEAD_PATTERN = /^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$/;
32
+ /**
33
+ * A transport could not deliver a port request to (or an answer from) the owning
34
+ * Thread's Durable Object. `retryable` carries the platform's own stub signal when one
35
+ * exists. This error never crosses the wire — it is the CALLER-side evidence that the
36
+ * authority was unreachable, which is exactly the case `AdmissionIndeterminate` was
37
+ * specified for (SUB-031).
38
+ */
39
+ var PortTransportError = class extends Schema.TaggedError()("PortTransportError", {
40
+ target: Schema.String,
41
+ message: Schema.String,
42
+ retryable: Schema.optionalKey(Schema.Boolean),
43
+ cause: Schema.optionalKey(Schema.Defect())
44
+ }) {};
45
+ const safeTransportDiagnostic = (cause) => {
46
+ try {
47
+ const message = cause instanceof Error ? cause.message : cause;
48
+ return boundPortDiagnostic(typeof message === "string" ? message : String(message));
49
+ } catch {
50
+ return "[unavailable transport diagnostic]";
51
+ }
52
+ };
53
+ const transportRetryableSignal = (cause) => {
54
+ if (!Predicate.isObjectKeyword(cause)) return void 0;
55
+ try {
56
+ const signal = Reflect.get(cause, "retryable");
57
+ return typeof signal === "boolean" ? signal : void 0;
58
+ } catch {
59
+ return;
60
+ }
61
+ };
62
+ /**
63
+ * Build a `PortTransportError` from an arbitrary thrown transport cause, preserving the
64
+ * platform stub's own `retryable` signal when present.
65
+ */
66
+ const portTransportFailure = (target, cause) => {
67
+ const retryable = transportRetryableSignal(cause);
68
+ return PortTransportError.make({
69
+ target,
70
+ message: safeTransportDiagnostic(cause),
71
+ ...retryable === void 0 ? {} : { retryable },
72
+ cause
73
+ });
74
+ };
75
+ /**
76
+ * Delivery of Schema-encoded port envelopes to the Durable Object that owns a FOREIGN
77
+ * Thread (plan §1.3, D-P6-3). The shipped implementation (platform-cloudflare, WP3)
78
+ * calls the owner's `portCall` over native Durable Object JS RPC via
79
+ * `namespace.idFromName(threadId)`; the protocol is transport-agnostic and any carrier
80
+ * that moves the encoded envelopes verbatim satisfies this service. Implementations MUST
81
+ * surface every delivery problem as `PortTransportError` and must never fabricate an answer.
82
+ */
83
+ var ThreadPortTransport = class extends Context.Service()("@effect-agent/storage-cloudflare/ThreadPortTransport") {};
84
+ const LOCAL = { _tag: "local" };
85
+ /**
86
+ * Parse a DC-minted routable Submission identity — `{uuidv7}:{threadId}`, split at the
87
+ * FIRST `:` because the Thread tail may itself contain colons (D-P6-5). This adapter
88
+ * minted the format at admission and is the ONLY component that parses it; identities that do
89
+ * not carry the minted shape (no separator, non-UUID head, empty tail) fall back to the local
90
+ * facet, which is the only authority this Object can consult without inventing an owner.
91
+ * Identities beyond the ledger's 1,024-character row bound fail typed: the minting side
92
+ * refused them at admission, so they cannot name any stored row anywhere.
93
+ */
94
+ const routableSubmissionTarget = (ownsThread) => Effect.fn("DoPortRouting.routableSubmissionTarget")(function* (operation, submissionId) {
95
+ if (submissionId.length > MAX_ROUTABLE_SUBMISSION_ID_LENGTH) return yield* LedgerError.make({
96
+ operation,
97
+ message: `A Submission identity of ${submissionId.length} characters exceeds the ${MAX_ROUTABLE_SUBMISSION_ID_LENGTH}-character routable identity bound; admission refuses such identities, so it cannot name any stored row.`
98
+ });
99
+ const separator = submissionId.indexOf(":");
100
+ if (separator === -1) return LOCAL;
101
+ if (!UUID_HEAD_PATTERN.test(submissionId.slice(0, separator))) return LOCAL;
102
+ const tail = submissionId.slice(separator + 1);
103
+ return yield* decodeThreadId(tail).pipe(Effect.map((threadId) => ownsThread(threadId) ? LOCAL : {
104
+ _tag: "foreign",
105
+ threadId
106
+ }), Effect.orElseSucceed(() => LOCAL));
107
+ });
108
+ /**
109
+ * Read a Submission only from this physical owner. Encoded foreign identities fail before
110
+ * storage access; opaque identities still use local lookup. A returned row must also belong
111
+ * to an owned Thread. This is placement validation, not caller authorization.
112
+ */
113
+ const makeLocalSubmissionLookup = (options) => {
114
+ const submissionTarget = routableSubmissionTarget(options.ownsThread);
115
+ return Effect.fn("DoPortRouting.lookupLocalSubmission")(function* (submissionId) {
116
+ const operation = "local Submission lookup";
117
+ if ((yield* submissionTarget(operation, submissionId))._tag === "foreign") return yield* LedgerError.make({
118
+ operation,
119
+ message: "The Submission belongs to another Thread Object"
120
+ });
121
+ const submission = yield* (yield* SubmissionLedger).lookup(SubmissionLookupById.make({ submissionId }));
122
+ if (Option.isSome(submission) && !options.ownsThread(submission.value.threadId)) return yield* LedgerError.make({
123
+ operation,
124
+ message: "The stored Submission belongs to another Thread Object"
125
+ });
126
+ return submission;
127
+ });
128
+ };
129
+ const NoAdditionalPortFailure = Schema.Never;
130
+ const AbortPortFailure = Schema.Union([SettlementConflict, JoinedToHost]);
131
+ const AppendPortFailure = Schema.Union([
132
+ ThreadNotMaterialized,
133
+ AppendConflict,
134
+ FenceRejected
135
+ ]);
136
+ /**
137
+ * The fail-fast refusal for any foreign operation OUTSIDE the closed route-capable subset
138
+ * (plan §1.3): honesty over accidental distribution.
139
+ */
140
+ const crossThreadLedgerError = (operation, target) => LedgerError.make({
141
+ operation,
142
+ message: `${operation} addressed to foreign Thread ${target} is not route-capable; the closed cross-Object subset is admit, markReady, lookup, resolveAdmission, requestAbort, and recordChildSettled. Every other ledger operation is lane-local by construction and must execute inside the owning Thread's Durable Object.`
143
+ });
144
+ const crossThreadStoreError = (operation, target) => ThreadStoreError.make({
145
+ operation,
146
+ message: `${operation} addressed to foreign Thread ${target} is not route-capable; the closed cross-Object subset is materialize, append, read (paged), inspectTail, and export. Observation and checkpoints are lane-local by construction and must execute inside the owning Thread's Durable Object.`
147
+ });
148
+ const makeTransportCall = (transport) => Effect.fn("DoPortRouting.transportCall")(function* (target, call) {
149
+ const encoded = yield* encodePortRequest(call).pipe(Effect.mapError((error) => PortProtocolError.make({ message: boundPortDiagnostic(`The port request could not be encoded: ${error.message}`) })));
150
+ const raw = yield* transport.call(target, encoded);
151
+ return yield* decodePortResponse(raw).pipe(Effect.mapError((error) => PortProtocolError.make({ message: boundPortDiagnostic(`The port response could not be decoded: ${error.message}`) })));
152
+ });
153
+ const makeRoutedLedgerServices = Effect.fn("DoPortRouting.makeRoutedLedgerServices")(function* (options) {
154
+ const local = yield* SubmissionLedger;
155
+ const transport = yield* ThreadPortTransport;
156
+ const transportCall = makeTransportCall(transport);
157
+ const submissionTarget = routableSubmissionTarget(options.ownsThread);
158
+ const routeFailure = (operation, target) => (error) => LedgerError.make({
159
+ operation,
160
+ message: boundPortDiagnostic(`Routed ${operation} to the Thread Object owning ${target} failed: ${error.message}`),
161
+ cause: error
162
+ });
163
+ /**
164
+ * One routed ledger call: encode, deliver, decode, then narrow the uniform envelope to the
165
+ * operation's own result and failure surface. A foreign `LedgerError` is always in-channel;
166
+ * any failure outside the operation's declared surface — including protocol anomalies — is
167
+ * folded into a `LedgerError` naming the anomaly instead of being erased or re-thrown raw.
168
+ */
169
+ const foreignLedgerCall = (operation, target, call, resultSchema, failureSchema) => {
170
+ const isExpectedResult = Schema.is(resultSchema);
171
+ const isExpectedFailure = Schema.is(failureSchema);
172
+ return transportCall(target, call).pipe(Effect.mapError(routeFailure(operation, target)), Effect.flatMap((response) => {
173
+ if (response._tag === "PortFailed") {
174
+ const failure = response.failure;
175
+ if (isExpectedFailure(failure)) return Effect.fail(failure);
176
+ if (failure._tag === "LedgerError") return Effect.fail(failure);
177
+ return Effect.fail(LedgerError.make({
178
+ operation,
179
+ message: boundPortDiagnostic(`The Thread Object owning ${target} answered ${operation} with the out-of-contract failure ${failure._tag}`),
180
+ cause: failure
181
+ }));
182
+ }
183
+ const result = response.result;
184
+ if (!isExpectedResult(result)) return Effect.fail(LedgerError.make({
185
+ operation,
186
+ message: `The Thread Object owning ${target} answered ${operation} with the mismatched result ${result._tag}.`
187
+ }));
188
+ return Effect.succeed(result);
189
+ }), Effect.withSpan("DoPortRouting.foreignLedgerCall", { attributes: {
190
+ operation,
191
+ target
192
+ } }));
193
+ };
194
+ /**
195
+ * Routed `resolveAdmission` — where the S2 tri-state becomes real (plan §1.3): when the
196
+ * owning Object cannot be reached, or its answer cannot be understood, the routed adapter
197
+ * answers `AdmissionIndeterminate{reason}` and NEVER `NotAdmitted` — an unreachable
198
+ * authority proves nothing, and only `NotAdmitted` permits an admission attempt (SUB-031).
199
+ * A typed `LedgerError` answered BY the authority still fails typed: the authority was
200
+ * reached and reported its own storage failure.
201
+ */
202
+ const resolveForeignAdmission = (target, request) => transportCall(target, LedgerResolveAdmissionCall.make({ request })).pipe(Effect.flatMap((response) => {
203
+ if (response._tag === "PortFailed") {
204
+ if (response.failure._tag === "LedgerError") return Effect.fail(response.failure);
205
+ return Effect.succeed(AdmissionIndeterminate.make({ reason: boundPortDiagnostic(`The Thread Object owning ${target} answered resolveAdmission with the out-of-contract failure ${response.failure._tag}: ${response.failure.message}`) }));
206
+ }
207
+ if (response.result._tag !== "LedgerResolveAdmissionResult") return Effect.succeed(AdmissionIndeterminate.make({ reason: boundPortDiagnostic(`The Thread Object owning ${target} answered resolveAdmission with the mismatched result ${response.result._tag}.`) }));
208
+ return Effect.succeed(response.result.resolution);
209
+ }), Effect.catchTags({
210
+ PortTransportError: (error) => Effect.succeed(AdmissionIndeterminate.make({ reason: boundPortDiagnostic(`The Thread Object owning ${target} is unreachable: ${error.message}`) })),
211
+ PortProtocolError: (error) => Effect.succeed(AdmissionIndeterminate.make({ reason: boundPortDiagnostic(`The answer of the Thread Object owning ${target} could not be understood: ${error.message}`) }))
212
+ }), Effect.withSpan("DoPortRouting.resolveForeignAdmission", { attributes: { target } }));
213
+ const foreignLookupById = (operation, target, submissionId) => foreignLedgerCall(operation, target, LedgerLookupCall.make({ request: SubmissionLookupById.make({ submissionId }) }), LedgerLookupResult, NoAdditionalPortFailure).pipe(Effect.map((result) => result.submission === void 0 ? Option.none() : Option.some(result.submission)));
214
+ /**
215
+ * Enrich a LOCAL parent's recovery snapshot with the lane state of attached children whose
216
+ * rows live in other Durable Objects (plan §1.3): markers first (the local facet already
217
+ * consulted them), then a routed per-child `lookup` for any attached child that is neither
218
+ * local nor marker-settled. A transport failure surfaces as `LedgerError` so the alarm
219
+ * pass retries; the child's canonical Settlement remains the only authority (DUR-015).
220
+ */
221
+ const enrichChildAttachments = Effect.fn("DoPortRouting.enrichChildAttachments")(function* (snapshot) {
222
+ const operation = "ledger load recovery snapshot";
223
+ const attachments = new Map(snapshot.childAttachments.map((attachment) => [attachment.childSubmissionId, attachment]));
224
+ let enriched = false;
225
+ for (const reservation of snapshot.childReservations) {
226
+ const childSubmissionId = reservation.childSubmissionId;
227
+ if (childSubmissionId === void 0 || attachments.has(childSubmissionId)) continue;
228
+ const target = yield* submissionTarget(operation, childSubmissionId);
229
+ if (target._tag !== "foreign") continue;
230
+ const child = yield* foreignLookupById(operation, target.threadId, childSubmissionId);
231
+ if (Option.isNone(child)) continue;
232
+ attachments.set(childSubmissionId, ChildAttachmentSnapshot.make({
233
+ toolCallId: reservation.parentToolCallId,
234
+ childSubmissionId,
235
+ childState: child.value.state,
236
+ ...child.value.settledOutcome === void 0 ? {} : { childOutcome: child.value.settledOutcome }
237
+ }));
238
+ enriched = true;
239
+ }
240
+ if (!enriched) return snapshot;
241
+ const ordered = [];
242
+ for (const reservation of snapshot.childReservations) {
243
+ if (reservation.childSubmissionId === void 0) continue;
244
+ const attachment = attachments.get(reservation.childSubmissionId);
245
+ if (attachment !== void 0) ordered.push(attachment);
246
+ }
247
+ return RecoverySnapshot.make({
248
+ ...snapshot,
249
+ childAttachments: ordered
250
+ });
251
+ });
252
+ const routed = SubmissionLedger.of({
253
+ capabilities: local.capabilities,
254
+ admit: (request) => options.ownsThread(request.threadId) ? local.admit(request) : foreignLedgerCall("ledger admit", request.threadId, LedgerAdmitCall.make({ request }), LedgerAdmitResult, Schema.Union([AdmissionConflict, AdmissionPolicyError])).pipe(Effect.map((reply) => reply.result)),
255
+ markReady: (request) => submissionTarget("ledger mark ready", request.submissionId).pipe(Effect.flatMap((target) => target._tag === "local" ? local.markReady(request) : foreignLedgerCall("ledger mark ready", target.threadId, LedgerMarkReadyCall.make({ request }), LedgerMarkReadyResult, NoAdditionalPortFailure).pipe(Effect.asVoid))),
256
+ lookup: (request) => request._tag === "SubmissionLookupById" ? submissionTarget("ledger lookup", request.submissionId).pipe(Effect.flatMap((target) => target._tag === "local" ? local.lookup(request) : foreignLookupById("ledger lookup", target.threadId, request.submissionId))) : options.ownsThread(request.threadId) ? local.lookup(request) : foreignLedgerCall("ledger lookup", request.threadId, LedgerLookupCall.make({ request }), LedgerLookupResult, NoAdditionalPortFailure).pipe(Effect.map((result) => result.submission === void 0 ? Option.none() : Option.some(result.submission))),
257
+ resolveAdmission: (request) => options.ownsThread(request.threadId) ? local.resolveAdmission(request) : resolveForeignAdmission(request.threadId, request),
258
+ inspectWorker: (threadId) => options.ownsThread(threadId) ? local.inspectWorker === void 0 ? Effect.fail(LedgerError.make({
259
+ operation: "inspectWorker",
260
+ message: "Worker inspection unavailable"
261
+ })) : local.inspectWorker(threadId) : foreignLedgerCall("inspect worker", threadId, LedgerInspectWorkerCall.make({ request: { threadId } }), LedgerInspectWorkerResult, NoAdditionalPortFailure).pipe(Effect.map((reply) => reply.state)),
262
+ stopWorker: (request) => options.ownsThread(request.threadId) ? local.stopWorker === void 0 ? Effect.fail(LedgerError.make({
263
+ operation: "stopWorker",
264
+ message: "Worker stop unavailable"
265
+ })) : local.stopWorker(request) : foreignLedgerCall("ledger stop worker", request.threadId, LedgerStopWorkerCall.make({ request }), LedgerStopWorkerResult, NoAdditionalPortFailure).pipe(Effect.map((reply) => reply.owned)),
266
+ requestAbort: (request) => submissionTarget("ledger request abort", request.submissionId).pipe(Effect.flatMap((target) => target._tag === "local" ? local.requestAbort(request) : foreignLedgerCall("ledger request abort", target.threadId, LedgerRequestAbortCall.make({ request }), LedgerRequestAbortResult, AbortPortFailure).pipe(Effect.map((reply) => reply.intent)))),
267
+ recordChildSettled: (request) => submissionTarget("ledger record child settled", request.parentSubmissionId).pipe(Effect.flatMap((target) => target._tag === "local" ? local.recordChildSettled(request) : foreignLedgerCall("ledger record child settled", target.threadId, LedgerRecordChildSettledCall.make({ request }), LedgerRecordChildSettledResult, NoAdditionalPortFailure).pipe(Effect.map((reply) => reply.outcome)))),
268
+ claim: (request) => options.ownsThread(request.threadId) ? local.claim(request) : Effect.fail(crossThreadLedgerError("ledger claim", request.threadId)),
269
+ claimJoining: (request) => options.ownsThread(request.threadId) ? local.claimJoining(request) : Effect.fail(crossThreadLedgerError("ledger claim joining", request.threadId)),
270
+ renewOwnership: (request) => submissionTarget("ledger renew ownership", request.submissionId).pipe(Effect.flatMap((target) => target._tag === "local" ? local.renewOwnership(request) : Effect.fail(crossThreadLedgerError("ledger renew ownership", target.threadId)))),
271
+ releaseOwnership: (request) => submissionTarget("ledger release ownership", request.submissionId).pipe(Effect.flatMap((target) => target._tag === "local" ? local.releaseOwnership(request) : Effect.fail(crossThreadLedgerError("ledger release ownership", target.threadId)))),
272
+ markInputApplied: (request) => submissionTarget("ledger mark input applied", request.submissionId).pipe(Effect.flatMap((target) => target._tag === "local" ? local.markInputApplied(request) : Effect.fail(crossThreadLedgerError("ledger mark input applied", target.threadId)))),
273
+ reserveSettlement: (request) => submissionTarget("ledger reserve settlement", request.submissionId).pipe(Effect.flatMap((target) => target._tag === "local" ? local.reserveSettlement(request) : Effect.fail(crossThreadLedgerError("ledger reserve settlement", target.threadId)))),
274
+ finalizeSettlement: (request) => submissionTarget("ledger finalize settlement", request.submissionId).pipe(Effect.flatMap((target) => target._tag === "local" ? local.finalizeSettlement(request) : Effect.fail(crossThreadLedgerError("ledger finalize settlement", target.threadId)))),
275
+ markJoined: (request) => submissionTarget("ledger mark joined", request.submissionId).pipe(Effect.flatMap((target) => target._tag === "local" ? local.markJoined(request) : Effect.fail(crossThreadLedgerError("ledger mark joined", target.threadId)))),
276
+ revertJoining: (request) => submissionTarget("ledger revert joining", request.submissionId).pipe(Effect.flatMap((target) => target._tag === "local" ? local.revertJoining(request) : Effect.fail(crossThreadLedgerError("ledger revert joining", target.threadId)))),
277
+ suspend: (request) => submissionTarget("ledger suspend", request.submissionId).pipe(Effect.flatMap((target) => target._tag === "local" ? local.suspend(request) : Effect.fail(crossThreadLedgerError("ledger suspend", target.threadId)))),
278
+ recordApprovalDecision: (command) => submissionTarget("ledger record approval decision", command.submissionId).pipe(Effect.flatMap((target) => target._tag === "local" ? local.recordApprovalDecision(command) : Effect.fail(crossThreadLedgerError("ledger record approval decision", target.threadId)))),
279
+ markUnknown: (request) => submissionTarget("ledger mark unknown", request.submissionId).pipe(Effect.flatMap((target) => target._tag === "local" ? local.markUnknown(request) : Effect.fail(crossThreadLedgerError("ledger mark unknown", target.threadId)))),
280
+ recordUnknownResolution: (command) => submissionTarget("ledger record unknown resolution", command.submissionId).pipe(Effect.flatMap((target) => target._tag === "local" ? local.recordUnknownResolution(command) : Effect.fail(crossThreadLedgerError("ledger record unknown resolution", target.threadId)))),
281
+ reserveChildBudget: (request) => submissionTarget("ledger reserve child budget", request.parentSubmissionId).pipe(Effect.flatMap((target) => target._tag === "local" ? local.reserveChildBudget(request) : Effect.fail(crossThreadLedgerError("ledger reserve child budget", target.threadId)))),
282
+ attachChildToReservation: local.attachChildToReservation,
283
+ beginChildBudgetRelease: local.beginChildBudgetRelease,
284
+ releaseChildBudget: local.releaseChildBudget,
285
+ scanNonterminal: local.scanNonterminal,
286
+ readAbortIntent: (request) => submissionTarget("ledger read abort intent", request.submissionId).pipe(Effect.flatMap((target) => target._tag === "local" ? local.readAbortIntent(request) : Effect.fail(crossThreadLedgerError("ledger read abort intent", target.threadId)))),
287
+ loadRecoverySnapshot: (request) => submissionTarget("ledger load recovery snapshot", request.submissionId).pipe(Effect.flatMap((target) => target._tag === "local" ? local.loadRecoverySnapshot(request).pipe(Effect.flatMap(enrichChildAttachments)) : Effect.fail(crossThreadLedgerError("ledger load recovery snapshot", target.threadId))))
288
+ });
289
+ return Context.make(SubmissionLedger, routed);
290
+ });
291
+ const makeRoutedStoreServices = Effect.fn("DoPortRouting.makeRoutedStoreServices")(function* (options) {
292
+ const local = yield* ThreadStore;
293
+ const checkpoints = local.checkpoints;
294
+ const recoveryCheckpoints = local.recoveryCheckpoints;
295
+ const lifecyclePublications = local.lifecyclePublications;
296
+ const acknowledgeMany = lifecyclePublications?.acknowledgeMany;
297
+ const transport = yield* ThreadPortTransport;
298
+ const transportCall = makeTransportCall(transport);
299
+ const routeFailure = (operation, target) => (error) => ThreadStoreError.make({
300
+ operation,
301
+ message: boundPortDiagnostic(`Routed ${operation} to the Thread Object owning ${target} failed: ${error.message}`),
302
+ cause: error
303
+ });
304
+ /** The store twin of `foreignLedgerCall` with `ThreadStoreError` as the base error. */
305
+ const foreignStoreCall = (operation, target, call, resultSchema, failureSchema) => {
306
+ const isExpectedResult = Schema.is(resultSchema);
307
+ const isExpectedFailure = Schema.is(failureSchema);
308
+ return transportCall(target, call).pipe(Effect.mapError(routeFailure(operation, target)), Effect.flatMap((response) => {
309
+ if (response._tag === "PortFailed") {
310
+ const failure = response.failure;
311
+ if (isExpectedFailure(failure)) return Effect.fail(failure);
312
+ if (failure._tag === "ThreadStoreError") return Effect.fail(failure);
313
+ return Effect.fail(ThreadStoreError.make({
314
+ operation,
315
+ message: boundPortDiagnostic(`The Thread Object owning ${target} answered ${operation} with the out-of-contract failure ${failure._tag}`),
316
+ cause: failure
317
+ }));
318
+ }
319
+ const result = response.result;
320
+ if (!isExpectedResult(result)) return Effect.fail(ThreadStoreError.make({
321
+ operation,
322
+ message: `The Thread Object owning ${target} answered ${operation} with the mismatched result ${result._tag}.`
323
+ }));
324
+ return Effect.succeed(result);
325
+ }), Effect.withSpan("DoPortRouting.foreignStoreCall", { attributes: {
326
+ operation,
327
+ target
328
+ } }));
329
+ };
330
+ const routed = ThreadStore.of({
331
+ countPeerMessages: (request) => options.ownsThread(request.threadId) ? local.countPeerMessages === void 0 ? Effect.fail(crossThreadStoreError("peer count unavailable", request.threadId)) : local.countPeerMessages(request) : foreignStoreCall("thread countPeerMessages", request.threadId, StoreCountPeerMessagesCall.make({ request }), StoreCountPeerMessagesResult, ThreadNotMaterialized).pipe(Effect.map((reply) => reply.count)),
332
+ materialize: (request) => options.ownsThread(request.threadId) ? local.materialize(request) : foreignStoreCall("thread materialize", request.threadId, StoreMaterializeCall.make({ request }), StoreMaterializeResult, FenceRejected).pipe(Effect.asVoid),
333
+ append: (request) => options.ownsThread(request.threadId) ? local.append(request) : foreignStoreCall("thread append", request.threadId, StoreAppendCall.make({ request }), StoreAppendResult, AppendPortFailure).pipe(Effect.map((reply) => reply.result)),
334
+ read: (request) => options.ownsThread(request.threadId) ? local.read(request) : Stream.unwrap(foreignStoreCall("thread read", request.threadId, StoreReadPageCall.make({ request }), StoreReadPageResult, ThreadNotMaterialized).pipe(Effect.map((reply) => Stream.fromIterable(reply.records)))),
335
+ inspectTail: (request) => options.ownsThread(request.threadId) ? local.inspectTail(request) : foreignStoreCall("thread inspect tail", request.threadId, StoreInspectTailCall.make({ request }), StoreInspectTailResult, ThreadNotMaterialized).pipe(Effect.map((reply) => reply.tail)),
336
+ readIdentity: (request) => options.ownsThread(request.threadId) ? local.readIdentity(request) : foreignStoreCall("thread read identity", request.threadId, StoreReadIdentityCall.make({ request }), StoreReadIdentityResult, ThreadNotMaterialized).pipe(Effect.flatMap((reply) => reply.identity.threadId === request.threadId ? Effect.succeed(reply.identity) : Effect.fail(ThreadStoreError.make({
337
+ operation: "thread read identity",
338
+ message: "The identity snapshot belongs to another Thread."
339
+ })))),
340
+ export: (request) => options.ownsThread(request.threadId) ? local.export(request) : foreignStoreCall("thread export", request.threadId, StoreExportCall.make({ request }), StoreExportResult, ThreadNotMaterialized).pipe(Effect.map((reply) => reply.export)),
341
+ observe: (request) => options.ownsThread(request.threadId) ? local.observe(request) : Stream.unwrap(Effect.fail(crossThreadStoreError("thread observe", request.threadId))),
342
+ ...lifecyclePublications === void 0 ? {} : { lifecyclePublications: {
343
+ ...lifecyclePublications,
344
+ ...acknowledgeMany === void 0 ? {} : { acknowledgeMany: (batches) => batches.every((batch) => batch.every((publication) => options.ownsThread(publication.ownerThreadId))) ? acknowledgeMany(batches) : Effect.fail(LifecyclePublicationError.make({ reason: "unavailable" })) },
345
+ acknowledge: (batch) => batch.every((publication) => options.ownsThread(publication.ownerThreadId)) ? lifecyclePublications.acknowledge(batch) : Effect.fail(LifecyclePublicationError.make({ reason: "unavailable" })),
346
+ claim: (batch, nowMillis, timeoutMillis) => batch.every((publication) => options.ownsThread(publication.ownerThreadId)) ? lifecyclePublications.claim(batch, nowMillis, timeoutMillis) : Effect.fail(LifecyclePublicationError.make({ reason: "unavailable" })),
347
+ retryParked: (ownerThreadId, nowMillis) => options.ownsThread(ownerThreadId) ? lifecyclePublications.retryParked(ownerThreadId, nowMillis) : Effect.fail(LifecyclePublicationError.make({ reason: "unavailable" }))
348
+ } },
349
+ ...recoveryCheckpoints === void 0 ? {} : { recoveryCheckpoints: {
350
+ save: (request) => options.ownsThread(request.checkpoint.threadId) ? recoveryCheckpoints.save(request) : Effect.fail(crossThreadStoreError("thread save recovery checkpoint", request.checkpoint.threadId)),
351
+ load: (request) => options.ownsThread(request.threadId) ? recoveryCheckpoints.load(request) : Effect.succeed(Option.none())
352
+ } },
353
+ ...checkpoints === void 0 ? {} : { checkpoints: {
354
+ save: (request) => options.ownsThread(request.checkpoint.threadId) ? checkpoints.save(request) : Effect.fail(crossThreadStoreError("thread save checkpoint", request.checkpoint.threadId)),
355
+ load: (request) => options.ownsThread(request.threadId) ? checkpoints.load(request) : Effect.fail(crossThreadStoreError("thread load checkpoint", request.threadId))
356
+ } }
357
+ });
358
+ return Context.make(ThreadStore, routed);
359
+ });
360
+ /**
361
+ * Routing decorator over the LOCAL `SubmissionLedger` facet (plan §1.3): a request addressing
362
+ * this Object's Thread executes locally; a route-capable request addressing another
363
+ * Thread is Schema-encoded onto the `ThreadPortTransport` and executed by the
364
+ * owning Object's local facet; any other foreign request fails fast typed. Provide the WP1
365
+ * local facet (`submissionLedgerLayer`/`ledgerLayer`) and a transport to close it.
366
+ */
367
+ const routedSubmissionLedgerLayer = (options) => Layer.effectContext(makeRoutedLedgerServices(options));
368
+ /**
369
+ * Routing decorator over the LOCAL `ThreadStore` facet (plan §1.3): this-thread
370
+ * requests execute locally; foreign materialize/append/read/inspectTail/export travel the
371
+ * transport. Foreign recovery-cache loads return none for canonical replay; other foreign
372
+ * checkpoint operations and observation fail fast typed.
373
+ */
374
+ const routedThreadStoreLayer = (options) => Layer.effectContext(makeRoutedStoreServices(options));
375
+ /** Route validated worker admission as one operation; source policy hooks stay at the caller. */
376
+ const routedWorkerAdmissionLayer = (options) => Layer.effect(WorkerAdmissionPort, Effect.gen(function* () {
377
+ const call = makeTransportCall(yield* ThreadPortTransport);
378
+ return WorkerAdmissionPort.of({ admit: (request) => options.ownsThread(request.threadId) ? admitWorker(request) : call(request.threadId, WorkerAdmitCall.make({ request })).pipe(Effect.mapError((cause) => LedgerError.make({
379
+ operation: "admit worker",
380
+ message: "Worker admission transport failed",
381
+ cause
382
+ })), Effect.flatMap((response) => {
383
+ if (response._tag === "PortSucceeded" && response.result._tag === "WorkerAdmitResult") return Effect.succeed(response.result.result);
384
+ return Effect.fail(response._tag === "PortFailed" && Schema.is(WorkerAdmissionFailure)(response.failure) ? response.failure : LedgerError.make({
385
+ operation: "admit worker",
386
+ message: "Unexpected worker admission response",
387
+ cause: response
388
+ }));
389
+ })) });
390
+ }));
391
+ /** Route the existing owner-scoped list; delivery mutations remain source local. */
392
+ const routedMessageDeliveryStoreLayer = (options) => Layer.effect(MessageDeliveryStore, Effect.gen(function* () {
393
+ const local = yield* MessageDeliveryStore;
394
+ const call = makeTransportCall(yield* ThreadPortTransport);
395
+ return MessageDeliveryStore.of({
396
+ ...local,
397
+ change: (key, change) => options.ownsThread(key.ownerThreadId) || change._tag !== "Complete" ? local.change(key, change) : call(key.ownerThreadId, MessageDeliveryCompleteCall.make({
398
+ key,
399
+ completion: change
400
+ })).pipe(Effect.catchCause((cause) => Effect.failCause(Cause.map(cause, (failure) => MessageDeliveryError.make({
401
+ reason: "storage",
402
+ operation: "route delivery completion",
403
+ cause: failure
404
+ })))), Effect.flatMap((response) => {
405
+ if (response._tag === "PortSucceeded" && response.result._tag === "MessageDeliveryCompleteResult") return Effect.succeed(response.result.record);
406
+ if (response._tag === "PortFailed" && (response.failure._tag === "MessageDeliveryError" || response.failure._tag === "MessageDeliveryFailpointError")) return Effect.fail(response.failure);
407
+ return Effect.fail(MessageDeliveryError.make({
408
+ reason: "storage",
409
+ operation: "route delivery completion",
410
+ cause: response
411
+ }));
412
+ })),
413
+ list: (request) => options.ownsThread(request.ownerThreadId) ? local.list(request) : call(request.ownerThreadId, MessageDeliveryListCall.make({ request })).pipe(Effect.mapError(() => MessageDeliveryError.make({
414
+ reason: "storage",
415
+ operation: "route delivery list"
416
+ })), Effect.flatMap((response) => {
417
+ if (response._tag === "PortSucceeded" && response.result._tag === "MessageDeliveryListResult") return Effect.succeed(response.result.page);
418
+ return Effect.fail(response._tag === "PortFailed" && response.failure._tag === "MessageDeliveryError" ? response.failure : MessageDeliveryError.make({
419
+ reason: "storage",
420
+ operation: "route delivery list"
421
+ }));
422
+ }))
423
+ });
424
+ }));
425
+ /** Fold one port operation's typed failures into the uniform response envelope. */
426
+ const capture = (effect) => effect.pipe(Effect.map((result) => PortSucceeded.make({ result })), Effect.catch((failure) => Effect.succeed(PortFailed.make({ failure }))));
427
+ /**
428
+ * Execute one decoded port request against THIS Object's LOCAL facets — the owner-side half
429
+ * of the routed ports (plan §1.3). Callers must provide the WP1 local facets, never the
430
+ * routed decorators: the routing layer already established that this Object owns the
431
+ * addressed Thread, and re-routing here could bounce a request between Objects.
432
+ * Failures never escape — every typed port failure becomes a `PortFailed` envelope that
433
+ * re-decodes on the caller side.
434
+ */
435
+ const executePortRequest = Effect.fn("DoPortRouting.executePortRequest")(function* (request) {
436
+ switch (request._tag) {
437
+ case "MessageDeliveryComplete": {
438
+ const store = yield* MessageDeliveryStore;
439
+ return yield* capture(store.change(request.key, {
440
+ _tag: "Complete",
441
+ ...request.completion,
442
+ nowMillis: yield* Clock.currentTimeMillis
443
+ }).pipe(Effect.map((record) => MessageDeliveryCompleteResult.make({ record }))));
444
+ }
445
+ case "WorkerAdmit": return yield* capture(admitWorker(request.request).pipe(Effect.map((result) => WorkerAdmitResult.make({ result }))));
446
+ case "MessageDeliveryList": {
447
+ const store = yield* MessageDeliveryStore;
448
+ return yield* capture(store.list(request.request).pipe(Effect.map((page) => MessageDeliveryListResult.make({ page }))));
449
+ }
450
+ case "StoreCountPeerMessages": {
451
+ const store = yield* ThreadStore;
452
+ return yield* capture(store.countPeerMessages === void 0 ? Effect.fail(crossThreadStoreError("native read unavailable", request.request.threadId)) : store.countPeerMessages(request.request).pipe(Effect.map((count) => StoreCountPeerMessagesResult.make({ count }))));
453
+ }
454
+ case "LedgerAdmit": {
455
+ const ledger = yield* SubmissionLedger;
456
+ return yield* capture(ledger.admit(request.request).pipe(Effect.map((result) => LedgerAdmitResult.make({ result }))));
457
+ }
458
+ case "LedgerMarkReady": {
459
+ const ledger = yield* SubmissionLedger;
460
+ return yield* capture(ledger.markReady(request.request).pipe(Effect.map(() => LedgerMarkReadyResult.make({}))));
461
+ }
462
+ case "LedgerLookup": {
463
+ const ledger = yield* SubmissionLedger;
464
+ return yield* capture(ledger.lookup(request.request).pipe(Effect.map((submission) => Option.isSome(submission) ? LedgerLookupResult.make({ submission: submission.value }) : LedgerLookupResult.make({}))));
465
+ }
466
+ case "LedgerResolveAdmission": {
467
+ const ledger = yield* SubmissionLedger;
468
+ return yield* capture(ledger.resolveAdmission(request.request).pipe(Effect.map((resolution) => LedgerResolveAdmissionResult.make({ resolution }))));
469
+ }
470
+ case "LedgerInspectWorker": {
471
+ const ledger = yield* SubmissionLedger;
472
+ return yield* capture(ledger.inspectWorker === void 0 ? Effect.fail(LedgerError.make({
473
+ operation: "inspectWorker",
474
+ message: "Worker inspection unavailable"
475
+ })) : ledger.inspectWorker(request.request.threadId).pipe(Effect.map((state) => LedgerInspectWorkerResult.make({ state }))));
476
+ }
477
+ case "LedgerStopWorker": {
478
+ const ledger = yield* SubmissionLedger;
479
+ return yield* capture(ledger.stopWorker === void 0 ? Effect.fail(LedgerError.make({
480
+ operation: "stopWorker",
481
+ message: "Worker stop unavailable"
482
+ })) : ledger.stopWorker(request.request).pipe(Effect.map((owned) => LedgerStopWorkerResult.make({ owned }))));
483
+ }
484
+ case "LedgerRequestAbort": {
485
+ const ledger = yield* SubmissionLedger;
486
+ return yield* capture(ledger.requestAbort(request.request).pipe(Effect.map((intent) => LedgerRequestAbortResult.make({ intent }))));
487
+ }
488
+ case "LedgerRecordChildSettled": {
489
+ const ledger = yield* SubmissionLedger;
490
+ return yield* capture(ledger.recordChildSettled(request.request).pipe(Effect.map((outcome) => LedgerRecordChildSettledResult.make({ outcome }))));
491
+ }
492
+ case "StoreMaterialize": {
493
+ const store = yield* ThreadStore;
494
+ return yield* capture(store.materialize(request.request).pipe(Effect.map(() => StoreMaterializeResult.make({}))));
495
+ }
496
+ case "StoreAppend": {
497
+ const store = yield* ThreadStore;
498
+ return yield* capture(store.append(request.request).pipe(Effect.map((result) => StoreAppendResult.make({ result }))));
499
+ }
500
+ case "StoreReadPage": {
501
+ const store = yield* ThreadStore;
502
+ return yield* capture(store.read(request.request).pipe(Stream.runCollect, Effect.map((records) => StoreReadPageResult.make({ records: [...records] }))));
503
+ }
504
+ case "StoreInspectTail": {
505
+ const store = yield* ThreadStore;
506
+ return yield* capture(store.inspectTail(request.request).pipe(Effect.map((tail) => StoreInspectTailResult.make({ tail }))));
507
+ }
508
+ case "StoreReadIdentity": {
509
+ const store = yield* ThreadStore;
510
+ return yield* capture(store.readIdentity(request.request).pipe(Effect.map((identity) => StoreReadIdentityResult.make({ identity }))));
511
+ }
512
+ case "StoreExport": {
513
+ const store = yield* ThreadStore;
514
+ return yield* capture(store.export(request.request).pipe(Effect.map((threadExport) => StoreExportResult.make({ export: threadExport }))));
515
+ }
516
+ }
517
+ });
518
+ /**
519
+ * The last-resort wire fallback when even encoding a response fails: the literal encoded
520
+ * form of `PortFailed(PortProtocolError)` — tagged classes of bounded strings encode to
521
+ * exactly this shape, so no Schema round trip is needed to produce it.
522
+ */
523
+ const encodedProtocolFailure = (message) => ({
524
+ _tag: "PortFailed",
525
+ failure: {
526
+ _tag: "PortProtocolError",
527
+ message: boundPortDiagnostic(message)
528
+ }
529
+ });
530
+ /**
531
+ * The complete owner-side endpoint body for `portCall` (D-P6-3): decode the wire request,
532
+ * execute it against this Object's LOCAL facets, and answer with the encoded response
533
+ * envelope. Total by construction — a request that cannot be decoded, or a response that
534
+ * cannot be encoded, answers `PortFailed(PortProtocolError)` instead of throwing, so the
535
+ * transport never has to interpret exceptions as protocol answers.
536
+ */
537
+ const handleEncodedPortRequest = Effect.fn("DoPortRouting.handleEncodedPortRequest")(function* (encoded) {
538
+ const response = yield* decodePortRequest(encoded).pipe(Effect.flatMap(executePortRequest), Effect.catch((error) => Effect.succeed(PortFailed.make({ failure: PortProtocolError.make({ message: boundPortDiagnostic(`The port request could not be decoded: ${error.message}`) }) }))));
539
+ return yield* encodePortResponse(response).pipe(Effect.catch((error) => Effect.succeed(encodedProtocolFailure(`The port response could not be encoded: ${error.message}`))));
540
+ });
541
+ //#endregion
542
+ export { PortTransportError, ThreadPortTransport, executePortRequest, handleEncodedPortRequest, makeLocalSubmissionLookup, portTransportFailure, routedMessageDeliveryStoreLayer, routedSubmissionLedgerLayer, routedThreadStoreLayer, routedWorkerAdmissionLayer, PortRouting_exports as t };
543
+
544
+ //# sourceMappingURL=PortRouting.mjs.map