mirror of
https://github.com/anomalyco/opencode.git
synced 2026-11-16 05:01:03 +03:00
fix(core): fetch Console instructions and skills only when the config says the workspace has them (#63259)
This commit is contained in:
@@ -65,6 +65,8 @@ const Unauthorized = Schema.Struct({ _tag: Schema.Literal("Unauthorized") })
|
||||
const ConsoleInstructions = Schema.Struct({
|
||||
instructions: Schema.Array(Schema.Struct({ id: Schema.String, content: Schema.String })),
|
||||
})
|
||||
/** The `GET /api/v2/config` response header Console sends while the caller has workspace instructions and skills. */
|
||||
const listsHeader = "x-opencode-instructions-skills"
|
||||
const ConsoleSkills = Schema.Struct({
|
||||
skills: Schema.Array(Schema.Struct({ slug: Schema.String, version: Schema.String })),
|
||||
})
|
||||
@@ -259,7 +261,7 @@ export const OpencodePlugin = define<
|
||||
"failed" in result ? Effect.fail(result.failed) : Effect.succeed(result.remote),
|
||||
),
|
||||
Effect.flatMap((remote) =>
|
||||
remote
|
||||
remote?.lists
|
||||
? Effect.all(
|
||||
{
|
||||
instructions: list(
|
||||
@@ -277,7 +279,7 @@ export const OpencodePlugin = define<
|
||||
},
|
||||
{ concurrency: 2 },
|
||||
).pipe(Effect.map((lists): ConsoleConfig => ({ ...remote, ...lists })))
|
||||
: Effect.succeed(undefined),
|
||||
: Effect.succeed(remote && { ...remote, instructions: [], skills: [] }),
|
||||
),
|
||||
Effect.map((remote) => ({
|
||||
remote,
|
||||
@@ -604,8 +606,9 @@ function fetchConfig(http: HttpClient.HttpClient, value: Credential.Key | Creden
|
||||
})
|
||||
}
|
||||
const watches = response.headers[OpencodeWatches.header] !== undefined
|
||||
const lists = response.headers[listsHeader] !== undefined
|
||||
const body = yield* HttpClientResponse.filterStatusOk(response).pipe(Effect.flatMap((ok) => ok.json))
|
||||
return { ...(yield* Schema.decodeUnknownEffect(ConfigIntegration.Remote)(body)), watches }
|
||||
return { ...(yield* Schema.decodeUnknownEffect(ConfigIntegration.Remote)(body)), watches, lists }
|
||||
}),
|
||||
),
|
||||
Effect.scoped,
|
||||
|
||||
@@ -115,7 +115,7 @@ function consoleServer(orgID: string | null | undefined, unavailable = false) {
|
||||
if (path === "/api/v2/config") {
|
||||
config.push({ authorization: request.headers.get("authorization"), orgID: request.headers.get("x-org-id") })
|
||||
if (orgID === "org-missing") return new Response("Forbidden", { status: 403 })
|
||||
return Response.json({ providers: {} })
|
||||
return Response.json({ providers: {} }, withLists)
|
||||
}
|
||||
return new Response("Not found", { status: 404 })
|
||||
},
|
||||
@@ -123,6 +123,9 @@ function consoleServer(orgID: string | null | undefined, unavailable = false) {
|
||||
return { server, config, requests, agents }
|
||||
}
|
||||
|
||||
// Console's config answer while the workspace has instructions and skills.
|
||||
const withLists = { headers: { "x-opencode-instructions-skills": "1" } }
|
||||
|
||||
function required<T>(value: T | undefined): T {
|
||||
if (value === undefined) throw new Error("Expected value")
|
||||
return value
|
||||
@@ -1394,8 +1397,6 @@ describe("OpencodePlugin", () => {
|
||||
)
|
||||
expect(requests).toEqual([
|
||||
"https://opencode.ai/console/api/v2/config",
|
||||
"https://opencode.ai/console/api/v2/instructions",
|
||||
"https://opencode.ai/console/api/v2/skills",
|
||||
"https://opencode.ai/console/api/websearch",
|
||||
])
|
||||
}),
|
||||
@@ -1580,7 +1581,7 @@ describe("OpencodePlugin", () => {
|
||||
authorization: request.headers.get("authorization"),
|
||||
orgID: request.headers.get("x-org-id"),
|
||||
})
|
||||
if (url.pathname === "/api/v2/config") return Response.json({ providers: {} })
|
||||
if (url.pathname === "/api/v2/config") return Response.json({ providers: {} }, withLists)
|
||||
if (url.pathname === "/api/v2/skills") return Response.json({ skills: [{ slug: "deploy", version: "1" }] })
|
||||
if (url.pathname === "/api/v2/skills/deploy") {
|
||||
// Skill archives come from presigned storage on its own host, where the signature covers the encoding.
|
||||
@@ -1634,7 +1635,7 @@ describe("OpencodePlugin", () => {
|
||||
const server = {
|
||||
fetch: (request: Request) => {
|
||||
const path = new URL(request.url).pathname
|
||||
if (path === "/api/v2/config") return Response.json({ providers: {} })
|
||||
if (path === "/api/v2/config") return Response.json({ providers: {} }, withLists)
|
||||
if ((path === "/api/v2/instructions" || path === "/api/v2/skills") && state.lists !== 200)
|
||||
return new Response(null, { status: state.lists })
|
||||
if (path === "/api/v2/instructions")
|
||||
@@ -1692,7 +1693,8 @@ describe("OpencodePlugin", () => {
|
||||
const server = {
|
||||
fetch: (request: Request) => {
|
||||
const path = new URL(request.url).pathname
|
||||
if (path === "/api/v2/config") return Response.json({ providers: {}, policies: [sudo] })
|
||||
if (path === "/api/v2/config")
|
||||
return Response.json({ providers: {}, policies: [sudo] }, withLists)
|
||||
if (path !== "/api/v2/instructions" && path !== "/api/v2/skills") return new Response(null, { status: 404 })
|
||||
if (state.lists === "down") return new Response("Unavailable", { status: 503 })
|
||||
if (path === "/api/v2/skills") return Response.json({ skills: [] })
|
||||
@@ -1745,7 +1747,7 @@ describe("OpencodePlugin", () => {
|
||||
fetch: async (request: Request) => {
|
||||
const path = new URL(request.url).pathname
|
||||
requests.push(path)
|
||||
if (path === "/api/v2/config") return Response.json({ providers: {} })
|
||||
if (path === "/api/v2/config") return Response.json({ providers: {} }, withLists)
|
||||
if (path === "/api/v2/instructions") {
|
||||
await skillsRequested.promise
|
||||
return Response.json({ instructions: [{ id: "style", content: "Use tabs." }] })
|
||||
@@ -1783,7 +1785,7 @@ describe("OpencodePlugin", () => {
|
||||
fetch: (request) => {
|
||||
const url = new URL(request.url)
|
||||
downloads.push({ path: url.pathname, authorization: request.headers.get("authorization") })
|
||||
if (url.pathname === "/api/v2/config") return Response.json({ providers: {} })
|
||||
if (url.pathname === "/api/v2/config") return Response.json({ providers: {} }, withLists)
|
||||
if (url.pathname === "/api/v2/skills") return Response.json({ skills: [{ slug: "deploy", version: "1" }] })
|
||||
if (url.pathname === "/api/v2/skills/deploy")
|
||||
return Response.redirect(`${url.origin}/assets/deploy.json`, 302)
|
||||
|
||||
Reference in New Issue
Block a user