@polka-codes/core 0.10.13 → 0.10.16

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 (250) hide show
  1. package/dist/Agent/backoff.d.ts +7 -0
  2. package/dist/Agent/backoff.js +21 -0
  3. package/dist/Agent/backoff.js.map +1 -0
  4. package/dist/Agent/index.d.ts +2 -0
  5. package/dist/Agent/index.js +3 -0
  6. package/dist/Agent/index.js.map +1 -0
  7. package/dist/Agent/parseJsonFromMarkdown.d.ts +8 -0
  8. package/dist/Agent/parseJsonFromMarkdown.js +34 -0
  9. package/dist/Agent/parseJsonFromMarkdown.js.map +1 -0
  10. package/dist/Agent/parseJsonFromMarkdown.test.d.ts +1 -0
  11. package/dist/Agent/parseJsonFromMarkdown.test.js +70 -0
  12. package/dist/Agent/parseJsonFromMarkdown.test.js.map +1 -0
  13. package/dist/Agent/prompts.d.ts +9 -0
  14. package/dist/Agent/prompts.js +107 -0
  15. package/dist/Agent/prompts.js.map +1 -0
  16. package/dist/UsageMeter.d.ts +101 -0
  17. package/dist/UsageMeter.js +299 -0
  18. package/dist/UsageMeter.js.map +1 -0
  19. package/dist/UsageMeter.test.d.ts +4 -0
  20. package/dist/UsageMeter.test.js +556 -0
  21. package/dist/UsageMeter.test.js.map +1 -0
  22. package/dist/config/base.d.ts +68 -0
  23. package/dist/config/base.js +56 -0
  24. package/dist/config/base.js.map +1 -0
  25. package/dist/config/memory.d.ts +24 -0
  26. package/dist/config/memory.js +36 -0
  27. package/dist/config/memory.js.map +1 -0
  28. package/dist/config.d.ts +236 -0
  29. package/dist/config.js +184 -0
  30. package/dist/config.js.map +1 -0
  31. package/dist/errors/base.d.ts +31 -0
  32. package/dist/errors/base.js +60 -0
  33. package/dist/errors/base.js.map +1 -0
  34. package/dist/errors/index.d.ts +1 -0
  35. package/dist/errors/index.js +3 -0
  36. package/dist/errors/index.js.map +1 -0
  37. package/dist/fs/index.d.ts +2 -0
  38. package/dist/fs/index.js +3 -0
  39. package/dist/fs/index.js.map +1 -0
  40. package/dist/fs/node-provider.d.ts +16 -0
  41. package/dist/fs/node-provider.js +47 -0
  42. package/dist/fs/node-provider.js.map +1 -0
  43. package/dist/fs/provider.d.ts +61 -0
  44. package/dist/fs/provider.js +3 -0
  45. package/dist/fs/provider.js.map +1 -0
  46. package/dist/index.d.ts +20 -191
  47. package/dist/index.js +21 -4123
  48. package/dist/index.js.map +1 -0
  49. package/dist/memory/index.d.ts +1 -0
  50. package/dist/memory/index.js +2 -0
  51. package/dist/memory/index.js.map +1 -0
  52. package/dist/memory/types.d.ts +136 -0
  53. package/dist/memory/types.js +2 -0
  54. package/dist/memory/types.js.map +1 -0
  55. package/dist/path.d.ts +9 -0
  56. package/dist/path.js +68 -0
  57. package/dist/path.js.map +1 -0
  58. package/dist/path.test.d.ts +1 -0
  59. package/dist/path.test.js +82 -0
  60. package/dist/path.test.js.map +1 -0
  61. package/dist/pricing/converter.d.ts +6 -0
  62. package/dist/pricing/converter.js +13 -0
  63. package/dist/pricing/converter.js.map +1 -0
  64. package/dist/pricing/converter.test.d.ts +1 -0
  65. package/dist/pricing/converter.test.js +54 -0
  66. package/dist/pricing/converter.test.js.map +1 -0
  67. package/dist/pricing/index.d.ts +2 -0
  68. package/dist/pricing/index.js +2 -0
  69. package/dist/pricing/index.js.map +1 -0
  70. package/dist/pricing/portkey-client.d.ts +2 -0
  71. package/dist/pricing/portkey-client.js +57 -0
  72. package/dist/pricing/portkey-client.js.map +1 -0
  73. package/dist/pricing/pricing-service.d.ts +6 -0
  74. package/dist/pricing/pricing-service.js +125 -0
  75. package/dist/pricing/pricing-service.js.map +1 -0
  76. package/dist/pricing/pricing-service.test.d.ts +1 -0
  77. package/dist/pricing/pricing-service.test.js +141 -0
  78. package/dist/pricing/pricing-service.test.js.map +1 -0
  79. package/dist/pricing/types.d.ts +24 -0
  80. package/dist/pricing/types.js +2 -0
  81. package/dist/pricing/types.js.map +1 -0
  82. package/dist/skills/__tests__/discovery.test.d.ts +1 -0
  83. package/dist/skills/__tests__/discovery.test.js +254 -0
  84. package/dist/skills/__tests__/discovery.test.js.map +1 -0
  85. package/dist/skills/__tests__/validation.test.d.ts +1 -0
  86. package/dist/skills/__tests__/validation.test.js +221 -0
  87. package/dist/skills/__tests__/validation.test.js.map +1 -0
  88. package/dist/skills/constants.d.ts +32 -0
  89. package/dist/skills/constants.js +50 -0
  90. package/dist/skills/constants.js.map +1 -0
  91. package/dist/skills/discovery.d.ts +56 -0
  92. package/dist/skills/discovery.js +392 -0
  93. package/dist/skills/discovery.js.map +1 -0
  94. package/dist/skills/index.d.ts +4 -0
  95. package/dist/skills/index.js +6 -0
  96. package/dist/skills/index.js.map +1 -0
  97. package/dist/skills/tools/index.d.ts +3 -0
  98. package/dist/skills/tools/index.js +5 -0
  99. package/dist/skills/tools/index.js.map +1 -0
  100. package/dist/skills/tools/listSkills.d.ts +54 -0
  101. package/dist/skills/tools/listSkills.js +52 -0
  102. package/dist/skills/tools/listSkills.js.map +1 -0
  103. package/dist/skills/tools/loadSkill.d.ts +52 -0
  104. package/dist/skills/tools/loadSkill.js +86 -0
  105. package/dist/skills/tools/loadSkill.js.map +1 -0
  106. package/dist/skills/tools/readSkillFile.d.ts +43 -0
  107. package/dist/skills/tools/readSkillFile.js +68 -0
  108. package/dist/skills/tools/readSkillFile.js.map +1 -0
  109. package/dist/skills/types.d.ts +83 -0
  110. package/dist/skills/types.js +42 -0
  111. package/dist/skills/types.js.map +1 -0
  112. package/dist/skills/validation.d.ts +30 -0
  113. package/dist/skills/validation.js +133 -0
  114. package/dist/skills/validation.js.map +1 -0
  115. package/dist/tool.d.ts +51 -0
  116. package/dist/tool.js +2 -0
  117. package/dist/tool.js.map +1 -0
  118. package/dist/tools/askFollowupQuestion.d.ts +35 -0
  119. package/dist/tools/askFollowupQuestion.js +105 -0
  120. package/dist/tools/askFollowupQuestion.js.map +1 -0
  121. package/dist/tools/askFollowupQuestion.test.d.ts +1 -0
  122. package/dist/tools/askFollowupQuestion.test.js +80 -0
  123. package/dist/tools/askFollowupQuestion.test.js.map +1 -0
  124. package/dist/tools/executeCommand.d.ts +29 -0
  125. package/dist/tools/executeCommand.js +82 -0
  126. package/dist/tools/executeCommand.js.map +1 -0
  127. package/dist/tools/executeCommand.test.d.ts +1 -0
  128. package/dist/tools/executeCommand.test.js +60 -0
  129. package/dist/tools/executeCommand.test.js.map +1 -0
  130. package/dist/tools/fetchUrl.d.ts +26 -0
  131. package/dist/tools/fetchUrl.js +85 -0
  132. package/dist/tools/fetchUrl.js.map +1 -0
  133. package/dist/tools/index.d.ts +15 -0
  134. package/dist/tools/index.js +17 -0
  135. package/dist/tools/index.js.map +1 -0
  136. package/dist/tools/listFiles.d.ts +35 -0
  137. package/dist/tools/listFiles.js +61 -0
  138. package/dist/tools/listFiles.js.map +1 -0
  139. package/dist/tools/listFiles.test.d.ts +1 -0
  140. package/dist/tools/listFiles.test.js +59 -0
  141. package/dist/tools/listFiles.test.js.map +1 -0
  142. package/dist/tools/provider.d.ts +76 -0
  143. package/dist/tools/provider.js +60 -0
  144. package/dist/tools/provider.js.map +1 -0
  145. package/dist/tools/readBinaryFile.d.ts +26 -0
  146. package/dist/tools/readBinaryFile.js +52 -0
  147. package/dist/tools/readBinaryFile.js.map +1 -0
  148. package/dist/tools/readFile.d.ts +35 -0
  149. package/dist/tools/readFile.js +128 -0
  150. package/dist/tools/readFile.js.map +1 -0
  151. package/dist/tools/readFile.test.d.ts +1 -0
  152. package/dist/tools/readFile.test.js +37 -0
  153. package/dist/tools/readFile.test.js.map +1 -0
  154. package/dist/tools/removeFile.d.ts +26 -0
  155. package/dist/tools/removeFile.js +49 -0
  156. package/dist/tools/removeFile.js.map +1 -0
  157. package/dist/tools/removeFile.test.d.ts +1 -0
  158. package/dist/tools/removeFile.test.js +32 -0
  159. package/dist/tools/removeFile.test.js.map +1 -0
  160. package/dist/tools/renameFile.d.ts +29 -0
  161. package/dist/tools/renameFile.js +48 -0
  162. package/dist/tools/renameFile.js.map +1 -0
  163. package/dist/tools/renameFile.test.d.ts +1 -0
  164. package/dist/tools/renameFile.test.js +53 -0
  165. package/dist/tools/renameFile.test.js.map +1 -0
  166. package/dist/tools/replaceInFile.d.ts +29 -0
  167. package/dist/tools/replaceInFile.js +233 -0
  168. package/dist/tools/replaceInFile.js.map +1 -0
  169. package/dist/tools/replaceInFile.test.d.ts +1 -0
  170. package/dist/tools/replaceInFile.test.js +79 -0
  171. package/dist/tools/replaceInFile.test.js.map +1 -0
  172. package/dist/tools/response-builders.d.ts +64 -0
  173. package/dist/tools/response-builders.js +88 -0
  174. package/dist/tools/response-builders.js.map +1 -0
  175. package/dist/tools/search.d.ts +26 -0
  176. package/dist/tools/search.js +56 -0
  177. package/dist/tools/search.js.map +1 -0
  178. package/dist/tools/search.test.d.ts +1 -0
  179. package/dist/tools/search.test.js +22 -0
  180. package/dist/tools/search.test.js.map +1 -0
  181. package/dist/tools/searchFiles.d.ts +32 -0
  182. package/dist/tools/searchFiles.js +86 -0
  183. package/dist/tools/searchFiles.js.map +1 -0
  184. package/dist/tools/todo.d.ts +37 -0
  185. package/dist/tools/todo.js +41 -0
  186. package/dist/tools/todo.js.map +1 -0
  187. package/dist/tools/utils/index.d.ts +1 -0
  188. package/dist/tools/utils/index.js +2 -0
  189. package/dist/tools/utils/index.js.map +1 -0
  190. package/dist/tools/utils/replaceInFile.d.ts +7 -0
  191. package/dist/tools/utils/replaceInFile.js +133 -0
  192. package/dist/tools/utils/replaceInFile.js.map +1 -0
  193. package/dist/tools/utils/replaceInFile.test.d.ts +1 -0
  194. package/dist/tools/utils/replaceInFile.test.js +308 -0
  195. package/dist/tools/utils/replaceInFile.test.js.map +1 -0
  196. package/dist/tools/utils.d.ts +10 -0
  197. package/dist/tools/utils.js +27 -0
  198. package/dist/tools/utils.js.map +1 -0
  199. package/dist/tools/writeToFile.d.ts +29 -0
  200. package/dist/tools/writeToFile.js +85 -0
  201. package/dist/tools/writeToFile.js.map +1 -0
  202. package/dist/tools/writeToFile.test.d.ts +1 -0
  203. package/dist/tools/writeToFile.test.js +46 -0
  204. package/dist/tools/writeToFile.test.js.map +1 -0
  205. package/dist/utils/index.d.ts +1 -0
  206. package/dist/utils/index.js +3 -0
  207. package/dist/utils/index.js.map +1 -0
  208. package/dist/utils/merge.d.ts +26 -0
  209. package/dist/utils/merge.js +45 -0
  210. package/dist/utils/merge.js.map +1 -0
  211. package/dist/workflow/agent.workflow.d.ts +39 -0
  212. package/dist/workflow/agent.workflow.js +166 -0
  213. package/dist/workflow/agent.workflow.js.map +1 -0
  214. package/dist/workflow/agent.workflow.test.d.ts +1 -0
  215. package/dist/workflow/agent.workflow.test.js +175 -0
  216. package/dist/workflow/agent.workflow.test.js.map +1 -0
  217. package/dist/workflow/control-flow.test.d.ts +1 -0
  218. package/dist/workflow/control-flow.test.js +323 -0
  219. package/dist/workflow/control-flow.test.js.map +1 -0
  220. package/dist/workflow/dynamic-edge-cases.test.d.ts +1 -0
  221. package/dist/workflow/dynamic-edge-cases.test.js +486 -0
  222. package/dist/workflow/dynamic-edge-cases.test.js.map +1 -0
  223. package/dist/workflow/dynamic-types.d.ts +124 -0
  224. package/dist/workflow/dynamic-types.js +105 -0
  225. package/dist/workflow/dynamic-types.js.map +1 -0
  226. package/dist/workflow/dynamic.d.ts +118 -0
  227. package/dist/workflow/dynamic.js +999 -0
  228. package/dist/workflow/dynamic.js.map +1 -0
  229. package/dist/workflow/index.d.ts +6 -0
  230. package/dist/workflow/index.js +8 -0
  231. package/dist/workflow/index.js.map +1 -0
  232. package/dist/workflow/json-ai-types.d.ts +122 -0
  233. package/dist/workflow/json-ai-types.js +144 -0
  234. package/dist/workflow/json-ai-types.js.map +1 -0
  235. package/dist/workflow/json-schema-conversion.test.d.ts +1 -0
  236. package/dist/workflow/json-schema-conversion.test.js +371 -0
  237. package/dist/workflow/json-schema-conversion.test.js.map +1 -0
  238. package/dist/workflow/try-catch.test.d.ts +1 -0
  239. package/dist/workflow/try-catch.test.js +443 -0
  240. package/dist/workflow/try-catch.test.js.map +1 -0
  241. package/dist/workflow/types.d.ts +103 -0
  242. package/dist/workflow/types.js +17 -0
  243. package/dist/workflow/types.js.map +1 -0
  244. package/dist/workflow/workflow.d.ts +29 -0
  245. package/dist/workflow/workflow.js +57 -0
  246. package/dist/workflow/workflow.js.map +1 -0
  247. package/dist/workflow/workflow.test.d.ts +1 -0
  248. package/dist/workflow/workflow.test.js +189 -0
  249. package/dist/workflow/workflow.test.js.map +1 -0
  250. package/package.json +9 -1
@@ -0,0 +1,29 @@
1
+ import { z } from 'zod';
2
+ import type { ToolHandler } from '../tool';
3
+ import type { FilesystemProvider } from './provider';
4
+ export declare const toolInfo: {
5
+ readonly name: "renameFile";
6
+ readonly description: "Request to rename a file from source path to target path.";
7
+ readonly parameters: z.ZodObject<{
8
+ source_path: z.ZodString;
9
+ target_path: z.ZodString;
10
+ }, z.core.$strip>;
11
+ };
12
+ export declare const handler: ToolHandler<typeof toolInfo, FilesystemProvider>;
13
+ declare const _default: {
14
+ handler: ToolHandler<{
15
+ readonly name: "renameFile";
16
+ readonly description: "Request to rename a file from source path to target path.";
17
+ readonly parameters: z.ZodObject<{
18
+ source_path: z.ZodString;
19
+ target_path: z.ZodString;
20
+ }, z.core.$strip>;
21
+ }, FilesystemProvider>;
22
+ name: "renameFile";
23
+ description: "Request to rename a file from source path to target path.";
24
+ parameters: z.ZodObject<{
25
+ source_path: z.ZodString;
26
+ target_path: z.ZodString;
27
+ }, z.core.$strip>;
28
+ };
29
+ export default _default;
@@ -0,0 +1,48 @@
1
+ // Generated by polka.codes
2
+ // Tool for renaming files in the filesystem
3
+ import { z } from 'zod';
4
+ export const toolInfo = {
5
+ name: 'renameFile',
6
+ description: 'Request to rename a file from source path to target path.',
7
+ parameters: z
8
+ .object({
9
+ source_path: z.string().describe('The current path of the file').meta({ usageValue: 'Source file path here' }),
10
+ target_path: z.string().describe('The new path for the file').meta({ usageValue: 'Target file path here' }),
11
+ })
12
+ .meta({
13
+ examples: [
14
+ {
15
+ description: 'Request to rename a file',
16
+ input: {
17
+ source_path: 'src/old-name.js',
18
+ target_path: 'src/new-name.js',
19
+ },
20
+ },
21
+ ],
22
+ }),
23
+ };
24
+ export const handler = async (provider, args) => {
25
+ if (!provider.renameFile) {
26
+ return {
27
+ success: false,
28
+ message: {
29
+ type: 'error-text',
30
+ value: 'Not possible to rename file.',
31
+ },
32
+ };
33
+ }
34
+ const { source_path, target_path } = toolInfo.parameters.parse(args);
35
+ await provider.renameFile(source_path, target_path);
36
+ return {
37
+ success: true,
38
+ message: {
39
+ type: 'text',
40
+ value: `<rename_file_path>${target_path}</rename_file_path><status>Success</status>`,
41
+ },
42
+ };
43
+ };
44
+ export default {
45
+ ...toolInfo,
46
+ handler,
47
+ };
48
+ //# sourceMappingURL=renameFile.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"renameFile.js","sourceRoot":"","sources":["../../src/tools/renameFile.ts"],"names":[],"mappings":"AAAA,2BAA2B;AAC3B,4CAA4C;AAE5C,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAIvB,MAAM,CAAC,MAAM,QAAQ,GAAG;IACtB,IAAI,EAAE,YAAY;IAClB,WAAW,EAAE,2DAA2D;IACxE,UAAU,EAAE,CAAC;SACV,MAAM,CAAC;QACN,WAAW,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,8BAA8B,CAAC,CAAC,IAAI,CAAC,EAAE,UAAU,EAAE,uBAAuB,EAAE,CAAC;QAC9G,WAAW,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,2BAA2B,CAAC,CAAC,IAAI,CAAC,EAAE,UAAU,EAAE,uBAAuB,EAAE,CAAC;KAC5G,CAAC;SACD,IAAI,CAAC;QACJ,QAAQ,EAAE;YACR;gBACE,WAAW,EAAE,0BAA0B;gBACvC,KAAK,EAAE;oBACL,WAAW,EAAE,iBAAiB;oBAC9B,WAAW,EAAE,iBAAiB;iBAC/B;aACF;SACF;KACF,CAAC;CACuB,CAAA;AAE7B,MAAM,CAAC,MAAM,OAAO,GAAqD,KAAK,EAAE,QAAQ,EAAE,IAAI,EAAE,EAAE;IAChG,IAAI,CAAC,QAAQ,CAAC,UAAU,EAAE,CAAC;QACzB,OAAO;YACL,OAAO,EAAE,KAAK;YACd,OAAO,EAAE;gBACP,IAAI,EAAE,YAAY;gBAClB,KAAK,EAAE,8BAA8B;aACtC;SACF,CAAA;IACH,CAAC;IAED,MAAM,EAAE,WAAW,EAAE,WAAW,EAAE,GAAG,QAAQ,CAAC,UAAU,CAAC,KAAK,CAAC,IAAI,CAAC,CAAA;IACpE,MAAM,QAAQ,CAAC,UAAU,CAAC,WAAW,EAAE,WAAW,CAAC,CAAA;IAEnD,OAAO;QACL,OAAO,EAAE,IAAI;QACb,OAAO,EAAE;YACP,IAAI,EAAE,MAAM;YACZ,KAAK,EAAE,qBAAqB,WAAW,6CAA6C;SACrF;KACF,CAAA;AACH,CAAC,CAAA;AAED,eAAe;IACb,GAAG,QAAQ;IACX,OAAO;CACe,CAAA"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,53 @@
1
+ // Generated by polka.codes
2
+ // Tests for the renameFile tool
3
+ import { describe, expect, it, spyOn } from 'bun:test';
4
+ import { MockProvider } from './provider';
5
+ import renameFile from './renameFile';
6
+ describe('renameFile', () => {
7
+ it('should rename file successfully', async () => {
8
+ const mockProvider = new MockProvider();
9
+ spyOn(mockProvider, 'renameFile').mockResolvedValue();
10
+ const result = await renameFile.handler(mockProvider, {
11
+ source_path: 'old.txt',
12
+ target_path: 'new.txt',
13
+ });
14
+ // Verify successful rename
15
+ expect(result).toEqual({
16
+ success: true,
17
+ message: {
18
+ type: 'text',
19
+ value: '<rename_file_path>new.txt</rename_file_path><status>Success</status>',
20
+ },
21
+ });
22
+ expect(mockProvider.renameFile).toHaveBeenCalledWith('old.txt', 'new.txt');
23
+ });
24
+ it('should handle rename errors', async () => {
25
+ const mockProvider = new MockProvider();
26
+ spyOn(mockProvider, 'renameFile').mockRejectedValue(new Error('Rename error'));
27
+ const result = renameFile.handler(mockProvider, {
28
+ source_path: 'error.txt',
29
+ target_path: 'new.txt',
30
+ });
31
+ // Verify error is propagated
32
+ await expect(result).rejects.toThrow('Rename error');
33
+ expect(mockProvider.renameFile).toHaveBeenCalledWith('error.txt', 'new.txt');
34
+ });
35
+ it('should handle unavailable provider', async () => {
36
+ const mockProvider = new MockProvider();
37
+ // @ts-expect-error
38
+ mockProvider.renameFile = undefined;
39
+ const result = await renameFile.handler(mockProvider, {
40
+ source_path: 'test.txt',
41
+ target_path: 'new.txt',
42
+ });
43
+ // Verify unavailable provider returns error message
44
+ expect(result).toEqual({
45
+ success: false,
46
+ message: {
47
+ type: 'error-text',
48
+ value: 'Not possible to rename file.',
49
+ },
50
+ });
51
+ });
52
+ });
53
+ //# sourceMappingURL=renameFile.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"renameFile.test.js","sourceRoot":"","sources":["../../src/tools/renameFile.test.ts"],"names":[],"mappings":"AAAA,2BAA2B;AAC3B,gCAAgC;AAEhC,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,KAAK,EAAE,MAAM,UAAU,CAAA;AACtD,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAA;AACzC,OAAO,UAAU,MAAM,cAAc,CAAA;AAErC,QAAQ,CAAC,YAAY,EAAE,GAAG,EAAE;IAC1B,EAAE,CAAC,iCAAiC,EAAE,KAAK,IAAI,EAAE;QAC/C,MAAM,YAAY,GAAG,IAAI,YAAY,EAAE,CAAA;QACvC,KAAK,CAAC,YAAY,EAAE,YAAY,CAAC,CAAC,iBAAiB,EAAE,CAAA;QAErD,MAAM,MAAM,GAAG,MAAM,UAAU,CAAC,OAAO,CAAC,YAAY,EAAE;YACpD,WAAW,EAAE,SAAS;YACtB,WAAW,EAAE,SAAS;SACvB,CAAC,CAAA;QAEF,2BAA2B;QAC3B,MAAM,CAA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;gBAClB,KAAK,EAAE,8BAA8B;aACtC;SACF,CAAC,CAAA;IACJ,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA"}
@@ -0,0 +1,29 @@
1
+ import { z } from 'zod';
2
+ import type { ToolHandler } from '../tool';
3
+ import type { FilesystemProvider } from './provider';
4
+ export declare const toolInfo: {
5
+ readonly name: "replaceInFile";
6
+ readonly description: "Request to replace sections of content in an existing file using\nSEARCH/REPLACE blocks.\n\nWhen to use:\n- Making targeted changes to specific parts of a file\n- Replacing variable names, function signatures, imports\n- Fixing bugs in existing code\n- When you know the exact content to replace\n\nWhen NOT to use:\n- For creating new files: Use writeToFile instead\n- For completely replacing file contents: Use writeToFile instead\n- When you don't know the exact content: Read file first\n\nSEARCH/REPLACE FORMAT:\n<<<<<<< SEARCH\n[exact content to find]\n=======\n[new content to replace with]\n>>>>>>> REPLACE\n\nCritical rules:\n1. SEARCH content must match EXACTLY (character-for-character including whitespace)\n2. Each block replaces only first occurrence\n3. Include just enough lines for uniqueness (not too many, not too few)\n4. Keep blocks concise (don't include long unchanged sections)\n5. List blocks in order they appear in file\n6. Use multiple blocks for multiple independent changes\n\nSpecial operations:\n- Move code: Two blocks (delete from original + insert at new location)\n- Delete code: Empty REPLACE section\n\nIMPORTANT CONSTRAINTS:\n- SEARCH text must match file content exactly\n- Each block is independent (doesn't affect other blocks)\n- Cannot use for appending or inserting without SEARCH context";
7
+ readonly parameters: z.ZodObject<{
8
+ path: z.ZodString;
9
+ diff: z.ZodString;
10
+ }, z.core.$strip>;
11
+ };
12
+ export declare const handler: ToolHandler<typeof toolInfo, FilesystemProvider>;
13
+ declare const _default: {
14
+ handler: ToolHandler<{
15
+ readonly name: "replaceInFile";
16
+ readonly description: "Request to replace sections of content in an existing file using\nSEARCH/REPLACE blocks.\n\nWhen to use:\n- Making targeted changes to specific parts of a file\n- Replacing variable names, function signatures, imports\n- Fixing bugs in existing code\n- When you know the exact content to replace\n\nWhen NOT to use:\n- For creating new files: Use writeToFile instead\n- For completely replacing file contents: Use writeToFile instead\n- When you don't know the exact content: Read file first\n\nSEARCH/REPLACE FORMAT:\n<<<<<<< SEARCH\n[exact content to find]\n=======\n[new content to replace with]\n>>>>>>> REPLACE\n\nCritical rules:\n1. SEARCH content must match EXACTLY (character-for-character including whitespace)\n2. Each block replaces only first occurrence\n3. Include just enough lines for uniqueness (not too many, not too few)\n4. Keep blocks concise (don't include long unchanged sections)\n5. List blocks in order they appear in file\n6. Use multiple blocks for multiple independent changes\n\nSpecial operations:\n- Move code: Two blocks (delete from original + insert at new location)\n- Delete code: Empty REPLACE section\n\nIMPORTANT CONSTRAINTS:\n- SEARCH text must match file content exactly\n- Each block is independent (doesn't affect other blocks)\n- Cannot use for appending or inserting without SEARCH context";
17
+ readonly parameters: z.ZodObject<{
18
+ path: z.ZodString;
19
+ diff: z.ZodString;
20
+ }, z.core.$strip>;
21
+ }, FilesystemProvider>;
22
+ name: "replaceInFile";
23
+ description: "Request to replace sections of content in an existing file using\nSEARCH/REPLACE blocks.\n\nWhen to use:\n- Making targeted changes to specific parts of a file\n- Replacing variable names, function signatures, imports\n- Fixing bugs in existing code\n- When you know the exact content to replace\n\nWhen NOT to use:\n- For creating new files: Use writeToFile instead\n- For completely replacing file contents: Use writeToFile instead\n- When you don't know the exact content: Read file first\n\nSEARCH/REPLACE FORMAT:\n<<<<<<< SEARCH\n[exact content to find]\n=======\n[new content to replace with]\n>>>>>>> REPLACE\n\nCritical rules:\n1. SEARCH content must match EXACTLY (character-for-character including whitespace)\n2. Each block replaces only first occurrence\n3. Include just enough lines for uniqueness (not too many, not too few)\n4. Keep blocks concise (don't include long unchanged sections)\n5. List blocks in order they appear in file\n6. Use multiple blocks for multiple independent changes\n\nSpecial operations:\n- Move code: Two blocks (delete from original + insert at new location)\n- Delete code: Empty REPLACE section\n\nIMPORTANT CONSTRAINTS:\n- SEARCH text must match file content exactly\n- Each block is independent (doesn't affect other blocks)\n- Cannot use for appending or inserting without SEARCH context";
24
+ parameters: z.ZodObject<{
25
+ path: z.ZodString;
26
+ diff: z.ZodString;
27
+ }, z.core.$strip>;
28
+ };
29
+ export default _default;
@@ -0,0 +1,233 @@
1
+ // generated by polka.codes
2
+ import { z } from 'zod';
3
+ import { replaceInFile } from './utils/replaceInFile';
4
+ export const toolInfo = {
5
+ name: 'replaceInFile',
6
+ description: `Request to replace sections of content in an existing file using
7
+ SEARCH/REPLACE blocks.
8
+
9
+ When to use:
10
+ - Making targeted changes to specific parts of a file
11
+ - Replacing variable names, function signatures, imports
12
+ - Fixing bugs in existing code
13
+ - When you know the exact content to replace
14
+
15
+ When NOT to use:
16
+ - For creating new files: Use writeToFile instead
17
+ - For completely replacing file contents: Use writeToFile instead
18
+ - When you don't know the exact content: Read file first
19
+
20
+ SEARCH/REPLACE FORMAT:
21
+ <<<<<<< SEARCH
22
+ [exact content to find]
23
+ =======
24
+ [new content to replace with]
25
+ >>>>>>> REPLACE
26
+
27
+ Critical rules:
28
+ 1. SEARCH content must match EXACTLY (character-for-character including whitespace)
29
+ 2. Each block replaces only first occurrence
30
+ 3. Include just enough lines for uniqueness (not too many, not too few)
31
+ 4. Keep blocks concise (don't include long unchanged sections)
32
+ 5. List blocks in order they appear in file
33
+ 6. Use multiple blocks for multiple independent changes
34
+
35
+ Special operations:
36
+ - Move code: Two blocks (delete from original + insert at new location)
37
+ - Delete code: Empty REPLACE section
38
+
39
+ IMPORTANT CONSTRAINTS:
40
+ - SEARCH text must match file content exactly
41
+ - Each block is independent (doesn't affect other blocks)
42
+ - Cannot use for appending or inserting without SEARCH context`,
43
+ parameters: z
44
+ .object({
45
+ path: z.string().describe('The path of the file to modify').meta({ usageValue: 'File path here' }),
46
+ diff: z
47
+ .string()
48
+ .describe(`One or more SEARCH/REPLACE blocks following this exact format:
49
+ \`\`\`
50
+ <<<<<<< SEARCH
51
+ [exact content to find]
52
+ =======
53
+ [new content to replace with]
54
+ >>>>>>> REPLACE
55
+ \`\`\`
56
+ Critical rules:
57
+ 1. SEARCH content must match the associated file section to find EXACTLY:
58
+ * Match character-for-character including whitespace, indentation, line endings
59
+ * Include all comments, docstrings, etc.
60
+ 2. SEARCH/REPLACE blocks will ONLY replace the first match occurrence.
61
+ * Including multiple unique SEARCH/REPLACE blocks if you need to make multiple changes.
62
+ * Include *just* enough lines in each SEARCH section to uniquely match each set of lines that need to change.
63
+ * When using multiple SEARCH/REPLACE blocks, list them in the order they appear in the file.
64
+ 3. Keep SEARCH/REPLACE blocks concise:
65
+ * Break large SEARCH/REPLACE blocks into a series of smaller blocks that each change a small portion of the file.
66
+ * Include just the changing lines, and a few surrounding lines if needed for uniqueness.
67
+ * Do not include long runs of unchanging lines in SEARCH/REPLACE blocks.
68
+ * Each line must be complete. Never truncate lines mid-way through as this can cause matching failures.
69
+ 4. Special operations:
70
+ * To move code: Use two SEARCH/REPLACE blocks (one to delete from original + one to insert at new location)
71
+ * To delete code: Empty REPLACE section`)
72
+ .meta({ usageValue: 'Search and replace blocks here' }),
73
+ })
74
+ .meta({
75
+ examples: [
76
+ {
77
+ description: 'Request to replace sections of content in a file',
78
+ input: {
79
+ path: 'src/main.js',
80
+ diff: `<<<<<<< SEARCH
81
+ import React from 'react';
82
+ =======
83
+ import React, { useState } from 'react';
84
+ >>>>>>> REPLACE
85
+
86
+ <<<<<<< SEARCH
87
+ function handleSubmit() {
88
+ saveData();
89
+ setLoading(false);
90
+ }
91
+
92
+ =======
93
+ >>>>>>> REPLACE
94
+
95
+ <<<<<<< SEARCH
96
+ return (
97
+ <div>
98
+ =======
99
+ function handleSubmit() {
100
+ saveData();
101
+ setLoading(false);
102
+ }
103
+
104
+ return (
105
+ <div>
106
+ >>>>>>> REPLACE`,
107
+ },
108
+ },
109
+ {
110
+ description: 'Request to perform a simple, single-line replacement',
111
+ input: {
112
+ path: 'src/config.js',
113
+ diff: `<<<<<<< SEARCH
114
+ const API_URL = 'https://api.example.com';
115
+ =======
116
+ const API_URL = 'https://api.staging.example.com';
117
+ >>>>>>> REPLACE`,
118
+ },
119
+ },
120
+ {
121
+ description: 'Request to add a new function to a file',
122
+ input: {
123
+ path: 'src/utils.js',
124
+ diff: `<<<<<<< SEARCH
125
+ function helperA() {
126
+ // ...
127
+ }
128
+ =======
129
+ function helperA() {
130
+ // ...
131
+ }
132
+
133
+ function newHelper() {
134
+ // implementation
135
+ }
136
+ >>>>>>> REPLACE`,
137
+ },
138
+ },
139
+ {
140
+ description: 'Request to delete a block of code from a file',
141
+ input: {
142
+ path: 'src/app.js',
143
+ diff: `<<<<<<< SEARCH
144
+ function oldFeature() {
145
+ // This is no longer needed
146
+ }
147
+
148
+ =======
149
+ >>>>>>> REPLACE`,
150
+ },
151
+ },
152
+ ],
153
+ }),
154
+ };
155
+ export const handler = async (provider, args) => {
156
+ if (!provider.readFile || !provider.writeFile) {
157
+ return {
158
+ success: false,
159
+ message: {
160
+ type: 'error-text',
161
+ value: 'Not possible to replace in file.',
162
+ },
163
+ };
164
+ }
165
+ const parsed = toolInfo.parameters.safeParse(args);
166
+ if (!parsed.success) {
167
+ return {
168
+ success: false,
169
+ message: {
170
+ type: 'error-text',
171
+ value: `Invalid arguments for replaceInFile: ${parsed.error.message}`,
172
+ },
173
+ };
174
+ }
175
+ const { path, diff } = parsed.data;
176
+ try {
177
+ const fileContent = await provider.readFile(path, false);
178
+ if (fileContent == null) {
179
+ return {
180
+ success: false,
181
+ message: {
182
+ type: 'error-text',
183
+ value: `<replace_in_file_result path="${path}" status="failed" message="File not found" />`,
184
+ },
185
+ };
186
+ }
187
+ const result = replaceInFile(fileContent, diff);
188
+ if (result.status === 'no_diff_applied') {
189
+ return {
190
+ success: false,
191
+ message: {
192
+ type: 'error-text',
193
+ value: `<replace_in_file_result path="${path}" status="failed" message="Unable to apply changes">
194
+ <file_content path="${path}">${fileContent}</file_content>
195
+ </replace_in_file_result>`,
196
+ },
197
+ };
198
+ }
199
+ await provider.writeFile(path, result.content);
200
+ if (result.status === 'some_diff_applied') {
201
+ return {
202
+ success: true,
203
+ message: {
204
+ type: 'text',
205
+ value: `<replace_in_file_result path="${path}" status="some_diff_applied" applied_count="${result.appliedCount}" total_count="${result.totalCount}">
206
+ <file_content path="${path}">${result.content}</file_content>
207
+ </replace_in_file_result>`,
208
+ },
209
+ };
210
+ }
211
+ return {
212
+ success: true,
213
+ message: {
214
+ type: 'text',
215
+ value: `<replace_in_file_result path="${path}" status="all_diff_applied" />`,
216
+ },
217
+ };
218
+ }
219
+ catch (error) {
220
+ return {
221
+ success: false,
222
+ message: {
223
+ type: 'error-text',
224
+ value: `Invalid arguments for replaceInFile: ${error}`,
225
+ },
226
+ };
227
+ }
228
+ };
229
+ export default {
230
+ ...toolInfo,
231
+ handler,
232
+ };
233
+ //# sourceMappingURL=replaceInFile.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"replaceInFile.js","sourceRoot":"","sources":["../../src/tools/replaceInFile.ts"],"names":[],"mappings":"AAAA,2BAA2B;AAC3B,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAGvB,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAA;AAErD,MAAM,CAAC,MAAM,QAAQ,GAAG;IACtB,IAAI,EAAE,eAAe;IACrB,WAAW,EAAE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;+DAoCgD;IAC7D,UAAU,EAAE,CAAC;SACV,MAAM,CAAC;QACN,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,gCAAgC,CAAC,CAAC,IAAI,CAAC,EAAE,UAAU,EAAE,gBAAgB,EAAE,CAAC;QAClG,IAAI,EAAE,CAAC;aACJ,MAAM,EAAE;aACR,QAAQ,CACP;;;;;;;;;;;;;;;;;;;;;;;4CAuBkC,CACnC;aACA,IAAI,CAAC,EAAE,UAAU,EAAE,gCAAgC,EAAE,CAAC;KAC1D,CAAC;SACD,IAAI,CAAC;QACJ,QAAQ,EAAE;YACR;gBACE,WAAW,EAAE,kDAAkD;gBAC/D,KAAK,EAAE;oBACL,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Q;IACX,OAAO;CACe,CAAA"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,79 @@
1
+ // generated by polka.codes
2
+ import { describe, expect, mock, spyOn, test } from 'bun:test';
3
+ import { handler } from './replaceInFile';
4
+ import * as replaceInFileModule from './utils/replaceInFile';
5
+ describe('replaceInFile tool', () => {
6
+ const mockProvider = {
7
+ readFile: mock((_path) => Promise.resolve('')),
8
+ writeFile: mock((_path, _content) => Promise.resolve()),
9
+ };
10
+ test('handler should return error if provider is missing methods', async () => {
11
+ const incompleteProvider = { writeFile: mock(() => Promise.resolve()) };
12
+ const result = await handler(incompleteProvider, {});
13
+ expect(result).toEqual({
14
+ success: false,
15
+ message: {
16
+ type: 'error-text',
17
+ value: 'Not possible to replace in file.',
18
+ },
19
+ });
20
+ });
21
+ test('handler should return file not found error', async () => {
22
+ ;
23
+ mockProvider.readFile.mockResolvedValueOnce(undefined);
24
+ const args = { path: 'nonexistent.txt', diff: '...' };
25
+ const result = await handler(mockProvider, args);
26
+ expect(result.success).toBe(false);
27
+ if (result.success === false) {
28
+ expect(result.message).toMatchSnapshot();
29
+ }
30
+ });
31
+ test('handler should return no_diff_applied message', async () => {
32
+ ;
33
+ mockProvider.readFile.mockResolvedValueOnce('file content');
34
+ spyOn(replaceInFileModule, 'replaceInFile').mockReturnValueOnce({
35
+ status: 'no_diff_applied',
36
+ appliedCount: 0,
37
+ totalCount: 2,
38
+ content: 'file content',
39
+ });
40
+ const args = { path: 'test.txt', diff: '...' };
41
+ const result = await handler(mockProvider, args);
42
+ expect(result).toMatchSnapshot();
43
+ });
44
+ test('handler should return some_diff_applied message', async () => {
45
+ ;
46
+ mockProvider.readFile.mockResolvedValueOnce('file content');
47
+ spyOn(replaceInFileModule, 'replaceInFile').mockReturnValueOnce({
48
+ status: 'some_diff_applied',
49
+ appliedCount: 1,
50
+ totalCount: 2,
51
+ content: 'new content',
52
+ });
53
+ const args = { path: 'test.txt', diff: '...' };
54
+ const result = await handler(mockProvider, args);
55
+ expect(result.success).toBe(true);
56
+ if (result.success === true) {
57
+ expect(result.message).toMatchSnapshot();
58
+ }
59
+ expect(mockProvider.writeFile).toHaveBeenCalledWith('test.txt', 'new content');
60
+ });
61
+ test('handler should return all_diff_applied message', async () => {
62
+ ;
63
+ mockProvider.readFile.mockResolvedValueOnce('file content');
64
+ spyOn(replaceInFileModule, 'replaceInFile').mockReturnValueOnce({
65
+ status: 'all_diff_applied',
66
+ appliedCount: 2,
67
+ totalCount: 2,
68
+ content: 'new content',
69
+ });
70
+ const args = { path: 'test.txt', diff: '...' };
71
+ const result = await handler(mockProvider, args);
72
+ expect(result.success).toBe(true);
73
+ if (result.success === true) {
74
+ expect(result.message).toMatchSnapshot();
75
+ }
76
+ expect(mockProvider.writeFile).toHaveBeenCalledWith('test.txt', 'new content');
77
+ });
78
+ });
79
+ //# sourceMappingURL=replaceInFile.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"replaceInFile.test.js","sourceRoot":"","sources":["../../src/tools/replaceInFile.test.ts"],"names":[],"mappings":"AAAA,2BAA2B;AAC3B,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAa,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,UAAU,CAAA;AAGzE,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAA;AACzC,OAAO,KAAK,mBAAmB,MAAM,uBAAuB,CAAA;AAE5D,QAAQ,CAAC,oBAAoB,EAAE,GAAG,EAAE;IAClC,MAAM,YAAY,GAAuB;QACvC,QAAQ,EAAE,IAAI,CAAC,CAAC,KAAa,EAA+B,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;QACnF,SAAS,EAAE,IAAI,CAAC,CAAC,KAAa,EAAE,QAAgB,EAAiB,EAAE,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC;KACvF,CAAA;IAED,IAAI,CAAC,4DAA4D,EAAE,KAAK,IAAI,EAAE;QAC5E,MAAM,kBAAkB,GAAG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CAAC;YACf,UAAU,EAAE,CAAC;YACb,OAAO,EAAE,aAAa;SACvB,CAAC,CAAA;QACF,MAAM,IAAI,GAAG,EAAE,IAAI,EAAE,UAAU,EAAE,IAAI,EAAE,KAAK,EAAE,CAAA;QAC9C,MAAM,MAAM,GAAG,MAAO,OAAiC,CAAC,YAAY,EAAE,IAAI,CAAC,CAAA;QAC3E,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;QACjC,IAAI,MAAM,CAAC,OAAO,KAAK,IAAI,EAAE,CAAC;YAC5B,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,eAAe,EAAE,CAAA;QAC1C,CAAC;QACD,MAAM,CAAC,YAAY,CAAC,SAAS,CAAC,CAAC,oBAAoB,CAAC,UAAU,EAAE,aAAa,CAAC,CAAA;IAChF,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA"}
@@ -0,0 +1,64 @@
1
+ /**
2
+ * Shared utilities for building tool response objects
3
+ * Eliminates duplication across 20+ tool files
4
+ */
5
+ import type { ToolResponse } from '../tool';
6
+ /**
7
+ * Create a successful tool response
8
+ *
9
+ * @param value - The response value (string or JSON string)
10
+ * @param type - Response type ('text' or 'json')
11
+ * @returns A successful tool response object
12
+ *
13
+ * @example
14
+ * ```ts
15
+ * return createSuccessResponse('File content loaded')
16
+ * return createSuccessResponse(JSON.stringify(data), 'json')
17
+ * ```
18
+ */
19
+ export declare function createSuccessResponse(value: string, type?: 'text' | 'json'): ToolResponse;
20
+ /**
21
+ * Create an error tool response
22
+ *
23
+ * @param message - The error message
24
+ * @returns An error tool response object
25
+ *
26
+ * @example
27
+ * ```ts
28
+ * return createErrorResponse('Failed to read file')
29
+ * ```
30
+ */
31
+ export declare function createErrorResponse(message: string): ToolResponse;
32
+ /**
33
+ * Create a provider capability error response
34
+ * Use this when a required provider capability is not available
35
+ *
36
+ * @param capability - The capability that's missing (e.g., "read file", "write file")
37
+ * @returns An error response indicating the missing capability
38
+ *
39
+ * @example
40
+ * ```ts
41
+ * if (!provider.readFile) {
42
+ * return createProviderErrorResponse('read file')
43
+ * }
44
+ * ```
45
+ */
46
+ export declare function createProviderErrorResponse(capability: string): ToolResponse;
47
+ /**
48
+ * Create a validation error response
49
+ * Use this when input validation fails
50
+ *
51
+ * @param errors - The validation error details
52
+ * @returns An error response with validation details
53
+ *
54
+ * @example
55
+ * ```ts
56
+ * const result = schema.safeParse(input)
57
+ * if (!result.success) {
58
+ * return createValidationErrorResponse(result.error)
59
+ * }
60
+ * ```
61
+ */
62
+ export declare function createValidationErrorResponse(errors: {
63
+ message: string;
64
+ }): ToolResponse;
@@ -0,0 +1,88 @@
1
+ /**
2
+ * Shared utilities for building tool response objects
3
+ * Eliminates duplication across 20+ tool files
4
+ */
5
+ /**
6
+ * Create a successful tool response
7
+ *
8
+ * @param value - The response value (string or JSON string)
9
+ * @param type - Response type ('text' or 'json')
10
+ * @returns A successful tool response object
11
+ *
12
+ * @example
13
+ * ```ts
14
+ * return createSuccessResponse('File content loaded')
15
+ * return createSuccessResponse(JSON.stringify(data), 'json')
16
+ * ```
17
+ */
18
+ export function createSuccessResponse(value, type = 'text') {
19
+ return {
20
+ success: true,
21
+ message: { type, value },
22
+ };
23
+ }
24
+ /**
25
+ * Create an error tool response
26
+ *
27
+ * @param message - The error message
28
+ * @returns An error tool response object
29
+ *
30
+ * @example
31
+ * ```ts
32
+ * return createErrorResponse('Failed to read file')
33
+ * ```
34
+ */
35
+ export function createErrorResponse(message) {
36
+ return {
37
+ success: false,
38
+ message: { type: 'error-text', value: message },
39
+ };
40
+ }
41
+ /**
42
+ * Create a provider capability error response
43
+ * Use this when a required provider capability is not available
44
+ *
45
+ * @param capability - The capability that's missing (e.g., "read file", "write file")
46
+ * @returns An error response indicating the missing capability
47
+ *
48
+ * @example
49
+ * ```ts
50
+ * if (!provider.readFile) {
51
+ * return createProviderErrorResponse('read file')
52
+ * }
53
+ * ```
54
+ */
55
+ export function createProviderErrorResponse(capability) {
56
+ return {
57
+ success: false,
58
+ message: {
59
+ type: 'error-text',
60
+ value: `Not possible to ${capability}.`,
61
+ },
62
+ };
63
+ }
64
+ /**
65
+ * Create a validation error response
66
+ * Use this when input validation fails
67
+ *
68
+ * @param errors - The validation error details
69
+ * @returns An error response with validation details
70
+ *
71
+ * @example
72
+ * ```ts
73
+ * const result = schema.safeParse(input)
74
+ * if (!result.success) {
75
+ * return createValidationErrorResponse(result.error)
76
+ * }
77
+ * ```
78
+ */
79
+ export function createValidationErrorResponse(errors) {
80
+ return {
81
+ success: false,
82
+ message: {
83
+ type: 'error-text',
84
+ value: `Validation failed: ${errors.message}`,
85
+ },
86
+ };
87
+ }
88
+ //# sourceMappingURL=response-builders.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"response-builders.js","sourceRoot":"","sources":["../../src/tools/response-builders.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,qBAAqB,CAAC,KAAa,EAAE,OAAwB,MAAM;IACjF,OAAO;QACL,OAAO,EAAE,IAAI;QACb,OAAO,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE;KACzB,CAAA;AACH,CAAC;AAED;;;;;;;;;;GAUG;AACH,MAAM,UAAU,mBAAmB,CAAC,OAAe;IACjD,OAAO;QACL,OAAO,EAAE,KAAK;QACd,OAAO,EAAE,EAAE,IAAI,EAAE,YAAY,EAAE,KAAK,EAAE,OAAO,EAAE;KAChD,CAAA;AACH,CAAC;AAED;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,2BAA2B,CAAC,UAAkB;IAC5D,OAAO;QACL,OAAO,EAAE,KAAK;QACd,OAAO,EAAE;YACP,IAAI,EAAE,YAAY;YAClB,KAAK,EAAE,mBAAmB,UAAU,GAAG;SACxC;KACF,CAAA;AACH,CAAC;AAED;;;;;;;;;;;;;;GAcG;AACH,MAAM,UAAU,6BAA6B,CAAC,MAA2B;IACvE,OAAO;QACL,OAAO,EAAE,KAAK;QACd,OAAO,EAAE;YACP,IAAI,EAAE,YAAY;YAClB,KAAK,EAAE,sBAAsB,MAAM,CAAC,OAAO,EAAE;SAC9C;KACF,CAAA;AACH,CAAC"}