@zyro-sec/protocol 1.0.0 → 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 (61) hide show
  1. package/openapi.json +33222 -0
  2. package/package.json +7 -14
  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
package/src/errors.ts ADDED
@@ -0,0 +1,398 @@
1
+ import { Schema } from "effect"
2
+ import { Skill } from "@zyro-sec/schema/skill"
3
+ import { Location } from "@zyro-sec/schema/location"
4
+
5
+ export class LocationNotFoundError extends Schema.TaggedError<LocationNotFoundError>()(
6
+ "LocationNotFoundError",
7
+ { location: Location.PublicRef, message: Schema.String },
8
+ { httpApiStatus: 404 },
9
+ ) {}
10
+
11
+ export class InvalidRequestError extends Schema.TaggedError<InvalidRequestError>()(
12
+ "InvalidRequestError",
13
+ {
14
+ message: Schema.String,
15
+ kind: Schema.optional(Schema.String),
16
+ field: Schema.optional(Schema.String),
17
+ },
18
+ { httpApiStatus: 400 },
19
+ ) {}
20
+
21
+ export class RpcError extends Schema.TaggedError<RpcError>()(
22
+ "RpcError",
23
+ {
24
+ type: Schema.String,
25
+ message: Schema.String,
26
+ data: Schema.optional(Schema.Unknown),
27
+ },
28
+ { httpApiStatus: 400 },
29
+ ) {}
30
+
31
+ export class RpcInternalError extends Schema.TaggedError<RpcInternalError>()(
32
+ "RpcInternalError",
33
+ {
34
+ type: Schema.Literals(["rpc.internal", "rpc.invalid_output"]),
35
+ message: Schema.String,
36
+ data: Schema.optional(Schema.Unknown),
37
+ },
38
+ { httpApiStatus: 500 },
39
+ ) {}
40
+
41
+ export class UnauthorizedError extends Schema.TaggedError<UnauthorizedError>()(
42
+ "UnauthorizedError",
43
+ { message: Schema.String },
44
+ { httpApiStatus: 401 },
45
+ ) {}
46
+
47
+ export class ConflictError extends Schema.TaggedError<ConflictError>()(
48
+ "ConflictError",
49
+ {
50
+ message: Schema.String,
51
+ resource: Schema.optional(Schema.String),
52
+ },
53
+ { httpApiStatus: 409 },
54
+ ) {}
55
+
56
+ export class SessionBusyError extends Schema.TaggedError<SessionBusyError>()(
57
+ "SessionBusyError",
58
+ {
59
+ sessionID: Schema.String,
60
+ message: Schema.String,
61
+ },
62
+ { httpApiStatus: 409 },
63
+ ) {}
64
+
65
+ export class ServiceUnavailableError extends Schema.TaggedError<ServiceUnavailableError>()(
66
+ "ServiceUnavailableError",
67
+ {
68
+ message: Schema.String,
69
+ service: Schema.optional(Schema.String),
70
+ },
71
+ { httpApiStatus: 503 },
72
+ ) {}
73
+
74
+ export class UnknownError extends Schema.TaggedError<UnknownError>()(
75
+ "UnknownError",
76
+ {
77
+ message: Schema.String,
78
+ ref: Schema.optional(Schema.String),
79
+ },
80
+ { httpApiStatus: 500 },
81
+ ) {}
82
+
83
+ export class ProviderNotFoundError extends Schema.TaggedError<ProviderNotFoundError>()(
84
+ "ProviderNotFoundError",
85
+ {
86
+ providerID: Schema.String,
87
+ message: Schema.String,
88
+ },
89
+ { httpApiStatus: 404 },
90
+ ) {}
91
+
92
+ export class IntegrationNotFoundError extends Schema.TaggedError<IntegrationNotFoundError>()(
93
+ "IntegrationNotFoundError",
94
+ {
95
+ integrationID: Schema.String,
96
+ message: Schema.String,
97
+ },
98
+ { httpApiStatus: 404 },
99
+ ) {}
100
+
101
+ export class IntegrationAttemptNotFoundError extends Schema.TaggedError<IntegrationAttemptNotFoundError>()(
102
+ "IntegrationAttemptNotFoundError",
103
+ {
104
+ integrationID: Schema.String,
105
+ attemptID: Schema.String,
106
+ message: Schema.String,
107
+ },
108
+ { httpApiStatus: 404 },
109
+ ) {}
110
+
111
+ export class IntegrationMethodNotFoundError extends Schema.TaggedError<IntegrationMethodNotFoundError>()(
112
+ "IntegrationMethodNotFoundError",
113
+ {
114
+ integrationID: Schema.String,
115
+ methodID: Schema.String,
116
+ message: Schema.String,
117
+ },
118
+ { httpApiStatus: 404 },
119
+ ) {}
120
+
121
+ export class ProjectNotFoundError extends Schema.TaggedError<ProjectNotFoundError>()(
122
+ "ProjectNotFoundError",
123
+ {
124
+ projectID: Schema.String,
125
+ message: Schema.String,
126
+ },
127
+ { httpApiStatus: 404 },
128
+ ) {}
129
+
130
+ export class FileNotFoundError extends Schema.TaggedError<FileNotFoundError>()(
131
+ "FileNotFoundError",
132
+ {
133
+ path: Schema.String,
134
+ message: Schema.String,
135
+ },
136
+ { httpApiStatus: 404 },
137
+ ) {}
138
+
139
+ export class PluginNotFoundError extends Schema.TaggedError<PluginNotFoundError>()(
140
+ "PluginNotFoundError",
141
+ {
142
+ pluginID: Schema.String,
143
+ message: Schema.String,
144
+ },
145
+ { httpApiStatus: 404 },
146
+ ) {}
147
+ export class AgentNotFoundError extends Schema.TaggedError<AgentNotFoundError>()(
148
+ "AgentNotFoundError",
149
+ {
150
+ agentID: Schema.String,
151
+ message: Schema.String,
152
+ },
153
+ { httpApiStatus: 404 },
154
+ ) {}
155
+
156
+ export class SessionNotFoundError extends Schema.TaggedError<SessionNotFoundError>()(
157
+ "SessionNotFoundError",
158
+ {
159
+ sessionID: Schema.String,
160
+ message: Schema.String,
161
+ },
162
+ { httpApiStatus: 404 },
163
+ ) {}
164
+
165
+ export class MessageNotFoundError extends Schema.TaggedError<MessageNotFoundError>()(
166
+ "MessageNotFoundError",
167
+ {
168
+ sessionID: Schema.String,
169
+ messageID: Schema.String,
170
+ message: Schema.String,
171
+ },
172
+ { httpApiStatus: 404 },
173
+ ) {}
174
+
175
+ export class SkillNotFoundError extends Schema.TaggedError<SkillNotFoundError>()(
176
+ "SkillNotFoundError",
177
+ {
178
+ skill: Skill.ID,
179
+ message: Schema.String,
180
+ },
181
+ { httpApiStatus: 404 },
182
+ ) {}
183
+
184
+ export class SkillLoadError extends Schema.TaggedError<SkillLoadError>()(
185
+ "SkillLoadError",
186
+ {
187
+ skill: Skill.ID,
188
+ message: Schema.String,
189
+ },
190
+ { httpApiStatus: 502 },
191
+ ) {}
192
+
193
+ export class McpServerNotFoundError extends Schema.TaggedError<McpServerNotFoundError>()(
194
+ "McpServerNotFoundError",
195
+ {
196
+ server: Schema.String,
197
+ message: Schema.String,
198
+ },
199
+ { httpApiStatus: 404 },
200
+ ) {}
201
+
202
+ export class CommandNotFoundError extends Schema.TaggedError<CommandNotFoundError>()(
203
+ "CommandNotFoundError",
204
+ {
205
+ command: Schema.String,
206
+ message: Schema.String,
207
+ },
208
+ { httpApiStatus: 404 },
209
+ ) {}
210
+
211
+ export class CommandExecutionError extends Schema.TaggedError<CommandExecutionError>()(
212
+ "CommandExecutionError",
213
+ {
214
+ command: Schema.String,
215
+ message: Schema.String,
216
+ },
217
+ { httpApiStatus: 500 },
218
+ ) {}
219
+
220
+ export class InvalidCursorError extends Schema.TaggedError<InvalidCursorError>()(
221
+ "InvalidCursorError",
222
+ { message: Schema.String },
223
+ { httpApiStatus: 400 },
224
+ ) {}
225
+
226
+ export class PermissionNotFoundError extends Schema.TaggedError<PermissionNotFoundError>()(
227
+ "PermissionNotFoundError",
228
+ {
229
+ requestID: Schema.String,
230
+ message: Schema.String,
231
+ },
232
+ { httpApiStatus: 404 },
233
+ ) {}
234
+
235
+ export class PermissionSavedNotFoundError extends Schema.TaggedError<PermissionSavedNotFoundError>()(
236
+ "PermissionSavedNotFoundError",
237
+ {
238
+ id: Schema.String,
239
+ message: Schema.String,
240
+ },
241
+ { httpApiStatus: 404 },
242
+ ) {}
243
+
244
+ export class FormNotFoundError extends Schema.TaggedError<FormNotFoundError>()(
245
+ "FormNotFoundError",
246
+ {
247
+ id: Schema.String,
248
+ message: Schema.String,
249
+ },
250
+ { httpApiStatus: 404 },
251
+ ) {}
252
+
253
+ export class FormAlreadySettledError extends Schema.TaggedError<FormAlreadySettledError>()(
254
+ "FormAlreadySettledError",
255
+ {
256
+ id: Schema.String,
257
+ message: Schema.String,
258
+ },
259
+ { httpApiStatus: 409 },
260
+ ) {}
261
+
262
+ export class FormInvalidAnswerError extends Schema.TaggedError<FormInvalidAnswerError>()(
263
+ "FormInvalidAnswerError",
264
+ {
265
+ id: Schema.String,
266
+ message: Schema.String,
267
+ },
268
+ { httpApiStatus: 400 },
269
+ ) {}
270
+
271
+ export class ForbiddenError extends Schema.TaggedError<ForbiddenError>()(
272
+ "ForbiddenError",
273
+ { message: Schema.String },
274
+ { httpApiStatus: 403 },
275
+ ) {}
276
+
277
+ export class PtyNotFoundError extends Schema.TaggedError<PtyNotFoundError>()(
278
+ "PtyNotFoundError",
279
+ {
280
+ ptyID: Schema.String,
281
+ message: Schema.String,
282
+ },
283
+ { httpApiStatus: 404 },
284
+ ) {}
285
+
286
+ export class PtyFeatureUnsupportedError extends Schema.TaggedError<PtyFeatureUnsupportedError>()(
287
+ "PtyFeatureUnsupportedError",
288
+ {
289
+ feature: Schema.String,
290
+ message: Schema.String,
291
+ },
292
+ { httpApiStatus: 501 },
293
+ ) {}
294
+
295
+ export class ShellNotFoundError extends Schema.TaggedError<ShellNotFoundError>()(
296
+ "ShellNotFoundError",
297
+ {
298
+ id: Schema.String,
299
+ message: Schema.String,
300
+ },
301
+ { httpApiStatus: 404 },
302
+ ) {}
303
+
304
+ export class ModelNotFoundError extends Schema.TaggedError<ModelNotFoundError>()(
305
+ "ModelNotFoundError",
306
+ {
307
+ providerID: Schema.String,
308
+ modelID: Schema.String,
309
+ message: Schema.String,
310
+ },
311
+ { httpApiStatus: 404 },
312
+ ) {}
313
+
314
+ /** The model exists but cannot serve this request, such as a chat model asked for images. */
315
+ export class UnsupportedModelError extends Schema.TaggedError<UnsupportedModelError>()(
316
+ "UnsupportedModelError",
317
+ {
318
+ providerID: Schema.String,
319
+ modelID: Schema.String,
320
+ capability: Schema.String,
321
+ message: Schema.String,
322
+ },
323
+ { httpApiStatus: 422 },
324
+ ) {}
325
+
326
+ /** The provider rejected or failed the request after the server sent it. */
327
+ export class ProviderRequestError extends Schema.TaggedError<ProviderRequestError>()(
328
+ "ProviderRequestError",
329
+ {
330
+ providerID: Schema.String,
331
+ reason: Schema.Literals([
332
+ "authentication",
333
+ "rate_limit",
334
+ "content_filter",
335
+ "invalid_request",
336
+ "overloaded",
337
+ "provider",
338
+ ]),
339
+ message: Schema.String,
340
+ status: Schema.optional(Schema.Int),
341
+ retryAfterMs: Schema.optional(Schema.Int),
342
+ },
343
+ { httpApiStatus: 502 },
344
+ ) {}
345
+
346
+ export class AutomationNotFoundError extends Schema.TaggedError<AutomationNotFoundError>()(
347
+ "AutomationNotFoundError",
348
+ {
349
+ automationID: Schema.String,
350
+ message: Schema.String,
351
+ },
352
+ { httpApiStatus: 404 },
353
+ ) {}
354
+
355
+ export class VideoNotFoundError extends Schema.TaggedError<VideoNotFoundError>()(
356
+ "VideoNotFoundError",
357
+ {
358
+ videoID: Schema.String,
359
+ message: Schema.String,
360
+ },
361
+ { httpApiStatus: 404 },
362
+ ) {}
363
+
364
+ export class BlobNotFoundError extends Schema.TaggedError<BlobNotFoundError>()(
365
+ "BlobNotFoundError",
366
+ {
367
+ blobID: Schema.String,
368
+ message: Schema.String,
369
+ },
370
+ { httpApiStatus: 404 },
371
+ ) {}
372
+
373
+ export class ArtifactNotFoundError extends Schema.TaggedError<ArtifactNotFoundError>()(
374
+ "ArtifactNotFoundError",
375
+ {
376
+ artifactID: Schema.String,
377
+ message: Schema.String,
378
+ },
379
+ { httpApiStatus: 404 },
380
+ ) {}
381
+
382
+ export class MachineNotFoundError extends Schema.TaggedError<MachineNotFoundError>()(
383
+ "MachineNotFoundError",
384
+ {
385
+ machine: Schema.String,
386
+ message: Schema.String,
387
+ },
388
+ { httpApiStatus: 404 },
389
+ ) {}
390
+
391
+ export class PushDeviceNotFoundError extends Schema.TaggedError<PushDeviceNotFoundError>()(
392
+ "PushDeviceNotFoundError",
393
+ {
394
+ deviceID: Schema.String,
395
+ message: Schema.String,
396
+ },
397
+ { httpApiStatus: 404 },
398
+ ) {}
@@ -0,0 +1,39 @@
1
+ import { Agent } from "@zyro-sec/schema/agent"
2
+ import { Location } from "@zyro-sec/schema/location"
3
+ import { Schema } from "effect"
4
+ import { HttpApiEndpoint, HttpApiGroup, OpenApi } from "effect/http-api"
5
+ import { LocationQuery, locationQueryOpenApi } from "./location.js"
6
+ import { AgentNotFoundError } from "../errors.js"
7
+
8
+ export const AgentGroup = HttpApiGroup.make("server.agent")
9
+ .add(
10
+ HttpApiEndpoint.get("agent.list", "/api/agent", {
11
+ query: LocationQuery,
12
+ success: Location.response(Schema.Array(Agent.Info)),
13
+ })
14
+ .annotateMerge(locationQueryOpenApi)
15
+ .annotateMerge(
16
+ OpenApi.annotations({
17
+ identifier: "agent.list",
18
+ summary: "List agents",
19
+ description: "Retrieve currently registered agents.",
20
+ }),
21
+ ),
22
+ )
23
+ .add(
24
+ HttpApiEndpoint.get("agent.get", "/api/agent/:agentID", {
25
+ params: { agentID: Agent.ID },
26
+ query: LocationQuery,
27
+ success: Location.response(Agent.Info),
28
+ error: AgentNotFoundError,
29
+ })
30
+ .annotateMerge(locationQueryOpenApi)
31
+ .annotateMerge(
32
+ OpenApi.annotations({
33
+ identifier: "agent.get",
34
+ summary: "Get agent",
35
+ description: "Retrieve a single currently registered agent.",
36
+ }),
37
+ ),
38
+ )
39
+ .annotateMerge(OpenApi.annotations({ title: "agent" }))
@@ -0,0 +1,103 @@
1
+ import { Artifact } from "@zyro-sec/schema/artifact"
2
+ import { Location } from "@zyro-sec/schema/location"
3
+ import { Session } from "@zyro-sec/schema/session"
4
+ import { Schema } from "effect"
5
+ import { HttpApiEndpoint, HttpApiSchema, OpenApi } from "effect/http-api"
6
+ import {
7
+ ArtifactNotFoundError,
8
+ FileNotFoundError,
9
+ ForbiddenError,
10
+ InvalidRequestError,
11
+ LocationNotFoundError,
12
+ ProviderNotFoundError,
13
+ ServiceUnavailableError,
14
+ SessionNotFoundError,
15
+ } from "../errors.js"
16
+ import { LocationQuery, locationQueryOpenApi } from "./location.js"
17
+
18
+ const EXPERIMENTAL =
19
+ "Experimental: needs experimental.artifacts in the Location's config and may change without notice."
20
+
21
+ const params = { artifactID: Artifact.ID }
22
+
23
+ const ListQuery = Schema.Struct({
24
+ ...LocationQuery.fields,
25
+ sessionID: Schema.optional(Session.ID),
26
+ provider: Schema.optional(Artifact.ProviderID),
27
+ })
28
+
29
+ const annotations = (identifier: string, summary: string, description: string) =>
30
+ OpenApi.annotations({
31
+ identifier: `experimental.artifacts.${identifier}`,
32
+ summary,
33
+ description: `${description} ${EXPERIMENTAL}`,
34
+ transform: (operation) => ({ ...operation, tags: ["experimental"] }),
35
+ })
36
+
37
+ const commonErrors = [ForbiddenError, LocationNotFoundError, ServiceUnavailableError] as const
38
+ const itemErrors = [ArtifactNotFoundError, ...commonErrors] as const
39
+
40
+ /** Lives in the `server.experimental` group (see `groups/experimental.ts`). */
41
+ export const ArtifactEndpoints = [
42
+ HttpApiEndpoint.get("artifacts.providers", "/api/experimental/artifacts/providers", {
43
+ query: LocationQuery,
44
+ success: Location.response(Schema.Array(Artifact.Provider)),
45
+ error: commonErrors,
46
+ })
47
+ .annotateMerge(locationQueryOpenApi)
48
+ .annotateMerge(annotations("providers", "List artifact providers", "Return active artifact providers and default.")),
49
+ HttpApiEndpoint.get("artifacts.list", "/api/experimental/artifacts", {
50
+ query: ListQuery,
51
+ success: Location.response(Schema.Array(Artifact.Info)),
52
+ error: [SessionNotFoundError, ...commonErrors],
53
+ })
54
+ .annotateMerge(locationQueryOpenApi)
55
+ .annotateMerge(annotations("list", "List artifacts", "List published artifacts, newest update first.")),
56
+ HttpApiEndpoint.post("artifacts.create", "/api/experimental/artifacts", {
57
+ query: LocationQuery,
58
+ payload: Artifact.CreateInput,
59
+ success: Location.response(Artifact.Info),
60
+ error: [InvalidRequestError, ProviderNotFoundError, SessionNotFoundError, ...commonErrors],
61
+ })
62
+ .annotateMerge(locationQueryOpenApi)
63
+ .annotateMerge(
64
+ annotations(
65
+ "create",
66
+ "Create artifact",
67
+ "Publish a new artifact through the selected or default artifact provider.",
68
+ ),
69
+ ),
70
+ HttpApiEndpoint.get("artifacts.get", "/api/experimental/artifacts/:artifactID", {
71
+ params,
72
+ query: LocationQuery,
73
+ success: Location.response(Artifact.Content),
74
+ error: itemErrors,
75
+ })
76
+ .annotateMerge(locationQueryOpenApi)
77
+ .annotateMerge(annotations("get", "Read artifact", "Read an artifact's metadata and file contents.")),
78
+ HttpApiEndpoint.patch("artifacts.update", "/api/experimental/artifacts/:artifactID", {
79
+ params,
80
+ query: LocationQuery,
81
+ payload: Artifact.UpdateInput,
82
+ success: Location.response(Artifact.Info),
83
+ error: [InvalidRequestError, SessionNotFoundError, ...itemErrors],
84
+ })
85
+ .annotateMerge(locationQueryOpenApi)
86
+ .annotateMerge(annotations("update", "Update artifact", "Replace an artifact's files at the same ID and URL.")),
87
+ HttpApiEndpoint.delete("artifacts.delete", "/api/experimental/artifacts/:artifactID", {
88
+ params,
89
+ query: LocationQuery,
90
+ success: HttpApiSchema.NoContent,
91
+ error: itemErrors,
92
+ })
93
+ .annotateMerge(locationQueryOpenApi)
94
+ .annotateMerge(annotations("delete", "Delete artifact", "Remove an artifact and its stored files.")),
95
+ HttpApiEndpoint.get("artifacts.view", "/api/experimental/artifacts/:artifactID/view/*", {
96
+ params,
97
+ query: LocationQuery,
98
+ success: Schema.Uint8Array.pipe(HttpApiSchema.asUint8Array()),
99
+ error: [FileNotFoundError, InvalidRequestError, ...itemErrors],
100
+ })
101
+ .annotateMerge(locationQueryOpenApi)
102
+ .annotateMerge(annotations("view", "View local artifact", "Serve HTML and static files from the local provider.")),
103
+ ] as const
@@ -0,0 +1,75 @@
1
+ import { Automation } from "@zyro-sec/schema/automation"
2
+ import { Session } from "@zyro-sec/schema/session"
3
+ import { Schema } from "effect"
4
+ import { HttpApiEndpoint, HttpApiSchema, OpenApi } from "effect/http-api"
5
+ import { AutomationNotFoundError, ForbiddenError, InvalidRequestError, SessionNotFoundError } from "../errors.js"
6
+
7
+ const EXPERIMENTAL =
8
+ "Experimental: may change without compatibility guarantees. Set automations to false in the directory's config to disable access."
9
+ const errors = [AutomationNotFoundError, ForbiddenError] as const
10
+ const params = { automationID: Automation.ID }
11
+ const annotations = (identifier: string, summary: string, description: string) =>
12
+ OpenApi.annotations({
13
+ identifier: `experimental.automation.${identifier}`,
14
+ summary,
15
+ description: `${description} ${EXPERIMENTAL}`,
16
+ // The routes share the `server.experimental` group with the persistent PTY prototype; tag them on their own.
17
+ transform: (operation) => ({ ...operation, tags: ["experimental"] }),
18
+ })
19
+
20
+ export const CreatePayload = Automation.CreateInput.annotate({ identifier: "Automation.CreatePayload" })
21
+ export type CreatePayload = typeof CreatePayload.Type
22
+
23
+ export const ListQuery = Schema.Struct({
24
+ sessionID: Session.ID.pipe(Schema.optional).annotate({ description: "Only automations created by this Session." }),
25
+ directory: Schema.String.pipe(Schema.optional).annotate({
26
+ description: "Only automations in the project that owns this directory.",
27
+ }),
28
+ }).annotate({ identifier: "Automation.ListQuery" })
29
+ export type ListQuery = typeof ListQuery.Type
30
+
31
+ /** Lives in the `server.experimental` group (see `groups/experimental.ts`). */
32
+ export const AutomationEndpoints = [
33
+ HttpApiEndpoint.post("automation.create", "/api/experimental/automation", {
34
+ payload: CreatePayload,
35
+ success: Schema.Struct({ data: Automation.Info }),
36
+ error: [InvalidRequestError, SessionNotFoundError, ForbiddenError],
37
+ }).annotateMerge(
38
+ annotations(
39
+ "create",
40
+ "Create automation",
41
+ "Create an automation that sends a prompt, runs a Code Mode program, or runs a shell command at a time, every interval, or on a cron. Creating an MCP event watch requires the automation_create tool in a local session; a session ID over HTTP is not a watch authorization.",
42
+ ),
43
+ ),
44
+ HttpApiEndpoint.get("automation.list", "/api/experimental/automation", {
45
+ query: ListQuery,
46
+ success: Schema.Struct({ data: Schema.Array(Automation.Info) }),
47
+ error: [SessionNotFoundError, ForbiddenError, InvalidRequestError],
48
+ }).annotateMerge(annotations("list", "List automations", "List automations, oldest first.")),
49
+ HttpApiEndpoint.get("automation.get", "/api/experimental/automation/:automationID", {
50
+ params,
51
+ success: Schema.Struct({ data: Automation.Info }),
52
+ error: errors,
53
+ }).annotateMerge(annotations("get", "Get automation", "Read one automation.")),
54
+ HttpApiEndpoint.post("automation.pause", "/api/experimental/automation/:automationID/pause", {
55
+ params,
56
+ success: Schema.Struct({ data: Automation.Info }),
57
+ error: errors,
58
+ }).annotateMerge(annotations("pause", "Pause automation", "Stop an automation from running until it is resumed.")),
59
+ HttpApiEndpoint.post("automation.resume", "/api/experimental/automation/:automationID/resume", {
60
+ params,
61
+ success: Schema.Struct({ data: Automation.Info }),
62
+ error: errors,
63
+ }).annotateMerge(
64
+ annotations(
65
+ "resume",
66
+ "Resume automation",
67
+ "Resume a paused automation. A missed `at` runs once; repeating timers resume at their next slot. Event watches request replay from their saved cursor.",
68
+ ),
69
+ ),
70
+ HttpApiEndpoint.delete("automation.delete", "/api/experimental/automation/:automationID", {
71
+ params,
72
+ success: HttpApiSchema.NoContent,
73
+ error: errors,
74
+ }).annotateMerge(annotations("delete", "Delete automation", "Delete an automation.")),
75
+ ] as const
@@ -0,0 +1,20 @@
1
+ import { BlobStore } from "@zyro-sec/schema/blob-store"
2
+ import { Schema } from "effect"
3
+ import { HttpApiEndpoint, HttpApiSchema, OpenApi } from "effect/http-api"
4
+ import { BlobNotFoundError } from "../errors.js"
5
+
6
+ /** Lives in the `server.experimental` group (see `groups/experimental.ts`). */
7
+ export const BlobGetEndpoint = HttpApiEndpoint.get("blob.get", "/api/experimental/blob/:id", {
8
+ params: { id: BlobStore.ID },
9
+ success: Schema.Uint8Array.pipe(HttpApiSchema.asUint8Array()),
10
+ error: [BlobNotFoundError],
11
+ }).annotateMerge(
12
+ OpenApi.annotations({
13
+ identifier: "experimental.blob.get",
14
+ summary: "Read a blob",
15
+ description:
16
+ "Stream a stored blob's bytes, such as a generated video, with single byte Range, ETag and 304 Not Modified support. A blob is deleted a week after it was stored. Experimental: may change without compatibility guarantees.",
17
+ // The route shares the `server.experimental` group with the persistent PTY prototype; tag it on its own.
18
+ transform: (operation) => ({ ...operation, tags: ["experimental"] }),
19
+ }),
20
+ )
@@ -0,0 +1,27 @@
1
+ import { Command } from "@zyro-sec/schema/command"
2
+ import { Location } from "@zyro-sec/schema/location"
3
+ import { Schema } from "effect"
4
+ import { HttpApiEndpoint, HttpApiGroup, OpenApi } from "effect/http-api"
5
+ import { LocationQuery, locationQueryOpenApi } from "./location.js"
6
+
7
+ export const CommandGroup = HttpApiGroup.make("server.command")
8
+ .add(
9
+ HttpApiEndpoint.get("command.list", "/api/command", {
10
+ query: LocationQuery,
11
+ success: Location.response(Schema.Array(Command.Info)),
12
+ })
13
+ .annotateMerge(locationQueryOpenApi)
14
+ .annotateMerge(
15
+ OpenApi.annotations({
16
+ identifier: "command.list",
17
+ summary: "List commands",
18
+ description: "Retrieve currently registered commands.",
19
+ }),
20
+ ),
21
+ )
22
+ .annotateMerge(
23
+ OpenApi.annotations({
24
+ title: "command",
25
+ description: "Experimental command routes.",
26
+ }),
27
+ )