mirror of
https://gitea.toothfairyai.com/ToothFairyAI/tf_code.git
synced 2026-04-05 00:23:10 +00:00
feat: write truncated tool outputs to files (#7239)
This commit is contained in:
@@ -2,7 +2,7 @@ import z from "zod"
|
||||
import type { MessageV2 } from "../session/message-v2"
|
||||
import type { Agent } from "../agent/agent"
|
||||
import type { PermissionNext } from "../permission/next"
|
||||
import { Truncate } from "../session/truncation"
|
||||
import { Truncate } from "./truncation"
|
||||
|
||||
export namespace Tool {
|
||||
interface Metadata {
|
||||
@@ -50,8 +50,8 @@ export namespace Tool {
|
||||
): Info<Parameters, Result> {
|
||||
return {
|
||||
id,
|
||||
init: async (ctx) => {
|
||||
const toolInfo = init instanceof Function ? await init(ctx) : init
|
||||
init: async (initCtx) => {
|
||||
const toolInfo = init instanceof Function ? await init(initCtx) : init
|
||||
const execute = toolInfo.execute
|
||||
toolInfo.execute = async (args, ctx) => {
|
||||
try {
|
||||
@@ -66,13 +66,18 @@ export namespace Tool {
|
||||
)
|
||||
}
|
||||
const result = await execute(args, ctx)
|
||||
const truncated = Truncate.output(result.output)
|
||||
// skip truncation for tools that handle it themselves
|
||||
if (result.metadata.truncated !== undefined) {
|
||||
return result
|
||||
}
|
||||
const truncated = await Truncate.output(result.output, {}, initCtx?.agent)
|
||||
return {
|
||||
...result,
|
||||
output: truncated.content,
|
||||
metadata: {
|
||||
...result.metadata,
|
||||
truncated: truncated.truncated,
|
||||
...(truncated.truncated && { outputPath: truncated.outputPath }),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user