@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.
- package/dist/api.d.ts +9383 -0
- package/dist/api.js +10 -0
- package/dist/auth.d.ts +21 -0
- package/dist/auth.js +20 -0
- package/dist/chunks/api-0q8mvh3b.js +62 -0
- package/dist/chunks/api-11hx8jza.js +39 -0
- package/dist/chunks/api-1jnx79t4.js +31 -0
- package/dist/chunks/api-1mn3274c.js +57 -0
- package/dist/chunks/api-238wcyzf.js +252 -0
- package/dist/chunks/api-280h8k1v.js +198 -0
- package/dist/chunks/api-31hzmefh.js +73 -0
- package/dist/chunks/api-34msk99p.js +208 -0
- package/dist/chunks/api-40z6h0fq.js +20 -0
- package/dist/chunks/api-5fr63cjn.js +27 -0
- package/dist/chunks/api-5ggmn0t6.js +348 -0
- package/dist/chunks/api-61ndsq4a.js +45 -0
- package/dist/chunks/api-7tqjsq7b.js +101 -0
- package/dist/chunks/api-8cw69z4p.js +15 -0
- package/dist/chunks/api-8sb6qqpn.js +28 -0
- package/dist/chunks/api-8tn84h85.js +39 -0
- package/dist/chunks/api-9bxtygz0.js +48 -0
- package/dist/chunks/api-9qr3r2v1.js +66 -0
- package/dist/chunks/api-9rqn6x4v.js +16 -0
- package/dist/chunks/api-azwdvyh3.js +4 -0
- package/dist/chunks/api-b3j0kcev.js +30 -0
- package/dist/chunks/api-bctzdhd7.js +21 -0
- package/dist/chunks/api-bnpt5zxx.js +36 -0
- package/dist/chunks/api-bxwfazps.js +90 -0
- package/dist/chunks/api-d4cyxj7e.js +80 -0
- package/dist/chunks/api-d8rk8yaw.js +20 -0
- package/dist/chunks/api-djs9m6v0.js +42 -0
- package/dist/chunks/api-e2746nhp.js +17 -0
- package/dist/chunks/api-e4v11dgy.js +58 -0
- package/dist/chunks/api-e6e4kz0w.js +23 -0
- package/dist/chunks/api-f6955nmc.js +19 -0
- package/dist/chunks/api-fhp54bwg.js +39 -0
- package/dist/chunks/api-fpzegjvk.js +35 -0
- package/dist/chunks/api-fq7f3wrn.js +13 -0
- package/dist/chunks/api-gg2tbqc5.js +270 -0
- package/dist/chunks/api-gghkbyq2.js +189 -0
- package/dist/chunks/api-ghyd9ren.js +32 -0
- package/dist/chunks/api-h8v4dbra.js +49 -0
- package/dist/chunks/api-hpgyxnbj.js +92 -0
- package/dist/chunks/api-jb6q2eqf.js +70 -0
- package/dist/chunks/api-k0fc7y6c.js +219 -0
- package/dist/chunks/api-kb0k6qg1.js +35 -0
- package/dist/chunks/api-kb431qm0.js +31 -0
- package/dist/chunks/api-kvefct3s.js +215 -0
- package/dist/chunks/api-mzafcgd5.js +23 -0
- package/dist/chunks/api-n0gqhwq7.js +109 -0
- package/dist/chunks/api-njzqh2v3.js +22 -0
- package/dist/chunks/api-nqw28mmv.js +62 -0
- package/dist/chunks/api-ns3kfwpq.js +48 -0
- package/dist/chunks/api-ph6j0w88.js +29 -0
- package/dist/chunks/api-q8azxbmk.js +38 -0
- package/dist/chunks/api-qft4mah5.js +33 -0
- package/dist/chunks/api-qz4nw4cc.js +130 -0
- package/dist/chunks/api-rrsy7az3.js +69 -0
- package/dist/chunks/api-t2s5ghf4.js +91 -0
- package/dist/chunks/api-t32e1bbt.js +32 -0
- package/dist/chunks/api-t7f8xf56.js +22 -0
- package/dist/chunks/api-trzj52xd.js +13 -0
- package/dist/chunks/api-v2h85c6p.js +143 -0
- package/dist/chunks/api-vtj5wyks.js +13 -0
- package/dist/chunks/api-wrj46kzw.js +41 -0
- package/dist/chunks/api-wrma0ern.js +36 -0
- package/dist/chunks/api-x180v472.js +22 -0
- package/dist/chunks/api-xcn5yyhy.js +134 -0
- package/dist/chunks/api-xthc02cw.js +6 -0
- package/dist/chunks/api-ygxfyj7m.js +111 -0
- package/dist/chunks/api-z3ybfekq.js +20 -0
- package/dist/chunks/api-zvb9sh2w.js +30 -0
- package/dist/content-headers.d.ts +13 -0
- package/dist/content-headers.js +12 -0
- package/dist/cors.d.ts +7 -0
- package/dist/cors.js +10 -0
- package/dist/event-feed.d.ts +44 -0
- package/dist/event-feed.js +20 -0
- package/dist/fetch.d.ts +164 -0
- package/dist/fetch.js +80 -0
- package/dist/handlers/agent.d.ts +1 -0
- package/dist/handlers/agent.js +11 -0
- package/dist/handlers/artifact.d.ts +62 -0
- package/dist/handlers/artifact.js +8 -0
- package/dist/handlers/automation.d.ts +23 -0
- package/dist/handlers/automation.js +7 -0
- package/dist/handlers/blob.d.ts +168 -0
- package/dist/handlers/blob.js +9 -0
- package/dist/handlers/command.d.ts +1 -0
- package/dist/handlers/command.js +11 -0
- package/dist/handlers/config.d.ts +1 -0
- package/dist/handlers/config.js +11 -0
- package/dist/handlers/credential.d.ts +4 -0
- package/dist/handlers/credential.js +12 -0
- package/dist/handlers/debug.d.ts +2 -0
- package/dist/handlers/debug.js +11 -0
- package/dist/handlers/event.d.ts +2 -0
- package/dist/handlers/event.js +12 -0
- package/dist/handlers/experimental/browser-tunnel.d.ts +11 -0
- package/dist/handlers/experimental/browser-tunnel.js +9 -0
- package/dist/handlers/flag.d.ts +1 -0
- package/dist/handlers/flag.js +11 -0
- package/dist/handlers/form.d.ts +1 -0
- package/dist/handlers/form.js +11 -0
- package/dist/handlers/fs.d.ts +2 -0
- package/dist/handlers/fs.js +13 -0
- package/dist/handlers/generate.d.ts +4 -0
- package/dist/handlers/generate.js +11 -0
- package/dist/handlers/integration.d.ts +7 -0
- package/dist/handlers/integration.js +13 -0
- package/dist/handlers/job.d.ts +73 -0
- package/dist/handlers/job.js +7 -0
- package/dist/handlers/location.d.ts +2 -0
- package/dist/handlers/location.js +11 -0
- package/dist/handlers/machine.d.ts +164 -0
- package/dist/handlers/machine.js +28 -0
- package/dist/handlers/mcp.d.ts +3 -0
- package/dist/handlers/mcp.js +13 -0
- package/dist/handlers/media.d.ts +6 -0
- package/dist/handlers/media.js +7 -0
- package/dist/handlers/message.d.ts +2 -0
- package/dist/handlers/message.js +12 -0
- package/dist/handlers/migration.d.ts +1 -0
- package/dist/handlers/migration.js +11 -0
- package/dist/handlers/model.d.ts +1 -0
- package/dist/handlers/model.js +11 -0
- package/dist/handlers/permission.d.ts +4 -0
- package/dist/handlers/permission.js +11 -0
- package/dist/handlers/persistent-pty.d.ts +3 -0
- package/dist/handlers/persistent-pty.js +25 -0
- package/dist/handlers/plugin.d.ts +2 -0
- package/dist/handlers/plugin.js +11 -0
- package/dist/handlers/project.d.ts +2 -0
- package/dist/handlers/project.js +11 -0
- package/dist/handlers/provider.d.ts +1 -0
- package/dist/handlers/provider.js +11 -0
- package/dist/handlers/pty-socket.d.ts +12 -0
- package/dist/handlers/pty-socket.js +8 -0
- package/dist/handlers/pty.d.ts +3 -0
- package/dist/handlers/pty.js +13 -0
- package/dist/handlers/push.d.ts +28 -0
- package/dist/handlers/push.js +6 -0
- package/dist/handlers/reference.d.ts +1 -0
- package/dist/handlers/reference.js +11 -0
- package/dist/handlers/rpc.d.ts +1 -0
- package/dist/handlers/rpc.js +11 -0
- package/dist/handlers/server.d.ts +4 -0
- package/dist/handlers/server.js +14 -0
- package/dist/handlers/session-error.d.ts +11 -0
- package/dist/handlers/session-error.js +14 -0
- package/dist/handlers/session.d.ts +5 -0
- package/dist/handlers/session.js +12 -0
- package/dist/handlers/shell.d.ts +1 -0
- package/dist/handlers/shell.js +11 -0
- package/dist/handlers/skill.d.ts +1 -0
- package/dist/handlers/skill.js +11 -0
- package/dist/handlers/space.d.ts +54 -0
- package/dist/handlers/space.js +7 -0
- package/dist/handlers/usage.d.ts +1 -0
- package/dist/handlers/usage.js +11 -0
- package/dist/handlers/vcs.d.ts +4 -0
- package/dist/handlers/vcs.js +11 -0
- package/dist/handlers/voice.d.ts +3 -0
- package/dist/handlers/voice.js +11 -0
- package/dist/handlers/websearch.d.ts +1 -0
- package/dist/handlers/websearch.js +11 -0
- package/dist/handlers/worktree.d.ts +2 -0
- package/dist/handlers/worktree.js +11 -0
- package/dist/handlers.d.ts +3 -0
- package/dist/handlers.js +63 -0
- package/dist/location.d.ts +28 -0
- package/dist/location.js +17 -0
- package/dist/media-uri.d.ts +6 -0
- package/dist/media-uri.js +6 -0
- package/dist/middleware/authorization.d.ts +8 -0
- package/dist/middleware/authorization.js +13 -0
- package/dist/middleware/defect-response.d.ts +2 -0
- package/dist/middleware/defect-response.js +6 -0
- package/dist/middleware/form-location.d.ts +18 -0
- package/dist/middleware/form-location.js +10 -0
- package/dist/middleware/schema-error.d.ts +3 -0
- package/dist/middleware/schema-error.js +8 -0
- package/dist/middleware/session-location.d.ts +17 -0
- package/dist/middleware/session-location.js +10 -0
- package/dist/options.d.ts +130 -0
- package/dist/options.js +55 -0
- package/dist/pairing.d.ts +13 -0
- package/dist/pairing.js +10 -0
- package/dist/process.d.ts +70 -0
- package/dist/process.js +241 -0
- package/dist/range.d.ts +6 -0
- package/dist/range.js +8 -0
- package/dist/request-site.d.ts +11 -0
- package/dist/request-site.js +11 -0
- package/dist/request-tracing.d.ts +1 -0
- package/dist/request-tracing.js +6 -0
- package/dist/routes.d.ts +54 -0
- package/dist/routes.js +69 -0
- package/dist/server-info.d.ts +14 -0
- package/dist/server-info.js +12 -0
- package/dist/service-status.d.ts +25 -0
- package/dist/service-status.js +8 -0
- package/dist/space-store.d.ts +62 -0
- package/dist/space-store.js +16 -0
- package/dist/workerd-machine-link.d.ts +107 -0
- package/dist/workerd-machine-link.js +19 -0
- package/dist/workerd.d.ts +113 -0
- package/dist/workerd.js +168 -0
- package/package.json +50 -4
- package/README.md +0 -3
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import {
|
|
2
|
+
__export
|
|
3
|
+
} from "./api-9rqn6x4v.js";
|
|
4
|
+
|
|
5
|
+
// src/auth.ts
|
|
6
|
+
var exports_auth = {};
|
|
7
|
+
__export(exports_auth, {
|
|
8
|
+
Config: () => Config2,
|
|
9
|
+
SESSION_TTL_SECONDS: () => SESSION_TTL_SECONDS2,
|
|
10
|
+
ServerAuth: () => exports_auth,
|
|
11
|
+
authorized: () => authorized2,
|
|
12
|
+
issueSession: () => issueSession2,
|
|
13
|
+
required: () => required2,
|
|
14
|
+
sessionCookieName: () => sessionCookieName2,
|
|
15
|
+
verifySession: () => verifySession2
|
|
16
|
+
});
|
|
17
|
+
import { Context, Layer, Option, Redacted } from "effect";
|
|
18
|
+
import { createHmac, timingSafeEqual } from "node:crypto";
|
|
19
|
+
var SESSION_TTL_SECONDS2 = 30 * 24 * 60 * 60;
|
|
20
|
+
|
|
21
|
+
class Config2 extends Context.Service()("@radheim/ServerAuthConfig") {
|
|
22
|
+
static configLayer(input) {
|
|
23
|
+
return Layer.succeed(this, this.of({ ...input, username: "opencode" }));
|
|
24
|
+
}
|
|
25
|
+
static get layer() {
|
|
26
|
+
return this.configLayer({ password: Option.none() });
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
function required2(config) {
|
|
30
|
+
return Option.isSome(config.password) && config.password.value !== "";
|
|
31
|
+
}
|
|
32
|
+
function authorized2(credentials, config) {
|
|
33
|
+
if (Option.isNone(config.password) || credentials.username !== config.username)
|
|
34
|
+
return false;
|
|
35
|
+
const password = Redacted.value(credentials.password);
|
|
36
|
+
return password === config.password.value || verifySession2(password, config);
|
|
37
|
+
}
|
|
38
|
+
function issueSession2(config, now = Date.now()) {
|
|
39
|
+
if (Option.isNone(config.password))
|
|
40
|
+
return;
|
|
41
|
+
const expires = String(Math.floor(now / 1000) + SESSION_TTL_SECONDS2);
|
|
42
|
+
return `${expires}.${sign(config.password.value, expires)}`;
|
|
43
|
+
}
|
|
44
|
+
function verifySession2(token, config, now = Date.now()) {
|
|
45
|
+
if (Option.isNone(config.password))
|
|
46
|
+
return false;
|
|
47
|
+
const parts = token.split(".");
|
|
48
|
+
if (parts.length !== 2)
|
|
49
|
+
return false;
|
|
50
|
+
const expires = Number(parts[0]);
|
|
51
|
+
if (!Number.isSafeInteger(expires) || expires * 1000 <= now)
|
|
52
|
+
return false;
|
|
53
|
+
const expected = Buffer.from(sign(config.password.value, parts[0]));
|
|
54
|
+
const actual = Buffer.from(parts[1]);
|
|
55
|
+
return actual.length === expected.length && timingSafeEqual(actual, expected);
|
|
56
|
+
}
|
|
57
|
+
function sessionCookieName2(host) {
|
|
58
|
+
const port = URL.parse(`http://${host ?? ""}`)?.port;
|
|
59
|
+
return port ? `opencode_session_${port}` : "opencode_session";
|
|
60
|
+
}
|
|
61
|
+
function sign(password, payload) {
|
|
62
|
+
const key = createHmac("sha256", password).update("opencode-session-v1").digest();
|
|
63
|
+
return createHmac("sha256", key).update(payload).digest("base64url");
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export { SESSION_TTL_SECONDS2, Config2, required2, authorized2, issueSession2, verifySession2, sessionCookieName2, exports_auth };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __returnValue = (v) => v;
|
|
3
|
+
function __exportSetter(name, newValue) {
|
|
4
|
+
this[name] = __returnValue.bind(null, newValue);
|
|
5
|
+
}
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, {
|
|
9
|
+
get: all[name],
|
|
10
|
+
enumerable: true,
|
|
11
|
+
configurable: true,
|
|
12
|
+
set: __exportSetter.bind(all, name)
|
|
13
|
+
});
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export { __export };
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import {
|
|
2
|
+
response2
|
|
3
|
+
} from "./api-0q8mvh3b.js";
|
|
4
|
+
import {
|
|
5
|
+
Api2
|
|
6
|
+
} from "./api-f6955nmc.js";
|
|
7
|
+
|
|
8
|
+
// src/handlers/skill.ts
|
|
9
|
+
import { Skill } from "@radheim/core/skill";
|
|
10
|
+
import { FileNotFoundError, SkillLoadError, SkillNotFoundError } from "@radheim/protocol/errors";
|
|
11
|
+
import { Effect } from "effect";
|
|
12
|
+
import { HttpApiBuilder } from "effect/http-api";
|
|
13
|
+
var SkillHandler2 = HttpApiBuilder.group(Api2, "server.skill", (handlers) => handlers.handle("skill.list", () => response2(Skill.Service.use((skill) => skill.list()))).handle("skill.file", (ctx) => Effect.gen(function* () {
|
|
14
|
+
const skills = yield* Skill.Service;
|
|
15
|
+
const raw = new URL(ctx.request.url, "http://localhost").pathname.split("/").slice(6).join("/");
|
|
16
|
+
const notFound = new FileNotFoundError({ path: raw, message: `File not found: ${raw}` });
|
|
17
|
+
const file = yield* Effect.try({
|
|
18
|
+
try: () => Skill.parseFilePath(decodeURIComponent(raw)),
|
|
19
|
+
catch: () => notFound
|
|
20
|
+
});
|
|
21
|
+
if (!file)
|
|
22
|
+
return yield* notFound;
|
|
23
|
+
return yield* skills.read(ctx.params.skillID, file).pipe(Effect.catchTags({
|
|
24
|
+
"Skill.NotFoundError": (error) => Effect.fail(new SkillNotFoundError({ skill: ctx.params.skillID, message: `Skill not found: ${error.skill}` })),
|
|
25
|
+
"Skill.FileNotFoundError": (error) => Effect.fail(new FileNotFoundError({ path: error.file, message: `File not found: ${error.file}` })),
|
|
26
|
+
"Skill.LoadError": (error) => Effect.fail(new SkillLoadError({ skill: ctx.params.skillID, message: error.message }))
|
|
27
|
+
}));
|
|
28
|
+
})));
|
|
29
|
+
|
|
30
|
+
export { SkillHandler2 };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
// src/middleware/defect-response.ts
|
|
2
|
+
import { StorageFailure } from "@radheim/core/database/storage-failure";
|
|
3
|
+
import { UnknownError } from "@radheim/protocol/errors";
|
|
4
|
+
import { Cause, Effect } from "effect";
|
|
5
|
+
import { HttpRouter, HttpServerError, HttpServerRequest, HttpServerResponse } from "effect/http";
|
|
6
|
+
var respond = HttpServerResponse.schemaJson(UnknownError);
|
|
7
|
+
var defectResponseLayer2 = HttpRouter.middleware((effect) => effect.pipe(Effect.catchCause((cause) => Effect.gen(function* () {
|
|
8
|
+
const [response] = yield* HttpServerError.causeResponse(cause);
|
|
9
|
+
if (response.status !== 500 || response.body._tag !== "Empty")
|
|
10
|
+
return yield* Effect.failCause(cause);
|
|
11
|
+
const request = yield* HttpServerRequest.HttpServerRequest;
|
|
12
|
+
const ref = `err_${crypto.randomUUID().slice(0, 8)}`;
|
|
13
|
+
yield* Effect.logError("request failed", cause).pipe(Effect.annotateLogs({ ref, route: `${request.method} ${request.url}` }));
|
|
14
|
+
const body = yield* respond(new UnknownError({
|
|
15
|
+
message: StorageFailure.message(cause) ?? "Server failed to handle the request. Check server logs for details.",
|
|
16
|
+
ref
|
|
17
|
+
}), { status: 500 }).pipe(Effect.orDie);
|
|
18
|
+
return yield* Effect.failCause(Cause.combine(cause, Cause.die(body)));
|
|
19
|
+
}))), { global: true });
|
|
20
|
+
|
|
21
|
+
export { defectResponseLayer2 };
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import {
|
|
2
|
+
locationErrors2,
|
|
3
|
+
sessionInfo2,
|
|
4
|
+
requestRef2
|
|
5
|
+
} from "./api-0q8mvh3b.js";
|
|
6
|
+
|
|
7
|
+
// src/middleware/form-location.ts
|
|
8
|
+
import { Instance } from "@radheim/core/instance/service";
|
|
9
|
+
import { LocationServiceMap } from "@radheim/core/location-services";
|
|
10
|
+
import { Session } from "@radheim/core/session";
|
|
11
|
+
import { LocationNotFoundError, InvalidRequestError, SessionNotFoundError } from "@radheim/protocol/errors";
|
|
12
|
+
import { Effect, Layer } from "effect";
|
|
13
|
+
import { HttpRouter, HttpServerRequest, HttpServerResponse } from "effect/http";
|
|
14
|
+
import { HttpApiMiddleware } from "effect/http-api";
|
|
15
|
+
class FormLocationMiddleware2 extends HttpApiMiddleware.Service()("@radheim/HttpApiFormLocation", {
|
|
16
|
+
error: [InvalidRequestError, SessionNotFoundError, LocationNotFoundError]
|
|
17
|
+
}) {
|
|
18
|
+
}
|
|
19
|
+
var formLocationLayer2 = Layer.effect(FormLocationMiddleware2, Effect.gen(function* () {
|
|
20
|
+
const sessions = yield* Session.Service;
|
|
21
|
+
const instances = yield* Instance.Service;
|
|
22
|
+
const locations = yield* LocationServiceMap.Service;
|
|
23
|
+
return FormLocationMiddleware2.of((effect, options) => Effect.gen(function* () {
|
|
24
|
+
const route = yield* HttpRouter.RouteContext;
|
|
25
|
+
if (route.params.sessionID === "global") {
|
|
26
|
+
const request = yield* HttpServerRequest.HttpServerRequest;
|
|
27
|
+
return yield* effect.pipe(Effect.provide(locations.get(requestRef2(request))), locationErrors2);
|
|
28
|
+
}
|
|
29
|
+
const session = yield* sessionInfo2(sessions, route.params.sessionID);
|
|
30
|
+
if (options.endpoint.identifier === "session.form.list" && instances.live && !(yield* instances.live(session)))
|
|
31
|
+
return HttpServerResponse.jsonUnsafe({ data: [] });
|
|
32
|
+
return yield* effect.pipe(instances.provide(session), locationErrors2);
|
|
33
|
+
}));
|
|
34
|
+
}));
|
|
35
|
+
|
|
36
|
+
export { FormLocationMiddleware2, formLocationLayer2 };
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Config2,
|
|
3
|
+
required2,
|
|
4
|
+
authorized2,
|
|
5
|
+
verifySession2,
|
|
6
|
+
sessionCookieName2
|
|
7
|
+
} from "./api-9qr3r2v1.js";
|
|
8
|
+
|
|
9
|
+
// src/middleware/authorization.ts
|
|
10
|
+
import { UnauthorizedError } from "@radheim/protocol/errors";
|
|
11
|
+
import { Authorization } from "@radheim/protocol/middleware/authorization";
|
|
12
|
+
import { Authorization as Authorization2 } from "@radheim/protocol/middleware/authorization";
|
|
13
|
+
import { PTY_CONNECT_PATH, PTY_CONNECT_TICKET_QUERY } from "@radheim/protocol/groups/pty";
|
|
14
|
+
import { PERSISTENT_PTY_CONNECT_PATH } from "@radheim/protocol/groups/persistent-pty";
|
|
15
|
+
import { MCP_CLIENT_PATH } from "@radheim/protocol/groups/mcp";
|
|
16
|
+
import { BROWSER_TUNNEL_PATH, hasBrowserTunnelUpgrade } from "@radheim/protocol/groups/experimental/browser-tunnel";
|
|
17
|
+
import { isWebSocketUpgrade, MACHINE_LINK_PATH } from "@radheim/protocol/groups/machine";
|
|
18
|
+
import { PAIRING_CONNECT_PATH } from "@radheim/protocol/groups/server";
|
|
19
|
+
import { Effect, Layer, Redacted } from "effect";
|
|
20
|
+
import { Base64 } from "effect/encoding";
|
|
21
|
+
import { HttpEffect, HttpRouter, HttpServerRequest, HttpServerResponse } from "effect/http";
|
|
22
|
+
var AUTH_TOKEN_QUERY = "auth_token";
|
|
23
|
+
var WWW_AUTHENTICATE = 'Basic realm="Secure Area"';
|
|
24
|
+
function emptyCredential() {
|
|
25
|
+
return { username: "", password: Redacted.make("") };
|
|
26
|
+
}
|
|
27
|
+
function decodeCredential(input) {
|
|
28
|
+
return Effect.fromResult(Base64.decodeString(input)).pipe(Effect.match({
|
|
29
|
+
onFailure: emptyCredential,
|
|
30
|
+
onSuccess: (header) => {
|
|
31
|
+
const separator = header.indexOf(":");
|
|
32
|
+
if (separator === -1)
|
|
33
|
+
return emptyCredential();
|
|
34
|
+
return { username: header.slice(0, separator), password: Redacted.make(header.slice(separator + 1)) };
|
|
35
|
+
}
|
|
36
|
+
}));
|
|
37
|
+
}
|
|
38
|
+
function credentialFromRequest(request) {
|
|
39
|
+
const url = new URL(request.url, "http://localhost");
|
|
40
|
+
const token = url.searchParams.get(AUTH_TOKEN_QUERY);
|
|
41
|
+
if (token)
|
|
42
|
+
return decodeCredential(token);
|
|
43
|
+
const match = /^Basic\s+(.+)$/i.exec(request.headers.authorization ?? "");
|
|
44
|
+
if (match)
|
|
45
|
+
return decodeCredential(match[1]);
|
|
46
|
+
return Effect.succeed(emptyCredential());
|
|
47
|
+
}
|
|
48
|
+
var UNAUTHORIZED_MESSAGE = "Authentication required";
|
|
49
|
+
function challengeRequest(request) {
|
|
50
|
+
const mode = request.headers["sec-fetch-mode"];
|
|
51
|
+
return mode === undefined || mode === "navigate";
|
|
52
|
+
}
|
|
53
|
+
function unauthorizedResponse2(request) {
|
|
54
|
+
return HttpServerResponse.jsonUnsafe({ _tag: "UnauthorizedError", message: UNAUTHORIZED_MESSAGE }, { status: 401, headers: challengeRequest(request) ? { "www-authenticate": WWW_AUTHENTICATE } : undefined });
|
|
55
|
+
}
|
|
56
|
+
function authorizedRequest2(request, config) {
|
|
57
|
+
return credentialFromRequest(request).pipe(Effect.map((credential) => authorized2(credential, config) || authorizedSessionCookie(request, config)));
|
|
58
|
+
}
|
|
59
|
+
function authorizedSessionCookie(request, config) {
|
|
60
|
+
const token = request.cookies[sessionCookieName2(request.headers.host)];
|
|
61
|
+
if (!token)
|
|
62
|
+
return false;
|
|
63
|
+
const origin = request.headers.origin;
|
|
64
|
+
if (origin !== undefined && URL.parse(origin)?.host !== request.headers.host)
|
|
65
|
+
return false;
|
|
66
|
+
return verifySession2(token, config);
|
|
67
|
+
}
|
|
68
|
+
var authorizationLayer2 = Layer.effect(Authorization, Effect.gen(function* () {
|
|
69
|
+
const config = yield* Config2;
|
|
70
|
+
if (!required2(config))
|
|
71
|
+
return Authorization.of((effect) => effect);
|
|
72
|
+
return Authorization.of((effect) => Effect.gen(function* () {
|
|
73
|
+
const request = yield* HttpServerRequest.HttpServerRequest;
|
|
74
|
+
const route = yield* HttpRouter.RouteContext;
|
|
75
|
+
const url = new URL(request.url, "http://localhost");
|
|
76
|
+
if ((route.route.path === PTY_CONNECT_PATH || route.route.path === PERSISTENT_PTY_CONNECT_PATH || route.route.path === MCP_CLIENT_PATH) && !!url.searchParams.get(PTY_CONNECT_TICKET_QUERY) || route.route.path === PAIRING_CONNECT_PATH)
|
|
77
|
+
return yield* effect;
|
|
78
|
+
if (route.route.path === MACHINE_LINK_PATH && isWebSocketUpgrade(request))
|
|
79
|
+
return yield* effect;
|
|
80
|
+
if (route.route.path === BROWSER_TUNNEL_PATH && hasBrowserTunnelUpgrade(request))
|
|
81
|
+
return yield* effect;
|
|
82
|
+
if (yield* authorizedRequest2(request, config))
|
|
83
|
+
return yield* effect;
|
|
84
|
+
if (challengeRequest(request))
|
|
85
|
+
yield* HttpEffect.appendPreResponseHandler((_request, response) => Effect.succeed(HttpServerResponse.setHeader(response, "www-authenticate", WWW_AUTHENTICATE)));
|
|
86
|
+
return yield* new UnauthorizedError({ message: UNAUTHORIZED_MESSAGE });
|
|
87
|
+
}));
|
|
88
|
+
}));
|
|
89
|
+
|
|
90
|
+
export { unauthorizedResponse2, authorizedRequest2, authorizationLayer2, Authorization2 };
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import {
|
|
2
|
+
download2
|
|
3
|
+
} from "./api-t32e1bbt.js";
|
|
4
|
+
import {
|
|
5
|
+
parse2
|
|
6
|
+
} from "./api-8sb6qqpn.js";
|
|
7
|
+
import {
|
|
8
|
+
missingSession2
|
|
9
|
+
} from "./api-ghyd9ren.js";
|
|
10
|
+
|
|
11
|
+
// src/handlers/blob.ts
|
|
12
|
+
import { BlobStore } from "@radheim/core/blob-store";
|
|
13
|
+
import { Session } from "@radheim/core/session";
|
|
14
|
+
import {
|
|
15
|
+
BlobNotFoundError,
|
|
16
|
+
InvalidCursorError,
|
|
17
|
+
InvalidRequestError,
|
|
18
|
+
ServiceUnavailableError
|
|
19
|
+
} from "@radheim/protocol/errors";
|
|
20
|
+
import { Effect } from "effect";
|
|
21
|
+
import { HttpServerResponse } from "effect/http";
|
|
22
|
+
var makeBlob2 = Effect.gen(function* () {
|
|
23
|
+
const blobs = yield* BlobStore.Service;
|
|
24
|
+
const sessions = yield* Session.Service;
|
|
25
|
+
const missing = (error) => new BlobNotFoundError({ blobID: error.id, message: error.message });
|
|
26
|
+
return {
|
|
27
|
+
list: Effect.fn("BlobHandler.list")(function* (query) {
|
|
28
|
+
return yield* blobs.list(query).pipe(Effect.mapError((error) => new InvalidCursorError({ message: error.message })));
|
|
29
|
+
}),
|
|
30
|
+
create: Effect.fn("BlobHandler.create")(function* (query, request) {
|
|
31
|
+
if (query.sessionID !== undefined)
|
|
32
|
+
yield* sessions.get(query.sessionID).pipe(Effect.catchTag("Session.NotFoundError", missingSession2));
|
|
33
|
+
const info = yield* blobs.write(request.stream, { ...query, mime: request.headers["content-type"] }).pipe(Effect.mapError((error) => error instanceof BlobStore.UnavailableError ? new ServiceUnavailableError({ message: error.message, service: "blob" }) : new InvalidRequestError({ message: "The upload ended before its body was complete" })));
|
|
34
|
+
return HttpServerResponse.jsonUnsafe({ data: info });
|
|
35
|
+
}),
|
|
36
|
+
get: Effect.fn("BlobHandler.get")(function* (id) {
|
|
37
|
+
return { data: yield* blobs.get(id).pipe(Effect.mapError(missing)) };
|
|
38
|
+
}),
|
|
39
|
+
content: Effect.fn("BlobHandler.content")(function* (id, request) {
|
|
40
|
+
const blob = yield* blobs.get(id).pipe(Effect.mapError(missing));
|
|
41
|
+
const etag = `"${id}"`;
|
|
42
|
+
const headers = {
|
|
43
|
+
...download2({ mime: blob.mime }),
|
|
44
|
+
"cache-control": "private, max-age=31536000, immutable",
|
|
45
|
+
etag,
|
|
46
|
+
"accept-ranges": "bytes"
|
|
47
|
+
};
|
|
48
|
+
if (request.headers["if-none-match"]?.split(",").some((tag) => tag.trim() === "*" || tag.trim().replace(/^w\//i, "") === etag))
|
|
49
|
+
return HttpServerResponse.empty({ status: 304, headers });
|
|
50
|
+
const ifRange = request.headers["if-range"];
|
|
51
|
+
const range = ifRange === undefined || ifRange.trim() === etag ? parse2(request.headers["range"], blob.bytes) : undefined;
|
|
52
|
+
if (range === "unsatisfiable")
|
|
53
|
+
return HttpServerResponse.empty({
|
|
54
|
+
status: 416,
|
|
55
|
+
headers: { ...headers, "content-range": `bytes */${blob.bytes}` }
|
|
56
|
+
});
|
|
57
|
+
const offset = range?.start ?? 0;
|
|
58
|
+
const length = range === undefined ? blob.bytes : range.end - range.start + 1;
|
|
59
|
+
return HttpServerResponse.stream(yield* blobs.content(id, { offset, length }).pipe(Effect.mapError(missing)), {
|
|
60
|
+
status: range === undefined ? 200 : 206,
|
|
61
|
+
contentType: headers["content-type"],
|
|
62
|
+
contentLength: length,
|
|
63
|
+
headers: range === undefined ? headers : { ...headers, "content-range": `bytes ${range.start}-${range.end}/${blob.bytes}` }
|
|
64
|
+
});
|
|
65
|
+
}),
|
|
66
|
+
update: Effect.fn("BlobHandler.update")(function* (id, payload) {
|
|
67
|
+
if (payload.metadata !== undefined && new TextEncoder().encode(JSON.stringify(payload.metadata)).length > BlobStore.METADATA_LIMIT)
|
|
68
|
+
return yield* new InvalidRequestError({
|
|
69
|
+
message: `metadata must be at most ${BlobStore.METADATA_LIMIT} bytes as JSON`,
|
|
70
|
+
field: "metadata"
|
|
71
|
+
});
|
|
72
|
+
return { data: yield* blobs.update(id, payload).pipe(Effect.mapError(missing)) };
|
|
73
|
+
}),
|
|
74
|
+
remove: Effect.fn("BlobHandler.remove")(function* (id) {
|
|
75
|
+
yield* blobs.remove(id).pipe(Effect.mapError(missing));
|
|
76
|
+
})
|
|
77
|
+
};
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
export { makeBlob2 };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Api2
|
|
3
|
+
} from "./api-f6955nmc.js";
|
|
4
|
+
|
|
5
|
+
// src/handlers/rpc.ts
|
|
6
|
+
import { Rpc } from "@radheim/core/rpc";
|
|
7
|
+
import { RpcError, RpcInternalError } from "@radheim/protocol/errors";
|
|
8
|
+
import { Effect } from "effect";
|
|
9
|
+
import { HttpApiBuilder } from "effect/http-api";
|
|
10
|
+
var RpcHandler2 = HttpApiBuilder.group(Api2, "server.rpc", (handlers) => handlers.handle("rpc.call", ({ params, payload }) => Effect.gen(function* () {
|
|
11
|
+
const rpc = yield* Rpc.Service;
|
|
12
|
+
const output = yield* rpc.call(params.rpcID, params.method, payload.input);
|
|
13
|
+
return output === undefined ? {} : { output };
|
|
14
|
+
}).pipe(Effect.mapError((error) => error.type === "rpc.invalid_output" || error.type === "rpc.internal" ? new RpcInternalError({ type: error.type, message: error.message }) : new RpcError({
|
|
15
|
+
type: error.type,
|
|
16
|
+
message: error.message,
|
|
17
|
+
...error.data === undefined ? {} : { data: error.data }
|
|
18
|
+
})), Effect.catchDefect((defect) => Effect.logError("rpc call failed", { rpc: params.rpcID, method: params.method, defect }).pipe(Effect.andThen(Effect.fail(new RpcInternalError({ type: "rpc.internal", message: "RPC call failed" }))))))));
|
|
19
|
+
|
|
20
|
+
export { RpcHandler2 };
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Api2
|
|
3
|
+
} from "./api-f6955nmc.js";
|
|
4
|
+
|
|
5
|
+
// src/handlers/worktree.ts
|
|
6
|
+
import { Git } from "@radheim/core/git";
|
|
7
|
+
import { Worktree } from "@radheim/core/worktree";
|
|
8
|
+
import { ProjectNotFoundError } from "@radheim/protocol/errors";
|
|
9
|
+
import { WorktreeError } from "@radheim/protocol/groups/worktree";
|
|
10
|
+
import { Effect } from "effect";
|
|
11
|
+
import { HttpApiBuilder, HttpApiSchema } from "effect/http-api";
|
|
12
|
+
var WorktreeHandler2 = HttpApiBuilder.group(Api2, "server.worktree", (handlers) => Effect.gen(function* () {
|
|
13
|
+
const worktrees = yield* Worktree.Service;
|
|
14
|
+
return handlers.handle("worktree.list", (ctx) => worktrees.list(ctx.query).pipe(Effect.catchTag("Project.NotFoundError", missingProject))).handle("worktree.create", (ctx) => worktrees.create(ctx.payload).pipe(badRequest)).handle("worktree.remove", (ctx) => worktrees.remove(ctx.payload).pipe(badRequest, Effect.as(HttpApiSchema.NoContent.make()))).handle("worktree.refresh", (ctx) => worktrees.refresh(ctx.payload).pipe(badRequest, Effect.as(HttpApiSchema.NoContent.make())));
|
|
15
|
+
}));
|
|
16
|
+
function badRequest(effect) {
|
|
17
|
+
return effect.pipe(Effect.mapError((error) => error._tag === "Project.NotFoundError" ? missingProject(error) : new WorktreeError({
|
|
18
|
+
name: "WorktreeError",
|
|
19
|
+
data: {
|
|
20
|
+
message: message(error),
|
|
21
|
+
forceRequired: error instanceof Git.WorktreeError || error instanceof Worktree.OperationError ? error.forceRequired : undefined
|
|
22
|
+
}
|
|
23
|
+
})));
|
|
24
|
+
}
|
|
25
|
+
function missingProject(error) {
|
|
26
|
+
return new ProjectNotFoundError({ projectID: error.projectID, message: `Project not found: ${error.projectID}` });
|
|
27
|
+
}
|
|
28
|
+
function message(error) {
|
|
29
|
+
if (error instanceof Worktree.SourceDirectoryNotFoundError)
|
|
30
|
+
return error.directory ? `Cannot create a worktree from ${error.directory}: it is not a checkout of this project that supports worktrees, such as a git repository` : `Worktree source not found for project: ${error.projectID}`;
|
|
31
|
+
if (error instanceof Worktree.DestinationExistsError)
|
|
32
|
+
return `Worktree destination already exists: ${error.directory}`;
|
|
33
|
+
if (error instanceof Worktree.DirectoryUnavailableError)
|
|
34
|
+
return `Worktree directory unavailable: ${error.directory}`;
|
|
35
|
+
if (error instanceof Worktree.InvalidDirectoryError)
|
|
36
|
+
return `Invalid worktree directory: ${error.directory}`;
|
|
37
|
+
if (error instanceof Worktree.StrategyUnavailableError)
|
|
38
|
+
return `Worktree strategy unavailable: ${error.strategy}`;
|
|
39
|
+
return error.message;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export { WorktreeHandler2 };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import {
|
|
2
|
+
response2
|
|
3
|
+
} from "./api-0q8mvh3b.js";
|
|
4
|
+
import {
|
|
5
|
+
Api2
|
|
6
|
+
} from "./api-f6955nmc.js";
|
|
7
|
+
|
|
8
|
+
// src/handlers/form.ts
|
|
9
|
+
import { Form } from "@radheim/core/form";
|
|
10
|
+
import { Effect } from "effect";
|
|
11
|
+
import { HttpApiBuilder } from "effect/http-api";
|
|
12
|
+
var FormHandler2 = HttpApiBuilder.group(Api2, "server.form", (handlers) => handlers.handle("form.list", Effect.fnUntraced(function* () {
|
|
13
|
+
const form = yield* Form.Service;
|
|
14
|
+
return yield* response2(form.list());
|
|
15
|
+
})));
|
|
16
|
+
|
|
17
|
+
export { FormHandler2 };
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
// src/handlers/push.ts
|
|
2
|
+
import { Effect, Option } from "effect";
|
|
3
|
+
import { HttpApiSchema } from "effect/http-api";
|
|
4
|
+
import { PushList } from "@radheim/core/push/list";
|
|
5
|
+
import { InvalidRequestError, PushDeviceNotFoundError } from "@radheim/protocol/errors";
|
|
6
|
+
import { Session } from "@radheim/core/session";
|
|
7
|
+
var makePush2 = Effect.gen(function* () {
|
|
8
|
+
const list = yield* PushList.Service;
|
|
9
|
+
const sessions = yield* Session.Service;
|
|
10
|
+
const invalid = (error) => new InvalidRequestError({ message: error.reason });
|
|
11
|
+
const notFound = (error) => new PushDeviceNotFoundError({ deviceID: error.id, message: error.message });
|
|
12
|
+
const rejectSubagent = Effect.fnUntraced(function* (sessionID) {
|
|
13
|
+
const session = Option.getOrUndefined(yield* sessions.get(sessionID).pipe(Effect.option));
|
|
14
|
+
if (session?.parentID)
|
|
15
|
+
return yield* new InvalidRequestError({ message: "Set the bell on the top-level session, not on a subagent" });
|
|
16
|
+
});
|
|
17
|
+
return {
|
|
18
|
+
get: Effect.fn("PushHandler.get")(function* () {
|
|
19
|
+
return { data: yield* list.info() };
|
|
20
|
+
}),
|
|
21
|
+
register: Effect.fn("PushHandler.register")(function* (id, payload) {
|
|
22
|
+
return { data: yield* list.register(id, payload).pipe(Effect.mapError(invalid)) };
|
|
23
|
+
}),
|
|
24
|
+
remove: Effect.fn("PushHandler.remove")(function* (id) {
|
|
25
|
+
yield* list.remove(id);
|
|
26
|
+
return HttpApiSchema.NoContent.make();
|
|
27
|
+
}),
|
|
28
|
+
update: Effect.fn("PushHandler.update")(function* (id, payload) {
|
|
29
|
+
return { data: yield* list.update(id, payload).pipe(Effect.mapError(notFound)) };
|
|
30
|
+
}),
|
|
31
|
+
setDeviceBell: Effect.fn("PushHandler.setDeviceBell")(function* (id, sessionID, bell) {
|
|
32
|
+
yield* rejectSubagent(sessionID);
|
|
33
|
+
return {
|
|
34
|
+
data: yield* list.setDeviceBell(id, sessionID, bell).pipe(Effect.catchTags({
|
|
35
|
+
"PushList.InvalidError": (error) => Effect.fail(invalid(error)),
|
|
36
|
+
"PushList.NotFoundError": (error) => Effect.fail(notFound(error))
|
|
37
|
+
}))
|
|
38
|
+
};
|
|
39
|
+
}),
|
|
40
|
+
removeDeviceBell: Effect.fn("PushHandler.removeDeviceBell")(function* (id, sessionID) {
|
|
41
|
+
yield* list.removeDeviceBell(id, sessionID).pipe(Effect.mapError(notFound));
|
|
42
|
+
return HttpApiSchema.NoContent.make();
|
|
43
|
+
}),
|
|
44
|
+
setSessionBell: Effect.fn("PushHandler.setSessionBell")(function* (sessionID, bell) {
|
|
45
|
+
yield* rejectSubagent(sessionID);
|
|
46
|
+
return { data: yield* list.setSessionBell(sessionID, bell).pipe(Effect.mapError(invalid)) };
|
|
47
|
+
}),
|
|
48
|
+
removeSessionBell: Effect.fn("PushHandler.removeSessionBell")(function* (sessionID) {
|
|
49
|
+
yield* list.removeSessionBell(sessionID);
|
|
50
|
+
return HttpApiSchema.NoContent.make();
|
|
51
|
+
}),
|
|
52
|
+
setSettings: Effect.fn("PushHandler.setSettings")(function* (settings) {
|
|
53
|
+
return { data: yield* list.setSettings(settings).pipe(Effect.mapError(invalid)) };
|
|
54
|
+
})
|
|
55
|
+
};
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
export { makePush2 };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import {
|
|
2
|
+
__export
|
|
3
|
+
} from "./api-9rqn6x4v.js";
|
|
4
|
+
|
|
5
|
+
// src/service-status.ts
|
|
6
|
+
var exports_service_status = {};
|
|
7
|
+
__export(exports_service_status, {
|
|
8
|
+
Status: () => exports_service_status,
|
|
9
|
+
make: () => make3
|
|
10
|
+
});
|
|
11
|
+
import { Effect, Ref } from "effect";
|
|
12
|
+
var make3 = Effect.fnUntraced(function* (options = {}) {
|
|
13
|
+
const current = yield* Ref.make(options.initial ?? { type: "starting" });
|
|
14
|
+
const beginStopping = Ref.update(current, (status) => status.type === "stopping" ? status : { type: "stopping" });
|
|
15
|
+
return {
|
|
16
|
+
current: Ref.get(current),
|
|
17
|
+
ready: Ref.update(current, (status) => status.type === "starting" ? { type: "ready" } : status),
|
|
18
|
+
fail: Ref.update(current, (status) => status.type === "starting" ? { type: "failed" } : status),
|
|
19
|
+
beginStopping
|
|
20
|
+
};
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
export { make3, exports_service_status };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import {
|
|
2
|
+
LocationMiddleware2
|
|
3
|
+
} from "./api-0q8mvh3b.js";
|
|
4
|
+
import {
|
|
5
|
+
FormLocationMiddleware2
|
|
6
|
+
} from "./api-bnpt5zxx.js";
|
|
7
|
+
import {
|
|
8
|
+
SessionLocationMiddleware2
|
|
9
|
+
} from "./api-5fr63cjn.js";
|
|
10
|
+
|
|
11
|
+
// src/api.ts
|
|
12
|
+
import { makeDefaultApi } from "@radheim/protocol/api";
|
|
13
|
+
var Api2 = makeDefaultApi({
|
|
14
|
+
locationMiddleware: LocationMiddleware2,
|
|
15
|
+
formLocationMiddleware: FormLocationMiddleware2,
|
|
16
|
+
sessionLocationMiddleware: SessionLocationMiddleware2
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
export { Api2 };
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import {
|
|
2
|
+
response2
|
|
3
|
+
} from "./api-0q8mvh3b.js";
|
|
4
|
+
import {
|
|
5
|
+
Api2
|
|
6
|
+
} from "./api-f6955nmc.js";
|
|
7
|
+
|
|
8
|
+
// src/handlers/websearch.ts
|
|
9
|
+
import { WebSearch } from "@radheim/core/websearch";
|
|
10
|
+
import { InvalidRequestError, ServiceUnavailableError } from "@radheim/protocol/errors";
|
|
11
|
+
import { Effect } from "effect";
|
|
12
|
+
import { HttpApiBuilder } from "effect/http-api";
|
|
13
|
+
var WebSearchHandler2 = HttpApiBuilder.group(Api2, "server.websearch", (handlers) => Effect.gen(function* () {
|
|
14
|
+
return handlers.handle("websearch.providers", Effect.fn("server.websearch.providers")(function* () {
|
|
15
|
+
const websearch = yield* WebSearch.Service;
|
|
16
|
+
return yield* response2(websearch.providers());
|
|
17
|
+
})).handle("websearch.query", Effect.fn("server.websearch.query")(function* (request) {
|
|
18
|
+
const websearch = yield* WebSearch.Service;
|
|
19
|
+
return yield* response2(websearch.query(request.payload).pipe(Effect.catchTags({
|
|
20
|
+
"WebSearch.ProviderRequired": () => new InvalidRequestError({
|
|
21
|
+
message: "Web search provider is required",
|
|
22
|
+
kind: "websearch_provider_required",
|
|
23
|
+
field: "providerID"
|
|
24
|
+
}),
|
|
25
|
+
"WebSearch.ProviderNotFound": (error) => new InvalidRequestError({
|
|
26
|
+
message: `Web search provider not found: ${error.providerID}`,
|
|
27
|
+
kind: "websearch_provider_not_found",
|
|
28
|
+
field: "providerID"
|
|
29
|
+
}),
|
|
30
|
+
"WebSearch.Disabled": () => new InvalidRequestError({ message: "Web search is disabled", kind: "websearch_disabled" }),
|
|
31
|
+
"WebSearch.Request": (error) => new ServiceUnavailableError({
|
|
32
|
+
message: `Web search request failed: ${error.providerID}`,
|
|
33
|
+
service: error.providerID
|
|
34
|
+
})
|
|
35
|
+
})));
|
|
36
|
+
}));
|
|
37
|
+
}));
|
|
38
|
+
|
|
39
|
+
export { WebSearchHandler2 };
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import {
|
|
2
|
+
__export
|
|
3
|
+
} from "./api-9rqn6x4v.js";
|
|
4
|
+
|
|
5
|
+
// src/pairing.ts
|
|
6
|
+
var exports_pairing = {};
|
|
7
|
+
__export(exports_pairing, {
|
|
8
|
+
ServerPairing: () => exports_pairing,
|
|
9
|
+
Service: () => Service4,
|
|
10
|
+
node: () => node3
|
|
11
|
+
});
|
|
12
|
+
import { Cache, Context, Duration, Effect, Layer } from "effect";
|
|
13
|
+
import { makeGlobalNode } from "@radheim/util/effect/app-node";
|
|
14
|
+
import { randomBytes } from "node:crypto";
|
|
15
|
+
var TTL = Duration.minutes(5);
|
|
16
|
+
|
|
17
|
+
class Service4 extends Context.Service()("@radheim/ServerPairing") {
|
|
18
|
+
}
|
|
19
|
+
var noLookup = () => Effect.die(new Error("ServerPairing cache must be used via set/invalidateWhen, never get"));
|
|
20
|
+
var layer = Layer.effect(Service4, Effect.gen(function* () {
|
|
21
|
+
const cache = yield* Cache.make({ capacity: 1000, lookup: noLookup, timeToLive: TTL });
|
|
22
|
+
return Service4.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 node3 = makeGlobalNode({ service: Service4, layer, deps: [] });
|
|
34
|
+
|
|
35
|
+
export { Service4, node3, exports_pairing };
|
|
@@ -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/reference.ts
|
|
9
|
+
import { Reference } from "@radheim/core/reference";
|
|
10
|
+
import { HttpApiBuilder } from "effect/http-api";
|
|
11
|
+
var ReferenceHandler2 = HttpApiBuilder.group(Api2, "server.reference", (handlers) => handlers.handle("reference.list", () => response2(Reference.Service.use((reference) => reference.list()))));
|
|
12
|
+
|
|
13
|
+
export { ReferenceHandler2 };
|