Skip to content

Commit 60d34f0

Browse files
committed
chore: Update ts-mastraai template and dependencies
1 parent 0d8030a commit 60d34f0

File tree

4 files changed

+56
-58
lines changed

4 files changed

+56
-58
lines changed

templates/ts-mastraai/package.json

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,23 @@
77
"node": ">=18.0.0"
88
},
99
"dependencies": {
10-
"@ai-sdk/openai": "^2.0.3",
11-
"@mastra/core": "^0.24.9",
12-
"apify": "^3.5.2",
13-
"mastra": "^0.18.9",
14-
"zod": "^3.25.67"
10+
"@ai-sdk/openai": "^3.0.23",
11+
"@mastra/core": "^1.1.0",
12+
"apify": "^3.5.3",
13+
"mastra": "^1.1.0",
14+
"zod": "^4.3.6"
1515
},
1616
"devDependencies": {
1717
"@apify/eslint-config": "^1.0.0",
1818
"@apify/tsconfig": "^0.1.1",
19-
"@types/node": "^22.15.32",
20-
"eslint": "^9.29.0",
21-
"eslint-config-prettier": "^10.1.5",
22-
"globals": "^17.0.0",
23-
"prettier": "^3.5.3",
24-
"tsx": "^4.20.3",
19+
"@types/node": "^25.1.0",
20+
"eslint": "^9.39.2",
21+
"eslint-config-prettier": "^10.1.8",
22+
"globals": "^17.2.0",
23+
"prettier": "^3.8.1",
24+
"tsx": "^4.21.0",
2525
"typescript": "^5.9.3",
26-
"typescript-eslint": "^8.34.1"
26+
"typescript-eslint": "^8.54.0"
2727
},
2828
"scripts": {
2929
"start": "npm run start:dev",

templates/ts-mastraai/src/agents.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { instagramScraperTool } from './tools.js';
66

77
export const createSocialMediaAgent = (modelName: string): Agent =>
88
new Agent({
9+
id: 'social-media-agent',
910
name: 'Social Media Agent',
1011
instructions: `You are an expert social media analyst specializing in Instagram analysis.
1112
You help users understand social media data and extract meaningful insights from

templates/ts-mastraai/src/main.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ const agent = createSocialMediaAgent(modelName);
3838
log.info(`Querying the agent with the following query: ${query}`);
3939

4040
// Query the agent and get the response
41-
const response = await agent.generateVNext([{ role: 'user', content: query }]);
41+
const response = await agent.generate([{ role: 'user', content: query }]);
4242

4343
log.info(`Agent response: ${response.text}`);
4444

templates/ts-mastraai/src/tools.ts

Lines changed: 42 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
// eslint-disable-next-line import/extensions
2-
import type { Tool } from '@mastra/core/tools';
3-
// eslint-disable-next-line import/extensions
42
import { createTool } from '@mastra/core/tools';
53
import { ApifyClient, log } from 'apify';
64
import { z } from 'zod';
@@ -17,46 +15,45 @@ const instagramScraperOutputSchema = z.object({
1715
});
1816

1917
// Define the Instagram Scraper Tool
20-
export const instagramScraperTool: Tool<typeof instagramScraperInputSchema, typeof instagramScraperOutputSchema> =
21-
createTool({
22-
id: 'instagram-profile-posts-scraper',
23-
description: "Tool to scrape Instagram profile posts using Apify's Instagram Scraper.",
24-
inputSchema: instagramScraperInputSchema,
25-
outputSchema: instagramScraperOutputSchema,
26-
execute: async ({ context }) => {
27-
const token = process.env.APIFY_TOKEN;
28-
if (!token) {
29-
throw new Error('APIFY_TOKEN environment variable is missing!');
30-
}
31-
32-
const { handle, maxPosts } = context;
33-
const runInput = {
34-
directUrls: [`https://www.instagram.com/${handle}/`],
35-
resultsLimit: maxPosts,
36-
resultsType: 'posts',
37-
searchLimit: 1,
38-
};
39-
40-
const apifyClient = new ApifyClient({ token });
41-
42-
// Call the Apify Instagram Scraper Actor
43-
const run = await apifyClient.actor('apify/instagram-scraper').call(runInput);
44-
if (!run) {
45-
throw new Error('Failed to start the Actor apify/instagram-scraper');
46-
}
47-
48-
// Fetch dataset items
49-
const datasetId = run.defaultDatasetId;
50-
const dataset = await apifyClient.dataset(datasetId).listItems();
51-
const datasetItems: unknown[] = dataset.items;
52-
53-
// Validate and convert dataset items to InstagramPosts
54-
try {
55-
const posts: InstagramPosts = InstagramPosts.fromRaw(datasetItems);
56-
return { posts: posts.root };
57-
} catch (error) {
58-
log.warning(`Received invalid dataset items: ${JSON.stringify(datasetItems)}. Error: ${error}`);
59-
throw new Error('Received invalid dataset items.');
60-
}
61-
},
62-
});
18+
export const instagramScraperTool = createTool({
19+
id: 'instagram-profile-posts-scraper',
20+
description: "Tool to scrape Instagram profile posts using Apify's Instagram Scraper.",
21+
inputSchema: instagramScraperInputSchema,
22+
outputSchema: instagramScraperOutputSchema,
23+
execute: async (inputData) => {
24+
const token = process.env.APIFY_TOKEN;
25+
if (!token) {
26+
throw new Error('APIFY_TOKEN environment variable is missing!');
27+
}
28+
29+
const { handle, maxPosts } = inputData;
30+
const runInput = {
31+
directUrls: [`https://www.instagram.com/${handle}/`],
32+
resultsLimit: maxPosts,
33+
resultsType: 'posts',
34+
searchLimit: 1,
35+
};
36+
37+
const apifyClient = new ApifyClient({ token });
38+
39+
// Call the Apify Instagram Scraper Actor
40+
const run = await apifyClient.actor('apify/instagram-scraper').call(runInput);
41+
if (!run) {
42+
throw new Error('Failed to start the Actor apify/instagram-scraper');
43+
}
44+
45+
// Fetch dataset items
46+
const datasetId = run.defaultDatasetId;
47+
const dataset = await apifyClient.dataset(datasetId).listItems();
48+
const datasetItems: unknown[] = dataset.items;
49+
50+
// Validate and convert dataset items to InstagramPosts
51+
try {
52+
const posts: InstagramPosts = InstagramPosts.fromRaw(datasetItems);
53+
return { posts: posts.root };
54+
} catch (error) {
55+
log.warning(`Received invalid dataset items: ${JSON.stringify(datasetItems)}. Error: ${error}`);
56+
throw new Error('Received invalid dataset items.');
57+
}
58+
},
59+
});

0 commit comments

Comments
 (0)