Integrationen

Mastra

Verpacke Thunderbit als Mastra-Tool für Agents und Workflows

Mastra ist ein TypeScript-Framework für KI-Agents und Workflows. Sein createTool-Primitive passt sauber auf /distill.

Installation

npm install @mastra/core zod

Tool definieren

import { createTool } from '@mastra/core/tools';
import { z } from 'zod';

const API = 'https://openapi.thunderbit.com/openapi/v1';
const H = { Authorization: `Bearer ${process.env.THUNDERBIT_API_KEY}` };

export const readUrlTool = createTool({
  id: 'read-url',
  description:
    'Fetch a URL and return clean Markdown for the agent to read.',
  inputSchema: z.object({
    url: z.string().url(),
    renderMode: z.enum(['basic', 'advanced']).default('basic'),
  }),
  outputSchema: z.object({ markdown: z.string() }),
  execute: async ({ context }) => {
    const res = await fetch(`${API}/distill`, {
      method: 'POST',
      headers: { ...H, 'Content-Type': 'application/json' },
      body: JSON.stringify(context),
    });
    const json = await res.json();
    return { markdown: json.data.markdown };
  },
});

In einen Agent einbinden

import { Agent } from '@mastra/core/agent';
import { openai } from '@ai-sdk/openai';

export const researcher = new Agent({
  name: 'researcher',
  instructions: 'Use read-url to fetch any URL the user asks about.',
  model: openai('gpt-4o'),
  tools: { readUrlTool },
});

In einem Workflow

Für mehrstufige Pipelines rufst du /batch/distill aus einem Mastra-Step auf und pollst, bis COMPLETED — siehe Batch Job Lifecycle.

Verwandt