@ducci/jarvis 1.0.94 → 1.0.95
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/package.json +1 -1
- package/src/server/agent.js +27 -3
package/package.json
CHANGED
package/src/server/agent.js
CHANGED
|
@@ -131,6 +131,18 @@ function extractApiError(err, model) {
|
|
|
131
131
|
};
|
|
132
132
|
}
|
|
133
133
|
|
|
134
|
+
// Extract the most specific error description available.
|
|
135
|
+
// Provider-specific APIs (e.g. z.ai) return a code + message in err.error;
|
|
136
|
+
// the OpenAI SDK sets err.message to the body message but sometimes prepends
|
|
137
|
+
// the HTTP status code, making it less readable. Prefer err.error.message + code.
|
|
138
|
+
function describeApiError(err) {
|
|
139
|
+
const bodyMsg = err?.error?.message;
|
|
140
|
+
const bodyCode = err?.error?.code;
|
|
141
|
+
if (bodyMsg && bodyCode) return `${bodyMsg} (code: ${bodyCode})`;
|
|
142
|
+
if (bodyMsg) return bodyMsg;
|
|
143
|
+
return err?.message ?? String(err);
|
|
144
|
+
}
|
|
145
|
+
|
|
134
146
|
async function callModelWithFallback(client, config, messages, tools) {
|
|
135
147
|
let primaryErr = null;
|
|
136
148
|
try {
|
|
@@ -141,9 +153,21 @@ async function callModelWithFallback(client, config, messages, tools) {
|
|
|
141
153
|
try {
|
|
142
154
|
return await callModel(client, config.fallbackModel, messages, tools);
|
|
143
155
|
} catch (fallbackErr) {
|
|
144
|
-
const
|
|
145
|
-
|
|
146
|
-
|
|
156
|
+
const primaryDesc = describeApiError(primaryErr);
|
|
157
|
+
const fallbackDesc = describeApiError(fallbackErr);
|
|
158
|
+
const sameModel = config.selectedModel === config.fallbackModel;
|
|
159
|
+
const sameError = primaryDesc === fallbackDesc;
|
|
160
|
+
|
|
161
|
+
let msg;
|
|
162
|
+
if (sameModel && sameError) {
|
|
163
|
+
msg = `Model (${config.selectedModel}) failed: ${fallbackDesc}`;
|
|
164
|
+
} else if (sameModel) {
|
|
165
|
+
msg = `Model (${config.selectedModel}) failed. Primary: ${primaryDesc} | Fallback: ${fallbackDesc}`;
|
|
166
|
+
} else {
|
|
167
|
+
msg = `Both primary (${config.selectedModel}) and fallback (${config.fallbackModel}) models failed. Primary: ${primaryDesc} | Fallback: ${fallbackDesc}`;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
const combined = new Error(msg);
|
|
147
171
|
combined.apiErrors = {
|
|
148
172
|
primary: extractApiError(primaryErr, config.selectedModel),
|
|
149
173
|
fallback: extractApiError(fallbackErr, config.fallbackModel),
|