Commit graph

12 commits

Author SHA1 Message Date
Bennet Bo Fenner
1dc07b40b9
copilot: Fix issue when switching between OpenAI and Anthropic models (#56655)
We were storing reasoning output inside `RedactedThinking` which causes
issues when switching mid-turn from an OpenAI to an Anthropic model.
This implementation fixes this by storing it inside `reasoning_details`,
which matches our responses implementation in `open_ai.rs`

See
https://github.com/microsoft/vscode-copilot-chat/blob/main/src/platform/endpoint/node/responsesApi.ts

For whatever reason the copilot chat extension sets `summary: []`, this
is what our implementation does too

Closes #56385

Release Notes:

- Fixed an issue where the agent would error when using Copilot as a
provider and switching between OpenAI and Anthropic models
2026-05-18 09:57:08 +00:00
Conrad Irwin
be705e677b
Merge gpui::Task and scheduler::Task (#53674)
Release Notes:

- N/A or Added/Fixed/Improved ...
2026-05-05 22:41:13 +00:00
Abhishek Tripathi
1115f768c9
copilot: Wire up reasoning tokens for GPT models (#53313)
Fix two issues with reasoning support in the Copilot provider:

- Responses API path: use the user's thinking_effort setting instead of
hardcoding Medium effort
- Chat Completions path: compute and pass thinking_budget when thinking
is enabled, instead of unconditionally setting it to None

Self-Review Checklist:

- [x] I've reviewed my own diff for quality, security, and reliability
- [ ] Unsafe blocks (if any) have justifying comments
- [ ] The content is consistent with the [UI/UX
checklist](https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md#uiux-checklist)
- [ ] Tests cover the new/changed behavior
- [ ] Performance impact has been considered and is acceptable

Closes #52140

Release Notes:

- Fixed a bug where copilot wouldn't use the thinking level the user's
have set

---------

Co-authored-by: Bennet Bo Fenner <bennetbo@gmx.de>
Co-authored-by: Bennet Bo Fenner <bennet@zed.dev>
2026-04-20 14:33:18 +02:00
Valery Borovsky
b0f286042b
copilot_chat: Serialize ToolChoice::Any as "required" instead of "any" (#52015)
**Observed behavior:** Inline assistant failed for GPT-4.1,
Gemini, and other non-Anthropic models. Claude worked correctly because
Anthropic's API accepts `"any"` as a valid value.

## Fix
Renamed `ToolChoice::Any` → `ToolChoice::Required` in both
`copilot_chat.rs` and `responses.rs`, matching the convention used by
other OpenAI-compatible providers (`open_ai`, `lmstudio`,
`open_router`).

`copilot_chat::ToolChoice` is a wire type only for the
`/chat/completions`
path — Anthropic models go through `into_anthropic()` and never touch
it,
so no per-model logic is needed.

Also fixes the same serialization bug in `responses::ToolChoice`, which
was not covered by the original approach, and adds regression tests for
both.

## Affected models
- `gpt-4.1` via copilot_chat provider
- `gemini-*` via copilot_chat provider
- Likely affects all OpenAI-compatible models routed through
copilot_chat

## Screenshots
**Bug (only Claude works, Gemini and GPT-4.1 fail):**
<img width="598" height="209" alt="image"
src="https://github.com/user-attachments/assets/bbd418d9-7de3-4191-9ca9-fd1961534e23"
/>

**Fix:**
<img width="532" height="154" alt="image"
src="https://github.com/user-attachments/assets/86bb0f8e-67e6-4417-9b78-b1b7ad328e9e"
/>

**Result:** After the fix, all models work correctly via inline
assistant.

## Release Notes
- Fix inline assistant 400 errors for GPT-4.1, Gemini, and other
  non-Anthropic models via the copilot_chat provider (`tool_choice` was
  sending `"any"` instead of `"required"`)
2026-03-24 13:22:21 +00:00
John Tur
dde76cd5f8
Enable extended reasoning for Anthropic models in Copilot (#46540)
Fixes https://github.com/zed-industries/zed/issues/45668

https://github.com/microsoft/vscode-copilot-chat used as a reference for
headers and properties we need to set

| Before | After | 
| --- | --- |
| <img width="300"
src="https://github.com/user-attachments/assets/d112a9ef-52d2-42ff-a77b-4b4b15f950fe"
/>| <img width="300"
src="https://github.com/user-attachments/assets/0f1d7ae0-bee1-46f7-92ef-aea0fa6cde7a"
/> |

Release Notes:

- Enabled thinking mode when using Anthropic models with Copilot
2026-03-08 09:34:46 +00:00
Sathiyaraman M
6e33d838c9
copilot: Display cost multiplier for Github Copilot models (#44800)
### Description

Related Discussions: #44499, #35742, #31851

Display cost multiplier for GitHub Copilot models in the model selectors
(Both in Chat Panel and Inline Assistant)

<img width="436" height="800" alt="image"
src="https://github.com/user-attachments/assets/c9ebd8fa-4d55-4be8-b3e1-f46dbf1f0145"
/>


### Some technical notes

Although this PR's primary intent is to show the cost multiplier for
GitHub Copilot models alone, I have included some necessary plumbing to
allow specifying costs for other providers in future. I have introduced
an enum called `LanguageModelCostInfo` for showing cost in different
ways for different models. Now, this enum is used in `LanguageModel`
trait to get the cost info.

For now to begin with, in `LanguageModelCostInfo`, I have specified two
ways of pricing: Request-based (1 Agent request - GitHub Copilot uses
this) and Token-based (1M Input tokens / 1M Output tokens). I had
initially thought about adding a `Free` type, especially for Ollama but
didn't do it after realizing that Ollama has paid plans. Right now, only
the Request-based pricing is implemented and used for Copilot models.

Feel free to suggest changes on how to improve this design better.

Release Notes:

- Show cost multiplier for GitHub Copilot models

---------

Co-authored-by: Danilo Leal <daniloleal09@gmail.com>
2026-02-16 15:24:59 -03:00
Anil Pai
13ad175c8d
copilot_chat: Return true context window size (#47557)
## Fix incorrect context size limits for GitHub Copilot Chat models

Fixes #44909

### Problem

The agent panel was displaying incorrect token limits for GitHub Copilot
models. Users reported that:
- The agent panel always showed a **128K token limit** for all GitHub
Copilot models, regardless of their actual context window size
- Claude models (e.g., Claude 3.7 Sonnet, Claude Opus 4.5) were showing
~90K instead of their actual 200K context window
- GPT-4o was showing 110K instead of its actual 128K context window
- Users could continue using models beyond the displayed limit, which
worked but was confusing

### Root Cause

The `max_token_count()` method in `copilot_chat.rs` was returning
`max_prompt_tokens` instead of `max_context_window_tokens`:

```rust
// Before (incorrect)
pub fn max_token_count(&self) -> u64 {
    self.capabilities.limits.max_prompt_tokens
}
```

GitHub's API returns three different token-related fields:
- `max_context_window_tokens`: The **full context window size** (e.g.,
200K for Claude 3.7)
- `max_prompt_tokens`: GitHub's limit for prompt input (e.g., 90K for
Claude 3.7)
- `max_output_tokens`: Maximum output tokens (e.g., 16K)

The `max_token_count()` method in the `LanguageModel` trait is expected
to return the **full context window size** — this is consistent with all
other providers (Anthropic returns 200K for Claude, OpenAI returns 128K
for GPT-4o, etc.).

### Solution

<img width="583" height="132" alt="Screenshot 2026-01-25 at 1 07 53 AM"
src="https://github.com/user-attachments/assets/847e2fdb-635d-44bc-a630-2d4867ba8c32"
/>


Changed `max_token_count()` to return `max_context_window_tokens`:

```rust
// After (correct)
pub fn max_token_count(&self) -> u64 {
    self.capabilities.limits.max_context_window_tokens as u64
}
```

### Impact

| Model | Before | After |
|-------|--------|-------|
| Claude 3.7 Sonnet | 90,000 | **200,000** |
| Claude Opus 4.5 | 90,000 | **200,000** |
| GPT-4o | 110,000 | **128,000** |

### Testing

Added a new test
`test_max_token_count_returns_context_window_not_prompt_tokens` that:

1. Deserializes model JSON with distinct `max_context_window_tokens` and
`max_prompt_tokens` values
2. Verifies Claude 3.7 Sonnet returns 200,000 (context window), not
90,000 (prompt tokens)
3. Verifies GPT-4o returns 128,000 (context window), not 110,000 (prompt
tokens)

All existing tests continue to pass:
```
running 4 tests
test tests::test_unknown_vendor_resilience ... ok
test tests::test_max_token_count_returns_context_window_not_prompt_tokens ... ok
test tests::test_resilient_model_schema_deserialize ... ok
test result: ok. 4 passed; 0 failed
```


Release Notes:

- copilot: Fixed incorrect context window size displayed for GitHub
Copilot Chat models in the agent panel.
2026-02-12 15:02:17 +00:00
Richard Feldman
6cd7586c16
Switch to a Zed user-agent header for Copilot traffic (#48591)
Follow-up to #48528

Release Notes:

- N/A

---------

Co-authored-by: Mikayla Maki <mikayla.c.maki@gmail.com>
2026-02-11 00:13:14 +00:00
Mikayla Maki
ff4489f426
Revert "Remove VS Code references from Copilot integration" (#48555)
Reverts zed-industries/zed#48528

Release Notes:

- N/A
2026-02-06 03:34:34 +00:00
Mikayla Maki
72a12eb97c
Remove VS Code references from Copilot integration (#48528)
Release Notes:

- N/A
2026-02-05 21:28:56 +00:00
Anil Pai
2f3c013cc7
copilot_chat: Fix Anthropic models not appearing in model picker (#47549)
## Summary

Fixes #47540 - Anthropic Claude models not appearing in GitHub Copilot
Chat model picker.

## Problem

Users reported that Anthropic Claude models (Claude Sonnet 4, Claude
Opus 4, etc.) were not appearing in the model picker when using GitHub
Copilot Chat, even though:
- The GitHub Copilot API returns these models
- The models have `model_picker_enabled: true`
- Users have valid Copilot subscriptions with access to these models

## Root Cause

The issue was in the `ModelSupportedEndpoint` enum deserialization. The
enum only defined two variants:

```rust
pub enum ModelSupportedEndpoint {
    #[serde(rename = "/chat/completions")]
    ChatCompletions,
    #[serde(rename = "/responses")]
    Responses,
}
```

Anthropic Claude models use the `/v1/messages` endpoint, which wasn't
defined. When deserializing the API response, serde failed with:

```
Error("unknown variant `/v1/messages`, expected `/chat/completions` or `/responses`")
```

Because the crate uses resilient deserialization via
`deserialize_models_skip_errors()`, the entire Claude model was silently
skipped rather than causing a hard failure. This meant users saw no
error - the models simply didn't appear.

## Solution

### 1. Added `/v1/messages` endpoint variant

```rust
pub enum ModelSupportedEndpoint {
    #[serde(rename = "/chat/completions")]
    ChatCompletions,
    #[serde(rename = "/responses")]
    Responses,
    #[serde(rename = "/v1/messages")]
    Messages,  // NEW: Anthropic models use this endpoint
    #[serde(other)]
    Unknown,   // NEW: Future-proofing for unknown endpoints
}
```

### 2. Removed incorrect `dedup_by()` call

The previous code deduplicated models by family:

```rust
.dedup_by(|a, b| a.capabilities.family == b.capabilities.family)
```

This incorrectly filtered out model variants that share the same family
(e.g., `claude-sonnet-4` and `claude-sonnet-4-thinking`). Removed this
call to preserve all model variants.

### 3. Removed unused import

Removed `use itertools::Itertools;` which was only used for the
now-removed `dedup_by()`.

## Changes

| File | Change |
|------|--------|
| `crates/copilot_chat/src/copilot_chat.rs` | Added `Messages` and
`Unknown` variants to `ModelSupportedEndpoint` enum |
| `crates/copilot_chat/src/copilot_chat.rs` | Removed `.dedup_by()` call
that incorrectly filtered models |
| `crates/copilot_chat/src/copilot_chat.rs` | Removed unused
`itertools::Itertools` import |
| `crates/copilot_chat/src/copilot_chat.rs` | Added 8 new unit tests |

## Test Coverage

Added 8 new unit tests to ensure the fix works and prevent regression:

| Test | Purpose |
|------|---------|
| `test_models_with_pending_policy_deserialize` | Verifies models with
non-"enabled" policy states deserialize correctly (they're filtered
later) |
| `test_multiple_anthropic_models_preserved` | Verifies multiple Claude
models are not incorrectly deduplicated |
| `test_models_with_same_family_both_preserved` | Verifies models
sharing the same family (e.g., thinking variants) are both preserved |
| `test_mixed_vendor_models_all_preserved` | Verifies models from
different vendors (OpenAI, Anthropic, Google) are all preserved |
| `test_model_with_messages_endpoint_deserializes` | **Critical test**:
Verifies `/v1/messages` endpoint deserializes correctly |
| `test_model_with_unknown_endpoint_deserializes` | Verifies unknown
future endpoints deserialize to `Unknown` variant |
| `test_model_with_multiple_endpoints` | Verifies models with multiple
endpoints deserialize correctly |
| `test_supports_response_method` | Verifies the `supports_response()`
method logic for endpoint routing |

### Test Results

```
running 10 tests
test tests::test_model_with_messages_endpoint_deserializes ... ok
test tests::test_model_with_multiple_endpoints ... ok
test tests::test_model_with_unknown_endpoint_deserializes ... ok
test tests::test_models_with_pending_policy_deserialize ... ok
test tests::test_models_with_same_family_both_preserved ... ok
test tests::test_mixed_vendor_models_all_preserved ... ok
test tests::test_multiple_anthropic_models_preserved ... ok
test tests::test_resilient_model_schema_deserialize ... ok
test tests::test_supports_response_method ... ok
test tests::test_unknown_vendor_resilience ... ok

test result: ok. 10 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out
```

## How to Test Manually

1. Sign in to GitHub Copilot in Zed
2. Open the model picker (Agent panel → model selector dropdown)
3. Verify that Anthropic Claude models appear in the list:
   - Claude Sonnet 4
   - Claude Opus 4
   - Other Claude variants (if enabled in your GitHub Copilot settings)

## Checklist

- [x] Code compiles without errors
- [x] `./script/clippy --package copilot_chat` passes with no warnings
- [x] All unit tests pass
- [x] Change is focused on a single bug fix
- [x] No unrelated refactoring or feature additions


<img width="320" height="400" alt="Screenshot 2026-01-24 at 11 57 21 PM"
src="https://github.com/user-attachments/assets/d5e17e1b-da80-4f4d-a218-d50d35114a21"
/>


Release Notes:

- Fixed Anthropic models not appearing in the Copilot Chat model picker

---------

Co-authored-by: Piotr Osiewicz <24362066+osiewicz@users.noreply.github.com>
2026-01-25 13:10:22 +01:00
Piotr Osiewicz
ca23fa7c7c
copilot: Un-globalify copilot + handle it more directly with EditPredictionStore (#46618)
- **copilot: Fix double lease panic when signing out**
- **Extract copilot_chat into a separate crate**
- **Do not use re-exports from copilot**
- **Use new SignIn API**
- **Extract copilot_ui out of copilot**

Closes #7501

Release Notes:

- Fixed Copilot providing suggestions from different Zed windows.
- Copilot edit predictions now support jumping to unresolved
diagnostics.
2026-01-14 14:44:13 +00:00