통합

Mastra

Thunderbit를 Mastra 에이전트와 워크플로용 Tool로 래핑

Mastra 는 AI 에이전트와 워크플로를 위한 TypeScript 프레임워크입니다. 그 createTool 프리미티브가 /distill 위에 깔끔하게 매핑됩니다.

설치

npm install @mastra/core zod

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

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

워크플로에서 사용

다단계 파이프라인이라면 Mastra Step 에서 /batch/distill 을 호출하고 COMPLETED 까지 폴링하세요 —— Batch Job Lifecycle 참고.

관련 문서