GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — docs(protocol): describe API request parameters (#65841) · erickwill/opencode@91365c8

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • packages
    • protocol
      • openapi.json
      • script
        • generate-openapi.ts
        • openapi-parameters.ts
      • src/groups
        • location.ts
        • mcp.ts
        • permission.ts
        • persistent-pty.ts
        • project.ts
        • pty.ts
        • session.ts
        • vcs.ts
      • test
        • openapi-parameters.test.ts
    • schema/src
      • shell.ts
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎packages/protocol/openapi.json‎

Copy file name to clipboardExpand all lines: packages/protocol/openapi.json
+414-236Lines changed: 414 additions & 236 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Collapse file

‎packages/protocol/script/generate-openapi.ts‎

Copy file name to clipboardExpand all lines: packages/protocol/script/generate-openapi.ts
+8-4Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,16 @@ import { OpenApi } from "effect/http-api"
22
import { format } from "prettier"
33
import { fileURLToPath } from "url"
44
import { ClientApi } from "../src/client.js"
5+
import { liftParameterDescriptions } from "./openapi-parameters.js"
56
import { stabilizeOpenApi } from "./openapi-stabilize.js"
67

7-
const document = await format(JSON.stringify(stabilizeOpenApi(OpenApi.fromApi(ClientApi)), null, 2), {
8-
parser: "json",
9-
printWidth: 120,
10-
})
8+
const document = await format(
9+
JSON.stringify(liftParameterDescriptions(stabilizeOpenApi(OpenApi.fromApi(ClientApi))), null, 2),
10+
{
11+
parser: "json",
12+
printWidth: 120,
13+
},
14+
)
1115
const target = fileURLToPath(new URL("../openapi.json", import.meta.url))
1216

1317
if (process.argv.includes("--check")) {
Collapse file

‎packages/protocol/script/openapi-parameters.ts‎

Copy file name to clipboard
+30Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
type Schema = { description?: string; allOf?: Array<Record<string, unknown>>; [key: string]: unknown }
2+
type Parameter = { description?: string; schema?: Schema; [key: string]: unknown }
3+
type Document = { paths?: Record<string, Record<string, { parameters?: Array<Parameter> }>> }
4+
5+
// Effect writes a parameter's description into its schema: `.annotate` sets `schema.description`, and `.annotateKey`
6+
// (used where annotating would rename a shared component) adds a `{ description }` member to `schema.allOf`. OpenAPI
7+
// documents parameters by `parameters[].description`, so move it there.
8+
export function liftParameterDescriptions<T extends object>(document: T): T {
9+
for (const operations of Object.values((document as Document).paths ?? {}))
10+
for (const operation of Object.values(operations))
11+
operation.parameters = operation.parameters?.map((parameter) => {
12+
if (parameter.schema === undefined || parameter.description !== undefined) return parameter
13+
const description = parameter.schema.allOf?.find(isDescription)?.description ?? parameter.schema.description
14+
if (description === undefined) return parameter
15+
return { ...parameter, description, schema: withoutDescription(parameter.schema) }
16+
})
17+
return document
18+
}
19+
20+
function isDescription(member: Record<string, unknown>): member is { description: string } {
21+
return Object.keys(member).length === 1 && typeof member.description === "string"
22+
}
23+
24+
function withoutDescription(schema: Schema): Schema {
25+
const rest = Object.fromEntries(Object.entries(schema).filter(([key]) => key !== "description" && key !== "allOf"))
26+
const allOf = schema.allOf?.filter((member) => !isDescription(member)) ?? []
27+
if (allOf.length === 0) return rest
28+
if (allOf.length === 1 && Object.keys(rest).length === 0) return allOf[0]
29+
return { ...rest, allOf }
30+
}
Collapse file

‎packages/protocol/src/groups/location.ts‎

Copy file name to clipboardExpand all lines: packages/protocol/src/groups/location.ts
+5-2Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,12 @@ import { ServiceUnavailableError } from "../errors.js"
66
export const LocationQuery = Schema.Struct({
77
location: Schema.optional(
88
Schema.Struct({
9-
directory: Schema.optional(Schema.String),
9+
directory: Schema.optional(Schema.String).annotate({ description: "Absolute path of the directory." }),
1010
}),
11-
),
11+
).annotateKey({
12+
description:
13+
"Location to run the request in, sent as location[directory]. Omit to use the server's default location.",
14+
}),
1215
}).annotate({ identifier: "LocationQuery" })
1316

1417
export const locationQueryOpenApi = OpenApi.annotations({
Collapse file

‎packages/protocol/src/groups/mcp.ts‎

Copy file name to clipboardExpand all lines: packages/protocol/src/groups/mcp.ts
+16-4Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { Context, Schema } from "effect"
55
import { HttpApiEndpoint, HttpApiGroup, HttpApiMiddleware, HttpApiSchema, OpenApi } from "effect/http-api"
66
import { ForbiddenError, LocationNotFoundError, McpServerNotFoundError } from "../errors.js"
77
import { LocationQuery, locationQueryOpenApi } from "./location.js"
8-
import { PTY_CONNECT_TICKET_QUERY, PTY_CONNECT_TOKEN_HEADER } from "./pty.js"
8+
import { PTY_CONNECT_TICKET_QUERY, PTY_CONNECT_TOKEN_HEADER, PTY_CONNECT_TOKEN_HEADER_VALUE } from "./pty.js"
99

1010
export const MCP_CLIENT_PATH = "/api/experimental/client-mcp"
1111

@@ -15,7 +15,9 @@ export function hasMcpClientTicketURL(url: URL) {
1515

1616
const McpClientQuery = Schema.Struct({
1717
...LocationQuery.fields,
18-
name: Schema.String.check(Schema.isPattern(/^[a-zA-Z0-9_-]+$/)),
18+
name: Schema.String.check(Schema.isPattern(/^[a-zA-Z0-9_-]+$/)).annotateKey({
19+
description: "Name of the MCP server the client hosts.",
20+
}),
1921
})
2022

2123
export const makeMcpGroup = <LocationId extends HttpApiMiddleware.AnyId, LocationService>(
@@ -119,7 +121,11 @@ export const makeMcpGroup = <LocationId extends HttpApiMiddleware.AnyId, Locatio
119121
.add(
120122
HttpApiEndpoint.post("mcp.clientToken", `${MCP_CLIENT_PATH}/token`, {
121123
query: McpClientQuery,
122-
headers: Schema.Struct({ [PTY_CONNECT_TOKEN_HEADER]: Schema.optional(Schema.String) }),
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+
}),
123129
success: Location.response(PtyTicket.ConnectToken),
124130
error: ForbiddenError,
125131
})
@@ -137,7 +143,13 @@ export const makeMcpGroup = <LocationId extends HttpApiMiddleware.AnyId, Locatio
137143
.middleware(locationMiddleware)
138144
.add(
139145
HttpApiEndpoint.get("mcp.client", MCP_CLIENT_PATH, {
140-
query: Schema.Struct({ ...McpClientQuery.fields, [PTY_CONNECT_TICKET_QUERY]: Schema.optional(Schema.String) }),
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+
}),
141153
success: Schema.Boolean,
142154
error: [ForbiddenError, LocationNotFoundError],
143155
})
Collapse file

‎packages/protocol/src/groups/permission.ts‎

Copy file name to clipboardExpand all lines: packages/protocol/src/groups/permission.ts
+5-1Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,11 @@ export const makePermissionGroup = <
4242
)
4343
.add(
4444
HttpApiEndpoint.get("permission.saved.list", "/api/permission/saved", {
45-
query: Schema.Struct({ projectID: Project.ID.pipe(Schema.optional) }),
45+
query: Schema.Struct({
46+
projectID: Project.ID.pipe(Schema.optional).annotateKey({
47+
description: "Project whose saved permissions to list. Defaults to the project of the requested location.",
48+
}),
49+
}),
4650
success: Schema.Struct({ data: Schema.Array(PermissionSaved.Info) }),
4751
})
4852
.middleware(locationMiddleware)
Collapse file

‎packages/protocol/src/groups/persistent-pty.ts‎

Copy file name to clipboardExpand all lines: packages/protocol/src/groups/persistent-pty.ts
+18-5Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,10 @@ export const PersistentPtyGroup = HttpApiGroup.make("server.experimental")
3131
HttpApiEndpoint.get("persistentPty.read", "/api/experimental/session/:sessionID/terminal/read", {
3232
params: { sessionID: Session.ID },
3333
query: {
34-
lines: Schema.NumberFromString.pipe(Schema.decodeTo(PersistentPty.ReadLines), Schema.optional),
34+
lines: Schema.NumberFromString.pipe(Schema.decodeTo(PersistentPty.ReadLines), Schema.optional).annotateKey({
35+
description:
36+
"Number of trailing rows to read, up to 65535. Defaults to the live terminal height; larger counts include retained history.",
37+
}),
3538
},
3639
success: Schema.Struct({ data: Schema.NullOr(PersistentPty.ReadResult) }),
3740
error: [ServiceUnavailableError],
@@ -109,7 +112,11 @@ export const PersistentPtyGroup = HttpApiGroup.make("server.experimental")
109112
.add(
110113
HttpApiEndpoint.post("persistentPty.connectToken", "/api/experimental/persistent-pty/:ptyID/connect-token", {
111114
params: { ptyID: Pty.ID },
112-
headers: Schema.Struct({ [PTY_CONNECT_TOKEN_HEADER]: Schema.optional(Schema.String) }),
115+
headers: Schema.Struct({
116+
[PTY_CONNECT_TOKEN_HEADER]: Schema.optional(Schema.String).annotateKey({
117+
description: `Must be ${PTY_CONNECT_TOKEN_HEADER_VALUE}; requests without it are refused.`,
118+
}),
119+
}),
113120
success: Schema.Struct({ data: PtyTicket.ConnectToken }),
114121
error: [ForbiddenError, PtyNotFoundError, ServiceUnavailableError],
115122
}).annotateMerge(OpenApi.annotations({ identifier: "experimental.persistentPty.connectToken" })),
@@ -129,9 +136,15 @@ export const PersistentPtyGroup = HttpApiGroup.make("server.experimental")
129136
"x-websocket": true,
130137
parameters: [
131138
...(operation.parameters ?? []),
132-
...["cursor", "role", "attachment_id", "takeover", "input_protocol", PTY_CONNECT_TICKET_QUERY].map(
133-
(name) => ({ in: "query", name, schema: { type: "string" } }),
134-
),
139+
{ in: "query", name: "attachment_id", schema: { type: "string" } },
140+
...Object.entries({
141+
cursor: "Output offset to replay from. Defaults to 0.",
142+
role: "Attach as controller (the default) or observer.",
143+
takeover: "Set to true to take over control of the terminal.",
144+
input_protocol: "Set to 1 to send framed input messages instead of raw terminal input.",
145+
[PTY_CONNECT_TICKET_QUERY]:
146+
"Single-use ticket from experimental.persistentPty.connectToken, which authorizes the connection without the usual credentials.",
147+
}).map(([name, description]) => ({ in: "query", name, description, schema: { type: "string" } })),
135148
],
136149
}),
137150
}),
Collapse file

‎packages/protocol/src/groups/project.ts‎

Copy file name to clipboardExpand all lines: packages/protocol/src/groups/project.ts
+5-1Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,11 @@ const BooleanFromString = Schema.Literals(["true", "false"]).pipe(
1515
export const ProjectGroup = HttpApiGroup.make("server.project")
1616
.add(
1717
HttpApiEndpoint.get("project.list", root, {
18-
query: Schema.Struct({ archived: BooleanFromString.pipe(Schema.optional) }),
18+
query: Schema.Struct({
19+
archived: BooleanFromString.pipe(Schema.optional).annotateKey({
20+
description: "Set to true to include archived projects.",
21+
}),
22+
}),
1923
success: Schema.Array(Project.Info),
2024
}).annotateMerge(
2125
OpenApi.annotations({
Collapse file

‎packages/protocol/src/groups/pty.ts‎

Copy file name to clipboardExpand all lines: packages/protocol/src/groups/pty.ts
+13-6Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,11 @@ export const makePtyGroup = <LocationId extends HttpApiMiddleware.AnyId, Locatio
103103
HttpApiEndpoint.post("pty.connectToken", "/api/pty/:ptyID/connect-token", {
104104
params: { ptyID: Pty.ID },
105105
query: LocationQuery,
106-
headers: Schema.Struct({ [PTY_CONNECT_TOKEN_HEADER]: Schema.optional(Schema.String) }),
106+
headers: Schema.Struct({
107+
[PTY_CONNECT_TOKEN_HEADER]: Schema.optional(Schema.String).annotateKey({
108+
description: `Must be ${PTY_CONNECT_TOKEN_HEADER_VALUE}; requests without it are refused.`,
109+
}),
110+
}),
107111
success: Location.response(PtyTicket.ConnectToken),
108112
error: [ForbiddenError, PtyNotFoundError],
109113
})
@@ -133,11 +137,14 @@ export const makePtyGroup = <LocationId extends HttpApiMiddleware.AnyId, Locatio
133137
"x-websocket": true,
134138
parameters: [
135139
...(operation.parameters ?? []),
136-
...["location[directory]", "cursor", PTY_CONNECT_TICKET_QUERY].map((name) => ({
137-
in: "query",
138-
name,
139-
schema: { type: "string" },
140-
})),
140+
...Object.entries({
141+
"location[directory]":
142+
"Absolute path of the location directory. Omit to use the server's default location.",
143+
cursor:
144+
"Output offset to replay from. Use -1 to start at the current end; omit to replay all retained output.",
145+
[PTY_CONNECT_TICKET_QUERY]:
146+
"Single-use ticket from pty.connect.token, which authorizes the connection without the usual credentials.",
147+
}).map(([name, description]) => ({ in: "query", name, description, schema: { type: "string" } })),
141148
],
142149
}),
143150
}),
Collapse file

‎packages/protocol/src/groups/session.ts‎

Copy file name to clipboardExpand all lines: packages/protocol/src/groups/session.ts
+53-10Lines changed: 53 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,23 @@ export const SessionsQuery = Schema.Struct({
116116
description: "Maximum number of sessions to return. Defaults to the newest 50 sessions.",
117117
}),
118118
...Session.ListFilter.fields,
119-
cursor: Session.ListCursor.pipe(Schema.optional),
119+
search: Session.ListFilter.fields.search.annotateKey({
120+
description: "Only sessions whose title contains this text, ignoring case. % and _ act as wildcards.",
121+
}),
122+
archived: Session.ListFilter.fields.archived.annotateKey({
123+
description:
124+
"Filter by archive state. Use true to return only archived sessions or false to exclude them. Omit to include both.",
125+
}),
126+
directory: Session.ListFilter.fields.directory.annotateKey({
127+
description: "Only sessions whose directory is exactly this absolute path.",
128+
}),
129+
subpath: Session.ListFilter.fields.subpath.annotateKey({
130+
description: "With project, only sessions at this path relative to the project directory.",
131+
}),
132+
cursor: Session.ListCursor.pipe(Schema.optional).annotateKey({
133+
description:
134+
"Opaque cursor from a previous page's cursor.next or cursor.previous. It carries that page's filters and order, so other filters are ignored.",
135+
}),
120136
}).annotate({ identifier: "SessionsQuery" })
121137

122138
export const makeSessionGroup = <I extends HttpApiMiddleware.AnyId, S, FormI extends HttpApiMiddleware.AnyId, FormS>(
@@ -147,11 +163,21 @@ export const makeSessionGroup = <I extends HttpApiMiddleware.AnyId, S, FormI ext
147163
.add(
148164
HttpApiEndpoint.get("session.stats", "/api/experimental/session/stats", {
149165
query: Schema.Struct({
150-
from: Schema.NumberFromString.pipe(Schema.optional),
151-
to: Schema.NumberFromString.pipe(Schema.optional),
166+
from: Schema.NumberFromString.pipe(Schema.optional).annotateKey({
167+
description:
168+
"Start of the range in Unix milliseconds, inclusive. Defaults to the earliest recorded message.",
169+
}),
170+
to: Schema.NumberFromString.pipe(Schema.optional).annotateKey({
171+
description: "End of the range in Unix milliseconds, exclusive. Defaults to now.",
172+
}),
152173
project: Project.ID.pipe(Schema.optional),
153-
timezone: Schema.String.pipe(Schema.optional),
154-
tools: SessionStats.ToolMode.pipe(Schema.optional),
174+
timezone: Schema.String.pipe(Schema.optional).annotateKey({
175+
description: "IANA time zone used to group activity by day. Defaults to UTC.",
176+
}),
177+
tools: SessionStats.ToolMode.pipe(Schema.optional).annotateKey({
178+
description:
179+
"How much tool usage to report: none, summary totals, or per-tool detail. Defaults to summary.",
180+
}),
155181
}),
156182
success: Schema.Struct({ data: SessionStats.Info }),
157183
error: InvalidRequestError,
@@ -219,7 +245,11 @@ export const makeSessionGroup = <I extends HttpApiMiddleware.AnyId, S, FormI ext
219245
.add(
220246
HttpApiEndpoint.get("session.export", "/api/experimental/session/:sessionID/export", {
221247
params: { sessionID: Session.ID },
222-
query: Schema.Struct({ sanitize: BooleanFromString.pipe(Schema.optional) }),
248+
query: Schema.Struct({
249+
sanitize: BooleanFromString.pipe(Schema.optional).annotateKey({
250+
description: "Set to true to redact titles, message text, file data, paths and metadata from the export.",
251+
}),
252+
}),
223253
success: Schema.Struct({ data: PublicSessionTransfer }),
224254
error: [SessionNotFoundError, UnknownError],
225255
}).annotateMerge(
@@ -697,8 +727,12 @@ export const makeSessionGroup = <I extends HttpApiMiddleware.AnyId, S, FormI ext
697727
HttpApiEndpoint.get("session.log", "/api/experimental/session/:sessionID/log", {
698728
params: { sessionID: Session.ID },
699729
query: {
700-
after: Schema.NumberFromString.pipe(Schema.decodeTo(Event.Seq), Schema.optional),
701-
follow: BooleanFromString.pipe(Schema.optional),
730+
after: Schema.NumberFromString.pipe(Schema.decodeTo(Event.Seq), Schema.optional).annotateKey({
731+
description: "Only return events after this sequence number.",
732+
}),
733+
follow: BooleanFromString.pipe(Schema.optional).annotateKey({
734+
description: "Set to true to keep the stream open and send live events after the stored ones.",
735+
}),
702736
},
703737
success: HttpApiSchema.StreamSse({
704738
data: Schema.Union([SessionEvent.Durable, EventLog.Synced]).annotate({ identifier: "SessionLogItem" }),
@@ -716,7 +750,12 @@ export const makeSessionGroup = <I extends HttpApiMiddleware.AnyId, S, FormI ext
716750
.add(
717751
HttpApiEndpoint.post("session.interrupt", "/api/session/:sessionID/interrupt", {
718752
params: { sessionID: Session.ID },
719-
query: { resume: BooleanFromString.pipe(Schema.optional) },
753+
query: {
754+
resume: BooleanFromString.pipe(Schema.optional).annotateKey({
755+
description:
756+
"Set to true to resume pending steering input and next-in-line control items after interrupting.",
757+
}),
758+
},
720759
success: Schema.Struct({
721760
interrupted: Schema.Boolean.annotate({
722761
description: "Whether an active execution owned by this OpenCode process was interrupted.",
@@ -824,7 +863,11 @@ export const makeSessionGroup = <I extends HttpApiMiddleware.AnyId, S, FormI ext
824863
.add(
825864
HttpApiEndpoint.delete("session.form.cancel", "/api/session/:sessionID/form/:formID", {
826865
params: { sessionID: Schema.String, formID: Form.ID },
827-
query: Schema.Struct({ message: Schema.optional(Schema.String) }),
866+
query: Schema.Struct({
867+
message: Schema.optional(Schema.String).annotateKey({
868+
description: "Why the form was not answered, passed on to the asker.",
869+
}),
870+
}),
828871
success: HttpApiSchema.NoContent,
829872
error: [SessionNotFoundError, FormAlreadySettledError, FormNotFoundError],
830873
})

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.