@mohanscodex/spectra-code 0.4.5 → 0.4.7
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/package.json +1 -1
- package/dist/src/agents/definitions.d.ts +2 -2
- package/dist/src/agents/definitions.d.ts.map +1 -1
- package/dist/src/agents/definitions.js +18 -18
- package/dist/src/agents/definitions.js.map +1 -1
- package/dist/src/agents/registry.d.ts +1 -1
- package/dist/src/agents/registry.d.ts.map +1 -1
- package/dist/src/agents/registry.js.map +1 -1
- package/dist/src/cli.js +117 -115
- package/dist/src/cli.js.map +1 -1
- package/dist/src/commands/agent.d.ts +1 -1
- package/dist/src/commands/agent.d.ts.map +1 -1
- package/dist/src/commands/agent.js +14 -14
- package/dist/src/commands/agent.js.map +1 -1
- package/dist/src/commands/db.d.ts +1 -1
- package/dist/src/commands/db.d.ts.map +1 -1
- package/dist/src/commands/db.js +11 -11
- package/dist/src/commands/db.js.map +1 -1
- package/dist/src/commands/doctor.d.ts.map +1 -1
- package/dist/src/commands/doctor.js +33 -30
- package/dist/src/commands/doctor.js.map +1 -1
- package/dist/src/commands/mcp.d.ts +1 -1
- package/dist/src/commands/mcp.d.ts.map +1 -1
- package/dist/src/commands/mcp.js +39 -39
- package/dist/src/commands/mcp.js.map +1 -1
- package/dist/src/commands/plugin.d.ts +1 -1
- package/dist/src/commands/plugin.d.ts.map +1 -1
- package/dist/src/commands/plugin.js +13 -13
- package/dist/src/commands/plugin.js.map +1 -1
- package/dist/src/commands/session.d.ts +1 -1
- package/dist/src/commands/session.d.ts.map +1 -1
- package/dist/src/commands/session.js +12 -12
- package/dist/src/commands/session.js.map +1 -1
- package/dist/src/index.d.ts +18 -18
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +16 -16
- package/dist/src/index.js.map +1 -1
- package/dist/src/integrations/acp/index.d.ts +1 -1
- package/dist/src/integrations/acp/index.js +1 -1
- package/dist/src/integrations/acp/server.d.ts.map +1 -1
- package/dist/src/integrations/acp/server.js +89 -79
- package/dist/src/integrations/acp/server.js.map +1 -1
- package/dist/src/integrations/custom-tools/index.d.ts +2 -2
- package/dist/src/integrations/custom-tools/index.js +1 -1
- package/dist/src/integrations/custom-tools/loader.d.ts +2 -2
- package/dist/src/integrations/custom-tools/loader.d.ts.map +1 -1
- package/dist/src/integrations/custom-tools/loader.js +19 -18
- package/dist/src/integrations/custom-tools/loader.js.map +1 -1
- package/dist/src/integrations/mcp/client.d.ts +5 -5
- package/dist/src/integrations/mcp/client.d.ts.map +1 -1
- package/dist/src/integrations/mcp/client.js +7 -7
- package/dist/src/integrations/mcp/client.js.map +1 -1
- package/dist/src/integrations/mcp/index.d.ts +2 -2
- package/dist/src/integrations/mcp/index.d.ts.map +1 -1
- package/dist/src/integrations/mcp/index.js +1 -1
- package/dist/src/integrations/mcp/index.js.map +1 -1
- package/dist/src/security/doom-loop.d.ts +1 -1
- package/dist/src/security/doom-loop.d.ts.map +1 -1
- package/dist/src/security/doom-loop.js +4 -4
- package/dist/src/security/doom-loop.js.map +1 -1
- package/dist/src/security/index.d.ts +10 -10
- package/dist/src/security/index.d.ts.map +1 -1
- package/dist/src/security/index.js +116 -69
- package/dist/src/security/index.js.map +1 -1
- package/dist/src/security/path-safety.d.ts +1 -1
- package/dist/src/security/path-safety.d.ts.map +1 -1
- package/dist/src/security/path-safety.js +19 -19
- package/dist/src/security/path-safety.js.map +1 -1
- package/dist/src/security/permissions.d.ts +1 -1
- package/dist/src/security/permissions.d.ts.map +1 -1
- package/dist/src/security/permissions.js +12 -10
- package/dist/src/security/permissions.js.map +1 -1
- package/dist/src/security/read-tracker.d.ts +2 -2
- package/dist/src/security/read-tracker.d.ts.map +1 -1
- package/dist/src/security/read-tracker.js +15 -13
- package/dist/src/security/read-tracker.js.map +1 -1
- package/dist/src/security/ssrf-guard.d.ts +1 -1
- package/dist/src/security/ssrf-guard.d.ts.map +1 -1
- package/dist/src/security/ssrf-guard.js +11 -11
- package/dist/src/security/ssrf-guard.js.map +1 -1
- package/dist/src/security/types.d.ts +4 -4
- package/dist/src/security/types.d.ts.map +1 -1
- package/dist/src/security/wildcard.d.ts.map +1 -1
- package/dist/src/security/wildcard.js +14 -16
- package/dist/src/security/wildcard.js.map +1 -1
- package/dist/src/services/auth-store.d.ts +3 -3
- package/dist/src/services/auth-store.d.ts.map +1 -1
- package/dist/src/services/auth-store.js +7 -7
- package/dist/src/services/auth-store.js.map +1 -1
- package/dist/src/services/config.d.ts +3 -3
- package/dist/src/services/config.d.ts.map +1 -1
- package/dist/src/services/config.js +17 -21
- package/dist/src/services/config.js.map +1 -1
- package/dist/src/services/context.d.ts.map +1 -1
- package/dist/src/services/context.js +5 -8
- package/dist/src/services/context.js.map +1 -1
- package/dist/src/services/custom-providers.d.ts +2 -2
- package/dist/src/services/custom-providers.d.ts.map +1 -1
- package/dist/src/services/custom-providers.js +108 -49
- package/dist/src/services/custom-providers.js.map +1 -1
- package/dist/src/services/session-store.d.ts +1 -1
- package/dist/src/services/session-store.d.ts.map +1 -1
- package/dist/src/services/session-store.js +32 -24
- package/dist/src/services/session-store.js.map +1 -1
- package/dist/src/services/snapshot-manager.d.ts.map +1 -1
- package/dist/src/services/snapshot-manager.js +14 -15
- package/dist/src/services/snapshot-manager.js.map +1 -1
- package/dist/src/tools/edit.d.ts +1 -1
- package/dist/src/tools/edit.js +18 -16
- package/dist/src/tools/edit.js.map +1 -1
- package/dist/src/tools/glob.d.ts +1 -1
- package/dist/src/tools/glob.d.ts.map +1 -1
- package/dist/src/tools/glob.js +20 -16
- package/dist/src/tools/glob.js.map +1 -1
- package/dist/src/tools/grep.d.ts +1 -1
- package/dist/src/tools/grep.d.ts.map +1 -1
- package/dist/src/tools/grep.js +18 -18
- package/dist/src/tools/grep.js.map +1 -1
- package/dist/src/tools/index.d.ts +4 -4
- package/dist/src/tools/index.d.ts.map +1 -1
- package/dist/src/tools/index.js +40 -32
- package/dist/src/tools/index.js.map +1 -1
- package/dist/src/tools/mcp-tool.d.ts +2 -2
- package/dist/src/tools/mcp-tool.d.ts.map +1 -1
- package/dist/src/tools/mcp-tool.js +28 -25
- package/dist/src/tools/mcp-tool.js.map +1 -1
- package/dist/src/tools/read.d.ts +1 -1
- package/dist/src/tools/read.d.ts.map +1 -1
- package/dist/src/tools/read.js +15 -13
- package/dist/src/tools/read.js.map +1 -1
- package/dist/src/tools/shell.d.ts +1 -1
- package/dist/src/tools/shell.d.ts.map +1 -1
- package/dist/src/tools/shell.js +71 -62
- package/dist/src/tools/shell.js.map +1 -1
- package/dist/src/tools/task.d.ts +1 -1
- package/dist/src/tools/task.js +22 -22
- package/dist/src/tools/task.js.map +1 -1
- package/dist/src/tools/types.d.ts +3 -3
- package/dist/src/tools/types.d.ts.map +1 -1
- package/dist/src/tools/utils.d.ts +1 -1
- package/dist/src/tools/utils.js +2 -2
- package/dist/src/tools/utils.js.map +1 -1
- package/dist/src/tools/web-fetch.d.ts +1 -1
- package/dist/src/tools/web-fetch.js +31 -31
- package/dist/src/tools/web-fetch.js.map +1 -1
- package/dist/src/tools/write.d.ts +1 -1
- package/dist/src/tools/write.js +9 -9
- package/dist/src/tools/write.js.map +1 -1
- package/dist/src/tui/app-constants.d.ts.map +1 -1
- package/dist/src/tui/app-constants.js +11 -2
- package/dist/src/tui/app-constants.js.map +1 -1
- package/dist/src/tui/app.d.ts +1 -1
- package/dist/src/tui/app.d.ts.map +1 -1
- package/dist/src/tui/app.js +293 -121
- package/dist/src/tui/app.js.map +1 -1
- package/dist/src/tui/commands.d.ts +14 -14
- package/dist/src/tui/commands.d.ts.map +1 -1
- package/dist/src/tui/commands.js +242 -49
- package/dist/src/tui/commands.js.map +1 -1
- package/dist/src/tui/components/chat-area.d.ts +2 -2
- package/dist/src/tui/components/chat-area.d.ts.map +1 -1
- package/dist/src/tui/components/chat-area.js +5 -5
- package/dist/src/tui/components/chat-area.js.map +1 -1
- package/dist/src/tui/components/command-palette.d.ts.map +1 -1
- package/dist/src/tui/components/command-palette.js +7 -5
- package/dist/src/tui/components/command-palette.js.map +1 -1
- package/dist/src/tui/components/message.d.ts +2 -2
- package/dist/src/tui/components/message.d.ts.map +1 -1
- package/dist/src/tui/components/message.js +63 -50
- package/dist/src/tui/components/message.js.map +1 -1
- package/dist/src/tui/components/slash-autocomplete.d.ts +2 -2
- package/dist/src/tui/components/slash-autocomplete.d.ts.map +1 -1
- package/dist/src/tui/components/slash-autocomplete.js +6 -8
- package/dist/src/tui/components/slash-autocomplete.js.map +1 -1
- package/dist/src/tui/components/toast.d.ts +2 -2
- package/dist/src/tui/components/toast.d.ts.map +1 -1
- package/dist/src/tui/components/toast.js +10 -5
- package/dist/src/tui/components/toast.js.map +1 -1
- package/dist/src/tui/hooks/use-agent.d.ts +3 -3
- package/dist/src/tui/hooks/use-agent.d.ts.map +1 -1
- package/dist/src/tui/hooks/use-agent.js +22 -29
- package/dist/src/tui/hooks/use-agent.js.map +1 -1
- package/dist/src/tui/hooks/use-app-keyboard.d.ts +3 -3
- package/dist/src/tui/hooks/use-app-keyboard.d.ts.map +1 -1
- package/dist/src/tui/hooks/use-app-keyboard.js +28 -29
- package/dist/src/tui/hooks/use-app-keyboard.js.map +1 -1
- package/dist/src/tui/hooks/use-chat-submit.d.ts +6 -6
- package/dist/src/tui/hooks/use-chat-submit.d.ts.map +1 -1
- package/dist/src/tui/hooks/use-chat-submit.js +115 -54
- package/dist/src/tui/hooks/use-chat-submit.js.map +1 -1
- package/dist/src/tui/hooks/use-permission-queue.d.ts +2 -2
- package/dist/src/tui/hooks/use-permission-queue.d.ts.map +1 -1
- package/dist/src/tui/hooks/use-permission-queue.js +1 -1
- package/dist/src/tui/hooks/use-permission-queue.js.map +1 -1
- package/dist/src/tui/hooks/use-revert.d.ts +4 -4
- package/dist/src/tui/hooks/use-revert.d.ts.map +1 -1
- package/dist/src/tui/hooks/use-revert.js +22 -13
- package/dist/src/tui/hooks/use-revert.js.map +1 -1
- package/dist/src/tui/index.d.ts.map +1 -1
- package/dist/src/tui/index.js +11 -11
- package/dist/src/tui/index.js.map +1 -1
- package/dist/src/tui/prompt-bar.d.ts +1 -1
- package/dist/src/tui/prompt-bar.d.ts.map +1 -1
- package/dist/src/tui/prompt-bar.js +14 -11
- package/dist/src/tui/prompt-bar.js.map +1 -1
- package/dist/src/tui/slash-commands.d.ts +2 -2
- package/dist/src/tui/slash-commands.d.ts.map +1 -1
- package/dist/src/tui/slash-commands.js +9 -9
- package/dist/src/tui/slash-commands.js.map +1 -1
- package/dist/src/tui/theme.d.ts +1 -1
- package/dist/src/tui/theme.d.ts.map +1 -1
- package/dist/src/tui/theme.js +46 -38
- package/dist/src/tui/theme.js.map +1 -1
- package/dist/src/tui/tips.d.ts.map +1 -1
- package/dist/src/tui/tips.js +14 -14
- package/dist/src/tui/tips.js.map +1 -1
- package/dist/src/tui/types.d.ts +5 -5
- package/dist/src/tui/types.d.ts.map +1 -1
- package/dist/src/tui/ui/about-dialog.d.ts.map +1 -1
- package/dist/src/tui/ui/about-dialog.js +5 -4
- package/dist/src/tui/ui/about-dialog.js.map +1 -1
- package/dist/src/tui/ui/agent-switcher.d.ts.map +1 -1
- package/dist/src/tui/ui/agent-switcher.js +16 -14
- package/dist/src/tui/ui/agent-switcher.js.map +1 -1
- package/dist/src/tui/ui/debug-dialog.d.ts +1 -1
- package/dist/src/tui/ui/debug-dialog.d.ts.map +1 -1
- package/dist/src/tui/ui/debug-dialog.js +26 -25
- package/dist/src/tui/ui/debug-dialog.js.map +1 -1
- package/dist/src/tui/ui/doctor-dialog.d.ts +2 -2
- package/dist/src/tui/ui/doctor-dialog.d.ts.map +1 -1
- package/dist/src/tui/ui/doctor-dialog.js +10 -8
- package/dist/src/tui/ui/doctor-dialog.js.map +1 -1
- package/dist/src/tui/ui/manage-providers-dialog.d.ts +1 -1
- package/dist/src/tui/ui/manage-providers-dialog.d.ts.map +1 -1
- package/dist/src/tui/ui/manage-providers-dialog.js +102 -86
- package/dist/src/tui/ui/manage-providers-dialog.js.map +1 -1
- package/dist/src/tui/ui/mcp-toggle-dialog.d.ts.map +1 -1
- package/dist/src/tui/ui/mcp-toggle-dialog.js +17 -14
- package/dist/src/tui/ui/mcp-toggle-dialog.js.map +1 -1
- package/dist/src/tui/ui/message-controls.d.ts +1 -1
- package/dist/src/tui/ui/message-controls.d.ts.map +1 -1
- package/dist/src/tui/ui/message-controls.js +40 -28
- package/dist/src/tui/ui/message-controls.js.map +1 -1
- package/dist/src/tui/ui/model-switcher.d.ts.map +1 -1
- package/dist/src/tui/ui/model-switcher.js +40 -25
- package/dist/src/tui/ui/model-switcher.js.map +1 -1
- package/dist/src/tui/ui/permission-dialog.d.ts +1 -1
- package/dist/src/tui/ui/permission-dialog.d.ts.map +1 -1
- package/dist/src/tui/ui/permission-dialog.js +11 -11
- package/dist/src/tui/ui/permission-dialog.js.map +1 -1
- package/dist/src/tui/ui/provider-dialog.d.ts.map +1 -1
- package/dist/src/tui/ui/provider-dialog.js +75 -64
- package/dist/src/tui/ui/provider-dialog.js.map +1 -1
- package/dist/src/tui/ui/session-list.d.ts +3 -3
- package/dist/src/tui/ui/session-list.d.ts.map +1 -1
- package/dist/src/tui/ui/session-list.js +44 -32
- package/dist/src/tui/ui/session-list.js.map +1 -1
- package/dist/src/tui/ui/thinking-effort-dialog.d.ts.map +1 -1
- package/dist/src/tui/ui/thinking-effort-dialog.js +19 -19
- package/dist/src/tui/ui/thinking-effort-dialog.js.map +1 -1
- package/dist/src/tui/utils/model-config.d.ts.map +1 -1
- package/dist/src/tui/utils/model-config.js +13 -13
- package/dist/src/tui/utils/model-config.js.map +1 -1
- package/dist/src/tui/utils/session-messages.d.ts +2 -2
- package/dist/src/tui/utils/session-messages.d.ts.map +1 -1
- package/dist/src/tui/utils/session-messages.js +35 -22
- package/dist/src/tui/utils/session-messages.js.map +1 -1
- package/dist/src/tui/utils/version.d.ts +2 -0
- package/dist/src/tui/utils/version.d.ts.map +1 -0
- package/dist/src/tui/utils/version.js +24 -0
- package/dist/src/tui/utils/version.js.map +1 -0
- package/dist/src/tui/utils.d.ts +2 -2
- package/dist/src/tui/utils.d.ts.map +1 -1
- package/dist/src/tui/utils.js +7 -7
- package/dist/src/tui/utils.js.map +1 -1
- package/dist/src/tui/variant-cycle.d.ts.map +1 -1
- package/dist/src/tui/variant-cycle.js +23 -23
- package/dist/src/tui/variant-cycle.js.map +1 -1
- package/dist/src/utils/paths.d.ts.map +1 -1
- package/dist/src/utils/paths.js +25 -25
- package/dist/src/utils/paths.js.map +1 -1
- package/dist/src/utils/platform.d.ts.map +1 -1
- package/dist/src/utils/platform.js +15 -17
- package/dist/src/utils/platform.js.map +1 -1
- package/package.json +3 -3
package/dist/src/tools/edit.d.ts
CHANGED
package/dist/src/tools/edit.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { z } from
|
|
2
|
-
import { errorResult, textResult } from
|
|
3
|
-
import { readFileSync, writeFileSync, existsSync } from
|
|
4
|
-
import { resolve, relative } from
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { errorResult, textResult } from './utils.js';
|
|
3
|
+
import { readFileSync, writeFileSync, existsSync } from 'fs';
|
|
4
|
+
import { resolve, relative } from 'path';
|
|
5
5
|
export const editTool = {
|
|
6
|
-
name:
|
|
6
|
+
name: 'edit',
|
|
7
7
|
capabilities: { reads: false, writes: true },
|
|
8
8
|
description: `Edit a file by finding and replacing text.
|
|
9
9
|
The tool finds the exact old string in the file and replaces it with the new string.
|
|
@@ -14,16 +14,16 @@ For best results:
|
|
|
14
14
|
Prefer the write tool for large or new files.`,
|
|
15
15
|
displayName: (args) => relative(process.cwd(), resolve(args.path)),
|
|
16
16
|
parameters: z.object({
|
|
17
|
-
path: z.string().describe(
|
|
18
|
-
oldString: z.string().describe(
|
|
19
|
-
newString: z.string().describe(
|
|
17
|
+
path: z.string().describe('Absolute or relative path to the file to edit'),
|
|
18
|
+
oldString: z.string().describe('The exact text to find and replace'),
|
|
19
|
+
newString: z.string().describe('The replacement text'),
|
|
20
20
|
}),
|
|
21
21
|
execute: async ({ path, oldString, newString }) => {
|
|
22
22
|
const resolved = resolve(process.cwd(), path);
|
|
23
23
|
if (!existsSync(resolved)) {
|
|
24
24
|
return errorResult(`File not found: ${resolved}`);
|
|
25
25
|
}
|
|
26
|
-
const content = readFileSync(resolved,
|
|
26
|
+
const content = readFileSync(resolved, 'utf-8');
|
|
27
27
|
if (!content.includes(oldString)) {
|
|
28
28
|
return errorResult(`Could not find the specified text in ${relative(process.cwd(), resolved)}.
|
|
29
29
|
The text may have different whitespace or formatting. Try reading the file first.`);
|
|
@@ -32,7 +32,7 @@ The text may have different whitespace or formatting. Try reading the file first
|
|
|
32
32
|
if (newContent === content) {
|
|
33
33
|
return errorResult("No changes made - the replacement didn't modify the file.");
|
|
34
34
|
}
|
|
35
|
-
writeFileSync(resolved, newContent,
|
|
35
|
+
writeFileSync(resolved, newContent, 'utf-8');
|
|
36
36
|
return textResult(`Applied edit to ${relative(process.cwd(), resolved)}
|
|
37
37
|
|
|
38
38
|
Changes made (showing context):
|
|
@@ -42,16 +42,18 @@ ${showDiff(content, newString, oldString)}`);
|
|
|
42
42
|
function showDiff(original, newStr, oldStr) {
|
|
43
43
|
const idx = original.indexOf(oldStr);
|
|
44
44
|
if (idx < 0)
|
|
45
|
-
return
|
|
45
|
+
return '';
|
|
46
46
|
const before = original.slice(Math.max(0, idx - 40), idx);
|
|
47
47
|
const after = original.slice(idx + oldStr.length, idx + oldStr.length + 40);
|
|
48
48
|
return [
|
|
49
|
-
|
|
50
|
-
before ? `${before}` :
|
|
49
|
+
'...',
|
|
50
|
+
before ? `${before}` : '',
|
|
51
51
|
`- ${oldStr.slice(0, 80)}`,
|
|
52
52
|
`+ ${newStr.slice(0, 80)}`,
|
|
53
|
-
after ? `${after}` :
|
|
54
|
-
|
|
55
|
-
]
|
|
53
|
+
after ? `${after}` : '',
|
|
54
|
+
'...',
|
|
55
|
+
]
|
|
56
|
+
.filter(Boolean)
|
|
57
|
+
.join('\n');
|
|
56
58
|
}
|
|
57
59
|
//# sourceMappingURL=edit.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"edit.js","sourceRoot":"","sources":["../../../src/tools/edit.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AACrD,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,IAAI,CAAC;AAC7D,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,MAAM,CAAC;AAEzC,MAAM,CAAC,MAAM,QAAQ,GAAgB;
|
|
1
|
+
{"version":3,"file":"edit.js","sourceRoot":"","sources":["../../../src/tools/edit.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AACrD,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,IAAI,CAAC;AAC7D,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,MAAM,CAAC;AAEzC,MAAM,CAAC,MAAM,QAAQ,GAAgB;IACpC,IAAI,EAAE,MAAM;IACZ,YAAY,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE;IAC5C,WAAW,EAAE;;;;;;8CAMgC;IAC7C,WAAW,EAAE,CAAC,IAAsB,EAAE,EAAE,CAAC,QAAQ,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACpF,UAAU,EAAE,CAAC,CAAC,MAAM,CAAC;QACpB,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,+CAA+C,CAAC;QAC1E,SAAS,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,oCAAoC,CAAC;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AAE,CAAC;IACvB,MAAM,MAAM,GAAG,QAAQ,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,GAAG,GAAG,EAAE,CAAC,EAAE,GAAG,CAAC,CAAC;IAC1D,MAAM,KAAK,GAAG,QAAQ,CAAC,KAAK,CAAC,GAAG,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,GAAG,MAAM,CAAC,MAAM,GAAG,EAAE,CAAC,CAAC;IAC5E,OAAO;QACN,KAAK;QACL,MAAM,CAAC,CAAC,CAAC,GAAG,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE;QACzB,KAAK,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,EAAE;QAC1B,KAAK,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,EAAE;QAC1B,KAAK,CAAC,CAAC,CAAC,GAAG,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE;QACvB,KAAK;KACL;SACC,MAAM,CAAC,OAAO,CAAC;SACf,IAAI,CAAC,IAAI,CAAC,CAAC;AACd,CAAC"}
|
package/dist/src/tools/glob.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"glob.d.ts","sourceRoot":"","sources":["../../../src/tools/glob.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAK9C,eAAO,MAAM,QAAQ,EAAE,
|
|
1
|
+
{"version":3,"file":"glob.d.ts","sourceRoot":"","sources":["../../../src/tools/glob.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAK9C,eAAO,MAAM,QAAQ,EAAE,WAgDtB,CAAC"}
|
package/dist/src/tools/glob.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { z } from
|
|
2
|
-
import { errorResult, textResult } from
|
|
3
|
-
import { execSync } from
|
|
4
|
-
import { resolve } from
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { errorResult, textResult } from './utils.js';
|
|
3
|
+
import { execSync } from 'child_process';
|
|
4
|
+
import { resolve } from 'path';
|
|
5
5
|
export const globTool = {
|
|
6
|
-
name:
|
|
6
|
+
name: 'glob',
|
|
7
7
|
capabilities: { reads: true, writes: false },
|
|
8
8
|
description: `Find files matching a glob pattern.
|
|
9
9
|
Supports common glob patterns like **/*.ts, src/**/*.css, etc.
|
|
@@ -12,34 +12,38 @@ Results are limited to prevent overwhelming output.`,
|
|
|
12
12
|
displayName: (args) => args.pattern,
|
|
13
13
|
parameters: z.object({
|
|
14
14
|
pattern: z.string().describe("Glob pattern to match files (e.g. '**/*.ts', 'src/**/*.css')"),
|
|
15
|
-
path: z.string().optional().describe(
|
|
16
|
-
maxResults: z.number().optional().describe(
|
|
15
|
+
path: z.string().optional().describe('Directory to search in (defaults to cwd)'),
|
|
16
|
+
maxResults: z.number().optional().describe('Maximum number of results to return'),
|
|
17
17
|
}),
|
|
18
18
|
execute: async ({ pattern, path, maxResults }) => {
|
|
19
19
|
const searchDir = path ? resolve(process.cwd(), path) : process.cwd();
|
|
20
20
|
const limit = maxResults || 100;
|
|
21
21
|
try {
|
|
22
|
-
const hasFd = execSync(
|
|
22
|
+
const hasFd = execSync('which fdfind 2>/dev/null || which fd 2>/dev/null || where fd 2>nul', {
|
|
23
|
+
encoding: 'utf-8',
|
|
24
|
+
timeout: 1000,
|
|
25
|
+
}).trim().length > 0;
|
|
23
26
|
let cmd;
|
|
24
27
|
if (hasFd) {
|
|
25
28
|
cmd = `fd "${pattern}" "${searchDir}" --no-ignore -H 2>/dev/null | head -${limit}`;
|
|
26
29
|
}
|
|
27
30
|
else {
|
|
28
|
-
cmd =
|
|
29
|
-
|
|
30
|
-
|
|
31
|
+
cmd =
|
|
32
|
+
process.platform === 'win32'
|
|
33
|
+
? `powershell -Command "Get-ChildItem -Path '${searchDir}' -Recurse -Filter '${pattern}' -ErrorAction SilentlyContinue | Select-Object -First ${limit} | %% { $_.FullName }"`
|
|
34
|
+
: `find "${searchDir}" -name "${pattern}" 2>/dev/null | head -${limit}`;
|
|
31
35
|
}
|
|
32
|
-
const stdout = execSync(cmd, { encoding:
|
|
36
|
+
const stdout = execSync(cmd, { encoding: 'utf-8', timeout: 15000, maxBuffer: 1024 * 1024 });
|
|
33
37
|
const results = stdout.trim();
|
|
34
38
|
if (!results)
|
|
35
|
-
return textResult(
|
|
36
|
-
const lines = results.split(
|
|
39
|
+
return textResult('No files matched the pattern.');
|
|
40
|
+
const lines = results.split('\n');
|
|
37
41
|
const truncated = lines.length >= limit;
|
|
38
|
-
return textResult(lines.join(
|
|
42
|
+
return textResult(lines.join('\n') + (truncated ? `\n... (${lines.length} results, truncated at ${limit})` : ''));
|
|
39
43
|
}
|
|
40
44
|
catch (err) {
|
|
41
45
|
const error = err;
|
|
42
|
-
return errorResult(`Glob search failed: ${error.message ||
|
|
46
|
+
return errorResult(`Glob search failed: ${error.message || 'unknown error'}`);
|
|
43
47
|
}
|
|
44
48
|
},
|
|
45
49
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"glob.js","sourceRoot":"","sources":["../../../src/tools/glob.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AACrD,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAE/B,MAAM,CAAC,MAAM,QAAQ,GAAgB;
|
|
1
|
+
{"version":3,"file":"glob.js","sourceRoot":"","sources":["../../../src/tools/glob.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AACrD,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,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","sourceRoot":"","sources":["../../../src/tools/grep.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAK9C,eAAO,MAAM,QAAQ,EAAE,WA6CtB,CAAC"}
|
package/dist/src/tools/grep.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { z } from
|
|
2
|
-
import { errorResult, textResult } from
|
|
3
|
-
import { execSync } from
|
|
4
|
-
import { resolve } from
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { errorResult, textResult } from './utils.js';
|
|
3
|
+
import { execSync } from 'child_process';
|
|
4
|
+
import { resolve } from 'path';
|
|
5
5
|
export const grepTool = {
|
|
6
|
-
name:
|
|
6
|
+
name: 'grep',
|
|
7
7
|
capabilities: { reads: true, writes: false },
|
|
8
8
|
description: `Search file contents using regular expressions.
|
|
9
9
|
Uses ripgrep (rg) if available, otherwise falls back to grep.
|
|
@@ -11,39 +11,39 @@ Returns matching file paths, line numbers, and the matched lines.
|
|
|
11
11
|
Results are truncated to prevent large outputs.`,
|
|
12
12
|
displayName: (args) => `"${args.pattern}"`,
|
|
13
13
|
parameters: z.object({
|
|
14
|
-
pattern: z.string().describe(
|
|
14
|
+
pattern: z.string().describe('The regex pattern to search for'),
|
|
15
15
|
include: z.string().optional().describe("File pattern to include (e.g. '*.ts', '*.{ts,js}')"),
|
|
16
|
-
path: z.string().optional().describe(
|
|
17
|
-
maxResults: z.number().optional().describe(
|
|
16
|
+
path: z.string().optional().describe('Directory to search in (defaults to cwd)'),
|
|
17
|
+
maxResults: z.number().optional().describe('Maximum number of results to return'),
|
|
18
18
|
}),
|
|
19
19
|
execute: async ({ pattern, include, path, maxResults }) => {
|
|
20
20
|
const searchDir = path ? resolve(process.cwd(), path) : process.cwd();
|
|
21
21
|
const limit = maxResults || 50;
|
|
22
22
|
try {
|
|
23
23
|
let cmd;
|
|
24
|
-
const useRipgrep = execSync(
|
|
24
|
+
const useRipgrep = execSync('which rg 2>/dev/null || where rg 2>nul', { encoding: 'utf-8', timeout: 1000 }).trim().length > 0;
|
|
25
25
|
if (useRipgrep) {
|
|
26
|
-
const includeFlag = include ? `-g "${include}"` :
|
|
26
|
+
const includeFlag = include ? `-g "${include}"` : '';
|
|
27
27
|
cmd = `rg -n --no-heading "${pattern}" "${searchDir}" ${includeFlag} | head -${limit}`;
|
|
28
28
|
}
|
|
29
29
|
else {
|
|
30
|
-
const includeFlag = include ? `--include="${include}"` :
|
|
30
|
+
const includeFlag = include ? `--include="${include}"` : '';
|
|
31
31
|
cmd = `grep -rn "${pattern}" "${searchDir}" ${includeFlag} 2>/dev/null | head -${limit}`;
|
|
32
32
|
}
|
|
33
|
-
const stdout = execSync(cmd, { encoding:
|
|
33
|
+
const stdout = execSync(cmd, { encoding: 'utf-8', timeout: 15000, maxBuffer: 1024 * 1024 });
|
|
34
34
|
const results = stdout.trim();
|
|
35
35
|
if (!results)
|
|
36
|
-
return textResult(
|
|
37
|
-
const lineCount = results.split(
|
|
36
|
+
return textResult('No matches found.');
|
|
37
|
+
const lineCount = results.split('\n').length;
|
|
38
38
|
const truncated = lineCount >= limit;
|
|
39
|
-
return textResult(results + (truncated ? `\n... (truncated at ${limit} results)` :
|
|
39
|
+
return textResult(results + (truncated ? `\n... (truncated at ${limit} results)` : ''));
|
|
40
40
|
}
|
|
41
41
|
catch (err) {
|
|
42
42
|
const error = err;
|
|
43
|
-
if (error.message?.includes(
|
|
44
|
-
return errorResult(
|
|
43
|
+
if (error.message?.includes('command failed') || error.stderr) {
|
|
44
|
+
return errorResult('No ripgrep or grep found on system, or search failed. Try using glob instead.');
|
|
45
45
|
}
|
|
46
|
-
return errorResult(`Search failed: ${error.message ||
|
|
46
|
+
return errorResult(`Search failed: ${error.message || 'unknown error'}`);
|
|
47
47
|
}
|
|
48
48
|
},
|
|
49
49
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"grep.js","sourceRoot":"","sources":["../../../src/tools/grep.ts"],"names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AAC,CAAC,MAAM,CAAC;YAC7C,MAAM,SAAS,GAAG,SAAS,IAAI,KAAK,CAAC;YACrC,OAAO,UAAU,CAAC,OAAO,GAAG,CAAC,SAAS,CAAC,CAAC,CAAC,uBAAuB,KAAK,WAAW,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;QACzF,CAAC;QAAC,OAAO,GAAY,EAAE,CAAC;YACvB,MAAM,KAAK,GAAG,GAA4C,CAAC;YAC3D,IAAI,KAAK,CAAC,OAAO,EAAE,QAAQ,CAAC,gBAAgB,CAAC,IAAI,KAAK,CAAC,MAAM,EAAE,CAAC;gBAC/D,OAAO,WAAW,CAAC,+EAA+E,CAAC,CAAC;YACrG,CAAC;YACD,OAAO,WAAW,CAAC,kBAAkB,KAAK,CAAC,OAAO,IAAI,eAAe,EAAE,CAAC,CAAC;QAC1E,CAAC;IACF,CAAC;CACD,CAAC"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type { SpectraTool } from
|
|
2
|
-
import type { AgentTool, ToolResult } from
|
|
3
|
-
import type { SecurityManager } from
|
|
4
|
-
export { type SpectraTool } from
|
|
1
|
+
import type { SpectraTool } from './types.js';
|
|
2
|
+
import type { AgentTool, ToolResult } from '@mohanscodex/spectra-agent';
|
|
3
|
+
import type { SecurityManager } from '../security/index.js';
|
|
4
|
+
export { type SpectraTool } from './types.js';
|
|
5
5
|
export declare const builtinTools: SpectraTool[];
|
|
6
6
|
export declare function spectraToolToAgentTool(specTool: SpectraTool, security?: SecurityManager): AgentTool;
|
|
7
7
|
export declare function createAllTools(): SpectraTool[];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/tools/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAS9C,OAAO,KAAK,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAC;AAMxE,OAAO,KAAK,EAAE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B,kBAAkB,CAAC,IAAI,EAAE,WAAW,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,CAAC,EAAE,UAAU,GAAG,MAAM,CAIhG"}
|
package/dist/src/tools/index.js
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import { shellTool } from
|
|
2
|
-
import { readTool } from
|
|
3
|
-
import { writeTool } from
|
|
4
|
-
import { editTool } from
|
|
5
|
-
import { grepTool } from
|
|
6
|
-
import { globTool } from
|
|
7
|
-
import { webFetchTool } from
|
|
8
|
-
import { taskTool } from
|
|
9
|
-
import { defineTool } from
|
|
10
|
-
import { listConnectedServers } from
|
|
11
|
-
import { createMcpAgentTools } from
|
|
12
|
-
import { loadCustomTools } from
|
|
13
|
-
import { PermissionDeniedError } from
|
|
1
|
+
import { shellTool } from './shell.js';
|
|
2
|
+
import { readTool } from './read.js';
|
|
3
|
+
import { writeTool } from './write.js';
|
|
4
|
+
import { editTool } from './edit.js';
|
|
5
|
+
import { grepTool } from './grep.js';
|
|
6
|
+
import { globTool } from './glob.js';
|
|
7
|
+
import { webFetchTool } from './web-fetch.js';
|
|
8
|
+
import { taskTool } from './task.js';
|
|
9
|
+
import { defineTool } from '@mohanscodex/spectra-agent';
|
|
10
|
+
import { listConnectedServers } from '../integrations/mcp/index.js';
|
|
11
|
+
import { createMcpAgentTools } from './mcp-tool.js';
|
|
12
|
+
import { loadCustomTools } from '../integrations/custom-tools/index.js';
|
|
13
|
+
import { PermissionDeniedError } from '../security/index.js';
|
|
14
14
|
export const builtinTools = [
|
|
15
15
|
shellTool,
|
|
16
16
|
readTool,
|
|
@@ -21,24 +21,27 @@ export const builtinTools = [
|
|
|
21
21
|
webFetchTool,
|
|
22
22
|
taskTool,
|
|
23
23
|
];
|
|
24
|
-
const FILE_TOOL_NAMES = new Set([
|
|
24
|
+
const FILE_TOOL_NAMES = new Set(['read', 'write', 'edit', 'grep', 'glob', 'bash', 'shell']);
|
|
25
25
|
function wrapExecute(tool, security) {
|
|
26
26
|
const tracker = security.getReadTracker();
|
|
27
27
|
const doomLoop = security.getDoomLoop();
|
|
28
28
|
return async (args, ctx) => {
|
|
29
29
|
const loopResult = doomLoop.recordToolCall(tool.name, args);
|
|
30
30
|
if (!loopResult.ok) {
|
|
31
|
-
return { content: [{ type:
|
|
31
|
+
return { content: [{ type: 'text', text: loopResult.message }], isError: true };
|
|
32
32
|
}
|
|
33
33
|
const patterns = security.extractToolPatterns(tool.name, args);
|
|
34
34
|
if (FILE_TOOL_NAMES.has(tool.name)) {
|
|
35
35
|
for (const extPath of patterns.externalPaths) {
|
|
36
36
|
try {
|
|
37
|
-
await security.checkPermission(
|
|
37
|
+
await security.checkPermission('external_directory', [extPath], tool.name, extPath);
|
|
38
38
|
}
|
|
39
39
|
catch (err) {
|
|
40
40
|
if (err instanceof PermissionDeniedError) {
|
|
41
|
-
return {
|
|
41
|
+
return {
|
|
42
|
+
content: [{ type: 'text', text: `External file access denied: ${err.message}` }],
|
|
43
|
+
isError: true,
|
|
44
|
+
};
|
|
42
45
|
}
|
|
43
46
|
throw err;
|
|
44
47
|
}
|
|
@@ -50,7 +53,7 @@ function wrapExecute(tool, security) {
|
|
|
50
53
|
}
|
|
51
54
|
catch (err) {
|
|
52
55
|
if (err instanceof PermissionDeniedError) {
|
|
53
|
-
return { content: [{ type:
|
|
56
|
+
return { content: [{ type: 'text', text: `Permission denied: ${err.message}` }], isError: true };
|
|
54
57
|
}
|
|
55
58
|
throw err;
|
|
56
59
|
}
|
|
@@ -61,7 +64,7 @@ function wrapExecute(tool, security) {
|
|
|
61
64
|
}
|
|
62
65
|
catch (err) {
|
|
63
66
|
if (err instanceof PermissionDeniedError) {
|
|
64
|
-
return { content: [{ type:
|
|
67
|
+
return { content: [{ type: 'text', text: `Path safety blocked: ${pathPattern}` }], isError: true };
|
|
65
68
|
}
|
|
66
69
|
throw err;
|
|
67
70
|
}
|
|
@@ -71,16 +74,16 @@ function wrapExecute(tool, security) {
|
|
|
71
74
|
if (caps.writes) {
|
|
72
75
|
const guard = tracker.checkWrite(pathPattern, process.cwd(), tool.name);
|
|
73
76
|
if (!guard.ok) {
|
|
74
|
-
return { content: [{ type:
|
|
77
|
+
return { content: [{ type: 'text', text: guard.reason }], isError: true };
|
|
75
78
|
}
|
|
76
79
|
}
|
|
77
80
|
}
|
|
78
|
-
if (tool.name ===
|
|
81
|
+
if (tool.name === 'web_fetch' || tool.name === 'webfetch') {
|
|
79
82
|
const url = args.url;
|
|
80
83
|
if (url) {
|
|
81
84
|
const ssrfResult = security.getSsrfGuard().check(url);
|
|
82
85
|
if (!ssrfResult.ok) {
|
|
83
|
-
return { content: [{ type:
|
|
86
|
+
return { content: [{ type: 'text', text: `SSRF guard: ${ssrfResult.reason}` }], isError: true };
|
|
84
87
|
}
|
|
85
88
|
}
|
|
86
89
|
}
|
|
@@ -89,14 +92,16 @@ function wrapExecute(tool, security) {
|
|
|
89
92
|
const loopCheck = doomLoop.recordToolResult(tool.name, toolOk);
|
|
90
93
|
if (!loopCheck.ok) {
|
|
91
94
|
const firstContent = result.content?.[0];
|
|
92
|
-
const existingContent = firstContent?.type ===
|
|
95
|
+
const existingContent = firstContent?.type === 'text' ? firstContent.text : '';
|
|
93
96
|
return {
|
|
94
|
-
content: [
|
|
97
|
+
content: [
|
|
98
|
+
{ type: 'text', text: `${existingContent}\n\n<system-reminder>${loopCheck.message}</system-reminder>` },
|
|
99
|
+
],
|
|
95
100
|
isError: result.isError,
|
|
96
101
|
details: result.details,
|
|
97
102
|
};
|
|
98
103
|
}
|
|
99
|
-
if (tool.name ===
|
|
104
|
+
if (tool.name === 'edit' || tool.name === 'patch') {
|
|
100
105
|
if (toolOk) {
|
|
101
106
|
for (const pathPattern of patterns.pathPatterns) {
|
|
102
107
|
doomLoop.recordPatchSuccess(pathPattern);
|
|
@@ -107,10 +112,15 @@ function wrapExecute(tool, security) {
|
|
|
107
112
|
const spiralResult = doomLoop.recordPatchFailure(pathPattern);
|
|
108
113
|
if (!spiralResult.ok) {
|
|
109
114
|
const firstContent = result.content?.[0];
|
|
110
|
-
const text = firstContent?.type ===
|
|
115
|
+
const text = firstContent?.type === 'text' ? firstContent.text : '';
|
|
111
116
|
if (text) {
|
|
112
117
|
return {
|
|
113
|
-
content: [
|
|
118
|
+
content: [
|
|
119
|
+
{
|
|
120
|
+
type: 'text',
|
|
121
|
+
text: `${text}\n\n<system-reminder>${spiralResult.message}</system-reminder>`,
|
|
122
|
+
},
|
|
123
|
+
],
|
|
114
124
|
isError: result.isError,
|
|
115
125
|
details: result.details,
|
|
116
126
|
};
|
|
@@ -131,12 +141,10 @@ function wrapExecute(tool, security) {
|
|
|
131
141
|
};
|
|
132
142
|
}
|
|
133
143
|
export function spectraToolToAgentTool(specTool, security) {
|
|
134
|
-
const execute = security
|
|
135
|
-
? wrapExecute(specTool, security)
|
|
136
|
-
: specTool.execute;
|
|
144
|
+
const execute = security ? wrapExecute(specTool, security) : specTool.execute;
|
|
137
145
|
return defineTool({
|
|
138
146
|
name: specTool.name,
|
|
139
|
-
label: typeof specTool.displayName ===
|
|
147
|
+
label: typeof specTool.displayName === 'string' ? specTool.displayName : undefined,
|
|
140
148
|
description: specTool.description,
|
|
141
149
|
parameters: specTool.parameters,
|
|
142
150
|
promptGuidelines: specTool.promptGuidelines,
|
|
@@ -195,7 +203,7 @@ export function createAllToolsWithSecurity(security) {
|
|
|
195
203
|
export function getToolDisplayName(tool, args, result) {
|
|
196
204
|
if (!tool.displayName)
|
|
197
205
|
return tool.name;
|
|
198
|
-
if (typeof tool.displayName ===
|
|
206
|
+
if (typeof tool.displayName === 'string')
|
|
199
207
|
return tool.displayName;
|
|
200
208
|
return tool.displayName(args, result);
|
|
201
209
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/tools/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AACvC,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,C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type { AgentTool } from '@mohanscodex/spectra-agent';
|
|
2
|
+
import type { Tool as McpToolDefinition } from '@modelcontextprotocol/sdk/types.js';
|
|
3
3
|
export declare function createMcpAgentTool(serverName: string, mcpTool: McpToolDefinition): AgentTool;
|
|
4
4
|
export declare function createMcpAgentTools(serverName: string, tools: McpToolDefinition[]): AgentTool[];
|
|
5
5
|
//# sourceMappingURL=mcp-tool.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mcp-tool.d.ts","sourceRoot":"","sources":["../../../src/tools/mcp-tool.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAc,MAAM,4BAA4B,CAAC;AAExE,OAAO,KAAK,EAAE,IAAI,IAAI,iBAAiB,EAAE,MAAM,oCAAoC,CAAC;
|
|
1
|
+
{"version":3,"file":"mcp-tool.d.ts","sourceRoot":"","sources":["../../../src/tools/mcp-tool.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAc,MAAM,4BAA4B,CAAC;AAExE,OAAO,KAAK,EAAE,IAAI,IAAI,iBAAiB,EAAE,MAAM,oCAAoC,CAAC;AAqFpF,wBAAgB,kBAAkB,CAAC,UAAU,EAAE,MAAM,EAAE,OAAO,EAAE,iBAAiB,GAAG,SAAS,CAmB5F;AAED,wBAAgB,mBAAmB,CAAC,UAAU,EAAE,MAAM,EAAE,KAAK,EAAE,iBAAiB,EAAE,GAAG,SAAS,EAAE,CAE/F"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { z } from
|
|
2
|
-
import { defineTool } from
|
|
3
|
-
import { callMcpTool, formatMcpToolName } from
|
|
4
|
-
import { textResult, errorResult } from
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { defineTool } from '@mohanscodex/spectra-agent';
|
|
3
|
+
import { callMcpTool, formatMcpToolName } from '../integrations/mcp/index.js';
|
|
4
|
+
import { textResult, errorResult } from './utils.js';
|
|
5
5
|
function mcpSchemaToZod(schema) {
|
|
6
6
|
const jsonSchema = schema;
|
|
7
7
|
const properties = jsonSchema.properties ?? {};
|
|
@@ -9,31 +9,34 @@ function mcpSchemaToZod(schema) {
|
|
|
9
9
|
const zodShape = {};
|
|
10
10
|
for (const [key, prop] of Object.entries(properties)) {
|
|
11
11
|
let zodType;
|
|
12
|
-
const propType = prop.type ??
|
|
12
|
+
const propType = prop.type ?? 'string';
|
|
13
13
|
switch (propType) {
|
|
14
|
-
case
|
|
15
|
-
zodType = z.string().describe(prop.description ??
|
|
14
|
+
case 'string':
|
|
15
|
+
zodType = z.string().describe(prop.description ?? '');
|
|
16
16
|
if (prop.enum) {
|
|
17
|
-
zodType = z.enum(prop.enum).describe(prop.description ??
|
|
17
|
+
zodType = z.enum(prop.enum).describe(prop.description ?? '');
|
|
18
18
|
}
|
|
19
19
|
break;
|
|
20
|
-
case
|
|
21
|
-
zodType = z.number().describe(prop.description ??
|
|
20
|
+
case 'number':
|
|
21
|
+
zodType = z.number().describe(prop.description ?? '');
|
|
22
22
|
break;
|
|
23
|
-
case
|
|
24
|
-
zodType = z
|
|
23
|
+
case 'integer':
|
|
24
|
+
zodType = z
|
|
25
|
+
.number()
|
|
26
|
+
.int()
|
|
27
|
+
.describe(prop.description ?? '');
|
|
25
28
|
break;
|
|
26
|
-
case
|
|
27
|
-
zodType = z.boolean().describe(prop.description ??
|
|
29
|
+
case 'boolean':
|
|
30
|
+
zodType = z.boolean().describe(prop.description ?? '');
|
|
28
31
|
break;
|
|
29
|
-
case
|
|
30
|
-
zodType = z.array(z.unknown()).describe(prop.description ??
|
|
32
|
+
case 'array':
|
|
33
|
+
zodType = z.array(z.unknown()).describe(prop.description ?? '');
|
|
31
34
|
break;
|
|
32
|
-
case
|
|
33
|
-
zodType = z.record(z.unknown()).describe(prop.description ??
|
|
35
|
+
case 'object':
|
|
36
|
+
zodType = z.record(z.unknown()).describe(prop.description ?? '');
|
|
34
37
|
break;
|
|
35
38
|
default:
|
|
36
|
-
zodType = z.unknown().describe(prop.description ??
|
|
39
|
+
zodType = z.unknown().describe(prop.description ?? '');
|
|
37
40
|
}
|
|
38
41
|
if (!required.includes(key)) {
|
|
39
42
|
zodType = zodType.optional();
|
|
@@ -45,15 +48,15 @@ function mcpSchemaToZod(schema) {
|
|
|
45
48
|
function extractResultText(result) {
|
|
46
49
|
if (result.isError) {
|
|
47
50
|
const text = result.content
|
|
48
|
-
?.filter((b) => b.type ===
|
|
49
|
-
.map((b) => b.text ??
|
|
50
|
-
.join(
|
|
51
|
+
?.filter((b) => b.type === 'text')
|
|
52
|
+
.map((b) => b.text ?? '')
|
|
53
|
+
.join('\n') || 'Tool execution failed';
|
|
51
54
|
return errorResult(text);
|
|
52
55
|
}
|
|
53
56
|
const text = result.content
|
|
54
|
-
?.filter((b) => b.type ===
|
|
55
|
-
.map((b) => b.text ??
|
|
56
|
-
.join(
|
|
57
|
+
?.filter((b) => b.type === 'text')
|
|
58
|
+
.map((b) => b.text ?? '')
|
|
59
|
+
.join('\n') || '(no output)';
|
|
57
60
|
return textResult(text);
|
|
58
61
|
}
|
|
59
62
|
export function createMcpAgentTool(serverName, mcpTool) {
|