cc-pets 2.4.0 → 2.6.0-beta.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/CC_BRIDGE.md +93 -14
- package/CC_BRIDGE.zh-CN.md +71 -11
- package/CHANGELOG.md +55 -0
- package/CHANGELOG.zh-CN.md +56 -1
- package/CONTRIBUTING.md +1 -1
- package/CONTRIBUTING.zh-CN.md +1 -1
- package/PROVIDER_PROTOCOL.md +5 -1
- package/PROVIDER_PROTOCOL.zh-CN.md +4 -1
- package/README.md +116 -34
- package/README.zh-CN.md +99 -35
- package/Resources/AgentIcons/antigravity.icns +0 -0
- package/Resources/zh-Hans.lproj/Localizable.strings +99 -26
- package/Sources/CCPets/App/CCPetsAppDelegate+AgentEvents.m +51 -4
- package/Sources/CCPets/App/CCPetsAppDelegate+AgentStatus.m +120 -17
- package/Sources/CCPets/App/CCPetsAppDelegate+Bridge.m +24 -11
- package/Sources/CCPets/App/CCPetsAppDelegate+MenuBar.m +86 -0
- package/Sources/CCPets/App/CCPetsAppDelegate+Private.h +24 -1
- package/Sources/CCPets/App/CCPetsAppDelegate+Profiles.m +21 -11
- package/Sources/CCPets/App/CCPetsAppDelegate+Quota.m +33 -17
- package/Sources/CCPets/App/CCPetsAppDelegate+Settings.m +43 -7
- package/Sources/CCPets/App/CCPetsAppDelegate+Speech.m +7 -4
- package/Sources/CCPets/App/CCPetsAppDelegate+Update.m +7 -4
- package/Sources/CCPets/App/CCPetsAppDelegate+Workbench.m +24 -22
- package/Sources/CCPets/App/CCPetsAppDelegate.h +10 -0
- package/Sources/CCPets/App/CCPetsAppDelegate.m +18 -8
- package/Sources/CCPets/App/CCPetsVersion.h +4 -0
- package/Sources/CCPets/App/CCPetsVersion.m +34 -0
- package/Sources/CCPets/App/main.m +11 -0
- package/Sources/CCPets/Bridge/CCPetsBridge.m +41 -17
- package/Sources/CCPets/Bridge/CCPetsBridgeAntigravityApp.h +4 -0
- package/Sources/CCPets/Bridge/CCPetsBridgeAntigravityApp.m +119 -0
- package/Sources/CCPets/Bridge/CCPetsBridgeCLI.h +3 -1
- package/Sources/CCPets/Bridge/CCPetsBridgeCLI.m +272 -50
- package/Sources/CCPets/Bridge/CCPetsBridgeCore.h +12 -3
- package/Sources/CCPets/Bridge/CCPetsBridgeCore.m +341 -95
- package/Sources/CCPets/Bridge/CCPetsBridgeSetup.h +0 -2
- package/Sources/CCPets/Bridge/CCPetsBridgeSetup.m +227 -95
- package/Sources/CCPets/Bridge/CCPetsBridgeStore.h +35 -5
- package/Sources/CCPets/Bridge/CCPetsBridgeStore.m +310 -42
- package/Sources/CCPets/Bridge/CCPetsBridgeTerminalTitle.h +12 -0
- package/Sources/CCPets/Bridge/CCPetsBridgeTerminalTitle.m +105 -0
- package/Sources/CCPets/Integrations/CCPetsAntigravityConfig.h +17 -0
- package/Sources/CCPets/Integrations/CCPetsAntigravityConfig.m +462 -0
- package/Sources/CCPets/Integrations/CCPetsAntigravityEvents.h +5 -0
- package/Sources/CCPets/Integrations/CCPetsAntigravityEvents.m +180 -0
- package/Sources/CCPets/Integrations/CCPetsBridgeTitleRelay.h +3 -0
- package/Sources/CCPets/Integrations/CCPetsBridgeTitleRelay.m +463 -0
- package/Sources/CCPets/Integrations/CCPetsEvents.h +5 -0
- package/Sources/CCPets/Integrations/CCPetsEvents.m +68 -12
- package/Sources/CCPets/Integrations/CCPetsIntegrations.h +1 -1
- package/Sources/CCPets/Integrations/CCPetsIntegrations.m +38 -8
- package/Sources/CCPets/Integrations/CCPetsLaunchPreflight.m +15 -5
- package/Sources/CCPets/Integrations/CCPetsProfiles.h +2 -1
- package/Sources/CCPets/Integrations/CCPetsProfiles.m +112 -81
- package/Sources/CCPets/Integrations/CCPetsTerminalFocus.h +11 -1
- package/Sources/CCPets/Integrations/CCPetsTerminalFocus.m +217 -45
- package/Sources/CCPets/Pet/CCPetsPhrasesEditor.m +7 -0
- package/Sources/CCPets/Pet/CCPetsPreviews.m +16 -8
- package/Sources/CCPets/Pet/PetView+Menu.m +64 -5
- package/Sources/CCPets/Pet/PetView.h +7 -0
- package/Sources/CCPets/Pet/PetView.m +12 -1
- package/Sources/CCPets/Support/CCPetsDoctor.m +126 -37
- package/Sources/CCPets/Support/CCPetsPaths.h +5 -0
- package/Sources/CCPets/Support/CCPetsPaths.m +15 -0
- package/Sources/CCPets/Support/CCPetsPreferences.h +14 -1
- package/Sources/CCPets/Support/CCPetsPreferences.m +36 -0
- package/Sources/CCPets/UI/CCPetsMenuBarIcon.h +16 -0
- package/Sources/CCPets/UI/CCPetsMenuBarIcon.m +70 -0
- package/Sources/CCPets/UI/CCPetsMenuBarPanel.h +18 -0
- package/Sources/CCPets/UI/CCPetsMenuBarPanel.m +533 -0
- package/Sources/CCPets/UI/CCPetsMenuBarSummary.h +51 -0
- package/Sources/CCPets/UI/CCPetsMenuBarSummary.m +98 -0
- package/Sources/CCPets/UI/CCPetsSettingsPage.h +7 -1
- package/Sources/CCPets/UI/CCPetsSettingsPage.m +205 -8
- package/Sources/CCPets/UI/CCPetsStatusItem.h +28 -0
- package/Sources/CCPets/UI/CCPetsStatusItem.m +147 -0
- package/Sources/CCPets/UI/CCPetsUIStyle.m +3 -1
- package/Sources/CCPets/UI/CCPetsUsagePage.h +4 -3
- package/Sources/CCPets/UI/CCPetsUsagePage.m +69 -43
- package/Sources/CCPets/UI/CCPetsUsageStore.m +11 -1
- package/Sources/CCPets/UI/CCPetsWorkbenchPages.m +6 -4
- package/Sources/CCPets/Usage/CCPetsAntigravityQuota.m +115 -0
- package/Sources/CCPets/Usage/CCPetsNormalizedUsage.h +5 -0
- package/Sources/CCPets/Usage/CCPetsNormalizedUsage.m +43 -0
- package/Sources/CCPets/Usage/CCPetsProviderRegistry+Testing.h +13 -0
- package/Sources/CCPets/Usage/CCPetsProviderRegistry.h +25 -0
- package/Sources/CCPets/Usage/CCPetsProviderRegistry.m +94 -0
- package/Sources/CCPets/Usage/CCPetsQuotaHistory.h +1 -1
- package/Sources/CCPets/Usage/CCPetsQuotaHistory.m +11 -8
- package/Sources/CCPets/Usage/CCPetsUsage+Internal.h +2 -0
- package/Sources/CCPets/Usage/CCPetsUsage+Models.m +206 -14
- package/Sources/CCPets/Usage/CCPetsUsage+TokenTotals.m +4 -4
- package/Sources/CCPets/Usage/CCPetsUsage.h +7 -2
- package/Sources/CCPets/Usage/CCPetsUsageMode.h +2 -0
- package/Sources/CCPets/Usage/CCPetsUsageMode.m +29 -4
- package/Sources/CCPets/Usage/CCPetsUsageMonitor.h +4 -4
- package/Sources/CCPets/Usage/CCPetsUsageMonitor.m +90 -7
- package/Sources/CCPets/Usage/QuotaDashboardView+CompactRow.m +81 -0
- package/Sources/CCPets/Usage/QuotaDashboardView+Primitives.m +5 -8
- package/Sources/CCPets/Usage/QuotaDashboardView+Private.h +26 -4
- package/Sources/CCPets/Usage/QuotaDashboardView+Rendering.m +99 -99
- package/Sources/CCPets/Usage/QuotaDashboardView.h +9 -10
- package/Sources/CCPets/Usage/QuotaDashboardView.m +232 -79
- package/THIRD_PARTY_NOTICES.md +5 -4
- package/THIRD_PARTY_NOTICES.zh-CN.md +6 -5
- package/bin/agy-with-pet +82 -0
- package/bin/cc-pets +1 -1
- package/bin/claude-with-pet +15 -0
- package/bin/codex-with-pet +17 -2
- package/package.json +5 -3
- package/scripts/install-shell-integration.sh +5 -0
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
#import "CCPetsUsagePage.h"
|
|
2
2
|
#import "CCPetsFormBuilder.h"
|
|
3
3
|
#import "CCPetsL10n.h"
|
|
4
|
+
#import "CCPetsPaths.h"
|
|
4
5
|
#import "CCPetsUIStyle.h"
|
|
5
6
|
#import "CCPetsUsage.h"
|
|
6
7
|
#import "CCPetsProfiles.h"
|
|
8
|
+
#import "CCPetsProviderRegistry.h"
|
|
7
9
|
#import "CCPetsCLISupport.h"
|
|
8
10
|
#import "CCPetsUsageShared.h"
|
|
9
11
|
#import "CCPetsUsageChartView.h"
|
|
@@ -38,7 +40,26 @@ static NSString *HitRateText(NSDictionary *counts) {
|
|
|
38
40
|
}
|
|
39
41
|
|
|
40
42
|
static NSString *ProviderTitle(NSString *provider) {
|
|
41
|
-
|
|
43
|
+
if ([provider isEqualToString:CCPetsProfileProviderClaude]) return @"Claude Code";
|
|
44
|
+
if ([provider isEqualToString:CCPetsProfileProviderAntigravity]) return @"Antigravity CLI";
|
|
45
|
+
if ([provider isEqualToString:CCPetsUsageProviderAntigravityApp]) return @"Antigravity App";
|
|
46
|
+
return CCPetsProviderForProfileProvider(provider).name ?: provider;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
static NSString *SourceTitle(NSDictionary *source) {
|
|
50
|
+
NSString *provider = source[@"provider"];
|
|
51
|
+
NSString *accountName = source[@"displayName"] ?: source[@"slug"];
|
|
52
|
+
if (accountName.length == 0) return ProviderTitle(provider);
|
|
53
|
+
if ([provider isEqualToString:CCPetsProfileProviderAntigravity]) {
|
|
54
|
+
NSString *title = ProviderTitle(provider);
|
|
55
|
+
if (CCPetsProfileIsOfficialDefault(source) && ![source[@"customName"] boolValue]) return title;
|
|
56
|
+
return [NSString stringWithFormat:@"%@ · %@", title, accountName];
|
|
57
|
+
}
|
|
58
|
+
return accountName;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
static NSString *SourceIdentity(NSDictionary *source) {
|
|
62
|
+
return source[@"id"] ?: source[@"provider"];
|
|
42
63
|
}
|
|
43
64
|
|
|
44
65
|
static NSString *EntrySourceTitle(NSDictionary *entry) {
|
|
@@ -115,8 +136,8 @@ static const NSTimeInterval UsagePageRefreshInterval = 60;
|
|
|
115
136
|
@property(nonatomic) NSSegmentedControl *sourceControl;
|
|
116
137
|
@property(nonatomic) NSPopUpButton *sourcePopup;
|
|
117
138
|
@property(nonatomic) NSStackView *sourceSwitcher;
|
|
118
|
-
// segment 0
|
|
119
|
-
@property(nonatomic) NSArray<NSDictionary *> *
|
|
139
|
+
// segment 0 是全部来源,其余与这里的顺序一一对应。
|
|
140
|
+
@property(nonatomic) NSArray<NSDictionary *> *filterSources;
|
|
120
141
|
@property(nonatomic) NSSegmentedControl *rangeControl;
|
|
121
142
|
@property(nonatomic) NSSegmentedControl *metricControl;
|
|
122
143
|
@property(nonatomic) NSProgressIndicator *spinner;
|
|
@@ -182,7 +203,7 @@ static const NSTimeInterval UsagePageRefreshInterval = 60;
|
|
|
182
203
|
self.sourceSwitcher = [NSStackView stackViewWithViews:@[self.sourceControl, self.sourcePopup]];
|
|
183
204
|
self.sourceSwitcher.orientation = NSUserInterfaceLayoutOrientationHorizontal;
|
|
184
205
|
self.sourceSwitcher.spacing = 0;
|
|
185
|
-
[self
|
|
206
|
+
[self rebuildSourceControlSelectingID:nil];
|
|
186
207
|
NSMutableArray<NSString *> *ranges = [NSMutableArray array];
|
|
187
208
|
for (NSNumber *days in @[@7, @30, @90]) {
|
|
188
209
|
[ranges addObject:[NSString stringWithFormat:L(@"%ld Days"), (long)days.integerValue]];
|
|
@@ -237,8 +258,7 @@ static const NSTimeInterval UsagePageRefreshInterval = 60;
|
|
|
237
258
|
|
|
238
259
|
- (void)storeDidChange:(NSNotification *)notification {
|
|
239
260
|
[self.spinner stopAnimation:nil];
|
|
240
|
-
|
|
241
|
-
[self rebuildSourceControlSelectingProfileID:selectedID];
|
|
261
|
+
[self rebuildSourceControlSelectingID:SourceIdentity([self selectedSource])];
|
|
242
262
|
[self computeColorSlots];
|
|
243
263
|
[self render];
|
|
244
264
|
}
|
|
@@ -252,32 +272,42 @@ static const NSTimeInterval UsagePageRefreshInterval = 60;
|
|
|
252
272
|
return (UsageMetric)MAX(0, self.metricControl.selectedSegment);
|
|
253
273
|
}
|
|
254
274
|
|
|
255
|
-
- (void)
|
|
256
|
-
NSMutableArray<NSDictionary *> *
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
275
|
+
- (void)rebuildSourceControlSelectingID:(NSString *)selectedID {
|
|
276
|
+
NSMutableArray<NSDictionary *> *sources = [NSMutableArray array];
|
|
277
|
+
for (CCPetsProviderDescriptor *descriptor in CCPetsProviderDescriptors()) {
|
|
278
|
+
NSString *provider = descriptor.profileProvider;
|
|
279
|
+
NSArray<NSDictionary *> *profiles = CCPetsProfilesForProvider(provider);
|
|
280
|
+
if ([provider isEqualToString:CCPetsProfileProviderAntigravity] && profiles.count > 1) {
|
|
281
|
+
[sources addObject:@{@"provider": provider}];
|
|
282
|
+
}
|
|
283
|
+
[sources addObjectsFromArray:profiles];
|
|
284
|
+
}
|
|
285
|
+
if (CCPetsUsageStore.results[CCPetsUsageProviderAntigravityApp] || CCPetsAntigravityAppUsageAvailable()) {
|
|
286
|
+
[sources addObject:@{@"provider": CCPetsUsageProviderAntigravityApp, @"home": DefaultAntigravityAppConfigDirectory()}];
|
|
287
|
+
}
|
|
288
|
+
self.filterSources = sources;
|
|
289
|
+
NSString *defaultTitle = L(@"All");
|
|
290
|
+
self.sourceControl.segmentCount = sources.count + 1;
|
|
291
|
+
[self.sourceControl setLabel:defaultTitle forSegment:0];
|
|
263
292
|
[self.sourceControl setWidth:0 forSegment:0];
|
|
264
293
|
[self.sourcePopup removeAllItems];
|
|
265
|
-
[self.sourcePopup addItemWithTitle:
|
|
294
|
+
[self.sourcePopup addItemWithTitle:defaultTitle];
|
|
266
295
|
NSInteger selectedSegment = 0;
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
296
|
+
NSDictionary *labelAttributes = @{NSFontAttributeName: self.sourceControl.font};
|
|
297
|
+
CGFloat estimatedWidth = MAX(44, [defaultTitle sizeWithAttributes:labelAttributes].width + 22);
|
|
298
|
+
for (NSUInteger index = 0; index < sources.count; index++) {
|
|
299
|
+
NSDictionary *source = sources[index];
|
|
300
|
+
NSString *title = SourceTitle(source);
|
|
301
|
+
NSString *home = source[@"home"];
|
|
302
|
+
NSString *toolTip = home ? CCPetsTildePath(home) : nil;
|
|
271
303
|
NSInteger segment = (NSInteger)index + 1;
|
|
272
304
|
[self.sourceControl setLabel:title forSegment:segment];
|
|
273
|
-
[self.sourceControl setToolTip:
|
|
305
|
+
[self.sourceControl setToolTip:toolTip forSegment:segment];
|
|
274
306
|
[self.sourceControl setWidth:0 forSegment:segment];
|
|
275
307
|
[self.sourcePopup addItemWithTitle:title];
|
|
276
|
-
self.sourcePopup.lastItem.toolTip =
|
|
277
|
-
estimatedWidth += MAX(54, [title sizeWithAttributes
|
|
278
|
-
|
|
279
|
-
}].width + 22);
|
|
280
|
-
if (selectedID.length > 0 && [profile[@"id"] isEqualToString:selectedID]) {
|
|
308
|
+
self.sourcePopup.lastItem.toolTip = toolTip;
|
|
309
|
+
estimatedWidth += MAX(54, [title sizeWithAttributes:labelAttributes].width + 22);
|
|
310
|
+
if ([SourceIdentity(source) isEqualToString:selectedID]) {
|
|
281
311
|
selectedSegment = segment;
|
|
282
312
|
}
|
|
283
313
|
}
|
|
@@ -285,22 +315,17 @@ static const NSTimeInterval UsagePageRefreshInterval = 60;
|
|
|
285
315
|
[self.sourcePopup selectItemAtIndex:selectedSegment];
|
|
286
316
|
// 少量短名称保留快速分段切换;账号多或名称长时自动降级为下拉菜单,避免和
|
|
287
317
|
// 右侧时间范围控件互相挤压。下拉菜单仍完整保留每个账号和 Home 提示。
|
|
288
|
-
BOOL usePopup =
|
|
318
|
+
BOOL usePopup = sources.count > 3 || estimatedWidth > 360;
|
|
289
319
|
self.sourceControl.hidden = usePopup;
|
|
290
320
|
self.sourcePopup.hidden = !usePopup;
|
|
291
321
|
}
|
|
292
322
|
|
|
293
|
-
- (NSDictionary *)
|
|
323
|
+
- (NSDictionary *)selectedSource {
|
|
294
324
|
NSInteger selected = self.sourcePopup.hidden
|
|
295
325
|
? self.sourceControl.selectedSegment : self.sourcePopup.indexOfSelectedItem;
|
|
296
326
|
NSInteger index = selected - 1;
|
|
297
|
-
return index >= 0 && index < (NSInteger)self.
|
|
298
|
-
? self.
|
|
299
|
-
}
|
|
300
|
-
|
|
301
|
-
- (NSString *)selectedAccountID {
|
|
302
|
-
NSString *value = [self selectedProfile][@"id"];
|
|
303
|
-
return [value isKindOfClass:NSString.class] && value.length > 0 ? value : nil;
|
|
327
|
+
return index >= 0 && index < (NSInteger)self.filterSources.count
|
|
328
|
+
? self.filterSources[(NSUInteger)index] : nil;
|
|
304
329
|
}
|
|
305
330
|
|
|
306
331
|
// 色板位置:90 天、全部来源里按总用量排名,前 8 名各占一色,其余归「其他」。
|
|
@@ -346,15 +371,17 @@ static const NSTimeInterval UsagePageRefreshInterval = 60;
|
|
|
346
371
|
// 按当前来源和区间整理条目。区间合计由截取后的每日数据现加,不用数据层的 models(那是整整 90 天的)。
|
|
347
372
|
- (NSArray<NSDictionary *> *)entriesForRangeDays:(NSInteger)rangeDays {
|
|
348
373
|
NSMutableArray<NSDictionary *> *entries = [NSMutableArray array];
|
|
349
|
-
NSDictionary *
|
|
350
|
-
NSString *selectedProvider =
|
|
351
|
-
|
|
352
|
-
|
|
374
|
+
NSDictionary *selectedSource = [self selectedSource];
|
|
375
|
+
NSString *selectedProvider = selectedSource[@"provider"];
|
|
376
|
+
NSString *selectedProfileID = selectedSource[@"id"];
|
|
377
|
+
NSString *sourceTitle = selectedProfileID ? SourceTitle(selectedSource) : nil;
|
|
378
|
+
NSDictionary *results = CCPetsUsageStore.results;
|
|
379
|
+
NSArray<NSString *> *providers = selectedProvider ? @[selectedProvider]
|
|
380
|
+
: [[CCPetsProviderDescriptors() valueForKey:@"profileProvider"] arrayByAddingObject:CCPetsUsageProviderAntigravityApp];
|
|
353
381
|
NSArray<NSNumber *> *stamps = nil;
|
|
354
382
|
for (NSString *provider in providers) {
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
? CCPetsUsageStore.profileResults[selectedID] : CCPetsUsageStore.results[provider];
|
|
383
|
+
NSDictionary *result = selectedProfileID
|
|
384
|
+
? CCPetsUsageStore.profileResults[selectedProfileID] : results[provider];
|
|
358
385
|
NSArray<NSDictionary *> *daily = result[@"daily"];
|
|
359
386
|
if (daily.count > (NSUInteger)rangeDays) {
|
|
360
387
|
daily = [daily subarrayWithRange:NSMakeRange(daily.count - (NSUInteger)rangeDays, (NSUInteger)rangeDays)];
|
|
@@ -369,8 +396,7 @@ static const NSTimeInterval UsagePageRefreshInterval = 60;
|
|
|
369
396
|
if (CCPetsTotalTokens(counts) == 0 && Count(counts, @"requests") == 0) continue;
|
|
370
397
|
NSMutableDictionary *entry = [@{@"key": [NSString stringWithFormat:@"%@|%@", provider, model],
|
|
371
398
|
@"provider": provider, @"model": model, @"counts": counts, @"days": days} mutableCopy];
|
|
372
|
-
|
|
373
|
-
if (accountName.length > 0) entry[@"accountName"] = accountName;
|
|
399
|
+
if (sourceTitle.length > 0) entry[@"accountName"] = sourceTitle;
|
|
374
400
|
[entries addObject:entry];
|
|
375
401
|
}
|
|
376
402
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
#import "CCPetsUsagePage.h"
|
|
2
2
|
#import "CCPetsProfiles.h"
|
|
3
|
+
#import "CCPetsProviderRegistry.h"
|
|
3
4
|
#import "CCPetsUsageShared.h"
|
|
4
5
|
|
|
5
6
|
#pragma mark - 数据
|
|
@@ -10,6 +11,7 @@ static const NSInteger UsageMaximumRangeDays = 90;
|
|
|
10
11
|
static const NSTimeInterval UsageStoreFreshness = 120;
|
|
11
12
|
|
|
12
13
|
NSNotificationName const CCPetsUsageStoreDidChangeNotification = @"CCPetsUsageStoreDidChange";
|
|
14
|
+
NSString *const CCPetsUsageProviderAntigravityApp = @"antigravity-app";
|
|
13
15
|
static NSDictionary<NSString *, NSDictionary *> *UsageStoreResults;
|
|
14
16
|
static NSDictionary<NSString *, NSDictionary *> *UsageStoreProfileResults;
|
|
15
17
|
static NSTimeInterval UsageStoreLoadedAt;
|
|
@@ -74,6 +76,8 @@ static NSDictionary *MergeModelUsageResults(NSArray<NSDictionary *> *values) {
|
|
|
74
76
|
for (NSDictionary *profile in CCPetsProfiles()) {
|
|
75
77
|
[identity addObject:[NSString stringWithFormat:@"%@|%@", profile[@"id"], profile[@"home"]]];
|
|
76
78
|
}
|
|
79
|
+
BOOL antigravityAppAvailable = CCPetsAntigravityAppUsageAvailable();
|
|
80
|
+
if (antigravityAppAvailable) [identity addObject:CCPetsUsageProviderAntigravityApp];
|
|
77
81
|
NSString *fingerprint = [identity componentsJoinedByString:@"\n"];
|
|
78
82
|
NSCalendar *calendar = NSCalendar.currentCalendar;
|
|
79
83
|
NSDate *today = [calendar startOfDayForDate:NSDate.date];
|
|
@@ -92,7 +96,8 @@ static NSDictionary *MergeModelUsageResults(NSArray<NSDictionary *> *values) {
|
|
|
92
96
|
dispatch_async(queue, ^{
|
|
93
97
|
NSMutableDictionary *results = [NSMutableDictionary dictionary];
|
|
94
98
|
NSMutableDictionary *profileResults = [NSMutableDictionary dictionary];
|
|
95
|
-
for (
|
|
99
|
+
for (CCPetsProviderDescriptor *descriptor in CCPetsProviderDescriptors()) {
|
|
100
|
+
NSString *provider = descriptor.profileProvider;
|
|
96
101
|
NSArray<NSDictionary *> *profiles = CCPetsProfilesForProvider(provider);
|
|
97
102
|
if (profiles.count == 0) continue;
|
|
98
103
|
NSMutableArray<NSDictionary *> *providerValues = [NSMutableArray array];
|
|
@@ -105,6 +110,11 @@ static NSDictionary *MergeModelUsageResults(NSArray<NSDictionary *> *values) {
|
|
|
105
110
|
}
|
|
106
111
|
results[provider] = MergeModelUsageResults(providerValues);
|
|
107
112
|
}
|
|
113
|
+
if (antigravityAppAvailable) {
|
|
114
|
+
NSDictionary *appUsage = CCPetsModelUsage(CCPetsUsageProviderAntigravityApp,
|
|
115
|
+
start.timeIntervalSince1970, end.timeIntervalSince1970);
|
|
116
|
+
if (appUsage) results[CCPetsUsageProviderAntigravityApp] = appUsage;
|
|
117
|
+
}
|
|
108
118
|
dispatch_async(dispatch_get_main_queue(), ^{
|
|
109
119
|
UsageStoreResults = results;
|
|
110
120
|
UsageStoreProfileResults = profileResults;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
#import "CCPetsWorkbenchPages.h"
|
|
2
|
+
#import "CCPetsBridgeStore.h"
|
|
2
3
|
#import "CCPetsDiagnosticsPage.h"
|
|
3
4
|
#import "CCPetsFormBuilder.h"
|
|
4
5
|
#import "CCPetsL10n.h"
|
|
@@ -161,7 +162,7 @@ static NSButton *ActionButton(NSString *title, BOOL prominent, void (^action)(vo
|
|
|
161
162
|
|
|
162
163
|
#pragma mark 宠物卡
|
|
163
164
|
|
|
164
|
-
//
|
|
165
|
+
// 从每个来源的 90 天数据取最后一天,合计为今日用量。
|
|
165
166
|
- (NSArray<NSArray<NSString *> *> *)todayStats {
|
|
166
167
|
NSDictionary *results = CCPetsUsageStore.results;
|
|
167
168
|
if (!results) {
|
|
@@ -632,7 +633,7 @@ static const CGFloat SessionStateWidth = 92, SessionTimeWidth = 72, SessionActio
|
|
|
632
633
|
kind:CCPetsStatusKindForAgentState(state)];
|
|
633
634
|
[chip.widthAnchor constraintLessThanOrEqualToConstant:SessionStateWidth].active = YES;
|
|
634
635
|
|
|
635
|
-
NSString *title = [session[@"
|
|
636
|
+
NSString *title = [session[@"displayName"] length] > 0 ? session[@"displayName"] : session[@"provider"];
|
|
636
637
|
NSTextField *name = CCPetsLabel(title, 13, NSFontWeightSemibold, CCPetsInkColor());
|
|
637
638
|
NSMutableArray<NSString *> *parts = [NSMutableArray arrayWithObject:session[@"provider"]];
|
|
638
639
|
if ([session[@"terminal"] length] > 0) [parts addObject:session[@"terminal"]];
|
|
@@ -746,7 +747,7 @@ static const CGFloat SessionStateWidth = 92, SessionTimeWidth = 72, SessionActio
|
|
|
746
747
|
NSString *session = entry[@"session"];
|
|
747
748
|
NSUInteger count = [entry[@"count"] unsignedIntegerValue];
|
|
748
749
|
NSTextField *icon = CCPetsLabel(@"", 12, NSFontWeightRegular, CCPetsTertiaryInkColor());
|
|
749
|
-
NSTextField *name = CCPetsLabel(entry[@"name"], 12, NSFontWeightSemibold, CCPetsInkColor());
|
|
750
|
+
NSTextField *name = CCPetsLabel(entry[@"displayName"] ?: entry[@"name"], 12, NSFontWeightSemibold, CCPetsInkColor());
|
|
750
751
|
NSTextField *detail = CCPetsLabel(count == 1 ? L(@"1 message waiting. Say anything in that terminal to deliver it.")
|
|
751
752
|
: [NSString stringWithFormat:L(@"%lu messages waiting. Say anything in that terminal to deliver them."),
|
|
752
753
|
(unsigned long)count], 12, NSFontWeightRegular, CCPetsSecondaryInkColor());
|
|
@@ -762,7 +763,8 @@ static const CGFloat SessionStateWidth = 92, SessionTimeWidth = 72, SessionActio
|
|
|
762
763
|
NSTextField *time = CCPetsNumberLabel([NSDateFormatter localizedStringFromDate:date
|
|
763
764
|
dateStyle:NSDateFormatterNoStyle timeStyle:NSDateFormatterShortStyle], 12, NSFontWeightRegular,
|
|
764
765
|
CCPetsTertiaryInkColor());
|
|
765
|
-
NSTextField *route = [self routeFrom:delivery[@"
|
|
766
|
+
NSTextField *route = [self routeFrom:CCBridgeSessionDisplayName(delivery[@"fromIdentity"])
|
|
767
|
+
to:CCBridgeSessionDisplayName(delivery[@"toIdentity"])];
|
|
766
768
|
NSTextField *detail = CCPetsLabel(@"", 12, NSFontWeightRegular, CCPetsSecondaryInkColor());
|
|
767
769
|
BOOL unseen = [delivery[@"unseen"] boolValue];
|
|
768
770
|
CCPetsChipView *chip = [[CCPetsChipView alloc] initWithText:unseen ? L(@"Unread") : L(@"Delivered")
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
#import "CCPetsUsage+Internal.h"
|
|
2
|
+
#import "CCPetsCLISupport.h"
|
|
3
|
+
#import "CCPetsPaths.h"
|
|
4
|
+
#import "CCPetsUsageMode.h"
|
|
5
|
+
#import <math.h>
|
|
6
|
+
|
|
7
|
+
static NSDictionary *JSONObject(NSData *data) {
|
|
8
|
+
id value = data.length ? [NSJSONSerialization JSONObjectWithData:data options:0 error:nil] : nil;
|
|
9
|
+
return [value isKindOfClass:NSDictionary.class] ? value : nil;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
static NSString *WindowKey(id value) {
|
|
13
|
+
if (![value isKindOfClass:NSString.class]) return nil;
|
|
14
|
+
NSString *label = [[[value lowercaseString] componentsSeparatedByCharactersInSet:
|
|
15
|
+
NSCharacterSet.alphanumericCharacterSet.invertedSet] componentsJoinedByString:@""];
|
|
16
|
+
for (NSString *term in @[@"rolling", @"quota", @"window", @"limit", @"period"]) {
|
|
17
|
+
label = [label stringByReplacingOccurrencesOfString:term withString:@""];
|
|
18
|
+
}
|
|
19
|
+
if ([@[@"5h", @"5hour", @"5hours", @"fivehour", @"fivehours", @"300m"] containsObject:label]) return @"fiveHour";
|
|
20
|
+
if ([@[@"week", @"weekly", @"1week", @"7d", @"7day", @"7days", @"sevenday", @"sevendays", @"168h"] containsObject:label]) return @"week";
|
|
21
|
+
return nil;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
static NSDictionary *UsageFromAntigravityQuotaReport(NSDictionary *report) {
|
|
25
|
+
if (![report[@"status"] isEqual:@"SUCCESS"]) return nil;
|
|
26
|
+
NSDictionary *command = [report[@"command"] isKindOfClass:NSDictionary.class] ? report[@"command"] : nil;
|
|
27
|
+
if (![command[@"name"] isEqual:@"usage"] && ![command[@"name"] isEqual:@"quota"]) return nil;
|
|
28
|
+
NSDictionary *data = [command[@"data"] isKindOfClass:NSDictionary.class] ? command[@"data"] : nil;
|
|
29
|
+
NSArray *groups = [data[@"groups"] isKindOfClass:NSArray.class] ? data[@"groups"] : nil;
|
|
30
|
+
if (!groups) return nil;
|
|
31
|
+
|
|
32
|
+
NSTimeInterval now = NSDate.date.timeIntervalSince1970;
|
|
33
|
+
NSMutableDictionary *usage = [@{@"sampledAt": @(now)} mutableCopy];
|
|
34
|
+
NSMutableArray *quotaGroups = [NSMutableArray array];
|
|
35
|
+
for (id value in groups) {
|
|
36
|
+
if (![value isKindOfClass:NSDictionary.class]) continue;
|
|
37
|
+
NSDictionary *group = value;
|
|
38
|
+
NSString *name = [group[@"name"] isKindOfClass:NSString.class] ? group[@"name"] : nil;
|
|
39
|
+
NSArray *buckets = [group[@"buckets"] isKindOfClass:NSArray.class] ? group[@"buckets"] : nil;
|
|
40
|
+
if (!name || !buckets) continue;
|
|
41
|
+
NSMutableArray *clean = [NSMutableArray array];
|
|
42
|
+
for (id candidate in buckets) {
|
|
43
|
+
if (![candidate isKindOfClass:NSDictionary.class]) continue;
|
|
44
|
+
NSDictionary *bucket = candidate;
|
|
45
|
+
NSMutableDictionary *details = [NSMutableDictionary dictionary];
|
|
46
|
+
for (NSString *field in @[@"id", @"name", @"description", @"window", @"reset_time"]) {
|
|
47
|
+
if ([bucket[field] isKindOfClass:NSString.class]) details[field] = bucket[field];
|
|
48
|
+
}
|
|
49
|
+
for (NSString *field in @[@"remaining_fraction", @"remaining_amount", @"disabled"]) {
|
|
50
|
+
if ([bucket[field] isKindOfClass:NSNumber.class]) details[field] = bucket[field];
|
|
51
|
+
}
|
|
52
|
+
[clean addObject:details];
|
|
53
|
+
NSString *key = WindowKey(details[@"window"]) ?: WindowKey(details[@"name"]);
|
|
54
|
+
NSNumber *remaining = details[@"remaining_fraction"];
|
|
55
|
+
if (!key || !remaining || !isfinite(remaining.doubleValue) || [details[@"disabled"] boolValue]) continue;
|
|
56
|
+
if (remaining.doubleValue < 0 || remaining.doubleValue > 1) continue;
|
|
57
|
+
NSDate *reset = ISO8601Timestamp(details[@"reset_time"]);
|
|
58
|
+
if (reset && reset.timeIntervalSince1970 <= now) continue;
|
|
59
|
+
double used = (1.0 - remaining.doubleValue) * 100.0;
|
|
60
|
+
// The overview and menu bar show the most constrained bucket in each window.
|
|
61
|
+
if (usage[key] && [usage[key][@"used_percent"] doubleValue] >= used) continue;
|
|
62
|
+
NSMutableDictionary *window = [@{@"used_percent": @(used), @"group": name,
|
|
63
|
+
@"window_minutes": [key isEqual:@"week"] ? @10080 : @300} mutableCopy];
|
|
64
|
+
if (reset) window[@"resets_at"] = @(reset.timeIntervalSince1970);
|
|
65
|
+
usage[key] = window;
|
|
66
|
+
}
|
|
67
|
+
[quotaGroups addObject:@{@"name": name, @"buckets": clean}];
|
|
68
|
+
}
|
|
69
|
+
usage[@"quotaGroups"] = quotaGroups;
|
|
70
|
+
return usage;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
NSDictionary *AntigravityRateLimitsForConfigDirectory(NSString *configDirectory) {
|
|
74
|
+
if (configDirectory.length == 0 || !CCPetsAntigravityQuotaReportEnabled(configDirectory)) return nil;
|
|
75
|
+
NSString *onboardingPath = [configDirectory stringByAppendingPathComponent:@"antigravity-cli/cache/onboarding.json"];
|
|
76
|
+
NSDictionary *onboarding = JSONObject([NSData dataWithContentsOfFile:onboardingPath]);
|
|
77
|
+
if (![onboarding[@"onboardingComplete"] isEqual:@YES] &&
|
|
78
|
+
![onboarding[@"consumerOnboardingComplete"] isEqual:@YES] &&
|
|
79
|
+
![onboarding[@"enterpriseOnboardingComplete"] isEqual:@YES]) return nil;
|
|
80
|
+
|
|
81
|
+
NSString *searchPath = CCPetsEnvironmentValue(@"PATH");
|
|
82
|
+
NSString *executable = CCPetsFindRealExecutableInPath(@"agy", @"AGY_REAL_BIN", searchPath);
|
|
83
|
+
if (!executable) {
|
|
84
|
+
searchPath = CCPetsLoginShellPath();
|
|
85
|
+
executable = CCPetsFindRealExecutableInPath(@"agy", @"AGY_REAL_BIN", searchPath);
|
|
86
|
+
}
|
|
87
|
+
if (!executable) return nil;
|
|
88
|
+
NSMutableArray *arguments = [NSMutableArray array];
|
|
89
|
+
NSString *standardRoot = [CCPetsHomeDirectory() stringByAppendingPathComponent:@".gemini"];
|
|
90
|
+
if (![configDirectory.stringByStandardizingPath isEqual:standardRoot.stringByStandardizingPath]) {
|
|
91
|
+
// This launcher flag was observed in agy 1.5.12. A version that doesn't recognize
|
|
92
|
+
// it fails before the query; avoid falling back to the default profile's quota.
|
|
93
|
+
[arguments addObject:[@"--gemini_dir=" stringByAppendingString:configDirectory]];
|
|
94
|
+
}
|
|
95
|
+
[arguments addObjectsFromArray:@[@"-p", @"/usage", @"--output-format", @"json"]];
|
|
96
|
+
NSMutableDictionary *environment = [NSProcessInfo.processInfo.environment mutableCopy];
|
|
97
|
+
if (searchPath.length) environment[@"PATH"] = searchPath;
|
|
98
|
+
// An app launched by one Agent can inherit that session's API or gateway settings.
|
|
99
|
+
for (NSString *key in environment.allKeys) {
|
|
100
|
+
if ([key hasPrefix:@"AGY_LLM_GATEWAY_"] || [@[@"GEMINI_API_KEY", @"GOOGLE_GEMINI_BASE_URL",
|
|
101
|
+
@"AGY_ADC_AUTH", @"GOOGLE_APPLICATION_CREDENTIALS"] containsObject:key]) [environment removeObjectForKey:key];
|
|
102
|
+
}
|
|
103
|
+
environment[@"AGY_CLI_DISABLE_AUTO_UPDATE"] = @"1";
|
|
104
|
+
// Earlier builds can treat /usage as a normal prompt and spend inference quota.
|
|
105
|
+
NSString *versionOutput = nil;
|
|
106
|
+
if (CCPetsRun(executable, @[@"--version"], configDirectory, environment, 4, &versionOutput, NULL) != 0) return nil;
|
|
107
|
+
NSRange versionRange = [versionOutput rangeOfString:@"[0-9]+\\.[0-9]+\\.[0-9]+" options:NSRegularExpressionSearch];
|
|
108
|
+
if (versionRange.location == NSNotFound ||
|
|
109
|
+
[[versionOutput substringWithRange:versionRange] compare:@"1.1.11" options:NSNumericSearch] == NSOrderedAscending) return nil;
|
|
110
|
+
|
|
111
|
+
NSString *output = nil;
|
|
112
|
+
int result = CCPetsRun(executable, arguments, configDirectory, environment, 8, &output, NULL);
|
|
113
|
+
if (result != 0) return nil;
|
|
114
|
+
return UsageFromAntigravityQuotaReport(JSONObject([output dataUsingEncoding:NSUTF8StringEncoding]));
|
|
115
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
#import "CCPetsNormalizedUsage.h"
|
|
2
|
+
|
|
3
|
+
static NSDictionary *Dictionary(id value) {
|
|
4
|
+
return [value isKindOfClass:NSDictionary.class] ? value : nil;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
NSDictionary *CCPetsTrendWindow(NSArray<NSDictionary *> *windows) {
|
|
8
|
+
for (NSDictionary *window in windows) {
|
|
9
|
+
if ([window[@"trend"] boolValue]) return window;
|
|
10
|
+
}
|
|
11
|
+
return windows.lastObject;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
NSDictionary *CCPetsNormalizedUsage(CCPetsProviderDescriptor *provider, NSDictionary *rawUsage, BOOL showsAPIUsage) {
|
|
15
|
+
if (provider.normalizer) return provider.normalizer(rawUsage ?: @{}, showsAPIUsage);
|
|
16
|
+
NSString *billing = showsAPIUsage ? @"api" : (provider.billing ?: @"none");
|
|
17
|
+
NSDictionary *tokens = Dictionary(rawUsage[@"tokenUsage"]);
|
|
18
|
+
BOOL exhausted = [rawUsage[@"exhaustedAt"] isKindOfClass:NSNumber.class];
|
|
19
|
+
BOOL hasWindowData = exhausted;
|
|
20
|
+
NSMutableArray *windows = [NSMutableArray array];
|
|
21
|
+
for (NSDictionary *spec in provider.windowSpecs) {
|
|
22
|
+
NSString *key = spec[@"key"];
|
|
23
|
+
NSDictionary *quota = Dictionary(rawUsage[key]);
|
|
24
|
+
NSDictionary *totals = Dictionary(tokens[key]);
|
|
25
|
+
id used = quota[provider.usedKey];
|
|
26
|
+
NSMutableDictionary *window = [spec mutableCopy];
|
|
27
|
+
window[@"quota"] = quota ?: @{};
|
|
28
|
+
window[@"tokens"] = totals ?: @{};
|
|
29
|
+
window[@"trend"] = @([spec[@"trend"] boolValue]);
|
|
30
|
+
if ([used isKindOfClass:NSNumber.class]) {
|
|
31
|
+
window[@"used"] = @(fmax(0, fmin(100, [used doubleValue])));
|
|
32
|
+
}
|
|
33
|
+
if (window[@"used"] || totals) hasWindowData = YES;
|
|
34
|
+
[windows addObject:[window copy]];
|
|
35
|
+
}
|
|
36
|
+
NSMutableDictionary *summary = [NSMutableDictionary dictionary];
|
|
37
|
+
for (NSString *key in @[@"month", @"monthComparable", @"previousMonthToDate", @"today", @"recentWeek", @"monthDaily"]) {
|
|
38
|
+
summary[key] = tokens[key];
|
|
39
|
+
}
|
|
40
|
+
BOOL hasData = [billing isEqualToString:@"subscription"] ? hasWindowData : Dictionary(tokens[@"month"]) != nil;
|
|
41
|
+
return @{@"billing": billing, @"windows": [windows copy], @"tokens": [summary copy],
|
|
42
|
+
@"exhausted": @(exhausted), @"hasData": @(hasData)};
|
|
43
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
#import "CCPetsProviderRegistry.h"
|
|
2
|
+
|
|
3
|
+
@interface CCPetsProviderDescriptor (Testing)
|
|
4
|
+
- (instancetype)initWithName:(NSString *)name key:(NSString *)key
|
|
5
|
+
usedKey:(NSString *)usedKey profileProvider:(NSString *)profileProvider
|
|
6
|
+
standardColorRGB:(NSArray<NSNumber *> *)standardColorRGB glassColorRGB:(NSArray<NSNumber *> *)glassColorRGB
|
|
7
|
+
logoBundleIdentifier:(NSString *)logoBundleIdentifier logoResourceName:(NSString *)logoResourceName
|
|
8
|
+
usageDisplayModeDefaultsKey:(NSString *)usageDisplayModeDefaultsKey billing:(NSString *)billing
|
|
9
|
+
windowSpecs:(NSArray<NSDictionary *> *)windowSpecs normalizer:(CCPetsUsageNormalizer)normalizer;
|
|
10
|
+
@end
|
|
11
|
+
|
|
12
|
+
// 测试期间在主线程安装;传 nil 恢复产品注册表。
|
|
13
|
+
void CCPetsProviderRegistrySetOverride(NSArray<CCPetsProviderDescriptor *> *providers);
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
#import <Foundation/Foundation.h>
|
|
2
|
+
|
|
3
|
+
typedef NSDictionary *(^CCPetsUsageNormalizer)(NSDictionary *rawUsage, BOOL showsAPIUsage);
|
|
4
|
+
|
|
5
|
+
// name 是面板和偏好设置使用的显示键;key / profileProvider 保留磁盘中的小写标识。
|
|
6
|
+
@interface CCPetsProviderDescriptor : NSObject
|
|
7
|
+
@property(readonly, copy) NSString *name;
|
|
8
|
+
@property(readonly, copy) NSString *key;
|
|
9
|
+
@property(readonly, copy) NSString *usedKey;
|
|
10
|
+
@property(readonly, copy) NSString *billing;
|
|
11
|
+
@property(readonly, copy) NSArray<NSDictionary *> *windowSpecs;
|
|
12
|
+
@property(readonly, copy) CCPetsUsageNormalizer normalizer;
|
|
13
|
+
@property(readonly, copy) NSString *profileProvider;
|
|
14
|
+
// Foundation-only 元数据;颜色分量顺序为 red、green、blue。
|
|
15
|
+
@property(readonly, copy) NSArray<NSNumber *> *standardColorRGB;
|
|
16
|
+
@property(readonly, copy) NSArray<NSNumber *> *glassColorRGB;
|
|
17
|
+
@property(readonly, copy) NSString *logoBundleIdentifier;
|
|
18
|
+
@property(readonly, copy) NSString *logoResourceName;
|
|
19
|
+
@property(readonly, copy) NSString *usageDisplayModeDefaultsKey;
|
|
20
|
+
@end
|
|
21
|
+
|
|
22
|
+
// 展示顺序固定:Codex、Claude、Antigravity。
|
|
23
|
+
NSArray<CCPetsProviderDescriptor *> *CCPetsProviderDescriptors(void);
|
|
24
|
+
CCPetsProviderDescriptor *CCPetsProviderForName(NSString *name);
|
|
25
|
+
CCPetsProviderDescriptor *CCPetsProviderForProfileProvider(NSString *profileProvider);
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
#import "CCPetsProviderRegistry.h"
|
|
2
|
+
#import "CCPetsProfiles.h"
|
|
3
|
+
#import "CCPetsPaths.h"
|
|
4
|
+
|
|
5
|
+
@interface CCPetsProviderDescriptor ()
|
|
6
|
+
- (instancetype)initWithName:(NSString *)name key:(NSString *)key
|
|
7
|
+
usedKey:(NSString *)usedKey profileProvider:(NSString *)profileProvider
|
|
8
|
+
standardColorRGB:(NSArray<NSNumber *> *)standardColorRGB glassColorRGB:(NSArray<NSNumber *> *)glassColorRGB
|
|
9
|
+
logoBundleIdentifier:(NSString *)logoBundleIdentifier logoResourceName:(NSString *)logoResourceName
|
|
10
|
+
usageDisplayModeDefaultsKey:(NSString *)usageDisplayModeDefaultsKey billing:(NSString *)billing
|
|
11
|
+
windowSpecs:(NSArray<NSDictionary *> *)windowSpecs normalizer:(CCPetsUsageNormalizer)normalizer;
|
|
12
|
+
@end
|
|
13
|
+
|
|
14
|
+
@implementation CCPetsProviderDescriptor
|
|
15
|
+
- (instancetype)initWithName:(NSString *)name key:(NSString *)key
|
|
16
|
+
usedKey:(NSString *)usedKey profileProvider:(NSString *)profileProvider
|
|
17
|
+
standardColorRGB:(NSArray<NSNumber *> *)standardColorRGB glassColorRGB:(NSArray<NSNumber *> *)glassColorRGB
|
|
18
|
+
logoBundleIdentifier:(NSString *)logoBundleIdentifier logoResourceName:(NSString *)logoResourceName
|
|
19
|
+
usageDisplayModeDefaultsKey:(NSString *)usageDisplayModeDefaultsKey billing:(NSString *)billing
|
|
20
|
+
windowSpecs:(NSArray<NSDictionary *> *)windowSpecs normalizer:(CCPetsUsageNormalizer)normalizer {
|
|
21
|
+
if ((self = [super init])) {
|
|
22
|
+
_billing = [billing copy];
|
|
23
|
+
_windowSpecs = [windowSpecs copy];
|
|
24
|
+
_normalizer = [normalizer copy];
|
|
25
|
+
_name = [name copy];
|
|
26
|
+
_key = [key copy];
|
|
27
|
+
_usedKey = [usedKey copy];
|
|
28
|
+
_profileProvider = [profileProvider copy];
|
|
29
|
+
_standardColorRGB = [standardColorRGB copy];
|
|
30
|
+
_glassColorRGB = [glassColorRGB copy];
|
|
31
|
+
_logoBundleIdentifier = [logoBundleIdentifier copy];
|
|
32
|
+
_logoResourceName = [logoResourceName copy];
|
|
33
|
+
_usageDisplayModeDefaultsKey = [usageDisplayModeDefaultsKey copy];
|
|
34
|
+
}
|
|
35
|
+
return self;
|
|
36
|
+
}
|
|
37
|
+
@end
|
|
38
|
+
|
|
39
|
+
static NSArray<CCPetsProviderDescriptor *> *overrideProviders;
|
|
40
|
+
|
|
41
|
+
void CCPetsProviderRegistrySetOverride(NSArray<CCPetsProviderDescriptor *> *providers) {
|
|
42
|
+
overrideProviders = [providers copy];
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
NSArray<CCPetsProviderDescriptor *> *CCPetsProviderDescriptors(void) {
|
|
46
|
+
if (overrideProviders) return overrideProviders;
|
|
47
|
+
static NSArray<CCPetsProviderDescriptor *> *providers;
|
|
48
|
+
static dispatch_once_t onceToken;
|
|
49
|
+
dispatch_once(&onceToken, ^{
|
|
50
|
+
// 这里的 L 只为多语言检查器标记英文源 key,绘制时才按当前语言翻译。
|
|
51
|
+
#define L(source) source
|
|
52
|
+
NSArray *windows = @[
|
|
53
|
+
@{@"key": @"fiveHour", @"titleKey": L(@"5h window"), @"minutes": @300, @"showDate": @NO},
|
|
54
|
+
@{@"key": @"week", @"titleKey": L(@"7d window"), @"minutes": @10080, @"showDate": @YES, @"trend": @YES}
|
|
55
|
+
];
|
|
56
|
+
#undef L
|
|
57
|
+
providers = @[
|
|
58
|
+
[[CCPetsProviderDescriptor alloc] initWithName:@"Codex" key:@"codex"
|
|
59
|
+
usedKey:@"used_percent" profileProvider:CCPetsProfileProviderCodex
|
|
60
|
+
standardColorRGB:@[@0.30, @0.82, @0.90] glassColorRGB:@[@0.30, @0.82, @0.90]
|
|
61
|
+
logoBundleIdentifier:@"com.openai.codex" logoResourceName:@"icon-chatgpt.icns"
|
|
62
|
+
usageDisplayModeDefaultsKey:CodexUsageDisplayModeKey billing:@"subscription"
|
|
63
|
+
windowSpecs:windows normalizer:nil],
|
|
64
|
+
// 原生玻璃背后只有一层压暗,原来的紫在上面偏暗,glass 色提亮到和青色相近的明度。
|
|
65
|
+
[[CCPetsProviderDescriptor alloc] initWithName:@"Claude" key:@"claude"
|
|
66
|
+
usedKey:@"used_percentage" profileProvider:CCPetsProfileProviderClaude
|
|
67
|
+
standardColorRGB:@[@0.66, @0.43, @0.94] glassColorRGB:@[@0.80, @0.66, @1.00]
|
|
68
|
+
logoBundleIdentifier:@"com.anthropic.claudefordesktop" logoResourceName:@"electron.icns"
|
|
69
|
+
usageDisplayModeDefaultsKey:ClaudeUsageDisplayModeKey billing:@"subscription"
|
|
70
|
+
windowSpecs:windows normalizer:nil],
|
|
71
|
+
[[CCPetsProviderDescriptor alloc] initWithName:@"Antigravity" key:@"antigravity"
|
|
72
|
+
usedKey:@"used_percent" profileProvider:CCPetsProfileProviderAntigravity
|
|
73
|
+
standardColorRGB:@[@0.28, @0.63, @0.98] glassColorRGB:@[@0.40, @0.71, @1.00]
|
|
74
|
+
logoBundleIdentifier:@"com.google.antigravity" logoResourceName:@"icon.icns"
|
|
75
|
+
usageDisplayModeDefaultsKey:AntigravityUsageDisplayModeKey billing:@"subscription"
|
|
76
|
+
windowSpecs:windows normalizer:nil]
|
|
77
|
+
];
|
|
78
|
+
});
|
|
79
|
+
return providers;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
CCPetsProviderDescriptor *CCPetsProviderForName(NSString *name) {
|
|
83
|
+
for (CCPetsProviderDescriptor *provider in CCPetsProviderDescriptors()) {
|
|
84
|
+
if ([provider.name isEqualToString:name]) return provider;
|
|
85
|
+
}
|
|
86
|
+
return nil;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
CCPetsProviderDescriptor *CCPetsProviderForProfileProvider(NSString *profileProvider) {
|
|
90
|
+
for (CCPetsProviderDescriptor *provider in CCPetsProviderDescriptors()) {
|
|
91
|
+
if ([provider.profileProvider isEqualToString:profileProvider]) return provider;
|
|
92
|
+
}
|
|
93
|
+
return nil;
|
|
94
|
+
}
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
// 本地额度历史始终记录并展示。
|
|
4
4
|
// RecordQuotaHistory 返回当前文档,调用方直接复用,避免一轮刷新里重复读盘。
|
|
5
5
|
NSDictionary *QuotaHistoryDocument(void);
|
|
6
|
-
NSDictionary *RecordQuotaHistory(NSDictionary
|
|
6
|
+
NSDictionary *RecordQuotaHistory(NSDictionary<NSString *, NSDictionary *> *usageByProvider);
|
|
7
7
|
// 每个点保留 timestamp 与 weekRemaining,绘图层才能按真实时间轴展示缺口和重置。
|
|
8
8
|
NSArray<NSDictionary *> *QuotaHistorySeries(NSDictionary *document, NSString *provider);
|
|
9
9
|
NSDictionary *RecordProfileQuotaHistory(NSDictionary<NSString *, NSDictionary *> *profileUsages,
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
#import "CCPetsQuotaHistory.h"
|
|
2
|
+
#import "CCPetsProviderRegistry.h"
|
|
2
3
|
#import "CCPetsPaths.h"
|
|
3
4
|
#import <sys/stat.h>
|
|
4
5
|
|
|
@@ -44,11 +45,14 @@ static NSDictionary *HistoryProviderSample(NSDictionary *usage, NSString *usedKe
|
|
|
44
45
|
|
|
45
46
|
// 返回当前的历史文档,供调用方直接取用:原先每次刷新要读盘+解析三次
|
|
46
47
|
// (这里一次、两条曲线各一次),现在整轮只读一次。
|
|
47
|
-
NSDictionary *RecordQuotaHistory(NSDictionary
|
|
48
|
+
NSDictionary *RecordQuotaHistory(NSDictionary<NSString *, NSDictionary *> *usageByProvider) {
|
|
48
49
|
NSDictionary *document = QuotaHistoryDocument();
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
50
|
+
NSMutableDictionary *providerSamples = [NSMutableDictionary dictionary];
|
|
51
|
+
for (CCPetsProviderDescriptor *provider in CCPetsProviderDescriptors()) {
|
|
52
|
+
NSDictionary *sample = HistoryProviderSample(usageByProvider[provider.name], provider.usedKey);
|
|
53
|
+
if (sample.count > 0) providerSamples[provider.key] = sample;
|
|
54
|
+
}
|
|
55
|
+
if (providerSamples.count == 0) return document;
|
|
52
56
|
|
|
53
57
|
NSTimeInterval now = NSDate.date.timeIntervalSince1970;
|
|
54
58
|
NSTimeInterval cutoff = now - 7 * 24 * 60 * 60;
|
|
@@ -62,8 +66,7 @@ NSDictionary *RecordQuotaHistory(NSDictionary *codexUsage, NSDictionary *claudeU
|
|
|
62
66
|
if (last && now - [last[@"timestamp"] doubleValue] < 15 * 60) return document;
|
|
63
67
|
|
|
64
68
|
NSMutableDictionary *sample = [@{@"timestamp": @(now)} mutableCopy];
|
|
65
|
-
|
|
66
|
-
if (claude.count > 0) sample[@"claude"] = claude;
|
|
69
|
+
[sample addEntriesFromDictionary:providerSamples];
|
|
67
70
|
[samples addObject:sample];
|
|
68
71
|
if (samples.count > 672) {
|
|
69
72
|
[samples removeObjectsInRange:NSMakeRange(0, samples.count - 672)];
|
|
@@ -114,8 +117,8 @@ NSDictionary *RecordProfileQuotaHistory(NSDictionary<NSString *, NSDictionary *>
|
|
|
114
117
|
for (NSDictionary *profile in profiles) {
|
|
115
118
|
NSString *profileID = profile[@"id"];
|
|
116
119
|
NSDictionary *usage = profileUsages[profileID];
|
|
117
|
-
NSString *usedKey =
|
|
118
|
-
|
|
120
|
+
NSString *usedKey = CCPetsProviderForProfileProvider(profile[@"provider"]).usedKey
|
|
121
|
+
?: @"used_percentage";
|
|
119
122
|
NSDictionary *sample = HistoryProviderSample(usage, usedKey);
|
|
120
123
|
if (profileID.length > 0 && sample.count > 0) profileSamples[profileID] = sample;
|
|
121
124
|
}
|