[Task][AI Proxy] Complete and extend native AI Protocol support
Parent issue: #7351
Depends on: #7381
Background
#7381 introduced the initial Protocol request contract and validated it with OpenAI Chat request decoding.
The Protocol layer now needs complete request, response, error, and streaming semantics, and should support multiple client-facing AI protocols without depending on a Provider or HTTP Transport.
OpenAI Chat Completions and OpenAI Responses are the initial native Protocol implementations required to validate this extensibility.
In this issue, "native Protocol support" means that ShenYu can independently detect, validate, decode, and encode the protocol's request and response wire format. It does not mean that every Provider natively exposes that protocol.
Goal
Complete the extensible AI Protocol layer and provide native protocol handling for both OpenAI Chat Completions and OpenAI Responses.
Protocol implementations must remain independent of Provider selection, Provider endpoint configuration, HTTP Transport, retry, and fallback policy.
Scope
Shared Protocol contract
- define only the normalized request, response, stream event, usage, finish-reason, tool-call, and error fields required by ShenYu behavior;
- retain raw payloads or extensions for fields that should pass through;
- decode normal responses without depending on Spring AI DTOs;
- decode streaming events incrementally without buffering the complete body;
- encode normal and streaming responses in the selected client protocol;
- define clear malformed-request, malformed-response, malformed-event, and protocol-error behavior;
- preserve unknown request and response fields whenever no transformation is required;
- retain the explicit Protocol registry as the extension mechanism.
OpenAI Chat Completions
- complete request validation and decoding;
- complete normal response decoding and encoding;
- process Chat Completions SSE events incrementally;
- represent text, model, finish reason, tool calls, token usage, and errors;
- validate and encode Chat streaming termination semantics, including
data: [DONE].
OpenAI Responses
- detect and validate OpenAI Responses requests;
- decode
input, instructions, tools, model, token limits, and streaming mode; - handle normal Responses API response bodies and
output[]content; - process named Responses SSE events incrementally, including
response.output_text.delta,response.completed,response.failed, and protocol error events; - represent Responses usage fields, tool calls, reasoning fields, and completion state where required by ShenYu;
- encode native Responses normal and streaming responses without converting them through OpenAI Chat;
- preserve Responses-specific and unknown fields when no transformation is required.
Future native Protocol implementations may include Anthropic Messages, OpenAI Embeddings, Gemini, or Bedrock, but they are not required by this task.
Boundaries
Protocol must not:
- choose an upstream Provider;
- determine whether a Provider natively supports a protocol;
- select a target/upstream protocol;
- perform cross-protocol routing;
- apply Provider authentication, endpoint, model mapping, or dialect rules;
- open or manage HTTP connections;
- configure network timeout or connection-pool policy;
- decide retry or fallback policy.
Cross-protocol conversion and Provider-native protocol routing are handled by a separate child task under #7351.
Acceptance criteria
- [ ] OpenAI Chat requests and normal responses can be decoded and encoded.
- [ ] OpenAI Chat SSE events are processed incrementally.
- [ ] OpenAI Responses requests and normal responses can be decoded and encoded.
- [ ] OpenAI Responses named SSE events are processed incrementally.
- [ ] Streaming processing does not buffer the complete response.
- [ ] Native Responses handling does not require conversion through Chat.
- [ ] Text, model, finish reason, token usage, tool calls, completion state, and protocol errors can be represented when present.
- [ ] Malformed requests, responses, and stream events produce classified Protocol errors.
- [ ] Unknown request and response fields are retained where possible.
- [ ] Protocol code does not depend on Spring AI clients or DTOs.
- [ ] Protocol code does not depend on a concrete Provider or Transport.
- [ ] Adding another native Protocol does not require changing Provider or Transport contracts.
- [ ] Focused tests cover Chat and Responses normal responses, streaming events, usage, finish reasons, errors, malformed events, and unknown-field preservation.
👋 Hello @Aias00
A new issue has been opened by @hengyuss:
- Title: [Task][AI Proxy] Implement the extensible AI Protocol layer
- Link: https://github.com/apache/shenyu/issues/7382
Please review when you have time. Thank you! 🙏
Status after #7543: the merged implementation now has OpenAI Chat request handling, raw normal-response pass-through, incremental SSE validation/reframing, malformed-event errors, and unknown-field preservation. Keeping this issue open because its broader acceptance criteria are not fully covered yet: protocol-neutral response/event/usage/finish-reason/error models, explicit normal-response decode/encode semantics, and focused coverage for usage, finish reasons, protocol errors, and unknown response fields still need to be completed or the scope needs to be revised.
/assign