docs: document llm helpers

This commit is contained in:
Peter Steinberger
2026-06-04 20:07:13 -04:00
parent f1bdc91b64
commit e6f85453dc
53 changed files with 53 additions and 0 deletions

View File

@@ -1,3 +1,4 @@
// Anthropic provider tests cover stream events, tools, and message mapping.
import { beforeEach, describe, expect, it, vi } from "vitest";
import { SYSTEM_PROMPT_CACHE_BOUNDARY } from "../../agents/system-prompt-cache-boundary.js";
import type { Context, Model } from "../types.js";

View File

@@ -1,3 +1,4 @@
// Anthropic provider adapts Anthropic streams and tool calls for the runtime.
import Anthropic from "@anthropic-ai/sdk";
import type {
CacheControlEphemeral,

View File

@@ -1,3 +1,4 @@
// Azure deployment map tests cover model-to-deployment resolution.
import { describe, expect, it } from "vitest";
import {
parseAzureDeploymentNameMap,

View File

@@ -1,3 +1,4 @@
// Azure OpenAI Responses provider adapts Azure deployments to Responses API streams.
import { AzureOpenAI } from "openai";
import type { ResponseCreateParamsStreaming } from "openai/resources/responses/responses.js";
import { getEnvApiKey } from "../env-api-keys.js";

View File

@@ -1,3 +1,4 @@
// Cloudflare provider metadata describes Cloudflare-hosted model capabilities.
import type { Model } from "../types.js";
/** Workers AI direct endpoint. */

View File

@@ -1,3 +1,4 @@
// GitHub Copilot header helpers build request headers for Copilot-backed providers.
import type { Message } from "../types.js";
// Copilot expects X-Initiator to indicate whether the request is user-initiated

View File

@@ -1,3 +1,4 @@
// Google shared conversion tests cover runtime-to-Google payload conversion.
import { describe, expect, it } from "vitest";
import type { Context, Tool } from "../types.js";
import { convertMessages, convertTools } from "./google-shared.js";

View File

@@ -1,3 +1,4 @@
// Google provider test helpers assert converted message and stream payloads.
import { expect } from "vitest";
import type { Model } from "../types.js";

View File

@@ -1,3 +1,4 @@
// Google shared provider tests cover response conversion and finish reasons.
import { FinishReason, type GenerateContentResponse } from "@google/genai";
import { describe, expect, it } from "vitest";
import type { AssistantMessage, Model } from "../types.js";

View File

@@ -1,3 +1,4 @@
// Google Vertex provider wires Google shared streaming through Vertex credentials.
import {
type GenerateContentParameters,
GoogleGenAI,

View File

@@ -1,3 +1,4 @@
// Google provider adapts Gemini streams and tools to the agent runtime.
import { type GenerateContentParameters, GoogleGenAI } from "@google/genai";
import { getEnvApiKey } from "../env-api-keys.js";
import type { Context, Model, SimpleStreamOptions, StreamFunction } from "../types.js";

View File

@@ -1,3 +1,4 @@
// Mistral provider tests cover request mapping and stream conversion.
import { beforeEach, describe, expect, it, vi } from "vitest";
import type { Context, Model } from "../types.js";

View File

@@ -1,3 +1,4 @@
// Mistral provider adapts Mistral streams and tool calls to the runtime.
import { Mistral } from "@mistralai/mistralai";
import type {
ChatCompletionStreamRequest,

View File

@@ -1,3 +1,4 @@
// ChatGPT Responses provider tests cover stream handling and timeout behavior.
import { MAX_TIMER_TIMEOUT_MS } from "@openclaw/normalization-core/number-coercion";
import { afterEach, describe, expect, it, vi } from "vitest";
import type { Context, Model } from "../types.js";

View File

@@ -1,3 +1,4 @@
// OpenAI ChatGPT Responses provider handles ChatGPT-authenticated response streams.
import type * as NodeOs from "node:os";
import type {
Tool as OpenAITool,

View File

@@ -1,3 +1,4 @@
// OpenAI-compatible auth tests cover API key and base URL normalization.
import { afterEach, describe, expect, it } from "vitest";
import type { Context, Model } from "../types.js";
import { streamOpenAICompletions } from "./openai-completions.js";

View File

@@ -1,3 +1,4 @@
// OpenAI completions tests cover chat completion stream adaptation.
import type { ChatCompletionChunk } from "openai/resources/chat/completions.js";
import { describe, expect, it, vi } from "vitest";
import { SYSTEM_PROMPT_CACHE_BOUNDARY } from "../../agents/system-prompt-cache-boundary.js";

View File

@@ -1,3 +1,4 @@
// OpenAI completions provider adapts chat completions to the agent runtime.
import OpenAI from "openai";
import type {
ChatCompletionAssistantMessageParam,

View File

@@ -1,3 +1,4 @@
// OpenAI Responses shared tests cover tool conversion and response item mapping.
import type { Tool as OpenAIResponsesTool } from "openai/resources/responses/responses.js";
import { describe, expect, it } from "vitest";
import type { Context, Model, Tool } from "../types.js";

View File

@@ -1,3 +1,4 @@
// OpenAI Responses shared helpers map runtime messages, tools, and stream events.
import type OpenAI from "openai";
import type {
ResponseCreateParamsStreaming,

View File

@@ -1,3 +1,4 @@
// OpenAI Responses tool helpers convert runtime tools to Responses API schemas.
import { createHash } from "node:crypto";
import type { Tool as OpenAITool } from "openai/resources/responses/responses.js";
import { resolveOpenAIStrictToolSetting } from "../../agents/openai-strict-tool-setting.js";

View File

@@ -1,3 +1,4 @@
// OpenAI Responses provider adapts OpenAI response streams to the agent runtime.
import OpenAI from "openai";
import type { ResponseCreateParamsStreaming } from "openai/resources/responses/responses.js";
import { getEnvApiKey } from "../env-api-keys.js";

View File

@@ -1,3 +1,4 @@
// Built-in provider registration installs the bundled provider factories.
import { registerApiProvider, unregisterApiProviders } from "../api-registry.js";
import type {
Api,

View File

@@ -1,3 +1,4 @@
// Simple provider option helpers normalize lightweight provider configuration.
import type {
Model,
SimpleStreamOptions,

View File

@@ -1,3 +1,4 @@
// Anthropic cache-control payload tests cover cache metadata preservation.
import { describe, expect, it } from "vitest";
import { applyAnthropicEphemeralCacheControlMarkers } from "./anthropic-cache-control-payload.js";

View File

@@ -1,3 +1,4 @@
// Anthropic-family cache wrapper preserves cache-control semantics in tool payloads.
import {
normalizeLowercaseStringOrEmpty,
normalizeOptionalLowercaseString,

View File

@@ -1,3 +1,4 @@
// Anthropic-family tool payload compatibility wraps provider tool payload shapes.
import { normalizeOptionalString } from "@openclaw/normalization-core/string-coerce";
import type { StreamFn } from "../../../agents/runtime/index.js";
import { streamSimple } from "../../stream.js";

View File

@@ -1,3 +1,4 @@
// Google stream wrapper tests cover Gemini stream payload normalization.
import { describe, expect, it } from "vitest";
import { sanitizeGoogleThinkingPayload } from "./google.js";

View File

@@ -1,3 +1,4 @@
// MiniMax stream wrapper tests cover streamed text and reasoning conversion.
import type { StreamFn } from "openclaw/plugin-sdk/agent-core";
import type { Context, Model } from "openclaw/plugin-sdk/llm";
import { describe, expect, it } from "vitest";

View File

@@ -1,3 +1,4 @@
// MiniMax stream wrapper normalizes MiniMax streamed text and reasoning output.
import type { StreamFn } from "../../../agents/runtime/index.js";
import { streamSimple } from "../../stream.js";

View File

@@ -1,3 +1,4 @@
// Moonshot thinking wrapper normalizes reasoning output from Moonshot streams.
import { normalizeOptionalLowercaseString } from "@openclaw/normalization-core/string-coerce";
import type { StreamFn } from "../../../agents/runtime/index.js";
import type { ThinkLevel } from "../../../auto-reply/thinking.js";

View File

@@ -1,3 +1,4 @@
// Moonshot stream wrapper normalizes Moonshot streamed text and reasoning output.
import type { StreamFn } from "../../../agents/runtime/index.js";
import type { ThinkLevel } from "../../../auto-reply/thinking.js";
import { streamSimple } from "../../stream.js";

View File

@@ -1,3 +1,4 @@
// OpenAI stream wrapper tests cover streamed text, tools, and reasoning fields.
import type { StreamFn } from "openclaw/plugin-sdk/agent-core";
import type { Model } from "openclaw/plugin-sdk/llm";
import { createAssistantMessageEventStream } from "openclaw/plugin-sdk/llm";

View File

@@ -1,3 +1,4 @@
// OpenAI stream wrapper normalizes OpenAI-compatible streamed tool and text events.
import {
normalizeOptionalLowercaseString,
readStringValue,

View File

@@ -1,3 +1,4 @@
// Proxy stream wrapper tests cover wrapper selection and provider passthrough.
import type { StreamFn } from "openclaw/plugin-sdk/agent-core";
import type { Context, Model } from "openclaw/plugin-sdk/llm";
import { createAssistantMessageEventStream } from "openclaw/plugin-sdk/llm";

View File

@@ -1,3 +1,4 @@
// Proxy stream wrapper applies provider-specific wrappers around base stream functions.
import {
normalizeOptionalLowercaseString,
readStringValue,

View File

@@ -1,3 +1,4 @@
// Reasoning effort utility tests cover provider reasoning effort normalization.
import { describe, expect, it } from "vitest";
import { mapThinkingLevelToReasoningEffort } from "./reasoning-effort-utils.js";

View File

@@ -1,3 +1,4 @@
// Reasoning effort utilities map provider thinking controls to runtime levels.
import type { ThinkLevel } from "../../../auto-reply/thinking.js";
/** Reasoning effort values accepted by OpenAI-compatible providers. */

View File

@@ -1,3 +1,4 @@
// Stream payload utilities normalize provider stream payload fields for wrappers.
import type { StreamFn } from "../../../agents/runtime/index.js";
/** Wraps a stream function and lets callers mutate outgoing provider payload objects. */

View File

@@ -1,3 +1,4 @@
// Z.ai stream wrapper normalizes Z.ai provider stream chunks.
import type { StreamFn } from "../../../agents/runtime/index.js";
import { streamSimple } from "../../stream.js";
import { streamWithPayloadPatch } from "./stream-payload-utils.js";

View File

@@ -1,3 +1,4 @@
// Provider message transform helpers convert runtime messages to provider payloads.
import type {
Api,
AssistantMessage,

View File

@@ -1,3 +1,4 @@
// JSON parse tests cover tolerant parsing of partial model JSON output.
import { describe, expect, it } from "vitest";
import { parseJsonWithRepair, parseStreamingJson, repairJson } from "./json-parse.js";

View File

@@ -1,3 +1,4 @@
// JSON parse helpers recover structured values from partial model output.
import { parse as partialParse } from "partial-json";
const VALID_JSON_ESCAPES = new Set(['"', "\\", "/", "b", "f", "n", "r", "t", "u"]);

View File

@@ -1,3 +1,4 @@
// Node HTTP proxy tests cover proxy agent creation for provider requests.
import { afterEach, describe, expect, it, vi } from "vitest";
import {
createHttpProxyAgentsForTarget,

View File

@@ -1,3 +1,4 @@
// Node HTTP proxy helpers build HTTP(S) agents from proxy settings.
import type { Agent as HttpAgent } from "node:http";
import type { Agent as HttpsAgent } from "node:https";
import {

View File

@@ -1,3 +1,4 @@
// OAuth abort tests cover cancellation of pending OAuth flows.
import { MAX_TIMER_TIMEOUT_MS } from "@openclaw/normalization-core/number-coercion";
import { afterEach, describe, expect, it, vi } from "vitest";
import { buildOAuthRequestSignal } from "./abort.js";

View File

@@ -1,3 +1,4 @@
// Anthropic OAuth tests cover token exchange and refresh behavior.
import { afterEach, describe, expect, it, vi } from "vitest";
import { anthropicOAuthProvider, refreshAnthropicToken } from "./anthropic.js";

View File

@@ -1,3 +1,4 @@
// GitHub Copilot OAuth tests cover device flow polling and timeout behavior.
import { MAX_TIMER_TIMEOUT_MS } from "@openclaw/normalization-core/number-coercion";
import { afterEach, describe, expect, it, vi } from "vitest";
import { refreshGitHubCopilotToken, testing } from "./github-copilot.js";

View File

@@ -1,3 +1,4 @@
// OpenAI ChatGPT JWT helpers inspect auth claims for ChatGPT OAuth sessions.
const OPENAI_CODEX_AUTH_CLAIM = "https://api.openai.com/auth";
export type OpenAICodexJwtPayload = {

View File

@@ -1,3 +1,4 @@
// OpenAI ChatGPT OAuth tests cover login, token refresh, and auth persistence.
import { beforeEach, describe, expect, it, vi } from "vitest";
type LoginOpenAICodexOAuth =

View File

@@ -1,3 +1,4 @@
// OpenAI ChatGPT OAuth helpers manage ChatGPT OAuth login and token refresh.
import { loadActivatedBundledPluginPublicSurfaceModuleSync } from "../../../plugin-sdk/facade-runtime.js";
import type { RuntimeEnv } from "../../../runtime.js";
import type { WizardPrompter } from "../../../wizard/prompts.js";

View File

@@ -1,3 +1,4 @@
// PKCE tests cover verifier and challenge generation for OAuth flows.
import { describe, expect, it } from "vitest";
import { generateOAuthState, generatePKCE } from "./pkce.js";

View File

@@ -1,3 +1,4 @@
// Overflow helpers classify provider overflow errors and retryable responses.
import type { AssistantMessage } from "../types.js";
/**