@jsonstudio/llms 0.6.3405 → 0.6.3539
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/conversion/codecs/anthropic-openai-codec.d.ts +12 -3
- package/dist/conversion/codecs/anthropic-openai-codec.js +32 -92
- package/dist/conversion/codecs/gemini-openai-codec.d.ts +6 -5
- package/dist/conversion/codecs/gemini-openai-codec.js +48 -685
- package/dist/conversion/codecs/openai-openai-codec.d.ts +1 -1
- package/dist/conversion/codecs/openai-openai-codec.js +34 -100
- package/dist/conversion/codecs/responses-openai-codec.d.ts +1 -1
- package/dist/conversion/codecs/responses-openai-codec.js +47 -159
- package/dist/conversion/compat/actions/anthropic-claude-code-system-prompt.d.ts +2 -6
- package/dist/conversion/compat/actions/anthropic-claude-code-system-prompt.js +29 -245
- package/dist/conversion/compat/actions/anthropic-claude-code-user-id.d.ts +3 -0
- package/dist/conversion/compat/actions/anthropic-claude-code-user-id.js +30 -0
- package/dist/conversion/compat/actions/antigravity-thought-signature-prepare.js +21 -232
- package/dist/conversion/compat/actions/deepseek-web-request.js +41 -276
- package/dist/conversion/compat/actions/deepseek-web-response.js +64 -859
- package/dist/conversion/compat/actions/gemini-cli-request.d.ts +1 -1
- package/dist/conversion/compat/actions/gemini-cli-request.js +20 -613
- package/dist/conversion/compat/actions/gemini-web-search.d.ts +1 -15
- package/dist/conversion/compat/actions/gemini-web-search.js +22 -69
- package/dist/conversion/compat/actions/glm-tool-extraction.d.ts +3 -2
- package/dist/conversion/compat/actions/glm-tool-extraction.js +28 -257
- package/dist/conversion/compat/actions/iflow-tool-text-fallback.d.ts +0 -8
- package/dist/conversion/compat/actions/iflow-tool-text-fallback.js +24 -206
- package/dist/conversion/compat/actions/qwen-transform.d.ts +3 -2
- package/dist/conversion/compat/actions/qwen-transform.js +30 -271
- package/dist/conversion/compat/actions/tool-text-request-guidance.js +3 -173
- package/dist/conversion/compat/actions/universal-shape-filter.d.ts +6 -23
- package/dist/conversion/compat/actions/universal-shape-filter.js +4 -383
- package/dist/conversion/hub/pipeline/compat/native-adapter-context.js +1 -0
- package/dist/conversion/pipeline/codecs/v2/anthropic-openai-pipeline.d.ts +1 -2
- package/dist/conversion/pipeline/codecs/v2/anthropic-openai-pipeline.js +50 -104
- package/dist/conversion/pipeline/codecs/v2/openai-openai-pipeline.js +12 -10
- package/dist/conversion/pipeline/codecs/v2/responses-openai-pipeline.d.ts +0 -2
- package/dist/conversion/pipeline/codecs/v2/responses-openai-pipeline.js +46 -67
- package/dist/conversion/pipeline/codecs/v2/shared/openai-chat-helpers.js +15 -40
- package/dist/conversion/responses/responses-openai-bridge/response-payload.js +47 -348
- package/dist/conversion/responses/responses-openai-bridge.js +129 -611
- package/dist/conversion/shared/chat-output-normalizer.js +6 -0
- package/dist/conversion/shared/chat-request-filters.js +1 -1
- package/dist/conversion/shared/output-content-normalizer.js +10 -0
- package/dist/conversion/shared/responses-conversation-store.js +22 -135
- package/dist/conversion/shared/responses-output-builder.d.ts +0 -2
- package/dist/conversion/shared/responses-output-builder.js +28 -318
- package/dist/conversion/shared/responses-response-utils.js +35 -86
- package/dist/conversion/shared/streaming-text-extractor.d.ts +1 -2
- package/dist/conversion/shared/streaming-text-extractor.js +13 -14
- package/dist/conversion/shared/tool-call-id-manager.js +18 -21
- package/dist/native/router_hotpath_napi.node +0 -0
- package/dist/router/virtual-router/bootstrap/routing-config.d.ts +2 -1
- package/dist/router/virtual-router/bootstrap/routing-config.js +57 -4
- package/dist/router/virtual-router/engine-legacy.d.ts +3 -3
- package/dist/router/virtual-router/engine-legacy.js +15 -7
- package/dist/router/virtual-router/engine-selection/native-compat-action-semantics.d.ts +16 -0
- package/dist/router/virtual-router/engine-selection/native-compat-action-semantics.js +434 -46
- package/dist/router/virtual-router/engine-selection/native-hub-bridge-action-semantics.d.ts +83 -0
- package/dist/router/virtual-router/engine-selection/native-hub-bridge-action-semantics.js +295 -0
- package/dist/router/virtual-router/engine-selection/native-hub-pipeline-req-outbound-semantics.d.ts +1 -0
- package/dist/router/virtual-router/engine-selection/native-hub-pipeline-resp-semantics.d.ts +7 -0
- package/dist/router/virtual-router/engine-selection/native-hub-pipeline-resp-semantics.js +8 -1
- package/dist/router/virtual-router/engine-selection/native-router-hotpath-loader.js +383 -298
- package/dist/router/virtual-router/engine-selection/native-shared-conversion-semantics.d.ts +20 -0
- package/dist/router/virtual-router/engine-selection/native-shared-conversion-semantics.js +201 -0
- package/dist/router/virtual-router/engine-selection/native-virtual-router-routing-instructions-semantics.d.ts +1 -0
- package/dist/router/virtual-router/engine-selection/native-virtual-router-routing-instructions-semantics.js +37 -0
- package/dist/router/virtual-router/engine-selection/tier-load-balancing.d.ts +16 -0
- package/dist/router/virtual-router/engine-selection/tier-load-balancing.js +120 -0
- package/dist/router/virtual-router/engine-selection/tier-selection-quota-integration.d.ts +2 -0
- package/dist/router/virtual-router/engine-selection/tier-selection-quota-integration.js +44 -66
- package/dist/router/virtual-router/engine-selection/tier-selection-select.js +53 -84
- package/dist/router/virtual-router/engine.js +0 -38
- package/dist/router/virtual-router/features.js +44 -3
- package/dist/router/virtual-router/routing-instructions/parse.d.ts +0 -12
- package/dist/router/virtual-router/routing-instructions/parse.js +9 -389
- package/dist/router/virtual-router/stop-message-state-sync.d.ts +3 -6
- package/dist/router/virtual-router/stop-message-state-sync.js +50 -21
- package/dist/router/virtual-router/types.d.ts +16 -0
- package/dist/sse/sse-to-json/anthropic-sse-to-json-converter.d.ts +1 -0
- package/dist/sse/sse-to-json/anthropic-sse-to-json-converter.js +26 -0
- package/dist/sse/sse-to-json/builders/anthropic-response-builder.js +12 -2
- package/package.json +1 -1
- package/dist/router/virtual-router/engine-legacy/route-finalize.d.ts +0 -9
- package/dist/router/virtual-router/engine-legacy/route-finalize.js +0 -84
- package/dist/router/virtual-router/engine-legacy/route-selection.d.ts +0 -17
- package/dist/router/virtual-router/engine-legacy/route-selection.js +0 -205
- package/dist/router/virtual-router/engine-legacy/route-state-allowlist.d.ts +0 -3
- package/dist/router/virtual-router/engine-legacy/route-state-allowlist.js +0 -36
- package/dist/router/virtual-router/engine-legacy/route-state.d.ts +0 -12
- package/dist/router/virtual-router/engine-legacy/route-state.js +0 -386
- package/dist/router/virtual-router/engine-legacy/routing.d.ts +0 -8
- package/dist/router/virtual-router/engine-legacy/routing.js +0 -8
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
import { failNativeRequired, isNativeDisabledByEnv } from
|
|
2
|
-
import { loadNativeRouterHotpathBindingForInternalUse } from
|
|
1
|
+
import { failNativeRequired, isNativeDisabledByEnv, } from "./native-router-hotpath-policy.js";
|
|
2
|
+
import { loadNativeRouterHotpathBindingForInternalUse } from "./native-router-hotpath.js";
|
|
3
3
|
function readNativeFunction(name) {
|
|
4
4
|
const binding = loadNativeRouterHotpathBindingForInternalUse();
|
|
5
5
|
const fn = binding?.[name];
|
|
6
|
-
return typeof fn ===
|
|
6
|
+
return typeof fn === "function"
|
|
7
|
+
? fn
|
|
8
|
+
: null;
|
|
7
9
|
}
|
|
8
10
|
function safeStringify(value) {
|
|
9
11
|
try {
|
|
@@ -16,7 +18,7 @@ function safeStringify(value) {
|
|
|
16
18
|
function parseRecord(raw) {
|
|
17
19
|
try {
|
|
18
20
|
const parsed = JSON.parse(raw);
|
|
19
|
-
if (!parsed || typeof parsed !==
|
|
21
|
+
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
|
|
20
22
|
return null;
|
|
21
23
|
}
|
|
22
24
|
return parsed;
|
|
@@ -26,38 +28,38 @@ function parseRecord(raw) {
|
|
|
26
28
|
}
|
|
27
29
|
}
|
|
28
30
|
export function normalizeResponsePayloadWithNative(payload, config) {
|
|
29
|
-
const capability =
|
|
31
|
+
const capability = "normalizeResponsePayloadJson";
|
|
30
32
|
const fail = (reason) => failNativeRequired(capability, reason);
|
|
31
33
|
if (isNativeDisabledByEnv()) {
|
|
32
|
-
return fail(
|
|
34
|
+
return fail("native disabled");
|
|
33
35
|
}
|
|
34
36
|
const fn = readNativeFunction(capability);
|
|
35
37
|
if (!fn) {
|
|
36
38
|
return fail();
|
|
37
39
|
}
|
|
38
40
|
const payloadJson = safeStringify(payload);
|
|
39
|
-
const configJson = config ? safeStringify(config) :
|
|
41
|
+
const configJson = config ? safeStringify(config) : "{}";
|
|
40
42
|
if (!payloadJson || !configJson) {
|
|
41
|
-
return fail(
|
|
43
|
+
return fail("json stringify failed");
|
|
42
44
|
}
|
|
43
45
|
try {
|
|
44
46
|
const raw = fn(payloadJson, configJson);
|
|
45
|
-
if (typeof raw !==
|
|
46
|
-
return fail(
|
|
47
|
+
if (typeof raw !== "string" || !raw) {
|
|
48
|
+
return fail("empty result");
|
|
47
49
|
}
|
|
48
50
|
const parsed = parseRecord(raw);
|
|
49
|
-
return parsed ?? fail(
|
|
51
|
+
return parsed ?? fail("invalid payload");
|
|
50
52
|
}
|
|
51
53
|
catch (error) {
|
|
52
|
-
const reason = error instanceof Error ? error.message : String(error ??
|
|
54
|
+
const reason = error instanceof Error ? error.message : String(error ?? "unknown");
|
|
53
55
|
return fail(reason);
|
|
54
56
|
}
|
|
55
57
|
}
|
|
56
58
|
export function validateResponsePayloadWithNative(payload) {
|
|
57
|
-
const capability =
|
|
59
|
+
const capability = "validateResponsePayloadJson";
|
|
58
60
|
const fail = (reason) => failNativeRequired(capability, reason);
|
|
59
61
|
if (isNativeDisabledByEnv()) {
|
|
60
|
-
return fail(
|
|
62
|
+
return fail("native disabled");
|
|
61
63
|
}
|
|
62
64
|
const fn = readNativeFunction(capability);
|
|
63
65
|
if (!fn) {
|
|
@@ -65,107 +67,493 @@ export function validateResponsePayloadWithNative(payload) {
|
|
|
65
67
|
}
|
|
66
68
|
const payloadJson = safeStringify(payload);
|
|
67
69
|
if (!payloadJson) {
|
|
68
|
-
return fail(
|
|
70
|
+
return fail("json stringify failed");
|
|
69
71
|
}
|
|
70
72
|
try {
|
|
71
73
|
fn(payloadJson);
|
|
72
74
|
}
|
|
73
75
|
catch (error) {
|
|
74
|
-
const reason = error instanceof Error ? error.message : String(error ??
|
|
76
|
+
const reason = error instanceof Error ? error.message : String(error ?? "unknown");
|
|
75
77
|
throw new Error(reason);
|
|
76
78
|
}
|
|
77
79
|
}
|
|
78
80
|
export function applyRequestRulesWithNative(payload, config) {
|
|
79
|
-
const capability =
|
|
81
|
+
const capability = "applyRequestRulesJson";
|
|
80
82
|
const fail = (reason) => failNativeRequired(capability, reason);
|
|
81
83
|
if (isNativeDisabledByEnv())
|
|
82
|
-
return fail(
|
|
84
|
+
return fail("native disabled");
|
|
83
85
|
const fn = readNativeFunction(capability);
|
|
84
86
|
if (!fn)
|
|
85
87
|
return fail();
|
|
86
88
|
const payloadJson = safeStringify(payload);
|
|
87
|
-
const configJson = config ? safeStringify(config) :
|
|
89
|
+
const configJson = config ? safeStringify(config) : "{}";
|
|
88
90
|
if (!payloadJson || !configJson)
|
|
89
|
-
return fail(
|
|
91
|
+
return fail("json stringify failed");
|
|
90
92
|
try {
|
|
91
93
|
const raw = fn(payloadJson, configJson);
|
|
92
|
-
if (typeof raw !==
|
|
93
|
-
return fail(
|
|
94
|
+
if (typeof raw !== "string" || !raw)
|
|
95
|
+
return fail("empty result");
|
|
94
96
|
const parsed = parseRecord(raw);
|
|
95
|
-
return parsed ?? fail(
|
|
97
|
+
return parsed ?? fail("invalid payload");
|
|
96
98
|
}
|
|
97
99
|
catch (error) {
|
|
98
|
-
const reason = error instanceof Error ? error.message : String(error ??
|
|
100
|
+
const reason = error instanceof Error ? error.message : String(error ?? "unknown");
|
|
99
101
|
return fail(reason);
|
|
100
102
|
}
|
|
101
103
|
}
|
|
102
104
|
export function applyResponseBlacklistWithNative(payload, config) {
|
|
103
|
-
const capability =
|
|
105
|
+
const capability = "applyResponseBlacklistJson";
|
|
104
106
|
const fail = (reason) => failNativeRequired(capability, reason);
|
|
105
107
|
if (isNativeDisabledByEnv())
|
|
106
|
-
return fail(
|
|
108
|
+
return fail("native disabled");
|
|
107
109
|
const fn = readNativeFunction(capability);
|
|
108
110
|
if (!fn)
|
|
109
111
|
return fail();
|
|
110
112
|
const payloadJson = safeStringify(payload);
|
|
111
|
-
const configJson = config ? safeStringify(config) :
|
|
113
|
+
const configJson = config ? safeStringify(config) : "{}";
|
|
112
114
|
if (!payloadJson || !configJson)
|
|
113
|
-
return fail(
|
|
115
|
+
return fail("json stringify failed");
|
|
114
116
|
try {
|
|
115
117
|
const raw = fn(payloadJson, configJson);
|
|
116
|
-
if (typeof raw !==
|
|
117
|
-
return fail(
|
|
118
|
+
if (typeof raw !== "string" || !raw)
|
|
119
|
+
return fail("empty result");
|
|
118
120
|
const parsed = parseRecord(raw);
|
|
119
|
-
return parsed ?? fail(
|
|
121
|
+
return parsed ?? fail("invalid payload");
|
|
120
122
|
}
|
|
121
123
|
catch (error) {
|
|
122
|
-
const reason = error instanceof Error ? error.message : String(error ??
|
|
124
|
+
const reason = error instanceof Error ? error.message : String(error ?? "unknown");
|
|
123
125
|
return fail(reason);
|
|
124
126
|
}
|
|
125
127
|
}
|
|
126
128
|
export function normalizeToolCallIdsWithNative(payload) {
|
|
127
|
-
const capability =
|
|
129
|
+
const capability = "normalizeToolCallIdsJson";
|
|
128
130
|
const fail = (reason) => failNativeRequired(capability, reason);
|
|
129
131
|
if (isNativeDisabledByEnv())
|
|
130
|
-
return fail(
|
|
132
|
+
return fail("native disabled");
|
|
131
133
|
const fn = readNativeFunction(capability);
|
|
132
134
|
if (!fn)
|
|
133
135
|
return fail();
|
|
134
136
|
const payloadJson = safeStringify(payload);
|
|
135
137
|
if (!payloadJson)
|
|
136
|
-
return fail(
|
|
138
|
+
return fail("json stringify failed");
|
|
137
139
|
try {
|
|
138
140
|
const raw = fn(payloadJson);
|
|
139
|
-
if (typeof raw !==
|
|
140
|
-
return fail(
|
|
141
|
+
if (typeof raw !== "string" || !raw)
|
|
142
|
+
return fail("empty result");
|
|
141
143
|
const parsed = parseRecord(raw);
|
|
142
|
-
return parsed ?? fail(
|
|
144
|
+
return parsed ?? fail("invalid payload");
|
|
143
145
|
}
|
|
144
146
|
catch (error) {
|
|
145
|
-
const reason = error instanceof Error ? error.message : String(error ??
|
|
147
|
+
const reason = error instanceof Error ? error.message : String(error ?? "unknown");
|
|
146
148
|
return fail(reason);
|
|
147
149
|
}
|
|
148
150
|
}
|
|
149
151
|
export function enforceLmstudioResponsesFcToolCallIdsWithNative(payload) {
|
|
150
|
-
const capability =
|
|
152
|
+
const capability = "enforceLmstudioResponsesFcToolCallIdsJson";
|
|
151
153
|
const fail = (reason) => failNativeRequired(capability, reason);
|
|
152
154
|
if (isNativeDisabledByEnv())
|
|
153
|
-
return fail(
|
|
155
|
+
return fail("native disabled");
|
|
154
156
|
const fn = readNativeFunction(capability);
|
|
155
157
|
if (!fn)
|
|
156
158
|
return fail();
|
|
157
159
|
const payloadJson = safeStringify(payload);
|
|
158
160
|
if (!payloadJson)
|
|
159
|
-
return fail(
|
|
161
|
+
return fail("json stringify failed");
|
|
160
162
|
try {
|
|
161
163
|
const raw = fn(payloadJson);
|
|
162
|
-
if (typeof raw !==
|
|
163
|
-
return fail(
|
|
164
|
+
if (typeof raw !== "string" || !raw)
|
|
165
|
+
return fail("empty result");
|
|
164
166
|
const parsed = parseRecord(raw);
|
|
165
|
-
return parsed ?? fail(
|
|
167
|
+
return parsed ?? fail("invalid payload");
|
|
166
168
|
}
|
|
167
169
|
catch (error) {
|
|
168
|
-
const reason = error instanceof Error ? error.message : String(error ??
|
|
170
|
+
const reason = error instanceof Error ? error.message : String(error ?? "unknown");
|
|
171
|
+
return fail(reason);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
export function applyAnthropicClaudeCodeUserIdWithNative(payload, adapterContext) {
|
|
175
|
+
const capability = "applyAnthropicClaudeCodeUserIdJson";
|
|
176
|
+
const fail = (reason) => failNativeRequired(capability, reason);
|
|
177
|
+
if (isNativeDisabledByEnv())
|
|
178
|
+
return fail("native disabled");
|
|
179
|
+
const fn = readNativeFunction(capability);
|
|
180
|
+
if (!fn)
|
|
181
|
+
return fail();
|
|
182
|
+
const payloadJson = safeStringify(payload);
|
|
183
|
+
const contextJson = adapterContext ? safeStringify(adapterContext) : "{}";
|
|
184
|
+
if (!payloadJson || !contextJson)
|
|
185
|
+
return fail("json stringify failed");
|
|
186
|
+
try {
|
|
187
|
+
const raw = fn(payloadJson, contextJson);
|
|
188
|
+
if (typeof raw !== "string" || !raw)
|
|
189
|
+
return fail("empty result");
|
|
190
|
+
const parsed = parseRecord(raw);
|
|
191
|
+
return parsed ?? fail("invalid payload");
|
|
192
|
+
}
|
|
193
|
+
catch (error) {
|
|
194
|
+
const reason = error instanceof Error ? error.message : String(error ?? "unknown");
|
|
195
|
+
return fail(reason);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
export function applyGeminiWebSearchRequestCompatWithNative(payload, adapterContext) {
|
|
199
|
+
const capability = "applyGeminiWebSearchRequestCompatJson";
|
|
200
|
+
const fail = (reason) => failNativeRequired(capability, reason);
|
|
201
|
+
if (isNativeDisabledByEnv())
|
|
202
|
+
return fail("native disabled");
|
|
203
|
+
const fn = readNativeFunction(capability);
|
|
204
|
+
if (!fn)
|
|
205
|
+
return fail();
|
|
206
|
+
const payloadJson = safeStringify(payload);
|
|
207
|
+
const contextJson = adapterContext ? safeStringify(adapterContext) : "{}";
|
|
208
|
+
if (!payloadJson || !contextJson)
|
|
209
|
+
return fail("json stringify failed");
|
|
210
|
+
try {
|
|
211
|
+
const raw = fn(payloadJson, contextJson);
|
|
212
|
+
if (typeof raw !== "string" || !raw)
|
|
213
|
+
return fail("empty result");
|
|
214
|
+
const parsed = parseRecord(raw);
|
|
215
|
+
return parsed ?? fail("invalid payload");
|
|
216
|
+
}
|
|
217
|
+
catch (error) {
|
|
218
|
+
const reason = error instanceof Error ? error.message : String(error ?? "unknown");
|
|
219
|
+
return fail(reason);
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
export function prepareAntigravityThoughtSignatureForGeminiRequestWithNative(payload, adapterContext) {
|
|
223
|
+
const capability = "prepareAntigravityThoughtSignatureForGeminiRequestJson";
|
|
224
|
+
const fail = (reason) => failNativeRequired(capability, reason);
|
|
225
|
+
if (isNativeDisabledByEnv())
|
|
226
|
+
return fail("native disabled");
|
|
227
|
+
const fn = readNativeFunction(capability);
|
|
228
|
+
if (!fn)
|
|
229
|
+
return fail();
|
|
230
|
+
const payloadJson = safeStringify(payload);
|
|
231
|
+
const contextJson = adapterContext ? safeStringify(adapterContext) : "{}";
|
|
232
|
+
if (!payloadJson || !contextJson)
|
|
233
|
+
return fail("json stringify failed");
|
|
234
|
+
try {
|
|
235
|
+
const raw = fn(payloadJson, contextJson);
|
|
236
|
+
if (typeof raw !== "string" || !raw)
|
|
237
|
+
return fail("empty result");
|
|
238
|
+
const parsed = parseRecord(raw);
|
|
239
|
+
return parsed ?? fail("invalid payload");
|
|
240
|
+
}
|
|
241
|
+
catch (error) {
|
|
242
|
+
const reason = error instanceof Error ? error.message : String(error ?? "unknown");
|
|
243
|
+
return fail(reason);
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
export function applyIflowToolTextFallbackWithNative(payload, adapterContext, models) {
|
|
247
|
+
const capability = "applyIflowToolTextFallbackJson";
|
|
248
|
+
const fail = (reason) => failNativeRequired(capability, reason);
|
|
249
|
+
if (isNativeDisabledByEnv())
|
|
250
|
+
return fail("native disabled");
|
|
251
|
+
const fn = readNativeFunction(capability);
|
|
252
|
+
if (!fn)
|
|
253
|
+
return fail();
|
|
254
|
+
const payloadJson = safeStringify(payload);
|
|
255
|
+
const contextJson = adapterContext ? safeStringify(adapterContext) : "{}";
|
|
256
|
+
const modelsJson = safeStringify(Array.isArray(models) ? models : []);
|
|
257
|
+
if (!payloadJson || !contextJson || !modelsJson)
|
|
258
|
+
return fail("json stringify failed");
|
|
259
|
+
try {
|
|
260
|
+
const raw = fn(payloadJson, contextJson, modelsJson);
|
|
261
|
+
if (typeof raw !== "string" || !raw)
|
|
262
|
+
return fail("empty result");
|
|
263
|
+
const parsed = parseRecord(raw);
|
|
264
|
+
return parsed ?? fail("invalid payload");
|
|
265
|
+
}
|
|
266
|
+
catch (error) {
|
|
267
|
+
const reason = error instanceof Error ? error.message : String(error ?? "unknown");
|
|
268
|
+
return fail(reason);
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
export function applyToolTextRequestGuidanceWithNative(payload, config) {
|
|
272
|
+
const capability = "applyToolTextRequestGuidanceJson";
|
|
273
|
+
const fail = (reason) => failNativeRequired(capability, reason);
|
|
274
|
+
if (isNativeDisabledByEnv())
|
|
275
|
+
return fail("native disabled");
|
|
276
|
+
const fn = readNativeFunction(capability);
|
|
277
|
+
if (!fn)
|
|
278
|
+
return fail();
|
|
279
|
+
const payloadJson = safeStringify(payload);
|
|
280
|
+
const configJson = config ? safeStringify(config) : "{}";
|
|
281
|
+
if (!payloadJson || !configJson)
|
|
282
|
+
return fail("json stringify failed");
|
|
283
|
+
try {
|
|
284
|
+
const raw = fn(payloadJson, configJson);
|
|
285
|
+
if (typeof raw !== "string" || !raw)
|
|
286
|
+
return fail("empty result");
|
|
287
|
+
const parsed = parseRecord(raw);
|
|
288
|
+
return parsed ?? fail("invalid payload");
|
|
289
|
+
}
|
|
290
|
+
catch (error) {
|
|
291
|
+
const reason = error instanceof Error ? error.message : String(error ?? "unknown");
|
|
292
|
+
return fail(reason);
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
export function applyUniversalShapeRequestFilterWithNative(payload, config) {
|
|
296
|
+
const capability = "applyUniversalShapeRequestFilterJson";
|
|
297
|
+
const fail = (reason) => failNativeRequired(capability, reason);
|
|
298
|
+
if (isNativeDisabledByEnv())
|
|
299
|
+
return fail("native disabled");
|
|
300
|
+
const fn = readNativeFunction(capability);
|
|
301
|
+
if (!fn)
|
|
302
|
+
return fail();
|
|
303
|
+
const payloadJson = safeStringify(payload);
|
|
304
|
+
const configJson = config ? safeStringify(config) : "{}";
|
|
305
|
+
if (!payloadJson || !configJson)
|
|
306
|
+
return fail("json stringify failed");
|
|
307
|
+
try {
|
|
308
|
+
const raw = fn(payloadJson, configJson);
|
|
309
|
+
if (typeof raw !== "string" || !raw)
|
|
310
|
+
return fail("empty result");
|
|
311
|
+
const parsed = parseRecord(raw);
|
|
312
|
+
return parsed ?? fail("invalid payload");
|
|
313
|
+
}
|
|
314
|
+
catch (error) {
|
|
315
|
+
const reason = error instanceof Error ? error.message : String(error ?? "unknown");
|
|
316
|
+
return fail(reason);
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
export function applyUniversalShapeResponseFilterWithNative(payload, config, adapterContext) {
|
|
320
|
+
const capability = "applyUniversalShapeResponseFilterJson";
|
|
321
|
+
const fail = (reason) => failNativeRequired(capability, reason);
|
|
322
|
+
if (isNativeDisabledByEnv())
|
|
323
|
+
return fail("native disabled");
|
|
324
|
+
const fn = readNativeFunction(capability);
|
|
325
|
+
if (!fn)
|
|
326
|
+
return fail();
|
|
327
|
+
const payloadJson = safeStringify(payload);
|
|
328
|
+
const configJson = config ? safeStringify(config) : "{}";
|
|
329
|
+
const contextJson = adapterContext ? safeStringify(adapterContext) : "{}";
|
|
330
|
+
if (!payloadJson || !configJson || !contextJson)
|
|
331
|
+
return fail("json stringify failed");
|
|
332
|
+
try {
|
|
333
|
+
const raw = fn(payloadJson, configJson, contextJson);
|
|
334
|
+
if (typeof raw !== "string" || !raw)
|
|
335
|
+
return fail("empty result");
|
|
336
|
+
const parsed = parseRecord(raw);
|
|
337
|
+
return parsed ?? fail("invalid payload");
|
|
338
|
+
}
|
|
339
|
+
catch (error) {
|
|
340
|
+
const reason = error instanceof Error ? error.message : String(error ?? "unknown");
|
|
341
|
+
return fail(reason);
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
export function buildOpenAIChatFromAnthropicWithNative(payload, options) {
|
|
345
|
+
const capability = "buildOpenaiChatFromAnthropicJson";
|
|
346
|
+
const fail = (reason) => failNativeRequired(capability, reason);
|
|
347
|
+
if (isNativeDisabledByEnv())
|
|
348
|
+
return fail("native disabled");
|
|
349
|
+
const fn = readNativeFunction(capability);
|
|
350
|
+
if (!fn)
|
|
351
|
+
return fail();
|
|
352
|
+
const payloadJson = safeStringify(payload);
|
|
353
|
+
const optionsJson = options ? safeStringify(options) : "{}";
|
|
354
|
+
if (!payloadJson || !optionsJson)
|
|
355
|
+
return fail("json stringify failed");
|
|
356
|
+
try {
|
|
357
|
+
const raw = fn(payloadJson, optionsJson);
|
|
358
|
+
if (typeof raw !== "string" || !raw)
|
|
359
|
+
return fail("empty result");
|
|
360
|
+
const parsed = parseRecord(raw);
|
|
361
|
+
return parsed ?? fail("invalid payload");
|
|
362
|
+
}
|
|
363
|
+
catch (error) {
|
|
364
|
+
const reason = error instanceof Error ? error.message : String(error ?? "unknown");
|
|
365
|
+
return fail(reason);
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
export function buildAnthropicFromOpenAIChatWithNative(payload, options) {
|
|
369
|
+
const capability = "buildAnthropicFromOpenaiChatJson";
|
|
370
|
+
const fail = (reason) => failNativeRequired(capability, reason);
|
|
371
|
+
if (isNativeDisabledByEnv())
|
|
372
|
+
return fail("native disabled");
|
|
373
|
+
const fn = readNativeFunction(capability);
|
|
374
|
+
if (!fn)
|
|
375
|
+
return fail();
|
|
376
|
+
const payloadJson = safeStringify(payload);
|
|
377
|
+
const optionsJson = options ? safeStringify(options) : "{}";
|
|
378
|
+
if (!payloadJson || !optionsJson)
|
|
379
|
+
return fail("json stringify failed");
|
|
380
|
+
try {
|
|
381
|
+
const raw = fn(payloadJson, optionsJson);
|
|
382
|
+
if (typeof raw !== "string" || !raw)
|
|
383
|
+
return fail("empty result");
|
|
384
|
+
const parsed = parseRecord(raw);
|
|
385
|
+
return parsed ?? fail("invalid payload");
|
|
386
|
+
}
|
|
387
|
+
catch (error) {
|
|
388
|
+
const reason = error instanceof Error ? error.message : String(error ?? "unknown");
|
|
389
|
+
return fail(reason);
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
export function runOpenAIRequestCodecWithNative(payload, options) {
|
|
393
|
+
const capability = "runOpenaiOpenaiRequestCodecJson";
|
|
394
|
+
const fail = (reason) => failNativeRequired(capability, reason);
|
|
395
|
+
if (isNativeDisabledByEnv())
|
|
396
|
+
return fail("native disabled");
|
|
397
|
+
const fn = readNativeFunction(capability);
|
|
398
|
+
if (!fn)
|
|
399
|
+
return fail();
|
|
400
|
+
const payloadJson = safeStringify(payload);
|
|
401
|
+
const optionsJson = options ? safeStringify(options) : "{}";
|
|
402
|
+
if (!payloadJson || !optionsJson)
|
|
403
|
+
return fail("json stringify failed");
|
|
404
|
+
try {
|
|
405
|
+
const raw = fn(payloadJson, optionsJson);
|
|
406
|
+
if (typeof raw !== "string" || !raw)
|
|
407
|
+
return fail("empty result");
|
|
408
|
+
const parsed = parseRecord(raw);
|
|
409
|
+
return parsed ?? fail("invalid payload");
|
|
410
|
+
}
|
|
411
|
+
catch (error) {
|
|
412
|
+
const reason = error instanceof Error ? error.message : String(error ?? "unknown");
|
|
413
|
+
return fail(reason);
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
export function runOpenAIResponseCodecWithNative(payload, options) {
|
|
417
|
+
const capability = "runOpenaiOpenaiResponseCodecJson";
|
|
418
|
+
const fail = (reason) => failNativeRequired(capability, reason);
|
|
419
|
+
if (isNativeDisabledByEnv())
|
|
420
|
+
return fail("native disabled");
|
|
421
|
+
const fn = readNativeFunction(capability);
|
|
422
|
+
if (!fn)
|
|
423
|
+
return fail();
|
|
424
|
+
const payloadJson = safeStringify(payload);
|
|
425
|
+
const optionsJson = options ? safeStringify(options) : "{}";
|
|
426
|
+
if (!payloadJson || !optionsJson)
|
|
427
|
+
return fail("json stringify failed");
|
|
428
|
+
try {
|
|
429
|
+
const raw = fn(payloadJson, optionsJson);
|
|
430
|
+
if (typeof raw !== "string" || !raw)
|
|
431
|
+
return fail("empty result");
|
|
432
|
+
const parsed = parseRecord(raw);
|
|
433
|
+
return parsed ?? fail("invalid payload");
|
|
434
|
+
}
|
|
435
|
+
catch (error) {
|
|
436
|
+
const reason = error instanceof Error ? error.message : String(error ?? "unknown");
|
|
437
|
+
return fail(reason);
|
|
438
|
+
}
|
|
439
|
+
}
|
|
440
|
+
export function runResponsesOpenAIRequestCodecWithNative(payload, options) {
|
|
441
|
+
const capability = "runResponsesOpenaiRequestCodecJson";
|
|
442
|
+
const fail = (reason) => failNativeRequired(capability, reason);
|
|
443
|
+
if (isNativeDisabledByEnv())
|
|
444
|
+
return fail("native disabled");
|
|
445
|
+
const fn = readNativeFunction(capability);
|
|
446
|
+
if (!fn)
|
|
447
|
+
return fail();
|
|
448
|
+
const payloadJson = safeStringify(payload);
|
|
449
|
+
const optionsJson = options ? safeStringify(options) : "{}";
|
|
450
|
+
if (!payloadJson || !optionsJson)
|
|
451
|
+
return fail("json stringify failed");
|
|
452
|
+
try {
|
|
453
|
+
const raw = fn(payloadJson, optionsJson);
|
|
454
|
+
if (typeof raw !== "string" || !raw)
|
|
455
|
+
return fail("empty result");
|
|
456
|
+
const parsed = parseRecord(raw);
|
|
457
|
+
return parsed ?? fail("invalid payload");
|
|
458
|
+
}
|
|
459
|
+
catch (error) {
|
|
460
|
+
const reason = error instanceof Error ? error.message : String(error ?? "unknown");
|
|
461
|
+
return fail(reason);
|
|
462
|
+
}
|
|
463
|
+
}
|
|
464
|
+
export function runResponsesOpenAIResponseCodecWithNative(payload, context) {
|
|
465
|
+
const capability = "runResponsesOpenaiResponseCodecJson";
|
|
466
|
+
const fail = (reason) => failNativeRequired(capability, reason);
|
|
467
|
+
if (isNativeDisabledByEnv())
|
|
468
|
+
return fail("native disabled");
|
|
469
|
+
const fn = readNativeFunction(capability);
|
|
470
|
+
if (!fn)
|
|
471
|
+
return fail();
|
|
472
|
+
const payloadJson = safeStringify(payload);
|
|
473
|
+
const contextJson = safeStringify(context);
|
|
474
|
+
if (!payloadJson || !contextJson)
|
|
475
|
+
return fail("json stringify failed");
|
|
476
|
+
try {
|
|
477
|
+
const raw = fn(payloadJson, contextJson);
|
|
478
|
+
if (typeof raw !== "string" || !raw)
|
|
479
|
+
return fail("empty result");
|
|
480
|
+
const parsed = parseRecord(raw);
|
|
481
|
+
return parsed ?? fail("invalid payload");
|
|
482
|
+
}
|
|
483
|
+
catch (error) {
|
|
484
|
+
const reason = error instanceof Error ? error.message : String(error ?? "unknown");
|
|
485
|
+
return fail(reason);
|
|
486
|
+
}
|
|
487
|
+
}
|
|
488
|
+
export function runGeminiOpenAIRequestCodecWithNative(payload, options) {
|
|
489
|
+
const capability = "runGeminiOpenaiRequestCodecJson";
|
|
490
|
+
const fail = (reason) => failNativeRequired(capability, reason);
|
|
491
|
+
if (isNativeDisabledByEnv())
|
|
492
|
+
return fail("native disabled");
|
|
493
|
+
const fn = readNativeFunction(capability);
|
|
494
|
+
if (!fn)
|
|
495
|
+
return fail();
|
|
496
|
+
const payloadJson = safeStringify(payload);
|
|
497
|
+
const optionsJson = options ? safeStringify(options) : "{}";
|
|
498
|
+
if (!payloadJson || !optionsJson)
|
|
499
|
+
return fail("json stringify failed");
|
|
500
|
+
try {
|
|
501
|
+
const raw = fn(payloadJson, optionsJson);
|
|
502
|
+
if (typeof raw !== "string" || !raw)
|
|
503
|
+
return fail("empty result");
|
|
504
|
+
const parsed = parseRecord(raw);
|
|
505
|
+
return parsed ?? fail("invalid payload");
|
|
506
|
+
}
|
|
507
|
+
catch (error) {
|
|
508
|
+
const reason = error instanceof Error ? error.message : String(error ?? "unknown");
|
|
509
|
+
return fail(reason);
|
|
510
|
+
}
|
|
511
|
+
}
|
|
512
|
+
export function runGeminiOpenAIResponseCodecWithNative(payload, options) {
|
|
513
|
+
const capability = "runGeminiOpenaiResponseCodecJson";
|
|
514
|
+
const fail = (reason) => failNativeRequired(capability, reason);
|
|
515
|
+
if (isNativeDisabledByEnv())
|
|
516
|
+
return fail("native disabled");
|
|
517
|
+
const fn = readNativeFunction(capability);
|
|
518
|
+
if (!fn)
|
|
519
|
+
return fail();
|
|
520
|
+
const payloadJson = safeStringify(payload);
|
|
521
|
+
const optionsJson = options ? safeStringify(options) : "{}";
|
|
522
|
+
if (!payloadJson || !optionsJson)
|
|
523
|
+
return fail("json stringify failed");
|
|
524
|
+
try {
|
|
525
|
+
const raw = fn(payloadJson, optionsJson);
|
|
526
|
+
if (typeof raw !== "string" || !raw)
|
|
527
|
+
return fail("empty result");
|
|
528
|
+
const parsed = parseRecord(raw);
|
|
529
|
+
return parsed ?? fail("invalid payload");
|
|
530
|
+
}
|
|
531
|
+
catch (error) {
|
|
532
|
+
const reason = error instanceof Error ? error.message : String(error ?? "unknown");
|
|
533
|
+
return fail(reason);
|
|
534
|
+
}
|
|
535
|
+
}
|
|
536
|
+
export function runGeminiFromOpenAIChatCodecWithNative(payload, options) {
|
|
537
|
+
const capability = "runGeminiFromOpenaiChatCodecJson";
|
|
538
|
+
const fail = (reason) => failNativeRequired(capability, reason);
|
|
539
|
+
if (isNativeDisabledByEnv())
|
|
540
|
+
return fail("native disabled");
|
|
541
|
+
const fn = readNativeFunction(capability);
|
|
542
|
+
if (!fn)
|
|
543
|
+
return fail();
|
|
544
|
+
const payloadJson = safeStringify(payload);
|
|
545
|
+
const optionsJson = options ? safeStringify(options) : "{}";
|
|
546
|
+
if (!payloadJson || !optionsJson)
|
|
547
|
+
return fail("json stringify failed");
|
|
548
|
+
try {
|
|
549
|
+
const raw = fn(payloadJson, optionsJson);
|
|
550
|
+
if (typeof raw !== "string" || !raw)
|
|
551
|
+
return fail("empty result");
|
|
552
|
+
const parsed = parseRecord(raw);
|
|
553
|
+
return parsed ?? fail("invalid payload");
|
|
554
|
+
}
|
|
555
|
+
catch (error) {
|
|
556
|
+
const reason = error instanceof Error ? error.message : String(error ?? "unknown");
|
|
169
557
|
return fail(reason);
|
|
170
558
|
}
|
|
171
559
|
}
|