@morphllm/morphsdk 0.2.43 → 0.2.45
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/{chunk-3NTGAUTJ.js → chunk-CP4NZGRY.js} +8 -3
- package/dist/{chunk-3NTGAUTJ.js.map → chunk-CP4NZGRY.js.map} +1 -1
- package/dist/{chunk-O45X46VL.js → chunk-K6FQZZ2E.js} +11 -4
- package/dist/chunk-K6FQZZ2E.js.map +1 -0
- package/dist/{chunk-EYHXBQQX.js → chunk-LVY5LPEX.js} +70 -10
- package/dist/chunk-LVY5LPEX.js.map +1 -0
- package/dist/client.cjs +150 -9
- package/dist/client.cjs.map +1 -1
- package/dist/client.d.ts +2 -1
- package/dist/client.js +3 -3
- package/dist/index.cjs +154 -11
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +7 -5
- package/dist/modelrouter/core.cjs +7 -2
- package/dist/modelrouter/core.cjs.map +1 -1
- package/dist/modelrouter/core.d.ts +1 -1
- package/dist/modelrouter/core.js +1 -1
- package/dist/modelrouter/index.cjs +7 -2
- package/dist/modelrouter/index.cjs.map +1 -1
- package/dist/modelrouter/index.js +1 -1
- package/dist/modelrouter/types.cjs.map +1 -1
- package/dist/modelrouter/types.d.ts +1 -1
- package/dist/tools/browser/anthropic.cjs +1 -0
- package/dist/tools/browser/anthropic.cjs.map +1 -1
- package/dist/tools/browser/anthropic.js +1 -1
- package/dist/tools/browser/core.cjs +69 -9
- package/dist/tools/browser/core.cjs.map +1 -1
- package/dist/tools/browser/core.js +1 -1
- package/dist/tools/browser/index.cjs +69 -9
- package/dist/tools/browser/index.cjs.map +1 -1
- package/dist/tools/browser/index.js +1 -1
- package/dist/tools/browser/openai.cjs +1 -0
- package/dist/tools/browser/openai.cjs.map +1 -1
- package/dist/tools/browser/openai.js +1 -1
- package/dist/tools/browser/types.cjs.map +1 -1
- package/dist/tools/browser/types.d.ts +2 -0
- package/dist/tools/browser/vercel.cjs +1 -0
- package/dist/tools/browser/vercel.cjs.map +1 -1
- package/dist/tools/browser/vercel.js +1 -1
- package/package.json +1 -1
- package/dist/chunk-EYHXBQQX.js.map +0 -1
- package/dist/chunk-O45X46VL.js.map +0 -1
|
@@ -135,7 +135,7 @@ var RawRouter = class extends BaseRouter {
|
|
|
135
135
|
* Get raw difficulty classification
|
|
136
136
|
*
|
|
137
137
|
* @param input - User input and mode
|
|
138
|
-
* @returns Raw difficulty (easy | medium | hard |
|
|
138
|
+
* @returns Raw difficulty (easy | medium | hard | needs_info)
|
|
139
139
|
*/
|
|
140
140
|
async classify(input) {
|
|
141
141
|
const mode = input.mode || "balanced";
|
|
@@ -181,7 +181,12 @@ var RawRouter = class extends BaseRouter {
|
|
|
181
181
|
);
|
|
182
182
|
}
|
|
183
183
|
const apiResult = await response.json();
|
|
184
|
-
|
|
184
|
+
let difficulty;
|
|
185
|
+
if (apiResult.difficulty === "") {
|
|
186
|
+
difficulty = "medium";
|
|
187
|
+
} else {
|
|
188
|
+
difficulty = apiResult.difficulty || apiResult.model;
|
|
189
|
+
}
|
|
185
190
|
const result = {
|
|
186
191
|
difficulty
|
|
187
192
|
};
|
|
@@ -204,4 +209,4 @@ export {
|
|
|
204
209
|
GeminiRouter,
|
|
205
210
|
RawRouter
|
|
206
211
|
};
|
|
207
|
-
//# sourceMappingURL=chunk-
|
|
212
|
+
//# sourceMappingURL=chunk-CP4NZGRY.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../modelrouter/core.ts"],"sourcesContent":["/**\n * Core implementation for intelligent model routing\n */\n\nimport { fetchWithRetry, withTimeout } from '../tools/utils/resilience.js';\nimport type {\n RouterConfig,\n RouterInput,\n RouterResult,\n RawRouterResult,\n ComplexityLevel,\n RouterMode,\n Provider,\n} from './types.js';\n\nconst DEFAULT_CONFIG = {\n apiUrl: 'https://api.morphllm.com',\n timeout: 5000, // 5 seconds (responses typically <500ms)\n debug: false,\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 * 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}/v1/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: string; confidence?: number } = await response.json();\n\n const result: RouterResult = {\n model: apiResult.model,\n };\n\n if (this.config.debug) {\n console.log(`[ModelRouter] Selected model: ${apiResult.model}, Confidence: ${apiResult.confidence?.toFixed(3)}`);\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/**\n * Raw difficulty classification router (no provider-specific mapping)\n */\nexport class RawRouter extends BaseRouter {\n constructor(config: RouterConfig = {}) {\n super('raw' as Provider, config);\n }\n\n /**\n * Get raw difficulty classification\n * \n * @param input - User input and mode\n * @returns Raw difficulty (easy | medium | hard | needs-info)\n */\n async classify(input: RouterInput): Promise<RawRouterResult> {\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}/v1/router/raw`;\n const payload = {\n input: input.input,\n mode,\n };\n\n if (this.config.debug) {\n console.log(`[RawRouter] Requesting raw difficulty classification:`, {\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?: string; difficulty?: string; confidence?: number } = await response.json();\n\n // Support both 'model' and 'difficulty' fields for compatibility\n const difficulty = (apiResult.difficulty || apiResult.model) as ComplexityLevel;\n\n const result: RawRouterResult = {\n difficulty,\n };\n\n if (this.config.debug) {\n console.log(`[RawRouter] Classified as: ${difficulty}`);\n }\n\n return result;\n } catch (error) {\n if (this.config.debug) {\n console.error(`[RawRouter] Error classifying:`, error);\n }\n throw error;\n }\n }\n}\n"],"mappings":";;;;;;AAeA,IAAM,iBAAiB;AAAA,EACrB,QAAQ;AAAA,EACR,SAAS;AAAA;AAAA,EACT,OAAO;AACT;AAEA,IAAe,aAAf,MAA0B;AAAA,EACd;AAAA,EACA;AAAA,EAEV,YAAY,UAAoB,SAAuB,CAAC,GAAG;AACzD,SAAK,WAAW;AAChB,SAAK,SAAS;AAAA,MACZ,QAAQ,OAAO;AAAA,MACf,QAAQ,OAAO,UAAU,eAAe;AAAA,MACxC,SAAS,OAAO,WAAW,eAAe;AAAA,MAC1C,OAAO,OAAO,SAAS,eAAe;AAAA,MACtC,aAAa,OAAO;AAAA,IACtB;AAAA,EACF;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,YAAY,OAA2C;AAC3D,UAAM,OAAO,MAAM,QAAQ;AAC3B,UAAM,SAAS,KAAK,OAAO,UAAU,QAAQ,IAAI;AAEjD,QAAI,CAAC,QAAQ;AACX,YAAM,IAAI;AAAA,QACR;AAAA,MACF;AAAA,IACF;AAEA,UAAM,MAAM,GAAG,KAAK,OAAO,MAAM,cAAc,KAAK,QAAQ;AAC5D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;AAAA,UACA,MAAM,KAAK,UAAU,OAAO;AAAA,QAC9B;AAAA,QACA,KAAK,OAAO;AAAA,MACd;AAEA,YAAM,WAAW,MAAM;AAAA,QACrB;AAAA,QACA,KAAK,OAAO;AAAA,QACZ,sCAAsC,KAAK,OAAO,OAAO;AAAA,MAC3D;AAEA,UAAI,CAAC,SAAS,IAAI;AAChB,cAAM,YAAY,MAAM,SAAS,KAAK;AACtC,cAAM,IAAI;AAAA,UACR,qBAAqB,SAAS,MAAM,MAAM,aAAa,SAAS,UAAU;AAAA,QAC5E;AAAA,MACF;AAEA,YAAM,YAA0E,MAAM,SAAS,KAAK;AAGpG,YAAM,aAAc,UAAU,cAAc,UAAU;AAEtD,YAAM,SAA0B;AAAA,QAC9B;AAAA,MACF;AAEA,UAAI,KAAK,OAAO,OAAO;AACrB,gBAAQ,IAAI,8BAA8B,UAAU,EAAE;AAAA,MACxD;AAEA,aAAO;AAAA,IACT,SAAS,OAAO;AACd,UAAI,KAAK,OAAO,OAAO;AACrB,gBAAQ,MAAM,kCAAkC,KAAK;AAAA,MACvD;AACA,YAAM;AAAA,IACR;AAAA,EACF;AACF;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../modelrouter/core.ts"],"sourcesContent":["/**\n * Core implementation for intelligent model routing\n */\n\nimport { fetchWithRetry, withTimeout } from '../tools/utils/resilience.js';\nimport type {\n RouterConfig,\n RouterInput,\n RouterResult,\n RawRouterResult,\n ComplexityLevel,\n RouterMode,\n Provider,\n} from './types.js';\n\nconst DEFAULT_CONFIG = {\n apiUrl: 'https://api.morphllm.com',\n timeout: 5000, // 5 seconds (responses typically <500ms)\n debug: false,\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 * 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}/v1/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: string; confidence?: number } = await response.json();\n\n const result: RouterResult = {\n model: apiResult.model,\n };\n\n if (this.config.debug) {\n console.log(`[ModelRouter] Selected model: ${apiResult.model}, Confidence: ${apiResult.confidence?.toFixed(3)}`);\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/**\n * Raw difficulty classification router (no provider-specific mapping)\n */\nexport class RawRouter extends BaseRouter {\n constructor(config: RouterConfig = {}) {\n super('raw' as Provider, config);\n }\n\n /**\n * Get raw difficulty classification\n * \n * @param input - User input and mode\n * @returns Raw difficulty (easy | medium | hard | needs_info)\n */\n async classify(input: RouterInput): Promise<RawRouterResult> {\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}/v1/router/raw`;\n const payload = {\n input: input.input,\n mode,\n };\n\n if (this.config.debug) {\n console.log(`[RawRouter] Requesting raw difficulty classification:`, {\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?: string; difficulty?: string; confidence?: number } = await response.json();\n\n // Support both 'model' and 'difficulty' fields for compatibility\n // Empty string from API means \"medium\" difficulty (API bug workaround)\n let difficulty: ComplexityLevel;\n if (apiResult.difficulty === '') {\n difficulty = 'medium';\n } else {\n difficulty = (apiResult.difficulty || apiResult.model) as ComplexityLevel;\n }\n\n const result: RawRouterResult = {\n difficulty,\n };\n\n if (this.config.debug) {\n console.log(`[RawRouter] Classified as: ${difficulty}`);\n }\n\n return result;\n } catch (error) {\n if (this.config.debug) {\n console.error(`[RawRouter] Error classifying:`, error);\n }\n throw error;\n }\n }\n}\n"],"mappings":";;;;;;AAeA,IAAM,iBAAiB;AAAA,EACrB,QAAQ;AAAA,EACR,SAAS;AAAA;AAAA,EACT,OAAO;AACT;AAEA,IAAe,aAAf,MAA0B;AAAA,EACd;AAAA,EACA;AAAA,EAEV,YAAY,UAAoB,SAAuB,CAAC,GAAG;AACzD,SAAK,WAAW;AAChB,SAAK,SAAS;AAAA,MACZ,QAAQ,OAAO;AAAA,MACf,QAAQ,OAAO,UAAU,eAAe;AAAA,MACxC,SAAS,OAAO,WAAW,eAAe;AAAA,MAC1C,OAAO,OAAO,SAAS,eAAe;AAAA,MACtC,aAAa,OAAO;AAAA,IACtB;AAAA,EACF;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,YAAY,OAA2C;AAC3D,UAAM,OAAO,MAAM,QAAQ;AAC3B,UAAM,SAAS,KAAK,OAAO,UAAU,QAAQ,IAAI;AAEjD,QAAI,CAAC,QAAQ;AACX,YAAM,IAAI;AAAA,QACR;AAAA,MACF;AAAA,IACF;AAEA,UAAM,MAAM,GAAG,KAAK,OAAO,MAAM,cAAc,KAAK,QAAQ;AAC5D,UAAM,UAAU;AAAA,MACd,OAAO,MAAM;AAAA,MACb;AAAA,IACF;AAEA,QAAI,KAAK,OAAO,OAAO;AACrB,cAAQ,IAAI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;AAAA,QACrB;AAAA,QACA,KAAK,OAAO;AAAA,QACZ,sCAAsC,KAAK,OAAO,OAAO;AAAA,MAC3D;AAEA,UAAI,CAAC,SAAS,IAAI;AAChB,cAAM,YAAY,MAAM,SAAS,KAAK;AACtC,cAAM,IAAI;AAAA,UACR,qBAAqB,SAAS,MAAM,MAAM,aAAa,SAAS,UAAU;AAAA,QAC5E;AAAA,MACF;AAEA,YAAM,YAA0E,MAAM,SAAS,KAAK;AAIpG,UAAI;AACJ,UAAI,UAAU,eAAe,IAAI;AAC/B,qBAAa;AAAA,MACf,OAAO;AACL,qBAAc,UAAU,cAAc,UAAU;AAAA,MAClD;AAEA,YAAM,SAA0B;AAAA,QAC9B;AAAA,MACF;AAEA,UAAI,KAAK,OAAO,OAAO;AACrB,gBAAQ,IAAI,8BAA8B,UAAU,EAAE;AAAA,MACxD;AAEA,aAAO;AAAA,IACT,SAAS,OAAO;AACd,UAAI,KAAK,OAAO,OAAO;AACrB,gBAAQ,MAAM,kCAAkC,KAAK;AAAA,MACvD;AACA,YAAM;AAAA,IACR;AAAA,EACF;AACF;","names":[]}
|
|
@@ -6,15 +6,16 @@ import {
|
|
|
6
6
|
} from "./chunk-64PMM72R.js";
|
|
7
7
|
import {
|
|
8
8
|
BrowserClient
|
|
9
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-LVY5LPEX.js";
|
|
10
10
|
import {
|
|
11
11
|
MorphGit
|
|
12
12
|
} from "./chunk-GDR65N2J.js";
|
|
13
13
|
import {
|
|
14
14
|
AnthropicRouter,
|
|
15
15
|
GeminiRouter,
|
|
16
|
-
OpenAIRouter
|
|
17
|
-
|
|
16
|
+
OpenAIRouter,
|
|
17
|
+
RawRouter
|
|
18
|
+
} from "./chunk-CP4NZGRY.js";
|
|
18
19
|
|
|
19
20
|
// client.ts
|
|
20
21
|
var MorphClient = class {
|
|
@@ -86,6 +87,12 @@ var MorphClient = class {
|
|
|
86
87
|
debug: config.debug,
|
|
87
88
|
timeout: config.timeout,
|
|
88
89
|
retryConfig: config.retryConfig
|
|
90
|
+
}),
|
|
91
|
+
raw: new RawRouter({
|
|
92
|
+
apiKey: config.apiKey,
|
|
93
|
+
debug: config.debug,
|
|
94
|
+
timeout: config.timeout,
|
|
95
|
+
retryConfig: config.retryConfig
|
|
89
96
|
})
|
|
90
97
|
};
|
|
91
98
|
}
|
|
@@ -94,4 +101,4 @@ var MorphClient = class {
|
|
|
94
101
|
export {
|
|
95
102
|
MorphClient
|
|
96
103
|
};
|
|
97
|
-
//# sourceMappingURL=chunk-
|
|
104
|
+
//# sourceMappingURL=chunk-K6FQZZ2E.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../client.ts"],"sourcesContent":["/**\n * Unified Morph SDK Client\n * \n * Provides access to all Morph tools through a single interface\n * \n * @example\n * ```typescript\n * import { MorphClient } from '@cuda_oom/morphsdk';\n * \n * const morph = new MorphClient({ \n * apiKey: process.env.MORPH_API_KEY,\n * debug: true,\n * timeout: 60000\n * });\n * \n * // Use FastApply\n * const editResult = await morph.fastApply.execute({\n * target_filepath: 'src/index.ts',\n * instructions: 'Add error handling',\n * code_edit: 'try { ... } catch (e) { ... }'\n * });\n * \n * // Use CodebaseSearch\n * const searchResult = await morph.codebaseSearch.search({\n * query: 'authentication logic',\n * repoId: 'my-project'\n * });\n * \n * // Use Browser automation\n * const browserResult = await morph.browser.execute({\n * task: 'Test the checkout flow',\n * url: 'https://example.com'\n * });\n * \n * // Use Model Router\n * const { model } = await morph.routers.openai.selectModel({\n * input: 'Complex refactoring task',\n * mode: 'balanced'\n * });\n * ```\n */\n\nimport type { RetryConfig } from './tools/utils/resilience.js';\nimport { FastApplyClient } from './tools/fastapply/core.js';\nimport { CodebaseSearchClient } from './tools/codebase_search/core.js';\nimport { BrowserClient } from './tools/browser/core.js';\nimport { MorphGit } from './git/index.js';\nimport { OpenAIRouter, AnthropicRouter, GeminiRouter, RawRouter } from './modelrouter/core.js';\n\n/**\n * Configuration for the MorphClient\n */\nexport interface MorphClientConfig {\n /** Morph API key for authentication (defaults to MORPH_API_KEY env var) */\n apiKey?: string;\n /** Enable debug logging across all tools */\n debug?: boolean;\n /** Default timeout in milliseconds for API requests */\n timeout?: number;\n /** Retry configuration for failed requests */\n retryConfig?: RetryConfig;\n}\n\n/**\n * Unified Morph SDK Client\n * \n * Provides access to all Morph tools through a single interface:\n * - fastApply: AI-powered file editing with intelligent merging\n * - codebaseSearch: Semantic code search\n * - browser: AI-powered browser automation\n * - git: Version control operations\n * - routers: Intelligent model selection (OpenAI, Anthropic, Gemini)\n */\nexport class MorphClient {\n /** Client configuration */\n public config: MorphClientConfig;\n\n /** FastApply tool for editing files with AI-powered merge */\n public fastApply: FastApplyClient;\n\n /** CodebaseSearch tool for semantic code search */\n public codebaseSearch: CodebaseSearchClient;\n\n /** Browser tool for AI-powered browser automation */\n public browser: BrowserClient;\n\n /** Git tool for version control operations */\n public git: MorphGit;\n\n /** Model routers for intelligent model selection */\n public routers: {\n openai: OpenAIRouter;\n anthropic: AnthropicRouter;\n gemini: GeminiRouter;\n raw: RawRouter;\n };\n\n /**\n * Create a new Morph SDK client\n * \n * @param config - Client configuration (apiKey, debug, timeout, retryConfig)\n * \n * @example\n * ```typescript\n * const morph = new MorphClient({ \n * apiKey: process.env.MORPH_API_KEY,\n * debug: true,\n * timeout: 60000\n * });\n * ```\n */\n constructor(config: MorphClientConfig = {}) {\n this.config = config;\n\n // Initialize all sub-clients with shared config\n this.fastApply = new FastApplyClient({\n apiKey: config.apiKey,\n debug: config.debug,\n timeout: config.timeout,\n retryConfig: config.retryConfig,\n });\n\n this.codebaseSearch = new CodebaseSearchClient({\n apiKey: config.apiKey,\n debug: config.debug,\n timeout: config.timeout,\n retryConfig: config.retryConfig,\n });\n\n this.browser = new BrowserClient({\n apiKey: config.apiKey,\n debug: config.debug,\n timeout: config.timeout,\n retryConfig: config.retryConfig,\n });\n\n this.git = new MorphGit({\n apiKey: config.apiKey,\n retryConfig: config.retryConfig,\n });\n\n this.routers = {\n openai: new OpenAIRouter({\n apiKey: config.apiKey,\n debug: config.debug,\n timeout: config.timeout,\n retryConfig: config.retryConfig,\n }),\n anthropic: new AnthropicRouter({\n apiKey: config.apiKey,\n debug: config.debug,\n timeout: config.timeout,\n retryConfig: config.retryConfig,\n }),\n gemini: new GeminiRouter({\n apiKey: config.apiKey,\n debug: config.debug,\n timeout: config.timeout,\n retryConfig: config.retryConfig,\n }),\n raw: new RawRouter({\n apiKey: config.apiKey,\n debug: config.debug,\n timeout: config.timeout,\n retryConfig: config.retryConfig,\n }),\n };\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAyEO,IAAM,cAAN,MAAkB;AAAA;AAAA,EAEhB;AAAA;AAAA,EAGA;AAAA;AAAA,EAGA;AAAA;AAAA,EAGA;AAAA;AAAA,EAGA;AAAA;AAAA,EAGA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAqBP,YAAY,SAA4B,CAAC,GAAG;AAC1C,SAAK,SAAS;AAGd,SAAK,YAAY,IAAI,gBAAgB;AAAA,MACnC,QAAQ,OAAO;AAAA,MACf,OAAO,OAAO;AAAA,MACd,SAAS,OAAO;AAAA,MAChB,aAAa,OAAO;AAAA,IACtB,CAAC;AAED,SAAK,iBAAiB,IAAI,qBAAqB;AAAA,MAC7C,QAAQ,OAAO;AAAA,MACf,OAAO,OAAO;AAAA,MACd,SAAS,OAAO;AAAA,MAChB,aAAa,OAAO;AAAA,IACtB,CAAC;AAED,SAAK,UAAU,IAAI,cAAc;AAAA,MAC/B,QAAQ,OAAO;AAAA,MACf,OAAO,OAAO;AAAA,MACd,SAAS,OAAO;AAAA,MAChB,aAAa,OAAO;AAAA,IACtB,CAAC;AAED,SAAK,MAAM,IAAI,SAAS;AAAA,MACtB,QAAQ,OAAO;AAAA,MACf,aAAa,OAAO;AAAA,IACtB,CAAC;AAED,SAAK,UAAU;AAAA,MACb,QAAQ,IAAI,aAAa;AAAA,QACvB,QAAQ,OAAO;AAAA,QACf,OAAO,OAAO;AAAA,QACd,SAAS,OAAO;AAAA,QAChB,aAAa,OAAO;AAAA,MACtB,CAAC;AAAA,MACD,WAAW,IAAI,gBAAgB;AAAA,QAC7B,QAAQ,OAAO;AAAA,QACf,OAAO,OAAO;AAAA,QACd,SAAS,OAAO;AAAA,QAChB,aAAa,OAAO;AAAA,MACtB,CAAC;AAAA,MACD,QAAQ,IAAI,aAAa;AAAA,QACvB,QAAQ,OAAO;AAAA,QACf,OAAO,OAAO;AAAA,QACd,SAAS,OAAO;AAAA,QAChB,aAAa,OAAO;AAAA,MACtB,CAAC;AAAA,MACD,KAAK,IAAI,UAAU;AAAA,QACjB,QAAQ,OAAO;AAAA,QACf,OAAO,OAAO;AAAA,QACd,SAAS,OAAO;AAAA,QAChB,aAAa,OAAO;AAAA,MACtB,CAAC;AAAA,IACH;AAAA,EACF;AACF;","names":[]}
|
|
@@ -31,15 +31,46 @@ var BrowserClient = class {
|
|
|
31
31
|
return executeBrowserTask(input, this.config);
|
|
32
32
|
}
|
|
33
33
|
async createTask(input) {
|
|
34
|
+
const apiUrl = this.config.apiUrl || DEFAULT_CONFIG.apiUrl;
|
|
35
|
+
const debug = this.config.debug || false;
|
|
36
|
+
if (debug) {
|
|
37
|
+
console.log(`[Browser] createTask: "${input.task.slice(0, 60)}..." url=${input.url || "none"}`);
|
|
38
|
+
console.log(`[Browser] Calling async endpoint: ${apiUrl}/browser-task/async`);
|
|
39
|
+
}
|
|
40
|
+
const headers = { "Content-Type": "application/json" };
|
|
41
|
+
if (this.config.apiKey) headers["Authorization"] = `Bearer ${this.config.apiKey}`;
|
|
42
|
+
const response = await fetch(`${apiUrl}/browser-task/async`, {
|
|
43
|
+
method: "POST",
|
|
44
|
+
headers,
|
|
45
|
+
body: JSON.stringify({
|
|
46
|
+
task: input.task,
|
|
47
|
+
url: input.url,
|
|
48
|
+
max_steps: input.max_steps ?? 10,
|
|
49
|
+
model: input.model ?? "morph-computer-use-v0",
|
|
50
|
+
viewport_width: input.viewport_width ?? 1280,
|
|
51
|
+
viewport_height: input.viewport_height ?? 720,
|
|
52
|
+
external_id: input.external_id,
|
|
53
|
+
repo_id: input.repo_id,
|
|
54
|
+
commit_id: input.commit_id,
|
|
55
|
+
record_video: input.record_video ?? false,
|
|
56
|
+
video_width: input.video_width ?? input.viewport_width ?? 1280,
|
|
57
|
+
video_height: input.video_height ?? input.viewport_height ?? 720,
|
|
58
|
+
allow_resizing: input.allow_resizing ?? false,
|
|
59
|
+
structured_output: "schema" in input ? stringifyStructuredOutput(input.schema) : void 0
|
|
60
|
+
})
|
|
61
|
+
});
|
|
62
|
+
if (!response.ok) {
|
|
63
|
+
const errorText = await response.text().catch(() => response.statusText);
|
|
64
|
+
if (debug) console.error(`[Browser] Error: ${response.status} - ${errorText}`);
|
|
65
|
+
throw new Error(`HTTP ${response.status}: ${errorText}`);
|
|
66
|
+
}
|
|
67
|
+
const result = await response.json();
|
|
68
|
+
if (debug) {
|
|
69
|
+
console.log(`[Browser] \u2705 Task created: recording_id=${result.recording_id ?? "none"} debug_url=${result.debugUrl ? "available" : "none"}`);
|
|
70
|
+
}
|
|
34
71
|
if ("schema" in input) {
|
|
35
|
-
const taskInput = {
|
|
36
|
-
...input,
|
|
37
|
-
structured_output: stringifyStructuredOutput(input.schema)
|
|
38
|
-
};
|
|
39
|
-
const result = await executeBrowserTask(taskInput, this.config);
|
|
40
72
|
return wrapTaskResponseWithSchema(result, this.config, input.schema);
|
|
41
73
|
} else {
|
|
42
|
-
const result = await executeBrowserTask(input, this.config);
|
|
43
74
|
return wrapTaskResponse(result, this.config);
|
|
44
75
|
}
|
|
45
76
|
}
|
|
@@ -116,6 +147,7 @@ async function executeBrowserTask(input, config = {}) {
|
|
|
116
147
|
record_video: input.record_video ?? false,
|
|
117
148
|
video_width: input.video_width ?? input.viewport_width ?? 1280,
|
|
118
149
|
video_height: input.video_height ?? input.viewport_height ?? 720,
|
|
150
|
+
allow_resizing: input.allow_resizing ?? false,
|
|
119
151
|
structured_output: input.structured_output
|
|
120
152
|
})
|
|
121
153
|
},
|
|
@@ -309,7 +341,21 @@ function wrapTaskResponse(result, config) {
|
|
|
309
341
|
task_id: result.task_id || "",
|
|
310
342
|
liveUrl: result.task_id ? generateLiveUrl(result.task_id, config) : result.debugUrl || "",
|
|
311
343
|
complete: async (pollConfig) => {
|
|
312
|
-
|
|
344
|
+
if (result.task_id) {
|
|
345
|
+
return pollTaskUntilComplete(result.task_id, config, pollConfig);
|
|
346
|
+
}
|
|
347
|
+
if (result.recording_id) {
|
|
348
|
+
const recording = await waitForRecording(
|
|
349
|
+
result.recording_id,
|
|
350
|
+
config,
|
|
351
|
+
pollConfig
|
|
352
|
+
);
|
|
353
|
+
return {
|
|
354
|
+
...result,
|
|
355
|
+
recording_status: recording.status
|
|
356
|
+
};
|
|
357
|
+
}
|
|
358
|
+
throw new Error("Cannot poll completion: no task_id or recording_id available");
|
|
313
359
|
},
|
|
314
360
|
// Add Steel live session helpers - either functional or error-throwing
|
|
315
361
|
getLiveUrl: result.debugUrl ? (options) => buildLiveUrl(result.debugUrl, options) : () => {
|
|
@@ -340,8 +386,22 @@ function wrapTaskResponseWithSchema(result, config, schema) {
|
|
|
340
386
|
task_id: result.task_id || "",
|
|
341
387
|
liveUrl: result.task_id ? generateLiveUrl(result.task_id, config) : result.debugUrl || "",
|
|
342
388
|
complete: async (pollConfig) => {
|
|
343
|
-
|
|
344
|
-
|
|
389
|
+
if (result.task_id) {
|
|
390
|
+
const finalResult = await pollTaskUntilComplete(result.task_id, config, pollConfig);
|
|
391
|
+
return parseStructuredTaskOutput(finalResult, schema);
|
|
392
|
+
}
|
|
393
|
+
if (result.recording_id) {
|
|
394
|
+
const recording = await waitForRecording(
|
|
395
|
+
result.recording_id,
|
|
396
|
+
config,
|
|
397
|
+
pollConfig
|
|
398
|
+
);
|
|
399
|
+
return {
|
|
400
|
+
...parsed,
|
|
401
|
+
recording_status: recording.status
|
|
402
|
+
};
|
|
403
|
+
}
|
|
404
|
+
throw new Error("Cannot poll completion: no task_id or recording_id available");
|
|
345
405
|
},
|
|
346
406
|
// Add Steel live session helpers - either functional or error-throwing
|
|
347
407
|
getLiveUrl: result.debugUrl ? (options) => buildLiveUrl(result.debugUrl, options) : () => {
|
|
@@ -402,4 +462,4 @@ export {
|
|
|
402
462
|
getErrors,
|
|
403
463
|
checkHealth
|
|
404
464
|
};
|
|
405
|
-
//# sourceMappingURL=chunk-
|
|
465
|
+
//# sourceMappingURL=chunk-LVY5LPEX.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../tools/browser/core.ts"],"sourcesContent":["/**\n * Core implementation for browser automation tasks\n */\n\nimport { fetchWithRetry, withTimeout } from '../utils/resilience.js';\nimport type {\n BrowserConfig,\n BrowserTaskInput,\n BrowserTaskInputWithSchema,\n BrowserTaskResult,\n BrowserTaskWithPromise,\n BrowserTaskWithPromiseAndSchema,\n RecordingStatus,\n ErrorsResponse,\n LiveSessionOptions,\n IframeOptions,\n} from './types.js';\nimport { buildLiveUrl, buildLiveIframe, buildEmbedCode, resolvePreset } from './live.js';\n\nconst DEFAULT_CONFIG = {\n apiUrl: process.env.MORPH_ENVIRONMENT === 'DEV' \n ? 'http://localhost:8000'\n : 'https://browser.morphllm.com',\n timeout: 1000000, // 10 minutes for complex tasks\n debug: false,\n};\n\n/**\n * BrowserClient class for easier usage with instance configuration\n */\nexport class BrowserClient {\n private config: BrowserConfig;\n\n constructor(config: BrowserConfig = {}) {\n this.config = {\n ...DEFAULT_CONFIG,\n ...config,\n };\n }\n\n /**\n * Execute a browser automation task\n */\n async execute(input: BrowserTaskInput): Promise<BrowserTaskResult> {\n return executeBrowserTask(input, this.config);\n }\n\n async createTask(input: BrowserTaskInput): Promise<BrowserTaskWithPromise>;\n async createTask<T>(input: BrowserTaskInputWithSchema<T>): Promise<BrowserTaskWithPromiseAndSchema<T>>;\n async createTask<T>(\n input: BrowserTaskInput | BrowserTaskInputWithSchema<T>\n ): Promise<BrowserTaskWithPromise | BrowserTaskWithPromiseAndSchema<T>> {\n const apiUrl = this.config.apiUrl || DEFAULT_CONFIG.apiUrl;\n const debug = this.config.debug || false;\n \n if (debug) {\n console.log(`[Browser] createTask: \"${input.task.slice(0, 60)}...\" url=${input.url || 'none'}`);\n console.log(`[Browser] Calling async endpoint: ${apiUrl}/browser-task/async`);\n }\n \n const headers: Record<string, string> = { 'Content-Type': 'application/json' };\n if (this.config.apiKey) headers['Authorization'] = `Bearer ${this.config.apiKey}`;\n \n // Call ASYNC endpoint for immediate return with live URL\n const response = await fetch(`${apiUrl}/browser-task/async`, {\n method: 'POST',\n headers,\n body: JSON.stringify({\n task: input.task,\n url: input.url,\n max_steps: input.max_steps ?? 10,\n model: input.model ?? 'morph-computer-use-v0',\n viewport_width: input.viewport_width ?? 1280,\n viewport_height: input.viewport_height ?? 720,\n external_id: input.external_id,\n repo_id: input.repo_id,\n commit_id: input.commit_id,\n record_video: input.record_video ?? false,\n video_width: input.video_width ?? input.viewport_width ?? 1280,\n video_height: input.video_height ?? input.viewport_height ?? 720,\n allow_resizing: input.allow_resizing ?? false,\n structured_output: 'schema' in input ? stringifyStructuredOutput(input.schema) : undefined,\n }),\n });\n \n if (!response.ok) {\n const errorText = await response.text().catch(() => response.statusText);\n if (debug) console.error(`[Browser] Error: ${response.status} - ${errorText}`);\n throw new Error(`HTTP ${response.status}: ${errorText}`);\n }\n \n const result = await response.json();\n \n if (debug) {\n console.log(`[Browser] ✅ Task created: recording_id=${result.recording_id ?? 'none'} debug_url=${result.debugUrl ? 'available' : 'none'}`);\n }\n \n if ('schema' in input) {\n return wrapTaskResponseWithSchema(result, this.config, input.schema);\n } else {\n return wrapTaskResponse(result, this.config);\n }\n }\n\n /**\n * Execute task with recording and wait for video to be ready\n */\n async executeWithRecording(\n input: BrowserTaskInput & { record_video: true }\n ): Promise<BrowserTaskResult & { recording?: RecordingStatus }> {\n return executeWithRecording(input, this.config);\n }\n\n /**\n * Get recording status and URLs\n */\n async getRecording(recordingId: string): Promise<RecordingStatus> {\n return getRecording(recordingId, this.config);\n }\n\n /**\n * Wait for recording to complete with automatic polling\n */\n async waitForRecording(\n recordingId: string,\n options?: { timeout?: number; pollInterval?: number }\n ): Promise<RecordingStatus> {\n return waitForRecording(recordingId, this.config, options);\n }\n\n /**\n * Get errors from recording with screenshots\n */\n async getErrors(recordingId: string): Promise<ErrorsResponse> {\n return getErrors(recordingId, this.config);\n }\n\n /**\n * Check if browser worker service is healthy\n */\n async checkHealth(): Promise<{\n ok: boolean;\n google_configured: boolean;\n database_configured: boolean;\n s3_configured: boolean;\n error?: string;\n }> {\n return checkHealth(this.config);\n }\n}\n\n/**\n * Execute a natural language browser automation task\n * \n * Returns the full task result including rich agent history data (urls, errors, \n * action_history, judgement, etc.). When using this as an agent tool, use the\n * formatResult() functions from the SDK adapters to return a concise summary.\n * \n * @param input - Task parameters\n * @param config - Optional configuration (apiKey, apiUrl to override default)\n * @returns Task result with success status, findings, and comprehensive execution history\n * \n * @example\n * ```typescript\n * const result = await executeBrowserTask(\n * {\n * task: \"Test checkout flow for buying a pineapple\",\n * url: \"https://3000-abc.e2b.dev\",\n * max_steps: 20,\n * repo_id: \"my-project\",\n * commit_id: \"uuid-here\"\n * },\n * {\n * apiKey: process.env.MORPH_API_KEY,\n * // apiUrl: 'http://localhost:8001' // Override for local testing\n * }\n * );\n * \n * if (result.success) {\n * console.log('Task completed:', result.result);\n * console.log('URLs visited:', result.urls);\n * console.log('Actions taken:', result.action_names);\n * console.log('Has errors:', result.has_errors);\n * console.log('Replay:', result.replay_url);\n * }\n * ```\n */\nexport async function executeBrowserTask(\n input: BrowserTaskInput,\n config: BrowserConfig = {}\n): Promise<BrowserTaskResult> {\n const apiUrl = config.apiUrl || DEFAULT_CONFIG.apiUrl;\n const timeout = config.timeout || DEFAULT_CONFIG.timeout;\n const debug = config.debug || false;\n\n if (!input.task || input.task.trim().length === 0) {\n return { \n success: false, \n error: 'Task description is required. Example: \"Go to example.com and click the login button\"' \n };\n }\n\n if (input.max_steps !== undefined && (input.max_steps < 1 || input.max_steps > 50)) {\n return { \n success: false, \n error: 'max_steps must be between 1 and 50. Use more steps for complex multi-page flows.' \n };\n }\n\n if (debug) {\n console.log(`[Browser] Task: \"${input.task.slice(0, 60)}...\" url=${input.url || 'none'} maxSteps=${input.max_steps ?? 10}`);\n console.log(`[Browser] Recording: ${input.record_video ? 'yes' : 'no'} | Calling ${apiUrl}/browser-task`);\n }\n\n const startTime = Date.now();\n\n try {\n const headers: Record<string, string> = { 'Content-Type': 'application/json' };\n if (config.apiKey) headers['Authorization'] = `Bearer ${config.apiKey}`;\n\n const fetchPromise = fetchWithRetry(\n `${apiUrl}/browser-task`,\n {\n method: 'POST',\n headers,\n body: JSON.stringify({\n task: input.task,\n url: input.url,\n max_steps: input.max_steps ?? 10,\n model: input.model ?? 'morph-computer-use-v0',\n viewport_width: input.viewport_width ?? 1280,\n viewport_height: input.viewport_height ?? 720,\n external_id: input.external_id,\n repo_id: input.repo_id,\n commit_id: input.commit_id,\n record_video: input.record_video ?? false,\n video_width: input.video_width ?? input.viewport_width ?? 1280,\n video_height: input.video_height ?? input.viewport_height ?? 720,\n allow_resizing: input.allow_resizing ?? false,\n structured_output: input.structured_output,\n }),\n },\n config.retryConfig\n );\n\n const response = await withTimeout(\n fetchPromise,\n timeout,\n `Browser task timed out after ${timeout}ms. Consider increasing timeout or reducing max_steps.`\n );\n\n if (!response.ok) {\n const errorText = await response.text().catch(() => response.statusText);\n if (debug) console.error(`[Browser] Error: ${response.status} - ${errorText}`);\n throw new Error(`HTTP ${response.status}: ${errorText}`);\n }\n\n const result: BrowserTaskResult = await response.json();\n const elapsed = Date.now() - startTime;\n \n if (debug) {\n console.log(`[Browser] ✅ ${result.success ? 'Success' : 'Failed'} in ${elapsed}ms | steps=${result.steps_taken ?? 0} recordingId=${result.recording_id ?? 'none'}`);\n }\n\n return result;\n\n } catch (error) {\n if (error instanceof Error) {\n // Handle network errors\n if (error.message.includes('ECONNREFUSED') || error.message.includes('fetch failed')) {\n return {\n success: false,\n error: `Cannot connect to browser worker at ${apiUrl}. Ensure the service is running and accessible. For local dev, set MORPH_ENVIRONMENT=DEV.`,\n };\n }\n\n return {\n success: false,\n error: error.message,\n };\n }\n\n return {\n success: false,\n error: String(error),\n };\n }\n}\n\n/**\n * Get recording status and video URL\n * \n * @param recordingId - Recording UUID from BrowserTaskResult\n * @param config - Configuration with apiKey\n * @returns Recording status with video URL when ready\n * \n * @example\n * ```typescript\n * const status = await getRecording('uuid-here', { apiKey: 'key' });\n * if (status.status === 'COMPLETED' && status.video_url) {\n * console.log('Video ready:', status.video_url);\n * }\n * ```\n */\nexport async function getRecording(\n recordingId: string,\n config: BrowserConfig = {}\n): Promise<RecordingStatus> {\n const apiUrl = config.apiUrl || DEFAULT_CONFIG.apiUrl;\n const debug = config.debug || false;\n\n if (!config.apiKey) {\n throw new Error('API key required for getRecording');\n }\n\n if (debug) console.log(`[Browser] getRecording: ${recordingId}`);\n\n const response = await fetch(`${apiUrl}/recordings/${recordingId}`, {\n method: 'GET',\n headers: { 'Authorization': `Bearer ${config.apiKey}` },\n });\n\n if (!response.ok) {\n const errorText = await response.text().catch(() => response.statusText);\n if (debug) console.error(`[Browser] getRecording error: ${response.status} - ${errorText}`);\n throw new Error(`HTTP ${response.status}: ${errorText}`);\n }\n\n const recording = await response.json();\n if (debug) console.log(`[Browser] Recording status: ${recording.status}`);\n\n return recording;\n}\n\n/**\n * Wait for recording to complete with automatic polling\n * \n * @param recordingId - Recording UUID\n * @param config - Configuration with apiKey\n * @param options - Polling options\n * @returns Recording status when completed or errored\n * \n * @example\n * ```typescript\n * const result = await executeBrowserTask({ task: '...', record_video: true }, config);\n * if (result.recording_id) {\n * const recording = await waitForRecording(result.recording_id, config, {\n * timeout: 60000, // 1 minute\n * pollInterval: 2000 // Check every 2 seconds\n * });\n * console.log('Video URL:', recording.video_url);\n * }\n * ```\n */\nexport async function waitForRecording(\n recordingId: string,\n config: BrowserConfig = {},\n options: { timeout?: number; pollInterval?: number } = {}\n): Promise<RecordingStatus> {\n const timeout = options.timeout ?? 60000; // Default 1 minute\n const pollInterval = options.pollInterval ?? 2000; // Default 2 seconds\n const startTime = Date.now();\n\n while (Date.now() - startTime < timeout) {\n const status = await getRecording(recordingId, config);\n \n if (status.status === 'COMPLETED' || status.status === 'ERROR') {\n return status;\n }\n\n // Wait before next poll\n await new Promise(resolve => setTimeout(resolve, pollInterval));\n }\n\n throw new Error(`Recording timeout after ${timeout}ms - status still pending`);\n}\n\n/**\n * Execute task with recording and wait for video to be ready\n * \n * @param input - Task parameters with record_video=true\n * @param config - Configuration with apiKey\n * @returns Task result with ready video URL\n * \n * @example\n * ```typescript\n * const result = await executeWithRecording(\n * {\n * task: \"Test checkout flow\",\n * url: \"https://example.com\",\n * record_video: true,\n * repo_id: \"my-project\"\n * },\n * { apiKey: process.env.MORPH_API_KEY }\n * );\n * \n * console.log('Task result:', result.result);\n * console.log('Video URL:', result.recording?.video_url);\n * ```\n */\nexport async function executeWithRecording(\n input: BrowserTaskInput & { record_video: true },\n config: BrowserConfig = {}\n): Promise<BrowserTaskResult & { recording?: RecordingStatus }> {\n // Execute task with recording\n const taskResult = await executeBrowserTask(input, config);\n\n // If recording was created, wait for it to complete\n if (taskResult.recording_id) {\n try {\n const recording = await waitForRecording(\n taskResult.recording_id,\n config,\n { timeout: 60000, pollInterval: 2000 }\n );\n return {\n ...taskResult,\n recording,\n };\n } catch (error) {\n // Return task result even if recording fails\n return {\n ...taskResult,\n recording: {\n id: taskResult.recording_id,\n status: 'ERROR',\n error: error instanceof Error ? error.message : String(error),\n created_at: new Date().toISOString(),\n },\n };\n }\n }\n\n return taskResult;\n}\n\n/**\n * Get errors from recording with screenshots\n * \n * Screenshots are captured in real-time (500ms after error occurs) during the browser session.\n * \n * @param recordingId - Recording UUID from BrowserTaskResult\n * @param config - Configuration with apiKey\n * @returns Errors with real-time screenshots\n * \n * @example\n * ```typescript\n * const { errors, total_errors } = await getErrors('uuid-here', { apiKey: 'key' });\n * \n * console.log(`Found ${total_errors} errors`);\n * \n * errors.forEach(err => {\n * console.log(`[${err.type}] ${err.message}`);\n * if (err.url) console.log(` URL: ${err.url}`);\n * if (err.screenshot_url) console.log(` Screenshot: ${err.screenshot_url}`);\n * \n * // Download screenshot\n * if (err.screenshot_url) {\n * const response = await fetch(err.screenshot_url);\n * const screenshot = await response.arrayBuffer();\n * // Save or process screenshot\n * }\n * });\n * ```\n */\nexport async function getErrors(\n recordingId: string,\n config: BrowserConfig = {}\n): Promise<ErrorsResponse> {\n const apiUrl = config.apiUrl || DEFAULT_CONFIG.apiUrl;\n const debug = config.debug || false;\n\n if (!config.apiKey) {\n throw new Error('API key required for getErrors');\n }\n\n if (debug) console.log(`[Browser] getErrors: ${recordingId}`);\n\n const response = await fetch(`${apiUrl}/recordings/${recordingId}/errors`, {\n method: 'GET',\n headers: { 'Authorization': `Bearer ${config.apiKey}` },\n });\n\n if (!response.ok) {\n const errorText = await response.text().catch(() => response.statusText);\n if (debug) console.error(`[Browser] getErrors error: ${response.status} - ${errorText}`);\n throw new Error(`HTTP ${response.status}: ${errorText}`);\n }\n\n const errors = await response.json();\n if (debug) console.log(`[Browser] Found ${errors.total_errors} errors`);\n\n return errors;\n}\n\n/**\n * Helper to serialize Zod schema for API\n */\nfunction stringifyStructuredOutput(schema: any): string {\n try {\n return JSON.stringify({\n type: 'object',\n description: 'Zod schema definition (Zod v3)',\n zodDef: schema._def,\n });\n } catch (error) {\n console.warn('[Browser] Failed to serialize Zod schema:', error);\n return JSON.stringify({\n type: 'object',\n description: 'Schema serialization failed',\n });\n }\n}\n\n/**\n * Parse and validate structured task output\n */\nfunction parseStructuredTaskOutput<T>(\n result: BrowserTaskResult,\n schema: any\n): BrowserTaskResult & { parsed: T | null } {\n if (!result.output) {\n return { ...result, parsed: null };\n }\n\n try {\n const parsed = JSON.parse(result.output);\n const validated = schema.parse(parsed) as T;\n return { ...result, parsed: validated };\n } catch (error) {\n if (error instanceof SyntaxError) {\n return { ...result, parsed: null };\n }\n throw error;\n }\n}\n\n/**\n * Get current task status\n */\nasync function getTaskStatus(\n taskId: string,\n config: BrowserConfig\n): Promise<BrowserTaskResult> {\n const apiUrl = config.apiUrl || DEFAULT_CONFIG.apiUrl;\n const debug = config.debug || false;\n\n if (debug) console.log(`[Browser] getTaskStatus: ${taskId}`);\n\n const headers: Record<string, string> = {};\n if (config.apiKey) headers['Authorization'] = `Bearer ${config.apiKey}`;\n\n const response = await fetch(`${apiUrl}/tasks/${taskId}`, {\n method: 'GET',\n headers,\n });\n\n if (!response.ok) {\n const errorText = await response.text().catch(() => response.statusText);\n if (debug) console.error(`[Browser] getTaskStatus error: ${response.status} - ${errorText}`);\n throw new Error(`HTTP ${response.status}: ${errorText}`);\n }\n\n const result: BrowserTaskResult = await response.json();\n if (debug) console.log(`[Browser] Task status: ${result.status}`);\n\n return result;\n}\n\n/**\n * Generate live URL for watching task execution in real-time\n */\nfunction generateLiveUrl(taskId: string, config: BrowserConfig): string {\n const apiUrl = config.apiUrl || DEFAULT_CONFIG.apiUrl;\n const baseUrl = apiUrl.replace('/api', '');\n return `${baseUrl}/tasks/${taskId}/live`;\n}\n\n/**\n * Poll task until completion\n */\nasync function pollTaskUntilComplete(\n taskId: string,\n config: BrowserConfig,\n pollConfig: { interval?: number; timeout?: number } = {}\n): Promise<BrowserTaskResult> {\n const interval = pollConfig.interval ?? 2000; // 2 seconds\n const timeout = pollConfig.timeout ?? 300000; // 5 minutes\n const startTime = Date.now();\n\n while (Date.now() - startTime < timeout) {\n const status = await getTaskStatus(taskId, config);\n \n if (status.status === 'completed' || status.status === 'failed') {\n return status;\n }\n\n await new Promise(resolve => setTimeout(resolve, interval));\n }\n\n throw new Error(`Task polling timeout after ${timeout}ms`);\n}\n\n/**\n * Wrap task response with convenience methods\n */\nfunction wrapTaskResponse(\n result: BrowserTaskResult,\n config: BrowserConfig\n): BrowserTaskWithPromise {\n const wrapped: BrowserTaskWithPromise = {\n ...result,\n task_id: result.task_id || '',\n liveUrl: result.task_id \n ? generateLiveUrl(result.task_id, config)\n : result.debugUrl || '',\n complete: async (pollConfig?: { interval?: number; timeout?: number }) => {\n // If we have a task_id, poll task status endpoint\n if (result.task_id) {\n return pollTaskUntilComplete(result.task_id!, config, pollConfig);\n }\n // If we have a recording_id, poll recording status instead\n if (result.recording_id) {\n const recording = await waitForRecording(\n result.recording_id,\n config,\n pollConfig\n );\n // Return a result-like object (recording doesn't have full task result)\n return {\n ...result,\n recording_status: recording.status,\n } as BrowserTaskResult;\n }\n // No way to poll completion\n throw new Error('Cannot poll completion: no task_id or recording_id available');\n },\n // Add Steel live session helpers - either functional or error-throwing\n getLiveUrl: result.debugUrl\n ? (options?: LiveSessionOptions) => buildLiveUrl(result.debugUrl!, options)\n : () => {\n throw new Error(\n 'Live sessions not available. Your backend must return a debugUrl in the response. Contact support@morphllm.com if you need help.'\n );\n },\n getLiveIframe: result.debugUrl\n ? (optionsOrPreset?: string | IframeOptions) => {\n const options = resolvePreset(optionsOrPreset);\n return buildLiveIframe(result.debugUrl!, options);\n }\n : () => {\n throw new Error(\n 'Live sessions not available. Your backend must return a debugUrl in the response. Contact support@morphllm.com if you need help.'\n );\n },\n getEmbedCode: result.debugUrl\n ? () => buildEmbedCode(result.debugUrl!)\n : () => {\n throw new Error(\n 'Live sessions not available. Your backend must return a debugUrl in the response. Contact support@morphllm.com if you need help.'\n );\n },\n };\n\n return wrapped;\n}\n\n/**\n * Wrap task response with schema validation\n */\nfunction wrapTaskResponseWithSchema<T>(\n result: BrowserTaskResult,\n config: BrowserConfig,\n schema: any\n): BrowserTaskWithPromiseAndSchema<T> {\n const parsed = result.output\n ? parseStructuredTaskOutput<T>(result, schema)\n : { ...result, parsed: null };\n\n const wrapped: BrowserTaskWithPromiseAndSchema<T> = {\n ...parsed,\n task_id: result.task_id || '',\n liveUrl: result.task_id\n ? generateLiveUrl(result.task_id, config)\n : result.debugUrl || '',\n complete: async (pollConfig?: { interval?: number; timeout?: number }) => {\n // If we have a task_id, poll task status endpoint\n if (result.task_id) {\n const finalResult = await pollTaskUntilComplete(result.task_id!, config, pollConfig);\n return parseStructuredTaskOutput<T>(finalResult, schema);\n }\n // If we have a recording_id, poll recording status instead\n if (result.recording_id) {\n const recording = await waitForRecording(\n result.recording_id,\n config,\n pollConfig\n );\n // Return parsed result (recording doesn't have task output)\n return {\n ...parsed,\n recording_status: recording.status,\n };\n }\n // No way to poll completion\n throw new Error('Cannot poll completion: no task_id or recording_id available');\n },\n // Add Steel live session helpers - either functional or error-throwing\n getLiveUrl: result.debugUrl\n ? (options?: LiveSessionOptions) => buildLiveUrl(result.debugUrl!, options)\n : () => {\n throw new Error(\n 'Live sessions not available. Your backend must return a debugUrl in the response. ' +\n 'Contact support@morphllm.com if you need help enabling live sessions. '\n );\n },\n getLiveIframe: result.debugUrl\n ? (optionsOrPreset?: string | IframeOptions) => {\n const options = resolvePreset(optionsOrPreset);\n return buildLiveIframe(result.debugUrl!, options);\n }\n : () => {\n throw new Error(\n 'Live sessions not available. Your backend must return a debugUrl in the response. ' +\n 'Contact support@morphllm.com if you need help enabling live sessions.'\n );\n },\n getEmbedCode: result.debugUrl\n ? () => buildEmbedCode(result.debugUrl!)\n : () => {\n throw new Error(\n 'Live sessions not available. Your backend must return a debugUrl in the response. ' +\n 'Contact support@morphllm.com if you need help enabling live sessions.'\n );\n },\n };\n\n return wrapped;\n}\n\n/**\n * Check if browser worker service is healthy\n * \n * @param config - Optional configuration\n * @returns Health status\n */\nexport async function checkHealth(config: BrowserConfig = {}): Promise<{\n ok: boolean;\n google_configured: boolean;\n database_configured: boolean;\n s3_configured: boolean;\n error?: string;\n}> {\n const apiUrl = config.apiUrl || DEFAULT_CONFIG.apiUrl;\n\n try {\n const response = await fetch(`${apiUrl}/health`, {\n method: 'GET',\n headers: config.apiKey\n ? { 'Authorization': `Bearer ${config.apiKey}` }\n : {},\n });\n\n if (!response.ok) {\n throw new Error(`HTTP ${response.status}`);\n }\n\n const data = await response.json();\n return {\n ok: true,\n google_configured: data.google_configured ?? false,\n database_configured: data.database_configured ?? false,\n s3_configured: data.s3_configured ?? false,\n };\n } catch (error) {\n return {\n ok: false,\n google_configured: false,\n database_configured: false,\n s3_configured: false,\n error: error instanceof Error ? error.message : String(error),\n };\n }\n}\n\n"],"mappings":";;;;;;;;;;;;AAmBA,IAAM,iBAAiB;AAAA,EACrB,QAAQ,QAAQ,IAAI,sBAAsB,QACtC,0BACA;AAAA,EACJ,SAAS;AAAA;AAAA,EACT,OAAO;AACT;AAKO,IAAM,gBAAN,MAAoB;AAAA,EACjB;AAAA,EAER,YAAY,SAAwB,CAAC,GAAG;AACtC,SAAK,SAAS;AAAA,MACZ,GAAG;AAAA,MACH,GAAG;AAAA,IACL;AAAA,EACF;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,QAAQ,OAAqD;AACjE,WAAO,mBAAmB,OAAO,KAAK,MAAM;AAAA,EAC9C;AAAA,EAIA,MAAM,WACJ,OACsE;AACtE,UAAM,SAAS,KAAK,OAAO,UAAU,eAAe;AACpD,UAAM,QAAQ,KAAK,OAAO,SAAS;AAEnC,QAAI,OAAO;AACT,cAAQ,IAAI,0BAA0B,MAAM,KAAK,MAAM,GAAG,EAAE,CAAC,YAAY,MAAM,OAAO,MAAM,EAAE;AAC9F,cAAQ,IAAI,qCAAqC,MAAM,qBAAqB;AAAA,IAC9E;AAEA,UAAM,UAAkC,EAAE,gBAAgB,mBAAmB;AAC7E,QAAI,KAAK,OAAO,OAAQ,SAAQ,eAAe,IAAI,UAAU,KAAK,OAAO,MAAM;AAG/E,UAAM,WAAW,MAAM,MAAM,GAAG,MAAM,uBAAuB;AAAA,MAC3D,QAAQ;AAAA,MACR;AAAA,MACA,MAAM,KAAK,UAAU;AAAA,QACnB,MAAM,MAAM;AAAA,QACZ,KAAK,MAAM;AAAA,QACX,WAAW,MAAM,aAAa;AAA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
@@ -468,15 +468,46 @@ var BrowserClient = class {
|
|
|
468
468
|
return executeBrowserTask(input, this.config);
|
|
469
469
|
}
|
|
470
470
|
async createTask(input) {
|
|
471
|
+
const apiUrl = this.config.apiUrl || DEFAULT_CONFIG2.apiUrl;
|
|
472
|
+
const debug = this.config.debug || false;
|
|
473
|
+
if (debug) {
|
|
474
|
+
console.log(`[Browser] createTask: "${input.task.slice(0, 60)}..." url=${input.url || "none"}`);
|
|
475
|
+
console.log(`[Browser] Calling async endpoint: ${apiUrl}/browser-task/async`);
|
|
476
|
+
}
|
|
477
|
+
const headers = { "Content-Type": "application/json" };
|
|
478
|
+
if (this.config.apiKey) headers["Authorization"] = `Bearer ${this.config.apiKey}`;
|
|
479
|
+
const response = await fetch(`${apiUrl}/browser-task/async`, {
|
|
480
|
+
method: "POST",
|
|
481
|
+
headers,
|
|
482
|
+
body: JSON.stringify({
|
|
483
|
+
task: input.task,
|
|
484
|
+
url: input.url,
|
|
485
|
+
max_steps: input.max_steps ?? 10,
|
|
486
|
+
model: input.model ?? "morph-computer-use-v0",
|
|
487
|
+
viewport_width: input.viewport_width ?? 1280,
|
|
488
|
+
viewport_height: input.viewport_height ?? 720,
|
|
489
|
+
external_id: input.external_id,
|
|
490
|
+
repo_id: input.repo_id,
|
|
491
|
+
commit_id: input.commit_id,
|
|
492
|
+
record_video: input.record_video ?? false,
|
|
493
|
+
video_width: input.video_width ?? input.viewport_width ?? 1280,
|
|
494
|
+
video_height: input.video_height ?? input.viewport_height ?? 720,
|
|
495
|
+
allow_resizing: input.allow_resizing ?? false,
|
|
496
|
+
structured_output: "schema" in input ? stringifyStructuredOutput(input.schema) : void 0
|
|
497
|
+
})
|
|
498
|
+
});
|
|
499
|
+
if (!response.ok) {
|
|
500
|
+
const errorText = await response.text().catch(() => response.statusText);
|
|
501
|
+
if (debug) console.error(`[Browser] Error: ${response.status} - ${errorText}`);
|
|
502
|
+
throw new Error(`HTTP ${response.status}: ${errorText}`);
|
|
503
|
+
}
|
|
504
|
+
const result = await response.json();
|
|
505
|
+
if (debug) {
|
|
506
|
+
console.log(`[Browser] \u2705 Task created: recording_id=${result.recording_id ?? "none"} debug_url=${result.debugUrl ? "available" : "none"}`);
|
|
507
|
+
}
|
|
471
508
|
if ("schema" in input) {
|
|
472
|
-
const taskInput = {
|
|
473
|
-
...input,
|
|
474
|
-
structured_output: stringifyStructuredOutput(input.schema)
|
|
475
|
-
};
|
|
476
|
-
const result = await executeBrowserTask(taskInput, this.config);
|
|
477
509
|
return wrapTaskResponseWithSchema(result, this.config, input.schema);
|
|
478
510
|
} else {
|
|
479
|
-
const result = await executeBrowserTask(input, this.config);
|
|
480
511
|
return wrapTaskResponse(result, this.config);
|
|
481
512
|
}
|
|
482
513
|
}
|
|
@@ -553,6 +584,7 @@ async function executeBrowserTask(input, config = {}) {
|
|
|
553
584
|
record_video: input.record_video ?? false,
|
|
554
585
|
video_width: input.video_width ?? input.viewport_width ?? 1280,
|
|
555
586
|
video_height: input.video_height ?? input.viewport_height ?? 720,
|
|
587
|
+
allow_resizing: input.allow_resizing ?? false,
|
|
556
588
|
structured_output: input.structured_output
|
|
557
589
|
})
|
|
558
590
|
},
|
|
@@ -746,7 +778,21 @@ function wrapTaskResponse(result, config) {
|
|
|
746
778
|
task_id: result.task_id || "",
|
|
747
779
|
liveUrl: result.task_id ? generateLiveUrl(result.task_id, config) : result.debugUrl || "",
|
|
748
780
|
complete: async (pollConfig) => {
|
|
749
|
-
|
|
781
|
+
if (result.task_id) {
|
|
782
|
+
return pollTaskUntilComplete(result.task_id, config, pollConfig);
|
|
783
|
+
}
|
|
784
|
+
if (result.recording_id) {
|
|
785
|
+
const recording = await waitForRecording(
|
|
786
|
+
result.recording_id,
|
|
787
|
+
config,
|
|
788
|
+
pollConfig
|
|
789
|
+
);
|
|
790
|
+
return {
|
|
791
|
+
...result,
|
|
792
|
+
recording_status: recording.status
|
|
793
|
+
};
|
|
794
|
+
}
|
|
795
|
+
throw new Error("Cannot poll completion: no task_id or recording_id available");
|
|
750
796
|
},
|
|
751
797
|
// Add Steel live session helpers - either functional or error-throwing
|
|
752
798
|
getLiveUrl: result.debugUrl ? (options) => buildLiveUrl(result.debugUrl, options) : () => {
|
|
@@ -777,8 +823,22 @@ function wrapTaskResponseWithSchema(result, config, schema) {
|
|
|
777
823
|
task_id: result.task_id || "",
|
|
778
824
|
liveUrl: result.task_id ? generateLiveUrl(result.task_id, config) : result.debugUrl || "",
|
|
779
825
|
complete: async (pollConfig) => {
|
|
780
|
-
|
|
781
|
-
|
|
826
|
+
if (result.task_id) {
|
|
827
|
+
const finalResult = await pollTaskUntilComplete(result.task_id, config, pollConfig);
|
|
828
|
+
return parseStructuredTaskOutput(finalResult, schema);
|
|
829
|
+
}
|
|
830
|
+
if (result.recording_id) {
|
|
831
|
+
const recording = await waitForRecording(
|
|
832
|
+
result.recording_id,
|
|
833
|
+
config,
|
|
834
|
+
pollConfig
|
|
835
|
+
);
|
|
836
|
+
return {
|
|
837
|
+
...parsed,
|
|
838
|
+
recording_status: recording.status
|
|
839
|
+
};
|
|
840
|
+
}
|
|
841
|
+
throw new Error("Cannot poll completion: no task_id or recording_id available");
|
|
782
842
|
},
|
|
783
843
|
// Add Steel live session helpers - either functional or error-throwing
|
|
784
844
|
getLiveUrl: result.debugUrl ? (options) => buildLiveUrl(result.debugUrl, options) : () => {
|
|
@@ -1471,6 +1531,81 @@ var GeminiRouter = class extends BaseRouter {
|
|
|
1471
1531
|
return super.selectModel(input);
|
|
1472
1532
|
}
|
|
1473
1533
|
};
|
|
1534
|
+
var RawRouter = class extends BaseRouter {
|
|
1535
|
+
constructor(config = {}) {
|
|
1536
|
+
super("raw", config);
|
|
1537
|
+
}
|
|
1538
|
+
/**
|
|
1539
|
+
* Get raw difficulty classification
|
|
1540
|
+
*
|
|
1541
|
+
* @param input - User input and mode
|
|
1542
|
+
* @returns Raw difficulty (easy | medium | hard | needs_info)
|
|
1543
|
+
*/
|
|
1544
|
+
async classify(input) {
|
|
1545
|
+
const mode = input.mode || "balanced";
|
|
1546
|
+
const apiKey = this.config.apiKey || process.env.MORPH_API_KEY;
|
|
1547
|
+
if (!apiKey) {
|
|
1548
|
+
throw new Error(
|
|
1549
|
+
"Morph API key is required. Set MORPH_API_KEY environment variable or pass apiKey in config."
|
|
1550
|
+
);
|
|
1551
|
+
}
|
|
1552
|
+
const url = `${this.config.apiUrl}/v1/router/raw`;
|
|
1553
|
+
const payload = {
|
|
1554
|
+
input: input.input,
|
|
1555
|
+
mode
|
|
1556
|
+
};
|
|
1557
|
+
if (this.config.debug) {
|
|
1558
|
+
console.log(`[RawRouter] Requesting raw difficulty classification:`, {
|
|
1559
|
+
mode,
|
|
1560
|
+
inputLength: input.input.length
|
|
1561
|
+
});
|
|
1562
|
+
}
|
|
1563
|
+
try {
|
|
1564
|
+
const fetchPromise = fetchWithRetry(
|
|
1565
|
+
url,
|
|
1566
|
+
{
|
|
1567
|
+
method: "POST",
|
|
1568
|
+
headers: {
|
|
1569
|
+
"Content-Type": "application/json",
|
|
1570
|
+
Authorization: `Bearer ${apiKey}`
|
|
1571
|
+
},
|
|
1572
|
+
body: JSON.stringify(payload)
|
|
1573
|
+
},
|
|
1574
|
+
this.config.retryConfig
|
|
1575
|
+
);
|
|
1576
|
+
const response = await withTimeout(
|
|
1577
|
+
fetchPromise,
|
|
1578
|
+
this.config.timeout,
|
|
1579
|
+
`Router API request timed out after ${this.config.timeout}ms`
|
|
1580
|
+
);
|
|
1581
|
+
if (!response.ok) {
|
|
1582
|
+
const errorText = await response.text();
|
|
1583
|
+
throw new Error(
|
|
1584
|
+
`Router API error (${response.status}): ${errorText || response.statusText}`
|
|
1585
|
+
);
|
|
1586
|
+
}
|
|
1587
|
+
const apiResult = await response.json();
|
|
1588
|
+
let difficulty;
|
|
1589
|
+
if (apiResult.difficulty === "") {
|
|
1590
|
+
difficulty = "medium";
|
|
1591
|
+
} else {
|
|
1592
|
+
difficulty = apiResult.difficulty || apiResult.model;
|
|
1593
|
+
}
|
|
1594
|
+
const result = {
|
|
1595
|
+
difficulty
|
|
1596
|
+
};
|
|
1597
|
+
if (this.config.debug) {
|
|
1598
|
+
console.log(`[RawRouter] Classified as: ${difficulty}`);
|
|
1599
|
+
}
|
|
1600
|
+
return result;
|
|
1601
|
+
} catch (error) {
|
|
1602
|
+
if (this.config.debug) {
|
|
1603
|
+
console.error(`[RawRouter] Error classifying:`, error);
|
|
1604
|
+
}
|
|
1605
|
+
throw error;
|
|
1606
|
+
}
|
|
1607
|
+
}
|
|
1608
|
+
};
|
|
1474
1609
|
|
|
1475
1610
|
// client.ts
|
|
1476
1611
|
var MorphClient = class {
|
|
@@ -1542,6 +1677,12 @@ var MorphClient = class {
|
|
|
1542
1677
|
debug: config.debug,
|
|
1543
1678
|
timeout: config.timeout,
|
|
1544
1679
|
retryConfig: config.retryConfig
|
|
1680
|
+
}),
|
|
1681
|
+
raw: new RawRouter({
|
|
1682
|
+
apiKey: config.apiKey,
|
|
1683
|
+
debug: config.debug,
|
|
1684
|
+
timeout: config.timeout,
|
|
1685
|
+
retryConfig: config.retryConfig
|
|
1545
1686
|
})
|
|
1546
1687
|
};
|
|
1547
1688
|
}
|