Skip to content
3 min read · 537 words

@nhtio/adk/batteries/llm/openai_chat_completions/helpers

Swappable translation helpers for rendering ADK state into Chat Completions requests.

Remarks

The swappable translation helpers that turn ADK primitives into OpenAI Chat Completions wire shapes. Each helper is exported under its unprefixed name AND under a default* alias so consumers can compose partial overrides. Helpers that compose other helpers receive their dependents via explicit input arguments — never via module-level closure — so a swap at any layer propagates correctly.

The wire-shape-AGNOSTIC helpers (renderUntrustedContent, renderMemories, renderChatCompletionsSystemPrompt, toolsToChatCompletionsTools, …) now live in the shared, internal ../chat_common/helpers submodule and are re-exported here under their original names so every existing import keeps resolving. Only the OpenAI-WIRE-SPECIFIC helpers (renderTimelineMessage, renderChatCompletionsToolCallResult, buildChatCompletionsHistory, createChatCompletionsToolCallDeltaAccumulator) and the reasoning-field extractor are defined here.

Variables

VariableDescription
defaultBuildChatCompletionsHistoryDefault history assembler; alias of buildChatCompletionsHistory.
defaultCreateChatCompletionsToolCallDeltaAccumulatorDefault delta-accumulator factory; alias of createChatCompletionsToolCallDeltaAccumulator.
defaultRenderChatCompletionsToolCallResultDefault tool-call-result renderer; alias of renderChatCompletionsToolCallResult.
defaultRenderTimelineMessageDefault timeline-message renderer; alias of renderTimelineMessage.

Functions

FunctionDescription
buildChatCompletionsHistoryAssembles the complete OpenAI Chat Completions message history for a dispatch — system prompt and content buckets, the interleaved timeline of messages/thoughts/tool calls (with synthetic assistant.tool_calls and tool.tool_call_id shaping), and the collected opaque reasoning payloads — by delegating to the injected sub-renderers.
createChatCompletionsToolCallDeltaAccumulatorCreates a fresh accumulator that stitches streamed ChatCompletionsToolCallDelta fragments (keyed by their stream index) into fully-assembled tool calls, drained once the stream completes.
extractReasoningFieldsPulls model reasoning/thinking text out of a Chat Completions response message or stream delta, reading every wire field named in precedence that carries a non-empty string.
renderChatCompletionsToolCallResultRenders a tool call's result(s) into the OpenAI Chat Completions tool-message body — either a plain string or an array of content blocks when the result carries media — wrapping textual output in the trust envelope appropriate to the tool's trust level.
renderTimelineMessageRenders a single timeline @nhtio/adk!Message into an OpenAI Chat Completions message — mapping media to content blocks (image_url / input_audio / file), wrapping textual bodies in the appropriate trust envelope, and applying the unsupported-media policy.

References

defaultDescriptionToChatCompletionsJsonSchema

Re-exports defaultDescriptionToChatCompletionsJsonSchema


defaultFilterThoughts

Re-exports defaultFilterThoughts


defaultRenderChatCompletionsSystemPrompt

Re-exports defaultRenderChatCompletionsSystemPrompt


defaultRenderFirstPartyRetrievables

Re-exports defaultRenderFirstPartyRetrievables


defaultRenderMemories

Re-exports defaultRenderMemories


defaultRenderRetrievables

Re-exports defaultRenderRetrievables


defaultRenderRetrievableSafetyDirective

Re-exports defaultRenderRetrievableSafetyDirective


defaultRenderStandingInstructions

Re-exports defaultRenderStandingInstructions


defaultRenderThirdPartyPrivateRetrievables

Re-exports defaultRenderThirdPartyPrivateRetrievables


defaultRenderThirdPartyPublicRetrievables

Re-exports defaultRenderThirdPartyPublicRetrievables


defaultRenderThought

Re-exports defaultRenderThought


defaultRenderTrustedContent

Re-exports defaultRenderTrustedContent


defaultRenderUntrustedContent

Re-exports defaultRenderUntrustedContent


defaultToolsToChatCompletionsTools

Re-exports defaultToolsToChatCompletionsTools


descriptionToChatCompletionsJsonSchema

Re-exports descriptionToChatCompletionsJsonSchema


filterThoughts

Re-exports filterThoughts


floorTrustTier

Re-exports floorTrustTier


neutraliseDeveloperRulesTag

Re-exports neutraliseDeveloperRulesTag


renderChatCompletionsSystemPrompt

Re-exports renderChatCompletionsSystemPrompt


renderFirstPartyRetrievables

Re-exports renderFirstPartyRetrievables


renderMemories

Re-exports renderMemories


renderRetrievables

Re-exports renderRetrievables


renderRetrievableSafetyDirective

Re-exports renderRetrievableSafetyDirective


renderStandingInstructions

Re-exports renderStandingInstructions


renderThirdPartyPrivateRetrievables

Re-exports renderThirdPartyPrivateRetrievables


renderThirdPartyPublicRetrievables

Re-exports renderThirdPartyPublicRetrievables


renderThought

Re-exports renderThought


renderTrustedContent

Re-exports renderTrustedContent


renderUntrustedContent

Re-exports renderUntrustedContent


sanitizeFilenameForDescription

Re-exports sanitizeFilenameForDescription


sanitizeMimeType

Re-exports sanitizeMimeType


stripEnvelopeSpecialTokens

Re-exports stripEnvelopeSpecialTokens


toolsToChatCompletionsTools

Re-exports toolsToChatCompletionsTools