@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
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/completion/url-builder.ts
|
|
21
|
+
var url_builder_exports = {};
|
|
22
|
+
__export(url_builder_exports, {
|
|
23
|
+
buildAnthropicApiUrl: () => buildAnthropicApiUrl,
|
|
24
|
+
buildAzureOpenAIApiUrl: () => buildAzureOpenAIApiUrl,
|
|
25
|
+
buildGeminiApiUrl: () => buildGeminiApiUrl,
|
|
26
|
+
buildGeminiModelActionUrl: () => buildGeminiModelActionUrl,
|
|
27
|
+
buildOpenAIApiUrl: () => buildOpenAIApiUrl,
|
|
28
|
+
buildOpenAIResponseApiUrl: () => buildOpenAIResponseApiUrl,
|
|
29
|
+
buildProviderApiUrl: () => buildProviderApiUrl,
|
|
30
|
+
normalizeAzureEndpoint: () => normalizeAzureEndpoint,
|
|
31
|
+
resolveApiFormat: () => resolveApiFormat,
|
|
32
|
+
resolveProviderEndpoint: () => resolveProviderEndpoint
|
|
33
|
+
});
|
|
34
|
+
module.exports = __toCommonJS(url_builder_exports);
|
|
35
|
+
var import_endpoint_resolver = require("@omnicross/contracts/endpoint-resolver");
|
|
36
|
+
function resolveApiFormat(provider) {
|
|
37
|
+
if (provider.apiFormat) {
|
|
38
|
+
return provider.apiFormat;
|
|
39
|
+
}
|
|
40
|
+
if (provider.chatApiFormat) {
|
|
41
|
+
return provider.chatApiFormat;
|
|
42
|
+
}
|
|
43
|
+
if (provider.apiType === "claudecode" || provider.apiType === "anthropic") {
|
|
44
|
+
return "anthropic";
|
|
45
|
+
}
|
|
46
|
+
if (provider.apiType === "google") {
|
|
47
|
+
return "google";
|
|
48
|
+
}
|
|
49
|
+
return "openai";
|
|
50
|
+
}
|
|
51
|
+
function buildOpenAIApiUrl(baseUrl) {
|
|
52
|
+
const url = baseUrl.replace(/\/+$/, "");
|
|
53
|
+
if (url.endsWith("/chat/completions")) {
|
|
54
|
+
return url;
|
|
55
|
+
}
|
|
56
|
+
if (/\/v\d+$/.test(url)) {
|
|
57
|
+
return url + "/chat/completions";
|
|
58
|
+
}
|
|
59
|
+
if (url.includes("/chat/completions")) {
|
|
60
|
+
return url;
|
|
61
|
+
}
|
|
62
|
+
return url + "/v1/chat/completions";
|
|
63
|
+
}
|
|
64
|
+
function buildAnthropicApiUrl(baseUrl) {
|
|
65
|
+
const url = baseUrl.replace(/\/+$/, "");
|
|
66
|
+
if (url.endsWith("/messages")) {
|
|
67
|
+
return url;
|
|
68
|
+
}
|
|
69
|
+
if (url.includes("/messages")) {
|
|
70
|
+
return url;
|
|
71
|
+
}
|
|
72
|
+
if (/\/v\d+$/.test(url)) {
|
|
73
|
+
return url + "/messages";
|
|
74
|
+
}
|
|
75
|
+
return url + "/v1/messages";
|
|
76
|
+
}
|
|
77
|
+
function buildGeminiModelActionUrl(baseUrl, model, action) {
|
|
78
|
+
let url = baseUrl.replace(/\/+$/, "");
|
|
79
|
+
if (url.includes("/models/")) {
|
|
80
|
+
return url;
|
|
81
|
+
}
|
|
82
|
+
if (!/\/v\d+(?:beta)?(?:$|\/)/.test(url)) {
|
|
83
|
+
url += "/v1beta";
|
|
84
|
+
}
|
|
85
|
+
return `${url}/models/${model}:${action}`;
|
|
86
|
+
}
|
|
87
|
+
function buildGeminiApiUrl(baseUrl, model, stream) {
|
|
88
|
+
const action = stream ? "streamGenerateContent?alt=sse" : "generateContent";
|
|
89
|
+
return buildGeminiModelActionUrl(baseUrl, model, action);
|
|
90
|
+
}
|
|
91
|
+
function normalizeAzureEndpoint(endpoint) {
|
|
92
|
+
return endpoint.replace(/\/+$/, "").replace(/\/openai(\/v\d+)?$/, "");
|
|
93
|
+
}
|
|
94
|
+
function buildAzureOpenAIApiUrl(baseUrl, model, apiVersion) {
|
|
95
|
+
const endpoint = normalizeAzureEndpoint(baseUrl);
|
|
96
|
+
return `${endpoint}/openai/deployments/${model}/chat/completions?api-version=${apiVersion}`;
|
|
97
|
+
}
|
|
98
|
+
function buildOpenAIResponseApiUrl(baseUrl) {
|
|
99
|
+
const url = baseUrl.replace(/\/+$/, "");
|
|
100
|
+
if (url.endsWith("/responses")) {
|
|
101
|
+
return url;
|
|
102
|
+
}
|
|
103
|
+
if (/\/v\d+$/.test(url)) {
|
|
104
|
+
return url + "/responses";
|
|
105
|
+
}
|
|
106
|
+
return url + "/v1/responses";
|
|
107
|
+
}
|
|
108
|
+
var resolveProviderEndpoint = import_endpoint_resolver.resolveProviderEndpoint;
|
|
109
|
+
function buildProviderApiUrl(provider, options = {}) {
|
|
110
|
+
const format = resolveApiFormat(provider);
|
|
111
|
+
const { baseUrl } = resolveProviderEndpoint(provider);
|
|
112
|
+
switch (format) {
|
|
113
|
+
case "anthropic":
|
|
114
|
+
return buildAnthropicApiUrl(baseUrl);
|
|
115
|
+
case "google":
|
|
116
|
+
return buildGeminiApiUrl(baseUrl, options.model || "", options.stream || false);
|
|
117
|
+
case "azure-openai":
|
|
118
|
+
return buildAzureOpenAIApiUrl(baseUrl, options.model || "", provider.apiVersion || "2024-08-01-preview");
|
|
119
|
+
case "openai-response":
|
|
120
|
+
return buildOpenAIResponseApiUrl(baseUrl);
|
|
121
|
+
case "openai":
|
|
122
|
+
default:
|
|
123
|
+
return buildOpenAIApiUrl(baseUrl);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
127
|
+
0 && (module.exports = {
|
|
128
|
+
buildAnthropicApiUrl,
|
|
129
|
+
buildAzureOpenAIApiUrl,
|
|
130
|
+
buildGeminiApiUrl,
|
|
131
|
+
buildGeminiModelActionUrl,
|
|
132
|
+
buildOpenAIApiUrl,
|
|
133
|
+
buildOpenAIResponseApiUrl,
|
|
134
|
+
buildProviderApiUrl,
|
|
135
|
+
normalizeAzureEndpoint,
|
|
136
|
+
resolveApiFormat,
|
|
137
|
+
resolveProviderEndpoint
|
|
138
|
+
});
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { LLMProvider } from '@omnicross/contracts/llm-config';
|
|
2
|
+
import { A as ApiFormat } from '../types-BScIHmPr.cjs';
|
|
3
|
+
import { resolveProviderEndpoint as resolveProviderEndpoint$1 } from '@omnicross/contracts/endpoint-resolver';
|
|
4
|
+
import '@omnicross/contracts/message-blocks';
|
|
5
|
+
import '@omnicross/contracts/completion-types';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* API URL Building Utilities
|
|
9
|
+
*
|
|
10
|
+
* Functions for building correct API URLs based on provider format.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Resolve API format from provider configuration
|
|
15
|
+
*
|
|
16
|
+
* Priority:
|
|
17
|
+
* 1. apiFormat (v3 preferred field)
|
|
18
|
+
* 2. chatApiFormat (legacy v3 field)
|
|
19
|
+
* 3. apiType if it's an explicit format (claudecode/anthropic/google)
|
|
20
|
+
* 4. Default to openai
|
|
21
|
+
*
|
|
22
|
+
* Note: This enables implicit routing - the API format determines which
|
|
23
|
+
* transformer is automatically applied without explicit router configuration.
|
|
24
|
+
*/
|
|
25
|
+
declare function resolveApiFormat(provider: LLMProvider): ApiFormat;
|
|
26
|
+
/**
|
|
27
|
+
* Build OpenAI Chat Completions API URL
|
|
28
|
+
* Handles various input formats:
|
|
29
|
+
* - https://api.openai.com → https://api.openai.com/v1/chat/completions
|
|
30
|
+
* - https://api.openai.com/v1/chat/completions → unchanged
|
|
31
|
+
* - https://api.deepseek.com/v1 → https://api.deepseek.com/v1/chat/completions
|
|
32
|
+
* - https://api.z.ai/api/coding/paas/v4 → https://api.z.ai/api/coding/paas/v4/chat/completions
|
|
33
|
+
*/
|
|
34
|
+
declare function buildOpenAIApiUrl(baseUrl: string): string;
|
|
35
|
+
/**
|
|
36
|
+
* Build Anthropic Messages API URL
|
|
37
|
+
* Handles various input formats:
|
|
38
|
+
* - https://api.anthropic.com → https://api.anthropic.com/v1/messages
|
|
39
|
+
* - https://api.anthropic.com/v1/messages → unchanged
|
|
40
|
+
* - https://api.z.ai/api/anthropic → https://api.z.ai/api/anthropic/v1/messages
|
|
41
|
+
* - https://api.z.ai/api/anthropic/v2 → https://api.z.ai/api/anthropic/v2/messages
|
|
42
|
+
*/
|
|
43
|
+
declare function buildAnthropicApiUrl(baseUrl: string): string;
|
|
44
|
+
/**
|
|
45
|
+
* Build a Gemini /v1beta/models/{model}:{action} URL with base-URL normalization.
|
|
46
|
+
* Strips trailing slashes, skips appending /v1beta if the base already has a version path,
|
|
47
|
+
* and returns the URL as-is if it already contains /models/.
|
|
48
|
+
*/
|
|
49
|
+
declare function buildGeminiModelActionUrl(baseUrl: string, model: string, action: string): string;
|
|
50
|
+
/**
|
|
51
|
+
* Build Google Gemini API URL
|
|
52
|
+
* Gemini uses a dynamic URL structure: /v1beta/models/{model}:generateContent or :streamGenerateContent
|
|
53
|
+
* @param baseUrl - Base URL (e.g., https://generativelanguage.googleapis.com)
|
|
54
|
+
* @param model - Model name (e.g., gemini-2.0-flash)
|
|
55
|
+
* @param stream - Whether to use streaming endpoint
|
|
56
|
+
*/
|
|
57
|
+
declare function buildGeminiApiUrl(baseUrl: string, model: string, stream: boolean): string;
|
|
58
|
+
/**
|
|
59
|
+
* Normalize Azure OpenAI endpoint
|
|
60
|
+
* Strips trailing /, /openai, /openai/v1 etc.
|
|
61
|
+
*/
|
|
62
|
+
declare function normalizeAzureEndpoint(endpoint: string): string;
|
|
63
|
+
/**
|
|
64
|
+
* Build Azure OpenAI API URL
|
|
65
|
+
* Format: {endpoint}/openai/deployments/{deploymentName}/chat/completions?api-version={version}
|
|
66
|
+
* @param baseUrl - Azure endpoint (e.g., https://my-resource.openai.azure.com)
|
|
67
|
+
* @param model - Deployment name (used as model in Azure)
|
|
68
|
+
* @param apiVersion - API version (e.g., 2024-08-01-preview)
|
|
69
|
+
*/
|
|
70
|
+
declare function buildAzureOpenAIApiUrl(baseUrl: string, model: string, apiVersion: string): string;
|
|
71
|
+
/**
|
|
72
|
+
* Build OpenAI Responses API URL
|
|
73
|
+
* Format: {baseUrl}/v1/responses
|
|
74
|
+
*/
|
|
75
|
+
declare function buildOpenAIResponseApiUrl(baseUrl: string): string;
|
|
76
|
+
|
|
77
|
+
declare const resolveProviderEndpoint: typeof resolveProviderEndpoint$1;
|
|
78
|
+
/**
|
|
79
|
+
* Build API URL based on provider format and options
|
|
80
|
+
* This is the main entry point for URL building
|
|
81
|
+
*/
|
|
82
|
+
declare function buildProviderApiUrl(provider: LLMProvider, options?: {
|
|
83
|
+
model?: string;
|
|
84
|
+
stream?: boolean;
|
|
85
|
+
}): string;
|
|
86
|
+
|
|
87
|
+
export { buildAnthropicApiUrl, buildAzureOpenAIApiUrl, buildGeminiApiUrl, buildGeminiModelActionUrl, buildOpenAIApiUrl, buildOpenAIResponseApiUrl, buildProviderApiUrl, normalizeAzureEndpoint, resolveApiFormat, resolveProviderEndpoint };
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { LLMProvider } from '@omnicross/contracts/llm-config';
|
|
2
|
+
import { A as ApiFormat } from '../types-BScIHmPr.js';
|
|
3
|
+
import { resolveProviderEndpoint as resolveProviderEndpoint$1 } from '@omnicross/contracts/endpoint-resolver';
|
|
4
|
+
import '@omnicross/contracts/message-blocks';
|
|
5
|
+
import '@omnicross/contracts/completion-types';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* API URL Building Utilities
|
|
9
|
+
*
|
|
10
|
+
* Functions for building correct API URLs based on provider format.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Resolve API format from provider configuration
|
|
15
|
+
*
|
|
16
|
+
* Priority:
|
|
17
|
+
* 1. apiFormat (v3 preferred field)
|
|
18
|
+
* 2. chatApiFormat (legacy v3 field)
|
|
19
|
+
* 3. apiType if it's an explicit format (claudecode/anthropic/google)
|
|
20
|
+
* 4. Default to openai
|
|
21
|
+
*
|
|
22
|
+
* Note: This enables implicit routing - the API format determines which
|
|
23
|
+
* transformer is automatically applied without explicit router configuration.
|
|
24
|
+
*/
|
|
25
|
+
declare function resolveApiFormat(provider: LLMProvider): ApiFormat;
|
|
26
|
+
/**
|
|
27
|
+
* Build OpenAI Chat Completions API URL
|
|
28
|
+
* Handles various input formats:
|
|
29
|
+
* - https://api.openai.com → https://api.openai.com/v1/chat/completions
|
|
30
|
+
* - https://api.openai.com/v1/chat/completions → unchanged
|
|
31
|
+
* - https://api.deepseek.com/v1 → https://api.deepseek.com/v1/chat/completions
|
|
32
|
+
* - https://api.z.ai/api/coding/paas/v4 → https://api.z.ai/api/coding/paas/v4/chat/completions
|
|
33
|
+
*/
|
|
34
|
+
declare function buildOpenAIApiUrl(baseUrl: string): string;
|
|
35
|
+
/**
|
|
36
|
+
* Build Anthropic Messages API URL
|
|
37
|
+
* Handles various input formats:
|
|
38
|
+
* - https://api.anthropic.com → https://api.anthropic.com/v1/messages
|
|
39
|
+
* - https://api.anthropic.com/v1/messages → unchanged
|
|
40
|
+
* - https://api.z.ai/api/anthropic → https://api.z.ai/api/anthropic/v1/messages
|
|
41
|
+
* - https://api.z.ai/api/anthropic/v2 → https://api.z.ai/api/anthropic/v2/messages
|
|
42
|
+
*/
|
|
43
|
+
declare function buildAnthropicApiUrl(baseUrl: string): string;
|
|
44
|
+
/**
|
|
45
|
+
* Build a Gemini /v1beta/models/{model}:{action} URL with base-URL normalization.
|
|
46
|
+
* Strips trailing slashes, skips appending /v1beta if the base already has a version path,
|
|
47
|
+
* and returns the URL as-is if it already contains /models/.
|
|
48
|
+
*/
|
|
49
|
+
declare function buildGeminiModelActionUrl(baseUrl: string, model: string, action: string): string;
|
|
50
|
+
/**
|
|
51
|
+
* Build Google Gemini API URL
|
|
52
|
+
* Gemini uses a dynamic URL structure: /v1beta/models/{model}:generateContent or :streamGenerateContent
|
|
53
|
+
* @param baseUrl - Base URL (e.g., https://generativelanguage.googleapis.com)
|
|
54
|
+
* @param model - Model name (e.g., gemini-2.0-flash)
|
|
55
|
+
* @param stream - Whether to use streaming endpoint
|
|
56
|
+
*/
|
|
57
|
+
declare function buildGeminiApiUrl(baseUrl: string, model: string, stream: boolean): string;
|
|
58
|
+
/**
|
|
59
|
+
* Normalize Azure OpenAI endpoint
|
|
60
|
+
* Strips trailing /, /openai, /openai/v1 etc.
|
|
61
|
+
*/
|
|
62
|
+
declare function normalizeAzureEndpoint(endpoint: string): string;
|
|
63
|
+
/**
|
|
64
|
+
* Build Azure OpenAI API URL
|
|
65
|
+
* Format: {endpoint}/openai/deployments/{deploymentName}/chat/completions?api-version={version}
|
|
66
|
+
* @param baseUrl - Azure endpoint (e.g., https://my-resource.openai.azure.com)
|
|
67
|
+
* @param model - Deployment name (used as model in Azure)
|
|
68
|
+
* @param apiVersion - API version (e.g., 2024-08-01-preview)
|
|
69
|
+
*/
|
|
70
|
+
declare function buildAzureOpenAIApiUrl(baseUrl: string, model: string, apiVersion: string): string;
|
|
71
|
+
/**
|
|
72
|
+
* Build OpenAI Responses API URL
|
|
73
|
+
* Format: {baseUrl}/v1/responses
|
|
74
|
+
*/
|
|
75
|
+
declare function buildOpenAIResponseApiUrl(baseUrl: string): string;
|
|
76
|
+
|
|
77
|
+
declare const resolveProviderEndpoint: typeof resolveProviderEndpoint$1;
|
|
78
|
+
/**
|
|
79
|
+
* Build API URL based on provider format and options
|
|
80
|
+
* This is the main entry point for URL building
|
|
81
|
+
*/
|
|
82
|
+
declare function buildProviderApiUrl(provider: LLMProvider, options?: {
|
|
83
|
+
model?: string;
|
|
84
|
+
stream?: boolean;
|
|
85
|
+
}): string;
|
|
86
|
+
|
|
87
|
+
export { buildAnthropicApiUrl, buildAzureOpenAIApiUrl, buildGeminiApiUrl, buildGeminiModelActionUrl, buildOpenAIApiUrl, buildOpenAIResponseApiUrl, buildProviderApiUrl, normalizeAzureEndpoint, resolveApiFormat, resolveProviderEndpoint };
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
// src/completion/url-builder.ts
|
|
2
|
+
import { resolveProviderEndpoint as resolveProviderEndpointShared } from "@omnicross/contracts/endpoint-resolver";
|
|
3
|
+
function resolveApiFormat(provider) {
|
|
4
|
+
if (provider.apiFormat) {
|
|
5
|
+
return provider.apiFormat;
|
|
6
|
+
}
|
|
7
|
+
if (provider.chatApiFormat) {
|
|
8
|
+
return provider.chatApiFormat;
|
|
9
|
+
}
|
|
10
|
+
if (provider.apiType === "claudecode" || provider.apiType === "anthropic") {
|
|
11
|
+
return "anthropic";
|
|
12
|
+
}
|
|
13
|
+
if (provider.apiType === "google") {
|
|
14
|
+
return "google";
|
|
15
|
+
}
|
|
16
|
+
return "openai";
|
|
17
|
+
}
|
|
18
|
+
function buildOpenAIApiUrl(baseUrl) {
|
|
19
|
+
const url = baseUrl.replace(/\/+$/, "");
|
|
20
|
+
if (url.endsWith("/chat/completions")) {
|
|
21
|
+
return url;
|
|
22
|
+
}
|
|
23
|
+
if (/\/v\d+$/.test(url)) {
|
|
24
|
+
return url + "/chat/completions";
|
|
25
|
+
}
|
|
26
|
+
if (url.includes("/chat/completions")) {
|
|
27
|
+
return url;
|
|
28
|
+
}
|
|
29
|
+
return url + "/v1/chat/completions";
|
|
30
|
+
}
|
|
31
|
+
function buildAnthropicApiUrl(baseUrl) {
|
|
32
|
+
const url = baseUrl.replace(/\/+$/, "");
|
|
33
|
+
if (url.endsWith("/messages")) {
|
|
34
|
+
return url;
|
|
35
|
+
}
|
|
36
|
+
if (url.includes("/messages")) {
|
|
37
|
+
return url;
|
|
38
|
+
}
|
|
39
|
+
if (/\/v\d+$/.test(url)) {
|
|
40
|
+
return url + "/messages";
|
|
41
|
+
}
|
|
42
|
+
return url + "/v1/messages";
|
|
43
|
+
}
|
|
44
|
+
function buildGeminiModelActionUrl(baseUrl, model, action) {
|
|
45
|
+
let url = baseUrl.replace(/\/+$/, "");
|
|
46
|
+
if (url.includes("/models/")) {
|
|
47
|
+
return url;
|
|
48
|
+
}
|
|
49
|
+
if (!/\/v\d+(?:beta)?(?:$|\/)/.test(url)) {
|
|
50
|
+
url += "/v1beta";
|
|
51
|
+
}
|
|
52
|
+
return `${url}/models/${model}:${action}`;
|
|
53
|
+
}
|
|
54
|
+
function buildGeminiApiUrl(baseUrl, model, stream) {
|
|
55
|
+
const action = stream ? "streamGenerateContent?alt=sse" : "generateContent";
|
|
56
|
+
return buildGeminiModelActionUrl(baseUrl, model, action);
|
|
57
|
+
}
|
|
58
|
+
function normalizeAzureEndpoint(endpoint) {
|
|
59
|
+
return endpoint.replace(/\/+$/, "").replace(/\/openai(\/v\d+)?$/, "");
|
|
60
|
+
}
|
|
61
|
+
function buildAzureOpenAIApiUrl(baseUrl, model, apiVersion) {
|
|
62
|
+
const endpoint = normalizeAzureEndpoint(baseUrl);
|
|
63
|
+
return `${endpoint}/openai/deployments/${model}/chat/completions?api-version=${apiVersion}`;
|
|
64
|
+
}
|
|
65
|
+
function buildOpenAIResponseApiUrl(baseUrl) {
|
|
66
|
+
const url = baseUrl.replace(/\/+$/, "");
|
|
67
|
+
if (url.endsWith("/responses")) {
|
|
68
|
+
return url;
|
|
69
|
+
}
|
|
70
|
+
if (/\/v\d+$/.test(url)) {
|
|
71
|
+
return url + "/responses";
|
|
72
|
+
}
|
|
73
|
+
return url + "/v1/responses";
|
|
74
|
+
}
|
|
75
|
+
var resolveProviderEndpoint = resolveProviderEndpointShared;
|
|
76
|
+
function buildProviderApiUrl(provider, options = {}) {
|
|
77
|
+
const format = resolveApiFormat(provider);
|
|
78
|
+
const { baseUrl } = resolveProviderEndpoint(provider);
|
|
79
|
+
switch (format) {
|
|
80
|
+
case "anthropic":
|
|
81
|
+
return buildAnthropicApiUrl(baseUrl);
|
|
82
|
+
case "google":
|
|
83
|
+
return buildGeminiApiUrl(baseUrl, options.model || "", options.stream || false);
|
|
84
|
+
case "azure-openai":
|
|
85
|
+
return buildAzureOpenAIApiUrl(baseUrl, options.model || "", provider.apiVersion || "2024-08-01-preview");
|
|
86
|
+
case "openai-response":
|
|
87
|
+
return buildOpenAIResponseApiUrl(baseUrl);
|
|
88
|
+
case "openai":
|
|
89
|
+
default:
|
|
90
|
+
return buildOpenAIApiUrl(baseUrl);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
export {
|
|
94
|
+
buildAnthropicApiUrl,
|
|
95
|
+
buildAzureOpenAIApiUrl,
|
|
96
|
+
buildGeminiApiUrl,
|
|
97
|
+
buildGeminiModelActionUrl,
|
|
98
|
+
buildOpenAIApiUrl,
|
|
99
|
+
buildOpenAIResponseApiUrl,
|
|
100
|
+
buildProviderApiUrl,
|
|
101
|
+
normalizeAzureEndpoint,
|
|
102
|
+
resolveApiFormat,
|
|
103
|
+
resolveProviderEndpoint
|
|
104
|
+
};
|
package/dist/completion.d.cts
CHANGED
|
@@ -1,17 +1,158 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { A as ApiFormat, C as CompletionOptions, a as CompletionResult, N as NATIVE_SEARCH_TOOL_NAMES, b as NativeSearchAugmentation, c as NativeSearchDetectionResult, d as NativeSearchProvider, e as NativeSearchUserConfig, S as StreamCallbacks } from './types-BScIHmPr.cjs';
|
|
2
|
+
export { C as CompletionService, V as VisionFallbackProvider } from './CompletionService-DtOF_War.cjs';
|
|
3
|
+
export { buildAnthropicApiUrl, buildAzureOpenAIApiUrl, buildGeminiApiUrl, buildOpenAIApiUrl, buildOpenAIResponseApiUrl, buildProviderApiUrl, normalizeAzureEndpoint, resolveApiFormat, resolveProviderEndpoint } from './completion/url-builder.cjs';
|
|
4
|
+
import { LLMProvider, OpenRouterProviderRouting } from '@omnicross/contracts/llm-config';
|
|
5
|
+
import { SimpleChatMessage, AnthropicMessage, OpenAIMessage } from '@omnicross/contracts/completion-types';
|
|
6
|
+
export { B as BuiltinToolExecutor, g as getBuiltinSearchTools } from './BuiltinToolExecutor-CS2WpXhM.cjs';
|
|
7
|
+
export { applyAugmentation, buildNativeSearchAugmentation, detectNativeSearch } from './completion/NativeSearchInjector.cjs';
|
|
2
8
|
import '@omnicross/contracts/message-blocks';
|
|
3
|
-
import '@omnicross/contracts/completion-types';
|
|
4
|
-
import '@omnicross/contracts/llm-config';
|
|
5
9
|
import './usage-event-sink-BX7FE1NL.cjs';
|
|
6
10
|
import './ApiKeyPoolService-BmMkau07.cjs';
|
|
7
|
-
import './
|
|
11
|
+
import './ports/provider-config-source.cjs';
|
|
12
|
+
import './transformer/types.cjs';
|
|
13
|
+
import './transformer/TransformerService.cjs';
|
|
14
|
+
import './provider-proxy/types.cjs';
|
|
8
15
|
import 'node:http';
|
|
9
16
|
import '@omnicross/contracts/subscription-types';
|
|
10
17
|
import '@omnicross/contracts/usage-types';
|
|
11
|
-
import './
|
|
18
|
+
import './pipeline/AuthSource.cjs';
|
|
19
|
+
import './pipeline/SubscriptionAuthSource.cjs';
|
|
12
20
|
import './pipeline/SubscriptionAuthStrategy.cjs';
|
|
13
|
-
import './
|
|
14
|
-
import './transformer/TransformerService.cjs';
|
|
21
|
+
import './ports/web-search-backend.cjs';
|
|
15
22
|
import '@omnicross/contracts/websearch-types';
|
|
16
23
|
import '@omnicross/contracts/mcp-types';
|
|
17
24
|
import '@omnicross/contracts/endpoint-resolver';
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* StreamEventBuffer — per-streamId event queue for streamed completion delivery.
|
|
28
|
+
*
|
|
29
|
+
* Closes the subscribe-vs-emit race between a producer that starts the LLM call
|
|
30
|
+
* asynchronously and a consumer that only attaches its listener after awaiting a
|
|
31
|
+
* reply. Events emitted before `attach(streamId)` is called are queued and
|
|
32
|
+
* replayed in order on attach.
|
|
33
|
+
*/
|
|
34
|
+
/**
|
|
35
|
+
* Minimal structural sender — the subset of an Electron `WebContents` (or any
|
|
36
|
+
* IPC channel) this buffer actually uses. Kept LOCAL so core has zero electron
|
|
37
|
+
* dependency; the host passes any object satisfying this shape.
|
|
38
|
+
*/
|
|
39
|
+
interface StreamSender {
|
|
40
|
+
isDestroyed(): boolean;
|
|
41
|
+
send(channel: string, payload: StreamEvent): void;
|
|
42
|
+
}
|
|
43
|
+
type StreamEventType = 'start' | 'delta' | 'reasoning' | 'tool_call' | 'tool_result' | 'tool_use' | 'block' | 'search_start' | 'search_result' | 'done' | 'error' | 'abort';
|
|
44
|
+
interface StreamEvent {
|
|
45
|
+
type: StreamEventType;
|
|
46
|
+
[key: string]: unknown;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Register a new stream. Called by the engine / handler immediately after the
|
|
50
|
+
* `streamId` is created, before any `emit`. Idempotent re-registration replaces
|
|
51
|
+
* the sender (covers the rare case of the engine retrying with the same id).
|
|
52
|
+
*/
|
|
53
|
+
declare function register(streamId: string, sender: StreamSender): void;
|
|
54
|
+
/**
|
|
55
|
+
* Emit an event for `streamId`. Forwards directly if the client has attached;
|
|
56
|
+
* otherwise queues until `attach` is called. Bounded at QUEUE_CAP — overflow
|
|
57
|
+
* evicts the oldest non-terminal event.
|
|
58
|
+
*/
|
|
59
|
+
declare function emit(streamId: string, event: StreamEvent): void;
|
|
60
|
+
/**
|
|
61
|
+
* The client announced readiness via the `completion:stream:subscribe` IPC. Drains
|
|
62
|
+
* the queue synchronously to the bound sender, then flips to direct-forward mode.
|
|
63
|
+
* Returns the number of events drained for diagnostic purposes.
|
|
64
|
+
*/
|
|
65
|
+
declare function attach(streamId: string): {
|
|
66
|
+
ok: boolean;
|
|
67
|
+
drained: number;
|
|
68
|
+
};
|
|
69
|
+
/**
|
|
70
|
+
* Mark a stream finished. If the client has already attached, release
|
|
71
|
+
* synchronously. Otherwise defer one tick so a late `subscribe` arriving on the
|
|
72
|
+
* heels of the `done`/`error` event still drains the queue before cleanup.
|
|
73
|
+
*/
|
|
74
|
+
declare function release(streamId: string): void;
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Request Header Building Utilities
|
|
78
|
+
*
|
|
79
|
+
* Functions for building correct request headers based on provider format.
|
|
80
|
+
*/
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Get request headers based on provider format
|
|
84
|
+
*/
|
|
85
|
+
declare function getProviderHeaders(provider: LLMProvider, apiKey: string): Record<string, string>;
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Message Format Conversion Utilities
|
|
89
|
+
*
|
|
90
|
+
* Functions for converting SimpleChatMessage to different API formats.
|
|
91
|
+
*/
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Convert SimpleChatMessage to OpenAI-compatible format (covers OpenAI, OpenRouter,
|
|
95
|
+
* and other OpenAI-compatible providers — DO NOT call from Anthropic / Gemini paths,
|
|
96
|
+
* which have their own converters above).
|
|
97
|
+
*
|
|
98
|
+
* - Text only: { role, content: string }
|
|
99
|
+
* - With media: { role, content: [{ type: "text" | "image_url" | "input_audio" | "video_url", ... }] }
|
|
100
|
+
*
|
|
101
|
+
* Audio is emitted as `input_audio` with base64 + format (the standard OpenAI / OpenRouter
|
|
102
|
+
* shape). Video is emitted as `video_url`: HTTPS URLs pass through; local data is sent as a
|
|
103
|
+
* `data:<mime>;base64,...` URL with a 25 MB cap before the request is even built.
|
|
104
|
+
*/
|
|
105
|
+
declare function convertMessageToOpenAI(msg: SimpleChatMessage): OpenAIMessage;
|
|
106
|
+
/**
|
|
107
|
+
* Convert SimpleChatMessage to Anthropic format (with vision support)
|
|
108
|
+
* Anthropic format:
|
|
109
|
+
* - Text only: { role, content: string }
|
|
110
|
+
* - With images: { role, content: [{ type: "text", text: "..." }, { type: "image", source: { type: "base64", media_type: "...", data: "..." } }] }
|
|
111
|
+
*/
|
|
112
|
+
declare function convertMessageToAnthropic(msg: SimpleChatMessage): AnthropicMessage;
|
|
113
|
+
/**
|
|
114
|
+
* Minimal Gemini part shape for the simple-chat DIRECT path (text + inline
|
|
115
|
+
* media only), serialized with the official REST JSON casing
|
|
116
|
+
* (`inlineData` / `mimeType`).
|
|
117
|
+
*
|
|
118
|
+
* NOT the same wire model as the transformer pipeline's full `GeminiPart`
|
|
119
|
+
* union in `transformer/transformers/utils/gemini.util.ts` (function calls /
|
|
120
|
+
* file data, snake_case alias keys). The two paths intentionally serialize
|
|
121
|
+
* differently — do not merge them blindly.
|
|
122
|
+
*/
|
|
123
|
+
interface SimpleChatGeminiPart {
|
|
124
|
+
text?: string;
|
|
125
|
+
inlineData?: {
|
|
126
|
+
mimeType: string;
|
|
127
|
+
data: string;
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
/** Gemini message for the simple-chat direct path. */
|
|
131
|
+
interface SimpleChatGeminiMessage {
|
|
132
|
+
role: string;
|
|
133
|
+
parts: SimpleChatGeminiPart[];
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Convert SimpleChatMessage to Gemini format (with vision support)
|
|
137
|
+
* Gemini format:
|
|
138
|
+
* - { role: "user"|"model", parts: [{ text: "..." }, { inlineData: { mimeType: "...", data: "..." } }] }
|
|
139
|
+
*/
|
|
140
|
+
declare function convertMessageToGemini(msg: SimpleChatMessage): SimpleChatGeminiMessage;
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* OpenRouter Provider Utilities
|
|
144
|
+
*
|
|
145
|
+
* Functions for handling OpenRouter-specific configuration and routing.
|
|
146
|
+
*/
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* Get OpenRouter provider routing config from model configuration
|
|
150
|
+
* Returns the provider routing config if the provider is OpenRouter and model has config
|
|
151
|
+
*/
|
|
152
|
+
declare function getOpenRouterProviderConfig(provider: LLMProvider, modelId: string): OpenRouterProviderRouting | undefined;
|
|
153
|
+
/**
|
|
154
|
+
* Add OpenRouter provider routing to request body if applicable
|
|
155
|
+
*/
|
|
156
|
+
declare function addOpenRouterProviderToRequest(requestBody: Record<string, unknown>, provider: LLMProvider, modelId: string): Record<string, unknown>;
|
|
157
|
+
|
|
158
|
+
export { type SimpleChatGeminiMessage, type SimpleChatGeminiPart, type StreamEvent, type StreamEventType, type StreamSender, addOpenRouterProviderToRequest, attach as attachStreamEventBuffer, convertMessageToAnthropic, convertMessageToGemini, convertMessageToOpenAI, emit as emitStreamEvent, getOpenRouterProviderConfig, getProviderHeaders, register as registerStreamEventBuffer, release as releaseStreamEventBuffer };
|