@mastra/dane 0.0.1 → 0.0.2-alpha.2

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/CHANGELOG.md ADDED
@@ -0,0 +1,37 @@
1
+ # @mastra/dane
2
+
3
+ ## 0.0.2-alpha.2
4
+
5
+ ### Patch Changes
6
+
7
+ - ad58c35: Adds a shebang to the dane entry file
8
+
9
+ ## 0.0.2-alpha.1
10
+
11
+ ### Patch Changes
12
+
13
+ - Updated dependencies [f031a1f]
14
+ - @mastra/core@0.1.27-alpha.38
15
+ - @mastra/rag@0.0.2-alpha.22
16
+ - @mastra/firecrawl@1.0.4-alpha.22
17
+ - @mastra/github@1.0.3-alpha.21
18
+ - @mastra/engine@0.0.5-alpha.32
19
+ - @mastra/memory@0.0.2-alpha.17
20
+
21
+ ## 0.0.2-alpha.0
22
+
23
+ ### Patch Changes
24
+
25
+ - b5393f1: New example: Dane and many fixes to make it work
26
+ - 697fbbe: Setup Dane, a cli assistant using the mastra framework.
27
+ - Updated dependencies [45fd5b8]
28
+ - Updated dependencies [c872875]
29
+ - Updated dependencies [f6da688]
30
+ - Updated dependencies [1cc6cc0]
31
+ - Updated dependencies [b5393f1]
32
+ - @mastra/rag@0.0.2-alpha.21
33
+ - @mastra/core@0.1.27-alpha.37
34
+ - @mastra/engine@0.0.5-alpha.31
35
+ - @mastra/firecrawl@1.0.4-alpha.21
36
+ - @mastra/memory@0.0.2-alpha.16
37
+ - @mastra/github@1.0.3-alpha.20
package/package.json CHANGED
@@ -1,20 +1,25 @@
1
1
  {
2
2
  "name": "@mastra/dane",
3
- "version": "0.0.1",
4
- "main": "index.js",
3
+ "version": "0.0.2-alpha.2",
4
+ "main": "dist/index.js",
5
+ "type": "module",
6
+ "bin": {
7
+ "dane": "./dist/index.js"
8
+ },
5
9
  "keywords": [],
6
10
  "author": "",
7
11
  "license": "ISC",
8
12
  "description": "",
9
13
  "devDependencies": {
10
14
  "@types/node": "^22.10.2",
11
- "tsx": "^4.19.2",
12
- "typescript": "^5.7.2"
15
+ "@types/pdf-parse": "^1.1.4",
16
+ "tsx": "^4.19.2"
13
17
  },
14
18
  "dependencies": {
15
19
  "boxen": "^8.0.1",
16
20
  "chalk": "^5.3.0",
17
21
  "cli-table3": "^0.6.5",
22
+ "commander": "^12.1.0",
18
23
  "execa": "^9.3.1",
19
24
  "inquirer": "^12.2.0",
20
25
  "luxon": "^3.5.0",
@@ -24,15 +29,17 @@
24
29
  "playwright": "^1.49.1",
25
30
  "playwright-core": "^1.49.1",
26
31
  "sqlite3": "^5.1.7",
32
+ "typescript": "^5.5.4",
27
33
  "zod": "^3.24.0",
28
- "@mastra/core": "0.1.27-alpha.36",
29
- "@mastra/github": "1.0.3-alpha.19",
30
- "@mastra/rag": "0.0.2-alpha.20",
31
- "@mastra/memory": "0.0.2-alpha.15",
32
- "@mastra/firecrawl": "1.0.4-alpha.20",
33
- "@mastra/engine": "0.0.5-alpha.30"
34
+ "@mastra/engine": "0.0.5-alpha.32",
35
+ "@mastra/core": "0.1.27-alpha.38",
36
+ "@mastra/github": "1.0.3-alpha.21",
37
+ "@mastra/memory": "0.0.2-alpha.17",
38
+ "@mastra/firecrawl": "1.0.4-alpha.22",
39
+ "@mastra/rag": "0.0.2-alpha.22"
34
40
  },
35
41
  "scripts": {
42
+ "build": "npx tsc",
36
43
  "issue-labeler": "npx bun src/issue-labeler.ts",
37
44
  "start": "npx bun src/index.ts",
38
45
  "test": "echo \"Error: no test specified\" && exit 1"
@@ -1,9 +1,8 @@
1
- // import inquirer from 'inquirer';
2
1
  import chalk from 'chalk';
3
2
 
4
- import { mastra } from './mastra';
3
+ import { mastra } from '../mastra/index.js';
5
4
 
6
- async function main() {
5
+ export async function issueLabelerCommand() {
7
6
  console.log(chalk.green("Hi! I'm Dane!"));
8
7
  console.log(chalk.green('Let me label this for you..\n'));
9
8
  const result = await mastra.getWorkflow('githubIssueLabeler').execute({
@@ -25,8 +24,3 @@ async function main() {
25
24
  ),
26
25
  );
27
26
  }
28
-
29
- main().catch(e => {
30
- console.error(e);
31
- process.exit(1);
32
- });
@@ -0,0 +1,16 @@
1
+ import chalk from 'chalk';
2
+
3
+ import { mastra } from '../mastra/index.js';
4
+
5
+ export async function message() {
6
+ console.log(chalk.green("Hi! I'm Dane!"));
7
+ console.log(chalk.green('What would you like to do today?\n'));
8
+ console.log(
9
+ await mastra.getWorkflow('message').execute({
10
+ triggerData: {
11
+ resourceid: 'f8b5c3a1-d6e7-4f9c-b2a3-1d8e4c7f9b5a',
12
+ threadId: '2d9e8c7f-6b5a-4d3c-8f1e-9b7d5c3a2e8h',
13
+ },
14
+ }),
15
+ );
16
+ }
package/src/index.ts CHANGED
@@ -1,19 +1,13 @@
1
- // import inquirer from 'inquirer';
2
- import chalk from 'chalk';
1
+ #! /usr/bin/env node
2
+ import { Command } from 'commander';
3
3
 
4
- import { mastra } from './mastra';
4
+ import { issueLabelerCommand } from './commands/issue-labeler.js';
5
+ import { message } from './commands/message.js';
5
6
 
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
- }
7
+ const program = new Command();
18
8
 
19
- main();
9
+ program.command('chat').action(message);
10
+
11
+ program.command('issue-labeler').action(issueLabelerCommand);
12
+
13
+ program.parse(process.argv);
@@ -1,11 +1,11 @@
1
1
  import { Agent } from '@mastra/core';
2
2
 
3
- import { browserTool, googleSearch } from '../tools/browser';
4
- import { listEvents } from '../tools/calendar';
5
- import { crawl } from '../tools/crawl';
6
- import { execaTool } from '../tools/execa';
7
- import { fsTool } from '../tools/fs';
8
- import { readPDF } from '../tools/pdf';
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
9
 
10
10
  export const daneIssueLabeler = new Agent({
11
11
  name: 'DaneIssueLabeler',
@@ -2,9 +2,9 @@ import { Mastra } from '@mastra/core';
2
2
  import { PostgresEngine } from '@mastra/engine';
3
3
  import { UpstashKVMemory } from '@mastra/memory';
4
4
 
5
- import { dane, daneIssueLabeler } from './agents';
6
- import { firecrawl } from './integrations';
7
- import { messageWorkflow, githubIssueLabeler } from './workflows';
5
+ import { dane, daneIssueLabeler } from './agents/index.js';
6
+ import { firecrawl } from './integrations/index.js';
7
+ import { messageWorkflow, githubIssueLabeler } from './workflows/index.js';
8
8
 
9
9
  const engine = new PostgresEngine({
10
10
  url: 'postgres://postgres:postgres@localhost:5433/mastra',
@@ -1,5 +1,5 @@
1
1
  import { createTool } from '@mastra/core';
2
- import { MastraDocument } from '@mastra/rag';
2
+ import { MDocument } from '@mastra/rag';
3
3
  import chalk from 'chalk';
4
4
  import { chromium } from 'playwright-core';
5
5
  import { z } from 'zod';
@@ -24,7 +24,7 @@ export const browserTool = createTool({
24
24
 
25
25
  await page.goto(url);
26
26
 
27
- const docs = MastraDocument.fromHTML(await page.content());
27
+ const docs = MDocument.fromHTML(await page.content());
28
28
 
29
29
  await docs.chunk({
30
30
  strategy: 'html',
@@ -51,8 +51,11 @@ export const browserTool = createTool({
51
51
 
52
52
  return { message: docs.getText().join('\n') };
53
53
  } catch (e) {
54
- console.log(`\n${chalk.red(e.message)}`);
55
- return { message: `Error: ${e.message}` };
54
+ if (e instanceof Error) {
55
+ console.log(`\n${chalk.red(e.message)}`);
56
+ return { message: `Error: ${e.message}` };
57
+ }
58
+ return { message: 'Error' };
56
59
  }
57
60
  },
58
61
  });
@@ -74,8 +77,11 @@ export const googleSearch = createTool({
74
77
  headless: true,
75
78
  });
76
79
  } catch (e) {
77
- console.log(`\n${chalk.red(e.message)}`);
78
- return { message: `Error: ${e.message}` };
80
+ if (e instanceof Error) {
81
+ console.log(`\n${chalk.red(e.message)}`);
82
+ return { message: `Error: ${e.message}` };
83
+ }
84
+ return { message: 'Error' };
79
85
  }
80
86
 
81
87
  try {
@@ -116,8 +122,11 @@ export const googleSearch = createTool({
116
122
 
117
123
  return { message: text.join('\n') };
118
124
  } catch (e) {
119
- console.log(`\n${chalk.red(e.message)}`);
120
- return { message: `Error: ${e.message}` };
125
+ if (e instanceof Error) {
126
+ console.log(`\n${chalk.red(e.message)}`);
127
+ return { message: `Error: ${e.message}` };
128
+ }
129
+ return { message: `Error` };
121
130
  }
122
131
  },
123
132
  });
@@ -2,7 +2,6 @@ import { createTool } from '@mastra/core';
2
2
  import chalk from 'chalk';
3
3
  import { execSync } from 'child_process';
4
4
  import Table from 'cli-table3';
5
- import * as os from 'os';
6
5
  import { z } from 'zod';
7
6
 
8
7
  interface CalendarEvent {
@@ -14,12 +13,6 @@ interface CalendarEvent {
14
13
  }
15
14
 
16
15
  class LocalCalendarReader {
17
- private platform: string;
18
-
19
- constructor() {
20
- this.platform = os.platform();
21
- }
22
-
23
16
  async getEvents(): Promise<CalendarEvent[]> {
24
17
  const script = `
25
18
  tell application "Calendar"
@@ -58,8 +51,13 @@ class LocalCalendarReader {
58
51
  const result = execSync(`osascript -e '${script}'`).toString();
59
52
  return this.parseAppleScriptOutput(result);
60
53
  } catch (error) {
61
- console.error('Raw AppleScript error:', error.message);
62
- throw new Error(`Failed to read Mac calendar: ${error.message}`);
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
+ }
63
61
  }
64
62
  }
65
63
 
@@ -73,19 +71,20 @@ class LocalCalendarReader {
73
71
  const [title, startDateStr, endDateStr, location, description] = line.split('|');
74
72
 
75
73
  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);
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 || '');
80
79
 
81
80
  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);
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 || '');
86
85
 
87
86
  const event: CalendarEvent = {
88
- title: title.trim(),
87
+ title: title?.trim()!,
89
88
  startDate,
90
89
  endDate,
91
90
  location: location?.trim() || '',
@@ -146,7 +145,9 @@ export const listEvents = createTool({
146
145
  content: JSON.stringify(events, null, 2),
147
146
  };
148
147
  } catch (e) {
149
- console.log(`\n${chalk.red(e.message)}`);
148
+ if (e instanceof Error) {
149
+ console.log(`\n${chalk.red(e.message)}`);
150
+ }
150
151
  return { content: 'Error' };
151
152
  }
152
153
  },
@@ -14,7 +14,7 @@ export const crawl = createTool({
14
14
  message: z.string(),
15
15
  }),
16
16
  execute: async ({ context, mastra }) => {
17
- await mastra?.syncs?.['FIRECRAWL:CRAWL_AND_SYNC'].execute({
17
+ await mastra?.syncs?.['FIRECRAWL:CRAWL_AND_SYNC']?.execute({
18
18
  context,
19
19
  mastra,
20
20
  });
@@ -6,7 +6,7 @@ import { z } from 'zod';
6
6
 
7
7
  // Create transform stream that applies chalk
8
8
  const colorTransform = new Transform({
9
- transform(chunk, encoding, callback) {
9
+ transform(chunk, _encoding, callback) {
10
10
  // Convert chunk to string and apply chalk
11
11
  const colored = chalk.blue(chunk.toString());
12
12
  this.push(colored);
@@ -3,7 +3,7 @@ import chalk from 'chalk';
3
3
  import inquirer from 'inquirer';
4
4
  import { z } from 'zod';
5
5
 
6
- import { dane } from '../agents';
6
+ import { dane } from '../agents/index.js';
7
7
 
8
8
  export const messageWorkflow = new Workflow({
9
9
  name: 'entry',
@@ -62,7 +62,7 @@ const messageOutputStep = new Step({
62
62
  messages = [];
63
63
  }
64
64
 
65
- const res = await mastra?.agents?.['dane'].generate(message, {
65
+ const res = await mastra?.agents?.['dane']?.generate(message, {
66
66
  stream: true,
67
67
  maxSteps: 5,
68
68
  resourceid,
@@ -85,7 +85,9 @@ const messageOutputStep = new Step({
85
85
  console.log(chalk.red(`\n`));
86
86
  console.log(chalk.red(`\n`));
87
87
  console.log(chalk.red(`Error streaming results. Let's try again.`));
88
- console.log(chalk.red(e.message));
88
+ if (e instanceof Error) {
89
+ console.log(chalk.red(e.message));
90
+ }
89
91
  }
90
92
 
91
93
  const res = await dane.generate(message, {
@@ -94,9 +96,9 @@ const messageOutputStep = new Step({
94
96
  resourceid,
95
97
  });
96
98
 
97
- console.log(chalk.green(res.text));
99
+ console.log(chalk.green(res?.text));
98
100
 
99
- return { message: res.text };
101
+ return { message: res?.text };
100
102
  },
101
103
  });
102
104
 
@@ -1,2 +1,2 @@
1
- export * from './chat';
2
- export * from './issue-labeler';
1
+ export * from './chat.js';
2
+ export * from './issue-labeler.js';
@@ -1,7 +1,7 @@
1
1
  import { Step, Workflow } from '@mastra/core';
2
2
  import { z } from 'zod';
3
3
 
4
- import { github } from '../integrations';
4
+ import { github } from '../integrations/index.js';
5
5
 
6
6
  export const githubIssueLabeler = new Workflow({
7
7
  name: 'github-issue-labeler',
@@ -24,6 +24,7 @@ const getIssue = new Step({
24
24
 
25
25
  const issue = await client.issuesGet({
26
26
  path: {
27
+ // TODO: Type triggerData in machineContext to the triggerSchema
27
28
  owner: context?.machineContext?.triggerData?.owner,
28
29
  repo: context?.machineContext?.triggerData?.repo,
29
30
  issue_number: context?.machineContext?.triggerData?.issue_number,
@@ -59,10 +60,10 @@ const labelIssue = new Step({
59
60
  const res = await daneIssueLabeler?.generate(
60
61
  `
61
62
  Hey Dane, given:
62
- * this issue title: ${parentStep?.payload?.title}
63
+ * this issue title: ${parentStep?.payload?.title}
63
64
  * this issue body: ${parentStep?.payload?.body}
64
65
  * these labels: ${parentStep?.payload?.labelNames}
65
-
66
+
66
67
  What label or labels would you assign?
67
68
  `,
68
69
  {
package/tsconfig.json ADDED
@@ -0,0 +1,11 @@
1
+ {
2
+ "extends": "../../tsconfig.json",
3
+ "compilerOptions": {
4
+ "moduleResolution": "bundler",
5
+ "outDir": "./dist",
6
+ "rootDir": "./src",
7
+ "noEmit": false
8
+ },
9
+ "include": ["src/**/*"],
10
+ "exclude": ["node_modules", "**/*.test.ts"]
11
+ }