Skip to content

Commit 3563850

Browse files
authored
fix(opencode-go): warm context metadata from provider catalog (#92913)
Register OpenCode Go's provider-owned static catalog so lifecycle cache warmup supplies the correct context window to memory flush and compaction without persisting catalog rows in user config. Fixes #92912. Co-authored-by: kumaxs <[email protected]>
1 parent a189baa commit 3563850

4 files changed

Lines changed: 61 additions & 0 deletions

File tree

extensions/opencode-go/index.test.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { beforeEach, describe, expect, it, vi } from "vitest";
1111
import plugin from "./index.js";
1212
import manifest from "./openclaw.plugin.json" with { type: "json" };
1313
import { buildOpencodeGoLiveProviderConfig } from "./provider-catalog.js";
14+
import opencodeGoProviderDiscovery from "./provider-discovery.js";
1415

1516
function requireRecord(value: unknown, label: string): Record<string, unknown> {
1617
if (value === null || typeof value !== "object" || Array.isArray(value)) {
@@ -209,9 +210,25 @@ describe("opencode-go provider plugin", () => {
209210
});
210211

211212
it("loads OpenCode Go model discovery through the provider runtime", () => {
213+
expect(manifest.providerCatalogEntry).toBe("./provider-discovery.ts");
212214
expect(manifest.modelCatalog.discovery["opencode-go"]).toBe("runtime");
213215
});
214216

217+
it("exposes the complete offline catalog through provider discovery", async () => {
218+
const result = await opencodeGoProviderDiscovery.staticCatalog?.run({} as never);
219+
if (!result || !("provider" in result)) {
220+
throw new Error("expected OpenCode Go static provider");
221+
}
222+
const deepSeekPro = result.provider.models.find((model) => model.id === "deepseek-v4-pro");
223+
224+
expect(result.provider.models).toHaveLength(18);
225+
expect(deepSeekPro).toMatchObject({
226+
provider: "opencode-go",
227+
contextWindow: 1_000_000,
228+
maxTokens: 384_000,
229+
});
230+
});
231+
215232
it("skips live OpenCode Go catalog discovery when no shared key is configured", async () => {
216233
const provider = await registerSingleProviderPlugin(plugin);
217234

extensions/opencode-go/openclaw.plugin.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"activation": {
44
"onStartup": false
55
},
6+
"providerCatalogEntry": "./provider-discovery.ts",
67
"enabledByDefault": true,
78
"providers": ["opencode-go"],
89
"providerEndpoints": [
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Opencode Go provider module exposes offline catalog metadata to core discovery.
2+
import type { ProviderPlugin } from "openclaw/plugin-sdk/provider-model-shared";
3+
import { buildStaticOpencodeGoProviderConfig } from "./provider-catalog.js";
4+
5+
const opencodeGoProviderDiscovery: ProviderPlugin = {
6+
id: "opencode-go",
7+
label: "OpenCode Go",
8+
docsPath: "/providers/models",
9+
auth: [],
10+
staticCatalog: {
11+
order: "simple",
12+
run: async () => ({
13+
provider: buildStaticOpencodeGoProviderConfig(),
14+
}),
15+
},
16+
};
17+
18+
export default opencodeGoProviderDiscovery;
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { afterEach, describe, expect, it } from "vitest";
2+
import { resolveMemoryFlushContextWindowTokens } from "../auto-reply/reply/memory-flush.js";
3+
import type { OpenClawConfig } from "../config/types.openclaw.js";
4+
import { refreshContextWindowCache, resetContextWindowCacheForTest } from "./context.js";
5+
6+
describe("OpenCode Go context metadata", () => {
7+
afterEach(() => {
8+
resetContextWindowCacheForTest();
9+
});
10+
11+
it("warms the provider-owned context window without writing model config", async () => {
12+
const cfg: OpenClawConfig = {};
13+
14+
await refreshContextWindowCache(cfg);
15+
16+
expect(
17+
resolveMemoryFlushContextWindowTokens({
18+
cfg,
19+
provider: "opencode-go",
20+
modelId: "deepseek-v4-pro",
21+
}),
22+
).toBe(1_000_000);
23+
expect(cfg.models).toBeUndefined();
24+
});
25+
});

0 commit comments

Comments
 (0)