@morlay/dsh-session 0.0.0-stage → 0.2.0-alpha.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.
Files changed (64) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +27 -2
  3. package/dist/contract-DcuROwBE.mjs +263 -0
  4. package/dist/contract.d.mts +3 -0
  5. package/dist/contract.mjs +3 -0
  6. package/dist/decorate-g56z_1VW.mjs +8 -0
  7. package/dist/endpoint.d.mts +261 -0
  8. package/dist/endpoint.mjs +256 -0
  9. package/dist/index-CslqzhJh.d.mts +87 -0
  10. package/dist/index.d.mts +5 -0
  11. package/dist/index.mjs +5 -0
  12. package/dist/rolldown-runtime-3qf6kE1h.d.mts +1 -0
  13. package/dist/server.d.mts +23 -0
  14. package/dist/server.mjs +35 -0
  15. package/dist/testing.d.mts +213 -0
  16. package/dist/testing.mjs +840 -0
  17. package/dist/token-meter.contract-BoF6536N.d.mts +136 -0
  18. package/dist/token-meter.contract-CVJ4qB0S.mjs +20 -0
  19. package/dist/token-meter.service-B_UwV7QS.d.mts +45 -0
  20. package/dist/token-meter.service-DVClfYcN.mjs +83 -0
  21. package/dist/ui.d.mts +50 -0
  22. package/dist/ui.mjs +77 -0
  23. package/package.json +65 -3
  24. package/src/contract/events.ts +62 -0
  25. package/src/contract/index.ts +14 -0
  26. package/src/contract/session-format.contract.ts +18 -0
  27. package/src/contract/session-log.contract.ts +10 -0
  28. package/src/contract/session-projection-cache.contract.ts +33 -0
  29. package/src/contract/session-projection-store.contract.ts +47 -0
  30. package/src/contract/session-projection-value.contract.ts +10 -0
  31. package/src/contract/session-query-tracing.contract.ts +8 -0
  32. package/src/contract/session-query.contract.ts +140 -0
  33. package/src/contract/session-surface.contract.ts +5 -0
  34. package/src/contract/session-workspace.contract.ts +64 -0
  35. package/src/contract/session.contract.ts +72 -0
  36. package/src/contract/token-meter.contract.ts +22 -0
  37. package/src/endpoint/index.ts +9 -0
  38. package/src/endpoint/session-controller.remote.ts +13 -0
  39. package/src/endpoint/session-controller.ts +120 -0
  40. package/src/endpoint/session-endpoint.ts +443 -0
  41. package/src/endpoint/session-id.ts +8 -0
  42. package/src/index.ts +15 -0
  43. package/src/server/index.ts +19 -0
  44. package/src/server/session-projection-cache.provide.ts +5 -0
  45. package/src/server/session-projection.provide.ts +10 -0
  46. package/src/server/session-projection.registry.ts +4 -0
  47. package/src/server/session-query.provide.ts +5 -0
  48. package/src/server/session-stats.service.ts +18 -0
  49. package/src/server/session-store.plugin.ts +4 -0
  50. package/src/server/session.provide.ts +5 -0
  51. package/src/server/sessions-host.provide.ts +6 -0
  52. package/src/server/token-meter.provide.ts +5 -0
  53. package/src/session-projection-cache.service.ts +41 -0
  54. package/src/session-projection-store.service.ts +15 -0
  55. package/src/session-query.service.ts +37 -0
  56. package/src/session-turn-outline.service.ts +2 -0
  57. package/src/session.service.ts +12 -0
  58. package/src/testing/context.ts +35 -0
  59. package/src/testing/coordinator-contract.ts +496 -0
  60. package/src/testing/index.ts +25 -0
  61. package/src/testing/log.ts +385 -0
  62. package/src/token-meter.service.ts +14 -0
  63. package/src/ui/index.ts +4 -0
  64. package/src/ui/session-endpoint.client.ts +125 -0
@@ -0,0 +1,443 @@
1
+ // `session` 组的**跨端契约**:组名、方法名,与每个端点的 wire 形参 / 应答类型。
2
+ //
3
+ // **类型全部取上游**(`@deepseek-ai/dsh-api-session-controller/types`):wire 形状在那里定义,抄一遍只会
4
+ // 多一份会漂的声明(历史债:`SessionListValue` 曾写成 `{ ids, byId }`,上游是 `{ items }`)。
5
+ //
6
+ // **应答是裸值**:宿主是真相(上游 `SessionController` 的 `@Remote` 方法回裸值),`RemoteResult` 是
7
+ // 客户端面 `faceOf` 的包装,不进契约。
8
+ //
9
+ // **wire 形参名以宿主那一侧为准**(`@RemoteMethod({ parameters })`):本组的宿主是上游控制器,
10
+ // 网关按**它**的 descriptor 校验参数——`list` 的形参名是 `_request`(整组里唯一带下划线的),
11
+ // 其余是 `request`;写错就是真机上的 `unexpected "request"` / `missing "_request"`。
12
+ import type {
13
+ ModelCatalog,
14
+ ModelSelection,
15
+ PromptContentPart,
16
+ QueueAction,
17
+ SessionAttachmentRequest,
18
+ SessionAttachmentValue,
19
+ SessionCancelRequest,
20
+ SessionCancelValue,
21
+ SessionControlFrame,
22
+ SessionCreateRequest,
23
+ SessionCreateValue,
24
+ SessionEventFrame,
25
+ SessionEventsPage,
26
+ SessionObserveEventRequest,
27
+ SessionProjectionFrame,
28
+ SessionState,
29
+ SessionStateRequest,
30
+ SessionWaitRequest,
31
+ SessionWaitValue,
32
+ SessionFollowFrame,
33
+ SessionFollowRequest,
34
+ SessionForkRequest,
35
+ SessionForkValue,
36
+ SessionListRequest,
37
+ SessionListValue,
38
+ SessionOpenWorkspacePathRequest,
39
+ SessionOpenWorkspacePathValue,
40
+ SessionPageRequest,
41
+ SessionProjectionsRequest,
42
+ SessionProjectionsValue,
43
+ SessionPromptRequest,
44
+ SessionPromptValue,
45
+ SessionRenameRequest,
46
+ SessionRenameValue,
47
+ SessionSearchRequest,
48
+ SessionSearchValue,
49
+ SessionSelectModelRequest,
50
+ SessionSelectModelValue,
51
+ SessionSummary,
52
+ SessionUpdateQueueRequest,
53
+ SessionUpdateQueueValue,
54
+ SessionWorkspacePathApplication,
55
+ } from "@deepseek-ai/dsh-api-session-controller/types";
56
+ import type { AssertTrue, AssertWireFace } from "@morlay/zephyr-app/client";
57
+ import type { AsyncReturn, DropParam } from "@morlay/zephyr-app/typert";
58
+ import { RemoteGroup, RemoteMethod, groupNameOf } from "@morlay/zephyr-app/remote";
59
+ import type SessionControllerHost from "@deepseek-ai/dsh-api-session-controller";
60
+
61
+ // 上游同名的那些直接转出(消费方零改动):wire 的请求 / 应答就是它们。
62
+ export type {
63
+ ModelCatalog,
64
+ ModelSelection,
65
+ PromptContentPart,
66
+ QueueAction,
67
+ SessionAttachmentRequest,
68
+ SessionAttachmentValue,
69
+ SessionCancelRequest,
70
+ SessionCancelValue,
71
+ SessionControlFrame,
72
+ SessionCreateRequest,
73
+ SessionCreateValue,
74
+ SessionEventFrame,
75
+ SessionEventsPage,
76
+ SessionObserveEventRequest,
77
+ SessionProjectionFrame,
78
+ SessionState,
79
+ SessionStateRequest,
80
+ SessionWaitRequest,
81
+ SessionWaitValue,
82
+ SessionFollowFrame,
83
+ SessionFollowRequest,
84
+ SessionForkRequest,
85
+ SessionForkValue,
86
+ SessionListRequest,
87
+ SessionListValue,
88
+ SessionOpenWorkspacePathRequest,
89
+ SessionOpenWorkspacePathValue,
90
+ SessionPageRequest,
91
+ SessionProjectionsRequest,
92
+ SessionProjectionsValue,
93
+ SessionPromptRequest,
94
+ SessionPromptValue,
95
+ SessionRenameRequest,
96
+ SessionRenameValue,
97
+ SessionSearchRequest,
98
+ SessionSearchValue,
99
+ SessionSelectModelRequest,
100
+ SessionSelectModelValue,
101
+ SessionSummary,
102
+ SessionUpdateQueueRequest,
103
+ SessionUpdateQueueValue,
104
+ SessionWorkspacePathApplication,
105
+ };
106
+
107
+ /** 模型目录的应答(上游 `ModelCatalog`;旧名保留给消费方)。 */
108
+ export type SessionModelCatalogValue = ModelCatalog;
109
+
110
+ /** 目录里的一行(上游 `SessionSummary`;旧名保留给消费方)。 */
111
+ export type SessionSummaryRow = SessionSummary;
112
+
113
+ /** `session/page` 的应答(上游 `SessionEventsPage`;旧名保留给消费方)。 */
114
+ export type SessionPageValue = SessionEventsPage;
115
+
116
+ /** `session/follow` 的首帧(上游 `SessionFollowFrame` 的 `snapshot` 分支)。 */
117
+ export type SessionFollowSnapshot = Extract<SessionFollowFrame, { readonly type: "snapshot" }>;
118
+
119
+ /** 一个模型选择(上游 `ModelSelection`)。 */
120
+ export type SessionModelSelection = ModelSelection;
121
+
122
+ /**
123
+ * 组名(`session`):唯一 home 是下面契约类上的 `@RemoteGroup({ name })`。
124
+ * @returns wire 组名。
125
+ * @throws 契约类漏了装饰器(装配期就该发现,而不是把空组名塞进 deps)。
126
+ */
127
+ export function sessionGroupName(): string {
128
+ return groupNameOf(SessionEndpoint);
129
+ }
130
+ /** `session` 组:目录(建档 / 列表 / 翻页 / 跟随)、改名、选模型、分叉、搜索、投影与会话控制。 */
131
+ @RemoteGroup({ name: "session" })
132
+ export class SessionEndpoint {
133
+ /**
134
+ * 列出一条目录(上游 `{ items }`)。
135
+ * @param _request - 预留的空请求(wire 名 `_request`:整组里唯一带下划线的形参)。
136
+ * @returns 目录行。
137
+ */
138
+ @RemoteMethod({ parameters: ["_request"] })
139
+ async list(_request: SessionListRequest): Promise<SessionListValue> {
140
+ throw new Error("session/list:契约类未实现(宿主侧要在子类里实现它)");
141
+ }
142
+
143
+ /**
144
+ * 建一个会话(可复用已有的空白会话)。
145
+ * @param _request - 位置、可复用身份与 agent preset。
146
+ * @returns 会话身份。
147
+ */
148
+ @RemoteMethod({ parameters: ["request"] })
149
+ async create(_request: SessionCreateRequest): Promise<SessionCreateValue> {
150
+ throw new Error("session/create:契约类未实现(宿主侧要在子类里实现它)");
151
+ }
152
+
153
+ /**
154
+ * 读一页历史。
155
+ * @param _request - 目标会话与续读位置。
156
+ * @returns 这一页与是否还有更多。
157
+ */
158
+ @RemoteMethod({ parameters: ["request"] })
159
+ async page(_request: SessionPageRequest): Promise<SessionEventsPage> {
160
+ throw new Error("session/page:契约类未实现(宿主侧要在子类里实现它)");
161
+ }
162
+
163
+ /**
164
+ * 打开一个会话窗口:先给基线快照,之后逐帧推事件,直到取消。
165
+ * @param _request - 目标会话。
166
+ * @param _signal - 宿主侧的取消通道(载具注入,不是 wire 参数)。
167
+ * @returns 基线快照与后续事件帧。
168
+ */
169
+ @RemoteMethod({ mode: "stream", parameters: ["request"] })
170
+ follow(_request: SessionFollowRequest, _signal: AbortSignal): AsyncIterable<SessionFollowFrame> {
171
+ throw new Error("session/follow:契约类未实现(宿主侧要在子类里实现它)");
172
+ }
173
+
174
+ /**
175
+ * Host 级的投影状态流:一帧基线,之后逐条投影增量,直到取消。
176
+ * @param _signal - 宿主侧的取消通道(载波注入,不是 wire 参数)。
177
+ * @returns baseline 与后续增量帧。
178
+ */
179
+ @RemoteMethod({ mode: "stream", parameters: [] })
180
+ control(_signal: AbortSignal): AsyncIterable<SessionControlFrame> {
181
+ throw new Error("session/control:契约类未实现(宿主侧要在子类里实现它)");
182
+ }
183
+
184
+ /**
185
+ * 改一个会话的标题。
186
+ * @param _request - 会话与提议的标题。
187
+ * @returns 被接受的标题与事件位置。
188
+ */
189
+ @RemoteMethod({ parameters: ["request"] })
190
+ async rename(_request: SessionRenameRequest): Promise<SessionRenameValue> {
191
+ throw new Error("session/rename:契约类未实现(宿主侧要在子类里实现它)");
192
+ }
193
+
194
+ /**
195
+ * 选模型。
196
+ * @param _request - 会话与模型选择。
197
+ * @returns 结算后的选择。
198
+ */
199
+ @RemoteMethod({ parameters: ["request"] })
200
+ async selectModel(_request: SessionSelectModelRequest): Promise<SessionSelectModelValue> {
201
+ throw new Error("session/selectModel:契约类未实现(宿主侧要在子类里实现它)");
202
+ }
203
+
204
+ /**
205
+ * 从某个前缀分叉。
206
+ * @param _request - 源会话与分叉位置。
207
+ * @returns 子会话身份。
208
+ */
209
+ @RemoteMethod({ parameters: ["request"] })
210
+ async fork(_request: SessionForkRequest): Promise<SessionForkValue> {
211
+ throw new Error("session/fork:契约类未实现(宿主侧要在子类里实现它)");
212
+ }
213
+
214
+ /**
215
+ * 全文搜索。
216
+ * @param _request - 查询。
217
+ * @returns 命中与是否有更多。
218
+ */
219
+ @RemoteMethod({ parameters: ["request"] })
220
+ async search(_request: SessionSearchRequest): Promise<SessionSearchValue> {
221
+ throw new Error("session/search:契约类未实现(宿主侧要在子类里实现它)");
222
+ }
223
+
224
+ /**
225
+ * 模型目录。
226
+ * @returns provider 分组与失败项。
227
+ */
228
+ @RemoteMethod({ parameters: [] })
229
+ async modelCatalog(): Promise<ModelCatalog> {
230
+ throw new Error("session/modelCatalog:契约类未实现(宿主侧要在子类里实现它)");
231
+ }
232
+
233
+ /** 初始化默认模型选择(首轮前调一次)。 */
234
+ @RemoteMethod({ parameters: [] })
235
+ async initializeDefaultModel(): Promise<void> {
236
+ throw new Error("session/initializeDefaultModel:契约类未实现(宿主侧要在子类里实现它)");
237
+ }
238
+
239
+ /** 宿主能不能「在文件管理器里打开」某个工作区路径。 */
240
+ @RemoteMethod({ parameters: [] })
241
+ async canOpenWorkspacePath(): Promise<boolean> {
242
+ throw new Error("session/canOpenWorkspacePath:契约类未实现(宿主侧要在子类里实现它)");
243
+ }
244
+
245
+ /**
246
+ * 给会话投递一段输入。
247
+ * @param _request - 输入与投递模式。
248
+ * @returns 受理回执。
249
+ */
250
+ @RemoteMethod({ parameters: ["request"] })
251
+ async prompt(_request: SessionPromptRequest): Promise<SessionPromptValue> {
252
+ throw new Error("session/prompt:契约类未实现(宿主侧要在子类里实现它)");
253
+ }
254
+
255
+ /**
256
+ * 取消当前这一轮。
257
+ * @param _request - 目标会话。
258
+ * @returns 受理回执。
259
+ */
260
+ @RemoteMethod({ parameters: ["request"] })
261
+ async cancel(_request: SessionCancelRequest): Promise<SessionCancelValue> {
262
+ throw new Error("session/cancel:契约类未实现(宿主侧要在子类里实现它)");
263
+ }
264
+
265
+ /**
266
+ * 改一条排队中的输入。
267
+ * @param _request - 目标条目与动作。
268
+ * @returns 受理回执。
269
+ */
270
+ @RemoteMethod({ parameters: ["request"] })
271
+ async updateQueue(_request: SessionUpdateQueueRequest): Promise<SessionUpdateQueueValue> {
272
+ throw new Error("session/updateQueue:契约类未实现(宿主侧要在子类里实现它)");
273
+ }
274
+
275
+ /**
276
+ * 某个路径可用的「打开方式」列表。
277
+ * @param _request - 目标路径。
278
+ * @returns 应用列表。
279
+ */
280
+ @RemoteMethod({ parameters: ["request"] })
281
+ async workspacePathApplications(
282
+ _request: SessionOpenWorkspacePathRequest,
283
+ ): Promise<readonly SessionWorkspacePathApplication[]> {
284
+ throw new Error("session/workspacePathApplications:契约类未实现(宿主侧要在子类里实现它)");
285
+ }
286
+
287
+ /**
288
+ * 读一条会话里的图片附件。
289
+ * @param _request - 会话与附件引用。
290
+ * @returns 校验过的引用与数据。
291
+ */
292
+ @RemoteMethod({ parameters: ["request"] })
293
+ async attachment(_request: SessionAttachmentRequest): Promise<SessionAttachmentValue> {
294
+ throw new Error("session/attachment:契约类未实现(宿主侧要在子类里实现它)");
295
+ }
296
+
297
+ /**
298
+ * 读一页事件(`session/page` 的旧别名)。
299
+ * @param _request - 目标会话与位置。
300
+ * @returns 这一页。
301
+ */
302
+ @RemoteMethod({ parameters: ["request"] })
303
+ async events(_request: SessionPageRequest): Promise<SessionEventsPage> {
304
+ throw new Error("session/events:契约类未实现(宿主侧要在子类里实现它)");
305
+ }
306
+
307
+ /**
308
+ * 在宿主的文件管理器里打开一个工作区路径。
309
+ * @param _request - 路径与打开方式。
310
+ * @returns 打开结果。
311
+ */
312
+ @RemoteMethod({ parameters: ["request"] })
313
+ async openWorkspacePath(
314
+ _request: SessionOpenWorkspacePathRequest,
315
+ ): Promise<SessionOpenWorkspacePathValue> {
316
+ throw new Error("session/openWorkspacePath:契约类未实现(宿主侧要在子类里实现它)");
317
+ }
318
+
319
+ /**
320
+ * 读一份投影快照。
321
+ * @param _request - 会话与投影键。
322
+ * @returns 投影值。
323
+ */
324
+ @RemoteMethod({ parameters: ["request"] })
325
+ async projections(_request: SessionProjectionsRequest): Promise<SessionProjectionsValue> {
326
+ throw new Error("session/projections:契约类未实现(宿主侧要在子类里实现它)");
327
+ }
328
+
329
+ /**
330
+ * 观察一个会话的事件流(上游 `SessionEventFrame`)。
331
+ * @param _request - 目标会话地址。
332
+ * @param _signal - 宿主侧的取消通道(载具注入,不是 wire 参数)。
333
+ * @returns 逐帧的事件。
334
+ */
335
+ @RemoteMethod({ mode: "stream", parameters: ["request"] })
336
+ observeEvent(
337
+ _request: SessionObserveEventRequest,
338
+ _signal: AbortSignal,
339
+ ): AsyncIterable<SessionEventFrame> {
340
+ throw new Error("session/observeEvent:契约类未实现(宿主侧要在子类里实现它)");
341
+ }
342
+
343
+ /**
344
+ * 观察一个会话的投影变化流。
345
+ * @param _request - 目标会话地址。
346
+ * @param _signal - 宿主侧的取消通道。
347
+ * @returns 逐帧的投影变化。
348
+ */
349
+ @RemoteMethod({ mode: "stream", parameters: ["request"] })
350
+ observeProjections(
351
+ _request: SessionProjectionsRequest,
352
+ _signal: AbortSignal,
353
+ ): AsyncIterable<SessionProjectionFrame> {
354
+ throw new Error("session/observeProjections:契约类未实现(宿主侧要在子类里实现它)");
355
+ }
356
+
357
+ /**
358
+ * 读一次会话状态(运行中 / 队列 / 待处理输入)。
359
+ * @param _request - 目标会话地址。
360
+ * @returns 这一拍的状态。
361
+ */
362
+ @RemoteMethod({ parameters: ["request"] })
363
+ async state(_request: SessionStateRequest): Promise<SessionState> {
364
+ throw new Error("session/state:契约类未实现(宿主侧要在子类里实现它)");
365
+ }
366
+
367
+ /**
368
+ * 观察会话状态的帧流。
369
+ * @param _request - 目标会话地址。
370
+ * @param _signal - 宿主侧的取消通道。
371
+ * @returns 逐帧的状态。
372
+ */
373
+ @RemoteMethod({ mode: "stream", parameters: ["request"] })
374
+ observeState(_request: SessionStateRequest, _signal: AbortSignal): AsyncIterable<SessionState> {
375
+ throw new Error("session/observeState:契约类未实现(宿主侧要在子类里实现它)");
376
+ }
377
+
378
+ /**
379
+ * 等这一轮结算(上游 `SessionWaitValue`)。
380
+ * @param _request - 目标会话与等待条件。
381
+ * @returns 等待结果。
382
+ */
383
+ @RemoteMethod({ parameters: ["request"] })
384
+ async wait(_request: SessionWaitRequest): Promise<SessionWaitValue> {
385
+ throw new Error("session/wait:契约类未实现(宿主侧要在子类里实现它)");
386
+ }
387
+ }
388
+ /** 本组覆盖的 **unary** 端点(显式列出:按 `keyof` 取会放过「契约掉了一个端点」)。 */
389
+ type UnaryEndpoints =
390
+ | "list"
391
+ | "create"
392
+ | "page"
393
+ | "rename"
394
+ | "selectModel"
395
+ | "fork"
396
+ | "search"
397
+ | "modelCatalog"
398
+ | "initializeDefaultModel"
399
+ | "canOpenWorkspacePath"
400
+ | "prompt"
401
+ | "cancel"
402
+ | "updateQueue"
403
+ | "workspacePathApplications"
404
+ | "attachment"
405
+ | "events"
406
+ | "openWorkspacePath"
407
+ | "projections"
408
+ | "state"
409
+ | "wait";
410
+
411
+ /** 本组覆盖的**流式**端点。 */
412
+ type StreamEndpoints =
413
+ | "follow"
414
+ | "control"
415
+ | "observeEvent"
416
+ | "observeProjections"
417
+ | "observeState";
418
+
419
+ /**
420
+ * 上游 `session` 的 **wire 面**:宿主类 `SessionController` 的三步投影(规则与出处见
421
+ * `@morlay/zephyr-app/typert` 的 `params.ts`):去末尾 `signal`(走 cancellation)→ `AsyncReturn`
422
+ * (unary 异步化;`AsyncIterable` 不包 `Promise`)。本组没有 lookup 形参(`sessionId` 在请求体里)。
423
+ */
424
+ type SessionWire = AsyncReturn<DropParam<SessionControllerHost, AbortSignal>>;
425
+
426
+ /**
427
+ * 覆盖守卫(unary):契约对上宿主类的 wire 面(形参与返回**双向**,见 `AssertWireFace`)。
428
+ */
429
+ export type SessionEndpointCovered = AssertTrue<
430
+ AssertWireFace<Pick<SessionWire, UnaryEndpoints>, Pick<SessionEndpoint, UnaryEndpoints>>
431
+ >;
432
+
433
+ /**
434
+ * 覆盖守卫(流式):**契约侧也要把末尾那个取消信号摘掉再比**——那个 `signal` 是宿主侧的取消通道
435
+ * (载具注入,`registerRemoteGroup` 按 `handler.length >= 2` 传),不是 wire 参数;宿主类的原文同样带它。
436
+ * 这套做法在 `workspaceFiles` 的 `changes` 上验过。
437
+ */
438
+ export type SessionEndpointStreamCovered = AssertTrue<
439
+ AssertWireFace<
440
+ Pick<SessionWire, StreamEndpoints>,
441
+ Pick<DropParam<SessionEndpoint, AbortSignal>, StreamEndpoints>
442
+ >
443
+ >;
@@ -0,0 +1,8 @@
1
+ // 会话身份的**两端共用面**:品牌铸造函数与上游会话类型。
2
+ //
3
+ // 住 `./endpoint` 而不是包根或单独的 `contract` 面:浏览器半(`./ui`)也要 `SessionId()`,
4
+ // 而包根聚合了 host 实现(`*.host.ts` / `*.service.ts`),引包根会把 node-only 运行时拖进浏览器;
5
+ // 两端共用的声明只有 `endpoint` 与 `ui` 两个出口,不额外开 `contract`。
6
+ // 走上游的 `types` 子路径而不是包根:包根会把 llm 的运行时(`createRequire`)拖进浏览器。
7
+ export type { SessionEvent, SessionHeader } from "@deepseek-ai/dsh-session/types";
8
+ export { SessionId } from "@deepseek-ai/dsh-session/types";
package/src/index.ts ADDED
@@ -0,0 +1,15 @@
1
+ export * from "./contract/index.ts";
2
+ // 上游会话的门面在 `./contract`(`session-id.ts`):包根只聚合契约与默认实现,
3
+ // 浏览器半要的值(`SessionId`)从 `./contract` 取,不从包根取。
4
+ // 会话域:核心(生命周期 / 投影 / 查询 / token 计量)的契约与默认实现都在根上——它们拆不开。
5
+ // **装配函数不在根上**:宿主面在 `./server`、浏览器面在 `./ui`(装配面只从这两个面取 `provideXxx`)。
6
+ // 两个子域各有出口、都不从这里导出:`./session-title`(独立能力)与 `./checkpoint-policy`(它依赖 agent,
7
+ // 放根会让会话核心反向依赖 agent)。
8
+ export * from "./session.service.ts";
9
+ export * from "./session-projection-store.service.ts";
10
+ export * from "./session-projection-cache.service.ts";
11
+ export * from "./session-query.service.ts";
12
+ export * from "./token-meter.service.ts";
13
+ // 事件统一放在 `Events` 命名空间下:不与服务混在同一个出口里,消费处一眼看出这是事件。
14
+ export * as Events from "./contract/events.ts";
15
+ export * from "./session-turn-outline.service.ts";
@@ -0,0 +1,19 @@
1
+ // session 的**宿主半**(`@morlay/dsh-session/server`):宿主面的装配函数 + wire 端点实现。
2
+ //
3
+ // 装配面只从这里取 `provideXxx`(host 侧);浏览器半在 `./ui`,契约与默认实现在包根。
4
+ export { provideSession } from "./session.provide.ts";
5
+
6
+ export * from "./session-projection.registry.ts";
7
+ export * from "./session-store.plugin.ts";
8
+
9
+ // 会话宿主的行实现(host 侧;root 不再导出,浏览器半取不到它们)。
10
+ export { provideSessionProjection } from "./session-projection.provide.ts";
11
+ export { provideSessionProjectionCache } from "./session-projection-cache.provide.ts";
12
+ export { provideSessionQuerySqlite } from "./session-query.provide.ts";
13
+ export { provideTokenMeter } from "./token-meter.provide.ts";
14
+ export { provideSessionsHost } from "./sessions-host.provide.ts";
15
+
16
+ // 上游会话的宿主机常量(浏览器半不需要,放这里避免把上游 index 拖进 client)。
17
+ export { SESSION_FORMAT_VERSION, SessionLogOffset } from "@deepseek-ai/dsh-session";
18
+ export { SessionStatsDefault } from "./session-stats.service.ts";
19
+ export { TokenMeter } from "@deepseek-ai/dsh-token-meter";
@@ -0,0 +1,5 @@
1
+ import { provide } from "@morlay/zephyr";
2
+ import { SessionProjectionCacheDefault } from "../session-projection-cache.service.ts";
3
+
4
+ /** 投影缓存:写穿节流的默认值在实现类里,装配面可 `configure` 覆盖。 */
5
+ export const provideSessionProjectionCache = provide([SessionProjectionCacheDefault]);
@@ -0,0 +1,10 @@
1
+ import { provide } from "@morlay/zephyr";
2
+ import { SessionProjectionStoreDefault } from "../session-projection-store.service.ts";
3
+ import { SessionStatsDefault } from "./session-stats.service.ts";
4
+
5
+ /** 会话投影:`SessionControllerHost` 建 agent 前的 `Session` 观测来源。 */
6
+ // 投影注册表在前,投影单元(`sessionStats`)在后:后者在 `apply` 里就 `register`。
7
+ export const provideSessionProjection = provide([
8
+ SessionProjectionStoreDefault,
9
+ SessionStatsDefault,
10
+ ]);
@@ -0,0 +1,4 @@
1
+ // 上游 `SessionProjectionRegistry` 的**实现类**(cordis Service):装配面要自己 `new` 它时从这里取。
2
+ //
3
+ // 契约面只有 `SessionProjectionStore` 端口;实现类属宿主半。
4
+ export { default as SessionProjectionRegistry } from "@deepseek-ai/dsh-session-projection";
@@ -0,0 +1,5 @@
1
+ import { provide } from "@morlay/zephyr";
2
+ import { SessionQuerySqlite } from "../session-query.service.ts";
3
+
4
+ /** 会话查询(sqlite):默认配置在实现类里(内存库、不自动打开),装配面可 `configure` 覆盖。 */
5
+ export const provideSessionQuerySqlite = provide([SessionQuerySqlite]);
@@ -0,0 +1,18 @@
1
+ // 会话统计投影(上游 `session-stats`):整条日志的轮数 / 步数,以及 LLM、工具、首字、解码的墙钟时长。
2
+ //
3
+ // 客户端的 `ui-chat` 用它渲染输入区下方那两枚统计 pills(`activity` / `usage`);
4
+ // 没有这个投影单元时它会退回「窗口内节点」的估算,翻页与压缩之后就只统计到一段。
5
+ import * as SessionStatsPlugin from "@deepseek-ai/dsh-session-stats";
6
+ import { inject, Injectable, type Context } from "@morlay/zephyr";
7
+ import { fromCordis } from "@morlay/zephyr/compat";
8
+ import { SessionProjectionStore } from "../contract/session-projection-store.contract.ts";
9
+
10
+ @Injectable()
11
+ export class SessionStatsDefault extends fromCordis(SessionStatsPlugin) {
12
+ private readonly projections = inject(SessionProjectionStore);
13
+
14
+ override async onInit(ctx: Context): Promise<void> {
15
+ // 上游按 `ctx.sessionProjections` 读;`register` 走的是同一个注册表,这里直接给契约面。
16
+ await this.mount(ctx, undefined, { sessionProjections: this.projections });
17
+ }
18
+ }
@@ -0,0 +1,4 @@
1
+ // 上游 `SessionStore` 的**实现类**(cordis Service):装配面要自己 `new` 它时从这里取。
2
+ //
3
+ // 契约面已经有同名端口 `SessionStore`(`@Injectable()` 抽象类),所以这里带 `Plugin` 后缀。
4
+ export { default as SessionStorePlugin } from "@deepseek-ai/dsh-session";
@@ -0,0 +1,5 @@
1
+ import { provide } from "@morlay/zephyr";
2
+ import { SessionStoreDefault } from "../session.service.ts";
3
+
4
+ /** 会话存储(真 store):`get` / `list` 都从这里来。 */
5
+ export const provideSession = provide([SessionStoreDefault]);
@@ -0,0 +1,6 @@
1
+ import { provide } from "@morlay/zephyr";
2
+ import { SessionStoreDefault } from "../session.service.ts";
3
+
4
+ // `remote.session` 的**会话存储**面:只装真 store(`get` / `list` 都从这里来)。
5
+ // 端点由上游 `SessionController` 那一族行提供,见 `provideSessionRemote()`。
6
+ export const provideSessionsHost = provide([SessionStoreDefault]);
@@ -0,0 +1,5 @@
1
+ import { provide } from "@morlay/zephyr";
2
+ import { TokenMeterDefault } from "../token-meter.service.ts";
3
+
4
+ /** 令牌计量:按会话累计 token 用量。 */
5
+ export const provideTokenMeter = provide([TokenMeterDefault]);
@@ -0,0 +1,41 @@
1
+ import SessionProjectionCacheService, {
2
+ type Config as SessionProjectionCacheConfig,
3
+ } from "@deepseek-ai/dsh-session-projection-cache";
4
+ import { Injectable, inject, type Context } from "@morlay/zephyr";
5
+ import { fromCordis } from "@morlay/zephyr/compat";
6
+ import { StorageDomain } from "@morlay/dsh-storage";
7
+ import { SessionStore } from "./contract/session.contract.ts";
8
+ import { SessionProjectionStore } from "./contract/session-projection-store.contract.ts";
9
+ import { SessionProjectionCache } from "./contract/session-projection-cache.contract.ts";
10
+
11
+ /** 默认配置:每 200 个事件或 5s 写一次(装配面用 `configure` 覆盖)。 */
12
+ const DEFAULT_CONFIG: SessionProjectionCacheConfig = {
13
+ writeEveryEvents: 200,
14
+ writeIntervalMs: 5000,
15
+ };
16
+
17
+ // 上游实现(一份 per-record KV + 写穿 checkpoint)。
18
+ @Injectable()
19
+ export class SessionProjectionCacheDefault extends fromCordis(
20
+ SessionProjectionCache,
21
+ SessionProjectionCacheService,
22
+ ) {
23
+ storageDomain = inject(StorageDomain);
24
+
25
+ sessionProjections = inject(SessionProjectionStore);
26
+
27
+ sessions = inject(SessionStore);
28
+
29
+ /** 行配置(清单条目的 `config`,`configure` 可覆盖):基类已接住,缺省用本文件的 `DEFAULT_CONFIG`。 */
30
+ private get rowOptions(): SessionProjectionCacheConfig {
31
+ return (this.rowConfig ?? DEFAULT_CONFIG) as SessionProjectionCacheConfig;
32
+ }
33
+
34
+ override async onInit(ctx: Context): Promise<void> {
35
+ await this.mount(ctx, this.rowOptions, {
36
+ storageDomain: this.storageDomain,
37
+ sessionProjections: this.sessionProjections,
38
+ sessions: this.sessions,
39
+ });
40
+ }
41
+ }
@@ -0,0 +1,15 @@
1
+ import { SessionProjectionRegistry } from "@deepseek-ai/dsh-session-projection";
2
+ import { Injectable, type Context } from "@morlay/zephyr";
3
+ import { fromCordis } from "@morlay/zephyr/compat";
4
+ import { SessionProjectionStore } from "./contract/session-projection-store.contract.ts";
5
+
6
+ @Injectable()
7
+ export class SessionProjectionStoreDefault extends fromCordis(
8
+ SessionProjectionStore,
9
+ SessionProjectionRegistry,
10
+ ) {
11
+ /** 上游投影注册表没有声明依赖:`mount` 只挂它自己(不传 deps,也不传 config)。 */
12
+ override async onInit(ctx: Context): Promise<void> {
13
+ await this.mount(ctx);
14
+ }
15
+ }
@@ -0,0 +1,37 @@
1
+ import SqliteSessionQuerySqliteEngine, {
2
+ type Config as SqliteQueryConfig,
3
+ } from "@deepseek-ai/dsh-session-query-sqlite";
4
+ import { SessionQuery } from "./contract/session-query.contract.ts";
5
+ import { Injectable, inject, type Context } from "@morlay/zephyr";
6
+ import { fromCordis } from "@morlay/zephyr/compat";
7
+ import { SessionStore } from "./contract/session.contract.ts";
8
+ import { SessionProjectionStore } from "./contract/session-projection-store.contract.ts";
9
+
10
+ /** 默认配置:内存库、不自动打开(装配面用 `configure` 覆盖)。 */
11
+ const DEFAULT_CONFIG: SqliteQueryConfig = { path: ":memory:", openAt: "never" };
12
+
13
+ @Injectable()
14
+ export class SessionQuerySqlite extends fromCordis(SessionQuery, SqliteSessionQuerySqliteEngine) {
15
+ sessions = inject(SessionStore);
16
+
17
+ /**
18
+ * 上游引擎在 `observeSession` 里用 `ctx.get('sessionProjections')?.snapshot(session)` 算投影快照——
19
+ * **可选**能力(上游 `inject` 不声明它)。所以这里按 optional 注入、随 mount 交出:装了投影行就给到
20
+ * 它的契约面,没装就与上游同语义地缺省(症状对照:看不到它时 `requires a projected Session observation`)。
21
+ */
22
+ sessionProjections = inject.optional(SessionProjectionStore);
23
+
24
+ /** 行配置(清单条目的 `config`,`configure` 可覆盖):基类已接住,缺省用本文件的 `DEFAULT_CONFIG`。 */
25
+ private get rowOptions(): SqliteQueryConfig {
26
+ return (this.rowConfig ?? DEFAULT_CONFIG) as SqliteQueryConfig;
27
+ }
28
+
29
+ override async onInit(ctx: Context): Promise<void> {
30
+ await this.mount(ctx, this.rowOptions, {
31
+ sessions: this.sessions,
32
+ ...(this.sessionProjections === undefined
33
+ ? {}
34
+ : { sessionProjections: this.sessionProjections }),
35
+ });
36
+ }
37
+ }
@@ -0,0 +1,2 @@
1
+ // 上游 `session-turn-outline` 的**投影单元插件**:折出回合轮廓,归会话域(数据面)。
2
+ export * as SessionTurnOutline from "@deepseek-ai/dsh-session-turn-outline";