@radheim/protocol 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 +60 -0
- package/dist/api.js +81 -0
- package/dist/client.d.ts +69 -0
- package/dist/client.js +102 -0
- package/dist/errors.d.ts +273 -0
- package/dist/errors.js +227 -0
- package/dist/groups/agent.d.ts +299 -0
- package/dist/groups/agent.js +30 -0
- package/dist/groups/artifact.d.ts +173 -0
- package/dist/groups/artifact.js +80 -0
- package/dist/groups/automation.d.ts +480 -0
- package/dist/groups/automation.js +55 -0
- package/dist/groups/blob.d.ts +415 -0
- package/dist/groups/blob.js +79 -0
- package/dist/groups/command.d.ts +15 -0
- package/dist/groups/command.js +20 -0
- package/dist/groups/config.d.ts +27 -0
- package/dist/groups/config.js +32 -0
- package/dist/groups/credential.d.ts +93 -0
- package/dist/groups/credential.js +50 -0
- package/dist/groups/debug.d.ts +22 -0
- package/dist/groups/debug.js +49 -0
- package/dist/groups/event.d.ts +16442 -0
- package/dist/groups/event.js +68 -0
- package/dist/groups/experimental/browser-tunnel.d.ts +20 -0
- package/dist/groups/experimental/browser-tunnel.js +29 -0
- package/dist/groups/experimental.d.ts +1519 -0
- package/dist/groups/experimental.js +12 -0
- package/dist/groups/flag.d.ts +12 -0
- package/dist/groups/flag.js +19 -0
- package/dist/groups/form.d.ts +138 -0
- package/dist/groups/form.js +18 -0
- package/dist/groups/fs.d.ts +60 -0
- package/dist/groups/fs.js +101 -0
- package/dist/groups/generate.d.ts +397 -0
- package/dist/groups/generate.js +77 -0
- package/dist/groups/integration.d.ts +1724 -0
- package/dist/groups/integration.js +169 -0
- package/dist/groups/job.d.ts +95 -0
- package/dist/groups/job.js +45 -0
- package/dist/groups/location.d.ts +23 -0
- package/dist/groups/location.js +47 -0
- package/dist/groups/machine.d.ts +91 -0
- package/dist/groups/machine.js +61 -0
- package/dist/groups/mcp.d.ts +104 -0
- package/dist/groups/mcp.js +125 -0
- package/dist/groups/media.d.ts +8 -0
- package/dist/groups/media.js +18 -0
- package/dist/groups/message.d.ts +3696 -0
- package/dist/groups/message.js +102 -0
- package/dist/groups/migration.d.ts +28 -0
- package/dist/groups/migration.js +21 -0
- package/dist/groups/model.d.ts +536 -0
- package/dist/groups/model.js +39 -0
- package/dist/groups/permission.d.ts +175 -0
- package/dist/groups/permission.js +115 -0
- package/dist/groups/persistent-pty.d.ts +251 -0
- package/dist/groups/persistent-pty.js +109 -0
- package/dist/groups/plugin.d.ts +102 -0
- package/dist/groups/plugin.js +59 -0
- package/dist/groups/project.d.ts +83 -0
- package/dist/groups/project.js +37 -0
- package/dist/groups/provider.d.ts +354 -0
- package/dist/groups/provider.js +34 -0
- package/dist/groups/pty.d.ts +151 -0
- package/dist/groups/pty.js +117 -0
- package/dist/groups/push.d.ts +123 -0
- package/dist/groups/push.js +60 -0
- package/dist/groups/reference.d.ts +25 -0
- package/dist/groups/reference.js +33 -0
- package/dist/groups/rpc.d.ts +21 -0
- package/dist/groups/rpc.js +24 -0
- package/dist/groups/server.d.ts +46 -0
- package/dist/groups/server.js +55 -0
- package/dist/groups/session.d.ts +11874 -0
- package/dist/groups/session.js +663 -0
- package/dist/groups/shell.d.ts +125 -0
- package/dist/groups/shell.js +65 -0
- package/dist/groups/skill.d.ts +26 -0
- package/dist/groups/skill.js +34 -0
- package/dist/groups/space.d.ts +56 -0
- package/dist/groups/space.js +59 -0
- package/dist/groups/usage.d.ts +96 -0
- package/dist/groups/usage.js +22 -0
- package/dist/groups/vcs.d.ts +89 -0
- package/dist/groups/vcs.js +94 -0
- package/dist/groups/voice.d.ts +81 -0
- package/dist/groups/voice.js +75 -0
- package/dist/groups/websearch.d.ts +29 -0
- package/dist/groups/websearch.js +34 -0
- package/dist/groups/worktree.d.ts +41 -0
- package/dist/groups/worktree.js +52 -0
- package/dist/middleware/authorization.d.ts +13 -0
- package/dist/middleware/authorization.js +6 -0
- package/dist/middleware/schema-error.d.ts +13 -0
- package/dist/middleware/schema-error.js +4 -0
- package/dist/simulation/image.d.ts +35 -0
- package/dist/simulation/image.js +21 -0
- package/dist/simulation/terminal.d.ts +81 -0
- package/dist/simulation/terminal.js +49 -0
- package/dist/simulation.d.ts +1784 -0
- package/dist/simulation.js +485 -0
- package/package.json +46 -4
- package/README.md +0 -3
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { Pty } from "@radheim/schema/pty";
|
|
2
|
+
import { PtyTicket } from "@radheim/schema/pty-ticket";
|
|
3
|
+
import { Location } from "@radheim/schema/location";
|
|
4
|
+
import { Context, Schema } from "effect";
|
|
5
|
+
import { HttpApiEndpoint, HttpApiGroup, HttpApiMiddleware, HttpApiSchema, OpenApi } from "effect/http-api";
|
|
6
|
+
import { ForbiddenError, LocationNotFoundError, PtyNotFoundError, ServiceUnavailableError } from "../errors.js";
|
|
7
|
+
import { LocationQuery, locationQueryOpenApi } from "./location.js";
|
|
8
|
+
export const PTY_CONNECT_TICKET_QUERY = "ticket";
|
|
9
|
+
export const PTY_CONNECT_TOKEN_HEADER = "x-opencode-ticket";
|
|
10
|
+
export const PTY_CONNECT_TOKEN_HEADER_VALUE = "1";
|
|
11
|
+
export const PTY_CONNECT_PATH = "/api/pty/:ptyID/connect";
|
|
12
|
+
const PTY_CONNECT_URL = /^\/api\/pty\/[^/]+\/connect$/;
|
|
13
|
+
export function hasPtyConnectTicketURL(url) {
|
|
14
|
+
return PTY_CONNECT_URL.test(url.pathname) && !!url.searchParams.get(PTY_CONNECT_TICKET_QUERY);
|
|
15
|
+
}
|
|
16
|
+
export const makePtyGroup = (locationMiddleware) => HttpApiGroup.make("server.pty")
|
|
17
|
+
.add(HttpApiEndpoint.get("pty.list", "/api/pty", {
|
|
18
|
+
query: LocationQuery,
|
|
19
|
+
success: Location.response(Schema.Array(Pty.Info)),
|
|
20
|
+
})
|
|
21
|
+
.annotateMerge(locationQueryOpenApi)
|
|
22
|
+
.annotateMerge(OpenApi.annotations({
|
|
23
|
+
identifier: "pty.list",
|
|
24
|
+
summary: "List PTY sessions",
|
|
25
|
+
description: "List PTY sessions for a location, including exited sessions retained until removal.",
|
|
26
|
+
})))
|
|
27
|
+
.add(HttpApiEndpoint.post("pty.create", "/api/pty", {
|
|
28
|
+
query: LocationQuery,
|
|
29
|
+
payload: Pty.CreateInput,
|
|
30
|
+
success: Location.response(Pty.Info),
|
|
31
|
+
error: ServiceUnavailableError,
|
|
32
|
+
})
|
|
33
|
+
.annotateMerge(locationQueryOpenApi)
|
|
34
|
+
.annotateMerge(OpenApi.annotations({
|
|
35
|
+
identifier: "pty.create",
|
|
36
|
+
summary: "Create PTY session",
|
|
37
|
+
description: "Create a pseudo-terminal session for a location.",
|
|
38
|
+
})))
|
|
39
|
+
.add(HttpApiEndpoint.get("pty.get", "/api/pty/:ptyID", {
|
|
40
|
+
params: { ptyID: Pty.ID },
|
|
41
|
+
query: LocationQuery,
|
|
42
|
+
success: Location.response(Pty.Info),
|
|
43
|
+
error: PtyNotFoundError,
|
|
44
|
+
})
|
|
45
|
+
.annotateMerge(locationQueryOpenApi)
|
|
46
|
+
.annotateMerge(OpenApi.annotations({
|
|
47
|
+
identifier: "pty.get",
|
|
48
|
+
summary: "Get PTY session",
|
|
49
|
+
description: "Get one PTY session, including its exit code once exited.",
|
|
50
|
+
})))
|
|
51
|
+
.add(HttpApiEndpoint.put("pty.update", "/api/pty/:ptyID", {
|
|
52
|
+
params: { ptyID: Pty.ID },
|
|
53
|
+
query: LocationQuery,
|
|
54
|
+
payload: Pty.UpdateInput,
|
|
55
|
+
success: Location.response(Pty.Info),
|
|
56
|
+
error: PtyNotFoundError,
|
|
57
|
+
})
|
|
58
|
+
.annotateMerge(locationQueryOpenApi)
|
|
59
|
+
.annotateMerge(OpenApi.annotations({
|
|
60
|
+
identifier: "pty.update",
|
|
61
|
+
summary: "Update PTY session",
|
|
62
|
+
description: "Update the title or viewport size of one PTY session.",
|
|
63
|
+
})))
|
|
64
|
+
.add(HttpApiEndpoint.delete("pty.remove", "/api/pty/:ptyID", {
|
|
65
|
+
params: { ptyID: Pty.ID },
|
|
66
|
+
query: LocationQuery,
|
|
67
|
+
success: HttpApiSchema.NoContent,
|
|
68
|
+
error: PtyNotFoundError,
|
|
69
|
+
})
|
|
70
|
+
.annotateMerge(locationQueryOpenApi)
|
|
71
|
+
.annotateMerge(OpenApi.annotations({
|
|
72
|
+
identifier: "pty.remove",
|
|
73
|
+
summary: "Remove PTY session",
|
|
74
|
+
description: "Terminate and remove one PTY session.",
|
|
75
|
+
})))
|
|
76
|
+
.add(HttpApiEndpoint.post("pty.connectToken", "/api/pty/:ptyID/connect-token", {
|
|
77
|
+
params: { ptyID: Pty.ID },
|
|
78
|
+
query: LocationQuery,
|
|
79
|
+
headers: Schema.Struct({
|
|
80
|
+
[PTY_CONNECT_TOKEN_HEADER]: Schema.optional(Schema.String).annotateKey({
|
|
81
|
+
description: `Must be ${PTY_CONNECT_TOKEN_HEADER_VALUE}; requests without it are refused.`,
|
|
82
|
+
}),
|
|
83
|
+
}),
|
|
84
|
+
success: Location.response(PtyTicket.ConnectToken),
|
|
85
|
+
error: [ForbiddenError, PtyNotFoundError],
|
|
86
|
+
})
|
|
87
|
+
.annotateMerge(locationQueryOpenApi)
|
|
88
|
+
.annotateMerge(OpenApi.annotations({
|
|
89
|
+
identifier: "pty.connect.token",
|
|
90
|
+
summary: "Create PTY WebSocket token",
|
|
91
|
+
description: "Create a short-lived single-use ticket for opening a PTY WebSocket connection.",
|
|
92
|
+
})))
|
|
93
|
+
.middleware(locationMiddleware)
|
|
94
|
+
.add(
|
|
95
|
+
// Query fields are decoded in the raw handler before upgrade work.
|
|
96
|
+
HttpApiEndpoint.get("pty.connect", PTY_CONNECT_PATH, {
|
|
97
|
+
params: { ptyID: Pty.ID },
|
|
98
|
+
success: Schema.Boolean,
|
|
99
|
+
error: [ForbiddenError, PtyNotFoundError, LocationNotFoundError],
|
|
100
|
+
}).annotateMerge(OpenApi.annotations({
|
|
101
|
+
identifier: "pty.connect",
|
|
102
|
+
summary: "Connect to PTY session",
|
|
103
|
+
description: "Establish a WebSocket connection streaming PTY output and accepting terminal input.",
|
|
104
|
+
transform: (operation) => ({
|
|
105
|
+
...operation,
|
|
106
|
+
"x-websocket": true,
|
|
107
|
+
parameters: [
|
|
108
|
+
...(operation.parameters ?? []),
|
|
109
|
+
...Object.entries({
|
|
110
|
+
"location[directory]": "Absolute path of the location directory. Omit to use the server's default location.",
|
|
111
|
+
cursor: "Output offset to replay from. Use -1 to start at the current end; omit to replay all retained output.",
|
|
112
|
+
[PTY_CONNECT_TICKET_QUERY]: "Single-use ticket from pty.connect.token, which authorizes the connection without the usual credentials.",
|
|
113
|
+
}).map(([name, description]) => ({ in: "query", name, description, schema: { type: "string" } })),
|
|
114
|
+
],
|
|
115
|
+
}),
|
|
116
|
+
})))
|
|
117
|
+
.annotateMerge(OpenApi.annotations({ title: "pty", description: "Experimental location-scoped PTY routes." }));
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import { Schema } from "effect";
|
|
2
|
+
import { HttpApiEndpoint, HttpApiSchema } from "effect/http-api";
|
|
3
|
+
import { InvalidRequestError, PushDeviceNotFoundError } from "../errors.js";
|
|
4
|
+
/** Lives in the `server.experimental` group (see `groups/experimental.ts`). */
|
|
5
|
+
export declare const PushEndpoints: readonly [HttpApiEndpoint.HttpApiEndpoint<"push.get", "GET", "/api/experimental/push", never, never, never, never, Schema.toCodecJson<Schema.Struct<{
|
|
6
|
+
readonly data: Schema.Struct<{
|
|
7
|
+
readonly settings: Schema.Struct<{
|
|
8
|
+
readonly paused: Schema.Boolean;
|
|
9
|
+
readonly until: Schema.decodeTo<Schema.optional<Schema.toType<Schema.Int>>, Schema.optionalKey<Schema.Int>, never, never>;
|
|
10
|
+
}>;
|
|
11
|
+
readonly devices: Schema.$Array<Schema.Struct<{
|
|
12
|
+
readonly id: Schema.brand<Schema.String, "Push.DeviceID">;
|
|
13
|
+
readonly name: Schema.String;
|
|
14
|
+
readonly platform: Schema.Literals<readonly ["android", "ios"]>;
|
|
15
|
+
readonly expiresAt: Schema.Int;
|
|
16
|
+
readonly settings: Schema.Struct<{
|
|
17
|
+
readonly default: Schema.Literals<readonly ["all", "attention", "none"]>;
|
|
18
|
+
}>;
|
|
19
|
+
readonly paused: Schema.Boolean;
|
|
20
|
+
readonly sessions: Schema.$Record<Schema.String, Schema.Struct<{
|
|
21
|
+
readonly level: Schema.Literals<readonly ["all", "attention", "none"]>;
|
|
22
|
+
readonly until: Schema.decodeTo<Schema.optional<Schema.toType<Schema.Int>>, Schema.optionalKey<Schema.Int>, never, never>;
|
|
23
|
+
}>>;
|
|
24
|
+
readonly time: Schema.Struct<{
|
|
25
|
+
readonly created: Schema.Int;
|
|
26
|
+
readonly updated: Schema.Int;
|
|
27
|
+
}>;
|
|
28
|
+
}>>;
|
|
29
|
+
readonly sessions: Schema.$Record<Schema.String, Schema.Struct<{
|
|
30
|
+
readonly level: Schema.Literals<readonly ["all", "attention", "none"]>;
|
|
31
|
+
readonly until: Schema.decodeTo<Schema.optional<Schema.toType<Schema.Int>>, Schema.optionalKey<Schema.Int>, never, never>;
|
|
32
|
+
}>>;
|
|
33
|
+
}>;
|
|
34
|
+
}>>, never, never, never>, HttpApiEndpoint.HttpApiEndpoint<"push.device.register", "PUT", "/api/experimental/push/device/:deviceID", Schema.toCodecStringTree<Schema.Struct<{
|
|
35
|
+
deviceID: Schema.brand<Schema.String, "Push.DeviceID">;
|
|
36
|
+
}>>, never, Schema.toCodecJson<Schema.Struct<{
|
|
37
|
+
readonly callbackURL: Schema.String;
|
|
38
|
+
readonly expiresAt: Schema.Int;
|
|
39
|
+
readonly publicKey: Schema.String;
|
|
40
|
+
readonly platform: Schema.Literals<readonly ["android", "ios"]>;
|
|
41
|
+
readonly name: Schema.String;
|
|
42
|
+
readonly settings: Schema.decodeTo<Schema.optional<Schema.toType<Schema.Struct<{
|
|
43
|
+
readonly default: Schema.Literals<readonly ["all", "attention", "none"]>;
|
|
44
|
+
}>>>, Schema.optionalKey<Schema.Struct<{
|
|
45
|
+
readonly default: Schema.Literals<readonly ["all", "attention", "none"]>;
|
|
46
|
+
}>>, never, never>;
|
|
47
|
+
}>>, never, Schema.toCodecJson<Schema.Struct<{
|
|
48
|
+
readonly data: Schema.Struct<{
|
|
49
|
+
readonly publicKey: Schema.String;
|
|
50
|
+
}>;
|
|
51
|
+
}>>, Schema.toCodecJson<typeof InvalidRequestError>, never, never>, HttpApiEndpoint.HttpApiEndpoint<"push.device.remove", "DELETE", "/api/experimental/push/device/:deviceID", Schema.toCodecStringTree<Schema.Struct<{
|
|
52
|
+
deviceID: Schema.brand<Schema.String, "Push.DeviceID">;
|
|
53
|
+
}>>, never, never, never, Schema.toCodecJson<HttpApiSchema.NoContent>, never, never, never>, HttpApiEndpoint.HttpApiEndpoint<"push.device.update", "PATCH", "/api/experimental/push/device/:deviceID", Schema.toCodecStringTree<Schema.Struct<{
|
|
54
|
+
deviceID: Schema.brand<Schema.String, "Push.DeviceID">;
|
|
55
|
+
}>>, never, Schema.toCodecJson<Schema.Struct<{
|
|
56
|
+
readonly paused: Schema.decodeTo<Schema.optional<Schema.toType<Schema.Boolean>>, Schema.optionalKey<Schema.Boolean>, never, never>;
|
|
57
|
+
readonly settings: Schema.decodeTo<Schema.optional<Schema.toType<Schema.Struct<{
|
|
58
|
+
readonly default: Schema.Literals<readonly ["all", "attention", "none"]>;
|
|
59
|
+
}>>>, Schema.optionalKey<Schema.Struct<{
|
|
60
|
+
readonly default: Schema.Literals<readonly ["all", "attention", "none"]>;
|
|
61
|
+
}>>, never, never>;
|
|
62
|
+
}>>, never, Schema.toCodecJson<Schema.Struct<{
|
|
63
|
+
readonly data: Schema.Struct<{
|
|
64
|
+
readonly id: Schema.brand<Schema.String, "Push.DeviceID">;
|
|
65
|
+
readonly name: Schema.String;
|
|
66
|
+
readonly platform: Schema.Literals<readonly ["android", "ios"]>;
|
|
67
|
+
readonly expiresAt: Schema.Int;
|
|
68
|
+
readonly settings: Schema.Struct<{
|
|
69
|
+
readonly default: Schema.Literals<readonly ["all", "attention", "none"]>;
|
|
70
|
+
}>;
|
|
71
|
+
readonly paused: Schema.Boolean;
|
|
72
|
+
readonly sessions: Schema.$Record<Schema.String, Schema.Struct<{
|
|
73
|
+
readonly level: Schema.Literals<readonly ["all", "attention", "none"]>;
|
|
74
|
+
readonly until: Schema.decodeTo<Schema.optional<Schema.toType<Schema.Int>>, Schema.optionalKey<Schema.Int>, never, never>;
|
|
75
|
+
}>>;
|
|
76
|
+
readonly time: Schema.Struct<{
|
|
77
|
+
readonly created: Schema.Int;
|
|
78
|
+
readonly updated: Schema.Int;
|
|
79
|
+
}>;
|
|
80
|
+
}>;
|
|
81
|
+
}>>, Schema.toCodecJson<typeof PushDeviceNotFoundError>, never, never>, HttpApiEndpoint.HttpApiEndpoint<"push.device.session.set", "PUT", "/api/experimental/push/device/:deviceID/session/:sessionID", Schema.toCodecStringTree<Schema.Struct<{
|
|
82
|
+
deviceID: Schema.brand<Schema.String, "Push.DeviceID">;
|
|
83
|
+
sessionID: Schema.brand<Schema.String, "SessionID"> & {
|
|
84
|
+
create: () => string & import("effect/Brand").Brand<"SessionID">;
|
|
85
|
+
};
|
|
86
|
+
}>>, never, Schema.toCodecJson<Schema.Struct<{
|
|
87
|
+
readonly level: Schema.Literals<readonly ["all", "attention", "none"]>;
|
|
88
|
+
readonly until: Schema.decodeTo<Schema.optional<Schema.toType<Schema.Int>>, Schema.optionalKey<Schema.Int>, never, never>;
|
|
89
|
+
}>>, never, Schema.toCodecJson<Schema.Struct<{
|
|
90
|
+
readonly data: Schema.Struct<{
|
|
91
|
+
readonly level: Schema.Literals<readonly ["all", "attention", "none"]>;
|
|
92
|
+
readonly until: Schema.decodeTo<Schema.optional<Schema.toType<Schema.Int>>, Schema.optionalKey<Schema.Int>, never, never>;
|
|
93
|
+
}>;
|
|
94
|
+
}>>, Schema.toCodecJson<typeof InvalidRequestError | typeof PushDeviceNotFoundError>, never, never>, HttpApiEndpoint.HttpApiEndpoint<"push.device.session.remove", "DELETE", "/api/experimental/push/device/:deviceID/session/:sessionID", Schema.toCodecStringTree<Schema.Struct<{
|
|
95
|
+
deviceID: Schema.brand<Schema.String, "Push.DeviceID">;
|
|
96
|
+
sessionID: Schema.brand<Schema.String, "SessionID"> & {
|
|
97
|
+
create: () => string & import("effect/Brand").Brand<"SessionID">;
|
|
98
|
+
};
|
|
99
|
+
}>>, never, never, never, Schema.toCodecJson<HttpApiSchema.NoContent>, Schema.toCodecJson<typeof PushDeviceNotFoundError>, never, never>, HttpApiEndpoint.HttpApiEndpoint<"push.session.set", "PUT", "/api/experimental/push/session/:sessionID", Schema.toCodecStringTree<Schema.Struct<{
|
|
100
|
+
sessionID: Schema.brand<Schema.String, "SessionID"> & {
|
|
101
|
+
create: () => string & import("effect/Brand").Brand<"SessionID">;
|
|
102
|
+
};
|
|
103
|
+
}>>, never, Schema.toCodecJson<Schema.Struct<{
|
|
104
|
+
readonly level: Schema.Literals<readonly ["all", "attention", "none"]>;
|
|
105
|
+
readonly until: Schema.decodeTo<Schema.optional<Schema.toType<Schema.Int>>, Schema.optionalKey<Schema.Int>, never, never>;
|
|
106
|
+
}>>, never, Schema.toCodecJson<Schema.Struct<{
|
|
107
|
+
readonly data: Schema.Struct<{
|
|
108
|
+
readonly level: Schema.Literals<readonly ["all", "attention", "none"]>;
|
|
109
|
+
readonly until: Schema.decodeTo<Schema.optional<Schema.toType<Schema.Int>>, Schema.optionalKey<Schema.Int>, never, never>;
|
|
110
|
+
}>;
|
|
111
|
+
}>>, Schema.toCodecJson<typeof InvalidRequestError>, never, never>, HttpApiEndpoint.HttpApiEndpoint<"push.session.remove", "DELETE", "/api/experimental/push/session/:sessionID", Schema.toCodecStringTree<Schema.Struct<{
|
|
112
|
+
sessionID: Schema.brand<Schema.String, "SessionID"> & {
|
|
113
|
+
create: () => string & import("effect/Brand").Brand<"SessionID">;
|
|
114
|
+
};
|
|
115
|
+
}>>, never, never, never, Schema.toCodecJson<HttpApiSchema.NoContent>, never, never, never>, HttpApiEndpoint.HttpApiEndpoint<"push.settings.set", "PUT", "/api/experimental/push/settings", never, never, Schema.toCodecJson<Schema.Struct<{
|
|
116
|
+
readonly paused: Schema.Boolean;
|
|
117
|
+
readonly until: Schema.decodeTo<Schema.optional<Schema.toType<Schema.Int>>, Schema.optionalKey<Schema.Int>, never, never>;
|
|
118
|
+
}>>, never, Schema.toCodecJson<Schema.Struct<{
|
|
119
|
+
readonly data: Schema.Struct<{
|
|
120
|
+
readonly paused: Schema.Boolean;
|
|
121
|
+
readonly until: Schema.decodeTo<Schema.optional<Schema.toType<Schema.Int>>, Schema.optionalKey<Schema.Int>, never, never>;
|
|
122
|
+
}>;
|
|
123
|
+
}>>, Schema.toCodecJson<typeof InvalidRequestError>, never, never>];
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { Push } from "@radheim/schema/push";
|
|
2
|
+
import { Session } from "@radheim/schema/session";
|
|
3
|
+
import { Schema } from "effect";
|
|
4
|
+
import { HttpApiEndpoint, HttpApiSchema, OpenApi } from "effect/http-api";
|
|
5
|
+
import { InvalidRequestError, PushDeviceNotFoundError } from "../errors.js";
|
|
6
|
+
const EXPERIMENTAL = "Experimental: may change without compatibility guarantees.";
|
|
7
|
+
const annotations = (identifier, summary, description) => OpenApi.annotations({
|
|
8
|
+
identifier: `experimental.push.${identifier}`,
|
|
9
|
+
summary,
|
|
10
|
+
description: `${description} ${EXPERIMENTAL}`,
|
|
11
|
+
transform: (operation) => ({ ...operation, tags: ["experimental"] }),
|
|
12
|
+
});
|
|
13
|
+
/** Lives in the `server.experimental` group (see `groups/experimental.ts`). */
|
|
14
|
+
export const PushEndpoints = [
|
|
15
|
+
HttpApiEndpoint.get("push.get", "/api/experimental/push", {
|
|
16
|
+
success: Schema.Struct({ data: Push.Info }),
|
|
17
|
+
}).annotateMerge(annotations("get", "Get push settings", "List the registered phones with their choices, bells and pauses, the server-wide pause and the shared session bells. Never returns callback URLs or keys.")),
|
|
18
|
+
HttpApiEndpoint.put("push.device.register", "/api/experimental/push/device/:deviceID", {
|
|
19
|
+
params: { deviceID: Push.DeviceID },
|
|
20
|
+
payload: Push.Register,
|
|
21
|
+
success: Schema.Struct({ data: Push.Registered }),
|
|
22
|
+
error: [InvalidRequestError],
|
|
23
|
+
}).annotateMerge(annotations("device.register", "Register a phone", "Register or renew a phone's relay callback URL and public key, and answer with the server's public key for it. Keeps the phone's pause, session bells and, unless given, its level.")),
|
|
24
|
+
HttpApiEndpoint.delete("push.device.remove", "/api/experimental/push/device/:deviceID", {
|
|
25
|
+
params: { deviceID: Push.DeviceID },
|
|
26
|
+
success: HttpApiSchema.NoContent,
|
|
27
|
+
}).annotateMerge(annotations("device.remove", "Remove a phone", "Stop sending notifications to a phone.")),
|
|
28
|
+
HttpApiEndpoint.patch("push.device.update", "/api/experimental/push/device/:deviceID", {
|
|
29
|
+
params: { deviceID: Push.DeviceID },
|
|
30
|
+
payload: Push.DevicePatch,
|
|
31
|
+
success: Schema.Struct({ data: Push.Device }),
|
|
32
|
+
error: [PushDeviceNotFoundError],
|
|
33
|
+
}).annotateMerge(annotations("device.update", "Update a phone", "Pause or resume notifications to one phone, or change the level it gets by default.")),
|
|
34
|
+
HttpApiEndpoint.put("push.device.session.set", "/api/experimental/push/device/:deviceID/session/:sessionID", {
|
|
35
|
+
params: { deviceID: Push.DeviceID, sessionID: Session.ID },
|
|
36
|
+
payload: Push.Bell,
|
|
37
|
+
success: Schema.Struct({ data: Push.Bell }),
|
|
38
|
+
error: [InvalidRequestError, PushDeviceNotFoundError],
|
|
39
|
+
}).annotateMerge(annotations("device.session.set", "Set a phone's session bell", "Choose what one phone gets for one session.")),
|
|
40
|
+
HttpApiEndpoint.delete("push.device.session.remove", "/api/experimental/push/device/:deviceID/session/:sessionID", {
|
|
41
|
+
params: { deviceID: Push.DeviceID, sessionID: Session.ID },
|
|
42
|
+
success: HttpApiSchema.NoContent,
|
|
43
|
+
error: [PushDeviceNotFoundError],
|
|
44
|
+
}).annotateMerge(annotations("device.session.remove", "Clear a phone's session bell", "Let one phone follow the shared bell or its default for one session again.")),
|
|
45
|
+
HttpApiEndpoint.put("push.session.set", "/api/experimental/push/session/:sessionID", {
|
|
46
|
+
params: { sessionID: Session.ID },
|
|
47
|
+
payload: Push.Bell,
|
|
48
|
+
success: Schema.Struct({ data: Push.Bell }),
|
|
49
|
+
error: [InvalidRequestError],
|
|
50
|
+
}).annotateMerge(annotations("session.set", "Set a session bell", "Choose what every phone gets for one session.")),
|
|
51
|
+
HttpApiEndpoint.delete("push.session.remove", "/api/experimental/push/session/:sessionID", {
|
|
52
|
+
params: { sessionID: Session.ID },
|
|
53
|
+
success: HttpApiSchema.NoContent,
|
|
54
|
+
}).annotateMerge(annotations("session.remove", "Clear a session bell", "Let every phone follow its default for one session again.")),
|
|
55
|
+
HttpApiEndpoint.put("push.settings.set", "/api/experimental/push/settings", {
|
|
56
|
+
payload: Push.Settings,
|
|
57
|
+
success: Schema.Struct({ data: Push.Settings }),
|
|
58
|
+
error: [InvalidRequestError],
|
|
59
|
+
}).annotateMerge(annotations("settings.set", "Pause all notifications", "Pause or resume notifications to every phone.")),
|
|
60
|
+
];
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { Schema } from "effect";
|
|
2
|
+
import { HttpApiEndpoint, HttpApiGroup } from "effect/http-api";
|
|
3
|
+
export declare const ReferenceGroup: HttpApiGroup.HttpApiGroup<"server.reference", HttpApiEndpoint.HttpApiEndpoint<"reference.list", "GET", "/api/reference", never, Schema.toCodecStringTree<Schema.Struct<{
|
|
4
|
+
readonly location: Schema.optional<Schema.Struct<{
|
|
5
|
+
readonly directory: Schema.optional<Schema.String>;
|
|
6
|
+
}>>;
|
|
7
|
+
}>>, never, never, Schema.toCodecJson<Schema.Struct<{
|
|
8
|
+
readonly location: Schema.Struct<{
|
|
9
|
+
readonly directory: Schema.brand<Schema.String, "AbsolutePath">;
|
|
10
|
+
}>;
|
|
11
|
+
readonly data: Schema.$Array<Schema.Struct<{
|
|
12
|
+
readonly name: Schema.String;
|
|
13
|
+
readonly path: Schema.brand<Schema.String, "AbsolutePath">;
|
|
14
|
+
readonly description: Schema.decodeTo<Schema.optional<Schema.toType<Schema.String>>, Schema.optionalKey<Schema.String>, never, never>;
|
|
15
|
+
readonly hidden: Schema.decodeTo<Schema.optional<Schema.toType<Schema.Boolean>>, Schema.optionalKey<Schema.Boolean>, never, never>;
|
|
16
|
+
readonly source: Schema.Union<readonly [Schema.Struct<{
|
|
17
|
+
readonly type: Schema.Literal<"local">;
|
|
18
|
+
readonly path: Schema.brand<Schema.String, "AbsolutePath">;
|
|
19
|
+
}>, Schema.Struct<{
|
|
20
|
+
readonly type: Schema.Literal<"git">;
|
|
21
|
+
readonly repository: Schema.String;
|
|
22
|
+
readonly branch: Schema.decodeTo<Schema.optional<Schema.toType<Schema.String>>, Schema.optionalKey<Schema.String>, never, never>;
|
|
23
|
+
}>]>;
|
|
24
|
+
}>>;
|
|
25
|
+
}>>, never, never, never>, false>;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { Location } from "@radheim/schema/location";
|
|
2
|
+
import { Reference } from "@radheim/schema/reference";
|
|
3
|
+
import { Schema, Struct } from "effect";
|
|
4
|
+
import { HttpApiEndpoint, HttpApiGroup, OpenApi } from "effect/http-api";
|
|
5
|
+
import { LocationQuery, locationQueryOpenApi } from "./location.js";
|
|
6
|
+
const PublicLocalSource = Schema.Struct(Struct.omit(Reference.LocalSource.fields, ["description", "hidden"])).annotate({
|
|
7
|
+
identifier: "Reference.LocalSource",
|
|
8
|
+
});
|
|
9
|
+
const PublicGitSource = Schema.Struct(Struct.omit(Reference.GitSource.fields, ["description", "hidden"])).annotate({
|
|
10
|
+
identifier: "Reference.GitSource",
|
|
11
|
+
});
|
|
12
|
+
const PublicSource = Schema.Union([PublicLocalSource, PublicGitSource])
|
|
13
|
+
.pipe(Schema.toTaggedUnion("type"))
|
|
14
|
+
.annotate({ identifier: "Reference.Source" });
|
|
15
|
+
const PublicInfo = Schema.Struct({
|
|
16
|
+
...Struct.omit(Reference.Info.fields, ["source"]),
|
|
17
|
+
source: PublicSource,
|
|
18
|
+
}).annotate({ identifier: "Reference.Info" });
|
|
19
|
+
export const ReferenceGroup = HttpApiGroup.make("server.reference")
|
|
20
|
+
.add(HttpApiEndpoint.get("reference.list", "/api/reference", {
|
|
21
|
+
query: LocationQuery,
|
|
22
|
+
success: Location.response(Schema.Array(PublicInfo)),
|
|
23
|
+
})
|
|
24
|
+
.annotateMerge(locationQueryOpenApi)
|
|
25
|
+
.annotateMerge(OpenApi.annotations({
|
|
26
|
+
identifier: "reference.list",
|
|
27
|
+
summary: "List references",
|
|
28
|
+
description: "List references available in the requested location.",
|
|
29
|
+
})))
|
|
30
|
+
.annotateMerge(OpenApi.annotations({
|
|
31
|
+
title: "reference",
|
|
32
|
+
description: "Location-scoped project references.",
|
|
33
|
+
}));
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Schema } from "effect";
|
|
2
|
+
import { HttpApiEndpoint, HttpApiGroup } from "effect/http-api";
|
|
3
|
+
import { RpcError, RpcInternalError } from "../errors.js";
|
|
4
|
+
export declare const RpcInput: Schema.Struct<{
|
|
5
|
+
readonly input: Schema.decodeTo<Schema.optional<Schema.toType<Schema.Unknown>>, Schema.optionalKey<Schema.Unknown>, never, never>;
|
|
6
|
+
}>;
|
|
7
|
+
export declare const RpcOutput: Schema.Struct<{
|
|
8
|
+
readonly output: Schema.optionalKey<Schema.Unknown>;
|
|
9
|
+
}>;
|
|
10
|
+
export declare const RpcGroup: HttpApiGroup.HttpApiGroup<"server.rpc", HttpApiEndpoint.HttpApiEndpoint<"rpc.call", "POST", "/api/rpc/:rpcID/:method", Schema.toCodecStringTree<Schema.Struct<{
|
|
11
|
+
rpcID: Schema.String;
|
|
12
|
+
method: Schema.String;
|
|
13
|
+
}>>, Schema.toCodecStringTree<Schema.Struct<{
|
|
14
|
+
readonly location: Schema.optional<Schema.Struct<{
|
|
15
|
+
readonly directory: Schema.optional<Schema.String>;
|
|
16
|
+
}>>;
|
|
17
|
+
}>>, Schema.toCodecJson<Schema.Struct<{
|
|
18
|
+
readonly input: Schema.decodeTo<Schema.optional<Schema.toType<Schema.Unknown>>, Schema.optionalKey<Schema.Unknown>, never, never>;
|
|
19
|
+
}>>, never, Schema.toCodecJson<Schema.Struct<{
|
|
20
|
+
readonly output: Schema.optionalKey<Schema.Unknown>;
|
|
21
|
+
}>>, Schema.toCodecJson<typeof RpcError | typeof RpcInternalError>, never, never>, false>;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { optional } from "@radheim/schema/schema";
|
|
2
|
+
import { Schema } from "effect";
|
|
3
|
+
import { HttpApiEndpoint, HttpApiGroup, OpenApi } from "effect/http-api";
|
|
4
|
+
import { RpcError, RpcInternalError } from "../errors.js";
|
|
5
|
+
import { LocationQuery, locationQueryOpenApi } from "./location.js";
|
|
6
|
+
export const RpcInput = Schema.Struct({ input: optional(Schema.Unknown) }).annotate({ identifier: "Rpc.Input" });
|
|
7
|
+
export const RpcOutput = Schema.Struct({ output: Schema.optionalKey(Schema.Unknown) }).annotate({
|
|
8
|
+
identifier: "Rpc.Output",
|
|
9
|
+
});
|
|
10
|
+
export const RpcGroup = HttpApiGroup.make("server.rpc")
|
|
11
|
+
.add(HttpApiEndpoint.post("rpc.call", "/api/rpc/:rpcID/:method", {
|
|
12
|
+
params: { rpcID: Schema.String, method: Schema.String },
|
|
13
|
+
query: LocationQuery,
|
|
14
|
+
payload: RpcInput,
|
|
15
|
+
success: RpcOutput,
|
|
16
|
+
error: [RpcError, RpcInternalError],
|
|
17
|
+
})
|
|
18
|
+
.annotateMerge(locationQueryOpenApi)
|
|
19
|
+
.annotateMerge(OpenApi.annotations({
|
|
20
|
+
identifier: "rpc.call",
|
|
21
|
+
summary: "Call a plugin RPC",
|
|
22
|
+
description: "Dispatch a method to the currently registered RPC at the requested location.",
|
|
23
|
+
})))
|
|
24
|
+
.annotateMerge(OpenApi.annotations({ title: "rpc", description: "Plugin RPC routes." }));
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { Schema } from "effect";
|
|
2
|
+
import { HttpApiEndpoint, HttpApiGroup } from "effect/http-api";
|
|
3
|
+
import { UnauthorizedError } from "../errors.js";
|
|
4
|
+
export declare const ServerInfo: Schema.Struct<{
|
|
5
|
+
readonly version: Schema.String;
|
|
6
|
+
readonly pid: Schema.Int;
|
|
7
|
+
readonly hostname: Schema.optional<Schema.String>;
|
|
8
|
+
readonly urls: Schema.$Array<Schema.String>;
|
|
9
|
+
readonly paths: Schema.Struct<{
|
|
10
|
+
readonly tmp: Schema.String;
|
|
11
|
+
}>;
|
|
12
|
+
readonly capabilities: Schema.optional<Schema.Struct<{
|
|
13
|
+
readonly persistentPty: Schema.optional<Schema.Boolean>;
|
|
14
|
+
}>>;
|
|
15
|
+
}>;
|
|
16
|
+
export type ServerInfo = typeof ServerInfo.Type;
|
|
17
|
+
export declare const PairingCode: Schema.Struct<{
|
|
18
|
+
readonly code: Schema.String;
|
|
19
|
+
readonly expires_in: Schema.Int;
|
|
20
|
+
}>;
|
|
21
|
+
export type PairingCode = typeof PairingCode.Type;
|
|
22
|
+
export declare const PairingSession: Schema.Struct<{
|
|
23
|
+
readonly token: Schema.String;
|
|
24
|
+
}>;
|
|
25
|
+
export type PairingSession = typeof PairingSession.Type;
|
|
26
|
+
export declare const PAIRING_CONNECT_PATH = "/auth/connect/:code";
|
|
27
|
+
export declare function isPairingConnectURL(url: URL): boolean;
|
|
28
|
+
export declare const ServerGroup: HttpApiGroup.HttpApiGroup<"server.server", HttpApiEndpoint.HttpApiEndpoint<"server.connect", "GET", "/auth/connect/:code", Schema.toCodecStringTree<Schema.Struct<{
|
|
29
|
+
code: Schema.String;
|
|
30
|
+
}>>, never, never, never, Schema.toCodecJson<Schema.Struct<{
|
|
31
|
+
readonly token: Schema.String;
|
|
32
|
+
}>>, Schema.toCodecJson<typeof UnauthorizedError>, never, never> | HttpApiEndpoint.HttpApiEndpoint<"server.info", "GET", "/api/info", never, never, never, never, Schema.toCodecJson<Schema.Struct<{
|
|
33
|
+
readonly version: Schema.String;
|
|
34
|
+
readonly pid: Schema.Int;
|
|
35
|
+
readonly hostname: Schema.optional<Schema.String>;
|
|
36
|
+
readonly urls: Schema.$Array<Schema.String>;
|
|
37
|
+
readonly paths: Schema.Struct<{
|
|
38
|
+
readonly tmp: Schema.String;
|
|
39
|
+
}>;
|
|
40
|
+
readonly capabilities: Schema.optional<Schema.Struct<{
|
|
41
|
+
readonly persistentPty: Schema.optional<Schema.Boolean>;
|
|
42
|
+
}>>;
|
|
43
|
+
}>>, never, never, never> | HttpApiEndpoint.HttpApiEndpoint<"server.pair", "POST", "/api/pair", never, never, never, never, Schema.toCodecJson<Schema.Struct<{
|
|
44
|
+
readonly code: Schema.String;
|
|
45
|
+
readonly expires_in: Schema.Int;
|
|
46
|
+
}>>, never, never, never>, false>;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { Schema } from "effect";
|
|
2
|
+
import { HttpApiEndpoint, HttpApiGroup, OpenApi } from "effect/http-api";
|
|
3
|
+
import { UnauthorizedError } from "../errors.js";
|
|
4
|
+
export const ServerInfo = Schema.Struct({
|
|
5
|
+
version: Schema.String,
|
|
6
|
+
// 0 means the runtime has no OS process identity (e.g. workerd).
|
|
7
|
+
pid: Schema.Int.check(Schema.isGreaterThanOrEqualTo(0)),
|
|
8
|
+
// The machine's name, absent where the runtime has none (e.g. workerd).
|
|
9
|
+
hostname: Schema.optional(Schema.String),
|
|
10
|
+
urls: Schema.Array(Schema.String),
|
|
11
|
+
paths: Schema.Struct({
|
|
12
|
+
tmp: Schema.String,
|
|
13
|
+
}),
|
|
14
|
+
// Optional at every level so clients still decode servers that predate a capability.
|
|
15
|
+
capabilities: Schema.optional(Schema.Struct({
|
|
16
|
+
persistentPty: Schema.optional(Schema.Boolean),
|
|
17
|
+
})),
|
|
18
|
+
}).annotate({ identifier: "ServerInfo" });
|
|
19
|
+
export const PairingCode = Schema.Struct({
|
|
20
|
+
code: Schema.String,
|
|
21
|
+
expires_in: Schema.Int,
|
|
22
|
+
}).annotate({ identifier: "PairingCode" });
|
|
23
|
+
export const PairingSession = Schema.Struct({
|
|
24
|
+
token: Schema.String,
|
|
25
|
+
}).annotate({ identifier: "PairingSession" });
|
|
26
|
+
export const PAIRING_CONNECT_PATH = "/auth/connect/:code";
|
|
27
|
+
const PAIRING_CONNECT_URL = /^\/auth\/connect\/[^/]+$/;
|
|
28
|
+
export function isPairingConnectURL(url) {
|
|
29
|
+
return PAIRING_CONNECT_URL.test(url.pathname);
|
|
30
|
+
}
|
|
31
|
+
export const ServerGroup = HttpApiGroup.make("server.server")
|
|
32
|
+
.add(HttpApiEndpoint.get("server.info", "/api/info", {
|
|
33
|
+
success: ServerInfo,
|
|
34
|
+
}).annotateMerge(OpenApi.annotations({
|
|
35
|
+
identifier: "server.info",
|
|
36
|
+
summary: "Get server info",
|
|
37
|
+
description: "Return the server identity, connection URLs, paths, and readiness status.",
|
|
38
|
+
})))
|
|
39
|
+
.add(HttpApiEndpoint.post("server.pair", "/api/pair", {
|
|
40
|
+
success: PairingCode,
|
|
41
|
+
}).annotateMerge(OpenApi.annotations({
|
|
42
|
+
identifier: "server.pair",
|
|
43
|
+
summary: "Create pairing code",
|
|
44
|
+
description: "Create a short-lived, single-use code for a /auth/connect/:code pairing link.",
|
|
45
|
+
})))
|
|
46
|
+
.add(HttpApiEndpoint.get("server.connect", PAIRING_CONNECT_PATH, {
|
|
47
|
+
params: { code: Schema.String },
|
|
48
|
+
success: PairingSession,
|
|
49
|
+
error: UnauthorizedError,
|
|
50
|
+
}).annotateMerge(OpenApi.annotations({
|
|
51
|
+
identifier: "server.connect",
|
|
52
|
+
summary: "Redeem pairing code",
|
|
53
|
+
description: "Redeem a pairing code. Browsers receive a session cookie and a redirect to the web app; requests that accept JSON receive a session token to use as the password.",
|
|
54
|
+
})))
|
|
55
|
+
.annotateMerge(OpenApi.annotations({ title: "server" }));
|