@omnicross/core 0.1.8 → 0.1.9
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/auth/GeminiCodeAssistProjectResolver.cjs +5 -3
- package/dist/auth/GeminiCodeAssistProjectResolver.js +4 -2
- package/dist/{chunk-N5T4M4GU.js → chunk-2UTGX6FM.js} +2 -2
- package/dist/{chunk-32O35CIF.js → chunk-45FHEOKW.js} +22 -7
- package/dist/{chunk-LVUCAWMK.js → chunk-55FMGZ3L.js} +13 -5
- package/dist/{chunk-OF3BECU2.cjs → chunk-56QD3YW6.cjs} +18 -5
- package/dist/{chunk-V4TXMEJS.cjs → chunk-5LNYGCIW.cjs} +15 -7
- package/dist/chunk-77USGNRW.cjs +37 -0
- package/dist/chunk-AOFWNWLT.cjs +203 -0
- package/dist/{chunk-LB6EBS6Y.js → chunk-CCVRRJOX.js} +17 -4
- package/dist/{chunk-OVQBNVSV.cjs → chunk-CMVXX7ON.cjs} +42 -27
- package/dist/{chunk-QYC54PMG.js → chunk-CQIJCPMF.js} +177 -77
- package/dist/{chunk-PEGTIPB3.js → chunk-HKB656B4.js} +37 -43
- package/dist/chunk-N2EIM2XJ.js +203 -0
- package/dist/{chunk-MYYR3HZL.js → chunk-NGYOO5TO.js} +5 -5
- package/dist/{chunk-OKMJLEXX.cjs → chunk-OC6DOOFX.cjs} +5 -5
- package/dist/{chunk-2Z4XM3H5.cjs → chunk-P7EM6BND.cjs} +10 -10
- package/dist/{chunk-KBM2W6UY.cjs → chunk-RICPANBY.cjs} +41 -24
- package/dist/{chunk-TOVPMMHM.js → chunk-S3DYFEBE.js} +37 -20
- package/dist/chunk-WYVGULTQ.js +37 -0
- package/dist/{chunk-26K6T2YS.cjs → chunk-XELFM7KL.cjs} +301 -201
- package/dist/{chunk-OXHNSZ53.cjs → chunk-ZQQUD66M.cjs} +54 -60
- package/dist/completion/CompletionService.cjs +12 -10
- package/dist/completion/CompletionService.js +11 -9
- package/dist/completion.cjs +12 -10
- package/dist/completion.js +11 -9
- package/dist/index.cjs +12 -10
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +11 -9
- package/dist/outbound-api/routeResolver.d.cts +1 -1
- package/dist/outbound-api/routeResolver.d.ts +1 -1
- package/dist/outbound-api/types.d.cts +1 -1
- package/dist/outbound-api/types.d.ts +1 -1
- package/dist/outbound-api.cjs +12 -10
- package/dist/outbound-api.d.cts +1 -1
- package/dist/outbound-api.d.ts +1 -1
- package/dist/outbound-api.js +11 -9
- package/dist/pipeline/AccountAllowanceScheduling.d.cts +1 -1
- package/dist/pipeline/AccountAllowanceScheduling.d.ts +1 -1
- package/dist/pipeline/executeProviderCall.d.cts +2 -0
- package/dist/pipeline/executeProviderCall.d.ts +2 -0
- package/dist/pipeline/resolveProviderChain.d.cts +1 -0
- package/dist/pipeline/resolveProviderChain.d.ts +1 -0
- package/dist/pipeline/resolveSubscriptionChain.d.cts +2 -0
- package/dist/pipeline/resolveSubscriptionChain.d.ts +2 -0
- package/dist/ports/provider-config-source.d.cts +1 -0
- package/dist/ports/provider-config-source.d.ts +1 -0
- package/dist/ports.d.cts +1 -1
- package/dist/ports.d.ts +1 -1
- package/dist/provider-proxy/ProviderProxy.cjs +12 -10
- package/dist/provider-proxy/ProviderProxy.js +11 -9
- package/dist/provider-proxy/ingress/providerProxyShared.cjs +12 -10
- package/dist/provider-proxy/ingress/providerProxyShared.js +11 -9
- package/dist/provider-proxy.cjs +12 -10
- package/dist/provider-proxy.js +11 -9
- package/dist/transformer/TransformerChainExecutor.d.cts +2 -0
- package/dist/transformer/TransformerChainExecutor.d.ts +2 -0
- package/dist/transformer/TransformerService.d.cts +2 -0
- package/dist/transformer/TransformerService.d.ts +2 -0
- package/dist/transformer/transformers/AnthropicTransformer.cjs +4 -2
- package/dist/transformer/transformers/AnthropicTransformer.d.cts +7 -2
- package/dist/transformer/transformers/AnthropicTransformer.d.ts +7 -2
- package/dist/transformer/transformers/AnthropicTransformer.js +3 -1
- package/dist/transformer/transformers/GeminiCodeAssistTransformer.cjs +5 -3
- package/dist/transformer/transformers/GeminiCodeAssistTransformer.d.cts +2 -0
- package/dist/transformer/transformers/GeminiCodeAssistTransformer.d.ts +2 -0
- package/dist/transformer/transformers/GeminiCodeAssistTransformer.js +4 -2
- package/dist/transformer/transformers/GeminiTransformer.cjs +5 -3
- package/dist/transformer/transformers/GeminiTransformer.d.cts +4 -2
- package/dist/transformer/transformers/GeminiTransformer.d.ts +4 -2
- package/dist/transformer/transformers/GeminiTransformer.js +4 -2
- package/dist/transformer/transformers/OpenAIResponseTransformer.cjs +3 -2
- package/dist/transformer/transformers/OpenAIResponseTransformer.d.cts +4 -2
- package/dist/transformer/transformers/OpenAIResponseTransformer.d.ts +4 -2
- package/dist/transformer/transformers/OpenAIResponseTransformer.js +2 -1
- package/dist/transformer/transformers/OpenAITransformer.cjs +3 -2
- package/dist/transformer/transformers/OpenAITransformer.d.cts +3 -1
- package/dist/transformer/transformers/OpenAITransformer.d.ts +3 -1
- package/dist/transformer/transformers/OpenAITransformer.js +2 -1
- package/dist/transformer/transformers.cjs +10 -8
- package/dist/transformer/transformers.d.cts +2 -0
- package/dist/transformer/transformers.d.ts +2 -0
- package/dist/transformer/transformers.js +9 -7
- package/dist/transformer/types.d.cts +16 -5
- package/dist/transformer/types.d.ts +16 -5
- package/dist/transformer.cjs +28 -9
- package/dist/transformer.d.cts +76 -1
- package/dist/transformer.d.ts +76 -1
- package/dist/transformer.js +28 -9
- package/package.json +1 -1
- /package/dist/{chunk-FZ46M34D.cjs → chunk-QVOB2DNX.cjs} +0 -0
- /package/dist/{chunk-46RLHI7D.js → chunk-WTQMX2Q6.js} +0 -0
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } var _class;
|
|
2
2
|
|
|
3
3
|
|
|
4
|
-
var
|
|
5
|
-
require('../chunk-
|
|
4
|
+
var _chunkOC6DOOFXcjs = require('../chunk-OC6DOOFX.cjs');
|
|
5
|
+
require('../chunk-RICPANBY.cjs');
|
|
6
|
+
require('../chunk-77USGNRW.cjs');
|
|
7
|
+
require('../chunk-AOFWNWLT.cjs');
|
|
6
8
|
|
|
7
9
|
|
|
8
10
|
var _chunkRJUONLUQcjs = require('../chunk-RJUONLUQ.cjs');
|
|
@@ -62,7 +64,7 @@ var GeminiCodeAssistProjectResolver = (_class = class {
|
|
|
62
64
|
return run;
|
|
63
65
|
}
|
|
64
66
|
codeAssistUrl(method) {
|
|
65
|
-
return `${
|
|
67
|
+
return `${_chunkOC6DOOFXcjs.resolveCodeAssistEndpoint.call(void 0, )}/${_chunkOC6DOOFXcjs.resolveCodeAssistApiVersion.call(void 0, )}:${method}`;
|
|
66
68
|
}
|
|
67
69
|
/** Seed project id from env; reject a purely-numeric value (project NUMBER). */
|
|
68
70
|
seedProjectId() {
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import {
|
|
2
2
|
resolveCodeAssistApiVersion,
|
|
3
3
|
resolveCodeAssistEndpoint
|
|
4
|
-
} from "../chunk-
|
|
5
|
-
import "../chunk-
|
|
4
|
+
} from "../chunk-2UTGX6FM.js";
|
|
5
|
+
import "../chunk-S3DYFEBE.js";
|
|
6
|
+
import "../chunk-WYVGULTQ.js";
|
|
7
|
+
import "../chunk-N2EIM2XJ.js";
|
|
6
8
|
import {
|
|
7
9
|
fetchUpstream
|
|
8
10
|
} from "../chunk-RJ5ZGNI3.js";
|
|
@@ -3,7 +3,7 @@ import {
|
|
|
3
3
|
transformRequestOut,
|
|
4
4
|
transformResponseIn,
|
|
5
5
|
transformResponseOut
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-S3DYFEBE.js";
|
|
7
7
|
|
|
8
8
|
// src/transformer/transformers/GeminiCodeAssistTransformer.ts
|
|
9
9
|
var DEFAULT_CODE_ASSIST_ENDPOINT = "https://cloudcode-pa.googleapis.com";
|
|
@@ -117,7 +117,7 @@ var GeminiCodeAssistTransformer = class {
|
|
|
117
117
|
* openaiResponsesIngress). `undefined` is the valid fresh free-tier value.
|
|
118
118
|
*/
|
|
119
119
|
async transformRequestIn(request, provider, _context) {
|
|
120
|
-
const inner = buildRequestBody(request);
|
|
120
|
+
const inner = buildRequestBody(request, provider);
|
|
121
121
|
const envelope = {
|
|
122
122
|
model: request.model,
|
|
123
123
|
project: provider.geminiProject,
|
|
@@ -2,6 +2,11 @@ import {
|
|
|
2
2
|
chatUsageToResponsesUsage,
|
|
3
3
|
responsesUsageToChatUsage
|
|
4
4
|
} from "./chunk-FU7EAR73.js";
|
|
5
|
+
import {
|
|
6
|
+
extractReasoningIntent,
|
|
7
|
+
normalizeThinkLevel,
|
|
8
|
+
resolveReasoningPlan
|
|
9
|
+
} from "./chunk-N2EIM2XJ.js";
|
|
5
10
|
|
|
6
11
|
// src/transformer/transformers/OpenAIResponseTransformer.ts
|
|
7
12
|
var OpenAIResponseTransformer = class {
|
|
@@ -26,7 +31,7 @@ var OpenAIResponseTransformer = class {
|
|
|
26
31
|
/**
|
|
27
32
|
* Transform unified request → Response API format
|
|
28
33
|
*/
|
|
29
|
-
async transformRequestIn(request, provider,
|
|
34
|
+
async transformRequestIn(request, provider, context) {
|
|
30
35
|
const input = [];
|
|
31
36
|
for (const msg of request.messages) {
|
|
32
37
|
if (msg.role === "system") {
|
|
@@ -82,8 +87,16 @@ var OpenAIResponseTransformer = class {
|
|
|
82
87
|
// public provider ever needs it honored, gate that on an opt-out flag.
|
|
83
88
|
...request.temperature !== void 0 ? { temperature: request.temperature } : {}
|
|
84
89
|
};
|
|
85
|
-
|
|
86
|
-
|
|
90
|
+
const reasoningPlan = resolveReasoningPlan({
|
|
91
|
+
intent: extractReasoningIntent(request),
|
|
92
|
+
model: request.model,
|
|
93
|
+
provider,
|
|
94
|
+
target: "openai-responses",
|
|
95
|
+
requestMaxTokens: request.max_tokens,
|
|
96
|
+
preserveNativeEffort: context.reasoningSourceFormat === this.name
|
|
97
|
+
});
|
|
98
|
+
if (reasoningPlan?.kind === "level" && reasoningPlan.enabled) {
|
|
99
|
+
body.reasoning = { effort: reasoningPlan.effort, summary: "auto" };
|
|
87
100
|
}
|
|
88
101
|
if (request.tools?.length) {
|
|
89
102
|
body.tools = request.tools.map((tool) => ({
|
|
@@ -106,7 +119,7 @@ var OpenAIResponseTransformer = class {
|
|
|
106
119
|
/**
|
|
107
120
|
* Transform Response API request → unified format
|
|
108
121
|
*/
|
|
109
|
-
async transformRequestOut(request,
|
|
122
|
+
async transformRequestOut(request, context) {
|
|
110
123
|
const req = request;
|
|
111
124
|
const messages = [];
|
|
112
125
|
let codexTools = null;
|
|
@@ -192,10 +205,12 @@ var OpenAIResponseTransformer = class {
|
|
|
192
205
|
temperature: req.temperature,
|
|
193
206
|
stream: req.stream
|
|
194
207
|
};
|
|
195
|
-
|
|
208
|
+
const effort = normalizeThinkLevel(req.reasoning?.effort);
|
|
209
|
+
if (effort) {
|
|
210
|
+
context.reasoningSourceFormat = this.name;
|
|
196
211
|
result.reasoning = {
|
|
197
|
-
effort
|
|
198
|
-
enabled:
|
|
212
|
+
effort,
|
|
213
|
+
enabled: effort !== "none"
|
|
199
214
|
};
|
|
200
215
|
}
|
|
201
216
|
const tools = [];
|
|
@@ -3,7 +3,7 @@ import {
|
|
|
3
3
|
transformRequestOut,
|
|
4
4
|
transformResponseIn,
|
|
5
5
|
transformResponseOut
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-S3DYFEBE.js";
|
|
7
7
|
|
|
8
8
|
// src/transformer/transformers/GeminiTransformer.ts
|
|
9
9
|
var GeminiTransformer = class {
|
|
@@ -43,8 +43,12 @@ var GeminiTransformer = class {
|
|
|
43
43
|
* Transform request from unified format to Gemini format
|
|
44
44
|
* Also builds the correct URL for the Gemini API
|
|
45
45
|
*/
|
|
46
|
-
async transformRequestIn(request, provider,
|
|
47
|
-
const body = buildRequestBody(
|
|
46
|
+
async transformRequestIn(request, provider, context) {
|
|
47
|
+
const body = buildRequestBody(
|
|
48
|
+
request,
|
|
49
|
+
provider,
|
|
50
|
+
context.reasoningSourceFormat === this.name
|
|
51
|
+
);
|
|
48
52
|
const action = request.stream ? "streamGenerateContent?alt=sse" : "generateContent";
|
|
49
53
|
const url = new URL(`./${request.model}:${action}`, provider.baseUrl);
|
|
50
54
|
const headers = {};
|
|
@@ -64,8 +68,12 @@ var GeminiTransformer = class {
|
|
|
64
68
|
* Transform incoming request to unified format
|
|
65
69
|
* (For requests coming into the Gemini endpoint)
|
|
66
70
|
*/
|
|
67
|
-
async transformRequestOut(request,
|
|
68
|
-
|
|
71
|
+
async transformRequestOut(request, context) {
|
|
72
|
+
const unifiedRequest = transformRequestOut(request);
|
|
73
|
+
if (unifiedRequest.reasoning?.effort) {
|
|
74
|
+
context.reasoningSourceFormat = this.name;
|
|
75
|
+
}
|
|
76
|
+
return unifiedRequest;
|
|
69
77
|
}
|
|
70
78
|
/**
|
|
71
79
|
* Transform Gemini response to OpenAI-compatible format
|
|
@@ -1,4 +1,9 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } var _class
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } var _class;
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
var _chunkAOFWNWLTcjs = require('./chunk-AOFWNWLT.cjs');
|
|
5
|
+
|
|
6
|
+
// src/transformer/transformers/OpenAITransformer.ts
|
|
2
7
|
var FOREIGN_MESSAGE_KEYS = ["cache_control", "thinking"];
|
|
3
8
|
var FOREIGN_BODY_KEYS = ["meta", "reasoning", "thinking"];
|
|
4
9
|
function normalizeContent(content) {
|
|
@@ -24,7 +29,7 @@ var OpenAITransformer = (_class = class {constructor() { _class.prototype.__init
|
|
|
24
29
|
/**
|
|
25
30
|
* Unified → OpenAI Chat Completions.
|
|
26
31
|
*/
|
|
27
|
-
async transformRequestIn(request,
|
|
32
|
+
async transformRequestIn(request, provider, _context) {
|
|
28
33
|
const source = request;
|
|
29
34
|
const out = {};
|
|
30
35
|
for (const key of Object.keys(source)) {
|
|
@@ -49,9 +54,17 @@ var OpenAITransformer = (_class = class {constructor() { _class.prototype.__init
|
|
|
49
54
|
return encoded;
|
|
50
55
|
});
|
|
51
56
|
}
|
|
52
|
-
const
|
|
53
|
-
|
|
54
|
-
|
|
57
|
+
const reasoningPlan = request.reasoning ? _chunkAOFWNWLTcjs.resolveReasoningPlan.call(void 0, {
|
|
58
|
+
intent: _chunkAOFWNWLTcjs.extractReasoningIntent.call(void 0, request),
|
|
59
|
+
model: request.model,
|
|
60
|
+
provider,
|
|
61
|
+
target: "openai-chat",
|
|
62
|
+
requestMaxTokens: request.max_tokens
|
|
63
|
+
}) : void 0;
|
|
64
|
+
if (_optionalChain([reasoningPlan, 'optionalAccess', _4 => _4.kind]) === "level" && reasoningPlan.enabled) {
|
|
65
|
+
out.reasoning_effort = reasoningPlan.effort;
|
|
66
|
+
} else if (request.reasoning) {
|
|
67
|
+
delete out.reasoning_effort;
|
|
55
68
|
}
|
|
56
69
|
return out;
|
|
57
70
|
}
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
|
|
4
4
|
|
|
5
5
|
|
|
6
|
-
var
|
|
6
|
+
var _chunkRICPANBYcjs = require('./chunk-RICPANBY.cjs');
|
|
7
7
|
|
|
8
8
|
// src/transformer/transformers/GeminiTransformer.ts
|
|
9
9
|
var GeminiTransformer = (_class = class {
|
|
@@ -43,8 +43,12 @@ var GeminiTransformer = (_class = class {
|
|
|
43
43
|
* Transform request from unified format to Gemini format
|
|
44
44
|
* Also builds the correct URL for the Gemini API
|
|
45
45
|
*/
|
|
46
|
-
async transformRequestIn(request, provider,
|
|
47
|
-
const body =
|
|
46
|
+
async transformRequestIn(request, provider, context) {
|
|
47
|
+
const body = _chunkRICPANBYcjs.buildRequestBody.call(void 0,
|
|
48
|
+
request,
|
|
49
|
+
provider,
|
|
50
|
+
context.reasoningSourceFormat === this.name
|
|
51
|
+
);
|
|
48
52
|
const action = request.stream ? "streamGenerateContent?alt=sse" : "generateContent";
|
|
49
53
|
const url = new URL(`./${request.model}:${action}`, provider.baseUrl);
|
|
50
54
|
const headers = {};
|
|
@@ -64,21 +68,25 @@ var GeminiTransformer = (_class = class {
|
|
|
64
68
|
* Transform incoming request to unified format
|
|
65
69
|
* (For requests coming into the Gemini endpoint)
|
|
66
70
|
*/
|
|
67
|
-
async transformRequestOut(request,
|
|
68
|
-
|
|
71
|
+
async transformRequestOut(request, context) {
|
|
72
|
+
const unifiedRequest = _chunkRICPANBYcjs.transformRequestOut.call(void 0, request);
|
|
73
|
+
if (_optionalChain([unifiedRequest, 'access', _2 => _2.reasoning, 'optionalAccess', _3 => _3.effort])) {
|
|
74
|
+
context.reasoningSourceFormat = this.name;
|
|
75
|
+
}
|
|
76
|
+
return unifiedRequest;
|
|
69
77
|
}
|
|
70
78
|
/**
|
|
71
79
|
* Transform Gemini response to OpenAI-compatible format
|
|
72
80
|
*/
|
|
73
81
|
async transformResponseOut(response, _context) {
|
|
74
|
-
return
|
|
82
|
+
return _chunkRICPANBYcjs.transformResponseOut.call(void 0, response, this.name, this.logger);
|
|
75
83
|
}
|
|
76
84
|
/**
|
|
77
85
|
* Transform OpenAI-compatible response back to Gemini format
|
|
78
86
|
* (For endpoint mode — returning Gemini-format responses to the client)
|
|
79
87
|
*/
|
|
80
88
|
async transformResponseIn(response, _context) {
|
|
81
|
-
return
|
|
89
|
+
return _chunkRICPANBYcjs.transformResponseIn.call(void 0, response, this.logger);
|
|
82
90
|
}
|
|
83
91
|
}, _class.__initStatic(), _class);
|
|
84
92
|
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});// src/transformer/transformers/AnthropicTypes.ts
|
|
2
|
+
function getThinkLevel(budgetTokens) {
|
|
3
|
+
if (!budgetTokens || budgetTokens <= 0) return "none";
|
|
4
|
+
if (budgetTokens < 4096) return "low";
|
|
5
|
+
if (budgetTokens < 16384) return "medium";
|
|
6
|
+
return "high";
|
|
7
|
+
}
|
|
8
|
+
function formatBase64(data, mediaType) {
|
|
9
|
+
if (data.startsWith("data:")) return data;
|
|
10
|
+
return `data:${mediaType || "image/png"};base64,${data}`;
|
|
11
|
+
}
|
|
12
|
+
function flattenToolResultContent(content) {
|
|
13
|
+
if (typeof content === "string") return content;
|
|
14
|
+
if (content == null) return "";
|
|
15
|
+
if (!Array.isArray(content)) return JSON.stringify(content);
|
|
16
|
+
const parts = [];
|
|
17
|
+
for (const block of content) {
|
|
18
|
+
if (typeof block === "string") {
|
|
19
|
+
parts.push(block);
|
|
20
|
+
continue;
|
|
21
|
+
}
|
|
22
|
+
if (!block || typeof block !== "object") continue;
|
|
23
|
+
const typed = block;
|
|
24
|
+
if (typed.type === "image" || typed.type === "image_url") {
|
|
25
|
+
parts.push("[image omitted]");
|
|
26
|
+
} else if (typeof typed.text === "string") {
|
|
27
|
+
parts.push(typed.text);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
return parts.filter((text) => text !== "").join("\n");
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
exports.getThinkLevel = getThinkLevel; exports.formatBase64 = formatBase64; exports.flattenToolResultContent = flattenToolResultContent;
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }// src/reasoning/reasoning-plan.ts
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
var _canonicalmodels = require('@omnicross/contracts/canonical-models');
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
var _thinkingconfig = require('@omnicross/contracts/thinking-config');
|
|
11
|
+
var THINK_LEVELS = [
|
|
12
|
+
"none",
|
|
13
|
+
"minimal",
|
|
14
|
+
"low",
|
|
15
|
+
"medium",
|
|
16
|
+
"high",
|
|
17
|
+
"xhigh",
|
|
18
|
+
"max"
|
|
19
|
+
];
|
|
20
|
+
var THINK_LEVEL_SET = new Set(THINK_LEVELS);
|
|
21
|
+
var ANTHROPIC_FALLBACK_BUDGET = {
|
|
22
|
+
minimal: 1024,
|
|
23
|
+
low: 2048,
|
|
24
|
+
medium: 8192,
|
|
25
|
+
high: 32768,
|
|
26
|
+
xhigh: 32768,
|
|
27
|
+
max: 32768
|
|
28
|
+
};
|
|
29
|
+
function normalizeThinkLevel(value) {
|
|
30
|
+
if (typeof value !== "string") return void 0;
|
|
31
|
+
const normalized = value.toLowerCase();
|
|
32
|
+
return THINK_LEVEL_SET.has(normalized) ? normalized : void 0;
|
|
33
|
+
}
|
|
34
|
+
function extractReasoningIntent(request) {
|
|
35
|
+
const reasoning = request.reasoning;
|
|
36
|
+
if (reasoning) {
|
|
37
|
+
if (reasoning.enabled === false) {
|
|
38
|
+
return { ...reasoning, effort: "none", enabled: false };
|
|
39
|
+
}
|
|
40
|
+
const effort = normalizeThinkLevel(reasoning.effort);
|
|
41
|
+
if (effort) {
|
|
42
|
+
return { ...reasoning, effort, enabled: effort !== "none" };
|
|
43
|
+
}
|
|
44
|
+
if (reasoning.enabled === true || isPositiveFinite(reasoning.max_tokens)) {
|
|
45
|
+
return { ...reasoning, effort: "medium", enabled: true };
|
|
46
|
+
}
|
|
47
|
+
return void 0;
|
|
48
|
+
}
|
|
49
|
+
const nativeEffort = normalizeThinkLevel(request.reasoning_effort);
|
|
50
|
+
if (!nativeEffort) return void 0;
|
|
51
|
+
return { effort: nativeEffort, enabled: nativeEffort !== "none" };
|
|
52
|
+
}
|
|
53
|
+
function canonicalModelId(model) {
|
|
54
|
+
return _canonicalmodels.applyAlias.call(void 0, _canonicalmodels.normalizeModelId.call(void 0, model));
|
|
55
|
+
}
|
|
56
|
+
function findModelOverride(targetModel, modelConfigs) {
|
|
57
|
+
if (!modelConfigs) return void 0;
|
|
58
|
+
const targetId = canonicalModelId(targetModel);
|
|
59
|
+
return modelConfigs.find(
|
|
60
|
+
(config) => config.id === targetModel || canonicalModelId(config.id) === targetId
|
|
61
|
+
);
|
|
62
|
+
}
|
|
63
|
+
function resolveTargetModelCapabilities(targetModel, provider) {
|
|
64
|
+
const rowOverride = findModelOverride(targetModel, _optionalChain([provider, 'optionalAccess', _ => _.modelConfigs]));
|
|
65
|
+
return _canonicalmodels.resolveModelCapabilities.call(void 0, targetModel, void 0, rowOverride);
|
|
66
|
+
}
|
|
67
|
+
function resolveReasoningEffort(requested, targetModel, provider) {
|
|
68
|
+
if (requested === "none") return "none";
|
|
69
|
+
const capabilities = resolveTargetModelCapabilities(targetModel, provider);
|
|
70
|
+
const candidates = _nullishCoalesce(_optionalChain([capabilities, 'access', _2 => _2.thinkingLevels, 'optionalAccess', _3 => _3.map, 'call', _4 => _4(normalizeThinkLevel), 'access', _5 => _5.filter, 'call', _6 => _6((level) => level !== void 0 && level !== "none")]), () => ( []));
|
|
71
|
+
if (candidates.includes(requested)) return requested;
|
|
72
|
+
if (_optionalChain([capabilities, 'access', _7 => _7.thinkingLevels, 'optionalAccess', _8 => _8.length]) && candidates.length === 0) return "none";
|
|
73
|
+
if (candidates.length === 0) return requested;
|
|
74
|
+
const requestedRatio = _thinkingconfig.EFFORT_RATIO[requested];
|
|
75
|
+
return candidates.reduce((best, candidate) => {
|
|
76
|
+
const distance = Math.abs(_thinkingconfig.EFFORT_RATIO[candidate] - requestedRatio);
|
|
77
|
+
const bestDistance = Math.abs(_thinkingconfig.EFFORT_RATIO[best] - requestedRatio);
|
|
78
|
+
if (distance < bestDistance - Number.EPSILON) return candidate;
|
|
79
|
+
if (Math.abs(distance - bestDistance) <= Number.EPSILON && _thinkingconfig.EFFORT_RATIO[candidate] < _thinkingconfig.EFFORT_RATIO[best]) {
|
|
80
|
+
return candidate;
|
|
81
|
+
}
|
|
82
|
+
return best;
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
function protocolFallback(model, target) {
|
|
86
|
+
if (target === "anthropic") return { min: 1024, max: 128e3 };
|
|
87
|
+
if (target === "gemini") {
|
|
88
|
+
return model.toLowerCase().includes("pro") ? { min: 128, max: 32768 } : { min: 0, max: 24576 };
|
|
89
|
+
}
|
|
90
|
+
return void 0;
|
|
91
|
+
}
|
|
92
|
+
function resolveTokenLimit(model, provider, target) {
|
|
93
|
+
const capabilities = resolveTargetModelCapabilities(model, provider);
|
|
94
|
+
if (capabilities.thinkingTokenLimit) {
|
|
95
|
+
return { limits: capabilities.thinkingTokenLimit, source: "capability" };
|
|
96
|
+
}
|
|
97
|
+
const legacy = _thinkingconfig.findLegacyTokenLimit.call(void 0, model);
|
|
98
|
+
if (legacy) return { limits: legacy, source: "legacy" };
|
|
99
|
+
const fallback = protocolFallback(model, target);
|
|
100
|
+
return fallback ? { limits: fallback, source: "protocol" } : void 0;
|
|
101
|
+
}
|
|
102
|
+
function resolveReasoningTokenLimit(model, provider, target) {
|
|
103
|
+
return _optionalChain([resolveTokenLimit, 'call', _9 => _9(model, provider, target), 'optionalAccess', _10 => _10.limits]);
|
|
104
|
+
}
|
|
105
|
+
function isPositiveFinite(value) {
|
|
106
|
+
return typeof value === "number" && Number.isFinite(value) && value > 0;
|
|
107
|
+
}
|
|
108
|
+
function isFiniteNumber(value) {
|
|
109
|
+
return typeof value === "number" && Number.isFinite(value);
|
|
110
|
+
}
|
|
111
|
+
function clampBudget(rawBudget, limits, target, effort, requestMaxTokens, explicitBudget = false) {
|
|
112
|
+
const protocolMin = target === "anthropic" ? 1024 : 0;
|
|
113
|
+
const min = Math.max(protocolMin, Math.floor(limits.min));
|
|
114
|
+
let max = Math.max(min, Math.floor(limits.max));
|
|
115
|
+
if (isPositiveFinite(requestMaxTokens)) {
|
|
116
|
+
const requestCeiling = target === "anthropic" ? explicitBudget ? Math.floor(requestMaxTokens) - 1 : Math.max(
|
|
117
|
+
min,
|
|
118
|
+
Math.floor(requestMaxTokens * Math.min(_thinkingconfig.EFFORT_RATIO[effort], 0.75))
|
|
119
|
+
) : Math.floor(requestMaxTokens);
|
|
120
|
+
if (requestCeiling < min) return void 0;
|
|
121
|
+
max = Math.min(max, requestCeiling);
|
|
122
|
+
}
|
|
123
|
+
return Math.max(min, Math.min(max, Math.floor(rawBudget)));
|
|
124
|
+
}
|
|
125
|
+
function resolveBudget(intent, effort, model, provider, target, requestMaxTokens) {
|
|
126
|
+
const resolved = resolveTokenLimit(model, provider, target);
|
|
127
|
+
if (!resolved) return void 0;
|
|
128
|
+
const { limits, source } = resolved;
|
|
129
|
+
const explicitBudget = isFiniteNumber(intent.max_tokens) ? Math.floor(intent.max_tokens) : void 0;
|
|
130
|
+
const interpolated = source === "protocol" && target === "anthropic" ? ANTHROPIC_FALLBACK_BUDGET[effort] : Math.floor((limits.max - limits.min) * _thinkingconfig.EFFORT_RATIO[effort] + limits.min);
|
|
131
|
+
return clampBudget(
|
|
132
|
+
_nullishCoalesce(explicitBudget, () => ( interpolated)),
|
|
133
|
+
limits,
|
|
134
|
+
target,
|
|
135
|
+
effort,
|
|
136
|
+
requestMaxTokens,
|
|
137
|
+
explicitBudget !== void 0
|
|
138
|
+
);
|
|
139
|
+
}
|
|
140
|
+
function resolveReasoningPlan(input) {
|
|
141
|
+
const normalizedIntent = input.intent ? extractReasoningIntent({ model: input.model, reasoning: input.intent }) : void 0;
|
|
142
|
+
if (!_optionalChain([normalizedIntent, 'optionalAccess', _11 => _11.effort])) return void 0;
|
|
143
|
+
const capabilities = resolveTargetModelCapabilities(input.model, input.provider);
|
|
144
|
+
const nativeEffort = normalizedIntent.effort;
|
|
145
|
+
if (nativeEffort === "none") {
|
|
146
|
+
if (input.target === "gemini" && _optionalChain([capabilities, 'access', _12 => _12.thinkingLevels, 'optionalAccess', _13 => _13.length]) && capabilities.thinkingLevels.includes("none")) {
|
|
147
|
+
return { kind: "level", effort: "none", enabled: false };
|
|
148
|
+
}
|
|
149
|
+
if (input.target === "gemini" && !_optionalChain([capabilities, 'access', _14 => _14.thinkingLevels, 'optionalAccess', _15 => _15.length])) {
|
|
150
|
+
const limits = _optionalChain([resolveTokenLimit, 'call', _16 => _16(input.model, input.provider, input.target), 'optionalAccess', _17 => _17.limits]);
|
|
151
|
+
if (_optionalChain([limits, 'optionalAccess', _18 => _18.min]) === 0) {
|
|
152
|
+
return { kind: "budget", effort: "none", enabled: false, budgetTokens: 0 };
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
return { kind: "off" };
|
|
156
|
+
}
|
|
157
|
+
if (_optionalChain([capabilities, 'access', _19 => _19.thinkingLevels, 'optionalAccess', _20 => _20.length]) && !capabilities.thinkingLevels.some((level) => level !== "none")) {
|
|
158
|
+
return { kind: "off" };
|
|
159
|
+
}
|
|
160
|
+
const effort = input.preserveNativeEffort ? nativeEffort : resolveReasoningEffort(nativeEffort, input.model, input.provider);
|
|
161
|
+
if (effort === "none") return { kind: "off" };
|
|
162
|
+
if (input.target === "openai-chat" || input.target === "openai-responses") {
|
|
163
|
+
return { kind: "level", effort, enabled: true };
|
|
164
|
+
}
|
|
165
|
+
if (_optionalChain([capabilities, 'access', _21 => _21.thinkingLevels, 'optionalAccess', _22 => _22.length])) {
|
|
166
|
+
return { kind: "level", effort, enabled: true };
|
|
167
|
+
}
|
|
168
|
+
const budgetTokens = resolveBudget(
|
|
169
|
+
normalizedIntent,
|
|
170
|
+
effort,
|
|
171
|
+
input.model,
|
|
172
|
+
input.provider,
|
|
173
|
+
input.target,
|
|
174
|
+
input.requestMaxTokens
|
|
175
|
+
);
|
|
176
|
+
if (budgetTokens === void 0) return { kind: "off" };
|
|
177
|
+
return { kind: "budget", effort, enabled: true, budgetTokens };
|
|
178
|
+
}
|
|
179
|
+
function resolveRequestReasoning(request, provider, options = {}) {
|
|
180
|
+
const intent = extractReasoningIntent(request);
|
|
181
|
+
if (!_optionalChain([intent, 'optionalAccess', _23 => _23.effort])) return void 0;
|
|
182
|
+
const plan = resolveReasoningPlan({
|
|
183
|
+
intent,
|
|
184
|
+
model: request.model,
|
|
185
|
+
provider,
|
|
186
|
+
target: "openai-chat",
|
|
187
|
+
preserveNativeEffort: options.preserveNativeEffort
|
|
188
|
+
});
|
|
189
|
+
if (!plan) return void 0;
|
|
190
|
+
if (plan.kind === "off") return { ...intent, effort: "none", enabled: false };
|
|
191
|
+
return { ...intent, effort: plan.effort, enabled: plan.enabled };
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
|
|
195
|
+
|
|
196
|
+
|
|
197
|
+
|
|
198
|
+
|
|
199
|
+
|
|
200
|
+
|
|
201
|
+
|
|
202
|
+
|
|
203
|
+
exports.THINK_LEVELS = THINK_LEVELS; exports.normalizeThinkLevel = normalizeThinkLevel; exports.extractReasoningIntent = extractReasoningIntent; exports.resolveTargetModelCapabilities = resolveTargetModelCapabilities; exports.resolveReasoningEffort = resolveReasoningEffort; exports.resolveReasoningTokenLimit = resolveReasoningTokenLimit; exports.resolveReasoningPlan = resolveReasoningPlan; exports.resolveRequestReasoning = resolveRequestReasoning;
|
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
import {
|
|
2
|
+
extractReasoningIntent,
|
|
3
|
+
resolveReasoningPlan
|
|
4
|
+
} from "./chunk-N2EIM2XJ.js";
|
|
5
|
+
|
|
1
6
|
// src/transformer/transformers/OpenAITransformer.ts
|
|
2
7
|
var FOREIGN_MESSAGE_KEYS = ["cache_control", "thinking"];
|
|
3
8
|
var FOREIGN_BODY_KEYS = ["meta", "reasoning", "thinking"];
|
|
@@ -24,7 +29,7 @@ var OpenAITransformer = class {
|
|
|
24
29
|
/**
|
|
25
30
|
* Unified → OpenAI Chat Completions.
|
|
26
31
|
*/
|
|
27
|
-
async transformRequestIn(request,
|
|
32
|
+
async transformRequestIn(request, provider, _context) {
|
|
28
33
|
const source = request;
|
|
29
34
|
const out = {};
|
|
30
35
|
for (const key of Object.keys(source)) {
|
|
@@ -49,9 +54,17 @@ var OpenAITransformer = class {
|
|
|
49
54
|
return encoded;
|
|
50
55
|
});
|
|
51
56
|
}
|
|
52
|
-
const
|
|
53
|
-
|
|
54
|
-
|
|
57
|
+
const reasoningPlan = request.reasoning ? resolveReasoningPlan({
|
|
58
|
+
intent: extractReasoningIntent(request),
|
|
59
|
+
model: request.model,
|
|
60
|
+
provider,
|
|
61
|
+
target: "openai-chat",
|
|
62
|
+
requestMaxTokens: request.max_tokens
|
|
63
|
+
}) : void 0;
|
|
64
|
+
if (reasoningPlan?.kind === "level" && reasoningPlan.enabled) {
|
|
65
|
+
out.reasoning_effort = reasoningPlan.effort;
|
|
66
|
+
} else if (request.reasoning) {
|
|
67
|
+
delete out.reasoning_effort;
|
|
55
68
|
}
|
|
56
69
|
return out;
|
|
57
70
|
}
|