mirror of
https://github.com/QwenLM/qwen-code.git
synced 2026-04-30 20:50:34 +00:00
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:
parent
505be40f82
commit
fb91acdf25
19 changed files with 839 additions and 107 deletions
|
|
@ -2,6 +2,7 @@ import { describe, it, expect } from 'vitest';
|
|||
import {
|
||||
normalize,
|
||||
tokenLimit,
|
||||
knownTokenLimit,
|
||||
DEFAULT_TOKEN_LIMIT,
|
||||
DEFAULT_OUTPUT_TOKEN_LIMIT,
|
||||
} from './tokenLimits.js';
|
||||
|
|
@ -234,6 +235,21 @@ describe('tokenLimit', () => {
|
|||
});
|
||||
});
|
||||
|
||||
describe('knownTokenLimit', () => {
|
||||
it('returns a limit for known input models', () => {
|
||||
expect(knownTokenLimit('qwen3-max')).toBe(262144);
|
||||
expect(knownTokenLimit('gpt-5')).toBe(272000);
|
||||
});
|
||||
|
||||
it('returns a limit for known output models', () => {
|
||||
expect(knownTokenLimit('qwen3-max', 'output')).toBe(32768);
|
||||
});
|
||||
|
||||
it('returns undefined for unknown models instead of the default fallback', () => {
|
||||
expect(knownTokenLimit('unknown-model-v1.0')).toBeUndefined();
|
||||
});
|
||||
});
|
||||
|
||||
describe('tokenLimit with output type', () => {
|
||||
describe('latest models output limits', () => {
|
||||
it('should return correct output limits for GPT-5.x', () => {
|
||||
|
|
|
|||
|
|
@ -191,6 +191,22 @@ const OUTPUT_PATTERNS: Array<[RegExp, TokenCount]> = [
|
|||
[/^kimi-k2\.5/, LIMITS['32k']],
|
||||
];
|
||||
|
||||
function findTokenLimit(
|
||||
model: Model,
|
||||
type: TokenLimitType = 'input',
|
||||
): TokenCount | undefined {
|
||||
const norm = normalize(model);
|
||||
const patterns = type === 'output' ? OUTPUT_PATTERNS : PATTERNS;
|
||||
|
||||
for (const [regex, limit] of patterns) {
|
||||
if (regex.test(norm)) {
|
||||
return limit;
|
||||
}
|
||||
}
|
||||
|
||||
return undefined;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a model has an explicitly defined output token limit.
|
||||
* This distinguishes between models with known limits in OUTPUT_PATTERNS
|
||||
|
|
@ -204,6 +220,13 @@ export function hasExplicitOutputLimit(model: Model): boolean {
|
|||
return OUTPUT_PATTERNS.some(([regex]) => regex.test(norm));
|
||||
}
|
||||
|
||||
export function knownTokenLimit(
|
||||
model: Model,
|
||||
type: TokenLimitType = 'input',
|
||||
): TokenCount | undefined {
|
||||
return findTokenLimit(model, type);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the token limit for a model string based on the specified type.
|
||||
*
|
||||
|
|
@ -223,17 +246,8 @@ export function tokenLimit(
|
|||
model: Model,
|
||||
type: TokenLimitType = 'input',
|
||||
): TokenCount {
|
||||
const norm = normalize(model);
|
||||
|
||||
// Choose the appropriate patterns based on token type
|
||||
const patterns = type === 'output' ? OUTPUT_PATTERNS : PATTERNS;
|
||||
|
||||
for (const [regex, limit] of patterns) {
|
||||
if (regex.test(norm)) {
|
||||
return limit;
|
||||
}
|
||||
}
|
||||
|
||||
// Return appropriate default based on token type
|
||||
return type === 'output' ? DEFAULT_OUTPUT_TOKEN_LIMIT : DEFAULT_TOKEN_LIMIT;
|
||||
return (
|
||||
knownTokenLimit(model, type) ??
|
||||
(type === 'output' ? DEFAULT_OUTPUT_TOKEN_LIMIT : DEFAULT_TOKEN_LIMIT)
|
||||
);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue