xonecas.io
79113
Ma

mini-coding-agent / commit 6c53a5c

feat: update local config so strata and ollama can relect real values

xonecas2026-10-07 6c53a5c0525b63295bdda8309fcf5c3553baff0a parent c984a9b

5 files changed

README.md+30−6
@@ -77,9 +77,19 @@ A full example:
7777 {
7878 "id": "local",
7979 "name": "Local",
80- "baseUrl": "http://127.0.0.1:11434/v1",
81- "api": "openai-completions",
82- "models": ["qwen3-coder"],
80+ "models": [
81+ {
82+ "id": "qwen3-coder",
83+ "api": "openai-completions",
84+ "baseUrl": "http://127.0.0.1:11434/v1",
85+ "context": 32768,
86+ "maxOutput": 8192,
87+ "images": false,
88+ "reasoning": true,
89+ "effort": ["low", "high"],
90+ "cost": [0, 0, 0]
91+ }
92+ ],
8393 "envKeys": ["LOCAL_API_KEY"],
8494 "headers": { "x-tenant": "mini" }
8595 }
@@ -111,12 +121,26 @@ A `customProvider` field:
111121 |---|---|---|
112122 | `id` | yes | the id `provider` selects |
113123 | `name` | no | display name; falls back to `id` |
114-| `baseUrl` | yes | request base URL |
115-| `api` | yes | one of `openai-completions`, `openai-responses`, `anthropic-messages`, `google-generative-ai` |
116-| `models` | yes | non-empty list of model ids |
124+| `models` | yes | non-empty list of model objects |
117125 | `envKeys` | no | environment variables searched, in order, for the API key |
118126 | `headers` | no | extra request headers |
119127
128+A `customProvider` model object; every model carries its own wire and metadata,
129+so one provider may mix APIs and base URLs:
130+
131+| Field | Required | Meaning |
132+|---|---|---|
133+| `id` | yes | the id `model` selects |
134+| `name` | no | display name; falls back to `id` |
135+| `api` | yes | one of `openai-completions`, `openai-responses`, `anthropic-messages`, `google-generative-ai` |
136+| `baseUrl` | yes | request base URL |
137+| `context` | yes | context window in tokens |
138+| `maxOutput` | yes | maximum output tokens |
139+| `images` | yes | whether the model accepts image input |
140+| `reasoning` | yes | whether the model reasons |
141+| `effort` | no | accepted thinking levels; empty means the full ladder |
142+| `cost` | yes | `[input, output, cache-read]` USD per million tokens |
143+
120144 ## Environment
121145
122146 The built-in providers read `OPENCODE_API_KEY`. Custom providers read the first
notes.md+0−30
@@ -1,30 +0,0 @@
1-# Some notes from reading the code.
2-
3-> Context: I'm mostly a web engineer, with some backend experience with python, node and go.
4-
5-Some of my notes might be because of lack of Zig experience.
6-These are **my** notes. Use your own file for your notes...
7-
8-## Notes from my code review
9-
10-`src/config.zig` - When we fixed the issue with the model specific api being at provider level for opencode in a recent commit, apparently we didn't do it for custom providers. Again, the models need to carry the metadata, the provider is just a label grouping.
11-
12-```jsonc
13-// Example custom provider **correct**
14-{
15- "id": "local",
16- "name": "Local",
17- "models": [{
18- "id": "qwen3-coder",
19- "api": "openai-completions",
20- "baseUrl": "http://127.0.0.1:11434/v1"
21- }],
22- "envKeys": ["LOCAL_API_KEY"],
23- "headers": { "x-tenant": "mini" }
24-}
25-```
26-
27-I suggest the above structure, so we match the work we did for opencode. Basically the mistake here is assuming all providers use the same api for all models, which is not true. Not even for local envs.
28-Another note here is that again, I'm shocked at how cumbersome it is to read and validate JSON.
29-
30-`src/tui/theme.zig` - will eventually grow too much, each theme we add will make that file worse. A refactor for later, since it's ok right now.
src/config.zig+14−3
@@ -12,12 +12,23 @@ pub const Api = enum {
1212 @"google-generative-ai",
1313 };
1414
15-pub const CustomProvider = struct {
15+pub const CustomModel = struct {
1616 id: []const u8,
1717 name: ?[]const u8 = null,
18- baseUrl: []const u8,
1918 api: Api,
20- models: []const []const u8,
19+ baseUrl: []const u8,
20+ context: u64,
21+ maxOutput: u64,
22+ images: bool,
23+ reasoning: bool,
24+ effort: []const []const u8 = &.{},
25+ cost: [3]f64,
26+};
27+
28+pub const CustomProvider = struct {
29+ id: []const u8,
30+ name: ?[]const u8 = null,
31+ models: []const CustomModel,
2132 envKeys: []const []const u8 = &.{},
2233 headers: ?std.json.ArrayHashMap([]const u8) = null,
2334 };
src/models.zig+52−38
@@ -36,19 +36,19 @@ fn normalizeEffort(value: []const u8) []const u8 {
3636 return if (std.mem.eql(u8, value, "none")) "off" else value;
3737 }
3838
39-fn clampEffort(info: *const catalog.ModelInfo, desired: ?[]const u8) []const u8 {
39+fn clampEffort(reasoning: bool, effort: []const []const u8, desired: ?[]const u8) []const u8 {
4040 const want = desired orelse return "";
41- if (!info.reasoning) return "off";
42- if (info.effort.len == 0) return want;
43- for (info.effort) |accepted| {
41+ if (!reasoning) return "off";
42+ if (effort.len == 0) return want;
43+ for (effort) |accepted| {
4444 if (std.mem.eql(u8, normalizeEffort(accepted), want)) return normalizeEffort(accepted);
4545 }
4646 const want_rank = rank(want);
47- if (want_rank < 0) return normalizeEffort(info.effort[0]);
47+ if (want_rank < 0) return normalizeEffort(effort[0]);
4848
4949 var up: ?[]const u8 = null;
5050 var down: ?[]const u8 = null;
51- for (info.effort) |accepted| {
51+ for (effort) |accepted| {
5252 const r = rank(normalizeEffort(accepted));
5353 if (r < 0) continue;
5454 if (r >= want_rank) {
@@ -103,7 +103,7 @@ pub fn resolveNamed(a: std.mem.Allocator, cfg: *const config.Config, provider_id
103103 .provider = provider_id,
104104 .base_url = info.base_url,
105105 .api_key = firstEnv(b.env_keys),
106- .effort = clampEffort(info, cfg.thinking_effort),
106+ .effort = clampEffort(info.reasoning, info.effort, cfg.thinking_effort),
107107 .supports_images = info.images,
108108 .context_window = info.context,
109109 .max_tokens = info.max_output,
@@ -115,31 +115,28 @@ pub fn resolveNamed(a: std.mem.Allocator, cfg: *const config.Config, provider_id
115115 }
116116
117117 if (custom(cfg, provider_id)) |p| {
118- var listed = false;
119- for (p.models) |id| {
120- if (std.mem.eql(u8, id, model_id)) listed = true;
118+ for (p.models) |m| {
119+ if (!std.mem.eql(u8, m.id, model_id)) continue;
120+ return types.Model{
121+ .id = m.id,
122+ .name = m.name orelse m.id,
123+ .api = @tagName(m.api),
124+ .provider = provider_id,
125+ .base_url = m.baseUrl,
126+ .api_key = firstEnv(p.envKeys),
127+ .effort = clampEffort(m.reasoning, m.effort, cfg.thinking_effort),
128+ .supports_images = m.images,
129+ .context_window = m.context,
130+ .max_tokens = m.maxOutput,
131+ .cost_input = m.cost[0],
132+ .cost_output = m.cost[1],
133+ .cost_cache_read = m.cost[2],
134+ .session_header = null,
135+ .headers = headerPairs(a, p.headers),
136+ };
121137 }
122- if (!listed) {
123- err.* = unknownModel(a, model_id, provider_id);
124- return null;
125- }
126- return types.Model{
127- .id = model_id,
128- .name = model_id,
129- .api = @tagName(p.api),
130- .provider = provider_id,
131- .base_url = p.baseUrl,
132- .api_key = firstEnv(p.envKeys),
133- .effort = cfg.thinking_effort orelse "",
134- .supports_images = true,
135- .context_window = 200_000,
136- .max_tokens = 32_768,
137- .cost_input = 0,
138- .cost_output = 0,
139- .cost_cache_read = 0,
140- .session_header = null,
141- .headers = headerPairs(a, p.headers),
142- };
138+ err.* = unknownModel(a, model_id, provider_id);
139+ return null;
143140 }
144141
145142 err.* = std.fmt.allocPrint(a, "unknown provider \"{s}\"", .{provider_id}) catch "unknown provider";
@@ -175,26 +172,43 @@ pub fn catalogModels(a: std.mem.Allocator, cfg: *const config.Config, provider_i
175172 if (resolveNamed(a, cfg, provider_id, entry.id, &err)) |m| try out.append(a, m);
176173 }
177174 if (custom(cfg, provider_id)) |p| {
178- for (p.models) |id| {
175+ for (p.models) |m| {
179176 var err: ?[]const u8 = null;
180- if (resolveNamed(a, cfg, provider_id, id, &err)) |m| try out.append(a, m);
177+ if (resolveNamed(a, cfg, provider_id, m.id, &err)) |resolved| try out.append(a, resolved);
181178 }
182179 }
183180 return out.toOwnedSlice(a);
184181 }
185182
186-pub fn supportedLevels(provider_id: []const u8, model_id: []const u8) []const []const u8 {
187- if (builtin(provider_id) == null) return &ladder;
183+pub fn supportedLevels(cfg: *const config.Config, provider_id: []const u8, model_id: []const u8) []const []const u8 {
184+ if (builtin(provider_id) == null) {
185+ if (custom(cfg, provider_id)) |p| {
186+ for (p.models) |m| {
187+ if (!std.mem.eql(u8, m.id, model_id)) continue;
188+ if (!m.reasoning) return &.{"off"};
189+ if (m.effort.len == 0) return &ladder;
190+ return m.effort;
191+ }
192+ }
193+ return &ladder;
194+ }
188195 const info = catalog.lookup(provider_id, model_id) orelse return &ladder;
189196 if (!info.reasoning) return &.{"off"};
190197 if (info.effort.len == 0) return &ladder;
191198 return info.effort;
192199 }
193200
194-pub fn clampNamed(provider_id: []const u8, model_id: []const u8, desired: []const u8) []const u8 {
195- if (builtin(provider_id) == null) return desired;
201+pub fn clampNamed(cfg: *const config.Config, provider_id: []const u8, model_id: []const u8, desired: []const u8) []const u8 {
202+ if (builtin(provider_id) == null) {
203+ if (custom(cfg, provider_id)) |p| {
204+ for (p.models) |m| {
205+ if (std.mem.eql(u8, m.id, model_id)) return clampEffort(m.reasoning, m.effort, desired);
206+ }
207+ }
208+ return desired;
209+ }
196210 const info = catalog.lookup(provider_id, model_id) orelse return desired;
197- return clampEffort(info, desired);
211+ return clampEffort(info.reasoning, info.effort, desired);
198212 }
199213
200214 fn unknownModel(a: std.mem.Allocator, model_id: []const u8, provider_id: []const u8) []const u8 {
src/tui/tui.zig+2−2
@@ -506,7 +506,7 @@ const Tui = struct {
506506 },
507507 .thinking => {
508508 const m = self.opts.model orelse return self.fail("! no model configured", .{});
509- const levels = models_mod.supportedLevels(m.provider, m.id);
509+ const levels = models_mod.supportedLevels(self.cfg, m.provider, m.id);
510510 self.beginPrompt("Select a thinking level", levels, levels);
511511 self.pending_command = .thinking;
512512 },
@@ -620,7 +620,7 @@ const Tui = struct {
620620 const m = self.opts.model orelse return;
621621 const updated = self.a.create(types.Model) catch return;
622622 updated.* = m.*;
623- updated.effort = models_mod.clampNamed(m.provider, m.id, id);
623+ updated.effort = models_mod.clampNamed(self.cfg, m.provider, m.id, id);
624624 self.select(updated);
625625 config.save(self.a, self.cfg, .{ .thinking_effort = id }) catch {};
626626 },