ManimCat / src /studio-agent /tools /read-tool.ts
Bin29's picture
Sync from main: 68df783 feat: support multimodal studio reference images
d47b053
import type { StudioToolDefinition, StudioToolResult } from '../domain/types'
import type { StudioRuntimeBackedToolContext } from '../runtime/tool-runtime-context'
import { readWorkspaceFile, toWorkspaceRelativePath, truncateToolText } from './workspace-paths'
interface ReadToolInput {
path?: string
file?: string
}
export function createStudioReadTool(): StudioToolDefinition<ReadToolInput> {
return {
name: 'read',
description: 'Read a file from the current workspace.',
category: 'safe-read',
permission: 'read',
allowedAgents: ['builder', 'reviewer', 'designer'],
requiresTask: false,
execute: async (input, context) => executeReadTool(input, context as StudioRuntimeBackedToolContext)
}
}
async function executeReadTool(
input: ReadToolInput,
context: StudioRuntimeBackedToolContext
): Promise<StudioToolResult> {
const target = input.path ?? input.file
if (!target) {
throw new Error('Read tool requires "path" or "file"')
}
const file = await readWorkspaceFile(context.session.directory, target)
const relativePath = toWorkspaceRelativePath(context.session.directory, file.absolutePath).replace(/\\/g, '/')
const output = truncateToolText(file.content)
return {
title: `Read ${relativePath}`,
output: output.text,
metadata: {
path: relativePath,
absolutePath: file.absolutePath,
truncated: output.truncated
}
}
}