@multiplayer-app/agent 0.0.1
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/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +29 -0
- package/dist/cli.js.map +1 -0
- package/dist/config.d.ts +14 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +36 -0
- package/dist/config.js.map +1 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +10 -0
- package/dist/index.js.map +1 -0
- package/dist/lambda-microvm-entrypoint.d.ts +3 -0
- package/dist/lambda-microvm-entrypoint.d.ts.map +1 -0
- package/dist/lambda-microvm-entrypoint.js +88 -0
- package/dist/lambda-microvm-entrypoint.js.map +1 -0
- package/dist/loop.d.ts +6 -0
- package/dist/loop.d.ts.map +1 -0
- package/dist/loop.js +68 -0
- package/dist/loop.js.map +1 -0
- package/dist/mcp/mcp-client.d.ts +11 -0
- package/dist/mcp/mcp-client.d.ts.map +1 -0
- package/dist/mcp/mcp-client.js +192 -0
- package/dist/mcp/mcp-client.js.map +1 -0
- package/dist/mcp/mcp-connection.d.ts +40 -0
- package/dist/mcp/mcp-connection.d.ts.map +1 -0
- package/dist/mcp/mcp-connection.js +6 -0
- package/dist/mcp/mcp-connection.js.map +1 -0
- package/dist/mcp/mcp-tool-schema.d.ts +25 -0
- package/dist/mcp/mcp-tool-schema.d.ts.map +1 -0
- package/dist/mcp/mcp-tool-schema.js +96 -0
- package/dist/mcp/mcp-tool-schema.js.map +1 -0
- package/dist/mcp/mcp-tools.d.ts +54 -0
- package/dist/mcp/mcp-tools.d.ts.map +1 -0
- package/dist/mcp/mcp-tools.js +115 -0
- package/dist/mcp/mcp-tools.js.map +1 -0
- package/dist/mcp/search-mcp-tools.d.ts +33 -0
- package/dist/mcp/search-mcp-tools.d.ts.map +1 -0
- package/dist/mcp/search-mcp-tools.js +149 -0
- package/dist/mcp/search-mcp-tools.js.map +1 -0
- package/dist/report.d.ts +30 -0
- package/dist/report.d.ts.map +1 -0
- package/dist/report.js +55 -0
- package/dist/report.js.map +1 -0
- package/dist/tools/exec-tools.d.ts +8 -0
- package/dist/tools/exec-tools.d.ts.map +1 -0
- package/dist/tools/exec-tools.js +53 -0
- package/dist/tools/exec-tools.js.map +1 -0
- package/dist/tools/fs-tools.d.ts +30 -0
- package/dist/tools/fs-tools.d.ts.map +1 -0
- package/dist/tools/fs-tools.js +80 -0
- package/dist/tools/fs-tools.js.map +1 -0
- package/package.json +44 -0
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MCP_AUTH_EXPIRED = exports.CALL_RESULT_MAX_BYTES = exports.INPUT_SCHEMA_MAX_BYTES = exports.TOOL_DESCRIPTION_MAX = exports.TOOL_NAME_MAX = exports.MAX_TOOLS = void 0;
|
|
4
|
+
exports.sanitizeInputSchema = sanitizeInputSchema;
|
|
5
|
+
exports.sanitizeDiscoveredTools = sanitizeDiscoveredTools;
|
|
6
|
+
exports.mergeTools = mergeTools;
|
|
7
|
+
exports.mcpErrorMessage = mcpErrorMessage;
|
|
8
|
+
exports.shapeCallToolResult = shapeCallToolResult;
|
|
9
|
+
exports.MAX_TOOLS = 200;
|
|
10
|
+
exports.TOOL_NAME_MAX = 200;
|
|
11
|
+
exports.TOOL_DESCRIPTION_MAX = 500;
|
|
12
|
+
exports.INPUT_SCHEMA_MAX_BYTES = 8 * 1024;
|
|
13
|
+
exports.CALL_RESULT_MAX_BYTES = 32 * 1024;
|
|
14
|
+
exports.MCP_AUTH_EXPIRED = 'MCP server authentication expired. Re-authenticate this connection.';
|
|
15
|
+
function sanitizeInputSchema(schema) {
|
|
16
|
+
if (!schema || typeof schema !== 'object' || Array.isArray(schema))
|
|
17
|
+
return undefined;
|
|
18
|
+
try {
|
|
19
|
+
const serialized = JSON.stringify(schema);
|
|
20
|
+
if (!serialized || serialized.length > exports.INPUT_SCHEMA_MAX_BYTES)
|
|
21
|
+
return undefined;
|
|
22
|
+
return JSON.parse(serialized);
|
|
23
|
+
}
|
|
24
|
+
catch (_a) {
|
|
25
|
+
return undefined;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
function sanitizeDiscoveredTools(tools) {
|
|
29
|
+
const seen = new Set();
|
|
30
|
+
const result = [];
|
|
31
|
+
for (const tool of tools) {
|
|
32
|
+
const name = tool.name.trim().slice(0, exports.TOOL_NAME_MAX);
|
|
33
|
+
if (!name || seen.has(name))
|
|
34
|
+
continue;
|
|
35
|
+
seen.add(name);
|
|
36
|
+
const description = (tool.description || tool.title || '').trim().slice(0, exports.TOOL_DESCRIPTION_MAX);
|
|
37
|
+
result.push({
|
|
38
|
+
name,
|
|
39
|
+
description: description || undefined,
|
|
40
|
+
enabled: true,
|
|
41
|
+
inputSchema: sanitizeInputSchema(tool.inputSchema),
|
|
42
|
+
});
|
|
43
|
+
if (result.length >= exports.MAX_TOOLS)
|
|
44
|
+
break;
|
|
45
|
+
}
|
|
46
|
+
return result;
|
|
47
|
+
}
|
|
48
|
+
function mergeTools(existing, discovered) {
|
|
49
|
+
const previous = new Map((existing !== null && existing !== void 0 ? existing : []).map((tool) => [tool.name, tool]));
|
|
50
|
+
return discovered.map((tool) => {
|
|
51
|
+
var _a, _b;
|
|
52
|
+
return ({
|
|
53
|
+
...tool,
|
|
54
|
+
enabled: (_b = (_a = previous.get(tool.name)) === null || _a === void 0 ? void 0 : _a.enabled) !== null && _b !== void 0 ? _b : true,
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
function mcpErrorMessage(error) {
|
|
59
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
60
|
+
if (message.startsWith('Unauthorized') ||
|
|
61
|
+
message.includes('authentication expired') ||
|
|
62
|
+
message.includes(exports.MCP_AUTH_EXPIRED)) {
|
|
63
|
+
return exports.MCP_AUTH_EXPIRED;
|
|
64
|
+
}
|
|
65
|
+
return message;
|
|
66
|
+
}
|
|
67
|
+
function shapeCallToolResult(result) {
|
|
68
|
+
const parts = [];
|
|
69
|
+
const content = Array.isArray(result.content) ? result.content : [];
|
|
70
|
+
for (const part of content) {
|
|
71
|
+
if (!part || typeof part !== 'object')
|
|
72
|
+
continue;
|
|
73
|
+
const item = part;
|
|
74
|
+
if (item.type === 'text' && typeof item.text === 'string') {
|
|
75
|
+
parts.push(item.text);
|
|
76
|
+
continue;
|
|
77
|
+
}
|
|
78
|
+
if (item.type === 'image' || item.type === 'audio' || item.type === 'resource' || item.type === 'resource_link') {
|
|
79
|
+
parts.push('[binary omitted]');
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
let text = parts.join('\n');
|
|
83
|
+
if (!text && result.structuredContent !== undefined) {
|
|
84
|
+
try {
|
|
85
|
+
text = JSON.stringify(result.structuredContent);
|
|
86
|
+
}
|
|
87
|
+
catch (_a) {
|
|
88
|
+
text = '';
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
if (text.length > exports.CALL_RESULT_MAX_BYTES) {
|
|
92
|
+
text = `${text.slice(0, exports.CALL_RESULT_MAX_BYTES)}…[truncated]`;
|
|
93
|
+
}
|
|
94
|
+
return { isError: Boolean(result.isError), content: text };
|
|
95
|
+
}
|
|
96
|
+
//# sourceMappingURL=mcp-tool-schema.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mcp-tool-schema.js","sourceRoot":"","sources":["../../src/mcp/mcp-tool-schema.ts"],"names":[],"mappings":";;;AAWA,kDASC;AAED,0DAmBC;AAED,gCAMC;AAED,0CAUC;AAED,kDA8BC;AAzFY,QAAA,SAAS,GAAG,GAAG,CAAA;AACf,QAAA,aAAa,GAAG,GAAG,CAAA;AACnB,QAAA,oBAAoB,GAAG,GAAG,CAAA;AAC1B,QAAA,sBAAsB,GAAG,CAAC,GAAG,IAAI,CAAA;AACjC,QAAA,qBAAqB,GAAG,E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builds the three MCP-access tools scoped to this run's connection list (from MCP_SERVERS_JSON). */
|
|
3
|
+
export declare function createMcpTools(connections: McpConnectionRecord[]): {
|
|
4
|
+
search_tools: import("ai").Tool<{
|
|
5
|
+
query?: string | undefined;
|
|
6
|
+
server?: string | undefined;
|
|
7
|
+
detail?: "names" | "names_and_descriptions" | undefined;
|
|
8
|
+
limit?: number | undefined;
|
|
9
|
+
}, import("./search-mcp-tools").McpToolSearchResult>;
|
|
10
|
+
get_tool_details: import("ai").Tool<{
|
|
11
|
+
name: string;
|
|
12
|
+
mcpConnectionId?: string | undefined;
|
|
13
|
+
server?: string | undefined;
|
|
14
|
+
}, {
|
|
15
|
+
isError: boolean;
|
|
16
|
+
message: string;
|
|
17
|
+
server?: undefined;
|
|
18
|
+
name?: undefined;
|
|
19
|
+
description?: undefined;
|
|
20
|
+
inputSchema?: undefined;
|
|
21
|
+
} | {
|
|
22
|
+
isError: boolean;
|
|
23
|
+
server: {
|
|
24
|
+
mcpConnectionId: string;
|
|
25
|
+
name: string;
|
|
26
|
+
};
|
|
27
|
+
name: string;
|
|
28
|
+
description: string | undefined;
|
|
29
|
+
inputSchema: Record<string, unknown>;
|
|
30
|
+
message?: undefined;
|
|
31
|
+
}>;
|
|
32
|
+
call_mcp_tool: import("ai").Tool<{
|
|
33
|
+
name: string;
|
|
34
|
+
mcpConnectionId?: string | undefined;
|
|
35
|
+
server?: string | undefined;
|
|
36
|
+
arguments?: Record<string, unknown> | undefined;
|
|
37
|
+
}, {
|
|
38
|
+
isError: boolean;
|
|
39
|
+
message: string;
|
|
40
|
+
server?: undefined;
|
|
41
|
+
name?: undefined;
|
|
42
|
+
content?: undefined;
|
|
43
|
+
} | {
|
|
44
|
+
isError: boolean;
|
|
45
|
+
server: {
|
|
46
|
+
mcpConnectionId: string;
|
|
47
|
+
name: string;
|
|
48
|
+
};
|
|
49
|
+
name: string;
|
|
50
|
+
content: string;
|
|
51
|
+
message: string | undefined;
|
|
52
|
+
}>;
|
|
53
|
+
};
|
|
54
|
+
//# sourceMappingURL=mcp-tools.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mcp-tools.d.ts","sourceRoot":"","sources":["../../src/mcp/mcp-tools.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAA;AA4B3D,sGAAsG;AACtG,wBAAgB,cAAc,CAAC,WAAW,EAAE,mBAAmB,EAAE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA8EhE"}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createMcpTools = createMcpTools;
|
|
4
|
+
// The three-tool MCP indirection pattern from
|
|
5
|
+
// libs/builder-api/src/agents/automation/automation.tools.ts (search_tools -> get_tool_details
|
|
6
|
+
// -> call_mcp_tool), adapted to resolve against an in-memory connection list instead of a
|
|
7
|
+
// database-backed "attached to this automation" lookup — the env var already hands us the
|
|
8
|
+
// full resolved connection list, so there's nothing to look up.
|
|
9
|
+
const ai_1 = require("ai");
|
|
10
|
+
const zod_1 = require("zod");
|
|
11
|
+
const mcp_client_1 = require("./mcp-client");
|
|
12
|
+
const mcp_tool_schema_1 = require("./mcp-tool-schema");
|
|
13
|
+
const search_mcp_tools_1 = require("./search-mcp-tools");
|
|
14
|
+
function findConnection(connections, toolName, hint) {
|
|
15
|
+
var _a;
|
|
16
|
+
const candidates = connections.filter((connection) => {
|
|
17
|
+
if (hint.mcpConnectionId)
|
|
18
|
+
return connection.mcpConnectionId === hint.mcpConnectionId;
|
|
19
|
+
if (hint.server) {
|
|
20
|
+
const needle = hint.server.trim().toLowerCase();
|
|
21
|
+
if (connection.mcpConnectionId.toLowerCase() !== needle && !connection.name.toLowerCase().includes(needle)) {
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
return connection.enabled && connection.transport === 'remote';
|
|
26
|
+
});
|
|
27
|
+
return (_a = candidates.find((connection) => connection.tools.some((t) => t.name === toolName && t.enabled))) !== null && _a !== void 0 ? _a : candidates[0];
|
|
28
|
+
}
|
|
29
|
+
const mcpToolSelectSchema = zod_1.z.object({
|
|
30
|
+
name: zod_1.z.string().trim().min(1).max(200).describe('Exact MCP tool name from search_tools.'),
|
|
31
|
+
mcpConnectionId: zod_1.z.string().trim().max(24).optional().describe('MCP connection id from search_tools.server.mcpConnectionId.'),
|
|
32
|
+
server: zod_1.z.string().trim().max(100).optional().describe('MCP connection name when it uniquely identifies the server.'),
|
|
33
|
+
});
|
|
34
|
+
/** Builds the three MCP-access tools scoped to this run's connection list (from MCP_SERVERS_JSON). */
|
|
35
|
+
function createMcpTools(connections) {
|
|
36
|
+
const searchToolsTool = (0, ai_1.tool)({
|
|
37
|
+
description: [
|
|
38
|
+
'Search MCP tools available in this session.',
|
|
39
|
+
'Returns matching tool names and brief descriptions grouped by server.',
|
|
40
|
+
'MCP tools are not in your tool list — search first, then get_tool_details, then call_mcp_tool.',
|
|
41
|
+
].join(' '),
|
|
42
|
+
inputSchema: zod_1.z.object({
|
|
43
|
+
query: zod_1.z.string().max(200).optional().describe('Natural-language search. Omit to list servers and tool counts only.'),
|
|
44
|
+
server: zod_1.z.string().max(100).optional().describe('Optional filter: MCP connection name substring or mcpConnectionId.'),
|
|
45
|
+
detail: zod_1.z.enum(['names', 'names_and_descriptions']).optional(),
|
|
46
|
+
limit: zod_1.z.number().int().min(1).max(25).optional(),
|
|
47
|
+
}),
|
|
48
|
+
execute: async (input) => {
|
|
49
|
+
var _a;
|
|
50
|
+
if (connections.length === 0)
|
|
51
|
+
return { total: 0, matches: [], message: 'No MCP connections configured for this session.' };
|
|
52
|
+
const result = (0, search_mcp_tools_1.searchMcpTools)(connections, input);
|
|
53
|
+
if (result.total === 0 && result.matches.length === 0 && !((_a = result.servers) === null || _a === void 0 ? void 0 : _a.length)) {
|
|
54
|
+
return { ...result, message: 'No matching MCP tools. Try a broader query, or omit query to list servers.' };
|
|
55
|
+
}
|
|
56
|
+
return result;
|
|
57
|
+
},
|
|
58
|
+
});
|
|
59
|
+
const getToolDetailsTool = (0, ai_1.tool)({
|
|
60
|
+
description: 'Get the input JSON Schema for one MCP tool available in this session. Call this for the tool you will invoke, after search_tools.',
|
|
61
|
+
inputSchema: mcpToolSelectSchema,
|
|
62
|
+
execute: async (input) => {
|
|
63
|
+
var _a;
|
|
64
|
+
const connection = findConnection(connections, input.name, input);
|
|
65
|
+
if (!connection)
|
|
66
|
+
return { isError: true, message: `No MCP connection has a tool named "${input.name}".` };
|
|
67
|
+
try {
|
|
68
|
+
let match = connection.tools.find((t) => t.name === input.name);
|
|
69
|
+
if (!(match === null || match === void 0 ? void 0 : match.inputSchema)) {
|
|
70
|
+
const discovered = await (0, mcp_client_1.listRemoteTools)(connection);
|
|
71
|
+
connection.tools = (0, mcp_tool_schema_1.mergeTools)(connection.tools, discovered);
|
|
72
|
+
match = (_a = discovered.find((t) => t.name === input.name)) !== null && _a !== void 0 ? _a : match;
|
|
73
|
+
}
|
|
74
|
+
if (!(match === null || match === void 0 ? void 0 : match.inputSchema)) {
|
|
75
|
+
return { isError: true, message: `No input schema available for "${input.name}". Try again.` };
|
|
76
|
+
}
|
|
77
|
+
return {
|
|
78
|
+
isError: false,
|
|
79
|
+
server: { mcpConnectionId: connection.mcpConnectionId, name: connection.name },
|
|
80
|
+
name: match.name,
|
|
81
|
+
description: match.description,
|
|
82
|
+
inputSchema: match.inputSchema,
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
catch (error) {
|
|
86
|
+
return { isError: true, message: (0, mcp_tool_schema_1.mcpErrorMessage)(error) };
|
|
87
|
+
}
|
|
88
|
+
},
|
|
89
|
+
});
|
|
90
|
+
const callMcpToolTool = (0, ai_1.tool)({
|
|
91
|
+
description: [
|
|
92
|
+
'Call one MCP tool available in this session.',
|
|
93
|
+
'Pass the exact name and server from search_tools, and arguments matching get_tool_details.',
|
|
94
|
+
'Only claim the action succeeded when isError is false.',
|
|
95
|
+
].join(' '),
|
|
96
|
+
inputSchema: mcpToolSelectSchema.extend({
|
|
97
|
+
arguments: zod_1.z.record(zod_1.z.string(), zod_1.z.unknown()).optional().describe('Arguments matching the tool inputSchema from get_tool_details.'),
|
|
98
|
+
}),
|
|
99
|
+
execute: async (input) => {
|
|
100
|
+
const connection = findConnection(connections, input.name, input);
|
|
101
|
+
if (!connection)
|
|
102
|
+
return { isError: true, message: `No MCP connection has a tool named "${input.name}".` };
|
|
103
|
+
const result = await (0, mcp_client_1.callRemoteTool)(connection, input.name, input.arguments);
|
|
104
|
+
return {
|
|
105
|
+
isError: result.isError,
|
|
106
|
+
server: { mcpConnectionId: connection.mcpConnectionId, name: connection.name },
|
|
107
|
+
name: input.name,
|
|
108
|
+
content: result.content,
|
|
109
|
+
message: result.isError ? result.content : undefined,
|
|
110
|
+
};
|
|
111
|
+
},
|
|
112
|
+
});
|
|
113
|
+
return { search_tools: searchToolsTool, get_tool_details: getToolDetailsTool, call_mcp_tool: callMcpToolTool };
|
|
114
|
+
}
|
|
115
|
+
//# sourceMappingURL=mcp-tools.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mcp-tools.js","sourceRoot":"","sources":["../../src/mcp/mcp-tools.ts"],"names":[],"mappings":";;AAqCA,wCA8EC;AAnHD,8CAA8C;AAC9C,+FAA+F;AAC/F,0FAA0F;AAC1F,0FAA0F;AAC1F,gEAAgE;AAChE,2BAAyB;AACzB,6BAAuB;AACvB,6CAA8D;AAE9D,uDAA+D;AAC/D,yDAAmD;AAEnD,SAAS,cAAc,CACrB,WAAkC,EAClC,QAAgB,EAChB,IAAmD;;IAEnD,MAAM,UAAU,GAAG,WAAW,CAAC,MAAM,CAAC,CAAC,UAAU,EAAE,EAAE;QACnD,IAAI,IAAI,CAAC,eAAe;YAAE,OAAO,UAAU,CAAC,eAAe,KAAK,IAAI,CAAC,eA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AAC,IAAI,EAAE;gBAC9E,IAAI,EAAE,KAAK,CAAC,IAAI;gBAChB,OAAO,EAAE,MAAM,CAAC,OAAO;gBACvB,OAAO,EAAE,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,SAAS;aACrD,CAAA;QACH,CAAC;KACF,CAAC,CAAA;IAEF,OAAO,EAAE,YAAY,EAAE,eAAe,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,aAAa,EAAE,eAAe,EAAE,CAAA;AAChH,CAAC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { McpConnectionSummary } from './mcp-connection';
|
|
2
|
+
export type McpToolSearchDetail = 'names' | 'names_and_descriptions';
|
|
3
|
+
export interface McpToolSearchInput {
|
|
4
|
+
query?: string;
|
|
5
|
+
server?: string;
|
|
6
|
+
detail?: McpToolSearchDetail;
|
|
7
|
+
limit?: number;
|
|
8
|
+
}
|
|
9
|
+
export interface McpToolSearchMatch {
|
|
10
|
+
server: {
|
|
11
|
+
mcpConnectionId: string;
|
|
12
|
+
name: string;
|
|
13
|
+
};
|
|
14
|
+
tools: Array<{
|
|
15
|
+
name: string;
|
|
16
|
+
description?: string;
|
|
17
|
+
}>;
|
|
18
|
+
}
|
|
19
|
+
export interface McpToolSearchServerSummary {
|
|
20
|
+
mcpConnectionId: string;
|
|
21
|
+
name: string;
|
|
22
|
+
toolCount: number;
|
|
23
|
+
}
|
|
24
|
+
export interface McpToolSearchResult {
|
|
25
|
+
total: number;
|
|
26
|
+
matches: McpToolSearchMatch[];
|
|
27
|
+
servers?: McpToolSearchServerSummary[];
|
|
28
|
+
message?: string;
|
|
29
|
+
}
|
|
30
|
+
export declare function tokenize(text: string): string[];
|
|
31
|
+
export declare function listSearchableServers(connections: McpConnectionSummary[]): McpToolSearchServerSummary[];
|
|
32
|
+
export declare function searchMcpTools(connections: McpConnectionSummary[], input?: McpToolSearchInput): McpToolSearchResult;
|
|
33
|
+
//# s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mB,CA6BrB"}
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.tokenize = tokenize;
|
|
4
|
+
exports.listSearchableServers = listSearchableServers;
|
|
5
|
+
exports.searchMcpTools = searchMcpTools;
|
|
6
|
+
const DEFAULT_LIMIT = 10;
|
|
7
|
+
const MAX_LIMIT = 25;
|
|
8
|
+
function tokenize(text) {
|
|
9
|
+
const split = text
|
|
10
|
+
.replace(/([a-z0-9])([A-Z])/g, '$1 $2')
|
|
11
|
+
.replace(/([A-Z]+)([A-Z][a-z])/g, '$1 $2')
|
|
12
|
+
.toLowerCase();
|
|
13
|
+
const seen = new Set();
|
|
14
|
+
const tokens = [];
|
|
15
|
+
for (const token of split.split(/[^a-z0-9]+/)) {
|
|
16
|
+
if (token.length < 2 || seen.has(token))
|
|
17
|
+
continue;
|
|
18
|
+
seen.add(token);
|
|
19
|
+
tokens.push(token);
|
|
20
|
+
}
|
|
21
|
+
return tokens;
|
|
22
|
+
}
|
|
23
|
+
function enabledRemoteTools(connection) {
|
|
24
|
+
var _a;
|
|
25
|
+
if (!connection.enabled || connection.transport !== 'remote')
|
|
26
|
+
return [];
|
|
27
|
+
return ((_a = connection.tools) !== null && _a !== void 0 ? _a : []).filter((tool) => tool.enabled && tool.name.trim().length > 0);
|
|
28
|
+
}
|
|
29
|
+
function listSearchableServers(connections) {
|
|
30
|
+
return connections.flatMap((connection) => {
|
|
31
|
+
const tools = enabledRemoteTools(connection);
|
|
32
|
+
if (tools.length === 0)
|
|
33
|
+
return [];
|
|
34
|
+
return [{ mcpConnectionId: connection.mcpConnectionId, name: connection.name, toolCount: tools.length }];
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
function matchesServerFilter(connection, server) {
|
|
38
|
+
if (!server)
|
|
39
|
+
return true;
|
|
40
|
+
const needle = server.trim().toLowerCase();
|
|
41
|
+
if (!needle)
|
|
42
|
+
return true;
|
|
43
|
+
if (connection.mcpConnectionId.toLowerCase() === needle)
|
|
44
|
+
return true;
|
|
45
|
+
return connection.name.toLowerCase().includes(needle);
|
|
46
|
+
}
|
|
47
|
+
function catalogTools(connections, server) {
|
|
48
|
+
const tools = [];
|
|
49
|
+
for (const connection of connections) {
|
|
50
|
+
if (!matchesServerFilter(connection, server))
|
|
51
|
+
continue;
|
|
52
|
+
for (const tool of enabledRemoteTools(connection)) {
|
|
53
|
+
tools.push({
|
|
54
|
+
mcpConnectionId: connection.mcpConnectionId,
|
|
55
|
+
serverName: connection.name,
|
|
56
|
+
name: tool.name,
|
|
57
|
+
description: tool.description,
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return tools;
|
|
62
|
+
}
|
|
63
|
+
function tokenScore(token, nameTokens, nameHaystack, serverTokens, serverHaystack, descriptionHaystack) {
|
|
64
|
+
if (nameTokens.includes(token))
|
|
65
|
+
return 10;
|
|
66
|
+
if (nameTokens.some((nameToken) => nameToken.startsWith(token) || nameToken.includes(token)) || nameHaystack.includes(token)) {
|
|
67
|
+
return 6;
|
|
68
|
+
}
|
|
69
|
+
if (serverTokens.includes(token) || serverHaystack.includes(token))
|
|
70
|
+
return 4;
|
|
71
|
+
if (descriptionHaystack.includes(token))
|
|
72
|
+
return 2;
|
|
73
|
+
return 0;
|
|
74
|
+
}
|
|
75
|
+
function scoreTool(tool, queryTokens) {
|
|
76
|
+
var _a;
|
|
77
|
+
const nameTokens = tokenize(tool.name);
|
|
78
|
+
const nameHaystack = tool.name.toLowerCase();
|
|
79
|
+
const serverTokens = tokenize(tool.serverName);
|
|
80
|
+
const serverHaystack = tool.serverName.toLowerCase();
|
|
81
|
+
const descriptionHaystack = ((_a = tool.description) !== null && _a !== void 0 ? _a : '').toLowerCase();
|
|
82
|
+
let score = 0;
|
|
83
|
+
let hits = 0;
|
|
84
|
+
for (const token of queryTokens) {
|
|
85
|
+
const points = tokenScore(token, nameTokens, nameHaystack, serverTokens, serverHaystack, descriptionHaystack);
|
|
86
|
+
if (points > 0)
|
|
87
|
+
hits += 1;
|
|
88
|
+
score += points;
|
|
89
|
+
}
|
|
90
|
+
if (hits === queryTokens.length)
|
|
91
|
+
score += 5;
|
|
92
|
+
return score;
|
|
93
|
+
}
|
|
94
|
+
function clampLimit(limit) {
|
|
95
|
+
if (limit === undefined)
|
|
96
|
+
return DEFAULT_LIMIT;
|
|
97
|
+
return Math.min(MAX_LIMIT, Math.max(1, Math.floor(limit)));
|
|
98
|
+
}
|
|
99
|
+
function toMatchTool(tool, detail) {
|
|
100
|
+
if (detail === 'names')
|
|
101
|
+
return { name: tool.name };
|
|
102
|
+
return { name: tool.name, description: tool.description };
|
|
103
|
+
}
|
|
104
|
+
function groupMatches(tools, detail) {
|
|
105
|
+
const matches = [];
|
|
106
|
+
const indexByServer = new Map();
|
|
107
|
+
for (const tool of tools) {
|
|
108
|
+
const existing = indexByServer.get(tool.mcpConnectionId);
|
|
109
|
+
const mapped = toMatchTool(tool, detail);
|
|
110
|
+
if (existing === undefined) {
|
|
111
|
+
indexByServer.set(tool.mcpConnectionId, matches.length);
|
|
112
|
+
matches.push({
|
|
113
|
+
server: { mcpConnectionId: tool.mcpConnectionId, name: tool.serverName },
|
|
114
|
+
tools: [mapped],
|
|
115
|
+
});
|
|
116
|
+
continue;
|
|
117
|
+
}
|
|
118
|
+
matches[existing].tools.push(mapped);
|
|
119
|
+
}
|
|
120
|
+
return matches;
|
|
121
|
+
}
|
|
122
|
+
function searchMcpTools(connections, input = {}) {
|
|
123
|
+
var _a, _b;
|
|
124
|
+
const detail = input.detail === 'names' ? 'names' : 'names_and_descriptions';
|
|
125
|
+
const limit = clampLimit(input.limit);
|
|
126
|
+
const query = (_b = (_a = input.query) === null || _a === void 0 ? void 0 : _a.trim()) !== null && _b !== void 0 ? _b : '';
|
|
127
|
+
const filteredConnections = connections.filter((connection) => matchesServerFilter(connection, input.server));
|
|
128
|
+
const servers = listSearchableServers(filteredConnections);
|
|
129
|
+
if (!query) {
|
|
130
|
+
const total = servers.reduce((sum, server) => sum + server.toolCount, 0);
|
|
131
|
+
return { total, matches: [], servers };
|
|
132
|
+
}
|
|
133
|
+
const queryTokens = tokenize(query);
|
|
134
|
+
if (queryTokens.length === 0) {
|
|
135
|
+
const total = servers.reduce((sum, server) => sum + server.toolCount, 0);
|
|
136
|
+
return { total, matches: [], servers };
|
|
137
|
+
}
|
|
138
|
+
const ranked = catalogTools(connections, input.server)
|
|
139
|
+
.map((tool) => ({ tool, score: scoreTool(tool, queryTokens) }))
|
|
140
|
+
.filter((entry) => entry.score > 0)
|
|
141
|
+
.sort((a, b) => b.score - a.score || a.tool.name.localeCompare(b.tool.name))
|
|
142
|
+
.slice(0, limit)
|
|
143
|
+
.map((entry) => entry.tool);
|
|
144
|
+
return {
|
|
145
|
+
total: ranked.length,
|
|
146
|
+
matches: groupMatches(ranked, detail),
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
//# sourceMappingURL=search-mcp-tools.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"search-mcp-tools.js","sourceRoot":"","sources":["../../src/mcp/search-mcp-tools.ts"],"names":[],"mappings":";;AAyCA,4BAaC;AAOD,sDAMC;AA0FD,wCAgCC;AAvJD,MAAM,aAAa,GAAG,EAAE,CAAA;AACxB,MAAM,SAAS,GAAG,EAAE,CAAA;AAEpB,SAAgB,QAAQ,CAAC,IAAY;IACnC,MAAM,KAAK,GAAG,IAAI;SACf,OAAO,CAAC,oBAAoB,EAAE,OAAO,CAAC;SACtC,OAAO,CAAC,uBAAuB,EAAE,OAAO,CAAC;SACzC,WAAW,EAAE,CAAA;IAChB,MAAM,IAAI,GAAG,IAAI,GAAG,EAAU,CAAA;IAC9B,MAAM,MAAM,GAAa,EAAE,CAAA;IAC3B,KAAK,MAAM,KAAK,IAAI,KAAK,CAAC,KAAK,CAAC,YAAY,CAAC,EAAE,CAAC;QAC9C,IAAI,KAAK,CAAC,MAAM,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AAC,KAAK,IAAI,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;SAC3E,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC;SACf,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,CAAA;IAE7B,OAAO;QACL,KAAK,EAAE,MAAM,CAAC,MAAM;QACpB,OAAO,EAAE,YAAY,CAAC,MAAM,EAAE,MAAM,CAAC;KACtC,CAAA;AACH,CAAC"}
|
package/dist/report.d.ts
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
export type AgentEvent = {
|
|
2
|
+
type: 'tool_call';
|
|
3
|
+
sessionId: string;
|
|
4
|
+
toolName: string;
|
|
5
|
+
input: unknown;
|
|
6
|
+
output: unknown;
|
|
7
|
+
timestamp: string;
|
|
8
|
+
} | {
|
|
9
|
+
type: 'message';
|
|
10
|
+
sessionId: string;
|
|
11
|
+
text: string;
|
|
12
|
+
timestamp: string;
|
|
13
|
+
} | {
|
|
14
|
+
type: 'done';
|
|
15
|
+
sessionId: string;
|
|
16
|
+
summary: string;
|
|
17
|
+
timestamp: string;
|
|
18
|
+
} | {
|
|
19
|
+
type: 'error';
|
|
20
|
+
sessionId: string;
|
|
21
|
+
message: string;
|
|
22
|
+
timestamp: string;
|
|
23
|
+
};
|
|
24
|
+
export interface Reporter {
|
|
25
|
+
send(event: AgentEvent): Promise<void>;
|
|
26
|
+
/** Call once after the run finishes (success or failure) so the last event can flush. */
|
|
27
|
+
close(): Promise<void>;
|
|
28
|
+
}
|
|
29
|
+
export declare function createReporter(socketUrl: string | undefined, socketToken: string | undefined, sessionId: string): Reporter;
|
|
30
|
+
//# sourceMappingURL=report.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"report.d.ts","sourceRoot":"","sources":["../src/report.ts"],"names":[],"mappings":"AAgBA,MAAM,MAAM,UAAU,GAClB;IAAE,IAAI,EAAE,WAAW,CAAC;IAAC,SAAS,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,OAAO,CAAC;IAAC,MAAM,EAAE,OAAO,CAAC;IAAC,SAAS,EAAE,MAAM,CAAA;CAAE,GAC9G;IAAE,IAAI,EAAE,SAAS,CAAC;IAAC,SAAS,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,MAAM,CAAA;CAAE,GACvE;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,MAAM,CAAA;CAAE,GACvE;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,SAAS,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,MAAM,CAAA;CAAE,CAAA;AAE5E,MAAM,WAAW,QAAQ;IACvB,IAAI,CAAC,KAAK,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;IACtC,yFAAyF;IACzF,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAA;CACvB;AASD,wBAAgB,cAAc,CAC5B,SAAS,EAAE,MAAM,GAAG,SAAS,EAC7B,WAAW,EAAE,MAAM,GAAG,SAAS,EAC/B,SAAS,EAAE,MAAM,GAChB,QAAQ,CA8BV"}
|
package/dist/report.js
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createReporter = createReporter;
|
|
4
|
+
// Reports progress back to the chat UI over a Socket.IO connection to the gateway's
|
|
5
|
+
// agent-socket-server (services/gateway/src/services/agent-socket-server.ts) — not a direct
|
|
6
|
+
// HTTP call to the api. The gateway relays each event onward (io.serverSideEmit over the
|
|
7
|
+
// shared Redis adapter); the api persists it and pushes it live into the chat's socket room.
|
|
8
|
+
// A failed/unavailable connection never fails the run — the agent's actual work (files/
|
|
9
|
+
// commands) already happened; losing a progress update is a lesser problem than aborting a
|
|
10
|
+
// task over a flaky socket.
|
|
11
|
+
const socket_io_client_1 = require("socket.io-client");
|
|
12
|
+
const AGENT_SESSION_EVENT = 'agent-session:event';
|
|
13
|
+
// Grace period before disconnecting in close(), so the last emit (the 'done'/'error' event)
|
|
14
|
+
// actually reaches the gateway before the process exits — socket.io buffers emits made before
|
|
15
|
+
// 'connect' fires, but a bare process.exit() right after send() resolves can still race the
|
|
16
|
+
// underlying write.
|
|
17
|
+
const CLOSE_GRACE_MS = 200;
|
|
18
|
+
const noopReporter = {
|
|
19
|
+
async send(event) {
|
|
20
|
+
console.log('[report]', JSON.stringify(event));
|
|
21
|
+
},
|
|
22
|
+
async close() { },
|
|
23
|
+
};
|
|
24
|
+
function createReporter(socketUrl, socketToken, sessionId) {
|
|
25
|
+
if (!socketUrl)
|
|
26
|
+
return noopReporter;
|
|
27
|
+
let socket;
|
|
28
|
+
let connected;
|
|
29
|
+
function ensureConnected() {
|
|
30
|
+
if (connected)
|
|
31
|
+
return connected;
|
|
32
|
+
socket = (0, socket_io_client_1.io)(socketUrl, { auth: { sessionId, token: socketToken } });
|
|
33
|
+
connected = new Promise((resolve) => {
|
|
34
|
+
socket === null || socket === void 0 ? void 0 : socket.once('connect', () => resolve());
|
|
35
|
+
socket === null || socket === void 0 ? void 0 : socket.once('connect_error', (error) => {
|
|
36
|
+
console.error('[report] socket connect failed:', error.message);
|
|
37
|
+
resolve(); // don't block the run — the emit below will just have nowhere to go
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
return connected;
|
|
41
|
+
}
|
|
42
|
+
return {
|
|
43
|
+
async send(event) {
|
|
44
|
+
await ensureConnected();
|
|
45
|
+
socket === null || socket === void 0 ? void 0 : socket.emit(AGENT_SESSION_EVENT, event);
|
|
46
|
+
},
|
|
47
|
+
async close() {
|
|
48
|
+
if (!socket)
|
|
49
|
+
return;
|
|
50
|
+
await new Promise((resolve) => setTimeout(resolve, CLOSE_GRACE_MS));
|
|
51
|
+
socket.disconnect();
|
|
52
|
+
},
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
//# sourceMappingURL=report.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"report.js","sourceRoot":"","sources":["../src/report.ts"],"names":[],"mappings":";;AAmCA,wCAkCC;AArED,oFAAoF;AACpF,4FAA4F;AAC5F,yFAAyF;AACzF,6FAA6F;AAC7F,wFAAwF;AACxF,2FAA2F;AAC3F,4BAA4B;AAC5B,uDAA8D;AAE9D,MAAM,mBAAmB,GAAG,qBAAqB,CAAA;AACjD,4FAA4F;AAC5F,8FAA8F;AAC9F,4FAA4F;AAC5F,oBAAoB;AACpB,MAAM,cAAc,GAAG,GAAG,CAAA;AAc1B,MAAM,YAAY,GAAa;IAC7B,KAAK,CAAC,IAAI,CAAC,KAAK;QACd,OAAO,CAAC,GAAG,CAAC,UAAU,EAAE,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,CAAA;IAChD,CAAC;IACD,KAAK,CAAC,KAAK,KAAI,CAAC;CACjB,CAAA;AAED,SAAgB,cAAc,CAC5B,SAA6B,EAC7B,WAA+B,EAC/B,SAAiB;IAEjB,IAAI,CAAC,SAAS;QAAE,OAAO,YAAY,CAAA;IAEnC,IAAI,MAA0B,CAAA;IAC9B,IAAI,SAAoC,CAAA;IAExC,SAAS,eAAe;QACtB,IAAI,SAAS;YAAE,OAAO,SAAS,CAAA;QAC/B,MAAM,GAAG,IAAA,qBAAQ,EAAC,SAAS,EAAE,EAAE,IAAI,EAAE,EAAE,SAAS,EAAE,KAAK,EAAE,WAAW,EAAE,EAAE,CAAC,CAAA;QACzE,SAAS,GAAG,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;YAClC,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,IAAI,CAAC,SAAS,EAAE,GAAG,EAAE,CAAC,OAAO,EAAE,CAAC,CAAA;YACxC,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,IAAI,CAAC,eAAe,EAAE,CAAC,KAAY,EAAE,EAAE;gBAC7C,OAAO,CAAC,KAAK,CAAC,iCAAiC,EAAE,KAAK,CAAC,OAAO,CAAC,CAAA;gBAC/D,OAAO,EAAE,CAAA,CAAC,oEAAoE;YAChF,CAAC,CAAC,CAAA;QACJ,CAAC,CAAC,CAAA;QACF,OAAO,SAAS,CAAA;IAClB,CAAC;IAED,OAAO;QACL,KAAK,CAAC,IAAI,CAAC,KAAK;YACd,MAAM,eAAe,EAAE,CAAA;YACvB,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,IAAI,CAAC,mBAAmB,EAAE,KAAK,CAAC,CAAA;QAC1C,CAAC;QACD,KAAK,CAAC,KAAK;YACT,IAAI,CAAC,MAAM;gBAAE,OAAM;YACnB,MAAM,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,cAAc,CAAC,CAAC,CAAA;YACnE,MAAM,CAAC,UAAU,EAAE,CAAA;QACrB,CAAC;KACF,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"exec-tools.d.ts","sourceRoot":"","sources":["../../src/tools/exec-tools.ts"],"names":[],"mappings":"AAeA,wBAAgB,eAAe,CAAC,YAAY,EAAE,MAAM;;;;;;EAqCnD"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.createExecTools = createExecTools;
|
|
7
|
+
// Local equivalent of app-vm.tools.ts's runAppCommandTool — a direct child_process.exec
|
|
8
|
+
// against the workspace, no RPC/session bridge (the agent already runs inside the VM).
|
|
9
|
+
const child_process_1 = require("child_process");
|
|
10
|
+
const path_1 = __importDefault(require("path"));
|
|
11
|
+
const ai_1 = require("ai");
|
|
12
|
+
const zod_1 = require("zod");
|
|
13
|
+
const MAX_OUTPUT_BYTES = 1024 * 1024;
|
|
14
|
+
const DEFAULT_TIMEOUT_MS = 60000;
|
|
15
|
+
function truncate(text) {
|
|
16
|
+
if (Buffer.byteLength(text, 'utf8') <= MAX_OUTPUT_BYTES)
|
|
17
|
+
return { text, truncated: false };
|
|
18
|
+
return { text: `${text.slice(0, MAX_OUTPUT_BYTES)}…[truncated]`, truncated: true };
|
|
19
|
+
}
|
|
20
|
+
function createExecTools(workspaceDir) {
|
|
21
|
+
const runCommandTool = (0, ai_1.tool)({
|
|
22
|
+
description: "Run a shell command inside the session's workspace (npm install, build steps, starting a dev server). Returns exit code and captured output. For a long-lived process (a dev server), background it (e.g. `nohup npm run dev &`) so this call returns promptly — the live preview picks it up once it's listening on $PORT.",
|
|
23
|
+
inputSchema: zod_1.z.object({
|
|
24
|
+
command: zod_1.z.string().min(1).max(4000).describe('Shell command run in the workspace root (or cwd)'),
|
|
25
|
+
cwd: zod_1.z.string().max(500).optional().describe('Workspace-relative working directory'),
|
|
26
|
+
timeoutMs: zod_1.z.number().int().positive().max(300000).optional().describe('Wall-clock limit, default 60000'),
|
|
27
|
+
}),
|
|
28
|
+
execute: async (input) => {
|
|
29
|
+
const cwd = input.cwd ? path_1.default.resolve(workspaceDir, input.cwd) : workspaceDir;
|
|
30
|
+
const startedAt = Date.now();
|
|
31
|
+
return new Promise((resolve) => {
|
|
32
|
+
var _a;
|
|
33
|
+
const child = (0, child_process_1.exec)(input.command, { cwd, timeout: (_a = input.timeoutMs) !== null && _a !== void 0 ? _a : DEFAULT_TIMEOUT_MS, maxBuffer: MAX_OUTPUT_BYTES * 2 }, (error, stdout, stderr) => {
|
|
34
|
+
const durationMs = Date.now() - startedAt;
|
|
35
|
+
const timedOut = Boolean((error === null || error === void 0 ? void 0 : error.killed) && error.signal === 'SIGTERM');
|
|
36
|
+
const out = truncate(stdout);
|
|
37
|
+
const err = truncate(stderr);
|
|
38
|
+
resolve({
|
|
39
|
+
exitCode: error && typeof error.code === 'number' ? error.code : error ? 1 : 0,
|
|
40
|
+
stdout: out.text,
|
|
41
|
+
stderr: err.text,
|
|
42
|
+
durationMs,
|
|
43
|
+
truncated: out.truncated || err.truncated,
|
|
44
|
+
timedOut,
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
void child;
|
|
48
|
+
});
|
|
49
|
+
},
|
|
50
|
+
});
|
|
51
|
+
return { run_command: runCommandTool };
|
|
52
|
+
}
|
|
53
|
+
//# sourceMappingURL=exec-tools.js.map
|