@opencode/server 0.0.0-dev-19794 → 0.0.0-dev-19808

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 (101) hide show
  1. package/dist/api.js +10 -9
  2. package/dist/auth.js +12 -17
  3. package/dist/chunks/workerd-00nn3k4b.js +20 -0
  4. package/dist/chunks/workerd-04xw3v55.js +23 -0
  5. package/dist/chunks/workerd-19c9ysa1.js +61 -0
  6. package/dist/chunks/workerd-1c4qas2w.js +346 -0
  7. package/dist/chunks/workerd-254zvkj6.js +22 -0
  8. package/dist/chunks/workerd-2rvsests.js +99 -0
  9. package/dist/chunks/workerd-2sy3c7de.js +83 -0
  10. package/dist/chunks/workerd-3kzx88w9.js +26 -0
  11. package/dist/chunks/workerd-4g0fa6m0.js +32 -0
  12. package/dist/chunks/workerd-4vn5bvkr.js +25 -0
  13. package/dist/chunks/workerd-5rwqcaw2.js +33 -0
  14. package/dist/chunks/workerd-5w24ch67.js +23 -0
  15. package/dist/chunks/workerd-6gkz39ey.js +55 -0
  16. package/dist/chunks/workerd-6nvan4e0.js +17 -0
  17. package/dist/chunks/workerd-6ptwb1q1.js +149 -0
  18. package/dist/chunks/workerd-75c938bc.js +23 -0
  19. package/dist/chunks/workerd-7cfyat0f.js +37 -0
  20. package/dist/chunks/workerd-7rzt3wm8.js +13 -0
  21. package/dist/chunks/workerd-8bajbwjh.js +40 -0
  22. package/dist/chunks/workerd-9rqn6x4v.js +16 -0
  23. package/dist/chunks/workerd-a6yp8301.js +156 -0
  24. package/dist/chunks/workerd-arj41x43.js +77 -0
  25. package/dist/chunks/workerd-b0b71rwa.js +39 -0
  26. package/dist/chunks/workerd-bjrwanme.js +22 -0
  27. package/dist/chunks/workerd-bkqymx4n.js +26 -0
  28. package/dist/chunks/workerd-br99j6q1.js +35 -0
  29. package/dist/chunks/workerd-ceh2h0m9.js +25 -0
  30. package/dist/chunks/workerd-hezj1jdf.js +7 -0
  31. package/dist/chunks/workerd-hjnxtxmk.js +34 -0
  32. package/dist/chunks/workerd-j2pfq4q6.js +42 -0
  33. package/dist/chunks/workerd-m6wvgbfq.js +60 -0
  34. package/dist/chunks/workerd-mzr9gftb.js +36 -0
  35. package/dist/chunks/workerd-n0er2m55.js +163 -0
  36. package/dist/chunks/workerd-pnqq1zxv.js +29 -0
  37. package/dist/chunks/workerd-q0ycym90.js +13 -0
  38. package/dist/chunks/workerd-q4bn6dy8.js +39 -0
  39. package/dist/chunks/workerd-qnwpcgp7.js +22 -0
  40. package/dist/chunks/workerd-qzap92t7.js +139 -0
  41. package/dist/chunks/workerd-r7e9r02j.js +13 -0
  42. package/dist/chunks/workerd-rcg4y18n.js +59 -0
  43. package/dist/chunks/workerd-req22b70.js +22 -0
  44. package/dist/chunks/workerd-smaf4a18.js +28 -0
  45. package/dist/chunks/workerd-t8yzmczr.js +18 -0
  46. package/dist/chunks/workerd-x1haxfjx.js +21 -0
  47. package/dist/chunks/workerd-yc7nft6q.js +5 -0
  48. package/dist/chunks/workerd-ysabas57.js +13 -0
  49. package/dist/chunks/workerd-z5shrcz9.js +19 -0
  50. package/dist/chunks/workerd-zp2jm6dt.js +15 -0
  51. package/dist/chunks/workerd-zyv89x5n.js +30 -0
  52. package/dist/cors.js +10 -36
  53. package/dist/event-feed.js +20 -60
  54. package/dist/fetch.js +53 -11
  55. package/dist/handlers/agent.js +11 -17
  56. package/dist/handlers/command.js +11 -5
  57. package/dist/handlers/config.js +11 -16
  58. package/dist/handlers/credential.js +11 -14
  59. package/dist/handlers/debug.js +11 -11
  60. package/dist/handlers/event.js +12 -27
  61. package/dist/handlers/form.js +11 -9
  62. package/dist/handlers/fs.js +11 -22
  63. package/dist/handlers/generate.js +11 -15
  64. package/dist/handlers/integration.js +10 -142
  65. package/dist/handlers/location.js +11 -16
  66. package/dist/handlers/mcp.js +11 -31
  67. package/dist/handlers/message.js +10 -42
  68. package/dist/handlers/migration.js +11 -7
  69. package/dist/handlers/model.js +11 -14
  70. package/dist/handlers/permission.js +11 -57
  71. package/dist/handlers/persistent-pty.js +12 -135
  72. package/dist/handlers/plugin.js +11 -47
  73. package/dist/handlers/project.js +11 -9
  74. package/dist/handlers/provider.js +11 -20
  75. package/dist/handlers/pty-socket.js +6 -4
  76. package/dist/handlers/pty.js +13 -107
  77. package/dist/handlers/reference.js +11 -5
  78. package/dist/handlers/rpc.js +11 -15
  79. package/dist/handlers/server.js +12 -13
  80. package/dist/handlers/session-error.js +12 -26
  81. package/dist/handlers/session.js +10 -311
  82. package/dist/handlers/shell.js +11 -25
  83. package/dist/handlers/skill.js +11 -5
  84. package/dist/handlers/vcs.js +11 -19
  85. package/dist/handlers/websearch.js +11 -31
  86. package/dist/handlers/worktree.js +11 -37
  87. package/dist/handlers.js +46 -33
  88. package/dist/location.js +15 -49
  89. package/dist/middleware/authorization.js +11 -49
  90. package/dist/middleware/form-location.js +10 -25
  91. package/dist/middleware/schema-error.js +8 -15
  92. package/dist/middleware/session-location.js +10 -19
  93. package/dist/options.js +5 -1
  94. package/dist/process.js +108 -28
  95. package/dist/pty-environment.js +12 -9
  96. package/dist/request-tracing.js +6 -2
  97. package/dist/routes.js +52 -118
  98. package/dist/server-info.js +12 -22
  99. package/dist/service-status.js +8 -11
  100. package/dist/workerd.js +80 -12
  101. package/package.json +8 -8
@@ -1,108 +1,14 @@
1
- import { Pty } from "@opencode/core/pty";
2
- import { PtyProtocol } from "@opencode/core/pty/protocol";
3
- import { PtyTicket } from "@opencode/core/pty/ticket";
4
- import { Location } from "@opencode/core/location";
5
- import { Effect, Queue } from "effect";
6
- import { HttpServerRequest, HttpServerResponse } from "effect/unstable/http";
7
- import { HttpApiBuilder, HttpApiSchema } from "effect/unstable/httpapi";
8
- import { Socket } from "effect/unstable/socket";
9
- import { Api } from "../api";
10
- import { CorsConfig, isAllowedRequestOrigin } from "../cors";
11
- import { ForbiddenError, PtyNotFoundError } from "@opencode/protocol/errors";
12
1
  import {
13
- PTY_CONNECT_TICKET_QUERY,
14
- PTY_CONNECT_TOKEN_HEADER,
15
- PTY_CONNECT_TOKEN_HEADER_VALUE
16
- } from "@opencode/protocol/groups/pty";
17
- import { response } from "../location";
18
- import { PtyEnvironment } from "../pty-environment";
19
- import { runPtySocket } from "./pty-socket";
20
- const ticketScope = Effect.gen(function* () {
21
- const location = yield* Location.Service;
22
- return { directory: location.directory, workspaceID: location.workspaceID };
23
- });
24
- export const PtyHandler = HttpApiBuilder.group(Api, "server.pty", (handlers) => Effect.gen(function* () {
25
- const tickets = yield* PtyTicket.Service, cors = yield* CorsConfig, environment = yield* PtyEnvironment.Service;
26
- return handlers.handle("pty.list", Effect.fn(function* () {
27
- const pty = yield* Pty.Service;
28
- return yield* response(pty.list());
29
- })).handle("pty.create", Effect.fn(function* (ctx) {
30
- const pty = yield* Pty.Service, location = yield* Location.Service, cwd = ctx.payload.cwd || location.directory;
31
- return yield* response(pty.create({
32
- ...ctx.payload,
33
- args: ctx.payload.args ? [...ctx.payload.args] : void 0,
34
- cwd,
35
- env: {
36
- ...ctx.payload.env,
37
- ...yield* environment.get({ directory: location.directory, cwd })
38
- }
39
- }));
40
- })).handle("pty.get", Effect.fn(function* (ctx) {
41
- const pty = yield* Pty.Service;
42
- return yield* response(pty.get(ctx.params.ptyID).pipe(Effect.catchTag("Pty.NotFoundError", () => new PtyNotFoundError({
43
- ptyID: ctx.params.ptyID,
44
- message: `PTY session not found: ${ctx.params.ptyID}`
45
- }))));
46
- })).handle("pty.update", Effect.fn(function* (ctx) {
47
- const pty = yield* Pty.Service;
48
- return yield* response(pty.update(ctx.params.ptyID, {
49
- ...ctx.payload,
50
- size: ctx.payload.size ? { ...ctx.payload.size } : void 0
51
- }).pipe(Effect.catchTag("Pty.NotFoundError", () => new PtyNotFoundError({
52
- ptyID: ctx.params.ptyID,
53
- message: `PTY session not found: ${ctx.params.ptyID}`
54
- }))));
55
- })).handle("pty.remove", Effect.fn(function* (ctx) {
56
- yield* (yield* Pty.Service).remove(ctx.params.ptyID).pipe(Effect.catchTag("Pty.NotFoundError", () => new PtyNotFoundError({
57
- ptyID: ctx.params.ptyID,
58
- message: `PTY session not found: ${ctx.params.ptyID}`
59
- })));
60
- return HttpApiSchema.NoContent.make();
61
- })).handle("pty.connectToken", Effect.fn(function* (ctx) {
62
- const request = yield* HttpServerRequest.HttpServerRequest;
63
- if (request.headers[PTY_CONNECT_TOKEN_HEADER] !== PTY_CONNECT_TOKEN_HEADER_VALUE || !isAllowedRequestOrigin(request.headers.origin, request.headers.host, cors))
64
- return yield* new ForbiddenError({ message: "Invalid PTY connect token request" });
65
- yield* (yield* Pty.Service).get(ctx.params.ptyID).pipe(Effect.catchTag("Pty.NotFoundError", () => new PtyNotFoundError({
66
- ptyID: ctx.params.ptyID,
67
- message: `PTY session not found: ${ctx.params.ptyID}`
68
- })));
69
- return yield* response(tickets.issue({ ptyID: ctx.params.ptyID, ...yield* ticketScope }));
70
- })).handleRaw("pty.connect", Effect.fn("PtyHandler.connect")(function* (ctx) {
71
- const pty = yield* Pty.Service;
72
- if (!(yield* pty.get(ctx.params.ptyID).pipe(Effect.as(!0), Effect.catchTag("Pty.NotFoundError", () => Effect.succeed(!1)))))
73
- return HttpServerResponse.empty({ status: 404 });
74
- const url = new URL(ctx.request.url, "http://localhost"), ticket = url.searchParams.get(PTY_CONNECT_TICKET_QUERY);
75
- if (ticket) {
76
- if (!(isAllowedRequestOrigin(ctx.request.headers.origin, ctx.request.headers.host, cors) ? yield* tickets.consume({ ticket, ptyID: ctx.params.ptyID, ...yield* ticketScope }) : !1))
77
- return HttpServerResponse.empty({ status: 403 });
78
- }
79
- const parsedCursor = url.searchParams.get("cursor"), cursorNumber = parsedCursor === null ? void 0 : Number(parsedCursor), cursor = cursorNumber !== void 0 && Number.isSafeInteger(cursorNumber) && cursorNumber >= -1 ? cursorNumber : void 0, socket = yield* Effect.orDie(ctx.request.upgrade), write = yield* socket.writer, closeAccepted = (event) => socket.runRaw(() => Effect.void, { onOpen: write(event).pipe(Effect.catch(() => Effect.void)) }).pipe(Effect.timeout("1 second"), Effect.catchReason("SocketError", "SocketCloseError", () => Effect.void), Effect.catch(() => Effect.void)), outbox = yield* Queue.unbounded(), attachment = yield* pty.attach(ctx.params.ptyID, {
80
- cursor,
81
- onData: (chunk) => Queue.offerUnsafe(outbox, chunk),
82
- onEnd: () => Queue.offerUnsafe(outbox, new Socket.CloseEvent(1000))
83
- }).pipe(Effect.catchTags({
84
- "Pty.NotFoundError": () => closeAccepted(new Socket.CloseEvent(4404, "session not found")).pipe(Effect.as(void 0)),
85
- "Pty.ExitedError": () => closeAccepted(new Socket.CloseEvent(4404, "session exited")).pipe(Effect.as(void 0))
86
- }));
87
- if (!attachment)
88
- return HttpServerResponse.empty();
89
- for (const chunk of PtyProtocol.chunks(attachment.replay))
90
- Queue.offerUnsafe(outbox, chunk);
91
- Queue.offerUnsafe(outbox, PtyProtocol.metaFrame(attachment.cursor));
92
- attachment.activate();
93
- const drain = Effect.gen(function* () {
94
- while (!0) {
95
- const item = yield* Queue.take(outbox);
96
- yield* write(item);
97
- if (item instanceof Socket.CloseEvent)
98
- return;
99
- }
100
- });
101
- yield* runPtySocket(drain, socket.runRaw((message) => {
102
- const decoded = PtyProtocol.decodeInput(message);
103
- if (decoded !== void 0)
104
- attachment.write(decoded);
105
- }), attachment.detach).pipe(Effect.catchReason("SocketError", "SocketCloseError", () => Effect.void), Effect.orDie);
106
- return HttpServerResponse.empty();
107
- }));
108
- }));
2
+ PtyHandler2
3
+ } from "../chunks/workerd-qzap92t7.js";
4
+ import"../chunks/workerd-hezj1jdf.js";
5
+ import"../chunks/workerd-q4bn6dy8.js";
6
+ import"../chunks/workerd-z5shrcz9.js";
7
+ import"../chunks/workerd-3kzx88w9.js";
8
+ import"../chunks/workerd-5rwqcaw2.js";
9
+ import"../chunks/workerd-6gkz39ey.js";
10
+ import"../chunks/workerd-smaf4a18.js";
11
+ import"../chunks/workerd-75c938bc.js";
12
+ export {
13
+ PtyHandler2 as PtyHandler
14
+ };
@@ -1,5 +1,11 @@
1
- import { Reference } from "@opencode/core/reference";
2
- import { HttpApiBuilder } from "effect/unstable/httpapi";
3
- import { Api } from "../api";
4
- import { response } from "../location";
5
- export const ReferenceHandler = HttpApiBuilder.group(Api, "server.reference", (handlers) => handlers.handle("reference.list", () => response(Reference.Service.use((reference) => reference.list()))));
1
+ import {
2
+ ReferenceHandler2
3
+ } from "../chunks/workerd-ysabas57.js";
4
+ import"../chunks/workerd-z5shrcz9.js";
5
+ import"../chunks/workerd-3kzx88w9.js";
6
+ import"../chunks/workerd-5rwqcaw2.js";
7
+ import"../chunks/workerd-6gkz39ey.js";
8
+ import"../chunks/workerd-smaf4a18.js";
9
+ export {
10
+ ReferenceHandler2 as ReferenceHandler
11
+ };
@@ -1,15 +1,11 @@
1
- import { Rpc } from "@opencode/core/rpc";
2
- import { Plugin } from "@opencode/core/plugin";
3
- import { RpcError, RpcInternalError } from "@opencode/protocol/errors";
4
- import { Effect } from "effect";
5
- import { HttpApiBuilder } from "effect/unstable/httpapi";
6
- import { Api } from "../api";
7
- export const RpcHandler = HttpApiBuilder.group(Api, "server.rpc", (handlers) => handlers.handle("rpc.call", ({ params, payload }) => Effect.gen(function* () {
8
- yield* Plugin.awaitActivation;
9
- const output = yield* (yield* Rpc.Service).call(params.rpcID, params.method, payload.input);
10
- return output === void 0 ? {} : { output };
11
- }).pipe(Effect.mapError((error) => error.type === "rpc.invalid_output" || error.type === "rpc.internal" ? new RpcInternalError({ type: error.type, message: error.message }) : new RpcError({
12
- type: error.type,
13
- message: error.message,
14
- ...error.data === void 0 ? {} : { data: error.data }
15
- })), Effect.catchDefect((defect) => Effect.logError("rpc call failed", { rpc: params.rpcID, method: params.method, defect }).pipe(Effect.andThen(Effect.fail(new RpcInternalError({ type: "rpc.internal", message: "RPC call failed" }))))))));
1
+ import {
2
+ RpcHandler2
3
+ } from "../chunks/workerd-bjrwanme.js";
4
+ import"../chunks/workerd-z5shrcz9.js";
5
+ import"../chunks/workerd-3kzx88w9.js";
6
+ import"../chunks/workerd-5rwqcaw2.js";
7
+ import"../chunks/workerd-6gkz39ey.js";
8
+ import"../chunks/workerd-smaf4a18.js";
9
+ export {
10
+ RpcHandler2 as RpcHandler
11
+ };
@@ -1,13 +1,12 @@
1
- import { Effect } from "effect";
2
- import { HttpApiBuilder } from "effect/unstable/httpapi";
3
- import { Api } from "../api";
4
- import { ServerInfo } from "../server-info";
5
- export const ServerHandler = HttpApiBuilder.group(Api, "server.server", (handlers) => handlers.handle("server.info", () => Effect.gen(function* () {
6
- const info = yield* ServerInfo.Service;
7
- return {
8
- version: info.app.version ?? "unknown",
9
- pid: process.pid ?? 0,
10
- urls: info.urls(),
11
- paths: info.paths
12
- };
13
- })));
1
+ import {
2
+ ServerHandler2
3
+ } from "../chunks/workerd-x1haxfjx.js";
4
+ import"../chunks/workerd-mzr9gftb.js";
5
+ import"../chunks/workerd-z5shrcz9.js";
6
+ import"../chunks/workerd-3kzx88w9.js";
7
+ import"../chunks/workerd-5rwqcaw2.js";
8
+ import"../chunks/workerd-6gkz39ey.js";
9
+ import"../chunks/workerd-smaf4a18.js";
10
+ export {
11
+ ServerHandler2 as ServerHandler
12
+ };
@@ -1,26 +1,12 @@
1
- import { Session } from "@opencode/core/session";
2
- import { MessageNotFoundError, SessionNotFoundError, UnknownError } from "@opencode/protocol/errors";
3
- import { Effect } from "effect";
4
- export function missingSession(error) {
5
- return new SessionNotFoundError({
6
- sessionID: error.sessionID,
7
- message: `Session not found: ${error.sessionID}`
8
- });
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
- }
17
- export function failedMessageDecode(error) {
18
- const ref = `err_${crypto.randomUUID().slice(0, 8)}`;
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 }))));
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
+ import {
2
+ missingSession2,
3
+ missingMessage2,
4
+ failedMessageDecode2,
5
+ failedSnapshot2
6
+ } from "../chunks/workerd-smaf4a18.js";
7
+ export {
8
+ failedMessageDecode2 as failedMessageDecode,
9
+ failedSnapshot2 as failedSnapshot,
10
+ missingMessage2 as missingMessage,
11
+ missingSession2 as missingSession
12
+ };
@@ -1,312 +1,11 @@
1
- import { Session } from "@opencode/core/session";
2
- import { SessionStats } from "@opencode/core/session/stats";
3
- import { SessionTitle } from "@opencode/core/session/title";
4
- import { SessionTransfer } from "@opencode/core/session/transfer";
5
- import { InstructionEntry } from "@opencode/core/session/instruction-entry";
6
- import { Form } from "@opencode/core/form";
7
- import { DateTime, Effect, Stream } from "effect";
8
- import { HttpApiBuilder, HttpApiSchema } from "effect/unstable/httpapi";
9
- import { Api } from "../api";
10
- import { SessionsCursor } from "@opencode/protocol/groups/session";
11
1
  import {
12
- ConflictError,
13
- CommandExecutionError,
14
- CommandNotFoundError,
15
- FormAlreadySettledError,
16
- FormInvalidAnswerError,
17
- FormNotFoundError,
18
- InvalidRequestError,
19
- InvalidCursorError,
20
- MessageNotFoundError,
21
- ServiceUnavailableError,
22
- SessionBusyError,
23
- SkillNotFoundError
24
- } from "@opencode/protocol/errors";
25
- import { AbsolutePath } from "@opencode/core/schema";
26
- import { failedMessageDecode, failedSnapshot, missingMessage, missingSession } from "./session-error";
27
- const DefaultSessionsLimit = 50;
28
- function missingForm(id) {
29
- return new FormNotFoundError({ id, message: `Form not found: ${id}` });
30
- }
31
- export const SessionHandler = HttpApiBuilder.group(Api, "server.session", (handlers) => Effect.gen(function* () {
32
- const session = yield* Session.Service, transfer = yield* SessionTransfer.Service, requireOwnedForm = Effect.fnUntraced(function* (sessionID, formID) {
33
- const form = yield* Form.Service, info = yield* form.get(formID).pipe(Effect.catchTag("Form.NotFoundError", () => missingForm(formID)));
34
- if (info.sessionID !== sessionID)
35
- return yield* missingForm(formID);
36
- return { form, info };
37
- }), busySession = (error) => new SessionBusyError({
38
- sessionID: error.sessionID,
39
- message: `Session is busy: ${error.sessionID}`
40
- }), pendingMutation = (effect, conflict) => effect.pipe(Effect.catchTag("Session.NotFoundError", missingSession), Effect.catchTag("Session.InboxConflictError", (error) => new ConflictError({ resource: error.inboxID, message: `${conflict}: ${error.inboxID}` })), Effect.as(HttpApiSchema.NoContent.make()));
41
- return handlers.handle("session.list", Effect.fn(function* (ctx) {
42
- const query = ctx.query.cursor !== void 0 ? yield* SessionsCursor.parse(ctx.query.cursor).pipe(Effect.mapError(() => new InvalidCursorError({ message: "Invalid cursor" }))) : ctx.query, sessions = (yield* session.list({
43
- ...query,
44
- limit: ctx.query.limit ?? DefaultSessionsLimit
45
- })).data, first = sessions[0], last = sessions.at(-1);
46
- return {
47
- data: sessions,
48
- cursor: {
49
- previous: first ? SessionsCursor.make({
50
- ...query,
51
- anchor: {
52
- id: first.id,
53
- time: DateTime.toEpochMillis(first.time.updated),
54
- direction: "previous"
55
- }
56
- }) : void 0,
57
- next: last ? SessionsCursor.make({
58
- ...query,
59
- anchor: {
60
- id: last.id,
61
- time: DateTime.toEpochMillis(last.time.updated),
62
- direction: "next"
63
- }
64
- }) : void 0
65
- }
66
- };
67
- })).handle("session.stats", Effect.fn(function* (ctx) {
68
- const timezone = ctx.query.timezone ?? "UTC";
69
- yield* Effect.try({
70
- try: () => new Intl.DateTimeFormat("en-US", { timeZone: timezone }),
71
- catch: () => new InvalidRequestError({ message: `Invalid time zone: ${timezone}` })
72
- });
73
- return {
74
- data: yield* SessionStats.get({
75
- from: ctx.query.from,
76
- to: ctx.query.to,
77
- projectID: ctx.query.project,
78
- timezone,
79
- tools: ctx.query.tools
80
- }).pipe(Effect.mapError(() => new InvalidRequestError({ message: "Stats range must end after it starts" })))
81
- };
82
- })).handle("session.create", Effect.fn(function* (ctx) {
83
- return {
84
- data: yield* session.create({
85
- id: ctx.payload.id,
86
- title: ctx.payload.title,
87
- agent: ctx.payload.agent,
88
- model: ctx.payload.model,
89
- metadata: ctx.payload.metadata,
90
- permissions: ctx.payload.permissions,
91
- location: ctx.payload.location ?? { directory: AbsolutePath.make(process.cwd()) }
92
- }).pipe(Effect.orDie)
93
- };
94
- })).handle("session.import", Effect.fn(function* (ctx) {
95
- return {
96
- data: yield* transfer.import({
97
- data: { info: ctx.payload.info, messages: ctx.payload.messages },
98
- location: ctx.payload.location ?? { directory: AbsolutePath.make(process.cwd()) }
99
- }).pipe(Effect.catchTag("Session.NotFoundError", missingSession), Effect.catchTag("SessionTransfer.ImportConflictError", (error) => new ConflictError({
100
- message: `Session already exists: ${error.sessionID}`,
101
- resource: error.sessionID
102
- })))
103
- };
104
- })).handle("session.export", Effect.fn(function* (ctx) {
105
- return {
106
- data: yield* transfer.export({ sessionID: ctx.params.sessionID, sanitize: ctx.query.sanitize }).pipe(Effect.catchTag("Session.NotFoundError", missingSession), Effect.catchTag("Session.MessageDecodeError", failedMessageDecode))
107
- };
108
- })).handle("session.active", Effect.fn(function* () {
109
- const active = yield* session.active;
110
- return {
111
- data: Object.fromEntries(Array.from(active, (sessionID) => [sessionID, { type: "running" }]))
112
- };
113
- })).handle("session.get", Effect.fn(function* (ctx) {
114
- return {
115
- data: yield* session.get(ctx.params.sessionID).pipe(Effect.catchTag("Session.NotFoundError", missingSession))
116
- };
117
- })).handle("session.view", Effect.fn(function* (ctx) {
118
- yield* session.view({ sessionID: ctx.params.sessionID, idle: DateTime.toEpochMillis(ctx.payload.idle) }).pipe(Effect.catchTag("Session.NotFoundError", missingSession));
119
- return HttpApiSchema.NoContent.make();
120
- })).handle("session.remove", Effect.fn(function* (ctx) {
121
- yield* session.remove(ctx.params.sessionID).pipe(Effect.catchTag("Session.NotFoundError", missingSession));
122
- return HttpApiSchema.NoContent.make();
123
- })).handle("session.environment", Effect.fn(function* (ctx) {
124
- yield* session.environment({ sessionID: ctx.params.sessionID, variables: ctx.payload.variables }).pipe(Effect.catchTag("Session.NotFoundError", missingSession));
125
- return HttpApiSchema.NoContent.make();
126
- })).handle("session.fork", Effect.fn(function* (ctx) {
127
- return {
128
- data: yield* session.fork({ sessionID: ctx.params.sessionID, before: ctx.payload.before }).pipe(Effect.catchTag("Session.NotFoundError", missingSession), Effect.catchTag("Session.MessageNotFoundError", missingMessage), Effect.catchTag("Session.ForkEmptyError", (error) => new InvalidRequestError({ message: error.message, kind: "empty_session" })))
129
- };
130
- })).handle("session.switchAgent", Effect.fn(function* (ctx) {
131
- yield* session.switchAgent({ sessionID: ctx.params.sessionID, agent: ctx.payload.agent }).pipe(Effect.catchTag("Session.NotFoundError", missingSession));
132
- return HttpApiSchema.NoContent.make();
133
- })).handle("session.switchModel", Effect.fn(function* (ctx) {
134
- yield* session.switchModel({ sessionID: ctx.params.sessionID, model: ctx.payload.model }).pipe(Effect.catchTag("Session.NotFoundError", missingSession));
135
- return HttpApiSchema.NoContent.make();
136
- })).handle("session.update", Effect.fn(function* (ctx) {
137
- yield* session.get(ctx.params.sessionID).pipe(Effect.catchTag("Session.NotFoundError", missingSession));
138
- if (ctx.payload.title !== void 0)
139
- if (ctx.payload.title)
140
- yield* session.rename({ sessionID: ctx.params.sessionID, title: ctx.payload.title }).pipe(Effect.catchTag("Session.NotFoundError", missingSession));
141
- else
142
- yield* (yield* SessionTitle.Service).generate(ctx.params.sessionID);
143
- if (ctx.payload.permissions !== void 0)
144
- yield* session.setPermissions({ sessionID: ctx.params.sessionID, permissions: ctx.payload.permissions }).pipe(Effect.catchTag("Session.NotFoundError", missingSession));
145
- return HttpApiSchema.NoContent.make();
146
- })).handle("session.move", Effect.fn(function* (ctx) {
147
- yield* session.move({
148
- sessionID: ctx.params.sessionID,
149
- directory: ctx.payload.directory,
150
- delivery: ctx.payload.delivery
151
- }).pipe(Effect.catchTag("Session.NotFoundError", missingSession), Effect.catchTag("Session.DestinationNotFoundError", (error) => Effect.fail(new InvalidRequestError({ message: `Directory does not exist: ${error.directory}` }))), Effect.catchTag("Session.DestinationNotDirectoryError", (error) => Effect.fail(new InvalidRequestError({ message: `Not a directory: ${error.directory}` }))), Effect.catchTag("Session.DestinationUnavailableError", (error) => Effect.fail(new InvalidRequestError({ message: `Directory is unavailable: ${error.directory}` }))));
152
- return HttpApiSchema.NoContent.make();
153
- })).handle("session.prompt", Effect.fn(function* (ctx) {
154
- return {
155
- data: yield* session.prompt({
156
- sessionID: ctx.params.sessionID,
157
- id: ctx.payload.id,
158
- text: ctx.payload.text,
159
- files: ctx.payload.files,
160
- agents: ctx.payload.agents,
161
- skills: ctx.payload.skills,
162
- metadata: ctx.payload.metadata,
163
- delivery: ctx.payload.delivery,
164
- resume: ctx.payload.resume
165
- }).pipe(Effect.catchTag("Session.NotFoundError", missingSession), Effect.catchTag("Session.PromptConflictError", (error) => Effect.fail(new ConflictError({
166
- message: `Prompt message ID conflicts with an existing durable record: ${error.messageID}`,
167
- resource: error.messageID
168
- }))), Effect.catchTag("Session.AttachmentError", (error) => Effect.fail(new InvalidRequestError({ message: error.message, field: "files" }))), Effect.catchTag("Session.SkillNotFoundError", (error) => Effect.fail(new InvalidRequestError({ message: `Skill not found: ${error.skill}`, field: "skills" }))))
169
- };
170
- })).handle("session.command", Effect.fn(function* (ctx) {
171
- yield* session.command({
172
- sessionID: ctx.params.sessionID,
173
- command: ctx.payload.name,
174
- text: ctx.payload.text,
175
- files: ctx.payload.files,
176
- agents: ctx.payload.agents,
177
- skills: ctx.payload.skills,
178
- delivery: ctx.payload.delivery
179
- }).pipe(Effect.catchTag("Session.NotFoundError", missingSession), Effect.catchTag("Command.NotFoundError", (error) => Effect.fail(new CommandNotFoundError({
180
- command: error.command,
181
- message: error.message
182
- }))), Effect.catchTag("Command.ExecutionError", (error) => Effect.fail(new CommandExecutionError({
183
- command: error.command,
184
- message: error.message
185
- }))));
186
- return HttpApiSchema.NoContent.make();
187
- })).handle("session.skill", Effect.fn(function* (ctx) {
188
- yield* session.skill({
189
- sessionID: ctx.params.sessionID,
190
- skill: ctx.payload.id,
191
- resume: ctx.payload.resume
192
- }).pipe(Effect.catchTag("Session.NotFoundError", missingSession), Effect.catchTag("Session.SkillNotFoundError", (error) => Effect.fail(new SkillNotFoundError({ skill: error.skill, message: `Skill not found: ${error.skill}` }))));
193
- return HttpApiSchema.NoContent.make();
194
- })).handle("session.synthetic", Effect.fn(function* (ctx) {
195
- return { data: yield* session.synthetic({
196
- id: ctx.payload.id,
197
- sessionID: ctx.params.sessionID,
198
- text: ctx.payload.text,
199
- description: ctx.payload.description,
200
- metadata: ctx.payload.metadata,
201
- delivery: ctx.payload.delivery,
202
- resume: ctx.payload.resume
203
- }).pipe(Effect.catchTag("Session.NotFoundError", missingSession), Effect.catchTag("Session.SyntheticConflictError", (error) => Effect.fail(new ConflictError({
204
- message: `Synthetic input ID conflicts with an existing durable record: ${error.inputID}`,
205
- resource: error.inputID
206
- })))) };
207
- })).handle("session.shell", Effect.fn(function* (ctx) {
208
- yield* session.shell({ sessionID: ctx.params.sessionID, id: ctx.payload.id, command: ctx.payload.command }).pipe(Effect.catchTag("Session.NotFoundError", missingSession));
209
- return HttpApiSchema.NoContent.make();
210
- })).handle("session.compact", Effect.fn(function* (ctx) {
211
- return {
212
- data: yield* session.compact({ sessionID: ctx.params.sessionID, id: ctx.payload.id, delivery: ctx.payload.delivery }).pipe(Effect.catchTag("Session.NotFoundError", missingSession), Effect.catchTag("Session.CompactionConflictError", (error) => Effect.fail(new ConflictError({
213
- message: `Compaction input ID conflicts with an existing durable record: ${error.inputID}`,
214
- resource: error.inputID
215
- }))))
216
- };
217
- })).handle("session.wait", Effect.fn(function* (ctx) {
218
- yield* session.wait(ctx.params.sessionID).pipe(Effect.catchTag("Session.NotFoundError", missingSession));
219
- return HttpApiSchema.NoContent.make();
220
- })).handle("session.revert.stage", Effect.fn(function* (ctx) {
221
- yield* Effect.log("session.revert.stage", {
222
- sessionID: ctx.params.sessionID,
223
- messageID: ctx.payload.messageID,
224
- files: ctx.payload.files
225
- });
226
- return {
227
- 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)))
228
- };
229
- })).handle("session.revert.clear", Effect.fn(function* (ctx) {
230
- yield* Effect.log("session.revert.clear", { sessionID: ctx.params.sessionID });
231
- 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)));
232
- return HttpApiSchema.NoContent.make();
233
- })).handle("session.revert.commit", Effect.fn(function* (ctx) {
234
- yield* Effect.log("session.revert.commit", { sessionID: ctx.params.sessionID });
235
- yield* session.revert.commit(ctx.params.sessionID).pipe(Effect.catchTag("Session.NotFoundError", missingSession), Effect.catchTag("Session.BusyError", busySession));
236
- return HttpApiSchema.NoContent.make();
237
- })).handle("session.context", Effect.fn(function* (ctx) {
238
- return {
239
- data: yield* session.context(ctx.params.sessionID).pipe(Effect.catchTag("Session.NotFoundError", missingSession), Effect.catchTag("Session.MessageDecodeError", failedMessageDecode))
240
- };
241
- })).handle("session.diff", Effect.fn(function* (ctx) {
242
- return {
243
- 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)))
244
- };
245
- })).handle("session.inbox.list", Effect.fn(function* (ctx) {
246
- return {
247
- data: yield* session.inbox(ctx.params.sessionID).pipe(Effect.catchTag("Session.NotFoundError", missingSession))
248
- };
249
- })).handle("session.inbox.cancel", Effect.fn(function* (ctx) {
250
- yield* session.cancelInbox({ sessionID: ctx.params.sessionID, inboxID: ctx.params.inboxID }).pipe(Effect.catchTag("Session.NotFoundError", missingSession), Effect.catchTag("Session.InboxConflictError", () => Effect.void));
251
- return HttpApiSchema.NoContent.make();
252
- })).handle("session.inbox.update", Effect.fn(function* (ctx) {
253
- return yield* pendingMutation(ctx.payload.delivery === "steer" ? session.steerInbox({ sessionID: ctx.params.sessionID, inboxID: ctx.params.inboxID }) : session.queueInbox({ sessionID: ctx.params.sessionID, inboxID: ctx.params.inboxID }), `Pending input cannot change to ${ctx.payload.delivery}`);
254
- })).handle("session.instructions.entry.list", Effect.fn(function* (ctx) {
255
- return { data: yield* (yield* InstructionEntry.Service).list(ctx.params.sessionID) };
256
- })).handle("session.instructions.entry.put", Effect.fn(function* (ctx) {
257
- yield* (yield* InstructionEntry.Service).put({ sessionID: ctx.params.sessionID, key: ctx.params.key, value: ctx.payload.value });
258
- return HttpApiSchema.NoContent.make();
259
- })).handle("session.instructions.entry.remove", Effect.fn(function* (ctx) {
260
- yield* (yield* InstructionEntry.Service).remove({ sessionID: ctx.params.sessionID, key: ctx.params.key });
261
- return HttpApiSchema.NoContent.make();
262
- })).handle("session.generate", Effect.fn(function* (ctx) {
263
- return { data: { text: yield* session.generate({ sessionID: ctx.params.sessionID, prompt: ctx.payload.prompt }).pipe(Effect.mapError((error) => error._tag === "Session.NotFoundError" ? missingSession(error) : new ServiceUnavailableError({ message: error.message, service: "session generation" }))) } };
264
- })).handle("session.log", Effect.fn(function* (ctx) {
265
- yield* session.get(ctx.params.sessionID).pipe(Effect.catchTag("Session.NotFoundError", missingSession));
266
- return session.log({ sessionID: ctx.params.sessionID, after: ctx.query.after, follow: ctx.query.follow }).pipe(Stream.orDie);
267
- })).handle("session.interrupt", Effect.fn(function* (ctx) {
268
- return { interrupted: yield* session.interrupt(ctx.params.sessionID, { resume: ctx.query.resume }) };
269
- })).handle("session.background", Effect.fn(function* (ctx) {
270
- yield* session.background(ctx.params.sessionID).pipe(Effect.catchTag("Session.NotFoundError", missingSession));
271
- return HttpApiSchema.NoContent.make();
272
- })).handle("session.message", Effect.fn(function* (ctx) {
273
- yield* session.get(ctx.params.sessionID).pipe(Effect.catchTag("Session.NotFoundError", missingSession));
274
- const message = yield* session.message(ctx.params);
275
- if (message)
276
- return { data: message };
277
- return yield* new MessageNotFoundError({
278
- sessionID: ctx.params.sessionID,
279
- messageID: ctx.params.messageID,
280
- message: `Message not found: ${ctx.params.messageID}`
281
- });
282
- })).handle("session.form.list", Effect.fn(function* (ctx) {
283
- return { data: yield* (yield* Form.Service).list({ sessionID: ctx.params.sessionID }) };
284
- })).handle("session.form.create", Effect.fn(function* (ctx) {
285
- return { data: yield* (yield* Form.Service).create({
286
- id: ctx.payload.id,
287
- sessionID: ctx.params.sessionID,
288
- title: ctx.payload.title,
289
- metadata: ctx.payload.metadata,
290
- fields: ctx.payload.fields
291
- }).pipe(Effect.catchTags({
292
- "Form.AlreadyExistsError": (error) => new ConflictError({ resource: error.id, message: error.message }),
293
- "Form.InvalidFormError": (error) => new InvalidRequestError({ message: error.message, field: "fields" })
294
- })) };
295
- })).handle("session.form.get", Effect.fn(function* (ctx) {
296
- const owned = yield* requireOwnedForm(ctx.params.sessionID, ctx.params.formID), state = yield* owned.form.state(ctx.params.formID).pipe(Effect.catchTag("Form.NotFoundError", () => missingForm(ctx.params.formID)));
297
- return { data: { ...owned.info, state } };
298
- })).handle("session.form.reply", Effect.fn(function* (ctx) {
299
- yield* (yield* requireOwnedForm(ctx.params.sessionID, ctx.params.formID)).form.reply({ id: ctx.params.formID, answer: ctx.payload.answer }).pipe(Effect.catchTags({
300
- "Form.AlreadySettledError": (error) => new FormAlreadySettledError({ id: error.id, message: error.message }),
301
- "Form.InvalidAnswerError": (error) => new FormInvalidAnswerError({ id: error.id, message: error.message }),
302
- "Form.NotFoundError": () => missingForm(ctx.params.formID)
303
- }));
304
- return HttpApiSchema.NoContent.make();
305
- })).handle("session.form.cancel", Effect.fn(function* (ctx) {
306
- yield* (yield* requireOwnedForm(ctx.params.sessionID, ctx.params.formID)).form.cancel(ctx.params.formID).pipe(Effect.catchTags({
307
- "Form.AlreadySettledError": (error) => new FormAlreadySettledError({ id: error.id, message: error.message }),
308
- "Form.NotFoundError": () => missingForm(ctx.params.formID)
309
- }));
310
- return HttpApiSchema.NoContent.make();
311
- }));
312
- }));
2
+ SessionHandler2
3
+ } from "../chunks/workerd-1c4qas2w.js";
4
+ import"../chunks/workerd-z5shrcz9.js";
5
+ import"../chunks/workerd-3kzx88w9.js";
6
+ import"../chunks/workerd-5rwqcaw2.js";
7
+ import"../chunks/workerd-6gkz39ey.js";
8
+ import"../chunks/workerd-smaf4a18.js";
9
+ export {
10
+ SessionHandler2 as SessionHandler
11
+ };
@@ -1,25 +1,11 @@
1
- import { Shell } from "@opencode/core/shell";
2
- import { Location } from "@opencode/core/location";
3
- import { Effect } from "effect";
4
- import { HttpApiBuilder, HttpApiSchema } from "effect/unstable/httpapi";
5
- import { ShellNotFoundError } from "@opencode/protocol/errors";
6
- import { Api } from "../api";
7
- import { response } from "../location";
8
- export const ShellHandler = HttpApiBuilder.group(Api, "server.shell", (handlers) => Effect.gen(function* () {
9
- return handlers.handle("shell.list", Effect.fn(function* () {
10
- const shell = yield* Shell.Service;
11
- return yield* response(shell.list());
12
- })).handle("shell.create", Effect.fn(function* (ctx) {
13
- const shell = yield* Shell.Service, location = yield* Location.Service;
14
- return yield* response(shell.create({ ...ctx.payload, cwd: ctx.payload.cwd || location.directory }).pipe(Effect.orDie));
15
- })).handle("shell.get", Effect.fn(function* (ctx) {
16
- const shell = yield* Shell.Service;
17
- return yield* response(shell.get(ctx.params.id).pipe(Effect.catchTag("Shell.NotFoundError", () => new ShellNotFoundError({ id: ctx.params.id, message: `Shell command not found: ${ctx.params.id}` }))));
18
- })).handle("shell.output", Effect.fn(function* (ctx) {
19
- const shell = yield* Shell.Service;
20
- return yield* response(shell.output(ctx.params.id, { cursor: ctx.query.cursor, limit: ctx.query.limit }).pipe(Effect.catchTag("Shell.NotFoundError", () => new ShellNotFoundError({ id: ctx.params.id, message: `Shell command not found: ${ctx.params.id}` }))));
21
- })).handle("shell.remove", Effect.fn(function* (ctx) {
22
- yield* (yield* Shell.Service).remove(ctx.params.id).pipe(Effect.catchTag("Shell.NotFoundError", () => Effect.void));
23
- return HttpApiSchema.NoContent.make();
24
- }));
25
- }));
1
+ import {
2
+ ShellHandler2
3
+ } from "../chunks/workerd-br99j6q1.js";
4
+ import"../chunks/workerd-z5shrcz9.js";
5
+ import"../chunks/workerd-3kzx88w9.js";
6
+ import"../chunks/workerd-5rwqcaw2.js";
7
+ import"../chunks/workerd-6gkz39ey.js";
8
+ import"../chunks/workerd-smaf4a18.js";
9
+ export {
10
+ ShellHandler2 as ShellHandler
11
+ };
@@ -1,5 +1,11 @@
1
- import { Skill } from "@opencode/core/skill";
2
- import { HttpApiBuilder } from "effect/unstable/httpapi";
3
- import { Api } from "../api";
4
- import { response } from "../location";
5
- export const SkillHandler = HttpApiBuilder.group(Api, "server.skill", (handlers) => handlers.handle("skill.list", () => response(Skill.Service.use((skill) => skill.list()))));
1
+ import {
2
+ SkillHandler2
3
+ } from "../chunks/workerd-q0ycym90.js";
4
+ import"../chunks/workerd-z5shrcz9.js";
5
+ import"../chunks/workerd-3kzx88w9.js";
6
+ import"../chunks/workerd-5rwqcaw2.js";
7
+ import"../chunks/workerd-6gkz39ey.js";
8
+ import"../chunks/workerd-smaf4a18.js";
9
+ export {
10
+ SkillHandler2 as SkillHandler
11
+ };