@wingman-ai/gateway 0.2.2 → 0.2.4
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/.wingman/agents/README.md +7 -1
- package/.wingman/agents/coding/agent.md +299 -201
- package/.wingman/agents/coding-v2/agent.md +127 -0
- package/.wingman/agents/coding-v2/implementor.md +89 -0
- package/.wingman/agents/main/agent.md +4 -0
- package/README.md +1 -0
- package/dist/agent/config/agentConfig.cjs +31 -17
- package/dist/agent/config/agentConfig.d.ts +23 -1
- package/dist/agent/config/agentConfig.js +30 -19
- package/dist/agent/config/agentLoader.cjs +26 -8
- package/dist/agent/config/agentLoader.d.ts +4 -2
- package/dist/agent/config/agentLoader.js +26 -8
- package/dist/agent/config/modelFactory.cjs +95 -25
- package/dist/agent/config/modelFactory.d.ts +13 -1
- package/dist/agent/config/modelFactory.js +95 -25
- package/dist/agent/config/toolRegistry.cjs +19 -6
- package/dist/agent/config/toolRegistry.d.ts +5 -2
- package/dist/agent/config/toolRegistry.js +19 -6
- package/dist/agent/middleware/hooks/types.cjs +13 -13
- package/dist/agent/middleware/hooks/types.d.ts +1 -1
- package/dist/agent/middleware/hooks/types.js +14 -14
- package/dist/agent/tests/agentConfig.test.cjs +22 -2
- package/dist/agent/tests/agentConfig.test.js +22 -2
- package/dist/agent/tests/agentLoader.test.cjs +38 -1
- package/dist/agent/tests/agentLoader.test.js +38 -1
- package/dist/agent/tests/backgroundTerminal.test.cjs +70 -0
- package/dist/agent/tests/backgroundTerminal.test.d.ts +1 -0
- package/dist/agent/tests/backgroundTerminal.test.js +64 -0
- package/dist/agent/tests/commandExecuteTool.test.cjs +29 -0
- package/dist/agent/tests/commandExecuteTool.test.d.ts +1 -0
- package/dist/agent/tests/commandExecuteTool.test.js +23 -0
- package/dist/agent/tests/modelFactory.test.cjs +47 -5
- package/dist/agent/tests/modelFactory.test.js +47 -5
- package/dist/agent/tests/terminalSessionManager.test.cjs +121 -0
- package/dist/agent/tests/terminalSessionManager.test.d.ts +1 -0
- package/dist/agent/tests/terminalSessionManager.test.js +115 -0
- package/dist/agent/tests/toolRegistry.test.cjs +14 -2
- package/dist/agent/tests/toolRegistry.test.js +14 -2
- package/dist/agent/tools/background_terminal.cjs +128 -0
- package/dist/agent/tools/background_terminal.d.ts +41 -0
- package/dist/agent/tools/background_terminal.js +94 -0
- package/dist/agent/tools/code_search.cjs +6 -6
- package/dist/agent/tools/code_search.d.ts +1 -1
- package/dist/agent/tools/code_search.js +7 -7
- package/dist/agent/tools/command_execute.cjs +22 -7
- package/dist/agent/tools/command_execute.d.ts +3 -2
- package/dist/agent/tools/command_execute.js +23 -8
- package/dist/agent/tools/git_status.cjs +3 -3
- package/dist/agent/tools/git_status.d.ts +1 -1
- package/dist/agent/tools/git_status.js +4 -4
- package/dist/agent/tools/internet_search.cjs +6 -6
- package/dist/agent/tools/internet_search.d.ts +1 -1
- package/dist/agent/tools/internet_search.js +7 -7
- package/dist/agent/tools/terminal_session_manager.cjs +321 -0
- package/dist/agent/tools/terminal_session_manager.d.ts +77 -0
- package/dist/agent/tools/terminal_session_manager.js +284 -0
- package/dist/agent/tools/think.cjs +4 -4
- package/dist/agent/tools/think.d.ts +1 -1
- package/dist/agent/tools/think.js +5 -5
- package/dist/agent/tools/ui_registry.cjs +13 -13
- package/dist/agent/tools/ui_registry.d.ts +4 -4
- package/dist/agent/tools/ui_registry.js +14 -14
- package/dist/agent/tools/web_crawler.cjs +4 -4
- package/dist/agent/tools/web_crawler.d.ts +1 -1
- package/dist/agent/tools/web_crawler.js +5 -5
- package/dist/agent/utils.cjs +2 -1
- package/dist/agent/utils.js +2 -1
- package/dist/cli/commands/init.cjs +7 -6
- package/dist/cli/commands/init.js +7 -6
- package/dist/cli/commands/provider.cjs +17 -3
- package/dist/cli/commands/provider.js +17 -3
- package/dist/cli/config/loader.cjs +27 -0
- package/dist/cli/config/loader.js +27 -0
- package/dist/cli/config/schema.cjs +146 -68
- package/dist/cli/config/schema.d.ts +89 -1
- package/dist/cli/config/schema.js +134 -68
- package/dist/cli/core/agentInvoker.cjs +344 -17
- package/dist/cli/core/agentInvoker.d.ts +63 -3
- package/dist/cli/core/agentInvoker.js +303 -12
- package/dist/cli/core/sessionManager.cjs +32 -5
- package/dist/cli/core/sessionManager.js +32 -5
- package/dist/cli/core/streamParser.cjs +15 -0
- package/dist/cli/core/streamParser.js +15 -0
- package/dist/cli/index.cjs +6 -5
- package/dist/cli/index.js +6 -5
- package/dist/cli/types.d.ts +32 -0
- package/dist/cli/ui/toolDisplayHelpers.cjs +2 -0
- package/dist/cli/ui/toolDisplayHelpers.js +2 -0
- package/dist/gateway/hooks/registry.cjs +2 -1
- package/dist/gateway/hooks/registry.d.ts +1 -1
- package/dist/gateway/hooks/registry.js +2 -1
- package/dist/gateway/hooks/types.cjs +11 -11
- package/dist/gateway/hooks/types.d.ts +1 -1
- package/dist/gateway/hooks/types.js +12 -12
- package/dist/gateway/http/agents.cjs +67 -4
- package/dist/gateway/http/agents.js +67 -4
- package/dist/gateway/http/sessions.cjs +7 -7
- package/dist/gateway/http/sessions.js +7 -7
- package/dist/gateway/http/types.d.ts +5 -3
- package/dist/gateway/http/webhooks.cjs +6 -5
- package/dist/gateway/http/webhooks.js +6 -5
- package/dist/gateway/server.cjs +198 -41
- package/dist/gateway/server.d.ts +9 -1
- package/dist/gateway/server.js +198 -41
- package/dist/gateway/types.d.ts +1 -0
- package/dist/gateway/validation.cjs +39 -39
- package/dist/gateway/validation.d.ts +1 -1
- package/dist/gateway/validation.js +40 -40
- package/dist/providers/codex.cjs +167 -0
- package/dist/providers/codex.d.ts +15 -0
- package/dist/providers/codex.js +127 -0
- package/dist/providers/credentials.cjs +8 -0
- package/dist/providers/credentials.js +8 -0
- package/dist/providers/registry.cjs +11 -0
- package/dist/providers/registry.d.ts +1 -1
- package/dist/providers/registry.js +11 -0
- package/dist/tests/additionalMessageMiddleware.test.cjs +3 -0
- package/dist/tests/additionalMessageMiddleware.test.js +3 -0
- package/dist/tests/agentInvokerSummarization.test.cjs +455 -0
- package/dist/tests/agentInvokerSummarization.test.d.ts +1 -0
- package/dist/tests/agentInvokerSummarization.test.js +449 -0
- package/dist/tests/agents-api.test.cjs +45 -5
- package/dist/tests/agents-api.test.js +45 -5
- package/dist/tests/cli-config-loader.test.cjs +88 -0
- package/dist/tests/cli-config-loader.test.js +88 -0
- package/dist/tests/cli-init.test.cjs +27 -3
- package/dist/tests/cli-init.test.js +27 -3
- package/dist/tests/codex-credentials-precedence.test.cjs +94 -0
- package/dist/tests/codex-credentials-precedence.test.d.ts +1 -0
- package/dist/tests/codex-credentials-precedence.test.js +88 -0
- package/dist/tests/codex-provider.test.cjs +210 -0
- package/dist/tests/codex-provider.test.d.ts +1 -0
- package/dist/tests/codex-provider.test.js +204 -0
- package/dist/tests/gateway.test.cjs +115 -8
- package/dist/tests/gateway.test.js +115 -8
- package/dist/tests/provider-command-codex.test.cjs +57 -0
- package/dist/tests/provider-command-codex.test.d.ts +1 -0
- package/dist/tests/provider-command-codex.test.js +51 -0
- package/dist/tests/sessionStateMessages.test.cjs +38 -0
- package/dist/tests/sessionStateMessages.test.js +38 -0
- package/dist/tests/toolDisplayHelpers.test.cjs +3 -0
- package/dist/tests/toolDisplayHelpers.test.js +3 -0
- package/dist/tools/mcp-finance.cjs +48 -48
- package/dist/tools/mcp-finance.js +48 -48
- package/dist/types/mcp.cjs +15 -15
- package/dist/types/mcp.d.ts +1 -1
- package/dist/types/mcp.js +16 -16
- package/dist/types/voice.cjs +21 -21
- package/dist/types/voice.d.ts +1 -1
- package/dist/types/voice.js +22 -22
- package/dist/webui/assets/index-DVWQluit.css +11 -0
- package/dist/webui/assets/index-Dlyzwalc.js +270 -0
- package/dist/webui/favicon-32x32.png +0 -0
- package/dist/webui/favicon-64x64.png +0 -0
- package/dist/webui/favicon.webp +0 -0
- package/dist/webui/index.html +4 -2
- package/package.json +13 -12
- package/.wingman/agents/coding/implementor.md +0 -79
- package/dist/webui/assets/index-CPhfGPHc.js +0 -182
- package/dist/webui/assets/index-DDsMIOTX.css +0 -11
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import * as z from "zod";
|
|
2
|
+
import type { TerminalSessionManager, TerminalSessionStatus } from "./terminal_session_manager.js";
|
|
3
|
+
export interface BackgroundTerminalToolOptions {
|
|
4
|
+
workspace: string;
|
|
5
|
+
ownerId: string;
|
|
6
|
+
sessionManager: TerminalSessionManager;
|
|
7
|
+
envVariables?: Record<string, string>;
|
|
8
|
+
blockedCommands?: string[];
|
|
9
|
+
allowScriptExecution?: boolean;
|
|
10
|
+
commandTimeout?: number;
|
|
11
|
+
}
|
|
12
|
+
export declare const createBackgroundTerminalTool: (options: BackgroundTerminalToolOptions) => import("langchain").DynamicStructuredTool<z.ZodObject<{
|
|
13
|
+
command: z.ZodOptional<z.ZodString>;
|
|
14
|
+
session_id: z.ZodOptional<z.ZodString>;
|
|
15
|
+
chars: z.ZodDefault<z.ZodOptional<z.ZodString>>;
|
|
16
|
+
wait_ms: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
|
|
17
|
+
max_output_chars: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
|
|
18
|
+
}, z.core.$strip>, {
|
|
19
|
+
command?: string;
|
|
20
|
+
session_id?: string;
|
|
21
|
+
chars?: string;
|
|
22
|
+
wait_ms?: number;
|
|
23
|
+
max_output_chars?: number;
|
|
24
|
+
}, {
|
|
25
|
+
command?: string | undefined;
|
|
26
|
+
session_id?: string | undefined;
|
|
27
|
+
chars?: string | undefined;
|
|
28
|
+
wait_ms?: number | undefined;
|
|
29
|
+
max_output_chars?: number | undefined;
|
|
30
|
+
}, {
|
|
31
|
+
session_id?: string;
|
|
32
|
+
status?: TerminalSessionStatus;
|
|
33
|
+
output?: string;
|
|
34
|
+
has_more?: boolean;
|
|
35
|
+
exit_code?: number | null;
|
|
36
|
+
signal?: NodeJS.Signals | null;
|
|
37
|
+
command?: string;
|
|
38
|
+
cwd?: string;
|
|
39
|
+
dropped_chars?: number;
|
|
40
|
+
error?: string;
|
|
41
|
+
}, "background_terminal">;
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { tool } from "langchain";
|
|
2
|
+
import { number, object, string } from "zod";
|
|
3
|
+
import { DEFAULT_BLOCKED_COMMANDS } from "./command_execute.js";
|
|
4
|
+
const normalizeCommandParts = (command)=>{
|
|
5
|
+
const commandParts = command.trim().split(/\s+/);
|
|
6
|
+
const commandName = (commandParts[0] || "").toLowerCase();
|
|
7
|
+
return commandName.split(/[\\/]/).pop() || "";
|
|
8
|
+
};
|
|
9
|
+
const isScriptCommand = (command)=>{
|
|
10
|
+
const normalized = command.trim().toLowerCase();
|
|
11
|
+
return normalized.endsWith(".sh") || normalized.endsWith(".bash") || normalized.endsWith(".zsh") || normalized.endsWith(".ps1") || normalized.endsWith(".cmd") || normalized.endsWith(".bat");
|
|
12
|
+
};
|
|
13
|
+
const createSafeEnv = (envVariables)=>{
|
|
14
|
+
const { NODE_OPTIONS, NODE_DEBUG, VSCODE_INSPECTOR_OPTIONS, ...cleanEnv } = process.env;
|
|
15
|
+
return {
|
|
16
|
+
...cleanEnv,
|
|
17
|
+
FORCE_COLOR: "0",
|
|
18
|
+
NO_COLOR: "1",
|
|
19
|
+
GIT_PAGER: "cat",
|
|
20
|
+
...envVariables ?? {}
|
|
21
|
+
};
|
|
22
|
+
};
|
|
23
|
+
const buildTerminalResponse = (payload)=>payload;
|
|
24
|
+
const createBackgroundTerminalTool = (options)=>{
|
|
25
|
+
const { workspace, ownerId, sessionManager, envVariables, blockedCommands = DEFAULT_BLOCKED_COMMANDS, allowScriptExecution = true, commandTimeout = 300000 } = options;
|
|
26
|
+
return tool(async ({ command, session_id, chars, wait_ms, max_output_chars })=>{
|
|
27
|
+
try {
|
|
28
|
+
if (command && session_id) return buildTerminalResponse({
|
|
29
|
+
error: "Provide either command or session_id, not both"
|
|
30
|
+
});
|
|
31
|
+
if (!command && !session_id) return buildTerminalResponse({
|
|
32
|
+
error: "Provide command to start a session or session_id to poll/write"
|
|
33
|
+
});
|
|
34
|
+
let resolvedSessionId = session_id;
|
|
35
|
+
if (command) {
|
|
36
|
+
const baseCommand = normalizeCommandParts(command);
|
|
37
|
+
if (blockedCommands.includes(baseCommand)) return buildTerminalResponse({
|
|
38
|
+
error: `Command "${command}" rejected by blockedCommands policy`
|
|
39
|
+
});
|
|
40
|
+
if (!allowScriptExecution && isScriptCommand(command)) return buildTerminalResponse({
|
|
41
|
+
error: `Command "${command}" rejected because script execution is disabled`
|
|
42
|
+
});
|
|
43
|
+
const session = sessionManager.startSession({
|
|
44
|
+
ownerId,
|
|
45
|
+
command,
|
|
46
|
+
cwd: workspace,
|
|
47
|
+
env: createSafeEnv(envVariables),
|
|
48
|
+
runtimeLimitMs: commandTimeout
|
|
49
|
+
});
|
|
50
|
+
resolvedSessionId = session.sessionId;
|
|
51
|
+
}
|
|
52
|
+
if (!resolvedSessionId) return buildTerminalResponse({
|
|
53
|
+
error: "session_id is required"
|
|
54
|
+
});
|
|
55
|
+
if (chars && chars.length > 0) sessionManager.writeSession({
|
|
56
|
+
ownerId,
|
|
57
|
+
sessionId: resolvedSessionId,
|
|
58
|
+
chars
|
|
59
|
+
});
|
|
60
|
+
const pollResult = await sessionManager.pollSession({
|
|
61
|
+
ownerId,
|
|
62
|
+
sessionId: resolvedSessionId,
|
|
63
|
+
waitMs: wait_ms,
|
|
64
|
+
maxOutputChars: max_output_chars
|
|
65
|
+
});
|
|
66
|
+
return buildTerminalResponse({
|
|
67
|
+
session_id: pollResult.sessionId,
|
|
68
|
+
status: pollResult.status,
|
|
69
|
+
output: pollResult.output,
|
|
70
|
+
has_more: pollResult.hasMore,
|
|
71
|
+
exit_code: pollResult.exitCode,
|
|
72
|
+
signal: pollResult.signal,
|
|
73
|
+
command: pollResult.command,
|
|
74
|
+
cwd: pollResult.cwd,
|
|
75
|
+
dropped_chars: pollResult.droppedChars
|
|
76
|
+
});
|
|
77
|
+
} catch (error) {
|
|
78
|
+
return buildTerminalResponse({
|
|
79
|
+
error: error instanceof Error ? error.message : String(error)
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
}, {
|
|
83
|
+
name: "background_terminal",
|
|
84
|
+
description: "Single background terminal interface for long-running sessions. Use this for commands that may not exit on their own (for example web servers, test watchers, or log tailing). Start a session with command, then poll or write using session_id. Use normal shell commands in-session (for example ps/jobs/kill) and control chars like \\u0003 to interrupt running programs.",
|
|
85
|
+
schema: object({
|
|
86
|
+
command: string().optional().describe("Command to start a new terminal session"),
|
|
87
|
+
session_id: string().optional().describe("Existing terminal session id for poll/write"),
|
|
88
|
+
chars: string().optional().default("").describe("Optional stdin text to write before polling"),
|
|
89
|
+
wait_ms: number().min(0).max(30000).optional().default(1000).describe("How long to wait for output before returning"),
|
|
90
|
+
max_output_chars: number().min(1).max(200000).optional().default(8000).describe("Maximum output characters to return")
|
|
91
|
+
})
|
|
92
|
+
});
|
|
93
|
+
};
|
|
94
|
+
export { createBackgroundTerminalTool };
|
|
@@ -90,12 +90,12 @@ const createCodeSearchTool = (workspace)=>{
|
|
|
90
90
|
}), {
|
|
91
91
|
name: "code_search",
|
|
92
92
|
description: "Search code patterns across the codebase using ripgrep (or grep as fallback). Fast and efficient for finding function definitions, variables, imports, or any text pattern. Returns file paths with line numbers and context.",
|
|
93
|
-
schema: external_zod_namespaceObject.
|
|
94
|
-
pattern: external_zod_namespaceObject.
|
|
95
|
-
path: external_zod_namespaceObject.
|
|
96
|
-
type: external_zod_namespaceObject.
|
|
97
|
-
context: external_zod_namespaceObject.
|
|
98
|
-
caseSensitive: external_zod_namespaceObject.
|
|
93
|
+
schema: external_zod_namespaceObject.object({
|
|
94
|
+
pattern: external_zod_namespaceObject.string().describe("The pattern to search for (regex or literal string). Examples: 'function.*processData', 'import.*React', 'TODO'"),
|
|
95
|
+
path: external_zod_namespaceObject.string().optional().describe("Optional: Directory or file to search in (e.g., 'src/', 'src/utils.ts'). Defaults to the active execution workspace."),
|
|
96
|
+
type: external_zod_namespaceObject.string().optional().describe("Optional: File type filter (e.g., 'ts', 'js', 'py', 'go'). Searches only files of this type."),
|
|
97
|
+
context: external_zod_namespaceObject.number().optional().default(2).describe("Optional: Number of context lines to show around matches. Default is 2."),
|
|
98
|
+
caseSensitive: external_zod_namespaceObject.boolean().optional().default(false).describe("Optional: Whether search should be case-sensitive.")
|
|
99
99
|
})
|
|
100
100
|
});
|
|
101
101
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { tool } from "langchain";
|
|
2
|
-
import {
|
|
2
|
+
import { boolean as external_zod_boolean, number, object, string } from "zod";
|
|
3
3
|
import { execSync, spawn } from "node:child_process";
|
|
4
4
|
function isRipgrepAvailable() {
|
|
5
5
|
try {
|
|
@@ -62,12 +62,12 @@ const createCodeSearchTool = (workspace)=>{
|
|
|
62
62
|
}), {
|
|
63
63
|
name: "code_search",
|
|
64
64
|
description: "Search code patterns across the codebase using ripgrep (or grep as fallback). Fast and efficient for finding function definitions, variables, imports, or any text pattern. Returns file paths with line numbers and context.",
|
|
65
|
-
schema:
|
|
66
|
-
pattern:
|
|
67
|
-
path:
|
|
68
|
-
type:
|
|
69
|
-
context:
|
|
70
|
-
caseSensitive:
|
|
65
|
+
schema: object({
|
|
66
|
+
pattern: string().describe("The pattern to search for (regex or literal string). Examples: 'function.*processData', 'import.*React', 'TODO'"),
|
|
67
|
+
path: string().optional().describe("Optional: Directory or file to search in (e.g., 'src/', 'src/utils.ts'). Defaults to the active execution workspace."),
|
|
68
|
+
type: string().optional().describe("Optional: File type filter (e.g., 'ts', 'js', 'py', 'go'). Searches only files of this type."),
|
|
69
|
+
context: number().optional().default(2).describe("Optional: Number of context lines to show around matches. Default is 2."),
|
|
70
|
+
caseSensitive: external_zod_boolean().optional().default(false).describe("Optional: Whether search should be case-sensitive.")
|
|
71
71
|
})
|
|
72
72
|
});
|
|
73
73
|
};
|
|
@@ -27,9 +27,9 @@ __webpack_require__.d(__webpack_exports__, {
|
|
|
27
27
|
createCommandExecuteTool: ()=>createCommandExecuteTool,
|
|
28
28
|
DEFAULT_BLOCKED_COMMANDS: ()=>DEFAULT_BLOCKED_COMMANDS
|
|
29
29
|
});
|
|
30
|
+
const external_node_child_process_namespaceObject = require("node:child_process");
|
|
30
31
|
const external_langchain_namespaceObject = require("langchain");
|
|
31
32
|
const external_zod_namespaceObject = require("zod");
|
|
32
|
-
const external_node_child_process_namespaceObject = require("node:child_process");
|
|
33
33
|
const DEFAULT_BLOCKED_COMMANDS = [
|
|
34
34
|
"rm",
|
|
35
35
|
"remove",
|
|
@@ -48,7 +48,22 @@ const DEFAULT_BLOCKED_COMMANDS = [
|
|
|
48
48
|
"sudo",
|
|
49
49
|
"su"
|
|
50
50
|
];
|
|
51
|
-
const
|
|
51
|
+
const DEFAULT_MAX_OUTPUT_CHARS = 200000;
|
|
52
|
+
const TRUNCATION_HEAD_CHARS = 120000;
|
|
53
|
+
const TRUNCATION_TAIL_CHARS = 80000;
|
|
54
|
+
function appendCommandOutput(existing, incoming, maxChars) {
|
|
55
|
+
if (!incoming) return existing;
|
|
56
|
+
if (maxChars <= 0) return "";
|
|
57
|
+
const combined = existing + incoming;
|
|
58
|
+
if (combined.length <= maxChars) return combined;
|
|
59
|
+
const headBudget = Math.min(TRUNCATION_HEAD_CHARS, Math.floor(0.6 * maxChars));
|
|
60
|
+
const tailBudget = Math.min(TRUNCATION_TAIL_CHARS, Math.max(0, maxChars - headBudget));
|
|
61
|
+
const head = combined.slice(0, headBudget);
|
|
62
|
+
const tail = tailBudget > 0 ? combined.slice(-tailBudget) : "";
|
|
63
|
+
const omitted = Math.max(0, combined.length - head.length - tail.length);
|
|
64
|
+
return `${head}\n\n[output truncated: omitted ${omitted} chars]\n\n${tail}`;
|
|
65
|
+
}
|
|
66
|
+
const createCommandExecuteTool = (workspace, envVariables, blockedCommands = DEFAULT_BLOCKED_COMMANDS, allowScriptExecution = true, timeoutInMilliseconds = 300000, maxOutputChars = DEFAULT_MAX_OUTPUT_CHARS)=>(0, external_langchain_namespaceObject.tool)(async ({ command })=>new Promise((resolve)=>{
|
|
52
67
|
try {
|
|
53
68
|
const commandParts = command.trim().split(/\s+/);
|
|
54
69
|
const commandName = (commandParts[0] || "").toLowerCase();
|
|
@@ -89,7 +104,7 @@ const createCommandExecuteTool = (workspace, envVariables, blockedCommands = DEF
|
|
|
89
104
|
hasExited = true;
|
|
90
105
|
try {
|
|
91
106
|
terminalProcess.kill();
|
|
92
|
-
} catch
|
|
107
|
+
} catch {}
|
|
93
108
|
const result = `Command: "${command}" timed out after ${timeoutInMilliseconds / 1000} seconds`;
|
|
94
109
|
resolve(result);
|
|
95
110
|
}
|
|
@@ -103,10 +118,10 @@ const createCommandExecuteTool = (workspace, envVariables, blockedCommands = DEF
|
|
|
103
118
|
}
|
|
104
119
|
};
|
|
105
120
|
terminalProcess.stdout?.on("data", (data)=>{
|
|
106
|
-
output
|
|
121
|
+
output = appendCommandOutput(output, data.toString(), maxOutputChars);
|
|
107
122
|
});
|
|
108
123
|
terminalProcess.stderr?.on("data", (data)=>{
|
|
109
|
-
output
|
|
124
|
+
output = appendCommandOutput(output, data.toString(), maxOutputChars);
|
|
110
125
|
});
|
|
111
126
|
terminalProcess.on("error", (err)=>{
|
|
112
127
|
resolveResponse(err.message, true);
|
|
@@ -121,8 +136,8 @@ const createCommandExecuteTool = (workspace, envVariables, blockedCommands = DEF
|
|
|
121
136
|
}), {
|
|
122
137
|
name: "command_execute",
|
|
123
138
|
description: "Executes a command in a terminal and reports the output. Cannot execute potentially destructive commands like rm, mv, chmod, sudo, etc. Use for safe operations like running tests, builds, or other validation commands. Do not run long-running commands like dev servers. Commands run with a timeout in the active execution workspace context.",
|
|
124
|
-
schema: external_zod_namespaceObject.
|
|
125
|
-
command: external_zod_namespaceObject.
|
|
139
|
+
schema: external_zod_namespaceObject.object({
|
|
140
|
+
command: external_zod_namespaceObject.string().describe("The command to execute in the terminal")
|
|
126
141
|
})
|
|
127
142
|
});
|
|
128
143
|
exports.DEFAULT_BLOCKED_COMMANDS = __webpack_exports__.DEFAULT_BLOCKED_COMMANDS;
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import
|
|
1
|
+
import * as z from "zod";
|
|
2
2
|
export declare const DEFAULT_BLOCKED_COMMANDS: string[];
|
|
3
3
|
/**
|
|
4
4
|
* Creates a tool that executes terminal commands safely
|
|
5
5
|
*/
|
|
6
|
-
export declare const createCommandExecuteTool: (workspace: string, envVariables?: Record<string, string>, blockedCommands?: string[], allowScriptExecution?: boolean, timeoutInMilliseconds?: number
|
|
6
|
+
export declare const createCommandExecuteTool: (workspace: string, envVariables?: Record<string, string>, blockedCommands?: string[], allowScriptExecution?: boolean, timeoutInMilliseconds?: number, // Default timeout of 5 minutes
|
|
7
|
+
maxOutputChars?: number) => import("langchain").DynamicStructuredTool<z.ZodObject<{
|
|
7
8
|
command: z.ZodString;
|
|
8
9
|
}, z.core.$strip>, {
|
|
9
10
|
command: string;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { tool } from "langchain";
|
|
2
|
-
import { z } from "zod";
|
|
3
1
|
import { spawn } from "node:child_process";
|
|
2
|
+
import { tool } from "langchain";
|
|
3
|
+
import { object, string } from "zod";
|
|
4
4
|
const DEFAULT_BLOCKED_COMMANDS = [
|
|
5
5
|
"rm",
|
|
6
6
|
"remove",
|
|
@@ -19,7 +19,22 @@ const DEFAULT_BLOCKED_COMMANDS = [
|
|
|
19
19
|
"sudo",
|
|
20
20
|
"su"
|
|
21
21
|
];
|
|
22
|
-
const
|
|
22
|
+
const DEFAULT_MAX_OUTPUT_CHARS = 200000;
|
|
23
|
+
const TRUNCATION_HEAD_CHARS = 120000;
|
|
24
|
+
const TRUNCATION_TAIL_CHARS = 80000;
|
|
25
|
+
function appendCommandOutput(existing, incoming, maxChars) {
|
|
26
|
+
if (!incoming) return existing;
|
|
27
|
+
if (maxChars <= 0) return "";
|
|
28
|
+
const combined = existing + incoming;
|
|
29
|
+
if (combined.length <= maxChars) return combined;
|
|
30
|
+
const headBudget = Math.min(TRUNCATION_HEAD_CHARS, Math.floor(0.6 * maxChars));
|
|
31
|
+
const tailBudget = Math.min(TRUNCATION_TAIL_CHARS, Math.max(0, maxChars - headBudget));
|
|
32
|
+
const head = combined.slice(0, headBudget);
|
|
33
|
+
const tail = tailBudget > 0 ? combined.slice(-tailBudget) : "";
|
|
34
|
+
const omitted = Math.max(0, combined.length - head.length - tail.length);
|
|
35
|
+
return `${head}\n\n[output truncated: omitted ${omitted} chars]\n\n${tail}`;
|
|
36
|
+
}
|
|
37
|
+
const createCommandExecuteTool = (workspace, envVariables, blockedCommands = DEFAULT_BLOCKED_COMMANDS, allowScriptExecution = true, timeoutInMilliseconds = 300000, maxOutputChars = DEFAULT_MAX_OUTPUT_CHARS)=>tool(async ({ command })=>new Promise((resolve)=>{
|
|
23
38
|
try {
|
|
24
39
|
const commandParts = command.trim().split(/\s+/);
|
|
25
40
|
const commandName = (commandParts[0] || "").toLowerCase();
|
|
@@ -60,7 +75,7 @@ const createCommandExecuteTool = (workspace, envVariables, blockedCommands = DEF
|
|
|
60
75
|
hasExited = true;
|
|
61
76
|
try {
|
|
62
77
|
terminalProcess.kill();
|
|
63
|
-
} catch
|
|
78
|
+
} catch {}
|
|
64
79
|
const result = `Command: "${command}" timed out after ${timeoutInMilliseconds / 1000} seconds`;
|
|
65
80
|
resolve(result);
|
|
66
81
|
}
|
|
@@ -74,10 +89,10 @@ const createCommandExecuteTool = (workspace, envVariables, blockedCommands = DEF
|
|
|
74
89
|
}
|
|
75
90
|
};
|
|
76
91
|
terminalProcess.stdout?.on("data", (data)=>{
|
|
77
|
-
output
|
|
92
|
+
output = appendCommandOutput(output, data.toString(), maxOutputChars);
|
|
78
93
|
});
|
|
79
94
|
terminalProcess.stderr?.on("data", (data)=>{
|
|
80
|
-
output
|
|
95
|
+
output = appendCommandOutput(output, data.toString(), maxOutputChars);
|
|
81
96
|
});
|
|
82
97
|
terminalProcess.on("error", (err)=>{
|
|
83
98
|
resolveResponse(err.message, true);
|
|
@@ -92,8 +107,8 @@ const createCommandExecuteTool = (workspace, envVariables, blockedCommands = DEF
|
|
|
92
107
|
}), {
|
|
93
108
|
name: "command_execute",
|
|
94
109
|
description: "Executes a command in a terminal and reports the output. Cannot execute potentially destructive commands like rm, mv, chmod, sudo, etc. Use for safe operations like running tests, builds, or other validation commands. Do not run long-running commands like dev servers. Commands run with a timeout in the active execution workspace context.",
|
|
95
|
-
schema:
|
|
96
|
-
command:
|
|
110
|
+
schema: object({
|
|
111
|
+
command: string().describe("The command to execute in the terminal")
|
|
97
112
|
})
|
|
98
113
|
});
|
|
99
114
|
export { DEFAULT_BLOCKED_COMMANDS, createCommandExecuteTool };
|
|
@@ -112,9 +112,9 @@ const createGitStatusTool = (workspace)=>(0, external_langchain_namespaceObject.
|
|
|
112
112
|
}), {
|
|
113
113
|
name: "git_status",
|
|
114
114
|
description: "Get current git repository status including uncommitted changes, current branch, and optionally diff statistics. Read-only operation that helps understand the state before making changes.",
|
|
115
|
-
schema: external_zod_namespaceObject.
|
|
116
|
-
includeDiff: external_zod_namespaceObject.
|
|
117
|
-
includeStaged: external_zod_namespaceObject.
|
|
115
|
+
schema: external_zod_namespaceObject.object({
|
|
116
|
+
includeDiff: external_zod_namespaceObject.boolean().optional().default(false).describe("Optional: Include summary of unstaged changes (diff --stat). Useful for understanding what has changed."),
|
|
117
|
+
includeStaged: external_zod_namespaceObject.boolean().optional().default(false).describe("Optional: Include summary of staged changes (diff --cached --stat). Shows what will be committed.")
|
|
118
118
|
})
|
|
119
119
|
});
|
|
120
120
|
exports.createGitStatusTool = __webpack_exports__.createGitStatusTool;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { tool } from "langchain";
|
|
2
|
-
import {
|
|
2
|
+
import { boolean as external_zod_boolean, object } from "zod";
|
|
3
3
|
import { spawn } from "node:child_process";
|
|
4
4
|
const createGitStatusTool = (workspace)=>tool(async ({ includeDiff = false, includeStaged = false })=>new Promise((resolve)=>{
|
|
5
5
|
try {
|
|
@@ -84,9 +84,9 @@ const createGitStatusTool = (workspace)=>tool(async ({ includeDiff = false, incl
|
|
|
84
84
|
}), {
|
|
85
85
|
name: "git_status",
|
|
86
86
|
description: "Get current git repository status including uncommitted changes, current branch, and optionally diff statistics. Read-only operation that helps understand the state before making changes.",
|
|
87
|
-
schema:
|
|
88
|
-
includeDiff:
|
|
89
|
-
includeStaged:
|
|
87
|
+
schema: object({
|
|
88
|
+
includeDiff: external_zod_boolean().optional().default(false).describe("Optional: Include summary of unstaged changes (diff --stat). Useful for understanding what has changed."),
|
|
89
|
+
includeStaged: external_zod_boolean().optional().default(false).describe("Optional: Include summary of staged changes (diff --cached --stat). Shows what will be committed.")
|
|
90
90
|
})
|
|
91
91
|
});
|
|
92
92
|
export { createGitStatusTool };
|
|
@@ -130,9 +130,9 @@ function createDuckDuckGoTool(maxResults) {
|
|
|
130
130
|
}, {
|
|
131
131
|
name: "internet_search",
|
|
132
132
|
description: "Run a web search using DuckDuckGo",
|
|
133
|
-
schema: external_zod_namespaceObject.
|
|
134
|
-
query: external_zod_namespaceObject.
|
|
135
|
-
maxResults: external_zod_namespaceObject.
|
|
133
|
+
schema: external_zod_namespaceObject.object({
|
|
134
|
+
query: external_zod_namespaceObject.string().describe("The search query"),
|
|
135
|
+
maxResults: external_zod_namespaceObject.number().optional().default(maxResults).describe("Maximum number of results to return")
|
|
136
136
|
})
|
|
137
137
|
});
|
|
138
138
|
}
|
|
@@ -154,9 +154,9 @@ function createPerplexityTool(maxResults) {
|
|
|
154
154
|
}, {
|
|
155
155
|
name: "internet_search",
|
|
156
156
|
description: "Run a web search using Perplexity Sonar with built-in citations",
|
|
157
|
-
schema: external_zod_namespaceObject.
|
|
158
|
-
query: external_zod_namespaceObject.
|
|
159
|
-
maxResults: external_zod_namespaceObject.
|
|
157
|
+
schema: external_zod_namespaceObject.object({
|
|
158
|
+
query: external_zod_namespaceObject.string().describe("The search query"),
|
|
159
|
+
maxResults: external_zod_namespaceObject.number().optional().default(maxResults).describe("Maximum number of results to return")
|
|
160
160
|
})
|
|
161
161
|
});
|
|
162
162
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { tool } from "langchain";
|
|
2
2
|
import { DuckDuckGoSearch } from "@langchain/community/tools/duckduckgo_search";
|
|
3
3
|
import { ChatOpenAI } from "@langchain/openai";
|
|
4
|
-
import {
|
|
4
|
+
import { number, object, string } from "zod";
|
|
5
5
|
function _define_property(obj, key, value) {
|
|
6
6
|
if (key in obj) Object.defineProperty(obj, key, {
|
|
7
7
|
value: value,
|
|
@@ -101,9 +101,9 @@ function createDuckDuckGoTool(maxResults) {
|
|
|
101
101
|
}, {
|
|
102
102
|
name: "internet_search",
|
|
103
103
|
description: "Run a web search using DuckDuckGo",
|
|
104
|
-
schema:
|
|
105
|
-
query:
|
|
106
|
-
maxResults:
|
|
104
|
+
schema: object({
|
|
105
|
+
query: string().describe("The search query"),
|
|
106
|
+
maxResults: number().optional().default(maxResults).describe("Maximum number of results to return")
|
|
107
107
|
})
|
|
108
108
|
});
|
|
109
109
|
}
|
|
@@ -125,9 +125,9 @@ function createPerplexityTool(maxResults) {
|
|
|
125
125
|
}, {
|
|
126
126
|
name: "internet_search",
|
|
127
127
|
description: "Run a web search using Perplexity Sonar with built-in citations",
|
|
128
|
-
schema:
|
|
129
|
-
query:
|
|
130
|
-
maxResults:
|
|
128
|
+
schema: object({
|
|
129
|
+
query: string().describe("The search query"),
|
|
130
|
+
maxResults: number().optional().default(maxResults).describe("Maximum number of results to return")
|
|
131
131
|
})
|
|
132
132
|
});
|
|
133
133
|
}
|