Skip to content

Commit afb7a5c

Browse files
committed
feat(config): add useFunctionApplyPatch option and implement patch handling in responses
1 parent 318855e commit afb7a5c

3 files changed

Lines changed: 38 additions & 1 deletion

File tree

src/lib/config.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export interface AppConfig {
1010
string,
1111
"none" | "minimal" | "low" | "medium" | "high" | "xhigh"
1212
>
13+
useFunctionApplyPatch?: boolean
1314
}
1415

1516
const gpt5ExplorationPrompt = `## Exploration and reading files
@@ -28,6 +29,7 @@ const defaultConfig: AppConfig = {
2829
modelReasoningEfforts: {
2930
"gpt-5-mini": "low",
3031
},
32+
useFunctionApplyPatch: true,
3133
}
3234

3335
let cachedConfig: AppConfig | null = null

src/routes/responses/handler.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import type { Context } from "hono"
33
import { streamSSE } from "hono/streaming"
44

55
import { awaitApproval } from "~/lib/approval"
6+
import { getConfig } from "~/lib/config"
67
import { createHandlerLogger } from "~/lib/logger"
78
import { checkRateLimit } from "~/lib/rate-limit"
89
import { state } from "~/lib/state"
@@ -24,6 +25,8 @@ export const handleResponses = async (c: Context) => {
2425
const payload = await c.req.json<ResponsesPayload>()
2526
logger.debug("Responses request payload:", JSON.stringify(payload))
2627

28+
useFunctionApplyPatch(payload)
29+
2730
const selectedModel = state.models?.data.find(
2831
(model) => model.id === payload.model,
2932
)
@@ -78,3 +81,35 @@ const isAsyncIterable = <T>(value: unknown): value is AsyncIterable<T> =>
7881

7982
const isStreamingRequested = (payload: ResponsesPayload): boolean =>
8083
Boolean(payload.stream)
84+
85+
const useFunctionApplyPatch = (payload: ResponsesPayload): void => {
86+
const config = getConfig()
87+
const useFunctionApplyPatch = config.useFunctionApplyPatch ?? true
88+
if (useFunctionApplyPatch) {
89+
logger.debug("Using function tool apply_patch for responses")
90+
if (Array.isArray(payload.tools)) {
91+
const toolsArr = payload.tools
92+
for (let i = 0; i < toolsArr.length; i++) {
93+
const t = toolsArr[i]
94+
if (t.type === "custom" && t.name === "apply_patch") {
95+
toolsArr[i] = {
96+
type: "function",
97+
name: t.name,
98+
description: "Use the `apply_patch` tool to edit files",
99+
parameters: {
100+
type: "object",
101+
properties: {
102+
input: {
103+
type: "string",
104+
description: "The entire contents of the apply_patch command",
105+
},
106+
},
107+
required: ["input"],
108+
},
109+
strict: false,
110+
}
111+
}
112+
}
113+
}
114+
}
115+
}

src/services/copilot/create-responses.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export interface ToolChoiceFunction {
3333
type: "function"
3434
}
3535

36-
export type Tool = FunctionTool
36+
export type Tool = FunctionTool | Record<string, unknown>
3737

3838
export interface FunctionTool {
3939
name: string

0 commit comments

Comments
 (0)