@kabmo-labs/kabmo 0.26.0 → 0.27.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/client/index.html +1 -1
- package/dist/client/index.js +164 -164
- package/dist/client/static/js/index-32rpkj6b.css +1 -0
- package/dist/client/static/js/{index-95b3n20k.js → index-e3qh2yps.js} +668 -668
- package/package.json +1 -1
- package/src/client/components/common/Toast.test.tsx +28 -2
- package/src/client/components/common/Toast.tsx +21 -9
- package/src/client/components/layout/desktop-layout/LeftColumn.tsx +2 -1
- package/src/client/components/layout/session-sidebar/CategoryItem.tsx +2 -1
- package/src/client/components/layout/session-sidebar/SessionList.tsx +2 -1
- package/src/client/components/layout/session-sidebar/about-modal/UpdateSection.tsx +3 -2
- package/src/client/components/layout/session-sidebar/about-modal/index.tsx +2 -1
- package/src/client/components/layout/session-sidebar/modern/RevealRow.tsx +56 -0
- package/src/client/components/layout/session-sidebar/modern/WorkspaceSection.tsx +10 -28
- package/src/client/components/layout/session-sidebar/modern/reveal-row.test.tsx +104 -0
- package/src/client/components/layout/session-sidebar/scheduler-modal/index.tsx +2 -1
- package/src/client/components/layout/session-sidebar/variant-props.ts +2 -1
- package/src/client/components/mobile/SessionSidebar.tsx +2 -1
- package/src/client/components/mobile/mobile-session-sidebar/ClassicDrawer.tsx +2 -1
- package/src/client/components/mobile/mobile-session-sidebar/Item.tsx +2 -1
- package/src/client/components/mobile/mobile-session-sidebar/List.tsx +2 -1
- package/src/client/components/settings/Modal.tsx +1 -1
- package/src/client/components/settings/categories/project-settings/WorktreeSettings.tsx +2 -1
- package/src/client/components/settings/categories/usage-settings/LimitsSection.tsx +39 -19
- package/src/client/components/settings/categories/usage-settings/ProviderDetail.tsx +1 -0
- package/src/client/components/settings/categories/usage-settings/limit-groups.test.ts +94 -0
- package/src/client/components/settings/categories/usage-settings/limit-groups.ts +118 -0
- package/src/client/components/settings/categories/usage-settings/limits-section.test.tsx +118 -0
- package/src/client/components/workspace/chat-timeline/EmptyWorkspacePrompt.tsx +58 -54
- package/src/client/components/workspace/chat-timeline/PendingChatView.tsx +11 -1
- package/src/client/components/workspace/chat-timeline/PendingTranscript.tsx +130 -0
- package/src/client/components/workspace/chat-timeline/fork-preview.test.tsx +141 -0
- package/src/client/components/workspace/chat-timeline/index.tsx +6 -1
- package/src/client/components/workspace/chat-timeline/target-picker/DraftTargetRow.tsx +2 -1
- package/src/client/components/workspace/chat-timeline/target-picker/WorktreePicker.tsx +5 -4
- package/src/client/components/workspace/git-panel/index.tsx +2 -2
- package/src/client/components/workspace/terminal-panel/RealtimeTerminalView.tsx +8 -5
- package/src/client/components/workspace/terminal-panel/index.tsx +3 -0
- package/src/client/hooks/chat/omp/session-list.tsx +5 -0
- package/src/client/hooks/chat/omp/sidebar-reload.test.ts +85 -0
- package/src/client/hooks/chat/omp/sidebar-reload.ts +30 -0
- package/src/client/hooks/chat/timeline/fork-preview.test.ts +148 -0
- package/src/client/hooks/chat/timeline/fork-preview.ts +104 -0
- package/src/client/hooks/chat/timeline/fork-send.test.ts +139 -0
- package/src/client/hooks/chat/timeline/pending-branch.ts +9 -0
- package/src/client/hooks/chat/timeline/pending-dispatch.ts +49 -0
- package/src/client/hooks/chat/timeline/stop-with-queue.ts +1 -1
- package/src/client/hooks/chat/waiting/cancel.ts +2 -1
- package/src/client/hooks/chat/waiting/dispatch.ts +5 -4
- package/src/client/hooks/chat/waiting/held.ts +2 -1
- package/src/client/hooks/settings/providers/actions.ts +3 -2
- package/src/client/hooks/settings/providers/messages.ts +9 -7
- package/src/client/hooks/settings/providers/model-actions.ts +2 -1
- package/src/client/hooks/ui/editor-error-toast.ts +2 -1
- package/src/client/hooks/workspace/batch-archive.test.ts +2 -2
- package/src/client/hooks/workspace/batch-archive.ts +4 -2
- package/src/client/hooks/workspace/git-action-outcome.ts +4 -3
- package/src/client/hooks/workspace/navbar-session-actions.ts +2 -1
- package/src/client/hooks/workspace/session-actions.test.ts +2 -1
- package/src/client/hooks/workspace/session-actions.ts +2 -1
- package/src/client/hooks/workspace/terminal/connection.test.ts +63 -0
- package/src/client/hooks/workspace/terminal/connection.ts +47 -0
- package/src/client/hooks/workspace/terminal/index.ts +35 -4
- package/src/client/hooks/workspace/workspace-folder-actions.ts +2 -1
- package/src/server/lib/usage/report.server.ts +57 -0
- package/src/shared/lib/chat/timeline/fork-preview.test.ts +62 -0
- package/src/shared/lib/chat/timeline/fork-preview.ts +36 -0
- package/src/shared/lib/ui/toast-duration.test.ts +25 -1
- package/src/shared/lib/ui/toast-duration.ts +22 -4
- package/src/shared/lib/workspace/session-state/store.ts +4 -0
- package/dist/client/static/js/index-p2yw9ywf.css +0 -1
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { UsageLimitWindow } from '@/shared/types';
|
|
2
2
|
import { formatDateTime, formatFractionPercent, formatUsageAmount } from '@/client/components/settings/categories/usage-settings/format';
|
|
3
|
+
import { groupProviderLimits } from '@/client/components/settings/categories/usage-settings/limit-groups';
|
|
3
4
|
|
|
4
5
|
interface LimitRowProps {
|
|
5
6
|
limit: UsageLimitWindow;
|
|
@@ -19,7 +20,14 @@ function LimitRow({ limit }: LimitRowProps) {
|
|
|
19
20
|
<div className="bg-paper border border-ink/15 rounded-lg p-3 shadow-xs space-y-2">
|
|
20
21
|
<div className="flex items-start justify-between gap-2">
|
|
21
22
|
<div className="min-w-0">
|
|
22
|
-
<div className="text-[11px] font-semibold text-ink truncate">
|
|
23
|
+
<div className="text-[11px] font-semibold text-ink truncate">
|
|
24
|
+
{limit.label}
|
|
25
|
+
{limit.windowLabel && (
|
|
26
|
+
<span className="ml-1.5 rounded border border-ink/15 px-1 py-px font-mono text-[9px] font-normal text-ink/50">
|
|
27
|
+
{limit.windowLabel}
|
|
28
|
+
</span>
|
|
29
|
+
)}
|
|
30
|
+
</div>
|
|
23
31
|
{scope && <div className="text-[10px] text-ink/50 truncate">{scope}</div>}
|
|
24
32
|
</div>
|
|
25
33
|
<span className="text-[10px] text-ink/50 flex-shrink-0 whitespace-nowrap">
|
|
@@ -70,6 +78,8 @@ function LimitRow({ limit }: LimitRowProps) {
|
|
|
70
78
|
}
|
|
71
79
|
|
|
72
80
|
interface LimitsSectionProps {
|
|
81
|
+
/** Provider slug, used to group Claude's balance and Antigravity's families. */
|
|
82
|
+
providerId: string;
|
|
73
83
|
limits: UsageLimitWindow[];
|
|
74
84
|
/** Whether omp ships a usage adapter for this provider. */
|
|
75
85
|
tracked: boolean;
|
|
@@ -80,13 +90,11 @@ interface LimitsSectionProps {
|
|
|
80
90
|
}
|
|
81
91
|
|
|
82
92
|
/** Generic quota windows for any provider omp reports usage for. */
|
|
83
|
-
export function LimitsSection({ limits, tracked, unavailable, notes }: LimitsSectionProps) {
|
|
93
|
+
export function LimitsSection({ providerId, limits, tracked, unavailable, notes }: LimitsSectionProps) {
|
|
94
|
+
const groups = groupProviderLimits(providerId, limits);
|
|
95
|
+
|
|
84
96
|
return (
|
|
85
97
|
<div className="space-y-2">
|
|
86
|
-
<h4 className="text-[10px] font-mono font-semibold uppercase tracking-wider text-ink/40">
|
|
87
|
-
Quota windows
|
|
88
|
-
</h4>
|
|
89
|
-
|
|
90
98
|
{notes && notes.length > 0 && (
|
|
91
99
|
<ul className="text-[10px] text-ink/50 leading-relaxed space-y-0.5">
|
|
92
100
|
{notes.map((note) => (
|
|
@@ -95,20 +103,32 @@ export function LimitsSection({ limits, tracked, unavailable, notes }: LimitsSec
|
|
|
95
103
|
</ul>
|
|
96
104
|
)}
|
|
97
105
|
|
|
98
|
-
{
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
+
{groups.length === 0 ? (
|
|
107
|
+
<>
|
|
108
|
+
<h4 className="text-[10px] font-mono font-semibold uppercase tracking-wider text-ink/40">
|
|
109
|
+
Quota windows
|
|
110
|
+
</h4>
|
|
111
|
+
<p className="text-[11px] text-ink/50">
|
|
112
|
+
{!tracked
|
|
113
|
+
? 'No quota source for this provider: omp ships no usage adapter for it and it exposes no balance endpoint Kabmo knows.'
|
|
114
|
+
: unavailable
|
|
115
|
+
? 'omp tracks this provider but its usage endpoint returned no data — an invalid or expired credential, an unreachable endpoint, or a plan without quota windows.'
|
|
116
|
+
: 'No quota windows were reported for this provider.'}
|
|
117
|
+
</p>
|
|
118
|
+
</>
|
|
106
119
|
) : (
|
|
107
|
-
|
|
108
|
-
{
|
|
109
|
-
<
|
|
110
|
-
|
|
111
|
-
|
|
120
|
+
groups.map((group) => (
|
|
121
|
+
<div key={group.id} className="@container space-y-2">
|
|
122
|
+
<h4 className="text-[10px] font-mono font-semibold uppercase tracking-wider text-ink/40">
|
|
123
|
+
{group.title}
|
|
124
|
+
</h4>
|
|
125
|
+
<div className="grid grid-cols-1 @[520px]:grid-cols-2 gap-2.5">
|
|
126
|
+
{group.limits.map((limit) => (
|
|
127
|
+
<LimitRow key={limit.id} limit={limit} />
|
|
128
|
+
))}
|
|
129
|
+
</div>
|
|
130
|
+
</div>
|
|
131
|
+
))
|
|
112
132
|
)}
|
|
113
133
|
</div>
|
|
114
134
|
);
|
|
@@ -37,6 +37,7 @@ export function ProviderDetail({ summary }: ProviderDetailProps) {
|
|
|
37
37
|
says so — a second "no quota source" note would contradict it. */}
|
|
38
38
|
{!hasRichReport && (summary.limits.length > 0 || !summary.error) && (
|
|
39
39
|
<LimitsSection
|
|
40
|
+
providerId={summary.id}
|
|
40
41
|
limits={summary.limits}
|
|
41
42
|
tracked={summary.tracked}
|
|
42
43
|
unavailable={summary.limitsUnavailable}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The grouping rule the quota section renders.
|
|
8
|
+
*
|
|
9
|
+
* Three shapes, three bugs prevented:
|
|
10
|
+
* - Claude's USD spend limit (`anthropic:extra`) must NOT sit in the same grid
|
|
11
|
+
* as its 5h/7d windows; it is a balance after the windows, not a window.
|
|
12
|
+
* - Antigravity's `anthropic:` and `openai:` rows are ONE upstream bucket
|
|
13
|
+
* ("Claude & GPT (shared)"), so they must land in one group rather than two
|
|
14
|
+
* headings repeating the same sentence.
|
|
15
|
+
* - Every other provider is a single group, and a row's order inside it is
|
|
16
|
+
* omp's own (sorted by remaining fraction) — regrouping must not reshuffle.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
import { describe, expect, test } from 'bun:test';
|
|
20
|
+
import { groupProviderLimits } from '@/client/components/settings/categories/usage-settings/limit-groups';
|
|
21
|
+
import type { UsageLimitWindow } from '@/shared/types';
|
|
22
|
+
|
|
23
|
+
const limit = (id: string, overrides: Partial<UsageLimitWindow> = {}): UsageLimitWindow => ({
|
|
24
|
+
id,
|
|
25
|
+
label: id,
|
|
26
|
+
unit: 'percent',
|
|
27
|
+
status: 'ok',
|
|
28
|
+
...overrides,
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
describe('groupProviderLimits', () => {
|
|
32
|
+
test('an ordinary provider is one group, in source order', () => {
|
|
33
|
+
const limits = [limit('openrouter:credits'), limit('openrouter:daily')];
|
|
34
|
+
const groups = groupProviderLimits('openrouter', limits);
|
|
35
|
+
expect(groups).toHaveLength(1);
|
|
36
|
+
expect(groups[0]?.title).toBe('Quota windows');
|
|
37
|
+
expect(groups[0]?.limits.map((row) => row.id)).toEqual(['openrouter:credits', 'openrouter:daily']);
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
test('Claude keeps its plan windows together and puts the spend limit under Balance', () => {
|
|
41
|
+
const limits = [
|
|
42
|
+
limit('anthropic:5h'),
|
|
43
|
+
limit('anthropic:7d'),
|
|
44
|
+
limit('anthropic:7d:opus'),
|
|
45
|
+
limit('anthropic:extra', { unit: 'usd', label: 'Claude Extra Usage' }),
|
|
46
|
+
];
|
|
47
|
+
const groups = groupProviderLimits('anthropic', limits);
|
|
48
|
+
expect(groups.map((group) => group.title)).toEqual(['Quota windows', 'Balance']);
|
|
49
|
+
expect(groups[0]?.limits.map((row) => row.id)).toEqual(['anthropic:5h', 'anthropic:7d', 'anthropic:7d:opus']);
|
|
50
|
+
expect(groups[1]?.limits.map((row) => row.id)).toEqual(['anthropic:extra']);
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
test('Claude without a spend limit renders one section, not an empty Balance', () => {
|
|
54
|
+
const groups = groupProviderLimits('anthropic', [limit('anthropic:5h')]);
|
|
55
|
+
expect(groups).toHaveLength(1);
|
|
56
|
+
expect(groups[0]?.title).toBe('Quota windows');
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
test('Antigravity merges the shared Anthropic/OpenAI bucket and keeps Google apart', () => {
|
|
60
|
+
const limits = [
|
|
61
|
+
limit('google-antigravity:google:default:weekly'),
|
|
62
|
+
limit('google-antigravity:anthropic:default:5h'),
|
|
63
|
+
limit('google-antigravity:openai:default:5h'),
|
|
64
|
+
limit('google-antigravity:default:default:daily'),
|
|
65
|
+
];
|
|
66
|
+
const groups = groupProviderLimits('google-antigravity', limits);
|
|
67
|
+
expect(groups.map((group) => group.title)).toEqual(['Google', 'Claude & GPT (shared)', 'Usage']);
|
|
68
|
+
expect(groups[1]?.limits.map((row) => row.id)).toEqual([
|
|
69
|
+
'google-antigravity:anthropic:default:5h',
|
|
70
|
+
'google-antigravity:openai:default:5h',
|
|
71
|
+
]);
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
test('Antigravity emits one row for the shared bucket even though omp names two families', () => {
|
|
75
|
+
const shared = { label: 'Claude & GPT (shared)', usedFraction: 0.71, remaining: 29, resetsAt: 1_800 };
|
|
76
|
+
const groups = groupProviderLimits('google-antigravity', [
|
|
77
|
+
limit('google-antigravity:anthropic:default:5h', shared),
|
|
78
|
+
limit('google-antigravity:openai:default:5h', shared),
|
|
79
|
+
]);
|
|
80
|
+
expect(groups).toHaveLength(1);
|
|
81
|
+
expect(groups[0]?.limits).toHaveLength(1);
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
test('an unknown Antigravity counter is shown under its own name, never dropped', () => {
|
|
85
|
+
const groups = groupProviderLimits('google-antigravity', [limit('google-antigravity:mistral:default:weekly')]);
|
|
86
|
+
expect(groups).toHaveLength(1);
|
|
87
|
+
expect(groups[0]?.title).toBe('mistral');
|
|
88
|
+
expect(groups[0]?.limits).toHaveLength(1);
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
test('no limits means no groups, so the caller draws its empty state', () => {
|
|
92
|
+
expect(groupProviderLimits('anthropic', [])).toEqual([]);
|
|
93
|
+
});
|
|
94
|
+
});
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Provider-aware grouping for the generic quota section.
|
|
8
|
+
*
|
|
9
|
+
* omp reports every provider's windows as one flat list, but three of them are
|
|
10
|
+
* not one list:
|
|
11
|
+
*
|
|
12
|
+
* - Anthropic mixes plan windows (5h, 7d, per-tier 7d) with a USD spend limit
|
|
13
|
+
* (`anthropic:extra`). Drawing the spend limit as a fourth quota window made
|
|
14
|
+
* it look like another reset window instead of "what happens after the
|
|
15
|
+
* windows run out".
|
|
16
|
+
* - Antigravity emits one entry per model family AND per window, so a Google
|
|
17
|
+
* bucket and the shared Claude/GPT bucket sat in one grid with no boundary;
|
|
18
|
+
* the rows even repeat the family in their label because there was nowhere
|
|
19
|
+
* else to put it.
|
|
20
|
+
* - Every other provider is one list, and stays one list.
|
|
21
|
+
*
|
|
22
|
+
* The grouping is a pure function of (provider slug, limit id) so it can be
|
|
23
|
+
* unit-tested without mounting the panel. Group order is first-seen order and
|
|
24
|
+
* rows keep omp's own order inside a group (omp sorts by remaining fraction).
|
|
25
|
+
*/
|
|
26
|
+
|
|
27
|
+
import type { UsageLimitWindow } from '@/shared/types';
|
|
28
|
+
|
|
29
|
+
export interface LimitGroup {
|
|
30
|
+
/** Stable key inside one provider's section: `windows`, `balance`, `google`, … */
|
|
31
|
+
id: string;
|
|
32
|
+
/** The group's own heading; the panel draws one heading per group. */
|
|
33
|
+
title: string;
|
|
34
|
+
limits: UsageLimitWindow[];
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const CLAUDE_EXTRA_ID = 'anthropic:extra';
|
|
38
|
+
const QUOTA_TITLE = 'Quota windows';
|
|
39
|
+
|
|
40
|
+
/** Push a row into the group named `id`, creating it on first use. */
|
|
41
|
+
function push(
|
|
42
|
+
groups: LimitGroup[],
|
|
43
|
+
id: string,
|
|
44
|
+
title: string,
|
|
45
|
+
limit: UsageLimitWindow,
|
|
46
|
+
): void {
|
|
47
|
+
const existing = groups.find((group) => group.id === id);
|
|
48
|
+
if (existing) {
|
|
49
|
+
existing.limits.push(limit);
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
groups.push({ id, title, limits: [limit] });
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* The model family Antigravity put in the second segment of the limit id:
|
|
57
|
+
* `${provider}:${counterKey}:${tier}:${windowId}`. `anthropic` and `openai`
|
|
58
|
+
* share one upstream bucket, which omp labels "Claude & GPT (shared)".
|
|
59
|
+
*/
|
|
60
|
+
function antigravityBucket(id: string): { id: string; title: string } {
|
|
61
|
+
const counter = (id.split(':')[1] ?? '').toLowerCase();
|
|
62
|
+
if (counter === 'google') return { id: 'google', title: 'Google' };
|
|
63
|
+
if (counter === 'anthropic' || counter === 'openai') {
|
|
64
|
+
return { id: 'third-party', title: 'Claude & GPT (shared)' };
|
|
65
|
+
}
|
|
66
|
+
if (counter === 'default' || counter === '') return { id: 'default', title: 'Usage' };
|
|
67
|
+
// An unknown counter still has to be visible; naming it beats dropping it.
|
|
68
|
+
return { id: counter, title: counter };
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/** Split Claude's plan windows from its USD spend limit. */
|
|
72
|
+
function groupClaude(limits: UsageLimitWindow[]): LimitGroup[] {
|
|
73
|
+
const groups: LimitGroup[] = [];
|
|
74
|
+
for (const limit of limits) {
|
|
75
|
+
if (limit.id === CLAUDE_EXTRA_ID) push(groups, 'balance', 'Balance', limit);
|
|
76
|
+
else push(groups, 'windows', QUOTA_TITLE, limit);
|
|
77
|
+
}
|
|
78
|
+
return groups;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/** Group Antigravity's rows by model family, merging the shared third-party bucket. */
|
|
82
|
+
function groupAntigravity(limits: UsageLimitWindow[]): LimitGroup[] {
|
|
83
|
+
const groups: LimitGroup[] = [];
|
|
84
|
+
for (const limit of limits) {
|
|
85
|
+
const bucket = antigravityBucket(limit.id);
|
|
86
|
+
// The quota-summary response emits the SAME shared bucket once for
|
|
87
|
+
// `anthropic:` and once for `openai:` — identical label, amount and reset,
|
|
88
|
+
// only the id differs. Rendering both would show the same number twice under
|
|
89
|
+
// one heading; the first row is the whole fact.
|
|
90
|
+
if (bucket.id === 'third-party') {
|
|
91
|
+
const shared = groups.find((group) => group.id === 'third-party');
|
|
92
|
+
if (shared?.limits.some((row) => isSameReading(row, limit))) continue;
|
|
93
|
+
}
|
|
94
|
+
push(groups, bucket.id, bucket.title, limit);
|
|
95
|
+
}
|
|
96
|
+
return groups;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/** Whether two rows describe the same reading of the same bucket. */
|
|
100
|
+
function isSameReading(a: UsageLimitWindow, b: UsageLimitWindow): boolean {
|
|
101
|
+
return a.unit === b.unit
|
|
102
|
+
&& a.label === b.label
|
|
103
|
+
&& a.usedFraction === b.usedFraction
|
|
104
|
+
&& a.remaining === b.remaining
|
|
105
|
+
&& a.resetsAt === b.resetsAt;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* The panel's sections for one provider: one group for an ordinary provider,
|
|
110
|
+
* two for Claude (windows + balance), and one per model family for Antigravity.
|
|
111
|
+
*/
|
|
112
|
+
export function groupProviderLimits(providerId: string, limits: UsageLimitWindow[]): LimitGroup[] {
|
|
113
|
+
if (limits.length === 0) return [];
|
|
114
|
+
const slug = providerId.trim().toLowerCase();
|
|
115
|
+
if (slug === 'anthropic') return groupClaude(limits);
|
|
116
|
+
if (slug === 'google-antigravity') return groupAntigravity(limits);
|
|
117
|
+
return [{ id: 'all', title: QUOTA_TITLE, limits: [...limits] }];
|
|
118
|
+
}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The quota section's two new shapes are asserted on the DOM, not on the
|
|
8
|
+
* grouping helper alone: a correct group list wired to the wrong prop renders
|
|
9
|
+
* one flat "Quota windows" grid, which is exactly the regression this covers.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import { afterEach, beforeEach, describe, expect, test } from 'bun:test';
|
|
13
|
+
import { Window } from 'happy-dom';
|
|
14
|
+
import { render } from 'preact';
|
|
15
|
+
import { act } from 'preact/test-utils';
|
|
16
|
+
import { LimitsSection } from '@/client/components/settings/categories/usage-settings/LimitsSection';
|
|
17
|
+
import { installDomGlobals, restoreDomGlobals } from '@/test-support/pristine-globals';
|
|
18
|
+
import type { UsageLimitWindow } from '@/shared/types';
|
|
19
|
+
|
|
20
|
+
let container: HTMLElement;
|
|
21
|
+
|
|
22
|
+
const limit = (id: string, overrides: Partial<UsageLimitWindow> = {}): UsageLimitWindow => ({
|
|
23
|
+
id,
|
|
24
|
+
label: id,
|
|
25
|
+
unit: 'percent',
|
|
26
|
+
status: 'ok',
|
|
27
|
+
...overrides,
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
function mount(node: preact.ComponentChild): HTMLElement {
|
|
31
|
+
act(() => render(node, container));
|
|
32
|
+
return container;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function headings(dom: HTMLElement): string[] {
|
|
36
|
+
return [...dom.querySelectorAll('h4')].map((heading) => heading.textContent ?? '');
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
beforeEach(() => {
|
|
40
|
+
installDomGlobals(new Window());
|
|
41
|
+
container = document.createElement('div');
|
|
42
|
+
document.body.appendChild(container);
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
afterEach(() => {
|
|
46
|
+
act(() => render(null, container));
|
|
47
|
+
container.remove();
|
|
48
|
+
restoreDomGlobals();
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
describe('LimitsSection sections', () => {
|
|
52
|
+
test('Claude draws plan windows and its spend balance as separate sections', () => {
|
|
53
|
+
const dom = mount(
|
|
54
|
+
<LimitsSection
|
|
55
|
+
providerId="anthropic"
|
|
56
|
+
tracked
|
|
57
|
+
limits={[
|
|
58
|
+
limit('anthropic:5h', { label: 'Claude 5 Hour', usedFraction: 0.42 }),
|
|
59
|
+
limit('anthropic:extra', {
|
|
60
|
+
label: 'Claude Extra Usage',
|
|
61
|
+
unit: 'usd',
|
|
62
|
+
used: 4.2,
|
|
63
|
+
limit: 25,
|
|
64
|
+
remaining: 20.8,
|
|
65
|
+
usedFraction: 0.168,
|
|
66
|
+
}),
|
|
67
|
+
]}
|
|
68
|
+
/>,
|
|
69
|
+
);
|
|
70
|
+
expect(headings(dom)).toEqual(['Quota windows', 'Balance']);
|
|
71
|
+
expect(dom.textContent).toContain('Claude Extra Usage');
|
|
72
|
+
expect(dom.textContent).toContain('$4,20');
|
|
73
|
+
expect(dom.textContent).toContain('$20,80');
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
test('Antigravity draws one heading per model family and merges the shared bucket', () => {
|
|
77
|
+
const dom = mount(
|
|
78
|
+
<LimitsSection
|
|
79
|
+
providerId="google-antigravity"
|
|
80
|
+
tracked
|
|
81
|
+
limits={[
|
|
82
|
+
limit('google-antigravity:google:default:weekly', {
|
|
83
|
+
label: 'Gemini',
|
|
84
|
+
windowLabel: 'weekly',
|
|
85
|
+
usedFraction: 0.42,
|
|
86
|
+
}),
|
|
87
|
+
limit('google-antigravity:anthropic:default:5h', {
|
|
88
|
+
label: 'Claude & GPT (shared)',
|
|
89
|
+
usedFraction: 0.71,
|
|
90
|
+
}),
|
|
91
|
+
limit('google-antigravity:openai:default:5h', {
|
|
92
|
+
label: 'Claude & GPT (shared)',
|
|
93
|
+
usedFraction: 0.13,
|
|
94
|
+
}),
|
|
95
|
+
]}
|
|
96
|
+
/>,
|
|
97
|
+
);
|
|
98
|
+
expect(headings(dom)).toEqual(['Google', 'Claude & GPT (shared)']);
|
|
99
|
+
expect(dom.textContent).toContain('Gemini');
|
|
100
|
+
expect(dom.textContent).toContain('weekly');
|
|
101
|
+
// Two rows, one 5h row per third-party family, under ONE heading.
|
|
102
|
+
expect(dom.querySelectorAll('h4')).toHaveLength(2);
|
|
103
|
+
expect(dom.textContent?.match(/Claude & GPT \(shared\)/g)).toHaveLength(3);
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
test('an ordinary provider keeps the single Quota windows section', () => {
|
|
107
|
+
const dom = mount(
|
|
108
|
+
<LimitsSection providerId="openrouter" tracked limits={[limit('openrouter:credits', { unit: 'usd' })]} />,
|
|
109
|
+
);
|
|
110
|
+
expect(headings(dom)).toEqual(['Quota windows']);
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
test('an untracked provider with no rows keeps its explanation', () => {
|
|
114
|
+
const dom = mount(<LimitsSection providerId="kenari" tracked={false} limits={[]} />);
|
|
115
|
+
expect(headings(dom)).toEqual(['Quota windows']);
|
|
116
|
+
expect(dom.textContent).toContain('No quota source for this provider');
|
|
117
|
+
});
|
|
118
|
+
});
|
|
@@ -1,13 +1,10 @@
|
|
|
1
1
|
import type { SetStateAction } from 'preact/compat';
|
|
2
|
-
import { Fragment } from 'preact';
|
|
3
2
|
import { useEffect, useMemo, useRef } from 'preact/hooks';
|
|
4
3
|
import type { Attachment, ChatMessageData, WorkspaceFolderData } from '@/shared/types';
|
|
5
4
|
import { ChatInput } from '@/client/components/workspace/chat-timeline/chat-input/index';
|
|
6
|
-
import {
|
|
7
|
-
import { RunFooter } from '@/client/components/workspace/chat-timeline/RunFooter';
|
|
5
|
+
import { PendingTranscript } from '@/client/components/workspace/chat-timeline/PendingTranscript';
|
|
8
6
|
import { ComposerDockFrame } from '@/client/components/workspace/chat-timeline/ComposerDockFrame';
|
|
9
7
|
import { GeneratingIndicator } from '@/client/components/workspace/chat-timeline/GeneratingIndicator';
|
|
10
|
-
import { resolveRunFooters, streamingRowIndex } from '@/shared/lib/chat/timeline/run-footer';
|
|
11
8
|
import type { ApprovalMode } from '@/shared/lib/omp/config/access-mode';
|
|
12
9
|
import {
|
|
13
10
|
waitingCandidates,
|
|
@@ -15,7 +12,10 @@ import {
|
|
|
15
12
|
} from '@/client/components/workspace/chat-timeline/chat-input/WaitingDependencyPicker';
|
|
16
13
|
import { Hourglass } from 'lucide-preact';
|
|
17
14
|
import { DraftTargetRow } from '@/client/components/workspace/chat-timeline/target-picker/DraftTargetRow';
|
|
15
|
+
import { ParentSessionPicker } from '@/client/components/workspace/chat-timeline/target-picker/ParentSessionPicker';
|
|
18
16
|
import type { SpawnTarget } from '@/client/hooks/chat/timeline/spawn-target';
|
|
17
|
+
import type { ForkPreview } from '@/client/hooks/chat/timeline/fork-preview';
|
|
18
|
+
import type { ToastTone } from '@/shared/lib/ui/toast-duration';
|
|
19
19
|
|
|
20
20
|
interface EmptyWorkspacePromptProps {
|
|
21
21
|
className?: string;
|
|
@@ -78,8 +78,17 @@ interface EmptyWorkspacePromptProps {
|
|
|
78
78
|
/** "Parent session" for a child, "Fork from" for a fork. */
|
|
79
79
|
branchLabel?: string;
|
|
80
80
|
branchAllowNone?: boolean;
|
|
81
|
+
/**
|
|
82
|
+
* The source transcript this FORK will carry.
|
|
83
|
+
*
|
|
84
|
+
* Present only for a fork that has not been created yet (the branch is built
|
|
85
|
+
* on the first send), so it both draws the history above the composer and
|
|
86
|
+
* marks the view as docked — which is what keeps the branch picker reachable
|
|
87
|
+
* while switching "Fork from".
|
|
88
|
+
*/
|
|
89
|
+
branchPreview?: ForkPreview | null;
|
|
81
90
|
/** Reports a worktree the composer created or failed to create. */
|
|
82
|
-
onWorktreeReport?: (message: string) => void;
|
|
91
|
+
onWorktreeReport?: (message: string, tone?: ToastTone) => void;
|
|
83
92
|
/** The "wait for session" pick, persisted per chat. */
|
|
84
93
|
waitingFor?: WaitingCandidate | null;
|
|
85
94
|
onWaitingForChange?: (candidate: WaitingCandidate | null) => void;
|
|
@@ -134,6 +143,7 @@ export function EmptyWorkspacePrompt({
|
|
|
134
143
|
onParentSessionChange,
|
|
135
144
|
branchLabel,
|
|
136
145
|
branchAllowNone,
|
|
146
|
+
branchPreview = null,
|
|
137
147
|
onWorktreeReport,
|
|
138
148
|
waitingFor = null,
|
|
139
149
|
onWaitingForChange,
|
|
@@ -152,21 +162,16 @@ export function EmptyWorkspacePrompt({
|
|
|
152
162
|
[folders, streamStatusMap, titleForSession],
|
|
153
163
|
);
|
|
154
164
|
|
|
155
|
-
//
|
|
156
|
-
//
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
streamingIdx: streamingRowIndex(messages),
|
|
160
|
-
footers: resolveRunFooters(messages, isGenerating),
|
|
161
|
-
}),
|
|
162
|
-
[messages, isGenerating],
|
|
163
|
-
);
|
|
165
|
+
// The rows the fork will carry, above the composer. A fork is composed on an
|
|
166
|
+
// empty `new-…` chat, so without this the operator chose the branch's first
|
|
167
|
+
// turn with none of the history it continues in sight.
|
|
168
|
+
const previewLength = branchPreview?.messages.length ?? 0;
|
|
164
169
|
|
|
165
170
|
useEffect(() => {
|
|
166
171
|
if (timelineRef.current) {
|
|
167
172
|
timelineRef.current.scrollTop = timelineRef.current.scrollHeight;
|
|
168
173
|
}
|
|
169
|
-
}, [messages.length]);
|
|
174
|
+
}, [messages.length, previewLength]);
|
|
170
175
|
|
|
171
176
|
const isMobile = variant === 'mobile';
|
|
172
177
|
// A chat with rows to show (or a prompt in flight) draws the SAME dock the
|
|
@@ -176,7 +181,11 @@ export function EmptyWorkspacePrompt({
|
|
|
176
181
|
// pane's bottom) than once the run streamed in the real timeline
|
|
177
182
|
// (`Thinking…`, 113px). The row jumped at the moment the chat was adopted,
|
|
178
183
|
// which read as two different indicators.
|
|
179
|
-
|
|
184
|
+
//
|
|
185
|
+
// A fork's preview docks from the FIRST frame, with or without rows: the
|
|
186
|
+
// "Fork from" picker must stay reachable while the source is being changed,
|
|
187
|
+
// and it lives in the docked branch.
|
|
188
|
+
const docked = messages.length > 0 || isGenerating || Boolean(branchPreview);
|
|
180
189
|
|
|
181
190
|
const heldPrompt = heldWait ? (
|
|
182
191
|
<div className="flex items-center gap-2 rounded-lg border border-ink/15 bg-ink/[0.03] px-3 py-2 text-xs text-ink/70">
|
|
@@ -224,8 +233,9 @@ export function EmptyWorkspacePrompt({
|
|
|
224
233
|
variant={variant}
|
|
225
234
|
expandable
|
|
226
235
|
// A brand-new chat has no turns: the `stage` composer style draws its
|
|
227
|
-
// wider, taller card here and nowhere else.
|
|
228
|
-
|
|
236
|
+
// wider, taller card here and nowhere else. A fork's preview is history,
|
|
237
|
+
// so its composer docks like any chat that already has rows.
|
|
238
|
+
hero={messages.length === 0 && previewLength === 0}
|
|
229
239
|
/>
|
|
230
240
|
);
|
|
231
241
|
|
|
@@ -236,6 +246,21 @@ export function EmptyWorkspacePrompt({
|
|
|
236
246
|
>
|
|
237
247
|
{docked ? (
|
|
238
248
|
<>
|
|
249
|
+
{/* A fork is composed, not created: the source it branches from is
|
|
250
|
+
still switchable, so its picker stays above the transcript the
|
|
251
|
+
preview draws. Every other pending chat loses the row once docked
|
|
252
|
+
because its first send already dispatched the spawn. */}
|
|
253
|
+
{branchPreview && onParentSessionChange && (
|
|
254
|
+
<div className={`shrink-0 flex items-center gap-1 flex-wrap ${isMobile ? 'pl-4 pr-3 pt-3' : 'px-4 pt-3'}`}>
|
|
255
|
+
<ParentSessionPicker
|
|
256
|
+
folders={folders as WorkspaceFolderData[]}
|
|
257
|
+
value={parentSessionId}
|
|
258
|
+
onChange={onParentSessionChange}
|
|
259
|
+
label={branchLabel ?? 'Fork from'}
|
|
260
|
+
allowNone={branchAllowNone ?? false}
|
|
261
|
+
/>
|
|
262
|
+
</div>
|
|
263
|
+
)}
|
|
239
264
|
{/* The pending transcript reserves the box the real timeline's own
|
|
240
265
|
scroller does (`TimelineBody`), so adoption moves no text either. */}
|
|
241
266
|
<div
|
|
@@ -244,42 +269,21 @@ export function EmptyWorkspacePrompt({
|
|
|
244
269
|
isMobile ? 'pl-4 pr-3 py-3 pb-8' : 'p-4 pb-10'
|
|
245
270
|
}`}
|
|
246
271
|
>
|
|
247
|
-
<
|
|
248
|
-
{messages
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
/>
|
|
263
|
-
{footer && (
|
|
264
|
-
<RunFooter
|
|
265
|
-
msg={footer.msg}
|
|
266
|
-
provider={provider}
|
|
267
|
-
providerNames={providerNames}
|
|
268
|
-
modelName={modelName}
|
|
269
|
-
modelNames={modelNames}
|
|
270
|
-
thinkingLevel={sessionThinkingLevel ?? undefined}
|
|
271
|
-
{...(harness ? { harness } : {})}
|
|
272
|
-
durationMs={footer.durationMs}
|
|
273
|
-
answerText={footer.answerText}
|
|
274
|
-
retryTargetId={footer.runUserId}
|
|
275
|
-
onRetry={onRetry}
|
|
276
|
-
onNewChat={onNewChat}
|
|
277
|
-
/>
|
|
278
|
-
)}
|
|
279
|
-
</Fragment>
|
|
280
|
-
);
|
|
281
|
-
})}
|
|
282
|
-
</div>
|
|
272
|
+
<PendingTranscript
|
|
273
|
+
messages={messages}
|
|
274
|
+
preview={branchPreview}
|
|
275
|
+
isGenerating={isGenerating}
|
|
276
|
+
isMobile={isMobile}
|
|
277
|
+
{...(provider ? { provider } : {})}
|
|
278
|
+
{...(providerNames ? { providerNames } : {})}
|
|
279
|
+
{...(modelName ? { modelName } : {})}
|
|
280
|
+
{...(modelNames ? { modelNames } : {})}
|
|
281
|
+
sessionThinkingLevel={sessionThinkingLevel}
|
|
282
|
+
{...(harness ? { harness } : {})}
|
|
283
|
+
{...(onUndo ? { onUndo } : {})}
|
|
284
|
+
{...(onRetry ? { onRetry } : {})}
|
|
285
|
+
{...(onNewChat ? { onNewChat } : {})}
|
|
286
|
+
/>
|
|
283
287
|
</div>
|
|
284
288
|
|
|
285
289
|
{/* One frame with the real dock (`ComposerDock`), so the indicator and
|
|
@@ -16,11 +16,13 @@
|
|
|
16
16
|
|
|
17
17
|
import type { Attachment, ChatMessageData, WorkspaceFolderData } from '@/shared/types';
|
|
18
18
|
import type { ApprovalMode } from '@/shared/lib/omp/config/access-mode';
|
|
19
|
+
import type { ForkPreview } from '@/client/hooks/chat/timeline/fork-preview';
|
|
19
20
|
import type { ComposerModes } from '@/client/components/workspace/chat-timeline/chat-input/modes-props';
|
|
20
21
|
import type { WaitingCandidate } from '@/client/components/workspace/chat-timeline/chat-input/WaitingDependencyPicker';
|
|
21
22
|
import type { DeferredModelStore } from '@/client/hooks/chat/timeline/deferred-model';
|
|
22
23
|
import { EmptyWorkspacePrompt } from '@/client/components/workspace/chat-timeline/EmptyWorkspacePrompt';
|
|
23
24
|
import type { SpawnTarget } from '@/client/hooks/chat/timeline/spawn-target';
|
|
25
|
+
import type { ToastTone } from '@/shared/lib/ui/toast-duration';
|
|
24
26
|
|
|
25
27
|
export interface PendingChatViewProps {
|
|
26
28
|
className: string;
|
|
@@ -69,7 +71,14 @@ export interface PendingChatViewProps {
|
|
|
69
71
|
/** "Parent session" for a child, "Fork from" for a fork. */
|
|
70
72
|
branchLabel?: string;
|
|
71
73
|
branchAllowNone?: boolean;
|
|
72
|
-
|
|
74
|
+
/**
|
|
75
|
+
* The source transcript a FORK will carry, rendered above the composer so the
|
|
76
|
+
* operator composes the first turn with the history it continues in sight. The
|
|
77
|
+
* same prop keeps the branch picker reachable while the transcript is docked:
|
|
78
|
+
* switching "Fork from" swaps the rows, because the composer has not sent yet.
|
|
79
|
+
*/
|
|
80
|
+
branchPreview?: ForkPreview | null;
|
|
81
|
+
onWorktreeReport?: (message: string, tone?: ToastTone) => void;
|
|
73
82
|
/**
|
|
74
83
|
* The harness this chat will spawn on, and the pick that writes it.
|
|
75
84
|
*
|
|
@@ -129,6 +138,7 @@ export function PendingChatView(props: PendingChatViewProps) {
|
|
|
129
138
|
onParentSessionChange={props.onParentSessionChange}
|
|
130
139
|
branchLabel={props.branchLabel}
|
|
131
140
|
branchAllowNone={props.branchAllowNone}
|
|
141
|
+
{...(props.branchPreview ? { branchPreview: props.branchPreview } : {})}
|
|
132
142
|
onWorktreeReport={props.onWorktreeReport}
|
|
133
143
|
{...(props.harness ? { harness: props.harness } : {})}
|
|
134
144
|
harnessEditable={props.harnessEditable}
|