|
1 | 1 | # GitHub Usage Report Library |
2 | 2 |
|
3 | | -A TypeScript library to read and process GitHub usage data from CSV files. |
| 3 | +A TypeScript library to read and process GitHub usage data and model usage data from CSV files. |
4 | 4 |
|
5 | 5 | ## Features |
6 | 6 |
|
7 | 7 | - Parse GitHub Actions usage reports from CSV files |
| 8 | +- Parse model usage reports (e.g., AI model interactions) from CSV files |
8 | 9 | - Support for both streaming (async) and direct (sync) file reading |
| 10 | +- Works in both Node.js and web environments |
9 | 11 | - TypeScript support with full type definitions |
10 | 12 | - Optional line-by-line processing callbacks |
11 | 13 |
|
12 | 14 | ## Installation |
13 | 15 |
|
14 | 16 | ```bash |
15 | | -npm install |
| 17 | +npm install github-usage-report |
16 | 18 | ``` |
17 | 19 |
|
18 | 20 | ## Usage |
19 | 21 |
|
20 | | -### Reading a Usage Report (Async) |
| 22 | +This library supports both Node.js and web environments through different import paths: |
21 | 23 |
|
22 | | -```typescript |
23 | | -import { readGithubUsageReportFile } from './src/index'; |
| 24 | +### Node.js Usage (with file system access) |
24 | 25 |
|
25 | | -// Basic usage |
26 | | -const report = await readGithubUsageReportFile('path/to/usage-report.csv'); |
27 | | -console.log(`Report covers ${report.days} days from ${report.startDate} to ${report.endDate}`); |
| 26 | +For Node.js applications, you can import the full library which includes file reading capabilities: |
28 | 27 |
|
29 | | -// With line-by-line callback |
30 | | -const report = await readGithubUsageReportFile('path/to/usage-report.csv', (line) => { |
| 28 | +```typescript |
| 29 | +import { readGithubUsageReportFile, readGithubUsageReportFileSync, readModelUsageReportFile, readModelUsageReportFileSync } from 'github-usage-report'; |
| 30 | + |
| 31 | +// GitHub Actions usage reports |
| 32 | +const githubReport = await readGithubUsageReportFile('path/to/usage-report.csv', (line) => { |
31 | 33 | console.log(`Processing: ${line.date} - ${line.product}`); |
32 | 34 | }); |
| 35 | + |
| 36 | +// Model usage reports |
| 37 | +const modelReport = await readModelUsageReportFile('path/to/model-usage.csv', (line) => { |
| 38 | + console.log(`Processing: ${line.user} - ${line.model}`); |
| 39 | +}); |
| 40 | + |
| 41 | +// Sync file reading |
| 42 | +const report = await readGithubUsageReportFileSync('path/to/usage-report.csv'); |
| 43 | +console.log(`Total lines: ${report.lines.length}`); |
33 | 44 | ``` |
34 | 45 |
|
35 | | -### Reading a Usage Report (Sync) |
| 46 | +### Web/Browser Usage (without file system dependencies) |
| 47 | + |
| 48 | +For web applications or environments where you don't need file system access, import from the core module: |
36 | 49 |
|
37 | 50 | ```typescript |
38 | | -import { readGithubUsageReportFileSync } from './src/index'; |
| 51 | +import { readGithubUsageReport, readModelUsageReport } from 'github-usage-report/core'; |
39 | 52 |
|
40 | | -const report = await readGithubUsageReportFileSync('path/to/usage-report.csv'); |
41 | | -console.log(`Total lines: ${report.lines.length}`); |
| 53 | +// Parse GitHub Actions CSV data from string (e.g., from a file upload or API) |
| 54 | +const githubCsvData = `Date,Product,SKU,... |
| 55 | +2023-01-01,Actions,minutes,...`; |
| 56 | + |
| 57 | +const githubReport = await readGithubUsageReport(githubCsvData); |
| 58 | + |
| 59 | +// Parse model usage CSV data from string |
| 60 | +const modelCsvData = `Timestamp,User,Model,Requests Used,Exceeds Monthly Quota,Total Monthly Quota |
| 61 | +2025-06-02T22:34:09Z,bspann,claude-sonnet-4,1.00,false,Unlimited`; |
| 62 | + |
| 63 | +const modelReport = await readModelUsageReport(modelCsvData); |
| 64 | +``` |
| 65 | +console.log(`Report covers ${report.days} days from ${report.startDate} to ${report.endDate}`); |
| 66 | +``` |
| 67 | +
|
| 68 | +### Universal Usage |
| 69 | +
|
| 70 | +You can also import specific functions based on your needs: |
| 71 | +
|
| 72 | +```typescript |
| 73 | +// Import only what you need from core (works everywhere) |
| 74 | +import { readGithubUsageReport, readModelUsageReport, UsageReport, UsageReportLine, ModelUsageReport, ModelUsageReportLine } from 'github-usage-report/core'; |
| 75 | +
|
| 76 | +// Import Node.js specific functions (works only in Node.js) |
| 77 | +import { readGithubUsageReportFile, readGithubUsageReportFileSync, readModelUsageReportFile, readModelUsageReportFileSync } from 'github-usage-report/node'; |
42 | 78 | ``` |
43 | 79 |
|
44 | 80 | ### Report Structure |
45 | 81 |
|
46 | | -The library returns a `UsageReport` object with the following structure: |
| 82 | +The library returns different report objects based on the data type: |
47 | 83 |
|
| 84 | +#### GitHub Usage Report |
48 | 85 | ```typescript |
49 | 86 | { |
50 | 87 | startDate: Date, // First date in the report |
51 | 88 | endDate: Date, // Last date in the report |
52 | 89 | days: number, // Number of days covered |
53 | | - lines: UsageReportLine[] // Array of parsed usage data |
| 90 | + lines: UsageReportLine[] // Array of parsed GitHub usage data |
54 | 91 | } |
55 | 92 | ``` |
56 | 93 |
|
| 94 | +#### Model Usage Report |
| 95 | +```typescript |
| 96 | +{ |
| 97 | + startDate: Date, // First timestamp in the report |
| 98 | + endDate: Date, // Last timestamp in the report |
| 99 | + days: number, // Number of days covered |
| 100 | + lines: ModelUsageReportLine[] // Array of parsed model usage data |
| 101 | +} |
| 102 | +``` |
| 103 | + |
| 104 | +### Model Usage Report Format |
| 105 | + |
| 106 | +The model usage report expects CSV files with this format: |
| 107 | + |
| 108 | +```csv |
| 109 | +Timestamp,User,Model,Requests Used,Exceeds Monthly Quota,Total Monthly Quota |
| 110 | +2025-06-02T22:34:09Z,bspann,claude-sonnet-4,1.00,false,Unlimited |
| 111 | +2025-06-02T22:35:15Z,jdoe,gpt-4,2.50,false,100 |
| 112 | +``` |
| 113 | + |
| 114 | +**Fields:** |
| 115 | +- **Timestamp**: ISO 8601 format (e.g., `2025-06-02T22:34:09Z`) |
| 116 | +- **User**: String username |
| 117 | +- **Model**: String model name |
| 118 | +- **Requests Used**: Numeric value (can be decimal) |
| 119 | +- **Exceeds Monthly Quota**: Boolean (`true` or `false`) |
| 120 | +- **Total Monthly Quota**: String (either "Unlimited" or a numeric value) |
| 121 | + |
57 | 122 | ## Getting Your GitHub Usage Report |
58 | 123 |
|
59 | 124 | To generate a GitHub usage report: |
|
0 commit comments