mirror of
https://github.com/anomalyco/opencode.git
synced 2026-11-20 10:18:46 +03:00
fix(server): don't boot a Location for global session routes (#58997)
This commit is contained in:
committed by
GitHub
Unverified
parent
5ed03ad137
commit
450e7b9241
+2
-2
@@ -1538,7 +1538,7 @@ export function make(options: ClientOptions) {
|
||||
path: `/api/project`,
|
||||
query: { archived: input?.["archived"] },
|
||||
successStatus: 200,
|
||||
declaredStatuses: [400, 401, 404],
|
||||
declaredStatuses: [400, 401],
|
||||
empty: false,
|
||||
},
|
||||
requestOptions,
|
||||
@@ -1621,7 +1621,7 @@ export function make(options: ClientOptions) {
|
||||
method: "DELETE",
|
||||
path: `/api/permission/saved/${encodeURIComponent(input.id)}`,
|
||||
successStatus: 204,
|
||||
declaredStatuses: [400, 401, 404],
|
||||
declaredStatuses: [400, 401],
|
||||
empty: true,
|
||||
},
|
||||
requestOptions,
|
||||
|
||||
@@ -47,7 +47,6 @@ import { SkillInstructions } from "./skill/instructions.js"
|
||||
import { Snapshot } from "./snapshot.js"
|
||||
import { InstructionDiscovery } from "./instruction-discovery.js"
|
||||
import { InstructionBuiltIns } from "./instructions/builtins.js"
|
||||
import { InstructionEntry } from "./session/instruction-entry.js"
|
||||
import { SessionInstructions } from "./session/instructions.js"
|
||||
import { McpTool } from "./tool/mcp.js"
|
||||
import { ReadToolFileSystem } from "./tool/read-filesystem.js"
|
||||
@@ -96,7 +95,6 @@ const nodes = [
|
||||
Image.node,
|
||||
SkillInstructions.node,
|
||||
ReferenceInstructions.node,
|
||||
InstructionEntry.node,
|
||||
Form.node,
|
||||
Generate.node,
|
||||
Voice.node,
|
||||
|
||||
@@ -4,7 +4,7 @@ import { and, asc, eq, isNotNull, isNull, ne, or } from "drizzle-orm"
|
||||
import { Context, Effect, Layer, Schema } from "effect"
|
||||
import { InstructionEntry } from "@opencode/schema/instruction-entry"
|
||||
import { Database } from "../database/database.js"
|
||||
import { makeLocationNode } from "@opencode/util/effect/app-node"
|
||||
import { makeGlobalNode } from "@opencode/util/effect/app-node"
|
||||
import { Instructions } from "../instructions/index.js"
|
||||
import { SessionSchema } from "./schema.js"
|
||||
import { InstructionEntryTable } from "./sql.js"
|
||||
@@ -178,4 +178,4 @@ const layer = Layer.effect(
|
||||
}),
|
||||
)
|
||||
|
||||
export const node = makeLocationNode({ service: Service, layer, deps: [Database.node] })
|
||||
export const node = makeGlobalNode({ service: Service, layer, deps: [Database.node] })
|
||||
|
||||
Generated
+23
-123
@@ -1803,7 +1803,7 @@
|
||||
}
|
||||
},
|
||||
"404": {
|
||||
"description": "SessionNotFoundError | MessageNotFoundError | LocationNotFoundError",
|
||||
"description": "SessionNotFoundError | MessageNotFoundError",
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
@@ -1813,9 +1813,6 @@
|
||||
},
|
||||
{
|
||||
"$ref": "#/components/schemas/MessageNotFoundErrorEncoded"
|
||||
},
|
||||
{
|
||||
"$ref": "#/components/schemas/LocationNotFoundErrorEncoded"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -1890,18 +1887,11 @@
|
||||
}
|
||||
},
|
||||
"404": {
|
||||
"description": "SessionNotFoundError | LocationNotFoundError",
|
||||
"description": "SessionNotFoundError",
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"anyOf": [
|
||||
{
|
||||
"$ref": "#/components/schemas/SessionNotFoundErrorEncoded"
|
||||
},
|
||||
{
|
||||
"$ref": "#/components/schemas/LocationNotFoundErrorEncoded"
|
||||
}
|
||||
]
|
||||
"$ref": "#/components/schemas/SessionNotFoundErrorEncoded"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1968,18 +1958,11 @@
|
||||
}
|
||||
},
|
||||
"404": {
|
||||
"description": "SessionNotFoundError | LocationNotFoundError",
|
||||
"description": "SessionNotFoundError",
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"anyOf": [
|
||||
{
|
||||
"$ref": "#/components/schemas/SessionNotFoundErrorEncoded"
|
||||
},
|
||||
{
|
||||
"$ref": "#/components/schemas/LocationNotFoundErrorEncoded"
|
||||
}
|
||||
]
|
||||
"$ref": "#/components/schemas/SessionNotFoundErrorEncoded"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2844,18 +2827,11 @@
|
||||
}
|
||||
},
|
||||
"404": {
|
||||
"description": "SessionNotFoundError | LocationNotFoundError",
|
||||
"description": "SessionNotFoundError",
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"anyOf": [
|
||||
{
|
||||
"$ref": "#/components/schemas/SessionNotFoundErrorEncoded"
|
||||
},
|
||||
{
|
||||
"$ref": "#/components/schemas/LocationNotFoundErrorEncoded"
|
||||
}
|
||||
]
|
||||
"$ref": "#/components/schemas/SessionNotFoundErrorEncoded"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3120,18 +3096,11 @@
|
||||
}
|
||||
},
|
||||
"404": {
|
||||
"description": "SessionNotFoundError | LocationNotFoundError",
|
||||
"description": "SessionNotFoundError",
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"anyOf": [
|
||||
{
|
||||
"$ref": "#/components/schemas/SessionNotFoundErrorEncoded"
|
||||
},
|
||||
{
|
||||
"$ref": "#/components/schemas/LocationNotFoundErrorEncoded"
|
||||
}
|
||||
]
|
||||
"$ref": "#/components/schemas/SessionNotFoundErrorEncoded"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3647,18 +3616,11 @@
|
||||
}
|
||||
},
|
||||
"404": {
|
||||
"description": "SessionNotFoundError | LocationNotFoundError",
|
||||
"description": "SessionNotFoundError",
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"anyOf": [
|
||||
{
|
||||
"$ref": "#/components/schemas/SessionNotFoundErrorEncoded"
|
||||
},
|
||||
{
|
||||
"$ref": "#/components/schemas/LocationNotFoundErrorEncoded"
|
||||
}
|
||||
]
|
||||
"$ref": "#/components/schemas/SessionNotFoundErrorEncoded"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3716,18 +3678,11 @@
|
||||
}
|
||||
},
|
||||
"404": {
|
||||
"description": "SessionNotFoundError | LocationNotFoundError",
|
||||
"description": "SessionNotFoundError",
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"anyOf": [
|
||||
{
|
||||
"$ref": "#/components/schemas/SessionNotFoundErrorEncoded"
|
||||
},
|
||||
{
|
||||
"$ref": "#/components/schemas/LocationNotFoundErrorEncoded"
|
||||
}
|
||||
]
|
||||
"$ref": "#/components/schemas/SessionNotFoundErrorEncoded"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3808,18 +3763,11 @@
|
||||
}
|
||||
},
|
||||
"404": {
|
||||
"description": "SessionNotFoundError | LocationNotFoundError",
|
||||
"description": "SessionNotFoundError",
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"anyOf": [
|
||||
{
|
||||
"$ref": "#/components/schemas/SessionNotFoundErrorEncoded"
|
||||
},
|
||||
{
|
||||
"$ref": "#/components/schemas/LocationNotFoundErrorEncoded"
|
||||
}
|
||||
]
|
||||
"$ref": "#/components/schemas/SessionNotFoundErrorEncoded"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4160,18 +4108,11 @@
|
||||
}
|
||||
},
|
||||
"404": {
|
||||
"description": "SessionNotFoundError | LocationNotFoundError",
|
||||
"description": "SessionNotFoundError",
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"anyOf": [
|
||||
{
|
||||
"$ref": "#/components/schemas/SessionNotFoundErrorEncoded"
|
||||
},
|
||||
{
|
||||
"$ref": "#/components/schemas/LocationNotFoundErrorEncoded"
|
||||
}
|
||||
]
|
||||
"$ref": "#/components/schemas/SessionNotFoundErrorEncoded"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4221,18 +4162,11 @@
|
||||
}
|
||||
},
|
||||
"404": {
|
||||
"description": "SessionNotFoundError | LocationNotFoundError",
|
||||
"description": "SessionNotFoundError",
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"anyOf": [
|
||||
{
|
||||
"$ref": "#/components/schemas/SessionNotFoundErrorEncoded"
|
||||
},
|
||||
{
|
||||
"$ref": "#/components/schemas/LocationNotFoundErrorEncoded"
|
||||
}
|
||||
]
|
||||
"$ref": "#/components/schemas/SessionNotFoundErrorEncoded"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -8263,16 +8197,6 @@
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"404": {
|
||||
"description": "LocationNotFoundError",
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"$ref": "#/components/schemas/LocationNotFoundErrorEncoded"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"description": "List known projects. Archived projects are excluded unless archived=true.",
|
||||
@@ -8326,18 +8250,11 @@
|
||||
}
|
||||
},
|
||||
"404": {
|
||||
"description": "ProjectNotFoundError | LocationNotFoundError",
|
||||
"description": "ProjectNotFoundError",
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"anyOf": [
|
||||
{
|
||||
"$ref": "#/components/schemas/ProjectNotFoundErrorEncoded"
|
||||
},
|
||||
{
|
||||
"$ref": "#/components/schemas/LocationNotFoundErrorEncoded"
|
||||
}
|
||||
]
|
||||
"$ref": "#/components/schemas/ProjectNotFoundErrorEncoded"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -8696,18 +8613,11 @@
|
||||
}
|
||||
},
|
||||
"404": {
|
||||
"description": "PermissionSavedNotFoundError | LocationNotFoundError",
|
||||
"description": "PermissionSavedNotFoundError",
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"anyOf": [
|
||||
{
|
||||
"$ref": "#/components/schemas/PermissionSavedNotFoundErrorEncoded"
|
||||
},
|
||||
{
|
||||
"$ref": "#/components/schemas/LocationNotFoundErrorEncoded"
|
||||
}
|
||||
]
|
||||
"$ref": "#/components/schemas/PermissionSavedNotFoundErrorEncoded"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -8796,16 +8706,6 @@
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"404": {
|
||||
"description": "LocationNotFoundError",
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"$ref": "#/components/schemas/LocationNotFoundErrorEncoded"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"description": "Remove a saved permission by ID.",
|
||||
|
||||
@@ -44,7 +44,6 @@ type LocationGroups<LocationId extends HttpApiMiddleware.AnyId> =
|
||||
| HttpApiGroup.AddMiddleware<typeof IntegrationGroup, LocationId>
|
||||
| HttpApiGroup.AddMiddleware<typeof WebSearchGroup, LocationId>
|
||||
| HttpApiGroup.AddMiddleware<typeof UsageGroup, LocationId>
|
||||
| HttpApiGroup.AddMiddleware<typeof ProjectGroup, LocationId>
|
||||
| HttpApiGroup.AddMiddleware<typeof FileSystemGroup, LocationId>
|
||||
| HttpApiGroup.AddMiddleware<typeof CommandGroup, LocationId>
|
||||
| HttpApiGroup.AddMiddleware<typeof SkillGroup, LocationId>
|
||||
@@ -103,6 +102,7 @@ type ApiGroups<
|
||||
| typeof VoiceGroup
|
||||
| typeof PersistentPtyGroup
|
||||
| typeof CredentialGroup
|
||||
| typeof ProjectGroup
|
||||
| LocationGroups<LocationId>
|
||||
| LocationGroup<LocationId, LocationService>
|
||||
| PtyGroups<LocationId, LocationService>
|
||||
@@ -178,7 +178,7 @@ const makeApiFromGroup = <
|
||||
.add(IntegrationGroup.middleware(locationMiddleware))
|
||||
.add(makeMcpGroup(locationMiddleware))
|
||||
.add(CredentialGroup)
|
||||
.add(ProjectGroup.middleware(locationMiddleware))
|
||||
.add(ProjectGroup)
|
||||
.add(makeFormGroup(locationMiddleware))
|
||||
.add(makePermissionGroup(locationMiddleware, sessionLocationMiddleware))
|
||||
.add(FileSystemGroup.middleware(locationMiddleware))
|
||||
|
||||
@@ -30,6 +30,7 @@ export const makePermissionGroup = <
|
||||
query: LocationQuery,
|
||||
success: Location.response(Schema.Array(Permission.Request)),
|
||||
})
|
||||
.middleware(locationMiddleware)
|
||||
.annotateMerge(locationQueryOpenApi)
|
||||
.annotateMerge(
|
||||
OpenApi.annotations({
|
||||
@@ -43,13 +44,15 @@ export const makePermissionGroup = <
|
||||
HttpApiEndpoint.get("permission.saved.list", "/api/permission/saved", {
|
||||
query: Schema.Struct({ projectID: Project.ID.pipe(Schema.optional) }),
|
||||
success: Schema.Struct({ data: Schema.Array(PermissionSaved.Info) }),
|
||||
}).annotateMerge(
|
||||
OpenApi.annotations({
|
||||
identifier: "permission.saved.list",
|
||||
summary: "List saved permissions",
|
||||
description: "Retrieve saved permissions, optionally filtered by project.",
|
||||
}),
|
||||
),
|
||||
})
|
||||
.middleware(locationMiddleware)
|
||||
.annotateMerge(
|
||||
OpenApi.annotations({
|
||||
identifier: "permission.saved.list",
|
||||
summary: "List saved permissions",
|
||||
description: "Retrieve saved permissions, optionally filtered by project.",
|
||||
}),
|
||||
),
|
||||
)
|
||||
.add(
|
||||
HttpApiEndpoint.patch("permission.saved.update", "/api/permission/saved/:id", {
|
||||
@@ -81,8 +84,6 @@ export const makePermissionGroup = <
|
||||
}),
|
||||
),
|
||||
)
|
||||
// Effect applies group middleware only to endpoints already added; session endpoints use session placement below.
|
||||
.middleware(locationMiddleware)
|
||||
.add(
|
||||
HttpApiEndpoint.post("session.permission.create", "/api/session/:sessionID/permission", {
|
||||
params: { sessionID: Session.ID },
|
||||
|
||||
@@ -251,16 +251,14 @@ export const makeSessionGroup = <I extends HttpApiMiddleware.AnyId, S, FormI ext
|
||||
payload: Schema.Struct({ before: SessionMessage.ID.pipe(Schema.optional) }),
|
||||
success: Schema.Struct({ data: PublicSessionInfo }),
|
||||
error: [SessionNotFoundError, MessageNotFoundError, InvalidRequestError],
|
||||
})
|
||||
.middleware(sessionLocationMiddleware)
|
||||
.annotateMerge(
|
||||
OpenApi.annotations({
|
||||
identifier: "session.fork",
|
||||
summary: "Fork session",
|
||||
description:
|
||||
"Create a child session by copying projected history before a message. Omit before to copy the full history.",
|
||||
}),
|
||||
),
|
||||
}).annotateMerge(
|
||||
OpenApi.annotations({
|
||||
identifier: "session.fork",
|
||||
summary: "Fork session",
|
||||
description:
|
||||
"Create a child session by copying projected history before a message. Omit before to copy the full history.",
|
||||
}),
|
||||
),
|
||||
)
|
||||
.add(
|
||||
HttpApiEndpoint.post("session.switchAgent", "/api/session/:sessionID/agent", {
|
||||
@@ -268,15 +266,13 @@ export const makeSessionGroup = <I extends HttpApiMiddleware.AnyId, S, FormI ext
|
||||
payload: Schema.Struct({ agent: Agent.ID }),
|
||||
success: HttpApiSchema.NoContent,
|
||||
error: SessionNotFoundError,
|
||||
})
|
||||
.middleware(sessionLocationMiddleware)
|
||||
.annotateMerge(
|
||||
OpenApi.annotations({
|
||||
identifier: "session.switchAgent",
|
||||
summary: "Switch session agent",
|
||||
description: "Switch the agent used by subsequent provider turns.",
|
||||
}),
|
||||
),
|
||||
}).annotateMerge(
|
||||
OpenApi.annotations({
|
||||
identifier: "session.switchAgent",
|
||||
summary: "Switch session agent",
|
||||
description: "Switch the agent used by subsequent provider turns.",
|
||||
}),
|
||||
),
|
||||
)
|
||||
.add(
|
||||
HttpApiEndpoint.post("session.switchModel", "/api/session/:sessionID/model", {
|
||||
@@ -284,15 +280,13 @@ export const makeSessionGroup = <I extends HttpApiMiddleware.AnyId, S, FormI ext
|
||||
payload: Schema.Struct({ model: Model.Ref }),
|
||||
success: HttpApiSchema.NoContent,
|
||||
error: SessionNotFoundError,
|
||||
})
|
||||
.middleware(sessionLocationMiddleware)
|
||||
.annotateMerge(
|
||||
OpenApi.annotations({
|
||||
identifier: "session.switchModel",
|
||||
summary: "Switch session model",
|
||||
description: "Switch the model used by subsequent provider turns.",
|
||||
}),
|
||||
),
|
||||
}).annotateMerge(
|
||||
OpenApi.annotations({
|
||||
identifier: "session.switchModel",
|
||||
summary: "Switch session model",
|
||||
description: "Switch the model used by subsequent provider turns.",
|
||||
}),
|
||||
),
|
||||
)
|
||||
.add(
|
||||
HttpApiEndpoint.patch("session.update", "/api/session/:sessionID", {
|
||||
@@ -302,20 +296,19 @@ export const makeSessionGroup = <I extends HttpApiMiddleware.AnyId, S, FormI ext
|
||||
metadata: Session.Metadata.pipe(Schema.optional),
|
||||
permissions: Permission.Ruleset.pipe(Schema.optional),
|
||||
archived: Schema.Boolean.pipe(Schema.optional).annotate({
|
||||
description: "Archive the session with true or restore it with false. Repeating the current state is a no-op.",
|
||||
description:
|
||||
"Archive the session with true or restore it with false. Repeating the current state is a no-op.",
|
||||
}),
|
||||
}),
|
||||
success: HttpApiSchema.NoContent,
|
||||
error: SessionNotFoundError,
|
||||
})
|
||||
.middleware(sessionLocationMiddleware)
|
||||
.annotateMerge(
|
||||
OpenApi.annotations({
|
||||
identifier: "session.update",
|
||||
summary: "Update session",
|
||||
description: "Update mutable session properties.",
|
||||
}),
|
||||
),
|
||||
error: [SessionNotFoundError, LocationNotFoundError],
|
||||
}).annotateMerge(
|
||||
OpenApi.annotations({
|
||||
identifier: "session.update",
|
||||
summary: "Update session",
|
||||
description: "Update mutable session properties.",
|
||||
}),
|
||||
),
|
||||
)
|
||||
.add(
|
||||
HttpApiEndpoint.post("session.move", "/api/session/:sessionID/move", {
|
||||
@@ -460,15 +453,13 @@ export const makeSessionGroup = <I extends HttpApiMiddleware.AnyId, S, FormI ext
|
||||
params: { sessionID: Session.ID },
|
||||
success: HttpApiSchema.NoContent,
|
||||
error: [SessionNotFoundError, ServiceUnavailableError],
|
||||
})
|
||||
.middleware(sessionLocationMiddleware)
|
||||
.annotateMerge(
|
||||
OpenApi.annotations({
|
||||
identifier: "experimental.session.wait",
|
||||
summary: "Wait for session",
|
||||
description: "Wait for a session agent loop to become idle.",
|
||||
}),
|
||||
),
|
||||
}).annotateMerge(
|
||||
OpenApi.annotations({
|
||||
identifier: "experimental.session.wait",
|
||||
summary: "Wait for session",
|
||||
description: "Wait for a session agent loop to become idle.",
|
||||
}),
|
||||
),
|
||||
)
|
||||
.add(
|
||||
HttpApiEndpoint.post("session.revert.stage", "/api/session/:sessionID/revert/stage", {
|
||||
@@ -500,9 +491,7 @@ export const makeSessionGroup = <I extends HttpApiMiddleware.AnyId, S, FormI ext
|
||||
params: { sessionID: Session.ID },
|
||||
success: HttpApiSchema.NoContent,
|
||||
error: [SessionNotFoundError, SessionBusyError],
|
||||
})
|
||||
.middleware(sessionLocationMiddleware)
|
||||
.annotateMerge(OpenApi.annotations({ identifier: "session.revert.commit", summary: "Commit staged revert" })),
|
||||
}).annotateMerge(OpenApi.annotations({ identifier: "session.revert.commit", summary: "Commit staged revert" })),
|
||||
)
|
||||
.add(
|
||||
HttpApiEndpoint.get("session.context", "/api/session/:sessionID/context", {
|
||||
@@ -592,15 +581,13 @@ export const makeSessionGroup = <I extends HttpApiMiddleware.AnyId, S, FormI ext
|
||||
success: Schema.Struct({ data: Schema.Array(InstructionEntry.Info) }),
|
||||
error: SessionNotFoundError,
|
||||
},
|
||||
)
|
||||
.middleware(sessionLocationMiddleware)
|
||||
.annotateMerge(
|
||||
OpenApi.annotations({
|
||||
identifier: "experimental.session.instructions.entry.list",
|
||||
summary: "List instruction entries",
|
||||
description: "List API-managed instruction entries attached to the session.",
|
||||
}),
|
||||
),
|
||||
).annotateMerge(
|
||||
OpenApi.annotations({
|
||||
identifier: "experimental.session.instructions.entry.list",
|
||||
summary: "List instruction entries",
|
||||
description: "List API-managed instruction entries attached to the session.",
|
||||
}),
|
||||
),
|
||||
)
|
||||
.add(
|
||||
HttpApiEndpoint.put(
|
||||
@@ -612,16 +599,14 @@ export const makeSessionGroup = <I extends HttpApiMiddleware.AnyId, S, FormI ext
|
||||
success: HttpApiSchema.NoContent,
|
||||
error: [SessionNotFoundError, InstructionEntry.ValueTooLargeError],
|
||||
},
|
||||
)
|
||||
.middleware(sessionLocationMiddleware)
|
||||
.annotateMerge(
|
||||
OpenApi.annotations({
|
||||
identifier: "experimental.session.instructions.entry.put",
|
||||
summary: "Put instruction entry",
|
||||
description:
|
||||
"Attach or replace one durable instruction entry. Changes announce as updates at the next step boundary.",
|
||||
}),
|
||||
),
|
||||
).annotateMerge(
|
||||
OpenApi.annotations({
|
||||
identifier: "experimental.session.instructions.entry.put",
|
||||
summary: "Put instruction entry",
|
||||
description:
|
||||
"Attach or replace one durable instruction entry. Changes announce as updates at the next step boundary.",
|
||||
}),
|
||||
),
|
||||
)
|
||||
.add(
|
||||
HttpApiEndpoint.delete(
|
||||
@@ -632,16 +617,13 @@ export const makeSessionGroup = <I extends HttpApiMiddleware.AnyId, S, FormI ext
|
||||
success: HttpApiSchema.NoContent,
|
||||
error: SessionNotFoundError,
|
||||
},
|
||||
)
|
||||
.middleware(sessionLocationMiddleware)
|
||||
.annotateMerge(
|
||||
OpenApi.annotations({
|
||||
identifier: "experimental.session.instructions.entry.remove",
|
||||
summary: "Remove instruction entry",
|
||||
description:
|
||||
"Remove one instruction entry; the removal is announced to the model at the next step boundary.",
|
||||
}),
|
||||
),
|
||||
).annotateMerge(
|
||||
OpenApi.annotations({
|
||||
identifier: "experimental.session.instructions.entry.remove",
|
||||
summary: "Remove instruction entry",
|
||||
description: "Remove one instruction entry; the removal is announced to the model at the next step boundary.",
|
||||
}),
|
||||
),
|
||||
)
|
||||
.add(
|
||||
HttpApiEndpoint.post("session.generate", "/api/session/:sessionID/generate", {
|
||||
@@ -691,32 +673,28 @@ export const makeSessionGroup = <I extends HttpApiMiddleware.AnyId, S, FormI ext
|
||||
}),
|
||||
}).annotate({ identifier: "SessionInterruptResponse" }),
|
||||
error: SessionNotFoundError,
|
||||
})
|
||||
.middleware(sessionLocationMiddleware)
|
||||
.annotateMerge(
|
||||
OpenApi.annotations({
|
||||
identifier: "session.interrupt",
|
||||
summary: "Interrupt session execution",
|
||||
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.",
|
||||
}),
|
||||
),
|
||||
}).annotateMerge(
|
||||
OpenApi.annotations({
|
||||
identifier: "session.interrupt",
|
||||
summary: "Interrupt session execution",
|
||||
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.",
|
||||
}),
|
||||
),
|
||||
)
|
||||
.add(
|
||||
HttpApiEndpoint.post("session.background", "/api/session/:sessionID/background", {
|
||||
params: { sessionID: Session.ID },
|
||||
success: HttpApiSchema.NoContent,
|
||||
error: SessionNotFoundError,
|
||||
})
|
||||
.middleware(sessionLocationMiddleware)
|
||||
.annotateMerge(
|
||||
OpenApi.annotations({
|
||||
identifier: "session.background",
|
||||
summary: "Background blocking session tools",
|
||||
description:
|
||||
"Move active foreground backgroundable tools for this session into background observation. Idle requests are a no-op.",
|
||||
}),
|
||||
),
|
||||
}).annotateMerge(
|
||||
OpenApi.annotations({
|
||||
identifier: "session.background",
|
||||
summary: "Background blocking session tools",
|
||||
description:
|
||||
"Move active foreground backgroundable tools for this session into background observation. Idle requests are a no-op.",
|
||||
}),
|
||||
),
|
||||
)
|
||||
.add(
|
||||
HttpApiEndpoint.get("session.message", "/api/session/:sessionID/message/:messageID", {
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { Instance } from "@opencode/core/instance/service"
|
||||
import { Session } from "@opencode/core/session"
|
||||
import { SessionStats } from "@opencode/core/session/stats"
|
||||
import { SessionTitle } from "@opencode/core/session/title"
|
||||
@@ -33,6 +34,10 @@ export const SessionHandler = HttpApiBuilder.group(Api, "server.session", (handl
|
||||
Effect.gen(function* () {
|
||||
const session = yield* Session.Service
|
||||
const transfer = yield* SessionTransfer.Service
|
||||
const instructions = yield* InstructionEntry.Service
|
||||
const instances = yield* Instance.Service
|
||||
const requireSession = (sessionID: Session.ID) =>
|
||||
session.get(sessionID).pipe(Effect.catchTag("Session.NotFoundError", missingSession))
|
||||
const requireOwnedForm = Effect.fnUntraced(function* (sessionID: Form.Info["sessionID"], formID: Form.ID) {
|
||||
const form = yield* Form.Service
|
||||
const info = yield* form.get(formID).pipe(Effect.catchTag("Form.NotFoundError", () => missingForm(formID)))
|
||||
@@ -225,15 +230,17 @@ export const SessionHandler = HttpApiBuilder.group(Api, "server.session", (handl
|
||||
.handle(
|
||||
"session.update",
|
||||
Effect.fn(function* (ctx) {
|
||||
yield* session.get(ctx.params.sessionID).pipe(Effect.catchTag("Session.NotFoundError", missingSession))
|
||||
const info = yield* requireSession(ctx.params.sessionID)
|
||||
if (ctx.payload.title !== undefined) {
|
||||
if (ctx.payload.title) {
|
||||
yield* session
|
||||
.rename({ sessionID: ctx.params.sessionID, title: ctx.payload.title })
|
||||
.pipe(Effect.catchTag("Session.NotFoundError", missingSession))
|
||||
} else {
|
||||
const title = yield* SessionTitle.Service
|
||||
yield* title.generate(ctx.params.sessionID)
|
||||
yield* SessionTitle.Service.use((title) => title.generate(ctx.params.sessionID)).pipe(
|
||||
instances.provide(info),
|
||||
locationErrors,
|
||||
)
|
||||
}
|
||||
}
|
||||
if (ctx.payload.metadata !== undefined)
|
||||
@@ -543,14 +550,14 @@ export const SessionHandler = HttpApiBuilder.group(Api, "server.session", (handl
|
||||
.handle(
|
||||
"session.instructions.entry.list",
|
||||
Effect.fn(function* (ctx) {
|
||||
const instructions = yield* InstructionEntry.Service
|
||||
yield* requireSession(ctx.params.sessionID)
|
||||
return { data: yield* instructions.list(ctx.params.sessionID) }
|
||||
}),
|
||||
)
|
||||
.handle(
|
||||
"session.instructions.entry.put",
|
||||
Effect.fn(function* (ctx) {
|
||||
const instructions = yield* InstructionEntry.Service
|
||||
yield* requireSession(ctx.params.sessionID)
|
||||
yield* instructions.put({ sessionID: ctx.params.sessionID, key: ctx.params.key, value: ctx.payload.value })
|
||||
return HttpApiSchema.NoContent.make()
|
||||
}),
|
||||
@@ -558,7 +565,7 @@ export const SessionHandler = HttpApiBuilder.group(Api, "server.session", (handl
|
||||
.handle(
|
||||
"session.instructions.entry.remove",
|
||||
Effect.fn(function* (ctx) {
|
||||
const instructions = yield* InstructionEntry.Service
|
||||
yield* requireSession(ctx.params.sessionID)
|
||||
yield* instructions.remove({ sessionID: ctx.params.sessionID, key: ctx.params.key })
|
||||
return HttpApiSchema.NoContent.make()
|
||||
}),
|
||||
@@ -590,6 +597,7 @@ export const SessionHandler = HttpApiBuilder.group(Api, "server.session", (handl
|
||||
.handle(
|
||||
"session.interrupt",
|
||||
Effect.fn(function* (ctx) {
|
||||
yield* requireSession(ctx.params.sessionID)
|
||||
return { interrupted: yield* session.interrupt(ctx.params.sessionID, { resume: ctx.query.resume }) }
|
||||
}),
|
||||
)
|
||||
|
||||
@@ -18,6 +18,7 @@ import { Worktree } from "@opencode/core/worktree"
|
||||
import { Session } from "@opencode/core/session"
|
||||
import { Instance } from "@opencode/core/instance/service"
|
||||
import { SessionTransfer } from "@opencode/core/session/transfer"
|
||||
import { InstructionEntry } from "@opencode/core/session/instruction-entry"
|
||||
import { ShellSelect } from "@opencode/core/shell/select"
|
||||
import { Job } from "@opencode/core/job"
|
||||
import { Mcp } from "@opencode/core/mcp/index"
|
||||
@@ -63,6 +64,7 @@ const applicationServiceNodes = [
|
||||
Session.node,
|
||||
Instance.node,
|
||||
SessionTransfer.node,
|
||||
InstructionEntry.node,
|
||||
SdkPlugins.node,
|
||||
PluginUpdate.node,
|
||||
PermissionSaved.node,
|
||||
|
||||
@@ -42,7 +42,6 @@ it.live("returns LocationNotFoundError for a missing folder and recovers once it
|
||||
"/api/model",
|
||||
"/api/integration",
|
||||
`/api/session/${session.id}/permission`,
|
||||
`/api/experimental/session/${session.id}/instructions/entries`,
|
||||
`/api/session/${session.id}/form`,
|
||||
"/api/session/global/form",
|
||||
]
|
||||
@@ -73,6 +72,59 @@ it.live("returns LocationNotFoundError for a missing folder and recovers once it
|
||||
}),
|
||||
)
|
||||
|
||||
it.live("manages a session whose directory was deleted", () =>
|
||||
Effect.gen(function* () {
|
||||
const config = yield* Effect.acquireDisposable(Effect.promise(() => tmpdir("opencode-deleted-directory-")))
|
||||
const directory = path.join(config.path, "project")
|
||||
yield* Effect.promise(() => fs.mkdir(directory))
|
||||
const handler = yield* ServerFetch.make({ ...options, config: { directory: config.path } })
|
||||
const request = (endpoint: string, method: string, body?: unknown) =>
|
||||
Effect.promise(() =>
|
||||
handler(
|
||||
new Request(`http://opencode.local${endpoint}`, {
|
||||
method,
|
||||
headers: { "content-type": "application/json" },
|
||||
body: body === undefined ? undefined : JSON.stringify(body),
|
||||
}),
|
||||
),
|
||||
)
|
||||
const created = yield* request("/api/session", "POST", { location: { directory } })
|
||||
expect(created.status).toBe(200)
|
||||
const session = Schema.decodeUnknownSync(Schema.Struct({ data: Session.Info }))(
|
||||
yield* Effect.promise(() => created.json()),
|
||||
).data
|
||||
yield* Effect.promise(() => fs.rm(directory, { recursive: true }))
|
||||
|
||||
const statuses = [
|
||||
yield* request(`/api/session/${session.id}`, "PATCH", { title: "Renamed" }),
|
||||
yield* request(`/api/session/${session.id}`, "PATCH", { archived: true }),
|
||||
yield* request(`/api/session/${session.id}/interrupt`, "POST"),
|
||||
yield* request(`/api/experimental/session/${session.id}/instructions/entries`, "GET"),
|
||||
].map((response) => response.status)
|
||||
expect(statuses).toEqual([204, 204, 200, 200])
|
||||
|
||||
const fetched = yield* request(`/api/session/${session.id}`, "GET")
|
||||
const updated = Schema.decodeUnknownSync(Schema.Struct({ data: Session.Info }))(
|
||||
yield* Effect.promise(() => fetched.json()),
|
||||
).data
|
||||
expect(updated.title).toBe("Renamed")
|
||||
expect(updated.time.archived).toBeDefined()
|
||||
|
||||
// Title generation still runs in the session's folder.
|
||||
const generated = yield* request(`/api/session/${session.id}`, "PATCH", { title: "" })
|
||||
expect(generated.status).toBe(404)
|
||||
expect(yield* Effect.promise(() => generated.json())).toEqual({
|
||||
_tag: "LocationNotFoundError",
|
||||
location: { directory },
|
||||
message: `Location not found: ${directory}`,
|
||||
})
|
||||
|
||||
const missing = yield* request("/api/session/ses_missing/interrupt", "POST")
|
||||
expect(missing.status).toBe(404)
|
||||
expect(((yield* Effect.promise(() => missing.json())) as { _tag: string })._tag).toBe("SessionNotFoundError")
|
||||
}),
|
||||
)
|
||||
|
||||
type Handler = (request: Request) => Promise<Response>
|
||||
|
||||
function occupy(port: number, cancel = false) {
|
||||
|
||||
Reference in New Issue
Block a user