@codeguide/core 0.0.29 → 0.0.33
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/codespace/codespace-v2.test.ts +53 -0
- package/__tests__/services/usage/usage-service.test.ts +91 -96
- package/dist/services/codespace/codespace-service.d.ts +11 -2
- package/dist/services/codespace/codespace-service.js +18 -3
- package/dist/services/codespace/codespace-types.d.ts +21 -0
- package/dist/services/codespace/index.d.ts +1 -1
- package/dist/services/subscriptions/subscription-service.d.ts +11 -1
- package/dist/services/subscriptions/subscription-service.js +14 -0
- package/dist/services/usage/usage-types.d.ts +11 -12
- package/dist/types.d.ts +18 -2
- package/package.json +2 -1
- package/services/codespace/codespace-service.ts +25 -3
- package/services/codespace/codespace-types.ts +33 -0
- package/services/codespace/index.ts +6 -1
- package/services/subscriptions/subscription-service.ts +23 -5
- package/services/usage/usage-types.ts +12 -13
- package/types.ts +22 -2
|
@@ -3,6 +3,8 @@ import {
|
|
|
3
3
|
CreateCodespaceTaskRequestV2,
|
|
4
4
|
CreateBackgroundCodespaceTaskRequest,
|
|
5
5
|
ModelApiKey,
|
|
6
|
+
GetCodespaceProjectSummaryRequest,
|
|
7
|
+
GetCodespaceProjectSummaryResponse,
|
|
6
8
|
} from '../../../services/codespace/codespace-types'
|
|
7
9
|
import { APIServiceConfig } from '../../../types'
|
|
8
10
|
import axios from 'axios'
|
|
@@ -268,4 +270,55 @@ describe('CodespaceService - V2 Task Endpoints', () => {
|
|
|
268
270
|
expect(result).toEqual(mockResponse)
|
|
269
271
|
})
|
|
270
272
|
})
|
|
273
|
+
|
|
274
|
+
describe('getCodespaceProjectSummary', () => {
|
|
275
|
+
it('should get project codespace summary successfully', async () => {
|
|
276
|
+
const request: GetCodespaceProjectSummaryRequest = {
|
|
277
|
+
project_id: 'project-123',
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
const mockResponse: GetCodespaceProjectSummaryResponse = {
|
|
281
|
+
status: 'success',
|
|
282
|
+
data: {
|
|
283
|
+
project_id: 'project-123',
|
|
284
|
+
total_codespace_tasks: 25,
|
|
285
|
+
status_summary: {
|
|
286
|
+
pending: 5,
|
|
287
|
+
in_progress: 8,
|
|
288
|
+
completed: 10,
|
|
289
|
+
failed: 2,
|
|
290
|
+
blocked: 0,
|
|
291
|
+
},
|
|
292
|
+
latest_task_created_at: '2025-11-16T10:30:00Z',
|
|
293
|
+
},
|
|
294
|
+
message: 'Retrieved summary for 25 codespace tasks in project project-123',
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
mockAxios.onGet('/codespace/project/project-123/summary').reply(200, mockResponse)
|
|
298
|
+
|
|
299
|
+
const result = await codespaceService.getCodespaceProjectSummary(request)
|
|
300
|
+
|
|
301
|
+
expect(result).toEqual(mockResponse)
|
|
302
|
+
})
|
|
303
|
+
|
|
304
|
+
it('should throw error when project_id is missing', async () => {
|
|
305
|
+
const invalidRequest = {} as GetCodespaceProjectSummaryRequest
|
|
306
|
+
|
|
307
|
+
await expect(
|
|
308
|
+
codespaceService.getCodespaceProjectSummary(invalidRequest)
|
|
309
|
+
).rejects.toThrow('project_id is required')
|
|
310
|
+
})
|
|
311
|
+
|
|
312
|
+
it('should handle API errors properly', async () => {
|
|
313
|
+
const request: GetCodespaceProjectSummaryRequest = {
|
|
314
|
+
project_id: 'project-123',
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
mockAxios.onGet('/codespace/project/project-123/summary').reply(404, {
|
|
318
|
+
detail: 'Project not found',
|
|
319
|
+
})
|
|
320
|
+
|
|
321
|
+
await expect(codespaceService.getCodespaceProjectSummary(request)).rejects.toThrow()
|
|
322
|
+
})
|
|
323
|
+
})
|
|
271
324
|
})
|
|
@@ -146,9 +146,7 @@ describe('UsageService', () => {
|
|
|
146
146
|
model_key: 'gpt-4',
|
|
147
147
|
}
|
|
148
148
|
|
|
149
|
-
mockAxios
|
|
150
|
-
.onGet('/usage/credit-check?model_key=gpt-4&input_tokens=100')
|
|
151
|
-
.reply(200, response)
|
|
149
|
+
mockAxios.onGet('/usage/credit-check?model_key=gpt-4&input_tokens=100').reply(200, response)
|
|
152
150
|
|
|
153
151
|
const result = await usageService.checkCredits(params)
|
|
154
152
|
|
|
@@ -156,7 +154,6 @@ describe('UsageService', () => {
|
|
|
156
154
|
})
|
|
157
155
|
})
|
|
158
156
|
|
|
159
|
-
|
|
160
157
|
describe('getAuthorization', () => {
|
|
161
158
|
it('should get authorization info successfully', async () => {
|
|
162
159
|
const response: AuthorizationResponse = {
|
|
@@ -417,26 +414,12 @@ describe('UsageService', () => {
|
|
|
417
414
|
describe('getCodespaceTaskUsage', () => {
|
|
418
415
|
it('should get codespace task usage successfully', async () => {
|
|
419
416
|
const response: CodespaceTaskUsageResponse = {
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
total_cost: 0.1,
|
|
417
|
+
status: 'success',
|
|
418
|
+
data: {
|
|
419
|
+
total_records: 2,
|
|
420
|
+
total_credits_consumed: 49.428799,
|
|
421
|
+
latest_usage: '2025-11-24T07:50:58.150274+00:00',
|
|
426
422
|
},
|
|
427
|
-
usage_records: [
|
|
428
|
-
{
|
|
429
|
-
id: 'usage123',
|
|
430
|
-
codespace_task_id: 'task123',
|
|
431
|
-
user_id: 'user123',
|
|
432
|
-
model_key: 'gpt-4',
|
|
433
|
-
input_tokens: 100,
|
|
434
|
-
output_tokens: 50,
|
|
435
|
-
call_seconds: 2,
|
|
436
|
-
cost_amount: 0.05,
|
|
437
|
-
created_at: '2024-01-01T00:00:00Z',
|
|
438
|
-
},
|
|
439
|
-
],
|
|
440
423
|
}
|
|
441
424
|
|
|
442
425
|
mockAxios.onGet('/usage/codespace/task/task123').reply(200, response)
|
|
@@ -485,7 +468,7 @@ describe('UsageService', () => {
|
|
|
485
468
|
describe('getDashboardAnalytics', () => {
|
|
486
469
|
it('should get dashboard analytics with period parameter', async () => {
|
|
487
470
|
const params: DashboardAnalyticsRequest = {
|
|
488
|
-
period: '7d'
|
|
471
|
+
period: '7d',
|
|
489
472
|
}
|
|
490
473
|
|
|
491
474
|
const response: DashboardAnalyticsResponse = {
|
|
@@ -494,7 +477,7 @@ describe('UsageService', () => {
|
|
|
494
477
|
period: {
|
|
495
478
|
start: '2024-01-25',
|
|
496
479
|
end: '2024-01-31',
|
|
497
|
-
label: '7d'
|
|
480
|
+
label: '7d',
|
|
498
481
|
},
|
|
499
482
|
daily_usage: [
|
|
500
483
|
{
|
|
@@ -502,30 +485,30 @@ describe('UsageService', () => {
|
|
|
502
485
|
credits_consumed: 1250,
|
|
503
486
|
cost_usd: 3.75,
|
|
504
487
|
requests_count: 15,
|
|
505
|
-
average_credits_per_request: 83.33
|
|
506
|
-
}
|
|
488
|
+
average_credits_per_request: 83.33,
|
|
489
|
+
},
|
|
507
490
|
],
|
|
508
491
|
totals: {
|
|
509
492
|
credits_consumed: 13870,
|
|
510
493
|
cost_usd: 41.61,
|
|
511
|
-
requests_count: 142
|
|
494
|
+
requests_count: 142,
|
|
512
495
|
},
|
|
513
496
|
averages: {
|
|
514
497
|
daily_credits: 1981.43,
|
|
515
|
-
daily_requests: 20.29
|
|
498
|
+
daily_requests: 20.29,
|
|
516
499
|
},
|
|
517
500
|
trends: {
|
|
518
501
|
credits_consumed: 15.7,
|
|
519
|
-
requests_count: 8.3
|
|
502
|
+
requests_count: 8.3,
|
|
520
503
|
},
|
|
521
504
|
top_services: [
|
|
522
505
|
{
|
|
523
506
|
service_type: 'docs',
|
|
524
507
|
credits_consumed: 5230,
|
|
525
|
-
requests_count: 58
|
|
526
|
-
}
|
|
527
|
-
]
|
|
528
|
-
}
|
|
508
|
+
requests_count: 58,
|
|
509
|
+
},
|
|
510
|
+
],
|
|
511
|
+
},
|
|
529
512
|
}
|
|
530
513
|
|
|
531
514
|
mockAxios.onGet('/usage/dashboard/analytics?period=7d').reply(200, response)
|
|
@@ -539,7 +522,7 @@ describe('UsageService', () => {
|
|
|
539
522
|
const params: DashboardAnalyticsRequest = {
|
|
540
523
|
start_date: '2024-01-01',
|
|
541
524
|
end_date: '2024-01-31',
|
|
542
|
-
service_type: 'docs'
|
|
525
|
+
service_type: 'docs',
|
|
543
526
|
}
|
|
544
527
|
|
|
545
528
|
const response: DashboardAnalyticsResponse = {
|
|
@@ -548,33 +531,37 @@ describe('UsageService', () => {
|
|
|
548
531
|
period: {
|
|
549
532
|
start: '2024-01-01',
|
|
550
533
|
end: '2024-01-31',
|
|
551
|
-
label: 'custom'
|
|
534
|
+
label: 'custom',
|
|
552
535
|
},
|
|
553
536
|
daily_usage: [],
|
|
554
537
|
totals: {
|
|
555
538
|
credits_consumed: 5000,
|
|
556
539
|
cost_usd: 15.0,
|
|
557
|
-
requests_count: 45
|
|
540
|
+
requests_count: 45,
|
|
558
541
|
},
|
|
559
542
|
averages: {
|
|
560
543
|
daily_credits: 161.29,
|
|
561
|
-
daily_requests: 1.45
|
|
544
|
+
daily_requests: 1.45,
|
|
562
545
|
},
|
|
563
546
|
trends: {
|
|
564
547
|
credits_consumed: 12.5,
|
|
565
|
-
requests_count: 5.2
|
|
548
|
+
requests_count: 5.2,
|
|
566
549
|
},
|
|
567
550
|
top_services: [
|
|
568
551
|
{
|
|
569
552
|
service_type: 'docs',
|
|
570
553
|
credits_consumed: 5000,
|
|
571
|
-
requests_count: 45
|
|
572
|
-
}
|
|
573
|
-
]
|
|
574
|
-
}
|
|
554
|
+
requests_count: 45,
|
|
555
|
+
},
|
|
556
|
+
],
|
|
557
|
+
},
|
|
575
558
|
}
|
|
576
559
|
|
|
577
|
-
mockAxios
|
|
560
|
+
mockAxios
|
|
561
|
+
.onGet(
|
|
562
|
+
'/usage/dashboard/analytics?start_date=2024-01-01&end_date=2024-01-31&service_type=docs'
|
|
563
|
+
)
|
|
564
|
+
.reply(200, response)
|
|
578
565
|
|
|
579
566
|
const result = await usageService.getDashboardAnalytics(params)
|
|
580
567
|
|
|
@@ -588,24 +575,24 @@ describe('UsageService', () => {
|
|
|
588
575
|
period: {
|
|
589
576
|
start: '2024-01-01',
|
|
590
577
|
end: '2024-01-07',
|
|
591
|
-
label: '7d'
|
|
578
|
+
label: '7d',
|
|
592
579
|
},
|
|
593
580
|
daily_usage: [],
|
|
594
581
|
totals: {
|
|
595
582
|
credits_consumed: 1000,
|
|
596
583
|
cost_usd: 3.0,
|
|
597
|
-
requests_count: 10
|
|
584
|
+
requests_count: 10,
|
|
598
585
|
},
|
|
599
586
|
averages: {
|
|
600
587
|
daily_credits: 142.86,
|
|
601
|
-
daily_requests: 1.43
|
|
588
|
+
daily_requests: 1.43,
|
|
602
589
|
},
|
|
603
590
|
trends: {
|
|
604
591
|
credits_consumed: 5.0,
|
|
605
|
-
requests_count: 2.0
|
|
592
|
+
requests_count: 2.0,
|
|
606
593
|
},
|
|
607
|
-
top_services: []
|
|
608
|
-
}
|
|
594
|
+
top_services: [],
|
|
595
|
+
},
|
|
609
596
|
}
|
|
610
597
|
|
|
611
598
|
mockAxios.onGet('/usage/dashboard/analytics').reply(200, response)
|
|
@@ -622,7 +609,7 @@ describe('UsageService', () => {
|
|
|
622
609
|
page: 1,
|
|
623
610
|
page_size: 25,
|
|
624
611
|
sort_by: 'credits_consumed',
|
|
625
|
-
sort_order: 'desc'
|
|
612
|
+
sort_order: 'desc',
|
|
626
613
|
}
|
|
627
614
|
|
|
628
615
|
const response: UsageDetailsResponse = {
|
|
@@ -636,8 +623,8 @@ describe('UsageService', () => {
|
|
|
636
623
|
usage_type: 'output_tokens',
|
|
637
624
|
units_consumed: 1250,
|
|
638
625
|
credits_consumed: 156,
|
|
639
|
-
cost_amount: 0.468
|
|
640
|
-
}
|
|
626
|
+
cost_amount: 0.468,
|
|
627
|
+
},
|
|
641
628
|
],
|
|
642
629
|
pagination: {
|
|
643
630
|
page: 1,
|
|
@@ -645,17 +632,21 @@ describe('UsageService', () => {
|
|
|
645
632
|
total_count: 142,
|
|
646
633
|
total_pages: 6,
|
|
647
634
|
has_next: true,
|
|
648
|
-
has_prev: false
|
|
635
|
+
has_prev: false,
|
|
649
636
|
},
|
|
650
637
|
filters: {
|
|
651
638
|
period: null,
|
|
652
639
|
start_date: null,
|
|
653
640
|
end_date: null,
|
|
654
|
-
service_type: null
|
|
655
|
-
}
|
|
641
|
+
service_type: null,
|
|
642
|
+
},
|
|
656
643
|
}
|
|
657
644
|
|
|
658
|
-
mockAxios
|
|
645
|
+
mockAxios
|
|
646
|
+
.onGet(
|
|
647
|
+
'/usage/dashboard/details?page=1&page_size=25&sort_by=credits_consumed&sort_order=desc'
|
|
648
|
+
)
|
|
649
|
+
.reply(200, response)
|
|
659
650
|
|
|
660
651
|
const result = await usageService.getUsageDetails(params)
|
|
661
652
|
|
|
@@ -665,7 +656,7 @@ describe('UsageService', () => {
|
|
|
665
656
|
it('should get usage details with filtering parameters', async () => {
|
|
666
657
|
const params: UsageDetailsRequest = {
|
|
667
658
|
period: '1m',
|
|
668
|
-
service_type: 'chat'
|
|
659
|
+
service_type: 'chat',
|
|
669
660
|
}
|
|
670
661
|
|
|
671
662
|
const response: UsageDetailsResponse = {
|
|
@@ -679,8 +670,8 @@ describe('UsageService', () => {
|
|
|
679
670
|
usage_type: 'input_tokens',
|
|
680
671
|
units_consumed: 890,
|
|
681
672
|
credits_consumed: 89,
|
|
682
|
-
cost_amount: null
|
|
683
|
-
}
|
|
673
|
+
cost_amount: null,
|
|
674
|
+
},
|
|
684
675
|
],
|
|
685
676
|
pagination: {
|
|
686
677
|
page: 1,
|
|
@@ -688,14 +679,14 @@ describe('UsageService', () => {
|
|
|
688
679
|
total_count: 25,
|
|
689
680
|
total_pages: 1,
|
|
690
681
|
has_next: false,
|
|
691
|
-
has_prev: false
|
|
682
|
+
has_prev: false,
|
|
692
683
|
},
|
|
693
684
|
filters: {
|
|
694
685
|
period: '1m',
|
|
695
686
|
start_date: null,
|
|
696
687
|
end_date: null,
|
|
697
|
-
service_type: 'chat'
|
|
698
|
-
}
|
|
688
|
+
service_type: 'chat',
|
|
689
|
+
},
|
|
699
690
|
}
|
|
700
691
|
|
|
701
692
|
mockAxios.onGet('/usage/dashboard/details?period=1m&service_type=chat').reply(200, response)
|
|
@@ -709,7 +700,7 @@ describe('UsageService', () => {
|
|
|
709
700
|
describe('getUsageSummary', () => {
|
|
710
701
|
it('should get usage summary dashboard with period parameter', async () => {
|
|
711
702
|
const params = {
|
|
712
|
-
period: '7d' as const
|
|
703
|
+
period: '7d' as const,
|
|
713
704
|
}
|
|
714
705
|
|
|
715
706
|
const response: UsageSummaryResponse = {
|
|
@@ -718,23 +709,23 @@ describe('UsageService', () => {
|
|
|
718
709
|
current_period: {
|
|
719
710
|
credits_consumed: 13870,
|
|
720
711
|
cost_usd: 41.61,
|
|
721
|
-
requests_count: 142
|
|
712
|
+
requests_count: 142,
|
|
722
713
|
},
|
|
723
714
|
previous_period: {
|
|
724
715
|
credits_consumed: 11990,
|
|
725
716
|
cost_usd: 35.97,
|
|
726
|
-
requests_count: 131
|
|
717
|
+
requests_count: 131,
|
|
727
718
|
},
|
|
728
719
|
billing_cycle: {
|
|
729
720
|
total_allotted: 50000,
|
|
730
721
|
total_consumed: 28450,
|
|
731
|
-
remaining_credits: 21550
|
|
722
|
+
remaining_credits: 21550,
|
|
732
723
|
},
|
|
733
724
|
utilization_percentage: 56.9,
|
|
734
725
|
remaining_credits: 21550,
|
|
735
726
|
daily_average: 1981.43,
|
|
736
|
-
projected_monthly: 59443
|
|
737
|
-
}
|
|
727
|
+
projected_monthly: 59443,
|
|
728
|
+
},
|
|
738
729
|
}
|
|
739
730
|
|
|
740
731
|
mockAxios.onGet('/usage/dashboard/summary?period=7d').reply(200, response)
|
|
@@ -747,7 +738,7 @@ describe('UsageService', () => {
|
|
|
747
738
|
it('should get usage summary dashboard with custom date range', async () => {
|
|
748
739
|
const params = {
|
|
749
740
|
start_date: '2024-01-01',
|
|
750
|
-
end_date: '2024-01-31'
|
|
741
|
+
end_date: '2024-01-31',
|
|
751
742
|
}
|
|
752
743
|
|
|
753
744
|
const response: UsageSummaryResponse = {
|
|
@@ -756,26 +747,28 @@ describe('UsageService', () => {
|
|
|
756
747
|
current_period: {
|
|
757
748
|
credits_consumed: 25000,
|
|
758
749
|
cost_usd: 75.0,
|
|
759
|
-
requests_count: 300
|
|
750
|
+
requests_count: 300,
|
|
760
751
|
},
|
|
761
752
|
previous_period: {
|
|
762
753
|
credits_consumed: 22000,
|
|
763
754
|
cost_usd: 66.0,
|
|
764
|
-
requests_count: 275
|
|
755
|
+
requests_count: 275,
|
|
765
756
|
},
|
|
766
757
|
billing_cycle: {
|
|
767
758
|
total_allotted: 50000,
|
|
768
759
|
total_consumed: 47000,
|
|
769
|
-
remaining_credits: 3000
|
|
760
|
+
remaining_credits: 3000,
|
|
770
761
|
},
|
|
771
762
|
utilization_percentage: 94.0,
|
|
772
763
|
remaining_credits: 3000,
|
|
773
764
|
daily_average: 806.45,
|
|
774
|
-
projected_monthly: 25000
|
|
775
|
-
}
|
|
765
|
+
projected_monthly: 25000,
|
|
766
|
+
},
|
|
776
767
|
}
|
|
777
768
|
|
|
778
|
-
mockAxios
|
|
769
|
+
mockAxios
|
|
770
|
+
.onGet('/usage/dashboard/summary?start_date=2024-01-01&end_date=2024-01-31')
|
|
771
|
+
.reply(200, response)
|
|
779
772
|
|
|
780
773
|
const result = await usageService.getUsageSummary(params)
|
|
781
774
|
|
|
@@ -786,7 +779,7 @@ describe('UsageService', () => {
|
|
|
786
779
|
describe('getServiceBreakdown', () => {
|
|
787
780
|
it('should get service breakdown with period parameter', async () => {
|
|
788
781
|
const params: ServiceBreakdownRequest = {
|
|
789
|
-
period: '7d'
|
|
782
|
+
period: '7d',
|
|
790
783
|
}
|
|
791
784
|
|
|
792
785
|
const response: ServiceBreakdownResponse = {
|
|
@@ -795,7 +788,7 @@ describe('UsageService', () => {
|
|
|
795
788
|
period: {
|
|
796
789
|
start: '2024-01-25',
|
|
797
790
|
end: '2024-01-31',
|
|
798
|
-
label: '7d'
|
|
791
|
+
label: '7d',
|
|
799
792
|
},
|
|
800
793
|
services: [
|
|
801
794
|
{
|
|
@@ -804,7 +797,7 @@ describe('UsageService', () => {
|
|
|
804
797
|
percentage: 37.71,
|
|
805
798
|
cost_usd: 15.69,
|
|
806
799
|
requests_count: 58,
|
|
807
|
-
trend: 12.5
|
|
800
|
+
trend: 12.5,
|
|
808
801
|
},
|
|
809
802
|
{
|
|
810
803
|
service_type: 'chat',
|
|
@@ -812,12 +805,12 @@ describe('UsageService', () => {
|
|
|
812
805
|
percentage: 29.71,
|
|
813
806
|
cost_usd: 12.36,
|
|
814
807
|
requests_count: 47,
|
|
815
|
-
trend: -5.2
|
|
816
|
-
}
|
|
808
|
+
trend: -5.2,
|
|
809
|
+
},
|
|
817
810
|
],
|
|
818
811
|
total_credits: 13870,
|
|
819
|
-
total_cost: 41.61
|
|
820
|
-
}
|
|
812
|
+
total_cost: 41.61,
|
|
813
|
+
},
|
|
821
814
|
}
|
|
822
815
|
|
|
823
816
|
mockAxios.onGet('/usage/dashboard/services?period=7d').reply(200, response)
|
|
@@ -830,7 +823,7 @@ describe('UsageService', () => {
|
|
|
830
823
|
it('should get service breakdown with custom date range', async () => {
|
|
831
824
|
const params: ServiceBreakdownRequest = {
|
|
832
825
|
start_date: '2024-01-01',
|
|
833
|
-
end_date: '2024-01-31'
|
|
826
|
+
end_date: '2024-01-31',
|
|
834
827
|
}
|
|
835
828
|
|
|
836
829
|
const response: ServiceBreakdownResponse = {
|
|
@@ -839,7 +832,7 @@ describe('UsageService', () => {
|
|
|
839
832
|
period: {
|
|
840
833
|
start: '2024-01-01',
|
|
841
834
|
end: '2024-01-31',
|
|
842
|
-
label: 'custom'
|
|
835
|
+
label: 'custom',
|
|
843
836
|
},
|
|
844
837
|
services: [
|
|
845
838
|
{
|
|
@@ -848,15 +841,17 @@ describe('UsageService', () => {
|
|
|
848
841
|
percentage: 60.0,
|
|
849
842
|
cost_usd: 45.0,
|
|
850
843
|
requests_count: 25,
|
|
851
|
-
trend: 28.4
|
|
852
|
-
}
|
|
844
|
+
trend: 28.4,
|
|
845
|
+
},
|
|
853
846
|
],
|
|
854
847
|
total_credits: 25000,
|
|
855
|
-
total_cost: 75.0
|
|
856
|
-
}
|
|
848
|
+
total_cost: 75.0,
|
|
849
|
+
},
|
|
857
850
|
}
|
|
858
851
|
|
|
859
|
-
mockAxios
|
|
852
|
+
mockAxios
|
|
853
|
+
.onGet('/usage/dashboard/services?start_date=2024-01-01&end_date=2024-01-31')
|
|
854
|
+
.reply(200, response)
|
|
860
855
|
|
|
861
856
|
const result = await usageService.getServiceBreakdown(params)
|
|
862
857
|
|
|
@@ -870,21 +865,21 @@ describe('UsageService', () => {
|
|
|
870
865
|
period: {
|
|
871
866
|
start: '2024-01-01',
|
|
872
867
|
end: '2024-01-07',
|
|
873
|
-
label: '7d'
|
|
868
|
+
label: '7d',
|
|
874
869
|
},
|
|
875
870
|
services: [
|
|
876
871
|
{
|
|
877
872
|
service_type: 'api',
|
|
878
873
|
credits_consumed: 700,
|
|
879
874
|
percentage: 100.0,
|
|
880
|
-
cost_usd: 2.
|
|
875
|
+
cost_usd: 2.1,
|
|
881
876
|
requests_count: 5,
|
|
882
|
-
trend: 0.0
|
|
883
|
-
}
|
|
877
|
+
trend: 0.0,
|
|
878
|
+
},
|
|
884
879
|
],
|
|
885
880
|
total_credits: 700,
|
|
886
|
-
total_cost: 2.
|
|
887
|
-
}
|
|
881
|
+
total_cost: 2.1,
|
|
882
|
+
},
|
|
888
883
|
}
|
|
889
884
|
|
|
890
885
|
mockAxios.onGet('/usage/dashboard/services').reply(200, response)
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { BaseService } from '../base/base-service';
|
|
2
|
-
import { GenerateTaskTitleRequest, GenerateTaskTitleResponse, CreateCodespaceTaskRequest, CreateCodespaceTaskResponse, CreateCodespaceTaskRequestV2, CreateCodespaceTaskResponseV2, CreateBackgroundCodespaceTaskRequest, CreateBackgroundCodespaceTaskResponse, GetCodespaceTaskResponse, GetProjectTasksByCodespaceResponse, GetCodespaceTasksByProjectRequest, GetCodespaceTasksByProjectResponse, CodespaceTaskDetailedResponse, CodespaceQuestionnaireRequest, CodespaceQuestionnaireResponse, GetCodespaceModelsQuery, GetCodespaceModelsResponse, GetCodespaceModelResponse, GetLLMModelProvidersResponse, GetLLMModelProviderResponse, GetModelsByProviderResponse, GetCodespaceTasksRequest, GetCodespaceTasksResponse, GetTasksByCodespaceIdRequest, GetTasksByCodespaceIdResponse, UpdateFinalReportPopupStateRequest, UpdateFinalReportPopupStateResponse, GetCodespaceTaskLogsRequest, CodespaceTaskLogsResponse, StreamCodespaceTaskLogsRequest, CodespaceLogStreamEvent } from './codespace-types';
|
|
2
|
+
import { GenerateTaskTitleRequest, GenerateTaskTitleResponse, CreateCodespaceTaskRequest, CreateCodespaceTaskResponse, CreateCodespaceTaskRequestV2, CreateCodespaceTaskResponseV2, CreateBackgroundCodespaceTaskRequest, CreateBackgroundCodespaceTaskResponse, GetCodespaceTaskResponse, GetProjectTasksByCodespaceResponse, GetCodespaceTasksByProjectRequest, GetCodespaceTasksByProjectResponse, CodespaceTaskDetailedResponse, CodespaceQuestionnaireRequest, CodespaceQuestionnaireResponse, GetCodespaceModelsQuery, GetCodespaceModelsResponse, GetCodespaceModelResponse, GetLLMModelProvidersResponse, GetLLMModelProviderResponse, GetModelsByProviderResponse, GetCodespaceTasksRequest, GetCodespaceTasksResponse, GetTasksByCodespaceIdRequest, GetTasksByCodespaceIdResponse, UpdateFinalReportPopupStateRequest, UpdateFinalReportPopupStateResponse, GetCodespaceTaskLogsRequest, CodespaceTaskLogsResponse, StreamCodespaceTaskLogsRequest, CodespaceLogStreamEvent, GetCodespaceProjectSummaryRequest, GetCodespaceProjectSummaryResponse } from './codespace-types';
|
|
3
3
|
export declare class CodespaceService extends BaseService {
|
|
4
4
|
generateTaskTitle(request: GenerateTaskTitleRequest): Promise<GenerateTaskTitleResponse>;
|
|
5
5
|
generateQuestionnaire(request: CodespaceQuestionnaireRequest): Promise<CodespaceQuestionnaireResponse>;
|
|
@@ -9,6 +9,15 @@ export declare class CodespaceService extends BaseService {
|
|
|
9
9
|
getCodespaceTask(codespaceTaskId: string): Promise<GetCodespaceTaskResponse>;
|
|
10
10
|
getProjectTasksByCodespace(codespaceTaskId: string): Promise<GetProjectTasksByCodespaceResponse>;
|
|
11
11
|
getCodespaceTasksByProject(params: GetCodespaceTasksByProjectRequest): Promise<GetCodespaceTasksByProjectResponse>;
|
|
12
|
+
/**
|
|
13
|
+
* Get aggregated statistics for all codespace tasks within a project
|
|
14
|
+
*
|
|
15
|
+
* GET /codespace/project/{project_id}/summary
|
|
16
|
+
*
|
|
17
|
+
* @param params - Request parameters including project_id
|
|
18
|
+
* @returns Promise resolving to aggregated task statistics by status
|
|
19
|
+
*/
|
|
20
|
+
getCodespaceProjectSummary(params: GetCodespaceProjectSummaryRequest): Promise<GetCodespaceProjectSummaryResponse>;
|
|
12
21
|
getCodespaceTaskDetailed(codespaceTaskId: string): Promise<CodespaceTaskDetailedResponse>;
|
|
13
22
|
/**
|
|
14
23
|
* Get tasks by codespace task ID with optional pagination and sorting
|
|
@@ -31,7 +40,7 @@ export declare class CodespaceService extends BaseService {
|
|
|
31
40
|
/**
|
|
32
41
|
* Update the final report popup state for a codespace task
|
|
33
42
|
*
|
|
34
|
-
* PATCH /task/{codespace_task_id}/final-report-popup-state
|
|
43
|
+
* PATCH /codespace/task/{codespace_task_id}/final-report-popup-state
|
|
35
44
|
*
|
|
36
45
|
* @param codespaceTaskId - The ID of the codespace task
|
|
37
46
|
* @param request - The request body containing the new popup state
|
|
@@ -51,6 +51,21 @@ class CodespaceService extends base_service_1.BaseService {
|
|
|
51
51
|
const url = `/codespace/tasks/project/${params.project_id}${queryParams.toString() ? `?${queryParams.toString()}` : ''}`;
|
|
52
52
|
return this.get(url);
|
|
53
53
|
}
|
|
54
|
+
/**
|
|
55
|
+
* Get aggregated statistics for all codespace tasks within a project
|
|
56
|
+
*
|
|
57
|
+
* GET /codespace/project/{project_id}/summary
|
|
58
|
+
*
|
|
59
|
+
* @param params - Request parameters including project_id
|
|
60
|
+
* @returns Promise resolving to aggregated task statistics by status
|
|
61
|
+
*/
|
|
62
|
+
async getCodespaceProjectSummary(params) {
|
|
63
|
+
if (!params.project_id) {
|
|
64
|
+
throw new Error('project_id is required');
|
|
65
|
+
}
|
|
66
|
+
const url = `/codespace/project/${params.project_id}/summary`;
|
|
67
|
+
return this.get(url);
|
|
68
|
+
}
|
|
54
69
|
async getCodespaceTaskDetailed(codespaceTaskId) {
|
|
55
70
|
if (!codespaceTaskId) {
|
|
56
71
|
throw new Error('codespace_task_id is required');
|
|
@@ -82,7 +97,7 @@ class CodespaceService extends base_service_1.BaseService {
|
|
|
82
97
|
if (params.sort_order) {
|
|
83
98
|
queryParams.append('sort_order', params.sort_order);
|
|
84
99
|
}
|
|
85
|
-
const url = `/tasks/by-codespace-id/${params.codespace_task_id}${queryParams.toString() ? `?${queryParams.toString()}` : ''}`;
|
|
100
|
+
const url = `/codespace/tasks/by-codespace-id/${params.codespace_task_id}${queryParams.toString() ? `?${queryParams.toString()}` : ''}`;
|
|
86
101
|
return this.get(url);
|
|
87
102
|
}
|
|
88
103
|
/**
|
|
@@ -126,7 +141,7 @@ class CodespaceService extends base_service_1.BaseService {
|
|
|
126
141
|
/**
|
|
127
142
|
* Update the final report popup state for a codespace task
|
|
128
143
|
*
|
|
129
|
-
* PATCH /task/{codespace_task_id}/final-report-popup-state
|
|
144
|
+
* PATCH /codespace/task/{codespace_task_id}/final-report-popup-state
|
|
130
145
|
*
|
|
131
146
|
* @param codespaceTaskId - The ID of the codespace task
|
|
132
147
|
* @param request - The request body containing the new popup state
|
|
@@ -140,7 +155,7 @@ class CodespaceService extends base_service_1.BaseService {
|
|
|
140
155
|
if (!['not_ready', 'open', 'closed'].includes(request.final_report_popup_state)) {
|
|
141
156
|
throw new Error('final_report_popup_state must be "not_ready", "open", or "closed"');
|
|
142
157
|
}
|
|
143
|
-
return this.patch(`/task/${codespaceTaskId}/final-report-popup-state`, request);
|
|
158
|
+
return this.patch(`/codespace/task/${codespaceTaskId}/final-report-popup-state`, request);
|
|
144
159
|
}
|
|
145
160
|
// ============================================================================
|
|
146
161
|
// Codespace Task Logs Methods
|
|
@@ -390,3 +390,24 @@ export interface StreamErrorEvent {
|
|
|
390
390
|
};
|
|
391
391
|
}
|
|
392
392
|
export type CodespaceLogStreamEvent = StreamLogEvent | StreamHeartbeatEvent | StreamCompleteEvent | StreamTimeoutEvent | StreamErrorEvent;
|
|
393
|
+
export interface GetCodespaceProjectSummaryRequest {
|
|
394
|
+
project_id: string;
|
|
395
|
+
}
|
|
396
|
+
export interface CodespaceStatusSummary {
|
|
397
|
+
pending: number;
|
|
398
|
+
in_progress: number;
|
|
399
|
+
completed: number;
|
|
400
|
+
failed: number;
|
|
401
|
+
blocked: number;
|
|
402
|
+
}
|
|
403
|
+
export interface CodespaceProjectSummaryData {
|
|
404
|
+
project_id: string;
|
|
405
|
+
total_codespace_tasks: number;
|
|
406
|
+
status_summary: CodespaceStatusSummary;
|
|
407
|
+
latest_task_created_at: string;
|
|
408
|
+
}
|
|
409
|
+
export interface GetCodespaceProjectSummaryResponse {
|
|
410
|
+
status: string;
|
|
411
|
+
data: CodespaceProjectSummaryData;
|
|
412
|
+
message: string;
|
|
413
|
+
}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
export { CodespaceService } from './codespace-service';
|
|
2
2
|
export * from './codespace-types';
|
|
3
|
-
export type { CreateCodespaceTaskRequestV2 as CreateCodespaceTaskRequest, CreateCodespaceTaskResponseV2 as CreateCodespaceTaskResponse, CreateBackgroundCodespaceTaskRequest, CreateBackgroundCodespaceTaskResponse, ModelApiKey, Attachment, GetCodespaceTaskResponse, CodespaceTaskData, TechnicalDocument, GetProjectTasksByCodespaceResponse, CodespaceProjectTask, CodespaceProjectTaskListResponse, CodespaceQuestionnaireRequest, CodespaceQuestionnaireResponse, LLMModelProviderInDB, CodespaceModelInDB, CodespaceModelWithProvider, GetCodespaceModelsQuery, GetCodespaceModelsResponse, GetCodespaceModelResponse, GetLLMModelProvidersResponse, GetLLMModelProviderResponse, GetModelsByProviderResponse, CodespaceModelsError, UpdateFinalReportPopupStateRequest, UpdateFinalReportPopupStateResponse, GetCodespaceTaskLogsRequest, CodespaceTaskLogsResponse, StreamCodespaceTaskLogsRequest, CodespaceTaskLog, CodespaceLogType, CodespaceLogStreamEvent, GetTasksByCodespaceIdRequest, GetTasksByCodespaceIdResponse } from './codespace-types';
|
|
3
|
+
export type { CreateCodespaceTaskRequestV2 as CreateCodespaceTaskRequest, CreateCodespaceTaskResponseV2 as CreateCodespaceTaskResponse, CreateBackgroundCodespaceTaskRequest, CreateBackgroundCodespaceTaskResponse, ModelApiKey, Attachment, GetCodespaceTaskResponse, CodespaceTaskData, TechnicalDocument, GetProjectTasksByCodespaceResponse, CodespaceProjectTask, CodespaceProjectTaskListResponse, CodespaceQuestionnaireRequest, CodespaceQuestionnaireResponse, LLMModelProviderInDB, CodespaceModelInDB, CodespaceModelWithProvider, GetCodespaceModelsQuery, GetCodespaceModelsResponse, GetCodespaceModelResponse, GetLLMModelProvidersResponse, GetLLMModelProviderResponse, GetModelsByProviderResponse, CodespaceModelsError, UpdateFinalReportPopupStateRequest, UpdateFinalReportPopupStateResponse, GetCodespaceTaskLogsRequest, CodespaceTaskLogsResponse, StreamCodespaceTaskLogsRequest, CodespaceTaskLog, CodespaceLogType, CodespaceLogStreamEvent, GetTasksByCodespaceIdRequest, GetTasksByCodespaceIdResponse, GetCodespaceProjectSummaryRequest, GetCodespaceProjectSummaryResponse, CodespaceStatusSummary, CodespaceProjectSummaryData } from './codespace-types';
|
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
import { BaseService } from '../base/base-service';
|
|
2
|
-
import { CurrentSubscriptionResponse, UserSubscriptionsResponse, CancelSubscriptionRequest, CancelSubscriptionResponse } from '../../types';
|
|
2
|
+
import { CurrentSubscriptionResponse, UserSubscriptionsResponse, CancelSubscriptionRequest, CancelSubscriptionResponse, SubscriptionProductsResponse, CreateCheckoutSessionRequest, CreateCheckoutSessionResponse } from '../../types';
|
|
3
3
|
export declare class SubscriptionService extends BaseService {
|
|
4
4
|
constructor(config: any);
|
|
5
|
+
/**
|
|
6
|
+
* Create a Stripe checkout session for subscription purchase
|
|
7
|
+
* POST /subscriptions/create-checkout-session
|
|
8
|
+
*/
|
|
9
|
+
createCheckoutSession(request: CreateCheckoutSessionRequest): Promise<CreateCheckoutSessionResponse>;
|
|
5
10
|
/**
|
|
6
11
|
* Get the currently active subscription for the authenticated user
|
|
7
12
|
* GET /subscriptions/current
|
|
@@ -12,6 +17,11 @@ export declare class SubscriptionService extends BaseService {
|
|
|
12
17
|
* GET /subscriptions/
|
|
13
18
|
*/
|
|
14
19
|
getAllSubscriptions(): Promise<UserSubscriptionsResponse>;
|
|
20
|
+
/**
|
|
21
|
+
* Get all available subscription products and their prices
|
|
22
|
+
* GET /subscriptions/products
|
|
23
|
+
*/
|
|
24
|
+
getSubscriptionProducts(): Promise<SubscriptionProductsResponse>;
|
|
15
25
|
/**
|
|
16
26
|
* Cancel subscription but keep it active until the end of the current billing period
|
|
17
27
|
* POST /subscriptions/{subscription_id}/cancel
|
|
@@ -6,6 +6,13 @@ class SubscriptionService extends base_service_1.BaseService {
|
|
|
6
6
|
constructor(config) {
|
|
7
7
|
super(config);
|
|
8
8
|
}
|
|
9
|
+
/**
|
|
10
|
+
* Create a Stripe checkout session for subscription purchase
|
|
11
|
+
* POST /subscriptions/create-checkout-session
|
|
12
|
+
*/
|
|
13
|
+
async createCheckoutSession(request) {
|
|
14
|
+
return this.post('/subscriptions/create-checkout-session', request);
|
|
15
|
+
}
|
|
9
16
|
/**
|
|
10
17
|
* Get the currently active subscription for the authenticated user
|
|
11
18
|
* GET /subscriptions/current
|
|
@@ -20,6 +27,13 @@ class SubscriptionService extends base_service_1.BaseService {
|
|
|
20
27
|
async getAllSubscriptions() {
|
|
21
28
|
return this.get('/subscriptions/');
|
|
22
29
|
}
|
|
30
|
+
/**
|
|
31
|
+
* Get all available subscription products and their prices
|
|
32
|
+
* GET /subscriptions/products
|
|
33
|
+
*/
|
|
34
|
+
async getSubscriptionProducts() {
|
|
35
|
+
return this.get('/subscriptions/products');
|
|
36
|
+
}
|
|
23
37
|
/**
|
|
24
38
|
* Cancel subscription but keep it active until the end of the current billing period
|
|
25
39
|
* POST /subscriptions/{subscription_id}/cancel
|
|
@@ -143,25 +143,24 @@ export interface TrackCodespaceUsageResponse {
|
|
|
143
143
|
cost_amount: number;
|
|
144
144
|
created_at: string;
|
|
145
145
|
}
|
|
146
|
+
export interface CodespaceTaskUsageData {
|
|
147
|
+
total_records: number;
|
|
148
|
+
total_credits_consumed: number;
|
|
149
|
+
latest_usage: string;
|
|
150
|
+
}
|
|
146
151
|
export interface CodespaceTaskUsageResponse {
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
total_input_tokens: number;
|
|
150
|
-
total_output_tokens: number;
|
|
151
|
-
total_call_seconds: number;
|
|
152
|
-
total_cost: number;
|
|
153
|
-
};
|
|
154
|
-
usage_records: TrackCodespaceUsageResponse[];
|
|
152
|
+
status: string;
|
|
153
|
+
data: CodespaceTaskUsageData;
|
|
155
154
|
}
|
|
156
155
|
export interface HealthResponse {
|
|
157
156
|
status: string;
|
|
158
157
|
timestamp: string;
|
|
159
158
|
version: string;
|
|
160
159
|
}
|
|
161
|
-
export type PeriodType =
|
|
162
|
-
export type ServiceType =
|
|
163
|
-
export type SortOrder =
|
|
164
|
-
export type SortByField =
|
|
160
|
+
export type PeriodType = '7d' | '1w' | '1m' | '3m';
|
|
161
|
+
export type ServiceType = 'docs' | 'chat' | 'codespace_task' | 'api';
|
|
162
|
+
export type SortOrder = 'asc' | 'desc';
|
|
163
|
+
export type SortByField = 'created_at' | 'credits_consumed' | 'cost_amount';
|
|
165
164
|
export interface DashboardAnalyticsRequest {
|
|
166
165
|
period?: PeriodType;
|
|
167
166
|
start_date?: string;
|
package/dist/types.d.ts
CHANGED
|
@@ -108,8 +108,8 @@ export interface Product {
|
|
|
108
108
|
id: string;
|
|
109
109
|
active: boolean;
|
|
110
110
|
name: string;
|
|
111
|
-
description: string;
|
|
112
|
-
image: string;
|
|
111
|
+
description: string | null;
|
|
112
|
+
image: string | null;
|
|
113
113
|
metadata: Record<string, any>;
|
|
114
114
|
marketing_features: string[];
|
|
115
115
|
live_mode: boolean;
|
|
@@ -140,6 +140,13 @@ export interface UserSubscriptionsResponse {
|
|
|
140
140
|
status: string;
|
|
141
141
|
data: Subscription[];
|
|
142
142
|
}
|
|
143
|
+
export interface SubscriptionProductsResponse {
|
|
144
|
+
status: string;
|
|
145
|
+
data: Array<{
|
|
146
|
+
product: Product;
|
|
147
|
+
prices: Price[];
|
|
148
|
+
}>;
|
|
149
|
+
}
|
|
143
150
|
export interface CancelSubscriptionRequest {
|
|
144
151
|
cancel_at_period_end: boolean;
|
|
145
152
|
}
|
|
@@ -148,6 +155,15 @@ export interface CancelSubscriptionResponse {
|
|
|
148
155
|
message: string;
|
|
149
156
|
data: Subscription;
|
|
150
157
|
}
|
|
158
|
+
export interface CreateCheckoutSessionRequest {
|
|
159
|
+
price_id: string;
|
|
160
|
+
success_url: string;
|
|
161
|
+
cancel_url: string;
|
|
162
|
+
}
|
|
163
|
+
export interface CreateCheckoutSessionResponse {
|
|
164
|
+
status: string;
|
|
165
|
+
checkout_url: string;
|
|
166
|
+
}
|
|
151
167
|
export interface CancellationFunnelInitiateRequest {
|
|
152
168
|
subscription_id: string;
|
|
153
169
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@codeguide/core",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.33",
|
|
4
4
|
"description": "Core package for code guidance with programmatic API",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -18,6 +18,7 @@
|
|
|
18
18
|
"test": "jest --config=jest.config.json",
|
|
19
19
|
"test:watch": "jest --config=jest.config.json --watch",
|
|
20
20
|
"test:coverage": "jest --config=jest.config.json --coverage",
|
|
21
|
+
"dev:link": "npm run build && npm link",
|
|
21
22
|
"docs:dev": "cd docs && npm run dev",
|
|
22
23
|
"docs:build": "cd docs && npm run build",
|
|
23
24
|
"docs:preview": "cd docs && npm run preview",
|
|
@@ -36,6 +36,9 @@ import {
|
|
|
36
36
|
CodespaceTaskLogsResponse,
|
|
37
37
|
StreamCodespaceTaskLogsRequest,
|
|
38
38
|
CodespaceLogStreamEvent,
|
|
39
|
+
// Project Summary Types
|
|
40
|
+
GetCodespaceProjectSummaryRequest,
|
|
41
|
+
GetCodespaceProjectSummaryResponse,
|
|
39
42
|
} from './codespace-types'
|
|
40
43
|
|
|
41
44
|
export class CodespaceService extends BaseService {
|
|
@@ -107,6 +110,25 @@ export class CodespaceService extends BaseService {
|
|
|
107
110
|
return this.get<GetCodespaceTasksByProjectResponse>(url)
|
|
108
111
|
}
|
|
109
112
|
|
|
113
|
+
/**
|
|
114
|
+
* Get aggregated statistics for all codespace tasks within a project
|
|
115
|
+
*
|
|
116
|
+
* GET /codespace/project/{project_id}/summary
|
|
117
|
+
*
|
|
118
|
+
* @param params - Request parameters including project_id
|
|
119
|
+
* @returns Promise resolving to aggregated task statistics by status
|
|
120
|
+
*/
|
|
121
|
+
async getCodespaceProjectSummary(
|
|
122
|
+
params: GetCodespaceProjectSummaryRequest
|
|
123
|
+
): Promise<GetCodespaceProjectSummaryResponse> {
|
|
124
|
+
if (!params.project_id) {
|
|
125
|
+
throw new Error('project_id is required')
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
const url = `/codespace/project/${params.project_id}/summary`
|
|
129
|
+
return this.get<GetCodespaceProjectSummaryResponse>(url)
|
|
130
|
+
}
|
|
131
|
+
|
|
110
132
|
async getCodespaceTaskDetailed(codespaceTaskId: string): Promise<CodespaceTaskDetailedResponse> {
|
|
111
133
|
if (!codespaceTaskId) {
|
|
112
134
|
throw new Error('codespace_task_id is required')
|
|
@@ -145,7 +167,7 @@ export class CodespaceService extends BaseService {
|
|
|
145
167
|
queryParams.append('sort_order', params.sort_order)
|
|
146
168
|
}
|
|
147
169
|
|
|
148
|
-
const url = `/tasks/by-codespace-id/${params.codespace_task_id}${
|
|
170
|
+
const url = `/codespace/tasks/by-codespace-id/${params.codespace_task_id}${
|
|
149
171
|
queryParams.toString() ? `?${queryParams.toString()}` : ''
|
|
150
172
|
}`
|
|
151
173
|
|
|
@@ -193,7 +215,7 @@ export class CodespaceService extends BaseService {
|
|
|
193
215
|
/**
|
|
194
216
|
* Update the final report popup state for a codespace task
|
|
195
217
|
*
|
|
196
|
-
* PATCH /task/{codespace_task_id}/final-report-popup-state
|
|
218
|
+
* PATCH /codespace/task/{codespace_task_id}/final-report-popup-state
|
|
197
219
|
*
|
|
198
220
|
* @param codespaceTaskId - The ID of the codespace task
|
|
199
221
|
* @param request - The request body containing the new popup state
|
|
@@ -213,7 +235,7 @@ export class CodespaceService extends BaseService {
|
|
|
213
235
|
}
|
|
214
236
|
|
|
215
237
|
return this.patch<UpdateFinalReportPopupStateResponse>(
|
|
216
|
-
`/task/${codespaceTaskId}/final-report-popup-state`,
|
|
238
|
+
`/codespace/task/${codespaceTaskId}/final-report-popup-state`,
|
|
217
239
|
request
|
|
218
240
|
)
|
|
219
241
|
}
|
|
@@ -497,3 +497,36 @@ export type CodespaceLogStreamEvent =
|
|
|
497
497
|
| StreamTimeoutEvent
|
|
498
498
|
| StreamErrorEvent
|
|
499
499
|
|
|
500
|
+
// ============================================================================
|
|
501
|
+
// Project Summary Endpoint Types
|
|
502
|
+
// ============================================================================
|
|
503
|
+
|
|
504
|
+
// Request parameters for project codespace summary
|
|
505
|
+
export interface GetCodespaceProjectSummaryRequest {
|
|
506
|
+
project_id: string
|
|
507
|
+
}
|
|
508
|
+
|
|
509
|
+
// Status summary interface
|
|
510
|
+
export interface CodespaceStatusSummary {
|
|
511
|
+
pending: number
|
|
512
|
+
in_progress: number
|
|
513
|
+
completed: number
|
|
514
|
+
failed: number
|
|
515
|
+
blocked: number
|
|
516
|
+
}
|
|
517
|
+
|
|
518
|
+
// Response data structure for project summary
|
|
519
|
+
export interface CodespaceProjectSummaryData {
|
|
520
|
+
project_id: string
|
|
521
|
+
total_codespace_tasks: number
|
|
522
|
+
status_summary: CodespaceStatusSummary
|
|
523
|
+
latest_task_created_at: string
|
|
524
|
+
}
|
|
525
|
+
|
|
526
|
+
// Response for project codespace summary endpoint
|
|
527
|
+
export interface GetCodespaceProjectSummaryResponse {
|
|
528
|
+
status: string
|
|
529
|
+
data: CodespaceProjectSummaryData
|
|
530
|
+
message: string
|
|
531
|
+
}
|
|
532
|
+
|
|
@@ -40,5 +40,10 @@ export type {
|
|
|
40
40
|
CodespaceLogStreamEvent,
|
|
41
41
|
// GET /tasks/by-codespace-id Types
|
|
42
42
|
GetTasksByCodespaceIdRequest,
|
|
43
|
-
GetTasksByCodespaceIdResponse
|
|
43
|
+
GetTasksByCodespaceIdResponse,
|
|
44
|
+
// Project Summary Types
|
|
45
|
+
GetCodespaceProjectSummaryRequest,
|
|
46
|
+
GetCodespaceProjectSummaryResponse,
|
|
47
|
+
CodespaceStatusSummary,
|
|
48
|
+
CodespaceProjectSummaryData
|
|
44
49
|
} from './codespace-types'
|
|
@@ -4,6 +4,9 @@ import {
|
|
|
4
4
|
UserSubscriptionsResponse,
|
|
5
5
|
CancelSubscriptionRequest,
|
|
6
6
|
CancelSubscriptionResponse,
|
|
7
|
+
SubscriptionProductsResponse,
|
|
8
|
+
CreateCheckoutSessionRequest,
|
|
9
|
+
CreateCheckoutSessionResponse,
|
|
7
10
|
} from '../../types'
|
|
8
11
|
|
|
9
12
|
export class SubscriptionService extends BaseService {
|
|
@@ -11,6 +14,16 @@ export class SubscriptionService extends BaseService {
|
|
|
11
14
|
super(config)
|
|
12
15
|
}
|
|
13
16
|
|
|
17
|
+
/**
|
|
18
|
+
* Create a Stripe checkout session for subscription purchase
|
|
19
|
+
* POST /subscriptions/create-checkout-session
|
|
20
|
+
*/
|
|
21
|
+
async createCheckoutSession(
|
|
22
|
+
request: CreateCheckoutSessionRequest
|
|
23
|
+
): Promise<CreateCheckoutSessionResponse> {
|
|
24
|
+
return this.post<CreateCheckoutSessionResponse>('/subscriptions/create-checkout-session', request)
|
|
25
|
+
}
|
|
26
|
+
|
|
14
27
|
/**
|
|
15
28
|
* Get the currently active subscription for the authenticated user
|
|
16
29
|
* GET /subscriptions/current
|
|
@@ -27,6 +40,14 @@ export class SubscriptionService extends BaseService {
|
|
|
27
40
|
return this.get<UserSubscriptionsResponse>('/subscriptions/')
|
|
28
41
|
}
|
|
29
42
|
|
|
43
|
+
/**
|
|
44
|
+
* Get all available subscription products and their prices
|
|
45
|
+
* GET /subscriptions/products
|
|
46
|
+
*/
|
|
47
|
+
async getSubscriptionProducts(): Promise<SubscriptionProductsResponse> {
|
|
48
|
+
return this.get<SubscriptionProductsResponse>('/subscriptions/products')
|
|
49
|
+
}
|
|
50
|
+
|
|
30
51
|
/**
|
|
31
52
|
* Cancel subscription but keep it active until the end of the current billing period
|
|
32
53
|
* POST /subscriptions/{subscription_id}/cancel
|
|
@@ -35,10 +56,7 @@ export class SubscriptionService extends BaseService {
|
|
|
35
56
|
subscriptionId: string,
|
|
36
57
|
request: CancelSubscriptionRequest
|
|
37
58
|
): Promise<CancelSubscriptionResponse> {
|
|
38
|
-
return this.post<CancelSubscriptionResponse>(
|
|
39
|
-
`/subscriptions/${subscriptionId}/cancel`,
|
|
40
|
-
request
|
|
41
|
-
)
|
|
59
|
+
return this.post<CancelSubscriptionResponse>(`/subscriptions/${subscriptionId}/cancel`, request)
|
|
42
60
|
}
|
|
43
61
|
|
|
44
62
|
/**
|
|
@@ -144,4 +162,4 @@ export class SubscriptionService extends BaseService {
|
|
|
144
162
|
}> {
|
|
145
163
|
return this.get(`/subscriptions/${subscriptionId}/history`)
|
|
146
164
|
}
|
|
147
|
-
}
|
|
165
|
+
}
|
|
@@ -45,7 +45,6 @@ export interface CreditCheckResponse {
|
|
|
45
45
|
model_key: string
|
|
46
46
|
}
|
|
47
47
|
|
|
48
|
-
|
|
49
48
|
export interface CreditBalance {
|
|
50
49
|
total_allotted: number
|
|
51
50
|
total_consumed: number
|
|
@@ -161,15 +160,15 @@ export interface TrackCodespaceUsageResponse {
|
|
|
161
160
|
created_at: string
|
|
162
161
|
}
|
|
163
162
|
|
|
163
|
+
export interface CodespaceTaskUsageData {
|
|
164
|
+
total_records: number
|
|
165
|
+
total_credits_consumed: number
|
|
166
|
+
latest_usage: string
|
|
167
|
+
}
|
|
168
|
+
|
|
164
169
|
export interface CodespaceTaskUsageResponse {
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
total_input_tokens: number
|
|
168
|
-
total_output_tokens: number
|
|
169
|
-
total_call_seconds: number
|
|
170
|
-
total_cost: number
|
|
171
|
-
}
|
|
172
|
-
usage_records: TrackCodespaceUsageResponse[]
|
|
170
|
+
status: string
|
|
171
|
+
data: CodespaceTaskUsageData
|
|
173
172
|
}
|
|
174
173
|
|
|
175
174
|
export interface HealthResponse {
|
|
@@ -179,10 +178,10 @@ export interface HealthResponse {
|
|
|
179
178
|
}
|
|
180
179
|
|
|
181
180
|
// Dashboard Analytics Types
|
|
182
|
-
export type PeriodType =
|
|
183
|
-
export type ServiceType =
|
|
184
|
-
export type SortOrder =
|
|
185
|
-
export type SortByField =
|
|
181
|
+
export type PeriodType = '7d' | '1w' | '1m' | '3m'
|
|
182
|
+
export type ServiceType = 'docs' | 'chat' | 'codespace_task' | 'api'
|
|
183
|
+
export type SortOrder = 'asc' | 'desc'
|
|
184
|
+
export type SortByField = 'created_at' | 'credits_consumed' | 'cost_amount'
|
|
186
185
|
|
|
187
186
|
export interface DashboardAnalyticsRequest {
|
|
188
187
|
period?: PeriodType
|
package/types.ts
CHANGED
|
@@ -136,8 +136,8 @@ export interface Product {
|
|
|
136
136
|
id: string
|
|
137
137
|
active: boolean
|
|
138
138
|
name: string
|
|
139
|
-
description: string
|
|
140
|
-
image: string
|
|
139
|
+
description: string | null
|
|
140
|
+
image: string | null
|
|
141
141
|
metadata: Record<string, any>
|
|
142
142
|
marketing_features: string[]
|
|
143
143
|
live_mode: boolean
|
|
@@ -172,6 +172,14 @@ export interface UserSubscriptionsResponse {
|
|
|
172
172
|
data: Subscription[]
|
|
173
173
|
}
|
|
174
174
|
|
|
175
|
+
export interface SubscriptionProductsResponse {
|
|
176
|
+
status: string
|
|
177
|
+
data: Array<{
|
|
178
|
+
product: Product
|
|
179
|
+
prices: Price[]
|
|
180
|
+
}>
|
|
181
|
+
}
|
|
182
|
+
|
|
175
183
|
export interface CancelSubscriptionRequest {
|
|
176
184
|
cancel_at_period_end: boolean
|
|
177
185
|
}
|
|
@@ -182,6 +190,18 @@ export interface CancelSubscriptionResponse {
|
|
|
182
190
|
data: Subscription
|
|
183
191
|
}
|
|
184
192
|
|
|
193
|
+
// Checkout Session Types
|
|
194
|
+
export interface CreateCheckoutSessionRequest {
|
|
195
|
+
price_id: string
|
|
196
|
+
success_url: string
|
|
197
|
+
cancel_url: string
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
export interface CreateCheckoutSessionResponse {
|
|
201
|
+
status: string
|
|
202
|
+
checkout_url: string
|
|
203
|
+
}
|
|
204
|
+
|
|
185
205
|
// Cancellation Funnel Types
|
|
186
206
|
export interface CancellationFunnelInitiateRequest {
|
|
187
207
|
subscription_id: string
|