@morphllm/morphsdk 0.2.18 → 0.2.19

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 (53) hide show
  1. package/dist/anthropic-CknfcMoO.d.ts +64 -0
  2. package/dist/{chunk-UFIIEUGW.js → chunk-OSJBHKA2.js} +9 -9
  3. package/dist/{chunk-VONZKK4S.js → chunk-YVGRWE7D.js} +1 -1
  4. package/dist/chunk-YVGRWE7D.js.map +1 -0
  5. package/dist/client.d.ts +114 -0
  6. package/dist/client.js +4 -4
  7. package/dist/git/client.d.ts +230 -0
  8. package/dist/git/config.d.ts +11 -0
  9. package/dist/git/index.d.ts +5 -0
  10. package/dist/git/types.d.ts +91 -0
  11. package/dist/index.d.ts +14 -0
  12. package/dist/index.js +10 -10
  13. package/dist/modelrouter/core.d.ts +56 -0
  14. package/dist/modelrouter/index.d.ts +2 -0
  15. package/dist/modelrouter/types.d.ts +35 -0
  16. package/dist/openai-BkKsS30n.d.ts +111 -0
  17. package/dist/tools/browser/anthropic.d.ts +51 -0
  18. package/dist/tools/browser/core.d.ts +196 -0
  19. package/dist/tools/browser/index.d.ts +72 -0
  20. package/dist/tools/browser/openai.d.ts +69 -0
  21. package/dist/tools/browser/prompts.d.ts +7 -0
  22. package/dist/tools/browser/types.d.ts +227 -0
  23. package/dist/tools/browser/vercel.cjs +1 -1
  24. package/dist/tools/browser/vercel.cjs.map +1 -1
  25. package/dist/tools/browser/vercel.d.ts +69 -0
  26. package/dist/tools/browser/vercel.js +1 -1
  27. package/dist/tools/browser/vercel.js.map +1 -1
  28. package/dist/tools/codebase_search/anthropic.d.ts +40 -0
  29. package/dist/tools/codebase_search/core.d.ts +40 -0
  30. package/dist/tools/codebase_search/index.cjs.map +1 -1
  31. package/dist/tools/codebase_search/index.d.ts +10 -0
  32. package/dist/tools/codebase_search/index.js +4 -4
  33. package/dist/tools/codebase_search/openai.d.ts +87 -0
  34. package/dist/tools/codebase_search/prompts.d.ts +7 -0
  35. package/dist/tools/codebase_search/types.d.ts +46 -0
  36. package/dist/tools/codebase_search/vercel.cjs.map +1 -1
  37. package/dist/tools/codebase_search/vercel.d.ts +65 -0
  38. package/dist/tools/codebase_search/vercel.js +1 -1
  39. package/dist/tools/fastapply/anthropic.d.ts +4 -0
  40. package/dist/tools/fastapply/core.d.ts +41 -0
  41. package/dist/tools/fastapply/index.d.ts +10 -0
  42. package/dist/tools/fastapply/index.js +3 -3
  43. package/dist/tools/fastapply/openai.d.ts +4 -0
  44. package/dist/tools/fastapply/prompts.d.ts +7 -0
  45. package/dist/tools/fastapply/types.d.ts +77 -0
  46. package/dist/tools/fastapply/vercel.d.ts +4 -0
  47. package/dist/tools/index.d.ts +10 -0
  48. package/dist/tools/index.js +3 -3
  49. package/dist/tools/utils/resilience.d.ts +58 -0
  50. package/dist/vercel-B1GZ_g9N.d.ts +69 -0
  51. package/package.json +1 -1
  52. package/dist/chunk-VONZKK4S.js.map +0 -1
  53. /package/dist/{chunk-UFIIEUGW.js.map → chunk-OSJBHKA2.js.map} +0 -0
@@ -0,0 +1,77 @@
1
+ import { RetryConfig } from '../utils/resilience.js';
2
+
3
+ /**
4
+ * Core types for Morph Fast Apply SDK
5
+ */
6
+
7
+ /**
8
+ * Input parameters for the edit_file tool
9
+ */
10
+ interface EditFileInput {
11
+ /** Path to the file to edit (relative to baseDir) */
12
+ target_filepath: string;
13
+ /** First-person description of what you're changing */
14
+ instructions: string;
15
+ /** Lazy edit with // ... existing code ... markers */
16
+ code_edit: string;
17
+ }
18
+ /**
19
+ * Statistics about the changes made
20
+ */
21
+ interface EditChanges {
22
+ linesAdded: number;
23
+ linesRemoved: number;
24
+ linesModified: number;
25
+ }
26
+ /**
27
+ * Result returned after executing an edit
28
+ */
29
+ interface EditFileResult {
30
+ /** Whether the edit was successful */
31
+ success: boolean;
32
+ /** Path to the edited file */
33
+ filepath: string;
34
+ /** Universal diff format showing changes */
35
+ udiff?: string;
36
+ /** Statistics about the changes */
37
+ changes: EditChanges;
38
+ /** Error message if unsuccessful */
39
+ error?: string;
40
+ }
41
+ /**
42
+ * Configuration options for the edit_file tool
43
+ */
44
+ interface EditFileConfig {
45
+ /** Morph API key (defaults to MORPH_API_KEY env var) */
46
+ morphApiKey?: string;
47
+ /** Morph API base URL */
48
+ morphApiUrl?: string;
49
+ /** Base directory for file operations (defaults to cwd) */
50
+ baseDir?: string;
51
+ /** Whether to generate udiff (default: true) */
52
+ generateUdiff?: boolean;
53
+ /** Whether to automatically write to file (default: true) */
54
+ autoWrite?: boolean;
55
+ /** Custom system prompt (null to disable) */
56
+ systemPrompt?: string | null;
57
+ /** Custom tool description (defaults to EDIT_FILE_TOOL_DESCRIPTION) */
58
+ description?: string;
59
+ /** Timeout for API calls in ms (default: 30000) */
60
+ timeout?: number;
61
+ /** Retry configuration for API calls */
62
+ retryConfig?: RetryConfig;
63
+ /** Enable debug logging (default: false) */
64
+ debug?: boolean;
65
+ }
66
+ /**
67
+ * Response from Morph Apply API
68
+ */
69
+ interface MorphApplyResponse {
70
+ choices: Array<{
71
+ message: {
72
+ content: string;
73
+ };
74
+ }>;
75
+ }
76
+
77
+ export type { EditChanges, EditFileConfig, EditFileInput, EditFileResult, MorphApplyResponse };
@@ -0,0 +1,4 @@
1
+ import 'ai';
2
+ import './types.js';
3
+ export { c as createEditFileTool, e as default, e as editFileTool, g as getSystemPrompt } from '../../vercel-B1GZ_g9N.js';
4
+ import '../utils/resilience.js';
@@ -0,0 +1,10 @@
1
+ export { countChanges, executeEditFile, generateUdiff } from './fastapply/core.js';
2
+ export { EditChanges, EditFileConfig, EditFileInput, EditFileResult } from './fastapply/types.js';
3
+ export { EDIT_FILE_SYSTEM_PROMPT, EDIT_FILE_TOOL_DESCRIPTION } from './fastapply/prompts.js';
4
+ export { a as anthropic } from '../anthropic-CknfcMoO.js';
5
+ export { o as openai } from '../openai-BkKsS30n.js';
6
+ export { v as vercel } from '../vercel-B1GZ_g9N.js';
7
+ import './utils/resilience.js';
8
+ import '@anthropic-ai/sdk/resources/messages';
9
+ import 'openai/resources/chat/completions';
10
+ import 'ai';
@@ -1,13 +1,13 @@
1
1
  import "../chunk-X2K57BH6.js";
2
+ import {
3
+ anthropic_exports
4
+ } from "../chunk-S3HTYGYF.js";
2
5
  import {
3
6
  openai_exports
4
7
  } from "../chunk-OZMHDB6O.js";
5
8
  import {
6
9
  vercel_exports
7
10
  } from "../chunk-Y5RCNDLV.js";
8
- import {
9
- anthropic_exports
10
- } from "../chunk-S3HTYGYF.js";
11
11
  import {
12
12
  EDIT_FILE_SYSTEM_PROMPT,
13
13
  EDIT_FILE_TOOL_DESCRIPTION
@@ -0,0 +1,58 @@
1
+ /**
2
+ * Resilience utilities for retry logic and timeout handling
3
+ */
4
+ interface RetryConfig {
5
+ maxRetries?: number;
6
+ initialDelay?: number;
7
+ maxDelay?: number;
8
+ backoffMultiplier?: number;
9
+ retryableErrors?: string[];
10
+ onRetry?: (attempt: number, error: Error) => void;
11
+ }
12
+ /**
13
+ * Retry a fetch request with exponential backoff
14
+ *
15
+ * @param url - Request URL
16
+ * @param options - Fetch options
17
+ * @param retryConfig - Retry configuration
18
+ * @returns Response from fetch
19
+ *
20
+ * @example
21
+ * ```typescript
22
+ * const response = await fetchWithRetry(
23
+ * 'https://api.example.com/data',
24
+ * { method: 'POST', body: JSON.stringify(data) },
25
+ * { maxRetries: 5, initialDelay: 500 }
26
+ * );
27
+ * ```
28
+ */
29
+ declare function fetchWithRetry(url: string, options: RequestInit, retryConfig?: RetryConfig): Promise<Response>;
30
+ /**
31
+ * Add timeout to any promise
32
+ *
33
+ * @param promise - Promise to wrap with timeout
34
+ * @param timeoutMs - Timeout in milliseconds
35
+ * @param errorMessage - Optional custom error message
36
+ * @returns Promise that rejects if timeout is reached
37
+ *
38
+ * @example
39
+ * ```typescript
40
+ * const result = await withTimeout(
41
+ * fetchData(),
42
+ * 5000,
43
+ * 'Data fetch timed out'
44
+ * );
45
+ * ```
46
+ */
47
+ declare function withTimeout<T>(promise: Promise<T>, timeoutMs: number, errorMessage?: string): Promise<T>;
48
+ /**
49
+ * Unified error type for all tools
50
+ */
51
+ declare class MorphError extends Error {
52
+ code: string;
53
+ statusCode?: number | undefined;
54
+ retryable: boolean;
55
+ constructor(message: string, code: string, statusCode?: number | undefined, retryable?: boolean);
56
+ }
57
+
58
+ export { MorphError, type RetryConfig, fetchWithRetry, withTimeout };
@@ -0,0 +1,69 @@
1
+ import * as ai from 'ai';
2
+ import { EditChanges, EditFileConfig } from './tools/fastapply/types.js';
3
+
4
+ declare const editFileTool: ai.Tool<{
5
+ target_filepath: string;
6
+ instructions: string;
7
+ code_edit: string;
8
+ }, {
9
+ success: boolean;
10
+ filepath: string;
11
+ changes: EditChanges;
12
+ udiff: string | undefined;
13
+ }>;
14
+ /**
15
+ * Get the system prompt for edit_file usage
16
+ *
17
+ * Add this to your system message to guide the model on using edit_file properly.
18
+ *
19
+ * @example
20
+ * ```ts
21
+ * const result = await generateText({
22
+ * model: anthropic('claude-sonnet-4-5-20250929'),
23
+ * system: getSystemPrompt(),
24
+ * tools: { editFile: editFileTool },
25
+ * prompt: "Fix bugs"
26
+ * });
27
+ * ```
28
+ */
29
+ declare function getSystemPrompt(): string;
30
+ /**
31
+ * Create a custom edit_file tool with configuration
32
+ *
33
+ * @param config - Configuration options
34
+ * @returns Vercel AI SDK tool with custom config
35
+ *
36
+ * @example
37
+ * ```ts
38
+ * const customEditTool = createEditFileTool({
39
+ * baseDir: './src',
40
+ * generateUdiff: true,
41
+ * description: 'Custom tool description for your use case'
42
+ * });
43
+ *
44
+ * const result = await generateText({
45
+ * model: anthropic('claude-sonnet-4-5-20250929'),
46
+ * tools: { editFile: customEditTool },
47
+ * prompt: "Fix bugs"
48
+ * });
49
+ * ```
50
+ */
51
+ declare function createEditFileTool(config?: EditFileConfig): ai.Tool<{
52
+ target_filepath: string;
53
+ instructions: string;
54
+ code_edit: string;
55
+ }, {
56
+ success: boolean;
57
+ filepath: string;
58
+ changes: EditChanges;
59
+ udiff: string | undefined;
60
+ }>;
61
+
62
+ declare const vercel_createEditFileTool: typeof createEditFileTool;
63
+ declare const vercel_editFileTool: typeof editFileTool;
64
+ declare const vercel_getSystemPrompt: typeof getSystemPrompt;
65
+ declare namespace vercel {
66
+ export { vercel_createEditFileTool as createEditFileTool, editFileTool as default, vercel_editFileTool as editFileTool, vercel_getSystemPrompt as getSystemPrompt };
67
+ }
68
+
69
+ export { createEditFileTool as c, editFileTool as e, getSystemPrompt as g, vercel as v };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@morphllm/morphsdk",
3
- "version": "0.2.18",
3
+ "version": "0.2.19",
4
4
  "description": "TypeScript SDK and CLI for Morph Fast Apply integration",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../tools/codebase_search/vercel.ts"],"sourcesContent":["/**\n * Vercel AI SDK adapter for codebase_search tool\n */\n\nimport { tool } from 'ai';\nimport { z } from 'zod';\nimport { executeCodebaseSearch } from './core.js';\nimport { CODEBASE_SEARCH_DESCRIPTION } from './prompts.js';\nimport type { CodebaseSearchConfig } from './types.js';\n\n/**\n * Create Vercel AI SDK codebase_search tool\n * \n * @param config - Configuration with repoId\n * @returns Vercel AI SDK tool definition (execution built-in)\n * \n * @example\n * ```ts\n * import { generateText } from 'ai';\n * import { anthropic } from '@ai-sdk/anthropic';\n * import { createCodebaseSearchTool } from 'morphsdk/tools/codebase-search/vercel';\n * \n * const tool = createCodebaseSearchTool({ repoId: 'my-project' });\n * \n * const result = await generateText({\n * model: anthropic('claude-3-5-sonnet-20241022'),\n * tools: { codebaseSearch: tool },\n * prompt: \"Find authentication code\",\n * maxSteps: 5\n * });\n * \n * // Vercel AI SDK automatically executes and handles results\n * console.log(result.text);\n * ```\n */\nexport function createCodebaseSearchTool(config: CodebaseSearchConfig) {\n const schema = z.object({\n query: z.string().describe('A complete question about what you want to understand. Ask as if talking to a colleague: \"How does X work?\", \"What happens when Y?\", \"Where is Z handled?\"'),\n target_directories: z.array(z.string()).describe('Prefix directory paths to limit search scope (single directory only, no glob patterns). Use [] to search entire repo.'),\n explanation: z.string().describe('One sentence explanation as to why this tool is being used, and how it contributes to the goal.'),\n limit: z.number().optional().describe('Max results to return (default: 10)'),\n });\n\n // @ts-expect-error - Vercel AI SDK runtime supports inputSchema but types are incomplete\n return tool({\n description: CODEBASE_SEARCH_DESCRIPTION,\n inputSchema: schema,\n execute: async (params) => {\n const { query, target_directories, explanation, limit } = params;\n const result = await executeCodebaseSearch(\n { query, target_directories, explanation, limit },\n config\n );\n\n if (!result.success) {\n return {\n error: result.error,\n results: [],\n };\n }\n\n // Format results for Vercel AI SDK\n return {\n found: result.results.length,\n searchTime: `${result.stats.searchTimeMs}ms`,\n results: result.results.map(r => ({\n file: r.filepath,\n symbol: r.symbolPath,\n lines: `${r.startLine}-${r.endLine}`,\n language: r.language,\n relevance: `${(r.rerankScore * 100).toFixed(1)}%`,\n code: r.content,\n })),\n };\n },\n });\n}\n\n/**\n * Get system prompt for Vercel AI SDK\n */\nexport function getSystemPrompt(): string {\n return CODEBASE_SEARCH_DESCRIPTION;\n}\n\n/**\n * Default export\n */\nexport default { createCodebaseSearchTool, getSystemPrompt };\n\n"],"mappings":";;;;;;;;AAIA,SAAS,YAAY;AACrB,SAAS,SAAS;AA8BX,SAAS,yBAAyB,QAA8B;AACrE,QAAM,SAAS,EAAE,OAAO;AAAA,IACtB,OAAO,EAAE,OAAO,EAAE,SAAS,4JAA4J;AAAA,IACvL,oBAAoB,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,SAAS,uHAAuH;AAAA,IACxK,aAAa,EAAE,OAAO,EAAE,SAAS,iGAAiG;AAAA,IAClI,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,SAAS,qCAAqC;AAAA,EAC7E,CAAC;AAGD,SAAO,KAAK;AAAA,IACV,aAAa;AAAA,IACb,aAAa;AAAA,IACb,SAAS,OAAO,WAAW;AACzB,YAAM,EAAE,OAAO,oBAAoB,aAAa,MAAM,IAAI;AAC1D,YAAM,SAAS,MAAM;AAAA,QACnB,EAAE,OAAO,oBAAoB,aAAa,MAAM;AAAA,QAChD;AAAA,MACF;AAEA,UAAI,CAAC,OAAO,SAAS;AACnB,eAAO;AAAA,UACL,OAAO,OAAO;AAAA,UACd,SAAS,CAAC;AAAA,QACZ;AAAA,MACF;AAGA,aAAO;AAAA,QACL,OAAO,OAAO,QAAQ;AAAA,QACtB,YAAY,GAAG,OAAO,MAAM,YAAY;AAAA,QACxC,SAAS,OAAO,QAAQ,IAAI,QAAM;AAAA,UAChC,MAAM,EAAE;AAAA,UACR,QAAQ,EAAE;AAAA,UACV,OAAO,GAAG,EAAE,SAAS,IAAI,EAAE,OAAO;AAAA,UAClC,UAAU,EAAE;AAAA,UACZ,WAAW,IAAI,EAAE,cAAc,KAAK,QAAQ,CAAC,CAAC;AAAA,UAC9C,MAAM,EAAE;AAAA,QACV,EAAE;AAAA,MACJ;AAAA,IACF;AAAA,EACF,CAAC;AACH;AAKO,SAAS,kBAA0B;AACxC,SAAO;AACT;AAKA,IAAO,iBAAQ,EAAE,0BAA0B,gBAAgB;","names":[]}