server: align ai.chat handler param shape with its OpenRPC spec #140
Labels
No labels
prio_critical
prio_low
type_bug
type_contact
type_issue
type_lead
type_question
type_story
type_task
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
lhumina_code/hero_aibroker#140
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Problem
The
chat.openrpc.jsonspec declaresai.chatwith a single named param:OpenRPC named-params convention puts the value at
params.request. Theopenrpc_client!macro correctly generatesAiChatInput { request: ChatRequest }which serialises to{"jsonrpc":"2.0","method":"ai.chat","params":{"request":{...}}}.But the server's handler (
crates/hero_aibroker_server/src/api_openrpc/chat/handlers.rs::ai_chat) reads params flat:So macro-generated clients fail with
'model' parameter requiredbecauseparams_valueis{"request":{...}}, not the ChatRequest itself.#131 worked around this by hand-rolling
chat::Client::ai_chatto sendChatRequestdirectly (flat). That fixes the client but locks the chat domain out of macro-generated code generation, and any consumer that builds a client from the spec themselves will hit the same bug.Proposal
Pick one of two:
Option A — unwrap
params["request"]on the server (smallest)In
chat/handlers.rs::ai_chatand the other chat methods (ai.messages,ai.responses,ai.completions), at the top:Two-line change per method. The hand-rolled
chat::Client::ai_chatin the SDK can then be removed and replaced with the macro-generated one.Option B — flatten the spec
Change
chat.openrpc.jsonai.chatparams from[{"name": "request", "schema": ChatRequest}]to an enumeration of each ChatRequest field (model,messages,temperature, …). Loses$refreuse and bloats the spec to ~30 named params per method. Not recommended.Recommendation
A. Server unwraps; spec stays clean; macro-generated clients work.
Acceptance
crates/hero_aibroker_server/src/api_openrpc/chat/handlers.rsaccepts both wrapped ({"request":{...}}) and legacy flat params forai.chat,ai.messages,ai.responses,ai.completionschat::Client::ai_chatincrates/hero_aibroker_sdk/src/lib.rsdeleted; replaced with the macro-generatedai_chat(AiChatInput)crates/hero_aibroker_sdk/src/prompt.rs::PromptBuilderuses macro-generatedAiChatInput { request: ChatRequest }shapecargo run -p hero_aibroker_examples --example verify_127_chatstill returns a real response (regression check)Refs #127, #131.
Implemented in #141 — #141.
Live-verified against a rebuilt broker (real Groq round-trip).