@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,70 @@
|
|
|
1
|
+
import {
|
|
2
|
+
response2
|
|
3
|
+
} from "./api-0q8mvh3b.js";
|
|
4
|
+
import {
|
|
5
|
+
Api2
|
|
6
|
+
} from "./api-f6955nmc.js";
|
|
7
|
+
|
|
8
|
+
// src/handlers/plugin.ts
|
|
9
|
+
import { Plugin } from "@radheim/core/plugin";
|
|
10
|
+
import { PluginUpdate } from "@radheim/core/plugin/update";
|
|
11
|
+
import { InvalidRequestError, PluginNotFoundError, ServiceUnavailableError } from "@radheim/protocol/errors";
|
|
12
|
+
import { Cause, Effect, Exit } from "effect";
|
|
13
|
+
import { HttpApiBuilder } from "effect/http-api";
|
|
14
|
+
var PluginHandler2 = HttpApiBuilder.group(Api2, "server.plugin", (handlers) => handlers.handle("plugin.list", () => Effect.gen(function* () {
|
|
15
|
+
return yield* response2(Plugin.Service.use((plugin) => plugin.list()));
|
|
16
|
+
})).handle("plugin.gui", (ctx) => Effect.gen(function* () {
|
|
17
|
+
const plugins = yield* Plugin.Service;
|
|
18
|
+
const bundle = yield* plugins.gui(ctx.query.id);
|
|
19
|
+
if (!bundle)
|
|
20
|
+
return yield* new PluginNotFoundError({
|
|
21
|
+
pluginID: ctx.query.id,
|
|
22
|
+
message: `No active plugin with a ./gui-experimental bundle: ${ctx.query.id}`
|
|
23
|
+
});
|
|
24
|
+
return yield* response2(Effect.succeed(bundle));
|
|
25
|
+
})).handle("plugin.check", (ctx) => Effect.gen(function* () {
|
|
26
|
+
const plugins = yield* Plugin.Service;
|
|
27
|
+
const inventory = yield* plugins.list();
|
|
28
|
+
const targets = [
|
|
29
|
+
...new Set(inventory.flatMap((plugin) => plugin.source.type === "package" ? [plugin.source.target] : []))
|
|
30
|
+
].filter((target) => ctx.payload.target === undefined || target === ctx.payload.target);
|
|
31
|
+
if (ctx.payload.target !== undefined && !targets.length)
|
|
32
|
+
return yield* new InvalidRequestError({
|
|
33
|
+
message: `Plugin package is not in the current server inventory: ${ctx.payload.target}`,
|
|
34
|
+
field: "target"
|
|
35
|
+
});
|
|
36
|
+
const updates = yield* PluginUpdate.Service;
|
|
37
|
+
const outdated = new Map(yield* Effect.forEach(targets, (target) => updates.check(target, { refresh: true }).pipe(Effect.map((value) => [target, value])), { concurrency: "unbounded" }));
|
|
38
|
+
return yield* response2(Effect.succeed(inventory.map((plugin) => {
|
|
39
|
+
if (plugin.source.type !== "package" || !outdated.has(plugin.source.target))
|
|
40
|
+
return plugin;
|
|
41
|
+
return {
|
|
42
|
+
...plugin,
|
|
43
|
+
source: {
|
|
44
|
+
type: "package",
|
|
45
|
+
target: plugin.source.target,
|
|
46
|
+
...plugin.source.version ? { version: plugin.source.version } : {},
|
|
47
|
+
...outdated.get(plugin.source.target) ? { outdated: true } : {},
|
|
48
|
+
...plugin.source.updating ? { updating: true } : {}
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
})));
|
|
52
|
+
})).handle("plugin.update", (ctx) => Effect.gen(function* () {
|
|
53
|
+
const plugins = yield* Plugin.Service;
|
|
54
|
+
const inventory = new Set((yield* plugins.list()).flatMap((plugin) => plugin.source.type === "package" ? [plugin.source.target] : []));
|
|
55
|
+
const unknown = ctx.payload.targets.filter((target) => !inventory.has(target));
|
|
56
|
+
if (unknown.length)
|
|
57
|
+
return yield* new InvalidRequestError({
|
|
58
|
+
message: `Plugin packages are not in the current server inventory: ${unknown.join(", ")}`,
|
|
59
|
+
field: "targets"
|
|
60
|
+
});
|
|
61
|
+
const updates = yield* PluginUpdate.Service;
|
|
62
|
+
const failures = yield* Effect.forEach(ctx.payload.targets, (target) => updates.update(target).pipe(Effect.exit, Effect.map((exit) => Exit.isFailure(exit) ? [`${target}: ${Cause.pretty(exit.cause)}`] : [])), { concurrency: "unbounded" }).pipe(Effect.map((results) => results.flat()));
|
|
63
|
+
if (failures.length)
|
|
64
|
+
return yield* new ServiceUnavailableError({
|
|
65
|
+
message: `Failed to update plugin packages: ${failures.join("; ")}`,
|
|
66
|
+
service: "plugin"
|
|
67
|
+
});
|
|
68
|
+
})));
|
|
69
|
+
|
|
70
|
+
export { PluginHandler2 };
|
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
import {
|
|
2
|
+
__export
|
|
3
|
+
} from "./api-9rqn6x4v.js";
|
|
4
|
+
|
|
5
|
+
// src/space-store.ts
|
|
6
|
+
var exports_space_store = {};
|
|
7
|
+
__export(exports_space_store, {
|
|
8
|
+
BatchSize: () => BatchSize2,
|
|
9
|
+
PurgeInterval: () => PurgeInterval2,
|
|
10
|
+
Service: () => Service3,
|
|
11
|
+
SpaceStore: () => exports_space_store,
|
|
12
|
+
extension: () => extension2,
|
|
13
|
+
node: () => node2
|
|
14
|
+
});
|
|
15
|
+
import { SpaceRows } from "@radheim/core/space";
|
|
16
|
+
import { Database } from "@radheim/core/database/database";
|
|
17
|
+
import { KeyedMutex } from "@radheim/core/effect/keyed-mutex";
|
|
18
|
+
import { Space } from "@radheim/schema/space";
|
|
19
|
+
import { Event } from "@radheim/schema/event";
|
|
20
|
+
import { makeGlobalNode } from "@radheim/util/effect/app-node";
|
|
21
|
+
import { Clock, Context, Effect, Layer } from "effect";
|
|
22
|
+
var BatchSize2 = 500;
|
|
23
|
+
var PurgeInterval2 = 64;
|
|
24
|
+
|
|
25
|
+
class Service3 extends Context.Service()("@radheim/server/SpaceStore") {
|
|
26
|
+
}
|
|
27
|
+
var layer = Layer.effect(Service3, Effect.gen(function* () {
|
|
28
|
+
const db = (yield* Database.Service).db;
|
|
29
|
+
let epoch = yield* SpaceRows.epoch(db).pipe(Effect.catchCause((cause) => Effect.logWarning("Could not read the space epoch", { cause }).pipe(Effect.as(crypto.randomUUID()))));
|
|
30
|
+
const listeners = new Array;
|
|
31
|
+
const locks = KeyedMutex.makeUnsafe();
|
|
32
|
+
const deletes = new Map;
|
|
33
|
+
const tombstoned = (space, count) => Effect.suspend(() => {
|
|
34
|
+
if (count === 0)
|
|
35
|
+
return Effect.void;
|
|
36
|
+
const since = (deletes.get(space) ?? PurgeInterval2 - 1) + count;
|
|
37
|
+
if (since < PurgeInterval2)
|
|
38
|
+
return Effect.sync(() => deletes.set(space, since));
|
|
39
|
+
return SpaceRows.purge(db, space).pipe(Effect.andThen(Effect.sync(() => deletes.set(space, 0))), Effect.catchCause((cause) => Effect.logWarning("Could not purge space tombstones", { space, cause })));
|
|
40
|
+
});
|
|
41
|
+
const streams = new Map;
|
|
42
|
+
const deliver = (stream, change) => Effect.suspend(() => {
|
|
43
|
+
const subscription = stream.spaces.get(change.data.space);
|
|
44
|
+
if (!subscription)
|
|
45
|
+
return Effect.void;
|
|
46
|
+
if (subscription.pending) {
|
|
47
|
+
subscription.pending.push(change);
|
|
48
|
+
return Effect.void;
|
|
49
|
+
}
|
|
50
|
+
return change.data.revision > subscription.covered ? stream.send(change) : Effect.void;
|
|
51
|
+
});
|
|
52
|
+
const page = (space, cursor, limit) => Effect.gen(function* () {
|
|
53
|
+
const position = cursor === undefined ? undefined : parse(epoch, cursor);
|
|
54
|
+
const from = position?.head === undefined ? position ? { type: "delta", since: position.since, snapshot: true } : { type: "snapshot", since: 0 } : position.since > position.head ? { type: "snapshot", since: 0 } : { type: "snapshot", since: position.since, until: position.head };
|
|
55
|
+
const read = yield* SpaceRows.read(db, space, from, limit + 1);
|
|
56
|
+
const more = read.rows.length > limit;
|
|
57
|
+
const kept = read.rows.slice(0, limit);
|
|
58
|
+
if (read.continued && from.type === "delta") {
|
|
59
|
+
const revision = kept.at(-1)?.revision ?? from.since;
|
|
60
|
+
const delta = {
|
|
61
|
+
type: "delta",
|
|
62
|
+
space,
|
|
63
|
+
epoch,
|
|
64
|
+
revision,
|
|
65
|
+
entries: entries(kept),
|
|
66
|
+
deleted: deleted(kept),
|
|
67
|
+
cursor: `${epoch}.${revision}`,
|
|
68
|
+
next: more ? `${epoch}.${revision}` : undefined
|
|
69
|
+
};
|
|
70
|
+
return delta;
|
|
71
|
+
}
|
|
72
|
+
const since = read.continued ? from.since : 0;
|
|
73
|
+
const until = read.continued && from.type === "snapshot" ? from.until ?? read.head : read.head;
|
|
74
|
+
const revision = more ? kept.at(-1)?.revision ?? since : until;
|
|
75
|
+
const snapshot = {
|
|
76
|
+
type: "snapshot",
|
|
77
|
+
space,
|
|
78
|
+
epoch,
|
|
79
|
+
revision,
|
|
80
|
+
entries: entries(kept),
|
|
81
|
+
cursor: `${epoch}.${revision}`,
|
|
82
|
+
next: more ? `${epoch}.${revision}.${until}` : read.head > until ? `${epoch}.${until}` : undefined
|
|
83
|
+
};
|
|
84
|
+
return snapshot;
|
|
85
|
+
});
|
|
86
|
+
const catchUp = (space, cursor, budget) => Effect.gen(function* () {
|
|
87
|
+
const position = parse(epoch, cursor);
|
|
88
|
+
const created = yield* Clock.currentTimeMillis;
|
|
89
|
+
const resync = (read) => ({
|
|
90
|
+
covered: 0,
|
|
91
|
+
read,
|
|
92
|
+
events: [{ id: Event.ID.create(), created, type: Space.Event.Resync.type, data: { space } }]
|
|
93
|
+
});
|
|
94
|
+
if (budget === 0 || !position || position.head !== undefined)
|
|
95
|
+
return resync(0);
|
|
96
|
+
const read = yield* SpaceRows.read(db, space, { type: "delta", since: position.since, snapshot: false }, budget + 1);
|
|
97
|
+
if (!read.continued || read.rows.length > budget)
|
|
98
|
+
return resync(read.rows.length);
|
|
99
|
+
return {
|
|
100
|
+
covered: read.rows.at(-1)?.revision ?? position.since,
|
|
101
|
+
read: read.rows.length,
|
|
102
|
+
events: read.rows.map((row) => change(space, row, created))
|
|
103
|
+
};
|
|
104
|
+
});
|
|
105
|
+
return Service3.of({
|
|
106
|
+
write: Effect.fn("SpaceStore.write")(function* (changes) {
|
|
107
|
+
return yield* [...new Set(changes.map((change) => change.space))].toSorted().reduceRight((effect, space) => locks.withLock(space)(effect), Effect.uninterruptible(Effect.gen(function* () {
|
|
108
|
+
const result = yield* SpaceRows.write(db, changes);
|
|
109
|
+
const tombstones = Map.groupBy(result.written.filter((row) => row.value === null), (row) => row.space);
|
|
110
|
+
yield* Effect.forEach(tombstones, ([space, rows]) => tombstoned(space, rows.length), { discard: true });
|
|
111
|
+
const created = yield* Clock.currentTimeMillis;
|
|
112
|
+
for (const row of result.written) {
|
|
113
|
+
const committed = change(row.space, row, created);
|
|
114
|
+
yield* Effect.forEach(listeners, (listener) => listener(committed), { discard: true });
|
|
115
|
+
yield* Effect.forEach(streams.values(), (stream) => deliver(stream, committed), { discard: true });
|
|
116
|
+
}
|
|
117
|
+
return result.heads.map((head) => ({ ...head, cursor: `${epoch}.${head.revision}` }));
|
|
118
|
+
})));
|
|
119
|
+
}),
|
|
120
|
+
get epoch() {
|
|
121
|
+
return epoch;
|
|
122
|
+
},
|
|
123
|
+
resetEpoch: Effect.fn("SpaceStore.resetEpoch")(function* () {
|
|
124
|
+
epoch = yield* SpaceRows.resetEpoch(db);
|
|
125
|
+
})(),
|
|
126
|
+
sync: Effect.fn("SpaceStore.sync")(function* (requests) {
|
|
127
|
+
const pages = new Array;
|
|
128
|
+
let budget = BatchSize2;
|
|
129
|
+
for (const request of requests) {
|
|
130
|
+
if (budget === 0)
|
|
131
|
+
break;
|
|
132
|
+
const next = yield* page(request.space, request.cursor, budget);
|
|
133
|
+
budget -= next.entries.length + (next.type === "delta" ? next.deleted.length : 0);
|
|
134
|
+
pages.push(next);
|
|
135
|
+
}
|
|
136
|
+
return pages;
|
|
137
|
+
}),
|
|
138
|
+
attach: (id, send) => Effect.acquireRelease(Effect.sync(() => streams.set(id, { send, spaces: new Map })), () => Effect.sync(() => streams.delete(id))).pipe(Effect.asVoid),
|
|
139
|
+
subscribe: Effect.fn("SpaceStore.subscribe")(function* (id, requests) {
|
|
140
|
+
const stream = streams.get(id);
|
|
141
|
+
if (!stream)
|
|
142
|
+
return false;
|
|
143
|
+
const subscriptions = requests.map((request) => {
|
|
144
|
+
const subscription = { covered: 0, pending: [] };
|
|
145
|
+
stream.spaces.set(request.space, subscription);
|
|
146
|
+
return { request, subscription };
|
|
147
|
+
});
|
|
148
|
+
let budget = BatchSize2;
|
|
149
|
+
yield* Effect.forEach(subscriptions, ({ request, subscription }) => Effect.gen(function* () {
|
|
150
|
+
const current = () => stream.spaces.get(request.space) === subscription;
|
|
151
|
+
const first = yield* catchUp(request.space, request.cursor, budget);
|
|
152
|
+
budget = Math.max(0, budget - first.read);
|
|
153
|
+
if (!subscription.pending)
|
|
154
|
+
return;
|
|
155
|
+
subscription.covered = first.covered;
|
|
156
|
+
for (const event of first.events)
|
|
157
|
+
if (current())
|
|
158
|
+
yield* stream.send(event);
|
|
159
|
+
for (let change = subscription.pending.shift();change && current(); change = subscription.pending.shift())
|
|
160
|
+
if (change.data.revision > subscription.covered)
|
|
161
|
+
yield* stream.send(change);
|
|
162
|
+
subscription.pending = undefined;
|
|
163
|
+
}), { discard: true }).pipe(Effect.ensuring(Effect.sync(() => {
|
|
164
|
+
for (const { request, subscription } of subscriptions)
|
|
165
|
+
if (subscription.pending && stream.spaces.get(request.space) === subscription)
|
|
166
|
+
stream.spaces.delete(request.space);
|
|
167
|
+
})));
|
|
168
|
+
return true;
|
|
169
|
+
}),
|
|
170
|
+
unsubscribe: (id, spaces) => Effect.sync(() => {
|
|
171
|
+
const stream = streams.get(id);
|
|
172
|
+
for (const space of spaces)
|
|
173
|
+
stream?.spaces.delete(space);
|
|
174
|
+
return stream !== undefined;
|
|
175
|
+
}),
|
|
176
|
+
listen: (listener) => Effect.sync(() => {
|
|
177
|
+
listeners.push(listener);
|
|
178
|
+
return Effect.sync(() => {
|
|
179
|
+
const index = listeners.indexOf(listener);
|
|
180
|
+
if (index >= 0)
|
|
181
|
+
listeners.splice(index, 1);
|
|
182
|
+
});
|
|
183
|
+
})
|
|
184
|
+
});
|
|
185
|
+
}));
|
|
186
|
+
var node2 = makeGlobalNode({ service: Service3, layer, deps: [Database.node] });
|
|
187
|
+
var extension2 = Effect.gen(function* () {
|
|
188
|
+
const store = yield* Service3;
|
|
189
|
+
return { open: (stream, send) => store.attach(stream, send) };
|
|
190
|
+
});
|
|
191
|
+
function change(space, row, created) {
|
|
192
|
+
return row.value === null ? {
|
|
193
|
+
id: Event.ID.create(),
|
|
194
|
+
created,
|
|
195
|
+
type: Space.Event.Deleted.type,
|
|
196
|
+
data: { space, key: row.key, revision: row.revision }
|
|
197
|
+
} : {
|
|
198
|
+
id: Event.ID.create(),
|
|
199
|
+
created,
|
|
200
|
+
type: Space.Event.Updated.type,
|
|
201
|
+
data: { space, key: row.key, value: row.value, revision: row.revision }
|
|
202
|
+
};
|
|
203
|
+
}
|
|
204
|
+
function entries(rows) {
|
|
205
|
+
return rows.flatMap((row) => row.value === null ? [] : [{ key: row.key, value: row.value }]);
|
|
206
|
+
}
|
|
207
|
+
function deleted(rows) {
|
|
208
|
+
return rows.flatMap((row) => row.value === null ? [row.key] : []);
|
|
209
|
+
}
|
|
210
|
+
function parse(epoch, cursor) {
|
|
211
|
+
if (!cursor.startsWith(`${epoch}.`))
|
|
212
|
+
return;
|
|
213
|
+
const parts = cursor.slice(epoch.length + 1).split(".");
|
|
214
|
+
if (parts.length > 2 || !parts.every((part) => /^\d+$/u.test(part) && Number.isSafeInteger(Number(part))))
|
|
215
|
+
return;
|
|
216
|
+
return { since: Number(parts[0]), head: parts[1] === undefined ? undefined : Number(parts[1]) };
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
export { BatchSize2, PurgeInterval2, Service3, node2, extension2, exports_space_store };
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import {
|
|
2
|
+
response2
|
|
3
|
+
} from "./api-0q8mvh3b.js";
|
|
4
|
+
import {
|
|
5
|
+
Api2
|
|
6
|
+
} from "./api-f6955nmc.js";
|
|
7
|
+
|
|
8
|
+
// src/handlers/shell.ts
|
|
9
|
+
import { Shell } from "@radheim/core/shell";
|
|
10
|
+
import { Location } from "@radheim/core/location";
|
|
11
|
+
import { Effect } from "effect";
|
|
12
|
+
import { HttpApiBuilder, HttpApiSchema } from "effect/http-api";
|
|
13
|
+
import { ServiceUnavailableError, ShellNotFoundError } from "@radheim/protocol/errors";
|
|
14
|
+
var ShellHandler2 = HttpApiBuilder.group(Api2, "server.shell", (handlers) => Effect.gen(function* () {
|
|
15
|
+
return handlers.handle("shell.list", Effect.fnUntraced(function* () {
|
|
16
|
+
const shell = yield* Shell.Service;
|
|
17
|
+
return yield* response2(shell.list());
|
|
18
|
+
})).handle("shell.create", Effect.fnUntraced(function* (ctx) {
|
|
19
|
+
const shell = yield* Shell.Service;
|
|
20
|
+
const location = yield* Location.Service;
|
|
21
|
+
return yield* response2(shell.create({ ...ctx.payload, cwd: ctx.payload.cwd || location.directory }).pipe(Effect.mapError((error) => new ServiceUnavailableError({ message: error.message, service: "shell" }))));
|
|
22
|
+
})).handle("shell.get", Effect.fnUntraced(function* (ctx) {
|
|
23
|
+
const shell = yield* Shell.Service;
|
|
24
|
+
return yield* response2(shell.get(ctx.params.id).pipe(Effect.catchTag("Shell.NotFoundError", () => new ShellNotFoundError({ id: ctx.params.id, message: `Shell command not found: ${ctx.params.id}` }))));
|
|
25
|
+
})).handle("shell.output", Effect.fnUntraced(function* (ctx) {
|
|
26
|
+
const shell = yield* Shell.Service;
|
|
27
|
+
return yield* response2(shell.output(ctx.params.id, { cursor: ctx.query.cursor, limit: ctx.query.limit }).pipe(Effect.catchTag("Shell.NotFoundError", () => new ShellNotFoundError({ id: ctx.params.id, message: `Shell command not found: ${ctx.params.id}` }))));
|
|
28
|
+
})).handle("shell.remove", Effect.fnUntraced(function* (ctx) {
|
|
29
|
+
const shell = yield* Shell.Service;
|
|
30
|
+
yield* shell.remove(ctx.params.id).pipe(Effect.catchTag("Shell.NotFoundError", () => Effect.void));
|
|
31
|
+
return HttpApiSchema.NoContent.make();
|
|
32
|
+
}));
|
|
33
|
+
}));
|
|
34
|
+
|
|
35
|
+
export { ShellHandler2 };
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import {
|
|
2
|
+
locationErrors2
|
|
3
|
+
} from "./api-0q8mvh3b.js";
|
|
4
|
+
import {
|
|
5
|
+
Api2
|
|
6
|
+
} from "./api-f6955nmc.js";
|
|
7
|
+
|
|
8
|
+
// src/handlers/voice.ts
|
|
9
|
+
import { Location } from "@radheim/core/location";
|
|
10
|
+
import { LocationServiceMap } from "@radheim/core/location-services";
|
|
11
|
+
import { AbsolutePath } from "@radheim/core/schema";
|
|
12
|
+
import { Voice } from "@radheim/core/voice";
|
|
13
|
+
import { InvalidRequestError, ServiceUnavailableError } from "@radheim/protocol/errors";
|
|
14
|
+
import { Global } from "@radheim/util/global";
|
|
15
|
+
import { Effect } from "effect";
|
|
16
|
+
import { HttpApiBuilder } from "effect/http-api";
|
|
17
|
+
var VoiceHandler2 = HttpApiBuilder.group(Api2, "server.voice", (handlers) => Effect.gen(function* () {
|
|
18
|
+
const global = yield* Global.Service;
|
|
19
|
+
const locations = yield* LocationServiceMap.Service;
|
|
20
|
+
const services = locations.get(Location.Ref.make({ directory: AbsolutePath.make(global.config) }));
|
|
21
|
+
return handlers.handle("voice.models", Effect.fn("server.voice.models")(function* () {
|
|
22
|
+
const voice = yield* Voice.Service;
|
|
23
|
+
return { data: yield* voice.models() };
|
|
24
|
+
}, Effect.provide(services), locationErrors2)).handle("voice.session", Effect.fn("server.voice.session")(function* (request) {
|
|
25
|
+
const voice = yield* Voice.Service;
|
|
26
|
+
const transport = yield* voice.session(request.payload).pipe(Effect.mapError((error) => error._tag === "Voice.InvalidRequestError" ? new InvalidRequestError({ message: error.message }) : new ServiceUnavailableError({ message: error.message, service: error.service })));
|
|
27
|
+
return { data: { transport } };
|
|
28
|
+
}, Effect.provide(services), locationErrors2));
|
|
29
|
+
}));
|
|
30
|
+
|
|
31
|
+
export { VoiceHandler2 };
|
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
import {
|
|
2
|
+
layer4
|
|
3
|
+
} from "./api-0q8mvh3b.js";
|
|
4
|
+
import {
|
|
5
|
+
formLocationLayer2
|
|
6
|
+
} from "./api-bnpt5zxx.js";
|
|
7
|
+
import {
|
|
8
|
+
sessionLocationLayer2
|
|
9
|
+
} from "./api-5fr63cjn.js";
|
|
10
|
+
import {
|
|
11
|
+
Api2
|
|
12
|
+
} from "./api-f6955nmc.js";
|
|
13
|
+
import {
|
|
14
|
+
Config2
|
|
15
|
+
} from "./api-9qr3r2v1.js";
|
|
16
|
+
import {
|
|
17
|
+
node2
|
|
18
|
+
} from "./api-k0fc7y6c.js";
|
|
19
|
+
import {
|
|
20
|
+
CorsConfig2
|
|
21
|
+
} from "./api-11hx8jza.js";
|
|
22
|
+
import {
|
|
23
|
+
layer2
|
|
24
|
+
} from "./api-wrj46kzw.js";
|
|
25
|
+
import {
|
|
26
|
+
node3
|
|
27
|
+
} from "./api-fpzegjvk.js";
|
|
28
|
+
import {
|
|
29
|
+
MachinesFlag2
|
|
30
|
+
} from "./api-238wcyzf.js";
|
|
31
|
+
import {
|
|
32
|
+
handlers2
|
|
33
|
+
} from "./api-ygxfyj7m.js";
|
|
34
|
+
import {
|
|
35
|
+
authorizationLayer2
|
|
36
|
+
} from "./api-bxwfazps.js";
|
|
37
|
+
import {
|
|
38
|
+
schemaErrorLayer2
|
|
39
|
+
} from "./api-qft4mah5.js";
|
|
40
|
+
import {
|
|
41
|
+
defectResponseLayer2
|
|
42
|
+
} from "./api-bctzdhd7.js";
|
|
43
|
+
|
|
44
|
+
// src/routes.ts
|
|
45
|
+
import { Database } from "@radheim/core/database/database";
|
|
46
|
+
import { V1Migration } from "@radheim/core/database/v1-migration";
|
|
47
|
+
import { App } from "@radheim/core/app";
|
|
48
|
+
import { CodeModeApi } from "@radheim/core/codemode/api";
|
|
49
|
+
import { LayerNode } from "@radheim/util/effect/layer-node";
|
|
50
|
+
import { fetchLayer, httpClient, httpFetch } from "@radheim/util/effect/app-node-platform";
|
|
51
|
+
import { AppNodeBuilder } from "@radheim/core/effect/app-node-builder";
|
|
52
|
+
import { Bus } from "@radheim/core/bus";
|
|
53
|
+
import { EventLogger } from "@radheim/core/event-logger";
|
|
54
|
+
import { FileSystemSearch } from "@radheim/core/filesystem/search";
|
|
55
|
+
import { Credential } from "@radheim/core/credential";
|
|
56
|
+
import { Config } from "@radheim/core/config";
|
|
57
|
+
import { PermissionSaved } from "@radheim/core/permission/saved";
|
|
58
|
+
import { BrowserTunnelGateway } from "@radheim/core/experimental/browser-tunnel";
|
|
59
|
+
import { PtyTicket } from "@radheim/core/pty/ticket";
|
|
60
|
+
import { PersistentPty } from "@radheim/core/persistent-pty";
|
|
61
|
+
import { Project } from "@radheim/core/project";
|
|
62
|
+
import { BlobStore } from "@radheim/core/blob-store";
|
|
63
|
+
import { VideoGeneration } from "@radheim/core/video-generation";
|
|
64
|
+
import { Worktree } from "@radheim/core/worktree";
|
|
65
|
+
import { Session } from "@radheim/core/session";
|
|
66
|
+
import { Instance } from "@radheim/core/instance/service";
|
|
67
|
+
import { SessionTransfer } from "@radheim/core/session/transfer";
|
|
68
|
+
import { InstructionEntry } from "@radheim/core/session/instruction-entry";
|
|
69
|
+
import { ShellSelect } from "@radheim/core/shell/select";
|
|
70
|
+
import { Shell } from "@radheim/core/shell";
|
|
71
|
+
import { Job } from "@radheim/core/job";
|
|
72
|
+
import { KV } from "@radheim/core/kv";
|
|
73
|
+
import { Mcp } from "@radheim/core/mcp/index";
|
|
74
|
+
import { Global } from "@radheim/util/global";
|
|
75
|
+
import { FSUtil } from "@radheim/util/fs-util";
|
|
76
|
+
import { InstructionDiscovery } from "@radheim/core/instruction-discovery";
|
|
77
|
+
import { LocationServiceMap } from "@radheim/core/location-service-map";
|
|
78
|
+
import { LocationActivity } from "@radheim/core/location-activity";
|
|
79
|
+
import { Identity } from "@radheim/core/machine/identity";
|
|
80
|
+
import { Machines } from "@radheim/core/machine/machines";
|
|
81
|
+
import { SessionSearchBuild } from "@radheim/core/session/search-build";
|
|
82
|
+
import { ModelsDev } from "@radheim/core/models-dev";
|
|
83
|
+
import { SessionRestart } from "@radheim/core/session/execution/restart";
|
|
84
|
+
import { Automation } from "@radheim/core/automation";
|
|
85
|
+
import { PluginUpdate } from "@radheim/core/plugin/update";
|
|
86
|
+
import { SdkPlugins } from "@radheim/core/plugin/sdk";
|
|
87
|
+
import { WellKnown } from "@radheim/core/wellknown";
|
|
88
|
+
import { PushList } from "@radheim/core/push/list";
|
|
89
|
+
import { PushSender } from "@radheim/core/push/sender";
|
|
90
|
+
import { PushWatcher } from "@radheim/core/push/watcher";
|
|
91
|
+
import { Workspace } from "@radheim/core/workspace";
|
|
92
|
+
import { WorkspaceConnector } from "@radheim/core/environment/workspace-connector";
|
|
93
|
+
import { Watcher } from "@radheim/core/filesystem/watcher";
|
|
94
|
+
import { FileWatch } from "@radheim/core/filesystem/file-watch";
|
|
95
|
+
import { HttpEffect, HttpRouter } from "effect/http";
|
|
96
|
+
import { HttpApiBuilder } from "effect/http-api";
|
|
97
|
+
import { Context, Effect, Layer, Option } from "effect";
|
|
98
|
+
import { Base64 } from "effect/encoding";
|
|
99
|
+
var applicationServiceNodes = [
|
|
100
|
+
App.node,
|
|
101
|
+
CodeModeApi.node,
|
|
102
|
+
Global.node,
|
|
103
|
+
FSUtil.node,
|
|
104
|
+
Database.node,
|
|
105
|
+
KV.node,
|
|
106
|
+
Bus.node,
|
|
107
|
+
PersistentPty.node,
|
|
108
|
+
Shell.daemonNode,
|
|
109
|
+
EventLogger.node,
|
|
110
|
+
httpClient,
|
|
111
|
+
Job.node,
|
|
112
|
+
Project.node,
|
|
113
|
+
Project.sweepNode,
|
|
114
|
+
Worktree.node,
|
|
115
|
+
Session.node,
|
|
116
|
+
Instance.node,
|
|
117
|
+
SessionTransfer.node,
|
|
118
|
+
InstructionEntry.node,
|
|
119
|
+
SdkPlugins.node,
|
|
120
|
+
PluginUpdate.node,
|
|
121
|
+
PermissionSaved.node,
|
|
122
|
+
PtyTicket.node,
|
|
123
|
+
BrowserTunnelGateway.node,
|
|
124
|
+
Credential.node,
|
|
125
|
+
WellKnown.node,
|
|
126
|
+
node3,
|
|
127
|
+
node2,
|
|
128
|
+
LocationServiceMap.node,
|
|
129
|
+
LocationActivity.node,
|
|
130
|
+
SessionRestart.node,
|
|
131
|
+
Automation.node,
|
|
132
|
+
BlobStore.node,
|
|
133
|
+
VideoGeneration.node,
|
|
134
|
+
SessionSearchBuild.node,
|
|
135
|
+
Workspace.node,
|
|
136
|
+
Machines.node,
|
|
137
|
+
MachinesFlag2.node,
|
|
138
|
+
Identity.node,
|
|
139
|
+
FileWatch.node,
|
|
140
|
+
PushList.node,
|
|
141
|
+
PushSender.node,
|
|
142
|
+
PushWatcher.node
|
|
143
|
+
];
|
|
144
|
+
var applicationServices = LayerNode.group(applicationServiceNodes);
|
|
145
|
+
function createRoutes2(options = {}, serviceURLs = () => [], overrides = []) {
|
|
146
|
+
return makeRoutes(options.password ? Option.some(options.password) : Option.none(), options, serviceURLs, overrides);
|
|
147
|
+
}
|
|
148
|
+
function createEmbeddedRoutes2(options = {}, overrides = [], instances) {
|
|
149
|
+
return makeRoutes(Option.none(), options, () => [], instances ? [Instance.node.replace(instances), ...overrides] : overrides);
|
|
150
|
+
}
|
|
151
|
+
function makeRoutes(password, options, serviceURLs, overrides) {
|
|
152
|
+
const auth = Config2.configLayer({ password });
|
|
153
|
+
const credential = Option.map(password, (value) => `Basic ${Base64.encode(`opencode:${value}`)}`);
|
|
154
|
+
let internal;
|
|
155
|
+
const standard = [
|
|
156
|
+
CodeModeApi.node.replace(Layer.succeed(CodeModeApi.Service, CodeModeApi.Service.of({
|
|
157
|
+
fetch: (request) => Effect.suspend(() => {
|
|
158
|
+
const handle = internal;
|
|
159
|
+
if (!handle)
|
|
160
|
+
return Effect.fail(new Error("The OpenCode API is not ready yet."));
|
|
161
|
+
if (Option.isSome(credential))
|
|
162
|
+
request.headers.set("authorization", credential.value);
|
|
163
|
+
return Effect.tryPromise({
|
|
164
|
+
try: () => handle(request),
|
|
165
|
+
catch: (error) => error instanceof Error ? error : new Error(String(error))
|
|
166
|
+
});
|
|
167
|
+
})
|
|
168
|
+
}))),
|
|
169
|
+
Database.node.replace(Database.configured(options.database)),
|
|
170
|
+
WorkspaceConnector.node.replace(Workspace.connectorNode),
|
|
171
|
+
PersistentPty.node.replace(PersistentPty.configured(options.pty)),
|
|
172
|
+
Bus.node.replace(Bus.configured({ persist: options.events?.persist })),
|
|
173
|
+
App.node.replace(App.configured(options.app)),
|
|
174
|
+
ModelsDev.node.replace(ModelsDev.configured(options.models)),
|
|
175
|
+
PushList.node.replace(PushList.configured(options.experimental?.push)),
|
|
176
|
+
httpFetch.replace(fetchLayer(options.fetch)),
|
|
177
|
+
Watcher.node.replace(Watcher.configured({ enabled: options.fs?.filewatcher })),
|
|
178
|
+
FileWatch.node.replace(FileWatch.configured({ enabled: options.fs?.filewatcher })),
|
|
179
|
+
FileSystemSearch.node.replace(FileSystemSearch.configured({ fff: options.fs?.fff })),
|
|
180
|
+
Global.node.replace(Global.layerWith(options.config?.directory ? { config: options.config.directory } : {})),
|
|
181
|
+
Config.node.replace(Config.configured({
|
|
182
|
+
project: options.config?.project,
|
|
183
|
+
claude: options.config?.claude,
|
|
184
|
+
file: options.config?.file,
|
|
185
|
+
content: options.config?.content
|
|
186
|
+
})),
|
|
187
|
+
InstructionDiscovery.node.replace(InstructionDiscovery.configured({
|
|
188
|
+
project: options.config?.project,
|
|
189
|
+
claude: options.instructions?.claude
|
|
190
|
+
})),
|
|
191
|
+
ShellSelect.node.replace(ShellSelect.configured({ gitbash: options.windows?.gitbash })),
|
|
192
|
+
Mcp.node.replace(Mcp.configured({
|
|
193
|
+
clientInfo: {
|
|
194
|
+
name: "opencode",
|
|
195
|
+
version: options.app?.version ?? "unknown"
|
|
196
|
+
}
|
|
197
|
+
}))
|
|
198
|
+
];
|
|
199
|
+
const build = (overrides) => AppNodeBuilder.build(applicationServices, [...standard, ...overrides]);
|
|
200
|
+
const serviceLayer = options.simulation ? Layer.unwrap(Effect.gen(function* () {
|
|
201
|
+
const { simulationReplacements } = yield* Effect.promise(() => import("@radheim/simulation/backend"));
|
|
202
|
+
const simulation = yield* simulationReplacements({ version: App.make(options.app).version });
|
|
203
|
+
return build([...overrides, ...simulation]);
|
|
204
|
+
})) : build(overrides);
|
|
205
|
+
return serviceLayer.pipe(Layer.flatMap((context) => {
|
|
206
|
+
const services = Layer.succeedContext(context);
|
|
207
|
+
const requestServices = Layer.merge(Layer.succeedContext(Context.pick(Database.Service, Credential.Service, PermissionSaved.Service, PluginUpdate.Service, Project.Service, WellKnown.Service)(context)), layer2(serviceURLs, Context.get(context, Global.Service).tmp, options.app));
|
|
208
|
+
const api = HttpApiBuilder.layer(Api2, { openapiPath: "/openapi.json" }).pipe(Layer.provide(handlers2.pipe(Layer.provide(services), Layer.provide(Layer.succeed(CorsConfig2, options)))), Layer.provide(formLocationLayer2), Layer.provide(sessionLocationLayer2), Layer.provide(layer4), Layer.provide(authorizationLayer2), Layer.provide(schemaErrorLayer2), Layer.provide(auth), HttpRouter.provideRequest(requestServices), Layer.merge(defectResponseLayer2), Layer.provideMerge(services), Layer.provideMerge(HttpRouter.layer.pipe(Layer.provide(Layer.succeed(HttpRouter.RouterConfig)({ maxParamLength: 512 })))), Layer.tap((context) => Effect.sync(() => {
|
|
209
|
+
internal = Context.get(context, HttpRouter.HttpRouter).asHttpEffect().pipe(HttpEffect.toWebHandlerWith(context));
|
|
210
|
+
})));
|
|
211
|
+
return Layer.merge(api, V1Migration.layer.pipe(Layer.provide(services)));
|
|
212
|
+
}));
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
export { createRoutes2, createEmbeddedRoutes2 };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import {
|
|
2
|
+
response2
|
|
3
|
+
} from "./api-0q8mvh3b.js";
|
|
4
|
+
import {
|
|
5
|
+
Api2
|
|
6
|
+
} from "./api-f6955nmc.js";
|
|
7
|
+
|
|
8
|
+
// src/handlers/agent.ts
|
|
9
|
+
import { Agent } from "@radheim/core/agent";
|
|
10
|
+
import { Effect } from "effect";
|
|
11
|
+
import { HttpApiBuilder } from "effect/http-api";
|
|
12
|
+
import { AgentNotFoundError } from "@radheim/protocol/errors";
|
|
13
|
+
var AgentHandler2 = HttpApiBuilder.group(Api2, "server.agent", (handlers) => handlers.handle("agent.list", () => response2(Agent.Service.use((agent) => agent.list()))).handle("agent.get", Effect.fnUntraced(function* (ctx) {
|
|
14
|
+
const agent = yield* Agent.Service.use((service) => service.get(ctx.params.agentID));
|
|
15
|
+
if (!agent)
|
|
16
|
+
return yield* new AgentNotFoundError({
|
|
17
|
+
agentID: ctx.params.agentID,
|
|
18
|
+
message: `Agent not found: ${ctx.params.agentID}`
|
|
19
|
+
});
|
|
20
|
+
return yield* response2(Effect.succeed(agent));
|
|
21
|
+
})));
|
|
22
|
+
|
|
23
|
+
export { AgentHandler2 };
|