@morphllm/morphsdk 0.2.6
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/README.md +39 -0
- package/dist/chunk-4UVEBIDK.js +358 -0
- package/dist/chunk-4UVEBIDK.js.map +1 -0
- package/dist/chunk-4V46N27D.js +169 -0
- package/dist/chunk-4V46N27D.js.map +1 -0
- package/dist/chunk-4VWJFZVS.js +89 -0
- package/dist/chunk-4VWJFZVS.js.map +1 -0
- package/dist/chunk-5COKN3XD.js +91 -0
- package/dist/chunk-5COKN3XD.js.map +1 -0
- package/dist/chunk-5VQEQSJQ.js +394 -0
- package/dist/chunk-5VQEQSJQ.js.map +1 -0
- package/dist/chunk-63WE2C5R.js +43 -0
- package/dist/chunk-63WE2C5R.js.map +1 -0
- package/dist/chunk-74ZHKB54.js +9 -0
- package/dist/chunk-74ZHKB54.js.map +1 -0
- package/dist/chunk-7PZJQFCY.js +39 -0
- package/dist/chunk-7PZJQFCY.js.map +1 -0
- package/dist/chunk-BILUTNBC.js +83 -0
- package/dist/chunk-BILUTNBC.js.map +1 -0
- package/dist/chunk-G4DJ6VSM.js +78 -0
- package/dist/chunk-G4DJ6VSM.js.map +1 -0
- package/dist/chunk-HGIFACNP.js +59 -0
- package/dist/chunk-HGIFACNP.js.map +1 -0
- package/dist/chunk-OI5YYE36.js +189 -0
- package/dist/chunk-OI5YYE36.js.map +1 -0
- package/dist/chunk-PZ5AY32C.js +10 -0
- package/dist/chunk-PZ5AY32C.js.map +1 -0
- package/dist/chunk-VJK4PH5V.js +105 -0
- package/dist/chunk-VJK4PH5V.js.map +1 -0
- package/dist/chunk-WXBUVKYL.js +128 -0
- package/dist/chunk-WXBUVKYL.js.map +1 -0
- package/dist/chunk-X2K57BH6.js +1 -0
- package/dist/chunk-X2K57BH6.js.map +1 -0
- package/dist/chunk-YQMPVJ2L.js +32 -0
- package/dist/chunk-YQMPVJ2L.js.map +1 -0
- package/dist/chunk-YWS2GRQC.js +97 -0
- package/dist/chunk-YWS2GRQC.js.map +1 -0
- package/dist/chunk-ZQEWQ7LJ.js +97 -0
- package/dist/chunk-ZQEWQ7LJ.js.map +1 -0
- package/dist/client.cjs +1358 -0
- package/dist/client.cjs.map +1 -0
- package/dist/client.js +15 -0
- package/dist/client.js.map +1 -0
- package/dist/git/client.cjs +428 -0
- package/dist/git/client.cjs.map +1 -0
- package/dist/git/client.js +8 -0
- package/dist/git/client.js.map +1 -0
- package/dist/git/config.cjs +41 -0
- package/dist/git/config.cjs.map +1 -0
- package/dist/git/config.js +17 -0
- package/dist/git/config.js.map +1 -0
- package/dist/git/index.cjs +438 -0
- package/dist/git/index.cjs.map +1 -0
- package/dist/git/index.js +14 -0
- package/dist/git/index.js.map +1 -0
- package/dist/git/types.cjs +19 -0
- package/dist/git/types.cjs.map +1 -0
- package/dist/git/types.js +1 -0
- package/dist/git/types.js.map +1 -0
- package/dist/index.cjs +1372 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.js +34 -0
- package/dist/index.js.map +1 -0
- package/dist/tools/browser/anthropic.cjs +281 -0
- package/dist/tools/browser/anthropic.cjs.map +1 -0
- package/dist/tools/browser/anthropic.js +72 -0
- package/dist/tools/browser/anthropic.js.map +1 -0
- package/dist/tools/browser/core.cjs +459 -0
- package/dist/tools/browser/core.cjs.map +1 -0
- package/dist/tools/browser/core.js +21 -0
- package/dist/tools/browser/core.js.map +1 -0
- package/dist/tools/browser/index.cjs +497 -0
- package/dist/tools/browser/index.cjs.map +1 -0
- package/dist/tools/browser/index.js +27 -0
- package/dist/tools/browser/index.js.map +1 -0
- package/dist/tools/browser/openai.cjs +297 -0
- package/dist/tools/browser/openai.cjs.map +1 -0
- package/dist/tools/browser/openai.js +85 -0
- package/dist/tools/browser/openai.js.map +1 -0
- package/dist/tools/browser/prompts.cjs +64 -0
- package/dist/tools/browser/prompts.cjs.map +1 -0
- package/dist/tools/browser/prompts.js +10 -0
- package/dist/tools/browser/prompts.js.map +1 -0
- package/dist/tools/browser/types.cjs +19 -0
- package/dist/tools/browser/types.cjs.map +1 -0
- package/dist/tools/browser/types.js +1 -0
- package/dist/tools/browser/types.js.map +1 -0
- package/dist/tools/browser/vercel.cjs +242 -0
- package/dist/tools/browser/vercel.cjs.map +1 -0
- package/dist/tools/browser/vercel.js +49 -0
- package/dist/tools/browser/vercel.js.map +1 -0
- package/dist/tools/codebase_search/anthropic.cjs +267 -0
- package/dist/tools/codebase_search/anthropic.cjs.map +1 -0
- package/dist/tools/codebase_search/anthropic.js +11 -0
- package/dist/tools/codebase_search/anthropic.js.map +1 -0
- package/dist/tools/codebase_search/core.cjs +201 -0
- package/dist/tools/codebase_search/core.cjs.map +1 -0
- package/dist/tools/codebase_search/core.js +11 -0
- package/dist/tools/codebase_search/core.js.map +1 -0
- package/dist/tools/codebase_search/index.cjs +393 -0
- package/dist/tools/codebase_search/index.cjs.map +1 -0
- package/dist/tools/codebase_search/index.js +27 -0
- package/dist/tools/codebase_search/index.js.map +1 -0
- package/dist/tools/codebase_search/openai.cjs +316 -0
- package/dist/tools/codebase_search/openai.cjs.map +1 -0
- package/dist/tools/codebase_search/openai.js +21 -0
- package/dist/tools/codebase_search/openai.js.map +1 -0
- package/dist/tools/codebase_search/prompts.cjs +57 -0
- package/dist/tools/codebase_search/prompts.cjs.map +1 -0
- package/dist/tools/codebase_search/prompts.js +10 -0
- package/dist/tools/codebase_search/prompts.js.map +1 -0
- package/dist/tools/codebase_search/types.cjs +19 -0
- package/dist/tools/codebase_search/types.cjs.map +1 -0
- package/dist/tools/codebase_search/types.js +1 -0
- package/dist/tools/codebase_search/types.js.map +1 -0
- package/dist/tools/codebase_search/vercel.cjs +230 -0
- package/dist/tools/codebase_search/vercel.cjs.map +1 -0
- package/dist/tools/codebase_search/vercel.js +15 -0
- package/dist/tools/codebase_search/vercel.js.map +1 -0
- package/dist/tools/fastapply/anthropic.cjs +335 -0
- package/dist/tools/fastapply/anthropic.cjs.map +1 -0
- package/dist/tools/fastapply/anthropic.js +13 -0
- package/dist/tools/fastapply/anthropic.js.map +1 -0
- package/dist/tools/fastapply/core.cjs +267 -0
- package/dist/tools/fastapply/core.cjs.map +1 -0
- package/dist/tools/fastapply/core.js +15 -0
- package/dist/tools/fastapply/core.js.map +1 -0
- package/dist/tools/fastapply/index.cjs +500 -0
- package/dist/tools/fastapply/index.cjs.map +1 -0
- package/dist/tools/fastapply/index.js +32 -0
- package/dist/tools/fastapply/index.js.map +1 -0
- package/dist/tools/fastapply/openai.cjs +353 -0
- package/dist/tools/fastapply/openai.cjs.map +1 -0
- package/dist/tools/fastapply/openai.js +21 -0
- package/dist/tools/fastapply/openai.js.map +1 -0
- package/dist/tools/fastapply/prompts.cjs +68 -0
- package/dist/tools/fastapply/prompts.cjs.map +1 -0
- package/dist/tools/fastapply/prompts.js +10 -0
- package/dist/tools/fastapply/prompts.js.map +1 -0
- package/dist/tools/fastapply/types.cjs +19 -0
- package/dist/tools/fastapply/types.cjs.map +1 -0
- package/dist/tools/fastapply/types.js +1 -0
- package/dist/tools/fastapply/types.js.map +1 -0
- package/dist/tools/fastapply/vercel.cjs +347 -0
- package/dist/tools/fastapply/vercel.cjs.map +1 -0
- package/dist/tools/fastapply/vercel.js +17 -0
- package/dist/tools/fastapply/vercel.js.map +1 -0
- package/dist/tools/index.cjs +500 -0
- package/dist/tools/index.cjs.map +1 -0
- package/dist/tools/index.js +32 -0
- package/dist/tools/index.js.map +1 -0
- package/dist/tools/modelrouter/core.cjs +286 -0
- package/dist/tools/modelrouter/core.cjs.map +1 -0
- package/dist/tools/modelrouter/core.js +13 -0
- package/dist/tools/modelrouter/core.js.map +1 -0
- package/dist/tools/modelrouter/index.cjs +286 -0
- package/dist/tools/modelrouter/index.cjs.map +1 -0
- package/dist/tools/modelrouter/index.js +13 -0
- package/dist/tools/modelrouter/index.js.map +1 -0
- package/dist/tools/modelrouter/types.cjs +19 -0
- package/dist/tools/modelrouter/types.cjs.map +1 -0
- package/dist/tools/modelrouter/types.js +1 -0
- package/dist/tools/modelrouter/types.js.map +1 -0
- package/dist/tools/utils/resilience.cjs +115 -0
- package/dist/tools/utils/resilience.cjs.map +1 -0
- package/dist/tools/utils/resilience.js +12 -0
- package/dist/tools/utils/resilience.js.map +1 -0
- package/package.json +159 -0
|
@@ -0,0 +1,286 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// tools/modelrouter/core.ts
|
|
21
|
+
var core_exports = {};
|
|
22
|
+
__export(core_exports, {
|
|
23
|
+
AnthropicRouter: () => AnthropicRouter,
|
|
24
|
+
GeminiRouter: () => GeminiRouter,
|
|
25
|
+
OpenAIRouter: () => OpenAIRouter
|
|
26
|
+
});
|
|
27
|
+
module.exports = __toCommonJS(core_exports);
|
|
28
|
+
|
|
29
|
+
// tools/utils/resilience.ts
|
|
30
|
+
var DEFAULT_RETRY_CONFIG = {
|
|
31
|
+
maxRetries: 3,
|
|
32
|
+
initialDelay: 1e3,
|
|
33
|
+
maxDelay: 3e4,
|
|
34
|
+
backoffMultiplier: 2,
|
|
35
|
+
retryableErrors: ["ECONNREFUSED", "ETIMEDOUT", "ENOTFOUND"]
|
|
36
|
+
};
|
|
37
|
+
async function fetchWithRetry(url, options, retryConfig = {}) {
|
|
38
|
+
const {
|
|
39
|
+
maxRetries = DEFAULT_RETRY_CONFIG.maxRetries,
|
|
40
|
+
initialDelay = DEFAULT_RETRY_CONFIG.initialDelay,
|
|
41
|
+
maxDelay = DEFAULT_RETRY_CONFIG.maxDelay,
|
|
42
|
+
backoffMultiplier = DEFAULT_RETRY_CONFIG.backoffMultiplier,
|
|
43
|
+
retryableErrors = DEFAULT_RETRY_CONFIG.retryableErrors,
|
|
44
|
+
onRetry
|
|
45
|
+
} = retryConfig;
|
|
46
|
+
let lastError = null;
|
|
47
|
+
let delay = initialDelay;
|
|
48
|
+
for (let attempt = 0; attempt <= maxRetries; attempt++) {
|
|
49
|
+
try {
|
|
50
|
+
const response = await fetch(url, options);
|
|
51
|
+
if (response.status === 429 || response.status === 503) {
|
|
52
|
+
if (attempt < maxRetries) {
|
|
53
|
+
const retryAfter = response.headers.get("Retry-After");
|
|
54
|
+
const waitTime = retryAfter ? parseInt(retryAfter) * 1e3 : Math.min(delay, maxDelay);
|
|
55
|
+
const error = new Error(`HTTP ${response.status}: Retrying after ${waitTime}ms`);
|
|
56
|
+
if (onRetry) {
|
|
57
|
+
onRetry(attempt + 1, error);
|
|
58
|
+
}
|
|
59
|
+
await sleep(waitTime);
|
|
60
|
+
delay *= backoffMultiplier;
|
|
61
|
+
continue;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
return response;
|
|
65
|
+
} catch (error) {
|
|
66
|
+
lastError = error;
|
|
67
|
+
const isRetryable = retryableErrors.some(
|
|
68
|
+
(errType) => lastError?.message?.includes(errType)
|
|
69
|
+
);
|
|
70
|
+
if (!isRetryable || attempt === maxRetries) {
|
|
71
|
+
throw lastError;
|
|
72
|
+
}
|
|
73
|
+
const waitTime = Math.min(delay, maxDelay);
|
|
74
|
+
if (onRetry) {
|
|
75
|
+
onRetry(attempt + 1, lastError);
|
|
76
|
+
}
|
|
77
|
+
await sleep(waitTime);
|
|
78
|
+
delay *= backoffMultiplier;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
throw lastError || new Error("Max retries exceeded");
|
|
82
|
+
}
|
|
83
|
+
async function withTimeout(promise, timeoutMs, errorMessage) {
|
|
84
|
+
let timeoutId;
|
|
85
|
+
const timeoutPromise = new Promise((_, reject) => {
|
|
86
|
+
timeoutId = setTimeout(() => {
|
|
87
|
+
reject(new Error(errorMessage || `Operation timed out after ${timeoutMs}ms`));
|
|
88
|
+
}, timeoutMs);
|
|
89
|
+
});
|
|
90
|
+
try {
|
|
91
|
+
const result = await Promise.race([promise, timeoutPromise]);
|
|
92
|
+
clearTimeout(timeoutId);
|
|
93
|
+
return result;
|
|
94
|
+
} catch (error) {
|
|
95
|
+
clearTimeout(timeoutId);
|
|
96
|
+
throw error;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
function sleep(ms) {
|
|
100
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// tools/modelrouter/core.ts
|
|
104
|
+
var DEFAULT_CONFIG = {
|
|
105
|
+
apiUrl: "https://api.morphllm.com",
|
|
106
|
+
timeout: 1e4,
|
|
107
|
+
// 10 seconds
|
|
108
|
+
debug: false
|
|
109
|
+
};
|
|
110
|
+
var MODEL_MAPPINGS = {
|
|
111
|
+
openai: {
|
|
112
|
+
balanced: {
|
|
113
|
+
easy: "gpt-5-mini",
|
|
114
|
+
medium: "gpt-5-low",
|
|
115
|
+
hard: "gpt-5-medium",
|
|
116
|
+
"needs-info": "gpt-5-mini"
|
|
117
|
+
},
|
|
118
|
+
aggressive: {
|
|
119
|
+
easy: "gpt-5-low",
|
|
120
|
+
medium: "gpt-5-medium",
|
|
121
|
+
hard: "gpt-5-high",
|
|
122
|
+
"needs-info": "gpt-5-mini"
|
|
123
|
+
}
|
|
124
|
+
},
|
|
125
|
+
anthropic: {
|
|
126
|
+
balanced: {
|
|
127
|
+
easy: "claude-4.5-haiku",
|
|
128
|
+
medium: "claude-4.5-haiku",
|
|
129
|
+
hard: "claude-4.5-sonnet",
|
|
130
|
+
"needs-info": "claude-4.5-haiku"
|
|
131
|
+
},
|
|
132
|
+
aggressive: {
|
|
133
|
+
easy: "claude-4.5-haiku",
|
|
134
|
+
medium: "claude-4.5-sonnet",
|
|
135
|
+
hard: "claude-4.5-sonnet",
|
|
136
|
+
"needs-info": "claude-4.5-haiku"
|
|
137
|
+
}
|
|
138
|
+
},
|
|
139
|
+
gemini: {
|
|
140
|
+
balanced: {
|
|
141
|
+
easy: "gemini-2.5-flash",
|
|
142
|
+
medium: "gemini-2.5-flash",
|
|
143
|
+
hard: "gemini-2.5-pro",
|
|
144
|
+
"needs-info": "gemini-2.5-flash"
|
|
145
|
+
},
|
|
146
|
+
aggressive: {
|
|
147
|
+
easy: "gemini-2.5-flash",
|
|
148
|
+
medium: "gemini-2.5-pro",
|
|
149
|
+
hard: "gemini-2.5-pro",
|
|
150
|
+
"needs-info": "gemini-2.5-flash"
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
};
|
|
154
|
+
var BaseRouter = class {
|
|
155
|
+
config;
|
|
156
|
+
provider;
|
|
157
|
+
constructor(provider, config = {}) {
|
|
158
|
+
this.provider = provider;
|
|
159
|
+
this.config = {
|
|
160
|
+
apiKey: config.apiKey,
|
|
161
|
+
apiUrl: config.apiUrl || DEFAULT_CONFIG.apiUrl,
|
|
162
|
+
timeout: config.timeout || DEFAULT_CONFIG.timeout,
|
|
163
|
+
debug: config.debug || DEFAULT_CONFIG.debug,
|
|
164
|
+
retryConfig: config.retryConfig
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* Map backend complexity classification to actual model name
|
|
169
|
+
*/
|
|
170
|
+
mapComplexityToModel(complexity, mode) {
|
|
171
|
+
const mapping = MODEL_MAPPINGS[this.provider][mode];
|
|
172
|
+
return mapping[complexity];
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Select the optimal model for a given input and mode
|
|
176
|
+
*/
|
|
177
|
+
async selectModel(input) {
|
|
178
|
+
const mode = input.mode || "balanced";
|
|
179
|
+
const apiKey = this.config.apiKey || process.env.MORPH_API_KEY;
|
|
180
|
+
if (!apiKey) {
|
|
181
|
+
throw new Error(
|
|
182
|
+
"Morph API key is required. Set MORPH_API_KEY environment variable or pass apiKey in config."
|
|
183
|
+
);
|
|
184
|
+
}
|
|
185
|
+
const url = `${this.config.apiUrl}/router/${this.provider}`;
|
|
186
|
+
const payload = {
|
|
187
|
+
input: input.input,
|
|
188
|
+
mode
|
|
189
|
+
};
|
|
190
|
+
if (this.config.debug) {
|
|
191
|
+
console.log(`[ModelRouter] Requesting ${this.provider} model selection:`, {
|
|
192
|
+
mode,
|
|
193
|
+
inputLength: input.input.length
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
try {
|
|
197
|
+
const fetchPromise = fetchWithRetry(
|
|
198
|
+
url,
|
|
199
|
+
{
|
|
200
|
+
method: "POST",
|
|
201
|
+
headers: {
|
|
202
|
+
"Content-Type": "application/json",
|
|
203
|
+
Authorization: `Bearer ${apiKey}`
|
|
204
|
+
},
|
|
205
|
+
body: JSON.stringify(payload)
|
|
206
|
+
},
|
|
207
|
+
this.config.retryConfig
|
|
208
|
+
);
|
|
209
|
+
const response = await withTimeout(
|
|
210
|
+
fetchPromise,
|
|
211
|
+
this.config.timeout,
|
|
212
|
+
`Router API request timed out after ${this.config.timeout}ms`
|
|
213
|
+
);
|
|
214
|
+
if (!response.ok) {
|
|
215
|
+
const errorText = await response.text();
|
|
216
|
+
throw new Error(
|
|
217
|
+
`Router API error (${response.status}): ${errorText || response.statusText}`
|
|
218
|
+
);
|
|
219
|
+
}
|
|
220
|
+
const apiResult = await response.json();
|
|
221
|
+
const actualModel = this.mapComplexityToModel(apiResult.model, mode);
|
|
222
|
+
const result = {
|
|
223
|
+
model: actualModel,
|
|
224
|
+
reasoning: apiResult.reasoning
|
|
225
|
+
};
|
|
226
|
+
if (this.config.debug) {
|
|
227
|
+
console.log(`[ModelRouter] Complexity: ${apiResult.model}, Selected model: ${actualModel}`);
|
|
228
|
+
}
|
|
229
|
+
return result;
|
|
230
|
+
} catch (error) {
|
|
231
|
+
if (this.config.debug) {
|
|
232
|
+
console.error(`[ModelRouter] Error selecting model:`, error);
|
|
233
|
+
}
|
|
234
|
+
throw error;
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
};
|
|
238
|
+
var OpenAIRouter = class extends BaseRouter {
|
|
239
|
+
constructor(config = {}) {
|
|
240
|
+
super("openai", config);
|
|
241
|
+
}
|
|
242
|
+
/**
|
|
243
|
+
* Select optimal GPT-5 model
|
|
244
|
+
*
|
|
245
|
+
* @param input - User input and mode
|
|
246
|
+
* @returns Selected model name (gpt-5-mini | gpt-5-low | gpt-5-medium | gpt-5-high)
|
|
247
|
+
*/
|
|
248
|
+
async selectModel(input) {
|
|
249
|
+
return super.selectModel(input);
|
|
250
|
+
}
|
|
251
|
+
};
|
|
252
|
+
var AnthropicRouter = class extends BaseRouter {
|
|
253
|
+
constructor(config = {}) {
|
|
254
|
+
super("anthropic", config);
|
|
255
|
+
}
|
|
256
|
+
/**
|
|
257
|
+
* Select optimal Claude model
|
|
258
|
+
*
|
|
259
|
+
* @param input - User input and mode
|
|
260
|
+
* @returns Selected model name (claude-4.5-haiku | claude-4.5-sonnet)
|
|
261
|
+
*/
|
|
262
|
+
async selectModel(input) {
|
|
263
|
+
return super.selectModel(input);
|
|
264
|
+
}
|
|
265
|
+
};
|
|
266
|
+
var GeminiRouter = class extends BaseRouter {
|
|
267
|
+
constructor(config = {}) {
|
|
268
|
+
super("gemini", config);
|
|
269
|
+
}
|
|
270
|
+
/**
|
|
271
|
+
* Select optimal Gemini model
|
|
272
|
+
*
|
|
273
|
+
* @param input - User input and mode
|
|
274
|
+
* @returns Selected model name (gemini-2.5-flash | gemini-2.5-pro)
|
|
275
|
+
*/
|
|
276
|
+
async selectModel(input) {
|
|
277
|
+
return super.selectModel(input);
|
|
278
|
+
}
|
|
279
|
+
};
|
|
280
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
281
|
+
0 && (module.exports = {
|
|
282
|
+
AnthropicRouter,
|
|
283
|
+
GeminiRouter,
|
|
284
|
+
OpenAIRouter
|
|
285
|
+
});
|
|
286
|
+
//# sourceMappingURL=core.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../tools/modelrouter/core.ts","../../../tools/utils/resilience.ts"],"sourcesContent":["/**\n * Core implementation for intelligent model routing\n */\n\nimport { fetchWithRetry, withTimeout } from '../utils/resilience.js';\nimport type {\n RouterConfig,\n RouterInput,\n RouterResult,\n ComplexityLevel,\n RouterMode,\n Provider,\n} from './types.js';\n\nconst DEFAULT_CONFIG = {\n apiUrl: 'https://api.morphllm.com',\n timeout: 10000, // 10 seconds\n debug: false,\n};\n\nconst MODEL_MAPPINGS: Record<Provider, Record<RouterMode, Record<ComplexityLevel, string>>> = {\n openai: {\n balanced: {\n easy: 'gpt-5-mini',\n medium: 'gpt-5-low',\n hard: 'gpt-5-medium',\n 'needs-info': 'gpt-5-mini',\n },\n aggressive: {\n easy: 'gpt-5-low',\n medium: 'gpt-5-medium',\n hard: 'gpt-5-high',\n 'needs-info': 'gpt-5-mini',\n },\n },\n anthropic: {\n balanced: {\n easy: 'claude-4.5-haiku',\n medium: 'claude-4.5-haiku',\n hard: 'claude-4.5-sonnet',\n 'needs-info': 'claude-4.5-haiku',\n },\n aggressive: {\n easy: 'claude-4.5-haiku',\n medium: 'claude-4.5-sonnet',\n hard: 'claude-4.5-sonnet',\n 'needs-info': 'claude-4.5-haiku',\n },\n },\n gemini: {\n balanced: {\n easy: 'gemini-2.5-flash',\n medium: 'gemini-2.5-flash',\n hard: 'gemini-2.5-pro',\n 'needs-info': 'gemini-2.5-flash',\n },\n aggressive: {\n easy: 'gemini-2.5-flash',\n medium: 'gemini-2.5-pro',\n hard: 'gemini-2.5-pro',\n 'needs-info': 'gemini-2.5-flash',\n },\n },\n};\n\nabstract class BaseRouter {\n protected config: Required<Omit<RouterConfig, 'apiKey' | 'retryConfig'>> & Pick<RouterConfig, 'apiKey' | 'retryConfig'>;\n protected provider: Provider;\n\n constructor(provider: Provider, config: RouterConfig = {}) {\n this.provider = provider;\n this.config = {\n apiKey: config.apiKey,\n apiUrl: config.apiUrl || DEFAULT_CONFIG.apiUrl,\n timeout: config.timeout || DEFAULT_CONFIG.timeout,\n debug: config.debug || DEFAULT_CONFIG.debug,\n retryConfig: config.retryConfig,\n };\n }\n\n /**\n * Map backend complexity classification to actual model name\n */\n protected mapComplexityToModel(complexity: ComplexityLevel, mode: RouterMode): string {\n const mapping = MODEL_MAPPINGS[this.provider][mode];\n return mapping[complexity];\n }\n\n /**\n * Select the optimal model for a given input and mode\n */\n async selectModel(input: RouterInput): Promise<RouterResult> {\n const mode = input.mode || 'balanced';\n const apiKey = this.config.apiKey || process.env.MORPH_API_KEY;\n\n if (!apiKey) {\n throw new Error(\n 'Morph API key is required. Set MORPH_API_KEY environment variable or pass apiKey in config.'\n );\n }\n\n const url = `${this.config.apiUrl}/router/${this.provider}`;\n const payload = {\n input: input.input,\n mode,\n };\n\n if (this.config.debug) {\n console.log(`[ModelRouter] Requesting ${this.provider} model selection:`, {\n mode,\n inputLength: input.input.length,\n });\n }\n\n try {\n const fetchPromise = fetchWithRetry(\n url,\n {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n Authorization: `Bearer ${apiKey}`,\n },\n body: JSON.stringify(payload),\n },\n this.config.retryConfig\n );\n\n const response = await withTimeout(\n fetchPromise,\n this.config.timeout,\n `Router API request timed out after ${this.config.timeout}ms`\n );\n\n if (!response.ok) {\n const errorText = await response.text();\n throw new Error(\n `Router API error (${response.status}): ${errorText || response.statusText}`\n );\n }\n\n const apiResult: { model: ComplexityLevel; reasoning?: string } = await response.json();\n const actualModel = this.mapComplexityToModel(apiResult.model, mode);\n\n const result: RouterResult = {\n model: actualModel,\n reasoning: apiResult.reasoning,\n };\n\n if (this.config.debug) {\n console.log(`[ModelRouter] Complexity: ${apiResult.model}, Selected model: ${actualModel}`);\n }\n\n return result;\n } catch (error) {\n if (this.config.debug) {\n console.error(`[ModelRouter] Error selecting model:`, error);\n }\n throw error;\n }\n }\n}\n\n/**\n * OpenAI model router for GPT-5 series\n */\nexport class OpenAIRouter extends BaseRouter {\n constructor(config: RouterConfig = {}) {\n super('openai', config);\n }\n\n /**\n * Select optimal GPT-5 model\n * \n * @param input - User input and mode\n * @returns Selected model name (gpt-5-mini | gpt-5-low | gpt-5-medium | gpt-5-high)\n */\n async selectModel(input: RouterInput): Promise<RouterResult> {\n return super.selectModel(input);\n }\n}\n\n/**\n * Anthropic model router for Claude 4.5 series\n */\nexport class AnthropicRouter extends BaseRouter {\n constructor(config: RouterConfig = {}) {\n super('anthropic', config);\n }\n\n /**\n * Select optimal Claude model\n * \n * @param input - User input and mode\n * @returns Selected model name (claude-4.5-haiku | claude-4.5-sonnet)\n */\n async selectModel(input: RouterInput): Promise<RouterResult> {\n return super.selectModel(input);\n }\n}\n\n/**\n * Google Gemini model router\n */\nexport class GeminiRouter extends BaseRouter {\n constructor(config: RouterConfig = {}) {\n super('gemini', config);\n }\n\n /**\n * Select optimal Gemini model\n * \n * @param input - User input and mode\n * @returns Selected model name (gemini-2.5-flash | gemini-2.5-pro)\n */\n async selectModel(input: RouterInput): Promise<RouterResult> {\n return super.selectModel(input);\n }\n}\n","/**\n * Resilience utilities for retry logic and timeout handling\n */\n\nexport interface RetryConfig {\n maxRetries?: number; // Default: 3\n initialDelay?: number; // Default: 1000ms\n maxDelay?: number; // Default: 30000ms\n backoffMultiplier?: number; // Default: 2\n retryableErrors?: string[]; // Default: ['ECONNREFUSED', 'ETIMEDOUT', 'ENOTFOUND']\n onRetry?: (attempt: number, error: Error) => void;\n}\n\nconst DEFAULT_RETRY_CONFIG: Required<Omit<RetryConfig, 'onRetry'>> = {\n maxRetries: 3,\n initialDelay: 1000,\n maxDelay: 30000,\n backoffMultiplier: 2,\n retryableErrors: ['ECONNREFUSED', 'ETIMEDOUT', 'ENOTFOUND'],\n};\n\n/**\n * Retry a fetch request with exponential backoff\n * \n * @param url - Request URL\n * @param options - Fetch options\n * @param retryConfig - Retry configuration\n * @returns Response from fetch\n * \n * @example\n * ```typescript\n * const response = await fetchWithRetry(\n * 'https://api.example.com/data',\n * { method: 'POST', body: JSON.stringify(data) },\n * { maxRetries: 5, initialDelay: 500 }\n * );\n * ```\n */\nexport async function fetchWithRetry(\n url: string,\n options: RequestInit,\n retryConfig: RetryConfig = {}\n): Promise<Response> {\n const {\n maxRetries = DEFAULT_RETRY_CONFIG.maxRetries,\n initialDelay = DEFAULT_RETRY_CONFIG.initialDelay,\n maxDelay = DEFAULT_RETRY_CONFIG.maxDelay,\n backoffMultiplier = DEFAULT_RETRY_CONFIG.backoffMultiplier,\n retryableErrors = DEFAULT_RETRY_CONFIG.retryableErrors,\n onRetry,\n } = retryConfig;\n\n let lastError: Error | null = null;\n let delay = initialDelay;\n\n for (let attempt = 0; attempt <= maxRetries; attempt++) {\n try {\n const response = await fetch(url, options);\n \n // Retry on 429 (rate limit) or 503 (service unavailable)\n if (response.status === 429 || response.status === 503) {\n if (attempt < maxRetries) {\n // Check for Retry-After header\n const retryAfter = response.headers.get('Retry-After');\n const waitTime = retryAfter \n ? parseInt(retryAfter) * 1000 \n : Math.min(delay, maxDelay);\n \n const error = new Error(`HTTP ${response.status}: Retrying after ${waitTime}ms`);\n if (onRetry) {\n onRetry(attempt + 1, error);\n }\n \n await sleep(waitTime);\n delay *= backoffMultiplier;\n continue;\n }\n }\n\n return response;\n } catch (error) {\n lastError = error as Error;\n \n // Check if error is retryable\n const isRetryable = retryableErrors.some(errType => \n lastError?.message?.includes(errType)\n );\n\n if (!isRetryable || attempt === maxRetries) {\n throw lastError;\n }\n\n // Exponential backoff\n const waitTime = Math.min(delay, maxDelay);\n if (onRetry) {\n onRetry(attempt + 1, lastError);\n }\n \n await sleep(waitTime);\n delay *= backoffMultiplier;\n }\n }\n\n throw lastError || new Error('Max retries exceeded');\n}\n\n/**\n * Add timeout to any promise\n * \n * @param promise - Promise to wrap with timeout\n * @param timeoutMs - Timeout in milliseconds\n * @param errorMessage - Optional custom error message\n * @returns Promise that rejects if timeout is reached\n * \n * @example\n * ```typescript\n * const result = await withTimeout(\n * fetchData(),\n * 5000,\n * 'Data fetch timed out'\n * );\n * ```\n */\nexport async function withTimeout<T>(\n promise: Promise<T>,\n timeoutMs: number,\n errorMessage?: string\n): Promise<T> {\n let timeoutId: NodeJS.Timeout | number;\n \n const timeoutPromise = new Promise<never>((_, reject) => {\n timeoutId = setTimeout(() => {\n reject(new Error(errorMessage || `Operation timed out after ${timeoutMs}ms`));\n }, timeoutMs);\n });\n\n try {\n const result = await Promise.race([promise, timeoutPromise]);\n clearTimeout(timeoutId!);\n return result;\n } catch (error) {\n clearTimeout(timeoutId!);\n throw error;\n }\n}\n\n/**\n * Sleep for specified milliseconds\n */\nfunction sleep(ms: number): Promise<void> {\n return new Promise(resolve => setTimeout(resolve, ms));\n}\n\n/**\n * Unified error type for all tools\n */\nexport class MorphError extends Error {\n constructor(\n message: string,\n public code: string,\n public statusCode?: number,\n public retryable: boolean = false\n ) {\n super(message);\n this.name = 'MorphError';\n }\n}\n\n\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACaA,IAAM,uBAA+D;AAAA,EACnE,YAAY;AAAA,EACZ,cAAc;AAAA,EACd,UAAU;AAAA,EACV,mBAAmB;AAAA,EACnB,iBAAiB,CAAC,gBAAgB,aAAa,WAAW;AAC5D;AAmBA,eAAsB,eACpB,KACA,SACA,cAA2B,CAAC,GACT;AACnB,QAAM;AAAA,IACJ,aAAa,qBAAqB;AAAA,IAClC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3
|
+
GeminiRouter,
|
|
4
|
+
OpenAIRouter
|
|
5
|
+
} from "../../chunk-OI5YYE36.js";
|
|
6
|
+
import "../../chunk-4VWJFZVS.js";
|
|
7
|
+
import "../../chunk-PZ5AY32C.js";
|
|
8
|
+
export {
|
|
9
|
+
AnthropicRouter,
|
|
10
|
+
GeminiRouter,
|
|
11
|
+
OpenAIRouter
|
|
12
|
+
};
|
|
13
|
+
//# sourceMappingURL=core.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -0,0 +1,286 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// tools/modelrouter/index.ts
|
|
21
|
+
var modelrouter_exports = {};
|
|
22
|
+
__export(modelrouter_exports, {
|
|
23
|
+
AnthropicRouter: () => AnthropicRouter,
|
|
24
|
+
GeminiRouter: () => GeminiRouter,
|
|
25
|
+
OpenAIRouter: () => OpenAIRouter
|
|
26
|
+
});
|
|
27
|
+
module.exports = __toCommonJS(modelrouter_exports);
|
|
28
|
+
|
|
29
|
+
// tools/utils/resilience.ts
|
|
30
|
+
var DEFAULT_RETRY_CONFIG = {
|
|
31
|
+
maxRetries: 3,
|
|
32
|
+
initialDelay: 1e3,
|
|
33
|
+
maxDelay: 3e4,
|
|
34
|
+
backoffMultiplier: 2,
|
|
35
|
+
retryableErrors: ["ECONNREFUSED", "ETIMEDOUT", "ENOTFOUND"]
|
|
36
|
+
};
|
|
37
|
+
async function fetchWithRetry(url, options, retryConfig = {}) {
|
|
38
|
+
const {
|
|
39
|
+
maxRetries = DEFAULT_RETRY_CONFIG.maxRetries,
|
|
40
|
+
initialDelay = DEFAULT_RETRY_CONFIG.initialDelay,
|
|
41
|
+
maxDelay = DEFAULT_RETRY_CONFIG.maxDelay,
|
|
42
|
+
backoffMultiplier = DEFAULT_RETRY_CONFIG.backoffMultiplier,
|
|
43
|
+
retryableErrors = DEFAULT_RETRY_CONFIG.retryableErrors,
|
|
44
|
+
onRetry
|
|
45
|
+
} = retryConfig;
|
|
46
|
+
let lastError = null;
|
|
47
|
+
let delay = initialDelay;
|
|
48
|
+
for (let attempt = 0; attempt <= maxRetries; attempt++) {
|
|
49
|
+
try {
|
|
50
|
+
const response = await fetch(url, options);
|
|
51
|
+
if (response.status === 429 || response.status === 503) {
|
|
52
|
+
if (attempt < maxRetries) {
|
|
53
|
+
const retryAfter = response.headers.get("Retry-After");
|
|
54
|
+
const waitTime = retryAfter ? parseInt(retryAfter) * 1e3 : Math.min(delay, maxDelay);
|
|
55
|
+
const error = new Error(`HTTP ${response.status}: Retrying after ${waitTime}ms`);
|
|
56
|
+
if (onRetry) {
|
|
57
|
+
onRetry(attempt + 1, error);
|
|
58
|
+
}
|
|
59
|
+
await sleep(waitTime);
|
|
60
|
+
delay *= backoffMultiplier;
|
|
61
|
+
continue;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
return response;
|
|
65
|
+
} catch (error) {
|
|
66
|
+
lastError = error;
|
|
67
|
+
const isRetryable = retryableErrors.some(
|
|
68
|
+
(errType) => lastError?.message?.includes(errType)
|
|
69
|
+
);
|
|
70
|
+
if (!isRetryable || attempt === maxRetries) {
|
|
71
|
+
throw lastError;
|
|
72
|
+
}
|
|
73
|
+
const waitTime = Math.min(delay, maxDelay);
|
|
74
|
+
if (onRetry) {
|
|
75
|
+
onRetry(attempt + 1, lastError);
|
|
76
|
+
}
|
|
77
|
+
await sleep(waitTime);
|
|
78
|
+
delay *= backoffMultiplier;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
throw lastError || new Error("Max retries exceeded");
|
|
82
|
+
}
|
|
83
|
+
async function withTimeout(promise, timeoutMs, errorMessage) {
|
|
84
|
+
let timeoutId;
|
|
85
|
+
const timeoutPromise = new Promise((_, reject) => {
|
|
86
|
+
timeoutId = setTimeout(() => {
|
|
87
|
+
reject(new Error(errorMessage || `Operation timed out after ${timeoutMs}ms`));
|
|
88
|
+
}, timeoutMs);
|
|
89
|
+
});
|
|
90
|
+
try {
|
|
91
|
+
const result = await Promise.race([promise, timeoutPromise]);
|
|
92
|
+
clearTimeout(timeoutId);
|
|
93
|
+
return result;
|
|
94
|
+
} catch (error) {
|
|
95
|
+
clearTimeout(timeoutId);
|
|
96
|
+
throw error;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
function sleep(ms) {
|
|
100
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// tools/modelrouter/core.ts
|
|
104
|
+
var DEFAULT_CONFIG = {
|
|
105
|
+
apiUrl: "https://api.morphllm.com",
|
|
106
|
+
timeout: 1e4,
|
|
107
|
+
// 10 seconds
|
|
108
|
+
debug: false
|
|
109
|
+
};
|
|
110
|
+
var MODEL_MAPPINGS = {
|
|
111
|
+
openai: {
|
|
112
|
+
balanced: {
|
|
113
|
+
easy: "gpt-5-mini",
|
|
114
|
+
medium: "gpt-5-low",
|
|
115
|
+
hard: "gpt-5-medium",
|
|
116
|
+
"needs-info": "gpt-5-mini"
|
|
117
|
+
},
|
|
118
|
+
aggressive: {
|
|
119
|
+
easy: "gpt-5-low",
|
|
120
|
+
medium: "gpt-5-medium",
|
|
121
|
+
hard: "gpt-5-high",
|
|
122
|
+
"needs-info": "gpt-5-mini"
|
|
123
|
+
}
|
|
124
|
+
},
|
|
125
|
+
anthropic: {
|
|
126
|
+
balanced: {
|
|
127
|
+
easy: "claude-4.5-haiku",
|
|
128
|
+
medium: "claude-4.5-haiku",
|
|
129
|
+
hard: "claude-4.5-sonnet",
|
|
130
|
+
"needs-info": "claude-4.5-haiku"
|
|
131
|
+
},
|
|
132
|
+
aggressive: {
|
|
133
|
+
easy: "claude-4.5-haiku",
|
|
134
|
+
medium: "claude-4.5-sonnet",
|
|
135
|
+
hard: "claude-4.5-sonnet",
|
|
136
|
+
"needs-info": "claude-4.5-haiku"
|
|
137
|
+
}
|
|
138
|
+
},
|
|
139
|
+
gemini: {
|
|
140
|
+
balanced: {
|
|
141
|
+
easy: "gemini-2.5-flash",
|
|
142
|
+
medium: "gemini-2.5-flash",
|
|
143
|
+
hard: "gemini-2.5-pro",
|
|
144
|
+
"needs-info": "gemini-2.5-flash"
|
|
145
|
+
},
|
|
146
|
+
aggressive: {
|
|
147
|
+
easy: "gemini-2.5-flash",
|
|
148
|
+
medium: "gemini-2.5-pro",
|
|
149
|
+
hard: "gemini-2.5-pro",
|
|
150
|
+
"needs-info": "gemini-2.5-flash"
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
};
|
|
154
|
+
var BaseRouter = class {
|
|
155
|
+
config;
|
|
156
|
+
provider;
|
|
157
|
+
constructor(provider, config = {}) {
|
|
158
|
+
this.provider = provider;
|
|
159
|
+
this.config = {
|
|
160
|
+
apiKey: config.apiKey,
|
|
161
|
+
apiUrl: config.apiUrl || DEFAULT_CONFIG.apiUrl,
|
|
162
|
+
timeout: config.timeout || DEFAULT_CONFIG.timeout,
|
|
163
|
+
debug: config.debug || DEFAULT_CONFIG.debug,
|
|
164
|
+
retryConfig: config.retryConfig
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* Map backend complexity classification to actual model name
|
|
169
|
+
*/
|
|
170
|
+
mapComplexityToModel(complexity, mode) {
|
|
171
|
+
const mapping = MODEL_MAPPINGS[this.provider][mode];
|
|
172
|
+
return mapping[complexity];
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Select the optimal model for a given input and mode
|
|
176
|
+
*/
|
|
177
|
+
async selectModel(input) {
|
|
178
|
+
const mode = input.mode || "balanced";
|
|
179
|
+
const apiKey = this.config.apiKey || process.env.MORPH_API_KEY;
|
|
180
|
+
if (!apiKey) {
|
|
181
|
+
throw new Error(
|
|
182
|
+
"Morph API key is required. Set MORPH_API_KEY environment variable or pass apiKey in config."
|
|
183
|
+
);
|
|
184
|
+
}
|
|
185
|
+
const url = `${this.config.apiUrl}/router/${this.provider}`;
|
|
186
|
+
const payload = {
|
|
187
|
+
input: input.input,
|
|
188
|
+
mode
|
|
189
|
+
};
|
|
190
|
+
if (this.config.debug) {
|
|
191
|
+
console.log(`[ModelRouter] Requesting ${this.provider} model selection:`, {
|
|
192
|
+
mode,
|
|
193
|
+
inputLength: input.input.length
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
try {
|
|
197
|
+
const fetchPromise = fetchWithRetry(
|
|
198
|
+
url,
|
|
199
|
+
{
|
|
200
|
+
method: "POST",
|
|
201
|
+
headers: {
|
|
202
|
+
"Content-Type": "application/json",
|
|
203
|
+
Authorization: `Bearer ${apiKey}`
|
|
204
|
+
},
|
|
205
|
+
body: JSON.stringify(payload)
|
|
206
|
+
},
|
|
207
|
+
this.config.retryConfig
|
|
208
|
+
);
|
|
209
|
+
const response = await withTimeout(
|
|
210
|
+
fetchPromise,
|
|
211
|
+
this.config.timeout,
|
|
212
|
+
`Router API request timed out after ${this.config.timeout}ms`
|
|
213
|
+
);
|
|
214
|
+
if (!response.ok) {
|
|
215
|
+
const errorText = await response.text();
|
|
216
|
+
throw new Error(
|
|
217
|
+
`Router API error (${response.status}): ${errorText || response.statusText}`
|
|
218
|
+
);
|
|
219
|
+
}
|
|
220
|
+
const apiResult = await response.json();
|
|
221
|
+
const actualModel = this.mapComplexityToModel(apiResult.model, mode);
|
|
222
|
+
const result = {
|
|
223
|
+
model: actualModel,
|
|
224
|
+
reasoning: apiResult.reasoning
|
|
225
|
+
};
|
|
226
|
+
if (this.config.debug) {
|
|
227
|
+
console.log(`[ModelRouter] Complexity: ${apiResult.model}, Selected model: ${actualModel}`);
|
|
228
|
+
}
|
|
229
|
+
return result;
|
|
230
|
+
} catch (error) {
|
|
231
|
+
if (this.config.debug) {
|
|
232
|
+
console.error(`[ModelRouter] Error selecting model:`, error);
|
|
233
|
+
}
|
|
234
|
+
throw error;
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
};
|
|
238
|
+
var OpenAIRouter = class extends BaseRouter {
|
|
239
|
+
constructor(config = {}) {
|
|
240
|
+
super("openai", config);
|
|
241
|
+
}
|
|
242
|
+
/**
|
|
243
|
+
* Select optimal GPT-5 model
|
|
244
|
+
*
|
|
245
|
+
* @param input - User input and mode
|
|
246
|
+
* @returns Selected model name (gpt-5-mini | gpt-5-low | gpt-5-medium | gpt-5-high)
|
|
247
|
+
*/
|
|
248
|
+
async selectModel(input) {
|
|
249
|
+
return super.selectModel(input);
|
|
250
|
+
}
|
|
251
|
+
};
|
|
252
|
+
var AnthropicRouter = class extends BaseRouter {
|
|
253
|
+
constructor(config = {}) {
|
|
254
|
+
super("anthropic", config);
|
|
255
|
+
}
|
|
256
|
+
/**
|
|
257
|
+
* Select optimal Claude model
|
|
258
|
+
*
|
|
259
|
+
* @param input - User input and mode
|
|
260
|
+
* @returns Selected model name (claude-4.5-haiku | claude-4.5-sonnet)
|
|
261
|
+
*/
|
|
262
|
+
async selectModel(input) {
|
|
263
|
+
return super.selectModel(input);
|
|
264
|
+
}
|
|
265
|
+
};
|
|
266
|
+
var GeminiRouter = class extends BaseRouter {
|
|
267
|
+
constructor(config = {}) {
|
|
268
|
+
super("gemini", config);
|
|
269
|
+
}
|
|
270
|
+
/**
|
|
271
|
+
* Select optimal Gemini model
|
|
272
|
+
*
|
|
273
|
+
* @param input - User input and mode
|
|
274
|
+
* @returns Selected model name (gemini-2.5-flash | gemini-2.5-pro)
|
|
275
|
+
*/
|
|
276
|
+
async selectModel(input) {
|
|
277
|
+
return super.selectModel(input);
|
|
278
|
+
}
|
|
279
|
+
};
|
|
280
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
281
|
+
0 && (module.exports = {
|
|
282
|
+
AnthropicRouter,
|
|
283
|
+
GeminiRouter,
|
|
284
|
+
OpenAIRouter
|
|
285
|
+
});
|
|
286
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../tools/modelrouter/index.ts","../../../tools/utils/resilience.ts","../../../tools/modelrouter/core.ts"],"sourcesContent":["/**\n * Intelligent model routing based on task complexity\n * \n * @module modelrouter\n */\n\nexport { OpenAIRouter, AnthropicRouter, GeminiRouter } from './core.js';\nexport type {\n RouterConfig,\n RouterInput,\n RouterResult,\n ComplexityLevel,\n RouterMode,\n Provider,\n} from './types.js';\n","/**\n * Resilience utilities for retry logic and timeout handling\n */\n\nexport interface RetryConfig {\n maxRetries?: number; // Default: 3\n initialDelay?: number; // Default: 1000ms\n maxDelay?: number; // Default: 30000ms\n backoffMultiplier?: number; // Default: 2\n retryableErrors?: string[]; // Default: ['ECONNREFUSED', 'ETIMEDOUT', 'ENOTFOUND']\n onRetry?: (attempt: number, error: Error) => void;\n}\n\nconst DEFAULT_RETRY_CONFIG: Required<Omit<RetryConfig, 'onRetry'>> = {\n maxRetries: 3,\n initialDelay: 1000,\n maxDelay: 30000,\n backoffMultiplier: 2,\n retryableErrors: ['ECONNREFUSED', 'ETIMEDOUT', 'ENOTFOUND'],\n};\n\n/**\n * Retry a fetch request with exponential backoff\n * \n * @param url - Request URL\n * @param options - Fetch options\n * @param retryConfig - Retry configuration\n * @returns Response from fetch\n * \n * @example\n * ```typescript\n * const response = await fetchWithRetry(\n * 'https://api.example.com/data',\n * { method: 'POST', body: JSON.stringify(data) },\n * { maxRetries: 5, initialDelay: 500 }\n * );\n * ```\n */\nexport async function fetchWithRetry(\n url: string,\n options: RequestInit,\n retryConfig: RetryConfig = {}\n): Promise<Response> {\n const {\n maxRetries = DEFAULT_RETRY_CONFIG.maxRetries,\n initialDelay = DEFAULT_RETRY_CONFIG.initialDelay,\n maxDelay = DEFAULT_RETRY_CONFIG.maxDelay,\n backoffMultiplier = DEFAULT_RETRY_CONFIG.backoffMultiplier,\n retryableErrors = DEFAULT_RETRY_CONFIG.retryableErrors,\n onRetry,\n } = retryConfig;\n\n let lastError: Error | null = null;\n let delay = initialDelay;\n\n for (let attempt = 0; attempt <= maxRetries; attempt++) {\n try {\n const response = await fetch(url, options);\n \n // Retry on 429 (rate limit) or 503 (service unavailable)\n if (response.status === 429 || response.status === 503) {\n if (attempt < maxRetries) {\n // Check for Retry-After header\n const retryAfter = response.headers.get('Retry-After');\n const waitTime = retryAfter \n ? parseInt(retryAfter) * 1000 \n : Math.min(delay, maxDelay);\n \n const error = new Error(`HTTP ${response.status}: Retrying after ${waitTime}ms`);\n if (onRetry) {\n onRetry(attempt + 1, error);\n }\n \n await sleep(waitTime);\n delay *= backoffMultiplier;\n continue;\n }\n }\n\n return response;\n } catch (error) {\n lastError = error as Error;\n \n // Check if error is retryable\n const isRetryable = retryableErrors.some(errType => \n lastError?.message?.includes(errType)\n );\n\n if (!isRetryable || attempt === maxRetries) {\n throw lastError;\n }\n\n // Exponential backoff\n const waitTime = Math.min(delay, maxDelay);\n if (onRetry) {\n onRetry(attempt + 1, lastError);\n }\n \n await sleep(waitTime);\n delay *= backoffMultiplier;\n }\n }\n\n throw lastError || new Error('Max retries exceeded');\n}\n\n/**\n * Add timeout to any promise\n * \n * @param promise - Promise to wrap with timeout\n * @param timeoutMs - Timeout in milliseconds\n * @param errorMessage - Optional custom error message\n * @returns Promise that rejects if timeout is reached\n * \n * @example\n * ```typescript\n * const result = await withTimeout(\n * fetchData(),\n * 5000,\n * 'Data fetch timed out'\n * );\n * ```\n */\nexport async function withTimeout<T>(\n promise: Promise<T>,\n timeoutMs: number,\n errorMessage?: string\n): Promise<T> {\n let timeoutId: NodeJS.Timeout | number;\n \n const timeoutPromise = new Promise<never>((_, reject) => {\n timeoutId = setTimeout(() => {\n reject(new Error(errorMessage || `Operation timed out after ${timeoutMs}ms`));\n }, timeoutMs);\n });\n\n try {\n const result = await Promise.race([promise, timeoutPromise]);\n clearTimeout(timeoutId!);\n return result;\n } catch (error) {\n clearTimeout(timeoutId!);\n throw error;\n }\n}\n\n/**\n * Sleep for specified milliseconds\n */\nfunction sleep(ms: number): Promise<void> {\n return new Promise(resolve => setTimeout(resolve, ms));\n}\n\n/**\n * Unified error type for all tools\n */\nexport class MorphError extends Error {\n constructor(\n message: string,\n public code: string,\n public statusCode?: number,\n public retryable: boolean = false\n ) {\n super(message);\n this.name = 'MorphError';\n }\n}\n\n\n","/**\n * Core implementation for intelligent model routing\n */\n\nimport { fetchWithRetry, withTimeout } from '../utils/resilience.js';\nimport type {\n RouterConfig,\n RouterInput,\n RouterResult,\n ComplexityLevel,\n RouterMode,\n Provider,\n} from './types.js';\n\nconst DEFAULT_CONFIG = {\n apiUrl: 'https://api.morphllm.com',\n timeout: 10000, // 10 seconds\n debug: false,\n};\n\nconst MODEL_MAPPINGS: Record<Provider, Record<RouterMode, Record<ComplexityLevel, string>>> = {\n openai: {\n balanced: {\n easy: 'gpt-5-mini',\n medium: 'gpt-5-low',\n hard: 'gpt-5-medium',\n 'needs-info': 'gpt-5-mini',\n },\n aggressive: {\n easy: 'gpt-5-low',\n medium: 'gpt-5-medium',\n hard: 'gpt-5-high',\n 'needs-info': 'gpt-5-mini',\n },\n },\n anthropic: {\n balanced: {\n easy: 'claude-4.5-haiku',\n medium: 'claude-4.5-haiku',\n hard: 'claude-4.5-sonnet',\n 'needs-info': 'claude-4.5-haiku',\n },\n aggressive: {\n easy: 'claude-4.5-haiku',\n medium: 'claude-4.5-sonnet',\n hard: 'claude-4.5-sonnet',\n 'needs-info': 'claude-4.5-haiku',\n },\n },\n gemini: {\n balanced: {\n easy: 'gemini-2.5-flash',\n medium: 'gemini-2.5-flash',\n hard: 'gemini-2.5-pro',\n 'needs-info': 'gemini-2.5-flash',\n },\n aggressive: {\n easy: 'gemini-2.5-flash',\n medium: 'gemini-2.5-pro',\n hard: 'gemini-2.5-pro',\n 'needs-info': 'gemini-2.5-flash',\n },\n },\n};\n\nabstract class BaseRouter {\n protected config: Required<Omit<RouterConfig, 'apiKey' | 'retryConfig'>> & Pick<RouterConfig, 'apiKey' | 'retryConfig'>;\n protected provider: Provider;\n\n constructor(provider: Provider, config: RouterConfig = {}) {\n this.provider = provider;\n this.config = {\n apiKey: config.apiKey,\n apiUrl: config.apiUrl || DEFAULT_CONFIG.apiUrl,\n timeout: config.timeout || DEFAULT_CONFIG.timeout,\n debug: config.debug || DEFAULT_CONFIG.debug,\n retryConfig: config.retryConfig,\n };\n }\n\n /**\n * Map backend complexity classification to actual model name\n */\n protected mapComplexityToModel(complexity: ComplexityLevel, mode: RouterMode): string {\n const mapping = MODEL_MAPPINGS[this.provider][mode];\n return mapping[complexity];\n }\n\n /**\n * Select the optimal model for a given input and mode\n */\n async selectModel(input: RouterInput): Promise<RouterResult> {\n const mode = input.mode || 'balanced';\n const apiKey = this.config.apiKey || process.env.MORPH_API_KEY;\n\n if (!apiKey) {\n throw new Error(\n 'Morph API key is required. Set MORPH_API_KEY environment variable or pass apiKey in config.'\n );\n }\n\n const url = `${this.config.apiUrl}/router/${this.provider}`;\n const payload = {\n input: input.input,\n mode,\n };\n\n if (this.config.debug) {\n console.log(`[ModelRouter] Requesting ${this.provider} model selection:`, {\n mode,\n inputLength: input.input.length,\n });\n }\n\n try {\n const fetchPromise = fetchWithRetry(\n url,\n {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n Authorization: `Bearer ${apiKey}`,\n },\n body: JSON.stringify(payload),\n },\n this.config.retryConfig\n );\n\n const response = await withTimeout(\n fetchPromise,\n this.config.timeout,\n `Router API request timed out after ${this.config.timeout}ms`\n );\n\n if (!response.ok) {\n const errorText = await response.text();\n throw new Error(\n `Router API error (${response.status}): ${errorText || response.statusText}`\n );\n }\n\n const apiResult: { model: ComplexityLevel; reasoning?: string } = await response.json();\n const actualModel = this.mapComplexityToModel(apiResult.model, mode);\n\n const result: RouterResult = {\n model: actualModel,\n reasoning: apiResult.reasoning,\n };\n\n if (this.config.debug) {\n console.log(`[ModelRouter] Complexity: ${apiResult.model}, Selected model: ${actualModel}`);\n }\n\n return result;\n } catch (error) {\n if (this.config.debug) {\n console.error(`[ModelRouter] Error selecting model:`, error);\n }\n throw error;\n }\n }\n}\n\n/**\n * OpenAI model router for GPT-5 series\n */\nexport class OpenAIRouter extends BaseRouter {\n constructor(config: RouterConfig = {}) {\n super('openai', config);\n }\n\n /**\n * Select optimal GPT-5 model\n * \n * @param input - User input and mode\n * @returns Selected model name (gpt-5-mini | gpt-5-low | gpt-5-medium | gpt-5-high)\n */\n async selectModel(input: RouterInput): Promise<RouterResult> {\n return super.selectModel(input);\n }\n}\n\n/**\n * Anthropic model router for Claude 4.5 series\n */\nexport class AnthropicRouter extends BaseRouter {\n constructor(config: RouterConfig = {}) {\n super('anthropic', config);\n }\n\n /**\n * Select optimal Claude model\n * \n * @param input - User input and mode\n * @returns Selected model name (claude-4.5-haiku | claude-4.5-sonnet)\n */\n async selectModel(input: RouterInput): Promise<RouterResult> {\n return super.selectModel(input);\n }\n}\n\n/**\n * Google Gemini model router\n */\nexport class GeminiRouter extends BaseRouter {\n constructor(config: RouterConfig = {}) {\n super('gemini', config);\n }\n\n /**\n * Select optimal Gemini model\n * \n * @param input - User input and mode\n * @returns Selected model name (gemini-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AAA;AAAA;AAAA;AAAA;AAAA,EAQA,MAAM,YAAY,OAA2C;AAC3D,WAAO,MAAM,YAAY,KAAK;AAAA,EAChC;AACF;AAKO,IAAM,eAAN,cAA2B,WAAW;AAAA,EAC3C,YAAY,SAAuB,CAAC,GAAG;AACrC,UAAM,UAAU,MAAM;AAAA,EACxB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,MAAM,YAAY,OAA2C;AAC3D,WAAO,MAAM,YAAY,KAAK;AAAA,EAChC;AACF;","names":[]}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import {
|
|
2
|
+
AnthropicRouter,
|
|
3
|
+
GeminiRouter,
|
|
4
|
+
OpenAIRouter
|
|
5
|
+
} from "../../chunk-OI5YYE36.js";
|
|
6
|
+
import "../../chunk-4VWJFZVS.js";
|
|
7
|
+
import "../../chunk-PZ5AY32C.js";
|
|
8
|
+
export {
|
|
9
|
+
AnthropicRouter,
|
|
10
|
+
GeminiRouter,
|
|
11
|
+
OpenAIRouter
|
|
12
|
+
};
|
|
13
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|