UNPKG

generator-begcode

Version:

Spring Boot + Angular/React/Vue in one handy generator

35 lines (34 loc) 1.25 kB
import { AgentOutputType, trimText, ChatMessageBuilder } from '../agent-core/index.js'; import { AgentFunctionBase } from './utils/index.js'; export class ReadDirectoryFunction extends AgentFunctionBase { name = 'fs_readDirectory'; description = 'Reads the contents of the directory'; parameters = { type: 'object', properties: { path: { type: 'string', }, }, required: ['path'], additionalProperties: false, }; buildExecutor(agent) { return async (params, rawParams) => { const data = await agent.context.workspace.readdir(params.path); return this.onSuccess(agent, params, rawParams, data.join('\n')); }; } onSuccess(agent, params, rawParams, result) { return { outputs: [ { type: AgentOutputType.Success, title: `[${agent.config.prompts.name}] ${this.name}`, content: `${params.path}\n${trimText(result, 200)}`, }, ], messages: [ChatMessageBuilder.functionCall(this.name, rawParams), ChatMessageBuilder.functionCallResult(this.name, result)], }; } }