@codeguide/core 0.0.27 → 0.0.28

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.
@@ -0,0 +1,326 @@
1
+ # Usage Service Documentation
2
+
3
+ ## Overview
4
+
5
+ The Usage Service provides methods to track usage, check credits, and retrieve authorization information for users.
6
+
7
+ ## Methods
8
+
9
+ ### `getAuthorization()`
10
+
11
+ Retrieves the authorization status and plan limits for the authenticated user. This endpoint returns different information based on whether the user has an active subscription or is on a free plan.
12
+
13
+ **Returns:** `Promise<AuthorizationResponse>`
14
+
15
+ **Response Structure:**
16
+
17
+ ```typescript
18
+ interface AuthorizationResponse {
19
+ success: boolean
20
+ data: AuthorizationData
21
+ message: string
22
+ }
23
+
24
+ interface AuthorizationData {
25
+ user_id: string
26
+ subscription: AuthorizationSubscription | null
27
+ credit_balance: CreditBalance
28
+ has_active_subscription: boolean
29
+ has_previous_subscriptions: boolean
30
+ is_within_credit_limit: boolean
31
+ authorization_level: string
32
+ restrictions: string[]
33
+ can_create_tasks: boolean
34
+ can_analyze_repos: boolean
35
+ can_access_previous_projects: boolean
36
+ plan_limits: PlanLimits
37
+ codespace_task_limit: LimitInfo | null
38
+ }
39
+ ```
40
+
41
+ ## Free vs. Subscribed Users
42
+
43
+ The `/usage/authorization` endpoint returns different data structures depending on whether the user has an active subscription.
44
+
45
+ ### Free Users
46
+
47
+ For users without an active subscription:
48
+
49
+ - **`subscription`**: `null`
50
+ - **`has_active_subscription`**: `false`
51
+ - **`authorization_level`**: `"free"`
52
+ - **`codespace_task_limit`**: Contains limit information (e.g., `limit: 2`, `remaining: 2`)
53
+ - **`plan_limits.plan_type`**: `"free"`
54
+ - **`plan_limits.limits.codespace_tasks`**: Has specific limits (e.g., 2 lifetime tasks)
55
+ - **`can_access_previous_projects`**: `false`
56
+
57
+ **Example Free User Response:**
58
+
59
+ ```json
60
+ {
61
+ "success": true,
62
+ "data": {
63
+ "user_id": "user_32CKVjVlcRfh4HAqpVckgILey0Z",
64
+ "subscription": null,
65
+ "credit_balance": {
66
+ "total_allotted": 500,
67
+ "total_consumed": 0,
68
+ "remaining_credits": 500,
69
+ "is_over_limit": false,
70
+ "utilization_percentage": 0.0,
71
+ "billing_cycle_start": "2025-11-03",
72
+ "billing_cycle_end": "2025-11-10"
73
+ },
74
+ "has_active_subscription": false,
75
+ "has_previous_subscriptions": false,
76
+ "is_within_credit_limit": true,
77
+ "authorization_level": "free",
78
+ "restrictions": [],
79
+ "can_create_tasks": true,
80
+ "can_analyze_repos": true,
81
+ "can_access_previous_projects": false,
82
+ "plan_limits": {
83
+ "plan_type": "free",
84
+ "limits": {
85
+ "codespace_tasks": {
86
+ "allowed": true,
87
+ "current_usage": 0,
88
+ "limit": 2,
89
+ "remaining": 2,
90
+ "period_type": "lifetime",
91
+ "period_start": null,
92
+ "period_end": null,
93
+ "message": "Can create 2 more codespace tasks. 2 codespace tasks (lifetime limit)",
94
+ "is_unlimited": false
95
+ },
96
+ "api_calls": {
97
+ "limit": 500,
98
+ "period": "7_days",
99
+ "description": "500 API credits (valid for 7 days)",
100
+ "is_unlimited": false
101
+ },
102
+ "storage_gb": {
103
+ "limit": 1,
104
+ "period": "lifetime",
105
+ "description": "1 GB storage",
106
+ "is_unlimited": false
107
+ },
108
+ "projects": {
109
+ "limit": 3,
110
+ "period": "lifetime",
111
+ "description": "3 projects maximum",
112
+ "is_unlimited": false
113
+ },
114
+ "collaborators": {
115
+ "limit": 0,
116
+ "period": "lifetime",
117
+ "description": "No team collaboration",
118
+ "is_unlimited": false
119
+ }
120
+ }
121
+ },
122
+ "codespace_task_limit": {
123
+ "allowed": true,
124
+ "current_usage": 0,
125
+ "limit": 2,
126
+ "remaining": 2,
127
+ "period_type": "lifetime",
128
+ "period_start": null,
129
+ "period_end": null,
130
+ "message": "Can create 2 more codespace tasks. 2 codespace tasks (lifetime limit)",
131
+ "is_unlimited": false
132
+ }
133
+ },
134
+ "message": "Authorization status retrieved successfully"
135
+ }
136
+ ```
137
+
138
+ ### Subscribed Users
139
+
140
+ For users with an active subscription:
141
+
142
+ - **`subscription`**: Contains detailed subscription information:
143
+ - `id`: Subscription ID
144
+ - `status`: Subscription status (e.g., `"active"`)
145
+ - `interval`: Billing interval (e.g., `"month"`, `"year"`)
146
+ - `current_period_start`: ISO 8601 timestamp
147
+ - `current_period_end`: ISO 8601 timestamp
148
+ - `price_id`: Stripe price ID
149
+ - `product_name`: Product name (can be `null`)
150
+ - `plan_name`: Plan name (e.g., `"Monthly Plan"`)
151
+ - **`has_active_subscription`**: `true`
152
+ - **`authorization_level`**: Plan tier (e.g., `"basic"`, `"pro"`)
153
+ - **`codespace_task_limit`**: `null` (when unlimited) or limit information
154
+ - **`plan_limits.plan_type`**: Plan tier name
155
+ - **`plan_limits.limits.codespace_tasks`**: May have `limit: -1` and `is_unlimited: true` for unlimited plans
156
+ - **`can_access_previous_projects`**: `true`
157
+
158
+ **Example Subscribed User Response:**
159
+
160
+ ```json
161
+ {
162
+ "success": true,
163
+ "data": {
164
+ "user_id": "user_2qaB6nlVH3R9QXhQZpt1nmVDymN",
165
+ "subscription": {
166
+ "id": "sub_1RbggdFb0vIg7N8EFOPTEhDh",
167
+ "status": "active",
168
+ "interval": "month",
169
+ "current_period_start": "2025-10-19T11:31:19+00:00",
170
+ "current_period_end": "2025-11-19T11:31:19+00:00",
171
+ "price_id": "price_1QYtmGFb0vIg7N8E71nw8g27",
172
+ "product_name": null,
173
+ "plan_name": "Monthly Plan"
174
+ },
175
+ "credit_balance": {
176
+ "total_allotted": 5000,
177
+ "total_consumed": 658,
178
+ "remaining_credits": 4342,
179
+ "is_over_limit": false,
180
+ "utilization_percentage": 13.16,
181
+ "billing_cycle_start": "2025-10-19",
182
+ "billing_cycle_end": "2025-11-19"
183
+ },
184
+ "has_active_subscription": true,
185
+ "has_previous_subscriptions": true,
186
+ "is_within_credit_limit": true,
187
+ "authorization_level": "basic",
188
+ "restrictions": [],
189
+ "can_create_tasks": true,
190
+ "can_analyze_repos": true,
191
+ "can_access_previous_projects": true,
192
+ "plan_limits": {
193
+ "plan_type": "basic",
194
+ "limits": {
195
+ "codespace_tasks": {
196
+ "allowed": true,
197
+ "current_usage": 0,
198
+ "limit": -1,
199
+ "remaining": -1,
200
+ "period_type": "monthly",
201
+ "period_start": null,
202
+ "period_end": null,
203
+ "message": "Unlimited codespace tasks",
204
+ "is_unlimited": true
205
+ },
206
+ "api_calls": {
207
+ "limit": 5000,
208
+ "period": "monthly",
209
+ "description": "5000 API credits per month",
210
+ "is_unlimited": false
211
+ },
212
+ "storage_gb": {
213
+ "limit": 10,
214
+ "period": "lifetime",
215
+ "description": "10 GB storage",
216
+ "is_unlimited": false
217
+ },
218
+ "projects": {
219
+ "limit": 20,
220
+ "period": "lifetime",
221
+ "description": "20 projects maximum",
222
+ "is_unlimited": false
223
+ },
224
+ "collaborators": {
225
+ "limit": 3,
226
+ "period": "monthly",
227
+ "description": "3 team collaborators",
228
+ "is_unlimited": false
229
+ }
230
+ }
231
+ },
232
+ "codespace_task_limit": null
233
+ },
234
+ "message": "Authorization status retrieved successfully"
235
+ }
236
+ ```
237
+
238
+ ## Key Differences Summary
239
+
240
+ | Feature | Free Users | Subscribed Users |
241
+ | ------------------------------------------------- | --------------------------- | -------------------------------------- |
242
+ | `subscription` | `null` | `AuthorizationSubscription` object |
243
+ | `has_active_subscription` | `false` | `true` |
244
+ | `authorization_level` | `"free"` | Plan tier (e.g., `"basic"`, `"pro"`) |
245
+ | `codespace_task_limit` | `LimitInfo` object | `null` (when unlimited) or `LimitInfo` |
246
+ | `plan_limits.limits.codespace_tasks.limit` | Positive number (e.g., `2`) | `-1` for unlimited |
247
+ | `plan_limits.limits.codespace_tasks.is_unlimited` | `false` | `true` for unlimited plans |
248
+ | `can_access_previous_projects` | `false` | `true` |
249
+ | Credit limits | Lower (e.g., 500) | Higher (e.g., 5000+) |
250
+ | Billing cycle | 7 days | Monthly/Yearly |
251
+
252
+ ## Usage Example
253
+
254
+ ```typescript
255
+ import { CodeGuide } from '@codeguide/core'
256
+
257
+ const codeguide = new CodeGuide({
258
+ baseUrl: 'https://api.codeguide.app',
259
+ databaseApiKey: 'sk_your_key',
260
+ })
261
+
262
+ // Get authorization status
263
+ const auth = await codeguide.usage.getAuthorization()
264
+
265
+ if (auth.data.has_active_subscription) {
266
+ console.log(`User has ${auth.data.plan_limits.plan_type} subscription`)
267
+ console.log(`Subscription: ${auth.data.subscription?.plan_name}`)
268
+
269
+ if (auth.data.codespace_task_limit === null) {
270
+ console.log('Unlimited codespace tasks')
271
+ }
272
+ } else {
273
+ console.log('Free user')
274
+ console.log(`Remaining codespace tasks: ${auth.data.codespace_task_limit?.remaining}`)
275
+ }
276
+ ```
277
+
278
+ ## Type Definitions
279
+
280
+ ```typescript
281
+ interface AuthorizationSubscription {
282
+ id: string
283
+ status: string
284
+ interval: string
285
+ current_period_start: string
286
+ current_period_end: string
287
+ price_id: string
288
+ product_name: string | null
289
+ plan_name: string
290
+ }
291
+
292
+ interface CreditBalance {
293
+ total_allotted: number
294
+ total_consumed: number
295
+ remaining_credits: number
296
+ is_over_limit: boolean
297
+ utilization_percentage: number
298
+ billing_cycle_start: string
299
+ billing_cycle_end: string
300
+ }
301
+
302
+ interface LimitInfo {
303
+ allowed?: boolean
304
+ current_usage?: number
305
+ limit: number // -1 for unlimited
306
+ remaining?: number // -1 for unlimited
307
+ period_type?: string
308
+ period_start?: string | null
309
+ period_end?: string | null
310
+ message?: string
311
+ is_unlimited: boolean
312
+ period?: string
313
+ description?: string
314
+ }
315
+
316
+ interface PlanLimits {
317
+ plan_type: string
318
+ limits: {
319
+ codespace_tasks: LimitInfo
320
+ api_calls: LimitInfo
321
+ storage_gb: LimitInfo
322
+ projects: LimitInfo
323
+ collaborators: LimitInfo
324
+ }
325
+ }
326
+ ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codeguide/core",
3
- "version": "0.0.27",
3
+ "version": "0.0.28",
4
4
  "description": "Core package for code guidance with programmatic API",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -29,7 +29,9 @@ export class CodespaceService extends BaseService {
29
29
  return this.post<GenerateTaskTitleResponse>('/codespace/generate-task-title', request)
30
30
  }
31
31
 
32
- async generateQuestionnaire(request: CodespaceQuestionnaireRequest): Promise<CodespaceQuestionnaireResponse> {
32
+ async generateQuestionnaire(
33
+ request: CodespaceQuestionnaireRequest
34
+ ): Promise<CodespaceQuestionnaireResponse> {
33
35
  this.validateQuestionnaireRequest(request)
34
36
  return this.post<CodespaceQuestionnaireResponse>('/codespace/generate-questionnaire', request)
35
37
  }
@@ -112,9 +114,7 @@ export class CodespaceService extends BaseService {
112
114
  */
113
115
  async getCodespaceModels(query?: GetCodespaceModelsQuery): Promise<GetCodespaceModelsResponse> {
114
116
  const params = this.buildQueryParams(query)
115
- const url = params
116
- ? `/api/codespace-models/models?${params}`
117
- : '/api/codespace-models/models'
117
+ const url = params ? `/api/codespace-models/models?${params}` : '/api/codespace-models/models'
118
118
 
119
119
  return this.get<GetCodespaceModelsResponse>(url)
120
120
  }
@@ -172,7 +172,9 @@ export class CodespaceService extends BaseService {
172
172
  if (!providerId) {
173
173
  throw new Error('provider_id is required')
174
174
  }
175
- return this.get<GetModelsByProviderResponse>(`/api/codespace-models/providers/${providerId}/models`)
175
+ return this.get<GetModelsByProviderResponse>(
176
+ `/api/codespace-models/providers/${providerId}/models`
177
+ )
176
178
  }
177
179
 
178
180
  /**
@@ -206,9 +208,9 @@ export class CodespaceService extends BaseService {
206
208
 
207
209
  if (
208
210
  request.execution_mode &&
209
- !['implementation', 'docs-only'].includes(request.execution_mode)
211
+ !['implementation', 'docs-only', 'direct'].includes(request.execution_mode)
210
212
  ) {
211
- throw new Error('execution_mode must be either "implementation" or "docs-only"')
213
+ throw new Error('execution_mode must be either "implementation", "docs-only", or "direct"')
212
214
  }
213
215
 
214
216
  // Validate model_api_keys if provided
@@ -237,7 +239,7 @@ export class CodespaceService extends BaseService {
237
239
  if (typeof request.ai_questionnaire !== 'object' || request.ai_questionnaire === null) {
238
240
  throw new Error('ai_questionnaire must be an object')
239
241
  }
240
-
242
+
241
243
  // Check if it's a plain object with string keys and string values
242
244
  for (const [key, value] of Object.entries(request.ai_questionnaire)) {
243
245
  if (typeof key !== 'string') {
@@ -46,7 +46,7 @@ export interface CreateCodespaceTaskRequestV2 {
46
46
  model_api_keys?: ModelApiKey[]
47
47
  github_token?: string
48
48
  codespace_task_id?: string
49
- execution_mode?: 'implementation' | 'docs-only'
49
+ execution_mode?: 'implementation' | 'docs-only' | 'direct'
50
50
  model_name?: string
51
51
  starter_kit_repo?: string
52
52
  use_enhanced_summary?: boolean
package/services/index.ts CHANGED
@@ -19,6 +19,7 @@ export { CancellationFunnelService } from './cancellation-funnel'
19
19
  export { CodespaceService } from './codespace'
20
20
  export { ExternalTokenService } from './external-tokens'
21
21
  export { SecurityKeysService } from './security-keys'
22
+ export { UserService } from './users'
22
23
 
23
24
  // Re-export all types for convenience
24
25
  export * from './generation'
@@ -32,3 +33,4 @@ export * from './cancellation-funnel'
32
33
  export * from './codespace'
33
34
  export * from './external-tokens'
34
35
  export * from './security-keys'
36
+ export * from './users'
@@ -9,6 +9,7 @@ export interface AnalyzeRepositoryRequest {
9
9
  codespace_task_description?: string
10
10
  codespace_branch?: string
11
11
  codespace_base_branch?: string
12
+ execution_mode?: 'implementation' | 'docs-only' | 'direct'
12
13
  model_api_keys?: {
13
14
  model_name: string
14
15
  api_key: string
@@ -68,18 +68,72 @@ export interface UsageSummaryResponse {
68
68
  }
69
69
  }
70
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
71
+ export interface CreditBalance {
72
+ total_allotted: number
73
+ total_consumed: number
74
+ remaining_credits: number
75
+ is_over_limit: boolean
76
+ utilization_percentage: number
77
+ billing_cycle_start: string
78
+ billing_cycle_end: string
79
+ }
80
+
81
+ export interface LimitInfo {
82
+ allowed?: boolean
83
+ current_usage?: number
84
+ limit: number
85
+ remaining?: number
86
+ period_type?: string
87
+ period_start?: string | null
88
+ period_end?: string | null
89
+ message?: string
90
+ is_unlimited: boolean
91
+ period?: string
92
+ description?: string
93
+ }
94
+
95
+ export interface PlanLimits {
96
+ plan_type: string
97
+ limits: {
98
+ codespace_tasks: LimitInfo
99
+ api_calls: LimitInfo
100
+ storage_gb: LimitInfo
101
+ projects: LimitInfo
102
+ collaborators: LimitInfo
81
103
  }
82
- permissions: string[]
104
+ }
105
+
106
+ export interface AuthorizationSubscription {
107
+ id: string
108
+ status: string
109
+ interval: string
110
+ current_period_start: string
111
+ current_period_end: string
112
+ price_id: string
113
+ product_name: string | null
114
+ plan_name: string
115
+ }
116
+
117
+ export interface AuthorizationData {
118
+ user_id: string
119
+ subscription: AuthorizationSubscription | null
120
+ credit_balance: CreditBalance
121
+ has_active_subscription: boolean
122
+ has_previous_subscriptions: boolean
123
+ is_within_credit_limit: boolean
124
+ authorization_level: string
125
+ restrictions: string[]
126
+ can_create_tasks: boolean
127
+ can_analyze_repos: boolean
128
+ can_access_previous_projects: boolean
129
+ plan_limits: PlanLimits
130
+ codespace_task_limit: LimitInfo | null
131
+ }
132
+
133
+ export interface AuthorizationResponse {
134
+ success: boolean
135
+ data: AuthorizationData
136
+ message: string
83
137
  }
84
138
 
85
139
  export interface FreeUserStatusResponse {
@@ -0,0 +1,2 @@
1
+ export { UserService } from './user-service'
2
+ export * from './user-types'
@@ -0,0 +1,15 @@
1
+ import { BaseService } from '../base/base-service'
2
+ import { GetCurrentClerkUserResponse } from './user-types'
3
+
4
+ export class UserService extends BaseService {
5
+ /**
6
+ * Get the current Clerk user information
7
+ *
8
+ * GET /users/me/clerk
9
+ *
10
+ * @returns Promise resolving to the current Clerk user data
11
+ */
12
+ async getCurrentClerkUser(): Promise<GetCurrentClerkUserResponse> {
13
+ return this.get<GetCurrentClerkUserResponse>('/users/me/clerk')
14
+ }
15
+ }
@@ -0,0 +1,59 @@
1
+ /**
2
+ * Email address verification information
3
+ */
4
+ export interface EmailVerification {
5
+ status: 'verified' | 'unverified'
6
+ strategy: string
7
+ }
8
+
9
+ /**
10
+ * Email address information
11
+ */
12
+ export interface EmailAddress {
13
+ id: string
14
+ email_address: string
15
+ verification: EmailVerification
16
+ }
17
+
18
+ /**
19
+ * Clerk user metadata
20
+ */
21
+ export interface ClerkUserMetadata {
22
+ [key: string]: any
23
+ }
24
+
25
+ /**
26
+ * Clerk user data structure
27
+ */
28
+ export interface ClerkUserData {
29
+ user_id: string
30
+ first_name: string | null
31
+ last_name: string | null
32
+ username: string | null
33
+ email_addresses: EmailAddress[]
34
+ phone_numbers: Array<{
35
+ id: string
36
+ phone_number: string
37
+ verification: {
38
+ status: 'verified' | 'unverified'
39
+ strategy: string
40
+ }
41
+ }>
42
+ primary_email_address: string | null
43
+ primary_phone_number: string | null
44
+ image_url: string | null
45
+ created_at: number
46
+ updated_at: number
47
+ last_sign_in_at: number | null
48
+ public_metadata: ClerkUserMetadata
49
+ private_metadata: ClerkUserMetadata
50
+ unsafe_metadata: ClerkUserMetadata
51
+ }
52
+
53
+ /**
54
+ * Response for getting current Clerk user
55
+ */
56
+ export interface GetCurrentClerkUserResponse {
57
+ status: 'success' | 'error'
58
+ data: ClerkUserData
59
+ }