@morphllm/morphsdk 0.2.28 → 0.2.38

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 (76) hide show
  1. package/README.md +7 -12
  2. package/dist/anthropic-DpEAqqZF.d.ts +88 -0
  3. package/dist/{chunk-S3HTYGYF.js → chunk-B4H7N4GZ.js} +14 -2
  4. package/dist/chunk-B4H7N4GZ.js.map +1 -0
  5. package/dist/{chunk-CMKITT6X.js → chunk-DJSQUQGY.js} +4 -4
  6. package/dist/client.d.ts +114 -0
  7. package/dist/client.js +2 -2
  8. package/dist/git/client.d.ts +261 -0
  9. package/dist/git/config.d.ts +11 -0
  10. package/dist/git/index.d.ts +5 -0
  11. package/dist/git/types.d.ts +102 -0
  12. package/dist/index.d.ts +14 -0
  13. package/dist/index.js +4 -4
  14. package/dist/modelrouter/core.d.ts +56 -0
  15. package/dist/modelrouter/index.d.ts +2 -0
  16. package/dist/modelrouter/types.d.ts +35 -0
  17. package/dist/openai-BkKsS30n.d.ts +111 -0
  18. package/dist/tools/browser/anthropic.d.ts +51 -0
  19. package/dist/tools/browser/core.d.ts +203 -0
  20. package/dist/tools/browser/index.d.ts +72 -0
  21. package/dist/tools/browser/openai.d.ts +73 -0
  22. package/dist/tools/browser/prompts.d.ts +7 -0
  23. package/dist/tools/browser/types.d.ts +255 -0
  24. package/dist/tools/browser/vercel.d.ts +69 -0
  25. package/dist/tools/codebase_search/anthropic.d.ts +40 -0
  26. package/dist/tools/codebase_search/core.d.ts +40 -0
  27. package/dist/tools/codebase_search/index.d.ts +10 -0
  28. package/dist/tools/codebase_search/openai.d.ts +87 -0
  29. package/dist/tools/codebase_search/prompts.d.ts +7 -0
  30. package/dist/tools/codebase_search/types.d.ts +50 -0
  31. package/dist/tools/codebase_search/vercel.d.ts +65 -0
  32. package/dist/tools/fastapply/anthropic.cjs +14 -2
  33. package/dist/tools/fastapply/anthropic.cjs.map +1 -1
  34. package/dist/tools/fastapply/anthropic.d.ts +4 -0
  35. package/dist/tools/fastapply/anthropic.js +9 -3
  36. package/dist/tools/fastapply/core.d.ts +41 -0
  37. package/dist/tools/fastapply/index.cjs +18 -9
  38. package/dist/tools/fastapply/index.cjs.map +1 -1
  39. package/dist/tools/fastapply/index.d.ts +10 -0
  40. package/dist/tools/fastapply/index.js +4 -4
  41. package/dist/tools/fastapply/openai.d.ts +4 -0
  42. package/dist/tools/fastapply/prompts.d.ts +7 -0
  43. package/dist/tools/fastapply/types.d.ts +77 -0
  44. package/dist/tools/fastapply/vercel.d.ts +4 -0
  45. package/dist/tools/index.cjs +18 -9
  46. package/dist/tools/index.cjs.map +1 -1
  47. package/dist/tools/index.d.ts +10 -0
  48. package/dist/tools/index.js +4 -4
  49. package/dist/tools/utils/resilience.d.ts +58 -0
  50. package/dist/tools/warp_grep/agent/config.d.ts +8 -0
  51. package/dist/tools/warp_grep/agent/formatter.d.ts +14 -0
  52. package/dist/tools/warp_grep/agent/grep_helpers.d.ts +16 -0
  53. package/dist/tools/warp_grep/agent/parser.d.ts +16 -0
  54. package/dist/tools/warp_grep/agent/prompt.d.ts +4 -0
  55. package/dist/tools/warp_grep/agent/runner.d.ts +10 -0
  56. package/dist/tools/warp_grep/agent/types.cjs.map +1 -1
  57. package/dist/tools/warp_grep/agent/types.d.ts +44 -0
  58. package/dist/tools/warp_grep/anthropic.d.ts +14 -0
  59. package/dist/tools/warp_grep/index.d.ts +11 -0
  60. package/dist/tools/warp_grep/openai.d.ts +33 -0
  61. package/dist/tools/warp_grep/providers/command.d.ts +48 -0
  62. package/dist/tools/warp_grep/providers/local.d.ts +30 -0
  63. package/dist/tools/warp_grep/providers/types.d.ts +49 -0
  64. package/dist/tools/warp_grep/tools/analyse.d.ts +10 -0
  65. package/dist/tools/warp_grep/tools/finish.d.ts +10 -0
  66. package/dist/tools/warp_grep/tools/grep.d.ts +8 -0
  67. package/dist/tools/warp_grep/tools/read.d.ts +9 -0
  68. package/dist/tools/warp_grep/utils/files.d.ts +3 -0
  69. package/dist/tools/warp_grep/utils/format.d.ts +4 -0
  70. package/dist/tools/warp_grep/utils/paths.d.ts +7 -0
  71. package/dist/tools/warp_grep/utils/ripgrep.d.ts +11 -0
  72. package/dist/tools/warp_grep/vercel.d.ts +33 -0
  73. package/dist/vercel-B1GZ_g9N.d.ts +69 -0
  74. package/package.json +1 -1
  75. package/dist/chunk-S3HTYGYF.js.map +0 -1
  76. /package/dist/{chunk-CMKITT6X.js.map → chunk-DJSQUQGY.js.map} +0 -0
@@ -0,0 +1,102 @@
1
+ import { RetryConfig } from '../tools/utils/resilience.js';
2
+
3
+ /**
4
+ * Types for Morph Git SDK
5
+ */
6
+
7
+ interface MorphGitConfig {
8
+ apiKey?: string;
9
+ proxyUrl?: string;
10
+ /** Retry configuration for API calls */
11
+ retryConfig?: RetryConfig;
12
+ }
13
+ interface CloneOptions {
14
+ repoId: string;
15
+ dir: string;
16
+ branch?: string;
17
+ depth?: number;
18
+ singleBranch?: boolean;
19
+ }
20
+ interface PushOptions {
21
+ dir: string;
22
+ remote?: string;
23
+ branch: string;
24
+ }
25
+ interface PullOptions {
26
+ dir: string;
27
+ remote?: string;
28
+ branch: string;
29
+ }
30
+ interface AddOptions {
31
+ dir: string;
32
+ filepath: string;
33
+ }
34
+ interface ChatMessage {
35
+ role: string;
36
+ content: string;
37
+ [key: string]: any;
38
+ }
39
+ interface CommitMetadata {
40
+ chatHistory?: ChatMessage[];
41
+ recordingId?: string;
42
+ }
43
+ interface CommitOptions {
44
+ dir: string;
45
+ message: string;
46
+ author?: {
47
+ name: string | "Morph AI Agent";
48
+ email: string | "ai@morphllm.com";
49
+ };
50
+ chatHistory?: ChatMessage[];
51
+ recordingId?: string;
52
+ }
53
+ interface StatusOptions {
54
+ dir: string;
55
+ filepath?: string;
56
+ }
57
+ interface LogOptions {
58
+ dir: string;
59
+ depth?: number;
60
+ ref?: string;
61
+ }
62
+ interface CheckoutOptions {
63
+ dir: string;
64
+ ref: string;
65
+ }
66
+ interface BranchOptions {
67
+ dir: string;
68
+ name: string;
69
+ checkout?: boolean;
70
+ }
71
+ interface DiffOptions {
72
+ dir: string;
73
+ ref1?: string;
74
+ ref2?: string;
75
+ filepath?: string;
76
+ }
77
+ interface GitUser {
78
+ name: string;
79
+ email: string;
80
+ }
81
+ interface CommitObject {
82
+ oid: string;
83
+ commit: {
84
+ message: string;
85
+ author: {
86
+ name: string | "Morph AI Agent";
87
+ email: string | "ai@morphllm.com";
88
+ timestamp: number;
89
+ };
90
+ committer: {
91
+ name: string | "Morph AI Agent";
92
+ email: string | "ai@morphllm.com";
93
+ timestamp: number;
94
+ };
95
+ };
96
+ }
97
+ interface StatusResult {
98
+ filepath: string;
99
+ status: 'unmodified' | 'modified' | '*modified' | 'added' | '*added' | 'deleted' | '*deleted' | 'absent';
100
+ }
101
+
102
+ export type { AddOptions, BranchOptions, ChatMessage, CheckoutOptions, CloneOptions, CommitMetadata, CommitObject, CommitOptions, DiffOptions, GitUser, LogOptions, MorphGitConfig, PullOptions, PushOptions, StatusOptions, StatusResult };
@@ -0,0 +1,14 @@
1
+ export { MorphClient, MorphClientConfig } from './client.js';
2
+ export { FastApplyClient } from './tools/fastapply/core.js';
3
+ export { CodebaseSearchClient } from './tools/codebase_search/core.js';
4
+ export { BrowserClient } from './tools/browser/core.js';
5
+ export { MorphGit } from './git/client.js';
6
+ export { MorphGitConfig } from './git/types.js';
7
+ export { AnthropicRouter, GeminiRouter, OpenAIRouter } from './modelrouter/core.js';
8
+ export { EditFileConfig, EditFileInput, EditFileResult } from './tools/fastapply/types.js';
9
+ export { CodebaseSearchConfig, CodebaseSearchInput, CodebaseSearchResult } from './tools/codebase_search/types.js';
10
+ export { BrowserConfig, BrowserError, BrowserTaskInput, BrowserTaskInputWithSchema, BrowserTaskResult, BrowserTaskWithPromise, BrowserTaskWithPromiseAndSchema, ErrorsResponse, RecordingStatus } from './tools/browser/types.js';
11
+ export { ComplexityLevel, Provider, RouterConfig, RouterInput, RouterMode, RouterResult } from './modelrouter/types.js';
12
+ export { RetryConfig } from './tools/utils/resilience.js';
13
+ import 'isomorphic-git';
14
+ import 'isomorphic-git/http/node';
package/dist/index.js CHANGED
@@ -1,15 +1,15 @@
1
1
  import {
2
2
  MorphClient
3
- } from "./chunk-CMKITT6X.js";
4
- import {
5
- BrowserClient
6
- } from "./chunk-NCVWIW7L.js";
3
+ } from "./chunk-DJSQUQGY.js";
7
4
  import {
8
5
  CodebaseSearchClient
9
6
  } from "./chunk-AG3ICTC5.js";
10
7
  import {
11
8
  FastApplyClient
12
9
  } from "./chunk-Q7USYY6R.js";
10
+ import {
11
+ BrowserClient
12
+ } from "./chunk-NCVWIW7L.js";
13
13
  import "./chunk-Q7PDN7TS.js";
14
14
  import {
15
15
  MorphGit
@@ -0,0 +1,56 @@
1
+ import { RouterConfig, Provider, RouterInput, RouterResult } from './types.js';
2
+
3
+ /**
4
+ * Core implementation for intelligent model routing
5
+ */
6
+
7
+ declare abstract class BaseRouter {
8
+ protected config: Required<Omit<RouterConfig, 'apiKey' | 'retryConfig'>> & Pick<RouterConfig, 'apiKey' | 'retryConfig'>;
9
+ protected provider: Provider;
10
+ constructor(provider: Provider, config?: RouterConfig);
11
+ /**
12
+ * Select the optimal model for a given input and mode
13
+ */
14
+ selectModel(input: RouterInput): Promise<RouterResult>;
15
+ }
16
+ /**
17
+ * OpenAI model router for GPT-5 series
18
+ */
19
+ declare class OpenAIRouter extends BaseRouter {
20
+ constructor(config?: RouterConfig);
21
+ /**
22
+ * Select optimal GPT-5 model
23
+ *
24
+ * @param input - User input and mode
25
+ * @returns Selected model name (gpt-5-mini | gpt-5-low | gpt-5-medium | gpt-5-high)
26
+ */
27
+ selectModel(input: RouterInput): Promise<RouterResult>;
28
+ }
29
+ /**
30
+ * Anthropic model router for Claude 4.5 series
31
+ */
32
+ declare class AnthropicRouter extends BaseRouter {
33
+ constructor(config?: RouterConfig);
34
+ /**
35
+ * Select optimal Claude model
36
+ *
37
+ * @param input - User input and mode
38
+ * @returns Selected model name (claude-4.5-haiku | claude-4.5-sonnet)
39
+ */
40
+ selectModel(input: RouterInput): Promise<RouterResult>;
41
+ }
42
+ /**
43
+ * Google Gemini model router
44
+ */
45
+ declare class GeminiRouter extends BaseRouter {
46
+ constructor(config?: RouterConfig);
47
+ /**
48
+ * Select optimal Gemini model
49
+ *
50
+ * @param input - User input and mode
51
+ * @returns Selected model name (gemini-2.5-flash | gemini-2.5-pro)
52
+ */
53
+ selectModel(input: RouterInput): Promise<RouterResult>;
54
+ }
55
+
56
+ export { AnthropicRouter, GeminiRouter, OpenAIRouter };
@@ -0,0 +1,2 @@
1
+ export { AnthropicRouter, GeminiRouter, OpenAIRouter } from './core.js';
2
+ export { ComplexityLevel, Provider, RouterConfig, RouterInput, RouterMode, RouterResult } from './types.js';
@@ -0,0 +1,35 @@
1
+ /**
2
+ * Model router types for intelligent model selection
3
+ */
4
+ type ComplexityLevel = 'easy' | 'medium' | 'hard' | 'needs-info';
5
+ type RouterMode = 'balanced' | 'aggressive';
6
+ type Provider = 'openai' | 'anthropic' | 'gemini';
7
+ interface RouterConfig {
8
+ /** Morph API key (defaults to MORPH_API_KEY env var) */
9
+ apiKey?: string;
10
+ /** Router API URL (defaults to https://api.morphllm.com) */
11
+ apiUrl?: string;
12
+ /** Request timeout in milliseconds (default: 10000) */
13
+ timeout?: number;
14
+ /** Enable debug logging */
15
+ debug?: boolean;
16
+ /** Retry configuration */
17
+ retryConfig?: {
18
+ maxRetries?: number;
19
+ initialDelay?: number;
20
+ maxDelay?: number;
21
+ backoffMultiplier?: number;
22
+ };
23
+ }
24
+ interface RouterInput {
25
+ /** User input or task description */
26
+ input: string;
27
+ /** Routing mode: balanced (cheaper models) or aggressive (more capable models) */
28
+ mode?: RouterMode;
29
+ }
30
+ interface RouterResult {
31
+ /** Selected model name */
32
+ model: string;
33
+ }
34
+
35
+ export type { ComplexityLevel, Provider, RouterConfig, RouterInput, RouterMode, RouterResult };
@@ -0,0 +1,111 @@
1
+ import { ChatCompletionTool } from 'openai/resources/chat/completions';
2
+ import { EditFileInput, EditFileConfig, EditFileResult } from './tools/fastapply/types.js';
3
+
4
+ /**
5
+ * OpenAI SDK adapter for edit_file tool
6
+ */
7
+
8
+ /**
9
+ * OpenAI-native tool definition for edit_file
10
+ *
11
+ * @example
12
+ * ```ts
13
+ * import OpenAI from 'openai';
14
+ * import { editFileTool } from 'morphsdk/tools/openai';
15
+ *
16
+ * const client = new OpenAI({ apiKey: process.env.OPENAI_API_KEY });
17
+ *
18
+ * const response = await client.chat.completions.create({
19
+ * model: "gpt-4o",
20
+ * tools: [editFileTool],
21
+ * messages: [{ role: "user", content: "Fix the bug in app.ts" }]
22
+ * });
23
+ * ```
24
+ */
25
+ declare const editFileTool: ChatCompletionTool;
26
+ /**
27
+ * Execute an edit_file tool call
28
+ *
29
+ * @param input - The tool input from GPT (parsed from tool_calls)
30
+ * @param config - Optional configuration
31
+ * @returns The result of the edit operation
32
+ *
33
+ * @example
34
+ * ```ts
35
+ * const args = JSON.parse(toolCall.function.arguments);
36
+ * const result = await execute(args);
37
+ * console.log('Changes applied:', result.udiff);
38
+ * ```
39
+ */
40
+ declare function execute(input: EditFileInput, config?: EditFileConfig): Promise<EditFileResult>;
41
+ /**
42
+ * Get the system prompt for edit_file usage
43
+ *
44
+ * Add this to your system message to guide GPT on using edit_file properly.
45
+ *
46
+ * @example
47
+ * ```ts
48
+ * const response = await client.chat.completions.create({
49
+ * model: "gpt-4o",
50
+ * messages: [
51
+ * { role: "system", content: getSystemPrompt() },
52
+ * { role: "user", content: "Fix bugs" }
53
+ * ],
54
+ * tools: [editFileTool]
55
+ * });
56
+ * ```
57
+ */
58
+ declare function getSystemPrompt(): string;
59
+ /**
60
+ * Format the result for passing back to GPT
61
+ *
62
+ * @param result - The edit result
63
+ * @returns Formatted string for tool message
64
+ */
65
+ declare function formatResult(result: EditFileResult): string;
66
+ /**
67
+ * Create a custom edit_file tool with configuration and methods
68
+ *
69
+ * @param config - Configuration options
70
+ * @returns Tool definition with execute and formatResult methods
71
+ *
72
+ * @example
73
+ * ```ts
74
+ * import OpenAI from 'openai';
75
+ * import { createEditFileTool } from 'morphsdk/tools/fastapply/openai';
76
+ *
77
+ * const tool = createEditFileTool({
78
+ * baseDir: './src',
79
+ * generateUdiff: true,
80
+ * description: 'Custom tool description for your use case'
81
+ * });
82
+ *
83
+ * const client = new OpenAI();
84
+ *
85
+ * const response = await client.chat.completions.create({
86
+ * model: 'gpt-4o',
87
+ * tools: [tool], // tool itself is the ChatCompletionTool
88
+ * messages: [{ role: 'user', content: 'Fix bug in app.ts' }]
89
+ * });
90
+ *
91
+ * // Execute and format
92
+ * const result = await tool.execute(toolCallArgs);
93
+ * const formatted = tool.formatResult(result);
94
+ * ```
95
+ */
96
+ declare function createEditFileTool(config?: EditFileConfig): ChatCompletionTool & {
97
+ execute: (input: EditFileInput | string) => Promise<EditFileResult>;
98
+ formatResult: (result: EditFileResult) => string;
99
+ getSystemPrompt: () => string;
100
+ };
101
+
102
+ declare const openai_createEditFileTool: typeof createEditFileTool;
103
+ declare const openai_editFileTool: typeof editFileTool;
104
+ declare const openai_execute: typeof execute;
105
+ declare const openai_formatResult: typeof formatResult;
106
+ declare const openai_getSystemPrompt: typeof getSystemPrompt;
107
+ declare namespace openai {
108
+ export { openai_createEditFileTool as createEditFileTool, editFileTool as default, openai_editFileTool as editFileTool, openai_execute as execute, openai_formatResult as formatResult, openai_getSystemPrompt as getSystemPrompt };
109
+ }
110
+
111
+ export { execute as a, createEditFileTool as c, editFileTool as e, formatResult as f, getSystemPrompt as g, openai as o };
@@ -0,0 +1,51 @@
1
+ import { Tool } from '@anthropic-ai/sdk/resources/messages.mjs';
2
+ import { BrowserConfig, BrowserTaskInput, BrowserTaskResult } from './types.js';
3
+ import '../utils/resilience.js';
4
+
5
+ /**
6
+ * Anthropic SDK adapter for browser automation tool
7
+ */
8
+
9
+ /**
10
+ * Anthropic tool definition for browser automation
11
+ */
12
+ declare const browserTool: Tool;
13
+ /**
14
+ * Create a configured browser tool with execute and formatResult methods
15
+ *
16
+ * @param config - Browser worker configuration
17
+ * @returns Tool definition with execute and formatResult methods
18
+ *
19
+ * @example
20
+ * ```typescript
21
+ * import Anthropic from '@anthropic-ai/sdk';
22
+ * import { createBrowserTool } from 'morphsdk/tools/browser/anthropic';
23
+ *
24
+ * const tool = createBrowserTool({
25
+ * apiKey: process.env.MORPH_API_KEY,
26
+ * timeout: 180000
27
+ * });
28
+ *
29
+ * const client = new Anthropic();
30
+ *
31
+ * const response = await client.messages.create({
32
+ * model: 'claude-sonnet-4-5-20250929',
33
+ * tools: [tool], // tool itself is the Tool definition
34
+ * messages: [{
35
+ * role: 'user',
36
+ * content: 'Test the checkout flow at https://3000-abc.e2b.dev'
37
+ * }]
38
+ * });
39
+ *
40
+ * // Execute and format
41
+ * const result = await tool.execute(toolUseBlock.input);
42
+ * const formatted = tool.formatResult(result);
43
+ * ```
44
+ */
45
+ declare function createBrowserTool(config?: BrowserConfig): Tool & {
46
+ execute: (input: BrowserTaskInput) => Promise<BrowserTaskResult>;
47
+ formatResult: (result: BrowserTaskResult) => string;
48
+ getSystemPrompt: () => string;
49
+ };
50
+
51
+ export { browserTool, createBrowserTool };
@@ -0,0 +1,203 @@
1
+ import { BrowserConfig, BrowserTaskInput, BrowserTaskResult, BrowserTaskWithPromise, BrowserTaskInputWithSchema, BrowserTaskWithPromiseAndSchema, RecordingStatus, ErrorsResponse } from './types.js';
2
+ import '../utils/resilience.js';
3
+
4
+ /**
5
+ * Core implementation for browser automation tasks
6
+ */
7
+
8
+ /**
9
+ * BrowserClient class for easier usage with instance configuration
10
+ */
11
+ declare class BrowserClient {
12
+ private config;
13
+ constructor(config?: BrowserConfig);
14
+ /**
15
+ * Execute a browser automation task
16
+ */
17
+ execute(input: BrowserTaskInput): Promise<BrowserTaskResult>;
18
+ createTask(input: BrowserTaskInput): Promise<BrowserTaskWithPromise>;
19
+ createTask<T>(input: BrowserTaskInputWithSchema<T>): Promise<BrowserTaskWithPromiseAndSchema<T>>;
20
+ /**
21
+ * Execute task with recording and wait for video to be ready
22
+ */
23
+ executeWithRecording(input: BrowserTaskInput & {
24
+ record_video: true;
25
+ }): Promise<BrowserTaskResult & {
26
+ recording?: RecordingStatus;
27
+ }>;
28
+ /**
29
+ * Get recording status and URLs
30
+ */
31
+ getRecording(recordingId: string): Promise<RecordingStatus>;
32
+ /**
33
+ * Wait for recording to complete with automatic polling
34
+ */
35
+ waitForRecording(recordingId: string, options?: {
36
+ timeout?: number;
37
+ pollInterval?: number;
38
+ }): Promise<RecordingStatus>;
39
+ /**
40
+ * Get errors from recording with screenshots
41
+ */
42
+ getErrors(recordingId: string): Promise<ErrorsResponse>;
43
+ /**
44
+ * Check if browser worker service is healthy
45
+ */
46
+ checkHealth(): Promise<{
47
+ ok: boolean;
48
+ google_configured: boolean;
49
+ database_configured: boolean;
50
+ s3_configured: boolean;
51
+ error?: string;
52
+ }>;
53
+ }
54
+ /**
55
+ * Execute a natural language browser automation task
56
+ *
57
+ * Returns the full task result including rich agent history data (urls, errors,
58
+ * action_history, judgement, etc.). When using this as an agent tool, use the
59
+ * formatResult() functions from the SDK adapters to return a concise summary.
60
+ *
61
+ * @param input - Task parameters
62
+ * @param config - Optional configuration (apiKey, apiUrl to override default)
63
+ * @returns Task result with success status, findings, and comprehensive execution history
64
+ *
65
+ * @example
66
+ * ```typescript
67
+ * const result = await executeBrowserTask(
68
+ * {
69
+ * task: "Test checkout flow for buying a pineapple",
70
+ * url: "https://3000-abc.e2b.dev",
71
+ * max_steps: 20,
72
+ * repo_id: "my-project",
73
+ * commit_id: "uuid-here"
74
+ * },
75
+ * {
76
+ * apiKey: process.env.MORPH_API_KEY,
77
+ * // apiUrl: 'http://localhost:8001' // Override for local testing
78
+ * }
79
+ * );
80
+ *
81
+ * if (result.success) {
82
+ * console.log('Task completed:', result.result);
83
+ * console.log('URLs visited:', result.urls);
84
+ * console.log('Actions taken:', result.action_names);
85
+ * console.log('Has errors:', result.has_errors);
86
+ * console.log('Replay:', result.replay_url);
87
+ * }
88
+ * ```
89
+ */
90
+ declare function executeBrowserTask(input: BrowserTaskInput, config?: BrowserConfig): Promise<BrowserTaskResult>;
91
+ /**
92
+ * Get recording status and video URL
93
+ *
94
+ * @param recordingId - Recording UUID from BrowserTaskResult
95
+ * @param config - Configuration with apiKey
96
+ * @returns Recording status with video URL when ready
97
+ *
98
+ * @example
99
+ * ```typescript
100
+ * const status = await getRecording('uuid-here', { apiKey: 'key' });
101
+ * if (status.status === 'COMPLETED' && status.video_url) {
102
+ * console.log('Video ready:', status.video_url);
103
+ * }
104
+ * ```
105
+ */
106
+ declare function getRecording(recordingId: string, config?: BrowserConfig): Promise<RecordingStatus>;
107
+ /**
108
+ * Wait for recording to complete with automatic polling
109
+ *
110
+ * @param recordingId - Recording UUID
111
+ * @param config - Configuration with apiKey
112
+ * @param options - Polling options
113
+ * @returns Recording status when completed or errored
114
+ *
115
+ * @example
116
+ * ```typescript
117
+ * const result = await executeBrowserTask({ task: '...', record_video: true }, config);
118
+ * if (result.recording_id) {
119
+ * const recording = await waitForRecording(result.recording_id, config, {
120
+ * timeout: 60000, // 1 minute
121
+ * pollInterval: 2000 // Check every 2 seconds
122
+ * });
123
+ * console.log('Video URL:', recording.video_url);
124
+ * }
125
+ * ```
126
+ */
127
+ declare function waitForRecording(recordingId: string, config?: BrowserConfig, options?: {
128
+ timeout?: number;
129
+ pollInterval?: number;
130
+ }): Promise<RecordingStatus>;
131
+ /**
132
+ * Execute task with recording and wait for video to be ready
133
+ *
134
+ * @param input - Task parameters with record_video=true
135
+ * @param config - Configuration with apiKey
136
+ * @returns Task result with ready video URL
137
+ *
138
+ * @example
139
+ * ```typescript
140
+ * const result = await executeWithRecording(
141
+ * {
142
+ * task: "Test checkout flow",
143
+ * url: "https://example.com",
144
+ * record_video: true,
145
+ * repo_id: "my-project"
146
+ * },
147
+ * { apiKey: process.env.MORPH_API_KEY }
148
+ * );
149
+ *
150
+ * console.log('Task result:', result.result);
151
+ * console.log('Video URL:', result.recording?.video_url);
152
+ * ```
153
+ */
154
+ declare function executeWithRecording(input: BrowserTaskInput & {
155
+ record_video: true;
156
+ }, config?: BrowserConfig): Promise<BrowserTaskResult & {
157
+ recording?: RecordingStatus;
158
+ }>;
159
+ /**
160
+ * Get errors from recording with screenshots
161
+ *
162
+ * Screenshots are captured in real-time (500ms after error occurs) during the browser session.
163
+ *
164
+ * @param recordingId - Recording UUID from BrowserTaskResult
165
+ * @param config - Configuration with apiKey
166
+ * @returns Errors with real-time screenshots
167
+ *
168
+ * @example
169
+ * ```typescript
170
+ * const { errors, total_errors } = await getErrors('uuid-here', { apiKey: 'key' });
171
+ *
172
+ * console.log(`Found ${total_errors} errors`);
173
+ *
174
+ * errors.forEach(err => {
175
+ * console.log(`[${err.type}] ${err.message}`);
176
+ * if (err.url) console.log(` URL: ${err.url}`);
177
+ * if (err.screenshot_url) console.log(` Screenshot: ${err.screenshot_url}`);
178
+ *
179
+ * // Download screenshot
180
+ * if (err.screenshot_url) {
181
+ * const response = await fetch(err.screenshot_url);
182
+ * const screenshot = await response.arrayBuffer();
183
+ * // Save or process screenshot
184
+ * }
185
+ * });
186
+ * ```
187
+ */
188
+ declare function getErrors(recordingId: string, config?: BrowserConfig): Promise<ErrorsResponse>;
189
+ /**
190
+ * Check if browser worker service is healthy
191
+ *
192
+ * @param config - Optional configuration
193
+ * @returns Health status
194
+ */
195
+ declare function checkHealth(config?: BrowserConfig): Promise<{
196
+ ok: boolean;
197
+ google_configured: boolean;
198
+ database_configured: boolean;
199
+ s3_configured: boolean;
200
+ error?: string;
201
+ }>;
202
+
203
+ export { BrowserClient, checkHealth, executeBrowserTask, executeWithRecording, getErrors, getRecording, waitForRecording };
@@ -0,0 +1,72 @@
1
+ export { BrowserClient, checkHealth, executeBrowserTask, executeWithRecording, getErrors, getRecording, waitForRecording } from './core.js';
2
+ import { LiveSessionOptions, IframeOptions } from './types.js';
3
+ export { BrowserConfig, BrowserError, BrowserModel, BrowserTaskInput, BrowserTaskInputWithSchema, BrowserTaskResult, BrowserTaskWithPromise, BrowserTaskWithPromiseAndSchema, ErrorsResponse, RecordingStatus } from './types.js';
4
+ export { BROWSER_SYSTEM_PROMPT, BROWSER_TOOL_DESCRIPTION } from './prompts.js';
5
+ import '../utils/resilience.js';
6
+
7
+ /**
8
+ * Live session utilities for Morph browser sessions
9
+ *
10
+ * Provides helpers for embedding and sharing live browser sessions with WebRTC streaming.
11
+ */
12
+
13
+ /**
14
+ * Preset configurations for common use cases
15
+ */
16
+ declare const LIVE_PRESETS: {
17
+ /** Read-only monitoring (no interaction) */
18
+ readonly readonly: LiveSessionOptions;
19
+ /** Interactive control (human-in-the-loop) */
20
+ readonly interactive: LiveSessionOptions;
21
+ /** Watch-only without controls */
22
+ readonly monitoring: LiveSessionOptions;
23
+ };
24
+ /**
25
+ * Build a live session URL with query parameters
26
+ *
27
+ * @param debugUrl - Live session debug URL (e.g., from task.debugUrl)
28
+ * @param options - Live session configuration options
29
+ * @returns URL with query parameters for iframe embedding
30
+ *
31
+ * @example
32
+ * ```typescript
33
+ * const url = buildLiveUrl(task.debugUrl, { interactive: true });
34
+ * // Returns: https://example.com/sessions/abc?interactive=true
35
+ * ```
36
+ */
37
+ declare function buildLiveUrl(debugUrl: string, options?: LiveSessionOptions): string;
38
+ /**
39
+ * Build iframe HTML for embedding a live session
40
+ *
41
+ * @param debugUrl - Live session debug URL
42
+ * @param options - Iframe configuration including dimensions and session options
43
+ * @returns HTML iframe element as string
44
+ *
45
+ * @example
46
+ * ```typescript
47
+ * const iframe = buildLiveIframe(task.debugUrl, {
48
+ * interactive: true,
49
+ * width: '100%',
50
+ * height: '600px'
51
+ * });
52
+ * ```
53
+ */
54
+ declare function buildLiveIframe(debugUrl: string, options?: IframeOptions): string;
55
+ /**
56
+ * Build complete embed code with HTML snippet
57
+ *
58
+ * @param debugUrl - Live session debug URL
59
+ * @param options - Iframe configuration
60
+ * @returns Multi-line HTML snippet ready to copy-paste
61
+ *
62
+ * @example
63
+ * ```typescript
64
+ * const code = buildEmbedCode(task.debugUrl, { interactive: false });
65
+ * console.log(code);
66
+ * // <!-- Embed Morph Live Session -->
67
+ * // <iframe src="..." style="..."></iframe>
68
+ * ```
69
+ */
70
+ declare function buildEmbedCode(debugUrl: string, options?: IframeOptions): string;
71
+
72
+ export { IframeOptions, LIVE_PRESETS, LiveSessionOptions, buildEmbedCode, buildLiveIframe, buildLiveUrl };