@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.
- package/openapi.json +33222 -0
- package/package.json +33 -4
- package/script/build.ts +9 -0
- package/script/generate-openapi.ts +25 -0
- package/script/openapi-parameters.ts +30 -0
- package/script/openapi-stabilize.ts +102 -0
- package/script/pack.ts +5 -0
- package/src/api.ts +264 -0
- package/src/client.ts +127 -0
- package/src/errors.ts +398 -0
- package/src/groups/agent.ts +39 -0
- package/src/groups/artifact.ts +103 -0
- package/src/groups/automation.ts +75 -0
- package/src/groups/blob.ts +20 -0
- package/src/groups/command.ts +27 -0
- package/src/groups/config.ts +46 -0
- package/src/groups/credential.ts +72 -0
- package/src/groups/debug.ts +68 -0
- package/src/groups/event.ts +86 -0
- package/src/groups/experimental.ts +19 -0
- package/src/groups/form.ts +26 -0
- package/src/groups/fs.ts +136 -0
- package/src/groups/generate.ts +120 -0
- package/src/groups/integration.ts +230 -0
- package/src/groups/job.ts +57 -0
- package/src/groups/location.ts +66 -0
- package/src/groups/machine.ts +120 -0
- package/src/groups/mcp.ts +167 -0
- package/src/groups/media.ts +23 -0
- package/src/groups/message.ts +124 -0
- package/src/groups/migration.ts +28 -0
- package/src/groups/model.ts +52 -0
- package/src/groups/permission.ts +164 -0
- package/src/groups/persistent-pty.ts +153 -0
- package/src/groups/plugin.ts +80 -0
- package/src/groups/project.ts +51 -0
- package/src/groups/provider.ts +45 -0
- package/src/groups/pty.ts +153 -0
- package/src/groups/push.ts +94 -0
- package/src/groups/reference.ts +42 -0
- package/src/groups/rpc.ts +30 -0
- package/src/groups/server.ts +80 -0
- package/src/groups/session.ts +918 -0
- package/src/groups/shell.ts +88 -0
- package/src/groups/skill.ts +46 -0
- package/src/groups/usage.ts +30 -0
- package/src/groups/vcs.ts +131 -0
- package/src/groups/voice.ts +96 -0
- package/src/groups/websearch.ts +46 -0
- package/src/groups/worktree.ts +78 -0
- package/src/middleware/authorization.ts +6 -0
- package/src/middleware/schema-error.ts +7 -0
- package/src/simulation.ts +691 -0
- package/test/event.test.ts +34 -0
- package/test/experimental-identifiers.test.ts +24 -0
- package/test/openapi-parameters.test.ts +43 -0
- package/test/openapi-patterns.test.ts +28 -0
- package/test/openapi-stabilize.test.ts +161 -0
- package/test/session-cursor.test.ts +7 -0
- package/tsconfig.build.json +11 -0
- package/tsconfig.json +14 -0
- package/README.md +0 -3
|
@@ -0,0 +1,918 @@
|
|
|
1
|
+
import { SessionMessage } from "@zyro-sec/schema/session-message"
|
|
2
|
+
import { SessionInbox } from "@zyro-sec/schema/session-inbox"
|
|
3
|
+
import { PromptInput } from "@zyro-sec/schema/prompt-input"
|
|
4
|
+
import { Session } from "@zyro-sec/schema/session"
|
|
5
|
+
import { SessionStats } from "@zyro-sec/schema/session-stats"
|
|
6
|
+
import { TokenUsage } from "@zyro-sec/schema/token-usage"
|
|
7
|
+
import { Money } from "@zyro-sec/schema/money"
|
|
8
|
+
import { InstructionEntry } from "@zyro-sec/schema/instruction-entry"
|
|
9
|
+
import { Project } from "@zyro-sec/schema/project"
|
|
10
|
+
import { DateTimeUtcFromMillis, NonNegativeInt, optional, PositiveInt } from "@zyro-sec/schema/schema"
|
|
11
|
+
import { Event } from "@zyro-sec/schema/event"
|
|
12
|
+
import { SessionLegacy } from "@zyro-sec/schema/session-legacy"
|
|
13
|
+
import { Context, Schema, SchemaGetter, Struct } from "effect"
|
|
14
|
+
import { HttpApiEndpoint, HttpApiGroup, HttpApiMiddleware, HttpApiSchema, OpenApi } from "effect/http-api"
|
|
15
|
+
import {
|
|
16
|
+
ConflictError,
|
|
17
|
+
LocationNotFoundError,
|
|
18
|
+
CommandExecutionError,
|
|
19
|
+
CommandNotFoundError,
|
|
20
|
+
FormAlreadySettledError,
|
|
21
|
+
FormInvalidAnswerError,
|
|
22
|
+
FormNotFoundError,
|
|
23
|
+
InvalidCursorError,
|
|
24
|
+
InvalidRequestError,
|
|
25
|
+
MessageNotFoundError,
|
|
26
|
+
ServiceUnavailableError,
|
|
27
|
+
SessionBusyError,
|
|
28
|
+
SessionNotFoundError,
|
|
29
|
+
SkillLoadError,
|
|
30
|
+
SkillNotFoundError,
|
|
31
|
+
UnknownError,
|
|
32
|
+
} from "../errors.js"
|
|
33
|
+
import { Agent } from "@zyro-sec/schema/agent"
|
|
34
|
+
import { Skill } from "@zyro-sec/schema/skill"
|
|
35
|
+
import { Model } from "@zyro-sec/schema/model"
|
|
36
|
+
import { Permission } from "@zyro-sec/schema/permission"
|
|
37
|
+
import { Location } from "@zyro-sec/schema/location"
|
|
38
|
+
import { SessionEvent } from "@zyro-sec/schema/session-event"
|
|
39
|
+
import { EventLog } from "@zyro-sec/schema/event-log"
|
|
40
|
+
import { FileDiff } from "@zyro-sec/schema/file-diff"
|
|
41
|
+
import { Form } from "@zyro-sec/schema/form"
|
|
42
|
+
import { PublicSessionMessage } from "./message.js"
|
|
43
|
+
|
|
44
|
+
const SessionActive = Schema.Struct({
|
|
45
|
+
type: Schema.Literal("running"),
|
|
46
|
+
}).annotate({ identifier: "SessionActive" })
|
|
47
|
+
|
|
48
|
+
const PublicSessionInfo = Schema.Struct({
|
|
49
|
+
...Struct.omit(Session.Info.fields, ["location"]),
|
|
50
|
+
location: Location.PublicRef,
|
|
51
|
+
}).annotate({ identifier: "Session.Info" })
|
|
52
|
+
|
|
53
|
+
const PublicSessionTransfer = Schema.Struct({
|
|
54
|
+
info: PublicSessionInfo,
|
|
55
|
+
messages: Schema.Array(PublicSessionMessage),
|
|
56
|
+
}).annotate({ identifier: "SessionTransfer.Data" })
|
|
57
|
+
|
|
58
|
+
const PublicMovePayload = Schema.Struct({
|
|
59
|
+
...Struct.omit(SessionInbox.MovePayload.fields, ["location"]),
|
|
60
|
+
location: Location.PublicRef,
|
|
61
|
+
}).annotate({ identifier: "Session.Inbox.MovePayload" })
|
|
62
|
+
|
|
63
|
+
const PublicMove = Schema.Struct({
|
|
64
|
+
...Struct.omit(SessionInbox.Move.fields, ["payload"]),
|
|
65
|
+
payload: PublicMovePayload,
|
|
66
|
+
}).annotate({ identifier: "Session.Inbox.Move" })
|
|
67
|
+
|
|
68
|
+
const PublicInboxInfo = Schema.Union([
|
|
69
|
+
SessionInbox.User,
|
|
70
|
+
SessionInbox.Synthetic,
|
|
71
|
+
SessionInbox.Compaction,
|
|
72
|
+
PublicMove,
|
|
73
|
+
]).annotate({ identifier: "Session.Inbox.Info" })
|
|
74
|
+
|
|
75
|
+
/** Experimental: the `session.inbox.list` response for clients that opt into `experimental-media-uri`. */
|
|
76
|
+
export const SessionMediaInboxResponse = Schema.Struct({
|
|
77
|
+
data: Schema.Array(
|
|
78
|
+
Schema.Union([SessionInbox.MediaUser, SessionInbox.Synthetic, SessionInbox.Compaction, PublicMove]).annotate({
|
|
79
|
+
identifier: "Session.Inbox.MediaInfo",
|
|
80
|
+
}),
|
|
81
|
+
),
|
|
82
|
+
})
|
|
83
|
+
|
|
84
|
+
// Transcripts exported before v2.1 carry older names for native data. The wire stays plain JSON so any export file
|
|
85
|
+
// is accepted; decoding upgrades those names and then validates the current message shape.
|
|
86
|
+
const ImportedMessages = Schema.Array(Schema.Json).pipe(
|
|
87
|
+
Schema.decodeTo(Schema.Array(Schema.Unknown), {
|
|
88
|
+
decode: SchemaGetter.transform(SessionLegacy.messages),
|
|
89
|
+
encode: SchemaGetter.passthrough({ strict: false }),
|
|
90
|
+
}),
|
|
91
|
+
Schema.decodeTo(Schema.Array(PublicSessionMessage), {
|
|
92
|
+
decode: SchemaGetter.passthrough({ strict: false }),
|
|
93
|
+
encode: SchemaGetter.passthrough({ strict: false }),
|
|
94
|
+
}),
|
|
95
|
+
)
|
|
96
|
+
|
|
97
|
+
const FormCreatePayload = Schema.Struct({
|
|
98
|
+
id: Form.ID.pipe(Schema.optional),
|
|
99
|
+
title: Form.Info.fields.title,
|
|
100
|
+
metadata: Form.Info.fields.metadata,
|
|
101
|
+
fields: Form.Info.fields.fields,
|
|
102
|
+
}).annotate({ identifier: "Form.CreatePayload" })
|
|
103
|
+
|
|
104
|
+
const BooleanFromString = Schema.Literals(["true", "false"]).pipe(
|
|
105
|
+
Schema.decodeTo(Schema.Boolean, {
|
|
106
|
+
decode: SchemaGetter.transform((value) => value === "true"),
|
|
107
|
+
encode: SchemaGetter.transform((value): "true" | "false" => (value ? "true" : "false")),
|
|
108
|
+
}),
|
|
109
|
+
)
|
|
110
|
+
|
|
111
|
+
// Kept so existing imports of SessionsCursor from Protocol keep working.
|
|
112
|
+
export const SessionsCursor = Session.ListCursor
|
|
113
|
+
export type SessionsCursor = Session.ListCursor
|
|
114
|
+
|
|
115
|
+
export const SessionsQuery = Schema.Struct({
|
|
116
|
+
limit: Schema.NumberFromString.pipe(Schema.decodeTo(PositiveInt), Schema.optional).annotate({
|
|
117
|
+
description: "Maximum number of sessions to return. Defaults to the newest 50 sessions.",
|
|
118
|
+
}),
|
|
119
|
+
...Session.ListFilter.fields,
|
|
120
|
+
search: Session.ListFilter.fields.search.annotateKey({
|
|
121
|
+
description: "Only sessions whose title contains this text, ignoring case. % and _ act as wildcards.",
|
|
122
|
+
}),
|
|
123
|
+
archived: Session.ListFilter.fields.archived.annotateKey({
|
|
124
|
+
description:
|
|
125
|
+
"Filter by archive state. Use true to return only archived sessions or false to exclude them. Omit to include both.",
|
|
126
|
+
}),
|
|
127
|
+
directory: Session.ListFilter.fields.directory.annotateKey({
|
|
128
|
+
description: "Only sessions whose directory is exactly this absolute path.",
|
|
129
|
+
}),
|
|
130
|
+
subpath: Session.ListFilter.fields.subpath.annotateKey({
|
|
131
|
+
description: "With project, only sessions at this path relative to the project directory.",
|
|
132
|
+
}),
|
|
133
|
+
cursor: Session.ListCursor.pipe(Schema.optional).annotateKey({
|
|
134
|
+
description:
|
|
135
|
+
"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.",
|
|
136
|
+
}),
|
|
137
|
+
}).annotate({ identifier: "SessionsQuery" })
|
|
138
|
+
|
|
139
|
+
export const makeSessionGroup = <I extends HttpApiMiddleware.AnyId, S, FormI extends HttpApiMiddleware.AnyId, FormS>(
|
|
140
|
+
sessionLocationMiddleware: Context.Key<I, S>,
|
|
141
|
+
formLocationMiddleware: Context.Key<FormI, FormS>,
|
|
142
|
+
) =>
|
|
143
|
+
HttpApiGroup.make("server.session")
|
|
144
|
+
.add(
|
|
145
|
+
HttpApiEndpoint.get("session.list", "/api/session", {
|
|
146
|
+
query: SessionsQuery,
|
|
147
|
+
success: Schema.Struct({
|
|
148
|
+
data: Schema.Array(PublicSessionInfo),
|
|
149
|
+
cursor: Schema.Struct({
|
|
150
|
+
previous: Session.ListCursor.pipe(Schema.optional),
|
|
151
|
+
next: Session.ListCursor.pipe(Schema.optional),
|
|
152
|
+
}),
|
|
153
|
+
}).annotate({ identifier: "SessionsResponse" }),
|
|
154
|
+
error: [InvalidCursorError, InvalidRequestError],
|
|
155
|
+
}).annotateMerge(
|
|
156
|
+
OpenApi.annotations({
|
|
157
|
+
identifier: "session.list",
|
|
158
|
+
summary: "List sessions",
|
|
159
|
+
description:
|
|
160
|
+
"Retrieve sessions in the requested order. Items keep that order across pages; use cursor.next or cursor.previous to move through the ordered list.",
|
|
161
|
+
}),
|
|
162
|
+
),
|
|
163
|
+
)
|
|
164
|
+
.add(
|
|
165
|
+
HttpApiEndpoint.get("session.stats", "/api/experimental/session/stats", {
|
|
166
|
+
query: Schema.Struct({
|
|
167
|
+
from: Schema.NumberFromString.pipe(Schema.optional).annotateKey({
|
|
168
|
+
description:
|
|
169
|
+
"Start of the range in Unix milliseconds, inclusive. Defaults to the earliest recorded message.",
|
|
170
|
+
}),
|
|
171
|
+
to: Schema.NumberFromString.pipe(Schema.optional).annotateKey({
|
|
172
|
+
description: "End of the range in Unix milliseconds, exclusive. Defaults to now.",
|
|
173
|
+
}),
|
|
174
|
+
project: Project.ID.pipe(Schema.optional),
|
|
175
|
+
timezone: Schema.String.pipe(Schema.optional).annotateKey({
|
|
176
|
+
description: "IANA time zone used to group activity by day. Defaults to UTC.",
|
|
177
|
+
}),
|
|
178
|
+
tools: SessionStats.ToolMode.pipe(Schema.optional).annotateKey({
|
|
179
|
+
description:
|
|
180
|
+
"How much tool usage to report: none, summary totals, or per-tool detail. Defaults to summary.",
|
|
181
|
+
}),
|
|
182
|
+
}),
|
|
183
|
+
success: Schema.Struct({ data: SessionStats.Info }),
|
|
184
|
+
error: InvalidRequestError,
|
|
185
|
+
}).annotateMerge(
|
|
186
|
+
OpenApi.annotations({
|
|
187
|
+
identifier: "experimental.session.stats",
|
|
188
|
+
summary: "Get session statistics",
|
|
189
|
+
description: "Aggregate local session activity, usage, and tool reliability for a time range.",
|
|
190
|
+
}),
|
|
191
|
+
),
|
|
192
|
+
)
|
|
193
|
+
.add(
|
|
194
|
+
HttpApiEndpoint.post("session.create", "/api/session", {
|
|
195
|
+
payload: Schema.Struct({
|
|
196
|
+
id: Session.ID.pipe(Schema.optional).annotate({
|
|
197
|
+
description: "If a session with this ID already exists, it is returned unchanged, so retries are safe.",
|
|
198
|
+
}),
|
|
199
|
+
parentID: Session.ID.pipe(Schema.optional).annotate({
|
|
200
|
+
description:
|
|
201
|
+
'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.',
|
|
202
|
+
}),
|
|
203
|
+
title: Schema.String.pipe(Schema.optional),
|
|
204
|
+
agent: Agent.ID.pipe(Schema.optional),
|
|
205
|
+
model: Model.Ref.pipe(Schema.optional),
|
|
206
|
+
location: Location.PublicRef.pipe(Schema.optional).annotate({
|
|
207
|
+
description: "Defaults to the server's working directory. Ignored when parentID is set.",
|
|
208
|
+
}),
|
|
209
|
+
metadata: Session.Metadata.pipe(Schema.optional).annotate({
|
|
210
|
+
description: "Opaque to OpenCode. Child sessions inherit the parent's metadata unless you pass your own.",
|
|
211
|
+
}),
|
|
212
|
+
permissions: Permission.Ruleset.pipe(Schema.optional).annotate({
|
|
213
|
+
description:
|
|
214
|
+
"Applied on top of the agent's rules. Child sessions inherit the parent's rules unless you pass your own.",
|
|
215
|
+
}),
|
|
216
|
+
}),
|
|
217
|
+
success: Schema.Struct({ data: PublicSessionInfo }),
|
|
218
|
+
error: SessionNotFoundError,
|
|
219
|
+
}).annotateMerge(
|
|
220
|
+
OpenApi.annotations({
|
|
221
|
+
identifier: "session.create",
|
|
222
|
+
summary: "Create session",
|
|
223
|
+
description:
|
|
224
|
+
"Create a session at the requested location. A parentID creates a linked child session at its parent's location.",
|
|
225
|
+
}),
|
|
226
|
+
),
|
|
227
|
+
)
|
|
228
|
+
.add(
|
|
229
|
+
HttpApiEndpoint.post("session.import", "/api/experimental/session/import", {
|
|
230
|
+
payload: Schema.Struct({
|
|
231
|
+
info: PublicSessionTransfer.fields.info,
|
|
232
|
+
messages: ImportedMessages,
|
|
233
|
+
location: Location.PublicRef.pipe(Schema.optional),
|
|
234
|
+
}),
|
|
235
|
+
success: Schema.Struct({ data: PublicSessionInfo }),
|
|
236
|
+
error: [ConflictError, SessionNotFoundError],
|
|
237
|
+
}).annotateMerge(
|
|
238
|
+
OpenApi.annotations({
|
|
239
|
+
identifier: "experimental.session.import",
|
|
240
|
+
summary: "Import session",
|
|
241
|
+
description:
|
|
242
|
+
"Import a projected session transcript at the requested location. Accepts transcripts exported by earlier releases. If parentID is supplied, the parent session must already exist; import parents before children.",
|
|
243
|
+
}),
|
|
244
|
+
),
|
|
245
|
+
)
|
|
246
|
+
.add(
|
|
247
|
+
HttpApiEndpoint.get("session.export", "/api/experimental/session/:sessionID/export", {
|
|
248
|
+
params: { sessionID: Session.ID },
|
|
249
|
+
query: Schema.Struct({
|
|
250
|
+
sanitize: BooleanFromString.pipe(Schema.optional).annotateKey({
|
|
251
|
+
description: "Set to true to redact titles, message text, file data, paths and metadata from the export.",
|
|
252
|
+
}),
|
|
253
|
+
}),
|
|
254
|
+
success: Schema.Struct({ data: PublicSessionTransfer }),
|
|
255
|
+
error: [SessionNotFoundError, UnknownError],
|
|
256
|
+
}).annotateMerge(
|
|
257
|
+
OpenApi.annotations({
|
|
258
|
+
identifier: "experimental.session.export",
|
|
259
|
+
summary: "Export session",
|
|
260
|
+
description: "Export a complete projected session transcript.",
|
|
261
|
+
}),
|
|
262
|
+
),
|
|
263
|
+
)
|
|
264
|
+
.add(
|
|
265
|
+
HttpApiEndpoint.get("session.active", "/api/session/active", {
|
|
266
|
+
success: Schema.Struct({ data: Schema.Record(Session.ID, SessionActive) }),
|
|
267
|
+
}).annotateMerge(
|
|
268
|
+
OpenApi.annotations({
|
|
269
|
+
identifier: "session.active",
|
|
270
|
+
summary: "List active sessions",
|
|
271
|
+
description:
|
|
272
|
+
"List the sessions whose agent is running right now in this server process. Sessions missing from the result are idle.",
|
|
273
|
+
}),
|
|
274
|
+
),
|
|
275
|
+
)
|
|
276
|
+
.add(
|
|
277
|
+
HttpApiEndpoint.get("session.get", "/api/session/:sessionID", {
|
|
278
|
+
params: { sessionID: Session.ID },
|
|
279
|
+
success: Schema.Struct({ data: PublicSessionInfo }),
|
|
280
|
+
error: SessionNotFoundError,
|
|
281
|
+
}).annotateMerge(
|
|
282
|
+
OpenApi.annotations({
|
|
283
|
+
identifier: "session.get",
|
|
284
|
+
summary: "Get session",
|
|
285
|
+
description: "Retrieve a session by ID.",
|
|
286
|
+
}),
|
|
287
|
+
),
|
|
288
|
+
)
|
|
289
|
+
.add(
|
|
290
|
+
HttpApiEndpoint.delete("session.remove", "/api/session/:sessionID", {
|
|
291
|
+
params: { sessionID: Session.ID },
|
|
292
|
+
success: HttpApiSchema.NoContent,
|
|
293
|
+
error: SessionNotFoundError,
|
|
294
|
+
}).annotateMerge(
|
|
295
|
+
OpenApi.annotations({
|
|
296
|
+
identifier: "session.remove",
|
|
297
|
+
summary: "Delete session",
|
|
298
|
+
description: "Delete a session and its child sessions.",
|
|
299
|
+
}),
|
|
300
|
+
),
|
|
301
|
+
)
|
|
302
|
+
.add(
|
|
303
|
+
HttpApiEndpoint.post("session.fork", "/api/session/:sessionID/fork", {
|
|
304
|
+
params: { sessionID: Session.ID },
|
|
305
|
+
payload: Schema.Struct({ before: SessionMessage.ID.pipe(Schema.optional) }),
|
|
306
|
+
success: Schema.Struct({ data: PublicSessionInfo }),
|
|
307
|
+
error: [SessionNotFoundError, MessageNotFoundError, InvalidRequestError],
|
|
308
|
+
}).annotateMerge(
|
|
309
|
+
OpenApi.annotations({
|
|
310
|
+
identifier: "session.fork",
|
|
311
|
+
summary: "Fork session",
|
|
312
|
+
description:
|
|
313
|
+
"Create a child session with this session's history before a message. Omit before to copy the full history.",
|
|
314
|
+
}),
|
|
315
|
+
),
|
|
316
|
+
)
|
|
317
|
+
.add(
|
|
318
|
+
HttpApiEndpoint.post("session.switchAgent", "/api/session/:sessionID/agent", {
|
|
319
|
+
params: { sessionID: Session.ID },
|
|
320
|
+
payload: Schema.Struct({ agent: Agent.ID }),
|
|
321
|
+
success: HttpApiSchema.NoContent,
|
|
322
|
+
error: SessionNotFoundError,
|
|
323
|
+
}).annotateMerge(
|
|
324
|
+
OpenApi.annotations({
|
|
325
|
+
identifier: "session.switchAgent",
|
|
326
|
+
summary: "Switch session agent",
|
|
327
|
+
description: "Change the agent the session uses from its next model call on.",
|
|
328
|
+
}),
|
|
329
|
+
),
|
|
330
|
+
)
|
|
331
|
+
.add(
|
|
332
|
+
HttpApiEndpoint.post("session.switchModel", "/api/session/:sessionID/model", {
|
|
333
|
+
params: { sessionID: Session.ID },
|
|
334
|
+
payload: Schema.Struct({ model: Model.Ref }),
|
|
335
|
+
success: HttpApiSchema.NoContent,
|
|
336
|
+
error: SessionNotFoundError,
|
|
337
|
+
}).annotateMerge(
|
|
338
|
+
OpenApi.annotations({
|
|
339
|
+
identifier: "session.switchModel",
|
|
340
|
+
summary: "Switch session model",
|
|
341
|
+
description: "Change the model the session uses from its next model call on.",
|
|
342
|
+
}),
|
|
343
|
+
),
|
|
344
|
+
)
|
|
345
|
+
.add(
|
|
346
|
+
HttpApiEndpoint.patch("session.update", "/api/session/:sessionID", {
|
|
347
|
+
params: { sessionID: Session.ID },
|
|
348
|
+
payload: Schema.Struct({
|
|
349
|
+
title: Schema.String.pipe(Schema.optional),
|
|
350
|
+
metadata: Session.Metadata.pipe(Schema.optional),
|
|
351
|
+
permissions: Permission.Ruleset.pipe(Schema.optional),
|
|
352
|
+
archived: Schema.Boolean.pipe(Schema.optional).annotate({
|
|
353
|
+
description:
|
|
354
|
+
"Archive the session with true or restore it with false. Repeating the current state is a no-op.",
|
|
355
|
+
}),
|
|
356
|
+
}),
|
|
357
|
+
success: HttpApiSchema.NoContent,
|
|
358
|
+
error: [SessionNotFoundError, LocationNotFoundError],
|
|
359
|
+
}).annotateMerge(
|
|
360
|
+
OpenApi.annotations({
|
|
361
|
+
identifier: "session.update",
|
|
362
|
+
summary: "Update session",
|
|
363
|
+
description: "Update mutable session properties.",
|
|
364
|
+
}),
|
|
365
|
+
),
|
|
366
|
+
)
|
|
367
|
+
.add(
|
|
368
|
+
HttpApiEndpoint.post("session.move", "/api/session/:sessionID/move", {
|
|
369
|
+
params: { sessionID: Session.ID },
|
|
370
|
+
payload: Schema.Struct({ ...Location.PublicRef.fields, delivery: SessionInbox.Delivery.pipe(Schema.optional) }),
|
|
371
|
+
success: HttpApiSchema.NoContent,
|
|
372
|
+
error: [SessionNotFoundError, InvalidRequestError],
|
|
373
|
+
}).annotateMerge(
|
|
374
|
+
OpenApi.annotations({
|
|
375
|
+
identifier: "session.move",
|
|
376
|
+
summary: "Move session",
|
|
377
|
+
description: "Move a session to another project directory at the requested delivery boundary.",
|
|
378
|
+
}),
|
|
379
|
+
),
|
|
380
|
+
)
|
|
381
|
+
.add(
|
|
382
|
+
HttpApiEndpoint.post("session.prompt", "/api/session/:sessionID/prompt", {
|
|
383
|
+
params: { sessionID: Session.ID },
|
|
384
|
+
payload: Schema.Struct({
|
|
385
|
+
id: SessionMessage.ID.pipe(Schema.optional).annotate({
|
|
386
|
+
description:
|
|
387
|
+
"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.",
|
|
388
|
+
}),
|
|
389
|
+
...PromptInput.Prompt.fields,
|
|
390
|
+
metadata: Schema.Record(Schema.String, Schema.Unknown)
|
|
391
|
+
.annotate({
|
|
392
|
+
description: "Stored on the message. The model doesn't see it.",
|
|
393
|
+
})
|
|
394
|
+
.pipe(optional),
|
|
395
|
+
delivery: SessionInbox.Delivery.pipe(Schema.optional),
|
|
396
|
+
resume: Schema.Boolean.pipe(Schema.optional).annotate({
|
|
397
|
+
description:
|
|
398
|
+
"false adds the message to the inbox without starting the agent; it is delivered the next time the session runs.",
|
|
399
|
+
}),
|
|
400
|
+
}),
|
|
401
|
+
success: Schema.Struct({ data: SessionInbox.User }),
|
|
402
|
+
error: [ConflictError, InvalidRequestError, SessionNotFoundError, SkillLoadError],
|
|
403
|
+
})
|
|
404
|
+
.middleware(sessionLocationMiddleware)
|
|
405
|
+
.annotateMerge(
|
|
406
|
+
OpenApi.annotations({
|
|
407
|
+
identifier: "session.prompt",
|
|
408
|
+
summary: "Send message",
|
|
409
|
+
description:
|
|
410
|
+
"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 POST /api/experimental/session/:sessionID/wait or the session.execution.* events, then read the reply with GET /api/session/:sessionID/message. An archived session is unarchived.",
|
|
411
|
+
}),
|
|
412
|
+
),
|
|
413
|
+
)
|
|
414
|
+
.add(
|
|
415
|
+
HttpApiEndpoint.post("session.command", "/api/session/:sessionID/command", {
|
|
416
|
+
params: { sessionID: Session.ID },
|
|
417
|
+
payload: Schema.Struct({
|
|
418
|
+
name: Schema.String,
|
|
419
|
+
...PromptInput.Prompt.fields,
|
|
420
|
+
text: PromptInput.Prompt.fields.text.annotate({
|
|
421
|
+
description: "The command's arguments.",
|
|
422
|
+
}),
|
|
423
|
+
delivery: SessionInbox.Delivery.pipe(Schema.optional),
|
|
424
|
+
}),
|
|
425
|
+
success: HttpApiSchema.NoContent,
|
|
426
|
+
error: [SessionNotFoundError, CommandNotFoundError, CommandExecutionError],
|
|
427
|
+
})
|
|
428
|
+
.middleware(sessionLocationMiddleware)
|
|
429
|
+
.annotateMerge(
|
|
430
|
+
OpenApi.annotations({
|
|
431
|
+
identifier: "session.command",
|
|
432
|
+
summary: "Run command",
|
|
433
|
+
description:
|
|
434
|
+
"Run a named command in the session. Most commands send a prompt, so like session.prompt this returns before the agent finishes. An archived session is unarchived.",
|
|
435
|
+
}),
|
|
436
|
+
),
|
|
437
|
+
)
|
|
438
|
+
.add(
|
|
439
|
+
HttpApiEndpoint.post("session.skill", "/api/experimental/session/:sessionID/skill", {
|
|
440
|
+
params: { sessionID: Session.ID },
|
|
441
|
+
payload: Schema.Struct({
|
|
442
|
+
id: Skill.ID,
|
|
443
|
+
resume: Schema.Boolean.pipe(Schema.optional),
|
|
444
|
+
}),
|
|
445
|
+
success: HttpApiSchema.NoContent,
|
|
446
|
+
error: [SessionNotFoundError, SkillNotFoundError, SkillLoadError],
|
|
447
|
+
})
|
|
448
|
+
.middleware(sessionLocationMiddleware)
|
|
449
|
+
.annotateMerge(
|
|
450
|
+
OpenApi.annotations({
|
|
451
|
+
identifier: "experimental.session.skill",
|
|
452
|
+
summary: "Activate skill",
|
|
453
|
+
description:
|
|
454
|
+
"Activate a skill for a session by appending a skill message and resuming execution. An archived session is unarchived.",
|
|
455
|
+
}),
|
|
456
|
+
),
|
|
457
|
+
)
|
|
458
|
+
.add(
|
|
459
|
+
HttpApiEndpoint.post("session.synthetic", "/api/session/:sessionID/synthetic", {
|
|
460
|
+
params: { sessionID: Session.ID },
|
|
461
|
+
payload: Schema.Struct({
|
|
462
|
+
id: SessionMessage.ID.pipe(Schema.optional).annotate({
|
|
463
|
+
description:
|
|
464
|
+
"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.",
|
|
465
|
+
}),
|
|
466
|
+
text: Schema.String,
|
|
467
|
+
description: Schema.String.pipe(Schema.optional).annotate({
|
|
468
|
+
description: "Short label shown in the transcript instead of the full text.",
|
|
469
|
+
}),
|
|
470
|
+
metadata: Schema.Record(Schema.String, Schema.Unknown)
|
|
471
|
+
.annotate({
|
|
472
|
+
description: "Stored on the message. The model doesn't see it.",
|
|
473
|
+
})
|
|
474
|
+
.pipe(optional),
|
|
475
|
+
delivery: SessionInbox.Delivery.pipe(Schema.optional),
|
|
476
|
+
resume: Schema.Boolean.pipe(Schema.optional).annotate({
|
|
477
|
+
description:
|
|
478
|
+
"false adds the message to the inbox without starting the agent; it is delivered the next time the session runs.",
|
|
479
|
+
}),
|
|
480
|
+
}),
|
|
481
|
+
success: Schema.Struct({ data: SessionInbox.Synthetic }),
|
|
482
|
+
error: [ConflictError, SessionNotFoundError],
|
|
483
|
+
}).annotateMerge(
|
|
484
|
+
OpenApi.annotations({
|
|
485
|
+
identifier: "session.synthetic",
|
|
486
|
+
summary: "Add synthetic message",
|
|
487
|
+
description:
|
|
488
|
+
"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.",
|
|
489
|
+
}),
|
|
490
|
+
),
|
|
491
|
+
)
|
|
492
|
+
.add(
|
|
493
|
+
HttpApiEndpoint.post("session.shell", "/api/session/:sessionID/shell", {
|
|
494
|
+
params: { sessionID: Session.ID },
|
|
495
|
+
payload: Schema.Struct({
|
|
496
|
+
id: SessionMessage.ID.pipe(Schema.optional),
|
|
497
|
+
command: Schema.String,
|
|
498
|
+
}),
|
|
499
|
+
success: HttpApiSchema.NoContent,
|
|
500
|
+
error: SessionNotFoundError,
|
|
501
|
+
})
|
|
502
|
+
.middleware(sessionLocationMiddleware)
|
|
503
|
+
.annotateMerge(
|
|
504
|
+
OpenApi.annotations({
|
|
505
|
+
identifier: "session.shell",
|
|
506
|
+
summary: "Run shell command",
|
|
507
|
+
description:
|
|
508
|
+
"Execute one shell command in the session's working directory. Emits a shell.started event before execution and a shell.ended event with the merged output after. An archived session is unarchived.",
|
|
509
|
+
}),
|
|
510
|
+
),
|
|
511
|
+
)
|
|
512
|
+
.add(
|
|
513
|
+
HttpApiEndpoint.post("session.compact", "/api/session/:sessionID/compact", {
|
|
514
|
+
params: { sessionID: Session.ID },
|
|
515
|
+
payload: Schema.Struct({
|
|
516
|
+
id: SessionMessage.ID.pipe(Schema.optional),
|
|
517
|
+
delivery: SessionInbox.Delivery.pipe(Schema.optional),
|
|
518
|
+
}),
|
|
519
|
+
success: Schema.Struct({ data: SessionInbox.Compaction }),
|
|
520
|
+
error: [ConflictError, SessionNotFoundError],
|
|
521
|
+
}).annotateMerge(
|
|
522
|
+
OpenApi.annotations({
|
|
523
|
+
identifier: "session.compact",
|
|
524
|
+
summary: "Compact session",
|
|
525
|
+
description:
|
|
526
|
+
"Queue a summary of the session's history. Steers by default: it runs before the next model call, ahead of queued messages.",
|
|
527
|
+
}),
|
|
528
|
+
),
|
|
529
|
+
)
|
|
530
|
+
.add(
|
|
531
|
+
HttpApiEndpoint.post("session.wait", "/api/experimental/session/:sessionID/wait", {
|
|
532
|
+
params: { sessionID: Session.ID },
|
|
533
|
+
success: HttpApiSchema.NoContent,
|
|
534
|
+
error: [SessionNotFoundError, ServiceUnavailableError],
|
|
535
|
+
}).annotateMerge(
|
|
536
|
+
OpenApi.annotations({
|
|
537
|
+
identifier: "experimental.session.wait",
|
|
538
|
+
summary: "Wait for session",
|
|
539
|
+
description:
|
|
540
|
+
"Wait until the session's agent stops running in this server process. Returns at once when idle. Experimental: may change without compatibility guarantees.",
|
|
541
|
+
}),
|
|
542
|
+
),
|
|
543
|
+
)
|
|
544
|
+
.add(
|
|
545
|
+
HttpApiEndpoint.post("session.revert.stage", "/api/session/:sessionID/revert/stage", {
|
|
546
|
+
params: { sessionID: Session.ID },
|
|
547
|
+
payload: Schema.Struct({ messageID: SessionMessage.ID, files: Schema.Boolean.pipe(Schema.optional) }),
|
|
548
|
+
success: Schema.Struct({ data: Session.Revert }),
|
|
549
|
+
error: [MessageNotFoundError, SessionNotFoundError, SessionBusyError, UnknownError],
|
|
550
|
+
})
|
|
551
|
+
.middleware(sessionLocationMiddleware)
|
|
552
|
+
.annotateMerge(
|
|
553
|
+
OpenApi.annotations({
|
|
554
|
+
identifier: "session.revert.stage",
|
|
555
|
+
summary: "Stage session revert",
|
|
556
|
+
description: "Stage or move a reversible session boundary and optionally apply its file changes.",
|
|
557
|
+
}),
|
|
558
|
+
),
|
|
559
|
+
)
|
|
560
|
+
.add(
|
|
561
|
+
HttpApiEndpoint.delete("session.revert.clear", "/api/session/:sessionID/revert", {
|
|
562
|
+
params: { sessionID: Session.ID },
|
|
563
|
+
success: HttpApiSchema.NoContent,
|
|
564
|
+
error: [SessionNotFoundError, SessionBusyError, UnknownError],
|
|
565
|
+
})
|
|
566
|
+
.middleware(sessionLocationMiddleware)
|
|
567
|
+
.annotateMerge(OpenApi.annotations({ identifier: "session.revert.clear", summary: "Clear staged revert" })),
|
|
568
|
+
)
|
|
569
|
+
.add(
|
|
570
|
+
HttpApiEndpoint.post("session.revert.commit", "/api/session/:sessionID/revert/commit", {
|
|
571
|
+
params: { sessionID: Session.ID },
|
|
572
|
+
success: HttpApiSchema.NoContent,
|
|
573
|
+
error: [SessionNotFoundError, SessionBusyError],
|
|
574
|
+
}).annotateMerge(OpenApi.annotations({ identifier: "session.revert.commit", summary: "Commit staged revert" })),
|
|
575
|
+
)
|
|
576
|
+
.add(
|
|
577
|
+
HttpApiEndpoint.get("session.context", "/api/session/:sessionID/context", {
|
|
578
|
+
params: { sessionID: Session.ID },
|
|
579
|
+
success: Schema.Struct({ data: Schema.Array(PublicSessionMessage) }),
|
|
580
|
+
error: [SessionNotFoundError, UnknownError],
|
|
581
|
+
}).annotateMerge(
|
|
582
|
+
OpenApi.annotations({
|
|
583
|
+
identifier: "session.context",
|
|
584
|
+
summary: "Get session context",
|
|
585
|
+
description: "Retrieve the active context messages for a session (all messages after the last compaction).",
|
|
586
|
+
}),
|
|
587
|
+
),
|
|
588
|
+
)
|
|
589
|
+
.add(
|
|
590
|
+
HttpApiEndpoint.get("session.diff", "/api/session/:sessionID/diff", {
|
|
591
|
+
params: { sessionID: Session.ID },
|
|
592
|
+
query: Schema.Struct({
|
|
593
|
+
from: Schema.optional(SessionMessage.ID).annotate({
|
|
594
|
+
description: "User message whose turn to diff. Defaults to the turn of the newest user message.",
|
|
595
|
+
}),
|
|
596
|
+
to: Schema.optional(SessionMessage.ID).annotate({
|
|
597
|
+
description: "Later user message whose turn ends the range. Defaults to the turn of `from` alone.",
|
|
598
|
+
}),
|
|
599
|
+
context: Schema.NumberFromString.pipe(Schema.decodeTo(NonNegativeInt), Schema.optional).annotate({
|
|
600
|
+
description: "Unchanged lines around each hunk. Omit for full-file patches.",
|
|
601
|
+
}),
|
|
602
|
+
}),
|
|
603
|
+
success: Schema.Struct({ data: Schema.Array(FileDiff.Info) }),
|
|
604
|
+
error: [InvalidRequestError, MessageNotFoundError, SessionNotFoundError, UnknownError, LocationNotFoundError],
|
|
605
|
+
}).annotateMerge(
|
|
606
|
+
OpenApi.annotations({
|
|
607
|
+
identifier: "session.diff",
|
|
608
|
+
summary: "Diff session turns",
|
|
609
|
+
description:
|
|
610
|
+
"Structured per-file diffs of the files a turn changed. A turn runs from the first prompt after the session was last idle until its next idle marker, so prompts steered in while it was busy belong to the same turn; `to` extends the range through a later turn. Compares the range's first recorded snapshot with its last; a step still running in the active session compares against the working copy. Ranges that span a location change are rejected. In sessions without any idle marker, a prompt's turn spans until the next user message.",
|
|
611
|
+
}),
|
|
612
|
+
),
|
|
613
|
+
)
|
|
614
|
+
.add(
|
|
615
|
+
HttpApiEndpoint.get("session.inbox.list", "/api/session/:sessionID/inbox", {
|
|
616
|
+
params: { sessionID: Session.ID },
|
|
617
|
+
success: Schema.Struct({ data: Schema.Array(PublicInboxInfo) }),
|
|
618
|
+
error: SessionNotFoundError,
|
|
619
|
+
}).annotateMerge(
|
|
620
|
+
OpenApi.annotations({
|
|
621
|
+
identifier: "session.inbox.list",
|
|
622
|
+
summary: "List session inbox",
|
|
623
|
+
description:
|
|
624
|
+
"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.",
|
|
625
|
+
}),
|
|
626
|
+
),
|
|
627
|
+
)
|
|
628
|
+
.add(
|
|
629
|
+
HttpApiEndpoint.delete("session.inbox.cancel", "/api/session/:sessionID/inbox/:inboxID", {
|
|
630
|
+
params: { sessionID: Session.ID, inboxID: SessionMessage.ID },
|
|
631
|
+
success: HttpApiSchema.NoContent,
|
|
632
|
+
error: SessionNotFoundError,
|
|
633
|
+
}).annotateMerge(
|
|
634
|
+
OpenApi.annotations({
|
|
635
|
+
identifier: "session.inbox.cancel",
|
|
636
|
+
summary: "Cancel inbox input",
|
|
637
|
+
description: "Cancel an inbox item that has not yet been delivered. Unavailable items are a no-op.",
|
|
638
|
+
}),
|
|
639
|
+
),
|
|
640
|
+
)
|
|
641
|
+
.add(
|
|
642
|
+
HttpApiEndpoint.patch("session.inbox.update", "/api/session/:sessionID/inbox/:inboxID", {
|
|
643
|
+
params: { sessionID: Session.ID, inboxID: SessionMessage.ID },
|
|
644
|
+
payload: Schema.Struct({ delivery: SessionInbox.Delivery }),
|
|
645
|
+
success: HttpApiSchema.NoContent,
|
|
646
|
+
error: [ConflictError, SessionNotFoundError],
|
|
647
|
+
}).annotateMerge(
|
|
648
|
+
OpenApi.annotations({
|
|
649
|
+
identifier: "session.inbox.update",
|
|
650
|
+
summary: "Update inbox item",
|
|
651
|
+
description: "Change a pending inbox item's delivery mode. Steering wakes session execution.",
|
|
652
|
+
}),
|
|
653
|
+
),
|
|
654
|
+
)
|
|
655
|
+
.add(
|
|
656
|
+
HttpApiEndpoint.get(
|
|
657
|
+
"session.instructions.entry.list",
|
|
658
|
+
"/api/experimental/session/:sessionID/instructions/entries",
|
|
659
|
+
{
|
|
660
|
+
params: { sessionID: Session.ID },
|
|
661
|
+
success: Schema.Struct({ data: Schema.Array(InstructionEntry.Info) }),
|
|
662
|
+
error: SessionNotFoundError,
|
|
663
|
+
},
|
|
664
|
+
).annotateMerge(
|
|
665
|
+
OpenApi.annotations({
|
|
666
|
+
identifier: "experimental.session.instructions.entry.list",
|
|
667
|
+
summary: "List instruction entries",
|
|
668
|
+
description: "List API-managed instruction entries attached to the session.",
|
|
669
|
+
}),
|
|
670
|
+
),
|
|
671
|
+
)
|
|
672
|
+
.add(
|
|
673
|
+
HttpApiEndpoint.put(
|
|
674
|
+
"session.instructions.entry.put",
|
|
675
|
+
"/api/experimental/session/:sessionID/instructions/entries/:key",
|
|
676
|
+
{
|
|
677
|
+
params: { sessionID: Session.ID, key: InstructionEntry.Key },
|
|
678
|
+
payload: Schema.Struct({ value: Schema.Json }),
|
|
679
|
+
success: HttpApiSchema.NoContent,
|
|
680
|
+
error: [SessionNotFoundError, InstructionEntry.ValueTooLargeError],
|
|
681
|
+
},
|
|
682
|
+
).annotateMerge(
|
|
683
|
+
OpenApi.annotations({
|
|
684
|
+
identifier: "experimental.session.instructions.entry.put",
|
|
685
|
+
summary: "Put instruction entry",
|
|
686
|
+
description:
|
|
687
|
+
"Attach or replace one durable instruction entry. Changes announce as updates at the next step boundary.",
|
|
688
|
+
}),
|
|
689
|
+
),
|
|
690
|
+
)
|
|
691
|
+
.add(
|
|
692
|
+
HttpApiEndpoint.delete(
|
|
693
|
+
"session.instructions.entry.remove",
|
|
694
|
+
"/api/experimental/session/:sessionID/instructions/entries/:key",
|
|
695
|
+
{
|
|
696
|
+
params: { sessionID: Session.ID, key: InstructionEntry.Key },
|
|
697
|
+
success: HttpApiSchema.NoContent,
|
|
698
|
+
error: SessionNotFoundError,
|
|
699
|
+
},
|
|
700
|
+
).annotateMerge(
|
|
701
|
+
OpenApi.annotations({
|
|
702
|
+
identifier: "experimental.session.instructions.entry.remove",
|
|
703
|
+
summary: "Remove instruction entry",
|
|
704
|
+
description: "Remove one instruction entry; the removal is announced to the model at the next step boundary.",
|
|
705
|
+
}),
|
|
706
|
+
),
|
|
707
|
+
)
|
|
708
|
+
.add(
|
|
709
|
+
HttpApiEndpoint.post("session.generate", "/api/session/:sessionID/generate", {
|
|
710
|
+
params: { sessionID: Session.ID },
|
|
711
|
+
payload: Schema.Struct({ prompt: Schema.String }),
|
|
712
|
+
success: Schema.Struct({
|
|
713
|
+
// Same `tokens` and `cost` an assistant message reports for a step.
|
|
714
|
+
data: Schema.Struct({ text: Schema.String, tokens: TokenUsage.Info, cost: Money.USD }),
|
|
715
|
+
}).annotate({ identifier: "SessionGenerateResponse" }),
|
|
716
|
+
error: [SessionNotFoundError, ServiceUnavailableError],
|
|
717
|
+
})
|
|
718
|
+
.middleware(sessionLocationMiddleware)
|
|
719
|
+
.annotateMerge(
|
|
720
|
+
OpenApi.annotations({
|
|
721
|
+
identifier: "session.generate",
|
|
722
|
+
summary: "Generate text from session context",
|
|
723
|
+
description:
|
|
724
|
+
"Generate transient text from the current session context without mutating session history. Its tokens and cost count toward the session's totals.",
|
|
725
|
+
}),
|
|
726
|
+
),
|
|
727
|
+
)
|
|
728
|
+
.add(
|
|
729
|
+
HttpApiEndpoint.get("session.log", "/api/experimental/session/:sessionID/log", {
|
|
730
|
+
params: { sessionID: Session.ID },
|
|
731
|
+
query: {
|
|
732
|
+
after: Schema.NumberFromString.pipe(Schema.decodeTo(Event.Seq), Schema.optional).annotateKey({
|
|
733
|
+
description: "Only return events after this sequence number.",
|
|
734
|
+
}),
|
|
735
|
+
follow: BooleanFromString.pipe(Schema.optional).annotateKey({
|
|
736
|
+
description: "Set to true to keep the stream open and send live events after the stored ones.",
|
|
737
|
+
}),
|
|
738
|
+
},
|
|
739
|
+
success: HttpApiSchema.StreamSse({
|
|
740
|
+
data: Schema.Union([SessionEvent.Durable, EventLog.Synced]).annotate({ identifier: "SessionLogItem" }),
|
|
741
|
+
}),
|
|
742
|
+
error: SessionNotFoundError,
|
|
743
|
+
}).annotateMerge(
|
|
744
|
+
OpenApi.annotations({
|
|
745
|
+
identifier: "experimental.session.log",
|
|
746
|
+
summary: "Read the session log",
|
|
747
|
+
description:
|
|
748
|
+
"Experimental durable session event log. Reads events after an exclusive aggregate sequence and continues with live events when follow=true.",
|
|
749
|
+
}),
|
|
750
|
+
),
|
|
751
|
+
)
|
|
752
|
+
.add(
|
|
753
|
+
HttpApiEndpoint.post("session.interrupt", "/api/session/:sessionID/interrupt", {
|
|
754
|
+
params: { sessionID: Session.ID },
|
|
755
|
+
query: {
|
|
756
|
+
resume: BooleanFromString.pipe(Schema.optional).annotateKey({
|
|
757
|
+
description:
|
|
758
|
+
"Set to true to resume pending steering input and next-in-line control items after interrupting.",
|
|
759
|
+
}),
|
|
760
|
+
},
|
|
761
|
+
success: Schema.Struct({
|
|
762
|
+
interrupted: Schema.Boolean.annotate({
|
|
763
|
+
description: "Whether an active execution owned by this OpenCode process was interrupted.",
|
|
764
|
+
}),
|
|
765
|
+
}).annotate({ identifier: "SessionInterruptResponse" }),
|
|
766
|
+
error: SessionNotFoundError,
|
|
767
|
+
}).annotateMerge(
|
|
768
|
+
OpenApi.annotations({
|
|
769
|
+
identifier: "session.interrupt",
|
|
770
|
+
summary: "Interrupt session execution",
|
|
771
|
+
description:
|
|
772
|
+
"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.",
|
|
773
|
+
}),
|
|
774
|
+
),
|
|
775
|
+
)
|
|
776
|
+
.add(
|
|
777
|
+
HttpApiEndpoint.post("session.background", "/api/session/:sessionID/background", {
|
|
778
|
+
params: { sessionID: Session.ID },
|
|
779
|
+
success: HttpApiSchema.NoContent,
|
|
780
|
+
error: SessionNotFoundError,
|
|
781
|
+
}).annotateMerge(
|
|
782
|
+
OpenApi.annotations({
|
|
783
|
+
identifier: "session.background",
|
|
784
|
+
summary: "Background blocking session tools",
|
|
785
|
+
description:
|
|
786
|
+
"Move active foreground backgroundable tools for this session into background observation. Idle requests are a no-op.",
|
|
787
|
+
}),
|
|
788
|
+
),
|
|
789
|
+
)
|
|
790
|
+
.add(
|
|
791
|
+
HttpApiEndpoint.get("session.message", "/api/session/:sessionID/message/:messageID", {
|
|
792
|
+
params: { sessionID: Session.ID, messageID: SessionMessage.ID },
|
|
793
|
+
success: Schema.Struct({ data: PublicSessionMessage }),
|
|
794
|
+
error: [SessionNotFoundError, MessageNotFoundError],
|
|
795
|
+
}).annotateMerge(
|
|
796
|
+
OpenApi.annotations({
|
|
797
|
+
identifier: "session.message.get",
|
|
798
|
+
summary: "Get session message",
|
|
799
|
+
description: "Retrieve one message of the session by ID.",
|
|
800
|
+
}),
|
|
801
|
+
),
|
|
802
|
+
)
|
|
803
|
+
.add(
|
|
804
|
+
HttpApiEndpoint.get("session.form.list", "/api/session/:sessionID/form", {
|
|
805
|
+
params: { sessionID: Schema.String },
|
|
806
|
+
success: Schema.Struct({ data: Schema.Array(Form.Info) }),
|
|
807
|
+
error: SessionNotFoundError,
|
|
808
|
+
})
|
|
809
|
+
.middleware(formLocationMiddleware)
|
|
810
|
+
.annotateMerge(
|
|
811
|
+
OpenApi.annotations({
|
|
812
|
+
identifier: "session.form.list",
|
|
813
|
+
summary: "List session forms",
|
|
814
|
+
description: "Retrieve pending forms for a session.",
|
|
815
|
+
}),
|
|
816
|
+
),
|
|
817
|
+
)
|
|
818
|
+
.add(
|
|
819
|
+
HttpApiEndpoint.post("session.form.create", "/api/session/:sessionID/form", {
|
|
820
|
+
params: { sessionID: Schema.String },
|
|
821
|
+
payload: FormCreatePayload,
|
|
822
|
+
success: Schema.Struct({ data: Form.Info }),
|
|
823
|
+
error: [SessionNotFoundError, ConflictError, InvalidRequestError],
|
|
824
|
+
})
|
|
825
|
+
.middleware(formLocationMiddleware)
|
|
826
|
+
.annotateMerge(
|
|
827
|
+
OpenApi.annotations({
|
|
828
|
+
identifier: "session.form.create",
|
|
829
|
+
summary: "Create session form",
|
|
830
|
+
description: "Create a form for a session.",
|
|
831
|
+
}),
|
|
832
|
+
),
|
|
833
|
+
)
|
|
834
|
+
.add(
|
|
835
|
+
HttpApiEndpoint.get("session.form.get", "/api/session/:sessionID/form/:formID", {
|
|
836
|
+
params: { sessionID: Schema.String, formID: Form.ID },
|
|
837
|
+
success: Schema.Struct({ data: Form.Detail }),
|
|
838
|
+
error: [SessionNotFoundError, FormNotFoundError],
|
|
839
|
+
})
|
|
840
|
+
.middleware(formLocationMiddleware)
|
|
841
|
+
.annotateMerge(
|
|
842
|
+
OpenApi.annotations({
|
|
843
|
+
identifier: "session.form.get",
|
|
844
|
+
summary: "Get session form",
|
|
845
|
+
description: "Retrieve a form and its current state for a session.",
|
|
846
|
+
}),
|
|
847
|
+
),
|
|
848
|
+
)
|
|
849
|
+
.add(
|
|
850
|
+
HttpApiEndpoint.post("session.form.reply", "/api/session/:sessionID/form/:formID/reply", {
|
|
851
|
+
params: { sessionID: Schema.String, formID: Form.ID },
|
|
852
|
+
payload: Form.Reply,
|
|
853
|
+
success: HttpApiSchema.NoContent,
|
|
854
|
+
error: [SessionNotFoundError, FormAlreadySettledError, FormInvalidAnswerError, FormNotFoundError],
|
|
855
|
+
})
|
|
856
|
+
.middleware(formLocationMiddleware)
|
|
857
|
+
.annotateMerge(
|
|
858
|
+
OpenApi.annotations({
|
|
859
|
+
identifier: "session.form.reply",
|
|
860
|
+
summary: "Reply to form",
|
|
861
|
+
description: "Submit an answer to a pending form.",
|
|
862
|
+
}),
|
|
863
|
+
),
|
|
864
|
+
)
|
|
865
|
+
.add(
|
|
866
|
+
HttpApiEndpoint.delete("session.form.cancel", "/api/session/:sessionID/form/:formID", {
|
|
867
|
+
params: { sessionID: Schema.String, formID: Form.ID },
|
|
868
|
+
query: Schema.Struct({
|
|
869
|
+
message: Schema.optional(Schema.String).annotateKey({
|
|
870
|
+
description: "Why the form was not answered, passed on to the asker.",
|
|
871
|
+
}),
|
|
872
|
+
}),
|
|
873
|
+
success: HttpApiSchema.NoContent,
|
|
874
|
+
error: [SessionNotFoundError, FormAlreadySettledError, FormNotFoundError],
|
|
875
|
+
})
|
|
876
|
+
.middleware(formLocationMiddleware)
|
|
877
|
+
.annotateMerge(
|
|
878
|
+
OpenApi.annotations({
|
|
879
|
+
identifier: "session.form.cancel",
|
|
880
|
+
summary: "Cancel form",
|
|
881
|
+
description: "Cancel a pending form, optionally telling the asker why it was not answered.",
|
|
882
|
+
}),
|
|
883
|
+
),
|
|
884
|
+
)
|
|
885
|
+
.add(
|
|
886
|
+
HttpApiEndpoint.put("session.environment", "/api/session/:sessionID/environment", {
|
|
887
|
+
params: { sessionID: Session.ID },
|
|
888
|
+
payload: Schema.Struct({ variables: Schema.Record(Schema.String, Schema.String) }),
|
|
889
|
+
success: HttpApiSchema.NoContent,
|
|
890
|
+
error: SessionNotFoundError,
|
|
891
|
+
}).annotateMerge(
|
|
892
|
+
OpenApi.annotations({
|
|
893
|
+
identifier: "session.environment",
|
|
894
|
+
summary: "Set session environment",
|
|
895
|
+
description: "Replace the process environment used by local shell commands for this session.",
|
|
896
|
+
}),
|
|
897
|
+
),
|
|
898
|
+
)
|
|
899
|
+
.add(
|
|
900
|
+
HttpApiEndpoint.post("session.view", "/api/session/:sessionID/view", {
|
|
901
|
+
params: { sessionID: Session.ID },
|
|
902
|
+
payload: Schema.Struct({ idle: DateTimeUtcFromMillis }),
|
|
903
|
+
success: HttpApiSchema.NoContent,
|
|
904
|
+
error: SessionNotFoundError,
|
|
905
|
+
}).annotateMerge(
|
|
906
|
+
OpenApi.annotations({
|
|
907
|
+
identifier: "session.view",
|
|
908
|
+
summary: "View session",
|
|
909
|
+
description: "Mark the idle transition observed by the viewer as viewed.",
|
|
910
|
+
}),
|
|
911
|
+
),
|
|
912
|
+
)
|
|
913
|
+
.annotateMerge(
|
|
914
|
+
OpenApi.annotations({
|
|
915
|
+
title: "session",
|
|
916
|
+
description: "Experimental session routes.",
|
|
917
|
+
}),
|
|
918
|
+
)
|