連携
Mastra
Thunderbit を Mastra のエージェント・ワークフロー用の Tool としてラップ
Mastra は AI エージェントとワークフロー向けの TypeScript フレームワークです。createTool プリミティブが /distill にきれいにマッピングされます。
インストール
npm install @mastra/core zodTool を定義
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 を参照。