@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,268 @@
|
|
|
1
|
+
### package.json
|
|
2
|
+
```json
|
|
3
|
+
{
|
|
4
|
+
"name": "memory-with-upstash",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"version": "1.0.1",
|
|
7
|
+
"description": "",
|
|
8
|
+
"private": true,
|
|
9
|
+
"main": "index.js",
|
|
10
|
+
"scripts": {
|
|
11
|
+
"prestart": "docker compose up -d",
|
|
12
|
+
"start": "npx bun src/index.ts",
|
|
13
|
+
"poststart": "docker compose down"
|
|
14
|
+
},
|
|
15
|
+
"keywords": [],
|
|
16
|
+
"author": "",
|
|
17
|
+
"license": "MIT",
|
|
18
|
+
"dependencies": {
|
|
19
|
+
"@ai-sdk/openai": "latest",
|
|
20
|
+
"@mastra/core": "workspace:*",
|
|
21
|
+
"@mastra/memory": "workspace:*",
|
|
22
|
+
"@mastra/pg": "workspace:*",
|
|
23
|
+
"@mastra/upstash": "workspace:*"
|
|
24
|
+
},
|
|
25
|
+
"devDependencies": {
|
|
26
|
+
"dotenv": "^16.4.7",
|
|
27
|
+
"tsx": "^4.19.3"
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
### bubble.ts
|
|
34
|
+
```typescript
|
|
35
|
+
type BubbleStyle = 'simple' | 'rounded';
|
|
36
|
+
|
|
37
|
+
interface BubbleOptions {
|
|
38
|
+
style?: BubbleStyle;
|
|
39
|
+
maxWidth?: number;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
interface BubbleCharacters {
|
|
43
|
+
topLeft: string;
|
|
44
|
+
topRight: string;
|
|
45
|
+
bottomLeft: string;
|
|
46
|
+
bottomRight: string;
|
|
47
|
+
horizontal: string;
|
|
48
|
+
vertical: string;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
class MessageBubble {
|
|
52
|
+
private readonly defaultMaxWidth = 80;
|
|
53
|
+
private readonly defaultStyle: BubbleStyle = 'simple';
|
|
54
|
+
|
|
55
|
+
private readonly styleCharacters: Record<BubbleStyle, BubbleCharacters> = {
|
|
56
|
+
rounded: {
|
|
57
|
+
topLeft: '╭',
|
|
58
|
+
topRight: '╮',
|
|
59
|
+
bottomLeft: '╰',
|
|
60
|
+
bottomRight: '╯',
|
|
61
|
+
horizontal: '─',
|
|
62
|
+
vertical: '│',
|
|
63
|
+
},
|
|
64
|
+
simple: {
|
|
65
|
+
topLeft: '+',
|
|
66
|
+
topRight: '+',
|
|
67
|
+
bottomLeft: '+',
|
|
68
|
+
bottomRight: '+',
|
|
69
|
+
horizontal: '-',
|
|
70
|
+
vertical: '|',
|
|
71
|
+
},
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
private wrapText(text: string, maxWidth: number): string[] {
|
|
75
|
+
const lines: string[] = [];
|
|
76
|
+
const rawLines = text.split('\n');
|
|
77
|
+
|
|
78
|
+
rawLines.forEach((line: string) => {
|
|
79
|
+
const isListItem = line.trim().match(/^[-*•]\s/);
|
|
80
|
+
const indent = isListItem ? 2 : 0;
|
|
81
|
+
const availableWidth = maxWidth - indent;
|
|
82
|
+
|
|
83
|
+
if (line.trim() === '') {
|
|
84
|
+
lines.push('');
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
let currentLine = '';
|
|
89
|
+
const words = line.trim().split(' ');
|
|
90
|
+
|
|
91
|
+
words.forEach((word: string) => {
|
|
92
|
+
if (currentLine === '' && isListItem) {
|
|
93
|
+
currentLine = ' ' + word;
|
|
94
|
+
} else if (currentLine === '') {
|
|
95
|
+
currentLine = word;
|
|
96
|
+
} else if ((currentLine + ' ' + word).length <= maxWidth) {
|
|
97
|
+
currentLine += ' ' + word;
|
|
98
|
+
} else {
|
|
99
|
+
lines.push(currentLine);
|
|
100
|
+
currentLine = isListItem ? ' ' + word : word;
|
|
101
|
+
}
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
if (currentLine) {
|
|
105
|
+
lines.push(currentLine);
|
|
106
|
+
}
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
return lines;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
private validateOptions(options: BubbleOptions): void {
|
|
113
|
+
if (options.maxWidth && options.maxWidth < 20) {
|
|
114
|
+
throw new Error('maxWidth must be at least 20 characters');
|
|
115
|
+
}
|
|
116
|
+
if (options.style && !this.styleCharacters[options.style]) {
|
|
117
|
+
throw new Error('Invalid style. Must be either "simple" or "rounded"');
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
public print(message: string, options: BubbleOptions = {}): void {
|
|
122
|
+
this.validateOptions(options);
|
|
123
|
+
|
|
124
|
+
const maxWidth = options.maxWidth || this.defaultMaxWidth;
|
|
125
|
+
const style = options.style || this.defaultStyle;
|
|
126
|
+
const chars = this.styleCharacters[style];
|
|
127
|
+
|
|
128
|
+
// Process and wrap the text
|
|
129
|
+
const wrappedLines = this.wrapText(message, maxWidth - 4);
|
|
130
|
+
const contentWidth = Math.min(maxWidth - 4, Math.max(...wrappedLines.map(line => line.length)));
|
|
131
|
+
|
|
132
|
+
// Create borders
|
|
133
|
+
const topBorder = chars.topLeft + chars.horizontal.repeat(contentWidth + 2) + chars.topRight;
|
|
134
|
+
const bottomBorder = chars.bottomLeft + chars.horizontal.repeat(contentWidth + 2) + chars.bottomRight;
|
|
135
|
+
|
|
136
|
+
// Print the bubble
|
|
137
|
+
console.log(topBorder);
|
|
138
|
+
wrappedLines.forEach(line => {
|
|
139
|
+
console.log(`${chars.vertical} ${line.padEnd(contentWidth)} ${chars.vertical}`);
|
|
140
|
+
});
|
|
141
|
+
console.log(bottomBorder);
|
|
142
|
+
console.log(' ╰╯');
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
// Example usage:
|
|
147
|
+
export const bubble = new MessageBubble();
|
|
148
|
+
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
### index.ts
|
|
152
|
+
```typescript
|
|
153
|
+
import { randomUUID } from 'crypto';
|
|
154
|
+
|
|
155
|
+
import { mastra } from './mastra';
|
|
156
|
+
|
|
157
|
+
function log(message: string) {
|
|
158
|
+
console.log(`\n>>Prompt: ${message}
|
|
159
|
+
`);
|
|
160
|
+
return message;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
const agent = mastra.getAgent('chefAgent');
|
|
164
|
+
const threadId = randomUUID();
|
|
165
|
+
const resourceId = 'SOME_USER_ID';
|
|
166
|
+
|
|
167
|
+
async function logRes(res: Awaited<ReturnType<typeof agent.stream>>) {
|
|
168
|
+
console.log(`\n👨🍳 Chef:`);
|
|
169
|
+
for await (const chunk of res.textStream) {
|
|
170
|
+
process.stdout.write(chunk);
|
|
171
|
+
}
|
|
172
|
+
console.log(`\n\n`);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
async function main() {
|
|
176
|
+
await logRes(
|
|
177
|
+
await agent.stream(
|
|
178
|
+
log(
|
|
179
|
+
'In my kitchen I have: pasta, canned tomatoes, garlic, olive oil, and some dried herbs (basil and oregano). What can I make? Please keep your answer brief, only give me the high level steps.',
|
|
180
|
+
),
|
|
181
|
+
{
|
|
182
|
+
threadId,
|
|
183
|
+
resourceId,
|
|
184
|
+
},
|
|
185
|
+
),
|
|
186
|
+
);
|
|
187
|
+
|
|
188
|
+
await logRes(
|
|
189
|
+
await agent.stream(
|
|
190
|
+
log(
|
|
191
|
+
"Now I'm over at my friend's house, and they have: chicken thighs, coconut milk, sweet potatoes, and some curry powder.",
|
|
192
|
+
),
|
|
193
|
+
{
|
|
194
|
+
threadId,
|
|
195
|
+
resourceId,
|
|
196
|
+
},
|
|
197
|
+
),
|
|
198
|
+
);
|
|
199
|
+
|
|
200
|
+
await logRes(
|
|
201
|
+
await agent.stream(log('What did we cook before I went to my friends house?'), {
|
|
202
|
+
threadId,
|
|
203
|
+
resourceId,
|
|
204
|
+
memoryOptions: {
|
|
205
|
+
lastMessages: 3,
|
|
206
|
+
},
|
|
207
|
+
}),
|
|
208
|
+
);
|
|
209
|
+
|
|
210
|
+
process.exit(0);
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
main();
|
|
214
|
+
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
### mastra/agents/index.ts
|
|
218
|
+
```typescript
|
|
219
|
+
import { openai } from '@ai-sdk/openai';
|
|
220
|
+
import { Agent } from '@mastra/core';
|
|
221
|
+
import { Memory } from '@mastra/memory';
|
|
222
|
+
import { PgVector } from '@mastra/pg';
|
|
223
|
+
import { UpstashStore } from '@mastra/upstash';
|
|
224
|
+
|
|
225
|
+
const memory = new Memory({
|
|
226
|
+
storage: new UpstashStore({
|
|
227
|
+
url: 'http://localhost:8089',
|
|
228
|
+
token: 'test_token',
|
|
229
|
+
}),
|
|
230
|
+
vector: new PgVector(`postgresql://postgres:postgres@localhost:5433`),
|
|
231
|
+
options: {
|
|
232
|
+
lastMessages: 1,
|
|
233
|
+
semanticRecall: {
|
|
234
|
+
topK: 3,
|
|
235
|
+
messageRange: 2,
|
|
236
|
+
},
|
|
237
|
+
},
|
|
238
|
+
});
|
|
239
|
+
|
|
240
|
+
export const chefAgent = new Agent({
|
|
241
|
+
name: 'chefAgent',
|
|
242
|
+
memory,
|
|
243
|
+
instructions:
|
|
244
|
+
'You are Michel, a practical and experienced home chef who helps people cook great meals with whatever ingredients they have available. Your first priority is understanding what ingredients and equipment the user has access to, then suggesting achievable recipes. You explain cooking steps clearly and offer substitutions when needed, maintaining a friendly and encouraging tone throughout.',
|
|
245
|
+
model: openai('gpt-4o'),
|
|
246
|
+
});
|
|
247
|
+
|
|
248
|
+
export const memoryAgent = new Agent({
|
|
249
|
+
name: 'Memory Agent',
|
|
250
|
+
memory,
|
|
251
|
+
instructions:
|
|
252
|
+
"You are an AI agent with the ability to automatically recall memories from previous interactions. You may have conversations that last hours, days, months, or years. If you don't know it already you should ask for the users name and some info about them.",
|
|
253
|
+
model: openai('gpt-4o'),
|
|
254
|
+
});
|
|
255
|
+
|
|
256
|
+
```
|
|
257
|
+
|
|
258
|
+
### mastra/index.ts
|
|
259
|
+
```typescript
|
|
260
|
+
import { Mastra } from '@mastra/core';
|
|
261
|
+
|
|
262
|
+
import { chefAgent, memoryAgent } from './agents';
|
|
263
|
+
|
|
264
|
+
export const mastra = new Mastra({
|
|
265
|
+
agents: { chefAgent, memoryAgent },
|
|
266
|
+
});
|
|
267
|
+
|
|
268
|
+
```
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
### package.json
|
|
2
|
+
```json
|
|
3
|
+
{
|
|
4
|
+
"name": "examples-quick-start",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"private": true,
|
|
7
|
+
"description": "",
|
|
8
|
+
"main": "index.js",
|
|
9
|
+
"scripts": {
|
|
10
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
11
|
+
},
|
|
12
|
+
"keywords": [],
|
|
13
|
+
"author": "",
|
|
14
|
+
"license": "MIT",
|
|
15
|
+
"devDependencies": {
|
|
16
|
+
"@types/node": "^20.17.27",
|
|
17
|
+
"tsx": "^4.19.3",
|
|
18
|
+
"typescript": "^5.8.2",
|
|
19
|
+
"zod": "^3.24.2"
|
|
20
|
+
},
|
|
21
|
+
"dependencies": {
|
|
22
|
+
"@ai-sdk/anthropic": "^1.1.15",
|
|
23
|
+
"@ai-sdk/groq": "latest",
|
|
24
|
+
"@ai-sdk/openai": "latest",
|
|
25
|
+
"@mastra/core": "workspace:*",
|
|
26
|
+
"@mastra/loggers": "workspace:*",
|
|
27
|
+
"@mastra/memory": "workspace:*",
|
|
28
|
+
"ai": "latest"
|
|
29
|
+
},
|
|
30
|
+
"version": "0.0.1"
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
### index.ts
|
|
36
|
+
```typescript
|
|
37
|
+
import { z } from 'zod';
|
|
38
|
+
|
|
39
|
+
import { mastra } from './mastra';
|
|
40
|
+
|
|
41
|
+
const specieSchema = z.object({
|
|
42
|
+
species: z.string(),
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
const main = async () => {
|
|
46
|
+
const agentCat = mastra.getAgent('catOne');
|
|
47
|
+
|
|
48
|
+
try {
|
|
49
|
+
const result = await agentCat.generate('What is the most popular cat species?', {
|
|
50
|
+
output: specieSchema,
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
const res = specieSchema.parse(result?.object);
|
|
54
|
+
|
|
55
|
+
console.log(res.species);
|
|
56
|
+
|
|
57
|
+
const { start } = mastra.getWorkflow('logCatWorkflow').createRun();
|
|
58
|
+
|
|
59
|
+
await start({ triggerData: { name: res.species } });
|
|
60
|
+
} catch (err) {
|
|
61
|
+
console.error(err);
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
main();
|
|
66
|
+
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
### mastra/agents/agent.ts
|
|
70
|
+
```typescript
|
|
71
|
+
import { openai } from '@ai-sdk/openai';
|
|
72
|
+
import { Agent } from '@mastra/core';
|
|
73
|
+
|
|
74
|
+
export const catOne = new Agent({
|
|
75
|
+
name: 'cat-one',
|
|
76
|
+
instructions:
|
|
77
|
+
'You are a feline expert with comprehensive knowledge of all cat species, from domestic breeds to wild big cats. As a lifelong cat specialist, you understand their behavior, biology, social structures, and evolutionary history in great depth. If you are asked for a specie name, do not return a paragraph, a succint two or three letter name of the species will suffice.',
|
|
78
|
+
model: openai('gpt-4o'),
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
### mastra/index.ts
|
|
84
|
+
```typescript
|
|
85
|
+
import { createLogger, Mastra } from '@mastra/core';
|
|
86
|
+
|
|
87
|
+
import { catOne } from './agents/agent';
|
|
88
|
+
import { logCatWorkflow } from './workflow';
|
|
89
|
+
|
|
90
|
+
export const mastra = new Mastra({
|
|
91
|
+
agents: { catOne },
|
|
92
|
+
workflows: {
|
|
93
|
+
logCatWorkflow,
|
|
94
|
+
},
|
|
95
|
+
logger: createLogger({
|
|
96
|
+
name: 'Mastra',
|
|
97
|
+
level: 'debug',
|
|
98
|
+
}),
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
### mastra/workflow/index.ts
|
|
104
|
+
```typescript
|
|
105
|
+
import { Workflow, Step } from '@mastra/core';
|
|
106
|
+
import { z } from 'zod';
|
|
107
|
+
|
|
108
|
+
const logCatName = new Step({
|
|
109
|
+
id: 'logCatName',
|
|
110
|
+
outputSchema: z.object({
|
|
111
|
+
rawText: z.string(),
|
|
112
|
+
}),
|
|
113
|
+
execute: async ({ context }) => {
|
|
114
|
+
const name = context?.getStepResult<{ name: string }>('trigger')?.name;
|
|
115
|
+
console.log(`Hello, ${name} 🐈`);
|
|
116
|
+
return { rawText: `Hello ${name}` };
|
|
117
|
+
},
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
export const logCatWorkflow = new Workflow({
|
|
121
|
+
name: 'log-cat-workflow',
|
|
122
|
+
triggerSchema: z.object({
|
|
123
|
+
name: z.string(),
|
|
124
|
+
}),
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
logCatWorkflow.step(logCatName).commit();
|
|
128
|
+
|
|
129
|
+
```
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
### package.json
|
|
2
|
+
```json
|
|
3
|
+
{
|
|
4
|
+
"name": "examples-stock-price-tool",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"private": true,
|
|
7
|
+
"main": "index.js",
|
|
8
|
+
"scripts": {
|
|
9
|
+
"dev": "mastra dev",
|
|
10
|
+
"test": "cross-env NODE_OPTIONS='--experimental-vm-modules --max-old-space-size=8192' jest"
|
|
11
|
+
},
|
|
12
|
+
"keywords": [],
|
|
13
|
+
"author": "",
|
|
14
|
+
"license": "MIT",
|
|
15
|
+
"description": "",
|
|
16
|
+
"dependencies": {
|
|
17
|
+
"@ai-sdk/openai": "latest",
|
|
18
|
+
"@mastra/core": "workspace:*",
|
|
19
|
+
"zod": "^3.24.2"
|
|
20
|
+
},
|
|
21
|
+
"devDependencies": {
|
|
22
|
+
"@jest/globals": "^29.7.0",
|
|
23
|
+
"jest": "^29.7.0",
|
|
24
|
+
"mastra": "workspace:*",
|
|
25
|
+
"ts-jest": "^29.2.6"
|
|
26
|
+
},
|
|
27
|
+
"version": "0.0.1"
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
### index.ts
|
|
33
|
+
```typescript
|
|
34
|
+
import { mastra } from './mastra';
|
|
35
|
+
|
|
36
|
+
async function main() {
|
|
37
|
+
const stockAgent = mastra.getAgent('stockAgent');
|
|
38
|
+
const response = await stockAgent.generate('What is the current stock price of Apple (AAPL)?');
|
|
39
|
+
|
|
40
|
+
const toolCall: any = response.toolResults.find((result: any) => result.toolName === 'stockPrices');
|
|
41
|
+
|
|
42
|
+
const currentPrice = toolCall?.result?.currentPrice;
|
|
43
|
+
|
|
44
|
+
console.log(`The current price of Apple (AAPL) is $${currentPrice}`);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
main();
|
|
48
|
+
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
### mastra/agents/index.ts
|
|
52
|
+
```typescript
|
|
53
|
+
import { openai } from '@ai-sdk/openai';
|
|
54
|
+
import { Agent } from '@mastra/core/agent';
|
|
55
|
+
|
|
56
|
+
import { stockPrices } from '../tools/stock-price';
|
|
57
|
+
|
|
58
|
+
export const stockAgent = new Agent({
|
|
59
|
+
name: 'Stock Agent',
|
|
60
|
+
instructions:
|
|
61
|
+
'You are a helpful assistant that provides current stock prices. When asked about a stock, use the stock price tool to fetch the stock price.',
|
|
62
|
+
model: openai('gpt-4o'),
|
|
63
|
+
tools: {
|
|
64
|
+
stockPrices,
|
|
65
|
+
},
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
### mastra/index.ts
|
|
71
|
+
```typescript
|
|
72
|
+
import { Mastra } from '@mastra/core';
|
|
73
|
+
|
|
74
|
+
import { stockAgent } from './agents';
|
|
75
|
+
|
|
76
|
+
export const mastra = new Mastra({
|
|
77
|
+
agents: { stockAgent },
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
### mastra/tools/stock-price.ts
|
|
83
|
+
```typescript
|
|
84
|
+
import { createTool } from '@mastra/core/tools';
|
|
85
|
+
import { z } from 'zod';
|
|
86
|
+
|
|
87
|
+
export const getStockPrice = async (symbol: string) => {
|
|
88
|
+
const data = await fetch(`https://mastra-stock-data.vercel.app/api/stock-data?symbol=${symbol}`).then(r => r.json());
|
|
89
|
+
return data.prices['4. close'];
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
export const stockPrices = createTool({
|
|
93
|
+
id: 'Get Stock Price',
|
|
94
|
+
inputSchema: z.object({
|
|
95
|
+
symbol: z.string(),
|
|
96
|
+
}),
|
|
97
|
+
description: `Fetches the last day's closing stock price for a given symbol`,
|
|
98
|
+
execute: async ({ context }) => {
|
|
99
|
+
console.log('Using tool to fetch stock price for', context.symbol);
|
|
100
|
+
return {
|
|
101
|
+
symbol: context.symbol,
|
|
102
|
+
currentPrice: await getStockPrice(context.symbol),
|
|
103
|
+
};
|
|
104
|
+
},
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
### mastra/tools/tools.test.ts
|
|
110
|
+
```typescript
|
|
111
|
+
import { describe, it, expect } from 'vitest';
|
|
112
|
+
|
|
113
|
+
import { getStockPrice } from './stock-price';
|
|
114
|
+
|
|
115
|
+
describe('Test Tools', () => {
|
|
116
|
+
it('should run the stockPrices', async () => {
|
|
117
|
+
const result = await getStockPrice('AAPL');
|
|
118
|
+
|
|
119
|
+
console.log(result);
|
|
120
|
+
expect(result).toBeDefined();
|
|
121
|
+
});
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
```
|