@mastra/dane 0.0.2-alpha.25 → 0.0.2-alpha.26
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/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 +9 -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 +282 -0
- package/dist/mastra/agents/index.d.ts.map +1 -0
- package/dist/mastra/agents/index.js +106 -0
- package/dist/mastra/index.d.ts +318 -0
- package/dist/mastra/index.d.ts.map +1 -0
- package/dist/mastra/index.js +34 -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 +27 -0
- package/dist/mastra/tools/execa.d.ts.map +1 -0
- package/dist/mastra/tools/execa.js +43 -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/tools/pnpm.d.ts +60 -0
- package/dist/mastra/tools/pnpm.d.ts.map +1 -0
- package/dist/mastra/tools/pnpm.js +128 -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/dist/mastra/workflows/index.js +3 -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/dist/mastra/workflows/publish-packages.d.ts +3 -0
- package/dist/mastra/workflows/publish-packages.d.ts.map +1 -0
- package/dist/mastra/workflows/publish-packages.js +188 -0
- package/package.json +4 -4
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import { createTool } from '@mastra/core';
|
|
2
|
+
import chalk from 'chalk';
|
|
3
|
+
import { execa, ExecaError } from 'execa';
|
|
4
|
+
import { readFileSync } from 'fs';
|
|
5
|
+
import path from 'path';
|
|
6
|
+
import { z } from 'zod';
|
|
7
|
+
export const pnpmBuild = createTool({
|
|
8
|
+
id: 'pnpmBuild',
|
|
9
|
+
name: 'PNPM Build Tool',
|
|
10
|
+
description: 'Used to build the pnpm module',
|
|
11
|
+
inputSchema: z.object({
|
|
12
|
+
name: z.string(),
|
|
13
|
+
packagePath: z.string(),
|
|
14
|
+
}),
|
|
15
|
+
outputSchema: z.object({
|
|
16
|
+
message: z.string(),
|
|
17
|
+
}),
|
|
18
|
+
execute: async ({ context: { name, packagePath } }) => {
|
|
19
|
+
try {
|
|
20
|
+
console.log(chalk.green(`Building: ${name} at ${packagePath}`));
|
|
21
|
+
const p = execa(`pnpm`, ['build'], {
|
|
22
|
+
stdio: 'inherit',
|
|
23
|
+
cwd: packagePath,
|
|
24
|
+
reject: false,
|
|
25
|
+
});
|
|
26
|
+
console.log(`\n`);
|
|
27
|
+
await p;
|
|
28
|
+
return { message: 'Done' };
|
|
29
|
+
}
|
|
30
|
+
catch (e) {
|
|
31
|
+
console.error(e);
|
|
32
|
+
if (e instanceof ExecaError) {
|
|
33
|
+
return { message: e.message };
|
|
34
|
+
}
|
|
35
|
+
return { message: 'Error' };
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
});
|
|
39
|
+
export const pnpmChangesetStatus = createTool({
|
|
40
|
+
id: 'pnpmChangesetStatus',
|
|
41
|
+
name: 'PNPM Changeset Status Tool',
|
|
42
|
+
description: 'Used to check which pnpm modules need to be published',
|
|
43
|
+
inputSchema: z.object({}),
|
|
44
|
+
outputSchema: z.object({
|
|
45
|
+
message: z.array(z.string()),
|
|
46
|
+
}),
|
|
47
|
+
execute: async () => {
|
|
48
|
+
try {
|
|
49
|
+
console.log('Checking');
|
|
50
|
+
const { stdout } = await execa('pnpm', ['publish', '-r', '--dry-run', '--no-git-checks'], {
|
|
51
|
+
all: true,
|
|
52
|
+
// We want to see stderr too since pnpm sometimes puts important info there
|
|
53
|
+
stderr: 'inherit',
|
|
54
|
+
});
|
|
55
|
+
const lines = stdout.split('\n');
|
|
56
|
+
const filteredLines = lines.filter(line => line.startsWith('+'));
|
|
57
|
+
const packages = filteredLines.map(line => line.trim().substring(2).split('@').slice(0, -1).join('@'));
|
|
58
|
+
return { message: packages };
|
|
59
|
+
}
|
|
60
|
+
catch (e) {
|
|
61
|
+
console.error(e);
|
|
62
|
+
if (e instanceof ExecaError) {
|
|
63
|
+
return { message: [e.message] };
|
|
64
|
+
}
|
|
65
|
+
return { message: ['Error'] };
|
|
66
|
+
}
|
|
67
|
+
},
|
|
68
|
+
});
|
|
69
|
+
export const pnpmChangesetPublish = createTool({
|
|
70
|
+
id: 'pnpmChangesetPublish',
|
|
71
|
+
name: 'PNPM Changeset Publish Tool',
|
|
72
|
+
description: 'Used to publish the pnpm module',
|
|
73
|
+
inputSchema: z.object({}),
|
|
74
|
+
outputSchema: z.object({
|
|
75
|
+
message: z.string(),
|
|
76
|
+
}),
|
|
77
|
+
execute: async () => {
|
|
78
|
+
try {
|
|
79
|
+
console.log(chalk.green(`Publishing...`));
|
|
80
|
+
const p = execa(`pnpm`, ['changeset', 'publish'], {
|
|
81
|
+
stdio: 'inherit',
|
|
82
|
+
reject: false,
|
|
83
|
+
});
|
|
84
|
+
console.log(`\n`);
|
|
85
|
+
await p;
|
|
86
|
+
return { message: 'Done' };
|
|
87
|
+
}
|
|
88
|
+
catch (e) {
|
|
89
|
+
console.error(e);
|
|
90
|
+
if (e instanceof ExecaError) {
|
|
91
|
+
return { message: e.message };
|
|
92
|
+
}
|
|
93
|
+
return { message: 'Error' };
|
|
94
|
+
}
|
|
95
|
+
},
|
|
96
|
+
});
|
|
97
|
+
export const activeDistTag = createTool({
|
|
98
|
+
id: 'activeDistTag',
|
|
99
|
+
name: 'PNPM Changeset set active tag',
|
|
100
|
+
description: 'Used to set active tag on the pnpm module',
|
|
101
|
+
inputSchema: z.object({
|
|
102
|
+
packagePath: z.string(),
|
|
103
|
+
}),
|
|
104
|
+
outputSchema: z.object({
|
|
105
|
+
message: z.string(),
|
|
106
|
+
}),
|
|
107
|
+
execute: async ({ context }) => {
|
|
108
|
+
try {
|
|
109
|
+
const pkgJson = JSON.parse(readFileSync(path.join(context.packagePath, 'package.json'), 'utf-8'));
|
|
110
|
+
const version = pkgJson.version;
|
|
111
|
+
console.log(chalk.green(`Setting active tag...`));
|
|
112
|
+
const p = execa(`npm`, ['dist-tag', `${pkgJson.name}@${version}`, `latest`], {
|
|
113
|
+
stdio: 'inherit',
|
|
114
|
+
reject: false,
|
|
115
|
+
});
|
|
116
|
+
console.log(`\n`);
|
|
117
|
+
await p;
|
|
118
|
+
return { message: 'Done' };
|
|
119
|
+
}
|
|
120
|
+
catch (e) {
|
|
121
|
+
console.error(e);
|
|
122
|
+
if (e instanceof ExecaError) {
|
|
123
|
+
return { message: e.message };
|
|
124
|
+
}
|
|
125
|
+
return { message: 'Error' };
|
|
126
|
+
}
|
|
127
|
+
},
|
|
128
|
+
});
|
|
@@ -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();
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"publish-packages.d.ts","sourceRoot":"","sources":["../../../src/mastra/workflows/publish-packages.ts"],"names":[],"mappings":"AAAA,OAAO,EAAQ,QAAQ,EAAE,MAAM,cAAc,CAAC;AAM9C,eAAO,MAAM,gBAAgB,oBAE3B,CAAC"}
|