// apply_patch: structured create_file operation, validated and reported as a dry run. STATUS: LIVE_VERIFIED 2026-09-18 (gpt-5.4-nano). // Run: node --env-file=.env --experimental-strip-types examples/openai/tools/apply-patch/apply_patch.ts import OpenAI from "openai"; import { logRequest } from "../../../shared/tool-loop/log.ts"; const client = new OpenAI(); const r: any = await client.responses.create({ model: "gpt-5.4-nano", input: "Create a new file hello.txt containing the single line OK using apply_patch.", tools: [{ type: "apply_patch" } as any], tool_choice: { type: "apply_patch" } as any, max_output_tokens: 128, reasoning: { effort: "low" } }); logRequest("openai", "POST", "/v1/responses", 200, 0.0002, "apply_patch.ts"); const call = r.output.find((i: any) => i.type === "apply_patch_call"); console.log("apply_patch_call:", call.call_id, call.operation.type, call.operation.path, JSON.stringify(call.operation.diff)); const ok = !call.operation.path.includes("..") && !call.operation.path.startsWith("/"); console.log("would send:", { type: "apply_patch_call_output", call_id: call.call_id, status: ok ? "completed" : "failed", output: ok ? "dry run: not applied" : "path rejected" });