Commit Graph

246 Commits

Author SHA1 Message Date
Cristina Poncela Cubeiro
d9adc536f5 feat: openrouter images 2026-05-04 17:00:58 +02:00
Cristina Poncela Cubeiro
cbf3c333ef revert 2026-05-04 15:43:45 +02:00
Cristina Poncela Cubeiro
59a89e0c1c fix: modalities from openrouter 2026-04-29 09:51:57 +02:00
Cristina Poncela Cubeiro
364ac0f3ab fix: test (openRouterImageGeneration) 2026-04-28 14:40:13 +02:00
Cristina Poncela Cubeiro
c3c10737d8 feat: image content 2026-04-28 13:43:28 +02:00
MC
d6e08b3da0 feat(ai): add Cloudflare Workers AI as a provider (#3851)
* feat(ai): add Cloudflare Workers AI as a provider

Cloudflare Workers AI hosts open-weight LLMs (Kimi K2.6, GPT-OSS,
GLM-4.7, Llama 4, Gemma 4, Nemotron 3) on Cloudflare's GPU network with
an OpenAI-compatible endpoint. Reuses the openai-completions API
protocol; the per-account URL contains a {CLOUDFLARE_ACCOUNT_ID}
placeholder resolved at request time by a small helper.

Pi automatically sets x-session-affinity for prefix caching:
https://developers.cloudflare.com/workers-ai/features/prompt-caching/

Auth: CLOUDFLARE_API_KEY (matches pi's *_API_KEY convention) +
CLOUDFLARE_ACCOUNT_ID. The User-Agent identifies traffic as
'pi-coding-agent' in Cloudflare analytics.

Verified end-to-end against a real Cloudflare account: 17 e2e tests
pass across stream/empty/tokens/unicode/tool-call-without-result/
total-tokens against @cf/moonshotai/kimi-k2.6.

Cloudflare AI Gateway is a separate, larger change (it requires routing
through provider-specific subpaths with the matching API protocol per
upstream) and will land in a follow-up PR.

* refactor(ai): move Cloudflare User-Agent and session-affinity flag to per-model metadata

Instead of conditionally setting them in openai-completions.ts based on
provider detection, declare them as model-level fields in the catalog
(headers + compat). This is consistent with how the github-copilot and
kimi-coding entries already declare their static headers.

  packages/ai/scripts/generate-models.ts: emit headers and compat fields
  on each cloudflare-workers-ai entry (CLOUDFLARE_STATIC_HEADERS).
  packages/ai/src/providers/openai-completions.ts: drop the
  isCloudflareProvider conditional that injected User-Agent and the
  isCloudflareWorkersAI override of sendSessionAffinityHeaders.
  packages/ai/src/models.generated.ts: re-spliced 8 cloudflare-workers-ai
  entries with headers + compat.

Behavior is unchanged - verified via fetch interceptor that User-Agent
and x-session-affinity / session_id / x-client-request-id are still sent
on outbound requests. 5/5 e2e tests pass.
2026-04-27 23:41:54 +02:00
Mario Zechner
65fc803671 fix(ai): refresh generated model catalog for release 2026-04-27 21:28:21 +02:00
Mario Zechner
27c0c2ec13 chore(ai): format bedrock thinking payload test 2026-04-27 21:02:11 +02:00
marcbloech
9dcde1e3fa add cognitive services implementation (#3799) 2026-04-27 18:38:03 +02:00
anirudhmarc
5a07d946ef fix(bedrock): check model.name for prompt caching and adaptive thinking (#3527)
supportsPromptCaching, supportsAdaptiveThinking, supportsThinkingSignature,
and the Claude detection in streamSimpleBedrock/buildAdditionalModelRequestFields
all check model.id for Claude model name patterns. Application inference profile
ARNs are opaque and do not contain the model name, so these checks silently fail.

Fix by also checking model.name (user-controlled via models.json or
registerProvider) as a fallback in all affected functions. Added a shared
isAnthropicClaudeModel helper for the common Claude detection pattern.

Fixes #2925

Co-authored-by: Your Name <you@example.com>
2026-04-25 19:58:17 +02:00
Mario Zechner
3e7ffff184 fix(ai): ignore unknown anthropic sse events
closes #3708
2026-04-25 16:57:03 +02:00
Mario Zechner
91154d9757 fix: update stale CI test expectations 2026-04-24 20:22:16 +02:00
HQidea
3e0ee69b5e fix(ai): omit tools field instead of sending empty array (#3650)
DashScope / Aliyun Qwen (OpenAI-compatible) rejects `tools: []`
with HTTP 400 `"[] is too short - 'tools'"`. Five providers used
a truthy check (`if (context.tools)`) that treated an empty array
as "send tools", so `pi --no-tools` produced `tools: []` in the
request body. Matching the Google provider's pattern, we now
guard on `context.tools.length > 0`:

- openai-completions.ts
- openai-responses.ts
- openai-codex-responses.ts
- azure-openai-responses.ts
- anthropic.ts

The openai-completions fallback that emits `tools: []` when the
conversation has tool history (required by LiteLLM / Anthropic
proxies) is preserved via the existing `else if (hasToolHistory)`
branch.

closes #3649

Co-authored-by: 槐聚 <huaiju@zbyte-inc.com>
Co-authored-by: Claude Opus 4.7 <noreply@anthropic.com>
Co-authored-by: Mario Zechner <badlogicgames@gmail.com>
2026-04-24 14:24:31 +02:00
Mario Zechner
1e33492525 fix(coding-agent): harden clipboard copy
closes #3639
2026-04-24 12:55:58 +02:00
Mario Zechner
65a6472bdd fix(ai): forward google vertex base url
closes #3619
2026-04-24 00:05:43 +02:00
Mario Zechner
95f4921250 fix(ai): repair codex stream test merge conflict 2026-04-23 23:51:20 +02:00
Markus Ylisiurunen
ba8f1c228a Align GPT-5.5 Codex capability handling (#3618)
* fix(ai): align gpt-5.5 codex capabilities

* chore(ai): update generated models

* fix(ai): apply gpt-5.5 priority pricing to api

---------

Co-authored-by: Mario Zechner <badlogicgames@gmail.com>
2026-04-23 23:49:33 +02:00
Mario Zechner
4cd4cfd98e fix(ai): support long cache retention compat
closes #3543
2026-04-23 23:43:34 +02:00
Mario Zechner
1312346199 fix(ai): expand Copilot eager streaming compat
closes #3575
2026-04-23 23:43:00 +02:00
Mario Zechner
c681d35d76 fix(ai): avoid double-counting reasoning tokens
closes #3581
2026-04-23 23:28:16 +02:00
Mario Zechner
ffa0f31239 fix(ai): support Anthropic eager tool streaming compat
closes #3575
2026-04-23 23:12:45 +02:00
Mario Zechner
6af10c9c7f fix(ai): make OpenAI Responses session_id header optional closes #3579 2026-04-23 23:12:24 +02:00
Mario Zechner
bf4aa3a601 fix(ai): support xhigh for Codex GPT-5.5 2026-04-23 22:49:09 +02:00
Armin Ronacher
0cb8ff3843 fix(ai): Restore original api contract for getEnvApiKey 2026-04-23 22:04:42 +02:00
Mario Zechner
535fdcea2c test(ai): refresh responses and codex e2e coverage closes #3576 2026-04-23 21:36:16 +02:00
Armin Ronacher
e97051313d fix(coding-agent,ai): show env auth source in /login 2026-04-23 21:19:53 +02:00
Mario Zechner
01509156b3 fix(ai): coalesce malformed streamed tool calls closes #3576 2026-04-23 16:05:21 +02:00
Mario Zechner
3dacaa8ed9 fix(coding-agent,tui): drop typebox compiler shim and fix progress 2026-04-22 21:12:20 +02:00
Armin Ronacher
35ff2689ee fix(typebox): migrate to v1 with extension compat (#3474)
* fix(typebox): migrate to v1 with extension compat

Replace AJV-based validation with TypeBox-native validation, keep legacy extension imports working (including @sinclair/typebox/compiler), and restore coercion for serialized/plain JSON schemas.

This change closes #3112.

* fix(typebox): use canonical imports and harden coercion

Switch first-party code to canonical typebox imports while retaining legacy extension aliases in the loader.

Remove obsolete runtime codegen guards, expand serialized JSON-schema coercion coverage, and update related tests and fixtures.

Fixes #3112.

---------

Co-authored-by: Mario Zechner <badlogicgames@gmail.com>
2026-04-22 19:59:33 +02:00
Mario Zechner
a23fab4693 fix(ai): synthesize trailing orphaned tool results closes #3555 2026-04-22 19:41:55 +02:00
Mario Zechner
8234ebf9ee feat(coding-agent,tui): add stacked autocomplete providers closes #2983 2026-04-22 15:44:08 +02:00
Mario Zechner
0bb0a58466 feat(ai): add Fireworks provider support closes #3519 2026-04-22 01:09:11 +02:00
Mario Zechner
e58d631c89 Reapply "fix(ai): own Anthropic SSE parsing to avoid SDK JSON.parse hard-failures"
This reverts commit fc9220d2de.
2026-04-21 23:42:19 +02:00
Mario Zechner
fc9220d2de Revert "fix(ai): own Anthropic SSE parsing to avoid SDK JSON.parse hard-failures"
This reverts commit 4b926a30a2.
2026-04-21 23:19:52 +02:00
Mario Zechner
4b926a30a2 fix(ai): own Anthropic SSE parsing to avoid SDK JSON.parse hard-failures
Bypass the Anthropic SDK streaming parser entirely. Use
client.messages.create().asResponse() and decode the SSE stream
ourselves with defensive JSON parsing that repairs invalid escape
sequences and control characters inside string literals.

- Switch from SDK .stream() to .asResponse() + pi-owned SSE decoder
- Add repairJson() / parseJsonWithRepair() to json-parse.ts
- Add anthropic-sse-parsing.test.ts regression for malformed tool deltas
- Update github-copilot-anthropic.test.ts mock to match new call path
- Update deprecated claude-3-5-haiku-20241022 refs to claude-haiku-4-5
- Remove stale non-reasoning model test

fixes #3175
2026-04-21 23:00:56 +02:00
Mario Zechner
a0a16c7762 fix(amazon-bedrock): restore regional endpoint resolution
closes #3481
closes #3485
closes #3486
closes #3487
closes #3488
2026-04-21 13:20:10 +02:00
Mario Zechner
1d488626d9 fix(ai): preserve requiresThinkingAsText replay semantics closes #3387 2026-04-20 19:44:38 +02:00
Mario Zechner
3054fd7a3b fix(ai,coding-agent): support anthropic-style cache control for openai compatibles closes #3392 2026-04-20 17:12:05 +02:00
Mario Zechner
4b2caf43a8 fix(ai): add completions session affinity compat closes #3430 2026-04-20 16:55:16 +02:00
Mario Zechner
aa1b587b10 fix(ai): add direct OpenAI completions prompt caching closes #3426 2026-04-20 15:37:29 +02:00
Ramiz Wachtler
cbe0e8304f fix(ai): replace stale OpenRouter Llama 4 Maverick test model with Llama 4 Scout (#3421)
* fix(ai): replace stale OpenRouter Llama 4 Maverick test model

- Switch OpenRouter Meta test model from `meta-llama/llama-4-maverick` to `meta-llama/llama-4-scout` in AI tests.

- CI failure body:
  - packages/ai/test/context-overflow.test.ts(531,41): error TS2345: Argument of type "meta-llama/llama-4-maverick" is not assignable to parameter of type "...".
  - packages/ai/test/total-tokens.test.ts(520,40): error TS2345: Argument of type "meta-llama/llama-4-maverick" is not assignable to parameter of type "...".

* chore(ai): add changelog entry for OpenRouter test model swap

- Add Unreleased Fixed entry for switching OpenRouter Meta test model to llama-4-scout

- Reference PR #3421 attribution
2026-04-20 13:21:29 +02:00
Vladyslav Tkachenko
f732f5e858 fix(ai): strip JSON Schema meta keys for Cloud Code Assist (#3412) 2026-04-19 16:54:49 +02:00
Mario Zechner
454b9619c7 fix(ai): use SDK token auth and omit Bedrock display in GovCloud closes #3359 2026-04-18 01:24:13 +02:00
Mario Zechner
2dddc5ba25 fix(ai): sanitize Mistral tool schemas closes #3361 2026-04-18 00:54:46 +02:00
Mario Zechner
62778a82d5 fix(ai): use reasoning_effort for Mistral Small 4 closes #3338 2026-04-17 22:44:27 +02:00
Markus Ylisiurunen
2cdac7382a fix(ai): trust requested Codex service tier (#3307) 2026-04-17 01:50:04 +02:00
Mario Zechner
8404fbafdb test(ai): align adaptive thinking payload assertions 2026-04-17 00:35:07 +02:00
Mario Zechner
f84c4c89f5 fix(ai): restore FakeOpenAI mock .withResponse() so openai-completions tests pass
The openai-completions provider now calls .withResponse() on the
create() result to surface HTTP status/headers for the new onResponse
hook (d131fcd4). The FakeOpenAI test mock only returned an async
iterable, so 4 tests in openai-completions-tool-choice.test.ts that
actually consume the stream failed with "withResponse is not a function".

Updated the mock to return a Promise augmented with .withResponse()
resolving to { data: <async iterable>, response: { status, headers } }.

closes #3304
2026-04-16 22:57:30 +02:00
Vegard Stikbakke
45f1a2cd00 fix(ai): set session id headers for all OpenAI compatible responses (#3264) 2026-04-16 22:38:40 +02:00
Markus Ylisiurunen
d1c6cb1e0f fix(ai): Fix a configuration bug with Opus 4.7 adaptive thinking (#3286) 2026-04-16 19:57:19 +02:00