feat: integrate token point usage v2
Some checks failed
Electron E2E / Electron E2E (macos-latest) (push) Has been cancelled
Electron E2E / Electron E2E (ubuntu-latest) (push) Has been cancelled
Electron E2E / Electron E2E (windows-latest) (push) Has been cancelled

This commit is contained in:
2026-09-06 14:24:50 +08:00
parent 9fed0cc7c4
commit 83ad10d95e
14 changed files with 907 additions and 201 deletions

View File

@@ -187,13 +187,26 @@ export type WorksSpeechTranscriptionInput = {
model?: string;
};
export type WorksTokenUsage = {
five_hour_remaining_percent: number | null;
five_hour_refresh_at?: string | null;
weekly_remaining_percent: number | null;
weekly_refresh_at?: string | null;
plan_code?: string | null;
plan_name?: string | null;
export type WorksTokenPointBalance = {
plan_code: string | null;
plan_name: string | null;
cycle_start: string | null;
cycle_end: string | null;
next_refresh_at: string | null;
weekly_allowance: string | null;
weekly_used: string | null;
weekly_reserved: string | null;
weekly_remaining: string | null;
permanent_total: string | null;
permanent_used: string | null;
permanent_reserved: string | null;
permanent_remaining: string | null;
total_remaining: string | null;
entitlement_source: 'self' | 'family_owner' | 'shared_group';
family_shared: boolean;
can_manage_membership: boolean;
upgrade_action: 'self_service' | 'contact_family_owner';
shared_available: boolean | null;
};
export type PlazaCard = {
@@ -402,16 +415,16 @@ export async function fetchMyWorksProjects(
return assertSuccess(response, 'page', 'Failed to load your Works Square projects');
}
export async function fetchWorksTokenUsage(accessToken: string): Promise<WorksTokenUsage> {
const response = await hostApiFetch<WorksActionResponse<'usage', WorksTokenUsage>>(
'/api/works/billing/token-usage',
export async function fetchWorksTokenPointBalance(accessToken: string): Promise<WorksTokenPointBalance> {
const response = await hostApiFetch<WorksActionResponse<'points', WorksTokenPointBalance>>(
'/api/works/billing/points',
{
headers: {
'X-NianCode-Access-Token': accessToken,
},
},
);
return assertSuccess(response, 'usage', 'Failed to load Works Square token usage');
return assertSuccess(response, 'points', 'Failed to load Works Square token points');
}
export async function fetchMyWorksProjectStatus(