8000 [pull] main from can1357:main by pull[bot] · Pull Request #10 · ericrihm/oh-my-pi · GitHub
[go: up one dir, main page]

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
c228dea
feat(catalog): route paid xAI through Responses like SuperGrok
geraint0923 Aug 3, 2026
651f209
feat(catalog): replay xAI encrypted reasoning on later turns
geraint0923 Aug 3, 2026
bd44ff1
docs: keep xAI changelog entries under Unreleased after 17.2.5
geraint0923 Aug 3, 2026
ef77597
fix(catalog): drop stale xAI Chat Completions model-cache rows
geraint0923 Aug 3, 2026
7a3a558
fix(catalog): clamp paid xAI Responses minimal effort to low
geraint0923 Aug 3, 2026
ca2fa4f
fix(ai): do not treat XAI_API_KEY as SuperGrok availability
geraint0923 Aug 3, 2026
3fb5780
fix(catalog): omit penalty and stop params on xAI reasoning models
geraint0923 Aug 3, 2026
b49b5b8
fix(catalog): strip stale xAI Responses effort dials from generated rows
geraint0923 Aug 3, 2026
01db5b0
fix(catalog): omit unsupported reasoning.summary on paid xAI Responses
geraint0923 Aug 3, 2026
4c150d2
docs: keep xAI changelog entries under Unreleased after 17.2.12
geraint0923 Aug 9, 2026
6c0f458
fix(catalog): rebuild paid xAI Responses discovery after helper rename
geraint0923 Aug 9, 2026
09830d2
fix(catalog): drop unsupported xhigh effort from first-party Grok
geraint0923 Aug 10, 2026
76faddf
fix(catalog): omit reasoningEffortMap on no-dial xAI rows
geraint0923 Aug 10, 2026
86866b8
fix(catalog): omit Responses penalties on all first-party xAI models
geraint0923 Aug 10, 2026
72168a6
fix(catalog): keep xhigh on Grok multi-agent Responses models
geraint0923 Aug 10, 2026
d14c028
fix(ai): allow explicit xai-oauth selectors with XAI_API_KEY
geraint0923 Aug 10, 2026
02eaee0
style(catalog): sort generated-policies imports after rebase
geraint0923 Aug 15, 2026
a7ac5d9
fix(catalog): route main's grok-4.6 through first-party Responses
geraint0923 Aug 15, 2026
d02aa3c
fix(catalog): advertise xhigh on first-party grok-4.6 Responses
geraint0923 Aug 15, 2026
f1095fc
Merge PR #7454: feat(catalog): route paid xAI through Responses like …
can1357 Aug 15, 2026
8a746fd
chore(catalog): regenerated models.json from upstream sources
can1357 Aug 15, 2026
de6b797
fix(natives): fall back to cargo without bazel
can1357 Aug 15, 2026
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
13 changes: 8 additions & 5 deletions docs/provider-endpoint-constraints.md
Original file line number Diff line number Diff line change
Expand Up @@ -235,13 +235,16 @@ Reasoning fields are not interchangeable.
- Compat needs both policies: disable reasoning for any tool choice, and disable
reasoning only for forced tool choice.

### xAI Grok through Responses/SuperGrok
### xAI Grok through Responses (`xai` and `xai-oauth`)

Keep these independent:
Both the paid API-key provider (`xai` / `XAI_API_KEY`) and SuperGrok OAuth
(`xai-oauth`) chat over `https://api.x.ai/v1/responses`. Keep these independent:

- omit `reasoning.effort`
- include or drop encrypted reasoning replay
- filter reasoning-history wrappers
- omit `reasoning.effort` unless the model is on the Grok effort-capable allowlist
- omit `reasoning.summary` (the host rejects it; do not fall back to `"auto"`)
- omit presence/frequency penalties (`/v1/responses` rejects them for every Grok model)
- include `reasoning.encrypted_content` on the request
- replay encrypted reasoning items on later turns

Some models reject only one of those fields; do not collapse them into one
"Grok mode" branch.
Expand Down
6 changes: 6 additions & 0 deletions packages/ai/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

## [Unreleased]

### Fixed

- Stopped treating `XAI_API_KEY` as SuperGrok (`xai-oauth`) sign-in for availability, so paid-key-only setups default to `xai/grok-4.5` instead of the zero-cost SuperGrok catalog path. Explicit `xai-oauth/…` selectors still accept the paid key via the existing env fallback.
- Omitted unsupported `reasoning.summary` on paid xAI Responses requests (`xai/grok-4.5`), matching SuperGrok, so a thinking level no longer serializes `summary: "auto"`.
- Omitted presence/frequency penalties on all first-party xAI Responses models, including non-reasoning ids such as `xai/grok-2`.

## [17.3.4] - 2026-08-14

### Fixed
Expand Down
38 changes: 34 additions & 4 deletions packages/ai/src/auth-storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2680,18 +2680,32 @@ export class AuthStorage {
}

/**
* Check if any form of auth is configured for a provider.
* Unlike getApiKey(), this doesn't refresh OAuth tokens.
* Dedicated auth for default-model availability (picker / `getAvailable`).
* Unlike {@link getApiKey}, this does not refresh OAuth tokens, and unlike
* {@link hasResolvableAuth} it ignores cross-provider env aliases so
* `XAI_API_KEY` does not auto-select SuperGrok (`xai-oauth`).
*/
hasAuth(provider: string): boolean {
if (this.#runtimeOverrides.has(provider)) return true;
if (this.#configOverrides.has(provider)) return true;
if (this.#getCredentialsForProvider(provider).length > 0) return true;
if (getEnvApiKey(provider)) return true;
if (this.#hasDedicatedEnvAuth(provider)) return true;
if (this.#fallbackResolver?.(provider)) return true;
return false;
}

/**
* Whether a request could resolve a key for this provider, including
* cross-provider env aliases (`xai-oauth` borrowing `XAI_API_KEY`).
* Use this for explicit model preflight (`xai-oauth/grok-4.5`); use
* {@link hasAuth} for auto-availability so the default picker stays on
* paid `xai` when only `XAI_API_KEY` is set.
*/
hasResolvableAuth(provider: string): boolean {
if (this.hasAuth(provider)) return true;
return Boolean(getEnvApiKey(provider));
}

/**
* True iff a dedicated, non-env credential source is configured for this
* provider — i.e. anything in the cascade EXCEPT `getEnvApiKey(provider)`.
Expand All @@ -2711,6 +2725,22 @@ export class AuthStorage {
return false;
}

/**
* Env auth that belongs to this provider, not a cross-provider alias.
*
* `getEnvApiKey("xai-oauth")` also accepts `XAI_API_KEY` so an explicit
* `xai-oauth/…` stream can still borrow the paid key. Availability and
* origin must not: otherwise an API-key-only setup marks SuperGrok as
* signed in and `pickDefaultAvailableModel` prefers `xai-oauth/grok-4.5`
* over paid `xai/grok-4.5`.
*/
#hasDedicatedEnvAuth(provider: string): boolean {
if (provider === "xai-oauth") {
return Boolean($env.XAI_OAUTH_TOKEN?.trim());
}
return Boolean(getEnvApiKey(provider));
}

/**
* Classify where a provider's auth comes from, following the same precedence
* as {@link AuthStorage.getApiKey}: runtime override → config override →
Expand All @@ -2727,7 +2757,7 @@ export class AuthStorage {
if (stored.some(credential => credential.type === "api_key" && credential.source === "login")) {
return { kind: "api_key" };
}
if (getEnvApiKey(provider)) return { kind: "env", envVar: getEnvApiKeyName(provider) };
if (this.#hasDedicatedEnvAuth(provider)) return { kind: "env", envVar: getEnvApiKeyName(provider) };
if (stored.some(credential => credential.type === "api_key")) return { kind: "api_key" };
if (this.#fallbackResolver?.(provider)) return { kind: "fallback" };
return undefined;
Expand Down
20 changes: 11 additions & 9 deletions packages/ai/src/providers/openai-completions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1575,17 +1575,19 @@ function buildParams(
if (options?.minP !== undefined) {
params.min_p = options.minP;
}
if (options?.presencePenalty !== undefined) {
params.presence_penalty = options.presencePenalty;
}
if (options?.repetitionPenalty !== undefined) {
params.repetition_penalty = options.repetitionPenalty;
}
if (options?.frequencyPenalty !== undefined) {
params.frequency_penalty = options.frequencyPenalty;
if (initialCompat.supportsPenaltyAndStopParams) {
if (options?.presencePenalty !== undefined) {
params.presence_penalty = options.presencePenalty;
}
if (options?.repetitionPenalty !== undefined) {
params.repetition_penalty = options.repetitionPenalty;
}
if (options?.frequencyPenalty !== undefined) {
params.frequency_penalty = options.frequencyPenalty;
}
}
}
if (options?.stopSequences?.length) {
if (options?.stopSequences?.length && initialCompat.supportsPenaltyAndStopParams) {
const seqs = options.stopSequences;
params.stop = seqs.length === 1 ? seqs[0] : seqs.slice(0, 4);
}
Expand Down
11 changes: 5 additions & 6 deletions packages/ai/src/providers/openai-responses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1285,12 +1285,11 @@ export function buildParams(
filterReasoningHistory: options?.filterReasoningHistory,
omitReasoningEffort: options?.omitReasoningEffort,
});
const reasoningSummary =
model.provider === "xai-oauth"
? options?.reasoning === undefined
? undefined
: null
: options?.reasoningSummary;
const reasoningSummary = model.compat.supportsReasoningSummary
? options?.reasoningSummary
: options?.reasoning === undefined
? undefined
: null;
applyResponsesCompatPolicy(params, reasoningPolicy, {
reasoningSummary,
forceReasoningOff: options?.forceReasoningOff,
Expand Down
8 changes: 5 additions & 3 deletions packages/ai/src/providers/openai-shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3308,7 +3308,7 @@ export function applyCommonResponsesSamplingParams<P extends CommonResponsesPara
params: P,
options: CommonSamplingOptions | undefined,
model: Pick<Model, "provider" | "api" | "id" | "omitMaxOutputTokens" | "maxTokens"> & {
compat: Pick<ResolvedOpenAISharedCompat, "supportsSamplingParams">;
compat: Pick<ResolvedOpenAISharedCompat, "supportsSamplingParams" | "supportsPenaltyAndStopParams">;
},
): void {
if (options?.maxTokens && !model.omitMaxOutputTokens) {
Expand All @@ -3325,8 +3325,10 @@ export function applyCommonResponsesSamplingParams<P extends CommonResponsesPara
if (options?.topP !== undefined) params.top_p = options.topP;
if (options?.topK !== undefined) params.top_k = options.topK;
if (options?.minP !== undefined) params.min_p = options.minP;
if (options?.presencePenalty !== undefined) params.presence_penalty = options.presencePenalty;
if (options?.repetitionPenalty !== undefined) params.repetition_penalty = options.repetitionPenalty;
if (model.compat.supportsPenaltyAndStopParams) {
if (options?.presencePenalty !== undefined) params.presence_penalty = options.presencePenalty;
if (options?.repetitionPenalty !== undefined) params.repetition_penalty = options.repetitionPenalty;
}
}
applyOpenAIServiceTier(params, options?.serviceTier, model);
}
Expand Down
1 change: 1 addition & 0 deletions packages/ai/test/issue-967-vision-guard.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ const compat: ResolvedOpenAICompat = {
supportsReasoningEffort: true,
supportsReasoningParams: true,
supportsSamplingParams: true,
supportsPenaltyAndStopParams: true,
alwaysSendMaxTokens: false,
isOpenRouterHost: false,
isVercelGatewayHost: false,
Expand Down
54 changes: 3 additions & 51 deletions packages/ai/test/openai-completions-cache-affinity.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@ import type { AssistantMessage, Context, FetchImpl, Model, SimpleStreamOptions,
import { buildOpenAICompat } from "@oh-my-pi/pi-catalog/compat/openai";
import { getBundledModel } from "@oh-my-pi/pi-catalog/models";

const model = getBundledModel<"openai-completions">("xai", "grok-code-fast-1");
if (!model) throw new Error("Expected bundled xAI Grok model");
if (model.api !== "openai-completions") throw new Error(`Expected Chat Completions model, received ${model.api}`);
const context: Context = { messages: [{ role: "user", content: "hello", timestamp: 0 }] };

const openAI56ResponsesModel = getBundledModel<"openai-responses">("openai", "gpt-5.6");
Expand Down Expand Up @@ -44,7 +41,7 @@ function chatCompletionsSse(): Response {
id: "chatcmpl-affinity",
object: "chat.completion.chunk",
created: 0,
model: model.id,
model: openAI56CompletionsModel.id,
choices: [{ index: 0, delta, finish_reason: finishReason }],
});

Expand All @@ -56,7 +53,7 @@ function chatCompletionsSse(): Response {

async function captureRequest(
options: OpenAICompletionsOptions,
requestModel: Model<"openai-completions"> = model,
requestModel: Model<"openai-completions"> = openAI56CompletionsModel,
requestContext: Context = context,
): Promise<{ headers: Headers; body: Record<string, unknown> }> {
let requestHeaders: Headers | undefined;
Expand All @@ -83,7 +80,7 @@ async function captureRequest(

async function captureSimpleRequest(
options: SimpleStreamOptions,
requestModel: Model<"openai-completions"> = model,
requestModel: Model<"openai-completions"> = openAI56CompletionsModel,
requestContext: Context = context,
): Promise<{ headers: Headers; body: Record<string, unknown> }> {
let requestHeaders: Headers | undefined;
Expand All @@ -104,51 +101,6 @@ async function captureSimpleRequest(
return { headers: requestHeaders, body };
}

describe("openai-completions xAI cache affinity", () => {
const cases: Array<{
name: string;
options: OpenAICompletionsOptions;
expectedHeader: string | null;
}> = [
{
name: "uses sessionId when no prompt cache key is provided",
options: { sessionId: "session-fallback" },
expectedHeader: "session-fallback",
},
{
name: "keeps the prompt cache key stable across a distinct side-channel session",
options: { promptCacheKey: "stable-cache-key", sessionId: "side-channel-session" },
expectedHeader: "stable-cache-key",
},
{
name: "omits automatic affinity when caching is disabled",
options: {
promptCacheKey: "disabled-cache-key",
sessionId: "disabled-session",
cacheRetention: "none",
},
expectedHeader: null,
},
{
name: "preserves a caller-provided mixed-case affinity header",
options: {
promptCacheKey: "automatic-cache-key",
sessionId: "automatic-session",
headers: { "X-Grok-Conv-Id": "caller-affinity" },
},
expectedHeader: "caller-affinity",
},
];

for (const { name, options, expectedHeader } of cases) {
it(name, async () => {
const { headers } = await captureRequest(options);

expect(headers.get("x-grok-conv-id")).toBe(expectedHeader);
});
}
});

describe("OpenAI Chat Completions explicit prompt cache policy", () => {
const historicalContext: Context = {
messages: [
Expand Down
1 change: 1 addition & 0 deletions packages/ai/test/openai-completions-compat.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ describe("openai-completions compatibility", () => {
toolStrictMode: "none",
supportsReasoningParams: true,
supportsSamplingParams: true,
supportsPenaltyAndStopParams: true,
alwaysSendMaxTokens: false,
isOpenRouterHost: false,
isVercelGatewayHost: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ const compat: ResolvedOpenAICompat = {
toolStrictMode: "none",
supportsReasoningParams: true,
supportsSamplingParams: true,
supportsPenaltyAndStopParams: true,
alwaysSendMaxTokens: false,
isOpenRouterHost: false,
isVercelGatewayHost: false,
Expand Down
24 changes: 24 additions & 0 deletions packages/ai/test/openai-responses-cache-affinity.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,20 @@ const xaiOAuthResponsesModel: Model<"openai-responses"> = {
reasoning: true,
}),
};
const xaiApiKeyResponsesModel: Model<"openai-responses"> = {
...model,
id: "grok-code-fast-1",
name: "Grok Code Fast 1",
provider: "xai",
baseUrl: "https://api.x.ai/v1",
compat: buildOpenAIResponsesCompat({
id: "grok-code-fast-1",
name: "Grok Code Fast 1",
provider: "xai",
baseUrl: "https://api.x.ai/v1",
reasoning: true,
}),
};

const openAI56ResponsesModel: Model<"openai-responses"> = {
...model,
Expand Down Expand Up @@ -675,6 +689,16 @@ describe("openai-responses cache affinity", () => {
}
});

it("sets x-grok-conv-id cache affinity for paid xai Responses requests", async () => {
const captured = await captureDispatchedOpenAIResponseHeaders(
{ sessionId: "session-fallback" },
xaiApiKeyResponsesModel,
);

expect(getHeader(captured.headers, "x-grok-conv-id")).toBe("session-fallback");
expect(captured.body?.prompt_cache_key).toBe("session-fallback");
});

it("sets OpenRouter Responses session_id from sessionId in the body", async () => {
const captured = await captureOpenAIResponseHeaders(
{ sessionId: "workflow-123", promptCacheKey: "cache-key-123" },
Expand Down
2 changes: 1 addition & 1 deletion packages/ai/test/stream.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1000,7 +1000,7 @@ describe("Generate E2E Tests", () => {
);
});

describe.skipIf(!e2eApiKey("XAI_API_KEY"))("xAI Provider (grok-code-fast-1 via OpenAI Completions)", () => {
describe.skipIf(!e2eApiKey("XAI_API_KEY"))("xAI Provider (grok-code-fast-1 via OpenAI Responses)", () => {
const llm = getBundledModel("xai", "grok-code-fast-1");

it(
Expand Down
46 changes: 46 additions & 0 deletions packages/ai/test/xai-login.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,52 @@ describe("xAI API login wiring", () => {
expect(getEnvApiKey("xai")).toBe("xai-env-key");
});

test("XAI_API_KEY alone does not mark SuperGrok as available", async () => {
const originalOauthToken = Bun.env.XAI_OAUTH_TOKEN;
Bun.env.XAI_API_KEY = "xai-env-key";
delete Bun.env.XAI_OAUTH_TOKEN;
const store = new SqliteAuthCredentialStore(new Database(":memory:"));
const storage = new AuthStorage(store);
await storage.reload();
try {
expect(storage.hasAuth("xai")).toBe(true);
expect(storage.hasAuth("xai-oauth")).toBe(false);
expect(storage.hasResolvableAuth("xai")).toBe(true);
expect(storage.hasResolvableAuth("xai-oauth")).toBe(true);
expect(getEnvApiKey("xai-oauth")).toBe("xai-env-key");
expect(storage.getCredentialOrigin("xai")).toEqual({ kind: "env", envVar: "XAI_API_KEY" });
expect(storage.getCredentialOrigin("xai-oauth")).toBeUndefined();
} finally {
if (originalOauthToken === undefined) {
delete Bun.env.XAI_OAUTH_TOKEN;
} else {
Bun.env.XAI_OAUTH_TOKEN = originalOauthToken;
}
store.close();
}
});

test("XAI_OAUTH_TOKEN marks SuperGrok available without a paid API key", async () => {
const originalOauthToken = Bun.env.XAI_OAUTH_TOKEN;
delete Bun.env.XAI_API_KEY;
Bun.env.XAI_OAUTH_TOKEN = "xai-oauth-env";
const store = new SqliteAuthCredentialStore(new Database(":memory:"));
const storage = new AuthStorage(store);
await storage.reload();
try {
expect(storage.hasAuth("xai")).toBe(false);
expect(storage.hasAuth("xai-oauth")).toBe(true);
expect(storage.getCredentialOrigin("xai-oauth")).toEqual({ kind: "env" });
} finally {
if (originalOauthToken === undefined) {
delete Bun.env.XAI_OAUTH_TOKEN;
} else {
Bun.env.XAI_OAUTH_TOKEN = originalOauthToken;
}
store.close();
}
});

test("AuthStorage.login('xai') validates against /models and stores the pasted key", async () => {
const fetchCalls: Array<{ url: string; init: RequestInit | undefined }> = [];
const fetchMock: FetchImpl = vi.fn(async (input: string | URL | Request, init?: RequestInit) => {
Expand Down
Loading
Loading
0