@opencode/server 0.0.0-dev-1357 → 0.0.0-dev-1359

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 (140) hide show
  1. package/dist/api.js +5 -5
  2. package/dist/auth.js +1 -1
  3. package/dist/chunks/api-0tgs6603.js +108 -0
  4. package/dist/chunks/{pairing-cwx7pqk1.js → api-0wjm8gvs.js} +3 -3
  5. package/dist/chunks/{pairing-10sj2tcf.js → api-10sj2tcf.js} +1 -1
  6. package/dist/chunks/{pairing-mp1tvqh7.js → api-1eazfxyk.js} +4 -4
  7. package/dist/chunks/{pairing-rktygpea.js → api-29nx48hm.js} +4 -1
  8. package/dist/chunks/{pairing-2tmcamrc.js → api-2tmcamrc.js} +2 -2
  9. package/dist/chunks/api-343ey9kd.js +189 -0
  10. package/dist/chunks/{pairing-39nnfjx1.js → api-39nnfjx1.js} +1 -1
  11. package/dist/chunks/{pairing-yjbzmfhm.js → api-3te71694.js} +5 -5
  12. package/dist/chunks/{pairing-ed0tz0nn.js → api-4aa8a7eb.js} +14 -12
  13. package/dist/chunks/{pairing-qssmdh31.js → api-5jwtxv1w.js} +4 -4
  14. package/dist/chunks/{pairing-6pm6ek88.js → api-6pm6ek88.js} +1 -1
  15. package/dist/chunks/{pairing-74nxvsrn.js → api-74nxvsrn.js} +2 -2
  16. package/dist/chunks/{pairing-7dkb5ks8.js → api-7dkb5ks8.js} +2 -2
  17. package/dist/chunks/{pairing-8fhq523v.js → api-8fhq523v.js} +4 -4
  18. package/dist/chunks/{pairing-8nezxn08.js → api-8nezxn08.js} +1 -1
  19. package/dist/chunks/{pairing-8qsq6tbs.js → api-8qsq6tbs.js} +2 -2
  20. package/dist/chunks/{pairing-8sb6qqpn.js → api-8sb6qqpn.js} +1 -1
  21. package/dist/chunks/{pairing-8xdajgpr.js → api-8xdajgpr.js} +2 -2
  22. package/dist/chunks/api-9hynp6rm.js +20 -0
  23. package/dist/chunks/{pairing-am27j67f.js → api-am27j67f.js} +1 -1
  24. package/dist/chunks/{pairing-ba6cev85.js → api-ba6cev85.js} +4 -4
  25. package/dist/chunks/{pairing-br4x4prt.js → api-br4x4prt.js} +1 -1
  26. package/dist/chunks/{pairing-ca564221.js → api-ca564221.js} +1 -1
  27. package/dist/chunks/{pairing-csnx1nj3.js → api-csnx1nj3.js} +2 -2
  28. package/dist/chunks/{pairing-djr0jy89.js → api-djr0jy89.js} +1 -1
  29. package/dist/chunks/{pairing-ehyp3zqd.js → api-ehyp3zqd.js} +1 -1
  30. package/dist/chunks/{pairing-em7ed65n.js → api-em7ed65n.js} +2 -2
  31. package/dist/chunks/{pairing-exwy1kbj.js → api-exwy1kbj.js} +2 -2
  32. package/dist/chunks/{pairing-f3gr6hfv.js → api-f3gr6hfv.js} +2 -2
  33. package/dist/chunks/{pairing-fvpjvjpp.js → api-fvpjvjpp.js} +1 -1
  34. package/dist/chunks/{pairing-darcrm5x.js → api-g1xn52zf.js} +8 -8
  35. package/dist/chunks/{pairing-50kbksvb.js → api-g23ffrnz.js} +2 -2
  36. package/dist/chunks/{pairing-bng99jk3.js → api-gbjwxtsb.js} +15 -11
  37. package/dist/chunks/{pairing-j4at0y5c.js → api-j4at0y5c.js} +1 -1
  38. package/dist/chunks/{pairing-javgytnb.js → api-javgytnb.js} +2 -2
  39. package/dist/chunks/{pairing-k74zefsg.js → api-k74zefsg.js} +1 -1
  40. package/dist/chunks/{pairing-kmwr1xw9.js → api-kmwr1xw9.js} +3 -3
  41. package/dist/chunks/{pairing-kshqfq8s.js → api-kshqfq8s.js} +2 -2
  42. package/dist/chunks/{pairing-myqk22k5.js → api-myqk22k5.js} +2 -2
  43. package/dist/chunks/{pairing-w9jcwh65.js → api-mzs0n5xz.js} +7 -7
  44. package/dist/chunks/{pairing-n2zyxnzr.js → api-n2zyxnzr.js} +1 -1
  45. package/dist/chunks/{pairing-p3bbq7g3.js → api-p3bbq7g3.js} +1 -1
  46. package/dist/chunks/{pairing-prwd5gwt.js → api-prwd5gwt.js} +2 -2
  47. package/dist/chunks/{pairing-qq3f8fnn.js → api-qq3f8fnn.js} +2 -2
  48. package/dist/chunks/{pairing-rgbnpstw.js → api-rgbnpstw.js} +2 -2
  49. package/dist/chunks/{pairing-rjhxbsc4.js → api-rjhxbsc4.js} +2 -2
  50. package/dist/chunks/{pairing-s0zgx365.js → api-s0zgx365.js} +2 -2
  51. package/dist/chunks/{pairing-t32e1bbt.js → api-t32e1bbt.js} +1 -1
  52. package/dist/chunks/{pairing-t5vqvama.js → api-thpam3yh.js} +5 -5
  53. package/dist/chunks/{pairing-g4964mny.js → api-ts1fhe9d.js} +3 -3
  54. package/dist/chunks/{pairing-whvq72as.js → api-whvq72as.js} +3 -3
  55. package/dist/chunks/{pairing-wsvmph03.js → api-wsvmph03.js} +2 -2
  56. package/dist/chunks/{pairing-x2qy7jg1.js → api-x2qy7jg1.js} +1 -1
  57. package/dist/chunks/{pairing-yc92za0p.js → api-yc92za0p.js} +2 -2
  58. package/dist/content-headers.js +1 -1
  59. package/dist/cors.js +1 -1
  60. package/dist/event-feed.js +1 -1
  61. package/dist/fetch.d.ts +1 -1
  62. package/dist/fetch.js +63 -61
  63. package/dist/handlers/agent.js +6 -6
  64. package/dist/handlers/artifact.js +3 -3
  65. package/dist/handlers/automation.js +2 -2
  66. package/dist/handlers/blob.js +3 -3
  67. package/dist/handlers/command.js +6 -6
  68. package/dist/handlers/config.js +6 -6
  69. package/dist/handlers/credential.js +7 -7
  70. package/dist/handlers/debug.js +6 -6
  71. package/dist/handlers/event.js +7 -7
  72. package/dist/handlers/experimental/browser-tunnel.d.ts +11 -0
  73. package/dist/handlers/experimental/browser-tunnel.js +9 -0
  74. package/dist/handlers/flag.d.ts +1 -0
  75. package/dist/handlers/flag.js +11 -0
  76. package/dist/handlers/form.js +6 -6
  77. package/dist/handlers/fs.js +8 -8
  78. package/dist/handlers/generate.js +6 -6
  79. package/dist/handlers/integration.js +6 -6
  80. package/dist/handlers/job.js +2 -2
  81. package/dist/handlers/location.js +6 -6
  82. package/dist/handlers/machine.js +1 -1
  83. package/dist/handlers/mcp.js +8 -8
  84. package/dist/handlers/media.js +2 -2
  85. package/dist/handlers/message.js +7 -7
  86. package/dist/handlers/migration.js +6 -6
  87. package/dist/handlers/model.js +6 -6
  88. package/dist/handlers/permission.js +6 -6
  89. package/dist/handlers/persistent-pty.d.ts +1 -1
  90. package/dist/handlers/persistent-pty.js +18 -17
  91. package/dist/handlers/plugin.js +6 -6
  92. package/dist/handlers/project.js +6 -6
  93. package/dist/handlers/provider.js +6 -6
  94. package/dist/handlers/pty-socket.js +1 -1
  95. package/dist/handlers/pty.js +8 -8
  96. package/dist/handlers/push.js +1 -1
  97. package/dist/handlers/reference.js +6 -6
  98. package/dist/handlers/rpc.js +6 -6
  99. package/dist/handlers/server.js +9 -9
  100. package/dist/handlers/session-error.js +1 -1
  101. package/dist/handlers/session.js +7 -7
  102. package/dist/handlers/shell.js +6 -6
  103. package/dist/handlers/skill.js +6 -6
  104. package/dist/handlers/usage.js +6 -6
  105. package/dist/handlers/vcs.js +6 -6
  106. package/dist/handlers/voice.js +6 -6
  107. package/dist/handlers/websearch.js +6 -6
  108. package/dist/handlers/worktree.js +6 -6
  109. package/dist/handlers.d.ts +1 -1
  110. package/dist/handlers.js +56 -54
  111. package/dist/location.js +2 -2
  112. package/dist/media-uri.js +1 -1
  113. package/dist/middleware/authorization.js +2 -2
  114. package/dist/middleware/defect-response.js +1 -1
  115. package/dist/middleware/form-location.js +3 -3
  116. package/dist/middleware/schema-error.js +1 -1
  117. package/dist/middleware/session-location.js +3 -3
  118. package/dist/pairing.js +3 -3
  119. package/dist/process.js +73 -63
  120. package/dist/range.js +1 -1
  121. package/dist/request-site.js +2 -2
  122. package/dist/request-tracing.js +1 -1
  123. package/dist/routes.d.ts +3 -2
  124. package/dist/routes.js +60 -58
  125. package/dist/server-info.js +3 -3
  126. package/dist/service-status.js +1 -1
  127. package/dist/workerd.d.ts +5 -5
  128. package/dist/workerd.js +66 -93
  129. package/package.json +8 -8
  130. package/dist/chunks/pairing-dms2vwqd.js +0 -105
  131. /package/dist/chunks/{pairing-017ycvbx.js → api-017ycvbx.js} +0 -0
  132. /package/dist/chunks/{pairing-9rqn6x4v.js → api-9rqn6x4v.js} +0 -0
  133. /package/dist/chunks/{pairing-bd8755ek.js → api-bd8755ek.js} +0 -0
  134. /package/dist/chunks/{pairing-n26yr6pw.js → api-n26yr6pw.js} +0 -0
  135. /package/dist/chunks/{pairing-q187pxxd.js → api-q187pxxd.js} +0 -0
  136. /package/dist/chunks/{pairing-q4bn6dy8.js → api-q4bn6dy8.js} +0 -0
  137. /package/dist/chunks/{pairing-qpnw2qd1.js → api-qpnw2qd1.js} +0 -0
  138. /package/dist/chunks/{pairing-rqgv9x42.js → api-rqgv9x42.js} +0 -0
  139. /package/dist/chunks/{pairing-xthc02cw.js → api-xthc02cw.js} +0 -0
  140. /package/dist/chunks/{pairing-yc7nft6q.js → api-yc7nft6q.js} +0 -0
package/dist/api.js CHANGED
@@ -1,10 +1,10 @@
1
1
  import {
2
2
  Api2
3
- } from "./chunks/pairing-whvq72as.js";
4
- import"./chunks/pairing-ehyp3zqd.js";
5
- import"./chunks/pairing-ca564221.js";
6
- import"./chunks/pairing-br4x4prt.js";
7
- import"./chunks/pairing-rqgv9x42.js";
3
+ } from "./chunks/api-whvq72as.js";
4
+ import"./chunks/api-ehyp3zqd.js";
5
+ import"./chunks/api-ca564221.js";
6
+ import"./chunks/api-br4x4prt.js";
7
+ import"./chunks/api-rqgv9x42.js";
8
8
  export {
9
9
  Api2 as Api
10
10
  };
package/dist/auth.js CHANGED
@@ -7,7 +7,7 @@ import {
7
7
  verifySession2,
8
8
  sessionCookieName2,
9
9
  exports_auth
10
- } from "./chunks/pairing-j4at0y5c.js";
10
+ } from "./chunks/api-j4at0y5c.js";
11
11
  export {
12
12
  Config2 as Config,
13
13
  SESSION_TTL_SECONDS2 as SESSION_TTL_SECONDS,
@@ -0,0 +1,108 @@
1
+ import {
2
+ GenerateHandler2
3
+ } from "./api-prwd5gwt.js";
4
+ import {
5
+ VoiceHandler2
6
+ } from "./api-rjhxbsc4.js";
7
+ import {
8
+ MessageHandler2
9
+ } from "./api-ts1fhe9d.js";
10
+ import {
11
+ ModelHandler2
12
+ } from "./api-s0zgx365.js";
13
+ import {
14
+ ProviderHandler2
15
+ } from "./api-yc92za0p.js";
16
+ import {
17
+ SessionHandler2
18
+ } from "./api-5jwtxv1w.js";
19
+ import {
20
+ PermissionHandler2
21
+ } from "./api-kmwr1xw9.js";
22
+ import {
23
+ FileSystemHandler2
24
+ } from "./api-1eazfxyk.js";
25
+ import {
26
+ FormHandler2
27
+ } from "./api-8qsq6tbs.js";
28
+ import {
29
+ CommandHandler2
30
+ } from "./api-rgbnpstw.js";
31
+ import {
32
+ SkillHandler2
33
+ } from "./api-74nxvsrn.js";
34
+ import {
35
+ RpcHandler2
36
+ } from "./api-k74zefsg.js";
37
+ import {
38
+ layer2
39
+ } from "./api-fvpjvjpp.js";
40
+ import {
41
+ EventHandler2
42
+ } from "./api-kshqfq8s.js";
43
+ import {
44
+ AgentHandler2
45
+ } from "./api-exwy1kbj.js";
46
+ import {
47
+ PluginHandler2
48
+ } from "./api-em7ed65n.js";
49
+ import {
50
+ ServerHandler2
51
+ } from "./api-g1xn52zf.js";
52
+ import {
53
+ DebugHandler2
54
+ } from "./api-csnx1nj3.js";
55
+ import {
56
+ PtyHandler2
57
+ } from "./api-8fhq523v.js";
58
+ import {
59
+ PersistentPtyHandler2
60
+ } from "./api-gbjwxtsb.js";
61
+ import {
62
+ ShellHandler2
63
+ } from "./api-f3gr6hfv.js";
64
+ import {
65
+ ReferenceHandler2
66
+ } from "./api-7dkb5ks8.js";
67
+ import {
68
+ LocationHandler2
69
+ } from "./api-p3bbq7g3.js";
70
+ import {
71
+ IntegrationHandler2
72
+ } from "./api-2tmcamrc.js";
73
+ import {
74
+ WebSearchHandler2
75
+ } from "./api-qq3f8fnn.js";
76
+ import {
77
+ UsageHandler2
78
+ } from "./api-wsvmph03.js";
79
+ import {
80
+ FlagHandler2
81
+ } from "./api-9hynp6rm.js";
82
+ import {
83
+ McpHandler2
84
+ } from "./api-ba6cev85.js";
85
+ import {
86
+ CredentialHandler2
87
+ } from "./api-8xdajgpr.js";
88
+ import {
89
+ ProjectHandler2
90
+ } from "./api-8nezxn08.js";
91
+ import {
92
+ WorktreeHandler2
93
+ } from "./api-n2zyxnzr.js";
94
+ import {
95
+ VcsHandler2
96
+ } from "./api-0wjm8gvs.js";
97
+ import {
98
+ MigrationHandler2
99
+ } from "./api-10sj2tcf.js";
100
+ import {
101
+ ConfigHandler2
102
+ } from "./api-am27j67f.js";
103
+
104
+ // src/handlers.ts
105
+ import { Layer } from "effect";
106
+ var handlers2 = Layer.mergeAll(ServerHandler2, DebugHandler2, MigrationHandler2, LocationHandler2, AgentHandler2, PluginHandler2, SessionHandler2, MessageHandler2, ModelHandler2, GenerateHandler2, VoiceHandler2, ProviderHandler2, IntegrationHandler2, WebSearchHandler2, UsageHandler2, FlagHandler2, McpHandler2, CredentialHandler2, ProjectHandler2, FormHandler2, PermissionHandler2, FileSystemHandler2, CommandHandler2, SkillHandler2, RpcHandler2, EventHandler2.pipe(Layer.provide(layer2)), PtyHandler2, PersistentPtyHandler2, ShellHandler2, ReferenceHandler2, WorktreeHandler2, VcsHandler2, ConfigHandler2);
107
+
108
+ export { handlers2 };
@@ -1,9 +1,9 @@
1
1
  import {
2
2
  response2
3
- } from "./pairing-br4x4prt.js";
3
+ } from "./api-br4x4prt.js";
4
4
  import {
5
5
  Api2
6
- } from "./pairing-whvq72as.js";
6
+ } from "./api-whvq72as.js";
7
7
 
8
8
  // src/handlers/vcs.ts
9
9
  import { Vcs } from "@opencode/core/vcs";
@@ -42,7 +42,7 @@ var VcsHandler2 = HttpApiBuilder.group(Api2, "server.vcs", (handlers) => Effect.
42
42
  });
43
43
  return new ServiceUnavailableError({ service: providerID, message: "VCS initialization failed" });
44
44
  }));
45
- const resolved = yield* project.resolve(directory);
45
+ const resolved = yield* project.resolve(directory, { local: location.workspaceID === undefined });
46
46
  if (!resolved.vcs)
47
47
  return yield* new ServiceUnavailableError({ service: providerID, message: "VCS initialization failed" });
48
48
  yield* locations.invalidate(Location.Ref.make({ directory: location.directory, workspaceID: location.workspaceID }));
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  Api2
3
- } from "./pairing-whvq72as.js";
3
+ } from "./api-whvq72as.js";
4
4
 
5
5
  // src/handlers/migration.ts
6
6
  import { V1Migration } from "@opencode/core/database/v1-migration";
@@ -1,15 +1,15 @@
1
1
  import {
2
2
  response2
3
- } from "./pairing-br4x4prt.js";
3
+ } from "./api-br4x4prt.js";
4
4
  import {
5
5
  Api2
6
- } from "./pairing-whvq72as.js";
6
+ } from "./api-whvq72as.js";
7
7
  import {
8
8
  download2
9
- } from "./pairing-t32e1bbt.js";
9
+ } from "./api-t32e1bbt.js";
10
10
  import {
11
11
  parse2
12
- } from "./pairing-8sb6qqpn.js";
12
+ } from "./api-8sb6qqpn.js";
13
13
 
14
14
  // src/handlers/fs.ts
15
15
  import { Environment } from "@opencode/core/environment/index";
@@ -4,7 +4,7 @@ import {
4
4
  authorized2,
5
5
  verifySession2,
6
6
  sessionCookieName2
7
- } from "./pairing-j4at0y5c.js";
7
+ } from "./api-j4at0y5c.js";
8
8
 
9
9
  // src/middleware/authorization.ts
10
10
  import { UnauthorizedError } from "@opencode/protocol/errors";
@@ -13,6 +13,7 @@ import { Authorization as Authorization2 } from "@opencode/protocol/middleware/a
13
13
  import { PTY_CONNECT_PATH, PTY_CONNECT_TICKET_QUERY } from "@opencode/protocol/groups/pty";
14
14
  import { PERSISTENT_PTY_CONNECT_PATH } from "@opencode/protocol/groups/persistent-pty";
15
15
  import { MCP_CLIENT_PATH } from "@opencode/protocol/groups/mcp";
16
+ import { BROWSER_TUNNEL_PATH, hasBrowserTunnelUpgrade } from "@opencode/protocol/groups/experimental/browser-tunnel";
16
17
  import { isWebSocketUpgrade, MACHINE_LINK_PATH } from "@opencode/protocol/groups/machine";
17
18
  import { PAIRING_CONNECT_PATH } from "@opencode/protocol/groups/server";
18
19
  import { Effect, Layer, Redacted } from "effect";
@@ -76,6 +77,8 @@ var authorizationLayer2 = Layer.effect(Authorization, Effect.gen(function* () {
76
77
  return yield* effect;
77
78
  if (route.route.path === MACHINE_LINK_PATH && isWebSocketUpgrade(request))
78
79
  return yield* effect;
80
+ if (route.route.path === BROWSER_TUNNEL_PATH && hasBrowserTunnelUpgrade(request))
81
+ return yield* effect;
79
82
  if (yield* authorizedRequest2(request, config))
80
83
  return yield* effect;
81
84
  if (challengeRequest(request))
@@ -1,9 +1,9 @@
1
1
  import {
2
2
  response2
3
- } from "./pairing-br4x4prt.js";
3
+ } from "./api-br4x4prt.js";
4
4
  import {
5
5
  Api2
6
- } from "./pairing-whvq72as.js";
6
+ } from "./api-whvq72as.js";
7
7
 
8
8
  // src/handlers/integration.ts
9
9
  import { Integration } from "@opencode/core/integration";
@@ -0,0 +1,189 @@
1
+ import {
2
+ CorsConfig2,
3
+ isAllowedRequestOrigin2
4
+ } from "./api-q4bn6dy8.js";
5
+ import {
6
+ locationErrors2,
7
+ requestRef2
8
+ } from "./api-br4x4prt.js";
9
+
10
+ // src/handlers/experimental/browser-tunnel.ts
11
+ import { NodeHttpServerRequest } from "@effect/platform-node";
12
+ import { WebSocketServer } from "@effect/platform-node-shared/NodeWS";
13
+ import { BrowserTunnelGateway } from "@opencode/core/experimental/browser-tunnel";
14
+ import { LocationLifecycle } from "@opencode/core/location-lifecycle";
15
+ import { LocationServiceMap } from "@opencode/core/location-service-map";
16
+ import {
17
+ BROWSER_TUNNEL_CONNECTION_HEADER,
18
+ BROWSER_TUNNEL_PROTOCOL_HEADER,
19
+ BROWSER_TUNNEL_PROTOCOL_VERSION,
20
+ BROWSER_TUNNEL_SESSION_HEADER,
21
+ BROWSER_TUNNEL_TICKET_HEADER
22
+ } from "@opencode/protocol/groups/experimental/browser-tunnel";
23
+ import { isWebSocketUpgrade } from "@opencode/protocol/groups/machine";
24
+ import { Session } from "@opencode/schema/session";
25
+ import { Effect, Option, Schema, Scope } from "effect";
26
+ import { HttpMiddleware, HttpServerResponse } from "effect/http";
27
+ import { IncomingMessage } from "node:http";
28
+ var STOPPING = "1 second";
29
+ var CLOSING = "5 seconds";
30
+ function toUint8Array(data) {
31
+ if (data instanceof Uint8Array)
32
+ return data;
33
+ if (data instanceof ArrayBuffer)
34
+ return new Uint8Array(data);
35
+ if (Array.isArray(data)) {
36
+ const buffers = data.map((part) => part instanceof Uint8Array ? part : new Uint8Array(part));
37
+ return Buffer.concat(buffers);
38
+ }
39
+ return new Uint8Array;
40
+ }
41
+ function adaptWebSocket(ws) {
42
+ return {
43
+ get readyState() {
44
+ return ws.readyState;
45
+ },
46
+ get bufferedAmount() {
47
+ return ws.bufferedAmount;
48
+ },
49
+ send(data, onWritten) {
50
+ ws.send(data, { binary: true, compress: false }, (error) => onWritten?.(error ?? undefined));
51
+ },
52
+ ping() {
53
+ if (ws.readyState === ws.OPEN)
54
+ ws.ping();
55
+ },
56
+ close(code, reason) {
57
+ if (ws.readyState === ws.OPEN || ws.readyState === ws.CONNECTING) {
58
+ ws.close(code, reason);
59
+ }
60
+ },
61
+ terminate() {
62
+ ws.terminate();
63
+ },
64
+ onMessage(listener) {
65
+ const handler = (raw, isBinary) => {
66
+ if (!isBinary) {
67
+ listener(String(raw));
68
+ return;
69
+ }
70
+ listener(toUint8Array(raw));
71
+ };
72
+ ws.on("message", handler);
73
+ ws.resume();
74
+ return () => {
75
+ ws.off("message", handler);
76
+ };
77
+ },
78
+ onClose(listener) {
79
+ const handler = (code, reason) => listener(code, reason.toString("utf8"));
80
+ ws.on("close", handler);
81
+ return () => {
82
+ ws.off("close", handler);
83
+ };
84
+ },
85
+ onError(listener) {
86
+ ws.on("error", listener);
87
+ return () => {
88
+ ws.off("error", listener);
89
+ };
90
+ },
91
+ onPong(listener) {
92
+ ws.on("pong", listener);
93
+ return () => {
94
+ ws.off("pong", listener);
95
+ };
96
+ }
97
+ };
98
+ }
99
+ var upgradeSocket = (sockets, incoming) => Effect.acquireRelease(Effect.callback((resume) => {
100
+ const refused = () => resume(Effect.fail(new Error("WebSocket upgrade closed before completion.")));
101
+ if (incoming.socket.destroyed)
102
+ return refused();
103
+ incoming.socket.once("close", refused);
104
+ sockets.handleUpgrade(incoming, incoming.socket, Buffer.alloc(0), (ws) => {
105
+ incoming.socket.off("close", refused);
106
+ incoming.socket.setNoDelay(true);
107
+ ws.pause();
108
+ resume(Effect.succeed(ws));
109
+ });
110
+ }), (ws) => Effect.gen(function* () {
111
+ if (ws.readyState === ws.CLOSED)
112
+ return;
113
+ const gone = Effect.callback((resume) => {
114
+ if (ws.readyState === ws.CLOSED)
115
+ return resume(Effect.void);
116
+ ws.once("close", () => resume(Effect.void));
117
+ });
118
+ ws.close(1001, "server closing");
119
+ if (Option.isNone(yield* Effect.timeoutOption(gone, CLOSING)))
120
+ ws.terminate();
121
+ }));
122
+ var makeBrowserTunnel2 = Effect.gen(function* () {
123
+ const gateway = yield* BrowserTunnelGateway.Service;
124
+ const locations = yield* LocationServiceMap.Service;
125
+ const cors = yield* CorsConfig2;
126
+ const scope = yield* Effect.scope;
127
+ const server = yield* Effect.cached(Effect.acquireRelease(Effect.sync(() => new WebSocketServer({
128
+ noServer: true,
129
+ perMessageDeflate: false,
130
+ maxPayload: BrowserTunnelGateway.MAX_WS_FRAME_BYTES
131
+ })), (sockets) => Effect.gen(function* () {
132
+ sockets.clients.forEach((ws) => ws.close(1012, "server stopping"));
133
+ const empty = Effect.callback((resume) => sockets.close(() => resume(Effect.void)));
134
+ if (Option.isNone(yield* Effect.timeoutOption(empty, STOPPING))) {
135
+ sockets.clients.forEach((ws) => ws.terminate());
136
+ }
137
+ })).pipe(Scope.provide(scope)));
138
+ return Effect.fn("BrowserTunnelHandler.connect")(function* (request) {
139
+ if (!isAllowedRequestOrigin2(request.headers.origin, request.headers.host, cors)) {
140
+ return HttpServerResponse.empty({ status: 403 });
141
+ }
142
+ const incoming = NodeHttpServerRequest.toIncomingMessage(request);
143
+ if (!(incoming instanceof IncomingMessage) || !isWebSocketUpgrade(request)) {
144
+ return HttpServerResponse.empty({ status: 400 });
145
+ }
146
+ const url = new URL(request.url, "http://localhost");
147
+ if (url.searchParams.has("ticket")) {
148
+ return HttpServerResponse.empty({ status: 403 });
149
+ }
150
+ const ticket = request.headers[BROWSER_TUNNEL_TICKET_HEADER]?.trim();
151
+ if (!ticket) {
152
+ return HttpServerResponse.empty({ status: 403 });
153
+ }
154
+ const rawSession = request.headers[BROWSER_TUNNEL_SESSION_HEADER]?.trim() ?? url.searchParams.get("sessionID")?.trim();
155
+ const connectionID = request.headers[BROWSER_TUNNEL_CONNECTION_HEADER]?.trim() ?? url.searchParams.get("connectionID")?.trim();
156
+ const rawProtocol = request.headers[BROWSER_TUNNEL_PROTOCOL_HEADER]?.trim() ?? url.searchParams.get("protocol")?.trim();
157
+ const protocol = rawProtocol ? Number(rawProtocol) : NaN;
158
+ const sessionID = rawSession ? Option.getOrUndefined(Schema.decodeUnknownOption(Session.ID)(rawSession)) : undefined;
159
+ if (!sessionID || !connectionID || protocol !== BROWSER_TUNNEL_PROTOCOL_VERSION) {
160
+ return HttpServerResponse.empty({ status: 403 });
161
+ }
162
+ const ref = LocationServiceMap.canonical(requestRef2(request));
163
+ const binding = yield* gateway.consumeTicket({
164
+ ticket,
165
+ location: ref,
166
+ sessionID,
167
+ connectionID,
168
+ protocol
169
+ });
170
+ if (!binding) {
171
+ return HttpServerResponse.empty({ status: 403 });
172
+ }
173
+ if (Option.isNone(yield* Effect.option(request.upgrade))) {
174
+ return HttpServerResponse.empty({ status: 400 });
175
+ }
176
+ return yield* Effect.gen(function* () {
177
+ const sockets = yield* server;
178
+ const ws = yield* upgradeSocket(sockets, incoming);
179
+ yield* HttpMiddleware.withLoggerDisabled(Effect.void);
180
+ const lifecycle = yield* LocationLifecycle.Service;
181
+ yield* lifecycle.retain;
182
+ yield* lifecycle.awaitShutdown.pipe(Effect.andThen(Effect.sync(() => ws.close(1012, "location shut down"))), Effect.forkChild);
183
+ yield* binding.onUpgrade(adaptWebSocket(ws));
184
+ return HttpServerResponse.empty();
185
+ }).pipe(Effect.scoped, Effect.provide(locations.get(ref)), locationErrors2, Effect.orElseSucceed(() => HttpServerResponse.empty()));
186
+ });
187
+ });
188
+
189
+ export { makeBrowserTunnel2 };
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  __export
3
- } from "./pairing-9rqn6x4v.js";
3
+ } from "./api-9rqn6x4v.js";
4
4
 
5
5
  // src/service-status.ts
6
6
  var exports_service_status = {};
@@ -1,22 +1,22 @@
1
1
  import {
2
2
  __export
3
- } from "./pairing-9rqn6x4v.js";
3
+ } from "./api-9rqn6x4v.js";
4
4
 
5
5
  // src/server-info.ts
6
6
  var exports_server_info = {};
7
7
  __export(exports_server_info, {
8
8
  ServerInfo: () => exports_server_info,
9
- Service: () => Service4,
9
+ Service: () => Service3,
10
10
  connectionURLs: () => connectionURLs2,
11
11
  layer: () => layer3
12
12
  });
13
13
  import { Context, Layer } from "effect";
14
14
  import { networkInterfaces } from "node:os";
15
15
 
16
- class Service4 extends Context.Service()("@opencode/server/ServerInfo") {
16
+ class Service3 extends Context.Service()("@opencode/server/ServerInfo") {
17
17
  }
18
18
  function layer3(urls, tmp, app = {}) {
19
- return Layer.succeed(Service4, Service4.of({ urls, app, paths: { tmp } }));
19
+ return Layer.succeed(Service3, Service3.of({ urls, app, paths: { tmp } }));
20
20
  }
21
21
  function connectionURLs2(value, requestedHostname) {
22
22
  const url = new URL(value);
@@ -38,4 +38,4 @@ function connectionURLs2(value, requestedHostname) {
38
38
  ];
39
39
  }
40
40
 
41
- export { Service4, layer3, connectionURLs2, exports_server_info };
41
+ export { Service3, layer3, connectionURLs2, exports_server_info };
@@ -1,39 +1,39 @@
1
1
  import {
2
2
  layer4
3
- } from "./pairing-br4x4prt.js";
3
+ } from "./api-br4x4prt.js";
4
4
  import {
5
5
  formLocationLayer2
6
- } from "./pairing-ca564221.js";
6
+ } from "./api-ca564221.js";
7
7
  import {
8
8
  sessionLocationLayer2
9
- } from "./pairing-ehyp3zqd.js";
9
+ } from "./api-ehyp3zqd.js";
10
10
  import {
11
11
  Api2
12
- } from "./pairing-whvq72as.js";
12
+ } from "./api-whvq72as.js";
13
13
  import {
14
14
  Config2
15
- } from "./pairing-j4at0y5c.js";
15
+ } from "./api-j4at0y5c.js";
16
16
  import {
17
17
  CorsConfig2
18
- } from "./pairing-q4bn6dy8.js";
18
+ } from "./api-q4bn6dy8.js";
19
19
  import {
20
20
  layer3
21
- } from "./pairing-yjbzmfhm.js";
21
+ } from "./api-3te71694.js";
22
22
  import {
23
23
  node2
24
- } from "./pairing-w9jcwh65.js";
24
+ } from "./api-mzs0n5xz.js";
25
25
  import {
26
26
  handlers2
27
- } from "./pairing-dms2vwqd.js";
27
+ } from "./api-0tgs6603.js";
28
28
  import {
29
29
  authorizationLayer2
30
- } from "./pairing-rktygpea.js";
30
+ } from "./api-29nx48hm.js";
31
31
  import {
32
32
  schemaErrorLayer2
33
- } from "./pairing-bd8755ek.js";
33
+ } from "./api-bd8755ek.js";
34
34
  import {
35
35
  defectResponseLayer2
36
- } from "./pairing-n26yr6pw.js";
36
+ } from "./api-n26yr6pw.js";
37
37
 
38
38
  // src/routes.ts
39
39
  import { Database } from "@opencode/core/database/database";
@@ -49,6 +49,7 @@ import { FileSystemSearch } from "@opencode/core/filesystem/search";
49
49
  import { Credential } from "@opencode/core/credential";
50
50
  import { Config } from "@opencode/core/config";
51
51
  import { PermissionSaved } from "@opencode/core/permission/saved";
52
+ import { BrowserTunnelGateway } from "@opencode/core/experimental/browser-tunnel";
52
53
  import { PtyTicket } from "@opencode/core/pty/ticket";
53
54
  import { PersistentPty } from "@opencode/core/persistent-pty";
54
55
  import { Project } from "@opencode/core/project";
@@ -113,6 +114,7 @@ var applicationServiceNodes = [
113
114
  PluginUpdate.node,
114
115
  PermissionSaved.node,
115
116
  PtyTicket.node,
117
+ BrowserTunnelGateway.node,
116
118
  Credential.node,
117
119
  WellKnown.node,
118
120
  node2,
@@ -4,16 +4,16 @@ import {
4
4
  missingMessage2,
5
5
  failedMessageDecode2,
6
6
  failedSnapshot2
7
- } from "./pairing-rqgv9x42.js";
7
+ } from "./api-rqgv9x42.js";
8
8
  import {
9
9
  locationErrors2
10
- } from "./pairing-br4x4prt.js";
10
+ } from "./api-br4x4prt.js";
11
11
  import {
12
12
  Api2
13
- } from "./pairing-whvq72as.js";
13
+ } from "./api-whvq72as.js";
14
14
  import {
15
15
  wantsMediaRefs2
16
- } from "./pairing-xthc02cw.js";
16
+ } from "./api-xthc02cw.js";
17
17
 
18
18
  // src/handlers/session.ts
19
19
  import { Instance } from "@opencode/core/instance/service";
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  missingSession2
3
- } from "./pairing-rqgv9x42.js";
3
+ } from "./api-rqgv9x42.js";
4
4
 
5
5
  // src/handlers/automation.ts
6
6
  import { Automation } from "@opencode/core/automation";
@@ -1,9 +1,9 @@
1
1
  import {
2
2
  response2
3
- } from "./pairing-br4x4prt.js";
3
+ } from "./api-br4x4prt.js";
4
4
  import {
5
5
  Api2
6
- } from "./pairing-whvq72as.js";
6
+ } from "./api-whvq72as.js";
7
7
 
8
8
  // src/handlers/skill.ts
9
9
  import { Skill } from "@opencode/core/skill";
@@ -1,9 +1,9 @@
1
1
  import {
2
2
  response2
3
- } from "./pairing-br4x4prt.js";
3
+ } from "./api-br4x4prt.js";
4
4
  import {
5
5
  Api2
6
- } from "./pairing-whvq72as.js";
6
+ } from "./api-whvq72as.js";
7
7
 
8
8
  // src/handlers/reference.ts
9
9
  import { Reference } from "@opencode/core/reference";
@@ -2,18 +2,18 @@ import {
2
2
  locationErrors2,
3
3
  response2,
4
4
  requestRef2
5
- } from "./pairing-br4x4prt.js";
5
+ } from "./api-br4x4prt.js";
6
6
  import {
7
7
  Api2
8
- } from "./pairing-whvq72as.js";
8
+ } from "./api-whvq72as.js";
9
9
  import {
10
10
  CorsConfig2,
11
11
  isAllowedRequestOrigin2
12
- } from "./pairing-q4bn6dy8.js";
12
+ } from "./api-q4bn6dy8.js";
13
13
  import {
14
14
  runPtySocket2,
15
15
  holdLocation2
16
- } from "./pairing-q187pxxd.js";
16
+ } from "./api-q187pxxd.js";
17
17
 
18
18
  // src/handlers/pty.ts
19
19
  import { Pty } from "@opencode/core/pty";
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  Api2
3
- } from "./pairing-whvq72as.js";
3
+ } from "./api-whvq72as.js";
4
4
 
5
5
  // src/handlers/project.ts
6
6
  import { Project } from "@opencode/core/project";
@@ -1,9 +1,9 @@
1
1
  import {
2
2
  response2
3
- } from "./pairing-br4x4prt.js";
3
+ } from "./api-br4x4prt.js";
4
4
  import {
5
5
  Api2
6
- } from "./pairing-whvq72as.js";
6
+ } from "./api-whvq72as.js";
7
7
 
8
8
  // src/handlers/form.ts
9
9
  import { Form } from "@opencode/core/form";
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  __export
3
- } from "./pairing-9rqn6x4v.js";
3
+ } from "./api-9rqn6x4v.js";
4
4
 
5
5
  // src/range.ts
6
6
  var exports_range = {};
@@ -1,9 +1,9 @@
1
1
  import {
2
2
  Api2
3
- } from "./pairing-whvq72as.js";
3
+ } from "./api-whvq72as.js";
4
4
  import {
5
5
  requireConnectable2
6
- } from "./pairing-2tmcamrc.js";
6
+ } from "./api-2tmcamrc.js";
7
7
 
8
8
  // src/handlers/credential.ts
9
9
  import { Credential } from "@opencode/core/credential";
@@ -0,0 +1,20 @@
1
+ import {
2
+ response2
3
+ } from "./api-br4x4prt.js";
4
+ import {
5
+ Api2
6
+ } from "./api-whvq72as.js";
7
+
8
+ // src/handlers/flag.ts
9
+ import { Flag } from "@opencode/core/flag";
10
+ import { ConfigFlag } from "@opencode/schema/config/flag";
11
+ import { Effect } from "effect";
12
+ import { HttpApiBuilder } from "effect/http-api";
13
+ var FlagHandler2 = HttpApiBuilder.group(Api2, "server.flag", (handlers) => Effect.gen(function* () {
14
+ return handlers.handle("experimental.flag.get", Effect.fn("server.flag.get")(function* () {
15
+ const flags = yield* Flag.Service;
16
+ return yield* response2(flags.all.pipe(Effect.map((all) => Object.fromEntries(ConfigFlag.ui.map((key) => [key, all[key].enabled])))));
17
+ }));
18
+ }));
19
+
20
+ export { FlagHandler2 };