@moltzap/client 2026.801.3 → 2026.803.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/dist/bounded-map.d.ts +3 -3
- package/dist/bounded-map.js +3 -3
- package/dist/channel-base/index.d.ts +3 -7
- package/dist/channel-base/index.d.ts.map +1 -1
- package/dist/channel-base/index.js +2 -6
- package/dist/channel-base/index.js.map +1 -1
- package/dist/channel-base/reply-guard.d.ts +52 -0
- package/dist/channel-base/reply-guard.d.ts.map +1 -0
- package/dist/channel-base/reply-guard.js +78 -0
- package/dist/channel-base/reply-guard.js.map +1 -0
- package/dist/channel-core-test-support.d.ts +5 -29
- package/dist/channel-core-test-support.d.ts.map +1 -1
- package/dist/channel-core-test-support.js +2 -92
- package/dist/channel-core-test-support.js.map +1 -1
- package/dist/channel-core.d.ts +130 -244
- package/dist/channel-core.d.ts.map +1 -1
- package/dist/channel-core.js +181 -505
- package/dist/channel-core.js.map +1 -1
- package/dist/cli/commands/start.d.ts +1 -5
- package/dist/cli/commands/start.d.ts.map +1 -1
- package/dist/cli/commands/start.js +0 -3
- package/dist/cli/commands/start.js.map +1 -1
- package/dist/harness-mcp-server.d.ts +19 -0
- package/dist/harness-mcp-server.d.ts.map +1 -0
- package/dist/harness-mcp-server.js +105 -0
- package/dist/harness-mcp-server.js.map +1 -0
- package/dist/harness-mcp-wire.d.ts +21 -0
- package/dist/harness-mcp-wire.d.ts.map +1 -0
- package/dist/harness-mcp-wire.js +48 -0
- package/dist/harness-mcp-wire.js.map +1 -0
- package/dist/index.d.ts +1 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -3
- package/dist/index.js.map +1 -1
- package/dist/local-daemon-rpc.d.ts +99 -178
- package/dist/local-daemon-rpc.d.ts.map +1 -1
- package/dist/local-daemon-rpc.js +8 -10
- package/dist/local-daemon-rpc.js.map +1 -1
- package/dist/moltzapd.d.ts +37 -0
- package/dist/moltzapd.d.ts.map +1 -0
- package/dist/moltzapd.js +64 -0
- package/dist/moltzapd.js.map +1 -0
- package/dist/notification/__tests__/subscribe-signatures.types-check.d.ts +14 -14
- package/dist/notification/__tests__/subscribe-signatures.types-check.d.ts.map +1 -1
- package/dist/notification/__tests__/subscribe-signatures.types-check.js +5 -5
- package/dist/notification/__tests__/subscribe-signatures.types-check.js.map +1 -1
- package/dist/service-local-daemon.d.ts +1 -1
- package/dist/service-local-daemon.d.ts.map +1 -1
- package/dist/service-local-daemon.js +2 -4
- package/dist/service-local-daemon.js.map +1 -1
- package/dist/service.d.ts +16 -29
- package/dist/service.d.ts.map +1 -1
- package/dist/service.js +41 -52
- package/dist/service.js.map +1 -1
- package/dist/test-utils/channel-service-fixture.d.ts +1 -3
- package/dist/test-utils/channel-service-fixture.d.ts.map +1 -1
- package/dist/test-utils/channel-service-fixture.js +2 -22
- package/dist/test-utils/channel-service-fixture.js.map +1 -1
- package/dist/test-utils/ids.d.ts +0 -13
- package/dist/test-utils/ids.d.ts.map +1 -1
- package/dist/test-utils/ids.js +1 -16
- package/dist/test-utils/ids.js.map +1 -1
- package/dist/test-utils/index.d.ts +1 -1
- package/dist/test-utils/index.d.ts.map +1 -1
- package/dist/test-utils/index.js +1 -1
- package/dist/test-utils/index.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +6 -3
- package/dist/app-client.d.ts +0 -5
- package/dist/app-client.d.ts.map +0 -1
- package/dist/app-client.js +0 -3
- package/dist/app-client.js.map +0 -1
- package/dist/channel-base/lease-guard.d.ts +0 -31
- package/dist/channel-base/lease-guard.d.ts.map +0 -1
- package/dist/channel-base/lease-guard.js +0 -44
- package/dist/channel-base/lease-guard.js.map +0 -1
- package/dist/channel-base/lease-store.d.ts +0 -48
- package/dist/channel-base/lease-store.d.ts.map +0 -1
- package/dist/channel-base/lease-store.js +0 -77
- package/dist/channel-base/lease-store.js.map +0 -1
- package/dist/channel-base/lease.d.ts +0 -96
- package/dist/channel-base/lease.d.ts.map +0 -1
- package/dist/channel-base/lease.js +0 -106
- package/dist/channel-base/lease.js.map +0 -1
package/dist/channel-core.d.ts
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Channel core: serialized inbound turn delivery over a MoltZapService.
|
|
3
|
+
* Owns the inbound queue, same-conversation coalescing, the interceptor
|
|
4
|
+
* gate, the per-turn timeout, and channel teardown; enrichment lives in
|
|
5
|
+
* channel-core-enrichment.ts.
|
|
3
6
|
*/
|
|
4
7
|
import { Effect } from "effect";
|
|
5
8
|
import type { ConversationId } from "@moltzap/protocol/conversation";
|
|
6
|
-
import type { LeaseId } from "@moltzap/protocol/message/dispatch";
|
|
7
9
|
import type { Message } from "@moltzap/protocol/message";
|
|
8
10
|
import type { CrossConversationEntry, CrossConvMessage, ServiceRpcError } from "./service.js";
|
|
9
11
|
/** Describes enriched sender. */
|
|
@@ -37,7 +39,7 @@ export interface EnrichedInboundMessage {
|
|
|
37
39
|
contextBlocks: ContextBlocks;
|
|
38
40
|
/**
|
|
39
41
|
* Present when multiple queued messages from the same conversation were
|
|
40
|
-
* coalesced into this single
|
|
42
|
+
* coalesced into this single turn. Includes the primary message first.
|
|
41
43
|
*/
|
|
42
44
|
coalescedMessages?: ReadonlyArray<{
|
|
43
45
|
id: string;
|
|
@@ -45,63 +47,6 @@ export interface EnrichedInboundMessage {
|
|
|
45
47
|
text: string;
|
|
46
48
|
createdAt: string;
|
|
47
49
|
}>;
|
|
48
|
-
/** Lease that authorizes a runtime reply for this dispatch, when present. */
|
|
49
|
-
dispatchLeaseId?: LeaseId;
|
|
50
|
-
}
|
|
51
|
-
/** Describes pending dispatch message. */
|
|
52
|
-
export interface PendingDispatchMessage {
|
|
53
|
-
messageId: string;
|
|
54
|
-
conversationId: string;
|
|
55
|
-
senderAgentId: string;
|
|
56
|
-
createdAt: string;
|
|
57
|
-
receivedAt: string;
|
|
58
|
-
parts?: Message["parts"];
|
|
59
|
-
}
|
|
60
|
-
/** Describes dispatch admission request. */
|
|
61
|
-
export interface DispatchAdmissionRequest {
|
|
62
|
-
message: Message;
|
|
63
|
-
conversationId: string;
|
|
64
|
-
senderAgentId: string;
|
|
65
|
-
attempt: number;
|
|
66
|
-
receivedAt: string;
|
|
67
|
-
pending: readonly PendingDispatchMessage[];
|
|
68
|
-
}
|
|
69
|
-
/** Represents dispatch admission decision values. */
|
|
70
|
-
export type DispatchAdmissionDecision = {
|
|
71
|
-
_tag: "grant";
|
|
72
|
-
leaseId?: LeaseId;
|
|
73
|
-
leaseTimeoutMs?: number;
|
|
74
|
-
dispatchMessageId?: string;
|
|
75
|
-
} | {
|
|
76
|
-
_tag: "deny";
|
|
77
|
-
reason?: string;
|
|
78
|
-
} | {
|
|
79
|
-
_tag: "hold";
|
|
80
|
-
reason?: string;
|
|
81
|
-
};
|
|
82
|
-
/**
|
|
83
|
-
* Server → recipient `agent/dispatch/released` notification payload (the
|
|
84
|
-
* verdict). Mirrors `NotificationParamsOf<typeof DispatchRelease>` from
|
|
85
|
-
* the protocol, kept structurally typed here so this module does not
|
|
86
|
-
* need a direct protocol descriptor import (the channel core stays
|
|
87
|
-
* descriptor-free; the wire shape is asserted by the service module).
|
|
88
|
-
*/
|
|
89
|
-
export interface DispatchReleaseFrame {
|
|
90
|
-
readonly dispatchId: string;
|
|
91
|
-
readonly leaseId: LeaseId;
|
|
92
|
-
readonly verdict: {
|
|
93
|
-
readonly decision: "grant";
|
|
94
|
-
readonly leaseId?: LeaseId;
|
|
95
|
-
readonly leaseTimeoutMs?: number;
|
|
96
|
-
readonly dispatchMessageId?: string;
|
|
97
|
-
} | {
|
|
98
|
-
readonly decision: "deny";
|
|
99
|
-
readonly reason?: string;
|
|
100
|
-
} | {
|
|
101
|
-
readonly decision: "hold";
|
|
102
|
-
readonly reason?: string;
|
|
103
|
-
};
|
|
104
|
-
readonly leaseTimeoutMs?: number;
|
|
105
50
|
}
|
|
106
51
|
/** The subset of MoltZapService that MoltZapChannelCore needs. */
|
|
107
52
|
export interface ChannelService {
|
|
@@ -110,12 +55,15 @@ export interface ChannelService {
|
|
|
110
55
|
message: Message;
|
|
111
56
|
}) => void): void;
|
|
112
57
|
on(event: "disconnect", handler: () => void): void;
|
|
113
|
-
on(event: "dispatchRelease", handler: (frame: DispatchReleaseFrame) => void): void;
|
|
114
58
|
connect(): Effect.Effect<unknown, ServiceRpcError>;
|
|
59
|
+
/**
|
|
60
|
+
* Effectful teardown for scoped process owners, which need the service's
|
|
61
|
+
* transports closed before the scope's release completes. Services that
|
|
62
|
+
* only offer the fire-and-forget {@link ChannelService.close} omit it.
|
|
63
|
+
*/
|
|
64
|
+
shutdown?(): Effect.Effect<void>;
|
|
115
65
|
close(): void;
|
|
116
|
-
send(conversationId: ConversationId, text: string,
|
|
117
|
-
dispatchLeaseId?: LeaseId;
|
|
118
|
-
}): Effect.Effect<void, ServiceRpcError>;
|
|
66
|
+
send(conversationId: ConversationId, text: string): Effect.Effect<void, ServiceRpcError>;
|
|
119
67
|
getConversation(convId: string): {
|
|
120
68
|
type: string;
|
|
121
69
|
name?: string;
|
|
@@ -134,36 +82,30 @@ export interface ChannelService {
|
|
|
134
82
|
messages: CrossConvMessage[];
|
|
135
83
|
commit: () => void;
|
|
136
84
|
};
|
|
137
|
-
/**
|
|
138
|
-
* Issue `agent/dispatch/request` and receive the immediate
|
|
139
|
-
* `{leaseId, dispatchId}` ack. The verdict arrives asynchronously
|
|
140
|
-
* via the `dispatchRelease` event.
|
|
141
|
-
*
|
|
142
|
-
* The argument shape mirrors `ParamsOf<DispatchRequest>` from the
|
|
143
|
-
* protocol (the channel core does not depend on the protocol
|
|
144
|
-
* descriptor, hence the structural shape duplicated here).
|
|
145
|
-
*
|
|
146
|
-
* Optional: when undefined (e.g. Unauthenticated test fakes), the
|
|
147
|
-
* channel core falls back to default-grant — every inbound message
|
|
148
|
-
* dispatches without admission.
|
|
149
|
-
*/
|
|
150
|
-
requestDispatch?(params: {
|
|
151
|
-
readonly conversationId: string;
|
|
152
|
-
readonly messageId: string;
|
|
153
|
-
readonly senderAgentId: string;
|
|
154
|
-
readonly parts?: readonly unknown[];
|
|
155
|
-
readonly receivedAt?: string;
|
|
156
|
-
readonly pending?: readonly unknown[];
|
|
157
|
-
readonly attempt?: number;
|
|
158
|
-
}): Effect.Effect<{
|
|
159
|
-
readonly leaseId: LeaseId;
|
|
160
|
-
readonly dispatchId: string;
|
|
161
|
-
}, ServiceRpcError>;
|
|
162
85
|
}
|
|
163
86
|
/** Configures channel core. */
|
|
164
87
|
export interface ChannelCoreOptions {
|
|
165
88
|
service: ChannelService;
|
|
166
|
-
|
|
89
|
+
/**
|
|
90
|
+
* Wall-clock bound on one handler invocation. On expiry the turn is
|
|
91
|
+
* abandoned and the consumer keeps draining.
|
|
92
|
+
*
|
|
93
|
+
* Unset means unbounded, which is the safe default for runtimes whose
|
|
94
|
+
* turns legitimately run for minutes: nothing else can interrupt the
|
|
95
|
+
* handler, so a bound that is too tight silently drops real work. The
|
|
96
|
+
* cost of leaving it unset is that a hung handler stalls the serial
|
|
97
|
+
* drain forever — set it for runtimes that can wedge.
|
|
98
|
+
*
|
|
99
|
+
* The bound covers the handler only. Enrichment and
|
|
100
|
+
* {@link ChannelCoreOptions.inboundInterceptor} run outside it.
|
|
101
|
+
*/
|
|
102
|
+
turnTimeoutMs?: number;
|
|
103
|
+
/**
|
|
104
|
+
* Endpoint-side gate consulted once per coalesced turn, after enrichment
|
|
105
|
+
* and before the handler. Unset is passthrough: every turn is delivered
|
|
106
|
+
* and the inbound path does no extra work.
|
|
107
|
+
*/
|
|
108
|
+
inboundInterceptor?: InboundInterceptor;
|
|
167
109
|
}
|
|
168
110
|
/**
|
|
169
111
|
* Handler invoked for every enriched inbound message. Returns an Effect so the
|
|
@@ -173,10 +115,47 @@ export interface ChannelCoreOptions {
|
|
|
173
115
|
*/
|
|
174
116
|
export type InboundHandler<E = unknown> = (msg: EnrichedInboundMessage) => Effect.Effect<void, E>;
|
|
175
117
|
/**
|
|
176
|
-
*
|
|
177
|
-
*
|
|
178
|
-
*
|
|
179
|
-
*
|
|
118
|
+
* Verdict an {@link InboundInterceptor} returns for one coalesced turn.
|
|
119
|
+
*
|
|
120
|
+
* The union is closed at deliver and drop on purpose: there is no hold or
|
|
121
|
+
* delay verdict. An interceptor is an Effect, so pacing is expressed by
|
|
122
|
+
* suspending inside it — an ambient Clock sleep, a semaphore, a gate the
|
|
123
|
+
* embedder opens later — and the verdict says only whether the turn runs. A
|
|
124
|
+
* hold verdict would ask the core to park this turn and start the next one,
|
|
125
|
+
* which is the multi-turn concurrency the single consumer fiber exists to
|
|
126
|
+
* prevent.
|
|
127
|
+
*/
|
|
128
|
+
export type InboundInterceptDecision = {
|
|
129
|
+
readonly _tag: "deliver";
|
|
130
|
+
} | {
|
|
131
|
+
readonly _tag: "drop";
|
|
132
|
+
readonly reason?: string;
|
|
133
|
+
};
|
|
134
|
+
/**
|
|
135
|
+
* Gate the embedder installs between enrichment and the handler. It receives
|
|
136
|
+
* the newest message of the coalesced batch — a gate deciding whether a turn
|
|
137
|
+
* is still worth running cares about the latest thing said — and its verdict
|
|
138
|
+
* governs the whole batch.
|
|
139
|
+
*
|
|
140
|
+
* It runs on the single consumer fiber, so suspending inside it delays this
|
|
141
|
+
* turn and every message queued behind it, and `turnTimeoutMs` does not bound
|
|
142
|
+
* that suspension. An interceptor that never resumes stalls the drain
|
|
143
|
+
* permanently.
|
|
144
|
+
*
|
|
145
|
+
* A defect, a failure, or a synchronous throw delivers. An embedder bug in a
|
|
146
|
+
* gate must not silently black-hole a production channel: a channel that
|
|
147
|
+
* over-delivers announces itself, one that has gone quiet looks like a network
|
|
148
|
+
* problem for hours.
|
|
149
|
+
*/
|
|
150
|
+
export type InboundInterceptor = (message: Message) => Effect.Effect<InboundInterceptDecision>;
|
|
151
|
+
/**
|
|
152
|
+
* Wraps a `MoltZapService` with message enrichment, one-turn-at-a-time
|
|
153
|
+
* inbound delivery, and a send helper. One core per service —
|
|
154
|
+
* `getContextEntries()` is side-effectful (advances per-conversation
|
|
155
|
+
* markers), so a second core would consume entries the first expected.
|
|
156
|
+
*
|
|
157
|
+
* Turn-taking is entirely endpoint-local: the server delivers every message
|
|
158
|
+
* it accepts, and this core decides when the runtime sees them.
|
|
180
159
|
*
|
|
181
160
|
* Inbound path from wire bytes to user handler:.
|
|
182
161
|
*
|
|
@@ -191,62 +170,30 @@ export type InboundHandler<E = unknown> = (msg: EnrichedInboundMessage) => Effec
|
|
|
191
170
|
* server->>ws: agent/message/received notification
|
|
192
171
|
* ws->>svc: subscribers.dispatch — fanout(message)
|
|
193
172
|
* svc->>core: message listener
|
|
194
|
-
* Note over core: dedup via recordMessageIdIfNew
|
|
195
|
-
* Note over core: consumer fiber — Queue.take
|
|
196
|
-
* core
|
|
197
|
-
*
|
|
198
|
-
* Note over
|
|
199
|
-
*
|
|
200
|
-
*
|
|
201
|
-
*
|
|
202
|
-
* Note over core: log + drop
|
|
203
|
-
* else verdict hold
|
|
204
|
-
* Note over core: parkDispatchWork — front of parked[convId]
|
|
205
|
-
* else verdict grant
|
|
206
|
-
* Note over core: takeCoalescedConversationMessages; drains same-conv from queue + parked
|
|
207
|
-
* Note over core: dispatchWithLease; leaseIdInFlight = leaseId; enrichMessage — sender name, conversation, context entries
|
|
208
|
-
* core->>handler: inboundHandler(enriched)
|
|
209
|
-
* handler-->>core: Effect.void
|
|
210
|
-
* Note over core: handler exceeds leaseTimeoutMs (90s) → DispatchLeaseExpired
|
|
211
|
-
* end
|
|
173
|
+
* Note over core: dedup via recordMessageIdIfNew, drop when stopped or no handler is installed, then Queue.unsafeOffer(inboundQueue, message)
|
|
174
|
+
* Note over core: consumer fiber — Queue.take
|
|
175
|
+
* Note over core: takeCoalescedConversationMessages drains same-conv backlog into one turn
|
|
176
|
+
* Note over core: enrichMessage — sender name, conversation, context entries
|
|
177
|
+
* Note over core: inboundInterceptor — deliver or drop this turn
|
|
178
|
+
* core->>handler: inboundHandler(enriched)
|
|
179
|
+
* handler-->>core: Effect.void
|
|
180
|
+
* Note over core: handler exceeds turnTimeoutMs — turn abandoned, drain continues
|
|
212
181
|
* ```
|
|
213
182
|
*
|
|
214
|
-
*
|
|
215
|
-
*
|
|
216
|
-
* so backpressure within one conversation does not starve others.
|
|
183
|
+
* The single consumer fiber awaits the handler inline, so at most one turn
|
|
184
|
+
* runs at a time and messages that arrive mid-turn wait in the queue.
|
|
217
185
|
*/
|
|
218
186
|
export declare class MoltZapChannelCore {
|
|
219
187
|
private readonly service;
|
|
220
|
-
private readonly
|
|
188
|
+
private readonly turnTimeoutMs?;
|
|
189
|
+
private readonly inboundInterceptor?;
|
|
221
190
|
private connected;
|
|
191
|
+
private stopped;
|
|
222
192
|
private inboundHandler;
|
|
223
193
|
/**
|
|
224
|
-
*
|
|
225
|
-
*
|
|
226
|
-
*
|
|
227
|
-
* strictly serially (one queue, one fiber); concurrent dispatches do
|
|
228
|
-
* not exist on this code path.
|
|
229
|
-
*/
|
|
230
|
-
private leaseIdInFlight?;
|
|
231
|
-
/**
|
|
232
|
-
* Per-lease parking Deferreds for dispatches awaiting their
|
|
233
|
-
* `dispatchRelease` verdict. Settled by the `dispatchRelease` event
|
|
234
|
-
* handler when a matching frame arrives.
|
|
235
|
-
*/
|
|
236
|
-
private readonly pendingDispatchesByLease;
|
|
237
|
-
/**
|
|
238
|
-
* Ring buffer of `dispatchRelease` frames that arrived before the
|
|
239
|
-
* recipient registered its parking Deferred (release-then-ack
|
|
240
|
-
* race). `BoundedMap` refreshes insertion order when a lease is set
|
|
241
|
-
* again and evicts the oldest entry at capacity. Soft-TTL eviction at
|
|
242
|
-
* `DISPATCH_RELEASE_RING_SOFT_TTL_MS` keeps a release without a matching
|
|
243
|
-
* ack from retaining memory.
|
|
244
|
-
*/
|
|
245
|
-
private readonly pendingReleasesByLease;
|
|
246
|
-
private readonly parkedByConversation;
|
|
247
|
-
/**
|
|
248
|
-
* Inbound messages enqueue synchronously; a single forked consumer fiber
|
|
249
|
-
* serialises delivery so handlers execute one-at-a-time in arrival order.
|
|
194
|
+
* Inbound messages with an installed handler enqueue synchronously; a single
|
|
195
|
+
* forked consumer fiber serialises delivery so handlers execute
|
|
196
|
+
* one-at-a-time in arrival order.
|
|
250
197
|
*/
|
|
251
198
|
private readonly inboundQueue;
|
|
252
199
|
private readonly consumerFiber;
|
|
@@ -256,20 +203,6 @@ export declare class MoltZapChannelCore {
|
|
|
256
203
|
private startConsumerFiber;
|
|
257
204
|
private logInboundFailure;
|
|
258
205
|
private registerConnectionListeners;
|
|
259
|
-
private registerDispatchReleaseListener;
|
|
260
|
-
/**
|
|
261
|
-
* Record an incoming `dispatchRelease` frame. If a matching
|
|
262
|
-
* parking Deferred is registered, settle it inline; otherwise
|
|
263
|
-
* insert into the ring buffer for the future ack-side `consume`.
|
|
264
|
-
* Soft-TTL evicts buffered entries whose age exceeds
|
|
265
|
-
* `DISPATCH_RELEASE_RING_SOFT_TTL_MS`; insertion at the hard cap
|
|
266
|
-
* evicts the oldest entry. Both eviction paths warn-log so operators
|
|
267
|
-
* can spot release-without-ack adversarial patterns.
|
|
268
|
-
* @param frame Value supplied to the operation.
|
|
269
|
-
*/
|
|
270
|
-
private recordDispatchRelease;
|
|
271
|
-
private evictDispatchReleaseRing;
|
|
272
|
-
private consumeDispatchRelease;
|
|
273
206
|
/**
|
|
274
207
|
* Replaces any previous handler.
|
|
275
208
|
* @param handler Handler invoked for matching requests.
|
|
@@ -278,115 +211,68 @@ export declare class MoltZapChannelCore {
|
|
|
278
211
|
onDisconnect(handler: () => void): void;
|
|
279
212
|
private fanout;
|
|
280
213
|
connect(): Effect.Effect<void, ServiceRpcError>;
|
|
214
|
+
/**
|
|
215
|
+
* Tear the channel down, resolving only once the service's own transports
|
|
216
|
+
* are closed. A scoped owner releases this before its process exits, so
|
|
217
|
+
* fire-and-forget teardown would leave sockets open past the scope.
|
|
218
|
+
*
|
|
219
|
+
* Service shutdown runs concurrently with interrupting the consumer fiber
|
|
220
|
+
* because an in-flight turn's finalizer can take arbitrarily long. Awaiting
|
|
221
|
+
* the interrupt first would hold the transports open for exactly as long as
|
|
222
|
+
* that finalizer runs.
|
|
223
|
+
* @returns Completion of the channel-owned teardown.
|
|
224
|
+
*/
|
|
281
225
|
disconnect(): Effect.Effect<void>;
|
|
282
226
|
isConnected(): boolean;
|
|
283
227
|
/**
|
|
284
|
-
* Reply into a conversation
|
|
285
|
-
* the caller names another.
|
|
228
|
+
* Reply into a conversation.
|
|
286
229
|
* @param conversationId Value supplied to the operation.
|
|
287
230
|
* @param text Text to process.
|
|
288
|
-
* @param opts Value supplied to the operation.
|
|
289
|
-
* @param opts.dispatchLeaseId Value supplied to the operation.
|
|
290
231
|
* @returns The send result.
|
|
291
232
|
*/
|
|
292
|
-
sendReply(conversationId: ConversationId, text: string,
|
|
293
|
-
|
|
294
|
-
}): Effect.Effect<void, ServiceRpcError>;
|
|
295
|
-
private takeDispatchCandidate;
|
|
296
|
-
private parkDispatchWork;
|
|
233
|
+
sendReply(conversationId: ConversationId, text: string): Effect.Effect<void, ServiceRpcError>;
|
|
234
|
+
private runInboundTurn;
|
|
297
235
|
/**
|
|
298
|
-
*
|
|
299
|
-
*
|
|
300
|
-
*
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
*
|
|
305
|
-
*
|
|
306
|
-
*
|
|
307
|
-
*
|
|
308
|
-
*
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
*
|
|
314
|
-
*
|
|
315
|
-
*
|
|
316
|
-
*
|
|
317
|
-
*
|
|
318
|
-
* AWAITING_RELEASE --> GRANTED : verdict grant
|
|
319
|
-
* AWAITING_RELEASE --> DENIED : verdict deny
|
|
320
|
-
* AWAITING_RELEASE --> HELD : verdict hold
|
|
321
|
-
* HELD : parkDispatchWork — re-queued at parked[convId] front
|
|
322
|
-
* GRANTED : proceed to enrichment
|
|
323
|
-
* DENIED : drop message — consumer fiber continues
|
|
324
|
-
* GRANTED --> IN_FLIGHT : dispatchWithLease
|
|
325
|
-
* IN_FLIGHT : leaseIdInFlight set; handler executing; lease authorizes one agent/message/send
|
|
326
|
-
* IN_FLIGHT --> CONSUMED : handler returns within leaseTimeoutMs; server marks via dispatchLeaseId
|
|
327
|
-
* IN_FLIGHT --> EXPIRED : handler exceeds leaseTimeoutMs; DispatchLeaseExpired logged
|
|
328
|
-
* CONSUMED --> [*]
|
|
329
|
-
* DENIED --> [*]
|
|
330
|
-
* EXPIRED --> [*]
|
|
331
|
-
* ```
|
|
332
|
-
*
|
|
333
|
-
* `HELD` re-enters the queue at the parked-front so the same
|
|
334
|
-
* conversation gets the next dispatch attempt without starving
|
|
335
|
-
* other conversations.
|
|
336
|
-
*
|
|
337
|
-
* When the service has no `requestDispatch` (test fakes that don't
|
|
338
|
-
* exercise admission), default-grant.
|
|
339
|
-
*
|
|
340
|
-
* On request error or release wait timeout, fail-closed with a
|
|
341
|
-
* synthetic deny verdict. The lease (if minted server-side) ages
|
|
342
|
-
* out via the post-grant TTL or LeaseRegistry's
|
|
343
|
-
* abandon-on-disconnect path; nothing here re-issues.
|
|
344
|
-
* @param work Value supplied to the operation.
|
|
345
|
-
* @returns The dispatch admission result.
|
|
236
|
+
* Consult the interceptor for this turn, if one is installed.
|
|
237
|
+
* @param messages The coalesced batch, primary first.
|
|
238
|
+
* @returns Whether the handler runs for this batch.
|
|
239
|
+
*/
|
|
240
|
+
private interceptTurn;
|
|
241
|
+
/**
|
|
242
|
+
* Apply a verdict, logging the drops at debug so a quiet channel can be
|
|
243
|
+
* traced back to its gate.
|
|
244
|
+
* @param newest Message the interceptor judged.
|
|
245
|
+
* @param decision Verdict for the whole coalesced batch.
|
|
246
|
+
* @returns Whether the handler runs.
|
|
247
|
+
*/
|
|
248
|
+
private applyInterceptDecision;
|
|
249
|
+
private logInterceptorFailure;
|
|
250
|
+
/**
|
|
251
|
+
* Await the user handler, bounded by `turnTimeoutMs` when it is set.
|
|
252
|
+
* @param handler Installed inbound handler.
|
|
253
|
+
* @param enriched Enriched form of the coalesced batch.
|
|
254
|
+
* @param primary Message that opened this turn.
|
|
255
|
+
* @returns Whether the handler ran to completion.
|
|
346
256
|
*/
|
|
347
|
-
private
|
|
257
|
+
private awaitHandlerTurn;
|
|
348
258
|
/**
|
|
349
|
-
*
|
|
350
|
-
*
|
|
351
|
-
*
|
|
352
|
-
*
|
|
353
|
-
*
|
|
354
|
-
* @param work Value supplied to the operation.
|
|
355
|
-
* @param leaseId Value supplied to the operation.
|
|
356
|
-
* @returns The buffered result.
|
|
259
|
+
* Drain every queued message for the primary's conversation into one turn,
|
|
260
|
+
* leaving other conversations queued in arrival order. Coalescing keeps a
|
|
261
|
+
* burst in one conversation from costing one turn per message.
|
|
262
|
+
* @param primary Message that opened this turn.
|
|
263
|
+
* @returns The messages belonging to this turn, primary first.
|
|
357
264
|
*/
|
|
358
|
-
private awaitDispatchRelease;
|
|
359
|
-
private projectVerdict;
|
|
360
|
-
private projectGrantVerdict;
|
|
361
|
-
private static denyDecision;
|
|
362
|
-
private static holdDecision;
|
|
363
|
-
private dispatchInboundWork;
|
|
364
|
-
private handleDispatchDecision;
|
|
365
|
-
private dispatchGrantedWork;
|
|
366
|
-
private messagesForGrantedDispatch;
|
|
367
|
-
private runGrantedDispatch;
|
|
368
|
-
private dispatchWithLease;
|
|
369
|
-
private static leaseTimeoutMs;
|
|
370
|
-
private handleDispatchFailure;
|
|
371
|
-
private holdDispatchWork;
|
|
372
|
-
private logDispatchTargetUnavailable;
|
|
373
|
-
private logDispatchStart;
|
|
374
|
-
private logDispatchLeaseExpired;
|
|
375
|
-
private logDispatchCompleted;
|
|
376
|
-
private logDeniedDispatch;
|
|
377
|
-
private pendingDispatchSnapshot;
|
|
378
265
|
private takeCoalescedConversationMessages;
|
|
379
266
|
/**
|
|
380
267
|
* Stateless enrichment helper. Falls back to `sender.id` if
|
|
381
268
|
* `resolveAgentName` throws (e.g. Service not yet connected).
|
|
382
269
|
* @param service Value supplied to the operation.
|
|
383
270
|
* @param messageOrMessages Value supplied to the operation.
|
|
384
|
-
* @returns The
|
|
271
|
+
* @returns The enriched message and its context-commit callback.
|
|
385
272
|
*/
|
|
386
273
|
static enrichMessage(service: ChannelService, messageOrMessages: Message | readonly Message[]): Effect.Effect<{
|
|
387
274
|
enriched: EnrichedInboundMessage;
|
|
388
275
|
commitContext?: () => void;
|
|
389
276
|
}>;
|
|
390
|
-
private dispatchInboundEffect;
|
|
391
277
|
}
|
|
392
278
|
//# sourceMappingURL=channel-core.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"channel-core.d.ts","sourceRoot":"","sources":["../src/channel-core.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"channel-core.d.ts","sourceRoot":"","sources":["../src/channel-core.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAA0B,MAAM,EAAwB,MAAM,QAAQ,CAAC;AAC9E,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gCAAgC,CAAC;AACrE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,2BAA2B,CAAC;AACzD,OAAO,KAAK,EACV,sBAAsB,EACtB,gBAAgB,EAChB,eAAe,EAChB,MAAM,cAAc,CAAC;AAGtB,iCAAiC;AACjC,MAAM,WAAW,cAAc;IAC7B,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;CACd;AAED,4CAA4C;AAC5C,MAAM,WAAW,wBAAwB;IACvC,IAAI,EAAE,IAAI,GAAG,OAAO,CAAC;IACrB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,6CAA6C;IAC7C,YAAY,EAAE,MAAM,EAAE,CAAC;CACxB;AAED,gCAAgC;AAChC,MAAM,WAAW,aAAa;IAC5B,aAAa,CAAC,EAAE,wBAAwB,CAAC;IACzC,iBAAiB,CAAC,EAAE,sBAAsB,EAAE,CAAC;IAC7C,yBAAyB,CAAC,EAAE,gBAAgB,EAAE,CAAC;CAChD;AAED,0CAA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