@mastra/dane 0.0.1 → 0.0.2-alpha.10
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 +2 -0
- package/dist/commands/issue-labeler.d.ts.map +1 -0
- package/dist/commands/issue-labeler.js +34 -0
- package/dist/commands/message.d.ts +2 -0
- package/dist/commands/message.d.ts.map +1 -0
- package/dist/commands/message.js +12 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +11 -0
- package/dist/mastra/agents/index.d.ts +168 -0
- package/dist/mastra/agents/index.d.ts.map +1 -0
- package/{src/mastra/agents/index.ts → dist/mastra/agents/index.js} +31 -34
- package/dist/mastra/index.d.ts +196 -0
- package/dist/mastra/index.d.ts.map +1 -0
- package/dist/mastra/index.js +32 -0
- package/dist/mastra/integrations/index.d.ts +5 -0
- package/dist/mastra/integrations/index.d.ts.map +1 -0
- package/{src/mastra/integrations/index.ts → dist/mastra/integrations/index.js} +3 -5
- package/dist/mastra/tools/browser.d.ts +40 -0
- package/dist/mastra/tools/browser.d.ts.map +1 -0
- package/dist/mastra/tools/browser.js +116 -0
- package/dist/mastra/tools/calendar.d.ts +21 -0
- package/dist/mastra/tools/calendar.d.ts.map +1 -0
- package/dist/mastra/tools/calendar.js +134 -0
- package/dist/mastra/tools/crawl.d.ts +33 -0
- package/dist/mastra/tools/crawl.d.ts.map +1 -0
- package/dist/mastra/tools/crawl.js +24 -0
- package/dist/mastra/tools/execa.d.ts +27 -0
- package/dist/mastra/tools/execa.d.ts.map +1 -0
- package/dist/mastra/tools/execa.js +39 -0
- package/dist/mastra/tools/fs.d.ts +33 -0
- package/dist/mastra/tools/fs.d.ts.map +1 -0
- package/dist/mastra/tools/fs.js +36 -0
- package/dist/mastra/tools/pdf.d.ts +21 -0
- package/dist/mastra/tools/pdf.d.ts.map +1 -0
- package/dist/mastra/tools/pdf.js +42 -0
- package/dist/mastra/workflows/chat.d.ts +13 -0
- package/dist/mastra/workflows/chat.d.ts.map +1 -0
- package/dist/mastra/workflows/chat.js +93 -0
- package/dist/mastra/workflows/index.d.ts +3 -0
- package/dist/mastra/workflows/index.d.ts.map +1 -0
- package/dist/mastra/workflows/index.js +2 -0
- package/dist/mastra/workflows/issue-labeler.d.ts +16 -0
- package/dist/mastra/workflows/issue-labeler.d.ts.map +1 -0
- package/dist/mastra/workflows/issue-labeler.js +85 -0
- package/package.json +23 -10
- package/docker-compose.yaml +0 -22
- package/src/index.ts +0 -19
- package/src/issue-labeler.ts +0 -32
- package/src/mastra/index.ts +0 -32
- package/src/mastra/tools/browser.ts +0 -123
- package/src/mastra/tools/calendar.ts +0 -153
- 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 -109
- package/src/mastra/workflows/index.ts +0 -2
- package/src/mastra/workflows/issue-labeler.ts +0 -103
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Workflow } from '@mastra/core';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
export declare const githubIssueLabeler: Workflow<any, z.ZodObject<{
|
|
4
|
+
repo: z.ZodString;
|
|
5
|
+
owner: z.ZodString;
|
|
6
|
+
issue_number: z.ZodNumber;
|
|
7
|
+
}, "strip", z.ZodTypeAny, {
|
|
8
|
+
repo: string;
|
|
9
|
+
owner: string;
|
|
10
|
+
issue_number: number;
|
|
11
|
+
}, {
|
|
12
|
+
repo: string;
|
|
13
|
+
owner: string;
|
|
14
|
+
issue_number: number;
|
|
15
|
+
}>>;
|
|
16
|
+
//# sourceMappingURL=issue-labeler.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"issue-labeler.d.ts","sourceRoot":"","sources":["../../../src/mastra/workflows/issue-labeler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAQ,QAAQ,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAIxB,eAAO,MAAM,kBAAkB;;;;;;;;;;;;GAO7B,CAAC"}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { Step, Workflow } from '@mastra/core';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import { github } from '../integrations/index.js';
|
|
4
|
+
export const githubIssueLabeler = new Workflow({
|
|
5
|
+
name: 'github-issue-labeler',
|
|
6
|
+
triggerSchema: z.object({
|
|
7
|
+
repo: z.string(),
|
|
8
|
+
owner: z.string(),
|
|
9
|
+
issue_number: z.number(),
|
|
10
|
+
}),
|
|
11
|
+
});
|
|
12
|
+
const getIssue = new Step({
|
|
13
|
+
id: 'getIssue',
|
|
14
|
+
outputSchema: z.object({
|
|
15
|
+
title: z.string(),
|
|
16
|
+
body: z.string(),
|
|
17
|
+
labelNames: z.array(z.string()),
|
|
18
|
+
}),
|
|
19
|
+
execute: async ({ context }) => {
|
|
20
|
+
const client = await github.getApiClient();
|
|
21
|
+
const issue = await client.issuesGet({
|
|
22
|
+
path: {
|
|
23
|
+
// TODO: Type triggerData in machineContext to the triggerSchema
|
|
24
|
+
owner: context?.machineContext?.triggerData?.owner,
|
|
25
|
+
repo: context?.machineContext?.triggerData?.repo,
|
|
26
|
+
issue_number: context?.machineContext?.triggerData?.issue_number,
|
|
27
|
+
},
|
|
28
|
+
});
|
|
29
|
+
const labels = await client.issuesListLabelsForRepo({
|
|
30
|
+
path: {
|
|
31
|
+
owner: context?.machineContext?.triggerData?.owner,
|
|
32
|
+
repo: context?.machineContext?.triggerData?.repo,
|
|
33
|
+
},
|
|
34
|
+
});
|
|
35
|
+
const labelNames = labels?.data?.map(label => label.name);
|
|
36
|
+
return { title: issue?.data?.title, body: issue?.data?.body, labelNames: labelNames };
|
|
37
|
+
},
|
|
38
|
+
});
|
|
39
|
+
const labelIssue = new Step({
|
|
40
|
+
id: 'labelIssue',
|
|
41
|
+
outputSchema: z.object({
|
|
42
|
+
labels: z.array(z.string()),
|
|
43
|
+
}),
|
|
44
|
+
execute: async ({ context, mastra }) => {
|
|
45
|
+
const parentStep = context?.machineContext?.stepResults?.getIssue;
|
|
46
|
+
if (!parentStep || parentStep.status !== 'success') {
|
|
47
|
+
return { labels: [] };
|
|
48
|
+
}
|
|
49
|
+
const daneIssueLabeler = mastra?.agents?.daneIssueLabeler;
|
|
50
|
+
const res = await daneIssueLabeler?.generate(`
|
|
51
|
+
Hey Dane, given:
|
|
52
|
+
* this issue title: ${parentStep?.payload?.title}
|
|
53
|
+
* this issue body: ${parentStep?.payload?.body}
|
|
54
|
+
* these labels: ${parentStep?.payload?.labelNames}
|
|
55
|
+
|
|
56
|
+
What label or labels would you assign?
|
|
57
|
+
`, {
|
|
58
|
+
schema: z.object({
|
|
59
|
+
labels: z.array(z.string()),
|
|
60
|
+
}),
|
|
61
|
+
});
|
|
62
|
+
return { labels: res?.object?.labels };
|
|
63
|
+
},
|
|
64
|
+
});
|
|
65
|
+
const applyLabels = new Step({
|
|
66
|
+
id: 'applyLabels',
|
|
67
|
+
execute: async ({ context }) => {
|
|
68
|
+
const parentStep = context?.machineContext?.stepResults?.labelIssue;
|
|
69
|
+
if (!parentStep || parentStep.status !== 'success') {
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
const client = await github.getApiClient();
|
|
73
|
+
await client.issuesAddLabels({
|
|
74
|
+
path: {
|
|
75
|
+
owner: context?.machineContext?.triggerData?.owner,
|
|
76
|
+
repo: context?.machineContext?.triggerData?.repo,
|
|
77
|
+
issue_number: context?.machineContext?.triggerData?.issue_number,
|
|
78
|
+
},
|
|
79
|
+
body: {
|
|
80
|
+
labels: parentStep.payload.labels,
|
|
81
|
+
},
|
|
82
|
+
});
|
|
83
|
+
},
|
|
84
|
+
});
|
|
85
|
+
githubIssueLabeler.step(getIssue).then(labelIssue).then(applyLabels).commit();
|
package/package.json
CHANGED
|
@@ -1,20 +1,31 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mastra/dane",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"main": "index.js",
|
|
3
|
+
"version": "0.0.2-alpha.10",
|
|
4
|
+
"main": "dist/index.js",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"files": [
|
|
7
|
+
"dist",
|
|
8
|
+
"test",
|
|
9
|
+
"test-files"
|
|
10
|
+
],
|
|
11
|
+
"bin": {
|
|
12
|
+
"dane": "./dist/index.js"
|
|
13
|
+
},
|
|
5
14
|
"keywords": [],
|
|
6
15
|
"author": "",
|
|
7
16
|
"license": "ISC",
|
|
8
17
|
"description": "",
|
|
9
18
|
"devDependencies": {
|
|
10
19
|
"@types/node": "^22.10.2",
|
|
11
|
-
"
|
|
12
|
-
"
|
|
20
|
+
"@types/pdf-parse": "^1.1.4",
|
|
21
|
+
"tsx": "^4.19.2"
|
|
13
22
|
},
|
|
14
23
|
"dependencies": {
|
|
15
24
|
"boxen": "^8.0.1",
|
|
16
25
|
"chalk": "^5.3.0",
|
|
17
26
|
"cli-table3": "^0.6.5",
|
|
27
|
+
"commander": "^12.1.0",
|
|
28
|
+
"dotenv": "^16.4.7",
|
|
18
29
|
"execa": "^9.3.1",
|
|
19
30
|
"inquirer": "^12.2.0",
|
|
20
31
|
"luxon": "^3.5.0",
|
|
@@ -24,15 +35,17 @@
|
|
|
24
35
|
"playwright": "^1.49.1",
|
|
25
36
|
"playwright-core": "^1.49.1",
|
|
26
37
|
"sqlite3": "^5.1.7",
|
|
38
|
+
"typescript": "^5.5.4",
|
|
27
39
|
"zod": "^3.24.0",
|
|
28
|
-
"@mastra/core": "0.1.27-alpha.
|
|
29
|
-
"@mastra/
|
|
30
|
-
"@mastra/
|
|
31
|
-
"@mastra/memory": "0.0.2-alpha.
|
|
32
|
-
"@mastra/
|
|
33
|
-
"@mastra/
|
|
40
|
+
"@mastra/core": "0.1.27-alpha.42",
|
|
41
|
+
"@mastra/engine": "0.0.5-alpha.36",
|
|
42
|
+
"@mastra/github": "1.0.3-alpha.26",
|
|
43
|
+
"@mastra/memory": "0.0.2-alpha.21",
|
|
44
|
+
"@mastra/rag": "0.0.2-alpha.26",
|
|
45
|
+
"@mastra/firecrawl": "1.0.4-alpha.27"
|
|
34
46
|
},
|
|
35
47
|
"scripts": {
|
|
48
|
+
"build": "npx tsc",
|
|
36
49
|
"issue-labeler": "npx bun src/issue-labeler.ts",
|
|
37
50
|
"start": "npx bun src/index.ts",
|
|
38
51
|
"test": "echo \"Error: no test specified\" && exit 1"
|
package/docker-compose.yaml
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
services:
|
|
2
|
-
db:
|
|
3
|
-
image: pgvector/pgvector:pg16
|
|
4
|
-
container_name: 'dane-db'
|
|
5
|
-
ports:
|
|
6
|
-
- '5433:5432'
|
|
7
|
-
environment:
|
|
8
|
-
POSTGRES_USER: ${POSTGRES_USER:-postgres}
|
|
9
|
-
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-postgres}
|
|
10
|
-
POSTGRES_DB: ${POSTGRES_DB:-mastra}
|
|
11
|
-
redis:
|
|
12
|
-
image: redis
|
|
13
|
-
ports:
|
|
14
|
-
- 6379:6379
|
|
15
|
-
serverless-redis-http:
|
|
16
|
-
ports:
|
|
17
|
-
- "8079:80"
|
|
18
|
-
image: hiett/serverless-redis-http:latest
|
|
19
|
-
environment:
|
|
20
|
-
SRH_MODE: env
|
|
21
|
-
SRH_TOKEN: example_token
|
|
22
|
-
SRH_CONNECTION_STRING: "redis://redis:6379" # Using `redis` hostname since they're in the same Docker network.
|
package/src/index.ts
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
// import inquirer from 'inquirer';
|
|
2
|
-
import chalk from 'chalk';
|
|
3
|
-
|
|
4
|
-
import { mastra } from './mastra';
|
|
5
|
-
|
|
6
|
-
async function main() {
|
|
7
|
-
console.log(chalk.green("Hi! I'm Dane!"));
|
|
8
|
-
console.log(chalk.green('What would you like to do today?\n'));
|
|
9
|
-
console.log(
|
|
10
|
-
await mastra.getWorkflow('message').execute({
|
|
11
|
-
triggerData: {
|
|
12
|
-
resourceid: 'f8b5c3a1-d6e7-4f9c-b2a3-1d8e4c7f9b5a',
|
|
13
|
-
threadId: '2d9e8c7f-6b5a-4d3c-8f1e-9b7d5c3a2e8h',
|
|
14
|
-
},
|
|
15
|
-
}),
|
|
16
|
-
);
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
main();
|
package/src/issue-labeler.ts
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
// import inquirer from 'inquirer';
|
|
2
|
-
import chalk from 'chalk';
|
|
3
|
-
|
|
4
|
-
import { mastra } from './mastra';
|
|
5
|
-
|
|
6
|
-
async function main() {
|
|
7
|
-
console.log(chalk.green("Hi! I'm Dane!"));
|
|
8
|
-
console.log(chalk.green('Let me label this for you..\n'));
|
|
9
|
-
const result = await mastra.getWorkflow('githubIssueLabeler').execute({
|
|
10
|
-
triggerData: {
|
|
11
|
-
issue_number: parseInt(process.env.ISSUE_NUMBER!, 10),
|
|
12
|
-
owner: process.env.OWNER!,
|
|
13
|
-
repo: process.env.REPO!,
|
|
14
|
-
},
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
if (result.results?.labelIssue?.status !== 'success') {
|
|
18
|
-
console.error(chalk.red(`Failed to apply labels for issue: ${result.triggerData?.issue_number}`));
|
|
19
|
-
return;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
console.log(
|
|
23
|
-
chalk.green(
|
|
24
|
-
`Issue: ${result.triggerData?.issue_number} has been labeled with: ${result.results?.labelIssue?.payload?.labels.join(', ')}`,
|
|
25
|
-
),
|
|
26
|
-
);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
main().catch(e => {
|
|
30
|
-
console.error(e);
|
|
31
|
-
process.exit(1);
|
|
32
|
-
});
|
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';
|
|
6
|
-
import { firecrawl } from './integrations';
|
|
7
|
-
import { messageWorkflow, githubIssueLabeler } from './workflows';
|
|
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,123 +0,0 @@
|
|
|
1
|
-
import { createTool } from '@mastra/core';
|
|
2
|
-
import { MastraDocument } 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 = MastraDocument.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
|
-
console.log(`\n${chalk.red(e.message)}`);
|
|
55
|
-
return { message: `Error: ${e.message}` };
|
|
56
|
-
}
|
|
57
|
-
},
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
export const googleSearch = createTool({
|
|
61
|
-
id: 'googleSearch',
|
|
62
|
-
name: 'Google Search',
|
|
63
|
-
description: 'Google Search. Passes the query to Google and returns the search results.',
|
|
64
|
-
inputSchema: z.object({
|
|
65
|
-
query: z.string(),
|
|
66
|
-
}),
|
|
67
|
-
outputSchema: z.object({
|
|
68
|
-
message: z.string(),
|
|
69
|
-
}),
|
|
70
|
-
execute: async ({ context: { query } }) => {
|
|
71
|
-
let browser;
|
|
72
|
-
try {
|
|
73
|
-
browser = await chromium.launch({
|
|
74
|
-
headless: true,
|
|
75
|
-
});
|
|
76
|
-
} catch (e) {
|
|
77
|
-
console.log(`\n${chalk.red(e.message)}`);
|
|
78
|
-
return { message: `Error: ${e.message}` };
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
try {
|
|
82
|
-
const page = await browser.newPage();
|
|
83
|
-
await page.goto(`https://www.google.com/search?q=${encodeURIComponent(query)}`);
|
|
84
|
-
|
|
85
|
-
console.log(`\n`);
|
|
86
|
-
console.log(chalk.blue('Waiting for search results...'));
|
|
87
|
-
|
|
88
|
-
try {
|
|
89
|
-
await page.click('button:has-text("Accept all")', { timeout: 5000 });
|
|
90
|
-
} catch (e) {
|
|
91
|
-
// Cookie dialog didn't appear, continue
|
|
92
|
-
}
|
|
93
|
-
// Wait for results and click first organic result
|
|
94
|
-
await page.waitForSelector('#search');
|
|
95
|
-
|
|
96
|
-
const text = await page.evaluate(() => {
|
|
97
|
-
const links: string[] = [];
|
|
98
|
-
const searchResults = document.querySelectorAll('div.g a');
|
|
99
|
-
|
|
100
|
-
searchResults.forEach(link => {
|
|
101
|
-
const href = link.getAttribute('href');
|
|
102
|
-
if (href && href.startsWith('http')) {
|
|
103
|
-
links.push(href);
|
|
104
|
-
}
|
|
105
|
-
});
|
|
106
|
-
|
|
107
|
-
return links;
|
|
108
|
-
});
|
|
109
|
-
|
|
110
|
-
await page.close();
|
|
111
|
-
await browser.close();
|
|
112
|
-
|
|
113
|
-
if (!text.length) {
|
|
114
|
-
return { message: 'No results' };
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
return { message: text.join('\n') };
|
|
118
|
-
} catch (e) {
|
|
119
|
-
console.log(`\n${chalk.red(e.message)}`);
|
|
120
|
-
return { message: `Error: ${e.message}` };
|
|
121
|
-
}
|
|
122
|
-
},
|
|
123
|
-
});
|
|
@@ -1,153 +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 * as os from 'os';
|
|
6
|
-
import { z } from 'zod';
|
|
7
|
-
|
|
8
|
-
interface CalendarEvent {
|
|
9
|
-
title: string;
|
|
10
|
-
startDate: Date;
|
|
11
|
-
endDate: Date;
|
|
12
|
-
location?: string;
|
|
13
|
-
description?: string;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
class LocalCalendarReader {
|
|
17
|
-
private platform: string;
|
|
18
|
-
|
|
19
|
-
constructor() {
|
|
20
|
-
this.platform = os.platform();
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
async getEvents(): Promise<CalendarEvent[]> {
|
|
24
|
-
const script = `
|
|
25
|
-
tell application "Calendar"
|
|
26
|
-
set eventList to {}
|
|
27
|
-
set startDate to (current date) - 7 * days
|
|
28
|
-
set endDate to (current date) + 365 * days
|
|
29
|
-
|
|
30
|
-
repeat with calendarAccount in calendars
|
|
31
|
-
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)
|
|
32
|
-
end repeat
|
|
33
|
-
|
|
34
|
-
set output to ""
|
|
35
|
-
repeat with anEvent in eventList
|
|
36
|
-
set theTitle to summary of anEvent
|
|
37
|
-
set theStart to start date of anEvent as string
|
|
38
|
-
set theEnd to end date of anEvent as string
|
|
39
|
-
set theLoc to location of anEvent
|
|
40
|
-
set theDesc to description of anEvent
|
|
41
|
-
|
|
42
|
-
if theLoc is missing value then
|
|
43
|
-
set theLoc to ""
|
|
44
|
-
end if
|
|
45
|
-
if theDesc is missing value then
|
|
46
|
-
set theDesc to ""
|
|
47
|
-
end if
|
|
48
|
-
|
|
49
|
-
set output to output & theTitle & "|" & theStart & "|" & theEnd & "|" & theLoc & "|" & theDesc & "
|
|
50
|
-
"
|
|
51
|
-
end repeat
|
|
52
|
-
|
|
53
|
-
return output
|
|
54
|
-
end tell
|
|
55
|
-
`;
|
|
56
|
-
|
|
57
|
-
try {
|
|
58
|
-
const result = execSync(`osascript -e '${script}'`).toString();
|
|
59
|
-
return this.parseAppleScriptOutput(result);
|
|
60
|
-
} catch (error) {
|
|
61
|
-
console.error('Raw AppleScript error:', error.message);
|
|
62
|
-
throw new Error(`Failed to read Mac calendar: ${error.message}`);
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
private parseAppleScriptOutput(output: string): CalendarEvent[] {
|
|
67
|
-
const events: CalendarEvent[] = [];
|
|
68
|
-
|
|
69
|
-
const lines = output.split('\n').filter(line => line.trim());
|
|
70
|
-
|
|
71
|
-
for (const line of lines) {
|
|
72
|
-
try {
|
|
73
|
-
const [title, startDateStr, endDateStr, location, description] = line.split('|');
|
|
74
|
-
|
|
75
|
-
const startStandardized = startDateStr
|
|
76
|
-
.split(',')[1] // Remove day name
|
|
77
|
-
.replace(' at ', ' ') // Remove 'at'
|
|
78
|
-
.trim(); // 'January 3, 2025 9:00:00 AM'
|
|
79
|
-
const startDate = new Date(startStandardized);
|
|
80
|
-
|
|
81
|
-
const endStandardized = endDateStr
|
|
82
|
-
.split(',')[1] // Remove day name
|
|
83
|
-
.replace(' at ', ' ') // Remove 'at'
|
|
84
|
-
.trim(); // 'January 3, 2025 9:00:00 AM'
|
|
85
|
-
const endDate = new Date(endStandardized);
|
|
86
|
-
|
|
87
|
-
const event: CalendarEvent = {
|
|
88
|
-
title: title.trim(),
|
|
89
|
-
startDate,
|
|
90
|
-
endDate,
|
|
91
|
-
location: location?.trim() || '',
|
|
92
|
-
description: description?.trim() || '',
|
|
93
|
-
};
|
|
94
|
-
|
|
95
|
-
events.push(event);
|
|
96
|
-
} catch (error) {
|
|
97
|
-
console.error('Failed to parse event line:', line, error);
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
return events.sort((a, b) => a.startDate.getTime() - b.startDate.getTime());
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
const reader = new LocalCalendarReader();
|
|
106
|
-
|
|
107
|
-
export const listEvents = createTool({
|
|
108
|
-
id: 'listEvents',
|
|
109
|
-
name: 'List Events',
|
|
110
|
-
description: 'List calendar events',
|
|
111
|
-
inputSchema: z.object({
|
|
112
|
-
startDate: z.string(),
|
|
113
|
-
}),
|
|
114
|
-
outputSchema: z.object({
|
|
115
|
-
content: z.string(),
|
|
116
|
-
}),
|
|
117
|
-
execute: async () => {
|
|
118
|
-
try {
|
|
119
|
-
const events = await reader.getEvents();
|
|
120
|
-
const table = new Table({
|
|
121
|
-
head: [
|
|
122
|
-
chalk.blue('Start'),
|
|
123
|
-
chalk.blue('End'),
|
|
124
|
-
chalk.blue('Title'),
|
|
125
|
-
chalk.blue('Location'),
|
|
126
|
-
chalk.blue('Description'),
|
|
127
|
-
],
|
|
128
|
-
colWidths: [12, 15, 30, 20, 40],
|
|
129
|
-
});
|
|
130
|
-
|
|
131
|
-
events.forEach(event => {
|
|
132
|
-
if (event.title) {
|
|
133
|
-
table.push([
|
|
134
|
-
event.startDate.toISOString(),
|
|
135
|
-
event.endDate.toISOString(),
|
|
136
|
-
event.title || '',
|
|
137
|
-
event.location || '',
|
|
138
|
-
(event.description || '').substring(0, 37) + '...',
|
|
139
|
-
]);
|
|
140
|
-
}
|
|
141
|
-
});
|
|
142
|
-
|
|
143
|
-
// console.log(chalk.blue(table.toString()));
|
|
144
|
-
|
|
145
|
-
return {
|
|
146
|
-
content: JSON.stringify(events, null, 2),
|
|
147
|
-
};
|
|
148
|
-
} catch (e) {
|
|
149
|
-
console.log(`\n${chalk.red(e.message)}`);
|
|
150
|
-
return { content: 'Error' };
|
|
151
|
-
}
|
|
152
|
-
},
|
|
153
|
-
});
|
|
@@ -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
|
-
});
|