Server comments

Give your AI agents the ability to read, write and edit comments in your document, fully server-side.

See the source code on GitHub.

Continuation from the AI agent chatbot guide

This guide continues the AI agent chatbot guide. Read it first.

Enable comment tools

To enable comment tools, pass the getThreads and editThreads options when fetching tool definitions from the Server AI Toolkit API.

import { getAuthHeaders } from '@/lib/server-ai-toolkit/get-auth-headers'

const response = await fetch(`${apiBaseUrl}/v4/ai/toolkit/fetch-tools`, {
  method: 'POST',
  headers: await getAuthHeaders(),
  body: JSON.stringify({
    editorContext,
    tools: {
      // Disable tiptap edit tool so that the AI can not edit the document,
      // only add comments
      tiptapEdit: false,
      // Enable comment tools
      getThreads: true,
      editThreads: true,
    },
  }),
})

Execute comment tools

Comment tools require a Tiptap Cloud document because threads and comments are stored on the Tiptap Document Server. Pass document: { type: 'cloud', id } so the AI Server can fetch it from the Document Server automatically.

Request body

Include the cloud document reference in the request body:

  • document.id (string, required): The ID of the document.
  • user (string, optional): The ID of the user creating comments. If omitted, comments are created without user attribution.
const result = await fetch(`${apiBaseUrl}/v4/ai/toolkit/execute-tool`, {
  method: 'POST',
  headers: await getAuthHeaders('your-document-id'),
  body: JSON.stringify({
    editorContext,
    // Reference the Tiptap Cloud document
    document: {
      type: 'cloud',
      id: 'your-document-id',
    },
    user: 'ai-assistant',
    tool: {
      name: 'editThreads',
      input: {},
    },
  }),
})

End result

The result is a simple but polished AI chatbot application:

See the source code on GitHub.

Next steps