mirror of
https://gitea.toothfairyai.com/ToothFairyAI/tf_code.git
synced 2026-03-31 14:22:27 +00:00
This release has a bunch of minor breaking changes if you are using opencode plugins or sdk 1. storage events have been removed (we might bring this back but had some issues) 2. concept of `app` is gone - there is a new concept called `project` and endpoints to list projects and get the current project 3. plugin receives `directory` which is cwd and `worktree` which is where the root of the project is if it's a git repo 4. the session.chat function has been renamed to session.prompt in sdk. it no longer requires model to be passed in (model is now an object) 5. every endpoint takes an optional `directory` parameter to operate as though opencode is running in that directory
47 lines
1.5 KiB
TypeScript
47 lines
1.5 KiB
TypeScript
import { z } from "zod"
|
|
import { Tool } from "./tool"
|
|
import { EditTool } from "./edit"
|
|
import DESCRIPTION from "./multiedit.txt"
|
|
import path from "path"
|
|
import { Instance } from "../project/instance"
|
|
|
|
export const MultiEditTool = Tool.define("multiedit", {
|
|
description: DESCRIPTION,
|
|
parameters: z.object({
|
|
filePath: z.string().describe("The absolute path to the file to modify"),
|
|
edits: z
|
|
.array(
|
|
z.object({
|
|
filePath: z.string().describe("The absolute path to the file to modify"),
|
|
oldString: z.string().describe("The text to replace"),
|
|
newString: z.string().describe("The text to replace it with (must be different from oldString)"),
|
|
replaceAll: z.boolean().optional().describe("Replace all occurrences of oldString (default false)"),
|
|
}),
|
|
)
|
|
.describe("Array of edit operations to perform sequentially on the file"),
|
|
}),
|
|
async execute(params, ctx) {
|
|
const tool = await EditTool.init()
|
|
const results = []
|
|
for (const [, edit] of params.edits.entries()) {
|
|
const result = await tool.execute(
|
|
{
|
|
filePath: params.filePath,
|
|
oldString: edit.oldString,
|
|
newString: edit.newString,
|
|
replaceAll: edit.replaceAll,
|
|
},
|
|
ctx,
|
|
)
|
|
results.push(result)
|
|
}
|
|
return {
|
|
title: path.relative(Instance.worktree, params.filePath),
|
|
metadata: {
|
|
results: results.map((r) => r.metadata),
|
|
},
|
|
output: results.at(-1)!.output,
|
|
}
|
|
},
|
|
})
|