-
-
Notifications
You must be signed in to change notification settings - Fork 6.1k
fix(search): newest-first context, session lookup, jsts split, ID disambiguation #2065
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -44,8 +44,10 @@ export class DataRoutes extends BaseRouteHandler { | |||||||||||
| app.get('/api/observations/by-file', this.handleGetObservationsByFile.bind(this)); | ||||||||||||
| app.post('/api/observations/batch', this.handleGetObservationsByIds.bind(this)); | ||||||||||||
| app.get('/api/session/:id', this.handleGetSessionById.bind(this)); | ||||||||||||
| app.post('/api/sessions/batch', this.handleGetSessionSummariesByIds.bind(this)); | ||||||||||||
| app.post('/api/sdk-sessions/batch', this.handleGetSdkSessionsByIds.bind(this)); | ||||||||||||
| app.get('/api/prompt/:id', this.handleGetPromptById.bind(this)); | ||||||||||||
| app.post('/api/prompts/batch', this.handleGetPromptsByIds.bind(this)); | ||||||||||||
|
|
||||||||||||
| // Metadata endpoints | ||||||||||||
| app.get('/api/stats', this.handleGetStats.bind(this)); | ||||||||||||
|
|
@@ -187,6 +189,40 @@ export class DataRoutes extends BaseRouteHandler { | |||||||||||
| res.json(sessions[0]); | ||||||||||||
| }); | ||||||||||||
|
|
||||||||||||
| /** | ||||||||||||
| * Get session summaries by array of IDs | ||||||||||||
| * POST /api/sessions/batch | ||||||||||||
| * Body: { ids: number[], orderBy?: 'date_desc' | 'date_asc', limit?: number, project?: string } | ||||||||||||
| */ | ||||||||||||
| private handleGetSessionSummariesByIds = this.wrapHandler((req: Request, res: Response): void => { | ||||||||||||
| let { ids, orderBy, limit, project } = req.body; | ||||||||||||
|
|
||||||||||||
| // Coerce string-encoded arrays from MCP clients (e.g. "[1,2,3]" or "1,2,3") | ||||||||||||
| if (typeof ids === 'string') { | ||||||||||||
| try { ids = JSON.parse(ids); } catch { ids = ids.split(',').map(Number); } | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| if (!ids || !Array.isArray(ids)) { | ||||||||||||
| this.badRequest(res, 'ids must be an array of numbers'); | ||||||||||||
| return; | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| if (ids.length === 0) { | ||||||||||||
| res.json([]); | ||||||||||||
| return; | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| if (!ids.every((id: any) => typeof id === 'number' && Number.isInteger(id))) { | ||||||||||||
| this.badRequest(res, 'All ids must be integers'); | ||||||||||||
| return; | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| const store = this.dbManager.getSessionStore(); | ||||||||||||
| const sessions = store.getSessionSummariesByIds(ids, { orderBy, limit, project }); | ||||||||||||
|
|
||||||||||||
| res.json(sessions); | ||||||||||||
| }); | ||||||||||||
|
|
||||||||||||
| /** | ||||||||||||
| * Get SDK sessions by SDK session IDs | ||||||||||||
| * POST /api/sdk-sessions/batch | ||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Both new batch handlers ( The existing
Suggested change
|
||||||||||||
|
|
@@ -229,6 +265,40 @@ export class DataRoutes extends BaseRouteHandler { | |||||||||||
| res.json(prompts[0]); | ||||||||||||
| }); | ||||||||||||
|
|
||||||||||||
| /** | ||||||||||||
| * Get user prompts by array of IDs | ||||||||||||
| * POST /api/prompts/batch | ||||||||||||
| * Body: { ids: number[], orderBy?: 'date_desc' | 'date_asc', limit?: number, project?: string } | ||||||||||||
| */ | ||||||||||||
| private handleGetPromptsByIds = this.wrapHandler((req: Request, res: Response): void => { | ||||||||||||
| let { ids, orderBy, limit, project } = req.body; | ||||||||||||
|
|
||||||||||||
| // Coerce string-encoded arrays from MCP clients (e.g. "[1,2,3]" or "1,2,3") | ||||||||||||
| if (typeof ids === 'string') { | ||||||||||||
| try { ids = JSON.parse(ids); } catch { ids = ids.split(',').map(Number); } | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| if (!ids || !Array.isArray(ids)) { | ||||||||||||
| this.badRequest(res, 'ids must be an array of numbers'); | ||||||||||||
| return; | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| if (ids.length === 0) { | ||||||||||||
| res.json([]); | ||||||||||||
| return; | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| if (!ids.every((id: any) => typeof id === 'number' && Number.isInteger(id))) { | ||||||||||||
| this.badRequest(res, 'All ids must be integers'); | ||||||||||||
| return; | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| const store = this.dbManager.getSessionStore(); | ||||||||||||
| const prompts = store.getUserPromptsByIds(ids, { orderBy, limit, project }); | ||||||||||||
|
|
||||||||||||
| res.json(prompts); | ||||||||||||
| }); | ||||||||||||
|
|
||||||||||||
| /** | ||||||||||||
| * Get database statistics (with worker metadata) | ||||||||||||
| */ | ||||||||||||
|
|
||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new fallback (
'unknown-project') correctly prevents future writes from using the worker'sprocess.cwd(), but any observations already stored under the incorrect cwd-derived project key (from before this fix) are still stranded — they won't surface in queries scoped to the user's real project key. Worth documenting a one-time migration path (or at least a note in the changelog) so users who hit #1918 before this fix know how to recover those records.