@opencode/protocol 0.0.0-dev-1325 → 0.0.0-dev-1328
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/client.js +2 -0
- package/dist/errors.d.ts +6 -0
- package/dist/errors.js +5 -0
- package/dist/groups/experimental.d.ts +24 -1
- package/dist/groups/experimental.js +2 -1
- package/dist/groups/machine.d.ts +76 -0
- package/dist/groups/machine.js +75 -0
- package/package.json +2 -2
package/dist/client.js
CHANGED
|
@@ -84,6 +84,7 @@ export const promiseOmitEndpoints = new Set([
|
|
|
84
84
|
"pty.connect",
|
|
85
85
|
"persistentPty.connect",
|
|
86
86
|
"mcp.client",
|
|
87
|
+
"machine.link",
|
|
87
88
|
"generate.textLegacy",
|
|
88
89
|
]);
|
|
89
90
|
export const effectOmitEndpoints = new Set([
|
|
@@ -95,5 +96,6 @@ export const effectOmitEndpoints = new Set([
|
|
|
95
96
|
"pty.connect",
|
|
96
97
|
"persistentPty.connect",
|
|
97
98
|
"mcp.client",
|
|
99
|
+
"machine.link",
|
|
98
100
|
"generate.textLegacy",
|
|
99
101
|
]);
|
package/dist/errors.d.ts
CHANGED
|
@@ -252,4 +252,10 @@ declare const ArtifactNotFoundError_base: Schema.Class<ArtifactNotFoundError, Sc
|
|
|
252
252
|
}>, import("effect/Cause").YieldableError>;
|
|
253
253
|
export declare class ArtifactNotFoundError extends ArtifactNotFoundError_base {
|
|
254
254
|
}
|
|
255
|
+
declare const MachineNotFoundError_base: Schema.Class<MachineNotFoundError, Schema.TaggedStruct<"MachineNotFoundError", {
|
|
256
|
+
readonly machine: Schema.String;
|
|
257
|
+
readonly message: Schema.String;
|
|
258
|
+
}>, import("effect/Cause").YieldableError>;
|
|
259
|
+
export declare class MachineNotFoundError extends MachineNotFoundError_base {
|
|
260
|
+
}
|
|
255
261
|
export {};
|
package/dist/errors.js
CHANGED
|
@@ -210,3 +210,8 @@ export class ArtifactNotFoundError extends Schema.TaggedError()("ArtifactNotFoun
|
|
|
210
210
|
message: Schema.String,
|
|
211
211
|
}, { httpApiStatus: 404 }) {
|
|
212
212
|
}
|
|
213
|
+
export class MachineNotFoundError extends Schema.TaggedError()("MachineNotFoundError", {
|
|
214
|
+
machine: Schema.String,
|
|
215
|
+
message: Schema.String,
|
|
216
|
+
}, { httpApiStatus: 404 }) {
|
|
217
|
+
}
|
|
@@ -663,7 +663,30 @@ export declare const ExperimentalGroup: import("effect/http-api/HttpApiGroup").H
|
|
|
663
663
|
}>;
|
|
664
664
|
readonly kind: import("effect/Schema").tag<"codemode">;
|
|
665
665
|
}>]>>;
|
|
666
|
-
}>>, import("effect/Schema").toCodecJson<typeof import("../errors.js").InvalidRequestError | typeof import("../errors.js").SessionNotFoundError>, never, never> | import("effect/http-api/HttpApiEndpoint").HttpApiEndpoint<"
|
|
666
|
+
}>>, import("effect/Schema").toCodecJson<typeof import("../errors.js").InvalidRequestError | typeof import("../errors.js").SessionNotFoundError>, never, never> | import("effect/http-api/HttpApiEndpoint").HttpApiEndpoint<"machine.add", "POST", "/api/experimental/machine", never, never, import("effect/Schema").toCodecJson<import("effect/Schema").Struct<{
|
|
667
|
+
readonly name: import("effect/Schema").String;
|
|
668
|
+
readonly reach: import("effect/Schema").$Array<import("effect/Schema").Struct<{
|
|
669
|
+
readonly type: import("effect/Schema").Literal<"url">;
|
|
670
|
+
readonly url: import("effect/Schema").String;
|
|
671
|
+
}>>;
|
|
672
|
+
readonly replace: import("effect/Schema").optional<import("effect/Schema").Boolean>;
|
|
673
|
+
}>>, never, import("effect/Schema").toCodecJson<import("effect/Schema").Struct<{
|
|
674
|
+
readonly data: import("effect/Schema").Struct<{
|
|
675
|
+
readonly name: import("effect/Schema").String;
|
|
676
|
+
readonly join: import("effect/Schema").String;
|
|
677
|
+
readonly expires: import("effect/Schema").Int;
|
|
678
|
+
}>;
|
|
679
|
+
}>>, import("effect/Schema").toCodecJson<typeof import("../errors.js").InvalidRequestError | typeof import("../errors.js").ConflictError | typeof import("../errors.js").ForbiddenError | typeof import("../errors.js").MachineNotFoundError>, never, never> | import("effect/http-api/HttpApiEndpoint").HttpApiEndpoint<"machine.link", "GET", "/api/experimental/machine/link", never, never, never, never, import("effect/Schema").toCodecJson<import("effect/Schema").Boolean>, never, never, never> | import("effect/http-api/HttpApiEndpoint").HttpApiEndpoint<"machine.list", "GET", "/api/experimental/machine", never, never, never, never, import("effect/Schema").toCodecJson<import("effect/Schema").Struct<{
|
|
680
|
+
readonly data: import("effect/Schema").$Array<import("effect/Schema").Struct<{
|
|
681
|
+
readonly id: import("effect/Schema").String;
|
|
682
|
+
readonly online: import("effect/Schema").Boolean;
|
|
683
|
+
readonly paired: import("effect/Schema").Boolean;
|
|
684
|
+
readonly os: import("effect/Schema").optionalKey<import("effect/Schema").String>;
|
|
685
|
+
readonly arch: import("effect/Schema").optionalKey<import("effect/Schema").String>;
|
|
686
|
+
}>>;
|
|
687
|
+
}>>, import("effect/Schema").toCodecJson<typeof import("../errors.js").ForbiddenError>, never, never> | import("effect/http-api/HttpApiEndpoint").HttpApiEndpoint<"machine.remove", "DELETE", "/api/experimental/machine/:name", import("effect/Schema").toCodecStringTree<import("effect/Schema").Struct<{
|
|
688
|
+
name: import("effect/Schema").String;
|
|
689
|
+
}>>, never, never, never, import("effect/Schema").toCodecJson<import("effect/http-api/HttpApiSchema").NoContent>, import("effect/Schema").toCodecJson<typeof import("../errors.js").ForbiddenError>, never, never> | import("effect/http-api/HttpApiEndpoint").HttpApiEndpoint<"media.get", "GET", "/api/experimental/media/:hash", import("effect/Schema").toCodecStringTree<import("effect/Schema").Struct<{
|
|
667
690
|
hash: import("effect/Schema").String;
|
|
668
691
|
}>>, never, never, never, import("effect/Schema").toCodecJson<import("effect/Schema").Uint8Array>, import("effect/Schema").toCodecJson<typeof import("../errors.js").InvalidRequestError | typeof import("../errors.js").FileNotFoundError>, never, never> | import("effect/http-api/HttpApiEndpoint").HttpApiEndpoint<"persistentPty.connect", "GET", "/api/experimental/persistent-pty/:ptyID/connect", import("effect/Schema").toCodecStringTree<import("effect/Schema").Struct<{
|
|
669
692
|
ptyID: import("effect/Schema").brand<import("effect/Schema").String, "PtyID"> & {
|
|
@@ -2,7 +2,8 @@ import { ArtifactEndpoints } from "./artifact.js";
|
|
|
2
2
|
import { BlobGetEndpoint } from "./blob.js";
|
|
3
3
|
import { AutomationEndpoints } from "./automation.js";
|
|
4
4
|
import { JobEndpoints } from "./job.js";
|
|
5
|
+
import { MachineEndpoints } from "./machine.js";
|
|
5
6
|
import { MediaGetEndpoint } from "./media.js";
|
|
6
7
|
import { PersistentPtyGroup } from "./persistent-pty.js";
|
|
7
8
|
/** `server.experimental`: routes under /api/experimental, without compatibility guarantees. */
|
|
8
|
-
export const ExperimentalGroup = PersistentPtyGroup.add(MediaGetEndpoint, BlobGetEndpoint, ...AutomationEndpoints, ...ArtifactEndpoints, ...JobEndpoints);
|
|
9
|
+
export const ExperimentalGroup = PersistentPtyGroup.add(MediaGetEndpoint, BlobGetEndpoint, ...AutomationEndpoints, ...ArtifactEndpoints, ...JobEndpoints, ...MachineEndpoints);
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { Schema } from "effect";
|
|
2
|
+
import { HttpApiEndpoint, HttpApiSchema } from "effect/http-api";
|
|
3
|
+
import { ConflictError, ForbiddenError, InvalidRequestError, MachineNotFoundError } from "../errors.js";
|
|
4
|
+
export declare const MACHINE_LINK_PATH = "/api/experimental/machine/link";
|
|
5
|
+
export declare const MachineInfo: Schema.Struct<{
|
|
6
|
+
readonly id: Schema.String;
|
|
7
|
+
readonly online: Schema.Boolean;
|
|
8
|
+
readonly paired: Schema.Boolean;
|
|
9
|
+
readonly os: Schema.optionalKey<Schema.String>;
|
|
10
|
+
readonly arch: Schema.optionalKey<Schema.String>;
|
|
11
|
+
}>;
|
|
12
|
+
export type MachineInfo = typeof MachineInfo.Type;
|
|
13
|
+
export declare const MachineReach: Schema.Struct<{
|
|
14
|
+
readonly type: Schema.Literal<"url">;
|
|
15
|
+
readonly url: Schema.String;
|
|
16
|
+
}>;
|
|
17
|
+
export type MachineReach = typeof MachineReach.Type;
|
|
18
|
+
export declare const MachineAddPayload: Schema.Struct<{
|
|
19
|
+
readonly name: Schema.String;
|
|
20
|
+
readonly reach: Schema.$Array<Schema.Struct<{
|
|
21
|
+
readonly type: Schema.Literal<"url">;
|
|
22
|
+
readonly url: Schema.String;
|
|
23
|
+
}>>;
|
|
24
|
+
readonly replace: Schema.optional<Schema.Boolean>;
|
|
25
|
+
}>;
|
|
26
|
+
export type MachineAddPayload = typeof MachineAddPayload.Type;
|
|
27
|
+
export declare const MachineInvite: Schema.Struct<{
|
|
28
|
+
readonly name: Schema.String;
|
|
29
|
+
readonly join: Schema.String;
|
|
30
|
+
readonly expires: Schema.Int;
|
|
31
|
+
}>;
|
|
32
|
+
export type MachineInvite = typeof MachineInvite.Type;
|
|
33
|
+
/**
|
|
34
|
+
* Whether a request asks to become a WebSocket, the one request the machine link serves and the one the server lets in
|
|
35
|
+
* without its password: a GET with `Upgrade: websocket` and `upgrade` among its `Connection` tokens.
|
|
36
|
+
*/
|
|
37
|
+
export declare function isWebSocketUpgrade(request: {
|
|
38
|
+
readonly method: string;
|
|
39
|
+
readonly headers: Readonly<Record<string, string | undefined>>;
|
|
40
|
+
}): boolean;
|
|
41
|
+
/**
|
|
42
|
+
* The same, for code that runs before the router has matched a route: the path is the request's own, up to its query,
|
|
43
|
+
* compared as it was sent. A URL parser would resolve `..` and a leading `//host` to this path, and the router would not.
|
|
44
|
+
*/
|
|
45
|
+
export declare function isMachineLinkUpgrade(request: {
|
|
46
|
+
readonly method: string;
|
|
47
|
+
readonly url: string;
|
|
48
|
+
readonly headers: Readonly<Record<string, string | undefined>>;
|
|
49
|
+
}): boolean;
|
|
50
|
+
/** Lives in the `server.experimental` group (see `groups/experimental.ts`). */
|
|
51
|
+
export declare const MachineLinkEndpoint: HttpApiEndpoint.HttpApiEndpoint<"machine.link", "GET", "/api/experimental/machine/link", never, never, never, never, Schema.toCodecJson<Schema.Boolean>, never, never, never>;
|
|
52
|
+
/** Lives in the `server.experimental` group (see `groups/experimental.ts`). */
|
|
53
|
+
export declare const MachineEndpoints: readonly [HttpApiEndpoint.HttpApiEndpoint<"machine.link", "GET", "/api/experimental/machine/link", never, never, never, never, Schema.toCodecJson<Schema.Boolean>, never, never, never>, HttpApiEndpoint.HttpApiEndpoint<"machine.list", "GET", "/api/experimental/machine", never, never, never, never, Schema.toCodecJson<Schema.Struct<{
|
|
54
|
+
readonly data: Schema.$Array<Schema.Struct<{
|
|
55
|
+
readonly id: Schema.String;
|
|
56
|
+
readonly online: Schema.Boolean;
|
|
57
|
+
readonly paired: Schema.Boolean;
|
|
58
|
+
readonly os: Schema.optionalKey<Schema.String>;
|
|
59
|
+
readonly arch: Schema.optionalKey<Schema.String>;
|
|
60
|
+
}>>;
|
|
61
|
+
}>>, Schema.toCodecJson<typeof ForbiddenError>, never, never>, HttpApiEndpoint.HttpApiEndpoint<"machine.add", "POST", "/api/experimental/machine", never, never, Schema.toCodecJson<Schema.Struct<{
|
|
62
|
+
readonly name: Schema.String;
|
|
63
|
+
readonly reach: Schema.$Array<Schema.Struct<{
|
|
64
|
+
readonly type: Schema.Literal<"url">;
|
|
65
|
+
readonly url: Schema.String;
|
|
66
|
+
}>>;
|
|
67
|
+
readonly replace: Schema.optional<Schema.Boolean>;
|
|
68
|
+
}>>, never, Schema.toCodecJson<Schema.Struct<{
|
|
69
|
+
readonly data: Schema.Struct<{
|
|
70
|
+
readonly name: Schema.String;
|
|
71
|
+
readonly join: Schema.String;
|
|
72
|
+
readonly expires: Schema.Int;
|
|
73
|
+
}>;
|
|
74
|
+
}>>, Schema.toCodecJson<typeof InvalidRequestError | typeof ConflictError | typeof ForbiddenError | typeof MachineNotFoundError>, never, never>, HttpApiEndpoint.HttpApiEndpoint<"machine.remove", "DELETE", "/api/experimental/machine/:name", Schema.toCodecStringTree<Schema.Struct<{
|
|
75
|
+
name: Schema.String;
|
|
76
|
+
}>>, never, never, never, Schema.toCodecJson<HttpApiSchema.NoContent>, Schema.toCodecJson<typeof ForbiddenError>, never, never>];
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { Schema } from "effect";
|
|
2
|
+
import { HttpApiEndpoint, HttpApiSchema, OpenApi } from "effect/http-api";
|
|
3
|
+
import { ConflictError, ForbiddenError, InvalidRequestError, MachineNotFoundError } from "../errors.js";
|
|
4
|
+
export const MACHINE_LINK_PATH = "/api/experimental/machine/link";
|
|
5
|
+
const EXPERIMENTAL = "Behind the machines flag. Experimental: may change without compatibility guarantees.";
|
|
6
|
+
const annotations = (identifier, summary, description) => OpenApi.annotations({
|
|
7
|
+
identifier: `experimental.machine.${identifier}`,
|
|
8
|
+
summary,
|
|
9
|
+
description: `${description} ${EXPERIMENTAL}`,
|
|
10
|
+
transform: (operation) => ({ ...operation, tags: ["experimental"] }),
|
|
11
|
+
});
|
|
12
|
+
export const MachineInfo = Schema.Struct({
|
|
13
|
+
id: Schema.String,
|
|
14
|
+
online: Schema.Boolean,
|
|
15
|
+
paired: Schema.Boolean,
|
|
16
|
+
os: Schema.optionalKey(Schema.String),
|
|
17
|
+
arch: Schema.optionalKey(Schema.String),
|
|
18
|
+
}).annotate({ identifier: "Machine.Info" });
|
|
19
|
+
export const MachineReach = Schema.Struct({
|
|
20
|
+
type: Schema.Literal("url"),
|
|
21
|
+
url: Schema.String,
|
|
22
|
+
}).annotate({ identifier: "Machine.Reach" });
|
|
23
|
+
export const MachineAddPayload = Schema.Struct({
|
|
24
|
+
name: Schema.String,
|
|
25
|
+
reach: Schema.Array(MachineReach),
|
|
26
|
+
replace: Schema.optional(Schema.Boolean),
|
|
27
|
+
}).annotate({ identifier: "Machine.AddPayload" });
|
|
28
|
+
export const MachineInvite = Schema.Struct({
|
|
29
|
+
name: Schema.String,
|
|
30
|
+
join: Schema.String,
|
|
31
|
+
expires: Schema.Int,
|
|
32
|
+
}).annotate({ identifier: "Machine.Invite" });
|
|
33
|
+
/**
|
|
34
|
+
* Whether a request asks to become a WebSocket, the one request the machine link serves and the one the server lets in
|
|
35
|
+
* without its password: a GET with `Upgrade: websocket` and `upgrade` among its `Connection` tokens.
|
|
36
|
+
*/
|
|
37
|
+
export function isWebSocketUpgrade(request) {
|
|
38
|
+
return (request.method === "GET" &&
|
|
39
|
+
request.headers.upgrade?.toLowerCase() === "websocket" &&
|
|
40
|
+
(request.headers.connection ?? "").split(",").some((token) => token.trim().toLowerCase() === "upgrade"));
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* The same, for code that runs before the router has matched a route: the path is the request's own, up to its query,
|
|
44
|
+
* compared as it was sent. A URL parser would resolve `..` and a leading `//host` to this path, and the router would not.
|
|
45
|
+
*/
|
|
46
|
+
export function isMachineLinkUpgrade(request) {
|
|
47
|
+
return request.url.split("?", 1)[0] === MACHINE_LINK_PATH && isWebSocketUpgrade(request);
|
|
48
|
+
}
|
|
49
|
+
/** Lives in the `server.experimental` group (see `groups/experimental.ts`). */
|
|
50
|
+
export const MachineLinkEndpoint = HttpApiEndpoint.get("machine.link", MACHINE_LINK_PATH, {
|
|
51
|
+
success: Schema.Boolean,
|
|
52
|
+
}).annotateMerge(OpenApi.annotations({
|
|
53
|
+
identifier: "experimental.machine.link",
|
|
54
|
+
summary: "Connect a machine",
|
|
55
|
+
description: "Upgrade to a WebSocket that carries a machine's link to this server: binary messages only, each at most 65,535 bytes. It takes no server password. The link's own handshake, which starts with the machine's first message, is the only way in: it admits a key this server has paired or a valid join string, and closes the socket on anything else without saying why. Behind the machines flag; without it the route does not exist. Experimental: may change without compatibility guarantees.",
|
|
56
|
+
transform: (operation) => ({ ...operation, "x-websocket": true, tags: ["experimental"] }),
|
|
57
|
+
}));
|
|
58
|
+
/** Lives in the `server.experimental` group (see `groups/experimental.ts`). */
|
|
59
|
+
export const MachineEndpoints = [
|
|
60
|
+
MachineLinkEndpoint,
|
|
61
|
+
HttpApiEndpoint.get("machine.list", "/api/experimental/machine", {
|
|
62
|
+
success: Schema.Struct({ data: Schema.Array(MachineInfo) }),
|
|
63
|
+
error: [ForbiddenError],
|
|
64
|
+
}).annotateMerge(annotations("list", "List machines", "List known machines and whether each is paired and online.")),
|
|
65
|
+
HttpApiEndpoint.post("machine.add", "/api/experimental/machine", {
|
|
66
|
+
payload: MachineAddPayload,
|
|
67
|
+
success: Schema.Struct({ data: MachineInvite }),
|
|
68
|
+
error: [InvalidRequestError, ForbiddenError, MachineNotFoundError, ConflictError],
|
|
69
|
+
}).annotateMerge(annotations("add", "Add or invite a machine", "Add a machine by name if it does not exist, then create a single-use join string carrying the given reach addresses.")),
|
|
70
|
+
HttpApiEndpoint.delete("machine.remove", "/api/experimental/machine/:name", {
|
|
71
|
+
params: { name: Schema.String },
|
|
72
|
+
success: HttpApiSchema.NoContent,
|
|
73
|
+
error: [ForbiddenError],
|
|
74
|
+
}).annotateMerge(annotations("remove", "Remove a machine", "Forget a machine by name, closing any live link and revoking its key.")),
|
|
75
|
+
];
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://json.schemastore.org/package.json",
|
|
3
3
|
"name": "@opencode/protocol",
|
|
4
|
-
"version": "0.0.0-dev-
|
|
4
|
+
"version": "0.0.0-dev-1328",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"repository": {
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
"typecheck:tsc": "tsc --noEmit"
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@opencode/schema": "0.0.0-dev-
|
|
38
|
+
"@opencode/schema": "0.0.0-dev-1328",
|
|
39
39
|
"effect": "4.1.0"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|