|
1 | 1 | import { db } from '@sim/db' |
2 | 2 | import { workspaceFiles } from '@sim/db/schema' |
| 3 | +import { createLogger } from '@sim/logger' |
3 | 4 | import { toStringOrNull } from '@sim/utils/coerce' |
4 | 5 | import { and, inArray, notInArray } from 'drizzle-orm' |
5 | 6 | import type { BaseServerTool } from '@/lib/mothership/tools/server/base-tool' |
6 | 7 |
|
| 8 | +const logger = createLogger('FileTabs') |
| 9 | + |
7 | 10 | /** Row contexts that open as a file tab: workspace files and chat uploads. */ |
8 | 11 | const FILE_TAB_CONTEXTS = ['workspace', 'mothership'] |
9 | 12 |
|
@@ -38,8 +41,16 @@ export function withFileTabFlag<TArgs, TResult extends { data?: Record<string, u |
38 | 41 | async execute(args, context) { |
39 | 42 | const result = await tool.execute(args, context) |
40 | 43 | const id = toStringOrNull(result.data?.id) |
41 | | - if (id === null || !(await findNonTabFileIds([id])).has(id)) return result |
42 | | - return { ...result, data: { ...result.data, fileTab: false } } |
| 44 | + if (id === null) return result |
| 45 | + let isTab: boolean |
| 46 | + try { |
| 47 | + isTab = !(await findNonTabFileIds([id])).has(id) |
| 48 | + } catch (error) { |
| 49 | + // The edit already saved, so a failed lookup opens no tab rather than failing it. |
| 50 | + logger.error('Could not check whether an edited file is a file tab', { id, error }) |
| 51 | + isTab = false |
| 52 | + } |
| 53 | + return isTab ? result : { ...result, data: { ...result.data, fileTab: false } } |
43 | 54 | }, |
44 | 55 | } |
45 | 56 | } |
0 commit comments