MCPcopy Create free account
hub / github.com/MoonshotAI/kimi-code / toUsageRow

Function toUsageRow

packages/oauth/src/managed-usage.ts:77–101  ·  view source on GitHub ↗
(raw: unknown, defaultLabel: string)

Source from the content-addressed store, hash-verified

75}
76
77function toUsageRow(raw: unknown, defaultLabel: string): UsageRow | null {
78 if (!isRecord(raw)) return null;
79 const limit = toInt(raw['limit']);
80 let used = toInt(raw['used']);
81 if (used === null) {
82 const remaining = toInt(raw['remaining']);
83 if (remaining !== null && limit !== null) {
84 used = limit - remaining;
85 }
86 }
87 if (used === null && limit === null) return null;
88 const name =
89 typeof raw['name'] === 'string'
90 ? raw['name']
91 : typeof raw['title'] === 'string'
92 ? raw['title']
93 : defaultLabel;
94 const resetHint = resetHintFrom(raw);
95 return {
96 label: name,
97 used: used ?? 0,
98 limit: limit ?? 0,
99 resetHint,
100 };
101}
102
103function limitLabel(
104 item: Record<string, unknown>,

Callers 1

parseManagedUsagePayloadFunction · 0.85

Calls 3

isRecordFunction · 0.90
toIntFunction · 0.85
resetHintFromFunction · 0.85

Tested by

no test coverage detected