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.

Experimental feature

This feature is experimental and the API will change in future releases.

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.

const response = await fetch(`${apiBaseUrl}/toolkit/tools`, {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
    Authorization: `Bearer ${jwtToken}`,
    'X-App-Id': appId,
  },
  body: JSON.stringify({
    schemaAwarenessData,
    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

When executing comment tools, include the experimental__commentsOptions object in the request body. This object contains the configuration for connecting to the Tiptap Collaboration server and updating the collaborative document with the new comments.

  • documentId (string): The ID of the document to create comments in.
  • apiSecret (string): The API secret for the Server AI Toolkit.
  • userId (string): The ID of the user creating comments.
  • appId (string, optional): The App ID for the Server AI Toolkit.
  • baseUrl (string, optional): The base URL for the Server AI Toolkit.
  • threadData (Record<string, any>, optional): Extra metadata of the AI-generated threads that are created with the editThreads tool. This metadata is attached to threads when they are created.
  • commentData (Record<string, any>, optional): Extra metadata of the AI-generated comments that are created with the editThreads tool. This metadata is attached to comments when they are created.

Either appId or baseUrl must be provided. If you are using Tiptap Cloud, use the appId property to connect to your deployment. If you deploy on your own infrastructure, use the baseUrl property to connect to the Tiptap Collaboration service.

const result = await fetch(`${apiBaseUrl}/toolkit/execute-tool`, {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
    Authorization: `Bearer ${jwtToken}`,
    'X-App-Id': appId,
  },
  body: JSON.stringify({
    toolName: 'editThreads',
    input: {},
    document,
    schemaAwarenessData,
    // Required for comment tools
    experimental__commentsOptions: {
      documentId: '123',
      apiSecret: 'your-api-secret',
      userId: 'ai-assistant',
      appId: 'your-app-id',
    },
  }),
})

End result

The result is a simple but polished AI chatbot application:

See the source code on GitHub.

Next steps