You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maka.apache.org by as...@apache.org on 2026/08/27 14:11:30 UTC

(maka) branch main updated: ui(desktop): compact context window readout (#3983)

This is an automated email from the ASF dual-hosted git repository.

Astro-Han pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/maka.git


The following commit(s) were added to refs/heads/main by this push:
     new d00e276a9 ui(desktop): compact context window readout (#3983)
d00e276a9 is described below

commit d00e276a93c74828b2a892dd538a4c62ce2dd1bc
Author: Phoenix <Ph...@163.com>
AuthorDate: Thu Aug 27 22:11:24 2026 +0800

    ui(desktop): compact context window readout (#3983)
    
    CLOSES #3982
    
    Signed-off-by: Jiawei Zhao <Ph...@163.com>
---
 .../session-inspector-context-format.test.ts       | 44 ++++++++++++++++++++++
 .../src/renderer/features/workbar/testing.ts       |  2 +-
 .../tools/inspector/session-inspector-panel.tsx    | 26 +++++++++++--
 3 files changed, 68 insertions(+), 4 deletions(-)

diff --git a/apps/desktop/src/main/__tests__/session-inspector-context-format.test.ts b/apps/desktop/src/main/__tests__/session-inspector-context-format.test.ts
new file mode 100644
index 000000000..b8fd94310
--- /dev/null
+++ b/apps/desktop/src/main/__tests__/session-inspector-context-format.test.ts
@@ -0,0 +1,44 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import assert from 'node:assert/strict';
+import { test } from 'node:test';
+import { compactNumberFormatter } from '../../renderer/features/workbar/testing.js';
+
+test('formats context-window capacity with stable K/M units in every UI locale', () => {
+  for (const locale of ['en', 'zh'] as const) {
+    const format = compactNumberFormatter(locale);
+
+    assert.equal(format(256_000), '256K');
+    assert.equal(format(1_000_000), '1M');
+  }
+});
+
+test('formats context-window capacity with at most one decimal and promotes rounded K values to M', () => {
+  const format = compactNumberFormatter('en');
+
+  assert.equal(format(999), '999');
+  assert.equal(format(1_000), '1K');
+  assert.equal(format(8_192), '8.2K');
+  assert.equal(format(69_000), '69K');
+  assert.equal(format(69_194), '69.2K');
+  assert.equal(format(990_000), '990K');
+  assert.equal(format(999_950), '1M');
+  assert.equal(format(1_250_000), '1.3M');
+});
diff --git a/apps/desktop/src/renderer/features/workbar/testing.ts b/apps/desktop/src/renderer/features/workbar/testing.ts
index da788175e..532076cbd 100644
--- a/apps/desktop/src/renderer/features/workbar/testing.ts
+++ b/apps/desktop/src/renderer/features/workbar/testing.ts
@@ -32,7 +32,7 @@ export * from './model/workbar-tool-definitions.js';
 export * from './tools/artifacts/artifact-list-keyboard.js';
 export * from './tools/artifacts/artifact-visibility.js';
 export * from './tools/inspector/session-inspector-panel-model.js';
-export { InspectorCompositionSection } from './tools/inspector/session-inspector-panel.js';
+export { compactNumberFormatter, InspectorCompositionSection } from './tools/inspector/session-inspector-panel.js';
 export * from './tools/inspector/session-inspector-overview-model.js';
 export * from './tools/side-chat/quote-companion-panel-state.js';
 export * from './tools/side-chat/quote-companion-core.js';
diff --git a/apps/desktop/src/renderer/features/workbar/tools/inspector/session-inspector-panel.tsx b/apps/desktop/src/renderer/features/workbar/tools/inspector/session-inspector-panel.tsx
index 93363638a..53cf37b86 100644
--- a/apps/desktop/src/renderer/features/workbar/tools/inspector/session-inspector-panel.tsx
+++ b/apps/desktop/src/renderer/features/workbar/tools/inspector/session-inspector-panel.tsx
@@ -261,6 +261,7 @@ function InspectorOverview(props: {
 }) {
   const { copy, overview } = props;
   const formatNumber = numberFormatter(props.locale);
+  const formatCompactNumber = compactNumberFormatter(props.locale);
   const context = overview.context;
 
   return (
@@ -287,7 +288,12 @@ function InspectorOverview(props: {
       )}
 
       {context && (
-        <InspectorContextSection copy={copy} context={context} formatNumber={formatNumber} />
+        <InspectorContextSection
+          copy={copy}
+          context={context}
+          formatCompactNumber={formatCompactNumber}
+          formatNumber={formatNumber}
+        />
       )}
 
       {overview.composition && (
@@ -351,9 +357,10 @@ function FactRow(props: { label: ReactNode; value: ReactNode; swatch?: ReactNode
 function InspectorContextSection(props: {
   copy: InspectorCopy;
   context: NonNullable<ReturnType<typeof deriveInspectorOverviewModel>['context']>;
+  formatCompactNumber: (value: number) => string;
   formatNumber: (value: number) => string;
 }) {
-  const { context, copy, formatNumber } = props;
+  const { context, copy, formatCompactNumber, formatNumber } = props;
   const level = context.ratio >= 0.9 ? 'error' : context.ratio >= 0.7 ? 'warning' : undefined;
 
   return (
@@ -363,7 +370,7 @@ function InspectorContextSection(props: {
           {copy.overview.context}
         </Heading>
         <span className="maka-inspector-section-readout">
-          {formatNumber(context.usedTokens)} / {formatNumber(context.windowTokens)} ·{' '}
+          {formatCompactNumber(context.usedTokens)} / {formatCompactNumber(context.windowTokens)} ·{' '}
           {formatPercent(context.ratio)}
         </span>
       </div>
@@ -511,6 +518,19 @@ function numberFormatter(locale: UiLocale): (value: number) => string {
   return (value) => formatter.format(value);
 }
 
+export function compactNumberFormatter(_locale: UiLocale): (value: number) => string {
+  return (value) => {
+    if (value < 1_000) return String(value);
+
+    if (value < 1_000_000) {
+      const thousands = Math.round(value / 100) / 10;
+      return thousands >= 1_000 ? '1M' : `${thousands}K`;
+    }
+
+    return `${Math.round(value / 100_000) / 10}M`;
+  };
+}
+
 function formatPercent(ratio: number): string {
   return `${(ratio * 100).toFixed(1)}%`;
 }


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@maka.apache.org
For additional commands, e-mail: commits-help@maka.apache.org