@dexto/core 1.6.1 → 1.6.3
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/dist/agent/DextoAgent.cjs +54 -0
- package/dist/agent/DextoAgent.d.ts +12 -1
- package/dist/agent/DextoAgent.d.ts.map +1 -1
- package/dist/agent/DextoAgent.js +54 -0
- package/dist/agent/agent-options.d.ts +6 -1
- package/dist/agent/agent-options.d.ts.map +1 -1
- package/dist/events/index.d.ts +9 -1
- package/dist/events/index.d.ts.map +1 -1
- package/dist/llm/executor/provider-options.cjs +223 -28
- package/dist/llm/executor/provider-options.d.ts +3 -37
- package/dist/llm/executor/provider-options.d.ts.map +1 -1
- package/dist/llm/executor/provider-options.js +227 -27
- package/dist/llm/executor/stream-processor.cjs +54 -31
- package/dist/llm/executor/stream-processor.d.ts +9 -2
- package/dist/llm/executor/stream-processor.d.ts.map +1 -1
- package/dist/llm/executor/stream-processor.js +52 -29
- package/dist/llm/executor/turn-executor.cjs +63 -41
- package/dist/llm/executor/turn-executor.d.ts +2 -2
- package/dist/llm/executor/turn-executor.d.ts.map +1 -1
- package/dist/llm/executor/turn-executor.js +53 -31
- package/dist/llm/formatters/vercel.cjs +15 -3
- package/dist/llm/formatters/vercel.d.ts +1 -0
- package/dist/llm/formatters/vercel.d.ts.map +1 -1
- package/dist/llm/formatters/vercel.js +15 -3
- package/dist/llm/index.cjs +8 -0
- package/dist/llm/index.d.ts +2 -1
- package/dist/llm/index.d.ts.map +1 -1
- package/dist/llm/index.js +7 -0
- package/dist/llm/providers/local/schemas.d.ts +2 -2
- package/dist/llm/providers/openrouter-model-registry.cjs +66 -11
- package/dist/llm/providers/openrouter-model-registry.d.ts +26 -0
- package/dist/llm/providers/openrouter-model-registry.d.ts.map +1 -1
- package/dist/llm/providers/openrouter-model-registry.js +65 -11
- package/dist/{utils/user-info.cjs → llm/reasoning/anthropic-betas.cjs} +9 -8
- package/dist/llm/reasoning/anthropic-betas.d.ts +3 -0
- package/dist/llm/reasoning/anthropic-betas.d.ts.map +1 -0
- package/dist/llm/reasoning/anthropic-betas.js +7 -0
- package/dist/llm/reasoning/anthropic-thinking.cjs +79 -0
- package/dist/llm/reasoning/anthropic-thinking.d.ts +15 -0
- package/dist/llm/reasoning/anthropic-thinking.d.ts.map +1 -0
- package/dist/llm/reasoning/anthropic-thinking.js +52 -0
- package/dist/llm/reasoning/openai-reasoning-effort.cjs +86 -0
- package/dist/llm/reasoning/openai-reasoning-effort.d.ts +5 -0
- package/dist/llm/reasoning/openai-reasoning-effort.d.ts.map +1 -0
- package/dist/llm/reasoning/openai-reasoning-effort.js +61 -0
- package/dist/llm/reasoning/profile.cjs +113 -0
- package/dist/llm/reasoning/profile.d.ts +13 -0
- package/dist/llm/reasoning/profile.d.ts.map +1 -0
- package/dist/llm/reasoning/profile.js +92 -0
- package/dist/llm/reasoning/profiles/anthropic.cjs +61 -0
- package/dist/llm/reasoning/profiles/anthropic.d.ts +8 -0
- package/dist/llm/reasoning/profiles/anthropic.d.ts.map +1 -0
- package/dist/llm/reasoning/profiles/anthropic.js +45 -0
- package/dist/llm/reasoning/profiles/bedrock.cjs +54 -0
- package/dist/llm/reasoning/profiles/bedrock.d.ts +3 -0
- package/dist/llm/reasoning/profiles/bedrock.d.ts.map +1 -0
- package/dist/llm/reasoning/profiles/bedrock.js +36 -0
- package/dist/llm/reasoning/profiles/google.cjs +45 -0
- package/dist/llm/reasoning/profiles/google.d.ts +9 -0
- package/dist/llm/reasoning/profiles/google.d.ts.map +1 -0
- package/dist/llm/reasoning/profiles/google.js +21 -0
- package/dist/llm/reasoning/profiles/openai-compatible.cjs +39 -0
- package/dist/llm/reasoning/profiles/openai-compatible.d.ts +3 -0
- package/dist/llm/reasoning/profiles/openai-compatible.d.ts.map +1 -0
- package/dist/llm/reasoning/profiles/openai-compatible.js +16 -0
- package/dist/llm/reasoning/profiles/openai.cjs +41 -0
- package/dist/llm/reasoning/profiles/openai.d.ts +3 -0
- package/dist/llm/reasoning/profiles/openai.d.ts.map +1 -0
- package/dist/llm/reasoning/profiles/openai.js +18 -0
- package/dist/llm/reasoning/profiles/openrouter.cjs +83 -0
- package/dist/llm/reasoning/profiles/openrouter.d.ts +10 -0
- package/dist/llm/reasoning/profiles/openrouter.d.ts.map +1 -0
- package/dist/llm/reasoning/profiles/openrouter.js +59 -0
- package/dist/llm/reasoning/profiles/shared.cjs +80 -0
- package/dist/llm/reasoning/profiles/shared.d.ts +25 -0
- package/dist/llm/reasoning/profiles/shared.d.ts.map +1 -0
- package/dist/llm/reasoning/profiles/shared.js +53 -0
- package/dist/llm/reasoning/profiles/vertex.cjs +46 -0
- package/dist/llm/reasoning/profiles/vertex.d.ts +3 -0
- package/dist/llm/reasoning/profiles/vertex.d.ts.map +1 -0
- package/dist/llm/reasoning/profiles/vertex.js +23 -0
- package/dist/llm/registry/auto-update.cjs +18 -0
- package/dist/llm/registry/auto-update.d.ts.map +1 -1
- package/dist/llm/registry/auto-update.js +18 -0
- package/dist/llm/registry/index.cjs +126 -26
- package/dist/llm/registry/index.d.ts +48 -4
- package/dist/llm/registry/index.d.ts.map +1 -1
- package/dist/llm/registry/index.js +136 -28
- package/dist/llm/registry/models.generated.cjs +5198 -59
- package/dist/llm/registry/models.generated.d.ts +1893 -76
- package/dist/llm/registry/models.generated.d.ts.map +1 -1
- package/dist/llm/registry/models.generated.js +5196 -58
- package/dist/llm/registry/sync.cjs +72 -1
- package/dist/llm/registry/sync.d.ts +21 -1
- package/dist/llm/registry/sync.d.ts.map +1 -1
- package/dist/llm/registry/sync.js +72 -1
- package/dist/llm/resolver.cjs +13 -1
- package/dist/llm/resolver.d.ts.map +1 -1
- package/dist/llm/resolver.js +13 -1
- package/dist/llm/schemas.cjs +75 -14
- package/dist/llm/schemas.d.ts +80 -23
- package/dist/llm/schemas.d.ts.map +1 -1
- package/dist/llm/schemas.js +75 -14
- package/dist/llm/services/factory.cjs +55 -8
- package/dist/llm/services/factory.d.ts +1 -1
- package/dist/llm/services/factory.d.ts.map +1 -1
- package/dist/llm/services/factory.js +58 -8
- package/dist/llm/services/vercel.cjs +1 -1
- package/dist/llm/services/vercel.js +1 -1
- package/dist/llm/types.d.ts +9 -0
- package/dist/llm/types.d.ts.map +1 -1
- package/dist/prompts/index.cjs +9 -0
- package/dist/prompts/index.d.ts +1 -0
- package/dist/prompts/index.d.ts.map +1 -1
- package/dist/prompts/index.js +10 -0
- package/dist/prompts/prompt-manager.cjs +2 -0
- package/dist/prompts/prompt-manager.d.ts.map +1 -1
- package/dist/prompts/prompt-manager.js +2 -0
- package/dist/prompts/providers/config-prompt-provider.cjs +11 -1
- package/dist/prompts/providers/config-prompt-provider.d.ts.map +1 -1
- package/dist/prompts/providers/config-prompt-provider.js +11 -1
- package/dist/prompts/schemas.cjs +2 -2
- package/dist/prompts/schemas.js +2 -2
- package/dist/prompts/types.d.ts +6 -2
- package/dist/prompts/types.d.ts.map +1 -1
- package/dist/tools/confirmation/allowed-tools-provider/types.d.ts +1 -1
- package/dist/tools/tool-manager.cjs +88 -2
- package/dist/tools/tool-manager.d.ts +15 -1
- package/dist/tools/tool-manager.d.ts.map +1 -1
- package/dist/tools/tool-manager.js +88 -2
- package/dist/utils/service-initializer.d.ts +1 -0
- package/dist/utils/service-initializer.d.ts.map +1 -1
- package/package.json +7 -5
- package/dist/utils/schema-metadata.cjs +0 -235
- package/dist/utils/schema-metadata.d.ts +0 -82
- package/dist/utils/schema-metadata.d.ts.map +0 -1
- package/dist/utils/schema-metadata.js +0 -208
- package/dist/utils/user-info.d.ts +0 -2
- package/dist/utils/user-info.d.ts.map +0 -1
- package/dist/utils/user-info.js +0 -7
|
@@ -1,49 +1,15 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Provider-specific options builder for Vercel AI SDK's streamText/generateText.
|
|
3
|
-
*
|
|
4
|
-
* Centralizes provider-specific configuration that requires explicit opt-in:
|
|
5
|
-
* - Anthropic: cacheControl for prompt caching, sendReasoning for extended thinking
|
|
6
|
-
* - Bedrock/Vertex Claude: Same as Anthropic (Claude models on these platforms)
|
|
7
|
-
* - Google: thinkingConfig for Gemini thinking models
|
|
8
|
-
* - OpenAI: reasoningEffort for o1/o3/codex/gpt-5 models
|
|
9
|
-
*
|
|
10
|
-
* Caching notes:
|
|
11
|
-
* - Anthropic: Requires explicit cacheControl option (we enable it)
|
|
12
|
-
* - OpenAI: Automatic for prompts ≥1024 tokens (no config needed)
|
|
13
|
-
* - Google: Implicit caching automatic for Gemini 2.5+ (≥1024 tokens for Flash,
|
|
14
|
-
* ≥2048 for Pro). Explicit caching requires pre-created cachedContent IDs.
|
|
15
|
-
* All providers return cached token counts in the response (cachedInputTokens).
|
|
16
3
|
*/
|
|
17
|
-
import type { LLMProvider } from '../types.js';
|
|
18
|
-
export type ReasoningEffort = 'none' | 'minimal' | 'low' | 'medium' | 'high' | 'xhigh';
|
|
4
|
+
import type { LLMProvider, LLMReasoningConfig } from '../types.js';
|
|
19
5
|
export interface ProviderOptionsConfig {
|
|
20
6
|
provider: LLMProvider;
|
|
21
7
|
model: string;
|
|
22
|
-
|
|
8
|
+
reasoning?: LLMReasoningConfig | undefined;
|
|
23
9
|
}
|
|
10
|
+
export declare function getEffectiveReasoningBudgetTokens(providerOptions: Record<string, Record<string, unknown>> | undefined): number | undefined;
|
|
24
11
|
/**
|
|
25
12
|
* Build provider-specific options for streamText/generateText.
|
|
26
|
-
*
|
|
27
|
-
* @param config Provider, model, and optional reasoning effort configuration
|
|
28
|
-
* @returns Provider options object or undefined if no special options needed
|
|
29
13
|
*/
|
|
30
14
|
export declare function buildProviderOptions(config: ProviderOptionsConfig): Record<string, Record<string, unknown>> | undefined;
|
|
31
|
-
/**
|
|
32
|
-
* Determine the default reasoning effort for OpenAI models.
|
|
33
|
-
*
|
|
34
|
-
* OpenAI reasoning effort levels (from lowest to highest):
|
|
35
|
-
* - 'none': No reasoning, fastest responses
|
|
36
|
-
* - 'low': Minimal reasoning, fast responses
|
|
37
|
-
* - 'medium': Balanced reasoning (OpenAI's recommended daily driver)
|
|
38
|
-
* - 'high': Thorough reasoning for complex tasks
|
|
39
|
-
* - 'xhigh': Extra high reasoning for quality-critical, non-latency-sensitive tasks
|
|
40
|
-
*
|
|
41
|
-
* Default strategy:
|
|
42
|
-
* - Reasoning-capable models (codex, o1, o3, gpt-5): 'medium' - OpenAI's recommended default
|
|
43
|
-
* - Other models: undefined (no reasoning effort needed)
|
|
44
|
-
*
|
|
45
|
-
* @param model The model name
|
|
46
|
-
* @returns Reasoning effort level or undefined if not applicable
|
|
47
|
-
*/
|
|
48
|
-
export declare function getDefaultReasoningEffort(model: string): Exclude<ReasoningEffort, 'none'> | undefined;
|
|
49
15
|
//# sourceMappingURL=provider-options.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"provider-options.d.ts","sourceRoot":"","sources":["../../../src/llm/executor/provider-options.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"provider-options.d.ts","sourceRoot":"","sources":["../../../src/llm/executor/provider-options.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAcnE,MAAM,WAAW,qBAAqB;IAClC,QAAQ,EAAE,WAAW,CAAC;IACtB,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,CAAC,EAAE,kBAAkB,GAAG,SAAS,CAAC;CAC9C;AA4LD,wBAAgB,iCAAiC,CAC7C,eAAe,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,GAAG,SAAS,GACrE,MAAM,GAAG,SAAS,CA4BpB;AAED;;GAEG;AACH,wBAAgB,oBAAoB,CAChC,MAAM,EAAE,qBAAqB,GAC9B,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,GAAG,SAAS,CA2IrD"}
|
|
@@ -1,63 +1,263 @@
|
|
|
1
1
|
import "../../chunk-PTJYTZNU.js";
|
|
2
2
|
import { isReasoningCapableModel } from "../registry/index.js";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
import {
|
|
4
|
+
isAnthropicAdaptiveThinkingModel,
|
|
5
|
+
supportsAnthropicInterleavedThinking
|
|
6
|
+
} from "../reasoning/anthropic-thinking.js";
|
|
7
|
+
import { ANTHROPIC_INTERLEAVED_THINKING_BETA } from "../reasoning/anthropic-betas.js";
|
|
8
|
+
import { getReasoningProfile } from "../reasoning/profile.js";
|
|
9
|
+
import { isOpenRouterGatewayProvider } from "../reasoning/profiles/openrouter.js";
|
|
10
|
+
import {
|
|
11
|
+
supportsOpenAIReasoningEffort
|
|
12
|
+
} from "../reasoning/openai-reasoning-effort.js";
|
|
13
|
+
const ANTHROPIC_MIN_THINKING_BUDGET_TOKENS = 1024;
|
|
14
|
+
const ANTHROPIC_DEFAULT_BUDGET_TOKENS = 2048;
|
|
15
|
+
const GOOGLE_DEFAULT_BUDGET_TOKENS = 2048;
|
|
16
|
+
const BEDROCK_DEFAULT_BUDGET_TOKENS = 2048;
|
|
17
|
+
const ANTHROPIC_CACHE_CONTROL = { type: "ephemeral" };
|
|
18
|
+
function coerceBudgetTokens(tokens, minimum) {
|
|
19
|
+
if (tokens === void 0) return void 0;
|
|
20
|
+
if (!Number.isFinite(tokens)) return void 0;
|
|
21
|
+
return Math.max(minimum, Math.floor(tokens));
|
|
22
|
+
}
|
|
23
|
+
function toOpenAIReasoningEffort(reasoningVariant) {
|
|
24
|
+
return reasoningVariant === "none" || reasoningVariant === "minimal" || reasoningVariant === "low" || reasoningVariant === "medium" || reasoningVariant === "high" || reasoningVariant === "xhigh" ? reasoningVariant : void 0;
|
|
25
|
+
}
|
|
26
|
+
function toOpenAICompatibleReasoningEffort(reasoningVariant) {
|
|
27
|
+
return reasoningVariant === "none" || reasoningVariant === "low" || reasoningVariant === "medium" || reasoningVariant === "high" ? reasoningVariant : void 0;
|
|
28
|
+
}
|
|
29
|
+
function getSelectedReasoningVariant(config) {
|
|
30
|
+
const profile = getReasoningProfile(config.provider, config.model);
|
|
31
|
+
const requested = config.reasoning?.variant;
|
|
32
|
+
if (requested !== void 0) {
|
|
33
|
+
const supported = profile.variants.some((entry) => entry.id === requested);
|
|
34
|
+
return {
|
|
35
|
+
reasoningVariant: supported ? requested : void 0,
|
|
36
|
+
hasInvalidRequestedReasoningVariant: !supported
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
return {
|
|
40
|
+
reasoningVariant: profile.defaultVariant,
|
|
41
|
+
hasInvalidRequestedReasoningVariant: false
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
function buildAnthropicProviderOptions(config) {
|
|
45
|
+
const { model, reasoningVariant, budgetTokens, capable } = config;
|
|
46
|
+
const adaptiveThinking = isAnthropicAdaptiveThinkingModel(model);
|
|
47
|
+
if (adaptiveThinking) {
|
|
48
|
+
if (reasoningVariant === "disabled") {
|
|
49
|
+
return {
|
|
50
|
+
anthropic: {
|
|
51
|
+
cacheControl: ANTHROPIC_CACHE_CONTROL,
|
|
52
|
+
sendReasoning: false,
|
|
53
|
+
thinking: { type: "disabled" }
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
const effort = reasoningVariant === "low" || reasoningVariant === "medium" || reasoningVariant === "high" || reasoningVariant === "max" ? reasoningVariant : void 0;
|
|
58
|
+
return {
|
|
59
|
+
anthropic: {
|
|
60
|
+
cacheControl: ANTHROPIC_CACHE_CONTROL,
|
|
61
|
+
sendReasoning: true,
|
|
62
|
+
thinking: { type: "adaptive" },
|
|
63
|
+
...effort !== void 0 && { effort }
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
if (!capable) {
|
|
7
68
|
return {
|
|
8
69
|
anthropic: {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
sendReasoning: true
|
|
70
|
+
cacheControl: ANTHROPIC_CACHE_CONTROL,
|
|
71
|
+
sendReasoning: false,
|
|
72
|
+
...reasoningVariant === "disabled" ? { thinking: { type: "disabled" } } : {}
|
|
13
73
|
}
|
|
14
74
|
};
|
|
15
75
|
}
|
|
16
|
-
if (
|
|
76
|
+
if (reasoningVariant === "disabled") {
|
|
17
77
|
return {
|
|
18
|
-
|
|
19
|
-
cacheControl:
|
|
20
|
-
sendReasoning:
|
|
78
|
+
anthropic: {
|
|
79
|
+
cacheControl: ANTHROPIC_CACHE_CONTROL,
|
|
80
|
+
sendReasoning: false,
|
|
81
|
+
thinking: { type: "disabled" }
|
|
21
82
|
}
|
|
22
83
|
};
|
|
23
84
|
}
|
|
24
|
-
|
|
85
|
+
const effectiveBudgetTokens = coerceBudgetTokens(
|
|
86
|
+
budgetTokens ?? ANTHROPIC_DEFAULT_BUDGET_TOKENS,
|
|
87
|
+
ANTHROPIC_MIN_THINKING_BUDGET_TOKENS
|
|
88
|
+
);
|
|
89
|
+
return {
|
|
90
|
+
anthropic: {
|
|
91
|
+
cacheControl: ANTHROPIC_CACHE_CONTROL,
|
|
92
|
+
sendReasoning: true,
|
|
93
|
+
...effectiveBudgetTokens !== void 0 ? { thinking: { type: "enabled", budgetTokens: effectiveBudgetTokens } } : {}
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
function buildOpenRouterProviderOptions(config) {
|
|
98
|
+
const { provider, model, reasoningVariant, budgetTokens } = config;
|
|
99
|
+
const profile = getReasoningProfile(provider, model);
|
|
100
|
+
if (!profile.capable) {
|
|
101
|
+
return void 0;
|
|
102
|
+
}
|
|
103
|
+
if (reasoningVariant === "disabled") {
|
|
104
|
+
return { openrouter: { include_reasoning: false } };
|
|
105
|
+
}
|
|
106
|
+
if (budgetTokens !== void 0) {
|
|
25
107
|
return {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
108
|
+
openrouter: {
|
|
109
|
+
include_reasoning: true,
|
|
110
|
+
reasoning: { enabled: true, max_tokens: budgetTokens }
|
|
29
111
|
}
|
|
30
112
|
};
|
|
31
113
|
}
|
|
114
|
+
if (profile.paradigm === "budget") {
|
|
115
|
+
if (reasoningVariant === void 0 || reasoningVariant === "enabled") {
|
|
116
|
+
return {
|
|
117
|
+
openrouter: {
|
|
118
|
+
include_reasoning: true
|
|
119
|
+
}
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
return void 0;
|
|
123
|
+
}
|
|
124
|
+
const explicitEffort = toOpenAIReasoningEffort(reasoningVariant);
|
|
125
|
+
const effort = explicitEffort ?? (profile.paradigm === "adaptive-effort" && reasoningVariant === "max" ? "xhigh" : void 0);
|
|
126
|
+
return {
|
|
127
|
+
openrouter: {
|
|
128
|
+
include_reasoning: true,
|
|
129
|
+
...effort !== void 0 ? { reasoning: { enabled: true, effort } } : {}
|
|
130
|
+
}
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
function asRecord(value) {
|
|
134
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) return void 0;
|
|
135
|
+
return value;
|
|
136
|
+
}
|
|
137
|
+
function getEffectiveReasoningBudgetTokens(providerOptions) {
|
|
138
|
+
if (providerOptions === void 0) return void 0;
|
|
139
|
+
const anthropic = asRecord(providerOptions["anthropic"]);
|
|
140
|
+
const thinking = asRecord(anthropic?.["thinking"]);
|
|
141
|
+
if (thinking?.["type"] === "enabled" && typeof thinking["budgetTokens"] === "number") {
|
|
142
|
+
return thinking["budgetTokens"];
|
|
143
|
+
}
|
|
144
|
+
const google = asRecord(providerOptions["google"]);
|
|
145
|
+
const thinkingConfig = asRecord(google?.["thinkingConfig"]);
|
|
146
|
+
if (typeof thinkingConfig?.["thinkingBudget"] === "number") {
|
|
147
|
+
return thinkingConfig["thinkingBudget"];
|
|
148
|
+
}
|
|
149
|
+
const bedrock = asRecord(providerOptions["bedrock"]);
|
|
150
|
+
const reasoningConfig = asRecord(bedrock?.["reasoningConfig"]);
|
|
151
|
+
if (typeof reasoningConfig?.["budgetTokens"] === "number") {
|
|
152
|
+
return reasoningConfig["budgetTokens"];
|
|
153
|
+
}
|
|
154
|
+
const openrouter = asRecord(providerOptions["openrouter"]);
|
|
155
|
+
const reasoning = asRecord(openrouter?.["reasoning"]);
|
|
156
|
+
if (typeof reasoning?.["max_tokens"] === "number") {
|
|
157
|
+
return reasoning["max_tokens"];
|
|
158
|
+
}
|
|
159
|
+
return void 0;
|
|
160
|
+
}
|
|
161
|
+
function buildProviderOptions(config) {
|
|
162
|
+
const { provider, model, reasoning } = config;
|
|
163
|
+
const modelLower = model.toLowerCase();
|
|
164
|
+
const { reasoningVariant, hasInvalidRequestedReasoningVariant } = getSelectedReasoningVariant(config);
|
|
165
|
+
const budgetTokens = reasoning?.budgetTokens;
|
|
166
|
+
if (hasInvalidRequestedReasoningVariant) {
|
|
167
|
+
return void 0;
|
|
168
|
+
}
|
|
169
|
+
if (provider === "anthropic") {
|
|
170
|
+
const capable = isReasoningCapableModel(model, "anthropic");
|
|
171
|
+
return buildAnthropicProviderOptions({ model, reasoningVariant, budgetTokens, capable });
|
|
172
|
+
}
|
|
173
|
+
if (provider === "bedrock") {
|
|
174
|
+
const capable = isReasoningCapableModel(model, "bedrock");
|
|
175
|
+
if (!capable) {
|
|
176
|
+
return { bedrock: {} };
|
|
177
|
+
}
|
|
178
|
+
const isAnthropicModel = modelLower.includes("anthropic");
|
|
179
|
+
const isNovaModel = modelLower.includes("nova");
|
|
180
|
+
if (!isAnthropicModel && !isNovaModel) {
|
|
181
|
+
return { bedrock: {} };
|
|
182
|
+
}
|
|
183
|
+
const bedrock = {};
|
|
184
|
+
if (reasoningVariant === "disabled") {
|
|
185
|
+
bedrock["reasoningConfig"] = { type: "disabled" };
|
|
186
|
+
return { bedrock };
|
|
187
|
+
}
|
|
188
|
+
if (isAnthropicModel) {
|
|
189
|
+
const effectiveBudgetTokens = coerceBudgetTokens(
|
|
190
|
+
budgetTokens ?? BEDROCK_DEFAULT_BUDGET_TOKENS,
|
|
191
|
+
1
|
|
192
|
+
);
|
|
193
|
+
if (effectiveBudgetTokens === void 0) {
|
|
194
|
+
return { bedrock: {} };
|
|
195
|
+
}
|
|
196
|
+
bedrock["reasoningConfig"] = { type: "enabled", budgetTokens: effectiveBudgetTokens };
|
|
197
|
+
if (supportsAnthropicInterleavedThinking(model)) {
|
|
198
|
+
bedrock["anthropicBeta"] = [ANTHROPIC_INTERLEAVED_THINKING_BETA];
|
|
199
|
+
}
|
|
200
|
+
return { bedrock };
|
|
201
|
+
}
|
|
202
|
+
const maxReasoningEffort = reasoningVariant === "low" || reasoningVariant === "medium" || reasoningVariant === "high" ? reasoningVariant : void 0;
|
|
203
|
+
if (maxReasoningEffort !== void 0) {
|
|
204
|
+
bedrock["reasoningConfig"] = { type: "enabled", maxReasoningEffort };
|
|
205
|
+
}
|
|
206
|
+
return { bedrock };
|
|
207
|
+
}
|
|
208
|
+
if (provider === "vertex" && modelLower.includes("claude")) {
|
|
209
|
+
const capable = isReasoningCapableModel(model, "vertex");
|
|
210
|
+
return buildAnthropicProviderOptions({ model, reasoningVariant, budgetTokens, capable });
|
|
211
|
+
}
|
|
32
212
|
if (provider === "google" || provider === "vertex" && !modelLower.includes("claude")) {
|
|
213
|
+
const profile = getReasoningProfile(provider, model);
|
|
214
|
+
const includeThoughts = profile.capable && reasoningVariant !== "disabled";
|
|
215
|
+
const isThinkingLevel = profile.paradigm === "thinking-level";
|
|
216
|
+
const thinkingLevel = includeThoughts && isThinkingLevel && (reasoningVariant === "minimal" || reasoningVariant === "low" || reasoningVariant === "medium" || reasoningVariant === "high") ? reasoningVariant : void 0;
|
|
217
|
+
const thinkingBudgetTokens = coerceBudgetTokens(
|
|
218
|
+
budgetTokens ?? GOOGLE_DEFAULT_BUDGET_TOKENS,
|
|
219
|
+
1
|
|
220
|
+
);
|
|
33
221
|
return {
|
|
34
222
|
google: {
|
|
35
223
|
thinkingConfig: {
|
|
36
|
-
|
|
37
|
-
includeThoughts
|
|
224
|
+
includeThoughts,
|
|
225
|
+
...includeThoughts && isThinkingLevel && thinkingLevel !== void 0 && {
|
|
226
|
+
thinkingLevel
|
|
227
|
+
},
|
|
228
|
+
...includeThoughts && profile.paradigm === "budget" && thinkingBudgetTokens !== void 0 && {
|
|
229
|
+
thinkingBudget: thinkingBudgetTokens
|
|
230
|
+
}
|
|
38
231
|
}
|
|
39
232
|
}
|
|
40
233
|
};
|
|
41
234
|
}
|
|
42
235
|
if (provider === "openai") {
|
|
43
|
-
const
|
|
44
|
-
if (
|
|
236
|
+
const effortCandidate = toOpenAIReasoningEffort(reasoningVariant);
|
|
237
|
+
if (effortCandidate && supportsOpenAIReasoningEffort(model, effortCandidate)) {
|
|
45
238
|
return {
|
|
46
239
|
openai: {
|
|
47
|
-
reasoningEffort:
|
|
240
|
+
reasoningEffort: effortCandidate,
|
|
241
|
+
...effortCandidate !== "none" && { reasoningSummary: "auto" }
|
|
48
242
|
}
|
|
49
243
|
};
|
|
50
244
|
}
|
|
51
245
|
}
|
|
52
|
-
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
if (
|
|
56
|
-
|
|
246
|
+
if (isOpenRouterGatewayProvider(provider)) {
|
|
247
|
+
return buildOpenRouterProviderOptions({ provider, model, reasoningVariant, budgetTokens });
|
|
248
|
+
}
|
|
249
|
+
if (provider === "openai-compatible") {
|
|
250
|
+
const profile = getReasoningProfile(provider, model);
|
|
251
|
+
if (!profile.capable) return void 0;
|
|
252
|
+
const reasoningEffort = toOpenAICompatibleReasoningEffort(reasoningVariant);
|
|
253
|
+
if (reasoningEffort === void 0) return void 0;
|
|
254
|
+
return {
|
|
255
|
+
openaiCompatible: { reasoningEffort }
|
|
256
|
+
};
|
|
57
257
|
}
|
|
58
258
|
return void 0;
|
|
59
259
|
}
|
|
60
260
|
export {
|
|
61
261
|
buildProviderOptions,
|
|
62
|
-
|
|
262
|
+
getEffectiveReasoningBudgetTokens
|
|
63
263
|
};
|
|
@@ -23,7 +23,7 @@ __export(stream_processor_exports, {
|
|
|
23
23
|
module.exports = __toCommonJS(stream_processor_exports);
|
|
24
24
|
var import_tool_output_truncator = require("./tool-output-truncator.js");
|
|
25
25
|
var import_utils = require("../../context/utils.js");
|
|
26
|
-
var
|
|
26
|
+
var import_types2 = require("../../logger/v2/types.js");
|
|
27
27
|
class StreamProcessor {
|
|
28
28
|
/**
|
|
29
29
|
* @param contextManager Context manager for message persistence
|
|
@@ -43,7 +43,7 @@ class StreamProcessor {
|
|
|
43
43
|
this.config = config;
|
|
44
44
|
this.streaming = streaming;
|
|
45
45
|
this.toolCallMetadata = toolCallMetadata;
|
|
46
|
-
this.logger = logger.createChild(
|
|
46
|
+
this.logger = logger.createChild(import_types2.DextoLogComponent.EXECUTOR);
|
|
47
47
|
}
|
|
48
48
|
assistantMessageId = null;
|
|
49
49
|
actualTokens = { inputTokens: 0, outputTokens: 0, totalTokens: 0 };
|
|
@@ -127,7 +127,7 @@ class StreamProcessor {
|
|
|
127
127
|
case "reasoning-delta":
|
|
128
128
|
this.reasoningText += event.text;
|
|
129
129
|
if (event.providerMetadata) {
|
|
130
|
-
this.
|
|
130
|
+
this.mergeReasoningMetadata(event.providerMetadata);
|
|
131
131
|
}
|
|
132
132
|
if (this.streaming) {
|
|
133
133
|
this.eventBus.emit("llm:chunk", {
|
|
@@ -284,10 +284,8 @@ class StreamProcessor {
|
|
|
284
284
|
this.logger.info("LLM response complete", {
|
|
285
285
|
finishReason: event.finishReason,
|
|
286
286
|
contentLength: this.accumulatedText.length,
|
|
287
|
-
content: this.accumulatedText,
|
|
288
287
|
...this.reasoningText && {
|
|
289
|
-
reasoningLength: this.reasoningText.length
|
|
290
|
-
reasoning: this.reasoningText
|
|
288
|
+
reasoningLength: this.reasoningText.length
|
|
291
289
|
},
|
|
292
290
|
usage,
|
|
293
291
|
provider: this.config.provider,
|
|
@@ -308,15 +306,8 @@ class StreamProcessor {
|
|
|
308
306
|
}
|
|
309
307
|
const hasContent = this.accumulatedText || this.reasoningText;
|
|
310
308
|
if (this.finishReason !== "tool-calls" || hasContent) {
|
|
311
|
-
this.
|
|
312
|
-
content: this.accumulatedText,
|
|
313
|
-
...this.reasoningText && { reasoning: this.reasoningText },
|
|
314
|
-
provider: this.config.provider,
|
|
315
|
-
model: this.config.model,
|
|
309
|
+
this.emitLLMResponse({
|
|
316
310
|
tokenUsage: usage,
|
|
317
|
-
...this.config.estimatedInputTokens !== void 0 && {
|
|
318
|
-
estimatedInputTokens: this.config.estimatedInputTokens
|
|
319
|
-
},
|
|
320
311
|
finishReason: this.finishReason
|
|
321
312
|
});
|
|
322
313
|
}
|
|
@@ -363,7 +354,7 @@ class StreamProcessor {
|
|
|
363
354
|
}
|
|
364
355
|
case "error": {
|
|
365
356
|
const err = event.error instanceof Error ? event.error : new Error(String(event.error));
|
|
366
|
-
this.logger.error(
|
|
357
|
+
this.logger.error("LLM error", { error: err });
|
|
367
358
|
this.eventBus.emit("llm:error", {
|
|
368
359
|
error: err
|
|
369
360
|
});
|
|
@@ -373,15 +364,8 @@ class StreamProcessor {
|
|
|
373
364
|
this.logger.debug("Stream aborted, emitting partial response");
|
|
374
365
|
this.finishReason = "cancelled";
|
|
375
366
|
await this.persistCancelledToolResults();
|
|
376
|
-
this.
|
|
377
|
-
content: this.accumulatedText,
|
|
378
|
-
...this.reasoningText && { reasoning: this.reasoningText },
|
|
379
|
-
provider: this.config.provider,
|
|
380
|
-
model: this.config.model,
|
|
367
|
+
this.emitLLMResponse({
|
|
381
368
|
tokenUsage: this.actualTokens,
|
|
382
|
-
...this.config.estimatedInputTokens !== void 0 && {
|
|
383
|
-
estimatedInputTokens: this.config.estimatedInputTokens
|
|
384
|
-
},
|
|
385
369
|
finishReason: "cancelled"
|
|
386
370
|
});
|
|
387
371
|
return {
|
|
@@ -397,15 +381,8 @@ class StreamProcessor {
|
|
|
397
381
|
this.logger.debug("Stream cancelled, emitting partial response");
|
|
398
382
|
this.finishReason = "cancelled";
|
|
399
383
|
await this.persistCancelledToolResults();
|
|
400
|
-
this.
|
|
401
|
-
content: this.accumulatedText,
|
|
402
|
-
...this.reasoningText && { reasoning: this.reasoningText },
|
|
403
|
-
provider: this.config.provider,
|
|
404
|
-
model: this.config.model,
|
|
384
|
+
this.emitLLMResponse({
|
|
405
385
|
tokenUsage: this.actualTokens,
|
|
406
|
-
...this.config.estimatedInputTokens !== void 0 && {
|
|
407
|
-
estimatedInputTokens: this.config.estimatedInputTokens
|
|
408
|
-
},
|
|
409
386
|
finishReason: "cancelled"
|
|
410
387
|
});
|
|
411
388
|
return {
|
|
@@ -463,6 +440,52 @@ class StreamProcessor {
|
|
|
463
440
|
}
|
|
464
441
|
return metadata;
|
|
465
442
|
}
|
|
443
|
+
getReasoningResponseFields() {
|
|
444
|
+
return {
|
|
445
|
+
...this.config.reasoningVariant !== void 0 && {
|
|
446
|
+
reasoningVariant: this.config.reasoningVariant
|
|
447
|
+
},
|
|
448
|
+
...this.config.reasoningBudgetTokens !== void 0 && {
|
|
449
|
+
reasoningBudgetTokens: this.config.reasoningBudgetTokens
|
|
450
|
+
}
|
|
451
|
+
};
|
|
452
|
+
}
|
|
453
|
+
emitLLMResponse(config) {
|
|
454
|
+
this.eventBus.emit("llm:response", {
|
|
455
|
+
content: this.accumulatedText,
|
|
456
|
+
...this.reasoningText && { reasoning: this.reasoningText },
|
|
457
|
+
provider: this.config.provider,
|
|
458
|
+
model: this.config.model,
|
|
459
|
+
...this.getReasoningResponseFields(),
|
|
460
|
+
tokenUsage: config.tokenUsage,
|
|
461
|
+
...this.config.estimatedInputTokens !== void 0 && {
|
|
462
|
+
estimatedInputTokens: this.config.estimatedInputTokens
|
|
463
|
+
},
|
|
464
|
+
finishReason: config.finishReason
|
|
465
|
+
});
|
|
466
|
+
}
|
|
467
|
+
mergeReasoningMetadata(providerMetadata) {
|
|
468
|
+
if (!this.reasoningMetadata) {
|
|
469
|
+
this.reasoningMetadata = providerMetadata;
|
|
470
|
+
return;
|
|
471
|
+
}
|
|
472
|
+
const isRecord = (value) => !!value && typeof value === "object" && !Array.isArray(value);
|
|
473
|
+
const previous = this.reasoningMetadata;
|
|
474
|
+
const merged = { ...previous, ...providerMetadata };
|
|
475
|
+
const previousOpenRouter = previous["openrouter"];
|
|
476
|
+
const nextOpenRouter = providerMetadata["openrouter"];
|
|
477
|
+
if (isRecord(previousOpenRouter) && isRecord(nextOpenRouter)) {
|
|
478
|
+
const previousDetails = previousOpenRouter["reasoning_details"];
|
|
479
|
+
const nextDetails = nextOpenRouter["reasoning_details"];
|
|
480
|
+
const combinedDetails = Array.isArray(previousDetails) && Array.isArray(nextDetails) ? [...previousDetails, ...nextDetails] : Array.isArray(nextDetails) ? nextDetails : Array.isArray(previousDetails) ? previousDetails : void 0;
|
|
481
|
+
merged["openrouter"] = {
|
|
482
|
+
...previousOpenRouter,
|
|
483
|
+
...nextOpenRouter,
|
|
484
|
+
...combinedDetails ? { reasoning_details: combinedDetails } : {}
|
|
485
|
+
};
|
|
486
|
+
}
|
|
487
|
+
this.reasoningMetadata = merged;
|
|
488
|
+
}
|
|
466
489
|
async createAssistantMessage() {
|
|
467
490
|
await this.contextManager.addAssistantMessage("", [], {});
|
|
468
491
|
return this.getLastMessageId();
|
|
@@ -3,14 +3,18 @@ import { ContextManager } from '../../context/manager.js';
|
|
|
3
3
|
import { SessionEventBus } from '../../events/index.js';
|
|
4
4
|
import { ResourceManager } from '../../resources/index.js';
|
|
5
5
|
import { StreamProcessorResult } from './types.js';
|
|
6
|
-
import { Logger } from '../../logger/v2/types.js';
|
|
7
|
-
import { LLMProvider } from '../types.js';
|
|
6
|
+
import type { Logger } from '../../logger/v2/types.js';
|
|
8
7
|
import type { ToolPresentationSnapshotV1 } from '../../tools/types.js';
|
|
8
|
+
import type { LLMProvider, ReasoningVariant } from '../types.js';
|
|
9
9
|
export interface StreamProcessorConfig {
|
|
10
10
|
provider: LLMProvider;
|
|
11
11
|
model: string;
|
|
12
12
|
/** Estimated input tokens before LLM call (for analytics/calibration) */
|
|
13
13
|
estimatedInputTokens?: number;
|
|
14
|
+
/** Reasoning variant used for this call, when the provider exposes it. */
|
|
15
|
+
reasoningVariant?: ReasoningVariant;
|
|
16
|
+
/** Reasoning budget tokens used for this call, when the provider exposes it. */
|
|
17
|
+
reasoningBudgetTokens?: number;
|
|
14
18
|
}
|
|
15
19
|
export declare class StreamProcessor {
|
|
16
20
|
private contextManager;
|
|
@@ -53,6 +57,9 @@ export declare class StreamProcessor {
|
|
|
53
57
|
private getCacheTokensFromProviderMetadata;
|
|
54
58
|
private normalizeUsage;
|
|
55
59
|
private getProviderMetadata;
|
|
60
|
+
private getReasoningResponseFields;
|
|
61
|
+
private emitLLMResponse;
|
|
62
|
+
private mergeReasoningMetadata;
|
|
56
63
|
private createAssistantMessage;
|
|
57
64
|
private getLastMessageId;
|
|
58
65
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stream-processor.d.ts","sourceRoot":"","sources":["../../../src/llm/executor/stream-processor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,OAAO,IAAI,aAAa,EAAE,MAAM,IAAI,CAAC;AAChE,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAC1D,OAAO,EAAE,eAAe,EAAmB,MAAM,uBAAuB,CAAC;AACzE,OAAO,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAE3D,OAAO,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAC;AAGnD,OAAO,EAAE,MAAM,EAAE,MAAM,0BAA0B,CAAC;
|
|
1
|
+
{"version":3,"file":"stream-processor.d.ts","sourceRoot":"","sources":["../../../src/llm/executor/stream-processor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,OAAO,IAAI,aAAa,EAAE,MAAM,IAAI,CAAC;AAChE,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAC1D,OAAO,EAAE,eAAe,EAAmB,MAAM,uBAAuB,CAAC;AACzE,OAAO,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAE3D,OAAO,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAC;AAGnD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,0BAA0B,CAAC;AAEvD,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,sBAAsB,CAAC;AACvE,OAAO,KAAK,EAAE,WAAW,EAAE,gBAAgB,EAAc,MAAM,aAAa,CAAC;AA4C7E,MAAM,WAAW,qBAAqB;IAClC,QAAQ,EAAE,WAAW,CAAC;IACtB,KAAK,EAAE,MAAM,CAAC;IACd,yEAAyE;IACzE,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B,0EAA0E;IAC1E,gBAAgB,CAAC,EAAE,gBAAgB,CAAC;IACpC,gFAAgF;IAChF,qBAAqB,CAAC,EAAE,MAAM,CAAC;CAClC;AAED,qBAAa,eAAe;IA2BpB,OAAO,CAAC,cAAc;IACtB,OAAO,CAAC,QAAQ;IAChB,OAAO,CAAC,eAAe;IACvB,OAAO,CAAC,WAAW;IACnB,OAAO,CAAC,MAAM;IAEd,OAAO,CAAC,SAAS;IACjB,OAAO,CAAC,gBAAgB,CAAC;IAjC7B,OAAO,CAAC,kBAAkB,CAAuB;IACjD,OAAO,CAAC,YAAY,CAAmE;IACvF,OAAO,CAAC,YAAY,CAA8B;IAClD,OAAO,CAAC,aAAa,CAAc;IACnC,OAAO,CAAC,iBAAiB,CAAsC;IAC/D,OAAO,CAAC,eAAe,CAAc;IACrC,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,YAAY,CAAS;IAC7B;;;OAGG;IACH,OAAO,CAAC,gBAAgB,CAAgD;IACxE,OAAO,CAAC,gBAAgB,CAAkE;IAE1F;;;;;;;;;OASG;gBAES,cAAc,EAAE,cAAc,EAC9B,QAAQ,EAAE,eAAe,EACzB,eAAe,EAAE,eAAe,EAChC,WAAW,EAAE,WAAW,EACxB,MAAM,EAAE,qBAAqB,EACrC,MAAM,EAAE,MAAM,EACN,SAAS,GAAE,OAAc,EACzB,gBAAgB,CAAC,EAAE,GAAG,CAC1B,MAAM,EACN;QACI,oBAAoB,CAAC,EAAE,0BAA0B,CAAC;QAClD,eAAe,CAAC,EAAE,OAAO,CAAC;QAC1B,cAAc,CAAC,EAAE,UAAU,GAAG,UAAU,CAAC;KAC5C,CACJ,YAAA;IAKC,OAAO,CACT,QAAQ,EAAE,MAAM,gBAAgB,CAAC,aAAa,EAAE,OAAO,CAAC,GACzD,OAAO,CAAC,qBAAqB,CAAC;IAuejC,OAAO,CAAC,kCAAkC;IAoB1C,OAAO,CAAC,cAAc;IA0CtB,OAAO,CAAC,mBAAmB;IAa3B,OAAO,CAAC,0BAA0B;IAclC,OAAO,CAAC,eAAe;IAkBvB,OAAO,CAAC,sBAAsB;YAwChB,sBAAsB;YAKtB,gBAAgB;IAO9B;;;;OAIG;YACW,2BAA2B;CAmC5C"}
|