@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,348 @@
|
|
|
1
|
+
import {
|
|
2
|
+
missingSession2,
|
|
3
|
+
skillLoadFailed2,
|
|
4
|
+
missingMessage2,
|
|
5
|
+
failedMessageDecode2,
|
|
6
|
+
failedSnapshot2
|
|
7
|
+
} from "./api-ghyd9ren.js";
|
|
8
|
+
import {
|
|
9
|
+
locationErrors2
|
|
10
|
+
} from "./api-0q8mvh3b.js";
|
|
11
|
+
import {
|
|
12
|
+
Api2
|
|
13
|
+
} from "./api-f6955nmc.js";
|
|
14
|
+
import {
|
|
15
|
+
wantsMediaRefs2
|
|
16
|
+
} from "./api-xthc02cw.js";
|
|
17
|
+
|
|
18
|
+
// src/handlers/session.ts
|
|
19
|
+
import { Instance } from "@radheim/core/instance/service";
|
|
20
|
+
import { Session } from "@radheim/core/session";
|
|
21
|
+
import { SessionStats } from "@radheim/core/session/stats";
|
|
22
|
+
import { SessionTitle } from "@radheim/core/session/title";
|
|
23
|
+
import { SessionTransfer } from "@radheim/core/session/transfer";
|
|
24
|
+
import { InstructionEntry } from "@radheim/core/session/instruction-entry";
|
|
25
|
+
import { Form } from "@radheim/core/form";
|
|
26
|
+
import { DateTime, Effect, Stream } from "effect";
|
|
27
|
+
import { HttpServerResponse } from "effect/http";
|
|
28
|
+
import { HttpApiBuilder, HttpApiSchema } from "effect/http-api";
|
|
29
|
+
import { SessionMediaMessageResponse } from "@radheim/protocol/groups/message";
|
|
30
|
+
import { SessionMediaInboxResponse } from "@radheim/protocol/groups/session";
|
|
31
|
+
import {
|
|
32
|
+
ConflictError,
|
|
33
|
+
CommandExecutionError,
|
|
34
|
+
CommandNotFoundError,
|
|
35
|
+
FormAlreadySettledError,
|
|
36
|
+
FormInvalidAnswerError,
|
|
37
|
+
FormNotFoundError,
|
|
38
|
+
InvalidRequestError,
|
|
39
|
+
InvalidCursorError,
|
|
40
|
+
MessageNotFoundError,
|
|
41
|
+
ServiceUnavailableError,
|
|
42
|
+
SessionBusyError,
|
|
43
|
+
SkillNotFoundError
|
|
44
|
+
} from "@radheim/protocol/errors";
|
|
45
|
+
import { AbsolutePath } from "@radheim/core/schema";
|
|
46
|
+
function missingForm(id) {
|
|
47
|
+
return new FormNotFoundError({ id, message: `Form not found: ${id}` });
|
|
48
|
+
}
|
|
49
|
+
var SessionHandler2 = HttpApiBuilder.group(Api2, "server.session", (handlers) => Effect.gen(function* () {
|
|
50
|
+
const session = yield* Session.Service;
|
|
51
|
+
const transfer = yield* SessionTransfer.Service;
|
|
52
|
+
const instructions = yield* InstructionEntry.Service;
|
|
53
|
+
const instances = yield* Instance.Service;
|
|
54
|
+
const requireSession = (sessionID) => session.get(sessionID).pipe(Effect.catchTag("Session.NotFoundError", missingSession2));
|
|
55
|
+
const requireOwnedForm = Effect.fnUntraced(function* (sessionID, formID) {
|
|
56
|
+
const form = yield* Form.Service;
|
|
57
|
+
const info = yield* form.get(formID).pipe(Effect.catchTag("Form.NotFoundError", () => missingForm(formID)));
|
|
58
|
+
if (info.sessionID !== sessionID)
|
|
59
|
+
return yield* missingForm(formID);
|
|
60
|
+
return { form, info };
|
|
61
|
+
});
|
|
62
|
+
const busySession = (error) => new SessionBusyError({
|
|
63
|
+
sessionID: error.sessionID,
|
|
64
|
+
message: `Session is busy: ${error.sessionID}`
|
|
65
|
+
});
|
|
66
|
+
const closedSession = (error) => new ConflictError({
|
|
67
|
+
resource: error.sessionID,
|
|
68
|
+
message: error.message
|
|
69
|
+
});
|
|
70
|
+
const pendingMutation = (effect, conflict) => effect.pipe(Effect.catchTag("Session.NotFoundError", missingSession2), Effect.catchTag("Session.InboxConflictError", (error) => new ConflictError({ resource: error.inboxID, message: `${conflict}: ${error.inboxID}` })), Effect.as(HttpApiSchema.NoContent.make()));
|
|
71
|
+
return handlers.handle("session.list", Effect.fnUntraced(function* (ctx) {
|
|
72
|
+
return yield* session.list(ctx.query).pipe(Effect.catchTag("Session.InvalidListCursorError", (error) => new InvalidCursorError({ message: error.message })));
|
|
73
|
+
})).handle("session.stats", Effect.fnUntraced(function* (ctx) {
|
|
74
|
+
const timezone = ctx.query.timezone ?? "UTC";
|
|
75
|
+
yield* Effect.try({
|
|
76
|
+
try: () => new Intl.DateTimeFormat("en-US", { timeZone: timezone }),
|
|
77
|
+
catch: () => new InvalidRequestError({ message: `Invalid time zone: ${timezone}` })
|
|
78
|
+
});
|
|
79
|
+
return {
|
|
80
|
+
data: yield* SessionStats.get({
|
|
81
|
+
from: ctx.query.from,
|
|
82
|
+
to: ctx.query.to,
|
|
83
|
+
projectID: ctx.query.project,
|
|
84
|
+
timezone,
|
|
85
|
+
tools: ctx.query.tools
|
|
86
|
+
}).pipe(Effect.mapError(() => new InvalidRequestError({ message: "Stats range must end after it starts" })))
|
|
87
|
+
};
|
|
88
|
+
})).handle("session.create", Effect.fnUntraced(function* (ctx) {
|
|
89
|
+
return {
|
|
90
|
+
data: yield* session.create({
|
|
91
|
+
id: ctx.payload.id,
|
|
92
|
+
title: ctx.payload.title,
|
|
93
|
+
agent: ctx.payload.agent,
|
|
94
|
+
model: ctx.payload.model,
|
|
95
|
+
metadata: ctx.payload.metadata,
|
|
96
|
+
permissions: ctx.payload.permissions,
|
|
97
|
+
...ctx.payload.parentID === undefined ? { location: ctx.payload.location ?? { directory: AbsolutePath.make(process.cwd()) } } : { parentID: ctx.payload.parentID }
|
|
98
|
+
}).pipe(Effect.catchTag("Session.NotFoundError", missingSession2))
|
|
99
|
+
};
|
|
100
|
+
})).handle("session.import", Effect.fnUntraced(function* (ctx) {
|
|
101
|
+
return {
|
|
102
|
+
data: yield* transfer.import({
|
|
103
|
+
data: { info: ctx.payload.info, messages: ctx.payload.messages },
|
|
104
|
+
location: ctx.payload.location ?? { directory: AbsolutePath.make(process.cwd()) }
|
|
105
|
+
}).pipe(Effect.catchTag("Session.NotFoundError", missingSession2), Effect.catchTag("SessionTransfer.ImportConflictError", (error) => new ConflictError({
|
|
106
|
+
message: `Session already exists: ${error.sessionID}`,
|
|
107
|
+
resource: error.sessionID
|
|
108
|
+
})))
|
|
109
|
+
};
|
|
110
|
+
})).handle("session.export", Effect.fnUntraced(function* (ctx) {
|
|
111
|
+
return {
|
|
112
|
+
data: yield* transfer.export({ sessionID: ctx.params.sessionID, sanitize: ctx.query.sanitize }).pipe(Effect.catchTag("Session.NotFoundError", missingSession2), Effect.catchTag("Session.MessageDecodeError", failedMessageDecode2))
|
|
113
|
+
};
|
|
114
|
+
})).handle("session.active", Effect.fnUntraced(function* () {
|
|
115
|
+
const active = yield* session.active;
|
|
116
|
+
return {
|
|
117
|
+
data: Object.fromEntries(Array.from(active, (sessionID) => [sessionID, { type: "running" }]))
|
|
118
|
+
};
|
|
119
|
+
})).handle("session.get", Effect.fnUntraced(function* (ctx) {
|
|
120
|
+
return {
|
|
121
|
+
data: yield* session.get(ctx.params.sessionID).pipe(Effect.catchTag("Session.NotFoundError", missingSession2))
|
|
122
|
+
};
|
|
123
|
+
})).handle("session.view", Effect.fnUntraced(function* (ctx) {
|
|
124
|
+
yield* session.view({ sessionID: ctx.params.sessionID, idle: DateTime.toEpochMillis(ctx.payload.idle) }).pipe(Effect.catchTag("Session.NotFoundError", missingSession2));
|
|
125
|
+
return HttpApiSchema.NoContent.make();
|
|
126
|
+
})).handle("session.remove", Effect.fnUntraced(function* (ctx) {
|
|
127
|
+
yield* session.remove(ctx.params.sessionID).pipe(Effect.catchTag("Session.NotFoundError", missingSession2));
|
|
128
|
+
return HttpApiSchema.NoContent.make();
|
|
129
|
+
})).handle("session.environment", Effect.fnUntraced(function* (ctx) {
|
|
130
|
+
yield* session.environment({ sessionID: ctx.params.sessionID, variables: ctx.payload.variables }).pipe(Effect.catchTag("Session.NotFoundError", missingSession2));
|
|
131
|
+
return HttpApiSchema.NoContent.make();
|
|
132
|
+
})).handle("session.fork", Effect.fnUntraced(function* (ctx) {
|
|
133
|
+
return {
|
|
134
|
+
data: yield* session.fork({ sessionID: ctx.params.sessionID, before: ctx.payload.before }).pipe(Effect.catchTag("Session.NotFoundError", missingSession2), Effect.catchTag("Session.MessageNotFoundError", missingMessage2), Effect.catchTag("Session.ForkEmptyError", (error) => new InvalidRequestError({ message: error.message, kind: "empty_session" })))
|
|
135
|
+
};
|
|
136
|
+
})).handle("session.switchAgent", Effect.fnUntraced(function* (ctx) {
|
|
137
|
+
yield* session.switchAgent({ sessionID: ctx.params.sessionID, agent: ctx.payload.agent }).pipe(Effect.catchTag("Session.NotFoundError", missingSession2));
|
|
138
|
+
return HttpApiSchema.NoContent.make();
|
|
139
|
+
})).handle("session.switchModel", Effect.fnUntraced(function* (ctx) {
|
|
140
|
+
yield* session.switchModel({ sessionID: ctx.params.sessionID, model: ctx.payload.model }).pipe(Effect.catchTag("Session.NotFoundError", missingSession2));
|
|
141
|
+
return HttpApiSchema.NoContent.make();
|
|
142
|
+
})).handle("session.update", Effect.fnUntraced(function* (ctx) {
|
|
143
|
+
const info = yield* requireSession(ctx.params.sessionID);
|
|
144
|
+
if (ctx.payload.title !== undefined) {
|
|
145
|
+
if (ctx.payload.title) {
|
|
146
|
+
yield* session.rename({ sessionID: ctx.params.sessionID, title: ctx.payload.title }).pipe(Effect.catchTag("Session.NotFoundError", missingSession2));
|
|
147
|
+
} else {
|
|
148
|
+
yield* SessionTitle.Service.use((title) => title.generate(ctx.params.sessionID)).pipe(instances.provide(info), locationErrors2);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
if (ctx.payload.metadata !== undefined)
|
|
152
|
+
yield* session.setMetadata({ sessionID: ctx.params.sessionID, metadata: ctx.payload.metadata }).pipe(Effect.catchTag("Session.NotFoundError", missingSession2));
|
|
153
|
+
if (ctx.payload.permissions !== undefined)
|
|
154
|
+
yield* session.setPermissions({ sessionID: ctx.params.sessionID, permissions: ctx.payload.permissions }).pipe(Effect.catchTag("Session.NotFoundError", missingSession2));
|
|
155
|
+
if (ctx.payload.archived !== undefined)
|
|
156
|
+
yield* (ctx.payload.archived ? session.archive : session.unarchive)(ctx.params.sessionID).pipe(Effect.catchTag("Session.NotFoundError", missingSession2));
|
|
157
|
+
return HttpApiSchema.NoContent.make();
|
|
158
|
+
})).handle("session.move", Effect.fnUntraced(function* (ctx) {
|
|
159
|
+
yield* session.move({
|
|
160
|
+
sessionID: ctx.params.sessionID,
|
|
161
|
+
directory: ctx.payload.directory,
|
|
162
|
+
delivery: ctx.payload.delivery
|
|
163
|
+
}).pipe(Effect.catchTag("Session.NotFoundError", missingSession2), Effect.catchTag("Session.DestinationNotFoundError", (error) => Effect.fail(new InvalidRequestError({ message: `Directory does not exist: ${error.directory}` }))), Effect.catchTag("Session.DestinationNotDirectoryError", (error) => Effect.fail(new InvalidRequestError({ message: `Not a directory: ${error.directory}` }))), Effect.catchTag("Session.DestinationUnavailableError", (error) => Effect.fail(new InvalidRequestError({ message: `Directory is unavailable: ${error.directory}` }))));
|
|
164
|
+
return HttpApiSchema.NoContent.make();
|
|
165
|
+
})).handle("session.prompt", Effect.fnUntraced(function* (ctx) {
|
|
166
|
+
return {
|
|
167
|
+
data: yield* session.prompt({
|
|
168
|
+
sessionID: ctx.params.sessionID,
|
|
169
|
+
id: ctx.payload.id,
|
|
170
|
+
text: ctx.payload.text,
|
|
171
|
+
files: ctx.payload.files,
|
|
172
|
+
agents: ctx.payload.agents,
|
|
173
|
+
skills: ctx.payload.skills,
|
|
174
|
+
metadata: ctx.payload.metadata,
|
|
175
|
+
delivery: ctx.payload.delivery,
|
|
176
|
+
resume: ctx.payload.resume
|
|
177
|
+
}).pipe(Effect.catchTag("Session.NotFoundError", missingSession2), Effect.catchTag("Session.ClosedError", closedSession), Effect.catchTag("Session.PromptConflictError", (error) => Effect.fail(new ConflictError({
|
|
178
|
+
message: `Prompt message ID conflicts with an existing durable record: ${error.messageID}`,
|
|
179
|
+
resource: error.messageID
|
|
180
|
+
}))), Effect.catchTag("Session.AttachmentError", (error) => Effect.fail(new InvalidRequestError({ message: error.message, field: "files" }))), Effect.catchTag("Session.SkillNotFoundError", (error) => Effect.fail(new InvalidRequestError({ message: `Skill not found: ${error.skill}`, field: "skills" }))), Effect.catchTag("Skill.LoadError", skillLoadFailed2), locationErrors2)
|
|
181
|
+
};
|
|
182
|
+
})).handle("session.command", Effect.fnUntraced(function* (ctx) {
|
|
183
|
+
yield* session.command({
|
|
184
|
+
sessionID: ctx.params.sessionID,
|
|
185
|
+
command: ctx.payload.name,
|
|
186
|
+
text: ctx.payload.text,
|
|
187
|
+
files: ctx.payload.files,
|
|
188
|
+
agents: ctx.payload.agents,
|
|
189
|
+
skills: ctx.payload.skills,
|
|
190
|
+
delivery: ctx.payload.delivery
|
|
191
|
+
}).pipe(Effect.catchTag("Session.NotFoundError", missingSession2), Effect.catchTag("Command.NotFoundError", (error) => Effect.fail(new CommandNotFoundError({
|
|
192
|
+
command: error.command,
|
|
193
|
+
message: error.message
|
|
194
|
+
}))), Effect.catchTag("Command.ExecutionError", (error) => Effect.fail(new CommandExecutionError({
|
|
195
|
+
command: error.command,
|
|
196
|
+
message: error.message
|
|
197
|
+
}))), locationErrors2);
|
|
198
|
+
return HttpApiSchema.NoContent.make();
|
|
199
|
+
})).handle("session.skill", Effect.fnUntraced(function* (ctx) {
|
|
200
|
+
yield* session.skill({
|
|
201
|
+
sessionID: ctx.params.sessionID,
|
|
202
|
+
skill: ctx.payload.id,
|
|
203
|
+
resume: ctx.payload.resume
|
|
204
|
+
}).pipe(Effect.catchTag("Session.NotFoundError", missingSession2), Effect.catchTag("Session.ClosedError", closedSession), Effect.catchTag("Session.SkillNotFoundError", (error) => Effect.fail(new SkillNotFoundError({ skill: error.skill, message: `Skill not found: ${error.skill}` }))), Effect.catchTag("Skill.LoadError", skillLoadFailed2), locationErrors2);
|
|
205
|
+
return HttpApiSchema.NoContent.make();
|
|
206
|
+
})).handle("session.synthetic", Effect.fnUntraced(function* (ctx) {
|
|
207
|
+
const data = yield* session.synthetic({
|
|
208
|
+
id: ctx.payload.id,
|
|
209
|
+
sessionID: ctx.params.sessionID,
|
|
210
|
+
text: ctx.payload.text,
|
|
211
|
+
description: ctx.payload.description,
|
|
212
|
+
metadata: ctx.payload.metadata,
|
|
213
|
+
delivery: ctx.payload.delivery,
|
|
214
|
+
resume: ctx.payload.resume
|
|
215
|
+
}).pipe(Effect.catchTag("Session.NotFoundError", missingSession2), Effect.catchTag("Session.SyntheticConflictError", (error) => Effect.fail(new ConflictError({
|
|
216
|
+
message: `Synthetic input ID conflicts with an existing durable record: ${error.inputID}`,
|
|
217
|
+
resource: error.inputID
|
|
218
|
+
}))));
|
|
219
|
+
return { data };
|
|
220
|
+
})).handle("session.shell", Effect.fnUntraced(function* (ctx) {
|
|
221
|
+
yield* session.shell({ sessionID: ctx.params.sessionID, id: ctx.payload.id, command: ctx.payload.command }).pipe(Effect.catchTag("Session.NotFoundError", missingSession2), Effect.catchTag("Session.ClosedError", closedSession), Effect.catchTag("Session.ShellStartError", (error) => Effect.fail(new ServiceUnavailableError({ message: error.message, service: "shell" }))));
|
|
222
|
+
return HttpApiSchema.NoContent.make();
|
|
223
|
+
})).handle("session.compact", Effect.fnUntraced(function* (ctx) {
|
|
224
|
+
return {
|
|
225
|
+
data: yield* session.compact({ sessionID: ctx.params.sessionID, id: ctx.payload.id, delivery: ctx.payload.delivery }).pipe(Effect.catchTag("Session.NotFoundError", missingSession2), Effect.catchTag("Session.ClosedError", closedSession), Effect.catchTag("Session.CompactionConflictError", (error) => Effect.fail(new ConflictError({
|
|
226
|
+
message: `Compaction input ID conflicts with an existing durable record: ${error.inputID}`,
|
|
227
|
+
resource: error.inputID
|
|
228
|
+
}))))
|
|
229
|
+
};
|
|
230
|
+
})).handle("session.wait", Effect.fnUntraced(function* (ctx) {
|
|
231
|
+
yield* session.wait(ctx.params.sessionID).pipe(Effect.catchTag("Session.NotFoundError", missingSession2));
|
|
232
|
+
return HttpApiSchema.NoContent.make();
|
|
233
|
+
})).handle("session.revert.stage", Effect.fnUntraced(function* (ctx) {
|
|
234
|
+
yield* Effect.log("session.revert.stage", {
|
|
235
|
+
sessionID: ctx.params.sessionID,
|
|
236
|
+
messageID: ctx.payload.messageID,
|
|
237
|
+
files: ctx.payload.files
|
|
238
|
+
});
|
|
239
|
+
return {
|
|
240
|
+
data: yield* session.revert.stage({ ...ctx.params, ...ctx.payload }).pipe(Effect.catchTag("Session.NotFoundError", missingSession2), Effect.catchTag("Session.MessageNotFoundError", missingMessage2), Effect.catchTag("Session.BusyError", busySession), Effect.catchTag("Snapshot.Error", failedSnapshot2("stage session revert", ctx.params.sessionID)), locationErrors2)
|
|
241
|
+
};
|
|
242
|
+
})).handle("session.revert.clear", Effect.fnUntraced(function* (ctx) {
|
|
243
|
+
yield* Effect.log("session.revert.clear", { sessionID: ctx.params.sessionID });
|
|
244
|
+
yield* session.revert.clear(ctx.params.sessionID).pipe(Effect.catchTag("Session.NotFoundError", missingSession2), Effect.catchTag("Session.BusyError", busySession), Effect.catchTag("Snapshot.Error", failedSnapshot2("clear session revert", ctx.params.sessionID)), locationErrors2);
|
|
245
|
+
return HttpApiSchema.NoContent.make();
|
|
246
|
+
})).handle("session.revert.commit", Effect.fnUntraced(function* (ctx) {
|
|
247
|
+
yield* Effect.log("session.revert.commit", { sessionID: ctx.params.sessionID });
|
|
248
|
+
yield* session.revert.commit(ctx.params.sessionID).pipe(Effect.catchTag("Session.NotFoundError", missingSession2), Effect.catchTag("Session.BusyError", busySession));
|
|
249
|
+
return HttpApiSchema.NoContent.make();
|
|
250
|
+
})).handle("session.context", Effect.fnUntraced(function* (ctx) {
|
|
251
|
+
return {
|
|
252
|
+
data: yield* session.context(ctx.params.sessionID).pipe(Effect.catchTag("Session.NotFoundError", missingSession2), Effect.catchTag("Session.MessageDecodeError", failedMessageDecode2))
|
|
253
|
+
};
|
|
254
|
+
})).handle("session.diff", Effect.fnUntraced(function* (ctx) {
|
|
255
|
+
return {
|
|
256
|
+
data: yield* session.diff({ sessionID: ctx.params.sessionID, ...ctx.query }).pipe(Effect.catchTag("Session.NotFoundError", missingSession2), Effect.catchTag("Session.MessageNotFoundError", missingMessage2), Effect.catchTag("Session.TurnRangeError", (error) => new InvalidRequestError({ message: error.message, field: error.field })), Effect.catchTag("Snapshot.Error", failedSnapshot2("diff session turn", ctx.params.sessionID)), locationErrors2)
|
|
257
|
+
};
|
|
258
|
+
})).handle("session.inbox.list", Effect.fnUntraced(function* (ctx) {
|
|
259
|
+
if (wantsMediaRefs2(ctx.request))
|
|
260
|
+
return yield* HttpServerResponse.schemaJson(SessionMediaInboxResponse)({
|
|
261
|
+
data: yield* session.inboxWithRefs(ctx.params.sessionID).pipe(Effect.catchTag("Session.NotFoundError", missingSession2))
|
|
262
|
+
}).pipe(Effect.orDie);
|
|
263
|
+
return {
|
|
264
|
+
data: yield* session.inbox(ctx.params.sessionID).pipe(Effect.catchTag("Session.NotFoundError", missingSession2))
|
|
265
|
+
};
|
|
266
|
+
})).handle("session.inbox.cancel", Effect.fnUntraced(function* (ctx) {
|
|
267
|
+
yield* session.cancelInbox({ sessionID: ctx.params.sessionID, inboxID: ctx.params.inboxID }).pipe(Effect.catchTag("Session.NotFoundError", missingSession2), Effect.catchTag("Session.InboxConflictError", () => Effect.void));
|
|
268
|
+
return HttpApiSchema.NoContent.make();
|
|
269
|
+
})).handle("session.inbox.update", Effect.fnUntraced(function* (ctx) {
|
|
270
|
+
return yield* pendingMutation(ctx.payload.delivery === "steer" ? session.steerInbox({ sessionID: ctx.params.sessionID, inboxID: ctx.params.inboxID }) : session.queueInbox({ sessionID: ctx.params.sessionID, inboxID: ctx.params.inboxID }), `Pending input cannot change to ${ctx.payload.delivery}`);
|
|
271
|
+
})).handle("session.instructions.entry.list", Effect.fnUntraced(function* (ctx) {
|
|
272
|
+
yield* requireSession(ctx.params.sessionID);
|
|
273
|
+
return { data: yield* instructions.list(ctx.params.sessionID) };
|
|
274
|
+
})).handle("session.instructions.entry.put", Effect.fnUntraced(function* (ctx) {
|
|
275
|
+
yield* requireSession(ctx.params.sessionID);
|
|
276
|
+
yield* instructions.put({ sessionID: ctx.params.sessionID, key: ctx.params.key, value: ctx.payload.value });
|
|
277
|
+
return HttpApiSchema.NoContent.make();
|
|
278
|
+
})).handle("session.instructions.entry.remove", Effect.fnUntraced(function* (ctx) {
|
|
279
|
+
yield* requireSession(ctx.params.sessionID);
|
|
280
|
+
yield* instructions.remove({ sessionID: ctx.params.sessionID, key: ctx.params.key });
|
|
281
|
+
return HttpApiSchema.NoContent.make();
|
|
282
|
+
})).handle("session.generate", Effect.fnUntraced(function* (ctx) {
|
|
283
|
+
const result = yield* session.generate({ sessionID: ctx.params.sessionID, prompt: ctx.payload.prompt }).pipe(Effect.mapError((error) => error._tag === "Session.NotFoundError" ? missingSession2(error) : new ServiceUnavailableError({ message: error.message, service: "session generation" })));
|
|
284
|
+
return { data: result };
|
|
285
|
+
})).handle("session.log", Effect.fnUntraced(function* (ctx) {
|
|
286
|
+
yield* session.get(ctx.params.sessionID).pipe(Effect.catchTag("Session.NotFoundError", missingSession2));
|
|
287
|
+
return session.log({ sessionID: ctx.params.sessionID, after: ctx.query.after, follow: ctx.query.follow }).pipe(Stream.orDie);
|
|
288
|
+
})).handle("session.interrupt", Effect.fnUntraced(function* (ctx) {
|
|
289
|
+
yield* requireSession(ctx.params.sessionID);
|
|
290
|
+
return { interrupted: yield* session.interrupt(ctx.params.sessionID, { resume: ctx.query.resume }) };
|
|
291
|
+
})).handle("session.background", Effect.fnUntraced(function* (ctx) {
|
|
292
|
+
yield* session.background(ctx.params.sessionID).pipe(Effect.catchTag("Session.NotFoundError", missingSession2));
|
|
293
|
+
return HttpApiSchema.NoContent.make();
|
|
294
|
+
})).handle("session.message", Effect.fnUntraced(function* (ctx) {
|
|
295
|
+
yield* session.get(ctx.params.sessionID).pipe(Effect.catchTag("Session.NotFoundError", missingSession2));
|
|
296
|
+
if (wantsMediaRefs2(ctx.request)) {
|
|
297
|
+
const message = yield* session.messageWithRefs(ctx.params);
|
|
298
|
+
if (message)
|
|
299
|
+
return yield* HttpServerResponse.schemaJson(SessionMediaMessageResponse)({ data: message }).pipe(Effect.orDie);
|
|
300
|
+
} else {
|
|
301
|
+
const message = yield* session.message(ctx.params);
|
|
302
|
+
if (message)
|
|
303
|
+
return { data: message };
|
|
304
|
+
}
|
|
305
|
+
return yield* new MessageNotFoundError({
|
|
306
|
+
sessionID: ctx.params.sessionID,
|
|
307
|
+
messageID: ctx.params.messageID,
|
|
308
|
+
message: `Message not found: ${ctx.params.messageID}`
|
|
309
|
+
});
|
|
310
|
+
})).handle("session.form.list", Effect.fnUntraced(function* (ctx) {
|
|
311
|
+
const form = yield* Form.Service;
|
|
312
|
+
return { data: yield* form.list({ sessionID: ctx.params.sessionID }) };
|
|
313
|
+
})).handle("session.form.create", Effect.fnUntraced(function* (ctx) {
|
|
314
|
+
const form = yield* Form.Service;
|
|
315
|
+
const created = yield* form.create({
|
|
316
|
+
id: ctx.payload.id,
|
|
317
|
+
sessionID: ctx.params.sessionID,
|
|
318
|
+
title: ctx.payload.title,
|
|
319
|
+
metadata: ctx.payload.metadata,
|
|
320
|
+
fields: ctx.payload.fields
|
|
321
|
+
}).pipe(Effect.catchTags({
|
|
322
|
+
"Form.AlreadyExistsError": (error) => new ConflictError({ resource: error.id, message: error.message }),
|
|
323
|
+
"Form.InvalidFormError": (error) => new InvalidRequestError({ message: error.message, field: "fields" })
|
|
324
|
+
}));
|
|
325
|
+
return { data: created };
|
|
326
|
+
})).handle("session.form.get", Effect.fnUntraced(function* (ctx) {
|
|
327
|
+
const owned = yield* requireOwnedForm(ctx.params.sessionID, ctx.params.formID);
|
|
328
|
+
const state = yield* owned.form.state(ctx.params.formID).pipe(Effect.catchTag("Form.NotFoundError", () => missingForm(ctx.params.formID)));
|
|
329
|
+
return { data: { ...owned.info, state } };
|
|
330
|
+
})).handle("session.form.reply", Effect.fnUntraced(function* (ctx) {
|
|
331
|
+
const owned = yield* requireOwnedForm(ctx.params.sessionID, ctx.params.formID);
|
|
332
|
+
yield* owned.form.reply({ id: ctx.params.formID, answer: ctx.payload.answer }).pipe(Effect.catchTags({
|
|
333
|
+
"Form.AlreadySettledError": (error) => new FormAlreadySettledError({ id: error.id, message: error.message }),
|
|
334
|
+
"Form.InvalidAnswerError": (error) => new FormInvalidAnswerError({ id: error.id, message: error.message }),
|
|
335
|
+
"Form.NotFoundError": () => missingForm(ctx.params.formID)
|
|
336
|
+
}));
|
|
337
|
+
return HttpApiSchema.NoContent.make();
|
|
338
|
+
})).handle("session.form.cancel", Effect.fnUntraced(function* (ctx) {
|
|
339
|
+
const owned = yield* requireOwnedForm(ctx.params.sessionID, ctx.params.formID);
|
|
340
|
+
yield* owned.form.cancel(ctx.params.formID, { message: ctx.query.message }).pipe(Effect.catchTags({
|
|
341
|
+
"Form.AlreadySettledError": (error) => new FormAlreadySettledError({ id: error.id, message: error.message }),
|
|
342
|
+
"Form.NotFoundError": () => missingForm(ctx.params.formID)
|
|
343
|
+
}));
|
|
344
|
+
return HttpApiSchema.NoContent.make();
|
|
345
|
+
}));
|
|
346
|
+
}));
|
|
347
|
+
|
|
348
|
+
export { SessionHandler2 };
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import {
|
|
2
|
+
isAllowedCorsOrigin2
|
|
3
|
+
} from "./api-11hx8jza.js";
|
|
4
|
+
import {
|
|
5
|
+
middleware3
|
|
6
|
+
} from "./api-8tn84h85.js";
|
|
7
|
+
import {
|
|
8
|
+
withoutParentSpan2
|
|
9
|
+
} from "./api-azwdvyh3.js";
|
|
10
|
+
import {
|
|
11
|
+
createRoutes2
|
|
12
|
+
} from "./api-kvefct3s.js";
|
|
13
|
+
import {
|
|
14
|
+
__export
|
|
15
|
+
} from "./api-9rqn6x4v.js";
|
|
16
|
+
|
|
17
|
+
// src/fetch.ts
|
|
18
|
+
var exports_fetch = {};
|
|
19
|
+
__export(exports_fetch, {
|
|
20
|
+
ServerFetch: () => exports_fetch,
|
|
21
|
+
build: () => build2,
|
|
22
|
+
make: () => make4,
|
|
23
|
+
makeWithContext: () => makeWithContext2,
|
|
24
|
+
middleware: () => middleware2,
|
|
25
|
+
serve: () => serve3
|
|
26
|
+
});
|
|
27
|
+
import { Context, Effect, flow, Layer } from "effect";
|
|
28
|
+
import { HttpEffect, HttpMiddleware, HttpRouter, HttpServer } from "effect/http";
|
|
29
|
+
import { SessionRestart } from "@radheim/core/session/execution/restart";
|
|
30
|
+
var makeWithContext2 = Effect.fn("ServerFetch.makeWithContext")(function* (options = {}, boot = {}) {
|
|
31
|
+
const context = yield* build2(createRoutes2(options, () => [], boot.overrides ?? []));
|
|
32
|
+
const handler = yield* serve3(context, middleware2(options));
|
|
33
|
+
return { handler, context };
|
|
34
|
+
});
|
|
35
|
+
var middleware2 = (options) => flow(middleware3(options), HttpMiddleware.cors({ allowedOrigins: (origin) => isAllowedCorsOrigin2(origin, options), maxAge: 86400 }));
|
|
36
|
+
var build2 = (routes) => Layer.build(routes.pipe(Layer.provide(HttpServer.layerServices))).pipe(withoutParentSpan2);
|
|
37
|
+
var serve3 = Effect.fnUntraced(function* (context, middleware = (app) => app) {
|
|
38
|
+
yield* Context.get(context, SessionRestart.Service).resumeSuspendedSessions.pipe(Effect.provideContext(context), withoutParentSpan2, Effect.forkScoped);
|
|
39
|
+
return Context.get(context, HttpRouter.HttpRouter).asHttpEffect().pipe(middleware, HttpEffect.toWebHandlerWith(context));
|
|
40
|
+
});
|
|
41
|
+
var make4 = Effect.fn("ServerFetch.make")(function* (options = {}, boot = {}) {
|
|
42
|
+
return (yield* makeWithContext2(options, boot)).handler;
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
export { makeWithContext2, middleware2, build2, serve3, make4, exports_fetch };
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import {
|
|
2
|
+
__export
|
|
3
|
+
} from "./api-9rqn6x4v.js";
|
|
4
|
+
|
|
5
|
+
// src/event-feed.ts
|
|
6
|
+
var exports_event_feed = {};
|
|
7
|
+
__export(exports_event_feed, {
|
|
8
|
+
EncodingError: () => EncodingError2,
|
|
9
|
+
EventFeed: () => exports_event_feed,
|
|
10
|
+
Service: () => Service5,
|
|
11
|
+
SubscriberCapacity: () => SubscriberCapacity2,
|
|
12
|
+
SubscriberOverflowError: () => SubscriberOverflowError2,
|
|
13
|
+
frame: () => frame2,
|
|
14
|
+
layer: () => layer3,
|
|
15
|
+
make: () => make5
|
|
16
|
+
});
|
|
17
|
+
import { Bus } from "@radheim/core/bus";
|
|
18
|
+
import { Event } from "@radheim/schema/event";
|
|
19
|
+
import { isRadheEvent } from "@radheim/protocol/groups/event";
|
|
20
|
+
import { Cause, Context, Effect, Exit, Layer, Queue, Schema, Scope, Stream } from "effect";
|
|
21
|
+
var SubscriberCapacity2 = 4096;
|
|
22
|
+
|
|
23
|
+
class SubscriberOverflowError2 extends Schema.TaggedError()("EventFeed.SubscriberOverflow", { capacity: Schema.Int }) {
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
class EncodingError2 extends Schema.TaggedError()("EventFeed.EncodingError", {
|
|
27
|
+
eventID: Event.ID,
|
|
28
|
+
eventType: Schema.String,
|
|
29
|
+
cause: Schema.Defect()
|
|
30
|
+
}) {
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
class Service5 extends Context.Service()("@radheim/server/EventFeed") {
|
|
34
|
+
}
|
|
35
|
+
function frame2(event) {
|
|
36
|
+
return `data: ${JSON.stringify(event)}
|
|
37
|
+
|
|
38
|
+
`;
|
|
39
|
+
}
|
|
40
|
+
var make5 = Effect.fn("EventFeed.make")(function* (observe, options) {
|
|
41
|
+
const capacity = options?.capacity ?? SubscriberCapacity2;
|
|
42
|
+
const render = options?.encode ?? frame2;
|
|
43
|
+
const subscribers = new Map;
|
|
44
|
+
const fail = (error) => Effect.sync(() => {
|
|
45
|
+
const current = Array.from(subscribers.keys());
|
|
46
|
+
subscribers.clear();
|
|
47
|
+
for (const subscriber of current)
|
|
48
|
+
Queue.failCauseUnsafe(subscriber, Cause.fail(error));
|
|
49
|
+
});
|
|
50
|
+
const offer = (subscriber, encoded) => {
|
|
51
|
+
if (Queue.offerUnsafe(subscriber, encoded))
|
|
52
|
+
return;
|
|
53
|
+
subscribers.delete(subscriber);
|
|
54
|
+
Queue.failCauseUnsafe(subscriber, Cause.fail(new SubscriberOverflowError2({ capacity })));
|
|
55
|
+
};
|
|
56
|
+
const publish = Effect.fnUntraced(function* (event) {
|
|
57
|
+
if (!isRadheEvent(event))
|
|
58
|
+
return;
|
|
59
|
+
let encoded;
|
|
60
|
+
for (const [subscriber, types] of subscribers) {
|
|
61
|
+
if (types && !types.has(event.type))
|
|
62
|
+
continue;
|
|
63
|
+
encoded ??= yield* Effect.try({
|
|
64
|
+
try: () => render(event),
|
|
65
|
+
catch: (cause) => new EncodingError2({ eventID: event.id, eventType: event.type, cause })
|
|
66
|
+
}).pipe(Effect.catch((error) => Effect.logError("Failed to encode public event", {
|
|
67
|
+
eventID: error.eventID,
|
|
68
|
+
eventType: error.eventType,
|
|
69
|
+
cause: error.cause
|
|
70
|
+
}).pipe(Effect.andThen(fail(error)), Effect.as(undefined))));
|
|
71
|
+
if (encoded === undefined)
|
|
72
|
+
return;
|
|
73
|
+
offer(subscriber, encoded);
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
const unsubscribe = yield* observe(publish);
|
|
77
|
+
yield* Effect.addFinalizer(() => unsubscribe);
|
|
78
|
+
return Service5.of({
|
|
79
|
+
subscribe: (types) => Effect.gen(function* () {
|
|
80
|
+
const queue = yield* Effect.acquireRelease(Queue.dropping(capacity).pipe(Effect.tap((queue) => Effect.sync(() => subscribers.set(queue, types?.length ? new Set(types) : undefined)))), (queue) => Effect.sync(() => subscribers.delete(queue)).pipe(Effect.andThen(Queue.shutdown(queue)), Effect.asVoid));
|
|
81
|
+
const id = crypto.randomUUID();
|
|
82
|
+
const send = (event) => Effect.suspend(() => {
|
|
83
|
+
if (!subscribers.has(queue))
|
|
84
|
+
return Effect.void;
|
|
85
|
+
return Effect.try(() => render(event)).pipe(Effect.flatMap((encoded) => Effect.sync(() => offer(queue, encoded))), Effect.catchCause((cause) => Effect.logError("Failed to encode extension event", { type: event.type, cause })));
|
|
86
|
+
});
|
|
87
|
+
const scope = yield* Scope.Scope;
|
|
88
|
+
yield* Effect.forEach(options?.extensions ?? [], (extension) => Effect.gen(function* () {
|
|
89
|
+
const child = yield* Scope.fork(scope);
|
|
90
|
+
yield* extension.open(id, send).pipe(Scope.provide(child), Effect.catchCause((cause) => Effect.logError("Event stream extension failed", { cause }).pipe(Effect.andThen(Scope.close(child, Exit.void)))));
|
|
91
|
+
}), { discard: true });
|
|
92
|
+
return { id, events: Stream.fromQueue(queue) };
|
|
93
|
+
})
|
|
94
|
+
});
|
|
95
|
+
});
|
|
96
|
+
var layer3 = (...extensions) => Layer.effect(Service5, Effect.gen(function* () {
|
|
97
|
+
const bus = yield* Bus.Service;
|
|
98
|
+
return yield* make5(bus.listen, { extensions: yield* Effect.all(extensions) });
|
|
99
|
+
}));
|
|
100
|
+
|
|
101
|
+
export { SubscriberCapacity2, SubscriberOverflowError2, EncodingError2, Service5, frame2, make5, layer3, exports_event_feed };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Api2
|
|
3
|
+
} from "./api-f6955nmc.js";
|
|
4
|
+
|
|
5
|
+
// src/handlers/project.ts
|
|
6
|
+
import { Project } from "@radheim/core/project";
|
|
7
|
+
import { Effect } from "effect";
|
|
8
|
+
import { HttpApiBuilder } from "effect/http-api";
|
|
9
|
+
import { ProjectNotFoundError } from "@radheim/protocol/errors";
|
|
10
|
+
var ProjectHandler2 = HttpApiBuilder.group(Api2, "server.project", (handlers) => handlers.handle("project.list", (ctx) => Project.Service.use((project) => project.list(ctx.query))).handle("project.update", (ctx) => Project.Service.use((project) => project.update({ ...ctx.payload, projectID: ctx.params.projectID }).pipe(Effect.mapError(() => new ProjectNotFoundError({
|
|
11
|
+
projectID: ctx.params.projectID,
|
|
12
|
+
message: `Project not found: ${ctx.params.projectID}`
|
|
13
|
+
}))))));
|
|
14
|
+
|
|
15
|
+
export { ProjectHandler2 };
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import {
|
|
2
|
+
__export
|
|
3
|
+
} from "./api-9rqn6x4v.js";
|
|
4
|
+
|
|
5
|
+
// src/range.ts
|
|
6
|
+
var exports_range = {};
|
|
7
|
+
__export(exports_range, {
|
|
8
|
+
ByteRange: () => exports_range,
|
|
9
|
+
parse: () => parse2
|
|
10
|
+
});
|
|
11
|
+
function parse2(header, size) {
|
|
12
|
+
const match = header === undefined ? null : /^bytes=\s*(\d*)\s*-\s*(\d*)\s*$/i.exec(header.trim());
|
|
13
|
+
if (match === null || match[1] === "" && match[2] === "")
|
|
14
|
+
return;
|
|
15
|
+
if (match[1] === "") {
|
|
16
|
+
const suffix = Number(match[2]);
|
|
17
|
+
if (suffix === 0 || size === 0)
|
|
18
|
+
return "unsatisfiable";
|
|
19
|
+
return { start: Math.max(size - suffix, 0), end: size - 1 };
|
|
20
|
+
}
|
|
21
|
+
const start = Number(match[1]);
|
|
22
|
+
const end = match[2] === "" ? size - 1 : Number(match[2]);
|
|
23
|
+
if (start > end || start >= size)
|
|
24
|
+
return "unsatisfiable";
|
|
25
|
+
return { start, end: Math.min(end, size - 1) };
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export { parse2, exports_range };
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import {
|
|
2
|
+
isAllowedRequestOrigin2
|
|
3
|
+
} from "./api-11hx8jza.js";
|
|
4
|
+
import {
|
|
5
|
+
__export
|
|
6
|
+
} from "./api-9rqn6x4v.js";
|
|
7
|
+
|
|
8
|
+
// src/request-site.ts
|
|
9
|
+
var exports_request_site = {};
|
|
10
|
+
__export(exports_request_site, {
|
|
11
|
+
RequestSite: () => exports_request_site,
|
|
12
|
+
middleware: () => middleware3,
|
|
13
|
+
rejected: () => rejected2
|
|
14
|
+
});
|
|
15
|
+
import { Effect } from "effect";
|
|
16
|
+
import { HttpMiddleware, HttpServerRequest, HttpServerResponse } from "effect/http";
|
|
17
|
+
var ARTIFACT_VIEW = /^\/api\/experimental\/artifacts\/[^/]+\/view(\/|$)/;
|
|
18
|
+
function rejected2(request, options) {
|
|
19
|
+
const site = request.headers["sec-fetch-site"];
|
|
20
|
+
if (site !== "cross-site" && site !== "same-site")
|
|
21
|
+
return false;
|
|
22
|
+
const pathname = new URL(request.url, "http://localhost").pathname;
|
|
23
|
+
if (pathname !== "/api" && !pathname.startsWith("/api/"))
|
|
24
|
+
return false;
|
|
25
|
+
if (ARTIFACT_VIEW.test(pathname))
|
|
26
|
+
return false;
|
|
27
|
+
if (request.headers["sec-fetch-mode"] === "navigate")
|
|
28
|
+
return true;
|
|
29
|
+
const origin = request.headers.origin;
|
|
30
|
+
return origin !== undefined && !isAllowedRequestOrigin2(origin, request.headers.host, options);
|
|
31
|
+
}
|
|
32
|
+
var middleware3 = (options) => HttpMiddleware.make((app) => Effect.gen(function* () {
|
|
33
|
+
const request = yield* HttpServerRequest.HttpServerRequest;
|
|
34
|
+
if (!rejected2(request, options))
|
|
35
|
+
return yield* app;
|
|
36
|
+
return HttpServerResponse.jsonUnsafe({ _tag: "ForbiddenError", message: "Cross-site requests to the API are not allowed" }, { status: 403 });
|
|
37
|
+
}));
|
|
38
|
+
|
|
39
|
+
export { rejected2, middleware3, exports_request_site };
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import {
|
|
2
|
+
missingSession2
|
|
3
|
+
} from "./api-ghyd9ren.js";
|
|
4
|
+
|
|
5
|
+
// src/handlers/automation.ts
|
|
6
|
+
import { Automation } from "@radheim/core/automation";
|
|
7
|
+
import { Permission } from "@radheim/core/permission";
|
|
8
|
+
import { AutomationNotFoundError, ForbiddenError, InvalidRequestError } from "@radheim/protocol/errors";
|
|
9
|
+
import { Effect } from "effect";
|
|
10
|
+
import { HttpApiSchema } from "effect/http-api";
|
|
11
|
+
var makeAutomation2 = Effect.gen(function* () {
|
|
12
|
+
const automations = yield* Automation.Service;
|
|
13
|
+
return {
|
|
14
|
+
create: (payload) => automations.create(payload).pipe(Effect.provideService(Permission.Unattended, []), Effect.map((data) => ({ data })), Effect.catchTags({
|
|
15
|
+
"Automation.InvalidError": (error) => Effect.fail(new InvalidRequestError({ message: error.message, kind: "automation" })),
|
|
16
|
+
"Automation.DisabledError": () => Effect.fail(disabled()),
|
|
17
|
+
"Permission.BlockedError": (error) => Effect.fail(new ForbiddenError({ message: error.message })),
|
|
18
|
+
"Permission.CorrectedError": (error) => Effect.fail(new ForbiddenError({ message: error.feedback })),
|
|
19
|
+
"Session.NotFoundError": (error) => Effect.fail(missingSession2(error))
|
|
20
|
+
})),
|
|
21
|
+
list: (query) => automations.list(query).pipe(Effect.map((data) => ({ data })), Effect.catchTags({
|
|
22
|
+
"Automation.InvalidError": (error) => Effect.fail(new InvalidRequestError({ message: error.message, kind: "automation" })),
|
|
23
|
+
"Automation.DisabledError": () => Effect.fail(disabled()),
|
|
24
|
+
"Session.NotFoundError": (error) => Effect.fail(missingSession2(error))
|
|
25
|
+
})),
|
|
26
|
+
get: (id) => managed(automations.get(id).pipe(Effect.map((data) => ({ data })))),
|
|
27
|
+
pause: (id) => managed(automations.pause(id).pipe(Effect.map((data) => ({ data })))),
|
|
28
|
+
resume: (id) => managed(automations.resume(id).pipe(Effect.map((data) => ({ data })))),
|
|
29
|
+
remove: (id) => managed(automations.remove(id).pipe(Effect.as(HttpApiSchema.NoContent.make())))
|
|
30
|
+
};
|
|
31
|
+
});
|
|
32
|
+
function managed(effect) {
|
|
33
|
+
return effect.pipe(Effect.catchTags({
|
|
34
|
+
"Automation.NotFoundError": (error) => Effect.fail(missingAutomation(error)),
|
|
35
|
+
"Automation.DisabledError": () => Effect.fail(disabled())
|
|
36
|
+
}));
|
|
37
|
+
}
|
|
38
|
+
function missingAutomation(error) {
|
|
39
|
+
return new AutomationNotFoundError({
|
|
40
|
+
automationID: error.automationID,
|
|
41
|
+
message: `Automation not found: ${error.automationID}`
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
function disabled() {
|
|
45
|
+
return new ForbiddenError({ message: new Automation.DisabledError().message });
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export { makeAutomation2 };
|