@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,192 @@
1
+ /** Live Session queue, jobs, and projection state with reconnect baselines. */
2
+ import { Deque } from '@deepseek-ai/dsh-deque';
3
+ /** Owns the Host-wide Session control stream. */
4
+ export class SessionControlController {
5
+ ctx;
6
+ streams = new Set();
7
+ /** @param ctx - Host context carrying live Agent, projection, and jobs services. */
8
+ constructor(ctx) {
9
+ this.ctx = ctx;
10
+ ctx.on('session/event', (session, event) => { this.onSessionEvent(session, event); });
11
+ ctx.sessionProjections.onChanged((session, key, value, seq) => {
12
+ this.broadcast({
13
+ type: 'projection',
14
+ sessionId: session.id,
15
+ key,
16
+ value: value,
17
+ seq,
18
+ });
19
+ });
20
+ ctx.inject(['jobs'], (jobsCtx) => {
21
+ jobsCtx.jobs.onJobsChanged((owner) => { this.onJobsChanged(owner); });
22
+ });
23
+ ctx.on('session/created', (session) => {
24
+ const jobs = this.jobsFor(this.ctx.agents.get(session.id));
25
+ if (jobs.length > 0)
26
+ this.broadcast({ type: 'jobs', sessionId: session.id, jobs });
27
+ });
28
+ ctx.effect(() => () => {
29
+ for (const stream of this.streams)
30
+ stream.end();
31
+ this.streams.clear();
32
+ }, 'session-controller.control');
33
+ }
34
+ /**
35
+ * Open one generation of Host-wide live control state.
36
+ * @param signal - Remote stream cancellation.
37
+ * @returns one complete baseline followed by live replacement frames.
38
+ */
39
+ async *control(signal) {
40
+ signal.throwIfAborted();
41
+ const queue = new ControlQueue();
42
+ this.streams.add(queue);
43
+ try {
44
+ yield { type: 'baseline', value: this.baseline() };
45
+ yield* queue.iterate(signal);
46
+ }
47
+ finally {
48
+ this.streams.delete(queue);
49
+ queue.end();
50
+ }
51
+ }
52
+ baseline() {
53
+ const sessions = this.ctx.sessions.list();
54
+ const queues = Object.create(null);
55
+ const jobs = Object.create(null);
56
+ for (const session of sessions) {
57
+ const agent = this.ctx.agents.get(session.id);
58
+ queues[session.id] = agent?.session === session ? queueItems(agent) : [];
59
+ jobs[session.id] = this.jobsFor(agent);
60
+ }
61
+ return {
62
+ queues,
63
+ jobs,
64
+ projections: this.projectionBaseline(sessions),
65
+ };
66
+ }
67
+ projectionBaseline(sessions) {
68
+ const blocks = Object.create(null);
69
+ for (const session of sessions) {
70
+ const snapshot = this.ctx.sessionProjections.snapshot(session);
71
+ blocks[session.id] = {
72
+ asOfSeq: snapshot.asOfSeq,
73
+ // Every projection definition validates its value before snapshot publication.
74
+ values: snapshot.values,
75
+ };
76
+ }
77
+ return blocks;
78
+ }
79
+ onSessionEvent(session, event) {
80
+ if (event.type !== 'agent/inbox/spliced')
81
+ return;
82
+ const agent = this.ctx.agents.get(session.id);
83
+ if (agent?.session !== session)
84
+ return;
85
+ this.broadcast({
86
+ type: 'queue',
87
+ sessionId: session.id,
88
+ items: queueItems(agent, event.data),
89
+ });
90
+ }
91
+ onJobsChanged(owner) {
92
+ if (owner !== undefined) {
93
+ this.broadcast({ type: 'jobs', sessionId: owner.id, jobs: this.jobsFor(owner) });
94
+ return;
95
+ }
96
+ for (const session of this.ctx.sessions.list()) {
97
+ this.broadcast({
98
+ type: 'jobs',
99
+ sessionId: session.id,
100
+ jobs: this.jobsFor(this.ctx.agents.get(session.id)),
101
+ });
102
+ }
103
+ }
104
+ jobsFor(agent) {
105
+ const jobs = this.ctx.get('jobs');
106
+ return jobs === undefined ? [] : jobs.list(agent).map(jobView);
107
+ }
108
+ broadcast(frame) {
109
+ for (const stream of this.streams)
110
+ stream.push(frame);
111
+ }
112
+ }
113
+ class ControlQueue {
114
+ buffer = new Deque();
115
+ wake;
116
+ done = false;
117
+ push(frame) {
118
+ if (this.done)
119
+ return;
120
+ this.buffer.pushBack(frame);
121
+ const wake = this.wake;
122
+ this.wake = undefined;
123
+ wake?.();
124
+ }
125
+ end() {
126
+ if (this.done)
127
+ return;
128
+ this.done = true;
129
+ const wake = this.wake;
130
+ this.wake = undefined;
131
+ wake?.();
132
+ }
133
+ async *iterate(signal) {
134
+ const onAbort = () => { this.end(); };
135
+ signal.addEventListener('abort', onAbort, { once: true });
136
+ try {
137
+ while (!this.done && !signal.aborted) {
138
+ const frame = this.buffer.popFront();
139
+ if (frame !== undefined) {
140
+ yield frame;
141
+ continue;
142
+ }
143
+ await new Promise((resolve) => { this.wake = resolve; });
144
+ }
145
+ while (this.buffer.size > 0 && !signal.aborted)
146
+ yield this.buffer.popFront();
147
+ }
148
+ finally {
149
+ signal.removeEventListener('abort', onAbort);
150
+ this.end();
151
+ }
152
+ }
153
+ }
154
+ function queueItems(agent, splice) {
155
+ const project = (target) => {
156
+ const messages = target === 'next-turn' ? agent.inbox.nextTurn : agent.inbox.nextStep;
157
+ return splice?.target === target
158
+ ? messages.toSpliced(splice.start, splice.removedCount ?? 0, ...splice.inserted)
159
+ : messages;
160
+ };
161
+ return [
162
+ ...project('next-turn').map(message => ({
163
+ id: message.id,
164
+ placement: 'queued',
165
+ ...promptRpcId(message),
166
+ message: { id: message.id, content: message.content },
167
+ })),
168
+ ...project('next-step').map(message => ({
169
+ id: message.id,
170
+ placement: message.source.kind === 'user' ? 'steering' : 'context',
171
+ ...promptRpcId(message),
172
+ message: { id: message.id, content: message.content },
173
+ })),
174
+ ];
175
+ }
176
+ /** Prompt-RPC identity carried by a browser-submitted message's user source. */
177
+ function promptRpcId(message) {
178
+ const source = message.source;
179
+ return source.kind === 'user' && 'rpcId' in source ? { rpcId: source.rpcId } : {};
180
+ }
181
+ function jobView(job) {
182
+ return {
183
+ id: job.id,
184
+ kind: job.kind,
185
+ label: job.label,
186
+ status: job.status,
187
+ ...(job.detail === undefined ? {} : { detail: job.detail }),
188
+ startedAt: job.startedAt,
189
+ ...(job.finishedAt === undefined ? {} : { finishedAt: job.finishedAt }),
190
+ };
191
+ }
192
+ //# sourceMappingURL=control.js.map
@@ -0,0 +1,27 @@
1
+ /** Session Controller adapter for Agent-scoped file-reference discovery. */
2
+ import type { Context } from '@deepseek-ai/cordis';
3
+ import type { Agent } from '@deepseek-ai/dsh-agent';
4
+ import type { FileReferenceCandidate } from '@deepseek-ai/dsh-file-reference/types';
5
+ import { TypertRemoteService } from '@deepseek-ai/dsh-typert-protocol';
6
+ declare module '@deepseek-ai/cordis' {
7
+ interface Context {
8
+ /** Host owner of the `fileReferences` Remote namespace. */
9
+ sessionFileReferences: SessionFileReferences;
10
+ }
11
+ }
12
+ /** Host Remote adapter over the composed file-reference provider. */
13
+ export declare class SessionFileReferences extends TypertRemoteService {
14
+ static inject: string[];
15
+ /** @param ctx - Host context carrying the selected file-reference provider. */
16
+ constructor(ctx: Context);
17
+ /**
18
+ * List file and directory candidates for one Agent's working directory.
19
+ * @param agent - target Agent resolved from the Session identity on the wire.
20
+ * @param query - path text following `@` or `@"`.
21
+ * @param signal - caller cancellation.
22
+ * @returns deterministic path-only candidates from the composed provider.
23
+ */
24
+ list(agent: Agent, query: string, signal: AbortSignal): Promise<FileReferenceCandidate[]>;
25
+ }
26
+ export default SessionFileReferences;
27
+ //# sourceMappingURL=file-references.d.ts.map
@@ -0,0 +1,69 @@
1
+ /** Session Controller adapter for Agent-scoped file-reference discovery. */
2
+ var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) {
3
+ var useValue = arguments.length > 2;
4
+ for (var i = 0; i < initializers.length; i++) {
5
+ value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
6
+ }
7
+ return useValue ? value : void 0;
8
+ };
9
+ var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
10
+ function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; }
11
+ var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
12
+ var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
13
+ var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
14
+ var _, done = false;
15
+ for (var i = decorators.length - 1; i >= 0; i--) {
16
+ var context = {};
17
+ for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p];
18
+ for (var p in contextIn.access) context.access[p] = contextIn.access[p];
19
+ context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); };
20
+ var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);
21
+ if (kind === "accessor") {
22
+ if (result === void 0) continue;
23
+ if (result === null || typeof result !== "object") throw new TypeError("Object expected");
24
+ if (_ = accept(result.get)) descriptor.get = _;
25
+ if (_ = accept(result.set)) descriptor.set = _;
26
+ if (_ = accept(result.init)) initializers.unshift(_);
27
+ }
28
+ else if (_ = accept(result)) {
29
+ if (kind === "field") initializers.unshift(_);
30
+ else descriptor[key] = _;
31
+ }
32
+ }
33
+ if (target) Object.defineProperty(target, contextIn.name, descriptor);
34
+ done = true;
35
+ };
36
+ import { Remote, TypertRemoteService } from '@deepseek-ai/dsh-typert-protocol';
37
+ /** Host Remote adapter over the composed file-reference provider. */
38
+ let SessionFileReferences = (() => {
39
+ let _classSuper = TypertRemoteService;
40
+ let _instanceExtraInitializers = [];
41
+ let _list_decorators;
42
+ return class SessionFileReferences extends _classSuper {
43
+ static {
44
+ const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
45
+ _list_decorators = [Remote];
46
+ __esDecorate(this, null, _list_decorators, { kind: "method", name: "list", static: false, private: false, access: { has: obj => "list" in obj, get: obj => obj.list }, metadata: _metadata }, null, _instanceExtraInitializers);
47
+ if (_metadata) Object.defineProperty(this, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
48
+ }
49
+ static inject = ['fileReferences', 'typert'];
50
+ /** @param ctx - Host context carrying the selected file-reference provider. */
51
+ constructor(ctx) {
52
+ super(ctx, 'sessionFileReferences', { namespace: 'fileReferences' });
53
+ __runInitializers(this, _instanceExtraInitializers);
54
+ }
55
+ /**
56
+ * List file and directory candidates for one Agent's working directory.
57
+ * @param agent - target Agent resolved from the Session identity on the wire.
58
+ * @param query - path text following `@` or `@"`.
59
+ * @param signal - caller cancellation.
60
+ * @returns deterministic path-only candidates from the composed provider.
61
+ */
62
+ list(agent, query, signal) {
63
+ return this.ctx.fileReferences.list(agent, query, signal);
64
+ }
65
+ };
66
+ })();
67
+ export { SessionFileReferences };
68
+ export default SessionFileReferences;
69
+ //# sourceMappingURL=file-references.js.map
@@ -0,0 +1,31 @@
1
+ /** Cold Session history pagination and live-event source. */
2
+ import type { Context } from '@deepseek-ai/cordis';
3
+ import { type SessionObservation } from '@deepseek-ai/dsh-session-query';
4
+ import type { SessionFollowRequest, SessionFollowFrame, SessionPage, SessionPageRequest } from './types.ts';
5
+ /** Implements cold-safe history operations delegated by the Session Controller. */
6
+ export declare class SessionHistoryController {
7
+ private readonly ctx;
8
+ private readonly promote;
9
+ private readonly closeFollowers;
10
+ /**
11
+ * @param ctx - Host context carrying Session query and projection services.
12
+ * @param promote - starts ordinary Session activation after snapshot delivery.
13
+ */
14
+ constructor(ctx: Context, promote: (observation: SessionObservation) => void);
15
+ /**
16
+ * Read one message-aligned history page without activating an Agent.
17
+ * @param request - durable address and backwards-page cursor.
18
+ * @param signal - caller cancellation for persistence reads.
19
+ * @returns a contiguous event page.
20
+ */
21
+ page(request: SessionPageRequest, signal: AbortSignal): Promise<SessionPage>;
22
+ /**
23
+ * Follow events appended after an initial cursor on one durable address.
24
+ * @param request - durable address and last committed sequence already held by the caller.
25
+ * @param signal - stream cancellation owned by the Remote carrier.
26
+ * @returns a complete opening snapshot followed by gap-free event frames.
27
+ */
28
+ follow(request: SessionFollowRequest, signal: AbortSignal): AsyncIterable<SessionFollowFrame>;
29
+ private sourceFor;
30
+ }
31
+ //# sourceMappingURL=history.d.ts.map