@deepseek-ai/dsh-session-persistence-jsonl 0.2.1-alpha.1 → 0.2.1-alpha.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.i18n.yaml +10 -10
- package/README.md +9 -1
- package/README.zh.md +9 -1
- package/lib/index.js +198 -83
- package/lib/types/index.d.ts +16 -249
- package/lib/types/migration-verifier.d.ts +1 -1
- package/lib/types/storage.d.ts +4 -3
- package/lib/worker.cjs +158 -37
- package/locale/en.json +5 -0
- package/locale/zh.json +6 -0
- package/package.json +18 -15
package/README.i18n.yaml
CHANGED
|
@@ -21,23 +21,23 @@
|
|
|
21
21
|
en: 37c10302bbbde268
|
|
22
22
|
zh: 3d5c027bac868efd
|
|
23
23
|
/deepseek-ai-dsh-session-persistence-jsonl/use-this-package/minimal-configuration:
|
|
24
|
-
en:
|
|
25
|
-
zh:
|
|
24
|
+
en: b6c2f0f11f2fa9cf
|
|
25
|
+
zh: 9fac03fcbe5bbad4
|
|
26
26
|
/deepseek-ai-dsh-session-persistence-jsonl/use-this-package/on-disk-layout:
|
|
27
27
|
en: e20cf32540d7c785
|
|
28
28
|
zh: 67e182529e9211ca
|
|
29
29
|
/deepseek-ai-dsh-session-persistence-jsonl/use-this-package/durability-and-crash-semantics:
|
|
30
|
-
en:
|
|
31
|
-
zh:
|
|
30
|
+
en: 96498792672f6d50
|
|
31
|
+
zh: d767a9c69dced889
|
|
32
32
|
/deepseek-ai-dsh-session-persistence-jsonl/use-this-package/reading-the-logs:
|
|
33
|
-
en:
|
|
34
|
-
zh:
|
|
33
|
+
en: 3e53fc90a486d373
|
|
34
|
+
zh: 00e6c6e65c56629e
|
|
35
35
|
/deepseek-ai-dsh-session-persistence-jsonl/understand-the-implementation:
|
|
36
36
|
en: a35407bb25671e7e
|
|
37
37
|
zh: 6a00f9510c85adcb
|
|
38
38
|
/deepseek-ai-dsh-session-persistence-jsonl/understand-the-implementation/design-concept:
|
|
39
|
-
en:
|
|
40
|
-
zh:
|
|
39
|
+
en: a422bd0f74a5b31a
|
|
40
|
+
zh: edc47e9530c87f67
|
|
41
41
|
/deepseek-ai-dsh-session-persistence-jsonl/understand-the-implementation/physical-encoding:
|
|
42
42
|
en: 5aaf80115840318f
|
|
43
43
|
zh: 0b0fb2b2e085a111
|
|
@@ -63,8 +63,8 @@
|
|
|
63
63
|
en: 53ce4da7ce68d21c
|
|
64
64
|
zh: 10f40bc354100f77
|
|
65
65
|
/deepseek-ai-dsh-session-persistence-jsonl/known-limitations-and-deferred-work:
|
|
66
|
-
en:
|
|
67
|
-
zh:
|
|
66
|
+
en: c46c91a811abc547
|
|
67
|
+
zh: 41fb942d4e61e544
|
|
68
68
|
/deepseek-ai-dsh-session-persistence-jsonl/known-limitations-and-deferred-work/dev-note:
|
|
69
69
|
en: e67f633dc6fe7773
|
|
70
70
|
zh: 3bb0c20c93f16f98
|
package/README.md
CHANGED
|
@@ -46,6 +46,7 @@ Choose this backend when consumers benefit from one artifact per session — nav
|
|
|
46
46
|
|---|---|---|
|
|
47
47
|
| `root` | required | Root directory for all session files |
|
|
48
48
|
| `compression` | `'zstd'` | Physical encoding: `'zstd'` checksummed frames, or `'none'` newline-delimited UTF-8 text |
|
|
49
|
+
| `listConcurrency` | `3` | Maximum directory, header, and stat reads in flight, shared by every concurrent listing of this backend |
|
|
49
50
|
|
|
50
51
|
Live-event write batching is not configuration: the batching window is the seam's internal scheduling policy inside each write handle.
|
|
51
52
|
|
|
@@ -77,10 +78,16 @@ A session is materialized lazily: `create(header)` writes nothing and returns th
|
|
|
77
78
|
|
|
78
79
|
The current-generation scanner applies the current codec owner’s structural admission checks before recoverable-tail handling. Retired required PTC tags and `request/header.header.system` refuse the file even after an earlier malformed row; recovery never truncates them as ordinary damaged tail data.
|
|
79
80
|
|
|
81
|
+
Unloading the backend waits for the consumer unloads it triggers through `sessionPersistence` injection before removing live-event listeners and draining and closing remaining handles. Consumers must register cleanup in that injecting scope; unrelated scopes and explicit Session or handle closure have their own lifetimes. Programmatic mounting uses the plugin namespace (`import * as JsonlSessionPersistence from '@deepseek-ai/dsh-session-persistence-jsonl'`) with `ctx.plugin`; access storage through `ctx.sessionPersistence`.
|
|
82
|
+
|
|
80
83
|
### Reading the logs
|
|
81
84
|
|
|
85
|
+
Materialized `stat` and `list` snapshots include the format catalog's header classification as `formatStatus`, alongside the translated logical `header`. A read-only preparation leaves the selected historical version unchanged; the status becomes `current` after publication of the successor. Unmaterialized pending Sessions omit `formatStatus`.
|
|
86
|
+
|
|
82
87
|
`open(id, 'read'|'write')` selects the highest canonical generation. Current input follows the ordinary fast path. For historical input, a read open decodes and migrates the source once, validates the current logical result, and returns it without publishing a successor. A write open reuses that revision-keyed preparation when available, or performs the same preparation, then encodes a same-directory temporary file in bounded chunks, verifies it in a Worker Thread, rechecks the source revision, and publishes the current successor without overwrite before returning. The source remains byte-identical. Source drift after preparation rejects that write open without replacing the logical history already returned to readers; a later write open prepares the new revision. The backend marks decoded event graphs `shared-frozen` when it freezes them before memoization; every nested object and array is frozen, and handle reads and slices preserve that state, including empty slices. Only an unmaterialized pending log reports `detached`. `stat(id)` and `list()` select and translate only the highest generation header without reading event rows or starting migration; snapshots carry the selected file’s `sizeBytes` and a best-effort revision. Current revisions identify that file; historical revisions also fingerprint the selected files across the persistence root, so child changes invalidate cached logical events. Fingerprinting reads filesystem metadata only; unrelated changes conservatively invalidate historical revisions. One `list()` call shares a corpus fingerprint across its historical entries. With `compression: 'none'`, the log is newline-delimited text an external reader can consume directly; the compressed default must be read through the backend.
|
|
83
88
|
|
|
89
|
+
Verification accepts a successful Worker response only after the Worker exits naturally with code 0. Its concurrency slot remains held through that exit; cancellation and Worker errors terminate and join the Worker before rejecting.
|
|
90
|
+
|
|
84
91
|
Historical body preparation completes the parent catalog through [V3→V4](../session-format-v3-to-v4/README.md). It finds candidate direct children from headers, reads each child's own descriptor through historical codecs, and retains compact evidence plus source revisions. It neither prepares child catalogs nor publishes child successors. Unreadable or unsupported headers, including corrupt Zstandard header frames, are omitted from discovery and `list()`. Direct access to a corrupt compressed header still rejects; header I/O and cancellation errors propagate. Child decoding and descriptor-field failures produce warnings naming the child path and retain header identity through `subagent/catalog` when the parent has no complete entry; healthy children and existing parent catalog entries remain available. Opening a damaged child still reports that child's error. Missing, unsupported, or multiple descriptors likewise produce unknown-mode membership without inventing a label. Published unknown entries remain browsable; child history reads retry the actual log and resolve its mode from a valid descriptor. Preparation rechecks membership and inspected source revisions before returning, reuse, and publication, including failed child reads so a repaired child invalidates stale preparation. Source drift retries a read open once and refuses a write open. Cancellation still aborts the operation. Current V4 opens bypass discovery and validate catalog fields, uniqueness, and current delivery ownership before exposing events.
|
|
85
92
|
|
|
86
93
|
Historical `stat` and `list` revisions require metadata work proportional to the root’s Session count. Fresh body preparation scans all selected headers and decodes direct-child bodies; memo reuse still scans membership and checks revisions. Read-only access never publishes an upgrade, so cold processes and evicted preparations repeat that work. Current V4 body reads and revisions avoid the historical corpus scan. See the [measured costs and diagnostic command](../../../.agents/notes/implemented/architecture/2026-08-31-released-session-format-migrations.md#catalog-scan-measurements).
|
|
@@ -97,7 +104,7 @@ This section explains the physical encoding and write path; the observable contr
|
|
|
97
104
|
|
|
98
105
|
### Design concept
|
|
99
106
|
|
|
100
|
-
The backend owns its complete storage runtime (`src/storage.ts`): `JsonlSessionHandle` carries the per-handle mutation chain, the routed live-event buffer with its fixed batching window and single-flight drain, monotonic reads, and idempotent close; a tracker holds the in-process single-writer claims, the open-handle set teardown sweeps, and the created-but-unmaterialized pending sessions the backend's own session listeners route into. Historical body reads share one per-session Decode/Migrate preparation, and a bounded revision-keyed memo lets an immediate observe-to-resume handoff reuse that parse; the backend deep-freezes each event graph once before memoization, so later handle reads reuse it without copying or freezing. Only a write open publishes the prepared successor. The package
|
|
107
|
+
The backend owns its complete storage runtime (`src/storage.ts`): `JsonlSessionHandle` carries the per-handle mutation chain, the routed live-event buffer with its fixed batching window and single-flight drain, monotonic reads, and idempotent close; a tracker holds the in-process single-writer claims, the open-handle set teardown sweeps, and the created-but-unmaterialized pending sessions the backend's own session listeners route into. Historical body reads share one per-session Decode/Migrate preparation, and a bounded revision-keyed memo lets an immediate observe-to-resume handoff reuse that parse; the backend deep-freezes each event graph once before memoization, so later handle reads reuse it without copying or freezing. Only a write open publishes the prepared successor. The package exposes plugin exports and configuration types — the concrete class is private, so consumers couple to `ctx.sessionPersistence`, and the shared seam suites (`runPersistenceContract`/`runLiveWritePathContract`) pin its observable behavior. Physical revisions combine device, inode, size, and nanosecond timestamps for the preparation memo, stable-read retries, and publication checks. Historical public revisions add a SHA-256 fingerprint of sorted selected paths and their physical revisions; lock files and retained unselected generations do not contribute.
|
|
101
108
|
|
|
102
109
|
### Physical encoding
|
|
103
110
|
|
|
@@ -159,6 +166,7 @@ These limits define when this backend is a poor fit or needs special operational
|
|
|
159
166
|
- **Compressed files are not directly line-readable** — use the backend to load them, or select `compression: 'none'` before writing a fresh root when external line readers are required.
|
|
160
167
|
- **Nothing deletes session files** — logs accumulate under `root` until removed externally; the seam has no deletion API.
|
|
161
168
|
- **One live writer per session** — the write-handle claim excludes a second writer inside the owning backend instance, and a kernel lock (non-blocking `flock(2)` on `session.lock`; on Windows a named kernel semaphore derived from that path, with no filesystem footprint) excludes every other instance and process; the lock is taken at write-open of an existing artifact and, for a created session, only right before its first materializing write, so an unmaterialized session leaves no filesystem footprint. A crashed holder's lock dies with its process, so its session is writable again immediately, while a live-but-wedged holder blocks writers until its process exits (on POSIX, removing the lock file forfeits that exclusion; release itself never removes it). Advisory `flock` is unreliable on some network filesystems (NFSv3), and the Windows semaphore name is per login session.
|
|
169
|
+
- **Concurrent root disposal is not ordered** — Cordis can remove already-disposing consumers from its registry before the provider can join their cleanup. Dependency ordering here covers consumer unloads triggered by removing this provider.
|
|
162
170
|
- **POSIX materialization requires hard-link support** — first append uses `link()` so same-id races fail instead of overwriting a committed log; Windows uses write-through rename without replacement.
|
|
163
171
|
- **POSIX writes require the matching prebuilt system addon** — [`node-addon-system`](../../../native/system/README.md) supplies asynchronous flock without consumer-side compilation. A missing addon rejects write ownership; Windows retains its semaphore implementation.
|
|
164
172
|
|
package/README.zh.md
CHANGED
|
@@ -46,6 +46,7 @@ kind: "package-reference"
|
|
|
46
46
|
|---|---|---|
|
|
47
47
|
| `root` | 必填 | 所有会话文件的根目录 |
|
|
48
48
|
| `compression` | `'zstd'` | 物理编码:`'zstd'` 带校验和帧,或 `'none'` 换行分隔 UTF-8 文本 |
|
|
49
|
+
| `listConcurrency` | `3` | 同时进行的目录、header 与 stat 读取上限,由该后端所有并发的列举共用 |
|
|
49
50
|
|
|
50
51
|
实时事件的写入批处理不是配置:批处理窗口是该 seam 在每个写句柄内部的调度策略。
|
|
51
52
|
|
|
@@ -77,10 +78,16 @@ kind: "package-reference"
|
|
|
77
78
|
|
|
78
79
|
当前代际扫描器在处理可恢复尾部之前,执行当前编解码器所有者的结构准入检查。已退役的必需 PTC 标签与 `request/header.header.system` 即使出现在较早的畸形行之后也会导致文件被拒绝;恢复绝不将它们作为普通损坏尾部数据截断。
|
|
79
80
|
|
|
81
|
+
卸载后端时,会先等待经由 `sessionPersistence` 注入所触发的消费者卸载,再移除实时事件监听器、排空并关闭剩余句柄。消费者必须在该注入作用域中注册清理;无依赖关系的作用域,以及显式关闭的 Session 或句柄,各自遵循其生命周期。通过代码挂载时,使用插件命名空间(`import * as JsonlSessionPersistence from '@deepseek-ai/dsh-session-persistence-jsonl'`)调用 `ctx.plugin`,并通过 `ctx.sessionPersistence` 访问存储。
|
|
82
|
+
|
|
80
83
|
### 读取日志
|
|
81
84
|
|
|
85
|
+
已实体化的 `stat` 与 `list` 快照在转换后的逻辑 `header` 之外,通过 `formatStatus` 保留格式 catalog 的头部分类。只读准备不会改变所选历史版本;发布后继之后,状态才变为 `current`。尚未实体化的待定 Session 省略 `formatStatus`。
|
|
86
|
+
|
|
82
87
|
`open(id, 'read'|'write')` 选择最高规范 generation。当前格式输入走普通快速路径。对于历史输入,只读 open 会单遍解码并迁移源、校验当前逻辑结果,然后在不发布后继的情况下返回。写 open 会在可用时复用按 revision 为键的 preparation,否则执行同一套 preparation,再按有界分片编码同目录临时文件、在 Worker Thread 中校验、复查源修订,并在返回前以不覆盖方式发布当前后继。源保持逐字节不变。如果源在 preparation 后发生变化,该次写 open 会失败,已经返回给读方的逻辑历史不会被替换;后续写 open 会针对新的 revision 重新执行 preparation。后端在 memo 化前冻结已解码的 event graph,并在此时将其标记为 `shared-frozen`;每个嵌套对象和数组都会冻结,句柄读取和 slice 即使为空也保留该状态。只有尚未实体化的 pending 空日志报告 `detached`。`stat(id)` 与 `list()` 只选择并转换最高 generation 的 header,不读取事件行,也不启动迁移;快照携带所选文件的 `sizeBytes` 与尽力而为的修订号。当前格式修订号标识该文件;历史格式修订号还包含持久化根目录中所选文件的指纹,因此子日志变化会使缓存的逻辑事件失效。指纹只读取文件系统元数据;无关变化也会保守地使历史修订号失效。一次 `list()` 为其历史条目共用一个全库指纹。选择 `compression: 'none'` 后,日志是外部读取方可直接消费的换行分隔文本;压缩默认值必须经后端读取。
|
|
83
88
|
|
|
89
|
+
校验只有在 Worker 自然以退出码 0 结束后,才接受其成功响应。并发配额一直保留到该次退出;取消或 Worker 错误会先终止并等待 Worker 退出,再使校验失败。
|
|
90
|
+
|
|
84
91
|
历史正文准备通过 [V3→V4](../session-format-v3-to-v4/README.zh.md) 补齐父目录:从 header 找到候选直属子 Session,通过历史编解码器逐个读取其自身 descriptor,保留紧凑证据与来源修订。此过程不准备子目录,也不发布子后继。不可读或不支持的 header(包括损坏的 Zstandard header 帧)不参与发现,也不出现在 `list()` 中。直接访问损坏的压缩 header 仍会失败;header 的 I/O 错误与取消错误继续传播。子日志解码或 descriptor 字段失败会产生带子路径的警告;父目录没有完整条目时,通过 `subagent/catalog` 保留 header 身份信息。健康子项和已有父目录项仍可使用。打开损坏子 Session 时仍报告该子会话的错误。缺失、不支持或多个 descriptor 同样生成模式未知的目录项,不编造标签。已发布的未知条目仍可浏览;读取子历史时会重试实际日志,并从有效 descriptor 确定模式。准备返回、复用与发布前会重新检查成员集合及已检查来源的修订,也包括读取失败的子日志,使修复后的子日志能够使旧准备缓存失效。来源变化时只读打开重试一次,写打开拒绝发布。取消仍会中止操作。当前 V4 打开跳过发现,并在暴露事件前校验目录字段、唯一性及当前投递归属。
|
|
85
92
|
|
|
86
93
|
历史格式的 `stat` 与 `list` 修订号需要与根目录 Session 数量成正比的元数据工作。首次正文准备扫描所有所选 header 并解码直属子正文;复用准备缓存仍扫描成员集合并检查修订。只读访问从不发布升级,因此冷进程与被淘汰的准备缓存会重复这些工作。当前 V4 正文读取和修订号避开历史全库扫描。见[实测成本与诊断命令](../../../.agents/notes/implemented/architecture/2026-08-31-released-session-format-migrations.zh.md#catalog-scan-measurements)。
|
|
@@ -97,7 +104,7 @@ kind: "package-reference"
|
|
|
97
104
|
|
|
98
105
|
### 设计理念
|
|
99
106
|
|
|
100
|
-
该后端拥有自己完整的存储运行时(`src/storage.ts`):`JsonlSessionHandle` 承载逐句柄修改链、带固定批处理窗口与 single-flight 排空的已路由实时事件缓冲、单调读取与幂等 close;一个 tracker 持有进程内单写者认领、teardown 清扫所遍历的打开句柄集合,以及后端自己的会话监听器所路由进的已创建但未实体化待定会话。历史正文读取共享每个 Session 唯一的一次 Decode/Migrate preparation,按 revision 为键的有界 memo 让紧接的观察到恢复交接复用该解析;backend 在 memo 化前只对每个 event graph 深度冻结一次,因此后续 handle read 无需复制或再次冻结。只有写 open
|
|
107
|
+
该后端拥有自己完整的存储运行时(`src/storage.ts`):`JsonlSessionHandle` 承载逐句柄修改链、带固定批处理窗口与 single-flight 排空的已路由实时事件缓冲、单调读取与幂等 close;一个 tracker 持有进程内单写者认领、teardown 清扫所遍历的打开句柄集合,以及后端自己的会话监听器所路由进的已创建但未实体化待定会话。历史正文读取共享每个 Session 唯一的一次 Decode/Migrate preparation,按 revision 为键的有界 memo 让紧接的观察到恢复交接复用该解析;backend 在 memo 化前只对每个 event graph 深度冻结一次,因此后续 handle read 无需复制或再次冻结。只有写 open 才发布准备好的后继。本包暴露插件导出与配置类型——具体类是私有的,因此消费方只耦合 `ctx.sessionPersistence`,其可观察行为由共享 seam 测试套件(`runPersistenceContract`/`runLiveWritePathContract`)钉住。物理修订号组合 device、inode、size 与纳秒时间戳,供准备缓存、稳定读取重试及发布检查使用。历史格式的公开修订号还加入所选路径排序后及其物理修订号的 SHA-256 指纹;锁文件与保留但未被选中的代际不参与计算。
|
|
101
108
|
|
|
102
109
|
### 物理编码
|
|
103
110
|
|
|
@@ -159,6 +166,7 @@ JSONL 存储不修改实时请求前缀。只有重建历史、当前 envelope
|
|
|
159
166
|
- **压缩文件不能直接按行读取**——使用后端加载;或在写入新根前选择 `compression: 'none'`,供外部行读取方使用。
|
|
160
167
|
- **不删除会话文件**——日志在 `root` 下累积,直到外部移除;seam 无删除接口。
|
|
161
168
|
- **每会话一个活动写入方**——写句柄认领在所属后端实例内排除第二个写入方,内核锁(`session.lock` 上的非阻塞 `flock(2)`;Windows 上为由该路径派生的命名内核信号量,零文件系统足迹)排除其他所有实例与进程;锁在以写模式打开既有产物时立即获取,新建会话则仅在首次实体化写入之前获取,因此未实体化的会话不留任何文件系统足迹。崩溃持有者的锁随其进程消亡,会话立即可再写入,而活着但卡死的持有者会阻塞写入方直到其进程退出(POSIX 上删除锁文件即放弃该排他;释放本身从不删除它)。咨询式 `flock` 在部分网络文件系统(NFSv3)上不可靠,Windows 信号量名按登录会话隔离。
|
|
169
|
+
- **根作用域的并发卸载不保证顺序**——Cordis 可能在提供者等待消费者清理前,已将正在卸载的消费者移出注册表。此处的依赖顺序仅覆盖移除该提供者所触发的消费者卸载。
|
|
162
170
|
- **POSIX 实体化需要硬链接支持**——第一次 append 使用 `link()`,使同 id 竞态失败而不覆盖已提交日志;Windows 使用无替换 write-through rename。
|
|
163
171
|
- **POSIX 写入需要匹配的预编译系统 addon**——[`node-addon-system`](../../../native/system/README.zh.md) 提供异步 flock,无须在用户侧编译。addon 缺失时拒绝写入所有权;Windows 保留其信号量实现。
|
|
164
172
|
|
package/lib/index.js
CHANGED
|
@@ -6,6 +6,7 @@ import { basename, dirname, isAbsolute, join, parse, resolve, toNamespacedPath }
|
|
|
6
6
|
import { performance } from "node:perf_hooks";
|
|
7
7
|
import { scheduler } from "node:timers/promises";
|
|
8
8
|
import { createHash, randomBytes } from "node:crypto";
|
|
9
|
+
import pLimit from "p-limit";
|
|
9
10
|
import { SessionAlreadyExistsError, SessionAlreadyOwnedError, SessionFormatUnsupportedError, SessionHandleClosedError, SessionPersistence, SessionPersistenceCorruptionError, SessionPersistenceNotFoundError, SessionPersistenceRevision, SessionReadOnlyError, assertContiguous, assertStoredId, materializeAppendBatch, materializeCreateHeader, sessionFormatVersionRefusal, validateStoredEvents } from "@deepseek-ai/dsh-session-persistence";
|
|
10
11
|
import { BlockAssembler, errorChain, expandAssistantStream } from "@deepseek-ai/dsh-llm";
|
|
11
12
|
import { tryLockExclusive } from "@deepseek-ai/node-addon-system/flock";
|
|
@@ -401,39 +402,43 @@ var JsonlBackendTracker = class {
|
|
|
401
402
|
* sessions' events by id; the teardown effect closes every open handle —
|
|
402
403
|
* close drains the routed buffer — and aggregates failures. This provider
|
|
403
404
|
* owns no separate storage connection, so closing handles is the complete
|
|
404
|
-
* teardown.
|
|
405
|
-
* @param ctx - the backend's context.
|
|
405
|
+
* teardown. The returned effect removes listeners before closing handles.
|
|
406
|
+
* @param ctx - the backend's resource-owning context.
|
|
407
|
+
* @returns the disposer to run after persistence consumers finish unloading.
|
|
406
408
|
*/
|
|
407
409
|
install(ctx) {
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
410
|
+
const { writers, openHandles, name } = this;
|
|
411
|
+
return ctx.effect(function* () {
|
|
412
|
+
yield async () => {
|
|
413
|
+
const errors = [];
|
|
414
|
+
for (const handle of [...openHandles]) try {
|
|
415
|
+
await handle.close();
|
|
416
|
+
} catch (error) {
|
|
417
|
+
errors.push(error);
|
|
418
|
+
}
|
|
419
|
+
if (errors.length > 0) throw new AggregateError(errors, `${name} dispose failed`);
|
|
420
|
+
};
|
|
421
|
+
yield ctx.on("session/event", (session, event) => {
|
|
422
|
+
writers.get(session.id)?.enqueueLive(event, (error) => {
|
|
423
|
+
ctx.logger.warn(`session-persistence: background write for session "${session.id}" failed (buffered events retained): ${String(error)}`);
|
|
424
|
+
});
|
|
411
425
|
});
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
})();
|
|
420
|
-
});
|
|
421
|
-
ctx.on("session/disposed", (session) => {
|
|
422
|
-
const writer = this.writers.get(session.id);
|
|
423
|
-
if (writer === null || writer === void 0) return;
|
|
424
|
-
writer.close().catch((error) => {
|
|
425
|
-
ctx.logger.warn(`session-persistence: final drain for session "${session.id}" failed: ${String(error)}`);
|
|
426
|
+
yield ctx.on("session/flush", (session) => {
|
|
427
|
+
const writer = writers.get(session.id);
|
|
428
|
+
if (writer === null || writer === void 0) return void 0;
|
|
429
|
+
return (async () => {
|
|
430
|
+
await writer.drainLive();
|
|
431
|
+
await writer.flush();
|
|
432
|
+
})();
|
|
426
433
|
});
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
if (errors.length > 0) throw new AggregateError(errors, `${this.name} dispose failed`);
|
|
436
|
-
}, `${this.name} open handles`);
|
|
434
|
+
yield ctx.on("session/disposed", (session) => {
|
|
435
|
+
const writer = writers.get(session.id);
|
|
436
|
+
if (writer === null || writer === void 0) return;
|
|
437
|
+
writer.close().catch((error) => {
|
|
438
|
+
ctx.logger.warn(`session-persistence: final drain for session "${session.id}" failed: ${String(error)}`);
|
|
439
|
+
});
|
|
440
|
+
});
|
|
441
|
+
}, `${this.name} live routing and open handles`);
|
|
437
442
|
}
|
|
438
443
|
};
|
|
439
444
|
//#endregion
|
|
@@ -1476,7 +1481,7 @@ function workerSpawn(request) {
|
|
|
1476
1481
|
* @param expectedEventCount - exact logical event count expected after decoding.
|
|
1477
1482
|
* @param expectedPrefix - verified physical prefix; an append tail may be present and is not validated.
|
|
1478
1483
|
* @param signal - optional cancellation for scheduler wait and Worker execution.
|
|
1479
|
-
* @returns
|
|
1484
|
+
* @returns the worker's physical identity and digest after its natural zero exit.
|
|
1480
1485
|
*/
|
|
1481
1486
|
function verifyCurrentGenerationInWorker(path, compression, expectedId, expectedEventCount, expectedPrefix, signal) {
|
|
1482
1487
|
return verificationScheduler.run(() => runVerificationWorker(path, compression, expectedId, expectedEventCount, expectedPrefix, signal), signal);
|
|
@@ -1493,6 +1498,7 @@ function runVerificationWorker(path, compression, expectedId, expectedEventCount
|
|
|
1493
1498
|
const worker = new Worker(entry, options);
|
|
1494
1499
|
return new Promise((resolve, reject) => {
|
|
1495
1500
|
let settled = false;
|
|
1501
|
+
let success;
|
|
1496
1502
|
const cleanup = () => {
|
|
1497
1503
|
signal?.removeEventListener("abort", abort);
|
|
1498
1504
|
};
|
|
@@ -1521,17 +1527,16 @@ function runVerificationWorker(path, compression, expectedId, expectedEventCount
|
|
|
1521
1527
|
fail(error);
|
|
1522
1528
|
return;
|
|
1523
1529
|
}
|
|
1524
|
-
|
|
1525
|
-
cleanup();
|
|
1526
|
-
worker.terminate().then(() => {
|
|
1527
|
-
resolve(response.result);
|
|
1528
|
-
}, (error) => {
|
|
1529
|
-
reject(error instanceof Error ? error : new Error(String(error)));
|
|
1530
|
-
});
|
|
1530
|
+
success = response;
|
|
1531
1531
|
});
|
|
1532
1532
|
worker.once("error", fail);
|
|
1533
1533
|
worker.once("exit", (code) => {
|
|
1534
|
-
if (
|
|
1534
|
+
if (settled) return;
|
|
1535
|
+
settled = true;
|
|
1536
|
+
cleanup();
|
|
1537
|
+
if (success === void 0) reject(/* @__PURE__ */ new Error(`migration verifier exited before reporting a result (code ${code})`));
|
|
1538
|
+
else if (code !== 0) reject(/* @__PURE__ */ new Error(`migration verifier exited after reporting a result (code ${code})`));
|
|
1539
|
+
else resolve(success.result);
|
|
1535
1540
|
});
|
|
1536
1541
|
const abort = () => {
|
|
1537
1542
|
fail(verifierAbortError(signal));
|
|
@@ -2295,6 +2300,8 @@ function assertZstdHeaderFrame(plaintext) {
|
|
|
2295
2300
|
}
|
|
2296
2301
|
/** Loader schema for the JSONL artifact's physical encoding. */
|
|
2297
2302
|
const JsonlCompressionSchema = z.union([z.const("zstd"), z.const("none")]).default(DEFAULT_COMPRESSION);
|
|
2303
|
+
/** Default maximum listing filesystem operations in flight per backend. */
|
|
2304
|
+
const DEFAULT_LIST_CONCURRENCY = 3;
|
|
2298
2305
|
/** Deep-freeze acyclic stored JSON; its arrays contain only indexed JSON values. */
|
|
2299
2306
|
function freezeStoredEvent(event) {
|
|
2300
2307
|
const pending = [event];
|
|
@@ -2334,6 +2341,30 @@ function fileRevision(identity) {
|
|
|
2334
2341
|
function isENOENT(error) {
|
|
2335
2342
|
return error?.code === "ENOENT";
|
|
2336
2343
|
}
|
|
2344
|
+
/**
|
|
2345
|
+
* Run `task` over `items` through the backend's shared listing limiter and
|
|
2346
|
+
* settle every call. Callers consume the outcomes in input order, so the first
|
|
2347
|
+
* failure they report matches a sequential loop whatever the completion order.
|
|
2348
|
+
* A limited task must never wait on the same limiter.
|
|
2349
|
+
* @param limit - the backend's shared listing limiter.
|
|
2350
|
+
* @param items - inputs in their sequential order.
|
|
2351
|
+
* @param task - per-item operation.
|
|
2352
|
+
* @returns one outcome per item, in input order.
|
|
2353
|
+
*/
|
|
2354
|
+
function settleLimited(limit, items, task) {
|
|
2355
|
+
return Promise.allSettled(items.map((item) => limit(() => task(item))));
|
|
2356
|
+
}
|
|
2357
|
+
/**
|
|
2358
|
+
* Unwrap outcomes from {@link settleLimited}, rethrowing the first rejection in input order.
|
|
2359
|
+
* @param outcomes - outcomes in input order.
|
|
2360
|
+
* @returns the fulfilled values in input order.
|
|
2361
|
+
*/
|
|
2362
|
+
function settledValues(outcomes) {
|
|
2363
|
+
return outcomes.map((outcome) => {
|
|
2364
|
+
if (outcome.status === "rejected") throw outcome.reason;
|
|
2365
|
+
return outcome.value;
|
|
2366
|
+
});
|
|
2367
|
+
}
|
|
2337
2368
|
/** Whether a filesystem-owned failure should retain its original errno and path. */
|
|
2338
2369
|
function isErrnoException(error) {
|
|
2339
2370
|
return typeof error?.code === "string";
|
|
@@ -2364,23 +2395,25 @@ function waitWithAbort(operation, signal) {
|
|
|
2364
2395
|
});
|
|
2365
2396
|
}
|
|
2366
2397
|
/**
|
|
2367
|
-
* The JSONL
|
|
2368
|
-
*
|
|
2398
|
+
* The JSONL backend registered as `ctx.sessionPersistence` by the plugin.
|
|
2399
|
+
* Sessions materialize lazily: a created session is
|
|
2369
2400
|
* visible to this process immediately, reaches disk on its first append or
|
|
2370
2401
|
* flush, and never existed if the process crashes before that.
|
|
2371
2402
|
*/
|
|
2372
2403
|
var JsonlSessionPersistence = class extends SessionPersistence {
|
|
2373
2404
|
config;
|
|
2374
|
-
|
|
2375
|
-
root: z.string().required(),
|
|
2376
|
-
compression: JsonlCompressionSchema
|
|
2377
|
-
});
|
|
2405
|
+
tracker;
|
|
2378
2406
|
/** Backend label for diagnostics and effects; shadows `Service.name` without changing the service key. */
|
|
2379
2407
|
name = "session-persistence-jsonl";
|
|
2380
2408
|
root;
|
|
2381
2409
|
compression;
|
|
2410
|
+
/**
|
|
2411
|
+
* Bounds directory, header, and stat I/O across every concurrent listing of
|
|
2412
|
+
* this backend (`list()`, the root encoding check, historical fingerprints).
|
|
2413
|
+
* Queued tasks of a cancelled listing run and reject at their signal check.
|
|
2414
|
+
*/
|
|
2415
|
+
listLimit;
|
|
2382
2416
|
rootEncodingCheck;
|
|
2383
|
-
tracker = new JsonlBackendTracker(this.name);
|
|
2384
2417
|
generationFormat;
|
|
2385
2418
|
/**
|
|
2386
2419
|
* Bounded LRU of parsed, validated stored logs keyed by session id and
|
|
@@ -2392,13 +2425,15 @@ var JsonlSessionPersistence = class extends SessionPersistence {
|
|
|
2392
2425
|
coldLogMemo = /* @__PURE__ */ new Map();
|
|
2393
2426
|
/** One joinable decode/migration operation per selected historical Session file revision. */
|
|
2394
2427
|
migrationPreparations = /* @__PURE__ */ new Map();
|
|
2395
|
-
constructor(ctx, config) {
|
|
2428
|
+
constructor(ctx, config, tracker) {
|
|
2396
2429
|
super(ctx);
|
|
2397
2430
|
this.config = config;
|
|
2431
|
+
this.tracker = tracker;
|
|
2398
2432
|
/* v8 ignore next 5 -- generated catalog and Session source share one build-time version owner. */
|
|
2399
2433
|
if (sessionFormatCatalog.currentVersion !== SESSION_FORMAT_VERSION) throw new Error(`session-persistence-jsonl: format catalog v${sessionFormatCatalog.currentVersion} does not match Session v${SESSION_FORMAT_VERSION}`);
|
|
2400
2434
|
this.root = resolve(config.root);
|
|
2401
2435
|
this.compression = config.compression ?? DEFAULT_COMPRESSION;
|
|
2436
|
+
this.listLimit = pLimit(config.listConcurrency ?? DEFAULT_LIST_CONCURRENCY);
|
|
2402
2437
|
this.generationFormat = {
|
|
2403
2438
|
currentVersion: sessionFormatCatalog.currentVersion,
|
|
2404
2439
|
encodeHeader: (header, inheritedEventCount) => sessionFormatCatalog.encodeCurrentHeader(header, inheritedEventCount),
|
|
@@ -2406,7 +2441,6 @@ var JsonlSessionPersistence = class extends SessionPersistence {
|
|
|
2406
2441
|
isUnsupportedMigrationError: (error) => error instanceof SessionFormatUnsupportedMigrationError
|
|
2407
2442
|
};
|
|
2408
2443
|
this.assertUsableRoot();
|
|
2409
|
-
this.tracker.install(ctx);
|
|
2410
2444
|
}
|
|
2411
2445
|
/**
|
|
2412
2446
|
* Refusal-diagnostics hook: the absolute target path, without touching the filesystem.
|
|
@@ -2544,13 +2578,13 @@ var JsonlSessionPersistence = class extends SessionPersistence {
|
|
|
2544
2578
|
};
|
|
2545
2579
|
const selected = await this.findLog(id, options?.signal);
|
|
2546
2580
|
if (selected === void 0) return void 0;
|
|
2547
|
-
const
|
|
2548
|
-
if (
|
|
2581
|
+
const metadata = await this.readGenerationHeader(selected, id, options?.signal);
|
|
2582
|
+
if (metadata === void 0) return void 0;
|
|
2549
2583
|
try {
|
|
2550
2584
|
const identity = await stat(selected.sourcePath, { bigint: true });
|
|
2551
2585
|
options?.signal?.throwIfAborted();
|
|
2552
2586
|
return {
|
|
2553
|
-
|
|
2587
|
+
...metadata,
|
|
2554
2588
|
revision: selected.sourceVersion < SESSION_FORMAT_VERSION ? SessionPersistenceRevision(`${fileRevision(identity)}:${await this.historicalCorpusRevision(options?.signal)}`) : fileRevision(identity),
|
|
2555
2589
|
sizeBytes: Number(identity.size)
|
|
2556
2590
|
};
|
|
@@ -2573,21 +2607,31 @@ var JsonlSessionPersistence = class extends SessionPersistence {
|
|
|
2573
2607
|
const pending = [...this.tracker.pendingEntries()];
|
|
2574
2608
|
const artifacts = await this.listArtifacts(signal);
|
|
2575
2609
|
const corpusRevision = artifacts.some((artifact) => artifact.sourceVersion < SESSION_FORMAT_VERSION) ? await this.historicalCorpusRevision(signal) : void 0;
|
|
2576
|
-
|
|
2610
|
+
const statted = settledValues(await settleLimited(this.listLimit, artifacts, async (artifact) => {
|
|
2577
2611
|
signal?.throwIfAborted();
|
|
2578
2612
|
try {
|
|
2579
2613
|
const identity = await stat(artifact.path, { bigint: true });
|
|
2580
2614
|
signal?.throwIfAborted();
|
|
2581
|
-
|
|
2582
|
-
|
|
2583
|
-
|
|
2584
|
-
|
|
2585
|
-
sizeBytes: Number(identity.size)
|
|
2586
|
-
});
|
|
2615
|
+
return {
|
|
2616
|
+
artifact,
|
|
2617
|
+
identity
|
|
2618
|
+
};
|
|
2587
2619
|
} catch (error) {
|
|
2588
2620
|
signal?.throwIfAborted();
|
|
2589
2621
|
if (!isENOENT(error)) throw error;
|
|
2622
|
+
return;
|
|
2590
2623
|
}
|
|
2624
|
+
}));
|
|
2625
|
+
for (const entry of statted) {
|
|
2626
|
+
if (entry === void 0) continue;
|
|
2627
|
+
const { artifact, identity } = entry;
|
|
2628
|
+
listed.add(artifact.header.id);
|
|
2629
|
+
snapshots.push({
|
|
2630
|
+
header: artifact.header,
|
|
2631
|
+
formatStatus: artifact.formatStatus,
|
|
2632
|
+
revision: artifact.sourceVersion < SESSION_FORMAT_VERSION ? SessionPersistenceRevision(`${fileRevision(identity)}:${corpusRevision}`) : fileRevision(identity),
|
|
2633
|
+
sizeBytes: Number(identity.size)
|
|
2634
|
+
});
|
|
2591
2635
|
}
|
|
2592
2636
|
for (const [id, entry] of pending) if (!listed.has(id)) snapshots.push({
|
|
2593
2637
|
header: entry.header,
|
|
@@ -3002,29 +3046,56 @@ var JsonlSessionPersistence = class extends SessionPersistence {
|
|
|
3002
3046
|
}
|
|
3003
3047
|
/** Enumerate selected physical generations without interpreting their headers or bodies. */
|
|
3004
3048
|
async listGenerations(signal) {
|
|
3005
|
-
|
|
3006
|
-
for (const project of await this.listProjectDirs(signal)) for (const dir of await this.listSessionDirs(project, signal)) {
|
|
3049
|
+
return (await this.mapSessionDirectories((dir) => {
|
|
3007
3050
|
signal?.throwIfAborted();
|
|
3008
|
-
|
|
3009
|
-
|
|
3051
|
+
return this.resolveGenerationInDirectory(dir, signal);
|
|
3052
|
+
}, signal)).filter((source) => source !== void 0);
|
|
3053
|
+
}
|
|
3054
|
+
/**
|
|
3055
|
+
* Apply `task` to every Session directory through the shared listing
|
|
3056
|
+
* limiter. Results and the first failure follow the sequential
|
|
3057
|
+
* project-then-directory order; a project whose listing fails ends the
|
|
3058
|
+
* traversal after the directories of the projects before it.
|
|
3059
|
+
* @param task - per-directory operation; must not wait on the listing limiter.
|
|
3060
|
+
* @param signal - optional cancellation for directory listings.
|
|
3061
|
+
* @returns per-directory results in traversal order.
|
|
3062
|
+
*/
|
|
3063
|
+
async mapSessionDirectories(task, signal) {
|
|
3064
|
+
const limit = this.listLimit;
|
|
3065
|
+
const projects = await settleLimited(limit, await limit(() => this.listProjectDirs(signal)), (project) => this.listSessionDirs(project, signal));
|
|
3066
|
+
const dirs = [];
|
|
3067
|
+
let projectFailure;
|
|
3068
|
+
for (const outcome of projects) {
|
|
3069
|
+
if (outcome.status === "rejected") {
|
|
3070
|
+
projectFailure = outcome;
|
|
3071
|
+
break;
|
|
3072
|
+
}
|
|
3073
|
+
for (const dir of outcome.value) dirs.push(dir);
|
|
3010
3074
|
}
|
|
3011
|
-
|
|
3075
|
+
const results = settledValues(await settleLimited(limit, dirs, task));
|
|
3076
|
+
if (projectFailure !== void 0) throw projectFailure.reason;
|
|
3077
|
+
return results;
|
|
3012
3078
|
}
|
|
3013
3079
|
/** Historical logical events depend on the corpus, including members with unreadable headers. */
|
|
3014
3080
|
async historicalCorpusRevision(signal) {
|
|
3015
3081
|
const paths = (await this.listGenerations(signal)).map((source) => source.sourcePath).sort();
|
|
3016
|
-
const
|
|
3017
|
-
for (const path of paths) {
|
|
3082
|
+
const entries = settledValues(await settleLimited(this.listLimit, paths, async (path) => {
|
|
3018
3083
|
signal?.throwIfAborted();
|
|
3019
|
-
let revision;
|
|
3020
3084
|
try {
|
|
3021
|
-
|
|
3085
|
+
return {
|
|
3086
|
+
path,
|
|
3087
|
+
revision: fileRevision(await stat(path, { bigint: true }))
|
|
3088
|
+
};
|
|
3022
3089
|
} catch (error) {
|
|
3023
3090
|
if (!isENOENT(error)) throw error;
|
|
3024
|
-
|
|
3091
|
+
return {
|
|
3092
|
+
path,
|
|
3093
|
+
revision: "missing"
|
|
3094
|
+
};
|
|
3025
3095
|
}
|
|
3026
|
-
|
|
3027
|
-
|
|
3096
|
+
}));
|
|
3097
|
+
const hash = createHash("sha256");
|
|
3098
|
+
for (const { path, revision } of entries) hash.update(JSON.stringify([path, revision]));
|
|
3028
3099
|
signal?.throwIfAborted();
|
|
3029
3100
|
return hash.digest("hex");
|
|
3030
3101
|
}
|
|
@@ -3032,22 +3103,32 @@ var JsonlSessionPersistence = class extends SessionPersistence {
|
|
|
3032
3103
|
signal?.throwIfAborted();
|
|
3033
3104
|
await this.ensureRootEncoding();
|
|
3034
3105
|
signal?.throwIfAborted();
|
|
3035
|
-
const
|
|
3036
|
-
const
|
|
3037
|
-
for (const selected of await this.listGenerations(signal)) {
|
|
3106
|
+
const generations = await this.listGenerations(signal);
|
|
3107
|
+
const headers = await settleLimited(this.listLimit, generations, async (selected) => {
|
|
3038
3108
|
signal?.throwIfAborted();
|
|
3039
|
-
let header;
|
|
3040
3109
|
try {
|
|
3041
|
-
|
|
3110
|
+
return {
|
|
3111
|
+
selected,
|
|
3112
|
+
metadata: await this.readGenerationHeader(selected, void 0, signal)
|
|
3113
|
+
};
|
|
3042
3114
|
} catch (error) {
|
|
3043
|
-
if (error instanceof SessionFormatUnsupportedError || error instanceof SessionPersistenceCorruptionError)
|
|
3115
|
+
if (error instanceof SessionFormatUnsupportedError || error instanceof SessionPersistenceCorruptionError) return {
|
|
3116
|
+
selected,
|
|
3117
|
+
metadata: void 0
|
|
3118
|
+
};
|
|
3044
3119
|
throw error;
|
|
3045
3120
|
}
|
|
3046
|
-
|
|
3047
|
-
|
|
3048
|
-
|
|
3121
|
+
});
|
|
3122
|
+
const artifacts = [];
|
|
3123
|
+
const ids = /* @__PURE__ */ new Set();
|
|
3124
|
+
for (const outcome of headers) {
|
|
3125
|
+
if (outcome.status === "rejected") throw outcome.reason;
|
|
3126
|
+
const { selected, metadata } = outcome.value;
|
|
3127
|
+
if (metadata === void 0) continue;
|
|
3128
|
+
if (ids.has(metadata.header.id)) throw new Error(`duplicate JSONL session id "${metadata.header.id}" appears in multiple project directories`);
|
|
3129
|
+
ids.add(metadata.header.id);
|
|
3049
3130
|
artifacts.push({
|
|
3050
|
-
|
|
3131
|
+
...metadata,
|
|
3051
3132
|
path: selected.sourcePath,
|
|
3052
3133
|
sourceVersion: selected.sourceVersion
|
|
3053
3134
|
});
|
|
@@ -3089,7 +3170,10 @@ var JsonlSessionPersistence = class extends SessionPersistence {
|
|
|
3089
3170
|
if (result.status === "malformed") return void 0;
|
|
3090
3171
|
const header = this.currentHeader(result.header);
|
|
3091
3172
|
await this.assertStoredIdentity(selected.sourcePath, selected.sourceVersion, header, expectedId, signal);
|
|
3092
|
-
return
|
|
3173
|
+
return {
|
|
3174
|
+
header,
|
|
3175
|
+
formatStatus: result.status
|
|
3176
|
+
};
|
|
3093
3177
|
}
|
|
3094
3178
|
/** Convert format-catalog string identities to current branded Session metadata. */
|
|
3095
3179
|
currentHeader(header) {
|
|
@@ -3445,10 +3529,10 @@ var JsonlSessionPersistence = class extends SessionPersistence {
|
|
|
3445
3529
|
return this.rootEncodingCheck;
|
|
3446
3530
|
}
|
|
3447
3531
|
async checkRootEncoding() {
|
|
3448
|
-
|
|
3532
|
+
await this.mapSessionDirectories(async (dir) => {
|
|
3449
3533
|
const incompatible = await this.findOppositeGenerationInDirectory(dir);
|
|
3450
3534
|
if (incompatible !== void 0) throw this.encodingMismatch(incompatible);
|
|
3451
|
-
}
|
|
3535
|
+
});
|
|
3452
3536
|
}
|
|
3453
3537
|
async rejectLegacyFlatArtifact(project, id, signal) {
|
|
3454
3538
|
signal?.throwIfAborted();
|
|
@@ -3523,5 +3607,36 @@ var JsonlSessionPersistence = class extends SessionPersistence {
|
|
|
3523
3607
|
}
|
|
3524
3608
|
}
|
|
3525
3609
|
};
|
|
3610
|
+
/** JSONL persistence plugin label. */
|
|
3611
|
+
const name = "session-persistence-jsonl";
|
|
3612
|
+
/** Loader schema for the backend's root, physical encoding, and listing concurrency. */
|
|
3613
|
+
const Config = z.object({
|
|
3614
|
+
root: z.string().required(),
|
|
3615
|
+
compression: JsonlCompressionSchema,
|
|
3616
|
+
listConcurrency: z.natural().min(1).default(DEFAULT_LIST_CONCURRENCY)
|
|
3617
|
+
});
|
|
3618
|
+
/**
|
|
3619
|
+
* Mount persistence with live routing and handles retained through the
|
|
3620
|
+
* consumer unloads triggered by removing this provider. Consumers must own
|
|
3621
|
+
* cleanup in their injecting scope; concurrent root disposal is not ordered.
|
|
3622
|
+
* @param ctx - the owning plugin context.
|
|
3623
|
+
* @param config - the storage root, physical encoding, and listing concurrency.
|
|
3624
|
+
* @returns resolves when the service is ready.
|
|
3625
|
+
*/
|
|
3626
|
+
async function apply(ctx, config) {
|
|
3627
|
+
let service;
|
|
3628
|
+
ctx.effect(function* () {
|
|
3629
|
+
const tracker = new JsonlBackendTracker(name);
|
|
3630
|
+
yield tracker.install(ctx);
|
|
3631
|
+
service = ctx.plugin({
|
|
3632
|
+
name: "session-persistence-jsonl-service",
|
|
3633
|
+
apply(serviceCtx) {
|
|
3634
|
+
new JsonlSessionPersistence(serviceCtx, config, tracker);
|
|
3635
|
+
}
|
|
3636
|
+
});
|
|
3637
|
+
yield service.dispose;
|
|
3638
|
+
}, "session-persistence-jsonl resources");
|
|
3639
|
+
await service.await();
|
|
3640
|
+
}
|
|
3526
3641
|
//#endregion
|
|
3527
|
-
export { JsonlCompressionSchema,
|
|
3642
|
+
export { Config, JsonlCompressionSchema, apply, name };
|