@jsonstudio/llms 0.6.473 → 0.6.567

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.
Files changed (47) hide show
  1. package/dist/conversion/compat/actions/claude-thinking-tools.d.ts +15 -0
  2. package/dist/conversion/compat/actions/claude-thinking-tools.js +72 -0
  3. package/dist/conversion/compat/profiles/chat-gemini.json +15 -14
  4. package/dist/conversion/compat/profiles/chat-glm.json +194 -194
  5. package/dist/conversion/compat/profiles/chat-iflow.json +199 -199
  6. package/dist/conversion/compat/profiles/chat-lmstudio.json +43 -43
  7. package/dist/conversion/compat/profiles/chat-qwen.json +20 -20
  8. package/dist/conversion/compat/profiles/responses-c4m.json +42 -42
  9. package/dist/conversion/compat/profiles/responses-output2choices-test.json +12 -0
  10. package/dist/conversion/hub/pipeline/compat/compat-pipeline-executor.js +6 -0
  11. package/dist/conversion/hub/pipeline/compat/compat-types.d.ts +2 -0
  12. package/dist/conversion/hub/pipeline/hub-pipeline.js +15 -0
  13. package/dist/conversion/hub/pipeline/stages/req_inbound/req_inbound_stage3_context_capture/index.js +15 -0
  14. package/dist/conversion/hub/process/chat-process.js +44 -17
  15. package/dist/conversion/hub/semantic-mappers/anthropic-mapper.js +8 -0
  16. package/dist/conversion/hub/semantic-mappers/gemini-mapper.js +13 -8
  17. package/dist/conversion/hub/tool-session-compat.d.ts +26 -0
  18. package/dist/conversion/hub/tool-session-compat.js +299 -0
  19. package/dist/conversion/responses/responses-openai-bridge.d.ts +0 -1
  20. package/dist/conversion/responses/responses-openai-bridge.js +0 -71
  21. package/dist/conversion/shared/gemini-tool-utils.js +8 -0
  22. package/dist/conversion/shared/responses-output-builder.js +6 -68
  23. package/dist/conversion/shared/tool-governor.js +75 -4
  24. package/dist/conversion/shared/tool-mapping.js +14 -8
  25. package/dist/filters/special/request-toolcalls-stringify.js +5 -55
  26. package/dist/filters/special/request-tools-normalize.js +0 -19
  27. package/dist/guidance/index.js +25 -9
  28. package/dist/router/virtual-router/engine-health.d.ts +11 -0
  29. package/dist/router/virtual-router/engine-health.js +210 -0
  30. package/dist/router/virtual-router/engine-logging.d.ts +19 -0
  31. package/dist/router/virtual-router/engine-logging.js +165 -0
  32. package/dist/router/virtual-router/engine-selection.d.ts +32 -0
  33. package/dist/router/virtual-router/engine-selection.js +649 -0
  34. package/dist/router/virtual-router/engine.d.ts +4 -13
  35. package/dist/router/virtual-router/engine.js +64 -535
  36. package/dist/router/virtual-router/message-utils.js +22 -0
  37. package/dist/router/virtual-router/routing-instructions.d.ts +6 -1
  38. package/dist/router/virtual-router/routing-instructions.js +119 -3
  39. package/dist/servertool/handlers/gemini-empty-reply-continue.d.ts +1 -0
  40. package/dist/servertool/handlers/gemini-empty-reply-continue.js +120 -0
  41. package/dist/servertool/handlers/stop-message-auto.d.ts +1 -0
  42. package/dist/servertool/handlers/stop-message-auto.js +147 -0
  43. package/dist/servertool/handlers/vision.js +105 -7
  44. package/dist/servertool/server-side-tools.d.ts +2 -0
  45. package/dist/servertool/server-side-tools.js +2 -0
  46. package/dist/tools/tool-registry.js +195 -4
  47. package/package.json +1 -1
@@ -0,0 +1,15 @@
1
+ import type { JsonObject } from '../../hub/types/json.js';
2
+ import type { AdapterContext } from '../../hub/types/chat-envelope.js';
3
+ /**
4
+ * Compat for Claude models routed via antigravity on gemini-chat.
5
+ *
6
+ * Anthropic requires tools[*].custom.input_schema to be valid JSON Schema draft 2020-12.
7
+ * We currently send OpenAI-style parameters which may not fully conform, causing upstream
8
+ * invalid_request_error on tools.N.custom.input_schema.
9
+ *
10
+ * For safety, when we detect the antigravity.*.claude-* path over gemini-chat,
11
+ * we aggressively simplify Gemini functionDeclarations[*].parameters to a minimal
12
+ * but valid object schema, letting RouteCodex govern tool semantics while keeping
13
+ * Anthropic's schema validator happy.
14
+ */
15
+ export declare function applyClaudeThinkingToolSchemaCompat(payload: JsonObject, adapterContext?: AdapterContext): JsonObject;
@@ -0,0 +1,72 @@
1
+ const isRecord = (value) => typeof value === 'object' && value !== null && !Array.isArray(value);
2
+ /**
3
+ * Compat for Claude models routed via antigravity on gemini-chat.
4
+ *
5
+ * Anthropic requires tools[*].custom.input_schema to be valid JSON Schema draft 2020-12.
6
+ * We currently send OpenAI-style parameters which may not fully conform, causing upstream
7
+ * invalid_request_error on tools.N.custom.input_schema.
8
+ *
9
+ * For safety, when we detect the antigravity.*.claude-* path over gemini-chat,
10
+ * we aggressively simplify Gemini functionDeclarations[*].parameters to a minimal
11
+ * but valid object schema, letting RouteCodex govern tool semantics while keeping
12
+ * Anthropic's schema validator happy.
13
+ */
14
+ export function applyClaudeThinkingToolSchemaCompat(payload, adapterContext) {
15
+ const modelRaw = payload.model;
16
+ const modelId = typeof modelRaw === 'string' ? modelRaw.trim() : '';
17
+ // Only apply on Claude models.
18
+ // Upstream Anthropic enforces strict JSON Schema 2020-12 on custom.input_schema for these models.
19
+ if (!modelId.startsWith('claude-')) {
20
+ return payload;
21
+ }
22
+ const root = structuredClone(payload);
23
+ // Support both shapes:
24
+ // - Provider envelope: { model, request: { tools, ... } }
25
+ // - Gemini mapper request: { model, tools, ... }
26
+ const requestNode = isRecord(root.request)
27
+ ? root.request
28
+ : root;
29
+ const toolsRaw = requestNode.tools;
30
+ if (!Array.isArray(toolsRaw)) {
31
+ return root;
32
+ }
33
+ const nextTools = [];
34
+ for (const entry of toolsRaw) {
35
+ if (!isRecord(entry)) {
36
+ nextTools.push(entry);
37
+ continue;
38
+ }
39
+ const decls = Array.isArray(entry.functionDeclarations)
40
+ ? entry.functionDeclarations
41
+ : undefined;
42
+ if (!decls || !decls.length) {
43
+ // Non functionDeclarations-based tools (e.g. googleSearch) are left as-is.
44
+ nextTools.push(entry);
45
+ continue;
46
+ }
47
+ const nextDecls = [];
48
+ for (const fn of decls) {
49
+ if (!isRecord(fn)) {
50
+ nextDecls.push(fn);
51
+ continue;
52
+ }
53
+ const fnCopy = { ...fn };
54
+ // Replace parameters with a minimal, always-valid object schema.
55
+ fnCopy.parameters = {
56
+ type: 'object',
57
+ properties: {},
58
+ additionalProperties: true
59
+ };
60
+ // Drop strict flag to avoid upstream schema incompatibilities.
61
+ if (Object.prototype.hasOwnProperty.call(fnCopy, 'strict')) {
62
+ delete fnCopy.strict;
63
+ }
64
+ nextDecls.push(fnCopy);
65
+ }
66
+ nextTools.push({
67
+ functionDeclarations: nextDecls
68
+ });
69
+ }
70
+ requestNode.tools = nextTools;
71
+ return root;
72
+ }
@@ -1,16 +1,17 @@
1
1
  {
2
- "id": "chat:gemini",
3
- "protocol": "gemini-chat",
4
- "request": {
5
- "mappings": [
6
- { "action": "snapshot", "phase": "compat-pre" },
7
- {
8
- "action": "gemini_web_search_request"
9
- },
10
- { "action": "snapshot", "phase": "compat-post" }
11
- ]
12
- },
13
- "response": {
14
- "mappings": []
15
- }
2
+ "id": "chat:gemini",
3
+ "protocol": "gemini-chat",
4
+ "request": {
5
+ "mappings": [
6
+ { "action": "snapshot", "phase": "compat-pre" },
7
+ { "action": "claude_thinking_tool_schema" },
8
+ {
9
+ "action": "gemini_web_search_request"
10
+ },
11
+ { "action": "snapshot", "phase": "compat-post" }
12
+ ]
13
+ },
14
+ "response": {
15
+ "mappings": []
16
+ }
16
17
  }
@@ -1,204 +1,204 @@
1
1
  {
2
- "id": "chat:glm",
3
- "protocol": "openai-chat",
4
- "request": {
5
- "mappings": [
6
- { "action": "snapshot", "phase": "compat-pre" },
7
- { "action": "dto_unwrap" },
8
- {
9
- "action": "remove",
10
- "path": "parallel_tool_calls"
2
+ "id": "chat:glm",
3
+ "protocol": "openai-chat",
4
+ "request": {
5
+ "mappings": [
6
+ { "action": "snapshot", "phase": "compat-pre" },
7
+ { "action": "dto_unwrap" },
8
+ {
9
+ "action": "remove",
10
+ "path": "parallel_tool_calls"
11
+ },
12
+ {
13
+ "action": "glm_image_content"
14
+ },
15
+ {
16
+ "action": "glm_vision_prompt"
17
+ },
18
+ {
19
+ "action": "rename",
20
+ "from": "response_format",
21
+ "to": "metadata.generation.response_format"
22
+ },
23
+ {
24
+ "action": "remove",
25
+ "path": "metadata.clientModelId"
26
+ },
27
+ {
28
+ "action": "shape_filter",
29
+ "target": "request",
30
+ "config": {
31
+ "request": {
32
+ "allowTopLevel": [
33
+ "model", "messages", "stream", "thinking", "do_sample", "temperature", "top_p",
34
+ "max_tokens", "tools", "tool_choice", "stop", "response_format", "web_search"
35
+ ],
36
+ "messages": {
37
+ "allowedRoles": ["system", "user", "assistant", "tool"],
38
+ "assistantWithToolCallsContentNull": true,
39
+ "toolContentStringify": false
11
40
  },
12
- {
13
- "action": "glm_image_content"
41
+ "messagesRules": [],
42
+ "tools": {
43
+ "normalize": false,
44
+ "forceToolChoiceAuto": true
14
45
  },
15
- {
16
- "action": "glm_vision_prompt"
46
+ "assistantToolCalls": { "functionArgumentsType": "string" }
47
+ },
48
+ "response": {
49
+ "allowTopLevel": [
50
+ "id", "request_id", "created", "model",
51
+ "choices", "usage", "video_result", "web_search", "content_filter",
52
+ "required_action", "output", "output_text", "status"
53
+ ],
54
+ "choices": {
55
+ "required": true,
56
+ "message": {
57
+ "allow": ["role", "content", "reasoning_content", "audio", "tool_calls"],
58
+ "roleDefault": "assistant",
59
+ "contentNullWhenToolCalls": true,
60
+ "tool_calls": { "function": { "nameRequired": true, "argumentsType": "string" } }
61
+ },
62
+ "finish_reason": ["stop", "tool_calls", "length", "sensitive", "network_error"]
17
63
  },
18
- {
19
- "action": "rename",
20
- "from": "response_format",
21
- "to": "metadata.generation.response_format"
22
- },
23
- {
24
- "action": "remove",
25
- "path": "metadata.clientModelId"
26
- },
27
- {
28
- "action": "shape_filter",
29
- "target": "request",
30
- "config": {
31
- "request": {
32
- "allowTopLevel": [
33
- "model", "messages", "stream", "thinking", "do_sample", "temperature", "top_p",
34
- "max_tokens", "tools", "tool_choice", "stop", "response_format", "web_search"
35
- ],
36
- "messages": {
37
- "allowedRoles": ["system", "user", "assistant", "tool"],
38
- "assistantWithToolCallsContentNull": true,
39
- "toolContentStringify": false
40
- },
41
- "messagesRules": [],
42
- "tools": {
43
- "normalize": false,
44
- "forceToolChoiceAuto": true
45
- },
46
- "assistantToolCalls": { "functionArgumentsType": "string" }
47
- },
48
- "response": {
49
- "allowTopLevel": [
50
- "id", "request_id", "created", "model",
51
- "choices", "usage", "video_result", "web_search", "content_filter",
52
- "required_action", "output", "output_text", "status"
53
- ],
54
- "choices": {
55
- "required": true,
56
- "message": {
57
- "allow": ["role", "content", "reasoning_content", "audio", "tool_calls"],
58
- "roleDefault": "assistant",
59
- "contentNullWhenToolCalls": true,
60
- "tool_calls": { "function": { "nameRequired": true, "argumentsType": "string" } }
61
- },
62
- "finish_reason": ["stop", "tool_calls", "length", "sensitive", "network_error"]
63
- },
64
- "usage": { "allow": ["prompt_tokens", "completion_tokens", "prompt_tokens_details", "total_tokens"] }
65
- }
66
- }
67
- },
68
- {
69
- "action": "apply_rules",
70
- "config": {
71
- "tools": {
72
- "function": {
73
- "removeKeys": ["strict", "json_schema"]
74
- }
75
- },
76
- "messages": {
77
- "assistantToolCalls": {
78
- "function": {
79
- "removeKeys": ["strict"]
80
- }
81
- }
82
- },
83
- "topLevel": {
84
- "conditional": [
85
- { "when": { "tools": "empty" }, "remove": ["tool_choice"] }
86
- ]
87
- }
88
- }
89
- },
90
- {
91
- "action": "field_map",
92
- "direction": "incoming",
93
- "config": [
94
- { "sourcePath": "usage.prompt_tokens", "targetPath": "usage.input_tokens", "type": "number" },
95
- { "sourcePath": "usage.completion_tokens", "targetPath": "usage.output_tokens", "type": "number" },
96
- { "sourcePath": "created", "targetPath": "created_at", "type": "number" },
97
- { "sourcePath": "request_id", "targetPath": "request_id", "type": "string" },
98
- { "sourcePath": "model", "targetPath": "model", "type": "string", "transform": "normalizeModelName" },
99
- {
100
- "sourcePath": "choices[*].message.tool_calls[*].function.arguments",
101
- "targetPath": "choices[*].message.tool_calls[*].function.arguments",
102
- "type": "string"
103
- }
104
- ]
105
- },
106
- { "action": "tool_schema_sanitize", "mode": "glm_shell" },
107
- {
108
- "action": "glm_web_search_request"
109
- },
110
- {
111
- "action": "auto_thinking",
112
- "config": {
113
- "modelPrefixes": ["glm-4.7", "glm-4.6", "glm-4.5", "glm-z1"],
114
- "excludePrefixes": ["glm-4.6v"]
115
- }
116
- },
117
- { "action": "snapshot", "phase": "compat-post" },
118
- { "action": "dto_rewrap" }
64
+ "usage": { "allow": ["prompt_tokens", "completion_tokens", "prompt_tokens_details", "total_tokens"] }
65
+ }
66
+ }
67
+ },
68
+ {
69
+ "action": "apply_rules",
70
+ "config": {
71
+ "tools": {
72
+ "function": {
73
+ "removeKeys": ["strict", "json_schema"]
74
+ }
75
+ },
76
+ "messages": {
77
+ "assistantToolCalls": {
78
+ "function": {
79
+ "removeKeys": ["strict"]
80
+ }
81
+ }
82
+ },
83
+ "topLevel": {
84
+ "conditional": [
85
+ { "when": { "tools": "empty" }, "remove": ["tool_choice"] }
86
+ ]
87
+ }
88
+ }
89
+ },
90
+ {
91
+ "action": "field_map",
92
+ "direction": "incoming",
93
+ "config": [
94
+ { "sourcePath": "usage.prompt_tokens", "targetPath": "usage.input_tokens", "type": "number" },
95
+ { "sourcePath": "usage.completion_tokens", "targetPath": "usage.output_tokens", "type": "number" },
96
+ { "sourcePath": "created", "targetPath": "created_at", "type": "number" },
97
+ { "sourcePath": "request_id", "targetPath": "request_id", "type": "string" },
98
+ { "sourcePath": "model", "targetPath": "model", "type": "string", "transform": "normalizeModelName" },
99
+ {
100
+ "sourcePath": "choices[*].message.tool_calls[*].function.arguments",
101
+ "targetPath": "choices[*].message.tool_calls[*].function.arguments",
102
+ "type": "string"
103
+ }
119
104
  ]
120
- },
121
- "response": {
122
- "mappings": [
123
- { "action": "snapshot", "phase": "compat-pre" },
124
- { "action": "dto_unwrap" },
125
- {
126
- "action": "resp_blacklist",
127
- "config": {
128
- "paths": ["usage.prompt_tokens_details.cached_tokens"],
129
- "keepCritical": true
130
- }
105
+ },
106
+ { "action": "tool_schema_sanitize", "mode": "glm_shell" },
107
+ {
108
+ "action": "glm_web_search_request"
109
+ },
110
+ {
111
+ "action": "auto_thinking",
112
+ "config": {
113
+ "modelPrefixes": ["glm-4.7", "glm-4.6", "glm-4.5", "glm-z1"],
114
+ "excludePrefixes": ["glm-4.6v"]
115
+ }
116
+ },
117
+ { "action": "snapshot", "phase": "compat-post" },
118
+ { "action": "dto_rewrap" }
119
+ ]
120
+ },
121
+ "response": {
122
+ "mappings": [
123
+ { "action": "snapshot", "phase": "compat-pre" },
124
+ { "action": "dto_unwrap" },
125
+ {
126
+ "action": "resp_blacklist",
127
+ "config": {
128
+ "paths": ["usage.prompt_tokens_details.cached_tokens"],
129
+ "keepCritical": true
130
+ }
131
+ },
132
+ {
133
+ "action": "shape_filter",
134
+ "target": "response",
135
+ "config": {
136
+ "request": {
137
+ "allowTopLevel": [
138
+ "model", "messages", "stream", "thinking", "do_sample", "temperature", "top_p",
139
+ "max_tokens", "tools", "tool_choice", "stop", "response_format"
140
+ ],
141
+ "messages": {
142
+ "allowedRoles": ["system", "user", "assistant", "tool"],
143
+ "assistantWithToolCallsContentNull": true,
144
+ "toolContentStringify": false
131
145
  },
132
- {
133
- "action": "shape_filter",
134
- "target": "response",
135
- "config": {
136
- "request": {
137
- "allowTopLevel": [
138
- "model", "messages", "stream", "thinking", "do_sample", "temperature", "top_p",
139
- "max_tokens", "tools", "tool_choice", "stop", "response_format"
140
- ],
141
- "messages": {
142
- "allowedRoles": ["system", "user", "assistant", "tool"],
143
- "assistantWithToolCallsContentNull": true,
144
- "toolContentStringify": false
145
- },
146
- "messagesRules": [],
147
- "tools": {
148
- "normalize": false,
149
- "forceToolChoiceAuto": true
150
- },
151
- "assistantToolCalls": { "functionArgumentsType": "string" }
152
- },
153
- "response": {
154
- "allowTopLevel": [
155
- "id", "request_id", "created", "model",
156
- "choices", "usage", "video_result", "web_search", "content_filter",
157
- "required_action", "output", "output_text", "status"
158
- ],
159
- "choices": {
160
- "required": true,
161
- "message": {
162
- "allow": ["role", "content", "reasoning_content", "audio", "tool_calls"],
163
- "roleDefault": "assistant",
164
- "contentNullWhenToolCalls": true,
165
- "tool_calls": { "function": { "nameRequired": true, "argumentsType": "string" } }
166
- },
167
- "finish_reason": ["stop", "tool_calls", "length", "sensitive", "network_error"]
168
- },
169
- "usage": { "allow": ["prompt_tokens", "completion_tokens", "prompt_tokens_details", "total_tokens"] }
170
- }
171
- }
146
+ "messagesRules": [],
147
+ "tools": {
148
+ "normalize": false,
149
+ "forceToolChoiceAuto": true
172
150
  },
173
- {
174
- "action": "field_map",
175
- "direction": "outgoing",
176
- "config": [
177
- { "sourcePath": "usage.input_tokens", "targetPath": "usage.prompt_tokens", "type": "number" },
178
- { "sourcePath": "usage.output_tokens", "targetPath": "usage.completion_tokens", "type": "number" },
179
- { "sourcePath": "usage.total_input_tokens", "targetPath": "usage.prompt_tokens", "type": "number" },
180
- { "sourcePath": "usage.total_output_tokens", "targetPath": "usage.completion_tokens", "type": "number" },
181
- { "sourcePath": "created_at", "targetPath": "created", "type": "number" },
182
- { "sourcePath": "request_id", "targetPath": "request_id", "type": "string" },
183
- {
184
- "sourcePath": "choices[*].finish_reason",
185
- "targetPath": "choices[*].finish_reason",
186
- "type": "string",
187
- "transform": "normalizeFinishReason"
188
- },
189
- {
190
- "sourcePath": "choices[*].message.tool_calls[*].function.arguments",
191
- "targetPath": "choices[*].message.tool_calls[*].function.arguments",
192
- "type": "string"
193
- }
194
- ]
151
+ "assistantToolCalls": { "functionArgumentsType": "string" }
152
+ },
153
+ "response": {
154
+ "allowTopLevel": [
155
+ "id", "request_id", "created", "model",
156
+ "choices", "usage", "video_result", "web_search", "content_filter",
157
+ "required_action", "output", "output_text", "status"
158
+ ],
159
+ "choices": {
160
+ "required": true,
161
+ "message": {
162
+ "allow": ["role", "content", "reasoning_content", "audio", "tool_calls"],
163
+ "roleDefault": "assistant",
164
+ "contentNullWhenToolCalls": true,
165
+ "tool_calls": { "function": { "nameRequired": true, "argumentsType": "string" } }
166
+ },
167
+ "finish_reason": ["stop", "tool_calls", "length", "sensitive", "network_error"]
195
168
  },
196
- { "action": "tool_schema_sanitize", "mode": "glm_shell" },
197
- { "action": "response_normalize" },
198
- { "action": "extract_glm_tool_markup" },
199
- { "action": "response_validate" },
200
- { "action": "snapshot", "phase": "compat-post" },
201
- { "action": "dto_rewrap" }
169
+ "usage": { "allow": ["prompt_tokens", "completion_tokens", "prompt_tokens_details", "total_tokens"] }
170
+ }
171
+ }
172
+ },
173
+ {
174
+ "action": "field_map",
175
+ "direction": "outgoing",
176
+ "config": [
177
+ { "sourcePath": "usage.input_tokens", "targetPath": "usage.prompt_tokens", "type": "number" },
178
+ { "sourcePath": "usage.output_tokens", "targetPath": "usage.completion_tokens", "type": "number" },
179
+ { "sourcePath": "usage.total_input_tokens", "targetPath": "usage.prompt_tokens", "type": "number" },
180
+ { "sourcePath": "usage.total_output_tokens", "targetPath": "usage.completion_tokens", "type": "number" },
181
+ { "sourcePath": "created_at", "targetPath": "created", "type": "number" },
182
+ { "sourcePath": "request_id", "targetPath": "request_id", "type": "string" },
183
+ {
184
+ "sourcePath": "choices[*].finish_reason",
185
+ "targetPath": "choices[*].finish_reason",
186
+ "type": "string",
187
+ "transform": "normalizeFinishReason"
188
+ },
189
+ {
190
+ "sourcePath": "choices[*].message.tool_calls[*].function.arguments",
191
+ "targetPath": "choices[*].message.tool_calls[*].function.arguments",
192
+ "type": "string"
193
+ }
202
194
  ]
203
- }
195
+ },
196
+ { "action": "tool_schema_sanitize", "mode": "glm_shell" },
197
+ { "action": "response_normalize" },
198
+ { "action": "extract_glm_tool_markup" },
199
+ { "action": "response_validate" },
200
+ { "action": "snapshot", "phase": "compat-post" },
201
+ { "action": "dto_rewrap" }
202
+ ]
203
+ }
204
204
  }