Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5,306 changes: 3,440 additions & 1,866 deletions package-lock.json

Large diffs are not rendered by default.

35 changes: 22 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,27 +46,26 @@
"@ai-sdk/google-vertex": "^4.0.11",
"@ai-sdk/openai": "^3.0.7",
"@ai-sdk/openai-compatible": "^2.0.4",
"@ai-sdk/react": "^3.0.25",
"@ai-sdk/react": "^3.0.29",
"@dotenvx/dotenvx": "^1.51.4",
"@e2b/code-interpreter": "^2.3.3",
"@emotion/react": "^11.14.0",
"@gsap/react": "^2.1.2",
"@mastra/ai-sdk": "^1.0.0-beta.13",
"@mastra/ai-sdk": "^1.0.0-beta.14",
"@mastra/auth-supabase": "^1.0.0-beta.1",
"@mastra/client-js": "^1.0.0-beta.21",
"@mastra/cloudflare-d1": "^1.0.0-beta.9",
"@mastra/core": "^1.0.0-beta.21",
"@mastra/deployer": "^1.0.0-beta.20",
"@mastra/deployer": "^1.0.0-beta.21",
"@mastra/evals": "^1.0.0-beta.4",
"@mastra/lance": "^1.0.0-beta.10",
"@mastra/libsql": "^1.0.0-beta.11",
"@mastra/loggers": "^1.0.0-beta.4",
"@mastra/mcp": "^1.0.0-beta.9",
"@mastra/memory": "^1.0.0-beta.12",
"@mastra/mongodb": "^1.0.0-beta.10",
"@mastra/mongodb": "^1.0.0-beta.11",
"@mastra/observability": "^1.0.0-beta.10",
"@mastra/otel-bridge": "^1.0.0-beta.10",
"@mastra/otel-exporter": "^1.0.0-beta.11",
"@mastra/otel-bridge": "^1.0.0-beta.11",
"@mastra/pg": "^1.0.0-beta.12",
"@mastra/qdrant": "^1.0.0-beta.3",
"@mastra/rag": "^2.0.0-beta.6",
Expand All @@ -84,7 +83,7 @@
"@openrouter/ai-sdk-provider": "^1.5.4",
"@opentelemetry/api": "^1.9.0",
"@opentelemetry/auto-instrumentations-node": "^0.67.3",
"@opentelemetry/exporter-trace-otlp-proto": "^0.208.0",
"@opentelemetry/exporter-trace-otlp-proto": "^0.209.0",
"@opeoginni/github-copilot-openai-compatible": "^1.0.0",
"@radix-ui/react-accordion": "^1.2.12",
"@radix-ui/react-collapsible": "^1.1.12",
Expand All @@ -108,10 +107,12 @@
"@vercel/otel": "^2.1.0",
"@xyflow/react": "^12.10.0",
"a2a-ai-provider": "^0.4.0-alpha.2",
"ai": "^5.0.118",
"ai-sdk-ollama": "^3.0.1",
"ai": "^5.0.119",
"ai-sdk-ollama": "^3.1.0",
"ai-sdk-provider-claude-code": "^3.1.0",
"ai-sdk-provider-gemini-cli": "^2.0.1",
"axios-retry": "^4.5.0",
"bottleneck": "^2.19.5",
"chalk": "^5.6.2",
"chart.js": "^4.5.1",
"cheerio": "^1.1.2",
Expand All @@ -124,6 +125,7 @@
"crawlee": "^3.15.3",
"critters": "^0.0.25",
"csv-parse": "^6.1.0",
"cytoscape": "^3.33.1",
"d3": "^7.9.0",
"diff": "^8.0.2",
"dotenv": "^17.2.3",
Expand All @@ -134,12 +136,14 @@
"framer-motion": "^12.25.0",
"gray-matter": "^4.0.3",
"gsap": "^3.14.2",
"html-to-image": "^1.11.13",
"husky": "^9.1.7",
"input-otp": "^1.4.2",
"isolated-vm": "^6.0.2",
"jose": "^6.1.3",
"jsdom": "^27.4.0",
"langfuse-vercel": "^3.38.6",
"leaflet": "^1.9.4",
"lenis": "^1.3.17",
"lucide-react": "^0.562.0",
"marked": "^17.0.1",
Expand All @@ -152,7 +156,8 @@
"next": "^16.1.1",
"next-themes": "^0.4.6",
"octokit": "^5.0.5",
"pino": "^10.1.0",
"openapi-typescript-codegen": "^0.30.0",
"pino": "^10.1.1",
"pino-pretty": "^13.1.3",
"playwright": "^1.57.0",
"postcss": "^8.5.6",
Expand All @@ -172,13 +177,17 @@
"remark-parse": "^11.0.0",
"remark-rehype": "^11.1.2",
"serpapi": "^2.2.1",
"sharp": "^0.34.5",
"shiki": "^3.21.0",
"simple-statistics": "^7.8.8",
"sonner": "^2.0.7",
"streamdown": "^1.6.11",
"strip-comments": "^2.0.1",
"svgjson": "^2.2.3",
"tailwind-merge": "^3.4.0",
"tailwindcss-animate": "^1.0.7",
"technicalindicators": "^3.1.0",
"tesseract.js": "^7.0.0",
"tokenlens": "^1.3.1",
"ts-morph": "^27.0.2",
"tslab": "^1.0.22",
Expand All @@ -201,7 +210,7 @@
"@types/fs-extra": "^11.0.4",
"@types/jsdom": "^27.0.0",
"@types/mdx": "^2.0.13",
"@types/node": "^24.10.4",
"@types/node": "^24.10.6",
"@types/react": "^19.2.7",
"@types/react-dom": "^19.2.3",
"@types/strip-comments": "^2.0.4",
Expand All @@ -214,7 +223,7 @@
"eslint-plugin-react-hooks": "^7.0.1",
"eslint-plugin-react-refresh": "^0.4.26",
"ink-testing-library": "^4.0.0",
"mastra": "^1.0.0-beta.13",
"mastra": "^1.0.0-beta.14",
"prettier": "^3.7.4",
"tailwindcss": "^4.1.18",
"tw-animate-css": "^1.4.0",
Expand All @@ -225,7 +234,7 @@
},
"overrides": {
"jsondiffpatch": "0.7.3",
"ai": "^5.0.118",
"ai": "^5.0.119",
"morgan": "^1.10.1",
"js-yaml": "^4.1.1",
"multer": "^2.0.2",
Expand Down
83 changes: 50 additions & 33 deletions src/mastra/tools/extractLearningsTool.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { MastraModelOutput } from '@mastra/core/stream'
import type { InferUITool } from '@mastra/core/tools'
import { createTool } from '@mastra/core/tools'
import { SpanStatusCode, trace } from '@opentelemetry/api'
import { SpanType } from '@mastra/core/observability'
import { z } from 'zod'
import { log } from '../config/logger'
import type { RequestContext } from '@mastra/core/request-context'
Expand All @@ -28,6 +28,7 @@ export const extractLearningsTool = createTool({
execute: async (inputData, context) => {
const mastra = context?.mastra
const writer = context?.writer
const tracingContext = context?.tracingContext
const requestContext = context?.requestContext as ExtractLearningsContext | undefined

// Emit progress start event
Expand All @@ -40,14 +41,21 @@ export const extractLearningsTool = createTool({
},
id: 'extract-learnings',
})
const tracer = trace.getTracer('extract-learnings')
const extractSpan = tracer.startSpan('extract_learnings', {
attributes: {

const extractSpan = tracingContext?.currentSpan?.createChildSpan({
type: SpanType.TOOL_CALL,
name: 'extract-learnings',
input: {
query: inputData?.query,
url: inputData?.result?.url,
contentLength: inputData?.result?.content?.length,
operation: 'extract_learnings',
'tool.requestContext.userId': requestContext?.userId,
},
metadata: {
'tool.id': 'extract-learnings',
'tool.input.query': inputData?.query,
'tool.input.url': inputData?.result?.url,
'tool.input.contentLength': inputData?.result?.content?.length,
'user.id': requestContext?.userId,
},
})

Expand Down Expand Up @@ -86,9 +94,14 @@ export const extractLearningsTool = createTool({
},
id: 'extract-learnings',
})
extractSpan.setAttribute('output.learningLength', 0)
extractSpan.setAttribute('output.followUpQuestionsCount', 0)
extractSpan.end()
extractSpan?.update({
output: { learning: 'Mastra instance not provided', followUpQuestions: [] },
metadata: {
'output.learningLength': 0,
'output.followUpQuestionsCount': 0,
},
})
extractSpan?.end()
return {
learning: 'Mastra instance not provided',
followUpQuestions: [],
Expand All @@ -106,9 +119,14 @@ export const extractLearningsTool = createTool({
},
id: 'extract-learnings',
})
extractSpan.setAttribute('output.learningLength', 0)
extractSpan.setAttribute('output.followUpQuestionsCount', 0)
extractSpan.end()
extractSpan?.update({
output: { learning: 'learningExtractionAgent not available', followUpQuestions: [] },
metadata: {
'output.learningLength': 0,
'output.followUpQuestionsCount': 0,
},
})
extractSpan?.end()
return {
learning: 'learningExtractionAgent not available',
followUpQuestions: [],
Expand Down Expand Up @@ -175,9 +193,14 @@ export const extractLearningsTool = createTool({
{ response: responseObject }
)

extractSpan.setAttribute('output.learningLength', 0)
extractSpan.setAttribute('output.followUpQuestionsCount', 0)
extractSpan.end()
extractSpan?.update({
output: { learning: 'Invalid response format from learning extraction agent', followUpQuestions: [] },
metadata: {
'output.learningLength': 0,
'output.followUpQuestionsCount': 0,
},
})
extractSpan?.end()

await writer?.custom({
type: 'data-tool-progress',
Expand All @@ -200,12 +223,14 @@ export const extractLearningsTool = createTool({
const followUpQuestionsCount =
parsed.data.followUpQuestions?.length ?? 0

extractSpan.setAttribute('output.learningLength', learningLength)
extractSpan.setAttribute(
'output.followUpQuestionsCount',
followUpQuestionsCount
)
extractSpan.end()
extractSpan?.update({
output: parsed.data,
metadata: {
'output.learningLength': learningLength,
'output.followUpQuestionsCount': followUpQuestionsCount,
},
})
extractSpan?.end()

await writer?.custom({
type: 'data-tool-progress',
Expand All @@ -226,18 +251,10 @@ export const extractLearningsTool = createTool({
const errorMessage =
error instanceof Error ? error.message : String(error)

try {
extractSpan.recordException(new Error(errorMessage))
extractSpan.setStatus({
code: SpanStatusCode.ERROR,
message: errorMessage,
})
} catch {
// ignore
}

extractSpan.setAttribute('metadata.error', errorMessage)
extractSpan.end()
extractSpan?.error({
error: error instanceof Error ? error : new Error(errorMessage),
endSpan: true,
})

await writer?.custom({
type: 'data-tool-progress',
Expand Down
Loading
Loading