@mastra/dane 0.0.2-alpha.5 → 0.0.2-alpha.50

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.
Files changed (68) hide show
  1. package/README.md +25 -4
  2. package/data/crawl/conventional-commit.json +25 -0
  3. package/dist/commands/commit-message.d.ts +2 -0
  4. package/dist/commands/commit-message.d.ts.map +1 -0
  5. package/dist/commands/commit-message.js +32 -0
  6. package/dist/commands/config.d.ts +3 -0
  7. package/dist/commands/config.d.ts.map +1 -0
  8. package/dist/commands/config.js +40 -0
  9. package/dist/commands/issue-labeler.d.ts.map +1 -1
  10. package/dist/commands/issue-labeler.js +19 -2
  11. package/dist/commands/message.d.ts.map +1 -1
  12. package/dist/commands/message.js +3 -1
  13. package/dist/commands/publish-packages.d.ts +2 -0
  14. package/dist/commands/publish-packages.d.ts.map +1 -0
  15. package/dist/commands/publish-packages.js +10 -0
  16. package/dist/commands/telephone-game.d.ts +2 -0
  17. package/dist/commands/telephone-game.d.ts.map +1 -0
  18. package/dist/commands/telephone-game.js +32 -0
  19. package/dist/config/index.d.ts +12 -0
  20. package/dist/config/index.d.ts.map +1 -0
  21. package/dist/config/index.js +75 -0
  22. package/dist/index.d.ts +1 -1
  23. package/dist/index.js +19 -2
  24. package/dist/mastra/agents/index.d.ts +114 -0
  25. package/dist/mastra/agents/index.d.ts.map +1 -1
  26. package/dist/mastra/agents/index.js +54 -24
  27. package/dist/mastra/index.d.ts +124 -1
  28. package/dist/mastra/index.d.ts.map +1 -1
  29. package/dist/mastra/index.js +9 -3
  30. package/dist/mastra/integrations/index.d.ts +2 -0
  31. package/dist/mastra/integrations/index.d.ts.map +1 -1
  32. package/dist/mastra/integrations/index.js +19 -2
  33. package/dist/mastra/tools/crawl.d.ts +3 -0
  34. package/dist/mastra/tools/crawl.d.ts.map +1 -1
  35. package/dist/mastra/tools/crawl.js +4 -2
  36. package/dist/mastra/tools/execa.d.ts.map +1 -1
  37. package/dist/mastra/tools/execa.js +5 -1
  38. package/dist/mastra/tools/image.d.ts +27 -0
  39. package/dist/mastra/tools/image.d.ts.map +1 -0
  40. package/dist/mastra/tools/image.js +37 -0
  41. package/dist/mastra/tools/pdf.d.ts.map +1 -1
  42. package/dist/mastra/tools/pdf.js +3 -2
  43. package/dist/mastra/tools/pnpm.d.ts +60 -0
  44. package/dist/mastra/tools/pnpm.d.ts.map +1 -0
  45. package/dist/mastra/tools/pnpm.js +128 -0
  46. package/dist/mastra/workflows/chat.d.ts.map +1 -1
  47. package/dist/mastra/workflows/chat.js +6 -11
  48. package/dist/mastra/workflows/commit-message.d.ts +10 -0
  49. package/dist/mastra/workflows/commit-message.d.ts.map +1 -0
  50. package/dist/mastra/workflows/commit-message.js +137 -0
  51. package/dist/mastra/workflows/index.d.ts +1 -0
  52. package/dist/mastra/workflows/index.d.ts.map +1 -1
  53. package/dist/mastra/workflows/index.js +1 -0
  54. package/dist/mastra/workflows/issue-labeler.js +1 -1
  55. package/dist/mastra/workflows/publish-packages.d.ts +3 -0
  56. package/dist/mastra/workflows/publish-packages.d.ts.map +1 -0
  57. package/dist/mastra/workflows/publish-packages.js +205 -0
  58. package/dist/mastra/workflows/telephone-game.d.ts +3 -0
  59. package/dist/mastra/workflows/telephone-game.d.ts.map +1 -0
  60. package/dist/mastra/workflows/telephone-game.js +95 -0
  61. package/package.json +15 -10
  62. package/test/data/05-versions-space.pdf +0 -0
  63. package/test/data/05-versions-space.pdf.txt +42 -0
  64. package/test-files/716a95a5c57a56d32a32b1c9592d6df0.png +0 -0
  65. package/test-files/roman.md +79 -0
  66. package/test-files/sample-1.pdf +0 -0
  67. package/test-files/taxes/2022.txt +45 -0
  68. package/test-files/taxes/2023.txt +44 -0
@@ -2,8 +2,9 @@ import { createTool } from '@mastra/core';
2
2
  import chalk from 'chalk';
3
3
  import { existsSync, readFileSync } from 'fs';
4
4
  import path from 'path';
5
- import pdf from 'pdf-parse';
6
5
  import { z } from 'zod';
6
+ // @ts-ignore
7
+ import pdfParse from 'pdf-parse/lib/pdf-parse.js';
7
8
  export const readPDF = createTool({
8
9
  id: 'readPDF',
9
10
  name: 'Read PDF',
@@ -27,7 +28,7 @@ export const readPDF = createTool({
27
28
  // Read the PDF file
28
29
  const dataBuffer = readFileSync(pdfPath);
29
30
  // Parse PDF content
30
- const data = await pdf(dataBuffer);
31
+ const data = await pdfParse(dataBuffer);
31
32
  console.log(chalk.blue('\n'));
32
33
  console.log(chalk.blue('PDF Information:'));
33
34
  console.log(chalk.blue('-----------------'));
@@ -0,0 +1,60 @@
1
+ import { z } from 'zod';
2
+ export declare const pnpmBuild: import("@mastra/core").Tool<"pnpmBuild", z.ZodObject<{
3
+ name: z.ZodString;
4
+ packagePath: z.ZodString;
5
+ }, "strip", z.ZodTypeAny, {
6
+ name: string;
7
+ packagePath: string;
8
+ }, {
9
+ name: string;
10
+ packagePath: 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
+ name: z.ZodString;
19
+ packagePath: z.ZodString;
20
+ }, "strip", z.ZodTypeAny, {
21
+ name: string;
22
+ packagePath: string;
23
+ }, {
24
+ name: string;
25
+ packagePath: string;
26
+ }>, import("@mastra/core").WorkflowContext<any>>>;
27
+ export declare const pnpmChangesetStatus: import("@mastra/core").Tool<"pnpmChangesetStatus", z.ZodObject<{}, "strip", z.ZodTypeAny, {}, {}>, z.ZodObject<{
28
+ message: z.ZodArray<z.ZodString, "many">;
29
+ }, "strip", z.ZodTypeAny, {
30
+ message: string[];
31
+ }, {
32
+ message: string[];
33
+ }>, import("@mastra/core").ToolExecutionContext<z.ZodObject<{}, "strip", z.ZodTypeAny, {}, {}>, import("@mastra/core").WorkflowContext<any>>>;
34
+ export declare const pnpmChangesetPublish: import("@mastra/core").Tool<"pnpmChangesetPublish", z.ZodObject<{}, "strip", z.ZodTypeAny, {}, {}>, z.ZodObject<{
35
+ message: z.ZodString;
36
+ }, "strip", z.ZodTypeAny, {
37
+ message: string;
38
+ }, {
39
+ message: string;
40
+ }>, import("@mastra/core").ToolExecutionContext<z.ZodObject<{}, "strip", z.ZodTypeAny, {}, {}>, import("@mastra/core").WorkflowContext<any>>>;
41
+ export declare const activeDistTag: import("@mastra/core").Tool<"activeDistTag", z.ZodObject<{
42
+ packagePath: z.ZodString;
43
+ }, "strip", z.ZodTypeAny, {
44
+ packagePath: string;
45
+ }, {
46
+ packagePath: string;
47
+ }>, z.ZodObject<{
48
+ message: z.ZodString;
49
+ }, "strip", z.ZodTypeAny, {
50
+ message: string;
51
+ }, {
52
+ message: string;
53
+ }>, import("@mastra/core").ToolExecutionContext<z.ZodObject<{
54
+ packagePath: z.ZodString;
55
+ }, "strip", z.ZodTypeAny, {
56
+ packagePath: string;
57
+ }, {
58
+ packagePath: string;
59
+ }>, import("@mastra/core").WorkflowContext<any>>>;
60
+ //# sourceMappingURL=pnpm.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pnpm.d.ts","sourceRoot":"","sources":["../../../src/mastra/tools/pnpm.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,eAAO,MAAM,SAAS;;;;;;;;;;;;;;;;;;;;;;;;iDA8BpB,CAAC;AAEH,eAAO,MAAM,mBAAmB;;;;;;6IA8B9B,CAAC;AAEH,eAAO,MAAM,oBAAoB;;;;;;6IA0B/B,CAAC;AAEH,eAAO,MAAM,aAAa;;;;;;;;;;;;;;;;;;iDA8BxB,CAAC"}
@@ -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 to latest for ${pkgJson.name}@${version}`));
112
+ const p = execa(`npm`, ['dist-tag', `add`, `${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
+ });
@@ -1 +1 @@
1
- {"version":3,"file":"chat.d.ts","sourceRoot":"","sources":["../../../src/mastra/workflows/chat.ts"],"names":[],"mappings":"AAAA,OAAO,EAAQ,QAAQ,EAAE,MAAM,cAAc,CAAC;AAG9C,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAIxB,eAAO,MAAM,eAAe;;;;;;;;;GAM1B,CAAC"}
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"}
@@ -1,6 +1,6 @@
1
+ import { input } from '@inquirer/prompts';
1
2
  import { Step, Workflow } from '@mastra/core';
2
3
  import chalk from 'chalk';
3
- import inquirer from 'inquirer';
4
4
  import { z } from 'zod';
5
5
  import { dane } from '../agents/index.js';
6
6
  export const messageWorkflow = new Workflow({
@@ -16,14 +16,10 @@ const messageStep = new Step({
16
16
  message: z.string(),
17
17
  }),
18
18
  execute: async () => {
19
- const { content } = await inquirer.prompt([
20
- {
21
- type: 'input',
22
- name: 'content',
23
- message: '\n You:',
24
- validate: input => input.trim().length > 0 || 'Message cannot be empty',
25
- },
26
- ]);
19
+ const content = await input({
20
+ message: '\n You:',
21
+ validate: input => input.trim().length > 0 || 'Message cannot be empty',
22
+ });
27
23
  return { message: content };
28
24
  },
29
25
  });
@@ -51,8 +47,7 @@ const messageOutputStep = new Step({
51
47
  if (!messages || messages.length === 0) {
52
48
  messages = [];
53
49
  }
54
- const res = await mastra?.agents?.['dane']?.generate(message, {
55
- stream: true,
50
+ const res = await mastra?.agents?.['dane']?.stream(message, {
56
51
  maxSteps: 5,
57
52
  resourceid,
58
53
  threadId,
@@ -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?.getStepPayload('trigger')?.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 diffData = context?.machineContext?.getStepPayload('getDiff');
49
+ const fileData = context?.machineContext?.getStepPayload('readConventionalCommitSpec');
50
+ if (!diffData) {
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
+ ${diffData.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
+ ${fileData && fileData.fileData?.message
62
+ ? `USE THE FOLLOWING GUIDELINES: ${fileData.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
+ output: 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();
@@ -1,3 +1,4 @@
1
1
  export * from './chat.js';
2
2
  export * from './issue-labeler.js';
3
+ export * from './commit-message.js';
3
4
  //# sourceMappingURL=index.d.ts.map
@@ -1 +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"}
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"}
@@ -1,2 +1,3 @@
1
1
  export * from './chat.js';
2
2
  export * from './issue-labeler.js';
3
+ export * from './commit-message.js';
@@ -55,7 +55,7 @@ const labelIssue = new Step({
55
55
 
56
56
  What label or labels would you assign?
57
57
  `, {
58
- schema: z.object({
58
+ output: z.object({
59
59
  labels: z.array(z.string()),
60
60
  }),
61
61
  });
@@ -0,0 +1,3 @@
1
+ import { Workflow } from '@mastra/core';
2
+ export declare const packagePublisher: Workflow<any, any>;
3
+ //# sourceMappingURL=publish-packages.d.ts.map
@@ -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"}
@@ -0,0 +1,205 @@
1
+ import { Step, Workflow } 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
+ export const packagePublisher = new Workflow({
7
+ name: 'pnpm-changset-publisher',
8
+ });
9
+ const getPacakgesToPublish = new Step({
10
+ id: 'getPacakgesToPublish',
11
+ outputSchema: z.object({
12
+ packages: z.array(z.string()),
13
+ integrations: z.array(z.string()),
14
+ danePackage: z.string(),
15
+ }),
16
+ execute: async ({ mastra }) => {
17
+ const agent = mastra?.agents?.['danePackagePublisher'];
18
+ if (!agent) {
19
+ throw new Error('Agent not found');
20
+ }
21
+ const result = await agent.generate(`
22
+ Can you tell me which packages within the packages and integrations directory need to be published to npm?
23
+ `);
24
+ const resultObj = await agent.generate(`
25
+ ONLY RETURN DATA IF WE HAVE PACKAGES TO PUBLISH. If we do not, return empty arrays.
26
+ Can you format this for me ${result.text}?
27
+ @mastra/core must be first. mastra must be second.
28
+ create-mastra is a package (not an integration) and should be listed in packages array.
29
+ @mastra/dane should be listed after packages and integrations.
30
+ `, {
31
+ output: z.object({
32
+ packages: z.array(z.string()),
33
+ integrations: z.array(z.string()),
34
+ danePackage: z.string(),
35
+ }),
36
+ });
37
+ return {
38
+ packages: resultObj?.object?.packages,
39
+ integrations: resultObj?.object?.integrations,
40
+ danePackage: resultObj?.object?.danePackage,
41
+ };
42
+ },
43
+ });
44
+ const assemblePackages = new Step({
45
+ id: 'assemblePackages',
46
+ outputSchema: z.object({
47
+ packages: z.array(z.string()),
48
+ }),
49
+ execute: async ({ context }) => {
50
+ if (context.machineContext?.stepResults.getPacakgesToPublish?.status !== 'success') {
51
+ return {
52
+ packages: [],
53
+ };
54
+ }
55
+ const payload = context.machineContext.stepResults.getPacakgesToPublish.payload;
56
+ const packagesToBuild = new Set();
57
+ if (payload?.packages) {
58
+ payload.packages.forEach((pkg) => {
59
+ let pkgName = pkg.replace('@mastra/', '');
60
+ if (pkgName === 'mastra') {
61
+ pkgName = 'cli';
62
+ }
63
+ const pkgPath = path.join(process.cwd(), 'packages', pkgName);
64
+ packagesToBuild.add(pkgPath);
65
+ });
66
+ }
67
+ if (payload?.integrations) {
68
+ const integrations = payload.integrations;
69
+ integrations.forEach((integration) => {
70
+ let pkgName = integration.replace('@mastra/', '');
71
+ const integrationPath = path.join(process.cwd(), 'integrations', pkgName);
72
+ packagesToBuild.add(integrationPath);
73
+ });
74
+ }
75
+ if (payload?.danePackage) {
76
+ const danePackage = payload.danePackage;
77
+ let pkgName = danePackage.replace('@mastra/', '');
78
+ const danePackageMapped = path.join(process.cwd(), 'examples', pkgName);
79
+ const pkgJsonPath = readFileSync(path.join(danePackageMapped, 'package.json'), 'utf-8');
80
+ const pkgJson = JSON.parse(pkgJsonPath);
81
+ const dependencies = Object.keys(pkgJson.dependencies || {}).filter((dep) => dep.startsWith('@mastra/'));
82
+ dependencies.forEach((dep) => {
83
+ const pkgName = dep.replace('@mastra/', '');
84
+ const pkgPath = path.join(process.cwd(), 'packages', pkgName);
85
+ const integrationPath = path.join(process.cwd(), 'integrations', pkgName);
86
+ try {
87
+ if (existsSync(pkgPath)) {
88
+ packagesToBuild.add(pkgPath);
89
+ }
90
+ else {
91
+ packagesToBuild.add(integrationPath);
92
+ }
93
+ }
94
+ catch (e) {
95
+ console.error(e);
96
+ }
97
+ });
98
+ packagesToBuild.add(path.join(process.cwd(), 'examples', 'dane'));
99
+ }
100
+ const pkgSet = Array.from(packagesToBuild.keys());
101
+ if (!packagesToBuild.size) {
102
+ console.error(chalk.red('No packages to build.'));
103
+ return {
104
+ packages: [],
105
+ };
106
+ }
107
+ return { packages: pkgSet };
108
+ },
109
+ });
110
+ const buildPackages = new Step({
111
+ id: 'buildPackages',
112
+ outputSchema: z.object({
113
+ packages: z.array(z.string()),
114
+ }),
115
+ execute: async ({ context, mastra }) => {
116
+ if (context.machineContext?.stepResults.assemblePackages?.status !== 'success') {
117
+ return {
118
+ packages: [],
119
+ };
120
+ }
121
+ const pkgSet = context.machineContext.stepResults.assemblePackages.payload.packages;
122
+ const agent = mastra?.agents?.['danePackagePublisher'];
123
+ if (!agent) {
124
+ throw new Error('Agent not found');
125
+ }
126
+ let res = await agent.generate(`
127
+ Here are the packages that need to be built: ${pkgSet.join(',')}.
128
+ Always build @mastra/core first.
129
+ Always build mastra second.
130
+ Next packages found within the 'packages' directory should be built next in parallel.
131
+ After packages found within the 'integrations' directory should be built in parallel.
132
+ dane should be built last.
133
+ `);
134
+ console.log(chalk.green(res.text));
135
+ return { packages: pkgSet };
136
+ },
137
+ });
138
+ const publishChangeset = new Step({
139
+ id: 'publishChangeset',
140
+ outputSchema: z.object({
141
+ packages: z.array(z.string()),
142
+ }),
143
+ execute: async ({ context, mastra }) => {
144
+ if (context.machineContext?.stepResults.buildPackages?.status !== 'success') {
145
+ return {
146
+ packages: [],
147
+ };
148
+ }
149
+ const pkgSet = context.machineContext.stepResults.buildPackages.payload.packages;
150
+ const agent = mastra?.agents?.['danePackagePublisher'];
151
+ if (!agent) {
152
+ throw new Error('Agent not found');
153
+ }
154
+ let res = await agent.generate(`
155
+ Publish the changeset.
156
+ `);
157
+ console.log(chalk.green(res.text));
158
+ return { packages: pkgSet };
159
+ },
160
+ });
161
+ const setLatestDistTag = new Step({
162
+ id: 'setLatestDistTag',
163
+ outputSchema: z.object({
164
+ packages: z.array(z.string()),
165
+ }),
166
+ execute: async ({ context, mastra }) => {
167
+ if (context.machineContext?.stepResults.publishChangeset?.status !== 'success') {
168
+ return {
169
+ packages: [],
170
+ };
171
+ }
172
+ const pkgSet = context.machineContext.stepResults.publishChangeset.payload.packages;
173
+ const agent = mastra?.agents?.['danePackagePublisher'];
174
+ if (!agent) {
175
+ throw new Error('Agent not found');
176
+ }
177
+ let res = await agent.generate(`
178
+ Set the active tag for these packages ${pkgSet.join(',')}.
179
+ `);
180
+ console.log(chalk.green(res.text));
181
+ return { packages: pkgSet };
182
+ },
183
+ });
184
+ packagePublisher
185
+ .step(getPacakgesToPublish)
186
+ .then(assemblePackages)
187
+ .then(buildPackages, {
188
+ when: async ({ context }) => {
189
+ return (context.stepResults.assemblePackages?.status === 'success' &&
190
+ context.stepResults.assemblePackages?.payload?.packages.length > 0);
191
+ },
192
+ })
193
+ .then(publishChangeset, {
194
+ when: async ({ context }) => {
195
+ return (context.stepResults.buildPackages?.status === 'success' &&
196
+ context.stepResults.buildPackages?.payload?.packages.length > 0);
197
+ },
198
+ })
199
+ .then(setLatestDistTag, {
200
+ when: async ({ context }) => {
201
+ return (context.stepResults.publishChangeset?.status === 'success' &&
202
+ context.stepResults.publishChangeset?.payload?.packages.length > 0);
203
+ },
204
+ })
205
+ .commit();
@@ -0,0 +1,3 @@
1
+ import { Workflow } from '@mastra/core';
2
+ export declare const telephoneGameWorkflow: Workflow<any, any>;
3
+ //# sourceMappingURL=telephone-game.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"telephone-game.d.ts","sourceRoot":"","sources":["../../../src/mastra/workflows/telephone-game.ts"],"names":[],"mappings":"AACA,OAAO,EAAQ,QAAQ,EAAiB,MAAM,cAAc,CAAC;AAG7D,eAAO,MAAM,qBAAqB,oBAEhC,CAAC"}