melchizedek-agents 0.18.0 → 0.20.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.env.example +12 -0
- package/CHANGELOG.md +1001 -0
- package/DOCUMENTATION.md +252 -65
- package/QUICKSTART.md +9 -6
- package/README.md +42 -4
- package/config/agents/examples/harness.yaml +3 -1
- package/config/agents/examples/model_zoo.yaml +10 -9
- package/config/agents/syndicateSchema.yaml +53 -16
- package/config/agents/templates/account_memory.yaml +2 -6
- package/config/agents/templates/case_desk.yaml +3 -9
- package/config/agents/templates/draft_review.yaml +3 -9
- package/config/agents/templates/intake_extractor.yaml +1 -3
- package/config/agents/templates/research_brief.yaml +3 -9
- package/config/agents/templates/research_desk.yaml +3 -9
- package/config/agents/templates/review_panel.yaml +4 -12
- package/config/agents/templates/support_triage.yaml +4 -12
- package/config/agents/templates/systems_operator.yaml +2 -6
- package/db/hardening.sql +7 -1
- package/db/migrations/0013_tool_credentials.sql +260 -0
- package/dist/lib/a2a/app.d.ts +70 -6
- package/dist/lib/a2a/app.js +107 -2
- package/dist/lib/a2a/executor.d.ts +20 -3
- package/dist/lib/a2a/executor.js +66 -7
- package/dist/lib/a2a/remoteAgent.d.ts +24 -9
- package/dist/lib/a2a/remoteAgent.js +31 -14
- package/dist/lib/adkPeer.d.ts +63 -0
- package/dist/lib/adkPeer.js +240 -0
- package/dist/lib/compile.d.ts +159 -30
- package/dist/lib/compile.js +215 -134
- package/dist/lib/compileAdk.d.ts +32 -0
- package/dist/lib/compileAdk.js +142 -0
- package/dist/lib/compileNative.d.ts +111 -0
- package/dist/lib/compileNative.js +278 -0
- package/dist/lib/config.d.ts +6 -5
- package/dist/lib/config.js +6 -5
- package/dist/lib/doctor.d.ts +28 -1
- package/dist/lib/doctor.js +64 -2
- package/dist/lib/index.d.ts +6 -1
- package/dist/lib/index.js +7 -1
- package/dist/lib/loadSyndicate.d.ts +18 -0
- package/dist/lib/memory/erase.d.ts +5 -3
- package/dist/lib/memory/erase.js +5 -2
- package/dist/lib/memory/namespace.d.ts +8 -1
- package/dist/lib/memory/namespace.js +12 -6
- package/dist/lib/memory/providers.js +2 -1
- package/dist/lib/memory/supabaseMemoryService.d.ts +37 -3
- package/dist/lib/memory/supabaseMemoryService.js +42 -2
- package/dist/lib/model.d.ts +47 -0
- package/dist/lib/model.js +37 -0
- package/dist/lib/models/adapterResolver.d.ts +115 -0
- package/dist/lib/models/adapterResolver.js +137 -0
- package/dist/lib/models/adkGeminiAdapter.d.ts +90 -0
- package/dist/lib/models/adkGeminiAdapter.js +369 -0
- package/dist/lib/models/adkShim.d.ts +111 -0
- package/dist/lib/models/adkShim.js +136 -0
- package/dist/lib/models/capabilities.d.ts +3 -0
- package/dist/lib/models/capabilities.js +33 -23
- package/dist/lib/models/chatCompletionsAdapter.d.ts +279 -0
- package/dist/lib/models/chatCompletionsAdapter.js +854 -0
- package/dist/lib/models/circuitBreaker.d.ts +42 -0
- package/dist/lib/models/circuitBreaker.js +70 -0
- package/dist/lib/models/claudeAdapter.d.ts +103 -0
- package/dist/lib/models/claudeAdapter.js +669 -0
- package/dist/lib/models/claudeLlm.d.ts +39 -62
- package/dist/lib/models/claudeLlm.js +45 -350
- package/dist/lib/models/claudeModels.d.ts +127 -0
- package/dist/lib/models/claudeModels.js +237 -0
- package/dist/lib/models/contract.d.ts +395 -0
- package/dist/lib/models/contract.js +39 -0
- package/dist/lib/models/endpoints.js +2 -1
- package/dist/lib/models/errorResponse.d.ts +50 -0
- package/dist/lib/models/errorResponse.js +48 -0
- package/dist/lib/models/fallback.d.ts +18 -11
- package/dist/lib/models/fallback.js +54 -43
- package/dist/lib/models/fallbackAdapter.d.ts +55 -0
- package/dist/lib/models/fallbackAdapter.js +62 -0
- package/dist/lib/models/gateway.js +2 -1
- package/dist/lib/models/gatewayAdapter.d.ts +51 -0
- package/dist/lib/models/gatewayAdapter.js +81 -0
- package/dist/lib/models/gatewayLlm.d.ts +12 -33
- package/dist/lib/models/gatewayLlm.js +16 -77
- package/dist/lib/models/geminiAdapter.d.ts +125 -0
- package/dist/lib/models/geminiAdapter.js +854 -0
- package/dist/lib/models/geminiState.d.ts +46 -0
- package/dist/lib/models/geminiState.js +51 -0
- package/dist/lib/models/genaiMapping.d.ts +283 -0
- package/dist/lib/models/genaiMapping.js +965 -0
- package/dist/lib/models/gptAdapter.d.ts +240 -0
- package/dist/lib/models/gptAdapter.js +804 -0
- package/dist/lib/models/gptLlm.d.ts +63 -123
- package/dist/lib/models/gptLlm.js +89 -603
- package/dist/lib/models/grokAdapter.d.ts +86 -0
- package/dist/lib/models/grokAdapter.js +142 -0
- package/dist/lib/models/grokLlm.d.ts +22 -45
- package/dist/lib/models/grokLlm.js +24 -69
- package/dist/lib/models/kimiAdapter.d.ts +157 -0
- package/dist/lib/models/kimiAdapter.js +203 -0
- package/dist/lib/models/kimiLlm.d.ts +15 -107
- package/dist/lib/models/kimiLlm.js +19 -155
- package/dist/lib/models/ollamaAdapter.d.ts +125 -0
- package/dist/lib/models/ollamaAdapter.js +155 -0
- package/dist/lib/models/ollamaLlm.d.ts +11 -107
- package/dist/lib/models/ollamaLlm.js +15 -153
- package/dist/lib/models/openAiCompatibleLlm.d.ts +73 -216
- package/dist/lib/models/openAiCompatibleLlm.js +109 -671
- package/dist/lib/models/providerState.d.ts +63 -0
- package/dist/lib/models/providerState.js +61 -0
- package/dist/lib/models/reasoning.d.ts +26 -0
- package/dist/lib/models/reasoning.js +59 -0
- package/dist/lib/models/registry.d.ts +62 -35
- package/dist/lib/models/registry.js +100 -124
- package/dist/lib/models/retry.d.ts +2 -1
- package/dist/lib/models/retry.js +3 -2
- package/dist/lib/models/schemaNormalize.d.ts +98 -0
- package/dist/lib/models/schemaNormalize.js +321 -1
- package/dist/lib/models/tracedGemini.d.ts +41 -0
- package/dist/lib/models/tracedGemini.js +98 -0
- package/dist/lib/models/urls.d.ts +11 -0
- package/dist/lib/models/urls.js +16 -0
- package/dist/lib/net/redirects.d.ts +21 -2
- package/dist/lib/net/redirects.js +11 -34
- package/dist/lib/observability/audit.d.ts +5 -1
- package/dist/lib/observability/lineage.d.ts +14 -0
- package/dist/lib/observability/lineage.js +33 -0
- package/dist/lib/observability/supabaseSpanExporter.d.ts +10 -4
- package/dist/lib/observability/supabaseSpanExporter.js +17 -9
- package/dist/lib/observability/tracer.d.ts +26 -8
- package/dist/lib/observability/tracer.js +43 -18
- package/dist/lib/runtime/adkMemoryBridge.d.ts +46 -0
- package/dist/lib/runtime/adkMemoryBridge.js +68 -0
- package/dist/lib/runtime/adkSessionBridge.d.ts +78 -0
- package/dist/lib/runtime/adkSessionBridge.js +176 -0
- package/dist/lib/runtime/approvals.d.ts +5 -0
- package/dist/lib/runtime/approvals.js +39 -8
- package/dist/lib/runtime/credentials.d.ts +61 -0
- package/dist/lib/runtime/credentials.js +67 -0
- package/dist/lib/runtime/events.d.ts +229 -0
- package/dist/lib/runtime/events.js +274 -0
- package/dist/lib/runtime/logging.d.ts +32 -0
- package/dist/lib/runtime/logging.js +55 -0
- package/dist/lib/runtime/memoryService.d.ts +72 -0
- package/dist/lib/runtime/memoryService.js +25 -0
- package/dist/lib/runtime/native/agentLoop.d.ts +209 -0
- package/dist/lib/runtime/native/agentLoop.js +705 -0
- package/dist/lib/runtime/native/compaction.d.ts +103 -0
- package/dist/lib/runtime/native/compaction.js +191 -0
- package/dist/lib/runtime/native/delegate.d.ts +151 -0
- package/dist/lib/runtime/native/delegate.js +256 -0
- package/dist/lib/runtime/native/history.d.ts +83 -0
- package/dist/lib/runtime/native/history.js +312 -0
- package/dist/lib/runtime/native/interrupts.d.ts +129 -0
- package/dist/lib/runtime/native/interrupts.js +310 -0
- package/dist/lib/runtime/native/request.d.ts +215 -0
- package/dist/lib/runtime/native/request.js +585 -0
- package/dist/lib/runtime/native/selfCorrection.d.ts +164 -0
- package/dist/lib/runtime/native/selfCorrection.js +327 -0
- package/dist/lib/runtime/native/step.d.ts +156 -0
- package/dist/lib/runtime/native/step.js +263 -0
- package/dist/lib/runtime/native/taskMode.d.ts +64 -0
- package/dist/lib/runtime/native/taskMode.js +126 -0
- package/dist/lib/runtime/native/telemetry.d.ts +75 -0
- package/dist/lib/runtime/native/telemetry.js +299 -0
- package/dist/lib/runtime/native/tempState.d.ts +31 -0
- package/dist/lib/runtime/native/tempState.js +56 -0
- package/dist/lib/runtime/nativeTurn.d.ts +86 -0
- package/dist/lib/runtime/nativeTurn.js +107 -0
- package/dist/lib/runtime/questions.d.ts +29 -7
- package/dist/lib/runtime/questions.js +47 -32
- package/dist/lib/runtime/runtimeFlag.d.ts +38 -0
- package/dist/lib/runtime/runtimeFlag.js +58 -0
- package/dist/lib/runtime/sessions.d.ts +166 -0
- package/dist/lib/runtime/sessions.js +201 -0
- package/dist/lib/runtime/syndicateTurn.d.ts +46 -5
- package/dist/lib/runtime/syndicateTurn.js +233 -36
- package/dist/lib/runtime/valueDepth.d.ts +23 -0
- package/dist/lib/runtime/valueDepth.js +41 -0
- package/dist/lib/session/supabaseSessionService.d.ts +65 -18
- package/dist/lib/session/supabaseSessionService.js +148 -105
- package/dist/lib/session/transcript.d.ts +69 -23
- package/dist/lib/session/transcript.js +105 -29
- package/dist/lib/skills.js +33 -7
- package/dist/lib/storage/postgres/credentialStore.d.ts +20 -0
- package/dist/lib/storage/postgres/credentialStore.js +82 -0
- package/dist/lib/storage/postgres/index.d.ts +12 -0
- package/dist/lib/storage/postgres/index.js +6 -1
- package/dist/lib/storage/postgres/sessionService.d.ts +44 -16
- package/dist/lib/storage/postgres/sessionService.js +128 -66
- package/dist/lib/syndicateSchema.d.ts +49 -0
- package/dist/lib/syndicateSchema.js +99 -9
- package/dist/lib/toolRegistry.d.ts +26 -2
- package/dist/lib/toolRegistry.js +73 -17
- package/dist/lib/tools/adkTool.d.ts +81 -0
- package/dist/lib/tools/adkTool.js +268 -0
- package/dist/lib/tools/auth.d.ts +118 -0
- package/dist/lib/tools/auth.js +89 -0
- package/dist/lib/tools/collectionsSearchTool.d.ts +8 -7
- package/dist/lib/tools/collectionsSearchTool.js +12 -27
- package/dist/lib/tools/credentialCipher.d.ts +58 -0
- package/dist/lib/tools/credentialCipher.js +116 -0
- package/dist/lib/tools/credentialStore.d.ts +77 -0
- package/dist/lib/tools/credentialStore.js +246 -0
- package/dist/lib/tools/examples.d.ts +43 -0
- package/dist/lib/tools/examples.js +62 -0
- package/dist/lib/tools/generateImageTool.d.ts +15 -6
- package/dist/lib/tools/generateImageTool.js +19 -29
- package/dist/lib/tools/inspectImageTool.d.ts +9 -6
- package/dist/lib/tools/inspectImageTool.js +13 -17
- package/dist/lib/tools/mcpToolFactory.d.ts +42 -1
- package/dist/lib/tools/mcpToolFactory.js +46 -47
- package/dist/lib/tools/memoryTools.d.ts +61 -0
- package/dist/lib/tools/memoryTools.js +119 -0
- package/dist/lib/tools/nativeTools.d.ts +38 -0
- package/dist/lib/tools/nativeTools.js +43 -0
- package/dist/lib/tools/oauthConsent.d.ts +181 -0
- package/dist/lib/tools/oauthConsent.js +330 -0
- package/dist/lib/tools/openapi/call.d.ts +108 -0
- package/dist/lib/tools/openapi/call.js +295 -0
- package/dist/lib/tools/openapi/parse.d.ts +147 -0
- package/dist/lib/tools/openapi/parse.js +570 -0
- package/dist/lib/tools/openapiTools.d.ts +25 -17
- package/dist/lib/tools/openapiTools.js +124 -121
- package/dist/lib/tools/scienceTools.d.ts +14 -14
- package/dist/lib/tools/skillToolset.d.ts +58 -87
- package/dist/lib/tools/skillToolset.js +61 -142
- package/dist/lib/tools/skills/env.d.ts +58 -0
- package/dist/lib/tools/skills/env.js +165 -0
- package/dist/lib/tools/skills/executor.d.ts +114 -0
- package/dist/lib/tools/skills/executor.js +331 -0
- package/dist/lib/tools/skills/frontmatter.d.ts +79 -0
- package/dist/lib/tools/skills/frontmatter.js +215 -0
- package/dist/lib/tools/skills/loader.d.ts +91 -0
- package/dist/lib/tools/skills/loader.js +257 -0
- package/dist/lib/tools/skills/tools.d.ts +187 -0
- package/dist/lib/tools/skills/tools.js +386 -0
- package/dist/lib/tools/taskTools.d.ts +15 -15
- package/dist/lib/tools/tool.d.ts +354 -0
- package/dist/lib/tools/tool.js +304 -0
- package/dist/lib/tools/toolContract.d.ts +89 -33
- package/dist/lib/tools/toolContract.js +104 -82
- package/dist/lib/tools/urlContextTool.d.ts +4 -1
- package/dist/lib/tools/urlContextTool.js +6 -2
- package/dist/lib/tools/webExtractTool.d.ts +3 -3
- package/dist/lib/tools/webExtractTool.js +2 -1
- package/dist/lib/tools/webSearchTool.d.ts +7 -10
- package/dist/lib/tools/webSearchTool.js +15 -60
- package/dist/lib/tools/wikiTools.d.ts +19 -19
- package/dist/lib/tools/wikiTools.js +13 -9
- package/dist/lib/tools/xApiSearchTool.d.ts +3 -3
- package/dist/lib/tools/xApiSearchTool.js +2 -1
- package/dist/lib/tools/xSearchTool.d.ts +8 -10
- package/dist/lib/tools/xSearchTool.js +12 -63
- package/dist/lib/tools/xaiSearchParams.d.ts +41 -0
- package/dist/lib/tools/xaiSearchParams.js +126 -0
- package/dist/lib/wiki/agentRun.d.ts +12 -0
- package/dist/lib/wiki/agentRun.js +74 -35
- package/dist/lib/wiki/entities.d.ts +12 -0
- package/dist/lib/wiki/entities.js +45 -3
- package/dist/lib/workflow/agentNode.d.ts +153 -0
- package/dist/lib/workflow/agentNode.js +365 -0
- package/dist/lib/workflow/graph.d.ts +178 -0
- package/dist/lib/workflow/graph.js +468 -0
- package/dist/lib/workflow/nodeEvents.d.ts +50 -0
- package/dist/lib/workflow/nodeEvents.js +101 -0
- package/dist/lib/workflow/pause.d.ts +122 -0
- package/dist/lib/workflow/pause.js +180 -0
- package/dist/lib/workflow/resume.d.ts +166 -0
- package/dist/lib/workflow/resume.js +441 -0
- package/dist/lib/workflow/route.d.ts +58 -0
- package/dist/lib/workflow/route.js +69 -0
- package/dist/lib/workflow/scheduler.d.ts +418 -0
- package/dist/lib/workflow/scheduler.js +756 -0
- package/dist/lib/workflow/toolNode.d.ts +127 -0
- package/dist/lib/workflow/toolNode.js +236 -0
- package/dist/lib/workflow/turn.d.ts +118 -0
- package/dist/lib/workflow/turn.js +216 -0
- package/dist/lib/workflow.d.ts +33 -11
- package/dist/lib/workflow.js +49 -27
- package/dist/lib/workflowConfig.d.ts +7 -2
- package/dist/lib/workflowConfig.js +7 -12
- package/dist/scripts/a2a_server.js +4 -3
- package/dist/scripts/assistant_worker.d.ts +2 -1
- package/dist/scripts/assistant_worker.js +9 -4
- package/dist/scripts/doctor.d.ts +3 -1
- package/dist/scripts/doctor.js +4 -2
- package/dist/scripts/syndicate_chat.js +19 -10
- package/package.json +9 -3
- package/skills/briefs/melchizedek-author.md +3 -2
- package/skills/briefs/melchizedek-models.md +13 -9
- package/skills/briefs/melchizedek.md +3 -3
- package/skills/melchizedek/SKILL.md +2 -1
- package/skills/melchizedek-author/SKILL.md +2 -1
- package/skills/melchizedek-author/assets/minimal.yaml +2 -0
- package/skills/melchizedek-models/SKILL.md +23 -6
|
@@ -1,239 +1,96 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* lib/models/openAiCompatibleLlm.ts —
|
|
3
|
-
*
|
|
2
|
+
* lib/models/openAiCompatibleLlm.ts — the ADK shim base for every
|
|
3
|
+
* chat-completions adapter (Ollama, Kimi, the gateway).
|
|
4
4
|
*
|
|
5
5
|
* WHY this file exists:
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
6
|
+
* The chat-completions translation lives on the engine's own model
|
|
7
|
+
* contract, in lib/models/chatCompletionsAdapter.ts and one adapter per
|
|
8
|
+
* provider (ollamaAdapter.ts, kimiAdapter.ts, gatewayAdapter.ts). ADK
|
|
9
|
+
* still runs every turn (ADR 0045), so each adapter runs behind an ADK
|
|
10
|
+
* BaseLlm: OllamaLlm, KimiLlm and GatewayLlm, subclasses of this class,
|
|
11
|
+
* which is an AdkShim (lib/models/adkShim.ts, ADR 0053). The shim charges
|
|
12
|
+
* the turn, opens the llm.request span and maps the request and responses;
|
|
13
|
+
* the adapter does the provider's work.
|
|
14
14
|
*
|
|
15
|
-
* WHAT
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
15
|
+
* WHAT THIS CLASS ADDS TO THE SHIM (ADR 0057): the ADK path stays what it
|
|
16
|
+
* was before the adapters moved onto the contract.
|
|
17
|
+
* - The request: an agent's older generateContentConfig spelling that the
|
|
18
|
+
* contract leaves out rides beside it (olderSpellingOf): an effort word
|
|
19
|
+
* that is no contract level (Kimi K3's `max`). JSON mode without a
|
|
20
|
+
* schema is the contract's `outputFormat` (ADR 0061).
|
|
21
|
+
* - The response: the final keeps the shape these classes always yielded,
|
|
22
|
+
* which the ledger and FallbackLlm read. usageMetadata counts the
|
|
23
|
+
* reasoning inside candidatesTokenCount, as the provider's
|
|
24
|
+
* completion_tokens does, so llm.tokens.output and the turn's charge are
|
|
25
|
+
* unchanged (the shim's default is Gemini's meaning, which excludes it).
|
|
26
|
+
* finishReason is set only for a reply cut short (MAX_TOKENS); a final
|
|
27
|
+
* with no parts keeps its empty content; an HTTP failure keeps its
|
|
28
|
+
* top-level `status` and `retryable` beside the verdict in
|
|
29
|
+
* customMetadata.
|
|
30
|
+
*
|
|
31
|
+
* A /chat/completions provider of your own is a ChatCompletionsAdapter
|
|
32
|
+
* subclass (the endpoint, headers, wire name, reasoning field and error
|
|
33
|
+
* wording), run under ADK as `adkShim(adapter)` or as a subclass of this
|
|
34
|
+
* class.
|
|
31
35
|
*/
|
|
32
|
-
import {
|
|
36
|
+
import type { GenerateContentConfig } from '@google/genai';
|
|
33
37
|
import type { LlmRequest, LlmResponse } from '@google/adk';
|
|
34
|
-
import
|
|
35
|
-
type
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
image_url: {
|
|
41
|
-
url: string;
|
|
42
|
-
};
|
|
43
|
-
};
|
|
44
|
-
type OpenAiMessage = {
|
|
45
|
-
role: 'system';
|
|
46
|
-
content: string;
|
|
47
|
-
} | {
|
|
48
|
-
role: 'user';
|
|
49
|
-
content: string | OpenAiContentPart[];
|
|
50
|
-
} | {
|
|
51
|
-
role: 'assistant';
|
|
52
|
-
content: string | null;
|
|
53
|
-
tool_calls?: Array<{
|
|
54
|
-
id: string;
|
|
55
|
-
type: 'function';
|
|
56
|
-
function: {
|
|
57
|
-
name: string;
|
|
58
|
-
arguments: string;
|
|
59
|
-
};
|
|
60
|
-
}>;
|
|
61
|
-
} | {
|
|
62
|
-
role: 'tool';
|
|
63
|
-
tool_call_id: string;
|
|
64
|
-
content: string;
|
|
65
|
-
};
|
|
38
|
+
import { AdkShim } from './adkShim.ts';
|
|
39
|
+
import type { AdkShimOptions } from './adkShim.ts';
|
|
40
|
+
import type { ModelResponse, Usage } from './contract.ts';
|
|
41
|
+
import type { ModelRequestOptions } from './genaiMapping.ts';
|
|
42
|
+
import type { ChatCompletionsAdapter, ChatCompletionsRequest, ChatMessage, OlderSpelling } from './chatCompletionsAdapter.ts';
|
|
43
|
+
export { REASONING_CONTENT_KIND, splitThinkBlocks, ThinkStreamSplitter } from './chatCompletionsAdapter.ts';
|
|
66
44
|
/**
|
|
67
|
-
*
|
|
68
|
-
*
|
|
69
|
-
*
|
|
70
|
-
*
|
|
71
|
-
*
|
|
45
|
+
* What a generateContentConfig asks of a chat-completions provider that the
|
|
46
|
+
* contract has no field for, or undefined when it asks nothing more:
|
|
47
|
+
* `reasoningEffort` when it is a word no ReasoningSetting carries (`max`,
|
|
48
|
+
* `xhigh`), sent as written. JSON mode without a schema is no longer here:
|
|
49
|
+
* the genai mapping reads it as `outputFormat: 'json'` (ADR 0061).
|
|
72
50
|
*/
|
|
73
|
-
export declare function
|
|
74
|
-
reasoning: string;
|
|
75
|
-
answer: string;
|
|
76
|
-
};
|
|
51
|
+
export declare function olderSpellingOf(config: GenerateContentConfig | undefined): OlderSpelling | undefined;
|
|
77
52
|
/**
|
|
78
|
-
*
|
|
79
|
-
*
|
|
80
|
-
*
|
|
81
|
-
* `</think>` has usually NOT arrived yet, so the regex matches nothing and
|
|
82
|
-
* the whole scratchpad would be printed as the reply. A tag can also be
|
|
83
|
-
* split mid-delta ("<thi" + "nk>"), so any tail that could still grow into
|
|
84
|
-
* a tag is held back instead of being emitted as answer text.
|
|
85
|
-
*
|
|
86
|
-
* Providers that report reasoning in a discrete field (Ollama's
|
|
87
|
-
* `delta.reasoning`, others' `reasoning_content`) never open a think block
|
|
88
|
-
* and pass straight through this untouched.
|
|
53
|
+
* Usage as the chat-completions classes have always reported it on the ADK
|
|
54
|
+
* path: candidatesTokenCount is the provider's completion_tokens, reasoning
|
|
55
|
+
* included, and thoughtsTokenCount the reasoning part of it.
|
|
89
56
|
*/
|
|
90
|
-
export declare
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
};
|
|
98
|
-
/** Releases the held tail; the stream ended, so it was never a tag. */
|
|
99
|
-
flush(): {
|
|
100
|
-
reasoning: string;
|
|
101
|
-
answer: string;
|
|
102
|
-
};
|
|
103
|
-
}
|
|
104
|
-
export declare abstract class OpenAiCompatibleLlm extends BaseLlm {
|
|
105
|
-
private webSearchWarned;
|
|
106
|
-
private retryWarned;
|
|
107
|
-
/** Provider id for telemetry, e.g. 'ollama', 'xai'. */
|
|
108
|
-
protected abstract providerId(): string;
|
|
109
|
-
/** Full chat-completions URL, e.g. "https://api.x.ai/v1/chat/completions". */
|
|
110
|
-
protected abstract endpointUrl(): string;
|
|
111
|
-
/** Auth/extra headers. Content-Type is added by the base. */
|
|
112
|
-
protected abstract headers(): Record<string, string>;
|
|
113
|
-
/** Model id as the wire expects it (e.g. strip the "ollama/" namespace). */
|
|
114
|
-
protected wireModelName(): string;
|
|
115
|
-
/**
|
|
116
|
-
* How the request reaches the provider: 'direct' (the provider's own
|
|
117
|
-
* endpoint) or 'gateway:<id>' (lib/models/gatewayLlm.ts). Recorded on the
|
|
118
|
-
* llm.request span as llm.transport so the ledger can tell a native call
|
|
119
|
-
* from a proxied one while llm.provider keeps the upstream attribution.
|
|
120
|
-
*/
|
|
57
|
+
export declare function chatUsageMetadata(usage: Usage): NonNullable<LlmResponse['usageMetadata']>;
|
|
58
|
+
export declare abstract class OpenAiCompatibleLlm extends AdkShim {
|
|
59
|
+
readonly adapter: ChatCompletionsAdapter;
|
|
60
|
+
constructor(adapter: ChatCompletionsAdapter, options?: AdkShimOptions);
|
|
61
|
+
/** Provider id for telemetry: the adapter's (a gateway reports the upstream provider). */
|
|
62
|
+
protected providerId(): string;
|
|
63
|
+
/** How the request reaches the provider: 'direct' or 'gateway:<id>' (llm.transport). */
|
|
121
64
|
protected transport(): string;
|
|
122
|
-
/**
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
/**
|
|
126
|
-
* Whether the endpoint honors stream_options.include_usage. Without it an
|
|
127
|
-
* SSE turn reports no token counts at all; Ollama and xAI both support it.
|
|
128
|
-
*/
|
|
129
|
-
protected supportsStreamUsage(): boolean;
|
|
130
|
-
protected extraBodyFields(_llmRequest: LlmRequest): Record<string, unknown>;
|
|
131
|
-
/**
|
|
132
|
-
* Body fields enabling the provider's NATIVE web search, or null when the
|
|
133
|
-
* provider has none (the base then omits the tool and warns once).
|
|
134
|
-
*/
|
|
135
|
-
protected webSearchBodyFields(): Record<string, unknown> | null;
|
|
136
|
-
/**
|
|
137
|
-
* Extracts reasoning from the response message. Default: "<think>" blocks
|
|
138
|
-
* in content plus the reasoning_content / reasoning fields emitted by
|
|
139
|
-
* OpenAI-compatible reasoning models.
|
|
140
|
-
*/
|
|
141
|
-
protected extractReasoning(message: {
|
|
142
|
-
content?: string | null;
|
|
143
|
-
reasoning_content?: string;
|
|
144
|
-
reasoning?: string;
|
|
145
|
-
}): {
|
|
146
|
-
reasoning: string;
|
|
147
|
-
answer: string;
|
|
148
|
-
};
|
|
149
|
-
/** Yielded before the HTTP call when a precondition is missing (e.g. no
|
|
150
|
-
* API key). Return undefined when ready to call. */
|
|
151
|
-
protected missingRequirement(): LlmResponse | undefined;
|
|
152
|
-
/** Error response for a non-2xx HTTP status. */
|
|
153
|
-
protected httpError(status: number, detail: string): LlmResponse;
|
|
154
|
-
/**
|
|
155
|
-
* Whether a turn that ended with no answer after thinking (noAnswerError)
|
|
156
|
-
* is sent once more with reasoning_effort "none". Default: never. An
|
|
157
|
-
* adapter for local reasoning models turns it on (OllamaLlm).
|
|
158
|
-
*/
|
|
159
|
-
protected retriesWithoutThinking(): boolean;
|
|
160
|
-
/**
|
|
161
|
-
* Error response for a turn that produced reasoning or ran out of tokens
|
|
162
|
-
* but no reply and no tool call. `truncated` is true when the provider
|
|
163
|
-
* reported finish_reason "length" (the token budget or context window
|
|
164
|
-
* filled up); false when it stopped after thinking with nothing to say.
|
|
165
|
-
*/
|
|
166
|
-
protected noAnswerError(truncated: boolean): LlmResponse;
|
|
167
|
-
/** Error response when the endpoint can't be reached at all. */
|
|
168
|
-
protected unreachable(message: string): LlmResponse;
|
|
169
|
-
generateContentAsync(llmRequest: LlmRequest, stream?: boolean): AsyncGenerator<LlmResponse, void>;
|
|
170
|
-
/**
|
|
171
|
-
* One request, retried once without thinking when the adapter opts in and
|
|
172
|
-
* the model thought its way to no answer (ADR 0027): a local reasoning
|
|
173
|
-
* model can spend its whole context window on the scratchpad. The first
|
|
174
|
-
* attempt's error is held back, never yielded; what it spent is added to
|
|
175
|
-
* the retry's usage, so budgets and the ledger still count it. An agent
|
|
176
|
-
* that already runs with reasoningEffort "none" is not retried.
|
|
177
|
-
*/
|
|
178
|
-
private generateInner;
|
|
179
|
-
private attempt;
|
|
180
|
-
/**
|
|
181
|
-
* SSE path: display-only partials as the tokens land, then ONE final
|
|
182
|
-
* non-partial response carrying the complete text, tool calls and usage.
|
|
183
|
-
*
|
|
184
|
-
* WHY the final repeats text already streamed: ADK's runner persists only
|
|
185
|
-
* non-partial events (`if (!event.partial) appendEvent(...)`), so a final
|
|
186
|
-
* without text would show the reply on screen and lose it from session
|
|
187
|
-
* history. Printers therefore skip text on a turnComplete event whose
|
|
188
|
-
* partials they already rendered — see scripts/syndicate_chat.ts.
|
|
189
|
-
*
|
|
190
|
-
* Thinking is deliberately NOT carried on the final: the scratchpad is
|
|
191
|
-
* display-only and stays out of history, which is what keeps it from
|
|
192
|
-
* being replayed to the model on the next turn.
|
|
193
|
-
*/
|
|
194
|
-
private streamResponse;
|
|
195
|
-
/**
|
|
196
|
-
* The one non-partial response that closes a turn, on both paths.
|
|
197
|
-
*
|
|
198
|
-
* WHY an empty reply becomes an error: ADK drops a final response with no
|
|
199
|
-
* parts and no errorCode (llm_agent: "empty content → return"), so the
|
|
200
|
-
* last event left is the thought partial — ADK logs "The last event is
|
|
201
|
-
* partial, which is not expected." and the turn ends with empty text and
|
|
202
|
-
* no reason. That is exactly what a thinking model does when its
|
|
203
|
-
* scratchpad fills the budget (finish_reason "length"): the answer never
|
|
204
|
-
* starts. Naming it lets the caller see why, and still carries the usage
|
|
205
|
-
* so the tokens spent thinking are counted.
|
|
206
|
-
*
|
|
207
|
-
* A reply that was cut short but did start keeps its text and is marked
|
|
208
|
-
* finishReason MAX_TOKENS.
|
|
209
|
-
*/
|
|
210
|
-
private finalResponse;
|
|
211
|
-
/** ADK Contents (Google GenAI format) → OpenAI-compatible chat messages. */
|
|
212
|
-
protected buildMessages(llmRequest: LlmRequest): OpenAiMessage[];
|
|
213
|
-
/** ADK toolsDict → OpenAI function-tool definitions (lowercase schemas). */
|
|
65
|
+
/** The chat messages the adapter sends for this LlmRequest. */
|
|
66
|
+
protected buildMessages(llmRequest: LlmRequest): ChatMessage[];
|
|
67
|
+
/** The function tools the adapter sends for this LlmRequest (lowercase schemas). */
|
|
214
68
|
protected buildTools(llmRequest: LlmRequest): unknown[];
|
|
215
|
-
/**
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
connect(_llmRequest: LlmRequest): Promise<BaseLlmConnection>;
|
|
69
|
+
/** The genai mapping's request, with the older spelling the contract leaves out. */
|
|
70
|
+
protected toModelRequest(llmRequest: LlmRequest, options: ModelRequestOptions): ChatCompletionsRequest;
|
|
71
|
+
/** The genai mapping's response, in the shape these classes have always yielded (see the header). */
|
|
72
|
+
protected toLlmResponse(response: ModelResponse): LlmResponse;
|
|
220
73
|
}
|
|
221
74
|
/**
|
|
222
75
|
* Stamps an HTTP error response with its numeric status and whether that
|
|
223
|
-
* status is transient,
|
|
224
|
-
*
|
|
225
|
-
*
|
|
226
|
-
*
|
|
227
|
-
* errorCode and wording and still gets the fields.
|
|
76
|
+
* status is transient, and the same verdict in customMetadata
|
|
77
|
+
* ('error.retryable', 'error.status'), where FallbackLlm reads it
|
|
78
|
+
* (lib/models/errorResponse.ts). The chat-completions shims take these
|
|
79
|
+
* fields from their adapter's error final instead (toLlmResponse).
|
|
228
80
|
*/
|
|
229
81
|
export declare function withHttpStatus(resp: LlmResponse, status: number): LlmResponse;
|
|
230
|
-
type
|
|
231
|
-
/** Two usage records summed, field by field. */
|
|
232
|
-
export declare function addUsage(a:
|
|
82
|
+
type GenaiUsage = NonNullable<ReturnType<typeof mapUsage>>;
|
|
83
|
+
/** Two genai usage records summed, field by field. */
|
|
84
|
+
export declare function addUsage(a: GenaiUsage | undefined, b: GenaiUsage | undefined): GenaiUsage | undefined;
|
|
85
|
+
/**
|
|
86
|
+
* OpenAI-style usage → GenAI usageMetadata in the ADK-path meaning
|
|
87
|
+
* (completion_tokens, reasoning included, as candidatesTokenCount), or
|
|
88
|
+
* undefined when absent. The contract's meaning is chatUsage in
|
|
89
|
+
* lib/models/chatCompletionsAdapter.ts.
|
|
90
|
+
*/
|
|
233
91
|
export declare function mapUsage(usage: any): {
|
|
234
92
|
promptTokenCount?: number;
|
|
235
93
|
candidatesTokenCount?: number;
|
|
236
94
|
thoughtsTokenCount?: number;
|
|
237
95
|
totalTokenCount?: number;
|
|
238
96
|
} | undefined;
|
|
239
|
-
export {};
|