@opencode/server 0.0.0-dev-19533 → 0.0.0-dev-19537
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.
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import { Session } from "@opencode/core/session";
|
|
2
|
-
import {
|
|
2
|
+
import type { Snapshot } from "@opencode/core/snapshot";
|
|
3
|
+
import { MessageNotFoundError, SessionNotFoundError, UnknownError } from "@opencode/protocol/errors";
|
|
3
4
|
import { Effect } from "effect";
|
|
4
5
|
export declare function missingSession(error: Session.NotFoundError): SessionNotFoundError;
|
|
6
|
+
export declare function missingMessage(error: Session.MessageNotFoundError): MessageNotFoundError;
|
|
5
7
|
export declare function failedMessageDecode(error: Session.MessageDecodeError): Effect.Effect<never, UnknownError, never>;
|
|
8
|
+
/** Snapshot repositories are host state clients cannot repair, so surface only a log reference. */
|
|
9
|
+
export declare function failedSnapshot(operation: string, sessionID: Session.ID): (error: Snapshot.Error) => Effect.Effect<never, UnknownError, never>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Session } from "@opencode/core/session";
|
|
2
|
-
import { SessionNotFoundError, UnknownError } from "@opencode/protocol/errors";
|
|
2
|
+
import { MessageNotFoundError, SessionNotFoundError, UnknownError } from "@opencode/protocol/errors";
|
|
3
3
|
import { Effect } from "effect";
|
|
4
4
|
export function missingSession(error) {
|
|
5
5
|
return new SessionNotFoundError({
|
|
@@ -7,7 +7,20 @@ export function missingSession(error) {
|
|
|
7
7
|
message: `Session not found: ${error.sessionID}`
|
|
8
8
|
});
|
|
9
9
|
}
|
|
10
|
+
export function missingMessage(error) {
|
|
11
|
+
return new MessageNotFoundError({
|
|
12
|
+
sessionID: error.sessionID,
|
|
13
|
+
messageID: error.messageID,
|
|
14
|
+
message: `Message not found: ${error.messageID}`
|
|
15
|
+
});
|
|
16
|
+
}
|
|
10
17
|
export function failedMessageDecode(error) {
|
|
11
18
|
const ref = `err_${crypto.randomUUID().slice(0, 8)}`;
|
|
12
19
|
return Effect.logError("failed to decode session message").pipe(Effect.annotateLogs({ ref, sessionID: error.sessionID, messageID: error.messageID }), Effect.andThen(Effect.fail(new UnknownError({ message: "Unexpected server error. Check server logs for details.", ref }))));
|
|
13
20
|
}
|
|
21
|
+
export function failedSnapshot(operation, sessionID) {
|
|
22
|
+
return (error) => {
|
|
23
|
+
const ref = `err_${crypto.randomUUID().slice(0, 8)}`;
|
|
24
|
+
return Effect.logError(`failed to ${operation}`, { cause: error }).pipe(Effect.annotateLogs({ ref, sessionID }), Effect.andThen(Effect.fail(new UnknownError({ message: "Unexpected server error. Check server logs for details.", ref }))));
|
|
25
|
+
};
|
|
26
|
+
}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { Session } from "@opencode/core/session";
|
|
2
2
|
import { SessionTransfer } from "@opencode/core/session/transfer";
|
|
3
|
-
export declare const SessionHandler: import("effect/Layer").Layer<import("effect/unstable/httpapi/HttpApiGroup").Service<"server", "server.session">, never,
|
|
3
|
+
export declare const SessionHandler: import("effect/Layer").Layer<import("effect/unstable/httpapi/HttpApiGroup").Service<"server", "server.session">, never, Session.Service | import("../middleware/session-location").SessionLocationMiddleware | SessionTransfer.Service | import("effect/unstable/http/HttpRouter").Request<"Requires", import("@opencode/core/database/database").Service> | (import("@opencode/protocol/middleware/schema-error").SchemaErrorMiddleware | import("@opencode/protocol/middleware/authorization").Authorization)>;
|
package/dist/handlers/session.js
CHANGED
|
@@ -16,11 +16,10 @@ import {
|
|
|
16
16
|
MessageNotFoundError,
|
|
17
17
|
ServiceUnavailableError,
|
|
18
18
|
SessionBusyError,
|
|
19
|
-
SkillNotFoundError
|
|
20
|
-
UnknownError
|
|
19
|
+
SkillNotFoundError
|
|
21
20
|
} from "@opencode/protocol/errors";
|
|
22
21
|
import { AbsolutePath } from "@opencode/core/schema";
|
|
23
|
-
import { failedMessageDecode, missingSession } from "./session-error";
|
|
22
|
+
import { failedMessageDecode, failedSnapshot, missingMessage, missingSession } from "./session-error";
|
|
24
23
|
const DefaultSessionsLimit = 50;
|
|
25
24
|
export const SessionHandler = HttpApiBuilder.group(Api, "server.session", (handlers) => Effect.gen(function* () {
|
|
26
25
|
const session = yield* Session.Service, transfer = yield* SessionTransfer.Service, busySession = (error) => new SessionBusyError({
|
|
@@ -115,11 +114,7 @@ export const SessionHandler = HttpApiBuilder.group(Api, "server.session", (handl
|
|
|
115
114
|
return HttpApiSchema.NoContent.make();
|
|
116
115
|
})).handle("session.fork", Effect.fn(function* (ctx) {
|
|
117
116
|
return {
|
|
118
|
-
data: yield* session.fork({ sessionID: ctx.params.sessionID, boundary: ctx.payload.boundary }).pipe(Effect.catchTag("Session.NotFoundError", missingSession), Effect.catchTag("Session.MessageNotFoundError", (error) => new
|
|
119
|
-
sessionID: error.sessionID,
|
|
120
|
-
messageID: error.messageID,
|
|
121
|
-
message: `Message not found: ${error.messageID}`
|
|
122
|
-
})), Effect.catchTag("Session.ForkEmptyError", (error) => new InvalidRequestError({ message: error.message, kind: "empty_session" })))
|
|
117
|
+
data: yield* session.fork({ sessionID: ctx.params.sessionID, boundary: ctx.payload.boundary }).pipe(Effect.catchTag("Session.NotFoundError", missingSession), Effect.catchTag("Session.MessageNotFoundError", missingMessage), Effect.catchTag("Session.ForkEmptyError", (error) => new InvalidRequestError({ message: error.message, kind: "empty_session" })))
|
|
123
118
|
};
|
|
124
119
|
})).handle("session.switchAgent", Effect.fn(function* (ctx) {
|
|
125
120
|
yield* session.switchAgent({ sessionID: ctx.params.sessionID, agent: ctx.payload.agent }).pipe(Effect.catchTag("Session.NotFoundError", missingSession));
|
|
@@ -217,27 +212,11 @@ export const SessionHandler = HttpApiBuilder.group(Api, "server.session", (handl
|
|
|
217
212
|
files: ctx.payload.files
|
|
218
213
|
});
|
|
219
214
|
return {
|
|
220
|
-
data: yield* session.revert.stage({ ...ctx.params, ...ctx.payload }).pipe(Effect.catchTag("Session.NotFoundError", missingSession), Effect.catchTag("Session.MessageNotFoundError", (
|
|
221
|
-
sessionID: error.sessionID,
|
|
222
|
-
messageID: error.messageID,
|
|
223
|
-
message: `Message not found: ${error.messageID}`
|
|
224
|
-
})), Effect.catchTag("Session.BusyError", busySession), Effect.catchTag("Snapshot.Error", (error) => {
|
|
225
|
-
const ref = `err_${crypto.randomUUID().slice(0, 8)}`;
|
|
226
|
-
return Effect.logError("failed to stage session revert", { cause: error }).pipe(Effect.andThen(Effect.fail(new UnknownError({
|
|
227
|
-
message: "Unexpected server error. Check server logs for details.",
|
|
228
|
-
ref
|
|
229
|
-
}))));
|
|
230
|
-
}))
|
|
215
|
+
data: yield* session.revert.stage({ ...ctx.params, ...ctx.payload }).pipe(Effect.catchTag("Session.NotFoundError", missingSession), Effect.catchTag("Session.MessageNotFoundError", missingMessage), Effect.catchTag("Session.BusyError", busySession), Effect.catchTag("Snapshot.Error", failedSnapshot("stage session revert", ctx.params.sessionID)))
|
|
231
216
|
};
|
|
232
217
|
})).handle("session.revert.clear", Effect.fn(function* (ctx) {
|
|
233
218
|
yield* Effect.log("session.revert.clear", { sessionID: ctx.params.sessionID });
|
|
234
|
-
yield* session.revert.clear(ctx.params.sessionID).pipe(Effect.catchTag("Session.NotFoundError", missingSession), Effect.catchTag("Session.BusyError", busySession), Effect.catchTag("Snapshot.Error", (
|
|
235
|
-
const ref = `err_${crypto.randomUUID().slice(0, 8)}`;
|
|
236
|
-
return Effect.logError("failed to clear session revert", { cause: error }).pipe(Effect.andThen(Effect.fail(new UnknownError({
|
|
237
|
-
message: "Unexpected server error. Check server logs for details.",
|
|
238
|
-
ref
|
|
239
|
-
}))));
|
|
240
|
-
}));
|
|
219
|
+
yield* session.revert.clear(ctx.params.sessionID).pipe(Effect.catchTag("Session.NotFoundError", missingSession), Effect.catchTag("Session.BusyError", busySession), Effect.catchTag("Snapshot.Error", failedSnapshot("clear session revert", ctx.params.sessionID)));
|
|
241
220
|
return HttpApiSchema.NoContent.make();
|
|
242
221
|
})).handle("session.revert.commit", Effect.fn(function* (ctx) {
|
|
243
222
|
yield* Effect.log("session.revert.commit", { sessionID: ctx.params.sessionID });
|
|
@@ -247,6 +226,10 @@ export const SessionHandler = HttpApiBuilder.group(Api, "server.session", (handl
|
|
|
247
226
|
return {
|
|
248
227
|
data: yield* session.context(ctx.params.sessionID).pipe(Effect.catchTag("Session.NotFoundError", missingSession), Effect.catchTag("Session.MessageDecodeError", failedMessageDecode))
|
|
249
228
|
};
|
|
229
|
+
})).handle("session.diff", Effect.fn(function* (ctx) {
|
|
230
|
+
return {
|
|
231
|
+
data: yield* session.diff({ sessionID: ctx.params.sessionID, ...ctx.query }).pipe(Effect.catchTag("Session.NotFoundError", missingSession), Effect.catchTag("Session.MessageNotFoundError", missingMessage), Effect.catchTag("Session.TurnRangeError", (error) => new InvalidRequestError({ message: error.message, field: error.field })), Effect.catchTag("Snapshot.Error", failedSnapshot("diff session turn", ctx.params.sessionID)))
|
|
232
|
+
};
|
|
250
233
|
})).handle("session.inbox.list", Effect.fn(function* (ctx) {
|
|
251
234
|
return {
|
|
252
235
|
data: yield* session.inbox(ctx.params.sessionID).pipe(Effect.catchTag("Session.NotFoundError", missingSession))
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://json.schemastore.org/package.json",
|
|
3
3
|
"name": "@opencode/server",
|
|
4
|
-
"version": "0.0.0-dev-
|
|
4
|
+
"version": "0.0.0-dev-19537",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"repository": {
|
|
@@ -30,17 +30,17 @@
|
|
|
30
30
|
"dependencies": {
|
|
31
31
|
"@effect/platform-node": "4.0.0-rc.112",
|
|
32
32
|
"@effect/platform-node-shared": "4.0.0-rc.112",
|
|
33
|
-
"@opencode/core": "0.0.0-dev-
|
|
34
|
-
"@opencode/protocol": "0.0.0-dev-
|
|
35
|
-
"@opencode/schema": "0.0.0-dev-
|
|
36
|
-
"@opencode/simulation": "0.0.0-dev-
|
|
37
|
-
"@opencode/util": "0.0.0-dev-
|
|
33
|
+
"@opencode/core": "0.0.0-dev-19537",
|
|
34
|
+
"@opencode/protocol": "0.0.0-dev-19537",
|
|
35
|
+
"@opencode/schema": "0.0.0-dev-19537",
|
|
36
|
+
"@opencode/simulation": "0.0.0-dev-19537",
|
|
37
|
+
"@opencode/util": "0.0.0-dev-19537",
|
|
38
38
|
"drizzle-orm": "1.0.0-rc.5-169397b",
|
|
39
39
|
"effect": "4.0.0-rc.112"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
|
-
"@opencode/client": "0.0.0-dev-
|
|
43
|
-
"@opencode/plugin": "0.0.0-dev-
|
|
42
|
+
"@opencode/client": "0.0.0-dev-19537",
|
|
43
|
+
"@opencode/plugin": "0.0.0-dev-19537",
|
|
44
44
|
"@tsconfig/bun": "1.0.9",
|
|
45
45
|
"@types/bun": "1.4.0",
|
|
46
46
|
"@typescript/native-preview": "7.0.0-dev.20251207.1"
|