@anureo/sdk 0.0.0-stage → 0.3.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/LICENSE +201 -0
- package/README.md +185 -2
- package/package.json +66 -4
- package/src/adapter/identity.d.ts +41 -0
- package/src/adapter/identity.js +71 -0
- package/src/client-options.d.ts +71 -0
- package/src/client-options.js +0 -0
- package/src/client.d.ts +106 -0
- package/src/client.js +254 -0
- package/src/diagnostics/errors.d.ts +15 -0
- package/src/diagnostics/errors.js +59 -0
- package/src/diagnostics/events.d.ts +46 -0
- package/src/diagnostics/events.js +47 -0
- package/src/diagnostics.d.ts +20 -0
- package/src/diagnostics.js +56 -0
- package/src/errors.d.ts +48 -0
- package/src/errors.js +63 -0
- package/src/index.d.ts +27 -0
- package/src/index.js +23 -0
- package/src/lifecycle/approval.d.ts +16 -0
- package/src/lifecycle/approval.js +18 -0
- package/src/lifecycle/deferred.d.ts +10 -0
- package/src/lifecycle/deferred.js +12 -0
- package/src/lifecycle/errors.d.ts +18 -0
- package/src/lifecycle/errors.js +45 -0
- package/src/lifecycle/events.d.ts +35 -0
- package/src/lifecycle/events.js +141 -0
- package/src/lifecycle/execution-observation.d.ts +33 -0
- package/src/lifecycle/execution-observation.js +0 -0
- package/src/lifecycle/immutable.d.ts +12 -0
- package/src/lifecycle/immutable.js +28 -0
- package/src/lifecycle/input.d.ts +9 -0
- package/src/lifecycle/input.js +19 -0
- package/src/lifecycle/interactions.d.ts +129 -0
- package/src/lifecycle/interactions.js +282 -0
- package/src/lifecycle/limits.d.ts +7 -0
- package/src/lifecycle/limits.js +13 -0
- package/src/lifecycle/result.d.ts +77 -0
- package/src/lifecycle/result.js +213 -0
- package/src/lifecycle/value.d.ts +4 -0
- package/src/lifecycle/value.js +5 -0
- package/src/ports.d.ts +224 -0
- package/src/ports.js +0 -0
- package/src/privacy/file-change-limits.d.ts +20 -0
- package/src/privacy/file-change-limits.js +124 -0
- package/src/privacy/secrets.d.ts +205 -0
- package/src/privacy/secrets.js +564 -0
- package/src/process.d.ts +92 -0
- package/src/process.js +331 -0
- package/src/queue.d.ts +143 -0
- package/src/queue.js +266 -0
- package/src/request.d.ts +28 -0
- package/src/request.js +81 -0
- package/src/requests/guard.d.ts +15 -0
- package/src/requests/guard.js +93 -0
- package/src/session.d.ts +459 -0
- package/src/session.js +1135 -0
- package/src/structured-output/adapter.d.ts +8 -0
- package/src/structured-output/adapter.js +54 -0
- package/src/structured-output/bridge.d.ts +81 -0
- package/src/structured-output/bridge.js +274 -0
- package/src/structured-output/errors.d.ts +17 -0
- package/src/structured-output/errors.js +31 -0
- package/src/structured-output/limits.d.ts +19 -0
- package/src/structured-output/limits.js +0 -0
- package/src/structured-output/schema.d.ts +20 -0
- package/src/structured-output/schema.js +122 -0
- package/src/structured-output/session.d.ts +329 -0
- package/src/structured-output/session.js +846 -0
- package/src/structured-output/stdio.mjs +83 -0
- package/src/structured-output/tool.d.ts +38 -0
- package/src/structured-output/tool.js +34 -0
- package/src/turn.d.ts +75 -0
- package/src/turn.js +95 -0
- package/src/types.d.ts +62 -0
- package/src/types.js +0 -0
package/src/session.d.ts
ADDED
|
@@ -0,0 +1,459 @@
|
|
|
1
|
+
import { type AhpEvent, type AhpEventPayload, type AhpRequestMap, type AhpResultMap, type Capabilities, type InteractionRequested, type InteractionResponse, type SessionBinding, type SessionOpenParams, type SessionState } from '@anureo/protocol';
|
|
2
|
+
import type { ClientOptions, SubmitOptions } from "./client-options.js";
|
|
3
|
+
import type { BackendSession, EventScope, NativeInteractionResponder, SessionEventSink, SessionMethod } from "./ports.js";
|
|
4
|
+
import { Turn } from "./turn.js";
|
|
5
|
+
import type { EventSubscriptionOptions, RequestOptions } from "./types.js";
|
|
6
|
+
/**
|
|
7
|
+
* Submit input, dispatch requests and observe events for a session opened through Client.
|
|
8
|
+
* Await close to request native close and release resources, or dispose to release observation
|
|
9
|
+
* and backend resources with native stop unconfirmed. Client.dispose also releases its sessions.
|
|
10
|
+
*/
|
|
11
|
+
export declare class Session implements SessionEventSink {
|
|
12
|
+
private readonly params;
|
|
13
|
+
private readonly options;
|
|
14
|
+
private readonly createId;
|
|
15
|
+
/**
|
|
16
|
+
* Client.open constructs this sink before starting native open so callbacks and teardown can race
|
|
17
|
+
* attachment safely. Clone initial state, allocate stream identity and install privacy/interaction
|
|
18
|
+
* hooks without acquiring a backend. ID generation or cloning can throw; Client owns later disposal.
|
|
19
|
+
*/
|
|
20
|
+
constructor(params: SessionOpenParams, options: ClientOptions, capabilities: Capabilities, createId: () => string);
|
|
21
|
+
/**
|
|
22
|
+
* Read the stable session ID used in request and event envelopes.
|
|
23
|
+
*/
|
|
24
|
+
get id(): string;
|
|
25
|
+
/**
|
|
26
|
+
* Read a detached, frozen copy of the current binding. Its native reference may change after
|
|
27
|
+
* a revert or a native state update. Cloning failures throw synchronously.
|
|
28
|
+
*/
|
|
29
|
+
get binding(): Readonly<SessionBinding>;
|
|
30
|
+
/**
|
|
31
|
+
* Capture the current binding and the original working directory for Client.sessions.resume or
|
|
32
|
+
* Client.sessions.fork. Cloning failures throw synchronously.
|
|
33
|
+
*/
|
|
34
|
+
get reference(): Readonly<{
|
|
35
|
+
binding: SessionBinding;
|
|
36
|
+
cwd: string;
|
|
37
|
+
}>;
|
|
38
|
+
/**
|
|
39
|
+
* Read a detached, frozen copy of the session's current capabilities before choosing an operation.
|
|
40
|
+
* Cloning failures throw synchronously.
|
|
41
|
+
*/
|
|
42
|
+
get capabilities(): Readonly<Capabilities>;
|
|
43
|
+
/**
|
|
44
|
+
* Read a frozen, privacy-filtered copy of the currently admitted state without waiting for
|
|
45
|
+
* the event queue. Projection or cloning failures throw synchronously.
|
|
46
|
+
*/
|
|
47
|
+
get snapshot(): Readonly<SessionState>;
|
|
48
|
+
/**
|
|
49
|
+
* OutputSession.publishOutput invokes this optional sink hook before revalidating final JSON.
|
|
50
|
+
* Return marked-secret projection without mutating the candidate; OutputSession owns schema failure
|
|
51
|
+
* handling and final publication.
|
|
52
|
+
*/
|
|
53
|
+
projectOutput(text: string): string;
|
|
54
|
+
/**
|
|
55
|
+
* Attach the backend, restore active observations and publish initial state. Client.attachSession
|
|
56
|
+
* awaits this before returning a session to the host. Dispose a mismatched or already-closed
|
|
57
|
+
* attachment before rejecting. Adoption or publication failure rejects to Client.open, which
|
|
58
|
+
* owns session cleanup.
|
|
59
|
+
*/
|
|
60
|
+
attach(backend: BackendSession): Promise<void>;
|
|
61
|
+
/**
|
|
62
|
+
* Subscribe to future session events without replay; subscribe before submitting to observe its
|
|
63
|
+
* lifecycle from admission. Each subscription is isolated and bounded; invalid limits throw and later
|
|
64
|
+
* failures reject reads. Consumers must exhaust, return or abort the iterator to release it. Detaching
|
|
65
|
+
* or overflowing this observer does not stop native execution or affect sibling subscriptions.
|
|
66
|
+
*/
|
|
67
|
+
events(options?: EventSubscriptionOptions): AsyncIterable<AhpEvent>;
|
|
68
|
+
/**
|
|
69
|
+
* Client.attachSession supplies this sink to OutputSession, whose event forwarding calls it;
|
|
70
|
+
* Session.bindSubmission, outcome bookkeeping and interaction hooks also await the same ordered path.
|
|
71
|
+
* Clone and enqueue a payload. Resolve once the ordered queue processes it, even when a duplicate
|
|
72
|
+
* is suppressed or observation has since closed. Reject closed admission, serialization, cloning,
|
|
73
|
+
* capacity or processing failures. Overflow and processing failures also end observation.
|
|
74
|
+
*/
|
|
75
|
+
emit(payload: AhpEventPayload, scope?: EventScope): Promise<void>;
|
|
76
|
+
/**
|
|
77
|
+
* A direct adapter sink consumer unable to await publication can use this admission probe. Return
|
|
78
|
+
* false on closure, serialization or capacity failure and invoke fail; true means the immediate
|
|
79
|
+
* checks passed, with emit rejection observed asynchronously. It does not promise successful
|
|
80
|
+
* publication. OutputSession.open supplies its own native-adapter tryEmit forwarding callback.
|
|
81
|
+
*/
|
|
82
|
+
tryEmit(payload: AhpEventPayload, scope?: EventScope): boolean;
|
|
83
|
+
/**
|
|
84
|
+
* Native sink consumers may report association here; onRequestSucceeded awaits it when a receipt
|
|
85
|
+
* contains turnId. Queue submission/bound through emit so event admission orders association against
|
|
86
|
+
* native completion. Publication failures reject; successful association can release submit's Turn
|
|
87
|
+
* before a separate native receipt settles. Wrapped adapters reach the same event path via OutputSession.
|
|
88
|
+
*/
|
|
89
|
+
bindSubmission(submissionId: string, turnId: string): Promise<void>;
|
|
90
|
+
/**
|
|
91
|
+
* Submit text or protocol blocks. Delivery defaults to native, so the adapter may queue the input
|
|
92
|
+
* or join an existing execution. Resolve a Turn as soon as the input is bound to an execution,
|
|
93
|
+
* independently of receipt or terminal timing. Normalization, admission, dispatch and wait failures
|
|
94
|
+
* can reject before association. Use Turn.result for the terminal outcome and dispose the handle
|
|
95
|
+
* when finished observing. Abort or timeout leaves admitted work running.
|
|
96
|
+
*/
|
|
97
|
+
submit(options: SubmitOptions, wait?: RequestOptions): Promise<Turn>;
|
|
98
|
+
/**
|
|
99
|
+
* Hosts start a native review through submitExecution's association lifecycle. Resolve a Turn on
|
|
100
|
+
* binding or reject admission/dispatch/wait failure; caller cancellation leaves admitted work alive.
|
|
101
|
+
* ID generation or option cloning can throw synchronously. The returned observer follows the same
|
|
102
|
+
* disposal and native-control rules as submit.
|
|
103
|
+
*/
|
|
104
|
+
review(options: {
|
|
105
|
+
target: AhpRequestMap['review/start']['target'];
|
|
106
|
+
}, wait?: RequestOptions): Promise<Turn>;
|
|
107
|
+
/**
|
|
108
|
+
* Request interruption for the whole session. Set cancelQueued only if advertised by the session.
|
|
109
|
+
* Resolve the native receipt or reject on capability, dispatch or wait failure. Caller cancellation
|
|
110
|
+
* affects waiting only. Use Turn.result for a terminal execution outcome.
|
|
111
|
+
* Request ID generation can throw synchronously before request is called.
|
|
112
|
+
*/
|
|
113
|
+
interrupt(options?: {
|
|
114
|
+
cancelQueued?: boolean;
|
|
115
|
+
}, wait?: RequestOptions): Promise<AhpResultMap['session/interrupt']>;
|
|
116
|
+
/**
|
|
117
|
+
* Dispatch a typed session request and await its receipt. Matching method/request IDs replay the
|
|
118
|
+
* cached outcome while retained; changed params or a submission reserved by another request reject
|
|
119
|
+
* with a conflict. session/close instead shares its existing close work regardless of request ID.
|
|
120
|
+
* Hosts and context's Turn control callbacks use this entry. Ordinary calls validate
|
|
121
|
+
* wait options before dispatch and return a caller-scoped receipt wait; session/close validates the
|
|
122
|
+
* request first and uses closeRequest's shared teardown. Validation, dispatch and wait failures reject;
|
|
123
|
+
* admitted native work, bookkeeping and cleanup survive cancellation without automatic retries.
|
|
124
|
+
*/
|
|
125
|
+
request<M extends SessionMethod>(method: M, params: AhpRequestMap[M], wait?: RequestOptions): Promise<AhpResultMap[M]>;
|
|
126
|
+
/**
|
|
127
|
+
* Settle a native interaction through a configured handler or manual interaction/respond request.
|
|
128
|
+
* OutputSession.open forwards the adapter's request/responder here. An own key in
|
|
129
|
+
* ClientOptions.interactions enables the kind; undefined selects manual handling and omission rejects
|
|
130
|
+
* it. Notify native rejection for closed/unsupported/handler-capacity cases, otherwise register
|
|
131
|
+
* settlement and publish interaction/requested before scheduling a configured host handler. Return
|
|
132
|
+
* the registry's response after native settlement/publication, or reject its failure. The host handler
|
|
133
|
+
* owns its work; Session aborts its signal on settlement/teardown without cancelling that work.
|
|
134
|
+
*/
|
|
135
|
+
requestInteraction(request: InteractionRequested, responder: NativeInteractionResponder): Promise<InteractionResponse>;
|
|
136
|
+
/**
|
|
137
|
+
* OutputSession.open forwards native settlement reports here; direct adapters can use the sink too.
|
|
138
|
+
* Return InteractionRegistry.resolveExternally's publication promise without invoking the responder.
|
|
139
|
+
* The original interaction wait rejects even for responded because native supplied no response value;
|
|
140
|
+
* unknown/already-resolved IDs are ignored by the registry.
|
|
141
|
+
*/
|
|
142
|
+
resolveInteraction(result: AhpResultMap['interaction/respond']): Promise<void>;
|
|
143
|
+
/**
|
|
144
|
+
* OutputSession forwards adapter observation loss here; emit, tryEmit, rejectNativeResult and cached
|
|
145
|
+
* bookkeeping also invoke it. Idempotently end observation with a safe unknown-outcome SDK error,
|
|
146
|
+
* await interaction cancellation, then attempt backend release while suppressing release-promise
|
|
147
|
+
* rejection. A synchronous disposal throw rejects this call. Native execution stop stays unconfirmed;
|
|
148
|
+
* the first caller can await cleanup without initiating a native interrupt; later calls return early.
|
|
149
|
+
*/
|
|
150
|
+
fail(cause: unknown): Promise<void>;
|
|
151
|
+
/**
|
|
152
|
+
* Request native close and await interaction and backend cleanup. Concurrent close calls share the
|
|
153
|
+
* work. A session whose observation already ended awaits backend release and returns its stored
|
|
154
|
+
* receipt or an unconfirmed-stop receipt. Cleanup failure can reject after native close succeeds.
|
|
155
|
+
* Abort or timeout rejects only this caller's wait.
|
|
156
|
+
* Request ID generation can throw synchronously before closeRequest is called.
|
|
157
|
+
*/
|
|
158
|
+
close(wait?: RequestOptions): Promise<AhpResultMap['session/close']>;
|
|
159
|
+
/**
|
|
160
|
+
* Client.open awaits this on setup/wait failure and Client.dispose awaits it before adapter release;
|
|
161
|
+
* host session consumers may also call it directly. Share teardown and its rejection: end observation,
|
|
162
|
+
* abort handler signals, await interaction cancellation, then release the backend. Native close is
|
|
163
|
+
* caller-owned and execution stop remains unconfirmed; repeated disposal never repeats owned work.
|
|
164
|
+
*/
|
|
165
|
+
dispose(): Promise<void>;
|
|
166
|
+
private backend?;
|
|
167
|
+
private observationFailure?;
|
|
168
|
+
private closed;
|
|
169
|
+
private recovering;
|
|
170
|
+
private closing?;
|
|
171
|
+
private closeReceipt?;
|
|
172
|
+
private disposal?;
|
|
173
|
+
private backendDisposal?;
|
|
174
|
+
private readonly ended;
|
|
175
|
+
private seq;
|
|
176
|
+
private readonly streamId;
|
|
177
|
+
private source;
|
|
178
|
+
private backlog;
|
|
179
|
+
private pendingBytes;
|
|
180
|
+
private totalBytes;
|
|
181
|
+
private readonly hub;
|
|
182
|
+
private readonly executions;
|
|
183
|
+
private readonly submissions;
|
|
184
|
+
private readonly requests;
|
|
185
|
+
private readonly interactions;
|
|
186
|
+
private readonly handlers;
|
|
187
|
+
private handlerCount;
|
|
188
|
+
private readonly secrets;
|
|
189
|
+
private state;
|
|
190
|
+
/**
|
|
191
|
+
* attach and admitEvent call before recomputing status. Replace native state with a detached clone,
|
|
192
|
+
* preserving earlier metadata patches omitted by the snapshot. Clone failure propagates to attachment
|
|
193
|
+
* or ordered publication; callers still own binding validation and active-execution bookkeeping.
|
|
194
|
+
*/
|
|
195
|
+
private adoptState;
|
|
196
|
+
/**
|
|
197
|
+
* Recompute the status and active IDs exposed by snapshot and state events after lifecycle changes.
|
|
198
|
+
* Closure, closing and recovery take precedence over execution activity.
|
|
199
|
+
*/
|
|
200
|
+
private updateStatus;
|
|
201
|
+
/**
|
|
202
|
+
* attach restores active observations here; admitEvent and bindRecord reuse the same execution
|
|
203
|
+
* registry for live events and late associations. Return an existing context or allocate bounded
|
|
204
|
+
* completion/events/results and explicit Turn controls. Reclaim only an eligible terminal snapshot;
|
|
205
|
+
* throw BACKPRESSURE_EXCEEDED if capacity stays pinned. Invalid budgets throw before insertion.
|
|
206
|
+
* Turn owns each observer's cancellation.
|
|
207
|
+
*/
|
|
208
|
+
private context;
|
|
209
|
+
/**
|
|
210
|
+
* context calls under execution-count pressure. Remove at most the oldest eligible terminal
|
|
211
|
+
* execution, subtract its retained bytes and remove its acknowledged submissions. Older unbound
|
|
212
|
+
* inputs pin possible late results; returning without eviction makes context reject capacity instead
|
|
213
|
+
* of silently losing a future association. Existing Turn handles keep their shared context.
|
|
214
|
+
*/
|
|
215
|
+
private reclaimExecution;
|
|
216
|
+
/** emit and tryEmit share the configured count budget, which defaults to 2048 queued events. */
|
|
217
|
+
private maxQueuedEvents;
|
|
218
|
+
/**
|
|
219
|
+
* emit and tryEmit use this shared rule before reserving bytes. Report a frame/pending-byte budget
|
|
220
|
+
* overflow without changing accounting; callers decide whether to reject or return false and fail
|
|
221
|
+
* observation.
|
|
222
|
+
*/
|
|
223
|
+
private eventExceedsByteCapacity;
|
|
224
|
+
/**
|
|
225
|
+
* emit schedules this synchronous phase on source and observes throws through fail. Validate before
|
|
226
|
+
* admitting state changes, then project private content, retain execution results and publish the
|
|
227
|
+
* public event. Ignore duplicate lifecycle events; settle terminal results before ending their stream.
|
|
228
|
+
* Queued work arriving after observation closes is ignored.
|
|
229
|
+
*/
|
|
230
|
+
private publish;
|
|
231
|
+
/**
|
|
232
|
+
* publish calls before any lifecycle mutation. Validate envelope/payload identity and extension
|
|
233
|
+
* support, returning the optional execution ID used for admission and retention. Shape, identity or
|
|
234
|
+
* capability errors throw into emit's failure chain without reserving execution/submission state.
|
|
235
|
+
*/
|
|
236
|
+
private validateEvent;
|
|
237
|
+
/**
|
|
238
|
+
* publish calls after validateEvent and consumes the returned payload/context for privacy projection
|
|
239
|
+
* and retention. Route submission and session changes separately from execution admission; ignored
|
|
240
|
+
* duplicates return undefined. Unknown/conflicting identity or invalid lifecycle transitions throw
|
|
241
|
+
* into emit's observation-failure chain. This phase neither publishes nor settles terminal results.
|
|
242
|
+
*/
|
|
243
|
+
private admitEvent;
|
|
244
|
+
/**
|
|
245
|
+
* admitEvent routes submission/status here before publish can expose it. Reject an unresolved
|
|
246
|
+
* association for rejected/unknown status, retaining unknown outcomes for late binding, then return
|
|
247
|
+
* projected diagnostics. Unknown IDs or projection failures throw into emit's observation-failure
|
|
248
|
+
* chain; acknowledgement remains owned by dispatch bookkeeping.
|
|
249
|
+
*/
|
|
250
|
+
private admitSubmissionStatus;
|
|
251
|
+
/**
|
|
252
|
+
* admitSubmissionStatus calls after any association rejection. Return status/identity unchanged
|
|
253
|
+
* while projecting receipt and error content so private native diagnostics cannot reach observers.
|
|
254
|
+
* Projection errors propagate through admission to emit; public event publication remains with publish.
|
|
255
|
+
*/
|
|
256
|
+
private projectSubmissionStatus;
|
|
257
|
+
/**
|
|
258
|
+
* admitEvent calls with the context for a validated execution event. Enforce native turn/item order,
|
|
259
|
+
* mutating execution-local markers only for admitted transitions. Return false to suppress duplicate
|
|
260
|
+
* turn starts/completions or item completions; throw for invalid transitions. retainEvent owns terminal
|
|
261
|
+
* settlement after privacy projection, so this phase does not finish the execution.
|
|
262
|
+
*/
|
|
263
|
+
private admitExecutionEvent;
|
|
264
|
+
/**
|
|
265
|
+
* admitExecutionEvent delegates item transitions here after payload validation. Require an active
|
|
266
|
+
* execution and reject repeated starts or deltas without a live item. Completion snapshots may
|
|
267
|
+
* introduce an item without a start; suppress repeated completions without changing its markers.
|
|
268
|
+
*/
|
|
269
|
+
private admitItemEvent;
|
|
270
|
+
/**
|
|
271
|
+
* publish passes an admitted public event here before session-wide fanout. Accumulate bounded result
|
|
272
|
+
* content and update shared byte accounting; accumulator/budget errors throw into emit's failure chain.
|
|
273
|
+
* For native completion, record terminal sequence and resolve Turn.result before publishing and ending
|
|
274
|
+
* the execution hub. Session-wide publication and activity recomputation remain with publish.
|
|
275
|
+
*/
|
|
276
|
+
private retainEvent;
|
|
277
|
+
/**
|
|
278
|
+
* The context control callbacks, submitExecution, interrupt and close allocate fresh host request
|
|
279
|
+
* identity here. Return sessionId/requestId from the configured ID source; generator failures throw.
|
|
280
|
+
* Deduplicated dispatch reuses supplied identity rather than generating another request.
|
|
281
|
+
*/
|
|
282
|
+
private requestIdentity;
|
|
283
|
+
/**
|
|
284
|
+
* admitEvent calls for an ordered submission/bound event. Reject conflicting or definitively rejected
|
|
285
|
+
* bindings with PROTOCOL_ERROR; otherwise reuse/allocate the execution and resolve association.
|
|
286
|
+
* submitExecution consumes that promise to construct a Turn independently of native acknowledgement;
|
|
287
|
+
* the caller still owns event publication and dispatch bookkeeping.
|
|
288
|
+
*/
|
|
289
|
+
private bindRecord;
|
|
290
|
+
/**
|
|
291
|
+
* submitExecution uses this on dispatch rejection; onRequestFailed calls after failure-status
|
|
292
|
+
* publication. Reject unresolved association with the original cause and track definitive rejection
|
|
293
|
+
* and acknowledgement. Unknown outcomes stay eligible for late binding; a pending dispatch remains
|
|
294
|
+
* pinned until bookkeeping acknowledges it. A resolved association is never undone.
|
|
295
|
+
*/
|
|
296
|
+
private rejectSubmission;
|
|
297
|
+
/**
|
|
298
|
+
* submitExecution allocates before waiting for association; reserveSubmission also uses it for dispatch
|
|
299
|
+
* admission, including raw requests. Return existing bookkeeping or allocate a binding gate, reclaiming
|
|
300
|
+
* at most one acknowledged rejected/terminal entry under pressure. Throw BACKPRESSURE_EXCEEDED rather
|
|
301
|
+
* than evict unresolved work; callers own reservation, acknowledgement and settlement.
|
|
302
|
+
*/
|
|
303
|
+
private getOrCreateSubmission;
|
|
304
|
+
/**
|
|
305
|
+
* getOrCreateSubmission calls under submission-count pressure. Evict the oldest acknowledged
|
|
306
|
+
* rejection or terminal association, if any. Unknown unbound submissions remain eligible for
|
|
307
|
+
* late binding; getOrCreateSubmission rejects admission if nothing can be reclaimed.
|
|
308
|
+
*/
|
|
309
|
+
private reclaimSubmission;
|
|
310
|
+
/**
|
|
311
|
+
* submit and review return this association wait. Validate before allocating bookkeeping, dispatch
|
|
312
|
+
* independently, then construct a Turn when binding resolves. Observe dispatch rejection separately
|
|
313
|
+
* so the original error reaches an unresolved association while admitted records stay pinned through
|
|
314
|
+
* status publication. Caller abort/deadline ends only waiting; late binding and native work continue.
|
|
315
|
+
* ID generation/cloning failures throw before dispatch; submit converts those throws to rejection.
|
|
316
|
+
*/
|
|
317
|
+
private submitExecution;
|
|
318
|
+
/**
|
|
319
|
+
* submitExecution checks before creating an association gate; dispatchOperation checks every
|
|
320
|
+
* dispatch, including replays. Lifecycle failures take precedence over protocol/capability errors.
|
|
321
|
+
* Callers return these throws as rejected promises before reserving native work.
|
|
322
|
+
*/
|
|
323
|
+
private validateRequestAdmission;
|
|
324
|
+
/**
|
|
325
|
+
* validateRequestAdmission checks lifecycle before protocol and capability admission.
|
|
326
|
+
* Throw for closed/closing/recovery-blocked business calls, retaining explicit interruption and
|
|
327
|
+
* interaction controls during close/recovery plus history and close during recovery. Callers expose
|
|
328
|
+
* these failures without native dispatch; this check changes no state.
|
|
329
|
+
*/
|
|
330
|
+
private assertCallable;
|
|
331
|
+
/**
|
|
332
|
+
* request, submitExecution and closeRequest call before applying their own wait ownership. Validate
|
|
333
|
+
* and detach params, replay matching cached outcomes, admit capacity and reserve submission identity,
|
|
334
|
+
* then cache new work. Admission errors reject before native dispatch; request identity conflicts do
|
|
335
|
+
* not replace cached work. Serialization/cloning can throw to the surrounding caller; host deadlines
|
|
336
|
+
* never cancel the cached outcome or its bookkeeping.
|
|
337
|
+
*/
|
|
338
|
+
private dispatchOperation;
|
|
339
|
+
/**
|
|
340
|
+
* dispatchOperation calls after replay checks and before reserving submission identity. Reclaim at
|
|
341
|
+
* most the oldest settled request, then report whether a new dispatch fits. Unsettled outcomes stay
|
|
342
|
+
* cached even when their host observers have cancelled; a false result becomes BACKPRESSURE_EXCEEDED.
|
|
343
|
+
*/
|
|
344
|
+
private admitRequestCapacity;
|
|
345
|
+
/**
|
|
346
|
+
* dispatchOperation calls only for submission-bearing methods once request-cache capacity is
|
|
347
|
+
* available. Reserve one request ID per submission or throw a conflict/capacity error before native
|
|
348
|
+
* execution. Association alone does not acknowledge dispatch; outcome bookkeeping owns that step.
|
|
349
|
+
*/
|
|
350
|
+
private reserveSubmission;
|
|
351
|
+
/**
|
|
352
|
+
* dispatchOperation returns this shared outcome after admission. Cache before native work starts
|
|
353
|
+
* in a microtask, race that work against observation closure, and observe bookkeeping separately.
|
|
354
|
+
* Replays receive the same receipt/rejection without awaiting binding/status events; bookkeeping
|
|
355
|
+
* failures end observation through fail rather than replace the cached outcome.
|
|
356
|
+
*/
|
|
357
|
+
private cacheRequestOutcome;
|
|
358
|
+
/**
|
|
359
|
+
* cacheRequestOutcome schedules this once per admitted request. Route interaction controls through
|
|
360
|
+
* the registry or await the backend, validate native identity before projecting content, then update
|
|
361
|
+
* request-owned state and return a frozen validated result. Failures reject the cached outcome unless
|
|
362
|
+
* observation closure wins its race; execution and state effects can still finish after that race.
|
|
363
|
+
* The caller owns outcome bookkeeping and never retries native work automatically.
|
|
364
|
+
*/
|
|
365
|
+
private executeRequest;
|
|
366
|
+
/**
|
|
367
|
+
* executeRequest awaits one invocation after request admission. Keep manual interaction responses
|
|
368
|
+
* and cancellations in the registry so they share settlement with automatic handlers; dispatch other
|
|
369
|
+
* methods to the attached backend. Throws/rejections become cached request failures without retries.
|
|
370
|
+
*/
|
|
371
|
+
private invokeRequest;
|
|
372
|
+
/**
|
|
373
|
+
* executeRequest projects only after native-result validation. Redact history before the optional
|
|
374
|
+
* host hook, preserve submission/close receipts, and project other method results. Projection failures
|
|
375
|
+
* reject the cached outcome; executeRequest still owns hook invocation and final result validation.
|
|
376
|
+
*/
|
|
377
|
+
private projectRequestResult;
|
|
378
|
+
/**
|
|
379
|
+
* executeRequest commits projected config, revert-reference and goal results before freezing the
|
|
380
|
+
* returned receipt. Cloning failures reject that request; caller cancellation does not roll back
|
|
381
|
+
* these updates. Other methods leave request-owned state unchanged; events own execution activity.
|
|
382
|
+
*/
|
|
383
|
+
private applyRequestResult;
|
|
384
|
+
/**
|
|
385
|
+
* executeRequest calls before privacy projection or request-owned state changes. Validate protocol
|
|
386
|
+
* shape and submission/steer identities; malformed results call rejectNativeResult, which throws an
|
|
387
|
+
* unknown-outcome protocol error and starts observation teardown. On success the assertion narrows
|
|
388
|
+
* the native value for projection.
|
|
389
|
+
*/
|
|
390
|
+
private validateNativeResult;
|
|
391
|
+
/**
|
|
392
|
+
* validateNativeResult calls for malformed shape or conflicting identity. Start fail without waiting
|
|
393
|
+
* for cleanup, then throw the same unknown-outcome protocol error into executeRequest's rejection.
|
|
394
|
+
* Native effects cannot be inferred safely, so caller-visible failure must not claim definite rejection.
|
|
395
|
+
*/
|
|
396
|
+
private rejectNativeResult;
|
|
397
|
+
/**
|
|
398
|
+
* cacheRequestOutcome registers this success continuation separately from its returned receipt.
|
|
399
|
+
* Acknowledge a retained submission, await receipt-based binding before status, and publish accepted/
|
|
400
|
+
* queued/dispatched disposition while observation remains open. A publication failure goes to the
|
|
401
|
+
* cache's fail observer without replacing the receipt; non-submission outcomes need no bookkeeping.
|
|
402
|
+
*/
|
|
403
|
+
private onRequestSucceeded;
|
|
404
|
+
/**
|
|
405
|
+
* cacheRequestOutcome registers this rejection continuation separately from its returned failure.
|
|
406
|
+
* Mark eligible unknown outcomes as requiring recovery, then publish submission failure before
|
|
407
|
+
* acknowledging it with rejectSubmission. Publication failure goes to the cache's fail observer;
|
|
408
|
+
* unknown outcomes remain available for late binding. Definite submission rejection alone leaves
|
|
409
|
+
* unrelated executions usable.
|
|
410
|
+
*/
|
|
411
|
+
private onRequestFailed;
|
|
412
|
+
/**
|
|
413
|
+
* requestInteraction calls only after requested-event publication. Invoke the supplied host handler
|
|
414
|
+
* with a cloned native request and abort signal, then send its answer through InteractionRegistry.
|
|
415
|
+
* Skip aborted invocation/delivery; release capacity only when host work settles, even after native
|
|
416
|
+
* settlement. Handler/delivery failure cancels an actionable interaction; secondary cancellation
|
|
417
|
+
* errors are observed and suppressed. This scheduling does not return a handler wait to the adapter.
|
|
418
|
+
*/
|
|
419
|
+
private startInteractionHandler;
|
|
420
|
+
/**
|
|
421
|
+
* fail, finishClose and dispose call at their respective teardown stages. Mark closed, reject the
|
|
422
|
+
* closure race and unresolved associations/results, abort handler signals and end unfinished streams.
|
|
423
|
+
* Completed execution snapshots/streams remain intact. Callers own interaction cancellation, backend
|
|
424
|
+
* release and any native close; rejecting observation does not assert execution stopped.
|
|
425
|
+
*/
|
|
426
|
+
private endObservation;
|
|
427
|
+
/**
|
|
428
|
+
* close and request(session/close) return this caller wait around shared close work or, once
|
|
429
|
+
* observation is closed, backend release. Invalid or already-aborted waits reject before either
|
|
430
|
+
* operation starts. Later abort/deadline affects only the caller's wait.
|
|
431
|
+
*/
|
|
432
|
+
private closeRequest;
|
|
433
|
+
/**
|
|
434
|
+
* closeRequest asks for a receipt on an already-closed session. Await backend release and
|
|
435
|
+
* propagate its failure before returning the stored native receipt or an unconfirmed stop.
|
|
436
|
+
*/
|
|
437
|
+
private closedReceipt;
|
|
438
|
+
/**
|
|
439
|
+
* closeRequest starts this once per close attempt. Dispatch before marking the session closing
|
|
440
|
+
* so close itself passes the lifecycle guard. A successful receipt proceeds through finishClose.
|
|
441
|
+
* Dispatch rejection clears the close gate, marks recovery when the outcome is unknown and
|
|
442
|
+
* rejects shared close work with the original cause.
|
|
443
|
+
*/
|
|
444
|
+
private startClose;
|
|
445
|
+
/**
|
|
446
|
+
* startClose registers this on native success and shares its result or cleanup rejection with host
|
|
447
|
+
* waiters. Store the receipt, attempt interaction cancellation then backend release in order, and end
|
|
448
|
+
* observation even if cleanup failed. Throw a safe combined error only after both attempts; native stop
|
|
449
|
+
* confirmation changes unfinished-observation diagnostics without inventing terminal Turn results.
|
|
450
|
+
*/
|
|
451
|
+
private finishClose;
|
|
452
|
+
/**
|
|
453
|
+
* fail, closedReceipt, finishClose and dispose share the backend's returned release promise and its
|
|
454
|
+
* rejection; never infer native stop. A synchronous disposal throw escapes before promise caching.
|
|
455
|
+
* Before attachment the no-op promise does not own a backend arriving later: attach rejects/releases
|
|
456
|
+
* that backend when observation has already closed.
|
|
457
|
+
*/
|
|
458
|
+
private disposeBackend;
|
|
459
|
+
}
|