@codeguide/core 0.0.22 → 0.0.24

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/index.ts CHANGED
@@ -12,13 +12,21 @@ export * from './services'
12
12
  export * from './types'
13
13
 
14
14
  // Export commonly used types for convenience
15
- export type { ConnectRepositoryRequest, ConnectRepositoryResponse } from './services/projects/project-types'
15
+ export type {
16
+ ConnectRepositoryRequest,
17
+ ConnectRepositoryResponse,
18
+ ProjectRepository,
19
+ GetProjectsRequest,
20
+ PaginatedProjectsRequest,
21
+ PaginatedProjectsResponse
22
+ } from './services/projects/project-types'
16
23
  export type {
17
24
  CreateCodespaceTaskRequestV2 as CreateCodespaceTaskRequest,
18
25
  CreateCodespaceTaskResponseV2 as CreateCodespaceTaskResponse,
19
26
  CreateBackgroundCodespaceTaskRequest,
20
27
  CreateBackgroundCodespaceTaskResponse,
21
28
  ModelApiKey,
29
+ Attachment,
22
30
  GetCodespaceTaskResponse,
23
31
  CodespaceTaskData,
24
32
  TechnicalDocument,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codeguide/core",
3
- "version": "0.0.22",
3
+ "version": "0.0.24",
4
4
  "description": "Core package for code guidance with programmatic API",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -10,6 +10,11 @@ import {
10
10
  CreateBackgroundCodespaceTaskResponse,
11
11
  GetCodespaceTaskResponse,
12
12
  GetProjectTasksByCodespaceResponse,
13
+ GetCodespaceTasksByProjectRequest,
14
+ GetCodespaceTasksByProjectResponse,
15
+ CodespaceTaskDetailedResponse,
16
+ CodespaceQuestionnaireRequest,
17
+ CodespaceQuestionnaireResponse,
13
18
  } from './codespace-types'
14
19
 
15
20
  export class CodespaceService extends BaseService {
@@ -17,16 +22,27 @@ export class CodespaceService extends BaseService {
17
22
  return this.post<GenerateTaskTitleResponse>('/codespace/generate-task-title', request)
18
23
  }
19
24
 
20
- async createCodespaceTask(request: CreateCodespaceTaskRequest): Promise<CreateCodespaceTaskResponse> {
25
+ async generateQuestionnaire(request: CodespaceQuestionnaireRequest): Promise<CodespaceQuestionnaireResponse> {
26
+ this.validateQuestionnaireRequest(request)
27
+ return this.post<CodespaceQuestionnaireResponse>('/codespace/generate-questionnaire', request)
28
+ }
29
+
30
+ async createCodespaceTask(
31
+ request: CreateCodespaceTaskRequest
32
+ ): Promise<CreateCodespaceTaskResponse> {
21
33
  return this.post<CreateCodespaceTaskResponse>('/codespace/create-task', request)
22
34
  }
23
35
 
24
- async createCodespaceTaskV2(request: CreateCodespaceTaskRequestV2): Promise<CreateCodespaceTaskResponseV2> {
36
+ async createCodespaceTaskV2(
37
+ request: CreateCodespaceTaskRequestV2
38
+ ): Promise<CreateCodespaceTaskResponseV2> {
25
39
  this.validateCodespaceTaskRequest(request)
26
40
  return this.post<CreateCodespaceTaskResponseV2>('/codespace/task', request)
27
41
  }
28
42
 
29
- async createBackgroundCodespaceTask(request: CreateBackgroundCodespaceTaskRequest): Promise<CreateBackgroundCodespaceTaskResponse> {
43
+ async createBackgroundCodespaceTask(
44
+ request: CreateBackgroundCodespaceTaskRequest
45
+ ): Promise<CreateBackgroundCodespaceTaskResponse> {
30
46
  this.validateCodespaceTaskRequest(request)
31
47
  return this.post<CreateBackgroundCodespaceTaskResponse>('/codespace/task/background', request)
32
48
  }
@@ -38,11 +54,41 @@ export class CodespaceService extends BaseService {
38
54
  return this.get<GetCodespaceTaskResponse>(`/codespace/task/${codespaceTaskId}`)
39
55
  }
40
56
 
41
- async getProjectTasksByCodespace(codespaceTaskId: string): Promise<GetProjectTasksByCodespaceResponse> {
57
+ async getProjectTasksByCodespace(
58
+ codespaceTaskId: string
59
+ ): Promise<GetProjectTasksByCodespaceResponse> {
60
+ if (!codespaceTaskId) {
61
+ throw new Error('codespace_task_id is required')
62
+ }
63
+ return this.get<GetProjectTasksByCodespaceResponse>(
64
+ `/project-tasks/by-codespace/${codespaceTaskId}`
65
+ )
66
+ }
67
+
68
+ async getCodespaceTasksByProject(
69
+ params: GetCodespaceTasksByProjectRequest
70
+ ): Promise<GetCodespaceTasksByProjectResponse> {
71
+ if (!params.project_id) {
72
+ throw new Error('project_id is required')
73
+ }
74
+
75
+ const queryParams = new URLSearchParams()
76
+
77
+ if (params.status) queryParams.append('status', params.status)
78
+ if (params.limit !== undefined) queryParams.append('limit', params.limit.toString())
79
+ if (params.offset !== undefined) queryParams.append('offset', params.offset.toString())
80
+ if (params.sort_by) queryParams.append('sort_by', params.sort_by)
81
+ if (params.sort_order) queryParams.append('sort_order', params.sort_order)
82
+
83
+ const url = `/codespace/tasks/project/${params.project_id}${queryParams.toString() ? `?${queryParams.toString()}` : ''}`
84
+ return this.get<GetCodespaceTasksByProjectResponse>(url)
85
+ }
86
+
87
+ async getCodespaceTaskDetailed(codespaceTaskId: string): Promise<CodespaceTaskDetailedResponse> {
42
88
  if (!codespaceTaskId) {
43
89
  throw new Error('codespace_task_id is required')
44
90
  }
45
- return this.get<GetProjectTasksByCodespaceResponse>(`/project-tasks/by-codespace/${codespaceTaskId}`)
91
+ return this.get<CodespaceTaskDetailedResponse>(`/codespace/task/${codespaceTaskId}/detailed`)
46
92
  }
47
93
 
48
94
  private validateCodespaceTaskRequest(request: CreateCodespaceTaskRequestV2): void {
@@ -54,7 +100,10 @@ export class CodespaceService extends BaseService {
54
100
  throw new Error('task_description is required')
55
101
  }
56
102
 
57
- if (request.execution_mode && !['implementation', 'docs-only'].includes(request.execution_mode)) {
103
+ if (
104
+ request.execution_mode &&
105
+ !['implementation', 'docs-only'].includes(request.execution_mode)
106
+ ) {
58
107
  throw new Error('execution_mode must be either "implementation" or "docs-only"')
59
108
  }
60
109
 
@@ -78,5 +127,56 @@ export class CodespaceService extends BaseService {
78
127
  if (request.base_branch === undefined) {
79
128
  request.base_branch = 'main'
80
129
  }
130
+
131
+ // Validate ai_questionnaire if provided
132
+ if (request.ai_questionnaire) {
133
+ if (typeof request.ai_questionnaire !== 'object' || request.ai_questionnaire === null) {
134
+ throw new Error('ai_questionnaire must be an object')
135
+ }
136
+
137
+ // Check if it's a plain object with string keys and string values
138
+ for (const [key, value] of Object.entries(request.ai_questionnaire)) {
139
+ if (typeof key !== 'string') {
140
+ throw new Error('All ai_questionnaire keys must be strings')
141
+ }
142
+ if (typeof value !== 'string') {
143
+ throw new Error('All ai_questionnaire values must be strings')
144
+ }
145
+ }
146
+ }
147
+ }
148
+
149
+ private validateQuestionnaireRequest(request: CodespaceQuestionnaireRequest): void {
150
+ if (!request.task_description) {
151
+ throw new Error('task_description is required')
152
+ }
153
+
154
+ // Validate attachments if provided
155
+ if (request.attachments) {
156
+ if (!Array.isArray(request.attachments)) {
157
+ throw new Error('attachments must be an array')
158
+ }
159
+
160
+ for (const attachment of request.attachments) {
161
+ // Check required fields
162
+ if (!attachment.filename || typeof attachment.filename !== 'string') {
163
+ throw new Error('Each attachment must have a valid filename string')
164
+ }
165
+ if (!attachment.file_data || typeof attachment.file_data !== 'string') {
166
+ throw new Error('Each attachment must have valid file_data string')
167
+ }
168
+ if (!attachment.mime_type || typeof attachment.mime_type !== 'string') {
169
+ throw new Error('Each attachment must have a valid mime_type string')
170
+ }
171
+ if (typeof attachment.file_size !== 'number' || attachment.file_size < 0) {
172
+ throw new Error('Each attachment must have a valid file_size number (>= 0)')
173
+ }
174
+
175
+ // Validate optional description field
176
+ if (attachment.description && typeof attachment.description !== 'string') {
177
+ throw new Error('Attachment description must be a string if provided')
178
+ }
179
+ }
180
+ }
81
181
  }
82
- }
182
+ }
@@ -25,6 +25,14 @@ export interface ModelApiKey {
25
25
  api_key: string
26
26
  }
27
27
 
28
+ export interface Attachment {
29
+ filename: string
30
+ file_data: string // bytes (base64)
31
+ mime_type: string
32
+ file_size: number
33
+ description?: string
34
+ }
35
+
28
36
  export interface CreateCodespaceTaskRequestV2 {
29
37
  project_id: string
30
38
  project_repository_id?: string
@@ -40,6 +48,9 @@ export interface CreateCodespaceTaskRequestV2 {
40
48
  execution_mode?: 'implementation' | 'docs-only'
41
49
  model_name?: string
42
50
  starter_kit_repo?: string
51
+ use_enhanced_summary?: boolean
52
+ attachments?: Attachment[]
53
+ ai_questionnaire?: Record<string, string>
43
54
  }
44
55
 
45
56
  export interface CreateCodespaceTaskResponseV2 {
@@ -124,4 +135,50 @@ export interface GetProjectTasksByCodespaceResponse {
124
135
 
125
136
  export interface CreateBackgroundCodespaceTaskRequest extends CreateCodespaceTaskRequestV2 {}
126
137
 
127
- export interface CreateBackgroundCodespaceTaskResponse extends CreateCodespaceTaskResponseV2 {}
138
+ export interface CreateBackgroundCodespaceTaskResponse extends CreateCodespaceTaskResponseV2 {}
139
+
140
+ // Request parameters for getting codespace tasks by project
141
+ export interface GetCodespaceTasksByProjectRequest {
142
+ project_id: string
143
+ status?: 'completed' | 'failed' | 'in_progress' | 'created' | 'cancelled'
144
+ limit?: number
145
+ offset?: number
146
+ sort_by?: string
147
+ sort_order?: 'asc' | 'desc'
148
+ }
149
+
150
+ // Response for getting codespace tasks by project
151
+ export interface GetCodespaceTasksByProjectResponse {
152
+ status: string
153
+ data: CodespaceTaskData[]
154
+ total_count: number
155
+ message: string
156
+ }
157
+
158
+ // Response for getting detailed codespace task with relations
159
+ export interface CodespaceTaskDetailedResponse {
160
+ status: string
161
+ data: {
162
+ task: CodespaceTaskData
163
+ project: any // Project data structure
164
+ repository: any // Repository data structure
165
+ usage_summary: any // Usage statistics
166
+ }
167
+ message: string
168
+ }
169
+
170
+ export interface CodespaceQuestionnaireRequest {
171
+ task_description: string
172
+ project_context?: string
173
+ repository_info?: {
174
+ name?: string
175
+ description?: string
176
+ }
177
+ attachments?: Attachment[]
178
+ }
179
+
180
+ export interface CodespaceQuestionnaireResponse {
181
+ success: boolean
182
+ questions: string[]
183
+ message: string
184
+ }
@@ -8,8 +8,11 @@ export type {
8
8
  CreateBackgroundCodespaceTaskRequest,
9
9
  CreateBackgroundCodespaceTaskResponse,
10
10
  ModelApiKey,
11
+ Attachment,
11
12
  GetCodespaceTaskResponse,
12
13
  CodespaceTaskData,
13
14
  TechnicalDocument,
14
- GetProjectTasksByCodespaceResponse
15
+ GetProjectTasksByCodespaceResponse,
16
+ CodespaceQuestionnaireRequest,
17
+ CodespaceQuestionnaireResponse
15
18
  } from './codespace-types'
@@ -0,0 +1,226 @@
1
+ # Projects Service
2
+
3
+ The Projects Service provides functionality for managing projects and their associated repositories. This service includes filtering capabilities to retrieve projects based on whether they have connected repositories.
4
+
5
+ ## Features
6
+
7
+ ### Project Filtering by Repository Status
8
+
9
+ The service supports filtering projects based on whether they have connected repositories using the `has_repository` parameter.
10
+
11
+ #### API Methods
12
+
13
+ ##### `getAllProjects(params?: GetProjectsRequest): Promise<Project[]>`
14
+
15
+ Retrieves a list of all projects with optional filtering.
16
+
17
+ ```typescript
18
+ // Get all projects with repositories
19
+ const projectsWithRepos = await codeGuide.project.getAllProjects({
20
+ has_repository: true
21
+ })
22
+
23
+ // Get all projects without repositories
24
+ const projectsWithoutRepos = await codeGuide.project.getAllProjects({
25
+ has_repository: false
26
+ })
27
+ ```
28
+
29
+ ##### `getPaginatedProjects(params: PaginatedProjectsRequest): Promise<PaginatedProjectsResponse>`
30
+
31
+ Retrieves paginated projects with advanced filtering options.
32
+
33
+ ```typescript
34
+ // Combine repository filter with other filters
35
+ const paginatedProjects = await codeGuide.project.getPaginatedProjects({
36
+ page: 1,
37
+ page_size: 10,
38
+ has_repository: true,
39
+ status: 'active',
40
+ search_query: 'web',
41
+ sort_by_date: 'desc'
42
+ })
43
+ ```
44
+
45
+ ### Types
46
+
47
+ #### `GetProjectsRequest`
48
+
49
+ ```typescript
50
+ interface GetProjectsRequest {
51
+ has_repository?: boolean // Filter by repository status
52
+ }
53
+ ```
54
+
55
+ #### `PaginatedProjectsRequest`
56
+
57
+ ```typescript
58
+ interface PaginatedProjectsRequest {
59
+ page?: number
60
+ page_size?: number
61
+ search_query?: string
62
+ status?: string
63
+ start_date?: string
64
+ end_date?: string
65
+ sort_by_date?: 'asc' | 'desc'
66
+ has_repository?: boolean // Filter by repository status
67
+ }
68
+ ```
69
+
70
+ #### `ProjectRepository`
71
+
72
+ ```typescript
73
+ interface ProjectRepository {
74
+ id: string
75
+ project_id: string
76
+ repo_url: string
77
+ branch: string
78
+ author: string
79
+ name: string
80
+ connection_status: 'pending' | 'connected' | 'failed'
81
+ created_at: string
82
+ updated_at: string
83
+ }
84
+ ```
85
+
86
+ #### `Project`
87
+
88
+ ```typescript
89
+ interface Project {
90
+ id: string
91
+ title: string
92
+ description: string
93
+ user_id: string
94
+ created_at: string
95
+ updated_at: string
96
+ project_documents: ProjectDocument[]
97
+ project_repositories: ProjectRepository[] // Added for repository information
98
+ category?: Category
99
+ codie_tool?: CodieTool
100
+ github_url?: string
101
+ status?: string
102
+ tools_selected?: string[]
103
+ ai_questionaire?: Record<string, any>
104
+ project_outline?: Record<string, any>
105
+ }
106
+ ```
107
+
108
+ ## Usage Examples
109
+
110
+ ### Basic Filtering
111
+
112
+ ```typescript
113
+ import { CodeGuide } from '@codeguide/core'
114
+
115
+ const codeGuide = new CodeGuide({
116
+ baseURL: 'https://api.example.com',
117
+ apiKey: 'your-api-key'
118
+ })
119
+
120
+ // Get projects that have repositories connected
121
+ const projectsWithRepos = await codeGuide.project.getAllProjects({
122
+ has_repository: true
123
+ })
124
+
125
+ console.log('Projects with repositories:', projectsWithRepos.length)
126
+ projectsWithRepos.forEach(project => {
127
+ console.log(`${project.title} - ${project.project_repositories.length} repositories`)
128
+ })
129
+ ```
130
+
131
+ ### Advanced Filtering
132
+
133
+ ```typescript
134
+ // Get paginated projects without repositories, filtered by status and search
135
+ const filteredProjects = await codeGuide.project.getPaginatedProjects({
136
+ page: 1,
137
+ page_size: 20,
138
+ has_repository: false,
139
+ status: 'in_progress',
140
+ search_query: 'mobile'
141
+ })
142
+
143
+ console.log(`Found ${filteredProjects.pagination.total} projects`)
144
+ filteredProjects.data.forEach(project => {
145
+ console.log(`${project.title} - No repositories connected`)
146
+ })
147
+ ```
148
+
149
+ ### Combining with Other Features
150
+
151
+ ```typescript
152
+ // Connect a repository to a project
153
+ const connectionResult = await codeGuide.project.connectRepository(
154
+ projectId,
155
+ {
156
+ repo_url: 'https://github.com/user/repo',
157
+ branch: 'main',
158
+ github_token: 'optional-token'
159
+ }
160
+ )
161
+
162
+ // After connecting, verify the project appears in filtered results
163
+ const updatedProjects = await codeGuide.project.getAllProjects({
164
+ has_repository: true
165
+ })
166
+
167
+ const isProjectInFilteredResults = updatedProjects.some(
168
+ project => project.id === projectId
169
+ )
170
+ ```
171
+
172
+ ## Response Format
173
+
174
+ The API response includes project data with repository information:
175
+
176
+ ```json
177
+ {
178
+ "status": "success",
179
+ "data": [
180
+ {
181
+ "id": "project-uuid",
182
+ "title": "My Project",
183
+ "description": "Project description",
184
+ "project_repositories": [
185
+ {
186
+ "id": "repo-uuid",
187
+ "project_id": "project-uuid",
188
+ "repo_url": "https://github.com/user/repo",
189
+ "branch": "main",
190
+ "author": "user",
191
+ "name": "repo",
192
+ "connection_status": "connected",
193
+ "created_at": "2023-01-01T00:00:00Z",
194
+ "updated_at": "2023-01-01T00:00:00Z"
195
+ }
196
+ ],
197
+ "created_at": "2023-01-01T00:00:00Z",
198
+ "updated_at": "2023-01-01T00:00:00Z"
199
+ }
200
+ ]
201
+ }
202
+ ```
203
+
204
+ ## Error Handling
205
+
206
+ The service includes validation for repository connections:
207
+
208
+ ```typescript
209
+ try {
210
+ await codeGuide.project.connectRepository(projectId, {
211
+ repo_url: 'invalid-url',
212
+ branch: 'main'
213
+ })
214
+ } catch (error) {
215
+ console.error('Connection failed:', error.message)
216
+ // Example: "Repository URL must be a valid GitHub URL (e.g., https://github.com/user/repo)"
217
+ }
218
+ ```
219
+
220
+ ## Notes
221
+
222
+ - The `has_repository` parameter is optional
223
+ - When `has_repository=true`, only projects with at least one connected repository are returned
224
+ - When `has_repository=false`, only projects with no connected repositories are returned
225
+ - Repository information is included in the `project_repositories` field of each project
226
+ - The filtering works with both basic project listing and paginated queries
@@ -7,6 +7,7 @@ import {
7
7
  ProjectResponse,
8
8
  PaginatedProjectsRequest,
9
9
  PaginatedProjectsResponse,
10
+ GetProjectsRequest,
10
11
  GetProjectDocumentsRequest,
11
12
  GetProjectDocumentsResponse,
12
13
  ConnectRepositoryRequest,
@@ -14,8 +15,15 @@ import {
14
15
  } from './project-types'
15
16
 
16
17
  export class ProjectService extends BaseService {
17
- async getAllProjects(): Promise<Project[]> {
18
- const response = await this.get<ProjectListResponse>('/projects')
18
+ async getAllProjects(params?: GetProjectsRequest): Promise<Project[]> {
19
+ const queryParams = new URLSearchParams()
20
+
21
+ if (params?.has_repository !== undefined) {
22
+ queryParams.append('has_repository', params.has_repository.toString())
23
+ }
24
+
25
+ const url = `/projects${queryParams.toString() ? `?${queryParams.toString()}` : ''}`
26
+ const response = await this.get<ProjectListResponse>(url)
19
27
  return response.data
20
28
  }
21
29
 
@@ -29,6 +37,7 @@ export class ProjectService extends BaseService {
29
37
  if (params.start_date) queryParams.append('start_date', params.start_date)
30
38
  if (params.end_date) queryParams.append('end_date', params.end_date)
31
39
  if (params.sort_by_date) queryParams.append('sort_by_date', params.sort_by_date)
40
+ if (params.has_repository !== undefined) queryParams.append('has_repository', params.has_repository.toString())
32
41
 
33
42
  const url = `/projects/paginated${queryParams.toString() ? `?${queryParams.toString()}` : ''}`
34
43
  return this.get<PaginatedProjectsResponse>(url)
@@ -1,3 +1,15 @@
1
+ export interface ProjectRepository {
2
+ id: string
3
+ project_id: string
4
+ repo_url: string
5
+ branch: string
6
+ author: string
7
+ name: string
8
+ connection_status: 'pending' | 'connected' | 'failed'
9
+ created_at: string
10
+ updated_at: string
11
+ }
12
+
1
13
  export interface Project {
2
14
  id: string
3
15
  title: string
@@ -6,6 +18,7 @@ export interface Project {
6
18
  created_at: string
7
19
  updated_at: string
8
20
  project_documents: ProjectDocument[]
21
+ project_repositories: ProjectRepository[]
9
22
  category?: Category
10
23
  codie_tool?: CodieTool
11
24
  github_url?: string
@@ -86,6 +99,10 @@ export interface ProjectResponse {
86
99
  data: Project
87
100
  }
88
101
 
102
+ export interface GetProjectsRequest {
103
+ has_repository?: boolean
104
+ }
105
+
89
106
  export interface PaginatedProjectsRequest {
90
107
  page?: number
91
108
  page_size?: number
@@ -94,6 +111,7 @@ export interface PaginatedProjectsRequest {
94
111
  start_date?: string
95
112
  end_date?: string
96
113
  sort_by_date?: 'asc' | 'desc'
114
+ has_repository?: boolean
97
115
  }
98
116
 
99
117
  export interface PaginatedProjectsResponse {
@@ -1,8 +1,22 @@
1
+ import { Attachment } from '../codespace/codespace-types'
2
+
1
3
  export interface AnalyzeRepositoryRequest {
2
- repository_url: string
4
+ github_url: string
5
+ github_token?: string
3
6
  generate_documents?: boolean
4
7
  create_codespace_task?: boolean
5
8
  project_id?: string
9
+ codespace_task_description?: string
10
+ codespace_branch?: string
11
+ codespace_base_branch?: string
12
+ model_api_keys?: {
13
+ model_name: string
14
+ api_key: string
15
+ }[]
16
+ model_name?: string
17
+ starter_kit_repo?: string
18
+ use_enhanced_summary?: boolean
19
+ attachments?: Attachment[]
6
20
  }
7
21
 
8
22
  export interface AnalyzeRepositoryResponse {