@codeguide/core 0.0.1
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__/authentication.test.ts +259 -0
- package/__tests__/codeguide.test.ts +293 -0
- package/__tests__/services/base/base-service.test.ts +334 -0
- package/__tests__/services/generation/generation-service.test.ts +294 -0
- package/__tests__/services/usage/usage-service.test.ts +385 -0
- package/__tests__/simple.test.ts +10 -0
- package/__tests__/test-service.ts +37 -0
- package/api-service.ts +67 -0
- package/codeguide.ts +70 -0
- package/dist/__tests__/test-service.d.ts +12 -0
- package/dist/__tests__/test-service.js +32 -0
- package/dist/api-service.d.ts +8 -0
- package/dist/api-service.js +64 -0
- package/dist/codeguide.d.ts +14 -0
- package/dist/codeguide.js +53 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +31 -0
- package/dist/services/base/base-service.d.ts +30 -0
- package/dist/services/base/base-service.js +187 -0
- package/dist/services/base/index.d.ts +1 -0
- package/dist/services/base/index.js +5 -0
- package/dist/services/generation/generation-service.d.ts +15 -0
- package/dist/services/generation/generation-service.js +40 -0
- package/dist/services/generation/generation-types.d.ts +111 -0
- package/dist/services/generation/generation-types.js +2 -0
- package/dist/services/generation/index.d.ts +2 -0
- package/dist/services/generation/index.js +20 -0
- package/dist/services/index.d.ts +11 -0
- package/dist/services/index.js +45 -0
- package/dist/services/projects/index.d.ts +2 -0
- package/dist/services/projects/index.js +20 -0
- package/dist/services/projects/project-service.d.ts +14 -0
- package/dist/services/projects/project-service.js +53 -0
- package/dist/services/projects/project-types.d.ts +97 -0
- package/dist/services/projects/project-types.js +2 -0
- package/dist/services/repository-analysis/index.d.ts +2 -0
- package/dist/services/repository-analysis/index.js +20 -0
- package/dist/services/repository-analysis/repository-service.d.ts +10 -0
- package/dist/services/repository-analysis/repository-service.js +31 -0
- package/dist/services/repository-analysis/repository-types.d.ts +90 -0
- package/dist/services/repository-analysis/repository-types.js +2 -0
- package/dist/services/tasks/index.d.ts +2 -0
- package/dist/services/tasks/index.js +20 -0
- package/dist/services/tasks/task-service.d.ts +30 -0
- package/dist/services/tasks/task-service.js +105 -0
- package/dist/services/tasks/task-types.d.ts +144 -0
- package/dist/services/tasks/task-types.js +2 -0
- package/dist/services/usage/index.d.ts +2 -0
- package/dist/services/usage/index.js +20 -0
- package/dist/services/usage/usage-service.d.ts +14 -0
- package/dist/services/usage/usage-service.js +68 -0
- package/dist/services/usage/usage-types.d.ts +133 -0
- package/dist/services/usage/usage-types.js +2 -0
- package/dist/types.d.ts +42 -0
- package/dist/types.js +2 -0
- package/index.ts +12 -0
- package/jest.config.json +19 -0
- package/package.json +45 -0
- package/services/README.md +113 -0
- package/services/base/base-service.ts +230 -0
- package/services/base/index.ts +1 -0
- package/services/generation/generation-service.ts +81 -0
- package/services/generation/generation-types.ts +131 -0
- package/services/generation/index.ts +2 -0
- package/services/index.ts +22 -0
- package/services/projects/index.ts +2 -0
- package/services/projects/project-service.ts +67 -0
- package/services/projects/project-types.ts +108 -0
- package/services/repository-analysis/index.ts +2 -0
- package/services/repository-analysis/repository-service.ts +42 -0
- package/services/repository-analysis/repository-types.ts +99 -0
- package/services/tasks/index.ts +2 -0
- package/services/tasks/task-service.ts +143 -0
- package/services/tasks/task-types.ts +165 -0
- package/services/usage/index.ts +2 -0
- package/services/usage/usage-service.ts +96 -0
- package/services/usage/usage-types.ts +147 -0
- package/tsconfig.json +10 -0
- package/types.ts +51 -0
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import { BaseService } from '../base/base-service'
|
|
2
|
+
import {
|
|
3
|
+
TaskGroup,
|
|
4
|
+
ProjectTask,
|
|
5
|
+
CreateTaskGroupRequest,
|
|
6
|
+
UpdateTaskGroupRequest,
|
|
7
|
+
CreateProjectTaskRequest,
|
|
8
|
+
UpdateProjectTaskRequest,
|
|
9
|
+
TaskGroupListResponse,
|
|
10
|
+
TaskGroupResponse,
|
|
11
|
+
ProjectTaskListResponse,
|
|
12
|
+
ProjectTaskResponse,
|
|
13
|
+
PaginatedTaskGroupsRequest,
|
|
14
|
+
PaginatedTaskGroupsResponse,
|
|
15
|
+
PaginatedProjectTasksRequest,
|
|
16
|
+
PaginatedProjectTasksResponse,
|
|
17
|
+
GenerateTasksRequest,
|
|
18
|
+
GenerateTasksResponse,
|
|
19
|
+
GetTasksByProjectRequest,
|
|
20
|
+
GetTasksByProjectResponse,
|
|
21
|
+
StartTaskRequest,
|
|
22
|
+
StartTaskResponse,
|
|
23
|
+
UpdateTaskRequest,
|
|
24
|
+
UpdateTaskResponse,
|
|
25
|
+
} from './task-types'
|
|
26
|
+
|
|
27
|
+
export class TaskService extends BaseService {
|
|
28
|
+
// Task Groups
|
|
29
|
+
async getAllTaskGroups(): Promise<TaskGroup[]> {
|
|
30
|
+
const response = await this.get<TaskGroupListResponse>('/task-groups')
|
|
31
|
+
return response.data
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
async getPaginatedTaskGroups(
|
|
35
|
+
params: PaginatedTaskGroupsRequest
|
|
36
|
+
): Promise<PaginatedTaskGroupsResponse> {
|
|
37
|
+
const queryParams = new URLSearchParams()
|
|
38
|
+
|
|
39
|
+
if (params.page !== undefined) queryParams.append('page', params.page.toString())
|
|
40
|
+
if (params.page_size !== undefined) queryParams.append('page_size', params.page_size.toString())
|
|
41
|
+
if (params.project_id) queryParams.append('project_id', params.project_id)
|
|
42
|
+
|
|
43
|
+
const url = `/task-groups/paginated${queryParams.toString() ? `?${queryParams.toString()}` : ''}`
|
|
44
|
+
return this.get<PaginatedTaskGroupsResponse>(url)
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
async getTaskGroupById(taskGroupId: string): Promise<TaskGroup> {
|
|
48
|
+
const response = await this.get<TaskGroupResponse>(`/task-groups/${taskGroupId}`)
|
|
49
|
+
return response.data
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
async createTaskGroup(request: CreateTaskGroupRequest): Promise<TaskGroup> {
|
|
53
|
+
const response = await this.post<TaskGroupResponse>('/task-groups', request)
|
|
54
|
+
return response.data
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
async updateTaskGroup(taskGroupId: string, request: UpdateTaskGroupRequest): Promise<TaskGroup> {
|
|
58
|
+
const response = await this.put<TaskGroupResponse>(`/task-groups/${taskGroupId}`, request)
|
|
59
|
+
return response.data
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
async deleteTaskGroup(taskGroupId: string): Promise<{ status: string; message: string }> {
|
|
63
|
+
return this.delete<{ status: string; message: string }>(`/task-groups/${taskGroupId}`)
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// Project Tasks
|
|
67
|
+
async getAllProjectTasks(filters?: {
|
|
68
|
+
task_group_id?: string
|
|
69
|
+
parent_task_id?: string
|
|
70
|
+
status?: string
|
|
71
|
+
}): Promise<ProjectTask[]> {
|
|
72
|
+
const queryParams = new URLSearchParams()
|
|
73
|
+
|
|
74
|
+
if (filters?.task_group_id) queryParams.append('task_group_id', filters.task_group_id)
|
|
75
|
+
if (filters?.parent_task_id) queryParams.append('parent_task_id', filters.parent_task_id)
|
|
76
|
+
if (filters?.status) queryParams.append('status', filters.status)
|
|
77
|
+
|
|
78
|
+
const url = `/project-tasks${queryParams.toString() ? `?${queryParams.toString()}` : ''}`
|
|
79
|
+
const response = await this.get<ProjectTaskListResponse>(url)
|
|
80
|
+
return response.data
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
async getPaginatedProjectTasks(
|
|
84
|
+
params: PaginatedProjectTasksRequest
|
|
85
|
+
): Promise<PaginatedProjectTasksResponse> {
|
|
86
|
+
const queryParams = new URLSearchParams()
|
|
87
|
+
|
|
88
|
+
if (params.page !== undefined) queryParams.append('page', params.page.toString())
|
|
89
|
+
if (params.page_size !== undefined) queryParams.append('page_size', params.page_size.toString())
|
|
90
|
+
if (params.task_group_id) queryParams.append('task_group_id', params.task_group_id)
|
|
91
|
+
if (params.parent_task_id) queryParams.append('parent_task_id', params.parent_task_id)
|
|
92
|
+
if (params.status) queryParams.append('status', params.status)
|
|
93
|
+
if (params.search_query) queryParams.append('search_query', params.search_query)
|
|
94
|
+
|
|
95
|
+
const url = `/project-tasks/paginated${queryParams.toString() ? `?${queryParams.toString()}` : ''}`
|
|
96
|
+
return this.get<PaginatedProjectTasksResponse>(url)
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
async getProjectTaskById(taskId: string): Promise<ProjectTask> {
|
|
100
|
+
const response = await this.get<ProjectTaskResponse>(`/project-tasks/${taskId}`)
|
|
101
|
+
return response.data
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
async createProjectTask(request: CreateProjectTaskRequest): Promise<ProjectTask> {
|
|
105
|
+
const response = await this.post<ProjectTaskResponse>('/project-tasks', request)
|
|
106
|
+
return response.data
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
async updateProjectTask(taskId: string, request: UpdateProjectTaskRequest): Promise<ProjectTask> {
|
|
110
|
+
const response = await this.put<ProjectTaskResponse>(`/project-tasks/${taskId}`, request)
|
|
111
|
+
return response.data
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
async deleteProjectTask(taskId: string): Promise<{ status: string; message: string }> {
|
|
115
|
+
return this.delete<{ status: string; message: string }>(`/project-tasks/${taskId}`)
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
// Generate Tasks
|
|
119
|
+
async generateTasks(request: GenerateTasksRequest): Promise<GenerateTasksResponse> {
|
|
120
|
+
return this.post<GenerateTasksResponse>('/project-tasks/generate-tasks', request)
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
// Get Tasks by Project
|
|
124
|
+
async getTasksByProject(request: GetTasksByProjectRequest): Promise<GetTasksByProjectResponse> {
|
|
125
|
+
const queryParams = new URLSearchParams()
|
|
126
|
+
|
|
127
|
+
if (request.status) queryParams.append('status', request.status)
|
|
128
|
+
if (request.task_group_id) queryParams.append('task_group_id', request.task_group_id)
|
|
129
|
+
|
|
130
|
+
const url = `/project-tasks/by-project/${request.project_id}${queryParams.toString() ? `?${queryParams.toString()}` : ''}`
|
|
131
|
+
return this.get<GetTasksByProjectResponse>(url)
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
// Start Task
|
|
135
|
+
async startTask(request: StartTaskRequest): Promise<StartTaskResponse> {
|
|
136
|
+
return this.post<StartTaskResponse>(`/project-tasks/${request.task_id}/start`, request)
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
// Update Task
|
|
140
|
+
async updateTask(taskId: string, request: UpdateTaskRequest): Promise<UpdateTaskResponse> {
|
|
141
|
+
return this.put<UpdateTaskResponse>(`/project-tasks/${taskId}`, request)
|
|
142
|
+
}
|
|
143
|
+
}
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
export interface TaskGroup {
|
|
2
|
+
id: string
|
|
3
|
+
name: string
|
|
4
|
+
description?: string
|
|
5
|
+
user_id: string
|
|
6
|
+
project_id: string
|
|
7
|
+
created_at: string
|
|
8
|
+
updated_at: string
|
|
9
|
+
project_tasks: ProjectTask[]
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export interface ProjectTask {
|
|
13
|
+
id: string
|
|
14
|
+
title: string
|
|
15
|
+
description?: string
|
|
16
|
+
status: string
|
|
17
|
+
user_id: string
|
|
18
|
+
task_group_id: string
|
|
19
|
+
parent_task_id?: string
|
|
20
|
+
ordinal: number
|
|
21
|
+
created_at: string
|
|
22
|
+
updated_at: string
|
|
23
|
+
subtasks?: ProjectTask[]
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export interface CreateTaskGroupRequest {
|
|
27
|
+
name: string
|
|
28
|
+
description?: string
|
|
29
|
+
project_id: string
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export interface UpdateTaskGroupRequest {
|
|
33
|
+
name?: string
|
|
34
|
+
description?: string
|
|
35
|
+
project_id?: string
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export interface CreateProjectTaskRequest {
|
|
39
|
+
title: string
|
|
40
|
+
description?: string
|
|
41
|
+
task_group_id: string
|
|
42
|
+
parent_task_id?: string
|
|
43
|
+
ordinal?: number
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export interface UpdateProjectTaskRequest {
|
|
47
|
+
title?: string
|
|
48
|
+
description?: string
|
|
49
|
+
status?: string
|
|
50
|
+
task_group_id?: string
|
|
51
|
+
parent_task_id?: string
|
|
52
|
+
ordinal?: number
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export interface TaskGroupListResponse {
|
|
56
|
+
status: string
|
|
57
|
+
data: TaskGroup[]
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export interface TaskGroupResponse {
|
|
61
|
+
status: string
|
|
62
|
+
data: TaskGroup
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export interface ProjectTaskListResponse {
|
|
66
|
+
status: string
|
|
67
|
+
data: ProjectTask[]
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export interface ProjectTaskResponse {
|
|
71
|
+
status: string
|
|
72
|
+
data: ProjectTask
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export interface PaginatedTaskGroupsRequest {
|
|
76
|
+
page?: number
|
|
77
|
+
page_size?: number
|
|
78
|
+
project_id?: string
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export interface PaginatedTaskGroupsResponse {
|
|
82
|
+
status: string
|
|
83
|
+
data: TaskGroup[]
|
|
84
|
+
pagination: {
|
|
85
|
+
total: number
|
|
86
|
+
page: number
|
|
87
|
+
page_size: number
|
|
88
|
+
total_pages: number
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export interface PaginatedProjectTasksRequest {
|
|
93
|
+
page?: number
|
|
94
|
+
page_size?: number
|
|
95
|
+
task_group_id?: string
|
|
96
|
+
parent_task_id?: string
|
|
97
|
+
status?: string
|
|
98
|
+
search_query?: string
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
export interface PaginatedProjectTasksResponse {
|
|
102
|
+
status: string
|
|
103
|
+
data: ProjectTask[]
|
|
104
|
+
pagination: {
|
|
105
|
+
total: number
|
|
106
|
+
page: number
|
|
107
|
+
page_size: number
|
|
108
|
+
total_pages: number
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
export interface GenerateTasksRequest {
|
|
113
|
+
project_id: string
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
export interface GenerateTasksResponse {
|
|
117
|
+
status: string
|
|
118
|
+
message: string
|
|
119
|
+
data?: {
|
|
120
|
+
task_groups_created: number
|
|
121
|
+
tasks_created: number
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
export interface GetTasksByProjectRequest {
|
|
126
|
+
project_id: string
|
|
127
|
+
status?: string
|
|
128
|
+
task_group_id?: string
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
export interface GetTasksByProjectResponse {
|
|
132
|
+
status: string
|
|
133
|
+
data: {
|
|
134
|
+
task_groups: TaskGroup[]
|
|
135
|
+
tasks: ProjectTask[]
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
export interface StartTaskRequest {
|
|
140
|
+
task_id: string
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
export interface StartTaskResponse {
|
|
144
|
+
status: string
|
|
145
|
+
message: string
|
|
146
|
+
data: {
|
|
147
|
+
task: ProjectTask
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
export interface UpdateTaskRequest {
|
|
152
|
+
task_id: string
|
|
153
|
+
status?: string
|
|
154
|
+
ai_result?: string
|
|
155
|
+
title?: string
|
|
156
|
+
description?: string
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
export interface UpdateTaskResponse {
|
|
160
|
+
status: string
|
|
161
|
+
message: string
|
|
162
|
+
data: {
|
|
163
|
+
task: ProjectTask
|
|
164
|
+
}
|
|
165
|
+
}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { BaseService } from '../base/base-service'
|
|
2
|
+
import {
|
|
3
|
+
TrackUsageRequest,
|
|
4
|
+
TrackUsageResponse,
|
|
5
|
+
CreditBalanceResponse,
|
|
6
|
+
CreditCheckRequest,
|
|
7
|
+
CreditCheckResponse,
|
|
8
|
+
UsageSummaryRequest,
|
|
9
|
+
UsageSummaryResponse,
|
|
10
|
+
AuthorizationResponse,
|
|
11
|
+
FreeUserStatusResponse,
|
|
12
|
+
CalculateUsageRequest,
|
|
13
|
+
CalculateUsageResponse,
|
|
14
|
+
TrackCodespaceUsageRequest,
|
|
15
|
+
TrackCodespaceUsageResponse,
|
|
16
|
+
CodespaceTaskUsageResponse,
|
|
17
|
+
HealthResponse,
|
|
18
|
+
} from './usage-types'
|
|
19
|
+
|
|
20
|
+
export class UsageService extends BaseService {
|
|
21
|
+
async trackUsage(request: TrackUsageRequest): Promise<TrackUsageResponse> {
|
|
22
|
+
return this.post<TrackUsageResponse>('/usage/track', request)
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
async getCreditBalance(): Promise<CreditBalanceResponse> {
|
|
26
|
+
return this.get<CreditBalanceResponse>('/usage/credit-balance')
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
async checkCredits(params: CreditCheckRequest): Promise<CreditCheckResponse> {
|
|
30
|
+
const queryParams = new URLSearchParams()
|
|
31
|
+
|
|
32
|
+
if (params.input_tokens !== undefined)
|
|
33
|
+
queryParams.append('input_tokens', params.input_tokens.toString())
|
|
34
|
+
if (params.output_tokens !== undefined)
|
|
35
|
+
queryParams.append('output_tokens', params.output_tokens.toString())
|
|
36
|
+
if (params.call_seconds !== undefined)
|
|
37
|
+
queryParams.append('call_seconds', params.call_seconds.toString())
|
|
38
|
+
|
|
39
|
+
const url = `/usage/credit-check?${queryParams.toString()}`
|
|
40
|
+
return this.get<CreditCheckResponse>(url)
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
async getUsageSummary(params?: UsageSummaryRequest): Promise<UsageSummaryResponse> {
|
|
44
|
+
const queryParams = new URLSearchParams()
|
|
45
|
+
|
|
46
|
+
if (params?.start_date) queryParams.append('start_date', params.start_date)
|
|
47
|
+
if (params?.end_date) queryParams.append('end_date', params.end_date)
|
|
48
|
+
|
|
49
|
+
const url = `/usage/summary${queryParams.toString() ? `?${queryParams.toString()}` : ''}`
|
|
50
|
+
return this.get<UsageSummaryResponse>(url)
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
async getAuthorization(): Promise<AuthorizationResponse> {
|
|
54
|
+
return this.get<AuthorizationResponse>('/usage/authorization')
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
async getFreeUserStatus(): Promise<FreeUserStatusResponse> {
|
|
58
|
+
return this.get<FreeUserStatusResponse>('/usage/free-user-status')
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
async calculateUsageCost(params: CalculateUsageRequest): Promise<CalculateUsageResponse> {
|
|
62
|
+
const queryParams = new URLSearchParams()
|
|
63
|
+
|
|
64
|
+
queryParams.append('model_key', params.model_key)
|
|
65
|
+
if (params.input_tokens !== undefined)
|
|
66
|
+
queryParams.append('input_tokens', params.input_tokens.toString())
|
|
67
|
+
if (params.output_tokens !== undefined)
|
|
68
|
+
queryParams.append('output_tokens', params.output_tokens.toString())
|
|
69
|
+
if (params.call_seconds !== undefined)
|
|
70
|
+
queryParams.append('call_seconds', params.call_seconds.toString())
|
|
71
|
+
if (params.cost_amount !== undefined)
|
|
72
|
+
queryParams.append('cost_amount', params.cost_amount.toString())
|
|
73
|
+
|
|
74
|
+
const url = `/usage/calculate?${queryParams.toString()}`
|
|
75
|
+
return this.get<CalculateUsageResponse>(url)
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
async trackCodespaceUsage(
|
|
79
|
+
request: TrackCodespaceUsageRequest
|
|
80
|
+
): Promise<TrackCodespaceUsageResponse> {
|
|
81
|
+
return this.post<TrackCodespaceUsageResponse>('/usage/codespace/track', request)
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
async getCodespaceTaskUsage(codespaceTaskId: string): Promise<CodespaceTaskUsageResponse> {
|
|
85
|
+
return this.get<CodespaceTaskUsageResponse>(`/usage/codespace/task/${codespaceTaskId}`)
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
async healthCheck(): Promise<boolean> {
|
|
89
|
+
try {
|
|
90
|
+
const response = await this.get<HealthResponse>('/usage/health')
|
|
91
|
+
return response.status === 'healthy'
|
|
92
|
+
} catch {
|
|
93
|
+
return false
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
export interface TrackUsageRequest {
|
|
2
|
+
model_key: string
|
|
3
|
+
input_tokens: number
|
|
4
|
+
output_tokens: number
|
|
5
|
+
call_seconds?: number
|
|
6
|
+
cost_amount?: number
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export interface TrackUsageResponse {
|
|
10
|
+
success: boolean
|
|
11
|
+
credits_used: number
|
|
12
|
+
remaining_credits: number
|
|
13
|
+
message: string
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export interface CreditBalanceResponse {
|
|
17
|
+
user_id: string
|
|
18
|
+
total_consumed: number
|
|
19
|
+
total_allotted: number
|
|
20
|
+
remaining_credits: number
|
|
21
|
+
utilization_percentage: number
|
|
22
|
+
billing_cycle_start: string
|
|
23
|
+
billing_cycle_end: string
|
|
24
|
+
subscription: {
|
|
25
|
+
plan: string
|
|
26
|
+
status: string
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export interface CreditCheckRequest {
|
|
31
|
+
model_key: string
|
|
32
|
+
input_tokens?: number
|
|
33
|
+
output_tokens?: number
|
|
34
|
+
call_seconds?: number
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export interface CreditCheckResponse {
|
|
38
|
+
has_sufficient_credits: boolean
|
|
39
|
+
estimated_cost: number
|
|
40
|
+
remaining_credits: number
|
|
41
|
+
model_key: string
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export interface UsageSummaryRequest {
|
|
45
|
+
start_date?: string
|
|
46
|
+
end_date?: string
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export interface UsageSummaryResponse {
|
|
50
|
+
user_id: string
|
|
51
|
+
period: {
|
|
52
|
+
start_date: string
|
|
53
|
+
end_date: string
|
|
54
|
+
}
|
|
55
|
+
usage_summary: {
|
|
56
|
+
total_credits_used: number
|
|
57
|
+
total_calls: number
|
|
58
|
+
model_breakdown: Record<string, any>
|
|
59
|
+
daily_usage: Array<{
|
|
60
|
+
date: string
|
|
61
|
+
credits_used: number
|
|
62
|
+
calls: number
|
|
63
|
+
}>
|
|
64
|
+
}
|
|
65
|
+
subscription: {
|
|
66
|
+
plan: string
|
|
67
|
+
status: string
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export interface AuthorizationResponse {
|
|
72
|
+
user_id: string
|
|
73
|
+
subscription: {
|
|
74
|
+
plan: string
|
|
75
|
+
status: string
|
|
76
|
+
features: string[]
|
|
77
|
+
}
|
|
78
|
+
usage_limits: {
|
|
79
|
+
monthly_credits: number
|
|
80
|
+
max_calls_per_day: number
|
|
81
|
+
}
|
|
82
|
+
permissions: string[]
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export interface FreeUserStatusResponse {
|
|
86
|
+
is_free_user: boolean
|
|
87
|
+
has_available_credits: boolean
|
|
88
|
+
credits_remaining: number
|
|
89
|
+
credits_expire_at?: string
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export interface CalculateUsageRequest {
|
|
93
|
+
model_key: string
|
|
94
|
+
input_tokens?: number
|
|
95
|
+
output_tokens?: number
|
|
96
|
+
call_seconds?: number
|
|
97
|
+
cost_amount?: number
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
export interface CalculateUsageResponse {
|
|
101
|
+
model_key: string
|
|
102
|
+
estimated_cost: number
|
|
103
|
+
calculation_breakdown: {
|
|
104
|
+
input_cost: number
|
|
105
|
+
output_cost: number
|
|
106
|
+
time_cost: number
|
|
107
|
+
total_cost: number
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
export interface TrackCodespaceUsageRequest {
|
|
112
|
+
codespace_task_id: string
|
|
113
|
+
model_key: string
|
|
114
|
+
input_tokens: number
|
|
115
|
+
output_tokens: number
|
|
116
|
+
call_seconds?: number
|
|
117
|
+
cost_amount?: number
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
export interface TrackCodespaceUsageResponse {
|
|
121
|
+
id: string
|
|
122
|
+
codespace_task_id: string
|
|
123
|
+
user_id: string
|
|
124
|
+
model_key: string
|
|
125
|
+
input_tokens: number
|
|
126
|
+
output_tokens: number
|
|
127
|
+
call_seconds: number
|
|
128
|
+
cost_amount: number
|
|
129
|
+
created_at: string
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
export interface CodespaceTaskUsageResponse {
|
|
133
|
+
codespace_task_id: string
|
|
134
|
+
total_usage: {
|
|
135
|
+
total_input_tokens: number
|
|
136
|
+
total_output_tokens: number
|
|
137
|
+
total_call_seconds: number
|
|
138
|
+
total_cost: number
|
|
139
|
+
}
|
|
140
|
+
usage_records: TrackCodespaceUsageResponse[]
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
export interface HealthResponse {
|
|
144
|
+
status: string
|
|
145
|
+
timestamp: string
|
|
146
|
+
version: string
|
|
147
|
+
}
|
package/tsconfig.json
ADDED
package/types.ts
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
export interface CodeGuideRequest {
|
|
2
|
+
prompt: string
|
|
3
|
+
language?: string
|
|
4
|
+
context?: string
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export interface CodeGuideResponse {
|
|
8
|
+
id?: string
|
|
9
|
+
response?: string
|
|
10
|
+
refined_prompt?: string
|
|
11
|
+
content?: string
|
|
12
|
+
timestamp: string
|
|
13
|
+
language?: string
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export interface APIServiceConfig {
|
|
17
|
+
baseUrl: string
|
|
18
|
+
// Database API Key (highest priority) - format: sk_...
|
|
19
|
+
databaseApiKey?: string
|
|
20
|
+
// Legacy API Key (medium priority)
|
|
21
|
+
apiKey?: string
|
|
22
|
+
// Legacy User ID (for legacy auth)
|
|
23
|
+
userId?: string
|
|
24
|
+
// Clerk JWT Token (lowest priority)
|
|
25
|
+
jwtToken?: string
|
|
26
|
+
timeout?: number
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export interface AuthenticationMethod {
|
|
30
|
+
type: 'database-api-key' | 'legacy-api-key' | 'clerk-jwt'
|
|
31
|
+
priority: number
|
|
32
|
+
headers: Record<string, string>
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export interface AuthenticationResult {
|
|
36
|
+
success: boolean
|
|
37
|
+
method?: AuthenticationMethod
|
|
38
|
+
user?: {
|
|
39
|
+
id: string
|
|
40
|
+
email?: string
|
|
41
|
+
subscriptionStatus?: string
|
|
42
|
+
creditsRemaining?: number
|
|
43
|
+
}
|
|
44
|
+
error?: string
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export interface CodeGuideOptions {
|
|
48
|
+
language?: string
|
|
49
|
+
context?: string
|
|
50
|
+
verbose?: boolean
|
|
51
|
+
}
|