Intégrations

Mastra

Encapsule Thunderbit comme Tool Mastra pour les agents et workflows

Mastra est un framework TypeScript pour les agents IA et les workflows. Sa primitive createTool se mappe proprement sur /distill.

Installation

npm install @mastra/core zod

Définir le Tool

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 };
  },
});

Branche dans un Agent

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 },
});

Utiliser dans un Workflow

Pour les pipelines multi-étapes, appelle /batch/distill depuis un Step Mastra et poll jusqu'à COMPLETED — voir Batch Job Lifecycle.

Liens connexes