Skip to content

Commit 2a79f74

Browse files
authored
fix(ui): prioritize active session quota provider (#120557) (#122053)
1 parent 49cd600 commit 2a79f74

2 files changed

Lines changed: 28 additions & 24 deletions

File tree

‎ui/src/pages/chat/chat-composer-context.test.ts‎

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -178,8 +178,17 @@ describe("renderChatComposer context usage", () => {
178178
expect(container.textContent).not.toContain("Est. cost");
179179
});
180180

181-
it("falls back from an unmatched session provider to the response quota group", () => {
182-
const container = renderComposer({
181+
it("uses response provenance only when the session provider is absent", () => {
182+
const session = {
183+
key: "main",
184+
kind: "direct",
185+
updatedAt: null,
186+
totalTokens: 1_000,
187+
contextTokens: 200_000,
188+
model: "gateway-injected",
189+
modelProvider: "openclaw" as string | undefined,
190+
};
191+
const composerProps = {
183192
messages: [
184193
{ role: "user", content: "hi" },
185194
{
@@ -191,19 +200,9 @@ describe("renderChatComposer context usage", () => {
191200
},
192201
],
193202
sessions: {
194-
sessions: [
195-
{
196-
key: "main",
197-
kind: "direct",
198-
updatedAt: null,
199-
totalTokens: 1_000,
200-
contextTokens: 200_000,
201-
model: "gateway-injected",
202-
modelProvider: "openclaw",
203-
},
204-
],
203+
sessions: [session],
205204
defaults: { contextTokens: 200_000 },
206-
} as never,
205+
},
207206
providerUsage: {
208207
modelAuthStatusResult: {
209208
ts: Date.now(),
@@ -231,16 +230,23 @@ describe("renderChatComposer context usage", () => {
231230
],
232231
},
233232
},
234-
});
235-
236-
expect(
233+
};
234+
const providerNames = (container: HTMLElement) =>
237235
[...container.querySelectorAll("[data-chat-usage-provider='true']")].map((row) =>
238236
row.textContent?.replace(/\s+/g, " ").trim(),
239-
),
240-
).toEqual(["Provider: OpenAI", "Provider: Claude"]);
241-
expect(container.textContent).not.toContain("Est. cost");
242-
expect(container.textContent).not.toContain("Cost by Type");
237+
);
238+
239+
const container = renderComposer(composerProps as never);
240+
241+
expect(providerNames(container)).toEqual(["Provider: Claude", "Provider: OpenAI"]);
242+
expect(container.textContent).toContain("Cost by Type");
243243
expect(container.textContent).not.toContain("Model:");
244+
245+
session.modelProvider = undefined;
246+
expect(providerNames(renderComposer(composerProps as never))).toEqual([
247+
"Provider: OpenAI",
248+
"Provider: Claude",
249+
]);
244250
});
245251

246252
it("omits the cost-by-type section when every recorded cost is zero", () => {

‎ui/src/pages/chat/components/chat-composer-context.ts‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,6 @@ function getContextNoticeViewModel(
120120
input: number | null;
121121
output: number | null;
122122
cost: number | null;
123-
provider: string | null;
124123
detail: string;
125124
color: string;
126125
bg: string;
@@ -154,7 +153,6 @@ function getContextNoticeViewModel(
154153
input,
155154
output,
156155
cost,
157-
provider: session?.modelProvider?.trim() || null,
158156
};
159157
if (!warning) {
160158
return {
@@ -350,7 +348,7 @@ export function renderContextNotice(
350348
)
351349
: undefined;
352350
};
353-
const currentGroup = findQuotaGroup(model?.provider) ?? findQuotaGroup(providerCosts?.provider);
351+
const currentGroup = findQuotaGroup(session?.modelProvider?.trim() || providerCosts?.provider);
354352
const planGroups = currentGroup
355353
? [currentGroup, ...quotaGroups.filter((group) => group !== currentGroup)]
356354
: quotaGroups;

0 commit comments

Comments
 (0)