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
|
@@ -4,12 +4,12 @@
|
|
|
4
4
|
* implements and the native runtime calls (ADR 0045, ADR 0048).
|
|
5
5
|
*
|
|
6
6
|
* WHY this file exists:
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
7
|
+
* ADK spoke @google/genai `Content`, which is Gemini's wire format. It
|
|
8
|
+
* has no slot for another provider's reasoning state, spells schemas in
|
|
9
|
+
* Gemini's uppercase dialect, carried server-side tools as sentinel tool
|
|
10
|
+
* objects, and surfaced failures as a throw on one path and a yielded
|
|
11
|
+
* `errorCode` on another. The native runtime owns its loop, so it owns
|
|
12
|
+
* this format instead. Each adapter translates it to its provider's
|
|
13
13
|
* wire; wiki/models/model-contract.md is the field-by-field spec, with the
|
|
14
14
|
* mapping for every provider.
|
|
15
15
|
*
|
|
@@ -290,9 +290,9 @@ type SetupErrorCode = 'MISSING_API_KEY' | 'ENDPOINT_MISCONFIGURED' | 'SDK_NOT_IN
|
|
|
290
290
|
/** The chat-completions failures, under the provider's id (the gateway names the upstream provider). */
|
|
291
291
|
type ChatErrorCode = `${'MOONSHOT' | 'OLLAMA' | 'GEMINI' | 'ANTHROPIC' | 'OPENAI' | 'XAI'}_${'MAX_TOKENS' | 'EMPTY_RESPONSE' | 'UNREACHABLE'}` | 'MOONSHOT_MISSING_KEY' | 'MOONSHOT_HTTP_ERROR' | 'OLLAMA_HTTP_ERROR' | 'GATEWAY_NOT_CONFIGURED' | 'GATEWAY_KEY_MISSING' | 'GATEWAY_HTTP_ERROR';
|
|
292
292
|
/**
|
|
293
|
-
* Gemini's codes:
|
|
294
|
-
*
|
|
295
|
-
* which ADK
|
|
293
|
+
* Gemini's codes: a candidate's finish reason, or the prompt's block reason,
|
|
294
|
+
* is the code itself, as ADK's adapter reported it. GEMINI_ERROR is a failed
|
|
295
|
+
* call, which ADK threw and the contract reports.
|
|
296
296
|
*/
|
|
297
297
|
type GeminiErrorCode = 'GEMINI_ERROR' | 'MAX_TOKENS' | 'SAFETY' | 'RECITATION' | 'LANGUAGE' | 'OTHER' | 'BLOCKLIST' | 'PROHIBITED_CONTENT' | 'SPII' | 'MALFORMED_FUNCTION_CALL' | 'IMAGE_SAFETY' | 'UNEXPECTED_TOOL_CALL' | 'TOO_MANY_TOOL_CALLS' | 'IMAGE_PROHIBITED_CONTENT' | 'NO_IMAGE' | 'IMAGE_RECITATION' | 'IMAGE_OTHER' | 'MODEL_ARMOR' | 'JAILBREAK' | 'UNKNOWN_ERROR';
|
|
298
298
|
/**
|
|
@@ -302,8 +302,8 @@ type GeminiErrorCode = 'GEMINI_ERROR' | 'MAX_TOKENS' | 'SAFETY' | 'RECITATION' |
|
|
|
302
302
|
*/
|
|
303
303
|
type TurnControlErrorCode = 'STEP_LIMIT' | 'DEADLINE_EXCEEDED' | 'CANCELED';
|
|
304
304
|
/**
|
|
305
|
-
* The codes the engine's adapters report, kept verbatim from what they
|
|
306
|
-
* under ADK so a caller matching on a code keeps working. An adapter the
|
|
305
|
+
* The codes the engine's adapters report, kept verbatim from what they
|
|
306
|
+
* emitted under ADK so a caller matching on a code keeps working. An adapter the
|
|
307
307
|
* engine does not ship may report its own; the engine's adapters use only
|
|
308
308
|
* these, and adding one is a change to wiki/models/model-contract.md.
|
|
309
309
|
*/
|
|
@@ -4,12 +4,12 @@
|
|
|
4
4
|
* implements and the native runtime calls (ADR 0045, ADR 0048).
|
|
5
5
|
*
|
|
6
6
|
* WHY this file exists:
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
7
|
+
* ADK spoke @google/genai `Content`, which is Gemini's wire format. It
|
|
8
|
+
* has no slot for another provider's reasoning state, spells schemas in
|
|
9
|
+
* Gemini's uppercase dialect, carried server-side tools as sentinel tool
|
|
10
|
+
* objects, and surfaced failures as a throw on one path and a yielded
|
|
11
|
+
* `errorCode` on another. The native runtime owns its loop, so it owns
|
|
12
|
+
* this format instead. Each adapter translates it to its provider's
|
|
13
13
|
* wire; wiki/models/model-contract.md is the field-by-field spec, with the
|
|
14
14
|
* mapping for every provider.
|
|
15
15
|
*
|
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* lib/models/errorResponse.ts —
|
|
3
|
-
*
|
|
2
|
+
* lib/models/errorResponse.ts — what a failed provider call says about
|
|
3
|
+
* trying again, and the genai-shaped error response that carries it.
|
|
4
4
|
*
|
|
5
|
-
* WHY:
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
* the request's own error without parsing a message
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
5
|
+
* WHY: an adapter reports a failed provider call as a final response with
|
|
6
|
+
* `error`, never a throw, and the fallback (FallbackAdapter,
|
|
7
|
+
* lib/models/fallbackAdapter.ts, ADR 0044) must tell a provider-side
|
|
8
|
+
* failure from the request's own error without parsing a message. The
|
|
9
|
+
* adapters' catch sites (Claude, GPT and Grok, and the chat-completions base
|
|
10
|
+
* for Kimi, Ollama and the gateway) take the verdict and the scrubbed text
|
|
11
|
+
* from here (errorDecision, statusDecision, errorText). A genai-shaped
|
|
12
|
+
* LlmResponse (lib/models/genaiMapping.ts) carries the same verdict in its
|
|
13
|
+
* customMetadata (withRetryVerdict). A response without the verdict is read
|
|
14
|
+
* as not retryable: passed on, never redirected.
|
|
14
15
|
*
|
|
15
16
|
* 'error.retryable' true when lib/models/retry.ts classifies the failure
|
|
16
17
|
* retryable (408/409/425/429/5xx, a connection reset);
|
|
@@ -22,7 +23,7 @@
|
|
|
22
23
|
* leaves the adapter, so an error never carries a key into a session, the
|
|
23
24
|
* ledger or a log.
|
|
24
25
|
*/
|
|
25
|
-
import type { LlmResponse } from '
|
|
26
|
+
import type { LlmResponse } from './genaiMapping.ts';
|
|
26
27
|
import type { RetryDecision } from './retry.ts';
|
|
27
28
|
/** customMetadata key: whether another attempt or model may succeed. */
|
|
28
29
|
export declare const ERROR_RETRYABLE_KEY = "error.retryable";
|
|
@@ -40,11 +41,3 @@ export declare function statusDecision(status: number): RetryDecision;
|
|
|
40
41
|
* the adapter's own; customMetadata it already carries is kept.
|
|
41
42
|
*/
|
|
42
43
|
export declare function withRetryVerdict(response: LlmResponse, decision: RetryDecision): LlmResponse;
|
|
43
|
-
/**
|
|
44
|
-
* The error response for a caught provider error: `errorCode`, the message
|
|
45
|
-
* (the error's own text unless the adapter words it), and the verdict from
|
|
46
|
-
* classifyError.
|
|
47
|
-
*/
|
|
48
|
-
export declare function providerErrorResponse(err: unknown, errorCode: string, errorMessage?: string): LlmResponse;
|
|
49
|
-
/** True when a response is an error its adapter marked retryable: a provider-side failure. */
|
|
50
|
-
export declare function isRetryableErrorResponse(response: LlmResponse): boolean;
|
|
@@ -34,15 +34,3 @@ export function withRetryVerdict(response, decision) {
|
|
|
34
34
|
},
|
|
35
35
|
};
|
|
36
36
|
}
|
|
37
|
-
/**
|
|
38
|
-
* The error response for a caught provider error: `errorCode`, the message
|
|
39
|
-
* (the error's own text unless the adapter words it), and the verdict from
|
|
40
|
-
* classifyError.
|
|
41
|
-
*/
|
|
42
|
-
export function providerErrorResponse(err, errorCode, errorMessage = errorText(err)) {
|
|
43
|
-
return withRetryVerdict({ errorCode, errorMessage }, errorDecision(err));
|
|
44
|
-
}
|
|
45
|
-
/** True when a response is an error its adapter marked retryable: a provider-side failure. */
|
|
46
|
-
export function isRetryableErrorResponse(response) {
|
|
47
|
-
return !!response.errorCode && response.customMetadata?.[ERROR_RETRYABLE_KEY] === true;
|
|
48
|
-
}
|
|
@@ -2,11 +2,10 @@
|
|
|
2
2
|
* lib/models/fallbackAdapter.ts — `fallback_model:` and the per-provider
|
|
3
3
|
* circuit breaker (ADR 0044) on the engine's own model contract (ADR 0048).
|
|
4
4
|
*
|
|
5
|
-
* WHY:
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
* read from that: one ModelAdapter around a primary and a fallback adapter.
|
|
5
|
+
* WHY: on the contract a failure is a final response with `error` set,
|
|
6
|
+
* never a throw, and `error.retryable` already says whether another model
|
|
7
|
+
* may succeed. This wrapper is ADR 0044's rule set read from that: one
|
|
8
|
+
* ModelAdapter around a primary and a fallback adapter.
|
|
10
9
|
*
|
|
11
10
|
* THE RULES (ADR 0044, unchanged):
|
|
12
11
|
* - Only a provider-side failure counts and redirects: `error.retryable`
|
|
@@ -19,9 +18,9 @@
|
|
|
19
18
|
* was yielded and the failed final holds no parts. A call that failed
|
|
20
19
|
* midway is passed on, never replayed on another model.
|
|
21
20
|
* - The breaker (lib/models/circuitBreaker.ts) is keyed on the primary's
|
|
22
|
-
* `provider` and shared
|
|
23
|
-
*
|
|
24
|
-
* called. A success closes it; the fallback's own outcome is not counted.
|
|
21
|
+
* `provider` and shared by every wrapped agent in the process, so a
|
|
22
|
+
* provider tripped for one agent is skipped for the others. While it is
|
|
23
|
+
* open the primary is not called. A success closes it; the fallback's own outcome is not counted.
|
|
25
24
|
*
|
|
26
25
|
* THE FALLBACK'S REQUEST: the caller's request with `model` rewritten to the
|
|
27
26
|
* fallback's id. `reasoning` goes unchanged, and the fallback adapter maps it
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
* (lib/models/gateway.ts owns that decision). It extends the
|
|
9
9
|
* chat-completions base (lib/models/chatCompletionsAdapter.ts) the way
|
|
10
10
|
* Ollama does, because chat completions is the one dialect every gateway
|
|
11
|
-
* serves.
|
|
11
|
+
* serves.
|
|
12
12
|
*
|
|
13
13
|
* WHAT STAYS TRUE THROUGH THE GATEWAY:
|
|
14
14
|
* - Attribution. `provider` is the YAML id's provider (anthropic, openai,
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
* (lib/models/gateway.ts owns that decision). It extends the
|
|
9
9
|
* chat-completions base (lib/models/chatCompletionsAdapter.ts) the way
|
|
10
10
|
* Ollama does, because chat completions is the one dialect every gateway
|
|
11
|
-
* serves.
|
|
11
|
+
* serves.
|
|
12
12
|
*
|
|
13
13
|
* WHAT STAYS TRUE THROUGH THE GATEWAY:
|
|
14
14
|
* - Attribution. `provider` is the YAML id's provider (anthropic, openai,
|
|
@@ -3,12 +3,11 @@
|
|
|
3
3
|
* contract (lib/models/contract.ts, ADR 0048), on @google/genai directly.
|
|
4
4
|
*
|
|
5
5
|
* WHY this file exists:
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
* returns it only when asked (GEMINI_ADAPTER=engine) until gate G3.
|
|
6
|
+
* The native loop (ADR 0045) needs Gemini as a contract ModelAdapter that
|
|
7
|
+
* shapes its own requests, aggregates its own stream and reports its own
|
|
8
|
+
* failures. This is that adapter, and the only Gemini adapter:
|
|
9
|
+
* resolveAdapter (lib/models/adapterResolver.ts) returns it for every
|
|
10
|
+
* Gemini id (ADR 0100, ADR 0107).
|
|
12
11
|
*
|
|
13
12
|
* THE MAPPING is the Gemini table of wiki/models/model-contract.md;
|
|
14
13
|
* wiki/models/gemini-adapter.md records the choices made inside it:
|
|
@@ -3,12 +3,11 @@
|
|
|
3
3
|
* contract (lib/models/contract.ts, ADR 0048), on @google/genai directly.
|
|
4
4
|
*
|
|
5
5
|
* WHY this file exists:
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
* returns it only when asked (GEMINI_ADAPTER=engine) until gate G3.
|
|
6
|
+
* The native loop (ADR 0045) needs Gemini as a contract ModelAdapter that
|
|
7
|
+
* shapes its own requests, aggregates its own stream and reports its own
|
|
8
|
+
* failures. This is that adapter, and the only Gemini adapter:
|
|
9
|
+
* resolveAdapter (lib/models/adapterResolver.ts) returns it for every
|
|
10
|
+
* Gemini id (ADR 0100, ADR 0107).
|
|
12
11
|
*
|
|
13
12
|
* THE MAPPING is the Gemini table of wiki/models/model-contract.md;
|
|
14
13
|
* wiki/models/gemini-adapter.md records the choices made inside it:
|
|
@@ -102,8 +101,8 @@ export class GeminiAdapter {
|
|
|
102
101
|
this.#placeholderSignatures = options.placeholderSignatures ?? PLACEHOLDER_SIGNATURES_BY_DEFAULT;
|
|
103
102
|
}
|
|
104
103
|
async *generate(request) {
|
|
105
|
-
// The request's signal alone: the caller (the
|
|
106
|
-
//
|
|
104
|
+
// The request's signal alone: the caller (the native loop) passes the
|
|
105
|
+
// turn's (ADR 0053).
|
|
107
106
|
const signal = request.signal;
|
|
108
107
|
const model = request.model || this.model;
|
|
109
108
|
const reply = new ReplyBuilder(model, request.messages.length);
|
|
@@ -277,8 +276,8 @@ function buildRequest(request, options) {
|
|
|
277
276
|
const native = tools.length > (declared ? 1 : 0);
|
|
278
277
|
let toolConfig = toolConfigFor(request);
|
|
279
278
|
// Native tools beside function declarations: the response carries the
|
|
280
|
-
// server-side invocations, as
|
|
281
|
-
//
|
|
279
|
+
// server-side invocations, as ADK asked on every Gemini agent. The SDK
|
|
280
|
+
// refuses the flag for Vertex AI.
|
|
282
281
|
if (declared && native && options.geminiApi)
|
|
283
282
|
toolConfig = { ...toolConfig, includeServerSideToolInvocations: true };
|
|
284
283
|
if (toolConfig)
|
|
@@ -3,15 +3,15 @@
|
|
|
3
3
|
* written under (ADR 0046), and the prefix of a call id the genai mapping
|
|
4
4
|
* mints, in one place.
|
|
5
5
|
*
|
|
6
|
-
* WHY:
|
|
7
|
-
* `providerState`: the genai mapping (lib/models/genaiMapping.ts)
|
|
8
|
-
* engine's
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
6
|
+
* WHY: two modules write or replay a Gemini `thoughtSignature` as
|
|
7
|
+
* `providerState`: the genai mapping (lib/models/genaiMapping.ts) and the
|
|
8
|
+
* engine's Gemini adapter (lib/models/geminiAdapter.ts). A reader replays
|
|
9
|
+
* only the provider and kind it wrote (`providerStateOf`), so the two must
|
|
10
|
+
* spell them the same. Each re-exports these names where they were exported
|
|
11
|
+
* before.
|
|
12
12
|
*
|
|
13
|
-
* A leaf with no imports, so
|
|
14
|
-
*
|
|
13
|
+
* A leaf with no imports, so a module takes the ids without the mapping and
|
|
14
|
+
* its @google/genai import graph.
|
|
15
15
|
*/
|
|
16
16
|
/** The provider id the Gemini adapters report, and write their state under (lib/models/providerMap.ts). */
|
|
17
17
|
export declare const GEMINI_PROVIDER = "gemini";
|
|
@@ -3,15 +3,15 @@
|
|
|
3
3
|
* written under (ADR 0046), and the prefix of a call id the genai mapping
|
|
4
4
|
* mints, in one place.
|
|
5
5
|
*
|
|
6
|
-
* WHY:
|
|
7
|
-
* `providerState`: the genai mapping (lib/models/genaiMapping.ts)
|
|
8
|
-
* engine's
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
6
|
+
* WHY: two modules write or replay a Gemini `thoughtSignature` as
|
|
7
|
+
* `providerState`: the genai mapping (lib/models/genaiMapping.ts) and the
|
|
8
|
+
* engine's Gemini adapter (lib/models/geminiAdapter.ts). A reader replays
|
|
9
|
+
* only the provider and kind it wrote (`providerStateOf`), so the two must
|
|
10
|
+
* spell them the same. Each re-exports these names where they were exported
|
|
11
|
+
* before.
|
|
12
12
|
*
|
|
13
|
-
* A leaf with no imports, so
|
|
14
|
-
*
|
|
13
|
+
* A leaf with no imports, so a module takes the ids without the mapping and
|
|
14
|
+
* its @google/genai import graph.
|
|
15
15
|
*/
|
|
16
16
|
/** The provider id the Gemini adapters report, and write their state under (lib/models/providerMap.ts). */
|
|
17
17
|
export const GEMINI_PROVIDER = 'gemini';
|
|
@@ -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,15 +141,64 @@
|
|
|
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
|
-
import
|
|
153
|
-
import type {
|
|
152
|
+
import { FinishReason } from '@google/genai';
|
|
153
|
+
import type { Content, ContentUnion, GenerateContentConfig, GenerateContentResponseUsageMetadata, GroundingMetadata, Part as GenaiPart, CitationMetadata } from '@google/genai';
|
|
154
154
|
import type { Message, ModelRequest, ModelResponse, NativeTool, Part, ReasoningSetting, Sampling, ToolChoice, Usage } from './contract.ts';
|
|
155
155
|
import { GEMINI_PROVIDER, GENAI_PART_KIND, MINTED_CALL_ID_PREFIX, THOUGHT_SIGNATURE_KIND } from './geminiState.ts';
|
|
156
|
+
/**
|
|
157
|
+
* A tool as a request's `toolsDict` holds it: a name and, for a function
|
|
158
|
+
* tool, `_getDeclaration()` giving its declaration with a lowercase schema as
|
|
159
|
+
* `parameters` (contractToolDeclaration reads it). A server-side tool carries
|
|
160
|
+
* its NativeTool marker instead (lib/tools/tool.ts NATIVE_TOOL).
|
|
161
|
+
*/
|
|
162
|
+
export interface DeclaredTool {
|
|
163
|
+
name: string;
|
|
164
|
+
description?: string;
|
|
165
|
+
isLongRunning?: boolean;
|
|
166
|
+
_getDeclaration?(): unknown;
|
|
167
|
+
[key: string | symbol]: unknown;
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* One model request in genai's shape: the JSON ADK's LlmRequest carried,
|
|
171
|
+
* owned by the engine since 1.0.0. The summarizer, the memory extractor and
|
|
172
|
+
* the tracer build or read it; llmRequestToModelRequest maps it onto the
|
|
173
|
+
* contract.
|
|
174
|
+
*/
|
|
175
|
+
export interface LlmRequest {
|
|
176
|
+
model?: string;
|
|
177
|
+
contents: Content[];
|
|
178
|
+
config?: GenerateContentConfig;
|
|
179
|
+
liveConnectConfig?: Record<string, unknown>;
|
|
180
|
+
toolsDict: Record<string, DeclaredTool>;
|
|
181
|
+
allowedTools?: string[];
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* One model response in genai's shape: the JSON ADK's LlmResponse carried,
|
|
185
|
+
* and what a stored model event is made from (lib/runtime/native/step.ts).
|
|
186
|
+
* Owned by the engine since 1.0.0.
|
|
187
|
+
*/
|
|
188
|
+
export interface LlmResponse {
|
|
189
|
+
content?: Content;
|
|
190
|
+
groundingMetadata?: GroundingMetadata;
|
|
191
|
+
citationMetadata?: CitationMetadata;
|
|
192
|
+
partial?: boolean;
|
|
193
|
+
turnComplete?: boolean;
|
|
194
|
+
errorCode?: string;
|
|
195
|
+
errorMessage?: string;
|
|
196
|
+
interrupted?: boolean;
|
|
197
|
+
customMetadata?: Record<string, unknown>;
|
|
198
|
+
usageMetadata?: GenerateContentResponseUsageMetadata;
|
|
199
|
+
finishReason?: FinishReason;
|
|
200
|
+
modelVersion?: string;
|
|
201
|
+
}
|
|
156
202
|
/**
|
|
157
203
|
* The provider id the mapping writes its own state under (only a Gemini
|
|
158
204
|
* adapter replays it), and the providerState kind for a Gemini
|
|
@@ -209,7 +255,7 @@ export declare function messagesToContents(history: {
|
|
|
209
255
|
system?: string;
|
|
210
256
|
messages: readonly Message[];
|
|
211
257
|
}): GenaiHistory;
|
|
212
|
-
/** What an LlmRequest does not carry:
|
|
258
|
+
/** What an LlmRequest does not carry: the caller passes these beside it, as ADK did to generateContentAsync. */
|
|
213
259
|
export interface ModelRequestOptions {
|
|
214
260
|
/** The model id; default the request's own `model`. */
|
|
215
261
|
model?: string;
|
|
@@ -239,7 +285,7 @@ export declare function toolChoiceOf(config: GenerateContentConfig | undefined):
|
|
|
239
285
|
};
|
|
240
286
|
/** The sampling fields the contract carries, or undefined when none is set. The native request builder reads an agent's config through it too. */
|
|
241
287
|
export declare function samplingOf(config: GenerateContentConfig | undefined): Sampling | undefined;
|
|
242
|
-
/**
|
|
288
|
+
/** A genai-shaped LlmRequest as a ModelRequest (see the header for what is not mapped). */
|
|
243
289
|
export declare function llmRequestToModelRequest(llmRequest: LlmRequest, options?: ModelRequestOptions): ModelRequest;
|
|
244
290
|
/**
|
|
245
291
|
* Usage in Gemini's meanings: `candidatesTokenCount` excludes the thinking
|
|
@@ -254,17 +300,17 @@ export declare const TOO_DEEP_ARGUMENTS = "[arguments nested deeper than 64 leve
|
|
|
254
300
|
/**
|
|
255
301
|
* `response` with each part held to the contract (contractOutputPart): the
|
|
256
302
|
* same object when every part already is, else a copy with the parts
|
|
257
|
-
* checked. Used by modelResponseToLlmResponse
|
|
258
|
-
*
|
|
303
|
+
* checked. Used by modelResponseToLlmResponse and by the native step, so the
|
|
304
|
+
* step reads the same answer it stores. A
|
|
259
305
|
* response that is not an object is returned as it is: the caller fails on
|
|
260
306
|
* it as on any adapter that broke the contract.
|
|
261
307
|
*/
|
|
262
308
|
export declare function contractModelResponse<R extends ModelResponse>(response: R): R;
|
|
263
|
-
/** A ModelResponse as
|
|
309
|
+
/** A ModelResponse as a genai-shaped LlmResponse, the shape a stored model event is made from (see the header). */
|
|
264
310
|
export declare function modelResponseToLlmResponse(unchecked: ModelResponse): LlmResponse;
|
|
265
311
|
/** The native tools in `tools` that Gemini has no tool for, each once: modelRequestToLlmRequest leaves them out. */
|
|
266
312
|
export declare function nativeToolsWithoutGeminiTool(tools?: readonly NativeTool[]): NativeTool[];
|
|
267
|
-
/** A ModelRequest as the
|
|
313
|
+
/** A ModelRequest as the genai-shaped request for a Gemini model (see the header for what does not come back the same). */
|
|
268
314
|
export declare function modelRequestToLlmRequest(request: ModelRequest): LlmRequest;
|
|
269
315
|
/** What an LlmResponse does not carry, for the response it maps to. */
|
|
270
316
|
export interface ModelResponseOptions {
|