melchizedek-agents 0.18.0 → 0.20.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 (293) hide show
  1. package/.env.example +12 -0
  2. package/CHANGELOG.md +1001 -0
  3. package/DOCUMENTATION.md +252 -65
  4. package/QUICKSTART.md +9 -6
  5. package/README.md +42 -4
  6. package/config/agents/examples/harness.yaml +3 -1
  7. package/config/agents/examples/model_zoo.yaml +10 -9
  8. package/config/agents/syndicateSchema.yaml +53 -16
  9. package/config/agents/templates/account_memory.yaml +2 -6
  10. package/config/agents/templates/case_desk.yaml +3 -9
  11. package/config/agents/templates/draft_review.yaml +3 -9
  12. package/config/agents/templates/intake_extractor.yaml +1 -3
  13. package/config/agents/templates/research_brief.yaml +3 -9
  14. package/config/agents/templates/research_desk.yaml +3 -9
  15. package/config/agents/templates/review_panel.yaml +4 -12
  16. package/config/agents/templates/support_triage.yaml +4 -12
  17. package/config/agents/templates/systems_operator.yaml +2 -6
  18. package/db/hardening.sql +7 -1
  19. package/db/migrations/0013_tool_credentials.sql +260 -0
  20. package/dist/lib/a2a/app.d.ts +70 -6
  21. package/dist/lib/a2a/app.js +107 -2
  22. package/dist/lib/a2a/executor.d.ts +20 -3
  23. package/dist/lib/a2a/executor.js +66 -7
  24. package/dist/lib/a2a/remoteAgent.d.ts +24 -9
  25. package/dist/lib/a2a/remoteAgent.js +31 -14
  26. package/dist/lib/adkPeer.d.ts +63 -0
  27. package/dist/lib/adkPeer.js +240 -0
  28. package/dist/lib/compile.d.ts +159 -30
  29. package/dist/lib/compile.js +215 -134
  30. package/dist/lib/compileAdk.d.ts +32 -0
  31. package/dist/lib/compileAdk.js +142 -0
  32. package/dist/lib/compileNative.d.ts +111 -0
  33. package/dist/lib/compileNative.js +278 -0
  34. package/dist/lib/config.d.ts +6 -5
  35. package/dist/lib/config.js +6 -5
  36. package/dist/lib/doctor.d.ts +28 -1
  37. package/dist/lib/doctor.js +64 -2
  38. package/dist/lib/index.d.ts +6 -1
  39. package/dist/lib/index.js +7 -1
  40. package/dist/lib/loadSyndicate.d.ts +18 -0
  41. package/dist/lib/memory/erase.d.ts +5 -3
  42. package/dist/lib/memory/erase.js +5 -2
  43. package/dist/lib/memory/namespace.d.ts +8 -1
  44. package/dist/lib/memory/namespace.js +12 -6
  45. package/dist/lib/memory/providers.js +2 -1
  46. package/dist/lib/memory/supabaseMemoryService.d.ts +37 -3
  47. package/dist/lib/memory/supabaseMemoryService.js +42 -2
  48. package/dist/lib/model.d.ts +47 -0
  49. package/dist/lib/model.js +37 -0
  50. package/dist/lib/models/adapterResolver.d.ts +115 -0
  51. package/dist/lib/models/adapterResolver.js +137 -0
  52. package/dist/lib/models/adkGeminiAdapter.d.ts +90 -0
  53. package/dist/lib/models/adkGeminiAdapter.js +369 -0
  54. package/dist/lib/models/adkShim.d.ts +111 -0
  55. package/dist/lib/models/adkShim.js +136 -0
  56. package/dist/lib/models/capabilities.d.ts +3 -0
  57. package/dist/lib/models/capabilities.js +33 -23
  58. package/dist/lib/models/chatCompletionsAdapter.d.ts +279 -0
  59. package/dist/lib/models/chatCompletionsAdapter.js +854 -0
  60. package/dist/lib/models/circuitBreaker.d.ts +42 -0
  61. package/dist/lib/models/circuitBreaker.js +70 -0
  62. package/dist/lib/models/claudeAdapter.d.ts +103 -0
  63. package/dist/lib/models/claudeAdapter.js +669 -0
  64. package/dist/lib/models/claudeLlm.d.ts +39 -62
  65. package/dist/lib/models/claudeLlm.js +45 -350
  66. package/dist/lib/models/claudeModels.d.ts +127 -0
  67. package/dist/lib/models/claudeModels.js +237 -0
  68. package/dist/lib/models/contract.d.ts +395 -0
  69. package/dist/lib/models/contract.js +39 -0
  70. package/dist/lib/models/endpoints.js +2 -1
  71. package/dist/lib/models/errorResponse.d.ts +50 -0
  72. package/dist/lib/models/errorResponse.js +48 -0
  73. package/dist/lib/models/fallback.d.ts +18 -11
  74. package/dist/lib/models/fallback.js +54 -43
  75. package/dist/lib/models/fallbackAdapter.d.ts +55 -0
  76. package/dist/lib/models/fallbackAdapter.js +62 -0
  77. package/dist/lib/models/gateway.js +2 -1
  78. package/dist/lib/models/gatewayAdapter.d.ts +51 -0
  79. package/dist/lib/models/gatewayAdapter.js +81 -0
  80. package/dist/lib/models/gatewayLlm.d.ts +12 -33
  81. package/dist/lib/models/gatewayLlm.js +16 -77
  82. package/dist/lib/models/geminiAdapter.d.ts +125 -0
  83. package/dist/lib/models/geminiAdapter.js +854 -0
  84. package/dist/lib/models/geminiState.d.ts +46 -0
  85. package/dist/lib/models/geminiState.js +51 -0
  86. package/dist/lib/models/genaiMapping.d.ts +283 -0
  87. package/dist/lib/models/genaiMapping.js +965 -0
  88. package/dist/lib/models/gptAdapter.d.ts +240 -0
  89. package/dist/lib/models/gptAdapter.js +804 -0
  90. package/dist/lib/models/gptLlm.d.ts +63 -123
  91. package/dist/lib/models/gptLlm.js +89 -603
  92. package/dist/lib/models/grokAdapter.d.ts +86 -0
  93. package/dist/lib/models/grokAdapter.js +142 -0
  94. package/dist/lib/models/grokLlm.d.ts +22 -45
  95. package/dist/lib/models/grokLlm.js +24 -69
  96. package/dist/lib/models/kimiAdapter.d.ts +157 -0
  97. package/dist/lib/models/kimiAdapter.js +203 -0
  98. package/dist/lib/models/kimiLlm.d.ts +15 -107
  99. package/dist/lib/models/kimiLlm.js +19 -155
  100. package/dist/lib/models/ollamaAdapter.d.ts +125 -0
  101. package/dist/lib/models/ollamaAdapter.js +155 -0
  102. package/dist/lib/models/ollamaLlm.d.ts +11 -107
  103. package/dist/lib/models/ollamaLlm.js +15 -153
  104. package/dist/lib/models/openAiCompatibleLlm.d.ts +73 -216
  105. package/dist/lib/models/openAiCompatibleLlm.js +109 -671
  106. package/dist/lib/models/providerState.d.ts +63 -0
  107. package/dist/lib/models/providerState.js +61 -0
  108. package/dist/lib/models/reasoning.d.ts +26 -0
  109. package/dist/lib/models/reasoning.js +59 -0
  110. package/dist/lib/models/registry.d.ts +62 -35
  111. package/dist/lib/models/registry.js +100 -124
  112. package/dist/lib/models/retry.d.ts +2 -1
  113. package/dist/lib/models/retry.js +3 -2
  114. package/dist/lib/models/schemaNormalize.d.ts +98 -0
  115. package/dist/lib/models/schemaNormalize.js +321 -1
  116. package/dist/lib/models/tracedGemini.d.ts +41 -0
  117. package/dist/lib/models/tracedGemini.js +98 -0
  118. package/dist/lib/models/urls.d.ts +11 -0
  119. package/dist/lib/models/urls.js +16 -0
  120. package/dist/lib/net/redirects.d.ts +21 -2
  121. package/dist/lib/net/redirects.js +11 -34
  122. package/dist/lib/observability/audit.d.ts +5 -1
  123. package/dist/lib/observability/lineage.d.ts +14 -0
  124. package/dist/lib/observability/lineage.js +33 -0
  125. package/dist/lib/observability/supabaseSpanExporter.d.ts +10 -4
  126. package/dist/lib/observability/supabaseSpanExporter.js +17 -9
  127. package/dist/lib/observability/tracer.d.ts +26 -8
  128. package/dist/lib/observability/tracer.js +43 -18
  129. package/dist/lib/runtime/adkMemoryBridge.d.ts +46 -0
  130. package/dist/lib/runtime/adkMemoryBridge.js +68 -0
  131. package/dist/lib/runtime/adkSessionBridge.d.ts +78 -0
  132. package/dist/lib/runtime/adkSessionBridge.js +176 -0
  133. package/dist/lib/runtime/approvals.d.ts +5 -0
  134. package/dist/lib/runtime/approvals.js +39 -8
  135. package/dist/lib/runtime/credentials.d.ts +61 -0
  136. package/dist/lib/runtime/credentials.js +67 -0
  137. package/dist/lib/runtime/events.d.ts +229 -0
  138. package/dist/lib/runtime/events.js +274 -0
  139. package/dist/lib/runtime/logging.d.ts +32 -0
  140. package/dist/lib/runtime/logging.js +55 -0
  141. package/dist/lib/runtime/memoryService.d.ts +72 -0
  142. package/dist/lib/runtime/memoryService.js +25 -0
  143. package/dist/lib/runtime/native/agentLoop.d.ts +209 -0
  144. package/dist/lib/runtime/native/agentLoop.js +705 -0
  145. package/dist/lib/runtime/native/compaction.d.ts +103 -0
  146. package/dist/lib/runtime/native/compaction.js +191 -0
  147. package/dist/lib/runtime/native/delegate.d.ts +151 -0
  148. package/dist/lib/runtime/native/delegate.js +256 -0
  149. package/dist/lib/runtime/native/history.d.ts +83 -0
  150. package/dist/lib/runtime/native/history.js +312 -0
  151. package/dist/lib/runtime/native/interrupts.d.ts +129 -0
  152. package/dist/lib/runtime/native/interrupts.js +310 -0
  153. package/dist/lib/runtime/native/request.d.ts +215 -0
  154. package/dist/lib/runtime/native/request.js +585 -0
  155. package/dist/lib/runtime/native/selfCorrection.d.ts +164 -0
  156. package/dist/lib/runtime/native/selfCorrection.js +327 -0
  157. package/dist/lib/runtime/native/step.d.ts +156 -0
  158. package/dist/lib/runtime/native/step.js +263 -0
  159. package/dist/lib/runtime/native/taskMode.d.ts +64 -0
  160. package/dist/lib/runtime/native/taskMode.js +126 -0
  161. package/dist/lib/runtime/native/telemetry.d.ts +75 -0
  162. package/dist/lib/runtime/native/telemetry.js +299 -0
  163. package/dist/lib/runtime/native/tempState.d.ts +31 -0
  164. package/dist/lib/runtime/native/tempState.js +56 -0
  165. package/dist/lib/runtime/nativeTurn.d.ts +86 -0
  166. package/dist/lib/runtime/nativeTurn.js +107 -0
  167. package/dist/lib/runtime/questions.d.ts +29 -7
  168. package/dist/lib/runtime/questions.js +47 -32
  169. package/dist/lib/runtime/runtimeFlag.d.ts +38 -0
  170. package/dist/lib/runtime/runtimeFlag.js +58 -0
  171. package/dist/lib/runtime/sessions.d.ts +166 -0
  172. package/dist/lib/runtime/sessions.js +201 -0
  173. package/dist/lib/runtime/syndicateTurn.d.ts +46 -5
  174. package/dist/lib/runtime/syndicateTurn.js +233 -36
  175. package/dist/lib/runtime/valueDepth.d.ts +23 -0
  176. package/dist/lib/runtime/valueDepth.js +41 -0
  177. package/dist/lib/session/supabaseSessionService.d.ts +65 -18
  178. package/dist/lib/session/supabaseSessionService.js +148 -105
  179. package/dist/lib/session/transcript.d.ts +69 -23
  180. package/dist/lib/session/transcript.js +105 -29
  181. package/dist/lib/skills.js +33 -7
  182. package/dist/lib/storage/postgres/credentialStore.d.ts +20 -0
  183. package/dist/lib/storage/postgres/credentialStore.js +82 -0
  184. package/dist/lib/storage/postgres/index.d.ts +12 -0
  185. package/dist/lib/storage/postgres/index.js +6 -1
  186. package/dist/lib/storage/postgres/sessionService.d.ts +44 -16
  187. package/dist/lib/storage/postgres/sessionService.js +128 -66
  188. package/dist/lib/syndicateSchema.d.ts +49 -0
  189. package/dist/lib/syndicateSchema.js +99 -9
  190. package/dist/lib/toolRegistry.d.ts +26 -2
  191. package/dist/lib/toolRegistry.js +73 -17
  192. package/dist/lib/tools/adkTool.d.ts +81 -0
  193. package/dist/lib/tools/adkTool.js +268 -0
  194. package/dist/lib/tools/auth.d.ts +118 -0
  195. package/dist/lib/tools/auth.js +89 -0
  196. package/dist/lib/tools/collectionsSearchTool.d.ts +8 -7
  197. package/dist/lib/tools/collectionsSearchTool.js +12 -27
  198. package/dist/lib/tools/credentialCipher.d.ts +58 -0
  199. package/dist/lib/tools/credentialCipher.js +116 -0
  200. package/dist/lib/tools/credentialStore.d.ts +77 -0
  201. package/dist/lib/tools/credentialStore.js +246 -0
  202. package/dist/lib/tools/examples.d.ts +43 -0
  203. package/dist/lib/tools/examples.js +62 -0
  204. package/dist/lib/tools/generateImageTool.d.ts +15 -6
  205. package/dist/lib/tools/generateImageTool.js +19 -29
  206. package/dist/lib/tools/inspectImageTool.d.ts +9 -6
  207. package/dist/lib/tools/inspectImageTool.js +13 -17
  208. package/dist/lib/tools/mcpToolFactory.d.ts +42 -1
  209. package/dist/lib/tools/mcpToolFactory.js +46 -47
  210. package/dist/lib/tools/memoryTools.d.ts +61 -0
  211. package/dist/lib/tools/memoryTools.js +119 -0
  212. package/dist/lib/tools/nativeTools.d.ts +38 -0
  213. package/dist/lib/tools/nativeTools.js +43 -0
  214. package/dist/lib/tools/oauthConsent.d.ts +181 -0
  215. package/dist/lib/tools/oauthConsent.js +330 -0
  216. package/dist/lib/tools/openapi/call.d.ts +108 -0
  217. package/dist/lib/tools/openapi/call.js +295 -0
  218. package/dist/lib/tools/openapi/parse.d.ts +147 -0
  219. package/dist/lib/tools/openapi/parse.js +570 -0
  220. package/dist/lib/tools/openapiTools.d.ts +25 -17
  221. package/dist/lib/tools/openapiTools.js +124 -121
  222. package/dist/lib/tools/scienceTools.d.ts +14 -14
  223. package/dist/lib/tools/skillToolset.d.ts +58 -87
  224. package/dist/lib/tools/skillToolset.js +61 -142
  225. package/dist/lib/tools/skills/env.d.ts +58 -0
  226. package/dist/lib/tools/skills/env.js +165 -0
  227. package/dist/lib/tools/skills/executor.d.ts +114 -0
  228. package/dist/lib/tools/skills/executor.js +331 -0
  229. package/dist/lib/tools/skills/frontmatter.d.ts +79 -0
  230. package/dist/lib/tools/skills/frontmatter.js +215 -0
  231. package/dist/lib/tools/skills/loader.d.ts +91 -0
  232. package/dist/lib/tools/skills/loader.js +257 -0
  233. package/dist/lib/tools/skills/tools.d.ts +187 -0
  234. package/dist/lib/tools/skills/tools.js +386 -0
  235. package/dist/lib/tools/taskTools.d.ts +15 -15
  236. package/dist/lib/tools/tool.d.ts +354 -0
  237. package/dist/lib/tools/tool.js +304 -0
  238. package/dist/lib/tools/toolContract.d.ts +89 -33
  239. package/dist/lib/tools/toolContract.js +104 -82
  240. package/dist/lib/tools/urlContextTool.d.ts +4 -1
  241. package/dist/lib/tools/urlContextTool.js +6 -2
  242. package/dist/lib/tools/webExtractTool.d.ts +3 -3
  243. package/dist/lib/tools/webExtractTool.js +2 -1
  244. package/dist/lib/tools/webSearchTool.d.ts +7 -10
  245. package/dist/lib/tools/webSearchTool.js +15 -60
  246. package/dist/lib/tools/wikiTools.d.ts +19 -19
  247. package/dist/lib/tools/wikiTools.js +13 -9
  248. package/dist/lib/tools/xApiSearchTool.d.ts +3 -3
  249. package/dist/lib/tools/xApiSearchTool.js +2 -1
  250. package/dist/lib/tools/xSearchTool.d.ts +8 -10
  251. package/dist/lib/tools/xSearchTool.js +12 -63
  252. package/dist/lib/tools/xaiSearchParams.d.ts +41 -0
  253. package/dist/lib/tools/xaiSearchParams.js +126 -0
  254. package/dist/lib/wiki/agentRun.d.ts +12 -0
  255. package/dist/lib/wiki/agentRun.js +74 -35
  256. package/dist/lib/wiki/entities.d.ts +12 -0
  257. package/dist/lib/wiki/entities.js +45 -3
  258. package/dist/lib/workflow/agentNode.d.ts +153 -0
  259. package/dist/lib/workflow/agentNode.js +365 -0
  260. package/dist/lib/workflow/graph.d.ts +178 -0
  261. package/dist/lib/workflow/graph.js +468 -0
  262. package/dist/lib/workflow/nodeEvents.d.ts +50 -0
  263. package/dist/lib/workflow/nodeEvents.js +101 -0
  264. package/dist/lib/workflow/pause.d.ts +122 -0
  265. package/dist/lib/workflow/pause.js +180 -0
  266. package/dist/lib/workflow/resume.d.ts +166 -0
  267. package/dist/lib/workflow/resume.js +441 -0
  268. package/dist/lib/workflow/route.d.ts +58 -0
  269. package/dist/lib/workflow/route.js +69 -0
  270. package/dist/lib/workflow/scheduler.d.ts +418 -0
  271. package/dist/lib/workflow/scheduler.js +756 -0
  272. package/dist/lib/workflow/toolNode.d.ts +127 -0
  273. package/dist/lib/workflow/toolNode.js +236 -0
  274. package/dist/lib/workflow/turn.d.ts +118 -0
  275. package/dist/lib/workflow/turn.js +216 -0
  276. package/dist/lib/workflow.d.ts +33 -11
  277. package/dist/lib/workflow.js +49 -27
  278. package/dist/lib/workflowConfig.d.ts +7 -2
  279. package/dist/lib/workflowConfig.js +7 -12
  280. package/dist/scripts/a2a_server.js +4 -3
  281. package/dist/scripts/assistant_worker.d.ts +2 -1
  282. package/dist/scripts/assistant_worker.js +9 -4
  283. package/dist/scripts/doctor.d.ts +3 -1
  284. package/dist/scripts/doctor.js +4 -2
  285. package/dist/scripts/syndicate_chat.js +19 -10
  286. package/package.json +9 -3
  287. package/skills/briefs/melchizedek-author.md +3 -2
  288. package/skills/briefs/melchizedek-models.md +13 -9
  289. package/skills/briefs/melchizedek.md +3 -3
  290. package/skills/melchizedek/SKILL.md +2 -1
  291. package/skills/melchizedek-author/SKILL.md +2 -1
  292. package/skills/melchizedek-author/assets/minimal.yaml +2 -0
  293. package/skills/melchizedek-models/SKILL.md +23 -6
@@ -0,0 +1,111 @@
1
+ /**
2
+ * lib/compileNative.ts — an AgentSpec as the native runtime runs it: the
3
+ * NativeAgent the agent loop takes (ADR 0045, ADR 0073).
4
+ *
5
+ * WHY this file exists:
6
+ * lib/compile.ts turns a YAML agent into a runtime-neutral AgentSpec, and
7
+ * lib/compileAdk.ts builds ADK's LlmAgent from it. This file builds the
8
+ * native loop's agent from the same spec (lib/runtime/native/request.ts,
9
+ * NativeAgent), so both runtimes run the agent the YAML describes, with
10
+ * the same tools, instruction and config. tests/compile.test.ts compiles
11
+ * one spec both ways and requires the same first request.
12
+ *
13
+ * TOOLS: each resolved tool is handed to the loop as the own Tool or
14
+ * InstructionTool behind it (lib/tools/tool.ts), else as itself: an MCP
15
+ * tool, the skills toolset, a gated registry FunctionTool, which the loop
16
+ * runs by shape during the dual period (ADR 0071). A delegated subagent
17
+ * becomes a subagentTool holding its own NativeAgent, which the loop runs as
18
+ * a child loop (lib/runtime/native/delegate.ts, ADR 0074), a nested
19
+ * syndicate as its orchestrator's agent, a nested workflow syndicate as a
20
+ * workflowSubagentTool whose call walks the whole graph (ADR 0098); a remote A2A subagent is the own
21
+ * Tool the ADK runtime's FunctionTool wraps (lib/a2a/remoteAgent.ts).
22
+ *
23
+ * EVERY AGENT KEY COMPILES for the native loop: `context:` is handed to
24
+ * the loop, which compacts as ADK does (lib/runtime/native/compaction.ts,
25
+ * WS2-9); `mode: task` and `code_execution: gemini` pass through, the
26
+ * request declaring finish_task (lib/runtime/native/taskMode.ts) and asking
27
+ * Gemini for its code-execution tool (lib/runtime/native/request.ts). What
28
+ * native does not run yet (workflows, resuming an approval or a
29
+ * question, a caller's agent transform) is refused by the turn runner
30
+ * (lib/runtime/nativeTurn.ts), which owns those choices.
31
+ *
32
+ * THE MODEL: the loop calls a model through its contract adapter. A
33
+ * resolver may return an id, a contract adapter, an ADK shim (which carries
34
+ * one) or ADK's Gemini (TracedGemini), whose key reaches the registry's
35
+ * Gemini adapter. Any other ADK model class has no adapter behind it, so
36
+ * compileNative and nativeAdapterFor refuse it with UnsupportedOnRuntimeError
37
+ * before any model call, naming adkShim as the way to run it on native,
38
+ * rather than run the registry's model for that id in its place (ADR 0088).
39
+ * ADK classes are told apart by ADK's own Symbol.for marks, so this file
40
+ * imports nothing from ADK.
41
+ */
42
+ import type { AgentSpec, CompileOptions, WorkflowSpec } from './compile.ts';
43
+ import type { SubagentYamlConfig, SyndicateYamlConfig } from './loadSyndicate.ts';
44
+ import type { ModelAdapter } from './models/contract.ts';
45
+ import type { WorkflowSubagent } from './runtime/native/delegate.ts';
46
+ import type { NativeAgent } from './runtime/native/request.ts';
47
+ export { UnsupportedOnRuntimeError, unsupportedOnNative } from './runtime/runtimeFlag.ts';
48
+ import type { WorkflowGraph } from './workflow/graph.ts';
49
+ /**
50
+ * The class name of an ADK model the native runtime cannot run, else
51
+ * undefined: an ADK BaseLlm that is neither ADK's Gemini (TracedGemini
52
+ * included) nor a shim carrying a contract adapter (lib/models/adkShim.ts).
53
+ */
54
+ export declare function unrunnableModelClass(resolved: unknown): string | undefined;
55
+ /**
56
+ * The NativeAgent for `spec`. Throws when no model id is known, and
57
+ * UnsupportedOnRuntimeError when the resolver returned an ADK model class
58
+ * the loop cannot call (see the header).
59
+ */
60
+ export declare function compileNative(spec: AgentSpec): NativeAgent;
61
+ /**
62
+ * The model id a request is sent under, as ADK's LlmAgent sends it: the id
63
+ * of the model object the resolver returned (an ADK model or a contract
64
+ * adapter carries its own), else the id the resolver returned, else the
65
+ * spec's. A resolver may answer a YAML id with a model under another id (a
66
+ * gateway stand-in, a caller's alias); the adapter, the span and the
67
+ * circuit breaker then see that id on both runtimes.
68
+ */
69
+ export declare function wireModelOf(spec: Pick<AgentSpec, 'modelId' | 'resolvedModel'>): string | undefined;
70
+ /** A syndicate's orchestrator for the native loop: compileSpec, then compileNative. */
71
+ export declare function compileNativeGraph(config: SyndicateYamlConfig, opts?: CompileOptions): Promise<NativeAgent>;
72
+ /** A workflow syndicate for the native walk (lib/workflow/turn.ts): its graph, every agent by YAML name, and the tool nodes' lookup. */
73
+ export interface NativeWorkflow {
74
+ name: string;
75
+ description: string;
76
+ graph: WorkflowGraph;
77
+ agents: Map<string, NativeAgent>;
78
+ resolveTool: (name: string) => unknown;
79
+ }
80
+ /**
81
+ * A workflow spec for the native walk: the graph, every agent compiled for
82
+ * native from the same specs ADK's assembleWorkflow builds its agents from,
83
+ * and the registry's lookup for tool nodes. A tool node ADK's compile
84
+ * refuses (an unregistered or long-running tool) is refused here, before
85
+ * any model call, with ADK's message.
86
+ */
87
+ export declare function compileNativeWorkflow(spec: WorkflowSpec): NativeWorkflow;
88
+ /**
89
+ * A nested workflow as the delegated subagent the native loop calls (ADR
90
+ * 0098): one call walks the whole graph with runNativeWorkflow on the child
91
+ * session lib/runtime/native/delegate.ts opened, as ADK's AgentTool runs a
92
+ * Workflow on its own Runner.
93
+ */
94
+ export declare function workflowSubagentOf(workflow: NativeWorkflow): WorkflowSubagent;
95
+ /** One subagent entry (a dispatch route) for the native loop: compileSubagentSpec, then compileNative. */
96
+ export declare function compileNativeSubagent(subCfg: SubagentYamlConfig, opts?: CompileOptions): Promise<NativeAgent>;
97
+ /** What nativeAdapterFor reads from a spec: its model resolution, the other ids it calls, and its delegated subagents. */
98
+ type NativeModelSpec = Pick<AgentSpec, 'modelId' | 'resolvedModel'> & Partial<Pick<AgentSpec, 'name' | 'fallbackModel' | 'context' | 'tools'>>;
99
+ /**
100
+ * The loop's `adapterFor` under the same model resolution the ADK runtime
101
+ * uses: the leaf adapter behind what CompileOptions.resolveModel returns
102
+ * (an ADK shim carries its contract adapter, so a caller's BYOK key on a
103
+ * shimmed provider reaches the call), else resolveAdapter for the id
104
+ * (lib/models/registry.ts). The spec's own resolution, and each delegated
105
+ * subagent's, is reused for the id its agent runs under (wireModelOf).
106
+ * Each agent's `fallback_model:` and compaction `summary_model` are
107
+ * resolved here, as compileAdk resolves them at compile time, so a model
108
+ * class native cannot run is refused before any model call; any other id
109
+ * is resolved when first asked for. Each is kept.
110
+ */
111
+ export declare function nativeAdapterFor(opts?: CompileOptions, spec?: NativeModelSpec | readonly NativeModelSpec[]): (model: string) => ModelAdapter;
@@ -0,0 +1,278 @@
1
+ /**
2
+ * lib/compileNative.ts — an AgentSpec as the native runtime runs it: the
3
+ * NativeAgent the agent loop takes (ADR 0045, ADR 0073).
4
+ *
5
+ * WHY this file exists:
6
+ * lib/compile.ts turns a YAML agent into a runtime-neutral AgentSpec, and
7
+ * lib/compileAdk.ts builds ADK's LlmAgent from it. This file builds the
8
+ * native loop's agent from the same spec (lib/runtime/native/request.ts,
9
+ * NativeAgent), so both runtimes run the agent the YAML describes, with
10
+ * the same tools, instruction and config. tests/compile.test.ts compiles
11
+ * one spec both ways and requires the same first request.
12
+ *
13
+ * TOOLS: each resolved tool is handed to the loop as the own Tool or
14
+ * InstructionTool behind it (lib/tools/tool.ts), else as itself: an MCP
15
+ * tool, the skills toolset, a gated registry FunctionTool, which the loop
16
+ * runs by shape during the dual period (ADR 0071). A delegated subagent
17
+ * becomes a subagentTool holding its own NativeAgent, which the loop runs as
18
+ * a child loop (lib/runtime/native/delegate.ts, ADR 0074), a nested
19
+ * syndicate as its orchestrator's agent, a nested workflow syndicate as a
20
+ * workflowSubagentTool whose call walks the whole graph (ADR 0098); a remote A2A subagent is the own
21
+ * Tool the ADK runtime's FunctionTool wraps (lib/a2a/remoteAgent.ts).
22
+ *
23
+ * EVERY AGENT KEY COMPILES for the native loop: `context:` is handed to
24
+ * the loop, which compacts as ADK does (lib/runtime/native/compaction.ts,
25
+ * WS2-9); `mode: task` and `code_execution: gemini` pass through, the
26
+ * request declaring finish_task (lib/runtime/native/taskMode.ts) and asking
27
+ * Gemini for its code-execution tool (lib/runtime/native/request.ts). What
28
+ * native does not run yet (workflows, resuming an approval or a
29
+ * question, a caller's agent transform) is refused by the turn runner
30
+ * (lib/runtime/nativeTurn.ts), which owns those choices.
31
+ *
32
+ * THE MODEL: the loop calls a model through its contract adapter. A
33
+ * resolver may return an id, a contract adapter, an ADK shim (which carries
34
+ * one) or ADK's Gemini (TracedGemini), whose key reaches the registry's
35
+ * Gemini adapter. Any other ADK model class has no adapter behind it, so
36
+ * compileNative and nativeAdapterFor refuse it with UnsupportedOnRuntimeError
37
+ * before any model call, naming adkShim as the way to run it on native,
38
+ * rather than run the registry's model for that id in its place (ADR 0088).
39
+ * ADK classes are told apart by ADK's own Symbol.for marks, so this file
40
+ * imports nothing from ADK.
41
+ */
42
+ import { remoteAgentOwnTool } from './a2a/remoteAgent.js';
43
+ import { compileSpec, compileSubagentSpec } from './compile.js';
44
+ import { providerForModel, resolveAdapter } from './models/registry.js';
45
+ import { subagentTool, workflowSubagentTool } from './runtime/native/delegate.js';
46
+ import { servedThroughShim } from './runtime/native/selfCorrection.js';
47
+ import { unsupportedOnNative } from './runtime/runtimeFlag.js';
48
+ export { UnsupportedOnRuntimeError, unsupportedOnNative } from './runtime/runtimeFlag.js';
49
+ import { instructionToolOf, toolOf, toolsetOf } from './tools/tool.js';
50
+ import { buildWorkflowGraph } from './workflow/graph.js';
51
+ import { refuseUnrunnableNodes, runNativeWorkflow } from './workflow/turn.js';
52
+ /** A resolved tool as the loop holds it: the own Tool, InstructionTool or Toolset behind it, else the object itself. */
53
+ function nativeTool(tool) {
54
+ return toolOf(tool) ?? instructionToolOf(tool) ?? toolsetOf(tool) ?? tool;
55
+ }
56
+ /** ADK's own marks on its model classes (BaseLlm, Gemini), registered with Symbol.for so they hold across copies of ADK. */
57
+ const ADK_BASE_MODEL = Symbol.for('google.adk.baseModel');
58
+ const ADK_GEMINI_MODEL = Symbol.for('google.adk.geminiModel');
59
+ const marked = (value, mark) => !!value && typeof value === 'object' && value[mark] === true;
60
+ /**
61
+ * The class name of an ADK model the native runtime cannot run, else
62
+ * undefined: an ADK BaseLlm that is neither ADK's Gemini (TracedGemini
63
+ * included) nor a shim carrying a contract adapter (lib/models/adkShim.ts).
64
+ */
65
+ export function unrunnableModelClass(resolved) {
66
+ if (!marked(resolved, ADK_BASE_MODEL) || marked(resolved, ADK_GEMINI_MODEL))
67
+ return undefined;
68
+ if (isModelAdapter(resolved.adapter))
69
+ return undefined;
70
+ const name = resolved.constructor?.name;
71
+ return typeof name === 'string' && name ? name : 'BaseLlm';
72
+ }
73
+ /** Throws UnsupportedOnRuntimeError when `resolved` is an ADK model class native cannot run (see the header). */
74
+ function refuseModelClass(resolved, modelId, where) {
75
+ const name = unrunnableModelClass(resolved);
76
+ if (!name)
77
+ return;
78
+ throw unsupportedOnNative(`the ADK model class ${name} that resolveModel returned${modelId ? ` for '${modelId}'` : ''}, which has no contract adapter behind it ` +
79
+ `(return the ModelAdapter itself, or adkShim(adapter) from melchizedek-agents/models/adkShim, to run it on native)`, where);
80
+ }
81
+ /**
82
+ * The NativeAgent for `spec`. Throws when no model id is known, and
83
+ * UnsupportedOnRuntimeError when the resolver returned an ADK model class
84
+ * the loop cannot call (see the header).
85
+ */
86
+ export function compileNative(spec) {
87
+ refuseModelClass(spec.resolvedModel, spec.model ?? spec.modelId, spec.name);
88
+ const tools = [];
89
+ for (const entry of spec.tools) {
90
+ if (entry.kind === 'agent')
91
+ tools.push(subagentTool(compileNative(entry.agent)));
92
+ else if (entry.kind === 'workflow')
93
+ tools.push(workflowSubagentTool(workflowSubagentOf(compileNativeWorkflow(entry.workflow))));
94
+ else if (entry.kind === 'remote')
95
+ tools.push(remoteAgentOwnTool({ name: entry.name, description: entry.description, url: entry.url }));
96
+ else
97
+ tools.push(nativeTool(entry.tool));
98
+ }
99
+ const model = wireModelOf(spec);
100
+ if (!model)
101
+ throw new Error(`${spec.name}: no model id to run on (the YAML names none and the resolver returned none).`);
102
+ const agent = {
103
+ name: spec.name,
104
+ model,
105
+ instruction: spec.instruction,
106
+ tools,
107
+ generateContentConfig: spec.generateContentConfig,
108
+ };
109
+ if (spec.description)
110
+ agent.description = spec.description;
111
+ if (spec.globalInstruction !== undefined)
112
+ agent.globalInstruction = spec.globalInstruction;
113
+ if (spec.outputSchema)
114
+ agent.outputSchema = spec.outputSchema;
115
+ if (spec.includeContents !== undefined)
116
+ agent.includeContents = spec.includeContents;
117
+ if (spec.disallowTransferToParent !== undefined)
118
+ agent.disallowTransferToParent = spec.disallowTransferToParent;
119
+ if (spec.disallowTransferToPeers !== undefined)
120
+ agent.disallowTransferToPeers = spec.disallowTransferToPeers;
121
+ if (spec.codeExecution)
122
+ agent.codeExecution = spec.codeExecution;
123
+ if (spec.mode)
124
+ agent.mode = spec.mode;
125
+ if (spec.outputKey !== undefined)
126
+ agent.outputKey = spec.outputKey;
127
+ if (spec.fallbackModel)
128
+ agent.fallbackModel = spec.fallbackModel;
129
+ if (spec.context)
130
+ agent.context = spec.context;
131
+ return agent;
132
+ }
133
+ /**
134
+ * The model id a request is sent under, as ADK's LlmAgent sends it: the id
135
+ * of the model object the resolver returned (an ADK model or a contract
136
+ * adapter carries its own), else the id the resolver returned, else the
137
+ * spec's. A resolver may answer a YAML id with a model under another id (a
138
+ * gateway stand-in, a caller's alias); the adapter, the span and the
139
+ * circuit breaker then see that id on both runtimes.
140
+ */
141
+ export function wireModelOf(spec) {
142
+ const resolved = spec.resolvedModel;
143
+ if (typeof resolved === 'string' && resolved)
144
+ return resolved;
145
+ const own = resolved && typeof resolved === 'object' ? resolved.model : undefined;
146
+ if (typeof own === 'string' && own)
147
+ return own;
148
+ return spec.modelId;
149
+ }
150
+ /** A syndicate's orchestrator for the native loop: compileSpec, then compileNative. */
151
+ export async function compileNativeGraph(config, opts = {}) {
152
+ return compileNative(await compileSpec(config, opts));
153
+ }
154
+ /**
155
+ * A workflow spec for the native walk: the graph, every agent compiled for
156
+ * native from the same specs ADK's assembleWorkflow builds its agents from,
157
+ * and the registry's lookup for tool nodes. A tool node ADK's compile
158
+ * refuses (an unregistered or long-running tool) is refused here, before
159
+ * any model call, with ADK's message.
160
+ */
161
+ export function compileNativeWorkflow(spec) {
162
+ const graph = buildWorkflowGraph(spec.config);
163
+ const agents = new Map();
164
+ for (const { yaml, spec: agentSpec } of spec.agents)
165
+ agents.set(yaml.name, compileNative(agentSpec));
166
+ refuseUnrunnableNodes(graph, spec.resolveTool);
167
+ return { name: spec.name, description: spec.description, graph, agents, resolveTool: spec.resolveTool };
168
+ }
169
+ /**
170
+ * A nested workflow as the delegated subagent the native loop calls (ADR
171
+ * 0098): one call walks the whole graph with runNativeWorkflow on the child
172
+ * session lib/runtime/native/delegate.ts opened, as ADK's AgentTool runs a
173
+ * Workflow on its own Runner.
174
+ */
175
+ export function workflowSubagentOf(workflow) {
176
+ return {
177
+ name: workflow.name,
178
+ ...(workflow.description ? { description: workflow.description } : {}),
179
+ walk: (run) => runNativeWorkflow({
180
+ graph: workflow.graph,
181
+ agents: workflow.agents,
182
+ resolveTool: workflow.resolveTool,
183
+ sessions: run.sessions,
184
+ appName: run.appName,
185
+ userId: run.userId,
186
+ sessionId: run.sessionId,
187
+ userParts: run.userParts,
188
+ adapterFor: run.adapterFor,
189
+ selfCorrection: run.selfCorrection,
190
+ stream: false,
191
+ ...(run.signal ? { signal: run.signal } : {}),
192
+ ...(run.memory ? { memory: run.memory } : {}),
193
+ ...(run.log ? { log: run.log } : {}),
194
+ ...(run.credentials ? { credentials: run.credentials } : {}),
195
+ }),
196
+ };
197
+ }
198
+ /** One subagent entry (a dispatch route) for the native loop: compileSubagentSpec, then compileNative. */
199
+ export async function compileNativeSubagent(subCfg, opts = {}) {
200
+ return compileNative(await compileSubagentSpec(subCfg, opts));
201
+ }
202
+ function isModelAdapter(value) {
203
+ return !!value && typeof value === 'object' && typeof value.generate === 'function' && typeof value.model === 'string';
204
+ }
205
+ /**
206
+ * The contract adapter behind what a resolver returned: an ADK shim's own
207
+ * adapter; for an ADK class that is not a shim (TracedGemini, ADK's Gemini)
208
+ * the registry's adapter under the key the instance carries, so a caller's
209
+ * BYOK key still pays for the call; else the registry's for the id.
210
+ */
211
+ function adapterOf(resolved, model) {
212
+ if (isModelAdapter(resolved))
213
+ return resolved;
214
+ refuseModelClass(resolved, model, 'the native runtime');
215
+ if (typeof resolved === 'string')
216
+ return resolveAdapter(resolved || model);
217
+ if (!resolved || typeof resolved !== 'object')
218
+ return resolveAdapter(model);
219
+ const held = resolved;
220
+ // On ADK a shim declares the toolsDict, the reflection tool included, whatever its adapter (ADR 0097).
221
+ if (isModelAdapter(held.adapter))
222
+ return servedThroughShim(held.adapter);
223
+ // On Vertex AI the client authenticates with the platform's credentials, never a key (ADR 0023).
224
+ if (typeof held.apiKey === 'string' && held.apiKey && held.vertexai !== true) {
225
+ return resolveAdapter(model, { apiKey: held.apiKey, keyProvider: providerForModel(model) });
226
+ }
227
+ return resolveAdapter(model);
228
+ }
229
+ /**
230
+ * The loop's `adapterFor` under the same model resolution the ADK runtime
231
+ * uses: the leaf adapter behind what CompileOptions.resolveModel returns
232
+ * (an ADK shim carries its contract adapter, so a caller's BYOK key on a
233
+ * shimmed provider reaches the call), else resolveAdapter for the id
234
+ * (lib/models/registry.ts). The spec's own resolution, and each delegated
235
+ * subagent's, is reused for the id its agent runs under (wireModelOf).
236
+ * Each agent's `fallback_model:` and compaction `summary_model` are
237
+ * resolved here, as compileAdk resolves them at compile time, so a model
238
+ * class native cannot run is refused before any model call; any other id
239
+ * is resolved when first asked for. Each is kept.
240
+ */
241
+ export function nativeAdapterFor(opts = {}, spec) {
242
+ const cache = new Map();
243
+ const known = new Map();
244
+ const learn = (s) => {
245
+ if (s.resolvedModel !== undefined) {
246
+ for (const id of [wireModelOf(s), s.modelId])
247
+ if (id && !known.has(id))
248
+ known.set(id, s.resolvedModel);
249
+ }
250
+ for (const id of [s.fallbackModel, s.context?.summary_model]) {
251
+ if (!id || known.has(id) || !opts.resolveModel)
252
+ continue;
253
+ const resolved = opts.resolveModel(id);
254
+ refuseModelClass(resolved, id, s.name ?? 'the native runtime');
255
+ known.set(id, resolved);
256
+ }
257
+ for (const entry of s.tools ?? []) {
258
+ if (entry.kind === 'agent')
259
+ learn(entry.agent);
260
+ // A nested workflow's agents run under the caller's lookup (ADR 0098).
261
+ else if (entry.kind === 'workflow')
262
+ for (const node of entry.workflow.agents)
263
+ learn(node.spec);
264
+ }
265
+ };
266
+ // A workflow's agents share one lookup: every node's spec is learned.
267
+ for (const s of spec === undefined ? [] : Array.isArray(spec) ? spec : [spec])
268
+ learn(s);
269
+ return (model) => {
270
+ const held = cache.get(model);
271
+ if (held)
272
+ return held;
273
+ const resolved = known.has(model) ? known.get(model) : opts.resolveModel ? opts.resolveModel(model) : model;
274
+ const adapter = adapterOf(resolved, model);
275
+ cache.set(model, adapter);
276
+ return adapter;
277
+ };
278
+ }
@@ -52,11 +52,12 @@ export declare const DEFAULT_GPT_MODEL = "gpt-5-mini";
52
52
  */
53
53
  export declare const DEFAULT_GROK_MODEL = "grok-4.7";
54
54
  /**
55
- * Reasoning effort sent with grok-4.5/4.7 requests: 'low' | 'medium' | 'high'
56
- * (xAI's own default is 'high'; 4.7 adds 'xhigh'). Pinned to MEDIUM — deeper
57
- * than low without high's latency and token cost. Source: docs.x.ai › Model
58
- * capabilities › Text › Reasoning › Effort levels. Older grok ids don't
59
- * accept the param and never receive it (lib/models/grokLlm.ts).
55
+ * Reasoning effort sent with grok-4.5, 4.6 and 4.7 requests that set no
56
+ * `reasoning:`: 'low' | 'medium' | 'high' (xAI's own default is 'high'; 4.7
57
+ * adds 'xhigh'). Pinned to MEDIUM — deeper than low without high's latency
58
+ * and token cost. Source: docs.x.ai › Model capabilities › Text › Reasoning ›
59
+ * Effort levels. Older grok ids don't accept the param and never receive it
60
+ * (lib/models/grokAdapter.ts).
60
61
  */
61
62
  export declare const DEFAULT_GROK_REASONING_EFFORT = "medium";
62
63
  /**
@@ -53,11 +53,12 @@ export const DEFAULT_GPT_MODEL = 'gpt-5-mini';
53
53
  */
54
54
  export const DEFAULT_GROK_MODEL = 'grok-4.7';
55
55
  /**
56
- * Reasoning effort sent with grok-4.5/4.7 requests: 'low' | 'medium' | 'high'
57
- * (xAI's own default is 'high'; 4.7 adds 'xhigh'). Pinned to MEDIUM — deeper
58
- * than low without high's latency and token cost. Source: docs.x.ai › Model
59
- * capabilities › Text › Reasoning › Effort levels. Older grok ids don't
60
- * accept the param and never receive it (lib/models/grokLlm.ts).
56
+ * Reasoning effort sent with grok-4.5, 4.6 and 4.7 requests that set no
57
+ * `reasoning:`: 'low' | 'medium' | 'high' (xAI's own default is 'high'; 4.7
58
+ * adds 'xhigh'). Pinned to MEDIUM — deeper than low without high's latency
59
+ * and token cost. Source: docs.x.ai › Model capabilities › Text › Reasoning ›
60
+ * Effort levels. Older grok ids don't accept the param and never receive it
61
+ * (lib/models/grokAdapter.ts).
61
62
  */
62
63
  export const DEFAULT_GROK_REASONING_EFFORT = 'medium';
63
64
  /**
@@ -18,11 +18,15 @@
18
18
  * The routing and capability judgments are not re-implemented here: they
19
19
  * come from lib/models/gateway.ts and lib/models/capabilities.ts, the same
20
20
  * modules the registry and the A2A server use, so the report cannot
21
- * disagree with what a run would do.
21
+ * disagree with what a run would do. The runtime line comes from
22
+ * lib/runtime/runtimeFlag.ts, which a turn reads (ADR 0102); whether
23
+ * @google/adk is installed is a module resolution, so the doctor never
24
+ * loads ADK to answer it.
22
25
  */
23
26
  import type { Platform } from './models/endpoints.ts';
24
27
  import type { CapabilityGap, CapabilityReport } from './models/capabilities.ts';
25
28
  import type { ProviderId } from './models/providerMap.ts';
29
+ import type { RuntimeName, RuntimeSource } from './runtime/runtimeFlag.ts';
26
30
  /**
27
31
  * What a file costs to run: `keyless` (all Ollama), a single provider's id
28
32
  * when every agent shares one (`gemini`, `anthropic`, `openai`, `xai` — one
@@ -81,8 +85,25 @@ export interface Unlock {
81
85
  /** Syndicates this one variable would move from blocked to ready. */
82
86
  syndicates: string[];
83
87
  }
88
+ /** The runtime a turn would run on here, where that came from, and the optional ADK peer (ADR 0102). */
89
+ export interface DoctorRuntime {
90
+ /** The runtime in use; undefined when MELCHIZEDEK_RUNTIME holds a value no turn accepts (`problem` says so). */
91
+ runtime?: RuntimeName;
92
+ /** Where it came from: MELCHIZEDEK_RUNTIME, or the default (a turn's own option is the caller's, not the environment's). */
93
+ source?: RuntimeSource;
94
+ /** @google/adk: whether it resolves from here, its version, and whether the runtime in use needs it. */
95
+ adk: {
96
+ installed: boolean;
97
+ version?: string;
98
+ needed: boolean;
99
+ };
100
+ /** Why no turn would run as configured, if none would. */
101
+ problem?: string;
102
+ }
84
103
  export interface DoctorResult {
85
104
  agentsDir: string;
105
+ /** The runtime in use and whether @google/adk is installed. */
106
+ runtime: DoctorRuntime;
86
107
  syndicates: DoctorSyndicate[];
87
108
  unlocks: Unlock[];
88
109
  gateway: {
@@ -110,6 +131,12 @@ export interface DoctorEndpoint {
110
131
  /** Cloud platforms are tested against mocks only (ADR 0023). */
111
132
  liveVerified: boolean;
112
133
  }
134
+ /**
135
+ * The runtime a turn would run on under this environment (lib/runtime/
136
+ * runtimeFlag.ts), where that came from, and whether @google/adk resolves.
137
+ * `adk` without the package is a problem: every turn would fail.
138
+ */
139
+ export declare function runtimeReport(env?: NodeJS.ProcessEnv, adkResolvable?: (module: string) => boolean): DoctorRuntime;
113
140
  /** One row per provider that is not on its vendor's public API with an env key. */
114
141
  export declare function endpointRows(): DoctorEndpoint[];
115
142
  export declare const CONSOLE_URLS: Record<ProviderId, string>;
@@ -18,7 +18,10 @@
18
18
  * The routing and capability judgments are not re-implemented here: they
19
19
  * come from lib/models/gateway.ts and lib/models/capabilities.ts, the same
20
20
  * modules the registry and the A2A server use, so the report cannot
21
- * disagree with what a run would do.
21
+ * disagree with what a run would do. The runtime line comes from
22
+ * lib/runtime/runtimeFlag.ts, which a turn reads (ADR 0102); whether
23
+ * @google/adk is installed is a module resolution, so the doctor never
24
+ * loads ADK to answer it.
22
25
  */
23
26
  import fs from 'node:fs';
24
27
  import path from 'node:path';
@@ -30,6 +33,7 @@ import { CAPABILITY_LABELS, capabilityGaps, describeCapabilities } from './model
30
33
  import { credentialSource, endpointFromEnv, endpointLabel, endpointProblems, PLATFORM_SDK, PLATFORMS_FOR } from './models/endpoints.js';
31
34
  import { GATEWAY_ENV, GATEWAY_KEY_ENV, GATEWAYS, gatewayConfig, gatewayProblem, gatewayUsable, } from './models/gateway.js';
32
35
  import { PROVIDERS } from './models/providerMap.js';
36
+ import { describeRuntime } from './runtime/runtimeFlag.js';
33
37
  function resolvable(module) {
34
38
  try {
35
39
  createRequire(import.meta.url).resolve(module);
@@ -39,6 +43,52 @@ function resolvable(module) {
39
43
  return false;
40
44
  }
41
45
  }
46
+ /** The installed version of a package that resolves from here, read from its package.json (its exports map may hide it). */
47
+ function installedVersion(module) {
48
+ try {
49
+ let dir = path.dirname(createRequire(import.meta.url).resolve(module));
50
+ for (let i = 0; i < 8; i++) {
51
+ const file = path.join(dir, 'package.json');
52
+ if (fs.existsSync(file)) {
53
+ const pkg = JSON.parse(fs.readFileSync(file, 'utf8'));
54
+ if (pkg.name === module)
55
+ return pkg.version;
56
+ }
57
+ const up = path.dirname(dir);
58
+ if (up === dir)
59
+ break;
60
+ dir = up;
61
+ }
62
+ }
63
+ catch {
64
+ // Not resolvable, or unreadable: no version to report.
65
+ }
66
+ return undefined;
67
+ }
68
+ /** The ADK peer, as an install command names it. */
69
+ const ADK_PEER = '@google/adk';
70
+ /**
71
+ * The runtime a turn would run on under this environment (lib/runtime/
72
+ * runtimeFlag.ts), where that came from, and whether @google/adk resolves.
73
+ * `adk` without the package is a problem: every turn would fail.
74
+ */
75
+ export function runtimeReport(env = process.env, adkResolvable = resolvable) {
76
+ const installed = adkResolvable(ADK_PEER);
77
+ const adk = { installed, ...(installed && installedVersion(ADK_PEER) ? { version: installedVersion(ADK_PEER) } : {}) };
78
+ let chosen;
79
+ try {
80
+ chosen = describeRuntime(undefined, env);
81
+ }
82
+ catch (err) {
83
+ return { adk: { ...adk, needed: false }, problem: err instanceof Error ? err.message : String(err) };
84
+ }
85
+ const needed = chosen.runtime === 'adk';
86
+ return {
87
+ ...chosen,
88
+ adk: { ...adk, needed },
89
+ ...(needed && !installed ? { problem: `MELCHIZEDEK_RUNTIME=adk needs ${ADK_PEER}, which is not installed: npm install ${ADK_PEER}@~2.2.0, or unset MELCHIZEDEK_RUNTIME to run on native` } : {}),
90
+ };
91
+ }
42
92
  /** One row per provider that is not on its vendor's public API with an env key. */
43
93
  export function endpointRows() {
44
94
  const rows = [];
@@ -155,6 +205,7 @@ function needsOf(agent, delegates = false) {
155
205
  tools: agent.tools ?? [],
156
206
  outputSchema: agent.outputSchema,
157
207
  generateContentConfig: agent.generateContentConfig,
208
+ reasoning: agent.reasoning,
158
209
  delegates,
159
210
  };
160
211
  }
@@ -380,7 +431,7 @@ export function runDoctor(options = {}) {
380
431
  for (const s of syndicates)
381
432
  counts[s.verdict.state]++;
382
433
  flagMemoryNamespaces(syndicates);
383
- return { agentsDir, syndicates, unlocks, gateway, endpoints: endpointRows(), counts };
434
+ return { agentsDir, runtime: runtimeReport(), syndicates, unlocks, gateway, endpoints: endpointRows(), counts };
384
435
  }
385
436
  // ── Rendering ────────────────────────────────────────────────────────────────
386
437
  const ANSI = {
@@ -416,6 +467,17 @@ export function renderDoctor(result, opts = {}) {
416
467
  : `${c.green}${text}${c.reset}`;
417
468
  lines.push(`${c.bold}melchizedek doctor${c.reset} ${c.dim}· ${result.agentsDir}${c.reset}`);
418
469
  lines.push('');
470
+ // The runtime a turn would run on, where that came from, and the ADK peer (ADR 0102).
471
+ if (result.runtime) {
472
+ const rt = result.runtime;
473
+ const adk = rt.adk.installed
474
+ ? `${ADK_PEER} ${rt.adk.version ?? ''}`.trimEnd() + ' installed'
475
+ : `${ADK_PEER} not installed${rt.adk.needed ? '' : ' (needed only for MELCHIZEDEK_RUNTIME=adk)'}`;
476
+ const source = rt.source === 'default' ? 'the default' : rt.source;
477
+ lines.push(rt.problem
478
+ ? `runtime ${c.red}✗${c.reset} ${rt.runtime ? `${rt.runtime} ${c.dim}(${source})${c.reset} · ` : ''}${c.red}${rt.problem}${c.reset}`
479
+ : `runtime ${c.green}✓${c.reset} ${rt.runtime} ${c.dim}(${source})${c.reset} · ${c.dim}${adk}${c.reset}`);
480
+ }
419
481
  // Provider line: what is funded, and how. Each provider is probed with an
420
482
  // id of its own prefix, so the line names ITS key (a fallthrough once put
421
483
  // xAI's key beside Moonshot).
@@ -14,6 +14,10 @@
14
14
  export { loadSyndicate, loadSyndicateFromRegistry, parseCliBindings, validateRegistryConfig, } from './loadSyndicate.ts';
15
15
  export type { AgentYamlConfig, LoadSyndicateOptions, SubagentYamlConfig, SyndicateYamlConfig, VariableMap, } from './loadSyndicate.ts';
16
16
  export { runSyndicateTurn, ingestTurnMemory } from './runtime/syndicateTurn.ts';
17
+ export { DEFAULT_RUNTIME, describeRuntime, AdkNotInstalledError, adkInstalled } from './runtime/syndicateTurn.ts';
18
+ export type { RuntimeName, RuntimeSource } from './runtime/syndicateTurn.ts';
19
+ export { InProcessSessionService } from './runtime/sessions.ts';
20
+ export { asAdkSessionService, asSessionService } from './runtime/adkSessionBridge.ts';
17
21
  export { approvalResponsePart, pendingApproval, APPROVAL_REQUEST } from './runtime/approvals.ts';
18
22
  export type { PendingApproval } from './runtime/approvals.ts';
19
23
  export type { DrainedRun, MessagePart, TurnUsage, RouteDecision, SyndicateTurnOptions, SyndicateTurnResult, TraceOptions, TurnEvents, TurnStage, } from './runtime/syndicateTurn.ts';
@@ -37,7 +41,8 @@ export type { RemoteAnswer } from './a2a/remoteAgent.ts';
37
41
  export { resolveTools, registerTool, registeredToolNames } from './toolRegistry.ts';
38
42
  export { registerGuard, resolveGuards } from './guards/index.ts';
39
43
  export type { Guard, GuardResult } from './guards/index.ts';
40
- export { defineTool, toFunctionTool } from './tools/toolContract.ts';
44
+ export { defineTool } from './tools/toolContract.ts';
45
+ export { toFunctionTool } from './tools/adkTool.ts';
41
46
  export { modelExtractor, geminiEmbedder, openAiCompatibleEmbedder, memoryProvidersFromEnv, } from './memory/providers.ts';
42
47
  export type { Embedder, MemoryExtractor } from './memory/providers.ts';
43
48
  export { eraseScope } from './memory/erase.ts';
package/dist/lib/index.js CHANGED
@@ -15,6 +15,11 @@
15
15
  export { loadSyndicate, loadSyndicateFromRegistry, parseCliBindings, validateRegistryConfig, } from './loadSyndicate.js';
16
16
  // ── Run it ──────────────────────────────────────────────────────────────────
17
17
  export { runSyndicateTurn, ingestTurnMemory } from './runtime/syndicateTurn.js';
18
+ // The runtime in use (native by default since 0.20.0) and the optional ADK peer (ADR 0102).
19
+ export { DEFAULT_RUNTIME, describeRuntime, AdkNotInstalledError, adkInstalled } from './runtime/syndicateTurn.js';
20
+ // An in-process session store that needs no ADK; runSyndicateTurn takes it through asAdkSessionService.
21
+ export { InProcessSessionService } from './runtime/sessions.js';
22
+ export { asAdkSessionService, asSessionService } from './runtime/adkSessionBridge.js';
18
23
  export { approvalResponsePart, pendingApproval, APPROVAL_REQUEST } from './runtime/approvals.js';
19
24
  export { compileGraph, compileSubagent } from './compile.js';
20
25
  export { compileWorkflow, isWorkflowSyndicate, describeInput } from './workflow.js';
@@ -28,7 +33,8 @@ export { RemoteA2AAgent, remoteAgentTool } from './a2a/remoteAgent.js';
28
33
  // ── Extend it ───────────────────────────────────────────────────────────────
29
34
  export { resolveTools, registerTool, registeredToolNames } from './toolRegistry.js';
30
35
  export { registerGuard, resolveGuards } from './guards/index.js';
31
- export { defineTool, toFunctionTool } from './tools/toolContract.js';
36
+ export { defineTool } from './tools/toolContract.js';
37
+ export { toFunctionTool } from './tools/adkTool.js';
32
38
  // ── Memory ──────────────────────────────────────────────────────────────────
33
39
  export { modelExtractor, geminiEmbedder, openAiCompatibleEmbedder, memoryProvidersFromEnv, } from './memory/providers.js';
34
40
  export { eraseScope } from './memory/erase.js';