@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,270 @@
|
|
|
1
|
+
import {
|
|
2
|
+
MAX_HANDSHAKES2,
|
|
3
|
+
MAX_FRAME2,
|
|
4
|
+
MIN_FRAME2,
|
|
5
|
+
CLOSE2,
|
|
6
|
+
machinesEnabled2
|
|
7
|
+
} from "./api-238wcyzf.js";
|
|
8
|
+
import {
|
|
9
|
+
rejected2
|
|
10
|
+
} from "./api-8tn84h85.js";
|
|
11
|
+
import {
|
|
12
|
+
__export
|
|
13
|
+
} from "./api-9rqn6x4v.js";
|
|
14
|
+
|
|
15
|
+
// src/workerd-machine-link.ts
|
|
16
|
+
var exports_workerd_machine_link = {};
|
|
17
|
+
__export(exports_workerd_machine_link, {
|
|
18
|
+
TAG: () => TAG2,
|
|
19
|
+
WorkerdMachineLink: () => exports_workerd_machine_link,
|
|
20
|
+
carrier: () => carrier2,
|
|
21
|
+
isUpgrade: () => isUpgrade2,
|
|
22
|
+
make: () => make2,
|
|
23
|
+
serve: () => serve2
|
|
24
|
+
});
|
|
25
|
+
import { Link } from "@radheim/core/machine/link";
|
|
26
|
+
import { Machines } from "@radheim/core/machine/machines";
|
|
27
|
+
import { MACHINE_LINK_PATH } from "@radheim/protocol/groups/machine";
|
|
28
|
+
import { Effect, Option, Queue, Schema, Semaphore, Struct } from "effect";
|
|
29
|
+
import { HttpServerRequest } from "effect/http";
|
|
30
|
+
var MAX_WAITING = 8 * 1024 * 1024;
|
|
31
|
+
var TOO_BIG = 1009;
|
|
32
|
+
var OPEN = 1;
|
|
33
|
+
var CLOSING = 2;
|
|
34
|
+
var sendable = (code) => code >= 1000 && code <= 1014 && code !== 1004 && code !== 1005 && code !== 1006 || code >= 3000 && code <= 4999;
|
|
35
|
+
var closeQuietly = (socket, code) => {
|
|
36
|
+
try {
|
|
37
|
+
socket.close(code);
|
|
38
|
+
} catch {}
|
|
39
|
+
};
|
|
40
|
+
var clearAttachment = (socket) => {
|
|
41
|
+
try {
|
|
42
|
+
socket.serializeAttachment(null);
|
|
43
|
+
} catch {}
|
|
44
|
+
};
|
|
45
|
+
var readAttachment = (socket) => {
|
|
46
|
+
try {
|
|
47
|
+
return socket.deserializeAttachment();
|
|
48
|
+
} catch {
|
|
49
|
+
return null;
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
var KEEPALIVE = 25000;
|
|
53
|
+
var TAG2 = "opencode-machine-link";
|
|
54
|
+
var Attachment = Schema.Struct({ v: Schema.Literal(1), ...Link.Resumable.fields });
|
|
55
|
+
var encodeAttachment = Schema.encodeSync(Attachment);
|
|
56
|
+
var decodeAttachment = Schema.decodeUnknownOption(Attachment);
|
|
57
|
+
var claimed = new WeakMap;
|
|
58
|
+
var claimsOf = (state) => {
|
|
59
|
+
const found = claimed.get(state);
|
|
60
|
+
if (found)
|
|
61
|
+
return found;
|
|
62
|
+
const made = new WeakSet;
|
|
63
|
+
claimed.set(state, made);
|
|
64
|
+
return made;
|
|
65
|
+
};
|
|
66
|
+
var make2 = (options = {}, fixed = {}) => Effect.gen(function* () {
|
|
67
|
+
const enabled = yield* machinesEnabled2;
|
|
68
|
+
const services = yield* Effect.context();
|
|
69
|
+
const scope = yield* Effect.scope;
|
|
70
|
+
const handshakes = Semaphore.makeUnsafe(MAX_HANDSHAKES2);
|
|
71
|
+
const state = options.state;
|
|
72
|
+
const claims = state ? claimsOf(state) : new WeakSet;
|
|
73
|
+
const inboxes = new Map;
|
|
74
|
+
const busy = new Set;
|
|
75
|
+
const awake = {};
|
|
76
|
+
const hold = (socket, working) => {
|
|
77
|
+
if (working)
|
|
78
|
+
busy.add(socket);
|
|
79
|
+
if (!working)
|
|
80
|
+
busy.delete(socket);
|
|
81
|
+
if (busy.size > 0 && !awake.timer)
|
|
82
|
+
awake.timer = setInterval(() => {}, KEEPALIVE);
|
|
83
|
+
if (busy.size === 0 && awake.timer) {
|
|
84
|
+
clearInterval(awake.timer);
|
|
85
|
+
awake.timer = undefined;
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
yield* Effect.addFinalizer(() => Effect.sync(() => {
|
|
89
|
+
busy.clear();
|
|
90
|
+
clearInterval(awake.timer);
|
|
91
|
+
awake.timer = undefined;
|
|
92
|
+
}));
|
|
93
|
+
const hibernating = (socket) => Effect.acquireRelease(Effect.gen(function* () {
|
|
94
|
+
const held = yield* inbox(socket);
|
|
95
|
+
claims.add(socket);
|
|
96
|
+
inboxes.set(socket, held);
|
|
97
|
+
return { ...held, keeper: keeper(socket, hold) };
|
|
98
|
+
}), (held) => Effect.sync(() => {
|
|
99
|
+
claims.delete(socket);
|
|
100
|
+
inboxes.delete(socket);
|
|
101
|
+
hold(socket, false);
|
|
102
|
+
clearAttachment(socket);
|
|
103
|
+
held.end(CLOSE2);
|
|
104
|
+
}));
|
|
105
|
+
for (const socket of state?.getWebSockets(TAG2) ?? []) {
|
|
106
|
+
if (claims.has(socket))
|
|
107
|
+
continue;
|
|
108
|
+
if (socket.readyState !== OPEN) {
|
|
109
|
+
clearAttachment(socket);
|
|
110
|
+
continue;
|
|
111
|
+
}
|
|
112
|
+
yield* Effect.gen(function* () {
|
|
113
|
+
const held = yield* hibernating(socket);
|
|
114
|
+
const saved = decodeAttachment(readAttachment(socket));
|
|
115
|
+
if (Option.isNone(saved))
|
|
116
|
+
return;
|
|
117
|
+
const link = yield* Link.resume(held.carrier, saved.value, fixed, { persist: held.keeper.persist });
|
|
118
|
+
const machines = yield* Machines.Service;
|
|
119
|
+
yield* Effect.raceFirst(machines.connect(link.machine, { ...link.connection, busy: held.keeper.busy }), Effect.flatMap(enabled, (on) => on ? Effect.never : Effect.void));
|
|
120
|
+
}).pipe(Effect.ignore, Effect.scoped, Effect.provide(services), Effect.forkIn(scope, { startImmediately: true }));
|
|
121
|
+
}
|
|
122
|
+
const accept = (pair, release) => {
|
|
123
|
+
if (!state) {
|
|
124
|
+
pair[1].accept();
|
|
125
|
+
return serve2(pair[1], release, fixed);
|
|
126
|
+
}
|
|
127
|
+
state.acceptWebSocket(pair[1], [TAG2]);
|
|
128
|
+
return Effect.gen(function* () {
|
|
129
|
+
const held = yield* hibernating(pair[1]);
|
|
130
|
+
const link = yield* Link.serve(held.carrier, fixed, { persist: held.keeper.persist }).pipe(Effect.ensuring(release));
|
|
131
|
+
const machines = yield* Machines.Service;
|
|
132
|
+
yield* machines.connect(link.machine, { ...link.connection, busy: held.keeper.busy });
|
|
133
|
+
}).pipe(Effect.ensuring(release), Effect.ignore, Effect.scoped);
|
|
134
|
+
};
|
|
135
|
+
const upgrade = Effect.fn("WorkerdMachineLink.upgrade")(function* (Pair) {
|
|
136
|
+
if (!(yield* enabled))
|
|
137
|
+
return new Response(null, { status: 404 });
|
|
138
|
+
return yield* Effect.uninterruptible(Effect.gen(function* () {
|
|
139
|
+
if (scope.state._tag === "Closed" || !(yield* handshakes.takeIfAvailable(1)))
|
|
140
|
+
return new Response(null, { status: 503 });
|
|
141
|
+
const released = { value: false };
|
|
142
|
+
const release = Effect.suspend(() => {
|
|
143
|
+
if (released.value)
|
|
144
|
+
return Effect.void;
|
|
145
|
+
released.value = true;
|
|
146
|
+
return handshakes.release(1);
|
|
147
|
+
});
|
|
148
|
+
const attempt = {
|
|
149
|
+
handedOff: false
|
|
150
|
+
};
|
|
151
|
+
return yield* Effect.gen(function* () {
|
|
152
|
+
const pair = new Pair;
|
|
153
|
+
attempt.pair = pair;
|
|
154
|
+
const init = { status: 101, webSocket: pair[0] };
|
|
155
|
+
const response = new Response(null, init);
|
|
156
|
+
yield* accept(pair, release).pipe(Effect.provide(services), Effect.forkIn(scope, { startImmediately: true }));
|
|
157
|
+
attempt.handedOff = scope.state._tag !== "Closed";
|
|
158
|
+
return response;
|
|
159
|
+
}).pipe(Effect.onError(() => Effect.sync(() => {
|
|
160
|
+
if (attempt.pair && attempt.pair[1].readyState === OPEN)
|
|
161
|
+
closeQuietly(attempt.pair[1], CLOSE2);
|
|
162
|
+
})), Effect.ensuring(Effect.suspend(() => attempt.handedOff ? Effect.void : release)));
|
|
163
|
+
}));
|
|
164
|
+
});
|
|
165
|
+
const holding = (socket) => {
|
|
166
|
+
const found = inboxes.get(socket);
|
|
167
|
+
if (!found && !claims.has(socket) && socket.readyState === OPEN)
|
|
168
|
+
closeQuietly(socket, CLOSE2);
|
|
169
|
+
return found;
|
|
170
|
+
};
|
|
171
|
+
const hibernation = {
|
|
172
|
+
webSocketMessage: (socket, message) => holding(socket)?.message(message),
|
|
173
|
+
webSocketClose: (socket, code) => {
|
|
174
|
+
inboxes.get(socket)?.end(CLOSE2);
|
|
175
|
+
if (socket.readyState === CLOSING)
|
|
176
|
+
closeQuietly(socket, sendable(code) ? code : 1000);
|
|
177
|
+
},
|
|
178
|
+
webSocketError: (socket) => holding(socket)?.end(CLOSE2)
|
|
179
|
+
};
|
|
180
|
+
return Object.assign((request, pair) => {
|
|
181
|
+
const resolved = pair ?? (typeof WebSocketPair === "undefined" ? undefined : WebSocketPair);
|
|
182
|
+
return !resolved || !isUpgrade2(request, options) ? undefined : upgrade(resolved);
|
|
183
|
+
}, hibernation, {
|
|
184
|
+
keepingAwake: () => awake.timer !== undefined
|
|
185
|
+
});
|
|
186
|
+
});
|
|
187
|
+
var keeper = (socket, hold) => {
|
|
188
|
+
const at = { busy: false };
|
|
189
|
+
const write = () => attach(socket, at.busy ? undefined : at.state);
|
|
190
|
+
return {
|
|
191
|
+
persist: (state) => {
|
|
192
|
+
at.state = state;
|
|
193
|
+
write();
|
|
194
|
+
},
|
|
195
|
+
busy: (busy) => {
|
|
196
|
+
at.busy = busy;
|
|
197
|
+
hold(socket, busy);
|
|
198
|
+
write();
|
|
199
|
+
}
|
|
200
|
+
};
|
|
201
|
+
};
|
|
202
|
+
var attach = (socket, state) => {
|
|
203
|
+
if (!state)
|
|
204
|
+
return clearAttachment(socket);
|
|
205
|
+
const hello = { ...Struct.omit(state.hello, ["processes", "links"]), processes: [] };
|
|
206
|
+
const value = encodeAttachment({ v: 1, ...state, hello });
|
|
207
|
+
try {
|
|
208
|
+
socket.serializeAttachment(value);
|
|
209
|
+
} catch {
|
|
210
|
+
clearAttachment(socket);
|
|
211
|
+
}
|
|
212
|
+
};
|
|
213
|
+
var serve2 = (socket, release, fixed = {}) => Effect.suspend(() => {
|
|
214
|
+
const released = { value: false };
|
|
215
|
+
const once = Effect.suspend(() => {
|
|
216
|
+
if (released.value)
|
|
217
|
+
return Effect.void;
|
|
218
|
+
released.value = true;
|
|
219
|
+
return release;
|
|
220
|
+
});
|
|
221
|
+
return Effect.gen(function* () {
|
|
222
|
+
const link = yield* Link.serve(yield* carrier2(socket), fixed).pipe(Effect.ensuring(once));
|
|
223
|
+
const machines = yield* Machines.Service;
|
|
224
|
+
yield* machines.connect(link.machine, link.connection);
|
|
225
|
+
}).pipe(Effect.ensuring(once), Effect.ignore, Effect.scoped);
|
|
226
|
+
});
|
|
227
|
+
var carrier2 = Effect.fnUntraced(function* (socket) {
|
|
228
|
+
const held = yield* inbox(socket);
|
|
229
|
+
yield* Effect.acquireRelease(Effect.sync(() => {
|
|
230
|
+
socket.binaryType = "arraybuffer";
|
|
231
|
+
socket.addEventListener("message", (event) => held.message(event.data));
|
|
232
|
+
socket.addEventListener("close", () => held.end(CLOSE2));
|
|
233
|
+
socket.addEventListener("error", () => held.end(CLOSE2));
|
|
234
|
+
}), () => Effect.sync(() => held.end(CLOSE2)));
|
|
235
|
+
return held.carrier;
|
|
236
|
+
});
|
|
237
|
+
var inbox = Effect.fnUntraced(function* (socket) {
|
|
238
|
+
const inbound = yield* Queue.unbounded();
|
|
239
|
+
const held = { bytes: 0 };
|
|
240
|
+
const end = (code) => {
|
|
241
|
+
if (socket.readyState === OPEN)
|
|
242
|
+
closeQuietly(socket, code);
|
|
243
|
+
Queue.endUnsafe(inbound);
|
|
244
|
+
};
|
|
245
|
+
const message = (data) => {
|
|
246
|
+
if (!(data instanceof ArrayBuffer))
|
|
247
|
+
return end(CLOSE2);
|
|
248
|
+
if (data.byteLength > MAX_FRAME2)
|
|
249
|
+
return end(TOO_BIG);
|
|
250
|
+
if (data.byteLength < MIN_FRAME2 || held.bytes + data.byteLength > MAX_WAITING)
|
|
251
|
+
return end(CLOSE2);
|
|
252
|
+
if (Queue.offerUnsafe(inbound, new Uint8Array(data)))
|
|
253
|
+
held.bytes += data.byteLength;
|
|
254
|
+
};
|
|
255
|
+
const carrier = {
|
|
256
|
+
describe: () => ({ type: "websocket" }),
|
|
257
|
+
send: (bytes) => Effect.try(() => {
|
|
258
|
+
if (socket.readyState === OPEN)
|
|
259
|
+
socket.send(bytes);
|
|
260
|
+
}).pipe(Effect.catch(() => Effect.sync(() => end(CLOSE2)))),
|
|
261
|
+
receive: Queue.take(inbound).pipe(Effect.map((bytes) => {
|
|
262
|
+
held.bytes -= bytes.byteLength;
|
|
263
|
+
return bytes;
|
|
264
|
+
}), Effect.mapError(() => new Link.Closed))
|
|
265
|
+
};
|
|
266
|
+
return { message, end, carrier };
|
|
267
|
+
});
|
|
268
|
+
var isUpgrade2 = (request, options) => request.method === "GET" && request.headers.get("upgrade")?.toLowerCase() === "websocket" && URL.parse(request.url, "http://localhost")?.pathname === MACHINE_LINK_PATH && !rejected2(HttpServerRequest.fromWeb(request), options);
|
|
269
|
+
|
|
270
|
+
export { TAG2, make2, serve2, carrier2, isUpgrade2, exports_workerd_machine_link };
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
import {
|
|
2
|
+
CorsConfig2,
|
|
3
|
+
isAllowedRequestOrigin2
|
|
4
|
+
} from "./api-11hx8jza.js";
|
|
5
|
+
import {
|
|
6
|
+
locationErrors2,
|
|
7
|
+
requestRef2
|
|
8
|
+
} from "./api-0q8mvh3b.js";
|
|
9
|
+
|
|
10
|
+
// src/handlers/experimental/browser-tunnel.ts
|
|
11
|
+
import { NodeHttpServerRequest } from "@effect/platform-node";
|
|
12
|
+
import { WebSocketServer } from "@effect/platform-node-shared/NodeWS";
|
|
13
|
+
import { BrowserTunnelGateway } from "@radheim/core/experimental/browser-tunnel";
|
|
14
|
+
import { LocationLifecycle } from "@radheim/core/location-lifecycle";
|
|
15
|
+
import { LocationServiceMap } from "@radheim/core/location-service-map";
|
|
16
|
+
import {
|
|
17
|
+
BROWSER_TUNNEL_CONNECTION_HEADER,
|
|
18
|
+
BROWSER_TUNNEL_PROTOCOL_HEADER,
|
|
19
|
+
BROWSER_TUNNEL_PROTOCOL_VERSION,
|
|
20
|
+
BROWSER_TUNNEL_SESSION_HEADER,
|
|
21
|
+
BROWSER_TUNNEL_TICKET_HEADER
|
|
22
|
+
} from "@radheim/protocol/groups/experimental/browser-tunnel";
|
|
23
|
+
import { isWebSocketUpgrade } from "@radheim/protocol/groups/machine";
|
|
24
|
+
import { Session } from "@radheim/schema/session";
|
|
25
|
+
import { Effect, Option, Schema, Scope } from "effect";
|
|
26
|
+
import { HttpMiddleware, HttpServerResponse } from "effect/http";
|
|
27
|
+
import { IncomingMessage } from "node:http";
|
|
28
|
+
var STOPPING = "1 second";
|
|
29
|
+
var CLOSING = "5 seconds";
|
|
30
|
+
function toUint8Array(data) {
|
|
31
|
+
if (data instanceof Uint8Array)
|
|
32
|
+
return data;
|
|
33
|
+
if (data instanceof ArrayBuffer)
|
|
34
|
+
return new Uint8Array(data);
|
|
35
|
+
if (Array.isArray(data)) {
|
|
36
|
+
const buffers = data.map((part) => part instanceof Uint8Array ? part : new Uint8Array(part));
|
|
37
|
+
return Buffer.concat(buffers);
|
|
38
|
+
}
|
|
39
|
+
return new Uint8Array;
|
|
40
|
+
}
|
|
41
|
+
function adaptWebSocket(ws) {
|
|
42
|
+
return {
|
|
43
|
+
get readyState() {
|
|
44
|
+
return ws.readyState;
|
|
45
|
+
},
|
|
46
|
+
get bufferedAmount() {
|
|
47
|
+
return ws.bufferedAmount;
|
|
48
|
+
},
|
|
49
|
+
send(data, onWritten) {
|
|
50
|
+
ws.send(data, { binary: true, compress: false }, (error) => onWritten?.(error ?? undefined));
|
|
51
|
+
},
|
|
52
|
+
ping() {
|
|
53
|
+
if (ws.readyState === ws.OPEN)
|
|
54
|
+
ws.ping();
|
|
55
|
+
},
|
|
56
|
+
close(code, reason) {
|
|
57
|
+
if (ws.readyState === ws.OPEN || ws.readyState === ws.CONNECTING) {
|
|
58
|
+
ws.close(code, reason);
|
|
59
|
+
}
|
|
60
|
+
},
|
|
61
|
+
terminate() {
|
|
62
|
+
ws.terminate();
|
|
63
|
+
},
|
|
64
|
+
onMessage(listener) {
|
|
65
|
+
const handler = (raw, isBinary) => {
|
|
66
|
+
if (!isBinary) {
|
|
67
|
+
listener(String(raw));
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
listener(toUint8Array(raw));
|
|
71
|
+
};
|
|
72
|
+
ws.on("message", handler);
|
|
73
|
+
ws.resume();
|
|
74
|
+
return () => {
|
|
75
|
+
ws.off("message", handler);
|
|
76
|
+
};
|
|
77
|
+
},
|
|
78
|
+
onClose(listener) {
|
|
79
|
+
const handler = (code, reason) => listener(code, reason.toString("utf8"));
|
|
80
|
+
ws.on("close", handler);
|
|
81
|
+
return () => {
|
|
82
|
+
ws.off("close", handler);
|
|
83
|
+
};
|
|
84
|
+
},
|
|
85
|
+
onError(listener) {
|
|
86
|
+
ws.on("error", listener);
|
|
87
|
+
return () => {
|
|
88
|
+
ws.off("error", listener);
|
|
89
|
+
};
|
|
90
|
+
},
|
|
91
|
+
onPong(listener) {
|
|
92
|
+
ws.on("pong", listener);
|
|
93
|
+
return () => {
|
|
94
|
+
ws.off("pong", listener);
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
var upgradeSocket = (sockets, incoming) => Effect.acquireRelease(Effect.callback((resume) => {
|
|
100
|
+
const refused = () => resume(Effect.fail(new Error("WebSocket upgrade closed before completion.")));
|
|
101
|
+
if (incoming.socket.destroyed)
|
|
102
|
+
return refused();
|
|
103
|
+
incoming.socket.once("close", refused);
|
|
104
|
+
sockets.handleUpgrade(incoming, incoming.socket, Buffer.alloc(0), (ws) => {
|
|
105
|
+
incoming.socket.off("close", refused);
|
|
106
|
+
incoming.socket.setNoDelay(true);
|
|
107
|
+
ws.pause();
|
|
108
|
+
resume(Effect.succeed(ws));
|
|
109
|
+
});
|
|
110
|
+
}), (ws) => Effect.gen(function* () {
|
|
111
|
+
if (ws.readyState === ws.CLOSED)
|
|
112
|
+
return;
|
|
113
|
+
const gone = Effect.callback((resume) => {
|
|
114
|
+
if (ws.readyState === ws.CLOSED)
|
|
115
|
+
return resume(Effect.void);
|
|
116
|
+
ws.once("close", () => resume(Effect.void));
|
|
117
|
+
});
|
|
118
|
+
ws.close(1001, "server closing");
|
|
119
|
+
if (Option.isNone(yield* Effect.timeoutOption(gone, CLOSING)))
|
|
120
|
+
ws.terminate();
|
|
121
|
+
}));
|
|
122
|
+
var makeBrowserTunnel2 = Effect.gen(function* () {
|
|
123
|
+
const gateway = yield* BrowserTunnelGateway.Service;
|
|
124
|
+
const locations = yield* LocationServiceMap.Service;
|
|
125
|
+
const cors = yield* CorsConfig2;
|
|
126
|
+
const scope = yield* Effect.scope;
|
|
127
|
+
const server = yield* Effect.cached(Effect.acquireRelease(Effect.sync(() => new WebSocketServer({
|
|
128
|
+
noServer: true,
|
|
129
|
+
perMessageDeflate: false,
|
|
130
|
+
maxPayload: BrowserTunnelGateway.MAX_WS_FRAME_BYTES
|
|
131
|
+
})), (sockets) => Effect.gen(function* () {
|
|
132
|
+
sockets.clients.forEach((ws) => ws.close(1012, "server stopping"));
|
|
133
|
+
const empty = Effect.callback((resume) => sockets.close(() => resume(Effect.void)));
|
|
134
|
+
if (Option.isNone(yield* Effect.timeoutOption(empty, STOPPING))) {
|
|
135
|
+
sockets.clients.forEach((ws) => ws.terminate());
|
|
136
|
+
}
|
|
137
|
+
})).pipe(Scope.provide(scope)));
|
|
138
|
+
return Effect.fn("BrowserTunnelHandler.connect")(function* (request) {
|
|
139
|
+
if (!isAllowedRequestOrigin2(request.headers.origin, request.headers.host, cors)) {
|
|
140
|
+
return HttpServerResponse.empty({ status: 403 });
|
|
141
|
+
}
|
|
142
|
+
const incoming = NodeHttpServerRequest.toIncomingMessage(request);
|
|
143
|
+
if (!(incoming instanceof IncomingMessage) || !isWebSocketUpgrade(request)) {
|
|
144
|
+
return HttpServerResponse.empty({ status: 400 });
|
|
145
|
+
}
|
|
146
|
+
const url = new URL(request.url, "http://localhost");
|
|
147
|
+
if (url.searchParams.has("ticket")) {
|
|
148
|
+
return HttpServerResponse.empty({ status: 403 });
|
|
149
|
+
}
|
|
150
|
+
const ticket = request.headers[BROWSER_TUNNEL_TICKET_HEADER]?.trim();
|
|
151
|
+
if (!ticket) {
|
|
152
|
+
return HttpServerResponse.empty({ status: 403 });
|
|
153
|
+
}
|
|
154
|
+
const rawSession = request.headers[BROWSER_TUNNEL_SESSION_HEADER]?.trim() ?? url.searchParams.get("sessionID")?.trim();
|
|
155
|
+
const connectionID = request.headers[BROWSER_TUNNEL_CONNECTION_HEADER]?.trim() ?? url.searchParams.get("connectionID")?.trim();
|
|
156
|
+
const rawProtocol = request.headers[BROWSER_TUNNEL_PROTOCOL_HEADER]?.trim() ?? url.searchParams.get("protocol")?.trim();
|
|
157
|
+
const protocol = rawProtocol ? Number(rawProtocol) : NaN;
|
|
158
|
+
const sessionID = rawSession ? Option.getOrUndefined(Schema.decodeUnknownOption(Session.ID)(rawSession)) : undefined;
|
|
159
|
+
if (!sessionID || !connectionID || protocol !== BROWSER_TUNNEL_PROTOCOL_VERSION) {
|
|
160
|
+
return HttpServerResponse.empty({ status: 403 });
|
|
161
|
+
}
|
|
162
|
+
const ref = LocationServiceMap.canonical(requestRef2(request));
|
|
163
|
+
const binding = yield* gateway.consumeTicket({
|
|
164
|
+
ticket,
|
|
165
|
+
location: ref,
|
|
166
|
+
sessionID,
|
|
167
|
+
connectionID,
|
|
168
|
+
protocol
|
|
169
|
+
});
|
|
170
|
+
if (!binding) {
|
|
171
|
+
return HttpServerResponse.empty({ status: 403 });
|
|
172
|
+
}
|
|
173
|
+
if (Option.isNone(yield* Effect.option(request.upgrade))) {
|
|
174
|
+
return HttpServerResponse.empty({ status: 400 });
|
|
175
|
+
}
|
|
176
|
+
return yield* Effect.gen(function* () {
|
|
177
|
+
const sockets = yield* server;
|
|
178
|
+
const ws = yield* upgradeSocket(sockets, incoming);
|
|
179
|
+
yield* HttpMiddleware.withLoggerDisabled(Effect.void);
|
|
180
|
+
const lifecycle = yield* LocationLifecycle.Service;
|
|
181
|
+
yield* lifecycle.retain;
|
|
182
|
+
yield* lifecycle.awaitShutdown.pipe(Effect.andThen(Effect.sync(() => ws.close(1012, "location shut down"))), Effect.forkChild);
|
|
183
|
+
yield* binding.onUpgrade(adaptWebSocket(ws));
|
|
184
|
+
return HttpServerResponse.empty();
|
|
185
|
+
}).pipe(Effect.scoped, Effect.provide(locations.get(ref)), locationErrors2, Effect.orElseSucceed(() => HttpServerResponse.empty()));
|
|
186
|
+
});
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
export { makeBrowserTunnel2 };
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
// src/handlers/session-error.ts
|
|
2
|
+
import { Skill } from "@radheim/core/skill";
|
|
3
|
+
import { MessageNotFoundError, SessionNotFoundError, SkillLoadError, UnknownError } from "@radheim/protocol/errors";
|
|
4
|
+
import { Effect } from "effect";
|
|
5
|
+
function missingSession2(error) {
|
|
6
|
+
return new SessionNotFoundError({
|
|
7
|
+
sessionID: error.sessionID,
|
|
8
|
+
message: `Session not found: ${error.sessionID}`
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
function skillLoadFailed2(error) {
|
|
12
|
+
return new SkillLoadError({ skill: Skill.ID.make(error.skill), message: error.message });
|
|
13
|
+
}
|
|
14
|
+
function missingMessage2(error) {
|
|
15
|
+
return new MessageNotFoundError({
|
|
16
|
+
sessionID: error.sessionID,
|
|
17
|
+
messageID: error.messageID,
|
|
18
|
+
message: `Message not found: ${error.messageID}`
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
function failedMessageDecode2(error) {
|
|
22
|
+
const ref = `err_${crypto.randomUUID().slice(0, 8)}`;
|
|
23
|
+
return Effect.logError("failed to decode session message").pipe(Effect.annotateLogs({ ref, sessionID: error.sessionID, messageID: error.messageID }), Effect.andThen(Effect.fail(new UnknownError({ message: "Unexpected server error. Check server logs for details.", ref }))));
|
|
24
|
+
}
|
|
25
|
+
function failedSnapshot2(operation, sessionID) {
|
|
26
|
+
return (error) => {
|
|
27
|
+
const ref = `err_${crypto.randomUUID().slice(0, 8)}`;
|
|
28
|
+
return Effect.logError(`failed to ${operation}`, { cause: error }).pipe(Effect.annotateLogs({ ref, sessionID }), Effect.andThen(Effect.fail(new UnknownError({ message: "Unexpected server error. Check server logs for details.", ref }))));
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export { missingSession2, skillLoadFailed2, missingMessage2, failedMessageDecode2, failedSnapshot2 };
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Service3
|
|
3
|
+
} from "./api-k0fc7y6c.js";
|
|
4
|
+
|
|
5
|
+
// src/handlers/space.ts
|
|
6
|
+
import { InvalidRequestError } from "@radheim/protocol/errors";
|
|
7
|
+
import { Space } from "@radheim/schema/space";
|
|
8
|
+
import { Effect } from "effect";
|
|
9
|
+
import { HttpApiSchema } from "effect/http-api";
|
|
10
|
+
var streamNotFound = () => new InvalidRequestError({ message: "No open event stream has this ID", kind: "stream_not_found", field: "stream" });
|
|
11
|
+
var repeated = (spaces) => new Set(spaces).size !== spaces.length;
|
|
12
|
+
var repeatedSpace = () => new InvalidRequestError({ message: "Each space may appear only once", field: "spaces" });
|
|
13
|
+
var makeSpace2 = Effect.gen(function* () {
|
|
14
|
+
const store = yield* Service3;
|
|
15
|
+
return {
|
|
16
|
+
write: Effect.fn("SpaceHandler.write")(function* (changes) {
|
|
17
|
+
const encoder = new TextEncoder;
|
|
18
|
+
const bytes = changes.reduce((total, change) => total + (change.value === null ? 0 : encoder.encode(change.value).length), 0);
|
|
19
|
+
if (bytes > Space.MaxValueBytes)
|
|
20
|
+
return yield* new InvalidRequestError({ message: "Values exceed 1 MiB of UTF-8 in total", field: "changes" });
|
|
21
|
+
return { spaces: yield* store.write(changes) };
|
|
22
|
+
}),
|
|
23
|
+
sync: Effect.fn("SpaceHandler.sync")(function* (spaces) {
|
|
24
|
+
if (repeated(spaces.map((item) => item.space)))
|
|
25
|
+
return yield* repeatedSpace();
|
|
26
|
+
return { pages: yield* store.sync(spaces) };
|
|
27
|
+
}),
|
|
28
|
+
subscribe: Effect.fn("SpaceHandler.subscribe")(function* (payload) {
|
|
29
|
+
if (repeated(payload.spaces.map((item) => item.space)))
|
|
30
|
+
return yield* repeatedSpace();
|
|
31
|
+
if (!(yield* store.subscribe(payload.stream, payload.spaces)))
|
|
32
|
+
return yield* streamNotFound();
|
|
33
|
+
return HttpApiSchema.NoContent.make();
|
|
34
|
+
}),
|
|
35
|
+
unsubscribe: Effect.fn("SpaceHandler.unsubscribe")(function* (payload) {
|
|
36
|
+
if (repeated(payload.spaces))
|
|
37
|
+
return yield* repeatedSpace();
|
|
38
|
+
if (!(yield* store.unsubscribe(payload.stream, payload.spaces)))
|
|
39
|
+
return yield* streamNotFound();
|
|
40
|
+
return HttpApiSchema.NoContent.make();
|
|
41
|
+
}),
|
|
42
|
+
reset: Effect.fn("SpaceHandler.reset")(function* () {
|
|
43
|
+
yield* store.resetEpoch;
|
|
44
|
+
return HttpApiSchema.NoContent.make();
|
|
45
|
+
})
|
|
46
|
+
};
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
export { makeSpace2 };
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import {
|
|
2
|
+
missingSession2
|
|
3
|
+
} from "./api-ghyd9ren.js";
|
|
4
|
+
import {
|
|
5
|
+
locationErrors2,
|
|
6
|
+
response2,
|
|
7
|
+
sessionInfo2
|
|
8
|
+
} from "./api-0q8mvh3b.js";
|
|
9
|
+
import {
|
|
10
|
+
Api2
|
|
11
|
+
} from "./api-f6955nmc.js";
|
|
12
|
+
|
|
13
|
+
// src/handlers/permission.ts
|
|
14
|
+
import { Instance } from "@radheim/core/instance/service";
|
|
15
|
+
import { Location } from "@radheim/core/location";
|
|
16
|
+
import { Permission } from "@radheim/core/permission";
|
|
17
|
+
import { PermissionSaved } from "@radheim/core/permission/saved";
|
|
18
|
+
import { Session } from "@radheim/core/session";
|
|
19
|
+
import { Effect } from "effect";
|
|
20
|
+
import { HttpApiBuilder, HttpApiSchema } from "effect/http-api";
|
|
21
|
+
import { ConflictError, PermissionNotFoundError, PermissionSavedNotFoundError } from "@radheim/protocol/errors";
|
|
22
|
+
function missingRequest(id) {
|
|
23
|
+
return new PermissionNotFoundError({ requestID: id, message: `Permission request not found: ${id}` });
|
|
24
|
+
}
|
|
25
|
+
var PermissionHandler2 = HttpApiBuilder.group(Api2, "server.permission", (handlers) => Effect.gen(function* () {
|
|
26
|
+
const instances = yield* Instance.Service;
|
|
27
|
+
const sessions = yield* Session.Service;
|
|
28
|
+
const requireOwnedRequest = Effect.fnUntraced(function* (sessionID, requestID) {
|
|
29
|
+
const permission = yield* Permission.Service;
|
|
30
|
+
const request = yield* permission.get(requestID);
|
|
31
|
+
if (!request || request.sessionID !== sessionID)
|
|
32
|
+
return yield* missingRequest(requestID);
|
|
33
|
+
return { permission, request };
|
|
34
|
+
});
|
|
35
|
+
return handlers.handle("permission.request.list", Effect.fnUntraced(function* () {
|
|
36
|
+
const permission = yield* Permission.Service;
|
|
37
|
+
return yield* response2(permission.list());
|
|
38
|
+
})).handle("session.permission.create", Effect.fnUntraced(function* (ctx) {
|
|
39
|
+
const permission = yield* Permission.Service;
|
|
40
|
+
return {
|
|
41
|
+
data: yield* permission.ask({
|
|
42
|
+
id: ctx.payload.id,
|
|
43
|
+
sessionID: ctx.params.sessionID,
|
|
44
|
+
action: ctx.payload.action,
|
|
45
|
+
resources: ctx.payload.resources,
|
|
46
|
+
save: ctx.payload.save,
|
|
47
|
+
metadata: ctx.payload.metadata,
|
|
48
|
+
source: ctx.payload.source,
|
|
49
|
+
agent: ctx.payload.agent
|
|
50
|
+
}).pipe(Effect.catchTag("Session.NotFoundError", missingSession2))
|
|
51
|
+
};
|
|
52
|
+
})).handle("session.permission.list", Effect.fnUntraced(function* (ctx) {
|
|
53
|
+
const session = yield* sessionInfo2(sessions, ctx.params.sessionID);
|
|
54
|
+
const requests = yield* Permission.Service.use((permission) => permission.forSession(ctx.params.sessionID)).pipe(instances.provide(session), locationErrors2);
|
|
55
|
+
return { data: requests };
|
|
56
|
+
})).handle("session.permission.get", Effect.fnUntraced(function* (ctx) {
|
|
57
|
+
const owned = yield* requireOwnedRequest(ctx.params.sessionID, ctx.params.requestID);
|
|
58
|
+
return { data: owned.request };
|
|
59
|
+
})).handle("session.permission.reply", Effect.fnUntraced(function* (ctx) {
|
|
60
|
+
const owned = yield* requireOwnedRequest(ctx.params.sessionID, ctx.params.requestID);
|
|
61
|
+
yield* owned.permission.reply({ requestID: ctx.params.requestID, reply: ctx.payload.decision, message: ctx.payload.message }).pipe(Effect.catchTag("Permission.NotFoundError", () => missingRequest(ctx.params.requestID)));
|
|
62
|
+
return HttpApiSchema.NoContent.make();
|
|
63
|
+
})).handle("permission.saved.list", Effect.fnUntraced(function* (ctx) {
|
|
64
|
+
const location = yield* Location.Service;
|
|
65
|
+
const saved = yield* PermissionSaved.Service;
|
|
66
|
+
return {
|
|
67
|
+
data: yield* saved.list({
|
|
68
|
+
projectID: ctx.query.projectID ?? location.project.id
|
|
69
|
+
})
|
|
70
|
+
};
|
|
71
|
+
})).handle("permission.saved.update", Effect.fnUntraced(function* (ctx) {
|
|
72
|
+
const saved = yield* PermissionSaved.Service;
|
|
73
|
+
return {
|
|
74
|
+
data: yield* saved.update({ id: ctx.params.id, action: ctx.payload.action, resource: ctx.payload.resource }).pipe(Effect.catchTags({
|
|
75
|
+
"PermissionSaved.NotFoundError": (error) => new PermissionSavedNotFoundError({
|
|
76
|
+
id: error.id,
|
|
77
|
+
message: `Saved permission not found: ${error.id}`
|
|
78
|
+
}),
|
|
79
|
+
"PermissionSaved.ConflictError": (error) => new ConflictError({
|
|
80
|
+
resource: error.id,
|
|
81
|
+
message: `A saved permission already allows ${error.action} for ${error.resource}`
|
|
82
|
+
})
|
|
83
|
+
}))
|
|
84
|
+
};
|
|
85
|
+
})).handle("permission.saved.remove", Effect.fnUntraced(function* (ctx) {
|
|
86
|
+
const saved = yield* PermissionSaved.Service;
|
|
87
|
+
yield* saved.remove(ctx.params.id);
|
|
88
|
+
return HttpApiSchema.NoContent.make();
|
|
89
|
+
}));
|
|
90
|
+
}));
|
|
91
|
+
|
|
92
|
+
export { PermissionHandler2 };
|