refactor(open-sse): extract chunkBuilder, dedup chat.completion.chunk (B1)
Add helpers/chunkBuilder.js; apply to claude/gemini/kiro/ollama/commandcode/ openai-responses response translators. Caller supplies id/created/model so each keeps exact id-generation + usage semantics. Extend golden response stream to openai-responses (codex). No behavior change; gate: no regression. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -445,3 +445,126 @@ exports[`GOLDEN response stream: Ollama → OpenAI > content + thinking + tool_c
|
||||
},
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`GOLDEN response stream: OpenAI-Responses (codex) → OpenAI > error event → error chunk (fallback id/created) 1`] = `
|
||||
[
|
||||
{
|
||||
"choices": [
|
||||
{
|
||||
"delta": {
|
||||
"content": "[Error] model_not_found",
|
||||
},
|
||||
"finish_reason": "stop",
|
||||
"index": 0,
|
||||
},
|
||||
],
|
||||
"created": 0,
|
||||
"id": "chatcmpl-<TS>",
|
||||
"model": "unknown",
|
||||
"object": "chat.completion.chunk",
|
||||
},
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`GOLDEN response stream: OpenAI-Responses (codex) → OpenAI > text + reasoning + tool_call + completed usage 1`] = `
|
||||
[
|
||||
{
|
||||
"choices": [
|
||||
{
|
||||
"delta": {
|
||||
"content": "Hello",
|
||||
},
|
||||
"finish_reason": null,
|
||||
"index": 0,
|
||||
},
|
||||
],
|
||||
"created": 0,
|
||||
"id": "chatcmpl-<TS>",
|
||||
"model": "unknown",
|
||||
"object": "chat.completion.chunk",
|
||||
},
|
||||
{
|
||||
"choices": [
|
||||
{
|
||||
"delta": {
|
||||
"reasoning_content": "thinking",
|
||||
},
|
||||
"finish_reason": null,
|
||||
"index": 0,
|
||||
},
|
||||
],
|
||||
"created": 0,
|
||||
"id": "chatcmpl-<TS>",
|
||||
"model": "unknown",
|
||||
"object": "chat.completion.chunk",
|
||||
},
|
||||
{
|
||||
"choices": [
|
||||
{
|
||||
"delta": {
|
||||
"tool_calls": [
|
||||
{
|
||||
"function": {
|
||||
"arguments": "",
|
||||
"name": "get_weather",
|
||||
},
|
||||
"id": "call_1",
|
||||
"index": 0,
|
||||
"type": "function",
|
||||
},
|
||||
],
|
||||
},
|
||||
"finish_reason": null,
|
||||
"index": 0,
|
||||
},
|
||||
],
|
||||
"created": 0,
|
||||
"id": "chatcmpl-<TS>",
|
||||
"model": "unknown",
|
||||
"object": "chat.completion.chunk",
|
||||
},
|
||||
{
|
||||
"choices": [
|
||||
{
|
||||
"delta": {
|
||||
"tool_calls": [
|
||||
{
|
||||
"function": {
|
||||
"arguments": "{"city":"NYC"}",
|
||||
},
|
||||
"index": 0,
|
||||
},
|
||||
],
|
||||
},
|
||||
"finish_reason": null,
|
||||
"index": 0,
|
||||
},
|
||||
],
|
||||
"created": 0,
|
||||
"id": "chatcmpl-<TS>",
|
||||
"model": "unknown",
|
||||
"object": "chat.completion.chunk",
|
||||
},
|
||||
{
|
||||
"choices": [
|
||||
{
|
||||
"delta": {},
|
||||
"finish_reason": "tool_calls",
|
||||
"index": 0,
|
||||
},
|
||||
],
|
||||
"created": 0,
|
||||
"id": "chatcmpl-<TS>",
|
||||
"model": "unknown",
|
||||
"object": "chat.completion.chunk",
|
||||
"usage": {
|
||||
"completion_tokens": 5,
|
||||
"prompt_tokens": 10,
|
||||
"prompt_tokens_details": {
|
||||
"cached_tokens": 3,
|
||||
},
|
||||
"total_tokens": 15,
|
||||
},
|
||||
},
|
||||
]
|
||||
`;
|
||||
|
||||
Reference in New Issue
Block a user