Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -164,17 +164,25 @@ function planRequest(
return Effect.gen(function* () {
const url = requestURL(request)
const envWorkspaceID = configuredWorkspaceID()
const local = shouldStayOnControlPlane(request, url)
const workspaceID = url.pathname.startsWith("/api/")
? selectedV2WorkspaceID(url, sessionWorkspaceID)
: selectedWorkspaceID(url, sessionWorkspaceID)
if (workspaceID === InvalidWorkspaceID) return RequestPlan.InvalidWorkspace()
// Control-plane reads can carry stale workspace params from clients; route
// them by directory instead of requiring the workspace to still exist.
if (local)
return RequestPlan.Local({
directory: defaultDirectory(request, url),
workspaceID: envWorkspaceID ?? workspaceID,
})
const workspace = yield* resolveWorkspace(workspaceID, envWorkspaceID)

if (workspaceID && workspace === undefined && !envWorkspaceID) {
return RequestPlan.MissingWorkspace({ workspaceID })
}

if (workspace !== undefined && !envWorkspaceID && !shouldStayOnControlPlane(request, url)) {
if (workspace !== undefined && !envWorkspaceID) {
return yield* planWorkspaceRequest(request, url, workspace)
}

Expand Down
1 change: 1 addition & 0 deletions packages/opencode/src/server/shared/workspace-routing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ type Rule = { method?: string; path: string; exact?: boolean; action: "local" |

const RULES: Array<Rule> = [
{ path: "/experimental/workspace", action: "local" },
{ method: "GET", path: "/agent", exact: true, action: "local" },
{ path: "/session/status", action: "forward" },
{ method: "GET", path: "/session", action: "local" },
]
Expand Down
28 changes: 28 additions & 0 deletions packages/opencode/test/server/httpapi-exercise/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,34 @@ const scenarios: Scenario[] = [
.status(400, undefined, "status"),
http.protected.get("/command", "command.list").json(200, array, "status"),
http.protected.get("/agent", "app.agents").json(200, array, "status"),
http.protected
.get("/agent", "app.agents.custom")
.inProject({
git: true,
config: {
agent: {
"custom-primary": {
mode: "primary",
description: "Custom primary agent",
},
},
},
})
.at((ctx) => ({
path: `/agent?directory=${encodeURIComponent(ctx.directory ?? "")}&workspace=wrk_stale`,
headers: ctx.headers(),
}))
.json(
200,
(body) => {
array(body)
check(
body.some((item) => isRecord(item) && item.name === "custom-primary" && item.mode === "primary"),
"agent list should include custom primary agents from the requested directory",
)
},
"status",
),
http.protected.get("/skill", "app.skills").json(200, array, "status"),
http.protected.get("/lsp", "lsp.status").json(200, array),
http.protected.get("/formatter", "formatter.status").json(200, array),
Expand Down
Loading