@crazx/dsh-api-session-controller 0.1.6-alpha.1.zw.2 → 0.1.6-alpha.2.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/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 +179 -161
- package/lib/typert.remote-client.js +168 -150
- 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 +70 -70
- 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
|
}
|
|
@@ -831,17 +833,24 @@ var SessionCommandController = class {
|
|
|
831
833
|
}
|
|
832
834
|
}
|
|
833
835
|
/**
|
|
834
|
-
* Mutate one
|
|
836
|
+
* Mutate one pending Inbox occurrence, restoring an ordinary cold Agent when needed.
|
|
835
837
|
* @param request - Session, queue item, and requested mutation.
|
|
836
838
|
* @returns acknowledgement that the queue mutation was applied.
|
|
837
839
|
*/
|
|
838
|
-
updateQueue(request) {
|
|
840
|
+
async updateQueue(request) {
|
|
839
841
|
if (request.action.kind === "edit") {
|
|
840
842
|
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" });
|
|
841
843
|
if (!hasPromptContent(request.action.content)) throw new RemoteError("gateway/bad-request", "queue edit content must include non-whitespace text", {});
|
|
842
844
|
}
|
|
843
|
-
|
|
844
|
-
if (agent === void 0)
|
|
845
|
+
let agent = this.ctx.agents.get(request.sessionId);
|
|
846
|
+
if (agent === void 0) {
|
|
847
|
+
const found = await this.agents.resolveAgent(request.sessionId);
|
|
848
|
+
if ("error" in found) {
|
|
849
|
+
if (found.error.code !== "session/not-found") throw found.error;
|
|
850
|
+
throw new RemoteError("session/queue-item-not-found", "queued item is no longer pending", { itemId: request.itemId });
|
|
851
|
+
}
|
|
852
|
+
agent = found.agent;
|
|
853
|
+
}
|
|
845
854
|
if (hasApiSessionSubagentOwner(this.ctx, agent.session, agent)) {
|
|
846
855
|
const identity = this.ctx.sessionProjections.snapshot(agent.session, ["subagent"]).values.subagent;
|
|
847
856
|
if (identity?.mode !== "continuable" || !agent.session.isOwnSeq(identity.seq)) throw apiSessionSubagentOwnershipError(request.sessionId);
|
|
@@ -1006,7 +1015,7 @@ function routeServed(ctx, provider) {
|
|
|
1006
1015
|
}
|
|
1007
1016
|
//#endregion
|
|
1008
1017
|
//#region lib/types/control.js
|
|
1009
|
-
/** Live Session
|
|
1018
|
+
/** Live Session jobs and projection state with reconnect baselines. */
|
|
1010
1019
|
/** Owns the Host-wide Session control stream. */
|
|
1011
1020
|
var SessionControlController = class {
|
|
1012
1021
|
ctx;
|
|
@@ -1022,13 +1031,6 @@ var SessionControlController = class {
|
|
|
1022
1031
|
value,
|
|
1023
1032
|
seq
|
|
1024
1033
|
});
|
|
1025
|
-
if (key !== "inbox") return;
|
|
1026
|
-
if (this.ctx.agents.get(session.id)?.session !== session) return;
|
|
1027
|
-
this.broadcast({
|
|
1028
|
-
type: "queue",
|
|
1029
|
-
sessionId: session.id,
|
|
1030
|
-
items: queueItemsFromInbox(value)
|
|
1031
|
-
});
|
|
1032
1034
|
});
|
|
1033
1035
|
ctx.inject(["jobs"], (jobsCtx) => {
|
|
1034
1036
|
jobsCtx.jobs.onJobsChanged((owner) => {
|
|
@@ -1070,15 +1072,12 @@ var SessionControlController = class {
|
|
|
1070
1072
|
}
|
|
1071
1073
|
baseline() {
|
|
1072
1074
|
const sessions = this.ctx.sessions.list();
|
|
1073
|
-
const queues = Object.create(null);
|
|
1074
1075
|
const jobs = Object.create(null);
|
|
1075
1076
|
for (const session of sessions) {
|
|
1076
1077
|
const agent = this.ctx.agents.get(session.id);
|
|
1077
|
-
queues[session.id] = agent?.session === session ? queueItems(agent) : [];
|
|
1078
1078
|
jobs[session.id] = this.jobsFor(agent);
|
|
1079
1079
|
}
|
|
1080
1080
|
return {
|
|
1081
|
-
queues,
|
|
1082
1081
|
jobs,
|
|
1083
1082
|
projections: this.projectionBaseline(sessions)
|
|
1084
1083
|
};
|
|
@@ -1158,36 +1157,6 @@ var ControlQueue = class {
|
|
|
1158
1157
|
}
|
|
1159
1158
|
}
|
|
1160
1159
|
};
|
|
1161
|
-
function queueItems(agent) {
|
|
1162
|
-
return queueItemsFromInbox({
|
|
1163
|
-
"next-turn": agent.inbox.nextTurn,
|
|
1164
|
-
"next-step": agent.inbox.nextStep
|
|
1165
|
-
});
|
|
1166
|
-
}
|
|
1167
|
-
function queueItemsFromInbox(inbox) {
|
|
1168
|
-
return [...inbox["next-turn"].map((message) => ({
|
|
1169
|
-
id: message.id,
|
|
1170
|
-
placement: "queued",
|
|
1171
|
-
...promptRpcId(message),
|
|
1172
|
-
message: {
|
|
1173
|
-
id: message.id,
|
|
1174
|
-
content: message.content
|
|
1175
|
-
}
|
|
1176
|
-
})), ...inbox["next-step"].map((message) => ({
|
|
1177
|
-
id: message.id,
|
|
1178
|
-
placement: message.source.kind === "user" ? "steering" : "context",
|
|
1179
|
-
...promptRpcId(message),
|
|
1180
|
-
message: {
|
|
1181
|
-
id: message.id,
|
|
1182
|
-
content: message.content
|
|
1183
|
-
}
|
|
1184
|
-
}))];
|
|
1185
|
-
}
|
|
1186
|
-
/** Prompt-RPC identity carried by a browser-submitted message's user source. */
|
|
1187
|
-
function promptRpcId(message) {
|
|
1188
|
-
const source = message.source;
|
|
1189
|
-
return source.kind === "user" && "rpcId" in source ? { rpcId: source.rpcId } : {};
|
|
1190
|
-
}
|
|
1191
1160
|
function jobView(job) {
|
|
1192
1161
|
return {
|
|
1193
1162
|
id: job.id,
|
|
@@ -2947,7 +2916,7 @@ let SessionController = (() => {
|
|
|
2947
2916
|
return this.commands.attachment(request);
|
|
2948
2917
|
}
|
|
2949
2918
|
/**
|
|
2950
|
-
* Mutate one still-pending queue occurrence
|
|
2919
|
+
* Mutate one still-pending queue occurrence, resuming a cold Agent first.
|
|
2951
2920
|
* @param request - Session, queue item, and requested mutation.
|
|
2952
2921
|
* @returns acknowledgement that the queue mutation was applied.
|
|
2953
2922
|
*/
|