MCPcopy Create free account
hub / github.com/anomalyco/opencode / makeSessionGroup

Function makeSessionGroup

packages/protocol/src/groups/session.ts:106–379  ·  view source on GitHub ↗
(sessionLocationMiddleware: Context.Key<I, S>)

Source from the content-addressed store, hash-verified

104}).annotate({ identifier: "SessionsQuery" })
105
106export const makeSessionGroup = <I extends HttpApiMiddleware.AnyId, S>(sessionLocationMiddleware: Context.Key<I, S>) =>
107 HttpApiGroup.make("server.session")
108 .add(
109 HttpApiEndpoint.get("session.list", "/api/session", {
110 query: SessionsQuery,
111 success: Schema.Struct({
112 data: Schema.Array(Session.Info),
113 cursor: Schema.Struct({
114 previous: SessionsCursor.pipe(Schema.optional),
115 next: SessionsCursor.pipe(Schema.optional),
116 }),
117 }).annotate({ identifier: "SessionsResponse" }),
118 error: [InvalidCursorError, InvalidRequestError],
119 }).annotateMerge(
120 OpenApi.annotations({
121 identifier: "v2.session.list",
122 summary: "List sessions",
123 description:
124 "Retrieve sessions in the requested order. Items keep that order across pages; use cursor.next or cursor.previous to move through the ordered list.",
125 }),
126 ),
127 )
128 .add(
129 HttpApiEndpoint.post("session.create", "/api/session", {
130 payload: Schema.Struct({
131 id: Session.ID.pipe(Schema.optional),
132 agent: Agent.ID.pipe(Schema.optional),
133 model: Model.Ref.pipe(Schema.optional),
134 location: Location.Ref.pipe(Schema.optional),
135 }),
136 success: Schema.Struct({ data: Session.Info }),
137 }).annotateMerge(
138 OpenApi.annotations({
139 identifier: "v2.session.create",
140 summary: "Create session",
141 description: "Create a session at the requested location.",
142 }),
143 ),
144 )
145 .add(
146 HttpApiEndpoint.get("session.active", "/api/session/active", {
147 success: Schema.Struct({ data: Schema.Record(Session.ID, SessionActive) }),
148 }).annotateMerge(
149 OpenApi.annotations({
150 identifier: "v2.session.active",
151 summary: "List active sessions",
152 description:
153 "Retrieve foreground Session drains currently owned by this OpenCode process. Sessions absent from the result are inactive.",
154 }),
155 ),
156 )
157 .add(
158 HttpApiEndpoint.get("session.get", "/api/session/:sessionID", {
159 params: { sessionID: Session.ID },
160 success: Schema.Struct({ data: Session.Info }),
161 error: SessionNotFoundError,
162 })
163 .middleware(sessionLocationMiddleware)

Callers 1

makeApiFromGroupFunction · 0.90

Calls 3

addMethod · 0.65
getMethod · 0.65
makeMethod · 0.45

Tested by

no test coverage detected