@opencode/server 2.0.7 → 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
package/dist/handlers.js CHANGED
@@ -1,33 +1,46 @@
1
- import { Layer } from "effect";
2
- import { GenerateHandler } from "./handlers/generate";
3
- import { MessageHandler } from "./handlers/message";
4
- import { ModelHandler } from "./handlers/model";
5
- import { ProviderHandler } from "./handlers/provider";
6
- import { SessionHandler } from "./handlers/session";
7
- import { PermissionHandler } from "./handlers/permission";
8
- import { FileSystemHandler } from "./handlers/fs";
9
- import { FormHandler } from "./handlers/form";
10
- import { CommandHandler } from "./handlers/command";
11
- import { SkillHandler } from "./handlers/skill";
12
- import { RpcHandler } from "./handlers/rpc";
13
- import { EventHandler } from "./handlers/event";
14
- import { AgentHandler } from "./handlers/agent";
15
- import { PluginHandler } from "./handlers/plugin";
16
- import { ServerHandler } from "./handlers/server";
17
- import { DebugHandler } from "./handlers/debug";
18
- import { PtyHandler } from "./handlers/pty";
19
- import { PersistentPtyHandler } from "./handlers/persistent-pty";
20
- import { ShellHandler } from "./handlers/shell";
21
- import { ReferenceHandler } from "./handlers/reference";
22
- import { LocationHandler } from "./handlers/location";
23
- import { IntegrationHandler } from "./handlers/integration";
24
- import { WebSearchHandler } from "./handlers/websearch";
25
- import { McpHandler } from "./handlers/mcp";
26
- import { CredentialHandler } from "./handlers/credential";
27
- import { ProjectHandler } from "./handlers/project";
28
- import { WorktreeHandler } from "./handlers/worktree";
29
- import { VcsHandler } from "./handlers/vcs";
30
- import { EventFeed } from "./event-feed";
31
- import { MigrationHandler } from "./handlers/migration";
32
- import { ConfigHandler } from "./handlers/config";
33
- export const handlers = Layer.mergeAll(ServerHandler, DebugHandler, MigrationHandler, LocationHandler, AgentHandler, PluginHandler, SessionHandler, MessageHandler, ModelHandler, GenerateHandler, ProviderHandler, IntegrationHandler, WebSearchHandler, McpHandler, CredentialHandler, ProjectHandler, FormHandler, PermissionHandler, FileSystemHandler, CommandHandler, SkillHandler, RpcHandler, EventHandler.pipe(Layer.provide(EventFeed.layer)), PtyHandler, PersistentPtyHandler, ShellHandler, ReferenceHandler, WorktreeHandler, VcsHandler, ConfigHandler);
1
+ import {
2
+ handlers2
3
+ } from "./chunks/fetch-csspsf0t.js";
4
+ import"./chunks/fetch-4vn5bvkr.js";
5
+ import"./chunks/fetch-br99j6q1.js";
6
+ import"./chunks/fetch-qnwpcgp7.js";
7
+ import"./chunks/fetch-req22b70.js";
8
+ import"./chunks/fetch-04xw3v55.js";
9
+ import"./chunks/fetch-bjrwanme.js";
10
+ import"./chunks/fetch-ceh2h0m9.js";
11
+ import"./chunks/fetch-8bajbwjh.js";
12
+ import"./chunks/fetch-hjnxtxmk.js";
13
+ import"./chunks/fetch-254zvkj6.js";
14
+ import"./chunks/fetch-a6yp8301.js";
15
+ import"./chunks/fetch-rcg4y18n.js";
16
+ import"./chunks/fetch-6nvan4e0.js";
17
+ import"./chunks/fetch-r7e9r02j.js";
18
+ import"./chunks/fetch-ychamt23.js";
19
+ import"./chunks/fetch-ysabas57.js";
20
+ import"./chunks/fetch-j2pfq4q6.js";
21
+ import"./chunks/fetch-19c9ysa1.js";
22
+ import"./chunks/fetch-1c4qas2w.js";
23
+ import"./chunks/fetch-7rzt3wm8.js";
24
+ import"./chunks/fetch-zp2jm6dt.js";
25
+ import"./chunks/fetch-q0ycym90.js";
26
+ import"./chunks/fetch-pnqq1zxv.js";
27
+ import"./chunks/fetch-4g0fa6m0.js";
28
+ import"./chunks/fetch-4cf3x1kw.js";
29
+ import"./chunks/fetch-d4bshj6j.js";
30
+ import"./chunks/fetch-00nn3k4b.js";
31
+ import"./chunks/fetch-n0er2m55.js";
32
+ import"./chunks/fetch-hezj1jdf.js";
33
+ import"./chunks/fetch-b0b71rwa.js";
34
+ import"./chunks/fetch-arj41x43.js";
35
+ import"./chunks/fetch-s4aja1df.js";
36
+ import"./chunks/fetch-q4bn6dy8.js";
37
+ import"./chunks/fetch-0d9kah4z.js";
38
+ import"./chunks/fetch-z5shrcz9.js";
39
+ import"./chunks/fetch-3kzx88w9.js";
40
+ import"./chunks/fetch-5rwqcaw2.js";
41
+ import"./chunks/fetch-6gkz39ey.js";
42
+ import"./chunks/fetch-smaf4a18.js";
43
+ import"./chunks/fetch-99sfd1j8.js";
44
+ export {
45
+ handlers2 as handlers
46
+ };
package/dist/location.js CHANGED
@@ -1,49 +1,15 @@
1
- import { Location } from "@opencode/core/location";
2
- import { LocationServiceMap } from "@opencode/core/location-services";
3
- import { AbsolutePath } from "@opencode/core/schema";
4
- import { Session } from "@opencode/core/session";
5
- import { InvalidRequestError } from "@opencode/protocol/errors";
6
- import { Effect, Layer, Schema } from "effect";
7
- import { HttpServerRequest } from "effect/unstable/http";
8
- import { HttpApiMiddleware } from "effect/unstable/httpapi";
9
- import { missingSession } from "./handlers/session-error";
10
-
11
- export class LocationMiddleware extends HttpApiMiddleware.Service()("@opencode/HttpApiLocation") {
12
- }
13
- export function response(data) {
14
- return Effect.gen(function* () {
15
- const location = yield* Location.Service;
16
- return {
17
- location: new Location.Info({
18
- directory: location.directory,
19
- project: location.project
20
- }),
21
- data: yield* data
22
- };
23
- });
24
- }
25
- const decodeSessionID = Schema.decodeUnknownEffect(Session.ID);
26
- export const sessionInfo = Effect.fnUntraced(function* (sessions, sessionID) {
27
- const id = yield* decodeSessionID(sessionID).pipe(Effect.mapError(() => new InvalidRequestError({ message: "Invalid session ID", field: "sessionID" })));
28
- return yield* sessions.get(id).pipe(Effect.catchTag("Session.NotFoundError", missingSession));
29
- });
30
- export function requestRef(request) {
31
- const directory = new URL(request.url, "http://localhost").searchParams.get("location[directory]") || (request.headers["x-opencode-directory"] ? decode(request.headers["x-opencode-directory"]) : process.cwd());
32
- return Location.Ref.make({
33
- directory: AbsolutePath.make(directory)
34
- });
35
- }
36
- function decode(input) {
37
- try {
38
- return decodeURIComponent(input);
39
- } catch {
40
- return input;
41
- }
42
- }
43
- export const layer = Layer.effect(LocationMiddleware, Effect.gen(function* () {
44
- const locations = yield* LocationServiceMap.Service;
45
- return LocationMiddleware.of((effect) => Effect.gen(function* () {
46
- const request = yield* HttpServerRequest.HttpServerRequest;
47
- return yield* effect.pipe(Effect.provide(locations.get(requestRef(request))));
48
- }));
49
- }));
1
+ import {
2
+ LocationMiddleware2,
3
+ response2,
4
+ sessionInfo2,
5
+ requestRef2,
6
+ layer4
7
+ } from "./chunks/fetch-6gkz39ey.js";
8
+ import"./chunks/fetch-smaf4a18.js";
9
+ export {
10
+ LocationMiddleware2 as LocationMiddleware,
11
+ layer4 as layer,
12
+ requestRef2 as requestRef,
13
+ response2 as response,
14
+ sessionInfo2 as sessionInfo
15
+ };
@@ -1,49 +1,11 @@
1
- import { ServerAuth } from "../auth";
2
- import { UnauthorizedError } from "@opencode/protocol/errors";
3
- import { Authorization } from "@opencode/protocol/middleware/authorization";
4
- export { Authorization } from "@opencode/protocol/middleware/authorization";
5
- import { hasPtyConnectTicketURL } from "@opencode/protocol/groups/pty";
6
- import { hasPersistentPtyConnectTicketURL } from "@opencode/protocol/groups/persistent-pty";
7
- import { Effect, Encoding, Layer, Redacted } from "effect";
8
- import { HttpEffect, HttpServerRequest, HttpServerResponse } from "effect/unstable/http";
9
- const AUTH_TOKEN_QUERY = "auth_token", WWW_AUTHENTICATE = 'Basic realm="Secure Area"';
10
- function emptyCredential() {
11
- return { username: "", password: Redacted.make("") };
12
- }
13
- function decodeCredential(input) {
14
- return Effect.fromResult(Encoding.decodeBase64String(input)).pipe(Effect.match({
15
- onFailure: emptyCredential,
16
- onSuccess: (header) => {
17
- const separator = header.indexOf(":");
18
- if (separator === -1)
19
- return emptyCredential();
20
- return { username: header.slice(0, separator), password: Redacted.make(header.slice(separator + 1)) };
21
- }
22
- }));
23
- }
24
- function credentialFromRequest(request) {
25
- const token = new URL(request.url, "http://localhost").searchParams.get(AUTH_TOKEN_QUERY);
26
- if (token)
27
- return decodeCredential(token);
28
- const match = /^Basic\s+(.+)$/i.exec(request.headers.authorization ?? "");
29
- if (match)
30
- return decodeCredential(match[1]);
31
- return Effect.succeed(emptyCredential());
32
- }
33
- export function authorizedRequest(request, config) {
34
- return credentialFromRequest(request).pipe(Effect.map((credential) => ServerAuth.authorized(credential, config)));
35
- }
36
- export const authorizationLayer = Layer.effect(Authorization, Effect.gen(function* () {
37
- const config = yield* ServerAuth.Config;
38
- if (!ServerAuth.required(config))
39
- return Authorization.of((effect) => effect);
40
- return Authorization.of((effect) => Effect.gen(function* () {
41
- const request = yield* HttpServerRequest.HttpServerRequest, url = new URL(request.url, "http://localhost");
42
- if (hasPtyConnectTicketURL(url) || hasPersistentPtyConnectTicketURL(url))
43
- return yield* effect;
44
- if (yield* authorizedRequest(request, config))
45
- return yield* effect;
46
- yield* HttpEffect.appendPreResponseHandler((_request, response) => Effect.succeed(HttpServerResponse.setHeader(response, "www-authenticate", WWW_AUTHENTICATE)));
47
- return yield* new UnauthorizedError({ message: "Authentication required" });
48
- }));
49
- }));
1
+ import {
2
+ authorizedRequest2,
3
+ authorizationLayer2,
4
+ Authorization2
5
+ } from "../chunks/fetch-m6wvgbfq.js";
6
+ import"../chunks/fetch-zyv89x5n.js";
7
+ export {
8
+ Authorization2 as Authorization,
9
+ authorizationLayer2 as authorizationLayer,
10
+ authorizedRequest2 as authorizedRequest
11
+ };
@@ -1,25 +1,10 @@
1
- import { Instance } from "@opencode/core/instance/service";
2
- import { LocationServiceMap } from "@opencode/core/location-services";
3
- import { Session } from "@opencode/core/session";
4
- import { InvalidRequestError, SessionNotFoundError } from "@opencode/protocol/errors";
5
- import { Effect, Layer } from "effect";
6
- import { HttpRouter, HttpServerRequest } from "effect/unstable/http";
7
- import { HttpApiMiddleware } from "effect/unstable/httpapi";
8
- import { requestRef, sessionInfo } from "../location";
9
-
10
- export class FormLocationMiddleware extends HttpApiMiddleware.Service()("@opencode/HttpApiFormLocation", {
11
- error: [InvalidRequestError, SessionNotFoundError]
12
- }) {
13
- }
14
- export const formLocationLayer = Layer.effect(FormLocationMiddleware, Effect.gen(function* () {
15
- const sessions = yield* Session.Service, instances = yield* Instance.Service, locations = yield* LocationServiceMap.Service;
16
- return FormLocationMiddleware.of((effect) => Effect.gen(function* () {
17
- const route = yield* HttpRouter.RouteContext;
18
- if (route.params.sessionID === "global") {
19
- const request = yield* HttpServerRequest.HttpServerRequest;
20
- return yield* effect.pipe(Effect.provide(locations.get(requestRef(request))));
21
- }
22
- const session = yield* sessionInfo(sessions, route.params.sessionID);
23
- return yield* effect.pipe(instances.provide(session));
24
- }));
25
- }));
1
+ import {
2
+ FormLocationMiddleware2,
3
+ formLocationLayer2
4
+ } from "../chunks/fetch-5rwqcaw2.js";
5
+ import"../chunks/fetch-6gkz39ey.js";
6
+ import"../chunks/fetch-smaf4a18.js";
7
+ export {
8
+ FormLocationMiddleware2 as FormLocationMiddleware,
9
+ formLocationLayer2 as formLocationLayer
10
+ };
@@ -1,15 +1,8 @@
1
- import { Effect } from "effect";
2
- import { HttpApiMiddleware } from "effect/unstable/httpapi";
3
- import { InvalidRequestError } from "@opencode/protocol/errors";
4
- import { SchemaErrorMiddleware } from "@opencode/protocol/middleware/schema-error";
5
- export { SchemaErrorMiddleware } from "@opencode/protocol/middleware/schema-error";
6
- const REASON_LIMIT = 1024;
7
- function truncateReason(reason) {
8
- if (reason.length <= REASON_LIMIT)
9
- return reason;
10
- return reason.slice(0, REASON_LIMIT) + `... (${reason.length - REASON_LIMIT} more chars)`;
11
- }
12
- export const schemaErrorLayer = HttpApiMiddleware.layerSchemaErrorTransform(SchemaErrorMiddleware, (error) => {
13
- const reason = truncateReason(error.cause.message);
14
- return Effect.logWarning("schema rejection").pipe(Effect.annotateLogs({ kind: error.kind, reason }), Effect.andThen(Effect.fail(new InvalidRequestError({ message: reason, kind: error.kind }))));
15
- });
1
+ import {
2
+ schemaErrorLayer2,
3
+ SchemaErrorMiddleware2
4
+ } from "../chunks/fetch-t8yzmczr.js";
5
+ export {
6
+ SchemaErrorMiddleware2 as SchemaErrorMiddleware,
7
+ schemaErrorLayer2 as schemaErrorLayer
8
+ };
@@ -1,19 +1,10 @@
1
- import { Instance } from "@opencode/core/instance/service";
2
- import { Session } from "@opencode/core/session";
3
- import { Effect, Layer } from "effect";
4
- import { HttpRouter } from "effect/unstable/http";
5
- import { HttpApiMiddleware } from "effect/unstable/httpapi";
6
- import { InvalidRequestError, SessionNotFoundError } from "@opencode/protocol/errors";
7
- import { sessionInfo } from "../location";
8
-
9
- export class SessionLocationMiddleware extends HttpApiMiddleware.Service()("@opencode/HttpApiSessionLocation", {
10
- error: [InvalidRequestError, SessionNotFoundError]
11
- }) {
12
- }
13
- export const sessionLocationLayer = Layer.effect(SessionLocationMiddleware, Effect.gen(function* () {
14
- const sessions = yield* Session.Service, instances = yield* Instance.Service;
15
- return SessionLocationMiddleware.of((effect) => Effect.gen(function* () {
16
- const route = yield* HttpRouter.RouteContext, session = yield* sessionInfo(sessions, route.params.sessionID);
17
- return yield* effect.pipe(instances.provide(session));
18
- }));
19
- }));
1
+ import {
2
+ SessionLocationMiddleware2,
3
+ sessionLocationLayer2
4
+ } from "../chunks/fetch-3kzx88w9.js";
5
+ import"../chunks/fetch-6gkz39ey.js";
6
+ import"../chunks/fetch-smaf4a18.js";
7
+ export {
8
+ SessionLocationMiddleware2 as SessionLocationMiddleware,
9
+ sessionLocationLayer2 as sessionLocationLayer
10
+ };
package/dist/options.js CHANGED
@@ -1,8 +1,9 @@
1
+ // src/options.ts
1
2
  import { Database } from "@opencode/core/database/database";
2
3
  import { ModelsDev } from "@opencode/core/models-dev";
3
4
  import { PersistentPty } from "@opencode/core/persistent-pty";
4
5
  import { Schema } from "effect";
5
- export const ServerOptions = Schema.Struct({
6
+ var ServerOptions = Schema.Struct({
6
7
  app: Schema.optional(Schema.Struct({
7
8
  name: Schema.optional(Schema.String),
8
9
  version: Schema.optional(Schema.String),
@@ -33,3 +34,6 @@ export const ServerOptions = Schema.Struct({
33
34
  fff: Schema.optional(Schema.Boolean)
34
35
  }))
35
36
  });
37
+ export {
38
+ ServerOptions
39
+ };
package/dist/process.js CHANGED
@@ -1,4 +1,74 @@
1
- export * as ServerProcess from "./process";
1
+ import {
2
+ Config2
3
+ } from "./chunks/fetch-zyv89x5n.js";
4
+ import {
5
+ isAllowedCorsOrigin2
6
+ } from "./chunks/fetch-q4bn6dy8.js";
7
+ import {
8
+ authorizedRequest2
9
+ } from "./chunks/fetch-m6wvgbfq.js";
10
+ import {
11
+ withoutParentSpan2
12
+ } from "./chunks/fetch-yc7nft6q.js";
13
+ import"./chunks/fetch-smaf4a18.js";
14
+ import"./chunks/fetch-6gkz39ey.js";
15
+ import"./chunks/fetch-5rwqcaw2.js";
16
+ import"./chunks/fetch-3kzx88w9.js";
17
+ import"./chunks/fetch-z5shrcz9.js";
18
+ import"./chunks/fetch-4vn5bvkr.js";
19
+ import"./chunks/fetch-rcg4y18n.js";
20
+ import"./chunks/fetch-254zvkj6.js";
21
+ import"./chunks/fetch-pnqq1zxv.js";
22
+ import"./chunks/fetch-1c4qas2w.js";
23
+ import"./chunks/fetch-arj41x43.js";
24
+ import"./chunks/fetch-hjnxtxmk.js";
25
+ import"./chunks/fetch-6nvan4e0.js";
26
+ import"./chunks/fetch-r7e9r02j.js";
27
+ import"./chunks/fetch-q0ycym90.js";
28
+ import"./chunks/fetch-bjrwanme.js";
29
+ import"./chunks/fetch-99sfd1j8.js";
30
+ import"./chunks/fetch-d4bshj6j.js";
31
+ import"./chunks/fetch-ceh2h0m9.js";
32
+ import"./chunks/fetch-19c9ysa1.js";
33
+ import {
34
+ connectionURLs2
35
+ } from "./chunks/fetch-s4aja1df.js";
36
+ import"./chunks/fetch-4cf3x1kw.js";
37
+ import"./chunks/fetch-00nn3k4b.js";
38
+ import"./chunks/fetch-0d9kah4z.js";
39
+ import"./chunks/fetch-hezj1jdf.js";
40
+ import"./chunks/fetch-ychamt23.js";
41
+ import"./chunks/fetch-n0er2m55.js";
42
+ import"./chunks/fetch-br99j6q1.js";
43
+ import"./chunks/fetch-ysabas57.js";
44
+ import"./chunks/fetch-req22b70.js";
45
+ import"./chunks/fetch-a6yp8301.js";
46
+ import"./chunks/fetch-b0b71rwa.js";
47
+ import"./chunks/fetch-8bajbwjh.js";
48
+ import"./chunks/fetch-04xw3v55.js";
49
+ import"./chunks/fetch-zp2jm6dt.js";
50
+ import"./chunks/fetch-j2pfq4q6.js";
51
+ import"./chunks/fetch-4g0fa6m0.js";
52
+ import"./chunks/fetch-7rzt3wm8.js";
53
+ import"./chunks/fetch-qnwpcgp7.js";
54
+ import"./chunks/fetch-csspsf0t.js";
55
+ import"./chunks/fetch-t8yzmczr.js";
56
+ import {
57
+ createRoutes2
58
+ } from "./chunks/fetch-vgpejxxy.js";
59
+ import {
60
+ make2
61
+ } from "./chunks/fetch-xsrtpxyd.js";
62
+ import {
63
+ __export
64
+ } from "./chunks/fetch-9rqn6x4v.js";
65
+
66
+ // src/process.ts
67
+ var exports_process = {};
68
+ __export(exports_process, {
69
+ ServerProcess: () => exports_process,
70
+ start: () => start
71
+ });
2
72
  import { NodeHttpServer } from "@effect/platform-node";
3
73
  import { Bus } from "@opencode/core/bus";
4
74
  import { SessionRestart } from "@opencode/core/session/execution/restart";
@@ -11,42 +81,42 @@ import {
11
81
  HttpMiddleware,
12
82
  HttpPlatform,
13
83
  HttpRouter,
14
- HttpServer,
15
84
  HttpServerRequest,
16
85
  HttpServerResponse
17
86
  } from "effect/unstable/http";
18
87
  import { createServer } from "node:http";
19
- import { ServerAuth } from "./auth";
20
- import { isAllowedCorsOrigin } from "./cors";
21
- import { authorizedRequest } from "./middleware/authorization";
22
- import { withoutParentSpan } from "./request-tracing";
23
- import { createRoutes } from "./routes";
24
- import { ServerInfo } from "./server-info";
25
- import { Status } from "./service-status";
26
- const errorResponseLogger = HttpMiddleware.make((app) => HttpMiddleware.logger(Effect.tap(app, (response) => response.status < 400 ? HttpMiddleware.withLoggerDisabled(Effect.void) : Effect.void)));
27
- export const start = Effect.fn("ServerProcess.start")(function* (options, lifecycle, transform) {
88
+ var errorResponseLogger = HttpMiddleware.make((app) => HttpMiddleware.logger(Effect.tap(app, (response) => response.status < 400 ? HttpMiddleware.withLoggerDisabled(Effect.void) : Effect.void)));
89
+ var start = Effect.fn("ServerProcess.start")(function* (options, lifecycle, transform) {
28
90
  const password = options.password;
29
91
  if (!password)
30
- return yield* Effect.fail(Error("Missing server password"));
31
- const hostname = options.hostname ?? "127.0.0.1", port = Option.fromNullishOr(options.port), shutdown = yield* Latch.make(), status = yield* Status.make(), bound = yield* listen({ hostname, port }), urls = () => {
92
+ return yield* Effect.fail(new Error("Missing server password"));
93
+ const hostname = options.hostname ?? "127.0.0.1";
94
+ const port = Option.fromNullishOr(options.port);
95
+ const shutdown = yield* Latch.make();
96
+ const status = yield* make2();
97
+ const bound = yield* listen({ hostname, port });
98
+ const urls = () => {
32
99
  const address = bound.server.address();
33
100
  if (address === null || typeof address === "string")
34
101
  return [];
35
102
  const host = address.family === "IPv6" ? `[${address.address}]` : address.address;
36
- return ServerInfo.connectionURLs(`http://${host}:${address.port}`, hostname);
37
- }, application = yield* Ref.make(Option.none());
38
- yield* bound.http.serve(dispatch(password, status, application, options.app?.version ?? "unknown", urls, Global.Path.tmp).pipe(HttpMiddleware.cors({ allowedOrigins: (origin) => isAllowedCorsOrigin(origin, options), maxAge: 86400 })), errorResponseLogger).pipe(withoutParentSpan);
103
+ return connectionURLs2(`http://${host}:${address.port}`, hostname);
104
+ };
105
+ const application = yield* Ref.make(Option.none());
106
+ yield* bound.http.serve(dispatch(password, status, application, options.app?.version ?? "unknown", urls, Global.Path.tmp).pipe(HttpMiddleware.cors({ allowedOrigins: (origin) => isAllowedCorsOrigin2(origin, options), maxAge: 86400 })), errorResponseLogger).pipe(withoutParentSpan2);
39
107
  if (lifecycle)
40
108
  yield* lifecycle.onListen(bound.http.address, shutdown.open.pipe(Effect.asVoid)).pipe(Effect.flatMap((cleanup) => Effect.addFinalizer(() => Scope.close(bound.scope, Exit.void).pipe(Effect.andThen(cleanup)))), Effect.uninterruptible);
41
- const parentScope = yield* Scope.Scope, applicationScope = yield* Scope.fork(parentScope);
109
+ const parentScope = yield* Scope.Scope;
110
+ const applicationScope = yield* Scope.fork(parentScope);
42
111
  yield* Effect.addFinalizer(() => status.beginStopping.pipe(Effect.andThen(Ref.set(application, Option.none())), Effect.andThen(Effect.sync(() => bound.server.closeAllConnections()))));
43
112
  const boot = Effect.gen(function* () {
44
- const context = yield* Layer.buildWithScope(createRoutes({
113
+ const context = yield* Layer.buildWithScope(createRoutes2({
45
114
  ...options,
46
115
  password
47
116
  }, urls).pipe(Layer.provideMerge(NodeHttpServer.layerHttpServices)), applicationScope);
48
- if (lifecycle)
117
+ if (lifecycle) {
49
118
  yield* installRestartContinuity(Context.get(context, SessionRestart.Service)).pipe(Effect.provideService(Scope.Scope, applicationScope));
119
+ }
50
120
  const app = Context.get(context, HttpRouter.HttpRouter).asHttpEffect().pipe(HttpMiddleware.compression(), Effect.provideService(HttpPlatform.HttpPlatform, Context.get(context, HttpPlatform.HttpPlatform)));
51
121
  yield* Ref.set(application, Option.some(transform ? transform(app) : app));
52
122
  yield* status.ready;
@@ -74,7 +144,9 @@ function listen(options) {
74
144
  }
75
145
  function bind(hostname, port) {
76
146
  return Effect.gen(function* () {
77
- const parentScope = yield* Scope.Scope, serverScope = yield* Scope.fork(parentScope), server = createServer();
147
+ const parentScope = yield* Scope.Scope;
148
+ const serverScope = yield* Scope.fork(parentScope);
149
+ const server = createServer();
78
150
  return yield* Effect.gen(function* () {
79
151
  const http = yield* NodeHttpServer.make(() => server, { port, host: hostname });
80
152
  yield* Effect.addFinalizer(() => Effect.sync(() => server.closeAllConnections()));
@@ -84,20 +156,24 @@ function bind(hostname, port) {
84
156
  }
85
157
  function addressInUse(error) {
86
158
  if (typeof error !== "object" || error === null || !("cause" in error))
87
- return !1;
159
+ return false;
88
160
  const cause = error.cause;
89
161
  return typeof cause === "object" && cause !== null && "code" in cause && cause.code === "EADDRINUSE";
90
162
  }
91
163
  function dispatch(password, status, application, version, urls, tmp) {
92
- const auth = ServerAuth.Config.of({ password: Option.some(password), username: "opencode" });
164
+ const auth = Config2.of({ password: Option.some(password), username: "opencode" });
93
165
  return Effect.gen(function* () {
94
- const request = yield* HttpServerRequest.HttpServerRequest, url = new URL(request.url, "http://localhost"), state = yield* status.current, app = yield* Ref.get(application), ready = state.type === "ready" && Option.isSome(app);
166
+ const request = yield* HttpServerRequest.HttpServerRequest;
167
+ const url = new URL(request.url, "http://localhost");
168
+ const state = yield* status.current;
169
+ const app = yield* Ref.get(application);
170
+ const ready = state.type === "ready" && Option.isSome(app);
95
171
  if (request.method === "GET" && url.pathname === "/api/info" && !ready) {
96
- if (!(yield* authorizedRequest(request, auth)))
172
+ if (!(yield* authorizedRequest2(request, auth)))
97
173
  return unauthorized();
98
174
  return yield* infoResponse(status, version, urls, tmp);
99
175
  }
100
- if ((!ready || !hasPtyConnectTicketURL(url) && !hasPersistentPtyConnectTicketURL(url)) && !(yield* authorizedRequest(request, auth)))
176
+ if ((!ready || !hasPtyConnectTicketURL(url) && !hasPersistentPtyConnectTicketURL(url)) && !(yield* authorizedRequest2(request, auth)))
101
177
  return unauthorized();
102
178
  if (ready)
103
179
  return yield* app.value;
@@ -110,11 +186,11 @@ function unauthorized() {
110
186
  headers: { "www-authenticate": 'Basic realm="Secure Area"' }
111
187
  });
112
188
  }
113
- const infoResponse = Effect.fnUntraced(function* (status, version, urls, tmp) {
189
+ var infoResponse = Effect.fnUntraced(function* (status, version, urls, tmp) {
114
190
  const state = yield* status.current;
115
191
  return HttpServerResponse.jsonUnsafe({ version, pid: process.pid, urls: urls(), paths: { tmp } }, {
116
192
  status: state.type === "ready" ? 200 : state.type === "failed" ? 500 : 503,
117
- headers: state.type === "starting" || state.type === "stopping" ? { "retry-after": "1" } : void 0
193
+ headers: state.type === "starting" || state.type === "stopping" ? { "retry-after": "1" } : undefined
118
194
  });
119
195
  });
120
196
  function unavailable(status) {
@@ -126,6 +202,10 @@ function unavailable(status) {
126
202
  }, { status: 503 });
127
203
  return HttpServerResponse.jsonUnsafe({ code: status.type === "stopping" ? "service_stopping" : "service_starting" }, { status: 503, headers: { "retry-after": "1" } });
128
204
  }
129
- const installRestartContinuity = Effect.fnUntraced(function* (restart) {
205
+ var installRestartContinuity = Effect.fnUntraced(function* (restart) {
130
206
  yield* Effect.forkScoped(restart.resumeSuspendedSessions);
131
207
  });
208
+ export {
209
+ exports_process as ServerProcess,
210
+ start
211
+ };
@@ -1,9 +1,12 @@
1
- export * as PtyEnvironment from "./pty-environment";
2
- import { Context, Effect, Layer } from "effect";
3
- import { makeGlobalNode } from "@opencode/util/effect/app-node";
4
-
5
- export class Service extends Context.Service()("@opencode/ServerPtyEnvironment") {
6
- }
7
- export const layer = Layer.succeed(Service, Service.of({
8
- get: () => Effect.succeed({})
9
- })), node = makeGlobalNode({ service: Service, layer, deps: [] });
1
+ import {
2
+ Service3,
3
+ layer3,
4
+ node2,
5
+ exports_pty_environment
6
+ } from "./chunks/fetch-0d9kah4z.js";
7
+ export {
8
+ exports_pty_environment as PtyEnvironment,
9
+ Service3 as Service,
10
+ layer3 as layer,
11
+ node2 as node
12
+ };
@@ -1,2 +1,6 @@
1
- import { Context, Effect, Scope, Tracer } from "effect";
2
- export const withoutParentSpan = (effect) => effect.pipe(Effect.updateContext((context) => Context.omit(Tracer.ParentSpan)(context)));
1
+ import {
2
+ withoutParentSpan2
3
+ } from "./chunks/fetch-yc7nft6q.js";
4
+ export {
5
+ withoutParentSpan2 as withoutParentSpan
6
+ };
package/dist/routes.d.ts CHANGED
@@ -24,7 +24,7 @@ import { HttpRouter } from "effect/unstable/http";
24
24
  import { Layer } from "effect";
25
25
  import { PtyEnvironment } from "./pty-environment";
26
26
  import type { ServerOptions } from "./options";
27
- export declare function createRoutes(options?: ServerOptions, serviceURLs?: () => ReadonlyArray<string>, overrides?: LayerNode.Replacements): Layer.Layer<Global.Service | Database.Service | Bus.Service | import("effect/unstable/http/HttpClient").HttpClient | Project.Service | Credential.Service | WellKnown.Service | Workspace.Service | PermissionSaved.Service | PersistentPty.Service | LocationServiceMap.Service | SdkPlugins.Service | PluginUpdate.Service | Session.Service | Job.Service | Instance.Service | Worktree.Service | SessionRestart.Service | PtyTicket.Service | SessionTransfer.Service | LocationActivity.Service | PtyEnvironment.Service | HttpRouter.HttpRouter, Error | PersistentPty.UnavailableError, import("effect/FileSystem").FileSystem | import("effect/Path").Path | import("effect/unstable/http/Etag").Generator | import("effect/unstable/http/HttpPlatform").HttpPlatform>;
27
+ export declare function createRoutes(options?: ServerOptions, serviceURLs?: () => ReadonlyArray<string>, overrides?: LayerNode.Replacements): Layer.Layer<Global.Service | Database.Service | Bus.Service | import("effect/unstable/http/HttpClient").HttpClient | Project.Service | Credential.Service | WellKnown.Service | Workspace.Service | PermissionSaved.Service | PersistentPty.Service | LocationServiceMap.Service | SdkPlugins.Service | PluginUpdate.Service | Job.Service | Session.Service | Worktree.Service | Instance.Service | SessionRestart.Service | PtyTicket.Service | SessionTransfer.Service | LocationActivity.Service | PtyEnvironment.Service | HttpRouter.HttpRouter, Error | PersistentPty.UnavailableError, import("effect/FileSystem").FileSystem | import("effect/Path").Path | import("effect/unstable/http/Etag").Generator | import("effect/unstable/http/HttpPlatform").HttpPlatform>;
28
28
  type InstanceNode = (replacements: () => LayerNode.Replacements) => LayerNode.Provider<Instance.Service, never, typeof Node.tags.values.global>;
29
- export declare function createEmbeddedRoutes(options?: ServerOptions, overrides?: LayerNode.Replacements, instances?: InstanceNode): Layer.Layer<Global.Service | Database.Service | Bus.Service | import("effect/unstable/http/HttpClient").HttpClient | Project.Service | Credential.Service | WellKnown.Service | Workspace.Service | PermissionSaved.Service | PersistentPty.Service | LocationServiceMap.Service | SdkPlugins.Service | PluginUpdate.Service | Session.Service | Job.Service | Instance.Service | Worktree.Service | SessionRestart.Service | PtyTicket.Service | SessionTransfer.Service | LocationActivity.Service | PtyEnvironment.Service | HttpRouter.HttpRouter, Error | PersistentPty.UnavailableError, import("effect/FileSystem").FileSystem | import("effect/Path").Path | import("effect/unstable/http/Etag").Generator | import("effect/unstable/http/HttpPlatform").HttpPlatform>;
29
+ export declare function createEmbeddedRoutes(options?: ServerOptions, overrides?: LayerNode.Replacements, instances?: InstanceNode): Layer.Layer<Global.Service | Database.Service | Bus.Service | import("effect/unstable/http/HttpClient").HttpClient | Project.Service | Credential.Service | WellKnown.Service | Workspace.Service | PermissionSaved.Service | PersistentPty.Service | LocationServiceMap.Service | SdkPlugins.Service | PluginUpdate.Service | Job.Service | Session.Service | Worktree.Service | Instance.Service | SessionRestart.Service | PtyTicket.Service | SessionTransfer.Service | LocationActivity.Service | PtyEnvironment.Service | HttpRouter.HttpRouter, Error | PersistentPty.UnavailableError, import("effect/FileSystem").FileSystem | import("effect/Path").Path | import("effect/unstable/http/Etag").Generator | import("effect/unstable/http/HttpPlatform").HttpPlatform>;
30
30
  export {};