@jsonstudio/llms 0.6.3409 → 0.6.3541
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 +117 -855
- 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/native/router_hotpath_napi.node +0 -0
- package/dist/quota/quota-state.js +29 -7
- package/dist/quota/types.d.ts +1 -0
- package/dist/router/virtual-router/bootstrap/routing-config.js +11 -3
- 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.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/servertool/handlers/followup-request-builder.js +12 -2
- 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,7 +1,16 @@
|
|
|
1
1
|
import type { ConversionCodec, ConversionContext, ConversionProfile } from '../types.js';
|
|
2
|
-
import {
|
|
3
|
-
export
|
|
4
|
-
|
|
2
|
+
import { buildAnthropicRequestFromOpenAIChat } from '../shared/anthropic-message-utils.js';
|
|
3
|
+
export declare function buildOpenAIChatFromAnthropic(payload: unknown, options?: {
|
|
4
|
+
includeToolCallIds?: boolean;
|
|
5
|
+
}): {
|
|
6
|
+
messages: unknown[];
|
|
7
|
+
} & Record<string, unknown>;
|
|
8
|
+
export declare function buildAnthropicFromOpenAIChat(payload: unknown, options?: {
|
|
9
|
+
toolNameMap?: Record<string, string>;
|
|
10
|
+
requestId?: string;
|
|
11
|
+
entryEndpoint?: string;
|
|
12
|
+
}): Record<string, unknown>;
|
|
13
|
+
export { buildAnthropicRequestFromOpenAIChat };
|
|
5
14
|
export declare class AnthropicOpenAIConversionCodec implements ConversionCodec {
|
|
6
15
|
private readonly _dependencies;
|
|
7
16
|
readonly id = "anthropic-openai";
|
|
@@ -1,8 +1,13 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import { buildAnthropicRequestFromOpenAIChat } from '../shared/anthropic-message-utils.js';
|
|
2
|
+
import { buildAnthropicFromOpenAIChatWithNative, buildOpenAIChatFromAnthropicWithNative } from '../../router/virtual-router/engine-selection/native-compat-action-semantics.js';
|
|
3
|
+
export function buildOpenAIChatFromAnthropic(payload, options) {
|
|
4
|
+
const result = buildOpenAIChatFromAnthropicWithNative((payload ?? {}), options);
|
|
5
|
+
return (result.request ?? {});
|
|
6
|
+
}
|
|
7
|
+
export function buildAnthropicFromOpenAIChat(payload, options) {
|
|
8
|
+
return buildAnthropicFromOpenAIChatWithNative((payload ?? {}), options);
|
|
9
|
+
}
|
|
10
|
+
export { buildAnthropicRequestFromOpenAIChat };
|
|
6
11
|
export class AnthropicOpenAIConversionCodec {
|
|
7
12
|
_dependencies;
|
|
8
13
|
id = 'anthropic-openai';
|
|
@@ -11,102 +16,37 @@ export class AnthropicOpenAIConversionCodec {
|
|
|
11
16
|
constructor(_dependencies) {
|
|
12
17
|
this._dependencies = _dependencies;
|
|
13
18
|
}
|
|
14
|
-
async initialize() {
|
|
19
|
+
async initialize() {
|
|
20
|
+
this.initialized = true;
|
|
21
|
+
}
|
|
15
22
|
async convertRequest(payload, _profile, context) {
|
|
16
|
-
if (!this.initialized)
|
|
23
|
+
if (!this.initialized)
|
|
17
24
|
await this.initialize();
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
const
|
|
22
|
-
|
|
23
|
-
|
|
25
|
+
const native = buildOpenAIChatFromAnthropicWithNative(payload ?? {}, {
|
|
26
|
+
includeToolCallIds: true
|
|
27
|
+
});
|
|
28
|
+
const request = native.request && typeof native.request === 'object'
|
|
29
|
+
? { ...native.request }
|
|
30
|
+
: {};
|
|
31
|
+
const aliasMap = native.anthropicToolNameMap && typeof native.anthropicToolNameMap === 'object'
|
|
32
|
+
? native.anthropicToolNameMap
|
|
33
|
+
: undefined;
|
|
34
|
+
if (aliasMap && Object.keys(aliasMap).length > 0) {
|
|
24
35
|
context.metadata = context.metadata ?? {};
|
|
25
36
|
context.metadata.anthropicToolNameMap = aliasMap;
|
|
26
37
|
}
|
|
27
|
-
|
|
28
|
-
try {
|
|
29
|
-
const normalizedTools = mapAnthropicToolsToChat(payload?.tools);
|
|
30
|
-
if (normalizedTools) {
|
|
31
|
-
out.tools = normalizedTools;
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
catch { /* keep tools undefined on failure */ }
|
|
35
|
-
if (Array.isArray(payload?.stop_sequences)) {
|
|
36
|
-
out.stop = payload.stop_sequences;
|
|
37
|
-
}
|
|
38
|
-
if (typeof payload?.temperature === 'number') {
|
|
39
|
-
out.temperature = payload.temperature;
|
|
40
|
-
}
|
|
41
|
-
if (typeof payload?.top_p === 'number') {
|
|
42
|
-
out.top_p = payload.top_p;
|
|
43
|
-
}
|
|
44
|
-
if (typeof payload?.max_tokens === 'number') {
|
|
45
|
-
out.max_tokens = payload.max_tokens;
|
|
46
|
-
}
|
|
47
|
-
// 不设置默认 tool_choice;统一由 Chat 后半段治理
|
|
48
|
-
// 统一流控:非流式由核心过滤器处理;此处不设置 stream
|
|
49
|
-
// 统一走 Chat 请求过滤链路,使 /v1/messages 与 /v1/chat 在工具治理上保持一致
|
|
50
|
-
const ctxForFilters = {
|
|
51
|
-
...context,
|
|
52
|
-
requestId: context.requestId ?? `req_${Date.now()}`,
|
|
53
|
-
entryEndpoint: context.entryEndpoint ?? context.endpoint,
|
|
54
|
-
endpoint: context.endpoint
|
|
55
|
-
};
|
|
56
|
-
return runStandardChatRequestFilters(out, _profile, ctxForFilters);
|
|
38
|
+
return request;
|
|
57
39
|
}
|
|
58
40
|
async convertResponse(payload, _profile, context) {
|
|
59
|
-
if (!this.initialized)
|
|
41
|
+
if (!this.initialized)
|
|
60
42
|
await this.initialize();
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
const dto = {
|
|
66
|
-
data: payload,
|
|
67
|
-
metadata: {
|
|
68
|
-
requestId: context.requestId ?? `req_${Date.now()}`,
|
|
69
|
-
pipelineId: context.metadata?.pipelineId ?? 'conversion-router',
|
|
70
|
-
processingTime: 0,
|
|
71
|
-
stages: []
|
|
72
|
-
}
|
|
73
|
-
};
|
|
74
|
-
const resCtxBase = {
|
|
75
|
-
requestId: context.requestId ?? dto.metadata.requestId,
|
|
76
|
-
model: undefined,
|
|
77
|
-
endpoint: context.entryEndpoint || context.endpoint,
|
|
78
|
-
profile: 'openai-chat',
|
|
79
|
-
debug: { emit: () => { } }
|
|
80
|
-
};
|
|
81
|
-
const engine = new FilterEngine();
|
|
82
|
-
engine.registerFilter(new ResponseToolTextCanonicalizeFilter());
|
|
83
|
-
engine.registerFilter(new ResponseToolArgumentsStringifyFilter());
|
|
84
|
-
engine.registerFilter(new ResponseFinishInvariantsFilter());
|
|
85
|
-
let staged = await engine.run('response_pre', dto.data, resCtxBase);
|
|
86
|
-
staged = await engine.run('response_map', staged, resCtxBase);
|
|
87
|
-
staged = await engine.run('response_post', staged, resCtxBase);
|
|
88
|
-
const governedChat = staged;
|
|
89
|
-
const aliasMap = coerceAliasMap(context.metadata?.anthropicToolNameMap);
|
|
90
|
-
return buildAnthropicFromOpenAIChat(governedChat, {
|
|
43
|
+
const aliasMap = context.metadata && typeof context.metadata === 'object'
|
|
44
|
+
? context.metadata.anthropicToolNameMap
|
|
45
|
+
: undefined;
|
|
46
|
+
return buildAnthropicFromOpenAIChatWithNative((payload ?? {}), {
|
|
91
47
|
toolNameMap: aliasMap,
|
|
92
|
-
requestId: context.requestId
|
|
48
|
+
requestId: context.requestId,
|
|
49
|
+
entryEndpoint: context.entryEndpoint ?? context.endpoint
|
|
93
50
|
});
|
|
94
51
|
}
|
|
95
52
|
}
|
|
96
|
-
function coerceAliasMap(candidate) {
|
|
97
|
-
if (!candidate || typeof candidate !== 'object' || Array.isArray(candidate)) {
|
|
98
|
-
return undefined;
|
|
99
|
-
}
|
|
100
|
-
let populated = false;
|
|
101
|
-
const map = {};
|
|
102
|
-
for (const [key, value] of Object.entries(candidate)) {
|
|
103
|
-
if (typeof key !== 'string' || typeof value !== 'string')
|
|
104
|
-
continue;
|
|
105
|
-
const trimmedKey = key.trim();
|
|
106
|
-
if (!trimmedKey.length)
|
|
107
|
-
continue;
|
|
108
|
-
map[trimmedKey] = value;
|
|
109
|
-
populated = true;
|
|
110
|
-
}
|
|
111
|
-
return populated ? map : undefined;
|
|
112
|
-
}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import type { ConversionCodec, ConversionContext, ConversionProfile } from '../types.js';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
export declare function
|
|
2
|
+
import type { JsonObject, JsonValue } from '../hub/types/json.js';
|
|
3
|
+
export declare function buildOpenAIChatFromGeminiRequest(payload: unknown): {
|
|
4
|
+
messages: JsonValue[];
|
|
5
|
+
} & JsonObject;
|
|
6
|
+
export declare function buildOpenAIChatFromGeminiResponse(payload: unknown): JsonObject;
|
|
7
|
+
export declare function buildGeminiFromOpenAIChat(chatResp: unknown): JsonObject;
|
|
7
8
|
export declare class GeminiOpenAIConversionCodec implements ConversionCodec {
|
|
8
9
|
private readonly _dependencies;
|
|
9
10
|
readonly id = "gemini-openai";
|