|
1 | 1 | import { isCurrentBrowserToolName } from '@sim/browser-protocol' |
2 | 2 | import { isTerminalToolName } from '@sim/terminal-protocol' |
| 3 | +import { toRecordOrNull } from '@sim/utils/object' |
3 | 4 | import { isDesktopApp } from '@/lib/desktop' |
4 | 5 | import { |
5 | 6 | MothershipStreamV1ToolPhase, |
@@ -97,12 +98,12 @@ function runToolResultSideEffects(ctx: StreamLoopContext, node: ToolNode, replay |
97 | 98 | invalidateResourceQueries(deps.queryClient, deps.workspaceId, resource.type, resource.id) |
98 | 99 | } |
99 | 100 |
|
100 | | - if (!replay && (name === ApplyFileEdit.id || name === PrepareFileEdit.id) && isSuccess) { |
101 | | - const out = output as Record<string, unknown> | undefined |
102 | | - const editData = |
103 | | - out && typeof out.data === 'object' && out.data !== null |
104 | | - ? (out.data as Record<string, unknown>) |
105 | | - : undefined |
| 101 | + const isFileEdit = name === ApplyFileEdit.id || name === PrepareFileEdit.id |
| 102 | + const editData = isFileEdit ? toRecordOrNull(toRecordOrNull(output)?.data) : null |
| 103 | + /** A file another resource owns (a test's source) never opens as a file tab. */ |
| 104 | + const editedFileIsTab = editData?.fileTab !== false |
| 105 | + |
| 106 | + if (!replay && isFileEdit && isSuccess && editedFileIsTab) { |
106 | 107 | const editedFileId = |
107 | 108 | (typeof editData?.id === 'string' ? editData.id : undefined) ?? |
108 | 109 | deps.previewSessionRef.current?.fileId |
@@ -139,7 +140,9 @@ function runToolResultSideEffects(ctx: StreamLoopContext, node: ToolNode, replay |
139 | 140 | if (name === PrepareFileEdit.id) { |
140 | 141 | deps.removePreviewSessionImmediate(node.id) |
141 | 142 | } |
142 | | - const fileResource = extractedResources.find((r) => r.type === 'file') |
| 143 | + const fileResource = editedFileIsTab |
| 144 | + ? extractedResources.find((r) => r.type === 'file') |
| 145 | + : undefined |
143 | 146 | if (fileResource) { |
144 | 147 | deps.promoteFileResource(fileResource.id, fileResource.title) |
145 | 148 | deps.onResourceEventRef.current?.( |
|
0 commit comments