-
Notifications
You must be signed in to change notification settings - Fork 1.7k
feat: mastra no storage #2650
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
feat: mastra no storage #2650
Changes from all commits
Commits
Show all changes
59 commits
Select commit
Hold shift + click to select a range
d8cde13
Onlool x Mastra
abhiaiyer91 1316f73
Remove .mastra folder
abhiaiyer91 836109c
more mastra
abhiaiyer91 204dbc3
add
Kitenite 47ac4d5
merge main
Kitenite e18f8ea
clean up
Kitenite 9ac9456
update types
Kitenite db2149e
update types
Kitenite e807a90
working ui
Kitenite c5eb8e5
more type check
Kitenite 4056b3a
more type check
Kitenite fd6426b
more updates
Kitenite dd2e1d5
more updates
Kitenite 7984818
merge main
Kitenite bce6c23
merge main
Kitenite 26edb34
update mastra
Kitenite 8145c9c
add oid
Kitenite 802ea8e
Merge branch 'main' into mastra-in-onlook
Kitenite 7377786
saving progress
Kitenite 329c239
merge from main
Kitenite 137ab62
Merge branch 'main' into mastra-in-onlook
Kitenite f3e3cc6
clean up
Kitenite 99080e9
working write
Kitenite 2146e55
working memory
Kitenite d102224
merge main
Kitenite 5a4fe7d
merge main
Kitenite a5924cd
working everything besides storage
Kitenite 15a58f0
working storage
Kitenite dc14508
working resubmit
Kitenite ddd3418
clean up
Kitenite de70a98
infinite loop issue
Kitenite 08021e2
save progress
Kitenite 98ecef0
merge main
Kitenite d540def
saving before custom storage
Kitenite f8b7f1e
remove mastra storage
Kitenite 8163751
update saving
Kitenite ff2ff00
restore behavior without storage
Kitenite 2ae8a33
clean up
Kitenite 027dd82
clean up
Kitenite 6c5a1db
working history again
Kitenite 5f3f4c9
revert eslint
Kitenite c6efc0f
update
Kitenite 298b3fe
clean up usage record
Kitenite 8917c7c
clean up
Kitenite 4a6e279
add decrement handler
Kitenite e5a318d
handle error handler
Kitenite 6ce9d6d
update messages
Kitenite 038a1e6
update suggestions
Kitenite 36ff530
clean up
Kitenite 768d176
update test
Kitenite c8e1102
working commit snapshot
Kitenite 85b04d0
add token counter
Kitenite cbe95cd
add toolcall trimmer
Kitenite 38f7cbd
add toolcall trimmer
Kitenite 1151c4b
use claude on edit
Kitenite 8a4a7f1
update test
Kitenite 378599f
use sonnet for titles
Kitenite 80ddce9
update conversation title
Kitenite 41f8581
add backwards compatible params to messages
Kitenite File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,125 @@ | ||
| import { createClient as createTRPCClient } from '@/trpc/request-server'; | ||
| import { createClient as createSupabaseClient } from '@/utils/supabase/request-server'; | ||
| import { initModel } from '@onlook/ai'; | ||
| import { LLMProvider, OPENROUTER_MODELS, UsageType, type Usage } from '@onlook/models'; | ||
| import { generateObject, NoSuchToolError, type ToolCall, type ToolSet } from 'ai'; | ||
| import { type NextRequest } from 'next/server'; | ||
|
|
||
| export const checkMessageLimit = async (req: NextRequest): Promise<{ | ||
| exceeded: boolean; | ||
| usage: Usage; | ||
| }> => { | ||
| const { api } = await createTRPCClient(req); | ||
| const usage = await api.usage.get(); | ||
|
|
||
| const dailyUsage = usage.daily; | ||
| const dailyExceeded = dailyUsage.usageCount >= dailyUsage.limitCount; | ||
| if (dailyExceeded) { | ||
| return { | ||
| exceeded: true, | ||
| usage: dailyUsage, | ||
| }; | ||
| } | ||
|
|
||
| const monthlyUsage = usage.monthly; | ||
| const monthlyExceeded = monthlyUsage.usageCount >= monthlyUsage.limitCount; | ||
| if (monthlyExceeded) { | ||
| return { | ||
| exceeded: true, | ||
| usage: monthlyUsage, | ||
| }; | ||
| } | ||
|
|
||
| return { | ||
| exceeded: false, | ||
| usage: monthlyUsage, | ||
| }; | ||
| } | ||
|
|
||
| export const getSupabaseUser = async (request: NextRequest) => { | ||
| const supabase = await createSupabaseClient(request); | ||
| const { data: { user } } = await supabase.auth.getUser(); | ||
| return user; | ||
| } | ||
|
|
||
| export const repairToolCall = async ({ toolCall, tools, error }: { toolCall: ToolCall<string, any>, tools: ToolSet, error: Error }) => { | ||
| if (NoSuchToolError.isInstance(error)) { | ||
| throw new Error( | ||
| `Tool "${toolCall.toolName}" not found. Available tools: ${Object.keys(tools).join(', ')}`, | ||
| ); | ||
| } | ||
| const tool = tools[toolCall.toolName as keyof typeof tools]; | ||
|
|
||
| console.warn( | ||
| `Invalid parameter for tool ${toolCall.toolName} with args ${JSON.stringify(toolCall.args)}, attempting to fix`, | ||
| ); | ||
|
|
||
| const { model } = await initModel({ | ||
| provider: LLMProvider.OPENROUTER, | ||
| model: OPENROUTER_MODELS.CLAUDE_4_SONNET, | ||
| }); | ||
|
|
||
| const { object: repairedArgs } = await generateObject({ | ||
| model, | ||
| schema: tool?.parameters, | ||
| prompt: [ | ||
| `The model tried to call the tool "${toolCall.toolName}"` + | ||
| ` with the following arguments:`, | ||
| JSON.stringify(toolCall.args), | ||
| `The tool accepts the following schema:`, | ||
| JSON.stringify(tool?.parameters), | ||
| 'Please fix the arguments.', | ||
| ].join('\n'), | ||
| }); | ||
|
|
||
| return { | ||
| ...toolCall, | ||
| args: JSON.stringify(repairedArgs), | ||
| toolCallType: 'function' as const | ||
| }; | ||
| } | ||
|
|
||
| export const incrementUsage = async (req: NextRequest): Promise<{ | ||
| usageRecordId: string | undefined, | ||
| rateLimitId: string | undefined, | ||
| } | null> => { | ||
| try { | ||
| const user = await getSupabaseUser(req); | ||
| if (!user) { | ||
| throw new Error('User not found'); | ||
| } | ||
| const { api } = await createTRPCClient(req); | ||
| const incrementRes = await api.usage.increment({ | ||
| type: UsageType.MESSAGE, | ||
| }); | ||
| return { | ||
| usageRecordId: incrementRes?.usageRecordId, | ||
| rateLimitId: incrementRes?.rateLimitId, | ||
| }; | ||
| } catch (error) { | ||
| console.error('Error in chat usage increment', error); | ||
| } | ||
| return null; | ||
| } | ||
|
|
||
| export const decrementUsage = async ( | ||
| req: NextRequest, | ||
| usageRecord: { | ||
| usageRecordId: string | undefined, | ||
| rateLimitId: string | undefined, | ||
| } | null | ||
| ): Promise<void> => { | ||
| try { | ||
| if (!usageRecord) { | ||
| return; | ||
| } | ||
| const { usageRecordId, rateLimitId } = usageRecord; | ||
| if (!usageRecordId || !rateLimitId) { | ||
| return; | ||
| } | ||
| const { api } = await createTRPCClient(req); | ||
| await api.usage.revertIncrement({ usageRecordId, rateLimitId }); | ||
| } catch (error) { | ||
| console.error('Error in chat usage decrement', error); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.