@deepseek-ai/dsh-api-session-controller 0.1.6-alpha.1 → 0.1.6-alpha.2
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/README.i18n.yaml +2 -2
- package/README.md +15 -3
- package/README.zh.md +15 -3
- package/lib/client.js +428 -471
- package/lib/index.js +16 -47
- package/lib/typert.host.js +178 -160
- package/lib/typert.remote-client.js +167 -149
- package/lib/types/agent.d.ts +1 -1
- package/lib/types/agent.js +8 -1
- package/lib/types/client/contract/sessions.d.ts +55 -20
- package/lib/types/client/contract/snapshot.d.ts +0 -14
- package/lib/types/client/index.d.ts +11 -2
- package/lib/types/client/index.js +16 -5
- package/lib/types/client/scope.d.ts +13 -3
- package/lib/types/client/scope.js +15 -22
- package/lib/types/client/sessions/lineage.d.ts +1 -4
- package/lib/types/client/sessions/lineage.js +1 -3
- package/lib/types/client/sessions/manager.d.ts +28 -49
- package/lib/types/client/sessions/manager.js +75 -174
- package/lib/types/client/sessions/projection-store.d.ts +5 -11
- package/lib/types/client/sessions/projection-store.js +6 -14
- package/lib/types/client/sessions/service.d.ts +34 -119
- package/lib/types/client/sessions/service.js +259 -244
- package/lib/types/client/sessions/session.d.ts +7 -20
- package/lib/types/client/sessions/session.js +29 -33
- package/lib/types/commands.d.ts +2 -2
- package/lib/types/commands.js +10 -4
- package/lib/types/control.d.ts +1 -1
- package/lib/types/control.js +1 -41
- package/lib/types/index.d.ts +2 -2
- package/lib/types/index.js +1 -1
- package/lib/types/types.d.ts +3 -17
- package/package.json +71 -71
- package/lib/types/client/sessions/queue-mirror.d.ts +0 -26
- package/lib/types/client/sessions/queue-mirror.js +0 -61
package/lib/index.js
CHANGED
|
@@ -227,7 +227,8 @@ var ApiSessionAgentController = class {
|
|
|
227
227
|
this.resumes.set(sessionId, resume);
|
|
228
228
|
}
|
|
229
229
|
try {
|
|
230
|
-
|
|
230
|
+
const agent = await resume;
|
|
231
|
+
return this.liveAgent(sessionId) ?? { agent };
|
|
231
232
|
} catch (error) {
|
|
232
233
|
if (error instanceof ApiSessionNotFound) return { error: new RemoteError("session/not-found", error.message, { sessionId }) };
|
|
233
234
|
if (error instanceof ApiSessionSubagentOwnership) return { error: apiSessionSubagentOwnershipError(error.sessionId) };
|
|
@@ -235,6 +236,7 @@ var ApiSessionAgentController = class {
|
|
|
235
236
|
if (raced !== void 0) return raced;
|
|
236
237
|
const racedSession = this.ctx.sessions.get(sessionId);
|
|
237
238
|
if (racedSession !== void 0 && hasApiSessionSubagentOwner(this.ctx, racedSession, void 0)) return { error: apiSessionSubagentOwnershipError(sessionId) };
|
|
239
|
+
if (error instanceof Error && error.name === "SessionAlreadyOwnedError") return { error: new RemoteError("session/writer-held", error.message, { sessionId }) };
|
|
238
240
|
return { error: new RemoteError("gateway/internal", `resume failed for session "${sessionId}": ${String(error)}`, {}) };
|
|
239
241
|
}
|
|
240
242
|
}
|
|
@@ -814,17 +816,24 @@ var SessionCommandController = class {
|
|
|
814
816
|
}
|
|
815
817
|
}
|
|
816
818
|
/**
|
|
817
|
-
* Mutate one
|
|
819
|
+
* Mutate one pending Inbox occurrence, restoring an ordinary cold Agent when needed.
|
|
818
820
|
* @param request - Session, queue item, and requested mutation.
|
|
819
821
|
* @returns acknowledgement that the queue mutation was applied.
|
|
820
822
|
*/
|
|
821
|
-
updateQueue(request) {
|
|
823
|
+
async updateQueue(request) {
|
|
822
824
|
if (request.action.kind === "edit") {
|
|
823
825
|
if (request.action.content.some((block) => block.type !== "text")) throw new RemoteError("session/attachment-invalid", "queue edits accept text content only", { reason: "QUEUE_EDIT_NON_TEXT" });
|
|
824
826
|
if (!hasPromptContent(request.action.content)) throw new RemoteError("gateway/bad-request", "queue edit content must include non-whitespace text", {});
|
|
825
827
|
}
|
|
826
|
-
|
|
827
|
-
if (agent === void 0)
|
|
828
|
+
let agent = this.ctx.agents.get(request.sessionId);
|
|
829
|
+
if (agent === void 0) {
|
|
830
|
+
const found = await this.agents.resolveAgent(request.sessionId);
|
|
831
|
+
if ("error" in found) {
|
|
832
|
+
if (found.error.code !== "session/not-found") throw found.error;
|
|
833
|
+
throw new RemoteError("session/queue-item-not-found", "queued item is no longer pending", { itemId: request.itemId });
|
|
834
|
+
}
|
|
835
|
+
agent = found.agent;
|
|
836
|
+
}
|
|
828
837
|
if (hasApiSessionSubagentOwner(this.ctx, agent.session, agent)) {
|
|
829
838
|
const identity = this.ctx.sessionProjections.snapshot(agent.session, ["subagent"]).values.subagent;
|
|
830
839
|
if (identity?.mode !== "continuable" || !agent.session.isOwnSeq(identity.seq)) throw apiSessionSubagentOwnershipError(request.sessionId);
|
|
@@ -989,7 +998,7 @@ function routeServed(ctx, provider) {
|
|
|
989
998
|
}
|
|
990
999
|
//#endregion
|
|
991
1000
|
//#region lib/types/control.js
|
|
992
|
-
/** Live Session
|
|
1001
|
+
/** Live Session jobs and projection state with reconnect baselines. */
|
|
993
1002
|
/** Owns the Host-wide Session control stream. */
|
|
994
1003
|
var SessionControlController = class {
|
|
995
1004
|
ctx;
|
|
@@ -1005,13 +1014,6 @@ var SessionControlController = class {
|
|
|
1005
1014
|
value,
|
|
1006
1015
|
seq
|
|
1007
1016
|
});
|
|
1008
|
-
if (key !== "inbox") return;
|
|
1009
|
-
if (this.ctx.agents.get(session.id)?.session !== session) return;
|
|
1010
|
-
this.broadcast({
|
|
1011
|
-
type: "queue",
|
|
1012
|
-
sessionId: session.id,
|
|
1013
|
-
items: queueItemsFromInbox(value)
|
|
1014
|
-
});
|
|
1015
1017
|
});
|
|
1016
1018
|
ctx.inject(["jobs"], (jobsCtx) => {
|
|
1017
1019
|
jobsCtx.jobs.onJobsChanged((owner) => {
|
|
@@ -1053,15 +1055,12 @@ var SessionControlController = class {
|
|
|
1053
1055
|
}
|
|
1054
1056
|
baseline() {
|
|
1055
1057
|
const sessions = this.ctx.sessions.list();
|
|
1056
|
-
const queues = Object.create(null);
|
|
1057
1058
|
const jobs = Object.create(null);
|
|
1058
1059
|
for (const session of sessions) {
|
|
1059
1060
|
const agent = this.ctx.agents.get(session.id);
|
|
1060
|
-
queues[session.id] = agent?.session === session ? queueItems(agent) : [];
|
|
1061
1061
|
jobs[session.id] = this.jobsFor(agent);
|
|
1062
1062
|
}
|
|
1063
1063
|
return {
|
|
1064
|
-
queues,
|
|
1065
1064
|
jobs,
|
|
1066
1065
|
projections: this.projectionBaseline(sessions)
|
|
1067
1066
|
};
|
|
@@ -1141,36 +1140,6 @@ var ControlQueue = class {
|
|
|
1141
1140
|
}
|
|
1142
1141
|
}
|
|
1143
1142
|
};
|
|
1144
|
-
function queueItems(agent) {
|
|
1145
|
-
return queueItemsFromInbox({
|
|
1146
|
-
"next-turn": agent.inbox.nextTurn,
|
|
1147
|
-
"next-step": agent.inbox.nextStep
|
|
1148
|
-
});
|
|
1149
|
-
}
|
|
1150
|
-
function queueItemsFromInbox(inbox) {
|
|
1151
|
-
return [...inbox["next-turn"].map((message) => ({
|
|
1152
|
-
id: message.id,
|
|
1153
|
-
placement: "queued",
|
|
1154
|
-
...promptRpcId(message),
|
|
1155
|
-
message: {
|
|
1156
|
-
id: message.id,
|
|
1157
|
-
content: message.content
|
|
1158
|
-
}
|
|
1159
|
-
})), ...inbox["next-step"].map((message) => ({
|
|
1160
|
-
id: message.id,
|
|
1161
|
-
placement: message.source.kind === "user" ? "steering" : "context",
|
|
1162
|
-
...promptRpcId(message),
|
|
1163
|
-
message: {
|
|
1164
|
-
id: message.id,
|
|
1165
|
-
content: message.content
|
|
1166
|
-
}
|
|
1167
|
-
}))];
|
|
1168
|
-
}
|
|
1169
|
-
/** Prompt-RPC identity carried by a browser-submitted message's user source. */
|
|
1170
|
-
function promptRpcId(message) {
|
|
1171
|
-
const source = message.source;
|
|
1172
|
-
return source.kind === "user" && "rpcId" in source ? { rpcId: source.rpcId } : {};
|
|
1173
|
-
}
|
|
1174
1143
|
function jobView(job) {
|
|
1175
1144
|
return {
|
|
1176
1145
|
id: job.id,
|
|
@@ -2930,7 +2899,7 @@ let SessionController = (() => {
|
|
|
2930
2899
|
return this.commands.attachment(request);
|
|
2931
2900
|
}
|
|
2932
2901
|
/**
|
|
2933
|
-
* Mutate one still-pending queue occurrence
|
|
2902
|
+
* Mutate one still-pending queue occurrence, resuming a cold Agent first.
|
|
2934
2903
|
* @param request - Session, queue item, and requested mutation.
|
|
2935
2904
|
* @returns acknowledgement that the queue mutation was applied.
|
|
2936
2905
|
*/
|