@mastra/mcp-docs-server 0.0.0-commonjs-20250414101718
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/.docs/organized/changelogs/%40mastra%2Fastra.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fchroma.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fclickhouse.md +161 -0
- package/.docs/organized/changelogs/%40mastra%2Fclient-js.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fcloudflare.md +110 -0
- package/.docs/organized/changelogs/%40mastra%2Fcore.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fdeployer-cloudflare.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fdeployer-netlify.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fdeployer-vercel.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fdeployer.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fevals.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Ffirecrawl.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fgithub.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Floggers.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fmcp-docs-server.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fmcp-registry-registry.md +26 -0
- package/.docs/organized/changelogs/%40mastra%2Fmcp.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fmem0.md +196 -0
- package/.docs/organized/changelogs/%40mastra%2Fmemory.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fpg.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fpinecone.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fplayground-ui.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fqdrant.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Frag.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fragie.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fserver.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fspeech-azure.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fspeech-deepgram.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fspeech-elevenlabs.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fspeech-google.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fspeech-ibm.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fspeech-murf.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fspeech-openai.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fspeech-playai.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fspeech-replicate.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fspeech-speechify.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fturbopuffer.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fupstash.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fvectorize.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fvoice-azure.md +250 -0
- package/.docs/organized/changelogs/%40mastra%2Fvoice-cloudflare.md +250 -0
- package/.docs/organized/changelogs/%40mastra%2Fvoice-deepgram.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fvoice-elevenlabs.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fvoice-google.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fvoice-murf.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fvoice-openai-realtime.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fvoice-openai.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fvoice-playai.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fvoice-sarvam.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fvoice-speechify.md +302 -0
- package/.docs/organized/changelogs/create-mastra.md +302 -0
- package/.docs/organized/changelogs/mastra.md +302 -0
- package/.docs/organized/code-examples/agent-network.md +282 -0
- package/.docs/organized/code-examples/agent.md +388 -0
- package/.docs/organized/code-examples/ai-sdk-useChat.md +378 -0
- package/.docs/organized/code-examples/assistant-ui.md +37 -0
- package/.docs/organized/code-examples/bird-checker-with-express.md +235 -0
- package/.docs/organized/code-examples/bird-checker-with-nextjs-and-eval.md +360 -0
- package/.docs/organized/code-examples/bird-checker-with-nextjs.md +250 -0
- package/.docs/organized/code-examples/client-side-tools.md +69 -0
- package/.docs/organized/code-examples/crypto-chatbot.md +96 -0
- package/.docs/organized/code-examples/fireworks-r1.md +159 -0
- package/.docs/organized/code-examples/mcp-registry-registry.md +63 -0
- package/.docs/organized/code-examples/memory-todo-agent.md +164 -0
- package/.docs/organized/code-examples/memory-with-context.md +167 -0
- package/.docs/organized/code-examples/memory-with-libsql.md +204 -0
- package/.docs/organized/code-examples/memory-with-mem0.md +121 -0
- package/.docs/organized/code-examples/memory-with-pg.md +224 -0
- package/.docs/organized/code-examples/memory-with-upstash.md +268 -0
- package/.docs/organized/code-examples/quick-start.md +129 -0
- package/.docs/organized/code-examples/stock-price-tool.md +124 -0
- package/.docs/organized/code-examples/weather-agent.md +353 -0
- package/.docs/organized/code-examples/workflow-ai-recruiter.md +159 -0
- package/.docs/organized/code-examples/workflow-with-inline-steps.md +111 -0
- package/.docs/organized/code-examples/workflow-with-memory.md +393 -0
- package/.docs/organized/code-examples/workflow-with-separate-steps.md +131 -0
- package/.docs/raw/agents/adding-tools.mdx +317 -0
- package/.docs/raw/agents/adding-voice.mdx +175 -0
- package/.docs/raw/agents/agent-memory.mdx +62 -0
- package/.docs/raw/agents/mcp-guide.mdx +215 -0
- package/.docs/raw/agents/overview.mdx +303 -0
- package/.docs/raw/community/discord.mdx +12 -0
- package/.docs/raw/community/licensing.mdx +63 -0
- package/.docs/raw/deployment/client.mdx +120 -0
- package/.docs/raw/deployment/deployment.mdx +127 -0
- package/.docs/raw/deployment/server.mdx +282 -0
- package/.docs/raw/evals/custom-eval.mdx +22 -0
- package/.docs/raw/evals/overview.mdx +95 -0
- package/.docs/raw/evals/running-in-ci.mdx +81 -0
- package/.docs/raw/evals/textual-evals.mdx +54 -0
- package/.docs/raw/faq/index.mdx +63 -0
- package/.docs/raw/frameworks/ai-sdk.mdx +296 -0
- package/.docs/raw/frameworks/next-js.mdx +238 -0
- package/.docs/raw/getting-started/installation.mdx +442 -0
- package/.docs/raw/getting-started/mcp-docs-server.mdx +141 -0
- package/.docs/raw/getting-started/project-structure.mdx +80 -0
- package/.docs/raw/index.mdx +22 -0
- package/.docs/raw/integrations/index.mdx +213 -0
- package/.docs/raw/local-dev/add-to-existing-project.mdx +48 -0
- package/.docs/raw/local-dev/creating-a-new-project.mdx +54 -0
- package/.docs/raw/local-dev/mastra-dev.mdx +108 -0
- package/.docs/raw/memory/memory-processors.mdx +131 -0
- package/.docs/raw/memory/overview.mdx +119 -0
- package/.docs/raw/memory/semantic-recall.mdx +122 -0
- package/.docs/raw/memory/working-memory.mdx +87 -0
- package/.docs/raw/observability/logging.mdx +38 -0
- package/.docs/raw/observability/nextjs-tracing.mdx +108 -0
- package/.docs/raw/observability/tracing.mdx +115 -0
- package/.docs/raw/rag/chunking-and-embedding.mdx +156 -0
- package/.docs/raw/rag/overview.mdx +85 -0
- package/.docs/raw/rag/retrieval.mdx +365 -0
- package/.docs/raw/rag/vector-databases.mdx +340 -0
- package/.docs/raw/reference/agents/createTool.mdx +229 -0
- package/.docs/raw/reference/agents/generate.mdx +334 -0
- package/.docs/raw/reference/agents/getAgent.mdx +54 -0
- package/.docs/raw/reference/agents/stream.mdx +369 -0
- package/.docs/raw/reference/cli/build.mdx +55 -0
- package/.docs/raw/reference/cli/dev.mdx +134 -0
- package/.docs/raw/reference/cli/init.mdx +43 -0
- package/.docs/raw/reference/client-js/agents.mdx +107 -0
- package/.docs/raw/reference/client-js/error-handling.mdx +38 -0
- package/.docs/raw/reference/client-js/logs.mdx +24 -0
- package/.docs/raw/reference/client-js/memory.mdx +97 -0
- package/.docs/raw/reference/client-js/telemetry.mdx +20 -0
- package/.docs/raw/reference/client-js/tools.mdx +44 -0
- package/.docs/raw/reference/client-js/vectors.mdx +79 -0
- package/.docs/raw/reference/client-js/workflows.mdx +136 -0
- package/.docs/raw/reference/core/mastra-class.mdx +232 -0
- package/.docs/raw/reference/deployer/cloudflare.mdx +207 -0
- package/.docs/raw/reference/deployer/deployer.mdx +159 -0
- package/.docs/raw/reference/deployer/netlify.mdx +109 -0
- package/.docs/raw/reference/deployer/vercel.mdx +117 -0
- package/.docs/raw/reference/evals/answer-relevancy.mdx +186 -0
- package/.docs/raw/reference/evals/bias.mdx +186 -0
- package/.docs/raw/reference/evals/completeness.mdx +174 -0
- package/.docs/raw/reference/evals/content-similarity.mdx +183 -0
- package/.docs/raw/reference/evals/context-position.mdx +190 -0
- package/.docs/raw/reference/evals/context-precision.mdx +189 -0
- package/.docs/raw/reference/evals/context-relevancy.mdx +188 -0
- package/.docs/raw/reference/evals/contextual-recall.mdx +191 -0
- package/.docs/raw/reference/evals/faithfulness.mdx +193 -0
- package/.docs/raw/reference/evals/hallucination.mdx +219 -0
- package/.docs/raw/reference/evals/keyword-coverage.mdx +176 -0
- package/.docs/raw/reference/evals/prompt-alignment.mdx +238 -0
- package/.docs/raw/reference/evals/summarization.mdx +205 -0
- package/.docs/raw/reference/evals/textual-difference.mdx +161 -0
- package/.docs/raw/reference/evals/tone-consistency.mdx +181 -0
- package/.docs/raw/reference/evals/toxicity.mdx +165 -0
- package/.docs/raw/reference/index.mdx +12 -0
- package/.docs/raw/reference/memory/Memory.mdx +212 -0
- package/.docs/raw/reference/memory/createThread.mdx +95 -0
- package/.docs/raw/reference/memory/getThreadById.mdx +46 -0
- package/.docs/raw/reference/memory/getThreadsByResourceId.mdx +48 -0
- package/.docs/raw/reference/memory/query.mdx +167 -0
- package/.docs/raw/reference/networks/agent-network.mdx +159 -0
- package/.docs/raw/reference/observability/create-logger.mdx +106 -0
- package/.docs/raw/reference/observability/logger.mdx +55 -0
- package/.docs/raw/reference/observability/otel-config.mdx +120 -0
- package/.docs/raw/reference/observability/providers/braintrust.mdx +40 -0
- package/.docs/raw/reference/observability/providers/dash0.mdx +40 -0
- package/.docs/raw/reference/observability/providers/index.mdx +16 -0
- package/.docs/raw/reference/observability/providers/laminar.mdx +41 -0
- package/.docs/raw/reference/observability/providers/langfuse.mdx +51 -0
- package/.docs/raw/reference/observability/providers/langsmith.mdx +48 -0
- package/.docs/raw/reference/observability/providers/langwatch.mdx +45 -0
- package/.docs/raw/reference/observability/providers/new-relic.mdx +40 -0
- package/.docs/raw/reference/observability/providers/signoz.mdx +40 -0
- package/.docs/raw/reference/observability/providers/traceloop.mdx +40 -0
- package/.docs/raw/reference/rag/astra.mdx +258 -0
- package/.docs/raw/reference/rag/chroma.mdx +281 -0
- package/.docs/raw/reference/rag/chunk.mdx +235 -0
- package/.docs/raw/reference/rag/document.mdx +127 -0
- package/.docs/raw/reference/rag/embeddings.mdx +160 -0
- package/.docs/raw/reference/rag/extract-params.mdx +226 -0
- package/.docs/raw/reference/rag/graph-rag.mdx +182 -0
- package/.docs/raw/reference/rag/libsql.mdx +357 -0
- package/.docs/raw/reference/rag/metadata-filters.mdx +298 -0
- package/.docs/raw/reference/rag/pg.mdx +477 -0
- package/.docs/raw/reference/rag/pinecone.mdx +281 -0
- package/.docs/raw/reference/rag/qdrant.mdx +236 -0
- package/.docs/raw/reference/rag/rerank.mdx +212 -0
- package/.docs/raw/reference/rag/turbopuffer.mdx +249 -0
- package/.docs/raw/reference/rag/upstash.mdx +247 -0
- package/.docs/raw/reference/rag/vectorize.mdx +298 -0
- package/.docs/raw/reference/storage/libsql.mdx +74 -0
- package/.docs/raw/reference/storage/postgresql.mdx +48 -0
- package/.docs/raw/reference/storage/upstash.mdx +86 -0
- package/.docs/raw/reference/tools/client.mdx +207 -0
- package/.docs/raw/reference/tools/document-chunker-tool.mdx +141 -0
- package/.docs/raw/reference/tools/graph-rag-tool.mdx +154 -0
- package/.docs/raw/reference/tools/mcp-configuration.mdx +206 -0
- package/.docs/raw/reference/tools/vector-query-tool.mdx +212 -0
- package/.docs/raw/reference/voice/composite-voice.mdx +140 -0
- package/.docs/raw/reference/voice/deepgram.mdx +164 -0
- package/.docs/raw/reference/voice/elevenlabs.mdx +216 -0
- package/.docs/raw/reference/voice/google.mdx +198 -0
- package/.docs/raw/reference/voice/mastra-voice.mdx +394 -0
- package/.docs/raw/reference/voice/murf.mdx +251 -0
- package/.docs/raw/reference/voice/openai-realtime.mdx +431 -0
- package/.docs/raw/reference/voice/openai.mdx +168 -0
- package/.docs/raw/reference/voice/playai.mdx +159 -0
- package/.docs/raw/reference/voice/sarvam.mdx +260 -0
- package/.docs/raw/reference/voice/speechify.mdx +145 -0
- package/.docs/raw/reference/voice/voice.answer.mdx +122 -0
- package/.docs/raw/reference/voice/voice.connect.mdx +124 -0
- package/.docs/raw/reference/voice/voice.listen.mdx +195 -0
- package/.docs/raw/reference/voice/voice.on.mdx +189 -0
- package/.docs/raw/reference/voice/voice.send.mdx +118 -0
- package/.docs/raw/reference/voice/voice.speak.mdx +203 -0
- package/.docs/raw/reference/workflows/after.mdx +88 -0
- package/.docs/raw/reference/workflows/afterEvent.mdx +76 -0
- package/.docs/raw/reference/workflows/commit.mdx +37 -0
- package/.docs/raw/reference/workflows/createRun.mdx +77 -0
- package/.docs/raw/reference/workflows/else.mdx +72 -0
- package/.docs/raw/reference/workflows/events.mdx +305 -0
- package/.docs/raw/reference/workflows/execute.mdx +110 -0
- package/.docs/raw/reference/workflows/if.mdx +107 -0
- package/.docs/raw/reference/workflows/resume.mdx +155 -0
- package/.docs/raw/reference/workflows/resumeWithEvent.mdx +133 -0
- package/.docs/raw/reference/workflows/snapshots.mdx +207 -0
- package/.docs/raw/reference/workflows/start.mdx +84 -0
- package/.docs/raw/reference/workflows/step-class.mdx +100 -0
- package/.docs/raw/reference/workflows/step-condition.mdx +134 -0
- package/.docs/raw/reference/workflows/step-function.mdx +92 -0
- package/.docs/raw/reference/workflows/step-options.mdx +69 -0
- package/.docs/raw/reference/workflows/step-retries.mdx +203 -0
- package/.docs/raw/reference/workflows/suspend.mdx +70 -0
- package/.docs/raw/reference/workflows/then.mdx +74 -0
- package/.docs/raw/reference/workflows/until.mdx +165 -0
- package/.docs/raw/reference/workflows/watch.mdx +118 -0
- package/.docs/raw/reference/workflows/while.mdx +168 -0
- package/.docs/raw/reference/workflows/workflow.mdx +233 -0
- package/.docs/raw/storage/overview.mdx +378 -0
- package/.docs/raw/voice/overview.mdx +135 -0
- package/.docs/raw/voice/speech-to-text.mdx +45 -0
- package/.docs/raw/voice/text-to-speech.mdx +52 -0
- package/.docs/raw/voice/voice-to-voice.mdx +310 -0
- package/.docs/raw/workflows/control-flow.mdx +778 -0
- package/.docs/raw/workflows/dynamic-workflows.mdx +236 -0
- package/.docs/raw/workflows/error-handling.mdx +183 -0
- package/.docs/raw/workflows/nested-workflows.mdx +352 -0
- package/.docs/raw/workflows/overview.mdx +203 -0
- package/.docs/raw/workflows/steps.mdx +108 -0
- package/.docs/raw/workflows/suspend-and-resume.mdx +404 -0
- package/.docs/raw/workflows/variables.mdx +313 -0
- package/LICENSE.md +46 -0
- package/README.md +129 -0
- package/dist/_tsup-dts-rollup.d.ts +149 -0
- package/dist/chunk-QWYMT5LP.js +194 -0
- package/dist/prepare-docs/prepare.d.ts +1 -0
- package/dist/prepare-docs/prepare.js +1 -0
- package/dist/stdio.d.ts +1 -0
- package/dist/stdio.js +518 -0
- package/package.json +60 -0
|
@@ -0,0 +1,378 @@
|
|
|
1
|
+
### package.json
|
|
2
|
+
```json
|
|
3
|
+
{
|
|
4
|
+
"name": "mastra-ai-sdk-use-chat-example",
|
|
5
|
+
"version": "0.1.1",
|
|
6
|
+
"private": true,
|
|
7
|
+
"scripts": {
|
|
8
|
+
"dev": "next dev --turbopack",
|
|
9
|
+
"build": "next build",
|
|
10
|
+
"start": "next start",
|
|
11
|
+
"lint": "next lint"
|
|
12
|
+
},
|
|
13
|
+
"dependencies": {
|
|
14
|
+
"@ai-sdk/anthropic": "^1.1.15",
|
|
15
|
+
"@ai-sdk/react": "^1.1.21",
|
|
16
|
+
"@mastra/core": "workspace:*",
|
|
17
|
+
"next": "15.1.7",
|
|
18
|
+
"react": "^19.0.0",
|
|
19
|
+
"react-dom": "^19.0.0",
|
|
20
|
+
"zod": "^3.24.2"
|
|
21
|
+
},
|
|
22
|
+
"devDependencies": {
|
|
23
|
+
"@eslint/eslintrc": "^3.3.0",
|
|
24
|
+
"@types/node": "^20.17.24",
|
|
25
|
+
"@types/react": "^19.0.10",
|
|
26
|
+
"@types/react-dom": "^19.0.4",
|
|
27
|
+
"eslint": "^9.23.0",
|
|
28
|
+
"eslint-config-next": "15.1.7",
|
|
29
|
+
"postcss": "^8.5.3",
|
|
30
|
+
"tailwindcss": "^3.4.17",
|
|
31
|
+
"typescript": "^5.8.2"
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
### mastra/agents/index.ts
|
|
38
|
+
```typescript
|
|
39
|
+
import { anthropic } from '@ai-sdk/anthropic';
|
|
40
|
+
import { Agent } from '@mastra/core/agent';
|
|
41
|
+
|
|
42
|
+
import { weatherTool } from '../tools';
|
|
43
|
+
|
|
44
|
+
export const weatherAgent = new Agent({
|
|
45
|
+
name: 'Weather Agent',
|
|
46
|
+
instructions: `
|
|
47
|
+
You are a helpful weather assistant that provides accurate weather information.
|
|
48
|
+
|
|
49
|
+
Your primary function is to help users get weather details for specific locations. When responding:
|
|
50
|
+
- Always ask for a location if none is provided
|
|
51
|
+
- If the location name isn’t in English, please translate it
|
|
52
|
+
- If giving a location with multiple parts (e.g. "New York, NY"), use the most relevant part (e.g. "New York")
|
|
53
|
+
- Include relevant details like humidity, wind conditions, and precipitation
|
|
54
|
+
- Keep responses concise but informative
|
|
55
|
+
|
|
56
|
+
Use the weatherTool to fetch current weather data.
|
|
57
|
+
`,
|
|
58
|
+
model: anthropic('claude-3-5-sonnet-20241022'),
|
|
59
|
+
tools: { weatherTool },
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
### mastra/index.ts
|
|
65
|
+
```typescript
|
|
66
|
+
import { createLogger } from '@mastra/core/logger';
|
|
67
|
+
import { Mastra } from '@mastra/core/mastra';
|
|
68
|
+
|
|
69
|
+
import { weatherAgent } from './agents';
|
|
70
|
+
import { weatherWorkflow } from './workflows';
|
|
71
|
+
|
|
72
|
+
export const mastra = new Mastra({
|
|
73
|
+
workflows: { weatherWorkflow },
|
|
74
|
+
agents: { weatherAgent },
|
|
75
|
+
logger: createLogger({
|
|
76
|
+
name: 'Mastra',
|
|
77
|
+
level: 'info',
|
|
78
|
+
}),
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
### mastra/tools/index.ts
|
|
84
|
+
```typescript
|
|
85
|
+
import { createTool } from '@mastra/core/tools';
|
|
86
|
+
import { z } from 'zod';
|
|
87
|
+
|
|
88
|
+
interface GeocodingResponse {
|
|
89
|
+
results: {
|
|
90
|
+
latitude: number;
|
|
91
|
+
longitude: number;
|
|
92
|
+
name: string;
|
|
93
|
+
}[];
|
|
94
|
+
}
|
|
95
|
+
interface WeatherResponse {
|
|
96
|
+
current: {
|
|
97
|
+
time: string;
|
|
98
|
+
temperature_2m: number;
|
|
99
|
+
apparent_temperature: number;
|
|
100
|
+
relative_humidity_2m: number;
|
|
101
|
+
wind_speed_10m: number;
|
|
102
|
+
wind_gusts_10m: number;
|
|
103
|
+
weather_code: number;
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
export const weatherTool = createTool({
|
|
108
|
+
id: 'get-weather',
|
|
109
|
+
description: 'Get current weather for a location',
|
|
110
|
+
inputSchema: z.object({
|
|
111
|
+
location: z.string().describe('City name'),
|
|
112
|
+
}),
|
|
113
|
+
outputSchema: z.object({
|
|
114
|
+
temperature: z.number(),
|
|
115
|
+
feelsLike: z.number(),
|
|
116
|
+
humidity: z.number(),
|
|
117
|
+
windSpeed: z.number(),
|
|
118
|
+
windGust: z.number(),
|
|
119
|
+
conditions: z.string(),
|
|
120
|
+
location: z.string(),
|
|
121
|
+
}),
|
|
122
|
+
execute: async ({ context }) => {
|
|
123
|
+
return await getWeather(context.location);
|
|
124
|
+
},
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
const getWeather = async (location: string) => {
|
|
128
|
+
const geocodingUrl = `https://geocoding-api.open-meteo.com/v1/search?name=${encodeURIComponent(location)}&count=1`;
|
|
129
|
+
const geocodingResponse = await fetch(geocodingUrl);
|
|
130
|
+
const geocodingData = (await geocodingResponse.json()) as GeocodingResponse;
|
|
131
|
+
|
|
132
|
+
if (!geocodingData.results?.[0]) {
|
|
133
|
+
throw new Error(`Location '${location}' not found`);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
const { latitude, longitude, name } = geocodingData.results[0];
|
|
137
|
+
|
|
138
|
+
const weatherUrl = `https://api.open-meteo.com/v1/forecast?latitude=${latitude}&longitude=${longitude}¤t=temperature_2m,apparent_temperature,relative_humidity_2m,wind_speed_10m,wind_gusts_10m,weather_code`;
|
|
139
|
+
|
|
140
|
+
const response = await fetch(weatherUrl);
|
|
141
|
+
const data = (await response.json()) as WeatherResponse;
|
|
142
|
+
|
|
143
|
+
return {
|
|
144
|
+
temperature: data.current.temperature_2m,
|
|
145
|
+
feelsLike: data.current.apparent_temperature,
|
|
146
|
+
humidity: data.current.relative_humidity_2m,
|
|
147
|
+
windSpeed: data.current.wind_speed_10m,
|
|
148
|
+
windGust: data.current.wind_gusts_10m,
|
|
149
|
+
conditions: getWeatherCondition(data.current.weather_code),
|
|
150
|
+
location: name,
|
|
151
|
+
};
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
function getWeatherCondition(code: number): string {
|
|
155
|
+
const conditions: Record<number, string> = {
|
|
156
|
+
0: 'Clear sky',
|
|
157
|
+
1: 'Mainly clear',
|
|
158
|
+
2: 'Partly cloudy',
|
|
159
|
+
3: 'Overcast',
|
|
160
|
+
45: 'Foggy',
|
|
161
|
+
48: 'Depositing rime fog',
|
|
162
|
+
51: 'Light drizzle',
|
|
163
|
+
53: 'Moderate drizzle',
|
|
164
|
+
55: 'Dense drizzle',
|
|
165
|
+
56: 'Light freezing drizzle',
|
|
166
|
+
57: 'Dense freezing drizzle',
|
|
167
|
+
61: 'Slight rain',
|
|
168
|
+
63: 'Moderate rain',
|
|
169
|
+
65: 'Heavy rain',
|
|
170
|
+
66: 'Light freezing rain',
|
|
171
|
+
67: 'Heavy freezing rain',
|
|
172
|
+
71: 'Slight snow fall',
|
|
173
|
+
73: 'Moderate snow fall',
|
|
174
|
+
75: 'Heavy snow fall',
|
|
175
|
+
77: 'Snow grains',
|
|
176
|
+
80: 'Slight rain showers',
|
|
177
|
+
81: 'Moderate rain showers',
|
|
178
|
+
82: 'Violent rain showers',
|
|
179
|
+
85: 'Slight snow showers',
|
|
180
|
+
86: 'Heavy snow showers',
|
|
181
|
+
95: 'Thunderstorm',
|
|
182
|
+
96: 'Thunderstorm with slight hail',
|
|
183
|
+
99: 'Thunderstorm with heavy hail',
|
|
184
|
+
};
|
|
185
|
+
return conditions[code] || 'Unknown';
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
### mastra/workflows/index.ts
|
|
191
|
+
```typescript
|
|
192
|
+
import { anthropic } from '@ai-sdk/anthropic';
|
|
193
|
+
import { Agent } from '@mastra/core/agent';
|
|
194
|
+
import { Step, Workflow } from '@mastra/core/workflows';
|
|
195
|
+
import { z } from 'zod';
|
|
196
|
+
|
|
197
|
+
const llm = anthropic('claude-3-5-sonnet-20241022');
|
|
198
|
+
|
|
199
|
+
const agent = new Agent({
|
|
200
|
+
name: 'Weather Agent',
|
|
201
|
+
model: llm,
|
|
202
|
+
instructions: `
|
|
203
|
+
You are a local activities and travel expert who excels at weather-based planning. Analyze the weather data and provide practical activity recommendations.
|
|
204
|
+
|
|
205
|
+
For each day in the forecast, structure your response exactly as follows:
|
|
206
|
+
|
|
207
|
+
📅 [Day, Month Date, Year]
|
|
208
|
+
═══════════════════════════
|
|
209
|
+
|
|
210
|
+
🌡️ WEATHER SUMMARY
|
|
211
|
+
• Conditions: [brief description]
|
|
212
|
+
• Temperature: [X°C/Y°F to A°C/B°F]
|
|
213
|
+
• Precipitation: [X% chance]
|
|
214
|
+
|
|
215
|
+
🌅 MORNING ACTIVITIES
|
|
216
|
+
Outdoor:
|
|
217
|
+
• [Activity Name] - [Brief description including specific location/route]
|
|
218
|
+
Best timing: [specific time range]
|
|
219
|
+
Note: [relevant weather consideration]
|
|
220
|
+
|
|
221
|
+
🌞 AFTERNOON ACTIVITIES
|
|
222
|
+
Outdoor:
|
|
223
|
+
• [Activity Name] - [Brief description including specific location/route]
|
|
224
|
+
Best timing: [specific time range]
|
|
225
|
+
Note: [relevant weather consideration]
|
|
226
|
+
|
|
227
|
+
🏠 INDOOR ALTERNATIVES
|
|
228
|
+
• [Activity Name] - [Brief description including specific venue]
|
|
229
|
+
Ideal for: [weather condition that would trigger this alternative]
|
|
230
|
+
|
|
231
|
+
⚠️ SPECIAL CONSIDERATIONS
|
|
232
|
+
• [Any relevant weather warnings, UV index, wind conditions, etc.]
|
|
233
|
+
|
|
234
|
+
Guidelines:
|
|
235
|
+
- Suggest 2-3 time-specific outdoor activities per day
|
|
236
|
+
- Include 1-2 indoor backup options
|
|
237
|
+
- For precipitation >50%, lead with indoor activities
|
|
238
|
+
- All activities must be specific to the location
|
|
239
|
+
- Include specific venues, trails, or locations
|
|
240
|
+
- Consider activity intensity based on temperature
|
|
241
|
+
- Keep descriptions concise but informative
|
|
242
|
+
|
|
243
|
+
Maintain this exact formatting for consistency, using the emoji and section headers as shown.
|
|
244
|
+
`,
|
|
245
|
+
});
|
|
246
|
+
|
|
247
|
+
const fetchWeather = new Step({
|
|
248
|
+
id: 'fetch-weather',
|
|
249
|
+
description: 'Fetches weather forecast for a given city',
|
|
250
|
+
inputSchema: z.object({
|
|
251
|
+
city: z.string().describe('The city to get the weather for'),
|
|
252
|
+
}),
|
|
253
|
+
execute: async ({ context }) => {
|
|
254
|
+
const triggerData = context?.getStepResult<{ city: string }>('trigger');
|
|
255
|
+
|
|
256
|
+
if (!triggerData) {
|
|
257
|
+
throw new Error('Trigger data not found');
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
const geocodingUrl = `https://geocoding-api.open-meteo.com/v1/search?name=${encodeURIComponent(triggerData.city)}&count=1`;
|
|
261
|
+
const geocodingResponse = await fetch(geocodingUrl);
|
|
262
|
+
const geocodingData = (await geocodingResponse.json()) as {
|
|
263
|
+
results: { latitude: number; longitude: number; name: string }[];
|
|
264
|
+
};
|
|
265
|
+
|
|
266
|
+
if (!geocodingData.results?.[0]) {
|
|
267
|
+
throw new Error(`Location '${triggerData.city}' not found`);
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
const { latitude, longitude, name } = geocodingData.results[0];
|
|
271
|
+
|
|
272
|
+
const weatherUrl = `https://api.open-meteo.com/v1/forecast?latitude=${latitude}&longitude=${longitude}&daily=temperature_2m_max,temperature_2m_min,precipitation_probability_mean,weathercode&timezone=auto`;
|
|
273
|
+
const response = await fetch(weatherUrl);
|
|
274
|
+
const data = (await response.json()) as {
|
|
275
|
+
daily: {
|
|
276
|
+
time: string[];
|
|
277
|
+
temperature_2m_max: number[];
|
|
278
|
+
temperature_2m_min: number[];
|
|
279
|
+
precipitation_probability_mean: number[];
|
|
280
|
+
weathercode: number[];
|
|
281
|
+
};
|
|
282
|
+
};
|
|
283
|
+
|
|
284
|
+
const forecast = data.daily.time.map((date: string, index: number) => ({
|
|
285
|
+
date,
|
|
286
|
+
maxTemp: data.daily.temperature_2m_max[index],
|
|
287
|
+
minTemp: data.daily.temperature_2m_min[index],
|
|
288
|
+
precipitationChance: data.daily.precipitation_probability_mean[index],
|
|
289
|
+
condition: getWeatherCondition(data.daily.weathercode[index]!),
|
|
290
|
+
location: name,
|
|
291
|
+
}));
|
|
292
|
+
|
|
293
|
+
return forecast;
|
|
294
|
+
},
|
|
295
|
+
});
|
|
296
|
+
|
|
297
|
+
const forecastSchema = z.array(
|
|
298
|
+
z.object({
|
|
299
|
+
date: z.string(),
|
|
300
|
+
maxTemp: z.number(),
|
|
301
|
+
minTemp: z.number(),
|
|
302
|
+
precipitationChance: z.number(),
|
|
303
|
+
condition: z.string(),
|
|
304
|
+
location: z.string(),
|
|
305
|
+
}),
|
|
306
|
+
);
|
|
307
|
+
|
|
308
|
+
const planActivities = new Step({
|
|
309
|
+
id: 'plan-activities',
|
|
310
|
+
description: 'Suggests activities based on weather conditions',
|
|
311
|
+
inputSchema: forecastSchema,
|
|
312
|
+
execute: async ({ context }) => {
|
|
313
|
+
const forecast = context?.getStepResult<z.infer<typeof forecastSchema>>('fetch-weather');
|
|
314
|
+
|
|
315
|
+
if (!forecast || forecast.length === 0) {
|
|
316
|
+
throw new Error('Forecast data not found');
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
const prompt = `Based on the following weather forecast for ${forecast[0]?.location}, suggest appropriate activities:
|
|
320
|
+
${JSON.stringify(forecast, null, 2)}
|
|
321
|
+
`;
|
|
322
|
+
|
|
323
|
+
const response = await agent.stream([
|
|
324
|
+
{
|
|
325
|
+
role: 'user',
|
|
326
|
+
content: prompt,
|
|
327
|
+
},
|
|
328
|
+
]);
|
|
329
|
+
|
|
330
|
+
let activitiesText = '';
|
|
331
|
+
|
|
332
|
+
for await (const chunk of response.textStream) {
|
|
333
|
+
process.stdout.write(chunk);
|
|
334
|
+
activitiesText += chunk;
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
return {
|
|
338
|
+
activities: activitiesText,
|
|
339
|
+
};
|
|
340
|
+
},
|
|
341
|
+
});
|
|
342
|
+
|
|
343
|
+
function getWeatherCondition(code: number): string {
|
|
344
|
+
const conditions: Record<number, string> = {
|
|
345
|
+
0: 'Clear sky',
|
|
346
|
+
1: 'Mainly clear',
|
|
347
|
+
2: 'Partly cloudy',
|
|
348
|
+
3: 'Overcast',
|
|
349
|
+
45: 'Foggy',
|
|
350
|
+
48: 'Depositing rime fog',
|
|
351
|
+
51: 'Light drizzle',
|
|
352
|
+
53: 'Moderate drizzle',
|
|
353
|
+
55: 'Dense drizzle',
|
|
354
|
+
61: 'Slight rain',
|
|
355
|
+
63: 'Moderate rain',
|
|
356
|
+
65: 'Heavy rain',
|
|
357
|
+
71: 'Slight snow fall',
|
|
358
|
+
73: 'Moderate snow fall',
|
|
359
|
+
75: 'Heavy snow fall',
|
|
360
|
+
95: 'Thunderstorm',
|
|
361
|
+
};
|
|
362
|
+
return conditions[code] || 'Unknown';
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
const weatherWorkflow = new Workflow({
|
|
366
|
+
name: 'weather-workflow',
|
|
367
|
+
triggerSchema: z.object({
|
|
368
|
+
city: z.string().describe('The city to get the weather for'),
|
|
369
|
+
}),
|
|
370
|
+
})
|
|
371
|
+
.step(fetchWeather)
|
|
372
|
+
.then(planActivities);
|
|
373
|
+
|
|
374
|
+
weatherWorkflow.commit();
|
|
375
|
+
|
|
376
|
+
export { weatherWorkflow };
|
|
377
|
+
|
|
378
|
+
```
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
### package.json
|
|
2
|
+
```json
|
|
3
|
+
{
|
|
4
|
+
"name": "examples-assistant-ui",
|
|
5
|
+
"private": true,
|
|
6
|
+
"scripts": {
|
|
7
|
+
"dev": "next dev --turbo",
|
|
8
|
+
"build": "next build",
|
|
9
|
+
"start": "next start",
|
|
10
|
+
"lint": "next lint"
|
|
11
|
+
},
|
|
12
|
+
"dependencies": {
|
|
13
|
+
"@ai-sdk/openai": "latest",
|
|
14
|
+
"@assistant-ui/react": "0.7.85",
|
|
15
|
+
"@assistant-ui/react-markdown": "^0.7.21",
|
|
16
|
+
"@assistant-ui/react-ui": "^0.1.8",
|
|
17
|
+
"@mastra/client-js": "workspace:*",
|
|
18
|
+
"next": "15.0.3",
|
|
19
|
+
"react": "^19.0.0",
|
|
20
|
+
"react-dom": "^19.0.0",
|
|
21
|
+
"tailwindcss-animate": "^1.0.7",
|
|
22
|
+
"zod": "^3.24.2"
|
|
23
|
+
},
|
|
24
|
+
"devDependencies": {
|
|
25
|
+
"@types/node": "^20.17.27",
|
|
26
|
+
"@types/react": "^19.0.10",
|
|
27
|
+
"@types/react-dom": "^19.0.4",
|
|
28
|
+
"eslint": "^8.57.1",
|
|
29
|
+
"eslint-config-next": "15.0.3",
|
|
30
|
+
"postcss": "^8.5.3",
|
|
31
|
+
"tailwindcss": "^3.4.17",
|
|
32
|
+
"typescript": "^5.8.2"
|
|
33
|
+
},
|
|
34
|
+
"version": "0.0.0"
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
```
|
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
### package.json
|
|
2
|
+
```json
|
|
3
|
+
{
|
|
4
|
+
"name": "examples-bird-checker-with-express",
|
|
5
|
+
"description": "",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"main": "index.js",
|
|
8
|
+
"version": "0.0.1",
|
|
9
|
+
"scripts": {
|
|
10
|
+
"start": "tsx src/index.ts"
|
|
11
|
+
},
|
|
12
|
+
"private": true,
|
|
13
|
+
"keywords": [],
|
|
14
|
+
"author": "",
|
|
15
|
+
"license": "MIT",
|
|
16
|
+
"devDependencies": {
|
|
17
|
+
"@types/express": "^4.0.0",
|
|
18
|
+
"@types/node": "^20.17.27",
|
|
19
|
+
"concurrently": "^9.1.2",
|
|
20
|
+
"dotenv": "^16.4.7",
|
|
21
|
+
"express": "^4.21.2",
|
|
22
|
+
"nodemon": "^3.1.9",
|
|
23
|
+
"ts-node": "^10.9.2",
|
|
24
|
+
"tsx": "^4.19.3",
|
|
25
|
+
"typescript": "^5.8.2"
|
|
26
|
+
},
|
|
27
|
+
"dependencies": {
|
|
28
|
+
"@ai-sdk/anthropic": "latest",
|
|
29
|
+
"@mastra/core": "workspace:*",
|
|
30
|
+
"ai": "latest",
|
|
31
|
+
"zod": "^3.24.2"
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
### index.ts
|
|
38
|
+
```typescript
|
|
39
|
+
import { config } from 'dotenv';
|
|
40
|
+
import express, { Request, Response } from 'express';
|
|
41
|
+
import { z } from 'zod';
|
|
42
|
+
|
|
43
|
+
import { getRandomImage, ImageQuery } from './lib/utils';
|
|
44
|
+
import { mastra } from './mastra/index';
|
|
45
|
+
|
|
46
|
+
config();
|
|
47
|
+
|
|
48
|
+
const app = express();
|
|
49
|
+
|
|
50
|
+
app.use(express.json());
|
|
51
|
+
|
|
52
|
+
const port = process.env.PORT || 3001;
|
|
53
|
+
|
|
54
|
+
app.get('/', (req: Request, res: Response) => {
|
|
55
|
+
res.send('Hello, TypeScript Express!');
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
app.get('/api/get-unsplash-image', async (req: Request, res: Response) => {
|
|
59
|
+
try {
|
|
60
|
+
const imageQuery = (req?.query?.query || 'wildlife') as ImageQuery;
|
|
61
|
+
|
|
62
|
+
const image = await getRandomImage({ query: imageQuery });
|
|
63
|
+
|
|
64
|
+
if (!image.ok) {
|
|
65
|
+
res.status(400).send({ msg: image.error });
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
res.send(image.data);
|
|
70
|
+
} catch (err) {
|
|
71
|
+
console.log('get unsplash image err===', err);
|
|
72
|
+
res.status(400).send({ msg: 'Could not fetch image' });
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
app.post('/api/image-metadata', async (req: Request, res: Response) => {
|
|
77
|
+
try {
|
|
78
|
+
const imageUrl = req.body?.imageUrl;
|
|
79
|
+
|
|
80
|
+
if (!imageUrl) {
|
|
81
|
+
res.status(400).send({ msg: 'Image url is required' });
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
const birdCheckerAgent = mastra.getAgent('birdCheckerAgent');
|
|
86
|
+
|
|
87
|
+
if (!birdCheckerAgent) {
|
|
88
|
+
res.sendStatus(404);
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
const response = await birdCheckerAgent.generate(
|
|
93
|
+
[
|
|
94
|
+
{
|
|
95
|
+
role: 'user',
|
|
96
|
+
content: [
|
|
97
|
+
{
|
|
98
|
+
type: 'image',
|
|
99
|
+
image: imageUrl,
|
|
100
|
+
},
|
|
101
|
+
{
|
|
102
|
+
type: 'text',
|
|
103
|
+
text: "view this image and let me know if it's a bird or not, and the scientific name of the bird without any explanation. Also summarize the location for this picture in one or two short sentences understandable by a high school student",
|
|
104
|
+
},
|
|
105
|
+
],
|
|
106
|
+
},
|
|
107
|
+
],
|
|
108
|
+
{
|
|
109
|
+
output: z.object({
|
|
110
|
+
bird: z.boolean(),
|
|
111
|
+
species: z.string(),
|
|
112
|
+
location: z.string(),
|
|
113
|
+
}),
|
|
114
|
+
},
|
|
115
|
+
);
|
|
116
|
+
|
|
117
|
+
const { object } = response;
|
|
118
|
+
|
|
119
|
+
console.log('response==', JSON.stringify(object, null, 2));
|
|
120
|
+
|
|
121
|
+
res.send(object);
|
|
122
|
+
} catch (err) {
|
|
123
|
+
console.log('get image metadata err===', err);
|
|
124
|
+
res.status(400).send({ msg: 'Could not fetch image metadata' });
|
|
125
|
+
}
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
app.listen(port, () => {
|
|
129
|
+
console.log(`Server running at http://localhost:${port}`);
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
### lib/utils.ts
|
|
135
|
+
```typescript
|
|
136
|
+
export type ImageQuery = 'wildlife' | 'feathers' | 'flying' | 'birds';
|
|
137
|
+
|
|
138
|
+
export const getRandomImage = async ({ query }: { query: ImageQuery }) => {
|
|
139
|
+
const page = Math.floor(Math.random() * 20);
|
|
140
|
+
const order_by = Math.random() < 0.5 ? 'relevant' : 'latest';
|
|
141
|
+
try {
|
|
142
|
+
const res = await fetch(`https://api.unsplash.com/search/photos?query=${query}&page=${page}&order_by=${order_by}`, {
|
|
143
|
+
method: 'GET',
|
|
144
|
+
headers: {
|
|
145
|
+
Authorization: `Client-ID ${process.env.UNSPLASH_ACCESS_KEY}`,
|
|
146
|
+
'Accept-Version': 'v1',
|
|
147
|
+
},
|
|
148
|
+
//@ts-ignore
|
|
149
|
+
cache: 'no-store',
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
if (!res.ok) {
|
|
153
|
+
console.log('res-----', res);
|
|
154
|
+
return {
|
|
155
|
+
ok: false,
|
|
156
|
+
error: 'Failed to fetch image',
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
const data = (await res.json()) as { results: any[] };
|
|
161
|
+
const randomNo = Math.floor(Math.random() * data.results.length);
|
|
162
|
+
|
|
163
|
+
const { urls, user } = data.results[randomNo];
|
|
164
|
+
|
|
165
|
+
const resp = {
|
|
166
|
+
imageUrl: urls?.raw,
|
|
167
|
+
photographerName: user?.first_name,
|
|
168
|
+
photographerProfile: user?.links?.html,
|
|
169
|
+
};
|
|
170
|
+
|
|
171
|
+
return {
|
|
172
|
+
ok: true,
|
|
173
|
+
data: resp,
|
|
174
|
+
};
|
|
175
|
+
} catch (err) {
|
|
176
|
+
console.log('Error in get_random_image api executor===', err);
|
|
177
|
+
return {
|
|
178
|
+
ok: false,
|
|
179
|
+
error: 'Error fetching image',
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
};
|
|
183
|
+
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
### mastra/agents/agent.ts
|
|
187
|
+
```typescript
|
|
188
|
+
import { anthropic } from '@ai-sdk/anthropic';
|
|
189
|
+
import { Agent } from '@mastra/core/agent';
|
|
190
|
+
|
|
191
|
+
export const birdCheckerAgent = new Agent({
|
|
192
|
+
name: 'Bird checker',
|
|
193
|
+
instructions:
|
|
194
|
+
'You can view an image and figure out if it is a bird or not. You can also figure out the species of the bird and where the picture was taken.',
|
|
195
|
+
model: anthropic('claude-3-haiku-20240307'),
|
|
196
|
+
});
|
|
197
|
+
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
### mastra/index.ts
|
|
201
|
+
```typescript
|
|
202
|
+
import { createLogger } from '@mastra/core/logger';
|
|
203
|
+
import { Mastra } from '@mastra/core';
|
|
204
|
+
|
|
205
|
+
import { birdCheckerAgent } from './agents/agent';
|
|
206
|
+
|
|
207
|
+
export const mastra = new Mastra({
|
|
208
|
+
agents: { birdCheckerAgent },
|
|
209
|
+
logger: createLogger({
|
|
210
|
+
name: 'CONSOLE',
|
|
211
|
+
level: 'info',
|
|
212
|
+
}),
|
|
213
|
+
});
|
|
214
|
+
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
### mastra/tools/index.ts
|
|
218
|
+
```typescript
|
|
219
|
+
import { createTool } from '@mastra/core/tools';
|
|
220
|
+
import { z } from 'zod';
|
|
221
|
+
|
|
222
|
+
import { getRandomImage } from '../../lib/utils';
|
|
223
|
+
|
|
224
|
+
export const getRandomImageTool = createTool({
|
|
225
|
+
id: 'Get a random image from unsplash',
|
|
226
|
+
description: 'Gets a random image from unsplash based on the selected option',
|
|
227
|
+
inputSchema: z.object({
|
|
228
|
+
query: z.enum(['wildlife', 'feathers', 'flying', 'birds']),
|
|
229
|
+
}),
|
|
230
|
+
execute: async ({ context }) => {
|
|
231
|
+
return getRandomImage(context);
|
|
232
|
+
},
|
|
233
|
+
});
|
|
234
|
+
|
|
235
|
+
```
|