@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,46 @@
1
+ import { Config } from "@zyro-sec/schema/config"
2
+ import { ConfigShell } from "@zyro-sec/schema/config/shell"
3
+ import { Schema } from "effect"
4
+ import { HttpApiEndpoint, HttpApiGroup, HttpApiSchema, OpenApi } from "effect/http-api"
5
+ import { LocationQuery, locationQueryOpenApi } from "./location.js"
6
+
7
+ export const ConfigGroup = HttpApiGroup.make("server.config")
8
+ .add(
9
+ HttpApiEndpoint.get("config.get", "/api/config", {
10
+ query: LocationQuery,
11
+ success: Schema.Array(Config.Entry),
12
+ })
13
+ .annotateMerge(locationQueryOpenApi)
14
+ .annotateMerge(
15
+ OpenApi.annotations({
16
+ identifier: "config.get",
17
+ summary: "Get configuration",
18
+ description:
19
+ "Return configuration documents and discovery sources for the requested location, from lowest to highest priority.",
20
+ }),
21
+ ),
22
+ )
23
+ .add(
24
+ HttpApiEndpoint.get("config.shells", "/api/config/shell", {
25
+ success: Schema.Array(ConfigShell.Option),
26
+ }).annotateMerge(
27
+ OpenApi.annotations({
28
+ identifier: "config.shells",
29
+ summary: "List available shells",
30
+ description: "Return shells available to terminal and agent execution.",
31
+ }),
32
+ ),
33
+ )
34
+ .add(
35
+ HttpApiEndpoint.patch("config.update", "/api/experimental/config", {
36
+ payload: Config.Patch,
37
+ success: HttpApiSchema.NoContent,
38
+ }).annotateMerge(
39
+ OpenApi.annotations({
40
+ identifier: "experimental.config.update",
41
+ summary: "Update global configuration",
42
+ description: "Patch supported fields in the highest-precedence global configuration document.",
43
+ }),
44
+ ),
45
+ )
46
+ .annotateMerge(OpenApi.annotations({ title: "config", description: "Location-scoped configuration routes." }))
@@ -0,0 +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
+ )
@@ -0,0 +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" }))
@@ -0,0 +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.")
@@ -0,0 +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
+ )
@@ -0,0 +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." }))
@@ -0,0 +1,136 @@
1
+ import { FileSystem } from "@zyro-sec/schema/filesystem"
2
+ import { Location } from "@zyro-sec/schema/location"
3
+ import { PositiveInt } from "@zyro-sec/schema/schema"
4
+ import { Schema } from "effect"
5
+ import { HttpApiEndpoint, HttpApiGroup, HttpApiSchema, OpenApi } from "effect/http-api"
6
+ import { FileNotFoundError, ServiceUnavailableError } from "../errors.js"
7
+ import { LocationQuery, locationQueryOpenApi } from "./location.js"
8
+
9
+ const ListQuery = Schema.Struct({
10
+ ...LocationQuery.fields,
11
+ path: Schema.String.pipe(Schema.optional).annotate({
12
+ description: "An absolute path or a path relative to the requested location. Defaults to the location directory.",
13
+ }),
14
+ })
15
+
16
+ const WriteQuery = Schema.Struct({
17
+ ...LocationQuery.fields,
18
+ path: Schema.String.annotate({
19
+ description:
20
+ "An absolute path or a path relative to the requested location. Missing parent directories are created.",
21
+ }),
22
+ })
23
+
24
+ const WatchPayload = Schema.Struct({
25
+ path: Schema.String.annotate({ description: "A file path relative to the requested location." }),
26
+ })
27
+
28
+ const FindQuery = Schema.Struct({
29
+ ...LocationQuery.fields,
30
+ query: FileSystem.FindInput.fields.query,
31
+ type: FileSystem.FindInput.fields.type,
32
+ limit: Schema.NumberFromString.pipe(Schema.decodeTo(PositiveInt), Schema.optional),
33
+ })
34
+
35
+ export const FileSystemGroup = HttpApiGroup.make("server.fs")
36
+ .add(
37
+ HttpApiEndpoint.get("fs.read", "/api/fs/read/*", {
38
+ query: LocationQuery,
39
+ success: Schema.Uint8Array.pipe(HttpApiSchema.asUint8Array()),
40
+ error: FileNotFoundError,
41
+ })
42
+ .annotateMerge(locationQueryOpenApi)
43
+ .annotateMerge(
44
+ OpenApi.annotations({
45
+ identifier: "fs.read",
46
+ summary: "Read file",
47
+ description:
48
+ "Stream one file relative to the requested location with ETag, Last-Modified, and single-range HTTP Range support (206 Partial Content, 416 Range Not Satisfiable, and 304 Not Modified; multi-range and malformed Range headers fall back to 200).",
49
+ }),
50
+ ),
51
+ )
52
+ .add(
53
+ HttpApiEndpoint.get("fs.list", "/api/fs/list", {
54
+ query: ListQuery,
55
+ success: Location.response(Schema.Array(FileSystem.Entry)),
56
+ error: FileNotFoundError,
57
+ })
58
+ .annotateMerge(locationQueryOpenApi)
59
+ .annotateMerge(
60
+ OpenApi.annotations({
61
+ identifier: "fs.list",
62
+ summary: "List directory",
63
+ description:
64
+ "List direct children using an absolute path or a path relative to the requested location, including parents and siblings outside its directory. Entry paths remain relative to the requested location; listing does not switch locations.",
65
+ }),
66
+ ),
67
+ )
68
+ .add(
69
+ HttpApiEndpoint.get("fs.find", "/api/fs/find", {
70
+ query: FindQuery,
71
+ success: Location.response(Schema.Array(FileSystem.Entry)),
72
+ })
73
+ .annotateMerge(locationQueryOpenApi)
74
+ .annotateMerge(
75
+ OpenApi.annotations({
76
+ identifier: "fs.find",
77
+ summary: "Find files",
78
+ description: "Find recursively ranked filesystem entries relative to the requested location.",
79
+ }),
80
+ ),
81
+ )
82
+ .add(
83
+ HttpApiEndpoint.post("fs.write", "/api/experimental/fs/write", {
84
+ query: WriteQuery,
85
+ payload: Schema.Uint8Array.pipe(HttpApiSchema.asUint8Array()),
86
+ success: Location.response(FileSystem.Write),
87
+ })
88
+ .annotateMerge(locationQueryOpenApi)
89
+ .annotateMerge(
90
+ OpenApi.annotations({
91
+ identifier: "experimental.fs.write",
92
+ summary: "Write file",
93
+ description:
94
+ "Write the raw request body to an absolute path or a path relative to the requested location, creating parent directories, and return the resolved absolute path. Unlike read, the target is not confined to the location. Experimental: may change without compatibility guarantees.",
95
+ }),
96
+ ),
97
+ )
98
+ .add(
99
+ HttpApiEndpoint.post("fs.watch", "/api/experimental/fs/watch", {
100
+ query: LocationQuery,
101
+ payload: WatchPayload,
102
+ success: HttpApiSchema.NoContent,
103
+ error: [FileNotFoundError, ServiceUnavailableError],
104
+ })
105
+ .annotateMerge(locationQueryOpenApi)
106
+ .annotateMerge(
107
+ OpenApi.annotations({
108
+ identifier: "experimental.fs.watch",
109
+ summary: "Watch file",
110
+ description:
111
+ "Watch one file relative to the requested location for 24 hours, publishing filesystem.changed on that location when it changes. Watching an already watched file resets its expiry. Paths follow read confinement. Experimental: may change without compatibility guarantees.",
112
+ }),
113
+ ),
114
+ )
115
+ .add(
116
+ HttpApiEndpoint.delete("fs.unwatch", "/api/experimental/fs/watch", {
117
+ query: LocationQuery,
118
+ payload: WatchPayload,
119
+ success: HttpApiSchema.NoContent,
120
+ })
121
+ .annotateMerge(locationQueryOpenApi)
122
+ .annotateMerge(
123
+ OpenApi.annotations({
124
+ identifier: "experimental.fs.unwatch",
125
+ summary: "Unwatch file",
126
+ description:
127
+ "Stop watching one file relative to the requested location. Experimental: may change without compatibility guarantees.",
128
+ }),
129
+ ),
130
+ )
131
+ .annotateMerge(
132
+ OpenApi.annotations({
133
+ title: "filesystem",
134
+ description: "Experimental location-scoped filesystem routes.",
135
+ }),
136
+ )
@@ -0,0 +1,120 @@
1
+ import { Generate } from "@zyro-sec/schema/generate"
2
+ import { Model } from "@zyro-sec/schema/model"
3
+ import { Schema } from "effect"
4
+ import { HttpApiEndpoint, HttpApiGroup, OpenApi } from "effect/http-api"
5
+ import {
6
+ VideoNotFoundError,
7
+ InvalidRequestError,
8
+ LocationNotFoundError,
9
+ ModelNotFoundError,
10
+ ProviderNotFoundError,
11
+ ProviderRequestError,
12
+ ServiceUnavailableError,
13
+ UnsupportedModelError,
14
+ } from "../errors.js"
15
+
16
+ const errors = [
17
+ InvalidRequestError,
18
+ ProviderNotFoundError,
19
+ ModelNotFoundError,
20
+ UnsupportedModelError,
21
+ ProviderRequestError,
22
+ ServiceUnavailableError,
23
+ LocationNotFoundError,
24
+ ]
25
+
26
+ const textContract = {
27
+ payload: Schema.Struct({
28
+ prompt: Schema.String,
29
+ model: Model.Ref.pipe(Schema.optional),
30
+ }),
31
+ success: Schema.Struct({
32
+ data: Schema.Struct({ text: Schema.String }),
33
+ }).annotate({ identifier: "GenerateTextResponse" }),
34
+ error: errors,
35
+ }
36
+
37
+ export const GenerateGroup = HttpApiGroup.make("server.generate")
38
+ .add(
39
+ HttpApiEndpoint.post("generate.text", "/api/experimental/generate/text", textContract).annotateMerge(
40
+ OpenApi.annotations({
41
+ identifier: "experimental.generate.text",
42
+ summary: "Generate text",
43
+ description:
44
+ "Run one stateless model generation using the server's base configuration and return the assistant text. Uses the base configuration's default model when none is specified.",
45
+ }),
46
+ ),
47
+ )
48
+ // Kept so clients built before the move to /generate/text keep working; omitted from generated clients.
49
+ .add(
50
+ HttpApiEndpoint.post("generate.textLegacy", "/api/experimental/generate", textContract).annotateMerge(
51
+ OpenApi.annotations({
52
+ identifier: "experimental.generate.textLegacy",
53
+ summary: "Generate text (deprecated path)",
54
+ description: "Deprecated alias of POST /api/experimental/generate/text.",
55
+ deprecated: true,
56
+ }),
57
+ ),
58
+ )
59
+ .add(
60
+ HttpApiEndpoint.post("generate.image", "/api/experimental/generate/image", {
61
+ payload: Generate.ImageRequest,
62
+ success: Schema.Struct({ data: Generate.ImageResult }).annotate({ identifier: "GenerateImageResponse" }),
63
+ error: errors,
64
+ }).annotateMerge(
65
+ OpenApi.annotations({
66
+ identifier: "experimental.generate.image",
67
+ summary: "Generate images",
68
+ description:
69
+ "Generate or edit images with an image model using the server's base configuration and return them as base64. Stateless: nothing is stored.",
70
+ }),
71
+ ),
72
+ )
73
+ .add(
74
+ HttpApiEndpoint.post("generate.video.create", "/api/experimental/generate/video", {
75
+ payload: Generate.VideoRequest,
76
+ success: Schema.Struct({ data: Generate.VideoRunning }).annotate({ identifier: "GenerateVideoCreateResponse" }),
77
+ error: errors,
78
+ }).annotateMerge(
79
+ OpenApi.annotations({
80
+ identifier: "experimental.generate.video.create",
81
+ summary: "Create a video generation",
82
+ description:
83
+ "Submit a video job to a video model using the server's base configuration and return its ID once the provider accepted it. The server polls the job and stores the finished videos as blobs; read the job with GET /api/experimental/generate/video/:id and the video with GET /api/experimental/blob/:id. Experimental: may change without compatibility guarantees.",
84
+ }),
85
+ ),
86
+ )
87
+ .add(
88
+ HttpApiEndpoint.get("generate.video.get", "/api/experimental/generate/video/:id", {
89
+ params: { id: Generate.VideoID },
90
+ success: Schema.Struct({ data: Generate.VideoJob }).annotate({ identifier: "GenerateVideoGetResponse" }),
91
+ error: [VideoNotFoundError, LocationNotFoundError],
92
+ }).annotateMerge(
93
+ OpenApi.annotations({
94
+ identifier: "experimental.generate.video.get",
95
+ summary: "Read a video generation",
96
+ description:
97
+ "Read a video job: running, completed with its videos' blobs, or error with a reason. Jobs survive a server restart, which resumes polling running ones. A job is not found 24 hours after it finished, or once none of its blobs remain. Experimental: may change without compatibility guarantees.",
98
+ }),
99
+ ),
100
+ )
101
+ .add(
102
+ HttpApiEndpoint.post("generate.decisions", "/api/experimental/generate/decisions", {
103
+ payload: Generate.DecisionRequest,
104
+ success: Schema.Struct({ data: Generate.DecisionResult }).annotate({ identifier: "GenerateDecisionsResponse" }),
105
+ error: errors,
106
+ }).annotateMerge(
107
+ OpenApi.annotations({
108
+ identifier: "experimental.generate.decisions",
109
+ summary: "Generate decisions",
110
+ description:
111
+ "Ask a decision model typed predicate, choice and score questions about the input and return one probability-bearing answer per question, in question order. Stateless: nothing is stored.",
112
+ }),
113
+ ),
114
+ )
115
+ .annotateMerge(
116
+ OpenApi.annotations({
117
+ title: "generate",
118
+ description: "Experimental one-shot generation routes.",
119
+ }),
120
+ )