@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.
Files changed (43) hide show
  1. package/dist/{chunk-3NTGAUTJ.js → chunk-CP4NZGRY.js} +8 -3
  2. package/dist/{chunk-3NTGAUTJ.js.map → chunk-CP4NZGRY.js.map} +1 -1
  3. package/dist/{chunk-O45X46VL.js → chunk-K6FQZZ2E.js} +11 -4
  4. package/dist/chunk-K6FQZZ2E.js.map +1 -0
  5. package/dist/{chunk-EYHXBQQX.js → chunk-LVY5LPEX.js} +70 -10
  6. package/dist/chunk-LVY5LPEX.js.map +1 -0
  7. package/dist/client.cjs +150 -9
  8. package/dist/client.cjs.map +1 -1
  9. package/dist/client.d.ts +2 -1
  10. package/dist/client.js +3 -3
  11. package/dist/index.cjs +154 -11
  12. package/dist/index.cjs.map +1 -1
  13. package/dist/index.d.ts +2 -2
  14. package/dist/index.js +7 -5
  15. package/dist/modelrouter/core.cjs +7 -2
  16. package/dist/modelrouter/core.cjs.map +1 -1
  17. package/dist/modelrouter/core.d.ts +1 -1
  18. package/dist/modelrouter/core.js +1 -1
  19. package/dist/modelrouter/index.cjs +7 -2
  20. package/dist/modelrouter/index.cjs.map +1 -1
  21. package/dist/modelrouter/index.js +1 -1
  22. package/dist/modelrouter/types.cjs.map +1 -1
  23. package/dist/modelrouter/types.d.ts +1 -1
  24. package/dist/tools/browser/anthropic.cjs +1 -0
  25. package/dist/tools/browser/anthropic.cjs.map +1 -1
  26. package/dist/tools/browser/anthropic.js +1 -1
  27. package/dist/tools/browser/core.cjs +69 -9
  28. package/dist/tools/browser/core.cjs.map +1 -1
  29. package/dist/tools/browser/core.js +1 -1
  30. package/dist/tools/browser/index.cjs +69 -9
  31. package/dist/tools/browser/index.cjs.map +1 -1
  32. package/dist/tools/browser/index.js +1 -1
  33. package/dist/tools/browser/openai.cjs +1 -0
  34. package/dist/tools/browser/openai.cjs.map +1 -1
  35. package/dist/tools/browser/openai.js +1 -1
  36. package/dist/tools/browser/types.cjs.map +1 -1
  37. package/dist/tools/browser/types.d.ts +2 -0
  38. package/dist/tools/browser/vercel.cjs +1 -0
  39. package/dist/tools/browser/vercel.cjs.map +1 -1
  40. package/dist/tools/browser/vercel.js +1 -1
  41. package/package.json +1 -1
  42. package/dist/chunk-EYHXBQQX.js.map +0 -1
  43. package/dist/chunk-O45X46VL.js.map +0 -1
package/dist/index.cjs CHANGED
@@ -37,7 +37,8 @@ __export(index_exports, {
37
37
  GeminiRouter: () => GeminiRouter,
38
38
  MorphClient: () => MorphClient,
39
39
  MorphGit: () => MorphGit,
40
- OpenAIRouter: () => OpenAIRouter
40
+ OpenAIRouter: () => OpenAIRouter,
41
+ RawRouter: () => RawRouter
41
42
  });
42
43
  module.exports = __toCommonJS(index_exports);
43
44
 
@@ -475,15 +476,46 @@ var BrowserClient = class {
475
476
  return executeBrowserTask(input, this.config);
476
477
  }
477
478
  async createTask(input) {
479
+ const apiUrl = this.config.apiUrl || DEFAULT_CONFIG2.apiUrl;
480
+ const debug = this.config.debug || false;
481
+ if (debug) {
482
+ console.log(`[Browser] createTask: "${input.task.slice(0, 60)}..." url=${input.url || "none"}`);
483
+ console.log(`[Browser] Calling async endpoint: ${apiUrl}/browser-task/async`);
484
+ }
485
+ const headers = { "Content-Type": "application/json" };
486
+ if (this.config.apiKey) headers["Authorization"] = `Bearer ${this.config.apiKey}`;
487
+ const response = await fetch(`${apiUrl}/browser-task/async`, {
488
+ method: "POST",
489
+ headers,
490
+ body: JSON.stringify({
491
+ task: input.task,
492
+ url: input.url,
493
+ max_steps: input.max_steps ?? 10,
494
+ model: input.model ?? "morph-computer-use-v0",
495
+ viewport_width: input.viewport_width ?? 1280,
496
+ viewport_height: input.viewport_height ?? 720,
497
+ external_id: input.external_id,
498
+ repo_id: input.repo_id,
499
+ commit_id: input.commit_id,
500
+ record_video: input.record_video ?? false,
501
+ video_width: input.video_width ?? input.viewport_width ?? 1280,
502
+ video_height: input.video_height ?? input.viewport_height ?? 720,
503
+ allow_resizing: input.allow_resizing ?? false,
504
+ structured_output: "schema" in input ? stringifyStructuredOutput(input.schema) : void 0
505
+ })
506
+ });
507
+ if (!response.ok) {
508
+ const errorText = await response.text().catch(() => response.statusText);
509
+ if (debug) console.error(`[Browser] Error: ${response.status} - ${errorText}`);
510
+ throw new Error(`HTTP ${response.status}: ${errorText}`);
511
+ }
512
+ const result = await response.json();
513
+ if (debug) {
514
+ console.log(`[Browser] \u2705 Task created: recording_id=${result.recording_id ?? "none"} debug_url=${result.debugUrl ? "available" : "none"}`);
515
+ }
478
516
  if ("schema" in input) {
479
- const taskInput = {
480
- ...input,
481
- structured_output: stringifyStructuredOutput(input.schema)
482
- };
483
- const result = await executeBrowserTask(taskInput, this.config);
484
517
  return wrapTaskResponseWithSchema(result, this.config, input.schema);
485
518
  } else {
486
- const result = await executeBrowserTask(input, this.config);
487
519
  return wrapTaskResponse(result, this.config);
488
520
  }
489
521
  }
@@ -560,6 +592,7 @@ async function executeBrowserTask(input, config = {}) {
560
592
  record_video: input.record_video ?? false,
561
593
  video_width: input.video_width ?? input.viewport_width ?? 1280,
562
594
  video_height: input.video_height ?? input.viewport_height ?? 720,
595
+ allow_resizing: input.allow_resizing ?? false,
563
596
  structured_output: input.structured_output
564
597
  })
565
598
  },
@@ -753,7 +786,21 @@ function wrapTaskResponse(result, config) {
753
786
  task_id: result.task_id || "",
754
787
  liveUrl: result.task_id ? generateLiveUrl(result.task_id, config) : result.debugUrl || "",
755
788
  complete: async (pollConfig) => {
756
- return pollTaskUntilComplete(result.task_id, config, pollConfig);
789
+ if (result.task_id) {
790
+ return pollTaskUntilComplete(result.task_id, config, pollConfig);
791
+ }
792
+ if (result.recording_id) {
793
+ const recording = await waitForRecording(
794
+ result.recording_id,
795
+ config,
796
+ pollConfig
797
+ );
798
+ return {
799
+ ...result,
800
+ recording_status: recording.status
801
+ };
802
+ }
803
+ throw new Error("Cannot poll completion: no task_id or recording_id available");
757
804
  },
758
805
  // Add Steel live session helpers - either functional or error-throwing
759
806
  getLiveUrl: result.debugUrl ? (options) => buildLiveUrl(result.debugUrl, options) : () => {
@@ -784,8 +831,22 @@ function wrapTaskResponseWithSchema(result, config, schema) {
784
831
  task_id: result.task_id || "",
785
832
  liveUrl: result.task_id ? generateLiveUrl(result.task_id, config) : result.debugUrl || "",
786
833
  complete: async (pollConfig) => {
787
- const finalResult = await pollTaskUntilComplete(result.task_id, config, pollConfig);
788
- return parseStructuredTaskOutput(finalResult, schema);
834
+ if (result.task_id) {
835
+ const finalResult = await pollTaskUntilComplete(result.task_id, config, pollConfig);
836
+ return parseStructuredTaskOutput(finalResult, schema);
837
+ }
838
+ if (result.recording_id) {
839
+ const recording = await waitForRecording(
840
+ result.recording_id,
841
+ config,
842
+ pollConfig
843
+ );
844
+ return {
845
+ ...parsed,
846
+ recording_status: recording.status
847
+ };
848
+ }
849
+ throw new Error("Cannot poll completion: no task_id or recording_id available");
789
850
  },
790
851
  // Add Steel live session helpers - either functional or error-throwing
791
852
  getLiveUrl: result.debugUrl ? (options) => buildLiveUrl(result.debugUrl, options) : () => {
@@ -1478,6 +1539,81 @@ var GeminiRouter = class extends BaseRouter {
1478
1539
  return super.selectModel(input);
1479
1540
  }
1480
1541
  };
1542
+ var RawRouter = class extends BaseRouter {
1543
+ constructor(config = {}) {
1544
+ super("raw", config);
1545
+ }
1546
+ /**
1547
+ * Get raw difficulty classification
1548
+ *
1549
+ * @param input - User input and mode
1550
+ * @returns Raw difficulty (easy | medium | hard | needs_info)
1551
+ */
1552
+ async classify(input) {
1553
+ const mode = input.mode || "balanced";
1554
+ const apiKey = this.config.apiKey || process.env.MORPH_API_KEY;
1555
+ if (!apiKey) {
1556
+ throw new Error(
1557
+ "Morph API key is required. Set MORPH_API_KEY environment variable or pass apiKey in config."
1558
+ );
1559
+ }
1560
+ const url = `${this.config.apiUrl}/v1/router/raw`;
1561
+ const payload = {
1562
+ input: input.input,
1563
+ mode
1564
+ };
1565
+ if (this.config.debug) {
1566
+ console.log(`[RawRouter] Requesting raw difficulty classification:`, {
1567
+ mode,
1568
+ inputLength: input.input.length
1569
+ });
1570
+ }
1571
+ try {
1572
+ const fetchPromise = fetchWithRetry(
1573
+ url,
1574
+ {
1575
+ method: "POST",
1576
+ headers: {
1577
+ "Content-Type": "application/json",
1578
+ Authorization: `Bearer ${apiKey}`
1579
+ },
1580
+ body: JSON.stringify(payload)
1581
+ },
1582
+ this.config.retryConfig
1583
+ );
1584
+ const response = await withTimeout(
1585
+ fetchPromise,
1586
+ this.config.timeout,
1587
+ `Router API request timed out after ${this.config.timeout}ms`
1588
+ );
1589
+ if (!response.ok) {
1590
+ const errorText = await response.text();
1591
+ throw new Error(
1592
+ `Router API error (${response.status}): ${errorText || response.statusText}`
1593
+ );
1594
+ }
1595
+ const apiResult = await response.json();
1596
+ let difficulty;
1597
+ if (apiResult.difficulty === "") {
1598
+ difficulty = "medium";
1599
+ } else {
1600
+ difficulty = apiResult.difficulty || apiResult.model;
1601
+ }
1602
+ const result = {
1603
+ difficulty
1604
+ };
1605
+ if (this.config.debug) {
1606
+ console.log(`[RawRouter] Classified as: ${difficulty}`);
1607
+ }
1608
+ return result;
1609
+ } catch (error) {
1610
+ if (this.config.debug) {
1611
+ console.error(`[RawRouter] Error classifying:`, error);
1612
+ }
1613
+ throw error;
1614
+ }
1615
+ }
1616
+ };
1481
1617
 
1482
1618
  // client.ts
1483
1619
  var MorphClient = class {
@@ -1549,6 +1685,12 @@ var MorphClient = class {
1549
1685
  debug: config.debug,
1550
1686
  timeout: config.timeout,
1551
1687
  retryConfig: config.retryConfig
1688
+ }),
1689
+ raw: new RawRouter({
1690
+ apiKey: config.apiKey,
1691
+ debug: config.debug,
1692
+ timeout: config.timeout,
1693
+ retryConfig: config.retryConfig
1552
1694
  })
1553
1695
  };
1554
1696
  }
@@ -1562,6 +1704,7 @@ var MorphClient = class {
1562
1704
  GeminiRouter,
1563
1705
  MorphClient,
1564
1706
  MorphGit,
1565
- OpenAIRouter
1707
+ OpenAIRouter,
1708
+ RawRouter
1566
1709
  });
1567
1710
  //# sourceMappingURL=index.cjs.map