@crazx/dsh-api-session-controller 0.1.2-alpha.3.zw.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 (74) hide show
  1. package/LICENSE +21 -0
  2. package/README.i18n.yaml +6 -0
  3. package/README.md +74 -0
  4. package/README.zh.md +74 -0
  5. package/lib/client.js +2724 -0
  6. package/lib/index.js +2826 -0
  7. package/lib/invariant.js +13 -0
  8. package/lib/typert.host.d.ts +3 -0
  9. package/lib/typert.host.js +2574 -0
  10. package/lib/typert.remote-client.d.ts +67 -0
  11. package/lib/typert.remote-client.js +1119 -0
  12. package/lib/types/agent.d.ts +156 -0
  13. package/lib/types/agent.js +537 -0
  14. package/lib/types/catalog.d.ts +11 -0
  15. package/lib/types/catalog.js +58 -0
  16. package/lib/types/client/contract/events.d.ts +71 -0
  17. package/lib/types/client/contract/events.js +91 -0
  18. package/lib/types/client/contract/session.d.ts +150 -0
  19. package/lib/types/client/contract/session.js +2 -0
  20. package/lib/types/client/contract/sessions.d.ts +125 -0
  21. package/lib/types/client/contract/sessions.js +2 -0
  22. package/lib/types/client/contract/snapshot.d.ts +82 -0
  23. package/lib/types/client/contract/snapshot.js +2 -0
  24. package/lib/types/client/index.d.ts +30 -0
  25. package/lib/types/client/index.js +48 -0
  26. package/lib/types/client/ordered-baseline.d.ts +12 -0
  27. package/lib/types/client/ordered-baseline.js +41 -0
  28. package/lib/types/client/scope.d.ts +36 -0
  29. package/lib/types/client/scope.js +54 -0
  30. package/lib/types/client/sessions/history-records.d.ts +22 -0
  31. package/lib/types/client/sessions/history-records.js +31 -0
  32. package/lib/types/client/sessions/lineage.d.ts +38 -0
  33. package/lib/types/client/sessions/lineage.js +56 -0
  34. package/lib/types/client/sessions/manager.d.ts +280 -0
  35. package/lib/types/client/sessions/manager.js +894 -0
  36. package/lib/types/client/sessions/notifier.d.ts +39 -0
  37. package/lib/types/client/sessions/notifier.js +98 -0
  38. package/lib/types/client/sessions/projection-store.d.ts +108 -0
  39. package/lib/types/client/sessions/projection-store.js +129 -0
  40. package/lib/types/client/sessions/queue-mirror.d.ts +26 -0
  41. package/lib/types/client/sessions/queue-mirror.js +61 -0
  42. package/lib/types/client/sessions/remotes.d.ts +30 -0
  43. package/lib/types/client/sessions/remotes.js +8 -0
  44. package/lib/types/client/sessions/service.d.ts +349 -0
  45. package/lib/types/client/sessions/service.js +574 -0
  46. package/lib/types/client/sessions/session.d.ts +294 -0
  47. package/lib/types/client/sessions/session.js +711 -0
  48. package/lib/types/client/time-zone.d.ts +8 -0
  49. package/lib/types/client/time-zone.js +14 -0
  50. package/lib/types/client/transport.d.ts +73 -0
  51. package/lib/types/client/transport.js +106 -0
  52. package/lib/types/commands.d.ts +69 -0
  53. package/lib/types/commands.js +544 -0
  54. package/lib/types/control.d.ts +23 -0
  55. package/lib/types/control.js +192 -0
  56. package/lib/types/file-references.d.ts +27 -0
  57. package/lib/types/file-references.js +69 -0
  58. package/lib/types/history.d.ts +31 -0
  59. package/lib/types/history.js +376 -0
  60. package/lib/types/index.d.ts +171 -0
  61. package/lib/types/index.js +424 -0
  62. package/lib/types/invariant.d.ts +9 -0
  63. package/lib/types/invariant.js +12 -0
  64. package/lib/types/list.d.ts +53 -0
  65. package/lib/types/list.js +405 -0
  66. package/lib/types/model-selection-projection.d.ts +8 -0
  67. package/lib/types/model-selection-projection.js +66 -0
  68. package/lib/types/remote-events.d.ts +8 -0
  69. package/lib/types/remote-events.js +2 -0
  70. package/lib/types/skill-catalog.d.ts +28 -0
  71. package/lib/types/skill-catalog.js +192 -0
  72. package/lib/types/types.d.ts +505 -0
  73. package/lib/types/types.js +6 -0
  74. package/package.json +154 -0
@@ -0,0 +1,294 @@
1
+ import type { Context } from '@deepseek-ai/cordis';
2
+ import type { AttachmentIdType, ImageAttachmentRef } from '@deepseek-ai/dsh-attachment';
3
+ import type { SubagentAddress } from '@deepseek-ai/dsh-subagent/client';
4
+ import type { MessageId } from '@deepseek-ai/dsh-llm/brand';
5
+ import type { SessionId } from '@deepseek-ai/dsh-session/types';
6
+ import type { PromptContentPart, QueueAction, SessionControlFrame, SessionQueuedItem, SessionRequestId } from '../../types.ts';
7
+ import type { BeginSubmissionInput, SessionFace, SubmissionHandle } from '../contract/session.ts';
8
+ import type { SessionSnapshot } from '../contract/snapshot.ts';
9
+ import { MutableSessionEventSource } from '../contract/events.ts';
10
+ import type { RemoteResult } from '@deepseek-ai/dsh-typert-protocol';
11
+ import type { SessionRemotes } from './remotes.ts';
12
+ import { ProjectionValueStore } from './projection-store.ts';
13
+ /** Messages requested per history page. */
14
+ export declare const PAGE_MESSAGES = 50;
15
+ /** Messages requested per page while a turn jump loops backwards (fewer, larger round trips). */
16
+ export declare const JUMP_PAGE_MESSAGES = 200;
17
+ /** Manager-owned observers of a Session object's local state edges. */
18
+ export interface SessionOptions {
19
+ /** Catalog-discovered address selecting non-activating subagent transport. */
20
+ address?: SubagentAddress;
21
+ /** Whether the exact direct parent Agent was live at the latest catalog read; absent before that read. */
22
+ parentAvailable?: boolean;
23
+ /**
24
+ * First ACCEPTED prompt on a blank session (fires at most once, on the
25
+ * prompt RPC's success response): the manager mirrors the blank→false flip
26
+ * into its list row so the session surfaces without waiting for a host
27
+ * frame. Acceptance is the flip point because it proves the user message
28
+ * is in the host log; a rejected first prompt keeps the session blank
29
+ * (hidden, still reusable by connectWorkspace).
30
+ */
31
+ onEngaged?(session: Session): void;
32
+ /**
33
+ * Manager-owned projection value store to adopt (frames route through the
34
+ * manager and values outlive instantiation); omitted, the Session owns a
35
+ * private store (bare object-layer construction).
36
+ */
37
+ projections?: ProjectionValueStore;
38
+ }
39
+ /**
40
+ * Owns a session's event window, lifecycle state, and observable
41
+ * snapshot. React bindings remain outside this data layer. Features see only
42
+ * the {@link SessionFace} slice (ISession verbs + the snapshot source); the
43
+ * remaining public members are Session Controller internals.
44
+ */
45
+ export declare class Session implements SessionFace {
46
+ readonly sessionId: SessionId;
47
+ private readonly remote;
48
+ private readonly options;
49
+ private baseSeq;
50
+ private hasMore;
51
+ private openState;
52
+ private openError;
53
+ private openPromise;
54
+ /** Bumped by stream replacement to invalidate an in-flight doOpen. Stale
55
+ * passes drop all writes once the generation moves on. */
56
+ private openGeneration;
57
+ private loadingOlder;
58
+ /** Shared low-water target of the running jump loop; null when no jump is paging. */
59
+ private jumpTargetSeq;
60
+ /** The running jump loop's completion, shared by retargeting callers. */
61
+ private jumpPromise;
62
+ /** Authoritative stream-only inbox snapshot; pending work never hits history. */
63
+ private readonly queueMirror;
64
+ private running;
65
+ private address;
66
+ private parentAvailable;
67
+ /**
68
+ * Sticky send marker, private input of the composerPhase derivation: set
69
+ * synchronously before prompt()'s first await, never reset — the blank →
70
+ * engaging edge of the phase machine (see ComposerPhase).
71
+ */
72
+ private promptAttempted;
73
+ /** A first accepted prompt stays in the engaging phase until its turn is observable. */
74
+ private firstPromptPendingTurn;
75
+ /** Empty-log mirror (see ConversationSnapshot.blank); unknown bare sessions begin conservatively blank. */
76
+ private blankBit;
77
+ private removed;
78
+ private promptError;
79
+ private lastAgentError;
80
+ /** Local submission echoes, insertion-ordered (see SessionSnapshot.pendingSubmissions). */
81
+ private pendingSubmissions;
82
+ /** Per-echo settlement state; `retiring` latches the first observation so a
83
+ * queue frame and its durable event cannot both retire one echo. */
84
+ private readonly submissionSettlements;
85
+ /** Owns the addressed page/follow lifecycle while this Session is open. */
86
+ private events;
87
+ /**
88
+ * Per-session projection value store (push model; see the session-projection
89
+ * subsystem page, docs/subsystems/session-projection.md): finished whole
90
+ * values computed on the Host, seeded by the tail page's
91
+ * projections block and updated by Session Controller control frames under the
92
+ * one higher-seq-wins rule. Keys are read via `projections.faceOf(key)`
93
+ * (the useProjection resolution face); the conversation snapshot never
94
+ * carries projection values, and no client-side domain folding exists.
95
+ * Manager-owned when constructed through SessionManager (frames route and
96
+ * the store outlives instantiation, the title-snapshot precedent); a bare
97
+ * construction gets a private store.
98
+ */
99
+ readonly projections: ProjectionValueStore;
100
+ /** Contiguous history and live tail consumed by Conversation assembly. */
101
+ readonly eventSource: MutableSessionEventSource;
102
+ private snapshotCache;
103
+ private readonly notifier;
104
+ /**
105
+ * Agent-scoped cordis context, bound once by ClientSessions when it
106
+ * mints the scope (the client mirror of the host Agent's loopCtx). The
107
+ * Session dispatches its own scoped events through it; undefined means
108
+ * unbound (bare object-layer construction) or already pruned — both skip
109
+ * dispatch-dependent behavior rather than fail.
110
+ */
111
+ private actx;
112
+ /**
113
+ * @param sessionId - Host session identity (client sessions are always Host-born).
114
+ * @param remote - generated Remote namespaces this session calls.
115
+ * @param options - optional manager-owned state observers.
116
+ */
117
+ constructor(sessionId: SessionId, remote: SessionRemotes, options?: SessionOptions);
118
+ /**
119
+ * Bind the Agent-scoped context minted by ClientSessions (single write;
120
+ * a second bind is a wiring error and throws). Direction stays one-way at
121
+ * this binding boundary: consumers still reach the Session via `sessions.sessionOf`,
122
+ * while the Session holds its own dispatch point (host Agent.loopCtx
123
+ * mirror).
124
+ * @param actx - the agent's scoped context.
125
+ */
126
+ bindScope(actx: Context): void;
127
+ /** Release the bound scope at prune time (a later rebind accompanies a freshly minted scope). */
128
+ unbindScope(): void;
129
+ /**
130
+ * Register one local submission echo (see the ISession declaration).
131
+ * Synchronous through markDirty: the echo is in the very next snapshot, so
132
+ * the conversation can paint it before the caller starts serializing.
133
+ * @param input - echo content and the optional settlement callback.
134
+ * @returns the minted identity for {@link prompt} plus the pre-prompt abandon path.
135
+ */
136
+ beginSubmission(input: BeginSubmissionInput): SubmissionHandle;
137
+ /**
138
+ * Send (queue/steer passed through 1:1); failures land in the snapshot's promptError.
139
+ * @param content - text plus browser-owned temporary image uploads.
140
+ * @param mode - queue appends after the current turn; steer interrupts it.
141
+ * @param signal - optional caller cancellation for the complete admission round-trip.
142
+ * @param requestId - identity from {@link beginSubmission}; a failed identified prompt retires its echo.
143
+ * @returns the prompt result (also mirrored into promptError on failure).
144
+ */
145
+ prompt(content: PromptContentPart[], mode: 'queue' | 'steer', signal?: AbortSignal, requestId?: SessionRequestId): Promise<RemoteResult<{
146
+ accepted: true;
147
+ }>>;
148
+ /**
149
+ * Resolve one image referenced by this session into browser-consumable bytes.
150
+ * @param attachmentId - opaque id found in the folded session log.
151
+ * @returns the authenticated reference and decoded bytes.
152
+ */
153
+ readAttachment(attachmentId: AttachmentIdType): Promise<RemoteResult<{
154
+ attachment: ImageAttachmentRef;
155
+ data: Uint8Array;
156
+ }>>;
157
+ /** Apply one operation to a still-pending queue occurrence. */
158
+ updateQueue(itemId: MessageId, action: QueueAction): Promise<RemoteResult<{
159
+ accepted: true;
160
+ }>>;
161
+ /**
162
+ * Stop the active turn while the Host preserves pending inbox work; failures
163
+ * land in promptError (same error-strip display slot). A subagent address
164
+ * routes through `subagents.interruptByParent`, whose durable parent-address
165
+ * authority works without a live parent Agent.
166
+ * @returns the cancel result.
167
+ */
168
+ cancel(): Promise<RemoteResult<{
169
+ accepted: true;
170
+ }>>;
171
+ /**
172
+ * Rename: contract session.rename 1:1. On success settle the 'title'
173
+ * projection cell from the response's `{title, seq}` under the store's
174
+ * higher-seq-wins rule (the push frame arriving later is a no-op replay),
175
+ * so the list row and any useProjection('title') reader update without
176
+ * waiting for the control-stream projection update.
177
+ * @param title - raw title text (the host normalizes acceptance).
178
+ * @returns the rename result (normalized accepted title + title event seq).
179
+ */
180
+ rename(title: string): Promise<RemoteResult<{
181
+ title: string;
182
+ seq: number;
183
+ }>>;
184
+ /**
185
+ * Execute one slash-command line against this session's agent — pure
186
+ * admission semantics (the host executor durably logs the lifecycle;
187
+ * outcomes render as flow nodes, never as a response echo).
188
+ * @param line - the full command line, leading slash included.
189
+ * @returns the admission result.
190
+ */
191
+ command(line: string): Promise<RemoteResult<{
192
+ matched: boolean;
193
+ }>>;
194
+ /** First open: pull the tail page (idempotent — in-flight/already-open returns the existing promise). */
195
+ open(): Promise<void>;
196
+ /** Page up: pull one earlier page with the window's first seq as beforeSeq and prepend. */
197
+ loadOlder(): Promise<void>;
198
+ /** Jump loader: page backwards until the window covers seq (see ISession.loadThrough). */
199
+ loadThrough(seq: number): Promise<void>;
200
+ /** Rebuild an opened history source after address replacement.
201
+ * Invalidates any in-flight open first; queue state belongs to the independently
202
+ * reconnecting control stream and remains untouched. */
203
+ resync(): Promise<void>;
204
+ /**
205
+ * uSES subscription entry.
206
+ * @param listener - change callback.
207
+ * @returns the unsubscribe function.
208
+ */
209
+ subscribe(listener: () => void): () => void;
210
+ /**
211
+ * Cached Session snapshot (rebuilt lazily when dirty with no listeners).
212
+ * @returns the cached reference (stable until the next flush).
213
+ */
214
+ getSnapshot(): SessionSnapshot;
215
+ /**
216
+ * Replace every transient control value for this Session from one stream baseline.
217
+ * @param queue - complete pending queue for this Session.
218
+ */
219
+ replaceControl(queue: readonly SessionQueuedItem[]): void;
220
+ /**
221
+ * Apply one Session-addressed live control update.
222
+ * @param frame - queue replacement addressed to this Session.
223
+ */
224
+ handleControlFrame(frame: Extract<SessionControlFrame, {
225
+ type: 'queue';
226
+ }>): void;
227
+ /**
228
+ * Running-bit relay from the host stream (list entry and snapshot stay consistent).
229
+ * @param running - the new running state.
230
+ */
231
+ handleRunning(running: boolean): void;
232
+ /**
233
+ * Install or clear the catalog-discovered transport address. A changed
234
+ * address rebuilds an already-open window through its new history route.
235
+ * @param address - direct parent/child address, or undefined for ordinary transport.
236
+ * @param parentAvailable - latest exact-parent availability hint, or undefined before a catalog read.
237
+ */
238
+ configureSubagent(address: SubagentAddress | undefined, parentAvailable?: boolean): void;
239
+ /**
240
+ * Update only the parent availability hint from a catalog refresh.
241
+ * @param available - whether the exact direct parent is live.
242
+ */
243
+ handleSubagentParentAvailable(available: boolean): void;
244
+ /**
245
+ * Blank-bit relay from the authoritative summary source (`session.list` and
246
+ * `api-session/added`). Monotone: once any signal (local first send,
247
+ * running flip, an earlier summary) cleared it, a stale true never
248
+ * re-blanks.
249
+ * @param blank - the summary's derived empty-log bit.
250
+ */
251
+ handleBlank(blank: boolean): void;
252
+ /** `api-session/removed` relay: flag the snapshot while retaining the resident instance. */
253
+ handleRemoved(): void;
254
+ /**
255
+ * `api-session/error` relay: the outlet for live failures with no turn position.
256
+ * @param message - the stringified error.
257
+ */
258
+ handleAgentError(message: string): void;
259
+ /**
260
+ * Stop the Session's live Remote source.
261
+ * @returns when the Remote iterator has completed teardown.
262
+ */
263
+ dispose(): Promise<void>;
264
+ /** @param generation - openGeneration at launch; stale passes cannot publish after replacement. */
265
+ private doOpen;
266
+ /** Apply one contiguous journal update already reconciled by the Remote stream. */
267
+ private acceptEventChange;
268
+ /** Replace the complete contiguous window and apply page-owned projection metadata. */
269
+ private installWindow;
270
+ /** Prepend one stream-validated history page. */
271
+ private prependWindow;
272
+ /** Append one stream-validated live event. */
273
+ private appendLive;
274
+ /** Retire the matching echo when a durable browser-prompt `user/message` becomes visible. */
275
+ private observeSubmissionEvent;
276
+ /** Retire echoes whose prompts landed in the host inbox instead of the log (running-turn submissions). */
277
+ private observeSubmissionQueue;
278
+ /**
279
+ * Latch one observed settlement and remove the echo an animation frame
280
+ * later. The delay keeps the echo in the snapshot until the frame in which
281
+ * the durable node (whose assembly frame was registered first) is
282
+ * renderable; the render-time rpcId dedupe hides the one-frame overlap.
283
+ */
284
+ private scheduleObservedRetirement;
285
+ /** Remove one unsettled echo immediately (prompt rejection, abort, or disposal). */
286
+ private retireFailedSubmission;
287
+ /** Single removal point: drop the echo, publish, then notify the owner. */
288
+ private finishSubmission;
289
+ /** Publish a terminal background failure only while this stream still owns the Session. */
290
+ private failEventStream;
291
+ private buildSnapshot;
292
+ private sessionAddress;
293
+ }
294
+ //# sourceMappingURL=session.d.ts.map