@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.
- package/LICENSE +21 -0
- package/README.md +27 -2
- package/dist/contract-DcuROwBE.mjs +263 -0
- package/dist/contract.d.mts +3 -0
- package/dist/contract.mjs +3 -0
- package/dist/decorate-g56z_1VW.mjs +8 -0
- package/dist/endpoint.d.mts +261 -0
- package/dist/endpoint.mjs +256 -0
- package/dist/index-CslqzhJh.d.mts +87 -0
- package/dist/index.d.mts +5 -0
- package/dist/index.mjs +5 -0
- package/dist/rolldown-runtime-3qf6kE1h.d.mts +1 -0
- package/dist/server.d.mts +23 -0
- package/dist/server.mjs +35 -0
- package/dist/testing.d.mts +213 -0
- package/dist/testing.mjs +840 -0
- package/dist/token-meter.contract-BoF6536N.d.mts +136 -0
- package/dist/token-meter.contract-CVJ4qB0S.mjs +20 -0
- package/dist/token-meter.service-B_UwV7QS.d.mts +45 -0
- package/dist/token-meter.service-DVClfYcN.mjs +83 -0
- package/dist/ui.d.mts +50 -0
- package/dist/ui.mjs +77 -0
- package/package.json +65 -3
- package/src/contract/events.ts +62 -0
- package/src/contract/index.ts +14 -0
- package/src/contract/session-format.contract.ts +18 -0
- package/src/contract/session-log.contract.ts +10 -0
- package/src/contract/session-projection-cache.contract.ts +33 -0
- package/src/contract/session-projection-store.contract.ts +47 -0
- package/src/contract/session-projection-value.contract.ts +10 -0
- package/src/contract/session-query-tracing.contract.ts +8 -0
- package/src/contract/session-query.contract.ts +140 -0
- package/src/contract/session-surface.contract.ts +5 -0
- package/src/contract/session-workspace.contract.ts +64 -0
- package/src/contract/session.contract.ts +72 -0
- package/src/contract/token-meter.contract.ts +22 -0
- package/src/endpoint/index.ts +9 -0
- package/src/endpoint/session-controller.remote.ts +13 -0
- package/src/endpoint/session-controller.ts +120 -0
- package/src/endpoint/session-endpoint.ts +443 -0
- package/src/endpoint/session-id.ts +8 -0
- package/src/index.ts +15 -0
- package/src/server/index.ts +19 -0
- package/src/server/session-projection-cache.provide.ts +5 -0
- package/src/server/session-projection.provide.ts +10 -0
- package/src/server/session-projection.registry.ts +4 -0
- package/src/server/session-query.provide.ts +5 -0
- package/src/server/session-stats.service.ts +18 -0
- package/src/server/session-store.plugin.ts +4 -0
- package/src/server/session.provide.ts +5 -0
- package/src/server/sessions-host.provide.ts +6 -0
- package/src/server/token-meter.provide.ts +5 -0
- package/src/session-projection-cache.service.ts +41 -0
- package/src/session-projection-store.service.ts +15 -0
- package/src/session-query.service.ts +37 -0
- package/src/session-turn-outline.service.ts +2 -0
- package/src/session.service.ts +12 -0
- package/src/testing/context.ts +35 -0
- package/src/testing/coordinator-contract.ts +496 -0
- package/src/testing/index.ts +25 -0
- package/src/testing/log.ts +385 -0
- package/src/token-meter.service.ts +14 -0
- package/src/ui/index.ts +4 -0
- package/src/ui/session-endpoint.client.ts +125 -0
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import { AgentCancelCause, SESSION_FORMAT_VERSION, Session, SessionEvent, SessionEventMap, SessionEventType, SessionHeader, SessionId, SessionLogOffset, SessionSeq, SessionSeqCursor, SessionStore as SessionStore$1, SurfaceOp } from "@deepseek-ai/dsh-session";
|
|
2
|
+
import { ProjectionHandle, SessionProjectionRegistry } from "@deepseek-ai/dsh-session-projection";
|
|
3
|
+
import { CheckpointIdentity, SessionProjectionCache as SessionProjectionCache$1 } from "@deepseek-ai/dsh-session-projection-cache";
|
|
4
|
+
import { AssertCoveredStrict, AssertTrue } from "@morlay/zephyr-app/client";
|
|
5
|
+
import { SESSION_QUERY_READ_WINDOW_MAX, SessionEventReadRequest, SessionEventRecord, SessionEventResultFilter, SessionEventSearchDocument, SessionEventSearchPage, SessionEventTraceObservation, SessionEventWindow, SessionLineageTrace, SessionListMetadata, SessionLogSnapshot, SessionObservation, SessionObservationOptions, SessionQueryEngine, SessionQueryEngine as SessionQueryEngine$1, SessionQueryError, SessionRecord, SessionResultFilter, SessionResultRange, SessionSearchHit, SessionSearchPage, SessionSurfaceSnapshot, SessionTitleObservation, SessionTitleObservationResult, buildSessionEventRecords, buildSessionEventSearchDocuments, extractSessionEventText, filterSessionEventDocuments, materializeSessionEventResultFilters, materializeSessionResultFilters } from "@deepseek-ai/dsh-session-query";
|
|
6
|
+
import TokenMeterService from "@deepseek-ai/dsh-token-meter";
|
|
7
|
+
declare abstract class SessionProjectionCache {
|
|
8
|
+
abstract readonly config: SessionProjectionCache$1["config"];
|
|
9
|
+
abstract readonly cachedSnapshot: SessionProjectionCache$1["cachedSnapshot"];
|
|
10
|
+
abstract readonly cachedPredecessorTitle: SessionProjectionCache$1["cachedPredecessorTitle"];
|
|
11
|
+
abstract readonly hydratePrepared: SessionProjectionCache$1["hydratePrepared"];
|
|
12
|
+
abstract readonly write: SessionProjectionCache$1["write"];
|
|
13
|
+
abstract readonly coldSnapshot: SessionProjectionCache$1["coldSnapshot"];
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* 覆盖守卫(严格):上游 `SessionProjectionCacheService` 的每个成员都要有同名、同签名的对应项。
|
|
17
|
+
*
|
|
18
|
+
* 为什么不是 `implements`:上游那份是 cordis `Service` **类**(带私有成员),`implements` 会报
|
|
19
|
+
* TS2720("Did you mean to extend … and inherit its members as a subclass?")。签名守卫在这里等价:
|
|
20
|
+
* 漏成员或签名对不上,编译期都会报出成员名(诊断的第二行)。
|
|
21
|
+
*/
|
|
22
|
+
type SessionProjectionCacheCovered = AssertTrue<AssertCoveredStrict<SessionProjectionCache$1, SessionProjectionCache>>;
|
|
23
|
+
/** 投影注册表:按会话状态键登记投影,并读取当前快照。 */
|
|
24
|
+
declare abstract class SessionProjectionStore {
|
|
25
|
+
abstract readonly register: SessionProjectionRegistry["register"];
|
|
26
|
+
abstract readonly onChanged: SessionProjectionRegistry["onChanged"];
|
|
27
|
+
abstract readonly stateOf: SessionProjectionRegistry["stateOf"];
|
|
28
|
+
abstract readonly snapshot: SessionProjectionRegistry["snapshot"];
|
|
29
|
+
abstract readonly cachedSnapshot: SessionProjectionRegistry["cachedSnapshot"];
|
|
30
|
+
abstract readonly checkpoint: SessionProjectionRegistry["checkpoint"];
|
|
31
|
+
abstract readonly restoreFloor: SessionProjectionRegistry["restoreFloor"];
|
|
32
|
+
abstract readonly viewCheckpoint: SessionProjectionRegistry["viewCheckpoint"];
|
|
33
|
+
abstract readonly restore: SessionProjectionRegistry["restore"];
|
|
34
|
+
abstract readonly hydrate: SessionProjectionRegistry["hydrate"];
|
|
35
|
+
abstract readonly summaryKeys: SessionProjectionRegistry["summaryKeys"];
|
|
36
|
+
/** 投影事件变化的订阅口(上游按它把 `session/event` 的投影变化喂给订阅者)。 */
|
|
37
|
+
abstract readonly onEventChanged: SessionProjectionRegistry["onEventChanged"];
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* 覆盖守卫(严格):上游 `SessionProjectionRegistry` 的每个成员都要有同名、同签名的对应项。
|
|
41
|
+
*
|
|
42
|
+
* 为什么不是 `implements`:上游那份是 cordis `Service` **类**(带私有成员),`implements` 会报
|
|
43
|
+
* TS2720("Did you mean to extend … and inherit its members as a subclass?")。签名守卫在这里等价:
|
|
44
|
+
* 漏成员或签名对不上,编译期都会报出成员名(诊断的第二行)。
|
|
45
|
+
*/
|
|
46
|
+
type SessionProjectionStoreCovered = AssertTrue<AssertCoveredStrict<SessionProjectionRegistry, SessionProjectionStore>>;
|
|
47
|
+
/**
|
|
48
|
+
* 会话查询:浏览 / 搜索 / 列表 / 读取。
|
|
49
|
+
*
|
|
50
|
+
* :装配期与派生名 `session-query` **并存**
|
|
51
|
+
* 发布同一个实例(`bootstrap.ts` 的别名发布),不是第二份实现。必须叫这个名字,是因为上游有六个读者
|
|
52
|
+
* 按驼峰名读 `this.ctx.sessionQuery`(`SessionReferenceResolver`、`SessionController` 与它的
|
|
53
|
+
* history / skill-catalog、`SubagentManager`、`ui-deliverables` …);而经 wire(typert gateway)分派时,
|
|
54
|
+
* cordis 会用**调用方**的 ctx 重建服务的 `this.ctx`(`createTraceable`),上游名只在 root store 里查:
|
|
55
|
+
* 少了它就读到 `undefined`(症状:`sessionReferenceResolver/candidates` 抛
|
|
56
|
+
* `Cannot read properties of undefined (reading 'listSessions')`)。
|
|
57
|
+
*
|
|
58
|
+
* 实现有两份,都在本仓库里,装配面选一份:
|
|
59
|
+
* - `packages/agent/dsh-session` 的 `SessionQuerySqlite`——上游 `session-query-sqlite` engine 的适配行(默认);
|
|
60
|
+
* - `packages/agent-ex/better-session` 的 `SessionQueryRdb`——直读 RDB 的替换实现。
|
|
61
|
+
*
|
|
62
|
+
* 装配面用一句 `without(SessionQuerySqlite)` 选后者(`apps/zephyr-custom/src/zephyr.provide.ts`)。
|
|
63
|
+
* 这两个名字(`session-query` / `sessionQuery`)指向**同一个实例**,不是两份实现;
|
|
64
|
+
* 别名只在名字**没被占**时发布(`bootstrap.ts`:`store.get(meta.alias, false) === undefined`),
|
|
65
|
+
* 所以漏写那句 `without` 时装配会当场抛 `service "sessionQuery" has been registered`——
|
|
66
|
+
* 这正是 `apps/zephyr-custom/src/__tests__/assembly.spec.ts` 的「替换面各只有一份实例」在守的东西。
|
|
67
|
+
*/
|
|
68
|
+
declare abstract class SessionQuery {
|
|
69
|
+
abstract observeSession(...args: Parameters<SessionQueryEngine$1["observeSession"]>): ReturnType<SessionQueryEngine$1["observeSession"]>;
|
|
70
|
+
abstract searchSessions(...args: Parameters<SessionQueryEngine$1["searchSessions"]>): ReturnType<SessionQueryEngine$1["searchSessions"]>;
|
|
71
|
+
abstract searchEvents(...args: Parameters<SessionQueryEngine$1["searchEvents"]>): ReturnType<SessionQueryEngine$1["searchEvents"]>;
|
|
72
|
+
abstract listSessions(...args: Parameters<SessionQueryEngine$1["listSessions"]>): ReturnType<SessionQueryEngine$1["listSessions"]>;
|
|
73
|
+
abstract readSession(...args: Parameters<SessionQueryEngine$1["readSession"]>): ReturnType<SessionQueryEngine$1["readSession"]>;
|
|
74
|
+
abstract filterSessions(...args: Parameters<SessionQueryEngine$1["filterSessions"]>): ReturnType<SessionQueryEngine$1["filterSessions"]>;
|
|
75
|
+
abstract readTitle(...args: Parameters<SessionQueryEngine$1["readTitle"]>): ReturnType<SessionQueryEngine$1["readTitle"]>;
|
|
76
|
+
abstract readTitleSnapshot(...args: Parameters<SessionQueryEngine$1["readTitleSnapshot"]>): ReturnType<SessionQueryEngine$1["readTitleSnapshot"]>;
|
|
77
|
+
abstract readTitleSnapshots(...args: Parameters<SessionQueryEngine$1["readTitleSnapshots"]>): ReturnType<SessionQueryEngine$1["readTitleSnapshots"]>;
|
|
78
|
+
abstract listEvents(...args: Parameters<SessionQueryEngine$1["listEvents"]>): ReturnType<SessionQueryEngine$1["listEvents"]>;
|
|
79
|
+
abstract filterEvents(...args: Parameters<SessionQueryEngine$1["filterEvents"]>): ReturnType<SessionQueryEngine$1["filterEvents"]>;
|
|
80
|
+
abstract readSurface(...args: Parameters<SessionQueryEngine$1["readSurface"]>): ReturnType<SessionQueryEngine$1["readSurface"]>;
|
|
81
|
+
abstract traceSession(...args: Parameters<SessionQueryEngine$1["traceSession"]>): ReturnType<SessionQueryEngine$1["traceSession"]>;
|
|
82
|
+
abstract traceEvent(...args: Parameters<SessionQueryEngine$1["traceEvent"]>): ReturnType<SessionQueryEngine$1["traceEvent"]>;
|
|
83
|
+
abstract readEvent(...args: Parameters<SessionQueryEngine$1["readEvent"]>): ReturnType<SessionQueryEngine$1["readEvent"]>;
|
|
84
|
+
/** 列表用的元数据(空白状态与最近人工提示词时间);上游 0.2.3 新增,`inspectSession` 随之下线。 */
|
|
85
|
+
abstract getListMetadata(...args: Parameters<SessionQueryEngine$1["getListMetadata"]>): ReturnType<SessionQueryEngine$1["getListMetadata"]>;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* 覆盖守卫(严格):上游 `SessionQueryEngine` 的每个成员都要有同名、同签名的对应项。
|
|
89
|
+
*
|
|
90
|
+
* 为什么不是 `implements`:上游那份是 cordis `Service` **类**(带私有成员),`implements` 会报
|
|
91
|
+
* TS2720("Did you mean to extend … and inherit its members as a subclass?")。签名守卫在这里等价:
|
|
92
|
+
* 漏成员或签名对不上,编译期都会报出成员名(诊断的第二行)。
|
|
93
|
+
*/
|
|
94
|
+
type SessionQueryCovered = AssertTrue<AssertCoveredStrict<SessionQueryEngine$1, SessionQuery>>;
|
|
95
|
+
/**
|
|
96
|
+
* 会话存储:建立 / 读取 / 分叉 / 落盘。
|
|
97
|
+
*
|
|
98
|
+
* **服务名 `sessions` 与浏览器半的 `SessionController`(`endpoint/session-controller.ts`)同名,但不同树**:
|
|
99
|
+
* 这一条只装在 Node 树(`server/session.provide.ts`),上游 `SessionStore` 是它的服务名主人;
|
|
100
|
+
* 浏览器树上的 `sessions` 由上游 `ClientSessions` 发布、`SessionController` 对上。两条不会出现在同一个 ctx 上,
|
|
101
|
+
* 所以「同名」不会互相顶替——改动任一侧的名字前先确认这一点(先例:`Jobs` 与宿主侧 `JobRegistry`)。
|
|
102
|
+
*/
|
|
103
|
+
declare abstract class SessionStore {
|
|
104
|
+
abstract readonly create: SessionStore$1["create"];
|
|
105
|
+
abstract readonly prepare: SessionStore$1["prepare"];
|
|
106
|
+
abstract readonly get: SessionStore$1["get"];
|
|
107
|
+
abstract readonly list: SessionStore$1["list"];
|
|
108
|
+
abstract readonly fork: SessionStore$1["fork"];
|
|
109
|
+
abstract readonly flush: SessionStore$1["flush"];
|
|
110
|
+
abstract readonly messageProjections: SessionStore$1["messageProjections"];
|
|
111
|
+
abstract readonly registerMessageProjection: SessionStore$1["registerMessageProjection"];
|
|
112
|
+
abstract readonly enter: SessionStore$1["enter"];
|
|
113
|
+
abstract readonly announce: SessionStore$1["announce"];
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* 覆盖守卫(严格):上游 `SessionStoreService` 的每个成员都要有同名、同签名的对应项。
|
|
117
|
+
*
|
|
118
|
+
* 为什么不是 `implements`:上游那份是 cordis `Service` **类**(带私有成员),`implements` 会报
|
|
119
|
+
* TS2720("Did you mean to extend … and inherit its members as a subclass?")。签名守卫在这里等价:
|
|
120
|
+
* 漏成员或签名对不上,编译期都会报出成员名(诊断的第二行)。
|
|
121
|
+
*/
|
|
122
|
+
type SessionStoreCovered = AssertTrue<AssertCoveredStrict<SessionStore$1, SessionStore>>;
|
|
123
|
+
declare abstract class TokenMeter {
|
|
124
|
+
abstract readonly measure: TokenMeterService["measure"];
|
|
125
|
+
abstract readonly estimateMessage: TokenMeterService["estimateMessage"];
|
|
126
|
+
abstract readonly contextPressure: TokenMeterService["contextPressure"];
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* 覆盖守卫(严格):上游 `TokenMeterService` 的每个成员都要有同名、同签名的对应项。
|
|
130
|
+
*
|
|
131
|
+
* 为什么不是 `implements`:上游那份是 cordis `Service` **类**(带私有成员),`implements` 会报
|
|
132
|
+
* TS2720("Did you mean to extend … and inherit its members as a subclass?")。签名守卫在这里等价:
|
|
133
|
+
* 漏成员或签名对不上,编译期都会报出成员名(诊断的第二行)。
|
|
134
|
+
*/
|
|
135
|
+
type TokenMeterCovered = AssertTrue<AssertCoveredStrict<TokenMeterService, TokenMeter>>;
|
|
136
|
+
export { SessionProjectionCacheCovered as $, SessionQuery as A, SessionTitleObservation as B, SessionEventTraceObservation as C, SessionLogSnapshot as D, SessionListMetadata as E, SessionResultFilter as F, filterSessionEventDocuments as G, buildSessionEventRecords as H, SessionResultRange as I, ProjectionHandle as J, materializeSessionEventResultFilters as K, SessionSearchHit as L, SessionQueryEngine as M, SessionQueryError as N, SessionObservation as O, SessionRecord as P, SessionProjectionCache as Q, SessionSearchPage as R, SessionEventSearchPage as S, SessionLineageTrace as T, buildSessionEventSearchDocuments as U, SessionTitleObservationResult as V, extractSessionEventText as W, SessionProjectionStoreCovered as X, SessionProjectionStore as Y, CheckpointIdentity as Z, SESSION_QUERY_READ_WINDOW_MAX as _, Session as a, SessionEventResultFilter as b, SessionEventType as c, SessionLogOffset as d, SessionSeq as f, SurfaceOp as g, SessionStoreCovered as h, SESSION_FORMAT_VERSION as i, SessionQueryCovered as j, SessionObservationOptions as k, SessionHeader as l, SessionStore as m, TokenMeterCovered as n, SessionEvent as o, SessionSeqCursor as p, materializeSessionResultFilters as q, AgentCancelCause as r, SessionEventMap as s, TokenMeter as t, SessionId as u, SessionEventReadRequest as v, SessionEventWindow as w, SessionEventSearchDocument as x, SessionEventRecord as y, SessionSurfaceSnapshot as z };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { t as __decorate } from "./decorate-g56z_1VW.mjs";
|
|
2
|
+
import { SESSION_FORMAT_VERSION, Session, SessionId, SessionLogOffset, SessionSeq } from "@deepseek-ai/dsh-session";
|
|
3
|
+
import { Injectable } from "@morlay/zephyr";
|
|
4
|
+
import { SESSION_QUERY_READ_WINDOW_MAX, SessionQueryEngine, SessionQueryError, buildSessionEventRecords, buildSessionEventSearchDocuments, extractSessionEventText, filterSessionEventDocuments, materializeSessionEventResultFilters, materializeSessionResultFilters } from "@deepseek-ai/dsh-session-query";
|
|
5
|
+
// src/contract/session-projection-cache.contract.ts
|
|
6
|
+
let SessionProjectionCache = class SessionProjectionCache {};
|
|
7
|
+
SessionProjectionCache = __decorate([Injectable({ name: "sessionProjectionCache" })], SessionProjectionCache);
|
|
8
|
+
// src/contract/session-projection-store.contract.ts
|
|
9
|
+
let SessionProjectionStore = class SessionProjectionStore {};
|
|
10
|
+
SessionProjectionStore = __decorate([Injectable({ name: "sessionProjections" })], SessionProjectionStore);
|
|
11
|
+
// src/contract/session-query.contract.ts
|
|
12
|
+
let SessionQuery = class SessionQuery {};
|
|
13
|
+
SessionQuery = __decorate([Injectable({ name: "sessionQuery" })], SessionQuery);
|
|
14
|
+
// src/contract/session.contract.ts
|
|
15
|
+
let SessionStore = class SessionStore {};
|
|
16
|
+
SessionStore = __decorate([Injectable({ name: "sessions" })], SessionStore);
|
|
17
|
+
// src/contract/token-meter.contract.ts
|
|
18
|
+
let TokenMeter = class TokenMeter {};
|
|
19
|
+
TokenMeter = __decorate([Injectable({ name: "tokenMeter" })], TokenMeter);
|
|
20
|
+
export { materializeSessionResultFilters as _, SessionLogOffset as a, SESSION_QUERY_READ_WINDOW_MAX as c, SessionQueryError as d, buildSessionEventRecords as f, materializeSessionEventResultFilters as g, filterSessionEventDocuments as h, SessionId as i, SessionQuery as l, extractSessionEventText as m, SESSION_FORMAT_VERSION as n, SessionSeq as o, buildSessionEventSearchDocuments as p, Session as r, SessionStore as s, TokenMeter as t, SessionQueryEngine as u, SessionProjectionStore as v, SessionProjectionCache as y };
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { A as SessionQuery, Q as SessionProjectionCache$1, Y as SessionProjectionStore, m as SessionStore$1, t as TokenMeter } from "./token-meter.contract-BoF6536N.mjs";
|
|
2
|
+
import SessionStoreService from "@deepseek-ai/dsh-session";
|
|
3
|
+
import { SessionProjectionRegistry } from "@deepseek-ai/dsh-session-projection";
|
|
4
|
+
import SessionProjectionCacheService from "@deepseek-ai/dsh-session-projection-cache";
|
|
5
|
+
import { Context } from "@morlay/zephyr";
|
|
6
|
+
import TokenMeterService from "@deepseek-ai/dsh-token-meter";
|
|
7
|
+
import { StorageDomain } from "@morlay/dsh-storage";
|
|
8
|
+
import SqliteSessionQuerySqliteEngine from "@deepseek-ai/dsh-session-query-sqlite";
|
|
9
|
+
declare const SessionStoreDefault_base: import("@morlay/zephyr/compat").AdaptedClass<typeof SessionStore$1, typeof SessionStoreService>;
|
|
10
|
+
declare class SessionStoreDefault extends SessionStoreDefault_base {
|
|
11
|
+
onInit(ctx: Context): Promise<void>;
|
|
12
|
+
}
|
|
13
|
+
declare const SessionProjectionStoreDefault_base: import("@morlay/zephyr/compat").AdaptedClass<typeof SessionProjectionStore, typeof SessionProjectionRegistry>;
|
|
14
|
+
declare class SessionProjectionStoreDefault extends SessionProjectionStoreDefault_base {
|
|
15
|
+
/** 上游投影注册表没有声明依赖:`mount` 只挂它自己(不传 deps,也不传 config)。 */
|
|
16
|
+
onInit(ctx: Context): Promise<void>;
|
|
17
|
+
}
|
|
18
|
+
declare const SessionProjectionCacheDefault_base: import("@morlay/zephyr/compat").AdaptedClass<typeof SessionProjectionCache$1, typeof SessionProjectionCacheService>;
|
|
19
|
+
declare class SessionProjectionCacheDefault extends SessionProjectionCacheDefault_base {
|
|
20
|
+
storageDomain: StorageDomain & import("@morlay/zephyr").Required<StorageDomain>;
|
|
21
|
+
sessionProjections: SessionProjectionStore & import("@morlay/zephyr").Required<SessionProjectionStore>;
|
|
22
|
+
sessions: SessionStore$1 & import("@morlay/zephyr").Required<SessionStore$1>;
|
|
23
|
+
/** 行配置(清单条目的 `config`,`configure` 可覆盖):基类已接住,缺省用本文件的 `DEFAULT_CONFIG`。 */
|
|
24
|
+
private get rowOptions();
|
|
25
|
+
onInit(ctx: Context): Promise<void>;
|
|
26
|
+
}
|
|
27
|
+
declare const SessionQuerySqlite_base: import("@morlay/zephyr/compat").AdaptedClass<typeof SessionQuery, typeof SqliteSessionQuerySqliteEngine>;
|
|
28
|
+
declare class SessionQuerySqlite extends SessionQuerySqlite_base {
|
|
29
|
+
sessions: SessionStore$1 & import("@morlay/zephyr").Required<SessionStore$1>;
|
|
30
|
+
/**
|
|
31
|
+
* 上游引擎在 `observeSession` 里用 `ctx.get('sessionProjections')?.snapshot(session)` 算投影快照——
|
|
32
|
+
* **可选**能力(上游 `inject` 不声明它)。所以这里按 optional 注入、随 mount 交出:装了投影行就给到
|
|
33
|
+
* 它的契约面,没装就与上游同语义地缺省(症状对照:看不到它时 `requires a projected Session observation`)。
|
|
34
|
+
*/
|
|
35
|
+
sessionProjections: SessionProjectionStore | undefined;
|
|
36
|
+
/** 行配置(清单条目的 `config`,`configure` 可覆盖):基类已接住,缺省用本文件的 `DEFAULT_CONFIG`。 */
|
|
37
|
+
private get rowOptions();
|
|
38
|
+
onInit(ctx: Context): Promise<void>;
|
|
39
|
+
}
|
|
40
|
+
declare const TokenMeterDefault_base: import("@morlay/zephyr/compat").AdaptedClass<typeof TokenMeter, typeof TokenMeterService>;
|
|
41
|
+
declare class TokenMeterDefault extends TokenMeterDefault_base {
|
|
42
|
+
sessionProjections: SessionProjectionStore & import("@morlay/zephyr").Required<SessionProjectionStore>;
|
|
43
|
+
onInit(ctx: Context): Promise<void>;
|
|
44
|
+
}
|
|
45
|
+
export { SessionStoreDefault as a, SessionProjectionStoreDefault as i, SessionQuerySqlite as n, SessionProjectionCacheDefault as r, TokenMeterDefault as t };
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { t as __decorate } from "./decorate-g56z_1VW.mjs";
|
|
2
|
+
import { l as SessionQuery, s as SessionStore$1, t as TokenMeter, v as SessionProjectionStore, y as SessionProjectionCache } from "./token-meter.contract-CVJ4qB0S.mjs";
|
|
3
|
+
import SessionStoreService from "@deepseek-ai/dsh-session";
|
|
4
|
+
import { Injectable, inject } from "@morlay/zephyr";
|
|
5
|
+
import { fromCordis } from "@morlay/zephyr/compat";
|
|
6
|
+
import { SessionProjectionRegistry } from "@deepseek-ai/dsh-session-projection";
|
|
7
|
+
import SessionProjectionCacheService from "@deepseek-ai/dsh-session-projection-cache";
|
|
8
|
+
import { StorageDomain } from "@morlay/dsh-storage";
|
|
9
|
+
import SqliteSessionQuerySqliteEngine from "@deepseek-ai/dsh-session-query-sqlite";
|
|
10
|
+
import TokenMeterService from "@deepseek-ai/dsh-token-meter";
|
|
11
|
+
// src/session.service.ts
|
|
12
|
+
let SessionStoreDefault = class SessionStoreDefault extends fromCordis(SessionStore$1, SessionStoreService) {
|
|
13
|
+
async onInit(ctx) {
|
|
14
|
+
await this.mount(ctx);
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
SessionStoreDefault = __decorate([Injectable()], SessionStoreDefault);
|
|
18
|
+
// src/session-projection-store.service.ts
|
|
19
|
+
let SessionProjectionStoreDefault = class SessionProjectionStoreDefault extends fromCordis(SessionProjectionStore, SessionProjectionRegistry) {
|
|
20
|
+
/** 上游投影注册表没有声明依赖:`mount` 只挂它自己(不传 deps,也不传 config)。 */
|
|
21
|
+
async onInit(ctx) {
|
|
22
|
+
await this.mount(ctx);
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
SessionProjectionStoreDefault = __decorate([Injectable()], SessionProjectionStoreDefault);
|
|
26
|
+
// src/session-projection-cache.service.ts
|
|
27
|
+
/** 默认配置:每 200 个事件或 5s 写一次(装配面用 `configure` 覆盖)。 */
|
|
28
|
+
const DEFAULT_CONFIG$1 = {
|
|
29
|
+
writeEveryEvents: 200,
|
|
30
|
+
writeIntervalMs: 5e3
|
|
31
|
+
};
|
|
32
|
+
let SessionProjectionCacheDefault = class SessionProjectionCacheDefault extends fromCordis(SessionProjectionCache, SessionProjectionCacheService) {
|
|
33
|
+
storageDomain = inject(StorageDomain);
|
|
34
|
+
sessionProjections = inject(SessionProjectionStore);
|
|
35
|
+
sessions = inject(SessionStore$1);
|
|
36
|
+
/** 行配置(清单条目的 `config`,`configure` 可覆盖):基类已接住,缺省用本文件的 `DEFAULT_CONFIG`。 */
|
|
37
|
+
get rowOptions() {
|
|
38
|
+
return this.rowConfig ?? DEFAULT_CONFIG$1;
|
|
39
|
+
}
|
|
40
|
+
async onInit(ctx) {
|
|
41
|
+
await this.mount(ctx, this.rowOptions, {
|
|
42
|
+
storageDomain: this.storageDomain,
|
|
43
|
+
sessionProjections: this.sessionProjections,
|
|
44
|
+
sessions: this.sessions
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
SessionProjectionCacheDefault = __decorate([Injectable()], SessionProjectionCacheDefault);
|
|
49
|
+
// src/session-query.service.ts
|
|
50
|
+
/** 默认配置:内存库、不自动打开(装配面用 `configure` 覆盖)。 */
|
|
51
|
+
const DEFAULT_CONFIG = {
|
|
52
|
+
path: ":memory:",
|
|
53
|
+
openAt: "never"
|
|
54
|
+
};
|
|
55
|
+
let SessionQuerySqlite = class SessionQuerySqlite extends fromCordis(SessionQuery, SqliteSessionQuerySqliteEngine) {
|
|
56
|
+
sessions = inject(SessionStore$1);
|
|
57
|
+
/**
|
|
58
|
+
* 上游引擎在 `observeSession` 里用 `ctx.get('sessionProjections')?.snapshot(session)` 算投影快照——
|
|
59
|
+
* **可选**能力(上游 `inject` 不声明它)。所以这里按 optional 注入、随 mount 交出:装了投影行就给到
|
|
60
|
+
* 它的契约面,没装就与上游同语义地缺省(症状对照:看不到它时 `requires a projected Session observation`)。
|
|
61
|
+
*/
|
|
62
|
+
sessionProjections = inject.optional(SessionProjectionStore);
|
|
63
|
+
/** 行配置(清单条目的 `config`,`configure` 可覆盖):基类已接住,缺省用本文件的 `DEFAULT_CONFIG`。 */
|
|
64
|
+
get rowOptions() {
|
|
65
|
+
return this.rowConfig ?? DEFAULT_CONFIG;
|
|
66
|
+
}
|
|
67
|
+
async onInit(ctx) {
|
|
68
|
+
await this.mount(ctx, this.rowOptions, {
|
|
69
|
+
sessions: this.sessions,
|
|
70
|
+
...this.sessionProjections === void 0 ? {} : { sessionProjections: this.sessionProjections }
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
SessionQuerySqlite = __decorate([Injectable()], SessionQuerySqlite);
|
|
75
|
+
// src/token-meter.service.ts
|
|
76
|
+
let TokenMeterDefault = class TokenMeterDefault extends fromCordis(TokenMeter, TokenMeterService) {
|
|
77
|
+
sessionProjections = inject(SessionProjectionStore);
|
|
78
|
+
async onInit(ctx) {
|
|
79
|
+
await this.mount(ctx, void 0, { sessionProjections: this.sessionProjections });
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
TokenMeterDefault = __decorate([Injectable()], TokenMeterDefault);
|
|
83
|
+
export { SessionStoreDefault as a, SessionProjectionStoreDefault as i, SessionQuerySqlite as n, SessionProjectionCacheDefault as r, TokenMeterDefault as t };
|
package/dist/ui.d.mts
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { Context, OnInit } from "@morlay/zephyr";
|
|
2
|
+
import { Remote, RemoteTransport } from "@morlay/zephyr-app/client";
|
|
3
|
+
import { SessionEndpoint } from "@morlay/dsh-session/endpoint";
|
|
4
|
+
/** `session` 组的客户端契约实例。 */
|
|
5
|
+
export declare class SessionEndpointClient extends SessionEndpoint implements OnInit {
|
|
6
|
+
/** 转发目标:`@RemoteClient()` 生成的方法都走 `remote.<组名>` 面(`face()`);流式方法自己转发同一面。 */
|
|
7
|
+
protected readonly remote: Remote & import("@morlay/zephyr").Required<Remote>;
|
|
8
|
+
/** 传输:转发走它(我们的组不注册进上游 `remote`)。 */
|
|
9
|
+
protected readonly transport: RemoteTransport & import("@morlay/zephyr").Required<RemoteTransport>;
|
|
10
|
+
/**
|
|
11
|
+
* 挂上这一组的 descriptor:客户端形态**自己挂自己那一组**,不另开 binding / mount 行。
|
|
12
|
+
*
|
|
13
|
+
* 挂的是**上游那份**(`SESSION_CONTROLLER_REMOTE`):宿主侧实现就是上游控制器,wire 描述符只有它
|
|
14
|
+
* 一份。这里不编译我们的组契约——那会造出第二份声明,`session/list` 的 `_request` / `request`
|
|
15
|
+
* 分叉就是这么来的。
|
|
16
|
+
*
|
|
17
|
+
* 挂完**立即发布** `remote.<组名>` 这个嵌套服务名:把它写成 `static inject` 的行(上游 `ui-session`
|
|
18
|
+
* 等)在它出现之前停在待激活,而「哪个 ns 要提前可读」是本域知道的事(框架不认识任何 ns)。
|
|
19
|
+
* @param ctx - 本行 ctx:disposer 挂在它上面,卸载随行 fiber。
|
|
20
|
+
*/
|
|
21
|
+
onInit(ctx: Context): Promise<void>;
|
|
22
|
+
/**
|
|
23
|
+
* 这一组的面挂上没有(`$mount` 在 {@link onInit} 里跑,装配完成前读它就是 `false`)。
|
|
24
|
+
* @returns 有面时 `true`。
|
|
25
|
+
*/
|
|
26
|
+
get mounted(): boolean;
|
|
27
|
+
follow(...args: Parameters<SessionEndpoint["follow"]>): ReturnType<SessionEndpoint["follow"]>;
|
|
28
|
+
control(...args: Parameters<SessionEndpoint["control"]>): ReturnType<SessionEndpoint["control"]>;
|
|
29
|
+
/**
|
|
30
|
+
* 读一页历史(上游 `SessionManager` 按这个名字取用;wire 上仍走 `session/page`)。
|
|
31
|
+
*
|
|
32
|
+
* 客户端 API 名 ≠ wire 方法名,这层差异由**客户端形态**负责:`LiveSessionRemotes` 与其它消费方
|
|
33
|
+
* 直通,不必各自知道这个别名。
|
|
34
|
+
* @param args - 与 `page` 相同的实参。
|
|
35
|
+
* @returns 与 `page` 相同的应答。
|
|
36
|
+
*/
|
|
37
|
+
readPage(...args: Parameters<SessionEndpoint["page"]>): ReturnType<SessionEndpoint["page"]>;
|
|
38
|
+
/**
|
|
39
|
+
* `remote.<组名>` 的调用面。
|
|
40
|
+
*
|
|
41
|
+
* 缺了**不静默**:没挂上就抛在调用处,不漂成上游内部的 `Cannot read properties of undefined`。
|
|
42
|
+
* @returns 这一组的流式方法面。
|
|
43
|
+
*/
|
|
44
|
+
private face;
|
|
45
|
+
/**
|
|
46
|
+
* 组名。唯一 home 是契约上的 `@RemoteGroup({ name })`——这里从契约读,不另写一份字符串。
|
|
47
|
+
* @returns wire 上的组名(`session`)。
|
|
48
|
+
*/
|
|
49
|
+
private groupName;
|
|
50
|
+
}
|
package/dist/ui.mjs
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { inject } from "@morlay/zephyr";
|
|
2
|
+
import { Remote, RemoteTransport } from "@morlay/zephyr-app/client";
|
|
3
|
+
import { remoteNamespaceOf } from "@morlay/zephyr-app/client/remote";
|
|
4
|
+
import { RemoteClient, groupNameOf } from "@morlay/zephyr-app/remote";
|
|
5
|
+
import { SESSION_CONTROLLER_REMOTE, SessionEndpoint } from "@morlay/dsh-session/endpoint";
|
|
6
|
+
import { t as __decorate } from "./decorate-g56z_1VW.mjs";
|
|
7
|
+
// src/ui/session-endpoint.client.ts
|
|
8
|
+
let SessionEndpointClient = class SessionEndpointClient extends SessionEndpoint {
|
|
9
|
+
/** 转发目标:`@RemoteClient()` 生成的方法都走 `remote.<组名>` 面(`face()`);流式方法自己转发同一面。 */
|
|
10
|
+
remote = inject(Remote);
|
|
11
|
+
/** 传输:转发走它(我们的组不注册进上游 `remote`)。 */
|
|
12
|
+
transport = inject(RemoteTransport);
|
|
13
|
+
/**
|
|
14
|
+
* 挂上这一组的 descriptor:客户端形态**自己挂自己那一组**,不另开 binding / mount 行。
|
|
15
|
+
*
|
|
16
|
+
* 挂的是**上游那份**(`SESSION_CONTROLLER_REMOTE`):宿主侧实现就是上游控制器,wire 描述符只有它
|
|
17
|
+
* 一份。这里不编译我们的组契约——那会造出第二份声明,`session/list` 的 `_request` / `request`
|
|
18
|
+
* 分叉就是这么来的。
|
|
19
|
+
*
|
|
20
|
+
* 挂完**立即发布** `remote.<组名>` 这个嵌套服务名:把它写成 `static inject` 的行(上游 `ui-session`
|
|
21
|
+
* 等)在它出现之前停在待激活,而「哪个 ns 要提前可读」是本域知道的事(框架不认识任何 ns)。
|
|
22
|
+
* @param ctx - 本行 ctx:disposer 挂在它上面,卸载随行 fiber。
|
|
23
|
+
*/
|
|
24
|
+
async onInit(ctx) {
|
|
25
|
+
try {
|
|
26
|
+
const dispose = await this.remote.$mount(SESSION_CONTROLLER_REMOTE);
|
|
27
|
+
ctx.effect(() => dispose);
|
|
28
|
+
this.remote.publishNamespace(this.groupName());
|
|
29
|
+
} catch (error) {
|
|
30
|
+
throw new Error(`挂载 remote.${this.groupName()} 失败:${error.message}`, { cause: error });
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* 这一组的面挂上没有(`$mount` 在 {@link onInit} 里跑,装配完成前读它就是 `false`)。
|
|
35
|
+
* @returns 有面时 `true`。
|
|
36
|
+
*/
|
|
37
|
+
get mounted() {
|
|
38
|
+
return remoteNamespaceOf(this.remote, this.groupName()) !== void 0;
|
|
39
|
+
}
|
|
40
|
+
follow(...args) {
|
|
41
|
+
return this.face().follow(...args);
|
|
42
|
+
}
|
|
43
|
+
control(...args) {
|
|
44
|
+
return this.face().control(...args);
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* 读一页历史(上游 `SessionManager` 按这个名字取用;wire 上仍走 `session/page`)。
|
|
48
|
+
*
|
|
49
|
+
* 客户端 API 名 ≠ wire 方法名,这层差异由**客户端形态**负责:`LiveSessionRemotes` 与其它消费方
|
|
50
|
+
* 直通,不必各自知道这个别名。
|
|
51
|
+
* @param args - 与 `page` 相同的实参。
|
|
52
|
+
* @returns 与 `page` 相同的应答。
|
|
53
|
+
*/
|
|
54
|
+
readPage(...args) {
|
|
55
|
+
return this.page(...args);
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* `remote.<组名>` 的调用面。
|
|
59
|
+
*
|
|
60
|
+
* 缺了**不静默**:没挂上就抛在调用处,不漂成上游内部的 `Cannot read properties of undefined`。
|
|
61
|
+
* @returns 这一组的流式方法面。
|
|
62
|
+
*/
|
|
63
|
+
face() {
|
|
64
|
+
const face = remoteNamespaceOf(this.remote, this.groupName());
|
|
65
|
+
if (face === void 0) throw new Error(`remote.${this.groupName()} 还没有挂载:等 remote.whenNamespace("${this.groupName()}") 之后再调用`);
|
|
66
|
+
return face;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* 组名。唯一 home 是契约上的 `@RemoteGroup({ name })`——这里从契约读,不另写一份字符串。
|
|
70
|
+
* @returns wire 上的组名(`session`)。
|
|
71
|
+
*/
|
|
72
|
+
groupName() {
|
|
73
|
+
return groupNameOf(this.constructor);
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
SessionEndpointClient = __decorate([RemoteClient()], SessionEndpointClient);
|
|
77
|
+
export { SessionEndpointClient };
|
package/package.json
CHANGED
|
@@ -1,6 +1,68 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@morlay/dsh-session",
|
|
3
|
-
"version": "0.0.0
|
|
4
|
-
"
|
|
5
|
-
"description": "
|
|
3
|
+
"version": "0.2.0-alpha.0",
|
|
4
|
+
"private": false,
|
|
5
|
+
"description": "会话核心:存储、投影、查询、token 计量与浏览器侧会话数据面;标题、检查点等子域在各自包里。",
|
|
6
|
+
"files": [
|
|
7
|
+
"dist",
|
|
8
|
+
"src",
|
|
9
|
+
"!**/__tests__"
|
|
10
|
+
],
|
|
11
|
+
"type": "module",
|
|
12
|
+
"exports": {
|
|
13
|
+
".": {
|
|
14
|
+
"types": "./dist/index.d.mts",
|
|
15
|
+
"default": "./dist/index.mjs"
|
|
16
|
+
},
|
|
17
|
+
"./contract": {
|
|
18
|
+
"types": "./dist/contract.d.mts",
|
|
19
|
+
"default": "./dist/contract.mjs"
|
|
20
|
+
},
|
|
21
|
+
"./testing": {
|
|
22
|
+
"types": "./dist/testing.d.mts",
|
|
23
|
+
"default": "./dist/testing.mjs"
|
|
24
|
+
},
|
|
25
|
+
"./server": {
|
|
26
|
+
"types": "./dist/server.d.mts",
|
|
27
|
+
"default": "./dist/server.mjs"
|
|
28
|
+
},
|
|
29
|
+
"./endpoint": {
|
|
30
|
+
"types": "./dist/endpoint.d.mts",
|
|
31
|
+
"default": "./dist/endpoint.mjs"
|
|
32
|
+
},
|
|
33
|
+
"./ui": {
|
|
34
|
+
"types": "./dist/ui.d.mts",
|
|
35
|
+
"default": "./dist/ui.mjs"
|
|
36
|
+
},
|
|
37
|
+
"./package.json": "./package.json"
|
|
38
|
+
},
|
|
39
|
+
"dependencies": {
|
|
40
|
+
"@morlay/dsh-storage": "^0.2.0-alpha.0",
|
|
41
|
+
"@morlay/zephyr": "^0.2.0-alpha.0",
|
|
42
|
+
"@morlay/zephyr-app": "^0.2.0-alpha.0"
|
|
43
|
+
},
|
|
44
|
+
"devDependencies": {},
|
|
45
|
+
"peerDependencies": {
|
|
46
|
+
"@deepseek-ai/cordis": "~4.2.0-alpha.2",
|
|
47
|
+
"@deepseek-ai/dsh-api-session-controller": "^0.2.3-alpha.3",
|
|
48
|
+
"@deepseek-ai/dsh-session": "^0.2.3-alpha.3",
|
|
49
|
+
"@deepseek-ai/dsh-session-format": "^0.2.3-alpha.3",
|
|
50
|
+
"@deepseek-ai/dsh-session-format-catalog": "^0.2.3-alpha.3",
|
|
51
|
+
"@deepseek-ai/dsh-session-projection": "^0.2.3-alpha.3",
|
|
52
|
+
"@deepseek-ai/dsh-session-projection-cache": "^0.2.3-alpha.3",
|
|
53
|
+
"@deepseek-ai/dsh-session-query": "^0.2.3-alpha.3",
|
|
54
|
+
"@deepseek-ai/dsh-session-query-sqlite": "^0.2.3-alpha.3",
|
|
55
|
+
"@deepseek-ai/dsh-session-stats": "^0.2.3-alpha.3",
|
|
56
|
+
"@deepseek-ai/dsh-session-turn-outline": "^0.2.3-alpha.3",
|
|
57
|
+
"@deepseek-ai/dsh-token-meter": "^0.2.3-alpha.3"
|
|
58
|
+
},
|
|
59
|
+
"engines": {
|
|
60
|
+
"dsh": ">= 0.2.3-alpha.3 < 0.2.4"
|
|
61
|
+
},
|
|
62
|
+
"repository": {
|
|
63
|
+
"type": "git",
|
|
64
|
+
"url": "https://github.com/morlay/zephyr.git",
|
|
65
|
+
"directory": "packages/agent/dsh-session"
|
|
66
|
+
},
|
|
67
|
+
"scripts": {}
|
|
6
68
|
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
// 会话域的事件:名字 + 参数表 + 返回类型都收在类里,订阅/发布走 `EventEmitter`。
|
|
2
|
+
//
|
|
3
|
+
// 为什么要包一层:上游用字符串事件名派发与订阅(`session/created` / `session/event` …),拼错要到
|
|
4
|
+
// 运行期才发现,payload 形状也没有一个 home。这里的类与上游 `SessionEventMap` **同名同形**,
|
|
5
|
+
// 所以订阅我们的事件、与上游的派发是同一个 cordis 事件。
|
|
6
|
+
//
|
|
7
|
+
// 域内所有订阅会话事件的包都从这里取,不各自再定义一份——`session/flush` 的签名曾经在别的包里写成
|
|
8
|
+
// `[SessionId]`(上游派发的是 `Session`),那种分叉只会在运行期露出来。
|
|
9
|
+
import type {
|
|
10
|
+
Session,
|
|
11
|
+
SessionEvent,
|
|
12
|
+
SessionEventMap,
|
|
13
|
+
SessionEventType,
|
|
14
|
+
} from "@deepseek-ai/dsh-session";
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* 把一条事件的 `type` 与 `data` **成对**换掉。
|
|
18
|
+
*
|
|
19
|
+
* 「`event.type` 与 `event.data` 相配」这件事在联合类型上表达不出来(展开一条联合事件时 `type` 各支冲突,
|
|
20
|
+
* TS 连可比性都不给),所以配对由**调用方**在签名里给出:`T` 与 `SessionEventMap[T]` 一起传。断言只在本
|
|
21
|
+
* 函数内发生一次,比在每个改写点各写一条 `as unknown as` 收口;读路径与编辑编排共用这一处。
|
|
22
|
+
* @param event - 原事件(`seq` / `time` / 信封字段都保留)。
|
|
23
|
+
* @param type - 新类型。
|
|
24
|
+
* @param data - 新类型对应的数据。
|
|
25
|
+
* @returns 换过 type/data 的事件。
|
|
26
|
+
*/
|
|
27
|
+
export function withEventType<T extends SessionEventType>(
|
|
28
|
+
event: SessionEvent,
|
|
29
|
+
type: T,
|
|
30
|
+
data: SessionEventMap[T],
|
|
31
|
+
): SessionEvent<T> {
|
|
32
|
+
return { ...event, type, data } as unknown as SessionEvent<T>;
|
|
33
|
+
}
|
|
34
|
+
import { EventEmitter } from "@morlay/zephyr";
|
|
35
|
+
|
|
36
|
+
/** 一个会话进了 store(`announce` 之后派发;监听者抛错会回滚这次挂载)。 */
|
|
37
|
+
export class SessionCreated extends EventEmitter<[Session]> {
|
|
38
|
+
constructor() {
|
|
39
|
+
super("session/created");
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** 会话日志追加了一条事件(`emit`,不等待)。 */
|
|
44
|
+
export class SessionEventAppended extends EventEmitter<[Session, SessionEvent]> {
|
|
45
|
+
constructor() {
|
|
46
|
+
super("session/event");
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** 并行耐久检查点:每个监听者都跑、调用方等全部结束,没有瀑布否决。 */
|
|
51
|
+
export class SessionFlush extends EventEmitter<[Session], Promise<void> | void> {
|
|
52
|
+
constructor() {
|
|
53
|
+
super("session/flush");
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** 会话从 store 上摘下来了(之后的读写都指向已关闭的实例)。 */
|
|
58
|
+
export class SessionDisposed extends EventEmitter<[Session]> {
|
|
59
|
+
constructor() {
|
|
60
|
+
super("session/disposed");
|
|
61
|
+
}
|
|
62
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// session 域的契约面(`@morlay/dsh-session/contract`):进程内的端口,不涉及 remote。
|
|
2
|
+
export * from "./session-format.contract.ts";
|
|
3
|
+
export * from "./session-log.contract.ts";
|
|
4
|
+
export * from "./session-surface.contract.ts";
|
|
5
|
+
export * from "./session-projection-value.contract.ts";
|
|
6
|
+
export * from "./session-projection-cache.contract.ts";
|
|
7
|
+
export * from "./session-projection-store.contract.ts";
|
|
8
|
+
export * from "./session-query.contract.ts";
|
|
9
|
+
export * from "./session-query-tracing.contract.ts";
|
|
10
|
+
export * from "./session-workspace.contract.ts";
|
|
11
|
+
export * from "./session.contract.ts";
|
|
12
|
+
// 事件 `type`/`data` 的成对改写(读路径与编辑编排共用):与 `SessionEventMap` 同一个 home。
|
|
13
|
+
export { withEventType } from "./events.ts";
|
|
14
|
+
export * from "./token-meter.contract.ts";
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
// 会话日志**文件格式**的契约词汇:header / 事件的 JSON 形状、每代格式的文件名、以及格式目录。
|
|
2
|
+
//
|
|
3
|
+
// 上游把这一层拆成 `-format`(一代格式的读写与文件名)与 `-format-catalog`(把若干代格式与迁移链
|
|
4
|
+
// 组成一个目录)。落盘实现要按文件名认出「这是第几代」,所以要这两组词;这里一处给全。
|
|
5
|
+
/** 一条落盘事件的 JSON 形状(写入磁盘的那份,不是内存里的事件)。 */
|
|
6
|
+
export type { SessionFormatEvent } from "@deepseek-ai/dsh-session-format";
|
|
7
|
+
/** 一份落盘 header 的 JSON 形状。 */
|
|
8
|
+
export type { SessionFormatHeader } from "@deepseek-ai/dsh-session-format";
|
|
9
|
+
/** 某一代格式的日志文件名(纯函数)。 */
|
|
10
|
+
export { sessionFormatLogFilename } from "@deepseek-ai/dsh-session-format";
|
|
11
|
+
/** 从日志文件名认出它是第几代格式(认不出给 `undefined`,纯函数)。 */
|
|
12
|
+
export { parseSessionFormatLogFilename } from "@deepseek-ai/dsh-session-format";
|
|
13
|
+
/** 一份格式目录:若干代格式与迁移链组成的可读旧日志的目录。 */
|
|
14
|
+
export type { SessionFormatCatalog } from "@deepseek-ai/dsh-session-format";
|
|
15
|
+
/** 把「本代格式 + 各代迁移」组成一个可读旧日志的格式目录(纯函数)。 */
|
|
16
|
+
export { createSessionFormatCatalogWithChildren } from "@deepseek-ai/dsh-session-format-catalog";
|
|
17
|
+
/** 本仓当前这一份格式目录实例。 */
|
|
18
|
+
export { sessionFormatCatalog } from "@deepseek-ai/dsh-session-format-catalog";
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
// 会话日志的**写面词汇**(上游 `@deepseek-ai/dsh-session`):表层事件类型与两件纯函数。
|
|
2
|
+
//
|
|
3
|
+
// 读侧/写侧都要它们:`SurfaceEventType` 给持久化落库时判「这条事件有没有 surfaceOp」,
|
|
4
|
+
// `interruptedTurnClosers` / `snapshotSessionEvent` 给修复与导出用(都是纯函数)。
|
|
5
|
+
/** 有表层语义的事件类型(`surfaceOp` 只出现在这些事件上)。 */
|
|
6
|
+
export type { SurfaceEventType } from "@deepseek-ai/dsh-session";
|
|
7
|
+
/** 一个被打断的回合要补哪些收尾事件(纯函数)。 */
|
|
8
|
+
export { interruptedTurnClosers } from "@deepseek-ai/dsh-session";
|
|
9
|
+
/** 取一条事件的快照(纯函数)。 */
|
|
10
|
+
export { snapshotSessionEvent } from "@deepseek-ai/dsh-session";
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
// sessionProjectionCache 契约:列表页的投影快照读面(只有读面与写穿,没有构造与生命周期钩子)。
|
|
2
|
+
import type { SessionProjectionCache as SessionProjectionCacheService } from "@deepseek-ai/dsh-session-projection-cache";
|
|
3
|
+
import { Injectable } from "@morlay/zephyr";
|
|
4
|
+
import type { AssertCoveredStrict, AssertTrue } from "@morlay/zephyr-app/client";
|
|
5
|
+
|
|
6
|
+
/** 能力词汇:检查点的身份(会话 + 水位 + 继承事件数),缓存行按它对齐。 */
|
|
7
|
+
export type { CheckpointIdentity } from "@deepseek-ai/dsh-session-projection-cache";
|
|
8
|
+
|
|
9
|
+
@Injectable({ name: "sessionProjectionCache" })
|
|
10
|
+
export abstract class SessionProjectionCache {
|
|
11
|
+
abstract readonly config: SessionProjectionCacheService["config"];
|
|
12
|
+
|
|
13
|
+
abstract readonly cachedSnapshot: SessionProjectionCacheService["cachedSnapshot"];
|
|
14
|
+
|
|
15
|
+
abstract readonly cachedPredecessorTitle: SessionProjectionCacheService["cachedPredecessorTitle"];
|
|
16
|
+
|
|
17
|
+
abstract readonly hydratePrepared: SessionProjectionCacheService["hydratePrepared"];
|
|
18
|
+
|
|
19
|
+
abstract readonly write: SessionProjectionCacheService["write"];
|
|
20
|
+
|
|
21
|
+
abstract readonly coldSnapshot: SessionProjectionCacheService["coldSnapshot"];
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* 覆盖守卫(严格):上游 `SessionProjectionCacheService` 的每个成员都要有同名、同签名的对应项。
|
|
26
|
+
*
|
|
27
|
+
* 为什么不是 `implements`:上游那份是 cordis `Service` **类**(带私有成员),`implements` 会报
|
|
28
|
+
* TS2720("Did you mean to extend … and inherit its members as a subclass?")。签名守卫在这里等价:
|
|
29
|
+
* 漏成员或签名对不上,编译期都会报出成员名(诊断的第二行)。
|
|
30
|
+
*/
|
|
31
|
+
export type SessionProjectionCacheCovered = AssertTrue<
|
|
32
|
+
AssertCoveredStrict<SessionProjectionCacheService, SessionProjectionCache>
|
|
33
|
+
>;
|