@codeguide/core 0.0.27 → 0.0.29
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +50 -41
- package/__tests__/services/codespace/codespace-v2.test.ts +29 -18
- package/__tests__/services/usage/usage-service.test.ts +597 -85
- package/codeguide.ts +6 -0
- package/dist/codeguide.d.ts +3 -1
- package/dist/codeguide.js +2 -0
- package/dist/index.d.ts +4 -3
- package/dist/services/base/base-service.d.ts +21 -0
- package/dist/services/base/base-service.js +114 -0
- package/dist/services/codespace/codespace-service.d.ts +55 -1
- package/dist/services/codespace/codespace-service.js +260 -5
- package/dist/services/codespace/codespace-types.d.ts +193 -13
- package/dist/services/codespace/index.d.ts +1 -1
- package/dist/services/index.d.ts +4 -0
- package/dist/services/index.js +7 -1
- package/dist/services/projects/project-types.d.ts +66 -32
- package/dist/services/repository-analysis/repository-types.d.ts +1 -0
- package/dist/services/starter-kits/index.d.ts +2 -0
- package/dist/services/starter-kits/index.js +20 -0
- package/dist/services/starter-kits/starter-kits-service.d.ts +13 -0
- package/dist/services/starter-kits/starter-kits-service.js +27 -0
- package/dist/services/starter-kits/starter-kits-types.d.ts +34 -0
- package/dist/services/starter-kits/starter-kits-types.js +2 -0
- package/dist/services/tasks/task-service.d.ts +2 -1
- package/dist/services/tasks/task-service.js +8 -0
- package/dist/services/tasks/task-types.d.ts +26 -7
- package/dist/services/usage/usage-service.d.ts +5 -2
- package/dist/services/usage/usage-service.js +58 -9
- package/dist/services/usage/usage-types.d.ts +207 -34
- package/dist/services/users/index.d.ts +2 -0
- package/dist/services/users/index.js +20 -0
- package/dist/services/users/user-service.d.ts +12 -0
- package/dist/services/users/user-service.js +17 -0
- package/dist/services/users/user-types.d.ts +55 -0
- package/dist/services/users/user-types.js +2 -0
- package/docs/.vitepress/README.md +51 -0
- package/docs/.vitepress/config.ts +139 -0
- package/docs/.vitepress/theme/custom.css +80 -0
- package/docs/.vitepress/theme/index.ts +13 -0
- package/docs/.vitepress/tsconfig.json +19 -0
- package/docs/QUICKSTART.md +77 -0
- package/docs/README.md +134 -0
- package/docs/README_SETUP.md +46 -0
- package/docs/authentication.md +351 -0
- package/docs/codeguide-client.md +350 -0
- package/docs/codespace-models.md +1004 -0
- package/docs/codespace-service.md +558 -81
- package/docs/index.md +135 -0
- package/docs/package.json +14 -0
- package/docs/projects-service.md +688 -0
- package/docs/security-keys-service.md +773 -0
- package/docs/starter-kits-service.md +249 -0
- package/docs/task-service.md +955 -0
- package/docs/testsprite_tests/TC001_Homepage_Load_and_Hero_Section_Display.py +70 -0
- package/docs/testsprite_tests/TC002_Sidebar_Navigation_ExpandCollapse_Functionality.py +73 -0
- package/docs/testsprite_tests/TC003_Full_Text_Local_Search_with_Keyboard_Shortcut.py +90 -0
- package/docs/testsprite_tests/TC004_Dark_Mode_Toggle_and_Persistence.py +73 -0
- package/docs/testsprite_tests/TC005_Mobile_Responsiveness_and_Touch_Navigation.py +113 -0
- package/docs/testsprite_tests/TC006_GitHub_Integration_Edit_this_page_Links.py +73 -0
- package/docs/testsprite_tests/TC007_Syntax_Highlighting_and_Code_Copy_Functionality.py +73 -0
- package/docs/testsprite_tests/TC008_Auto_Generated_Table_of_Contents_Accuracy.py +73 -0
- package/docs/testsprite_tests/TC009_SEO_and_Content_Discoverability_Verification.py +73 -0
- package/docs/testsprite_tests/TC010_Accessibility_Compliance_WCAG_AA.py +73 -0
- package/docs/testsprite_tests/TC011_Local_Development_Workflow_Build_and_Hot_Reload.py +74 -0
- package/docs/testsprite_tests/TC012_Performance_Metrics_Compliance.py +73 -0
- package/docs/testsprite_tests/standard_prd.json +122 -0
- package/docs/testsprite_tests/testsprite-mcp-test-report.html +2508 -0
- package/docs/testsprite_tests/testsprite-mcp-test-report.md +273 -0
- package/docs/testsprite_tests/testsprite_frontend_test_plan.json +390 -0
- package/docs/usage-service.md +616 -0
- package/index.ts +11 -3
- package/package.json +16 -2
- package/plans/CODESPACE_LOGS_STREAMING_GUIDE.md +320 -0
- package/plans/CODESPACE_TASK_LOGS_API_COMPLETE_GUIDE.md +821 -0
- package/services/base/base-service.ts +130 -0
- package/services/codespace/codespace-service.ts +347 -8
- package/services/codespace/codespace-types.ts +263 -14
- package/services/codespace/index.ts +16 -1
- package/services/index.ts +4 -0
- package/services/projects/README.md +107 -34
- package/services/projects/project-types.ts +69 -32
- package/services/repository-analysis/repository-types.ts +1 -0
- package/services/starter-kits/index.ts +2 -0
- package/services/starter-kits/starter-kits-service.ts +33 -0
- package/services/starter-kits/starter-kits-types.ts +38 -0
- package/services/tasks/task-service.ts +10 -0
- package/services/tasks/task-types.ts +29 -7
- package/services/usage/usage-service.ts +59 -10
- package/services/usage/usage-types.ts +239 -34
- package/services/users/index.ts +2 -0
- package/services/users/user-service.ts +15 -0
- package/services/users/user-types.ts +59 -0
|
@@ -0,0 +1,320 @@
|
|
|
1
|
+
# Codespace Logs Streaming Guide
|
|
2
|
+
|
|
3
|
+
## Overview
|
|
4
|
+
The codespace logs API now supports real-time streaming using Server-Sent Events (SSE). This allows you to monitor logs from long-running codespace tasks in real-time.
|
|
5
|
+
|
|
6
|
+
## Endpoints
|
|
7
|
+
|
|
8
|
+
### 1. Standard REST API (Polling)
|
|
9
|
+
```
|
|
10
|
+
GET /codespace/task/{codespace_task_id}/logs
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
**Query Parameters:**
|
|
14
|
+
- `limit` (1-500, default: 50) - Number of logs to return
|
|
15
|
+
- `offset` (default: 0) - Pagination offset
|
|
16
|
+
- `log_type` - Filter by type (thinking, coding, info, error, success)
|
|
17
|
+
- `step_name` - Filter by step name (partial matching)
|
|
18
|
+
- `search` - Search in message content
|
|
19
|
+
- `sort_by` (created_at, step_name, log_type) - Sort field
|
|
20
|
+
- `sort_order` (asc, desc) - Sort order
|
|
21
|
+
- `since` - Get logs after timestamp (for incremental updates)
|
|
22
|
+
|
|
23
|
+
### 2. Real-time Streaming (SSE) ⭐
|
|
24
|
+
```
|
|
25
|
+
GET /codespace/task/{codespace_task_id}/logs/stream
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
**Query Parameters:**
|
|
29
|
+
- `since` (optional) - Start from timestamp (gets recent logs if not provided)
|
|
30
|
+
- `timeout` (30-1800 seconds, default: 300) - Stream timeout
|
|
31
|
+
|
|
32
|
+
## Client Implementation Examples
|
|
33
|
+
|
|
34
|
+
### JavaScript/TypeScript (Recommended)
|
|
35
|
+
|
|
36
|
+
```javascript
|
|
37
|
+
// Basic streaming setup
|
|
38
|
+
const taskLogsStream = (taskId) => {
|
|
39
|
+
const eventSource = new EventSource(
|
|
40
|
+
`/codespace/task/${taskId}/logs/stream`,
|
|
41
|
+
{
|
|
42
|
+
headers: {
|
|
43
|
+
'Authorization': `Bearer ${yourAuthToken}`
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
);
|
|
47
|
+
|
|
48
|
+
// Listen for new logs
|
|
49
|
+
eventSource.addEventListener('log', (event) => {
|
|
50
|
+
const log = JSON.parse(event.data);
|
|
51
|
+
console.log('New log:', log);
|
|
52
|
+
|
|
53
|
+
// Update UI
|
|
54
|
+
appendLogToTerminal(log);
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
// Listen for heartbeat (keep-alive)
|
|
58
|
+
eventSource.addEventListener('heartbeat', (event) => {
|
|
59
|
+
const data = JSON.parse(event.data);
|
|
60
|
+
console.log('Heartbeat:', data.timestamp);
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
// Listen for completion
|
|
64
|
+
eventSource.addEventListener('complete', (event) => {
|
|
65
|
+
console.log('Task completed!');
|
|
66
|
+
eventSource.close();
|
|
67
|
+
showCompletionMessage();
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
// Handle errors
|
|
71
|
+
eventSource.addEventListener('error', (event) => {
|
|
72
|
+
console.error('Stream error:', event);
|
|
73
|
+
eventSource.close();
|
|
74
|
+
showErrorMessage();
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
// Handle timeout
|
|
78
|
+
eventSource.addEventListener('timeout', (event) => {
|
|
79
|
+
console.log('Stream timeout, reconnecting...');
|
|
80
|
+
eventSource.close();
|
|
81
|
+
// Optionally reconnect with the 'since' parameter
|
|
82
|
+
reconnectWithTimestamp(taskId, lastTimestamp);
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
return eventSource;
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
// Usage
|
|
89
|
+
const stream = taskLogsStream('your-codespace-task-id');
|
|
90
|
+
|
|
91
|
+
// To stop streaming
|
|
92
|
+
stream.close();
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
### React Hook Example
|
|
96
|
+
|
|
97
|
+
```jsx
|
|
98
|
+
import { useEffect, useState } from 'react';
|
|
99
|
+
|
|
100
|
+
export const useCodespaceLogs = (taskId, authToken) => {
|
|
101
|
+
const [logs, setLogs] = useState([]);
|
|
102
|
+
const [isStreaming, setIsStreaming] = useState(false);
|
|
103
|
+
const [error, setError] = useState(null);
|
|
104
|
+
|
|
105
|
+
useEffect(() => {
|
|
106
|
+
if (!taskId) return;
|
|
107
|
+
|
|
108
|
+
setIsStreaming(true);
|
|
109
|
+
setError(null);
|
|
110
|
+
|
|
111
|
+
const eventSource = new EventSource(
|
|
112
|
+
`/codespace/task/${taskId}/logs/stream`,
|
|
113
|
+
{
|
|
114
|
+
headers: {
|
|
115
|
+
'Authorization': `Bearer ${authToken}`
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
);
|
|
119
|
+
|
|
120
|
+
eventSource.addEventListener('log', (event) => {
|
|
121
|
+
const log = JSON.parse(event.data);
|
|
122
|
+
setLogs(prev => [...prev, log]);
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
eventSource.addEventListener('complete', () => {
|
|
126
|
+
setIsStreaming(false);
|
|
127
|
+
eventSource.close();
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
eventSource.addEventListener('error', () => {
|
|
131
|
+
setError('Failed to stream logs');
|
|
132
|
+
setIsStreaming(false);
|
|
133
|
+
eventSource.close();
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
return () => {
|
|
137
|
+
eventSource.close();
|
|
138
|
+
};
|
|
139
|
+
}, [taskId, authToken]);
|
|
140
|
+
|
|
141
|
+
return { logs, isStreaming, error };
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
// Usage in component
|
|
145
|
+
function LogsViewer({ taskId, authToken }) {
|
|
146
|
+
const { logs, isStreaming, error } = useCodespaceLogs(taskId, authToken);
|
|
147
|
+
|
|
148
|
+
if (error) return <div>Error: {error}</div>;
|
|
149
|
+
|
|
150
|
+
return (
|
|
151
|
+
<div className="logs-container">
|
|
152
|
+
<div className="status">
|
|
153
|
+
{isStreaming ? '🔄 Streaming...' : '✅ Complete'}
|
|
154
|
+
</div>
|
|
155
|
+
{logs.map(log => (
|
|
156
|
+
<div key={log.id} className={`log log-${log.log_type}`}>
|
|
157
|
+
<span className="timestamp">{log.created_at}</span>
|
|
158
|
+
<span className="step">{log.step_name}</span>
|
|
159
|
+
<span className="message">{log.message}</span>
|
|
160
|
+
</div>
|
|
161
|
+
))}
|
|
162
|
+
</div>
|
|
163
|
+
);
|
|
164
|
+
}
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
### Python Example
|
|
168
|
+
|
|
169
|
+
```python
|
|
170
|
+
import requests
|
|
171
|
+
import json
|
|
172
|
+
from datetime import datetime
|
|
173
|
+
|
|
174
|
+
def stream_codespace_logs(task_id, auth_token):
|
|
175
|
+
"""Stream logs from a codespace task."""
|
|
176
|
+
url = f"http://localhost:8000/codespace/task/{task_id}/logs/stream"
|
|
177
|
+
headers = {
|
|
178
|
+
'Authorization': f'Bearer {auth_token}',
|
|
179
|
+
'Accept': 'text/event-stream'
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
try:
|
|
183
|
+
response = requests.get(url, headers=headers, stream=True)
|
|
184
|
+
response.raise_for_status()
|
|
185
|
+
|
|
186
|
+
for line in response.iter_lines():
|
|
187
|
+
if line:
|
|
188
|
+
line = line.decode('utf-8')
|
|
189
|
+
|
|
190
|
+
if line.startswith('data: '):
|
|
191
|
+
data = json.loads(line[6:])
|
|
192
|
+
print(f"[{datetime.now()}] {data}")
|
|
193
|
+
elif line.startswith('event: '):
|
|
194
|
+
event_type = line[7:]
|
|
195
|
+
print(f"Event: {event_type}")
|
|
196
|
+
|
|
197
|
+
if event_type == 'complete':
|
|
198
|
+
print("Task completed!")
|
|
199
|
+
break
|
|
200
|
+
elif event_type == 'error':
|
|
201
|
+
print("Error occurred!")
|
|
202
|
+
break
|
|
203
|
+
|
|
204
|
+
except requests.exceptions.RequestException as e:
|
|
205
|
+
print(f"Error streaming logs: {e}")
|
|
206
|
+
|
|
207
|
+
# Usage
|
|
208
|
+
stream_codespace_logs('your-task-id', 'your-auth-token')
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
### curl Example (for testing)
|
|
212
|
+
|
|
213
|
+
```bash
|
|
214
|
+
# Basic stream
|
|
215
|
+
curl -N -H "Authorization: Bearer YOUR_TOKEN" \
|
|
216
|
+
"http://localhost:8000/codespace/task/TASK_ID/logs/stream"
|
|
217
|
+
|
|
218
|
+
# With custom timeout
|
|
219
|
+
curl -N -H "Authorization: Bearer YOUR_TOKEN" \
|
|
220
|
+
"http://localhost:8000/codespace/task/TASK_ID/logs/stream?timeout=600"
|
|
221
|
+
|
|
222
|
+
# Start from specific timestamp
|
|
223
|
+
curl -N -H "Authorization: Bearer YOUR_TOKEN" \
|
|
224
|
+
"http://localhost:8000/codespace/task/TASK_ID/logs/stream?since=2024-01-01T00:00:00Z"
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
## SSE Event Types
|
|
228
|
+
|
|
229
|
+
### `log`
|
|
230
|
+
```json
|
|
231
|
+
{
|
|
232
|
+
"id": "uuid",
|
|
233
|
+
"step_name": "task_creation",
|
|
234
|
+
"log_type": "info",
|
|
235
|
+
"message": "🚀 Your coding task is ready!",
|
|
236
|
+
"created_at": "2024-01-01T00:00:00Z",
|
|
237
|
+
"progress_percentage": 25,
|
|
238
|
+
"metadata": {}
|
|
239
|
+
}
|
|
240
|
+
```
|
|
241
|
+
|
|
242
|
+
### `heartbeat`
|
|
243
|
+
```json
|
|
244
|
+
{
|
|
245
|
+
"timestamp": "2024-01-01T00:00:00Z"
|
|
246
|
+
}
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
### `complete`
|
|
250
|
+
```json
|
|
251
|
+
{
|
|
252
|
+
"message": "Task completed"
|
|
253
|
+
}
|
|
254
|
+
```
|
|
255
|
+
|
|
256
|
+
### `timeout`
|
|
257
|
+
```json
|
|
258
|
+
{
|
|
259
|
+
"message": "Stream timeout reached"
|
|
260
|
+
}
|
|
261
|
+
```
|
|
262
|
+
|
|
263
|
+
### `error`
|
|
264
|
+
```json
|
|
265
|
+
{
|
|
266
|
+
"error": "Error message"
|
|
267
|
+
}
|
|
268
|
+
```
|
|
269
|
+
|
|
270
|
+
## Reconnection Strategy
|
|
271
|
+
|
|
272
|
+
For production use, implement automatic reconnection:
|
|
273
|
+
|
|
274
|
+
```javascript
|
|
275
|
+
const connectWithRetry = (taskId, maxRetries = 5) => {
|
|
276
|
+
let retryCount = 0;
|
|
277
|
+
|
|
278
|
+
const connect = () => {
|
|
279
|
+
const eventSource = new EventSource(`/codespace/task/${taskId}/logs/stream`);
|
|
280
|
+
|
|
281
|
+
eventSource.addEventListener('log', (event) => {
|
|
282
|
+
retryCount = 0; // Reset retry count on successful message
|
|
283
|
+
const log = JSON.parse(event.data);
|
|
284
|
+
handleLog(log);
|
|
285
|
+
});
|
|
286
|
+
|
|
287
|
+
eventSource.addEventListener('error', () => {
|
|
288
|
+
eventSource.close();
|
|
289
|
+
|
|
290
|
+
if (retryCount < maxRetries) {
|
|
291
|
+
retryCount++;
|
|
292
|
+
console.log(`Reconnecting... (${retryCount}/${maxRetries})`);
|
|
293
|
+
setTimeout(connect, 2000 * retryCount); // Exponential backoff
|
|
294
|
+
} else {
|
|
295
|
+
console.error('Max retries reached');
|
|
296
|
+
showErrorMessage();
|
|
297
|
+
}
|
|
298
|
+
});
|
|
299
|
+
|
|
300
|
+
return eventSource;
|
|
301
|
+
};
|
|
302
|
+
|
|
303
|
+
return connect();
|
|
304
|
+
};
|
|
305
|
+
```
|
|
306
|
+
|
|
307
|
+
## Production Considerations
|
|
308
|
+
|
|
309
|
+
1. **Authentication**: Ensure proper auth tokens are sent with SSE requests
|
|
310
|
+
2. **Error Handling**: Implement robust error handling and reconnection logic
|
|
311
|
+
3. **Rate Limiting**: Be mindful of server resources and implement client-side throttling
|
|
312
|
+
4. **Browser Compatibility**: SSE is supported in all modern browsers
|
|
313
|
+
5. **Connection Limits**: Most browsers limit concurrent SSE connections per domain (typically 6)
|
|
314
|
+
|
|
315
|
+
## Troubleshooting
|
|
316
|
+
|
|
317
|
+
- **Connection closes immediately**: Check authentication token
|
|
318
|
+
- **No logs received**: Verify task ID and user permissions
|
|
319
|
+
- **Connection times out**: Check network stability and increase timeout parameter
|
|
320
|
+
- **Server errors**: Check server logs for authentication or database issues
|