@mastra/dane 0.0.2-alpha.2 → 0.0.2-alpha.21
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/README.md +25 -4
- package/data/crawl/conventional-commit.json +25 -0
- package/dist/commands/commit-message.d.ts +2 -0
- package/dist/commands/commit-message.d.ts.map +1 -0
- package/dist/commands/commit-message.js +31 -0
- package/dist/commands/config.d.ts +3 -0
- package/dist/commands/config.d.ts.map +1 -0
- package/dist/commands/config.js +40 -0
- 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/commands/publish-packages.d.ts +2 -0
- package/dist/commands/publish-packages.d.ts.map +1 -0
- package/dist/commands/publish-packages.js +73 -0
- package/dist/config/index.d.ts +12 -0
- package/dist/config/index.d.ts.map +1 -0
- package/dist/config/index.js +75 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +23 -0
- package/dist/mastra/agents/index.d.ts +256 -0
- package/dist/mastra/agents/index.d.ts.map +1 -0
- package/dist/mastra/agents/index.js +103 -0
- package/dist/mastra/index.d.ts +291 -0
- package/dist/mastra/index.d.ts.map +1 -0
- package/dist/mastra/index.js +32 -0
- package/dist/mastra/integrations/index.d.ts +7 -0
- package/dist/mastra/integrations/index.d.ts.map +1 -0
- package/dist/mastra/integrations/index.js +29 -0
- 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 +36 -0
- package/dist/mastra/tools/crawl.d.ts.map +1 -0
- package/dist/mastra/tools/crawl.js +26 -0
- package/dist/mastra/tools/execa.d.ts +59 -0
- package/dist/mastra/tools/execa.d.ts.map +1 -0
- package/dist/mastra/tools/execa.js +103 -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/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 +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 +89 -0
- package/dist/mastra/workflows/commit-message.d.ts +10 -0
- package/dist/mastra/workflows/commit-message.d.ts.map +1 -0
- package/dist/mastra/workflows/commit-message.js +137 -0
- package/dist/mastra/workflows/index.d.ts +4 -0
- package/dist/mastra/workflows/index.d.ts.map +1 -0
- package/{src/mastra/workflows/index.ts → dist/mastra/workflows/index.js} +1 -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 +18 -10
- package/test-files/716a95a5c57a56d32a32b1c9592d6df0.png +0 -0
- package/CHANGELOG.md +0 -37
- 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 -13
- 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/issue-labeler.ts +0 -104
- package/tsconfig.json +0 -11
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { createTool } from '@mastra/core';
|
|
2
|
+
import { readFileSync, writeFileSync } from 'fs';
|
|
3
|
+
import { z } from 'zod';
|
|
4
|
+
export const fsTool = createTool({
|
|
5
|
+
id: 'fsTool',
|
|
6
|
+
name: 'File System Tool',
|
|
7
|
+
description: 'File System Tool',
|
|
8
|
+
inputSchema: z.object({
|
|
9
|
+
action: z.string(),
|
|
10
|
+
file: z.string(),
|
|
11
|
+
data: z.string(),
|
|
12
|
+
}),
|
|
13
|
+
outputSchema: z.object({
|
|
14
|
+
message: z.string(),
|
|
15
|
+
}),
|
|
16
|
+
execute: async ({ context: { action, file, data } }) => {
|
|
17
|
+
try {
|
|
18
|
+
switch (action) {
|
|
19
|
+
case 'write':
|
|
20
|
+
writeFileSync(file, data);
|
|
21
|
+
break;
|
|
22
|
+
case 'read':
|
|
23
|
+
return { message: readFileSync(file, 'utf8') };
|
|
24
|
+
case 'append':
|
|
25
|
+
writeFileSync(file, data, { flag: 'a' });
|
|
26
|
+
break;
|
|
27
|
+
default:
|
|
28
|
+
return { message: 'Invalid action' };
|
|
29
|
+
}
|
|
30
|
+
return { message: 'Success' };
|
|
31
|
+
}
|
|
32
|
+
catch (e) {
|
|
33
|
+
return { message: 'Error' };
|
|
34
|
+
}
|
|
35
|
+
},
|
|
36
|
+
});
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
export declare const imageTool: import("@mastra/core").Tool<"imageTool", z.ZodObject<{
|
|
3
|
+
directory: z.ZodString;
|
|
4
|
+
prompt: z.ZodString;
|
|
5
|
+
}, "strip", z.ZodTypeAny, {
|
|
6
|
+
directory: string;
|
|
7
|
+
prompt: string;
|
|
8
|
+
}, {
|
|
9
|
+
directory: string;
|
|
10
|
+
prompt: string;
|
|
11
|
+
}>, z.ZodObject<{
|
|
12
|
+
message: z.ZodString;
|
|
13
|
+
}, "strip", z.ZodTypeAny, {
|
|
14
|
+
message: string;
|
|
15
|
+
}, {
|
|
16
|
+
message: string;
|
|
17
|
+
}>, import("@mastra/core").ToolExecutionContext<z.ZodObject<{
|
|
18
|
+
directory: z.ZodString;
|
|
19
|
+
prompt: z.ZodString;
|
|
20
|
+
}, "strip", z.ZodTypeAny, {
|
|
21
|
+
directory: string;
|
|
22
|
+
prompt: string;
|
|
23
|
+
}, {
|
|
24
|
+
directory: string;
|
|
25
|
+
prompt: string;
|
|
26
|
+
}>, import("@mastra/core").WorkflowContext<any>>>;
|
|
27
|
+
//# sourceMappingURL=image.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"image.d.ts","sourceRoot":"","sources":["../../../src/mastra/tools/image.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAIxB,eAAO,MAAM,SAAS;;;;;;;;;;;;;;;;;;;;;;;;iDAgCpB,CAAC"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { createTool } from '@mastra/core';
|
|
2
|
+
import chalk from 'chalk';
|
|
3
|
+
import { writeFileSync } from 'fs';
|
|
4
|
+
import { resolve } from 'path';
|
|
5
|
+
import { z } from 'zod';
|
|
6
|
+
import { stabilityai } from '../integrations/index.js';
|
|
7
|
+
export const imageTool = createTool({
|
|
8
|
+
id: 'imageTool',
|
|
9
|
+
name: 'imageTool',
|
|
10
|
+
description: 'Generate an image based on a text prompt',
|
|
11
|
+
inputSchema: z.object({
|
|
12
|
+
directory: z.string(),
|
|
13
|
+
prompt: z.string(),
|
|
14
|
+
}),
|
|
15
|
+
outputSchema: z.object({
|
|
16
|
+
message: z.string(),
|
|
17
|
+
}),
|
|
18
|
+
execute: async ({ context: { directory, prompt } }) => {
|
|
19
|
+
try {
|
|
20
|
+
console.log('\n' + chalk.blue(`Generating image...`));
|
|
21
|
+
const generateImageResult = await stabilityai.generateImage(prompt);
|
|
22
|
+
const file = resolve(directory, generateImageResult.filename);
|
|
23
|
+
writeFileSync(file, generateImageResult.buffer);
|
|
24
|
+
console.log(chalk.blue(`Successfully generated: ${file}`));
|
|
25
|
+
return {
|
|
26
|
+
message: `Successfully created ${file}`,
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
catch (e) {
|
|
30
|
+
if (e instanceof Error) {
|
|
31
|
+
console.log(`\n${chalk.red(e.message)}`);
|
|
32
|
+
return { message: e.message };
|
|
33
|
+
}
|
|
34
|
+
return { message: 'Error' };
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
});
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
export declare const readPDF: import("@mastra/core").Tool<"readPDF", z.ZodObject<{
|
|
3
|
+
pdfPath: z.ZodString;
|
|
4
|
+
}, "strip", z.ZodTypeAny, {
|
|
5
|
+
pdfPath: string;
|
|
6
|
+
}, {
|
|
7
|
+
pdfPath: string;
|
|
8
|
+
}>, z.ZodObject<{
|
|
9
|
+
content: z.ZodString;
|
|
10
|
+
}, "strip", z.ZodTypeAny, {
|
|
11
|
+
content: string;
|
|
12
|
+
}, {
|
|
13
|
+
content: string;
|
|
14
|
+
}>, import("@mastra/core").ToolExecutionContext<z.ZodObject<{
|
|
15
|
+
pdfPath: z.ZodString;
|
|
16
|
+
}, "strip", z.ZodTypeAny, {
|
|
17
|
+
pdfPath: string;
|
|
18
|
+
}, {
|
|
19
|
+
pdfPath: string;
|
|
20
|
+
}>, import("@mastra/core").WorkflowContext<any>>>;
|
|
21
|
+
//# sourceMappingURL=pdf.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pdf.d.ts","sourceRoot":"","sources":["../../../src/mastra/tools/pdf.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAKxB,eAAO,MAAM,OAAO;;;;;;;;;;;;;;;;;;iDAsClB,CAAC"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { createTool } from '@mastra/core';
|
|
2
|
+
import chalk from 'chalk';
|
|
3
|
+
import { existsSync, readFileSync } from 'fs';
|
|
4
|
+
import path from 'path';
|
|
5
|
+
import { z } from 'zod';
|
|
6
|
+
// @ts-ignore
|
|
7
|
+
import pdfParse from 'pdf-parse/lib/pdf-parse.js';
|
|
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
|
+
// Check if file is a PDF
|
|
25
|
+
if (path.extname(pdfPath).toLowerCase() !== '.pdf') {
|
|
26
|
+
throw new Error('File is not a PDF');
|
|
27
|
+
}
|
|
28
|
+
// Read the PDF file
|
|
29
|
+
const dataBuffer = readFileSync(pdfPath);
|
|
30
|
+
// Parse PDF content
|
|
31
|
+
const data = await pdfParse(dataBuffer);
|
|
32
|
+
console.log(chalk.blue('\n'));
|
|
33
|
+
console.log(chalk.blue('PDF Information:'));
|
|
34
|
+
console.log(chalk.blue('-----------------'));
|
|
35
|
+
console.log(chalk.blue(`Number of pages: ${data.numpages}`));
|
|
36
|
+
return { content: data.text };
|
|
37
|
+
}
|
|
38
|
+
catch (e) {
|
|
39
|
+
return { content: 'Error scanning PDF' };
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
});
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Workflow } from '@mastra/core';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
export declare const messageWorkflow: Workflow<any, z.ZodObject<{
|
|
4
|
+
resourceid: z.ZodString;
|
|
5
|
+
threadId: z.ZodString;
|
|
6
|
+
}, "strip", z.ZodTypeAny, {
|
|
7
|
+
resourceid: string;
|
|
8
|
+
threadId: string;
|
|
9
|
+
}, {
|
|
10
|
+
resourceid: string;
|
|
11
|
+
threadId: string;
|
|
12
|
+
}>>;
|
|
13
|
+
//# sourceMappingURL=chat.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chat.d.ts","sourceRoot":"","sources":["../../../src/mastra/workflows/chat.ts"],"names":[],"mappings":"AACA,OAAO,EAAQ,QAAQ,EAAE,MAAM,cAAc,CAAC;AAE9C,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAIxB,eAAO,MAAM,eAAe;;;;;;;;;GAM1B,CAAC"}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { input } from '@inquirer/prompts';
|
|
2
|
+
import { Step, Workflow } from '@mastra/core';
|
|
3
|
+
import chalk from 'chalk';
|
|
4
|
+
import { z } from 'zod';
|
|
5
|
+
import { dane } from '../agents/index.js';
|
|
6
|
+
export const messageWorkflow = new Workflow({
|
|
7
|
+
name: 'entry',
|
|
8
|
+
triggerSchema: z.object({
|
|
9
|
+
resourceid: z.string(),
|
|
10
|
+
threadId: z.string(),
|
|
11
|
+
}),
|
|
12
|
+
});
|
|
13
|
+
const messageStep = new Step({
|
|
14
|
+
id: 'message-input',
|
|
15
|
+
outputSchema: z.object({
|
|
16
|
+
message: z.string(),
|
|
17
|
+
}),
|
|
18
|
+
execute: async () => {
|
|
19
|
+
const content = await input({
|
|
20
|
+
message: '\n You:',
|
|
21
|
+
validate: input => input.trim().length > 0 || 'Message cannot be empty',
|
|
22
|
+
});
|
|
23
|
+
return { message: content };
|
|
24
|
+
},
|
|
25
|
+
});
|
|
26
|
+
const messageOutputStep = new Step({
|
|
27
|
+
id: 'message-output',
|
|
28
|
+
outputSchema: z.object({
|
|
29
|
+
message: z.string(),
|
|
30
|
+
}),
|
|
31
|
+
// SHOULD BE ABLE TO ACCESS ALL MASTRA PRIMS FROM EXECTUE
|
|
32
|
+
execute: async ({ context, mastra }) => {
|
|
33
|
+
// WISH THIS WAS TYPED
|
|
34
|
+
const threadId = context?.machineContext?.triggerData?.threadId;
|
|
35
|
+
const resourceid = context?.machineContext?.triggerData?.resourceid;
|
|
36
|
+
const messageInputStatus = context?.machineContext?.stepResults?.['message-input']?.status;
|
|
37
|
+
if (messageInputStatus !== 'success') {
|
|
38
|
+
return { message: 'Failure in workflow' };
|
|
39
|
+
}
|
|
40
|
+
// is there someway to know what steps are flowing into this one and type their props
|
|
41
|
+
const message = context?.machineContext?.stepResults?.['message-input']?.payload?.message;
|
|
42
|
+
try {
|
|
43
|
+
let messages = await mastra?.memory?.getContextWindow({
|
|
44
|
+
threadId,
|
|
45
|
+
format: 'core_message',
|
|
46
|
+
});
|
|
47
|
+
if (!messages || messages.length === 0) {
|
|
48
|
+
messages = [];
|
|
49
|
+
}
|
|
50
|
+
const res = await mastra?.agents?.['dane']?.generate(message, {
|
|
51
|
+
stream: true,
|
|
52
|
+
maxSteps: 5,
|
|
53
|
+
resourceid,
|
|
54
|
+
threadId,
|
|
55
|
+
context: [],
|
|
56
|
+
});
|
|
57
|
+
if (res) {
|
|
58
|
+
console.log(chalk.green(`\nDane: \n`));
|
|
59
|
+
for await (const chunk of res.textStream) {
|
|
60
|
+
process.stdout.write(chalk.green(chunk));
|
|
61
|
+
}
|
|
62
|
+
console.log(chalk.green(`\n`));
|
|
63
|
+
return { message: 'success' };
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
catch (e) {
|
|
67
|
+
console.log(chalk.red(`\n`));
|
|
68
|
+
console.log(chalk.red(`\n`));
|
|
69
|
+
console.log(chalk.red(`Error streaming results. Let's try again.`));
|
|
70
|
+
if (e instanceof Error) {
|
|
71
|
+
console.log(chalk.red(e.message));
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
const res = await dane.generate(message, {
|
|
75
|
+
maxSteps: 5,
|
|
76
|
+
threadId,
|
|
77
|
+
resourceid,
|
|
78
|
+
});
|
|
79
|
+
console.log(chalk.green(res?.text));
|
|
80
|
+
return { message: res?.text };
|
|
81
|
+
},
|
|
82
|
+
});
|
|
83
|
+
messageWorkflow
|
|
84
|
+
.step(messageStep)
|
|
85
|
+
.after(messageStep)
|
|
86
|
+
.step(messageOutputStep)
|
|
87
|
+
.after(messageOutputStep)
|
|
88
|
+
.step(messageStep)
|
|
89
|
+
.commit();
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Workflow } from '@mastra/core';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
export declare const commitMessageGenerator: Workflow<any, z.ZodObject<{
|
|
4
|
+
repoPath: z.ZodString;
|
|
5
|
+
}, "strip", z.ZodTypeAny, {
|
|
6
|
+
repoPath: string;
|
|
7
|
+
}, {
|
|
8
|
+
repoPath: string;
|
|
9
|
+
}>>;
|
|
10
|
+
//# sourceMappingURL=commit-message.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"commit-message.d.ts","sourceRoot":"","sources":["../../../src/mastra/workflows/commit-message.ts"],"names":[],"mappings":"AACA,OAAO,EAAQ,QAAQ,EAAE,MAAM,cAAc,CAAC;AAG9C,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAIxB,eAAO,MAAM,sBAAsB;;;;;;GAKjC,CAAC"}
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import { confirm } from '@inquirer/prompts';
|
|
2
|
+
import { Step, Workflow } from '@mastra/core';
|
|
3
|
+
import chalk from 'chalk';
|
|
4
|
+
import { execSync } from 'child_process';
|
|
5
|
+
import { z } from 'zod';
|
|
6
|
+
import { fsTool } from '../tools/fs.js';
|
|
7
|
+
export const commitMessageGenerator = new Workflow({
|
|
8
|
+
name: 'commit-message',
|
|
9
|
+
triggerSchema: z.object({
|
|
10
|
+
repoPath: z.string(),
|
|
11
|
+
}),
|
|
12
|
+
});
|
|
13
|
+
const getDiff = new Step({
|
|
14
|
+
id: 'getDiff',
|
|
15
|
+
outputSchema: z.object({
|
|
16
|
+
diff: z.string(),
|
|
17
|
+
}),
|
|
18
|
+
execute: async ({ context }) => {
|
|
19
|
+
const repoPath = context?.machineContext?.triggerData?.repoPath;
|
|
20
|
+
// Get the git diff of staged changes
|
|
21
|
+
const diff = execSync('git diff --staged', {
|
|
22
|
+
cwd: repoPath,
|
|
23
|
+
encoding: 'utf-8',
|
|
24
|
+
});
|
|
25
|
+
return { diff };
|
|
26
|
+
},
|
|
27
|
+
});
|
|
28
|
+
const readConventionalCommitSpec = new Step({
|
|
29
|
+
id: 'readConventionalCommitSpec',
|
|
30
|
+
outputSchema: z.object({
|
|
31
|
+
fileData: z.any(),
|
|
32
|
+
}),
|
|
33
|
+
execute: async () => {
|
|
34
|
+
const fileData = await fsTool.execute({
|
|
35
|
+
context: { action: 'read', file: 'data/crawl/conventional-commit.json', data: '' },
|
|
36
|
+
});
|
|
37
|
+
return { fileData };
|
|
38
|
+
},
|
|
39
|
+
});
|
|
40
|
+
const generateMessage = new Step({
|
|
41
|
+
id: 'generateMessage',
|
|
42
|
+
outputSchema: z.object({
|
|
43
|
+
commitMessage: z.string(),
|
|
44
|
+
generated: z.boolean(),
|
|
45
|
+
guidelines: z.array(z.string()),
|
|
46
|
+
}),
|
|
47
|
+
execute: async ({ context, mastra }) => {
|
|
48
|
+
const diffStep = context?.machineContext?.stepResults?.getDiff;
|
|
49
|
+
const fileDataStep = context?.machineContext?.stepResults?.readConventionalCommitSpec;
|
|
50
|
+
if (!diffStep || diffStep.status !== 'success') {
|
|
51
|
+
return { commitMessage: '', generated: false, guidelines: [] };
|
|
52
|
+
}
|
|
53
|
+
const daneCommitGenerator = mastra?.agents?.daneCommitMessage;
|
|
54
|
+
const res = await daneCommitGenerator?.generate(`
|
|
55
|
+
Given this git diff:
|
|
56
|
+
${diffStep.payload.diff}
|
|
57
|
+
|
|
58
|
+
IF THE DIFF IS EMPTY, RETURN "No staged changes found", AND SET GENERATED TO FALSE,
|
|
59
|
+
OTHERWISE, SET GENERATED TO TRUE
|
|
60
|
+
|
|
61
|
+
${fileDataStep?.status === 'success' && fileDataStep?.payload?.fileData?.message
|
|
62
|
+
? `USE THE FOLLOWING GUIDELINES: ${fileDataStep?.payload?.fileData?.message}`
|
|
63
|
+
: `USE THE FOLLOWING GUIDELINES:
|
|
64
|
+
- Start with a verb in the present tense
|
|
65
|
+
- Be specific but concise
|
|
66
|
+
- Focus on the "what" and "why" of the changes
|
|
67
|
+
IF THERE ARE MULTIPLE LOGICAL CHANGES, USE THE DESCRIPTION TO EXPLAIN THE CHANGES IN BULLET POINTS.
|
|
68
|
+
|
|
69
|
+
- Keep the first line under 50 characters
|
|
70
|
+
- If needed, add more detailed description after a blank line`}
|
|
71
|
+
|
|
72
|
+
RETURN THE GUIDELINES YOU ARE USING AS AN ARRAY OF STRINGS ON THE GUIDELINES KEY, AND THE COMMIT MESSAGE ON THE COMMIT MESSAGE KEY
|
|
73
|
+
`, {
|
|
74
|
+
schema: z.object({
|
|
75
|
+
commitMessage: z.string(),
|
|
76
|
+
generated: z.boolean(),
|
|
77
|
+
guidelines: z.array(z.string()),
|
|
78
|
+
}),
|
|
79
|
+
});
|
|
80
|
+
if (!res?.object?.generated) {
|
|
81
|
+
throw new Error(res?.object?.commitMessage);
|
|
82
|
+
}
|
|
83
|
+
return {
|
|
84
|
+
commitMessage: res?.object?.commitMessage,
|
|
85
|
+
generated: res?.object?.generated,
|
|
86
|
+
guidelines: res?.object?.guidelines,
|
|
87
|
+
};
|
|
88
|
+
},
|
|
89
|
+
});
|
|
90
|
+
const confirmationStep = new Step({
|
|
91
|
+
id: 'confirmation',
|
|
92
|
+
outputSchema: z.object({
|
|
93
|
+
confirm: z.boolean(),
|
|
94
|
+
}),
|
|
95
|
+
execute: async ({ context }) => {
|
|
96
|
+
const parentStep = context?.machineContext?.stepResults?.generateMessage;
|
|
97
|
+
if (!parentStep || parentStep.status !== 'success') {
|
|
98
|
+
return { confirm: false };
|
|
99
|
+
}
|
|
100
|
+
if (!parentStep.payload.generated) {
|
|
101
|
+
return { confirm: false };
|
|
102
|
+
}
|
|
103
|
+
const commitMessage = parentStep.payload.commitMessage;
|
|
104
|
+
const confirmationMessage = await confirm({
|
|
105
|
+
message: `\n Would you like to use this commit message? \n\n ${chalk.yellow(commitMessage)}\n\n`,
|
|
106
|
+
});
|
|
107
|
+
return { confirm: confirmationMessage };
|
|
108
|
+
},
|
|
109
|
+
});
|
|
110
|
+
const commitStep = new Step({
|
|
111
|
+
id: 'commit',
|
|
112
|
+
outputSchema: z.object({
|
|
113
|
+
commit: z.boolean(),
|
|
114
|
+
}),
|
|
115
|
+
execute: async ({ context }) => {
|
|
116
|
+
const parentStep = context?.machineContext?.stepResults?.confirmation;
|
|
117
|
+
if (!parentStep || parentStep.status !== 'success' || !parentStep.payload.confirm) {
|
|
118
|
+
throw new Error('Commit message generation cancelled');
|
|
119
|
+
}
|
|
120
|
+
if (context?.machineContext?.stepResults?.generateMessage?.status !== 'success') {
|
|
121
|
+
throw new Error('Failed to generate commit message');
|
|
122
|
+
}
|
|
123
|
+
const commitMessage = context?.machineContext?.stepResults?.generateMessage?.payload?.commitMessage;
|
|
124
|
+
execSync(`git commit -m "${commitMessage}"`, {
|
|
125
|
+
cwd: context?.machineContext?.triggerData?.repoPath,
|
|
126
|
+
encoding: 'utf-8',
|
|
127
|
+
});
|
|
128
|
+
return { commit: true };
|
|
129
|
+
},
|
|
130
|
+
});
|
|
131
|
+
commitMessageGenerator
|
|
132
|
+
.step(getDiff)
|
|
133
|
+
.then(readConventionalCommitSpec)
|
|
134
|
+
.then(generateMessage)
|
|
135
|
+
.then(confirmationStep)
|
|
136
|
+
.then(commitStep)
|
|
137
|
+
.commit();
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/mastra/workflows/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,oBAAoB,CAAC;AACnC,cAAc,qBAAqB,CAAC"}
|
|
@@ -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,8 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mastra/dane",
|
|
3
|
-
"version": "0.0.2-alpha.
|
|
3
|
+
"version": "0.0.2-alpha.21",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"type": "module",
|
|
6
|
+
"files": [
|
|
7
|
+
"dist",
|
|
8
|
+
"data",
|
|
9
|
+
"test",
|
|
10
|
+
"test-files"
|
|
11
|
+
],
|
|
6
12
|
"bin": {
|
|
7
13
|
"dane": "./dist/index.js"
|
|
8
14
|
},
|
|
@@ -16,12 +22,13 @@
|
|
|
16
22
|
"tsx": "^4.19.2"
|
|
17
23
|
},
|
|
18
24
|
"dependencies": {
|
|
25
|
+
"@inquirer/prompts": "^7.2.1",
|
|
19
26
|
"boxen": "^8.0.1",
|
|
20
27
|
"chalk": "^5.3.0",
|
|
21
28
|
"cli-table3": "^0.6.5",
|
|
22
29
|
"commander": "^12.1.0",
|
|
30
|
+
"dotenv": "^16.4.7",
|
|
23
31
|
"execa": "^9.3.1",
|
|
24
|
-
"inquirer": "^12.2.0",
|
|
25
32
|
"luxon": "^3.5.0",
|
|
26
33
|
"node-ical": "^0.20.1",
|
|
27
34
|
"node-screenshots": "^0.2.1",
|
|
@@ -31,17 +38,18 @@
|
|
|
31
38
|
"sqlite3": "^5.1.7",
|
|
32
39
|
"typescript": "^5.5.4",
|
|
33
40
|
"zod": "^3.24.0",
|
|
34
|
-
"@mastra/
|
|
35
|
-
"@mastra/
|
|
36
|
-
"@mastra/
|
|
37
|
-
"@mastra/
|
|
38
|
-
"@mastra/
|
|
39
|
-
"@mastra/rag": "0.0.2-alpha.
|
|
41
|
+
"@mastra/core": "0.1.27-alpha.46",
|
|
42
|
+
"@mastra/engine": "0.0.5-alpha.40",
|
|
43
|
+
"@mastra/firecrawl": "1.0.4-alpha.32",
|
|
44
|
+
"@mastra/github": "1.0.3-alpha.30",
|
|
45
|
+
"@mastra/memory": "0.0.2-alpha.26",
|
|
46
|
+
"@mastra/rag": "0.0.2-alpha.30",
|
|
47
|
+
"@mastra/stabilityai": "1.0.1-alpha.21"
|
|
40
48
|
},
|
|
41
49
|
"scripts": {
|
|
42
50
|
"build": "npx tsc",
|
|
43
|
-
"issue-labeler": "npx bun src/issue-labeler.ts",
|
|
44
51
|
"start": "npx bun src/index.ts",
|
|
45
|
-
"test": "echo \"Error: no test specified\" && exit 1"
|
|
52
|
+
"test": "echo \"Error: no test specified\" && exit 1",
|
|
53
|
+
"prepublish": "pnpm build"
|
|
46
54
|
}
|
|
47
55
|
}
|
|
Binary file
|
package/CHANGELOG.md
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
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
|