refactor(tool): reuse edit entry schema in multiedit
This commit is contained in:
parent
f2cbcacf00
commit
e2eff19a32
2 changed files with 9 additions and 15 deletions
|
|
@ -31,8 +31,7 @@ function convertToLineEnding(text: string, ending: "\n" | "\r\n"): string {
|
||||||
return text.replaceAll("\n", "\r\n")
|
return text.replaceAll("\n", "\r\n")
|
||||||
}
|
}
|
||||||
|
|
||||||
export const Parameters = Schema.Struct({
|
export const Entry = Schema.Struct({
|
||||||
filePath: Schema.String.annotate({ description: "The absolute path to the file to modify" }),
|
|
||||||
oldString: Schema.String.annotate({ description: "The text to replace" }),
|
oldString: Schema.String.annotate({ description: "The text to replace" }),
|
||||||
newString: Schema.String.annotate({
|
newString: Schema.String.annotate({
|
||||||
description: "The text to replace it with (must be different from oldString)",
|
description: "The text to replace it with (must be different from oldString)",
|
||||||
|
|
@ -42,6 +41,11 @@ export const Parameters = Schema.Struct({
|
||||||
}),
|
}),
|
||||||
})
|
})
|
||||||
|
|
||||||
|
export const Parameters = Schema.Struct({
|
||||||
|
filePath: Schema.String.annotate({ description: "The absolute path to the file to modify" }),
|
||||||
|
...Entry.fields,
|
||||||
|
})
|
||||||
|
|
||||||
export const EditTool = Tool.define(
|
export const EditTool = Tool.define(
|
||||||
"edit",
|
"edit",
|
||||||
Effect.gen(function* () {
|
Effect.gen(function* () {
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
import { Effect, Schema } from "effect"
|
import { Effect, Schema } from "effect"
|
||||||
import * as Tool from "./tool"
|
import * as Tool from "./tool"
|
||||||
import { EditTool } from "./edit"
|
import * as Edit from "./edit"
|
||||||
import DESCRIPTION from "./multiedit.txt"
|
import DESCRIPTION from "./multiedit.txt"
|
||||||
import path from "path"
|
import path from "path"
|
||||||
import { Instance } from "../project/instance"
|
import { Instance } from "../project/instance"
|
||||||
|
|
@ -8,24 +8,14 @@ import { Instance } from "../project/instance"
|
||||||
export const Parameters = Schema.Struct({
|
export const Parameters = Schema.Struct({
|
||||||
filePath: Schema.String.annotate({ description: "The absolute path to the file to modify" }),
|
filePath: Schema.String.annotate({ description: "The absolute path to the file to modify" }),
|
||||||
edits: Schema.mutable(
|
edits: Schema.mutable(
|
||||||
Schema.Array(
|
Schema.Array(Edit.Entry),
|
||||||
Schema.Struct({
|
|
||||||
oldString: Schema.String.annotate({ description: "The text to replace" }),
|
|
||||||
newString: Schema.String.annotate({
|
|
||||||
description: "The text to replace it with (must be different from oldString)",
|
|
||||||
}),
|
|
||||||
replaceAll: Schema.optional(Schema.Boolean).annotate({
|
|
||||||
description: "Replace all occurrences of oldString (default false)",
|
|
||||||
}),
|
|
||||||
}),
|
|
||||||
),
|
|
||||||
).annotate({ description: "Array of edit operations to perform sequentially on the file" }),
|
).annotate({ description: "Array of edit operations to perform sequentially on the file" }),
|
||||||
})
|
})
|
||||||
|
|
||||||
export const MultiEditTool = Tool.define(
|
export const MultiEditTool = Tool.define(
|
||||||
"multiedit",
|
"multiedit",
|
||||||
Effect.gen(function* () {
|
Effect.gen(function* () {
|
||||||
const editInfo = yield* EditTool
|
const editInfo = yield* Edit.EditTool
|
||||||
const edit = yield* editInfo.init()
|
const edit = yield* editInfo.init()
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue