@opencode/server 0.0.0-dev-20114 → 0.0.0-dev-20116

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 (110) hide show
  1. package/dist/api.js +5 -5
  2. package/dist/auth.d.ts +4 -0
  3. package/dist/auth.js +10 -2
  4. package/dist/chunks/{pty-environment-6nvan4e0.js → location-1aa7fc0d.js} +2 -2
  5. package/dist/chunks/{pty-environment-18k6g42r.js → location-1gshyx5c.js} +7 -7
  6. package/dist/chunks/{pty-environment-z5shrcz9.js → location-2v3qky60.js} +3 -3
  7. package/dist/chunks/{pty-environment-6gkz39ey.js → location-43k13dmj.js} +3 -3
  8. package/dist/chunks/{pty-environment-bjrwanme.js → location-50jg7xmc.js} +1 -1
  9. package/dist/chunks/{pty-environment-7rzt3wm8.js → location-5frajas6.js} +1 -1
  10. package/dist/chunks/{pty-environment-vpz7f20y.js → location-5w24ch67.js} +4 -4
  11. package/dist/chunks/{pty-environment-4g0fa6m0.js → location-7zxr3tkk.js} +2 -2
  12. package/dist/chunks/{pty-environment-q0ycym90.js → location-83rfx0sp.js} +2 -2
  13. package/dist/chunks/{pty-environment-7ztbq3kp.js → location-97q9zpj5.js} +33 -33
  14. package/dist/chunks/{pty-environment-4vn5bvkr.js → location-9vrrrs57.js} +1 -1
  15. package/dist/chunks/{pty-environment-gdvmrvey.js → location-ahxdh0dq.js} +2 -2
  16. package/dist/chunks/location-anm12x33.js +66 -0
  17. package/dist/chunks/{pty-environment-pnqq1zxv.js → location-b6gan3yw.js} +2 -2
  18. package/dist/chunks/{pty-environment-a6yp8301.js → location-bp2kj98m.js} +2 -2
  19. package/dist/chunks/{pty-environment-sedm9jvw.js → location-cd6r3a3k.js} +7 -7
  20. package/dist/chunks/{pty-environment-3kzx88w9.js → location-d65y46ag.js} +1 -1
  21. package/dist/chunks/{pty-environment-00nn3k4b.js → location-e3vgmqs2.js} +2 -2
  22. package/dist/chunks/{pty-environment-zp2jm6dt.js → location-eptkag0m.js} +1 -1
  23. package/dist/chunks/{pty-environment-8bajbwjh.js → location-epwv4y6g.js} +2 -2
  24. package/dist/chunks/{pty-environment-jm9b3xcv.js → location-eq3gyxjf.js} +4 -4
  25. package/dist/chunks/{pty-environment-ceh2h0m9.js → location-f2ryx3d8.js} +2 -2
  26. package/dist/chunks/{pty-environment-qnwpcgp7.js → location-fdfc8k8f.js} +1 -1
  27. package/dist/chunks/{pty-environment-m6wvgbfq.js → location-gtkdacvk.js} +28 -7
  28. package/dist/chunks/{pty-environment-b0b71rwa.js → location-h1w0a8ky.js} +2 -2
  29. package/dist/chunks/{pty-environment-r7e9r02j.js → location-h91pzmtp.js} +2 -2
  30. package/dist/chunks/{pty-environment-5rwqcaw2.js → location-hrfm0p6n.js} +1 -1
  31. package/dist/chunks/{pty-environment-c5m64enw.js → location-jbp1pw2x.js} +19 -15
  32. package/dist/chunks/{pty-environment-ysabas57.js → location-jd22znxy.js} +2 -2
  33. package/dist/chunks/{pty-environment-j2pfq4q6.js → location-jefcrg4z.js} +1 -1
  34. package/dist/chunks/{pty-environment-5qp6e77f.js → location-jsqc7hhj.js} +3 -3
  35. package/dist/chunks/{pty-environment-04xw3v55.js → location-n0k9wajg.js} +1 -1
  36. package/dist/chunks/{pty-environment-kmrabwkf.js → location-n9y13hgv.js} +10 -10
  37. package/dist/chunks/{pty-environment-arj41x43.js → location-p0qxanbk.js} +3 -3
  38. package/dist/chunks/{pty-environment-rcg4y18n.js → location-pqe05x32.js} +2 -2
  39. package/dist/chunks/{pty-environment-gtbdnsdy.js → location-q2f2v80b.js} +3 -3
  40. package/dist/chunks/{pty-environment-19c9ysa1.js → location-qmx5gmxb.js} +2 -2
  41. package/dist/chunks/location-rbn15j6z.js +35 -0
  42. package/dist/chunks/{pty-environment-br99j6q1.js → location-tsyxj4xh.js} +2 -2
  43. package/dist/chunks/{pty-environment-hjnxtxmk.js → location-vsmvcx85.js} +2 -2
  44. package/dist/chunks/location-whf1c5t3.js +53 -0
  45. package/dist/chunks/{pty-environment-0d9kah4z.js → location-wv5twc2g.js} +8 -8
  46. package/dist/chunks/{pty-environment-req22b70.js → location-y07r8paj.js} +1 -1
  47. package/dist/chunks/{pty-environment-254zvkj6.js → location-ybmm73jc.js} +2 -2
  48. package/dist/cors.js +1 -1
  49. package/dist/event-feed.js +7 -7
  50. package/dist/fetch.js +47 -46
  51. package/dist/handlers/agent.js +6 -6
  52. package/dist/handlers/command.js +6 -6
  53. package/dist/handlers/config.js +6 -6
  54. package/dist/handlers/credential.js +6 -6
  55. package/dist/handlers/debug.js +6 -6
  56. package/dist/handlers/event.js +7 -7
  57. package/dist/handlers/form.js +6 -6
  58. package/dist/handlers/fs.js +6 -6
  59. package/dist/handlers/generate.js +6 -6
  60. package/dist/handlers/integration.js +6 -6
  61. package/dist/handlers/location.js +6 -6
  62. package/dist/handlers/mcp.js +6 -6
  63. package/dist/handlers/message.js +6 -6
  64. package/dist/handlers/migration.js +6 -6
  65. package/dist/handlers/model.js +6 -6
  66. package/dist/handlers/permission.js +6 -6
  67. package/dist/handlers/persistent-pty.js +8 -8
  68. package/dist/handlers/plugin.js +6 -6
  69. package/dist/handlers/project.js +6 -6
  70. package/dist/handlers/provider.js +6 -6
  71. package/dist/handlers/pty-socket.js +1 -1
  72. package/dist/handlers/pty.js +9 -9
  73. package/dist/handlers/reference.js +6 -6
  74. package/dist/handlers/rpc.js +6 -6
  75. package/dist/handlers/server.d.ts +3 -1
  76. package/dist/handlers/server.js +9 -7
  77. package/dist/handlers/session-error.js +1 -1
  78. package/dist/handlers/session.js +6 -6
  79. package/dist/handlers/shell.js +6 -6
  80. package/dist/handlers/skill.js +6 -6
  81. package/dist/handlers/vcs.js +6 -6
  82. package/dist/handlers/websearch.js +6 -6
  83. package/dist/handlers/worktree.js +6 -6
  84. package/dist/handlers.d.ts +1 -1
  85. package/dist/handlers.js +43 -41
  86. package/dist/location.js +4 -4
  87. package/dist/middleware/authorization.d.ts +2 -1
  88. package/dist/middleware/authorization.js +5 -3
  89. package/dist/middleware/form-location.js +3 -3
  90. package/dist/middleware/schema-error.js +1 -1
  91. package/dist/middleware/session-location.js +3 -3
  92. package/dist/pairing.d.ts +13 -0
  93. package/dist/pairing.js +10 -0
  94. package/dist/process.js +56 -59
  95. package/dist/pty-environment.js +7 -7
  96. package/dist/request-tracing.js +1 -1
  97. package/dist/routes.d.ts +3 -2
  98. package/dist/routes.js +46 -45
  99. package/dist/server-info.js +5 -5
  100. package/dist/service-status.js +3 -3
  101. package/dist/workerd.js +48 -47
  102. package/package.json +8 -8
  103. package/dist/chunks/pty-environment-d3favc8w.js +0 -21
  104. package/dist/chunks/pty-environment-zyv89x5n.js +0 -30
  105. /package/dist/chunks/{pty-environment-9rqn6x4v.js → location-9rqn6x4v.js} +0 -0
  106. /package/dist/chunks/{pty-environment-hezj1jdf.js → location-hezj1jdf.js} +0 -0
  107. /package/dist/chunks/{pty-environment-q4bn6dy8.js → location-q4bn6dy8.js} +0 -0
  108. /package/dist/chunks/{pty-environment-smaf4a18.js → location-smaf4a18.js} +0 -0
  109. /package/dist/chunks/{pty-environment-t8yzmczr.js → location-t8yzmczr.js} +0 -0
  110. /package/dist/chunks/{pty-environment-yc7nft6q.js → location-yc7nft6q.js} +0 -0
@@ -1,8 +1,10 @@
1
1
  import {
2
2
  Config2,
3
3
  required2,
4
- authorized2
5
- } from "./pty-environment-zyv89x5n.js";
4
+ authorized2,
5
+ verifySession2,
6
+ sessionCookieName2
7
+ } from "./location-anm12x33.js";
6
8
 
7
9
  // src/middleware/authorization.ts
8
10
  import { UnauthorizedError } from "@opencode/protocol/errors";
@@ -10,6 +12,7 @@ import { Authorization } from "@opencode/protocol/middleware/authorization";
10
12
  import { Authorization as Authorization2 } from "@opencode/protocol/middleware/authorization";
11
13
  import { hasPtyConnectTicketURL } from "@opencode/protocol/groups/pty";
12
14
  import { hasPersistentPtyConnectTicketURL } from "@opencode/protocol/groups/persistent-pty";
15
+ import { isPairingConnectURL } from "@opencode/protocol/groups/server";
13
16
  import { Effect, Encoding, Layer, Redacted } from "effect";
14
17
  import { HttpEffect, HttpServerRequest, HttpServerResponse } from "effect/unstable/http";
15
18
  var AUTH_TOKEN_QUERY = "auth_token";
@@ -38,8 +41,25 @@ function credentialFromRequest(request) {
38
41
  return decodeCredential(match[1]);
39
42
  return Effect.succeed(emptyCredential());
40
43
  }
44
+ var UNAUTHORIZED_MESSAGE = "Authentication required";
45
+ function challengeRequest(request) {
46
+ const mode = request.headers["sec-fetch-mode"];
47
+ return mode === undefined || mode === "navigate";
48
+ }
49
+ function unauthorizedResponse2(request) {
50
+ return HttpServerResponse.jsonUnsafe({ _tag: "UnauthorizedError", message: UNAUTHORIZED_MESSAGE }, { status: 401, headers: challengeRequest(request) ? { "www-authenticate": WWW_AUTHENTICATE } : undefined });
51
+ }
41
52
  function authorizedRequest2(request, config) {
42
- return credentialFromRequest(request).pipe(Effect.map((credential) => authorized2(credential, config)));
53
+ return credentialFromRequest(request).pipe(Effect.map((credential) => authorized2(credential, config) || authorizedSessionCookie(request, config)));
54
+ }
55
+ function authorizedSessionCookie(request, config) {
56
+ const token = request.cookies[sessionCookieName2(request.headers.host)];
57
+ if (!token)
58
+ return false;
59
+ const origin = request.headers.origin;
60
+ if (origin !== undefined && URL.parse(origin)?.host !== request.headers.host)
61
+ return false;
62
+ return verifySession2(token, config);
43
63
  }
44
64
  var authorizationLayer2 = Layer.effect(Authorization, Effect.gen(function* () {
45
65
  const config = yield* Config2;
@@ -48,13 +68,14 @@ var authorizationLayer2 = Layer.effect(Authorization, Effect.gen(function* () {
48
68
  return Authorization.of((effect) => Effect.gen(function* () {
49
69
  const request = yield* HttpServerRequest.HttpServerRequest;
50
70
  const url = new URL(request.url, "http://localhost");
51
- if (hasPtyConnectTicketURL(url) || hasPersistentPtyConnectTicketURL(url))
71
+ if (hasPtyConnectTicketURL(url) || hasPersistentPtyConnectTicketURL(url) || isPairingConnectURL(url))
52
72
  return yield* effect;
53
73
  if (yield* authorizedRequest2(request, config))
54
74
  return yield* effect;
55
- yield* HttpEffect.appendPreResponseHandler((_request, response) => Effect.succeed(HttpServerResponse.setHeader(response, "www-authenticate", WWW_AUTHENTICATE)));
56
- return yield* new UnauthorizedError({ message: "Authentication required" });
75
+ if (challengeRequest(request))
76
+ yield* HttpEffect.appendPreResponseHandler((_request, response) => Effect.succeed(HttpServerResponse.setHeader(response, "www-authenticate", WWW_AUTHENTICATE)));
77
+ return yield* new UnauthorizedError({ message: UNAUTHORIZED_MESSAGE });
57
78
  }));
58
79
  }));
59
80
 
60
- export { authorizedRequest2, authorizationLayer2, Authorization2 };
81
+ export { unauthorizedResponse2, authorizedRequest2, authorizationLayer2, Authorization2 };
@@ -1,9 +1,9 @@
1
1
  import {
2
2
  response2
3
- } from "./pty-environment-6gkz39ey.js";
3
+ } from "./location-43k13dmj.js";
4
4
  import {
5
5
  Api2
6
- } from "./pty-environment-z5shrcz9.js";
6
+ } from "./location-2v3qky60.js";
7
7
 
8
8
  // src/handlers/websearch.ts
9
9
  import { WebSearch } from "@opencode/core/websearch";
@@ -1,9 +1,9 @@
1
1
  import {
2
2
  response2
3
- } from "./pty-environment-6gkz39ey.js";
3
+ } from "./location-43k13dmj.js";
4
4
  import {
5
5
  Api2
6
- } from "./pty-environment-z5shrcz9.js";
6
+ } from "./location-2v3qky60.js";
7
7
 
8
8
  // src/handlers/command.ts
9
9
  import { Command } from "@opencode/core/command";
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  sessionInfo2,
3
3
  requestRef2
4
- } from "./pty-environment-6gkz39ey.js";
4
+ } from "./location-43k13dmj.js";
5
5
 
6
6
  // src/middleware/form-location.ts
7
7
  import { Instance } from "@opencode/core/instance/service";
@@ -1,36 +1,39 @@
1
1
  import {
2
- layer4
3
- } from "./pty-environment-6gkz39ey.js";
2
+ layer3
3
+ } from "./location-43k13dmj.js";
4
4
  import {
5
5
  formLocationLayer2
6
- } from "./pty-environment-5rwqcaw2.js";
6
+ } from "./location-hrfm0p6n.js";
7
7
  import {
8
8
  sessionLocationLayer2
9
- } from "./pty-environment-3kzx88w9.js";
9
+ } from "./location-d65y46ag.js";
10
10
  import {
11
11
  Api2
12
- } from "./pty-environment-z5shrcz9.js";
12
+ } from "./location-2v3qky60.js";
13
13
  import {
14
14
  Config2
15
- } from "./pty-environment-zyv89x5n.js";
15
+ } from "./location-anm12x33.js";
16
16
  import {
17
17
  CorsConfig2
18
- } from "./pty-environment-q4bn6dy8.js";
18
+ } from "./location-q4bn6dy8.js";
19
19
  import {
20
- layer5
21
- } from "./pty-environment-18k6g42r.js";
20
+ layer2
21
+ } from "./location-1gshyx5c.js";
22
22
  import {
23
23
  node2
24
- } from "./pty-environment-0d9kah4z.js";
24
+ } from "./location-rbn15j6z.js";
25
+ import {
26
+ node3
27
+ } from "./location-wv5twc2g.js";
25
28
  import {
26
29
  handlers2
27
- } from "./pty-environment-7ztbq3kp.js";
30
+ } from "./location-97q9zpj5.js";
28
31
  import {
29
32
  authorizationLayer2
30
- } from "./pty-environment-m6wvgbfq.js";
33
+ } from "./location-gtkdacvk.js";
31
34
  import {
32
35
  schemaErrorLayer2
33
- } from "./pty-environment-t8yzmczr.js";
36
+ } from "./location-t8yzmczr.js";
34
37
 
35
38
  // src/routes.ts
36
39
  import { Database } from "@opencode/core/database/database";
@@ -88,6 +91,7 @@ var applicationServiceNodes = [
88
91
  PersistentPty.node,
89
92
  Credential.node,
90
93
  WellKnown.node,
94
+ node3,
91
95
  node2,
92
96
  LocationServiceMap.node,
93
97
  LocationActivity.node,
@@ -140,8 +144,8 @@ function makeRoutes(auth, options, serviceURLs, overrides, instances) {
140
144
  })) : build(overrides);
141
145
  return serviceLayer.pipe(Layer.flatMap((context) => {
142
146
  const services = Layer.succeedContext(context);
143
- const requestServices = Layer.merge(Layer.succeedContext(Context.pick(Database.Service, Credential.Service, PermissionSaved.Service, PluginUpdate.Service, Project.Service, WellKnown.Service)(context)), layer5(serviceURLs, Context.get(context, Global.Service).tmp, options.app));
144
- const api = HttpApiBuilder.layer(Api2, { openapiPath: "/openapi.json" }).pipe(Layer.provide(handlers2.pipe(Layer.provide(services), Layer.provide(Layer.succeed(CorsConfig2, options)))), Layer.provide(formLocationLayer2), Layer.provide(sessionLocationLayer2), Layer.provide(layer4), Layer.provide(authorizationLayer2), Layer.provide(schemaErrorLayer2), Layer.provide(auth), HttpRouter.provideRequest(requestServices), Layer.provideMerge(services), Layer.provideMerge(HttpRouter.layer));
147
+ const requestServices = Layer.merge(Layer.succeedContext(Context.pick(Database.Service, Credential.Service, PermissionSaved.Service, PluginUpdate.Service, Project.Service, WellKnown.Service)(context)), layer2(serviceURLs, Context.get(context, Global.Service).tmp, options.app));
148
+ const api = HttpApiBuilder.layer(Api2, { openapiPath: "/openapi.json" }).pipe(Layer.provide(handlers2.pipe(Layer.provide(services), Layer.provide(Layer.succeed(CorsConfig2, options)))), Layer.provide(formLocationLayer2), Layer.provide(sessionLocationLayer2), Layer.provide(layer3), Layer.provide(authorizationLayer2), Layer.provide(schemaErrorLayer2), Layer.provide(auth), HttpRouter.provideRequest(requestServices), Layer.provideMerge(services), Layer.provideMerge(HttpRouter.layer));
145
149
  return Layer.merge(api, V1Migration.layer.pipe(Layer.provide(services)));
146
150
  }));
147
151
  }
@@ -1,9 +1,9 @@
1
1
  import {
2
2
  response2
3
- } from "./pty-environment-6gkz39ey.js";
3
+ } from "./location-43k13dmj.js";
4
4
  import {
5
5
  Api2
6
- } from "./pty-environment-z5shrcz9.js";
6
+ } from "./location-2v3qky60.js";
7
7
 
8
8
  // src/handlers/reference.ts
9
9
  import { Reference } from "@opencode/core/reference";
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  Api2
3
- } from "./pty-environment-z5shrcz9.js";
3
+ } from "./location-2v3qky60.js";
4
4
 
5
5
  // src/handlers/worktree.ts
6
6
  import { Git } from "@opencode/core/git";
@@ -1,12 +1,12 @@
1
1
  import {
2
2
  isAllowedCorsOrigin2
3
- } from "./pty-environment-q4bn6dy8.js";
3
+ } from "./location-q4bn6dy8.js";
4
4
  import {
5
5
  createRoutes2
6
- } from "./pty-environment-c5m64enw.js";
6
+ } from "./location-jbp1pw2x.js";
7
7
  import {
8
8
  __export
9
- } from "./pty-environment-9rqn6x4v.js";
9
+ } from "./location-9rqn6x4v.js";
10
10
 
11
11
  // src/fetch.ts
12
12
  var exports_fetch = {};
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  Api2
3
- } from "./pty-environment-z5shrcz9.js";
3
+ } from "./location-2v3qky60.js";
4
4
 
5
5
  // src/handlers/credential.ts
6
6
  import { Credential } from "@opencode/core/credential";
@@ -1,18 +1,18 @@
1
1
  import {
2
2
  __export
3
- } from "./pty-environment-9rqn6x4v.js";
3
+ } from "./location-9rqn6x4v.js";
4
4
 
5
5
  // src/event-feed.ts
6
6
  var exports_event_feed = {};
7
7
  __export(exports_event_feed, {
8
8
  EncodingError: () => EncodingError2,
9
9
  EventFeed: () => exports_event_feed,
10
- Service: () => Service2,
10
+ Service: () => Service4,
11
11
  SubscriberCapacity: () => SubscriberCapacity2,
12
12
  SubscriberOverflowError: () => SubscriberOverflowError2,
13
13
  frame: () => frame2,
14
- layer: () => layer2,
15
- make: () => make3
14
+ layer: () => layer4,
15
+ make: () => make4
16
16
  });
17
17
  import { Bus } from "@opencode/core/bus";
18
18
  import { Event } from "@opencode/schema/event";
@@ -30,14 +30,14 @@ class EncodingError2 extends Schema.TaggedError()("EventFeed.EncodingError", {
30
30
  }) {
31
31
  }
32
32
 
33
- class Service2 extends Context.Service()("@opencode/server/EventFeed") {
33
+ class Service4 extends Context.Service()("@opencode/server/EventFeed") {
34
34
  }
35
35
  function frame2(event) {
36
36
  return `data: ${JSON.stringify(event)}
37
37
 
38
38
  `;
39
39
  }
40
- var make3 = Effect.fn("EventFeed.make")(function* (observe, options) {
40
+ var make4 = Effect.fn("EventFeed.make")(function* (observe, options) {
41
41
  const capacity = options?.capacity ?? SubscriberCapacity2;
42
42
  const render = options?.encode ?? frame2;
43
43
  const subscribers = new Set;
@@ -71,13 +71,13 @@ var make3 = Effect.fn("EventFeed.make")(function* (observe, options) {
71
71
  });
72
72
  const unsubscribe = yield* observe(publish);
73
73
  yield* Effect.addFinalizer(() => unsubscribe);
74
- return Service2.of({
74
+ return Service4.of({
75
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
76
  });
77
77
  });
78
- var layer2 = Layer.effect(Service2, Effect.gen(function* () {
78
+ var layer4 = Layer.effect(Service4, Effect.gen(function* () {
79
79
  const bus = yield* Bus.Service;
80
- return yield* make3(bus.listen);
80
+ return yield* make4(bus.listen);
81
81
  }));
82
82
 
83
- export { SubscriberCapacity2, SubscriberOverflowError2, EncodingError2, Service2, frame2, make3, layer2, exports_event_feed };
83
+ export { SubscriberCapacity2, SubscriberOverflowError2, EncodingError2, Service4, frame2, make4, layer4, exports_event_feed };
@@ -1,13 +1,13 @@
1
1
  import {
2
2
  missingSession2
3
- } from "./pty-environment-smaf4a18.js";
3
+ } from "./location-smaf4a18.js";
4
4
  import {
5
5
  response2,
6
6
  sessionInfo2
7
- } from "./pty-environment-6gkz39ey.js";
7
+ } from "./location-43k13dmj.js";
8
8
  import {
9
9
  Api2
10
- } from "./pty-environment-z5shrcz9.js";
10
+ } from "./location-2v3qky60.js";
11
11
 
12
12
  // src/handlers/permission.ts
13
13
  import { Instance } from "@opencode/core/instance/service";
@@ -1,10 +1,10 @@
1
1
  import {
2
2
  missingSession2,
3
3
  failedMessageDecode2
4
- } from "./pty-environment-smaf4a18.js";
4
+ } from "./location-smaf4a18.js";
5
5
  import {
6
6
  Api2
7
- } from "./pty-environment-z5shrcz9.js";
7
+ } from "./location-2v3qky60.js";
8
8
 
9
9
  // src/handlers/message.ts
10
10
  import { SessionMessage } from "@opencode/core/session/message";
@@ -1,13 +1,13 @@
1
1
  import {
2
2
  Api2
3
- } from "./pty-environment-z5shrcz9.js";
3
+ } from "./location-2v3qky60.js";
4
4
  import {
5
5
  CorsConfig2,
6
6
  isAllowedRequestOrigin2
7
- } from "./pty-environment-q4bn6dy8.js";
7
+ } from "./location-q4bn6dy8.js";
8
8
  import {
9
9
  runPtySocket2
10
- } from "./pty-environment-hezj1jdf.js";
10
+ } from "./location-hezj1jdf.js";
11
11
 
12
12
  // src/handlers/persistent-pty.ts
13
13
  import { PersistentPty } from "@opencode/core/persistent-pty";
@@ -1,9 +1,9 @@
1
1
  import {
2
2
  response2
3
- } from "./pty-environment-6gkz39ey.js";
3
+ } from "./location-43k13dmj.js";
4
4
  import {
5
5
  Api2
6
- } from "./pty-environment-z5shrcz9.js";
6
+ } from "./location-2v3qky60.js";
7
7
 
8
8
  // src/handlers/plugin.ts
9
9
  import { Plugin } from "@opencode/core/plugin";
@@ -0,0 +1,35 @@
1
+ import {
2
+ __export
3
+ } from "./location-9rqn6x4v.js";
4
+
5
+ // src/pairing.ts
6
+ var exports_pairing = {};
7
+ __export(exports_pairing, {
8
+ ServerPairing: () => exports_pairing,
9
+ Service: () => Service2,
10
+ node: () => node2
11
+ });
12
+ import { Cache, Context, Duration, Effect, Layer } from "effect";
13
+ import { makeGlobalNode } from "@opencode/util/effect/app-node";
14
+ import { randomBytes } from "node:crypto";
15
+ var TTL = Duration.minutes(5);
16
+
17
+ class Service2 extends Context.Service()("@opencode/ServerPairing") {
18
+ }
19
+ var noLookup = () => Effect.die(new Error("ServerPairing cache must be used via set/invalidateWhen, never get"));
20
+ var layer = Layer.effect(Service2, Effect.gen(function* () {
21
+ const cache = yield* Cache.make({ capacity: 1000, lookup: noLookup, timeToLive: TTL });
22
+ return Service2.of({
23
+ issue: Effect.fn("ServerPairing.issue")(function* () {
24
+ const code = randomBytes(16).toString("base64url");
25
+ yield* Cache.set(cache, code, true);
26
+ return { code, expires_in: Duration.toSeconds(TTL) };
27
+ }),
28
+ consume: Effect.fn("ServerPairing.consume")(function* (code) {
29
+ return yield* Cache.invalidateWhen(cache, code, () => true);
30
+ })
31
+ });
32
+ }));
33
+ var node2 = makeGlobalNode({ service: Service2, layer, deps: [] });
34
+
35
+ export { Service2, node2, exports_pairing };
@@ -1,9 +1,9 @@
1
1
  import {
2
2
  response2
3
- } from "./pty-environment-6gkz39ey.js";
3
+ } from "./location-43k13dmj.js";
4
4
  import {
5
5
  Api2
6
- } from "./pty-environment-z5shrcz9.js";
6
+ } from "./location-2v3qky60.js";
7
7
 
8
8
  // src/handlers/shell.ts
9
9
  import { Shell } from "@opencode/core/shell";
@@ -1,9 +1,9 @@
1
1
  import {
2
2
  response2
3
- } from "./pty-environment-6gkz39ey.js";
3
+ } from "./location-43k13dmj.js";
4
4
  import {
5
5
  Api2
6
- } from "./pty-environment-z5shrcz9.js";
6
+ } from "./location-2v3qky60.js";
7
7
 
8
8
  // src/handlers/fs.ts
9
9
  import { FileSystem } from "@opencode/core/filesystem";
@@ -0,0 +1,53 @@
1
+ import {
2
+ Api2
3
+ } from "./location-2v3qky60.js";
4
+ import {
5
+ SESSION_TTL_SECONDS2,
6
+ Config2,
7
+ issueSession2,
8
+ sessionCookieName2
9
+ } from "./location-anm12x33.js";
10
+ import {
11
+ Service3
12
+ } from "./location-1gshyx5c.js";
13
+ import {
14
+ Service2
15
+ } from "./location-rbn15j6z.js";
16
+
17
+ // src/handlers/server.ts
18
+ import { Duration, Effect } from "effect";
19
+ import { HttpServerRequest, HttpServerResponse } from "effect/unstable/http";
20
+ import { HttpApiBuilder } from "effect/unstable/httpapi";
21
+ import { UnauthorizedError } from "@opencode/protocol/errors";
22
+ var ServerHandler2 = HttpApiBuilder.group(Api2, "server.server", (handlers) => Effect.gen(function* () {
23
+ const pairing = yield* Service2;
24
+ const auth = yield* Config2;
25
+ return handlers.handle("server.info", () => Effect.gen(function* () {
26
+ const info = yield* Service3;
27
+ return {
28
+ version: info.app.version ?? "unknown",
29
+ pid: process.pid ?? 0,
30
+ urls: info.urls(),
31
+ paths: info.paths
32
+ };
33
+ })).handle("server.pair", () => pairing.issue()).handle("server.connect", Effect.fn(function* (ctx) {
34
+ const request = yield* HttpServerRequest.HttpServerRequest;
35
+ const browser = request.headers.accept?.includes("text/html") === true;
36
+ const token = (yield* pairing.consume(ctx.params.code)) ? issueSession2(auth) : undefined;
37
+ if (token === undefined) {
38
+ if (!browser)
39
+ return yield* new UnauthorizedError({ message: "Pairing link expired or already used" });
40
+ return HttpServerResponse.text("This pairing link expired or was already used. Run `opencode pair` to get a new one.", { status: 401 });
41
+ }
42
+ if (!browser)
43
+ return { token };
44
+ return HttpServerResponse.redirect("/").pipe(HttpServerResponse.setCookieUnsafe(sessionCookieName2(request.headers.host), token, {
45
+ path: "/",
46
+ httpOnly: true,
47
+ sameSite: "lax",
48
+ maxAge: Duration.seconds(SESSION_TTL_SECONDS2)
49
+ }));
50
+ }));
51
+ }));
52
+
53
+ export { ServerHandler2 };
@@ -1,23 +1,23 @@
1
1
  import {
2
2
  __export
3
- } from "./pty-environment-9rqn6x4v.js";
3
+ } from "./location-9rqn6x4v.js";
4
4
 
5
5
  // src/pty-environment.ts
6
6
  var exports_pty_environment = {};
7
7
  __export(exports_pty_environment, {
8
8
  PtyEnvironment: () => exports_pty_environment,
9
- Service: () => Service3,
10
- layer: () => layer3,
11
- node: () => node2
9
+ Service: () => Service5,
10
+ layer: () => layer5,
11
+ node: () => node3
12
12
  });
13
13
  import { Context, Effect, Layer } from "effect";
14
14
  import { makeGlobalNode } from "@opencode/util/effect/app-node";
15
15
 
16
- class Service3 extends Context.Service()("@opencode/ServerPtyEnvironment") {
16
+ class Service5 extends Context.Service()("@opencode/ServerPtyEnvironment") {
17
17
  }
18
- var layer3 = Layer.succeed(Service3, Service3.of({
18
+ var layer5 = Layer.succeed(Service5, Service5.of({
19
19
  get: () => Effect.succeed({})
20
20
  }));
21
- var node2 = makeGlobalNode({ service: Service3, layer: layer3, deps: [] });
21
+ var node3 = makeGlobalNode({ service: Service5, layer: layer5, deps: [] });
22
22
 
23
- export { Service3, layer3, node2, exports_pty_environment };
23
+ export { Service5, layer5, node3, exports_pty_environment };
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  Api2
3
- } from "./pty-environment-z5shrcz9.js";
3
+ } from "./location-2v3qky60.js";
4
4
 
5
5
  // src/handlers/location.ts
6
6
  import { Location } from "@opencode/core/location";
@@ -1,9 +1,9 @@
1
1
  import {
2
2
  response2
3
- } from "./pty-environment-6gkz39ey.js";
3
+ } from "./location-43k13dmj.js";
4
4
  import {
5
5
  Api2
6
- } from "./pty-environment-z5shrcz9.js";
6
+ } from "./location-2v3qky60.js";
7
7
 
8
8
  // src/handlers/model.ts
9
9
  import { Model } from "@opencode/core/model";
package/dist/cors.js CHANGED
@@ -2,7 +2,7 @@ import {
2
2
  CorsConfig2,
3
3
  isAllowedCorsOrigin2,
4
4
  isAllowedRequestOrigin2
5
- } from "./chunks/pty-environment-q4bn6dy8.js";
5
+ } from "./chunks/location-q4bn6dy8.js";
6
6
  export {
7
7
  CorsConfig2 as CorsConfig,
8
8
  isAllowedCorsOrigin2 as isAllowedCorsOrigin,
@@ -2,19 +2,19 @@ import {
2
2
  SubscriberCapacity2,
3
3
  SubscriberOverflowError2,
4
4
  EncodingError2,
5
- Service2,
5
+ Service4,
6
6
  frame2,
7
- make3,
8
- layer2,
7
+ make4,
8
+ layer4,
9
9
  exports_event_feed
10
- } from "./chunks/pty-environment-kmrabwkf.js";
10
+ } from "./chunks/location-n9y13hgv.js";
11
11
  export {
12
12
  EncodingError2 as EncodingError,
13
13
  exports_event_feed as EventFeed,
14
- Service2 as Service,
14
+ Service4 as Service,
15
15
  SubscriberCapacity2 as SubscriberCapacity,
16
16
  SubscriberOverflowError2 as SubscriberOverflowError,
17
17
  frame2 as frame,
18
- layer2 as layer,
19
- make3 as make
18
+ layer4 as layer,
19
+ make4 as make
20
20
  };