SPB Git forge

spb/doc-api

Public
2commits 1branches 0releases
15.7 MBsize
maindefault branch
13 days agolast push
Python 88.3% TypeScript 7.6% Shell 4.1%
1.2 KB · 13 lines typescript
Raw Blame History
1// apply_patch: structured create_file operation, validated and reported as a dry run. STATUS: LIVE_VERIFIED 2026-09-18 (gpt-5.4-nano).2// Run: node --env-file=.env --experimental-strip-types examples/openai/tools/apply-patch/apply_patch.ts3import OpenAI from "openai";4import { logRequest } from "../../../shared/tool-loop/log.ts";5const client = new OpenAI();6const 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.",7  tools: [{ type: "apply_patch" } as any], tool_choice: { type: "apply_patch" } as any, max_output_tokens: 128, reasoning: { effort: "low" } });8logRequest("openai", "POST", "/v1/responses", 200, 0.0002, "apply_patch.ts");9const call = r.output.find((i: any) => i.type === "apply_patch_call");10console.log("apply_patch_call:", call.call_id, call.operation.type, call.operation.path, JSON.stringify(call.operation.diff));11const ok = !call.operation.path.includes("..") && !call.operation.path.startsWith("/");12console.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" });13