@nodetool-ai/agents 0.7.0-rc.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/agent-executor.d.ts +62 -0
- package/dist/agent-executor.d.ts.map +1 -0
- package/dist/agent-executor.js +324 -0
- package/dist/agent-executor.js.map +1 -0
- package/dist/agent-step-executor.d.ts +28 -0
- package/dist/agent-step-executor.d.ts.map +1 -0
- package/dist/agent-step-executor.js +99 -0
- package/dist/agent-step-executor.js.map +1 -0
- package/dist/agent-workflow-runner.d.ts +31 -0
- package/dist/agent-workflow-runner.d.ts.map +1 -0
- package/dist/agent-workflow-runner.js +124 -0
- package/dist/agent-workflow-runner.js.map +1 -0
- package/dist/agent.d.ts +115 -0
- package/dist/agent.d.ts.map +1 -0
- package/dist/agent.js +587 -0
- package/dist/agent.js.map +1 -0
- package/dist/base-agent.d.ts +42 -0
- package/dist/base-agent.d.ts.map +1 -0
- package/dist/base-agent.js +29 -0
- package/dist/base-agent.js.map +1 -0
- package/dist/constants.d.ts +8 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +8 -0
- package/dist/constants.js.map +1 -0
- package/dist/graph-builder.d.ts +49 -0
- package/dist/graph-builder.d.ts.map +1 -0
- package/dist/graph-builder.js +206 -0
- package/dist/graph-builder.js.map +1 -0
- package/dist/graph-planner.d.ts +56 -0
- package/dist/graph-planner.d.ts.map +1 -0
- package/dist/graph-planner.js +311 -0
- package/dist/graph-planner.js.map +1 -0
- package/dist/index.d.ts +79 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +81 -0
- package/dist/index.js.map +1 -0
- package/dist/js-sandbox.d.ts +84 -0
- package/dist/js-sandbox.d.ts.map +1 -0
- package/dist/js-sandbox.js +654 -0
- package/dist/js-sandbox.js.map +1 -0
- package/dist/multi-mode-agent.d.ts +86 -0
- package/dist/multi-mode-agent.d.ts.map +1 -0
- package/dist/multi-mode-agent.js +476 -0
- package/dist/multi-mode-agent.js.map +1 -0
- package/dist/output-format.d.ts +10 -0
- package/dist/output-format.d.ts.map +1 -0
- package/dist/output-format.js +17 -0
- package/dist/output-format.js.map +1 -0
- package/dist/parallel-task-executor.d.ts +87 -0
- package/dist/parallel-task-executor.d.ts.map +1 -0
- package/dist/parallel-task-executor.js +332 -0
- package/dist/parallel-task-executor.js.map +1 -0
- package/dist/prompts/graph-planner-prompt.d.ts +48 -0
- package/dist/prompts/graph-planner-prompt.d.ts.map +1 -0
- package/dist/prompts/graph-planner-prompt.js +180 -0
- package/dist/prompts/graph-planner-prompt.js.map +1 -0
- package/dist/reject-agentic-provider.d.ts +21 -0
- package/dist/reject-agentic-provider.d.ts.map +1 -0
- package/dist/reject-agentic-provider.js +32 -0
- package/dist/reject-agentic-provider.js.map +1 -0
- package/dist/simple-agent.d.ts +29 -0
- package/dist/simple-agent.d.ts.map +1 -0
- package/dist/simple-agent.js +54 -0
- package/dist/simple-agent.js.map +1 -0
- package/dist/step-executor.d.ts +162 -0
- package/dist/step-executor.d.ts.map +1 -0
- package/dist/step-executor.js +1114 -0
- package/dist/step-executor.js.map +1 -0
- package/dist/sub-agent-planner.d.ts +33 -0
- package/dist/sub-agent-planner.d.ts.map +1 -0
- package/dist/sub-agent-planner.js +203 -0
- package/dist/sub-agent-planner.js.map +1 -0
- package/dist/task-executor.d.ts +89 -0
- package/dist/task-executor.d.ts.map +1 -0
- package/dist/task-executor.js +359 -0
- package/dist/task-executor.js.map +1 -0
- package/dist/task-planner.d.ts +44 -0
- package/dist/task-planner.d.ts.map +1 -0
- package/dist/task-planner.js +532 -0
- package/dist/task-planner.js.map +1 -0
- package/dist/team/db-task-board.d.ts +54 -0
- package/dist/team/db-task-board.d.ts.map +1 -0
- package/dist/team/db-task-board.js +361 -0
- package/dist/team/db-task-board.js.map +1 -0
- package/dist/team/edge-message-bus.d.ts +51 -0
- package/dist/team/edge-message-bus.d.ts.map +1 -0
- package/dist/team/edge-message-bus.js +169 -0
- package/dist/team/edge-message-bus.js.map +1 -0
- package/dist/team/edge-task-board.d.ts +77 -0
- package/dist/team/edge-task-board.d.ts.map +1 -0
- package/dist/team/edge-task-board.js +140 -0
- package/dist/team/edge-task-board.js.map +1 -0
- package/dist/team/index.d.ts +16 -0
- package/dist/team/index.d.ts.map +1 -0
- package/dist/team/index.js +17 -0
- package/dist/team/index.js.map +1 -0
- package/dist/team/message-bus.d.ts +58 -0
- package/dist/team/message-bus.d.ts.map +1 -0
- package/dist/team/message-bus.js +151 -0
- package/dist/team/message-bus.js.map +1 -0
- package/dist/team/task-board.d.ts +106 -0
- package/dist/team/task-board.d.ts.map +1 -0
- package/dist/team/task-board.js +370 -0
- package/dist/team/task-board.js.map +1 -0
- package/dist/team/team-executor.d.ts +72 -0
- package/dist/team/team-executor.d.ts.map +1 -0
- package/dist/team/team-executor.js +466 -0
- package/dist/team/team-executor.js.map +1 -0
- package/dist/team/team-tools.d.ts +252 -0
- package/dist/team/team-tools.d.ts.map +1 -0
- package/dist/team/team-tools.js +412 -0
- package/dist/team/team-tools.js.map +1 -0
- package/dist/team/types.d.ts +198 -0
- package/dist/team/types.d.ts.map +1 -0
- package/dist/team/types.js +8 -0
- package/dist/team/types.js.map +1 -0
- package/dist/tools/add-edge-tool.d.ts +18 -0
- package/dist/tools/add-edge-tool.d.ts.map +1 -0
- package/dist/tools/add-edge-tool.js +92 -0
- package/dist/tools/add-edge-tool.js.map +1 -0
- package/dist/tools/add-node-tool.d.ts +22 -0
- package/dist/tools/add-node-tool.d.ts.map +1 -0
- package/dist/tools/add-node-tool.js +128 -0
- package/dist/tools/add-node-tool.js.map +1 -0
- package/dist/tools/asset-tools.d.ts +58 -0
- package/dist/tools/asset-tools.d.ts.map +1 -0
- package/dist/tools/asset-tools.js +191 -0
- package/dist/tools/asset-tools.js.map +1 -0
- package/dist/tools/base-tool.d.ts +25 -0
- package/dist/tools/base-tool.d.ts.map +1 -0
- package/dist/tools/base-tool.js +24 -0
- package/dist/tools/base-tool.js.map +1 -0
- package/dist/tools/browser-tools.d.ts +32 -0
- package/dist/tools/browser-tools.d.ts.map +1 -0
- package/dist/tools/browser-tools.js +208 -0
- package/dist/tools/browser-tools.js.map +1 -0
- package/dist/tools/calculator-tool.d.ts +24 -0
- package/dist/tools/calculator-tool.d.ts.map +1 -0
- package/dist/tools/calculator-tool.js +64 -0
- package/dist/tools/calculator-tool.js.map +1 -0
- package/dist/tools/claude-code-tools.d.ts +96 -0
- package/dist/tools/claude-code-tools.d.ts.map +1 -0
- package/dist/tools/claude-code-tools.js +463 -0
- package/dist/tools/claude-code-tools.js.map +1 -0
- package/dist/tools/code-tools.d.ts +26 -0
- package/dist/tools/code-tools.d.ts.map +1 -0
- package/dist/tools/code-tools.js +82 -0
- package/dist/tools/code-tools.js.map +1 -0
- package/dist/tools/control-tool.d.ts +47 -0
- package/dist/tools/control-tool.d.ts.map +1 -0
- package/dist/tools/control-tool.js +101 -0
- package/dist/tools/control-tool.js.map +1 -0
- package/dist/tools/create-plan-tool.d.ts +29 -0
- package/dist/tools/create-plan-tool.d.ts.map +1 -0
- package/dist/tools/create-plan-tool.js +355 -0
- package/dist/tools/create-plan-tool.js.map +1 -0
- package/dist/tools/create-task-tool.d.ts +28 -0
- package/dist/tools/create-task-tool.d.ts.map +1 -0
- package/dist/tools/create-task-tool.js +254 -0
- package/dist/tools/create-task-tool.js.map +1 -0
- package/dist/tools/dataseo-tools.d.ts +38 -0
- package/dist/tools/dataseo-tools.d.ts.map +1 -0
- package/dist/tools/dataseo-tools.js +329 -0
- package/dist/tools/dataseo-tools.js.map +1 -0
- package/dist/tools/email-tools.d.ts +76 -0
- package/dist/tools/email-tools.d.ts.map +1 -0
- package/dist/tools/email-tools.js +259 -0
- package/dist/tools/email-tools.js.map +1 -0
- package/dist/tools/filesystem-tools.d.ts +77 -0
- package/dist/tools/filesystem-tools.d.ts.map +1 -0
- package/dist/tools/filesystem-tools.js +334 -0
- package/dist/tools/filesystem-tools.js.map +1 -0
- package/dist/tools/find-model-tool.d.ts +25 -0
- package/dist/tools/find-model-tool.d.ts.map +1 -0
- package/dist/tools/find-model-tool.js +236 -0
- package/dist/tools/find-model-tool.js.map +1 -0
- package/dist/tools/finish-graph-tool.d.ts +23 -0
- package/dist/tools/finish-graph-tool.d.ts.map +1 -0
- package/dist/tools/finish-graph-tool.js +46 -0
- package/dist/tools/finish-graph-tool.js.map +1 -0
- package/dist/tools/finish-step-tool.d.ts +16 -0
- package/dist/tools/finish-step-tool.d.ts.map +1 -0
- package/dist/tools/finish-step-tool.js +68 -0
- package/dist/tools/finish-step-tool.js.map +1 -0
- package/dist/tools/google-tools.d.ts +44 -0
- package/dist/tools/google-tools.d.ts.map +1 -0
- package/dist/tools/google-tools.js +176 -0
- package/dist/tools/google-tools.js.map +1 -0
- package/dist/tools/http-tools.d.ts +56 -0
- package/dist/tools/http-tools.d.ts.map +1 -0
- package/dist/tools/http-tools.js +180 -0
- package/dist/tools/http-tools.js.map +1 -0
- package/dist/tools/js-code-tool.d.ts +30 -0
- package/dist/tools/js-code-tool.d.ts.map +1 -0
- package/dist/tools/js-code-tool.js +98 -0
- package/dist/tools/js-code-tool.js.map +1 -0
- package/dist/tools/local-get-node-info-tool.d.ts +19 -0
- package/dist/tools/local-get-node-info-tool.d.ts.map +1 -0
- package/dist/tools/local-get-node-info-tool.js +75 -0
- package/dist/tools/local-get-node-info-tool.js.map +1 -0
- package/dist/tools/local-list-nodes-tool.d.ts +19 -0
- package/dist/tools/local-list-nodes-tool.d.ts.map +1 -0
- package/dist/tools/local-list-nodes-tool.js +69 -0
- package/dist/tools/local-list-nodes-tool.js.map +1 -0
- package/dist/tools/local-search-nodes-tool.d.ts +21 -0
- package/dist/tools/local-search-nodes-tool.d.ts.map +1 -0
- package/dist/tools/local-search-nodes-tool.js +111 -0
- package/dist/tools/local-search-nodes-tool.js.map +1 -0
- package/dist/tools/math-tools.d.ts +156 -0
- package/dist/tools/math-tools.d.ts.map +1 -0
- package/dist/tools/math-tools.js +422 -0
- package/dist/tools/math-tools.js.map +1 -0
- package/dist/tools/mcp-tools.d.ts +413 -0
- package/dist/tools/mcp-tools.d.ts.map +1 -0
- package/dist/tools/mcp-tools.js +618 -0
- package/dist/tools/mcp-tools.js.map +1 -0
- package/dist/tools/media-tools.d.ts +277 -0
- package/dist/tools/media-tools.d.ts.map +1 -0
- package/dist/tools/media-tools.js +682 -0
- package/dist/tools/media-tools.js.map +1 -0
- package/dist/tools/model-tools.d.ts +25 -0
- package/dist/tools/model-tools.d.ts.map +1 -0
- package/dist/tools/model-tools.js +48 -0
- package/dist/tools/model-tools.js.map +1 -0
- package/dist/tools/openai-tools.d.ts +73 -0
- package/dist/tools/openai-tools.d.ts.map +1 -0
- package/dist/tools/openai-tools.js +193 -0
- package/dist/tools/openai-tools.js.map +1 -0
- package/dist/tools/pdf-tools.d.ts +152 -0
- package/dist/tools/pdf-tools.d.ts.map +1 -0
- package/dist/tools/pdf-tools.js +339 -0
- package/dist/tools/pdf-tools.js.map +1 -0
- package/dist/tools/plan-builder-tools.d.ts +72 -0
- package/dist/tools/plan-builder-tools.d.ts.map +1 -0
- package/dist/tools/plan-builder-tools.js +438 -0
- package/dist/tools/plan-builder-tools.js.map +1 -0
- package/dist/tools/search-tools.d.ts +39 -0
- package/dist/tools/search-tools.d.ts.map +1 -0
- package/dist/tools/search-tools.js +218 -0
- package/dist/tools/search-tools.js.map +1 -0
- package/dist/tools/serp-providers/dataforseo-provider.d.ts +14 -0
- package/dist/tools/serp-providers/dataforseo-provider.d.ts.map +1 -0
- package/dist/tools/serp-providers/dataforseo-provider.js +114 -0
- package/dist/tools/serp-providers/dataforseo-provider.js.map +1 -0
- package/dist/tools/serp-providers/index.d.ts +35 -0
- package/dist/tools/serp-providers/index.d.ts.map +1 -0
- package/dist/tools/serp-providers/index.js +14 -0
- package/dist/tools/serp-providers/index.js.map +1 -0
- package/dist/tools/serp-providers/serpapi-provider.d.ts +18 -0
- package/dist/tools/serp-providers/serpapi-provider.d.ts.map +1 -0
- package/dist/tools/serp-providers/serpapi-provider.js +66 -0
- package/dist/tools/serp-providers/serpapi-provider.js.map +1 -0
- package/dist/tools/tool-registry.d.ts +9 -0
- package/dist/tools/tool-registry.d.ts.map +1 -0
- package/dist/tools/tool-registry.js +17 -0
- package/dist/tools/tool-registry.js.map +1 -0
- package/dist/tools/vector-tools.d.ts +224 -0
- package/dist/tools/vector-tools.d.ts.map +1 -0
- package/dist/tools/vector-tools.js +582 -0
- package/dist/tools/vector-tools.js.map +1 -0
- package/dist/tools/workspace-tools.d.ts +58 -0
- package/dist/tools/workspace-tools.d.ts.map +1 -0
- package/dist/tools/workspace-tools.js +152 -0
- package/dist/tools/workspace-tools.js.map +1 -0
- package/dist/types.d.ts +65 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +5 -0
- package/dist/types.js.map +1 -0
- package/dist/utils/json-parser.d.ts +15 -0
- package/dist/utils/json-parser.d.ts.map +1 -0
- package/dist/utils/json-parser.js +78 -0
- package/dist/utils/json-parser.js.map +1 -0
- package/dist/utils/remove-base64-images.d.ts +12 -0
- package/dist/utils/remove-base64-images.d.ts.map +1 -0
- package/dist/utils/remove-base64-images.js +20 -0
- package/dist/utils/remove-base64-images.js.map +1 -0
- package/dist/utils/wrap-generators-parallel.d.ts +11 -0
- package/dist/utils/wrap-generators-parallel.d.ts.map +1 -0
- package/dist/utils/wrap-generators-parallel.js +38 -0
- package/dist/utils/wrap-generators-parallel.js.map +1 -0
- package/package.json +65 -0
|
@@ -0,0 +1,334 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Filesystem tools for reading, writing, and listing files.
|
|
3
|
+
*
|
|
4
|
+
* Port of src/nodetool/agents/tools/workspace_tools.py
|
|
5
|
+
*/
|
|
6
|
+
import { readFile, writeFile, appendFile, mkdir, readdir, stat, access } from "node:fs/promises";
|
|
7
|
+
import { dirname, join } from "node:path";
|
|
8
|
+
import { Tool } from "./base-tool.js";
|
|
9
|
+
const MAX_READ_CHARS = 100_000;
|
|
10
|
+
const MAX_TOKENS = 25_000;
|
|
11
|
+
const TOKEN_MODEL = "gpt-4";
|
|
12
|
+
async function countTokens(text) {
|
|
13
|
+
const { encodingForModel } = await import("js-tiktoken");
|
|
14
|
+
const enc = encodingForModel(TOKEN_MODEL);
|
|
15
|
+
return enc.encode(text).length;
|
|
16
|
+
}
|
|
17
|
+
function isBinaryBuffer(buf) {
|
|
18
|
+
// Check first 8KB for null bytes — a strong indicator of binary content
|
|
19
|
+
const check = buf.subarray(0, 8192);
|
|
20
|
+
for (let i = 0; i < check.length; i++) {
|
|
21
|
+
if (check[i] === 0)
|
|
22
|
+
return true;
|
|
23
|
+
}
|
|
24
|
+
return false;
|
|
25
|
+
}
|
|
26
|
+
function resolveSafePath(context, rawPath) {
|
|
27
|
+
return context.resolveWorkspacePath(rawPath);
|
|
28
|
+
}
|
|
29
|
+
export class ReadFileTool extends Tool {
|
|
30
|
+
name = "read_file";
|
|
31
|
+
description = "Read the contents of a text file within the agent workspace. Automatically counts tokens and supports reading specific line ranges. Cannot read binary files.";
|
|
32
|
+
inputSchema = {
|
|
33
|
+
type: "object",
|
|
34
|
+
properties: {
|
|
35
|
+
path: {
|
|
36
|
+
type: "string",
|
|
37
|
+
description: "Path to the file to read, relative to the workspace directory"
|
|
38
|
+
},
|
|
39
|
+
start_line: {
|
|
40
|
+
type: "number",
|
|
41
|
+
description: "Start line (1-indexed, optional)"
|
|
42
|
+
},
|
|
43
|
+
end_line: {
|
|
44
|
+
type: "number",
|
|
45
|
+
description: "End line (1-indexed, inclusive, optional)"
|
|
46
|
+
}
|
|
47
|
+
},
|
|
48
|
+
required: ["path"]
|
|
49
|
+
};
|
|
50
|
+
async process(context, params) {
|
|
51
|
+
const rawPath = params["path"];
|
|
52
|
+
if (typeof rawPath !== "string") {
|
|
53
|
+
return { error: "path must be a string" };
|
|
54
|
+
}
|
|
55
|
+
let filePath;
|
|
56
|
+
try {
|
|
57
|
+
filePath = resolveSafePath(context, rawPath);
|
|
58
|
+
}
|
|
59
|
+
catch (e) {
|
|
60
|
+
return {
|
|
61
|
+
success: false,
|
|
62
|
+
error: String(e instanceof Error ? e.message : e)
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
try {
|
|
66
|
+
await access(filePath);
|
|
67
|
+
}
|
|
68
|
+
catch {
|
|
69
|
+
return {
|
|
70
|
+
success: false,
|
|
71
|
+
error: `Path ${rawPath} does not exist`
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
// Binary detection
|
|
75
|
+
try {
|
|
76
|
+
const rawBuf = await readFile(filePath);
|
|
77
|
+
if (isBinaryBuffer(rawBuf)) {
|
|
78
|
+
return {
|
|
79
|
+
success: false,
|
|
80
|
+
is_binary: true,
|
|
81
|
+
path: rawPath,
|
|
82
|
+
full_path: filePath,
|
|
83
|
+
error: `The file ${rawPath} contains binary data that cannot be processed`
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
const raw = rawBuf.toString("utf-8");
|
|
87
|
+
const startLine = params["start_line"];
|
|
88
|
+
const endLine = params["end_line"];
|
|
89
|
+
let content;
|
|
90
|
+
let lineInfo;
|
|
91
|
+
if (typeof startLine === "number" || typeof endLine === "number") {
|
|
92
|
+
const lines = raw.split("\n");
|
|
93
|
+
const totalLines = lines.length;
|
|
94
|
+
const startIdx = Math.max(0, (typeof startLine === "number" ? startLine : 1) - 1);
|
|
95
|
+
const endIdx = Math.min(totalLines, typeof endLine === "number" ? endLine : totalLines);
|
|
96
|
+
if (startIdx >= totalLines || startIdx > endIdx) {
|
|
97
|
+
return {
|
|
98
|
+
success: false,
|
|
99
|
+
is_directory: false,
|
|
100
|
+
path: rawPath,
|
|
101
|
+
full_path: filePath,
|
|
102
|
+
error: `Invalid line range: start_line=${startLine}, end_line=${endLine}, total lines=${totalLines}`,
|
|
103
|
+
suggested_ranges: [
|
|
104
|
+
`1-${Math.min(500, totalLines)}`,
|
|
105
|
+
`${Math.max(1, totalLines - 500)}-${totalLines}`
|
|
106
|
+
]
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
content = lines.slice(startIdx, endIdx).join("\n");
|
|
110
|
+
lineInfo = {
|
|
111
|
+
start_line: typeof startLine === "number" ? startLine : 1,
|
|
112
|
+
end_line: endIdx,
|
|
113
|
+
total_lines: totalLines
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
else {
|
|
117
|
+
content =
|
|
118
|
+
raw.length > MAX_READ_CHARS ? raw.slice(0, MAX_READ_CHARS) : raw;
|
|
119
|
+
lineInfo = { total_lines: (raw.match(/\n/g) || []).length + 1 };
|
|
120
|
+
}
|
|
121
|
+
const tokenCount = await countTokens(content);
|
|
122
|
+
const tokenInfo = { count: tokenCount, model: TOKEN_MODEL };
|
|
123
|
+
if (tokenCount > MAX_TOKENS) {
|
|
124
|
+
const totalLines = lineInfo.total_lines ?? 0;
|
|
125
|
+
const approxLinesPerToken = totalLines / Math.max(1, tokenCount);
|
|
126
|
+
const suggestedLineCount = Math.floor(approxLinesPerToken * MAX_TOKENS * 0.9);
|
|
127
|
+
let suggestedRanges;
|
|
128
|
+
if (typeof startLine === "number") {
|
|
129
|
+
const suggestedEnd = Math.min(startLine + suggestedLineCount - 1, totalLines);
|
|
130
|
+
suggestedRanges = [`${startLine}-${suggestedEnd}`];
|
|
131
|
+
}
|
|
132
|
+
else {
|
|
133
|
+
const chunkSize = Math.min(suggestedLineCount, 500);
|
|
134
|
+
suggestedRanges = [];
|
|
135
|
+
for (let i = 1; i <= totalLines && suggestedRanges.length < 3; i += chunkSize) {
|
|
136
|
+
suggestedRanges.push(`${i}-${Math.min(i + chunkSize - 1, totalLines)}`);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
return {
|
|
140
|
+
success: false,
|
|
141
|
+
is_directory: false,
|
|
142
|
+
path: rawPath,
|
|
143
|
+
full_path: filePath,
|
|
144
|
+
error: `Token count (${tokenCount}) exceeds maximum (${MAX_TOKENS}). Please read only a portion of the file.`,
|
|
145
|
+
token_info: tokenInfo,
|
|
146
|
+
line_info: lineInfo,
|
|
147
|
+
suggested_ranges: suggestedRanges
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
return {
|
|
151
|
+
success: true,
|
|
152
|
+
is_directory: false,
|
|
153
|
+
path: rawPath,
|
|
154
|
+
full_path: filePath,
|
|
155
|
+
content,
|
|
156
|
+
truncated: raw.length > MAX_READ_CHARS,
|
|
157
|
+
is_binary: false,
|
|
158
|
+
line_info: lineInfo,
|
|
159
|
+
token_info: tokenInfo
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
catch (e) {
|
|
163
|
+
return {
|
|
164
|
+
success: false,
|
|
165
|
+
error: `Failed to read file: ${String(e)}`
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
userMessage(params) {
|
|
170
|
+
const path = params["path"];
|
|
171
|
+
const msg = `Reading content from ${path}...`;
|
|
172
|
+
return msg.length > 80 ? "Reading content from a path..." : msg;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
export class WriteFileTool extends Tool {
|
|
176
|
+
name = "write_file";
|
|
177
|
+
description = "Write content to a file in the agent workspace, creating it if it doesn't exist.";
|
|
178
|
+
inputSchema = {
|
|
179
|
+
type: "object",
|
|
180
|
+
properties: {
|
|
181
|
+
path: {
|
|
182
|
+
type: "string",
|
|
183
|
+
description: "Path to the file to write, relative to the workspace directory"
|
|
184
|
+
},
|
|
185
|
+
content: {
|
|
186
|
+
type: "string",
|
|
187
|
+
description: "Content to write to the file"
|
|
188
|
+
},
|
|
189
|
+
append: {
|
|
190
|
+
type: "boolean",
|
|
191
|
+
description: "Whether to append to the file instead of overwriting",
|
|
192
|
+
default: false
|
|
193
|
+
}
|
|
194
|
+
},
|
|
195
|
+
required: ["path", "content"]
|
|
196
|
+
};
|
|
197
|
+
async process(context, params) {
|
|
198
|
+
const rawPath = params["path"];
|
|
199
|
+
const content = params["content"];
|
|
200
|
+
const appendMode = params["append"] === true;
|
|
201
|
+
if (typeof rawPath !== "string") {
|
|
202
|
+
return { error: "path must be a string" };
|
|
203
|
+
}
|
|
204
|
+
if (typeof content !== "string") {
|
|
205
|
+
return { error: "content must be a string" };
|
|
206
|
+
}
|
|
207
|
+
let filePath;
|
|
208
|
+
try {
|
|
209
|
+
filePath = resolveSafePath(context, rawPath);
|
|
210
|
+
}
|
|
211
|
+
catch (e) {
|
|
212
|
+
return {
|
|
213
|
+
success: false,
|
|
214
|
+
error: String(e instanceof Error ? e.message : e)
|
|
215
|
+
};
|
|
216
|
+
}
|
|
217
|
+
try {
|
|
218
|
+
await mkdir(dirname(filePath), { recursive: true });
|
|
219
|
+
let created;
|
|
220
|
+
try {
|
|
221
|
+
await access(filePath);
|
|
222
|
+
created = false;
|
|
223
|
+
}
|
|
224
|
+
catch {
|
|
225
|
+
created = true;
|
|
226
|
+
}
|
|
227
|
+
if (appendMode) {
|
|
228
|
+
await appendFile(filePath, content, "utf-8");
|
|
229
|
+
}
|
|
230
|
+
else {
|
|
231
|
+
await writeFile(filePath, content, "utf-8");
|
|
232
|
+
}
|
|
233
|
+
return {
|
|
234
|
+
success: true,
|
|
235
|
+
path: rawPath,
|
|
236
|
+
full_path: filePath,
|
|
237
|
+
append: appendMode,
|
|
238
|
+
created
|
|
239
|
+
};
|
|
240
|
+
}
|
|
241
|
+
catch (e) {
|
|
242
|
+
return { success: false, error: `Failed to write file: ${String(e)}` };
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
userMessage(params) {
|
|
246
|
+
const path = params["path"] ?? "";
|
|
247
|
+
const appendMode = params["append"] === true;
|
|
248
|
+
const action = appendMode ? "Appending to" : "Writing to";
|
|
249
|
+
const msg = `${action} file ${path}...`;
|
|
250
|
+
return msg.length > 160 ? `${action} a file...` : msg;
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
export class ListDirectoryTool extends Tool {
|
|
254
|
+
name = "list_directory";
|
|
255
|
+
description = "List the contents (files and subdirectories) of a directory within the agent workspace.";
|
|
256
|
+
inputSchema = {
|
|
257
|
+
type: "object",
|
|
258
|
+
properties: {
|
|
259
|
+
path: {
|
|
260
|
+
type: "string",
|
|
261
|
+
description: "Path to the directory to list, relative to the workspace directory"
|
|
262
|
+
},
|
|
263
|
+
recursive: {
|
|
264
|
+
type: "boolean",
|
|
265
|
+
description: "Whether to list contents recursively (default false)"
|
|
266
|
+
}
|
|
267
|
+
},
|
|
268
|
+
required: ["path"]
|
|
269
|
+
};
|
|
270
|
+
async process(context, params) {
|
|
271
|
+
const rawPath = params["path"];
|
|
272
|
+
if (typeof rawPath !== "string") {
|
|
273
|
+
return { error: "path must be a string" };
|
|
274
|
+
}
|
|
275
|
+
let dirPath;
|
|
276
|
+
try {
|
|
277
|
+
dirPath = resolveSafePath(context, rawPath);
|
|
278
|
+
}
|
|
279
|
+
catch (e) {
|
|
280
|
+
return {
|
|
281
|
+
success: false,
|
|
282
|
+
error: String(e instanceof Error ? e.message : e)
|
|
283
|
+
};
|
|
284
|
+
}
|
|
285
|
+
const recursive = params["recursive"] === true;
|
|
286
|
+
try {
|
|
287
|
+
const entries = await readdir(dirPath, { withFileTypes: true });
|
|
288
|
+
const results = [];
|
|
289
|
+
for (const entry of entries) {
|
|
290
|
+
const fullPath = join(dirPath, entry.name);
|
|
291
|
+
try {
|
|
292
|
+
const info = await stat(fullPath);
|
|
293
|
+
results.push({
|
|
294
|
+
name: entry.name,
|
|
295
|
+
size: info.size,
|
|
296
|
+
isDirectory: entry.isDirectory()
|
|
297
|
+
});
|
|
298
|
+
}
|
|
299
|
+
catch {
|
|
300
|
+
results.push({
|
|
301
|
+
name: entry.name,
|
|
302
|
+
size: 0,
|
|
303
|
+
isDirectory: entry.isDirectory()
|
|
304
|
+
});
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
if (recursive) {
|
|
308
|
+
const subdirs = results.filter((e) => e.isDirectory);
|
|
309
|
+
for (const sub of subdirs) {
|
|
310
|
+
const subResult = (await this.process(context, {
|
|
311
|
+
path: join(rawPath, sub.name),
|
|
312
|
+
recursive: true
|
|
313
|
+
}));
|
|
314
|
+
if (subResult.entries) {
|
|
315
|
+
for (const child of subResult.entries) {
|
|
316
|
+
results.push({
|
|
317
|
+
...child,
|
|
318
|
+
name: `${sub.name}/${child.name}`
|
|
319
|
+
});
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
return { entries: results };
|
|
325
|
+
}
|
|
326
|
+
catch (e) {
|
|
327
|
+
return { error: `Failed to list directory: ${String(e)}` };
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
userMessage(params) {
|
|
331
|
+
return `Listing directory: ${String(params["path"] ?? "")}`;
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
//# sourceMappingURL=filesystem-tools.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"filesystem-tools.js","sourceRoot":"","sources":["../../src/tools/filesystem-tools.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EACL,QAAQ,EACR,SAAS,EACT,UAAU,EACV,KAAK,EACL,OAAO,EACP,IAAI,EACJ,MAAM,EACP,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAE1C,OAAO,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAC;AAEtC,MAAM,cAAc,GAAG,OAAO,CAAC;AAC/B,MAAM,UAAU,GAAG,MAAM,CAAC;AAC1B,MAAM,WAAW,GAAG,OAAgB,CAAC;AAErC,KAAK,UAAU,WAAW,CAAC,IAAY;IACrC,MAAM,EAAE,gBAAgB,EAAE,GAAG,MAAM,MAAM,CAAC,aAAa,CAAC,CAAC;IACzD,MAAM,GAAG,GAAG,gBAAgB,CAAC,WAAW,CAAC,CAAC;IAC1C,OAAO,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC;AACjC,CAAC;AAED,SAAS,cAAc,CAAC,GAAW;IACjC,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|
4
|
+
* The workflow-building agent calls this before adding any of the generic AI
|
|
5
|
+
* nodes (`nodetool.image.TextToImage`, `nodetool.video.TextToVideo`, etc.).
|
|
6
|
+
* It walks the configured providers, asks each one for its capability set,
|
|
7
|
+
* collects models from the providers that support the requested capability,
|
|
8
|
+
* and returns a small ranked list.
|
|
9
|
+
*
|
|
10
|
+
* In-process by design — uses the runtime `BaseProvider` instances directly
|
|
11
|
+
* rather than going over HTTP, so it works identically from the CLI and the
|
|
12
|
+
* WebSocket runner.
|
|
13
|
+
*/
|
|
14
|
+
import type { BaseProvider, ProcessingContext } from "@nodetool-ai/runtime";
|
|
15
|
+
import { Tool } from "./base-tool.js";
|
|
16
|
+
export declare class FindModelTool extends Tool {
|
|
17
|
+
private readonly providers;
|
|
18
|
+
readonly name = "find_model";
|
|
19
|
+
readonly description = "Find a real {provider, model_id} for a generic AI node by capability. Returns models from providers the user has configured, ranked by recommended/downloaded/preferences. Call this before adding any generic AI node (TextToImage, TextToVideo, TextToSpeech, etc.).";
|
|
20
|
+
readonly inputSchema: Record<string, unknown>;
|
|
21
|
+
constructor(providers: Record<string, BaseProvider>);
|
|
22
|
+
process(_context: ProcessingContext, params: Record<string, unknown>): Promise<unknown>;
|
|
23
|
+
userMessage(params: Record<string, unknown>): string;
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=find-model-tool.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"find-model-tool.d.ts","sourceRoot":"","sources":["../../src/tools/find-model-tool.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,OAAO,KAAK,EAEV,YAAY,EAIZ,iBAAiB,EAIlB,MAAM,sBAAsB,CAAC;AAM9B,OAAO,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAC;AAsKtC,qBAAa,aAAc,SAAQ,IAAI;IAMzB,OAAO,CAAC,QAAQ,CAAC,SAAS;IALtC,QAAQ,CAAC,IAAI,gBAAgB;IAC7B,QAAQ,CAAC,WAAW,4QACuP;IAC3Q,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAA2B;gBAE3C,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC;IAI9D,OAAO,CACX,QAAQ,EAAE,iBAAiB,EAC3B,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAC9B,OAAO,CAAC,OAAO,CAAC;IAoGnB,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM;CAGrD"}
|
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
import { RECOMMENDED_MODELS, providerCapabilities } from "@nodetool-ai/runtime";
|
|
2
|
+
import { Tool } from "./base-tool.js";
|
|
3
|
+
const SUPPORTED_CAPABILITIES = [
|
|
4
|
+
"text_to_image",
|
|
5
|
+
"image_to_image",
|
|
6
|
+
"text_to_video",
|
|
7
|
+
"image_to_video",
|
|
8
|
+
"text_to_speech",
|
|
9
|
+
"automatic_speech_recognition",
|
|
10
|
+
"generate_embedding",
|
|
11
|
+
"generate_message"
|
|
12
|
+
];
|
|
13
|
+
const LOCAL_PROVIDER_IDS = new Set([
|
|
14
|
+
"ollama",
|
|
15
|
+
"lmstudio",
|
|
16
|
+
"vllm",
|
|
17
|
+
"llama_cpp",
|
|
18
|
+
"huggingface"
|
|
19
|
+
]);
|
|
20
|
+
const FIND_MODEL_INPUT_SCHEMA = {
|
|
21
|
+
type: "object",
|
|
22
|
+
properties: {
|
|
23
|
+
capability: {
|
|
24
|
+
type: "string",
|
|
25
|
+
enum: [...SUPPORTED_CAPABILITIES],
|
|
26
|
+
description: "Provider capability needed by the generic AI node (e.g. text_to_image, generate_embedding)."
|
|
27
|
+
},
|
|
28
|
+
task: {
|
|
29
|
+
type: "string",
|
|
30
|
+
description: "Optional task hint matched against model.supportedTasks (e.g. 'text_to_image' vs 'image_to_image')."
|
|
31
|
+
},
|
|
32
|
+
provider_hint: {
|
|
33
|
+
type: "string",
|
|
34
|
+
description: "Optional preferred provider id (e.g. 'openai'). Boosts matching providers."
|
|
35
|
+
},
|
|
36
|
+
model_hint: {
|
|
37
|
+
type: "array",
|
|
38
|
+
items: { type: "string" },
|
|
39
|
+
description: "Optional preferred model ids. Strongly boosts matching models in the ranking."
|
|
40
|
+
},
|
|
41
|
+
prefer_local: {
|
|
42
|
+
type: "boolean",
|
|
43
|
+
description: "If true, ranks local providers (ollama, lmstudio, vllm, llama_cpp, huggingface) above hosted ones.",
|
|
44
|
+
default: false
|
|
45
|
+
},
|
|
46
|
+
limit: {
|
|
47
|
+
type: "number",
|
|
48
|
+
description: "Maximum number of results to return (default 5).",
|
|
49
|
+
default: 5
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
required: ["capability"]
|
|
53
|
+
};
|
|
54
|
+
function getRecommendedSet(capability) {
|
|
55
|
+
const wantedTasks = capabilityToRecommendedTasks(capability);
|
|
56
|
+
const wantedModalities = capabilityToRecommendedModalities(capability);
|
|
57
|
+
const ids = new Set();
|
|
58
|
+
for (const m of RECOMMENDED_MODELS) {
|
|
59
|
+
const taskMatch = !wantedTasks || (m.task && wantedTasks.has(m.task));
|
|
60
|
+
const modalityMatch = wantedModalities.has(m.modality);
|
|
61
|
+
if (modalityMatch && taskMatch && m.provider) {
|
|
62
|
+
ids.add(`${m.provider}::${m.id}`);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
return ids;
|
|
66
|
+
}
|
|
67
|
+
function capabilityToRecommendedTasks(capability) {
|
|
68
|
+
switch (capability) {
|
|
69
|
+
case "text_to_image":
|
|
70
|
+
return new Set(["text_to_image"]);
|
|
71
|
+
case "image_to_image":
|
|
72
|
+
return new Set(["image_to_image"]);
|
|
73
|
+
case "text_to_video":
|
|
74
|
+
return new Set(["text_to_video"]);
|
|
75
|
+
case "image_to_video":
|
|
76
|
+
return new Set(["image_to_video"]);
|
|
77
|
+
case "generate_embedding":
|
|
78
|
+
return new Set(["embedding"]);
|
|
79
|
+
case "generate_message":
|
|
80
|
+
return new Set(["text_generation"]);
|
|
81
|
+
default:
|
|
82
|
+
// tts/asr have no `task` set on recommended entries — fall back to
|
|
83
|
+
// modality-only filtering.
|
|
84
|
+
return null;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
function capabilityToRecommendedModalities(capability) {
|
|
88
|
+
switch (capability) {
|
|
89
|
+
case "text_to_image":
|
|
90
|
+
case "image_to_image":
|
|
91
|
+
return new Set(["image"]);
|
|
92
|
+
case "text_to_video":
|
|
93
|
+
case "image_to_video":
|
|
94
|
+
return new Set(["video"]);
|
|
95
|
+
case "text_to_speech":
|
|
96
|
+
return new Set(["tts"]);
|
|
97
|
+
case "automatic_speech_recognition":
|
|
98
|
+
return new Set(["asr"]);
|
|
99
|
+
case "generate_embedding":
|
|
100
|
+
case "generate_message":
|
|
101
|
+
return new Set(["language"]);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
async function fetchModelsForCapability(provider, capability) {
|
|
105
|
+
switch (capability) {
|
|
106
|
+
case "text_to_image":
|
|
107
|
+
case "image_to_image":
|
|
108
|
+
return (await provider.getAvailableImageModels());
|
|
109
|
+
case "text_to_video":
|
|
110
|
+
case "image_to_video":
|
|
111
|
+
return (await provider.getAvailableVideoModels());
|
|
112
|
+
case "text_to_speech":
|
|
113
|
+
return (await provider.getAvailableTTSModels());
|
|
114
|
+
case "automatic_speech_recognition":
|
|
115
|
+
return (await provider.getAvailableASRModels());
|
|
116
|
+
case "generate_embedding":
|
|
117
|
+
return (await provider.getAvailableEmbeddingModels());
|
|
118
|
+
case "generate_message":
|
|
119
|
+
return (await provider.getAvailableLanguageModels());
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
function taskMatch(model, task) {
|
|
123
|
+
if (!task)
|
|
124
|
+
return true;
|
|
125
|
+
if (!model.supportedTasks || model.supportedTasks.length === 0)
|
|
126
|
+
return true;
|
|
127
|
+
return model.supportedTasks.includes(task);
|
|
128
|
+
}
|
|
129
|
+
export class FindModelTool extends Tool {
|
|
130
|
+
providers;
|
|
131
|
+
name = "find_model";
|
|
132
|
+
description = "Find a real {provider, model_id} for a generic AI node by capability. Returns models from providers the user has configured, ranked by recommended/downloaded/preferences. Call this before adding any generic AI node (TextToImage, TextToVideo, TextToSpeech, etc.).";
|
|
133
|
+
inputSchema = FIND_MODEL_INPUT_SCHEMA;
|
|
134
|
+
constructor(providers) {
|
|
135
|
+
super();
|
|
136
|
+
this.providers = providers;
|
|
137
|
+
}
|
|
138
|
+
async process(_context, params) {
|
|
139
|
+
const capability = params["capability"];
|
|
140
|
+
if (!capability || !SUPPORTED_CAPABILITIES.includes(capability)) {
|
|
141
|
+
return {
|
|
142
|
+
capability,
|
|
143
|
+
total: 0,
|
|
144
|
+
results: [],
|
|
145
|
+
error: `capability must be one of: ${SUPPORTED_CAPABILITIES.join(", ")}`
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
const task = typeof params["task"] === "string" ? params["task"] : undefined;
|
|
149
|
+
const providerHint = typeof params["provider_hint"] === "string"
|
|
150
|
+
? params["provider_hint"]
|
|
151
|
+
: undefined;
|
|
152
|
+
const modelHintRaw = params["model_hint"];
|
|
153
|
+
const modelHints = new Set(typeof modelHintRaw === "string"
|
|
154
|
+
? [modelHintRaw]
|
|
155
|
+
: Array.isArray(modelHintRaw)
|
|
156
|
+
? modelHintRaw.filter((x) => typeof x === "string")
|
|
157
|
+
: []);
|
|
158
|
+
const preferLocal = params["prefer_local"] === true;
|
|
159
|
+
const limit = typeof params["limit"] === "number" && params["limit"] > 0
|
|
160
|
+
? Math.floor(params["limit"])
|
|
161
|
+
: 5;
|
|
162
|
+
const providerEntries = Object.entries(this.providers);
|
|
163
|
+
if (providerEntries.length === 0) {
|
|
164
|
+
return {
|
|
165
|
+
capability,
|
|
166
|
+
total: 0,
|
|
167
|
+
results: [],
|
|
168
|
+
note: "No providers configured. Use nodetool.agents.AgentStep for AI work."
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
const recommendedSet = getRecommendedSet(capability);
|
|
172
|
+
const collected = [];
|
|
173
|
+
for (const [providerId, instance] of providerEntries) {
|
|
174
|
+
let supports;
|
|
175
|
+
try {
|
|
176
|
+
supports = providerCapabilities(instance).includes(capability);
|
|
177
|
+
}
|
|
178
|
+
catch {
|
|
179
|
+
continue;
|
|
180
|
+
}
|
|
181
|
+
if (!supports)
|
|
182
|
+
continue;
|
|
183
|
+
let models;
|
|
184
|
+
try {
|
|
185
|
+
models = await fetchModelsForCapability(instance, capability);
|
|
186
|
+
}
|
|
187
|
+
catch {
|
|
188
|
+
continue;
|
|
189
|
+
}
|
|
190
|
+
for (const m of models) {
|
|
191
|
+
if (!taskMatch(m, task))
|
|
192
|
+
continue;
|
|
193
|
+
const recommended = recommendedSet.has(`${providerId}::${m.id}`);
|
|
194
|
+
const downloaded = LOCAL_PROVIDER_IDS.has(providerId);
|
|
195
|
+
let score = 0;
|
|
196
|
+
if (recommended)
|
|
197
|
+
score += 100;
|
|
198
|
+
if (downloaded)
|
|
199
|
+
score += 30;
|
|
200
|
+
// Explicit user preferences outrank the default recommended bonus.
|
|
201
|
+
if (providerHint && providerId === providerHint)
|
|
202
|
+
score += 200;
|
|
203
|
+
if (modelHints.has(m.id))
|
|
204
|
+
score += 250;
|
|
205
|
+
if (preferLocal && LOCAL_PROVIDER_IDS.has(providerId))
|
|
206
|
+
score += 150;
|
|
207
|
+
else if (preferLocal && !LOCAL_PROVIDER_IDS.has(providerId))
|
|
208
|
+
score -= 5;
|
|
209
|
+
collected.push({
|
|
210
|
+
provider: providerId,
|
|
211
|
+
model_id: m.id,
|
|
212
|
+
name: m.name,
|
|
213
|
+
downloaded,
|
|
214
|
+
recommended,
|
|
215
|
+
score
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
collected.sort((a, b) => {
|
|
220
|
+
if (b.score !== a.score)
|
|
221
|
+
return b.score - a.score;
|
|
222
|
+
if (a.provider !== b.provider)
|
|
223
|
+
return a.provider.localeCompare(b.provider);
|
|
224
|
+
return a.model_id.localeCompare(b.model_id);
|
|
225
|
+
});
|
|
226
|
+
return {
|
|
227
|
+
capability,
|
|
228
|
+
total: collected.length,
|
|
229
|
+
results: collected.slice(0, limit)
|
|
230
|
+
};
|
|
231
|
+
}
|
|
232
|
+
userMessage(params) {
|
|
233
|
+
return `Looking up models for capability: ${String(params["capability"])}`;
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
//# sourceMappingURL=find-model-tool.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"find-model-tool.js","sourceRoot":"","sources":["../../src/tools/find-model-tool.ts"],"names":[],"mappings":"AAwBA,OAAO,EACL,kBAAkB,EAClB,oBAAoB,EACrB,MAAM,sBAAsB,CAAC;AAE9B,OAAO,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAC;AAEtC,MAAM,sBAAsB,GAAG;IAC7B,eAAe;IACf,gBAAgB;IAChB,eAAe;IACf,gBAAgB;IAChB,gBAAgB;IAChB,8BAA8B;IAC9B,oBAAoB;IACpB,kBAAkB;CACV,CAAC;AAIX,MAAM,kBAAkB,GAAG,IAAI,GAAG,CAAC;IACjC,QAAQ;IACR,UAAU;IACV,MAAM;IACN,WAAW;IACX,aAAa;CACd,CAAC,CAAC;AAkBH,MAAM,uBAAuB,GAAG;IAC9B,IAAI,EAAE,QAAiB;IACvB,UAAU,EAAE;QACV,UAAU,EAAE;YACV,IAAI,EAAE,QAAiB;YACvB,IAAI,EAAE,CAAC,GAAG,sBAAsB,CAAC;YACjC,WAAW,EACT,6FAA6F;SAChG;QACD,IAAI,EAAE;YACJ,IAAI,EAAE,QAAiB;YACvB,WAAW,EACT,qGAAqG;SACxG;QACD,aAAa,EAAE;YACb,IAAI,EAAE,QAAiB;YACvB,WAAW,EACT,4EAA4E;SAC/E;QACD,UAAU,EAAE;YACV,IAAI,EAAE,OAAgB;YACtB,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K,IAAI,GAAG,CAAC;qBAC/D,IAAI,WAAW,IAAI,CAAC,kBAAkB,CAAC,GAAG,CAAC,UAAU,CAAC;oBAAE,KAAK,IAAI,CAAC,CAAC;gBAExE,SAAS,CAAC,IAAI,CAAC;oBACb,QAAQ,EAAE,UAAU;oBACpB,QAAQ,EAAE,CAAC,CAAC,EAAE;oBACd,IAAI,EAAE,CAAC,CAAC,IAAI;oBACZ,UAAU;oBACV,WAAW;oBACX,KAAK;iBACN,CAAC,CAAC;YACL,CAAC;QACH,CAAC;QAED,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE;YACtB,IAAI,CAAC,CAAC,KAAK,KAAK,CAAC,CAAC,KAAK;gBAAE,OAAO,CAAC,CAAC,KAAK,GAAG,CAAC,CAAC,KAAK,CAAC;YAClD,IAAI,CAAC,CAAC,QAAQ,KAAK,CAAC,CAAC,QAAQ;gBAAE,OAAO,CAAC,CAAC,QAAQ,CAAC,aAAa,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC;YAC3E,OAAO,CAAC,CAAC,QAAQ,CAAC,aAAa,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC;QAC9C,CAAC,CAAC,CAAC;QAEH,OAAO;YACL,UAAU;YACV,KAAK,EAAE,SAAS,CAAC,MAAM;YACvB,OAAO,EAAE,SAAS,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC;SACnC,CAAC;IACJ,CAAC;IAED,WAAW,CAAC,MAA+B;QACzC,OAAO,qCAAqC,MAAM,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC,EAAE,CAAC;IAC7E,CAAC;CACF"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* FinishGraphTool -- planner tool that validates and finalizes the graph.
|
|
3
|
+
*
|
|
4
|
+
* Called by the LLM when it's done building the graph. Runs full validation
|
|
5
|
+
* (cycle detection, connectivity) and produces the GraphData.
|
|
6
|
+
*/
|
|
7
|
+
import type { ProcessingContext } from "@nodetool-ai/runtime";
|
|
8
|
+
import type { GraphData } from "@nodetool-ai/protocol";
|
|
9
|
+
import { Tool } from "./base-tool.js";
|
|
10
|
+
import type { GraphBuilder } from "../graph-builder.js";
|
|
11
|
+
export declare class FinishGraphTool extends Tool {
|
|
12
|
+
private readonly builder;
|
|
13
|
+
readonly name = "finish_graph";
|
|
14
|
+
readonly description = "Validate and finalize the workflow graph. Call this when you are done adding nodes and edges.";
|
|
15
|
+
readonly inputSchema: Record<string, unknown>;
|
|
16
|
+
/** The finalized graph, available after a successful call. */
|
|
17
|
+
private _graph;
|
|
18
|
+
get graph(): GraphData | null;
|
|
19
|
+
constructor(builder: GraphBuilder);
|
|
20
|
+
process(_context: ProcessingContext, _params: Record<string, unknown>): Promise<unknown>;
|
|
21
|
+
userMessage(_params: Record<string, unknown>): string;
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=finish-graph-tool.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"finish-graph-tool.d.ts","sourceRoot":"","sources":["../../src/tools/finish-graph-tool.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAC9D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAC;AACtC,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAQxD,qBAAa,eAAgB,SAAQ,IAAI;IAa3B,OAAO,CAAC,QAAQ,CAAC,OAAO;IAZpC,QAAQ,CAAC,IAAI,kBAAkB;IAC/B,QAAQ,CAAC,WAAW,mGAC8E;IAClG,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAA6B;IAE1E,8DAA8D;IAC9D,OAAO,CAAC,MAAM,CAA0B;IAExC,IAAI,KAAK,IAAI,SAAS,GAAG,IAAI,CAE5B;gBAE4B,OAAO,EAAE,YAAY;IAI5C,OAAO,CACX,QAAQ,EAAE,iBAAiB,EAC3B,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAC/B,OAAO,CAAC,OAAO,CAAC;IAkBnB,WAAW,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM;CAGtD"}
|