@leo000001/opencode-quota-sidebar 4.1.1 → 4.1.2
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/cli.js +16 -7
- package/dist/provider_catalog.d.ts +4 -0
- package/dist/provider_catalog.js +41 -2
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -12,7 +12,7 @@ import { sinceFromLast } from './period.js';
|
|
|
12
12
|
import { authFilePath, loadConfig, loadState,
|
|
13
13
|
// reused for CLI-local config layering
|
|
14
14
|
quotaConfigPaths, resolveOpencodeDataDir, stateFilePath, } from './storage.js';
|
|
15
|
-
import { filterHistoryProvidersForDisplay, filterUsageProvidersForDisplay, listCurrentProviderIDs, } from './provider_catalog.js';
|
|
15
|
+
import { filterHistoryProvidersForDisplay, filterUsageProvidersForDisplay, listConnectedProviderIDs, listCurrentProviderIDs, } from './provider_catalog.js';
|
|
16
16
|
import { createUsageService } from './usage_service.js';
|
|
17
17
|
function emptyProviderUsage(usage) {
|
|
18
18
|
return {
|
|
@@ -38,6 +38,9 @@ function strictFilterHistoryProviders(history, allowedProviderIDs) {
|
|
|
38
38
|
}
|
|
39
39
|
return filterHistoryProvidersForDisplay(history, allowedProviderIDs);
|
|
40
40
|
}
|
|
41
|
+
function cliQuotaProviderIDs(usageProviderIDs, connectedProviderIDs) {
|
|
42
|
+
return [...new Set([...usageProviderIDs, ...connectedProviderIDs])];
|
|
43
|
+
}
|
|
41
44
|
const DEFAULT_OPENCODE_BASE_URL = 'http://localhost:4096';
|
|
42
45
|
const DEFAULT_OPENCODE_HOST = '127.0.0.1';
|
|
43
46
|
const DEFAULT_OPENCODE_PORT = 4096;
|
|
@@ -656,15 +659,21 @@ export async function runCli(argv) {
|
|
|
656
659
|
listDescendantSessionIDs: async () => [],
|
|
657
660
|
},
|
|
658
661
|
});
|
|
659
|
-
const allowedProviderIDs = await
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
662
|
+
const [allowedProviderIDs, connectedProviderIDs] = await Promise.all([
|
|
663
|
+
listCurrentProviderIDs({
|
|
664
|
+
client,
|
|
665
|
+
directory,
|
|
666
|
+
}),
|
|
667
|
+
listConnectedProviderIDs({
|
|
668
|
+
client,
|
|
669
|
+
directory,
|
|
670
|
+
}),
|
|
671
|
+
]);
|
|
663
672
|
if (command.since || command.last !== undefined) {
|
|
664
673
|
const resolvedSince = command.since || sinceFromLast(command.period, command.last);
|
|
665
674
|
const historyRaw = await usageService.summarizeHistoryUsage(command.period, resolvedSince);
|
|
666
675
|
const history = strictFilterHistoryProviders(historyRaw, allowedProviderIDs);
|
|
667
|
-
const quotas = await quotaService.getQuotaSnapshots(Object.keys(history.total.providers));
|
|
676
|
+
const quotas = await quotaService.getQuotaSnapshots(cliQuotaProviderIDs(Object.keys(history.total.providers), connectedProviderIDs));
|
|
668
677
|
return renderCliHistoryDashboard({
|
|
669
678
|
result: history,
|
|
670
679
|
quotas,
|
|
@@ -674,7 +683,7 @@ export async function runCli(argv) {
|
|
|
674
683
|
}
|
|
675
684
|
const usageRaw = await usageService.summarizeForTool(command.period, '', false);
|
|
676
685
|
const usage = strictFilterUsageProviders(usageRaw, allowedProviderIDs);
|
|
677
|
-
const quotas = await quotaService.getQuotaSnapshots(Object.keys(usage.providers));
|
|
686
|
+
const quotas = await quotaService.getQuotaSnapshots(cliQuotaProviderIDs(Object.keys(usage.providers), connectedProviderIDs));
|
|
678
687
|
return renderCliDashboard({
|
|
679
688
|
label: cliCurrentLabel(command.period),
|
|
680
689
|
usage,
|
|
@@ -4,5 +4,9 @@ export declare function listCurrentProviderIDs(input: {
|
|
|
4
4
|
client: unknown;
|
|
5
5
|
directory: string;
|
|
6
6
|
}): Promise<Set<string>>;
|
|
7
|
+
export declare function listConnectedProviderIDs(input: {
|
|
8
|
+
client: unknown;
|
|
9
|
+
directory: string;
|
|
10
|
+
}): Promise<Set<string>>;
|
|
7
11
|
export declare function filterUsageProvidersForDisplay(usage: UsageSummary, allowedProviderIDs: ReadonlySet<string>): UsageSummary;
|
|
8
12
|
export declare function filterHistoryProvidersForDisplay(result: HistoryUsageResult, allowedProviderIDs: ReadonlySet<string>): HistoryUsageResult;
|
package/dist/provider_catalog.js
CHANGED
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
function isRecord(value) {
|
|
2
2
|
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
3
3
|
}
|
|
4
|
-
function
|
|
5
|
-
|
|
4
|
+
function providerDataFromResponse(response) {
|
|
5
|
+
return isRecord(response) &&
|
|
6
|
+
Object.prototype.hasOwnProperty.call(response, 'data')
|
|
6
7
|
? response.data
|
|
7
8
|
: undefined;
|
|
9
|
+
}
|
|
10
|
+
function providerListFromResponse(response) {
|
|
11
|
+
const data = providerDataFromResponse(response);
|
|
8
12
|
const record = isRecord(data) ? data : undefined;
|
|
9
13
|
return Array.isArray(record?.providers)
|
|
10
14
|
? record.providers
|
|
@@ -14,6 +18,13 @@ function providerListFromResponse(response) {
|
|
|
14
18
|
? data
|
|
15
19
|
: undefined;
|
|
16
20
|
}
|
|
21
|
+
function connectedProviderIDsFromResponse(response) {
|
|
22
|
+
const data = providerDataFromResponse(response);
|
|
23
|
+
const record = isRecord(data) ? data : undefined;
|
|
24
|
+
return Array.isArray(record?.connected)
|
|
25
|
+
? record.connected.filter((item) => typeof item === 'string' && !!item)
|
|
26
|
+
: undefined;
|
|
27
|
+
}
|
|
17
28
|
export async function listCurrentProviderIDs(input) {
|
|
18
29
|
const client = input.client;
|
|
19
30
|
const ids = new Set();
|
|
@@ -46,6 +57,34 @@ export async function listCurrentProviderIDs(input) {
|
|
|
46
57
|
}
|
|
47
58
|
return ids;
|
|
48
59
|
}
|
|
60
|
+
export async function listConnectedProviderIDs(input) {
|
|
61
|
+
const client = input.client;
|
|
62
|
+
const ids = new Set();
|
|
63
|
+
const collect = (response) => {
|
|
64
|
+
const connected = connectedProviderIDsFromResponse(response);
|
|
65
|
+
if (!connected)
|
|
66
|
+
return false;
|
|
67
|
+
for (const providerID of connected)
|
|
68
|
+
ids.add(providerID);
|
|
69
|
+
return ids.size > 0;
|
|
70
|
+
};
|
|
71
|
+
if (client.config?.providers) {
|
|
72
|
+
const response = await client.config.providers({
|
|
73
|
+
query: { directory: input.directory },
|
|
74
|
+
throwOnError: true,
|
|
75
|
+
});
|
|
76
|
+
if (collect(response))
|
|
77
|
+
return ids;
|
|
78
|
+
}
|
|
79
|
+
if (client.provider?.list) {
|
|
80
|
+
const response = await client.provider.list({
|
|
81
|
+
query: { directory: input.directory },
|
|
82
|
+
throwOnError: true,
|
|
83
|
+
});
|
|
84
|
+
collect(response);
|
|
85
|
+
}
|
|
86
|
+
return ids;
|
|
87
|
+
}
|
|
49
88
|
export function filterUsageProvidersForDisplay(usage, allowedProviderIDs) {
|
|
50
89
|
if (allowedProviderIDs.size === 0)
|
|
51
90
|
return usage;
|
package/package.json
CHANGED