@deepseek-ai/dsh-api-session-controller 0.1.6-alpha.1 → 0.1.7-alpha.1

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 (44) hide show
  1. package/README.i18n.yaml +2 -2
  2. package/README.md +42 -7
  3. package/README.zh.md +42 -7
  4. package/lib/client.js +1037 -992
  5. package/lib/index.js +314 -183
  6. package/lib/typert.host.js +539 -331
  7. package/lib/typert.remote-client.d.ts +10 -5
  8. package/lib/typert.remote-client.js +374 -264
  9. package/lib/types/agent.d.ts +1 -1
  10. package/lib/types/agent.js +8 -1
  11. package/lib/types/archived-session-gate.d.ts +30 -0
  12. package/lib/types/archived-session-gate.js +52 -0
  13. package/lib/types/client/contract/session.d.ts +2 -0
  14. package/lib/types/client/contract/sessions.d.ts +65 -35
  15. package/lib/types/client/contract/snapshot.d.ts +0 -14
  16. package/lib/types/client/index.d.ts +12 -3
  17. package/lib/types/client/index.js +16 -5
  18. package/lib/types/client/scope.d.ts +13 -3
  19. package/lib/types/client/scope.js +15 -22
  20. package/lib/types/client/sessions/lineage.d.ts +5 -5
  21. package/lib/types/client/sessions/lineage.js +3 -4
  22. package/lib/types/client/sessions/manager.d.ts +91 -105
  23. package/lib/types/client/sessions/manager.js +307 -434
  24. package/lib/types/client/sessions/projection-store.d.ts +34 -21
  25. package/lib/types/client/sessions/projection-store.js +48 -24
  26. package/lib/types/client/sessions/remotes.d.ts +1 -2
  27. package/lib/types/client/sessions/service.d.ts +53 -150
  28. package/lib/types/client/sessions/service.js +267 -264
  29. package/lib/types/client/sessions/session.d.ts +24 -35
  30. package/lib/types/client/sessions/session.js +131 -73
  31. package/lib/types/commands.d.ts +6 -4
  32. package/lib/types/commands.js +82 -40
  33. package/lib/types/control.d.ts +2 -4
  34. package/lib/types/control.js +2 -84
  35. package/lib/types/history.js +1 -1
  36. package/lib/types/index.d.ts +34 -7
  37. package/lib/types/index.js +118 -14
  38. package/lib/types/list.js +24 -15
  39. package/lib/types/skill-catalog.js +60 -50
  40. package/lib/types/types.d.ts +40 -40
  41. package/lib/types/types.js +0 -1
  42. package/package.json +71 -76
  43. package/lib/types/client/sessions/queue-mirror.d.ts +0 -26
  44. package/lib/types/client/sessions/queue-mirror.js +0 -61
@@ -1,11 +1,14 @@
1
- import type { SubagentAddress, SubagentCatalog } from '@deepseek-ai/dsh-subagent/client';
1
+ /** Host catalog, durable projection caches, and explicitly retained Client instances. */
2
+ import type { SubagentAddress } from '@deepseek-ai/dsh-subagent/client';
2
3
  import { SessionSeq, type SessionId } from '@deepseek-ai/dsh-session/types';
4
+ import type { SessionProjectionMap } from '@deepseek-ai/dsh-session-projection/types';
3
5
  import type { WorkspaceId } from '@deepseek-ai/dsh-workspace/types';
4
- import type { SessionControlFrame, SessionSummary, SessionJob as JobView } from '../../types.ts';
6
+ import type { SessionControlFrame, SessionRenameValue, SessionSummary } from '../../types.ts';
5
7
  import type { RemoteFailure, RemoteResult } from '@deepseek-ai/dsh-typert-protocol';
6
8
  import type { SessionListEntry } from './lineage.ts';
7
9
  import { Session } from './session.ts';
8
10
  import type { SessionRemotes } from './remotes.ts';
11
+ import type { SessionTarget } from '../contract/sessions.ts';
9
12
  /**
10
13
  * List arrival lifecycle, orthogonal to the pull-activity `state` axis:
11
14
  * `pending` (no successful pull yet — an empty items array means "nothing
@@ -23,40 +26,33 @@ export interface SessionSearchResultItem {
23
26
  /** Immutable session-list snapshot for useSessionList. */
24
27
  export interface SessionListSnapshot {
25
28
  items: readonly SessionListEntry[];
26
- /** Selected Session id (validated against items; masked to undefined while its session is off the list). */
27
- current: SessionId | undefined;
28
29
  state: 'idle' | 'loading' | 'error';
29
30
  /** Arrival lifecycle (see {@link SessionListPhase}); `state` stays the pull-activity axis. */
30
31
  phase: SessionListPhase;
31
32
  error: RemoteFailure | null;
32
- subagentsByParent: Readonly<Record<SessionId, SubagentCatalogSnapshot>>;
33
- /** Background jobs per session; an absent key is an empty set. */
34
- jobsBySession: Readonly<Record<SessionId, readonly JobView[]>>;
35
- currentAddress: SubagentAddress | undefined;
33
+ projectionsBySession: Readonly<Record<SessionId, SessionProjectionSnapshot>>;
34
+ }
35
+ /** Shared projection values and the lifecycle of their explicit baseline read. */
36
+ export interface SessionProjectionSnapshot {
37
+ readonly values: Readonly<Partial<SessionProjectionMap>>;
38
+ readonly state: 'idle' | 'loading' | 'ready' | 'error';
39
+ readonly error: RemoteFailure | null;
36
40
  }
37
- /** One parent-addressed durable catalog projected through the sessions snapshot. */
38
- export type SubagentCatalogSnapshot = Omit<SubagentCatalog, 'parentAvailable'> & {
39
- /** Absent until the first successful catalog read. */
40
- readonly parentAvailable?: boolean;
41
- state: 'loading' | 'ready' | 'error';
42
- error: RemoteFailure | null;
43
- };
44
41
  /** Instance cluster + frame entry + the session list. */
45
42
  export declare class SessionManager {
46
43
  private readonly remote;
47
44
  private readonly sessions;
48
45
  /** In-flight Session disposals remain here after instances leave `sessions`, so manager disposal can await quiescence. */
49
46
  private readonly sessionDisposals;
50
- /** Latest transient queues, retained independently of Session object materialization. */
51
- private readonly queues;
52
47
  /**
53
- * Sessions that finished running while not selected — the sidebar's green
54
- * "done" reminder (manager-owned, survives connection generations; cleared
55
- * on select and session-removed, re-armed by the next completion).
48
+ * Accepted/running presentation must survive a later empty-history list
49
+ * response. Host-asserted running is recorded even before a row, instance, or
50
+ * address holds the identity — the listing that would hold it may not have
51
+ * landed yet — while the client-local acceptance callback requires a current
52
+ * holder, because it can arrive from a replaced or already-dropped Session.
56
53
  */
57
- private readonly completedNotifications;
58
- /** Last-observed running bits per session; the true→false edge here arms {@link completedNotifications}. */
59
- private readonly prevRunning;
54
+ private readonly engagedSessions;
55
+ private disposed;
60
56
  /** Per-session projection value stores, retained independently of instance arrival (the
61
57
  * title-snapshot precedent, generalized): push frames land here whether or not the Session
62
58
  * is instantiated (list rows read the 'title' key), and an instantiated Session adopts the
@@ -68,22 +64,11 @@ export declare class SessionManager {
68
64
  private listPhase;
69
65
  private listError;
70
66
  private listInflight;
71
- /** Mutations arriving after a list request starts are replayed over its response. */
67
+ /** Active list request's mutation log; its identity also fences completion after reconnect. */
72
68
  private listMutations;
73
69
  private readonly addresses;
74
- private readonly catalogs;
75
- private readonly catalogInflight;
76
- /** Catalog owners whose membership changed while a pull was in flight: one trailing refresh after it settles. */
77
- private readonly catalogStale;
78
- private readonly openCatalogs;
79
- private readonly catalogDebounce;
80
- /**
81
- * Background jobs per session, last-wins from Session Controller's control
82
- * stream. An empty set is stored as an absent key, so absence and `[]` are
83
- * one representation.
84
- */
85
- private readonly jobsBySession;
86
- private selected;
70
+ private readonly projectionLoads;
71
+ private readonly projectionInflight;
87
72
  private listSnapshotCache;
88
73
  /** Entry-identity cache (reference stability): list rebuilds reuse the previous entry
89
74
  * object when every field matches — wire refreshes mint all-new summary objects, so identity
@@ -91,71 +76,68 @@ export declare class SessionManager {
91
76
  private entryCache;
92
77
  private itemsCache;
93
78
  private readonly notifier;
79
+ /** @param remote - generated Remote namespaces used by catalog and history readers. */
80
+ constructor(remote: SessionRemotes);
94
81
  /**
95
- * @param remote - generated Remote namespaces the Session cluster calls.
96
- * @param restoredSelection - persisted real-Session selection candidate.
82
+ * Resolve an acquisition target without materializing a Session.
83
+ * @param target - known identity or durable direct-parent address.
84
+ * @returns the resolved identity with its explicit or catalog-derived history route installed.
97
85
  */
98
- constructor(remote: SessionRemotes, restoredSelection?: SessionId, restoredAddress?: SubagentAddress);
99
- /**
100
- * Select a listed Session or a retained catalog-addressed child.
101
- * @param sessionId - listed or catalog-addressed Session id.
102
- */
103
- select(sessionId: SessionId): void;
104
- /**
105
- * Select a healthy child through its durable direct-parent address.
106
- * @param address - catalog-derived parent and child ids.
107
- */
108
- selectSubagent(address: SubagentAddress): void;
109
- /** Clear the selection (the layout falls to the no-session view state). */
110
- clearSelection(): void;
111
- /**
112
- * Return the durable catalog address retained for one child.
113
- * @param sessionId - possible addressed child id.
114
- * @returns The direct-parent address, when navigation discovered one.
115
- */
116
- subagentAddress(sessionId: SessionId): SubagentAddress | undefined;
86
+ resolveTarget(target: SessionTarget): SessionId;
117
87
  /**
118
88
  * Resolve an address for breadcrumb navigation without retaining transport authority.
119
89
  * @param sessionId - possible child id in an already-loaded catalog.
120
90
  * @returns A retained or catalog-derived direct-parent address.
121
91
  */
122
- navigationAddress(sessionId: SessionId): SubagentAddress | undefined;
92
+ subagentAddress(sessionId: SessionId): SubagentAddress | undefined;
123
93
  /**
124
- * Drop a session instance (scope-prune companion: instance
125
- * and scope share one lifecycle). The host session log is the durable
126
- * truth — a later get() lazily rebuilds and open() backfills history.
127
- * @param sessionId - the session to drop.
94
+ * Withdraw an exact Client instance before running its teardown callbacks.
95
+ * @param sessionId - identity to withdraw.
96
+ * @param expected - instance being released; a replacement is left untouched.
97
+ * @returns completion of the detached instance's stream teardown.
128
98
  */
129
- drop(sessionId: SessionId): Promise<void>;
99
+ drop(sessionId: SessionId, expected: Session): Promise<void>;
130
100
  /**
131
- * Stop owned timers and every remaining Session instance.
132
- * @returns when every Session Remote iterator has completed teardown.
101
+ * Stop catalog requests and dispose every resident Session.
102
+ * @returns once catalog requests and every Session stream have stopped.
133
103
  */
134
104
  dispose(): Promise<void>;
135
105
  private startSessionDisposal;
136
106
  private drainSessionDisposals;
137
107
  /**
138
108
  * Lazy build: return the existing instance or construct one (no auto-open —
139
- * open is triggered by the container's select callback).
109
+ * the reference allocator opens history after binding the scope).
110
+ * New instances reconcile retained metadata before returning.
140
111
  * @param sessionId - the session to get.
141
112
  * @returns the resident instance.
142
113
  */
143
114
  get(sessionId: SessionId): Session;
144
115
  private createSession;
145
- /** Resident per-session projection store (create-on-demand; outlives instantiation). */
146
- private projectionStore;
116
+ private effectiveBlank;
147
117
  /**
148
- * Refresh one direct-child catalog, reusing its in-flight request.
149
- * @param parentSessionId - catalog owner.
118
+ * Identities an engagement may still belong to: the given list rows, resident
119
+ * Session instances, and retained child addresses.
120
+ * @param summaries - list rows of the caller's snapshot.
121
+ * @returns the retained identity set.
150
122
  */
151
- refreshSubagents(parentSessionId: SessionId): Promise<void>;
123
+ private retainedIds;
152
124
  /**
153
- * Mark whether a catalog menu is consuming live membership updates.
154
- * @param parentSessionId - catalog owner.
155
- * @param open - current menu state.
125
+ * Forget one engagement that no retained identity holds.
126
+ * @param sessionId - identity whose engagement may be dropped.
127
+ * @param retained - identities from {@link retainedIds} for the caller's snapshot.
156
128
  */
157
- setSubagentCatalogOpen(parentSessionId: SessionId, open: boolean): void;
158
- /** Full refresh via session.list (single-flight: an in-flight call is reused). */
129
+ private pruneEngagement;
130
+ /** Resident per-session projection store (create-on-demand; outlives instantiation). */
131
+ private projectionStore;
132
+ /**
133
+ * Load a complete projection baseline once per connection; retry unsuccessful reads.
134
+ * @param sessionId - Session to inspect without opening its conversation.
135
+ * @returns completion of the current or newly started read.
136
+ */
137
+ refreshProjections(sessionId: SessionId): Promise<void>;
138
+ private agentAvailable;
139
+ private updateParentAvailability;
140
+ /** Full refresh via session.list (single-flight within one Host generation). */
159
141
  refreshList(): Promise<void>;
160
142
  /**
161
143
  * Search visible session message content without adding transient query
@@ -184,11 +166,12 @@ export declare class SessionManager {
184
166
  }>>;
185
167
  /**
186
168
  * Contract session.fork; on success merge the child into summaries
187
- * immediately (same synchronous-addressability guarantee as create). The
188
- * child carries the source's history, so it is never blank; lineage rides
189
- * parentSessionId so the list nests it under its source. A child published
190
- * before Workspace attachment fails is also reconciled into the list.
191
- * @param opts - source session and the optional seq anchoring the cut.
169
+ * immediately (same synchronous-addressability guarantee as create).
170
+ * Blankness starts provisionally true so the authoritative Host summary can
171
+ * preserve it or lower it after an exact cut before the first `turn/start`;
172
+ * lineage rides parentSessionId. A child published before Workspace
173
+ * attachment fails is also reconciled into the list.
174
+ * @param opts - source session and the optional exact inclusive boundary seq.
192
175
  * @returns the fork result (the child session id).
193
176
  */
194
177
  fork(opts: {
@@ -198,10 +181,15 @@ export declare class SessionManager {
198
181
  sessionId: SessionId;
199
182
  }>>;
200
183
  /**
201
- * Insert-or-enrich a locally synthesized summary: a new id prepends; an
202
- * existing entry only gains fields it lacks (the session-added frame and the
203
- * create() echo race — whichever lands second must fill the placeholder's
204
- * missing cwd/parentSessionId, never overwrite list-refresh data).
184
+ * Rename a Session and update its title projection without opening its history.
185
+ * @param sessionId - Session to rename.
186
+ * @param title - raw title text for Host normalization.
187
+ * @returns the accepted title and event position, or the Remote failure.
188
+ */
189
+ rename(sessionId: SessionId, title: string): Promise<RemoteResult<SessionRenameValue>>;
190
+ /**
191
+ * Merge a Host summary, replacing live state and filling missing metadata.
192
+ * Local create/fork placeholders only fill metadata on an existing row.
205
193
  */
206
194
  private mergeSummary;
207
195
  /** Apply immediately and retain for replay when a list response is in flight. */
@@ -217,6 +205,12 @@ export declare class SessionManager {
217
205
  * @returns the cached reference (stable until the next flush).
218
206
  */
219
207
  getListSnapshot(): SessionListSnapshot;
208
+ /**
209
+ * Read cached projection values for a Session that may exist only in a loaded subagent catalog.
210
+ * @param sessionId - Session whose control or history baseline supplied projections.
211
+ * @returns current values, or undefined before any projection store exists.
212
+ */
213
+ projectionValues(sessionId: SessionId): Readonly<Partial<SessionProjectionMap>> | undefined;
220
214
  /**
221
215
  * Apply a complete control baseline or one later replacement frame.
222
216
  * @param frame - baseline or live control replacement from Session Controller.
@@ -228,6 +222,15 @@ export declare class SessionManager {
228
222
  * @param summary - current Host summary for the added Session.
229
223
  */
230
224
  handleSessionAdded(summary: SessionSummary): void;
225
+ /**
226
+ * Merge one list-surface projection block by the sequence space it declares.
227
+ * A `sequenced` block came from the Host's live registry for an attached
228
+ * Session, so each key lands under higher-seq-wins against that Session's
229
+ * baselines and frames. A `cached` block was viewed from the persisted
230
+ * checkpoint by a header-only listing: its watermark is not comparable with
231
+ * this connection's seqs, so it only fills keys no sequenced row holds.
232
+ */
233
+ private applyListBlock;
231
234
  /**
232
235
  * Apply one Session removal forwarded through `ctx.remote.$on`.
233
236
  * @param sessionId - removed Session identity.
@@ -253,28 +256,11 @@ export declare class SessionManager {
253
256
  handleSessionError(sessionId: SessionId, message: string): void;
254
257
  /**
255
258
  * Repair one re-established Host-event generation with queryable baselines.
259
+ * Discard old projection cuts before new queries, including cold Sessions
260
+ * absent from the process-local control baseline.
256
261
  * Opened Session follow streams resume independently through API Gateway.
257
262
  */
258
263
  handleConnected(): void;
259
- /** Debounce membership refetches while one parent catalog is selected or open. */
260
- private scheduleCatalogRefresh;
261
- /** Apply one Agent-driver transition to loaded and in-flight catalogs. */
262
- private updateCatalogActivity;
263
- /** Preserve and project a positive expandability hint after one direct subagent publishes. */
264
- private markCatalogParentExpandable;
265
- /** Apply one positive expandability hint to every loaded catalog containing that unique row id. */
266
- private applyCatalogParentExpandable;
267
- /** Fold request-local row mutations into one catalog result before publication. */
268
- private withCatalogMutations;
269
- /**
270
- * Reconcile completion reminders against the latest summaries, eagerly after
271
- * every mutation and pull (a snapshot-build-time pass would collapse
272
- * consecutive status frames into one observation). A running→idle edge of a
273
- * non-selected session arms its reminder; running disarms it; removal drops
274
- * it. First observation only records the running bit — sessions already
275
- * idle at load get no reminder.
276
- */
277
- private syncCompletedNotifications;
278
264
  private buildListSnapshot;
279
265
  }
280
266
  //# sourceMappingURL=manager.d.ts.map