@omnicross/core 0.1.0 → 0.1.1
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/ApiConverter.cjs +799 -0
- package/dist/ApiConverter.d.cts +82 -0
- package/dist/ApiConverter.d.ts +82 -0
- package/dist/ApiConverter.js +763 -0
- package/dist/BuiltinToolExecutor-BluWyeob.d.ts +81 -0
- package/dist/BuiltinToolExecutor-CS2WpXhM.d.cts +81 -0
- package/dist/CompletionService-7fCmKAP3.d.ts +212 -0
- package/dist/CompletionService-DtOF_War.d.cts +212 -0
- package/dist/{ProviderProxy-f_8ziIhW.d.cts → ProviderProxy-C-xqrkKi.d.ts} +7 -2
- package/dist/{ProviderProxy-vjt8sQQk.d.ts → ProviderProxy-CnMQYN59.d.cts} +7 -2
- package/dist/completion/BuiltinToolExecutor.cjs +327 -0
- package/dist/completion/BuiltinToolExecutor.d.cts +4 -0
- package/dist/completion/BuiltinToolExecutor.d.ts +4 -0
- package/dist/completion/BuiltinToolExecutor.js +296 -0
- package/dist/completion/CompletionService.cjs +3487 -0
- package/dist/completion/CompletionService.d.cts +21 -0
- package/dist/completion/CompletionService.d.ts +21 -0
- package/dist/completion/CompletionService.js +3461 -0
- package/dist/completion/NativeSearchInjector.cjs +196 -0
- package/dist/completion/NativeSearchInjector.d.cts +42 -0
- package/dist/completion/NativeSearchInjector.d.ts +42 -0
- package/dist/completion/NativeSearchInjector.js +167 -0
- package/dist/completion/ProviderSearchInjector.cjs +87 -0
- package/dist/completion/ProviderSearchInjector.d.cts +47 -0
- package/dist/completion/ProviderSearchInjector.d.ts +47 -0
- package/dist/completion/ProviderSearchInjector.js +60 -0
- package/dist/completion/native-search-types.cjs +67 -0
- package/dist/completion/native-search-types.d.cts +3 -0
- package/dist/completion/native-search-types.d.ts +3 -0
- package/dist/completion/native-search-types.js +38 -0
- package/dist/completion/openrouter-headers.cjs +72 -0
- package/dist/completion/openrouter-headers.d.cts +44 -0
- package/dist/completion/openrouter-headers.d.ts +44 -0
- package/dist/completion/openrouter-headers.js +42 -0
- package/dist/completion/openrouter-models.cjs +86 -0
- package/dist/completion/openrouter-models.d.cts +27 -0
- package/dist/completion/openrouter-models.d.ts +27 -0
- package/dist/completion/openrouter-models.js +59 -0
- package/dist/completion/types.cjs +18 -0
- package/dist/completion/types.d.cts +3 -0
- package/dist/completion/types.d.ts +3 -0
- package/dist/completion/types.js +0 -0
- package/dist/completion/url-builder.cjs +138 -0
- package/dist/completion/url-builder.d.cts +87 -0
- package/dist/completion/url-builder.d.ts +87 -0
- package/dist/completion/url-builder.js +104 -0
- package/dist/completion.d.cts +148 -7
- package/dist/completion.d.ts +148 -7
- package/dist/index.cjs +1 -0
- package/dist/index.d.cts +27 -90
- package/dist/index.d.ts +27 -90
- package/dist/index.js +1 -0
- package/dist/outbound-api/routeResolver.cjs +221 -0
- package/dist/outbound-api/routeResolver.d.cts +18 -0
- package/dist/outbound-api/routeResolver.d.ts +18 -0
- package/dist/outbound-api/routeResolver.js +192 -0
- package/dist/outbound-api/subscriptionRegistryPort.d.cts +5 -2
- package/dist/outbound-api/subscriptionRegistryPort.d.ts +5 -2
- package/dist/outbound-api/types.cjs +18 -0
- package/dist/{types-CbCN2NQP.d.ts → outbound-api/types.d.cts} +17 -3
- package/dist/{types-CGGrKqC_.d.cts → outbound-api/types.d.ts} +17 -3
- package/dist/outbound-api/types.js +0 -0
- package/dist/outbound-api.cjs +1 -0
- package/dist/outbound-api.d.cts +14 -87
- package/dist/outbound-api.d.ts +14 -87
- package/dist/outbound-api.js +1 -0
- package/dist/pipeline/AuthSource.cjs +18 -0
- package/dist/pipeline/AuthSource.d.cts +101 -0
- package/dist/pipeline/AuthSource.d.ts +101 -0
- package/dist/pipeline/AuthSource.js +0 -0
- package/dist/pipeline/LlmConfigProviderAuth.cjs +169 -0
- package/dist/pipeline/LlmConfigProviderAuth.d.cts +86 -0
- package/dist/pipeline/LlmConfigProviderAuth.d.ts +86 -0
- package/dist/pipeline/LlmConfigProviderAuth.js +142 -0
- package/dist/pipeline/SubscriptionAuthSource.d.cts +165 -3
- package/dist/pipeline/SubscriptionAuthSource.d.ts +165 -3
- package/dist/pipeline/executeProviderCall.cjs +70 -0
- package/dist/pipeline/executeProviderCall.d.cts +149 -0
- package/dist/pipeline/executeProviderCall.d.ts +149 -0
- package/dist/pipeline/executeProviderCall.js +45 -0
- package/dist/pipeline/resolveProviderChain.cjs +47 -0
- package/dist/pipeline/resolveProviderChain.d.cts +58 -0
- package/dist/pipeline/resolveProviderChain.d.ts +58 -0
- package/dist/pipeline/resolveProviderChain.js +22 -0
- package/dist/pipeline/resolveSubscriptionChain.cjs +68 -0
- package/dist/pipeline/resolveSubscriptionChain.d.cts +68 -0
- package/dist/pipeline/resolveSubscriptionChain.d.ts +68 -0
- package/dist/pipeline/resolveSubscriptionChain.js +43 -0
- package/dist/ports/provider-config-source.cjs +18 -0
- package/dist/ports/provider-config-source.d.cts +51 -0
- package/dist/ports/provider-config-source.d.ts +51 -0
- package/dist/ports/provider-config-source.js +0 -0
- package/dist/ports/web-search-backend.cjs +18 -0
- package/dist/ports/web-search-backend.d.cts +29 -0
- package/dist/ports/web-search-backend.d.ts +29 -0
- package/dist/ports/web-search-backend.js +0 -0
- package/dist/ports.d.cts +10 -7
- package/dist/ports.d.ts +10 -7
- package/dist/provider-proxy/ProviderProxy.cjs +4643 -0
- package/dist/provider-proxy/ProviderProxy.d.cts +16 -0
- package/dist/provider-proxy/ProviderProxy.d.ts +16 -0
- package/dist/provider-proxy/ProviderProxy.js +4618 -0
- package/dist/provider-proxy/ingress/providerProxyShared.d.cts +5 -2
- package/dist/provider-proxy/ingress/providerProxyShared.d.ts +5 -2
- package/dist/provider-proxy/types.d.cts +406 -8
- package/dist/provider-proxy/types.d.ts +406 -8
- package/dist/provider-proxy.cjs +1 -0
- package/dist/provider-proxy.d.cts +8 -5
- package/dist/provider-proxy.d.ts +8 -5
- package/dist/provider-proxy.js +1 -0
- package/dist/routeResolver-BrbK6ja9.d.cts +88 -0
- package/dist/routeResolver-HE-ZO0fO.d.ts +88 -0
- package/dist/transformer/anthropicBetaInject.cjs +51 -0
- package/dist/transformer/anthropicBetaInject.d.cts +20 -0
- package/dist/transformer/anthropicBetaInject.d.ts +20 -0
- package/dist/transformer/anthropicBetaInject.js +25 -0
- package/dist/transformer/transformers/AnthropicTransformer.cjs +1017 -0
- package/dist/transformer/transformers/AnthropicTransformer.d.cts +148 -0
- package/dist/transformer/transformers/AnthropicTransformer.d.ts +148 -0
- package/dist/transformer/transformers/AnthropicTransformer.js +990 -0
- package/dist/transformer/transformers/ReasoningTransformer.cjs +273 -0
- package/dist/transformer/transformers/ReasoningTransformer.d.cts +47 -0
- package/dist/transformer/transformers/ReasoningTransformer.d.ts +47 -0
- package/dist/transformer/transformers/ReasoningTransformer.js +253 -0
- package/dist/transformer/transformers.cjs +3206 -0
- package/dist/transformer/transformers.d.cts +100 -0
- package/dist/transformer/transformers.d.ts +100 -0
- package/dist/transformer/transformers.js +3174 -0
- package/dist/transformer.d.cts +8 -31
- package/dist/transformer.d.ts +8 -31
- package/dist/types-BScIHmPr.d.cts +153 -0
- package/dist/types-BScIHmPr.d.ts +153 -0
- package/package.json +3 -3
- package/dist/SubscriptionAuthSource-Cr4fVEYY.d.cts +0 -264
- package/dist/SubscriptionAuthSource-D89zmiSS.d.ts +0 -264
- package/dist/index-BTSmc9Sm.d.ts +0 -645
- package/dist/index-DXazdTzZ.d.cts +0 -645
- package/dist/types-DCzHkhJt.d.ts +0 -467
- package/dist/types-DZIQbgp0.d.cts +0 -467
package/dist/transformer.d.cts
CHANGED
|
@@ -1,33 +1,10 @@
|
|
|
1
1
|
export { ChainExecutionOptions, TransformerChainExecutor } from './transformer/TransformerChainExecutor.cjs';
|
|
2
|
-
|
|
2
|
+
export { TransformerService } from './transformer/TransformerService.cjs';
|
|
3
|
+
export { registerBuiltinTransformers } from './transformer/transformers.cjs';
|
|
3
4
|
export { Annotation, ImageContent, LLMProvider, MessageContent, ModelRoute, ModelTransformerConfig, ReasoningConfig, RequestConfig, RequestRouteInfo, ResolvedTransformerChain, StreamChunk, TextContent, ThinkLevel, ThinkingContent, ToolCall, ToolChoice, ToolParameterSchema, TransformRequestResult, Transformer, TransformerChainConfig, TransformerConfigEntry, TransformerConstructor, TransformerContext, TransformerLogger, TransformerOptions, TransformerReference, TransformerServiceConfig, UnifiedChatRequest, UnifiedChatResponse, UnifiedMessage, UnifiedTool, UrlCitation } from './transformer/types.cjs';
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
* @module transformer/transformers/index
|
|
11
|
-
*/
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Single self-registration entry point for the built-in transformer set.
|
|
15
|
-
*
|
|
16
|
-
* This is the **one** place the built-in set is seeded onto a
|
|
17
|
-
* {@link TransformerService}. Production seeders (bootstrap deferred-init and
|
|
18
|
-
* the host proxy's local instance) call this instead of
|
|
19
|
-
* re-deriving the set from {@link getBuiltinTransformers} at the call site, so
|
|
20
|
-
* adding/removing a built-in is a single-file edit (append to
|
|
21
|
-
* {@link BuiltinTransformers} + {@link BUILTIN_TRANSFORMER_NAMES} + its module)
|
|
22
|
-
* that every seeder inherits.
|
|
23
|
-
*
|
|
24
|
-
* Registration is delegated verbatim to {@link TransformerService.initialize}
|
|
25
|
-
* so the registered map contents and all side effects (constructor-vs-instance
|
|
26
|
-
* handling, static `TransformerName` honoring, the summary log line) are
|
|
27
|
-
* byte-identical to the prior `initialize(getBuiltinTransformers())` call.
|
|
28
|
-
*
|
|
29
|
-
* @param service - The TransformerService instance to seed.
|
|
30
|
-
*/
|
|
31
|
-
declare function registerBuiltinTransformers(service: TransformerService): Promise<void>;
|
|
32
|
-
|
|
33
|
-
export { TransformerService, registerBuiltinTransformers };
|
|
5
|
+
import './transformer/transformers/AnthropicTransformer.cjs';
|
|
6
|
+
import './transformer/transformers/GeminiCodeAssistTransformer.cjs';
|
|
7
|
+
import './transformer/transformers/GeminiTransformer.cjs';
|
|
8
|
+
import './transformer/transformers/OpenAIResponseTransformer.cjs';
|
|
9
|
+
import './transformer/transformers/OpenCodeGoTransformer.cjs';
|
|
10
|
+
import './transformer/transformers/ReasoningTransformer.cjs';
|
package/dist/transformer.d.ts
CHANGED
|
@@ -1,33 +1,10 @@
|
|
|
1
1
|
export { ChainExecutionOptions, TransformerChainExecutor } from './transformer/TransformerChainExecutor.js';
|
|
2
|
-
|
|
2
|
+
export { TransformerService } from './transformer/TransformerService.js';
|
|
3
|
+
export { registerBuiltinTransformers } from './transformer/transformers.js';
|
|
3
4
|
export { Annotation, ImageContent, LLMProvider, MessageContent, ModelRoute, ModelTransformerConfig, ReasoningConfig, RequestConfig, RequestRouteInfo, ResolvedTransformerChain, StreamChunk, TextContent, ThinkLevel, ThinkingContent, ToolCall, ToolChoice, ToolParameterSchema, TransformRequestResult, Transformer, TransformerChainConfig, TransformerConfigEntry, TransformerConstructor, TransformerContext, TransformerLogger, TransformerOptions, TransformerReference, TransformerServiceConfig, UnifiedChatRequest, UnifiedChatResponse, UnifiedMessage, UnifiedTool, UrlCitation } from './transformer/types.js';
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
* @module transformer/transformers/index
|
|
11
|
-
*/
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Single self-registration entry point for the built-in transformer set.
|
|
15
|
-
*
|
|
16
|
-
* This is the **one** place the built-in set is seeded onto a
|
|
17
|
-
* {@link TransformerService}. Production seeders (bootstrap deferred-init and
|
|
18
|
-
* the host proxy's local instance) call this instead of
|
|
19
|
-
* re-deriving the set from {@link getBuiltinTransformers} at the call site, so
|
|
20
|
-
* adding/removing a built-in is a single-file edit (append to
|
|
21
|
-
* {@link BuiltinTransformers} + {@link BUILTIN_TRANSFORMER_NAMES} + its module)
|
|
22
|
-
* that every seeder inherits.
|
|
23
|
-
*
|
|
24
|
-
* Registration is delegated verbatim to {@link TransformerService.initialize}
|
|
25
|
-
* so the registered map contents and all side effects (constructor-vs-instance
|
|
26
|
-
* handling, static `TransformerName` honoring, the summary log line) are
|
|
27
|
-
* byte-identical to the prior `initialize(getBuiltinTransformers())` call.
|
|
28
|
-
*
|
|
29
|
-
* @param service - The TransformerService instance to seed.
|
|
30
|
-
*/
|
|
31
|
-
declare function registerBuiltinTransformers(service: TransformerService): Promise<void>;
|
|
32
|
-
|
|
33
|
-
export { TransformerService, registerBuiltinTransformers };
|
|
5
|
+
import './transformer/transformers/AnthropicTransformer.js';
|
|
6
|
+
import './transformer/transformers/GeminiCodeAssistTransformer.js';
|
|
7
|
+
import './transformer/transformers/GeminiTransformer.js';
|
|
8
|
+
import './transformer/transformers/OpenAIResponseTransformer.js';
|
|
9
|
+
import './transformer/transformers/OpenCodeGoTransformer.js';
|
|
10
|
+
import './transformer/transformers/ReasoningTransformer.js';
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import { MessageBlock } from '@omnicross/contracts/message-blocks';
|
|
2
|
+
import { SimpleChatMessage, ThinkLevel, SimpleChatAudio, SimpleChatVideo } from '@omnicross/contracts/completion-types';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Native Search Types
|
|
6
|
+
*
|
|
7
|
+
* Type definitions for provider-native web search capabilities.
|
|
8
|
+
* Used by NativeSearchInjector to detect and configure built-in
|
|
9
|
+
* search for OpenAI, Anthropic, Google, xAI, and OpenRouter.
|
|
10
|
+
*
|
|
11
|
+
* @module completion/native-search-types
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
/** Providers that support native/built-in web search */
|
|
15
|
+
type NativeSearchProvider = 'openai' | 'anthropic' | 'google' | 'xai' | 'openrouter';
|
|
16
|
+
/** Result of detecting native search support for a model */
|
|
17
|
+
interface NativeSearchDetectionResult {
|
|
18
|
+
/** Whether the model supports native search */
|
|
19
|
+
supported: boolean;
|
|
20
|
+
/** Which native provider to use, if supported */
|
|
21
|
+
nativeProvider: NativeSearchProvider | null;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Model ID patterns for detecting native search support.
|
|
25
|
+
* OpenRouter is detected via provider metadata, not model ID.
|
|
26
|
+
*/
|
|
27
|
+
declare const NATIVE_SEARCH_MODEL_PATTERNS: Record<NativeSearchProvider, RegExp[]>;
|
|
28
|
+
/**
|
|
29
|
+
* OpenAI models that use Chat Completion endpoint (not Response API).
|
|
30
|
+
* These models use `web_search_options` instead of a `web_search` tool.
|
|
31
|
+
*/
|
|
32
|
+
declare const OPENAI_CHAT_COMPLETION_SEARCH_MODELS: string[];
|
|
33
|
+
/**
|
|
34
|
+
* Models that match a native search pattern but do NOT support web search.
|
|
35
|
+
* These are excluded from auto-detection (but can still be user-overridden).
|
|
36
|
+
*
|
|
37
|
+
* - `gpt-4.1-nano`: Matches `/^gpt-4/` but OpenAI explicitly excludes it
|
|
38
|
+
* from web search support in the Responses API.
|
|
39
|
+
*/
|
|
40
|
+
declare const NATIVE_SEARCH_EXCLUDED_MODELS: string[];
|
|
41
|
+
/** Native search tool names that should NOT be executed locally */
|
|
42
|
+
declare const NATIVE_SEARCH_TOOL_NAMES: string[];
|
|
43
|
+
/** User-facing configuration for native search */
|
|
44
|
+
interface NativeSearchUserConfig {
|
|
45
|
+
/** Whether native search is enabled */
|
|
46
|
+
enabled: boolean;
|
|
47
|
+
/** Max search results / uses (maps to provider-specific settings) */
|
|
48
|
+
maxResults?: number;
|
|
49
|
+
/** Domains to block (Anthropic) */
|
|
50
|
+
blockedDomains?: string[];
|
|
51
|
+
/** xAI search mode override */
|
|
52
|
+
searchMode?: 'on' | 'off' | 'auto';
|
|
53
|
+
/** xAI search sources */
|
|
54
|
+
sources?: Array<{
|
|
55
|
+
type: 'web' | 'x' | 'news';
|
|
56
|
+
}>;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Request body augmentation produced by NativeSearchInjector.
|
|
60
|
+
*
|
|
61
|
+
* - `additionalTools`: Appended to the tools array in the request body.
|
|
62
|
+
* - `bodyFields`: Merged into the top-level request body.
|
|
63
|
+
*/
|
|
64
|
+
interface NativeSearchAugmentation {
|
|
65
|
+
/** Extra tools to append (OpenAI web_search, Anthropic web_search_20250305, Gemini grounding) */
|
|
66
|
+
additionalTools?: unknown[];
|
|
67
|
+
/** Top-level body fields (xAI search_parameters, OpenRouter plugins, OpenAI web_search_options) */
|
|
68
|
+
bodyFields?: Record<string, unknown>;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Map from API format to potential native search providers.
|
|
72
|
+
*
|
|
73
|
+
* Note: `openai` (Chat Completions) is NOT mapped here because regular models
|
|
74
|
+
* (gpt-4o, o1, etc.) don't support native search via Chat Completions API.
|
|
75
|
+
* Only `gpt-4o-search-preview` models support it (via `web_search_options` body
|
|
76
|
+
* field), and those are handled by a special case in `detectNativeSearch()`.
|
|
77
|
+
*
|
|
78
|
+
* `openai-response` (Responses API) DOES support native `web_search` tool
|
|
79
|
+
* for gpt-4o, o1, o3, o4-mini, etc.
|
|
80
|
+
*/
|
|
81
|
+
declare const API_FORMAT_PROVIDER_MAP: Partial<Record<ApiFormat, NativeSearchProvider>>;
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Completion Service Types
|
|
85
|
+
*
|
|
86
|
+
* Type definitions for completion options, results, and callbacks.
|
|
87
|
+
*/
|
|
88
|
+
|
|
89
|
+
interface CompletionOptions {
|
|
90
|
+
providerId: string;
|
|
91
|
+
model: string;
|
|
92
|
+
messages: SimpleChatMessage[];
|
|
93
|
+
maxTokens?: number;
|
|
94
|
+
temperature?: number;
|
|
95
|
+
stream?: boolean;
|
|
96
|
+
/** Thinking effort level for reasoning models */
|
|
97
|
+
thinkLevel?: ThinkLevel;
|
|
98
|
+
/** Native search augmentation to apply to the request body */
|
|
99
|
+
nativeSearchAugmentation?: NativeSearchAugmentation;
|
|
100
|
+
/** Session ID for API key pool affinity (preserves prompt cache) and usage attribution. */
|
|
101
|
+
sessionId?: string;
|
|
102
|
+
/**
|
|
103
|
+
* Assistant-message id this request is producing — used to attribute
|
|
104
|
+
* recorded usage rows back to host messages. Optional; if absent the row is
|
|
105
|
+
* still recorded but won't be linked.
|
|
106
|
+
*/
|
|
107
|
+
messageId?: string;
|
|
108
|
+
/**
|
|
109
|
+
* Parent message id (for subagent-style nested calls). Best-effort: callers
|
|
110
|
+
* that know the parent should fill this; otherwise leave unset.
|
|
111
|
+
*/
|
|
112
|
+
parentMessageId?: string;
|
|
113
|
+
/**
|
|
114
|
+
* Opt into the Anthropic 1M-context tier for this request. The transformer
|
|
115
|
+
* pipeline (and any direct Anthropic-format paths) inject the
|
|
116
|
+
* `'context-1m-2025-08-07'` beta into the outbound request body when this
|
|
117
|
+
* is true AND the resolved model is in the 1M-capable allowlist.
|
|
118
|
+
*/
|
|
119
|
+
useExtendedContext?: boolean;
|
|
120
|
+
}
|
|
121
|
+
interface CompletionResult {
|
|
122
|
+
success: boolean;
|
|
123
|
+
message?: SimpleChatMessage;
|
|
124
|
+
error?: string;
|
|
125
|
+
usage?: {
|
|
126
|
+
promptTokens: number;
|
|
127
|
+
completionTokens: number;
|
|
128
|
+
totalTokens: number;
|
|
129
|
+
};
|
|
130
|
+
/** Provider finish reason (e.g. 'stop', 'tool_use', 'max_tokens') */
|
|
131
|
+
finishReason?: string;
|
|
132
|
+
}
|
|
133
|
+
interface StreamCallbacks {
|
|
134
|
+
onStart?: (messageId: string) => void;
|
|
135
|
+
onDelta?: (content: string) => void;
|
|
136
|
+
onReasoning?: (reasoning: string) => void;
|
|
137
|
+
onAudio?: (audio: SimpleChatAudio) => void;
|
|
138
|
+
onVideo?: (video: SimpleChatVideo) => void;
|
|
139
|
+
/** Called when a new content block is created (thinking, text, tool_use, tool_result) */
|
|
140
|
+
onBlock?: (block: MessageBlock) => void;
|
|
141
|
+
onDone?: (message: SimpleChatMessage, usage?: CompletionResult['usage'], metrics?: {
|
|
142
|
+
completionTokens: number;
|
|
143
|
+
timeCompletionMs: number;
|
|
144
|
+
timeFirstTokenMs?: number;
|
|
145
|
+
}) => void;
|
|
146
|
+
onError?: (error: string) => void;
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* API format type for determining endpoint structure
|
|
150
|
+
*/
|
|
151
|
+
type ApiFormat = 'openai' | 'anthropic' | 'google' | 'azure-openai' | 'openai-response';
|
|
152
|
+
|
|
153
|
+
export { type ApiFormat as A, type CompletionOptions as C, NATIVE_SEARCH_TOOL_NAMES as N, OPENAI_CHAT_COMPLETION_SEARCH_MODELS as O, type StreamCallbacks as S, type CompletionResult as a, type NativeSearchAugmentation as b, type NativeSearchDetectionResult as c, type NativeSearchProvider as d, type NativeSearchUserConfig as e, API_FORMAT_PROVIDER_MAP as f, NATIVE_SEARCH_EXCLUDED_MODELS as g, NATIVE_SEARCH_MODEL_PATTERNS as h };
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import { MessageBlock } from '@omnicross/contracts/message-blocks';
|
|
2
|
+
import { SimpleChatMessage, ThinkLevel, SimpleChatAudio, SimpleChatVideo } from '@omnicross/contracts/completion-types';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Native Search Types
|
|
6
|
+
*
|
|
7
|
+
* Type definitions for provider-native web search capabilities.
|
|
8
|
+
* Used by NativeSearchInjector to detect and configure built-in
|
|
9
|
+
* search for OpenAI, Anthropic, Google, xAI, and OpenRouter.
|
|
10
|
+
*
|
|
11
|
+
* @module completion/native-search-types
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
/** Providers that support native/built-in web search */
|
|
15
|
+
type NativeSearchProvider = 'openai' | 'anthropic' | 'google' | 'xai' | 'openrouter';
|
|
16
|
+
/** Result of detecting native search support for a model */
|
|
17
|
+
interface NativeSearchDetectionResult {
|
|
18
|
+
/** Whether the model supports native search */
|
|
19
|
+
supported: boolean;
|
|
20
|
+
/** Which native provider to use, if supported */
|
|
21
|
+
nativeProvider: NativeSearchProvider | null;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Model ID patterns for detecting native search support.
|
|
25
|
+
* OpenRouter is detected via provider metadata, not model ID.
|
|
26
|
+
*/
|
|
27
|
+
declare const NATIVE_SEARCH_MODEL_PATTERNS: Record<NativeSearchProvider, RegExp[]>;
|
|
28
|
+
/**
|
|
29
|
+
* OpenAI models that use Chat Completion endpoint (not Response API).
|
|
30
|
+
* These models use `web_search_options` instead of a `web_search` tool.
|
|
31
|
+
*/
|
|
32
|
+
declare const OPENAI_CHAT_COMPLETION_SEARCH_MODELS: string[];
|
|
33
|
+
/**
|
|
34
|
+
* Models that match a native search pattern but do NOT support web search.
|
|
35
|
+
* These are excluded from auto-detection (but can still be user-overridden).
|
|
36
|
+
*
|
|
37
|
+
* - `gpt-4.1-nano`: Matches `/^gpt-4/` but OpenAI explicitly excludes it
|
|
38
|
+
* from web search support in the Responses API.
|
|
39
|
+
*/
|
|
40
|
+
declare const NATIVE_SEARCH_EXCLUDED_MODELS: string[];
|
|
41
|
+
/** Native search tool names that should NOT be executed locally */
|
|
42
|
+
declare const NATIVE_SEARCH_TOOL_NAMES: string[];
|
|
43
|
+
/** User-facing configuration for native search */
|
|
44
|
+
interface NativeSearchUserConfig {
|
|
45
|
+
/** Whether native search is enabled */
|
|
46
|
+
enabled: boolean;
|
|
47
|
+
/** Max search results / uses (maps to provider-specific settings) */
|
|
48
|
+
maxResults?: number;
|
|
49
|
+
/** Domains to block (Anthropic) */
|
|
50
|
+
blockedDomains?: string[];
|
|
51
|
+
/** xAI search mode override */
|
|
52
|
+
searchMode?: 'on' | 'off' | 'auto';
|
|
53
|
+
/** xAI search sources */
|
|
54
|
+
sources?: Array<{
|
|
55
|
+
type: 'web' | 'x' | 'news';
|
|
56
|
+
}>;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Request body augmentation produced by NativeSearchInjector.
|
|
60
|
+
*
|
|
61
|
+
* - `additionalTools`: Appended to the tools array in the request body.
|
|
62
|
+
* - `bodyFields`: Merged into the top-level request body.
|
|
63
|
+
*/
|
|
64
|
+
interface NativeSearchAugmentation {
|
|
65
|
+
/** Extra tools to append (OpenAI web_search, Anthropic web_search_20250305, Gemini grounding) */
|
|
66
|
+
additionalTools?: unknown[];
|
|
67
|
+
/** Top-level body fields (xAI search_parameters, OpenRouter plugins, OpenAI web_search_options) */
|
|
68
|
+
bodyFields?: Record<string, unknown>;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Map from API format to potential native search providers.
|
|
72
|
+
*
|
|
73
|
+
* Note: `openai` (Chat Completions) is NOT mapped here because regular models
|
|
74
|
+
* (gpt-4o, o1, etc.) don't support native search via Chat Completions API.
|
|
75
|
+
* Only `gpt-4o-search-preview` models support it (via `web_search_options` body
|
|
76
|
+
* field), and those are handled by a special case in `detectNativeSearch()`.
|
|
77
|
+
*
|
|
78
|
+
* `openai-response` (Responses API) DOES support native `web_search` tool
|
|
79
|
+
* for gpt-4o, o1, o3, o4-mini, etc.
|
|
80
|
+
*/
|
|
81
|
+
declare const API_FORMAT_PROVIDER_MAP: Partial<Record<ApiFormat, NativeSearchProvider>>;
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Completion Service Types
|
|
85
|
+
*
|
|
86
|
+
* Type definitions for completion options, results, and callbacks.
|
|
87
|
+
*/
|
|
88
|
+
|
|
89
|
+
interface CompletionOptions {
|
|
90
|
+
providerId: string;
|
|
91
|
+
model: string;
|
|
92
|
+
messages: SimpleChatMessage[];
|
|
93
|
+
maxTokens?: number;
|
|
94
|
+
temperature?: number;
|
|
95
|
+
stream?: boolean;
|
|
96
|
+
/** Thinking effort level for reasoning models */
|
|
97
|
+
thinkLevel?: ThinkLevel;
|
|
98
|
+
/** Native search augmentation to apply to the request body */
|
|
99
|
+
nativeSearchAugmentation?: NativeSearchAugmentation;
|
|
100
|
+
/** Session ID for API key pool affinity (preserves prompt cache) and usage attribution. */
|
|
101
|
+
sessionId?: string;
|
|
102
|
+
/**
|
|
103
|
+
* Assistant-message id this request is producing — used to attribute
|
|
104
|
+
* recorded usage rows back to host messages. Optional; if absent the row is
|
|
105
|
+
* still recorded but won't be linked.
|
|
106
|
+
*/
|
|
107
|
+
messageId?: string;
|
|
108
|
+
/**
|
|
109
|
+
* Parent message id (for subagent-style nested calls). Best-effort: callers
|
|
110
|
+
* that know the parent should fill this; otherwise leave unset.
|
|
111
|
+
*/
|
|
112
|
+
parentMessageId?: string;
|
|
113
|
+
/**
|
|
114
|
+
* Opt into the Anthropic 1M-context tier for this request. The transformer
|
|
115
|
+
* pipeline (and any direct Anthropic-format paths) inject the
|
|
116
|
+
* `'context-1m-2025-08-07'` beta into the outbound request body when this
|
|
117
|
+
* is true AND the resolved model is in the 1M-capable allowlist.
|
|
118
|
+
*/
|
|
119
|
+
useExtendedContext?: boolean;
|
|
120
|
+
}
|
|
121
|
+
interface CompletionResult {
|
|
122
|
+
success: boolean;
|
|
123
|
+
message?: SimpleChatMessage;
|
|
124
|
+
error?: string;
|
|
125
|
+
usage?: {
|
|
126
|
+
promptTokens: number;
|
|
127
|
+
completionTokens: number;
|
|
128
|
+
totalTokens: number;
|
|
129
|
+
};
|
|
130
|
+
/** Provider finish reason (e.g. 'stop', 'tool_use', 'max_tokens') */
|
|
131
|
+
finishReason?: string;
|
|
132
|
+
}
|
|
133
|
+
interface StreamCallbacks {
|
|
134
|
+
onStart?: (messageId: string) => void;
|
|
135
|
+
onDelta?: (content: string) => void;
|
|
136
|
+
onReasoning?: (reasoning: string) => void;
|
|
137
|
+
onAudio?: (audio: SimpleChatAudio) => void;
|
|
138
|
+
onVideo?: (video: SimpleChatVideo) => void;
|
|
139
|
+
/** Called when a new content block is created (thinking, text, tool_use, tool_result) */
|
|
140
|
+
onBlock?: (block: MessageBlock) => void;
|
|
141
|
+
onDone?: (message: SimpleChatMessage, usage?: CompletionResult['usage'], metrics?: {
|
|
142
|
+
completionTokens: number;
|
|
143
|
+
timeCompletionMs: number;
|
|
144
|
+
timeFirstTokenMs?: number;
|
|
145
|
+
}) => void;
|
|
146
|
+
onError?: (error: string) => void;
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* API format type for determining endpoint structure
|
|
150
|
+
*/
|
|
151
|
+
type ApiFormat = 'openai' | 'anthropic' | 'google' | 'azure-openai' | 'openai-response';
|
|
152
|
+
|
|
153
|
+
export { type ApiFormat as A, type CompletionOptions as C, NATIVE_SEARCH_TOOL_NAMES as N, OPENAI_CHAT_COMPLETION_SEARCH_MODELS as O, type StreamCallbacks as S, type CompletionResult as a, type NativeSearchAugmentation as b, type NativeSearchDetectionResult as c, type NativeSearchProvider as d, type NativeSearchUserConfig as e, API_FORMAT_PROVIDER_MAP as f, NATIVE_SEARCH_EXCLUDED_MODELS as g, NATIVE_SEARCH_MODEL_PATTERNS as h };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@omnicross/core",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"description": "Omnicross LLM serving core — provider dispatch, completion pipeline, transformers, and the provider proxy.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Sayo (https://github.com/Dumoedss)",
|
|
@@ -54,9 +54,9 @@
|
|
|
54
54
|
"typecheck": "tsc -p tsconfig.typecheck.json --noEmit"
|
|
55
55
|
},
|
|
56
56
|
"dependencies": {
|
|
57
|
+
"@mozilla/readability": "^0.6.0",
|
|
57
58
|
"@omnicross/contracts": "^0.1.0",
|
|
58
|
-
"turndown": "^7.2.2",
|
|
59
59
|
"jsdom": "^24.1.3",
|
|
60
|
-
"
|
|
60
|
+
"turndown": "^7.2.2"
|
|
61
61
|
}
|
|
62
62
|
}
|
|
@@ -1,264 +0,0 @@
|
|
|
1
|
-
import { OpenCodeGoTokenConfig, OpenCodeGoScenario, OpenCodeGoModelEntry } from '@omnicross/contracts/subscription-types';
|
|
2
|
-
import { AuthStrategy } from './pipeline/SubscriptionAuthStrategy.cjs';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* AuthSource — unified outbound-authentication strategy for the provider
|
|
6
|
-
* request pipeline.
|
|
7
|
-
*
|
|
8
|
-
* Phase 2 of the `provider-request-pipeline` OpenSpec change (design D3).
|
|
9
|
-
*
|
|
10
|
-
* The three consumer paths (the wire-format proxy handler, the host engine
|
|
11
|
-
* adapter, TransformerHandler) each authenticate differently:
|
|
12
|
-
*
|
|
13
|
-
* - provider-key (+ ApiKeyPool failover) — LLM-config provider rows
|
|
14
|
-
* - subscription `AuthStrategy` (+ 401 refresh + fallback) — code-cli OAuth
|
|
15
|
-
* - OAuth pass-through — SDK forwards its own Bearer
|
|
16
|
-
*
|
|
17
|
-
* `AuthSource` is the single contract that unifies these. THIS PHASE ONLY
|
|
18
|
-
* DEFINES the interface and provides three behavior-preserving WRAPPERS
|
|
19
|
-
* (`LlmConfigProviderAuth`, `SubscriptionAuthSource`, `OAuthPassThroughAuth`)
|
|
20
|
-
* around the existing logic. NO caller is routed through it yet — the core
|
|
21
|
-
* (`executeProviderCall`) is NOT changed to consume `ctx.auth`, and
|
|
22
|
-
* the host handler's branch structure is UNCHANGED. Wiring (and
|
|
23
|
-
* the `onResult` pool-rotation integration) is Phase 3.
|
|
24
|
-
*
|
|
25
|
-
* @module pipeline/AuthSource
|
|
26
|
-
*/
|
|
27
|
-
/**
|
|
28
|
-
* Hints an `AuthSource` may need to vary header formatting per request.
|
|
29
|
-
*
|
|
30
|
-
* Mirrors the subscription-side `AuthApplyHints` (which uses optional
|
|
31
|
-
* `upstreamUrl` / `resolvedModel`) but with REQUIRED fields, since the
|
|
32
|
-
* pipeline always knows both at the point it applies headers. Adapters that
|
|
33
|
-
* wrap the looser subscription shape map these across at the boundary.
|
|
34
|
-
*/
|
|
35
|
-
interface AuthApplyHints {
|
|
36
|
-
/** Resolved upstream URL the request will be sent to. */
|
|
37
|
-
upstreamUrl: string;
|
|
38
|
-
/** Resolved model id for the request. */
|
|
39
|
-
model: string;
|
|
40
|
-
}
|
|
41
|
-
/**
|
|
42
|
-
* Result of {@link AuthSource.onResult}.
|
|
43
|
-
*
|
|
44
|
-
* `rebound` is `true` when the auth source rotated to a different credential
|
|
45
|
-
* (e.g. ApiKeyPool re-bound the session to a new key after a 429). `newKey`
|
|
46
|
-
* carries the freshly-resolved key string when a rotation produced one, so a
|
|
47
|
-
* caller MAY retry the same call once with it. Mirrors the
|
|
48
|
-
* `{ newKey | null }` contract of `ApiKeyPoolService.reportError` lifted into
|
|
49
|
-
* a structured shape.
|
|
50
|
-
*/
|
|
51
|
-
interface AuthResultOutcome {
|
|
52
|
-
/** Whether the credential was rotated/re-bound as a result of this status. */
|
|
53
|
-
rebound: boolean;
|
|
54
|
-
/** The new resolved key when a rotation produced one; omitted otherwise. */
|
|
55
|
-
newKey?: string;
|
|
56
|
-
}
|
|
57
|
-
/**
|
|
58
|
-
* A pluggable outbound-authentication source for one provider request.
|
|
59
|
-
*
|
|
60
|
-
* Implementations OWN exactly the auth concern: which headers carry the
|
|
61
|
-
* credential, how to recover from a 401, where the request should be sent
|
|
62
|
-
* (when the credential dictates the endpoint), and how to react to a final
|
|
63
|
-
* HTTP status (pool rotation / refresh). The pipeline core composes the rest.
|
|
64
|
-
*/
|
|
65
|
-
interface AuthSource {
|
|
66
|
-
/**
|
|
67
|
-
* Inject the authentication headers for this request, mutating `headers`
|
|
68
|
-
* in place. Implementations MAY refresh expiring tokens here.
|
|
69
|
-
*
|
|
70
|
-
* NOTE (Phase 2 boundary, see report): exactly WHAT this owns vs what the
|
|
71
|
-
* ingress assembles (content-type, OpenRouter app headers, proxy auth
|
|
72
|
-
* stripping) is intentionally left to the caller this phase. The wrappers
|
|
73
|
-
* preserve their source's CURRENT header behavior verbatim.
|
|
74
|
-
*/
|
|
75
|
-
applyHeaders(headers: Record<string, string>, hints: AuthApplyHints): Promise<void> | void;
|
|
76
|
-
/**
|
|
77
|
-
* Called when the upstream returns 401. Return `true` to ask the caller to
|
|
78
|
-
* retry once with freshly-applied headers; `false` to surface the 401.
|
|
79
|
-
* Optional — sources without a refresh notion omit it.
|
|
80
|
-
*/
|
|
81
|
-
onUnauthorized?(): Promise<boolean>;
|
|
82
|
-
/**
|
|
83
|
-
* Resolve the upstream URL the request should target, when the credential
|
|
84
|
-
* dictates it (e.g. a subscription profile's per-model endpoint). Returns
|
|
85
|
-
* `undefined` when the source does not override the URL (the ingress keeps
|
|
86
|
-
* its own URL logic). Optional.
|
|
87
|
-
*/
|
|
88
|
-
resolveUpstreamUrl?(model: string): string | undefined;
|
|
89
|
-
/**
|
|
90
|
-
* React to a final HTTP status (pool participation seam — design D5).
|
|
91
|
-
*
|
|
92
|
-
* For the provider-key source this reports the status to the
|
|
93
|
-
* `ApiKeyPoolService` (cooldown / disable / re-bind) and returns whether it
|
|
94
|
-
* rotated plus any new key. THIS PHASE ONLY: `onResult` is implemented and
|
|
95
|
-
* unit-tested in isolation; NO caller invokes it yet. Phase 3 wires it into
|
|
96
|
-
* `fetchWithRetry`. Optional.
|
|
97
|
-
*
|
|
98
|
-
* @param status The final HTTP status, or `null` for non-HTTP failures
|
|
99
|
-
* (e.g. network errors). Non-reportable statuses no-op.
|
|
100
|
-
*/
|
|
101
|
-
onResult?(status: number | null): Promise<AuthResultOutcome>;
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
/**
|
|
105
|
-
* SubscriptionAuthSource — `AuthSource` wrapping a subscription `AuthStrategy`.
|
|
106
|
-
*
|
|
107
|
-
* Phase 2 of the `provider-request-pipeline` OpenSpec change (design D3, task 4.3).
|
|
108
|
-
*
|
|
109
|
-
* Re-expresses the subscription auth used by `SubscriptionDispatcher` behind
|
|
110
|
-
* the unified `AuthSource` contract, delegating to the existing
|
|
111
|
-
* `AuthStrategy` so the OAuth refresh / token formatting logic is NOT
|
|
112
|
-
* rewritten:
|
|
113
|
-
*
|
|
114
|
-
* - `applyHeaders` → `stripAuthHeaders(headers)` then
|
|
115
|
-
* `authStrategy.applyHeaders(headers, { upstreamUrl, resolvedModel })`,
|
|
116
|
-
* wrapped in the same best-effort try/catch as
|
|
117
|
-
* `SubscriptionDispatcher.applyHeadersWithRetry` (a thrown
|
|
118
|
-
* `applyHeaders` is logged + swallowed, NOT propagated — preserved
|
|
119
|
-
* verbatim).
|
|
120
|
-
* - `onUnauthorized` → `authStrategy.onUnauthorized()`.
|
|
121
|
-
* - `resolveUpstreamUrl` → `profile.resolveUpstreamUrl?.(model)`.
|
|
122
|
-
*
|
|
123
|
-
* IMPORTANT (Phase 2 scope): this WRAPS the strategy + strip behavior but does
|
|
124
|
-
* NOT re-route `SubscriptionDispatcher` through it. The dispatcher's fragile
|
|
125
|
-
* 401-refresh + fallback loop is left UNCHANGED (task 4.5 deferred). This
|
|
126
|
-
* class is unit-tested in isolation only.
|
|
127
|
-
*
|
|
128
|
-
* @module pipeline/SubscriptionAuthSource
|
|
129
|
-
*/
|
|
130
|
-
|
|
131
|
-
/**
|
|
132
|
-
* Lightweight summary derived from the inbound request body — consumed by a
|
|
133
|
-
* profile's `modelMapper` (scenario routing). Structural mirror of
|
|
134
|
-
* `provider-proxy/types.ts`'s `SubscriptionRequestSummary`, declared here so
|
|
135
|
-
* `SubscriptionAuthProfile.modelMapper` is type-identical WITHOUT a circular
|
|
136
|
-
* import back into `provider-proxy/types` (which imports THIS module).
|
|
137
|
-
*/
|
|
138
|
-
interface SubscriptionRequestSummary {
|
|
139
|
-
messageCount: number;
|
|
140
|
-
estimatedInputTokens: number;
|
|
141
|
-
/**
|
|
142
|
-
* OPTIONAL bounded per-message match-text slice — kept structurally identical
|
|
143
|
-
* to the canonical declaration in `provider-proxy/types.ts` (the two are
|
|
144
|
-
* deliberate mirrors, not one shared import). Consumed only by the OpenCodeGo
|
|
145
|
-
* keyword matcher in `@omnicross/subscriptions`; core writes, never reads it.
|
|
146
|
-
*/
|
|
147
|
-
matchText?: string[];
|
|
148
|
-
}
|
|
149
|
-
/**
|
|
150
|
-
* The subset of a `SubscriptionDispatchProfile` the subscription paths need.
|
|
151
|
-
* Kept structural (not the full profile type) so the wrapper does not pull in
|
|
152
|
-
* the whole registry surface. The full `SubscriptionDispatchProfile` (which IS
|
|
153
|
-
* what gets passed here) satisfies this shape; the optional `mode` + `modelMapper`
|
|
154
|
-
* are read by the built-in `/v1/messages` subscription path (RT2.1) to decide the
|
|
155
|
-
* verbatim-vs-transformer shape and to apply opencodego scenario routing.
|
|
156
|
-
*/
|
|
157
|
-
interface SubscriptionAuthProfile {
|
|
158
|
-
readonly authStrategy: AuthStrategy;
|
|
159
|
-
/** Per-model upstream URL resolver (transformer profiles). Optional for
|
|
160
|
-
* pass-through profiles that hard-code their endpoint upstream. The OPTIONAL
|
|
161
|
-
* 2nd `config` arg (opencodego `baseUrl` override, D1) is additive — existing
|
|
162
|
-
* one-arg callers compile unchanged; mirrors the full
|
|
163
|
-
* `SubscriptionDispatchProfile.resolveUpstreamUrl` so the registry profile
|
|
164
|
-
* stays assignable. */
|
|
165
|
-
readonly resolveUpstreamUrl?: (resolvedModel: string, config?: OpenCodeGoTokenConfig) => string;
|
|
166
|
-
/**
|
|
167
|
-
* Names of provider-level transformers (registered in `TransformerService`)
|
|
168
|
-
* to run on the subscription chain — re-encode Unified → the upstream's wire.
|
|
169
|
-
* The full `SubscriptionDispatchProfile` (which IS what gets passed here)
|
|
170
|
-
* carries these; exposing them on the narrow structural type lets the
|
|
171
|
-
* Responses ingress build the profile's REAL chain (cross-vendor route-to,
|
|
172
|
-
* task #29) instead of hard-coding `['openai-response']`. Absent/empty →
|
|
173
|
-
* the ingress falls back to its endpoint transformer (codex byte-identity).
|
|
174
|
-
*/
|
|
175
|
-
readonly providerTransformerNames?: readonly string[];
|
|
176
|
-
/** Names of model-specific transformers — usually empty. See above. */
|
|
177
|
-
readonly modelTransformerNames?: readonly string[];
|
|
178
|
-
/**
|
|
179
|
-
* OPTIONAL shape-aware provider transformer-name resolver (opencodego zen).
|
|
180
|
-
* Type-identical to `SubscriptionDispatchProfile.resolveProviderTransformerNames`
|
|
181
|
-
* so the registry profile stays assignable. The built-in `/v1/messages`
|
|
182
|
-
* subscription path (Phase 3) consults it via
|
|
183
|
-
* `profile.resolveProviderTransformerNames?.(model, route.subscriptionConfig)`
|
|
184
|
-
* to pick the right zen chain per resolved shape. `config` is `unknown` (core
|
|
185
|
-
* opaque-config discipline — no `@omnicross/subscriptions` import). When ABSENT
|
|
186
|
-
* the path reads the static `providerTransformerNames` exactly as today (codex
|
|
187
|
-
* byte-identity).
|
|
188
|
-
*/
|
|
189
|
-
readonly resolveProviderTransformerNames?: (model: string, config?: unknown) => readonly string[];
|
|
190
|
-
/**
|
|
191
|
-
* Pass-through (claude) vs transformer (codex / opencodego / gemini). The
|
|
192
|
-
* built-in `/v1/messages` subscription path (RT2.1) reads this for its
|
|
193
|
-
* core-local same-format signal (pass-through ⇒ always verbatim relay).
|
|
194
|
-
* Optional on the narrow type — partial profiles built by other route-minting
|
|
195
|
-
* sites may omit it.
|
|
196
|
-
*/
|
|
197
|
-
readonly mode?: 'pass-through' | 'transformer';
|
|
198
|
-
/**
|
|
199
|
-
* Optional model placeholder rewriter — only set for OpenCodeGo. Type-identical
|
|
200
|
-
* to `SubscriptionDispatchProfile.modelMapper` so the registry profile stays
|
|
201
|
-
* assignable. Applied by the built-in `/v1/messages` subscription path BEFORE
|
|
202
|
-
* resolving the upstream URL (so scenario-based shape routing picks the right
|
|
203
|
-
* Anthropic-shape vs OpenAI-shape upstream).
|
|
204
|
-
*/
|
|
205
|
-
readonly modelMapper?: (sdkModel: string, summary: SubscriptionRequestSummary, config: OpenCodeGoTokenConfig | undefined) => {
|
|
206
|
-
resolvedModel: string;
|
|
207
|
-
scenario: OpenCodeGoScenario;
|
|
208
|
-
};
|
|
209
|
-
/**
|
|
210
|
-
* Optional fallback resolver — only set for OpenCodeGo. Type-identical to
|
|
211
|
-
* `SubscriptionDispatchProfile.nextFallback` so the registry profile stays
|
|
212
|
-
* assignable. Read by the built-in `/v1/messages` fallback loop (D6b) to pick
|
|
213
|
-
* the next model after an unrecoverable upstream failure; returns `null` when
|
|
214
|
-
* exhausted (claude / codex / gemini omit it → no fallback attempted).
|
|
215
|
-
*/
|
|
216
|
-
readonly nextFallback?: (scenario: OpenCodeGoScenario, attempted: readonly string[], config: OpenCodeGoTokenConfig | undefined) => OpenCodeGoModelEntry | null;
|
|
217
|
-
/**
|
|
218
|
-
* Optional circuit-breaker admission gate for the PRIMARY (mapped) model (D5
|
|
219
|
-
* primary-gating). Type-identical to `SubscriptionDispatchProfile.allowModel`.
|
|
220
|
-
* Only OpenCodeGo sets it; the core `/v1/messages` loop consults it for the
|
|
221
|
-
* primary before its first attempt and jumps to the first admitting
|
|
222
|
-
* `nextFallback` candidate when the primary's circuit is open. Absent ⇒ the
|
|
223
|
-
* primary is always admitted (claude / codex / gemini — no breaker).
|
|
224
|
-
*/
|
|
225
|
-
readonly allowModel?: (modelId: string) => boolean;
|
|
226
|
-
/**
|
|
227
|
-
* Optional record-outcome callback (D5 record seam). Type-identical to
|
|
228
|
-
* `SubscriptionDispatchProfile.recordModelOutcome`. The core `/v1/messages`
|
|
229
|
-
* loop calls `profile.recordModelOutcome?.(model, ok)` THROUGH this optional
|
|
230
|
-
* field after each attempt, so `@omnicross/core` gains NO import of
|
|
231
|
-
* `@omnicross/subscriptions` (the cross-layer litmus stays 0 — exactly the
|
|
232
|
-
* `nextFallback` precedent). `ok: true` on `2xx`; `ok: false` on
|
|
233
|
-
* thrown/`5xx`/`429`; a non-429 `4xx` is NEUTRAL (the loop does NOT call it).
|
|
234
|
-
* Absent for claude / codex / gemini ⇒ no-op.
|
|
235
|
-
*/
|
|
236
|
-
readonly recordModelOutcome?: (modelId: string, ok: boolean) => void;
|
|
237
|
-
}
|
|
238
|
-
/**
|
|
239
|
-
* Drop auth headers the transformer chain may have set so the `AuthStrategy`
|
|
240
|
-
* is the single source of truth for outbound authentication. Byte-identical
|
|
241
|
-
* to `SubscriptionDispatcher.stripAuthHeaders`.
|
|
242
|
-
*/
|
|
243
|
-
declare function stripAuthHeaders(headers: Record<string, string>): void;
|
|
244
|
-
declare class SubscriptionAuthSource implements AuthSource {
|
|
245
|
-
private readonly profile;
|
|
246
|
-
constructor(profile: SubscriptionAuthProfile);
|
|
247
|
-
/**
|
|
248
|
-
* Strip any transformer-set auth headers, then delegate to the bound
|
|
249
|
-
* strategy. Mirrors `SubscriptionDispatcher`'s
|
|
250
|
-
* `stripAuthHeaders(...)` + `applyHeadersWithRetry(...)` sequence, including
|
|
251
|
-
* the best-effort swallow-and-warn around a throwing `applyHeaders`.
|
|
252
|
-
*
|
|
253
|
-
* The strategy's looser `AuthApplyHints` (optional `upstreamUrl` /
|
|
254
|
-
* `resolvedModel`) is fed from the pipeline's required `{ upstreamUrl,
|
|
255
|
-
* model }` at the boundary.
|
|
256
|
-
*/
|
|
257
|
-
applyHeaders(headers: Record<string, string>, hints: AuthApplyHints): Promise<void>;
|
|
258
|
-
/** Delegate the 401-refresh decision to the bound strategy. */
|
|
259
|
-
onUnauthorized(): Promise<boolean>;
|
|
260
|
-
/** Resolve the upstream URL from the profile, when it provides one. */
|
|
261
|
-
resolveUpstreamUrl(model: string): string | undefined;
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
export { type AuthSource as A, type SubscriptionAuthProfile as S, SubscriptionAuthSource as a, type SubscriptionRequestSummary as b, stripAuthHeaders as s };
|