@opencode/server 2.0.8 → 2.0.10

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/auth-0ar9gf7q.js +55 -0
  5. package/dist/chunks/auth-0qzy9yxk.js +163 -0
  6. package/dist/chunks/auth-1wj0ectp.js +22 -0
  7. package/dist/chunks/auth-23w8t84j.js +26 -0
  8. package/dist/chunks/auth-34e6wr3b.js +13 -0
  9. package/dist/chunks/auth-3582t7j8.js +139 -0
  10. package/dist/chunks/auth-40g8rvw4.js +59 -0
  11. package/dist/chunks/auth-5p62ed52.js +36 -0
  12. package/dist/chunks/auth-6aya8ky6.js +39 -0
  13. package/dist/chunks/auth-760vtqy2.js +29 -0
  14. package/dist/chunks/auth-7bj707s9.js +99 -0
  15. package/dist/chunks/auth-7qtja2kq.js +15 -0
  16. package/dist/chunks/auth-8e21y1bd.js +20 -0
  17. package/dist/chunks/auth-8nbs1vvt.js +34 -0
  18. package/dist/chunks/auth-8ygjd1s8.js +40 -0
  19. package/dist/chunks/auth-9rqn6x4v.js +16 -0
  20. package/dist/chunks/auth-b4atwt7w.js +37 -0
  21. package/dist/chunks/auth-bgzrbsek.js +13 -0
  22. package/dist/chunks/auth-bkb1xk38.js +42 -0
  23. package/dist/chunks/auth-bkk2wfbz.js +23 -0
  24. package/dist/chunks/auth-byzd2nk7.js +21 -0
  25. package/dist/chunks/auth-cm8xmqjn.js +13 -0
  26. package/dist/chunks/auth-d2g7egyw.js +25 -0
  27. package/dist/chunks/auth-e09mshwt.js +23 -0
  28. package/dist/chunks/auth-erwrh284.js +156 -0
  29. package/dist/chunks/auth-frv6gfy7.js +33 -0
  30. package/dist/chunks/auth-fyjxk8m3.js +22 -0
  31. package/dist/chunks/auth-gsks0nj8.js +149 -0
  32. package/dist/chunks/auth-hezj1jdf.js +7 -0
  33. package/dist/chunks/auth-kv6ycdgm.js +77 -0
  34. package/dist/chunks/auth-m6wvgbfq.js +60 -0
  35. package/dist/chunks/auth-p5hgn93y.js +26 -0
  36. package/dist/chunks/auth-pd1pbg0v.js +17 -0
  37. package/dist/chunks/auth-q4bn6dy8.js +39 -0
  38. package/dist/chunks/auth-r4dhhtgz.js +346 -0
  39. package/dist/chunks/auth-rjpqaa8h.js +83 -0
  40. package/dist/chunks/auth-smaf4a18.js +28 -0
  41. package/dist/chunks/auth-t8yzmczr.js +18 -0
  42. package/dist/chunks/auth-tk6nqkmh.js +22 -0
  43. package/dist/chunks/auth-txhx6f1m.js +13 -0
  44. package/dist/chunks/auth-vgxn80m1.js +61 -0
  45. package/dist/chunks/auth-xpxp1sqb.js +22 -0
  46. package/dist/chunks/auth-xsrtpxyd.js +23 -0
  47. package/dist/chunks/auth-yc7nft6q.js +5 -0
  48. package/dist/chunks/auth-z3nth2hg.js +35 -0
  49. package/dist/chunks/auth-z6kg9h7e.js +19 -0
  50. package/dist/chunks/auth-zw9j8b8g.js +32 -0
  51. package/dist/chunks/auth-zxvt7wd3.js +25 -0
  52. package/dist/chunks/auth-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
@@ -1,143 +1,11 @@
1
- import { Integration } from "@opencode/core/integration";
2
- import { Plugin } from "@opencode/core/plugin";
3
- import { Effect } from "effect";
4
- import { HttpApiBuilder, HttpApiSchema } from "effect/unstable/httpapi";
5
- import { Api } from "../api";
6
1
  import {
7
- IntegrationAttemptNotFoundError,
8
- IntegrationMethodNotFoundError,
9
- IntegrationNotFoundError,
10
- InvalidRequestError
11
- } from "@opencode/protocol/errors";
12
- import { response } from "../location";
13
- import { WellKnown } from "@opencode/core/wellknown";
14
- const authorize = (effect) => effect.pipe(Effect.mapError((error) => new InvalidRequestError({
15
- message: error.cause instanceof Error && error.cause.message.trim() ? error.cause.message : "Authentication failed",
16
- kind: "integration_authorization"
17
- })));
18
- export const IntegrationHandler = HttpApiBuilder.group(Api, "server.integration", (handlers) => Effect.gen(function* () {
19
- return handlers.handle("integration.list", Effect.fn(function* () {
20
- yield* Plugin.awaitActivation;
21
- const service = yield* Integration.Service;
22
- return yield* response(service.list());
23
- })).handle("integration.get", Effect.fn(function* (ctx) {
24
- const integration = yield* (yield* Integration.Service).get(ctx.params.integrationID);
25
- if (!integration)
26
- return yield* new IntegrationNotFoundError({
27
- integrationID: ctx.params.integrationID,
28
- message: `Integration not found: ${ctx.params.integrationID}`
29
- });
30
- return yield* response(Effect.succeed(integration));
31
- })).handle("integration.wellknown.add", Effect.fn(function* (ctx) {
32
- const wellknown = yield* WellKnown.Service, integration = yield* Integration.Service;
33
- yield* wellknown.add(ctx.payload.url).pipe(Effect.mapError((error) => new InvalidRequestError({ message: error.message, kind: "well_known_discovery" })));
34
- yield* integration.reload();
35
- return HttpApiSchema.NoContent.make();
36
- })).handle("integration.connect.key", Effect.fn(function* (ctx) {
37
- const service = yield* Integration.Service;
38
- if (!(yield* service.get(ctx.params.integrationID)))
39
- return yield* new IntegrationNotFoundError({
40
- integrationID: ctx.params.integrationID,
41
- message: `Integration not found: ${ctx.params.integrationID}`
42
- });
43
- yield* authorize(service.connection.key({
44
- integrationID: ctx.params.integrationID,
45
- key: ctx.payload.key,
46
- answer: ctx.payload.answer,
47
- label: ctx.payload.label
48
- }));
49
- return HttpApiSchema.NoContent.make();
50
- })).handle("integration.oauth.connect", Effect.fn(function* (ctx) {
51
- const service = yield* Integration.Service;
52
- return yield* response(authorize(service.oauth.connect({
53
- integrationID: ctx.params.integrationID,
54
- methodID: ctx.payload.methodID,
55
- answer: ctx.payload.answer,
56
- label: ctx.payload.label
57
- })));
58
- })).handle("integration.oauth.status", Effect.fn(function* (ctx) {
59
- const service = yield* Integration.Service;
60
- if (!(yield* service.get(ctx.params.integrationID)))
61
- return yield* new IntegrationNotFoundError({
62
- integrationID: ctx.params.integrationID,
63
- message: `Integration not found: ${ctx.params.integrationID}`
64
- });
65
- return yield* response(service.oauth.status({
66
- integrationID: ctx.params.integrationID,
67
- attemptID: ctx.params.attemptID
68
- }).pipe(Effect.mapError((error) => new IntegrationAttemptNotFoundError({
69
- integrationID: error.integrationID,
70
- attemptID: error.attemptID,
71
- message: `OAuth attempt not found: ${error.attemptID}`
72
- }))));
73
- })).handle("integration.oauth.complete", Effect.fn(function* (ctx) {
74
- const service = yield* Integration.Service;
75
- if (!(yield* service.get(ctx.params.integrationID)))
76
- return yield* new IntegrationNotFoundError({
77
- integrationID: ctx.params.integrationID,
78
- message: `Integration not found: ${ctx.params.integrationID}`
79
- });
80
- yield* service.oauth.complete({
81
- integrationID: ctx.params.integrationID,
82
- attemptID: ctx.params.attemptID,
83
- code: ctx.payload.code
84
- }).pipe(Effect.mapError((error) => {
85
- if (error._tag === "Integration.AttemptNotFound")
86
- return new IntegrationAttemptNotFoundError({
87
- integrationID: error.integrationID,
88
- attemptID: error.attemptID,
89
- message: `OAuth attempt not found: ${error.attemptID}`
90
- });
91
- return new InvalidRequestError({
92
- message: error._tag === "Integration.CodeRequired" ? "Authorization code is required" : "Authentication failed",
93
- kind: error._tag === "Integration.CodeRequired" ? "integration_code_required" : "integration_authorization"
94
- });
95
- }));
96
- return HttpApiSchema.NoContent.make();
97
- })).handle("integration.oauth.cancel", Effect.fn(function* (ctx) {
98
- yield* (yield* Integration.Service).oauth.cancel({
99
- integrationID: ctx.params.integrationID,
100
- attemptID: ctx.params.attemptID
101
- });
102
- return HttpApiSchema.NoContent.make();
103
- })).handle("integration.command.connect", Effect.fn(function* (ctx) {
104
- const service = yield* Integration.Service, integration = yield* service.get(ctx.params.integrationID);
105
- if (!integration)
106
- return yield* new IntegrationNotFoundError({
107
- integrationID: ctx.params.integrationID,
108
- message: `Integration not found: ${ctx.params.integrationID}`
109
- });
110
- if (!integration.methods.some((method) => method.type === "command" && method.id === ctx.payload.methodID))
111
- return yield* new IntegrationMethodNotFoundError({
112
- integrationID: ctx.params.integrationID,
113
- methodID: ctx.payload.methodID,
114
- message: `Integration method not found: ${ctx.payload.methodID}`
115
- });
116
- return yield* response(authorize(service.command.connect({
117
- integrationID: ctx.params.integrationID,
118
- methodID: ctx.payload.methodID,
119
- label: ctx.payload.label
120
- })));
121
- })).handle("integration.command.status", Effect.fn(function* (ctx) {
122
- const service = yield* Integration.Service;
123
- if (!(yield* service.get(ctx.params.integrationID)))
124
- return yield* new IntegrationNotFoundError({
125
- integrationID: ctx.params.integrationID,
126
- message: `Integration not found: ${ctx.params.integrationID}`
127
- });
128
- return yield* response(service.command.status({
129
- integrationID: ctx.params.integrationID,
130
- attemptID: ctx.params.attemptID
131
- }).pipe(Effect.mapError((error) => new IntegrationAttemptNotFoundError({
132
- integrationID: error.integrationID,
133
- attemptID: error.attemptID,
134
- message: `Command attempt not found: ${error.attemptID}`
135
- }))));
136
- })).handle("integration.command.cancel", Effect.fn(function* (ctx) {
137
- yield* (yield* Integration.Service).command.cancel({
138
- integrationID: ctx.params.integrationID,
139
- attemptID: ctx.params.attemptID
140
- });
141
- return HttpApiSchema.NoContent.make();
142
- }));
143
- }));
2
+ IntegrationHandler2
3
+ } from "../chunks/auth-erwrh284.js";
4
+ import"../chunks/auth-z6kg9h7e.js";
5
+ import"../chunks/auth-23w8t84j.js";
6
+ import"../chunks/auth-frv6gfy7.js";
7
+ import"../chunks/auth-0ar9gf7q.js";
8
+ import"../chunks/auth-smaf4a18.js";
9
+ export {
10
+ IntegrationHandler2 as IntegrationHandler
11
+ };
@@ -1,16 +1,11 @@
1
- import { Location } from "@opencode/core/location";
2
- import { LocationServiceMap } from "@opencode/core/location-service-map";
3
- import { ServiceUnavailableError } from "@opencode/protocol/errors";
4
- import { Cause, Effect } from "effect";
5
- import { HttpApiBuilder } from "effect/unstable/httpapi";
6
- import { Api } from "../api";
7
- export const LocationHandler = HttpApiBuilder.group(Api, "server.location", (handlers) => Effect.gen(function* () {
8
- const locations = yield* LocationServiceMap.Service;
9
- return handlers.handle("location.get", Effect.fn(function* () {
10
- const location = yield* Location.Service;
11
- return new Location.Info({
12
- directory: location.directory,
13
- project: location.project
14
- });
15
- })).handle("location.reload", () => LocationServiceMap.reload().pipe(Effect.provideService(LocationServiceMap.Service, locations), Effect.catchCause((cause) => Cause.hasInterruptsOnly(cause) ? Effect.failCause(cause) : Effect.fail(new ServiceUnavailableError({ message: Cause.pretty(cause), service: "location" })))));
16
- }));
1
+ import {
2
+ LocationHandler2
3
+ } from "../chunks/auth-tk6nqkmh.js";
4
+ import"../chunks/auth-z6kg9h7e.js";
5
+ import"../chunks/auth-23w8t84j.js";
6
+ import"../chunks/auth-frv6gfy7.js";
7
+ import"../chunks/auth-0ar9gf7q.js";
8
+ import"../chunks/auth-smaf4a18.js";
9
+ export {
10
+ LocationHandler2 as LocationHandler
11
+ };
@@ -1,31 +1,11 @@
1
- import { Mcp } from "@opencode/core/mcp/index";
2
- import { McpServerNotFoundError } from "@opencode/protocol/errors";
3
- import { Effect } from "effect";
4
- import { HttpApiBuilder, HttpApiSchema } from "effect/unstable/httpapi";
5
- import { Api } from "../api";
6
- import { response } from "../location";
7
- const notFound = (effect) => effect.pipe(Effect.mapError((error) => new McpServerNotFoundError({ server: error.server, message: error.message })));
8
- export const McpHandler = HttpApiBuilder.group(Api, "server.mcp", (handlers) => Effect.gen(function* () {
9
- return handlers.handle("mcp.list", Effect.fn(function* () {
10
- const service = yield* Mcp.Service;
11
- return yield* response(service.servers().pipe(Effect.map((servers) => servers.map((info) => ({ name: info.name, status: info.status, integrationID: info.integrationID })))));
12
- })).handle("mcp.add", Effect.fn(function* (ctx) {
13
- yield* (yield* Mcp.Service).add(ctx.params.server, ctx.payload.config);
14
- return HttpApiSchema.NoContent.make();
15
- })).handle("mcp.remove", Effect.fn(function* (ctx) {
16
- const service = yield* Mcp.Service;
17
- yield* notFound(service.remove(ctx.params.server));
18
- return HttpApiSchema.NoContent.make();
19
- })).handle("mcp.connect", Effect.fn(function* (ctx) {
20
- const service = yield* Mcp.Service;
21
- yield* notFound(service.connect(ctx.params.server));
22
- return HttpApiSchema.NoContent.make();
23
- })).handle("mcp.disconnect", Effect.fn(function* (ctx) {
24
- const service = yield* Mcp.Service;
25
- yield* notFound(service.disconnect(ctx.params.server));
26
- return HttpApiSchema.NoContent.make();
27
- })).handle("mcp.resource.catalog", Effect.fn(function* () {
28
- const service = yield* Mcp.Service;
29
- return yield* response(service.resourceCatalog());
30
- }));
31
- }));
1
+ import {
2
+ McpHandler2
3
+ } from "../chunks/auth-8ygjd1s8.js";
4
+ import"../chunks/auth-z6kg9h7e.js";
5
+ import"../chunks/auth-23w8t84j.js";
6
+ import"../chunks/auth-frv6gfy7.js";
7
+ import"../chunks/auth-0ar9gf7q.js";
8
+ import"../chunks/auth-smaf4a18.js";
9
+ export {
10
+ McpHandler2 as McpHandler
11
+ };
@@ -1,43 +1,11 @@
1
- import { SessionMessage } from "@opencode/core/session/message";
2
- import { Session } from "@opencode/core/session";
3
- import { Effect, Schema } from "effect";
4
- import { HttpApiBuilder } from "effect/unstable/httpapi";
5
- import { Api } from "../api";
6
- import { InvalidCursorError } from "@opencode/protocol/errors";
7
- import { failedMessageDecode, missingSession } from "./session-error";
8
- const DefaultMessagesLimit = 50, Cursor = Schema.Struct({
9
- id: SessionMessage.ID,
10
- order: Schema.Union([Schema.Literal("asc"), Schema.Literal("desc")]),
11
- direction: Schema.Union([Schema.Literal("previous"), Schema.Literal("next")])
12
- }), decodeCursor = Schema.decodeUnknownSync(Cursor), cursor = {
13
- encode(message, order, direction) {
14
- return Buffer.from(JSON.stringify({ id: message.id, order, direction })).toString("base64url");
15
- },
16
- decode(input) {
17
- return decodeCursor(JSON.parse(Buffer.from(input, "base64url").toString("utf8")));
18
- }
1
+ import {
2
+ MessageHandler2
3
+ } from "../chunks/auth-40g8rvw4.js";
4
+ import"../chunks/auth-z6kg9h7e.js";
5
+ import"../chunks/auth-23w8t84j.js";
6
+ import"../chunks/auth-frv6gfy7.js";
7
+ import"../chunks/auth-0ar9gf7q.js";
8
+ import"../chunks/auth-smaf4a18.js";
9
+ export {
10
+ MessageHandler2 as MessageHandler
19
11
  };
20
- export const MessageHandler = HttpApiBuilder.group(Api, "server.message", (handlers) => Effect.gen(function* () {
21
- const session = yield* Session.Service;
22
- return handlers.handle("session.messages", Effect.fn(function* (ctx) {
23
- if (ctx.query.cursor && ctx.query.order !== void 0)
24
- return yield* new InvalidCursorError({ message: "Cursor cannot be combined with order" });
25
- const decoded = yield* Effect.try({
26
- try: () => ctx.query.cursor ? cursor.decode(ctx.query.cursor) : void 0,
27
- catch: () => new InvalidCursorError({ message: "Invalid cursor" })
28
- }), order = decoded?.order ?? ctx.query.order ?? "desc", messages = yield* session.messages({
29
- sessionID: ctx.params.sessionID,
30
- limit: ctx.query.limit ?? DefaultMessagesLimit,
31
- order,
32
- type: ctx.query.type,
33
- cursor: decoded ? { id: decoded.id, direction: decoded.direction } : void 0
34
- }).pipe(Effect.catchTag("Session.NotFoundError", missingSession), Effect.catchTag("Session.MessageDecodeError", failedMessageDecode)), first = messages[0], last = messages.at(-1);
35
- return {
36
- data: messages,
37
- cursor: {
38
- previous: first ? cursor.encode(first, order, "previous") : void 0,
39
- next: last ? cursor.encode(last, order, "next") : void 0
40
- }
41
- };
42
- }));
43
- }));
@@ -1,7 +1,11 @@
1
- import { V1Migration } from "@opencode/core/database/v1-migration";
2
- import { HttpApiBuilder } from "effect/unstable/httpapi";
3
- import { Effect } from "effect";
4
- import { Api } from "../api";
5
- export const MigrationHandler = HttpApiBuilder.group(Api, "server.migration", (handlers) => handlers.handle("migration.v1.status", Effect.fn(function* () {
6
- return yield* V1Migration.status();
7
- })));
1
+ import {
2
+ MigrationHandler2
3
+ } from "../chunks/auth-txhx6f1m.js";
4
+ import"../chunks/auth-z6kg9h7e.js";
5
+ import"../chunks/auth-23w8t84j.js";
6
+ import"../chunks/auth-frv6gfy7.js";
7
+ import"../chunks/auth-0ar9gf7q.js";
8
+ import"../chunks/auth-smaf4a18.js";
9
+ export {
10
+ MigrationHandler2 as MigrationHandler
11
+ };
@@ -1,14 +1,11 @@
1
- import { Model } from "@opencode/core/model";
2
- import { Effect } from "effect";
3
- import { HttpApiBuilder } from "effect/unstable/httpapi";
4
- import { Api } from "../api";
5
- import { response } from "../location";
6
- export const ModelHandler = HttpApiBuilder.group(Api, "server.model", (handlers) => Effect.gen(function* () {
7
- return handlers.handle("model.list", Effect.fn(function* () {
8
- const models = yield* Model.Service;
9
- return yield* response(models.available());
10
- })).handle("model.default", Effect.fn(function* () {
11
- const models = yield* Model.Service;
12
- return yield* response(models.default());
13
- }));
14
- }));
1
+ import {
2
+ ModelHandler2
3
+ } from "../chunks/auth-fyjxk8m3.js";
4
+ import"../chunks/auth-z6kg9h7e.js";
5
+ import"../chunks/auth-23w8t84j.js";
6
+ import"../chunks/auth-frv6gfy7.js";
7
+ import"../chunks/auth-0ar9gf7q.js";
8
+ import"../chunks/auth-smaf4a18.js";
9
+ export {
10
+ ModelHandler2 as ModelHandler
11
+ };
@@ -1,57 +1,11 @@
1
- import { Instance } from "@opencode/core/instance/service";
2
- import { Location } from "@opencode/core/location";
3
- import { Permission } from "@opencode/core/permission";
4
- import { PermissionSaved } from "@opencode/core/permission/saved";
5
- import { Session } from "@opencode/core/session";
6
- import { Effect } from "effect";
7
- import { HttpApiBuilder, HttpApiSchema } from "effect/unstable/httpapi";
8
- import { Api } from "../api";
9
- import { PermissionNotFoundError } from "@opencode/protocol/errors";
10
- import { response, sessionInfo } from "../location";
11
- import { missingSession } from "./session-error";
12
- function missingRequest(id) {
13
- return new PermissionNotFoundError({ requestID: id, message: `Permission request not found: ${id}` });
14
- }
15
- export const PermissionHandler = HttpApiBuilder.group(Api, "server.permission", (handlers) => Effect.gen(function* () {
16
- const instances = yield* Instance.Service, sessions = yield* Session.Service, requireOwnedRequest = Effect.fnUntraced(function* (sessionID, requestID) {
17
- const permission = yield* Permission.Service, request = yield* permission.get(requestID);
18
- if (!request || request.sessionID !== sessionID)
19
- return yield* missingRequest(requestID);
20
- return { permission, request };
21
- });
22
- return handlers.handle("permission.request.list", Effect.fn(function* () {
23
- const permission = yield* Permission.Service;
24
- return yield* response(permission.list());
25
- })).handle("session.permission.create", Effect.fn(function* (ctx) {
26
- return {
27
- data: yield* (yield* Permission.Service).ask({
28
- id: ctx.payload.id,
29
- sessionID: ctx.params.sessionID,
30
- action: ctx.payload.action,
31
- resources: ctx.payload.resources,
32
- save: ctx.payload.save,
33
- metadata: ctx.payload.metadata,
34
- source: ctx.payload.source,
35
- agent: ctx.payload.agent
36
- }).pipe(Effect.catchTag("Session.NotFoundError", missingSession))
37
- };
38
- })).handle("session.permission.list", Effect.fn(function* (ctx) {
39
- const session = yield* sessionInfo(sessions, ctx.params.sessionID);
40
- return { data: yield* Permission.Service.use((permission) => permission.forSession(ctx.params.sessionID)).pipe(instances.provide(session)) };
41
- })).handle("session.permission.get", Effect.fn(function* (ctx) {
42
- return { data: (yield* requireOwnedRequest(ctx.params.sessionID, ctx.params.requestID)).request };
43
- })).handle("session.permission.reply", Effect.fn(function* (ctx) {
44
- yield* (yield* requireOwnedRequest(ctx.params.sessionID, ctx.params.requestID)).permission.reply({ requestID: ctx.params.requestID, reply: ctx.payload.decision, message: ctx.payload.message }).pipe(Effect.catchTag("Permission.NotFoundError", () => missingRequest(ctx.params.requestID)));
45
- return HttpApiSchema.NoContent.make();
46
- })).handle("permission.saved.list", Effect.fn(function* (ctx) {
47
- const location = yield* Location.Service;
48
- return {
49
- data: yield* (yield* PermissionSaved.Service).list({
50
- projectID: ctx.query.projectID ?? location.project.id
51
- })
52
- };
53
- })).handle("permission.saved.remove", Effect.fn(function* (ctx) {
54
- yield* (yield* PermissionSaved.Service).remove(ctx.params.id);
55
- return HttpApiSchema.NoContent.make();
56
- }));
57
- }));
1
+ import {
2
+ PermissionHandler2
3
+ } from "../chunks/auth-kv6ycdgm.js";
4
+ import"../chunks/auth-z6kg9h7e.js";
5
+ import"../chunks/auth-23w8t84j.js";
6
+ import"../chunks/auth-frv6gfy7.js";
7
+ import"../chunks/auth-0ar9gf7q.js";
8
+ import"../chunks/auth-smaf4a18.js";
9
+ export {
10
+ PermissionHandler2 as PermissionHandler
11
+ };
@@ -1,136 +1,13 @@
1
- import { PersistentPty } from "@opencode/core/persistent-pty";
2
- import { PtyTicket } from "@opencode/core/pty/ticket";
3
- import { ForbiddenError, PtyNotFoundError, ServiceUnavailableError } from "@opencode/protocol/errors";
4
1
  import {
5
- PTY_CONNECT_TICKET_QUERY,
6
- PTY_CONNECT_TOKEN_HEADER,
7
- PTY_CONNECT_TOKEN_HEADER_VALUE
8
- } from "@opencode/protocol/groups/persistent-pty";
9
- import { Effect, Queue, Semaphore } from "effect";
10
- import { HttpServerRequest, HttpServerResponse } from "effect/unstable/http";
11
- import { HttpApiBuilder, HttpApiSchema } from "effect/unstable/httpapi";
12
- import { Socket } from "effect/unstable/socket";
13
- import { Api } from "../api";
14
- import { CorsConfig, isAllowedRequestOrigin } from "../cors";
15
- import { runPtySocket } from "./pty-socket";
16
- export const PersistentPtyHandler = HttpApiBuilder.group(Api, "server.experimental", (handlers) => Effect.gen(function* () {
17
- const tickets = yield* PtyTicket.Service, cors = yield* CorsConfig, pty = yield* PersistentPty.Service;
18
- return handlers.handle("persistentPty.read", Effect.fn(function* (ctx) {
19
- return { data: yield* pty.read(ctx.params.sessionID, ctx.query.lines).pipe(mapUnavailable) };
20
- })).handle("persistentPty.list", Effect.fn(function* (ctx) {
21
- return { data: yield* pty.list(ctx.params.sessionID).pipe(mapUnavailable) };
22
- })).handle("persistentPty.create", Effect.fn(function* (ctx) {
23
- return {
24
- data: yield* pty.create(ctx.params.sessionID, {
25
- command: ctx.payload.command,
26
- args: ctx.payload.args,
27
- cwd: ctx.payload.cwd,
28
- title: ctx.payload.title,
29
- env: ctx.payload.env,
30
- cols: ctx.payload.size?.cols,
31
- rows: ctx.payload.size?.rows
32
- }).pipe(Effect.catchTag("PersistentPty.UnavailableError", unavailable))
33
- };
34
- })).handle("persistentPty.shutdown", Effect.fn(function* () {
35
- yield* pty.shutdown().pipe(mapUnavailable);
36
- return HttpApiSchema.NoContent.make();
37
- })).handle("persistentPty.handoff", Effect.fn(function* () {
38
- return { handoff: yield* pty.handoff().pipe(mapUnavailable) };
39
- })).handle("persistentPty.get", Effect.fn(function* (ctx) {
40
- return { data: yield* pty.get(ctx.params.ptyID).pipe(mapTerminalError) };
41
- })).handle("persistentPty.update", Effect.fn(function* (ctx) {
42
- yield* pty.resize(ctx.params.ptyID, ctx.payload.size.cols, ctx.payload.size.rows, ctx.payload.attachmentID).pipe(mapTerminalError);
43
- return { data: yield* pty.get(ctx.params.ptyID).pipe(mapTerminalError) };
44
- })).handle("persistentPty.snapshot", Effect.fn(function* (ctx) {
45
- return { data: yield* pty.snapshot(ctx.params.ptyID).pipe(mapTerminalError) };
46
- })).handle("persistentPty.remove", Effect.fn(function* (ctx) {
47
- yield* pty.remove(ctx.params.ptyID).pipe(mapTerminalError);
48
- return HttpApiSchema.NoContent.make();
49
- })).handle("persistentPty.connectToken", Effect.fn(function* (ctx) {
50
- const request = yield* HttpServerRequest.HttpServerRequest;
51
- if (request.headers[PTY_CONNECT_TOKEN_HEADER] !== PTY_CONNECT_TOKEN_HEADER_VALUE || !isAllowedRequestOrigin(request.headers.origin, request.headers.host, cors))
52
- return yield* new ForbiddenError({ message: "Invalid persistent PTY connect token request" });
53
- yield* pty.get(ctx.params.ptyID).pipe(mapTerminalError);
54
- return { data: yield* tickets.issue({ ptyID: ctx.params.ptyID }) };
55
- })).handleRaw("persistentPty.connect", Effect.fn("PersistentPtyHandler.connect")(function* (ctx) {
56
- const url = new URL(ctx.request.url, "http://localhost"), ticket = url.searchParams.get(PTY_CONNECT_TICKET_QUERY);
57
- if (ticket) {
58
- if (!(isAllowedRequestOrigin(ctx.request.headers.origin, ctx.request.headers.host, cors) ? yield* tickets.consume({ ticket, ptyID: ctx.params.ptyID }) : !1))
59
- return HttpServerResponse.empty({ status: 403 });
60
- }
61
- const cursor = Number(url.searchParams.get("cursor") ?? "0"), role = url.searchParams.get("role") === "observer" ? "observer" : "controller", framedInput = url.searchParams.get("input_protocol") === "1", attachmentID = url.searchParams.get("attachment_id") ?? crypto.randomUUID();
62
- if (!Number.isSafeInteger(cursor) || cursor < 0)
63
- return HttpServerResponse.empty({ status: 400 });
64
- const socket = yield* Effect.orDie(ctx.request.upgrade), write = yield* socket.writer, outbox = yield* Queue.unbounded(), input = yield* Semaphore.make(1);
65
- let attachment;
66
- const onOpen = Effect.gen(function* () {
67
- attachment = yield* pty.attach(ctx.params.ptyID, {
68
- cursor,
69
- attachmentID,
70
- role,
71
- takeover: url.searchParams.get("takeover") === "true",
72
- onEvent: (event) => {
73
- if (event.type === "output")
74
- Queue.offerUnsafe(outbox, event.data);
75
- if (event.type === "resized")
76
- Queue.offerUnsafe(outbox, JSON.stringify({ ...event, checkpoint: Buffer.from(event.checkpoint).toString("base64") }));
77
- if (event.type !== "output" && event.type !== "resized")
78
- Queue.offerUnsafe(outbox, JSON.stringify(event));
79
- },
80
- onEnd: () => Queue.offerUnsafe(outbox, new Socket.CloseEvent(1000))
81
- }).pipe(Effect.catchTags({
82
- "PersistentPty.NotFoundError": () => Effect.succeed(void 0),
83
- "PersistentPty.UnavailableError": () => Effect.succeed(void 0)
84
- }));
85
- if (!attachment) {
86
- Queue.offerUnsafe(outbox, new Socket.CloseEvent(4404, "terminal unavailable"));
87
- return;
88
- }
89
- Queue.offerUnsafe(outbox, JSON.stringify({
90
- type: "attached",
91
- attachmentID,
92
- inputProtocol: framedInput ? 1 : 0,
93
- info: attachment.info,
94
- role: attachment.role,
95
- generation: attachment.generation,
96
- replay: {
97
- requestedOffset: attachment.replay.requestedOffset,
98
- availableOffset: attachment.replay.availableOffset,
99
- endOffset: attachment.replay.endOffset,
100
- truncated: attachment.replay.truncated
101
- }
102
- }));
103
- if (attachment.replay.data.length > 0)
104
- Queue.offerUnsafe(outbox, attachment.replay.data);
105
- Queue.offerUnsafe(outbox, JSON.stringify({ type: "replay_complete", endOffset: attachment.replay.endOffset }));
106
- attachment.activate();
107
- }), drain = Effect.gen(function* () {
108
- while (!0) {
109
- const item = yield* Queue.take(outbox);
110
- yield* write(item);
111
- if (item instanceof Socket.CloseEvent)
112
- return;
113
- }
114
- });
115
- yield* runPtySocket(drain, socket.runRaw((message) => input.withPermit(Effect.suspend(() => {
116
- if (!attachment)
117
- return Effect.void;
118
- const data = typeof message === "string" ? Buffer.from(message) : message;
119
- if (!framedInput)
120
- return pty.input(ctx.params.ptyID, attachmentID, attachment.info.size.cols, attachment.info.size.rows, data).pipe(Effect.ignore);
121
- if (data.byteLength < 5)
122
- return Effect.void;
123
- const view = new DataView(data.buffer, data.byteOffset, data.byteLength), type = data[0], cols = view.getUint16(1), rows = view.getUint16(3);
124
- if (type !== 0 && type !== 1 || cols === 0 || rows === 0)
125
- return Effect.void;
126
- if (type === 0)
127
- return pty.control(ctx.params.ptyID, attachmentID, cols, rows).pipe(Effect.ignore);
128
- return pty.input(ctx.params.ptyID, attachmentID, cols, rows, data.subarray(5)).pipe(Effect.ignore);
129
- })), { onOpen }), () => attachment?.detach()).pipe(Effect.catchReason("SocketError", "SocketCloseError", () => Effect.void), Effect.orDie);
130
- return HttpServerResponse.empty();
131
- }));
132
- }));
133
- const mapUnavailable = (effect) => effect.pipe(Effect.catchTag("PersistentPty.UnavailableError", unavailable)), mapTerminalError = (effect) => effect.pipe(Effect.catchTags({
134
- "PersistentPty.NotFoundError": (error) => new PtyNotFoundError({ ptyID: error.ptyID, message: `PTY session not found: ${error.ptyID}` }),
135
- "PersistentPty.UnavailableError": unavailable
136
- })), unavailable = (error) => new ServiceUnavailableError({ message: error.message, service: "opencode-pty" });
2
+ PersistentPtyHandler2
3
+ } from "../chunks/auth-0qzy9yxk.js";
4
+ import"../chunks/auth-hezj1jdf.js";
5
+ import"../chunks/auth-q4bn6dy8.js";
6
+ import"../chunks/auth-z6kg9h7e.js";
7
+ import"../chunks/auth-23w8t84j.js";
8
+ import"../chunks/auth-frv6gfy7.js";
9
+ import"../chunks/auth-0ar9gf7q.js";
10
+ import"../chunks/auth-smaf4a18.js";
11
+ export {
12
+ PersistentPtyHandler2 as PersistentPtyHandler
13
+ };
@@ -1,47 +1,11 @@
1
- import { Plugin } from "@opencode/core/plugin";
2
- import { PluginUpdate } from "@opencode/core/plugin/update";
3
- import { InvalidRequestError, ServiceUnavailableError } from "@opencode/protocol/errors";
4
- import { Cause, Effect, Exit } from "effect";
5
- import { HttpApiBuilder } from "effect/unstable/httpapi";
6
- import { Api } from "../api";
7
- import { response } from "../location";
8
- export const PluginHandler = HttpApiBuilder.group(Api, "server.plugin", (handlers) => handlers.handle("plugin.list", () => Effect.gen(function* () {
9
- return yield* response(Plugin.Service.use((plugin) => plugin.list()));
10
- })).handle("plugin.check", (ctx) => Effect.gen(function* () {
11
- const inventory = yield* (yield* Plugin.Service).list(), targets = [
12
- ...new Set(inventory.flatMap((plugin) => plugin.source.type === "package" ? [plugin.source.target] : []))
13
- ].filter((target) => ctx.payload.target === void 0 || target === ctx.payload.target);
14
- if (ctx.payload.target !== void 0 && !targets.length)
15
- return yield* new InvalidRequestError({
16
- message: `Plugin package is not in the current server inventory: ${ctx.payload.target}`,
17
- field: "target"
18
- });
19
- const updates = yield* PluginUpdate.Service, outdated = new Map(yield* Effect.forEach(targets, (target) => updates.check(target, { refresh: !0 }).pipe(Effect.map((value) => [target, value])), { concurrency: "unbounded" }));
20
- return yield* response(Effect.succeed(inventory.map((plugin) => {
21
- if (plugin.source.type !== "package" || !outdated.has(plugin.source.target))
22
- return plugin;
23
- return {
24
- ...plugin,
25
- source: {
26
- type: "package",
27
- target: plugin.source.target,
28
- ...plugin.source.version ? { version: plugin.source.version } : {},
29
- ...outdated.get(plugin.source.target) ? { outdated: !0 } : {},
30
- ...plugin.source.updating ? { updating: !0 } : {}
31
- }
32
- };
33
- })));
34
- })).handle("plugin.update", (ctx) => Effect.gen(function* () {
35
- const plugins = yield* Plugin.Service, inventory = new Set((yield* plugins.list()).flatMap((plugin) => plugin.source.type === "package" ? [plugin.source.target] : [])), unknown = ctx.payload.targets.filter((target) => !inventory.has(target));
36
- if (unknown.length)
37
- return yield* new InvalidRequestError({
38
- message: `Plugin packages are not in the current server inventory: ${unknown.join(", ")}`,
39
- field: "targets"
40
- });
41
- const updates = yield* PluginUpdate.Service, failures = yield* Effect.forEach(ctx.payload.targets, (target) => updates.update(target).pipe(Effect.exit, Effect.map((exit) => Exit.isFailure(exit) ? [`${target}: ${Cause.pretty(exit.cause)}`] : [])), { concurrency: "unbounded" }).pipe(Effect.map((results) => results.flat()));
42
- if (failures.length)
43
- return yield* new ServiceUnavailableError({
44
- message: `Failed to update plugin packages: ${failures.join("; ")}`,
45
- service: "plugin"
46
- });
47
- })));
1
+ import {
2
+ PluginHandler2
3
+ } from "../chunks/auth-vgxn80m1.js";
4
+ import"../chunks/auth-z6kg9h7e.js";
5
+ import"../chunks/auth-23w8t84j.js";
6
+ import"../chunks/auth-frv6gfy7.js";
7
+ import"../chunks/auth-0ar9gf7q.js";
8
+ import"../chunks/auth-smaf4a18.js";
9
+ export {
10
+ PluginHandler2 as PluginHandler
11
+ };
@@ -1,9 +1,11 @@
1
- import { Project } from "@opencode/core/project";
2
- import { Effect } from "effect";
3
- import { HttpApiBuilder } from "effect/unstable/httpapi";
4
- import { Api } from "../api";
5
- import { ProjectNotFoundError } from "@opencode/protocol/errors";
6
- export const ProjectHandler = HttpApiBuilder.group(Api, "server.project", (handlers) => handlers.handle("project.list", () => Project.Service.use((project) => project.list())).handle("project.update", (ctx) => Project.Service.use((project) => project.update({ ...ctx.payload, projectID: ctx.params.projectID }).pipe(Effect.mapError(() => new ProjectNotFoundError({
7
- projectID: ctx.params.projectID,
8
- message: `Project not found: ${ctx.params.projectID}`
9
- }))))));
1
+ import {
2
+ ProjectHandler2
3
+ } from "../chunks/auth-7qtja2kq.js";
4
+ import"../chunks/auth-z6kg9h7e.js";
5
+ import"../chunks/auth-23w8t84j.js";
6
+ import"../chunks/auth-frv6gfy7.js";
7
+ import"../chunks/auth-0ar9gf7q.js";
8
+ import"../chunks/auth-smaf4a18.js";
9
+ export {
10
+ ProjectHandler2 as ProjectHandler
11
+ };