@zyro-sec/protocol 0.0.0-stage → 1.0.1

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 (62) hide show
  1. package/openapi.json +33222 -0
  2. package/package.json +33 -4
  3. package/script/build.ts +9 -0
  4. package/script/generate-openapi.ts +25 -0
  5. package/script/openapi-parameters.ts +30 -0
  6. package/script/openapi-stabilize.ts +102 -0
  7. package/script/pack.ts +5 -0
  8. package/src/api.ts +264 -0
  9. package/src/client.ts +127 -0
  10. package/src/errors.ts +398 -0
  11. package/src/groups/agent.ts +39 -0
  12. package/src/groups/artifact.ts +103 -0
  13. package/src/groups/automation.ts +75 -0
  14. package/src/groups/blob.ts +20 -0
  15. package/src/groups/command.ts +27 -0
  16. package/src/groups/config.ts +46 -0
  17. package/src/groups/credential.ts +72 -0
  18. package/src/groups/debug.ts +68 -0
  19. package/src/groups/event.ts +86 -0
  20. package/src/groups/experimental.ts +19 -0
  21. package/src/groups/form.ts +26 -0
  22. package/src/groups/fs.ts +136 -0
  23. package/src/groups/generate.ts +120 -0
  24. package/src/groups/integration.ts +230 -0
  25. package/src/groups/job.ts +57 -0
  26. package/src/groups/location.ts +66 -0
  27. package/src/groups/machine.ts +120 -0
  28. package/src/groups/mcp.ts +167 -0
  29. package/src/groups/media.ts +23 -0
  30. package/src/groups/message.ts +124 -0
  31. package/src/groups/migration.ts +28 -0
  32. package/src/groups/model.ts +52 -0
  33. package/src/groups/permission.ts +164 -0
  34. package/src/groups/persistent-pty.ts +153 -0
  35. package/src/groups/plugin.ts +80 -0
  36. package/src/groups/project.ts +51 -0
  37. package/src/groups/provider.ts +45 -0
  38. package/src/groups/pty.ts +153 -0
  39. package/src/groups/push.ts +94 -0
  40. package/src/groups/reference.ts +42 -0
  41. package/src/groups/rpc.ts +30 -0
  42. package/src/groups/server.ts +80 -0
  43. package/src/groups/session.ts +918 -0
  44. package/src/groups/shell.ts +88 -0
  45. package/src/groups/skill.ts +46 -0
  46. package/src/groups/usage.ts +30 -0
  47. package/src/groups/vcs.ts +131 -0
  48. package/src/groups/voice.ts +96 -0
  49. package/src/groups/websearch.ts +46 -0
  50. package/src/groups/worktree.ts +78 -0
  51. package/src/middleware/authorization.ts +6 -0
  52. package/src/middleware/schema-error.ts +7 -0
  53. package/src/simulation.ts +691 -0
  54. package/test/event.test.ts +34 -0
  55. package/test/experimental-identifiers.test.ts +24 -0
  56. package/test/openapi-parameters.test.ts +43 -0
  57. package/test/openapi-patterns.test.ts +28 -0
  58. package/test/openapi-stabilize.test.ts +161 -0
  59. package/test/session-cursor.test.ts +7 -0
  60. package/tsconfig.build.json +11 -0
  61. package/tsconfig.json +14 -0
  62. package/README.md +0 -3
@@ -0,0 +1,45 @@
1
+ import { Provider } from "@zyro-sec/schema/provider"
2
+ import { Location } from "@zyro-sec/schema/location"
3
+ import { Schema } from "effect"
4
+ import { HttpApiEndpoint, HttpApiGroup, OpenApi } from "effect/http-api"
5
+ import { ProviderNotFoundError, ServiceUnavailableError } from "../errors.js"
6
+ import { LocationQuery, locationQueryOpenApi } from "./location.js"
7
+
8
+ export const ProviderGroup = HttpApiGroup.make("server.provider")
9
+ .add(
10
+ HttpApiEndpoint.get("provider.list", "/api/provider", {
11
+ query: LocationQuery,
12
+ success: Location.response(Schema.Array(Provider.Info)),
13
+ error: ServiceUnavailableError,
14
+ })
15
+ .annotateMerge(locationQueryOpenApi)
16
+ .annotateMerge(
17
+ OpenApi.annotations({
18
+ identifier: "provider.list",
19
+ summary: "List providers",
20
+ description: "Retrieve active AI providers so clients can show provider availability and configuration.",
21
+ }),
22
+ ),
23
+ )
24
+ .add(
25
+ HttpApiEndpoint.get("provider.get", "/api/provider/:providerID", {
26
+ params: { providerID: Provider.ID },
27
+ query: LocationQuery,
28
+ success: Location.response(Provider.Info),
29
+ error: [ProviderNotFoundError, ServiceUnavailableError],
30
+ })
31
+ .annotateMerge(locationQueryOpenApi)
32
+ .annotateMerge(
33
+ OpenApi.annotations({
34
+ identifier: "provider.get",
35
+ summary: "Get provider",
36
+ description: "Retrieve a single AI provider so clients can inspect its availability and endpoint settings.",
37
+ }),
38
+ ),
39
+ )
40
+ .annotateMerge(
41
+ OpenApi.annotations({
42
+ title: "provider",
43
+ description: "Experimental provider routes.",
44
+ }),
45
+ )
@@ -0,0 +1,153 @@
1
+ import { Pty } from "@zyro-sec/schema/pty"
2
+ import { PtyTicket } from "@zyro-sec/schema/pty-ticket"
3
+ import { Location } from "@zyro-sec/schema/location"
4
+ import { Context, Schema } from "effect"
5
+ import { HttpApiEndpoint, HttpApiGroup, HttpApiMiddleware, HttpApiSchema, OpenApi } from "effect/http-api"
6
+ import { ForbiddenError, LocationNotFoundError, PtyNotFoundError } from "../errors.js"
7
+ import { LocationQuery, locationQueryOpenApi } from "./location.js"
8
+
9
+ export const PTY_CONNECT_TICKET_QUERY = "ticket"
10
+ export const PTY_CONNECT_TOKEN_HEADER = "x-opencode-ticket"
11
+ export const PTY_CONNECT_TOKEN_HEADER_VALUE = "1"
12
+ export const PTY_CONNECT_PATH = "/api/pty/:ptyID/connect"
13
+
14
+ const PTY_CONNECT_URL = /^\/api\/pty\/[^/]+\/connect$/
15
+
16
+ export function hasPtyConnectTicketURL(url: URL) {
17
+ return PTY_CONNECT_URL.test(url.pathname) && !!url.searchParams.get(PTY_CONNECT_TICKET_QUERY)
18
+ }
19
+
20
+ export const makePtyGroup = <LocationId extends HttpApiMiddleware.AnyId, LocationService>(
21
+ locationMiddleware: Context.Key<LocationId, LocationService>,
22
+ ) =>
23
+ HttpApiGroup.make("server.pty")
24
+ .add(
25
+ HttpApiEndpoint.get("pty.list", "/api/pty", {
26
+ query: LocationQuery,
27
+ success: Location.response(Schema.Array(Pty.Info)),
28
+ })
29
+ .annotateMerge(locationQueryOpenApi)
30
+ .annotateMerge(
31
+ OpenApi.annotations({
32
+ identifier: "pty.list",
33
+ summary: "List PTY sessions",
34
+ description: "List PTY sessions for a location, including exited sessions retained until removal.",
35
+ }),
36
+ ),
37
+ )
38
+ .add(
39
+ HttpApiEndpoint.post("pty.create", "/api/pty", {
40
+ query: LocationQuery,
41
+ payload: Pty.CreateInput,
42
+ success: Location.response(Pty.Info),
43
+ })
44
+ .annotateMerge(locationQueryOpenApi)
45
+ .annotateMerge(
46
+ OpenApi.annotations({
47
+ identifier: "pty.create",
48
+ summary: "Create PTY session",
49
+ description: "Create a pseudo-terminal session for a location.",
50
+ }),
51
+ ),
52
+ )
53
+ .add(
54
+ HttpApiEndpoint.get("pty.get", "/api/pty/:ptyID", {
55
+ params: { ptyID: Pty.ID },
56
+ query: LocationQuery,
57
+ success: Location.response(Pty.Info),
58
+ error: PtyNotFoundError,
59
+ })
60
+ .annotateMerge(locationQueryOpenApi)
61
+ .annotateMerge(
62
+ OpenApi.annotations({
63
+ identifier: "pty.get",
64
+ summary: "Get PTY session",
65
+ description: "Get one PTY session, including its exit code once exited.",
66
+ }),
67
+ ),
68
+ )
69
+ .add(
70
+ HttpApiEndpoint.put("pty.update", "/api/pty/:ptyID", {
71
+ params: { ptyID: Pty.ID },
72
+ query: LocationQuery,
73
+ payload: Pty.UpdateInput,
74
+ success: Location.response(Pty.Info),
75
+ error: PtyNotFoundError,
76
+ })
77
+ .annotateMerge(locationQueryOpenApi)
78
+ .annotateMerge(
79
+ OpenApi.annotations({
80
+ identifier: "pty.update",
81
+ summary: "Update PTY session",
82
+ description: "Update the title or viewport size of one PTY session.",
83
+ }),
84
+ ),
85
+ )
86
+ .add(
87
+ HttpApiEndpoint.delete("pty.remove", "/api/pty/:ptyID", {
88
+ params: { ptyID: Pty.ID },
89
+ query: LocationQuery,
90
+ success: HttpApiSchema.NoContent,
91
+ error: PtyNotFoundError,
92
+ })
93
+ .annotateMerge(locationQueryOpenApi)
94
+ .annotateMerge(
95
+ OpenApi.annotations({
96
+ identifier: "pty.remove",
97
+ summary: "Remove PTY session",
98
+ description: "Terminate and remove one PTY session.",
99
+ }),
100
+ ),
101
+ )
102
+ .add(
103
+ HttpApiEndpoint.post("pty.connectToken", "/api/pty/:ptyID/connect-token", {
104
+ params: { ptyID: Pty.ID },
105
+ query: LocationQuery,
106
+ headers: Schema.Struct({
107
+ [PTY_CONNECT_TOKEN_HEADER]: Schema.optional(Schema.String).annotateKey({
108
+ description: `Must be ${PTY_CONNECT_TOKEN_HEADER_VALUE}; requests without it are refused.`,
109
+ }),
110
+ }),
111
+ success: Location.response(PtyTicket.ConnectToken),
112
+ error: [ForbiddenError, PtyNotFoundError],
113
+ })
114
+ .annotateMerge(locationQueryOpenApi)
115
+ .annotateMerge(
116
+ OpenApi.annotations({
117
+ identifier: "pty.connect.token",
118
+ summary: "Create PTY WebSocket token",
119
+ description: "Create a short-lived single-use ticket for opening a PTY WebSocket connection.",
120
+ }),
121
+ ),
122
+ )
123
+ .middleware(locationMiddleware)
124
+ .add(
125
+ // Query fields are decoded in the raw handler before upgrade work.
126
+ HttpApiEndpoint.get("pty.connect", PTY_CONNECT_PATH, {
127
+ params: { ptyID: Pty.ID },
128
+ success: Schema.Boolean,
129
+ error: [ForbiddenError, PtyNotFoundError, LocationNotFoundError],
130
+ }).annotateMerge(
131
+ OpenApi.annotations({
132
+ identifier: "pty.connect",
133
+ summary: "Connect to PTY session",
134
+ description: "Establish a WebSocket connection streaming PTY output and accepting terminal input.",
135
+ transform: (operation) => ({
136
+ ...operation,
137
+ "x-websocket": true,
138
+ parameters: [
139
+ ...(operation.parameters ?? []),
140
+ ...Object.entries({
141
+ "location[directory]":
142
+ "Absolute path of the location directory. Omit to use the server's default location.",
143
+ cursor:
144
+ "Output offset to replay from. Use -1 to start at the current end; omit to replay all retained output.",
145
+ [PTY_CONNECT_TICKET_QUERY]:
146
+ "Single-use ticket from pty.connect.token, which authorizes the connection without the usual credentials.",
147
+ }).map(([name, description]) => ({ in: "query", name, description, schema: { type: "string" } })),
148
+ ],
149
+ }),
150
+ }),
151
+ ),
152
+ )
153
+ .annotateMerge(OpenApi.annotations({ title: "pty", description: "Experimental location-scoped PTY routes." }))
@@ -0,0 +1,94 @@
1
+ import { Push } from "@zyro-sec/schema/push"
2
+ import { Session } from "@zyro-sec/schema/session"
3
+ import { Schema } from "effect"
4
+ import { HttpApiEndpoint, HttpApiSchema, OpenApi } from "effect/http-api"
5
+ import { InvalidRequestError, PushDeviceNotFoundError } from "../errors.js"
6
+
7
+ const EXPERIMENTAL = "Experimental: may change without compatibility guarantees."
8
+
9
+ const annotations = (identifier: string, summary: string, description: string) =>
10
+ OpenApi.annotations({
11
+ identifier: `experimental.push.${identifier}`,
12
+ summary,
13
+ description: `${description} ${EXPERIMENTAL}`,
14
+ transform: (operation) => ({ ...operation, tags: ["experimental"] }),
15
+ })
16
+
17
+ /** Lives in the `server.experimental` group (see `groups/experimental.ts`). */
18
+ export const PushEndpoints = [
19
+ HttpApiEndpoint.get("push.get", "/api/experimental/push", {
20
+ success: Schema.Struct({ data: Push.Info }),
21
+ }).annotateMerge(
22
+ annotations(
23
+ "get",
24
+ "Get push settings",
25
+ "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.",
26
+ ),
27
+ ),
28
+ HttpApiEndpoint.put("push.device.register", "/api/experimental/push/device/:deviceID", {
29
+ params: { deviceID: Push.DeviceID },
30
+ payload: Push.Register,
31
+ success: Schema.Struct({ data: Push.Registered }),
32
+ error: [InvalidRequestError],
33
+ }).annotateMerge(
34
+ annotations(
35
+ "device.register",
36
+ "Register a phone",
37
+ "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.",
38
+ ),
39
+ ),
40
+ HttpApiEndpoint.delete("push.device.remove", "/api/experimental/push/device/:deviceID", {
41
+ params: { deviceID: Push.DeviceID },
42
+ success: HttpApiSchema.NoContent,
43
+ }).annotateMerge(annotations("device.remove", "Remove a phone", "Stop sending notifications to a phone.")),
44
+ HttpApiEndpoint.patch("push.device.update", "/api/experimental/push/device/:deviceID", {
45
+ params: { deviceID: Push.DeviceID },
46
+ payload: Push.DevicePatch,
47
+ success: Schema.Struct({ data: Push.Device }),
48
+ error: [PushDeviceNotFoundError],
49
+ }).annotateMerge(
50
+ annotations(
51
+ "device.update",
52
+ "Update a phone",
53
+ "Pause or resume notifications to one phone, or change the level it gets by default.",
54
+ ),
55
+ ),
56
+ HttpApiEndpoint.put("push.device.session.set", "/api/experimental/push/device/:deviceID/session/:sessionID", {
57
+ params: { deviceID: Push.DeviceID, sessionID: Session.ID },
58
+ payload: Push.Bell,
59
+ success: Schema.Struct({ data: Push.Bell }),
60
+ error: [InvalidRequestError, PushDeviceNotFoundError],
61
+ }).annotateMerge(
62
+ annotations("device.session.set", "Set a phone's session bell", "Choose what one phone gets for one session."),
63
+ ),
64
+ HttpApiEndpoint.delete("push.device.session.remove", "/api/experimental/push/device/:deviceID/session/:sessionID", {
65
+ params: { deviceID: Push.DeviceID, sessionID: Session.ID },
66
+ success: HttpApiSchema.NoContent,
67
+ error: [PushDeviceNotFoundError],
68
+ }).annotateMerge(
69
+ annotations(
70
+ "device.session.remove",
71
+ "Clear a phone's session bell",
72
+ "Let one phone follow the shared bell or its default for one session again.",
73
+ ),
74
+ ),
75
+ HttpApiEndpoint.put("push.session.set", "/api/experimental/push/session/:sessionID", {
76
+ params: { sessionID: Session.ID },
77
+ payload: Push.Bell,
78
+ success: Schema.Struct({ data: Push.Bell }),
79
+ error: [InvalidRequestError],
80
+ }).annotateMerge(annotations("session.set", "Set a session bell", "Choose what every phone gets for one session.")),
81
+ HttpApiEndpoint.delete("push.session.remove", "/api/experimental/push/session/:sessionID", {
82
+ params: { sessionID: Session.ID },
83
+ success: HttpApiSchema.NoContent,
84
+ }).annotateMerge(
85
+ annotations("session.remove", "Clear a session bell", "Let every phone follow its default for one session again."),
86
+ ),
87
+ HttpApiEndpoint.put("push.settings.set", "/api/experimental/push/settings", {
88
+ payload: Push.Settings,
89
+ success: Schema.Struct({ data: Push.Settings }),
90
+ error: [InvalidRequestError],
91
+ }).annotateMerge(
92
+ annotations("settings.set", "Pause all notifications", "Pause or resume notifications to every phone."),
93
+ ),
94
+ ] as const
@@ -0,0 +1,42 @@
1
+ import { Location } from "@zyro-sec/schema/location"
2
+ import { Reference } from "@zyro-sec/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
+
7
+ const PublicLocalSource = Schema.Struct(Struct.omit(Reference.LocalSource.fields, ["description", "hidden"])).annotate({
8
+ identifier: "Reference.LocalSource",
9
+ })
10
+ const PublicGitSource = Schema.Struct(Struct.omit(Reference.GitSource.fields, ["description", "hidden"])).annotate({
11
+ identifier: "Reference.GitSource",
12
+ })
13
+ const PublicSource = Schema.Union([PublicLocalSource, PublicGitSource])
14
+ .pipe(Schema.toTaggedUnion("type"))
15
+ .annotate({ identifier: "Reference.Source" })
16
+
17
+ const PublicInfo = Schema.Struct({
18
+ ...Struct.omit(Reference.Info.fields, ["source"]),
19
+ source: PublicSource,
20
+ }).annotate({ identifier: "Reference.Info" })
21
+
22
+ export const ReferenceGroup = HttpApiGroup.make("server.reference")
23
+ .add(
24
+ HttpApiEndpoint.get("reference.list", "/api/reference", {
25
+ query: LocationQuery,
26
+ success: Location.response(Schema.Array(PublicInfo)),
27
+ })
28
+ .annotateMerge(locationQueryOpenApi)
29
+ .annotateMerge(
30
+ OpenApi.annotations({
31
+ identifier: "reference.list",
32
+ summary: "List references",
33
+ description: "List references available in the requested location.",
34
+ }),
35
+ ),
36
+ )
37
+ .annotateMerge(
38
+ OpenApi.annotations({
39
+ title: "reference",
40
+ description: "Location-scoped project references.",
41
+ }),
42
+ )
@@ -0,0 +1,30 @@
1
+ import { optional } from "@zyro-sec/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
+
7
+ export const RpcInput = Schema.Struct({ input: optional(Schema.Unknown) }).annotate({ identifier: "Rpc.Input" })
8
+ export const RpcOutput = Schema.Struct({ output: Schema.optionalKey(Schema.Unknown) }).annotate({
9
+ identifier: "Rpc.Output",
10
+ })
11
+
12
+ export const RpcGroup = HttpApiGroup.make("server.rpc")
13
+ .add(
14
+ HttpApiEndpoint.post("rpc.call", "/api/rpc/:rpcID/:method", {
15
+ params: { rpcID: Schema.String, method: Schema.String },
16
+ query: LocationQuery,
17
+ payload: RpcInput,
18
+ success: RpcOutput,
19
+ error: [RpcError, RpcInternalError],
20
+ })
21
+ .annotateMerge(locationQueryOpenApi)
22
+ .annotateMerge(
23
+ OpenApi.annotations({
24
+ identifier: "rpc.call",
25
+ summary: "Call a plugin RPC",
26
+ description: "Dispatch a method to the currently registered RPC at the requested location.",
27
+ }),
28
+ ),
29
+ )
30
+ .annotateMerge(OpenApi.annotations({ title: "rpc", description: "Plugin RPC routes." }))
@@ -0,0 +1,80 @@
1
+ import { Schema } from "effect"
2
+ import { HttpApiEndpoint, HttpApiGroup, OpenApi } from "effect/http-api"
3
+ import { UnauthorizedError } from "../errors.js"
4
+
5
+ export const ServerInfo = Schema.Struct({
6
+ version: Schema.String,
7
+ // 0 means the runtime has no OS process identity (e.g. workerd).
8
+ pid: Schema.Int.check(Schema.isGreaterThanOrEqualTo(0)),
9
+ // The machine's name, absent where the runtime has none (e.g. workerd).
10
+ hostname: Schema.optional(Schema.String),
11
+ urls: Schema.Array(Schema.String),
12
+ paths: Schema.Struct({
13
+ tmp: Schema.String,
14
+ }),
15
+ // Optional at every level so clients still decode servers that predate a capability.
16
+ capabilities: Schema.optional(
17
+ Schema.Struct({
18
+ persistentPty: Schema.optional(Schema.Boolean),
19
+ }),
20
+ ),
21
+ }).annotate({ identifier: "ServerInfo" })
22
+ export type ServerInfo = typeof ServerInfo.Type
23
+
24
+ export const PairingCode = Schema.Struct({
25
+ code: Schema.String,
26
+ expires_in: Schema.Int,
27
+ }).annotate({ identifier: "PairingCode" })
28
+ export type PairingCode = typeof PairingCode.Type
29
+
30
+ export const PairingSession = Schema.Struct({
31
+ token: Schema.String,
32
+ }).annotate({ identifier: "PairingSession" })
33
+ export type PairingSession = typeof PairingSession.Type
34
+
35
+ export const PAIRING_CONNECT_PATH = "/auth/connect/:code"
36
+
37
+ const PAIRING_CONNECT_URL = /^\/auth\/connect\/[^/]+$/
38
+
39
+ export function isPairingConnectURL(url: URL) {
40
+ return PAIRING_CONNECT_URL.test(url.pathname)
41
+ }
42
+
43
+ export const ServerGroup = HttpApiGroup.make("server.server")
44
+ .add(
45
+ HttpApiEndpoint.get("server.info", "/api/info", {
46
+ success: ServerInfo,
47
+ }).annotateMerge(
48
+ OpenApi.annotations({
49
+ identifier: "server.info",
50
+ summary: "Get server info",
51
+ description: "Return the server identity, connection URLs, paths, and readiness status.",
52
+ }),
53
+ ),
54
+ )
55
+ .add(
56
+ HttpApiEndpoint.post("server.pair", "/api/pair", {
57
+ success: PairingCode,
58
+ }).annotateMerge(
59
+ OpenApi.annotations({
60
+ identifier: "server.pair",
61
+ summary: "Create pairing code",
62
+ description: "Create a short-lived, single-use code for a /auth/connect/:code pairing link.",
63
+ }),
64
+ ),
65
+ )
66
+ .add(
67
+ HttpApiEndpoint.get("server.connect", PAIRING_CONNECT_PATH, {
68
+ params: { code: Schema.String },
69
+ success: PairingSession,
70
+ error: UnauthorizedError,
71
+ }).annotateMerge(
72
+ OpenApi.annotations({
73
+ identifier: "server.connect",
74
+ summary: "Redeem pairing code",
75
+ description:
76
+ "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.",
77
+ }),
78
+ ),
79
+ )
80
+ .annotateMerge(OpenApi.annotations({ title: "server" }))