Sanity App SDK
    Preparing search index...
    • Alpha

      Transforms an existing document or selected fields using Sanity Agent Actions.

      Parameters

      Returns (options: TransformDocument) => Subscribable<unknown>

      A stable callback that triggers the action and yields a Subscribable stream.

      This hook provides a stable callback to apply AI-powered transformations to document content.

      Features:

      • Accepts instruction and instructionParams (constants, fields, documents, GROQ queries).
      • Can write to the same or a different targetDocument (create/edit), and target specific paths.
      • Supports per-path image transform instructions and image description operations.
      • Optional temperature, async, noWrite, conditionalPaths.
      import {useAgentTransform} from '@sanity/sdk-react'

      function SummarizeArticle({documentId}: {documentId: string}) {
      const transform = useAgentTransform()

      const handleSummarize = () => {
      transform({
      documentId,
      instruction: 'Summarize the following content into 2-3 sentences: $body',
      instructionParams: {
      body: {type: 'field', path: 'body'},
      },
      targetPaths: ['summary'],
      }).subscribe({
      complete: () => console.log('Summary generated'),
      error: (err) => console.error('Transform failed:', err),
      })
      }

      return <button onClick={handleSummarize}>Generate Summary</button>
      }
      import {useAgentTransform} from '@sanity/sdk-react'

      function CreateVariant({sourceDocumentId}: {sourceDocumentId: string}) {
      const transform = useAgentTransform()

      const handleCreateVariant = () => {
      transform({
      documentId: sourceDocumentId,
      instruction: 'Rewrite this product description for a younger audience: $description',
      instructionParams: {
      description: {type: 'field', path: 'description'},
      },
      targetDocument: {
      operation: 'create',
      _type: 'product',
      },
      targetPaths: ['description'],
      }).subscribe({
      next: (result) => console.log('New document:', result),
      complete: () => console.log('Variant created'),
      })
      }

      return <button onClick={handleCreateVariant}>Create Youth Variant</button>
      }