@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,198 @@
|
|
|
1
|
+
import {
|
|
2
|
+
response2
|
|
3
|
+
} from "./api-0q8mvh3b.js";
|
|
4
|
+
import {
|
|
5
|
+
Api2
|
|
6
|
+
} from "./api-f6955nmc.js";
|
|
7
|
+
|
|
8
|
+
// src/handlers/integration.ts
|
|
9
|
+
import { Integration } from "@radheim/core/integration";
|
|
10
|
+
import { Effect } from "effect";
|
|
11
|
+
import { HttpApiBuilder, HttpApiSchema } from "effect/http-api";
|
|
12
|
+
import {
|
|
13
|
+
IntegrationAttemptNotFoundError,
|
|
14
|
+
IntegrationMethodNotFoundError,
|
|
15
|
+
IntegrationNotFoundError,
|
|
16
|
+
InvalidRequestError
|
|
17
|
+
} from "@radheim/protocol/errors";
|
|
18
|
+
import { WellKnown } from "@radheim/core/wellknown";
|
|
19
|
+
import { Config } from "@radheim/core/config";
|
|
20
|
+
import { ManagedPolicy } from "@radheim/core/managed-policy";
|
|
21
|
+
var statements = Effect.fnUntraced(function* () {
|
|
22
|
+
const config = yield* Config.Service;
|
|
23
|
+
return ManagedPolicy.statements(yield* config.entries());
|
|
24
|
+
});
|
|
25
|
+
var isMcp = (integration) => integration?.metadata?.source === "mcp";
|
|
26
|
+
var requireConnectable2 = Effect.fnUntraced(function* (integrationID) {
|
|
27
|
+
const integrations = yield* Integration.Service;
|
|
28
|
+
if (isMcp(yield* integrations.get(integrationID)))
|
|
29
|
+
return;
|
|
30
|
+
const denied = ManagedPolicy.match(yield* statements(), "integration.connect", integrationID);
|
|
31
|
+
if (denied?.effect !== "deny")
|
|
32
|
+
return;
|
|
33
|
+
return yield* new InvalidRequestError({
|
|
34
|
+
message: `${denied.message}: connecting ${integrationID} is not allowed`,
|
|
35
|
+
kind: "integration_policy"
|
|
36
|
+
});
|
|
37
|
+
});
|
|
38
|
+
var authorize = (effect) => effect.pipe(Effect.mapError((error) => new InvalidRequestError({
|
|
39
|
+
message: error.cause instanceof Error && error.cause.message.trim() ? error.cause.message : "Authentication failed",
|
|
40
|
+
kind: "integration_authorization"
|
|
41
|
+
})));
|
|
42
|
+
var IntegrationHandler2 = HttpApiBuilder.group(Api2, "server.integration", (handlers) => Effect.gen(function* () {
|
|
43
|
+
return handlers.handle("integration.list", Effect.fnUntraced(function* () {
|
|
44
|
+
const service = yield* Integration.Service;
|
|
45
|
+
const current = yield* statements();
|
|
46
|
+
return yield* response2(service.list().pipe(Effect.map((integrations) => integrations.filter((integration) => isMcp(integration) || ManagedPolicy.decision(current, "integration.connect", integration.id) !== "deny"))));
|
|
47
|
+
})).handle("integration.get", Effect.fnUntraced(function* (ctx) {
|
|
48
|
+
const service = yield* Integration.Service;
|
|
49
|
+
const integration = yield* service.get(ctx.params.integrationID);
|
|
50
|
+
if (!integration)
|
|
51
|
+
return yield* new IntegrationNotFoundError({
|
|
52
|
+
integrationID: ctx.params.integrationID,
|
|
53
|
+
message: `Integration not found: ${ctx.params.integrationID}`
|
|
54
|
+
});
|
|
55
|
+
return yield* response2(Effect.succeed(integration));
|
|
56
|
+
})).handle("integration.wellknown.add", Effect.fnUntraced(function* (ctx) {
|
|
57
|
+
const wellknown = yield* WellKnown.Service;
|
|
58
|
+
const integration = yield* Integration.Service;
|
|
59
|
+
yield* requireConnectable2(Integration.ID.make(ctx.payload.url.replace(/\/+$/, "")));
|
|
60
|
+
yield* wellknown.add(ctx.payload.url).pipe(Effect.mapError((error) => new InvalidRequestError({ message: error.message, kind: "well_known_discovery" })));
|
|
61
|
+
yield* integration.reload();
|
|
62
|
+
return HttpApiSchema.NoContent.make();
|
|
63
|
+
})).handle("integration.connect.key", Effect.fnUntraced(function* (ctx) {
|
|
64
|
+
yield* requireConnectable2(ctx.params.integrationID);
|
|
65
|
+
const service = yield* Integration.Service;
|
|
66
|
+
if (!(yield* service.get(ctx.params.integrationID)))
|
|
67
|
+
return yield* new IntegrationNotFoundError({
|
|
68
|
+
integrationID: ctx.params.integrationID,
|
|
69
|
+
message: `Integration not found: ${ctx.params.integrationID}`
|
|
70
|
+
});
|
|
71
|
+
yield* authorize(service.connection.key({
|
|
72
|
+
integrationID: ctx.params.integrationID,
|
|
73
|
+
key: ctx.payload.key,
|
|
74
|
+
answer: ctx.payload.answer,
|
|
75
|
+
label: ctx.payload.label
|
|
76
|
+
}));
|
|
77
|
+
return HttpApiSchema.NoContent.make();
|
|
78
|
+
})).handle("integration.connect.external", Effect.fnUntraced(function* (ctx) {
|
|
79
|
+
yield* requireConnectable2(ctx.params.integrationID);
|
|
80
|
+
const service = yield* Integration.Service;
|
|
81
|
+
if (!(yield* service.get(ctx.params.integrationID)))
|
|
82
|
+
return yield* new IntegrationNotFoundError({
|
|
83
|
+
integrationID: ctx.params.integrationID,
|
|
84
|
+
message: `Integration not found: ${ctx.params.integrationID}`
|
|
85
|
+
});
|
|
86
|
+
yield* authorize(service.connection.external({
|
|
87
|
+
integrationID: ctx.params.integrationID,
|
|
88
|
+
methodID: ctx.payload.methodID,
|
|
89
|
+
answer: ctx.payload.answer,
|
|
90
|
+
label: ctx.payload.label
|
|
91
|
+
}));
|
|
92
|
+
return HttpApiSchema.NoContent.make();
|
|
93
|
+
})).handle("integration.oauth.connect", Effect.fnUntraced(function* (ctx) {
|
|
94
|
+
yield* requireConnectable2(ctx.params.integrationID);
|
|
95
|
+
const service = yield* Integration.Service;
|
|
96
|
+
return yield* response2(authorize(service.oauth.connect({
|
|
97
|
+
integrationID: ctx.params.integrationID,
|
|
98
|
+
methodID: ctx.payload.methodID,
|
|
99
|
+
answer: ctx.payload.answer,
|
|
100
|
+
label: ctx.payload.label
|
|
101
|
+
})));
|
|
102
|
+
})).handle("integration.oauth.status", Effect.fnUntraced(function* (ctx) {
|
|
103
|
+
const service = yield* Integration.Service;
|
|
104
|
+
if (!(yield* service.get(ctx.params.integrationID)))
|
|
105
|
+
return yield* new IntegrationNotFoundError({
|
|
106
|
+
integrationID: ctx.params.integrationID,
|
|
107
|
+
message: `Integration not found: ${ctx.params.integrationID}`
|
|
108
|
+
});
|
|
109
|
+
return yield* response2(service.oauth.status({
|
|
110
|
+
integrationID: ctx.params.integrationID,
|
|
111
|
+
attemptID: ctx.params.attemptID
|
|
112
|
+
}).pipe(Effect.mapError((error) => new IntegrationAttemptNotFoundError({
|
|
113
|
+
integrationID: error.integrationID,
|
|
114
|
+
attemptID: error.attemptID,
|
|
115
|
+
message: `OAuth attempt not found: ${error.attemptID}`
|
|
116
|
+
}))));
|
|
117
|
+
})).handle("integration.oauth.complete", Effect.fnUntraced(function* (ctx) {
|
|
118
|
+
const service = yield* Integration.Service;
|
|
119
|
+
if (!(yield* service.get(ctx.params.integrationID)))
|
|
120
|
+
return yield* new IntegrationNotFoundError({
|
|
121
|
+
integrationID: ctx.params.integrationID,
|
|
122
|
+
message: `Integration not found: ${ctx.params.integrationID}`
|
|
123
|
+
});
|
|
124
|
+
yield* service.oauth.complete({
|
|
125
|
+
integrationID: ctx.params.integrationID,
|
|
126
|
+
attemptID: ctx.params.attemptID,
|
|
127
|
+
code: ctx.payload.code
|
|
128
|
+
}).pipe(Effect.mapError((error) => {
|
|
129
|
+
if (error._tag === "Integration.AttemptNotFound")
|
|
130
|
+
return new IntegrationAttemptNotFoundError({
|
|
131
|
+
integrationID: error.integrationID,
|
|
132
|
+
attemptID: error.attemptID,
|
|
133
|
+
message: `OAuth attempt not found: ${error.attemptID}`
|
|
134
|
+
});
|
|
135
|
+
if (error._tag === "Integration.CodeRequired")
|
|
136
|
+
return new InvalidRequestError({
|
|
137
|
+
message: "Authorization code is required",
|
|
138
|
+
kind: "integration_code_required"
|
|
139
|
+
});
|
|
140
|
+
return new InvalidRequestError({
|
|
141
|
+
message: error.cause instanceof Error && error.cause.message.trim() ? error.cause.message : "Authentication failed",
|
|
142
|
+
kind: "integration_authorization"
|
|
143
|
+
});
|
|
144
|
+
}));
|
|
145
|
+
return HttpApiSchema.NoContent.make();
|
|
146
|
+
})).handle("integration.oauth.cancel", Effect.fnUntraced(function* (ctx) {
|
|
147
|
+
const service = yield* Integration.Service;
|
|
148
|
+
yield* service.oauth.cancel({
|
|
149
|
+
integrationID: ctx.params.integrationID,
|
|
150
|
+
attemptID: ctx.params.attemptID
|
|
151
|
+
});
|
|
152
|
+
return HttpApiSchema.NoContent.make();
|
|
153
|
+
})).handle("integration.command.connect", Effect.fnUntraced(function* (ctx) {
|
|
154
|
+
yield* requireConnectable2(ctx.params.integrationID);
|
|
155
|
+
const service = yield* Integration.Service;
|
|
156
|
+
const integration = yield* service.get(ctx.params.integrationID);
|
|
157
|
+
if (!integration)
|
|
158
|
+
return yield* new IntegrationNotFoundError({
|
|
159
|
+
integrationID: ctx.params.integrationID,
|
|
160
|
+
message: `Integration not found: ${ctx.params.integrationID}`
|
|
161
|
+
});
|
|
162
|
+
if (!integration.methods.some((method) => method.type === "command" && method.id === ctx.payload.methodID))
|
|
163
|
+
return yield* new IntegrationMethodNotFoundError({
|
|
164
|
+
integrationID: ctx.params.integrationID,
|
|
165
|
+
methodID: ctx.payload.methodID,
|
|
166
|
+
message: `Integration method not found: ${ctx.payload.methodID}`
|
|
167
|
+
});
|
|
168
|
+
return yield* response2(authorize(service.command.connect({
|
|
169
|
+
integrationID: ctx.params.integrationID,
|
|
170
|
+
methodID: ctx.payload.methodID,
|
|
171
|
+
label: ctx.payload.label
|
|
172
|
+
})));
|
|
173
|
+
})).handle("integration.command.status", Effect.fnUntraced(function* (ctx) {
|
|
174
|
+
const service = yield* Integration.Service;
|
|
175
|
+
if (!(yield* service.get(ctx.params.integrationID)))
|
|
176
|
+
return yield* new IntegrationNotFoundError({
|
|
177
|
+
integrationID: ctx.params.integrationID,
|
|
178
|
+
message: `Integration not found: ${ctx.params.integrationID}`
|
|
179
|
+
});
|
|
180
|
+
return yield* response2(service.command.status({
|
|
181
|
+
integrationID: ctx.params.integrationID,
|
|
182
|
+
attemptID: ctx.params.attemptID
|
|
183
|
+
}).pipe(Effect.mapError((error) => new IntegrationAttemptNotFoundError({
|
|
184
|
+
integrationID: error.integrationID,
|
|
185
|
+
attemptID: error.attemptID,
|
|
186
|
+
message: `Command attempt not found: ${error.attemptID}`
|
|
187
|
+
}))));
|
|
188
|
+
})).handle("integration.command.cancel", Effect.fnUntraced(function* (ctx) {
|
|
189
|
+
const service = yield* Integration.Service;
|
|
190
|
+
yield* service.command.cancel({
|
|
191
|
+
integrationID: ctx.params.integrationID,
|
|
192
|
+
attemptID: ctx.params.attemptID
|
|
193
|
+
});
|
|
194
|
+
return HttpApiSchema.NoContent.make();
|
|
195
|
+
}));
|
|
196
|
+
}));
|
|
197
|
+
|
|
198
|
+
export { requireConnectable2, IntegrationHandler2 };
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import {
|
|
2
|
+
response2
|
|
3
|
+
} from "./api-0q8mvh3b.js";
|
|
4
|
+
import {
|
|
5
|
+
Api2
|
|
6
|
+
} from "./api-f6955nmc.js";
|
|
7
|
+
|
|
8
|
+
// src/handlers/vcs.ts
|
|
9
|
+
import { Vcs } from "@radheim/core/vcs";
|
|
10
|
+
import { Project } from "@radheim/core/project";
|
|
11
|
+
import { Worktree } from "@radheim/core/worktree";
|
|
12
|
+
import { Bus } from "@radheim/core/bus";
|
|
13
|
+
import { Location } from "@radheim/core/location";
|
|
14
|
+
import { LocationServiceMap } from "@radheim/core/location-services";
|
|
15
|
+
import { ConflictError, InvalidRequestError, ServiceUnavailableError } from "@radheim/protocol/errors";
|
|
16
|
+
import { VcsInitNotSupportedError } from "@radheim/protocol/groups/vcs";
|
|
17
|
+
import { Effect } from "effect";
|
|
18
|
+
import { HttpApiBuilder, HttpApiSchema } from "effect/http-api";
|
|
19
|
+
var VcsHandler2 = HttpApiBuilder.group(Api2, "server.vcs", (handlers) => Effect.gen(function* () {
|
|
20
|
+
const project = yield* Project.Service;
|
|
21
|
+
const bus = yield* Bus.Service;
|
|
22
|
+
const locations = yield* LocationServiceMap.Service;
|
|
23
|
+
return handlers.handle("vcs.init", (ctx) => Effect.gen(function* () {
|
|
24
|
+
const location = yield* Location.Service;
|
|
25
|
+
const directory = location.project.directory;
|
|
26
|
+
const providerID = ctx.query.provider ?? "git";
|
|
27
|
+
const vcs = yield* Vcs.Service;
|
|
28
|
+
yield* vcs.initialize(providerID).pipe(Effect.mapError((error) => {
|
|
29
|
+
if (error.kind === "missing")
|
|
30
|
+
return new InvalidRequestError({ message: "Project directory does not exist", field: "location" });
|
|
31
|
+
if (error.kind === "conflict")
|
|
32
|
+
return new ConflictError({ message: "Project already has version control", resource: directory });
|
|
33
|
+
if (error.kind === "unknown")
|
|
34
|
+
return new InvalidRequestError({
|
|
35
|
+
message: "Unknown VCS provider",
|
|
36
|
+
field: "provider"
|
|
37
|
+
});
|
|
38
|
+
if (error.kind === "unsupported")
|
|
39
|
+
return new VcsInitNotSupportedError({
|
|
40
|
+
providerID,
|
|
41
|
+
message: "VCS provider does not support initialization"
|
|
42
|
+
});
|
|
43
|
+
return new ServiceUnavailableError({ service: providerID, message: "VCS initialization failed" });
|
|
44
|
+
}));
|
|
45
|
+
const resolved = yield* project.resolve(directory, { local: location.workspaceID === undefined });
|
|
46
|
+
if (!resolved.vcs)
|
|
47
|
+
return yield* new ServiceUnavailableError({ service: providerID, message: "VCS initialization failed" });
|
|
48
|
+
yield* locations.invalidate(Location.Ref.make({ directory: location.directory, workspaceID: location.workspaceID }));
|
|
49
|
+
yield* bus.publish(Worktree.Event.Updated, { projectID: resolved.id });
|
|
50
|
+
return HttpApiSchema.NoContent.make();
|
|
51
|
+
})).handle("vcs.get", () => response2(Effect.gen(function* () {
|
|
52
|
+
const vcs = yield* Vcs.Service;
|
|
53
|
+
return yield* vcs.info();
|
|
54
|
+
}))).handle("vcs.base", () => response2(Effect.gen(function* () {
|
|
55
|
+
const vcs = yield* Vcs.Service;
|
|
56
|
+
return yield* vcs.base().pipe(Effect.mapError((error) => new ServiceUnavailableError({ service: "vcs", message: error.message })));
|
|
57
|
+
}))).handle("vcs.status", () => response2(Effect.gen(function* () {
|
|
58
|
+
const vcs = yield* Vcs.Service;
|
|
59
|
+
return yield* vcs.status();
|
|
60
|
+
}))).handle("vcs.branch.list", (ctx) => response2(Effect.gen(function* () {
|
|
61
|
+
const vcs = yield* Vcs.Service;
|
|
62
|
+
return yield* vcs.branches({ search: ctx.query.search, limit: Math.min(ctx.query.limit ?? 50, 100) });
|
|
63
|
+
}))).handle("vcs.diff", (ctx) => response2(Effect.gen(function* () {
|
|
64
|
+
const vcs = yield* Vcs.Service;
|
|
65
|
+
return yield* vcs.diff(ctx.query.mode, {
|
|
66
|
+
context: ctx.query.context,
|
|
67
|
+
base: ctx.query.base,
|
|
68
|
+
untracked: ctx.query.untracked
|
|
69
|
+
}).pipe(Effect.mapError((error) => new ServiceUnavailableError({ service: "vcs", message: error.message })));
|
|
70
|
+
})));
|
|
71
|
+
}));
|
|
72
|
+
|
|
73
|
+
export { VcsHandler2 };
|
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Api2
|
|
3
|
+
} from "./api-f6955nmc.js";
|
|
4
|
+
import {
|
|
5
|
+
CorsConfig2,
|
|
6
|
+
isAllowedRequestOrigin2
|
|
7
|
+
} from "./api-11hx8jza.js";
|
|
8
|
+
import {
|
|
9
|
+
makeArtifact2
|
|
10
|
+
} from "./api-v2h85c6p.js";
|
|
11
|
+
import {
|
|
12
|
+
makeBlob2
|
|
13
|
+
} from "./api-d4cyxj7e.js";
|
|
14
|
+
import {
|
|
15
|
+
makeBrowserTunnel2
|
|
16
|
+
} from "./api-gghkbyq2.js";
|
|
17
|
+
import {
|
|
18
|
+
makeAutomation2
|
|
19
|
+
} from "./api-9bxtygz0.js";
|
|
20
|
+
import {
|
|
21
|
+
makeJob2
|
|
22
|
+
} from "./api-1jnx79t4.js";
|
|
23
|
+
import {
|
|
24
|
+
makeMachineLink2,
|
|
25
|
+
makeMachine2
|
|
26
|
+
} from "./api-238wcyzf.js";
|
|
27
|
+
import {
|
|
28
|
+
makeMediaGet2
|
|
29
|
+
} from "./api-ns3kfwpq.js";
|
|
30
|
+
import {
|
|
31
|
+
makePush2
|
|
32
|
+
} from "./api-e4v11dgy.js";
|
|
33
|
+
import {
|
|
34
|
+
makeSpace2
|
|
35
|
+
} from "./api-h8v4dbra.js";
|
|
36
|
+
import {
|
|
37
|
+
runPtySocket2
|
|
38
|
+
} from "./api-zvb9sh2w.js";
|
|
39
|
+
|
|
40
|
+
// src/handlers/persistent-pty.ts
|
|
41
|
+
import { PersistentPty } from "@radheim/core/persistent-pty";
|
|
42
|
+
import { PtyTicket } from "@radheim/core/pty/ticket";
|
|
43
|
+
import {
|
|
44
|
+
ForbiddenError,
|
|
45
|
+
InvalidRequestError,
|
|
46
|
+
PtyNotFoundError,
|
|
47
|
+
ServiceUnavailableError
|
|
48
|
+
} from "@radheim/protocol/errors";
|
|
49
|
+
import {
|
|
50
|
+
PTY_CONNECT_TICKET_QUERY,
|
|
51
|
+
PTY_CONNECT_TOKEN_HEADER,
|
|
52
|
+
PTY_CONNECT_TOKEN_HEADER_VALUE
|
|
53
|
+
} from "@radheim/protocol/groups/persistent-pty";
|
|
54
|
+
import { Effect, Queue } from "effect";
|
|
55
|
+
import { HttpServerRequest, HttpServerResponse } from "effect/http";
|
|
56
|
+
import { HttpApiBuilder, HttpApiSchema } from "effect/http-api";
|
|
57
|
+
import { Socket } from "effect/socket";
|
|
58
|
+
var PersistentPtyHandler2 = HttpApiBuilder.group(Api2, "server.experimental", (handlers) => Effect.gen(function* () {
|
|
59
|
+
const tickets = yield* PtyTicket.Service;
|
|
60
|
+
const cors = yield* CorsConfig2;
|
|
61
|
+
const pty = yield* PersistentPty.Service;
|
|
62
|
+
const artifact = yield* makeArtifact2;
|
|
63
|
+
const job = yield* makeJob2;
|
|
64
|
+
const space = yield* makeSpace2;
|
|
65
|
+
const mediaGet = yield* makeMediaGet2;
|
|
66
|
+
const blob = yield* makeBlob2;
|
|
67
|
+
const automation = yield* makeAutomation2;
|
|
68
|
+
const machine = yield* makeMachine2;
|
|
69
|
+
const machineLink = yield* makeMachineLink2;
|
|
70
|
+
const browserTunnel = yield* makeBrowserTunnel2;
|
|
71
|
+
const push = yield* makePush2;
|
|
72
|
+
return handlers.handleRaw("media.get", (ctx) => mediaGet(ctx.params.hash, ctx.request)).handle("blob.list", (ctx) => blob.list(ctx.query)).handleRaw("blob.create", (ctx) => blob.create(ctx.query, ctx.request)).handle("blob.get", (ctx) => blob.get(ctx.params.blobID)).handleRaw("blob.content", (ctx) => blob.content(ctx.params.blobID, ctx.request)).handle("blob.update", (ctx) => blob.update(ctx.params.blobID, ctx.payload)).handle("blob.remove", (ctx) => blob.remove(ctx.params.blobID)).handleRaw("browser.tunnel", (ctx) => browserTunnel(ctx.request)).handle("job.list", (ctx) => job.list(ctx.query)).handle("job.cancel", (ctx) => job.cancel(ctx.params.id)).handleRaw("machine.link", (ctx) => machineLink(ctx.request)).handle("machine.list", () => machine.list()).handle("machine.add", (ctx) => machine.add(ctx.payload)).handle("machine.remove", (ctx) => machine.remove(ctx.params.name)).handle("machine.update", (ctx) => machine.update(ctx.params.name, ctx.payload)).handle("push.get", () => push.get()).handle("push.device.register", (ctx) => push.register(ctx.params.deviceID, ctx.payload)).handle("push.device.remove", (ctx) => push.remove(ctx.params.deviceID)).handle("push.device.update", (ctx) => push.update(ctx.params.deviceID, ctx.payload)).handle("push.device.session.set", (ctx) => push.setDeviceBell(ctx.params.deviceID, ctx.params.sessionID, ctx.payload)).handle("push.device.session.remove", (ctx) => push.removeDeviceBell(ctx.params.deviceID, ctx.params.sessionID)).handle("push.session.set", (ctx) => push.setSessionBell(ctx.params.sessionID, ctx.payload)).handle("push.session.remove", (ctx) => push.removeSessionBell(ctx.params.sessionID)).handle("push.settings.set", (ctx) => push.setSettings(ctx.payload)).handle("space.write", (ctx) => space.write(ctx.payload.changes)).handle("space.sync", (ctx) => space.sync(ctx.payload.spaces)).handle("space.subscribe", (ctx) => space.subscribe(ctx.payload)).handle("space.unsubscribe", (ctx) => space.unsubscribe(ctx.payload)).handle("space.reset", () => space.reset()).handle("artifacts.providers", (ctx) => artifact.providers(ctx.query, ctx.request)).handle("artifacts.list", (ctx) => artifact.list(ctx.query, ctx.request)).handle("artifacts.create", (ctx) => artifact.create(ctx.query, ctx.payload, ctx.request)).handle("artifacts.get", (ctx) => artifact.get(ctx.params.artifactID, ctx.query, ctx.request)).handle("artifacts.update", (ctx) => artifact.update(ctx.params.artifactID, ctx.query, ctx.payload, ctx.request)).handle("artifacts.delete", (ctx) => artifact.remove(ctx.params.artifactID, ctx.query, ctx.request)).handleRaw("artifacts.view", (ctx) => artifact.view(ctx.params.artifactID, ctx.query, ctx.request)).handle("automation.create", (ctx) => automation.create(ctx.payload)).handle("automation.list", (ctx) => automation.list(ctx.query)).handle("automation.get", (ctx) => automation.get(ctx.params.automationID)).handle("automation.pause", (ctx) => automation.pause(ctx.params.automationID)).handle("automation.resume", (ctx) => automation.resume(ctx.params.automationID)).handle("automation.delete", (ctx) => automation.remove(ctx.params.automationID)).handle("persistentPty.read", Effect.fnUntraced(function* (ctx) {
|
|
73
|
+
return { data: yield* pty.read(ctx.params.sessionID, ctx.query.lines).pipe(mapUnavailable) };
|
|
74
|
+
})).handle("persistentPty.list", Effect.fnUntraced(function* (ctx) {
|
|
75
|
+
return { data: yield* pty.list(ctx.params.sessionID).pipe(mapUnavailable) };
|
|
76
|
+
})).handle("persistentPty.create", Effect.fnUntraced(function* (ctx) {
|
|
77
|
+
return {
|
|
78
|
+
data: yield* pty.create(ctx.params.sessionID, {
|
|
79
|
+
command: ctx.payload.command,
|
|
80
|
+
args: ctx.payload.args,
|
|
81
|
+
cwd: ctx.payload.cwd,
|
|
82
|
+
title: ctx.payload.title,
|
|
83
|
+
env: ctx.payload.env,
|
|
84
|
+
cols: ctx.payload.size?.cols,
|
|
85
|
+
rows: ctx.payload.size?.rows
|
|
86
|
+
}).pipe(Effect.catchTags({
|
|
87
|
+
"PersistentPty.InvalidCwdError": (error) => new InvalidRequestError({ message: error.message, kind: "invalid_cwd", field: "cwd" }),
|
|
88
|
+
"PersistentPty.UnavailableError": unavailable
|
|
89
|
+
}))
|
|
90
|
+
};
|
|
91
|
+
})).handle("persistentPty.shutdown", Effect.fnUntraced(function* () {
|
|
92
|
+
yield* pty.shutdown().pipe(mapUnavailable);
|
|
93
|
+
return HttpApiSchema.NoContent.make();
|
|
94
|
+
})).handle("persistentPty.handoff", Effect.fnUntraced(function* () {
|
|
95
|
+
return { handoff: yield* pty.handoff().pipe(mapUnavailable) };
|
|
96
|
+
})).handle("persistentPty.get", Effect.fnUntraced(function* (ctx) {
|
|
97
|
+
return { data: yield* pty.get(ctx.params.ptyID).pipe(mapTerminalError) };
|
|
98
|
+
})).handle("persistentPty.update", Effect.fnUntraced(function* (ctx) {
|
|
99
|
+
if (ctx.payload.size)
|
|
100
|
+
yield* pty.resize(ctx.params.ptyID, ctx.payload.size.cols, ctx.payload.size.rows, ctx.payload.attachmentID).pipe(mapTerminalError);
|
|
101
|
+
if (ctx.payload.title === undefined)
|
|
102
|
+
return { data: yield* pty.get(ctx.params.ptyID).pipe(mapTerminalError) };
|
|
103
|
+
return { data: yield* pty.rename(ctx.params.ptyID, ctx.payload.title).pipe(mapTerminalError) };
|
|
104
|
+
})).handle("persistentPty.snapshot", Effect.fnUntraced(function* (ctx) {
|
|
105
|
+
return { data: yield* pty.snapshot(ctx.params.ptyID).pipe(mapTerminalError) };
|
|
106
|
+
})).handle("persistentPty.remove", Effect.fnUntraced(function* (ctx) {
|
|
107
|
+
yield* pty.remove(ctx.params.ptyID).pipe(mapTerminalError);
|
|
108
|
+
return HttpApiSchema.NoContent.make();
|
|
109
|
+
})).handle("persistentPty.connectToken", Effect.fnUntraced(function* (ctx) {
|
|
110
|
+
const request = yield* HttpServerRequest.HttpServerRequest;
|
|
111
|
+
if (request.headers[PTY_CONNECT_TOKEN_HEADER] !== PTY_CONNECT_TOKEN_HEADER_VALUE || !isAllowedRequestOrigin2(request.headers.origin, request.headers.host, cors))
|
|
112
|
+
return yield* new ForbiddenError({ message: "Invalid persistent PTY connect token request" });
|
|
113
|
+
yield* pty.get(ctx.params.ptyID).pipe(mapTerminalError);
|
|
114
|
+
return { data: yield* tickets.issue({ ptyID: ctx.params.ptyID }) };
|
|
115
|
+
})).handleRaw("persistentPty.connect", Effect.fn("PersistentPtyHandler.connect")(function* (ctx) {
|
|
116
|
+
if (!isAllowedRequestOrigin2(ctx.request.headers.origin, ctx.request.headers.host, cors))
|
|
117
|
+
return HttpServerResponse.empty({ status: 403 });
|
|
118
|
+
const url = new URL(ctx.request.url, "http://localhost");
|
|
119
|
+
const ticket = url.searchParams.get(PTY_CONNECT_TICKET_QUERY);
|
|
120
|
+
if (ticket && !(yield* tickets.consume({ ticket, ptyID: ctx.params.ptyID })))
|
|
121
|
+
return HttpServerResponse.empty({ status: 403 });
|
|
122
|
+
const cursor = Number(url.searchParams.get("cursor") ?? "0");
|
|
123
|
+
const role = url.searchParams.get("role") === "observer" ? "observer" : "controller";
|
|
124
|
+
const framedInput = url.searchParams.get("input_protocol") === "1";
|
|
125
|
+
const attachmentID = url.searchParams.get("attachment_id") ?? crypto.randomUUID();
|
|
126
|
+
if (!Number.isSafeInteger(cursor) || cursor < 0)
|
|
127
|
+
return HttpServerResponse.empty({ status: 400 });
|
|
128
|
+
const socket = yield* Effect.orDie(ctx.request.upgrade);
|
|
129
|
+
const outbox = yield* Queue.unbounded();
|
|
130
|
+
let attachment;
|
|
131
|
+
const onOpen = Effect.gen(function* () {
|
|
132
|
+
attachment = yield* pty.attach(ctx.params.ptyID, {
|
|
133
|
+
cursor,
|
|
134
|
+
attachmentID,
|
|
135
|
+
role,
|
|
136
|
+
takeover: url.searchParams.get("takeover") === "true",
|
|
137
|
+
onEvent: (event) => {
|
|
138
|
+
if (event.type === "output")
|
|
139
|
+
Queue.offerUnsafe(outbox, event.data);
|
|
140
|
+
if (event.type === "resized")
|
|
141
|
+
Queue.offerUnsafe(outbox, JSON.stringify({ ...event, checkpoint: Buffer.from(event.checkpoint).toString("base64") }));
|
|
142
|
+
if (event.type !== "output" && event.type !== "resized")
|
|
143
|
+
Queue.offerUnsafe(outbox, JSON.stringify(event));
|
|
144
|
+
},
|
|
145
|
+
onEnd: () => Queue.offerUnsafe(outbox, new Socket.CloseEvent(1000))
|
|
146
|
+
}).pipe(Effect.catchTags({
|
|
147
|
+
"PersistentPty.NotFoundError": () => Effect.succeed(undefined),
|
|
148
|
+
"PersistentPty.UnavailableError": () => Effect.succeed(undefined)
|
|
149
|
+
}));
|
|
150
|
+
if (!attachment) {
|
|
151
|
+
Queue.offerUnsafe(outbox, new Socket.CloseEvent(4404, "terminal unavailable"));
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
Queue.offerUnsafe(outbox, JSON.stringify({
|
|
155
|
+
type: "attached",
|
|
156
|
+
attachmentID,
|
|
157
|
+
inputProtocol: framedInput ? 1 : 0,
|
|
158
|
+
info: attachment.info,
|
|
159
|
+
role: attachment.role,
|
|
160
|
+
generation: attachment.generation,
|
|
161
|
+
replay: {
|
|
162
|
+
requestedOffset: attachment.replay.requestedOffset,
|
|
163
|
+
availableOffset: attachment.replay.availableOffset,
|
|
164
|
+
endOffset: attachment.replay.endOffset,
|
|
165
|
+
truncated: attachment.replay.truncated
|
|
166
|
+
}
|
|
167
|
+
}));
|
|
168
|
+
if (attachment.replay.data.length > 0)
|
|
169
|
+
Queue.offerUnsafe(outbox, attachment.replay.data);
|
|
170
|
+
Queue.offerUnsafe(outbox, JSON.stringify({ type: "replay_complete", endOffset: attachment.replay.endOffset }));
|
|
171
|
+
attachment.activate();
|
|
172
|
+
});
|
|
173
|
+
yield* runPtySocket2({
|
|
174
|
+
socket,
|
|
175
|
+
outbox,
|
|
176
|
+
onOpen,
|
|
177
|
+
onMessage: (message) => {
|
|
178
|
+
if (!attachment)
|
|
179
|
+
return Effect.void;
|
|
180
|
+
const data = typeof message === "string" ? Buffer.from(message) : message;
|
|
181
|
+
if (!framedInput)
|
|
182
|
+
return pty.input(ctx.params.ptyID, attachmentID, attachment.info.size.cols, attachment.info.size.rows, data).pipe(Effect.ignore);
|
|
183
|
+
if (data.byteLength < 5)
|
|
184
|
+
return Effect.void;
|
|
185
|
+
const view = new DataView(data.buffer, data.byteOffset, data.byteLength);
|
|
186
|
+
const type = data[0];
|
|
187
|
+
const cols = view.getUint16(1);
|
|
188
|
+
const rows = view.getUint16(3);
|
|
189
|
+
if (type !== 0 && type !== 1 || cols === 0 || rows === 0)
|
|
190
|
+
return Effect.void;
|
|
191
|
+
if (type === 0)
|
|
192
|
+
return pty.control(ctx.params.ptyID, attachmentID, cols, rows).pipe(Effect.ignore);
|
|
193
|
+
return pty.input(ctx.params.ptyID, attachmentID, cols, rows, data.subarray(5)).pipe(Effect.ignore);
|
|
194
|
+
},
|
|
195
|
+
detach: () => attachment?.detach()
|
|
196
|
+
});
|
|
197
|
+
return HttpServerResponse.empty();
|
|
198
|
+
}));
|
|
199
|
+
}));
|
|
200
|
+
var mapUnavailable = (effect) => effect.pipe(Effect.catchTag("PersistentPty.UnavailableError", unavailable));
|
|
201
|
+
var mapTerminalError = (effect) => effect.pipe(Effect.catchTags({
|
|
202
|
+
"PersistentPty.NotFoundError": notFound,
|
|
203
|
+
"PersistentPty.UnavailableError": unavailable
|
|
204
|
+
}));
|
|
205
|
+
var notFound = (error) => new PtyNotFoundError({ ptyID: error.ptyID, message: `PTY session not found: ${error.ptyID}` });
|
|
206
|
+
var unavailable = (error) => new ServiceUnavailableError({ message: error.message, service: "opencode-pty" });
|
|
207
|
+
|
|
208
|
+
export { PersistentPtyHandler2 };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import {
|
|
2
|
+
response2
|
|
3
|
+
} from "./api-0q8mvh3b.js";
|
|
4
|
+
import {
|
|
5
|
+
Api2
|
|
6
|
+
} from "./api-f6955nmc.js";
|
|
7
|
+
|
|
8
|
+
// src/handlers/flag.ts
|
|
9
|
+
import { Flag } from "@radheim/core/flag";
|
|
10
|
+
import { ConfigFlag } from "@radheim/schema/config/flag";
|
|
11
|
+
import { Effect } from "effect";
|
|
12
|
+
import { HttpApiBuilder } from "effect/http-api";
|
|
13
|
+
var FlagHandler2 = HttpApiBuilder.group(Api2, "server.flag", (handlers) => Effect.gen(function* () {
|
|
14
|
+
return handlers.handle("experimental.flag.get", Effect.fn("server.flag.get")(function* () {
|
|
15
|
+
const flags = yield* Flag.Service;
|
|
16
|
+
return yield* response2(flags.all.pipe(Effect.map((all) => Object.fromEntries(ConfigFlag.ui.map((key) => [key, all[key].enabled])))));
|
|
17
|
+
}));
|
|
18
|
+
}));
|
|
19
|
+
|
|
20
|
+
export { FlagHandler2 };
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import {
|
|
2
|
+
locationErrors2,
|
|
3
|
+
sessionInfo2
|
|
4
|
+
} from "./api-0q8mvh3b.js";
|
|
5
|
+
|
|
6
|
+
// src/middleware/session-location.ts
|
|
7
|
+
import { Instance } from "@radheim/core/instance/service";
|
|
8
|
+
import { Session } from "@radheim/core/session";
|
|
9
|
+
import { Effect, Layer } from "effect";
|
|
10
|
+
import { HttpRouter } from "effect/http";
|
|
11
|
+
import { HttpApiMiddleware } from "effect/http-api";
|
|
12
|
+
import { LocationNotFoundError, InvalidRequestError, SessionNotFoundError } from "@radheim/protocol/errors";
|
|
13
|
+
class SessionLocationMiddleware2 extends HttpApiMiddleware.Service()("@radheim/HttpApiSessionLocation", {
|
|
14
|
+
error: [InvalidRequestError, SessionNotFoundError, LocationNotFoundError]
|
|
15
|
+
}) {
|
|
16
|
+
}
|
|
17
|
+
var sessionLocationLayer2 = Layer.effect(SessionLocationMiddleware2, Effect.gen(function* () {
|
|
18
|
+
const sessions = yield* Session.Service;
|
|
19
|
+
const instances = yield* Instance.Service;
|
|
20
|
+
return SessionLocationMiddleware2.of((effect) => Effect.gen(function* () {
|
|
21
|
+
const route = yield* HttpRouter.RouteContext;
|
|
22
|
+
const session = yield* sessionInfo2(sessions, route.params.sessionID);
|
|
23
|
+
return yield* effect.pipe(instances.provide(session), locationErrors2);
|
|
24
|
+
}));
|
|
25
|
+
}));
|
|
26
|
+
|
|
27
|
+
export { SessionLocationMiddleware2, sessionLocationLayer2 };
|