fix(vscode): force fresh ACP session on new-session action (#2874)

* fix(vscode-ide-companion/session): force fresh sessions for new chats

Ensure explicit new-session actions bypass active ACP session reuse so the VS Code sidebar clears context correctly.

Add regression coverage for the agent manager and webview new-session entry points.

* fix(vscode): remove core runtime imports from webview bundle

Replace the runtime import of `isSupportedImageMimeType` from
`@qwen-code/qwen-code-core` with a local `SUPPORTED_PASTED_IMAGE_MIME_TYPES`
set in the vscode-ide-companion package. The webview is bundled for a
browser environment where Node.js-only core modules are unavailable,
so keeping the MIME list local avoids esbuild failures during development.

Added tests to verify the local list stays aligned with core and that
the webview bundle does not contain core runtime imports.

* fix(vscode): reset context usage display on new session (#2847)

The webview context-usage bar did not clear when the user started a new
session because the old code always fell back to DEFAULT_TOKEN_LIMIT,
producing a stale percentage even after usageStats and modelInfo were
both cleared.

Key changes:
- Extract `knownTokenLimit()` in core/tokenLimits.ts that returns
  `undefined` for unrecognized models instead of a default, keeping
  `tokenLimit()` behavior unchanged.
- In acpModelInfo.ts, derive `_meta.contextLimit` from the known-model
  table when the ACP payload omits a numeric limit.
- Extract `computeContextUsage()` into its own module, which returns
  `null` when no trusted numeric limit is available — the UI then
  correctly hides the context bar.
- Remove the `@qwen-code/qwen-code-core` runtime import from App.tsx
  so the webview bundle stays free of Node-only dependencies.

Closes #2847

* fix(vscode-ide-companion/webview): reset state on new session

* test(vscode-ide-companion/webview): cover stale conversation reset

* fix(vscode): remove webview token limit runtime import

* fix(vscode): fully reset state for explicit new session

* fix(vscode-ide-companion/webview): clear residual state on new session

---------

Co-authored-by: tanzhenxin <tanzhenxing1987@gmail.com>
This commit is contained in:
易良 2026-04-11 10:16:16 +08:00 committed by GitHub
parent 505be40f82
commit fb91acdf25
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
19 changed files with 839 additions and 107 deletions

View file

@ -0,0 +1,87 @@
/**
* @license
* Copyright 2025 Qwen Team
* SPDX-License-Identifier: Apache-2.0
*/
import { describe, expect, it } from 'vitest';
import { computeContextUsage } from './contextUsage.js';
describe('computeContextUsage', () => {
it('returns null when there is no trusted token limit', () => {
expect(
computeContextUsage(
{
usage: {
promptTokens: 1234,
},
},
{
modelId: 'unknown-model',
name: 'Unknown Model',
},
),
).toBeNull();
});
it('prefers usageStats.tokenLimit over model metadata', () => {
expect(
computeContextUsage(
{
usage: {
promptTokens: 1000,
},
tokenLimit: 4000,
},
{
modelId: 'qwen3-max',
name: 'Qwen3 Max',
_meta: { contextLimit: 8000 },
},
),
).toEqual({
percentLeft: 75,
usedTokens: 1000,
tokenLimit: 4000,
});
});
it('falls back to model metadata when usageStats does not include a limit', () => {
expect(
computeContextUsage(
{
usage: {
promptTokens: 2000,
},
},
{
modelId: 'qwen3-max',
name: 'Qwen3 Max',
_meta: { contextLimit: 8000 },
},
),
).toEqual({
percentLeft: 75,
usedTokens: 2000,
tokenLimit: 8000,
});
});
it('uses inputTokens when promptTokens is unavailable', () => {
expect(
computeContextUsage(
{
usage: {
inputTokens: 3000,
},
tokenLimit: 12000,
},
null,
),
).toEqual({
percentLeft: 75,
usedTokens: 3000,
tokenLimit: 12000,
});
});
});