@polka-codes/core 0.10.11 → 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.
- package/dist/Agent/backoff.d.ts +7 -0
- package/dist/Agent/backoff.js +21 -0
- package/dist/Agent/backoff.js.map +1 -0
- package/dist/Agent/index.d.ts +2 -0
- package/dist/Agent/index.js +3 -0
- package/dist/Agent/index.js.map +1 -0
- package/dist/Agent/parseJsonFromMarkdown.d.ts +8 -0
- package/dist/Agent/parseJsonFromMarkdown.js +34 -0
- package/dist/Agent/parseJsonFromMarkdown.js.map +1 -0
- package/dist/Agent/parseJsonFromMarkdown.test.d.ts +1 -0
- package/dist/Agent/parseJsonFromMarkdown.test.js +70 -0
- package/dist/Agent/parseJsonFromMarkdown.test.js.map +1 -0
- package/dist/Agent/prompts.d.ts +9 -0
- package/dist/Agent/prompts.js +107 -0
- package/dist/Agent/prompts.js.map +1 -0
- package/dist/UsageMeter.d.ts +101 -0
- package/dist/UsageMeter.js +299 -0
- package/dist/UsageMeter.js.map +1 -0
- package/dist/UsageMeter.test.d.ts +4 -0
- package/dist/UsageMeter.test.js +556 -0
- package/dist/UsageMeter.test.js.map +1 -0
- package/dist/config/base.d.ts +68 -0
- package/dist/config/base.js +56 -0
- package/dist/config/base.js.map +1 -0
- package/dist/config/memory.d.ts +24 -0
- package/dist/config/memory.js +36 -0
- package/dist/config/memory.js.map +1 -0
- package/dist/config.d.ts +236 -0
- package/dist/config.js +184 -0
- package/dist/config.js.map +1 -0
- package/dist/errors/base.d.ts +31 -0
- package/dist/errors/base.js +60 -0
- package/dist/errors/base.js.map +1 -0
- package/dist/errors/index.d.ts +1 -0
- package/dist/errors/index.js +3 -0
- package/dist/errors/index.js.map +1 -0
- package/dist/fs/index.d.ts +2 -0
- package/dist/fs/index.js +3 -0
- package/dist/fs/index.js.map +1 -0
- package/dist/fs/node-provider.d.ts +16 -0
- package/dist/fs/node-provider.js +47 -0
- package/dist/fs/node-provider.js.map +1 -0
- package/dist/fs/provider.d.ts +61 -0
- package/dist/fs/provider.js +3 -0
- package/dist/fs/provider.js.map +1 -0
- package/dist/index.d.ts +20 -191
- package/dist/index.js +21 -4123
- package/dist/index.js.map +1 -0
- package/dist/memory/index.d.ts +1 -0
- package/dist/memory/index.js +2 -0
- package/dist/memory/index.js.map +1 -0
- package/dist/memory/types.d.ts +136 -0
- package/dist/memory/types.js +2 -0
- package/dist/memory/types.js.map +1 -0
- package/dist/path.d.ts +9 -0
- package/dist/path.js +68 -0
- package/dist/path.js.map +1 -0
- package/dist/path.test.d.ts +1 -0
- package/dist/path.test.js +82 -0
- package/dist/path.test.js.map +1 -0
- package/dist/pricing/converter.d.ts +6 -0
- package/dist/pricing/converter.js +13 -0
- package/dist/pricing/converter.js.map +1 -0
- package/dist/pricing/converter.test.d.ts +1 -0
- package/dist/pricing/converter.test.js +54 -0
- package/dist/pricing/converter.test.js.map +1 -0
- package/dist/pricing/index.d.ts +2 -0
- package/dist/pricing/index.js +2 -0
- package/dist/pricing/index.js.map +1 -0
- package/dist/pricing/portkey-client.d.ts +2 -0
- package/dist/pricing/portkey-client.js +57 -0
- package/dist/pricing/portkey-client.js.map +1 -0
- package/dist/pricing/pricing-service.d.ts +6 -0
- package/dist/pricing/pricing-service.js +125 -0
- package/dist/pricing/pricing-service.js.map +1 -0
- package/dist/pricing/pricing-service.test.d.ts +1 -0
- package/dist/pricing/pricing-service.test.js +141 -0
- package/dist/pricing/pricing-service.test.js.map +1 -0
- package/dist/pricing/types.d.ts +24 -0
- package/dist/pricing/types.js +2 -0
- package/dist/pricing/types.js.map +1 -0
- package/dist/skills/__tests__/discovery.test.d.ts +1 -0
- package/dist/skills/__tests__/discovery.test.js +254 -0
- package/dist/skills/__tests__/discovery.test.js.map +1 -0
- package/dist/skills/__tests__/validation.test.d.ts +1 -0
- package/dist/skills/__tests__/validation.test.js +221 -0
- package/dist/skills/__tests__/validation.test.js.map +1 -0
- package/dist/skills/constants.d.ts +32 -0
- package/dist/skills/constants.js +50 -0
- package/dist/skills/constants.js.map +1 -0
- package/dist/skills/discovery.d.ts +56 -0
- package/dist/skills/discovery.js +392 -0
- package/dist/skills/discovery.js.map +1 -0
- package/dist/skills/index.d.ts +4 -0
- package/dist/skills/index.js +6 -0
- package/dist/skills/index.js.map +1 -0
- package/dist/skills/tools/index.d.ts +3 -0
- package/dist/skills/tools/index.js +5 -0
- package/dist/skills/tools/index.js.map +1 -0
- package/dist/skills/tools/listSkills.d.ts +54 -0
- package/dist/skills/tools/listSkills.js +52 -0
- package/dist/skills/tools/listSkills.js.map +1 -0
- package/dist/skills/tools/loadSkill.d.ts +52 -0
- package/dist/skills/tools/loadSkill.js +86 -0
- package/dist/skills/tools/loadSkill.js.map +1 -0
- package/dist/skills/tools/readSkillFile.d.ts +43 -0
- package/dist/skills/tools/readSkillFile.js +68 -0
- package/dist/skills/tools/readSkillFile.js.map +1 -0
- package/dist/skills/types.d.ts +83 -0
- package/dist/skills/types.js +42 -0
- package/dist/skills/types.js.map +1 -0
- package/dist/skills/validation.d.ts +30 -0
- package/dist/skills/validation.js +133 -0
- package/dist/skills/validation.js.map +1 -0
- package/dist/tool.d.ts +51 -0
- package/dist/tool.js +2 -0
- package/dist/tool.js.map +1 -0
- package/dist/tools/askFollowupQuestion.d.ts +35 -0
- package/dist/tools/askFollowupQuestion.js +105 -0
- package/dist/tools/askFollowupQuestion.js.map +1 -0
- package/dist/tools/askFollowupQuestion.test.d.ts +1 -0
- package/dist/tools/askFollowupQuestion.test.js +80 -0
- package/dist/tools/askFollowupQuestion.test.js.map +1 -0
- package/dist/tools/executeCommand.d.ts +29 -0
- package/dist/tools/executeCommand.js +82 -0
- package/dist/tools/executeCommand.js.map +1 -0
- package/dist/tools/executeCommand.test.d.ts +1 -0
- package/dist/tools/executeCommand.test.js +60 -0
- package/dist/tools/executeCommand.test.js.map +1 -0
- package/dist/tools/fetchUrl.d.ts +26 -0
- package/dist/tools/fetchUrl.js +85 -0
- package/dist/tools/fetchUrl.js.map +1 -0
- package/dist/tools/index.d.ts +15 -0
- package/dist/tools/index.js +17 -0
- package/dist/tools/index.js.map +1 -0
- package/dist/tools/listFiles.d.ts +35 -0
- package/dist/tools/listFiles.js +61 -0
- package/dist/tools/listFiles.js.map +1 -0
- package/dist/tools/listFiles.test.d.ts +1 -0
- package/dist/tools/listFiles.test.js +59 -0
- package/dist/tools/listFiles.test.js.map +1 -0
- package/dist/tools/provider.d.ts +76 -0
- package/dist/tools/provider.js +60 -0
- package/dist/tools/provider.js.map +1 -0
- package/dist/tools/readBinaryFile.d.ts +26 -0
- package/dist/tools/readBinaryFile.js +52 -0
- package/dist/tools/readBinaryFile.js.map +1 -0
- package/dist/tools/readFile.d.ts +35 -0
- package/dist/tools/readFile.js +128 -0
- package/dist/tools/readFile.js.map +1 -0
- package/dist/tools/readFile.test.d.ts +1 -0
- package/dist/tools/readFile.test.js +37 -0
- package/dist/tools/readFile.test.js.map +1 -0
- package/dist/tools/removeFile.d.ts +26 -0
- package/dist/tools/removeFile.js +49 -0
- package/dist/tools/removeFile.js.map +1 -0
- package/dist/tools/removeFile.test.d.ts +1 -0
- package/dist/tools/removeFile.test.js +32 -0
- package/dist/tools/removeFile.test.js.map +1 -0
- package/dist/tools/renameFile.d.ts +29 -0
- package/dist/tools/renameFile.js +48 -0
- package/dist/tools/renameFile.js.map +1 -0
- package/dist/tools/renameFile.test.d.ts +1 -0
- package/dist/tools/renameFile.test.js +53 -0
- package/dist/tools/renameFile.test.js.map +1 -0
- package/dist/tools/replaceInFile.d.ts +29 -0
- package/dist/tools/replaceInFile.js +233 -0
- package/dist/tools/replaceInFile.js.map +1 -0
- package/dist/tools/replaceInFile.test.d.ts +1 -0
- package/dist/tools/replaceInFile.test.js +79 -0
- package/dist/tools/replaceInFile.test.js.map +1 -0
- package/dist/tools/response-builders.d.ts +64 -0
- package/dist/tools/response-builders.js +88 -0
- package/dist/tools/response-builders.js.map +1 -0
- package/dist/tools/search.d.ts +26 -0
- package/dist/tools/search.js +56 -0
- package/dist/tools/search.js.map +1 -0
- package/dist/tools/search.test.d.ts +1 -0
- package/dist/tools/search.test.js +22 -0
- package/dist/tools/search.test.js.map +1 -0
- package/dist/tools/searchFiles.d.ts +32 -0
- package/dist/tools/searchFiles.js +86 -0
- package/dist/tools/searchFiles.js.map +1 -0
- package/dist/tools/todo.d.ts +37 -0
- package/dist/tools/todo.js +41 -0
- package/dist/tools/todo.js.map +1 -0
- package/dist/tools/utils/index.d.ts +1 -0
- package/dist/tools/utils/index.js +2 -0
- package/dist/tools/utils/index.js.map +1 -0
- package/dist/tools/utils/replaceInFile.d.ts +7 -0
- package/dist/tools/utils/replaceInFile.js +133 -0
- package/dist/tools/utils/replaceInFile.js.map +1 -0
- package/dist/tools/utils/replaceInFile.test.d.ts +1 -0
- package/dist/tools/utils/replaceInFile.test.js +308 -0
- package/dist/tools/utils/replaceInFile.test.js.map +1 -0
- package/dist/tools/utils.d.ts +10 -0
- package/dist/tools/utils.js +27 -0
- package/dist/tools/utils.js.map +1 -0
- package/dist/tools/writeToFile.d.ts +29 -0
- package/dist/tools/writeToFile.js +85 -0
- package/dist/tools/writeToFile.js.map +1 -0
- package/dist/tools/writeToFile.test.d.ts +1 -0
- package/dist/tools/writeToFile.test.js +46 -0
- package/dist/tools/writeToFile.test.js.map +1 -0
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.js +3 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/merge.d.ts +26 -0
- package/dist/utils/merge.js +45 -0
- package/dist/utils/merge.js.map +1 -0
- package/dist/workflow/agent.workflow.d.ts +39 -0
- package/dist/workflow/agent.workflow.js +166 -0
- package/dist/workflow/agent.workflow.js.map +1 -0
- package/dist/workflow/agent.workflow.test.d.ts +1 -0
- package/dist/workflow/agent.workflow.test.js +175 -0
- package/dist/workflow/agent.workflow.test.js.map +1 -0
- package/dist/workflow/control-flow.test.d.ts +1 -0
- package/dist/workflow/control-flow.test.js +323 -0
- package/dist/workflow/control-flow.test.js.map +1 -0
- package/dist/workflow/dynamic-edge-cases.test.d.ts +1 -0
- package/dist/workflow/dynamic-edge-cases.test.js +486 -0
- package/dist/workflow/dynamic-edge-cases.test.js.map +1 -0
- package/dist/workflow/dynamic-types.d.ts +124 -0
- package/dist/workflow/dynamic-types.js +105 -0
- package/dist/workflow/dynamic-types.js.map +1 -0
- package/dist/workflow/dynamic.d.ts +118 -0
- package/dist/workflow/dynamic.js +999 -0
- package/dist/workflow/dynamic.js.map +1 -0
- package/dist/workflow/index.d.ts +6 -0
- package/dist/workflow/index.js +8 -0
- package/dist/workflow/index.js.map +1 -0
- package/dist/workflow/json-ai-types.d.ts +122 -0
- package/dist/workflow/json-ai-types.js +144 -0
- package/dist/workflow/json-ai-types.js.map +1 -0
- package/dist/workflow/json-schema-conversion.test.d.ts +1 -0
- package/dist/workflow/json-schema-conversion.test.js +371 -0
- package/dist/workflow/json-schema-conversion.test.js.map +1 -0
- package/dist/workflow/try-catch.test.d.ts +1 -0
- package/dist/workflow/try-catch.test.js +443 -0
- package/dist/workflow/try-catch.test.js.map +1 -0
- package/dist/workflow/types.d.ts +103 -0
- package/dist/workflow/types.js +17 -0
- package/dist/workflow/types.js.map +1 -0
- package/dist/workflow/workflow.d.ts +29 -0
- package/dist/workflow/workflow.js +57 -0
- package/dist/workflow/workflow.js.map +1 -0
- package/dist/workflow/workflow.test.d.ts +1 -0
- package/dist/workflow/workflow.test.js +189 -0
- package/dist/workflow/workflow.test.js.map +1 -0
- 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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,KAAK,IAAI,EAAE;QAClD,MAAM,YAAY,GAAG,IAAI,YAAY,EAAE,CAAA;QACvC,mBAAmB;QACnB,YAAY,CAAC,UAAU,GAAG,SAAS,CAAA;QAEnC,MAAM,MAAM,GAAG,MAAM,UAAU,CAAC,OAAO,CAAC,YAAY,EAAE;YACpD,WAAW,EAAE,UAAU;YACvB,WAAW,EAAE,SAAS;SACvB,CAAC,CAAA;QAEF,oDAAoD;QACpD,MAAM,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC;YACrB,OAAO,EAAE,KAAK;YACd,OAAO,EAAE;gBACP,IAAI,EAAE,YAAY;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,IAAI,EAAE,aAAa;oBACnB,IAAI,EAAE;;;;;;;;;;;;;;;;;;;;;;;;;;gBA0BF;iBACL;aACF;YACD;gBACE,WAAW,EAAE,sDAAsD;gBACnE,KAAK,EAAE;oBACL,IAAI,EAAE,eAAe;oBACrB,IAAI,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
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,iBA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AAM,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;IAEF,IAAI,CAAC,gDAAgD,EAAE,KAAK,IAAI,EAAE;QAChE,CAAC;QAAC,YAAY,CAAC,QAAsB,CAAC,qBAAqB,CAAC,cAAc,CAAC,CAAA;QAC3E,KAAK,CAAC,mBAAmB,EAAE,eAAe,CAAC,CAAC,mBAAmB,CAAC;YAC9D,MAAM,EAAE,kBAAkB;YAC1B,YAAY,EAAE,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"}
|