melchizedek-agents 0.20.0 → 1.0.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 (207) hide show
  1. package/.env.example +4 -5
  2. package/AGENT_SETUP.md +3 -3
  3. package/CHANGELOG.md +240 -0
  4. package/DOCUMENTATION.md +142 -150
  5. package/QUICKSTART.md +12 -11
  6. package/README.md +11 -11
  7. package/config/agents/examples/image_production.yaml +2 -2
  8. package/config/agents/syndicateSchema.yaml +52 -26
  9. package/dist/lib/a2a/app.d.ts +17 -12
  10. package/dist/lib/a2a/app.js +16 -6
  11. package/dist/lib/a2a/executor.d.ts +10 -14
  12. package/dist/lib/a2a/executor.js +10 -18
  13. package/dist/lib/a2a/remoteAgent.d.ts +5 -12
  14. package/dist/lib/a2a/remoteAgent.js +5 -12
  15. package/dist/lib/compile.d.ts +76 -86
  16. package/dist/lib/compile.js +100 -116
  17. package/dist/lib/compileNative.d.ts +44 -56
  18. package/dist/lib/compileNative.js +91 -89
  19. package/dist/lib/config.d.ts +6 -6
  20. package/dist/lib/config.js +6 -6
  21. package/dist/lib/doctor.d.ts +8 -14
  22. package/dist/lib/doctor.js +10 -46
  23. package/dist/lib/index.d.ts +12 -9
  24. package/dist/lib/index.js +10 -11
  25. package/dist/lib/loadSyndicate.d.ts +3 -3
  26. package/dist/lib/loadSyndicate.js +2 -2
  27. package/dist/lib/memory/erase.d.ts +1 -1
  28. package/dist/lib/memory/erase.js +1 -1
  29. package/dist/lib/memory/namespace.d.ts +12 -14
  30. package/dist/lib/memory/namespace.js +13 -14
  31. package/dist/lib/memory/providers.d.ts +4 -5
  32. package/dist/lib/memory/providers.js +12 -6
  33. package/dist/lib/memory/supabaseMemoryService.d.ts +9 -30
  34. package/dist/lib/memory/supabaseMemoryService.js +8 -30
  35. package/dist/lib/model.d.ts +6 -12
  36. package/dist/lib/model.js +6 -12
  37. package/dist/lib/models/adapterResolver.d.ts +21 -40
  38. package/dist/lib/models/adapterResolver.js +32 -40
  39. package/dist/lib/models/chatCompletionsAdapter.d.ts +12 -33
  40. package/dist/lib/models/chatCompletionsAdapter.js +13 -18
  41. package/dist/lib/models/circuitBreaker.d.ts +5 -5
  42. package/dist/lib/models/circuitBreaker.js +5 -5
  43. package/dist/lib/models/claudeAdapter.d.ts +9 -26
  44. package/dist/lib/models/claudeAdapter.js +11 -15
  45. package/dist/lib/models/claudeModels.d.ts +4 -4
  46. package/dist/lib/models/claudeModels.js +4 -4
  47. package/dist/lib/models/contract.d.ts +11 -11
  48. package/dist/lib/models/contract.js +6 -6
  49. package/dist/lib/models/errorResponse.d.ts +13 -20
  50. package/dist/lib/models/errorResponse.js +0 -12
  51. package/dist/lib/models/fallbackAdapter.d.ts +7 -8
  52. package/dist/lib/models/gatewayAdapter.d.ts +1 -1
  53. package/dist/lib/models/gatewayAdapter.js +1 -1
  54. package/dist/lib/models/geminiAdapter.d.ts +5 -6
  55. package/dist/lib/models/geminiAdapter.js +9 -10
  56. package/dist/lib/models/geminiState.d.ts +8 -8
  57. package/dist/lib/models/geminiState.js +8 -8
  58. package/dist/lib/models/genaiMapping.d.ts +82 -36
  59. package/dist/lib/models/genaiMapping.js +41 -41
  60. package/dist/lib/models/gptAdapter.d.ts +11 -11
  61. package/dist/lib/models/gptAdapter.js +13 -13
  62. package/dist/lib/models/kimiAdapter.d.ts +6 -7
  63. package/dist/lib/models/kimiAdapter.js +6 -9
  64. package/dist/lib/models/ollamaAdapter.d.ts +3 -3
  65. package/dist/lib/models/ollamaAdapter.js +3 -3
  66. package/dist/lib/models/providerMap.d.ts +6 -5
  67. package/dist/lib/models/providerMap.js +6 -5
  68. package/dist/lib/models/providerState.d.ts +3 -2
  69. package/dist/lib/models/providerState.js +3 -2
  70. package/dist/lib/models/reasoning.d.ts +1 -1
  71. package/dist/lib/models/registry.d.ts +26 -73
  72. package/dist/lib/models/registry.js +31 -144
  73. package/dist/lib/models/retry.d.ts +2 -2
  74. package/dist/lib/models/retry.js +2 -2
  75. package/dist/lib/models/schemaNormalize.d.ts +25 -55
  76. package/dist/lib/models/schemaNormalize.js +30 -100
  77. package/dist/lib/observability/lineage.d.ts +3 -3
  78. package/dist/lib/observability/lineage.js +10 -10
  79. package/dist/lib/observability/supabaseSpanExporter.js +1 -1
  80. package/dist/lib/observability/tracer.d.ts +25 -23
  81. package/dist/lib/observability/tracer.js +26 -63
  82. package/dist/lib/persistence/supabaseProvider.d.ts +4 -3
  83. package/dist/lib/runtime/approvals.d.ts +1 -1
  84. package/dist/lib/runtime/credentials.d.ts +1 -1
  85. package/dist/lib/runtime/events.d.ts +3 -4
  86. package/dist/lib/runtime/events.js +3 -4
  87. package/dist/lib/runtime/logging.d.ts +3 -8
  88. package/dist/lib/runtime/logging.js +3 -8
  89. package/dist/lib/runtime/memoryService.d.ts +4 -6
  90. package/dist/lib/runtime/memoryService.js +3 -5
  91. package/dist/lib/runtime/native/agentLoop.d.ts +18 -16
  92. package/dist/lib/runtime/native/agentLoop.js +38 -26
  93. package/dist/lib/runtime/native/compaction.d.ts +10 -11
  94. package/dist/lib/runtime/native/compaction.js +10 -11
  95. package/dist/lib/runtime/native/delegate.d.ts +13 -14
  96. package/dist/lib/runtime/native/delegate.js +11 -18
  97. package/dist/lib/runtime/native/history.d.ts +5 -6
  98. package/dist/lib/runtime/native/history.js +5 -6
  99. package/dist/lib/runtime/native/interrupts.d.ts +6 -6
  100. package/dist/lib/runtime/native/interrupts.js +6 -6
  101. package/dist/lib/runtime/native/request.d.ts +24 -24
  102. package/dist/lib/runtime/native/request.js +35 -24
  103. package/dist/lib/runtime/native/selfCorrection.d.ts +32 -32
  104. package/dist/lib/runtime/native/selfCorrection.js +34 -34
  105. package/dist/lib/runtime/native/step.d.ts +23 -23
  106. package/dist/lib/runtime/native/step.js +49 -27
  107. package/dist/lib/runtime/native/taskMode.d.ts +8 -8
  108. package/dist/lib/runtime/native/taskMode.js +8 -8
  109. package/dist/lib/runtime/native/telemetry.d.ts +11 -11
  110. package/dist/lib/runtime/native/telemetry.js +11 -11
  111. package/dist/lib/runtime/native/tempState.d.ts +4 -4
  112. package/dist/lib/runtime/native/tempState.js +4 -4
  113. package/dist/lib/runtime/nativeTurn.d.ts +29 -32
  114. package/dist/lib/runtime/nativeTurn.js +30 -41
  115. package/dist/lib/runtime/questions.d.ts +8 -9
  116. package/dist/lib/runtime/questions.js +1 -2
  117. package/dist/lib/runtime/runtimeFlag.d.ts +28 -14
  118. package/dist/lib/runtime/runtimeFlag.js +38 -16
  119. package/dist/lib/runtime/sessions.d.ts +10 -12
  120. package/dist/lib/runtime/sessions.js +10 -12
  121. package/dist/lib/runtime/syndicateTurn.d.ts +44 -45
  122. package/dist/lib/runtime/syndicateTurn.js +163 -158
  123. package/dist/lib/runtime/turnControl.d.ts +8 -8
  124. package/dist/lib/runtime/turnControl.js +8 -8
  125. package/dist/lib/session/supabaseSessionService.d.ts +7 -21
  126. package/dist/lib/session/supabaseSessionService.js +7 -43
  127. package/dist/lib/session/transcript.d.ts +16 -26
  128. package/dist/lib/session/transcript.js +17 -57
  129. package/dist/lib/storage/postgres/sessionService.d.ts +6 -20
  130. package/dist/lib/storage/postgres/sessionService.js +6 -39
  131. package/dist/lib/syndicateSchema.js +7 -6
  132. package/dist/lib/toolRegistry.d.ts +9 -14
  133. package/dist/lib/toolRegistry.js +36 -33
  134. package/dist/lib/tools/auth.d.ts +1 -1
  135. package/dist/lib/tools/auth.js +1 -1
  136. package/dist/lib/tools/examples.d.ts +2 -4
  137. package/dist/lib/tools/examples.js +2 -4
  138. package/dist/lib/tools/generateImageTool.d.ts +3 -3
  139. package/dist/lib/tools/generateImageTool.js +4 -5
  140. package/dist/lib/tools/inspectImageTool.d.ts +2 -2
  141. package/dist/lib/tools/inspectImageTool.js +3 -4
  142. package/dist/lib/tools/mcpToolFactory.d.ts +4 -24
  143. package/dist/lib/tools/mcpToolFactory.js +19 -9
  144. package/dist/lib/tools/memoryTools.d.ts +5 -6
  145. package/dist/lib/tools/memoryTools.js +5 -6
  146. package/dist/lib/tools/nativeTools.d.ts +9 -14
  147. package/dist/lib/tools/nativeTools.js +9 -14
  148. package/dist/lib/tools/openapiTools.d.ts +5 -7
  149. package/dist/lib/tools/openapiTools.js +6 -13
  150. package/dist/lib/tools/scienceTools.d.ts +3 -3
  151. package/dist/lib/tools/scienceTools.js +8 -10
  152. package/dist/lib/tools/skillToolset.d.ts +1 -2
  153. package/dist/lib/tools/skillToolset.js +1 -2
  154. package/dist/lib/tools/skills/executor.d.ts +1 -1
  155. package/dist/lib/tools/skills/executor.js +1 -1
  156. package/dist/lib/tools/skills/frontmatter.d.ts +2 -2
  157. package/dist/lib/tools/skills/frontmatter.js +2 -2
  158. package/dist/lib/tools/skills/tools.d.ts +8 -10
  159. package/dist/lib/tools/skills/tools.js +9 -11
  160. package/dist/lib/tools/tool.d.ts +24 -40
  161. package/dist/lib/tools/tool.js +24 -56
  162. package/dist/lib/tools/toolContract.d.ts +8 -13
  163. package/dist/lib/tools/toolContract.js +6 -17
  164. package/dist/lib/tools/webExtractTool.d.ts +2 -2
  165. package/dist/lib/tools/webExtractTool.js +3 -4
  166. package/dist/lib/tools/wikiTools.d.ts +2 -2
  167. package/dist/lib/tools/wikiTools.js +5 -6
  168. package/dist/lib/tools/xApiSearchTool.d.ts +2 -2
  169. package/dist/lib/tools/xApiSearchTool.js +3 -4
  170. package/dist/lib/tools/xaiSearchParams.d.ts +2 -5
  171. package/dist/lib/tools/xaiSearchParams.js +2 -5
  172. package/dist/lib/wiki/agentRun.d.ts +10 -11
  173. package/dist/lib/wiki/agentRun.js +24 -42
  174. package/dist/lib/workflow/agentNode.d.ts +10 -1
  175. package/dist/lib/workflow/agentNode.js +5 -3
  176. package/dist/lib/workflow/graph.d.ts +8 -9
  177. package/dist/lib/workflow/graph.js +12 -12
  178. package/dist/lib/workflow/nodeEvents.d.ts +5 -5
  179. package/dist/lib/workflow/nodeEvents.js +5 -5
  180. package/dist/lib/workflow/pause.d.ts +5 -4
  181. package/dist/lib/workflow/pause.js +5 -4
  182. package/dist/lib/workflow/resume.d.ts +4 -4
  183. package/dist/lib/workflow/resume.js +4 -4
  184. package/dist/lib/workflow/route.d.ts +7 -7
  185. package/dist/lib/workflow/route.js +8 -8
  186. package/dist/lib/workflow/scheduler.d.ts +44 -2
  187. package/dist/lib/workflow/scheduler.js +60 -6
  188. package/dist/lib/workflow/toolNode.d.ts +18 -29
  189. package/dist/lib/workflow/toolNode.js +29 -35
  190. package/dist/lib/workflow/turn.d.ts +29 -20
  191. package/dist/lib/workflow/turn.js +111 -24
  192. package/dist/lib/workflow.d.ts +34 -60
  193. package/dist/lib/workflow.js +34 -168
  194. package/dist/lib/workflowConfig.d.ts +2 -10
  195. package/dist/lib/workflowConfig.js +2 -31
  196. package/dist/scripts/a2a_server.js +1 -2
  197. package/dist/scripts/assistant_worker.d.ts +2 -2
  198. package/dist/scripts/assistant_worker.js +8 -7
  199. package/dist/scripts/doctor.d.ts +2 -2
  200. package/dist/scripts/doctor.js +2 -2
  201. package/dist/scripts/syndicate_chat.js +14 -24
  202. package/package.json +3 -9
  203. package/skills/briefs/_shared.md +2 -2
  204. package/skills/briefs/melchizedek-author.md +2 -2
  205. package/skills/briefs/melchizedek-models.md +6 -6
  206. package/skills/melchizedek-author/SKILL.md +2 -2
  207. package/skills/melchizedek-models/SKILL.md +5 -5
@@ -1,16 +1,15 @@
1
1
  /**
2
- * lib/models/genaiMapping.ts — @google/genai `Content`, and ADK's LlmRequest
3
- * and LlmResponse, to and from the engine's model contract
2
+ * lib/models/genaiMapping.ts — @google/genai `Content`, and the genai-shaped
3
+ * LlmRequest and LlmResponse, to and from the engine's model contract
4
4
  * (lib/models/contract.ts, ADR 0048).
5
5
  *
6
6
  * WHY this file exists:
7
- * The ADK runtime holds and stores @google/genai `Content`: the history of
8
- * an LlmRequest, and the `content` of every stored event. The native
9
- * runtime and every adapter on the contract speak `Message` and `Part`.
10
- * This module converts between the two, so the native runtime can read a
11
- * session ADK stored, and an adapter can move onto the contract while ADK
12
- * still runs: its ADK class maps the LlmRequest in and each ModelResponse
13
- * out. It is pure (no I/O, clock or randomness) and never mutates its
7
+ * Every stored event's `content` is @google/genai `Content`, the shape ADK
8
+ * wrote and the engine keeps (ADR 0045's fixed shapes). The native loop
9
+ * and every adapter on the contract speak `Message` and `Part`. This
10
+ * module converts between the two, so the loop reads a session ADK stored
11
+ * before 1.0.0 as it reads its own, and stores each answer in the same
12
+ * shape (modelResponseToLlmResponse). It is pure (no I/O, clock or randomness) and never mutates its
14
13
  * input; leaf values (args, results, payloads) are shared, not copied.
15
14
  * The contract stays a leaf: only this module names @google/*.
16
15
  * wiki/models/model-contract.md ("From genai Content") is the spec.
@@ -63,7 +62,8 @@
63
62
  * genai bytes cannot tell the two apart.
64
63
  *
65
64
  * Ids. A ToolCallPart always has an id. A genai call without one (Gemini
66
- * returns none, and ADK strips its own `adk-` ids from every request) gets
65
+ * returns none, and the engine strips its own `adk-` ids from every
66
+ * request, as ADK did) gets
67
67
  * `genai-noid-<content>-<part>`, from its position, and a result without
68
68
  * one takes the id of the latest open minted call of the same name, else
69
69
  * one of its own (it then answers no call in the history). Back, a minted
@@ -91,27 +91,24 @@
91
91
  * true`; usage in Gemini's meanings (usageToMetadata); error as `errorCode`
92
92
  * and `errorMessage`, key-shaped text scrubbed, with `retryable` and
93
93
  * `status` as customMetadata['error.retryable'] and ['error.status']
94
- * (withRetryVerdict, lib/models/errorResponse.ts), the only place
95
- * FallbackLlm reads whether a fallback may answer; finishReason as
94
+ * (withRetryVerdict, lib/models/errorResponse.ts); finishReason as
96
95
  * Gemini's, except that an error whose code is one of Gemini's finish
97
- * reasons (the Gemini adapters keep it verbatim: MALFORMED_FUNCTION_CALL,
98
- * RECITATION, ...) gets that reason itself, as ADK's Gemini reports both, so
99
- * self-correction retries a malformed call and the stored event reads the
100
- * same on either runtime (ADR 0088); grounding as the `webSearchQueries` and
96
+ * reasons (the Gemini adapter keeps it verbatim: MALFORMED_FUNCTION_CALL,
97
+ * RECITATION, ...) gets that reason itself, as ADK's Gemini reported both,
98
+ * so self-correction retries a malformed call and the stored event reads as
99
+ * one ADK stored (ADR 0088); grounding as the `webSearchQueries` and
101
100
  * `groundingChunks[].web` that lib/grounding.ts reads. Not carried, since
102
101
  * an LlmResponse has no field for them: `cacheWriteTokens`, a citation's
103
102
  * span and cited text, and which native tool ran a query.
104
103
  *
105
- * THE REVERSE: a contract adapter over an ADK BaseLlm (lib/models/
106
- * adkGeminiAdapter.ts, the wrapper over ADK's Gemini) maps the ModelRequest
107
- * it is given to an LlmRequest, and each LlmResponse back.
104
+ * THE REVERSE: a ModelRequest as a genai-shaped LlmRequest, and each
105
+ * LlmResponse back, for a caller that holds a genai-speaking model.
108
106
  *
109
- * modelRequestToLlmRequest builds the LlmRequest ADK's path builds for a
110
- * Gemini model: the system prompt as `systemInstruction`; the messages as
107
+ * modelRequestToLlmRequest builds the genai-shaped request for a Gemini
108
+ * model: the system prompt as `systemInstruction`; the messages as
111
109
  * above; client tools as `functionDeclarations` with the lowercase schema
112
110
  * in `parametersJsonSchema`, and in `toolsDict` as declaration-only
113
- * entries, where llmRequestToModelRequest and the ADK-path adapters read
114
- * them; native tools as Gemini's tool objects, in the request's order;
111
+ * entries, where llmRequestToModelRequest reads them; native tools as Gemini's tool objects, in the request's order;
115
112
  * toolChoice and strict as the function-calling mode, sent only beside
116
113
  * declarations; the output schema as `responseJsonSchema`, and
117
114
  * `outputFormat: 'json'` without one as `responseMimeType:
@@ -120,7 +117,7 @@
120
117
  * it; sampling; the signal as `config.abortSignal`. What does not come
121
118
  * back the same through llmRequestToModelRequest: `google_search` reads as
122
119
  * `web_search`; `x_search` and `collections_search` are left out (Gemini
123
- * has no tool for them, and ADK adds their sentinels only for xAI); `auto`
120
+ * has no tool for them, and they go only to xAI); `auto`
124
121
  * reads as absent, and a choice without tools is not sent; one strict tool
125
122
  * makes every tool strict, and strict is lost beside a forced choice; a
126
123
  * level a model renders as a budget or another word reads back as that
@@ -144,10 +141,13 @@
144
141
  * display only (the caller yields it as a partial).
145
142
  *
146
143
  * USAGE MEANINGS. usageToMetadata and usageFromMetadata use Gemini's: its
147
- * `candidatesTokenCount` excludes the thinking in `thoughtsTokenCount`. The
148
- * ADK-path GPT and chat-completions adapters write `candidatesTokenCount`
149
- * with reasoning included, so usageFromMetadata on an event they stored
150
- * counts that reasoning twice in `outputTokens`.
144
+ * `candidatesTokenCount` excludes the thinking in `thoughtsTokenCount`.
145
+ * Every adapter's final is stored and charged through usageToMetadata, so
146
+ * this is the ledger's one meaning for every provider (ADR 0107).
147
+ * Events the GPT and chat-completions adapters stored under ADK (before
148
+ * 1.0.0) carry `candidatesTokenCount` with reasoning included, so
149
+ * usageFromMetadata on such an event counts that reasoning twice in
150
+ * `outputTokens`.
151
151
  */
152
152
  import { FinishReason, FunctionCallingConfigMode } from '@google/genai';
153
153
  import { ERROR_RETRYABLE_KEY, ERROR_STATUS_KEY, errorText, withRetryVerdict } from './errorResponse.js';
@@ -555,7 +555,7 @@ export function samplingOf(config) {
555
555
  sampling.stop = [...config.stopSequences];
556
556
  return Object.keys(sampling).length > 0 ? sampling : undefined;
557
557
  }
558
- /** An ADK LlmRequest as a ModelRequest (see the header for what is not mapped). */
558
+ /** A genai-shaped LlmRequest as a ModelRequest (see the header for what is not mapped). */
559
559
  export function llmRequestToModelRequest(llmRequest, options = {}) {
560
560
  const model = options.model ?? llmRequest.model;
561
561
  if (!model)
@@ -662,8 +662,8 @@ export const TOO_DEEP_ARGUMENTS = `[arguments nested deeper than ${MAX_VALUE_DEP
662
662
  /**
663
663
  * One part of a model's answer as the contract allows it (lib/models/
664
664
  * contract.ts), or undefined to drop it. The contract binds an adapter, and
665
- * a model's answer is untrusted input to the runtime that stores it, so the
666
- * runtimes hold an adapter to it here rather than store a part no reader
665
+ * a model's answer is untrusted input to the loop that stores it, so the
666
+ * loop holds an adapter to it here rather than store a part no reader
667
667
  * expects (WS5-5, wiki/operations/native-loop-security.md):
668
668
  * - a part that is not an object, of no known kind, or a tool result (an
669
669
  * answer holds none) is dropped;
@@ -713,8 +713,8 @@ function contractOutputPart(part) {
713
713
  /**
714
714
  * `response` with each part held to the contract (contractOutputPart): the
715
715
  * same object when every part already is, else a copy with the parts
716
- * checked. Used by modelResponseToLlmResponse (the ADK shim's mapping) and
717
- * by the native step, so both runtimes read and store the same answer. A
716
+ * checked. Used by modelResponseToLlmResponse and by the native step, so the
717
+ * step reads the same answer it stores. A
718
718
  * response that is not an object is returned as it is: the caller fails on
719
719
  * it as on any adapter that broke the contract.
720
720
  */
@@ -728,7 +728,7 @@ export function contractModelResponse(response) {
728
728
  return response;
729
729
  return { ...response, parts: checked.filter((p) => p !== undefined) };
730
730
  }
731
- /** A ModelResponse as the LlmResponse ADK expects from a model (see the header). */
731
+ /** A ModelResponse as a genai-shaped LlmResponse, the shape a stored model event is made from (see the header). */
732
732
  export function modelResponseToLlmResponse(unchecked) {
733
733
  const response = contractModelResponse(unchecked);
734
734
  const parts = partsToGenai(response.parts);
@@ -744,8 +744,8 @@ export function modelResponseToLlmResponse(unchecked) {
744
744
  ...(groundingMetadata ? { groundingMetadata } : {}),
745
745
  turnComplete: true,
746
746
  };
747
- // FallbackLlm reads the verdict from customMetadata alone (ADR 0044): an
748
- // error without it would be passed on, never answered by the fallback.
747
+ // A reader of this shape takes the verdict from customMetadata alone
748
+ // (ADR 0044): an error without it reads as not retryable.
749
749
  if (!response.error)
750
750
  return llmResponse;
751
751
  const { retryable, status } = response.error;
@@ -766,9 +766,9 @@ export function nativeToolsWithoutGeminiTool(tools = []) {
766
766
  /**
767
767
  * A toolsDict entry that only declares. `_getDeclaration()` gives the
768
768
  * declaration with its lowercase schema as `parameters`, where
769
- * llmRequestToModelRequest (contractToolDeclaration) and the ADK-path
770
- * adapters (toolDeclarationFor) read it. It is never run: ADK's Gemini sends
771
- * `config.tools`, and nothing calls a tool out of a request.
769
+ * llmRequestToModelRequest (contractToolDeclaration) reads it. It is never
770
+ * run: a Gemini request sends `config.tools`, and nothing calls a tool out
771
+ * of a request.
772
772
  */
773
773
  function declaredTool({ name, description, parameters }) {
774
774
  return { name, description, isLongRunning: false, _getDeclaration: () => ({ name, description, parameters }) };
@@ -792,7 +792,7 @@ function toolConfigOf(request) {
792
792
  : undefined;
793
793
  return mode ? { functionCallingConfig: { mode } } : undefined;
794
794
  }
795
- /** A ModelRequest as the LlmRequest ADK's path builds for a Gemini model (see the header for what does not come back the same). */
795
+ /** A ModelRequest as the genai-shaped request for a Gemini model (see the header for what does not come back the same). */
796
796
  export function modelRequestToLlmRequest(request) {
797
797
  const config = {};
798
798
  if (request.system)
@@ -895,7 +895,7 @@ function outputPartsOf(parts, model) {
895
895
  return out;
896
896
  return out.map((p) => (isSignatureState(p.providerState) && p.providerState.model === undefined ? { ...p, providerState: { ...p.providerState, model } } : p));
897
897
  }
898
- /** An ADK error code as the contract's error, with the verdict the adapter stamped (withRetryVerdict). `STOP` is no error. */
898
+ /** A genai-shaped error code as the contract's error, with the verdict the adapter stamped (withRetryVerdict). `STOP` is no error. */
899
899
  function errorOf(response) {
900
900
  const code = response.errorCode;
901
901
  if (!code || code === 'STOP')
@@ -6,11 +6,9 @@
6
6
  * WHY this file exists:
7
7
  * OpenAI's Responses API is where OpenAI exposes reasoning summaries and
8
8
  * its first-class `web_search` tool, and xAI's Agent Tools API speaks the
9
- * same wire. GptLlm and GrokLlm translated ADK's LlmRequest to it
10
- * directly. This module is that translation on the contract: it reads a
11
- * ModelRequest and yields ModelResponses, with no ADK in the path, so the
12
- * native runtime (ADR 0045) can call it. GptLlm and GrokLlm (gptLlm.ts,
13
- * grokLlm.ts) are now the ADK shim (lib/models/adkShim.ts) around it.
9
+ * same wire. This module is the translation on the contract: it reads a
10
+ * ModelRequest and yields ModelResponses, and the native loop (ADR 0045)
11
+ * calls it directly.
14
12
  *
15
13
  * THE MAPPING is the OpenAI Responses table of wiki/models/model-contract.md
16
14
  * (and its xAI table for the subclass). In short:
@@ -40,8 +38,9 @@
40
38
  *
41
39
  * BEYOND THE CONTRACT: the server-side tool calls a response reports, with
42
40
  * their arguments and sources, have no contract field. responsesServerTools()
43
- * returns them for a final this adapter yielded, so GptLlm can put them on the
44
- * ADK event's customMetadata where the ledger reads them (ADR 0056).
41
+ * returns them for a final this adapter yielded (ADR 0056); the native step
42
+ * writes them on the stored final's customMetadata
43
+ * (`responses.server_tool_calls`), where the ledger counts them.
45
44
  */
46
45
  import type { FinalModelResponse, ModelAdapter, ModelRequest, ModelResponse, NativeTool, PartialModelResponse, ReasoningSetting, Usage } from './contract.ts';
47
46
  import type { ProviderEndpoint } from './endpoints.ts';
@@ -72,7 +71,7 @@ export interface ResponsesInput {
72
71
  * loop only (currentTurnStart). An assistant message that replays keeps the
73
72
  * model's order of text and calls, so each run of reasoning items is
74
73
  * followed by the item it preceded; one that does not puts its calls before
75
- * its text, as the ADK path always built it.
74
+ * its text, as ADK always built it.
76
75
  */
77
76
  export declare function responsesInput(request: Pick<ModelRequest, 'system' | 'messages'>, replay?: ReasoningReplay): ResponsesInput;
78
77
  /** The request's client-side tools as Responses function tools; a strict one sends the strict form of its schema. */
@@ -120,9 +119,10 @@ export interface ResponsesServerTools {
120
119
  /**
121
120
  * The server-side tool calls and counters behind a final response a
122
121
  * Responses adapter yielded, or undefined when it reported none. The
123
- * contract has no field for them (only their queries, as grounding); GptLlm
124
- * writes them on the ADK event's customMetadata, where the ledger counts
125
- * them (lib/observability/tracer.ts, serverToolEvents).
122
+ * contract has no field for them (only their queries, as grounding). The
123
+ * native step (lib/runtime/native/step.ts, withServerTools) writes them on
124
+ * the stored final's customMetadata, and the root span counts them from
125
+ * there (lib/observability/tracer.ts, serverToolEvents).
126
126
  */
127
127
  export declare function responsesServerTools(response: ModelResponse): ResponsesServerTools | undefined;
128
128
  /**
@@ -6,11 +6,9 @@
6
6
  * WHY this file exists:
7
7
  * OpenAI's Responses API is where OpenAI exposes reasoning summaries and
8
8
  * its first-class `web_search` tool, and xAI's Agent Tools API speaks the
9
- * same wire. GptLlm and GrokLlm translated ADK's LlmRequest to it
10
- * directly. This module is that translation on the contract: it reads a
11
- * ModelRequest and yields ModelResponses, with no ADK in the path, so the
12
- * native runtime (ADR 0045) can call it. GptLlm and GrokLlm (gptLlm.ts,
13
- * grokLlm.ts) are now the ADK shim (lib/models/adkShim.ts) around it.
9
+ * same wire. This module is the translation on the contract: it reads a
10
+ * ModelRequest and yields ModelResponses, and the native loop (ADR 0045)
11
+ * calls it directly.
14
12
  *
15
13
  * THE MAPPING is the OpenAI Responses table of wiki/models/model-contract.md
16
14
  * (and its xAI table for the subclass). In short:
@@ -40,8 +38,9 @@
40
38
  *
41
39
  * BEYOND THE CONTRACT: the server-side tool calls a response reports, with
42
40
  * their arguments and sources, have no contract field. responsesServerTools()
43
- * returns them for a final this adapter yielded, so GptLlm can put them on the
44
- * ADK event's customMetadata where the ledger reads them (ADR 0056).
41
+ * returns them for a final this adapter yielded (ADR 0056); the native step
42
+ * writes them on the stored final's customMetadata
43
+ * (`responses.server_tool_calls`), where the ledger counts them.
45
44
  */
46
45
  import { endpointFromEnv, entraTokenSource, nativeSearchOn, platformModel } from './endpoints.js';
47
46
  import { errorDecision, errorText, statusDecision } from './errorResponse.js';
@@ -69,8 +68,8 @@ function resultJson(part) {
69
68
  }
70
69
  /** A user-turn blob as an input content item, or why it is left out. */
71
70
  function blobItem(part) {
72
- // The genai mapping types an untyped part as octet-stream; the ADK path
73
- // sent an untyped image as PNG, and the provider reads the bytes.
71
+ // The genai mapping types an untyped part as octet-stream; an untyped
72
+ // image goes as PNG, as ADK sent it, and the provider reads the bytes.
74
73
  const mimeType = !part.mimeType || part.mimeType === 'application/octet-stream' ? 'image/png' : part.mimeType;
75
74
  if (part.url !== undefined && !/^https:\/\//i.test(part.url))
76
75
  return 'URL scheme';
@@ -95,7 +94,7 @@ function replayedItems(part, replay) {
95
94
  * loop only (currentTurnStart). An assistant message that replays keeps the
96
95
  * model's order of text and calls, so each run of reasoning items is
97
96
  * followed by the item it preceded; one that does not puts its calls before
98
- * its text, as the ADK path always built it.
97
+ * its text, as ADK always built it.
99
98
  */
100
99
  export function responsesInput(request, replay) {
101
100
  const system = request.system ? [request.system] : [];
@@ -243,9 +242,10 @@ const SERVER_TOOLS = new WeakMap();
243
242
  /**
244
243
  * The server-side tool calls and counters behind a final response a
245
244
  * Responses adapter yielded, or undefined when it reported none. The
246
- * contract has no field for them (only their queries, as grounding); GptLlm
247
- * writes them on the ADK event's customMetadata, where the ledger counts
248
- * them (lib/observability/tracer.ts, serverToolEvents).
245
+ * contract has no field for them (only their queries, as grounding). The
246
+ * native step (lib/runtime/native/step.ts, withServerTools) writes them on
247
+ * the stored final's customMetadata, and the root span counts them from
248
+ * there (lib/observability/tracer.ts, serverToolEvents).
249
249
  */
250
250
  export function responsesServerTools(response) {
251
251
  return response.partial ? undefined : SERVER_TOOLS.get(response);
@@ -8,8 +8,8 @@
8
8
  * Kimi K3 (July 2026) is the strongest open-weight model on the public
9
9
  * coding and research boards, and Moonshot serves it first-party with
10
10
  * tool calling, strict structured output and vision, so it earns a
11
- * direct adapter rather than only the gateway path. Under ADK it runs
12
- * behind KimiLlm (lib/models/kimiLlm.ts), which any `kimi-*` id routes to.
11
+ * direct adapter rather than only the gateway path; any `kimi-*` id
12
+ * resolves to it (resolveAdapter, lib/models/adapterResolver.ts).
13
13
  *
14
14
  * WHY the chat-completions base (lib/models/chatCompletionsAdapter.ts):
15
15
  * Moonshot's API is OpenAI Chat Completions at https://api.moonshot.ai/v1
@@ -26,7 +26,8 @@
26
26
  * .cn console serves mainland China) and put it in .env as
27
27
  * MOONSHOT_API_KEY.
28
28
  * 2. Set model: "kimi-k3" (or any kimi-* id) in your YAML.
29
- * registerAvailableProviders() registers this adapter when the key is set.
29
+ * The adapter is available when the key is set (logProviderStatuses()
30
+ * reports it).
30
31
  * Optional: MOONSHOT_BASE_URL for a proxy that speaks the same dialect.
31
32
  *
32
33
  * THE FAMILY (platform.moonshot.ai › Model list, October 2026; USD per 1M tokens):
@@ -67,9 +68,7 @@
67
68
  * goes as its Kimi word (`medium` → `high`, a budget → the level that
68
69
  * covers it), `none` as `low` since K3 cannot switch thinking off, and a
69
70
  * request with none pins DEFAULT_KIMI_REASONING_EFFORT (lib/config.ts).
70
- * `max` has no contract level: an agent that needs it writes the older
71
- * spelling `generateContentConfig.reasoningEffort: max`, which the ADK
72
- * path carries beside the contract (ChatCompletionsRequest.olderSpelling).
71
+ * `max` has no contract level, so no request sends it.
73
72
  * K2.x models take no reasoning_effort: a `thinking: { type }` switch
74
73
  * instead, so `none` (or a budget of 0) sends `disabled` and any other
75
74
  * setting sends nothing. K2.7 Code (and its highspeed variant) cannot
@@ -153,5 +152,5 @@ export declare class KimiAdapter extends ChatCompletionsAdapter {
153
152
  protected missingRequirement(): ChatFailure | undefined;
154
153
  protected httpError(status: number, detail: string, model: string): ChatFailure;
155
154
  /** The reasoning controls, per generation (see the header). */
156
- protected reasoningFields(model: string, setting: ReasoningSetting | undefined, olderWord: string | undefined): Record<string, unknown>;
155
+ protected reasoningFields(model: string, setting: ReasoningSetting | undefined): Record<string, unknown>;
157
156
  }
@@ -8,8 +8,8 @@
8
8
  * Kimi K3 (July 2026) is the strongest open-weight model on the public
9
9
  * coding and research boards, and Moonshot serves it first-party with
10
10
  * tool calling, strict structured output and vision, so it earns a
11
- * direct adapter rather than only the gateway path. Under ADK it runs
12
- * behind KimiLlm (lib/models/kimiLlm.ts), which any `kimi-*` id routes to.
11
+ * direct adapter rather than only the gateway path; any `kimi-*` id
12
+ * resolves to it (resolveAdapter, lib/models/adapterResolver.ts).
13
13
  *
14
14
  * WHY the chat-completions base (lib/models/chatCompletionsAdapter.ts):
15
15
  * Moonshot's API is OpenAI Chat Completions at https://api.moonshot.ai/v1
@@ -26,7 +26,8 @@
26
26
  * .cn console serves mainland China) and put it in .env as
27
27
  * MOONSHOT_API_KEY.
28
28
  * 2. Set model: "kimi-k3" (or any kimi-* id) in your YAML.
29
- * registerAvailableProviders() registers this adapter when the key is set.
29
+ * The adapter is available when the key is set (logProviderStatuses()
30
+ * reports it).
30
31
  * Optional: MOONSHOT_BASE_URL for a proxy that speaks the same dialect.
31
32
  *
32
33
  * THE FAMILY (platform.moonshot.ai › Model list, October 2026; USD per 1M tokens):
@@ -67,9 +68,7 @@
67
68
  * goes as its Kimi word (`medium` → `high`, a budget → the level that
68
69
  * covers it), `none` as `low` since K3 cannot switch thinking off, and a
69
70
  * request with none pins DEFAULT_KIMI_REASONING_EFFORT (lib/config.ts).
70
- * `max` has no contract level: an agent that needs it writes the older
71
- * spelling `generateContentConfig.reasoningEffort: max`, which the ADK
72
- * path carries beside the contract (ChatCompletionsRequest.olderSpelling).
71
+ * `max` has no contract level, so no request sends it.
73
72
  * K2.x models take no reasoning_effort: a `thinking: { type }` switch
74
73
  * instead, so `none` (or a budget of 0) sends `disabled` and any other
75
74
  * setting sends nothing. K2.7 Code (and its highspeed variant) cannot
@@ -188,10 +187,8 @@ export class KimiAdapter extends ChatCompletionsAdapter {
188
187
  };
189
188
  }
190
189
  /** The reasoning controls, per generation (see the header). */
191
- reasoningFields(model, setting, olderWord) {
190
+ reasoningFields(model, setting) {
192
191
  if (isKimiK3(model)) {
193
- if (olderWord !== undefined)
194
- return { reasoning_effort: olderWord };
195
192
  if (setting === undefined)
196
193
  return { reasoning_effort: DEFAULT_KIMI_REASONING_EFFORT };
197
194
  const word = reasoningConfig(model, setting).reasoningEffort;
@@ -11,8 +11,8 @@
11
11
  * local inference. The chat-completions translation is the shared base
12
12
  * (lib/models/chatCompletionsAdapter.ts); this adapter supplies Ollama's
13
13
  * endpoint, its wire model name and its error wording.
14
- * Under ADK it runs behind OllamaLlm (lib/models/ollamaLlm.ts), which any
15
- * agent with model: "ollama/<model>" routes to.
14
+ * Any agent with model: "ollama/<model>" resolves to it (resolveAdapter,
15
+ * lib/models/adapterResolver.ts).
16
16
  *
17
17
  * HOW TO ENABLE:
18
18
  * 1. Install Ollama (https://ollama.com — macOS: brew install ollama)
@@ -21,7 +21,7 @@
21
21
  * ollama pull qwen3.5:9b # the default recommendation
22
22
  * ollama pull qwen3.5:4b # lighter; teaching and small machines
23
23
  * 3. Set model: "ollama/qwen3.5:9b" in your YAML. No API key needed —
24
- * registerAvailableProviders() registers this provider unconditionally.
24
+ * the provider is always available (logProviderStatuses() reports it).
25
25
  * Optional: OLLAMA_BASE_URL in .env overrides the default endpoint
26
26
  * (http://localhost:11434/v1 — Ollama's OpenAI-compatible API).
27
27
  *
@@ -11,8 +11,8 @@
11
11
  * local inference. The chat-completions translation is the shared base
12
12
  * (lib/models/chatCompletionsAdapter.ts); this adapter supplies Ollama's
13
13
  * endpoint, its wire model name and its error wording.
14
- * Under ADK it runs behind OllamaLlm (lib/models/ollamaLlm.ts), which any
15
- * agent with model: "ollama/<model>" routes to.
14
+ * Any agent with model: "ollama/<model>" resolves to it (resolveAdapter,
15
+ * lib/models/adapterResolver.ts).
16
16
  *
17
17
  * HOW TO ENABLE:
18
18
  * 1. Install Ollama (https://ollama.com — macOS: brew install ollama)
@@ -21,7 +21,7 @@
21
21
  * ollama pull qwen3.5:9b # the default recommendation
22
22
  * ollama pull qwen3.5:4b # lighter; teaching and small machines
23
23
  * 3. Set model: "ollama/qwen3.5:9b" in your YAML. No API key needed —
24
- * registerAvailableProviders() registers this provider unconditionally.
24
+ * the provider is always available (logProviderStatuses() reports it).
25
25
  * Optional: OLLAMA_BASE_URL in .env overrides the default endpoint
26
26
  * (http://localhost:11434/v1 — Ollama's OpenAI-compatible API).
27
27
  *
@@ -3,14 +3,15 @@
3
3
  * (as declared in an agent YAML) to its provider.
4
4
  *
5
5
  * WHY a leaf module:
6
- * Both the LLM registry (lib/models/registry.ts) and the web-search
7
- * abstraction (lib/tools/webSearchTool.ts) need this mapping; keeping it
6
+ * The adapter resolver (lib/models/adapterResolver.ts, through
7
+ * lib/models/registry.ts) and the server-side tools' per-provider routing
8
+ * (lib/runtime/native/request.ts) both need this mapping; keeping it
8
9
  * dependency-free avoids an import cycle between adapters and tools.
9
10
  *
10
11
  * Model-name conventions (see DOCUMENTATION.md §7):
11
12
  * claude-* → anthropic gpt-* / o<digit>* → openai
12
13
  * grok-* → xai ollama/<model> → ollama (local, keyless)
13
- * kimi-* → moonshot everything else → gemini (the ADK-native default)
14
+ * kimi-* → moonshot everything else → gemini (the default)
14
15
  */
15
16
  export type ProviderId = 'gemini' | 'anthropic' | 'openai' | 'xai' | 'moonshot' | 'ollama';
16
17
  interface ProviderInfo {
@@ -20,8 +21,8 @@ interface ProviderInfo {
20
21
  label: string;
21
22
  }
22
23
  export declare const PROVIDERS: Record<ProviderId, ProviderInfo>;
23
- /** Maps a model id to its provider. Unknown ids default to gemini — the
24
- * ADK-native provider — matching the LLMRegistry's fallback behavior. */
24
+ /** Maps a model id to its provider. Unknown ids default to gemini, as
25
+ * resolveAdapter does: a typo in a claude- id becomes a Gemini call. */
25
26
  export declare function providerForModel(model: string): ProviderId;
26
27
  /** True when the provider's key is present (always true for local Ollama). */
27
28
  export declare function providerKeyPresent(provider: ProviderId): boolean;
@@ -3,14 +3,15 @@
3
3
  * (as declared in an agent YAML) to its provider.
4
4
  *
5
5
  * WHY a leaf module:
6
- * Both the LLM registry (lib/models/registry.ts) and the web-search
7
- * abstraction (lib/tools/webSearchTool.ts) need this mapping; keeping it
6
+ * The adapter resolver (lib/models/adapterResolver.ts, through
7
+ * lib/models/registry.ts) and the server-side tools' per-provider routing
8
+ * (lib/runtime/native/request.ts) both need this mapping; keeping it
8
9
  * dependency-free avoids an import cycle between adapters and tools.
9
10
  *
10
11
  * Model-name conventions (see DOCUMENTATION.md §7):
11
12
  * claude-* → anthropic gpt-* / o<digit>* → openai
12
13
  * grok-* → xai ollama/<model> → ollama (local, keyless)
13
- * kimi-* → moonshot everything else → gemini (the ADK-native default)
14
+ * kimi-* → moonshot everything else → gemini (the default)
14
15
  */
15
16
  export const PROVIDERS = {
16
17
  gemini: { keyEnv: 'GOOGLE_GENAI_API_KEY', label: 'Google Gemini' },
@@ -20,8 +21,8 @@ export const PROVIDERS = {
20
21
  moonshot: { keyEnv: 'MOONSHOT_API_KEY', label: 'Moonshot Kimi' },
21
22
  ollama: { keyEnv: null, label: 'Ollama (local)' },
22
23
  };
23
- /** Maps a model id to its provider. Unknown ids default to gemini — the
24
- * ADK-native provider — matching the LLMRegistry's fallback behavior. */
24
+ /** Maps a model id to its provider. Unknown ids default to gemini, as
25
+ * resolveAdapter does: a typo in a claude- id becomes a Gemini call. */
25
26
  export function providerForModel(model) {
26
27
  if (/^ollama\//.test(model))
27
28
  return 'ollama';
@@ -5,8 +5,9 @@
5
5
  * WHY: some providers want back, on the next request of a tool loop, state
6
6
  * only they can read: Anthropic's signed `thinking` and `redacted_thinking`
7
7
  * blocks, OpenAI's and xAI's reasoning items, Moonshot's reasoning_content.
8
- * ADK's request is built from each event's `content` alone (event metadata
9
- * never reaches it), and @google/genai serializes a part field by field, so
8
+ * A request is built from each event's `content` alone (event metadata
9
+ * never reaches it, as with ADK), and @google/genai serializes a part field
10
+ * by field, so
10
11
  * the state rides as one extra field on a part the model actually produced:
11
12
  *
12
13
  * { functionCall: {...}, providerState: { provider, kind, payload } }
@@ -5,8 +5,9 @@
5
5
  * WHY: some providers want back, on the next request of a tool loop, state
6
6
  * only they can read: Anthropic's signed `thinking` and `redacted_thinking`
7
7
  * blocks, OpenAI's and xAI's reasoning items, Moonshot's reasoning_content.
8
- * ADK's request is built from each event's `content` alone (event metadata
9
- * never reaches it), and @google/genai serializes a part field by field, so
8
+ * A request is built from each event's `content` alone (event metadata
9
+ * never reaches it, as with ADK), and @google/genai serializes a part field
10
+ * by field, so
10
11
  * the state rides as one extra field on a part the model actually produced:
11
12
  *
12
13
  * { functionCall: {...}, providerState: { provider, kind, payload } }
@@ -5,7 +5,7 @@
5
5
  * WHY HERE: the compiler maps an agent's `reasoning:` key through this, and
6
6
  * a model adapter on the contract (lib/models/geminiAdapter.ts) maps a
7
7
  * ModelRequest's `reasoning` the same way. Keeping it out of lib/compile.ts
8
- * keeps ADK out of an adapter's imports. lib/compile.ts re-exports both
8
+ * keeps the compiler out of an adapter's imports. lib/compile.ts re-exports both
9
9
  * names, so existing imports keep working.
10
10
  */
11
11
  import type { ReasoningLevel, ReasoningSetting } from './contract.ts';