Skip to content

Commit 1cb7df7

Browse files
authored
refactor(provider): flow branded ProviderID/ModelID through internal signatures (#17182)
1 parent a4f8d66 commit 1cb7df7

24 files changed

Lines changed: 227 additions & 205 deletions

File tree

bun.lock

Lines changed: 12 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
"dompurify": "3.3.1",
4444
"drizzle-kit": "1.0.0-beta.16-ea816b6",
4545
"drizzle-orm": "1.0.0-beta.16-ea816b6",
46-
"effect": "4.0.0-beta.29",
46+
"effect": "4.0.0-beta.31",
4747
"ai": "5.0.124",
4848
"hono": "4.10.7",
4949
"hono-openapi": "1.1.2",

packages/app/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
"@solidjs/router": "catalog:",
5757
"@thisbeyond/solid-dnd": "0.7.5",
5858
"diff": "catalog:",
59-
"effect": "4.0.0-beta.29",
59+
"effect": "4.0.0-beta.31",
6060
"fuzzysort": "catalog:",
6161
"ghostty-web": "github:anomalyco/ghostty-web#main",
6262
"luxon": "catalog:",

packages/desktop-electron/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
"@solid-primitives/storage": "catalog:",
3131
"@solidjs/meta": "catalog:",
3232
"@solidjs/router": "0.15.4",
33-
"effect": "4.0.0-beta.29",
33+
"effect": "4.0.0-beta.31",
3434
"electron-log": "^5",
3535
"electron-store": "^10",
3636
"electron-updater": "^6",

packages/opencode/src/acp/agent.ts

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ import { Hash } from "../util/hash"
3535
import { ACPSessionManager } from "./session"
3636
import type { ACPConfig } from "./types"
3737
import { Provider } from "../provider/provider"
38-
import { ProviderID } from "../provider/schema"
38+
import { ModelID, ProviderID } from "../provider/schema"
3939
import { Agent as AgentModule } from "../agent/agent"
4040
import { Installation } from "@/installation"
4141
import { MessageV2 } from "@/session/message-v2"
@@ -56,8 +56,8 @@ export namespace ACP {
5656

5757
async function getContextLimit(
5858
sdk: OpencodeClient,
59-
providerID: string,
60-
modelID: string,
59+
providerID: ProviderID,
60+
modelID: ModelID,
6161
directory: string,
6262
): Promise<number | null> {
6363
const providers = await sdk.config
@@ -97,7 +97,8 @@ export namespace ACP {
9797
if (!lastAssistant) return
9898

9999
const msg = lastAssistant.info
100-
const size = await getContextLimit(sdk, msg.providerID, msg.modelID, directory)
100+
if (!msg.providerID || !msg.modelID) return
101+
const size = await getContextLimit(sdk, ProviderID.make(msg.providerID), ModelID.make(msg.modelID), directory)
101102

102103
if (!size) {
103104
// Cannot calculate usage without known context size
@@ -637,8 +638,8 @@ export namespace ACP {
637638
if (lastUser?.role === "user") {
638639
result.models.currentModelId = `${lastUser.model.providerID}/${lastUser.model.modelID}`
639640
this.sessionManager.setModel(sessionId, {
640-
providerID: lastUser.model.providerID,
641-
modelID: lastUser.model.modelID,
641+
providerID: ProviderID.make(lastUser.model.providerID),
642+
modelID: ModelID.make(lastUser.model.modelID),
642643
})
643644
if (result.modes?.availableModes.some((m) => m.id === lastUser.agent)) {
644645
result.modes.currentModeId = lastUser.agent
@@ -1526,7 +1527,7 @@ export namespace ACP {
15261527
}
15271528
}
15281529

1529-
async function defaultModel(config: ACPConfig, cwd?: string) {
1530+
async function defaultModel(config: ACPConfig, cwd?: string): Promise<{ providerID: ProviderID; modelID: ModelID }> {
15301531
const sdk = config.sdk
15311532
const configured = config.defaultModel
15321533
if (configured) return configured
@@ -1538,11 +1539,7 @@ export namespace ACP {
15381539
.then((resp) => {
15391540
const cfg = resp.data
15401541
if (!cfg || !cfg.model) return undefined
1541-
const parsed = Provider.parseModel(cfg.model)
1542-
return {
1543-
providerID: parsed.providerID,
1544-
modelID: parsed.modelID,
1545-
}
1542+
return Provider.parseModel(cfg.model)
15461543
})
15471544
.catch((error) => {
15481545
log.error("failed to load user config for default model", { error })
@@ -1567,13 +1564,13 @@ export namespace ACP {
15671564
const opencodeProvider = providers.find((p) => p.id === "opencode")
15681565
if (opencodeProvider) {
15691566
if (opencodeProvider.models["big-pickle"]) {
1570-
return { providerID: "opencode", modelID: "big-pickle" }
1567+
return { providerID: ProviderID.opencode, modelID: ModelID.make("big-pickle") }
15711568
}
15721569
const [best] = Provider.sort(Object.values(opencodeProvider.models))
15731570
if (best) {
15741571
return {
1575-
providerID: best.providerID,
1576-
modelID: best.id,
1572+
providerID: ProviderID.make(best.providerID),
1573+
modelID: ModelID.make(best.id),
15771574
}
15781575
}
15791576
}
@@ -1582,14 +1579,14 @@ export namespace ACP {
15821579
const [best] = Provider.sort(models)
15831580
if (best) {
15841581
return {
1585-
providerID: best.providerID,
1586-
modelID: best.id,
1582+
providerID: ProviderID.make(best.providerID),
1583+
modelID: ModelID.make(best.id),
15871584
}
15881585
}
15891586

15901587
if (specified) return specified
15911588

1592-
return { providerID: "opencode", modelID: "big-pickle" }
1589+
return { providerID: ProviderID.opencode, modelID: ModelID.make("big-pickle") }
15931590
}
15941591

15951592
function parseUri(
@@ -1652,7 +1649,7 @@ export namespace ACP {
16521649

16531650
function modelVariantsFromProviders(
16541651
providers: Array<{ id: string; models: Record<string, { variants?: Record<string, any> }> }>,
1655-
model: { providerID: string; modelID: string },
1652+
model: { providerID: ProviderID; modelID: ModelID },
16561653
): string[] {
16571654
const provider = providers.find((entry) => entry.id === model.providerID)
16581655
if (!provider) return []
@@ -1688,7 +1685,7 @@ export namespace ACP {
16881685
}
16891686

16901687
function formatModelIdWithVariant(
1691-
model: { providerID: string; modelID: string },
1688+
model: { providerID: ProviderID; modelID: ModelID },
16921689
variant: string | undefined,
16931690
availableVariants: string[],
16941691
includeVariant: boolean,
@@ -1699,7 +1696,7 @@ export namespace ACP {
16991696
}
17001697

17011698
function buildVariantMeta(input: {
1702-
model: { providerID: string; modelID: string }
1699+
model: { providerID: ProviderID; modelID: ModelID }
17031700
variant?: string
17041701
availableVariants: string[]
17051702
}) {
@@ -1715,7 +1712,7 @@ export namespace ACP {
17151712
function parseModelSelection(
17161713
modelId: string,
17171714
providers: Array<{ id: string; models: Record<string, { variants?: Record<string, any> }> }>,
1718-
): { model: { providerID: string; modelID: string }; variant?: string } {
1715+
): { model: { providerID: ProviderID; modelID: ModelID }; variant?: string } {
17191716
const parsed = Provider.parseModel(modelId)
17201717
const provider = providers.find((p) => p.id === parsed.providerID)
17211718
if (!provider) {
@@ -1735,7 +1732,7 @@ export namespace ACP {
17351732
const baseModelInfo = provider.models[baseModelId]
17361733
if (baseModelInfo?.variants && candidateVariant in baseModelInfo.variants) {
17371734
return {
1738-
model: { providerID: parsed.providerID, modelID: baseModelId },
1735+
model: { providerID: parsed.providerID, modelID: ModelID.make(baseModelId) },
17391736
variant: candidateVariant,
17401737
}
17411738
}

packages/opencode/src/acp/types.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
import type { McpServer } from "@agentclientprotocol/sdk"
22
import type { OpencodeClient } from "@opencode-ai/sdk/v2"
3+
import type { ProviderID, ModelID } from "../provider/schema"
34

45
export interface ACPSessionState {
56
id: string
67
cwd: string
78
mcpServers: McpServer[]
89
createdAt: Date
910
model?: {
10-
providerID: string
11-
modelID: string
11+
providerID: ProviderID
12+
modelID: ModelID
1213
}
1314
variant?: string
1415
modeId?: string
@@ -17,7 +18,7 @@ export interface ACPSessionState {
1718
export interface ACPConfig {
1819
sdk: OpencodeClient
1920
defaultModel?: {
20-
providerID: string
21-
modelID: string
21+
providerID: ProviderID
22+
modelID: ModelID
2223
}
2324
}

packages/opencode/src/agent/agent.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ export namespace Agent {
281281
return primaryVisible.name
282282
}
283283

284-
export async function generate(input: { description: string; model?: { providerID: string; modelID: string } }) {
284+
export async function generate(input: { description: string; model?: { providerID: ProviderID; modelID: ModelID } }) {
285285
const cfg = await Config.get()
286286
const defaultModel = input.model ?? (await Provider.defaultModel())
287287
const model = await Provider.getModel(defaultModel.providerID, defaultModel.modelID)

packages/opencode/src/cli/cmd/models.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import type { Argv } from "yargs"
22
import { Instance } from "../../project/instance"
33
import { Provider } from "../../provider/provider"
4+
import { ProviderID } from "../../provider/schema"
45
import { ModelsDev } from "../../provider/models"
56
import { cmd } from "./cmd"
67
import { UI } from "../ui"
@@ -36,7 +37,7 @@ export const ModelsCommand = cmd({
3637
async fn() {
3738
const providers = await Provider.list()
3839

39-
function printModels(providerID: string, verbose?: boolean) {
40+
function printModels(providerID: ProviderID, verbose?: boolean) {
4041
const provider = providers[providerID]
4142
const sortedModels = Object.entries(provider.models).sort(([a], [b]) => a.localeCompare(b))
4243
for (const [modelID, model] of sortedModels) {
@@ -56,7 +57,7 @@ export const ModelsCommand = cmd({
5657
return
5758
}
5859

59-
printModels(args.provider, args.verbose)
60+
printModels(ProviderID.make(args.provider), args.verbose)
6061
return
6162
}
6263

@@ -69,7 +70,7 @@ export const ModelsCommand = cmd({
6970
})
7071

7172
for (const providerID of providerIDs) {
72-
printModels(providerID, args.verbose)
73+
printModels(ProviderID.make(providerID), args.verbose)
7374
}
7475
},
7576
})

0 commit comments

Comments
 (0)