@morphllm/morphsdk 0.2.16 → 0.2.18

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 (84) hide show
  1. package/dist/{chunk-UIEIJZA3.js → chunk-GPFHYUKV.js} +2 -1
  2. package/dist/chunk-GPFHYUKV.js.map +1 -0
  3. package/dist/{chunk-CDFM7C52.js → chunk-UFIIEUGW.js} +9 -9
  4. package/dist/{chunk-HGIFACNP.js → chunk-VONZKK4S.js} +2 -3
  5. package/dist/chunk-VONZKK4S.js.map +1 -0
  6. package/dist/{chunk-KP75GOQS.js → chunk-Y5RCNDLV.js} +3 -5
  7. package/dist/chunk-Y5RCNDLV.js.map +1 -0
  8. package/dist/client.cjs +1 -0
  9. package/dist/client.cjs.map +1 -1
  10. package/dist/client.js +5 -5
  11. package/dist/index.cjs +1 -0
  12. package/dist/index.cjs.map +1 -1
  13. package/dist/index.js +11 -11
  14. package/dist/tools/browser/anthropic.cjs +1 -0
  15. package/dist/tools/browser/anthropic.cjs.map +1 -1
  16. package/dist/tools/browser/anthropic.js +1 -1
  17. package/dist/tools/browser/core.cjs +1 -0
  18. package/dist/tools/browser/core.cjs.map +1 -1
  19. package/dist/tools/browser/core.js +1 -1
  20. package/dist/tools/browser/index.cjs +1 -0
  21. package/dist/tools/browser/index.cjs.map +1 -1
  22. package/dist/tools/browser/index.js +1 -1
  23. package/dist/tools/browser/openai.cjs +1 -0
  24. package/dist/tools/browser/openai.cjs.map +1 -1
  25. package/dist/tools/browser/openai.js +1 -1
  26. package/dist/tools/browser/types.cjs.map +1 -1
  27. package/dist/tools/browser/vercel.cjs +1 -0
  28. package/dist/tools/browser/vercel.cjs.map +1 -1
  29. package/dist/tools/browser/vercel.js +1 -1
  30. package/dist/tools/codebase_search/index.cjs +1 -2
  31. package/dist/tools/codebase_search/index.cjs.map +1 -1
  32. package/dist/tools/codebase_search/index.js +4 -4
  33. package/dist/tools/codebase_search/vercel.cjs +1 -2
  34. package/dist/tools/codebase_search/vercel.cjs.map +1 -1
  35. package/dist/tools/codebase_search/vercel.js +1 -1
  36. package/dist/tools/fastapply/index.cjs +2 -4
  37. package/dist/tools/fastapply/index.cjs.map +1 -1
  38. package/dist/tools/fastapply/index.js +4 -4
  39. package/dist/tools/fastapply/vercel.cjs +2 -4
  40. package/dist/tools/fastapply/vercel.cjs.map +1 -1
  41. package/dist/tools/fastapply/vercel.js +1 -1
  42. package/dist/tools/index.cjs +2 -4
  43. package/dist/tools/index.cjs.map +1 -1
  44. package/dist/tools/index.js +4 -4
  45. package/package.json +2 -2
  46. package/dist/anthropic-CknfcMoO.d.ts +0 -64
  47. package/dist/chunk-HGIFACNP.js.map +0 -1
  48. package/dist/chunk-KP75GOQS.js.map +0 -1
  49. package/dist/chunk-UIEIJZA3.js.map +0 -1
  50. package/dist/client.d.ts +0 -114
  51. package/dist/git/client.d.ts +0 -230
  52. package/dist/git/config.d.ts +0 -11
  53. package/dist/git/index.d.ts +0 -5
  54. package/dist/git/types.d.ts +0 -91
  55. package/dist/index.d.ts +0 -14
  56. package/dist/modelrouter/core.d.ts +0 -56
  57. package/dist/modelrouter/index.d.ts +0 -2
  58. package/dist/modelrouter/types.d.ts +0 -35
  59. package/dist/openai-BkKsS30n.d.ts +0 -111
  60. package/dist/tools/browser/anthropic.d.ts +0 -51
  61. package/dist/tools/browser/core.d.ts +0 -196
  62. package/dist/tools/browser/index.d.ts +0 -72
  63. package/dist/tools/browser/openai.d.ts +0 -69
  64. package/dist/tools/browser/prompts.d.ts +0 -7
  65. package/dist/tools/browser/types.d.ts +0 -225
  66. package/dist/tools/browser/vercel.d.ts +0 -128
  67. package/dist/tools/codebase_search/anthropic.d.ts +0 -40
  68. package/dist/tools/codebase_search/core.d.ts +0 -40
  69. package/dist/tools/codebase_search/index.d.ts +0 -11
  70. package/dist/tools/codebase_search/openai.d.ts +0 -87
  71. package/dist/tools/codebase_search/prompts.d.ts +0 -7
  72. package/dist/tools/codebase_search/types.d.ts +0 -46
  73. package/dist/tools/codebase_search/vercel.d.ts +0 -100
  74. package/dist/tools/fastapply/anthropic.d.ts +0 -4
  75. package/dist/tools/fastapply/core.d.ts +0 -41
  76. package/dist/tools/fastapply/index.d.ts +0 -11
  77. package/dist/tools/fastapply/openai.d.ts +0 -4
  78. package/dist/tools/fastapply/prompts.d.ts +0 -7
  79. package/dist/tools/fastapply/types.d.ts +0 -77
  80. package/dist/tools/fastapply/vercel.d.ts +0 -5
  81. package/dist/tools/index.d.ts +0 -11
  82. package/dist/tools/utils/resilience.d.ts +0 -58
  83. package/dist/vercel-Cd1wjuoK.d.ts +0 -108
  84. /package/dist/{chunk-CDFM7C52.js.map → chunk-UFIIEUGW.js.map} +0 -0
@@ -1,225 +0,0 @@
1
- import { RetryConfig } from '../utils/resilience.js';
2
-
3
- /**
4
- * Type definitions for browser automation tool
5
- */
6
-
7
- /**
8
- * Available browser automation models
9
- */
10
- type BrowserModel = 'gemini-flash-latest' | 'morph-computer-use-v0';
11
- /**
12
- * Configuration for the browser worker service
13
- */
14
- interface BrowserConfig {
15
- /** Browser worker API URL (default: https://browser.morphllm.com) */
16
- apiUrl?: string;
17
- /** Morph API key for authentication (required in production) */
18
- apiKey?: string;
19
- /** Request timeout in milliseconds (default: 120000) */
20
- timeout?: number;
21
- /** Retry configuration for API calls */
22
- retryConfig?: RetryConfig;
23
- /** Enable debug logging (default: false) */
24
- debug?: boolean;
25
- }
26
- /**
27
- * Input parameters for browser automation task
28
- */
29
- interface BrowserTaskInput {
30
- /** Natural language description of what to do */
31
- task: string;
32
- /** Starting URL (e.g., https://3000-xyz.e2b.dev) */
33
- url?: string;
34
- /** Maximum number of browser actions to take (1-50, default: 10) */
35
- max_steps?: number;
36
- /** Model to use for task execution (default: morph-computer-use-v0) */
37
- model?: BrowserModel;
38
- /** Browserless region: 'sfo' (US West) or 'lon' (Europe) */
39
- region?: 'sfo' | 'lon';
40
- /** Enable stealth mode to avoid bot detection (default: true) */
41
- stealth?: boolean;
42
- /** Browser viewport width (default: 1280) */
43
- viewport_width?: number;
44
- /** Browser viewport height (default: 720) */
45
- viewport_height?: number;
46
- /** Optional repository ID to associate with this session */
47
- repo_id?: string;
48
- /** Optional commit UUID to associate with this session */
49
- commit_id?: string;
50
- /** Record session video to S3 (default: false) */
51
- record_video?: boolean;
52
- /** Video width (default: 1280) */
53
- video_width?: number;
54
- /** Video height (default: 720) */
55
- video_height?: number;
56
- /** Serialized structured output schema (internal use) */
57
- structured_output?: string;
58
- }
59
- /**
60
- * Input with Zod schema for structured output
61
- */
62
- interface BrowserTaskInputWithSchema<T> extends Omit<BrowserTaskInput, 'structured_output'> {
63
- /** Zod schema for structured output */
64
- schema: any;
65
- }
66
- /**
67
- * Result from executing a browser task
68
- */
69
- interface BrowserTaskResult {
70
- /** Whether the task completed successfully */
71
- success: boolean;
72
- /** Task result or findings */
73
- result?: string;
74
- /** Error message if task failed */
75
- error?: string;
76
- /** Number of browser actions taken */
77
- steps_taken?: number;
78
- /** Total execution time in milliseconds */
79
- execution_time_ms?: number;
80
- /** UUID of saved replay record (if session replay enabled) */
81
- replay_id?: string;
82
- /** Browserless replay URL (if session replay enabled) */
83
- replay_url?: string;
84
- /** Recording ID (if record_video=true) */
85
- recording_id?: string;
86
- /** Recording status: PENDING, PROCESSING, COMPLETED, ERROR */
87
- recording_status?: string;
88
- /** Task ID for async task tracking */
89
- task_id?: string;
90
- /** Task status: pending, running, completed, failed */
91
- status?: string;
92
- /** Structured output (JSON string) */
93
- output?: string;
94
- /** Live session debug URL for real-time viewing (WebRTC streaming) */
95
- debugUrl?: string;
96
- }
97
- /**
98
- * Configuration for live session viewing
99
- */
100
- interface LiveSessionOptions {
101
- /** Enable or disable remote control (default: true for headful, varies for headless) */
102
- interactive?: boolean;
103
- /** UI theme: 'dark' or 'light' (headless only, default: 'dark') */
104
- theme?: 'dark' | 'light';
105
- /** Show or hide navigation controls (headless only, default: true) */
106
- showControls?: boolean;
107
- /** Focus view on specific page/tab ID (headless only) */
108
- pageId?: string;
109
- /** Display specific tab by index (headless only) */
110
- pageIndex?: string;
111
- }
112
- /**
113
- * Configuration for iframe generation
114
- */
115
- interface IframeOptions extends LiveSessionOptions {
116
- /** Iframe width (default: '100%') */
117
- width?: string | number;
118
- /** Iframe height (default: '600px') */
119
- height?: string | number;
120
- /** Additional inline styles */
121
- style?: string;
122
- /** CSS class name */
123
- className?: string;
124
- }
125
- /**
126
- * Task result with convenience methods for async execution
127
- */
128
- interface BrowserTaskWithPromise extends BrowserTaskResult {
129
- task_id: string;
130
- /** Live URL to watch task execution in real-time */
131
- liveUrl: string;
132
- /** Wait for task completion */
133
- complete: (pollConfig?: {
134
- interval?: number;
135
- timeout?: number;
136
- }) => Promise<BrowserTaskResult>;
137
- /** Get live session URL with optional parameters (Steel.dev) - throws if debugUrl not available */
138
- getLiveUrl: (options?: LiveSessionOptions) => string;
139
- /** Get iframe HTML for embedding live session - throws if debugUrl not available */
140
- getLiveIframe: (optionsOrPreset?: string | IframeOptions) => string;
141
- /** Get complete embed code snippet - throws if debugUrl not available */
142
- getEmbedCode: () => string;
143
- }
144
- /**
145
- * Task result with schema validation
146
- */
147
- interface BrowserTaskWithPromiseAndSchema<T> extends BrowserTaskResult {
148
- task_id: string;
149
- /** Live URL to watch task execution in real-time */
150
- liveUrl: string;
151
- /** Parsed and validated output */
152
- parsed: T | null;
153
- /** Wait for task completion with schema validation */
154
- complete: (pollConfig?: {
155
- interval?: number;
156
- timeout?: number;
157
- }) => Promise<BrowserTaskResult & {
158
- parsed: T | null;
159
- }>;
160
- /** Get live session URL with optional parameters - throws if debugUrl not available */
161
- getLiveUrl: (options?: LiveSessionOptions) => string;
162
- /** Get iframe HTML for embedding live session - throws if debugUrl not available */
163
- getLiveIframe: (optionsOrPreset?: string | IframeOptions) => string;
164
- /** Get complete embed code snippet - throws if debugUrl not available */
165
- getEmbedCode: () => string;
166
- }
167
- /**
168
- * Recording status and metadata
169
- */
170
- interface RecordingStatus {
171
- /** Recording ID */
172
- id: string;
173
- /** Current status */
174
- status: 'PENDING' | 'PROCESSING' | 'COMPLETED' | 'ERROR';
175
- /** Presigned S3 URL for rrweb replay JSON (interactive DOM replay) */
176
- replay_url?: string;
177
- /** Presigned S3 URL for network logs (NDJSON format) */
178
- network_url?: string;
179
- /** Presigned S3 URL for console logs (NDJSON format) */
180
- console_url?: string;
181
- /** Presigned S3 URL for native browser video (WebM or MP4 format, real-time recording) */
182
- video_url?: string;
183
- /** Total rrweb events captured */
184
- total_events?: number;
185
- /** Total bytes of all files */
186
- file_size?: number;
187
- /** Duration in milliseconds */
188
- duration?: number;
189
- /** Error message if status=ERROR */
190
- error?: string;
191
- /** When recording was created */
192
- created_at: string;
193
- }
194
- /**
195
- * Browser error with screenshot captured at error time
196
- */
197
- interface BrowserError {
198
- /** Error type: console error or network error */
199
- type: 'console' | 'network';
200
- /** Error message */
201
- message: string;
202
- /** URL where error occurred */
203
- url?: string;
204
- /** CDP timestamp in seconds since browser start */
205
- timestamp: number;
206
- /** Presigned S3 URL to screenshot JPEG (captured 500ms after error) */
207
- screenshot_url?: string;
208
- /** When screenshot was captured (Unix timestamp) */
209
- captured_at?: number;
210
- /** HTTP status code (for network errors) */
211
- status?: number;
212
- }
213
- /**
214
- * Response from getErrors()
215
- */
216
- interface ErrorsResponse {
217
- /** Recording ID */
218
- recording_id: string;
219
- /** Total number of errors */
220
- total_errors: number;
221
- /** Errors with real-time screenshots */
222
- errors: BrowserError[];
223
- }
224
-
225
- export type { BrowserConfig, BrowserError, BrowserModel, BrowserTaskInput, BrowserTaskInputWithSchema, BrowserTaskResult, BrowserTaskWithPromise, BrowserTaskWithPromiseAndSchema, ErrorsResponse, IframeOptions, LiveSessionOptions, RecordingStatus };
@@ -1,128 +0,0 @@
1
- import * as ai from 'ai';
2
- import { z } from 'zod';
3
- import { BrowserConfig } from './types.js';
4
- import '../utils/resilience.js';
5
-
6
- /**
7
- * Create Vercel AI SDK tool for browser automation
8
- *
9
- * @param config - Optional browser worker configuration
10
- * @returns Vercel AI SDK tool
11
- *
12
- * @example
13
- * ```typescript
14
- * import { generateText } from 'ai';
15
- * import { anthropic } from '@ai-sdk/anthropic';
16
- * import { createBrowserTool } from 'morphsdk/tools/browser/vercel';
17
- *
18
- * const browserTool = createBrowserTool({
19
- * apiUrl: 'https://browser-worker.example.com'
20
- * });
21
- *
22
- * const result = await generateText({
23
- * model: anthropic('claude-sonnet-4-5-20250929'),
24
- * tools: { browserTask: browserTool },
25
- * prompt: 'Test the checkout flow at https://3000-abc.e2b.dev',
26
- * maxSteps: 5
27
- * });
28
- * ```
29
- */
30
- declare function createBrowserTool(config?: BrowserConfig): ai.Tool<z.ZodObject<{
31
- task: z.ZodString;
32
- url: z.ZodOptional<z.ZodString>;
33
- max_steps: z.ZodDefault<z.ZodNumber>;
34
- region: z.ZodDefault<z.ZodEnum<["sfo", "lon"]>>;
35
- }, "strip", z.ZodTypeAny, {
36
- task: string;
37
- max_steps: number;
38
- region: "sfo" | "lon";
39
- url?: string | undefined;
40
- }, {
41
- task: string;
42
- url?: string | undefined;
43
- max_steps?: number | undefined;
44
- region?: "sfo" | "lon" | undefined;
45
- }>, {
46
- success: boolean;
47
- result: string | undefined;
48
- steps_taken: number | undefined;
49
- execution_time_ms: number | undefined;
50
- error?: undefined;
51
- } | {
52
- success: boolean;
53
- error: string | undefined;
54
- result?: undefined;
55
- steps_taken?: undefined;
56
- execution_time_ms?: undefined;
57
- }> & {
58
- execute: (args: {
59
- task: string;
60
- max_steps: number;
61
- region: "sfo" | "lon";
62
- url?: string | undefined;
63
- }, options: ai.ToolExecutionOptions) => PromiseLike<{
64
- success: boolean;
65
- result: string | undefined;
66
- steps_taken: number | undefined;
67
- execution_time_ms: number | undefined;
68
- error?: undefined;
69
- } | {
70
- success: boolean;
71
- error: string | undefined;
72
- result?: undefined;
73
- steps_taken?: undefined;
74
- execution_time_ms?: undefined;
75
- }>;
76
- };
77
- /**
78
- * Default browser tool for Vercel AI SDK
79
- */
80
- declare const browserTool: ai.Tool<z.ZodObject<{
81
- task: z.ZodString;
82
- url: z.ZodOptional<z.ZodString>;
83
- max_steps: z.ZodDefault<z.ZodNumber>;
84
- region: z.ZodDefault<z.ZodEnum<["sfo", "lon"]>>;
85
- }, "strip", z.ZodTypeAny, {
86
- task: string;
87
- max_steps: number;
88
- region: "sfo" | "lon";
89
- url?: string | undefined;
90
- }, {
91
- task: string;
92
- url?: string | undefined;
93
- max_steps?: number | undefined;
94
- region?: "sfo" | "lon" | undefined;
95
- }>, {
96
- success: boolean;
97
- result: string | undefined;
98
- steps_taken: number | undefined;
99
- execution_time_ms: number | undefined;
100
- error?: undefined;
101
- } | {
102
- success: boolean;
103
- error: string | undefined;
104
- result?: undefined;
105
- steps_taken?: undefined;
106
- execution_time_ms?: undefined;
107
- }> & {
108
- execute: (args: {
109
- task: string;
110
- max_steps: number;
111
- region: "sfo" | "lon";
112
- url?: string | undefined;
113
- }, options: ai.ToolExecutionOptions) => PromiseLike<{
114
- success: boolean;
115
- result: string | undefined;
116
- steps_taken: number | undefined;
117
- execution_time_ms: number | undefined;
118
- error?: undefined;
119
- } | {
120
- success: boolean;
121
- error: string | undefined;
122
- result?: undefined;
123
- steps_taken?: undefined;
124
- execution_time_ms?: undefined;
125
- }>;
126
- };
127
-
128
- export { browserTool, createBrowserTool };
@@ -1,40 +0,0 @@
1
- import { Tool } from '@anthropic-ai/sdk/resources/messages';
2
- import { CodebaseSearchConfig, CodebaseSearchInput, CodebaseSearchResult } from './types.js';
3
- import '../utils/resilience.js';
4
-
5
- /**
6
- * Anthropic SDK adapter for codebase_search tool
7
- */
8
-
9
- /**
10
- * Create Anthropic-native codebase_search tool with execute and formatResult methods
11
- *
12
- * @param config - Configuration with repoId
13
- * @returns Anthropic Tool definition with execute and formatResult methods
14
- *
15
- * @example
16
- * ```ts
17
- * import Anthropic from '@anthropic-ai/sdk';
18
- * import { createCodebaseSearchTool } from 'morphsdk/tools/anthropic';
19
- *
20
- * const client = new Anthropic({ apiKey: process.env.ANTHROPIC_API_KEY });
21
- * const tool = createCodebaseSearchTool({ repoId: 'my-project' });
22
- *
23
- * const response = await client.messages.create({
24
- * model: "claude-sonnet-4-5-20250929",
25
- * tools: [tool], // tool itself is the Tool definition
26
- * messages: [{ role: "user", content: "Find authentication code" }]
27
- * });
28
- *
29
- * // Execute tool and format result
30
- * const result = await tool.execute(toolUseBlock.input);
31
- * const formatted = tool.formatResult(result);
32
- * ```
33
- */
34
- declare function createCodebaseSearchTool(config: CodebaseSearchConfig): Tool & {
35
- execute: (input: CodebaseSearchInput) => Promise<CodebaseSearchResult>;
36
- formatResult: (result: CodebaseSearchResult) => string;
37
- getSystemPrompt: () => string;
38
- };
39
-
40
- export { createCodebaseSearchTool };
@@ -1,40 +0,0 @@
1
- import { CodebaseSearchResult, CodebaseSearchInput, CodebaseSearchConfig } from './types.js';
2
- import '../utils/resilience.js';
3
-
4
- /**
5
- * Core implementation for codebase search
6
- * Calls Morph rerank service for two-stage semantic search
7
- */
8
-
9
- /**
10
- * CodebaseSearch client for programmatic semantic search
11
- */
12
- declare class CodebaseSearchClient {
13
- private config;
14
- constructor(config?: {
15
- apiKey?: string;
16
- debug?: boolean;
17
- timeout?: number;
18
- retryConfig?: any;
19
- });
20
- /**
21
- * Execute a semantic code search
22
- *
23
- * @param input - Search parameters including query, repoId, and target directories
24
- * @param overrides - Optional config overrides for this operation
25
- * @returns Search results with ranked code matches
26
- */
27
- search(input: {
28
- query: string;
29
- repoId: string;
30
- target_directories?: string[];
31
- explanation?: string;
32
- limit?: number;
33
- }, overrides?: any): Promise<CodebaseSearchResult>;
34
- }
35
- /**
36
- * Execute semantic code search
37
- */
38
- declare function executeCodebaseSearch(input: CodebaseSearchInput, config: CodebaseSearchConfig): Promise<CodebaseSearchResult>;
39
-
40
- export { CodebaseSearchClient, executeCodebaseSearch };
@@ -1,11 +0,0 @@
1
- export { executeCodebaseSearch } from './core.js';
2
- export { CODEBASE_SEARCH_DESCRIPTION, CODEBASE_SEARCH_SYSTEM_PROMPT } from './prompts.js';
3
- export { CodeSearchResult, CodebaseSearchConfig, CodebaseSearchInput, CodebaseSearchResult, SearchStats } from './types.js';
4
- export { createCodebaseSearchTool as anthropicCodebaseSearchTool } from './anthropic.js';
5
- export { createCodebaseSearchTool as openaiCodebaseSearchTool } from './openai.js';
6
- export { createCodebaseSearchTool as vercelCodebaseSearchTool } from './vercel.js';
7
- import '../utils/resilience.js';
8
- import '@anthropic-ai/sdk/resources/messages';
9
- import 'openai/resources/chat/completions';
10
- import 'ai';
11
- import 'zod';
@@ -1,87 +0,0 @@
1
- import { ChatCompletionTool } from 'openai/resources/chat/completions';
2
- import { CodebaseSearchConfig, CodebaseSearchInput, CodebaseSearchResult } from './types.js';
3
- import '../utils/resilience.js';
4
-
5
- /**
6
- * OpenAI SDK adapter for codebase_search tool
7
- */
8
-
9
- /**
10
- * Direct codebase_search tool definition
11
- * Use this when you want to pass config at execute time
12
- */
13
- declare const codebaseSearchTool: ChatCompletionTool;
14
- /**
15
- * Create OpenAI-native codebase_search tool with execute and formatResult methods
16
- *
17
- * @param config - Configuration with repoId
18
- * @returns OpenAI ChatCompletionTool definition with methods
19
- *
20
- * @example
21
- * ```ts
22
- * import OpenAI from 'openai';
23
- * import { createCodebaseSearchTool } from 'morphsdk/tools/openai';
24
- *
25
- * const client = new OpenAI({ apiKey: process.env.OPENAI_API_KEY });
26
- * const tool = createCodebaseSearchTool({ repoId: 'my-project' });
27
- *
28
- * const response = await client.chat.completions.create({
29
- * model: "gpt-4o",
30
- * tools: [tool], // tool itself is the ChatCompletionTool
31
- * messages: [{ role: "user", content: "Find authentication code" }]
32
- * });
33
- *
34
- * // Execute and format
35
- * const result = await tool.execute(toolCallArgs);
36
- * const formatted = tool.formatResult(result);
37
- * ```
38
- */
39
- declare function createCodebaseSearchTool(config: CodebaseSearchConfig): ChatCompletionTool & {
40
- execute: (input: CodebaseSearchInput | string) => Promise<CodebaseSearchResult>;
41
- formatResult: (result: CodebaseSearchResult) => string;
42
- getSystemPrompt: () => string;
43
- };
44
- /**
45
- * Execute codebase_search tool call
46
- *
47
- * @param input - Tool input from GPT (parsed from tool_calls)
48
- * @param config - Configuration with repoId (REQUIRED)
49
- * @returns Search results
50
- *
51
- * @example
52
- * ```ts
53
- * // Handle tool calls from GPT:
54
- * if (response.choices[0].message.tool_calls) {
55
- * for (const toolCall of response.choices[0].message.tool_calls) {
56
- * const args = JSON.parse(toolCall.function.arguments);
57
- * const result = await execute(args, { repoId: 'my-project' });
58
- * console.log(`Found ${result.results.length} matches`);
59
- * }
60
- * }
61
- * ```
62
- */
63
- declare function execute(input: CodebaseSearchInput, config: CodebaseSearchConfig): Promise<CodebaseSearchResult>;
64
- /**
65
- * Format search results for GPT
66
- *
67
- * @param result - Search result from endpoint
68
- * @returns Formatted string for tool message
69
- */
70
- declare function formatResult(result: CodebaseSearchResult): string;
71
- /**
72
- * Get the system prompt for codebase_search usage
73
- *
74
- * @returns System prompt to guide GPT
75
- */
76
- declare function getSystemPrompt(): string;
77
- /**
78
- * Default export for convenience
79
- */
80
- declare const _default: {
81
- createCodebaseSearchTool: typeof createCodebaseSearchTool;
82
- execute: typeof execute;
83
- formatResult: typeof formatResult;
84
- getSystemPrompt: typeof getSystemPrompt;
85
- };
86
-
87
- export { codebaseSearchTool, createCodebaseSearchTool, _default as default, execute, formatResult, getSystemPrompt };
@@ -1,7 +0,0 @@
1
- /**
2
- * Tool descriptions and system prompts for codebase search
3
- */
4
- declare const CODEBASE_SEARCH_DESCRIPTION = "Semantic search that finds code by meaning, not exact text.\n\nUse this to explore unfamiliar codebases or ask \"how/where/what\" questions:\n- \"How does X work?\" - Find implementation details\n- \"Where is Y handled?\" - Locate specific functionality\n- \"What happens when Z?\" - Understand flow\n\nThe tool uses two-stage retrieval (embedding similarity + reranking) to find the most semantically relevant code chunks.\n\nReturns code chunks with file paths, line ranges, and full content ranked by relevance.";
5
- declare const CODEBASE_SEARCH_SYSTEM_PROMPT = "You have access to the codebase_search tool that performs semantic code search.\n\nWhen searching:\n- Use natural language queries describing what you're looking for\n- Be specific about functionality, not variable names\n- Use target_directories to narrow search if you know the area\n- Results are ranked by relevance (rerank score is most important)\n\nThe tool returns:\n- File paths with symbol names (e.g. \"src/auth.ts::AuthService@L1-L17\")\n- Line ranges for precise navigation\n- Full code content for each match\n- Dual relevance scores: embedding similarity + rerank score\n\nUse results to understand code or answer questions. The content is provided in full - avoid re-reading unless you need more context.";
6
-
7
- export { CODEBASE_SEARCH_DESCRIPTION, CODEBASE_SEARCH_SYSTEM_PROMPT };
@@ -1,46 +0,0 @@
1
- import { RetryConfig } from '../utils/resilience.js';
2
-
3
- /**
4
- * Type definitions for codebase search tool
5
- */
6
-
7
- interface CodebaseSearchConfig {
8
- repoId: string;
9
- searchUrl?: string;
10
- apiKey?: string;
11
- /** Timeout for search requests in ms (default: 30000) */
12
- timeout?: number;
13
- /** Retry configuration for API calls */
14
- retryConfig?: RetryConfig;
15
- /** Enable debug logging (default: false) */
16
- debug?: boolean;
17
- }
18
- interface CodebaseSearchInput {
19
- query: string;
20
- target_directories?: string[];
21
- explanation?: string;
22
- limit?: number;
23
- }
24
- interface CodeSearchResult {
25
- filepath: string;
26
- symbolPath: string;
27
- content: string;
28
- language: string;
29
- startLine: number;
30
- endLine: number;
31
- embeddingSimilarity: number;
32
- rerankScore: number;
33
- }
34
- interface SearchStats {
35
- totalResults: number;
36
- candidatesRetrieved: number;
37
- searchTimeMs: number;
38
- }
39
- interface CodebaseSearchResult {
40
- success: boolean;
41
- results: CodeSearchResult[];
42
- stats: SearchStats;
43
- error?: string;
44
- }
45
-
46
- export type { CodeSearchResult, CodebaseSearchConfig, CodebaseSearchInput, CodebaseSearchResult, SearchStats };
@@ -1,100 +0,0 @@
1
- import * as ai from 'ai';
2
- import { z } from 'zod';
3
- import { CodebaseSearchConfig } from './types.js';
4
- import '../utils/resilience.js';
5
-
6
- /**
7
- * Create Vercel AI SDK codebase_search tool
8
- *
9
- * @param config - Configuration with repoId
10
- * @returns Vercel AI SDK tool definition (execution built-in)
11
- *
12
- * @example
13
- * ```ts
14
- * import { generateText } from 'ai';
15
- * import { anthropic } from '@ai-sdk/anthropic';
16
- * import { createCodebaseSearchTool } from 'morphsdk/tools/codebase-search/vercel';
17
- *
18
- * const tool = createCodebaseSearchTool({ repoId: 'my-project' });
19
- *
20
- * const result = await generateText({
21
- * model: anthropic('claude-3-5-sonnet-20241022'),
22
- * tools: { codebaseSearch: tool },
23
- * prompt: "Find authentication code",
24
- * maxSteps: 5
25
- * });
26
- *
27
- * // Vercel AI SDK automatically executes and handles results
28
- * console.log(result.text);
29
- * ```
30
- */
31
- declare function createCodebaseSearchTool(config: CodebaseSearchConfig): ai.Tool<z.ZodObject<{
32
- query: z.ZodString;
33
- target_directories: z.ZodArray<z.ZodString, "many">;
34
- explanation: z.ZodString;
35
- limit: z.ZodOptional<z.ZodNumber>;
36
- }, "strip", z.ZodTypeAny, {
37
- query: string;
38
- target_directories: string[];
39
- explanation: string;
40
- limit?: number | undefined;
41
- }, {
42
- query: string;
43
- target_directories: string[];
44
- explanation: string;
45
- limit?: number | undefined;
46
- }>, {
47
- error: string | undefined;
48
- results: never[];
49
- found?: undefined;
50
- searchTime?: undefined;
51
- } | {
52
- found: number;
53
- searchTime: string;
54
- results: {
55
- file: string;
56
- symbol: string;
57
- lines: string;
58
- language: string;
59
- relevance: string;
60
- code: string;
61
- }[];
62
- error?: undefined;
63
- }> & {
64
- execute: (args: {
65
- query: string;
66
- target_directories: string[];
67
- explanation: string;
68
- limit?: number | undefined;
69
- }, options: ai.ToolExecutionOptions) => PromiseLike<{
70
- error: string | undefined;
71
- results: never[];
72
- found?: undefined;
73
- searchTime?: undefined;
74
- } | {
75
- found: number;
76
- searchTime: string;
77
- results: {
78
- file: string;
79
- symbol: string;
80
- lines: string;
81
- language: string;
82
- relevance: string;
83
- code: string;
84
- }[];
85
- error?: undefined;
86
- }>;
87
- };
88
- /**
89
- * Get system prompt for Vercel AI SDK
90
- */
91
- declare function getSystemPrompt(): string;
92
- /**
93
- * Default export
94
- */
95
- declare const _default: {
96
- createCodebaseSearchTool: typeof createCodebaseSearchTool;
97
- getSystemPrompt: typeof getSystemPrompt;
98
- };
99
-
100
- export { createCodebaseSearchTool, _default as default, getSystemPrompt };