@codeguide/core 0.0.27 → 0.0.29
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/README.md +50 -41
- package/__tests__/services/codespace/codespace-v2.test.ts +29 -18
- package/__tests__/services/usage/usage-service.test.ts +597 -85
- package/codeguide.ts +6 -0
- package/dist/codeguide.d.ts +3 -1
- package/dist/codeguide.js +2 -0
- package/dist/index.d.ts +4 -3
- package/dist/services/base/base-service.d.ts +21 -0
- package/dist/services/base/base-service.js +114 -0
- package/dist/services/codespace/codespace-service.d.ts +55 -1
- package/dist/services/codespace/codespace-service.js +260 -5
- package/dist/services/codespace/codespace-types.d.ts +193 -13
- package/dist/services/codespace/index.d.ts +1 -1
- package/dist/services/index.d.ts +4 -0
- package/dist/services/index.js +7 -1
- package/dist/services/projects/project-types.d.ts +66 -32
- package/dist/services/repository-analysis/repository-types.d.ts +1 -0
- package/dist/services/starter-kits/index.d.ts +2 -0
- package/dist/services/starter-kits/index.js +20 -0
- package/dist/services/starter-kits/starter-kits-service.d.ts +13 -0
- package/dist/services/starter-kits/starter-kits-service.js +27 -0
- package/dist/services/starter-kits/starter-kits-types.d.ts +34 -0
- package/dist/services/starter-kits/starter-kits-types.js +2 -0
- package/dist/services/tasks/task-service.d.ts +2 -1
- package/dist/services/tasks/task-service.js +8 -0
- package/dist/services/tasks/task-types.d.ts +26 -7
- package/dist/services/usage/usage-service.d.ts +5 -2
- package/dist/services/usage/usage-service.js +58 -9
- package/dist/services/usage/usage-types.d.ts +207 -34
- package/dist/services/users/index.d.ts +2 -0
- package/dist/services/users/index.js +20 -0
- package/dist/services/users/user-service.d.ts +12 -0
- package/dist/services/users/user-service.js +17 -0
- package/dist/services/users/user-types.d.ts +55 -0
- package/dist/services/users/user-types.js +2 -0
- package/docs/.vitepress/README.md +51 -0
- package/docs/.vitepress/config.ts +139 -0
- package/docs/.vitepress/theme/custom.css +80 -0
- package/docs/.vitepress/theme/index.ts +13 -0
- package/docs/.vitepress/tsconfig.json +19 -0
- package/docs/QUICKSTART.md +77 -0
- package/docs/README.md +134 -0
- package/docs/README_SETUP.md +46 -0
- package/docs/authentication.md +351 -0
- package/docs/codeguide-client.md +350 -0
- package/docs/codespace-models.md +1004 -0
- package/docs/codespace-service.md +558 -81
- package/docs/index.md +135 -0
- package/docs/package.json +14 -0
- package/docs/projects-service.md +688 -0
- package/docs/security-keys-service.md +773 -0
- package/docs/starter-kits-service.md +249 -0
- package/docs/task-service.md +955 -0
- package/docs/testsprite_tests/TC001_Homepage_Load_and_Hero_Section_Display.py +70 -0
- package/docs/testsprite_tests/TC002_Sidebar_Navigation_ExpandCollapse_Functionality.py +73 -0
- package/docs/testsprite_tests/TC003_Full_Text_Local_Search_with_Keyboard_Shortcut.py +90 -0
- package/docs/testsprite_tests/TC004_Dark_Mode_Toggle_and_Persistence.py +73 -0
- package/docs/testsprite_tests/TC005_Mobile_Responsiveness_and_Touch_Navigation.py +113 -0
- package/docs/testsprite_tests/TC006_GitHub_Integration_Edit_this_page_Links.py +73 -0
- package/docs/testsprite_tests/TC007_Syntax_Highlighting_and_Code_Copy_Functionality.py +73 -0
- package/docs/testsprite_tests/TC008_Auto_Generated_Table_of_Contents_Accuracy.py +73 -0
- package/docs/testsprite_tests/TC009_SEO_and_Content_Discoverability_Verification.py +73 -0
- package/docs/testsprite_tests/TC010_Accessibility_Compliance_WCAG_AA.py +73 -0
- package/docs/testsprite_tests/TC011_Local_Development_Workflow_Build_and_Hot_Reload.py +74 -0
- package/docs/testsprite_tests/TC012_Performance_Metrics_Compliance.py +73 -0
- package/docs/testsprite_tests/standard_prd.json +122 -0
- package/docs/testsprite_tests/testsprite-mcp-test-report.html +2508 -0
- package/docs/testsprite_tests/testsprite-mcp-test-report.md +273 -0
- package/docs/testsprite_tests/testsprite_frontend_test_plan.json +390 -0
- package/docs/usage-service.md +616 -0
- package/index.ts +11 -3
- package/package.json +16 -2
- package/plans/CODESPACE_LOGS_STREAMING_GUIDE.md +320 -0
- package/plans/CODESPACE_TASK_LOGS_API_COMPLETE_GUIDE.md +821 -0
- package/services/base/base-service.ts +130 -0
- package/services/codespace/codespace-service.ts +347 -8
- package/services/codespace/codespace-types.ts +263 -14
- package/services/codespace/index.ts +16 -1
- package/services/index.ts +4 -0
- package/services/projects/README.md +107 -34
- package/services/projects/project-types.ts +69 -32
- package/services/repository-analysis/repository-types.ts +1 -0
- package/services/starter-kits/index.ts +2 -0
- package/services/starter-kits/starter-kits-service.ts +33 -0
- package/services/starter-kits/starter-kits-types.ts +38 -0
- package/services/tasks/task-service.ts +10 -0
- package/services/tasks/task-types.ts +29 -7
- package/services/usage/usage-service.ts +59 -10
- package/services/usage/usage-types.ts +239 -34
- package/services/users/index.ts +2 -0
- package/services/users/user-service.ts +15 -0
- package/services/users/user-types.ts +59 -0
|
@@ -0,0 +1,616 @@
|
|
|
1
|
+
# Usage Service Documentation
|
|
2
|
+
|
|
3
|
+
## Overview
|
|
4
|
+
|
|
5
|
+
The Usage Service provides methods to track usage, check credits, retrieve authorization information, and access comprehensive dashboard analytics for users.
|
|
6
|
+
|
|
7
|
+
## Methods
|
|
8
|
+
|
|
9
|
+
### `getAuthorization()`
|
|
10
|
+
|
|
11
|
+
Retrieves the authorization status and plan limits for the authenticated user. This endpoint returns different information based on whether the user has an active subscription or is on a free plan.
|
|
12
|
+
|
|
13
|
+
**Returns:** `Promise<AuthorizationResponse>`
|
|
14
|
+
|
|
15
|
+
**Response Structure:**
|
|
16
|
+
|
|
17
|
+
```typescript
|
|
18
|
+
interface AuthorizationResponse {
|
|
19
|
+
success: boolean
|
|
20
|
+
data: AuthorizationData
|
|
21
|
+
message: string
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
interface AuthorizationData {
|
|
25
|
+
user_id: string
|
|
26
|
+
subscription: AuthorizationSubscription | null
|
|
27
|
+
credit_balance: CreditBalance
|
|
28
|
+
has_active_subscription: boolean
|
|
29
|
+
has_previous_subscriptions: boolean
|
|
30
|
+
is_within_credit_limit: boolean
|
|
31
|
+
authorization_level: string
|
|
32
|
+
restrictions: string[]
|
|
33
|
+
can_create_tasks: boolean
|
|
34
|
+
can_analyze_repos: boolean
|
|
35
|
+
can_access_previous_projects: boolean
|
|
36
|
+
plan_limits: PlanLimits
|
|
37
|
+
codespace_task_limit: LimitInfo | null
|
|
38
|
+
}
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
## Free vs. Subscribed Users
|
|
42
|
+
|
|
43
|
+
The `/usage/authorization` endpoint returns different data structures depending on whether the user has an active subscription.
|
|
44
|
+
|
|
45
|
+
### Free Users
|
|
46
|
+
|
|
47
|
+
For users without an active subscription:
|
|
48
|
+
|
|
49
|
+
- **`subscription`**: `null`
|
|
50
|
+
- **`has_active_subscription`**: `false`
|
|
51
|
+
- **`authorization_level`**: `"free"`
|
|
52
|
+
- **`codespace_task_limit`**: Contains limit information (e.g., `limit: 2`, `remaining: 2`)
|
|
53
|
+
- **`plan_limits.plan_type`**: `"free"`
|
|
54
|
+
- **`plan_limits.limits.codespace_tasks`**: Has specific limits (e.g., 2 lifetime tasks)
|
|
55
|
+
- **`can_access_previous_projects`**: `false`
|
|
56
|
+
|
|
57
|
+
**Example Free User Response:**
|
|
58
|
+
|
|
59
|
+
```json
|
|
60
|
+
{
|
|
61
|
+
"success": true,
|
|
62
|
+
"data": {
|
|
63
|
+
"user_id": "user_32CKVjVlcRfh4HAqpVckgILey0Z",
|
|
64
|
+
"subscription": null,
|
|
65
|
+
"credit_balance": {
|
|
66
|
+
"total_allotted": 500,
|
|
67
|
+
"total_consumed": 0,
|
|
68
|
+
"remaining_credits": 500,
|
|
69
|
+
"is_over_limit": false,
|
|
70
|
+
"utilization_percentage": 0.0,
|
|
71
|
+
"billing_cycle_start": "2025-11-03",
|
|
72
|
+
"billing_cycle_end": "2025-11-10"
|
|
73
|
+
},
|
|
74
|
+
"has_active_subscription": false,
|
|
75
|
+
"has_previous_subscriptions": false,
|
|
76
|
+
"is_within_credit_limit": true,
|
|
77
|
+
"authorization_level": "free",
|
|
78
|
+
"restrictions": [],
|
|
79
|
+
"can_create_tasks": true,
|
|
80
|
+
"can_analyze_repos": true,
|
|
81
|
+
"can_access_previous_projects": false,
|
|
82
|
+
"plan_limits": {
|
|
83
|
+
"plan_type": "free",
|
|
84
|
+
"limits": {
|
|
85
|
+
"codespace_tasks": {
|
|
86
|
+
"allowed": true,
|
|
87
|
+
"current_usage": 0,
|
|
88
|
+
"limit": 2,
|
|
89
|
+
"remaining": 2,
|
|
90
|
+
"period_type": "lifetime",
|
|
91
|
+
"period_start": null,
|
|
92
|
+
"period_end": null,
|
|
93
|
+
"message": "Can create 2 more codespace tasks. 2 codespace tasks (lifetime limit)",
|
|
94
|
+
"is_unlimited": false
|
|
95
|
+
},
|
|
96
|
+
"api_calls": {
|
|
97
|
+
"limit": 500,
|
|
98
|
+
"period": "7_days",
|
|
99
|
+
"description": "500 API credits (valid for 7 days)",
|
|
100
|
+
"is_unlimited": false
|
|
101
|
+
},
|
|
102
|
+
"storage_gb": {
|
|
103
|
+
"limit": 1,
|
|
104
|
+
"period": "lifetime",
|
|
105
|
+
"description": "1 GB storage",
|
|
106
|
+
"is_unlimited": false
|
|
107
|
+
},
|
|
108
|
+
"projects": {
|
|
109
|
+
"limit": 3,
|
|
110
|
+
"period": "lifetime",
|
|
111
|
+
"description": "3 projects maximum",
|
|
112
|
+
"is_unlimited": false
|
|
113
|
+
},
|
|
114
|
+
"collaborators": {
|
|
115
|
+
"limit": 0,
|
|
116
|
+
"period": "lifetime",
|
|
117
|
+
"description": "No team collaboration",
|
|
118
|
+
"is_unlimited": false
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
},
|
|
122
|
+
"codespace_task_limit": {
|
|
123
|
+
"allowed": true,
|
|
124
|
+
"current_usage": 0,
|
|
125
|
+
"limit": 2,
|
|
126
|
+
"remaining": 2,
|
|
127
|
+
"period_type": "lifetime",
|
|
128
|
+
"period_start": null,
|
|
129
|
+
"period_end": null,
|
|
130
|
+
"message": "Can create 2 more codespace tasks. 2 codespace tasks (lifetime limit)",
|
|
131
|
+
"is_unlimited": false
|
|
132
|
+
}
|
|
133
|
+
},
|
|
134
|
+
"message": "Authorization status retrieved successfully"
|
|
135
|
+
}
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
### Subscribed Users
|
|
139
|
+
|
|
140
|
+
For users with an active subscription:
|
|
141
|
+
|
|
142
|
+
- **`subscription`**: Contains detailed subscription information:
|
|
143
|
+
- `id`: Subscription ID
|
|
144
|
+
- `status`: Subscription status (e.g., `"active"`)
|
|
145
|
+
- `interval`: Billing interval (e.g., `"month"`, `"year"`)
|
|
146
|
+
- `current_period_start`: ISO 8601 timestamp
|
|
147
|
+
- `current_period_end`: ISO 8601 timestamp
|
|
148
|
+
- `price_id`: Stripe price ID
|
|
149
|
+
- `product_name`: Product name (can be `null`)
|
|
150
|
+
- `plan_name`: Plan name (e.g., `"Monthly Plan"`)
|
|
151
|
+
- **`has_active_subscription`**: `true`
|
|
152
|
+
- **`authorization_level`**: Plan tier (e.g., `"basic"`, `"pro"`)
|
|
153
|
+
- **`codespace_task_limit`**: `null` (when unlimited) or limit information
|
|
154
|
+
- **`plan_limits.plan_type`**: Plan tier name
|
|
155
|
+
- **`plan_limits.limits.codespace_tasks`**: May have `limit: -1` and `is_unlimited: true` for unlimited plans
|
|
156
|
+
- **`can_access_previous_projects`**: `true`
|
|
157
|
+
|
|
158
|
+
**Example Subscribed User Response:**
|
|
159
|
+
|
|
160
|
+
```json
|
|
161
|
+
{
|
|
162
|
+
"success": true,
|
|
163
|
+
"data": {
|
|
164
|
+
"user_id": "user_2qaB6nlVH3R9QXhQZpt1nmVDymN",
|
|
165
|
+
"subscription": {
|
|
166
|
+
"id": "sub_1RbggdFb0vIg7N8EFOPTEhDh",
|
|
167
|
+
"status": "active",
|
|
168
|
+
"interval": "month",
|
|
169
|
+
"current_period_start": "2025-10-19T11:31:19+00:00",
|
|
170
|
+
"current_period_end": "2025-11-19T11:31:19+00:00",
|
|
171
|
+
"price_id": "price_1QYtmGFb0vIg7N8E71nw8g27",
|
|
172
|
+
"product_name": null,
|
|
173
|
+
"plan_name": "Monthly Plan"
|
|
174
|
+
},
|
|
175
|
+
"credit_balance": {
|
|
176
|
+
"total_allotted": 5000,
|
|
177
|
+
"total_consumed": 658,
|
|
178
|
+
"remaining_credits": 4342,
|
|
179
|
+
"is_over_limit": false,
|
|
180
|
+
"utilization_percentage": 13.16,
|
|
181
|
+
"billing_cycle_start": "2025-10-19",
|
|
182
|
+
"billing_cycle_end": "2025-11-19"
|
|
183
|
+
},
|
|
184
|
+
"has_active_subscription": true,
|
|
185
|
+
"has_previous_subscriptions": true,
|
|
186
|
+
"is_within_credit_limit": true,
|
|
187
|
+
"authorization_level": "basic",
|
|
188
|
+
"restrictions": [],
|
|
189
|
+
"can_create_tasks": true,
|
|
190
|
+
"can_analyze_repos": true,
|
|
191
|
+
"can_access_previous_projects": true,
|
|
192
|
+
"plan_limits": {
|
|
193
|
+
"plan_type": "basic",
|
|
194
|
+
"limits": {
|
|
195
|
+
"codespace_tasks": {
|
|
196
|
+
"allowed": true,
|
|
197
|
+
"current_usage": 0,
|
|
198
|
+
"limit": -1,
|
|
199
|
+
"remaining": -1,
|
|
200
|
+
"period_type": "monthly",
|
|
201
|
+
"period_start": null,
|
|
202
|
+
"period_end": null,
|
|
203
|
+
"message": "Unlimited codespace tasks",
|
|
204
|
+
"is_unlimited": true
|
|
205
|
+
},
|
|
206
|
+
"api_calls": {
|
|
207
|
+
"limit": 5000,
|
|
208
|
+
"period": "monthly",
|
|
209
|
+
"description": "5000 API credits per month",
|
|
210
|
+
"is_unlimited": false
|
|
211
|
+
},
|
|
212
|
+
"storage_gb": {
|
|
213
|
+
"limit": 10,
|
|
214
|
+
"period": "lifetime",
|
|
215
|
+
"description": "10 GB storage",
|
|
216
|
+
"is_unlimited": false
|
|
217
|
+
},
|
|
218
|
+
"projects": {
|
|
219
|
+
"limit": 20,
|
|
220
|
+
"period": "lifetime",
|
|
221
|
+
"description": "20 projects maximum",
|
|
222
|
+
"is_unlimited": false
|
|
223
|
+
},
|
|
224
|
+
"collaborators": {
|
|
225
|
+
"limit": 3,
|
|
226
|
+
"period": "monthly",
|
|
227
|
+
"description": "3 team collaborators",
|
|
228
|
+
"is_unlimited": false
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
},
|
|
232
|
+
"codespace_task_limit": null
|
|
233
|
+
},
|
|
234
|
+
"message": "Authorization status retrieved successfully"
|
|
235
|
+
}
|
|
236
|
+
```
|
|
237
|
+
|
|
238
|
+
## Key Differences Summary
|
|
239
|
+
|
|
240
|
+
| Feature | Free Users | Subscribed Users |
|
|
241
|
+
| ------------------------------------------------- | --------------------------- | -------------------------------------- |
|
|
242
|
+
| `subscription` | `null` | `AuthorizationSubscription` object |
|
|
243
|
+
| `has_active_subscription` | `false` | `true` |
|
|
244
|
+
| `authorization_level` | `"free"` | Plan tier (e.g., `"basic"`, `"pro"`) |
|
|
245
|
+
| `codespace_task_limit` | `LimitInfo` object | `null` (when unlimited) or `LimitInfo` |
|
|
246
|
+
| `plan_limits.limits.codespace_tasks.limit` | Positive number (e.g., `2`) | `-1` for unlimited |
|
|
247
|
+
| `plan_limits.limits.codespace_tasks.is_unlimited` | `false` | `true` for unlimited plans |
|
|
248
|
+
| `can_access_previous_projects` | `false` | `true` |
|
|
249
|
+
| Credit limits | Lower (e.g., 500) | Higher (e.g., 5000+) |
|
|
250
|
+
| Billing cycle | 7 days | Monthly/Yearly |
|
|
251
|
+
|
|
252
|
+
## Usage Example
|
|
253
|
+
|
|
254
|
+
```typescript
|
|
255
|
+
import { CodeGuide } from '@codeguide/core'
|
|
256
|
+
|
|
257
|
+
const codeguide = new CodeGuide({
|
|
258
|
+
baseUrl: 'https://api.codeguide.app',
|
|
259
|
+
databaseApiKey: 'sk_your_key',
|
|
260
|
+
})
|
|
261
|
+
|
|
262
|
+
// Get authorization status
|
|
263
|
+
const auth = await codeguide.usage.getAuthorization()
|
|
264
|
+
|
|
265
|
+
if (auth.data.has_active_subscription) {
|
|
266
|
+
console.log(`User has ${auth.data.plan_limits.plan_type} subscription`)
|
|
267
|
+
console.log(`Subscription: ${auth.data.subscription?.plan_name}`)
|
|
268
|
+
|
|
269
|
+
if (auth.data.codespace_task_limit === null) {
|
|
270
|
+
console.log('Unlimited codespace tasks')
|
|
271
|
+
}
|
|
272
|
+
} else {
|
|
273
|
+
console.log('Free user')
|
|
274
|
+
console.log(`Remaining codespace tasks: ${auth.data.codespace_task_limit?.remaining}`)
|
|
275
|
+
}
|
|
276
|
+
```
|
|
277
|
+
|
|
278
|
+
## Type Definitions
|
|
279
|
+
|
|
280
|
+
```typescript
|
|
281
|
+
interface AuthorizationSubscription {
|
|
282
|
+
id: string
|
|
283
|
+
status: string
|
|
284
|
+
interval: string
|
|
285
|
+
current_period_start: string
|
|
286
|
+
current_period_end: string
|
|
287
|
+
price_id: string
|
|
288
|
+
product_name: string | null
|
|
289
|
+
plan_name: string
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
interface CreditBalance {
|
|
293
|
+
total_allotted: number
|
|
294
|
+
total_consumed: number
|
|
295
|
+
remaining_credits: number
|
|
296
|
+
is_over_limit: boolean
|
|
297
|
+
utilization_percentage: number
|
|
298
|
+
billing_cycle_start: string
|
|
299
|
+
billing_cycle_end: string
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
interface LimitInfo {
|
|
303
|
+
allowed?: boolean
|
|
304
|
+
current_usage?: number
|
|
305
|
+
limit: number // -1 for unlimited
|
|
306
|
+
remaining?: number // -1 for unlimited
|
|
307
|
+
period_type?: string
|
|
308
|
+
period_start?: string | null
|
|
309
|
+
period_end?: string | null
|
|
310
|
+
message?: string
|
|
311
|
+
is_unlimited: boolean
|
|
312
|
+
period?: string
|
|
313
|
+
description?: string
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
interface PlanLimits {
|
|
317
|
+
plan_type: string
|
|
318
|
+
limits: {
|
|
319
|
+
codespace_tasks: LimitInfo
|
|
320
|
+
api_calls: LimitInfo
|
|
321
|
+
storage_gb: LimitInfo
|
|
322
|
+
projects: LimitInfo
|
|
323
|
+
collaborators: LimitInfo
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
```
|
|
327
|
+
|
|
328
|
+
# Dashboard Analytics
|
|
329
|
+
|
|
330
|
+
The Usage Service also provides comprehensive dashboard analytics endpoints for visualizing usage patterns, costs, and trends. All dashboard endpoints follow the `/usage/dashboard/*` pattern.
|
|
331
|
+
|
|
332
|
+
## `getDashboardAnalytics(params?)`
|
|
333
|
+
|
|
334
|
+
Retrieves comprehensive analytics data with daily breakdowns, trends, and top services for dashboard visualization.
|
|
335
|
+
|
|
336
|
+
**Endpoint:** `GET /usage/dashboard/analytics`
|
|
337
|
+
|
|
338
|
+
**Parameters:** `DashboardAnalyticsRequest` (optional)
|
|
339
|
+
```typescript
|
|
340
|
+
interface DashboardAnalyticsRequest {
|
|
341
|
+
period?: "7d" | "1w" | "1m" | "3m" // Time period
|
|
342
|
+
start_date?: string // Custom start date (YYYY-MM-DD)
|
|
343
|
+
end_date?: string // Custom end date (YYYY-MM-DD)
|
|
344
|
+
service_type?: "docs" | "chat" | "codespace_task" | "api"
|
|
345
|
+
}
|
|
346
|
+
```
|
|
347
|
+
|
|
348
|
+
**Returns:** `Promise<DashboardAnalyticsResponse>`
|
|
349
|
+
|
|
350
|
+
**Response Structure:**
|
|
351
|
+
```typescript
|
|
352
|
+
interface DashboardAnalyticsResponse {
|
|
353
|
+
status: string
|
|
354
|
+
data: {
|
|
355
|
+
period: {
|
|
356
|
+
start: string
|
|
357
|
+
end: string
|
|
358
|
+
label: string
|
|
359
|
+
}
|
|
360
|
+
daily_usage: Array<{
|
|
361
|
+
date: string
|
|
362
|
+
credits_consumed: number
|
|
363
|
+
cost_usd: number
|
|
364
|
+
requests_count: number
|
|
365
|
+
average_credits_per_request: number
|
|
366
|
+
}>
|
|
367
|
+
totals: {
|
|
368
|
+
credits_consumed: number
|
|
369
|
+
cost_usd: number
|
|
370
|
+
requests_count: number
|
|
371
|
+
}
|
|
372
|
+
averages: {
|
|
373
|
+
daily_credits: number
|
|
374
|
+
daily_requests: number
|
|
375
|
+
}
|
|
376
|
+
trends: {
|
|
377
|
+
credits_consumed: number // Percentage change
|
|
378
|
+
requests_count: number // Percentage change
|
|
379
|
+
}
|
|
380
|
+
top_services: Array<{
|
|
381
|
+
service_type: string
|
|
382
|
+
credits_consumed: number
|
|
383
|
+
requests_count: number
|
|
384
|
+
}>
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
```
|
|
388
|
+
|
|
389
|
+
**Example Usage:**
|
|
390
|
+
```typescript
|
|
391
|
+
// Get last 7 days analytics
|
|
392
|
+
const analytics = await codeguide.usage.getDashboardAnalytics({ period: '7d' })
|
|
393
|
+
|
|
394
|
+
// Get custom date range for docs service
|
|
395
|
+
const docsAnalytics = await codeguide.usage.getDashboardAnalytics({
|
|
396
|
+
start_date: '2024-01-01',
|
|
397
|
+
end_date: '2024-01-31',
|
|
398
|
+
service_type: 'docs'
|
|
399
|
+
})
|
|
400
|
+
```
|
|
401
|
+
|
|
402
|
+
## `getUsageDetails(params?)`
|
|
403
|
+
|
|
404
|
+
Retrieves paginated individual usage records with filtering and sorting capabilities for detailed analysis.
|
|
405
|
+
|
|
406
|
+
**Endpoint:** `GET /usage/dashboard/details`
|
|
407
|
+
|
|
408
|
+
**Parameters:** `UsageDetailsRequest` (optional)
|
|
409
|
+
```typescript
|
|
410
|
+
interface UsageDetailsRequest {
|
|
411
|
+
period?: "7d" | "1w" | "1m" | "3m"
|
|
412
|
+
start_date?: string
|
|
413
|
+
end_date?: string
|
|
414
|
+
service_type?: "docs" | "chat" | "codespace_task" | "api"
|
|
415
|
+
page?: number // Default: 1
|
|
416
|
+
page_size?: number // Default: 50, Max: 100
|
|
417
|
+
sort_by?: "created_at" | "credits_consumed" | "cost_amount" // Default: "created_at"
|
|
418
|
+
sort_order?: "asc" | "desc" // Default: "desc"
|
|
419
|
+
}
|
|
420
|
+
```
|
|
421
|
+
|
|
422
|
+
**Returns:** `Promise<UsageDetailsResponse>`
|
|
423
|
+
|
|
424
|
+
**Response Structure:**
|
|
425
|
+
```typescript
|
|
426
|
+
interface UsageDetailsResponse {
|
|
427
|
+
status: string
|
|
428
|
+
data: Array<{
|
|
429
|
+
id: string
|
|
430
|
+
created_at: string
|
|
431
|
+
service_type: string
|
|
432
|
+
model_name: string
|
|
433
|
+
usage_type: string
|
|
434
|
+
units_consumed: number
|
|
435
|
+
credits_consumed: number
|
|
436
|
+
cost_amount: number | null
|
|
437
|
+
}>
|
|
438
|
+
pagination: {
|
|
439
|
+
page: number
|
|
440
|
+
page_size: number
|
|
441
|
+
total_count: number
|
|
442
|
+
total_pages: number
|
|
443
|
+
has_next: boolean
|
|
444
|
+
has_prev: boolean
|
|
445
|
+
}
|
|
446
|
+
filters: {
|
|
447
|
+
period: string | null
|
|
448
|
+
start_date: string | null
|
|
449
|
+
end_date: string | null
|
|
450
|
+
service_type: string | null
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
```
|
|
454
|
+
|
|
455
|
+
**Example Usage:**
|
|
456
|
+
```typescript
|
|
457
|
+
// Get first page of usage details for last 7 days
|
|
458
|
+
const details = await codeguide.usage.getUsageDetails({ period: '7d' })
|
|
459
|
+
|
|
460
|
+
// Get page 2 with custom sorting
|
|
461
|
+
const sortedDetails = await codeguide.usage.getUsageDetails({
|
|
462
|
+
period: '1m',
|
|
463
|
+
page: 2,
|
|
464
|
+
page_size: 25,
|
|
465
|
+
sort_by: 'credits_consumed',
|
|
466
|
+
sort_order: 'desc'
|
|
467
|
+
})
|
|
468
|
+
```
|
|
469
|
+
|
|
470
|
+
## `getUsageSummary(params?)`
|
|
471
|
+
|
|
472
|
+
Retrieves quick overview statistics for dashboard widgets, including current vs previous period comparisons and billing cycle information.
|
|
473
|
+
|
|
474
|
+
**Endpoint:** `GET /usage/dashboard/summary`
|
|
475
|
+
|
|
476
|
+
**Parameters:** `UsageSummaryRequest` (optional)
|
|
477
|
+
```typescript
|
|
478
|
+
interface UsageSummaryRequest {
|
|
479
|
+
period?: "7d" | "1w" | "1m" | "3m"
|
|
480
|
+
start_date?: string
|
|
481
|
+
end_date?: string
|
|
482
|
+
}
|
|
483
|
+
```
|
|
484
|
+
|
|
485
|
+
**Returns:** `Promise<UsageSummaryResponse>`
|
|
486
|
+
|
|
487
|
+
**Response Structure:**
|
|
488
|
+
```typescript
|
|
489
|
+
interface UsageSummaryResponse {
|
|
490
|
+
status: string
|
|
491
|
+
data: {
|
|
492
|
+
current_period: {
|
|
493
|
+
credits_consumed: number
|
|
494
|
+
cost_usd: number
|
|
495
|
+
requests_count: number
|
|
496
|
+
}
|
|
497
|
+
previous_period: {
|
|
498
|
+
credits_consumed: number
|
|
499
|
+
cost_usd: number
|
|
500
|
+
requests_count: number
|
|
501
|
+
}
|
|
502
|
+
billing_cycle: {
|
|
503
|
+
total_allotted: number
|
|
504
|
+
total_consumed: number
|
|
505
|
+
remaining_credits: number
|
|
506
|
+
}
|
|
507
|
+
utilization_percentage: number
|
|
508
|
+
remaining_credits: number
|
|
509
|
+
daily_average: number
|
|
510
|
+
projected_monthly: number
|
|
511
|
+
}
|
|
512
|
+
}
|
|
513
|
+
```
|
|
514
|
+
|
|
515
|
+
**Example Usage:**
|
|
516
|
+
```typescript
|
|
517
|
+
// Get summary for last 7 days
|
|
518
|
+
const summary = await codeguide.usage.getUsageSummary({ period: '7d' })
|
|
519
|
+
|
|
520
|
+
// Get monthly summary
|
|
521
|
+
const monthlySummary = await codeguide.usage.getUsageSummary({ period: '1m' })
|
|
522
|
+
```
|
|
523
|
+
|
|
524
|
+
## `getServiceBreakdown(params?)`
|
|
525
|
+
|
|
526
|
+
Retrieves usage breakdown by service type for pie charts and comparative analysis.
|
|
527
|
+
|
|
528
|
+
**Endpoint:** `GET /usage/dashboard/services`
|
|
529
|
+
|
|
530
|
+
**Parameters:** `ServiceBreakdownRequest` (optional)
|
|
531
|
+
```typescript
|
|
532
|
+
interface ServiceBreakdownRequest {
|
|
533
|
+
period?: "7d" | "1w" | "1m" | "3m"
|
|
534
|
+
start_date?: string
|
|
535
|
+
end_date?: string
|
|
536
|
+
}
|
|
537
|
+
```
|
|
538
|
+
|
|
539
|
+
**Returns:** `Promise<ServiceBreakdownResponse>`
|
|
540
|
+
|
|
541
|
+
**Response Structure:**
|
|
542
|
+
```typescript
|
|
543
|
+
interface ServiceBreakdownResponse {
|
|
544
|
+
status: string
|
|
545
|
+
data: {
|
|
546
|
+
period: {
|
|
547
|
+
start: string
|
|
548
|
+
end: string
|
|
549
|
+
label: string
|
|
550
|
+
}
|
|
551
|
+
services: Array<{
|
|
552
|
+
service_type: string
|
|
553
|
+
credits_consumed: number
|
|
554
|
+
percentage: number
|
|
555
|
+
cost_usd: number
|
|
556
|
+
requests_count: number
|
|
557
|
+
trend: number // Percentage change
|
|
558
|
+
}>
|
|
559
|
+
total_credits: number
|
|
560
|
+
total_cost: number
|
|
561
|
+
}
|
|
562
|
+
}
|
|
563
|
+
```
|
|
564
|
+
|
|
565
|
+
**Example Usage:**
|
|
566
|
+
```typescript
|
|
567
|
+
// Get service breakdown for last 7 days
|
|
568
|
+
const breakdown = await codeguide.usage.getServiceBreakdown({ period: '7d' })
|
|
569
|
+
|
|
570
|
+
// Get service breakdown for custom date range
|
|
571
|
+
const customBreakdown = await codeguide.usage.getServiceBreakdown({
|
|
572
|
+
start_date: '2024-01-01',
|
|
573
|
+
end_date: '2024-01-31'
|
|
574
|
+
})
|
|
575
|
+
```
|
|
576
|
+
|
|
577
|
+
## Complete Dashboard Example
|
|
578
|
+
|
|
579
|
+
```typescript
|
|
580
|
+
import { CodeGuide } from '@codeguide/core'
|
|
581
|
+
|
|
582
|
+
const codeguide = new CodeGuide({
|
|
583
|
+
baseUrl: 'https://api.codeguide.app',
|
|
584
|
+
databaseApiKey: 'sk_your_key',
|
|
585
|
+
})
|
|
586
|
+
|
|
587
|
+
// Get comprehensive dashboard data
|
|
588
|
+
async function loadDashboardData() {
|
|
589
|
+
try {
|
|
590
|
+
// Main analytics with trends
|
|
591
|
+
const analytics = await codeguide.usage.getDashboardAnalytics({ period: '7d' })
|
|
592
|
+
|
|
593
|
+
// Quick overview for widgets
|
|
594
|
+
const summary = await codeguide.usage.getUsageSummary({ period: '7d' })
|
|
595
|
+
|
|
596
|
+
// Service breakdown for pie charts
|
|
597
|
+
const services = await codeguide.usage.getServiceBreakdown({ period: '7d' })
|
|
598
|
+
|
|
599
|
+
// Detailed records for table
|
|
600
|
+
const details = await codeguide.usage.getUsageDetails({
|
|
601
|
+
period: '7d',
|
|
602
|
+
page_size: 100,
|
|
603
|
+
sort_by: 'credits_consumed',
|
|
604
|
+
sort_order: 'desc'
|
|
605
|
+
})
|
|
606
|
+
|
|
607
|
+
console.log('Dashboard Analytics:', analytics.data)
|
|
608
|
+
console.log('Summary Stats:', summary.data)
|
|
609
|
+
console.log('Service Breakdown:', services.data)
|
|
610
|
+
console.log('Usage Details:', details.data)
|
|
611
|
+
|
|
612
|
+
} catch (error) {
|
|
613
|
+
console.error('Failed to load dashboard data:', error)
|
|
614
|
+
}
|
|
615
|
+
}
|
|
616
|
+
```
|
package/index.ts
CHANGED
|
@@ -18,7 +18,7 @@ export type {
|
|
|
18
18
|
ProjectRepository,
|
|
19
19
|
GetProjectsRequest,
|
|
20
20
|
PaginatedProjectsRequest,
|
|
21
|
-
PaginatedProjectsResponse
|
|
21
|
+
PaginatedProjectsResponse,
|
|
22
22
|
} from './services/projects/project-types'
|
|
23
23
|
export type {
|
|
24
24
|
CreateCodespaceTaskRequestV2 as CreateCodespaceTaskRequest,
|
|
@@ -30,7 +30,7 @@ export type {
|
|
|
30
30
|
GetCodespaceTaskResponse,
|
|
31
31
|
CodespaceTaskData,
|
|
32
32
|
TechnicalDocument,
|
|
33
|
-
GetProjectTasksByCodespaceResponse
|
|
33
|
+
GetProjectTasksByCodespaceResponse,
|
|
34
34
|
} from './services/codespace/codespace-types'
|
|
35
35
|
|
|
36
36
|
// Export commonly used external tokens types for convenience
|
|
@@ -44,5 +44,13 @@ export type {
|
|
|
44
44
|
FindBestMatchRequest,
|
|
45
45
|
FindBestMatchResponse,
|
|
46
46
|
Platform,
|
|
47
|
-
TokenType
|
|
47
|
+
TokenType,
|
|
48
48
|
} from './services/external-tokens/external-tokens-types'
|
|
49
|
+
|
|
50
|
+
// Export commonly used starter kits types for convenience
|
|
51
|
+
export type {
|
|
52
|
+
StarterKit,
|
|
53
|
+
StarterKitMetadata,
|
|
54
|
+
GetStarterKitsRequest,
|
|
55
|
+
GetStarterKitsResponse,
|
|
56
|
+
} from './services/starter-kits/starter-kits-types'
|
package/package.json
CHANGED
|
@@ -1,14 +1,28 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@codeguide/core",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.29",
|
|
4
4
|
"description": "Core package for code guidance with programmatic API",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"default": "./dist/index.js"
|
|
11
|
+
},
|
|
12
|
+
"./dist/services/starter-kits/starter-kits-types": {
|
|
13
|
+
"types": "./dist/services/starter-kits/starter-kits-types.d.ts"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
7
16
|
"scripts": {
|
|
8
17
|
"build": "tsc",
|
|
9
18
|
"test": "jest --config=jest.config.json",
|
|
10
19
|
"test:watch": "jest --config=jest.config.json --watch",
|
|
11
|
-
"test:coverage": "jest --config=jest.config.json --coverage"
|
|
20
|
+
"test:coverage": "jest --config=jest.config.json --coverage",
|
|
21
|
+
"docs:dev": "cd docs && npm run dev",
|
|
22
|
+
"docs:build": "cd docs && npm run build",
|
|
23
|
+
"docs:preview": "cd docs && npm run preview",
|
|
24
|
+
"docs:install": "cd docs && npm install",
|
|
25
|
+
"docs:setup": "npm run docs:install"
|
|
12
26
|
},
|
|
13
27
|
"keywords": [
|
|
14
28
|
"api",
|