@radheim/server 0.0.0-stage → 2.4.3

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 (210) hide show
  1. package/dist/api.d.ts +9383 -0
  2. package/dist/api.js +10 -0
  3. package/dist/auth.d.ts +21 -0
  4. package/dist/auth.js +20 -0
  5. package/dist/chunks/api-0q8mvh3b.js +62 -0
  6. package/dist/chunks/api-11hx8jza.js +39 -0
  7. package/dist/chunks/api-1jnx79t4.js +31 -0
  8. package/dist/chunks/api-1mn3274c.js +57 -0
  9. package/dist/chunks/api-238wcyzf.js +252 -0
  10. package/dist/chunks/api-280h8k1v.js +198 -0
  11. package/dist/chunks/api-31hzmefh.js +73 -0
  12. package/dist/chunks/api-34msk99p.js +208 -0
  13. package/dist/chunks/api-40z6h0fq.js +20 -0
  14. package/dist/chunks/api-5fr63cjn.js +27 -0
  15. package/dist/chunks/api-5ggmn0t6.js +348 -0
  16. package/dist/chunks/api-61ndsq4a.js +45 -0
  17. package/dist/chunks/api-7tqjsq7b.js +101 -0
  18. package/dist/chunks/api-8cw69z4p.js +15 -0
  19. package/dist/chunks/api-8sb6qqpn.js +28 -0
  20. package/dist/chunks/api-8tn84h85.js +39 -0
  21. package/dist/chunks/api-9bxtygz0.js +48 -0
  22. package/dist/chunks/api-9qr3r2v1.js +66 -0
  23. package/dist/chunks/api-9rqn6x4v.js +16 -0
  24. package/dist/chunks/api-azwdvyh3.js +4 -0
  25. package/dist/chunks/api-b3j0kcev.js +30 -0
  26. package/dist/chunks/api-bctzdhd7.js +21 -0
  27. package/dist/chunks/api-bnpt5zxx.js +36 -0
  28. package/dist/chunks/api-bxwfazps.js +90 -0
  29. package/dist/chunks/api-d4cyxj7e.js +80 -0
  30. package/dist/chunks/api-d8rk8yaw.js +20 -0
  31. package/dist/chunks/api-djs9m6v0.js +42 -0
  32. package/dist/chunks/api-e2746nhp.js +17 -0
  33. package/dist/chunks/api-e4v11dgy.js +58 -0
  34. package/dist/chunks/api-e6e4kz0w.js +23 -0
  35. package/dist/chunks/api-f6955nmc.js +19 -0
  36. package/dist/chunks/api-fhp54bwg.js +39 -0
  37. package/dist/chunks/api-fpzegjvk.js +35 -0
  38. package/dist/chunks/api-fq7f3wrn.js +13 -0
  39. package/dist/chunks/api-gg2tbqc5.js +270 -0
  40. package/dist/chunks/api-gghkbyq2.js +189 -0
  41. package/dist/chunks/api-ghyd9ren.js +32 -0
  42. package/dist/chunks/api-h8v4dbra.js +49 -0
  43. package/dist/chunks/api-hpgyxnbj.js +92 -0
  44. package/dist/chunks/api-jb6q2eqf.js +70 -0
  45. package/dist/chunks/api-k0fc7y6c.js +219 -0
  46. package/dist/chunks/api-kb0k6qg1.js +35 -0
  47. package/dist/chunks/api-kb431qm0.js +31 -0
  48. package/dist/chunks/api-kvefct3s.js +215 -0
  49. package/dist/chunks/api-mzafcgd5.js +23 -0
  50. package/dist/chunks/api-n0gqhwq7.js +109 -0
  51. package/dist/chunks/api-njzqh2v3.js +22 -0
  52. package/dist/chunks/api-nqw28mmv.js +62 -0
  53. package/dist/chunks/api-ns3kfwpq.js +48 -0
  54. package/dist/chunks/api-ph6j0w88.js +29 -0
  55. package/dist/chunks/api-q8azxbmk.js +38 -0
  56. package/dist/chunks/api-qft4mah5.js +33 -0
  57. package/dist/chunks/api-qz4nw4cc.js +130 -0
  58. package/dist/chunks/api-rrsy7az3.js +69 -0
  59. package/dist/chunks/api-t2s5ghf4.js +91 -0
  60. package/dist/chunks/api-t32e1bbt.js +32 -0
  61. package/dist/chunks/api-t7f8xf56.js +22 -0
  62. package/dist/chunks/api-trzj52xd.js +13 -0
  63. package/dist/chunks/api-v2h85c6p.js +143 -0
  64. package/dist/chunks/api-vtj5wyks.js +13 -0
  65. package/dist/chunks/api-wrj46kzw.js +41 -0
  66. package/dist/chunks/api-wrma0ern.js +36 -0
  67. package/dist/chunks/api-x180v472.js +22 -0
  68. package/dist/chunks/api-xcn5yyhy.js +134 -0
  69. package/dist/chunks/api-xthc02cw.js +6 -0
  70. package/dist/chunks/api-ygxfyj7m.js +111 -0
  71. package/dist/chunks/api-z3ybfekq.js +20 -0
  72. package/dist/chunks/api-zvb9sh2w.js +30 -0
  73. package/dist/content-headers.d.ts +13 -0
  74. package/dist/content-headers.js +12 -0
  75. package/dist/cors.d.ts +7 -0
  76. package/dist/cors.js +10 -0
  77. package/dist/event-feed.d.ts +44 -0
  78. package/dist/event-feed.js +20 -0
  79. package/dist/fetch.d.ts +164 -0
  80. package/dist/fetch.js +80 -0
  81. package/dist/handlers/agent.d.ts +1 -0
  82. package/dist/handlers/agent.js +11 -0
  83. package/dist/handlers/artifact.d.ts +62 -0
  84. package/dist/handlers/artifact.js +8 -0
  85. package/dist/handlers/automation.d.ts +23 -0
  86. package/dist/handlers/automation.js +7 -0
  87. package/dist/handlers/blob.d.ts +168 -0
  88. package/dist/handlers/blob.js +9 -0
  89. package/dist/handlers/command.d.ts +1 -0
  90. package/dist/handlers/command.js +11 -0
  91. package/dist/handlers/config.d.ts +1 -0
  92. package/dist/handlers/config.js +11 -0
  93. package/dist/handlers/credential.d.ts +4 -0
  94. package/dist/handlers/credential.js +12 -0
  95. package/dist/handlers/debug.d.ts +2 -0
  96. package/dist/handlers/debug.js +11 -0
  97. package/dist/handlers/event.d.ts +2 -0
  98. package/dist/handlers/event.js +12 -0
  99. package/dist/handlers/experimental/browser-tunnel.d.ts +11 -0
  100. package/dist/handlers/experimental/browser-tunnel.js +9 -0
  101. package/dist/handlers/flag.d.ts +1 -0
  102. package/dist/handlers/flag.js +11 -0
  103. package/dist/handlers/form.d.ts +1 -0
  104. package/dist/handlers/form.js +11 -0
  105. package/dist/handlers/fs.d.ts +2 -0
  106. package/dist/handlers/fs.js +13 -0
  107. package/dist/handlers/generate.d.ts +4 -0
  108. package/dist/handlers/generate.js +11 -0
  109. package/dist/handlers/integration.d.ts +7 -0
  110. package/dist/handlers/integration.js +13 -0
  111. package/dist/handlers/job.d.ts +73 -0
  112. package/dist/handlers/job.js +7 -0
  113. package/dist/handlers/location.d.ts +2 -0
  114. package/dist/handlers/location.js +11 -0
  115. package/dist/handlers/machine.d.ts +164 -0
  116. package/dist/handlers/machine.js +28 -0
  117. package/dist/handlers/mcp.d.ts +3 -0
  118. package/dist/handlers/mcp.js +13 -0
  119. package/dist/handlers/media.d.ts +6 -0
  120. package/dist/handlers/media.js +7 -0
  121. package/dist/handlers/message.d.ts +2 -0
  122. package/dist/handlers/message.js +12 -0
  123. package/dist/handlers/migration.d.ts +1 -0
  124. package/dist/handlers/migration.js +11 -0
  125. package/dist/handlers/model.d.ts +1 -0
  126. package/dist/handlers/model.js +11 -0
  127. package/dist/handlers/permission.d.ts +4 -0
  128. package/dist/handlers/permission.js +11 -0
  129. package/dist/handlers/persistent-pty.d.ts +3 -0
  130. package/dist/handlers/persistent-pty.js +25 -0
  131. package/dist/handlers/plugin.d.ts +2 -0
  132. package/dist/handlers/plugin.js +11 -0
  133. package/dist/handlers/project.d.ts +2 -0
  134. package/dist/handlers/project.js +11 -0
  135. package/dist/handlers/provider.d.ts +1 -0
  136. package/dist/handlers/provider.js +11 -0
  137. package/dist/handlers/pty-socket.d.ts +12 -0
  138. package/dist/handlers/pty-socket.js +8 -0
  139. package/dist/handlers/pty.d.ts +3 -0
  140. package/dist/handlers/pty.js +13 -0
  141. package/dist/handlers/push.d.ts +28 -0
  142. package/dist/handlers/push.js +6 -0
  143. package/dist/handlers/reference.d.ts +1 -0
  144. package/dist/handlers/reference.js +11 -0
  145. package/dist/handlers/rpc.d.ts +1 -0
  146. package/dist/handlers/rpc.js +11 -0
  147. package/dist/handlers/server.d.ts +4 -0
  148. package/dist/handlers/server.js +14 -0
  149. package/dist/handlers/session-error.d.ts +11 -0
  150. package/dist/handlers/session-error.js +14 -0
  151. package/dist/handlers/session.d.ts +5 -0
  152. package/dist/handlers/session.js +12 -0
  153. package/dist/handlers/shell.d.ts +1 -0
  154. package/dist/handlers/shell.js +11 -0
  155. package/dist/handlers/skill.d.ts +1 -0
  156. package/dist/handlers/skill.js +11 -0
  157. package/dist/handlers/space.d.ts +54 -0
  158. package/dist/handlers/space.js +7 -0
  159. package/dist/handlers/usage.d.ts +1 -0
  160. package/dist/handlers/usage.js +11 -0
  161. package/dist/handlers/vcs.d.ts +4 -0
  162. package/dist/handlers/vcs.js +11 -0
  163. package/dist/handlers/voice.d.ts +3 -0
  164. package/dist/handlers/voice.js +11 -0
  165. package/dist/handlers/websearch.d.ts +1 -0
  166. package/dist/handlers/websearch.js +11 -0
  167. package/dist/handlers/worktree.d.ts +2 -0
  168. package/dist/handlers/worktree.js +11 -0
  169. package/dist/handlers.d.ts +3 -0
  170. package/dist/handlers.js +63 -0
  171. package/dist/location.d.ts +28 -0
  172. package/dist/location.js +17 -0
  173. package/dist/media-uri.d.ts +6 -0
  174. package/dist/media-uri.js +6 -0
  175. package/dist/middleware/authorization.d.ts +8 -0
  176. package/dist/middleware/authorization.js +13 -0
  177. package/dist/middleware/defect-response.d.ts +2 -0
  178. package/dist/middleware/defect-response.js +6 -0
  179. package/dist/middleware/form-location.d.ts +18 -0
  180. package/dist/middleware/form-location.js +10 -0
  181. package/dist/middleware/schema-error.d.ts +3 -0
  182. package/dist/middleware/schema-error.js +8 -0
  183. package/dist/middleware/session-location.d.ts +17 -0
  184. package/dist/middleware/session-location.js +10 -0
  185. package/dist/options.d.ts +130 -0
  186. package/dist/options.js +55 -0
  187. package/dist/pairing.d.ts +13 -0
  188. package/dist/pairing.js +10 -0
  189. package/dist/process.d.ts +70 -0
  190. package/dist/process.js +241 -0
  191. package/dist/range.d.ts +6 -0
  192. package/dist/range.js +8 -0
  193. package/dist/request-site.d.ts +11 -0
  194. package/dist/request-site.js +11 -0
  195. package/dist/request-tracing.d.ts +1 -0
  196. package/dist/request-tracing.js +6 -0
  197. package/dist/routes.d.ts +54 -0
  198. package/dist/routes.js +69 -0
  199. package/dist/server-info.d.ts +14 -0
  200. package/dist/server-info.js +12 -0
  201. package/dist/service-status.d.ts +25 -0
  202. package/dist/service-status.js +8 -0
  203. package/dist/space-store.d.ts +62 -0
  204. package/dist/space-store.js +16 -0
  205. package/dist/workerd-machine-link.d.ts +107 -0
  206. package/dist/workerd-machine-link.js +19 -0
  207. package/dist/workerd.d.ts +113 -0
  208. package/dist/workerd.js +168 -0
  209. package/package.json +50 -4
  210. package/README.md +0 -3
@@ -0,0 +1,32 @@
1
+ import {
2
+ __export
3
+ } from "./api-9rqn6x4v.js";
4
+
5
+ // src/content-headers.ts
6
+ var exports_content_headers = {};
7
+ __export(exports_content_headers, {
8
+ CONTENT_SECURITY_POLICY: () => CONTENT_SECURITY_POLICY2,
9
+ ContentHeaders: () => exports_content_headers,
10
+ disposition: () => disposition2,
11
+ download: () => download2
12
+ });
13
+ import path from "path";
14
+ var CONTENT_SECURITY_POLICY2 = "default-src 'none'; img-src 'self'; media-src 'self'; sandbox";
15
+ var TEXT_TYPE = "text/plain; charset=utf-8";
16
+ function download2(input) {
17
+ return {
18
+ "content-type": /^(text\/html|text\/javascript|application\/(x-)?javascript)\b|[/+]xml\b/i.test(input.mime) ? TEXT_TYPE : input.mime,
19
+ "content-disposition": disposition2(input.path === undefined ? "" : path.basename(input.path)),
20
+ "content-security-policy": CONTENT_SECURITY_POLICY2,
21
+ "x-content-type-options": "nosniff"
22
+ };
23
+ }
24
+ function disposition2(name) {
25
+ if (name === "")
26
+ return "attachment";
27
+ const fallback = name.replace(/[^\x20-\x7e]|["\\%]/g, "_");
28
+ const encoded = encodeURIComponent(name).replace(/['()*]/g, (char) => `%${char.charCodeAt(0).toString(16).toUpperCase()}`);
29
+ return `attachment; filename="${fallback}"; filename*=UTF-8''${encoded}`;
30
+ }
31
+
32
+ export { CONTENT_SECURITY_POLICY2, download2, disposition2, exports_content_headers };
@@ -0,0 +1,22 @@
1
+ import {
2
+ response2
3
+ } from "./api-0q8mvh3b.js";
4
+ import {
5
+ Api2
6
+ } from "./api-f6955nmc.js";
7
+
8
+ // src/handlers/model.ts
9
+ import { Model } from "@radheim/core/model";
10
+ import { Effect } from "effect";
11
+ import { HttpApiBuilder } from "effect/http-api";
12
+ var ModelHandler2 = HttpApiBuilder.group(Api2, "server.model", (handlers) => Effect.gen(function* () {
13
+ return handlers.handle("model.list", Effect.fnUntraced(function* (ctx) {
14
+ const models = yield* Model.Service;
15
+ return yield* response2(models.available(ctx.query.types));
16
+ })).handle("model.default", Effect.fnUntraced(function* () {
17
+ const models = yield* Model.Service;
18
+ return yield* response2(models.default());
19
+ }));
20
+ }));
21
+
22
+ export { ModelHandler2 };
@@ -0,0 +1,13 @@
1
+ import {
2
+ response2
3
+ } from "./api-0q8mvh3b.js";
4
+ import {
5
+ Api2
6
+ } from "./api-f6955nmc.js";
7
+
8
+ // src/handlers/command.ts
9
+ import { Command } from "@radheim/core/command";
10
+ import { HttpApiBuilder } from "effect/http-api";
11
+ var CommandHandler2 = HttpApiBuilder.group(Api2, "server.command", (handlers) => handlers.handle("command.list", () => response2(Command.Service.use((command) => command.list()))));
12
+
13
+ export { CommandHandler2 };
@@ -0,0 +1,143 @@
1
+ import {
2
+ missingSession2
3
+ } from "./api-ghyd9ren.js";
4
+ import {
5
+ locationErrors2,
6
+ response2,
7
+ requestRef2
8
+ } from "./api-0q8mvh3b.js";
9
+
10
+ // src/handlers/artifact.ts
11
+ import { Artifact } from "@radheim/core/artifact";
12
+ import { KV } from "@radheim/core/kv";
13
+ import { Location } from "@radheim/core/location";
14
+ import { LocationServiceMap } from "@radheim/core/location-service-map";
15
+ import { AbsolutePath } from "@radheim/core/schema";
16
+ import { Session } from "@radheim/core/session";
17
+ import {
18
+ ArtifactNotFoundError,
19
+ FileNotFoundError,
20
+ ForbiddenError,
21
+ InvalidRequestError,
22
+ ProviderNotFoundError,
23
+ ServiceUnavailableError
24
+ } from "@radheim/protocol/errors";
25
+ import { Effect } from "effect";
26
+ import { HttpServerResponse } from "effect/http";
27
+ import { HttpApiSchema } from "effect/http-api";
28
+ var makeArtifact2 = Effect.gen(function* () {
29
+ const locations = yield* LocationServiceMap.Service;
30
+ const sessions = yield* Session.Service;
31
+ const kv = yield* KV.Service;
32
+ const explicitDirectory = (request, location) => {
33
+ if (location?.directory !== undefined)
34
+ return location.directory;
35
+ const query = new URL(request.url, "http://localhost").searchParams.get("location[directory]");
36
+ if (query)
37
+ return query;
38
+ const header = request.headers["x-opencode-directory"];
39
+ if (!header)
40
+ return;
41
+ try {
42
+ return decodeURIComponent(header);
43
+ } catch {
44
+ return header;
45
+ }
46
+ };
47
+ const resolveLocation = (request, options) => Effect.gen(function* () {
48
+ const requestedDir = explicitDirectory(request, options.location);
49
+ if (requestedDir !== undefined) {
50
+ return Location.Ref.make({ directory: AbsolutePath.make(requestedDir) });
51
+ }
52
+ if (options.sessionID !== undefined) {
53
+ const session = yield* sessions.get(options.sessionID).pipe(Effect.mapError(missingSession2));
54
+ return session.location;
55
+ }
56
+ if (options.artifactID !== undefined) {
57
+ const directory = yield* Artifact.locate(kv, options.artifactID);
58
+ if (directory !== undefined) {
59
+ return Location.Ref.make({ directory: AbsolutePath.make(directory) });
60
+ }
61
+ }
62
+ return requestRef2(request);
63
+ });
64
+ const inLocation = (request, options, effect) => Effect.gen(function* () {
65
+ const ref = yield* resolveLocation(request, options);
66
+ return yield* effect.pipe(Effect.provide(locations.get(ref)), locationErrors2);
67
+ });
68
+ const mapCommon = (effect) => effect.pipe(Effect.catchTags({
69
+ "Artifact.DisabledError": (error) => Effect.fail(new ForbiddenError({ message: error.message })),
70
+ "Artifact.NotFoundError": (error) => Effect.fail(new ArtifactNotFoundError({ artifactID: error.artifactID, message: error.message })),
71
+ "Artifact.ProviderNotFoundError": (error) => Effect.fail(new ProviderNotFoundError({ providerID: error.providerID, message: error.message })),
72
+ "Artifact.InvalidError": (error) => Effect.fail(new InvalidRequestError({ message: error.message, kind: "artifact_invalid", field: error.field })),
73
+ "Artifact.ProviderError": (error) => Effect.fail(new ServiceUnavailableError({ message: error.message, service: error.providerID })),
74
+ "Session.NotFoundError": (error) => Effect.fail(missingSession2(error))
75
+ }));
76
+ return {
77
+ providers: (query, request) => inLocation(request, { location: query.location }, Effect.gen(function* () {
78
+ const artifacts = yield* Artifact.Service;
79
+ return yield* response2(artifacts.providers());
80
+ })).pipe(mapCommon),
81
+ list: (query, request) => inLocation(request, { location: query.location, sessionID: query.sessionID }, Effect.gen(function* () {
82
+ const artifacts = yield* Artifact.Service;
83
+ return yield* response2(artifacts.list({ sessionID: query.sessionID, provider: query.provider }));
84
+ })).pipe(mapCommon),
85
+ create: (query, payload, request) => inLocation(request, { location: query.location, sessionID: payload.sessionID }, Effect.gen(function* () {
86
+ const artifacts = yield* Artifact.Service;
87
+ return yield* response2(artifacts.create(payload));
88
+ })).pipe(mapCommon),
89
+ get: (artifactID, query, request) => inLocation(request, { location: query.location, artifactID }, Effect.gen(function* () {
90
+ const artifacts = yield* Artifact.Service;
91
+ return yield* response2(artifacts.get(artifactID));
92
+ })).pipe(mapCommon),
93
+ update: (artifactID, query, payload, request) => inLocation(request, { location: query.location, sessionID: payload.sessionID, artifactID }, Effect.gen(function* () {
94
+ const artifacts = yield* Artifact.Service;
95
+ return yield* response2(artifacts.update(artifactID, payload));
96
+ })).pipe(mapCommon),
97
+ remove: (artifactID, query, request) => inLocation(request, { location: query.location, artifactID }, Effect.gen(function* () {
98
+ const artifacts = yield* Artifact.Service;
99
+ yield* artifacts.remove(artifactID);
100
+ return HttpApiSchema.NoContent.make();
101
+ })).pipe(mapCommon),
102
+ view: (artifactID, query, request) => inLocation(request, { location: query.location, artifactID }, Effect.gen(function* () {
103
+ const artifacts = yield* Artifact.Service;
104
+ const parsed = new URL(request.url, "http://localhost");
105
+ const prefix = `/api/experimental/artifacts/${encodeURIComponent(artifactID)}/view`;
106
+ if (parsed.pathname === prefix) {
107
+ yield* artifacts.info(artifactID);
108
+ return HttpServerResponse.empty({
109
+ status: 308,
110
+ headers: { location: `${prefix}/${parsed.search}` }
111
+ });
112
+ }
113
+ const subpath = extractViewSubpath(request.url, artifactID);
114
+ const file = yield* artifacts.readLocalFile(artifactID, subpath).pipe(Effect.catchTag("Artifact.FileMissingError", (error) => Effect.fail(new FileNotFoundError({ path: error.path, message: error.message }))));
115
+ return HttpServerResponse.uint8Array(file.bytes, {
116
+ status: 200,
117
+ contentType: file.mime,
118
+ headers: {
119
+ "access-control-allow-origin": "*",
120
+ "cache-control": "private, no-cache",
121
+ "content-security-policy": "sandbox allow-scripts",
122
+ "x-content-type-options": "nosniff"
123
+ }
124
+ });
125
+ })).pipe(mapCommon)
126
+ };
127
+ });
128
+ function extractViewSubpath(url, artifactID) {
129
+ const pathname = new URL(url, "http://localhost").pathname;
130
+ const prefix = `/api/experimental/artifacts/${encodeURIComponent(artifactID)}/view/`;
131
+ if (!pathname.startsWith(prefix))
132
+ return;
133
+ const raw = pathname.slice(prefix.length);
134
+ if (!raw)
135
+ return;
136
+ try {
137
+ return decodeURIComponent(raw);
138
+ } catch {
139
+ return raw;
140
+ }
141
+ }
142
+
143
+ export { makeArtifact2 };
@@ -0,0 +1,13 @@
1
+ import {
2
+ Api2
3
+ } from "./api-f6955nmc.js";
4
+
5
+ // src/handlers/migration.ts
6
+ import { V1Migration } from "@radheim/core/database/v1-migration";
7
+ import { HttpApiBuilder } from "effect/http-api";
8
+ import { Effect } from "effect";
9
+ var MigrationHandler2 = HttpApiBuilder.group(Api2, "server.migration", (handlers) => handlers.handle("migration.v1.status", Effect.fnUntraced(function* () {
10
+ return yield* V1Migration.status();
11
+ })));
12
+
13
+ export { MigrationHandler2 };
@@ -0,0 +1,41 @@
1
+ import {
2
+ __export
3
+ } from "./api-9rqn6x4v.js";
4
+
5
+ // src/server-info.ts
6
+ var exports_server_info = {};
7
+ __export(exports_server_info, {
8
+ ServerInfo: () => exports_server_info,
9
+ Service: () => Service2,
10
+ connectionURLs: () => connectionURLs2,
11
+ layer: () => layer2
12
+ });
13
+ import { Context, Layer } from "effect";
14
+ import { networkInterfaces } from "node:os";
15
+
16
+ class Service2 extends Context.Service()("@radheim/server/ServerInfo") {
17
+ }
18
+ function layer2(urls, tmp, app = {}) {
19
+ return Layer.succeed(Service2, Service2.of({ urls, app, paths: { tmp } }));
20
+ }
21
+ function connectionURLs2(value, requestedHostname) {
22
+ const url = new URL(value);
23
+ const hostname = requestedHostname ?? url.hostname;
24
+ const family = hostname === "0.0.0.0" ? "IPv4" : hostname === "::" || hostname === "[::]" ? "IPv6" : undefined;
25
+ if (family === undefined)
26
+ return [value];
27
+ const loopback = new URL(value);
28
+ loopback.hostname = family === "IPv6" ? "[::1]" : "127.0.0.1";
29
+ return [
30
+ ...new Set([
31
+ loopback.toString().replace(/\/$/, ""),
32
+ ...Object.values(networkInterfaces()).flatMap((entries) => entries ?? []).filter((entry) => !entry.internal && entry.family === family).map((entry) => {
33
+ const result = new URL(value);
34
+ result.hostname = family === "IPv6" ? `[${entry.address}]` : entry.address;
35
+ return result.toString().replace(/\/$/, "");
36
+ })
37
+ ])
38
+ ];
39
+ }
40
+
41
+ export { Service2, layer2, connectionURLs2, exports_server_info };
@@ -0,0 +1,36 @@
1
+ import {
2
+ Api2
3
+ } from "./api-f6955nmc.js";
4
+ import {
5
+ Service5,
6
+ frame2
7
+ } from "./api-7tqjsq7b.js";
8
+
9
+ // src/handlers/event.ts
10
+ import { Event } from "@radheim/schema/event";
11
+ import { Effect, Stream } from "effect";
12
+ import { HttpServerResponse } from "effect/http";
13
+ import { HttpApiBuilder } from "effect/http-api";
14
+ var EventHandler2 = HttpApiBuilder.group(Api2, "server.event", (handlers) => Effect.gen(function* () {
15
+ const feed = yield* Service5;
16
+ return handlers.handleRaw("event.subscribe", (ctx) => Effect.gen(function* () {
17
+ const output = Stream.unwrap(feed.subscribe(ctx.query.types).pipe(Effect.map((subscription) => Stream.make(frame2({
18
+ id: Event.ID.create(),
19
+ type: "server.connected",
20
+ data: { stream: subscription.id }
21
+ })).pipe(Stream.concat(subscription.events)))));
22
+ const heartbeat = Stream.tick("15 seconds").pipe(Stream.map(() => `: heartbeat
23
+
24
+ `));
25
+ return HttpServerResponse.stream(output.pipe(Stream.merge(heartbeat, { haltStrategy: "left" }), Stream.encodeText), {
26
+ contentType: "text/event-stream",
27
+ headers: {
28
+ "Cache-Control": "no-cache, no-transform",
29
+ "X-Accel-Buffering": "no",
30
+ "X-Content-Type-Options": "nosniff"
31
+ }
32
+ });
33
+ }));
34
+ }));
35
+
36
+ export { EventHandler2 };
@@ -0,0 +1,22 @@
1
+ import {
2
+ Api2
3
+ } from "./api-f6955nmc.js";
4
+
5
+ // src/handlers/config.ts
6
+ import { Config } from "@radheim/core/config";
7
+ import { ShellSelect } from "@radheim/core/shell/select";
8
+ import { Effect } from "effect";
9
+ import { HttpApiBuilder } from "effect/http-api";
10
+ var ConfigHandler2 = HttpApiBuilder.group(Api2, "server.config", (handlers) => handlers.handle("config.get", () => Config.Service.use((config) => config.entries())).handle("config.update", Effect.fnUntraced(function* (ctx) {
11
+ const config = yield* Config.Service;
12
+ if (!config.update)
13
+ return yield* Effect.die(new Error("Config updates are unavailable"));
14
+ return yield* config.update(ctx.payload).pipe(Effect.orDie);
15
+ })).handle("config.shells", Effect.fnUntraced(function* () {
16
+ const shell = yield* ShellSelect.Service;
17
+ if (!shell.list)
18
+ return yield* Effect.die(new Error("Shell discovery is unavailable"));
19
+ return yield* shell.list();
20
+ })));
21
+
22
+ export { ConfigHandler2 };
@@ -0,0 +1,134 @@
1
+ import {
2
+ response2
3
+ } from "./api-0q8mvh3b.js";
4
+ import {
5
+ Api2
6
+ } from "./api-f6955nmc.js";
7
+ import {
8
+ download2
9
+ } from "./api-t32e1bbt.js";
10
+ import {
11
+ parse2
12
+ } from "./api-8sb6qqpn.js";
13
+
14
+ // src/handlers/fs.ts
15
+ import { Environment } from "@radheim/core/environment/index";
16
+ import { FileSystem } from "@radheim/core/filesystem";
17
+ import { FileWatch } from "@radheim/core/filesystem/file-watch";
18
+ import { Location } from "@radheim/core/location";
19
+ import { RelativePath } from "@radheim/core/schema";
20
+ import { FileNotFoundError, ServiceUnavailableError } from "@radheim/protocol/errors";
21
+ import { Effect, Option, Stream } from "effect";
22
+ import { HttpServerResponse } from "effect/http";
23
+ import { HttpApiBuilder } from "effect/http-api";
24
+ import path from "path";
25
+ var FileSystemHandler2 = HttpApiBuilder.group(Api2, "server.fs", (handlers) => Effect.gen(function* () {
26
+ const fileWatch = yield* FileWatch.Service;
27
+ return handlers.handleRaw("fs.read", (ctx) => Effect.gen(function* () {
28
+ const path2 = yield* decodeRequestPath(ctx.request.url);
29
+ const fs = yield* FileSystem.Service;
30
+ const file = yield* fs.read({ path: path2 }).pipe(Effect.catchTags({
31
+ "FileSystem.NotFoundError": (error) => Effect.fail(new FileNotFoundError({ path: error.path, message: `File not found: ${error.path}` })),
32
+ "FileSystem.UnavailableError": (error) => Effect.fail(serviceUnavailable(error))
33
+ }));
34
+ return serveFile(ctx.request, file, download2({ path: path2, mime: file.mime }));
35
+ })).handle("fs.list", (ctx) => response2(Effect.gen(function* () {
36
+ const fs = yield* FileSystem.Service;
37
+ return yield* fs.list(ctx.query).pipe(Effect.catchTags({
38
+ "FileSystem.NotFoundError": (error) => Effect.fail(new FileNotFoundError({ path: error.path, message: `Directory not found: ${error.path}` })),
39
+ "FileSystem.UnavailableError": (error) => Effect.fail(serviceUnavailable(error))
40
+ }));
41
+ }))).handle("fs.find", (ctx) => response2(Effect.gen(function* () {
42
+ const fs = yield* FileSystem.Service;
43
+ return yield* fs.find(ctx.query).pipe(Effect.mapError(serviceUnavailable));
44
+ }))).handle("fs.write", (ctx) => response2(Effect.gen(function* () {
45
+ const fs = yield* FileSystem.Service;
46
+ return yield* fs.write({ path: ctx.query.path, data: ctx.payload }).pipe(Effect.mapError(serviceUnavailable));
47
+ }))).handle("fs.watch", (ctx) => Effect.gen(function* () {
48
+ const environment = yield* Environment.Service;
49
+ if (!environment.local)
50
+ return yield* new ServiceUnavailableError({
51
+ service: "filewatcher",
52
+ message: "File watching is not available for this location"
53
+ });
54
+ const fs = yield* FileSystem.Service;
55
+ const location = yield* Location.Service;
56
+ yield* fs.read({ path: RelativePath.make(ctx.payload.path) }).pipe(Effect.catchTags({
57
+ "FileSystem.NotFoundError": (error) => Effect.fail(new FileNotFoundError({ path: error.path, message: `File not found: ${error.path}` })),
58
+ "FileSystem.UnavailableError": (error) => Effect.fail(serviceUnavailable(error))
59
+ }));
60
+ yield* fileWatch.watch({
61
+ location: { directory: location.directory, workspaceID: location.workspaceID },
62
+ file: path.resolve(location.directory, ctx.payload.path)
63
+ }).pipe(Effect.mapError((error) => new ServiceUnavailableError({ message: error.message, service: "filewatcher" })));
64
+ })).handle("fs.unwatch", (ctx) => Effect.gen(function* () {
65
+ const environment = yield* Environment.Service;
66
+ if (!environment.local)
67
+ return;
68
+ const location = yield* Location.Service;
69
+ yield* fileWatch.unwatch({
70
+ location: { directory: location.directory, workspaceID: location.workspaceID },
71
+ file: path.resolve(location.directory, ctx.payload.path)
72
+ });
73
+ }));
74
+ }));
75
+ var serviceUnavailable = (error) => new ServiceUnavailableError({ message: error.message, service: "filesystem" });
76
+ function decodeRequestPath(url) {
77
+ const raw = new URL(url, "http://localhost").pathname.slice(13);
78
+ return Effect.try({
79
+ try: () => RelativePath.make(decodeURIComponent(raw)),
80
+ catch: () => new FileNotFoundError({ path: raw, message: `File not found: ${raw}` })
81
+ });
82
+ }
83
+ function serveFile(request, file, content) {
84
+ const etag = `W/"${file.size.toString(16)}-${Option.match(file.mtime, {
85
+ onNone: () => "0",
86
+ onSome: (mtime) => mtime.getTime().toString(16)
87
+ })}"`;
88
+ const lastModified = Option.getOrUndefined(Option.map(file.mtime, (mtime) => mtime.toUTCString()));
89
+ const validators = {
90
+ "cache-control": "no-cache, no-transform",
91
+ etag,
92
+ ...lastModified === undefined ? {} : { "last-modified": lastModified }
93
+ };
94
+ if (isNotModified(request, etag, lastModified))
95
+ return HttpServerResponse.empty({ status: 304, headers: { ...validators, ...content } });
96
+ const rangeHeader = request.method === "GET" ? request.headers["range"] : undefined;
97
+ const range = rangeHeader !== undefined && matchesIfRange(request.headers["if-range"], etag, lastModified) ? parse2(rangeHeader, file.size) : undefined;
98
+ if (range === "unsatisfiable")
99
+ return HttpServerResponse.empty({
100
+ status: 416,
101
+ headers: { "accept-ranges": "bytes", "content-range": `bytes */${file.size}` }
102
+ });
103
+ const offset = range?.start ?? 0;
104
+ const length = range === undefined ? file.size : range.end - range.start + 1;
105
+ return HttpServerResponse.stream(length === 0 ? Stream.empty : file.stream({ offset, bytesToRead: length }), {
106
+ status: range === undefined ? 200 : 206,
107
+ contentLength: length,
108
+ headers: {
109
+ ...validators,
110
+ ...content,
111
+ "accept-ranges": "bytes",
112
+ ...range === undefined ? {} : { "content-range": `bytes ${range.start}-${range.end}/${file.size}` }
113
+ }
114
+ });
115
+ }
116
+ function isNotModified(request, etag, lastModified) {
117
+ const ifNoneMatch = request.headers["if-none-match"];
118
+ if (ifNoneMatch !== undefined)
119
+ return ifNoneMatch.split(",").some((tag) => tag.trim() === "*" || stripWeak(tag) === stripWeak(etag));
120
+ const ifModifiedSince = request.headers["if-modified-since"];
121
+ return ifModifiedSince !== undefined && lastModified !== undefined && Date.parse(lastModified) <= Date.parse(ifModifiedSince);
122
+ }
123
+ function matchesIfRange(ifRange, etag, lastModified) {
124
+ if (ifRange === undefined)
125
+ return true;
126
+ if (/^\s*(w\/)?"/i.test(ifRange))
127
+ return stripWeak(ifRange) === stripWeak(etag);
128
+ return lastModified !== undefined && Date.parse(ifRange) === Date.parse(lastModified);
129
+ }
130
+ function stripWeak(etag) {
131
+ return etag.trim().replace(/^w\//i, "");
132
+ }
133
+
134
+ export { FileSystemHandler2 };
@@ -0,0 +1,6 @@
1
+ // src/media-uri.ts
2
+ var CAPABILITIES_HEADER = "x-opencode-capabilities";
3
+ var MEDIA_URI_CAPABILITY = "experimental-media-uri";
4
+ var wantsMediaRefs2 = (request) => request.headers[CAPABILITIES_HEADER]?.split(",").some((token) => token.trim().toLowerCase() === MEDIA_URI_CAPABILITY) ?? false;
5
+
6
+ export { wantsMediaRefs2 };
@@ -0,0 +1,111 @@
1
+ import {
2
+ GenerateHandler2
3
+ } from "./api-t2s5ghf4.js";
4
+ import {
5
+ VoiceHandler2
6
+ } from "./api-kb431qm0.js";
7
+ import {
8
+ MessageHandler2
9
+ } from "./api-rrsy7az3.js";
10
+ import {
11
+ ModelHandler2
12
+ } from "./api-t7f8xf56.js";
13
+ import {
14
+ ProviderHandler2
15
+ } from "./api-ph6j0w88.js";
16
+ import {
17
+ SessionHandler2
18
+ } from "./api-5ggmn0t6.js";
19
+ import {
20
+ PermissionHandler2
21
+ } from "./api-hpgyxnbj.js";
22
+ import {
23
+ FileSystemHandler2
24
+ } from "./api-xcn5yyhy.js";
25
+ import {
26
+ FormHandler2
27
+ } from "./api-e2746nhp.js";
28
+ import {
29
+ CommandHandler2
30
+ } from "./api-trzj52xd.js";
31
+ import {
32
+ SkillHandler2
33
+ } from "./api-b3j0kcev.js";
34
+ import {
35
+ RpcHandler2
36
+ } from "./api-d8rk8yaw.js";
37
+ import {
38
+ layer3
39
+ } from "./api-7tqjsq7b.js";
40
+ import {
41
+ EventHandler2
42
+ } from "./api-wrma0ern.js";
43
+ import {
44
+ AgentHandler2
45
+ } from "./api-mzafcgd5.js";
46
+ import {
47
+ PluginHandler2
48
+ } from "./api-jb6q2eqf.js";
49
+ import {
50
+ ServerHandler2
51
+ } from "./api-1mn3274c.js";
52
+ import {
53
+ DebugHandler2
54
+ } from "./api-q8azxbmk.js";
55
+ import {
56
+ PtyHandler2
57
+ } from "./api-qz4nw4cc.js";
58
+ import {
59
+ extension2
60
+ } from "./api-k0fc7y6c.js";
61
+ import {
62
+ PersistentPtyHandler2
63
+ } from "./api-34msk99p.js";
64
+ import {
65
+ ShellHandler2
66
+ } from "./api-kb0k6qg1.js";
67
+ import {
68
+ ReferenceHandler2
69
+ } from "./api-fq7f3wrn.js";
70
+ import {
71
+ LocationHandler2
72
+ } from "./api-njzqh2v3.js";
73
+ import {
74
+ IntegrationHandler2
75
+ } from "./api-280h8k1v.js";
76
+ import {
77
+ WebSearchHandler2
78
+ } from "./api-fhp54bwg.js";
79
+ import {
80
+ UsageHandler2
81
+ } from "./api-z3ybfekq.js";
82
+ import {
83
+ FlagHandler2
84
+ } from "./api-40z6h0fq.js";
85
+ import {
86
+ McpHandler2
87
+ } from "./api-n0gqhwq7.js";
88
+ import {
89
+ CredentialHandler2
90
+ } from "./api-nqw28mmv.js";
91
+ import {
92
+ ProjectHandler2
93
+ } from "./api-8cw69z4p.js";
94
+ import {
95
+ WorktreeHandler2
96
+ } from "./api-djs9m6v0.js";
97
+ import {
98
+ VcsHandler2
99
+ } from "./api-31hzmefh.js";
100
+ import {
101
+ MigrationHandler2
102
+ } from "./api-vtj5wyks.js";
103
+ import {
104
+ ConfigHandler2
105
+ } from "./api-x180v472.js";
106
+
107
+ // src/handlers.ts
108
+ import { Layer } from "effect";
109
+ 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(layer3(extension2))), PtyHandler2, PersistentPtyHandler2, ShellHandler2, ReferenceHandler2, WorktreeHandler2, VcsHandler2, ConfigHandler2);
110
+
111
+ export { handlers2 };
@@ -0,0 +1,20 @@
1
+ import {
2
+ response2
3
+ } from "./api-0q8mvh3b.js";
4
+ import {
5
+ Api2
6
+ } from "./api-f6955nmc.js";
7
+
8
+ // src/handlers/usage.ts
9
+ import { UsageLimits } from "@radheim/core/usage-limits";
10
+ import { ServiceUnavailableError } from "@radheim/protocol/errors";
11
+ import { Effect } from "effect";
12
+ import { HttpApiBuilder } from "effect/http-api";
13
+ var UsageHandler2 = HttpApiBuilder.group(Api2, "server.usage", (handlers) => Effect.gen(function* () {
14
+ return handlers.handle("usage.limits", Effect.fn("server.usage.limits")(function* () {
15
+ const limits = yield* UsageLimits.Service;
16
+ return yield* response2(limits.get().pipe(Effect.map((info) => info ?? null), Effect.mapError((error) => new ServiceUnavailableError({ message: error.message, service: "opencode" }))));
17
+ }));
18
+ }));
19
+
20
+ export { UsageHandler2 };
@@ -0,0 +1,30 @@
1
+ // src/handlers/pty-socket.ts
2
+ import { LocationLifecycle } from "@radheim/core/location-lifecycle";
3
+ import { Effect, Queue } from "effect";
4
+ import { Socket } from "effect/socket";
5
+ function runPtySocket2(input) {
6
+ const drain = Effect.gen(function* () {
7
+ const writer = yield* input.socket.writer;
8
+ while (true) {
9
+ const item = yield* Queue.take(input.outbox);
10
+ yield* writer.write(item);
11
+ if (item instanceof Socket.CloseEvent)
12
+ return;
13
+ }
14
+ });
15
+ const read = Effect.gen(function* () {
16
+ const reader = yield* input.socket.reader;
17
+ if (input.onOpen)
18
+ yield* input.onOpen;
19
+ while (true)
20
+ yield* Effect.forEach(yield* reader.pull, input.onMessage, { discard: true });
21
+ });
22
+ return Effect.raceFirst(drain, read).pipe(Effect.ensuring(Effect.sync(input.detach)), Effect.catchReason("SocketError", "SocketCloseError", () => Effect.void), Effect.orDie);
23
+ }
24
+ var holdLocation2 = Effect.fnUntraced(function* (outbox) {
25
+ const lifecycle = yield* LocationLifecycle.Service;
26
+ yield* lifecycle.retain;
27
+ yield* lifecycle.awaitShutdown.pipe(Effect.andThen(Queue.offer(outbox, new Socket.CloseEvent(1012, "location shut down"))), Effect.forkChild);
28
+ });
29
+
30
+ export { runPtySocket2, holdLocation2 };
@@ -0,0 +1,13 @@
1
+ export * as ContentHeaders from "./content-headers";
2
+ export declare const CONTENT_SECURITY_POLICY = "default-src 'none'; img-src 'self'; media-src 'self'; sandbox";
3
+ /** Headers for raw file bytes: always a download, never rendered as a page on the server's origin. */
4
+ export declare function download(input: {
5
+ readonly path?: string;
6
+ readonly mime: string;
7
+ }): {
8
+ "content-type": string;
9
+ "content-disposition": string;
10
+ "content-security-policy": string;
11
+ "x-content-type-options": string;
12
+ };
13
+ export declare function disposition(name: string): string;
@@ -0,0 +1,12 @@
1
+ import {
2
+ CONTENT_SECURITY_POLICY2,
3
+ download2,
4
+ disposition2,
5
+ exports_content_headers
6
+ } from "./chunks/api-t32e1bbt.js";
7
+ export {
8
+ CONTENT_SECURITY_POLICY2 as CONTENT_SECURITY_POLICY,
9
+ exports_content_headers as ContentHeaders,
10
+ disposition2 as disposition,
11
+ download2 as download
12
+ };
package/dist/cors.d.ts ADDED
@@ -0,0 +1,7 @@
1
+ import { Context } from "effect";
2
+ export type CorsOptions = {
3
+ readonly cors?: ReadonlyArray<string>;
4
+ };
5
+ export declare const CorsConfig: Context.Reference<CorsOptions | undefined>;
6
+ export declare function isAllowedCorsOrigin(input: string | undefined, opts?: CorsOptions): boolean;
7
+ export declare function isAllowedRequestOrigin(input: string | undefined, host: string | undefined, opts?: CorsOptions): boolean;