-
Notifications
You must be signed in to change notification settings - Fork 0
feat: Create-Page Tool & Improved System Prompt #74
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
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
9f24b76
feat: enhance AI agent with create-page tool and improved editor inte…
rmolinamir 9cd8a58
Merge branch 'main' into feat/ai-agent-create-page-tool
rmolinamir a204da7
refactor: update create-page tool imports and organization
rmolinamir 388799b
refactor: journl user state
rmolinamir a4d4962
Update apps/web/src/ai/agents/journl-agent.ts
rmolinamir 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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| "use client"; | ||
|
|
||
| import type { Page } from "@acme/db/schema"; | ||
| import { useMutation, useQueryClient } from "@tanstack/react-query"; | ||
| import { useRouter } from "next/navigation"; | ||
| import { useTRPC } from "~/trpc/react"; | ||
| import { useAppEventEmitter } from "../../components/events/app-event-context"; | ||
| import { PageCreatedEvent } from "../../events/page-created-event"; | ||
| import { createClientTool } from "../utils/create-client-tool"; | ||
| import { zCreatePageInput } from "./create-page.schema"; | ||
|
|
||
| export function useCreatePageTool() { | ||
| const router = useRouter(); | ||
| const trpc = useTRPC(); | ||
| const queryClient = useQueryClient(); | ||
| const eventEmitter = useAppEventEmitter(); | ||
|
|
||
| const { mutate: createPage } = useMutation( | ||
| trpc.pages.create.mutationOptions({}), | ||
| ); | ||
|
|
||
| const tool = createClientTool({ | ||
| execute: async (toolCall, chat) => { | ||
| createPage( | ||
| { | ||
| children: [], | ||
| title: toolCall.input.title, | ||
| }, | ||
| { | ||
| onError: (error) => { | ||
| console.error("Failed to create page:", error); | ||
| void chat.addToolResult({ | ||
| output: `Failed to create page ${toolCall.input.title}`, | ||
| tool: toolCall.toolName, | ||
| toolCallId: toolCall.toolCallId, | ||
| }); | ||
| }, | ||
| onSuccess: (newPage) => { | ||
| queryClient.setQueryData( | ||
| trpc.pages.getByUser.queryOptions().queryKey, | ||
| (oldPages: Page[] | undefined) => { | ||
| if (!oldPages) return [newPage]; | ||
| return [newPage, ...oldPages]; | ||
| }, | ||
| ); | ||
|
|
||
| eventEmitter.buffer( | ||
| new PageCreatedEvent({ | ||
| chat, | ||
| id: newPage.id, | ||
| title: toolCall.input.title, | ||
| toolCallId: toolCall.toolCallId, | ||
| toolName: toolCall.toolName, | ||
| }), | ||
| ); | ||
|
|
||
| router.push(`/pages/${newPage.id}`); | ||
| }, | ||
| }, | ||
| ); | ||
| }, | ||
| inputSchema: zCreatePageInput, | ||
| name: "createPage", | ||
| }); | ||
| return tool; | ||
| } |
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,5 @@ | ||
| import { z } from "zod"; | ||
|
|
||
| export const zCreatePageInput = z.object({ | ||
| title: z.string().describe("The title of the page to create."), | ||
| }); |
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,10 @@ | ||
| import { createTool } from "@mastra/core/tools"; | ||
| import { z } from "zod"; | ||
| import { zCreatePageInput } from "./create-page.schema"; | ||
|
|
||
| export const createPage = createTool({ | ||
| description: "A client-side tool that creates a new page", | ||
| id: "create-page", | ||
| inputSchema: zCreatePageInput, | ||
| outputSchema: z.void(), | ||
| }); |
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
Oops, something went wrong.
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.