@davia/agent 0.1.0
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/LICENSE +21 -0
- package/dist/agent/agent.d.ts +13 -0
- package/dist/agent/agent.d.ts.map +1 -0
- package/dist/agent/agent.js +40 -0
- package/dist/agent/context.d.ts +9 -0
- package/dist/agent/context.d.ts.map +1 -0
- package/dist/agent/context.js +7 -0
- package/dist/agent/helpers/initialization.d.ts +30 -0
- package/dist/agent/helpers/initialization.d.ts.map +1 -0
- package/dist/agent/helpers/initialization.js +247 -0
- package/dist/agent/helpers/messages-caching-handler.d.ts +14 -0
- package/dist/agent/helpers/messages-caching-handler.d.ts.map +1 -0
- package/dist/agent/helpers/messages-caching-handler.js +162 -0
- package/dist/agent/helpers/tools.d.ts +46 -0
- package/dist/agent/helpers/tools.d.ts.map +1 -0
- package/dist/agent/helpers/tools.js +164 -0
- package/dist/agent/helpers/tree.d.ts +15 -0
- package/dist/agent/helpers/tree.d.ts.map +1 -0
- package/dist/agent/helpers/tree.js +146 -0
- package/dist/agent/middlewares/after-model.d.ts +6 -0
- package/dist/agent/middlewares/after-model.d.ts.map +1 -0
- package/dist/agent/middlewares/after-model.js +19 -0
- package/dist/agent/middlewares/initialization.d.ts +17 -0
- package/dist/agent/middlewares/initialization.d.ts.map +1 -0
- package/dist/agent/middlewares/initialization.js +93 -0
- package/dist/agent/prompts/agent.d.ts +9 -0
- package/dist/agent/prompts/agent.d.ts.map +1 -0
- package/dist/agent/prompts/agent.js +151 -0
- package/dist/agent/prompts/blocks/data.d.ts +2 -0
- package/dist/agent/prompts/blocks/data.d.ts.map +1 -0
- package/dist/agent/prompts/blocks/data.js +90 -0
- package/dist/agent/prompts/blocks/excalidraw.d.ts +2 -0
- package/dist/agent/prompts/blocks/excalidraw.d.ts.map +1 -0
- package/dist/agent/prompts/blocks/excalidraw.js +52 -0
- package/dist/agent/prompts/blocks/file_handling.d.ts +2 -0
- package/dist/agent/prompts/blocks/file_handling.d.ts.map +1 -0
- package/dist/agent/prompts/blocks/file_handling.js +29 -0
- package/dist/agent/prompts/blocks/mdx/available_packages.d.ts +2 -0
- package/dist/agent/prompts/blocks/mdx/available_packages.d.ts.map +1 -0
- package/dist/agent/prompts/blocks/mdx/available_packages.js +8 -0
- package/dist/agent/prompts/blocks/mdx/custom_components.d.ts +2 -0
- package/dist/agent/prompts/blocks/mdx/custom_components.d.ts.map +1 -0
- package/dist/agent/prompts/blocks/mdx/custom_components.js +77 -0
- package/dist/agent/prompts/blocks/mdx/davia_specific.d.ts +2 -0
- package/dist/agent/prompts/blocks/mdx/davia_specific.d.ts.map +1 -0
- package/dist/agent/prompts/blocks/mdx/davia_specific.js +116 -0
- package/dist/agent/prompts/blocks/mdx/mdx.d.ts +2 -0
- package/dist/agent/prompts/blocks/mdx/mdx.d.ts.map +1 -0
- package/dist/agent/prompts/blocks/mdx/mdx.js +91 -0
- package/dist/agent/prompts/blocks/mdx/shadcn.d.ts +2 -0
- package/dist/agent/prompts/blocks/mdx/shadcn.d.ts.map +1 -0
- package/dist/agent/prompts/blocks/mdx/shadcn.js +132 -0
- package/dist/agent/prompts/blocks/tiptap.d.ts +2 -0
- package/dist/agent/prompts/blocks/tiptap.d.ts.map +1 -0
- package/dist/agent/prompts/blocks/tiptap.js +100 -0
- package/dist/agent/prompts/index.d.ts +7 -0
- package/dist/agent/prompts/index.d.ts.map +1 -0
- package/dist/agent/prompts/index.js +6 -0
- package/dist/agent/prompts/repo_instructions.d.ts +3 -0
- package/dist/agent/prompts/repo_instructions.d.ts.map +1 -0
- package/dist/agent/prompts/repo_instructions.js +442 -0
- package/dist/agent/prompts/tool_descriptions.d.ts +4 -0
- package/dist/agent/prompts/tool_descriptions.d.ts.map +1 -0
- package/dist/agent/prompts/tool_descriptions.js +80 -0
- package/dist/agent/tools.d.ts +79 -0
- package/dist/agent/tools.d.ts.map +1 -0
- package/dist/agent/tools.js +303 -0
- package/dist/config.d.ts +16 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +108 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +3 -0
- package/dist/main.d.ts +2 -0
- package/dist/main.d.ts.map +1 -0
- package/dist/main.js +44 -0
- package/package.json +57 -0
|
@@ -0,0 +1,303 @@
|
|
|
1
|
+
import { tool } from "langchain";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
import fs from "fs-extra";
|
|
4
|
+
import * as path from "path";
|
|
5
|
+
import chalk from "chalk";
|
|
6
|
+
import { WRITE_TOOL_DESCRIPTION, SEARCH_REPLACE_TOOL_DESCRIPTION, MULTI_EDIT_TOOL_DESCRIPTION, } from "./prompts/tool_descriptions.js";
|
|
7
|
+
import { getFileCreationMessage, resolveFilePath, parseMermaidWithPuppeteer, robustSearchReplace, getAssetsPath, getBaseDestinationPath, } from "./helpers/tools.js";
|
|
8
|
+
/**
|
|
9
|
+
* Tool for writing content to a file
|
|
10
|
+
*/
|
|
11
|
+
export const writeTool = tool(async ({ filePath, content }, runtime) => {
|
|
12
|
+
try {
|
|
13
|
+
if (!runtime.context) {
|
|
14
|
+
throw new Error("Runtime context is required");
|
|
15
|
+
}
|
|
16
|
+
const context = runtime.context;
|
|
17
|
+
// Check if this is a mermaid file that needs conversion
|
|
18
|
+
const ext = path.extname(filePath).toLowerCase();
|
|
19
|
+
if (ext === ".mermaid" || ext === ".mmd") {
|
|
20
|
+
console.log(chalk.blue("Parsing mermaid to Excalidraw"));
|
|
21
|
+
// Parse mermaid to Excalidraw using Puppeteer headless browser
|
|
22
|
+
try {
|
|
23
|
+
const { elements, files } = await parseMermaidWithPuppeteer(content);
|
|
24
|
+
// Create JSON file path by replacing extension
|
|
25
|
+
const jsonFilePath = filePath.replace(/\.(mermaid|mmd)$/, ".json");
|
|
26
|
+
const absoluteJsonPath = resolveFilePath(jsonFilePath, context);
|
|
27
|
+
// Write the JSON file with elements (ensureDir is handled by outputJson)
|
|
28
|
+
const result = {
|
|
29
|
+
elements,
|
|
30
|
+
};
|
|
31
|
+
if (files)
|
|
32
|
+
result.files = files;
|
|
33
|
+
await fs.outputJson(absoluteJsonPath, result, { spaces: 2 });
|
|
34
|
+
console.log(chalk.dim(` → Converted mermaid to Excalidraw: ${jsonFilePath}`));
|
|
35
|
+
return `Converted mermaid to Excalidraw diagram. JSON saved to: ${jsonFilePath}`;
|
|
36
|
+
}
|
|
37
|
+
catch (error) {
|
|
38
|
+
console.error(chalk.red("Error parsing mermaid to Excalidraw:"), error instanceof Error ? error.message : String(error));
|
|
39
|
+
throw new Error(`Error parsing mermaid to Excalidraw. Generate JSON instead.`);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
// For isUpdate mode, ensure file exists in assets first
|
|
43
|
+
if (context.isUpdate) {
|
|
44
|
+
const assetsPath = getAssetsPath(context.projectPath);
|
|
45
|
+
const assetsFilePath = path.join(assetsPath, filePath);
|
|
46
|
+
// Check if file exists in assets, create it if it doesn't
|
|
47
|
+
const fileExists = await fs.pathExists(assetsFilePath);
|
|
48
|
+
if (!fileExists) {
|
|
49
|
+
await fs.outputFile(assetsFilePath, "");
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
// Resolve the absolute path (will use proposed or assets based on isUpdate)
|
|
53
|
+
const absolutePath = resolveFilePath(filePath, context);
|
|
54
|
+
// Write the file (ensureDir is handled by outputFile)
|
|
55
|
+
await fs.outputFile(absolutePath, content, "utf-8");
|
|
56
|
+
const message = getFileCreationMessage(filePath, context);
|
|
57
|
+
// getFileCreationMessage already includes chalk formatting, so just log it
|
|
58
|
+
console.log(message);
|
|
59
|
+
return `Successfully wrote content to ${filePath}`;
|
|
60
|
+
}
|
|
61
|
+
catch (error) {
|
|
62
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
63
|
+
throw new Error(`Error writing '${filePath}': ${errorMessage}`);
|
|
64
|
+
}
|
|
65
|
+
}, {
|
|
66
|
+
name: "write_file",
|
|
67
|
+
description: WRITE_TOOL_DESCRIPTION,
|
|
68
|
+
schema: z.object({
|
|
69
|
+
filePath: z
|
|
70
|
+
.string()
|
|
71
|
+
.describe("The relative path to the file to write (e.g., 'page1/page2/file.html', not '/page1/page2/file.html')"),
|
|
72
|
+
content: z.string().describe("The content to write to the file"),
|
|
73
|
+
}),
|
|
74
|
+
});
|
|
75
|
+
/**
|
|
76
|
+
* Tool for searching and replacing text in a file
|
|
77
|
+
*/
|
|
78
|
+
export const searchReplaceTool = tool(async ({ filePath, oldString, newString, replaceAll = false }, runtime) => {
|
|
79
|
+
try {
|
|
80
|
+
if (!runtime.context) {
|
|
81
|
+
throw new Error("Runtime context is required");
|
|
82
|
+
}
|
|
83
|
+
const context = runtime.context;
|
|
84
|
+
// Resolve the absolute path (will use proposed or assets based on isUpdate)
|
|
85
|
+
const absolutePath = resolveFilePath(filePath, context);
|
|
86
|
+
// Read the file
|
|
87
|
+
const originalContent = await fs.readFile(absolutePath, "utf-8");
|
|
88
|
+
// Perform robust search and replace
|
|
89
|
+
const { newContent, success, errorMessage } = robustSearchReplace(originalContent, oldString, newString, replaceAll);
|
|
90
|
+
if (!success) {
|
|
91
|
+
throw new Error(`Failed to replace string in file '${filePath}': ${errorMessage}`);
|
|
92
|
+
}
|
|
93
|
+
// Write the updated content back
|
|
94
|
+
await fs.writeFile(absolutePath, newContent, "utf-8");
|
|
95
|
+
return `File '${filePath}' has been edited`;
|
|
96
|
+
}
|
|
97
|
+
catch (error) {
|
|
98
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
99
|
+
throw new Error(`Error editing '${filePath}': ${errorMessage}`);
|
|
100
|
+
}
|
|
101
|
+
}, {
|
|
102
|
+
name: "search_replace",
|
|
103
|
+
description: SEARCH_REPLACE_TOOL_DESCRIPTION,
|
|
104
|
+
schema: z.object({
|
|
105
|
+
filePath: z
|
|
106
|
+
.string()
|
|
107
|
+
.describe("The relative path to the file to modify (e.g., 'page1/page2/file.html', not '/page1/page2/file.html')"),
|
|
108
|
+
oldString: z
|
|
109
|
+
.string()
|
|
110
|
+
.describe("The exact literal text to replace (including all whitespace, indentation, newlines, and surrounding code)"),
|
|
111
|
+
newString: z
|
|
112
|
+
.string()
|
|
113
|
+
.describe("The exact literal text to replace old_string with (including all whitespace, indentation, newlines, and surrounding code)"),
|
|
114
|
+
replaceAll: z
|
|
115
|
+
.boolean()
|
|
116
|
+
.optional()
|
|
117
|
+
.default(false)
|
|
118
|
+
.describe("Replace all occurrences of old_string (default false)"),
|
|
119
|
+
}),
|
|
120
|
+
});
|
|
121
|
+
/**
|
|
122
|
+
* Tool for reading file contents
|
|
123
|
+
*/
|
|
124
|
+
export const readFileTool = tool(async ({ filePath }, runtime) => {
|
|
125
|
+
try {
|
|
126
|
+
if (!runtime.context) {
|
|
127
|
+
throw new Error("Runtime context is required");
|
|
128
|
+
}
|
|
129
|
+
const context = runtime.context;
|
|
130
|
+
// If isUpdate, try to read from proposed first, then fallback to assets
|
|
131
|
+
if (context.isUpdate) {
|
|
132
|
+
// Files are at projectPath/.davia/proposed or projectPath/.davia/assets
|
|
133
|
+
const proposedPath = getBaseDestinationPath(context.projectPath, true);
|
|
134
|
+
const proposedFilePath = path.join(proposedPath, filePath);
|
|
135
|
+
try {
|
|
136
|
+
// Try to read from proposed first
|
|
137
|
+
const content = await fs.readFile(proposedFilePath, "utf-8");
|
|
138
|
+
return content;
|
|
139
|
+
}
|
|
140
|
+
catch {
|
|
141
|
+
// Fallback to assets
|
|
142
|
+
const assetsPath = getAssetsPath(context.projectPath);
|
|
143
|
+
const assetsFilePath = path.join(assetsPath, filePath);
|
|
144
|
+
const content = await fs.readFile(assetsFilePath, "utf-8");
|
|
145
|
+
return content;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
// If not isUpdate, read from assets directly
|
|
149
|
+
const assetsPath = getAssetsPath(context.projectPath);
|
|
150
|
+
const assetsFilePath = path.join(assetsPath, filePath);
|
|
151
|
+
const content = await fs.readFile(assetsFilePath, "utf-8");
|
|
152
|
+
return content;
|
|
153
|
+
}
|
|
154
|
+
catch (error) {
|
|
155
|
+
if (error instanceof Error &&
|
|
156
|
+
"code" in error &&
|
|
157
|
+
error.code === "ENOENT") {
|
|
158
|
+
throw new Error(`Path '${filePath}' not found`);
|
|
159
|
+
}
|
|
160
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
161
|
+
throw new Error(`Error reading '${filePath}': ${errorMessage}`);
|
|
162
|
+
}
|
|
163
|
+
}, {
|
|
164
|
+
name: "read_file",
|
|
165
|
+
description: "Reads and returns the complete contents of a specified file. Use this tool to read the content of a file from the filesystem. This tool reads the entire content of a file and returns it as a string. If the file is not found, it returns an error message.",
|
|
166
|
+
schema: z.object({
|
|
167
|
+
filePath: z
|
|
168
|
+
.string()
|
|
169
|
+
.describe("The relative path to the file to read (e.g., 'page1/page2/file.html', not '/page1/page2/file.html')"),
|
|
170
|
+
}),
|
|
171
|
+
});
|
|
172
|
+
/**
|
|
173
|
+
* Tool for deleting a file
|
|
174
|
+
*/
|
|
175
|
+
export const deleteTool = tool(async ({ filePath }, runtime) => {
|
|
176
|
+
try {
|
|
177
|
+
if (!runtime.context) {
|
|
178
|
+
throw new Error("Runtime context is required");
|
|
179
|
+
}
|
|
180
|
+
const context = runtime.context;
|
|
181
|
+
let deleted = false;
|
|
182
|
+
// Delete from proposed if exists
|
|
183
|
+
if (context.isUpdate) {
|
|
184
|
+
const proposedPath = getBaseDestinationPath(context.projectPath, true);
|
|
185
|
+
const proposedFilePath = path.join(proposedPath, filePath);
|
|
186
|
+
try {
|
|
187
|
+
await fs.unlink(proposedFilePath);
|
|
188
|
+
deleted = true;
|
|
189
|
+
}
|
|
190
|
+
catch {
|
|
191
|
+
// File doesn't exist in proposed, continue
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
// Delete from assets
|
|
195
|
+
const assetsPath = getAssetsPath(context.projectPath);
|
|
196
|
+
const assetsFilePath = path.join(assetsPath, filePath);
|
|
197
|
+
try {
|
|
198
|
+
await fs.unlink(assetsFilePath);
|
|
199
|
+
deleted = true;
|
|
200
|
+
}
|
|
201
|
+
catch {
|
|
202
|
+
// File doesn't exist in assets
|
|
203
|
+
}
|
|
204
|
+
if (!deleted) {
|
|
205
|
+
throw new Error(`Path '${filePath}' not found`);
|
|
206
|
+
}
|
|
207
|
+
return `File '${filePath}' has been deleted`;
|
|
208
|
+
}
|
|
209
|
+
catch (error) {
|
|
210
|
+
if (error instanceof Error &&
|
|
211
|
+
"code" in error &&
|
|
212
|
+
error.code === "ENOENT") {
|
|
213
|
+
throw new Error(`Path '${filePath}' not found`);
|
|
214
|
+
}
|
|
215
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
216
|
+
throw new Error(`Error deleting '${filePath}': ${errorMessage}`);
|
|
217
|
+
}
|
|
218
|
+
}, {
|
|
219
|
+
name: "delete_file",
|
|
220
|
+
description: "Permanently deletes a specified file from the filesystem. Use this tool to delete a file from the filesystem at the specified path.",
|
|
221
|
+
schema: z.object({
|
|
222
|
+
filePath: z
|
|
223
|
+
.string()
|
|
224
|
+
.describe("The relative path to the file to delete (e.g., 'page1/page2/file.html', not '/page1/page2/file.html')"),
|
|
225
|
+
}),
|
|
226
|
+
});
|
|
227
|
+
/**
|
|
228
|
+
* Tool for making multiple edits to a single file
|
|
229
|
+
*/
|
|
230
|
+
export const multiEditTool = tool(async ({ filePath, edits }, runtime) => {
|
|
231
|
+
try {
|
|
232
|
+
if (!runtime.context) {
|
|
233
|
+
throw new Error("Runtime context is required");
|
|
234
|
+
}
|
|
235
|
+
const context = runtime.context;
|
|
236
|
+
// Validate that edits array is not empty
|
|
237
|
+
if (!edits || edits.length === 0) {
|
|
238
|
+
throw new Error("At least one edit operation must be provided");
|
|
239
|
+
}
|
|
240
|
+
// Validate each edit operation
|
|
241
|
+
for (let i = 0; i < edits.length; i++) {
|
|
242
|
+
const edit = edits[i];
|
|
243
|
+
if (!edit) {
|
|
244
|
+
throw new Error(`Edit ${i + 1} is undefined`);
|
|
245
|
+
}
|
|
246
|
+
if (!edit.oldString || !edit.newString) {
|
|
247
|
+
throw new Error(`Edit ${i + 1} must contain 'oldString' and 'newString' fields`);
|
|
248
|
+
}
|
|
249
|
+
if (edit.oldString === edit.newString) {
|
|
250
|
+
throw new Error(`Edit ${i + 1}: oldString and newString must be different`);
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
// Resolve the absolute path (will use proposed or assets based on isUpdate)
|
|
254
|
+
const absolutePath = resolveFilePath(filePath, context);
|
|
255
|
+
// Read the file once
|
|
256
|
+
let currentContent = await fs.readFile(absolutePath, "utf-8");
|
|
257
|
+
// Apply edits sequentially
|
|
258
|
+
for (let i = 0; i < edits.length; i++) {
|
|
259
|
+
const edit = edits[i];
|
|
260
|
+
if (!edit) {
|
|
261
|
+
throw new Error(`Edit ${i + 1} is undefined`);
|
|
262
|
+
}
|
|
263
|
+
const { oldString, newString, replaceAll = false } = edit;
|
|
264
|
+
const { newContent, success, errorMessage } = robustSearchReplace(currentContent, oldString, newString, replaceAll);
|
|
265
|
+
if (!success) {
|
|
266
|
+
throw new Error(`Edit operation ${i + 1} failed: ${errorMessage}`);
|
|
267
|
+
}
|
|
268
|
+
// Update current content for next iteration
|
|
269
|
+
currentContent = newContent;
|
|
270
|
+
}
|
|
271
|
+
// Write the final content
|
|
272
|
+
await fs.writeFile(absolutePath, currentContent, "utf-8");
|
|
273
|
+
const editCount = edits.length;
|
|
274
|
+
return `File '${filePath}' has been edited with ${editCount} operation${editCount > 1 ? "s" : ""}`;
|
|
275
|
+
}
|
|
276
|
+
catch (error) {
|
|
277
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
278
|
+
throw new Error(`Error editing '${filePath}': ${errorMessage}`);
|
|
279
|
+
}
|
|
280
|
+
}, {
|
|
281
|
+
name: "multi_edit",
|
|
282
|
+
description: MULTI_EDIT_TOOL_DESCRIPTION,
|
|
283
|
+
schema: z.object({
|
|
284
|
+
filePath: z
|
|
285
|
+
.string()
|
|
286
|
+
.describe("The relative path to the file to modify (e.g., 'page1/page2/file.html', not '/page1/page2/file.html')"),
|
|
287
|
+
edits: z
|
|
288
|
+
.array(z.object({
|
|
289
|
+
oldString: z
|
|
290
|
+
.string()
|
|
291
|
+
.describe("The exact literal text to replace (including all whitespace, indentation, newlines, and surrounding code)"),
|
|
292
|
+
newString: z
|
|
293
|
+
.string()
|
|
294
|
+
.describe("The exact literal text to replace old_string with (including all whitespace, indentation, newlines, and surrounding code)"),
|
|
295
|
+
replaceAll: z
|
|
296
|
+
.boolean()
|
|
297
|
+
.optional()
|
|
298
|
+
.default(false)
|
|
299
|
+
.describe("Replace all occurrences of old_string (default false)"),
|
|
300
|
+
}))
|
|
301
|
+
.describe("Array of edit operations to perform sequentially on the file"),
|
|
302
|
+
}),
|
|
303
|
+
});
|
package/dist/config.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Maximum number of files to read from a repository
|
|
3
|
+
*/
|
|
4
|
+
export declare const MAX_FILES = 1000;
|
|
5
|
+
/**
|
|
6
|
+
* Maximum tokens allowed for the entire repository content
|
|
7
|
+
* Uses the rule of thumb: 4 characters = 1 token
|
|
8
|
+
*/
|
|
9
|
+
export declare const MAX_TOKENS = 130000;
|
|
10
|
+
/**
|
|
11
|
+
* Maximum number of graph recursion steps for LangGraph agent
|
|
12
|
+
* Default is 25, we increase it for complex documentation generation tasks
|
|
13
|
+
*/
|
|
14
|
+
export declare const GRAPH_RECURSION_LIMIT = 1000;
|
|
15
|
+
export declare const EXCLUDED_FILE_EXTENSIONS: string[];
|
|
16
|
+
//# sourceMappingURL=config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,eAAO,MAAM,SAAS,OAAQ,CAAC;AAE/B;;;GAGG;AACH,eAAO,MAAM,UAAU,SAAU,CAAC;AAElC;;;GAGG;AACH,eAAO,MAAM,qBAAqB,OAAO,CAAC;AAE1C,eAAO,MAAM,wBAAwB,UA6FpC,CAAC"}
|
package/dist/config.js
ADDED
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Maximum number of files to read from a repository
|
|
3
|
+
*/
|
|
4
|
+
export const MAX_FILES = 1_000;
|
|
5
|
+
/**
|
|
6
|
+
* Maximum tokens allowed for the entire repository content
|
|
7
|
+
* Uses the rule of thumb: 4 characters = 1 token
|
|
8
|
+
*/
|
|
9
|
+
export const MAX_TOKENS = 130_000;
|
|
10
|
+
/**
|
|
11
|
+
* Maximum number of graph recursion steps for LangGraph agent
|
|
12
|
+
* Default is 25, we increase it for complex documentation generation tasks
|
|
13
|
+
*/
|
|
14
|
+
export const GRAPH_RECURSION_LIMIT = 1000;
|
|
15
|
+
export const EXCLUDED_FILE_EXTENSIONS = [
|
|
16
|
+
".jpg",
|
|
17
|
+
".jpeg",
|
|
18
|
+
".png",
|
|
19
|
+
".gif",
|
|
20
|
+
".bmp",
|
|
21
|
+
".tiff",
|
|
22
|
+
".tif",
|
|
23
|
+
".webp",
|
|
24
|
+
".svg",
|
|
25
|
+
".ico",
|
|
26
|
+
".ttf",
|
|
27
|
+
".otf",
|
|
28
|
+
".woff",
|
|
29
|
+
".woff2",
|
|
30
|
+
".eot",
|
|
31
|
+
".exe",
|
|
32
|
+
".dll",
|
|
33
|
+
".so",
|
|
34
|
+
".dylib",
|
|
35
|
+
".bin",
|
|
36
|
+
".obj",
|
|
37
|
+
".o",
|
|
38
|
+
".a",
|
|
39
|
+
".lib",
|
|
40
|
+
".zip",
|
|
41
|
+
".tar",
|
|
42
|
+
".gz",
|
|
43
|
+
".bz2",
|
|
44
|
+
".7z",
|
|
45
|
+
".rar",
|
|
46
|
+
".xz",
|
|
47
|
+
".mp3",
|
|
48
|
+
".mp4",
|
|
49
|
+
".avi",
|
|
50
|
+
".mov",
|
|
51
|
+
".wmv",
|
|
52
|
+
".flv",
|
|
53
|
+
".mkv",
|
|
54
|
+
".webm",
|
|
55
|
+
".wav",
|
|
56
|
+
".flac",
|
|
57
|
+
".aac",
|
|
58
|
+
".ogg",
|
|
59
|
+
".m4a",
|
|
60
|
+
".pdf",
|
|
61
|
+
".doc",
|
|
62
|
+
".docx",
|
|
63
|
+
".xls",
|
|
64
|
+
".xlsx",
|
|
65
|
+
".ppt",
|
|
66
|
+
".pptx",
|
|
67
|
+
".db",
|
|
68
|
+
".sqlite",
|
|
69
|
+
".sqlite3",
|
|
70
|
+
".mdb",
|
|
71
|
+
".accdb",
|
|
72
|
+
".log",
|
|
73
|
+
".logs",
|
|
74
|
+
".cache",
|
|
75
|
+
".tmp",
|
|
76
|
+
".temp",
|
|
77
|
+
".swp",
|
|
78
|
+
".swo",
|
|
79
|
+
".bak",
|
|
80
|
+
".pyc",
|
|
81
|
+
".min.js",
|
|
82
|
+
".min.css",
|
|
83
|
+
".bundle.js",
|
|
84
|
+
".chunk.js",
|
|
85
|
+
".dat",
|
|
86
|
+
".data",
|
|
87
|
+
".dump",
|
|
88
|
+
".backup",
|
|
89
|
+
".pem",
|
|
90
|
+
".key",
|
|
91
|
+
".crt",
|
|
92
|
+
".cer",
|
|
93
|
+
".p12",
|
|
94
|
+
".pfx",
|
|
95
|
+
".csv",
|
|
96
|
+
".tsv",
|
|
97
|
+
".json",
|
|
98
|
+
".xml",
|
|
99
|
+
".vscode",
|
|
100
|
+
".idea",
|
|
101
|
+
".sublime-project",
|
|
102
|
+
".sublime-workspace",
|
|
103
|
+
".DS_Store",
|
|
104
|
+
"Thumbs.db",
|
|
105
|
+
".directory",
|
|
106
|
+
".lock",
|
|
107
|
+
".pid",
|
|
108
|
+
];
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AACrC,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AACpD,cAAc,0BAA0B,CAAC"}
|
package/dist/index.js
ADDED
package/dist/main.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"main.d.ts","sourceRoot":"","sources":["../src/main.ts"],"names":[],"mappings":"AAIA,wBAAsB,QAAQ,CAC5B,SAAS,EAAE,MAAM,EACjB,WAAW,EAAE,MAAM,EACnB,QAAQ,EAAE,OAAO,EACjB,KAAK,EAAE,WAAW,GAAG,QAAQ,GAAG,QAAQ,EACxC,sBAAsB,CAAC,EAAE,MAAM,GAC9B,OAAO,CAAC,IAAI,CAAC,CAiDf"}
|
package/dist/main.js
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { createDaviaAgent } from "./agent/agent.js";
|
|
2
|
+
import { GRAPH_RECURSION_LIMIT } from "./config.js";
|
|
3
|
+
import chalk from "chalk";
|
|
4
|
+
export async function runAgent(projectId, projectPath, isUpdate, model, additionalInstructions) {
|
|
5
|
+
console.log(chalk.blue.bold("\n🚀 Starting Davia Agent"));
|
|
6
|
+
console.log(chalk.dim(` Project Path: ${projectPath}`));
|
|
7
|
+
console.log(chalk.dim(` Model: ${chalk.bold(model)}`));
|
|
8
|
+
try {
|
|
9
|
+
// Create the agent with the specified model
|
|
10
|
+
const agent = await createDaviaAgent(model);
|
|
11
|
+
// Build the user message
|
|
12
|
+
let userMessage = `Please analyze the source files, perform any necessary transformations, and write the results following the guidelines.`;
|
|
13
|
+
// Append user's documentation goal if provided
|
|
14
|
+
if (additionalInstructions) {
|
|
15
|
+
const goalPrefix = isUpdate
|
|
16
|
+
? "User's documentation update goal:"
|
|
17
|
+
: "User's documentation goal:";
|
|
18
|
+
userMessage += `\n\n**${goalPrefix}** ${additionalInstructions}\n\nPlease prioritize and incorporate this context when generating the documentation.`;
|
|
19
|
+
}
|
|
20
|
+
// Invoke the agent with the initial task
|
|
21
|
+
await agent.invoke({
|
|
22
|
+
messages: [
|
|
23
|
+
{
|
|
24
|
+
role: "user",
|
|
25
|
+
content: userMessage,
|
|
26
|
+
},
|
|
27
|
+
],
|
|
28
|
+
}, {
|
|
29
|
+
recursionLimit: GRAPH_RECURSION_LIMIT,
|
|
30
|
+
context: {
|
|
31
|
+
projectId,
|
|
32
|
+
projectPath,
|
|
33
|
+
isUpdate,
|
|
34
|
+
modelName: model,
|
|
35
|
+
},
|
|
36
|
+
});
|
|
37
|
+
console.log(chalk.green.bold("\n✅ Agent completed successfully!"));
|
|
38
|
+
}
|
|
39
|
+
catch (error) {
|
|
40
|
+
console.error(chalk.red.bold("\n❌ Agent failed with error:"));
|
|
41
|
+
console.error(chalk.red(error instanceof Error ? error.message : String(error)));
|
|
42
|
+
throw error;
|
|
43
|
+
}
|
|
44
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@davia/agent",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"description": "AI agent for Davia documentation",
|
|
6
|
+
"homepage": "https://davia.ai",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "https://github.com/davia-labs/davia.git"
|
|
10
|
+
},
|
|
11
|
+
"bugs": {
|
|
12
|
+
"url": "https://github.com/davialabs/davia/issues"
|
|
13
|
+
},
|
|
14
|
+
"publishConfig": {
|
|
15
|
+
"access": "public"
|
|
16
|
+
},
|
|
17
|
+
"type": "module",
|
|
18
|
+
"main": "./dist/index.js",
|
|
19
|
+
"types": "./dist/index.d.ts",
|
|
20
|
+
"exports": {
|
|
21
|
+
".": {
|
|
22
|
+
"types": "./dist/index.d.ts",
|
|
23
|
+
"default": "./dist/index.js"
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
"files": [
|
|
27
|
+
"dist"
|
|
28
|
+
],
|
|
29
|
+
"dependencies": {
|
|
30
|
+
"@langchain/anthropic": "^1.1.0",
|
|
31
|
+
"@langchain/core": "^1.0.6",
|
|
32
|
+
"@langchain/google-genai": "^1.0.2",
|
|
33
|
+
"@langchain/langgraph": "^1.0.2",
|
|
34
|
+
"@langchain/openai": "^1.1.2",
|
|
35
|
+
"chalk": "^5.6.2",
|
|
36
|
+
"fs-extra": "^11.3.2",
|
|
37
|
+
"ignore": "^7.0.5",
|
|
38
|
+
"langchain": "^1.0.6",
|
|
39
|
+
"puppeteer": "^24.29.1",
|
|
40
|
+
"zod": "^4.1.12"
|
|
41
|
+
},
|
|
42
|
+
"devDependencies": {
|
|
43
|
+
"@types/fs-extra": "^11.0.4",
|
|
44
|
+
"@types/node": "^22.15.3",
|
|
45
|
+
"eslint": "^9.38.0",
|
|
46
|
+
"tsx": "^4.19.2",
|
|
47
|
+
"typescript": "5.9.2",
|
|
48
|
+
"@repo/typescript-config": "0.0.0",
|
|
49
|
+
"@repo/eslint-config": "0.0.0"
|
|
50
|
+
},
|
|
51
|
+
"scripts": {
|
|
52
|
+
"dev": "tsx watch src/index.ts",
|
|
53
|
+
"build": "tsc",
|
|
54
|
+
"lint": "eslint --max-warnings 0",
|
|
55
|
+
"check-types": "tsc --noEmit"
|
|
56
|
+
}
|
|
57
|
+
}
|