Skip to content

nevescloud/chat-compat

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

@nevescloud/chat-compat

One source of truth for the OpenAI-Codex (chatgpt.com Responses API) and Gemini-Code-Assist (cloudcode-pa.googleapis.com) ↔ Chat Completions translation. Pure transforms, no I/O — runtime-agnostic (CJS), so the same logic runs unchanged in a Node http server and a Cloudflare Worker (fetch). Each runtime keeps its own streaming I/O and wraps these.

npm i @nevescloud/chat-compat
const { openai, gemini, drainSSE } = require('@nevescloud/chat-compat');         // Node
// import cc from '@nevescloud/chat-compat'; const { openai, gemini, drainSSE } = cc; // ESM/Worker (default import — CJS)
  • openai: normalizeModel · resolveCodexModel · chatToResponsesPayload · responsesToChatCompletion · newCodexStream + transformCodexEvent (per-SSE-event → Chat-Completion chunks).
  • gemini: resolveGeminiModel · toCodeAssistRequest · isRetryableGeminiError · extractGeminiText · geminiTextChunk.
  • drainSSE(buffer){ events, rest } — drains \n\n-delimited SSE events, keeps the remainder.

Streaming pattern (per runtime): accumulate bytes → drainSSE → per event call the transform → write returned chunks → on done/stream-end emit data: [DONE]\n\n.

npm test — golden tests lock the exact output.

About

OpenAI-Codex & Gemini ↔ Chat Completions translation — pure, runtime-agnostic (Node + Cloudflare Workers)

Resources

License

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors