@zyro-sec/protocol 1.0.2 → 1.0.4
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/mcp.ts
CHANGED
|
@@ -1,167 +1,167 @@
|
|
|
1
|
-
import { Mcp } from "@zyro-sec/schema/mcp"
|
|
2
|
-
import { Location } from "@zyro-sec/schema/location"
|
|
3
|
-
import { PtyTicket } from "@zyro-sec/schema/pty-ticket"
|
|
4
|
-
import { Context, Schema } from "effect"
|
|
5
|
-
import { HttpApiEndpoint, HttpApiGroup, HttpApiMiddleware, HttpApiSchema, OpenApi } from "effect/http-api"
|
|
6
|
-
import { ForbiddenError, LocationNotFoundError, McpServerNotFoundError } from "../errors.js"
|
|
7
|
-
import { LocationQuery, locationQueryOpenApi } from "./location.js"
|
|
8
|
-
import { PTY_CONNECT_TICKET_QUERY, PTY_CONNECT_TOKEN_HEADER, PTY_CONNECT_TOKEN_HEADER_VALUE } from "./pty.js"
|
|
9
|
-
|
|
10
|
-
export const MCP_CLIENT_PATH = "/api/experimental/client-mcp"
|
|
11
|
-
|
|
12
|
-
export function hasMcpClientTicketURL(url: URL) {
|
|
13
|
-
return url.pathname === MCP_CLIENT_PATH && !!url.searchParams.get(PTY_CONNECT_TICKET_QUERY)
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
const McpClientQuery = Schema.Struct({
|
|
17
|
-
...LocationQuery.fields,
|
|
18
|
-
name: Schema.String.check(Schema.isPattern(/^[a-zA-Z0-9_-]+$/)).annotateKey({
|
|
19
|
-
description: "Name of the MCP server the client hosts.",
|
|
20
|
-
}),
|
|
21
|
-
})
|
|
22
|
-
|
|
23
|
-
export const makeMcpGroup = <LocationId extends HttpApiMiddleware.AnyId, LocationService>(
|
|
24
|
-
locationMiddleware: Context.Key<LocationId, LocationService>,
|
|
25
|
-
) =>
|
|
26
|
-
HttpApiGroup.make("server.mcp")
|
|
27
|
-
.add(
|
|
28
|
-
HttpApiEndpoint.get("mcp.list", "/api/mcp", {
|
|
29
|
-
query: LocationQuery,
|
|
30
|
-
success: Location.response(Schema.Array(Mcp.Server)),
|
|
31
|
-
})
|
|
32
|
-
.annotateMerge(locationQueryOpenApi)
|
|
33
|
-
.annotateMerge(
|
|
34
|
-
OpenApi.annotations({
|
|
35
|
-
identifier: "mcp.list",
|
|
36
|
-
summary: "List MCP servers",
|
|
37
|
-
description: "Retrieve configured MCP servers and their connection status.",
|
|
38
|
-
}),
|
|
39
|
-
),
|
|
40
|
-
)
|
|
41
|
-
.add(
|
|
42
|
-
HttpApiEndpoint.put("mcp.add", "/api/experimental/mcp/:server", {
|
|
43
|
-
params: { server: Schema.String },
|
|
44
|
-
query: LocationQuery,
|
|
45
|
-
// Wrapped in a struct because the client codegen flattens payload fields and cannot
|
|
46
|
-
// represent a top-level union payload.
|
|
47
|
-
payload: Schema.Struct({ config: Mcp.ServerConfig }),
|
|
48
|
-
success: HttpApiSchema.NoContent,
|
|
49
|
-
})
|
|
50
|
-
.annotateMerge(locationQueryOpenApi)
|
|
51
|
-
.annotateMerge(
|
|
52
|
-
OpenApi.annotations({
|
|
53
|
-
identifier: "experimental.mcp.add",
|
|
54
|
-
summary: "Add MCP server",
|
|
55
|
-
description: "Add an MCP server at runtime or replace an existing one, connecting it immediately.",
|
|
56
|
-
}),
|
|
57
|
-
),
|
|
58
|
-
)
|
|
59
|
-
.add(
|
|
60
|
-
HttpApiEndpoint.delete("mcp.remove", "/api/experimental/mcp/:server", {
|
|
61
|
-
params: { server: Schema.String },
|
|
62
|
-
query: LocationQuery,
|
|
63
|
-
success: HttpApiSchema.NoContent,
|
|
64
|
-
error: McpServerNotFoundError,
|
|
65
|
-
})
|
|
66
|
-
.annotateMerge(locationQueryOpenApi)
|
|
67
|
-
.annotateMerge(
|
|
68
|
-
OpenApi.annotations({
|
|
69
|
-
identifier: "experimental.mcp.remove",
|
|
70
|
-
summary: "Remove MCP server",
|
|
71
|
-
description: "Stop an MCP server and remove it from the runtime set until restart.",
|
|
72
|
-
}),
|
|
73
|
-
),
|
|
74
|
-
)
|
|
75
|
-
.add(
|
|
76
|
-
HttpApiEndpoint.post("mcp.connect", "/api/experimental/mcp/:server/connect", {
|
|
77
|
-
params: { server: Schema.String },
|
|
78
|
-
query: LocationQuery,
|
|
79
|
-
success: HttpApiSchema.NoContent,
|
|
80
|
-
error: McpServerNotFoundError,
|
|
81
|
-
})
|
|
82
|
-
.annotateMerge(locationQueryOpenApi)
|
|
83
|
-
.annotateMerge(
|
|
84
|
-
OpenApi.annotations({
|
|
85
|
-
identifier: "experimental.mcp.connect",
|
|
86
|
-
summary: "Connect MCP server",
|
|
87
|
-
description: "Connect an MCP server at runtime, overriding a disabled configuration until restart.",
|
|
88
|
-
}),
|
|
89
|
-
),
|
|
90
|
-
)
|
|
91
|
-
.add(
|
|
92
|
-
HttpApiEndpoint.post("mcp.disconnect", "/api/experimental/mcp/:server/disconnect", {
|
|
93
|
-
params: { server: Schema.String },
|
|
94
|
-
query: LocationQuery,
|
|
95
|
-
success: HttpApiSchema.NoContent,
|
|
96
|
-
error: McpServerNotFoundError,
|
|
97
|
-
})
|
|
98
|
-
.annotateMerge(locationQueryOpenApi)
|
|
99
|
-
.annotateMerge(
|
|
100
|
-
OpenApi.annotations({
|
|
101
|
-
identifier: "experimental.mcp.disconnect",
|
|
102
|
-
summary: "Disconnect MCP server",
|
|
103
|
-
description: "Disconnect an MCP server at runtime, removing its tools until reconnected.",
|
|
104
|
-
}),
|
|
105
|
-
),
|
|
106
|
-
)
|
|
107
|
-
.add(
|
|
108
|
-
HttpApiEndpoint.get("mcp.resource.catalog", "/api/mcp/resource", {
|
|
109
|
-
query: LocationQuery,
|
|
110
|
-
success: Location.response(Mcp.ResourceCatalog),
|
|
111
|
-
})
|
|
112
|
-
.annotateMerge(locationQueryOpenApi)
|
|
113
|
-
.annotateMerge(
|
|
114
|
-
OpenApi.annotations({
|
|
115
|
-
identifier: "mcp.resource.catalog",
|
|
116
|
-
summary: "List MCP resources",
|
|
117
|
-
description: "Retrieve resources and resource templates from connected MCP servers.",
|
|
118
|
-
}),
|
|
119
|
-
),
|
|
120
|
-
)
|
|
121
|
-
.add(
|
|
122
|
-
HttpApiEndpoint.post("mcp.clientToken", `${MCP_CLIENT_PATH}/token`, {
|
|
123
|
-
query: McpClientQuery,
|
|
124
|
-
headers: Schema.Struct({
|
|
125
|
-
[PTY_CONNECT_TOKEN_HEADER]: Schema.optional(Schema.String).annotateKey({
|
|
126
|
-
description: `Must be ${PTY_CONNECT_TOKEN_HEADER_VALUE}; requests without it are refused.`,
|
|
127
|
-
}),
|
|
128
|
-
}),
|
|
129
|
-
success: Location.response(PtyTicket.ConnectToken),
|
|
130
|
-
error: ForbiddenError,
|
|
131
|
-
})
|
|
132
|
-
.annotateMerge(locationQueryOpenApi)
|
|
133
|
-
.annotateMerge(
|
|
134
|
-
OpenApi.annotations({
|
|
135
|
-
identifier: "experimental.mcp.client.token",
|
|
136
|
-
summary: "Create client MCP WebSocket token",
|
|
137
|
-
description:
|
|
138
|
-
"Create a short-lived single-use ticket for opening a client MCP WebSocket connection from a browser.",
|
|
139
|
-
}),
|
|
140
|
-
),
|
|
141
|
-
)
|
|
142
|
-
// The client handler checks origin and ticket before it boots the location itself.
|
|
143
|
-
.middleware(locationMiddleware)
|
|
144
|
-
.add(
|
|
145
|
-
HttpApiEndpoint.get("mcp.client", MCP_CLIENT_PATH, {
|
|
146
|
-
query: Schema.Struct({
|
|
147
|
-
...McpClientQuery.fields,
|
|
148
|
-
[PTY_CONNECT_TICKET_QUERY]: Schema.optional(Schema.String).annotateKey({
|
|
149
|
-
description:
|
|
150
|
-
"Single-use ticket from experimental.mcp.client.token, which authorizes the connection without the usual credentials.",
|
|
151
|
-
}),
|
|
152
|
-
}),
|
|
153
|
-
success: Schema.Boolean,
|
|
154
|
-
error: [ForbiddenError, LocationNotFoundError],
|
|
155
|
-
})
|
|
156
|
-
.annotateMerge(locationQueryOpenApi)
|
|
157
|
-
.annotateMerge(
|
|
158
|
-
OpenApi.annotations({
|
|
159
|
-
identifier: "experimental.mcp.client",
|
|
160
|
-
summary: "Attach client MCP server",
|
|
161
|
-
description:
|
|
162
|
-
"Upgrade to a WebSocket over which the client hosts an MCP server named after `name`; its tools stay available while the socket is open. One JSON-RPC message per text frame. Experimental: may change without compatibility guarantees.",
|
|
163
|
-
transform: (operation) => ({ ...operation, "x-websocket": true }),
|
|
164
|
-
}),
|
|
165
|
-
),
|
|
166
|
-
)
|
|
167
|
-
.annotateMerge(OpenApi.annotations({ title: "mcp", description: "MCP server and resource routes." }))
|
|
1
|
+
import { Mcp } from "@zyro-sec/schema/mcp"
|
|
2
|
+
import { Location } from "@zyro-sec/schema/location"
|
|
3
|
+
import { PtyTicket } from "@zyro-sec/schema/pty-ticket"
|
|
4
|
+
import { Context, Schema } from "effect"
|
|
5
|
+
import { HttpApiEndpoint, HttpApiGroup, HttpApiMiddleware, HttpApiSchema, OpenApi } from "effect/http-api"
|
|
6
|
+
import { ForbiddenError, LocationNotFoundError, McpServerNotFoundError } from "../errors.js"
|
|
7
|
+
import { LocationQuery, locationQueryOpenApi } from "./location.js"
|
|
8
|
+
import { PTY_CONNECT_TICKET_QUERY, PTY_CONNECT_TOKEN_HEADER, PTY_CONNECT_TOKEN_HEADER_VALUE } from "./pty.js"
|
|
9
|
+
|
|
10
|
+
export const MCP_CLIENT_PATH = "/api/experimental/client-mcp"
|
|
11
|
+
|
|
12
|
+
export function hasMcpClientTicketURL(url: URL) {
|
|
13
|
+
return url.pathname === MCP_CLIENT_PATH && !!url.searchParams.get(PTY_CONNECT_TICKET_QUERY)
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const McpClientQuery = Schema.Struct({
|
|
17
|
+
...LocationQuery.fields,
|
|
18
|
+
name: Schema.String.check(Schema.isPattern(/^[a-zA-Z0-9_-]+$/)).annotateKey({
|
|
19
|
+
description: "Name of the MCP server the client hosts.",
|
|
20
|
+
}),
|
|
21
|
+
})
|
|
22
|
+
|
|
23
|
+
export const makeMcpGroup = <LocationId extends HttpApiMiddleware.AnyId, LocationService>(
|
|
24
|
+
locationMiddleware: Context.Key<LocationId, LocationService>,
|
|
25
|
+
) =>
|
|
26
|
+
HttpApiGroup.make("server.mcp")
|
|
27
|
+
.add(
|
|
28
|
+
HttpApiEndpoint.get("mcp.list", "/api/mcp", {
|
|
29
|
+
query: LocationQuery,
|
|
30
|
+
success: Location.response(Schema.Array(Mcp.Server)),
|
|
31
|
+
})
|
|
32
|
+
.annotateMerge(locationQueryOpenApi)
|
|
33
|
+
.annotateMerge(
|
|
34
|
+
OpenApi.annotations({
|
|
35
|
+
identifier: "mcp.list",
|
|
36
|
+
summary: "List MCP servers",
|
|
37
|
+
description: "Retrieve configured MCP servers and their connection status.",
|
|
38
|
+
}),
|
|
39
|
+
),
|
|
40
|
+
)
|
|
41
|
+
.add(
|
|
42
|
+
HttpApiEndpoint.put("mcp.add", "/api/experimental/mcp/:server", {
|
|
43
|
+
params: { server: Schema.String },
|
|
44
|
+
query: LocationQuery,
|
|
45
|
+
// Wrapped in a struct because the client codegen flattens payload fields and cannot
|
|
46
|
+
// represent a top-level union payload.
|
|
47
|
+
payload: Schema.Struct({ config: Mcp.ServerConfig }),
|
|
48
|
+
success: HttpApiSchema.NoContent,
|
|
49
|
+
})
|
|
50
|
+
.annotateMerge(locationQueryOpenApi)
|
|
51
|
+
.annotateMerge(
|
|
52
|
+
OpenApi.annotations({
|
|
53
|
+
identifier: "experimental.mcp.add",
|
|
54
|
+
summary: "Add MCP server",
|
|
55
|
+
description: "Add an MCP server at runtime or replace an existing one, connecting it immediately.",
|
|
56
|
+
}),
|
|
57
|
+
),
|
|
58
|
+
)
|
|
59
|
+
.add(
|
|
60
|
+
HttpApiEndpoint.delete("mcp.remove", "/api/experimental/mcp/:server", {
|
|
61
|
+
params: { server: Schema.String },
|
|
62
|
+
query: LocationQuery,
|
|
63
|
+
success: HttpApiSchema.NoContent,
|
|
64
|
+
error: McpServerNotFoundError,
|
|
65
|
+
})
|
|
66
|
+
.annotateMerge(locationQueryOpenApi)
|
|
67
|
+
.annotateMerge(
|
|
68
|
+
OpenApi.annotations({
|
|
69
|
+
identifier: "experimental.mcp.remove",
|
|
70
|
+
summary: "Remove MCP server",
|
|
71
|
+
description: "Stop an MCP server and remove it from the runtime set until restart.",
|
|
72
|
+
}),
|
|
73
|
+
),
|
|
74
|
+
)
|
|
75
|
+
.add(
|
|
76
|
+
HttpApiEndpoint.post("mcp.connect", "/api/experimental/mcp/:server/connect", {
|
|
77
|
+
params: { server: Schema.String },
|
|
78
|
+
query: LocationQuery,
|
|
79
|
+
success: HttpApiSchema.NoContent,
|
|
80
|
+
error: McpServerNotFoundError,
|
|
81
|
+
})
|
|
82
|
+
.annotateMerge(locationQueryOpenApi)
|
|
83
|
+
.annotateMerge(
|
|
84
|
+
OpenApi.annotations({
|
|
85
|
+
identifier: "experimental.mcp.connect",
|
|
86
|
+
summary: "Connect MCP server",
|
|
87
|
+
description: "Connect an MCP server at runtime, overriding a disabled configuration until restart.",
|
|
88
|
+
}),
|
|
89
|
+
),
|
|
90
|
+
)
|
|
91
|
+
.add(
|
|
92
|
+
HttpApiEndpoint.post("mcp.disconnect", "/api/experimental/mcp/:server/disconnect", {
|
|
93
|
+
params: { server: Schema.String },
|
|
94
|
+
query: LocationQuery,
|
|
95
|
+
success: HttpApiSchema.NoContent,
|
|
96
|
+
error: McpServerNotFoundError,
|
|
97
|
+
})
|
|
98
|
+
.annotateMerge(locationQueryOpenApi)
|
|
99
|
+
.annotateMerge(
|
|
100
|
+
OpenApi.annotations({
|
|
101
|
+
identifier: "experimental.mcp.disconnect",
|
|
102
|
+
summary: "Disconnect MCP server",
|
|
103
|
+
description: "Disconnect an MCP server at runtime, removing its tools until reconnected.",
|
|
104
|
+
}),
|
|
105
|
+
),
|
|
106
|
+
)
|
|
107
|
+
.add(
|
|
108
|
+
HttpApiEndpoint.get("mcp.resource.catalog", "/api/mcp/resource", {
|
|
109
|
+
query: LocationQuery,
|
|
110
|
+
success: Location.response(Mcp.ResourceCatalog),
|
|
111
|
+
})
|
|
112
|
+
.annotateMerge(locationQueryOpenApi)
|
|
113
|
+
.annotateMerge(
|
|
114
|
+
OpenApi.annotations({
|
|
115
|
+
identifier: "mcp.resource.catalog",
|
|
116
|
+
summary: "List MCP resources",
|
|
117
|
+
description: "Retrieve resources and resource templates from connected MCP servers.",
|
|
118
|
+
}),
|
|
119
|
+
),
|
|
120
|
+
)
|
|
121
|
+
.add(
|
|
122
|
+
HttpApiEndpoint.post("mcp.clientToken", `${MCP_CLIENT_PATH}/token`, {
|
|
123
|
+
query: McpClientQuery,
|
|
124
|
+
headers: Schema.Struct({
|
|
125
|
+
[PTY_CONNECT_TOKEN_HEADER]: Schema.optional(Schema.String).annotateKey({
|
|
126
|
+
description: `Must be ${PTY_CONNECT_TOKEN_HEADER_VALUE}; requests without it are refused.`,
|
|
127
|
+
}),
|
|
128
|
+
}),
|
|
129
|
+
success: Location.response(PtyTicket.ConnectToken),
|
|
130
|
+
error: ForbiddenError,
|
|
131
|
+
})
|
|
132
|
+
.annotateMerge(locationQueryOpenApi)
|
|
133
|
+
.annotateMerge(
|
|
134
|
+
OpenApi.annotations({
|
|
135
|
+
identifier: "experimental.mcp.client.token",
|
|
136
|
+
summary: "Create client MCP WebSocket token",
|
|
137
|
+
description:
|
|
138
|
+
"Create a short-lived single-use ticket for opening a client MCP WebSocket connection from a browser.",
|
|
139
|
+
}),
|
|
140
|
+
),
|
|
141
|
+
)
|
|
142
|
+
// The client handler checks origin and ticket before it boots the location itself.
|
|
143
|
+
.middleware(locationMiddleware)
|
|
144
|
+
.add(
|
|
145
|
+
HttpApiEndpoint.get("mcp.client", MCP_CLIENT_PATH, {
|
|
146
|
+
query: Schema.Struct({
|
|
147
|
+
...McpClientQuery.fields,
|
|
148
|
+
[PTY_CONNECT_TICKET_QUERY]: Schema.optional(Schema.String).annotateKey({
|
|
149
|
+
description:
|
|
150
|
+
"Single-use ticket from experimental.mcp.client.token, which authorizes the connection without the usual credentials.",
|
|
151
|
+
}),
|
|
152
|
+
}),
|
|
153
|
+
success: Schema.Boolean,
|
|
154
|
+
error: [ForbiddenError, LocationNotFoundError],
|
|
155
|
+
})
|
|
156
|
+
.annotateMerge(locationQueryOpenApi)
|
|
157
|
+
.annotateMerge(
|
|
158
|
+
OpenApi.annotations({
|
|
159
|
+
identifier: "experimental.mcp.client",
|
|
160
|
+
summary: "Attach client MCP server",
|
|
161
|
+
description:
|
|
162
|
+
"Upgrade to a WebSocket over which the client hosts an MCP server named after `name`; its tools stay available while the socket is open. One JSON-RPC message per text frame. Experimental: may change without compatibility guarantees.",
|
|
163
|
+
transform: (operation) => ({ ...operation, "x-websocket": true }),
|
|
164
|
+
}),
|
|
165
|
+
),
|
|
166
|
+
)
|
|
167
|
+
.annotateMerge(OpenApi.annotations({ title: "mcp", description: "MCP server and resource routes." }))
|
package/src/groups/media.ts
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
import { Schema } from "effect"
|
|
2
|
-
import { HttpApiEndpoint, HttpApiSchema, OpenApi } from "effect/http-api"
|
|
3
|
-
import { FileNotFoundError, InvalidRequestError } from "../errors.js"
|
|
4
|
-
|
|
5
|
-
export const MediaHash = Schema.String.check(Schema.isPattern(/^[0-9a-f]{64}$/u)).annotate({
|
|
6
|
-
identifier: "MediaHash",
|
|
7
|
-
})
|
|
8
|
-
|
|
9
|
-
/** Lives in the `server.experimental` group (see `groups/experimental.ts`). */
|
|
10
|
-
export const MediaGetEndpoint = HttpApiEndpoint.get("media.get", "/api/experimental/media/:hash", {
|
|
11
|
-
params: { hash: MediaHash },
|
|
12
|
-
success: Schema.Uint8Array.pipe(HttpApiSchema.asUint8Array()),
|
|
13
|
-
error: [FileNotFoundError, InvalidRequestError],
|
|
14
|
-
}).annotateMerge(
|
|
15
|
-
OpenApi.annotations({
|
|
16
|
-
identifier: "experimental.media.get",
|
|
17
|
-
summary: "Read media blob",
|
|
18
|
-
description:
|
|
19
|
-
"Read a content-addressed media blob by SHA-256 hash with immutable Cache-Control, ETag, and 304 Not Modified support. Only blobs a stored message or inbox item still references are served. Experimental: may change without compatibility guarantees.",
|
|
20
|
-
// The route shares the `server.experimental` group with the persistent PTY prototype; tag it on its own.
|
|
21
|
-
transform: (operation) => ({ ...operation, tags: ["experimental"] }),
|
|
22
|
-
}),
|
|
23
|
-
)
|
|
1
|
+
import { Schema } from "effect"
|
|
2
|
+
import { HttpApiEndpoint, HttpApiSchema, OpenApi } from "effect/http-api"
|
|
3
|
+
import { FileNotFoundError, InvalidRequestError } from "../errors.js"
|
|
4
|
+
|
|
5
|
+
export const MediaHash = Schema.String.check(Schema.isPattern(/^[0-9a-f]{64}$/u)).annotate({
|
|
6
|
+
identifier: "MediaHash",
|
|
7
|
+
})
|
|
8
|
+
|
|
9
|
+
/** Lives in the `server.experimental` group (see `groups/experimental.ts`). */
|
|
10
|
+
export const MediaGetEndpoint = HttpApiEndpoint.get("media.get", "/api/experimental/media/:hash", {
|
|
11
|
+
params: { hash: MediaHash },
|
|
12
|
+
success: Schema.Uint8Array.pipe(HttpApiSchema.asUint8Array()),
|
|
13
|
+
error: [FileNotFoundError, InvalidRequestError],
|
|
14
|
+
}).annotateMerge(
|
|
15
|
+
OpenApi.annotations({
|
|
16
|
+
identifier: "experimental.media.get",
|
|
17
|
+
summary: "Read media blob",
|
|
18
|
+
description:
|
|
19
|
+
"Read a content-addressed media blob by SHA-256 hash with immutable Cache-Control, ETag, and 304 Not Modified support. Only blobs a stored message or inbox item still references are served. Experimental: may change without compatibility guarantees.",
|
|
20
|
+
// The route shares the `server.experimental` group with the persistent PTY prototype; tag it on its own.
|
|
21
|
+
transform: (operation) => ({ ...operation, tags: ["experimental"] }),
|
|
22
|
+
}),
|
|
23
|
+
)
|
package/src/groups/message.ts
CHANGED
|
@@ -1,124 +1,124 @@
|
|
|
1
|
-
import { Session } from "@zyro-sec/schema/session"
|
|
2
|
-
import { SessionMessage } from "@zyro-sec/schema/session-message"
|
|
3
|
-
import { Location } from "@zyro-sec/schema/location"
|
|
4
|
-
import { Schema, Struct } from "effect"
|
|
5
|
-
import { HttpApiEndpoint, HttpApiGroup, OpenApi } from "effect/http-api"
|
|
6
|
-
import { InvalidCursorError, SessionNotFoundError, UnknownError } from "../errors.js"
|
|
7
|
-
|
|
8
|
-
// Keyed by message type so a new message type cannot be left out of the filter.
|
|
9
|
-
const MessageTypes = {
|
|
10
|
-
"agent-switched": true,
|
|
11
|
-
"model-switched": true,
|
|
12
|
-
"location-switched": true,
|
|
13
|
-
user: true,
|
|
14
|
-
synthetic: true,
|
|
15
|
-
system: true,
|
|
16
|
-
skill: true,
|
|
17
|
-
shell: true,
|
|
18
|
-
assistant: true,
|
|
19
|
-
compaction: true,
|
|
20
|
-
idle: true,
|
|
21
|
-
} satisfies Record<SessionMessage.Type, true>
|
|
22
|
-
|
|
23
|
-
export const SessionMessagesQuery = Schema.Struct({
|
|
24
|
-
limit: Schema.optional(
|
|
25
|
-
Schema.NumberFromString.check(Schema.isInt(), Schema.isGreaterThanOrEqualTo(1), Schema.isLessThanOrEqualTo(200)),
|
|
26
|
-
).annotate({
|
|
27
|
-
description: "Maximum number of messages to return. When omitted, the endpoint returns its default page size.",
|
|
28
|
-
}),
|
|
29
|
-
order: Schema.optional(Schema.Union([Schema.Literal("asc"), Schema.Literal("desc")])).annotate({
|
|
30
|
-
description: "Message order for the first page. Use desc for newest first or asc for oldest first.",
|
|
31
|
-
}),
|
|
32
|
-
cursor: Schema.optional(
|
|
33
|
-
Schema.String.annotate({
|
|
34
|
-
description:
|
|
35
|
-
"Opaque pagination cursor returned as cursor.previous or cursor.next in the previous response. Do not combine with order.",
|
|
36
|
-
}),
|
|
37
|
-
),
|
|
38
|
-
type: Schema.optional(Schema.Literals(Object.keys(MessageTypes) as ReadonlyArray<SessionMessage.Type>)).annotate({
|
|
39
|
-
description:
|
|
40
|
-
"Filter by message type before pagination. When omitted, all message types are returned. Pass the same type when following cursors.",
|
|
41
|
-
}),
|
|
42
|
-
}).annotate({ identifier: "SessionMessagesQuery" })
|
|
43
|
-
|
|
44
|
-
const PublicLocationSwitched = Schema.Struct({
|
|
45
|
-
...Struct.omit(SessionMessage.LocationSwitched.fields, ["location", "previous"]),
|
|
46
|
-
location: Location.PublicRef,
|
|
47
|
-
previous: Schema.Struct({
|
|
48
|
-
location: Location.PublicRef,
|
|
49
|
-
projectID: SessionMessage.LocationSwitched.fields.projectID,
|
|
50
|
-
subpath: SessionMessage.LocationSwitched.fields.subpath,
|
|
51
|
-
}).pipe(Schema.optional),
|
|
52
|
-
}).annotate({ identifier: "Session.Message.LocationSwitched" })
|
|
53
|
-
|
|
54
|
-
export const PublicSessionMessage = Schema.Union([
|
|
55
|
-
SessionMessage.AgentSelected,
|
|
56
|
-
SessionMessage.ModelSelected,
|
|
57
|
-
PublicLocationSwitched,
|
|
58
|
-
SessionMessage.User,
|
|
59
|
-
SessionMessage.Synthetic,
|
|
60
|
-
SessionMessage.System,
|
|
61
|
-
SessionMessage.Skill,
|
|
62
|
-
SessionMessage.Shell,
|
|
63
|
-
SessionMessage.Assistant,
|
|
64
|
-
SessionMessage.Compaction,
|
|
65
|
-
SessionMessage.Idle,
|
|
66
|
-
]).annotate({ identifier: "Session.Message.Info" })
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* Experimental: {@link PublicSessionMessage} as sent to clients that opt in with `X-OpenCode-Capabilities:
|
|
70
|
-
* experimental-media-uri` while `experimental.media_blob` is on. User files stored in `blob` stay `media:` refs.
|
|
71
|
-
*/
|
|
72
|
-
export const PublicMediaSessionMessage = Schema.Union([
|
|
73
|
-
SessionMessage.AgentSelected,
|
|
74
|
-
SessionMessage.ModelSelected,
|
|
75
|
-
PublicLocationSwitched,
|
|
76
|
-
SessionMessage.MediaUser,
|
|
77
|
-
SessionMessage.Synthetic,
|
|
78
|
-
SessionMessage.System,
|
|
79
|
-
SessionMessage.Skill,
|
|
80
|
-
SessionMessage.Shell,
|
|
81
|
-
SessionMessage.Assistant,
|
|
82
|
-
SessionMessage.Compaction,
|
|
83
|
-
SessionMessage.Idle,
|
|
84
|
-
]).annotate({ identifier: "Session.Message.MediaInfo" })
|
|
85
|
-
|
|
86
|
-
const MessagesCursor = Schema.Struct({
|
|
87
|
-
previous: Schema.String.pipe(Schema.optional),
|
|
88
|
-
next: Schema.String.pipe(Schema.optional),
|
|
89
|
-
})
|
|
90
|
-
|
|
91
|
-
/** Experimental: the `session.messages` response for clients that opt into `experimental-media-uri`. */
|
|
92
|
-
export const SessionMediaMessagesResponse = Schema.Struct({
|
|
93
|
-
data: Schema.Array(PublicMediaSessionMessage),
|
|
94
|
-
cursor: MessagesCursor,
|
|
95
|
-
})
|
|
96
|
-
|
|
97
|
-
/** Experimental: the `session.message` response for clients that opt into `experimental-media-uri`. */
|
|
98
|
-
export const SessionMediaMessageResponse = Schema.Struct({ data: PublicMediaSessionMessage })
|
|
99
|
-
|
|
100
|
-
export const MessageGroup = HttpApiGroup.make("server.message")
|
|
101
|
-
.add(
|
|
102
|
-
HttpApiEndpoint.get("session.messages", "/api/session/:sessionID/message", {
|
|
103
|
-
params: { sessionID: Session.ID },
|
|
104
|
-
query: SessionMessagesQuery,
|
|
105
|
-
success: Schema.Struct({
|
|
106
|
-
data: Schema.Array(PublicSessionMessage),
|
|
107
|
-
cursor: MessagesCursor,
|
|
108
|
-
}).annotate({ identifier: "SessionMessagesResponse" }),
|
|
109
|
-
error: [InvalidCursorError, SessionNotFoundError, UnknownError],
|
|
110
|
-
}).annotateMerge(
|
|
111
|
-
OpenApi.annotations({
|
|
112
|
-
identifier: "session.message.list",
|
|
113
|
-
summary: "Get session messages",
|
|
114
|
-
description:
|
|
115
|
-
"List a session's messages, optionally filtered by type. Follow cursor.next or cursor.previous with the same type filter. Items still in the inbox aren't included.",
|
|
116
|
-
}),
|
|
117
|
-
),
|
|
118
|
-
)
|
|
119
|
-
.annotateMerge(
|
|
120
|
-
OpenApi.annotations({
|
|
121
|
-
title: "session",
|
|
122
|
-
description: "Experimental message routes.",
|
|
123
|
-
}),
|
|
124
|
-
)
|
|
1
|
+
import { Session } from "@zyro-sec/schema/session"
|
|
2
|
+
import { SessionMessage } from "@zyro-sec/schema/session-message"
|
|
3
|
+
import { Location } from "@zyro-sec/schema/location"
|
|
4
|
+
import { Schema, Struct } from "effect"
|
|
5
|
+
import { HttpApiEndpoint, HttpApiGroup, OpenApi } from "effect/http-api"
|
|
6
|
+
import { InvalidCursorError, SessionNotFoundError, UnknownError } from "../errors.js"
|
|
7
|
+
|
|
8
|
+
// Keyed by message type so a new message type cannot be left out of the filter.
|
|
9
|
+
const MessageTypes = {
|
|
10
|
+
"agent-switched": true,
|
|
11
|
+
"model-switched": true,
|
|
12
|
+
"location-switched": true,
|
|
13
|
+
user: true,
|
|
14
|
+
synthetic: true,
|
|
15
|
+
system: true,
|
|
16
|
+
skill: true,
|
|
17
|
+
shell: true,
|
|
18
|
+
assistant: true,
|
|
19
|
+
compaction: true,
|
|
20
|
+
idle: true,
|
|
21
|
+
} satisfies Record<SessionMessage.Type, true>
|
|
22
|
+
|
|
23
|
+
export const SessionMessagesQuery = Schema.Struct({
|
|
24
|
+
limit: Schema.optional(
|
|
25
|
+
Schema.NumberFromString.check(Schema.isInt(), Schema.isGreaterThanOrEqualTo(1), Schema.isLessThanOrEqualTo(200)),
|
|
26
|
+
).annotate({
|
|
27
|
+
description: "Maximum number of messages to return. When omitted, the endpoint returns its default page size.",
|
|
28
|
+
}),
|
|
29
|
+
order: Schema.optional(Schema.Union([Schema.Literal("asc"), Schema.Literal("desc")])).annotate({
|
|
30
|
+
description: "Message order for the first page. Use desc for newest first or asc for oldest first.",
|
|
31
|
+
}),
|
|
32
|
+
cursor: Schema.optional(
|
|
33
|
+
Schema.String.annotate({
|
|
34
|
+
description:
|
|
35
|
+
"Opaque pagination cursor returned as cursor.previous or cursor.next in the previous response. Do not combine with order.",
|
|
36
|
+
}),
|
|
37
|
+
),
|
|
38
|
+
type: Schema.optional(Schema.Literals(Object.keys(MessageTypes) as ReadonlyArray<SessionMessage.Type>)).annotate({
|
|
39
|
+
description:
|
|
40
|
+
"Filter by message type before pagination. When omitted, all message types are returned. Pass the same type when following cursors.",
|
|
41
|
+
}),
|
|
42
|
+
}).annotate({ identifier: "SessionMessagesQuery" })
|
|
43
|
+
|
|
44
|
+
const PublicLocationSwitched = Schema.Struct({
|
|
45
|
+
...Struct.omit(SessionMessage.LocationSwitched.fields, ["location", "previous"]),
|
|
46
|
+
location: Location.PublicRef,
|
|
47
|
+
previous: Schema.Struct({
|
|
48
|
+
location: Location.PublicRef,
|
|
49
|
+
projectID: SessionMessage.LocationSwitched.fields.projectID,
|
|
50
|
+
subpath: SessionMessage.LocationSwitched.fields.subpath,
|
|
51
|
+
}).pipe(Schema.optional),
|
|
52
|
+
}).annotate({ identifier: "Session.Message.LocationSwitched" })
|
|
53
|
+
|
|
54
|
+
export const PublicSessionMessage = Schema.Union([
|
|
55
|
+
SessionMessage.AgentSelected,
|
|
56
|
+
SessionMessage.ModelSelected,
|
|
57
|
+
PublicLocationSwitched,
|
|
58
|
+
SessionMessage.User,
|
|
59
|
+
SessionMessage.Synthetic,
|
|
60
|
+
SessionMessage.System,
|
|
61
|
+
SessionMessage.Skill,
|
|
62
|
+
SessionMessage.Shell,
|
|
63
|
+
SessionMessage.Assistant,
|
|
64
|
+
SessionMessage.Compaction,
|
|
65
|
+
SessionMessage.Idle,
|
|
66
|
+
]).annotate({ identifier: "Session.Message.Info" })
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Experimental: {@link PublicSessionMessage} as sent to clients that opt in with `X-OpenCode-Capabilities:
|
|
70
|
+
* experimental-media-uri` while `experimental.media_blob` is on. User files stored in `blob` stay `media:` refs.
|
|
71
|
+
*/
|
|
72
|
+
export const PublicMediaSessionMessage = Schema.Union([
|
|
73
|
+
SessionMessage.AgentSelected,
|
|
74
|
+
SessionMessage.ModelSelected,
|
|
75
|
+
PublicLocationSwitched,
|
|
76
|
+
SessionMessage.MediaUser,
|
|
77
|
+
SessionMessage.Synthetic,
|
|
78
|
+
SessionMessage.System,
|
|
79
|
+
SessionMessage.Skill,
|
|
80
|
+
SessionMessage.Shell,
|
|
81
|
+
SessionMessage.Assistant,
|
|
82
|
+
SessionMessage.Compaction,
|
|
83
|
+
SessionMessage.Idle,
|
|
84
|
+
]).annotate({ identifier: "Session.Message.MediaInfo" })
|
|
85
|
+
|
|
86
|
+
const MessagesCursor = Schema.Struct({
|
|
87
|
+
previous: Schema.String.pipe(Schema.optional),
|
|
88
|
+
next: Schema.String.pipe(Schema.optional),
|
|
89
|
+
})
|
|
90
|
+
|
|
91
|
+
/** Experimental: the `session.messages` response for clients that opt into `experimental-media-uri`. */
|
|
92
|
+
export const SessionMediaMessagesResponse = Schema.Struct({
|
|
93
|
+
data: Schema.Array(PublicMediaSessionMessage),
|
|
94
|
+
cursor: MessagesCursor,
|
|
95
|
+
})
|
|
96
|
+
|
|
97
|
+
/** Experimental: the `session.message` response for clients that opt into `experimental-media-uri`. */
|
|
98
|
+
export const SessionMediaMessageResponse = Schema.Struct({ data: PublicMediaSessionMessage })
|
|
99
|
+
|
|
100
|
+
export const MessageGroup = HttpApiGroup.make("server.message")
|
|
101
|
+
.add(
|
|
102
|
+
HttpApiEndpoint.get("session.messages", "/api/session/:sessionID/message", {
|
|
103
|
+
params: { sessionID: Session.ID },
|
|
104
|
+
query: SessionMessagesQuery,
|
|
105
|
+
success: Schema.Struct({
|
|
106
|
+
data: Schema.Array(PublicSessionMessage),
|
|
107
|
+
cursor: MessagesCursor,
|
|
108
|
+
}).annotate({ identifier: "SessionMessagesResponse" }),
|
|
109
|
+
error: [InvalidCursorError, SessionNotFoundError, UnknownError],
|
|
110
|
+
}).annotateMerge(
|
|
111
|
+
OpenApi.annotations({
|
|
112
|
+
identifier: "session.message.list",
|
|
113
|
+
summary: "Get session messages",
|
|
114
|
+
description:
|
|
115
|
+
"List a session's messages, optionally filtered by type. Follow cursor.next or cursor.previous with the same type filter. Items still in the inbox aren't included.",
|
|
116
|
+
}),
|
|
117
|
+
),
|
|
118
|
+
)
|
|
119
|
+
.annotateMerge(
|
|
120
|
+
OpenApi.annotations({
|
|
121
|
+
title: "session",
|
|
122
|
+
description: "Experimental message routes.",
|
|
123
|
+
}),
|
|
124
|
+
)
|