diff --git a/apps/kitchensink-react/src/AppRoutes.tsx b/apps/kitchensink-react/src/AppRoutes.tsx index 2c98a823a..85e265b25 100644 --- a/apps/kitchensink-react/src/AppRoutes.tsx +++ b/apps/kitchensink-react/src/AppRoutes.tsx @@ -1,3 +1,4 @@ +import {ResourceProvider} from '@sanity/sdk-react' import {type JSX} from 'react' import {Route, Routes} from 'react-router' @@ -14,6 +15,7 @@ import {SearchRoute} from './DocumentCollection/SearchRoute' import {PresenceRoute} from './Presence/PresenceRoute' import {ProjectAuthHome} from './ProjectAuthentication/ProjectAuthHome' import {ProtectedRoute} from './ProtectedRoute' +import {AgentActionsRoute} from './routes/AgentActionsRoute' import {DashboardContextRoute} from './routes/DashboardContextRoute' import {DashboardWorkspacesRoute} from './routes/DashboardWorkspacesRoute' import ExperimentalResourceClientRoute from './routes/ExperimentalResourceClientRoute' @@ -121,6 +123,14 @@ export function AppRoutes(): JSX.Element { {documentCollectionRoutes.map((route) => ( ))} + + + + } + /> } /> } /> } /> diff --git a/apps/kitchensink-react/src/routes/AgentActionsRoute.tsx b/apps/kitchensink-react/src/routes/AgentActionsRoute.tsx new file mode 100644 index 000000000..495d8b10e --- /dev/null +++ b/apps/kitchensink-react/src/routes/AgentActionsRoute.tsx @@ -0,0 +1,136 @@ +import { + type AgentGenerateOptions, + type AgentPromptOptions, + useAgentGenerate, + useAgentPrompt, +} from '@sanity/sdk-react' +import {Box, Button, Card, Code, Label, Stack, Text} from '@sanity/ui' +import {type JSX, useMemo, useState} from 'react' + +import {PageLayout} from '../components/PageLayout' + +export function AgentActionsRoute(): JSX.Element { + const generate = useAgentGenerate() + const prompt = useAgentPrompt() + const [text, setText] = useState('Write a short poem about typescript and cats') + const [promptResult, setPromptResult] = useState('') + const [generateResult, setGenerateResult] = useState('') + const [isLoadingPrompt, setIsLoadingPrompt] = useState(false) + const [isLoadingGenerate, setIsLoadingGenerate] = useState(false) + const generateOptions = useMemo(() => { + return { + // Use the schema collection id (workspace name), not the type name + schemaId: '_.schemas.default', + targetDocument: { + operation: 'create', + _id: crypto.randomUUID(), + _type: 'movie', + }, + instruction: + 'Generate a title and overview for a movie about $topic based on a famous movie. Try to not pick the same movie as someone else would pick.', + instructionParams: {topic: 'Sanity SDK'}, + target: {include: ['title', 'overview']}, + noWrite: true, + } + }, []) + + const promptOptions = useMemo( + () => ({instruction: text, format: 'string'}), + [text], + ) + + return ( + + + + + + + Sends an instruction to the LLM and returns plain text (or JSON if requested). Does + not reference a schema or write any data. + +