Commit Graph

429 Commits

Author SHA1 Message Date
Vegard Stikbakke b91bdd5a3e fix(ai): preserve Z.AI thinking content
closes #6083
2026-06-29 08:40:20 +02:00
Armin Ronacher 54113731b2 fix(ai): use HTTP timeout for Codex SSE headers
Refs #4945
2026-06-28 19:57:47 +02:00
Mario Zechner 09f1059575 fix(ai): clamp streamSimple max tokens
Clamps streamSimple max-token defaults against estimated context, addressing #5595.

closes #6061
2026-06-25 14:10:28 +02:00
Mario Zechner f78b163713 fix(ai): revert minimax max token clamp 2026-06-25 13:36:04 +02:00
Stephan Schneider 62fad94f1a fix(ai): surface provider HTTP error body instead of opaque SDK message
Add a shared normalizeProviderError helper in packages/ai/src/utils/error-body.ts
and route the 8 body-blind / status-only providers through it (amazon-bedrock,
azure-openai-responses, google, google-vertex, images/openrouter,
openai-codex-responses, openai-completions, openai-responses). Non-schema 4xx/5xx
responses from proxies / gateways now show the real reason carried in the response
body alongside the HTTP status, instead of "403 status code (no body)" or
"Unknown: UnknownError".

The helper probes status (statusCode, status, $metadata.httpStatusCode,
$response.statusCode) and body (body, parsed error object, $response.body) across
the Mistral, OpenAI, Google, and Bedrock SDK shapes, truncates the body at a 4000
char cap, and preserves error.message when the SDK already folded the body in
(Anthropic / Google happy path). mistral.ts and anthropic.ts are left untouched.
Provider prefixes and the OpenRouter metadata.raw append are preserved.

closes #5763
2026-06-25 12:07:51 +02:00
Mario Zechner b940c52e7e fix(ai): clamp MiniMax shared budget max tokens
closes #6061
2026-06-25 12:00:37 +02:00
Armin Ronacher 371adcf371 fix(coding-agent): retry explicit provider retry errors
closes #6019
2026-06-24 18:14:06 +02:00
Mario Zechner a2e3e9d8b2 Merge pull request #6004 from gukoff/support-azure-foundry-endpoints
feat: Normalize modern Microsoft Foundry Responses API endpoints
2026-06-24 10:38:57 +02:00
Mario Zechner ef231c4910 fix(ai): resolve request-scoped auth before provider calls
closes #6021
2026-06-23 23:27:00 +02:00
Mario Zechner 49fbe6834f fix(ai): align api key credentials with auth json 2026-06-23 22:29:46 +02:00
Mario Zechner 6184307c39 fix(ai): require explicit anthropic compat metadata 2026-06-23 21:04:59 +02:00
Mario Zechner cd95c2749f fix(ai): require OpenAI Responses terminal events 2026-06-23 16:35:45 +02:00
Konstantin Gukov e3dcb244f8 Support modern Microsoft Foundry Responses API endpoints:
- support *.ai.azure.com endpoints
- normalize away the /responses postfix in the query path which by
  default is added on Microsoft Foundry UI
2026-06-23 15:38:43 +02:00
Mario Zechner 129eb460cd feat(ai): complete models runtime migration 2026-06-23 15:29:46 +02:00
Mario Zechner 6a4813a7ca Merge remote-tracking branch 'origin/main'
# Conflicts:
#	packages/ai/CHANGELOG.md
2026-06-23 13:52:09 +02:00
Mario Zechner 8eeaa2bcba fix(ai): honor scoped env in compat API key injection 2026-06-23 13:45:26 +02:00
Mario Zechner 2cbce395fb feat(ai): pass provider-resolved env to APIs 2026-06-23 13:42:25 +02:00
Armin Ronacher d0e0b84cb9 fix(ai): reconnect Codex websocket on connection limit
closes #5973
2026-06-23 00:17:37 +02:00
Armin Ronacher f7d3331df6 fix(ai): mock copilot models in oauth test 2026-06-22 17:49:18 +02:00
Mario Zechner abbd911693 Merge main into model-registry 2026-06-22 14:00:18 +02:00
Mario Zechner 717a8f958a fix(ai): revert selective pi-ai base entrypoints 2026-06-22 12:54:32 +02:00
Vegard Stikbakke 7d0497fdb7 fix(ai): preserve early reasoning details
closes #5114
2026-06-22 10:14:59 +02:00
Armin Ronacher 8b97e75c6b feat(ai): add chat-template thinking compat
closes #5673
2026-06-19 23:34:17 +02:00
Vegard Stikbakke 6e6ce70caf fix(ai): filter Copilot models by account availability
closes #5897
2026-06-19 13:17:13 +02:00
Fred K. Schott 0d89a33373 feat(packages): Add selective pi-ai base entrypoints (#5348) 2026-06-19 00:41:49 +02:00
Armin Ronacher 651d10d90b feat(ai): enable Mistral prompt caching 2026-06-18 23:47:25 +02:00
Armin Ronacher 7f29e7a369 feat: add provider-scoped environment overrides (#5807) 2026-06-16 17:19:08 +02:00
Armin Ronacher 75b0d723c0 fix(ai): support Z.AI GLM-5.2 effort levels
closes #5770
2026-06-16 14:29:27 +02:00
Armin Ronacher 0369bdb8f4 fix(ai): add Moonshot CN Kimi K2.7 metadata
closes #5760
2026-06-15 17:08:59 +02:00
Armin Ronacher 408ac103ec fix(ai): update Copilot Claude thinking metadata
closes #4637
2026-06-15 09:50:25 +02:00
Bucky 0be5bb6c96 fix(ai): price anthropic 1h cache writes at 2x input (#5738)
anthropic 1h cache writes were billed at the 5m rate; split the bucket and price the 1h portion correctly
2026-06-15 09:21:14 +02:00
Armin Ronacher 21a904f4b7 fix(ai): disable OpenCode long cache retention for rejecting routes
closes #5702
2026-06-13 23:59:45 +02:00
Armin Ronacher 6f29450e13 fix(ai): update adaptive thinking model expectations 2026-06-13 11:17:38 +02:00
Armin Ronacher aa3a5233ad fix(ai): restore Codex context limits 2026-06-13 11:02:38 +02:00
Armin Ronacher 121f0edbf4 fix(ai): detect parenthesized context overflow errors
closes #5677
2026-06-13 00:01:37 +02:00
Armin Ronacher a7cdc679e7 fix(ai): correct GPT-5 context window metadata
closes #5644
2026-06-12 23:03:10 +02:00
Armin Ronacher be7d5cf585 fix(ai): relax Codex SSE header timeout 2026-06-12 17:08:30 +02:00
Ramiz Wachtler a455f62f72 fix(ai): preserve Anthropic refusal details (#5666)
Propagate Anthropic refusal stop_details explanation to errorMessage
2026-06-12 14:52:46 +02:00
Vegard Stikbakke 3f44d3e2eb fix(ai): remove stale OpenRouter Kimi free model assertion (#5650) 2026-06-12 09:00:15 +02:00
Mario Zechner 827fe1e2c4 feat(ai): ImagesModels collections mirroring the chat-side design
createImagesModels()/ImagesProvider/createImagesProvider() give image
generation the same shape as chat: sync model reads, explicit async
refresh(provider?) with in-flight dedupe, provider-resolved auth, and
never-rejecting generateImages() (failures return AssistantImages with
stopReason error). Auth resolution is shared with the chat side via the
free-standing resolveProviderAuth() in auth/resolve.ts, which also owns
ModelsError; both collections pass their store/context as arguments.

The OpenRouter implementation moves to api/openrouter-images.ts with a
lazy wrapper; openrouterImagesProvider() factory plus
builtinImagesProviders()/builtinImagesModels() land in providers/all.
The ImagesProvider id type alias is renamed to ImagesProviderId
(mirror of Provider -> ProviderId). The old global image API
(getImageModel*, generateImages, registerImagesApiProvider) stays on
/compat, its registration shim repointed at the moved implementation.

README: Quick Start uses builtinModels(), the full streaming event
switch, image generation and the development checklist are restored in
full, image generation documents the new collections with compat noted
for the old API, plus the review fixes (builtinModels options,
credential-store mention for browsers, ImagesModels notes).
2026-06-11 00:27:43 +02:00
Mario Zechner 6e98573f24 feat(ai): sync model reads, explicit async refresh
Provider.getModels() is sync-only (last-known list; must not throw) with
an optional refreshModels() where dynamic providers fetch. The
sync-or-async union invited latent sync assumptions that would detonate
on the first dynamic provider; async-only reads would force sync
consumer surfaces (extension find/getAll) through Promises. Sync reads
plus an explicit refresh verb keeps the contract single and the
staleness visible.

Models.getModels()/getModel() are sync best-effort reads;
Models.refresh(provider?) rejects with ModelsError(model_source) for a
single provider and is concurrent best-effort across all providers.
createProvider() takes a models array plus an optional refreshModels
fetcher (stored on success, in-flight calls deduped, list unchanged on
rejection). forceRefresh options are gone.

Also finishes the in-progress AuthStorage fallbackResolver removal
(drops the now-unused includeFallback option from getApiKey).
2026-06-10 23:30:04 +02:00
Mario Zechner 8a0903ebf2 feat(ai): compat entrypoint, core-only root barrel (phase 5)
The root barrel is now core-only and side-effect free: types,
createModels/createProvider, auth substrate, lazyStream/lazyApi, faux,
utils. Generated catalogs, api-registry, env-api-keys, images, global
stream functions, and per-API lazy wrappers leave the root.

New @earendil-works/pi-ai/compat preserves the old surface verbatim as
a strict superset of the root: api-dispatch stream/complete with env
key injection, the builtin registration side effect (skip-if-present so
it cannot clobber earlier overrides), deprecated getModel/getModels/
getProviders aliases of the new getBuiltin* reads in providers/all,
lazy api wrappers + setBedrockProviderModule, and image generation.
Compat dies with the coding-agent ModelManager migration.

Packaging: exports map gains ./compat, ./providers/*, ./api/*;
sideEffects array lists only the effectful modules.

Old-global imports across agent/coding-agent/examples and pi-ai tests
switch to /compat (path-only; compat is a superset). The coding-agent
extension loader resolves the pi-ai ROOT specifier to compat, so
existing user extensions using the old global API keep working at
runtime until compat is removed. vitest configs alias /compat to src;
browser smoke imports old globals from /compat.
2026-06-10 21:17:12 +02:00
Mario Zechner 4d5c015820 feat(ai): adapt OAuth flows to OAuthAuth (phase 4)
anthropic, openai-codex, and github-copilot flow modules gain OAuthAuth
exports (login/refresh/toAuth) wired to the prompt()/notify() login
callbacks, making the lazyOAuth attachments on the provider factories
functional. Copilot's modifyModels baseUrl rewriting becomes toAuth()
returning ModelAuth.baseUrl derived from the token proxy endpoint.

Callback-server flows race a manual_code prompt and abort it through
AuthPrompt.signal once the flow settles; OAuthAuth has no
usesCallbackServer flag. The old OAuthProviderInterface exports stay
unchanged until the coding-agent migration.
2026-06-10 20:41:29 +02:00
Mario Zechner fec0c3d12f feat(ai): provider factories, per-provider catalogs, createProvider (phase 3)
Auth helpers in src/auth/helpers.ts: envApiKeyAuth() (stored key wins,
then env vars in order, with secret-prompt login) and lazyOAuth()
(flow loads on first use through bundler-opaque dynamic imports in
utils/oauth/load.ts; the OAuthAuth flow exports land in phase 4).
There is no OAuth factory toggle: providers that support OAuth always
attach it, advertising costs nothing until login/refresh runs.

createProvider() in models.ts builds providers from parts: single API
implementation or a map dispatched on model.api (mixed-API providers
like opencode and github-copilot); unknown api yields a stream error.

generate-models.ts now emits one providers/<id>.models.ts catalog per
provider (35 files, biome-excluded like models.generated.ts) and
models.generated.ts becomes a generated aggregator, so importing one
provider factory pulls one catalog. Typed getModel globals unchanged.

One factory per built-in provider under src/providers/: envApiKeyAuth
for standard providers, OAuth for anthropic/openai-codex/github-copilot,
ambient ApiKeyAuth for amazon-bedrock (AWS env/profile/IAM) and
google-vertex (explicit key or ADC+project+location).

providers/all.ts: builtinProviders(), builtinModels(), getBuiltin*
re-exports. fauxProvider() factory returns a real Provider for tests;
legacy registerFauxProvider() unchanged.
2026-06-10 20:33:20 +02:00
Mario Zechner 20a9b82cf9 fix(ai): regenerate model catalog
Picks up the Claude Fable 5 thinking-off metadata (off: null in
thinkingLevelMap) that 9ccfcd7c added to the generator without
regenerating, fixing anthropic-thinking-disable and supports-xhigh
tests. Includes upstream catalog drift; OpenRouter delisted
moonshotai/kimi-k2.6:free, so the kimi compat test now pins only the
listed variant.
2026-06-10 20:09:13 +02:00
Mario Zechner ba93da9a93 feat(ai): move API implementations to src/api with lazy wrappers (phase 2)
Stream implementations move from src/providers/ to src/api/, renamed by
API id (anthropic.ts -> anthropic-messages.ts, google.ts ->
google-generative-ai.ts, mistral.ts -> mistral-conversations.ts,
amazon-bedrock.ts -> bedrock-converse-stream.ts). Every module now
exports exactly stream/streamSimple; shared helpers move alongside.

New ProviderStreams dispatch contract in types.ts, lazyApi() wrapper in
api/lazy.ts, and one .lazy.ts wrapper per API. Bedrock's wrapper keeps
the node-only variable-specifier import and setBedrockProviderModule()
(now taking ProviderStreams).

providers/register-builtins.ts deleted; interim until the compat
entrypoint lands, builtin api-registry registration lives in stream.ts
and lazy wrappers are exported from the root barrel. Old per-API lazy
exports (streamAnthropic, ...) are gone; package.json subpaths retarget
to dist/api/.
2026-06-10 20:08:59 +02:00
Mario Zechner ee276e4db5 Merge remote-tracking branch 'origin/main' into model-registry 2026-06-10 18:49:18 +02:00
Mario Zechner f63095cfff feat(ai): add Models runtime with provider-owned auth (phase 1)
New Models/MutableModels/createModels collection: provider map, async
model listing (best-effort aggregation), getAuth decision tree with
double-checked locked OAuth refresh, stream/complete with per-field
auth merge over lazyStream.

Auth substrate: ProviderAuth { apiKey?, oauth? }, one type-tagged
credential per provider, CredentialStore (read/modify/delete; modify
is the only write path, serialized RMW), OAuthAuth login/refresh/toAuth
split, prompt()/notify() login callbacks, browser-safe default
AuthContext.

types.ts: Provider alias renamed to ProviderId; ApiOptionsMap and
ApiStreamOptions<TApi> for typed per-API stream options; hasApi()
runtime narrowing guard.
2026-06-10 18:49:10 +02:00
Armin Ronacher 9ccfcd7cfc fix(ai): omit disabled thinking for Claude Fable 5 2026-06-10 00:27:11 +02:00
Armin Ronacher dacb367e9e fix(ai): expect Claude Fable 5 in adaptive thinking model test 2026-06-09 23:20:20 +02:00