@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,339 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PDF tools for extracting text, tables, and converting documents.
|
|
3
|
+
*
|
|
4
|
+
* Port of src/nodetool/agents/tools/pdf_tools.py
|
|
5
|
+
*/
|
|
6
|
+
import { readFile, writeFile, mkdir } from "node:fs/promises";
|
|
7
|
+
import { dirname } from "node:path";
|
|
8
|
+
import { execFile } from "node:child_process";
|
|
9
|
+
import { promisify } from "node:util";
|
|
10
|
+
import { Tool } from "./base-tool.js";
|
|
11
|
+
const execFileAsync = promisify(execFile);
|
|
12
|
+
/**
|
|
13
|
+
* Extract text from a PDF buffer using @llamaindex/liteparse.
|
|
14
|
+
* Returns per-page text so callers can slice by page range.
|
|
15
|
+
*/
|
|
16
|
+
async function extractPdfPages(buffer) {
|
|
17
|
+
const { LiteParse } = await import("@llamaindex/liteparse");
|
|
18
|
+
const parser = new LiteParse({ ocrEnabled: false });
|
|
19
|
+
const result = await parser.parse(buffer, true);
|
|
20
|
+
const pages = result.pages.map((p) => p.text);
|
|
21
|
+
return { pages, numPages: result.pages.length };
|
|
22
|
+
}
|
|
23
|
+
export class ExtractPDFTextTool extends Tool {
|
|
24
|
+
name = "extract_pdf_text";
|
|
25
|
+
description = "Extract plain text from a PDF document";
|
|
26
|
+
inputSchema = {
|
|
27
|
+
type: "object",
|
|
28
|
+
properties: {
|
|
29
|
+
path: {
|
|
30
|
+
type: "string",
|
|
31
|
+
description: "Path to the PDF file"
|
|
32
|
+
},
|
|
33
|
+
start_page: {
|
|
34
|
+
type: "integer",
|
|
35
|
+
description: "First page to extract (0-based index)",
|
|
36
|
+
default: 0
|
|
37
|
+
},
|
|
38
|
+
end_page: {
|
|
39
|
+
type: "integer",
|
|
40
|
+
description: "Last page to extract (-1 for last page)",
|
|
41
|
+
default: -1
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
required: ["path"]
|
|
45
|
+
};
|
|
46
|
+
async process(context, params) {
|
|
47
|
+
try {
|
|
48
|
+
const filePath = context.resolveWorkspacePath(params["path"]);
|
|
49
|
+
const buffer = await readFile(filePath);
|
|
50
|
+
const { pages } = await extractPdfPages(buffer);
|
|
51
|
+
const startPage = params["start_page"] ?? 0;
|
|
52
|
+
const endPage = params["end_page"] ?? -1;
|
|
53
|
+
if (startPage === 0 && endPage === -1) {
|
|
54
|
+
return { text: pages.join("\n") };
|
|
55
|
+
}
|
|
56
|
+
const end = endPage === -1 ? pages.length - 1 : endPage;
|
|
57
|
+
const selectedPages = pages.slice(startPage, end + 1);
|
|
58
|
+
return { text: selectedPages.join("\n") };
|
|
59
|
+
}
|
|
60
|
+
catch (e) {
|
|
61
|
+
return { error: String(e instanceof Error ? e.message : e) };
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
userMessage(params) {
|
|
65
|
+
const path = params["path"] ?? "a PDF";
|
|
66
|
+
const msg = `Extracting text from ${path}...`;
|
|
67
|
+
return msg.length > 80 ? "Extracting text from PDF..." : msg;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
export class ExtractPDFTablesTool extends Tool {
|
|
71
|
+
name = "extract_pdf_tables";
|
|
72
|
+
description = "Extract tables from a PDF document to a JSON file";
|
|
73
|
+
inputSchema = {
|
|
74
|
+
type: "object",
|
|
75
|
+
properties: {
|
|
76
|
+
path: {
|
|
77
|
+
type: "string",
|
|
78
|
+
description: "Path to the PDF file"
|
|
79
|
+
},
|
|
80
|
+
output_file: {
|
|
81
|
+
type: "string",
|
|
82
|
+
description: "Path to the output JSON file"
|
|
83
|
+
},
|
|
84
|
+
start_page: {
|
|
85
|
+
type: "integer",
|
|
86
|
+
description: "First page to extract (0-based index)",
|
|
87
|
+
default: 0
|
|
88
|
+
},
|
|
89
|
+
end_page: {
|
|
90
|
+
type: "integer",
|
|
91
|
+
description: "Last page to extract (-1 for last page)",
|
|
92
|
+
default: -1
|
|
93
|
+
}
|
|
94
|
+
},
|
|
95
|
+
required: ["path", "output_file"]
|
|
96
|
+
};
|
|
97
|
+
async process(context, params) {
|
|
98
|
+
try {
|
|
99
|
+
const filePath = context.resolveWorkspacePath(params["path"]);
|
|
100
|
+
const outputFile = context.resolveWorkspacePath(params["output_file"]);
|
|
101
|
+
const buffer = await readFile(filePath);
|
|
102
|
+
const { pages } = await extractPdfPages(buffer);
|
|
103
|
+
const startPage = params["start_page"] ?? 0;
|
|
104
|
+
const endPage = params["end_page"] ?? -1;
|
|
105
|
+
const end = endPage === -1 ? pages.length - 1 : endPage;
|
|
106
|
+
// Best-effort table extraction: look for lines with consistent
|
|
107
|
+
// column-like separators (multiple spaces or tabs)
|
|
108
|
+
const allTables = [];
|
|
109
|
+
for (let pageNum = startPage; pageNum <= end && pageNum < pages.length; pageNum++) {
|
|
110
|
+
const pageText = pages[pageNum] ?? "";
|
|
111
|
+
const lines = pageText
|
|
112
|
+
.split("\n")
|
|
113
|
+
.filter((l) => l.trim().length > 0);
|
|
114
|
+
// Detect tabular rows: lines with 2+ segments separated by 2+ spaces
|
|
115
|
+
const tabularLines = [];
|
|
116
|
+
for (const line of lines) {
|
|
117
|
+
const cells = line
|
|
118
|
+
.split(/\s{2,}/)
|
|
119
|
+
.filter((c) => c.trim().length > 0);
|
|
120
|
+
if (cells.length >= 2) {
|
|
121
|
+
tabularLines.push(cells);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
// Group consecutive tabular lines into tables
|
|
125
|
+
if (tabularLines.length >= 2) {
|
|
126
|
+
allTables.push({
|
|
127
|
+
page: pageNum,
|
|
128
|
+
rows: tabularLines.length,
|
|
129
|
+
columns: Math.max(...tabularLines.map((r) => r.length)),
|
|
130
|
+
content: tabularLines
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
const parentDir = dirname(outputFile);
|
|
135
|
+
await mkdir(parentDir, { recursive: true });
|
|
136
|
+
await writeFile(outputFile, JSON.stringify(allTables), "utf-8");
|
|
137
|
+
return { output_file: outputFile };
|
|
138
|
+
}
|
|
139
|
+
catch (e) {
|
|
140
|
+
return { error: String(e instanceof Error ? e.message : e) };
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
userMessage(params) {
|
|
144
|
+
const path = params["path"] ?? "a PDF";
|
|
145
|
+
const output = params["output_file"] ?? "output";
|
|
146
|
+
let msg = `Extracting tables from ${path} to ${output}...`;
|
|
147
|
+
if (msg.length > 80)
|
|
148
|
+
msg = `Extracting tables from PDF to ${output}...`;
|
|
149
|
+
if (msg.length > 80)
|
|
150
|
+
msg = "Extracting tables from PDF...";
|
|
151
|
+
return msg;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
export class ConvertPDFToMarkdownTool extends Tool {
|
|
155
|
+
name = "convert_pdf_to_markdown";
|
|
156
|
+
description = "Convert PDF to Markdown format";
|
|
157
|
+
inputSchema = {
|
|
158
|
+
type: "object",
|
|
159
|
+
properties: {
|
|
160
|
+
input_file: {
|
|
161
|
+
type: "string",
|
|
162
|
+
description: "Path to the input PDF file"
|
|
163
|
+
},
|
|
164
|
+
output_file: {
|
|
165
|
+
type: "string",
|
|
166
|
+
description: "Path to the output Markdown file"
|
|
167
|
+
},
|
|
168
|
+
start_page: {
|
|
169
|
+
type: "integer",
|
|
170
|
+
description: "First page to extract (0-based index)",
|
|
171
|
+
default: 0
|
|
172
|
+
},
|
|
173
|
+
end_page: {
|
|
174
|
+
type: "integer",
|
|
175
|
+
description: "Last page to extract (-1 for last page)",
|
|
176
|
+
default: -1
|
|
177
|
+
}
|
|
178
|
+
},
|
|
179
|
+
required: ["input_file", "output_file"]
|
|
180
|
+
};
|
|
181
|
+
async process(context, params) {
|
|
182
|
+
try {
|
|
183
|
+
const inputFile = context.resolveWorkspacePath(params["input_file"]);
|
|
184
|
+
const outputFile = context.resolveWorkspacePath(params["output_file"]);
|
|
185
|
+
const buffer = await readFile(inputFile);
|
|
186
|
+
const { pages } = await extractPdfPages(buffer);
|
|
187
|
+
const startPage = params["start_page"] ?? 0;
|
|
188
|
+
const endPage = params["end_page"] ?? -1;
|
|
189
|
+
let mdText;
|
|
190
|
+
if (startPage !== 0 || endPage !== -1) {
|
|
191
|
+
const end = endPage === -1 ? pages.length - 1 : endPage;
|
|
192
|
+
mdText = pages.slice(startPage, end + 1).join("\n");
|
|
193
|
+
}
|
|
194
|
+
else {
|
|
195
|
+
mdText = pages.join("\n");
|
|
196
|
+
}
|
|
197
|
+
const parentDir = dirname(outputFile);
|
|
198
|
+
await mkdir(parentDir, { recursive: true });
|
|
199
|
+
await writeFile(outputFile, mdText, "utf-8");
|
|
200
|
+
return { output_file: outputFile };
|
|
201
|
+
}
|
|
202
|
+
catch (e) {
|
|
203
|
+
return { error: String(e instanceof Error ? e.message : e) };
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
userMessage(params) {
|
|
207
|
+
const inputFile = params["input_file"] ?? "a PDF";
|
|
208
|
+
const outputFile = params["output_file"] ?? "Markdown";
|
|
209
|
+
let msg = `Converting ${inputFile} to ${outputFile}...`;
|
|
210
|
+
if (msg.length > 80)
|
|
211
|
+
msg = `Converting PDF to ${outputFile}...`;
|
|
212
|
+
if (msg.length > 80)
|
|
213
|
+
msg = "Converting PDF to Markdown...";
|
|
214
|
+
return msg;
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
export class ConvertMarkdownToPDFTool extends Tool {
|
|
218
|
+
name = "convert_markdown_to_pdf";
|
|
219
|
+
description = "Convert Markdown to PDF using Pandoc.";
|
|
220
|
+
inputSchema = {
|
|
221
|
+
type: "object",
|
|
222
|
+
properties: {
|
|
223
|
+
input_file: {
|
|
224
|
+
type: "string",
|
|
225
|
+
description: "Path to the input Markdown file"
|
|
226
|
+
},
|
|
227
|
+
output_file: {
|
|
228
|
+
type: "string",
|
|
229
|
+
description: "Path to the output PDF file"
|
|
230
|
+
}
|
|
231
|
+
},
|
|
232
|
+
required: ["input_file", "output_file"]
|
|
233
|
+
};
|
|
234
|
+
async process(context, params) {
|
|
235
|
+
try {
|
|
236
|
+
const inputFile = context.resolveWorkspacePath(params["input_file"]);
|
|
237
|
+
const outputFile = context.resolveWorkspacePath(params["output_file"]);
|
|
238
|
+
const parentDir = dirname(outputFile);
|
|
239
|
+
await mkdir(parentDir, { recursive: true });
|
|
240
|
+
await execFileAsync("pandoc", [
|
|
241
|
+
inputFile,
|
|
242
|
+
"-f",
|
|
243
|
+
"markdown",
|
|
244
|
+
"-t",
|
|
245
|
+
"pdf",
|
|
246
|
+
"-o",
|
|
247
|
+
outputFile
|
|
248
|
+
]);
|
|
249
|
+
return { output_file: outputFile, status: "success" };
|
|
250
|
+
}
|
|
251
|
+
catch (e) {
|
|
252
|
+
return { error: String(e instanceof Error ? e.message : e) };
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
userMessage(params) {
|
|
256
|
+
const inputFile = params["input_file"] ?? "Markdown";
|
|
257
|
+
const outputFile = params["output_file"] ?? "a PDF";
|
|
258
|
+
let msg = `Converting ${inputFile} to ${outputFile}...`;
|
|
259
|
+
if (msg.length > 80)
|
|
260
|
+
msg = `Converting Markdown to ${outputFile}...`;
|
|
261
|
+
if (msg.length > 80)
|
|
262
|
+
msg = "Converting Markdown to PDF...";
|
|
263
|
+
return msg;
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
export class ConvertDocumentTool extends Tool {
|
|
267
|
+
name = "convert_document";
|
|
268
|
+
description = "Convert between document formats using Pandoc, supports markdown, docx, rst, pdf, html, etc.";
|
|
269
|
+
inputSchema = {
|
|
270
|
+
type: "object",
|
|
271
|
+
properties: {
|
|
272
|
+
input_file: {
|
|
273
|
+
type: "string",
|
|
274
|
+
description: "Path to the input file"
|
|
275
|
+
},
|
|
276
|
+
output_file: {
|
|
277
|
+
type: "string",
|
|
278
|
+
description: "Path to the output file"
|
|
279
|
+
},
|
|
280
|
+
from_format: {
|
|
281
|
+
type: "string",
|
|
282
|
+
description: "Input format (e.g., markdown, docx, rst)",
|
|
283
|
+
default: "markdown"
|
|
284
|
+
},
|
|
285
|
+
to_format: {
|
|
286
|
+
type: "string",
|
|
287
|
+
description: "Output format (e.g., pdf, docx, html)",
|
|
288
|
+
default: "pdf"
|
|
289
|
+
},
|
|
290
|
+
extra_args: {
|
|
291
|
+
type: "array",
|
|
292
|
+
description: "Additional Pandoc arguments",
|
|
293
|
+
items: { type: "string" },
|
|
294
|
+
default: []
|
|
295
|
+
}
|
|
296
|
+
},
|
|
297
|
+
required: ["input_file", "output_file"]
|
|
298
|
+
};
|
|
299
|
+
async process(context, params) {
|
|
300
|
+
try {
|
|
301
|
+
const inputFile = context.resolveWorkspacePath(params["input_file"]);
|
|
302
|
+
const outputFile = context.resolveWorkspacePath(params["output_file"]);
|
|
303
|
+
const fromFormat = params["from_format"] ?? "markdown";
|
|
304
|
+
const toFormat = params["to_format"] ?? "pdf";
|
|
305
|
+
let extraArgs = params["extra_args"] ?? [];
|
|
306
|
+
if (typeof extraArgs === "string") {
|
|
307
|
+
extraArgs = [extraArgs];
|
|
308
|
+
}
|
|
309
|
+
const parentDir = dirname(outputFile);
|
|
310
|
+
await mkdir(parentDir, { recursive: true });
|
|
311
|
+
await execFileAsync("pandoc", [
|
|
312
|
+
inputFile,
|
|
313
|
+
"-f",
|
|
314
|
+
fromFormat,
|
|
315
|
+
"-t",
|
|
316
|
+
toFormat,
|
|
317
|
+
"-o",
|
|
318
|
+
outputFile,
|
|
319
|
+
...extraArgs
|
|
320
|
+
]);
|
|
321
|
+
return { output_file: outputFile, status: "success" };
|
|
322
|
+
}
|
|
323
|
+
catch (e) {
|
|
324
|
+
return { error: String(e instanceof Error ? e.message : e) };
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
userMessage(params) {
|
|
328
|
+
const inputFile = params["input_file"] ?? "input";
|
|
329
|
+
const outputFile = params["output_file"] ?? "output";
|
|
330
|
+
const toFormat = params["to_format"] ?? "target format";
|
|
331
|
+
let msg = `Converting ${inputFile} to ${outputFile} (${toFormat})...`;
|
|
332
|
+
if (msg.length > 80)
|
|
333
|
+
msg = `Converting ${inputFile} to ${toFormat}...`;
|
|
334
|
+
if (msg.length > 80)
|
|
335
|
+
msg = `Converting document to ${toFormat}...`;
|
|
336
|
+
return msg;
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
//# sourceMappingURL=pdf-tools.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pdf-tools.js","sourceRoot":"","sources":["../../src/tools/pdf-tools.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,KAA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GAAG,GAAG,0BAA0B,QAAQ,KAAK,CAAC;QACnE,OAAO,GAAG,CAAC;IACb,CAAC;CACF"}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Incremental plan construction tools shared via a PlanBuilder state object.
|
|
3
|
+
*
|
|
4
|
+
* The LLM calls add_task repeatedly, optionally remove_task to correct a
|
|
5
|
+
* mistake, and finally finish_plan to commit. Each add_task validates the
|
|
6
|
+
* task in isolation and against previously added tasks so failures are
|
|
7
|
+
* caught at the moment they're introduced, pointing to one task rather
|
|
8
|
+
* than the whole plan.
|
|
9
|
+
*/
|
|
10
|
+
import type { ProcessingContext } from "@nodetool-ai/runtime";
|
|
11
|
+
import { Tool } from "./base-tool.js";
|
|
12
|
+
import type { Task, TaskPlan } from "../types.js";
|
|
13
|
+
export declare class PlanBuilder {
|
|
14
|
+
private readonly tasks;
|
|
15
|
+
private readonly inputKeys;
|
|
16
|
+
private committedPlan;
|
|
17
|
+
constructor(inputs?: Record<string, unknown>);
|
|
18
|
+
get currentTasks(): readonly Task[];
|
|
19
|
+
get taskCount(): number;
|
|
20
|
+
get plan(): TaskPlan | null;
|
|
21
|
+
hasTask(id: string): boolean;
|
|
22
|
+
private allStepIds;
|
|
23
|
+
addTask(params: Record<string, unknown>): {
|
|
24
|
+
ok: true;
|
|
25
|
+
task: Task;
|
|
26
|
+
} | {
|
|
27
|
+
ok: false;
|
|
28
|
+
errors: string[];
|
|
29
|
+
};
|
|
30
|
+
removeTask(id: string): {
|
|
31
|
+
ok: boolean;
|
|
32
|
+
error?: string;
|
|
33
|
+
};
|
|
34
|
+
finish(title: string): {
|
|
35
|
+
ok: true;
|
|
36
|
+
plan: TaskPlan;
|
|
37
|
+
} | {
|
|
38
|
+
ok: false;
|
|
39
|
+
errors: string[];
|
|
40
|
+
};
|
|
41
|
+
private buildTask;
|
|
42
|
+
private validateNewTask;
|
|
43
|
+
private validateFullPlan;
|
|
44
|
+
}
|
|
45
|
+
export declare class AddTaskTool extends Tool {
|
|
46
|
+
private readonly builder;
|
|
47
|
+
readonly name = "add_task";
|
|
48
|
+
readonly description: string;
|
|
49
|
+
readonly inputSchema: Record<string, unknown>;
|
|
50
|
+
constructor(builder: PlanBuilder);
|
|
51
|
+
process(_context: ProcessingContext, params: Record<string, unknown>): Promise<unknown>;
|
|
52
|
+
userMessage(params: Record<string, unknown>): string;
|
|
53
|
+
}
|
|
54
|
+
export declare class RemoveTaskTool extends Tool {
|
|
55
|
+
private readonly builder;
|
|
56
|
+
readonly name = "remove_task";
|
|
57
|
+
readonly description: string;
|
|
58
|
+
readonly inputSchema: Record<string, unknown>;
|
|
59
|
+
constructor(builder: PlanBuilder);
|
|
60
|
+
process(_context: ProcessingContext, params: Record<string, unknown>): Promise<unknown>;
|
|
61
|
+
userMessage(params: Record<string, unknown>): string;
|
|
62
|
+
}
|
|
63
|
+
export declare class FinishPlanTool extends Tool {
|
|
64
|
+
private readonly builder;
|
|
65
|
+
readonly name = "finish_plan";
|
|
66
|
+
readonly description: string;
|
|
67
|
+
readonly inputSchema: Record<string, unknown>;
|
|
68
|
+
constructor(builder: PlanBuilder);
|
|
69
|
+
process(_context: ProcessingContext, params: Record<string, unknown>): Promise<unknown>;
|
|
70
|
+
userMessage(params: Record<string, unknown>): string;
|
|
71
|
+
}
|
|
72
|
+
//# sourceMappingURL=plan-builder-tools.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plan-builder-tools.d.ts","sourceRoot":"","sources":["../../src/tools/plan-builder-tools.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAC9D,OAAO,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAC;AACtC,OAAO,KAAK,EAAQ,IAAI,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAOxD,qBAAa,WAAW;IACtB,OAAO,CAAC,QAAQ,CAAC,KAAK,CAA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