@foldrun/core 18.0.1 → 18.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,9 +1,13 @@
1
1
  import { type WireFormat } from "./providers.ts";
2
- export type SupplyProviderName = "anthropic" | "openai" | "gemini" | "deepseek" | "moonshot";
2
+ export type SupplyProviderName = "anthropic" | "openai" | "gemini" | "deepseek" | "moonshot" | "zai" | "qwen" | "minimax" | "mimo";
3
3
  export interface SupplyProvider {
4
4
  name: SupplyProviderName;
5
- /** The preset the step's provider block is built from (providers.ts). */
5
+ /** The preset the step's provider block is built from (providers.ts);
6
+ * "" when the runtime has none for this provider. */
6
7
  preset: string;
8
+ /** The endpoint, where the preset has none (a per-account address) or
9
+ * there is no preset: the one place the platform's key is used. */
10
+ baseUrl?: string;
7
11
  format: WireFormat;
8
12
  /** The one host the key is granted to. */
9
13
  host: string;
@@ -33,6 +37,10 @@ export interface SendShape {
33
37
  drop?: string[];
34
38
  /** The keys of `thinking` that are sent; null drops `thinking` whole. */
35
39
  thinking?: string[] | null;
40
+ /** `thinking.type` as this provider spells it (Claude Code sends
41
+ * `adaptive` to newer models; an endpoint that documents enabled |
42
+ * disabled alone gets `enabled`). A type not listed is sent as it is. */
43
+ thinkingType?: Record<string, string>;
36
44
  /** `output_config.effort`, as this provider spells it. */
37
45
  effort?: Record<string, string>;
38
46
  /** A `system` message inside `messages` (Anthropic's mid-conversation
@@ -87,6 +87,77 @@ export const SUPPLY_PROVIDERS = {
87
87
  dropDeferredTools: true,
88
88
  },
89
89
  },
90
+ // Four more open-weight coding families (owner, 10 Nov 2026), each on its
91
+ // own Anthropic-format endpoint, pay-as-you-go keys (a coding-plan key is
92
+ // a different product). What each documents was read from its own docs on
93
+ // 10 Nov 2026; `service_tier` is dropped everywhere — MiniMax bills its
94
+ // priority tier at 1.5x, and the others do not say what it does.
95
+ zai: {
96
+ name: "zai",
97
+ preset: "zai",
98
+ format: "anthropic",
99
+ host: "api.z.ai",
100
+ auth: "bearer",
101
+ metered: ["/api/anthropic/v1/messages"],
102
+ free: [],
103
+ // docs.z.ai documents no request schema for its Anthropic endpoint, only
104
+ // that Claude Code runs on it; its OpenAI one takes thinking.type
105
+ // enabled | disabled (GLM-5.3 refuses disabled). Context editing and
106
+ // tool search are Claude's alone.
107
+ send: { drop: ["context_management", "service_tier"], thinking: ["type", "budget_tokens"], thinkingType: { adaptive: "enabled" }, mergeSystemMessages: true, dropDeferredTools: true },
108
+ },
109
+ qwen: {
110
+ name: "qwen",
111
+ preset: "qwen",
112
+ // The preset's address is per account and per plan; the platform's
113
+ // pay-as-you-go key is used on the region-wide Singapore host.
114
+ baseUrl: "https://dashscope-intl.aliyuncs.com/apps/anthropic",
115
+ format: "anthropic",
116
+ // Alibaba Model Studio, Singapore: the region-wide host (still fully
117
+ // supported; the per-workspace host differs per account).
118
+ host: "dashscope-intl.aliyuncs.com",
119
+ auth: "x-api-key",
120
+ metered: ["/apps/anthropic/v1/messages"],
121
+ free: [],
122
+ // alibabacloud.com/help/en/model-studio/anthropic-api-messages (5 Nov
123
+ // 2026): thinking.type enabled | disabled, budget_tokens; effort xhigh |
124
+ // medium | low (max and high run as xhigh); user and assistant roles
125
+ // only. Web search is a typed tool, refused like Anthropic's.
126
+ send: { drop: ["context_management", "service_tier"], thinking: ["type", "budget_tokens"], thinkingType: { adaptive: "enabled" }, mergeSystemMessages: true, dropDeferredTools: true },
127
+ },
128
+ minimax: {
129
+ name: "minimax",
130
+ preset: "minimax",
131
+ format: "anthropic",
132
+ host: "api.minimax.io",
133
+ auth: "bearer",
134
+ metered: ["/anthropic/v1/messages"],
135
+ free: [{ method: "GET", path: "/anthropic/v1/models" }],
136
+ // platform.minimax.io/docs/api-reference/text-chat-anthropic (10 Nov
137
+ // 2026): thinking.type disabled | adaptive (no budget); effort takes
138
+ // every word ours does; no system role in messages (roles alternate);
139
+ // context_management, stop_sequences and top_k ignored.
140
+ send: { drop: ["context_management", "service_tier"], thinking: ["type"], thinkingType: { enabled: "adaptive" }, mergeSystemMessages: true, dropDeferredTools: true },
141
+ },
142
+ mimo: {
143
+ name: "mimo",
144
+ preset: "",
145
+ baseUrl: "https://api.xiaomimimo.com/anthropic",
146
+ format: "anthropic",
147
+ host: "api.xiaomimimo.com",
148
+ auth: "bearer",
149
+ metered: ["/anthropic/v1/messages"],
150
+ free: [],
151
+ // mimo.mi.com/static/docs/api/chat/anthropic-api-post (10 Nov 2026):
152
+ // the request schema is these fields alone; thinking.type enabled |
153
+ // disabled; a system role in messages is accepted; no effort.
154
+ send: {
155
+ fields: ["model", "messages", "max_tokens", "system", "stream", "stop_sequences", "temperature", "top_p", "tools", "tool_choice", "thinking"],
156
+ thinking: ["type"],
157
+ thinkingType: { adaptive: "enabled" },
158
+ dropDeferredTools: true,
159
+ },
160
+ },
90
161
  };
91
162
  export const SUPPLY_PROVIDER_NAMES = Object.keys(SUPPLY_PROVIDERS);
92
163
  /** How each reads to a person: on a step's credential line, in Settings. */
@@ -96,6 +167,10 @@ export const SUPPLY_TITLES = {
96
167
  gemini: "Google Gemini",
97
168
  deepseek: "DeepSeek",
98
169
  moonshot: "Moonshot Kimi",
170
+ zai: "Z.ai GLM",
171
+ qwen: "Alibaba Qwen",
172
+ minimax: "MiniMax",
173
+ mimo: "Xiaomi MiMo",
99
174
  };
100
175
  export function isSupplyProvider(name) {
101
176
  return typeof name === "string" && Object.hasOwn(SUPPLY_PROVIDERS, name);
@@ -119,13 +194,17 @@ export function supplyProviderOfToken(value) {
119
194
  * placeholder only. */
120
195
  export function supplyProviderBlock(provider, tiers) {
121
196
  const p = SUPPLY_PROVIDERS[provider];
122
- const preset = providerPreset(p.preset);
123
- if (!preset?.baseUrl)
124
- throw new Error(`model supply: no preset endpoint for ${provider}`);
197
+ const preset = p.preset ? providerPreset(p.preset) : undefined;
198
+ const baseUrl = p.baseUrl ?? preset?.baseUrl;
199
+ if (!baseUrl)
200
+ throw new Error(`model supply: no endpoint for ${provider}`);
125
201
  return {
126
- name: p.preset,
127
- base_url: preset.baseUrl,
202
+ // A provider the runtime has no preset for is spelled out whole: its
203
+ // address, format and auth, no name to look up.
204
+ ...(preset ? { name: p.preset } : {}),
205
+ base_url: baseUrl,
128
206
  format: p.format,
207
+ auth: p.auth,
129
208
  token: supplyToken(provider),
130
209
  ...(Object.keys(tiers).length ? { models: tiers } : {}),
131
210
  };
@@ -161,6 +240,14 @@ export function shapeRequest(p, json) {
161
240
  (delete t[k], (changed = true));
162
241
  }
163
242
  }
243
+ if (shape.thinkingType && json.thinking && typeof json.thinking === "object") {
244
+ const t = json.thinking;
245
+ const to = typeof t.type === "string" ? shape.thinkingType[t.type] : undefined;
246
+ if (to !== undefined && to !== t.type) {
247
+ t.type = to;
248
+ changed = true;
249
+ }
250
+ }
164
251
  if (shape.dropDeferredTools && Array.isArray(json.tools)) {
165
252
  const kept = json.tools.filter((t) => !(t && typeof t === "object" && t.defer_loading === true));
166
253
  if (kept.length !== json.tools.length) {
@@ -207,6 +294,10 @@ export function shapeRequest(p, json) {
207
294
  /** DeepSeek takes every foldrun word but runs three levels (its docs:
208
295
  * "medium and xhigh both map to high"). Said, not rewritten. */
209
296
  const DEEPSEEK_RUNS = { low: "low", medium: "high", high: "high", xhigh: "high", max: "max" };
297
+ /** Qwen 3.8 runs xhigh, medium and low ("max and high map to xhigh",
298
+ * Alibaba's Anthropic API page, 5 Nov 2026). Its other models' levels are
299
+ * not documented: said as written. */
300
+ const QWEN38_RUNS = { low: "low", medium: "medium", high: "xhigh", xhigh: "xhigh", max: "xhigh" };
210
301
  /**
211
302
  * The effort a foldrun level actually runs at on one of foldrun's models:
212
303
  * the provider's own aliases (DeepSeek), its reshaping (Kimi), the model's
@@ -222,6 +313,8 @@ export function effortRunsAs(provider, model, word) {
222
313
  return p.send.effort[word] ?? null;
223
314
  if (provider === "deepseek")
224
315
  return DEEPSEEK_RUNS[word] ?? null;
316
+ if (provider === "qwen" && /^qwen3\.8/i.test(model))
317
+ return QWEN38_RUNS[word] ?? null;
225
318
  if (p.format === "anthropic")
226
319
  return word;
227
320
  return fitEffort(model, word);
package/dist/src/otel.js CHANGED
@@ -92,7 +92,7 @@ const lastError = (s) => {
92
92
  * says whose model it was: the platform's own Claude credential, or one of
93
93
  * foldrun's models. An account's own provider: block could be anyone's, so
94
94
  * it says nothing rather than guess. */
95
- const PROVIDER = { anthropic: "anthropic", openai: "openai", gemini: "gcp.gemini", deepseek: "deepseek", moonshot: "moonshot_ai" };
95
+ const PROVIDER = { anthropic: "anthropic", openai: "openai", gemini: "gcp.gemini", deepseek: "deepseek", moonshot: "moonshot_ai", zai: "z_ai", qwen: "alibaba_qwen", minimax: "minimax", mimo: "xiaomi_mimo" };
96
96
  function providerOf(step) {
97
97
  if (!step)
98
98
  return null;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@foldrun/core",
3
- "version": "18.0.1",
3
+ "version": "18.1.0",
4
4
  "description": "Agents are just folders. The format, the runner, the checks.",
5
5
  "license": "FSL-1.1-ALv2",
6
6
  "type": "module",
@@ -16,12 +16,16 @@
16
16
  import { providerPreset, type WireFormat } from "./providers.ts";
17
17
  import { fitEffort, EFFORT_ORDER } from "./effort-fit.ts";
18
18
 
19
- export type SupplyProviderName = "anthropic" | "openai" | "gemini" | "deepseek" | "moonshot";
19
+ export type SupplyProviderName = "anthropic" | "openai" | "gemini" | "deepseek" | "moonshot" | "zai" | "qwen" | "minimax" | "mimo";
20
20
 
21
21
  export interface SupplyProvider {
22
22
  name: SupplyProviderName;
23
- /** The preset the step's provider block is built from (providers.ts). */
23
+ /** The preset the step's provider block is built from (providers.ts);
24
+ * "" when the runtime has none for this provider. */
24
25
  preset: string;
26
+ /** The endpoint, where the preset has none (a per-account address) or
27
+ * there is no preset: the one place the platform's key is used. */
28
+ baseUrl?: string;
25
29
  format: WireFormat;
26
30
  /** The one host the key is granted to. */
27
31
  host: string;
@@ -49,6 +53,10 @@ export interface SendShape {
49
53
  drop?: string[];
50
54
  /** The keys of `thinking` that are sent; null drops `thinking` whole. */
51
55
  thinking?: string[] | null;
56
+ /** `thinking.type` as this provider spells it (Claude Code sends
57
+ * `adaptive` to newer models; an endpoint that documents enabled |
58
+ * disabled alone gets `enabled`). A type not listed is sent as it is. */
59
+ thinkingType?: Record<string, string>;
52
60
  /** `output_config.effort`, as this provider spells it. */
53
61
  effort?: Record<string, string>;
54
62
  /** A `system` message inside `messages` (Anthropic's mid-conversation
@@ -133,6 +141,77 @@ export const SUPPLY_PROVIDERS: Record<SupplyProviderName, SupplyProvider> = {
133
141
  dropDeferredTools: true,
134
142
  },
135
143
  },
144
+ // Four more open-weight coding families (owner, 10 Nov 2026), each on its
145
+ // own Anthropic-format endpoint, pay-as-you-go keys (a coding-plan key is
146
+ // a different product). What each documents was read from its own docs on
147
+ // 10 Nov 2026; `service_tier` is dropped everywhere — MiniMax bills its
148
+ // priority tier at 1.5x, and the others do not say what it does.
149
+ zai: {
150
+ name: "zai",
151
+ preset: "zai",
152
+ format: "anthropic",
153
+ host: "api.z.ai",
154
+ auth: "bearer",
155
+ metered: ["/api/anthropic/v1/messages"],
156
+ free: [],
157
+ // docs.z.ai documents no request schema for its Anthropic endpoint, only
158
+ // that Claude Code runs on it; its OpenAI one takes thinking.type
159
+ // enabled | disabled (GLM-5.3 refuses disabled). Context editing and
160
+ // tool search are Claude's alone.
161
+ send: { drop: ["context_management", "service_tier"], thinking: ["type", "budget_tokens"], thinkingType: { adaptive: "enabled" }, mergeSystemMessages: true, dropDeferredTools: true },
162
+ },
163
+ qwen: {
164
+ name: "qwen",
165
+ preset: "qwen",
166
+ // The preset's address is per account and per plan; the platform's
167
+ // pay-as-you-go key is used on the region-wide Singapore host.
168
+ baseUrl: "https://dashscope-intl.aliyuncs.com/apps/anthropic",
169
+ format: "anthropic",
170
+ // Alibaba Model Studio, Singapore: the region-wide host (still fully
171
+ // supported; the per-workspace host differs per account).
172
+ host: "dashscope-intl.aliyuncs.com",
173
+ auth: "x-api-key",
174
+ metered: ["/apps/anthropic/v1/messages"],
175
+ free: [],
176
+ // alibabacloud.com/help/en/model-studio/anthropic-api-messages (5 Nov
177
+ // 2026): thinking.type enabled | disabled, budget_tokens; effort xhigh |
178
+ // medium | low (max and high run as xhigh); user and assistant roles
179
+ // only. Web search is a typed tool, refused like Anthropic's.
180
+ send: { drop: ["context_management", "service_tier"], thinking: ["type", "budget_tokens"], thinkingType: { adaptive: "enabled" }, mergeSystemMessages: true, dropDeferredTools: true },
181
+ },
182
+ minimax: {
183
+ name: "minimax",
184
+ preset: "minimax",
185
+ format: "anthropic",
186
+ host: "api.minimax.io",
187
+ auth: "bearer",
188
+ metered: ["/anthropic/v1/messages"],
189
+ free: [{ method: "GET", path: "/anthropic/v1/models" }],
190
+ // platform.minimax.io/docs/api-reference/text-chat-anthropic (10 Nov
191
+ // 2026): thinking.type disabled | adaptive (no budget); effort takes
192
+ // every word ours does; no system role in messages (roles alternate);
193
+ // context_management, stop_sequences and top_k ignored.
194
+ send: { drop: ["context_management", "service_tier"], thinking: ["type"], thinkingType: { enabled: "adaptive" }, mergeSystemMessages: true, dropDeferredTools: true },
195
+ },
196
+ mimo: {
197
+ name: "mimo",
198
+ preset: "",
199
+ baseUrl: "https://api.xiaomimimo.com/anthropic",
200
+ format: "anthropic",
201
+ host: "api.xiaomimimo.com",
202
+ auth: "bearer",
203
+ metered: ["/anthropic/v1/messages"],
204
+ free: [],
205
+ // mimo.mi.com/static/docs/api/chat/anthropic-api-post (10 Nov 2026):
206
+ // the request schema is these fields alone; thinking.type enabled |
207
+ // disabled; a system role in messages is accepted; no effort.
208
+ send: {
209
+ fields: ["model", "messages", "max_tokens", "system", "stream", "stop_sequences", "temperature", "top_p", "tools", "tool_choice", "thinking"],
210
+ thinking: ["type"],
211
+ thinkingType: { adaptive: "enabled" },
212
+ dropDeferredTools: true,
213
+ },
214
+ },
136
215
  };
137
216
 
138
217
  export const SUPPLY_PROVIDER_NAMES = Object.keys(SUPPLY_PROVIDERS) as SupplyProviderName[];
@@ -144,6 +223,10 @@ export const SUPPLY_TITLES: Record<SupplyProviderName, string> = {
144
223
  gemini: "Google Gemini",
145
224
  deepseek: "DeepSeek",
146
225
  moonshot: "Moonshot Kimi",
226
+ zai: "Z.ai GLM",
227
+ qwen: "Alibaba Qwen",
228
+ minimax: "MiniMax",
229
+ mimo: "Xiaomi MiMo",
147
230
  };
148
231
 
149
232
  export function isSupplyProvider(name: unknown): name is SupplyProviderName {
@@ -192,12 +275,16 @@ export function supplyProviderOfToken(value: string | null | undefined): SupplyP
192
275
  * placeholder only. */
193
276
  export function supplyProviderBlock(provider: SupplyProviderName, tiers: Partial<Record<"fast" | "default" | "max", string>>): Record<string, unknown> {
194
277
  const p = SUPPLY_PROVIDERS[provider];
195
- const preset = providerPreset(p.preset);
196
- if (!preset?.baseUrl) throw new Error(`model supply: no preset endpoint for ${provider}`);
278
+ const preset = p.preset ? providerPreset(p.preset) : undefined;
279
+ const baseUrl = p.baseUrl ?? preset?.baseUrl;
280
+ if (!baseUrl) throw new Error(`model supply: no endpoint for ${provider}`);
197
281
  return {
198
- name: p.preset,
199
- base_url: preset.baseUrl,
282
+ // A provider the runtime has no preset for is spelled out whole: its
283
+ // address, format and auth, no name to look up.
284
+ ...(preset ? { name: p.preset } : {}),
285
+ base_url: baseUrl,
200
286
  format: p.format,
287
+ auth: p.auth,
201
288
  token: supplyToken(provider),
202
289
  ...(Object.keys(tiers).length ? { models: tiers } : {}),
203
290
  };
@@ -226,6 +313,14 @@ export function shapeRequest(p: SupplyProvider, json: Record<string, unknown>):
226
313
  for (const k of Object.keys(t)) if (!shape.thinking.includes(k)) (delete t[k], (changed = true));
227
314
  }
228
315
  }
316
+ if (shape.thinkingType && json.thinking && typeof json.thinking === "object") {
317
+ const t = json.thinking as Record<string, unknown>;
318
+ const to = typeof t.type === "string" ? shape.thinkingType[t.type] : undefined;
319
+ if (to !== undefined && to !== t.type) {
320
+ t.type = to;
321
+ changed = true;
322
+ }
323
+ }
229
324
  if (shape.dropDeferredTools && Array.isArray(json.tools)) {
230
325
  const kept = (json.tools as unknown[]).filter((t) => !(t && typeof t === "object" && (t as Record<string, unknown>).defer_loading === true));
231
326
  if (kept.length !== json.tools.length) {
@@ -271,6 +366,11 @@ export function shapeRequest(p: SupplyProvider, json: Record<string, unknown>):
271
366
  * "medium and xhigh both map to high"). Said, not rewritten. */
272
367
  const DEEPSEEK_RUNS: Record<string, string> = { low: "low", medium: "high", high: "high", xhigh: "high", max: "max" };
273
368
 
369
+ /** Qwen 3.8 runs xhigh, medium and low ("max and high map to xhigh",
370
+ * Alibaba's Anthropic API page, 5 Nov 2026). Its other models' levels are
371
+ * not documented: said as written. */
372
+ const QWEN38_RUNS: Record<string, string> = { low: "low", medium: "medium", high: "xhigh", xhigh: "xhigh", max: "xhigh" };
373
+
274
374
  /**
275
375
  * The effort a foldrun level actually runs at on one of foldrun's models:
276
376
  * the provider's own aliases (DeepSeek), its reshaping (Kimi), the model's
@@ -283,6 +383,7 @@ export function effortRunsAs(provider: SupplyProviderName, model: string, word:
283
383
  const p = SUPPLY_PROVIDERS[provider];
284
384
  if (p.send?.effort) return p.send.effort[word] ?? null;
285
385
  if (provider === "deepseek") return DEEPSEEK_RUNS[word] ?? null;
386
+ if (provider === "qwen" && /^qwen3\.8/i.test(model)) return QWEN38_RUNS[word] ?? null;
286
387
  if (p.format === "anthropic") return word;
287
388
  return fitEffort(model, word);
288
389
  }
package/src/otel.ts CHANGED
@@ -99,7 +99,7 @@ const lastError = (s: StepRecord | undefined) => {
99
99
  * says whose model it was: the platform's own Claude credential, or one of
100
100
  * foldrun's models. An account's own provider: block could be anyone's, so
101
101
  * it says nothing rather than guess. */
102
- const PROVIDER: Record<string, string> = { anthropic: "anthropic", openai: "openai", gemini: "gcp.gemini", deepseek: "deepseek", moonshot: "moonshot_ai" };
102
+ const PROVIDER: Record<string, string> = { anthropic: "anthropic", openai: "openai", gemini: "gcp.gemini", deepseek: "deepseek", moonshot: "moonshot_ai", zai: "z_ai", qwen: "alibaba_qwen", minimax: "minimax", mimo: "xiaomi_mimo" };
103
103
  function providerOf(step: StepRecord | undefined): string | null {
104
104
  if (!step) return null;
105
105
  // A refusal retried on the fallback supply (runner.ts) runs calls the