@jsonstudio/llms 0.6.187 → 0.6.198
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-glm.json +181 -181
- package/dist/conversion/compat/profiles/chat-iflow.json +195 -195
- 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/conversion/hub/pipeline/compat/compat-engine.js +20 -0
- package/dist/router/virtual-router/bootstrap.js +21 -0
- package/dist/router/virtual-router/token-file-scanner.d.ts +15 -0
- package/dist/router/virtual-router/token-file-scanner.js +56 -0
- package/package.json +1 -1
|
@@ -1,191 +1,191 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
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": "rename",
|
|
10
|
+
"from": "response_format",
|
|
11
|
+
"to": "metadata.generation.response_format"
|
|
12
|
+
},
|
|
13
|
+
{
|
|
14
|
+
"action": "remove",
|
|
15
|
+
"path": "metadata.clientModelId"
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
"action": "shape_filter",
|
|
19
|
+
"target": "request",
|
|
20
|
+
"config": {
|
|
21
|
+
"request": {
|
|
22
|
+
"allowTopLevel": [
|
|
23
|
+
"model", "messages", "stream", "thinking", "do_sample", "temperature", "top_p",
|
|
24
|
+
"max_tokens", "tools", "tool_choice", "stop", "response_format"
|
|
25
|
+
],
|
|
26
|
+
"messages": {
|
|
27
|
+
"allowedRoles": ["system", "user", "assistant", "tool"],
|
|
28
|
+
"assistantWithToolCallsContentNull": true,
|
|
29
|
+
"toolContentStringify": false
|
|
12
30
|
},
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
31
|
+
"messagesRules": [],
|
|
32
|
+
"tools": {
|
|
33
|
+
"normalize": false,
|
|
34
|
+
"forceToolChoiceAuto": true
|
|
16
35
|
},
|
|
17
|
-
{
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
"forceToolChoiceAuto": true
|
|
35
|
-
},
|
|
36
|
-
"assistantToolCalls": { "functionArgumentsType": "string" }
|
|
37
|
-
},
|
|
38
|
-
"response": {
|
|
39
|
-
"allowTopLevel": [
|
|
40
|
-
"id", "request_id", "created", "model",
|
|
41
|
-
"choices", "usage", "video_result", "web_search", "content_filter",
|
|
42
|
-
"required_action", "output", "output_text", "status"
|
|
43
|
-
],
|
|
44
|
-
"choices": {
|
|
45
|
-
"required": true,
|
|
46
|
-
"message": {
|
|
47
|
-
"allow": ["role", "content", "reasoning_content", "audio", "tool_calls"],
|
|
48
|
-
"roleDefault": "assistant",
|
|
49
|
-
"contentNullWhenToolCalls": true,
|
|
50
|
-
"tool_calls": { "function": { "nameRequired": true, "argumentsType": "string" } }
|
|
51
|
-
},
|
|
52
|
-
"finish_reason": ["stop", "tool_calls", "length", "sensitive", "network_error"]
|
|
53
|
-
},
|
|
54
|
-
"usage": { "allow": ["prompt_tokens", "completion_tokens", "prompt_tokens_details", "total_tokens"] }
|
|
55
|
-
}
|
|
56
|
-
}
|
|
36
|
+
"assistantToolCalls": { "functionArgumentsType": "string" }
|
|
37
|
+
},
|
|
38
|
+
"response": {
|
|
39
|
+
"allowTopLevel": [
|
|
40
|
+
"id", "request_id", "created", "model",
|
|
41
|
+
"choices", "usage", "video_result", "web_search", "content_filter",
|
|
42
|
+
"required_action", "output", "output_text", "status"
|
|
43
|
+
],
|
|
44
|
+
"choices": {
|
|
45
|
+
"required": true,
|
|
46
|
+
"message": {
|
|
47
|
+
"allow": ["role", "content", "reasoning_content", "audio", "tool_calls"],
|
|
48
|
+
"roleDefault": "assistant",
|
|
49
|
+
"contentNullWhenToolCalls": true,
|
|
50
|
+
"tool_calls": { "function": { "nameRequired": true, "argumentsType": "string" } }
|
|
51
|
+
},
|
|
52
|
+
"finish_reason": ["stop", "tool_calls", "length", "sensitive", "network_error"]
|
|
57
53
|
},
|
|
58
|
-
{
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
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
|
-
"action": "auto_thinking",
|
|
99
|
-
"config": {
|
|
100
|
-
"modelPrefixes": ["glm-4.7", "glm-4.6", "glm-4.5", "glm-z1"],
|
|
101
|
-
"excludePrefixes": ["glm-4.6v"]
|
|
102
|
-
}
|
|
103
|
-
},
|
|
104
|
-
{ "action": "snapshot", "phase": "compat-post" },
|
|
105
|
-
{ "action": "dto_rewrap" }
|
|
54
|
+
"usage": { "allow": ["prompt_tokens", "completion_tokens", "prompt_tokens_details", "total_tokens"] }
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
"action": "apply_rules",
|
|
60
|
+
"config": {
|
|
61
|
+
"tools": {
|
|
62
|
+
"function": {
|
|
63
|
+
"removeKeys": ["strict", "json_schema"]
|
|
64
|
+
}
|
|
65
|
+
},
|
|
66
|
+
"messages": {
|
|
67
|
+
"assistantToolCalls": {
|
|
68
|
+
"function": {
|
|
69
|
+
"removeKeys": ["strict"]
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
},
|
|
73
|
+
"topLevel": {
|
|
74
|
+
"conditional": [
|
|
75
|
+
{ "when": { "tools": "empty" }, "remove": ["tool_choice"] }
|
|
76
|
+
]
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
},
|
|
80
|
+
{
|
|
81
|
+
"action": "field_map",
|
|
82
|
+
"direction": "incoming",
|
|
83
|
+
"config": [
|
|
84
|
+
{ "sourcePath": "usage.prompt_tokens", "targetPath": "usage.input_tokens", "type": "number" },
|
|
85
|
+
{ "sourcePath": "usage.completion_tokens", "targetPath": "usage.output_tokens", "type": "number" },
|
|
86
|
+
{ "sourcePath": "created", "targetPath": "created_at", "type": "number" },
|
|
87
|
+
{ "sourcePath": "request_id", "targetPath": "request_id", "type": "string" },
|
|
88
|
+
{ "sourcePath": "model", "targetPath": "model", "type": "string", "transform": "normalizeModelName" },
|
|
89
|
+
{
|
|
90
|
+
"sourcePath": "choices[*].message.tool_calls[*].function.arguments",
|
|
91
|
+
"targetPath": "choices[*].message.tool_calls[*].function.arguments",
|
|
92
|
+
"type": "string"
|
|
93
|
+
}
|
|
106
94
|
]
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
95
|
+
},
|
|
96
|
+
{ "action": "tool_schema_sanitize", "mode": "glm_shell" },
|
|
97
|
+
{
|
|
98
|
+
"action": "auto_thinking",
|
|
99
|
+
"config": {
|
|
100
|
+
"modelPrefixes": ["glm-4.7", "glm-4.6", "glm-4.5", "glm-z1"],
|
|
101
|
+
"excludePrefixes": ["glm-4.6v"]
|
|
102
|
+
}
|
|
103
|
+
},
|
|
104
|
+
{ "action": "snapshot", "phase": "compat-post" },
|
|
105
|
+
{ "action": "dto_rewrap" }
|
|
106
|
+
]
|
|
107
|
+
},
|
|
108
|
+
"response": {
|
|
109
|
+
"mappings": [
|
|
110
|
+
{ "action": "snapshot", "phase": "compat-pre" },
|
|
111
|
+
{ "action": "dto_unwrap" },
|
|
112
|
+
{
|
|
113
|
+
"action": "resp_blacklist",
|
|
114
|
+
"config": {
|
|
115
|
+
"paths": ["usage.prompt_tokens_details.cached_tokens"],
|
|
116
|
+
"keepCritical": true
|
|
117
|
+
}
|
|
118
|
+
},
|
|
119
|
+
{
|
|
120
|
+
"action": "shape_filter",
|
|
121
|
+
"target": "response",
|
|
122
|
+
"config": {
|
|
123
|
+
"request": {
|
|
124
|
+
"allowTopLevel": [
|
|
125
|
+
"model", "messages", "stream", "thinking", "do_sample", "temperature", "top_p",
|
|
126
|
+
"max_tokens", "tools", "tool_choice", "stop", "response_format"
|
|
127
|
+
],
|
|
128
|
+
"messages": {
|
|
129
|
+
"allowedRoles": ["system", "user", "assistant", "tool"],
|
|
130
|
+
"assistantWithToolCallsContentNull": true,
|
|
131
|
+
"toolContentStringify": false
|
|
118
132
|
},
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
"request": {
|
|
124
|
-
"allowTopLevel": [
|
|
125
|
-
"model", "messages", "stream", "thinking", "do_sample", "temperature", "top_p",
|
|
126
|
-
"max_tokens", "tools", "tool_choice", "stop", "response_format"
|
|
127
|
-
],
|
|
128
|
-
"messages": {
|
|
129
|
-
"allowedRoles": ["system", "user", "assistant", "tool"],
|
|
130
|
-
"assistantWithToolCallsContentNull": true,
|
|
131
|
-
"toolContentStringify": false
|
|
132
|
-
},
|
|
133
|
-
"messagesRules": [],
|
|
134
|
-
"tools": {
|
|
135
|
-
"normalize": false,
|
|
136
|
-
"forceToolChoiceAuto": true
|
|
137
|
-
},
|
|
138
|
-
"assistantToolCalls": { "functionArgumentsType": "string" }
|
|
139
|
-
},
|
|
140
|
-
"response": {
|
|
141
|
-
"allowTopLevel": [
|
|
142
|
-
"id", "request_id", "created", "model",
|
|
143
|
-
"choices", "usage", "video_result", "web_search", "content_filter",
|
|
144
|
-
"required_action", "output", "output_text", "status"
|
|
145
|
-
],
|
|
146
|
-
"choices": {
|
|
147
|
-
"required": true,
|
|
148
|
-
"message": {
|
|
149
|
-
"allow": ["role", "content", "reasoning_content", "audio", "tool_calls"],
|
|
150
|
-
"roleDefault": "assistant",
|
|
151
|
-
"contentNullWhenToolCalls": true,
|
|
152
|
-
"tool_calls": { "function": { "nameRequired": true, "argumentsType": "string" } }
|
|
153
|
-
},
|
|
154
|
-
"finish_reason": ["stop", "tool_calls", "length", "sensitive", "network_error"]
|
|
155
|
-
},
|
|
156
|
-
"usage": { "allow": ["prompt_tokens", "completion_tokens", "prompt_tokens_details", "total_tokens"] }
|
|
157
|
-
}
|
|
158
|
-
}
|
|
133
|
+
"messagesRules": [],
|
|
134
|
+
"tools": {
|
|
135
|
+
"normalize": false,
|
|
136
|
+
"forceToolChoiceAuto": true
|
|
159
137
|
},
|
|
160
|
-
{
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
"sourcePath": "choices[*].message.tool_calls[*].function.arguments",
|
|
178
|
-
"targetPath": "choices[*].message.tool_calls[*].function.arguments",
|
|
179
|
-
"type": "string"
|
|
180
|
-
}
|
|
181
|
-
]
|
|
138
|
+
"assistantToolCalls": { "functionArgumentsType": "string" }
|
|
139
|
+
},
|
|
140
|
+
"response": {
|
|
141
|
+
"allowTopLevel": [
|
|
142
|
+
"id", "request_id", "created", "model",
|
|
143
|
+
"choices", "usage", "video_result", "web_search", "content_filter",
|
|
144
|
+
"required_action", "output", "output_text", "status"
|
|
145
|
+
],
|
|
146
|
+
"choices": {
|
|
147
|
+
"required": true,
|
|
148
|
+
"message": {
|
|
149
|
+
"allow": ["role", "content", "reasoning_content", "audio", "tool_calls"],
|
|
150
|
+
"roleDefault": "assistant",
|
|
151
|
+
"contentNullWhenToolCalls": true,
|
|
152
|
+
"tool_calls": { "function": { "nameRequired": true, "argumentsType": "string" } }
|
|
153
|
+
},
|
|
154
|
+
"finish_reason": ["stop", "tool_calls", "length", "sensitive", "network_error"]
|
|
182
155
|
},
|
|
183
|
-
{ "
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
156
|
+
"usage": { "allow": ["prompt_tokens", "completion_tokens", "prompt_tokens_details", "total_tokens"] }
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
},
|
|
160
|
+
{
|
|
161
|
+
"action": "field_map",
|
|
162
|
+
"direction": "outgoing",
|
|
163
|
+
"config": [
|
|
164
|
+
{ "sourcePath": "usage.input_tokens", "targetPath": "usage.prompt_tokens", "type": "number" },
|
|
165
|
+
{ "sourcePath": "usage.output_tokens", "targetPath": "usage.completion_tokens", "type": "number" },
|
|
166
|
+
{ "sourcePath": "usage.total_input_tokens", "targetPath": "usage.prompt_tokens", "type": "number" },
|
|
167
|
+
{ "sourcePath": "usage.total_output_tokens", "targetPath": "usage.completion_tokens", "type": "number" },
|
|
168
|
+
{ "sourcePath": "created_at", "targetPath": "created", "type": "number" },
|
|
169
|
+
{ "sourcePath": "request_id", "targetPath": "request_id", "type": "string" },
|
|
170
|
+
{
|
|
171
|
+
"sourcePath": "choices[*].finish_reason",
|
|
172
|
+
"targetPath": "choices[*].finish_reason",
|
|
173
|
+
"type": "string",
|
|
174
|
+
"transform": "normalizeFinishReason"
|
|
175
|
+
},
|
|
176
|
+
{
|
|
177
|
+
"sourcePath": "choices[*].message.tool_calls[*].function.arguments",
|
|
178
|
+
"targetPath": "choices[*].message.tool_calls[*].function.arguments",
|
|
179
|
+
"type": "string"
|
|
180
|
+
}
|
|
189
181
|
]
|
|
190
|
-
|
|
182
|
+
},
|
|
183
|
+
{ "action": "tool_schema_sanitize", "mode": "glm_shell" },
|
|
184
|
+
{ "action": "response_normalize" },
|
|
185
|
+
{ "action": "extract_glm_tool_markup" },
|
|
186
|
+
{ "action": "response_validate" },
|
|
187
|
+
{ "action": "snapshot", "phase": "compat-post" },
|
|
188
|
+
{ "action": "dto_rewrap" }
|
|
189
|
+
]
|
|
190
|
+
}
|
|
191
191
|
}
|
|
@@ -1,204 +1,204 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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"
|
|
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
|
+
],
|
|
39
|
+
"messages": {
|
|
40
|
+
"allowedRoles": ["system", "user", "assistant", "tool"],
|
|
41
|
+
"assistantWithToolCallsContentNull": true,
|
|
42
|
+
"toolContentStringify": false
|
|
11
43
|
},
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
44
|
+
"messagesRules": [],
|
|
45
|
+
"tools": {
|
|
46
|
+
"normalize": false,
|
|
47
|
+
"forceToolChoiceAuto": true
|
|
15
48
|
},
|
|
16
|
-
{
|
|
17
|
-
|
|
18
|
-
|
|
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"]
|
|
19
76
|
},
|
|
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
|
-
|
|
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" }
|
|
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
|
+
}
|
|
107
102
|
]
|
|
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
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
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
|
-
}
|
|
103
|
+
},
|
|
104
|
+
{ "action": "tool_schema_sanitize", "mode": "glm_shell" },
|
|
105
|
+
{ "action": "snapshot", "phase": "compat-post" },
|
|
106
|
+
{ "action": "dto_rewrap" }
|
|
107
|
+
]
|
|
108
|
+
},
|
|
109
|
+
"response": {
|
|
110
|
+
"mappings": [
|
|
111
|
+
{ "action": "snapshot", "phase": "compat-pre" },
|
|
112
|
+
{ "action": "dto_unwrap" },
|
|
113
|
+
{
|
|
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
|
|
175
141
|
},
|
|
176
|
-
{
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
]
|
|
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"]
|
|
198
169
|
},
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
170
|
+
"usage": {
|
|
171
|
+
"allow": ["prompt_tokens", "completion_tokens", "prompt_tokens_details", "total_tokens"]
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
},
|
|
176
|
+
{
|
|
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
|
+
}
|
|
202
197
|
]
|
|
203
|
-
|
|
198
|
+
},
|
|
199
|
+
{ "action": "tool_schema_sanitize", "mode": "glm_shell" },
|
|
200
|
+
{ "action": "snapshot", "phase": "compat-post" },
|
|
201
|
+
{ "action": "dto_rewrap" }
|
|
202
|
+
]
|
|
203
|
+
}
|
|
204
204
|
}
|
|
@@ -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
|
-
|
|
33
|
-
]
|
|
34
|
-
}
|
|
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"
|
|
35
33
|
]
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
34
|
+
}
|
|
35
|
+
]
|
|
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
|
}
|
|
@@ -934,6 +934,26 @@ function extractToolCallsFromText(text, choiceIndex) {
|
|
|
934
934
|
applyPattern(pattern, factory);
|
|
935
935
|
}
|
|
936
936
|
applyTaggedArgPatterns(text, matches);
|
|
937
|
+
if (!matches.length && typeof text === 'string' && text.includes('<arg_key>')) {
|
|
938
|
+
GLM_INLINE_NAME.lastIndex = 0;
|
|
939
|
+
const inline = GLM_INLINE_NAME.exec(text);
|
|
940
|
+
GLM_INLINE_NAME.lastIndex = 0;
|
|
941
|
+
if (inline && inline[1]) {
|
|
942
|
+
const name = inline[1].trim();
|
|
943
|
+
const block = text.slice(inline[0].length);
|
|
944
|
+
const argsRecord = parseTaggedArgBlock(block);
|
|
945
|
+
if (name && argsRecord) {
|
|
946
|
+
matches.push({
|
|
947
|
+
start: 0,
|
|
948
|
+
end: text.length,
|
|
949
|
+
call: {
|
|
950
|
+
name,
|
|
951
|
+
args: safeStringify(argsRecord)
|
|
952
|
+
}
|
|
953
|
+
});
|
|
954
|
+
}
|
|
955
|
+
}
|
|
956
|
+
}
|
|
937
957
|
matches.sort((a, b) => a.start - b.start);
|
|
938
958
|
const toolCalls = matches.map((entry, idx) => ({
|
|
939
959
|
id: `glm_tool_${choiceIndex}_${idx + 1}`,
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { DEFAULT_MODEL_CONTEXT_TOKENS, VirtualRouterError, VirtualRouterErrorCode } from './types.js';
|
|
2
|
+
import { scanOAuthTokenFiles } from './token-file-scanner.js';
|
|
2
3
|
const DEFAULT_CLASSIFIER = {
|
|
3
4
|
longContextThresholdTokens: 180000,
|
|
4
5
|
thinkingKeywords: ['think step', 'analysis', 'reasoning', '仔细分析', '深度思考'],
|
|
@@ -529,6 +530,25 @@ function extractProviderAuthEntries(providerId, raw) {
|
|
|
529
530
|
else if (typeof apiKeyField === 'string' && apiKeyField.trim()) {
|
|
530
531
|
pushEntry(undefined, buildAuthCandidate(baseTypeSource, { value: apiKeyField.trim() }));
|
|
531
532
|
}
|
|
533
|
+
// 自动多 token 扫描:仅在未显式声明多 key、且为受支持的 OAuth 提供方时触发
|
|
534
|
+
if (!entries.length && baseType === 'oauth') {
|
|
535
|
+
const oauthProviderId = baseTypeInfo.oauthProviderId;
|
|
536
|
+
if (oauthProviderId && MULTI_TOKEN_OAUTH_PROVIDERS.has(oauthProviderId)) {
|
|
537
|
+
const tokenFiles = scanOAuthTokenFiles(oauthProviderId);
|
|
538
|
+
for (const match of tokenFiles) {
|
|
539
|
+
const alias = match.alias && match.alias !== 'default'
|
|
540
|
+
? `${match.sequence}-${match.alias}`
|
|
541
|
+
: String(match.sequence);
|
|
542
|
+
const authConfig = {
|
|
543
|
+
...defaults,
|
|
544
|
+
type: baseTypeSource ?? `${oauthProviderId}-oauth`,
|
|
545
|
+
tokenFile: match.filePath,
|
|
546
|
+
oauthProviderId
|
|
547
|
+
};
|
|
548
|
+
pushEntry(alias, authConfig);
|
|
549
|
+
}
|
|
550
|
+
}
|
|
551
|
+
}
|
|
532
552
|
if (!entries.length) {
|
|
533
553
|
const fallbackExtras = {
|
|
534
554
|
value: readOptionalString(auth.value),
|
|
@@ -692,6 +712,7 @@ function mergeScopes(primary, fallback) {
|
|
|
692
712
|
}
|
|
693
713
|
return merged.size ? Array.from(merged) : undefined;
|
|
694
714
|
}
|
|
715
|
+
const MULTI_TOKEN_OAUTH_PROVIDERS = new Set(['iflow']);
|
|
695
716
|
function interpretAuthType(value) {
|
|
696
717
|
if (typeof value !== 'string') {
|
|
697
718
|
return { type: 'apiKey' };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export interface OAuthTokenFileMatch {
|
|
2
|
+
filePath: string;
|
|
3
|
+
sequence: number;
|
|
4
|
+
alias: string;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* 扫描本地 RouteCodex auth 目录中的 OAuth token 文件。
|
|
8
|
+
*
|
|
9
|
+
* 约定:
|
|
10
|
+
* - 目录: ~/.routecodex/auth
|
|
11
|
+
* - 文件名: <provider>-oauth-<sequence>[-<alias>].json
|
|
12
|
+
*
|
|
13
|
+
* 仅在 Node 环境下使用;如果环境不满足,返回空列表。
|
|
14
|
+
*/
|
|
15
|
+
export declare function scanOAuthTokenFiles(oauthProviderId: string, authDir?: string): OAuthTokenFileMatch[];
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import os from 'os';
|
|
4
|
+
const TOKEN_FILE_PATTERN = /^([a-z0-9_-]+)-oauth-(\d+)(?:-(.+))?\.json$/i;
|
|
5
|
+
/**
|
|
6
|
+
* 扫描本地 RouteCodex auth 目录中的 OAuth token 文件。
|
|
7
|
+
*
|
|
8
|
+
* 约定:
|
|
9
|
+
* - 目录: ~/.routecodex/auth
|
|
10
|
+
* - 文件名: <provider>-oauth-<sequence>[-<alias>].json
|
|
11
|
+
*
|
|
12
|
+
* 仅在 Node 环境下使用;如果环境不满足,返回空列表。
|
|
13
|
+
*/
|
|
14
|
+
export function scanOAuthTokenFiles(oauthProviderId, authDir) {
|
|
15
|
+
if (!isNodeEnvironment()) {
|
|
16
|
+
return [];
|
|
17
|
+
}
|
|
18
|
+
const provider = oauthProviderId.trim().toLowerCase();
|
|
19
|
+
if (!provider) {
|
|
20
|
+
return [];
|
|
21
|
+
}
|
|
22
|
+
const baseDir = authDir && authDir.trim()
|
|
23
|
+
? authDir.trim()
|
|
24
|
+
: path.join(os.homedir(), '.routecodex', 'auth');
|
|
25
|
+
let entries;
|
|
26
|
+
try {
|
|
27
|
+
entries = fs.readdirSync(baseDir);
|
|
28
|
+
}
|
|
29
|
+
catch {
|
|
30
|
+
return [];
|
|
31
|
+
}
|
|
32
|
+
const matches = [];
|
|
33
|
+
for (const entry of entries) {
|
|
34
|
+
if (!entry.endsWith('.json'))
|
|
35
|
+
continue;
|
|
36
|
+
const match = entry.match(TOKEN_FILE_PATTERN);
|
|
37
|
+
if (!match)
|
|
38
|
+
continue;
|
|
39
|
+
const [, providerPrefix, sequenceStr, alias] = match;
|
|
40
|
+
if (providerPrefix.toLowerCase() !== provider)
|
|
41
|
+
continue;
|
|
42
|
+
const sequence = parseInt(sequenceStr, 10);
|
|
43
|
+
if (!Number.isFinite(sequence) || sequence <= 0)
|
|
44
|
+
continue;
|
|
45
|
+
matches.push({
|
|
46
|
+
filePath: path.join(baseDir, entry),
|
|
47
|
+
sequence,
|
|
48
|
+
alias: alias || 'default'
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
matches.sort((a, b) => a.sequence - b.sequence);
|
|
52
|
+
return matches;
|
|
53
|
+
}
|
|
54
|
+
function isNodeEnvironment() {
|
|
55
|
+
return typeof process !== 'undefined' && !!process.release && process.release.name === 'node';
|
|
56
|
+
}
|