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,47 @@
1
+ /**
2
+ * lib/model.ts — the `melchizedek-agents/model` entry: the engine's model
3
+ * layer on its own, with no @google/adk (ADR 0068).
4
+ *
5
+ * What it holds: the model contract's types (ADR 0048), every provider's
6
+ * contract adapter, resolveAdapter and resolveAdapterWithFallback over the
7
+ * one prefix table (ADR 0060), FallbackAdapter and the circuit breaker's
8
+ * helpers (ADR 0044). A consumer can call any model through it without
9
+ * installing ADK, the peer dependency the rest of the package needs.
10
+ *
11
+ * What it leaves out, because each loads ADK: AdkGeminiAdapter, the ADK
12
+ * shims (ClaudeLlm, GptLlm and the rest), TracedGemini, resolveModel and
13
+ * registerAvailableProviders. They stay at `melchizedek-agents/models/*`.
14
+ *
15
+ * Gemini: resolveAdapter here returns the engine's GeminiAdapter for a
16
+ * Gemini id. Asking for `adk` (the option, or GEMINI_ADAPTER=adk) throws and
17
+ * names `melchizedek-agents/models/registry`, whose resolveAdapter keeps
18
+ * ADR 0060's default until gate G3.
19
+ *
20
+ * tests/packageSurface.test.ts walks this module's runtime import graph and
21
+ * fails if any module in it names @google/adk.
22
+ */
23
+ export type * from './models/contract.ts';
24
+ export { resolveAdapter, resolveAdapterWithFallback, geminiAdapterSetting } from './models/adapterResolver.ts';
25
+ export type { GeminiAdapterChoice, ResolveAdapterOptions } from './models/adapterResolver.ts';
26
+ export { PROVIDERS, providerForModel, providerKeyPresent } from './models/providerMap.ts';
27
+ export type { ProviderId } from './models/providerMap.ts';
28
+ export type { Platform, ProviderEndpoint } from './models/endpoints.ts';
29
+ export { ClaudeAdapter } from './models/claudeAdapter.ts';
30
+ export type { ClaudeAdapterOptions } from './models/claudeAdapter.ts';
31
+ export { GptAdapter } from './models/gptAdapter.ts';
32
+ export type { GptAdapterOptions } from './models/gptAdapter.ts';
33
+ export { GrokAdapter } from './models/grokAdapter.ts';
34
+ export type { GrokAdapterOptions } from './models/grokAdapter.ts';
35
+ export { ChatCompletionsAdapter } from './models/chatCompletionsAdapter.ts';
36
+ export type { ChatCompletionsAdapterOptions } from './models/chatCompletionsAdapter.ts';
37
+ export { KimiAdapter } from './models/kimiAdapter.ts';
38
+ export type { KimiAdapterOptions } from './models/kimiAdapter.ts';
39
+ export { OllamaAdapter } from './models/ollamaAdapter.ts';
40
+ export type { OllamaAdapterOptions } from './models/ollamaAdapter.ts';
41
+ export { GatewayAdapter } from './models/gatewayAdapter.ts';
42
+ export type { GatewayAdapterOptions } from './models/gatewayAdapter.ts';
43
+ export { GeminiAdapter } from './models/geminiAdapter.ts';
44
+ export type { GeminiAdapterOptions } from './models/geminiAdapter.ts';
45
+ export { FallbackAdapter, isProviderError } from './models/fallbackAdapter.ts';
46
+ export type { FallbackAdapterOptions } from './models/fallbackAdapter.ts';
47
+ export { breakerSettings, circuitOpen, recordFailure, recordSuccess, resetCircuits } from './models/circuitBreaker.ts';
@@ -0,0 +1,37 @@
1
+ /**
2
+ * lib/model.ts — the `melchizedek-agents/model` entry: the engine's model
3
+ * layer on its own, with no @google/adk (ADR 0068).
4
+ *
5
+ * What it holds: the model contract's types (ADR 0048), every provider's
6
+ * contract adapter, resolveAdapter and resolveAdapterWithFallback over the
7
+ * one prefix table (ADR 0060), FallbackAdapter and the circuit breaker's
8
+ * helpers (ADR 0044). A consumer can call any model through it without
9
+ * installing ADK, the peer dependency the rest of the package needs.
10
+ *
11
+ * What it leaves out, because each loads ADK: AdkGeminiAdapter, the ADK
12
+ * shims (ClaudeLlm, GptLlm and the rest), TracedGemini, resolveModel and
13
+ * registerAvailableProviders. They stay at `melchizedek-agents/models/*`.
14
+ *
15
+ * Gemini: resolveAdapter here returns the engine's GeminiAdapter for a
16
+ * Gemini id. Asking for `adk` (the option, or GEMINI_ADAPTER=adk) throws and
17
+ * names `melchizedek-agents/models/registry`, whose resolveAdapter keeps
18
+ * ADR 0060's default until gate G3.
19
+ *
20
+ * tests/packageSurface.test.ts walks this module's runtime import graph and
21
+ * fails if any module in it names @google/adk.
22
+ */
23
+ // ── Resolve an adapter by model id ──────────────────────────────────────────
24
+ export { resolveAdapter, resolveAdapterWithFallback, geminiAdapterSetting } from './models/adapterResolver.js';
25
+ export { PROVIDERS, providerForModel, providerKeyPresent } from './models/providerMap.js';
26
+ // ── The adapters ────────────────────────────────────────────────────────────
27
+ export { ClaudeAdapter } from './models/claudeAdapter.js';
28
+ export { GptAdapter } from './models/gptAdapter.js';
29
+ export { GrokAdapter } from './models/grokAdapter.js';
30
+ export { ChatCompletionsAdapter } from './models/chatCompletionsAdapter.js';
31
+ export { KimiAdapter } from './models/kimiAdapter.js';
32
+ export { OllamaAdapter } from './models/ollamaAdapter.js';
33
+ export { GatewayAdapter } from './models/gatewayAdapter.js';
34
+ export { GeminiAdapter } from './models/geminiAdapter.js';
35
+ // ── Fallback and the circuit breaker ────────────────────────────────────────
36
+ export { FallbackAdapter, isProviderError } from './models/fallbackAdapter.js';
37
+ export { breakerSettings, circuitOpen, recordFailure, recordSuccess, resetCircuits } from './models/circuitBreaker.js';
@@ -0,0 +1,113 @@
1
+ /**
2
+ * lib/models/adapterResolver.ts — one model id to one ModelAdapter on the
3
+ * engine's own contract (ADR 0048, ADR 0060), with no @google/adk in its
4
+ * import graph.
5
+ *
6
+ * WHY its own module: lib/models/registry.ts imports ADK (it registers the
7
+ * ADK classes and builds TracedGemini), so the `melchizedek-agents/model`
8
+ * entry (lib/model.ts) cannot load it. The routing step both paths share
9
+ * (routeFor: the provider from the prefix table, the caller's endpoint merged
10
+ * over the environment's, the transport from planTransport), the BYOK scoping
11
+ * and the contract adapter table live here; registry.ts imports them for
12
+ * resolveModel and for its own resolveAdapter.
13
+ *
14
+ * GEMINI (ADR 0068): `adapterResolver(adkGemini)` takes the factory for the
15
+ * temporary AdkGeminiAdapter from its caller. registry.ts passes one, so its
16
+ * resolveAdapter keeps ADR 0060's default (`adk` until gate G3). The resolver
17
+ * exported here has none: a Gemini id gets the engine's GeminiAdapter unless
18
+ * `adk` is asked for, by the option or by GEMINI_ADAPTER=adk, which throws
19
+ * and names the entry that has it.
20
+ */
21
+ import type { ModelAdapter } from './contract.ts';
22
+ import type { ProviderEndpoint } from './endpoints.ts';
23
+ import type { FallbackAdapterOptions } from './fallbackAdapter.ts';
24
+ import type { ProviderId } from './providerMap.ts';
25
+ /** Where one model id goes: its provider, its transport, and what the caller injects. */
26
+ export interface Route {
27
+ provider: ProviderId;
28
+ model: string;
29
+ transport: 'direct' | 'gateway';
30
+ /** A caller's own key for this provider, already scoped to it. */
31
+ apiKey?: string;
32
+ /** The caller's endpoint merged over the environment's (ADR 0023). */
33
+ endpoint?: ProviderEndpoint;
34
+ }
35
+ /**
36
+ * The fallback rule (lib/models/gateway.ts): the direct adapter whenever the
37
+ * provider's key — from env, or the caller's own BYOK key or endpoint — is
38
+ * present; the gateway stand-in only when it is absent and a gateway is
39
+ * configured. The gateway key is server env only, never a request header.
40
+ */
41
+ export declare function routeFor(model: string, apiKey: string | undefined, endpoint: Partial<ProviderEndpoint> | undefined): Route;
42
+ /**
43
+ * BYOK is scoped to the CALLER'S provider: the key a client sends
44
+ * authenticates that client's own provider (typically Gemini). Passing it to
45
+ * a different provider's adapter would override the server's env key
46
+ * (adapters prefer a passed key), fail auth, and hand the key to another
47
+ * vendor — e.g. a Gemini key sent to xAI. Cross-provider models therefore
48
+ * resolve keys from server env.
49
+ */
50
+ export declare function scopedKey(model: string, apiKey: string | undefined, keyProvider: ProviderId): string | undefined;
51
+ /** A provider name as the A2A X-Provider header gives it; anything unknown reads as gemini. */
52
+ export declare function normalizeProvider(provider?: string): ProviderId;
53
+ /**
54
+ * Which adapter serves a Gemini id on the contract path: `adk`, the temporary
55
+ * AdkGeminiAdapter over ADK's Gemini (lib/models/adkGeminiAdapter.ts), or
56
+ * `engine`, the engine's own GeminiAdapter on @google/genai
57
+ * (lib/models/geminiAdapter.ts).
58
+ */
59
+ export type GeminiAdapterChoice = 'adk' | 'engine';
60
+ /** GEMINI_ADAPTER as set (`adk` or `engine`), or undefined when unset. Any other value is a configuration error. */
61
+ export declare function geminiAdapterSetting(env?: NodeJS.ProcessEnv): GeminiAdapterChoice | undefined;
62
+ export interface ResolveAdapterOptions {
63
+ /**
64
+ * A caller's own API key (BYOK). It authenticates `keyProvider`'s models
65
+ * only, and wins over the endpoint's and the environment's key there.
66
+ */
67
+ apiKey?: string;
68
+ /**
69
+ * The provider `apiKey` belongs to (a provider id; anything else reads as
70
+ * gemini, as the A2A X-Provider header does). Default: the model's own.
71
+ * A model of another provider resolves its key from server env.
72
+ */
73
+ keyProvider?: string;
74
+ /** Where requests go (ADR 0023), merged over the environment's endpoint for the model's provider. */
75
+ endpoint?: Partial<ProviderEndpoint>;
76
+ /**
77
+ * Which Gemini adapter a Gemini id gets. Default: GEMINI_ADAPTER, else
78
+ * `adk` through `melchizedek-agents/models/registry` and `engine` through
79
+ * `melchizedek-agents/model`, which has no `adk`.
80
+ */
81
+ gemini?: GeminiAdapterChoice;
82
+ }
83
+ /** What a direct route's adapter is built from. */
84
+ export type AdapterRoute = Pick<Route, 'model' | 'apiKey' | 'endpoint'>;
85
+ /** Builds the temporary AdkGeminiAdapter; only lib/models/registry.ts supplies one. */
86
+ export type AdkGeminiFactory = (route: AdapterRoute) => ModelAdapter;
87
+ export interface AdapterResolver {
88
+ resolveAdapter(modelId: string, options?: ResolveAdapterOptions): ModelAdapter;
89
+ resolveAdapterWithFallback(modelId: string, fallbackId: string | undefined, options?: ResolveAdapterOptions, fallbackOptions?: FallbackAdapterOptions): ModelAdapter;
90
+ }
91
+ /**
92
+ * A resolver over the one prefix table. With `adkGemini`, a Gemini id gets
93
+ * AdkGeminiAdapter unless `engine` is asked for (ADR 0060). Without it, a
94
+ * Gemini id gets GeminiAdapter, and asking for `adk` throws (ADR 0068).
95
+ */
96
+ export declare function adapterResolver(adkGemini?: AdkGeminiFactory): AdapterResolver;
97
+ /**
98
+ * Resolves a model id to the engine's own ModelAdapter (ADR 0048), from the
99
+ * prefix table and the transport rule resolveModel uses, with no ADK: the
100
+ * provider's adapter when its key (env, BYOK or endpoint) is present, the
101
+ * gateway's when it is absent and MODEL_GATEWAY is set. A Gemini id gets
102
+ * GeminiAdapter (ADR 0068). The adapter opens no span and charges nothing:
103
+ * its caller does (ADR 0053).
104
+ */
105
+ export declare function resolveAdapter(modelId: string, options?: ResolveAdapterOptions): ModelAdapter;
106
+ /**
107
+ * An agent's model and its `fallback_model:`: a FallbackAdapter (ADR 0044)
108
+ * around resolveAdapter's two adapters, or the primary alone. The caller's
109
+ * key stays with its own provider: unless `keyProvider` says otherwise it
110
+ * belongs to the primary's, so a fallback on another provider resolves from
111
+ * server env.
112
+ */
113
+ export declare function resolveAdapterWithFallback(modelId: string, fallbackId: string | undefined, options?: ResolveAdapterOptions, fallbackOptions?: FallbackAdapterOptions): ModelAdapter;
@@ -0,0 +1,136 @@
1
+ /**
2
+ * lib/models/adapterResolver.ts — one model id to one ModelAdapter on the
3
+ * engine's own contract (ADR 0048, ADR 0060), with no @google/adk in its
4
+ * import graph.
5
+ *
6
+ * WHY its own module: lib/models/registry.ts imports ADK (it registers the
7
+ * ADK classes and builds TracedGemini), so the `melchizedek-agents/model`
8
+ * entry (lib/model.ts) cannot load it. The routing step both paths share
9
+ * (routeFor: the provider from the prefix table, the caller's endpoint merged
10
+ * over the environment's, the transport from planTransport), the BYOK scoping
11
+ * and the contract adapter table live here; registry.ts imports them for
12
+ * resolveModel and for its own resolveAdapter.
13
+ *
14
+ * GEMINI (ADR 0068): `adapterResolver(adkGemini)` takes the factory for the
15
+ * temporary AdkGeminiAdapter from its caller. registry.ts passes one, so its
16
+ * resolveAdapter keeps ADR 0060's default (`adk` until gate G3). The resolver
17
+ * exported here has none: a Gemini id gets the engine's GeminiAdapter unless
18
+ * `adk` is asked for, by the option or by GEMINI_ADAPTER=adk, which throws
19
+ * and names the entry that has it.
20
+ */
21
+ import { ClaudeAdapter } from './claudeAdapter.js';
22
+ import { mergeEndpoint } from './endpoints.js';
23
+ import { FallbackAdapter } from './fallbackAdapter.js';
24
+ import { planTransport } from './gateway.js';
25
+ import { GatewayAdapter } from './gatewayAdapter.js';
26
+ import { GeminiAdapter } from './geminiAdapter.js';
27
+ import { GptAdapter } from './gptAdapter.js';
28
+ import { GrokAdapter } from './grokAdapter.js';
29
+ import { KimiAdapter } from './kimiAdapter.js';
30
+ import { OllamaAdapter } from './ollamaAdapter.js';
31
+ import { providerForModel } from './providerMap.js';
32
+ /**
33
+ * The fallback rule (lib/models/gateway.ts): the direct adapter whenever the
34
+ * provider's key — from env, or the caller's own BYOK key or endpoint — is
35
+ * present; the gateway stand-in only when it is absent and a gateway is
36
+ * configured. The gateway key is server env only, never a request header.
37
+ */
38
+ export function routeFor(model, apiKey, endpoint) {
39
+ const provider = providerForModel(model);
40
+ const merged = endpoint ? mergeEndpoint(provider, endpoint) : undefined;
41
+ const { transport } = planTransport(model, { callerKey: !!apiKey || !!merged });
42
+ return { provider, model, transport, ...(apiKey ? { apiKey } : {}), ...(merged ? { endpoint: merged } : {}) };
43
+ }
44
+ /**
45
+ * BYOK is scoped to the CALLER'S provider: the key a client sends
46
+ * authenticates that client's own provider (typically Gemini). Passing it to
47
+ * a different provider's adapter would override the server's env key
48
+ * (adapters prefer a passed key), fail auth, and hand the key to another
49
+ * vendor — e.g. a Gemini key sent to xAI. Cross-provider models therefore
50
+ * resolve keys from server env.
51
+ */
52
+ export function scopedKey(model, apiKey, keyProvider) {
53
+ return providerForModel(model) === keyProvider ? apiKey : undefined;
54
+ }
55
+ /** A provider name as the A2A X-Provider header gives it; anything unknown reads as gemini. */
56
+ export function normalizeProvider(provider) {
57
+ const p = provider?.toLowerCase();
58
+ if (p === 'ollama' || p === 'anthropic' || p === 'openai' || p === 'xai' || p === 'moonshot') {
59
+ return p;
60
+ }
61
+ return 'gemini';
62
+ }
63
+ /** GEMINI_ADAPTER as set (`adk` or `engine`), or undefined when unset. Any other value is a configuration error. */
64
+ export function geminiAdapterSetting(env = process.env) {
65
+ const raw = env.GEMINI_ADAPTER?.trim().toLowerCase();
66
+ if (!raw)
67
+ return undefined;
68
+ if (raw === 'adk' || raw === 'engine')
69
+ return raw;
70
+ throw new Error('GEMINI_ADAPTER must be "adk" or "engine".');
71
+ }
72
+ /** Each non-Gemini provider's contract adapter for a direct route. */
73
+ const CONTRACT_ADAPTER = {
74
+ ollama: (r) => new OllamaAdapter({ model: r.model }),
75
+ anthropic: (r) => new ClaudeAdapter({ model: r.model, apiKey: r.apiKey, endpoint: r.endpoint }),
76
+ openai: (r) => new GptAdapter({ model: r.model, apiKey: r.apiKey, endpoint: r.endpoint }),
77
+ xai: (r) => new GrokAdapter({ model: r.model, apiKey: r.apiKey }),
78
+ moonshot: (r) => new KimiAdapter({ model: r.model, apiKey: r.apiKey, baseUrl: r.endpoint?.baseURL }),
79
+ };
80
+ /**
81
+ * A resolver over the one prefix table. With `adkGemini`, a Gemini id gets
82
+ * AdkGeminiAdapter unless `engine` is asked for (ADR 0060). Without it, a
83
+ * Gemini id gets GeminiAdapter, and asking for `adk` throws (ADR 0068).
84
+ */
85
+ export function adapterResolver(adkGemini) {
86
+ const geminiFor = (r, choice) => {
87
+ const route = { model: r.model, apiKey: r.apiKey, endpoint: r.endpoint };
88
+ if (choice === 'engine')
89
+ return new GeminiAdapter(route);
90
+ if (!adkGemini) {
91
+ throw new Error('The ADK Gemini adapter is not available from melchizedek-agents/model, which loads no @google/adk. ' +
92
+ 'Use gemini: "engine" (or unset GEMINI_ADAPTER), or resolve through melchizedek-agents/models/registry.');
93
+ }
94
+ return adkGemini(route);
95
+ };
96
+ function resolveAdapter(modelId, options = {}) {
97
+ const keyProvider = options.keyProvider === undefined ? providerForModel(modelId) : normalizeProvider(options.keyProvider);
98
+ const route = routeFor(modelId, scopedKey(modelId, options.apiKey, keyProvider), options.endpoint);
99
+ if (route.transport === 'gateway')
100
+ return new GatewayAdapter({ model: modelId });
101
+ if (route.provider === 'gemini') {
102
+ return geminiFor(route, options.gemini ?? geminiAdapterSetting() ?? (adkGemini ? 'adk' : 'engine'));
103
+ }
104
+ return CONTRACT_ADAPTER[route.provider](route);
105
+ }
106
+ function resolveAdapterWithFallback(modelId, fallbackId, options = {}, fallbackOptions = {}) {
107
+ const scoped = { ...options, keyProvider: options.keyProvider ?? providerForModel(modelId) };
108
+ const primary = resolveAdapter(modelId, scoped);
109
+ if (!fallbackId)
110
+ return primary;
111
+ return new FallbackAdapter(primary, resolveAdapter(fallbackId, scoped), fallbackOptions);
112
+ }
113
+ return { resolveAdapter, resolveAdapterWithFallback };
114
+ }
115
+ const ADK_FREE = adapterResolver();
116
+ /**
117
+ * Resolves a model id to the engine's own ModelAdapter (ADR 0048), from the
118
+ * prefix table and the transport rule resolveModel uses, with no ADK: the
119
+ * provider's adapter when its key (env, BYOK or endpoint) is present, the
120
+ * gateway's when it is absent and MODEL_GATEWAY is set. A Gemini id gets
121
+ * GeminiAdapter (ADR 0068). The adapter opens no span and charges nothing:
122
+ * its caller does (ADR 0053).
123
+ */
124
+ export function resolveAdapter(modelId, options = {}) {
125
+ return ADK_FREE.resolveAdapter(modelId, options);
126
+ }
127
+ /**
128
+ * An agent's model and its `fallback_model:`: a FallbackAdapter (ADR 0044)
129
+ * around resolveAdapter's two adapters, or the primary alone. The caller's
130
+ * key stays with its own provider: unless `keyProvider` says otherwise it
131
+ * belongs to the primary's, so a fallback on another provider resolves from
132
+ * server env.
133
+ */
134
+ export function resolveAdapterWithFallback(modelId, fallbackId, options = {}, fallbackOptions = {}) {
135
+ return ADK_FREE.resolveAdapterWithFallback(modelId, fallbackId, options, fallbackOptions);
136
+ }
@@ -0,0 +1,90 @@
1
+ /**
2
+ * lib/models/adkGeminiAdapter.ts — TEMPORARY: Gemini as a contract
3
+ * ModelAdapter (ADR 0048) over ADK's own Gemini, the TracedGemini path of
4
+ * lib/models/tracedGemini.ts, through the genai mapping (lib/models/genaiMapping.ts).
5
+ *
6
+ * WHY this file exists:
7
+ * The native loop (ADR 0045) calls ModelAdapters only. The engine's own
8
+ * Gemini adapter (lib/models/geminiAdapter.ts) calls @google/genai with no
9
+ * ADK, and waits for its live parity run at gate G3. Until it passes,
10
+ * Gemini on the native runtime goes through ADK's proven Gemini, wrapped
11
+ * here, so every provider has a contract adapter before gate G1. Delete
12
+ * this file once G3 is signed and GeminiAdapter serves every Gemini id
13
+ * (the plan's G3 risk: "The WS1-8 wrapper over ADK's Gemini stays until
14
+ * the cells pass"). resolveAdapter (lib/models/registry.ts) returns it for Gemini ids.
15
+ *
16
+ * THE CALL:
17
+ * 1. The ModelRequest becomes an LlmRequest (modelRequestToLlmRequest),
18
+ * and then what ADK's path does to one before its Gemini sees it:
19
+ * - system messages joined onto the system prompt, in order, since
20
+ * Gemini takes no `system` content;
21
+ * - `adk-` call ids taken off calls and results, as ADK's flow does
22
+ * before every model call (ids the mapping minted are already off);
23
+ * - `includeServerSideToolInvocations`, which the compiler sends on
24
+ * every Gemini agent (lib/compile.ts);
25
+ * - `includeThoughts` under any reasoning but `none`, the contract's
26
+ * Gemini table, as GeminiAdapter sends it;
27
+ * - the platform's wire model (GEMINI_MODEL_MAP), as TracedGemini's own.
28
+ * The request is copied where ADK writes to it (a blob's display name),
29
+ * so the caller's history is never changed.
30
+ * 2. TracedGemini.generateWithRetries runs it: ADK's Gemini with the
31
+ * shared retries, tagging the span that is open around this adapter
32
+ * (llm.web_search.native, llm.retries, llm.http_status), as it tags its
33
+ * own. `llm.capability.dropped` marks native tools Gemini has none for.
34
+ * 3. Each LlmResponse comes back through llmResponseToModelResponse,
35
+ * folded into the contract's stream. A thought signature becomes
36
+ * providerState naming the request's model. A call Gemini returns
37
+ * without an id gets the mapping's `genai-noid-<position>-<part>`, or,
38
+ * streamed, ADK's own `adk-` id; neither goes back on the wire.
39
+ *
40
+ * REPLAY: every Gemini signature in the history goes back on its part, as
41
+ * ADK sends a stored session's, whichever turn or model wrote it.
42
+ * GeminiAdapter replays only the current turn's, for its own model.
43
+ *
44
+ * THE SPAN AND THE CHARGE are the caller's (ADR 0053): this adapter opens no
45
+ * llm.request span and never charges the turn. Behind the ADK shim
46
+ * (lib/models/adkShim.ts) it records the span TracedGemini records today for
47
+ * the same exchange, but for a failed call's code (tests/telemetryLedger.test.ts).
48
+ *
49
+ * THE ADAPTER RULES (contract.ts header) as this adapter keeps them:
50
+ * - Partials: a streamed call's text and thinking deltas, as ADK's stream
51
+ * aggregator yields them. A call that does not stream yields its
52
+ * thinking as one partial before the final.
53
+ * - One final: every non-partial response ADK yields for the call (its
54
+ * aggregator flushes the text before each tool call) folds into it, with
55
+ * the last usage, grounding and finish reason.
56
+ * - Errors are finals, never throws. ADK's Gemini throws on a failed call:
57
+ * that is GEMINI_ERROR, `retryable` from lib/models/retry.ts's
58
+ * classifyError, `status` when the error had one. An error code ADK
59
+ * yields (a finish or block reason) is the code, not retryable; ADK's
60
+ * `STOP` is no error. Setup failures are MISSING_API_KEY and
61
+ * ENDPOINT_MISCONFIGURED, as GeminiAdapter's.
62
+ * - The abort: `request.signal` (the shim aborts it when the turn stops)
63
+ * goes on the request config. An aborted call is GEMINI_ERROR, never
64
+ * retryable, and the iteration ends at once whatever the transport does;
65
+ * a signal aborted before the call sends nothing.
66
+ * - Retries: TracedGemini's, only before the first chunk.
67
+ * - Messages never carry the key in use or anything shaped like a key.
68
+ */
69
+ import type { ModelAdapter, ModelRequest, ModelResponse } from './contract.ts';
70
+ import type { ProviderEndpoint } from './endpoints.ts';
71
+ export interface AdkGeminiAdapterOptions {
72
+ /** The model id as the YAML names it. */
73
+ model: string;
74
+ /**
75
+ * A Gemini API (AI Studio) key: a caller's own, or one the credentials plug
76
+ * point returned. It wins over the endpoint's and the environment's, and is
77
+ * never sent to Vertex AI.
78
+ */
79
+ apiKey?: string;
80
+ /** Where requests go (ADR 0023). Default: `endpointFromEnv('gemini')`, read on the first call. */
81
+ endpoint?: ProviderEndpoint;
82
+ }
83
+ /** Temporary: ADK's Gemini behind the model contract, until GeminiAdapter passes gate G3. */
84
+ export declare class AdkGeminiAdapter implements ModelAdapter {
85
+ #private;
86
+ readonly provider = "gemini";
87
+ readonly model: string;
88
+ constructor(options: AdkGeminiAdapterOptions);
89
+ generate(request: ModelRequest): AsyncGenerator<ModelResponse, void>;
90
+ }