@mastra/dane 0.0.2-alpha.0 → 0.0.2-alpha.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/commands/issue-labeler.d.ts +1 -0
- package/dist/commands/issue-labeler.d.ts.map +1 -0
- package/dist/commands/issue-labeler.js +17 -1
- package/dist/commands/message.d.ts +1 -0
- package/dist/commands/message.d.ts.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +4 -0
- package/dist/mastra/agents/index.d.ts +26 -0
- package/dist/mastra/agents/index.d.ts.map +1 -0
- package/dist/mastra/agents/index.js +5 -0
- package/dist/mastra/index.d.ts +27 -1
- package/dist/mastra/index.d.ts.map +1 -0
- package/dist/mastra/index.js +5 -2
- package/dist/mastra/integrations/index.d.ts +3 -0
- package/dist/mastra/integrations/index.d.ts.map +1 -0
- package/dist/mastra/integrations/index.js +6 -0
- package/dist/mastra/tools/browser.d.ts +1 -0
- package/dist/mastra/tools/browser.d.ts.map +1 -0
- package/dist/mastra/tools/browser.js +10 -12
- package/dist/mastra/tools/calendar.d.ts +1 -0
- package/dist/mastra/tools/calendar.d.ts.map +1 -0
- package/dist/mastra/tools/crawl.d.ts +1 -0
- package/dist/mastra/tools/crawl.d.ts.map +1 -0
- package/dist/mastra/tools/execa.d.ts +1 -0
- package/dist/mastra/tools/execa.d.ts.map +1 -0
- package/dist/mastra/tools/execa.js +4 -1
- package/dist/mastra/tools/fs.d.ts +1 -0
- package/dist/mastra/tools/fs.d.ts.map +1 -0
- package/dist/mastra/tools/image.d.ts +27 -0
- package/dist/mastra/tools/image.d.ts.map +1 -0
- package/dist/mastra/tools/image.js +37 -0
- package/dist/mastra/tools/pdf.d.ts +1 -0
- package/dist/mastra/tools/pdf.d.ts.map +1 -0
- package/dist/mastra/tools/pdf.js +3 -2
- package/dist/mastra/workflows/chat.d.ts +1 -0
- package/dist/mastra/workflows/chat.d.ts.map +1 -0
- package/dist/mastra/workflows/index.d.ts +1 -0
- package/dist/mastra/workflows/index.d.ts.map +1 -0
- package/dist/mastra/workflows/issue-labeler.d.ts +1 -0
- package/dist/mastra/workflows/issue-labeler.d.ts.map +1 -0
- package/package.json +14 -7
- package/test-files/716a95a5c57a56d32a32b1c9592d6df0.png +0 -0
- package/CHANGELOG.md +0 -19
- package/docker-compose.yaml +0 -22
- package/src/commands/issue-labeler.ts +0 -26
- package/src/commands/message.ts +0 -16
- package/src/index.ts +0 -12
- package/src/mastra/agents/index.ts +0 -79
- package/src/mastra/index.ts +0 -32
- package/src/mastra/integrations/index.ts +0 -14
- package/src/mastra/tools/browser.ts +0 -132
- package/src/mastra/tools/calendar.ts +0 -154
- package/src/mastra/tools/crawl.ts +0 -26
- package/src/mastra/tools/execa.ts +0 -41
- package/src/mastra/tools/fs.ts +0 -36
- package/src/mastra/tools/pdf.ts +0 -46
- package/src/mastra/workflows/chat.ts +0 -111
- package/src/mastra/workflows/index.ts +0 -2
- package/src/mastra/workflows/issue-labeler.ts +0 -104
- package/tsconfig.json +0 -11
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
import { Agent } from '@mastra/core';
|
|
2
|
-
|
|
3
|
-
import { browserTool, googleSearch } from '../tools/browser.js';
|
|
4
|
-
import { listEvents } from '../tools/calendar.js';
|
|
5
|
-
import { crawl } from '../tools/crawl.js';
|
|
6
|
-
import { execaTool } from '../tools/execa.js';
|
|
7
|
-
import { fsTool } from '../tools/fs.js';
|
|
8
|
-
import { readPDF } from '../tools/pdf.js';
|
|
9
|
-
|
|
10
|
-
export const daneIssueLabeler = new Agent({
|
|
11
|
-
name: 'DaneIssueLabeler',
|
|
12
|
-
instructions: `
|
|
13
|
-
You are Dane, the ultimate GitHub operator.
|
|
14
|
-
You help engineers label their issues.
|
|
15
|
-
`,
|
|
16
|
-
model: {
|
|
17
|
-
provider: 'ANTHROPIC',
|
|
18
|
-
toolChoice: 'auto',
|
|
19
|
-
name: 'claude-3-5-sonnet-20241022',
|
|
20
|
-
},
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
export const dane = new Agent({
|
|
24
|
-
name: 'Dane',
|
|
25
|
-
instructions: `
|
|
26
|
-
You are Dane, my assistant and one of my best friends. We are an ace team!
|
|
27
|
-
You help me with my code, write tests, and even deploy my code to the cloud!
|
|
28
|
-
|
|
29
|
-
DO NOT ATTEMPT TO USE GENERAL KNOWLEDGE! We are only as good as the tools we use.
|
|
30
|
-
|
|
31
|
-
# Our tools:
|
|
32
|
-
|
|
33
|
-
## readPDF
|
|
34
|
-
Makes you a powerful agent capable of reading PDF files.
|
|
35
|
-
|
|
36
|
-
## fsTool
|
|
37
|
-
Makes you a powerful agent capable of reading and writing files to the local filesystem.
|
|
38
|
-
|
|
39
|
-
## execaTool
|
|
40
|
-
Makes you a powerful agent capabale of executing files on the local system.
|
|
41
|
-
|
|
42
|
-
## googleSearch
|
|
43
|
-
Makes you a powerful agent capabale answering all questions by finding the answer on Google search.
|
|
44
|
-
Pass the query as a JS object. If you have links, ALWAYS CITE YOUR SOURCES.
|
|
45
|
-
|
|
46
|
-
## browserTool
|
|
47
|
-
Makes you a powerful agent capable of scraping the web. Pass the url as a JS object.
|
|
48
|
-
|
|
49
|
-
## listEvents
|
|
50
|
-
Makes you a powerful agent capable of listing events on a calendar. When using this tool ONLY RETURN RELEVANT EVENTS.
|
|
51
|
-
DO NOT ATTEMPT TO DO ANYTHING MORE.
|
|
52
|
-
|
|
53
|
-
## crawl
|
|
54
|
-
Use this when the user asks you to crawl. CRAWL is the signal to use this tool.
|
|
55
|
-
Makes you a powerful agent capable of crawling a site and extracting markdown metadata.
|
|
56
|
-
The data will be stored in a database. Confirm that it is sucessful.
|
|
57
|
-
|
|
58
|
-
# Rules
|
|
59
|
-
* DO NOT ATTEMPT TO USE GENERAL KNOWLEDGE. Use the 'googleSearch' tool to find the answer.
|
|
60
|
-
* Don't reference tools when you communicate with the user. Do not mention what tools you are using.
|
|
61
|
-
* Tell the user what you are doing.
|
|
62
|
-
`,
|
|
63
|
-
model: {
|
|
64
|
-
provider: 'ANTHROPIC',
|
|
65
|
-
toolChoice: 'auto',
|
|
66
|
-
name: 'claude-3-5-sonnet-20241022',
|
|
67
|
-
},
|
|
68
|
-
tools: {
|
|
69
|
-
fsTool,
|
|
70
|
-
execaTool,
|
|
71
|
-
browserTool,
|
|
72
|
-
googleSearch,
|
|
73
|
-
readPDF,
|
|
74
|
-
listEvents,
|
|
75
|
-
crawl,
|
|
76
|
-
// TODO I SHOULD BE ABLE TO PASS A WORKFLOW EXECUTE HERE
|
|
77
|
-
// browserAgentRelay,
|
|
78
|
-
},
|
|
79
|
-
});
|
package/src/mastra/index.ts
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import { Mastra } from '@mastra/core';
|
|
2
|
-
import { PostgresEngine } from '@mastra/engine';
|
|
3
|
-
import { UpstashKVMemory } from '@mastra/memory';
|
|
4
|
-
|
|
5
|
-
import { dane, daneIssueLabeler } from './agents/index.js';
|
|
6
|
-
import { firecrawl } from './integrations/index.js';
|
|
7
|
-
import { messageWorkflow, githubIssueLabeler } from './workflows/index.js';
|
|
8
|
-
|
|
9
|
-
const engine = new PostgresEngine({
|
|
10
|
-
url: 'postgres://postgres:postgres@localhost:5433/mastra',
|
|
11
|
-
});
|
|
12
|
-
|
|
13
|
-
export const mastra = new Mastra({
|
|
14
|
-
agents: {
|
|
15
|
-
dane,
|
|
16
|
-
daneIssueLabeler,
|
|
17
|
-
},
|
|
18
|
-
engine,
|
|
19
|
-
memory: new UpstashKVMemory({
|
|
20
|
-
url: 'http://localhost:8079',
|
|
21
|
-
token: `example_token`,
|
|
22
|
-
maxTokens: 39000,
|
|
23
|
-
}),
|
|
24
|
-
workflows: {
|
|
25
|
-
message: messageWorkflow,
|
|
26
|
-
githubIssueLabeler: githubIssueLabeler,
|
|
27
|
-
},
|
|
28
|
-
logger: false,
|
|
29
|
-
syncs: {
|
|
30
|
-
...firecrawl.getSyncs(),
|
|
31
|
-
},
|
|
32
|
-
});
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { FirecrawlIntegration } from "@mastra/firecrawl";
|
|
2
|
-
import { GithubIntegration } from "@mastra/github";
|
|
3
|
-
|
|
4
|
-
export const firecrawl = new FirecrawlIntegration({
|
|
5
|
-
config: {
|
|
6
|
-
API_KEY: process.env.FIRECRAWL_API_KEY!,
|
|
7
|
-
},
|
|
8
|
-
});
|
|
9
|
-
|
|
10
|
-
export const github = new GithubIntegration({
|
|
11
|
-
config: {
|
|
12
|
-
PERSONAL_ACCESS_TOKEN: process.env.GITHUB_PERSONAL_ACCESS_TOKEN!,
|
|
13
|
-
}
|
|
14
|
-
})
|
|
@@ -1,132 +0,0 @@
|
|
|
1
|
-
import { createTool } from '@mastra/core';
|
|
2
|
-
import { MDocument } from '@mastra/rag';
|
|
3
|
-
import chalk from 'chalk';
|
|
4
|
-
import { chromium } from 'playwright-core';
|
|
5
|
-
import { z } from 'zod';
|
|
6
|
-
|
|
7
|
-
export const browserTool = createTool({
|
|
8
|
-
id: 'browserTool',
|
|
9
|
-
name: 'Browser Tool',
|
|
10
|
-
description: 'Browser Tool, opens a browser and navigates to a url capturing the content',
|
|
11
|
-
inputSchema: z.object({
|
|
12
|
-
url: z.string(),
|
|
13
|
-
}),
|
|
14
|
-
outputSchema: z.object({
|
|
15
|
-
message: z.string(),
|
|
16
|
-
}),
|
|
17
|
-
execute: async ({ context: { url } }) => {
|
|
18
|
-
try {
|
|
19
|
-
const browser = await chromium.launch({
|
|
20
|
-
headless: true,
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
const page = await browser.newPage();
|
|
24
|
-
|
|
25
|
-
await page.goto(url);
|
|
26
|
-
|
|
27
|
-
const docs = MDocument.fromHTML(await page.content());
|
|
28
|
-
|
|
29
|
-
await docs.chunk({
|
|
30
|
-
strategy: 'html',
|
|
31
|
-
options: {
|
|
32
|
-
chunkSize: 300,
|
|
33
|
-
sections: [
|
|
34
|
-
['h1', 'Header 1'],
|
|
35
|
-
['h2', 'Header 2'],
|
|
36
|
-
['h3', 'Header 3'],
|
|
37
|
-
['h4', 'Header 4'],
|
|
38
|
-
['h5', 'Header 5'],
|
|
39
|
-
['h6', 'Header 6'],
|
|
40
|
-
['p', 'Paragraph'],
|
|
41
|
-
],
|
|
42
|
-
},
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
await page.close();
|
|
46
|
-
await browser.close();
|
|
47
|
-
|
|
48
|
-
if (!docs.getText().length) {
|
|
49
|
-
return { message: 'No content' };
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
return { message: docs.getText().join('\n') };
|
|
53
|
-
} catch (e) {
|
|
54
|
-
if (e instanceof Error) {
|
|
55
|
-
console.log(`\n${chalk.red(e.message)}`);
|
|
56
|
-
return { message: `Error: ${e.message}` };
|
|
57
|
-
}
|
|
58
|
-
return { message: 'Error' };
|
|
59
|
-
}
|
|
60
|
-
},
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
export const googleSearch = createTool({
|
|
64
|
-
id: 'googleSearch',
|
|
65
|
-
name: 'Google Search',
|
|
66
|
-
description: 'Google Search. Passes the query to Google and returns the search results.',
|
|
67
|
-
inputSchema: z.object({
|
|
68
|
-
query: z.string(),
|
|
69
|
-
}),
|
|
70
|
-
outputSchema: z.object({
|
|
71
|
-
message: z.string(),
|
|
72
|
-
}),
|
|
73
|
-
execute: async ({ context: { query } }) => {
|
|
74
|
-
let browser;
|
|
75
|
-
try {
|
|
76
|
-
browser = await chromium.launch({
|
|
77
|
-
headless: true,
|
|
78
|
-
});
|
|
79
|
-
} catch (e) {
|
|
80
|
-
if (e instanceof Error) {
|
|
81
|
-
console.log(`\n${chalk.red(e.message)}`);
|
|
82
|
-
return { message: `Error: ${e.message}` };
|
|
83
|
-
}
|
|
84
|
-
return { message: 'Error' };
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
try {
|
|
88
|
-
const page = await browser.newPage();
|
|
89
|
-
await page.goto(`https://www.google.com/search?q=${encodeURIComponent(query)}`);
|
|
90
|
-
|
|
91
|
-
console.log(`\n`);
|
|
92
|
-
console.log(chalk.blue('Waiting for search results...'));
|
|
93
|
-
|
|
94
|
-
try {
|
|
95
|
-
await page.click('button:has-text("Accept all")', { timeout: 5000 });
|
|
96
|
-
} catch (e) {
|
|
97
|
-
// Cookie dialog didn't appear, continue
|
|
98
|
-
}
|
|
99
|
-
// Wait for results and click first organic result
|
|
100
|
-
await page.waitForSelector('#search');
|
|
101
|
-
|
|
102
|
-
const text = await page.evaluate(() => {
|
|
103
|
-
const links: string[] = [];
|
|
104
|
-
const searchResults = document.querySelectorAll('div.g a');
|
|
105
|
-
|
|
106
|
-
searchResults.forEach(link => {
|
|
107
|
-
const href = link.getAttribute('href');
|
|
108
|
-
if (href && href.startsWith('http')) {
|
|
109
|
-
links.push(href);
|
|
110
|
-
}
|
|
111
|
-
});
|
|
112
|
-
|
|
113
|
-
return links;
|
|
114
|
-
});
|
|
115
|
-
|
|
116
|
-
await page.close();
|
|
117
|
-
await browser.close();
|
|
118
|
-
|
|
119
|
-
if (!text.length) {
|
|
120
|
-
return { message: 'No results' };
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
return { message: text.join('\n') };
|
|
124
|
-
} catch (e) {
|
|
125
|
-
if (e instanceof Error) {
|
|
126
|
-
console.log(`\n${chalk.red(e.message)}`);
|
|
127
|
-
return { message: `Error: ${e.message}` };
|
|
128
|
-
}
|
|
129
|
-
return { message: `Error` };
|
|
130
|
-
}
|
|
131
|
-
},
|
|
132
|
-
});
|
|
@@ -1,154 +0,0 @@
|
|
|
1
|
-
import { createTool } from '@mastra/core';
|
|
2
|
-
import chalk from 'chalk';
|
|
3
|
-
import { execSync } from 'child_process';
|
|
4
|
-
import Table from 'cli-table3';
|
|
5
|
-
import { z } from 'zod';
|
|
6
|
-
|
|
7
|
-
interface CalendarEvent {
|
|
8
|
-
title: string;
|
|
9
|
-
startDate: Date;
|
|
10
|
-
endDate: Date;
|
|
11
|
-
location?: string;
|
|
12
|
-
description?: string;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
class LocalCalendarReader {
|
|
16
|
-
async getEvents(): Promise<CalendarEvent[]> {
|
|
17
|
-
const script = `
|
|
18
|
-
tell application "Calendar"
|
|
19
|
-
set eventList to {}
|
|
20
|
-
set startDate to (current date) - 7 * days
|
|
21
|
-
set endDate to (current date) + 365 * days
|
|
22
|
-
|
|
23
|
-
repeat with calendarAccount in calendars
|
|
24
|
-
set eventList to eventList & (every event of calendarAccount whose start date is greater than or equal to startDate and start date is less than or equal to endDate)
|
|
25
|
-
end repeat
|
|
26
|
-
|
|
27
|
-
set output to ""
|
|
28
|
-
repeat with anEvent in eventList
|
|
29
|
-
set theTitle to summary of anEvent
|
|
30
|
-
set theStart to start date of anEvent as string
|
|
31
|
-
set theEnd to end date of anEvent as string
|
|
32
|
-
set theLoc to location of anEvent
|
|
33
|
-
set theDesc to description of anEvent
|
|
34
|
-
|
|
35
|
-
if theLoc is missing value then
|
|
36
|
-
set theLoc to ""
|
|
37
|
-
end if
|
|
38
|
-
if theDesc is missing value then
|
|
39
|
-
set theDesc to ""
|
|
40
|
-
end if
|
|
41
|
-
|
|
42
|
-
set output to output & theTitle & "|" & theStart & "|" & theEnd & "|" & theLoc & "|" & theDesc & "
|
|
43
|
-
"
|
|
44
|
-
end repeat
|
|
45
|
-
|
|
46
|
-
return output
|
|
47
|
-
end tell
|
|
48
|
-
`;
|
|
49
|
-
|
|
50
|
-
try {
|
|
51
|
-
const result = execSync(`osascript -e '${script}'`).toString();
|
|
52
|
-
return this.parseAppleScriptOutput(result);
|
|
53
|
-
} catch (error) {
|
|
54
|
-
if (error instanceof Error) {
|
|
55
|
-
console.error('Raw AppleScript error:', error.message);
|
|
56
|
-
throw new Error(`Failed to read Mac calendar: ${error.message}`);
|
|
57
|
-
} else {
|
|
58
|
-
console.error('An unknown error occurred:', error);
|
|
59
|
-
throw new Error('Failed to read Mac calendar');
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
private parseAppleScriptOutput(output: string): CalendarEvent[] {
|
|
65
|
-
const events: CalendarEvent[] = [];
|
|
66
|
-
|
|
67
|
-
const lines = output.split('\n').filter(line => line.trim());
|
|
68
|
-
|
|
69
|
-
for (const line of lines) {
|
|
70
|
-
try {
|
|
71
|
-
const [title, startDateStr, endDateStr, location, description] = line.split('|');
|
|
72
|
-
|
|
73
|
-
const startStandardized = startDateStr
|
|
74
|
-
?.split(',')?.[1] // Remove day name
|
|
75
|
-
?.replace(' at ', ' ') // Remove 'at'
|
|
76
|
-
?.trim(); // 'January 3, 2025 9:00:00 AM'
|
|
77
|
-
|
|
78
|
-
const startDate = new Date(startStandardized || '');
|
|
79
|
-
|
|
80
|
-
const endStandardized = endDateStr
|
|
81
|
-
?.split(',')?.[1] // Remove day name
|
|
82
|
-
?.replace(' at ', ' ') // Remove 'at'
|
|
83
|
-
?.trim(); // 'January 3, 2025 9:00:00 AM'
|
|
84
|
-
const endDate = new Date(endStandardized || '');
|
|
85
|
-
|
|
86
|
-
const event: CalendarEvent = {
|
|
87
|
-
title: title?.trim()!,
|
|
88
|
-
startDate,
|
|
89
|
-
endDate,
|
|
90
|
-
location: location?.trim() || '',
|
|
91
|
-
description: description?.trim() || '',
|
|
92
|
-
};
|
|
93
|
-
|
|
94
|
-
events.push(event);
|
|
95
|
-
} catch (error) {
|
|
96
|
-
console.error('Failed to parse event line:', line, error);
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
return events.sort((a, b) => a.startDate.getTime() - b.startDate.getTime());
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
const reader = new LocalCalendarReader();
|
|
105
|
-
|
|
106
|
-
export const listEvents = createTool({
|
|
107
|
-
id: 'listEvents',
|
|
108
|
-
name: 'List Events',
|
|
109
|
-
description: 'List calendar events',
|
|
110
|
-
inputSchema: z.object({
|
|
111
|
-
startDate: z.string(),
|
|
112
|
-
}),
|
|
113
|
-
outputSchema: z.object({
|
|
114
|
-
content: z.string(),
|
|
115
|
-
}),
|
|
116
|
-
execute: async () => {
|
|
117
|
-
try {
|
|
118
|
-
const events = await reader.getEvents();
|
|
119
|
-
const table = new Table({
|
|
120
|
-
head: [
|
|
121
|
-
chalk.blue('Start'),
|
|
122
|
-
chalk.blue('End'),
|
|
123
|
-
chalk.blue('Title'),
|
|
124
|
-
chalk.blue('Location'),
|
|
125
|
-
chalk.blue('Description'),
|
|
126
|
-
],
|
|
127
|
-
colWidths: [12, 15, 30, 20, 40],
|
|
128
|
-
});
|
|
129
|
-
|
|
130
|
-
events.forEach(event => {
|
|
131
|
-
if (event.title) {
|
|
132
|
-
table.push([
|
|
133
|
-
event.startDate.toISOString(),
|
|
134
|
-
event.endDate.toISOString(),
|
|
135
|
-
event.title || '',
|
|
136
|
-
event.location || '',
|
|
137
|
-
(event.description || '').substring(0, 37) + '...',
|
|
138
|
-
]);
|
|
139
|
-
}
|
|
140
|
-
});
|
|
141
|
-
|
|
142
|
-
// console.log(chalk.blue(table.toString()));
|
|
143
|
-
|
|
144
|
-
return {
|
|
145
|
-
content: JSON.stringify(events, null, 2),
|
|
146
|
-
};
|
|
147
|
-
} catch (e) {
|
|
148
|
-
if (e instanceof Error) {
|
|
149
|
-
console.log(`\n${chalk.red(e.message)}`);
|
|
150
|
-
}
|
|
151
|
-
return { content: 'Error' };
|
|
152
|
-
}
|
|
153
|
-
},
|
|
154
|
-
});
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { createTool } from '@mastra/core';
|
|
2
|
-
import { z } from 'zod';
|
|
3
|
-
|
|
4
|
-
export const crawl = createTool({
|
|
5
|
-
id: 'crawler',
|
|
6
|
-
name: 'Crawler Tool',
|
|
7
|
-
description: 'Crawler Tool to crawl a website and return the content',
|
|
8
|
-
inputSchema: z.object({
|
|
9
|
-
url: z.string(),
|
|
10
|
-
limit: z.number().default(3),
|
|
11
|
-
pathRegex: z.string().nullable(),
|
|
12
|
-
}),
|
|
13
|
-
outputSchema: z.object({
|
|
14
|
-
message: z.string(),
|
|
15
|
-
}),
|
|
16
|
-
execute: async ({ context, mastra }) => {
|
|
17
|
-
await mastra?.syncs?.['FIRECRAWL:CRAWL_AND_SYNC']?.execute({
|
|
18
|
-
context,
|
|
19
|
-
mastra,
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
return {
|
|
23
|
-
message: 'The website has been successfully crawled and chunks have been synced to the database. Finish.',
|
|
24
|
-
};
|
|
25
|
-
},
|
|
26
|
-
});
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import { createTool } from '@mastra/core';
|
|
2
|
-
import chalk from 'chalk';
|
|
3
|
-
import { execa } from 'execa';
|
|
4
|
-
import { Transform } from 'stream';
|
|
5
|
-
import { z } from 'zod';
|
|
6
|
-
|
|
7
|
-
// Create transform stream that applies chalk
|
|
8
|
-
const colorTransform = new Transform({
|
|
9
|
-
transform(chunk, _encoding, callback) {
|
|
10
|
-
// Convert chunk to string and apply chalk
|
|
11
|
-
const colored = chalk.blue(chunk.toString());
|
|
12
|
-
this.push(colored);
|
|
13
|
-
callback();
|
|
14
|
-
},
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
export const execaTool = createTool({
|
|
18
|
-
id: 'execaTool',
|
|
19
|
-
name: 'Execa System Tool',
|
|
20
|
-
description: 'Execa System Tool',
|
|
21
|
-
inputSchema: z.object({
|
|
22
|
-
command: z.string(),
|
|
23
|
-
args: z.array(z.string()),
|
|
24
|
-
}),
|
|
25
|
-
outputSchema: z.object({
|
|
26
|
-
message: z.string(),
|
|
27
|
-
}),
|
|
28
|
-
execute: async ({ context: { command, args } }) => {
|
|
29
|
-
try {
|
|
30
|
-
const p = execa(command, args);
|
|
31
|
-
console.log(`\n`);
|
|
32
|
-
p.stdout.pipe(colorTransform).pipe(process.stdout);
|
|
33
|
-
p.stderr.pipe(colorTransform).pipe(process.stderr);
|
|
34
|
-
const r = await p;
|
|
35
|
-
|
|
36
|
-
return { message: r.stdout };
|
|
37
|
-
} catch (e) {
|
|
38
|
-
return { message: 'Error' };
|
|
39
|
-
}
|
|
40
|
-
},
|
|
41
|
-
});
|
package/src/mastra/tools/fs.ts
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import { createTool } from '@mastra/core';
|
|
2
|
-
import { readFileSync, writeFileSync } from 'fs';
|
|
3
|
-
import { z } from 'zod';
|
|
4
|
-
|
|
5
|
-
export const fsTool = createTool({
|
|
6
|
-
id: 'fsTool',
|
|
7
|
-
name: 'File System Tool',
|
|
8
|
-
description: 'File System Tool',
|
|
9
|
-
inputSchema: z.object({
|
|
10
|
-
action: z.string(),
|
|
11
|
-
file: z.string(),
|
|
12
|
-
data: z.string(),
|
|
13
|
-
}),
|
|
14
|
-
outputSchema: z.object({
|
|
15
|
-
message: z.string(),
|
|
16
|
-
}),
|
|
17
|
-
execute: async ({ context: { action, file, data } }) => {
|
|
18
|
-
try {
|
|
19
|
-
switch (action) {
|
|
20
|
-
case 'write':
|
|
21
|
-
writeFileSync(file, data);
|
|
22
|
-
break;
|
|
23
|
-
case 'read':
|
|
24
|
-
return { message: readFileSync(file, 'utf8') };
|
|
25
|
-
case 'append':
|
|
26
|
-
writeFileSync(file, data, { flag: 'a' });
|
|
27
|
-
break;
|
|
28
|
-
default:
|
|
29
|
-
return { message: 'Invalid action' };
|
|
30
|
-
}
|
|
31
|
-
return { message: 'Success' };
|
|
32
|
-
} catch (e) {
|
|
33
|
-
return { message: 'Error' };
|
|
34
|
-
}
|
|
35
|
-
},
|
|
36
|
-
});
|
package/src/mastra/tools/pdf.ts
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import { createTool } from '@mastra/core';
|
|
2
|
-
import chalk from 'chalk';
|
|
3
|
-
import { existsSync, readFileSync } from 'fs';
|
|
4
|
-
import path from 'path';
|
|
5
|
-
import pdf from 'pdf-parse';
|
|
6
|
-
import { z } from 'zod';
|
|
7
|
-
|
|
8
|
-
export const readPDF = createTool({
|
|
9
|
-
id: 'readPDF',
|
|
10
|
-
name: 'Read PDF',
|
|
11
|
-
description: 'Read PDF file and extract information',
|
|
12
|
-
inputSchema: z.object({
|
|
13
|
-
pdfPath: z.string(),
|
|
14
|
-
}),
|
|
15
|
-
outputSchema: z.object({
|
|
16
|
-
content: z.string(),
|
|
17
|
-
}),
|
|
18
|
-
execute: async ({ context: { pdfPath } }) => {
|
|
19
|
-
try {
|
|
20
|
-
// Check if file exists
|
|
21
|
-
if (!existsSync(pdfPath)) {
|
|
22
|
-
throw new Error('PDF file not found');
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
// Check if file is a PDF
|
|
26
|
-
if (path.extname(pdfPath).toLowerCase() !== '.pdf') {
|
|
27
|
-
throw new Error('File is not a PDF');
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
// Read the PDF file
|
|
31
|
-
const dataBuffer = readFileSync(pdfPath);
|
|
32
|
-
|
|
33
|
-
// Parse PDF content
|
|
34
|
-
const data = await pdf(dataBuffer);
|
|
35
|
-
|
|
36
|
-
console.log(chalk.blue('\n'));
|
|
37
|
-
console.log(chalk.blue('PDF Information:'));
|
|
38
|
-
console.log(chalk.blue('-----------------'));
|
|
39
|
-
console.log(chalk.blue(`Number of pages: ${data.numpages}`));
|
|
40
|
-
|
|
41
|
-
return { content: data.text };
|
|
42
|
-
} catch (e) {
|
|
43
|
-
return { content: 'Error scanning PDF' };
|
|
44
|
-
}
|
|
45
|
-
},
|
|
46
|
-
});
|
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
import { Step, Workflow } from '@mastra/core';
|
|
2
|
-
import chalk from 'chalk';
|
|
3
|
-
import inquirer from 'inquirer';
|
|
4
|
-
import { z } from 'zod';
|
|
5
|
-
|
|
6
|
-
import { dane } from '../agents/index.js';
|
|
7
|
-
|
|
8
|
-
export const messageWorkflow = new Workflow({
|
|
9
|
-
name: 'entry',
|
|
10
|
-
triggerSchema: z.object({
|
|
11
|
-
resourceid: z.string(),
|
|
12
|
-
threadId: z.string(),
|
|
13
|
-
}),
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
const messageStep = new Step({
|
|
17
|
-
id: 'message-input',
|
|
18
|
-
outputSchema: z.object({
|
|
19
|
-
message: z.string(),
|
|
20
|
-
}),
|
|
21
|
-
execute: async () => {
|
|
22
|
-
const { content } = await inquirer.prompt([
|
|
23
|
-
{
|
|
24
|
-
type: 'input',
|
|
25
|
-
name: 'content',
|
|
26
|
-
message: '\n You:',
|
|
27
|
-
validate: input => input.trim().length > 0 || 'Message cannot be empty',
|
|
28
|
-
},
|
|
29
|
-
]);
|
|
30
|
-
|
|
31
|
-
return { message: content };
|
|
32
|
-
},
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
const messageOutputStep = new Step({
|
|
36
|
-
id: 'message-output',
|
|
37
|
-
outputSchema: z.object({
|
|
38
|
-
message: z.string(),
|
|
39
|
-
}),
|
|
40
|
-
// SHOULD BE ABLE TO ACCESS ALL MASTRA PRIMS FROM EXECTUE
|
|
41
|
-
execute: async ({ context, mastra }) => {
|
|
42
|
-
// WISH THIS WAS TYPED
|
|
43
|
-
const threadId = context?.machineContext?.triggerData?.threadId;
|
|
44
|
-
const resourceid = context?.machineContext?.triggerData?.resourceid;
|
|
45
|
-
|
|
46
|
-
const messageInputStatus = context?.machineContext?.stepResults?.['message-input']?.status;
|
|
47
|
-
|
|
48
|
-
if (messageInputStatus !== 'success') {
|
|
49
|
-
return { message: 'Failure in workflow' };
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
// is there someway to know what steps are flowing into this one and type their props
|
|
53
|
-
const message = context?.machineContext?.stepResults?.['message-input']?.payload?.message;
|
|
54
|
-
|
|
55
|
-
try {
|
|
56
|
-
let messages = await mastra?.memory?.getContextWindow({
|
|
57
|
-
threadId,
|
|
58
|
-
format: 'core_message',
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
if (!messages || messages.length === 0) {
|
|
62
|
-
messages = [];
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
const res = await mastra?.agents?.['dane']?.generate(message, {
|
|
66
|
-
stream: true,
|
|
67
|
-
maxSteps: 5,
|
|
68
|
-
resourceid,
|
|
69
|
-
threadId,
|
|
70
|
-
context: [],
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
if (res) {
|
|
74
|
-
console.log(chalk.green(`\nDane: \n`));
|
|
75
|
-
|
|
76
|
-
for await (const chunk of res.textStream) {
|
|
77
|
-
process.stdout.write(chalk.green(chunk));
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
console.log(chalk.green(`\n`));
|
|
81
|
-
|
|
82
|
-
return { message: 'success' };
|
|
83
|
-
}
|
|
84
|
-
} catch (e) {
|
|
85
|
-
console.log(chalk.red(`\n`));
|
|
86
|
-
console.log(chalk.red(`\n`));
|
|
87
|
-
console.log(chalk.red(`Error streaming results. Let's try again.`));
|
|
88
|
-
if (e instanceof Error) {
|
|
89
|
-
console.log(chalk.red(e.message));
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
const res = await dane.generate(message, {
|
|
94
|
-
maxSteps: 5,
|
|
95
|
-
threadId,
|
|
96
|
-
resourceid,
|
|
97
|
-
});
|
|
98
|
-
|
|
99
|
-
console.log(chalk.green(res?.text));
|
|
100
|
-
|
|
101
|
-
return { message: res?.text };
|
|
102
|
-
},
|
|
103
|
-
});
|
|
104
|
-
|
|
105
|
-
messageWorkflow
|
|
106
|
-
.step(messageStep)
|
|
107
|
-
.after(messageStep)
|
|
108
|
-
.step(messageOutputStep)
|
|
109
|
-
.after(messageOutputStep)
|
|
110
|
-
.step(messageStep)
|
|
111
|
-
.commit();
|