|
| 1 | +*** Begin Patch |
| 2 | +*** Update File: PATH/TO/PLAN_APPROVAL_FILE.ts |
| 3 | +@@ |
| 4 | +-import { buildMenuFromFunctionCall } from './menu-builder'; |
| 5 | ++import { buildMenuFromFunctionCall } from './menu-builder'; |
| 6 | ++import parsePlanReviewOptions from '../../src/parsePlanReview'; |
| 7 | +@@ |
| 8 | +-export function buildPlanApprovalMenu(response: AssistantResponse): MenuItem[] { |
| 9 | +- // existing flow: prefer structured function_call/tool metadata |
| 10 | +- if (response.metadata && response.metadata.function_call && response.metadata.function_call.arguments) { |
| 11 | +- try { |
| 12 | +- const args = JSON.parse(response.metadata.function_call.arguments); |
| 13 | +- return buildMenuFromFunctionCall(args); |
| 14 | +- } catch (e) { |
| 15 | +- // fall through to text parsing |
| 16 | +- } |
| 17 | +- } |
| 18 | +- |
| 19 | +- // Fallback: parse assistant text for simple enumerated choices |
| 20 | +- return textBasedMenuParser(response.text); |
| 21 | +-} |
| 22 | ++export function buildPlanApprovalMenu(response: AssistantResponse): MenuItem[] { |
| 23 | ++ // Prefer structured function_call metadata when present. |
| 24 | ++ if (response.metadata && response.metadata.function_call && response.metadata.function_call.arguments) { |
| 25 | ++ try { |
| 26 | ++ const args = JSON.parse(response.metadata.function_call.arguments); |
| 27 | ++ // Existing helper may already convert this into MenuItem[], reuse if available |
| 28 | ++ const fromFunc = buildMenuFromFunctionCall(args); |
| 29 | ++ if (fromFunc && fromFunc.length) return fromFunc; |
| 30 | ++ } catch (e) { |
| 31 | ++ // ignore and continue to text parsing fallback |
| 32 | ++ } |
| 33 | ++ } |
| 34 | ++ |
| 35 | ++ // Robust fallback: parse the assistant text using the JSON-first then bullets heuristic. |
| 36 | ++ // This handles strict OpenAI-compatible backends that don't provide function_call/tool metadata. |
| 37 | ++ const menuItems = parsePlanReviewOptions(response.text, response.metadata); |
| 38 | ++ if (menuItems && menuItems.length) return menuItems; |
| 39 | ++ |
| 40 | ++ // As a last resort, keep the minimal previous fallback behavior (Accept / Request changes) |
| 41 | ++ return [ |
| 42 | ++ { id: 'accept', label: 'Accept plan', description: 'Apply the plan as-is' }, |
| 43 | ++ { id: 'request_changes', label: 'Request changes', description: 'Ask the model for updates' }, |
| 44 | ++ ]; |
| 45 | ++} |
| 46 | +*** End Patch |
| 47 | + |
| 48 | +Notes: |
| 49 | +- Replace PATH/TO/PLAN_APPROVAL_FILE.ts with the actual file path in the codebase where the plan approval menu is built. |
| 50 | +- Ensure relative import path to src/parsePlanReview is correct; adjust as needed. |
| 51 | +- If the codebase is in Go or another language, apply the same algorithm: prefer structured metadata, then parse JSON/YAML code blocks, then numbered/bulleted lists, then minimal fallback. |
| 52 | +- Add unit tests to the file's existing test suite using tests/plan-review-fallback-cases.json as vectors. |
0 commit comments