@zyro-sec/protocol 1.0.1 → 1.0.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.
Files changed (61) hide show
  1. package/openapi.json +33222 -33222
  2. package/package.json +6 -2
  3. package/script/build.ts +9 -9
  4. package/script/generate-openapi.ts +25 -25
  5. package/script/openapi-parameters.ts +30 -30
  6. package/script/openapi-stabilize.ts +102 -102
  7. package/script/pack.ts +5 -5
  8. package/src/api.ts +264 -264
  9. package/src/client.ts +127 -127
  10. package/src/errors.ts +398 -398
  11. package/src/groups/agent.ts +39 -39
  12. package/src/groups/artifact.ts +103 -103
  13. package/src/groups/automation.ts +75 -75
  14. package/src/groups/blob.ts +20 -20
  15. package/src/groups/command.ts +27 -27
  16. package/src/groups/config.ts +46 -46
  17. package/src/groups/credential.ts +72 -72
  18. package/src/groups/debug.ts +68 -68
  19. package/src/groups/event.ts +86 -86
  20. package/src/groups/experimental.ts +19 -19
  21. package/src/groups/form.ts +26 -26
  22. package/src/groups/fs.ts +136 -136
  23. package/src/groups/generate.ts +120 -120
  24. package/src/groups/integration.ts +230 -230
  25. package/src/groups/job.ts +57 -57
  26. package/src/groups/location.ts +66 -66
  27. package/src/groups/machine.ts +120 -120
  28. package/src/groups/mcp.ts +167 -167
  29. package/src/groups/media.ts +23 -23
  30. package/src/groups/message.ts +124 -124
  31. package/src/groups/migration.ts +28 -28
  32. package/src/groups/model.ts +52 -52
  33. package/src/groups/permission.ts +164 -164
  34. package/src/groups/persistent-pty.ts +153 -153
  35. package/src/groups/plugin.ts +80 -80
  36. package/src/groups/project.ts +51 -51
  37. package/src/groups/provider.ts +45 -45
  38. package/src/groups/pty.ts +153 -153
  39. package/src/groups/push.ts +94 -94
  40. package/src/groups/reference.ts +42 -42
  41. package/src/groups/rpc.ts +30 -30
  42. package/src/groups/server.ts +80 -80
  43. package/src/groups/session.ts +918 -918
  44. package/src/groups/shell.ts +88 -88
  45. package/src/groups/skill.ts +46 -46
  46. package/src/groups/usage.ts +30 -30
  47. package/src/groups/vcs.ts +131 -131
  48. package/src/groups/voice.ts +96 -96
  49. package/src/groups/websearch.ts +46 -46
  50. package/src/groups/worktree.ts +78 -78
  51. package/src/middleware/authorization.ts +6 -6
  52. package/src/middleware/schema-error.ts +7 -7
  53. package/src/simulation.ts +691 -691
  54. package/tsconfig.build.json +11 -11
  55. package/tsconfig.json +14 -14
  56. package/test/event.test.ts +0 -34
  57. package/test/experimental-identifiers.test.ts +0 -24
  58. package/test/openapi-parameters.test.ts +0 -43
  59. package/test/openapi-patterns.test.ts +0 -28
  60. package/test/openapi-stabilize.test.ts +0 -161
  61. package/test/session-cursor.test.ts +0 -7
@@ -1,66 +1,66 @@
1
- import { Location } from "@zyro-sec/schema/location"
2
- import { Context, Schema } from "effect"
3
- import { HttpApiEndpoint, HttpApiGroup, HttpApiMiddleware, HttpApiSchema, OpenApi } from "effect/http-api"
4
- import { ServiceUnavailableError } from "../errors.js"
5
-
6
- export const LocationQuery = Schema.Struct({
7
- location: Schema.optional(
8
- Schema.Struct({
9
- directory: Schema.optional(Schema.String).annotate({ description: "Absolute path of the directory." }),
10
- }),
11
- ).annotateKey({
12
- description:
13
- "Location to run the request in, sent as location[directory]. Omit to use the server's default location.",
14
- }),
15
- }).annotate({ identifier: "LocationQuery" })
16
-
17
- export const locationQueryOpenApi = OpenApi.annotations({
18
- transform: (operation) => {
19
- const parameters = operation.parameters
20
- if (!Array.isArray(parameters)) return operation
21
- return {
22
- ...operation,
23
- parameters: parameters.map((parameter) =>
24
- parameter?.name === "location" && parameter?.in === "query"
25
- ? { ...parameter, style: "deepObject", explode: true }
26
- : parameter,
27
- ),
28
- }
29
- },
30
- })
31
-
32
- // Middleware is applied per endpoint: reload acts on every loaded location and
33
- // must not boot the caller's location first.
34
- export const makeLocationGroup = <LocationId extends HttpApiMiddleware.AnyId, LocationService>(
35
- locationMiddleware: Context.Key<LocationId, LocationService>,
36
- ) =>
37
- HttpApiGroup.make("server.location")
38
- .add(
39
- HttpApiEndpoint.get("location.get", "/api/location", {
40
- query: LocationQuery,
41
- success: Location.PublicInfo,
42
- })
43
- .middleware(locationMiddleware)
44
- .annotateMerge(locationQueryOpenApi)
45
- .annotateMerge(
46
- OpenApi.annotations({
47
- identifier: "location.get",
48
- summary: "Get location",
49
- description: "Resolve the requested location or the server default location.",
50
- }),
51
- ),
52
- )
53
- .add(
54
- HttpApiEndpoint.post("location.reload", "/api/location/reload", {
55
- success: HttpApiSchema.NoContent,
56
- error: ServiceUnavailableError,
57
- }).annotateMerge(
58
- OpenApi.annotations({
59
- identifier: "location.reload",
60
- summary: "Reload configuration",
61
- description:
62
- "Shut down and rebuild every loaded location. Pending permissions and forms are cancelled; running sessions continue with fresh services at the next step boundary. Emits location.shutdown for client recovery and responds once all replacement builds settle.",
63
- }),
64
- ),
65
- )
66
- .annotateMerge(OpenApi.annotations({ title: "location" }))
1
+ import { Location } from "@zyro-sec/schema/location"
2
+ import { Context, Schema } from "effect"
3
+ import { HttpApiEndpoint, HttpApiGroup, HttpApiMiddleware, HttpApiSchema, OpenApi } from "effect/http-api"
4
+ import { ServiceUnavailableError } from "../errors.js"
5
+
6
+ export const LocationQuery = Schema.Struct({
7
+ location: Schema.optional(
8
+ Schema.Struct({
9
+ directory: Schema.optional(Schema.String).annotate({ description: "Absolute path of the directory." }),
10
+ }),
11
+ ).annotateKey({
12
+ description:
13
+ "Location to run the request in, sent as location[directory]. Omit to use the server's default location.",
14
+ }),
15
+ }).annotate({ identifier: "LocationQuery" })
16
+
17
+ export const locationQueryOpenApi = OpenApi.annotations({
18
+ transform: (operation) => {
19
+ const parameters = operation.parameters
20
+ if (!Array.isArray(parameters)) return operation
21
+ return {
22
+ ...operation,
23
+ parameters: parameters.map((parameter) =>
24
+ parameter?.name === "location" && parameter?.in === "query"
25
+ ? { ...parameter, style: "deepObject", explode: true }
26
+ : parameter,
27
+ ),
28
+ }
29
+ },
30
+ })
31
+
32
+ // Middleware is applied per endpoint: reload acts on every loaded location and
33
+ // must not boot the caller's location first.
34
+ export const makeLocationGroup = <LocationId extends HttpApiMiddleware.AnyId, LocationService>(
35
+ locationMiddleware: Context.Key<LocationId, LocationService>,
36
+ ) =>
37
+ HttpApiGroup.make("server.location")
38
+ .add(
39
+ HttpApiEndpoint.get("location.get", "/api/location", {
40
+ query: LocationQuery,
41
+ success: Location.PublicInfo,
42
+ })
43
+ .middleware(locationMiddleware)
44
+ .annotateMerge(locationQueryOpenApi)
45
+ .annotateMerge(
46
+ OpenApi.annotations({
47
+ identifier: "location.get",
48
+ summary: "Get location",
49
+ description: "Resolve the requested location or the server default location.",
50
+ }),
51
+ ),
52
+ )
53
+ .add(
54
+ HttpApiEndpoint.post("location.reload", "/api/location/reload", {
55
+ success: HttpApiSchema.NoContent,
56
+ error: ServiceUnavailableError,
57
+ }).annotateMerge(
58
+ OpenApi.annotations({
59
+ identifier: "location.reload",
60
+ summary: "Reload configuration",
61
+ description:
62
+ "Shut down and rebuild every loaded location. Pending permissions and forms are cancelled; running sessions continue with fresh services at the next step boundary. Emits location.shutdown for client recovery and responds once all replacement builds settle.",
63
+ }),
64
+ ),
65
+ )
66
+ .annotateMerge(OpenApi.annotations({ title: "location" }))
@@ -1,120 +1,120 @@
1
- import { Schema } from "effect"
2
- import { HttpApiEndpoint, HttpApiSchema, OpenApi } from "effect/http-api"
3
- import { ConflictError, ForbiddenError, InvalidRequestError, MachineNotFoundError } from "../errors.js"
4
-
5
- export const MACHINE_LINK_PATH = "/api/experimental/machine/link"
6
-
7
- const EXPERIMENTAL = "Behind the machines flag. Experimental: may change without compatibility guarantees."
8
-
9
- const annotations = (identifier: string, summary: string, description: string) =>
10
- OpenApi.annotations({
11
- identifier: `experimental.machine.${identifier}`,
12
- summary,
13
- description: `${description} ${EXPERIMENTAL}`,
14
- transform: (operation) => ({ ...operation, tags: ["experimental"] }),
15
- })
16
-
17
- export const MachineInfo = Schema.Struct({
18
- id: Schema.String,
19
- online: Schema.Boolean,
20
- paired: Schema.Boolean,
21
- os: Schema.optionalKey(Schema.String),
22
- arch: Schema.optionalKey(Schema.String),
23
- connection: Schema.optionalKey(
24
- Schema.Struct({
25
- kind: Schema.Literals(["websocket", "iroh"]),
26
- path: Schema.optionalKey(Schema.Literals(["direct", "relayed"])),
27
- /** Round-trip time in milliseconds. */
28
- rtt: Schema.optionalKey(Schema.Number),
29
- }),
30
- ),
31
- }).annotate({ identifier: "Machine.Info" })
32
- export type MachineInfo = typeof MachineInfo.Type
33
-
34
- export const MachineReach = Schema.Struct({
35
- type: Schema.Literal("url"),
36
- url: Schema.String,
37
- }).annotate({ identifier: "Machine.Reach" })
38
- export type MachineReach = typeof MachineReach.Type
39
-
40
- export const MachineAddPayload = Schema.Struct({
41
- name: Schema.String,
42
- reach: Schema.Array(MachineReach),
43
- replace: Schema.optional(Schema.Boolean),
44
- }).annotate({ identifier: "Machine.AddPayload" })
45
- export type MachineAddPayload = typeof MachineAddPayload.Type
46
-
47
- export const MachineInvite = Schema.Struct({
48
- name: Schema.String,
49
- join: Schema.String,
50
- expires: Schema.Int,
51
- reach: Schema.Array(Schema.Union([MachineReach, Schema.Struct({ type: Schema.Literal("iroh") })])),
52
- }).annotate({ identifier: "Machine.Invite" })
53
- export type MachineInvite = typeof MachineInvite.Type
54
-
55
- /**
56
- * Whether a request asks to become a WebSocket, the one request the machine link serves and the one the server lets in
57
- * without its password: a GET with `Upgrade: websocket` and `upgrade` among its `Connection` tokens.
58
- */
59
- export function isWebSocketUpgrade(request: {
60
- readonly method: string
61
- readonly headers: Readonly<Record<string, string | undefined>>
62
- }) {
63
- return (
64
- request.method === "GET" &&
65
- request.headers.upgrade?.toLowerCase() === "websocket" &&
66
- (request.headers.connection ?? "").split(",").some((token) => token.trim().toLowerCase() === "upgrade")
67
- )
68
- }
69
-
70
- /**
71
- * The same, for code that runs before the router has matched a route: the path is the request's own, up to its query,
72
- * compared as it was sent. A URL parser would resolve `..` and a leading `//host` to this path, and the router would not.
73
- */
74
- export function isMachineLinkUpgrade(request: {
75
- readonly method: string
76
- readonly url: string
77
- readonly headers: Readonly<Record<string, string | undefined>>
78
- }) {
79
- return request.url.split("?", 1)[0] === MACHINE_LINK_PATH && isWebSocketUpgrade(request)
80
- }
81
-
82
- /** Lives in the `server.experimental` group (see `groups/experimental.ts`). */
83
- export const MachineLinkEndpoint = HttpApiEndpoint.get("machine.link", MACHINE_LINK_PATH, {
84
- success: Schema.Boolean,
85
- }).annotateMerge(
86
- OpenApi.annotations({
87
- identifier: "experimental.machine.link",
88
- summary: "Connect a machine",
89
- description:
90
- "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.",
91
- transform: (operation) => ({ ...operation, "x-websocket": true, tags: ["experimental"] }),
92
- }),
93
- )
94
-
95
- /** Lives in the `server.experimental` group (see `groups/experimental.ts`). */
96
- export const MachineEndpoints = [
97
- MachineLinkEndpoint,
98
- HttpApiEndpoint.get("machine.list", "/api/experimental/machine", {
99
- success: Schema.Struct({ data: Schema.Array(MachineInfo) }),
100
- error: [ForbiddenError],
101
- }).annotateMerge(annotations("list", "List machines", "List known machines and whether each is paired and online.")),
102
- HttpApiEndpoint.post("machine.add", "/api/experimental/machine", {
103
- payload: MachineAddPayload,
104
- success: Schema.Struct({ data: MachineInvite }),
105
- error: [InvalidRequestError, ForbiddenError, MachineNotFoundError, ConflictError],
106
- }).annotateMerge(
107
- annotations(
108
- "add",
109
- "Add or invite a machine",
110
- "Add a machine by name if it does not exist, then create a single-use join string carrying the given reach addresses.",
111
- ),
112
- ),
113
- HttpApiEndpoint.delete("machine.remove", "/api/experimental/machine/:name", {
114
- params: { name: Schema.String },
115
- success: HttpApiSchema.NoContent,
116
- error: [ForbiddenError, MachineNotFoundError],
117
- }).annotateMerge(
118
- annotations("remove", "Remove a machine", "Forget a machine by name, closing any live link and revoking its key."),
119
- ),
120
- ] as const
1
+ import { Schema } from "effect"
2
+ import { HttpApiEndpoint, HttpApiSchema, OpenApi } from "effect/http-api"
3
+ import { ConflictError, ForbiddenError, InvalidRequestError, MachineNotFoundError } from "../errors.js"
4
+
5
+ export const MACHINE_LINK_PATH = "/api/experimental/machine/link"
6
+
7
+ const EXPERIMENTAL = "Behind the machines flag. Experimental: may change without compatibility guarantees."
8
+
9
+ const annotations = (identifier: string, summary: string, description: string) =>
10
+ OpenApi.annotations({
11
+ identifier: `experimental.machine.${identifier}`,
12
+ summary,
13
+ description: `${description} ${EXPERIMENTAL}`,
14
+ transform: (operation) => ({ ...operation, tags: ["experimental"] }),
15
+ })
16
+
17
+ export const MachineInfo = Schema.Struct({
18
+ id: Schema.String,
19
+ online: Schema.Boolean,
20
+ paired: Schema.Boolean,
21
+ os: Schema.optionalKey(Schema.String),
22
+ arch: Schema.optionalKey(Schema.String),
23
+ connection: Schema.optionalKey(
24
+ Schema.Struct({
25
+ kind: Schema.Literals(["websocket", "iroh"]),
26
+ path: Schema.optionalKey(Schema.Literals(["direct", "relayed"])),
27
+ /** Round-trip time in milliseconds. */
28
+ rtt: Schema.optionalKey(Schema.Number),
29
+ }),
30
+ ),
31
+ }).annotate({ identifier: "Machine.Info" })
32
+ export type MachineInfo = typeof MachineInfo.Type
33
+
34
+ export const MachineReach = Schema.Struct({
35
+ type: Schema.Literal("url"),
36
+ url: Schema.String,
37
+ }).annotate({ identifier: "Machine.Reach" })
38
+ export type MachineReach = typeof MachineReach.Type
39
+
40
+ export const MachineAddPayload = Schema.Struct({
41
+ name: Schema.String,
42
+ reach: Schema.Array(MachineReach),
43
+ replace: Schema.optional(Schema.Boolean),
44
+ }).annotate({ identifier: "Machine.AddPayload" })
45
+ export type MachineAddPayload = typeof MachineAddPayload.Type
46
+
47
+ export const MachineInvite = Schema.Struct({
48
+ name: Schema.String,
49
+ join: Schema.String,
50
+ expires: Schema.Int,
51
+ reach: Schema.Array(Schema.Union([MachineReach, Schema.Struct({ type: Schema.Literal("iroh") })])),
52
+ }).annotate({ identifier: "Machine.Invite" })
53
+ export type MachineInvite = typeof MachineInvite.Type
54
+
55
+ /**
56
+ * Whether a request asks to become a WebSocket, the one request the machine link serves and the one the server lets in
57
+ * without its password: a GET with `Upgrade: websocket` and `upgrade` among its `Connection` tokens.
58
+ */
59
+ export function isWebSocketUpgrade(request: {
60
+ readonly method: string
61
+ readonly headers: Readonly<Record<string, string | undefined>>
62
+ }) {
63
+ return (
64
+ request.method === "GET" &&
65
+ request.headers.upgrade?.toLowerCase() === "websocket" &&
66
+ (request.headers.connection ?? "").split(",").some((token) => token.trim().toLowerCase() === "upgrade")
67
+ )
68
+ }
69
+
70
+ /**
71
+ * The same, for code that runs before the router has matched a route: the path is the request's own, up to its query,
72
+ * compared as it was sent. A URL parser would resolve `..` and a leading `//host` to this path, and the router would not.
73
+ */
74
+ export function isMachineLinkUpgrade(request: {
75
+ readonly method: string
76
+ readonly url: string
77
+ readonly headers: Readonly<Record<string, string | undefined>>
78
+ }) {
79
+ return request.url.split("?", 1)[0] === MACHINE_LINK_PATH && isWebSocketUpgrade(request)
80
+ }
81
+
82
+ /** Lives in the `server.experimental` group (see `groups/experimental.ts`). */
83
+ export const MachineLinkEndpoint = HttpApiEndpoint.get("machine.link", MACHINE_LINK_PATH, {
84
+ success: Schema.Boolean,
85
+ }).annotateMerge(
86
+ OpenApi.annotations({
87
+ identifier: "experimental.machine.link",
88
+ summary: "Connect a machine",
89
+ description:
90
+ "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.",
91
+ transform: (operation) => ({ ...operation, "x-websocket": true, tags: ["experimental"] }),
92
+ }),
93
+ )
94
+
95
+ /** Lives in the `server.experimental` group (see `groups/experimental.ts`). */
96
+ export const MachineEndpoints = [
97
+ MachineLinkEndpoint,
98
+ HttpApiEndpoint.get("machine.list", "/api/experimental/machine", {
99
+ success: Schema.Struct({ data: Schema.Array(MachineInfo) }),
100
+ error: [ForbiddenError],
101
+ }).annotateMerge(annotations("list", "List machines", "List known machines and whether each is paired and online.")),
102
+ HttpApiEndpoint.post("machine.add", "/api/experimental/machine", {
103
+ payload: MachineAddPayload,
104
+ success: Schema.Struct({ data: MachineInvite }),
105
+ error: [InvalidRequestError, ForbiddenError, MachineNotFoundError, ConflictError],
106
+ }).annotateMerge(
107
+ annotations(
108
+ "add",
109
+ "Add or invite a machine",
110
+ "Add a machine by name if it does not exist, then create a single-use join string carrying the given reach addresses.",
111
+ ),
112
+ ),
113
+ HttpApiEndpoint.delete("machine.remove", "/api/experimental/machine/:name", {
114
+ params: { name: Schema.String },
115
+ success: HttpApiSchema.NoContent,
116
+ error: [ForbiddenError, MachineNotFoundError],
117
+ }).annotateMerge(
118
+ annotations("remove", "Remove a machine", "Forget a machine by name, closing any live link and revoking its key."),
119
+ ),
120
+ ] as const