Skip to content

Commit f6ab7e1

Browse files
committed
feat: enhance tool imports and add UI types
- Updated imports in various tool files to include InferUITool for type inference. - Added UI type exports for multiple tools including: - AlphaVantageCryptoUITool - ArxivUITool - BrowserToolUITool - CsvToJsonUITool - DataValidatorJSONUITool - EditorAgentUITool - EvaluateResultUITool - ExecaUITool - ExtractLearningsUITool - FinancialChartTools - FinnhubTools - PgSqlTool - PnpmBuildUITool - PolygonStockQuotesUITool - WeatherUITool - WebScraperUITool - WriteNoteUITool
1 parent 4e5d98a commit f6ab7e1

29 files changed

Lines changed: 187 additions & 32 deletions

app/chat/providers/chat-context.tsx

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,10 @@ export function ChatProvider({
9999
const [pendingConfirmations, setPendingConfirmations] = useState<PendingConfirmation[]>([])
100100

101101
const {
102+
regenerate,
103+
stop,
102104
messages,
103105
sendMessage: aiSendMessage,
104-
stop,
105106
status: aiStatus,
106107
error: aiError,
107108
} = useChat({
@@ -111,9 +112,14 @@ export function ChatProvider({
111112
prepareSendMessagesRequest({ messages }) {
112113
return {
113114
id: selectedAgent,
114-
messages: messages,
115+
messages,
116+
memory: {
117+
thread: "user-1",
118+
resource: "user-1",
119+
},
115120
requestMetadata: {
116-
agentId: selectedAgent
121+
agentId: selectedAgent,
122+
resourceId: selectedAgent
117123
},
118124
body: {
119125
messages,

lib/utils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@ import { type ClassValue, clsx } from "clsx"
22
import { twMerge } from "tailwind-merge"
33

44
export function cn(...inputs: ClassValue[]) {
5-
return twMerge(clsx(inputs))
6-
}
5+
return twMerge(clsx(inputs))
6+
}

src/mastra/tools/alpha-vantage.tool.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { AISpanType, InternalSpans } from "@mastra/core/ai-tracing";
2-
import { createTool } from "@mastra/core/tools";
2+
import { InferUITool, createTool } from "@mastra/core/tools";
33
import { z } from "zod";
44

55
/**
@@ -548,3 +548,7 @@ export const alphaVantageTool = createTool({
548548
}
549549
}
550550
});
551+
552+
export type AlphaVantageCryptoUITool = InferUITool<typeof alphaVantageCryptoTool>;
553+
export type AlphaVantageStockUITool = InferUITool<typeof alphaVantageStockTool>;
554+
export type AlphaVantageUITool = InferUITool<typeof alphaVantageTool>;

src/mastra/tools/arxiv.tool.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { AISpanType, InternalSpans } from "@mastra/core/ai-tracing";
2-
import { createTool } from "@mastra/core/tools";
2+
import { InferUITool, createTool } from "@mastra/core/tools";
33
import { z } from "zod";
44

55
// In-memory counter to track tool calls per request
@@ -274,6 +274,8 @@ export const arxivTool = createTool({
274274
}
275275
});
276276

277+
export type ArxivUITool = InferUITool<typeof arxivTool>;
278+
277279
/**
278280
* ArXiv PDF Parser Tool
279281
*
@@ -442,6 +444,8 @@ export const arxivPdfParserTool = createTool({
442444
}
443445
});
444446

447+
export type ArxivPdfParserUITool = InferUITool<typeof arxivPdfParserTool>;
448+
445449
/**
446450
* ArXiv Paper Downloader Tool
447451
*
@@ -580,6 +584,8 @@ export const arxivPaperDownloaderTool = createTool({
580584
}
581585
});
582586

587+
export type ArxivPaperDownloaderUITool = InferUITool<typeof arxivPaperDownloaderTool>;
588+
583589
/**
584590
* Simple XML parser for ArXiv API response
585591
* In production, consider using a proper XML parsing library

src/mastra/tools/browser-tool.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
import { createTool } from '@mastra/core/tools';
1+
/*
2+
* Not working
3+
*/
4+
import { InferUITool, createTool } from "@mastra/core/tools";
25
import { AISpanType, InternalSpans } from '@mastra/core/ai-tracing';
36
import { MDocument } from '@mastra/rag';
47
import { chromium, Browser } from 'playwright-core';
@@ -508,3 +511,12 @@ export const monitorPageTool = createTool({
508511
}
509512
},
510513
});
514+
515+
export type BrowserToolUITool = InferUITool<typeof browserTool>;
516+
export type ScreenshotToolUITool = InferUITool<typeof screenshotTool>;
517+
export type PdfGeneratorToolUITool = InferUITool<typeof pdfGeneratorTool>;
518+
export type ClickAndExtractToolUITool = InferUITool<typeof clickAndExtractTool>;
519+
export type FillFormToolUITool = InferUITool<typeof fillFormTool>;
520+
export type GoogleSearchUITool = InferUITool<typeof googleSearch>;
521+
export type ExtractTablesToolUITool = InferUITool<typeof extractTablesTool>;
522+
export type MonitorPageToolUITool = InferUITool<typeof monitorPageTool>;

src/mastra/tools/calendar-tool.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { createTool } from '@mastra/core/tools';
1+
import { InferUITools, createTool } from "@mastra/core/tools";
22
import { AISpanType, InternalSpans } from '@mastra/core/ai-tracing';
33
import { execSync } from 'child_process';
44
import { z } from 'zod';

src/mastra/tools/copywriter-agent-tool.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { AISpanType, InternalSpans } from '@mastra/core/ai-tracing'
2-
import { createTool } from '@mastra/core/tools'
2+
import { InferUITool, createTool } from "@mastra/core/tools";
33
import { z } from 'zod'
44
import { log } from '../config/logger'
55

@@ -208,3 +208,7 @@ export const copywriterTool = createTool({
208208
}
209209
},
210210
})
211+
212+
// InferUITools expects a ToolSet (an object mapping ids to tools), not a single Tool.
213+
// Provide an object with the tool id as the key to satisfy the constraint.
214+
export type CopywriterUITool = InferUITool<typeof copywriterTool>;

src/mastra/tools/csv-to-json.tool.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { AISpanType, InternalSpans } from "@mastra/core/ai-tracing";
2-
import { createTool } from "@mastra/core/tools";
2+
import { InferUITool, createTool } from "@mastra/core/tools";
33
import { parse } from "csv-parse/sync";
44
import * as fs from "node:fs/promises";
55
import { z } from "zod";
@@ -82,3 +82,5 @@ export const csvToJsonTool = createTool({
8282
}
8383
},
8484
});
85+
86+
export type CsvToJsonUITool = InferUITool<typeof csvToJsonTool>;

src/mastra/tools/data-file-manager.ts

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
// approvalDate: 9/22
1515

1616
import { AISpanType, InternalSpans } from '@mastra/core/ai-tracing'
17-
import { createTool } from '@mastra/core/tools'
17+
import { InferUITool, createTool } from "@mastra/core/tools";
1818
import * as fs from 'fs/promises'
1919
import * as path from 'path'
2020
import { pipeline } from 'stream/promises'
@@ -91,6 +91,8 @@ export const readDataFileTool = createTool({
9191
},
9292
})
9393

94+
export type ReadDataFileUITool = InferUITool<typeof readDataFileTool>;
95+
9496
export const writeDataFileTool = createTool({
9597
id: 'write-data-file',
9698
description:
@@ -150,6 +152,8 @@ export const writeDataFileTool = createTool({
150152
},
151153
})
152154

155+
export type WriteDataFileUITool = InferUITool<typeof writeDataFileTool>;
156+
153157
export const deleteDataFileTool = createTool({
154158
id: 'delete-data-file',
155159
description: 'Deletes a file within the data directory.',
@@ -195,6 +199,8 @@ export const deleteDataFileTool = createTool({
195199
},
196200
})
197201

202+
export type DeleteDataFileUITool = InferUITool<typeof deleteDataFileTool>;
203+
198204
export const listDataDirTool = createTool({
199205
id: 'list-data-directory',
200206
description:
@@ -241,6 +247,9 @@ export const listDataDirTool = createTool({
241247
}
242248
},
243249
})
250+
251+
export type ListDataDirUITool = InferUITool<typeof listDataDirTool>;
252+
244253
export const copyDataFileTool = createTool({
245254
id: 'copy-data-file',
246255
description: 'Copies a file within the data directory to a new location.',
@@ -300,6 +309,8 @@ export const copyDataFileTool = createTool({
300309
},
301310
})
302311

312+
export type CopyDataFileUITool = InferUITool<typeof copyDataFileTool>;
313+
303314
export const moveDataFileTool = createTool({
304315
id: 'move-data-file',
305316
description: 'Moves or renames a file within the data directory.',
@@ -359,6 +370,8 @@ export const moveDataFileTool = createTool({
359370
},
360371
})
361372

373+
export type MoveDataFileUITool = InferUITool<typeof moveDataFileTool>;
374+
362375
export const searchDataFilesTool = createTool({
363376
id: 'search-data-files',
364377
description:
@@ -463,6 +476,8 @@ export const searchDataFilesTool = createTool({
463476
},
464477
})
465478

479+
export type SearchDataFilesUITool = InferUITool<typeof searchDataFilesTool>;
480+
466481
export const getDataFileInfoTool = createTool({
467482
id: 'get-data-file-info',
468483
description:
@@ -525,6 +540,7 @@ export const getDataFileInfoTool = createTool({
525540
},
526541
})
527542

543+
export type GetDataFileInfoUITool = InferUITool<typeof getDataFileInfoTool>;
528544
export const createDataDirTool = createTool({
529545
id: 'create-data-directory',
530546
description: 'Creates a new directory within the data directory.',
@@ -568,6 +584,8 @@ export const createDataDirTool = createTool({
568584
},
569585
})
570586

587+
export type CreateDataDirUITool = InferUITool<typeof createDataDirTool>;
588+
571589
export const removeDataDirTool = createTool({
572590
id: 'remove-data-directory',
573591
description: 'Removes an empty directory within the data directory.',
@@ -617,6 +635,8 @@ export const removeDataDirTool = createTool({
617635
},
618636
})
619637

638+
export type RemoveDataDirUITool = InferUITool<typeof removeDataDirTool>;
639+
620640
export const archiveDataTool = createTool({
621641
id: 'archive-data',
622642
description:
@@ -682,6 +702,8 @@ export const archiveDataTool = createTool({
682702
},
683703
})
684704

705+
export type ArchiveDataUITool = InferUITool<typeof archiveDataTool>;
706+
685707
export const backupDataTool = createTool({
686708
id: 'backup-data',
687709
description:
@@ -749,3 +771,5 @@ export const backupDataTool = createTool({
749771
}
750772
},
751773
})
774+
775+
export type BackupDataUITool = InferUITool<typeof backupDataTool>;

src/mastra/tools/data-processing-tools.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { AISpanType, InternalSpans } from '@mastra/core/ai-tracing'
2-
import { createTool } from '@mastra/core/tools'
2+
import { InferUITool, createTool } from "@mastra/core/tools";
33
import * as fs from 'fs/promises'
44
import * as path from 'path'
55
import { DOMParser } from 'xmldom'
@@ -1232,3 +1232,14 @@ function jsonToXML(data: JSONLike, rootElement = 'root'): string {
12321232

12331233
return objectToXML(data, rootElement)
12341234
}
1235+
1236+
1237+
export type ReadCSVDataToolUITool = InferUITool<typeof readCSVDataTool>;
1238+
export type ImageToCSVUITool = InferUITool<typeof imageToCSVTool>;
1239+
export type DataProcessingUITool = InferUITool<typeof convertDataFormatTool>;
1240+
export type ExcalidrawValidationUITool = InferUITool<typeof validateExcalidrawTool>;
1241+
export type SVGProcessingUITool = InferUITool<typeof processSVGTool>;
1242+
export type XMLProcessingUITool = InferUITool<typeof processXMLTool>;
1243+
export type DataValidationUITool = InferUITool<typeof validateDataTool>;
1244+
1245+

0 commit comments

Comments
 (0)