@codeguide/core 0.0.28 → 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/__tests__/services/usage/usage-service.test.ts +442 -83
- package/codeguide.ts +3 -0
- package/dist/codeguide.d.ts +2 -1
- package/dist/codeguide.js +1 -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 +257 -0
- package/dist/services/codespace/codespace-types.d.ts +192 -12
- package/dist/services/codespace/index.d.ts +1 -1
- package/dist/services/index.d.ts +2 -0
- package/dist/services/index.js +4 -1
- package/dist/services/projects/project-types.d.ts +66 -32
- 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 +150 -26
- 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 +444 -0
- 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 +291 -1
- 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 +337 -0
- package/services/codespace/codespace-types.ts +262 -13
- package/services/codespace/index.ts +16 -1
- package/services/index.ts +2 -0
- package/services/projects/README.md +107 -34
- package/services/projects/project-types.ts +69 -32
- 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 +178 -27
|
@@ -6,12 +6,19 @@ import {
|
|
|
6
6
|
TrackUsageRequest,
|
|
7
7
|
TrackUsageResponse,
|
|
8
8
|
CreditBalanceResponse,
|
|
9
|
+
CreditBalanceData,
|
|
9
10
|
CreditCheckResponse,
|
|
10
11
|
UsageSummaryResponse,
|
|
11
12
|
AuthorizationResponse,
|
|
12
13
|
CalculateUsageResponse,
|
|
13
14
|
TrackCodespaceUsageResponse,
|
|
14
15
|
CodespaceTaskUsageResponse,
|
|
16
|
+
DashboardAnalyticsRequest,
|
|
17
|
+
DashboardAnalyticsResponse,
|
|
18
|
+
UsageDetailsRequest,
|
|
19
|
+
UsageDetailsResponse,
|
|
20
|
+
ServiceBreakdownRequest,
|
|
21
|
+
ServiceBreakdownResponse,
|
|
15
22
|
} from '../../../services/usage/usage-types'
|
|
16
23
|
|
|
17
24
|
describe('UsageService', () => {
|
|
@@ -20,12 +27,12 @@ describe('UsageService', () => {
|
|
|
20
27
|
let config: APIServiceConfig
|
|
21
28
|
|
|
22
29
|
beforeEach(() => {
|
|
23
|
-
mockAxios = new MockAdapter(axios)
|
|
24
30
|
config = {
|
|
25
31
|
baseUrl: 'https://api.codeguide.app',
|
|
26
32
|
databaseApiKey: 'sk_test123',
|
|
27
33
|
}
|
|
28
34
|
usageService = new UsageService(config)
|
|
35
|
+
mockAxios = new MockAdapter((usageService as any).client)
|
|
29
36
|
})
|
|
30
37
|
|
|
31
38
|
afterEach(() => {
|
|
@@ -49,7 +56,7 @@ describe('UsageService', () => {
|
|
|
49
56
|
message: 'Usage tracked successfully',
|
|
50
57
|
}
|
|
51
58
|
|
|
52
|
-
mockAxios.onPost('/
|
|
59
|
+
mockAxios.onPost('/usage/track', request).reply(200, response)
|
|
53
60
|
|
|
54
61
|
const result = await usageService.trackUsage(request)
|
|
55
62
|
|
|
@@ -63,7 +70,7 @@ describe('UsageService', () => {
|
|
|
63
70
|
output_tokens: 50,
|
|
64
71
|
}
|
|
65
72
|
|
|
66
|
-
mockAxios.onPost('/
|
|
73
|
+
mockAxios.onPost('/usage/track', request).reply(400, {
|
|
67
74
|
detail: 'Invalid request',
|
|
68
75
|
})
|
|
69
76
|
|
|
@@ -73,7 +80,7 @@ describe('UsageService', () => {
|
|
|
73
80
|
|
|
74
81
|
describe('getCreditBalance', () => {
|
|
75
82
|
it('should get credit balance successfully', async () => {
|
|
76
|
-
const
|
|
83
|
+
const creditBalanceData: CreditBalanceData = {
|
|
77
84
|
user_id: 'user123',
|
|
78
85
|
total_consumed: 10.5,
|
|
79
86
|
total_allotted: 100,
|
|
@@ -87,7 +94,11 @@ describe('UsageService', () => {
|
|
|
87
94
|
},
|
|
88
95
|
}
|
|
89
96
|
|
|
90
|
-
|
|
97
|
+
const response: CreditBalanceResponse = {
|
|
98
|
+
data: creditBalanceData,
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
mockAxios.onGet('/usage/credit-balance').reply(200, response)
|
|
91
102
|
|
|
92
103
|
const result = await usageService.getCreditBalance()
|
|
93
104
|
|
|
@@ -113,7 +124,7 @@ describe('UsageService', () => {
|
|
|
113
124
|
|
|
114
125
|
mockAxios
|
|
115
126
|
.onGet(
|
|
116
|
-
'/
|
|
127
|
+
'/usage/credit-check?model_key=gpt-4&input_tokens=100&output_tokens=50&call_seconds=2'
|
|
117
128
|
)
|
|
118
129
|
.reply(200, response)
|
|
119
130
|
|
|
@@ -136,7 +147,7 @@ describe('UsageService', () => {
|
|
|
136
147
|
}
|
|
137
148
|
|
|
138
149
|
mockAxios
|
|
139
|
-
.onGet('/
|
|
150
|
+
.onGet('/usage/credit-check?model_key=gpt-4&input_tokens=100')
|
|
140
151
|
.reply(200, response)
|
|
141
152
|
|
|
142
153
|
const result = await usageService.checkCredits(params)
|
|
@@ -145,73 +156,7 @@ describe('UsageService', () => {
|
|
|
145
156
|
})
|
|
146
157
|
})
|
|
147
158
|
|
|
148
|
-
|
|
149
|
-
it('should get usage summary with date range', async () => {
|
|
150
|
-
const params = {
|
|
151
|
-
start_date: '2024-01-01',
|
|
152
|
-
end_date: '2024-01-31',
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
const response: UsageSummaryResponse = {
|
|
156
|
-
user_id: 'user123',
|
|
157
|
-
period: {
|
|
158
|
-
start_date: '2024-01-01',
|
|
159
|
-
end_date: '2024-01-31',
|
|
160
|
-
},
|
|
161
|
-
usage_summary: {
|
|
162
|
-
total_credits_used: 15.5,
|
|
163
|
-
total_calls: 42,
|
|
164
|
-
model_breakdown: {
|
|
165
|
-
'gpt-4': { calls: 20, credits: 12.0 },
|
|
166
|
-
'gpt-3.5': { calls: 22, credits: 3.5 },
|
|
167
|
-
},
|
|
168
|
-
daily_usage: [
|
|
169
|
-
{ date: '2024-01-01', credits_used: 1.5, calls: 5 },
|
|
170
|
-
{ date: '2024-01-02', credits_used: 2.0, calls: 8 },
|
|
171
|
-
],
|
|
172
|
-
},
|
|
173
|
-
subscription: {
|
|
174
|
-
plan: 'pro',
|
|
175
|
-
status: 'active',
|
|
176
|
-
},
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
mockAxios
|
|
180
|
-
.onGet('/v1/usage/summary?start_date=2024-01-01&end_date=2024-01-31')
|
|
181
|
-
.reply(200, response)
|
|
182
|
-
|
|
183
|
-
const result = await usageService.getUsageSummary(params)
|
|
184
|
-
|
|
185
|
-
expect(result).toEqual(response)
|
|
186
|
-
})
|
|
187
|
-
|
|
188
|
-
it('should get usage summary without date range', async () => {
|
|
189
|
-
const response: UsageSummaryResponse = {
|
|
190
|
-
user_id: 'user123',
|
|
191
|
-
period: {
|
|
192
|
-
start_date: '2024-01-01',
|
|
193
|
-
end_date: '2024-01-31',
|
|
194
|
-
},
|
|
195
|
-
usage_summary: {
|
|
196
|
-
total_credits_used: 15.5,
|
|
197
|
-
total_calls: 42,
|
|
198
|
-
model_breakdown: {},
|
|
199
|
-
daily_usage: [],
|
|
200
|
-
},
|
|
201
|
-
subscription: {
|
|
202
|
-
plan: 'pro',
|
|
203
|
-
status: 'active',
|
|
204
|
-
},
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
mockAxios.onGet('/v1/usage/summary').reply(200, response)
|
|
208
|
-
|
|
209
|
-
const result = await usageService.getUsageSummary()
|
|
210
|
-
|
|
211
|
-
expect(result).toEqual(response)
|
|
212
|
-
})
|
|
213
|
-
})
|
|
214
|
-
|
|
159
|
+
|
|
215
160
|
describe('getAuthorization', () => {
|
|
216
161
|
it('should get authorization info successfully', async () => {
|
|
217
162
|
const response: AuthorizationResponse = {
|
|
@@ -291,7 +236,7 @@ describe('UsageService', () => {
|
|
|
291
236
|
message: 'Authorization status retrieved successfully',
|
|
292
237
|
}
|
|
293
238
|
|
|
294
|
-
mockAxios.onGet('/
|
|
239
|
+
mockAxios.onGet('/usage/authorization').reply(200, response)
|
|
295
240
|
|
|
296
241
|
const result = await usageService.getAuthorization()
|
|
297
242
|
|
|
@@ -375,7 +320,7 @@ describe('UsageService', () => {
|
|
|
375
320
|
message: 'Authorization status retrieved successfully',
|
|
376
321
|
}
|
|
377
322
|
|
|
378
|
-
mockAxios.onGet('/
|
|
323
|
+
mockAxios.onGet('/usage/authorization').reply(200, response)
|
|
379
324
|
|
|
380
325
|
const result = await usageService.getAuthorization()
|
|
381
326
|
|
|
@@ -397,7 +342,7 @@ describe('UsageService', () => {
|
|
|
397
342
|
credits_expire_at: '2024-12-31',
|
|
398
343
|
}
|
|
399
344
|
|
|
400
|
-
mockAxios.onGet('/
|
|
345
|
+
mockAxios.onGet('/usage/free-user-status').reply(200, response)
|
|
401
346
|
|
|
402
347
|
const result = await usageService.getFreeUserStatus()
|
|
403
348
|
|
|
@@ -428,7 +373,7 @@ describe('UsageService', () => {
|
|
|
428
373
|
|
|
429
374
|
mockAxios
|
|
430
375
|
.onGet(
|
|
431
|
-
'/
|
|
376
|
+
'/usage/calculate?model_key=gpt-4&input_tokens=100&output_tokens=50&call_seconds=2&cost_amount=0.05'
|
|
432
377
|
)
|
|
433
378
|
.reply(200, response)
|
|
434
379
|
|
|
@@ -461,7 +406,7 @@ describe('UsageService', () => {
|
|
|
461
406
|
created_at: '2024-01-01T00:00:00Z',
|
|
462
407
|
}
|
|
463
408
|
|
|
464
|
-
mockAxios.onPost('/
|
|
409
|
+
mockAxios.onPost('/usage/codespace/track', request).reply(200, response)
|
|
465
410
|
|
|
466
411
|
const result = await usageService.trackCodespaceUsage(request)
|
|
467
412
|
|
|
@@ -494,7 +439,7 @@ describe('UsageService', () => {
|
|
|
494
439
|
],
|
|
495
440
|
}
|
|
496
441
|
|
|
497
|
-
mockAxios.onGet('/
|
|
442
|
+
mockAxios.onGet('/usage/codespace/task/task123').reply(200, response)
|
|
498
443
|
|
|
499
444
|
const result = await usageService.getCodespaceTaskUsage('task123')
|
|
500
445
|
|
|
@@ -504,7 +449,7 @@ describe('UsageService', () => {
|
|
|
504
449
|
|
|
505
450
|
describe('healthCheck', () => {
|
|
506
451
|
it('should return true when API is healthy', async () => {
|
|
507
|
-
mockAxios.onGet('/
|
|
452
|
+
mockAxios.onGet('/usage/health').reply(200, {
|
|
508
453
|
status: 'healthy',
|
|
509
454
|
timestamp: '2024-01-01T00:00:00Z',
|
|
510
455
|
version: '1.0.0',
|
|
@@ -516,7 +461,7 @@ describe('UsageService', () => {
|
|
|
516
461
|
})
|
|
517
462
|
|
|
518
463
|
it('should return false when API is not healthy', async () => {
|
|
519
|
-
mockAxios.onGet('/
|
|
464
|
+
mockAxios.onGet('/usage/health').reply(200, {
|
|
520
465
|
status: 'unhealthy',
|
|
521
466
|
timestamp: '2024-01-01T00:00:00Z',
|
|
522
467
|
version: '1.0.0',
|
|
@@ -528,11 +473,425 @@ describe('UsageService', () => {
|
|
|
528
473
|
})
|
|
529
474
|
|
|
530
475
|
it('should return false when health check fails', async () => {
|
|
531
|
-
mockAxios.onGet('/
|
|
476
|
+
mockAxios.onGet('/usage/health').reply(500)
|
|
532
477
|
|
|
533
478
|
const result = await usageService.healthCheck()
|
|
534
479
|
|
|
535
480
|
expect(result).toBe(false)
|
|
536
481
|
})
|
|
537
482
|
})
|
|
483
|
+
|
|
484
|
+
// Dashboard Analytics Tests
|
|
485
|
+
describe('getDashboardAnalytics', () => {
|
|
486
|
+
it('should get dashboard analytics with period parameter', async () => {
|
|
487
|
+
const params: DashboardAnalyticsRequest = {
|
|
488
|
+
period: '7d'
|
|
489
|
+
}
|
|
490
|
+
|
|
491
|
+
const response: DashboardAnalyticsResponse = {
|
|
492
|
+
status: 'success',
|
|
493
|
+
data: {
|
|
494
|
+
period: {
|
|
495
|
+
start: '2024-01-25',
|
|
496
|
+
end: '2024-01-31',
|
|
497
|
+
label: '7d'
|
|
498
|
+
},
|
|
499
|
+
daily_usage: [
|
|
500
|
+
{
|
|
501
|
+
date: '2024-01-25',
|
|
502
|
+
credits_consumed: 1250,
|
|
503
|
+
cost_usd: 3.75,
|
|
504
|
+
requests_count: 15,
|
|
505
|
+
average_credits_per_request: 83.33
|
|
506
|
+
}
|
|
507
|
+
],
|
|
508
|
+
totals: {
|
|
509
|
+
credits_consumed: 13870,
|
|
510
|
+
cost_usd: 41.61,
|
|
511
|
+
requests_count: 142
|
|
512
|
+
},
|
|
513
|
+
averages: {
|
|
514
|
+
daily_credits: 1981.43,
|
|
515
|
+
daily_requests: 20.29
|
|
516
|
+
},
|
|
517
|
+
trends: {
|
|
518
|
+
credits_consumed: 15.7,
|
|
519
|
+
requests_count: 8.3
|
|
520
|
+
},
|
|
521
|
+
top_services: [
|
|
522
|
+
{
|
|
523
|
+
service_type: 'docs',
|
|
524
|
+
credits_consumed: 5230,
|
|
525
|
+
requests_count: 58
|
|
526
|
+
}
|
|
527
|
+
]
|
|
528
|
+
}
|
|
529
|
+
}
|
|
530
|
+
|
|
531
|
+
mockAxios.onGet('/usage/dashboard/analytics?period=7d').reply(200, response)
|
|
532
|
+
|
|
533
|
+
const result = await usageService.getDashboardAnalytics(params)
|
|
534
|
+
|
|
535
|
+
expect(result).toEqual(response)
|
|
536
|
+
})
|
|
537
|
+
|
|
538
|
+
it('should get dashboard analytics with all parameters', async () => {
|
|
539
|
+
const params: DashboardAnalyticsRequest = {
|
|
540
|
+
start_date: '2024-01-01',
|
|
541
|
+
end_date: '2024-01-31',
|
|
542
|
+
service_type: 'docs'
|
|
543
|
+
}
|
|
544
|
+
|
|
545
|
+
const response: DashboardAnalyticsResponse = {
|
|
546
|
+
status: 'success',
|
|
547
|
+
data: {
|
|
548
|
+
period: {
|
|
549
|
+
start: '2024-01-01',
|
|
550
|
+
end: '2024-01-31',
|
|
551
|
+
label: 'custom'
|
|
552
|
+
},
|
|
553
|
+
daily_usage: [],
|
|
554
|
+
totals: {
|
|
555
|
+
credits_consumed: 5000,
|
|
556
|
+
cost_usd: 15.0,
|
|
557
|
+
requests_count: 45
|
|
558
|
+
},
|
|
559
|
+
averages: {
|
|
560
|
+
daily_credits: 161.29,
|
|
561
|
+
daily_requests: 1.45
|
|
562
|
+
},
|
|
563
|
+
trends: {
|
|
564
|
+
credits_consumed: 12.5,
|
|
565
|
+
requests_count: 5.2
|
|
566
|
+
},
|
|
567
|
+
top_services: [
|
|
568
|
+
{
|
|
569
|
+
service_type: 'docs',
|
|
570
|
+
credits_consumed: 5000,
|
|
571
|
+
requests_count: 45
|
|
572
|
+
}
|
|
573
|
+
]
|
|
574
|
+
}
|
|
575
|
+
}
|
|
576
|
+
|
|
577
|
+
mockAxios.onGet('/usage/dashboard/analytics?start_date=2024-01-01&end_date=2024-01-31&service_type=docs').reply(200, response)
|
|
578
|
+
|
|
579
|
+
const result = await usageService.getDashboardAnalytics(params)
|
|
580
|
+
|
|
581
|
+
expect(result).toEqual(response)
|
|
582
|
+
})
|
|
583
|
+
|
|
584
|
+
it('should get dashboard analytics without parameters', async () => {
|
|
585
|
+
const response: DashboardAnalyticsResponse = {
|
|
586
|
+
status: 'success',
|
|
587
|
+
data: {
|
|
588
|
+
period: {
|
|
589
|
+
start: '2024-01-01',
|
|
590
|
+
end: '2024-01-07',
|
|
591
|
+
label: '7d'
|
|
592
|
+
},
|
|
593
|
+
daily_usage: [],
|
|
594
|
+
totals: {
|
|
595
|
+
credits_consumed: 1000,
|
|
596
|
+
cost_usd: 3.0,
|
|
597
|
+
requests_count: 10
|
|
598
|
+
},
|
|
599
|
+
averages: {
|
|
600
|
+
daily_credits: 142.86,
|
|
601
|
+
daily_requests: 1.43
|
|
602
|
+
},
|
|
603
|
+
trends: {
|
|
604
|
+
credits_consumed: 5.0,
|
|
605
|
+
requests_count: 2.0
|
|
606
|
+
},
|
|
607
|
+
top_services: []
|
|
608
|
+
}
|
|
609
|
+
}
|
|
610
|
+
|
|
611
|
+
mockAxios.onGet('/usage/dashboard/analytics').reply(200, response)
|
|
612
|
+
|
|
613
|
+
const result = await usageService.getDashboardAnalytics()
|
|
614
|
+
|
|
615
|
+
expect(result).toEqual(response)
|
|
616
|
+
})
|
|
617
|
+
})
|
|
618
|
+
|
|
619
|
+
describe('getUsageDetails', () => {
|
|
620
|
+
it('should get usage details with pagination parameters', async () => {
|
|
621
|
+
const params: UsageDetailsRequest = {
|
|
622
|
+
page: 1,
|
|
623
|
+
page_size: 25,
|
|
624
|
+
sort_by: 'credits_consumed',
|
|
625
|
+
sort_order: 'desc'
|
|
626
|
+
}
|
|
627
|
+
|
|
628
|
+
const response: UsageDetailsResponse = {
|
|
629
|
+
status: 'success',
|
|
630
|
+
data: [
|
|
631
|
+
{
|
|
632
|
+
id: 'rec_123456789',
|
|
633
|
+
created_at: '2024-01-31T14:30:15.123Z',
|
|
634
|
+
service_type: 'docs',
|
|
635
|
+
model_name: 'GPT-4',
|
|
636
|
+
usage_type: 'output_tokens',
|
|
637
|
+
units_consumed: 1250,
|
|
638
|
+
credits_consumed: 156,
|
|
639
|
+
cost_amount: 0.468
|
|
640
|
+
}
|
|
641
|
+
],
|
|
642
|
+
pagination: {
|
|
643
|
+
page: 1,
|
|
644
|
+
page_size: 25,
|
|
645
|
+
total_count: 142,
|
|
646
|
+
total_pages: 6,
|
|
647
|
+
has_next: true,
|
|
648
|
+
has_prev: false
|
|
649
|
+
},
|
|
650
|
+
filters: {
|
|
651
|
+
period: null,
|
|
652
|
+
start_date: null,
|
|
653
|
+
end_date: null,
|
|
654
|
+
service_type: null
|
|
655
|
+
}
|
|
656
|
+
}
|
|
657
|
+
|
|
658
|
+
mockAxios.onGet('/usage/dashboard/details?page=1&page_size=25&sort_by=credits_consumed&sort_order=desc').reply(200, response)
|
|
659
|
+
|
|
660
|
+
const result = await usageService.getUsageDetails(params)
|
|
661
|
+
|
|
662
|
+
expect(result).toEqual(response)
|
|
663
|
+
})
|
|
664
|
+
|
|
665
|
+
it('should get usage details with filtering parameters', async () => {
|
|
666
|
+
const params: UsageDetailsRequest = {
|
|
667
|
+
period: '1m',
|
|
668
|
+
service_type: 'chat'
|
|
669
|
+
}
|
|
670
|
+
|
|
671
|
+
const response: UsageDetailsResponse = {
|
|
672
|
+
status: 'success',
|
|
673
|
+
data: [
|
|
674
|
+
{
|
|
675
|
+
id: 'rec_123456790',
|
|
676
|
+
created_at: '2024-01-30T10:15:20.456Z',
|
|
677
|
+
service_type: 'chat',
|
|
678
|
+
model_name: 'GPT-3.5 Turbo',
|
|
679
|
+
usage_type: 'input_tokens',
|
|
680
|
+
units_consumed: 890,
|
|
681
|
+
credits_consumed: 89,
|
|
682
|
+
cost_amount: null
|
|
683
|
+
}
|
|
684
|
+
],
|
|
685
|
+
pagination: {
|
|
686
|
+
page: 1,
|
|
687
|
+
page_size: 50,
|
|
688
|
+
total_count: 25,
|
|
689
|
+
total_pages: 1,
|
|
690
|
+
has_next: false,
|
|
691
|
+
has_prev: false
|
|
692
|
+
},
|
|
693
|
+
filters: {
|
|
694
|
+
period: '1m',
|
|
695
|
+
start_date: null,
|
|
696
|
+
end_date: null,
|
|
697
|
+
service_type: 'chat'
|
|
698
|
+
}
|
|
699
|
+
}
|
|
700
|
+
|
|
701
|
+
mockAxios.onGet('/usage/dashboard/details?period=1m&service_type=chat').reply(200, response)
|
|
702
|
+
|
|
703
|
+
const result = await usageService.getUsageDetails(params)
|
|
704
|
+
|
|
705
|
+
expect(result).toEqual(response)
|
|
706
|
+
})
|
|
707
|
+
})
|
|
708
|
+
|
|
709
|
+
describe('getUsageSummary', () => {
|
|
710
|
+
it('should get usage summary dashboard with period parameter', async () => {
|
|
711
|
+
const params = {
|
|
712
|
+
period: '7d' as const
|
|
713
|
+
}
|
|
714
|
+
|
|
715
|
+
const response: UsageSummaryResponse = {
|
|
716
|
+
status: 'success',
|
|
717
|
+
data: {
|
|
718
|
+
current_period: {
|
|
719
|
+
credits_consumed: 13870,
|
|
720
|
+
cost_usd: 41.61,
|
|
721
|
+
requests_count: 142
|
|
722
|
+
},
|
|
723
|
+
previous_period: {
|
|
724
|
+
credits_consumed: 11990,
|
|
725
|
+
cost_usd: 35.97,
|
|
726
|
+
requests_count: 131
|
|
727
|
+
},
|
|
728
|
+
billing_cycle: {
|
|
729
|
+
total_allotted: 50000,
|
|
730
|
+
total_consumed: 28450,
|
|
731
|
+
remaining_credits: 21550
|
|
732
|
+
},
|
|
733
|
+
utilization_percentage: 56.9,
|
|
734
|
+
remaining_credits: 21550,
|
|
735
|
+
daily_average: 1981.43,
|
|
736
|
+
projected_monthly: 59443
|
|
737
|
+
}
|
|
738
|
+
}
|
|
739
|
+
|
|
740
|
+
mockAxios.onGet('/usage/dashboard/summary?period=7d').reply(200, response)
|
|
741
|
+
|
|
742
|
+
const result = await usageService.getUsageSummary(params)
|
|
743
|
+
|
|
744
|
+
expect(result).toEqual(response)
|
|
745
|
+
})
|
|
746
|
+
|
|
747
|
+
it('should get usage summary dashboard with custom date range', async () => {
|
|
748
|
+
const params = {
|
|
749
|
+
start_date: '2024-01-01',
|
|
750
|
+
end_date: '2024-01-31'
|
|
751
|
+
}
|
|
752
|
+
|
|
753
|
+
const response: UsageSummaryResponse = {
|
|
754
|
+
status: 'success',
|
|
755
|
+
data: {
|
|
756
|
+
current_period: {
|
|
757
|
+
credits_consumed: 25000,
|
|
758
|
+
cost_usd: 75.0,
|
|
759
|
+
requests_count: 300
|
|
760
|
+
},
|
|
761
|
+
previous_period: {
|
|
762
|
+
credits_consumed: 22000,
|
|
763
|
+
cost_usd: 66.0,
|
|
764
|
+
requests_count: 275
|
|
765
|
+
},
|
|
766
|
+
billing_cycle: {
|
|
767
|
+
total_allotted: 50000,
|
|
768
|
+
total_consumed: 47000,
|
|
769
|
+
remaining_credits: 3000
|
|
770
|
+
},
|
|
771
|
+
utilization_percentage: 94.0,
|
|
772
|
+
remaining_credits: 3000,
|
|
773
|
+
daily_average: 806.45,
|
|
774
|
+
projected_monthly: 25000
|
|
775
|
+
}
|
|
776
|
+
}
|
|
777
|
+
|
|
778
|
+
mockAxios.onGet('/usage/dashboard/summary?start_date=2024-01-01&end_date=2024-01-31').reply(200, response)
|
|
779
|
+
|
|
780
|
+
const result = await usageService.getUsageSummary(params)
|
|
781
|
+
|
|
782
|
+
expect(result).toEqual(response)
|
|
783
|
+
})
|
|
784
|
+
})
|
|
785
|
+
|
|
786
|
+
describe('getServiceBreakdown', () => {
|
|
787
|
+
it('should get service breakdown with period parameter', async () => {
|
|
788
|
+
const params: ServiceBreakdownRequest = {
|
|
789
|
+
period: '7d'
|
|
790
|
+
}
|
|
791
|
+
|
|
792
|
+
const response: ServiceBreakdownResponse = {
|
|
793
|
+
status: 'success',
|
|
794
|
+
data: {
|
|
795
|
+
period: {
|
|
796
|
+
start: '2024-01-25',
|
|
797
|
+
end: '2024-01-31',
|
|
798
|
+
label: '7d'
|
|
799
|
+
},
|
|
800
|
+
services: [
|
|
801
|
+
{
|
|
802
|
+
service_type: 'docs',
|
|
803
|
+
credits_consumed: 5230,
|
|
804
|
+
percentage: 37.71,
|
|
805
|
+
cost_usd: 15.69,
|
|
806
|
+
requests_count: 58,
|
|
807
|
+
trend: 12.5
|
|
808
|
+
},
|
|
809
|
+
{
|
|
810
|
+
service_type: 'chat',
|
|
811
|
+
credits_consumed: 4120,
|
|
812
|
+
percentage: 29.71,
|
|
813
|
+
cost_usd: 12.36,
|
|
814
|
+
requests_count: 47,
|
|
815
|
+
trend: -5.2
|
|
816
|
+
}
|
|
817
|
+
],
|
|
818
|
+
total_credits: 13870,
|
|
819
|
+
total_cost: 41.61
|
|
820
|
+
}
|
|
821
|
+
}
|
|
822
|
+
|
|
823
|
+
mockAxios.onGet('/usage/dashboard/services?period=7d').reply(200, response)
|
|
824
|
+
|
|
825
|
+
const result = await usageService.getServiceBreakdown(params)
|
|
826
|
+
|
|
827
|
+
expect(result).toEqual(response)
|
|
828
|
+
})
|
|
829
|
+
|
|
830
|
+
it('should get service breakdown with custom date range', async () => {
|
|
831
|
+
const params: ServiceBreakdownRequest = {
|
|
832
|
+
start_date: '2024-01-01',
|
|
833
|
+
end_date: '2024-01-31'
|
|
834
|
+
}
|
|
835
|
+
|
|
836
|
+
const response: ServiceBreakdownResponse = {
|
|
837
|
+
status: 'success',
|
|
838
|
+
data: {
|
|
839
|
+
period: {
|
|
840
|
+
start: '2024-01-01',
|
|
841
|
+
end: '2024-01-31',
|
|
842
|
+
label: 'custom'
|
|
843
|
+
},
|
|
844
|
+
services: [
|
|
845
|
+
{
|
|
846
|
+
service_type: 'codespace_task',
|
|
847
|
+
credits_consumed: 15000,
|
|
848
|
+
percentage: 60.0,
|
|
849
|
+
cost_usd: 45.0,
|
|
850
|
+
requests_count: 25,
|
|
851
|
+
trend: 28.4
|
|
852
|
+
}
|
|
853
|
+
],
|
|
854
|
+
total_credits: 25000,
|
|
855
|
+
total_cost: 75.0
|
|
856
|
+
}
|
|
857
|
+
}
|
|
858
|
+
|
|
859
|
+
mockAxios.onGet('/usage/dashboard/services?start_date=2024-01-01&end_date=2024-01-31').reply(200, response)
|
|
860
|
+
|
|
861
|
+
const result = await usageService.getServiceBreakdown(params)
|
|
862
|
+
|
|
863
|
+
expect(result).toEqual(response)
|
|
864
|
+
})
|
|
865
|
+
|
|
866
|
+
it('should get service breakdown without parameters', async () => {
|
|
867
|
+
const response: ServiceBreakdownResponse = {
|
|
868
|
+
status: 'success',
|
|
869
|
+
data: {
|
|
870
|
+
period: {
|
|
871
|
+
start: '2024-01-01',
|
|
872
|
+
end: '2024-01-07',
|
|
873
|
+
label: '7d'
|
|
874
|
+
},
|
|
875
|
+
services: [
|
|
876
|
+
{
|
|
877
|
+
service_type: 'api',
|
|
878
|
+
credits_consumed: 700,
|
|
879
|
+
percentage: 100.0,
|
|
880
|
+
cost_usd: 2.10,
|
|
881
|
+
requests_count: 5,
|
|
882
|
+
trend: 0.0
|
|
883
|
+
}
|
|
884
|
+
],
|
|
885
|
+
total_credits: 700,
|
|
886
|
+
total_cost: 2.10
|
|
887
|
+
}
|
|
888
|
+
}
|
|
889
|
+
|
|
890
|
+
mockAxios.onGet('/usage/dashboard/services').reply(200, response)
|
|
891
|
+
|
|
892
|
+
const result = await usageService.getServiceBreakdown()
|
|
893
|
+
|
|
894
|
+
expect(result).toEqual(response)
|
|
895
|
+
})
|
|
896
|
+
})
|
|
538
897
|
})
|
package/codeguide.ts
CHANGED
|
@@ -19,6 +19,7 @@ import {
|
|
|
19
19
|
ExternalTokenService,
|
|
20
20
|
SecurityKeysService,
|
|
21
21
|
UserService,
|
|
22
|
+
StarterKitsService,
|
|
22
23
|
} from './services'
|
|
23
24
|
import { APIServiceConfig, CodeGuideOptions } from './types'
|
|
24
25
|
|
|
@@ -35,6 +36,7 @@ export class CodeGuide {
|
|
|
35
36
|
public externalTokens: ExternalTokenService
|
|
36
37
|
public securityKeys: SecurityKeysService
|
|
37
38
|
public users: UserService
|
|
39
|
+
public starterKits: StarterKitsService
|
|
38
40
|
private options: CodeGuideOptions
|
|
39
41
|
|
|
40
42
|
constructor(config: APIServiceConfig, options: CodeGuideOptions = {}) {
|
|
@@ -53,6 +55,7 @@ export class CodeGuide {
|
|
|
53
55
|
this.externalTokens = new ExternalTokenService(config)
|
|
54
56
|
this.securityKeys = new SecurityKeysService(config)
|
|
55
57
|
this.users = new UserService(config)
|
|
58
|
+
this.starterKits = new StarterKitsService(config)
|
|
56
59
|
}
|
|
57
60
|
|
|
58
61
|
// Convenience method for backward compatibility
|
package/dist/codeguide.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { GenerationService, ProjectService, UsageService, RepositoryAnalysisService, TaskService, ApiKeyEnhancedService, SubscriptionService, CancellationFunnelService, CodespaceService, ExternalTokenService, SecurityKeysService, UserService } from './services';
|
|
1
|
+
import { GenerationService, ProjectService, UsageService, RepositoryAnalysisService, TaskService, ApiKeyEnhancedService, SubscriptionService, CancellationFunnelService, CodespaceService, ExternalTokenService, SecurityKeysService, UserService, StarterKitsService } from './services';
|
|
2
2
|
import { APIServiceConfig, CodeGuideOptions } from './types';
|
|
3
3
|
export declare class CodeGuide {
|
|
4
4
|
generation: GenerationService;
|
|
@@ -13,6 +13,7 @@ export declare class CodeGuide {
|
|
|
13
13
|
externalTokens: ExternalTokenService;
|
|
14
14
|
securityKeys: SecurityKeysService;
|
|
15
15
|
users: UserService;
|
|
16
|
+
starterKits: StarterKitsService;
|
|
16
17
|
private options;
|
|
17
18
|
constructor(config: APIServiceConfig, options?: CodeGuideOptions);
|
|
18
19
|
getGuidance(prompt: string): Promise<any>;
|
package/dist/codeguide.js
CHANGED
|
@@ -28,6 +28,7 @@ class CodeGuide {
|
|
|
28
28
|
this.externalTokens = new services_1.ExternalTokenService(config);
|
|
29
29
|
this.securityKeys = new services_1.SecurityKeysService(config);
|
|
30
30
|
this.users = new services_1.UserService(config);
|
|
31
|
+
this.starterKits = new services_1.StarterKitsService(config);
|
|
31
32
|
}
|
|
32
33
|
// Convenience method for backward compatibility
|
|
33
34
|
async getGuidance(prompt) {
|