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.
- package/.env.example +4 -5
- package/AGENT_SETUP.md +3 -3
- package/CHANGELOG.md +240 -0
- package/DOCUMENTATION.md +142 -150
- package/QUICKSTART.md +12 -11
- package/README.md +11 -11
- package/config/agents/examples/image_production.yaml +2 -2
- package/config/agents/syndicateSchema.yaml +52 -26
- package/dist/lib/a2a/app.d.ts +17 -12
- package/dist/lib/a2a/app.js +16 -6
- package/dist/lib/a2a/executor.d.ts +10 -14
- package/dist/lib/a2a/executor.js +10 -18
- package/dist/lib/a2a/remoteAgent.d.ts +5 -12
- package/dist/lib/a2a/remoteAgent.js +5 -12
- package/dist/lib/compile.d.ts +76 -86
- package/dist/lib/compile.js +100 -116
- package/dist/lib/compileNative.d.ts +44 -56
- package/dist/lib/compileNative.js +91 -89
- package/dist/lib/config.d.ts +6 -6
- package/dist/lib/config.js +6 -6
- package/dist/lib/doctor.d.ts +8 -14
- package/dist/lib/doctor.js +10 -46
- package/dist/lib/index.d.ts +12 -9
- package/dist/lib/index.js +10 -11
- package/dist/lib/loadSyndicate.d.ts +3 -3
- package/dist/lib/loadSyndicate.js +2 -2
- package/dist/lib/memory/erase.d.ts +1 -1
- package/dist/lib/memory/erase.js +1 -1
- package/dist/lib/memory/namespace.d.ts +12 -14
- package/dist/lib/memory/namespace.js +13 -14
- package/dist/lib/memory/providers.d.ts +4 -5
- package/dist/lib/memory/providers.js +12 -6
- package/dist/lib/memory/supabaseMemoryService.d.ts +9 -30
- package/dist/lib/memory/supabaseMemoryService.js +8 -30
- package/dist/lib/model.d.ts +6 -12
- package/dist/lib/model.js +6 -12
- package/dist/lib/models/adapterResolver.d.ts +21 -40
- package/dist/lib/models/adapterResolver.js +32 -40
- package/dist/lib/models/chatCompletionsAdapter.d.ts +12 -33
- package/dist/lib/models/chatCompletionsAdapter.js +13 -18
- package/dist/lib/models/circuitBreaker.d.ts +5 -5
- package/dist/lib/models/circuitBreaker.js +5 -5
- package/dist/lib/models/claudeAdapter.d.ts +9 -26
- package/dist/lib/models/claudeAdapter.js +11 -15
- package/dist/lib/models/claudeModels.d.ts +4 -4
- package/dist/lib/models/claudeModels.js +4 -4
- package/dist/lib/models/contract.d.ts +11 -11
- package/dist/lib/models/contract.js +6 -6
- package/dist/lib/models/errorResponse.d.ts +13 -20
- package/dist/lib/models/errorResponse.js +0 -12
- package/dist/lib/models/fallbackAdapter.d.ts +7 -8
- package/dist/lib/models/gatewayAdapter.d.ts +1 -1
- package/dist/lib/models/gatewayAdapter.js +1 -1
- package/dist/lib/models/geminiAdapter.d.ts +5 -6
- package/dist/lib/models/geminiAdapter.js +9 -10
- package/dist/lib/models/geminiState.d.ts +8 -8
- package/dist/lib/models/geminiState.js +8 -8
- package/dist/lib/models/genaiMapping.d.ts +82 -36
- package/dist/lib/models/genaiMapping.js +41 -41
- package/dist/lib/models/gptAdapter.d.ts +11 -11
- package/dist/lib/models/gptAdapter.js +13 -13
- package/dist/lib/models/kimiAdapter.d.ts +6 -7
- package/dist/lib/models/kimiAdapter.js +6 -9
- package/dist/lib/models/ollamaAdapter.d.ts +3 -3
- package/dist/lib/models/ollamaAdapter.js +3 -3
- package/dist/lib/models/providerMap.d.ts +6 -5
- package/dist/lib/models/providerMap.js +6 -5
- package/dist/lib/models/providerState.d.ts +3 -2
- package/dist/lib/models/providerState.js +3 -2
- package/dist/lib/models/reasoning.d.ts +1 -1
- package/dist/lib/models/registry.d.ts +26 -73
- package/dist/lib/models/registry.js +31 -144
- package/dist/lib/models/retry.d.ts +2 -2
- package/dist/lib/models/retry.js +2 -2
- package/dist/lib/models/schemaNormalize.d.ts +25 -55
- package/dist/lib/models/schemaNormalize.js +30 -100
- package/dist/lib/observability/lineage.d.ts +3 -3
- package/dist/lib/observability/lineage.js +10 -10
- package/dist/lib/observability/supabaseSpanExporter.js +1 -1
- package/dist/lib/observability/tracer.d.ts +25 -23
- package/dist/lib/observability/tracer.js +26 -63
- package/dist/lib/persistence/supabaseProvider.d.ts +4 -3
- package/dist/lib/runtime/approvals.d.ts +1 -1
- package/dist/lib/runtime/credentials.d.ts +1 -1
- package/dist/lib/runtime/events.d.ts +3 -4
- package/dist/lib/runtime/events.js +3 -4
- package/dist/lib/runtime/logging.d.ts +3 -8
- package/dist/lib/runtime/logging.js +3 -8
- package/dist/lib/runtime/memoryService.d.ts +4 -6
- package/dist/lib/runtime/memoryService.js +3 -5
- package/dist/lib/runtime/native/agentLoop.d.ts +18 -16
- package/dist/lib/runtime/native/agentLoop.js +38 -26
- package/dist/lib/runtime/native/compaction.d.ts +10 -11
- package/dist/lib/runtime/native/compaction.js +10 -11
- package/dist/lib/runtime/native/delegate.d.ts +13 -14
- package/dist/lib/runtime/native/delegate.js +11 -18
- package/dist/lib/runtime/native/history.d.ts +5 -6
- package/dist/lib/runtime/native/history.js +5 -6
- package/dist/lib/runtime/native/interrupts.d.ts +6 -6
- package/dist/lib/runtime/native/interrupts.js +6 -6
- package/dist/lib/runtime/native/request.d.ts +24 -24
- package/dist/lib/runtime/native/request.js +35 -24
- package/dist/lib/runtime/native/selfCorrection.d.ts +32 -32
- package/dist/lib/runtime/native/selfCorrection.js +34 -34
- package/dist/lib/runtime/native/step.d.ts +23 -23
- package/dist/lib/runtime/native/step.js +49 -27
- package/dist/lib/runtime/native/taskMode.d.ts +8 -8
- package/dist/lib/runtime/native/taskMode.js +8 -8
- package/dist/lib/runtime/native/telemetry.d.ts +11 -11
- package/dist/lib/runtime/native/telemetry.js +11 -11
- package/dist/lib/runtime/native/tempState.d.ts +4 -4
- package/dist/lib/runtime/native/tempState.js +4 -4
- package/dist/lib/runtime/nativeTurn.d.ts +29 -32
- package/dist/lib/runtime/nativeTurn.js +30 -41
- package/dist/lib/runtime/questions.d.ts +8 -9
- package/dist/lib/runtime/questions.js +1 -2
- package/dist/lib/runtime/runtimeFlag.d.ts +28 -14
- package/dist/lib/runtime/runtimeFlag.js +38 -16
- package/dist/lib/runtime/sessions.d.ts +10 -12
- package/dist/lib/runtime/sessions.js +10 -12
- package/dist/lib/runtime/syndicateTurn.d.ts +44 -45
- package/dist/lib/runtime/syndicateTurn.js +163 -158
- package/dist/lib/runtime/turnControl.d.ts +8 -8
- package/dist/lib/runtime/turnControl.js +8 -8
- package/dist/lib/session/supabaseSessionService.d.ts +7 -21
- package/dist/lib/session/supabaseSessionService.js +7 -43
- package/dist/lib/session/transcript.d.ts +16 -26
- package/dist/lib/session/transcript.js +17 -57
- package/dist/lib/storage/postgres/sessionService.d.ts +6 -20
- package/dist/lib/storage/postgres/sessionService.js +6 -39
- package/dist/lib/syndicateSchema.js +7 -6
- package/dist/lib/toolRegistry.d.ts +9 -14
- package/dist/lib/toolRegistry.js +36 -33
- package/dist/lib/tools/auth.d.ts +1 -1
- package/dist/lib/tools/auth.js +1 -1
- package/dist/lib/tools/examples.d.ts +2 -4
- package/dist/lib/tools/examples.js +2 -4
- package/dist/lib/tools/generateImageTool.d.ts +3 -3
- package/dist/lib/tools/generateImageTool.js +4 -5
- package/dist/lib/tools/inspectImageTool.d.ts +2 -2
- package/dist/lib/tools/inspectImageTool.js +3 -4
- package/dist/lib/tools/mcpToolFactory.d.ts +4 -24
- package/dist/lib/tools/mcpToolFactory.js +19 -9
- package/dist/lib/tools/memoryTools.d.ts +5 -6
- package/dist/lib/tools/memoryTools.js +5 -6
- package/dist/lib/tools/nativeTools.d.ts +9 -14
- package/dist/lib/tools/nativeTools.js +9 -14
- package/dist/lib/tools/openapiTools.d.ts +5 -7
- package/dist/lib/tools/openapiTools.js +6 -13
- package/dist/lib/tools/scienceTools.d.ts +3 -3
- package/dist/lib/tools/scienceTools.js +8 -10
- package/dist/lib/tools/skillToolset.d.ts +1 -2
- package/dist/lib/tools/skillToolset.js +1 -2
- package/dist/lib/tools/skills/executor.d.ts +1 -1
- package/dist/lib/tools/skills/executor.js +1 -1
- package/dist/lib/tools/skills/frontmatter.d.ts +2 -2
- package/dist/lib/tools/skills/frontmatter.js +2 -2
- package/dist/lib/tools/skills/tools.d.ts +8 -10
- package/dist/lib/tools/skills/tools.js +9 -11
- package/dist/lib/tools/tool.d.ts +24 -40
- package/dist/lib/tools/tool.js +24 -56
- package/dist/lib/tools/toolContract.d.ts +8 -13
- package/dist/lib/tools/toolContract.js +6 -17
- package/dist/lib/tools/webExtractTool.d.ts +2 -2
- package/dist/lib/tools/webExtractTool.js +3 -4
- package/dist/lib/tools/wikiTools.d.ts +2 -2
- package/dist/lib/tools/wikiTools.js +5 -6
- package/dist/lib/tools/xApiSearchTool.d.ts +2 -2
- package/dist/lib/tools/xApiSearchTool.js +3 -4
- package/dist/lib/tools/xaiSearchParams.d.ts +2 -5
- package/dist/lib/tools/xaiSearchParams.js +2 -5
- package/dist/lib/wiki/agentRun.d.ts +10 -11
- package/dist/lib/wiki/agentRun.js +24 -42
- package/dist/lib/workflow/agentNode.d.ts +10 -1
- package/dist/lib/workflow/agentNode.js +5 -3
- package/dist/lib/workflow/graph.d.ts +8 -9
- package/dist/lib/workflow/graph.js +12 -12
- package/dist/lib/workflow/nodeEvents.d.ts +5 -5
- package/dist/lib/workflow/nodeEvents.js +5 -5
- package/dist/lib/workflow/pause.d.ts +5 -4
- package/dist/lib/workflow/pause.js +5 -4
- package/dist/lib/workflow/resume.d.ts +4 -4
- package/dist/lib/workflow/resume.js +4 -4
- package/dist/lib/workflow/route.d.ts +7 -7
- package/dist/lib/workflow/route.js +8 -8
- package/dist/lib/workflow/scheduler.d.ts +44 -2
- package/dist/lib/workflow/scheduler.js +60 -6
- package/dist/lib/workflow/toolNode.d.ts +18 -29
- package/dist/lib/workflow/toolNode.js +29 -35
- package/dist/lib/workflow/turn.d.ts +29 -20
- package/dist/lib/workflow/turn.js +111 -24
- package/dist/lib/workflow.d.ts +34 -60
- package/dist/lib/workflow.js +34 -168
- package/dist/lib/workflowConfig.d.ts +2 -10
- package/dist/lib/workflowConfig.js +2 -31
- package/dist/scripts/a2a_server.js +1 -2
- package/dist/scripts/assistant_worker.d.ts +2 -2
- package/dist/scripts/assistant_worker.js +8 -7
- package/dist/scripts/doctor.d.ts +2 -2
- package/dist/scripts/doctor.js +2 -2
- package/dist/scripts/syndicate_chat.js +14 -24
- package/package.json +3 -9
- package/skills/briefs/_shared.md +2 -2
- package/skills/briefs/melchizedek-author.md +2 -2
- package/skills/briefs/melchizedek-models.md +6 -6
- package/skills/melchizedek-author/SKILL.md +2 -2
- package/skills/melchizedek-models/SKILL.md +5 -5
|
@@ -1,16 +1,15 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* lib/models/genaiMapping.ts — @google/genai `Content`, and
|
|
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
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
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
|
|
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)
|
|
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
|
|
98
|
-
* RECITATION, ...) gets that reason itself, as ADK's Gemini
|
|
99
|
-
* self-correction retries a malformed call and the stored event reads
|
|
100
|
-
*
|
|
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
|
|
106
|
-
*
|
|
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
|
|
110
|
-
*
|
|
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
|
|
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
|
|
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`.
|
|
148
|
-
*
|
|
149
|
-
*
|
|
150
|
-
*
|
|
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
|
-
/**
|
|
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
|
|
666
|
-
*
|
|
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
|
|
717
|
-
*
|
|
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
|
|
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
|
-
//
|
|
748
|
-
// error without it
|
|
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)
|
|
770
|
-
*
|
|
771
|
-
*
|
|
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
|
|
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
|
-
/**
|
|
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.
|
|
10
|
-
*
|
|
11
|
-
*
|
|
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
|
|
44
|
-
*
|
|
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
|
|
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)
|
|
124
|
-
*
|
|
125
|
-
*
|
|
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.
|
|
10
|
-
*
|
|
11
|
-
*
|
|
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
|
|
44
|
-
*
|
|
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;
|
|
73
|
-
//
|
|
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
|
|
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)
|
|
247
|
-
*
|
|
248
|
-
*
|
|
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
|
|
12
|
-
*
|
|
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
|
-
*
|
|
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
|
|
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
|
|
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
|
|
12
|
-
*
|
|
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
|
-
*
|
|
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
|
|
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
|
|
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
|
-
*
|
|
15
|
-
*
|
|
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
|
-
*
|
|
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
|
-
*
|
|
15
|
-
*
|
|
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
|
-
*
|
|
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
|
-
*
|
|
7
|
-
*
|
|
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
|
|
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
|
|
24
|
-
*
|
|
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
|
-
*
|
|
7
|
-
*
|
|
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
|
|
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
|
|
24
|
-
*
|
|
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
|
-
*
|
|
9
|
-
* never reaches it), and @google/genai serializes a part field
|
|
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
|
-
*
|
|
9
|
-
* never reaches it), and @google/genai serializes a part field
|
|
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
|
|
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';
|