@opencode/server 0.0.0-dev-19795 → 0.0.0-dev-19812

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/process-172x6jgf.js +139 -0
  4. package/dist/chunks/process-18k6g42r.js +36 -0
  5. package/dist/chunks/process-1crq7hen.js +13 -0
  6. package/dist/chunks/process-27edjygf.js +33 -0
  7. package/dist/chunks/process-3esm6t0a.js +156 -0
  8. package/dist/chunks/process-3ra48t04.js +26 -0
  9. package/dist/chunks/process-8j6eh3dh.js +55 -0
  10. package/dist/chunks/process-910kejdj.js +37 -0
  11. package/dist/chunks/process-9rqn6x4v.js +16 -0
  12. package/dist/chunks/process-b0dj656z.js +13 -0
  13. package/dist/chunks/process-b4s3wxap.js +23 -0
  14. package/dist/chunks/process-c23ng5tp.js +17 -0
  15. package/dist/chunks/process-d0efjmp3.js +83 -0
  16. package/dist/chunks/process-d5nhwenp.js +22 -0
  17. package/dist/chunks/process-dhcrxjg3.js +163 -0
  18. package/dist/chunks/process-fa3dg36p.js +15 -0
  19. package/dist/chunks/process-gw2hwgqh.js +20 -0
  20. package/dist/chunks/process-h965rd83.js +25 -0
  21. package/dist/chunks/process-hezj1jdf.js +7 -0
  22. package/dist/chunks/process-j26nh0zz.js +40 -0
  23. package/dist/chunks/process-ja6yvede.js +22 -0
  24. package/dist/chunks/process-k319q0y1.js +39 -0
  25. package/dist/chunks/process-k8tgqrb7.js +61 -0
  26. package/dist/chunks/process-kadtbwy3.js +77 -0
  27. package/dist/chunks/process-kb9735wh.js +26 -0
  28. package/dist/chunks/process-kgbwhj3q.js +149 -0
  29. package/dist/chunks/process-kheky2r0.js +35 -0
  30. package/dist/chunks/process-knez9aqv.js +13 -0
  31. package/dist/chunks/process-ks9pc2xc.js +19 -0
  32. package/dist/chunks/process-m5dqr0xs.js +21 -0
  33. package/dist/chunks/process-m6wvgbfq.js +60 -0
  34. package/dist/chunks/process-m8y6333k.js +346 -0
  35. package/dist/chunks/process-mx2h5aqn.js +59 -0
  36. package/dist/chunks/process-prrj1pgd.js +42 -0
  37. package/dist/chunks/process-q4bn6dy8.js +39 -0
  38. package/dist/chunks/process-qc2xtz00.js +34 -0
  39. package/dist/chunks/process-qswqf30g.js +25 -0
  40. package/dist/chunks/process-rkdaz036.js +32 -0
  41. package/dist/chunks/process-smaf4a18.js +28 -0
  42. package/dist/chunks/process-t7k3q1ah.js +23 -0
  43. package/dist/chunks/process-t8yzmczr.js +18 -0
  44. package/dist/chunks/process-tp6dn9dc.js +99 -0
  45. package/dist/chunks/process-w0mvbrhx.js +22 -0
  46. package/dist/chunks/process-wt4btb09.js +13 -0
  47. package/dist/chunks/process-xettb16v.js +22 -0
  48. package/dist/chunks/process-xn1y01ws.js +29 -0
  49. package/dist/chunks/process-xsrtpxyd.js +23 -0
  50. package/dist/chunks/process-yc7nft6q.js +5 -0
  51. package/dist/chunks/process-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
@@ -0,0 +1,59 @@
1
+ import {
2
+ missingSession2,
3
+ failedMessageDecode2
4
+ } from "./process-smaf4a18.js";
5
+ import {
6
+ Api2
7
+ } from "./process-ks9pc2xc.js";
8
+
9
+ // src/handlers/message.ts
10
+ import { SessionMessage } from "@opencode/core/session/message";
11
+ import { Session } from "@opencode/core/session";
12
+ import { Effect, Schema } from "effect";
13
+ import { HttpApiBuilder } from "effect/unstable/httpapi";
14
+ import { InvalidCursorError } from "@opencode/protocol/errors";
15
+ var DefaultMessagesLimit = 50;
16
+ var Cursor = Schema.Struct({
17
+ id: SessionMessage.ID,
18
+ order: Schema.Union([Schema.Literal("asc"), Schema.Literal("desc")]),
19
+ direction: Schema.Union([Schema.Literal("previous"), Schema.Literal("next")])
20
+ });
21
+ var decodeCursor = Schema.decodeUnknownSync(Cursor);
22
+ var cursor = {
23
+ encode(message, order, direction) {
24
+ return Buffer.from(JSON.stringify({ id: message.id, order, direction })).toString("base64url");
25
+ },
26
+ decode(input) {
27
+ return decodeCursor(JSON.parse(Buffer.from(input, "base64url").toString("utf8")));
28
+ }
29
+ };
30
+ var MessageHandler2 = HttpApiBuilder.group(Api2, "server.message", (handlers) => Effect.gen(function* () {
31
+ const session = yield* Session.Service;
32
+ return handlers.handle("session.messages", Effect.fn(function* (ctx) {
33
+ if (ctx.query.cursor && ctx.query.order !== undefined)
34
+ return yield* new InvalidCursorError({ message: "Cursor cannot be combined with order" });
35
+ const decoded = yield* Effect.try({
36
+ try: () => ctx.query.cursor ? cursor.decode(ctx.query.cursor) : undefined,
37
+ catch: () => new InvalidCursorError({ message: "Invalid cursor" })
38
+ });
39
+ const order = decoded?.order ?? ctx.query.order ?? "desc";
40
+ const messages = yield* session.messages({
41
+ sessionID: ctx.params.sessionID,
42
+ limit: ctx.query.limit ?? DefaultMessagesLimit,
43
+ order,
44
+ type: ctx.query.type,
45
+ cursor: decoded ? { id: decoded.id, direction: decoded.direction } : undefined
46
+ }).pipe(Effect.catchTag("Session.NotFoundError", missingSession2), Effect.catchTag("Session.MessageDecodeError", failedMessageDecode2));
47
+ const first = messages[0];
48
+ const last = messages.at(-1);
49
+ return {
50
+ data: messages,
51
+ cursor: {
52
+ previous: first ? cursor.encode(first, order, "previous") : undefined,
53
+ next: last ? cursor.encode(last, order, "next") : undefined
54
+ }
55
+ };
56
+ }));
57
+ }));
58
+
59
+ export { MessageHandler2 };
@@ -0,0 +1,42 @@
1
+ import {
2
+ Api2
3
+ } from "./process-ks9pc2xc.js";
4
+
5
+ // src/handlers/worktree.ts
6
+ import { Git } from "@opencode/core/git";
7
+ import { Worktree } from "@opencode/core/worktree";
8
+ import { ProjectNotFoundError } from "@opencode/protocol/errors";
9
+ import { WorktreeError } from "@opencode/protocol/groups/worktree";
10
+ import { Effect } from "effect";
11
+ import { HttpApiBuilder, HttpApiSchema } from "effect/unstable/httpapi";
12
+ var WorktreeHandler2 = HttpApiBuilder.group(Api2, "server.worktree", (handlers) => Effect.gen(function* () {
13
+ const worktrees = yield* Worktree.Service;
14
+ return handlers.handle("worktree.list", (ctx) => worktrees.list(ctx.query).pipe(Effect.catchTag("Project.NotFoundError", missingProject))).handle("worktree.create", (ctx) => worktrees.create(ctx.payload).pipe(badRequest)).handle("worktree.remove", (ctx) => worktrees.remove(ctx.payload).pipe(badRequest, Effect.as(HttpApiSchema.NoContent.make()))).handle("worktree.refresh", (ctx) => worktrees.refresh(ctx.payload).pipe(badRequest, Effect.as(HttpApiSchema.NoContent.make())));
15
+ }));
16
+ function badRequest(effect) {
17
+ return effect.pipe(Effect.catchTag("Project.NotFoundError", missingProject), Effect.mapError((error) => error instanceof ProjectNotFoundError ? error : new WorktreeError({
18
+ name: "WorktreeError",
19
+ data: {
20
+ message: message(error),
21
+ forceRequired: error instanceof Git.WorktreeError || error instanceof Worktree.OperationError ? error.forceRequired : undefined
22
+ }
23
+ })));
24
+ }
25
+ function missingProject(error) {
26
+ return Effect.fail(new ProjectNotFoundError({ projectID: error.projectID, message: `Project not found: ${error.projectID}` }));
27
+ }
28
+ function message(error) {
29
+ if (error instanceof Worktree.SourceDirectoryNotFoundError)
30
+ return error.directory ? `Worktree source not found: ${error.directory}` : `Worktree source not found for project: ${error.projectID}`;
31
+ if (error instanceof Worktree.DestinationExistsError)
32
+ return `Worktree destination already exists: ${error.directory}`;
33
+ if (error instanceof Worktree.DirectoryUnavailableError)
34
+ return `Worktree directory unavailable: ${error.directory}`;
35
+ if (error instanceof Worktree.InvalidDirectoryError)
36
+ return `Invalid worktree directory: ${error.directory}`;
37
+ if (error instanceof Worktree.StrategyUnavailableError)
38
+ return `Worktree strategy unavailable: ${error.strategy}`;
39
+ return error.message;
40
+ }
41
+
42
+ export { WorktreeHandler2 };
@@ -0,0 +1,39 @@
1
+ // src/cors.ts
2
+ import { Context } from "effect";
3
+ var opencodeOrigin = /^https:\/\/([a-z0-9-]+\.)*opencode\.ai$/;
4
+ var CorsConfig2 = Context.Reference("@opencode/ServerCorsConfig", {
5
+ defaultValue: () => {
6
+ return;
7
+ }
8
+ });
9
+ function isAllowedCorsOrigin2(input, opts) {
10
+ if (!input)
11
+ return true;
12
+ if (input.startsWith("http://localhost:"))
13
+ return true;
14
+ if (input.startsWith("http://127.0.0.1:"))
15
+ return true;
16
+ if (input.startsWith("oc://renderer"))
17
+ return true;
18
+ if (input === "tauri://localhost" || input === "http://tauri.localhost" || input === "https://tauri.localhost")
19
+ return true;
20
+ if (opencodeOrigin.test(input))
21
+ return true;
22
+ return opts?.cors?.includes(input) ?? false;
23
+ }
24
+ function isAllowedRequestOrigin2(input, host, opts) {
25
+ if (!input)
26
+ return true;
27
+ if (host && sameHost(input, host))
28
+ return true;
29
+ return isAllowedCorsOrigin2(input, opts);
30
+ }
31
+ function sameHost(origin, host) {
32
+ try {
33
+ return new URL(origin).host === host;
34
+ } catch {
35
+ return false;
36
+ }
37
+ }
38
+
39
+ export { CorsConfig2, isAllowedCorsOrigin2, isAllowedRequestOrigin2 };
@@ -0,0 +1,34 @@
1
+ import {
2
+ response2
3
+ } from "./process-8j6eh3dh.js";
4
+ import {
5
+ Api2
6
+ } from "./process-ks9pc2xc.js";
7
+
8
+ // src/handlers/fs.ts
9
+ import { FileSystem } from "@opencode/core/filesystem";
10
+ import { RelativePath } from "@opencode/core/schema";
11
+ import { FileNotFoundError } from "@opencode/protocol/errors";
12
+ import { Effect } from "effect";
13
+ import { HttpServerResponse } from "effect/unstable/http";
14
+ import { HttpApiBuilder } from "effect/unstable/httpapi";
15
+ var FileSystemHandler2 = HttpApiBuilder.group(Api2, "server.fs", (handlers) => Effect.gen(function* () {
16
+ return handlers.handleRaw("fs.read", (ctx) => Effect.gen(function* () {
17
+ const fs = yield* FileSystem.Service;
18
+ const file = yield* fs.read({
19
+ path: RelativePath.make(decodeURIComponent(new URL(ctx.request.url, "http://localhost").pathname.slice(13)))
20
+ }).pipe(Effect.mapError((error) => new FileNotFoundError({ path: error.path, message: `File not found: ${error.path}` })));
21
+ return HttpServerResponse.uint8Array(file.content, { contentType: file.mime });
22
+ })).handle("fs.list", (ctx) => response2(Effect.gen(function* () {
23
+ const fs = yield* FileSystem.Service;
24
+ return yield* fs.list(ctx.query);
25
+ }))).handle("fs.find", (ctx) => response2(Effect.gen(function* () {
26
+ const fs = yield* FileSystem.Service;
27
+ return yield* fs.find(ctx.query);
28
+ }))).handle("fs.write", (ctx) => response2(Effect.gen(function* () {
29
+ const fs = yield* FileSystem.Service;
30
+ return yield* fs.write({ path: ctx.query.path, data: ctx.payload });
31
+ })));
32
+ }));
33
+
34
+ export { FileSystemHandler2 };
@@ -0,0 +1,25 @@
1
+ import {
2
+ response2
3
+ } from "./process-8j6eh3dh.js";
4
+ import {
5
+ Api2
6
+ } from "./process-ks9pc2xc.js";
7
+
8
+ // src/handlers/agent.ts
9
+ import { Agent } from "@opencode/core/agent";
10
+ import { Effect } from "effect";
11
+ import { HttpApiBuilder } from "effect/unstable/httpapi";
12
+ import { AgentNotFoundError } from "@opencode/protocol/errors";
13
+ var AgentHandler2 = HttpApiBuilder.group(Api2, "server.agent", (handlers) => handlers.handle("agent.list", () => Effect.gen(function* () {
14
+ return yield* response2(Agent.Service.use((agent) => agent.list()));
15
+ })).handle("agent.get", Effect.fn(function* (ctx) {
16
+ const agent = yield* Agent.Service.use((service) => service.get(ctx.params.agentID));
17
+ if (!agent)
18
+ return yield* new AgentNotFoundError({
19
+ agentID: ctx.params.agentID,
20
+ message: `Agent not found: ${ctx.params.agentID}`
21
+ });
22
+ return yield* response2(Effect.succeed(agent));
23
+ })));
24
+
25
+ export { AgentHandler2 };
@@ -0,0 +1,32 @@
1
+ import {
2
+ response2
3
+ } from "./process-8j6eh3dh.js";
4
+ import {
5
+ Api2
6
+ } from "./process-ks9pc2xc.js";
7
+
8
+ // src/handlers/vcs.ts
9
+ import { Vcs } from "@opencode/core/vcs";
10
+ import { ServiceUnavailableError } from "@opencode/protocol/errors";
11
+ import { Effect } from "effect";
12
+ import { HttpApiBuilder } from "effect/unstable/httpapi";
13
+ var VcsHandler2 = HttpApiBuilder.group(Api2, "server.vcs", (handlers) => Effect.gen(function* () {
14
+ return handlers.handle("vcs.get", () => response2(Effect.gen(function* () {
15
+ const vcs = yield* Vcs.Service;
16
+ return yield* vcs.info();
17
+ }))).handle("vcs.base", () => response2(Effect.gen(function* () {
18
+ const vcs = yield* Vcs.Service;
19
+ return yield* vcs.base().pipe(Effect.mapError((error) => new ServiceUnavailableError({ service: "vcs", message: error.message })));
20
+ }))).handle("vcs.status", () => response2(Effect.gen(function* () {
21
+ const vcs = yield* Vcs.Service;
22
+ return yield* vcs.status();
23
+ }))).handle("vcs.branch.list", (ctx) => response2(Effect.gen(function* () {
24
+ const vcs = yield* Vcs.Service;
25
+ return yield* vcs.branches({ search: ctx.query.search, limit: Math.min(ctx.query.limit ?? 50, 100) });
26
+ }))).handle("vcs.diff", (ctx) => response2(Effect.gen(function* () {
27
+ const vcs = yield* Vcs.Service;
28
+ return yield* vcs.diff(ctx.query.mode, { context: ctx.query.context, base: ctx.query.base }).pipe(Effect.mapError((error) => new ServiceUnavailableError({ service: "vcs", message: error.message })));
29
+ })));
30
+ }));
31
+
32
+ export { VcsHandler2 };
@@ -0,0 +1,28 @@
1
+ // src/handlers/session-error.ts
2
+ import { MessageNotFoundError, SessionNotFoundError, UnknownError } from "@opencode/protocol/errors";
3
+ import { Effect } from "effect";
4
+ function missingSession2(error) {
5
+ return new SessionNotFoundError({
6
+ sessionID: error.sessionID,
7
+ message: `Session not found: ${error.sessionID}`
8
+ });
9
+ }
10
+ function missingMessage2(error) {
11
+ return new MessageNotFoundError({
12
+ sessionID: error.sessionID,
13
+ messageID: error.messageID,
14
+ message: `Message not found: ${error.messageID}`
15
+ });
16
+ }
17
+ function failedMessageDecode2(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
+ function failedSnapshot2(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
+ }
27
+
28
+ export { missingSession2, missingMessage2, failedMessageDecode2, failedSnapshot2 };
@@ -0,0 +1,23 @@
1
+ import {
2
+ __export
3
+ } from "./process-9rqn6x4v.js";
4
+
5
+ // src/pty-environment.ts
6
+ var exports_pty_environment = {};
7
+ __export(exports_pty_environment, {
8
+ PtyEnvironment: () => exports_pty_environment,
9
+ Service: () => Service2,
10
+ layer: () => layer3,
11
+ node: () => node2
12
+ });
13
+ import { Context, Effect, Layer } from "effect";
14
+ import { makeGlobalNode } from "@opencode/util/effect/app-node";
15
+
16
+ class Service2 extends Context.Service()("@opencode/ServerPtyEnvironment") {
17
+ }
18
+ var layer3 = Layer.succeed(Service2, Service2.of({
19
+ get: () => Effect.succeed({})
20
+ }));
21
+ var node2 = makeGlobalNode({ service: Service2, layer: layer3, deps: [] });
22
+
23
+ export { Service2, layer3, node2, exports_pty_environment };
@@ -0,0 +1,18 @@
1
+ // src/middleware/schema-error.ts
2
+ import { Effect } from "effect";
3
+ import { HttpApiMiddleware } from "effect/unstable/httpapi";
4
+ import { InvalidRequestError } from "@opencode/protocol/errors";
5
+ import { SchemaErrorMiddleware } from "@opencode/protocol/middleware/schema-error";
6
+ import { SchemaErrorMiddleware as SchemaErrorMiddleware2 } from "@opencode/protocol/middleware/schema-error";
7
+ var REASON_LIMIT = 1024;
8
+ function truncateReason(reason) {
9
+ if (reason.length <= REASON_LIMIT)
10
+ return reason;
11
+ return reason.slice(0, REASON_LIMIT) + `... (${reason.length - REASON_LIMIT} more chars)`;
12
+ }
13
+ var schemaErrorLayer2 = HttpApiMiddleware.layerSchemaErrorTransform(SchemaErrorMiddleware, (error) => {
14
+ const reason = truncateReason(error.cause.message);
15
+ return Effect.logWarning("schema rejection").pipe(Effect.annotateLogs({ kind: error.kind, reason }), Effect.andThen(Effect.fail(new InvalidRequestError({ message: reason, kind: error.kind }))));
16
+ });
17
+
18
+ export { schemaErrorLayer2, SchemaErrorMiddleware2 };
@@ -0,0 +1,99 @@
1
+ import {
2
+ GenerateHandler2
3
+ } from "./process-h965rd83.js";
4
+ import {
5
+ MessageHandler2
6
+ } from "./process-mx2h5aqn.js";
7
+ import {
8
+ ModelHandler2
9
+ } from "./process-d5nhwenp.js";
10
+ import {
11
+ ProviderHandler2
12
+ } from "./process-xn1y01ws.js";
13
+ import {
14
+ SessionHandler2
15
+ } from "./process-m8y6333k.js";
16
+ import {
17
+ PermissionHandler2
18
+ } from "./process-kadtbwy3.js";
19
+ import {
20
+ FileSystemHandler2
21
+ } from "./process-qc2xtz00.js";
22
+ import {
23
+ FormHandler2
24
+ } from "./process-c23ng5tp.js";
25
+ import {
26
+ CommandHandler2
27
+ } from "./process-1crq7hen.js";
28
+ import {
29
+ SkillHandler2
30
+ } from "./process-wt4btb09.js";
31
+ import {
32
+ RpcHandler2
33
+ } from "./process-xettb16v.js";
34
+ import {
35
+ layer4
36
+ } from "./process-d0efjmp3.js";
37
+ import {
38
+ EventHandler2
39
+ } from "./process-910kejdj.js";
40
+ import {
41
+ AgentHandler2
42
+ } from "./process-qswqf30g.js";
43
+ import {
44
+ PluginHandler2
45
+ } from "./process-k8tgqrb7.js";
46
+ import {
47
+ ServerHandler2
48
+ } from "./process-m5dqr0xs.js";
49
+ import {
50
+ DebugHandler2
51
+ } from "./process-gw2hwgqh.js";
52
+ import {
53
+ PtyHandler2
54
+ } from "./process-172x6jgf.js";
55
+ import {
56
+ PersistentPtyHandler2
57
+ } from "./process-dhcrxjg3.js";
58
+ import {
59
+ ShellHandler2
60
+ } from "./process-kheky2r0.js";
61
+ import {
62
+ ReferenceHandler2
63
+ } from "./process-b0dj656z.js";
64
+ import {
65
+ LocationHandler2
66
+ } from "./process-ja6yvede.js";
67
+ import {
68
+ IntegrationHandler2
69
+ } from "./process-3esm6t0a.js";
70
+ import {
71
+ WebSearchHandler2
72
+ } from "./process-k319q0y1.js";
73
+ import {
74
+ McpHandler2
75
+ } from "./process-j26nh0zz.js";
76
+ import {
77
+ CredentialHandler2
78
+ } from "./process-b4s3wxap.js";
79
+ import {
80
+ ProjectHandler2
81
+ } from "./process-fa3dg36p.js";
82
+ import {
83
+ WorktreeHandler2
84
+ } from "./process-prrj1pgd.js";
85
+ import {
86
+ VcsHandler2
87
+ } from "./process-rkdaz036.js";
88
+ import {
89
+ MigrationHandler2
90
+ } from "./process-knez9aqv.js";
91
+ import {
92
+ ConfigHandler2
93
+ } from "./process-w0mvbrhx.js";
94
+
95
+ // src/handlers.ts
96
+ import { Layer } from "effect";
97
+ var handlers2 = Layer.mergeAll(ServerHandler2, DebugHandler2, MigrationHandler2, LocationHandler2, AgentHandler2, PluginHandler2, SessionHandler2, MessageHandler2, ModelHandler2, GenerateHandler2, ProviderHandler2, IntegrationHandler2, WebSearchHandler2, McpHandler2, CredentialHandler2, ProjectHandler2, FormHandler2, PermissionHandler2, FileSystemHandler2, CommandHandler2, SkillHandler2, RpcHandler2, EventHandler2.pipe(Layer.provide(layer4)), PtyHandler2, PersistentPtyHandler2, ShellHandler2, ReferenceHandler2, WorktreeHandler2, VcsHandler2, ConfigHandler2);
98
+
99
+ export { handlers2 };
@@ -0,0 +1,22 @@
1
+ import {
2
+ Api2
3
+ } from "./process-ks9pc2xc.js";
4
+
5
+ // src/handlers/config.ts
6
+ import { Config } from "@opencode/core/config";
7
+ import { ShellSelect } from "@opencode/core/shell/select";
8
+ import { Effect } from "effect";
9
+ import { HttpApiBuilder } from "effect/unstable/httpapi";
10
+ var ConfigHandler2 = HttpApiBuilder.group(Api2, "server.config", (handlers) => handlers.handle("config.get", () => Config.Service.use((config) => config.entries())).handle("config.update", Effect.fn(function* (ctx) {
11
+ const config = yield* Config.Service;
12
+ if (!config.update)
13
+ return yield* Effect.die(new Error("Config updates are unavailable"));
14
+ return yield* config.update(ctx.payload).pipe(Effect.orDie);
15
+ })).handle("config.shells", Effect.fn(function* () {
16
+ const shell = yield* ShellSelect.Service;
17
+ if (!shell.list)
18
+ return yield* Effect.die(new Error("Shell discovery is unavailable"));
19
+ return yield* shell.list();
20
+ })));
21
+
22
+ export { ConfigHandler2 };
@@ -0,0 +1,13 @@
1
+ import {
2
+ response2
3
+ } from "./process-8j6eh3dh.js";
4
+ import {
5
+ Api2
6
+ } from "./process-ks9pc2xc.js";
7
+
8
+ // src/handlers/skill.ts
9
+ import { Skill } from "@opencode/core/skill";
10
+ import { HttpApiBuilder } from "effect/unstable/httpapi";
11
+ var SkillHandler2 = HttpApiBuilder.group(Api2, "server.skill", (handlers) => handlers.handle("skill.list", () => response2(Skill.Service.use((skill) => skill.list()))));
12
+
13
+ export { SkillHandler2 };
@@ -0,0 +1,22 @@
1
+ import {
2
+ Api2
3
+ } from "./process-ks9pc2xc.js";
4
+
5
+ // src/handlers/rpc.ts
6
+ import { Rpc } from "@opencode/core/rpc";
7
+ import { Plugin } from "@opencode/core/plugin";
8
+ import { RpcError, RpcInternalError } from "@opencode/protocol/errors";
9
+ import { Effect } from "effect";
10
+ import { HttpApiBuilder } from "effect/unstable/httpapi";
11
+ var RpcHandler2 = HttpApiBuilder.group(Api2, "server.rpc", (handlers) => handlers.handle("rpc.call", ({ params, payload }) => Effect.gen(function* () {
12
+ yield* Plugin.awaitActivation;
13
+ const rpc = yield* Rpc.Service;
14
+ const output = yield* rpc.call(params.rpcID, params.method, payload.input);
15
+ return output === undefined ? {} : { output };
16
+ }).pipe(Effect.mapError((error) => error.type === "rpc.invalid_output" || error.type === "rpc.internal" ? new RpcInternalError({ type: error.type, message: error.message }) : new RpcError({
17
+ type: error.type,
18
+ message: error.message,
19
+ ...error.data === undefined ? {} : { data: error.data }
20
+ })), 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" }))))))));
21
+
22
+ export { RpcHandler2 };
@@ -0,0 +1,29 @@
1
+ import {
2
+ response2
3
+ } from "./process-8j6eh3dh.js";
4
+ import {
5
+ Api2
6
+ } from "./process-ks9pc2xc.js";
7
+
8
+ // src/handlers/provider.ts
9
+ import { Provider } from "@opencode/core/provider";
10
+ import { ProviderNotFoundError } from "@opencode/protocol/errors";
11
+ import { Effect } from "effect";
12
+ import { HttpApiBuilder } from "effect/unstable/httpapi";
13
+ var ProviderHandler2 = HttpApiBuilder.group(Api2, "server.provider", (handlers) => Effect.gen(function* () {
14
+ return handlers.handle("provider.list", Effect.fn(function* () {
15
+ const providers = yield* Provider.Service;
16
+ return yield* response2(providers.available());
17
+ })).handle("provider.get", Effect.fn(function* (ctx) {
18
+ const providers = yield* Provider.Service;
19
+ const provider = yield* providers.get(ctx.params.providerID);
20
+ if (!provider)
21
+ return yield* new ProviderNotFoundError({
22
+ providerID: ctx.params.providerID,
23
+ message: `Provider not found: ${ctx.params.providerID}`
24
+ });
25
+ return yield* response2(Effect.succeed(provider));
26
+ }));
27
+ }));
28
+
29
+ export { ProviderHandler2 };
@@ -0,0 +1,23 @@
1
+ import {
2
+ __export
3
+ } from "./process-9rqn6x4v.js";
4
+
5
+ // src/service-status.ts
6
+ var exports_service_status = {};
7
+ __export(exports_service_status, {
8
+ Status: () => exports_service_status,
9
+ make: () => make2
10
+ });
11
+ import { Effect, Ref } from "effect";
12
+ var make2 = Effect.fnUntraced(function* (options = {}) {
13
+ const current = yield* Ref.make(options.initial ?? { type: "starting" });
14
+ const beginStopping = Ref.update(current, (status) => status.type === "stopping" ? status : { type: "stopping" });
15
+ return {
16
+ current: Ref.get(current),
17
+ ready: Ref.update(current, (status) => status.type === "starting" ? { type: "ready" } : status),
18
+ fail: Ref.update(current, (status) => status.type === "starting" ? { type: "failed" } : status),
19
+ beginStopping
20
+ };
21
+ });
22
+
23
+ export { make2, exports_service_status };
@@ -0,0 +1,5 @@
1
+ // src/request-tracing.ts
2
+ import { Context, Effect, Tracer } from "effect";
3
+ var withoutParentSpan2 = (effect) => effect.pipe(Effect.updateContext((context) => Context.omit(Tracer.ParentSpan)(context)));
4
+
5
+ export { withoutParentSpan2 };
@@ -0,0 +1,30 @@
1
+ import {
2
+ __export
3
+ } from "./process-9rqn6x4v.js";
4
+
5
+ // src/auth.ts
6
+ var exports_auth = {};
7
+ __export(exports_auth, {
8
+ Config: () => Config2,
9
+ ServerAuth: () => exports_auth,
10
+ authorized: () => authorized2,
11
+ required: () => required2
12
+ });
13
+ import { Context, Layer, Option, Redacted } from "effect";
14
+
15
+ class Config2 extends Context.Service()("@opencode/ServerAuthConfig") {
16
+ static configLayer(input) {
17
+ return Layer.succeed(this, this.of({ ...input, username: "opencode" }));
18
+ }
19
+ static get layer() {
20
+ return this.configLayer({ password: Option.none() });
21
+ }
22
+ }
23
+ function required2(config) {
24
+ return Option.isSome(config.password) && config.password.value !== "";
25
+ }
26
+ function authorized2(credentials, config) {
27
+ return Option.isSome(config.password) && credentials.username === config.username && Redacted.value(credentials.password) === config.password.value;
28
+ }
29
+
30
+ export { Config2, required2, authorized2, exports_auth };
package/dist/cors.js CHANGED
@@ -1,36 +1,10 @@
1
- import { Context } from "effect";
2
- const opencodeOrigin = /^https:\/\/([a-z0-9-]+\.)*opencode\.ai$/;
3
- export const CorsConfig = Context.Reference("@opencode/ServerCorsConfig", {
4
- defaultValue: () => {
5
- return;
6
- }
7
- });
8
- export function isAllowedCorsOrigin(input, opts) {
9
- if (!input)
10
- return !0;
11
- if (input.startsWith("http://localhost:"))
12
- return !0;
13
- if (input.startsWith("http://127.0.0.1:"))
14
- return !0;
15
- if (input.startsWith("oc://renderer"))
16
- return !0;
17
- if (input === "tauri://localhost" || input === "http://tauri.localhost" || input === "https://tauri.localhost")
18
- return !0;
19
- if (opencodeOrigin.test(input))
20
- return !0;
21
- return opts?.cors?.includes(input) ?? !1;
22
- }
23
- export function isAllowedRequestOrigin(input, host, opts) {
24
- if (!input)
25
- return !0;
26
- if (host && sameHost(input, host))
27
- return !0;
28
- return isAllowedCorsOrigin(input, opts);
29
- }
30
- function sameHost(origin, host) {
31
- try {
32
- return new URL(origin).host === host;
33
- } catch {
34
- return !1;
35
- }
36
- }
1
+ import {
2
+ CorsConfig2,
3
+ isAllowedCorsOrigin2,
4
+ isAllowedRequestOrigin2
5
+ } from "./chunks/process-q4bn6dy8.js";
6
+ export {
7
+ CorsConfig2 as CorsConfig,
8
+ isAllowedCorsOrigin2 as isAllowedCorsOrigin,
9
+ isAllowedRequestOrigin2 as isAllowedRequestOrigin
10
+ };