@jsonstudio/llms 0.6.467 → 0.6.473
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/compat/profiles/chat-gemini.json +14 -15
- package/dist/conversion/compat/profiles/chat-glm.json +194 -194
- package/dist/conversion/compat/profiles/chat-iflow.json +199 -199
- package/dist/conversion/compat/profiles/chat-lmstudio.json +43 -43
- package/dist/conversion/compat/profiles/chat-qwen.json +20 -20
- package/dist/conversion/compat/profiles/responses-c4m.json +42 -42
- package/dist/router/virtual-router/engine.js +18 -0
- package/dist/router/virtual-router/health-manager.d.ts +23 -0
- package/dist/router/virtual-router/health-manager.js +14 -0
- package/dist/router/virtual-router/routing-instructions.js +10 -0
- package/dist/router/virtual-router/types.d.ts +6 -0
- package/package.json +1 -1
|
@@ -1,17 +1,16 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
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
|
+
}
|
|
16
16
|
}
|
|
17
|
-
|
|
@@ -1,204 +1,204 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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
|
|
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"
|
|
40
11
|
},
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
"normalize": false,
|
|
44
|
-
"forceToolChoiceAuto": true
|
|
12
|
+
{
|
|
13
|
+
"action": "glm_image_content"
|
|
45
14
|
},
|
|
46
|
-
|
|
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"]
|
|
15
|
+
{
|
|
16
|
+
"action": "glm_vision_prompt"
|
|
63
17
|
},
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
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" }
|
|
104
119
|
]
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
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
|
|
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
|
+
}
|
|
145
131
|
},
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
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
|
+
}
|
|
150
172
|
},
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
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
|
+
]
|
|
168
195
|
},
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
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
|
-
}
|
|
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" }
|
|
194
202
|
]
|
|
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
|
-
}
|
|
203
|
+
}
|
|
204
204
|
}
|
|
@@ -1,208 +1,208 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
},
|
|
12
|
-
{
|
|
13
|
-
"action": "remove",
|
|
14
|
-
"path": "metadata.clientModelId"
|
|
15
|
-
},
|
|
16
|
-
{
|
|
17
|
-
"action": "remove",
|
|
18
|
-
"path": "metadata.providerHint"
|
|
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
|
-
"web_search"
|
|
39
|
-
],
|
|
40
|
-
"messages": {
|
|
41
|
-
"allowedRoles": ["system", "user", "assistant", "tool"],
|
|
42
|
-
"assistantWithToolCallsContentNull": true,
|
|
43
|
-
"toolContentStringify": false
|
|
2
|
+
"id": "chat:iflow",
|
|
3
|
+
"protocol": "openai-chat",
|
|
4
|
+
"request": {
|
|
5
|
+
"mappings": [
|
|
6
|
+
{ "action": "snapshot", "phase": "compat-pre" },
|
|
7
|
+
{ "action": "dto_unwrap" },
|
|
8
|
+
{
|
|
9
|
+
"action": "remove",
|
|
10
|
+
"path": "metadata.toolCallIdStyle"
|
|
44
11
|
},
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
"forceToolChoiceAuto": true
|
|
12
|
+
{
|
|
13
|
+
"action": "remove",
|
|
14
|
+
"path": "metadata.clientModelId"
|
|
49
15
|
},
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
"allowTopLevel": [
|
|
54
|
-
"id",
|
|
55
|
-
"request_id",
|
|
56
|
-
"created",
|
|
57
|
-
"model",
|
|
58
|
-
"choices",
|
|
59
|
-
"usage",
|
|
60
|
-
"video_result",
|
|
61
|
-
"web_search",
|
|
62
|
-
"content_filter",
|
|
63
|
-
"required_action",
|
|
64
|
-
"output",
|
|
65
|
-
"output_text",
|
|
66
|
-
"status"
|
|
67
|
-
],
|
|
68
|
-
"choices": {
|
|
69
|
-
"required": true,
|
|
70
|
-
"message": {
|
|
71
|
-
"allow": ["role", "content", "reasoning_content", "audio", "tool_calls"],
|
|
72
|
-
"roleDefault": "assistant",
|
|
73
|
-
"contentNullWhenToolCalls": true,
|
|
74
|
-
"tool_calls": { "function": { "nameRequired": true, "argumentsType": "string" } }
|
|
75
|
-
},
|
|
76
|
-
"finish_reason": ["stop", "tool_calls", "length", "sensitive", "network_error"]
|
|
16
|
+
{
|
|
17
|
+
"action": "remove",
|
|
18
|
+
"path": "metadata.providerHint"
|
|
77
19
|
},
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
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
|
+
"web_search"
|
|
39
|
+
],
|
|
40
|
+
"messages": {
|
|
41
|
+
"allowedRoles": ["system", "user", "assistant", "tool"],
|
|
42
|
+
"assistantWithToolCallsContentNull": true,
|
|
43
|
+
"toolContentStringify": false
|
|
44
|
+
},
|
|
45
|
+
"messagesRules": [],
|
|
46
|
+
"tools": {
|
|
47
|
+
"normalize": false,
|
|
48
|
+
"forceToolChoiceAuto": true
|
|
49
|
+
},
|
|
50
|
+
"assistantToolCalls": { "functionArgumentsType": "string" }
|
|
51
|
+
},
|
|
52
|
+
"response": {
|
|
53
|
+
"allowTopLevel": [
|
|
54
|
+
"id",
|
|
55
|
+
"request_id",
|
|
56
|
+
"created",
|
|
57
|
+
"model",
|
|
58
|
+
"choices",
|
|
59
|
+
"usage",
|
|
60
|
+
"video_result",
|
|
61
|
+
"web_search",
|
|
62
|
+
"content_filter",
|
|
63
|
+
"required_action",
|
|
64
|
+
"output",
|
|
65
|
+
"output_text",
|
|
66
|
+
"status"
|
|
67
|
+
],
|
|
68
|
+
"choices": {
|
|
69
|
+
"required": true,
|
|
70
|
+
"message": {
|
|
71
|
+
"allow": ["role", "content", "reasoning_content", "audio", "tool_calls"],
|
|
72
|
+
"roleDefault": "assistant",
|
|
73
|
+
"contentNullWhenToolCalls": true,
|
|
74
|
+
"tool_calls": { "function": { "nameRequired": true, "argumentsType": "string" } }
|
|
75
|
+
},
|
|
76
|
+
"finish_reason": ["stop", "tool_calls", "length", "sensitive", "network_error"]
|
|
77
|
+
},
|
|
78
|
+
"usage": {
|
|
79
|
+
"allow": ["prompt_tokens", "completion_tokens", "prompt_tokens_details", "total_tokens"]
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
},
|
|
84
|
+
{
|
|
85
|
+
"action": "field_map",
|
|
86
|
+
"direction": "incoming",
|
|
87
|
+
"config": [
|
|
88
|
+
{ "sourcePath": "usage.prompt_tokens", "targetPath": "usage.input_tokens", "type": "number" },
|
|
89
|
+
{ "sourcePath": "usage.completion_tokens", "targetPath": "usage.output_tokens", "type": "number" },
|
|
90
|
+
{ "sourcePath": "created", "targetPath": "created_at", "type": "number" },
|
|
91
|
+
{ "sourcePath": "request_id", "targetPath": "request_id", "type": "string" },
|
|
92
|
+
{
|
|
93
|
+
"sourcePath": "model",
|
|
94
|
+
"targetPath": "model",
|
|
95
|
+
"type": "string",
|
|
96
|
+
"transform": "normalizeModelName"
|
|
97
|
+
},
|
|
98
|
+
{
|
|
99
|
+
"sourcePath": "choices[*].message.tool_calls[*].function.arguments",
|
|
100
|
+
"targetPath": "choices[*].message.tool_calls[*].function.arguments",
|
|
101
|
+
"type": "string"
|
|
102
|
+
}
|
|
103
|
+
]
|
|
140
104
|
},
|
|
141
|
-
"
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
105
|
+
{ "action": "tool_schema_sanitize", "mode": "glm_shell" },
|
|
106
|
+
{
|
|
107
|
+
"action": "iflow_web_search_request"
|
|
108
|
+
},
|
|
109
|
+
{ "action": "snapshot", "phase": "compat-post" },
|
|
110
|
+
{ "action": "dto_rewrap" }
|
|
111
|
+
]
|
|
112
|
+
},
|
|
113
|
+
"response": {
|
|
114
|
+
"mappings": [
|
|
115
|
+
{ "action": "snapshot", "phase": "compat-pre" },
|
|
116
|
+
{ "action": "dto_unwrap" },
|
|
117
|
+
{
|
|
118
|
+
"action": "shape_filter",
|
|
119
|
+
"target": "response",
|
|
120
|
+
"config": {
|
|
121
|
+
"request": {
|
|
122
|
+
"allowTopLevel": [
|
|
123
|
+
"model",
|
|
124
|
+
"messages",
|
|
125
|
+
"stream",
|
|
126
|
+
"thinking",
|
|
127
|
+
"do_sample",
|
|
128
|
+
"temperature",
|
|
129
|
+
"top_p",
|
|
130
|
+
"max_tokens",
|
|
131
|
+
"tools",
|
|
132
|
+
"tool_choice",
|
|
133
|
+
"stop",
|
|
134
|
+
"response_format"
|
|
135
|
+
],
|
|
136
|
+
"messages": {
|
|
137
|
+
"allowedRoles": ["system", "user", "assistant", "tool"],
|
|
138
|
+
"assistantWithToolCallsContentNull": true,
|
|
139
|
+
"toolContentStringify": false
|
|
140
|
+
},
|
|
141
|
+
"messagesRules": [],
|
|
142
|
+
"tools": {
|
|
143
|
+
"normalize": false,
|
|
144
|
+
"forceToolChoiceAuto": true
|
|
145
|
+
},
|
|
146
|
+
"assistantToolCalls": { "functionArgumentsType": "string" }
|
|
147
|
+
},
|
|
148
|
+
"response": {
|
|
149
|
+
"allowTopLevel": [
|
|
150
|
+
"id",
|
|
151
|
+
"request_id",
|
|
152
|
+
"created",
|
|
153
|
+
"model",
|
|
154
|
+
"choices",
|
|
155
|
+
"usage",
|
|
156
|
+
"video_result",
|
|
157
|
+
"web_search",
|
|
158
|
+
"content_filter",
|
|
159
|
+
"required_action",
|
|
160
|
+
"output",
|
|
161
|
+
"output_text",
|
|
162
|
+
"status"
|
|
163
|
+
],
|
|
164
|
+
"choices": {
|
|
165
|
+
"required": true,
|
|
166
|
+
"message": {
|
|
167
|
+
"allow": ["role", "content", "reasoning_content", "audio", "tool_calls"],
|
|
168
|
+
"roleDefault": "assistant",
|
|
169
|
+
"contentNullWhenToolCalls": true,
|
|
170
|
+
"tool_calls": { "function": { "nameRequired": true, "argumentsType": "string" } }
|
|
171
|
+
},
|
|
172
|
+
"finish_reason": ["stop", "tool_calls", "length", "sensitive", "network_error"]
|
|
173
|
+
},
|
|
174
|
+
"usage": {
|
|
175
|
+
"allow": ["prompt_tokens", "completion_tokens", "prompt_tokens_details", "total_tokens"]
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
}
|
|
145
179
|
},
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
"roleDefault": "assistant",
|
|
169
|
-
"contentNullWhenToolCalls": true,
|
|
170
|
-
"tool_calls": { "function": { "nameRequired": true, "argumentsType": "string" } }
|
|
171
|
-
},
|
|
172
|
-
"finish_reason": ["stop", "tool_calls", "length", "sensitive", "network_error"]
|
|
180
|
+
{
|
|
181
|
+
"action": "field_map",
|
|
182
|
+
"direction": "outgoing",
|
|
183
|
+
"config": [
|
|
184
|
+
{ "sourcePath": "usage.input_tokens", "targetPath": "usage.prompt_tokens", "type": "number" },
|
|
185
|
+
{ "sourcePath": "usage.output_tokens", "targetPath": "usage.completion_tokens", "type": "number" },
|
|
186
|
+
{ "sourcePath": "usage.total_input_tokens", "targetPath": "usage.prompt_tokens", "type": "number" },
|
|
187
|
+
{ "sourcePath": "usage.total_output_tokens", "targetPath": "usage.completion_tokens", "type": "number" },
|
|
188
|
+
{ "sourcePath": "created_at", "targetPath": "created", "type": "number" },
|
|
189
|
+
{ "sourcePath": "request_id", "targetPath": "request_id", "type": "string" },
|
|
190
|
+
{
|
|
191
|
+
"sourcePath": "choices[*].finish_reason",
|
|
192
|
+
"targetPath": "choices[*].finish_reason",
|
|
193
|
+
"type": "string",
|
|
194
|
+
"transform": "normalizeFinishReason"
|
|
195
|
+
},
|
|
196
|
+
{
|
|
197
|
+
"sourcePath": "choices[*].message.tool_calls[*].function.arguments",
|
|
198
|
+
"targetPath": "choices[*].message.tool_calls[*].function.arguments",
|
|
199
|
+
"type": "string"
|
|
200
|
+
}
|
|
201
|
+
]
|
|
173
202
|
},
|
|
174
|
-
"
|
|
175
|
-
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
},
|
|
180
|
-
{
|
|
181
|
-
"action": "field_map",
|
|
182
|
-
"direction": "outgoing",
|
|
183
|
-
"config": [
|
|
184
|
-
{ "sourcePath": "usage.input_tokens", "targetPath": "usage.prompt_tokens", "type": "number" },
|
|
185
|
-
{ "sourcePath": "usage.output_tokens", "targetPath": "usage.completion_tokens", "type": "number" },
|
|
186
|
-
{ "sourcePath": "usage.total_input_tokens", "targetPath": "usage.prompt_tokens", "type": "number" },
|
|
187
|
-
{ "sourcePath": "usage.total_output_tokens", "targetPath": "usage.completion_tokens", "type": "number" },
|
|
188
|
-
{ "sourcePath": "created_at", "targetPath": "created", "type": "number" },
|
|
189
|
-
{ "sourcePath": "request_id", "targetPath": "request_id", "type": "string" },
|
|
190
|
-
{
|
|
191
|
-
"sourcePath": "choices[*].finish_reason",
|
|
192
|
-
"targetPath": "choices[*].finish_reason",
|
|
193
|
-
"type": "string",
|
|
194
|
-
"transform": "normalizeFinishReason"
|
|
195
|
-
},
|
|
196
|
-
{
|
|
197
|
-
"sourcePath": "choices[*].message.tool_calls[*].function.arguments",
|
|
198
|
-
"targetPath": "choices[*].message.tool_calls[*].function.arguments",
|
|
199
|
-
"type": "string"
|
|
200
|
-
}
|
|
203
|
+
{ "action": "tool_schema_sanitize", "mode": "glm_shell" },
|
|
204
|
+
{ "action": "snapshot", "phase": "compat-post" },
|
|
205
|
+
{ "action": "dto_rewrap" }
|
|
201
206
|
]
|
|
202
|
-
|
|
203
|
-
{ "action": "tool_schema_sanitize", "mode": "glm_shell" },
|
|
204
|
-
{ "action": "snapshot", "phase": "compat-post" },
|
|
205
|
-
{ "action": "dto_rewrap" }
|
|
206
|
-
]
|
|
207
|
-
}
|
|
207
|
+
}
|
|
208
208
|
}
|
|
@@ -1,45 +1,45 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
2
|
+
"id": "chat:lmstudio",
|
|
3
|
+
"protocol": "openai-chat",
|
|
4
|
+
"request": {
|
|
5
|
+
"mappings": [
|
|
6
|
+
{ "action": "snapshot", "phase": "compat-pre" },
|
|
7
|
+
{ "action": "dto_unwrap" },
|
|
8
|
+
{
|
|
9
|
+
"action": "normalize_tool_choice",
|
|
10
|
+
"path": "tool_choice",
|
|
11
|
+
"objectReplacement": "required"
|
|
12
|
+
},
|
|
13
|
+
{ "action": "snapshot", "phase": "compat-post" },
|
|
14
|
+
{ "action": "dto_rewrap" }
|
|
15
|
+
]
|
|
16
|
+
},
|
|
17
|
+
"response": {
|
|
18
|
+
"mappings": [
|
|
19
|
+
{ "action": "snapshot", "phase": "compat-pre" },
|
|
20
|
+
{ "action": "dto_unwrap" },
|
|
21
|
+
{
|
|
22
|
+
"action": "set_default",
|
|
23
|
+
"path": "object",
|
|
24
|
+
"value": "chat.completion"
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
"action": "set_default",
|
|
28
|
+
"path": "id",
|
|
29
|
+
"valueSource": "chat_completion_id"
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
"action": "set_default",
|
|
33
|
+
"path": "created",
|
|
34
|
+
"valueSource": "timestamp_seconds"
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
"action": "set_default",
|
|
38
|
+
"path": "model",
|
|
39
|
+
"value": "unknown"
|
|
40
|
+
},
|
|
41
|
+
{ "action": "snapshot", "phase": "compat-post" },
|
|
42
|
+
{ "action": "dto_rewrap" }
|
|
43
|
+
]
|
|
44
|
+
}
|
|
45
45
|
}
|
|
@@ -1,22 +1,22 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
2
|
+
"id": "chat:qwen",
|
|
3
|
+
"protocol": "openai-chat",
|
|
4
|
+
"request": {
|
|
5
|
+
"mappings": [
|
|
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" }
|
|
20
|
+
]
|
|
21
|
+
}
|
|
22
22
|
}
|
|
@@ -1,45 +1,45 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
2
|
+
"id": "responses:c4m",
|
|
3
|
+
"protocol": "openai-responses",
|
|
4
|
+
"request": {
|
|
5
|
+
"mappings": [
|
|
6
|
+
{
|
|
7
|
+
"action": "remove",
|
|
8
|
+
"path": "max_tokens"
|
|
9
|
+
},
|
|
10
|
+
{
|
|
11
|
+
"action": "remove",
|
|
12
|
+
"path": "maxTokens"
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
"action": "remove",
|
|
16
|
+
"path": "max_output_tokens"
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
"action": "remove",
|
|
20
|
+
"path": "maxOutputTokens"
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
"action": "inject_instruction",
|
|
24
|
+
"sourcePath": "instructions",
|
|
25
|
+
"targetPath": "input",
|
|
26
|
+
"role": "system",
|
|
27
|
+
"contentType": "input_text",
|
|
28
|
+
"stripHtml": true,
|
|
29
|
+
"maxLengthEnv": [
|
|
30
|
+
"ROUTECODEX_C4M_INSTRUCTIONS_MAX",
|
|
31
|
+
"RCC_C4M_INSTRUCTIONS_MAX",
|
|
32
|
+
"ROUTECODEX_COMPAT_INSTRUCTIONS_MAX"
|
|
33
|
+
]
|
|
34
|
+
}
|
|
33
35
|
]
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
]
|
|
44
|
-
}
|
|
36
|
+
},
|
|
37
|
+
"response": {
|
|
38
|
+
"filters": [
|
|
39
|
+
{
|
|
40
|
+
"action": "rate_limit_text",
|
|
41
|
+
"needle": "The Codex-For.ME service is available, but you have reached the request limit"
|
|
42
|
+
}
|
|
43
|
+
]
|
|
44
|
+
}
|
|
45
45
|
}
|
|
@@ -135,6 +135,11 @@ export class VirtualRouterEngine {
|
|
|
135
135
|
if (event.fatal) {
|
|
136
136
|
this.healthManager.tripProvider(event.providerKey, event.reason, event.cooldownOverrideMs);
|
|
137
137
|
}
|
|
138
|
+
else if (event.reason === 'rate_limit' && event.statusCode === 429) {
|
|
139
|
+
// 对可恢复的 429 错误使用短冷静期:在 cooldownMs 内将该 key 标记为不可用,
|
|
140
|
+
// 以便 Virtual Router 在随后的选路中优先尝试其他 key 或模型。
|
|
141
|
+
this.healthManager.cooldownProvider(event.providerKey, event.reason, event.cooldownOverrideMs);
|
|
142
|
+
}
|
|
138
143
|
else {
|
|
139
144
|
this.healthManager.recordFailure(event.providerKey, event.reason);
|
|
140
145
|
}
|
|
@@ -284,6 +289,19 @@ export class VirtualRouterEngine {
|
|
|
284
289
|
}
|
|
285
290
|
trySelectFromTier(routeName, tier, stickyKey, estimatedTokens, features, disabledProviders, disabledKeysMap, allowedProviders, disabledModels, requiredProviderKeys, allowAliasRotation) {
|
|
286
291
|
let targets = Array.isArray(tier.targets) ? tier.targets : [];
|
|
292
|
+
// 基于本次请求 metadata 中的 excludedProviderKeys 做临时过滤:
|
|
293
|
+
// - 这些 key 仅在当前 route() 调用内被排除,不会写入 sticky 状态;
|
|
294
|
+
// - 主要用于 HTTP 层在同一请求内对 429 失败的 key 进行快速 failover。
|
|
295
|
+
const excludedRaw = features.metadata?.excludedProviderKeys &&
|
|
296
|
+
Array.isArray(features.metadata.excludedProviderKeys)
|
|
297
|
+
? features.metadata.excludedProviderKeys
|
|
298
|
+
: [];
|
|
299
|
+
const excludedKeys = new Set(excludedRaw
|
|
300
|
+
.map((val) => (typeof val === 'string' ? val.trim() : ''))
|
|
301
|
+
.filter((val) => Boolean(val)));
|
|
302
|
+
if (excludedKeys.size > 0) {
|
|
303
|
+
targets = targets.filter((key) => !excludedKeys.has(key));
|
|
304
|
+
}
|
|
287
305
|
if (allowedProviders && allowedProviders.size > 0) {
|
|
288
306
|
targets = targets.filter(key => {
|
|
289
307
|
const providerId = this.extractProviderId(key);
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { ProviderHealthConfig, ProviderHealthState } from './types.js';
|
|
2
|
+
interface ProviderInternalState extends ProviderHealthState {
|
|
3
|
+
lastFailureAt?: number;
|
|
4
|
+
}
|
|
5
|
+
export declare class ProviderHealthManager {
|
|
6
|
+
private readonly states;
|
|
7
|
+
private config;
|
|
8
|
+
configure(config?: ProviderHealthConfig): void;
|
|
9
|
+
registerProviders(providerKeys: string[]): void;
|
|
10
|
+
recordFailure(providerKey: string, reason?: string): ProviderInternalState;
|
|
11
|
+
/**
|
|
12
|
+
* 为可恢复错误(例如 429)提供短暂冷静期:在 cooldownMs 内将 providerKey
|
|
13
|
+
* 视为不可用,但不使用 fatalCooldownMs 的长熔断时间。
|
|
14
|
+
*/
|
|
15
|
+
cooldownProvider(providerKey: string, reason?: string, overrideMs?: number): ProviderInternalState;
|
|
16
|
+
recordSuccess(providerKey: string): ProviderInternalState;
|
|
17
|
+
tripProvider(providerKey: string, reason?: string, cooldownOverrideMs?: number): ProviderInternalState;
|
|
18
|
+
isAvailable(providerKey: string): boolean;
|
|
19
|
+
getSnapshot(): ProviderHealthState[];
|
|
20
|
+
getConfig(): Required<ProviderHealthConfig>;
|
|
21
|
+
private getState;
|
|
22
|
+
}
|
|
23
|
+
export {};
|
|
@@ -39,6 +39,20 @@ export class ProviderHealthManager {
|
|
|
39
39
|
// 只有显式 fatal 或 tripProvider 调用时才会进入 tripped 状态。
|
|
40
40
|
return state;
|
|
41
41
|
}
|
|
42
|
+
/**
|
|
43
|
+
* 为可恢复错误(例如 429)提供短暂冷静期:在 cooldownMs 内将 providerKey
|
|
44
|
+
* 视为不可用,但不使用 fatalCooldownMs 的长熔断时间。
|
|
45
|
+
*/
|
|
46
|
+
cooldownProvider(providerKey, reason, overrideMs) {
|
|
47
|
+
const state = this.getState(providerKey);
|
|
48
|
+
state.failureCount += 1;
|
|
49
|
+
state.state = 'tripped';
|
|
50
|
+
state.reason = reason;
|
|
51
|
+
const ttl = overrideMs ?? this.config.cooldownMs;
|
|
52
|
+
state.cooldownExpiresAt = Date.now() + ttl;
|
|
53
|
+
state.lastFailureAt = Date.now();
|
|
54
|
+
return state;
|
|
55
|
+
}
|
|
42
56
|
recordSuccess(providerKey) {
|
|
43
57
|
const state = this.getState(providerKey);
|
|
44
58
|
state.failureCount = 0;
|
|
@@ -113,6 +113,16 @@ function parseSingleInstruction(instruction) {
|
|
|
113
113
|
return { type: 'force', ...normalized };
|
|
114
114
|
}
|
|
115
115
|
}
|
|
116
|
+
else if (isValidIdentifier(instruction)) {
|
|
117
|
+
// 仅 provider 标识(无 .)时,视为 provider 级白名单,等价于 "<**!provider**>"。
|
|
118
|
+
// 这样可以用 "<**antigravity**>" 快速激活当前 routing 中所有 antigravity 相关池子,
|
|
119
|
+
// 并保证路由仅命中该 provider 的所有模型/key。
|
|
120
|
+
return {
|
|
121
|
+
type: 'allow',
|
|
122
|
+
provider: instruction,
|
|
123
|
+
pathLength: 1
|
|
124
|
+
};
|
|
125
|
+
}
|
|
116
126
|
return null;
|
|
117
127
|
}
|
|
118
128
|
function parseTarget(target) {
|
|
@@ -200,6 +200,12 @@ export interface RouterMetadataInput {
|
|
|
200
200
|
* 禁用的 provider keyIndex 列表 (从 1 开始)
|
|
201
201
|
*/
|
|
202
202
|
disabledProviderKeyIndexes?: number[];
|
|
203
|
+
/**
|
|
204
|
+
* 本次请求内需要临时排除的 providerKey 列表。
|
|
205
|
+
* 与 disabledProviders/disabledKeys 不同,这些 key 仅对当前路由决策生效,
|
|
206
|
+
* 不会写入或持久化到 RoutingInstructionState/sticky 存储中。
|
|
207
|
+
*/
|
|
208
|
+
excludedProviderKeys?: string[];
|
|
203
209
|
sessionId?: string;
|
|
204
210
|
conversationId?: string;
|
|
205
211
|
responsesResume?: {
|