Skip to content

The open-source agent harness - the runtime layer that turns an LLM into a working agent.

Fix vercel sdk integration and add models (#33)

pranjaltrvd09fb12b57eb6
diff --git a/fern/openapi/openapi.json b/fern/openapi/openapi.json
index 8ea4ceb00..e65df335f 100644
--- a/fern/openapi/openapi.json
+++ b/fern/openapi/openapi.json
@@ -143,42 +143,6 @@
],
"type": "object"
},
- "AnthropicModelProvider": {
- "additionalProperties": false,
- "properties": {
- "auth": {
- "$ref": "#/components/schemas/ModelProviderAuth"
- },
- "base_url": {
- "description": "Optional override of the provider's default API base URL.",
- "format": "uri",
- "type": "string"
- },
- "models": {
- "items": {
- "$ref": "#/components/schemas/ModelEntry"
- },
- "minItems": 1,
- "type": "array"
- },
- "name": {
- "$ref": "#/components/schemas/ResourceName"
- },
- "type": {
- "enum": [
- "anthropic"
- ],
- "type": "string"
- }
- },
- "required": [
- "auth",
- "models",
- "type",
- "name"
- ],
- "type": "object"
- },
"ApprovalAllow": {
"properties": {
"status": {
@@ -277,6 +241,44 @@
],
"type": "object"
},
+ "CallerSuppliedModelProvider": {
+ "additionalProperties": false,
+ "properties": {
+ "auth": {
+ "$ref": "#/components/schemas/ModelProviderAuth"
+ },
+ "base_url": {
+ "description": "Base URL of the provider's API.",
+ "format": "uri",
+ "type": "string"
+ },
+ "models": {
+ "items": {
+ "$ref": "#/components/schemas/ModelEntry"
+ },
+ "minItems": 1,
+ "type": "array"
+ },
+ "name": {
+ "$ref": "#/components/schemas/ResourceName"
+ },
+ "type": {
+ "enum": [
+ "alibaba",
+ "custom"
+ ],
+ "type": "string"
+ }
+ },
+ "required": [
+ "auth",
+ "models",
+ "type",
+ "base_url",
+ "name"
+ ],
+ "type": "object"
+ },
"CancelSessionRequest": {
"properties": {},
"type": "object"
@@ -368,7 +370,12 @@
"type": {
"enum": [
"openai",
- "anthropic"
+ "anthropic",
+ "google-gemini",
+ "fireworks",
+ "zai",
+ "moonshot",
+ "alibaba"
],
"type": "string"
}
@@ -628,43 +635,6 @@
},
"type": "object"
},
- "CustomModelProvider": {
- "additionalProperties": false,
- "properties": {
- "auth": {
- "$ref": "#/components/schemas/ModelProviderAuth"
- },
- "base_url": {
- "description": "Base URL of the provider's API.",
- "format": "uri",
- "type": "string"
- },
- "models": {
- "items": {
- "$ref": "#/components/schemas/ModelEntry"
- },
- "minItems": 1,
- "type": "array"
- },
- "name": {
- "$ref": "#/components/schemas/ResourceName"
- },
- "type": {
- "enum": [
- "custom"
- ],
- "type": "string"
- }
- },
- "required": [
- "auth",
- "models",
- "type",
- "base_url",
- "name"
- ],
- "type": "object"
- },
"DaytonaSandboxProvider": {
"additionalProperties": false,
"properties": {
@@ -1761,30 +1731,15 @@
"type": "array"
}
},
- "required": [
- "context_length",
- "max_output_tokens"
- ],
"type": "object"
},
"ModelProvider": {
- "discriminator": {
- "mapping": {
- "anthropic": "#/components/schemas/AnthropicModelProvider",
- "custom": "#/components/schemas/CustomModelProvider",
- "openai": "#/components/schemas/OpenAIModelProvider"
- },
- "propertyName": "type"
- },
- "oneOf": [
- {
- "$ref": "#/components/schemas/OpenAIModelProvider"
- },
+ "anyOf": [
{
- "$ref": "#/components/schemas/AnthropicModelProvider"
+ "$ref": "#/components/schemas/WellKnownModelProvider"
},
{
- "$ref": "#/components/schemas/CustomModelProvider"
+ "$ref": "#/components/schemas/CallerSuppliedModelProvider"
}
]
},
@@ -1801,42 +1756,6 @@
],
"type": "object"
},
- "OpenAIModelProvider": {
- "additionalProperties": false,
- "properties": {
- "auth": {
- "$ref": "#/components/schemas/ModelProviderAuth"
- },
- "base_url": {
- "description": "Optional override of the provider's default API base URL.",
- "format": "uri",
- "type": "string"
- },
- "models": {
- "items": {
- "$ref": "#/components/schemas/ModelEntry"
- },
- "minItems": 1,
- "type": "array"
- },
- "name": {
- "$ref": "#/components/schemas/ResourceName"
- },
- "type": {
- "enum": [
- "openai"
- ],
- "type": "string"
- }
- },
- "required": [
- "auth",
- "models",
- "type",
- "name"
- ],
- "type": "object"
- },
"PreviousTurnIdInput": {
"anyOf": [
{
@@ -3204,6 +3123,47 @@
"content"
],
"type": "object"
+ },
+ "WellKnownModelProvider": {
+ "additionalProperties": false,
+ "properties": {
+ "auth": {
+ "$ref": "#/components/schemas/ModelProviderAuth"
+ },
+ "base_url": {
+ "description": "Optional override of the provider's default API base URL.",
+ "format": "uri",
+ "type": "string"
+ },
+ "models": {
+ "items": {
+ "$ref": "#/components/schemas/ModelEntry"
+ },
+ "minItems": 1,
+ "type": "array"
+ },
+ "name": {
+ "$ref": "#/components/schemas/ResourceName"
+ },
+ "type": {
+ "enum": [
+ "openai",
+ "anthropic",
+ "google-gemini",
+ "fireworks",
+ "zai",
+ "moonshot"
+ ],
+ "type": "string"
+ }
+ },
+ "required": [
+ "auth",
+ "models",
+ "type",
+ "name"
+ ],
+ "type": "object"
}
}
},
diff --git a/packages/frontend/src/modelProviderCatalog.ts b/packages/frontend/src/modelProviderCatalog.ts
index 7d6ab718f..8f4c6e9fb 100644
--- a/packages/frontend/src/modelProviderCatalog.ts
+++ b/packages/frontend/src/modelProviderCatalog.ts
@@ -13,8 +13,7 @@ import type {
ModelProviderCatalogEntry,
UpdateModelProviderRequest,
} from '@truefoundry/agent-ui-sdk';
-import type { TrueHarness as Harness } from 'trueharness';
-import { TrueHarnessClient } from 'trueharness';
+import { TrueHarness as Harness, TrueHarnessClient } from 'trueharness';
/** Custom-form rows omit properties; catalog rows round-trip them. */
export type UiModelEntry = ModelEntry & {
@@ -65,6 +64,17 @@ export function toUiCatalogEntry(provider: Harness.CatalogProvider): UiModelProv
};
}
+const WELL_KNOWN_TYPES: readonly string[] = Object.values(Harness.WellKnownModelProviderType);
+const CALLER_SUPPLIED_TYPES: readonly string[] = Object.values(Harness.CallerSuppliedModelProviderType);
+
+function isWellKnownType(type: string): type is Harness.WellKnownModelProviderType {
+ return WELL_KNOWN_TYPES.includes(type);
+}
+
+function isCallerSuppliedType(type: string): type is Harness.CallerSuppliedModelProviderType {
+ return CALLER_SUPPLIED_TYPES.includes(type);
+}
+
export function toHarnessModelProvider(req: {
type: string;
name: string;
@@ -74,30 +84,21 @@ export function toHarnessModelProvider(req: {
}): Harness.ModelProvider {
const models = req.models.map(toHarnessModelEntry);
const auth = { apiKey: req.apiKey };
- if (req.type === 'openai') {
- return {
- type: 'openai',
- name: req.name,
- auth,
- models,
- ...(req.baseUrl === undefined ? {} : { baseUrl: req.baseUrl }),
- };
- }
- if (req.type === 'anthropic') {
+ if (isWellKnownType(req.type)) {
return {
- type: 'anthropic',
+ type: req.type,
name: req.name,
auth,
models,
...(req.baseUrl === undefined ? {} : { baseUrl: req.baseUrl }),
};
}
- if (req.type === 'custom') {
+ if (isCallerSuppliedType(req.type)) {
if (req.baseUrl === undefined || req.baseUrl.trim() === '') {
- throw new Error('Custom model providers require a base URL');
+ throw new Error(`Model providers of type "${req.type}" require a base URL`);
}
return {
- type: 'custom',
+ type: req.type,
name: req.name,
auth,
models,
diff --git a/packages/frontend/tests/modelProviderCatalog.test.ts b/packages/frontend/tests/modelProviderCatalog.test.ts
index ceec03855..76c565def 100644
--- a/packages/frontend/tests/modelProviderCatalog.test.ts
+++ b/packages/frontend/tests/modelProviderCatalog.test.ts
@@ -1,5 +1,6 @@
import assert from 'node:assert/strict';
import { describe, it } from 'node:test';
+import { TrueHarness } from 'trueharness';
import {
toHarnessModelEntry,
toHarnessModelProvider,
@@ -158,4 +159,23 @@ describe('modelProviderCatalog mappers', () => {
/base URL/i,
);
});
+
+ // Catalog presets are copied straight into this form, so a type the API accepts but this mapper
+ // does not is a preset the user cannot save.
+ it('builds a body for every provider type the API accepts', () => {
+ const types = [
+ ...Object.values(TrueHarness.WellKnownModelProviderType),
+ ...Object.values(TrueHarness.CallerSuppliedModelProviderType),
+ ];
+ for (const type of types) {
+ const body = toHarnessModelProvider({
+ type,
+ name: type,
+ apiKey: 'sk',
+ baseUrl: 'https://example.com/v1',
+ models: [{ id: 'm', name: 'm' }],
+ });
+ assert.equal(body.type, type);
+ }
+ });
});
diff --git a/packages/harness/package.json b/packages/harness/package.json
index 3409f940d..aad2c4307 100644
--- a/packages/harness/package.json
+++ b/packages/harness/package.json
@@ -82,10 +82,14 @@
"pack:dry": "cd dist && pnpm pack --dry-run"
},
"dependencies": {
+ "@ai-sdk/alibaba": "^2.0.24",
"@ai-sdk/anthropic": "^4.0.25",
"@ai-sdk/google": "^4.0.29",
+ "@ai-sdk/moonshotai": "^3.0.25",
"@ai-sdk/openai": "^4.0.25",
"@ai-sdk/openai-compatible": "^3.0.18",
+ "@ai-sdk/provider": "^4.0.4",
+ "@ai-sdk/provider-utils": "^5.0.16",
"@daytona/sdk": "^0.190.0",
"@hono/zod-openapi": "^0.19.10",
"@modelcontextprotocol/sdk": "^1.29.0",
diff --git a/packages/harness/src/core/index.ts b/packages/harness/src/core/index.ts
index c451fcbed..38fad7aa4 100644
--- a/packages/harness/src/core/index.ts
+++ b/packages/harness/src/core/index.ts
@@ -96,7 +96,7 @@ export { ToolSet } from './mcp/ToolSet';
export type { AgentMetadata, ILLM } from './llm/ILLM';
export { ResponseFormatSchema, toOpenAIResponseFormat } from './llm/responseFormat';
export type { ResponseFormat } from './llm/responseFormat';
-export { VercelAILLM } from './llm/VercelAILLM';
+export { SUPPORTED_REASONING_EFFORTS, VERCEL_AI_PROVIDER_NAMES, VercelAILLM } from './llm/VercelAILLM';
export type { VercelAILLMConfig, VercelAIProviderConfig, VercelAIProviderName } from './llm/VercelAILLM';
// Event contracts
diff --git a/packages/harness/src/core/llm/VercelAILLM.ts b/packages/harness/src/core/llm/VercelAILLM.ts
index 9cafb6558..ee1ae0954 100644
--- a/packages/harness/src/core/llm/VercelAILLM.ts
+++ b/packages/harness/src/core/llm/VercelAILLM.ts
@@ -1,9 +1,15 @@
+import { createAlibaba } from '@ai-sdk/alibaba';
import { createAnthropic } from '@ai-sdk/anthropic';
import { createGoogle } from '@ai-sdk/google';
+import type { MoonshotAIProviderOptions } from '@ai-sdk/moonshotai';
+import { createMoonshotAI } from '@ai-sdk/moonshotai';
import { createOpenAI } from '@ai-sdk/openai';
import { createOpenAICompatible } from '@ai-sdk/openai-compatible';
+import type { JSONObject } from '@ai-sdk/provider';
+import type { ProviderOptions, ReasoningPart } from '@ai-sdk/provider-utils';
import type {
AssistantContent,
+ CallWarning,
FilePart,
FinishReason,
JSONValue,
@@ -38,37 +44,42 @@ import {
type ThinkingBlock,
} from './LLMTypes';
-/** Structurally identical to ProviderOptions from @ai-sdk/provider-utils, not re-exported by `ai`. */
-type ProviderOptions = ProviderMetadata;
-
-/** Returns true for any non-null, non-array object — narrows to an indexable record. */
+/** Narrows to an indexable record. */
function isPlainObject(v: unknown): v is Record<string, unknown> {
return typeof v === 'object' && v !== null && !Array.isArray(v);
}
-/** Structurally matches ReasoningPart from @ai-sdk/provider-utils. */
-interface ReasoningPart {
- type: 'reasoning';
- text: string;
- providerOptions?: ProviderOptions;
-}
-
-/** Providers with a dedicated code path in {@link buildLanguageModel}. */
-export type VercelAIProviderName = 'openai' | 'anthropic' | 'google-gemini' | 'custom';
+/**
+ * Providers with a case in {@link buildLanguageModel}. Canonical: the server derives the provider
+ * types it will configure from this, so anything it accepts has an adapter behind it.
+ */
+export const VERCEL_AI_PROVIDER_NAMES = [
+ 'openai',
+ 'anthropic',
+ 'google-gemini',
+ 'fireworks',
+ 'zai',
+ 'moonshot',
+ 'alibaba',
+ 'custom',
+] as const;
+
+export type VercelAIProviderName = (typeof VERCEL_AI_PROVIDER_NAMES)[number];
-/** Structural config accepted by VercelAILLM; compatible with server's ProviderConfig. */
+/**
+ * Adapter-facing config, camelCase throughout. Callers translate from the snake_case wire and
+ * storage shapes, which stay as they are because they are the published contract.
+ */
export interface VercelAIProviderConfig {
provider: VercelAIProviderName;
- /** Display name / alias. Also used as the provider model identifier when `model_id` is absent. */
+ /** Display name / alias, used for logs and errors. Often provider-qualified, so never sent. */
name: string;
- /** Provider-facing model identifier, sent instead of `name` when present. */
- model_id?: string | undefined;
+ /** Provider-facing model identifier. */
+ modelId: string;
/** Optional base URL override. Explicitly includes `undefined` for Zod-derived type compat. */
- base_url?: string | undefined;
+ baseUrl?: string | undefined;
apiKey: string;
headers: Record<string, string>;
- /** API format for the `custom` provider. Only option today; defaults when absent. */
- api_format?: 'openai-chat-completions' | undefined;
}
export interface VercelAILLMConfig {
@@ -77,16 +88,40 @@ export interface VercelAILLMConfig {
signal?: AbortSignal;
}
+/**
+ * Every OpenAI-compatible provider shares this adapter and differs only by endpoint, which the
+ * caller resolves. The provider name doubles as the `providerOptions` key, which is why
+ * {@link buildProviderOptions} can key on it directly. Fireworks and Z AI stay here on purpose:
+ * `@ai-sdk/fireworks` downgrades `json_schema` to a schema-less `json_object`, and the only Z AI
+ * package is a community one that drops replayed reasoning.
+ */
+function compatibleModel(config: VercelAIProviderConfig): LanguageModel {
+ const { provider, modelId, apiKey, headers, baseUrl } = config;
+ if (baseUrl === undefined) {
+ throw new Error(`Provider "${provider}" requires a baseUrl`);
+ }
+ const client = createOpenAICompatible({
+ name: provider,
+ baseURL: baseUrl,
+ apiKey,
+ // Without this the adapter silently downgrades json_schema to a schema-less json_object.
+ supportsStructuredOutputs: true,
+ // These endpoints omit token counts from streamed responses unless asked.
+ includeUsage: true,
+ ...(Object.keys(headers).length > 0 ? { headers } : {}),
+ });
+ return client(modelId);
+}
+
export function buildLanguageModel(config: VercelAIProviderConfig): LanguageModel {
- const { provider, name, model_id, base_url, apiKey, headers } = config;
- const modelId = model_id ?? name;
+ const { provider, modelId, baseUrl, apiKey, headers } = config;
const extraHeaders = Object.keys(headers).length > 0 ? headers : undefined;
switch (provider) {
case 'openai': {
const client = createOpenAI({
apiKey,
- ...(base_url !== undefined ? { baseURL: base_url } : {}),
+ ...(baseUrl !== undefined ? { baseURL: baseUrl } : {}),
...(extraHeaders !== undefined ? { headers: extraHeaders } : {}),
});
return client.responses(modelId);
@@ -94,7 +129,7 @@ export function buildLanguageModel(config: VercelAIProviderConfig): LanguageMode
case 'anthropic': {
const client = createAnthropic({
apiKey,
- ...(base_url !== undefined ? { baseURL: base_url } : {}),
+ ...(baseUrl !== undefined ? { baseURL: baseUrl } : {}),
...(extraHeaders !== undefined ? { headers: extraHeaders } : {}),
});
return client(modelId);
@@ -102,26 +137,36 @@ export function buildLanguageModel(config: VercelAIProviderConfig): LanguageMode
case 'google-gemini': {
const client = createGoogle({
apiKey,
- ...(base_url !== undefined ? { baseURL: base_url } : {}),
+ ...(baseUrl !== undefined ? { baseURL: baseUrl } : {}),
...(extraHeaders !== undefined ? { headers: extraHeaders } : {}),
});
return client(modelId);
}
- case 'custom': {
- if (base_url === undefined) {
- throw new Error('Provider "custom" requires a base_url in models.yaml');
+ case 'moonshot': {
+ const client = createMoonshotAI({
+ apiKey,
+ ...(baseUrl !== undefined ? { baseURL: baseUrl } : {}),
+ ...(extraHeaders !== undefined ? { headers: extraHeaders } : {}),
+ });
+ return client(modelId);
+ }
+ case 'alibaba': {
+ // Endpoints are workspace-scoped, so the package default would address the wrong tenant.
+ if (baseUrl === undefined) {
+ throw new Error(`Provider "alibaba" requires a baseUrl`);
}
- const client = createOpenAICompatible({
- name: 'custom',
- baseURL: base_url,
+ const client = createAlibaba({
apiKey,
- // Without this, @ai-sdk/openai-compatible silently downgrades json_schema requests
- // to a schema-less json_object, dropping the schema and strictJsonSchema.
- supportsStructuredOutputs: true,
+ baseURL: baseUrl,
...(extraHeaders !== undefined ? { headers: extraHeaders } : {}),
});
return client(modelId);
}
+ case 'fireworks':
+ case 'zai':
+ case 'custom': {
+ return compatibleModel(config);
+ }
default: {
const _exhaustive: never = provider;
throw new Error(`Unknown provider "${String(_exhaustive)}"`);
@@ -156,9 +201,8 @@ export function normalizeUsage(usage: {
}
/**
- * The SDK's standardized cross-provider `streamText({ reasoning })` setting, distinct from the
- * `providerOptions` bucket. Derived from `LanguageModelCallOptions` so it stays in sync with the
- * SDK's own definition rather than being a hand-maintained mirror.
+ * The cross-provider `streamText({ reasoning })` setting, distinct from `providerOptions`. Derived
+ * from the SDK's own type rather than mirrored by hand.
*/
type ReasoningLevel = NonNullable<LanguageModelCallOptions['reasoning']>;
@@ -177,21 +221,53 @@ function isReasoningLevel(v: string): v is ReasoningLevel {
}
/**
- * Maps a harness `reasoning_effort` to the SDK's standardized `reasoning` setting. Only
- * `google-gemini` needs this — `@ai-sdk/google` derives its `thinkingConfig` from it, since it has
- * no `providerOptions.google.reasoningEffort` lever like openai/anthropic/custom do.
+ * Efforts models advertise that the SDK's cross-provider union cannot express. `xhigh` is its
+ * ceiling, so `max` rides in as `xhigh`. Anthropic's adapter raises that back to `max` for models
+ * without an `xhigh` level; everyone else receives `xhigh` as sent, which for models offering both
+ * levels — the gpt-5.6 family — is one step below what was asked for.
*/
-export function toReasoningLevel({
- provider,
- reasoningEffort,
-}: {
- provider: VercelAIProviderName;
- reasoningEffort: string | undefined;
-}): ReasoningLevel | undefined {
- if (provider !== 'google-gemini' || reasoningEffort === undefined || !isReasoningLevel(reasoningEffort)) {
+const EFFORT_ALIASES: Readonly<Record<string, ReasoningLevel>> = { max: 'xhigh' };
+
+/**
+ * What a model may advertise in `reasoning_efforts`. Anything else reaches `toReasoningLevel`,
+ * resolves to `undefined`, and runs at the provider default without a word of complaint.
+ */
+export const SUPPORTED_REASONING_EFFORTS: readonly string[] = [...REASONING_LEVELS, ...Object.keys(EFFORT_ALIASES)];
+
+/**
+ * Every provider takes the effort through the top-level `reasoning` setting, leaving the adapters
+ * to translate it: an effort string for OpenAI-shaped APIs, a per-model thinking shape for
+ * Anthropic, `thinkingLevel` or `thinkingBudget` for Gemini. Reasoning-related `providerOptions`
+ * would override this rather than merge with it, so nothing here sets them.
+ */
+export function toReasoningLevel(reasoningEffort: string | undefined): ReasoningLevel | undefined {
+ if (reasoningEffort === undefined) {
return undefined;
}
- return reasoningEffort;
+ const aliased = EFFORT_ALIASES[reasoningEffort];
+ if (aliased !== undefined) {
+ return aliased;
+ }
+ return isReasoningLevel(reasoningEffort) ? reasoningEffort : undefined;
+}
+
+/**
+ * Providers surface stream errors as plain objects as often as Errors; `String()` on those
+ * yields "[object Object]" and loses the only description of what went wrong.
+ */
+export function describeStreamError(raw: unknown): string {
+ if (typeof raw !== 'object' || raw === null) {
+ return String(raw);
+ }
+ const message: unknown = Reflect.get(raw, 'message');
+ if (typeof message === 'string' && message.length > 0) {
+ return message;
+ }
+ try {
+ return JSON.stringify(raw);
+ } catch {
+ return `unserialisable provider error (${Object.keys(raw).join(', ')})`;
+ }
}
export function mapFinishReason(reason: FinishReason): RawAssistantMessageWithUsage['finish_reason'] {
@@ -215,35 +291,27 @@ export function mapFinishReason(reason: FinishReason): RawAssistantMessageWithUs
}
}
-/** Opaque alias — each provider bucket is an arbitrary JSON object from the request body. */
-type JSONObject = Record<string, JSONValue | undefined>;
-
-/**
- * Reads a single top-level field from rawBody by snake_case key and returns it as-is.
- * rawBody originates from a parsed JSON request body, so any value present is a valid JSONValue.
- */
-function readBodyField(rawBody: unknown, key: string): JSONValue | undefined {
+/** `rawBody` is a parsed JSON request body, so any value present is a valid JSONValue. */
+function readBodyField({ rawBody, key }: { rawBody: unknown; key: string }): JSONValue | undefined {
const val: unknown = Reflect.get(Object(rawBody), key);
return val !== undefined ? (val as JSONValue) : undefined;
}
-const ANTHROPIC_BUDGET_BY_EFFORT: Record<string, number> = { low: 1024, medium: 8192, high: 32768 };
-
-function openaiProviderOptions(
- rawBody: unknown,
- reasoningEffort: string | undefined,
- strictJsonSchema: boolean | undefined,
-): JSONObject {
- const serviceTier = readBodyField(rawBody, 'service_tier');
- const user = readBodyField(rawBody, 'user');
- const promptCacheKey = readBodyField(rawBody, 'prompt_cache_key');
- const parallelToolCalls = readBodyField(rawBody, 'parallel_tool_calls');
- // Disables server-side storage and requests the encrypted reasoning token so multi-turn
- // conversations can replay reasoning statelessly; harmless no-op for non-reasoning models.
+function openaiProviderOptions({
+ rawBody,
+ strictJsonSchema,
+}: {
+ rawBody: unknown;
+ strictJsonSchema: boolean | undefined;
+}): JSONObject {
+ const serviceTier = readBodyField({ rawBody, key: 'service_tier' });
+ const user = readBodyField({ rawBody, key: 'user' });
+ const promptCacheKey = readBodyField({ rawBody, key: 'prompt_cache_key' });
+ const parallelToolCalls = readBodyField({ rawBody, key: 'parallel_tool_calls' });
+ // No server-side storage, and request the encrypted reasoning token so replay stays stateless.
return {
store: false,
include: ['reasoning.encrypted_content'],
- ...(reasoningEffort !== undefined ? { reasoningEffort } : {}),
...(strictJsonSchema !== undefined ? { strictJsonSchema } : {}),
...(serviceTier !== undefined ? { serviceTier } : {}),
...(user !== undefined ? { user } : {}),
@@ -252,23 +320,57 @@ function openaiProviderOptions(
};
}
-function anthropicProviderOptions(rawBody: unknown, reasoningEffort: string | undefined): JSONObject | undefined {
- const cacheControl = readBodyField(rawBody, 'cache_control');
- const disableParallelToolUse = readBodyField(rawBody, 'disable_parallel_tool_use');
+/**
+ * Forwards but never pins `thinking` and `effort`: both replace the adapter's per-model resolution
+ * and no single value fits every model. This is the caller's only route to disabling thinking, or to
+ * the `display: 'summarized'` that makes Claude 5 return reasoning text instead of an empty block.
+ */
+function anthropicProviderOptions(rawBody: unknown): JSONObject | undefined {
+ const cacheControl = readBodyField({ rawBody, key: 'cache_control' });
+ const disableParallelToolUse = readBodyField({ rawBody, key: 'disable_parallel_tool_use' });
+ const thinking = readBodyField({ rawBody, key: 'thinking' });
+ const effort = readBodyField({ rawBody, key: 'effort' });
const opts: JSONObject = {
- ...(reasoningEffort !== undefined
- ? { thinking: { type: 'enabled', budgetTokens: ANTHROPIC_BUDGET_BY_EFFORT[reasoningEffort] ?? 8192 } }
- : {}),
...(cacheControl !== undefined ? { cacheControl } : {}),
...(disableParallelToolUse !== undefined ? { disableParallelToolUse } : {}),
+ ...(thinking !== undefined ? { thinking } : {}),
+ ...(effort !== undefined ? { effort } : {}),
};
return Object.keys(opts).length > 0 ? opts : undefined;
}
-function googleProviderOptions(rawBody: unknown): JSONObject | undefined {
- const safetySettings = readBodyField(rawBody, 'safety_settings');
- const thinkingConfig = readBodyField(rawBody, 'thinking_config');
- const cachedContent = readBodyField(rawBody, 'cached_content');
+/**
+ * Gemini returns thought summaries only when `includeThoughts` is set, and `@ai-sdk/google` omits it
+ * — without this the model bills reasoning tokens and returns none. The effort itself rides in the
+ * top-level `reasoning` setting. An explicit `thinking_config` in the request body wins.
+ */
+function googleGeminiThinkingConfig({
+ rawBody,
+ reasoningRequested,
+}: {
+ rawBody: unknown;
+ reasoningRequested: boolean;
+}): JSONValue | undefined {
+ const fromBody = readBodyField({ rawBody, key: 'thinking_config' });
+ if (!reasoningRequested) {
+ return fromBody;
+ }
+ if (typeof fromBody === 'object' && fromBody !== null && !Array.isArray(fromBody)) {
+ return { includeThoughts: true, ...fromBody };
+ }
+ return { includeThoughts: true };
+}
+
+function googleGeminiProviderOptions({
+ rawBody,
+ reasoningRequested,
+}: {
+ rawBody: unknown;
+ reasoningRequested: boolean;
+}): JSONObject | undefined {
+ const safetySettings = readBodyField({ rawBody, key: 'safety_settings' });
+ const thinkingConfig = googleGeminiThinkingConfig({ rawBody, reasoningRequested });
+ const cachedContent = readBodyField({ rawBody, key: 'cached_content' });
const opts: JSONObject = {
...(safetySettings !== undefined ? { safetySettings } : {}),
...(thinkingConfig !== undefined ? { thinkingConfig } : {}),
@@ -277,26 +379,59 @@ function googleProviderOptions(rawBody: unknown): JSONObject | undefined {
return Object.keys(opts).length > 0 ? opts : undefined;
}
-function customProviderOptions(
- rawBody: unknown,
- reasoningEffort: string | undefined,
- strictJsonSchema: boolean | undefined,
-): JSONObject | undefined {
- const parallelToolCalls = readBodyField(rawBody, 'parallel_tool_calls');
+/**
+ * Moonshot is the only adapter that accepts `max` directly, so it escapes the `xhigh` alias every
+ * other provider settles for. `thinking` and `reasoning_history` are forwarded but never pinned:
+ * they are the caller's route to turning thinking off, or to replaying it verbatim.
+ */
+function moonshotProviderOptions({
+ rawBody,
+ reasoningEffort,
+}: {
+ rawBody: unknown;
+ reasoningEffort: string | undefined;
+}): JSONObject | undefined {
+ // Typed against the package so a change to the literal it accepts breaks the build, not the call.
+ const effort: Pick<MoonshotAIProviderOptions, 'reasoningEffort'> =
+ reasoningEffort === 'max' ? { reasoningEffort: 'max' } : {};
+ const thinking = readBodyField({ rawBody, key: 'thinking' });
+ const reasoningHistory = readBodyField({ rawBody, key: 'reasoning_history' });
const opts: JSONObject = {
- ...(reasoningEffort !== undefined ? { reasoningEffort } : {}),
- ...(strictJsonSchema !== undefined ? { strictJsonSchema } : {}),
+ ...effort,
+ ...(thinking !== undefined ? { thinking } : {}),
+ ...(reasoningHistory !== undefined ? { reasoningHistory } : {}),
+ };
+ return Object.keys(opts).length > 0 ? opts : undefined;
+}
+
+/** Qwen resolves the top-level effort into a thinking budget; these override that resolution. */
+function alibabaProviderOptions(rawBody: unknown): JSONObject | undefined {
+ const enableThinking = readBodyField({ rawBody, key: 'enable_thinking' });
+ const thinkingBudget = readBodyField({ rawBody, key: 'thinking_budget' });
+ const parallelToolCalls = readBodyField({ rawBody, key: 'parallel_tool_calls' });
+ const opts: JSONObject = {
+ ...(enableThinking !== undefined ? { enableThinking } : {}),
+ ...(thinkingBudget !== undefined ? { thinkingBudget } : {}),
...(parallelToolCalls !== undefined ? { parallelToolCalls } : {}),
};
return Object.keys(opts).length > 0 ? opts : undefined;
}
/**
- * Builds provider-specific options for reasoning/thinking budget, structured-output strictness,
- * and any extra fields passed through from the request body via `rawBody`.
- *
- * `rawBody` is the raw request body; provider-specific fields (e.g. `cache_control`,
- * `service_tier`, `safety_settings`) are forwarded by snake_case key with no further validation.
+ * `parallel_tool_calls` is deliberately not forwarded: `OpenAICompatibleProviderOptions` has no
+ * field for it, so it never reached the wire.
+ */
+function compatibleProviderOptions({
+ strictJsonSchema,
+}: {
+ strictJsonSchema: boolean | undefined;
+}): JSONObject | undefined {
+ return strictJsonSchema !== undefined ? { strictJsonSchema } : undefined;
+}
+
+/**
+ * Provider-specific fields in `rawBody` (`cache_control`, `service_tier`, `safety_settings`, …)
+ * are forwarded by snake_case key with no validation.
*/
export function buildProviderOptions({
config,
@@ -305,31 +440,36 @@ export function buildProviderOptions({
rawBody,
}: {
config: VercelAIProviderConfig;
+ /** The requested effort, which rides in the top-level `reasoning` setting for every provider. */
reasoningEffort: string | undefined;
structuredOutputSpec: StructuredOutputSpec;
rawBody: unknown;
}): ProviderOptions {
const strictJsonSchema = structuredOutputSpec.mode === 'json_schema' ? structuredOutputSpec.strict : undefined;
if (config.provider === 'openai') {
- return { openai: openaiProviderOptions(rawBody, reasoningEffort, strictJsonSchema) };
+ return { openai: openaiProviderOptions({ rawBody, strictJsonSchema }) };
} else if (config.provider === 'anthropic') {
- const anthropic = anthropicProviderOptions(rawBody, reasoningEffort);
+ const anthropic = anthropicProviderOptions(rawBody);
return anthropic !== undefined ? { anthropic } : {};
} else if (config.provider === 'google-gemini') {
- const google = googleProviderOptions(rawBody);
+ const google = googleGeminiProviderOptions({ rawBody, reasoningRequested: reasoningEffort !== undefined });
return google !== undefined ? { google } : {};
+ } else if (config.provider === 'moonshot') {
+ // The package names its options key after itself, not after the provider.
+ const moonshotai = moonshotProviderOptions({ rawBody, reasoningEffort });
+ return moonshotai !== undefined ? { moonshotai } : {};
+ } else if (config.provider === 'alibaba') {
+ const alibaba = alibabaProviderOptions(rawBody);
+ return alibaba !== undefined ? { alibaba } : {};
} else {
- // 'custom' — @ai-sdk/openai-compatible registers under the name 'custom'.
- // this will have to become api_format specific in the future.
- const custom = customProviderOptions(rawBody, reasoningEffort, strictJsonSchema);
- return custom !== undefined ? { custom } : {};
+ // The remaining providers all share the compatible adapter, which reads its options from a key
+ // matching the `name` it was built with — the provider name itself.
+ const compatible = compatibleProviderOptions({ strictJsonSchema });
+ return compatible !== undefined ? { [config.provider]: compatible } : {};
}
}
-/**
- * Prefers `max_completion_tokens`, falling back to the deprecated `max_tokens` (not part of the
- * OpenAI SDK type, read via `Reflect.get` to avoid an unsafe-member-access lint error).
- */
+/** Prefers `max_completion_tokens`, falling back to the deprecated `max_tokens`. */
export function resolveMaxOutputTokens(
body: Pick<ChatCompletionCreateParamsStreaming, 'max_completion_tokens'>,
): number | undefined {
@@ -337,20 +477,13 @@ export function resolveMaxOutputTokens(
return typeof limit === 'number' ? limit : undefined;
}
-/**
- * Parses the MIME type from a data URI (`data:<mime>;base64,...`).
- * Returns `undefined` when the URI is not a data URI or has no MIME segment.
- */
+/** Parses the MIME type from a data URI (`data:<mime>;base64,...`). */
export function parseMimeFromDataUri(uri: string): string | undefined {
const match = /^data:([^;,]+)/.exec(uri);
return match?.[1];
}
-/**
- * Builds a Vercel AI SDK FilePart from an OpenAI-format file content part.
- * Returns `undefined` when the part carries no usable data (e.g. file_id only,
- * which requires a server-side lookup we don't support here).
- */
+/** Returns `undefined` for parts with no inline data, e.g. `file_id` only. */
export function toFilePart(file: {
file_data?: string | undefined;
filename?: string | undefined;
@@ -378,8 +511,7 @@ export function toUserContent(content: string | ChatCompletionContentPart[]): Us
continue;
}
if (part.type === 'image_url') {
- // Map image URLs/data-URIs as FilePart with image/* mediaType.
- // ImagePart ({ type: 'image' }) is deprecated in favour of FilePart.
+ // ImagePart is deprecated in favour of FilePart.
const url = part.image_url.url;
const mediaType = parseMimeFromDataUri(url) ?? 'image/*';
parts.push({ type: 'file', data: url, mediaType });
@@ -399,22 +531,17 @@ export function toUserContent(content: string | ChatCompletionContentPart[]): Us
}
/**
- * Converts an assistant ChatCompletionMessageParam → AssistantModelMessage for multi-turn replay.
+ * Converts an assistant message to the SDK shape for multi-turn replay.
*
- * The harness attaches `thinking_blocks` to assistant messages at runtime (via Object.assign in
- * AgentThread) for reasoning replay. Since `ChatCompletionMessageParam` does not declare this
- * field in its TypeScript type, we read it via Reflect.get so no assertion is needed.
+ * Each adapter reads its reasoning-replay token from a different key, and a mismatch fails
+ * silently: the adapter drops the reasoning part and the model loses its chain.
+ * - `'openai'` → `openai.reasoningEncryptedContent`
+ * - `'anthropic'` → `anthropic.signature`
+ * - `'google-gemini'` → per-tool-call `google.thoughtSignature`, no standalone reasoning block
+ * - `'custom'` → OpenAI-compatible ignores providerOptions, so the token has nowhere to go
*
- * `provider` is used to place the opaque reasoning-replay token under the correct providerOptions key:
- * - `'openai'` / `'custom'` → `providerOptions[provider].encryptedContent` (Responses API)
- * - `'anthropic'` → `providerOptions.anthropic.signature`
- * - `'google-gemini'` → no standalone reasoning block; replay token is per-tool-call (see below)
- *
- * Independently of `provider`, a tool call's own `provider_specific_fields.thought_signature`
- * (Gemini attaches its thinking signature to the function-call part itself, not a separate
- * reasoning block) is placed at `providerOptions.google.thoughtSignature` on the `ToolCallPart` —
- * the convention `@ai-sdk/google` reads back out when replaying a tool call. Harmless no-op for
- * other providers, since this field is never populated for them.
+ * Alibaba gets no reasoning at all: its adapter appends replayed thinking to the visible answer,
+ * and Qwen issues no signature, so there is nothing to lose by leaving it out.
*/
export function toAssistantModelMessage({
msg,
@@ -425,10 +552,10 @@ export function toAssistantModelMessage({
}): ModelMessage {
const parts: AssistantContent = [];
+ // `thinking_blocks` is attached at runtime by AgentThread and absent from the OpenAI SDK type.
const rawThinking: unknown = Reflect.get(msg, 'thinking_blocks');
- if (Array.isArray(rawThinking)) {
- // Widen any[] → unknown[] so TypeScript's in-guards can narrow safely
- // without triggering no-unsafe-member-access on every property access.
+ if (Array.isArray(rawThinking) && provider !== 'alibaba') {
+ // Widen any[] → unknown[] so the in-guards below narrow safely.
const blocks: unknown[] = rawThinking;
for (const tb of blocks) {
if (
@@ -441,10 +568,10 @@ export function toAssistantModelMessage({
) {
const signature = 'signature' in tb && typeof tb.signature === 'string' ? tb.signature : undefined;
let reasoningProviderOptions: ProviderOptions | undefined;
- if (signature !== undefined && provider !== 'google-gemini') {
- if (provider === 'openai' || provider === 'custom') {
- reasoningProviderOptions = { [provider]: { encryptedContent: signature } };
- } else {
+ if (signature !== undefined) {
+ if (provider === 'openai') {
+ reasoningProviderOptions = { openai: { reasoningEncryptedContent: signature } };
+ } else if (provider === 'anthropic') {
reasoningProviderOptions = { anthropic: { signature } };
}
}
@@ -508,25 +635,15 @@ export function toAssistantModelMessage({
};
}
-/**
- * Converts OpenAI-format messages to Vercel AI SDK ModelMessage[].
- *
- * Builds a toolCallId → toolName lookup from assistant messages first so that
- * tool result messages (which only carry toolCallId) can include the name
- * required by ToolResultPart.
- *
- * `provider` is threaded into assistant message conversion so that reasoning
- * replay tokens are placed under the correct providerOptions key.
- */
export interface ConvertedMessages {
instructions: string | undefined;
messages: ModelMessage[];
}
/**
- * Splits an OpenAI message list into Vercel AI SDK format. System messages are extracted into
- * `instructions` since the SDK v7 no longer accepts `{ role: 'system' }` in the messages array.
- * Builds a toolCallId → toolName lookup first, since tool result messages only carry the id.
+ * System messages are extracted into `instructions`, since SDK v7 no longer accepts
+ * `{ role: 'system' }` in the messages array. The toolCallId → toolName lookup is built first
+ * because tool result messages carry only the id.
*/
export function convertMessages({
messages,
@@ -597,8 +714,7 @@ export function convertTools(tools: ChatCompletionTool[] | undefined): ToolSet |
}
/**
- * Normalized structured-response mode, derived from an OpenAI-format `response_format`. Kept as
- * plain data rather than a Vercel AI SDK `Output` instance, since `Output` isn't a nameable
+ * Kept as plain data rather than an SDK `Output` instance, since `Output` isn't a nameable
* exported type from `ai` — see `buildOutput`.
*/
export type StructuredOutputSpec =
@@ -633,10 +749,7 @@ export function toStructuredOutputSpec(
};
}
-/**
- * Builds the Vercel AI SDK `Output` spec for `streamText`. Not exported: `Output`'s type isn't
- * nameable outside `ai`, so an exported function can't declare it as a return type.
- */
+/** Not exported: `Output`'s type isn't nameable outside `ai`, so a return type can't be declared. */
function buildOutput(spec: StructuredOutputSpec) {
switch (spec.mode) {
case 'text':
@@ -657,10 +770,8 @@ function buildOutput(spec: StructuredOutputSpec) {
}
/**
- * Pure-data subset of `streamText(...)`'s call args. Composes `LanguageModelCallOptions` for the
- * model settings so new SDK settings are picked up automatically. Uses `?` (omitted keys) rather
- * than this file's usual explicit `| undefined`, since these fields cross directly into
- * `streamText`'s own optional-property call signature under `exactOptionalPropertyTypes`.
+ * Pure-data subset of `streamText(...)`'s call args. Uses `?` rather than this file's usual
+ * explicit `| undefined`, to match `streamText`'s own signature under `exactOptionalPropertyTypes`.
*/
export type StreamTextArgs = LanguageModelCallOptions & {
model: LanguageModel;
@@ -673,15 +784,9 @@ export type StreamTextArgs = LanguageModelCallOptions & {
};
/**
- * Builds the pure-data subset of `streamText(...)`'s call args from already-computed
- * translations. Exported so the final wiring itself — not just the sub-functions that feed it
- * (`convertMessages`, `convertTools`, `buildProviderOptions`, `toReasoningLevel`,
- * `resolveMaxOutputTokens`) — is directly unit-testable: a value computed correctly but never
- * spread into this object wouldn't be caught by testing those sub-functions alone.
- *
- * `output` (from `buildOutput`) is deliberately excluded and spread separately by the caller:
- * its type isn't nameable outside `ai` (see `buildOutput`), so including it here would make this
- * exported function's return type unnameable too.
+ * Exported so the final wiring is unit-testable: a value computed correctly but never spread into
+ * this object would pass every sub-function test. `output` is excluded and spread by the caller,
+ * since its unnameable type would make this function's return type unnameable too.
*/
export function buildStreamTextArgs(input: {
model: LanguageModel;
@@ -746,6 +851,56 @@ interface ToolCallState {
thoughtSignature: string | undefined;
}
+/**
+ * Copies the reasoning-replay token onto the block, scanning every provider namespace since only
+ * the active one is populated. Providers disagree on where it arrives: OpenAI attaches it to
+ * `reasoning-end`, Anthropic to a text-less `reasoning-delta`. Missing either silently loses the
+ * chain, since unsigned thinking blocks are dropped on replay.
+ */
+function applyReasoningSignature({
+ block,
+ providerMetadata,
+}: {
+ block: ThinkingBlock;
+ providerMetadata: ProviderMetadata | undefined;
+}): void {
+ if (providerMetadata === undefined) {
+ return;
+ }
+ for (const meta of Object.values(providerMetadata)) {
+ if ('reasoningEncryptedContent' in meta && typeof meta['reasoningEncryptedContent'] === 'string') {
+ block.signature = meta['reasoningEncryptedContent'];
+ return;
+ }
+ if ('signature' in meta && typeof meta['signature'] === 'string') {
+ block.signature = meta['signature'];
+ return;
+ }
+ }
+}
+
+/**
+ * Where the SDK reports what it changed about our request: an effort a model cannot honour and so
+ * was coerced, a setting the provider ignored. Nothing else surfaces these.
+ */
+export function describeCallWarning(warning: CallWarning): string {
+ switch (warning.type) {
+ case 'unsupported':
+ case 'compatibility':
+ return warning.details !== undefined
+ ? `${warning.type}: ${warning.feature} (${warning.details})`
+ : `${warning.type}: ${warning.feature}`;
+ case 'deprecated':
+ return `deprecated: ${warning.setting} - ${warning.message}`;
+ case 'other':
+ return `other: ${warning.message}`;
+ default: {
+ const _exhaustive: never = warning;
+ throw new Error(`Unknown call warning: ${JSON.stringify(_exhaustive)}`);
+ }
+ }
+}
+
/** Synthetic chunk fields shared by every chunk emitted for a single stream. */
interface ChunkMeta {
id: string;
@@ -754,9 +909,8 @@ interface ChunkMeta {
}
/**
- * Converts a Vercel AI SDK stream of `TextStreamPart`s into harness-format
- * `ExtendedChatCompletionChunk`s, returning the final aggregated assistant message on completion.
- * Takes a plain `AsyncIterable` so hand-built fixtures work in tests too.
+ * Converts an SDK stream into harness chunks, returning the aggregated assistant message.
+ * Takes a plain `AsyncIterable` so hand-built fixtures work in tests.
*/
export async function* mapStreamToChunks({
stream,
@@ -805,9 +959,14 @@ export async function* mapStreamToChunks({
}
case 'reasoning-delta': {
- if (currentThinkingBlock !== null) {
- currentThinkingBlock.thinking += part.text;
+ // A delta with no preceding `reasoning-start` would otherwise drop the block and its
+ // signature, breaking replay while the text still streams out.
+ if (currentThinkingBlock === null) {
+ currentThinkingBlock = { type: 'thinking', thinking: '' };
+ accumulatedThinking.push(currentThinkingBlock);
}
+ currentThinkingBlock.thinking += part.text;
+ applyReasoningSignature({ block: currentThinkingBlock, providerMetadata: part.providerMetadata });
yield {
...makeBase(),
choices: [
@@ -826,21 +985,8 @@ export async function* mapStreamToChunks({
}
case 'reasoning-end': {
- if (currentThinkingBlock !== null && part.providerMetadata !== undefined) {
- // Scan all provider namespace values — only the active provider's key will
- // be populated, so this is provider-agnostic without coupling to replayKey.
- // OpenAI Responses API → meta.reasoningEncryptedContent
- // Anthropic → meta.signature
- for (const meta of Object.values(part.providerMetadata)) {
- if ('reasoningEncryptedContent' in meta && typeof meta['reasoningEncryptedContent'] === 'string') {
- currentThinkingBlock.signature = meta['reasoningEncryptedContent'];
- break;
- }
- if ('signature' in meta && typeof meta['signature'] === 'string') {
- currentThinkingBlock.signature = meta['signature'];
- break;
- }
- }
+ if (currentThinkingBlock !== null) {
+ applyReasoningSignature({ block: currentThinkingBlock, providerMetadata: part.providerMetadata });
}
currentThinkingBlock = null;
break;
@@ -848,10 +994,7 @@ export async function* mapStreamToChunks({
case 'tool-input-start': {
const idx = nextToolIndex++;
- // @ai-sdk/google sets providerMetadata.google.thoughtSignature on tool-input-start for
- // Gemini thinking models. Capture it here so the finalized tool_call can carry
- // provider_specific_fields.thought_signature — the field toAssistantModelMessage reads
- // when replaying tool calls in multi-turn conversations.
+ // Gemini's replay token arrives here, and only here, for thinking models.
const googleMeta = part.providerMetadata?.['google'];
const thoughtSignature =
googleMeta !== undefined && typeof googleMeta['thoughtSignature'] === 'string'
@@ -889,17 +1032,19 @@ export async function* mapStreamToChunks({
case 'tool-input-delta': {
const state = toolCallStates.get(part.id);
- if (state !== undefined) {
- state.arguments += part.delta;
+ // With no matching `tool-input-start` there is no index to attribute this to; emitting it
+ // anyway would append the arguments to an unrelated tool call.
+ if (state === undefined) {
+ break;
}
- const idx = state?.index ?? 0;
+ state.arguments += part.delta;
yield {
...makeBase(),
choices: [
{
index: 0,
delta: {
- tool_calls: [{ index: idx, function: { arguments: part.delta } }],
+ tool_calls: [{ index: state.index, function: { arguments: part.delta } }],
},
finish_reason: null,
logprobs: null,
@@ -929,10 +1074,16 @@ export async function* mapStreamToChunks({
case 'error': {
const raw = part.error;
- const err = raw instanceof Error ? raw : new Error(String(raw));
+ const err = raw instanceof Error ? raw : new Error(describeStreamError(raw));
throw new Error('LLM stream error', { cause: err });
}
+ case 'abort': {
+ const aborted = new Error('LLM stream aborted');
+ aborted.name = 'AbortError';
+ throw aborted;
+ }
+
case 'start':
case 'text-start':
case 'text-end':
@@ -949,7 +1100,6 @@ export async function* mapStreamToChunks({
case 'tool-approval-response':
case 'start-step':
case 'finish':
- case 'abort':
case 'raw':
// Structural/bookkeeping events — no harness chunk is emitted for these.
break;
@@ -1014,7 +1164,7 @@ export class VercelAILLM implements ILLM {
structuredOutputSpec,
rawBody: body,
});
- const reasoning = toReasoningLevel({ provider: providerConfig.provider, reasoningEffort });
+ const reasoning = toReasoningLevel(reasoningEffort);
// top_k is injected by AgentThread via Object.assign; not in the SDK type.
const rawTopK: unknown = Reflect.get(body, 'top_k');
@@ -1051,6 +1201,23 @@ export class VercelAILLM implements ILLM {
throw error;
}
+ // Detached: warnings resolve at stream start, and a pending or rejected promise must never
+ // stall the stream. Stream failures are reported by the error paths below.
+ void streamResult.warnings.then(
+ warnings => {
+ if (warnings !== undefined && warnings.length > 0) {
+ this.logger.warn('Provider adjusted the request', {
+ model: body.model,
+ warnings: warnings.map(describeCallWarning),
+ });
+ }
+ },
+ (reason: unknown) => {
+ // Rejects with the same failure the stream throws, which the error paths below already log.
+ this.logger.debug('Provider warnings unavailable', extractErrorLogFields(reason));
+ },
+ );
+
// Synthetic chunk fields; id is unique per stream instance.
const chunkMeta: ChunkMeta = {
id: `vc-${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 7)}`,
diff --git a/packages/harness/tests/core/llm/VercelAILLM.messages.test.ts b/packages/harness/tests/core/llm/VercelAILLM.messages.test.ts
index 412595f65..85eb37b4d 100644
--- a/packages/harness/tests/core/llm/VercelAILLM.messages.test.ts
+++ b/packages/harness/tests/core/llm/VercelAILLM.messages.test.ts
@@ -174,7 +174,7 @@ describe('toAssistantModelMessage', () => {
expect(toolCallPart?.input).toEqual({});
});
- it('places thinking_blocks as reasoning parts — openai provider → encryptedContent', () => {
+ it('places thinking_blocks as reasoning parts — openai provider → reasoningEncryptedContent', () => {
const msg: Extract<ChatCompletionMessageParam, { role: 'assistant' }> = {
role: 'assistant',
content: null,
@@ -186,7 +186,8 @@ describe('toAssistantModelMessage', () => {
p => p.type === 'reasoning',
);
expect(reasoningPart?.text).toBe('step one');
- expect(reasoningPart?.providerOptions).toEqual({ openai: { encryptedContent: 'sig-openai' } });
+ // Key name is the one @ai-sdk/openai reads; anything else and it silently drops the part.
+ expect(reasoningPart?.providerOptions).toEqual({ openai: { reasoningEncryptedContent: 'sig-openai' } });
});
it('places thinking_blocks as reasoning parts — anthropic provider → signature', () => {
@@ -203,7 +204,7 @@ describe('toAssistantModelMessage', () => {
expect(reasoningPart?.providerOptions).toEqual({ anthropic: { signature: 'sig-ant' } });
});
- it('places thinking_blocks as reasoning parts — custom provider → encryptedContent', () => {
+ it('places thinking_blocks as reasoning parts — custom provider carries no replay token', () => {
const msg: Extract<ChatCompletionMessageParam, { role: 'assistant' }> = {
role: 'assistant',
content: null,
@@ -211,10 +212,12 @@ describe('toAssistantModelMessage', () => {
Reflect.set(msg, 'thinking_blocks', [{ type: 'thinking', thinking: 'step', signature: 'sig-gen' }]);
const result = toAssistantModelMessage({ msg: msg, provider: 'custom' });
- const reasoningPart = (result.content as Array<{ type: string; providerOptions?: unknown }>).find(
+ const reasoningPart = (result.content as Array<{ type: string; text?: string; providerOptions?: unknown }>).find(
p => p.type === 'reasoning',
);
- expect(reasoningPart?.providerOptions).toEqual({ custom: { encryptedContent: 'sig-gen' } });
+ // OpenAI-compatible replays reasoning as `reasoning_content` text and ignores providerOptions.
+ expect(reasoningPart?.text).toBe('step');
+ expect(reasoningPart?.providerOptions).toBeUndefined();
});
it('omits providerOptions on reasoning part when provider is google-gemini', () => {
diff --git a/packages/harness/tests/core/llm/VercelAILLM.model.test.ts b/packages/harness/tests/core/llm/VercelAILLM.model.test.ts
index cea249443..3d412cc61 100644
--- a/packages/harness/tests/core/llm/VercelAILLM.model.test.ts
+++ b/packages/harness/tests/core/llm/VercelAILLM.model.test.ts
@@ -15,53 +15,45 @@ import {
function makeConfig(
overrides: Partial<VercelAIProviderConfig> & { provider: VercelAIProviderConfig['provider'] },
): VercelAIProviderConfig {
- return { name: 'test', apiKey: 'sk-test', headers: {}, ...overrides };
+ return { name: 'test', modelId: 'test-model', apiKey: 'sk-test', headers: {}, ...overrides };
}
// ─────────── buildLanguageModel ───────────
describe('buildLanguageModel', () => {
- it('throws for custom provider without base_url', () => {
- const config = makeConfig({ provider: 'custom' });
- expect(() => buildLanguageModel(config)).toThrow('base_url');
+ it('builds the providers whose adapter carries its own endpoint', () => {
+ for (const provider of ['openai', 'anthropic', 'google-gemini', 'moonshot'] as const) {
+ expect(buildLanguageModel(makeConfig({ provider }))).toBeDefined();
+ }
});
- it('throws for unknown provider string (exhaustive default branch)', () => {
- const badConfig = JSON.parse('{"provider":"unknown-provider","name":"x","apiKey":"k","headers":{}}');
- expect(() => buildLanguageModel(badConfig)).toThrow('Unknown provider');
- });
-
- it('constructs openai model without throwing', () => {
- const model = buildLanguageModel(makeConfig({ provider: 'openai' }));
- expect(model).toBeDefined();
- });
-
- it('constructs anthropic model without throwing', () => {
- const model = buildLanguageModel(makeConfig({ provider: 'anthropic' }));
- expect(model).toBeDefined();
+ // The compatible providers take their endpoint from the caller, which the server resolves from
+ // its own defaults. Throwing here beats letting the adapter build a request against no host.
+ it('demands a baseUrl from every compatible provider', () => {
+ for (const provider of ['fireworks', 'zai', 'custom'] as const) {
+ expect(() => buildLanguageModel(makeConfig({ provider }))).toThrow('baseUrl');
+ const model: unknown = buildLanguageModel(makeConfig({ provider, baseUrl: 'http://localhost:11434/v1' }));
+ if (typeof model !== 'object' || model === null) throw new Error('Expected model to be an object');
+ expect(Reflect.get(model, 'supportsStructuredOutputs')).toBe(true);
+ }
});
- it('constructs google-gemini model without throwing', () => {
- const model = buildLanguageModel(makeConfig({ provider: 'google-gemini' }));
- expect(model).toBeDefined();
+ // Alibaba endpoints are per-workspace, so falling back to the package default would quietly
+ // address someone else's tenant.
+ it('demands a baseUrl from alibaba even though its adapter ships a default', () => {
+ expect(() => buildLanguageModel(makeConfig({ provider: 'alibaba' }))).toThrow('baseUrl');
+ expect(buildLanguageModel(makeConfig({ provider: 'alibaba', baseUrl: 'http://localhost/v1' }))).toBeDefined();
});
- it('constructs custom model without throwing when base_url is provided', () => {
- const model = buildLanguageModel(makeConfig({ provider: 'custom', base_url: 'http://localhost:11434/v1' }));
- expect(model).toBeDefined();
- });
-
- it('sets supportsStructuredOutputs:true on the custom model instance', () => {
- const model: unknown = buildLanguageModel(
- makeConfig({ provider: 'custom', base_url: 'http://localhost:11434/v1' }),
- );
- if (typeof model !== 'object' || model === null) throw new Error('Expected model to be an object');
- expect(Reflect.get(model, 'supportsStructuredOutputs')).toBe(true);
+ it('throws for unknown provider string (exhaustive default branch)', () => {
+ const badConfig = JSON.parse('{"provider":"unknown-provider","name":"x","apiKey":"k","headers":{}}');
+ expect(() => buildLanguageModel(badConfig)).toThrow('Unknown provider');
});
- it('uses model_id over name when provided', () => {
+ // `name` carries the provider-qualified alias, which no provider would accept as a model id.
+ it('sends modelId, never name', () => {
const model: unknown = buildLanguageModel(
- makeConfig({ provider: 'anthropic', name: 'alias', model_id: 'claude-sonnet-5' }),
+ makeConfig({ provider: 'anthropic', name: 'anthropic/alias', modelId: 'claude-sonnet-5' }),
);
if (typeof model !== 'object' || model === null) throw new Error('Expected model to be an object');
expect(Reflect.get(model, 'modelId')).toBe('claude-sonnet-5');
diff --git a/packages/harness/tests/core/llm/VercelAILLM.output.test.ts b/packages/harness/tests/core/llm/VercelAILLM.output.test.ts
index 9348ce874..5144f0fb4 100644
--- a/packages/harness/tests/core/llm/VercelAILLM.output.test.ts
+++ b/packages/harness/tests/core/llm/VercelAILLM.output.test.ts
@@ -8,7 +8,7 @@ import { buildProviderOptions, toReasoningLevel, toStructuredOutputSpec } from '
function makeConfig(
overrides: Partial<VercelAIProviderConfig> & { provider: VercelAIProviderConfig['provider'] },
): VercelAIProviderConfig {
- return { name: 'test', apiKey: 'sk-test', headers: {}, ...overrides };
+ return { name: 'test', modelId: 'test-model', apiKey: 'sk-test', headers: {}, ...overrides };
}
// ─────────── toStructuredOutputSpec ───────────
@@ -87,26 +87,21 @@ describe('toStructuredOutputSpec', () => {
// ─────────── toReasoningLevel ───────────
describe('toReasoningLevel', () => {
- it('returns undefined for non-google-gemini providers regardless of effort', () => {
- expect(toReasoningLevel({ provider: 'openai', reasoningEffort: 'high' })).toBeUndefined();
- expect(toReasoningLevel({ provider: 'anthropic', reasoningEffort: 'medium' })).toBeUndefined();
- expect(toReasoningLevel({ provider: 'custom', reasoningEffort: 'low' })).toBeUndefined();
+ it('passes through every level the SDK union can express', () => {
+ const validLevels = ['provider-default', 'none', 'minimal', 'low', 'medium', 'high', 'xhigh'] as const;
+ for (const level of validLevels) {
+ expect(toReasoningLevel(level)).toBe(level);
+ }
});
- it('returns undefined when reasoningEffort is undefined', () => {
- expect(toReasoningLevel({ provider: 'google-gemini', reasoningEffort: undefined })).toBeUndefined();
+ it('returns undefined for an absent or unrecognised effort', () => {
+ expect(toReasoningLevel(undefined)).toBeUndefined();
+ expect(toReasoningLevel('ultra')).toBeUndefined();
+ expect(toReasoningLevel('')).toBeUndefined();
});
- it('returns undefined when reasoningEffort is not a valid ReasoningLevel', () => {
- expect(toReasoningLevel({ provider: 'google-gemini', reasoningEffort: 'ultra' })).toBeUndefined();
- expect(toReasoningLevel({ provider: 'google-gemini', reasoningEffort: '' })).toBeUndefined();
- });
-
- it('returns the level for all valid ReasoningLevel values on google-gemini', () => {
- const validLevels = ['provider-default', 'none', 'minimal', 'low', 'medium', 'high', 'xhigh'] as const;
- for (const level of validLevels) {
- expect(toReasoningLevel({ provider: 'google-gemini', reasoningEffort: level })).toBe(level);
- }
+ it('maps `max` onto the SDK ceiling, which adapters raise back for models lacking xhigh', () => {
+ expect(toReasoningLevel('max')).toBe('xhigh');
});
});
@@ -143,26 +138,6 @@ describe('buildProviderOptions', () => {
expect(opts['openai']).toMatchObject({ store: false, include: ['reasoning.encrypted_content'] });
});
- it('includes reasoningEffort when present', () => {
- const opts = buildProviderOptions({
- config: config,
- reasoningEffort: 'high',
- structuredOutputSpec: textSpec,
- rawBody: {},
- });
- expect(opts['openai']).toMatchObject({ reasoningEffort: 'high' });
- });
-
- it('omits reasoningEffort key when undefined', () => {
- const opts = buildProviderOptions({
- config: config,
- reasoningEffort: undefined,
- structuredOutputSpec: textSpec,
- rawBody: {},
- });
- expect(opts['openai']).not.toHaveProperty('reasoningEffort');
- });
-
it('includes strictJsonSchema:true when spec is json_schema with strict:true', () => {
const opts = buildProviderOptions({
config: config,
@@ -219,45 +194,32 @@ describe('buildProviderOptions', () => {
describe('anthropic provider', () => {
const config = makeConfig({ provider: 'anthropic' });
- it('returns empty options when reasoningEffort is absent', () => {
- const opts = buildProviderOptions({
- config: config,
- reasoningEffort: undefined,
- structuredOutputSpec: textSpec,
- rawBody: {},
- });
- expect(opts).toEqual({});
- });
-
- it('maps low → 1024, medium → 8192, high → 32768', () => {
- expect(
- buildProviderOptions({ config: config, reasoningEffort: 'low', structuredOutputSpec: textSpec, rawBody: {} })[
- 'anthropic'
- ],
- ).toEqual({ thinking: { type: 'enabled', budgetTokens: 1024 } });
- expect(
- buildProviderOptions({
+ it('leaves thinking to the SDK so per-model shapes stay correct', () => {
+ // Pinning `thinking` here would override the SDK's per-model mapping and send
+ // `thinking.type: 'enabled'` to Claude 5, which only accepts 'adaptive'.
+ for (const reasoningEffort of [undefined, 'high']) {
+ const opts = buildProviderOptions({
config: config,
- reasoningEffort: 'medium',
+ reasoningEffort,
structuredOutputSpec: textSpec,
rawBody: {},
- })['anthropic'],
- ).toEqual({ thinking: { type: 'enabled', budgetTokens: 8192 } });
- expect(
- buildProviderOptions({ config: config, reasoningEffort: 'high', structuredOutputSpec: textSpec, rawBody: {} })[
- 'anthropic'
- ],
- ).toEqual({ thinking: { type: 'enabled', budgetTokens: 32768 } });
+ });
+ expect(opts).toEqual({});
+ }
});
- it('falls back to 8192 for an unrecognised effort level', () => {
+ it('forwards a caller-supplied thinking and effort, which override the per-model shape', () => {
+ // The caller's only route to disabling thinking, a raw effort, or Claude 5's `display`.
const opts = buildProviderOptions({
- config: config,
- reasoningEffort: 'ultra',
+ config,
+ reasoningEffort: 'high',
structuredOutputSpec: textSpec,
- rawBody: {},
+ rawBody: { thinking: { type: 'adaptive', display: 'summarized' }, effort: 'max' },
+ });
+ expect(opts['anthropic']).toEqual({
+ thinking: { type: 'adaptive', display: 'summarized' },
+ effort: 'max',
});
- expect(opts['anthropic']).toEqual({ thinking: { type: 'enabled', budgetTokens: 8192 } });
});
it('ignores strictJsonSchema (no anthropic key for structured-output strictness)', () => {
@@ -282,69 +244,89 @@ describe('buildProviderOptions', () => {
disableParallelToolUse: true,
});
});
+ });
+
+ describe('custom provider', () => {
+ const config = makeConfig({ provider: 'custom', baseUrl: 'http://localhost/v1' });
- it('omits anthropic key when rawBody fields are absent and no reasoningEffort', () => {
+ // The compatible adapter reads options from a key matching the name it was built with, so each
+ // OpenAI-compatible provider gets its own bucket rather than a shared one.
+ it.each(['custom', 'fireworks', 'zai'] as const)('%s: passes strictJsonSchema under its own key', provider => {
const opts = buildProviderOptions({
- config,
+ config: makeConfig({ provider, baseUrl: 'http://localhost/v1' }),
reasoningEffort: undefined,
- structuredOutputSpec: textSpec,
+ structuredOutputSpec: schemaSpecStrict,
rawBody: {},
});
- expect(opts).not.toHaveProperty('anthropic');
+ expect(opts).toEqual({ [provider]: { strictJsonSchema: true } });
});
- });
-
- describe('custom provider', () => {
- const config = makeConfig({ provider: 'custom', base_url: 'http://localhost/v1' });
- it('returns empty options when both reasoningEffort and strictJsonSchema are absent', () => {
+ it('omits the custom key when the resulting object would be empty', () => {
const opts = buildProviderOptions({
config: config,
- reasoningEffort: undefined,
+ reasoningEffort: 'high',
structuredOutputSpec: textSpec,
rawBody: {},
});
expect(opts).toEqual({});
});
+ });
- it('passes reasoningEffort through', () => {
+ describe('moonshot provider', () => {
+ const config = makeConfig({ provider: 'moonshot' });
+
+ it('sends `max` as an effort of its own, since the top-level setting caps at xhigh', () => {
const opts = buildProviderOptions({
- config: config,
- reasoningEffort: 'medium',
+ config,
+ reasoningEffort: 'max',
structuredOutputSpec: textSpec,
rawBody: {},
});
- expect(opts['custom']).toMatchObject({ reasoningEffort: 'medium' });
+ expect(opts).toEqual({ moonshotai: { reasoningEffort: 'max' } });
});
- it('passes strictJsonSchema for json_schema mode', () => {
+ it('leaves every other effort to the top-level setting', () => {
const opts = buildProviderOptions({
- config: config,
- reasoningEffort: undefined,
- structuredOutputSpec: schemaSpecStrict,
+ config,
+ reasoningEffort: 'high',
+ structuredOutputSpec: textSpec,
rawBody: {},
});
- expect(opts['custom']).toMatchObject({ strictJsonSchema: true });
+ expect(opts).toEqual({});
});
- it('includes both when both are present', () => {
+ it('forwards thinking and reasoning_history from rawBody', () => {
const opts = buildProviderOptions({
- config: config,
- reasoningEffort: 'low',
- structuredOutputSpec: schemaSpecStrict,
- rawBody: {},
+ config,
+ reasoningEffort: undefined,
+ structuredOutputSpec: textSpec,
+ rawBody: { thinking: { type: 'disabled' }, reasoning_history: 'preserved' },
});
- expect(opts['custom']).toEqual({ reasoningEffort: 'low', strictJsonSchema: true });
+ expect(opts['moonshotai']).toEqual({ thinking: { type: 'disabled' }, reasoningHistory: 'preserved' });
});
+ });
- it('omits the custom key when the resulting object would be empty', () => {
+ describe('alibaba provider', () => {
+ const config = makeConfig({ provider: 'alibaba', baseUrl: 'http://localhost/v1' });
+
+ it('forwards thinking overrides and parallel_tool_calls, which the compatible adapter drops', () => {
const opts = buildProviderOptions({
- config: config,
- reasoningEffort: undefined,
+ config,
+ reasoningEffort: 'high',
structuredOutputSpec: textSpec,
+ rawBody: { enable_thinking: false, thinking_budget: 512, parallel_tool_calls: false },
+ });
+ expect(opts['alibaba']).toEqual({ enableThinking: false, thinkingBudget: 512, parallelToolCalls: false });
+ });
+
+ it('sends nothing of its own when rawBody carries no overrides', () => {
+ const opts = buildProviderOptions({
+ config,
+ reasoningEffort: 'high',
+ structuredOutputSpec: schemaSpecStrict,
rawBody: {},
});
- expect(opts).not.toHaveProperty('custom');
+ expect(opts).toEqual({});
});
});
@@ -360,9 +342,6 @@ describe('buildProviderOptions', () => {
rawBody: {},
}),
).toEqual({});
- expect(
- buildProviderOptions({ config: config, reasoningEffort: 'high', structuredOutputSpec: textSpec, rawBody: {} }),
- ).toEqual({});
expect(
buildProviderOptions({
config: config,
@@ -373,6 +352,23 @@ describe('buildProviderOptions', () => {
).toEqual({});
});
+ it('requests thought summaries when a reasoning effort is set', () => {
+ expect(
+ buildProviderOptions({ config, reasoningEffort: 'high', structuredOutputSpec: textSpec, rawBody: {} }),
+ ).toEqual({ google: { thinkingConfig: { includeThoughts: true } } });
+ });
+
+ it('keeps an explicit thinking_config while still requesting thought summaries', () => {
+ expect(
+ buildProviderOptions({
+ config,
+ reasoningEffort: 'high',
+ structuredOutputSpec: textSpec,
+ rawBody: { thinking_config: { thinkingBudget: 2048 } },
+ }),
+ ).toEqual({ google: { thinkingConfig: { includeThoughts: true, thinkingBudget: 2048 } } });
+ });
+
it('forwards safety_settings, thinking_config, cached_content from rawBody', () => {
const opts = buildProviderOptions({
config,
@@ -392,29 +388,35 @@ describe('buildProviderOptions', () => {
});
});
- describe('cross-provider completeness: every provider must surface reasoningEffort somewhere', () => {
- const providers: VercelAIProviderConfig['provider'][] = ['openai', 'anthropic', 'custom', 'google-gemini'];
- const effort = 'high';
-
- it.each(providers)('%s: reasoningEffort reaches providerOptions or toReasoningLevel', provider => {
+ describe('cross-provider completeness', () => {
+ const providers: VercelAIProviderConfig['provider'][] = [
+ 'openai',
+ 'anthropic',
+ 'custom',
+ 'google-gemini',
+ 'moonshot',
+ 'alibaba',
+ ];
+
+ // Reasoning travels only on the top-level setting. A providerOptions copy would take precedence
+ // over it, so any provider growing one here would silently shadow the requested effort. Moonshot
+ // is the deliberate exception, and only for `max`, which the top-level setting cannot express.
+ it.each(providers)('%s: no providerOptions entry carries the effort', provider => {
const config = makeConfig({
provider,
- ...(provider === 'custom' ? { base_url: 'http://localhost/v1' } : {}),
+ ...(provider === 'custom' || provider === 'alibaba' ? { baseUrl: 'http://localhost/v1' } : {}),
});
const opts = buildProviderOptions({
- config: config,
- reasoningEffort: effort,
+ config,
+ reasoningEffort: 'high',
structuredOutputSpec: textSpec,
rawBody: {},
});
- const reasoningLevel = toReasoningLevel({ provider: provider, reasoningEffort: effort });
-
- const inProviderOptions =
- (opts['openai'] !== undefined && 'reasoningEffort' in opts['openai']) ||
- opts['anthropic'] !== undefined ||
- (opts['custom'] !== undefined && 'reasoningEffort' in opts['custom']);
- expect(inProviderOptions || reasoningLevel !== undefined).toBe(true);
+ expect(toReasoningLevel('high')).toBe('high');
+ for (const entry of Object.values(opts)) {
+ expect(entry === undefined || !('reasoningEffort' in entry)).toBe(true);
+ }
});
});
});
diff --git a/packages/harness/tests/core/llm/VercelAILLM.replay.test.ts b/packages/harness/tests/core/llm/VercelAILLM.replay.test.ts
index e0ced08b4..fe96e4e7a 100644
--- a/packages/harness/tests/core/llm/VercelAILLM.replay.test.ts
+++ b/packages/harness/tests/core/llm/VercelAILLM.replay.test.ts
@@ -132,12 +132,17 @@ describe('Gemini tool thoughtSignature replay round-trip', () => {
// ─────────── Reasoning signature round-trips ───────────
+/**
+ * `metadataKey`/`signatureField` are where the response carries the token; `expectedProviderOptions`
+ * is what replay must attach to the next request. The keys differ per provider.
+ */
type ReasoningRoundTripCase = {
provider: VercelAIProviderName;
metadataKey: string;
signatureField: string;
signatureValue: string;
- expectedProviderOptions: Record<string, unknown>;
+ /** `undefined` for providers whose adapter has nowhere to put the token. */
+ expectedProviderOptions: Record<string, unknown> | undefined;
};
const REASONING_CASES: ReasoningRoundTripCase[] = [
@@ -146,7 +151,7 @@ const REASONING_CASES: ReasoningRoundTripCase[] = [
metadataKey: 'openai',
signatureField: 'reasoningEncryptedContent',
signatureValue: 'enc-content-openai',
- expectedProviderOptions: { openai: { encryptedContent: 'enc-content-openai' } },
+ expectedProviderOptions: { openai: { reasoningEncryptedContent: 'enc-content-openai' } },
},
{
provider: 'anthropic',
@@ -157,10 +162,11 @@ const REASONING_CASES: ReasoningRoundTripCase[] = [
},
{
provider: 'custom',
+ // Synthetic namespace: real OpenAI-compatible endpoints send unsigned `reasoning_content` text.
metadataKey: 'custom',
signatureField: 'reasoningEncryptedContent',
signatureValue: 'enc-content-custom',
- expectedProviderOptions: { custom: { encryptedContent: 'enc-content-custom' } },
+ expectedProviderOptions: undefined,
},
];
@@ -205,6 +211,41 @@ describe.each(REASONING_CASES)(
},
);
+describe('anthropic reasoning replay, on the shape Anthropic actually sends', () => {
+ // Anthropic delivers its signature on a text-less reasoning-delta, never on reasoning-end, and a
+ // tool turn replays thinking and the tool call together with thinking first.
+ it('replays a delta-delivered signature, with thinking ahead of the tool call', async () => {
+ const { output } = await drainStream(
+ mapStreamToChunks({
+ stream: makeStream([
+ { type: 'reasoning-start', id: 'r1' },
+ { type: 'reasoning-delta', id: 'r1', text: 'need the weather' },
+ { type: 'reasoning-delta', id: 'r1', text: '', providerMetadata: { anthropic: { signature: 'ant-delta' } } },
+ { type: 'reasoning-end', id: 'r1' },
+ { type: 'tool-input-start', id: 'call-a1', toolName: 'get_weather' },
+ { type: 'tool-input-delta', id: 'call-a1', delta: '{"city":"Paris"}' },
+ makeFinishStep('tool-calls'),
+ ]),
+ chunkMeta: CHUNK_META,
+ }),
+ );
+
+ const assistantMsg: Extract<ChatCompletionMessageParam, { role: 'assistant' }> = {
+ role: 'assistant',
+ content: null,
+ ...(output.tool_calls !== undefined ? { tool_calls: output.tool_calls } : {}),
+ };
+ Reflect.set(assistantMsg, 'thinking_blocks', output.thinking_blocks);
+ const parts = toAssistantModelMessage({ msg: assistantMsg, provider: 'anthropic' }).content as Array<{
+ type: string;
+ providerOptions?: unknown;
+ }>;
+
+ expect(parts.map(p => p.type)).toEqual(['reasoning', 'tool-call']);
+ expect(parts[0]?.providerOptions).toEqual({ anthropic: { signature: 'ant-delta' } });
+ });
+});
+
describe('google-gemini reasoning replay round-trip', () => {
it('emits a reasoning part with no providerOptions (signature is per-tool-call for Gemini)', async () => {
// Gemini does not attach a standalone reasoning block signature; thoughtSignature is per
diff --git a/packages/harness/tests/core/llm/VercelAILLM.stream.test.ts b/packages/harness/tests/core/llm/VercelAILLM.stream.test.ts
index f23281b29..659e3ee32 100644
--- a/packages/harness/tests/core/llm/VercelAILLM.stream.test.ts
+++ b/packages/harness/tests/core/llm/VercelAILLM.stream.test.ts
@@ -204,6 +204,69 @@ describe('mapStreamToChunks', () => {
});
});
+ // Anthropic's real wire shape: signature_delta surfaces as a text-less reasoning-delta, not on
+ // reasoning-end. Missing it leaves the block unsigned, and Anthropic drops unsigned thinking
+ // blocks when they are replayed, silently losing the reasoning chain.
+ it('attaches signature from a text-less reasoning-delta (Anthropic signature_delta)', async () => {
+ const providerMetadata: ProviderMetadata = { anthropic: { signature: 'ant-delta-sig' } };
+ const { final } = await drainStream(
+ mapStreamToChunks({
+ stream: makeStream([
+ { type: 'reasoning-start', id: 'r1' },
+ { type: 'reasoning-delta', id: 'r1', text: 'thought' },
+ { type: 'reasoning-delta', id: 'r1', text: '', providerMetadata },
+ { type: 'reasoning-end', id: 'r1' },
+ makeFinishStep('stop'),
+ ]),
+ chunkMeta: CHUNK_META,
+ }),
+ );
+
+ expect(final.output.thinking_blocks?.[0]).toMatchObject({
+ type: 'thinking',
+ thinking: 'thought',
+ signature: 'ant-delta-sig',
+ });
+ });
+
+ it('keeps a reasoning-delta that arrives without a reasoning-start, along with its signature', async () => {
+ const providerMetadata: ProviderMetadata = { anthropic: { signature: 'orphan-sig' } };
+ const { final } = await drainStream(
+ mapStreamToChunks({
+ stream: makeStream([
+ { type: 'reasoning-delta', id: 'r1', text: 'unopened thought', providerMetadata },
+ makeFinishStep('stop'),
+ ]),
+ chunkMeta: CHUNK_META,
+ }),
+ );
+
+ expect(final.output.thinking_blocks).toEqual([
+ { type: 'thinking', thinking: 'unopened thought', signature: 'orphan-sig' },
+ ]);
+ });
+
+ it('drops a tool-input-delta whose id never opened, rather than crediting tool call 0', async () => {
+ const { chunks } = await drainStream(
+ mapStreamToChunks({
+ stream: makeStream([
+ { type: 'tool-input-start', id: 'call-a', toolName: 'tool_a' },
+ { type: 'tool-input-delta', id: 'call-a', delta: '{"city":' },
+ { type: 'tool-input-delta', id: 'ghost', delta: '"CORRUPT"' },
+ { type: 'tool-input-delta', id: 'call-a', delta: '"Paris"}' },
+ makeFinishStep('tool-calls'),
+ ]),
+ chunkMeta: CHUNK_META,
+ }),
+ );
+
+ const streamedArgs = chunks
+ .map(c => c.choices[0]?.delta.tool_calls?.[0]?.function?.arguments)
+ .filter(Boolean)
+ .join('');
+ expect(streamedArgs).toBe('{"city":"Paris"}');
+ });
+
it('assigns unique ascending indices to interleaved tool-input-* parts', async () => {
const { chunks } = await drainStream(
mapStreamToChunks({
@@ -305,6 +368,45 @@ describe('mapStreamToChunks', () => {
).rejects.toMatchObject({ message: 'LLM stream error', cause });
});
+ it('rejects on an abort part rather than returning the partial message as a clean stop', async () => {
+ await expect(
+ drainStream(
+ mapStreamToChunks({
+ stream: makeStream([{ type: 'text-delta', id: 't1', text: 'partial' }, { type: 'abort' }]),
+ chunkMeta: CHUNK_META,
+ }),
+ ),
+ ).rejects.toMatchObject({ name: 'AbortError' });
+ });
+
+ it('keeps the provider message when the error part carries a plain object', async () => {
+ await expect(
+ drainStream(
+ mapStreamToChunks({
+ stream: makeStream([{ type: 'error', error: { message: 'The requested model does not exist.' } }]),
+ chunkMeta: CHUNK_META,
+ }),
+ ),
+ ).rejects.toMatchObject({
+ message: 'LLM stream error',
+ cause: { message: 'The requested model does not exist.' },
+ });
+ });
+
+ it('serialises a message-less error object rather than stringifying it to [object Object]', async () => {
+ await expect(
+ drainStream(
+ mapStreamToChunks({
+ stream: makeStream([{ type: 'error', error: { code: 'model_not_found', status: 404 } }]),
+ chunkMeta: CHUNK_META,
+ }),
+ ),
+ ).rejects.toMatchObject({
+ message: 'LLM stream error',
+ cause: { message: '{"code":"model_not_found","status":404}' },
+ });
+ });
+
it('wraps non-Error error values in an Error with cause', async () => {
await expect(
drainStream(
diff --git a/packages/sdk/.fern/metadata.json b/packages/sdk/.fern/metadata.json
index e1732ead8..4007c1f7d 100644
--- a/packages/sdk/.fern/metadata.json
+++ b/packages/sdk/.fern/metadata.json
@@ -26,10 +26,10 @@
"streamType": "web",
"useDefaultRequestParameterValues": true
},
- "originGitCommit": "37a4fd4ccf9bbfdd6079a2be14b950617bd0577e",
+ "originGitCommit": "afc3ae37e5f2d08a3a5b7d2c1f18961fe44b475e",
"originGitCommitIsDirty": true,
"invokedBy": "ci",
"requestedVersion": "0.0.0",
- "ciProvider": "github",
+ "ciProvider": "unknown",
"sdkVersion": "0.0.0"
}
diff --git a/packages/sdk/reference.md b/packages/sdk/reference.md
index 354cab8b8..7612ca1be 100644
--- a/packages/sdk/reference.md
+++ b/packages/sdk/reference.md
@@ -261,12 +261,7 @@ Create a session holding an inline agent spec. Turns are executed against this s
await client.sessions.create({
agentSpec: {
model: {
- modelId: "model_id",
- name: "name",
- properties: {
- contextLength: 1,
- maxOutputTokens: 1
- }
+ name: "name"
}
}
});
@@ -1479,13 +1474,10 @@ await client.settings.modelProviders.upsert({
models: [{
modelId: "model_id",
name: "name",
- properties: {
- contextLength: 1,
- maxOutputTokens: 1
- }
+ properties: {}
}],
name: "name",
- type: "anthropic"
+ type: "openai"
});
```
diff --git a/packages/sdk/src/api/resources/sessions/client/Client.ts b/packages/sdk/src/api/resources/sessions/client/Client.ts
index 19970ebc1..0c9c4e8f5 100644
--- a/packages/sdk/src/api/resources/sessions/client/Client.ts
+++ b/packages/sdk/src/api/resources/sessions/client/Client.ts
@@ -148,12 +148,7 @@ export class SessionsClient {
* await client.sessions.create({
* agentSpec: {
* model: {
- * modelId: "model_id",
- * name: "name",
- * properties: {
- * contextLength: 1,
- * maxOutputTokens: 1
- * }
+ * name: "name"
* }
* }
* })
diff --git a/packages/sdk/src/api/resources/sessions/client/requests/CreateSessionRequest.ts b/packages/sdk/src/api/resources/sessions/client/requests/CreateSessionRequest.ts
index fc2ce45e2..6fd0540df 100644
--- a/packages/sdk/src/api/resources/sessions/client/requests/CreateSessionRequest.ts
+++ b/packages/sdk/src/api/resources/sessions/client/requests/CreateSessionRequest.ts
@@ -7,12 +7,7 @@ import type * as TrueHarness from "../../../../index.js";
* {
* agentSpec: {
* model: {
- * modelId: "model_id",
- * name: "name",
- * properties: {
- * contextLength: 1,
- * maxOutputTokens: 1
- * }
+ * name: "name"
* }
* }
* }
diff --git a/packages/sdk/src/api/resources/settings/resources/modelProviders/client/Client.ts b/packages/sdk/src/api/resources/settings/resources/modelProviders/client/Client.ts
index f3a69c929..c624002f2 100644
--- a/packages/sdk/src/api/resources/settings/resources/modelProviders/client/Client.ts
+++ b/packages/sdk/src/api/resources/settings/resources/modelProviders/client/Client.ts
@@ -106,13 +106,10 @@ export class ModelProvidersClient {
* models: [{
* modelId: "model_id",
* name: "name",
- * properties: {
- * contextLength: 1,
- * maxOutputTokens: 1
- * }
+ * properties: {}
* }],
* name: "name",
- * type: "anthropic"
+ * type: "openai"
* })
*/
public upsert(
diff --git a/packages/sdk/src/api/types/CustomModelProvider.ts b/packages/sdk/src/api/types/CallerSuppliedModelProvider.ts
similarity index 74%
rename from packages/sdk/src/api/types/CustomModelProvider.ts
rename to packages/sdk/src/api/types/CallerSuppliedModelProvider.ts
index 97e894fc6..c7177a82c 100644
--- a/packages/sdk/src/api/types/CustomModelProvider.ts
+++ b/packages/sdk/src/api/types/CallerSuppliedModelProvider.ts
@@ -2,11 +2,11 @@
import type * as TrueHarness from "../index.js";
-export interface CustomModelProvider {
+export interface CallerSuppliedModelProvider {
auth: TrueHarness.ModelProviderAuth;
/** Base URL of the provider's API. */
baseUrl: string;
models: TrueHarness.ModelEntry[];
name: TrueHarness.ResourceName;
- type: "custom";
+ type: TrueHarness.CallerSuppliedModelProviderType;
}
diff --git a/packages/sdk/src/api/types/CallerSuppliedModelProviderType.ts b/packages/sdk/src/api/types/CallerSuppliedModelProviderType.ts
new file mode 100644
index 000000000..41edbef22
--- /dev/null
+++ b/packages/sdk/src/api/types/CallerSuppliedModelProviderType.ts
@@ -0,0 +1,8 @@
+// This file was auto-generated by Fern from our API Definition.
+
+export const CallerSuppliedModelProviderType = {
+ Alibaba: "alibaba",
+ Custom: "custom",
+} as const;
+export type CallerSuppliedModelProviderType =
+ (typeof CallerSuppliedModelProviderType)[keyof typeof CallerSuppliedModelProviderType];
diff --git a/packages/sdk/src/api/types/CatalogProviderType.ts b/packages/sdk/src/api/types/CatalogProviderType.ts
index e9356ce63..2405ddffc 100644
--- a/packages/sdk/src/api/types/CatalogProviderType.ts
+++ b/packages/sdk/src/api/types/CatalogProviderType.ts
@@ -3,5 +3,10 @@
export const CatalogProviderType = {
Openai: "openai",
Anthropic: "anthropic",
+ GoogleGemini: "google-gemini",
+ Fireworks: "fireworks",
+ Zai: "zai",
+ Moonshot: "moonshot",
+ Alibaba: "alibaba",
} as const;
export type CatalogProviderType = (typeof CatalogProviderType)[keyof typeof CatalogProviderType];
diff --git a/packages/sdk/src/api/types/ModelProperties.ts b/packages/sdk/src/api/types/ModelProperties.ts
index e0c7ebbf2..93bc6f02d 100644
--- a/packages/sdk/src/api/types/ModelProperties.ts
+++ b/packages/sdk/src/api/types/ModelProperties.ts
@@ -1,7 +1,7 @@
// This file was auto-generated by Fern from our API Definition.
export interface ModelProperties {
- contextLength: number;
- maxOutputTokens: number;
+ contextLength?: number;
+ maxOutputTokens?: number;
reasoningEfforts?: string[];
}
diff --git a/packages/sdk/src/api/types/ModelProvider.ts b/packages/sdk/src/api/types/ModelProvider.ts
index 3a5c47228..9bfcaa082 100644
--- a/packages/sdk/src/api/types/ModelProvider.ts
+++ b/packages/sdk/src/api/types/ModelProvider.ts
@@ -2,7 +2,4 @@
import type * as TrueHarness from "../index.js";
-export type ModelProvider =
- | TrueHarness.AnthropicModelProvider
- | TrueHarness.CustomModelProvider
- | TrueHarness.OpenAiModelProvider;
+export type ModelProvider = TrueHarness.WellKnownModelProvider | TrueHarness.CallerSuppliedModelProvider;
diff --git a/packages/sdk/src/api/types/OpenAiModelProvider.ts b/packages/sdk/src/api/types/OpenAiModelProvider.ts
deleted file mode 100644
index 2c4fa322e..000000000
--- a/packages/sdk/src/api/types/OpenAiModelProvider.ts
+++ /dev/null
@@ -1,12 +0,0 @@
-// This file was auto-generated by Fern from our API Definition.
-
-import type * as TrueHarness from "../index.js";
-
-export interface OpenAiModelProvider {
- auth: TrueHarness.ModelProviderAuth;
- /** Optional override of the provider's default API base URL. */
- baseUrl?: string;
- models: TrueHarness.ModelEntry[];
- name: TrueHarness.ResourceName;
- type: "openai";
-}
diff --git a/packages/sdk/src/api/types/AnthropicModelProvider.ts b/packages/sdk/src/api/types/WellKnownModelProvider.ts
similarity index 77%
rename from packages/sdk/src/api/types/AnthropicModelProvider.ts
rename to packages/sdk/src/api/types/WellKnownModelProvider.ts
index 5eb7e4086..cb819f075 100644
--- a/packages/sdk/src/api/types/AnthropicModelProvider.ts
+++ b/packages/sdk/src/api/types/WellKnownModelProvider.ts
@@ -2,11 +2,11 @@
import type * as TrueHarness from "../index.js";
-export interface AnthropicModelProvider {
+export interface WellKnownModelProvider {
auth: TrueHarness.ModelProviderAuth;
/** Optional override of the provider's default API base URL. */
baseUrl?: string;
models: TrueHarness.ModelEntry[];
name: TrueHarness.ResourceName;
- type: "anthropic";
+ type: TrueHarness.WellKnownModelProviderType;
}
diff --git a/packages/sdk/src/api/types/WellKnownModelProviderType.ts b/packages/sdk/src/api/types/WellKnownModelProviderType.ts
new file mode 100644
index 000000000..8a262c9c4
--- /dev/null
+++ b/packages/sdk/src/api/types/WellKnownModelProviderType.ts
@@ -0,0 +1,11 @@
+// This file was auto-generated by Fern from our API Definition.
+
+export const WellKnownModelProviderType = {
+ Openai: "openai",
+ Anthropic: "anthropic",
+ GoogleGemini: "google-gemini",
+ Fireworks: "fireworks",
+ Zai: "zai",
+ Moonshot: "moonshot",
+} as const;
+export type WellKnownModelProviderType = (typeof WellKnownModelProviderType)[keyof typeof WellKnownModelProviderType];
diff --git a/packages/sdk/src/api/types/index.ts b/packages/sdk/src/api/types/index.ts
index 5667ea909..8c76673ce 100644
--- a/packages/sdk/src/api/types/index.ts
+++ b/packages/sdk/src/api/types/index.ts
@@ -4,13 +4,14 @@ export * from "./AgentParent.js";
export * from "./AgentSpec.js";
export * from "./AgentSpecModel.js";
export * from "./AgentSpecUserMessage.js";
-export * from "./AnthropicModelProvider.js";
export * from "./ApprovalAllow.js";
export * from "./ApprovalDecision.js";
export * from "./ApprovalDeny.js";
export * from "./AskUserQuestionsConfig.js";
export * from "./BaseMcpAuthRequiredEvent.js";
export * from "./BaseThreadDoneEvent.js";
+export * from "./CallerSuppliedModelProvider.js";
+export * from "./CallerSuppliedModelProviderType.js";
export * from "./CancelSessionResponse.js";
export * from "./CatalogDaytonaSandboxProvider.js";
export * from "./CatalogMcpServer.js";
@@ -27,7 +28,6 @@ export * from "./ConfiguredMcpServer.js";
export * from "./ConfiguredMcpServerAuth.js";
export * from "./ContextManagementConfig.js";
export * from "./ContextManagementConfigCompaction.js";
-export * from "./CustomModelProvider.js";
export * from "./DaytonaSandboxProvider.js";
export * from "./DaytonaSandboxProviderAuth.js";
export * from "./DynamicSubAgentsConfig.js";
@@ -89,7 +89,6 @@ export * from "./ModelParams.js";
export * from "./ModelProperties.js";
export * from "./ModelProvider.js";
export * from "./ModelProviderAuth.js";
-export * from "./OpenAiModelProvider.js";
export * from "./PreviousTurnIdInput.js";
export * from "./PutMcpServerResponse.js";
export * from "./PutModelProviderResponse.js";
@@ -150,3 +149,5 @@ export * from "./UserMessageContent.js";
export * from "./UserMessageContentItem.js";
export * from "./UserToolApprovalEvent.js";
export * from "./UserToolResponseEvent.js";
+export * from "./WellKnownModelProvider.js";
+export * from "./WellKnownModelProviderType.js";
diff --git a/packages/sdk/src/serialization/types/CustomModelProvider.ts b/packages/sdk/src/serialization/types/CallerSuppliedModelProvider.ts
similarity index 65%
rename from packages/sdk/src/serialization/types/CustomModelProvider.ts
rename to packages/sdk/src/serialization/types/CallerSuppliedModelProvider.ts
index 698cc1d14..880b4d8a5 100644
--- a/packages/sdk/src/serialization/types/CustomModelProvider.ts
+++ b/packages/sdk/src/serialization/types/CallerSuppliedModelProvider.ts
@@ -3,27 +3,28 @@
import type * as TrueHarness from "../../api/index.js";
import * as core from "../../core/index.js";
import type * as serializers from "../index.js";
+import { CallerSuppliedModelProviderType } from "./CallerSuppliedModelProviderType.js";
import { ModelEntry } from "./ModelEntry.js";
import { ModelProviderAuth } from "./ModelProviderAuth.js";
import { ResourceName } from "./ResourceName.js";
-export const CustomModelProvider: core.serialization.ObjectSchema<
- serializers.CustomModelProvider.Raw,
- TrueHarness.CustomModelProvider
+export const CallerSuppliedModelProvider: core.serialization.ObjectSchema<
+ serializers.CallerSuppliedModelProvider.Raw,
+ TrueHarness.CallerSuppliedModelProvider
> = core.serialization.object({
auth: ModelProviderAuth,
baseUrl: core.serialization.property("base_url", core.serialization.string()),
models: core.serialization.list(ModelEntry),
name: ResourceName,
- type: core.serialization.stringLiteral("custom"),
+ type: CallerSuppliedModelProviderType,
});
-export declare namespace CustomModelProvider {
+export declare namespace CallerSuppliedModelProvider {
export interface Raw {
auth: ModelProviderAuth.Raw;
base_url: string;
models: ModelEntry.Raw[];
name: ResourceName.Raw;
- type: "custom";
+ type: CallerSuppliedModelProviderType.Raw;
}
}
diff --git a/packages/sdk/src/serialization/types/CallerSuppliedModelProviderType.ts b/packages/sdk/src/serialization/types/CallerSuppliedModelProviderType.ts
new file mode 100644
index 000000000..c7bccf5bb
--- /dev/null
+++ b/packages/sdk/src/serialization/types/CallerSuppliedModelProviderType.ts
@@ -0,0 +1,14 @@
+// This file was auto-generated by Fern from our API Definition.
+
+import type * as TrueHarness from "../../api/index.js";
+import * as core from "../../core/index.js";
+import type * as serializers from "../index.js";
+
+export const CallerSuppliedModelProviderType: core.serialization.Schema<
+ serializers.CallerSuppliedModelProviderType.Raw,
+ TrueHarness.CallerSuppliedModelProviderType
+> = core.serialization.enum_(["alibaba", "custom"]);
+
+export declare namespace CallerSuppliedModelProviderType {
+ export type Raw = "alibaba" | "custom";
+}
diff --git a/packages/sdk/src/serialization/types/CatalogProviderType.ts b/packages/sdk/src/serialization/types/CatalogProviderType.ts
index 8f58147d5..faf405395 100644
--- a/packages/sdk/src/serialization/types/CatalogProviderType.ts
+++ b/packages/sdk/src/serialization/types/CatalogProviderType.ts
@@ -7,8 +7,8 @@ import type * as serializers from "../index.js";
export const CatalogProviderType: core.serialization.Schema<
serializers.CatalogProviderType.Raw,
TrueHarness.CatalogProviderType
-> = core.serialization.enum_(["openai", "anthropic"]);
+> = core.serialization.enum_(["openai", "anthropic", "google-gemini", "fireworks", "zai", "moonshot", "alibaba"]);
export declare namespace CatalogProviderType {
- export type Raw = "openai" | "anthropic";
+ export type Raw = "openai" | "anthropic" | "google-gemini" | "fireworks" | "zai" | "moonshot" | "alibaba";
}
diff --git a/packages/sdk/src/serialization/types/ModelProperties.ts b/packages/sdk/src/serialization/types/ModelProperties.ts
index 1e9e3232d..8e11d64cc 100644
--- a/packages/sdk/src/serialization/types/ModelProperties.ts
+++ b/packages/sdk/src/serialization/types/ModelProperties.ts
@@ -8,8 +8,8 @@ export const ModelProperties: core.serialization.ObjectSchema<
serializers.ModelProperties.Raw,
TrueHarness.ModelProperties
> = core.serialization.object({
- contextLength: core.serialization.property("context_length", core.serialization.number()),
- maxOutputTokens: core.serialization.property("max_output_tokens", core.serialization.number()),
+ contextLength: core.serialization.property("context_length", core.serialization.number().optional()),
+ maxOutputTokens: core.serialization.property("max_output_tokens", core.serialization.number().optional()),
reasoningEfforts: core.serialization.property(
"reasoning_efforts",
core.serialization.list(core.serialization.string()).optional(),
@@ -18,8 +18,8 @@ export const ModelProperties: core.serialization.ObjectSchema<
export declare namespace ModelProperties {
export interface Raw {
- context_length: number;
- max_output_tokens: number;
+ context_length?: number | null;
+ max_output_tokens?: number | null;
reasoning_efforts?: string[] | null;
}
}
diff --git a/packages/sdk/src/serialization/types/ModelProvider.ts b/packages/sdk/src/serialization/types/ModelProvider.ts
index 7decdec8e..81df1dcd0 100644
--- a/packages/sdk/src/serialization/types/ModelProvider.ts
+++ b/packages/sdk/src/serialization/types/ModelProvider.ts
@@ -3,13 +3,12 @@
import type * as TrueHarness from "../../api/index.js";
import * as core from "../../core/index.js";
import type * as serializers from "../index.js";
-import { AnthropicModelProvider } from "./AnthropicModelProvider.js";
-import { CustomModelProvider } from "./CustomModelProvider.js";
-import { OpenAiModelProvider } from "./OpenAiModelProvider.js";
+import { CallerSuppliedModelProvider } from "./CallerSuppliedModelProvider.js";
+import { WellKnownModelProvider } from "./WellKnownModelProvider.js";
export const ModelProvider: core.serialization.Schema<serializers.ModelProvider.Raw, TrueHarness.ModelProvider> =
- core.serialization.undiscriminatedUnion([AnthropicModelProvider, CustomModelProvider, OpenAiModelProvider]);
+ core.serialization.undiscriminatedUnion([WellKnownModelProvider, CallerSuppliedModelProvider]);
export declare namespace ModelProvider {
- export type Raw = AnthropicModelProvider.Raw | CustomModelProvider.Raw | OpenAiModelProvider.Raw;
+ export type Raw = WellKnownModelProvider.Raw | CallerSuppliedModelProvider.Raw;
}
diff --git a/packages/sdk/src/serialization/types/OpenAiModelProvider.ts b/packages/sdk/src/serialization/types/OpenAiModelProvider.ts
deleted file mode 100644
index 34773d48c..000000000
--- a/packages/sdk/src/serialization/types/OpenAiModelProvider.ts
+++ /dev/null
@@ -1,29 +0,0 @@
-// This file was auto-generated by Fern from our API Definition.
-
-import type * as TrueHarness from "../../api/index.js";
-import * as core from "../../core/index.js";
-import type * as serializers from "../index.js";
-import { ModelEntry } from "./ModelEntry.js";
-import { ModelProviderAuth } from "./ModelProviderAuth.js";
-import { ResourceName } from "./ResourceName.js";
-
-export const OpenAiModelProvider: core.serialization.ObjectSchema<
- serializers.OpenAiModelProvider.Raw,
- TrueHarness.OpenAiModelProvider
-> = core.serialization.object({
- auth: ModelProviderAuth,
- baseUrl: core.serialization.property("base_url", core.serialization.string().optional()),
- models: core.serialization.list(ModelEntry),
- name: ResourceName,
- type: core.serialization.stringLiteral("openai"),
-});
-
-export declare namespace OpenAiModelProvider {
- export interface Raw {
- auth: ModelProviderAuth.Raw;
- base_url?: string | null;
- models: ModelEntry.Raw[];
- name: ResourceName.Raw;
- type: "openai";
- }
-}
diff --git a/packages/sdk/src/serialization/types/AnthropicModelProvider.ts b/packages/sdk/src/serialization/types/WellKnownModelProvider.ts
similarity index 68%
rename from packages/sdk/src/serialization/types/AnthropicModelProvider.ts
rename to packages/sdk/src/serialization/types/WellKnownModelProvider.ts
index 08a890bd1..0ea73a13c 100644
--- a/packages/sdk/src/serialization/types/AnthropicModelProvider.ts
+++ b/packages/sdk/src/serialization/types/WellKnownModelProvider.ts
@@ -6,24 +6,25 @@ import type * as serializers from "../index.js";
import { ModelEntry } from "./ModelEntry.js";
import { ModelProviderAuth } from "./ModelProviderAuth.js";
import { ResourceName } from "./ResourceName.js";
+import { WellKnownModelProviderType } from "./WellKnownModelProviderType.js";
-export const AnthropicModelProvider: core.serialization.ObjectSchema<
- serializers.AnthropicModelProvider.Raw,
- TrueHarness.AnthropicModelProvider
+export const WellKnownModelProvider: core.serialization.ObjectSchema<
+ serializers.WellKnownModelProvider.Raw,
+ TrueHarness.WellKnownModelProvider
> = core.serialization.object({
auth: ModelProviderAuth,
baseUrl: core.serialization.property("base_url", core.serialization.string().optional()),
models: core.serialization.list(ModelEntry),
name: ResourceName,
- type: core.serialization.stringLiteral("anthropic"),
+ type: WellKnownModelProviderType,
});
-export declare namespace AnthropicModelProvider {
+export declare namespace WellKnownModelProvider {
export interface Raw {
auth: ModelProviderAuth.Raw;
base_url?: string | null;
models: ModelEntry.Raw[];
name: ResourceName.Raw;
- type: "anthropic";
+ type: WellKnownModelProviderType.Raw;
}
}
diff --git a/packages/sdk/src/serialization/types/WellKnownModelProviderType.ts b/packages/sdk/src/serialization/types/WellKnownModelProviderType.ts
new file mode 100644
index 000000000..dd9a01f2f
--- /dev/null
+++ b/packages/sdk/src/serialization/types/WellKnownModelProviderType.ts
@@ -0,0 +1,14 @@
+// This file was auto-generated by Fern from our API Definition.
+
+import type * as TrueHarness from "../../api/index.js";
+import * as core from "../../core/index.js";
+import type * as serializers from "../index.js";
+
+export const WellKnownModelProviderType: core.serialization.Schema<
+ serializers.WellKnownModelProviderType.Raw,
+ TrueHarness.WellKnownModelProviderType
+> = core.serialization.enum_(["openai", "anthropic", "google-gemini", "fireworks", "zai", "moonshot"]);
+
+export declare namespace WellKnownModelProviderType {
+ export type Raw = "openai" | "anthropic" | "google-gemini" | "fireworks" | "zai" | "moonshot";
+}
diff --git a/packages/sdk/src/serialization/types/index.ts b/packages/sdk/src/serialization/types/index.ts
index 5667ea909..8c76673ce 100644
--- a/packages/sdk/src/serialization/types/index.ts
+++ b/packages/sdk/src/serialization/types/index.ts
@@ -4,13 +4,14 @@ export * from "./AgentParent.js";
export * from "./AgentSpec.js";
export * from "./AgentSpecModel.js";
export * from "./AgentSpecUserMessage.js";
-export * from "./AnthropicModelProvider.js";
export * from "./ApprovalAllow.js";
export * from "./ApprovalDecision.js";
export * from "./ApprovalDeny.js";
export * from "./AskUserQuestionsConfig.js";
export * from "./BaseMcpAuthRequiredEvent.js";
export * from "./BaseThreadDoneEvent.js";
+export * from "./CallerSuppliedModelProvider.js";
+export * from "./CallerSuppliedModelProviderType.js";
export * from "./CancelSessionResponse.js";
export * from "./CatalogDaytonaSandboxProvider.js";
export * from "./CatalogMcpServer.js";
@@ -27,7 +28,6 @@ export * from "./ConfiguredMcpServer.js";
export * from "./ConfiguredMcpServerAuth.js";
export * from "./ContextManagementConfig.js";
export * from "./ContextManagementConfigCompaction.js";
-export * from "./CustomModelProvider.js";
export * from "./DaytonaSandboxProvider.js";
export * from "./DaytonaSandboxProviderAuth.js";
export * from "./DynamicSubAgentsConfig.js";
@@ -89,7 +89,6 @@ export * from "./ModelParams.js";
export * from "./ModelProperties.js";
export * from "./ModelProvider.js";
export * from "./ModelProviderAuth.js";
-export * from "./OpenAiModelProvider.js";
export * from "./PreviousTurnIdInput.js";
export * from "./PutMcpServerResponse.js";
export * from "./PutModelProviderResponse.js";
@@ -150,3 +149,5 @@ export * from "./UserMessageContent.js";
export * from "./UserMessageContentItem.js";
export * from "./UserToolApprovalEvent.js";
export * from "./UserToolResponseEvent.js";
+export * from "./WellKnownModelProvider.js";
+export * from "./WellKnownModelProviderType.js";
diff --git a/packages/sdk/tests/wire/models.test.ts b/packages/sdk/tests/wire/models.test.ts
index ed42f4b67..a53fb48d4 100644
--- a/packages/sdk/tests/wire/models.test.ts
+++ b/packages/sdk/tests/wire/models.test.ts
@@ -8,9 +8,7 @@ describe("ModelsClient", () => {
const server = mockServerPool.createServer();
const client = new TrueHarness({ maxRetries: 0, environment: server.baseUrl });
- const rawResponseBody = {
- data: [{ model_id: "model_id", name: "name", properties: { context_length: 1, max_output_tokens: 1 } }],
- };
+ const rawResponseBody = { data: [{ model_id: "model_id", name: "name", properties: {} }] };
server.mockEndpoint().get("/api/v1/models").respondWith().statusCode(200).jsonBody(rawResponseBody).build();
@@ -20,10 +18,7 @@ describe("ModelsClient", () => {
{
modelId: "model_id",
name: "name",
- properties: {
- contextLength: 1,
- maxOutputTokens: 1,
- },
+ properties: {},
},
],
});
diff --git a/packages/sdk/tests/wire/sessions.test.ts b/packages/sdk/tests/wire/sessions.test.ts
index 7871c880e..3e03cb797 100644
--- a/packages/sdk/tests/wire/sessions.test.ts
+++ b/packages/sdk/tests/wire/sessions.test.ts
@@ -12,13 +12,7 @@ describe("SessionsClient", () => {
const rawResponseBody = {
data: [
{
- agent_spec: {
- model: {
- model_id: "model_id",
- name: "name",
- properties: { context_length: 1, max_output_tokens: 1 },
- },
- },
+ agent_spec: { model: { name: "name" } },
created_at: "created_at",
id: "id",
title: "title",
@@ -41,12 +35,7 @@ describe("SessionsClient", () => {
{
agentSpec: {
model: {
- modelId: "model_id",
name: "name",
- properties: {
- contextLength: 1,
- maxOutputTokens: 1,
- },
},
},
createdAt: "created_at",
@@ -85,22 +74,14 @@ describe("SessionsClient", () => {
test("create (1)", async () => {
const server = mockServerPool.createServer();
const client = new TrueHarness({ maxRetries: 0, environment: server.baseUrl });
- const rawRequestBody = {
- agent_spec: {
- model: { model_id: "model_id", name: "name", properties: { context_length: 1, max_output_tokens: 1 } },
- },
- };
+ const rawRequestBody = { agent_spec: { model: { name: "name" } } };
const rawResponseBody = {
data: {
agent_spec: {
instructions: "instructions",
mcp_servers: [{ name: "name" }],
messages: [{ content: "content", type: "user.message" }],
- model: {
- model_id: "model_id",
- name: "name",
- properties: { context_length: 1, max_output_tokens: 1 },
- },
+ model: { name: "name" },
response_format: { type: "json_object" },
skills: [{ name: "name" }],
variables: { key: "value" },
@@ -124,12 +105,7 @@ describe("SessionsClient", () => {
const response = await client.sessions.create({
agentSpec: {
model: {
- modelId: "model_id",
name: "name",
- properties: {
- contextLength: 1,
- maxOutputTokens: 1,
- },
},
},
});
@@ -149,12 +125,7 @@ describe("SessionsClient", () => {
},
],
model: {
- modelId: "model_id",
name: "name",
- properties: {
- contextLength: 1,
- maxOutputTokens: 1,
- },
},
responseFormat: {
type: "json_object",
@@ -179,11 +150,7 @@ describe("SessionsClient", () => {
test("create (2)", async () => {
const server = mockServerPool.createServer();
const client = new TrueHarness({ maxRetries: 0, environment: server.baseUrl });
- const rawRequestBody = {
- agent_spec: {
- model: { model_id: "model_id", name: "name", properties: { context_length: 1, max_output_tokens: 1 } },
- },
- };
+ const rawRequestBody = { agent_spec: { model: { name: "x" } } };
const rawResponseBody = { error: { message: "message" } };
server
@@ -199,12 +166,7 @@ describe("SessionsClient", () => {
return await client.sessions.create({
agentSpec: {
model: {
- modelId: "model_id",
- name: "name",
- properties: {
- contextLength: 1,
- maxOutputTokens: 1,
- },
+ name: "x",
},
},
});
@@ -214,11 +176,7 @@ describe("SessionsClient", () => {
test("create (3)", async () => {
const server = mockServerPool.createServer();
const client = new TrueHarness({ maxRetries: 0, environment: server.baseUrl });
- const rawRequestBody = {
- agent_spec: {
- model: { model_id: "model_id", name: "name", properties: { context_length: 1, max_output_tokens: 1 } },
- },
- };
+ const rawRequestBody = { agent_spec: { model: { name: "x" } } };
const rawResponseBody = { error: { message: "message" } };
server
@@ -234,12 +192,7 @@ describe("SessionsClient", () => {
return await client.sessions.create({
agentSpec: {
model: {
- modelId: "model_id",
- name: "name",
- properties: {
- contextLength: 1,
- maxOutputTokens: 1,
- },
+ name: "x",
},
},
});
@@ -256,11 +209,7 @@ describe("SessionsClient", () => {
instructions: "instructions",
mcp_servers: [{ name: "name" }],
messages: [{ content: "content", type: "user.message" }],
- model: {
- model_id: "model_id",
- name: "name",
- properties: { context_length: 1, max_output_tokens: 1 },
- },
+ model: { name: "name" },
response_format: { type: "json_object" },
skills: [{ name: "name" }],
variables: { key: "value" },
@@ -297,12 +246,7 @@ describe("SessionsClient", () => {
},
],
model: {
- modelId: "model_id",
name: "name",
- properties: {
- contextLength: 1,
- maxOutputTokens: 1,
- },
},
responseFormat: {
type: "json_object",
@@ -363,11 +307,7 @@ describe("SessionsClient", () => {
instructions: "instructions",
mcp_servers: [{ name: "name" }],
messages: [{ content: "content", type: "user.message" }],
- model: {
- model_id: "model_id",
- name: "name",
- properties: { context_length: 1, max_output_tokens: 1 },
- },
+ model: { name: "name" },
response_format: { type: "json_object" },
skills: [{ name: "name" }],
variables: { key: "value" },
@@ -405,12 +345,7 @@ describe("SessionsClient", () => {
},
],
model: {
- modelId: "model_id",
name: "name",
- properties: {
- contextLength: 1,
- maxOutputTokens: 1,
- },
},
responseFormat: {
type: "json_object",
diff --git a/packages/sdk/tests/wire/settings/modelProviders.test.ts b/packages/sdk/tests/wire/settings/modelProviders.test.ts
index 6f04303ef..95716dd24 100644
--- a/packages/sdk/tests/wire/settings/modelProviders.test.ts
+++ b/packages/sdk/tests/wire/settings/modelProviders.test.ts
@@ -14,11 +14,9 @@ describe("ModelProvidersClient", () => {
{
auth: { api_key: "api_key" },
base_url: "base_url",
- models: [
- { model_id: "model_id", name: "name", properties: { context_length: 1, max_output_tokens: 1 } },
- ],
+ models: [{ model_id: "model_id", name: "name", properties: {} }],
name: "name",
- type: "anthropic",
+ type: "openai",
},
],
};
@@ -43,14 +41,11 @@ describe("ModelProvidersClient", () => {
{
modelId: "model_id",
name: "name",
- properties: {
- contextLength: 1,
- maxOutputTokens: 1,
- },
+ properties: {},
},
],
name: "name",
- type: "anthropic",
+ type: "openai",
},
],
});
@@ -61,19 +56,17 @@ describe("ModelProvidersClient", () => {
const client = new TrueHarness({ maxRetries: 0, environment: server.baseUrl });
const rawRequestBody = {
auth: { api_key: "api_key" },
- models: [{ model_id: "model_id", name: "name", properties: { context_length: 1, max_output_tokens: 1 } }],
+ models: [{ model_id: "model_id", name: "name", properties: {} }],
name: "name",
- type: "anthropic",
+ type: "openai",
};
const rawResponseBody = {
data: {
auth: { api_key: "api_key" },
base_url: "base_url",
- models: [
- { model_id: "model_id", name: "name", properties: { context_length: 1, max_output_tokens: 1 } },
- ],
+ models: [{ model_id: "model_id", name: "name", properties: {} }],
name: "name",
- type: "anthropic",
+ type: "openai",
},
};
@@ -94,14 +87,11 @@ describe("ModelProvidersClient", () => {
{
modelId: "model_id",
name: "name",
- properties: {
- contextLength: 1,
- maxOutputTokens: 1,
- },
+ properties: {},
},
],
name: "name",
- type: "anthropic",
+ type: "openai",
});
expect(response).toEqual({
data: {
@@ -113,14 +103,11 @@ describe("ModelProvidersClient", () => {
{
modelId: "model_id",
name: "name",
- properties: {
- contextLength: 1,
- maxOutputTokens: 1,
- },
+ properties: {},
},
],
name: "name",
- type: "anthropic",
+ type: "openai",
},
});
});
@@ -131,11 +118,11 @@ describe("ModelProvidersClient", () => {
const rawRequestBody = {
auth: { api_key: "x" },
models: [
- { model_id: "x", name: "xy", properties: { context_length: 1, max_output_tokens: 1 } },
- { model_id: "x", name: "xy", properties: { context_length: 1, max_output_tokens: 1 } },
+ { model_id: "x", name: "xy", properties: {} },
+ { model_id: "x", name: "xy", properties: {} },
],
name: "xy",
- type: "anthropic",
+ type: "openai",
};
const rawResponseBody = { error: { message: "message" } };
@@ -157,22 +144,16 @@ describe("ModelProvidersClient", () => {
{
modelId: "x",
name: "xy",
- properties: {
- contextLength: 1,
- maxOutputTokens: 1,
- },
+ properties: {},
},
{
modelId: "x",
name: "xy",
- properties: {
- contextLength: 1,
- maxOutputTokens: 1,
- },
+ properties: {},
},
],
name: "xy",
- type: "anthropic",
+ type: "openai",
});
}).rejects.toThrow(TrueHarnessTypes.BadRequestError);
});
@@ -182,15 +163,7 @@ describe("ModelProvidersClient", () => {
const client = new TrueHarness({ maxRetries: 0, environment: server.baseUrl });
const rawResponseBody = {
- data: [
- {
- models: [
- { model_id: "model_id", name: "name", properties: { context_length: 1, max_output_tokens: 1 } },
- ],
- name: "name",
- type: "openai",
- },
- ],
+ data: [{ models: [{ model_id: "model_id", name: "name", properties: {} }], name: "name", type: "openai" }],
};
server
@@ -209,10 +182,7 @@ describe("ModelProvidersClient", () => {
{
modelId: "model_id",
name: "name",
- properties: {
- contextLength: 1,
- maxOutputTokens: 1,
- },
+ properties: {},
},
],
name: "name",
diff --git a/packages/server/src/catalog/model-catalog.yaml b/packages/server/src/catalog/model-catalog.yaml
index d9c5977ca..ad64f22ab 100644
--- a/packages/server/src/catalog/model-catalog.yaml
+++ b/packages/server/src/catalog/model-catalog.yaml
@@ -5,18 +5,806 @@ providers:
- type: openai
name: openai
models:
- - model_id: gpt-5.6-sol
- name: gpt-5-6-sol
+ - model_id: chat-latest
+ name: chat-latest
properties:
context_length: 400000
+ max_output_tokens: 128000
+ reasoning_efforts:
+ - medium
+ - model_id: gpt-3.5-turbo-0125
+ name: gpt-3-5-turbo-0125
+ properties:
+ context_length: 16385
+ max_output_tokens: 4096
+ - model_id: gpt-3.5-turbo-1106
+ name: gpt-3-5-turbo-1106
+ properties:
+ max_output_tokens: 4096
+ - model_id: gpt-3.5-turbo
+ name: gpt-3-5-turbo
+ properties:
+ max_output_tokens: 4096
+ - model_id: gpt-4.1-2025-04-14
+ name: gpt-4-1-2025-04-14
+ properties:
+ context_length: 1047576
+ max_output_tokens: 32768
+ - model_id: gpt-4.1-mini-2025-04-14
+ name: gpt-4-1-mini-2025-04-14
+ properties:
+ context_length: 1047576
max_output_tokens: 32768
- reasoning_efforts: [low, medium, high]
+ - model_id: gpt-4.1-mini
+ name: gpt-4-1-mini
+ properties:
+ context_length: 1047576
+ max_output_tokens: 32768
+ - model_id: gpt-4.1
+ name: gpt-4-1
+ properties:
+ context_length: 1047576
+ max_output_tokens: 32768
+ - model_id: gpt-4o-2024-11-20
+ name: gpt-4o-2024-11-20
+ properties:
+ context_length: 128000
+ max_output_tokens: 16384
+ - model_id: gpt-4o-mini-2024-07-18
+ name: gpt-4o-mini-2024-07-18
+ properties:
+ context_length: 128000
+ max_output_tokens: 16384
+ - model_id: gpt-4o-mini
+ name: gpt-4o-mini
+ properties:
+ context_length: 128000
+ max_output_tokens: 16384
+ - model_id: gpt-4o
+ name: gpt-4o
+ properties:
+ context_length: 128000
+ max_output_tokens: 16384
+ - model_id: gpt-5-mini
+ name: gpt-5-mini
+ properties:
+ context_length: 400000
+ max_output_tokens: 128000
+ reasoning_efforts:
+ - minimal
+ - low
+ - medium
+ - high
+ - model_id: gpt-5-nano
+ name: gpt-5-nano
+ properties:
+ context_length: 400000
+ max_output_tokens: 128000
+ - model_id: gpt-5-pro
+ name: gpt-5-pro
+ properties:
+ context_length: 400000
+ max_output_tokens: 272000
+ - model_id: gpt-5.1-2025-11-13
+ name: gpt-5-1-2025-11-13
+ properties:
+ context_length: 400000
+ max_output_tokens: 128000
+ reasoning_efforts:
+ - none
+ - low
+ - medium
+ - high
+ - model_id: gpt-5.1
+ name: gpt-5-1
+ properties:
+ context_length: 400000
+ max_output_tokens: 128000
+ reasoning_efforts:
+ - none
+ - low
+ - medium
+ - high
+ - model_id: gpt-5.2-2025-12-11
+ name: gpt-5-2-2025-12-11
+ properties:
+ context_length: 400000
+ max_output_tokens: 128000
+ reasoning_efforts:
+ - none
+ - low
+ - medium
+ - high
+ - xhigh
+ - model_id: gpt-5.2-pro-2025-12-11
+ name: gpt-5-2-pro-2025-12-11
+ properties:
+ context_length: 400000
+ max_output_tokens: 128000
+ reasoning_efforts:
+ - medium
+ - high
+ - xhigh
+ - model_id: gpt-5.2-pro
+ name: gpt-5-2-pro
+ properties:
+ context_length: 400000
+ max_output_tokens: 128000
+ reasoning_efforts:
+ - medium
+ - high
+ - xhigh
+ - model_id: gpt-5.2
+ name: gpt-5-2
+ properties:
+ context_length: 400000
+ max_output_tokens: 128000
+ reasoning_efforts:
+ - none
+ - low
+ - medium
+ - high
+ - xhigh
+ - model_id: gpt-5.4-2026-03-05
+ name: gpt-5-4-2026-03-05
+ properties:
+ context_length: 1050000
+ max_output_tokens: 128000
+ reasoning_efforts:
+ - none
+ - low
+ - medium
+ - high
+ - xhigh
+ - model_id: gpt-5.4-mini-2026-03-17
+ name: gpt-5-4-mini-2026-03-17
+ properties:
+ context_length: 400000
+ max_output_tokens: 128000
+ reasoning_efforts:
+ - none
+ - low
+ - medium
+ - high
+ - xhigh
+ - model_id: gpt-5.4-mini
+ name: gpt-5-4-mini
+ properties:
+ context_length: 400000
+ max_output_tokens: 128000
+ reasoning_efforts:
+ - none
+ - low
+ - medium
+ - high
+ - xhigh
+ - model_id: gpt-5.4-nano-2026-03-17
+ name: gpt-5-4-nano-2026-03-17
+ properties:
+ context_length: 400000
+ max_output_tokens: 128000
+ reasoning_efforts:
+ - none
+ - low
+ - medium
+ - high
+ - xhigh
+ - model_id: gpt-5.4-nano
+ name: gpt-5-4-nano
+ properties:
+ context_length: 400000
+ max_output_tokens: 128000
+ reasoning_efforts:
+ - none
+ - low
+ - medium
+ - high
+ - xhigh
+ - model_id: gpt-5.4-pro-2026-03-05
+ name: gpt-5-4-pro-2026-03-05
+ properties:
+ context_length: 1050000
+ max_output_tokens: 128000
+ reasoning_efforts:
+ - medium
+ - high
+ - xhigh
+ - model_id: gpt-5.4-pro
+ name: gpt-5-4-pro
+ properties:
+ context_length: 1050000
+ max_output_tokens: 128000
+ reasoning_efforts:
+ - medium
+ - high
+ - xhigh
+ - model_id: gpt-5.4
+ name: gpt-5-4
+ properties:
+ context_length: 1050000
+ max_output_tokens: 128000
+ reasoning_efforts:
+ - none
+ - low
+ - medium
+ - high
+ - xhigh
+ - model_id: gpt-5.5-2026-04-23
+ name: gpt-5-5-2026-04-23
+ properties:
+ context_length: 1050000
+ max_output_tokens: 128000
+ reasoning_efforts:
+ - none
+ - low
+ - medium
+ - high
+ - xhigh
+ - model_id: gpt-5.5-pro-2026-04-23
+ name: gpt-5-5-pro-2026-04-23
+ properties:
+ context_length: 1050000
+ max_output_tokens: 128000
+ reasoning_efforts:
+ - medium
+ - high
+ - xhigh
+ - model_id: gpt-5.5-pro
+ name: gpt-5-5-pro
+ properties:
+ context_length: 1050000
+ max_output_tokens: 128000
+ reasoning_efforts:
+ - medium
+ - high
+ - xhigh
+ - model_id: gpt-5.5
+ name: gpt-5-5
+ properties:
+ context_length: 1050000
+ max_output_tokens: 128000
+ reasoning_efforts:
+ - none
+ - low
+ - medium
+ - high
+ - xhigh
+ - model_id: gpt-5.6-luna
+ name: gpt-5-6-luna
+ properties:
+ context_length: 1050000
+ max_output_tokens: 128000
+ reasoning_efforts:
+ - none
+ - low
+ - medium
+ - high
+ - xhigh
+ - max
+ - model_id: gpt-5.6-sol
+ name: gpt-5-6-sol
+ properties:
+ context_length: 1050000
+ max_output_tokens: 128000
+ reasoning_efforts:
+ - none
+ - low
+ - medium
+ - high
+ - xhigh
+ - max
+ - model_id: gpt-5.6-terra
+ name: gpt-5-6-terra
+ properties:
+ context_length: 1050000
+ max_output_tokens: 128000
+ reasoning_efforts:
+ - none
+ - low
+ - medium
+ - high
+ - xhigh
+ - max
- type: anthropic
name: anthropic
models:
+ - model_id: claude-fable-5
+ name: claude-fable-5
+ properties:
+ context_length: 1000000
+ max_output_tokens: 128000
+ - model_id: claude-haiku-4-5-20251001
+ name: claude-haiku-4-5-20251001
+ properties:
+ context_length: 200000
+ max_output_tokens: 64000
+ - model_id: claude-haiku-4-5
+ name: claude-haiku-4-5
+ properties:
+ context_length: 200000
+ max_output_tokens: 64000
+ - model_id: claude-opus-4-5-20251101
+ name: claude-opus-4-5-20251101
+ properties:
+ context_length: 200000
+ max_output_tokens: 64000
+ reasoning_efforts:
+ - low
+ - medium
+ - high
+ - model_id: claude-opus-4-5
+ name: claude-opus-4-5
+ properties:
+ context_length: 200000
+ max_output_tokens: 64000
+ reasoning_efforts:
+ - low
+ - medium
+ - high
+ - model_id: claude-opus-4-6
+ name: claude-opus-4-6
+ properties:
+ context_length: 1000000
+ max_output_tokens: 128000
+ reasoning_efforts:
+ - low
+ - medium
+ - high
+ - max
+ - model_id: claude-opus-4-7
+ name: claude-opus-4-7
+ properties:
+ context_length: 1000000
+ max_output_tokens: 128000
+ - model_id: claude-opus-4-8
+ name: claude-opus-4-8
+ properties:
+ context_length: 1000000
+ max_output_tokens: 128000
+ - model_id: claude-opus-5
+ name: claude-opus-5
+ properties:
+ context_length: 1000000
+ max_output_tokens: 128000
+ - model_id: claude-sonnet-4-5-20250929
+ name: claude-sonnet-4-5-20250929
+ properties:
+ context_length: 200000
+ max_output_tokens: 64000
+ - model_id: claude-sonnet-4-5
+ name: claude-sonnet-4-5
+ properties:
+ context_length: 200000
+ max_output_tokens: 64000
- model_id: claude-sonnet-4-6
name: claude-sonnet-4-6
properties:
- context_length: 200000
+ context_length: 1000000
+ max_output_tokens: 128000
+ reasoning_efforts:
+ - low
+ - medium
+ - high
+ - max
+ - model_id: claude-sonnet-5
+ name: claude-sonnet-5
+ properties:
+ context_length: 1000000
+ max_output_tokens: 128000
+ - type: google-gemini
+ name: google-gemini
+ models:
+ - model_id: gemini-2.5-flash-lite
+ name: gemini-2-5-flash-lite
+ properties:
+ context_length: 1048576
+ max_output_tokens: 65536
+ - model_id: gemini-2.5-flash
+ name: gemini-2-5-flash
+ properties:
+ max_output_tokens: 65536
+ - model_id: gemini-2.5-pro
+ name: gemini-2-5-pro
+ properties:
+ max_output_tokens: 65536
+ - model_id: gemini-3-flash-preview
+ name: gemini-3-flash-preview
+ properties:
+ context_length: 1048576
+ max_output_tokens: 65536
+ - model_id: gemini-3.1-flash-lite
+ name: gemini-3-1-flash-lite
+ properties:
+ context_length: 1048576
+ max_output_tokens: 65536
+ reasoning_efforts:
+ - minimal
+ - low
+ - medium
+ - high
+ - model_id: gemini-3.1-pro-preview-customtools
+ name: gemini-3-1-pro-preview-customtools
+ properties:
+ context_length: 1048576
+ max_output_tokens: 65536
+ reasoning_efforts:
+ - low
+ - medium
+ - high
+ - model_id: gemini-3.1-pro-preview
+ name: gemini-3-1-pro-preview
+ properties:
+ context_length: 1048576
+ max_output_tokens: 65536
+ reasoning_efforts:
+ - low
+ - medium
+ - high
+ - model_id: gemini-3.5-flash-lite
+ name: gemini-3-5-flash-lite
+ properties:
+ context_length: 1048576
+ max_output_tokens: 65536
+ - model_id: gemini-3.5-flash
+ name: gemini-3-5-flash
+ properties:
+ context_length: 1048576
+ max_output_tokens: 65536
+ reasoning_efforts:
+ - low
+ - medium
+ - high
+ - model_id: gemini-3.6-flash
+ name: gemini-3-6-flash
+ properties:
+ context_length: 1048576
+ max_output_tokens: 65536
+ - model_id: gemini-flash-latest
+ name: gemini-flash-latest
+ properties:
+ context_length: 1048576
+ max_output_tokens: 65536
+ - model_id: gemini-flash-lite-latest
+ name: gemini-flash-lite-latest
+ properties:
+ context_length: 1048576
+ max_output_tokens: 65536
+ - model_id: gemini-pro-latest
+ name: gemini-pro-latest
+ properties:
+ max_output_tokens: 65536
+ - model_id: gemini-robotics-er-1.6-preview
+ name: gemini-robotics-er-1-6-preview
+ properties:
+ context_length: 131072
+ max_output_tokens: 65536
+ - model_id: gemini-robotics-er-2-preview
+ name: gemini-robotics-er-2-preview
+ properties:
+ context_length: 131072
+ max_output_tokens: 65536
+ - model_id: gemma-4-26b-a4b-it
+ name: gemma-4-26b-a4b-it
+ properties:
+ context_length: 262144
max_output_tokens: 32768
- reasoning_efforts: [low, medium, high]
+ - model_id: gemma-4-31b-it
+ name: gemma-4-31b-it
+ properties:
+ context_length: 256000
+ - type: fireworks
+ name: fireworks
+ models:
+ - model_id: accounts/fireworks/models/deepseek-v4-flash
+ name: deepseek-v4-flash
+ properties:
+ context_length: 1048576
+ - model_id: accounts/fireworks/models/deepseek-v4-flash-0731
+ name: deepseek-v4-flash-0731
+ properties:
+ context_length: 1048576
+ - model_id: accounts/fireworks/models/deepseek-v4-pro
+ name: deepseek-v4-pro
+ properties:
+ context_length: 1048576
+ - model_id: accounts/fireworks/models/glm-5p2
+ name: glm-5p2
+ properties:
+ context_length: 1048576
+ - model_id: accounts/fireworks/models/gpt-oss-120b
+ name: gpt-oss-120b
+ properties:
+ context_length: 131072
+ - model_id: accounts/fireworks/models/gpt-oss-20b
+ name: gpt-oss-20b
+ properties:
+ context_length: 131072
+ - model_id: accounts/fireworks/models/inkling
+ name: inkling
+ properties:
+ context_length: 1048576
+ - model_id: accounts/fireworks/models/kimi-k2p6
+ name: kimi-k2p6
+ properties:
+ context_length: 262144
+ - model_id: accounts/fireworks/models/kimi-k2p7-code
+ name: kimi-k2p7-code
+ properties:
+ context_length: 262144
+ - model_id: accounts/fireworks/models/kimi-k3
+ name: kimi-k3
+ properties:
+ context_length: 1048576
+ - model_id: accounts/fireworks/models/minimax-m2p7
+ name: minimax-m2p7
+ properties:
+ context_length: 196608
+ - model_id: accounts/fireworks/models/minimax-m3
+ name: minimax-m3
+ properties:
+ context_length: 512000
+ - model_id: accounts/fireworks/models/nemotron-3-ultra-nvfp4
+ name: nemotron-3-ultra-nvfp4
+ properties:
+ context_length: 262144
+ - model_id: accounts/fireworks/routers/glm-5p2-fast
+ name: glm-5p2-fast
+ properties:
+ context_length: 1048576
+ - model_id: accounts/fireworks/routers/kimi-k2p6-turbo
+ name: kimi-k2p6-turbo
+ properties:
+ context_length: 262144
+ - model_id: accounts/fireworks/routers/kimi-k2p7-code-fast
+ name: kimi-k2p7-code-fast
+ properties:
+ context_length: 262144
+ - model_id: accounts/fireworks/routers/kimi-k3-fast
+ name: kimi-k3-fast
+ properties:
+ context_length: 1048576
+ - type: zai
+ name: zai
+ models:
+ - model_id: glm-4.5
+ name: glm-4-5
+ properties: {}
+ - model_id: glm-4.5-air
+ name: glm-4-5-air
+ properties: {}
+ - model_id: glm-4.6
+ name: glm-4-6
+ properties: {}
+ - model_id: glm-4.7
+ name: glm-4-7
+ properties: {}
+ - model_id: glm-5
+ name: glm-5
+ properties: {}
+ - model_id: glm-5-turbo
+ name: glm-5-turbo
+ properties: {}
+ - model_id: glm-5.1
+ name: glm-5-1
+ properties: {}
+ - model_id: glm-5.2
+ name: glm-5-2
+ properties: {}
+ - type: moonshot
+ name: moonshot
+ models:
+ - model_id: kimi-k2.6
+ name: kimi-k2-6
+ properties:
+ context_length: 262144
+ - model_id: kimi-k2.7-code
+ name: kimi-k2-7-code
+ properties:
+ context_length: 262144
+ - model_id: kimi-k2.7-code-highspeed
+ name: kimi-k2-7-code-highspeed
+ properties:
+ context_length: 262144
+ - model_id: kimi-k3
+ name: kimi-k3
+ properties:
+ context_length: 1048576
+ reasoning_efforts:
+ - low
+ - high
+ - max
+ - type: alibaba
+ name: alibaba
+ models:
+ - model_id: deepseek-v3.2
+ name: deepseek-v3-2
+ properties: {}
+ - model_id: deepseek-v4-flash
+ name: deepseek-v4-flash
+ properties: {}
+ - model_id: deepseek-v4-flash-0731
+ name: deepseek-v4-flash-0731
+ properties: {}
+ - model_id: deepseek-v4-pro
+ name: deepseek-v4-pro
+ properties: {}
+ - model_id: glm-5.1
+ name: glm-5-1
+ properties: {}
+ - model_id: glm-5.2
+ name: glm-5-2
+ properties: {}
+ - model_id: kimi-k2.7-code
+ name: kimi-k2-7-code
+ properties: {}
+ - model_id: qwen-coder-plus
+ name: qwen-coder-plus
+ properties: {}
+ - model_id: qwen-flash
+ name: qwen-flash
+ properties: {}
+ - model_id: qwen-flash-character
+ name: qwen-flash-character
+ properties: {}
+ - model_id: qwen-max
+ name: qwen-max
+ properties: {}
+ - model_id: qwen-plus
+ name: qwen-plus
+ properties: {}
+ - model_id: qwen-plus-2025-04-28
+ name: qwen-plus-2025-04-28
+ properties: {}
+ - model_id: qwen-plus-2025-09-11
+ name: qwen-plus-2025-09-11
+ properties: {}
+ - model_id: qwen-plus-2025-12-01
+ name: qwen-plus-2025-12-01
+ properties: {}
+ - model_id: qwen-plus-character
+ name: qwen-plus-character
+ properties: {}
+ - model_id: qwen-plus-latest
+ name: qwen-plus-latest
+ properties: {}
+ - model_id: qwen-turbo
+ name: qwen-turbo
+ properties: {}
+ - model_id: qwen3-14b
+ name: qwen3-14b
+ properties: {}
+ - model_id: qwen3-235b-a22b
+ name: qwen3-235b-a22b
+ properties: {}
+ - model_id: qwen3-235b-a22b-instruct-2507
+ name: qwen3-235b-a22b-instruct-2507
+ properties: {}
+ - model_id: qwen3-235b-a22b-thinking-2507
+ name: qwen3-235b-a22b-thinking-2507
+ properties: {}
+ - model_id: qwen3-30b-a3b
+ name: qwen3-30b-a3b
+ properties: {}
+ - model_id: qwen3-30b-a3b-instruct-2507
+ name: qwen3-30b-a3b-instruct-2507
+ properties: {}
+ - model_id: qwen3-30b-a3b-thinking-2507
+ name: qwen3-30b-a3b-thinking-2507
+ properties: {}
+ - model_id: qwen3-8b
+ name: qwen3-8b
+ properties: {}
+ - model_id: qwen3-coder-480b-a35b-instruct
+ name: qwen3-coder-480b-a35b-instruct
+ properties: {}
+ - model_id: qwen3-coder-flash
+ name: qwen3-coder-flash
+ properties: {}
+ - model_id: qwen3-coder-next
+ name: qwen3-coder-next
+ properties: {}
+ - model_id: qwen3-coder-plus
+ name: qwen3-coder-plus
+ properties: {}
+ - model_id: qwen3-coder-plus-2025-07-22
+ name: qwen3-coder-plus-2025-07-22
+ properties: {}
+ - model_id: qwen3-coder-plus-2025-09-23
+ name: qwen3-coder-plus-2025-09-23
+ properties: {}
+ - model_id: qwen3-max
+ name: qwen3-max
+ properties: {}
+ - model_id: qwen3-max-2025-09-23
+ name: qwen3-max-2025-09-23
+ properties: {}
+ - model_id: qwen3-max-2026-01-23
+ name: qwen3-max-2026-01-23
+ properties: {}
+ - model_id: qwen3-max-preview
+ name: qwen3-max-preview
+ properties: {}
+ - model_id: qwen3-next-80b-a3b-instruct
+ name: qwen3-next-80b-a3b-instruct
+ properties: {}
+ - model_id: qwen3-next-80b-a3b-thinking
+ name: qwen3-next-80b-a3b-thinking
+ properties: {}
+ - model_id: qwen3.5-122b-a10b
+ name: qwen3-5-122b-a10b
+ properties: {}
+ - model_id: qwen3.5-27b
+ name: qwen3-5-27b
+ properties: {}
+ - model_id: qwen3.5-35b-a3b
+ name: qwen3-5-35b-a3b
+ properties: {}
+ - model_id: qwen3.5-397b-a17b
+ name: qwen3-5-397b-a17b
+ properties: {}
+ - model_id: qwen3.5-flash
+ name: qwen3-5-flash
+ properties: {}
+ - model_id: qwen3.5-flash-2026-02-23
+ name: qwen3-5-flash-2026-02-23
+ properties: {}
+ - model_id: qwen3.5-plus
+ name: qwen3-5-plus
+ properties: {}
+ - model_id: qwen3.5-plus-2026-02-15
+ name: qwen3-5-plus-2026-02-15
+ properties: {}
+ - model_id: qwen3.5-plus-2026-04-20
+ name: qwen3-5-plus-2026-04-20
+ properties: {}
+ - model_id: qwen3.6-27b
+ name: qwen3-6-27b
+ properties: {}
+ - model_id: qwen3.6-35b-a3b
+ name: qwen3-6-35b-a3b
+ properties: {}
+ - model_id: qwen3.6-flash
+ name: qwen3-6-flash
+ properties: {}
+ - model_id: qwen3.6-flash-2026-04-16
+ name: qwen3-6-flash-2026-04-16
+ properties: {}
+ - model_id: qwen3.6-max-preview
+ name: qwen3-6-max-preview
+ properties: {}
+ - model_id: qwen3.6-plus
+ name: qwen3-6-plus
+ properties: {}
+ - model_id: qwen3.6-plus-2026-04-02
+ name: qwen3-6-plus-2026-04-02
+ properties: {}
+ - model_id: qwen3.7-flash
+ name: qwen3-7-flash
+ properties: {}
+ - model_id: qwen3.7-flash-2026-07-15
+ name: qwen3-7-flash-2026-07-15
+ properties: {}
+ - model_id: qwen3.7-max
+ name: qwen3-7-max
+ properties: {}
+ - model_id: qwen3.7-max-2026-05-17
+ name: qwen3-7-max-2026-05-17
+ properties: {}
+ - model_id: qwen3.7-max-2026-05-20
+ name: qwen3-7-max-2026-05-20
+ properties: {}
+ - model_id: qwen3.7-max-2026-06-08
+ name: qwen3-7-max-2026-06-08
+ properties: {}
+ - model_id: qwen3.7-max-preview
+ name: qwen3-7-max-preview
+ properties: {}
+ - model_id: qwen3.7-plus
+ name: qwen3-7-plus
+ properties: {}
+ - model_id: qwen3.7-plus-2026-05-26
+ name: qwen3-7-plus-2026-05-26
+ properties: {}
+ - model_id: qwen3.8-max
+ name: qwen3-8-max
+ properties: {}
diff --git a/packages/server/src/runtime/sessionResources.ts b/packages/server/src/runtime/sessionResources.ts
index 5b0142e3d..01f22d83e 100644
--- a/packages/server/src/runtime/sessionResources.ts
+++ b/packages/server/src/runtime/sessionResources.ts
@@ -24,6 +24,7 @@ import type { IModelProviderStore } from '../db/modelProviderStore';
import type { ISandboxProviderStore } from '../db/sandboxProviderStore';
import type { ISkillStore } from '../db/skillStore';
import { resolveConfiguredMcpRequestHeaders } from '../schemas/mcpServer';
+import { PROVIDER_DEFAULT_BASE_URLS } from '../schemas/modelProvider';
import { toDaytonaSandboxProviderInput } from '../schemas/sandboxProvider';
export interface McpConnection {
@@ -74,11 +75,14 @@ export async function getProviderConfig({
message: `Unknown model "${name}" — not configured on provider`,
});
}
+ // Provider types are adapter names, so this assignment is what keeps them so: a type with no
+ // `buildLanguageModel` case fails to compile here. An explicit base_url always wins.
+ const { type, base_url } = provider.manifest;
return {
- provider: provider.manifest.type,
+ provider: type,
name,
- model_id: model.model_id,
- base_url: provider.manifest.base_url,
+ modelId: model.model_id,
+ baseUrl: base_url ?? PROVIDER_DEFAULT_BASE_URLS[type],
apiKey: provider.manifest.auth.api_key,
headers: {},
};
diff --git a/packages/server/src/schemas/modelProvider.ts b/packages/server/src/schemas/modelProvider.ts
index 8cf5ea3cf..10f236ca4 100644
--- a/packages/server/src/schemas/modelProvider.ts
+++ b/packages/server/src/schemas/modelProvider.ts
@@ -4,15 +4,62 @@
* ModelCatalog.
*/
import { z } from '@hono/zod-openapi';
+import type { VercelAIProviderName } from '@truefoundry/utils-core/core';
+import { SUPPORTED_REASONING_EFFORTS } from '@truefoundry/utils-core/core';
import { NameSchema, uniqueNames } from './common';
-export const ProviderTypeSchema = z.enum(['openai', 'anthropic', 'custom']).openapi('ProviderType');
+/**
+ * A provider's endpoint is either already known or it isn't, and that is the only thing the wire
+ * shape turns on. `openai`, `anthropic` and `google-gemini` get theirs from their dedicated Vercel
+ * AI SDK adapter; the OpenAI-compatible ones named here get {@link PROVIDER_DEFAULT_BASE_URLS}.
+ *
+ * `satisfies` ties both lists to the adapters the harness can actually build. A type missing from
+ * them is the dangerous direction — its catalog entries would be unconfigurable — so a test asserts
+ * the two together cover every adapter.
+ */
+const WELL_KNOWN_BASE_URL_TYPES = [
+ 'openai',
+ 'anthropic',
+ 'google-gemini',
+ 'fireworks',
+ 'zai',
+ 'moonshot',
+] as const satisfies readonly VercelAIProviderName[];
+
+/** `alibaba` scopes its endpoint to the caller's workspace, `custom` is arbitrary by definition. */
+const CALLER_SUPPLIED_BASE_URL_TYPES = ['alibaba', 'custom'] as const satisfies readonly VercelAIProviderName[];
+
+export const ProviderTypeSchema = z
+ .enum([...WELL_KNOWN_BASE_URL_TYPES, ...CALLER_SUPPLIED_BASE_URL_TYPES])
+ .openapi('ProviderType');
+
+export type ProviderType = z.infer<typeof ProviderTypeSchema>;
+
+/**
+ * Endpoint to use when a manifest omits `base_url`. Absent means the provider's adapter supplies its
+ * own, or that the schema required a `base_url` in the first place.
+ */
+export const PROVIDER_DEFAULT_BASE_URLS: Partial<Record<ProviderType, string>> = {
+ fireworks: 'https://api.fireworks.ai/inference/v1',
+ zai: 'https://api.z.ai/api/paas/v4',
+ moonshot: 'https://api.moonshot.ai/v1',
+};
export const ModelPropertiesSchema = z
.object({
- context_length: z.number().int().positive(),
- max_output_tokens: z.number().int().positive(),
- reasoning_efforts: z.array(z.string().min(1)).min(1).optional(),
+ context_length: z.number().int().positive().optional(),
+ max_output_tokens: z.number().int().positive().optional(),
+ reasoning_efforts: z
+ .array(
+ z
+ .string()
+ .min(1)
+ .refine(effort => SUPPORTED_REASONING_EFFORTS.includes(effort), {
+ message: `Reasoning effort must be one of: ${SUPPORTED_REASONING_EFFORTS.join(', ')}`,
+ }),
+ )
+ .min(1)
+ .optional(),
})
.strict()
.openapi('ModelProperties');
@@ -56,22 +103,15 @@ const ModelProviderManifestBaseSchema = z
})
.strict();
-/** Shared by openai/anthropic: optional override of the provider's default endpoint. */
-const WellKnownModelProviderManifestBaseSchema = ModelProviderManifestBaseSchema.extend({
+/** The endpoint is already known, so `base_url` only overrides it. */
+const WellKnownModelProviderManifestSchema = ModelProviderManifestBaseSchema.extend({
+ type: z.enum(WELL_KNOWN_BASE_URL_TYPES),
base_url: z.string().url().optional().describe("Optional override of the provider's default API base URL."),
}).strict();
-const OpenAIModelProviderManifestSchema = WellKnownModelProviderManifestBaseSchema.extend({
- type: z.literal('openai'),
-}).strict();
-
-const AnthropicModelProviderManifestSchema = WellKnownModelProviderManifestBaseSchema.extend({
- type: z.literal('anthropic'),
-}).strict();
-
-/** Same fields as well-known providers, but base_url is required (no canonical endpoint). */
-const CustomModelProviderManifestSchema = ModelProviderManifestBaseSchema.extend({
- type: z.literal('custom'),
+/** Nothing to fall back on, so `base_url` is required. */
+const CallerSuppliedModelProviderManifestSchema = ModelProviderManifestBaseSchema.extend({
+ type: z.enum(CALLER_SUPPLIED_BASE_URL_TYPES),
base_url: z.string().url().describe("Base URL of the provider's API."),
}).strict();
@@ -79,10 +119,9 @@ const CustomModelProviderManifestSchema = ModelProviderManifestBaseSchema.extend
* Non-identity fields of a configured provider, shared verbatim between the
* PUT request body and the persisted `model_provider.manifest` document.
*/
-export const ModelProviderManifestObjectSchema = z.discriminatedUnion('type', [
- OpenAIModelProviderManifestSchema,
- AnthropicModelProviderManifestSchema,
- CustomModelProviderManifestSchema,
+export const ModelProviderManifestObjectSchema = z.union([
+ WellKnownModelProviderManifestSchema,
+ CallerSuppliedModelProviderManifestSchema,
]);
export function refineModelProviderManifest(
@@ -95,30 +134,20 @@ export function refineModelProviderManifest(
export type ModelProperties = z.infer<typeof ModelPropertiesSchema>;
export type ModelProviderManifest = z.infer<typeof ModelProviderManifestObjectSchema>;
-const OpenAIModelProviderSchema = OpenAIModelProviderManifestSchema.extend({
- name: NameSchema,
-})
- .strict()
- .openapi('OpenAIModelProvider');
-
-const AnthropicModelProviderSchema = AnthropicModelProviderManifestSchema.extend({
- name: NameSchema,
-})
+const WellKnownModelProviderSchema = WellKnownModelProviderManifestSchema.extend({ name: NameSchema })
.strict()
- .openapi('AnthropicModelProvider');
+ .openapi('WellKnownModelProvider');
-const CustomModelProviderSchema = CustomModelProviderManifestSchema.extend({
- name: NameSchema,
-})
+const CallerSuppliedModelProviderSchema = CallerSuppliedModelProviderManifestSchema.extend({ name: NameSchema })
.strict()
- .openapi('CustomModelProvider');
+ .openapi('CallerSuppliedModelProvider');
/**
* Configured provider: PUT body and list/upsert response data (identity `name`
* plus manifest fields, including `auth.api_key`).
*/
export const ModelProviderSchema = z
- .discriminatedUnion('type', [OpenAIModelProviderSchema, AnthropicModelProviderSchema, CustomModelProviderSchema])
+ .union([WellKnownModelProviderSchema, CallerSuppliedModelProviderSchema])
.superRefine(refineModelProviderManifest)
.openapi('ModelProvider');
diff --git a/packages/server/tests/unit/apis/modelProviders.test.ts b/packages/server/tests/unit/apis/modelProviders.test.ts
index 76991e54b..14edd3819 100644
--- a/packages/server/tests/unit/apis/modelProviders.test.ts
+++ b/packages/server/tests/unit/apis/modelProviders.test.ts
@@ -42,15 +42,15 @@ function putInit(body: unknown): RequestInit {
};
}
-describe('settings model-providers and models routers', () => {
- let settingsRouter: ReturnType<typeof createSettingsRouter>;
- let modelsRouter: ReturnType<typeof createModelsRouter>;
-
- beforeAll(async () => {
- const db = createSqliteDb(':memory:');
- await migrateSqliteToLatest(db);
- const modelProviderStore = new SqliteModelProviderStore(db);
- settingsRouter = createSettingsRouter({
+async function createRouters(): Promise<{
+ settingsRouter: ReturnType<typeof createSettingsRouter>;
+ modelsRouter: ReturnType<typeof createModelsRouter>;
+}> {
+ const db = createSqliteDb(':memory:');
+ await migrateSqliteToLatest(db);
+ const modelProviderStore = new SqliteModelProviderStore(db);
+ return {
+ settingsRouter: createSettingsRouter({
modelCatalog: ModelCatalog.load(),
modelProviderStore,
mcpCatalog: McpCatalog.load(),
@@ -61,8 +61,17 @@ describe('settings model-providers and models routers', () => {
sandboxCatalog: SandboxCatalog.load(),
sandboxProviderStore: new SqliteSandboxProviderStore(db),
logger: winston.createLogger({ silent: true }),
- });
- modelsRouter = createModelsRouter(modelProviderStore);
+ }),
+ modelsRouter: createModelsRouter(modelProviderStore),
+ };
+}
+
+describe('settings model-providers and models routers', () => {
+ let settingsRouter: ReturnType<typeof createSettingsRouter>;
+ let modelsRouter: ReturnType<typeof createModelsRouter>;
+
+ beforeAll(async () => {
+ ({ settingsRouter, modelsRouter } = await createRouters());
});
it('GET /model-providers/catalog returns the shipped catalog verbatim', async () => {
@@ -121,3 +130,20 @@ describe('settings model-providers and models routers', () => {
});
});
});
+
+describe('catalog presets are configurable', () => {
+ // A preset is meant to be copied into a PUT body with an api_key added. Every type the catalog
+ // ships must therefore be in the configuration union; five of them once were not.
+ it.each(ModelCatalog.load().list())('PUT accepts the $type preset', async preset => {
+ const { settingsRouter } = await createRouters();
+ const body = {
+ ...preset,
+ auth: { api_key: `sk-${preset.name}` },
+ // Alibaba is the one catalog type that also needs a base_url: a MaaS host embeds the
+ // workspace id, so there is nothing to default to.
+ ...(preset.type === 'alibaba' ? { base_url: 'https://ws-x.ap-southeast-1.maas.aliyuncs.com/v1' } : {}),
+ };
+ const response = await settingsRouter.request('/model-providers', putInit(body));
+ expect(response.status).toBe(200);
+ });
+});
diff --git a/packages/server/tests/unit/schemas/modelProvider.test.ts b/packages/server/tests/unit/schemas/modelProvider.test.ts
new file mode 100644
index 000000000..5d45252db
--- /dev/null
+++ b/packages/server/tests/unit/schemas/modelProvider.test.ts
@@ -0,0 +1,39 @@
+import { VERCEL_AI_PROVIDER_NAMES } from '@truefoundry/utils-core/core';
+import { ModelProviderManifestObjectSchema, PROVIDER_DEFAULT_BASE_URLS } from '../../../src/schemas/modelProvider';
+
+const models = [{ model_id: 'a-model', name: 'a-model', properties: {} }];
+
+function parses(body: Record<string, unknown>): boolean {
+ return ModelProviderManifestObjectSchema.safeParse({ auth: { api_key: 'k' }, models, ...body }).success;
+}
+
+describe('ModelProviderManifestObjectSchema', () => {
+ // The `satisfies` on the two type lists rejects a name with no adapter, but not an adapter left
+ // out of both lists. That omission is what once left most of the catalog unconfigurable.
+ it('can configure every adapter the harness can build', () => {
+ const rejected = VERCEL_AI_PROVIDER_NAMES.filter(type => !parses({ type, base_url: 'https://example.com/v1' }));
+ expect(rejected).toEqual([]);
+ });
+
+ // Omitting base_url is only safe when something downstream supplies one, otherwise
+ // buildLanguageModel throws at turn time instead of the API rejecting the config.
+ it('only allows omitting base_url where an endpoint is known', () => {
+ for (const type of VERCEL_AI_PROVIDER_NAMES) {
+ const dedicatedAdapter = ['openai', 'anthropic', 'google-gemini'].includes(type);
+ const hasEndpoint = dedicatedAdapter || PROVIDER_DEFAULT_BASE_URLS[type] !== undefined;
+ expect([type, parses({ type })]).toEqual([type, hasEndpoint]);
+ }
+ });
+
+ // An effort the adapter cannot map is dropped on the way to the provider, so a session that
+ // requests it runs at the provider default and reports success.
+ it('rejects a reasoning effort no adapter can honour', () => {
+ const withEfforts = (efforts: string[]): boolean =>
+ parses({
+ type: 'anthropic',
+ models: [{ model_id: 'a-model', name: 'a-model', properties: { reasoning_efforts: efforts } }],
+ });
+ expect(withEfforts(['low', 'medium', 'high', 'max'])).toBe(true);
+ expect(withEfforts(['ultra'])).toBe(false);
+ });
+});
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 337d24a86..c3b57ffc5 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -104,18 +104,30 @@ importers:
packages/harness:
dependencies:
+ '@ai-sdk/alibaba':
+ specifier: ^2.0.24
+ version: 2.0.24([email protected])
'@ai-sdk/anthropic':
specifier: ^4.0.25
version: 4.0.29([email protected])
'@ai-sdk/google':
specifier: ^4.0.29
version: 4.0.33([email protected])
+ '@ai-sdk/moonshotai':
+ specifier: ^3.0.25
+ version: 3.0.25([email protected])
'@ai-sdk/openai':
specifier: ^4.0.25
version: 4.0.29([email protected])
'@ai-sdk/openai-compatible':
specifier: ^3.0.18
version: 3.0.22([email protected])
+ '@ai-sdk/provider':
+ specifier: ^4.0.4
+ version: 4.0.5
+ '@ai-sdk/provider-utils':
+ specifier: ^5.0.16
+ version: 5.0.20([email protected])
'@daytona/sdk':
specifier: ^0.190.0
@@ -271,6 +283,12 @@ packages:
resolution: {integrity: sha512-11UocR7fFdMWw503bWCX2IOK15vbWfxT11Mn9xOiPBVO/UVcn57ywGrlLL4UaBlPgmUTvuzr2yYR2ElSqiN2wQ==}
+ '@ai-sdk/[email protected]':
+ resolution: {integrity: sha512-54kjLyttw8BnymvSUZ46tcL1ktkWY6kIYvKOwIMp5GDDkllD2Tistm9Il8tPgj8IowDxKzoQhcGjxfR7z3JstA==}
+ engines: {node: '>=22'}
+ peerDependencies:
+ zod: ^3.25.76 || ^4.1.8
+
'@ai-sdk/[email protected]':
resolution: {integrity: sha512-e5McXB9sqfGBCCPVjoxKVGuWT8LIwRI4k6a8MbZWq6J+W1hmAsWv6oK0sD8z9GIcGJ66aEJSuzMuLyg+FtL4Ew==}
engines: {node: '>=22'}
@@ -289,6 +307,12 @@ packages:
peerDependencies:
zod: ^3.25.76 || ^4.1.8
+ '@ai-sdk/[email protected]':
+ resolution: {integrity: sha512-GGkfFh0DpjciBISrM5uioGupReE0t5+veZAWQw99+EAm/Fl+DhnnocOrP44ZJT0FWhdZbzVoChUOKCZT3tvnUg==}
+ engines: {node: '>=22'}
+ peerDependencies:
+ zod: ^3.25.76 || ^4.1.8
+
'@ai-sdk/[email protected]':
resolution: {integrity: sha512-KHohs5/BZWEw1q16sXdxr/jvG+DsoPlB5j98yQd+GFWfYIqB2qGtxnbvzpvGXLaNH9zZPUzF+qH6AiWvkjNjAQ==}
engines: {node: '>=22'}
@@ -6015,6 +6039,13 @@ snapshots:
dependencies:
zod: 3.25.76
+ dependencies:
+ '@ai-sdk/openai-compatible': 3.0.22([email protected])
+ '@ai-sdk/provider': 4.0.5
+ '@ai-sdk/provider-utils': 5.0.20([email protected])
+ zod: 3.25.76
+
dependencies:
'@ai-sdk/provider': 4.0.5
@@ -6034,6 +6065,13 @@ snapshots:
'@ai-sdk/provider-utils': 5.0.20([email protected])
zod: 3.25.76
+ dependencies:
+ '@ai-sdk/openai-compatible': 3.0.22([email protected])
+ '@ai-sdk/provider': 4.0.5
+ '@ai-sdk/provider-utils': 5.0.20([email protected])
+ zod: 3.25.76
+
dependencies:
'@ai-sdk/provider': 4.0.5