@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.
- package/LICENSE +21 -0
- package/README.i18n.yaml +6 -0
- package/README.md +74 -0
- package/README.zh.md +74 -0
- package/lib/client.js +2724 -0
- package/lib/index.js +2826 -0
- package/lib/invariant.js +13 -0
- package/lib/typert.host.d.ts +3 -0
- package/lib/typert.host.js +2574 -0
- package/lib/typert.remote-client.d.ts +67 -0
- package/lib/typert.remote-client.js +1119 -0
- package/lib/types/agent.d.ts +156 -0
- package/lib/types/agent.js +537 -0
- package/lib/types/catalog.d.ts +11 -0
- package/lib/types/catalog.js +58 -0
- package/lib/types/client/contract/events.d.ts +71 -0
- package/lib/types/client/contract/events.js +91 -0
- package/lib/types/client/contract/session.d.ts +150 -0
- package/lib/types/client/contract/session.js +2 -0
- package/lib/types/client/contract/sessions.d.ts +125 -0
- package/lib/types/client/contract/sessions.js +2 -0
- package/lib/types/client/contract/snapshot.d.ts +82 -0
- package/lib/types/client/contract/snapshot.js +2 -0
- package/lib/types/client/index.d.ts +30 -0
- package/lib/types/client/index.js +48 -0
- package/lib/types/client/ordered-baseline.d.ts +12 -0
- package/lib/types/client/ordered-baseline.js +41 -0
- package/lib/types/client/scope.d.ts +36 -0
- package/lib/types/client/scope.js +54 -0
- package/lib/types/client/sessions/history-records.d.ts +22 -0
- package/lib/types/client/sessions/history-records.js +31 -0
- package/lib/types/client/sessions/lineage.d.ts +38 -0
- package/lib/types/client/sessions/lineage.js +56 -0
- package/lib/types/client/sessions/manager.d.ts +280 -0
- package/lib/types/client/sessions/manager.js +894 -0
- package/lib/types/client/sessions/notifier.d.ts +39 -0
- package/lib/types/client/sessions/notifier.js +98 -0
- package/lib/types/client/sessions/projection-store.d.ts +108 -0
- package/lib/types/client/sessions/projection-store.js +129 -0
- package/lib/types/client/sessions/queue-mirror.d.ts +26 -0
- package/lib/types/client/sessions/queue-mirror.js +61 -0
- package/lib/types/client/sessions/remotes.d.ts +30 -0
- package/lib/types/client/sessions/remotes.js +8 -0
- package/lib/types/client/sessions/service.d.ts +349 -0
- package/lib/types/client/sessions/service.js +574 -0
- package/lib/types/client/sessions/session.d.ts +294 -0
- package/lib/types/client/sessions/session.js +711 -0
- package/lib/types/client/time-zone.d.ts +8 -0
- package/lib/types/client/time-zone.js +14 -0
- package/lib/types/client/transport.d.ts +73 -0
- package/lib/types/client/transport.js +106 -0
- package/lib/types/commands.d.ts +69 -0
- package/lib/types/commands.js +544 -0
- package/lib/types/control.d.ts +23 -0
- package/lib/types/control.js +192 -0
- package/lib/types/file-references.d.ts +27 -0
- package/lib/types/file-references.js +69 -0
- package/lib/types/history.d.ts +31 -0
- package/lib/types/history.js +376 -0
- package/lib/types/index.d.ts +171 -0
- package/lib/types/index.js +424 -0
- package/lib/types/invariant.d.ts +9 -0
- package/lib/types/invariant.js +12 -0
- package/lib/types/list.d.ts +53 -0
- package/lib/types/list.js +405 -0
- package/lib/types/model-selection-projection.d.ts +8 -0
- package/lib/types/model-selection-projection.js +66 -0
- package/lib/types/remote-events.d.ts +8 -0
- package/lib/types/remote-events.js +2 -0
- package/lib/types/skill-catalog.d.ts +28 -0
- package/lib/types/skill-catalog.js +192 -0
- package/lib/types/types.d.ts +505 -0
- package/lib/types/types.js +6 -0
- package/package.json +154 -0
|
@@ -0,0 +1,424 @@
|
|
|
1
|
+
/** Session Remote owner: cold reads, explicit Agent commands, and live control state. */
|
|
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
|
+
var __addDisposableResource = (this && this.__addDisposableResource) || function (env, value, async) {
|
|
37
|
+
if (value !== null && value !== void 0) {
|
|
38
|
+
if (typeof value !== "object" && typeof value !== "function") throw new TypeError("Object expected.");
|
|
39
|
+
var dispose, inner;
|
|
40
|
+
if (async) {
|
|
41
|
+
if (!Symbol.asyncDispose) throw new TypeError("Symbol.asyncDispose is not defined.");
|
|
42
|
+
dispose = value[Symbol.asyncDispose];
|
|
43
|
+
}
|
|
44
|
+
if (dispose === void 0) {
|
|
45
|
+
if (!Symbol.dispose) throw new TypeError("Symbol.dispose is not defined.");
|
|
46
|
+
dispose = value[Symbol.dispose];
|
|
47
|
+
if (async) inner = dispose;
|
|
48
|
+
}
|
|
49
|
+
if (typeof dispose !== "function") throw new TypeError("Object not disposable.");
|
|
50
|
+
if (inner) dispose = function() { try { inner.call(this); } catch (e) { return Promise.reject(e); } };
|
|
51
|
+
env.stack.push({ value: value, dispose: dispose, async: async });
|
|
52
|
+
}
|
|
53
|
+
else if (async) {
|
|
54
|
+
env.stack.push({ async: true });
|
|
55
|
+
}
|
|
56
|
+
return value;
|
|
57
|
+
};
|
|
58
|
+
var __disposeResources = (this && this.__disposeResources) || (function (SuppressedError) {
|
|
59
|
+
return function (env) {
|
|
60
|
+
function fail(e) {
|
|
61
|
+
env.error = env.hasError ? new SuppressedError(e, env.error, "An error was suppressed during disposal.") : e;
|
|
62
|
+
env.hasError = true;
|
|
63
|
+
}
|
|
64
|
+
var r, s = 0;
|
|
65
|
+
function next() {
|
|
66
|
+
while (r = env.stack.pop()) {
|
|
67
|
+
try {
|
|
68
|
+
if (!r.async && s === 1) return s = 0, env.stack.push(r), Promise.resolve().then(next);
|
|
69
|
+
if (r.dispose) {
|
|
70
|
+
var result = r.dispose.call(r.value);
|
|
71
|
+
if (r.async) return s |= 2, Promise.resolve(result).then(next, function(e) { fail(e); return next(); });
|
|
72
|
+
}
|
|
73
|
+
else s |= 1;
|
|
74
|
+
}
|
|
75
|
+
catch (e) {
|
|
76
|
+
fail(e);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
if (s === 1) return env.hasError ? Promise.reject(env.error) : Promise.resolve();
|
|
80
|
+
if (env.hasError) throw env.error;
|
|
81
|
+
}
|
|
82
|
+
return next();
|
|
83
|
+
};
|
|
84
|
+
})(typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
85
|
+
var e = new Error(message);
|
|
86
|
+
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
87
|
+
});
|
|
88
|
+
import z from '@deepseek-ai/schemastery';
|
|
89
|
+
import { errorChain } from '@deepseek-ai/dsh-llm';
|
|
90
|
+
import { canOpenNativePath, openNativePath } from '@deepseek-ai/dsh-native-command';
|
|
91
|
+
import { Remote, RemoteError, TypertRemoteService } from '@deepseek-ai/dsh-typert-protocol';
|
|
92
|
+
import { ApiSessionAgentController, inspectApiSession, } from "./agent.js";
|
|
93
|
+
import { SessionCommandController } from "./commands.js";
|
|
94
|
+
import { SessionControlController } from "./control.js";
|
|
95
|
+
import { SessionHistoryController } from "./history.js";
|
|
96
|
+
import { SessionFileReferences } from "./file-references.js";
|
|
97
|
+
import { ApiSessionList, DEFAULT_COLD_BLANK_PROBE_MAX_BYTES } from "./list.js";
|
|
98
|
+
import { buildModelCatalog } from "./catalog.js";
|
|
99
|
+
import { installModelSelectionProjection } from "./model-selection-projection.js";
|
|
100
|
+
import { SessionSkillCatalog } from "./skill-catalog.js";
|
|
101
|
+
export { ApiSessionNotFound } from "./agent.js";
|
|
102
|
+
export { SessionFileReferences } from "./file-references.js";
|
|
103
|
+
export { SessionSkillCatalog } from "./skill-catalog.js";
|
|
104
|
+
/** Host service backing the generated `ctx.remote.session` namespace. */
|
|
105
|
+
let SessionController = (() => {
|
|
106
|
+
let _classSuper = TypertRemoteService;
|
|
107
|
+
let _instanceExtraInitializers = [];
|
|
108
|
+
let _list_decorators;
|
|
109
|
+
let _search_decorators;
|
|
110
|
+
let _create_decorators;
|
|
111
|
+
let _selectModel_decorators;
|
|
112
|
+
let _modelCatalog_decorators;
|
|
113
|
+
let _canOpenWorkspacePath_decorators;
|
|
114
|
+
let _openWorkspacePath_decorators;
|
|
115
|
+
let _rename_decorators;
|
|
116
|
+
let _fork_decorators;
|
|
117
|
+
let _prompt_decorators;
|
|
118
|
+
let _attachment_decorators;
|
|
119
|
+
let _updateQueue_decorators;
|
|
120
|
+
let _cancel_decorators;
|
|
121
|
+
let _page_decorators;
|
|
122
|
+
let _follow_decorators;
|
|
123
|
+
let _control_decorators;
|
|
124
|
+
return class SessionController extends _classSuper {
|
|
125
|
+
static {
|
|
126
|
+
const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
|
|
127
|
+
_list_decorators = [Remote('list')];
|
|
128
|
+
_search_decorators = [Remote('search')];
|
|
129
|
+
_create_decorators = [Remote('create')];
|
|
130
|
+
_selectModel_decorators = [Remote('selectModel')];
|
|
131
|
+
_modelCatalog_decorators = [Remote('modelCatalog')];
|
|
132
|
+
_canOpenWorkspacePath_decorators = [Remote];
|
|
133
|
+
_openWorkspacePath_decorators = [Remote('openWorkspacePath')];
|
|
134
|
+
_rename_decorators = [Remote('rename')];
|
|
135
|
+
_fork_decorators = [Remote('fork')];
|
|
136
|
+
_prompt_decorators = [Remote('prompt')];
|
|
137
|
+
_attachment_decorators = [Remote('attachment')];
|
|
138
|
+
_updateQueue_decorators = [Remote('updateQueue')];
|
|
139
|
+
_cancel_decorators = [Remote('cancel')];
|
|
140
|
+
_page_decorators = [Remote('page')];
|
|
141
|
+
_follow_decorators = [Remote({ mode: 'stream' })];
|
|
142
|
+
_control_decorators = [Remote({ mode: 'stream' })];
|
|
143
|
+
__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);
|
|
144
|
+
__esDecorate(this, null, _search_decorators, { kind: "method", name: "search", static: false, private: false, access: { has: obj => "search" in obj, get: obj => obj.search }, metadata: _metadata }, null, _instanceExtraInitializers);
|
|
145
|
+
__esDecorate(this, null, _create_decorators, { kind: "method", name: "create", static: false, private: false, access: { has: obj => "create" in obj, get: obj => obj.create }, metadata: _metadata }, null, _instanceExtraInitializers);
|
|
146
|
+
__esDecorate(this, null, _selectModel_decorators, { kind: "method", name: "selectModel", static: false, private: false, access: { has: obj => "selectModel" in obj, get: obj => obj.selectModel }, metadata: _metadata }, null, _instanceExtraInitializers);
|
|
147
|
+
__esDecorate(this, null, _modelCatalog_decorators, { kind: "method", name: "modelCatalog", static: false, private: false, access: { has: obj => "modelCatalog" in obj, get: obj => obj.modelCatalog }, metadata: _metadata }, null, _instanceExtraInitializers);
|
|
148
|
+
__esDecorate(this, null, _canOpenWorkspacePath_decorators, { kind: "method", name: "canOpenWorkspacePath", static: false, private: false, access: { has: obj => "canOpenWorkspacePath" in obj, get: obj => obj.canOpenWorkspacePath }, metadata: _metadata }, null, _instanceExtraInitializers);
|
|
149
|
+
__esDecorate(this, null, _openWorkspacePath_decorators, { kind: "method", name: "openWorkspacePath", static: false, private: false, access: { has: obj => "openWorkspacePath" in obj, get: obj => obj.openWorkspacePath }, metadata: _metadata }, null, _instanceExtraInitializers);
|
|
150
|
+
__esDecorate(this, null, _rename_decorators, { kind: "method", name: "rename", static: false, private: false, access: { has: obj => "rename" in obj, get: obj => obj.rename }, metadata: _metadata }, null, _instanceExtraInitializers);
|
|
151
|
+
__esDecorate(this, null, _fork_decorators, { kind: "method", name: "fork", static: false, private: false, access: { has: obj => "fork" in obj, get: obj => obj.fork }, metadata: _metadata }, null, _instanceExtraInitializers);
|
|
152
|
+
__esDecorate(this, null, _prompt_decorators, { kind: "method", name: "prompt", static: false, private: false, access: { has: obj => "prompt" in obj, get: obj => obj.prompt }, metadata: _metadata }, null, _instanceExtraInitializers);
|
|
153
|
+
__esDecorate(this, null, _attachment_decorators, { kind: "method", name: "attachment", static: false, private: false, access: { has: obj => "attachment" in obj, get: obj => obj.attachment }, metadata: _metadata }, null, _instanceExtraInitializers);
|
|
154
|
+
__esDecorate(this, null, _updateQueue_decorators, { kind: "method", name: "updateQueue", static: false, private: false, access: { has: obj => "updateQueue" in obj, get: obj => obj.updateQueue }, metadata: _metadata }, null, _instanceExtraInitializers);
|
|
155
|
+
__esDecorate(this, null, _cancel_decorators, { kind: "method", name: "cancel", static: false, private: false, access: { has: obj => "cancel" in obj, get: obj => obj.cancel }, metadata: _metadata }, null, _instanceExtraInitializers);
|
|
156
|
+
__esDecorate(this, null, _page_decorators, { kind: "method", name: "page", static: false, private: false, access: { has: obj => "page" in obj, get: obj => obj.page }, metadata: _metadata }, null, _instanceExtraInitializers);
|
|
157
|
+
__esDecorate(this, null, _follow_decorators, { kind: "method", name: "follow", static: false, private: false, access: { has: obj => "follow" in obj, get: obj => obj.follow }, metadata: _metadata }, null, _instanceExtraInitializers);
|
|
158
|
+
__esDecorate(this, null, _control_decorators, { kind: "method", name: "control", static: false, private: false, access: { has: obj => "control" in obj, get: obj => obj.control }, metadata: _metadata }, null, _instanceExtraInitializers);
|
|
159
|
+
if (_metadata) Object.defineProperty(this, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
|
|
160
|
+
}
|
|
161
|
+
static inject = [
|
|
162
|
+
'agentDefaultModel',
|
|
163
|
+
'agents',
|
|
164
|
+
'attachments',
|
|
165
|
+
'llm',
|
|
166
|
+
'sessions',
|
|
167
|
+
'sessionProjections',
|
|
168
|
+
'sessionQuery',
|
|
169
|
+
'typert',
|
|
170
|
+
'workspaceRegistry',
|
|
171
|
+
];
|
|
172
|
+
static Config = z.object({
|
|
173
|
+
coldBlankProbeMaxBytes: z.natural().default(DEFAULT_COLD_BLANK_PROBE_MAX_BYTES),
|
|
174
|
+
nativeOpen: z.boolean(),
|
|
175
|
+
});
|
|
176
|
+
agents = __runInitializers(this, _instanceExtraInitializers);
|
|
177
|
+
commands;
|
|
178
|
+
controlState;
|
|
179
|
+
history;
|
|
180
|
+
listState;
|
|
181
|
+
openPath;
|
|
182
|
+
canOpenPath;
|
|
183
|
+
promotions = new Set();
|
|
184
|
+
/**
|
|
185
|
+
* @param ctx - Host context containing the Session capability assembly.
|
|
186
|
+
* @param config - cold-list observation policy.
|
|
187
|
+
*/
|
|
188
|
+
constructor(ctx, config, internals = {}) {
|
|
189
|
+
super(ctx, 'sessionController', { namespace: 'session' });
|
|
190
|
+
installModelSelectionProjection(ctx);
|
|
191
|
+
this.agents = new ApiSessionAgentController(ctx);
|
|
192
|
+
this.commands = new SessionCommandController(ctx, this.agents, process.cwd());
|
|
193
|
+
this.controlState = new SessionControlController(ctx);
|
|
194
|
+
// Registered before history so reverse-order teardown closes every
|
|
195
|
+
// follower before waiting for already-admitted promotions.
|
|
196
|
+
ctx.effect(() => async () => {
|
|
197
|
+
await Promise.allSettled([...this.promotions]);
|
|
198
|
+
}, 'session-controller.promotions');
|
|
199
|
+
this.history = new SessionHistoryController(ctx, (observation) => { this.promote(observation); });
|
|
200
|
+
this.listState = new ApiSessionList(ctx, config.coldBlankProbeMaxBytes ?? DEFAULT_COLD_BLANK_PROBE_MAX_BYTES);
|
|
201
|
+
this.openPath = internals.openPath ?? openNativePath;
|
|
202
|
+
this.canOpenPath = internals.canOpenPath
|
|
203
|
+
?? (() => config.nativeOpen ?? (internals.openPath !== undefined || canOpenNativePath()));
|
|
204
|
+
ctx.plugin(SessionFileReferences);
|
|
205
|
+
ctx.plugin(SessionSkillCatalog);
|
|
206
|
+
ctx.on('session/created', (session) => {
|
|
207
|
+
ctx.emit('api-session/added', this.listState.summaryFor(session));
|
|
208
|
+
});
|
|
209
|
+
ctx.on('session/disposed', (session) => {
|
|
210
|
+
ctx.emit('api-session/removed', session.id);
|
|
211
|
+
});
|
|
212
|
+
ctx.on('agent/status', ({ agent, status }) => {
|
|
213
|
+
ctx.emit('api-session/status', agent.id, status === 'running');
|
|
214
|
+
});
|
|
215
|
+
ctx.on('agent/error', ({ agent, error }) => {
|
|
216
|
+
ctx.emit('api-session/error', agent.id, errorChain(error));
|
|
217
|
+
});
|
|
218
|
+
ctx.on('session/event', (session, event) => {
|
|
219
|
+
if (event.type === 'request/header') {
|
|
220
|
+
const agent = ctx.agents.get(session.id);
|
|
221
|
+
if (agent?.session === session)
|
|
222
|
+
this.agents.consumeSelection(agent, event.data.header.config.provider, event.data.header.config.model, event.data.header.config.reasoningEffort);
|
|
223
|
+
}
|
|
224
|
+
if (event.type !== 'user/message' || event.data.source.kind !== 'user')
|
|
225
|
+
return;
|
|
226
|
+
ctx.emit('api-session/activity', session.id, event.time);
|
|
227
|
+
});
|
|
228
|
+
}
|
|
229
|
+
promote(observation) {
|
|
230
|
+
const sessionId = observation.header.id;
|
|
231
|
+
const task = (async () => {
|
|
232
|
+
const env_1 = { stack: [], error: void 0, hasError: false };
|
|
233
|
+
try {
|
|
234
|
+
const ownedObservation = __addDisposableResource(env_1, observation, false);
|
|
235
|
+
const result = await this.agents.resolveObservedAgent(ownedObservation);
|
|
236
|
+
if ('error' in result)
|
|
237
|
+
this.ctx.emit('api-session/error', sessionId, result.error.message);
|
|
238
|
+
}
|
|
239
|
+
catch (e_1) {
|
|
240
|
+
env_1.error = e_1;
|
|
241
|
+
env_1.hasError = true;
|
|
242
|
+
}
|
|
243
|
+
finally {
|
|
244
|
+
__disposeResources(env_1);
|
|
245
|
+
}
|
|
246
|
+
})().catch((error) => {
|
|
247
|
+
this.ctx.logger.error(`session-controller: background activation for "${sessionId}" failed: ${errorChain(error)}`);
|
|
248
|
+
});
|
|
249
|
+
this.promotions.add(task);
|
|
250
|
+
void task.finally(() => { this.promotions.delete(task); });
|
|
251
|
+
}
|
|
252
|
+
/**
|
|
253
|
+
* Resolve or resume one ordinary Session for another Host API domain.
|
|
254
|
+
* @param sessionId - Session identity whose Agent owns the operation.
|
|
255
|
+
* @returns the live Agent or the stable Session-domain failure.
|
|
256
|
+
*/
|
|
257
|
+
resolveAgent(sessionId) {
|
|
258
|
+
return this.agents.resolveAgent(sessionId);
|
|
259
|
+
}
|
|
260
|
+
/**
|
|
261
|
+
* Inspect one attached or persisted Session without activating its Agent.
|
|
262
|
+
* @param sessionId - durable Session identity.
|
|
263
|
+
* @param signal - optional caller cancellation for persistence reads.
|
|
264
|
+
* @returns the current attached state or persisted header and event prefix.
|
|
265
|
+
*/
|
|
266
|
+
inspect(sessionId, signal) {
|
|
267
|
+
const attached = this.ctx.sessions.get(sessionId);
|
|
268
|
+
if (attached !== undefined) {
|
|
269
|
+
return Promise.resolve({ meta: attached.header, events: [...attached.events] });
|
|
270
|
+
}
|
|
271
|
+
return inspectApiSession(this.ctx, sessionId, signal);
|
|
272
|
+
}
|
|
273
|
+
/**
|
|
274
|
+
* Read all visible Session rows without resuming an Agent.
|
|
275
|
+
* @param _request - reserved empty list request.
|
|
276
|
+
* @param signal - cancellation for persistence reads.
|
|
277
|
+
* @returns visible Session summaries ordered by activity.
|
|
278
|
+
*/
|
|
279
|
+
async list(_request, signal) {
|
|
280
|
+
return { items: await this.listState.list(signal) };
|
|
281
|
+
}
|
|
282
|
+
/**
|
|
283
|
+
* Search visible Session content without resuming an Agent.
|
|
284
|
+
* @param request - literal message-content query.
|
|
285
|
+
* @param signal - cancellation for list and search reads.
|
|
286
|
+
* @returns authorized bounded Session search results.
|
|
287
|
+
*/
|
|
288
|
+
search(request, signal) {
|
|
289
|
+
return this.listState.search(request.query, signal);
|
|
290
|
+
}
|
|
291
|
+
/**
|
|
292
|
+
* Create or idempotently adopt one ordinary Session.
|
|
293
|
+
* @param request - requested identity, location, and Agent preset.
|
|
294
|
+
* @returns the Session identity and resolved preset when configured.
|
|
295
|
+
*/
|
|
296
|
+
create(request) {
|
|
297
|
+
return this.commands.create(request);
|
|
298
|
+
}
|
|
299
|
+
/**
|
|
300
|
+
* Select one Session-local model after explicitly resuming the Session.
|
|
301
|
+
* @param request - Session identity and requested model selection.
|
|
302
|
+
* @returns the normalized selection installed for the Session.
|
|
303
|
+
*/
|
|
304
|
+
selectModel(request) {
|
|
305
|
+
return this.commands.selectModel(request);
|
|
306
|
+
}
|
|
307
|
+
/**
|
|
308
|
+
* Describe every currently routable model for Host-generation selectors.
|
|
309
|
+
* @returns provider-grouped models, the deployment default, and isolated provider failures.
|
|
310
|
+
*/
|
|
311
|
+
modelCatalog() {
|
|
312
|
+
return buildModelCatalog(this.ctx);
|
|
313
|
+
}
|
|
314
|
+
/**
|
|
315
|
+
* Report whether this deployment can hand a Session workspace path to a native desktop.
|
|
316
|
+
* @returns true when the matching open operation is available.
|
|
317
|
+
*/
|
|
318
|
+
canOpenWorkspacePath() {
|
|
319
|
+
return this.canOpenPath();
|
|
320
|
+
}
|
|
321
|
+
/**
|
|
322
|
+
* Open one path prepared by a Session-aware caller on the Host desktop.
|
|
323
|
+
* @param request - path after best-effort Session workspace resolution.
|
|
324
|
+
* @param signal - caller lifetime; abort terminates the native command.
|
|
325
|
+
* @returns confirmation after the native opener accepts the path.
|
|
326
|
+
* @throws RemoteError when the request is invalid, cancelled, or the opener fails.
|
|
327
|
+
*/
|
|
328
|
+
async openWorkspacePath(request, signal) {
|
|
329
|
+
if (request.path.length === 0) {
|
|
330
|
+
throw new RemoteError('gateway/bad-request', 'session.openWorkspacePath requires a non-empty path', {});
|
|
331
|
+
}
|
|
332
|
+
signal.throwIfAborted();
|
|
333
|
+
try {
|
|
334
|
+
await this.openPath(request.path, signal);
|
|
335
|
+
return { opened: true };
|
|
336
|
+
}
|
|
337
|
+
catch (error) {
|
|
338
|
+
if (signal.aborted)
|
|
339
|
+
throw new RemoteError('gateway/cancelled', 'path open was aborted', {});
|
|
340
|
+
throw new RemoteError('gateway/internal', `path open failed: ${error instanceof Error ? error.message : String(error)}`, {});
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
/**
|
|
344
|
+
* Rename one Session after explicitly resuming it.
|
|
345
|
+
* @param request - Session identity and proposed title.
|
|
346
|
+
* @returns the accepted title and durable event sequence.
|
|
347
|
+
*/
|
|
348
|
+
rename(request) {
|
|
349
|
+
return this.commands.rename(request);
|
|
350
|
+
}
|
|
351
|
+
/**
|
|
352
|
+
* Fork one cold-readable completed-turn prefix into a new Session.
|
|
353
|
+
* @param request - source Session and optional event anchor.
|
|
354
|
+
* @returns the new Session identity.
|
|
355
|
+
*/
|
|
356
|
+
fork(request) {
|
|
357
|
+
return this.commands.fork(request);
|
|
358
|
+
}
|
|
359
|
+
/**
|
|
360
|
+
* Admit one prompt after explicitly resuming its Session.
|
|
361
|
+
* @param request - Session identity, prompt content, source metadata, and delivery mode.
|
|
362
|
+
* @param signal - caller cancellation before prompt admission begins.
|
|
363
|
+
* @returns acknowledgement that the Agent accepted the prompt.
|
|
364
|
+
*/
|
|
365
|
+
prompt(request, signal) {
|
|
366
|
+
signal.throwIfAborted();
|
|
367
|
+
return this.commands.prompt(request);
|
|
368
|
+
}
|
|
369
|
+
/**
|
|
370
|
+
* Read one image proven reachable from the addressed Session log.
|
|
371
|
+
* @param request - Session and attachment identities used for authorization.
|
|
372
|
+
* @returns the durable attachment reference and base64-encoded bytes.
|
|
373
|
+
*/
|
|
374
|
+
attachment(request) {
|
|
375
|
+
return this.commands.attachment(request);
|
|
376
|
+
}
|
|
377
|
+
/**
|
|
378
|
+
* Mutate one still-pending queue occurrence on a live Agent.
|
|
379
|
+
* @param request - Session, queue item, and requested mutation.
|
|
380
|
+
* @returns acknowledgement that the queue mutation was applied.
|
|
381
|
+
*/
|
|
382
|
+
updateQueue(request) {
|
|
383
|
+
return this.commands.updateQueue(request);
|
|
384
|
+
}
|
|
385
|
+
/**
|
|
386
|
+
* Cancel one active Agent turn without dropping its pending inbox.
|
|
387
|
+
* @param request - Session whose active Agent turn is cancelled.
|
|
388
|
+
* @returns acknowledgement that cancellation was requested.
|
|
389
|
+
*/
|
|
390
|
+
cancel(request) {
|
|
391
|
+
return this.commands.cancel(request);
|
|
392
|
+
}
|
|
393
|
+
/**
|
|
394
|
+
* Read one cold-safe, message-aligned Session history page.
|
|
395
|
+
* @param request - durable address, backward cursor, and page budget.
|
|
396
|
+
* @param signal - cancellation for persistence reads.
|
|
397
|
+
* @returns one chronological page.
|
|
398
|
+
*/
|
|
399
|
+
page(request, signal) {
|
|
400
|
+
return this.history.page(request, signal);
|
|
401
|
+
}
|
|
402
|
+
/**
|
|
403
|
+
* Follow one Session log from its opening or resume cursor.
|
|
404
|
+
* @param request - durable address and last committed sequence already held by the caller.
|
|
405
|
+
* @param signal - cancellation owned by the Remote stream carrier.
|
|
406
|
+
* @returns a complete opening snapshot followed by gap-free event frames.
|
|
407
|
+
*/
|
|
408
|
+
follow(request, signal) {
|
|
409
|
+
return this.history.follow(request, signal);
|
|
410
|
+
}
|
|
411
|
+
/**
|
|
412
|
+
* Stream a complete live-control baseline followed by replacement frames.
|
|
413
|
+
* @param signal - cancellation owned by the Remote stream carrier.
|
|
414
|
+
* @returns one complete baseline followed by live replacement frames.
|
|
415
|
+
*/
|
|
416
|
+
control(signal) {
|
|
417
|
+
return this.controlState.control(signal);
|
|
418
|
+
}
|
|
419
|
+
};
|
|
420
|
+
})();
|
|
421
|
+
export { SessionController };
|
|
422
|
+
export { buildModelCatalog };
|
|
423
|
+
export default SessionController;
|
|
424
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/** Package-owned invariant companion. @module @deepseek-ai/dsh-api-session-controller/invariant */
|
|
2
|
+
import type { Context } from '@deepseek-ai/cordis';
|
|
3
|
+
/** Cordis companion plugin name. */
|
|
4
|
+
export declare const name = "api-session-controller-invariant";
|
|
5
|
+
/** Service required before the companion can reserve package ownership. */
|
|
6
|
+
export declare const inject: string[];
|
|
7
|
+
/** Register this package's invariant companion. */
|
|
8
|
+
export declare const apply: (ctx: Context) => Promise<() => void>;
|
|
9
|
+
//# sourceMappingURL=invariant.d.ts.map
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/** Package-owned invariant companion. @module @deepseek-ai/dsh-api-session-controller/invariant */
|
|
2
|
+
const PACKAGE_NAME = '@deepseek-ai/dsh-api-session-controller';
|
|
3
|
+
/** Cordis companion plugin name. */
|
|
4
|
+
export const name = 'api-session-controller-invariant';
|
|
5
|
+
/** Service required before the companion can reserve package ownership. */
|
|
6
|
+
export const inject = ['invariants'];
|
|
7
|
+
/** No runtime invariant: every page and frame is checked against the addressed durable Session. */
|
|
8
|
+
const install = () => { };
|
|
9
|
+
/** Register this package's invariant companion. */
|
|
10
|
+
export const apply = (ctx) => Promise.resolve(ctx.invariants.register(PACKAGE_NAME, install));
|
|
11
|
+
/* jscpd:ignore-end */
|
|
12
|
+
//# sourceMappingURL=invariant.js.map
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/** Cold-safe Session list and search projection. */
|
|
2
|
+
import type { Context } from '@deepseek-ai/cordis';
|
|
3
|
+
import type { Session, SessionEvent } from '@deepseek-ai/dsh-session';
|
|
4
|
+
import type { SessionListMetadata, SessionSearchValue, SessionSummary } from './types.ts';
|
|
5
|
+
/** Default maximum artifact size eligible for one cold projection observation. */
|
|
6
|
+
export declare const DEFAULT_COLD_BLANK_PROBE_MAX_BYTES = 1024;
|
|
7
|
+
/**
|
|
8
|
+
* Advance the Session-list metadata projection by one committed event.
|
|
9
|
+
* @param state - metadata before the event.
|
|
10
|
+
* @param event - next committed Session event.
|
|
11
|
+
* @returns the original or advanced metadata value.
|
|
12
|
+
*/
|
|
13
|
+
export declare function applySessionListMetadata(state: SessionListMetadata, event: SessionEvent): SessionListMetadata;
|
|
14
|
+
/**
|
|
15
|
+
* Return the longest prefix containing at most `maximum` Unicode code points.
|
|
16
|
+
* @param value - source text.
|
|
17
|
+
* @param maximum - maximum number of Unicode code points.
|
|
18
|
+
* @returns the source text or its longest allowed prefix.
|
|
19
|
+
*/
|
|
20
|
+
export declare function truncateUnicodeCodePoints(value: string, maximum: number): string;
|
|
21
|
+
/** Owns list projection registration, bounded cold summaries, and authorized search. */
|
|
22
|
+
export declare class ApiSessionList {
|
|
23
|
+
private readonly ctx;
|
|
24
|
+
private readonly coldBlankProbeMaxBytes;
|
|
25
|
+
/**
|
|
26
|
+
* @param ctx - Host context carrying Session, query, persistence, and projection services.
|
|
27
|
+
* @param coldBlankProbeMaxBytes - maximum physical artifact size eligible for a full observation.
|
|
28
|
+
*/
|
|
29
|
+
constructor(ctx: Context, coldBlankProbeMaxBytes: number);
|
|
30
|
+
/**
|
|
31
|
+
* Build one current attached-Session summary.
|
|
32
|
+
* @param session - attached Session to summarize.
|
|
33
|
+
* @returns current list metadata and available projections.
|
|
34
|
+
*/
|
|
35
|
+
summaryFor(session: Session): SessionSummary;
|
|
36
|
+
/**
|
|
37
|
+
* Read every visible attached and persisted Session without activating an Agent.
|
|
38
|
+
* @param signal - optional cancellation for persistence reads.
|
|
39
|
+
* @returns visible Session summaries ordered by activity.
|
|
40
|
+
*/
|
|
41
|
+
list(signal?: AbortSignal): Promise<SessionSummary[]>;
|
|
42
|
+
private summarizeCold;
|
|
43
|
+
private probeSmallCold;
|
|
44
|
+
/**
|
|
45
|
+
* Search current visible message content without activating any matching Session.
|
|
46
|
+
* @param query - literal message-content query.
|
|
47
|
+
* @param signal - cancellation for list and search reads.
|
|
48
|
+
* @returns authorized bounded Session search results.
|
|
49
|
+
*/
|
|
50
|
+
search(query: string, signal: AbortSignal): Promise<SessionSearchValue>;
|
|
51
|
+
private projectionsFor;
|
|
52
|
+
}
|
|
53
|
+
//# sourceMappingURL=list.d.ts.map
|