@zyro-sec/protocol 1.0.2 → 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.
- package/openapi.json +33222 -33222
- package/package.json +2 -2
- package/script/build.ts +9 -9
- package/script/generate-openapi.ts +25 -25
- package/script/openapi-parameters.ts +30 -30
- package/script/openapi-stabilize.ts +102 -102
- package/script/pack.ts +5 -5
- package/src/api.ts +264 -264
- package/src/client.ts +127 -127
- package/src/errors.ts +398 -398
- package/src/groups/agent.ts +39 -39
- package/src/groups/artifact.ts +103 -103
- package/src/groups/automation.ts +75 -75
- package/src/groups/blob.ts +20 -20
- package/src/groups/command.ts +27 -27
- package/src/groups/config.ts +46 -46
- package/src/groups/credential.ts +72 -72
- package/src/groups/debug.ts +68 -68
- package/src/groups/event.ts +86 -86
- package/src/groups/experimental.ts +19 -19
- package/src/groups/form.ts +26 -26
- package/src/groups/fs.ts +136 -136
- package/src/groups/generate.ts +120 -120
- package/src/groups/integration.ts +230 -230
- package/src/groups/job.ts +57 -57
- package/src/groups/location.ts +66 -66
- package/src/groups/machine.ts +120 -120
- package/src/groups/mcp.ts +167 -167
- package/src/groups/media.ts +23 -23
- package/src/groups/message.ts +124 -124
- package/src/groups/migration.ts +28 -28
- package/src/groups/model.ts +52 -52
- package/src/groups/permission.ts +164 -164
- package/src/groups/persistent-pty.ts +153 -153
- package/src/groups/plugin.ts +80 -80
- package/src/groups/project.ts +51 -51
- package/src/groups/provider.ts +45 -45
- package/src/groups/pty.ts +153 -153
- package/src/groups/push.ts +94 -94
- package/src/groups/reference.ts +42 -42
- package/src/groups/rpc.ts +30 -30
- package/src/groups/server.ts +80 -80
- package/src/groups/session.ts +918 -918
- package/src/groups/shell.ts +88 -88
- package/src/groups/skill.ts +46 -46
- package/src/groups/usage.ts +30 -30
- package/src/groups/vcs.ts +131 -131
- package/src/groups/voice.ts +96 -96
- package/src/groups/websearch.ts +46 -46
- package/src/groups/worktree.ts +78 -78
- package/src/middleware/authorization.ts +6 -6
- package/src/middleware/schema-error.ts +7 -7
- package/src/simulation.ts +691 -691
- package/tsconfig.build.json +11 -11
- package/tsconfig.json +14 -14
- package/test/event.test.ts +0 -34
- package/test/experimental-identifiers.test.ts +0 -24
- package/test/openapi-parameters.test.ts +0 -43
- package/test/openapi-patterns.test.ts +0 -28
- package/test/openapi-stabilize.test.ts +0 -161
- package/test/session-cursor.test.ts +0 -7
package/src/groups/credential.ts
CHANGED
|
@@ -1,72 +1,72 @@
|
|
|
1
|
-
import { Credential } from "@zyro-sec/schema/credential"
|
|
2
|
-
import { Schema } from "effect"
|
|
3
|
-
import { HttpApiEndpoint, HttpApiGroup, HttpApiSchema, OpenApi } from "effect/http-api"
|
|
4
|
-
import { ConflictError, InvalidRequestError } from "../errors.js"
|
|
5
|
-
|
|
6
|
-
export const CredentialGroup = HttpApiGroup.make("server.credential")
|
|
7
|
-
.add(
|
|
8
|
-
HttpApiEndpoint.get("credential.list", "/api/credential", {
|
|
9
|
-
success: Schema.Struct({ data: Schema.Array(Credential.Entry) }),
|
|
10
|
-
}).annotateMerge(
|
|
11
|
-
OpenApi.annotations({
|
|
12
|
-
identifier: "credential.list",
|
|
13
|
-
summary: "List credentials",
|
|
14
|
-
description: "List every stored integration credential, including its secret value.",
|
|
15
|
-
}),
|
|
16
|
-
),
|
|
17
|
-
)
|
|
18
|
-
.add(
|
|
19
|
-
HttpApiEndpoint.post("credential.create", "/api/credential", {
|
|
20
|
-
payload: Credential.CreateInput,
|
|
21
|
-
success: Schema.Struct({ data: Credential.Entry }),
|
|
22
|
-
error: [ConflictError, InvalidRequestError],
|
|
23
|
-
}).annotateMerge(
|
|
24
|
-
OpenApi.annotations({
|
|
25
|
-
identifier: "credential.create",
|
|
26
|
-
summary: "Create credential",
|
|
27
|
-
description:
|
|
28
|
-
"Store an integration credential. It becomes the integration's active credential unless activate is false and the integration already has one. Fails with a conflict when the requested ID already exists, and with an invalid request when an `integration.connect` policy denies the integration.",
|
|
29
|
-
}),
|
|
30
|
-
),
|
|
31
|
-
)
|
|
32
|
-
.add(
|
|
33
|
-
HttpApiEndpoint.patch("credential.update", "/api/credential/:credentialID", {
|
|
34
|
-
params: { credentialID: Credential.ID },
|
|
35
|
-
payload: Schema.Struct({ label: Schema.String }),
|
|
36
|
-
success: HttpApiSchema.NoContent,
|
|
37
|
-
})
|
|
38
|
-
.annotateMerge(
|
|
39
|
-
OpenApi.annotations({
|
|
40
|
-
identifier: "credential.update",
|
|
41
|
-
summary: "Update credential",
|
|
42
|
-
description: "Update a stored credential label.",
|
|
43
|
-
}),
|
|
44
|
-
),
|
|
45
|
-
)
|
|
46
|
-
.annotateMerge(OpenApi.annotations({ title: "credential" }))
|
|
47
|
-
.add(
|
|
48
|
-
HttpApiEndpoint.post("credential.activate", "/api/credential/:credentialID/activate", {
|
|
49
|
-
params: { credentialID: Credential.ID },
|
|
50
|
-
success: HttpApiSchema.NoContent,
|
|
51
|
-
})
|
|
52
|
-
.annotateMerge(
|
|
53
|
-
OpenApi.annotations({
|
|
54
|
-
identifier: "credential.activate",
|
|
55
|
-
summary: "Activate credential",
|
|
56
|
-
description: "Activate a stored integration credential.",
|
|
57
|
-
}),
|
|
58
|
-
),
|
|
59
|
-
)
|
|
60
|
-
.add(
|
|
61
|
-
HttpApiEndpoint.delete("credential.remove", "/api/credential/:credentialID", {
|
|
62
|
-
params: { credentialID: Credential.ID },
|
|
63
|
-
success: HttpApiSchema.NoContent,
|
|
64
|
-
})
|
|
65
|
-
.annotateMerge(
|
|
66
|
-
OpenApi.annotations({
|
|
67
|
-
identifier: "credential.remove",
|
|
68
|
-
summary: "Remove credential",
|
|
69
|
-
description: "Remove a stored integration credential.",
|
|
70
|
-
}),
|
|
71
|
-
),
|
|
72
|
-
)
|
|
1
|
+
import { Credential } from "@zyro-sec/schema/credential"
|
|
2
|
+
import { Schema } from "effect"
|
|
3
|
+
import { HttpApiEndpoint, HttpApiGroup, HttpApiSchema, OpenApi } from "effect/http-api"
|
|
4
|
+
import { ConflictError, InvalidRequestError } from "../errors.js"
|
|
5
|
+
|
|
6
|
+
export const CredentialGroup = HttpApiGroup.make("server.credential")
|
|
7
|
+
.add(
|
|
8
|
+
HttpApiEndpoint.get("credential.list", "/api/credential", {
|
|
9
|
+
success: Schema.Struct({ data: Schema.Array(Credential.Entry) }),
|
|
10
|
+
}).annotateMerge(
|
|
11
|
+
OpenApi.annotations({
|
|
12
|
+
identifier: "credential.list",
|
|
13
|
+
summary: "List credentials",
|
|
14
|
+
description: "List every stored integration credential, including its secret value.",
|
|
15
|
+
}),
|
|
16
|
+
),
|
|
17
|
+
)
|
|
18
|
+
.add(
|
|
19
|
+
HttpApiEndpoint.post("credential.create", "/api/credential", {
|
|
20
|
+
payload: Credential.CreateInput,
|
|
21
|
+
success: Schema.Struct({ data: Credential.Entry }),
|
|
22
|
+
error: [ConflictError, InvalidRequestError],
|
|
23
|
+
}).annotateMerge(
|
|
24
|
+
OpenApi.annotations({
|
|
25
|
+
identifier: "credential.create",
|
|
26
|
+
summary: "Create credential",
|
|
27
|
+
description:
|
|
28
|
+
"Store an integration credential. It becomes the integration's active credential unless activate is false and the integration already has one. Fails with a conflict when the requested ID already exists, and with an invalid request when an `integration.connect` policy denies the integration.",
|
|
29
|
+
}),
|
|
30
|
+
),
|
|
31
|
+
)
|
|
32
|
+
.add(
|
|
33
|
+
HttpApiEndpoint.patch("credential.update", "/api/credential/:credentialID", {
|
|
34
|
+
params: { credentialID: Credential.ID },
|
|
35
|
+
payload: Schema.Struct({ label: Schema.String }),
|
|
36
|
+
success: HttpApiSchema.NoContent,
|
|
37
|
+
})
|
|
38
|
+
.annotateMerge(
|
|
39
|
+
OpenApi.annotations({
|
|
40
|
+
identifier: "credential.update",
|
|
41
|
+
summary: "Update credential",
|
|
42
|
+
description: "Update a stored credential label.",
|
|
43
|
+
}),
|
|
44
|
+
),
|
|
45
|
+
)
|
|
46
|
+
.annotateMerge(OpenApi.annotations({ title: "credential" }))
|
|
47
|
+
.add(
|
|
48
|
+
HttpApiEndpoint.post("credential.activate", "/api/credential/:credentialID/activate", {
|
|
49
|
+
params: { credentialID: Credential.ID },
|
|
50
|
+
success: HttpApiSchema.NoContent,
|
|
51
|
+
})
|
|
52
|
+
.annotateMerge(
|
|
53
|
+
OpenApi.annotations({
|
|
54
|
+
identifier: "credential.activate",
|
|
55
|
+
summary: "Activate credential",
|
|
56
|
+
description: "Activate a stored integration credential.",
|
|
57
|
+
}),
|
|
58
|
+
),
|
|
59
|
+
)
|
|
60
|
+
.add(
|
|
61
|
+
HttpApiEndpoint.delete("credential.remove", "/api/credential/:credentialID", {
|
|
62
|
+
params: { credentialID: Credential.ID },
|
|
63
|
+
success: HttpApiSchema.NoContent,
|
|
64
|
+
})
|
|
65
|
+
.annotateMerge(
|
|
66
|
+
OpenApi.annotations({
|
|
67
|
+
identifier: "credential.remove",
|
|
68
|
+
summary: "Remove credential",
|
|
69
|
+
description: "Remove a stored integration credential.",
|
|
70
|
+
}),
|
|
71
|
+
),
|
|
72
|
+
)
|
package/src/groups/debug.ts
CHANGED
|
@@ -1,68 +1,68 @@
|
|
|
1
|
-
import { Location } from "@zyro-sec/schema/location"
|
|
2
|
-
import { Schema } from "effect"
|
|
3
|
-
import { HttpApiEndpoint, HttpApiGroup, HttpApiSchema, OpenApi } from "effect/http-api"
|
|
4
|
-
import { InvalidRequestError, UnknownError } from "../errors.js"
|
|
5
|
-
import { LocationQuery, locationQueryOpenApi } from "./location.js"
|
|
6
|
-
|
|
7
|
-
export const DebugGroup = HttpApiGroup.make("server.debug")
|
|
8
|
-
.add(
|
|
9
|
-
HttpApiEndpoint.post("debug.heapDump", "/api/debug/heap-dump", {
|
|
10
|
-
query: Schema.Struct({
|
|
11
|
-
directory: Schema.String.pipe(
|
|
12
|
-
Schema.optional,
|
|
13
|
-
Schema.annotate({
|
|
14
|
-
description:
|
|
15
|
-
"Absolute server-local directory to write the snapshot into, created when missing. Defaults to the server's log directory.",
|
|
16
|
-
}),
|
|
17
|
-
),
|
|
18
|
-
}),
|
|
19
|
-
success: Schema.Struct({
|
|
20
|
-
path: Schema.String,
|
|
21
|
-
pid: Schema.Int,
|
|
22
|
-
memory: Schema.Struct({
|
|
23
|
-
rss: Schema.Number,
|
|
24
|
-
heapTotal: Schema.Number,
|
|
25
|
-
heapUsed: Schema.Number,
|
|
26
|
-
external: Schema.Number,
|
|
27
|
-
arrayBuffers: Schema.Number,
|
|
28
|
-
}).annotate({
|
|
29
|
-
description:
|
|
30
|
-
"The server process's memory in bytes, read just before the snapshot (Node's process.memoryUsage()). rss covers native memory the snapshot cannot show.",
|
|
31
|
-
}),
|
|
32
|
-
}),
|
|
33
|
-
error: [InvalidRequestError, UnknownError],
|
|
34
|
-
}).annotateMerge(
|
|
35
|
-
OpenApi.annotations({
|
|
36
|
-
identifier: "debug.heapDump",
|
|
37
|
-
summary: "Write a heap snapshot",
|
|
38
|
-
description:
|
|
39
|
-
"Write a JavaScript heap snapshot of the server process into its log directory, or the requested directory, and return the server-local path once the file is complete. Pauses the server while the heap serializes and can temporarily increase its memory use. The snapshot can contain credentials, prompts, and file contents.",
|
|
40
|
-
}),
|
|
41
|
-
),
|
|
42
|
-
)
|
|
43
|
-
.add(
|
|
44
|
-
HttpApiEndpoint.get("debug.location", "/api/debug/location", {
|
|
45
|
-
success: Schema.Array(Location.PublicRef),
|
|
46
|
-
}).annotateMerge(
|
|
47
|
-
OpenApi.annotations({
|
|
48
|
-
identifier: "debug.location.list",
|
|
49
|
-
summary: "List loaded locations",
|
|
50
|
-
description: "List locations currently loaded by the server.",
|
|
51
|
-
}),
|
|
52
|
-
),
|
|
53
|
-
)
|
|
54
|
-
.add(
|
|
55
|
-
HttpApiEndpoint.delete("debug.location.evict", "/api/debug/location", {
|
|
56
|
-
query: LocationQuery,
|
|
57
|
-
success: HttpApiSchema.NoContent,
|
|
58
|
-
})
|
|
59
|
-
.annotateMerge(locationQueryOpenApi)
|
|
60
|
-
.annotateMerge(
|
|
61
|
-
OpenApi.annotations({
|
|
62
|
-
identifier: "debug.location.evict",
|
|
63
|
-
summary: "Evict a loaded location",
|
|
64
|
-
description: "Dispose the requested location's cached services so its next use boots them fresh.",
|
|
65
|
-
}),
|
|
66
|
-
),
|
|
67
|
-
)
|
|
68
|
-
.annotateMerge(OpenApi.annotations({ title: "debug" }))
|
|
1
|
+
import { Location } from "@zyro-sec/schema/location"
|
|
2
|
+
import { Schema } from "effect"
|
|
3
|
+
import { HttpApiEndpoint, HttpApiGroup, HttpApiSchema, OpenApi } from "effect/http-api"
|
|
4
|
+
import { InvalidRequestError, UnknownError } from "../errors.js"
|
|
5
|
+
import { LocationQuery, locationQueryOpenApi } from "./location.js"
|
|
6
|
+
|
|
7
|
+
export const DebugGroup = HttpApiGroup.make("server.debug")
|
|
8
|
+
.add(
|
|
9
|
+
HttpApiEndpoint.post("debug.heapDump", "/api/debug/heap-dump", {
|
|
10
|
+
query: Schema.Struct({
|
|
11
|
+
directory: Schema.String.pipe(
|
|
12
|
+
Schema.optional,
|
|
13
|
+
Schema.annotate({
|
|
14
|
+
description:
|
|
15
|
+
"Absolute server-local directory to write the snapshot into, created when missing. Defaults to the server's log directory.",
|
|
16
|
+
}),
|
|
17
|
+
),
|
|
18
|
+
}),
|
|
19
|
+
success: Schema.Struct({
|
|
20
|
+
path: Schema.String,
|
|
21
|
+
pid: Schema.Int,
|
|
22
|
+
memory: Schema.Struct({
|
|
23
|
+
rss: Schema.Number,
|
|
24
|
+
heapTotal: Schema.Number,
|
|
25
|
+
heapUsed: Schema.Number,
|
|
26
|
+
external: Schema.Number,
|
|
27
|
+
arrayBuffers: Schema.Number,
|
|
28
|
+
}).annotate({
|
|
29
|
+
description:
|
|
30
|
+
"The server process's memory in bytes, read just before the snapshot (Node's process.memoryUsage()). rss covers native memory the snapshot cannot show.",
|
|
31
|
+
}),
|
|
32
|
+
}),
|
|
33
|
+
error: [InvalidRequestError, UnknownError],
|
|
34
|
+
}).annotateMerge(
|
|
35
|
+
OpenApi.annotations({
|
|
36
|
+
identifier: "debug.heapDump",
|
|
37
|
+
summary: "Write a heap snapshot",
|
|
38
|
+
description:
|
|
39
|
+
"Write a JavaScript heap snapshot of the server process into its log directory, or the requested directory, and return the server-local path once the file is complete. Pauses the server while the heap serializes and can temporarily increase its memory use. The snapshot can contain credentials, prompts, and file contents.",
|
|
40
|
+
}),
|
|
41
|
+
),
|
|
42
|
+
)
|
|
43
|
+
.add(
|
|
44
|
+
HttpApiEndpoint.get("debug.location", "/api/debug/location", {
|
|
45
|
+
success: Schema.Array(Location.PublicRef),
|
|
46
|
+
}).annotateMerge(
|
|
47
|
+
OpenApi.annotations({
|
|
48
|
+
identifier: "debug.location.list",
|
|
49
|
+
summary: "List loaded locations",
|
|
50
|
+
description: "List locations currently loaded by the server.",
|
|
51
|
+
}),
|
|
52
|
+
),
|
|
53
|
+
)
|
|
54
|
+
.add(
|
|
55
|
+
HttpApiEndpoint.delete("debug.location.evict", "/api/debug/location", {
|
|
56
|
+
query: LocationQuery,
|
|
57
|
+
success: HttpApiSchema.NoContent,
|
|
58
|
+
})
|
|
59
|
+
.annotateMerge(locationQueryOpenApi)
|
|
60
|
+
.annotateMerge(
|
|
61
|
+
OpenApi.annotations({
|
|
62
|
+
identifier: "debug.location.evict",
|
|
63
|
+
summary: "Evict a loaded location",
|
|
64
|
+
description: "Dispose the requested location's cached services so its next use boots them fresh.",
|
|
65
|
+
}),
|
|
66
|
+
),
|
|
67
|
+
)
|
|
68
|
+
.annotateMerge(OpenApi.annotations({ title: "debug" }))
|
package/src/groups/event.ts
CHANGED
|
@@ -1,86 +1,86 @@
|
|
|
1
|
-
import { Event } from "@zyro-sec/schema/event"
|
|
2
|
-
import { EventManifest } from "@zyro-sec/schema/event-manifest"
|
|
3
|
-
import { Location } from "@zyro-sec/schema/location"
|
|
4
|
-
import type { Definition } from "@zyro-sec/schema/event"
|
|
5
|
-
import { Schema } from "effect"
|
|
6
|
-
import { HttpApiEndpoint, HttpApiGroup, HttpApiSchema, OpenApi } from "effect/http-api"
|
|
7
|
-
|
|
8
|
-
const fields = {
|
|
9
|
-
id: Event.ID,
|
|
10
|
-
metadata: Schema.optional(Schema.Record(Schema.String, Schema.Unknown)),
|
|
11
|
-
location: Schema.optional(Location.PublicRef),
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
const rpcEvent = Schema.Struct({
|
|
15
|
-
id: Event.ID,
|
|
16
|
-
created: Schema.Finite,
|
|
17
|
-
metadata: Schema.optional(Schema.Record(Schema.String, Schema.Unknown)),
|
|
18
|
-
type: Schema.TemplateLiteral(["rpc.", Schema.String]),
|
|
19
|
-
location: Location.PublicRef,
|
|
20
|
-
data: Schema.Record(Schema.String, Schema.Unknown),
|
|
21
|
-
}).annotate({ identifier: "V2Event.rpc" })
|
|
22
|
-
|
|
23
|
-
const schema = <const Definitions extends ReadonlyArray<Definition>>(definitions: Definitions) =>
|
|
24
|
-
Schema.Union([
|
|
25
|
-
...definitions,
|
|
26
|
-
rpcEvent,
|
|
27
|
-
...(definitions.some((definition) => definition.type === "server.connected")
|
|
28
|
-
? []
|
|
29
|
-
: [
|
|
30
|
-
Schema.Struct({
|
|
31
|
-
...fields,
|
|
32
|
-
type: Schema.Literal("server.connected"),
|
|
33
|
-
data: Schema.Struct({}),
|
|
34
|
-
}).annotate({ identifier: "V2Event.server.connected" }),
|
|
35
|
-
]),
|
|
36
|
-
]).annotate({ identifier: "V2Event" })
|
|
37
|
-
|
|
38
|
-
const query = <const Definitions extends ReadonlyArray<Definition>>(definitions: Definitions) =>
|
|
39
|
-
Schema.Struct({
|
|
40
|
-
types: Schema.optional(
|
|
41
|
-
Schema.ArrayEnsure(
|
|
42
|
-
Schema.Union([
|
|
43
|
-
Schema.Literals(
|
|
44
|
-
definitions.map((definition) => definition.type) as ReadonlyArray<Definitions[number]["type"]>,
|
|
45
|
-
),
|
|
46
|
-
rpcEvent.fields.type,
|
|
47
|
-
]),
|
|
48
|
-
),
|
|
49
|
-
).annotate({
|
|
50
|
-
description:
|
|
51
|
-
"Only send events of these types, plus the initial server.connected event. When omitted, all events are sent.",
|
|
52
|
-
}),
|
|
53
|
-
}).annotate({ identifier: "EventSubscribeQuery" })
|
|
54
|
-
|
|
55
|
-
const make = <const Definitions extends ReadonlyArray<Definition>>(definitions: Definitions) => {
|
|
56
|
-
const EventSchema = schema(definitions)
|
|
57
|
-
return {
|
|
58
|
-
schema: EventSchema,
|
|
59
|
-
group: HttpApiGroup.make("server.event")
|
|
60
|
-
.add(
|
|
61
|
-
HttpApiEndpoint.get("event.subscribe", "/api/event", {
|
|
62
|
-
query: query(definitions),
|
|
63
|
-
success: HttpApiSchema.StreamSse({ data: EventSchema }),
|
|
64
|
-
}).annotateMerge(
|
|
65
|
-
OpenApi.annotations({
|
|
66
|
-
identifier: "event.subscribe",
|
|
67
|
-
summary: "Subscribe to events",
|
|
68
|
-
description:
|
|
69
|
-
"Subscribe to native events and plugin RPC events across all server locations. Volatile by contract: a slow consumer overflows and fails the stream, and events during disconnection are missed.",
|
|
70
|
-
}),
|
|
71
|
-
),
|
|
72
|
-
)
|
|
73
|
-
.annotateMerge(OpenApi.annotations({ title: "event", description: "Experimental event stream routes." })),
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
export const makeEventGroup = <const Definitions extends ReadonlyArray<Definition>>(definitions: Definitions) =>
|
|
78
|
-
make(definitions).group
|
|
79
|
-
|
|
80
|
-
const event = make(EventManifest.ServerDefinitions)
|
|
81
|
-
export const EventGroup = event.group
|
|
82
|
-
export const OpenCodeEvent = event.schema
|
|
83
|
-
export type OpenCodeEvent = typeof OpenCodeEvent.Type
|
|
84
|
-
export type OpenCodeEventEncoded = typeof OpenCodeEvent.Encoded
|
|
85
|
-
export const isOpenCodeEvent = (event: { readonly type: string }): event is OpenCodeEvent =>
|
|
86
|
-
event.type === "server.connected" || EventManifest.isServer(event) || event.type.startsWith("rpc.")
|
|
1
|
+
import { Event } from "@zyro-sec/schema/event"
|
|
2
|
+
import { EventManifest } from "@zyro-sec/schema/event-manifest"
|
|
3
|
+
import { Location } from "@zyro-sec/schema/location"
|
|
4
|
+
import type { Definition } from "@zyro-sec/schema/event"
|
|
5
|
+
import { Schema } from "effect"
|
|
6
|
+
import { HttpApiEndpoint, HttpApiGroup, HttpApiSchema, OpenApi } from "effect/http-api"
|
|
7
|
+
|
|
8
|
+
const fields = {
|
|
9
|
+
id: Event.ID,
|
|
10
|
+
metadata: Schema.optional(Schema.Record(Schema.String, Schema.Unknown)),
|
|
11
|
+
location: Schema.optional(Location.PublicRef),
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const rpcEvent = Schema.Struct({
|
|
15
|
+
id: Event.ID,
|
|
16
|
+
created: Schema.Finite,
|
|
17
|
+
metadata: Schema.optional(Schema.Record(Schema.String, Schema.Unknown)),
|
|
18
|
+
type: Schema.TemplateLiteral(["rpc.", Schema.String]),
|
|
19
|
+
location: Location.PublicRef,
|
|
20
|
+
data: Schema.Record(Schema.String, Schema.Unknown),
|
|
21
|
+
}).annotate({ identifier: "V2Event.rpc" })
|
|
22
|
+
|
|
23
|
+
const schema = <const Definitions extends ReadonlyArray<Definition>>(definitions: Definitions) =>
|
|
24
|
+
Schema.Union([
|
|
25
|
+
...definitions,
|
|
26
|
+
rpcEvent,
|
|
27
|
+
...(definitions.some((definition) => definition.type === "server.connected")
|
|
28
|
+
? []
|
|
29
|
+
: [
|
|
30
|
+
Schema.Struct({
|
|
31
|
+
...fields,
|
|
32
|
+
type: Schema.Literal("server.connected"),
|
|
33
|
+
data: Schema.Struct({}),
|
|
34
|
+
}).annotate({ identifier: "V2Event.server.connected" }),
|
|
35
|
+
]),
|
|
36
|
+
]).annotate({ identifier: "V2Event" })
|
|
37
|
+
|
|
38
|
+
const query = <const Definitions extends ReadonlyArray<Definition>>(definitions: Definitions) =>
|
|
39
|
+
Schema.Struct({
|
|
40
|
+
types: Schema.optional(
|
|
41
|
+
Schema.ArrayEnsure(
|
|
42
|
+
Schema.Union([
|
|
43
|
+
Schema.Literals(
|
|
44
|
+
definitions.map((definition) => definition.type) as ReadonlyArray<Definitions[number]["type"]>,
|
|
45
|
+
),
|
|
46
|
+
rpcEvent.fields.type,
|
|
47
|
+
]),
|
|
48
|
+
),
|
|
49
|
+
).annotate({
|
|
50
|
+
description:
|
|
51
|
+
"Only send events of these types, plus the initial server.connected event. When omitted, all events are sent.",
|
|
52
|
+
}),
|
|
53
|
+
}).annotate({ identifier: "EventSubscribeQuery" })
|
|
54
|
+
|
|
55
|
+
const make = <const Definitions extends ReadonlyArray<Definition>>(definitions: Definitions) => {
|
|
56
|
+
const EventSchema = schema(definitions)
|
|
57
|
+
return {
|
|
58
|
+
schema: EventSchema,
|
|
59
|
+
group: HttpApiGroup.make("server.event")
|
|
60
|
+
.add(
|
|
61
|
+
HttpApiEndpoint.get("event.subscribe", "/api/event", {
|
|
62
|
+
query: query(definitions),
|
|
63
|
+
success: HttpApiSchema.StreamSse({ data: EventSchema }),
|
|
64
|
+
}).annotateMerge(
|
|
65
|
+
OpenApi.annotations({
|
|
66
|
+
identifier: "event.subscribe",
|
|
67
|
+
summary: "Subscribe to events",
|
|
68
|
+
description:
|
|
69
|
+
"Subscribe to native events and plugin RPC events across all server locations. Volatile by contract: a slow consumer overflows and fails the stream, and events during disconnection are missed.",
|
|
70
|
+
}),
|
|
71
|
+
),
|
|
72
|
+
)
|
|
73
|
+
.annotateMerge(OpenApi.annotations({ title: "event", description: "Experimental event stream routes." })),
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export const makeEventGroup = <const Definitions extends ReadonlyArray<Definition>>(definitions: Definitions) =>
|
|
78
|
+
make(definitions).group
|
|
79
|
+
|
|
80
|
+
const event = make(EventManifest.ServerDefinitions)
|
|
81
|
+
export const EventGroup = event.group
|
|
82
|
+
export const OpenCodeEvent = event.schema
|
|
83
|
+
export type OpenCodeEvent = typeof OpenCodeEvent.Type
|
|
84
|
+
export type OpenCodeEventEncoded = typeof OpenCodeEvent.Encoded
|
|
85
|
+
export const isOpenCodeEvent = (event: { readonly type: string }): event is OpenCodeEvent =>
|
|
86
|
+
event.type === "server.connected" || EventManifest.isServer(event) || event.type.startsWith("rpc.")
|
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
import { ArtifactEndpoints } from "./artifact.js"
|
|
2
|
-
import { BlobGetEndpoint } from "./blob.js"
|
|
3
|
-
import { AutomationEndpoints } from "./automation.js"
|
|
4
|
-
import { JobEndpoints } from "./job.js"
|
|
5
|
-
import { MachineEndpoints } from "./machine.js"
|
|
6
|
-
import { MediaGetEndpoint } from "./media.js"
|
|
7
|
-
import { PersistentPtyGroup } from "./persistent-pty.js"
|
|
8
|
-
import { PushEndpoints } from "./push.js"
|
|
9
|
-
|
|
10
|
-
/** `server.experimental`: routes under /api/experimental, without compatibility guarantees. */
|
|
11
|
-
export const ExperimentalGroup = PersistentPtyGroup.add(
|
|
12
|
-
MediaGetEndpoint,
|
|
13
|
-
BlobGetEndpoint,
|
|
14
|
-
...AutomationEndpoints,
|
|
15
|
-
...ArtifactEndpoints,
|
|
16
|
-
...JobEndpoints,
|
|
17
|
-
...MachineEndpoints,
|
|
18
|
-
...PushEndpoints,
|
|
19
|
-
)
|
|
1
|
+
import { ArtifactEndpoints } from "./artifact.js"
|
|
2
|
+
import { BlobGetEndpoint } from "./blob.js"
|
|
3
|
+
import { AutomationEndpoints } from "./automation.js"
|
|
4
|
+
import { JobEndpoints } from "./job.js"
|
|
5
|
+
import { MachineEndpoints } from "./machine.js"
|
|
6
|
+
import { MediaGetEndpoint } from "./media.js"
|
|
7
|
+
import { PersistentPtyGroup } from "./persistent-pty.js"
|
|
8
|
+
import { PushEndpoints } from "./push.js"
|
|
9
|
+
|
|
10
|
+
/** `server.experimental`: routes under /api/experimental, without compatibility guarantees. */
|
|
11
|
+
export const ExperimentalGroup = PersistentPtyGroup.add(
|
|
12
|
+
MediaGetEndpoint,
|
|
13
|
+
BlobGetEndpoint,
|
|
14
|
+
...AutomationEndpoints,
|
|
15
|
+
...ArtifactEndpoints,
|
|
16
|
+
...JobEndpoints,
|
|
17
|
+
...MachineEndpoints,
|
|
18
|
+
...PushEndpoints,
|
|
19
|
+
)
|
package/src/groups/form.ts
CHANGED
|
@@ -1,26 +1,26 @@
|
|
|
1
|
-
import { Form } from "@zyro-sec/schema/form"
|
|
2
|
-
import { Location } from "@zyro-sec/schema/location"
|
|
3
|
-
import { Context, Schema } from "effect"
|
|
4
|
-
import { HttpApiEndpoint, HttpApiGroup, HttpApiMiddleware, OpenApi } from "effect/http-api"
|
|
5
|
-
import { LocationQuery, locationQueryOpenApi } from "./location.js"
|
|
6
|
-
|
|
7
|
-
export const makeFormGroup = <LocationId extends HttpApiMiddleware.AnyId, LocationService>(
|
|
8
|
-
locationMiddleware: Context.Key<LocationId, LocationService>,
|
|
9
|
-
) =>
|
|
10
|
-
HttpApiGroup.make("server.form")
|
|
11
|
-
.add(
|
|
12
|
-
HttpApiEndpoint.get("form.list", "/api/form", {
|
|
13
|
-
query: LocationQuery,
|
|
14
|
-
success: Location.response(Schema.Array(Form.Info)),
|
|
15
|
-
})
|
|
16
|
-
.annotateMerge(locationQueryOpenApi)
|
|
17
|
-
.annotateMerge(
|
|
18
|
-
OpenApi.annotations({
|
|
19
|
-
identifier: "form.list",
|
|
20
|
-
summary: "List pending forms",
|
|
21
|
-
description: "Retrieve pending forms for a location.",
|
|
22
|
-
}),
|
|
23
|
-
),
|
|
24
|
-
)
|
|
25
|
-
.middleware(locationMiddleware)
|
|
26
|
-
.annotateMerge(OpenApi.annotations({ title: "form", description: "Location form routes." }))
|
|
1
|
+
import { Form } from "@zyro-sec/schema/form"
|
|
2
|
+
import { Location } from "@zyro-sec/schema/location"
|
|
3
|
+
import { Context, Schema } from "effect"
|
|
4
|
+
import { HttpApiEndpoint, HttpApiGroup, HttpApiMiddleware, OpenApi } from "effect/http-api"
|
|
5
|
+
import { LocationQuery, locationQueryOpenApi } from "./location.js"
|
|
6
|
+
|
|
7
|
+
export const makeFormGroup = <LocationId extends HttpApiMiddleware.AnyId, LocationService>(
|
|
8
|
+
locationMiddleware: Context.Key<LocationId, LocationService>,
|
|
9
|
+
) =>
|
|
10
|
+
HttpApiGroup.make("server.form")
|
|
11
|
+
.add(
|
|
12
|
+
HttpApiEndpoint.get("form.list", "/api/form", {
|
|
13
|
+
query: LocationQuery,
|
|
14
|
+
success: Location.response(Schema.Array(Form.Info)),
|
|
15
|
+
})
|
|
16
|
+
.annotateMerge(locationQueryOpenApi)
|
|
17
|
+
.annotateMerge(
|
|
18
|
+
OpenApi.annotations({
|
|
19
|
+
identifier: "form.list",
|
|
20
|
+
summary: "List pending forms",
|
|
21
|
+
description: "Retrieve pending forms for a location.",
|
|
22
|
+
}),
|
|
23
|
+
),
|
|
24
|
+
)
|
|
25
|
+
.middleware(locationMiddleware)
|
|
26
|
+
.annotateMerge(OpenApi.annotations({ title: "form", description: "Location form routes." }))
|