xonecas.io
79113
Ma

mini-coding-agent / commit b7215a5

feat: model metadata gen

xonecas2026-10-08 b7215a565d4064fc8b895b44f5d501be4a3526ca parent b4d6182

3 files changed

src/models_dev.json+1−0
@@ -0,0 +1 @@
1+{"opencode":{"id":"opencode","env":["OPENCODE_API_KEY"],"npm":"@ai-sdk/openai-compatible","api":"https://opencode.ai/zen/v1","name":"OpenCode Zen","doc":"https://opencode.ai/docs/zen","models":{"ling-3.0-flash-fin-free":{"id":"ling-3.0-flash-fin-free","name":"Ling 3.0 Flash Fin Free","description":"Finance-enhanced model for financial research, multi-step investment workflows, and long-horizon planning and execution","family":"ling","attachment":false,"reasoning":true,"reasoning_options":[{"type …
src/models_dev.zig+100−0
@@ -0,0 +1,100 @@
1+// models.dev metadata, embedded at build time. Refresh with
2+// `python3 tools/gen_models_dev.py`.
3+
4+const std = @import("std");
5+
6+/// The raw models.dev document, filtered to the providers this agent talks to.
7+pub const raw = @embedFile("models_dev.json");
8+
9+pub const Info = struct {
10+ name: []const u8,
11+ api: []const u8,
12+ base_url: []const u8,
13+ images: bool,
14+ reasoning: bool,
15+ context: u64,
16+ max_output: u64,
17+ effort: []const []const u8,
18+ cost_input: f64,
19+ cost_output: f64,
20+ cost_cache_read: f64,
21+};
22+
23+const wires = [_][2][]const u8{
24+ .{ "@ai-sdk/openai-compatible", "openai-completions" },
25+ .{ "@ai-sdk/openai", "openai-responses" },
26+ .{ "@ai-sdk/anthropic", "anthropic-messages" },
27+ .{ "@ai-sdk/google", "google-generative-ai" },
28+};
29+
30+fn wire(npm: []const u8) ?[]const u8 {
31+ for (wires) |w| {
32+ if (std.mem.eql(u8, w[0], npm)) return w[1];
33+ }
34+ return null;
35+}
36+
37+const Effort = struct { type: []const u8 = "", values: []const []const u8 = &.{} };
38+const Limit = struct { context: u64 = 0, output: u64 = 0 };
39+const Cost = struct { input: f64 = 0, output: f64 = 0, cache_read: f64 = 0 };
40+const Package = struct { npm: []const u8 = "" };
41+
42+const Model = struct {
43+ name: []const u8 = "",
44+ attachment: bool = false,
45+ reasoning: bool = false,
46+ reasoning_options: []const Effort = &.{},
47+ limit: Limit = .{},
48+ cost: Cost = .{},
49+ provider: ?Package = null,
50+};
51+
52+const Provider = struct {
53+ api: []const u8 = "",
54+ npm: []const u8 = "",
55+ models: std.json.ArrayHashMap(Model) = .{},
56+};
57+
58+const File = std.json.ArrayHashMap(Provider);
59+
60+/// A parsed models.dev document. The provider listing and each model's wire,
61+/// base URL and metadata all come from here.
62+pub const Db = struct {
63+ file: File,
64+
65+ pub fn open(a: std.mem.Allocator) !Db {
66+ return .{ .file = try std.json.parseFromSliceLeaky(File, a, raw, .{ .ignore_unknown_fields = true }) };
67+ }
68+
69+ pub fn baseUrl(self: Db, provider_id: []const u8) ?[]const u8 {
70+ const p = self.file.map.get(provider_id) orelse return null;
71+ if (p.api.len == 0) return null;
72+ return std.mem.trimEnd(u8, p.api, "/");
73+ }
74+
75+ pub fn info(self: Db, provider_id: []const u8, model_id: []const u8) ?Info {
76+ const p = self.file.map.get(provider_id) orelse return null;
77+ if (p.api.len == 0) return null;
78+ const m = p.models.map.get(model_id) orelse return null;
79+ return .{
80+ .name = if (m.name.len > 0) m.name else model_id,
81+ .api = wire(if (m.provider) |pkg| pkg.npm else p.npm) orelse return null,
82+ .base_url = std.mem.trimEnd(u8, p.api, "/"),
83+ .images = m.attachment,
84+ .reasoning = m.reasoning,
85+ .context = m.limit.context,
86+ .max_output = m.limit.output,
87+ .effort = effortOf(m),
88+ .cost_input = m.cost.input,
89+ .cost_output = m.cost.output,
90+ .cost_cache_read = m.cost.cache_read,
91+ };
92+ }
93+};
94+
95+fn effortOf(m: Model) []const []const u8 {
96+ for (m.reasoning_options) |opt| {
97+ if (std.mem.eql(u8, opt.type, "effort")) return opt.values;
98+ }
99+ return &.{};
100+}
tools/gen_models_dev.py+39−0
@@ -0,0 +1,39 @@
1+#!/usr/bin/env python3
2+"""Fetches models.dev and writes src/models_dev.json.
3+
4+The provider decides which models exist (we ask it at runtime); models.dev
5+decides the wire, base URL and metadata for each model id. Only the providers
6+this agent can talk to are kept. The output is committed, so a normal
7+`zig build` needs no network. Run `python3 tools/gen_models_dev.py` to refresh.
8+"""
9+
10+import json
11+import sys
12+import urllib.request
13+
14+MODELS_DEV = "https://models.dev/api.json"
15+
16+PROVIDERS = ["opencode", "opencode-go"]
17+
18+
19+def main():
20+ out = sys.argv[1] if len(sys.argv) > 1 else "src/models_dev.json"
21+ req = urllib.request.Request(MODELS_DEV, headers={"User-Agent": "mini-models-dev/1"})
22+ with urllib.request.urlopen(req) as r:
23+ data = json.loads(r.read())
24+
25+ kept = {}
26+ for pid in PROVIDERS:
27+ if pid not in data:
28+ sys.exit("models.dev: provider %r missing" % pid)
29+ kept[pid] = data[pid]
30+
31+ with open(out, "w") as f:
32+ json.dump(kept, f, separators=(",", ":"))
33+ f.write("\n")
34+ print("wrote %s (%d providers, %d models)" % (
35+ out, len(kept), sum(len(p["models"]) for p in kept.values())))
36+
37+
38+if __name__ == "__main__":
39+ main()