@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,48 @@
1
+ import { WarpGrepProvider, GrepResult, ReadResult, AnalyseEntry } from './types.js';
2
+
3
+ type ExecResult = {
4
+ stdout: string;
5
+ stderr: string;
6
+ exitCode: number;
7
+ };
8
+ declare class CommandExecProvider implements WarpGrepProvider {
9
+ private readonly opts;
10
+ constructor(opts: {
11
+ run: (cmd: string, args: string[], options?: {
12
+ cwd?: string;
13
+ env?: Record<string, string>;
14
+ }) => Promise<ExecResult>;
15
+ pathMap?: (localPath: string) => string;
16
+ cwd?: string;
17
+ env?: Record<string, string>;
18
+ readCommand?: (remotePath: string, start?: number, end?: number) => {
19
+ cmd: string;
20
+ args: string[];
21
+ };
22
+ excludes?: string[];
23
+ });
24
+ private map;
25
+ grep(params: {
26
+ pattern: string;
27
+ path: string;
28
+ }): Promise<GrepResult>;
29
+ glob(params: {
30
+ pattern: string;
31
+ path: string;
32
+ }): Promise<{
33
+ files: string[];
34
+ }>;
35
+ read(params: {
36
+ path: string;
37
+ start?: number;
38
+ end?: number;
39
+ }): Promise<ReadResult>;
40
+ analyse(params: {
41
+ path: string;
42
+ pattern?: string | null;
43
+ maxResults?: number;
44
+ maxDepth?: number;
45
+ }): Promise<AnalyseEntry[]>;
46
+ }
47
+
48
+ export { CommandExecProvider };
@@ -0,0 +1,30 @@
1
+ import { WarpGrepProvider, GrepResult, ReadResult, AnalyseEntry } from './types.js';
2
+
3
+ declare class LocalRipgrepProvider implements WarpGrepProvider {
4
+ private readonly repoRoot;
5
+ private readonly excludes;
6
+ constructor(repoRoot: string, excludes?: string[]);
7
+ grep(params: {
8
+ pattern: string;
9
+ path: string;
10
+ }): Promise<GrepResult>;
11
+ glob(params: {
12
+ pattern: string;
13
+ path: string;
14
+ }): Promise<{
15
+ files: string[];
16
+ }>;
17
+ read(params: {
18
+ path: string;
19
+ start?: number;
20
+ end?: number;
21
+ }): Promise<ReadResult>;
22
+ analyse(params: {
23
+ path: string;
24
+ pattern?: string | null;
25
+ maxResults?: number;
26
+ maxDepth?: number;
27
+ }): Promise<AnalyseEntry[]>;
28
+ }
29
+
30
+ export { LocalRipgrepProvider };
@@ -0,0 +1,49 @@
1
+ type GrepResult = {
2
+ lines: string[];
3
+ };
4
+ type ReadResult = {
5
+ lines: string[];
6
+ };
7
+ type AnalyseEntry = {
8
+ name: string;
9
+ path: string;
10
+ type: 'file' | 'dir';
11
+ depth: number;
12
+ };
13
+ interface WarpGrepProvider {
14
+ /**
15
+ * Run regex grep
16
+ */
17
+ grep(params: {
18
+ pattern: string;
19
+ path: string;
20
+ }): Promise<GrepResult>;
21
+ /**
22
+ * List files by glob pattern (optional; may fallback internally)
23
+ */
24
+ glob?(params: {
25
+ pattern: string;
26
+ path: string;
27
+ }): Promise<{
28
+ files: string[];
29
+ }>;
30
+ /**
31
+ * Read lines from a file, optionally a range (1-based inclusive)
32
+ */
33
+ read(params: {
34
+ path: string;
35
+ start?: number;
36
+ end?: number;
37
+ }): Promise<ReadResult>;
38
+ /**
39
+ * Provide a lightweight directory overview for guidance
40
+ */
41
+ analyse(params: {
42
+ path: string;
43
+ pattern?: string | null;
44
+ maxResults?: number;
45
+ maxDepth?: number;
46
+ }): Promise<AnalyseEntry[]>;
47
+ }
48
+
49
+ export type { AnalyseEntry, GrepResult, ReadResult, WarpGrepProvider };
@@ -0,0 +1,10 @@
1
+ import { WarpGrepProvider } from '../providers/types.js';
2
+
3
+ declare function toolAnalyse(provider: WarpGrepProvider, args: {
4
+ path: string;
5
+ pattern?: string | null;
6
+ maxResults?: number;
7
+ maxDepth?: number;
8
+ }): Promise<string>;
9
+
10
+ export { toolAnalyse };
@@ -0,0 +1,10 @@
1
+ import { FinishFileSpec } from '../agent/types.js';
2
+
3
+ declare function normalizeFinishFiles(files: FinishFileSpec[]): FinishFileSpec[];
4
+ declare function readFinishFiles(repoRoot: string, files: FinishFileSpec[], reader: (path: string, start: number, end: number) => Promise<string[]>): Promise<{
5
+ path: string;
6
+ ranges: Array<[number, number]>;
7
+ content: string;
8
+ }[]>;
9
+
10
+ export { normalizeFinishFiles, readFinishFiles };
@@ -0,0 +1,8 @@
1
+ import { WarpGrepProvider } from '../providers/types.js';
2
+
3
+ declare function toolGrep(provider: WarpGrepProvider, args: {
4
+ pattern: string;
5
+ path: string;
6
+ }): Promise<string>;
7
+
8
+ export { toolGrep };
@@ -0,0 +1,9 @@
1
+ import { WarpGrepProvider } from '../providers/types.js';
2
+
3
+ declare function toolRead(provider: WarpGrepProvider, args: {
4
+ path: string;
5
+ start?: number;
6
+ end?: number;
7
+ }): Promise<string>;
8
+
9
+ export { toolRead };
@@ -0,0 +1,3 @@
1
+ declare function readAllLines(filePath: string): Promise<string[]>;
2
+
3
+ export { readAllLines };
@@ -0,0 +1,4 @@
1
+ declare function section(name: string, content: string): string;
2
+ declare function joinSections(sections: string[]): string;
3
+
4
+ export { joinSections, section };
@@ -0,0 +1,7 @@
1
+ declare function resolveUnderRepo(repoRoot: string, targetPath: string): string;
2
+ declare function ensureWithinRepo(repoRoot: string, absTarget: string): void;
3
+ declare function toRepoRelative(repoRoot: string, absPath: string): string;
4
+ declare function isSymlink(p: string): boolean;
5
+ declare function isTextualFile(filePath: string, maxBytes?: number): boolean;
6
+
7
+ export { ensureWithinRepo, isSymlink, isTextualFile, resolveUnderRepo, toRepoRelative };
@@ -0,0 +1,11 @@
1
+ type ExecResult = {
2
+ stdout: string;
3
+ stderr: string;
4
+ exitCode: number;
5
+ };
6
+ declare function runRipgrep(args: string[], opts?: {
7
+ cwd?: string;
8
+ env?: NodeJS.ProcessEnv;
9
+ }): Promise<ExecResult>;
10
+
11
+ export { type ExecResult, runRipgrep };
@@ -0,0 +1,33 @@
1
+ import * as ai from 'ai';
2
+ import { ChatMessage } from './agent/types.js';
3
+ import { WarpGrepProvider } from './providers/types.js';
4
+
5
+ type WarpGrepConfig = {
6
+ repoRoot: string;
7
+ provider?: WarpGrepProvider;
8
+ excludes?: string[];
9
+ includes?: string[];
10
+ debug?: boolean;
11
+ apiKey?: string;
12
+ description?: string;
13
+ };
14
+ declare function createMorphWarpGrepTool(config: WarpGrepConfig): ai.Tool<{
15
+ query: string;
16
+ }, {
17
+ success: boolean;
18
+ error: string;
19
+ messages: ChatMessage[];
20
+ contexts?: undefined;
21
+ summary?: undefined;
22
+ } | {
23
+ success: boolean;
24
+ contexts: {
25
+ file: any;
26
+ content: any;
27
+ }[];
28
+ summary: string;
29
+ error?: undefined;
30
+ messages?: undefined;
31
+ }>;
32
+
33
+ export { type WarpGrepConfig, createMorphWarpGrepTool };
@@ -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.28",
3
+ "version": "0.2.38",
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/fastapply/anthropic.ts"],"sourcesContent":["/**\n * Anthropic SDK adapter for edit_file tool\n */\n\nimport type { Tool } from '@anthropic-ai/sdk/resources/messages';\nimport { executeEditFile } from './core.js';\nimport { EDIT_FILE_TOOL_DESCRIPTION, EDIT_FILE_SYSTEM_PROMPT } from './prompts.js';\nimport type { EditFileInput, EditFileResult, EditFileConfig } from './types.js';\n\n/**\n * Anthropic-native tool definition for edit_file\n * \n * @example\n * ```ts\n * import Anthropic from '@anthropic-ai/sdk';\n * import { editFileTool } from 'morphsdk/tools/anthropic';\n * \n * const client = new Anthropic({ apiKey: process.env.ANTHROPIC_API_KEY });\n * \n * const response = await client.messages.create({\n * model: \"claude-sonnet-4-5-20250929\",\n * tools: [editFileTool],\n * messages: [{ role: \"user\", content: \"Fix the bug in app.ts\" }]\n * });\n * ```\n */\nexport const editFileTool: Tool = {\n name: 'edit_file',\n description: EDIT_FILE_TOOL_DESCRIPTION,\n input_schema: {\n type: 'object',\n properties: {\n target_filepath: {\n type: 'string',\n description: 'The path of the target file to modify',\n },\n instructions: {\n type: 'string',\n description: 'A single sentence describing what you are changing (first person)',\n },\n code_edit: {\n type: 'string',\n description: 'The lazy edit with // ... existing code ... markers',\n },\n },\n required: ['target_filepath', 'instructions', 'code_edit'],\n },\n};\n\n/**\n * Format the result for passing back to Claude\n * \n * @param result - The edit result\n * @returns Formatted string for tool_result\n */\nfunction formatResult(result: EditFileResult): string {\n if (!result.success) {\n return `Error editing file: ${result.error}`;\n }\n \n const { changes } = result;\n const summary = [\n changes.linesAdded && `+${changes.linesAdded} lines`,\n changes.linesRemoved && `-${changes.linesRemoved} lines`,\n changes.linesModified && `~${changes.linesModified} lines modified`,\n ]\n .filter(Boolean)\n .join(', ');\n \n if (result.udiff) {\n return `Successfully applied changes to ${result.filepath}:\\n\\n${result.udiff}\\n\\nSummary: ${summary}`;\n }\n \n return `Successfully applied changes to ${result.filepath}. ${summary}`;\n}\n\n/**\n * Create a custom edit_file tool with configuration\n * \n * @param config - Configuration options\n * @returns Tool definition with execute and formatResult methods\n * \n * @example\n * ```ts\n * const tool = createEditFileTool({\n * baseDir: './src',\n * generateUdiff: true,\n * morphApiKey: 'sk-...',\n * description: 'Custom tool description for your use case'\n * });\n * \n * // Use as Anthropic tool\n * const response = await client.messages.create({\n * tools: [tool], // tool itself is the Tool definition\n * ...\n * });\n * \n * // Execute and format\n * const result = await tool.execute(toolUseBlock.input);\n * const formatted = tool.formatResult(result);\n * ```\n */\nexport function createEditFileTool(config: EditFileConfig = {}) {\n const toolDef: Tool = {\n ...editFileTool,\n ...(config.description && { description: config.description }),\n };\n \n return Object.assign({}, toolDef, {\n execute: async (input: EditFileInput): Promise<EditFileResult> => {\n return executeEditFile(input, config);\n },\n formatResult: (result: EditFileResult): string => {\n return formatResult(result);\n },\n getSystemPrompt: (): string => {\n return EDIT_FILE_SYSTEM_PROMPT;\n },\n });\n}\n\n"],"mappings":";;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AA0BO,IAAM,eAAqB;AAAA,EAChC,MAAM;AAAA,EACN,aAAa;AAAA,EACb,cAAc;AAAA,IACZ,MAAM;AAAA,IACN,YAAY;AAAA,MACV,iBAAiB;AAAA,QACf,MAAM;AAAA,QACN,aAAa;AAAA,MACf;AAAA,MACA,cAAc;AAAA,QACZ,MAAM;AAAA,QACN,aAAa;AAAA,MACf;AAAA,MACA,WAAW;AAAA,QACT,MAAM;AAAA,QACN,aAAa;AAAA,MACf;AAAA,IACF;AAAA,IACA,UAAU,CAAC,mBAAmB,gBAAgB,WAAW;AAAA,EAC3D;AACF;AAQA,SAAS,aAAa,QAAgC;AACpD,MAAI,CAAC,OAAO,SAAS;AACnB,WAAO,uBAAuB,OAAO,KAAK;AAAA,EAC5C;AAEA,QAAM,EAAE,QAAQ,IAAI;AACpB,QAAM,UAAU;AAAA,IACd,QAAQ,cAAc,IAAI,QAAQ,UAAU;AAAA,IAC5C,QAAQ,gBAAgB,IAAI,QAAQ,YAAY;AAAA,IAChD,QAAQ,iBAAiB,IAAI,QAAQ,aAAa;AAAA,EACpD,EACG,OAAO,OAAO,EACd,KAAK,IAAI;AAEZ,MAAI,OAAO,OAAO;AAChB,WAAO,mCAAmC,OAAO,QAAQ;AAAA;AAAA,EAAQ,OAAO,KAAK;AAAA;AAAA,WAAgB,OAAO;AAAA,EACtG;AAEA,SAAO,mCAAmC,OAAO,QAAQ,KAAK,OAAO;AACvE;AA4BO,SAAS,mBAAmB,SAAyB,CAAC,GAAG;AAC9D,QAAM,UAAgB;AAAA,IACpB,GAAG;AAAA,IACH,GAAI,OAAO,eAAe,EAAE,aAAa,OAAO,YAAY;AAAA,EAC9D;AAEA,SAAO,OAAO,OAAO,CAAC,GAAG,SAAS;AAAA,IAChC,SAAS,OAAO,UAAkD;AAChE,aAAO,gBAAgB,OAAO,MAAM;AAAA,IACtC;AAAA,IACA,cAAc,CAAC,WAAmC;AAChD,aAAO,aAAa,MAAM;AAAA,IAC5B;AAAA,IACA,iBAAiB,MAAc;AAC7B,aAAO;AAAA,IACT;AAAA,EACF,CAAC;AACH;","names":[]}