@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,109 @@
|
|
|
1
|
+
import {
|
|
2
|
+
locationErrors2,
|
|
3
|
+
response2,
|
|
4
|
+
requestRef2
|
|
5
|
+
} from "./api-0q8mvh3b.js";
|
|
6
|
+
import {
|
|
7
|
+
Api2
|
|
8
|
+
} from "./api-f6955nmc.js";
|
|
9
|
+
import {
|
|
10
|
+
CorsConfig2,
|
|
11
|
+
isAllowedRequestOrigin2
|
|
12
|
+
} from "./api-11hx8jza.js";
|
|
13
|
+
import {
|
|
14
|
+
runPtySocket2,
|
|
15
|
+
holdLocation2
|
|
16
|
+
} from "./api-zvb9sh2w.js";
|
|
17
|
+
|
|
18
|
+
// src/handlers/mcp.ts
|
|
19
|
+
import { Location } from "@radheim/core/location";
|
|
20
|
+
import { LocationServiceMap } from "@radheim/core/location-service-map";
|
|
21
|
+
import { Mcp } from "@radheim/core/mcp/index";
|
|
22
|
+
import { PtyTicket } from "@radheim/core/pty/ticket";
|
|
23
|
+
import { ForbiddenError, McpServerNotFoundError } from "@radheim/protocol/errors";
|
|
24
|
+
import { PTY_CONNECT_TOKEN_HEADER, PTY_CONNECT_TOKEN_HEADER_VALUE } from "@radheim/protocol/groups/pty";
|
|
25
|
+
import { Effect, Queue } from "effect";
|
|
26
|
+
import { HttpServerResponse } from "effect/http";
|
|
27
|
+
import { HttpApiBuilder, HttpApiSchema } from "effect/http-api";
|
|
28
|
+
import { Socket } from "effect/socket";
|
|
29
|
+
var notFound = (effect) => effect.pipe(Effect.mapError((error) => new McpServerNotFoundError({ server: error.server, message: error.message })));
|
|
30
|
+
var McpHandler2 = HttpApiBuilder.group(Api2, "server.mcp", (handlers) => Effect.gen(function* () {
|
|
31
|
+
const locations = yield* LocationServiceMap.Service;
|
|
32
|
+
const cors = yield* CorsConfig2;
|
|
33
|
+
const tickets = yield* PtyTicket.Service;
|
|
34
|
+
return handlers.handle("mcp.list", Effect.fnUntraced(function* () {
|
|
35
|
+
const service = yield* Mcp.Service;
|
|
36
|
+
return yield* response2(service.servers());
|
|
37
|
+
})).handle("mcp.add", Effect.fnUntraced(function* (ctx) {
|
|
38
|
+
const service = yield* Mcp.Service;
|
|
39
|
+
yield* service.add(ctx.params.server, ctx.payload.config);
|
|
40
|
+
return HttpApiSchema.NoContent.make();
|
|
41
|
+
})).handle("mcp.remove", Effect.fnUntraced(function* (ctx) {
|
|
42
|
+
const service = yield* Mcp.Service;
|
|
43
|
+
yield* notFound(service.remove(ctx.params.server));
|
|
44
|
+
return HttpApiSchema.NoContent.make();
|
|
45
|
+
})).handle("mcp.connect", Effect.fnUntraced(function* (ctx) {
|
|
46
|
+
const service = yield* Mcp.Service;
|
|
47
|
+
yield* notFound(service.connect(ctx.params.server));
|
|
48
|
+
return HttpApiSchema.NoContent.make();
|
|
49
|
+
})).handle("mcp.disconnect", Effect.fnUntraced(function* (ctx) {
|
|
50
|
+
const service = yield* Mcp.Service;
|
|
51
|
+
yield* notFound(service.disconnect(ctx.params.server));
|
|
52
|
+
return HttpApiSchema.NoContent.make();
|
|
53
|
+
})).handle("mcp.resource.catalog", Effect.fnUntraced(function* () {
|
|
54
|
+
const service = yield* Mcp.Service;
|
|
55
|
+
return yield* response2(service.resourceCatalog());
|
|
56
|
+
})).handle("mcp.clientToken", Effect.fnUntraced(function* (ctx) {
|
|
57
|
+
if (ctx.headers[PTY_CONNECT_TOKEN_HEADER] !== PTY_CONNECT_TOKEN_HEADER_VALUE || !isAllowedRequestOrigin2(ctx.request.headers.origin, ctx.request.headers.host, cors))
|
|
58
|
+
return yield* new ForbiddenError({ message: "Invalid client MCP connect token request" });
|
|
59
|
+
const location = yield* Location.Service;
|
|
60
|
+
return yield* response2(tickets.issue({
|
|
61
|
+
mcpClient: ctx.query.name,
|
|
62
|
+
directory: location.directory,
|
|
63
|
+
workspaceID: location.workspaceID
|
|
64
|
+
}));
|
|
65
|
+
})).handleRaw("mcp.client", Effect.fn("McpHandler.client")(function* (ctx) {
|
|
66
|
+
if (!isAllowedRequestOrigin2(ctx.request.headers.origin, ctx.request.headers.host, cors))
|
|
67
|
+
return HttpServerResponse.empty({ status: 403 });
|
|
68
|
+
const name = ctx.query.name;
|
|
69
|
+
const ref = LocationServiceMap.canonical(requestRef2(ctx.request));
|
|
70
|
+
if (ctx.query.ticket && !(yield* tickets.consume({
|
|
71
|
+
ticket: ctx.query.ticket,
|
|
72
|
+
mcpClient: name,
|
|
73
|
+
directory: ref.directory,
|
|
74
|
+
workspaceID: ref.workspaceID
|
|
75
|
+
})))
|
|
76
|
+
return HttpServerResponse.empty({ status: 403 });
|
|
77
|
+
return yield* Effect.gen(function* () {
|
|
78
|
+
const mcp = yield* Mcp.Service;
|
|
79
|
+
const { McpSocketClient } = yield* Effect.promise(() => import("@radheim/core/mcp/socket-client"));
|
|
80
|
+
const socket = yield* Effect.orDie(ctx.request.upgrade);
|
|
81
|
+
const outbox = yield* Queue.unbounded();
|
|
82
|
+
yield* holdLocation2(outbox);
|
|
83
|
+
const state = { attached: false, disconnected: false };
|
|
84
|
+
const transport = McpSocketClient.make({
|
|
85
|
+
send: (text) => Queue.offerUnsafe(outbox, text),
|
|
86
|
+
close: (code, reason) => {
|
|
87
|
+
if (state.attached)
|
|
88
|
+
Queue.offerUnsafe(outbox, new Socket.CloseEvent(code, reason));
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
const decoder = new TextDecoder;
|
|
92
|
+
yield* mcp.attach(name, transport).pipe(Effect.tap(() => Effect.sync(() => {
|
|
93
|
+
state.attached = true;
|
|
94
|
+
})), Effect.catch((error) => state.disconnected ? Effect.logInfo("client MCP disconnected during initialize", { name, error: error.message }) : Effect.logError("client MCP attach failed", { name, error: error.message }).pipe(Effect.andThen(Effect.sync(() => Queue.offerUnsafe(outbox, new Socket.CloseEvent(1011, "attach failed")))))), Effect.forkScoped);
|
|
95
|
+
yield* runPtySocket2({
|
|
96
|
+
socket,
|
|
97
|
+
outbox,
|
|
98
|
+
onMessage: (message) => Effect.sync(() => transport.deliver(typeof message === "string" ? message : decoder.decode(message))),
|
|
99
|
+
detach: () => {
|
|
100
|
+
state.disconnected = true;
|
|
101
|
+
transport.ended();
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
return HttpServerResponse.empty();
|
|
105
|
+
}).pipe(Effect.scoped, Effect.provide(locations.get(ref)), locationErrors2);
|
|
106
|
+
}));
|
|
107
|
+
}));
|
|
108
|
+
|
|
109
|
+
export { McpHandler2 };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Api2
|
|
3
|
+
} from "./api-f6955nmc.js";
|
|
4
|
+
|
|
5
|
+
// src/handlers/location.ts
|
|
6
|
+
import { Location } from "@radheim/core/location";
|
|
7
|
+
import { LocationServiceMap } from "@radheim/core/location-service-map";
|
|
8
|
+
import { ServiceUnavailableError } from "@radheim/protocol/errors";
|
|
9
|
+
import { Cause, Effect } from "effect";
|
|
10
|
+
import { HttpApiBuilder } from "effect/http-api";
|
|
11
|
+
var LocationHandler2 = HttpApiBuilder.group(Api2, "server.location", (handlers) => Effect.gen(function* () {
|
|
12
|
+
const locations = yield* LocationServiceMap.Service;
|
|
13
|
+
return handlers.handle("location.get", Effect.fnUntraced(function* () {
|
|
14
|
+
const location = yield* Location.Service;
|
|
15
|
+
return new Location.Info({
|
|
16
|
+
directory: location.directory,
|
|
17
|
+
project: location.project
|
|
18
|
+
});
|
|
19
|
+
})).handle("location.reload", () => locations.reload.pipe(Effect.withSpan("LocationServiceMap.reload"), Effect.catchCause((cause) => Cause.hasInterruptsOnly(cause) ? Effect.failCause(Cause.fromReasons(cause.reasons.filter(Cause.isInterruptReason))) : Effect.fail(new ServiceUnavailableError({ message: Cause.pretty(cause), service: "location" })))));
|
|
20
|
+
}));
|
|
21
|
+
|
|
22
|
+
export { LocationHandler2 };
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Api2
|
|
3
|
+
} from "./api-f6955nmc.js";
|
|
4
|
+
import {
|
|
5
|
+
requireConnectable2
|
|
6
|
+
} from "./api-280h8k1v.js";
|
|
7
|
+
|
|
8
|
+
// src/handlers/credential.ts
|
|
9
|
+
import { Credential } from "@radheim/core/credential";
|
|
10
|
+
import { FileSystem } from "@radheim/core/filesystem";
|
|
11
|
+
import { Integration } from "@radheim/core/integration";
|
|
12
|
+
import { Location } from "@radheim/core/location";
|
|
13
|
+
import { LocationServiceMap } from "@radheim/core/location-services";
|
|
14
|
+
import { AbsolutePath } from "@radheim/core/schema";
|
|
15
|
+
import { ConflictError } from "@radheim/protocol/errors";
|
|
16
|
+
import { Global } from "@radheim/util/global";
|
|
17
|
+
import { Effect } from "effect";
|
|
18
|
+
import { HttpApiBuilder, HttpApiSchema } from "effect/http-api";
|
|
19
|
+
var CredentialHandler2 = HttpApiBuilder.group(Api2, "server.credential", (handlers) => Effect.gen(function* () {
|
|
20
|
+
const global = yield* Global.Service;
|
|
21
|
+
const locations = yield* LocationServiceMap.Service;
|
|
22
|
+
const services = locations.get(Location.Ref.make({ directory: AbsolutePath.make(global.config) }));
|
|
23
|
+
return handlers.handle("credential.list", Effect.fnUntraced(function* () {
|
|
24
|
+
const credential = yield* Credential.Service;
|
|
25
|
+
return { data: entries(yield* credential.all()) };
|
|
26
|
+
})).handle("credential.create", Effect.fnUntraced(function* (ctx) {
|
|
27
|
+
yield* requireConnectable2(ctx.payload.integrationID).pipe(Effect.provide(services), Effect.catchIf((error) => error instanceof FileSystem.DirectoryNotFoundError, Effect.die));
|
|
28
|
+
const credential = yield* Credential.Service;
|
|
29
|
+
if (ctx.payload.id && (yield* credential.get(ctx.payload.id)))
|
|
30
|
+
return yield* new ConflictError({
|
|
31
|
+
resource: ctx.payload.id,
|
|
32
|
+
message: `Credential already exists: ${ctx.payload.id}`
|
|
33
|
+
});
|
|
34
|
+
const created = yield* credential.create(ctx.payload);
|
|
35
|
+
const entry = entries(yield* credential.list(created.integrationID)).find((item) => item.id === created.id);
|
|
36
|
+
return { data: entry ?? { ...created, active: false } };
|
|
37
|
+
})).handle("credential.update", Effect.fnUntraced(function* (ctx) {
|
|
38
|
+
const credential = yield* Credential.Service;
|
|
39
|
+
yield* credential.update(ctx.params.credentialID, { label: ctx.payload.label });
|
|
40
|
+
return HttpApiSchema.NoContent.make();
|
|
41
|
+
})).handle("credential.activate", Effect.fnUntraced(function* (ctx) {
|
|
42
|
+
const credential = yield* Credential.Service;
|
|
43
|
+
yield* credential.activate(ctx.params.credentialID);
|
|
44
|
+
return HttpApiSchema.NoContent.make();
|
|
45
|
+
})).handle("credential.remove", Effect.fnUntraced(function* (ctx) {
|
|
46
|
+
const integrations = yield* Integration.Service.pipe(Effect.provide(services), Effect.orDie);
|
|
47
|
+
yield* integrations.connection.remove(ctx.params.credentialID);
|
|
48
|
+
return HttpApiSchema.NoContent.make();
|
|
49
|
+
}));
|
|
50
|
+
}));
|
|
51
|
+
function entries(credentials) {
|
|
52
|
+
const selected = new Map(credentials.map((item) => [item.integrationID, item.id]));
|
|
53
|
+
return credentials.map((item) => ({
|
|
54
|
+
id: item.id,
|
|
55
|
+
integrationID: item.integrationID,
|
|
56
|
+
label: item.label,
|
|
57
|
+
active: selected.get(item.integrationID) === item.id,
|
|
58
|
+
value: item.value
|
|
59
|
+
}));
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export { CredentialHandler2 };
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import {
|
|
2
|
+
CONTENT_SECURITY_POLICY2,
|
|
3
|
+
disposition2
|
|
4
|
+
} from "./api-t32e1bbt.js";
|
|
5
|
+
|
|
6
|
+
// src/handlers/media.ts
|
|
7
|
+
import { Database } from "@radheim/core/database/database";
|
|
8
|
+
import { SessionBlob } from "@radheim/core/session/blob";
|
|
9
|
+
import { FileNotFoundError } from "@radheim/protocol/errors";
|
|
10
|
+
import { Effect } from "effect";
|
|
11
|
+
import { HttpServerResponse } from "effect/http";
|
|
12
|
+
var INLINE_IMAGE_MIMES = new Set(["image/png", "image/jpeg", "image/gif", "image/webp"]);
|
|
13
|
+
var CACHE_CONTROL = "private, max-age=31536000, immutable";
|
|
14
|
+
var makeMediaGet2 = Effect.gen(function* () {
|
|
15
|
+
const { db } = yield* Database.Service;
|
|
16
|
+
return (hash, request) => Effect.gen(function* () {
|
|
17
|
+
const path = `/api/experimental/media/${hash}`;
|
|
18
|
+
const blob = yield* SessionBlob.read(db, hash);
|
|
19
|
+
if (!blob)
|
|
20
|
+
return yield* new FileNotFoundError({ path, message: `Media blob not found: ${hash}` });
|
|
21
|
+
const etag = `"${hash}"`;
|
|
22
|
+
const inline = INLINE_IMAGE_MIMES.has(blob.mime);
|
|
23
|
+
const headers = {
|
|
24
|
+
"cache-control": CACHE_CONTROL,
|
|
25
|
+
etag,
|
|
26
|
+
"content-disposition": disposition2(""),
|
|
27
|
+
"content-security-policy": CONTENT_SECURITY_POLICY2,
|
|
28
|
+
"x-content-type-options": "nosniff"
|
|
29
|
+
};
|
|
30
|
+
if (matchesIfNoneMatch(request.headers["if-none-match"], etag))
|
|
31
|
+
return HttpServerResponse.empty({ status: 304, headers });
|
|
32
|
+
return HttpServerResponse.uint8Array(blob.data, {
|
|
33
|
+
status: 200,
|
|
34
|
+
contentType: inline ? blob.mime : "application/octet-stream",
|
|
35
|
+
headers
|
|
36
|
+
});
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
function matchesIfNoneMatch(ifNoneMatch, etag) {
|
|
40
|
+
if (ifNoneMatch === undefined)
|
|
41
|
+
return false;
|
|
42
|
+
return ifNoneMatch.split(",").some((tag) => {
|
|
43
|
+
const trimmed = tag.trim();
|
|
44
|
+
return trimmed === "*" || trimmed.replace(/^w\//i, "") === etag;
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export { makeMediaGet2 };
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import {
|
|
2
|
+
response2
|
|
3
|
+
} from "./api-0q8mvh3b.js";
|
|
4
|
+
import {
|
|
5
|
+
Api2
|
|
6
|
+
} from "./api-f6955nmc.js";
|
|
7
|
+
|
|
8
|
+
// src/handlers/provider.ts
|
|
9
|
+
import { Provider } from "@radheim/core/provider";
|
|
10
|
+
import { ProviderNotFoundError } from "@radheim/protocol/errors";
|
|
11
|
+
import { Effect } from "effect";
|
|
12
|
+
import { HttpApiBuilder } from "effect/http-api";
|
|
13
|
+
var ProviderHandler2 = HttpApiBuilder.group(Api2, "server.provider", (handlers) => Effect.gen(function* () {
|
|
14
|
+
return handlers.handle("provider.list", Effect.fnUntraced(function* () {
|
|
15
|
+
const providers = yield* Provider.Service;
|
|
16
|
+
return yield* response2(providers.available());
|
|
17
|
+
})).handle("provider.get", Effect.fnUntraced(function* (ctx) {
|
|
18
|
+
const providers = yield* Provider.Service;
|
|
19
|
+
const provider = yield* providers.get(ctx.params.providerID);
|
|
20
|
+
if (!provider)
|
|
21
|
+
return yield* new ProviderNotFoundError({
|
|
22
|
+
providerID: ctx.params.providerID,
|
|
23
|
+
message: `Provider not found: ${ctx.params.providerID}`
|
|
24
|
+
});
|
|
25
|
+
return yield* response2(Effect.succeed(provider));
|
|
26
|
+
}));
|
|
27
|
+
}));
|
|
28
|
+
|
|
29
|
+
export { ProviderHandler2 };
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import {
|
|
2
|
+
requestRef2
|
|
3
|
+
} from "./api-0q8mvh3b.js";
|
|
4
|
+
import {
|
|
5
|
+
Api2
|
|
6
|
+
} from "./api-f6955nmc.js";
|
|
7
|
+
|
|
8
|
+
// src/handlers/debug.ts
|
|
9
|
+
import { LocationServiceMap } from "@radheim/core/location-service-map";
|
|
10
|
+
import { InvalidRequestError, UnknownError } from "@radheim/protocol/errors";
|
|
11
|
+
import { Global } from "@radheim/util/global";
|
|
12
|
+
import { HeapSnapshot } from "@radheim/util/heap-snapshot";
|
|
13
|
+
import { Effect, Option } from "effect";
|
|
14
|
+
import { HttpApiBuilder } from "effect/http-api";
|
|
15
|
+
import path from "node:path";
|
|
16
|
+
var DebugHandler2 = HttpApiBuilder.group(Api2, "server.debug", (handlers) => Effect.gen(function* () {
|
|
17
|
+
const global = yield* Global.Service;
|
|
18
|
+
return handlers.handle("debug.heapDump", Effect.fn("server.debug.heapDump")(function* (ctx) {
|
|
19
|
+
const directory = ctx.query.directory;
|
|
20
|
+
if (directory !== undefined && !path.isAbsolute(directory))
|
|
21
|
+
return yield* new InvalidRequestError({ message: "directory must be an absolute path", field: "directory" });
|
|
22
|
+
return yield* HeapSnapshot.write(directory ?? global.log).pipe(Effect.catch((cause) => {
|
|
23
|
+
const ref = `err_${crypto.randomUUID().slice(0, 8)}`;
|
|
24
|
+
return Effect.logError("failed to write heap snapshot", { cause }).pipe(Effect.annotateLogs({ ref }), Effect.andThen(Effect.fail(new UnknownError({
|
|
25
|
+
message: `Failed to write heap snapshot: ${cause.cause instanceof Error ? cause.cause.message : cause.message}`,
|
|
26
|
+
ref
|
|
27
|
+
}))));
|
|
28
|
+
}));
|
|
29
|
+
})).handle("debug.location", Effect.fnUntraced(function* () {
|
|
30
|
+
const locations = Option.getOrThrow(yield* Effect.serviceOption(LocationServiceMap.Service));
|
|
31
|
+
return yield* locations.keys;
|
|
32
|
+
})).handle("debug.location.evict", Effect.fnUntraced(function* (ctx) {
|
|
33
|
+
const locations = Option.getOrThrow(yield* Effect.serviceOption(LocationServiceMap.Service));
|
|
34
|
+
yield* locations.invalidate(requestRef2(ctx.request));
|
|
35
|
+
}));
|
|
36
|
+
}));
|
|
37
|
+
|
|
38
|
+
export { DebugHandler2 };
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
// src/middleware/schema-error.ts
|
|
2
|
+
import { Effect } from "effect";
|
|
3
|
+
import { HttpServerResponse } from "effect/http";
|
|
4
|
+
import { HttpApiMiddleware } from "effect/http-api";
|
|
5
|
+
import { InvalidRequestError } from "@radheim/protocol/errors";
|
|
6
|
+
import { SchemaErrorMiddleware } from "@radheim/protocol/middleware/schema-error";
|
|
7
|
+
import { SchemaErrorMiddleware as SchemaErrorMiddleware2 } from "@radheim/protocol/middleware/schema-error";
|
|
8
|
+
var REASON_LIMIT = 1024;
|
|
9
|
+
function truncateReason(reason) {
|
|
10
|
+
if (reason.length <= REASON_LIMIT)
|
|
11
|
+
return reason;
|
|
12
|
+
return reason.slice(0, REASON_LIMIT) + `... (${reason.length - REASON_LIMIT} more chars)`;
|
|
13
|
+
}
|
|
14
|
+
var schemaErrorLayer2 = HttpApiMiddleware.layerSchemaErrorTransform(SchemaErrorMiddleware, (error, context) => {
|
|
15
|
+
const reason = truncateReason(error.cause.message);
|
|
16
|
+
if (error.kind === "Body" || error.kind === "ResponseHeaders") {
|
|
17
|
+
const ref = `err_${crypto.randomUUID().slice(0, 8)}`;
|
|
18
|
+
return Effect.logError("failed to encode response").pipe(Effect.annotateLogs({
|
|
19
|
+
ref,
|
|
20
|
+
kind: error.kind,
|
|
21
|
+
endpoint: `${context.group.identifier}.${context.endpoint.name}`,
|
|
22
|
+
route: `${context.endpoint.method} ${context.endpoint.path}`,
|
|
23
|
+
reason
|
|
24
|
+
}), Effect.as(HttpServerResponse.jsonUnsafe({
|
|
25
|
+
_tag: "UnknownError",
|
|
26
|
+
message: "Server failed to encode its response. Check server logs for details.",
|
|
27
|
+
ref
|
|
28
|
+
}, { status: 500 })));
|
|
29
|
+
}
|
|
30
|
+
return Effect.logWarning("schema rejection").pipe(Effect.annotateLogs({ kind: error.kind, reason }), Effect.andThen(Effect.fail(new InvalidRequestError({ message: reason, kind: error.kind }))));
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
export { schemaErrorLayer2, SchemaErrorMiddleware2 };
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import {
|
|
2
|
+
locationErrors2,
|
|
3
|
+
response2,
|
|
4
|
+
requestRef2
|
|
5
|
+
} from "./api-0q8mvh3b.js";
|
|
6
|
+
import {
|
|
7
|
+
Api2
|
|
8
|
+
} from "./api-f6955nmc.js";
|
|
9
|
+
import {
|
|
10
|
+
CorsConfig2,
|
|
11
|
+
isAllowedRequestOrigin2
|
|
12
|
+
} from "./api-11hx8jza.js";
|
|
13
|
+
import {
|
|
14
|
+
runPtySocket2,
|
|
15
|
+
holdLocation2
|
|
16
|
+
} from "./api-zvb9sh2w.js";
|
|
17
|
+
|
|
18
|
+
// src/handlers/pty.ts
|
|
19
|
+
import { Pty } from "@radheim/core/pty";
|
|
20
|
+
import { PtyProtocol } from "@radheim/core/pty/protocol";
|
|
21
|
+
import { PtyTicket } from "@radheim/core/pty/ticket";
|
|
22
|
+
import { Location } from "@radheim/core/location";
|
|
23
|
+
import { LocationServiceMap } from "@radheim/core/location-service-map";
|
|
24
|
+
import { Effect, Queue } from "effect";
|
|
25
|
+
import { HttpServerRequest, HttpServerResponse } from "effect/http";
|
|
26
|
+
import { HttpApiBuilder, HttpApiSchema } from "effect/http-api";
|
|
27
|
+
import { Socket } from "effect/socket";
|
|
28
|
+
import { ForbiddenError, PtyNotFoundError, ServiceUnavailableError } from "@radheim/protocol/errors";
|
|
29
|
+
import {
|
|
30
|
+
PTY_CONNECT_TICKET_QUERY,
|
|
31
|
+
PTY_CONNECT_TOKEN_HEADER,
|
|
32
|
+
PTY_CONNECT_TOKEN_HEADER_VALUE
|
|
33
|
+
} from "@radheim/protocol/groups/pty";
|
|
34
|
+
var notFound = (ptyID) => new PtyNotFoundError({ ptyID, message: `PTY session not found: ${ptyID}` });
|
|
35
|
+
var PtyHandler2 = HttpApiBuilder.group(Api2, "server.pty", (handlers) => Effect.gen(function* () {
|
|
36
|
+
const locations = yield* LocationServiceMap.Service;
|
|
37
|
+
const tickets = yield* PtyTicket.Service;
|
|
38
|
+
const cors = yield* CorsConfig2;
|
|
39
|
+
return handlers.handle("pty.list", Effect.fnUntraced(function* () {
|
|
40
|
+
const pty = yield* Pty.Service;
|
|
41
|
+
return yield* response2(pty.list());
|
|
42
|
+
})).handle("pty.create", Effect.fnUntraced(function* (ctx) {
|
|
43
|
+
const pty = yield* Pty.Service;
|
|
44
|
+
const location = yield* Location.Service;
|
|
45
|
+
return yield* response2(pty.create({
|
|
46
|
+
...ctx.payload,
|
|
47
|
+
cwd: ctx.payload.cwd || location.directory
|
|
48
|
+
}).pipe(Effect.mapError((error) => new ServiceUnavailableError({ message: error.message, service: "pty" }))));
|
|
49
|
+
})).handle("pty.get", Effect.fnUntraced(function* (ctx) {
|
|
50
|
+
const pty = yield* Pty.Service;
|
|
51
|
+
return yield* response2(pty.get(ctx.params.ptyID).pipe(Effect.catchTag("Pty.NotFoundError", () => notFound(ctx.params.ptyID))));
|
|
52
|
+
})).handle("pty.update", Effect.fnUntraced(function* (ctx) {
|
|
53
|
+
const pty = yield* Pty.Service;
|
|
54
|
+
return yield* response2(pty.update(ctx.params.ptyID, ctx.payload).pipe(Effect.catchTag("Pty.NotFoundError", () => notFound(ctx.params.ptyID))));
|
|
55
|
+
})).handle("pty.remove", Effect.fnUntraced(function* (ctx) {
|
|
56
|
+
const pty = yield* Pty.Service;
|
|
57
|
+
yield* pty.remove(ctx.params.ptyID).pipe(Effect.catchTag("Pty.NotFoundError", () => notFound(ctx.params.ptyID)));
|
|
58
|
+
return HttpApiSchema.NoContent.make();
|
|
59
|
+
})).handle("pty.connectToken", Effect.fnUntraced(function* (ctx) {
|
|
60
|
+
const request = yield* HttpServerRequest.HttpServerRequest;
|
|
61
|
+
if (request.headers[PTY_CONNECT_TOKEN_HEADER] !== PTY_CONNECT_TOKEN_HEADER_VALUE || !isAllowedRequestOrigin2(request.headers.origin, request.headers.host, cors))
|
|
62
|
+
return yield* new ForbiddenError({ message: "Invalid PTY connect token request" });
|
|
63
|
+
const pty = yield* Pty.Service;
|
|
64
|
+
const location = yield* Location.Service;
|
|
65
|
+
yield* pty.get(ctx.params.ptyID).pipe(Effect.catchTag("Pty.NotFoundError", () => notFound(ctx.params.ptyID)));
|
|
66
|
+
return yield* response2(tickets.issue({
|
|
67
|
+
ptyID: ctx.params.ptyID,
|
|
68
|
+
directory: location.directory,
|
|
69
|
+
workspaceID: location.workspaceID
|
|
70
|
+
}));
|
|
71
|
+
})).handleRaw("pty.connect", Effect.fn("PtyHandler.connect")(function* (ctx) {
|
|
72
|
+
if (!isAllowedRequestOrigin2(ctx.request.headers.origin, ctx.request.headers.host, cors))
|
|
73
|
+
return HttpServerResponse.empty({ status: 403 });
|
|
74
|
+
const ref = LocationServiceMap.canonical(requestRef2(ctx.request));
|
|
75
|
+
const url = new URL(ctx.request.url, "http://localhost");
|
|
76
|
+
const ticket = url.searchParams.get(PTY_CONNECT_TICKET_QUERY);
|
|
77
|
+
if (ticket && !(yield* tickets.consume({
|
|
78
|
+
ticket,
|
|
79
|
+
ptyID: ctx.params.ptyID,
|
|
80
|
+
directory: ref.directory,
|
|
81
|
+
workspaceID: ref.workspaceID
|
|
82
|
+
})))
|
|
83
|
+
return HttpServerResponse.empty({ status: 403 });
|
|
84
|
+
return yield* Effect.gen(function* () {
|
|
85
|
+
const pty = yield* Pty.Service;
|
|
86
|
+
const exists = yield* pty.get(ctx.params.ptyID).pipe(Effect.as(true), Effect.catchTag("Pty.NotFoundError", () => Effect.succeed(false)));
|
|
87
|
+
if (!exists)
|
|
88
|
+
return HttpServerResponse.empty({ status: 404 });
|
|
89
|
+
const parsedCursor = url.searchParams.get("cursor");
|
|
90
|
+
const cursorNumber = parsedCursor === null ? undefined : Number(parsedCursor);
|
|
91
|
+
const cursor = cursorNumber !== undefined && Number.isSafeInteger(cursorNumber) && cursorNumber >= -1 ? cursorNumber : undefined;
|
|
92
|
+
const socket = yield* Effect.orDie(ctx.request.upgrade);
|
|
93
|
+
const outbox = yield* Queue.unbounded();
|
|
94
|
+
yield* holdLocation2(outbox);
|
|
95
|
+
const attachment = yield* pty.attach(ctx.params.ptyID, {
|
|
96
|
+
cursor,
|
|
97
|
+
onData: (chunk) => Queue.offerUnsafe(outbox, chunk),
|
|
98
|
+
onEnd: () => Queue.offerUnsafe(outbox, new Socket.CloseEvent(1000))
|
|
99
|
+
}).pipe(Effect.catchTags({
|
|
100
|
+
"Pty.NotFoundError": () => Effect.sync(() => {
|
|
101
|
+
Queue.offerUnsafe(outbox, new Socket.CloseEvent(4404, "session not found"));
|
|
102
|
+
}),
|
|
103
|
+
"Pty.ExitedError": () => Effect.sync(() => {
|
|
104
|
+
Queue.offerUnsafe(outbox, new Socket.CloseEvent(4404, "session exited"));
|
|
105
|
+
})
|
|
106
|
+
}));
|
|
107
|
+
if (attachment) {
|
|
108
|
+
for (const chunk of PtyProtocol.chunks(attachment.replay))
|
|
109
|
+
Queue.offerUnsafe(outbox, chunk);
|
|
110
|
+
Queue.offerUnsafe(outbox, PtyProtocol.metaFrame(attachment.cursor));
|
|
111
|
+
attachment.activate();
|
|
112
|
+
}
|
|
113
|
+
yield* runPtySocket2({
|
|
114
|
+
socket,
|
|
115
|
+
outbox,
|
|
116
|
+
onMessage: (message) => Effect.sync(() => {
|
|
117
|
+
if (!attachment)
|
|
118
|
+
return;
|
|
119
|
+
const decoded = PtyProtocol.decodeInput(message);
|
|
120
|
+
if (decoded !== undefined)
|
|
121
|
+
attachment.write(decoded);
|
|
122
|
+
}),
|
|
123
|
+
detach: () => attachment?.detach()
|
|
124
|
+
});
|
|
125
|
+
return HttpServerResponse.empty();
|
|
126
|
+
}).pipe(Effect.scoped, Effect.provide(locations.get(ref)), locationErrors2);
|
|
127
|
+
}));
|
|
128
|
+
}));
|
|
129
|
+
|
|
130
|
+
export { PtyHandler2 };
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import {
|
|
2
|
+
missingSession2,
|
|
3
|
+
failedMessageDecode2
|
|
4
|
+
} from "./api-ghyd9ren.js";
|
|
5
|
+
import {
|
|
6
|
+
Api2
|
|
7
|
+
} from "./api-f6955nmc.js";
|
|
8
|
+
import {
|
|
9
|
+
wantsMediaRefs2
|
|
10
|
+
} from "./api-xthc02cw.js";
|
|
11
|
+
|
|
12
|
+
// src/handlers/message.ts
|
|
13
|
+
import { SessionMessage } from "@radheim/core/session/message";
|
|
14
|
+
import { Session } from "@radheim/core/session";
|
|
15
|
+
import { Effect, Option, Schema } from "effect";
|
|
16
|
+
import { HttpServerResponse } from "effect/http";
|
|
17
|
+
import { HttpApiBuilder } from "effect/http-api";
|
|
18
|
+
import { InvalidCursorError } from "@radheim/protocol/errors";
|
|
19
|
+
import { SessionMediaMessagesResponse } from "@radheim/protocol/groups/message";
|
|
20
|
+
var DefaultMessagesLimit = 50;
|
|
21
|
+
var Cursor = Schema.Struct({
|
|
22
|
+
id: SessionMessage.ID,
|
|
23
|
+
order: Schema.Union([Schema.Literal("asc"), Schema.Literal("desc")]),
|
|
24
|
+
direction: Schema.Union([Schema.Literal("previous"), Schema.Literal("next")])
|
|
25
|
+
});
|
|
26
|
+
var decodeCursor = Schema.decodeUnknownOption(Schema.fromJsonString(Cursor));
|
|
27
|
+
var cursor = {
|
|
28
|
+
encode(message, order, direction) {
|
|
29
|
+
return Buffer.from(JSON.stringify({ id: message.id, order, direction })).toString("base64url");
|
|
30
|
+
},
|
|
31
|
+
decode(input) {
|
|
32
|
+
return decodeCursor(Buffer.from(input, "base64url").toString("utf8"));
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
var MessageHandler2 = HttpApiBuilder.group(Api2, "server.message", (handlers) => Effect.gen(function* () {
|
|
36
|
+
const session = yield* Session.Service;
|
|
37
|
+
return handlers.handle("session.messages", Effect.fnUntraced(function* (ctx) {
|
|
38
|
+
if (ctx.query.cursor && ctx.query.order !== undefined)
|
|
39
|
+
return yield* new InvalidCursorError({ message: "Cursor cannot be combined with order" });
|
|
40
|
+
const decoded = ctx.query.cursor ? Option.getOrUndefined(cursor.decode(ctx.query.cursor)) ?? (yield* new InvalidCursorError({ message: "Invalid cursor" })) : undefined;
|
|
41
|
+
const order = decoded?.order ?? ctx.query.order ?? "desc";
|
|
42
|
+
const input = {
|
|
43
|
+
sessionID: ctx.params.sessionID,
|
|
44
|
+
limit: ctx.query.limit ?? DefaultMessagesLimit,
|
|
45
|
+
order,
|
|
46
|
+
type: ctx.query.type,
|
|
47
|
+
cursor: decoded ? { id: decoded.id, direction: decoded.direction } : undefined
|
|
48
|
+
};
|
|
49
|
+
const page = (messages) => {
|
|
50
|
+
const first = messages[0];
|
|
51
|
+
const last = messages.at(-1);
|
|
52
|
+
return {
|
|
53
|
+
data: messages,
|
|
54
|
+
cursor: {
|
|
55
|
+
previous: first ? cursor.encode(first, order, "previous") : undefined,
|
|
56
|
+
next: last ? cursor.encode(last, order, "next") : undefined
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
};
|
|
60
|
+
if (wantsMediaRefs2(ctx.request)) {
|
|
61
|
+
const messages = yield* session.messagesWithRefs(input).pipe(Effect.catchTag("Session.NotFoundError", missingSession2), Effect.catchTag("Session.MessageDecodeError", failedMessageDecode2));
|
|
62
|
+
return yield* HttpServerResponse.schemaJson(SessionMediaMessagesResponse)(page(messages)).pipe(Effect.orDie);
|
|
63
|
+
}
|
|
64
|
+
const messages = yield* session.messages(input).pipe(Effect.catchTag("Session.NotFoundError", missingSession2), Effect.catchTag("Session.MessageDecodeError", failedMessageDecode2));
|
|
65
|
+
return page(messages);
|
|
66
|
+
}));
|
|
67
|
+
}));
|
|
68
|
+
|
|
69
|
+
export { MessageHandler2 };
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import {
|
|
2
|
+
locationErrors2
|
|
3
|
+
} from "./api-0q8mvh3b.js";
|
|
4
|
+
import {
|
|
5
|
+
Api2
|
|
6
|
+
} from "./api-f6955nmc.js";
|
|
7
|
+
|
|
8
|
+
// src/handlers/generate.ts
|
|
9
|
+
import { Generate } from "@radheim/core/generate";
|
|
10
|
+
import { VideoGeneration } from "@radheim/core/video-generation";
|
|
11
|
+
import { Location } from "@radheim/core/location";
|
|
12
|
+
import { LocationServiceMap } from "@radheim/core/location-services";
|
|
13
|
+
import { AbsolutePath } from "@radheim/core/schema";
|
|
14
|
+
import {
|
|
15
|
+
VideoNotFoundError,
|
|
16
|
+
InvalidRequestError,
|
|
17
|
+
ModelNotFoundError,
|
|
18
|
+
ProviderRequestError,
|
|
19
|
+
ServiceUnavailableError,
|
|
20
|
+
UnsupportedModelError
|
|
21
|
+
} from "@radheim/protocol/errors";
|
|
22
|
+
import { Global } from "@radheim/util/global";
|
|
23
|
+
import { Effect } from "effect";
|
|
24
|
+
import { HttpApiBuilder } from "effect/http-api";
|
|
25
|
+
var GenerateHandler2 = HttpApiBuilder.group(Api2, "server.generate", (handlers) => Effect.gen(function* () {
|
|
26
|
+
const global = yield* Global.Service;
|
|
27
|
+
const locations = yield* LocationServiceMap.Service;
|
|
28
|
+
const videos = yield* VideoGeneration.Service;
|
|
29
|
+
const services = locations.get(Location.Ref.make({ directory: AbsolutePath.make(global.config) }));
|
|
30
|
+
const text = Effect.fn("server.generate.text")(function* (request) {
|
|
31
|
+
const generate = yield* Generate.Service;
|
|
32
|
+
return { data: { text: yield* generate.text(request.payload).pipe(Effect.mapError(generateError)) } };
|
|
33
|
+
}, Effect.provide(services), locationErrors2);
|
|
34
|
+
const image = Effect.fn("server.generate.image")(function* (request) {
|
|
35
|
+
const generate = yield* Generate.Service;
|
|
36
|
+
return { data: yield* generate.image(request.payload).pipe(Effect.mapError(generateError)) };
|
|
37
|
+
}, Effect.provide(services), locationErrors2);
|
|
38
|
+
const decisions = Effect.fn("server.generate.decisions")(function* (request) {
|
|
39
|
+
const names = new Set(request.payload.questions.map((question) => question.name));
|
|
40
|
+
if (names.size !== request.payload.questions.length)
|
|
41
|
+
return yield* new InvalidRequestError({
|
|
42
|
+
message: "Decision question names must be unique",
|
|
43
|
+
field: "questions"
|
|
44
|
+
});
|
|
45
|
+
const generate = yield* Generate.Service;
|
|
46
|
+
return { data: yield* generate.decisions(request.payload).pipe(Effect.mapError(generateError)) };
|
|
47
|
+
}, Effect.provide(services), locationErrors2);
|
|
48
|
+
const videoCreate = Effect.fn("server.generate.video.create")(function* (request) {
|
|
49
|
+
return {
|
|
50
|
+
data: yield* videos.start(Generate.videoInput(request.payload)).pipe(Effect.mapError(generateError))
|
|
51
|
+
};
|
|
52
|
+
}, Effect.provide(services), locationErrors2);
|
|
53
|
+
const videoGet = Effect.fn("server.generate.video.get")(function* (request) {
|
|
54
|
+
const job = yield* videos.get(request.params.id).pipe(Effect.mapError((error) => new VideoNotFoundError({ videoID: error.id, message: error.message })));
|
|
55
|
+
return { data: job };
|
|
56
|
+
}, Effect.provide(services), locationErrors2);
|
|
57
|
+
return handlers.handle("generate.text", text).handle("generate.textLegacy", text).handle("generate.image", image).handle("generate.decisions", decisions).handle("generate.video.create", videoCreate).handle("generate.video.get", videoGet);
|
|
58
|
+
}));
|
|
59
|
+
function generateError(error) {
|
|
60
|
+
switch (error._tag) {
|
|
61
|
+
case "Generate.ModelNotFoundError":
|
|
62
|
+
return new ModelNotFoundError({ providerID: error.providerID, modelID: error.modelID, message: error.message });
|
|
63
|
+
case "Generate.UnsupportedModelError":
|
|
64
|
+
return new UnsupportedModelError({
|
|
65
|
+
providerID: error.providerID,
|
|
66
|
+
modelID: error.modelID,
|
|
67
|
+
capability: error.capability,
|
|
68
|
+
message: error.message
|
|
69
|
+
});
|
|
70
|
+
case "Generate.InvalidRequestError":
|
|
71
|
+
return new InvalidRequestError({
|
|
72
|
+
message: error.message,
|
|
73
|
+
...error.field === undefined ? {} : { field: error.field }
|
|
74
|
+
});
|
|
75
|
+
case "Generate.ProviderRequestError":
|
|
76
|
+
return new ProviderRequestError({
|
|
77
|
+
providerID: error.providerID,
|
|
78
|
+
reason: error.reason,
|
|
79
|
+
message: error.message,
|
|
80
|
+
...error.status === undefined ? {} : { status: error.status },
|
|
81
|
+
...error.retryAfterMs === undefined ? {} : { retryAfterMs: error.retryAfterMs }
|
|
82
|
+
});
|
|
83
|
+
case "Generate.UnavailableError":
|
|
84
|
+
return new ServiceUnavailableError({
|
|
85
|
+
message: error.message,
|
|
86
|
+
...error.service === undefined ? {} : { service: error.service }
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export { GenerateHandler2 };
|