@opencode/protocol 0.0.0-dev-1341 → 0.0.0-dev-1343

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.
@@ -4,8 +4,10 @@ import { HttpApiEndpoint, HttpApiGroup, HttpApiMiddleware, HttpApiSchema, OpenAp
4
4
  import { ServiceUnavailableError } from "../errors.js";
5
5
  export const LocationQuery = Schema.Struct({
6
6
  location: Schema.optional(Schema.Struct({
7
- directory: Schema.optional(Schema.String),
8
- })),
7
+ directory: Schema.optional(Schema.String).annotate({ description: "Absolute path of the directory." }),
8
+ })).annotateKey({
9
+ description: "Location to run the request in, sent as location[directory]. Omit to use the server's default location.",
10
+ }),
9
11
  }).annotate({ identifier: "LocationQuery" });
10
12
  export const locationQueryOpenApi = OpenApi.annotations({
11
13
  transform: (operation) => {
@@ -5,14 +5,16 @@ import { Context, Schema } from "effect";
5
5
  import { HttpApiEndpoint, HttpApiGroup, HttpApiMiddleware, HttpApiSchema, OpenApi } from "effect/http-api";
6
6
  import { ForbiddenError, LocationNotFoundError, McpServerNotFoundError } from "../errors.js";
7
7
  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";
9
9
  export const MCP_CLIENT_PATH = "/api/experimental/client-mcp";
10
10
  export function hasMcpClientTicketURL(url) {
11
11
  return url.pathname === MCP_CLIENT_PATH && !!url.searchParams.get(PTY_CONNECT_TICKET_QUERY);
12
12
  }
13
13
  const McpClientQuery = Schema.Struct({
14
14
  ...LocationQuery.fields,
15
- name: Schema.String.check(Schema.isPattern(/^[a-zA-Z0-9_-]+$/)),
15
+ name: Schema.String.check(Schema.isPattern(/^[a-zA-Z0-9_-]+$/)).annotateKey({
16
+ description: "Name of the MCP server the client hosts.",
17
+ }),
16
18
  });
17
19
  export const makeMcpGroup = (locationMiddleware) => HttpApiGroup.make("server.mcp")
18
20
  .add(HttpApiEndpoint.get("mcp.list", "/api/mcp", {
@@ -87,7 +89,11 @@ export const makeMcpGroup = (locationMiddleware) => HttpApiGroup.make("server.mc
87
89
  })))
88
90
  .add(HttpApiEndpoint.post("mcp.clientToken", `${MCP_CLIENT_PATH}/token`, {
89
91
  query: McpClientQuery,
90
- headers: Schema.Struct({ [PTY_CONNECT_TOKEN_HEADER]: Schema.optional(Schema.String) }),
92
+ headers: Schema.Struct({
93
+ [PTY_CONNECT_TOKEN_HEADER]: Schema.optional(Schema.String).annotateKey({
94
+ description: `Must be ${PTY_CONNECT_TOKEN_HEADER_VALUE}; requests without it are refused.`,
95
+ }),
96
+ }),
91
97
  success: Location.response(PtyTicket.ConnectToken),
92
98
  error: ForbiddenError,
93
99
  })
@@ -100,7 +106,12 @@ export const makeMcpGroup = (locationMiddleware) => HttpApiGroup.make("server.mc
100
106
  // The client handler checks origin and ticket before it boots the location itself.
101
107
  .middleware(locationMiddleware)
102
108
  .add(HttpApiEndpoint.get("mcp.client", MCP_CLIENT_PATH, {
103
- query: Schema.Struct({ ...McpClientQuery.fields, [PTY_CONNECT_TICKET_QUERY]: Schema.optional(Schema.String) }),
109
+ query: Schema.Struct({
110
+ ...McpClientQuery.fields,
111
+ [PTY_CONNECT_TICKET_QUERY]: Schema.optional(Schema.String).annotateKey({
112
+ description: "Single-use ticket from experimental.mcp.client.token, which authorizes the connection without the usual credentials.",
113
+ }),
114
+ }),
104
115
  success: Schema.Boolean,
105
116
  error: [ForbiddenError, LocationNotFoundError],
106
117
  })
@@ -94,7 +94,7 @@ export const MessageGroup = HttpApiGroup.make("server.message")
94
94
  }).annotateMerge(OpenApi.annotations({
95
95
  identifier: "session.message.list",
96
96
  summary: "Get session messages",
97
- description: "Retrieve projected messages for a session, optionally filtered by type. Items keep the requested order across pages; use cursor.next or cursor.previous to move through the ordered timeline, passing the same type filter on each page.",
97
+ description: "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.",
98
98
  })))
99
99
  .annotateMerge(OpenApi.annotations({
100
100
  title: "session",
@@ -21,7 +21,11 @@ export const makePermissionGroup = (locationMiddleware, sessionLocationMiddlewar
21
21
  description: "Retrieve pending permission requests for a location.",
22
22
  })))
23
23
  .add(HttpApiEndpoint.get("permission.saved.list", "/api/permission/saved", {
24
- query: Schema.Struct({ projectID: Project.ID.pipe(Schema.optional) }),
24
+ query: Schema.Struct({
25
+ projectID: Project.ID.pipe(Schema.optional).annotateKey({
26
+ description: "Project whose saved permissions to list. Defaults to the project of the requested location.",
27
+ }),
28
+ }),
25
29
  success: Schema.Struct({ data: Schema.Array(PermissionSaved.Info) }),
26
30
  })
27
31
  .middleware(locationMiddleware)
@@ -18,7 +18,9 @@ export const PersistentPtyGroup = HttpApiGroup.make("server.experimental")
18
18
  .add(HttpApiEndpoint.get("persistentPty.read", "/api/experimental/session/:sessionID/terminal/read", {
19
19
  params: { sessionID: Session.ID },
20
20
  query: {
21
- lines: Schema.NumberFromString.pipe(Schema.decodeTo(PersistentPty.ReadLines), Schema.optional),
21
+ lines: Schema.NumberFromString.pipe(Schema.decodeTo(PersistentPty.ReadLines), Schema.optional).annotateKey({
22
+ description: "Number of trailing rows to read, up to 65535. Defaults to the live terminal height; larger counts include retained history.",
23
+ }),
22
24
  },
23
25
  success: Schema.Struct({ data: Schema.NullOr(PersistentPty.ReadResult) }),
24
26
  error: [ServiceUnavailableError],
@@ -72,7 +74,11 @@ export const PersistentPtyGroup = HttpApiGroup.make("server.experimental")
72
74
  }).annotateMerge(OpenApi.annotations({ identifier: "experimental.persistentPty.remove" })))
73
75
  .add(HttpApiEndpoint.post("persistentPty.connectToken", "/api/experimental/persistent-pty/:ptyID/connect-token", {
74
76
  params: { ptyID: Pty.ID },
75
- headers: Schema.Struct({ [PTY_CONNECT_TOKEN_HEADER]: Schema.optional(Schema.String) }),
77
+ headers: Schema.Struct({
78
+ [PTY_CONNECT_TOKEN_HEADER]: Schema.optional(Schema.String).annotateKey({
79
+ description: `Must be ${PTY_CONNECT_TOKEN_HEADER_VALUE}; requests without it are refused.`,
80
+ }),
81
+ }),
76
82
  success: Schema.Struct({ data: PtyTicket.ConnectToken }),
77
83
  error: [ForbiddenError, PtyNotFoundError, ServiceUnavailableError],
78
84
  }).annotateMerge(OpenApi.annotations({ identifier: "experimental.persistentPty.connectToken" })))
@@ -89,7 +95,14 @@ export const PersistentPtyGroup = HttpApiGroup.make("server.experimental")
89
95
  "x-websocket": true,
90
96
  parameters: [
91
97
  ...(operation.parameters ?? []),
92
- ...["cursor", "role", "attachment_id", "takeover", "input_protocol", PTY_CONNECT_TICKET_QUERY].map((name) => ({ in: "query", name, schema: { type: "string" } })),
98
+ { in: "query", name: "attachment_id", schema: { type: "string" } },
99
+ ...Object.entries({
100
+ cursor: "Output offset to replay from. Defaults to 0.",
101
+ role: "Attach as controller (the default) or observer.",
102
+ takeover: "Set to true to take over control of the terminal.",
103
+ input_protocol: "Set to 1 to send framed input messages instead of raw terminal input.",
104
+ [PTY_CONNECT_TICKET_QUERY]: "Single-use ticket from experimental.persistentPty.connectToken, which authorizes the connection without the usual credentials.",
105
+ }).map(([name, description]) => ({ in: "query", name, description, schema: { type: "string" } })),
93
106
  ],
94
107
  }),
95
108
  })))
@@ -10,7 +10,11 @@ const BooleanFromString = Schema.Literals(["true", "false"]).pipe(Schema.decodeT
10
10
  }));
11
11
  export const ProjectGroup = HttpApiGroup.make("server.project")
12
12
  .add(HttpApiEndpoint.get("project.list", root, {
13
- query: Schema.Struct({ archived: BooleanFromString.pipe(Schema.optional) }),
13
+ query: Schema.Struct({
14
+ archived: BooleanFromString.pipe(Schema.optional).annotateKey({
15
+ description: "Set to true to include archived projects.",
16
+ }),
17
+ }),
14
18
  success: Schema.Array(Project.Info),
15
19
  }).annotateMerge(OpenApi.annotations({
16
20
  identifier: "project.list",
@@ -75,7 +75,11 @@ export const makePtyGroup = (locationMiddleware) => HttpApiGroup.make("server.pt
75
75
  .add(HttpApiEndpoint.post("pty.connectToken", "/api/pty/:ptyID/connect-token", {
76
76
  params: { ptyID: Pty.ID },
77
77
  query: LocationQuery,
78
- headers: Schema.Struct({ [PTY_CONNECT_TOKEN_HEADER]: Schema.optional(Schema.String) }),
78
+ headers: Schema.Struct({
79
+ [PTY_CONNECT_TOKEN_HEADER]: Schema.optional(Schema.String).annotateKey({
80
+ description: `Must be ${PTY_CONNECT_TOKEN_HEADER_VALUE}; requests without it are refused.`,
81
+ }),
82
+ }),
79
83
  success: Location.response(PtyTicket.ConnectToken),
80
84
  error: [ForbiddenError, PtyNotFoundError],
81
85
  })
@@ -101,11 +105,11 @@ HttpApiEndpoint.get("pty.connect", PTY_CONNECT_PATH, {
101
105
  "x-websocket": true,
102
106
  parameters: [
103
107
  ...(operation.parameters ?? []),
104
- ...["location[directory]", "cursor", PTY_CONNECT_TICKET_QUERY].map((name) => ({
105
- in: "query",
106
- name,
107
- schema: { type: "string" },
108
- })),
108
+ ...Object.entries({
109
+ "location[directory]": "Absolute path of the location directory. Omit to use the server's default location.",
110
+ cursor: "Output offset to replay from. Use -1 to start at the current end; omit to replay all retained output.",
111
+ [PTY_CONNECT_TICKET_QUERY]: "Single-use ticket from pty.connect.token, which authorizes the connection without the usual credentials.",
112
+ }).map(([name, description]) => ({ in: "query", name, description, schema: { type: "string" } })),
109
113
  ],
110
114
  }),
111
115
  })))
@@ -324,17 +324,17 @@ export declare const SessionsCursor: Schema.brand<Schema.String, "SessionsCursor
324
324
  export type SessionsCursor = Session.ListCursor;
325
325
  export declare const SessionsQuery: Schema.Struct<{
326
326
  readonly order: Schema.optional<Schema.Literals<readonly ["asc", "desc"]>>;
327
- readonly search: Schema.optional<Schema.String>;
328
327
  readonly parentID: Schema.optional<Schema.Union<readonly [Schema.brand<Schema.String, "SessionID"> & {
329
328
  create: () => string & import("effect/Brand").Brand<"SessionID">;
330
329
  }, Schema.decodeTo<Schema.Null, Schema.Literal<"null">, never, never>]>>;
331
- readonly archived: Schema.optional<Schema.decodeTo<Schema.Boolean, Schema.Literals<readonly ["true", "false"]>, never, never>>;
332
- readonly directory: Schema.optional<Schema.brand<Schema.String, "AbsolutePath">>;
333
330
  readonly project: Schema.optional<Schema.brand<Schema.String, "Project.ID"> & {
334
331
  global: string & import("effect/Brand").Brand<"Project.ID">;
335
332
  }>;
336
- readonly subpath: Schema.optional<Schema.brand<Schema.String, "RelativePath">>;
337
333
  readonly limit: Schema.optional<Schema.compose<Schema.Int, Schema.NumberFromString>>;
334
+ readonly search: Schema.optional<Schema.String>;
335
+ readonly archived: Schema.optional<Schema.decodeTo<Schema.Boolean, Schema.Literals<readonly ["true", "false"]>, never, never>>;
336
+ readonly directory: Schema.optional<Schema.brand<Schema.String, "AbsolutePath">>;
337
+ readonly subpath: Schema.optional<Schema.brand<Schema.String, "RelativePath">>;
338
338
  readonly cursor: Schema.optional<Schema.brand<Schema.String, "SessionsCursor"> & {
339
339
  make: (input: {
340
340
  readonly order?: "asc" | "desc" | undefined;
@@ -421,7 +421,6 @@ export declare const makeSessionGroup: <I extends HttpApiMiddleware.AnyId, S, Fo
421
421
  create: () => string & import("effect/Brand").Brand<"SessionID">;
422
422
  };
423
423
  }>>, never, Schema.toCodecJson<Schema.Struct<{
424
- readonly text: Schema.String;
425
424
  readonly files: Schema.decodeTo<Schema.optional<Schema.toType<Schema.$Array<Schema.Struct<{
426
425
  readonly uri: Schema.String;
427
426
  readonly source: Schema.decodeTo<Schema.optional<Schema.toType<Schema.Union<readonly [Schema.Struct<{
@@ -518,6 +517,7 @@ export declare const makeSessionGroup: <I extends HttpApiMiddleware.AnyId, S, Fo
518
517
  }>>, never, never>;
519
518
  }>>>, never, never>;
520
519
  readonly name: Schema.String;
520
+ readonly text: Schema.String;
521
521
  readonly delivery: Schema.optional<Schema.Literals<readonly ["steer", "queue"]>>;
522
522
  }>>, never, Schema.toCodecJson<HttpApiSchema.NoContent>, Schema.toCodecJson<typeof SessionNotFoundError | typeof CommandNotFoundError | typeof CommandExecutionError>, I, HttpApiMiddleware.Requires<I>> | HttpApiEndpoint.HttpApiEndpoint<"session.compact", "POST", "/api/session/:sessionID/compact", Schema.toCodecStringTree<Schema.Struct<{
523
523
  sessionID: Schema.brand<Schema.String, "SessionID"> & {
@@ -4638,17 +4638,17 @@ export declare const makeSessionGroup: <I extends HttpApiMiddleware.AnyId, S, Fo
4638
4638
  readonly interrupted: Schema.Boolean;
4639
4639
  }>>, Schema.toCodecJson<typeof SessionNotFoundError>, never, never> | HttpApiEndpoint.HttpApiEndpoint<"session.list", "GET", "/api/session", never, Schema.toCodecStringTree<Schema.Struct<{
4640
4640
  readonly order: Schema.optional<Schema.Literals<readonly ["asc", "desc"]>>;
4641
- readonly search: Schema.optional<Schema.String>;
4642
4641
  readonly parentID: Schema.optional<Schema.Union<readonly [Schema.brand<Schema.String, "SessionID"> & {
4643
4642
  create: () => string & import("effect/Brand").Brand<"SessionID">;
4644
4643
  }, Schema.decodeTo<Schema.Null, Schema.Literal<"null">, never, never>]>>;
4645
- readonly archived: Schema.optional<Schema.decodeTo<Schema.Boolean, Schema.Literals<readonly ["true", "false"]>, never, never>>;
4646
- readonly directory: Schema.optional<Schema.brand<Schema.String, "AbsolutePath">>;
4647
4644
  readonly project: Schema.optional<Schema.brand<Schema.String, "Project.ID"> & {
4648
4645
  global: string & import("effect/Brand").Brand<"Project.ID">;
4649
4646
  }>;
4650
- readonly subpath: Schema.optional<Schema.brand<Schema.String, "RelativePath">>;
4651
4647
  readonly limit: Schema.optional<Schema.compose<Schema.Int, Schema.NumberFromString>>;
4648
+ readonly search: Schema.optional<Schema.String>;
4649
+ readonly archived: Schema.optional<Schema.decodeTo<Schema.Boolean, Schema.Literals<readonly ["true", "false"]>, never, never>>;
4650
+ readonly directory: Schema.optional<Schema.brand<Schema.String, "AbsolutePath">>;
4651
+ readonly subpath: Schema.optional<Schema.brand<Schema.String, "RelativePath">>;
4652
4652
  readonly cursor: Schema.optional<Schema.brand<Schema.String, "SessionsCursor"> & {
4653
4653
  make: (input: {
4654
4654
  readonly order?: "asc" | "desc" | undefined;
@@ -7,7 +7,7 @@ import { TokenUsage } from "@opencode/schema/token-usage";
7
7
  import { Money } from "@opencode/schema/money";
8
8
  import { InstructionEntry } from "@opencode/schema/instruction-entry";
9
9
  import { Project } from "@opencode/schema/project";
10
- import { DateTimeUtcFromMillis, NonNegativeInt, PositiveInt } from "@opencode/schema/schema";
10
+ import { DateTimeUtcFromMillis, NonNegativeInt, optional, PositiveInt } from "@opencode/schema/schema";
11
11
  import { Event } from "@opencode/schema/event";
12
12
  import { SessionLegacy } from "@opencode/schema/session-legacy";
13
13
  import { Context, Schema, SchemaGetter, Struct } from "effect";
@@ -80,7 +80,21 @@ export const SessionsQuery = Schema.Struct({
80
80
  description: "Maximum number of sessions to return. Defaults to the newest 50 sessions.",
81
81
  }),
82
82
  ...Session.ListFilter.fields,
83
- cursor: Session.ListCursor.pipe(Schema.optional),
83
+ search: Session.ListFilter.fields.search.annotateKey({
84
+ description: "Only sessions whose title contains this text, ignoring case. % and _ act as wildcards.",
85
+ }),
86
+ archived: Session.ListFilter.fields.archived.annotateKey({
87
+ description: "Filter by archive state. Use true to return only archived sessions or false to exclude them. Omit to include both.",
88
+ }),
89
+ directory: Session.ListFilter.fields.directory.annotateKey({
90
+ description: "Only sessions whose directory is exactly this absolute path.",
91
+ }),
92
+ subpath: Session.ListFilter.fields.subpath.annotateKey({
93
+ description: "With project, only sessions at this path relative to the project directory.",
94
+ }),
95
+ cursor: Session.ListCursor.pipe(Schema.optional).annotateKey({
96
+ description: "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.",
97
+ }),
84
98
  }).annotate({ identifier: "SessionsQuery" });
85
99
  export const makeSessionGroup = (sessionLocationMiddleware, formLocationMiddleware) => HttpApiGroup.make("server.session")
86
100
  .add(HttpApiEndpoint.get("session.list", "/api/session", {
@@ -100,11 +114,19 @@ export const makeSessionGroup = (sessionLocationMiddleware, formLocationMiddlewa
100
114
  })))
101
115
  .add(HttpApiEndpoint.get("session.stats", "/api/experimental/session/stats", {
102
116
  query: Schema.Struct({
103
- from: Schema.NumberFromString.pipe(Schema.optional),
104
- to: Schema.NumberFromString.pipe(Schema.optional),
117
+ from: Schema.NumberFromString.pipe(Schema.optional).annotateKey({
118
+ description: "Start of the range in Unix milliseconds, inclusive. Defaults to the earliest recorded message.",
119
+ }),
120
+ to: Schema.NumberFromString.pipe(Schema.optional).annotateKey({
121
+ description: "End of the range in Unix milliseconds, exclusive. Defaults to now.",
122
+ }),
105
123
  project: Project.ID.pipe(Schema.optional),
106
- timezone: Schema.String.pipe(Schema.optional),
107
- tools: SessionStats.ToolMode.pipe(Schema.optional),
124
+ timezone: Schema.String.pipe(Schema.optional).annotateKey({
125
+ description: "IANA time zone used to group activity by day. Defaults to UTC.",
126
+ }),
127
+ tools: SessionStats.ToolMode.pipe(Schema.optional).annotateKey({
128
+ description: "How much tool usage to report: none, summary totals, or per-tool detail. Defaults to summary.",
129
+ }),
108
130
  }),
109
131
  success: Schema.Struct({ data: SessionStats.Info }),
110
132
  error: InvalidRequestError,
@@ -115,16 +137,24 @@ export const makeSessionGroup = (sessionLocationMiddleware, formLocationMiddlewa
115
137
  })))
116
138
  .add(HttpApiEndpoint.post("session.create", "/api/session", {
117
139
  payload: Schema.Struct({
118
- id: Session.ID.pipe(Schema.optional),
140
+ id: Session.ID.pipe(Schema.optional).annotate({
141
+ description: "If a session with this ID already exists, it is returned unchanged, so retries are safe.",
142
+ }),
119
143
  parentID: Session.ID.pipe(Schema.optional).annotate({
120
- description: "Set parentID to create a subagent session at the parent's location; set agent to choose its agent (otherwise it uses the default) and start it with session.prompt. After each completed round, the child sends a `<background-result kind=\"subagent\">` report to the parent's inbox and wakes the parent unless it has a staged revert.",
144
+ description: 'Creates a child session at the parent\'s location. Each time the child finishes running, it sends its last reply to the parent as a `<background-result kind="subagent">` message and wakes the parent, unless the parent has a staged revert.',
121
145
  }),
122
146
  title: Schema.String.pipe(Schema.optional),
123
147
  agent: Agent.ID.pipe(Schema.optional),
124
148
  model: Model.Ref.pipe(Schema.optional),
125
- location: Location.PublicRef.pipe(Schema.optional),
126
- metadata: Session.Metadata.pipe(Schema.optional),
127
- permissions: Permission.Ruleset.pipe(Schema.optional),
149
+ location: Location.PublicRef.pipe(Schema.optional).annotate({
150
+ description: "Defaults to the server's working directory. Ignored when parentID is set.",
151
+ }),
152
+ metadata: Session.Metadata.pipe(Schema.optional).annotate({
153
+ description: "Opaque to OpenCode. Child sessions inherit the parent's metadata unless you pass your own.",
154
+ }),
155
+ permissions: Permission.Ruleset.pipe(Schema.optional).annotate({
156
+ description: "Applied on top of the agent's rules. Child sessions inherit the parent's rules unless you pass your own.",
157
+ }),
128
158
  }),
129
159
  success: Schema.Struct({ data: PublicSessionInfo }),
130
160
  error: SessionNotFoundError,
@@ -148,7 +178,11 @@ export const makeSessionGroup = (sessionLocationMiddleware, formLocationMiddlewa
148
178
  })))
149
179
  .add(HttpApiEndpoint.get("session.export", "/api/experimental/session/:sessionID/export", {
150
180
  params: { sessionID: Session.ID },
151
- query: Schema.Struct({ sanitize: BooleanFromString.pipe(Schema.optional) }),
181
+ query: Schema.Struct({
182
+ sanitize: BooleanFromString.pipe(Schema.optional).annotateKey({
183
+ description: "Set to true to redact titles, message text, file data, paths and metadata from the export.",
184
+ }),
185
+ }),
152
186
  success: Schema.Struct({ data: PublicSessionTransfer }),
153
187
  error: [SessionNotFoundError, UnknownError],
154
188
  }).annotateMerge(OpenApi.annotations({
@@ -161,7 +195,7 @@ export const makeSessionGroup = (sessionLocationMiddleware, formLocationMiddlewa
161
195
  }).annotateMerge(OpenApi.annotations({
162
196
  identifier: "session.active",
163
197
  summary: "List active sessions",
164
- description: "Retrieve foreground Session drains currently owned by this OpenCode process. Sessions absent from the result are inactive.",
198
+ description: "List the sessions whose agent is running right now in this server process. Sessions missing from the result are idle.",
165
199
  })))
166
200
  .add(HttpApiEndpoint.get("session.get", "/api/session/:sessionID", {
167
201
  params: { sessionID: Session.ID },
@@ -189,7 +223,7 @@ export const makeSessionGroup = (sessionLocationMiddleware, formLocationMiddlewa
189
223
  }).annotateMerge(OpenApi.annotations({
190
224
  identifier: "session.fork",
191
225
  summary: "Fork session",
192
- description: "Create a child session by copying projected history before a message. Omit before to copy the full history.",
226
+ description: "Create a child session with this session's history before a message. Omit before to copy the full history.",
193
227
  })))
194
228
  .add(HttpApiEndpoint.post("session.switchAgent", "/api/session/:sessionID/agent", {
195
229
  params: { sessionID: Session.ID },
@@ -199,7 +233,7 @@ export const makeSessionGroup = (sessionLocationMiddleware, formLocationMiddlewa
199
233
  }).annotateMerge(OpenApi.annotations({
200
234
  identifier: "session.switchAgent",
201
235
  summary: "Switch session agent",
202
- description: "Switch the agent used by subsequent provider turns.",
236
+ description: "Change the agent the session uses from its next model call on.",
203
237
  })))
204
238
  .add(HttpApiEndpoint.post("session.switchModel", "/api/session/:sessionID/model", {
205
239
  params: { sessionID: Session.ID },
@@ -209,7 +243,7 @@ export const makeSessionGroup = (sessionLocationMiddleware, formLocationMiddlewa
209
243
  }).annotateMerge(OpenApi.annotations({
210
244
  identifier: "session.switchModel",
211
245
  summary: "Switch session model",
212
- description: "Switch the model used by subsequent provider turns.",
246
+ description: "Change the model the session uses from its next model call on.",
213
247
  })))
214
248
  .add(HttpApiEndpoint.patch("session.update", "/api/session/:sessionID", {
215
249
  params: { sessionID: Session.ID },
@@ -241,11 +275,19 @@ export const makeSessionGroup = (sessionLocationMiddleware, formLocationMiddlewa
241
275
  .add(HttpApiEndpoint.post("session.prompt", "/api/session/:sessionID/prompt", {
242
276
  params: { sessionID: Session.ID },
243
277
  payload: Schema.Struct({
244
- id: SessionMessage.ID.pipe(Schema.optional),
278
+ id: SessionMessage.ID.pipe(Schema.optional).annotate({
279
+ description: "Sending the same ID again returns the original item instead of adding a second one, so retries are safe. Reusing it in another session or for another kind of item fails with 409.",
280
+ }),
245
281
  ...PromptInput.Prompt.fields,
246
- metadata: SessionInbox.UserPayload.fields.metadata,
282
+ metadata: Schema.Record(Schema.String, Schema.Unknown)
283
+ .annotate({
284
+ description: "Stored on the message. The model doesn't see it.",
285
+ })
286
+ .pipe(optional),
247
287
  delivery: SessionInbox.Delivery.pipe(Schema.optional),
248
- resume: Schema.Boolean.pipe(Schema.optional),
288
+ resume: Schema.Boolean.pipe(Schema.optional).annotate({
289
+ description: "false adds the message to the inbox without starting the agent; it is delivered the next time the session runs.",
290
+ }),
249
291
  }),
250
292
  success: Schema.Struct({ data: SessionInbox.User }),
251
293
  error: [ConflictError, InvalidRequestError, SessionNotFoundError],
@@ -254,13 +296,16 @@ export const makeSessionGroup = (sessionLocationMiddleware, formLocationMiddlewa
254
296
  .annotateMerge(OpenApi.annotations({
255
297
  identifier: "session.prompt",
256
298
  summary: "Send message",
257
- description: "Durably admit one session input and schedule agent-loop execution unless resume is false.",
299
+ description: "Send a user message and start the agent unless resume is false. Returns once the message is queued, not when the agent finishes: wait with experimental.session.wait or the session.execution.* events, then read the reply with session.message.list.",
258
300
  })))
259
301
  .add(HttpApiEndpoint.post("session.command", "/api/session/:sessionID/command", {
260
302
  params: { sessionID: Session.ID },
261
303
  payload: Schema.Struct({
262
304
  name: Schema.String,
263
305
  ...PromptInput.Prompt.fields,
306
+ text: PromptInput.Prompt.fields.text.annotate({
307
+ description: "The command's arguments.",
308
+ }),
264
309
  delivery: SessionInbox.Delivery.pipe(Schema.optional),
265
310
  }),
266
311
  success: HttpApiSchema.NoContent,
@@ -270,7 +315,7 @@ export const makeSessionGroup = (sessionLocationMiddleware, formLocationMiddlewa
270
315
  .annotateMerge(OpenApi.annotations({
271
316
  identifier: "session.command",
272
317
  summary: "Run command",
273
- description: "Execute a slash command callback immediately.",
318
+ description: "Run a named command in the session. Most commands send a prompt, so like session.prompt this returns before the agent finishes.",
274
319
  })))
275
320
  .add(HttpApiEndpoint.post("session.skill", "/api/experimental/session/:sessionID/skill", {
276
321
  params: { sessionID: Session.ID },
@@ -290,19 +335,29 @@ export const makeSessionGroup = (sessionLocationMiddleware, formLocationMiddlewa
290
335
  .add(HttpApiEndpoint.post("session.synthetic", "/api/session/:sessionID/synthetic", {
291
336
  params: { sessionID: Session.ID },
292
337
  payload: Schema.Struct({
293
- id: SessionMessage.ID.pipe(Schema.optional),
338
+ id: SessionMessage.ID.pipe(Schema.optional).annotate({
339
+ description: "Sending the same ID again returns the original item instead of adding a second one, so retries are safe. Reusing it in another session or for another kind of item fails with 409.",
340
+ }),
294
341
  text: Schema.String,
295
- description: Schema.String.pipe(Schema.optional),
296
- metadata: SessionMessage.Synthetic.fields.metadata,
342
+ description: Schema.String.pipe(Schema.optional).annotate({
343
+ description: "Short label shown in the transcript instead of the full text.",
344
+ }),
345
+ metadata: Schema.Record(Schema.String, Schema.Unknown)
346
+ .annotate({
347
+ description: "Stored on the message. The model doesn't see it.",
348
+ })
349
+ .pipe(optional),
297
350
  delivery: SessionInbox.Delivery.pipe(Schema.optional),
298
- resume: Schema.Boolean.pipe(Schema.optional),
351
+ resume: Schema.Boolean.pipe(Schema.optional).annotate({
352
+ description: "false adds the message to the inbox without starting the agent; it is delivered the next time the session runs.",
353
+ }),
299
354
  }),
300
355
  success: Schema.Struct({ data: SessionInbox.Synthetic }),
301
356
  error: [ConflictError, SessionNotFoundError],
302
357
  }).annotateMerge(OpenApi.annotations({
303
358
  identifier: "session.synthetic",
304
359
  summary: "Add synthetic message",
305
- description: "Durably admit synthetic session input and schedule execution unless resume is false.",
360
+ description: "Add a message the model reads as user input but the user didn't type, such as a notification. Starts the agent unless resume is false or the session has a staged revert.",
306
361
  })))
307
362
  .add(HttpApiEndpoint.post("session.shell", "/api/session/:sessionID/shell", {
308
363
  params: { sessionID: Session.ID },
@@ -330,7 +385,7 @@ export const makeSessionGroup = (sessionLocationMiddleware, formLocationMiddlewa
330
385
  }).annotateMerge(OpenApi.annotations({
331
386
  identifier: "session.compact",
332
387
  summary: "Compact session",
333
- description: "Durably admit a session compaction request. Steers by default: it runs at the next step boundary instead of waiting behind queued prompts.",
388
+ description: "Queue a summary of the session's history. Steers by default: it runs before the next model call, ahead of queued messages.",
334
389
  })))
335
390
  .add(HttpApiEndpoint.post("session.wait", "/api/experimental/session/:sessionID/wait", {
336
391
  params: { sessionID: Session.ID },
@@ -339,7 +394,7 @@ export const makeSessionGroup = (sessionLocationMiddleware, formLocationMiddlewa
339
394
  }).annotateMerge(OpenApi.annotations({
340
395
  identifier: "experimental.session.wait",
341
396
  summary: "Wait for session",
342
- description: "Wait for a session agent loop to become idle.",
397
+ description: "Wait until the session's agent stops running in this server process. Returns at once when idle. Experimental: may change without compatibility guarantees.",
343
398
  })))
344
399
  .add(HttpApiEndpoint.post("session.revert.stage", "/api/session/:sessionID/revert/stage", {
345
400
  params: { sessionID: Session.ID },
@@ -401,7 +456,7 @@ export const makeSessionGroup = (sessionLocationMiddleware, formLocationMiddlewa
401
456
  }).annotateMerge(OpenApi.annotations({
402
457
  identifier: "session.inbox.list",
403
458
  summary: "List session inbox",
404
- description: "List durable enqueued session work not yet delivered, ordered by enqueue sequence. Includes user, synthetic, compaction, and move items.",
459
+ description: "List user, synthetic, compaction and move items not yet delivered to the agent, oldest first. Delivered user and synthetic items move to session.message.list.",
405
460
  })))
406
461
  .add(HttpApiEndpoint.delete("session.inbox.cancel", "/api/session/:sessionID/inbox/:inboxID", {
407
462
  params: { sessionID: Session.ID, inboxID: SessionMessage.ID },
@@ -468,8 +523,12 @@ export const makeSessionGroup = (sessionLocationMiddleware, formLocationMiddlewa
468
523
  .add(HttpApiEndpoint.get("session.log", "/api/experimental/session/:sessionID/log", {
469
524
  params: { sessionID: Session.ID },
470
525
  query: {
471
- after: Schema.NumberFromString.pipe(Schema.decodeTo(Event.Seq), Schema.optional),
472
- follow: BooleanFromString.pipe(Schema.optional),
526
+ after: Schema.NumberFromString.pipe(Schema.decodeTo(Event.Seq), Schema.optional).annotateKey({
527
+ description: "Only return events after this sequence number.",
528
+ }),
529
+ follow: BooleanFromString.pipe(Schema.optional).annotateKey({
530
+ description: "Set to true to keep the stream open and send live events after the stored ones.",
531
+ }),
473
532
  },
474
533
  success: HttpApiSchema.StreamSse({
475
534
  data: Schema.Union([SessionEvent.Durable, EventLog.Synced]).annotate({ identifier: "SessionLogItem" }),
@@ -482,7 +541,11 @@ export const makeSessionGroup = (sessionLocationMiddleware, formLocationMiddlewa
482
541
  })))
483
542
  .add(HttpApiEndpoint.post("session.interrupt", "/api/session/:sessionID/interrupt", {
484
543
  params: { sessionID: Session.ID },
485
- query: { resume: BooleanFromString.pipe(Schema.optional) },
544
+ query: {
545
+ resume: BooleanFromString.pipe(Schema.optional).annotateKey({
546
+ description: "Set to true to resume pending steering input and next-in-line control items after interrupting.",
547
+ }),
548
+ },
486
549
  success: Schema.Struct({
487
550
  interrupted: Schema.Boolean.annotate({
488
551
  description: "Whether an active execution owned by this OpenCode process was interrupted.",
@@ -492,7 +555,7 @@ export const makeSessionGroup = (sessionLocationMiddleware, formLocationMiddlewa
492
555
  }).annotateMerge(OpenApi.annotations({
493
556
  identifier: "session.interrupt",
494
557
  summary: "Interrupt session execution",
495
- description: "Interrupt active execution owned by this OpenCode process. Returns interrupted=true when an active execution was interrupted and false for the idle no-op. When resume=true, execution resumes pending steering input and next-in-line control items (manual compaction, moves) while queued prompts remain parked.",
558
+ description: "Stop the session's agent if it is running in this server process; interrupted=false means nothing was running. With resume=true it continues with pending steer items, compaction and moves, while queued messages keep waiting.",
496
559
  })))
497
560
  .add(HttpApiEndpoint.post("session.background", "/api/session/:sessionID/background", {
498
561
  params: { sessionID: Session.ID },
@@ -510,7 +573,7 @@ export const makeSessionGroup = (sessionLocationMiddleware, formLocationMiddlewa
510
573
  }).annotateMerge(OpenApi.annotations({
511
574
  identifier: "session.message.get",
512
575
  summary: "Get session message",
513
- description: "Retrieve one projected message owned by the Session.",
576
+ description: "Retrieve one message of the session by ID.",
514
577
  })))
515
578
  .add(HttpApiEndpoint.get("session.form.list", "/api/session/:sessionID/form", {
516
579
  params: { sessionID: Schema.String },
@@ -560,7 +623,11 @@ export const makeSessionGroup = (sessionLocationMiddleware, formLocationMiddlewa
560
623
  })))
561
624
  .add(HttpApiEndpoint.delete("session.form.cancel", "/api/session/:sessionID/form/:formID", {
562
625
  params: { sessionID: Schema.String, formID: Form.ID },
563
- query: Schema.Struct({ message: Schema.optional(Schema.String) }),
626
+ query: Schema.Struct({
627
+ message: Schema.optional(Schema.String).annotateKey({
628
+ description: "Why the form was not answered, passed on to the asker.",
629
+ }),
630
+ }),
564
631
  success: HttpApiSchema.NoContent,
565
632
  error: [SessionNotFoundError, FormAlreadySettledError, FormNotFoundError],
566
633
  })
@@ -8,7 +8,7 @@ import { LocationQuery, locationQueryOpenApi } from "./location.js";
8
8
  import { ConflictError, InvalidRequestError, ServiceUnavailableError } from "../errors.js";
9
9
  const InitQuery = Schema.Struct({
10
10
  ...LocationQuery.fields,
11
- provider: Schema.optional(Schema.String),
11
+ provider: Schema.optional(Schema.String).annotateKey({ description: "VCS provider to initialize. Defaults to git." }),
12
12
  });
13
13
  export class VcsInitNotSupportedError extends Schema.TaggedError()("VcsInitNotSupportedError", { providerID: Schema.String, message: Schema.String }, { httpApiStatus: 501 }) {
14
14
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "https://json.schemastore.org/package.json",
3
3
  "name": "@opencode/protocol",
4
- "version": "0.0.0-dev-1341",
4
+ "version": "0.0.0-dev-1343",
5
5
  "type": "module",
6
6
  "license": "MIT",
7
7
  "repository": {
@@ -35,7 +35,7 @@
35
35
  "typecheck:tsc": "tsc --noEmit"
36
36
  },
37
37
  "dependencies": {
38
- "@opencode/schema": "0.0.0-dev-1341",
38
+ "@opencode/schema": "0.0.0-dev-1343",
39
39
  "effect": "4.1.0"
40
40
  },
41
41
  "devDependencies": {