@jsonstudio/llms 0.6.141 → 0.6.187

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 (61) hide show
  1. package/dist/conversion/codecs/gemini-openai-codec.js +15 -1
  2. package/dist/conversion/compat/actions/auto-thinking.d.ts +6 -0
  3. package/dist/conversion/compat/actions/auto-thinking.js +25 -0
  4. package/dist/conversion/compat/actions/field-mapping.d.ts +14 -0
  5. package/dist/conversion/compat/actions/field-mapping.js +155 -0
  6. package/dist/conversion/compat/actions/qwen-transform.d.ts +3 -0
  7. package/dist/conversion/compat/actions/qwen-transform.js +209 -0
  8. package/dist/conversion/compat/actions/request-rules.d.ts +24 -0
  9. package/dist/conversion/compat/actions/request-rules.js +63 -0
  10. package/dist/conversion/compat/actions/response-blacklist.d.ts +14 -0
  11. package/dist/conversion/compat/actions/response-blacklist.js +85 -0
  12. package/dist/conversion/compat/actions/response-normalize.d.ts +5 -0
  13. package/dist/conversion/compat/actions/response-normalize.js +121 -0
  14. package/dist/conversion/compat/actions/response-validate.d.ts +5 -0
  15. package/dist/conversion/compat/actions/response-validate.js +76 -0
  16. package/dist/conversion/compat/actions/snapshot.d.ts +8 -0
  17. package/dist/conversion/compat/actions/snapshot.js +21 -0
  18. package/dist/conversion/compat/actions/tool-schema.d.ts +6 -0
  19. package/dist/conversion/compat/actions/tool-schema.js +91 -0
  20. package/dist/conversion/compat/actions/universal-shape-filter.d.ts +74 -0
  21. package/dist/conversion/compat/actions/universal-shape-filter.js +382 -0
  22. package/dist/conversion/compat/profiles/chat-glm.json +187 -13
  23. package/dist/conversion/compat/profiles/chat-iflow.json +177 -9
  24. package/dist/conversion/compat/profiles/chat-lmstudio.json +10 -2
  25. package/dist/conversion/compat/profiles/chat-qwen.json +14 -10
  26. package/dist/conversion/hub/pipeline/compat/compat-engine.d.ts +7 -2
  27. package/dist/conversion/hub/pipeline/compat/compat-engine.js +409 -5
  28. package/dist/conversion/hub/pipeline/compat/compat-types.d.ts +47 -0
  29. package/dist/conversion/hub/pipeline/hub-pipeline.d.ts +2 -0
  30. package/dist/conversion/hub/pipeline/hub-pipeline.js +35 -1
  31. package/dist/conversion/hub/pipeline/stages/req_outbound/req_outbound_stage3_compat/index.js +2 -2
  32. package/dist/conversion/hub/pipeline/target-utils.js +3 -0
  33. package/dist/conversion/hub/response/response-runtime.js +19 -2
  34. package/dist/conversion/responses/responses-host-policy.d.ts +6 -0
  35. package/dist/conversion/responses/responses-host-policy.js +14 -0
  36. package/dist/conversion/responses/responses-openai-bridge.js +51 -2
  37. package/dist/conversion/shared/anthropic-message-utils.js +6 -0
  38. package/dist/conversion/shared/responses-conversation-store.js +3 -26
  39. package/dist/conversion/shared/responses-reasoning-registry.d.ts +4 -0
  40. package/dist/conversion/shared/responses-reasoning-registry.js +62 -1
  41. package/dist/conversion/shared/responses-response-utils.js +23 -1
  42. package/dist/conversion/shared/tool-canonicalizer.d.ts +2 -0
  43. package/dist/conversion/shared/tool-filter-pipeline.js +11 -0
  44. package/dist/router/virtual-router/bootstrap.js +218 -39
  45. package/dist/router/virtual-router/classifier.js +19 -52
  46. package/dist/router/virtual-router/context-advisor.d.ts +21 -0
  47. package/dist/router/virtual-router/context-advisor.js +76 -0
  48. package/dist/router/virtual-router/engine.d.ts +11 -26
  49. package/dist/router/virtual-router/engine.js +191 -386
  50. package/dist/router/virtual-router/features.js +24 -621
  51. package/dist/router/virtual-router/health-manager.js +2 -7
  52. package/dist/router/virtual-router/message-utils.d.ts +7 -0
  53. package/dist/router/virtual-router/message-utils.js +66 -0
  54. package/dist/router/virtual-router/provider-registry.js +6 -2
  55. package/dist/router/virtual-router/token-estimator.d.ts +2 -0
  56. package/dist/router/virtual-router/token-estimator.js +16 -0
  57. package/dist/router/virtual-router/tool-signals.d.ts +13 -0
  58. package/dist/router/virtual-router/tool-signals.js +403 -0
  59. package/dist/router/virtual-router/types.d.ts +21 -7
  60. package/dist/router/virtual-router/types.js +1 -0
  61. package/package.json +2 -2
@@ -3,6 +3,8 @@
3
3
  "protocol": "openai-chat",
4
4
  "request": {
5
5
  "mappings": [
6
+ { "action": "snapshot", "phase": "compat-pre" },
7
+ { "action": "dto_unwrap" },
6
8
  {
7
9
  "action": "remove",
8
10
  "path": "metadata.toolCallIdStyle"
@@ -14,23 +16,189 @@
14
16
  {
15
17
  "action": "remove",
16
18
  "path": "metadata.providerHint"
17
- }
19
+ },
20
+ {
21
+ "action": "shape_filter",
22
+ "target": "request",
23
+ "config": {
24
+ "request": {
25
+ "allowTopLevel": [
26
+ "model",
27
+ "messages",
28
+ "stream",
29
+ "thinking",
30
+ "do_sample",
31
+ "temperature",
32
+ "top_p",
33
+ "max_tokens",
34
+ "tools",
35
+ "tool_choice",
36
+ "stop",
37
+ "response_format"
38
+ ],
39
+ "messages": {
40
+ "allowedRoles": ["system", "user", "assistant", "tool"],
41
+ "assistantWithToolCallsContentNull": true,
42
+ "toolContentStringify": false
43
+ },
44
+ "messagesRules": [],
45
+ "tools": {
46
+ "normalize": false,
47
+ "forceToolChoiceAuto": true
48
+ },
49
+ "assistantToolCalls": { "functionArgumentsType": "string" }
50
+ },
51
+ "response": {
52
+ "allowTopLevel": [
53
+ "id",
54
+ "request_id",
55
+ "created",
56
+ "model",
57
+ "choices",
58
+ "usage",
59
+ "video_result",
60
+ "web_search",
61
+ "content_filter",
62
+ "required_action",
63
+ "output",
64
+ "output_text",
65
+ "status"
66
+ ],
67
+ "choices": {
68
+ "required": true,
69
+ "message": {
70
+ "allow": ["role", "content", "reasoning_content", "audio", "tool_calls"],
71
+ "roleDefault": "assistant",
72
+ "contentNullWhenToolCalls": true,
73
+ "tool_calls": { "function": { "nameRequired": true, "argumentsType": "string" } }
74
+ },
75
+ "finish_reason": ["stop", "tool_calls", "length", "sensitive", "network_error"]
76
+ },
77
+ "usage": {
78
+ "allow": ["prompt_tokens", "completion_tokens", "prompt_tokens_details", "total_tokens"]
79
+ }
80
+ }
81
+ }
82
+ },
83
+ {
84
+ "action": "field_map",
85
+ "direction": "incoming",
86
+ "config": [
87
+ { "sourcePath": "usage.prompt_tokens", "targetPath": "usage.input_tokens", "type": "number" },
88
+ { "sourcePath": "usage.completion_tokens", "targetPath": "usage.output_tokens", "type": "number" },
89
+ { "sourcePath": "created", "targetPath": "created_at", "type": "number" },
90
+ { "sourcePath": "request_id", "targetPath": "request_id", "type": "string" },
91
+ {
92
+ "sourcePath": "model",
93
+ "targetPath": "model",
94
+ "type": "string",
95
+ "transform": "normalizeModelName"
96
+ },
97
+ {
98
+ "sourcePath": "choices[*].message.tool_calls[*].function.arguments",
99
+ "targetPath": "choices[*].message.tool_calls[*].function.arguments",
100
+ "type": "string"
101
+ }
102
+ ]
103
+ },
104
+ { "action": "tool_schema_sanitize", "mode": "glm_shell" },
105
+ { "action": "snapshot", "phase": "compat-post" },
106
+ { "action": "dto_rewrap" }
18
107
  ]
19
108
  },
20
109
  "response": {
21
110
  "mappings": [
111
+ { "action": "snapshot", "phase": "compat-pre" },
112
+ { "action": "dto_unwrap" },
22
113
  {
23
- "action": "rename",
24
- "from": "created_at",
25
- "to": "created"
114
+ "action": "shape_filter",
115
+ "target": "response",
116
+ "config": {
117
+ "request": {
118
+ "allowTopLevel": [
119
+ "model",
120
+ "messages",
121
+ "stream",
122
+ "thinking",
123
+ "do_sample",
124
+ "temperature",
125
+ "top_p",
126
+ "max_tokens",
127
+ "tools",
128
+ "tool_choice",
129
+ "stop",
130
+ "response_format"
131
+ ],
132
+ "messages": {
133
+ "allowedRoles": ["system", "user", "assistant", "tool"],
134
+ "assistantWithToolCallsContentNull": true,
135
+ "toolContentStringify": false
136
+ },
137
+ "messagesRules": [],
138
+ "tools": {
139
+ "normalize": false,
140
+ "forceToolChoiceAuto": true
141
+ },
142
+ "assistantToolCalls": { "functionArgumentsType": "string" }
143
+ },
144
+ "response": {
145
+ "allowTopLevel": [
146
+ "id",
147
+ "request_id",
148
+ "created",
149
+ "model",
150
+ "choices",
151
+ "usage",
152
+ "video_result",
153
+ "web_search",
154
+ "content_filter",
155
+ "required_action",
156
+ "output",
157
+ "output_text",
158
+ "status"
159
+ ],
160
+ "choices": {
161
+ "required": true,
162
+ "message": {
163
+ "allow": ["role", "content", "reasoning_content", "audio", "tool_calls"],
164
+ "roleDefault": "assistant",
165
+ "contentNullWhenToolCalls": true,
166
+ "tool_calls": { "function": { "nameRequired": true, "argumentsType": "string" } }
167
+ },
168
+ "finish_reason": ["stop", "tool_calls", "length", "sensitive", "network_error"]
169
+ },
170
+ "usage": {
171
+ "allow": ["prompt_tokens", "completion_tokens", "prompt_tokens_details", "total_tokens"]
172
+ }
173
+ }
174
+ }
26
175
  },
27
176
  {
28
- "action": "convert_responses_output_to_choices"
177
+ "action": "field_map",
178
+ "direction": "outgoing",
179
+ "config": [
180
+ { "sourcePath": "usage.input_tokens", "targetPath": "usage.prompt_tokens", "type": "number" },
181
+ { "sourcePath": "usage.output_tokens", "targetPath": "usage.completion_tokens", "type": "number" },
182
+ { "sourcePath": "usage.total_input_tokens", "targetPath": "usage.prompt_tokens", "type": "number" },
183
+ { "sourcePath": "usage.total_output_tokens", "targetPath": "usage.completion_tokens", "type": "number" },
184
+ { "sourcePath": "created_at", "targetPath": "created", "type": "number" },
185
+ { "sourcePath": "request_id", "targetPath": "request_id", "type": "string" },
186
+ {
187
+ "sourcePath": "choices[*].finish_reason",
188
+ "targetPath": "choices[*].finish_reason",
189
+ "type": "string",
190
+ "transform": "normalizeFinishReason"
191
+ },
192
+ {
193
+ "sourcePath": "choices[*].message.tool_calls[*].function.arguments",
194
+ "targetPath": "choices[*].message.tool_calls[*].function.arguments",
195
+ "type": "string"
196
+ }
197
+ ]
29
198
  },
30
- {
31
- "action": "stringify",
32
- "path": "choices[*].message.tool_calls[*].function.arguments"
33
- }
199
+ { "action": "tool_schema_sanitize", "mode": "glm_shell" },
200
+ { "action": "snapshot", "phase": "compat-post" },
201
+ { "action": "dto_rewrap" }
34
202
  ]
35
203
  }
36
204
  }
@@ -3,15 +3,21 @@
3
3
  "protocol": "openai-chat",
4
4
  "request": {
5
5
  "mappings": [
6
+ { "action": "snapshot", "phase": "compat-pre" },
7
+ { "action": "dto_unwrap" },
6
8
  {
7
9
  "action": "normalize_tool_choice",
8
10
  "path": "tool_choice",
9
11
  "objectReplacement": "required"
10
- }
12
+ },
13
+ { "action": "snapshot", "phase": "compat-post" },
14
+ { "action": "dto_rewrap" }
11
15
  ]
12
16
  },
13
17
  "response": {
14
18
  "mappings": [
19
+ { "action": "snapshot", "phase": "compat-pre" },
20
+ { "action": "dto_unwrap" },
15
21
  {
16
22
  "action": "set_default",
17
23
  "path": "object",
@@ -31,7 +37,9 @@
31
37
  "action": "set_default",
32
38
  "path": "model",
33
39
  "value": "unknown"
34
- }
40
+ },
41
+ { "action": "snapshot", "phase": "compat-post" },
42
+ { "action": "dto_rewrap" }
35
43
  ]
36
44
  }
37
45
  }
@@ -3,16 +3,20 @@
3
3
  "protocol": "openai-chat",
4
4
  "request": {
5
5
  "mappings": [
6
- {
7
- "action": "parse_json",
8
- "path": "messages[*].tool_calls[*].function.arguments",
9
- "fallback": {}
10
- },
11
- {
12
- "action": "stringify",
13
- "path": "messages[*].tool_calls[*].function.arguments",
14
- "fallback": {}
15
- }
6
+ { "action": "snapshot", "phase": "compat-pre" },
7
+ { "action": "dto_unwrap" },
8
+ { "action": "qwen_request_transform" },
9
+ { "action": "snapshot", "phase": "compat-post" },
10
+ { "action": "dto_rewrap" }
11
+ ]
12
+ },
13
+ "response": {
14
+ "mappings": [
15
+ { "action": "snapshot", "phase": "compat-pre" },
16
+ { "action": "dto_unwrap" },
17
+ { "action": "qwen_response_transform" },
18
+ { "action": "snapshot", "phase": "compat-post" },
19
+ { "action": "dto_rewrap" }
16
20
  ]
17
21
  }
18
22
  }
@@ -1,4 +1,9 @@
1
1
  import type { JsonObject } from '../../types/json.js';
2
+ import type { AdapterContext } from '../../types/chat-envelope.js';
2
3
  import type { CompatApplicationResult } from './compat-types.js';
3
- export declare function applyRequestCompat(profileId: string | undefined, payload: JsonObject): CompatApplicationResult;
4
- export declare function applyResponseCompat(profileId: string | undefined, payload: JsonObject): CompatApplicationResult;
4
+ export declare function applyRequestCompat(profileId: string | undefined, payload: JsonObject, options?: {
5
+ adapterContext?: AdapterContext;
6
+ }): CompatApplicationResult;
7
+ export declare function applyResponseCompat(profileId: string | undefined, payload: JsonObject, options?: {
8
+ adapterContext?: AdapterContext;
9
+ }): CompatApplicationResult;