Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions packages/core/src/__tests__/model-metadata.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,12 @@ describe('openAiAdapterApiProtocol', () => {
assert.equal(openAiAdapterApiProtocol('muse-spark-1.2-contributor', 'opencode'), 'openai-chat');
assert.equal(openAiAdapterApiProtocol('minimax-m3', 'opencode-go'), 'openai-chat');
});

it('routes only Qwen3.8 Max through Alibaba Token Plan Responses', () => {
for (const providerType of ['alibaba-token-plan-cn', 'alibaba-token-plan'] as const) {
assert.equal(openAiAdapterApiProtocol('qwen3.8-max', providerType), 'openai-responses');
assert.equal(openAiAdapterApiProtocol('qwen3.7-max', providerType), 'openai-chat');
}
assert.equal(openAiAdapterApiProtocol('qwen3.8-max', 'alibaba-cn'), 'openai-chat');
});
});
13 changes: 13 additions & 0 deletions packages/core/src/__tests__/provider-catalog-contract.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,19 @@ describe('provider catalog contract — structural invariants over CATALOG_PROVI
);
}
});

it('delegates Alibaba Token Plan execution through one explicit Runtime profile', () => {
const delegated = Object.entries(PROVIDER_REGISTRY).flatMap(([providerType, definition]) => {
const adapter = definition.runtimeAdapter;
return adapter.kind === 'openai-compatible' && adapter.runtimeProfile
? [{ providerType, runtimeProfile: adapter.runtimeProfile }]
: [];
});
assert.deepEqual(delegated, [
{ providerType: 'alibaba-token-plan-cn', runtimeProfile: 'alibaba-token-plan' },
{ providerType: 'alibaba-token-plan', runtimeProfile: 'alibaba-token-plan' },
]);
});
});

describe('retired provider contract', () => {
Expand Down
2 changes: 2 additions & 0 deletions packages/core/src/llm-connections.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import {
type ProviderCategory,
type ProviderDefaults,
type ProviderRuntimeAdapter,
type ProviderRuntimeProfileId,
type ProviderResponsesContract,
type ProviderType,
} from './provider-registry.js';
Expand All @@ -64,6 +65,7 @@ export type {
ProviderCategory,
ProviderDefaults,
ProviderRuntimeAdapter,
ProviderRuntimeProfileId,
ProviderResponsesContract,
ProviderType,
};
Expand Down
11 changes: 6 additions & 5 deletions packages/core/src/model-metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,11 +125,10 @@ export function lookupModelProviderOverride(
/**
* The request wire a model served over the OpenAI adapter must use.
*
* OpenAI's `gpt-5*` families and xAI's `grok-4.5` are served only over the
* Responses API; every other model on the native OpenAI adapter uses Chat
* Completions. This is the single declared source of that protocol split,
* expressed through the {@link ModelInfo.apiProtocol} seam. It is consumed by
* the runtime model factory and the conformance matrix.
* Provider/model routing facts live here even when the concrete Responses SDK
* and replay policy are delegated to a Runtime profile. This is the single
* declared source of the default protocol split, expressed through the
* {@link ModelInfo.apiProtocol} seam.
*/
export function openAiAdapterApiProtocol(
modelId: string,
Expand All @@ -138,6 +137,8 @@ export function openAiAdapterApiProtocol(
const id = modelId.trim();
return (providerType === 'deepseek' && deepSeekModelSupportsResponses(id)) ||
(providerType === 'opencode-go' && id === 'muse-spark-1.2-contributor') ||
((providerType === 'alibaba-token-plan-cn' || providerType === 'alibaba-token-plan') &&
id === 'qwen3.8-max') ||
/^gpt-5/i.test(id) ||
((providerType === 'xai' || providerType === 'xai-oauth') && id === 'grok-4.5')
? 'openai-responses'
Expand Down
53 changes: 41 additions & 12 deletions packages/core/src/provider-registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@ export type ProviderCatalogGroup = 'recommended' | 'plans' | 'api' | 'aggregator

export type ApplyPatchProtocol = 'openai-structured' | 'codex-v4a-freeform';

/**
* Stable reference to provider execution policy implemented by `@maka/runtime`.
* Core owns only this protocol-level delegation; SDK selection, replay
* carriers, and request mutation remain Runtime implementation details.
*/
export type ProviderRuntimeProfileId = 'alibaba-token-plan';

export type ProviderResponsesContract =
| {
readonly adapter: 'openai';
Expand All @@ -41,6 +48,29 @@ export type ProviderResponsesContract =
readonly reasoningReplay: 'plaintext-content';
};

type OpenAiCompatibleRuntimeAdapterBase = {
kind: 'openai-compatible';
name: 'provider' | 'connection';
includeUsage?: boolean;
requireBaseUrl?: boolean;
replayAssistantReasoningAs?: 'reasoning';
replayAssistantReasoningDetails?: true;
};

type OpenAiCompatibleRuntimeAdapter = OpenAiCompatibleRuntimeAdapterBase &
(
| {
/** Presence enables a complete Core-owned Responses contract. */
responses?: ProviderResponsesContract;
runtimeProfile?: never;
}
| {
responses?: never;
/** Explicitly delegates concrete execution policy to `@maka/runtime`. */
runtimeProfile: ProviderRuntimeProfileId;
}
);

type ProviderRuntimeAdapterDefinition =
| { kind: 'anthropic'; auth: 'api-key' | 'bearer'; normalizeBaseUrl: boolean }
/**
Expand All @@ -53,16 +83,7 @@ type ProviderRuntimeAdapterDefinition =
| { kind: 'google'; normalizeBaseUrl?: boolean }
| { kind: 'github-copilot' }
| { kind: 'cohere' }
| {
kind: 'openai-compatible';
name: 'provider' | 'connection';
includeUsage?: boolean;
requireBaseUrl?: boolean;
/** Presence enables Responses and fixes the only supported SDK/replay pairing. */
responses?: ProviderResponsesContract;
replayAssistantReasoningAs?: 'reasoning';
replayAssistantReasoningDetails?: true;
};
| OpenAiCompatibleRuntimeAdapter;

export type ProviderRuntimeAdapter = ProviderRuntimeAdapterDefinition & {
/** Provider wire contract for ApplyPatch. Model support is resolved separately. */
Expand Down Expand Up @@ -1664,7 +1685,11 @@ const providerRegistry = {
fallbackModels: [...alibabaTokenPlanModelIds],
status: 'ready',
protocol: 'openai',
runtimeAdapter: { kind: 'openai-compatible', name: 'provider' },
runtimeAdapter: {
kind: 'openai-compatible',
name: 'provider',
runtimeProfile: 'alibaba-token-plan',
},
modelDiscovery: { kind: 'protocol' },
category: 'domestic',
catalogGroup: 'plans',
Expand All @@ -1684,7 +1709,11 @@ const providerRegistry = {
fallbackModels: [...alibabaTokenPlanModelIds],
status: 'ready',
protocol: 'openai',
runtimeAdapter: { kind: 'openai-compatible', name: 'provider' },
runtimeAdapter: {
kind: 'openai-compatible',
name: 'provider',
runtimeProfile: 'alibaba-token-plan',
},
modelDiscovery: { kind: 'protocol' },
category: 'overseas',
catalogGroup: 'plans',
Expand Down
Loading