langwatch 0.3.0-prerelease.1 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/chunk-4BZATFKJ.mjs +181 -0
- package/dist/chunk-4BZATFKJ.mjs.map +1 -0
- package/dist/chunk-76KNOWLS.js +39 -0
- package/dist/chunk-76KNOWLS.js.map +1 -0
- package/dist/chunk-CSC3CMIT.mjs +118 -0
- package/dist/chunk-CSC3CMIT.mjs.map +1 -0
- package/dist/chunk-F63YKTXA.mjs +47 -0
- package/dist/chunk-F63YKTXA.mjs.map +1 -0
- package/dist/chunk-G3AUABT7.js +4 -0
- package/dist/chunk-G3AUABT7.js.map +1 -0
- package/dist/chunk-HPC6Z7J4.js +118 -0
- package/dist/chunk-HPC6Z7J4.js.map +1 -0
- package/dist/chunk-KGDAENGD.js +50 -0
- package/dist/chunk-KGDAENGD.js.map +1 -0
- package/dist/chunk-LD74LVRU.js +47 -0
- package/dist/chunk-LD74LVRU.js.map +1 -0
- package/dist/chunk-OM7VY3XT.mjs +4 -0
- package/dist/chunk-OM7VY3XT.mjs.map +1 -0
- package/dist/chunk-PCQVQ7SB.js +45 -0
- package/dist/chunk-PCQVQ7SB.js.map +1 -0
- package/dist/chunk-PMBEK6YE.mjs +424 -0
- package/dist/chunk-PMBEK6YE.mjs.map +1 -0
- package/dist/chunk-PR3JDWC3.mjs +50 -0
- package/dist/chunk-PR3JDWC3.mjs.map +1 -0
- package/dist/chunk-PTJ6AAI7.js +360 -0
- package/dist/chunk-PTJ6AAI7.js.map +1 -0
- package/dist/chunk-QEWDG5QE.mjs +45 -0
- package/dist/chunk-QEWDG5QE.mjs.map +1 -0
- package/dist/chunk-SVJ7SCGB.js +424 -0
- package/dist/chunk-SVJ7SCGB.js.map +1 -0
- package/dist/chunk-VJSOCNPA.js +181 -0
- package/dist/chunk-VJSOCNPA.js.map +1 -0
- package/dist/chunk-X62YT4WB.mjs +39 -0
- package/dist/chunk-X62YT4WB.mjs.map +1 -0
- package/dist/chunk-Z5J5UI5E.mjs +360 -0
- package/dist/chunk-Z5J5UI5E.mjs.map +1 -0
- package/dist/client-B2HqIKg6.d.ts +51 -0
- package/dist/client-XyCqclCi.d.mts +51 -0
- package/dist/client-browser.d.mts +8 -0
- package/dist/client-browser.d.ts +8 -0
- package/dist/client-browser.js +83 -0
- package/dist/client-browser.js.map +1 -0
- package/dist/client-browser.mjs +83 -0
- package/dist/client-browser.mjs.map +1 -0
- package/dist/client-node.d.mts +8 -0
- package/dist/client-node.d.ts +8 -0
- package/dist/client-node.js +90 -0
- package/dist/client-node.js.map +1 -0
- package/dist/client-node.mjs +90 -0
- package/dist/client-node.mjs.map +1 -0
- package/dist/evaluation/index.d.mts +897 -0
- package/dist/evaluation/index.d.ts +897 -0
- package/dist/evaluation/index.js +13 -0
- package/dist/evaluation/index.js.map +1 -0
- package/dist/evaluation/index.mjs +13 -0
- package/dist/evaluation/index.mjs.map +1 -0
- package/dist/filterable-batch-span-processor-zO5kcjBY.d.mts +64 -0
- package/dist/filterable-batch-span-processor-zO5kcjBY.d.ts +64 -0
- package/dist/index.d.mts +48 -0
- package/{src/observability/exporters/langwatch-exporter.ts → dist/index.d.ts} +13 -18
- package/dist/index.js +30 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +30 -0
- package/dist/index.mjs.map +1 -0
- package/dist/observability/index.d.mts +260 -0
- package/dist/observability/index.d.ts +260 -0
- package/dist/observability/index.js +20 -0
- package/dist/observability/index.js.map +1 -0
- package/dist/observability/index.mjs +20 -0
- package/dist/observability/index.mjs.map +1 -0
- package/dist/observability/instrumentation/langchain/index.d.mts +40 -0
- package/dist/observability/instrumentation/langchain/index.d.ts +40 -0
- package/dist/observability/instrumentation/langchain/index.js +666 -0
- package/dist/observability/instrumentation/langchain/index.js.map +1 -0
- package/dist/observability/instrumentation/langchain/index.mjs +666 -0
- package/dist/observability/instrumentation/langchain/index.mjs.map +1 -0
- package/dist/prompt/index.d.mts +10 -0
- package/dist/prompt/index.d.ts +10 -0
- package/dist/prompt/index.js +18 -0
- package/dist/prompt/index.js.map +1 -0
- package/dist/prompt/index.mjs +18 -0
- package/dist/prompt/index.mjs.map +1 -0
- package/dist/prompt-BXJWdbQp.d.mts +1967 -0
- package/dist/prompt-BXJWdbQp.d.ts +1967 -0
- package/dist/record-evaluation-CmxMXa-3.d.mts +25 -0
- package/dist/record-evaluation-CmxMXa-3.d.ts +25 -0
- package/dist/trace-D-bZOuqb.d.mts +622 -0
- package/dist/trace-G2312klE.d.ts +622 -0
- package/package.json +9 -4
- package/.editorconfig +0 -16
- package/.eslintrc.cjs +0 -37
- package/copy-types.sh +0 -28
- package/examples/langchain/.env.example +0 -2
- package/examples/langchain/README.md +0 -42
- package/examples/langchain/package-lock.json +0 -2930
- package/examples/langchain/package.json +0 -27
- package/examples/langchain/src/cli-markdown.d.ts +0 -137
- package/examples/langchain/src/index.ts +0 -109
- package/examples/langchain/tsconfig.json +0 -25
- package/examples/langgraph/.env.example +0 -2
- package/examples/langgraph/README.md +0 -42
- package/examples/langgraph/package-lock.json +0 -3031
- package/examples/langgraph/package.json +0 -28
- package/examples/langgraph/src/cli-markdown.d.ts +0 -137
- package/examples/langgraph/src/index.ts +0 -196
- package/examples/langgraph/tsconfig.json +0 -25
- package/examples/mastra/.env.example +0 -2
- package/examples/mastra/README.md +0 -57
- package/examples/mastra/package-lock.json +0 -5296
- package/examples/mastra/package.json +0 -32
- package/examples/mastra/src/cli-markdown.d.ts +0 -137
- package/examples/mastra/src/index.ts +0 -120
- package/examples/mastra/src/mastra/agents/weather-agent.ts +0 -30
- package/examples/mastra/src/mastra/index.ts +0 -21
- package/examples/mastra/src/mastra/tools/weather-tool.ts +0 -102
- package/examples/mastra/tsconfig.json +0 -25
- package/examples/vercel-ai/.env.example +0 -2
- package/examples/vercel-ai/README.md +0 -38
- package/examples/vercel-ai/package-lock.json +0 -2571
- package/examples/vercel-ai/package.json +0 -27
- package/examples/vercel-ai/src/cli-markdown.d.ts +0 -137
- package/examples/vercel-ai/src/index.ts +0 -110
- package/examples/vercel-ai/src/instrumentation.ts +0 -9
- package/examples/vercel-ai/tsconfig.json +0 -25
- package/src/__tests__/client-browser.test.ts +0 -92
- package/src/__tests__/client-node.test.ts +0 -76
- package/src/__tests__/client.test.ts +0 -71
- package/src/__tests__/integration/client-browser.test.ts +0 -46
- package/src/__tests__/integration/client-node.test.ts +0 -46
- package/src/client-browser.ts +0 -70
- package/src/client-node.ts +0 -82
- package/src/client-shared.ts +0 -72
- package/src/client.ts +0 -119
- package/src/evaluation/__tests__/record-evaluation.test.ts +0 -112
- package/src/evaluation/__tests__/run-evaluation.test.ts +0 -171
- package/src/evaluation/index.ts +0 -2
- package/src/evaluation/record-evaluation.ts +0 -101
- package/src/evaluation/run-evaluation.ts +0 -133
- package/src/evaluation/tracer.ts +0 -3
- package/src/evaluation/types.ts +0 -23
- package/src/index.ts +0 -13
- package/src/internal/api/__tests__/errors.test.ts +0 -98
- package/src/internal/api/client.ts +0 -30
- package/src/internal/api/errors.ts +0 -32
- package/src/internal/generated/openapi/.gitkeep +0 -0
- package/src/internal/generated/types/.gitkeep +0 -0
- package/src/observability/__tests__/integration/base.test.ts +0 -74
- package/src/observability/__tests__/integration/browser-setup-ordering.test.ts +0 -60
- package/src/observability/__tests__/integration/complex-nested-spans.test.ts +0 -29
- package/src/observability/__tests__/integration/error-handling.test.ts +0 -24
- package/src/observability/__tests__/integration/langwatch-disabled-otel.test.ts +0 -24
- package/src/observability/__tests__/integration/langwatch-first-then-vercel.test.ts +0 -24
- package/src/observability/__tests__/integration/multiple-setup-attempts.test.ts +0 -27
- package/src/observability/__tests__/integration/otel-ordering.test.ts +0 -27
- package/src/observability/__tests__/integration/vercel-configurations.test.ts +0 -20
- package/src/observability/__tests__/integration/vercel-first-then-langwatch.test.ts +0 -27
- package/src/observability/__tests__/span.test.ts +0 -214
- package/src/observability/__tests__/trace.test.ts +0 -180
- package/src/observability/exporters/index.ts +0 -1
- package/src/observability/index.ts +0 -4
- package/src/observability/instrumentation/langchain/__tests__/integration/langchain-chatbot.test.ts +0 -112
- package/src/observability/instrumentation/langchain/__tests__/langchain.test.ts +0 -284
- package/src/observability/instrumentation/langchain/index.ts +0 -624
- package/src/observability/processors/__tests__/filterable-batch-span-exporter.test.ts +0 -98
- package/src/observability/processors/filterable-batch-span-processor.ts +0 -99
- package/src/observability/processors/index.ts +0 -1
- package/src/observability/semconv/attributes.ts +0 -185
- package/src/observability/semconv/events.ts +0 -42
- package/src/observability/semconv/index.ts +0 -16
- package/src/observability/semconv/values.ts +0 -159
- package/src/observability/span.ts +0 -728
- package/src/observability/trace.ts +0 -301
- package/src/prompt/__tests__/prompt.test.ts +0 -139
- package/src/prompt/get-prompt-version.ts +0 -49
- package/src/prompt/get-prompt.ts +0 -44
- package/src/prompt/index.ts +0 -3
- package/src/prompt/prompt.ts +0 -133
- package/src/prompt/service.ts +0 -221
- package/src/prompt/tracer.ts +0 -3
- package/src/prompt/types.ts +0 -0
- package/ts-to-zod.config.js +0 -35
- package/tsconfig.json +0 -26
- package/tsup.config.ts +0 -20
- package/vitest.config.ts +0 -9
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "mastra-sdk-example",
|
|
3
|
-
"version": "1.0.0",
|
|
4
|
-
"description": "",
|
|
5
|
-
"main": "index.js",
|
|
6
|
-
"scripts": {
|
|
7
|
-
"start": "tsc && dotenv -- node dist/index.js",
|
|
8
|
-
"cli": "tsc && dotenv -- node dist/index.js",
|
|
9
|
-
"build": "tsc",
|
|
10
|
-
"test": "echo \"Error: no test specified\" && exit 1"
|
|
11
|
-
},
|
|
12
|
-
"keywords": [],
|
|
13
|
-
"author": "LangWatch",
|
|
14
|
-
"type": "module",
|
|
15
|
-
"license": "MIT",
|
|
16
|
-
"dependencies": {
|
|
17
|
-
"@ai-sdk/openai": "^1.3.23",
|
|
18
|
-
"@mastra/core": "^0.12.1",
|
|
19
|
-
"@mastra/libsql": "^0.12.0",
|
|
20
|
-
"@mastra/loggers": "^0.10.5",
|
|
21
|
-
"@mastra/memory": "^0.12.0",
|
|
22
|
-
"@opentelemetry/context-async-hooks": "^2.0.1",
|
|
23
|
-
"@opentelemetry/sdk-node": "^0.203.0",
|
|
24
|
-
"ai": "^5.0.0",
|
|
25
|
-
"cli-markdown": "^3.5.1",
|
|
26
|
-
"dotenv-cli": "^10.0.0",
|
|
27
|
-
"langwatch": "file:../../"
|
|
28
|
-
},
|
|
29
|
-
"devDependencies": {
|
|
30
|
-
"typescript": "^5.9.2"
|
|
31
|
-
}
|
|
32
|
-
}
|
|
@@ -1,137 +0,0 @@
|
|
|
1
|
-
declare module 'cli-markdown' {
|
|
2
|
-
export interface CliMarkdownOptions {
|
|
3
|
-
/**
|
|
4
|
-
* Custom styles for different markdown elements
|
|
5
|
-
*/
|
|
6
|
-
styles?: {
|
|
7
|
-
/**
|
|
8
|
-
* Style for headings (h1, h2, h3, etc.)
|
|
9
|
-
*/
|
|
10
|
-
heading?: string;
|
|
11
|
-
/**
|
|
12
|
-
* Style for bold text
|
|
13
|
-
*/
|
|
14
|
-
bold?: string;
|
|
15
|
-
/**
|
|
16
|
-
* Style for italic text
|
|
17
|
-
*/
|
|
18
|
-
italic?: string;
|
|
19
|
-
/**
|
|
20
|
-
* Style for code blocks
|
|
21
|
-
*/
|
|
22
|
-
code?: string;
|
|
23
|
-
/**
|
|
24
|
-
* Style for inline code
|
|
25
|
-
*/
|
|
26
|
-
inlineCode?: string;
|
|
27
|
-
/**
|
|
28
|
-
* Style for links
|
|
29
|
-
*/
|
|
30
|
-
link?: string;
|
|
31
|
-
/**
|
|
32
|
-
* Style for lists
|
|
33
|
-
*/
|
|
34
|
-
list?: string;
|
|
35
|
-
/**
|
|
36
|
-
* Style for blockquotes
|
|
37
|
-
*/
|
|
38
|
-
blockquote?: string;
|
|
39
|
-
/**
|
|
40
|
-
* Style for horizontal rules
|
|
41
|
-
*/
|
|
42
|
-
hr?: string;
|
|
43
|
-
};
|
|
44
|
-
/**
|
|
45
|
-
* Whether to preserve line breaks
|
|
46
|
-
*/
|
|
47
|
-
preserveLineBreaks?: boolean;
|
|
48
|
-
/**
|
|
49
|
-
* Custom renderer functions for different markdown elements
|
|
50
|
-
*/
|
|
51
|
-
renderers?: {
|
|
52
|
-
/**
|
|
53
|
-
* Custom renderer for headings
|
|
54
|
-
*/
|
|
55
|
-
heading?: (text: string, level: number) => string;
|
|
56
|
-
/**
|
|
57
|
-
* Custom renderer for paragraphs
|
|
58
|
-
*/
|
|
59
|
-
paragraph?: (text: string) => string;
|
|
60
|
-
/**
|
|
61
|
-
* Custom renderer for lists
|
|
62
|
-
*/
|
|
63
|
-
list?: (items: string[], ordered: boolean) => string;
|
|
64
|
-
/**
|
|
65
|
-
* Custom renderer for list items
|
|
66
|
-
*/
|
|
67
|
-
listItem?: (text: string, index: number) => string;
|
|
68
|
-
/**
|
|
69
|
-
* Custom renderer for code blocks
|
|
70
|
-
*/
|
|
71
|
-
code?: (code: string, language?: string) => string;
|
|
72
|
-
/**
|
|
73
|
-
* Custom renderer for inline code
|
|
74
|
-
*/
|
|
75
|
-
inlineCode?: (code: string) => string;
|
|
76
|
-
/**
|
|
77
|
-
* Custom renderer for links
|
|
78
|
-
*/
|
|
79
|
-
link?: (text: string, url: string) => string;
|
|
80
|
-
/**
|
|
81
|
-
* Custom renderer for images
|
|
82
|
-
*/
|
|
83
|
-
image?: (alt: string, url: string) => string;
|
|
84
|
-
/**
|
|
85
|
-
* Custom renderer for blockquotes
|
|
86
|
-
*/
|
|
87
|
-
blockquote?: (text: string) => string;
|
|
88
|
-
/**
|
|
89
|
-
* Custom renderer for horizontal rules
|
|
90
|
-
*/
|
|
91
|
-
hr?: () => string;
|
|
92
|
-
/**
|
|
93
|
-
* Custom renderer for emphasis (bold/italic)
|
|
94
|
-
*/
|
|
95
|
-
emphasis?: (text: string, type: 'bold' | 'italic') => string;
|
|
96
|
-
};
|
|
97
|
-
/**
|
|
98
|
-
* Maximum width for text wrapping
|
|
99
|
-
*/
|
|
100
|
-
maxWidth?: number;
|
|
101
|
-
/**
|
|
102
|
-
* Whether to enable ANSI color codes
|
|
103
|
-
*/
|
|
104
|
-
colors?: boolean;
|
|
105
|
-
/**
|
|
106
|
-
* Custom color theme
|
|
107
|
-
*/
|
|
108
|
-
theme?: {
|
|
109
|
-
/**
|
|
110
|
-
* Color for headings
|
|
111
|
-
*/
|
|
112
|
-
heading?: string;
|
|
113
|
-
/**
|
|
114
|
-
* Color for links
|
|
115
|
-
*/
|
|
116
|
-
link?: string;
|
|
117
|
-
/**
|
|
118
|
-
* Color for code
|
|
119
|
-
*/
|
|
120
|
-
code?: string;
|
|
121
|
-
/**
|
|
122
|
-
* Color for blockquotes
|
|
123
|
-
*/
|
|
124
|
-
blockquote?: string;
|
|
125
|
-
};
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
/**
|
|
129
|
-
* Converts markdown text to formatted CLI output
|
|
130
|
-
* @param markdown - The markdown text to convert
|
|
131
|
-
* @param options - Configuration options for the conversion
|
|
132
|
-
* @returns Formatted CLI text
|
|
133
|
-
*/
|
|
134
|
-
function cliMarkdown(markdown: string, options?: CliMarkdownOptions): string;
|
|
135
|
-
|
|
136
|
-
export = cliMarkdown;
|
|
137
|
-
}
|
|
@@ -1,120 +0,0 @@
|
|
|
1
|
-
import { setupLangWatch } from "langwatch/node";
|
|
2
|
-
import { getLangWatchTracer } from "langwatch";
|
|
3
|
-
import { semconv } from "langwatch/observability";
|
|
4
|
-
import * as readline from "readline";
|
|
5
|
-
import cliMarkdown from "cli-markdown";
|
|
6
|
-
import { mastra } from "./mastra/index.js";
|
|
7
|
-
|
|
8
|
-
await setupLangWatch();
|
|
9
|
-
|
|
10
|
-
const tracer = getLangWatchTracer("mastra-weather-agent-example");
|
|
11
|
-
|
|
12
|
-
async function main() {
|
|
13
|
-
const threadId = crypto.randomUUID();
|
|
14
|
-
|
|
15
|
-
const rl = readline.createInterface({
|
|
16
|
-
input: process.stdin,
|
|
17
|
-
output: process.stdout,
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
console.log('🌤️ Weather Agent Chatbot started! Type "quit" to exit.');
|
|
21
|
-
console.log("Ask me about weather for any location and I'll help you plan activities!");
|
|
22
|
-
console.log("---");
|
|
23
|
-
|
|
24
|
-
const conversationHistory: Array<{
|
|
25
|
-
role: "user" | "assistant" | "system";
|
|
26
|
-
content: string;
|
|
27
|
-
}> = [
|
|
28
|
-
{
|
|
29
|
-
role: "system",
|
|
30
|
-
content:
|
|
31
|
-
"You are a helpful weather assistant that provides accurate weather information and can help planning activities based on the weather. You may use markdown to format your responses.",
|
|
32
|
-
},
|
|
33
|
-
];
|
|
34
|
-
|
|
35
|
-
while (true) {
|
|
36
|
-
let finish = false;
|
|
37
|
-
|
|
38
|
-
await tracer.withActiveSpan("iteration", {
|
|
39
|
-
attributes: {
|
|
40
|
-
[semconv.ATTR_LANGWATCH_THREAD_ID]: threadId,
|
|
41
|
-
},
|
|
42
|
-
}, async (span) => {
|
|
43
|
-
try {
|
|
44
|
-
// Get user input
|
|
45
|
-
const userInput = await new Promise<string>((resolve) => {
|
|
46
|
-
rl.question("You: ", resolve);
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
// Check for exit command
|
|
50
|
-
if (
|
|
51
|
-
userInput.toLowerCase() === "quit" ||
|
|
52
|
-
userInput.toLowerCase() === "exit"
|
|
53
|
-
) {
|
|
54
|
-
console.log("👋 Goodbye!");
|
|
55
|
-
finish = true;
|
|
56
|
-
return;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
// Skip empty input
|
|
60
|
-
if (!userInput.trim()) {
|
|
61
|
-
return;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
// Add user message to conversation history
|
|
65
|
-
conversationHistory.push({ role: "user", content: userInput });
|
|
66
|
-
|
|
67
|
-
// Set input string for tracing
|
|
68
|
-
span.setInputString(userInput);
|
|
69
|
-
|
|
70
|
-
// Generate AI response using Mastra agent
|
|
71
|
-
console.log("🌤️ Checking weather and planning activities...");
|
|
72
|
-
|
|
73
|
-
const agent = mastra.getAgent("weatherAgent");
|
|
74
|
-
if (!agent) {
|
|
75
|
-
throw new Error("Weather agent not found");
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
const response = await agent.generate([
|
|
79
|
-
{
|
|
80
|
-
role: "user",
|
|
81
|
-
content: userInput,
|
|
82
|
-
},
|
|
83
|
-
]);
|
|
84
|
-
|
|
85
|
-
// Add AI response to conversation history
|
|
86
|
-
conversationHistory.push({ role: "assistant", content: response.text });
|
|
87
|
-
|
|
88
|
-
// Set output string for tracing
|
|
89
|
-
span.setOutputString(response.text);
|
|
90
|
-
|
|
91
|
-
// Display AI response with markdown formatting
|
|
92
|
-
console.log("\nAI:");
|
|
93
|
-
console.log(
|
|
94
|
-
`${cliMarkdown(response.text, {
|
|
95
|
-
colors: true,
|
|
96
|
-
maxWidth: 80,
|
|
97
|
-
theme: {
|
|
98
|
-
heading: "cyan",
|
|
99
|
-
link: "blue",
|
|
100
|
-
code: "green",
|
|
101
|
-
blockquote: "yellow",
|
|
102
|
-
},
|
|
103
|
-
})}---`,
|
|
104
|
-
);
|
|
105
|
-
} catch (error) {
|
|
106
|
-
console.error("❌ Error:", error);
|
|
107
|
-
console.log("Please try again.");
|
|
108
|
-
}
|
|
109
|
-
});
|
|
110
|
-
|
|
111
|
-
if (finish) {
|
|
112
|
-
break;
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
rl.close();
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
// Run the chatbot
|
|
120
|
-
main().catch(console.error);
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { openai } from '@ai-sdk/openai';
|
|
2
|
-
import { Agent } from '@mastra/core/agent';
|
|
3
|
-
import { Memory } from '@mastra/memory';
|
|
4
|
-
import { LibSQLStore } from '@mastra/libsql';
|
|
5
|
-
import { weatherTool } from '../tools/weather-tool.js';
|
|
6
|
-
|
|
7
|
-
export const weatherAgent = new Agent({
|
|
8
|
-
name: 'Weather Agent',
|
|
9
|
-
instructions: `
|
|
10
|
-
You are a helpful weather assistant that provides accurate weather information and can help planning activities based on the weather.
|
|
11
|
-
|
|
12
|
-
Your primary function is to help users get weather details for specific locations. When responding:
|
|
13
|
-
- Always ask for a location if none is provided
|
|
14
|
-
- If the location name isn't in English, please translate it
|
|
15
|
-
- If giving a location with multiple parts (e.g. "New York, NY"), use the most relevant part (e.g. "New York")
|
|
16
|
-
- Include relevant details like humidity, wind conditions, and precipitation
|
|
17
|
-
- Keep responses concise but informative
|
|
18
|
-
- If the user asks for activities and provides the weather forecast, suggest activities based on the weather forecast.
|
|
19
|
-
- If the user asks for activities, respond in the format they request.
|
|
20
|
-
|
|
21
|
-
Use the weatherTool to fetch current weather data.
|
|
22
|
-
`,
|
|
23
|
-
model: openai('gpt-4o-mini'),
|
|
24
|
-
tools: { weatherTool },
|
|
25
|
-
memory: new Memory({
|
|
26
|
-
storage: new LibSQLStore({
|
|
27
|
-
url: 'file:../mastra.db', // path is relative to the .mastra/output directory
|
|
28
|
-
}),
|
|
29
|
-
}),
|
|
30
|
-
});
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
import { Mastra } from '@mastra/core/mastra';
|
|
3
|
-
import { PinoLogger } from '@mastra/loggers';
|
|
4
|
-
import { LibSQLStore } from '@mastra/libsql';
|
|
5
|
-
import { weatherAgent } from './agents/weather-agent.js';
|
|
6
|
-
|
|
7
|
-
export const mastra = new Mastra({
|
|
8
|
-
agents: { weatherAgent },
|
|
9
|
-
storage: new LibSQLStore({
|
|
10
|
-
// stores telemetry, evals, ... into memory storage, if it needs to persist, change to file:../mastra.db
|
|
11
|
-
url: ":memory:",
|
|
12
|
-
}),
|
|
13
|
-
logger: new PinoLogger({
|
|
14
|
-
name: 'Mastra',
|
|
15
|
-
level: 'info',
|
|
16
|
-
}),
|
|
17
|
-
telemetry: {
|
|
18
|
-
enabled: true,
|
|
19
|
-
serviceName: "mastra-and-vercel-ai-sdk-example",
|
|
20
|
-
},
|
|
21
|
-
});
|
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
import { createTool } from '@mastra/core/tools';
|
|
2
|
-
import { z } from 'zod';
|
|
3
|
-
|
|
4
|
-
interface GeocodingResponse {
|
|
5
|
-
results: {
|
|
6
|
-
latitude: number;
|
|
7
|
-
longitude: number;
|
|
8
|
-
name: string;
|
|
9
|
-
}[];
|
|
10
|
-
}
|
|
11
|
-
interface WeatherResponse {
|
|
12
|
-
current: {
|
|
13
|
-
time: string;
|
|
14
|
-
temperature_2m: number;
|
|
15
|
-
apparent_temperature: number;
|
|
16
|
-
relative_humidity_2m: number;
|
|
17
|
-
wind_speed_10m: number;
|
|
18
|
-
wind_gusts_10m: number;
|
|
19
|
-
weather_code: number;
|
|
20
|
-
};
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export const weatherTool = createTool({
|
|
24
|
-
id: 'get-weather',
|
|
25
|
-
description: 'Get current weather for a location',
|
|
26
|
-
inputSchema: z.object({
|
|
27
|
-
location: z.string().describe('City name'),
|
|
28
|
-
}),
|
|
29
|
-
outputSchema: z.object({
|
|
30
|
-
temperature: z.number(),
|
|
31
|
-
feelsLike: z.number(),
|
|
32
|
-
humidity: z.number(),
|
|
33
|
-
windSpeed: z.number(),
|
|
34
|
-
windGust: z.number(),
|
|
35
|
-
conditions: z.string(),
|
|
36
|
-
location: z.string(),
|
|
37
|
-
}),
|
|
38
|
-
execute: async ({ context }: { context: { location: string } }) => {
|
|
39
|
-
return await getWeather(context.location);
|
|
40
|
-
},
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
const getWeather = async (location: string) => {
|
|
44
|
-
const geocodingUrl = `https://geocoding-api.open-meteo.com/v1/search?name=${encodeURIComponent(location)}&count=1`;
|
|
45
|
-
const geocodingResponse = await fetch(geocodingUrl);
|
|
46
|
-
const geocodingData = (await geocodingResponse.json()) as GeocodingResponse;
|
|
47
|
-
|
|
48
|
-
if (!geocodingData.results?.[0]) {
|
|
49
|
-
throw new Error(`Location '${location}' not found`);
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
const { latitude, longitude, name } = geocodingData.results[0];
|
|
53
|
-
|
|
54
|
-
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`;
|
|
55
|
-
|
|
56
|
-
const response = await fetch(weatherUrl);
|
|
57
|
-
const data = (await response.json()) as WeatherResponse;
|
|
58
|
-
|
|
59
|
-
return {
|
|
60
|
-
temperature: data.current.temperature_2m,
|
|
61
|
-
feelsLike: data.current.apparent_temperature,
|
|
62
|
-
humidity: data.current.relative_humidity_2m,
|
|
63
|
-
windSpeed: data.current.wind_speed_10m,
|
|
64
|
-
windGust: data.current.wind_gusts_10m,
|
|
65
|
-
conditions: getWeatherCondition(data.current.weather_code),
|
|
66
|
-
location: name,
|
|
67
|
-
};
|
|
68
|
-
};
|
|
69
|
-
|
|
70
|
-
function getWeatherCondition(code: number): string {
|
|
71
|
-
const conditions: Record<number, string> = {
|
|
72
|
-
0: 'Clear sky',
|
|
73
|
-
1: 'Mainly clear',
|
|
74
|
-
2: 'Partly cloudy',
|
|
75
|
-
3: 'Overcast',
|
|
76
|
-
45: 'Foggy',
|
|
77
|
-
48: 'Depositing rime fog',
|
|
78
|
-
51: 'Light drizzle',
|
|
79
|
-
53: 'Moderate drizzle',
|
|
80
|
-
55: 'Dense drizzle',
|
|
81
|
-
56: 'Light freezing drizzle',
|
|
82
|
-
57: 'Dense freezing drizzle',
|
|
83
|
-
61: 'Slight rain',
|
|
84
|
-
63: 'Moderate rain',
|
|
85
|
-
65: 'Heavy rain',
|
|
86
|
-
66: 'Light freezing rain',
|
|
87
|
-
67: 'Heavy freezing rain',
|
|
88
|
-
71: 'Slight snow fall',
|
|
89
|
-
73: 'Moderate snow fall',
|
|
90
|
-
75: 'Heavy snow fall',
|
|
91
|
-
77: 'Snow grains',
|
|
92
|
-
80: 'Slight rain showers',
|
|
93
|
-
81: 'Moderate rain showers',
|
|
94
|
-
82: 'Violent rain showers',
|
|
95
|
-
85: 'Slight snow showers',
|
|
96
|
-
86: 'Heavy snow showers',
|
|
97
|
-
95: 'Thunderstorm',
|
|
98
|
-
96: 'Thunderstorm with slight hail',
|
|
99
|
-
99: 'Thunderstorm with heavy hail',
|
|
100
|
-
};
|
|
101
|
-
return conditions[code] || 'Unknown';
|
|
102
|
-
}
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"target": "ES2022",
|
|
4
|
-
"module": "ES2022",
|
|
5
|
-
"moduleResolution": "Bundler",
|
|
6
|
-
"outDir": "./dist",
|
|
7
|
-
"rootDir": "./src",
|
|
8
|
-
"strict": true,
|
|
9
|
-
"esModuleInterop": true,
|
|
10
|
-
"skipLibCheck": true,
|
|
11
|
-
"forceConsistentCasingInFileNames": true,
|
|
12
|
-
"allowSyntheticDefaultImports": true,
|
|
13
|
-
"resolveJsonModule": true,
|
|
14
|
-
"declaration": true,
|
|
15
|
-
"declarationMap": true,
|
|
16
|
-
"sourceMap": true
|
|
17
|
-
},
|
|
18
|
-
"include": [
|
|
19
|
-
"src/**/*"
|
|
20
|
-
],
|
|
21
|
-
"exclude": [
|
|
22
|
-
"node_modules",
|
|
23
|
-
"dist"
|
|
24
|
-
]
|
|
25
|
-
}
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
# Vercel AI Examples
|
|
2
|
-
|
|
3
|
-
This directory contains examples of AI apps built with the LangWatch SDK and Vercel AI.
|
|
4
|
-
|
|
5
|
-
## Example
|
|
6
|
-
|
|
7
|
-
### Basic Chatbot (`src/index.ts`)
|
|
8
|
-
|
|
9
|
-
A simple chatbot that handles basic conversation flow:
|
|
10
|
-
|
|
11
|
-
- **Features:**
|
|
12
|
-
- Basic conversation loop
|
|
13
|
-
- User input handling
|
|
14
|
-
- AI response generation
|
|
15
|
-
- Conversation history management
|
|
16
|
-
- Error handling
|
|
17
|
-
- Exit commands (`quit`, `exit`)
|
|
18
|
-
|
|
19
|
-
- **Usage:**
|
|
20
|
-
```bash
|
|
21
|
-
npm run start
|
|
22
|
-
```
|
|
23
|
-
|
|
24
|
-
## Troubleshooting
|
|
25
|
-
|
|
26
|
-
### Common Issues:
|
|
27
|
-
|
|
28
|
-
1. **"Cannot find module 'langwatch/node'"**
|
|
29
|
-
- Make sure you've built the LangWatch SDK
|
|
30
|
-
- Check that the package is properly built
|
|
31
|
-
|
|
32
|
-
2. **OpenAI API errors**
|
|
33
|
-
- Verify your API key is set correctly
|
|
34
|
-
- Check your OpenAI account has sufficient credits
|
|
35
|
-
|
|
36
|
-
3. **TypeScript compilation errors**
|
|
37
|
-
- Run `npm run start` to check for type errors
|
|
38
|
-
- Ensure all dependencies are installed
|