@warmdrift/kgauto-compiler 2.0.0-alpha.64 → 2.0.0-alpha.65
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.
- package/dist/{chunk-QKXTMVCT.mjs → chunk-4UO4CCSP.mjs} +150 -0
- package/dist/{chunk-YZRPNSSQ.mjs → chunk-DJVGJEJU.mjs} +13 -3
- package/dist/{chunk-DGPYLFDG.mjs → chunk-XTZ2ZQJQ.mjs} +14 -1
- package/dist/glassbox/index.d.mts +3 -3
- package/dist/glassbox/index.d.ts +3 -3
- package/dist/glassbox-routes/format.d.mts +2 -2
- package/dist/glassbox-routes/format.d.ts +2 -2
- package/dist/glassbox-routes/index.d.mts +4 -4
- package/dist/glassbox-routes/index.d.ts +4 -4
- package/dist/glassbox-routes/index.js +162 -2
- package/dist/glassbox-routes/index.mjs +2 -2
- package/dist/glassbox-routes/react/index.d.mts +2 -2
- package/dist/glassbox-routes/react/index.d.ts +2 -2
- package/dist/index.d.mts +4 -4
- package/dist/index.d.ts +4 -4
- package/dist/index.js +284 -3
- package/dist/index.mjs +111 -3
- package/dist/{ir-B2dRyJXO.d.mts → ir-9rrfI3yB.d.mts} +32 -1
- package/dist/{ir-ClU56aBc.d.ts → ir-Dx_UXPfP.d.ts} +32 -1
- package/dist/key-health.d.mts +1 -1
- package/dist/key-health.d.ts +1 -1
- package/dist/key-health.js +14 -1
- package/dist/key-health.mjs +1 -1
- package/dist/profiles.d.mts +1 -1
- package/dist/profiles.d.ts +1 -1
- package/dist/profiles.js +150 -0
- package/dist/profiles.mjs +1 -1
- package/dist/{types-CSDweZsl.d.mts → types-B4zlO58J.d.mts} +1 -1
- package/dist/{types-axAX1Bg0.d.mts → types-D-G7KXeI.d.mts} +1 -1
- package/dist/{types-C-Wp7HpI.d.ts → types-DSknEy2B.d.ts} +1 -1
- package/dist/{types-ByN3r0_7.d.ts → types-iwyFQHt3.d.ts} +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1718,6 +1718,156 @@ var PROFILES_RAW = [
|
|
|
1718
1718
|
classify: 8
|
|
1719
1719
|
// overkill
|
|
1720
1720
|
}
|
|
1721
|
+
},
|
|
1722
|
+
// ── Z.ai (GLM) ──
|
|
1723
|
+
// alpha.65 (2026-07-18): first Z.ai profile, provider `zai` added same
|
|
1724
|
+
// release. Step-zero sources (L-049/L-081, all fetched 2026-07-18):
|
|
1725
|
+
// docs.z.ai/guides/llm/glm-5.2 (capabilities), docs.z.ai api-reference
|
|
1726
|
+
// chat-completion (wire params: thinking.type enabled|disabled default
|
|
1727
|
+
// enabled, reasoning_effort max..none, tool_stream, max output 131072),
|
|
1728
|
+
// docs.z.ai/guides/overview/pricing ($1.4 in / $4.4 out, cached input
|
|
1729
|
+
// $0.26, cache storage limited-time free), vLLM recipe (native ctx
|
|
1730
|
+
// 1,048,576). NO AI-trained numbers.
|
|
1731
|
+
{
|
|
1732
|
+
id: "glm-5.2",
|
|
1733
|
+
verifiedAgainstDocs: "2026-07-18",
|
|
1734
|
+
provider: "zai",
|
|
1735
|
+
status: "preview",
|
|
1736
|
+
maxContextTokens: 1048576,
|
|
1737
|
+
maxOutputTokens: 131072,
|
|
1738
|
+
// No documented tool-count cap — conservative default pending measured
|
|
1739
|
+
// evidence; matches the deepseek posture, not a doc number.
|
|
1740
|
+
maxTools: 16,
|
|
1741
|
+
// Hosted-API docs document tools + tool_choice + tool_stream but say
|
|
1742
|
+
// NOTHING about multiple tool_calls per response. Conservative false so
|
|
1743
|
+
// hunt-shaped ranking doesn't over-promise; flip on doc or probe
|
|
1744
|
+
// evidence (L-081: undocumented ≠ true).
|
|
1745
|
+
parallelToolCalls: false,
|
|
1746
|
+
structuredOutput: "native",
|
|
1747
|
+
systemPromptMode: "inline",
|
|
1748
|
+
streaming: true,
|
|
1749
|
+
cliffs: [],
|
|
1750
|
+
costInputPer1m: 1.4,
|
|
1751
|
+
costOutputPer1m: 4.4,
|
|
1752
|
+
lowering: {
|
|
1753
|
+
system: { mode: "inline" },
|
|
1754
|
+
// Automatic prefix caching ("intelligent caching mechanism") — no wire
|
|
1755
|
+
// marker to emit, DeepSeek-style. Cache-hit input $0.26/M (~0.19× of
|
|
1756
|
+
// miss) tracked in notes; storage limited-time free as of 2026-07-18.
|
|
1757
|
+
cache: { strategy: "unsupported" },
|
|
1758
|
+
tools: { format: "openai" },
|
|
1759
|
+
// thinking.type: 'enabled' (server default) | 'disabled'. lowerZai
|
|
1760
|
+
// emits an explicit disable only on forceThinkingZero cliffs.
|
|
1761
|
+
thinking: { field: "thinking.type", default: "auto" }
|
|
1762
|
+
},
|
|
1763
|
+
recovery: [
|
|
1764
|
+
{ signal: "rate_limit", action: "escalate", reason: "429 \u2014 escalate" },
|
|
1765
|
+
{ signal: "model_not_found", action: "escalate", reason: "Deprecated \u2014 escalate (L-061)" }
|
|
1766
|
+
],
|
|
1767
|
+
strengths: ["cost", "1m_context", "code", "tool_use", "json_output", "reasoning"],
|
|
1768
|
+
weaknesses: ["parallel_tools"],
|
|
1769
|
+
notes: "GLM-5.2 (Z.ai, 2026-06): agentic-coding flagship. 1,048,576 ctx / 131,072 max out. $1.40/$4.40 per 1M; cached input $0.26/M (automatic caching, no marker; storage limited-time free as of 2026-07-18). Thinking on by default (`thinking.type`), `reasoning_effort` max..none. Parallel tool calls UNDOCUMENTED on the hosted API \u2014 profile says false until doc or probe evidence. status:preview \u2014 no brain evidence yet; earns placement via the machinery.",
|
|
1770
|
+
// Starter hypotheses — verify with telemetry/probes; NO brain evidence
|
|
1771
|
+
// yet. Anchored on the vendor's agentic-coding positioning at a
|
|
1772
|
+
// mid-cost tier, discounted for the unproven parallel-tool story.
|
|
1773
|
+
archetypePerf: {
|
|
1774
|
+
generate: 7,
|
|
1775
|
+
// agentic-coding positioning — starter hypothesis
|
|
1776
|
+
transform: 7,
|
|
1777
|
+
// starter hypothesis
|
|
1778
|
+
plan: 7,
|
|
1779
|
+
// starter hypothesis
|
|
1780
|
+
summarize: 7,
|
|
1781
|
+
// tolerant archetype — starter hypothesis
|
|
1782
|
+
ask: 6,
|
|
1783
|
+
extract: 6,
|
|
1784
|
+
critique: 6,
|
|
1785
|
+
classify: 6,
|
|
1786
|
+
hunt: 5
|
|
1787
|
+
// tools work; parallel unproven → discounted
|
|
1788
|
+
}
|
|
1789
|
+
},
|
|
1790
|
+
// ── Moonshot (Kimi) ──
|
|
1791
|
+
// alpha.65 (2026-07-18): first Moonshot profile, provider `moonshot` added
|
|
1792
|
+
// same release. Step-zero sources (all fetched 2026-07-18):
|
|
1793
|
+
// platform.kimi.ai/docs/pricing/chat-k3 ($3.00 cache-miss in / $0.30
|
|
1794
|
+
// cache-hit in / $15.00 out; 1,048,576 ctx; ToolCalls + JSON Mode +
|
|
1795
|
+
// Partial Mode), kimi-k3-quickstart (max_completion_tokens default
|
|
1796
|
+
// 131072, up to 1,048,576; base https://api.moonshot.ai/v1; vision via
|
|
1797
|
+
// base64 or ms://file-id, NO public image URLs), models-overview
|
|
1798
|
+
// (temperature FIXED 1.0, top_p FIXED 0.95, n FIXED 1, always reasons,
|
|
1799
|
+
// reasoning_effort 'max' only), tool-calls guide ("can choose to call
|
|
1800
|
+
// multiple tools at once … will tend to call them in parallel").
|
|
1801
|
+
{
|
|
1802
|
+
id: "kimi-k3",
|
|
1803
|
+
verifiedAgainstDocs: "2026-07-18",
|
|
1804
|
+
provider: "moonshot",
|
|
1805
|
+
status: "preview",
|
|
1806
|
+
maxContextTokens: 1048576,
|
|
1807
|
+
// Documented ceiling; default is 131,072 when unset.
|
|
1808
|
+
maxOutputTokens: 1048576,
|
|
1809
|
+
// No hard doc cap; docs recommend dynamic tool loading at "dozens or
|
|
1810
|
+
// hundreds" — 64 matches the frontier-agentic posture (sonnet-5 tier).
|
|
1811
|
+
maxTools: 64,
|
|
1812
|
+
parallelToolCalls: true,
|
|
1813
|
+
structuredOutput: "native",
|
|
1814
|
+
systemPromptMode: "inline",
|
|
1815
|
+
streaming: true,
|
|
1816
|
+
cliffs: [],
|
|
1817
|
+
costInputPer1m: 3,
|
|
1818
|
+
costOutputPer1m: 15,
|
|
1819
|
+
lowering: {
|
|
1820
|
+
system: { mode: "inline" },
|
|
1821
|
+
// Automatic context caching — no wire marker. Cache-hit input $0.30/M
|
|
1822
|
+
// (0.1× of miss) tracked in notes.
|
|
1823
|
+
cache: { strategy: "unsupported" },
|
|
1824
|
+
tools: { format: "openai" }
|
|
1825
|
+
// No thinking knob: reasoning is always-on and reasoning_effort
|
|
1826
|
+
// accepts only 'max' (= the server default). Nothing to lower.
|
|
1827
|
+
},
|
|
1828
|
+
recovery: [
|
|
1829
|
+
{ signal: "rate_limit", action: "escalate", reason: "429 \u2014 escalate" },
|
|
1830
|
+
{ signal: "model_not_found", action: "escalate", reason: "Deprecated \u2014 escalate (L-061)" }
|
|
1831
|
+
],
|
|
1832
|
+
strengths: ["quality", "reasoning", "1m_context", "parallel_tools", "tool_use", "code", "vision"],
|
|
1833
|
+
// 'latency' → latencyTierOf derives 'slow': always-on max-effort
|
|
1834
|
+
// reasoner with no off switch; no measured p50 yet, the tag is the
|
|
1835
|
+
// honest prior (reasoner family precedent: deepseek-v4-pro ~48s).
|
|
1836
|
+
weaknesses: ["cost", "latency"],
|
|
1837
|
+
notes: "Kimi K3 (Moonshot, API live 2026-07-16): 2.8T-param open-weight flagship, native vision. 1,048,576 ctx; max_completion_tokens default 131,072, ceiling 1,048,576. $3.00/$15.00 per 1M, cache-hit input $0.30/M (automatic caching). Reasoning ALWAYS ON (reasoning_effort max only, cannot disable; responses may carry reasoning_content). Wire quirks: temperature fixed 1.0 / top_p 0.95 / n 1 (kgauto never emits those); vision input must be base64 or ms://file-id \u2014 public image URLs rejected. status:preview \u2014 earns placement via the machinery.",
|
|
1838
|
+
// Starter hypotheses — verify with telemetry/probes; NO brain evidence
|
|
1839
|
+
// yet. Anchored on documented long-horizon-agentic + parallel-tool
|
|
1840
|
+
// strengths; discounted on terse archetypes where always-on reasoning
|
|
1841
|
+
// bills $15/M output for thinking the archetype doesn't need.
|
|
1842
|
+
archetypePerf: {
|
|
1843
|
+
hunt: 8,
|
|
1844
|
+
// parallel tools + long-horizon agentic — starter hypothesis
|
|
1845
|
+
plan: 8,
|
|
1846
|
+
// starter hypothesis
|
|
1847
|
+
generate: 8,
|
|
1848
|
+
// starter hypothesis
|
|
1849
|
+
critique: 7,
|
|
1850
|
+
ask: 7,
|
|
1851
|
+
extract: 7,
|
|
1852
|
+
transform: 7,
|
|
1853
|
+
summarize: 6,
|
|
1854
|
+
// works, but $15/M output reasoning tax on a tolerant archetype
|
|
1855
|
+
classify: 5
|
|
1856
|
+
// always-on reasoning cost + reasoner hedge risk
|
|
1857
|
+
},
|
|
1858
|
+
// Diagnostics-only (no prompt rewrite): reasoner-family hedge risk on
|
|
1859
|
+
// decisive archetypes, carried as a warning until K3-specific probe
|
|
1860
|
+
// evidence exists. The deepseek-reasoner family showed 8/10 judge
|
|
1861
|
+
// rationales citing hedging on classify (exclusion-finding ID 20,
|
|
1862
|
+
// 2026-05-28); K3 is an always-on reasoner and inherits the risk class,
|
|
1863
|
+
// not the conviction.
|
|
1864
|
+
archetypeConventions: [
|
|
1865
|
+
{
|
|
1866
|
+
archetype: "classify",
|
|
1867
|
+
cliffWarning: "kimi-k3 is an always-on reasoner: decisive archetypes (classify) may hedge, and reasoning tokens bill at $15/M output. Family-prior risk (deepseek-reasoner precedent), not K3-measured \u2014 probe before relying on it for classify.",
|
|
1868
|
+
reason: "Reasoner-family prior (exclusion-finding ID 20, 2026-05-28, deepseek-v4-pro on tt-intel/classify). No K3-specific evidence yet \u2014 warning only, no prompt rewrite."
|
|
1869
|
+
}
|
|
1870
|
+
]
|
|
1721
1871
|
}
|
|
1722
1872
|
];
|
|
1723
1873
|
var ALIASES = {
|
|
@@ -2972,6 +3122,10 @@ function lower(ir, profile, hints = {}) {
|
|
|
2972
3122
|
return lowerOpenAI(ir, profile, hints);
|
|
2973
3123
|
case "deepseek":
|
|
2974
3124
|
return lowerDeepSeek(ir, profile);
|
|
3125
|
+
case "zai":
|
|
3126
|
+
return lowerZai(ir, profile, hints);
|
|
3127
|
+
case "moonshot":
|
|
3128
|
+
return lowerMoonshot(ir, profile);
|
|
2975
3129
|
default:
|
|
2976
3130
|
throw new Error(`No lowering implementation for provider: ${profile.provider}`);
|
|
2977
3131
|
}
|
|
@@ -3260,6 +3414,68 @@ function lowerDeepSeek(ir, profile) {
|
|
|
3260
3414
|
}
|
|
3261
3415
|
};
|
|
3262
3416
|
}
|
|
3417
|
+
function buildOpenAICompatibleParts(ir) {
|
|
3418
|
+
const ordered = sortSections(ir.sections);
|
|
3419
|
+
const systemText = ordered.map((s) => s.text).join("\n\n");
|
|
3420
|
+
const messages = systemText ? [{ role: "system", content: systemText }] : [];
|
|
3421
|
+
for (const m of ir.history ?? []) {
|
|
3422
|
+
if (m.role === "system") continue;
|
|
3423
|
+
messages.push({ role: m.role, content: m.parts ?? m.content });
|
|
3424
|
+
}
|
|
3425
|
+
if (ir.currentTurn && ir.currentTurn.role !== "system") {
|
|
3426
|
+
messages.push({
|
|
3427
|
+
role: ir.currentTurn.role,
|
|
3428
|
+
content: ir.currentTurn.parts ?? ir.currentTurn.content
|
|
3429
|
+
});
|
|
3430
|
+
}
|
|
3431
|
+
const history = (ir.history ?? []).filter((m) => m.role !== "system");
|
|
3432
|
+
const histMarkIndex = resolveHistoryMarkIndex(history.length, ir.historyCachePolicy);
|
|
3433
|
+
const historyCacheableTokens = histMarkIndex >= 0 ? sumHistoryTokens(history, histMarkIndex) : 0;
|
|
3434
|
+
return {
|
|
3435
|
+
messages,
|
|
3436
|
+
tools: ir.tools && ir.tools.length > 0 ? toOpenAITools(ir.tools) : void 0,
|
|
3437
|
+
response_format: ir.constraints?.structuredOutput ? { type: "json_object" } : void 0,
|
|
3438
|
+
historyCacheableTokens
|
|
3439
|
+
};
|
|
3440
|
+
}
|
|
3441
|
+
function lowerZai(ir, profile, hints) {
|
|
3442
|
+
const parts = buildOpenAICompatibleParts(ir);
|
|
3443
|
+
return {
|
|
3444
|
+
request: {
|
|
3445
|
+
provider: "zai",
|
|
3446
|
+
model: profile.id,
|
|
3447
|
+
messages: parts.messages,
|
|
3448
|
+
tools: parts.tools,
|
|
3449
|
+
response_format: parts.response_format,
|
|
3450
|
+
// Z.ai thinking defaults to enabled server-side; emit an explicit
|
|
3451
|
+
// disable only when a cliff forced thinking off (the GLM analogue of
|
|
3452
|
+
// Gemini's thinkingBudget=0).
|
|
3453
|
+
thinking: hints.forceThinkingZero ? { type: "disabled" } : void 0
|
|
3454
|
+
},
|
|
3455
|
+
diagnostics: {
|
|
3456
|
+
cacheableTokens: 0,
|
|
3457
|
+
historyCacheableTokens: parts.historyCacheableTokens,
|
|
3458
|
+
estimatedCacheSavingsUsd: 0
|
|
3459
|
+
}
|
|
3460
|
+
};
|
|
3461
|
+
}
|
|
3462
|
+
function lowerMoonshot(ir, profile) {
|
|
3463
|
+
const parts = buildOpenAICompatibleParts(ir);
|
|
3464
|
+
return {
|
|
3465
|
+
request: {
|
|
3466
|
+
provider: "moonshot",
|
|
3467
|
+
model: profile.id,
|
|
3468
|
+
messages: parts.messages,
|
|
3469
|
+
tools: parts.tools,
|
|
3470
|
+
response_format: parts.response_format
|
|
3471
|
+
},
|
|
3472
|
+
diagnostics: {
|
|
3473
|
+
cacheableTokens: 0,
|
|
3474
|
+
historyCacheableTokens: parts.historyCacheableTokens,
|
|
3475
|
+
estimatedCacheSavingsUsd: 0
|
|
3476
|
+
}
|
|
3477
|
+
};
|
|
3478
|
+
}
|
|
3263
3479
|
function sortSections(sections) {
|
|
3264
3480
|
return [...sections].sort((a, b) => {
|
|
3265
3481
|
const wa = a.weight ?? 100;
|
|
@@ -5316,7 +5532,9 @@ var SUPPORTED_PROVIDERS = Object.freeze([
|
|
|
5316
5532
|
"anthropic",
|
|
5317
5533
|
"google",
|
|
5318
5534
|
"openai",
|
|
5319
|
-
"deepseek"
|
|
5535
|
+
"deepseek",
|
|
5536
|
+
"zai",
|
|
5537
|
+
"moonshot"
|
|
5320
5538
|
]);
|
|
5321
5539
|
function isSupportedProvider(p) {
|
|
5322
5540
|
return SUPPORTED_PROVIDERS.includes(p);
|
|
@@ -5329,7 +5547,15 @@ var PROVIDER_ENV_KEYS = Object.freeze({
|
|
|
5329
5547
|
"GOOGLE_GENERATIVE_AI_API_KEY"
|
|
5330
5548
|
]),
|
|
5331
5549
|
openai: Object.freeze(["OPENAI_API_KEY"]),
|
|
5332
|
-
deepseek: Object.freeze(["DEEPSEEK_API_KEY"])
|
|
5550
|
+
deepseek: Object.freeze(["DEEPSEEK_API_KEY"]),
|
|
5551
|
+
// alpha.65 — Z.ai (GLM family). ZAI_API_KEY is the canonical name; the
|
|
5552
|
+
// Z_AI_API_KEY variant covers the underscore convention some tooling uses
|
|
5553
|
+
// for the brand's "Z.ai" spelling.
|
|
5554
|
+
zai: Object.freeze(["ZAI_API_KEY", "Z_AI_API_KEY"]),
|
|
5555
|
+
// alpha.65 — Moonshot AI (Kimi family). MOONSHOT_API_KEY is canonical
|
|
5556
|
+
// (api.moonshot.ai); KIMI_API_KEY covers the platform.kimi.ai rebrand
|
|
5557
|
+
// surface so consumers keyed under either name resolve.
|
|
5558
|
+
moonshot: Object.freeze(["MOONSHOT_API_KEY", "KIMI_API_KEY"])
|
|
5333
5559
|
});
|
|
5334
5560
|
function defaultEnv() {
|
|
5335
5561
|
return typeof process !== "undefined" && process.env ? process.env : {};
|
|
@@ -5673,6 +5899,8 @@ function retryableError(status, code, message, raw) {
|
|
|
5673
5899
|
var ANTHROPIC_URL2 = "https://api.anthropic.com/v1/messages";
|
|
5674
5900
|
var OPENAI_URL = "https://api.openai.com/v1/chat/completions";
|
|
5675
5901
|
var DEEPSEEK_URL = "https://api.deepseek.com/chat/completions";
|
|
5902
|
+
var ZAI_URL = "https://api.z.ai/api/paas/v4/chat/completions";
|
|
5903
|
+
var MOONSHOT_URL = "https://api.moonshot.ai/v1/chat/completions";
|
|
5676
5904
|
async function execute(request, opts = {}) {
|
|
5677
5905
|
const merged = applyOverrides(request, opts.providerOverrides);
|
|
5678
5906
|
switch (merged.provider) {
|
|
@@ -5684,6 +5912,18 @@ async function execute(request, opts = {}) {
|
|
|
5684
5912
|
return executeOpenAI(merged, opts);
|
|
5685
5913
|
case "deepseek":
|
|
5686
5914
|
return executeDeepSeek(merged, opts);
|
|
5915
|
+
case "zai":
|
|
5916
|
+
return executeOpenAICompatible(
|
|
5917
|
+
merged,
|
|
5918
|
+
opts,
|
|
5919
|
+
{ provider: "zai", url: ZAI_URL, missingKeyMessage: "ZAI_API_KEY missing" }
|
|
5920
|
+
);
|
|
5921
|
+
case "moonshot":
|
|
5922
|
+
return executeOpenAICompatible(
|
|
5923
|
+
merged,
|
|
5924
|
+
opts,
|
|
5925
|
+
{ provider: "moonshot", url: MOONSHOT_URL, missingKeyMessage: "MOONSHOT_API_KEY missing" }
|
|
5926
|
+
);
|
|
5687
5927
|
default: {
|
|
5688
5928
|
const _exhaustive = merged;
|
|
5689
5929
|
throw new Error(`execute(): no executor for provider: ${JSON.stringify(_exhaustive)}`);
|
|
@@ -5833,6 +6073,34 @@ async function executeDeepSeek(request, opts) {
|
|
|
5833
6073
|
if (!res.ok) return classifyHttpError2(res.status, json);
|
|
5834
6074
|
return { ok: true, status: res.status, response: normalizeOpenAILike(json) };
|
|
5835
6075
|
}
|
|
6076
|
+
async function executeOpenAICompatible(request, opts, spec) {
|
|
6077
|
+
const apiKey = resolveProviderKey(spec.provider, { apiKeys: opts.apiKeys });
|
|
6078
|
+
if (!apiKey) {
|
|
6079
|
+
return terminalError(401, "auth", spec.missingKeyMessage);
|
|
6080
|
+
}
|
|
6081
|
+
if (opts.onChunk) {
|
|
6082
|
+
return streamOpenAILike(spec.url, request, apiKey, spec.provider, {
|
|
6083
|
+
onChunk: opts.onChunk,
|
|
6084
|
+
fetchImpl: opts.fetchImpl
|
|
6085
|
+
});
|
|
6086
|
+
}
|
|
6087
|
+
const { provider: _provider, ...body } = request;
|
|
6088
|
+
const fetchFn = opts.fetchImpl ?? fetch;
|
|
6089
|
+
let res;
|
|
6090
|
+
let json;
|
|
6091
|
+
try {
|
|
6092
|
+
res = await fetchFn(spec.url, {
|
|
6093
|
+
method: "POST",
|
|
6094
|
+
headers: { authorization: `Bearer ${apiKey}`, "content-type": "application/json" },
|
|
6095
|
+
body: JSON.stringify(body)
|
|
6096
|
+
});
|
|
6097
|
+
json = await res.json().catch(() => ({}));
|
|
6098
|
+
} catch (err) {
|
|
6099
|
+
return retryableError2(0, "network_error", String(err), null);
|
|
6100
|
+
}
|
|
6101
|
+
if (!res.ok) return classifyHttpError2(res.status, json);
|
|
6102
|
+
return { ok: true, status: res.status, response: normalizeOpenAILike(json) };
|
|
6103
|
+
}
|
|
5836
6104
|
function normalizeOpenAILike(raw) {
|
|
5837
6105
|
const r = raw;
|
|
5838
6106
|
const choice = r.choices?.[0];
|
|
@@ -7948,7 +8216,7 @@ function createBrainForwardRoutes(config) {
|
|
|
7948
8216
|
}
|
|
7949
8217
|
|
|
7950
8218
|
// src/version.ts
|
|
7951
|
-
var LIBRARY_VERSION = "2.0.0-alpha.
|
|
8219
|
+
var LIBRARY_VERSION = "2.0.0-alpha.65";
|
|
7952
8220
|
|
|
7953
8221
|
// src/key-health.ts
|
|
7954
8222
|
var JSON_HEADERS2 = { "Content-Type": "application/json" };
|
|
@@ -7997,6 +8265,14 @@ var PROBE_SPECS = [
|
|
|
7997
8265
|
return Number.isFinite(n) ? n : void 0;
|
|
7998
8266
|
}
|
|
7999
8267
|
},
|
|
8268
|
+
{
|
|
8269
|
+
provider: "moonshot",
|
|
8270
|
+
canonicalEnvName: "MOONSHOT_API_KEY",
|
|
8271
|
+
buildRequest: (key) => ({
|
|
8272
|
+
url: "https://api.moonshot.ai/v1/models",
|
|
8273
|
+
headers: { Authorization: `Bearer ${key}` }
|
|
8274
|
+
})
|
|
8275
|
+
},
|
|
8000
8276
|
{
|
|
8001
8277
|
provider: "google",
|
|
8002
8278
|
canonicalEnvName: "GEMINI_API_KEY",
|
|
@@ -8028,6 +8304,11 @@ function createKeyHealthRoute(config) {
|
|
|
8028
8304
|
const aiSdk = envKey(env, "GOOGLE_GENERATIVE_AI_API_KEY");
|
|
8029
8305
|
key = gemini ?? google ?? aiSdk;
|
|
8030
8306
|
envName = gemini ? "GEMINI_API_KEY" : google ? "GOOGLE_API_KEY" : aiSdk ? "GOOGLE_GENERATIVE_AI_API_KEY" : "GEMINI_API_KEY";
|
|
8307
|
+
} else if (spec.provider === "moonshot") {
|
|
8308
|
+
const moonshot = envKey(env, "MOONSHOT_API_KEY");
|
|
8309
|
+
const kimi = envKey(env, "KIMI_API_KEY");
|
|
8310
|
+
key = moonshot ?? kimi;
|
|
8311
|
+
envName = moonshot ? "MOONSHOT_API_KEY" : kimi ? "KIMI_API_KEY" : "MOONSHOT_API_KEY";
|
|
8031
8312
|
} else {
|
|
8032
8313
|
key = envKey(env, spec.canonicalEnvName);
|
|
8033
8314
|
}
|
package/dist/index.mjs
CHANGED
|
@@ -15,7 +15,7 @@ import {
|
|
|
15
15
|
import {
|
|
16
16
|
LIBRARY_VERSION,
|
|
17
17
|
createKeyHealthRoute
|
|
18
|
-
} from "./chunk-
|
|
18
|
+
} from "./chunk-XTZ2ZQJQ.mjs";
|
|
19
19
|
import {
|
|
20
20
|
ABSOLUTE_FLOOR,
|
|
21
21
|
ARCHETYPE_FLOOR_DEFAULT,
|
|
@@ -40,7 +40,7 @@ import {
|
|
|
40
40
|
loadChainsFromBrain,
|
|
41
41
|
readBrainReadEnv,
|
|
42
42
|
resolveProviderKey
|
|
43
|
-
} from "./chunk-
|
|
43
|
+
} from "./chunk-DJVGJEJU.mjs";
|
|
44
44
|
import {
|
|
45
45
|
ALIASES,
|
|
46
46
|
LATENCY_TIER_MS,
|
|
@@ -51,7 +51,7 @@ import {
|
|
|
51
51
|
latencyTierOf,
|
|
52
52
|
profilesByProvider,
|
|
53
53
|
tryGetProfile
|
|
54
|
-
} from "./chunk-
|
|
54
|
+
} from "./chunk-4UO4CCSP.mjs";
|
|
55
55
|
import {
|
|
56
56
|
emitAdvisoryFired,
|
|
57
57
|
emitCompileDone,
|
|
@@ -1102,6 +1102,10 @@ function lower(ir, profile, hints = {}) {
|
|
|
1102
1102
|
return lowerOpenAI(ir, profile, hints);
|
|
1103
1103
|
case "deepseek":
|
|
1104
1104
|
return lowerDeepSeek(ir, profile);
|
|
1105
|
+
case "zai":
|
|
1106
|
+
return lowerZai(ir, profile, hints);
|
|
1107
|
+
case "moonshot":
|
|
1108
|
+
return lowerMoonshot(ir, profile);
|
|
1105
1109
|
default:
|
|
1106
1110
|
throw new Error(`No lowering implementation for provider: ${profile.provider}`);
|
|
1107
1111
|
}
|
|
@@ -1390,6 +1394,68 @@ function lowerDeepSeek(ir, profile) {
|
|
|
1390
1394
|
}
|
|
1391
1395
|
};
|
|
1392
1396
|
}
|
|
1397
|
+
function buildOpenAICompatibleParts(ir) {
|
|
1398
|
+
const ordered = sortSections(ir.sections);
|
|
1399
|
+
const systemText = ordered.map((s) => s.text).join("\n\n");
|
|
1400
|
+
const messages = systemText ? [{ role: "system", content: systemText }] : [];
|
|
1401
|
+
for (const m of ir.history ?? []) {
|
|
1402
|
+
if (m.role === "system") continue;
|
|
1403
|
+
messages.push({ role: m.role, content: m.parts ?? m.content });
|
|
1404
|
+
}
|
|
1405
|
+
if (ir.currentTurn && ir.currentTurn.role !== "system") {
|
|
1406
|
+
messages.push({
|
|
1407
|
+
role: ir.currentTurn.role,
|
|
1408
|
+
content: ir.currentTurn.parts ?? ir.currentTurn.content
|
|
1409
|
+
});
|
|
1410
|
+
}
|
|
1411
|
+
const history = (ir.history ?? []).filter((m) => m.role !== "system");
|
|
1412
|
+
const histMarkIndex = resolveHistoryMarkIndex(history.length, ir.historyCachePolicy);
|
|
1413
|
+
const historyCacheableTokens = histMarkIndex >= 0 ? sumHistoryTokens(history, histMarkIndex) : 0;
|
|
1414
|
+
return {
|
|
1415
|
+
messages,
|
|
1416
|
+
tools: ir.tools && ir.tools.length > 0 ? toOpenAITools(ir.tools) : void 0,
|
|
1417
|
+
response_format: ir.constraints?.structuredOutput ? { type: "json_object" } : void 0,
|
|
1418
|
+
historyCacheableTokens
|
|
1419
|
+
};
|
|
1420
|
+
}
|
|
1421
|
+
function lowerZai(ir, profile, hints) {
|
|
1422
|
+
const parts = buildOpenAICompatibleParts(ir);
|
|
1423
|
+
return {
|
|
1424
|
+
request: {
|
|
1425
|
+
provider: "zai",
|
|
1426
|
+
model: profile.id,
|
|
1427
|
+
messages: parts.messages,
|
|
1428
|
+
tools: parts.tools,
|
|
1429
|
+
response_format: parts.response_format,
|
|
1430
|
+
// Z.ai thinking defaults to enabled server-side; emit an explicit
|
|
1431
|
+
// disable only when a cliff forced thinking off (the GLM analogue of
|
|
1432
|
+
// Gemini's thinkingBudget=0).
|
|
1433
|
+
thinking: hints.forceThinkingZero ? { type: "disabled" } : void 0
|
|
1434
|
+
},
|
|
1435
|
+
diagnostics: {
|
|
1436
|
+
cacheableTokens: 0,
|
|
1437
|
+
historyCacheableTokens: parts.historyCacheableTokens,
|
|
1438
|
+
estimatedCacheSavingsUsd: 0
|
|
1439
|
+
}
|
|
1440
|
+
};
|
|
1441
|
+
}
|
|
1442
|
+
function lowerMoonshot(ir, profile) {
|
|
1443
|
+
const parts = buildOpenAICompatibleParts(ir);
|
|
1444
|
+
return {
|
|
1445
|
+
request: {
|
|
1446
|
+
provider: "moonshot",
|
|
1447
|
+
model: profile.id,
|
|
1448
|
+
messages: parts.messages,
|
|
1449
|
+
tools: parts.tools,
|
|
1450
|
+
response_format: parts.response_format
|
|
1451
|
+
},
|
|
1452
|
+
diagnostics: {
|
|
1453
|
+
cacheableTokens: 0,
|
|
1454
|
+
historyCacheableTokens: parts.historyCacheableTokens,
|
|
1455
|
+
estimatedCacheSavingsUsd: 0
|
|
1456
|
+
}
|
|
1457
|
+
};
|
|
1458
|
+
}
|
|
1393
1459
|
function sortSections(sections) {
|
|
1394
1460
|
return [...sections].sort((a, b) => {
|
|
1395
1461
|
const wa = a.weight ?? 100;
|
|
@@ -3732,6 +3798,8 @@ function retryableError(status, code, message, raw) {
|
|
|
3732
3798
|
var ANTHROPIC_URL2 = "https://api.anthropic.com/v1/messages";
|
|
3733
3799
|
var OPENAI_URL = "https://api.openai.com/v1/chat/completions";
|
|
3734
3800
|
var DEEPSEEK_URL = "https://api.deepseek.com/chat/completions";
|
|
3801
|
+
var ZAI_URL = "https://api.z.ai/api/paas/v4/chat/completions";
|
|
3802
|
+
var MOONSHOT_URL = "https://api.moonshot.ai/v1/chat/completions";
|
|
3735
3803
|
async function execute(request, opts = {}) {
|
|
3736
3804
|
const merged = applyOverrides(request, opts.providerOverrides);
|
|
3737
3805
|
switch (merged.provider) {
|
|
@@ -3743,6 +3811,18 @@ async function execute(request, opts = {}) {
|
|
|
3743
3811
|
return executeOpenAI(merged, opts);
|
|
3744
3812
|
case "deepseek":
|
|
3745
3813
|
return executeDeepSeek(merged, opts);
|
|
3814
|
+
case "zai":
|
|
3815
|
+
return executeOpenAICompatible(
|
|
3816
|
+
merged,
|
|
3817
|
+
opts,
|
|
3818
|
+
{ provider: "zai", url: ZAI_URL, missingKeyMessage: "ZAI_API_KEY missing" }
|
|
3819
|
+
);
|
|
3820
|
+
case "moonshot":
|
|
3821
|
+
return executeOpenAICompatible(
|
|
3822
|
+
merged,
|
|
3823
|
+
opts,
|
|
3824
|
+
{ provider: "moonshot", url: MOONSHOT_URL, missingKeyMessage: "MOONSHOT_API_KEY missing" }
|
|
3825
|
+
);
|
|
3746
3826
|
default: {
|
|
3747
3827
|
const _exhaustive = merged;
|
|
3748
3828
|
throw new Error(`execute(): no executor for provider: ${JSON.stringify(_exhaustive)}`);
|
|
@@ -3892,6 +3972,34 @@ async function executeDeepSeek(request, opts) {
|
|
|
3892
3972
|
if (!res.ok) return classifyHttpError2(res.status, json);
|
|
3893
3973
|
return { ok: true, status: res.status, response: normalizeOpenAILike(json) };
|
|
3894
3974
|
}
|
|
3975
|
+
async function executeOpenAICompatible(request, opts, spec) {
|
|
3976
|
+
const apiKey = resolveProviderKey(spec.provider, { apiKeys: opts.apiKeys });
|
|
3977
|
+
if (!apiKey) {
|
|
3978
|
+
return terminalError(401, "auth", spec.missingKeyMessage);
|
|
3979
|
+
}
|
|
3980
|
+
if (opts.onChunk) {
|
|
3981
|
+
return streamOpenAILike(spec.url, request, apiKey, spec.provider, {
|
|
3982
|
+
onChunk: opts.onChunk,
|
|
3983
|
+
fetchImpl: opts.fetchImpl
|
|
3984
|
+
});
|
|
3985
|
+
}
|
|
3986
|
+
const { provider: _provider, ...body } = request;
|
|
3987
|
+
const fetchFn = opts.fetchImpl ?? fetch;
|
|
3988
|
+
let res;
|
|
3989
|
+
let json;
|
|
3990
|
+
try {
|
|
3991
|
+
res = await fetchFn(spec.url, {
|
|
3992
|
+
method: "POST",
|
|
3993
|
+
headers: { authorization: `Bearer ${apiKey}`, "content-type": "application/json" },
|
|
3994
|
+
body: JSON.stringify(body)
|
|
3995
|
+
});
|
|
3996
|
+
json = await res.json().catch(() => ({}));
|
|
3997
|
+
} catch (err) {
|
|
3998
|
+
return retryableError2(0, "network_error", String(err), null);
|
|
3999
|
+
}
|
|
4000
|
+
if (!res.ok) return classifyHttpError2(res.status, json);
|
|
4001
|
+
return { ok: true, status: res.status, response: normalizeOpenAILike(json) };
|
|
4002
|
+
}
|
|
3895
4003
|
function normalizeOpenAILike(raw) {
|
|
3896
4004
|
const r = raw;
|
|
3897
4005
|
const choice = r.choices?.[0];
|
|
@@ -373,7 +373,7 @@ interface PromptIR {
|
|
|
373
373
|
*/
|
|
374
374
|
historyCachePolicy?: HistoryCachePolicy;
|
|
375
375
|
}
|
|
376
|
-
type Provider = 'anthropic' | 'google' | 'openai' | 'deepseek' | 'mistral' | 'xai';
|
|
376
|
+
type Provider = 'anthropic' | 'google' | 'openai' | 'deepseek' | 'zai' | 'moonshot' | 'mistral' | 'xai';
|
|
377
377
|
/**
|
|
378
378
|
* Mutation IDs that fired during compile. Empty in v1 (no mutation engine
|
|
379
379
|
* yet). Populated when the brain is online and pushing mutations.
|
|
@@ -456,6 +456,33 @@ type CompiledRequest = {
|
|
|
456
456
|
content: unknown;
|
|
457
457
|
}>;
|
|
458
458
|
tools?: unknown[];
|
|
459
|
+
} | {
|
|
460
|
+
provider: 'zai';
|
|
461
|
+
model: string;
|
|
462
|
+
messages: Array<{
|
|
463
|
+
role: string;
|
|
464
|
+
content: unknown;
|
|
465
|
+
}>;
|
|
466
|
+
tools?: unknown[];
|
|
467
|
+
response_format?: unknown;
|
|
468
|
+
/**
|
|
469
|
+
* alpha.65 — Z.ai thinking knob (docs.z.ai chat-completion reference):
|
|
470
|
+
* `thinking.type` is 'enabled' (default) or 'disabled'. Emitted only
|
|
471
|
+
* when a cliff forces thinking off (`force_thinking_budget_zero`);
|
|
472
|
+
* omitted otherwise so the provider default applies.
|
|
473
|
+
*/
|
|
474
|
+
thinking?: {
|
|
475
|
+
type: 'enabled' | 'disabled';
|
|
476
|
+
};
|
|
477
|
+
} | {
|
|
478
|
+
provider: 'moonshot';
|
|
479
|
+
model: string;
|
|
480
|
+
messages: Array<{
|
|
481
|
+
role: string;
|
|
482
|
+
content: unknown;
|
|
483
|
+
}>;
|
|
484
|
+
tools?: unknown[];
|
|
485
|
+
response_format?: unknown;
|
|
459
486
|
};
|
|
460
487
|
/**
|
|
461
488
|
* Best-practice advisory emitted by the compiler at compile time. Non-fatal —
|
|
@@ -866,6 +893,8 @@ interface ApiKeys {
|
|
|
866
893
|
google?: string;
|
|
867
894
|
openai?: string;
|
|
868
895
|
deepseek?: string;
|
|
896
|
+
zai?: string;
|
|
897
|
+
moonshot?: string;
|
|
869
898
|
}
|
|
870
899
|
/**
|
|
871
900
|
* Per-provider override fields shallow-merged into the lowered request before
|
|
@@ -877,6 +906,8 @@ interface ProviderOverrides {
|
|
|
877
906
|
google?: Record<string, unknown>;
|
|
878
907
|
openai?: Record<string, unknown>;
|
|
879
908
|
deepseek?: Record<string, unknown>;
|
|
909
|
+
zai?: Record<string, unknown>;
|
|
910
|
+
moonshot?: Record<string, unknown>;
|
|
880
911
|
}
|
|
881
912
|
/**
|
|
882
913
|
* Full-IR inline shadow-probe config (Shape B, Phase 1 — 2026-05-29 s51).
|
|
@@ -373,7 +373,7 @@ interface PromptIR {
|
|
|
373
373
|
*/
|
|
374
374
|
historyCachePolicy?: HistoryCachePolicy;
|
|
375
375
|
}
|
|
376
|
-
type Provider = 'anthropic' | 'google' | 'openai' | 'deepseek' | 'mistral' | 'xai';
|
|
376
|
+
type Provider = 'anthropic' | 'google' | 'openai' | 'deepseek' | 'zai' | 'moonshot' | 'mistral' | 'xai';
|
|
377
377
|
/**
|
|
378
378
|
* Mutation IDs that fired during compile. Empty in v1 (no mutation engine
|
|
379
379
|
* yet). Populated when the brain is online and pushing mutations.
|
|
@@ -456,6 +456,33 @@ type CompiledRequest = {
|
|
|
456
456
|
content: unknown;
|
|
457
457
|
}>;
|
|
458
458
|
tools?: unknown[];
|
|
459
|
+
} | {
|
|
460
|
+
provider: 'zai';
|
|
461
|
+
model: string;
|
|
462
|
+
messages: Array<{
|
|
463
|
+
role: string;
|
|
464
|
+
content: unknown;
|
|
465
|
+
}>;
|
|
466
|
+
tools?: unknown[];
|
|
467
|
+
response_format?: unknown;
|
|
468
|
+
/**
|
|
469
|
+
* alpha.65 — Z.ai thinking knob (docs.z.ai chat-completion reference):
|
|
470
|
+
* `thinking.type` is 'enabled' (default) or 'disabled'. Emitted only
|
|
471
|
+
* when a cliff forces thinking off (`force_thinking_budget_zero`);
|
|
472
|
+
* omitted otherwise so the provider default applies.
|
|
473
|
+
*/
|
|
474
|
+
thinking?: {
|
|
475
|
+
type: 'enabled' | 'disabled';
|
|
476
|
+
};
|
|
477
|
+
} | {
|
|
478
|
+
provider: 'moonshot';
|
|
479
|
+
model: string;
|
|
480
|
+
messages: Array<{
|
|
481
|
+
role: string;
|
|
482
|
+
content: unknown;
|
|
483
|
+
}>;
|
|
484
|
+
tools?: unknown[];
|
|
485
|
+
response_format?: unknown;
|
|
459
486
|
};
|
|
460
487
|
/**
|
|
461
488
|
* Best-practice advisory emitted by the compiler at compile time. Non-fatal —
|
|
@@ -866,6 +893,8 @@ interface ApiKeys {
|
|
|
866
893
|
google?: string;
|
|
867
894
|
openai?: string;
|
|
868
895
|
deepseek?: string;
|
|
896
|
+
zai?: string;
|
|
897
|
+
moonshot?: string;
|
|
869
898
|
}
|
|
870
899
|
/**
|
|
871
900
|
* Per-provider override fields shallow-merged into the lowered request before
|
|
@@ -877,6 +906,8 @@ interface ProviderOverrides {
|
|
|
877
906
|
google?: Record<string, unknown>;
|
|
878
907
|
openai?: Record<string, unknown>;
|
|
879
908
|
deepseek?: Record<string, unknown>;
|
|
909
|
+
zai?: Record<string, unknown>;
|
|
910
|
+
moonshot?: Record<string, unknown>;
|
|
880
911
|
}
|
|
881
912
|
/**
|
|
882
913
|
* Full-IR inline shadow-probe config (Shape B, Phase 1 — 2026-05-29 s51).
|
package/dist/key-health.d.mts
CHANGED
|
@@ -73,7 +73,7 @@
|
|
|
73
73
|
* ]
|
|
74
74
|
* }
|
|
75
75
|
*/
|
|
76
|
-
type KeyHealthProvider = 'anthropic' | 'deepseek' | 'google' | 'openai';
|
|
76
|
+
type KeyHealthProvider = 'anthropic' | 'deepseek' | 'google' | 'moonshot' | 'openai';
|
|
77
77
|
interface KeyHealthConfig {
|
|
78
78
|
/** Consumer app id echoed as `app_id` in the response (e.g. 'playbacksam'). */
|
|
79
79
|
appId: string;
|
package/dist/key-health.d.ts
CHANGED
|
@@ -73,7 +73,7 @@
|
|
|
73
73
|
* ]
|
|
74
74
|
* }
|
|
75
75
|
*/
|
|
76
|
-
type KeyHealthProvider = 'anthropic' | 'deepseek' | 'google' | 'openai';
|
|
76
|
+
type KeyHealthProvider = 'anthropic' | 'deepseek' | 'google' | 'moonshot' | 'openai';
|
|
77
77
|
interface KeyHealthConfig {
|
|
78
78
|
/** Consumer app id echoed as `app_id` in the response (e.g. 'playbacksam'). */
|
|
79
79
|
appId: string;
|