fix(core): bound tool structured output
This commit is contained in:
parent
61b7caa0b5
commit
2deaa7786c
17 changed files with 440 additions and 165 deletions
|
|
@ -3,8 +3,8 @@ export * as PatchTool from "./patch"
|
|||
import type { Context as PluginContext } from "@opencode-ai/plugin/v2/effect/plugin"
|
||||
import { ToolFailure } from "@opencode-ai/ai"
|
||||
import { FileDiff } from "@opencode-ai/schema/file-diff"
|
||||
import { createTwoFilesPatch, diffLines } from "diff"
|
||||
import { Effect, Schema } from "effect"
|
||||
import { diffLines } from "diff"
|
||||
import { Effect, Schema, Struct } from "effect"
|
||||
import { FileMutation } from "../file-mutation"
|
||||
import { FSUtil } from "../fs-util"
|
||||
import { LocationMutation } from "../location-mutation"
|
||||
|
|
@ -26,9 +26,11 @@ export const Applied = Schema.Struct({
|
|||
target: Schema.String,
|
||||
})
|
||||
|
||||
const FileInfo = FileDiff.Info.mapFields(Struct.omit(["patch"]))
|
||||
|
||||
export const Output = Schema.Struct({
|
||||
applied: Schema.Array(Applied),
|
||||
files: Schema.Array(FileDiff.Info),
|
||||
files: Schema.Array(FileInfo),
|
||||
})
|
||||
export type Output = typeof Output.Type
|
||||
|
||||
|
|
@ -211,7 +213,7 @@ export const Plugin = {
|
|||
}),
|
||||
}
|
||||
|
||||
function patchFile(change: Prepared): typeof FileDiff.Info.Type {
|
||||
function patchFile(change: Prepared): typeof FileInfo.Type {
|
||||
const counts = diffLines(change.before, change.after).reduce(
|
||||
(result, item) => ({
|
||||
additions: result.additions + (item.added ? (item.count ?? 0) : 0),
|
||||
|
|
@ -221,7 +223,6 @@ function patchFile(change: Prepared): typeof FileDiff.Info.Type {
|
|||
)
|
||||
return {
|
||||
file: change.target.resource,
|
||||
patch: createTwoFilesPatch(change.target.resource, change.target.resource, change.before, change.after),
|
||||
status: change.type === "add" ? "added" : change.type === "delete" ? "deleted" : "modified",
|
||||
...counts,
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue