Skip to content

Commit f4206f4

Browse files
Merge branch 'dev' into update/opencode-go-mimo-v2-5-pricing
2 parents d11b0e4 + ec4ec6d commit f4206f4

1,362 files changed

Lines changed: 16708 additions & 7784 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.github/workflows/deploy.yml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,4 @@ jobs:
3535
- run: bun sst deploy --stage=dev
3636
env:
3737
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
38+
CLOUDFLARE_DEFAULT_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_DEFAULT_ACCOUNT_ID }}

‎.github/workflows/sync-models.yml‎

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
name: Sync Model Catalogs
2+
3+
on:
4+
schedule:
5+
- cron: "17 * * * *"
6+
workflow_dispatch:
7+
8+
permissions:
9+
contents: write
10+
issues: write
11+
pull-requests: write
12+
13+
concurrency: ${{ github.workflow }}-${{ github.ref }}
14+
15+
jobs:
16+
providers:
17+
runs-on: ubuntu-latest
18+
outputs:
19+
matrix: ${{ steps.providers.outputs.matrix }}
20+
steps:
21+
- name: Checkout code
22+
uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5
23+
with:
24+
ref: dev
25+
26+
- name: Setup Bun
27+
uses: oven-sh/setup-bun@f4d14e03ff726c06358e5557344e1da148b56cf7
28+
with:
29+
bun-version: latest
30+
31+
- name: Install dependencies
32+
run: bun install
33+
34+
- name: List sync providers
35+
id: providers
36+
run: echo "matrix=$(bun models:sync --list-providers)" >> "$GITHUB_OUTPUT"
37+
38+
sync:
39+
needs: providers
40+
runs-on: ubuntu-latest
41+
strategy:
42+
fail-fast: false
43+
matrix: ${{ fromJSON(needs.providers.outputs.matrix) }}
44+
45+
steps:
46+
- name: Checkout code
47+
uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5
48+
with:
49+
ref: dev
50+
51+
- name: Setup Bun
52+
uses: oven-sh/setup-bun@f4d14e03ff726c06358e5557344e1da148b56cf7
53+
with:
54+
bun-version: latest
55+
56+
- name: Install dependencies
57+
run: bun install
58+
59+
- name: Sync model catalogs
60+
run: bun models:sync ${{ matrix.provider }}
61+
env:
62+
OPENROUTER_API_KEY: ${{ secrets.OPENROUTER_API_KEY }}
63+
GOOGLE_API_KEY: ${{ secrets.GOOGLE_API_KEY }}
64+
GEMINI_API_KEY: ${{ secrets.GEMINI_API_KEY }}
65+
GOOGLE_GENERATIVE_AI_API_KEY: ${{ secrets.GOOGLE_GENERATIVE_AI_API_KEY }}
66+
XAI_API_KEY: ${{ secrets.XAI_API_KEY }}
67+
CLOUDFLARE_WORKERS_AI_SYNC_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_WORKERS_AI_SYNC_ACCOUNT_ID }}
68+
CLOUDFLARE_WORKERS_AI_SYNC_API_TOKEN: ${{ secrets.CLOUDFLARE_WORKERS_AI_SYNC_API_TOKEN }}
69+
70+
- name: Validate models
71+
run: bun validate
72+
73+
- name: Create pull request
74+
env:
75+
GH_TOKEN: ${{ github.token }}
76+
BRANCH: automation/sync-models-${{ matrix.provider }}
77+
LABELS: automation,model-sync,provider:${{ matrix.provider }}
78+
TITLE: "chore(sync): update ${{ matrix.name }} model catalog"
79+
run: |
80+
if [ -z "$(git status --porcelain -- providers)" ]; then
81+
echo "No model catalog changes found."
82+
exit 0
83+
fi
84+
85+
git config user.name "github-actions[bot]"
86+
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
87+
git fetch --no-tags --depth=1 origin "+refs/heads/$BRANCH:refs/remotes/origin/$BRANCH" || true
88+
git checkout -B "$BRANCH"
89+
git add providers
90+
git commit -m "$TITLE"
91+
git push --force-with-lease origin "$BRANCH"
92+
93+
label_args=()
94+
IFS=',' read -ra labels <<< "$LABELS"
95+
for label in "${labels[@]}"; do
96+
gh label create "$label" --color "0E8A16" --description "Automated model catalog sync" >/dev/null 2>&1 || true
97+
label_args+=(--label "$label")
98+
done
99+
100+
pr_number="$(gh pr list --head "$BRANCH" --base dev --json number --jq '.[0].number')"
101+
if [ -n "$pr_number" ]; then
102+
gh pr edit "$pr_number" --title "$TITLE" --body-file .sync/model-sync-report.md
103+
for label in "${labels[@]}"; do
104+
gh pr edit "$pr_number" --add-label "$label"
105+
done
106+
else
107+
gh pr create --base dev --head "$BRANCH" --title "$TITLE" --body-file .sync/model-sync-report.md "${label_args[@]}"
108+
fi

‎.gitignore‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
.idea
44
dist
55
.DS_Store
6+
.sync/
67
node_modules
78
data/tokenspeed-monitor.sqlite
89
data/tokenspeed-monitor.sqlite-shm

‎bun.lock‎

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

‎models.json‎

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.

‎package.json‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,16 @@
1717
"scripts": {
1818
"validate": "bun ./packages/core/script/validate.ts",
1919
"compare:migrations": "bun ./packages/core/script/compare-model-migrations.ts",
20+
"cloudflare:sync": "bun ./packages/core/script/sync-models.ts cloudflare-workers-ai",
21+
"chutes:generate": "bun ./packages/core/script/generate-chutes.ts",
22+
"databricks:generate": "bun ./packages/core/script/generate-databricks.ts",
2023
"helicone:generate": "bun ./packages/core/script/generate-helicone.ts",
2124
"venice:generate": "bun ./packages/core/script/generate-venice.ts",
2225
"vercel:generate": "bun ./packages/core/script/generate-vercel.ts",
2326
"wandb:generate": "bun ./packages/core/script/generate-wandb.ts",
24-
"digitalocean:generate": "bun ./packages/core/script/generate-digitalocean.ts"
27+
"digitalocean:generate": "bun ./packages/core/script/generate-digitalocean.ts",
28+
"ambient:generate": "bun ./packages/core/script/generate-ambient.ts",
29+
"models:sync": "bun ./packages/core/script/sync-models.ts"
2530
},
2631
"dependencies": {
2732
"@cloudflare/workers-types": "^4.20260424.1",
Lines changed: 172 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,172 @@
1+
#!/usr/bin/env bun
2+
3+
/**
4+
* Generates Ambient model TOML files from https://api.ambient.xyz/v1/models.
5+
*
6+
* Emits `[extends]`-format TOMLs that inherit upstream metadata
7+
* (family, release_date, knowledge, capabilities) from the canonical
8+
* provider model, and override only the fields Ambient's API reports:
9+
* cost, limit, modalities.
10+
*
11+
* Flags:
12+
* --dry-run Preview generated TOMLs without writing files.
13+
*/
14+
15+
import { z } from "zod";
16+
import path from "node:path";
17+
import { mkdir } from "node:fs/promises";
18+
19+
const API_ENDPOINT = "https://api.ambient.xyz/v1/models";
20+
21+
// Allowlist for the initial rollout.
22+
const ALLOWLIST = new Set<string>([
23+
"zai-org/GLM-5.1-FP8",
24+
"moonshotai/kimi-k2.6",
25+
]);
26+
27+
// Maps Ambient model IDs to canonical <provider>/<model> in this repo.
28+
// The generated TOML uses this path as `[extends].from` so capabilities
29+
// and metadata propagate from the upstream provider automatically.
30+
const EXTENDS_MAP: Record<string, string> = {
31+
"zai-org/GLM-5.1-FP8": "zai/glm-5.1",
32+
"moonshotai/kimi-k2.6": "moonshotai/kimi-k2.6",
33+
};
34+
35+
const Pricing = z
36+
.object({
37+
prompt: z.string(),
38+
completion: z.string(),
39+
input_cache_read: z.string().optional(),
40+
input_cache_write: z.string().optional(),
41+
})
42+
.passthrough();
43+
44+
const AmbientModel = z
45+
.object({
46+
id: z.string(),
47+
name: z.string(),
48+
context_length: z.number(),
49+
max_output_length: z.number(),
50+
input_modalities: z.array(z.string()),
51+
output_modalities: z.array(z.string()),
52+
pricing: Pricing,
53+
})
54+
.passthrough();
55+
56+
const AmbientResponse = z
57+
.object({
58+
object: z.literal("list"),
59+
data: z.array(AmbientModel),
60+
})
61+
.passthrough();
62+
63+
const ALLOWED_MODALITIES = new Set(["text", "audio", "image", "video", "pdf"]);
64+
65+
function modalities(values: string[]): string[] {
66+
return values
67+
.map((v) => v.toLowerCase())
68+
.filter((v) => ALLOWED_MODALITIES.has(v));
69+
}
70+
71+
function perMTok(price: string): number {
72+
const n = parseFloat(price);
73+
if (!Number.isFinite(n)) {
74+
throw new Error(`Invalid price: ${price}`);
75+
}
76+
// Round to 6 decimals to absorb float noise from per-token strings.
77+
return Math.round(n * 1_000_000 * 1_000_000) / 1_000_000;
78+
}
79+
80+
function formatToml(
81+
model: z.infer<typeof AmbientModel>,
82+
extendsFrom: string,
83+
): string {
84+
const lines: string[] = [];
85+
lines.push("[extends]");
86+
lines.push(`from = "${extendsFrom}"`);
87+
lines.push("");
88+
89+
lines.push("[cost]");
90+
lines.push(`input = ${perMTok(model.pricing.prompt)}`);
91+
lines.push(`output = ${perMTok(model.pricing.completion)}`);
92+
if (model.pricing.input_cache_read !== undefined) {
93+
lines.push(`cache_read = ${perMTok(model.pricing.input_cache_read)}`);
94+
}
95+
if (model.pricing.input_cache_write !== undefined) {
96+
lines.push(`cache_write = ${perMTok(model.pricing.input_cache_write)}`);
97+
}
98+
lines.push("");
99+
100+
lines.push("[limit]");
101+
lines.push(`context = ${model.context_length}`);
102+
lines.push(`output = ${model.max_output_length}`);
103+
lines.push("");
104+
105+
const input = modalities(model.input_modalities);
106+
const output = modalities(model.output_modalities);
107+
lines.push("[modalities]");
108+
lines.push(`input = [${input.map((m) => `"${m}"`).join(", ")}]`);
109+
lines.push(`output = [${output.map((m) => `"${m}"`).join(", ")}]`);
110+
111+
return lines.join("\n") + "\n";
112+
}
113+
114+
async function main() {
115+
const dryRun = process.argv.includes("--dry-run");
116+
117+
const outDir = path.join(
118+
import.meta.dirname,
119+
"..",
120+
"..",
121+
"..",
122+
"providers",
123+
"ambient",
124+
"models",
125+
);
126+
127+
const res = await fetch(API_ENDPOINT);
128+
if (!res.ok) {
129+
console.error(`Fetch failed: ${res.status} ${res.statusText}`);
130+
process.exit(1);
131+
}
132+
133+
const parsed = AmbientResponse.safeParse(await res.json());
134+
if (!parsed.success) {
135+
console.error("Invalid Ambient response:", parsed.error.issues);
136+
process.exit(1);
137+
}
138+
139+
const selected = parsed.data.data.filter((m) => ALLOWLIST.has(m.id));
140+
const missing = [...ALLOWLIST].filter(
141+
(id) => !selected.some((m) => m.id === id),
142+
);
143+
if (missing.length > 0) {
144+
console.error(`Allowlisted models missing from API: ${missing.join(", ")}`);
145+
process.exit(1);
146+
}
147+
148+
let count = 0;
149+
for (const model of selected) {
150+
const extendsFrom = EXTENDS_MAP[model.id];
151+
if (!extendsFrom) {
152+
console.error(`No EXTENDS_MAP entry for ${model.id}; skipping`);
153+
continue;
154+
}
155+
const filePath = path.join(outDir, `${model.id}.toml`);
156+
const toml = formatToml(model, extendsFrom);
157+
if (dryRun) {
158+
console.log(`--- ${path.relative(process.cwd(), filePath)} ---`);
159+
console.log(toml);
160+
} else {
161+
await mkdir(path.dirname(filePath), { recursive: true });
162+
await Bun.write(filePath, toml);
163+
}
164+
count++;
165+
}
166+
167+
console.log(
168+
`${dryRun ? "Previewed" : "Wrote"} ${count} model file(s) under providers/ambient/models/`,
169+
);
170+
}
171+
172+
await main();

0 commit comments

Comments
 (0)