@morphllm/morphsdk 0.2.27 → 0.2.32

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 (107) hide show
  1. package/README.md +195 -3
  2. package/dist/anthropic-DpEAqqZF.d.ts +88 -0
  3. package/dist/{chunk-LFYQ6GKI.js → chunk-4OBDFXR4.js} +2 -2
  4. package/dist/{chunk-S3HTYGYF.js → chunk-B4H7N4GZ.js} +14 -2
  5. package/dist/chunk-B4H7N4GZ.js.map +1 -0
  6. package/dist/{chunk-HNYSKGCP.js → chunk-BGDEQTRF.js} +2 -2
  7. package/dist/{chunk-PRIYMEI6.js → chunk-JJ5ONKDN.js} +4 -4
  8. package/dist/{chunk-2DXRTGRH.js → chunk-Q7PDN7TS.js} +1 -1
  9. package/dist/chunk-Q7PDN7TS.js.map +1 -0
  10. package/dist/{chunk-DF2ZOO7R.js → chunk-TBVDBQZ2.js} +19 -3
  11. package/dist/chunk-TBVDBQZ2.js.map +1 -0
  12. package/dist/{chunk-22WVN4MC.js → chunk-U6ZHZ5LY.js} +11 -11
  13. package/dist/{chunk-ZKIVLLZY.js → chunk-VD7US3AJ.js} +2 -2
  14. package/dist/client.cjs +18 -2
  15. package/dist/client.cjs.map +1 -1
  16. package/dist/client.d.ts +114 -0
  17. package/dist/client.js +6 -6
  18. package/dist/git/client.cjs +18 -2
  19. package/dist/git/client.cjs.map +1 -1
  20. package/dist/git/client.d.ts +261 -0
  21. package/dist/git/client.js +1 -1
  22. package/dist/git/config.d.ts +11 -0
  23. package/dist/git/index.cjs +18 -2
  24. package/dist/git/index.cjs.map +1 -1
  25. package/dist/git/index.d.ts +5 -0
  26. package/dist/git/index.js +2 -2
  27. package/dist/git/types.cjs.map +1 -1
  28. package/dist/git/types.d.ts +102 -0
  29. package/dist/index.cjs +18 -2
  30. package/dist/index.cjs.map +1 -1
  31. package/dist/index.d.ts +14 -0
  32. package/dist/index.js +12 -12
  33. package/dist/modelrouter/core.d.ts +56 -0
  34. package/dist/modelrouter/index.d.ts +2 -0
  35. package/dist/modelrouter/types.d.ts +35 -0
  36. package/dist/openai-BkKsS30n.d.ts +111 -0
  37. package/dist/tools/browser/anthropic.d.ts +51 -0
  38. package/dist/tools/browser/core.d.ts +203 -0
  39. package/dist/tools/browser/index.d.ts +72 -0
  40. package/dist/tools/browser/openai.d.ts +73 -0
  41. package/dist/tools/browser/prompts.d.ts +7 -0
  42. package/dist/tools/browser/types.d.ts +255 -0
  43. package/dist/tools/browser/vercel.d.ts +69 -0
  44. package/dist/tools/codebase_search/anthropic.d.ts +40 -0
  45. package/dist/tools/codebase_search/core.d.ts +40 -0
  46. package/dist/tools/codebase_search/index.d.ts +10 -0
  47. package/dist/tools/codebase_search/index.js +3 -3
  48. package/dist/tools/codebase_search/openai.d.ts +87 -0
  49. package/dist/tools/codebase_search/prompts.d.ts +7 -0
  50. package/dist/tools/codebase_search/types.d.ts +50 -0
  51. package/dist/tools/codebase_search/vercel.d.ts +65 -0
  52. package/dist/tools/fastapply/anthropic.cjs +14 -2
  53. package/dist/tools/fastapply/anthropic.cjs.map +1 -1
  54. package/dist/tools/fastapply/anthropic.d.ts +4 -0
  55. package/dist/tools/fastapply/anthropic.js +9 -3
  56. package/dist/tools/fastapply/core.d.ts +41 -0
  57. package/dist/tools/fastapply/index.cjs +18 -9
  58. package/dist/tools/fastapply/index.cjs.map +1 -1
  59. package/dist/tools/fastapply/index.d.ts +10 -0
  60. package/dist/tools/fastapply/index.js +3 -3
  61. package/dist/tools/fastapply/openai.d.ts +4 -0
  62. package/dist/tools/fastapply/prompts.d.ts +7 -0
  63. package/dist/tools/fastapply/types.d.ts +77 -0
  64. package/dist/tools/fastapply/vercel.d.ts +4 -0
  65. package/dist/tools/index.cjs +18 -9
  66. package/dist/tools/index.cjs.map +1 -1
  67. package/dist/tools/index.d.ts +10 -0
  68. package/dist/tools/index.js +3 -3
  69. package/dist/tools/utils/resilience.d.ts +58 -0
  70. package/dist/tools/warp_grep/agent/config.d.ts +8 -0
  71. package/dist/tools/warp_grep/agent/formatter.d.ts +14 -0
  72. package/dist/tools/warp_grep/agent/grep_helpers.d.ts +16 -0
  73. package/dist/tools/warp_grep/agent/parser.d.ts +16 -0
  74. package/dist/tools/warp_grep/agent/prompt.d.ts +4 -0
  75. package/dist/tools/warp_grep/agent/runner.d.ts +10 -0
  76. package/dist/tools/warp_grep/agent/runner.js +2 -2
  77. package/dist/tools/warp_grep/agent/types.cjs.map +1 -1
  78. package/dist/tools/warp_grep/agent/types.d.ts +44 -0
  79. package/dist/tools/warp_grep/anthropic.d.ts +14 -0
  80. package/dist/tools/warp_grep/anthropic.js +6 -6
  81. package/dist/tools/warp_grep/index.d.ts +11 -0
  82. package/dist/tools/warp_grep/index.js +8 -8
  83. package/dist/tools/warp_grep/openai.d.ts +33 -0
  84. package/dist/tools/warp_grep/openai.js +6 -6
  85. package/dist/tools/warp_grep/providers/command.d.ts +48 -0
  86. package/dist/tools/warp_grep/providers/local.d.ts +30 -0
  87. package/dist/tools/warp_grep/providers/types.d.ts +49 -0
  88. package/dist/tools/warp_grep/tools/analyse.d.ts +10 -0
  89. package/dist/tools/warp_grep/tools/finish.d.ts +10 -0
  90. package/dist/tools/warp_grep/tools/grep.d.ts +8 -0
  91. package/dist/tools/warp_grep/tools/read.d.ts +9 -0
  92. package/dist/tools/warp_grep/utils/files.d.ts +3 -0
  93. package/dist/tools/warp_grep/utils/format.d.ts +4 -0
  94. package/dist/tools/warp_grep/utils/paths.d.ts +7 -0
  95. package/dist/tools/warp_grep/utils/ripgrep.d.ts +11 -0
  96. package/dist/tools/warp_grep/vercel.d.ts +33 -0
  97. package/dist/tools/warp_grep/vercel.js +6 -6
  98. package/dist/vercel-B1GZ_g9N.d.ts +69 -0
  99. package/package.json +1 -1
  100. package/dist/chunk-2DXRTGRH.js.map +0 -1
  101. package/dist/chunk-DF2ZOO7R.js.map +0 -1
  102. package/dist/chunk-S3HTYGYF.js.map +0 -1
  103. /package/dist/{chunk-LFYQ6GKI.js.map → chunk-4OBDFXR4.js.map} +0 -0
  104. /package/dist/{chunk-HNYSKGCP.js.map → chunk-BGDEQTRF.js.map} +0 -0
  105. /package/dist/{chunk-PRIYMEI6.js.map → chunk-JJ5ONKDN.js.map} +0 -0
  106. /package/dist/{chunk-22WVN4MC.js.map → chunk-U6ZHZ5LY.js.map} +0 -0
  107. /package/dist/{chunk-ZKIVLLZY.js.map → chunk-VD7US3AJ.js.map} +0 -0
@@ -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,24 +1,24 @@
1
1
  import {
2
2
  MorphClient
3
- } from "./chunk-22WVN4MC.js";
3
+ } from "./chunk-U6ZHZ5LY.js";
4
4
  import {
5
- BrowserClient
6
- } from "./chunk-NCVWIW7L.js";
7
- import {
8
- FastApplyClient
9
- } from "./chunk-Q7USYY6R.js";
5
+ AnthropicRouter,
6
+ GeminiRouter,
7
+ OpenAIRouter
8
+ } from "./chunk-AKVAAKRB.js";
10
9
  import {
11
10
  CodebaseSearchClient
12
11
  } from "./chunk-AG3ICTC5.js";
13
- import "./chunk-2DXRTGRH.js";
12
+ import "./chunk-Q7PDN7TS.js";
14
13
  import {
15
14
  MorphGit
16
- } from "./chunk-DF2ZOO7R.js";
15
+ } from "./chunk-TBVDBQZ2.js";
17
16
  import {
18
- AnthropicRouter,
19
- GeminiRouter,
20
- OpenAIRouter
21
- } from "./chunk-AKVAAKRB.js";
17
+ FastApplyClient
18
+ } from "./chunk-Q7USYY6R.js";
19
+ import {
20
+ BrowserClient
21
+ } from "./chunk-NCVWIW7L.js";
22
22
  import "./chunk-4VWJFZVS.js";
23
23
  import "./chunk-PZ5AY32C.js";
24
24
  export {
@@ -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 };
@@ -0,0 +1,73 @@
1
+ import { ChatCompletionTool } from 'openai/resources/chat/completions.mjs';
2
+ import { BrowserTaskInput, BrowserConfig, BrowserTaskResult } from './types.js';
3
+ import '../utils/resilience.js';
4
+
5
+ /**
6
+ * OpenAI SDK adapter for browser automation tool
7
+ */
8
+
9
+ /**
10
+ * OpenAI tool definition for browser automation
11
+ */
12
+ declare const browserTool: ChatCompletionTool;
13
+ /**
14
+ * Execute a browser task (for use in tool call handling)
15
+ *
16
+ * @param input - Tool input parameters (may be JSON string)
17
+ * @param config - Optional browser worker configuration
18
+ * @returns Task execution result
19
+ */
20
+ declare function execute(input: BrowserTaskInput | string, config?: BrowserConfig): Promise<BrowserTaskResult>;
21
+ /**
22
+ * Format browser task result for OpenAI tool result
23
+ *
24
+ * Returns a concise summary suitable for agent context. The full result object
25
+ * (with urls, errors, action_history, judgement, etc.) is available when calling
26
+ * execute() directly, but this formatted string omits those details to save tokens.
27
+ *
28
+ * @param result - Browser task result with full history data
29
+ * @returns Formatted string summary for tool result
30
+ */
31
+ declare function formatResult(result: BrowserTaskResult): string;
32
+ /**
33
+ * Get system prompt for browser automation
34
+ */
35
+ declare function getSystemPrompt(): string;
36
+ /**
37
+ * Create a configured browser tool with execute and formatResult methods
38
+ *
39
+ * @param config - Browser worker configuration
40
+ * @returns Tool definition with execute and formatResult methods
41
+ *
42
+ * @example
43
+ * ```typescript
44
+ * import OpenAI from 'openai';
45
+ * import { createBrowserTool } from 'morphsdk/tools/browser/openai';
46
+ *
47
+ * const tool = createBrowserTool({
48
+ * apiUrl: 'https://browser-worker.example.com'
49
+ * });
50
+ *
51
+ * const client = new OpenAI();
52
+ *
53
+ * const response = await client.chat.completions.create({
54
+ * model: 'gpt-4o',
55
+ * tools: [tool], // tool itself is the ChatCompletionTool
56
+ * messages: [{
57
+ * role: 'user',
58
+ * content: 'Test the checkout at https://3000-abc.e2b.dev'
59
+ * }]
60
+ * });
61
+ *
62
+ * // Execute and format
63
+ * const result = await tool.execute(toolCallArgs);
64
+ * const formatted = tool.formatResult(result);
65
+ * ```
66
+ */
67
+ declare function createBrowserTool(config?: BrowserConfig): ChatCompletionTool & {
68
+ execute: (input: BrowserTaskInput | string) => Promise<BrowserTaskResult>;
69
+ formatResult: (result: BrowserTaskResult) => string;
70
+ getSystemPrompt: () => string;
71
+ };
72
+
73
+ export { browserTool, createBrowserTool, execute, formatResult, getSystemPrompt };
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Tool descriptions and prompts for AI models
3
+ */
4
+ declare const BROWSER_TOOL_DESCRIPTION = "Test and verify your implemented code in a live browser. This tool executes natural language test instructions and returns a video recording plus detailed logs to help you debug issues.\n\n## When to Use\nUse this AFTER coding is complete to verify your implementation:\n- You've finished writing/modifying code and need to verify it works\n- You need to test user interactions end-to-end (clicks, forms, navigation)\n- You want to catch runtime errors, console warnings, or network failures\n- You need visual confirmation that UI elements render and behave correctly\n\n## What You Get Back\nThe tool returns debugging artifacts to help you identify and fix issues:\n- **Video recording**: Watch exactly what happened in the browser session\n- **Console logs**: All console.log, warnings, and errors with timestamps\n- **Network logs**: Failed requests, 404s, API errors with screenshots\n- **Error screenshots**: Visual snapshots captured when errors occur\n\n## How to Write Good Tests\nBe specific about the user journey you're testing:\n\u274C Bad: \"Test the login feature\"\n\u2705 Good: \"Navigate to /login, enter 'test@example.com' and 'password123', click the Login button, verify we reach the /dashboard page\"\n\nInclude verification steps:\n\u2705 \"Click the Add Item button, verify the item appears in the list\"\n\u2705 \"Submit the form, verify a success message is displayed\"\n\n## Iterating on Failures\n1. Run the test and review the video + logs\n2. Identify the specific issue (console error, failed request, wrong behavior)\n3. Fix the code based on the evidence\n4. Re-run the test to verify the fix\n5. Repeat until test passes\n\n## Requirements\n- **URL**: Must be publicly accessible (use tunnels like ngrok, Cloudflare, or deploy to staging)\n- **Timing**: Use this after implementation, not during coding\n- **Complexity**: Set max_steps higher (20-30) for multi-step user workflows";
5
+ declare const BROWSER_SYSTEM_PROMPT = "You are an AI agent designed to automate browser tasks to accomplish the <user_request>. Respond with a valid JSON object in the format: {\"thinking\": \"Reason step-by-step about your current state, history, and the user request to decide your next goal and action. Analyze the browser state and screenshot to confirm the outcome of your last action.\", \"evaluation_previous_goal\": \"A concise, one-sentence evaluation of your last action's outcome (e.g., Success, Failure, or Uncertain).\", \"memory\": \"1-3 sentences summarizing key information and progress so far. This helps you track progress across multiple steps (e.g., items collected, pages visited).\", \"next_goal\": \"A clear, one-sentence description of your immediate next objective.\", \"action\": [{\"action_name\": {\"parameter\": \"value\"}}]}";
6
+
7
+ export { BROWSER_SYSTEM_PROMPT, BROWSER_TOOL_DESCRIPTION };