@morphllm/morphsdk 0.2.44 → 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/index.cjs CHANGED
@@ -476,15 +476,46 @@ var BrowserClient = class {
476
476
  return executeBrowserTask(input, this.config);
477
477
  }
478
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
+ }
479
516
  if ("schema" in input) {
480
- const taskInput = {
481
- ...input,
482
- structured_output: stringifyStructuredOutput(input.schema)
483
- };
484
- const result = await executeBrowserTask(taskInput, this.config);
485
517
  return wrapTaskResponseWithSchema(result, this.config, input.schema);
486
518
  } else {
487
- const result = await executeBrowserTask(input, this.config);
488
519
  return wrapTaskResponse(result, this.config);
489
520
  }
490
521
  }
@@ -561,6 +592,7 @@ async function executeBrowserTask(input, config = {}) {
561
592
  record_video: input.record_video ?? false,
562
593
  video_width: input.video_width ?? input.viewport_width ?? 1280,
563
594
  video_height: input.video_height ?? input.viewport_height ?? 720,
595
+ allow_resizing: input.allow_resizing ?? false,
564
596
  structured_output: input.structured_output
565
597
  })
566
598
  },
@@ -754,7 +786,21 @@ function wrapTaskResponse(result, config) {
754
786
  task_id: result.task_id || "",
755
787
  liveUrl: result.task_id ? generateLiveUrl(result.task_id, config) : result.debugUrl || "",
756
788
  complete: async (pollConfig) => {
757
- 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");
758
804
  },
759
805
  // Add Steel live session helpers - either functional or error-throwing
760
806
  getLiveUrl: result.debugUrl ? (options) => buildLiveUrl(result.debugUrl, options) : () => {
@@ -785,8 +831,22 @@ function wrapTaskResponseWithSchema(result, config, schema) {
785
831
  task_id: result.task_id || "",
786
832
  liveUrl: result.task_id ? generateLiveUrl(result.task_id, config) : result.debugUrl || "",
787
833
  complete: async (pollConfig) => {
788
- const finalResult = await pollTaskUntilComplete(result.task_id, config, pollConfig);
789
- 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");
790
850
  },
791
851
  // Add Steel live session helpers - either functional or error-throwing
792
852
  getLiveUrl: result.debugUrl ? (options) => buildLiveUrl(result.debugUrl, options) : () => {