melchizedek-agents 0.18.0 → 0.19.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.
Files changed (281) hide show
  1. package/.env.example +12 -0
  2. package/CHANGELOG.md +825 -0
  3. package/DOCUMENTATION.md +217 -59
  4. package/README.md +42 -1
  5. package/config/agents/examples/harness.yaml +3 -1
  6. package/config/agents/examples/model_zoo.yaml +10 -9
  7. package/config/agents/syndicateSchema.yaml +50 -16
  8. package/config/agents/templates/account_memory.yaml +2 -6
  9. package/config/agents/templates/case_desk.yaml +3 -9
  10. package/config/agents/templates/draft_review.yaml +3 -9
  11. package/config/agents/templates/intake_extractor.yaml +1 -3
  12. package/config/agents/templates/research_brief.yaml +3 -9
  13. package/config/agents/templates/research_desk.yaml +3 -9
  14. package/config/agents/templates/review_panel.yaml +4 -12
  15. package/config/agents/templates/support_triage.yaml +4 -12
  16. package/config/agents/templates/systems_operator.yaml +2 -6
  17. package/db/hardening.sql +7 -1
  18. package/db/migrations/0013_tool_credentials.sql +260 -0
  19. package/dist/lib/a2a/app.d.ts +70 -6
  20. package/dist/lib/a2a/app.js +107 -2
  21. package/dist/lib/a2a/executor.d.ts +20 -3
  22. package/dist/lib/a2a/executor.js +66 -7
  23. package/dist/lib/a2a/remoteAgent.d.ts +24 -9
  24. package/dist/lib/a2a/remoteAgent.js +31 -14
  25. package/dist/lib/compile.d.ts +121 -30
  26. package/dist/lib/compile.js +137 -124
  27. package/dist/lib/compileAdk.d.ts +29 -0
  28. package/dist/lib/compileAdk.js +132 -0
  29. package/dist/lib/compileNative.d.ts +85 -0
  30. package/dist/lib/compileNative.js +222 -0
  31. package/dist/lib/config.d.ts +6 -5
  32. package/dist/lib/config.js +6 -5
  33. package/dist/lib/doctor.js +1 -0
  34. package/dist/lib/index.d.ts +2 -1
  35. package/dist/lib/index.js +2 -1
  36. package/dist/lib/loadSyndicate.d.ts +18 -0
  37. package/dist/lib/memory/erase.d.ts +5 -3
  38. package/dist/lib/memory/erase.js +5 -2
  39. package/dist/lib/memory/namespace.d.ts +8 -1
  40. package/dist/lib/memory/namespace.js +12 -6
  41. package/dist/lib/memory/providers.js +2 -1
  42. package/dist/lib/memory/supabaseMemoryService.d.ts +37 -3
  43. package/dist/lib/memory/supabaseMemoryService.js +42 -2
  44. package/dist/lib/model.d.ts +47 -0
  45. package/dist/lib/model.js +37 -0
  46. package/dist/lib/models/adapterResolver.d.ts +113 -0
  47. package/dist/lib/models/adapterResolver.js +136 -0
  48. package/dist/lib/models/adkGeminiAdapter.d.ts +90 -0
  49. package/dist/lib/models/adkGeminiAdapter.js +367 -0
  50. package/dist/lib/models/adkShim.d.ts +111 -0
  51. package/dist/lib/models/adkShim.js +136 -0
  52. package/dist/lib/models/capabilities.d.ts +3 -0
  53. package/dist/lib/models/capabilities.js +20 -13
  54. package/dist/lib/models/chatCompletionsAdapter.d.ts +279 -0
  55. package/dist/lib/models/chatCompletionsAdapter.js +854 -0
  56. package/dist/lib/models/circuitBreaker.d.ts +42 -0
  57. package/dist/lib/models/circuitBreaker.js +70 -0
  58. package/dist/lib/models/claudeAdapter.d.ts +103 -0
  59. package/dist/lib/models/claudeAdapter.js +669 -0
  60. package/dist/lib/models/claudeLlm.d.ts +39 -62
  61. package/dist/lib/models/claudeLlm.js +44 -349
  62. package/dist/lib/models/claudeModels.d.ts +127 -0
  63. package/dist/lib/models/claudeModels.js +237 -0
  64. package/dist/lib/models/contract.d.ts +395 -0
  65. package/dist/lib/models/contract.js +39 -0
  66. package/dist/lib/models/endpoints.js +2 -1
  67. package/dist/lib/models/errorResponse.d.ts +50 -0
  68. package/dist/lib/models/errorResponse.js +48 -0
  69. package/dist/lib/models/fallback.d.ts +17 -10
  70. package/dist/lib/models/fallback.js +53 -42
  71. package/dist/lib/models/fallbackAdapter.d.ts +55 -0
  72. package/dist/lib/models/fallbackAdapter.js +62 -0
  73. package/dist/lib/models/gateway.js +2 -1
  74. package/dist/lib/models/gatewayAdapter.d.ts +51 -0
  75. package/dist/lib/models/gatewayAdapter.js +81 -0
  76. package/dist/lib/models/gatewayLlm.d.ts +12 -33
  77. package/dist/lib/models/gatewayLlm.js +14 -75
  78. package/dist/lib/models/geminiAdapter.d.ts +123 -0
  79. package/dist/lib/models/geminiAdapter.js +831 -0
  80. package/dist/lib/models/geminiState.d.ts +25 -0
  81. package/dist/lib/models/geminiState.js +25 -0
  82. package/dist/lib/models/genaiMapping.d.ts +263 -0
  83. package/dist/lib/models/genaiMapping.js +862 -0
  84. package/dist/lib/models/gptAdapter.d.ts +240 -0
  85. package/dist/lib/models/gptAdapter.js +804 -0
  86. package/dist/lib/models/gptLlm.d.ts +63 -123
  87. package/dist/lib/models/gptLlm.js +88 -602
  88. package/dist/lib/models/grokAdapter.d.ts +86 -0
  89. package/dist/lib/models/grokAdapter.js +142 -0
  90. package/dist/lib/models/grokLlm.d.ts +22 -45
  91. package/dist/lib/models/grokLlm.js +22 -67
  92. package/dist/lib/models/kimiAdapter.d.ts +157 -0
  93. package/dist/lib/models/kimiAdapter.js +203 -0
  94. package/dist/lib/models/kimiLlm.d.ts +15 -107
  95. package/dist/lib/models/kimiLlm.js +17 -153
  96. package/dist/lib/models/ollamaAdapter.d.ts +125 -0
  97. package/dist/lib/models/ollamaAdapter.js +155 -0
  98. package/dist/lib/models/ollamaLlm.d.ts +11 -107
  99. package/dist/lib/models/ollamaLlm.js +13 -151
  100. package/dist/lib/models/openAiCompatibleLlm.d.ts +73 -216
  101. package/dist/lib/models/openAiCompatibleLlm.js +109 -671
  102. package/dist/lib/models/providerState.d.ts +63 -0
  103. package/dist/lib/models/providerState.js +61 -0
  104. package/dist/lib/models/reasoning.d.ts +26 -0
  105. package/dist/lib/models/reasoning.js +59 -0
  106. package/dist/lib/models/registry.d.ts +58 -35
  107. package/dist/lib/models/registry.js +89 -118
  108. package/dist/lib/models/retry.d.ts +2 -1
  109. package/dist/lib/models/retry.js +3 -2
  110. package/dist/lib/models/schemaNormalize.d.ts +98 -0
  111. package/dist/lib/models/schemaNormalize.js +321 -1
  112. package/dist/lib/models/tracedGemini.d.ts +41 -0
  113. package/dist/lib/models/tracedGemini.js +98 -0
  114. package/dist/lib/models/urls.d.ts +11 -0
  115. package/dist/lib/models/urls.js +16 -0
  116. package/dist/lib/net/redirects.d.ts +21 -2
  117. package/dist/lib/net/redirects.js +11 -34
  118. package/dist/lib/observability/audit.d.ts +5 -1
  119. package/dist/lib/observability/lineage.d.ts +14 -0
  120. package/dist/lib/observability/lineage.js +33 -0
  121. package/dist/lib/observability/supabaseSpanExporter.d.ts +10 -4
  122. package/dist/lib/observability/supabaseSpanExporter.js +17 -9
  123. package/dist/lib/observability/tracer.d.ts +26 -8
  124. package/dist/lib/observability/tracer.js +43 -18
  125. package/dist/lib/runtime/adkMemoryBridge.d.ts +46 -0
  126. package/dist/lib/runtime/adkMemoryBridge.js +68 -0
  127. package/dist/lib/runtime/adkSessionBridge.d.ts +78 -0
  128. package/dist/lib/runtime/adkSessionBridge.js +176 -0
  129. package/dist/lib/runtime/credentials.d.ts +59 -0
  130. package/dist/lib/runtime/credentials.js +62 -0
  131. package/dist/lib/runtime/events.d.ts +229 -0
  132. package/dist/lib/runtime/events.js +274 -0
  133. package/dist/lib/runtime/logging.d.ts +32 -0
  134. package/dist/lib/runtime/logging.js +55 -0
  135. package/dist/lib/runtime/memoryService.d.ts +72 -0
  136. package/dist/lib/runtime/memoryService.js +25 -0
  137. package/dist/lib/runtime/native/agentLoop.d.ts +203 -0
  138. package/dist/lib/runtime/native/agentLoop.js +687 -0
  139. package/dist/lib/runtime/native/compaction.d.ts +103 -0
  140. package/dist/lib/runtime/native/compaction.js +191 -0
  141. package/dist/lib/runtime/native/delegate.d.ts +98 -0
  142. package/dist/lib/runtime/native/delegate.js +173 -0
  143. package/dist/lib/runtime/native/history.d.ts +83 -0
  144. package/dist/lib/runtime/native/history.js +312 -0
  145. package/dist/lib/runtime/native/interrupts.d.ts +126 -0
  146. package/dist/lib/runtime/native/interrupts.js +291 -0
  147. package/dist/lib/runtime/native/request.d.ts +215 -0
  148. package/dist/lib/runtime/native/request.js +585 -0
  149. package/dist/lib/runtime/native/selfCorrection.d.ts +106 -0
  150. package/dist/lib/runtime/native/selfCorrection.js +253 -0
  151. package/dist/lib/runtime/native/step.d.ts +148 -0
  152. package/dist/lib/runtime/native/step.js +239 -0
  153. package/dist/lib/runtime/native/taskMode.d.ts +64 -0
  154. package/dist/lib/runtime/native/taskMode.js +126 -0
  155. package/dist/lib/runtime/native/telemetry.d.ts +75 -0
  156. package/dist/lib/runtime/native/telemetry.js +299 -0
  157. package/dist/lib/runtime/native/tempState.d.ts +31 -0
  158. package/dist/lib/runtime/native/tempState.js +56 -0
  159. package/dist/lib/runtime/nativeTurn.d.ts +86 -0
  160. package/dist/lib/runtime/nativeTurn.js +107 -0
  161. package/dist/lib/runtime/questions.d.ts +29 -7
  162. package/dist/lib/runtime/questions.js +47 -32
  163. package/dist/lib/runtime/runtimeFlag.d.ts +30 -0
  164. package/dist/lib/runtime/runtimeFlag.js +50 -0
  165. package/dist/lib/runtime/sessions.d.ts +166 -0
  166. package/dist/lib/runtime/sessions.js +201 -0
  167. package/dist/lib/runtime/syndicateTurn.d.ts +41 -5
  168. package/dist/lib/runtime/syndicateTurn.js +202 -32
  169. package/dist/lib/session/supabaseSessionService.d.ts +64 -17
  170. package/dist/lib/session/supabaseSessionService.js +148 -105
  171. package/dist/lib/session/transcript.d.ts +68 -22
  172. package/dist/lib/session/transcript.js +102 -28
  173. package/dist/lib/skills.js +33 -7
  174. package/dist/lib/storage/postgres/credentialStore.d.ts +20 -0
  175. package/dist/lib/storage/postgres/credentialStore.js +82 -0
  176. package/dist/lib/storage/postgres/index.d.ts +12 -0
  177. package/dist/lib/storage/postgres/index.js +6 -1
  178. package/dist/lib/storage/postgres/sessionService.d.ts +43 -15
  179. package/dist/lib/storage/postgres/sessionService.js +128 -66
  180. package/dist/lib/syndicateSchema.d.ts +47 -0
  181. package/dist/lib/syndicateSchema.js +72 -3
  182. package/dist/lib/toolRegistry.d.ts +15 -2
  183. package/dist/lib/toolRegistry.js +33 -17
  184. package/dist/lib/tools/adkTool.d.ts +81 -0
  185. package/dist/lib/tools/adkTool.js +268 -0
  186. package/dist/lib/tools/auth.d.ts +118 -0
  187. package/dist/lib/tools/auth.js +89 -0
  188. package/dist/lib/tools/collectionsSearchTool.d.ts +7 -6
  189. package/dist/lib/tools/collectionsSearchTool.js +11 -26
  190. package/dist/lib/tools/credentialCipher.d.ts +58 -0
  191. package/dist/lib/tools/credentialCipher.js +116 -0
  192. package/dist/lib/tools/credentialStore.d.ts +77 -0
  193. package/dist/lib/tools/credentialStore.js +246 -0
  194. package/dist/lib/tools/examples.d.ts +43 -0
  195. package/dist/lib/tools/examples.js +62 -0
  196. package/dist/lib/tools/generateImageTool.d.ts +15 -6
  197. package/dist/lib/tools/generateImageTool.js +19 -29
  198. package/dist/lib/tools/inspectImageTool.d.ts +9 -6
  199. package/dist/lib/tools/inspectImageTool.js +13 -17
  200. package/dist/lib/tools/mcpToolFactory.d.ts +42 -1
  201. package/dist/lib/tools/mcpToolFactory.js +46 -47
  202. package/dist/lib/tools/memoryTools.d.ts +61 -0
  203. package/dist/lib/tools/memoryTools.js +119 -0
  204. package/dist/lib/tools/nativeTools.d.ts +38 -0
  205. package/dist/lib/tools/nativeTools.js +43 -0
  206. package/dist/lib/tools/oauthConsent.d.ts +181 -0
  207. package/dist/lib/tools/oauthConsent.js +330 -0
  208. package/dist/lib/tools/openapi/call.d.ts +108 -0
  209. package/dist/lib/tools/openapi/call.js +295 -0
  210. package/dist/lib/tools/openapi/parse.d.ts +147 -0
  211. package/dist/lib/tools/openapi/parse.js +570 -0
  212. package/dist/lib/tools/openapiTools.d.ts +25 -17
  213. package/dist/lib/tools/openapiTools.js +124 -121
  214. package/dist/lib/tools/scienceTools.d.ts +14 -14
  215. package/dist/lib/tools/skillToolset.d.ts +58 -87
  216. package/dist/lib/tools/skillToolset.js +61 -142
  217. package/dist/lib/tools/skills/env.d.ts +58 -0
  218. package/dist/lib/tools/skills/env.js +165 -0
  219. package/dist/lib/tools/skills/executor.d.ts +114 -0
  220. package/dist/lib/tools/skills/executor.js +331 -0
  221. package/dist/lib/tools/skills/frontmatter.d.ts +79 -0
  222. package/dist/lib/tools/skills/frontmatter.js +215 -0
  223. package/dist/lib/tools/skills/loader.d.ts +91 -0
  224. package/dist/lib/tools/skills/loader.js +257 -0
  225. package/dist/lib/tools/skills/tools.d.ts +187 -0
  226. package/dist/lib/tools/skills/tools.js +386 -0
  227. package/dist/lib/tools/taskTools.d.ts +15 -15
  228. package/dist/lib/tools/tool.d.ts +354 -0
  229. package/dist/lib/tools/tool.js +304 -0
  230. package/dist/lib/tools/toolContract.d.ts +89 -33
  231. package/dist/lib/tools/toolContract.js +104 -82
  232. package/dist/lib/tools/urlContextTool.d.ts +3 -0
  233. package/dist/lib/tools/urlContextTool.js +5 -1
  234. package/dist/lib/tools/webExtractTool.d.ts +2 -2
  235. package/dist/lib/tools/webExtractTool.js +2 -1
  236. package/dist/lib/tools/webSearchTool.d.ts +6 -9
  237. package/dist/lib/tools/webSearchTool.js +14 -59
  238. package/dist/lib/tools/wikiTools.d.ts +19 -19
  239. package/dist/lib/tools/wikiTools.js +13 -9
  240. package/dist/lib/tools/xApiSearchTool.d.ts +2 -2
  241. package/dist/lib/tools/xApiSearchTool.js +2 -1
  242. package/dist/lib/tools/xSearchTool.d.ts +7 -9
  243. package/dist/lib/tools/xSearchTool.js +11 -62
  244. package/dist/lib/tools/xaiSearchParams.d.ts +41 -0
  245. package/dist/lib/tools/xaiSearchParams.js +126 -0
  246. package/dist/lib/wiki/agentRun.d.ts +12 -0
  247. package/dist/lib/wiki/agentRun.js +72 -34
  248. package/dist/lib/wiki/entities.d.ts +12 -0
  249. package/dist/lib/wiki/entities.js +45 -3
  250. package/dist/lib/workflow/agentNode.d.ts +136 -0
  251. package/dist/lib/workflow/agentNode.js +274 -0
  252. package/dist/lib/workflow/graph.d.ts +177 -0
  253. package/dist/lib/workflow/graph.js +458 -0
  254. package/dist/lib/workflow/nodeEvents.d.ts +50 -0
  255. package/dist/lib/workflow/nodeEvents.js +101 -0
  256. package/dist/lib/workflow/pause.d.ts +122 -0
  257. package/dist/lib/workflow/pause.js +180 -0
  258. package/dist/lib/workflow/resume.d.ts +165 -0
  259. package/dist/lib/workflow/resume.js +440 -0
  260. package/dist/lib/workflow/route.d.ts +58 -0
  261. package/dist/lib/workflow/route.js +69 -0
  262. package/dist/lib/workflow/scheduler.d.ts +415 -0
  263. package/dist/lib/workflow/scheduler.js +743 -0
  264. package/dist/lib/workflow/toolNode.d.ts +127 -0
  265. package/dist/lib/workflow/toolNode.js +236 -0
  266. package/dist/lib/workflow/turn.d.ts +118 -0
  267. package/dist/lib/workflow/turn.js +216 -0
  268. package/dist/lib/workflowConfig.d.ts +3 -2
  269. package/dist/lib/workflowConfig.js +3 -12
  270. package/dist/scripts/a2a_server.js +4 -3
  271. package/dist/scripts/assistant_worker.d.ts +2 -1
  272. package/dist/scripts/assistant_worker.js +9 -4
  273. package/dist/scripts/syndicate_chat.js +19 -10
  274. package/package.json +4 -1
  275. package/skills/briefs/melchizedek-author.md +3 -2
  276. package/skills/briefs/melchizedek-models.md +13 -9
  277. package/skills/briefs/melchizedek.md +3 -3
  278. package/skills/melchizedek/SKILL.md +2 -1
  279. package/skills/melchizedek-author/SKILL.md +2 -1
  280. package/skills/melchizedek-author/assets/minimal.yaml +2 -0
  281. package/skills/melchizedek-models/SKILL.md +23 -6
@@ -0,0 +1,203 @@
1
+ /**
2
+ * lib/models/kimiAdapter.ts — Moonshot AI (Kimi) behind the engine's own
3
+ * model contract (lib/models/contract.ts, ADR 0048).
4
+ *
5
+ * WHY this file exists:
6
+ * Model optionality is a primary driver of this framework: the agent YAML
7
+ * declares `model`, and the registry routes it to the right provider.
8
+ * Kimi K3 (July 2026) is the strongest open-weight model on the public
9
+ * coding and research boards, and Moonshot serves it first-party with
10
+ * tool calling, strict structured output and vision, so it earns a
11
+ * direct adapter rather than only the gateway path. Under ADK it runs
12
+ * behind KimiLlm (lib/models/kimiLlm.ts), which any `kimi-*` id routes to.
13
+ *
14
+ * WHY the chat-completions base (lib/models/chatCompletionsAdapter.ts):
15
+ * Moonshot's API is OpenAI Chat Completions at https://api.moonshot.ai/v1
16
+ * (it also serves Responses on the same base and Anthropic Messages at
17
+ * /anthropic; neither adds a capability the chat dialect lacks here).
18
+ * The base provides tool calling, strict `json_schema` structured output
19
+ * (Moonshot documents `strict: true`), SSE streaming with usage, image
20
+ * parts as base64 data URIs (Moonshot rejects public image URLs, so a URL
21
+ * blob is never sent), `reasoning_content` surfaced as thinking, and
22
+ * retries.
23
+ *
24
+ * HOW TO ENABLE:
25
+ * 1. Create a key at https://platform.moonshot.ai (international; the
26
+ * .cn console serves mainland China) and put it in .env as
27
+ * MOONSHOT_API_KEY.
28
+ * 2. Set model: "kimi-k3" (or any kimi-* id) in your YAML.
29
+ * registerAvailableProviders() registers this adapter when the key is set.
30
+ * Optional: MOONSHOT_BASE_URL for a proxy that speaks the same dialect.
31
+ *
32
+ * THE FAMILY (platform.moonshot.ai › Model list, October 2026; USD per 1M tokens):
33
+ *
34
+ * model context in / cache hit / out use it for
35
+ * ──────────────────────────────────────────────────────────────────────
36
+ * kimi-k3 1M $3.00 / $0.30 / $15 DEFAULT — the flagship: 2.8T MoE, vision,
37
+ * always-on thinking, effort low|high|max
38
+ * kimi-k2.6 256K $0.95 / $0.16 / $4 the cheaper general tier: vision, thinking
39
+ * switchable; fragile on complex schemas
40
+ * kimi-k2.7-code 256K $0.95 / $0.19 / $4 coding; thinking cannot be turned off
41
+ * kimi-k2.7-code-highspeed 256K $1.90 / $0.38 / $8 the same model at ~180 tokens/s
42
+ *
43
+ * CHOOSING A MODEL (cost is a design property; see the model-routing skill):
44
+ * K3 is priced like a mid-tier closed model, not like an open-weight
45
+ * bargain: $3 / $15 is Claude Sonnet 4.6's price, and Claude Sonnet 5.5
46
+ * ($2 / $10, cache reads $0.20) undercuts it on every token while sitting
47
+ * above it on the coding boards. Two things make K3 dearer than its list
48
+ * price: thinking is always on and billed as output, and Moonshot's
49
+ * default effort is max — hence the pinned DEFAULT_KIMI_REASONING_EFFORT
50
+ * and the zoo agent at "low". What K3 buys is the strongest open-weight
51
+ * model (a self-host option) and a 1M context at a flat rate. For cost,
52
+ * reach for kimi-k2.6 (a quarter of K3's price, vision and tools) on
53
+ * subagent and bulk work, or serve K3 through the gateway: OpenRouter's
54
+ * endpoints range from about $0.88 to $3.45 per 1M input, the cheap ones
55
+ * quantized, with fidelity as the trade.
56
+ *
57
+ * There is no small or "flash" K3; K2.6 is the light tier. K3's weights
58
+ * are open (moonshotai/Kimi-K3 on Hugging Face), so the id is also served
59
+ * by OpenRouter, Together, Fireworks, Vercel AI Gateway and others; with
60
+ * no direct key, MODEL_GATEWAY serves it as `moonshotai/kimi-k3`
61
+ * (lib/models/gateway.ts). kimi-k2.5 and the moonshot-v1 ids were retired
62
+ * on 2026-08-31 and are not routed here on purpose.
63
+ *
64
+ * REASONING (ADR 0047):
65
+ * K3 always thinks; the lever is the top-level `reasoning_effort`
66
+ * (low | high | max, Moonshot's default max). A request's `reasoning`
67
+ * goes as its Kimi word (`medium` → `high`, a budget → the level that
68
+ * covers it), `none` as `low` since K3 cannot switch thinking off, and a
69
+ * request with none pins DEFAULT_KIMI_REASONING_EFFORT (lib/config.ts).
70
+ * `max` has no contract level: an agent that needs it writes the older
71
+ * spelling `generateContentConfig.reasoningEffort: max`, which the ADK
72
+ * path carries beside the contract (ChatCompletionsRequest.olderSpelling).
73
+ * K2.x models take no reasoning_effort: a `thinking: { type }` switch
74
+ * instead, so `none` (or a budget of 0) sends `disabled` and any other
75
+ * setting sends nothing. K2.7 Code (and its highspeed variant) cannot
76
+ * switch thinking off and Moonshot refuses `disabled` for it, so there
77
+ * `none` sends nothing either: the model thinks at its default.
78
+ *
79
+ * TOOL CHOICE (toolChoiceModes; checked live against Moonshot on
80
+ * 2026-10-08, PR #87): auto and none always (none by sending no tools).
81
+ * The forced modes depend on the model and on whether it thinks:
82
+ * kimi-k3 `required` is honoured with thinking on, so it goes as
83
+ * asked; a named tool is refused with thinking on (400
84
+ * "tool_choice 'specified' is incompatible with thinking
85
+ * enabled") and K3 always thinks, so it goes as `required`.
86
+ * kimi-k2.6 both forced modes are refused with thinking on and
87
+ * honoured with it off, so they go as asked only when the
88
+ * request's reasoning is `none` (or a budget of 0), which
89
+ * sends `thinking: disabled`; otherwise auto.
90
+ * others (K2.7 Code) unverified: weakened to auto.
91
+ * A weakened choice is marked on the span (llm.tool_choice.weakened).
92
+ *
93
+ * LIMITATIONS:
94
+ * - web_search: Moonshot's model-side `$web_search` built-in retires on
95
+ * 2026-10-20 and its replacement is a separate REST API
96
+ * (POST /v1/tools/search, billed per call), not a tool the model
97
+ * enables in the request. The tool is therefore dropped with a
98
+ * warning, like on Ollama; `web_extract` works, and `MOONSHOT_API_KEY`
99
+ * would fund a client-side search tool over that REST API if one is
100
+ * added (lib/tools/).
101
+ * - Thinking with tools: Moonshot's thinking-model guide (October 2026)
102
+ * asks for every id above that an assistant message's
103
+ * `reasoning_content` be sent back on the next request of a tool loop
104
+ * ("required" on K3). This adapter turns on the base's
105
+ * replaysReasoningContent for those ids (wantsReasoningReplay), so the
106
+ * field rides as providerState on the part that followed it and goes
107
+ * back on that message within the turn's tool loop, for the same model
108
+ * only (ADR 0046). Earlier turns' reasoning is not sent: K3 and
109
+ * K2.7 Code also ask for it across turns ("preserved thinking"), and
110
+ * the stored history of a past turn is not what the model saw. The
111
+ * replayed text is billed again as input on every later step of the
112
+ * loop, mostly at the cache-hit price, since the prefix is unchanged.
113
+ * - Every cell of its capability row is asserted against the request body
114
+ * the adapter sends (tests/capabilityMatrix.test.ts), as for every other
115
+ * provider. Verified live on 2026-10-03 through `npm run demo:models`:
116
+ * kimi-k3 at low effort answered the zoo's explainer prompt in 17.9 s,
117
+ * 440 tokens in, 486 out, 262 of them thinking, the scratchpad surfaced
118
+ * from reasoning_content; tool loops and search were not exercised.
119
+ */
120
+ import { DEFAULT_KIMI_REASONING_EFFORT } from '../config.js';
121
+ import { ChatCompletionsAdapter, reasonsNotAtAll } from './chatCompletionsAdapter.js';
122
+ import { reasoningConfig } from './reasoning.js';
123
+ import { trimTrailingSlashes } from './urls.js';
124
+ export const MOONSHOT_BASE_URL = 'https://api.moonshot.ai/v1';
125
+ /** The flagship takes `reasoning_effort`; the K2 generation takes a `thinking` switch. */
126
+ export function isKimiK3(model) {
127
+ return /^kimi-k3\b/.test(model);
128
+ }
129
+ /** K2.6: thinking is on by default and switchable, and forcing a tool needs it off. */
130
+ export function isKimiK26(model) {
131
+ return /^kimi-k2\.6\b/.test(model);
132
+ }
133
+ /** K2.7 Code and its highspeed variant: thinking cannot be switched off, and `disabled` is refused. */
134
+ export function isKimiK27Code(model) {
135
+ return /^kimi-k2\.7-code\b/.test(model);
136
+ }
137
+ /**
138
+ * The ids Moonshot documents as wanting `reasoning_content` back on a tool
139
+ * loop: K3, K2.6 and K2.7 Code (with its highspeed variant).
140
+ */
141
+ export function wantsReasoningReplay(model) {
142
+ return isKimiK3(model) || /^kimi-k2\.(6|7-code)\b/.test(model);
143
+ }
144
+ export class KimiAdapter extends ChatCompletionsAdapter {
145
+ provider = 'moonshot';
146
+ #apiKey;
147
+ #baseUrl;
148
+ constructor({ model, apiKey, baseUrl }) {
149
+ super({ model });
150
+ this.#apiKey = apiKey;
151
+ this.#baseUrl = trimTrailingSlashes(baseUrl || process.env.MOONSHOT_BASE_URL || MOONSHOT_BASE_URL);
152
+ }
153
+ endpointUrl() {
154
+ return `${this.#baseUrl}/chat/completions`;
155
+ }
156
+ #key() {
157
+ return this.#apiKey ?? process.env.MOONSHOT_API_KEY;
158
+ }
159
+ headers() {
160
+ return { Authorization: `Bearer ${this.#key() ?? ''}` };
161
+ }
162
+ /** The forced tool choices each model honours, per the live checks in the header. */
163
+ toolChoiceModes(model, reasoning) {
164
+ if (isKimiK3(model))
165
+ return ['auto', 'none', 'required'];
166
+ if (isKimiK26(model) && reasonsNotAtAll(reasoning))
167
+ return ['auto', 'none', 'required', 'named'];
168
+ return ['auto', 'none'];
169
+ }
170
+ /** reasoning_content goes back on the tool loop for the ids that ask for it (see the header). */
171
+ replaysReasoningContent(model) {
172
+ return wantsReasoningReplay(model);
173
+ }
174
+ missingRequirement() {
175
+ if (this.#key())
176
+ return undefined;
177
+ return { code: 'MOONSHOT_MISSING_KEY', message: 'MOONSHOT_API_KEY is not set in environment.' };
178
+ }
179
+ httpError(status, detail, model) {
180
+ const hint = status === 401
181
+ ? ' Check MOONSHOT_API_KEY (platform.moonshot.ai).'
182
+ : status === 404
183
+ ? ` Is "${model}" a current Kimi id? kimi-k2.5 and moonshot-v1-* were retired on 2026-08-31.`
184
+ : '';
185
+ return {
186
+ code: 'MOONSHOT_HTTP_ERROR',
187
+ message: `Moonshot returned ${status}: ${detail.slice(0, 4000)}.${hint}`,
188
+ };
189
+ }
190
+ /** The reasoning controls, per generation (see the header). */
191
+ reasoningFields(model, setting, olderWord) {
192
+ if (isKimiK3(model)) {
193
+ if (olderWord !== undefined)
194
+ return { reasoning_effort: olderWord };
195
+ if (setting === undefined)
196
+ return { reasoning_effort: DEFAULT_KIMI_REASONING_EFFORT };
197
+ const word = reasoningConfig(model, setting).reasoningEffort;
198
+ return { reasoning_effort: word === 'none' ? 'low' : word }; // K3 cannot switch thinking off
199
+ }
200
+ // K2.7 Code always thinks, and Moonshot refuses `disabled` for it.
201
+ return reasonsNotAtAll(setting) && !isKimiK27Code(model) ? { thinking: { type: 'disabled' } } : {};
202
+ }
203
+ }
@@ -1,123 +1,31 @@
1
1
  /**
2
- * lib/models/kimiLlm.ts — Moonshot AI (Kimi) provider for the ADK LLMRegistry.
2
+ * lib/models/kimiLlm.ts — Moonshot AI (Kimi), as an ADK BaseLlm for the
3
+ * LLMRegistry.
3
4
  *
4
5
  * WHY this file exists:
5
- * Model optionality is a primary driver of this framework: the agent YAML
6
- * declares `model`, and the registry routes it to the right provider.
7
- * Kimi K3 (July 2026) is the strongest open-weight model on the public
8
- * coding and research boards, and Moonshot serves it first-party with
9
- * tool calling, strict structured output and vision, so it earns a
10
- * direct adapter rather than only the gateway path.
11
- *
12
- * WHY it subclasses the chat-completions base (lib/models/openAiCompatibleLlm.ts):
13
- * Moonshot's API is OpenAI Chat Completions at https://api.moonshot.ai/v1
14
- * (it also serves Responses on the same base and Anthropic Messages at
15
- * /anthropic; neither adds a capability the chat dialect lacks here).
16
- * The base provides tool calling, strict `json_schema` structured output
17
- * (Moonshot documents `strict: true`), SSE streaming with usage, image
18
- * parts as base64 data URIs (Moonshot rejects public image URLs, which is
19
- * what the base never sends), `reasoning_content` surfaced as THINKING
20
- * output, retries, and the llm.request span.
21
- *
22
- * HOW TO ENABLE:
23
- * 1. Create a key at https://platform.moonshot.ai (international; the
24
- * .cn console serves mainland China) and put it in .env as
25
- * MOONSHOT_API_KEY.
26
- * 2. Set model: "kimi-k3" (or any kimi-* id) in your YAML.
27
- * registerAvailableProviders() registers this adapter when the key is set.
28
- * Optional: MOONSHOT_BASE_URL for a proxy that speaks the same dialect.
29
- *
30
- * THE FAMILY (platform.moonshot.ai › Model list, October 2026; USD per 1M tokens):
31
- *
32
- * model context in / cache hit / out use it for
33
- * ──────────────────────────────────────────────────────────────────────
34
- * kimi-k3 1M $3.00 / $0.30 / $15 DEFAULT — the flagship: 2.8T MoE, vision,
35
- * always-on thinking, effort low|high|max
36
- * kimi-k2.6 256K $0.95 / $0.16 / $4 the cheaper general tier: vision, thinking
37
- * switchable; fragile on complex schemas
38
- * kimi-k2.7-code 256K $0.95 / $0.19 / $4 coding; thinking cannot be turned off
39
- * kimi-k2.7-code-highspeed 256K $1.90 / $0.38 / $8 the same model at ~180 tokens/s
40
- *
41
- * CHOOSING A MODEL (cost is a design property; see the model-routing skill):
42
- * K3 is priced like a mid-tier closed model, not like an open-weight
43
- * bargain: $3 / $15 is Claude Sonnet 4.6's price, and Claude Sonnet 5.5
44
- * ($2 / $10, cache reads $0.20) undercuts it on every token while sitting
45
- * above it on the coding boards. Two things make K3 dearer than its list
46
- * price: thinking is always on and billed as output, and Moonshot's
47
- * default effort is max — hence the pinned DEFAULT_KIMI_REASONING_EFFORT
48
- * and the zoo agent at "low". What K3 buys is the strongest open-weight
49
- * model (a self-host option) and a 1M context at a flat rate. For cost,
50
- * reach for kimi-k2.6 (a quarter of K3's price, vision and tools) on
51
- * subagent and bulk work, or serve K3 through the gateway: OpenRouter's
52
- * endpoints range from about $0.88 to $3.45 per 1M input, the cheap ones
53
- * quantized, with fidelity as the trade.
54
- *
55
- * There is no small or "flash" K3; K2.6 is the light tier. K3's weights
56
- * are open (moonshotai/Kimi-K3 on Hugging Face), so the id is also served
57
- * by OpenRouter, Together, Fireworks, Vercel AI Gateway and others; with
58
- * no direct key, MODEL_GATEWAY serves it as `moonshotai/kimi-k3`
59
- * (lib/models/gateway.ts). kimi-k2.5 and the moonshot-v1 ids were retired
60
- * on 2026-08-31 and are not routed here on purpose.
61
- *
62
- * REASONING:
63
- * K3 always thinks; the lever is the top-level `reasoning_effort`
64
- * (low | high | max, Moonshot's default max). Requests pin
65
- * DEFAULT_KIMI_REASONING_EFFORT (lib/config.ts) unless the agent sets
66
- * generateContentConfig.reasoningEffort; "none" is mapped to "low" on
67
- * K3, which cannot switch thinking off. K2.x models take no
68
- * reasoning_effort: a `thinking: { type }` switch instead, so on those
69
- * ids reasoningEffort "none" or thinkingBudget 0 sends `disabled` and
70
- * any effort value is dropped from the body (K2.7 Code rejects
71
- * disabled thinking; Moonshot's own error says so).
72
- *
73
- * LIMITATIONS:
74
- * - web_search: Moonshot's model-side `$web_search` built-in retires on
75
- * 2026-10-20 and its replacement is a separate REST API
76
- * (POST /v1/tools/search, billed per call), not a tool the model
77
- * enables in the request. The sentinel is therefore dropped with a
78
- * warning, like on Ollama; `web_extract` works, and `MOONSHOT_API_KEY`
79
- * would fund a client-side search tool over that REST API if one is
80
- * added (lib/tools/).
81
- * - Thinking with tools: Moonshot asks that K3's `reasoning_content` be
82
- * passed back with the assistant message on a tool loop. This base
83
- * keeps scratchpads out of history, so K3 re-reasons each step
84
- * (degraded, stated in lib/models/capabilities.ts); if Moonshot ever
85
- * enforces it, the turn ends with MOONSHOT_HTTP_ERROR naming the field.
86
- * - Every cell of its capability row is asserted against the request body
87
- * the adapter sends (tests/capabilityMatrix.test.ts), as for every other
88
- * provider. Verified live on 2026-10-03 through `npm run demo:models`:
89
- * kimi-k3 at low effort answered the zoo's explainer prompt in 17.9 s,
90
- * 440 tokens in, 486 out, 262 of them thinking, the scratchpad surfaced
91
- * from reasoning_content; tool loops and search were not exercised.
6
+ * The provider's work is KimiAdapter (lib/models/kimiAdapter.ts), on the
7
+ * engine's own model contract; its header covers the family, cost, the
8
+ * reasoning controls per generation, and reasoning_content on tool loops
9
+ * (ADR 0046). ADK still runs every turn, so this class runs the adapter
10
+ * under ADK: it is the chat-completions shim
11
+ * (lib/models/openAiCompatibleLlm.ts, ADR 0057), registered for any
12
+ * `kimi-*` id when MOONSHOT_API_KEY is set. The constructor and
13
+ * supportedModels are what they were before the adapter moved onto the
14
+ * contract, so lib/models/registry.ts and every caller are unchanged. On
15
+ * this path an agent's older spelling `reasoningEffort: max` still reaches
16
+ * K3, which the contract has no level for.
92
17
  */
93
- import type { LlmRequest, LlmResponse } from '@google/adk';
94
18
  import { OpenAiCompatibleLlm } from './openAiCompatibleLlm.ts';
95
- export declare const MOONSHOT_BASE_URL = "https://api.moonshot.ai/v1";
96
- /** The flagship takes `reasoning_effort`; the K2 generation takes a `thinking` switch. */
97
- export declare function isKimiK3(model: string): boolean;
19
+ export { MOONSHOT_BASE_URL, isKimiK3, wantsReasoningReplay } from './kimiAdapter.ts';
98
20
  export declare class KimiLlm extends OpenAiCompatibleLlm {
99
21
  /** Any model: "kimi-*" in a YAML config routes here after registration. */
100
22
  static readonly supportedModels: Array<string | RegExp>;
101
- private readonly apiKey?;
102
- private readonly baseUrl;
23
+ /** `apiKey` defaults to MOONSHOT_API_KEY; `baseUrl` to MOONSHOT_BASE_URL, else https://api.moonshot.ai/v1. */
103
24
  constructor({ model, apiKey, baseUrl }: {
104
25
  model: string;
105
26
  apiKey?: string;
106
27
  baseUrl?: string;
107
28
  });
108
- protected providerId(): string;
109
- protected endpointUrl(): string;
110
- private key;
111
- protected headers(): Record<string, string>;
112
- protected missingRequirement(): LlmResponse | undefined;
113
- protected httpError(status: number, detail: string): LlmResponse;
114
- /**
115
- * The reasoning controls, per generation (see the header). The base has
116
- * already put `reasoning_effort` in the body when the agent set one;
117
- * these fields are merged after it, so an `undefined` here removes it
118
- * (JSON.stringify drops undefined keys).
119
- */
120
- protected extraBodyFields(llmRequest: LlmRequest): Record<string, unknown>;
121
29
  }
122
30
  /** Registers KimiLlm with the ADK LLMRegistry (called when MOONSHOT_API_KEY is set). */
123
31
  export declare function registerKimiLlm(): void;
@@ -1,167 +1,31 @@
1
1
  /**
2
- * lib/models/kimiLlm.ts — Moonshot AI (Kimi) provider for the ADK LLMRegistry.
2
+ * lib/models/kimiLlm.ts — Moonshot AI (Kimi), as an ADK BaseLlm for the
3
+ * LLMRegistry.
3
4
  *
4
5
  * WHY this file exists:
5
- * Model optionality is a primary driver of this framework: the agent YAML
6
- * declares `model`, and the registry routes it to the right provider.
7
- * Kimi K3 (July 2026) is the strongest open-weight model on the public
8
- * coding and research boards, and Moonshot serves it first-party with
9
- * tool calling, strict structured output and vision, so it earns a
10
- * direct adapter rather than only the gateway path.
11
- *
12
- * WHY it subclasses the chat-completions base (lib/models/openAiCompatibleLlm.ts):
13
- * Moonshot's API is OpenAI Chat Completions at https://api.moonshot.ai/v1
14
- * (it also serves Responses on the same base and Anthropic Messages at
15
- * /anthropic; neither adds a capability the chat dialect lacks here).
16
- * The base provides tool calling, strict `json_schema` structured output
17
- * (Moonshot documents `strict: true`), SSE streaming with usage, image
18
- * parts as base64 data URIs (Moonshot rejects public image URLs, which is
19
- * what the base never sends), `reasoning_content` surfaced as THINKING
20
- * output, retries, and the llm.request span.
21
- *
22
- * HOW TO ENABLE:
23
- * 1. Create a key at https://platform.moonshot.ai (international; the
24
- * .cn console serves mainland China) and put it in .env as
25
- * MOONSHOT_API_KEY.
26
- * 2. Set model: "kimi-k3" (or any kimi-* id) in your YAML.
27
- * registerAvailableProviders() registers this adapter when the key is set.
28
- * Optional: MOONSHOT_BASE_URL for a proxy that speaks the same dialect.
29
- *
30
- * THE FAMILY (platform.moonshot.ai › Model list, October 2026; USD per 1M tokens):
31
- *
32
- * model context in / cache hit / out use it for
33
- * ──────────────────────────────────────────────────────────────────────
34
- * kimi-k3 1M $3.00 / $0.30 / $15 DEFAULT — the flagship: 2.8T MoE, vision,
35
- * always-on thinking, effort low|high|max
36
- * kimi-k2.6 256K $0.95 / $0.16 / $4 the cheaper general tier: vision, thinking
37
- * switchable; fragile on complex schemas
38
- * kimi-k2.7-code 256K $0.95 / $0.19 / $4 coding; thinking cannot be turned off
39
- * kimi-k2.7-code-highspeed 256K $1.90 / $0.38 / $8 the same model at ~180 tokens/s
40
- *
41
- * CHOOSING A MODEL (cost is a design property; see the model-routing skill):
42
- * K3 is priced like a mid-tier closed model, not like an open-weight
43
- * bargain: $3 / $15 is Claude Sonnet 4.6's price, and Claude Sonnet 5.5
44
- * ($2 / $10, cache reads $0.20) undercuts it on every token while sitting
45
- * above it on the coding boards. Two things make K3 dearer than its list
46
- * price: thinking is always on and billed as output, and Moonshot's
47
- * default effort is max — hence the pinned DEFAULT_KIMI_REASONING_EFFORT
48
- * and the zoo agent at "low". What K3 buys is the strongest open-weight
49
- * model (a self-host option) and a 1M context at a flat rate. For cost,
50
- * reach for kimi-k2.6 (a quarter of K3's price, vision and tools) on
51
- * subagent and bulk work, or serve K3 through the gateway: OpenRouter's
52
- * endpoints range from about $0.88 to $3.45 per 1M input, the cheap ones
53
- * quantized, with fidelity as the trade.
54
- *
55
- * There is no small or "flash" K3; K2.6 is the light tier. K3's weights
56
- * are open (moonshotai/Kimi-K3 on Hugging Face), so the id is also served
57
- * by OpenRouter, Together, Fireworks, Vercel AI Gateway and others; with
58
- * no direct key, MODEL_GATEWAY serves it as `moonshotai/kimi-k3`
59
- * (lib/models/gateway.ts). kimi-k2.5 and the moonshot-v1 ids were retired
60
- * on 2026-08-31 and are not routed here on purpose.
61
- *
62
- * REASONING:
63
- * K3 always thinks; the lever is the top-level `reasoning_effort`
64
- * (low | high | max, Moonshot's default max). Requests pin
65
- * DEFAULT_KIMI_REASONING_EFFORT (lib/config.ts) unless the agent sets
66
- * generateContentConfig.reasoningEffort; "none" is mapped to "low" on
67
- * K3, which cannot switch thinking off. K2.x models take no
68
- * reasoning_effort: a `thinking: { type }` switch instead, so on those
69
- * ids reasoningEffort "none" or thinkingBudget 0 sends `disabled` and
70
- * any effort value is dropped from the body (K2.7 Code rejects
71
- * disabled thinking; Moonshot's own error says so).
72
- *
73
- * LIMITATIONS:
74
- * - web_search: Moonshot's model-side `$web_search` built-in retires on
75
- * 2026-10-20 and its replacement is a separate REST API
76
- * (POST /v1/tools/search, billed per call), not a tool the model
77
- * enables in the request. The sentinel is therefore dropped with a
78
- * warning, like on Ollama; `web_extract` works, and `MOONSHOT_API_KEY`
79
- * would fund a client-side search tool over that REST API if one is
80
- * added (lib/tools/).
81
- * - Thinking with tools: Moonshot asks that K3's `reasoning_content` be
82
- * passed back with the assistant message on a tool loop. This base
83
- * keeps scratchpads out of history, so K3 re-reasons each step
84
- * (degraded, stated in lib/models/capabilities.ts); if Moonshot ever
85
- * enforces it, the turn ends with MOONSHOT_HTTP_ERROR naming the field.
86
- * - Every cell of its capability row is asserted against the request body
87
- * the adapter sends (tests/capabilityMatrix.test.ts), as for every other
88
- * provider. Verified live on 2026-10-03 through `npm run demo:models`:
89
- * kimi-k3 at low effort answered the zoo's explainer prompt in 17.9 s,
90
- * 440 tokens in, 486 out, 262 of them thinking, the scratchpad surfaced
91
- * from reasoning_content; tool loops and search were not exercised.
6
+ * The provider's work is KimiAdapter (lib/models/kimiAdapter.ts), on the
7
+ * engine's own model contract; its header covers the family, cost, the
8
+ * reasoning controls per generation, and reasoning_content on tool loops
9
+ * (ADR 0046). ADK still runs every turn, so this class runs the adapter
10
+ * under ADK: it is the chat-completions shim
11
+ * (lib/models/openAiCompatibleLlm.ts, ADR 0057), registered for any
12
+ * `kimi-*` id when MOONSHOT_API_KEY is set. The constructor and
13
+ * supportedModels are what they were before the adapter moved onto the
14
+ * contract, so lib/models/registry.ts and every caller are unchanged. On
15
+ * this path an agent's older spelling `reasoningEffort: max` still reaches
16
+ * K3, which the contract has no level for.
92
17
  */
93
18
  import { LLMRegistry } from '@google/adk';
94
- import { DEFAULT_KIMI_REASONING_EFFORT } from '../config.js';
19
+ import { KimiAdapter } from './kimiAdapter.js';
95
20
  import { OpenAiCompatibleLlm } from './openAiCompatibleLlm.js';
96
- export const MOONSHOT_BASE_URL = 'https://api.moonshot.ai/v1';
97
- /** The flagship takes `reasoning_effort`; the K2 generation takes a `thinking` switch. */
98
- export function isKimiK3(model) {
99
- return /^kimi-k3\b/.test(model);
100
- }
21
+ export { MOONSHOT_BASE_URL, isKimiK3, wantsReasoningReplay } from './kimiAdapter.js';
101
22
  // ── KimiLlm ───────────────────────────────────────────────────────────────────
102
23
  export class KimiLlm extends OpenAiCompatibleLlm {
103
24
  /** Any model: "kimi-*" in a YAML config routes here after registration. */
104
25
  static supportedModels = [/^kimi-.+/];
105
- apiKey;
106
- baseUrl;
26
+ /** `apiKey` defaults to MOONSHOT_API_KEY; `baseUrl` to MOONSHOT_BASE_URL, else https://api.moonshot.ai/v1. */
107
27
  constructor({ model, apiKey, baseUrl }) {
108
- super({ model });
109
- this.apiKey = apiKey;
110
- this.baseUrl = (baseUrl || process.env.MOONSHOT_BASE_URL || MOONSHOT_BASE_URL).replace(/\/+$/, '');
111
- }
112
- providerId() {
113
- return 'moonshot';
114
- }
115
- endpointUrl() {
116
- return `${this.baseUrl}/chat/completions`;
117
- }
118
- key() {
119
- return this.apiKey ?? process.env.MOONSHOT_API_KEY;
120
- }
121
- headers() {
122
- return { Authorization: `Bearer ${this.key() ?? ''}` };
123
- }
124
- missingRequirement() {
125
- if (this.key())
126
- return undefined;
127
- return {
128
- errorCode: 'MOONSHOT_MISSING_KEY',
129
- errorMessage: 'MOONSHOT_API_KEY is not set in environment.',
130
- };
131
- }
132
- httpError(status, detail) {
133
- const hint = status === 401
134
- ? ' Check MOONSHOT_API_KEY (platform.moonshot.ai).'
135
- : status === 404
136
- ? ` Is "${this.model}" a current Kimi id? kimi-k2.5 and moonshot-v1-* were retired on 2026-08-31.`
137
- : '';
138
- return {
139
- errorCode: 'MOONSHOT_HTTP_ERROR',
140
- errorMessage: `Moonshot returned ${status}: ${detail.slice(0, 4000)}.${hint}`,
141
- };
142
- }
143
- /**
144
- * The reasoning controls, per generation (see the header). The base has
145
- * already put `reasoning_effort` in the body when the agent set one;
146
- * these fields are merged after it, so an `undefined` here removes it
147
- * (JSON.stringify drops undefined keys).
148
- */
149
- extraBodyFields(llmRequest) {
150
- const cfg = llmRequest.config ?? {};
151
- const effort = cfg.reasoningEffort;
152
- if (isKimiK3(this.model)) {
153
- if (effort === undefined)
154
- return { reasoning_effort: DEFAULT_KIMI_REASONING_EFFORT };
155
- if (effort === 'none')
156
- return { reasoning_effort: 'low' }; // K3 cannot switch thinking off
157
- return {};
158
- }
159
- const budget = cfg.thinkingConfig?.thinkingBudget;
160
- const off = effort === 'none' || budget === 0;
161
- return {
162
- reasoning_effort: undefined,
163
- ...(off ? { thinking: { type: 'disabled' } } : {}),
164
- };
28
+ super(new KimiAdapter({ model, apiKey, baseUrl }), { model });
165
29
  }
166
30
  }
167
31
  // ── Registration helper ───────────────────────────────────────────────────────