@opencode/server 2.0.8 → 2.0.9

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 (104) hide show
  1. package/dist/api.d.ts +4 -4
  2. package/dist/api.js +10 -9
  3. package/dist/auth.js +12 -17
  4. package/dist/chunks/fetch-00nn3k4b.js +20 -0
  5. package/dist/chunks/fetch-04xw3v55.js +23 -0
  6. package/dist/chunks/fetch-0d9kah4z.js +23 -0
  7. package/dist/chunks/fetch-19c9ysa1.js +61 -0
  8. package/dist/chunks/fetch-1c4qas2w.js +346 -0
  9. package/dist/chunks/fetch-254zvkj6.js +22 -0
  10. package/dist/chunks/fetch-3kzx88w9.js +26 -0
  11. package/dist/chunks/fetch-4cf3x1kw.js +21 -0
  12. package/dist/chunks/fetch-4g0fa6m0.js +32 -0
  13. package/dist/chunks/fetch-4vn5bvkr.js +25 -0
  14. package/dist/chunks/fetch-5rwqcaw2.js +33 -0
  15. package/dist/chunks/fetch-6gkz39ey.js +55 -0
  16. package/dist/chunks/fetch-6nvan4e0.js +17 -0
  17. package/dist/chunks/fetch-7rzt3wm8.js +13 -0
  18. package/dist/chunks/fetch-8bajbwjh.js +40 -0
  19. package/dist/chunks/fetch-99sfd1j8.js +83 -0
  20. package/dist/chunks/fetch-9rqn6x4v.js +16 -0
  21. package/dist/chunks/fetch-a6yp8301.js +156 -0
  22. package/dist/chunks/fetch-arj41x43.js +77 -0
  23. package/dist/chunks/fetch-b0b71rwa.js +39 -0
  24. package/dist/chunks/fetch-bjrwanme.js +22 -0
  25. package/dist/chunks/fetch-br99j6q1.js +35 -0
  26. package/dist/chunks/fetch-ceh2h0m9.js +25 -0
  27. package/dist/chunks/fetch-csspsf0t.js +99 -0
  28. package/dist/chunks/fetch-d4bshj6j.js +37 -0
  29. package/dist/chunks/fetch-hezj1jdf.js +7 -0
  30. package/dist/chunks/fetch-hjnxtxmk.js +34 -0
  31. package/dist/chunks/fetch-j2pfq4q6.js +42 -0
  32. package/dist/chunks/fetch-m6wvgbfq.js +60 -0
  33. package/dist/chunks/fetch-n0er2m55.js +163 -0
  34. package/dist/chunks/fetch-pnqq1zxv.js +29 -0
  35. package/dist/chunks/fetch-q0ycym90.js +13 -0
  36. package/dist/chunks/fetch-q4bn6dy8.js +39 -0
  37. package/dist/chunks/fetch-qm92ga5h.js +26 -0
  38. package/dist/chunks/fetch-qnwpcgp7.js +22 -0
  39. package/dist/chunks/fetch-r7e9r02j.js +13 -0
  40. package/dist/chunks/fetch-rcg4y18n.js +59 -0
  41. package/dist/chunks/fetch-req22b70.js +22 -0
  42. package/dist/chunks/fetch-s4aja1df.js +36 -0
  43. package/dist/chunks/fetch-smaf4a18.js +28 -0
  44. package/dist/chunks/fetch-t8yzmczr.js +18 -0
  45. package/dist/chunks/fetch-vgpejxxy.js +149 -0
  46. package/dist/chunks/fetch-xsrtpxyd.js +23 -0
  47. package/dist/chunks/fetch-yc7nft6q.js +5 -0
  48. package/dist/chunks/fetch-ychamt23.js +139 -0
  49. package/dist/chunks/fetch-ysabas57.js +13 -0
  50. package/dist/chunks/fetch-z5shrcz9.js +19 -0
  51. package/dist/chunks/fetch-zp2jm6dt.js +15 -0
  52. package/dist/chunks/fetch-zyv89x5n.js +30 -0
  53. package/dist/cors.js +10 -36
  54. package/dist/event-feed.js +20 -60
  55. package/dist/fetch.js +53 -11
  56. package/dist/handlers/agent.js +11 -17
  57. package/dist/handlers/command.js +11 -5
  58. package/dist/handlers/config.js +11 -16
  59. package/dist/handlers/credential.js +11 -14
  60. package/dist/handlers/debug.js +11 -11
  61. package/dist/handlers/event.js +12 -27
  62. package/dist/handlers/form.js +11 -9
  63. package/dist/handlers/fs.js +11 -22
  64. package/dist/handlers/generate.js +11 -15
  65. package/dist/handlers/integration.js +10 -142
  66. package/dist/handlers/location.js +11 -16
  67. package/dist/handlers/mcp.js +11 -31
  68. package/dist/handlers/message.js +10 -42
  69. package/dist/handlers/migration.js +11 -7
  70. package/dist/handlers/model.js +11 -14
  71. package/dist/handlers/permission.js +11 -57
  72. package/dist/handlers/persistent-pty.js +12 -135
  73. package/dist/handlers/plugin.js +11 -47
  74. package/dist/handlers/project.js +11 -9
  75. package/dist/handlers/provider.js +11 -20
  76. package/dist/handlers/pty-socket.js +6 -4
  77. package/dist/handlers/pty.js +13 -107
  78. package/dist/handlers/reference.js +11 -5
  79. package/dist/handlers/rpc.js +11 -15
  80. package/dist/handlers/server.js +12 -13
  81. package/dist/handlers/session-error.js +12 -26
  82. package/dist/handlers/session.js +10 -311
  83. package/dist/handlers/shell.js +11 -25
  84. package/dist/handlers/skill.js +11 -5
  85. package/dist/handlers/vcs.js +11 -19
  86. package/dist/handlers/websearch.js +11 -31
  87. package/dist/handlers/worktree.js +11 -37
  88. package/dist/handlers.d.ts +1 -1
  89. package/dist/handlers.js +46 -33
  90. package/dist/location.js +15 -49
  91. package/dist/middleware/authorization.js +11 -49
  92. package/dist/middleware/form-location.js +10 -25
  93. package/dist/middleware/schema-error.js +8 -15
  94. package/dist/middleware/session-location.js +10 -19
  95. package/dist/options.js +5 -1
  96. package/dist/process.js +108 -28
  97. package/dist/pty-environment.js +12 -9
  98. package/dist/request-tracing.js +6 -2
  99. package/dist/routes.d.ts +2 -2
  100. package/dist/routes.js +52 -118
  101. package/dist/server-info.js +12 -22
  102. package/dist/service-status.js +8 -11
  103. package/dist/workerd.js +80 -12
  104. package/package.json +8 -8
@@ -0,0 +1,32 @@
1
+ import {
2
+ response2
3
+ } from "./fetch-6gkz39ey.js";
4
+ import {
5
+ Api2
6
+ } from "./fetch-z5shrcz9.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,25 @@
1
+ import {
2
+ Api2
3
+ } from "./fetch-z5shrcz9.js";
4
+
5
+ // src/handlers/generate.ts
6
+ import { Generate } from "@opencode/core/generate";
7
+ import { Location } from "@opencode/core/location";
8
+ import { LocationServiceMap } from "@opencode/core/location-services";
9
+ import { AbsolutePath } from "@opencode/core/schema";
10
+ import { InvalidRequestError, ServiceUnavailableError } from "@opencode/protocol/errors";
11
+ import { Global } from "@opencode/util/global";
12
+ import { Effect } from "effect";
13
+ import { HttpApiBuilder } from "effect/unstable/httpapi";
14
+ var GenerateHandler2 = HttpApiBuilder.group(Api2, "server.generate", (handlers) => Effect.gen(function* () {
15
+ const global = yield* Global.Service;
16
+ const locations = yield* LocationServiceMap.Service;
17
+ const services = locations.get(Location.Ref.make({ directory: AbsolutePath.make(global.config) }));
18
+ return handlers.handle("generate.text", Effect.fn("server.generate.text")(function* (request) {
19
+ const generate = yield* Generate.Service;
20
+ const text = yield* generate.text(request.payload).pipe(Effect.mapError((error) => error._tag === "Generate.ModelSelectionError" ? new InvalidRequestError({ message: error.message }) : new ServiceUnavailableError({ message: error.message, service: error.service })));
21
+ return { data: { text } };
22
+ }, Effect.provide(services)));
23
+ }));
24
+
25
+ export { GenerateHandler2 };
@@ -0,0 +1,33 @@
1
+ import {
2
+ sessionInfo2,
3
+ requestRef2
4
+ } from "./fetch-6gkz39ey.js";
5
+
6
+ // src/middleware/form-location.ts
7
+ import { Instance } from "@opencode/core/instance/service";
8
+ import { LocationServiceMap } from "@opencode/core/location-services";
9
+ import { Session } from "@opencode/core/session";
10
+ import { InvalidRequestError, SessionNotFoundError } from "@opencode/protocol/errors";
11
+ import { Effect, Layer } from "effect";
12
+ import { HttpRouter, HttpServerRequest } from "effect/unstable/http";
13
+ import { HttpApiMiddleware } from "effect/unstable/httpapi";
14
+ class FormLocationMiddleware2 extends HttpApiMiddleware.Service()("@opencode/HttpApiFormLocation", {
15
+ error: [InvalidRequestError, SessionNotFoundError]
16
+ }) {
17
+ }
18
+ var formLocationLayer2 = Layer.effect(FormLocationMiddleware2, Effect.gen(function* () {
19
+ const sessions = yield* Session.Service;
20
+ const instances = yield* Instance.Service;
21
+ const locations = yield* LocationServiceMap.Service;
22
+ return FormLocationMiddleware2.of((effect) => Effect.gen(function* () {
23
+ const route = yield* HttpRouter.RouteContext;
24
+ if (route.params.sessionID === "global") {
25
+ const request = yield* HttpServerRequest.HttpServerRequest;
26
+ return yield* effect.pipe(Effect.provide(locations.get(requestRef2(request))));
27
+ }
28
+ const session = yield* sessionInfo2(sessions, route.params.sessionID);
29
+ return yield* effect.pipe(instances.provide(session));
30
+ }));
31
+ }));
32
+
33
+ export { FormLocationMiddleware2, formLocationLayer2 };
@@ -0,0 +1,55 @@
1
+ import {
2
+ missingSession2
3
+ } from "./fetch-smaf4a18.js";
4
+
5
+ // src/location.ts
6
+ import { Location } from "@opencode/core/location";
7
+ import { LocationServiceMap } from "@opencode/core/location-services";
8
+ import { AbsolutePath } from "@opencode/core/schema";
9
+ import { Session } from "@opencode/core/session";
10
+ import { InvalidRequestError } from "@opencode/protocol/errors";
11
+ import { Effect, Layer, Schema } from "effect";
12
+ import { HttpServerRequest } from "effect/unstable/http";
13
+ import { HttpApiMiddleware } from "effect/unstable/httpapi";
14
+ class LocationMiddleware2 extends HttpApiMiddleware.Service()("@opencode/HttpApiLocation") {
15
+ }
16
+ function response2(data) {
17
+ return Effect.gen(function* () {
18
+ const location = yield* Location.Service;
19
+ return {
20
+ location: new Location.Info({
21
+ directory: location.directory,
22
+ project: location.project
23
+ }),
24
+ data: yield* data
25
+ };
26
+ });
27
+ }
28
+ var decodeSessionID = Schema.decodeUnknownEffect(Session.ID);
29
+ var sessionInfo2 = Effect.fnUntraced(function* (sessions, sessionID) {
30
+ const id = yield* decodeSessionID(sessionID).pipe(Effect.mapError(() => new InvalidRequestError({ message: "Invalid session ID", field: "sessionID" })));
31
+ return yield* sessions.get(id).pipe(Effect.catchTag("Session.NotFoundError", missingSession2));
32
+ });
33
+ function requestRef2(request) {
34
+ const query = new URL(request.url, "http://localhost").searchParams;
35
+ const directory = query.get("location[directory]") || (request.headers["x-opencode-directory"] ? decode(request.headers["x-opencode-directory"]) : process.cwd());
36
+ return Location.Ref.make({
37
+ directory: AbsolutePath.make(directory)
38
+ });
39
+ }
40
+ function decode(input) {
41
+ try {
42
+ return decodeURIComponent(input);
43
+ } catch {
44
+ return input;
45
+ }
46
+ }
47
+ var layer4 = Layer.effect(LocationMiddleware2, Effect.gen(function* () {
48
+ const locations = yield* LocationServiceMap.Service;
49
+ return LocationMiddleware2.of((effect) => Effect.gen(function* () {
50
+ const request = yield* HttpServerRequest.HttpServerRequest;
51
+ return yield* effect.pipe(Effect.provide(locations.get(requestRef2(request))));
52
+ }));
53
+ }));
54
+
55
+ export { LocationMiddleware2, response2, sessionInfo2, requestRef2, layer4 };
@@ -0,0 +1,17 @@
1
+ import {
2
+ response2
3
+ } from "./fetch-6gkz39ey.js";
4
+ import {
5
+ Api2
6
+ } from "./fetch-z5shrcz9.js";
7
+
8
+ // src/handlers/form.ts
9
+ import { Form } from "@opencode/core/form";
10
+ import { Effect } from "effect";
11
+ import { HttpApiBuilder } from "effect/unstable/httpapi";
12
+ var FormHandler2 = HttpApiBuilder.group(Api2, "server.form", (handlers) => handlers.handle("form.list", Effect.fn(function* () {
13
+ const form = yield* Form.Service;
14
+ return yield* response2(form.list());
15
+ })));
16
+
17
+ export { FormHandler2 };
@@ -0,0 +1,13 @@
1
+ import {
2
+ Api2
3
+ } from "./fetch-z5shrcz9.js";
4
+
5
+ // src/handlers/migration.ts
6
+ import { V1Migration } from "@opencode/core/database/v1-migration";
7
+ import { HttpApiBuilder } from "effect/unstable/httpapi";
8
+ import { Effect } from "effect";
9
+ var MigrationHandler2 = HttpApiBuilder.group(Api2, "server.migration", (handlers) => handlers.handle("migration.v1.status", Effect.fn(function* () {
10
+ return yield* V1Migration.status();
11
+ })));
12
+
13
+ export { MigrationHandler2 };
@@ -0,0 +1,40 @@
1
+ import {
2
+ response2
3
+ } from "./fetch-6gkz39ey.js";
4
+ import {
5
+ Api2
6
+ } from "./fetch-z5shrcz9.js";
7
+
8
+ // src/handlers/mcp.ts
9
+ import { Mcp } from "@opencode/core/mcp/index";
10
+ import { McpServerNotFoundError } from "@opencode/protocol/errors";
11
+ import { Effect } from "effect";
12
+ import { HttpApiBuilder, HttpApiSchema } from "effect/unstable/httpapi";
13
+ var notFound = (effect) => effect.pipe(Effect.mapError((error) => new McpServerNotFoundError({ server: error.server, message: error.message })));
14
+ var McpHandler2 = HttpApiBuilder.group(Api2, "server.mcp", (handlers) => Effect.gen(function* () {
15
+ return handlers.handle("mcp.list", Effect.fn(function* () {
16
+ const service = yield* Mcp.Service;
17
+ return yield* response2(service.servers().pipe(Effect.map((servers) => servers.map((info) => ({ name: info.name, status: info.status, integrationID: info.integrationID })))));
18
+ })).handle("mcp.add", Effect.fn(function* (ctx) {
19
+ const service = yield* Mcp.Service;
20
+ yield* service.add(ctx.params.server, ctx.payload.config);
21
+ return HttpApiSchema.NoContent.make();
22
+ })).handle("mcp.remove", Effect.fn(function* (ctx) {
23
+ const service = yield* Mcp.Service;
24
+ yield* notFound(service.remove(ctx.params.server));
25
+ return HttpApiSchema.NoContent.make();
26
+ })).handle("mcp.connect", Effect.fn(function* (ctx) {
27
+ const service = yield* Mcp.Service;
28
+ yield* notFound(service.connect(ctx.params.server));
29
+ return HttpApiSchema.NoContent.make();
30
+ })).handle("mcp.disconnect", Effect.fn(function* (ctx) {
31
+ const service = yield* Mcp.Service;
32
+ yield* notFound(service.disconnect(ctx.params.server));
33
+ return HttpApiSchema.NoContent.make();
34
+ })).handle("mcp.resource.catalog", Effect.fn(function* () {
35
+ const service = yield* Mcp.Service;
36
+ return yield* response2(service.resourceCatalog());
37
+ }));
38
+ }));
39
+
40
+ export { McpHandler2 };
@@ -0,0 +1,83 @@
1
+ import {
2
+ __export
3
+ } from "./fetch-9rqn6x4v.js";
4
+
5
+ // src/event-feed.ts
6
+ var exports_event_feed = {};
7
+ __export(exports_event_feed, {
8
+ EncodingError: () => EncodingError2,
9
+ EventFeed: () => exports_event_feed,
10
+ Service: () => Service4,
11
+ SubscriberCapacity: () => SubscriberCapacity2,
12
+ SubscriberOverflowError: () => SubscriberOverflowError2,
13
+ frame: () => frame2,
14
+ layer: () => layer5,
15
+ make: () => make4
16
+ });
17
+ import { Bus } from "@opencode/core/bus";
18
+ import { Event } from "@opencode/schema/event";
19
+ import { isOpenCodeEvent } from "@opencode/protocol/groups/event";
20
+ import { Cause, Context, Effect, Layer, Queue, Schema, Stream } from "effect";
21
+ var SubscriberCapacity2 = 4096;
22
+
23
+ class SubscriberOverflowError2 extends Schema.TaggedError()("EventFeed.SubscriberOverflow", { capacity: Schema.Int }) {
24
+ }
25
+
26
+ class EncodingError2 extends Schema.TaggedError()("EventFeed.EncodingError", {
27
+ eventID: Event.ID,
28
+ eventType: Schema.String,
29
+ cause: Schema.Defect()
30
+ }) {
31
+ }
32
+
33
+ class Service4 extends Context.Service()("@opencode/server/EventFeed") {
34
+ }
35
+ function frame2(event) {
36
+ return `data: ${JSON.stringify(event)}
37
+
38
+ `;
39
+ }
40
+ var make4 = Effect.fn("EventFeed.make")(function* (observe, options) {
41
+ const capacity = options?.capacity ?? SubscriberCapacity2;
42
+ const render = options?.encode ?? frame2;
43
+ const subscribers = new Set;
44
+ const fail = (error) => Effect.sync(() => {
45
+ const current = Array.from(subscribers);
46
+ subscribers.clear();
47
+ for (const subscriber of current)
48
+ Queue.failCauseUnsafe(subscriber, Cause.fail(error));
49
+ });
50
+ const publish = Effect.fnUntraced(function* (event) {
51
+ if (!isOpenCodeEvent(event))
52
+ return;
53
+ if (subscribers.size === 0)
54
+ return;
55
+ const encoded = yield* Effect.try({
56
+ try: () => render(event),
57
+ catch: (cause) => new EncodingError2({ eventID: event.id, eventType: event.type, cause })
58
+ }).pipe(Effect.catch((error) => Effect.logError("Failed to encode public event", {
59
+ eventID: error.eventID,
60
+ eventType: error.eventType,
61
+ cause: error.cause
62
+ }).pipe(Effect.andThen(fail(error)), Effect.as(undefined))));
63
+ if (encoded === undefined)
64
+ return;
65
+ for (const subscriber of subscribers) {
66
+ if (Queue.offerUnsafe(subscriber, encoded))
67
+ continue;
68
+ subscribers.delete(subscriber);
69
+ Queue.failCauseUnsafe(subscriber, Cause.fail(new SubscriberOverflowError2({ capacity })));
70
+ }
71
+ });
72
+ const unsubscribe = yield* observe(publish);
73
+ yield* Effect.addFinalizer(() => unsubscribe);
74
+ return Service4.of({
75
+ subscribe: Effect.acquireRelease(Queue.dropping(capacity).pipe(Effect.tap((queue) => Effect.sync(() => subscribers.add(queue)))), (queue) => Effect.sync(() => subscribers.delete(queue)).pipe(Effect.andThen(Queue.shutdown(queue)), Effect.asVoid)).pipe(Effect.map(Stream.fromQueue))
76
+ });
77
+ });
78
+ var layer5 = Layer.effect(Service4, Effect.gen(function* () {
79
+ const bus = yield* Bus.Service;
80
+ return yield* make4(bus.listen);
81
+ }));
82
+
83
+ export { SubscriberCapacity2, SubscriberOverflowError2, EncodingError2, Service4, frame2, make4, layer5, exports_event_feed };
@@ -0,0 +1,16 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __returnValue = (v) => v;
3
+ function __exportSetter(name, newValue) {
4
+ this[name] = __returnValue.bind(null, newValue);
5
+ }
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, {
9
+ get: all[name],
10
+ enumerable: true,
11
+ configurable: true,
12
+ set: __exportSetter.bind(all, name)
13
+ });
14
+ };
15
+
16
+ export { __export };
@@ -0,0 +1,156 @@
1
+ import {
2
+ response2
3
+ } from "./fetch-6gkz39ey.js";
4
+ import {
5
+ Api2
6
+ } from "./fetch-z5shrcz9.js";
7
+
8
+ // src/handlers/integration.ts
9
+ import { Integration } from "@opencode/core/integration";
10
+ import { Plugin } from "@opencode/core/plugin";
11
+ import { Effect } from "effect";
12
+ import { HttpApiBuilder, HttpApiSchema } from "effect/unstable/httpapi";
13
+ import {
14
+ IntegrationAttemptNotFoundError,
15
+ IntegrationMethodNotFoundError,
16
+ IntegrationNotFoundError,
17
+ InvalidRequestError
18
+ } from "@opencode/protocol/errors";
19
+ import { WellKnown } from "@opencode/core/wellknown";
20
+ var authorize = (effect) => effect.pipe(Effect.mapError((error) => new InvalidRequestError({
21
+ message: error.cause instanceof Error && error.cause.message.trim() ? error.cause.message : "Authentication failed",
22
+ kind: "integration_authorization"
23
+ })));
24
+ var IntegrationHandler2 = HttpApiBuilder.group(Api2, "server.integration", (handlers) => Effect.gen(function* () {
25
+ return handlers.handle("integration.list", Effect.fn(function* () {
26
+ yield* Plugin.awaitActivation;
27
+ const service = yield* Integration.Service;
28
+ return yield* response2(service.list());
29
+ })).handle("integration.get", Effect.fn(function* (ctx) {
30
+ const service = yield* Integration.Service;
31
+ const integration = yield* service.get(ctx.params.integrationID);
32
+ if (!integration)
33
+ return yield* new IntegrationNotFoundError({
34
+ integrationID: ctx.params.integrationID,
35
+ message: `Integration not found: ${ctx.params.integrationID}`
36
+ });
37
+ return yield* response2(Effect.succeed(integration));
38
+ })).handle("integration.wellknown.add", Effect.fn(function* (ctx) {
39
+ const wellknown = yield* WellKnown.Service;
40
+ const integration = yield* Integration.Service;
41
+ yield* wellknown.add(ctx.payload.url).pipe(Effect.mapError((error) => new InvalidRequestError({ message: error.message, kind: "well_known_discovery" })));
42
+ yield* integration.reload();
43
+ return HttpApiSchema.NoContent.make();
44
+ })).handle("integration.connect.key", Effect.fn(function* (ctx) {
45
+ const service = yield* Integration.Service;
46
+ if (!(yield* service.get(ctx.params.integrationID)))
47
+ return yield* new IntegrationNotFoundError({
48
+ integrationID: ctx.params.integrationID,
49
+ message: `Integration not found: ${ctx.params.integrationID}`
50
+ });
51
+ yield* authorize(service.connection.key({
52
+ integrationID: ctx.params.integrationID,
53
+ key: ctx.payload.key,
54
+ answer: ctx.payload.answer,
55
+ label: ctx.payload.label
56
+ }));
57
+ return HttpApiSchema.NoContent.make();
58
+ })).handle("integration.oauth.connect", Effect.fn(function* (ctx) {
59
+ const service = yield* Integration.Service;
60
+ return yield* response2(authorize(service.oauth.connect({
61
+ integrationID: ctx.params.integrationID,
62
+ methodID: ctx.payload.methodID,
63
+ answer: ctx.payload.answer,
64
+ label: ctx.payload.label
65
+ })));
66
+ })).handle("integration.oauth.status", Effect.fn(function* (ctx) {
67
+ const service = yield* Integration.Service;
68
+ if (!(yield* service.get(ctx.params.integrationID)))
69
+ return yield* new IntegrationNotFoundError({
70
+ integrationID: ctx.params.integrationID,
71
+ message: `Integration not found: ${ctx.params.integrationID}`
72
+ });
73
+ return yield* response2(service.oauth.status({
74
+ integrationID: ctx.params.integrationID,
75
+ attemptID: ctx.params.attemptID
76
+ }).pipe(Effect.mapError((error) => new IntegrationAttemptNotFoundError({
77
+ integrationID: error.integrationID,
78
+ attemptID: error.attemptID,
79
+ message: `OAuth attempt not found: ${error.attemptID}`
80
+ }))));
81
+ })).handle("integration.oauth.complete", Effect.fn(function* (ctx) {
82
+ const service = yield* Integration.Service;
83
+ if (!(yield* service.get(ctx.params.integrationID)))
84
+ return yield* new IntegrationNotFoundError({
85
+ integrationID: ctx.params.integrationID,
86
+ message: `Integration not found: ${ctx.params.integrationID}`
87
+ });
88
+ yield* service.oauth.complete({
89
+ integrationID: ctx.params.integrationID,
90
+ attemptID: ctx.params.attemptID,
91
+ code: ctx.payload.code
92
+ }).pipe(Effect.mapError((error) => {
93
+ if (error._tag === "Integration.AttemptNotFound")
94
+ return new IntegrationAttemptNotFoundError({
95
+ integrationID: error.integrationID,
96
+ attemptID: error.attemptID,
97
+ message: `OAuth attempt not found: ${error.attemptID}`
98
+ });
99
+ return new InvalidRequestError({
100
+ message: error._tag === "Integration.CodeRequired" ? "Authorization code is required" : "Authentication failed",
101
+ kind: error._tag === "Integration.CodeRequired" ? "integration_code_required" : "integration_authorization"
102
+ });
103
+ }));
104
+ return HttpApiSchema.NoContent.make();
105
+ })).handle("integration.oauth.cancel", Effect.fn(function* (ctx) {
106
+ const service = yield* Integration.Service;
107
+ yield* service.oauth.cancel({
108
+ integrationID: ctx.params.integrationID,
109
+ attemptID: ctx.params.attemptID
110
+ });
111
+ return HttpApiSchema.NoContent.make();
112
+ })).handle("integration.command.connect", Effect.fn(function* (ctx) {
113
+ const service = yield* Integration.Service;
114
+ const integration = yield* service.get(ctx.params.integrationID);
115
+ if (!integration)
116
+ return yield* new IntegrationNotFoundError({
117
+ integrationID: ctx.params.integrationID,
118
+ message: `Integration not found: ${ctx.params.integrationID}`
119
+ });
120
+ if (!integration.methods.some((method) => method.type === "command" && method.id === ctx.payload.methodID))
121
+ return yield* new IntegrationMethodNotFoundError({
122
+ integrationID: ctx.params.integrationID,
123
+ methodID: ctx.payload.methodID,
124
+ message: `Integration method not found: ${ctx.payload.methodID}`
125
+ });
126
+ return yield* response2(authorize(service.command.connect({
127
+ integrationID: ctx.params.integrationID,
128
+ methodID: ctx.payload.methodID,
129
+ label: ctx.payload.label
130
+ })));
131
+ })).handle("integration.command.status", Effect.fn(function* (ctx) {
132
+ const service = yield* Integration.Service;
133
+ if (!(yield* service.get(ctx.params.integrationID)))
134
+ return yield* new IntegrationNotFoundError({
135
+ integrationID: ctx.params.integrationID,
136
+ message: `Integration not found: ${ctx.params.integrationID}`
137
+ });
138
+ return yield* response2(service.command.status({
139
+ integrationID: ctx.params.integrationID,
140
+ attemptID: ctx.params.attemptID
141
+ }).pipe(Effect.mapError((error) => new IntegrationAttemptNotFoundError({
142
+ integrationID: error.integrationID,
143
+ attemptID: error.attemptID,
144
+ message: `Command attempt not found: ${error.attemptID}`
145
+ }))));
146
+ })).handle("integration.command.cancel", Effect.fn(function* (ctx) {
147
+ const service = yield* Integration.Service;
148
+ yield* service.command.cancel({
149
+ integrationID: ctx.params.integrationID,
150
+ attemptID: ctx.params.attemptID
151
+ });
152
+ return HttpApiSchema.NoContent.make();
153
+ }));
154
+ }));
155
+
156
+ export { IntegrationHandler2 };
@@ -0,0 +1,77 @@
1
+ import {
2
+ missingSession2
3
+ } from "./fetch-smaf4a18.js";
4
+ import {
5
+ response2,
6
+ sessionInfo2
7
+ } from "./fetch-6gkz39ey.js";
8
+ import {
9
+ Api2
10
+ } from "./fetch-z5shrcz9.js";
11
+
12
+ // src/handlers/permission.ts
13
+ import { Instance } from "@opencode/core/instance/service";
14
+ import { Location } from "@opencode/core/location";
15
+ import { Permission } from "@opencode/core/permission";
16
+ import { PermissionSaved } from "@opencode/core/permission/saved";
17
+ import { Session } from "@opencode/core/session";
18
+ import { Effect } from "effect";
19
+ import { HttpApiBuilder, HttpApiSchema } from "effect/unstable/httpapi";
20
+ import { PermissionNotFoundError } from "@opencode/protocol/errors";
21
+ function missingRequest(id) {
22
+ return new PermissionNotFoundError({ requestID: id, message: `Permission request not found: ${id}` });
23
+ }
24
+ var PermissionHandler2 = HttpApiBuilder.group(Api2, "server.permission", (handlers) => Effect.gen(function* () {
25
+ const instances = yield* Instance.Service;
26
+ const sessions = yield* Session.Service;
27
+ const requireOwnedRequest = Effect.fnUntraced(function* (sessionID, requestID) {
28
+ const permission = yield* Permission.Service;
29
+ const request = yield* permission.get(requestID);
30
+ if (!request || request.sessionID !== sessionID)
31
+ return yield* missingRequest(requestID);
32
+ return { permission, request };
33
+ });
34
+ return handlers.handle("permission.request.list", Effect.fn(function* () {
35
+ const permission = yield* Permission.Service;
36
+ return yield* response2(permission.list());
37
+ })).handle("session.permission.create", Effect.fn(function* (ctx) {
38
+ const permission = yield* Permission.Service;
39
+ return {
40
+ data: yield* permission.ask({
41
+ id: ctx.payload.id,
42
+ sessionID: ctx.params.sessionID,
43
+ action: ctx.payload.action,
44
+ resources: ctx.payload.resources,
45
+ save: ctx.payload.save,
46
+ metadata: ctx.payload.metadata,
47
+ source: ctx.payload.source,
48
+ agent: ctx.payload.agent
49
+ }).pipe(Effect.catchTag("Session.NotFoundError", missingSession2))
50
+ };
51
+ })).handle("session.permission.list", Effect.fn(function* (ctx) {
52
+ const session = yield* sessionInfo2(sessions, ctx.params.sessionID);
53
+ const requests = yield* Permission.Service.use((permission) => permission.forSession(ctx.params.sessionID)).pipe(instances.provide(session));
54
+ return { data: requests };
55
+ })).handle("session.permission.get", Effect.fn(function* (ctx) {
56
+ const owned = yield* requireOwnedRequest(ctx.params.sessionID, ctx.params.requestID);
57
+ return { data: owned.request };
58
+ })).handle("session.permission.reply", Effect.fn(function* (ctx) {
59
+ const owned = yield* requireOwnedRequest(ctx.params.sessionID, ctx.params.requestID);
60
+ yield* owned.permission.reply({ requestID: ctx.params.requestID, reply: ctx.payload.decision, message: ctx.payload.message }).pipe(Effect.catchTag("Permission.NotFoundError", () => missingRequest(ctx.params.requestID)));
61
+ return HttpApiSchema.NoContent.make();
62
+ })).handle("permission.saved.list", Effect.fn(function* (ctx) {
63
+ const location = yield* Location.Service;
64
+ const saved = yield* PermissionSaved.Service;
65
+ return {
66
+ data: yield* saved.list({
67
+ projectID: ctx.query.projectID ?? location.project.id
68
+ })
69
+ };
70
+ })).handle("permission.saved.remove", Effect.fn(function* (ctx) {
71
+ const saved = yield* PermissionSaved.Service;
72
+ yield* saved.remove(ctx.params.id);
73
+ return HttpApiSchema.NoContent.make();
74
+ }));
75
+ }));
76
+
77
+ export { PermissionHandler2 };
@@ -0,0 +1,39 @@
1
+ import {
2
+ response2
3
+ } from "./fetch-6gkz39ey.js";
4
+ import {
5
+ Api2
6
+ } from "./fetch-z5shrcz9.js";
7
+
8
+ // src/handlers/websearch.ts
9
+ import { WebSearch } from "@opencode/core/websearch";
10
+ import { InvalidRequestError, ServiceUnavailableError } from "@opencode/protocol/errors";
11
+ import { Effect } from "effect";
12
+ import { HttpApiBuilder } from "effect/unstable/httpapi";
13
+ var WebSearchHandler2 = HttpApiBuilder.group(Api2, "server.websearch", (handlers) => Effect.gen(function* () {
14
+ return handlers.handle("websearch.providers", Effect.fn("server.websearch.providers")(function* () {
15
+ const websearch = yield* WebSearch.Service;
16
+ return yield* response2(websearch.providers());
17
+ })).handle("websearch.query", Effect.fn("server.websearch.query")(function* (request) {
18
+ const websearch = yield* WebSearch.Service;
19
+ return yield* response2(websearch.query(request.payload).pipe(Effect.catchTags({
20
+ "WebSearch.ProviderRequired": () => new InvalidRequestError({
21
+ message: "Web search provider is required",
22
+ kind: "websearch_provider_required",
23
+ field: "providerID"
24
+ }),
25
+ "WebSearch.ProviderNotFound": (error) => new InvalidRequestError({
26
+ message: `Web search provider not found: ${error.providerID}`,
27
+ kind: "websearch_provider_not_found",
28
+ field: "providerID"
29
+ }),
30
+ "WebSearch.Disabled": () => new InvalidRequestError({ message: "Web search is disabled", kind: "websearch_disabled" }),
31
+ "WebSearch.Request": (error) => new ServiceUnavailableError({
32
+ message: `Web search request failed: ${error.providerID}`,
33
+ service: error.providerID
34
+ })
35
+ })));
36
+ }));
37
+ }));
38
+
39
+ export { WebSearchHandler2 };
@@ -0,0 +1,22 @@
1
+ import {
2
+ Api2
3
+ } from "./fetch-z5shrcz9.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,35 @@
1
+ import {
2
+ response2
3
+ } from "./fetch-6gkz39ey.js";
4
+ import {
5
+ Api2
6
+ } from "./fetch-z5shrcz9.js";
7
+
8
+ // src/handlers/shell.ts
9
+ import { Shell } from "@opencode/core/shell";
10
+ import { Location } from "@opencode/core/location";
11
+ import { Effect } from "effect";
12
+ import { HttpApiBuilder, HttpApiSchema } from "effect/unstable/httpapi";
13
+ import { ShellNotFoundError } from "@opencode/protocol/errors";
14
+ var ShellHandler2 = HttpApiBuilder.group(Api2, "server.shell", (handlers) => Effect.gen(function* () {
15
+ return handlers.handle("shell.list", Effect.fn(function* () {
16
+ const shell = yield* Shell.Service;
17
+ return yield* response2(shell.list());
18
+ })).handle("shell.create", Effect.fn(function* (ctx) {
19
+ const shell = yield* Shell.Service;
20
+ const location = yield* Location.Service;
21
+ return yield* response2(shell.create({ ...ctx.payload, cwd: ctx.payload.cwd || location.directory }).pipe(Effect.orDie));
22
+ })).handle("shell.get", Effect.fn(function* (ctx) {
23
+ const shell = yield* Shell.Service;
24
+ return yield* response2(shell.get(ctx.params.id).pipe(Effect.catchTag("Shell.NotFoundError", () => new ShellNotFoundError({ id: ctx.params.id, message: `Shell command not found: ${ctx.params.id}` }))));
25
+ })).handle("shell.output", Effect.fn(function* (ctx) {
26
+ const shell = yield* Shell.Service;
27
+ return yield* response2(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}` }))));
28
+ })).handle("shell.remove", Effect.fn(function* (ctx) {
29
+ const shell = yield* Shell.Service;
30
+ yield* shell.remove(ctx.params.id).pipe(Effect.catchTag("Shell.NotFoundError", () => Effect.void));
31
+ return HttpApiSchema.NoContent.make();
32
+ }));
33
+ }));
34
+
35
+ export { ShellHandler2 };