GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — feat(core): wire Ark provider into aisdk-native and variant system · anomalyco/opencode@e746ca1

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • packages
    • core/src
      • aisdk-native.ts
      • ark
        • models.ts
      • plugin
        • provider.ts
        • provider
          • ark.ts
      • provider.ts
      • variant.ts
    • ui/src
      • assets/icons/provider
        • byteplus.svg
      • components/provider-icons
        • sprite.svg
        • types.ts
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎packages/core/src/aisdk-native.ts‎

Copy file name to clipboardExpand all lines: packages/core/src/aisdk-native.ts
+7Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,13 @@ const HOSTS: Readonly<Record<string, Readonly<Record<string, string>>>> = {
147147
"alibaba-token-plan": protocols("alibaba"),
148148
"alibaba-token-plan-cn": protocols("alibaba"),
149149
baseten: { "@ai-sdk/openai-compatible": "@opencode/ai/providers/baseten" },
150+
// Volcengine Ark API — three provider IDs share the same Ark Chat protocol
151+
// package. The model catalog (models.dev / local.txt) sets per-model base
152+
// URLs so BytePlus overseas traffic goes to ark.ap-southeast.bytepluses.com
153+
// while mainland traffic goes to ark.cn-beijing.volces.com.
154+
byteplus: { "@ai-sdk/openai-compatible": "@opencode/ai/providers/ark" },
155+
volcengine: { "@ai-sdk/openai-compatible": "@opencode/ai/providers/ark" },
156+
"volcengine-coding-plan": { "@ai-sdk/openai-compatible": "@opencode/ai/providers/ark" },
150157
"cloudflare-ai-gateway": {
151158
"@ai-sdk/anthropic": "@opencode/ai/providers/cloudflare-ai-gateway",
152159
"@ai-sdk/openai": "@opencode/ai/providers/cloudflare-ai-gateway",
Collapse file

‎packages/core/src/ark/models.ts‎

Copy file name to clipboard
+100Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
/**
2+
* Generic OpenAI-compatible model discovery.
3+
*
4+
* Many providers (Volcengine Ark, BytePlus, MiniMax, DeepSeek, etc.) expose an
5+
* OpenAI-compatible `GET /models` endpoint. This module fetches that endpoint
6+
* and merges the results with catalog templates from models.dev so the
7+
* discovered models inherit family, cost, capabilities, and compatibility
8+
* metadata from the catalog while their availability is determined live.
9+
*/
10+
export * as OpenAICompatibleModels from "./models.js"
11+
12+
import { Money } from "@opencode/schema/money"
13+
import { Effect, Option, Schema } from "effect"
14+
import { HttpClient, HttpClientRequest, HttpClientResponse } from "effect/http"
15+
import { Model } from "../model.js"
16+
import { Provider } from "../provider.js"
17+
18+
const Response = Schema.Struct({ data: Schema.Array(Schema.Unknown) })
19+
20+
/** A single entry returned by `GET /models`. */
21+
const RemoteModel = Schema.Struct({
22+
id: Schema.String,
23+
})
24+
const decodeModel = Schema.decodeUnknownOption(RemoteModel)
25+
26+
type RemoteModel = typeof RemoteModel.Type
27+
28+
export type Snapshot = readonly RemoteModel[]
29+
30+
/**
31+
* Fetch the model list from `GET <baseURL>/models`.
32+
* Each entry in `data` is decoded tolerantly so one malformed item cannot
33+
* discard the whole inventory.
34+
*/
35+
export const load = Effect.fn("OpenAICompatibleModels.load")(function* (
36+
http: HttpClient.HttpClient,
37+
baseURL: string,
38+
apiKey: string,
39+
) {
40+
const response = yield* HttpClient.filterStatusOk(http)
41+
.execute(
42+
HttpClientRequest.get(`${baseURL.replace(/\/+$/, "")}/models`).pipe(
43+
HttpClientRequest.bearerToken(apiKey),
44+
),
45+
)
46+
.pipe(Effect.flatMap(HttpClientResponse.schemaBodyJson(Response)), Effect.timeout("3 seconds"))
47+
return response.data.flatMap((raw) => {
48+
const model = Option.getOrUndefined(decodeModel(raw))
49+
return model ? [model] : []
50+
})
51+
})
52+
53+
/**
54+
* Combine remote facts with source templates. A discovered model whose ID
55+
* matches a catalog template inherits the template's metadata (family, cost,
56+
* capabilities, compatibility, variants, etc.). A discovered model with no
57+
* template gets sensible defaults from `Model.Info.default`.
58+
*/
59+
export function derive(
60+
providerID: Provider.ID,
61+
baseURL: string,
62+
remote: Snapshot,
63+
existing: readonly Model.Info[],
64+
) {
65+
const templates = new Map(existing.map((model) => [model.id, model]))
66+
const result = new Map<Model.ID, Model.Info>()
67+
for (const item of remote) {
68+
const id = Model.ID.make(item.id)
69+
const template = templates.get(id)
70+
result.set(id, build(providerID, id, baseURL, template))
71+
}
72+
return result
73+
}
74+
75+
function build(providerID: Provider.ID, id: Model.ID, baseURL: string, previous?: Model.Info) {
76+
return Model.Info.make({
77+
...Model.Info.default(providerID, id),
78+
id,
79+
modelID: id,
80+
providerID,
81+
name: previous?.name ?? id,
82+
family: previous?.family,
83+
compatibility: previous?.compatibility,
84+
package: previous?.package,
85+
settings: Provider.mergeOverlay(previous?.settings, { baseURL, provider: providerID }),
86+
headers: previous?.headers,
87+
body: previous?.body,
88+
capabilities: {
89+
tools: previous?.capabilities.tools ?? true,
90+
input: previous?.capabilities.input ?? ["text"],
91+
output: previous?.capabilities.output ?? ["text"],
92+
},
93+
variants: previous?.variants ?? [],
94+
time: previous?.time ?? { released: 0 },
95+
cost: previous ? previous.cost : [{ input: Money.USDPerMillionTokens.zero, output: Money.USDPerMillionTokens.zero, cache: { read: Money.USDPerMillionTokens.zero, write: Money.USDPerMillionTokens.zero } }],
96+
status: previous?.status ?? "active",
97+
enabled: previous?.enabled ?? true,
98+
limit: previous?.limit ?? { context: 0, output: 0 },
99+
})
100+
}
Collapse file

‎packages/core/src/plugin/provider.ts‎

Copy file name to clipboardExpand all lines: packages/core/src/plugin/provider.ts
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { ArkPlugin } from "./provider/ark.js"
12
import { AmazonBedrockPlugin } from "./provider/amazon-bedrock.js"
23
import { AzurePlugin } from "./provider/azure.js"
34
import { CerebrasPlugin } from "./provider/cerebras.js"
@@ -31,6 +32,7 @@ import { ZenmuxPlugin } from "./provider/zenmux.js"
3132
import type { PluginInternal } from "./internal.js"
3233

3334
export const ProviderPlugins: PluginInternal.InternalPlugin[] = [
35+
ArkPlugin,
3436
AmazonBedrockPlugin,
3537
AzurePlugin,
3638
CerebrasPlugin,

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.