@arona/core 0.0.1-dev.ff9c398 → 0.0.1-nightly.20261203.1.2

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.
@@ -0,0 +1,721 @@
1
+ import { $ as GONE, A as SessionMessageRef, At as leaseOwnerAt, B as encodeInteractionId, Bt as sessionStateAt, C as MessageSessionStoreShape, Ct as deriveMachineTable, D as SessionErrorCode, Dt as isTerminal, E as SessionConflict, Et as isExpired, F as SessionStoreError, Ft as rootModeModel, G as sessionAlreadyExists, Gt as transition, H as makeSessionId, Ht as targetModeMachine, I as SessionStoreInconsistent, It as rootModel, J as sessionExpired, K as sessionClosed, Kt as transitionOrThrow, L as SessionSweepPage, Lt as sessionAllows, M as SessionPage, Mt as reachableStates, N as SessionPageOptions, Nt as rootMachine, O as SessionExpired, Ot as leaseMachine, P as SessionRepair, Pt as rootModeMachine, Q as storeError, R as StrongMessageSessionStore, Rt as sessionMachine, S as MessageSessionStore, St as canTransition, T as SessionClosed, Tt as interactionModel, U as nowMillis, Ut as targetModeModel, V as isStrongStore, Vt as targetMachine, W as parseInteractionId, Wt as targetModel, X as sessionNotFound, Y as sessionLeaseLost, Z as sessionPageLimit, _ as MAX_INTERACTION_ID_LENGTH, _t as StateMachineTable, a as migrateSqlSessionStore, at as Lease, b as MessageSessionSchema, bt as TargetModeEvent, c as SessionMutation, ct as LeaseState, d as checkSessionMutable, dt as RootEvent, et as Gone, f as isActive, ft as RootMode, g as InteractionIdParts, gt as SessionStatus, h as INTERACTION_ID_PREFIX, ht as SessionEvent, i as applySqlSessionSchema, it as LEASE_FREE, j as SessionNotFound, jt as leaseTransition, k as SessionLeaseLost, kt as leaseModel, l as advanceError, lt as LeaseStatus, m as DEFAULT_SESSION_PAGE_LIMIT, mt as RootState, n as MemoryStore, nt as InteractionEvent, o as sqlSessionStore, ot as LeaseEvent, p as Consistency, pt as RootModeEvent, q as sessionConflict, r as index_d_exports, rt as InteractionState, s as SessionAdvance, st as LeaseEventName, t as FileStore, tt as IllegalTransitionError, u as advanceSession, ut as LeaseTransition, v as MAX_SESSION_PAGE_LIMIT, vt as TargetEvent, w as SessionAlreadyExists, wt as interactionMachine, x as MessageSessionState, xt as TargetState, y as MessageSession, yt as TargetMode, z as asStrongStore, zt as sessionModel } from "./index-DROCSc-k.js";
2
+ import { Cause, Context, Data, Duration, Effect, Exit, Layer, Option, Schema, Scope, Stream, Tracer } from "effect";
3
+ import { OtlpExporter } from "effect/observability";
4
+ import { Component, Renderer, View } from "effect/ui";
5
+ /** Any Effect UI component, with each type parameter defaulted. */
6
+ export type AnyComponent<Name extends string = string, Props = any, Model = any, Msg = any, Events = any, R = any, V extends View.Elements = View.Elements> = Component.Members<Name, Props, Model, Msg, Events, R, V, any>;
7
+ /**
8
+ * The stable error identity and repair hint shared by Arona's tagged errors.
9
+ *
10
+ * Spread into a `Schema.TaggedError` field record so every adapter declares the
11
+ * same optional pair once:
12
+ *
13
+ * ```ts
14
+ * class MyError extends Schema.TaggedError<MyError, Brand>()("MyError", {
15
+ * message: Schema.String,
16
+ * ...CodedErrorFields,
17
+ * }) {}
18
+ * ```
19
+ *
20
+ * `code` is for logs, metrics and API responses; `repair` says what to do next.
21
+ * Tag names and messages stay free to change.
22
+ */
23
+ export declare const CodedErrorFields: {
24
+ readonly code: Schema.optional<Schema.String>;
25
+ readonly repair: Schema.optional<Schema.String>;
26
+ };
27
+ export interface EventBusOptions<A> {
28
+ /** Buffer size for non-critical events. Defaults to 256. */
29
+ readonly capacity?: number;
30
+ /**
31
+ * Critical events (interactions and user messages) are never dropped. They
32
+ * use an unbounded bus, which is safe because their volume is user-driven.
33
+ */
34
+ readonly isCritical: (event: A) => boolean;
35
+ }
36
+ export interface EventBus<A> {
37
+ /** One stream per subscriber, in per-lane order. */
38
+ readonly events: Stream.Stream<A>;
39
+ /** Routes an event to the critical or coalescing lane. */
40
+ publish(event: A): Effect.Effect<void>;
41
+ }
42
+ /**
43
+ * A two-lane event bus.
44
+ *
45
+ * The previous implementation used `PubSub.unbounded` for every gateway and
46
+ * Slack event, so a slow subscriber could grow memory without bound. Critical
47
+ * events keep that guarantee because losing an interaction is worse than
48
+ * memory pressure; high-volume state dispatches use a sliding buffer that keeps
49
+ * the newest events. The merge does not promise ordering between the two lanes;
50
+ * each lane keeps its own order and interactions are handled before they are
51
+ * published.
52
+ */
53
+ export declare const makeEventBus: <A>(options: EventBusOptions<A>) => Effect.Effect<EventBus<A>, never, Scope.Scope>;
54
+ /**
55
+ * A platform-neutral node in a rendered bot tree.
56
+ *
57
+ * Discord and Slack both use mutable trees that the renderer owns. Keeping the
58
+ * shape here means both hosts share the same node semantics and the same
59
+ * interaction bookkeeping.
60
+ */
61
+ export declare class BotNode {
62
+ #private;
63
+ readonly tag: string;
64
+ readonly isText: boolean;
65
+ text: string;
66
+ parent: BotNode | null;
67
+ children: BotNode[];
68
+ attrs: Record<string, string>;
69
+ props: Record<string, unknown>;
70
+ handlers: Readonly<Record<string, View.Handler<unknown, any>>>;
71
+ eventOptions: Readonly<Record<string, View.EventOptions>>;
72
+ dispatch: Renderer.Dispatch | null;
73
+ /** The host-generated id, used for default block/action ids. */
74
+ id: string;
75
+ /** The author's custom id, before Arona wraps it for a session. */
76
+ explicitCustomId: string | null;
77
+ /** The id the platform sends back on an interaction. */
78
+ customId: string | null;
79
+ /** A platform-specific modal already shown for this node. */
80
+ modalShown: boolean;
81
+ constructor(tag: string, id: string, isText?: boolean);
82
+ append(node: BotNode): void;
83
+ insertBefore(node: BotNode, anchor?: BotNode): void;
84
+ detach(): void;
85
+ remove(node: BotNode): void;
86
+ /** The text of this node and its text children. */
87
+ textContent(): string;
88
+ descendants(): Generator<BotNode>;
89
+ }
90
+ /** The prop or attribute a rendered node exposes under `name`. */
91
+ export declare const nodeValue: (node: BotNode, name: string) => unknown;
92
+ /**
93
+ * A deterministic structural fingerprint of one pre-order node list.
94
+ *
95
+ * The host already walks its tree once per commit for interaction ids and
96
+ * routing. Hashing the same list here answers "did the visible tree change?"
97
+ * without serializing the whole Component payload a second time. It covers a
98
+ * superset of what the wire emits (every tag, text, id and prop), so a change
99
+ * is never missed; an occasional extra send is acceptable.
100
+ */
101
+ export declare const fingerprintNodes: (nodes: ReadonlyArray<BotNode>) => string;
102
+ /** A node value rendered as text; numbers and booleans are stringified. */
103
+ export declare const stringValue: (node: BotNode, name: string) => string | undefined;
104
+ /** A node value as a finite number, or `undefined` for empty or invalid input. */
105
+ export declare const numberValue: (node: BotNode, name: string) => number | undefined;
106
+ /** A node value as a boolean; only the string `"false"` is falsy. */
107
+ export declare const booleanValue: (node: BotNode, name: string) => boolean | undefined;
108
+ /** A node value when it is an array. */
109
+ export declare const arrayValue: (node: BotNode, name: string) => ReadonlyArray<unknown> | undefined;
110
+ /** A node array value filtered to its string entries. */
111
+ export declare const stringArrayValue: (node: BotNode, name: string) => ReadonlyArray<string> | undefined;
112
+ /** The session an Arona host stamps onto its generated interaction ids. */
113
+ export interface HostSession {
114
+ readonly id: string;
115
+ readonly version: number;
116
+ }
117
+ export interface BotHostOptions {
118
+ /** The vocabulary name this host renders, such as `discord` or `slack`. */
119
+ readonly name: string;
120
+ /** Prefix for generated ids. Tests can pass a deterministic value. */
121
+ readonly prefix?: string;
122
+ /** Tags that receive a generated interaction id when they are created. */
123
+ readonly interactiveTags?: ReadonlySet<string>;
124
+ }
125
+ /**
126
+ * Shared host operations for node-based bot platforms.
127
+ *
128
+ * The renderer only needs node mutation, events and a commit boundary. Each
129
+ * platform supplies a commit implementation that serializes its tree.
130
+ */
131
+ export declare class BotHost implements Renderer.Host<BotNode> {
132
+ #private;
133
+ readonly container: BotNode;
134
+ readonly elements: ReadonlyArray<string>;
135
+ readonly controlled: ReadonlySet<string>;
136
+ readonly runsMounts = true;
137
+ /** The platform this host serializes for, such as `discord` or `slack`. */
138
+ readonly platform: string;
139
+ protected readonly prefix: string;
140
+ /** How many commits this host has completed. */
141
+ get commits(): number;
142
+ constructor(options: BotHostOptions);
143
+ protected nextId(): string;
144
+ /** The session whose id and version are stamped onto interaction ids. */
145
+ get session(): HostSession | null;
146
+ /** Binds the host to a resumable message session. */
147
+ setSession(session: HostSession | null): void;
148
+ /** Advances the version used by the next commit. */
149
+ setSessionVersion(version: number): void;
150
+ /**
151
+ * Assigns every interactive node its platform-facing custom id.
152
+ *
153
+ * Without a session the id keeps the old host-generated value. With one,
154
+ * auto ids are document-order ordinals and explicit ids keep the author's
155
+ * text as the key, both wrapped with the session and its current version.
156
+ * A restored tree therefore produces the same ids as the state it shows.
157
+ *
158
+ * Returns a message when an id exceeds the platform limit. Callers surface
159
+ * that message as a target failure instead of throwing from the renderer.
160
+ */
161
+ prepareInteractionIds(nodes?: ReadonlyArray<BotNode>): string | undefined;
162
+ /**
163
+ * Marks every interactive node disabled, so a painted copy shows the
164
+ * state without offering controls that cannot route to a live root.
165
+ */
166
+ freeze(nodes?: ReadonlyArray<BotNode>): void;
167
+ /**
168
+ * Marks a commit complete and wakes everyone waiting for the next one.
169
+ * Platform hosts call this once they have serialized their tree.
170
+ */
171
+ protected recordCommit(): void;
172
+ /** Waits until a commit after `after` has run, or the timeout elapses. */
173
+ waitForCommit(after: number, timeoutMs?: number): Effect.Effect<void>;
174
+ /**
175
+ * Every node in document order.
176
+ *
177
+ * Hosts walk the tree several times per commit (ids, routing, serialization).
178
+ * Taking one list and passing it to the other steps keeps those walks in
179
+ * sync and avoids re-traversing the whole tree for each concern.
180
+ */
181
+ nodes(): ReadonlyArray<BotNode>;
182
+ createElement(tag: string): BotNode;
183
+ createText(text: string): BotNode;
184
+ createContainer(): BotNode;
185
+ setText(node: BotNode, text: string): void;
186
+ setAttr(node: BotNode, name: string, value: string | undefined, _previous?: string): void;
187
+ setProp(node: BotNode, name: string, value: unknown): void;
188
+ insertBefore(parent: BotNode, node: BotNode, ref: BotNode | undefined): void;
189
+ remove(node: BotNode): void;
190
+ parentOf(node: BotNode): BotNode | undefined;
191
+ nextOf(node: BotNode): BotNode | undefined;
192
+ setEvents(node: BotNode, handlers: Readonly<Record<string, View.Handler<unknown, any>>>, dispatch: Renderer.Dispatch, options: Readonly<Record<string, View.EventOptions>>): void;
193
+ }
194
+ /** Stable codes for message failures. */
195
+ export declare const MessageErrorCode: {
196
+ readonly send: "message/send";
197
+ readonly closed: "message/closed";
198
+ readonly mount: "message/mount";
199
+ readonly unsupported: "message/unsupported";
200
+ };
201
+ export type MessageErrorCode = (typeof MessageErrorCode)[keyof typeof MessageErrorCode];
202
+ /** What a caller can do about a message failure. */
203
+ export declare const MessageRepair: {
204
+ readonly send: "Retry the edit; a failed send does not advance the message version.";
205
+ readonly closed: "Mount a new message; a closed target cannot send.";
206
+ readonly mount: "Check the application layer and the component tree, then mount again.";
207
+ readonly unsupported: "Use a URL or the Node profile that supports uploaded files.";
208
+ };
209
+ declare const MessageTargetError_base: Schema.Class<MessageTargetError, Schema.TaggedStruct<"MessageTargetError", {
210
+ readonly code: Schema.optional<Schema.String>;
211
+ readonly repair: Schema.optional<Schema.String>;
212
+ readonly message: Schema.String;
213
+ readonly cause: Schema.Defect;
214
+ }>, Cause.YieldableError & {
215
+ readonly brand: unique symbol;
216
+ }>;
217
+ /** A target could not create or edit a platform message. */
218
+ export declare class MessageTargetError extends MessageTargetError_base {}
219
+ /** Builds a target error with its code and repair hint. */
220
+ export declare const messageTargetError: (message: string, cause?: unknown, code?: string, repair?: string) => MessageTargetError;
221
+ /** What a platform target must provide to the shared message lifecycle. */
222
+ export interface MessageTarget<Message, Snapshot> {
223
+ /** The first platform message, once it has been created. */
224
+ readonly ready: Effect.Effect<Message, MessageTargetError>;
225
+ /**
226
+ * Drains queued snapshots while the target is open. The effect stays alive
227
+ * after `close()` so the owning mount scope controls when it ends.
228
+ */
229
+ readonly run: Effect.Effect<never>;
230
+ /** Enqueues the newest snapshot. Safe to call from a host commit. */
231
+ queue(snapshot: Snapshot): void;
232
+ /** Fails the in-flight attempt when the host cannot produce a snapshot. */
233
+ fail(error: MessageTargetError): void;
234
+ /** Stops future sends and fails `ready` if no message was created yet. */
235
+ close(): void;
236
+ /** Stops draining queued snapshots until `resume`. */
237
+ readonly pause?: (() => void) | undefined;
238
+ /** Resumes draining the newest queued snapshot. */
239
+ readonly resume?: (() => void) | undefined;
240
+ }
241
+ /** Scopes a target so `close()` runs when the surrounding scope closes. */
242
+ export declare const acquireMessageTarget: <Message, Snapshot>(target: MessageTarget<Message, Snapshot>) => Effect.Effect<MessageTarget<Message, Snapshot>, never, Scope.Scope>;
243
+ /** The shared target surface used by renderers and tests. */
244
+ export interface BotMessageTarget<Message, Snapshot> extends MessageTarget<Message, Snapshot> {
245
+ /** The platform this target sends to, such as `discord` or `slack`. */
246
+ readonly platform: string;
247
+ /** The first platform message if it already exists. */
248
+ readonly message: Message | null;
249
+ /** The explicit send lifecycle state. */
250
+ readonly state: TargetState;
251
+ /** Resolves once no request is in flight and no snapshot is queued. */
252
+ readonly whenIdle: Effect.Effect<void>;
253
+ /**
254
+ * Sends one snapshot immediately, even while paused, and invalidates the
255
+ * live fingerprint so the next live snapshot is sent after resume.
256
+ */
257
+ readonly paint?: ((snapshot: Snapshot) => Effect.Effect<Message, MessageTargetError>) | undefined;
258
+ }
259
+ export interface BotMessageTargetOptions<Message, Snapshot> {
260
+ readonly platform: string;
261
+ /** Creates the first message or edits the existing one. */
262
+ readonly send: (snapshot: Snapshot) => Effect.Effect<Message, MessageTargetError>;
263
+ /**
264
+ * A stable string used to skip snapshots that produce no visible change.
265
+ * Defaults to `JSON.stringify`; hosts that already walked their tree should
266
+ * pass the structural fingerprint they computed.
267
+ */
268
+ readonly fingerprint?: ((snapshot: Snapshot) => string) | undefined;
269
+ /** Continues an existing message instead of creating one. */
270
+ readonly seed?: {
271
+ readonly message: Message;
272
+ readonly skipInitial?: boolean;
273
+ } | undefined;
274
+ }
275
+ /**
276
+ * Creates the shared lifecycle for a platform message target.
277
+ *
278
+ * Renderers can commit faster than a chat platform accepts edits, so the
279
+ * target keeps only the newest snapshot and drains it after the in-flight
280
+ * request. This gives last-write-wins semantics without overlapping requests.
281
+ *
282
+ * The send lifecycle is the explicit `idle -> sending -> idle` machine from
283
+ * `state-machine/index.ts`. `lastSent` is only advanced after a successful send, so
284
+ * a failed edit can be retried by queuing the same snapshot again.
285
+ */
286
+ export declare const makeBotMessageTarget: <Message, Snapshot>(options: BotMessageTargetOptions<Message, Snapshot>) => BotMessageTarget<Message, Snapshot>;
287
+ /** The session a message root is bound to, if it is resumable. */
288
+ export interface RootSession {
289
+ readonly id: string;
290
+ readonly version: number;
291
+ }
292
+ export interface MessageRenderOptions {
293
+ readonly ephemeral?: boolean;
294
+ readonly unmountAfter?: Duration.Input | undefined;
295
+ }
296
+ /** What a platform client must expose to route and release message roots. */
297
+ export interface MessageRootClientShape {
298
+ addRoot?(root: BotMessageRoot<any, any, any, any>): void;
299
+ removeInteractionListener(uuid: string): void;
300
+ registerComponent?(key: string, component: unknown): void;
301
+ }
302
+ declare const MessageRootClient_base: Context.ServiceClass<MessageRootClient, "@arona/core/message/MessageRootClient", MessageRootClientShape>;
303
+ /** The client service a mounted message registers itself with. */
304
+ export declare class MessageRootClient extends MessageRootClient_base {}
305
+ /** Compatibility alias for the structural client shape. */
306
+ export type MessageRootClientLike = MessageRootClientShape;
307
+ export interface BotMessageRootOptions<Host, Message, Snapshot, Interaction> {
308
+ /** The Scope that owns the renderer, target and timer fibers. */
309
+ readonly scope: Scope.Closeable;
310
+ readonly host: Host;
311
+ readonly target: MessageTarget<Message, Snapshot>;
312
+ readonly client: MessageRootClientShape | undefined;
313
+ readonly interaction: (interaction: Interaction, root: BotMessageRoot<Host, Message, Snapshot, Interaction>) => Effect.Effect<void>;
314
+ /** Encodes the mounted tree's current models for a later resume. */
315
+ readonly snapshot: Effect.Effect<Renderer.State>;
316
+ /** Queues the live tree's current snapshot so resume can repaint it. */
317
+ readonly refresh?: (() => void) | undefined;
318
+ readonly session?: RootSession | undefined;
319
+ }
320
+ /** The platform a host exposes, such as `discord` or `slack`. */
321
+ export declare const platformOf: (host: unknown) => string;
322
+ /** The name a component exposes. */
323
+ export declare const componentNameOf: (component: unknown) => string;
324
+ /** Explicit lifecycle for one rendered platform message. */
325
+ export declare class BotMessageRoot<Host, Message, Snapshot, Interaction> {
326
+ #private;
327
+ readonly uuid: string;
328
+ readonly sessionId: string | undefined;
329
+ private constructor();
330
+ /** Creates a root. Mount code owns the lifecycle; direct construction is not public. */
331
+ static make<Host, Message, Snapshot, Interaction>(options: BotMessageRootOptions<Host, Message, Snapshot, Interaction>): BotMessageRoot<Host, Message, Snapshot, Interaction>;
332
+ get host(): Host;
333
+ /** `true` while closing or after close, so callers never use a closing root. */
334
+ get closed(): boolean;
335
+ /** The explicit root lifecycle state. */
336
+ get state(): RootState;
337
+ /** The state version the platform message currently shows. */
338
+ get sessionVersion(): number;
339
+ /** Updates the version the host stamps on the next commit. */
340
+ setSessionVersion(version: number): void;
341
+ /** Encodes every mounted instance's model, for a later `mount({ state })`. */
342
+ get snapshot(): Effect.Effect<Renderer.State>;
343
+ /** Whether platform interactions and live edits are paused. */
344
+ get paused(): boolean;
345
+ /** Freezes live edits and drops platform interactions until `resume`. */
346
+ pause(): void;
347
+ /** Resumes live edits and platform interactions. */
348
+ resume(): void;
349
+ /** Routes one platform interaction through the root's serialized handler. */
350
+ get interactionListener(): (interaction: Interaction) => Effect.Effect<void>;
351
+ /**
352
+ * Explicitly releases the renderer, platform cache, target, timer and client
353
+ * registration. The returned Effect is single-flight: every caller gets the
354
+ * same close, and a second close after completion is a no-op.
355
+ */
356
+ get close(): Effect.Effect<void>;
357
+ }
358
+ /** What dispatching one message to an instance did. */
359
+ export type Dispatched = Data.TaggedEnum<{
360
+ Updated: {
361
+ readonly seq: number;
362
+ };
363
+ Failed: {
364
+ readonly seq: number;
365
+ };
366
+ Ignored: {
367
+ readonly reason: "closed" | "waiting" | "frozen" | "unchanged";
368
+ };
369
+ }>;
370
+ export declare const Dispatched: Data.TaggedEnum.Constructor<{
371
+ readonly _tag: "Updated";
372
+ readonly seq: number;
373
+ } | {
374
+ readonly _tag: "Failed";
375
+ readonly seq: number;
376
+ } | {
377
+ readonly _tag: "Ignored";
378
+ readonly reason: "closed" | "waiting" | "frozen" | "unchanged";
379
+ }>;
380
+ /** One live instance a DevTools host can dispatch to. */
381
+ export interface ControlledInstance {
382
+ readonly instance: number;
383
+ readonly path: string;
384
+ readonly component: string;
385
+ readonly message: Schema.Top;
386
+ readonly dispatch: (message: unknown) => Effect.Effect<Dispatched>;
387
+ }
388
+ /** A mounted message root a DevTools host can control. */
389
+ export interface Controllable {
390
+ readonly session: string;
391
+ readonly path: string;
392
+ readonly instance: (instance: number) => ControlledInstance | undefined;
393
+ /** Freezes live edits and platform interactions. */
394
+ readonly pause?: (() => void) | undefined;
395
+ /** Resumes live edits and platform interactions. */
396
+ readonly resume?: (() => void) | undefined;
397
+ /** Sends a historical state to the platform message. */
398
+ readonly paint?: ((state: (path: string) => Renderer.Recorded | undefined) => Effect.Effect<Renderer.Painted, MessageTargetError>) | undefined;
399
+ }
400
+ export interface ControllableControls {
401
+ readonly pause?: (() => void) | undefined;
402
+ readonly resume?: (() => void) | undefined;
403
+ readonly paint?: ((state: (path: string) => Renderer.Recorded | undefined) => Effect.Effect<Renderer.Painted, MessageTargetError>) | undefined;
404
+ }
405
+ /**
406
+ * Projects a mounted root onto the host-neutral control contract through
407
+ * `Renderer.instance`, so no runtime internals leak into Arona.
408
+ */
409
+ export declare const toControllable: (root: Renderer.Root<any, any>, controls?: ControllableControls) => Controllable;
410
+ /** The controller interface a DevTools host registers with. */
411
+ export interface ControllablesShape {
412
+ /** Whether a DevTools host is attached and wants control registrations. */
413
+ readonly enabled: boolean;
414
+ readonly register: (root: Controllable) => () => void;
415
+ }
416
+ /**
417
+ * Roots mounted for a host that wants to control them.
418
+ *
419
+ * The reference defaults to a disabled registry, so production pays nothing
420
+ * for the DevTools projection and no caller has to provide the service.
421
+ */
422
+ export declare const Controllables: Context.Reference<ControllablesShape>;
423
+ declare const MessageMountError_base: Schema.Class<MessageMountError, Schema.TaggedStruct<"MessageMountError", {
424
+ readonly code: Schema.optional<Schema.String>;
425
+ readonly repair: Schema.optional<Schema.String>;
426
+ readonly message: Schema.String;
427
+ readonly cause: Schema.Defect;
428
+ }>, Cause.YieldableError & {
429
+ readonly brand: unique symbol;
430
+ }>;
431
+ /** The renderer could not be mounted or its first target message failed. */
432
+ export declare class MessageMountError extends MessageMountError_base {}
433
+ /**
434
+ * A platform host that can render one frozen tree into a snapshot without
435
+ * sending it. Discord and Slack both expose this shape.
436
+ */
437
+ export interface SnapshotCapture<Snapshot> {
438
+ readonly container: unknown;
439
+ setSession(session: HostSession | null): void;
440
+ snapshot(inert?: boolean): Snapshot;
441
+ }
442
+ export interface PaintMessageOptions<Name extends string, Props, Model, Msg, Events, R, V extends View.Elements, Message, Snapshot, Capture extends SnapshotCapture<Snapshot>> {
443
+ readonly component: AnyComponent<Name, Props, Model, Msg, Events, R, V>;
444
+ readonly props: Props;
445
+ readonly state: (path: string) => Renderer.Recorded | undefined;
446
+ readonly capture: Capture;
447
+ /**
448
+ * Builds the layer around the capture host, not the live host. Its services
449
+ * are opaque because `effect/ui` erases the component's `R` through
450
+ * `AnyComponent`; it must be self-contained for paint.
451
+ */
452
+ readonly layerFor: (capture: Capture) => Layer.Layer<any, never, never>;
453
+ readonly target: BotMessageTarget<Message, Snapshot>;
454
+ /** The session the capture host stamps on generated interaction ids. */
455
+ readonly session?: HostSession | null | undefined;
456
+ }
457
+ /**
458
+ * Paints a historical state into a platform message.
459
+ *
460
+ * The copy is inert: `Renderer.paint` runs no Command, Subscription, query
461
+ * fetch or Layer build, and `snapshot(true)` disables its controls so none can
462
+ * route to the live root. The result replaces the live message through
463
+ * `target.paint` and reports what the frozen copy could not show.
464
+ */
465
+ export declare const paintMessageSnapshot: <Name extends string, Props, Model, Msg, Events, R, V extends View.Elements, Message, Snapshot, Capture extends SnapshotCapture<Snapshot>>(options: PaintMessageOptions<Name, Props, Model, Msg, Events, R, V, Message, Snapshot, Capture>) => Effect.Effect<Renderer.Painted, MessageTargetError>;
466
+ export interface MountBotMessageOptions<Host, Message, Snapshot, Interaction, Props, R = never, E = never> {
467
+ readonly component: AnyComponent;
468
+ readonly props: Props;
469
+ readonly host: Host;
470
+ readonly target: MessageTarget<Message, Snapshot>;
471
+ readonly container: unknown;
472
+ /**
473
+ * Renderer, host and application layers for this message. Requirements and
474
+ * errors stay honest; the provided services are opaque to Arona because
475
+ * `effect/ui` erases the component's `R` through `AnyComponent`.
476
+ */
477
+ readonly layer: Layer.Layer<any, E, R>;
478
+ readonly onInteraction: (interaction: Interaction, root: BotMessageRoot<Host, Message, Snapshot, Interaction>) => Effect.Effect<void>;
479
+ readonly renderOptions: MessageRenderOptions;
480
+ /** Models from `Root.snapshot` to resume instead of calling `init`. */
481
+ readonly state?: Renderer.State | undefined;
482
+ /** Binds the root and host to a resumable message session. */
483
+ readonly session?: RootSession | undefined;
484
+ /** Sends a historical state to the platform message for time travel. */
485
+ readonly paint?: ((state: (path: string) => Renderer.Recorded | undefined) => Effect.Effect<Renderer.Painted, MessageTargetError>) | undefined;
486
+ }
487
+ /**
488
+ * Scoped form of `mountBotMessage`: the root closes when the surrounding Scope
489
+ * closes.
490
+ */
491
+ export declare const mountBotMessageScoped: <Host, Message, Snapshot, Interaction, Props, R = never, E = never>(options: MountBotMessageOptions<Host, Message, Snapshot, Interaction, Props, R, E>) => Effect.Effect<{
492
+ readonly message: Message;
493
+ readonly root: BotMessageRoot<Host, Message, Snapshot, Interaction>;
494
+ }, MessageTargetError | MessageMountError | E, R | Scope.Scope>;
495
+ /**
496
+ * Shared message lifecycle for node-based bot platforms.
497
+ *
498
+ * It mounts the component tree in a fiber owned by the returned root's Scope,
499
+ * waits for the platform target's first message, and returns an explicitly
500
+ * closable root. Closing the root closes the Scope, which releases the
501
+ * renderer, query cache, target fiber and every Layer built for the message.
502
+ */
503
+ export declare const mountBotMessage: <Host, Message, Snapshot, Interaction, Props, R = never, E = never>(options: MountBotMessageOptions<Host, Message, Snapshot, Interaction, Props, R, E>) => Effect.Effect<{
504
+ readonly message: Message;
505
+ readonly root: BotMessageRoot<Host, Message, Snapshot, Interaction>;
506
+ }, MessageTargetError | MessageMountError | E, R>;
507
+ type LeaseFailure = SessionLeaseLost | SessionStoreError | SessionNotFound | SessionClosed | SessionExpired | SessionConflict | SessionAlreadyExists | SessionStoreInconsistent;
508
+ /** What the body of a leased operation can see. */
509
+ interface LeaseUse {
510
+ readonly owner: string;
511
+ /** `true` after a renewal reported that this owner no longer holds the lease. */
512
+ readonly lost: Effect.Effect<boolean>;
513
+ readonly update: MessageSessionStoreShape["update"];
514
+ }
515
+ /** The fields shared by every lease helper. */
516
+ interface LeaseOptions<A, E, R> {
517
+ readonly sessionId: string;
518
+ readonly leaseTtlMs: number;
519
+ readonly use: (lease: LeaseUse) => Effect.Effect<A, E, R>;
520
+ }
521
+ /** A lease that waits for a busy writer before giving up. */
522
+ interface WindowLeaseOptions<A, E, R> extends LeaseOptions<A, E, R> {
523
+ /** Total time an interaction may wait. Defaults to 1000 ms. */
524
+ readonly windowMs?: number | undefined;
525
+ /** Delay between attempts. Defaults to 50 ms. */
526
+ readonly retryDelayMs?: number | undefined;
527
+ }
528
+ /**
529
+ * Holds a session's writer lease for the duration of `use`.
530
+ *
531
+ * The lease renews on a schedule. Each renewal is recorded before the next
532
+ * wait, so a lost lease is visible to `use` while it is still running. A store
533
+ * error does not stop the renewal loop: the lease is only reported lost once a
534
+ * renewal has failed for longer than its TTL, so one transient failure does not
535
+ * abort healthy work and a persistent failure cannot hide behind a stale
536
+ * `lost` flag. `update` also checks the owner inside the store, in the same
537
+ * transaction as the version.
538
+ */
539
+ export declare const withLeaseOn: <A, E, R>(store: StrongMessageSessionStore, options: LeaseOptions<A, E, R>) => Effect.Effect<Option.Option<A>, E | LeaseFailure, R>;
540
+ /** How long a busy interaction waits for the current writer by default. */
541
+ export declare const DEFAULT_INTERACTION_WINDOW_MS = 1000;
542
+ /** How often a waiting interaction retries the lease by default. */
543
+ export declare const DEFAULT_INTERACTION_RETRY_MS = 50;
544
+ /**
545
+ * Acquires a lease within a bounded window instead of dropping the first miss.
546
+ *
547
+ * A chat interaction can arrive while another process is committing the same
548
+ * session. The old behaviour returned `Option.none` immediately, so the press
549
+ * was lost even though the lease would have been free a few milliseconds later.
550
+ * This keeps the interaction in the `interactionMachine` waiting state until
551
+ * the deadline, then gives up explicitly.
552
+ */
553
+ export declare const withLeaseWithin: <A, E, R>(store: StrongMessageSessionStore, options: WindowLeaseOptions<A, E, R>) => Effect.Effect<Option.Option<A>, E | LeaseFailure, R>;
554
+ /** Holds a session's writer lease, reading `MessageSessionStore` from context. */
555
+ export declare const withLease: <A, E, R>(options: LeaseOptions<A, E, R>) => Effect.Effect<Option.Option<A>, E | LeaseFailure, R | MessageSessionStore>;
556
+ /** Explicit-store form kept for callers that already hold a store value. */
557
+ export declare const withSessionLease: <A, E, R>(options: {
558
+ readonly store: StrongMessageSessionStore;
559
+ readonly sessionId: string;
560
+ readonly leaseTtlMs: number;
561
+ readonly use: (lease: LeaseUse) => Effect.Effect<A, E, R>;
562
+ }) => Effect.Effect<Option.Option<A>, E | LeaseFailure, R>;
563
+ /**
564
+ * Low-cardinality span names used by Arona's renderers and integrations.
565
+ *
566
+ * Add attributes such as `messaging.system` or `arona.platform` instead of
567
+ * creating platform-specific span names.
568
+ */
569
+ export declare const TelemetrySpans: {
570
+ readonly messageMount: "arona.message.mount";
571
+ readonly messageSend: "arona.message.send";
572
+ readonly messageClose: "arona.message.close";
573
+ readonly messageInteraction: "arona.message.interaction";
574
+ readonly interaction: "arona.interaction";
575
+ readonly command: "arona.command";
576
+ readonly commandsReload: "arona.commands.reload";
577
+ readonly clientLogin: "arona.client.login";
578
+ readonly clientStart: "arona.client.start";
579
+ readonly slackEvent: "arona.slack.event";
580
+ };
581
+ /** Metric names emitted by Arona's core and integrations. */
582
+ export declare const TelemetryMetrics: {
583
+ readonly operations: "arona.operations";
584
+ readonly operationDuration: "arona.operation.duration";
585
+ readonly operationErrors: "arona.operation.errors";
586
+ readonly messagesMounted: "arona.messages.mounted";
587
+ readonly messagesSent: "arona.messages.sent";
588
+ readonly messagesClosed: "arona.messages.closed";
589
+ readonly messageErrors: "arona.messages.errors";
590
+ readonly interactions: "arona.interactions";
591
+ readonly commandsExecuted: "arona.commands.executed";
592
+ readonly commandsReloaded: "arona.commands.reloaded";
593
+ readonly commandErrors: "arona.commands.errors";
594
+ };
595
+ export interface TelemetrySpanOptions {
596
+ readonly attributes?: Readonly<Record<string, unknown>> | undefined;
597
+ readonly kind?: Tracer.SpanKind | undefined;
598
+ }
599
+ /** Configuration for the built-in OTLP exporters. */
600
+ export interface TelemetryConfig {
601
+ /**
602
+ * Set to `false` to disable every exporter. Defaults to `true` when an
603
+ * endpoint or console tracing is configured.
604
+ */
605
+ readonly enabled?: boolean | undefined;
606
+ /** OTLP/HTTP base endpoint, for example `http://localhost:4318`. */
607
+ readonly endpoint?: string | undefined;
608
+ /**
609
+ * Write finished spans to the console instead of exporting them over OTLP.
610
+ *
611
+ * Console spans still keep Effect's trace context, so nested Arona spans are
612
+ * indented and printed when they end. Metrics and logs keep using the OTLP
613
+ * endpoint when one is configured.
614
+ */
615
+ readonly console?: boolean | undefined;
616
+ /** Per-signal endpoint overrides. */
617
+ readonly tracesEndpoint?: string | undefined;
618
+ readonly metricsEndpoint?: string | undefined;
619
+ readonly logsEndpoint?: string | undefined;
620
+ readonly serviceName?: string | undefined;
621
+ readonly serviceVersion?: string | undefined;
622
+ readonly attributes?: Readonly<Record<string, unknown>> | undefined;
623
+ readonly headers?: Readonly<Record<string, string>> | undefined;
624
+ /** Enable traces. Defaults to `true`. */
625
+ readonly traces?: boolean | undefined;
626
+ /** Enable metrics. Defaults to `true`. */
627
+ readonly metrics?: boolean | undefined;
628
+ /** Enable Effect logs. Defaults to `true`. */
629
+ readonly logs?: boolean | undefined;
630
+ readonly compression?: "gzip" | "none" | undefined;
631
+ readonly tracerExportInterval?: number | undefined;
632
+ readonly metricExportInterval?: number | undefined;
633
+ readonly loggerExportInterval?: number | undefined;
634
+ readonly maxBatchSize?: number | undefined;
635
+ readonly maxQueueSize?: number | undefined;
636
+ readonly onDrop?: ((count: number) => void) | undefined;
637
+ readonly shutdownTimeout?: number | undefined;
638
+ }
639
+ /** The services a telemetry layer can provide. */
640
+ export type TelemetryLayer = Layer.Layer<Tracer.Tracer | OtlpExporter.Flusher, never, never>;
641
+ /** Records one operation's duration and outcome. */
642
+ export declare const recordOperation: (exit: Exit.Exit<unknown, unknown>, name: string, attributes: Readonly<Record<string, unknown>>, durationMs: number) => Effect.Effect<void>;
643
+ /**
644
+ * Traces an Effect, records its duration and outcome, and preserves its error
645
+ * channel. This is the Effect-native replacement for the old telemetry handle.
646
+ */
647
+ export declare const withSpan: <A, E, R>(effect: Effect.Effect<A, E, R>, name: string, options?: TelemetrySpanOptions) => Effect.Effect<A, E, R>;
648
+ /** Records a counter metric. */
649
+ export declare const count: (name: string, value?: number, attributes?: Readonly<Record<string, unknown>>) => Effect.Effect<void>;
650
+ /** Records a histogram value. */
651
+ export declare const histogram: (name: string, value: number, attributes?: Readonly<Record<string, unknown>>) => Effect.Effect<void>;
652
+ /** A descriptive name for an unknown error, used as a metric attribute. */
653
+ export declare const describeError: (error: unknown) => string;
654
+ /** Reads the OTLP environment as a plain record, inside Effect. */
655
+ export declare const envFromProcess: Effect.Effect<Readonly<Record<string, string | undefined>>>;
656
+ /**
657
+ * Reads OTLP configuration from environment variables.
658
+ *
659
+ * Telemetry is enabled when `OTEL_EXPORTER_OTLP_ENDPOINT` (or a per-signal
660
+ * endpoint) is present, or when console tracing is enabled.
661
+ * `OTEL_SDK_DISABLED=true` and `ARONA_TELEMETRY=0` disable every exporter.
662
+ *
663
+ * Set `ARONA_TELEMETRY_CONSOLE=true` (or `OTEL_TRACES_EXPORTER=console`) to
664
+ * print finished spans to the console instead of exporting them over OTLP.
665
+ */
666
+ export declare const configFromEnv: (env: Readonly<Record<string, string | undefined>>) => TelemetryConfig;
667
+ /**
668
+ * A tracer Layer that prints finished spans to the console.
669
+ *
670
+ * Spans are indented by nesting depth and include duration and attributes.
671
+ */
672
+ export declare const consoleTracerLayer: Layer.Layer<Tracer.Tracer>;
673
+ /** The default OTLP/HTTP collector endpoint, used when telemetry is explicitly enabled. */
674
+ export declare const defaultEndpoint = "http://localhost:4318";
675
+ export declare const layer: (config: TelemetryConfig) => TelemetryLayer;
676
+ /** Flushes buffered telemetry when a flusher is present. */
677
+ export declare const flush: Effect.Effect<void>;
678
+ /** Flushes buffered telemetry; requires an exporter layer. */
679
+ export declare const flushRequired: Effect.Effect<void, never, OtlpExporter.Flusher>;
680
+ /** The environment-configured telemetry Layer. */
681
+ export declare const layerFromEnv: TelemetryLayer;
682
+ /** The public telemetry namespace, also available through named exports. */
683
+ export declare const Telemetry: {
684
+ readonly Spans: {
685
+ readonly messageMount: "arona.message.mount";
686
+ readonly messageSend: "arona.message.send";
687
+ readonly messageClose: "arona.message.close";
688
+ readonly messageInteraction: "arona.message.interaction";
689
+ readonly interaction: "arona.interaction";
690
+ readonly command: "arona.command";
691
+ readonly commandsReload: "arona.commands.reload";
692
+ readonly clientLogin: "arona.client.login";
693
+ readonly clientStart: "arona.client.start";
694
+ readonly slackEvent: "arona.slack.event";
695
+ };
696
+ readonly Metrics: {
697
+ readonly operations: "arona.operations";
698
+ readonly operationDuration: "arona.operation.duration";
699
+ readonly operationErrors: "arona.operation.errors";
700
+ readonly messagesMounted: "arona.messages.mounted";
701
+ readonly messagesSent: "arona.messages.sent";
702
+ readonly messagesClosed: "arona.messages.closed";
703
+ readonly messageErrors: "arona.messages.errors";
704
+ readonly interactions: "arona.interactions";
705
+ readonly commandsExecuted: "arona.commands.executed";
706
+ readonly commandsReloaded: "arona.commands.reloaded";
707
+ readonly commandErrors: "arona.commands.errors";
708
+ };
709
+ readonly configFromEnv: (env: Readonly<Record<string, string | undefined>>) => TelemetryConfig;
710
+ readonly layer: (config: TelemetryConfig) => TelemetryLayer;
711
+ readonly layerFromEnv: TelemetryLayer;
712
+ readonly consoleTracerLayer: Layer.Layer<Tracer.Tracer, never, never>;
713
+ readonly withSpan: <A, E, R>(effect: Effect.Effect<A, E, R>, name: string, options?: TelemetrySpanOptions) => Effect.Effect<A, E, R>;
714
+ readonly recordOperation: (exit: Exit.Exit<unknown, unknown>, name: string, attributes: Readonly<Record<string, unknown>>, durationMs: number) => Effect.Effect<void>;
715
+ readonly count: (name: string, value?: number, attributes?: Readonly<Record<string, unknown>>) => Effect.Effect<void>;
716
+ readonly histogram: (name: string, value: number, attributes?: Readonly<Record<string, unknown>>) => Effect.Effect<void>;
717
+ readonly flush: Effect.Effect<void, never, never>;
718
+ readonly flushRequired: Effect.Effect<void, never, OtlpExporter.Flusher>;
719
+ readonly describeError: (error: unknown) => string;
720
+ };
721
+ export { type Consistency, DEFAULT_SESSION_PAGE_LIMIT, FileStore, GONE, Gone, INTERACTION_ID_PREFIX, IllegalTransitionError, InteractionEvent, InteractionIdParts, InteractionState, LEASE_FREE, Lease, LeaseEvent, LeaseEventName, LeaseState, LeaseStatus, LeaseTransition, MAX_INTERACTION_ID_LENGTH, MAX_SESSION_PAGE_LIMIT, MemoryStore, type MessageSession, MessageSessionSchema, MessageSessionState, MessageSessionStore, type MessageSessionStoreShape, RootEvent, RootMode, RootModeEvent, RootState, index_d_exports as Session, SessionAdvance, SessionAlreadyExists, SessionClosed, SessionConflict, SessionErrorCode, SessionEvent, SessionExpired, SessionLeaseLost, SessionMessageRef, SessionMutation, SessionNotFound, type SessionPage, type SessionPageOptions, SessionRepair, SessionStatus, SessionStoreError, SessionStoreInconsistent, type SessionSweepPage, StateMachineTable, type StrongMessageSessionStore, TargetEvent, TargetMode, TargetModeEvent, TargetState, advanceError, advanceSession, applySqlSessionSchema, asStrongStore, canTransition, checkSessionMutable, deriveMachineTable, encodeInteractionId, interactionMachine, interactionModel, isActive, isExpired, isStrongStore, isTerminal, leaseMachine, leaseModel, leaseOwnerAt, leaseTransition, makeSessionId, migrateSqlSessionStore, nowMillis, parseInteractionId, reachableStates, rootMachine, rootModeMachine, rootModeModel, rootModel, sessionAllows, sessionAlreadyExists, sessionClosed, sessionConflict, sessionExpired, sessionLeaseLost, sessionMachine, sessionModel, sessionNotFound, sessionPageLimit, sessionStateAt, sqlSessionStore, storeError, targetMachine, targetModeMachine, targetModeModel, targetModel, transition, transitionOrThrow };