[π Bounty] feat: OpenAI Function Calling editor β JSON schema UI#349
[π Bounty] feat: OpenAI Function Calling editor β JSON schema UI#349zhangyei1976-dotcom wants to merge 2 commits into
Conversation
Completed Working on "Code Review"β Review submitted: COMMENT. Total comments: 4 across 2 files. β Workflow completed successfully. π View complete log |
There was a problem hiding this comment.
Thanks for the implementation β Iβve summarized the already-posted review findings below.
Findings summary
- 4 MAJOR issues identified (no BLOCKER/CRITICAL findings)
- Affected files: 2
apps/console/src/components/prompts/editor/function/FunctionCallSettingsCard.tsxapps/console/src/components/prompts/editor/function/FunctionEditMode.tsx
Key themes
- State synchronization risks between local component state and
react-hook-formsource-of-truth. - Data normalization/identity gaps for nested editable items (missing stable ids, index-based keys).
- Schema validity edge cases in JSON preview generation when required input fields are incomplete.
Recommended next steps
- Ensure function/parameter UI state is derived from or synced to watched form values to avoid stale edits.
- Normalize loaded function/parameter objects by assigning stable identifiers when missing; avoid index-based React keys.
- Filter/validate invalid parameter entries (e.g., blank names) before generating schema preview and required arrays.
Once these MAJOR issues are addressed, this feature should be in a much safer state for merge.
| parameters: { | ||
| type: "object", | ||
| properties: Object.fromEntries( | ||
| (f.parameters || []).map((p: any) => [ |
There was a problem hiding this comment.
[major]: The preview includes every parameter row without validating p.name, so empty names become "" keys in parameters.properties and can also appear in required. This generates an invalid/misleading OpenAI schema preview when users leave a parameter name blank.
Filter parameters before mapping/required generation (e.g., const validParams = (f.parameters || []).filter(p => p.name?.trim())) and use validParams for both properties and required.
| const { getForm } = useEditorContext(); | ||
| const { promptId } = useCurrentPrompt(); | ||
| const form = getForm(); | ||
|
|
There was a problem hiding this comment.
[major]: The component initializes local functions state from form.getValues("content") once and never re-syncs, so switching prompts or async form resets can leave the UI editing stale data while the form holds different content.functions.
Derive functions from useWatch({ control: form.control, name: "content.functions" }) (or sync local state in an effect on watched value) so UI always reflects current form state.
| className="flex items-start gap-2 rounded-md border bg-muted/30 p-2" | ||
| > | ||
| <div {...provided.dragHandleProps}> | ||
| <GripVerticalIcon className="mt-2 h-4 w-4 text-muted-foreground" /> |
There was a problem hiding this comment.
[major]: New parameters get id values, but loaded parameters from persisted content.functions may not include id; this causes Draggable to receive undefined draggableId and update/remove operations keyed by param.id to fail.
Normalize loaded parameters on read by assigning stable ids when missing (e.g., map parameters and inject generated ids before rendering/updating).
| return ( | ||
| <div className="flex flex-col gap-6"> | ||
| {functions.map((func, fi) => ( | ||
| <Card key={fi} className="p-4"> |
There was a problem hiding this comment.
[major]: Using key={fi} for function cards causes React to reuse DOM/state by position. After removing a function, inputs can appear to jump between cards or keep stale values, which is risky for nested editable forms.
Add a stable per-function identifier and use it as the React key (and ideally for updates), rather than array index.
OpenAI Function Calling Support β Issue #244
Adds a visual JSON schema editor for defining OpenAI function calling definitions within Pezzo's prompt editor.
New Components
FunctionEditMode(components/prompts/editor/function/FunctionEditMode.tsx)FunctionCallSettingsCard(components/prompts/editor/function/FunctionCallSettingsCard.tsx)Architecture
EditorContextform viareact-hook-formcontent.functionson the form stateChatEditMode(drag-drop, form integration,@pezzo/uicomponents)How to integrate into PromptEditView
Closes #244