Skip to content

Commit 7456c3c

Browse files
committed
fix(mothership): address PR review — move FileAttachmentForApi to types, defer onEditValueConsumed to effect, await sendMessage in sendNow
1 parent 8610d67 commit 7456c3c

File tree

4 files changed

+22
-14
lines changed

4 files changed

+22
-14
lines changed

apps/sim/app/workspace/[workspaceId]/home/components/user-input/user-input.tsx

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,10 @@ import { cn } from '@/lib/core/utils/cn'
6464
import { CHAT_ACCEPT_ATTRIBUTE } from '@/lib/uploads/utils/validation'
6565
import { useAvailableResources } from '@/app/workspace/[workspaceId]/home/components/mothership-view/components/add-resource-dropdown'
6666
import { getResourceConfig } from '@/app/workspace/[workspaceId]/home/components/mothership-view/components/resource-registry'
67-
import type { MothershipResource } from '@/app/workspace/[workspaceId]/home/types'
67+
import type {
68+
FileAttachmentForApi,
69+
MothershipResource,
70+
} from '@/app/workspace/[workspaceId]/home/types'
6871
import {
6972
useContextManagement,
7073
useFileAttachments,
@@ -145,13 +148,7 @@ function mapResourceToContext(resource: MothershipResource): ChatContext {
145148
}
146149
}
147150

148-
export interface FileAttachmentForApi {
149-
id: string
150-
key: string
151-
filename: string
152-
media_type: string
153-
size: number
154-
}
151+
export type { FileAttachmentForApi } from '@/app/workspace/[workspaceId]/home/types'
155152

156153
interface UserInputProps {
157154
defaultValue?: string
@@ -200,11 +197,16 @@ export function UserInput({
200197
if (editValue && editValue !== prevEditValue) {
201198
setPrevEditValue(editValue)
202199
setValue(editValue)
203-
onEditValueConsumed?.()
204200
} else if (!editValue && prevEditValue) {
205201
setPrevEditValue(editValue)
206202
}
207203

204+
useEffect(() => {
205+
if (editValue) {
206+
onEditValueConsumed?.()
207+
}
208+
}, [editValue, onEditValueConsumed])
209+
208210
const animatedPlaceholder = useAnimatedPlaceholder(isInitialView)
209211
const placeholder = isInitialView ? animatedPlaceholder : 'Send message to Sim'
210212

apps/sim/app/workspace/[workspaceId]/home/home.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,8 @@ import {
2525
UserMessageContent,
2626
} from './components'
2727
import { PendingTagIndicator } from './components/message-content/components/special-tags'
28-
import type { FileAttachmentForApi } from './components/user-input/user-input'
2928
import { useAutoScroll, useChat } from './hooks'
30-
import type { MothershipResource, MothershipResourceType } from './types'
29+
import type { FileAttachmentForApi, MothershipResource, MothershipResourceType } from './types'
3130

3231
const logger = createLogger('Home')
3332

apps/sim/app/workspace/[workspaceId]/home/hooks/use-chat.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,12 @@ import { useFolderStore } from '@/stores/folders/store'
2828
import type { ChatContext } from '@/stores/panel'
2929
import { useTerminalConsoleStore } from '@/stores/terminal'
3030
import { useWorkflowRegistry } from '@/stores/workflows/registry/store'
31-
import type { FileAttachmentForApi } from '../components/user-input/user-input'
3231
import type {
3332
ChatMessage,
3433
ChatMessageAttachment,
3534
ContentBlock,
3635
ContentBlockType,
36+
FileAttachmentForApi,
3737
MothershipResource,
3838
MothershipResourceType,
3939
QueuedMessage,
@@ -1016,7 +1016,7 @@ export function useChat(
10161016
if (!msg) return
10171017
await stopGeneration()
10181018
setMessageQueue((prev) => prev.filter((m) => m.id !== id))
1019-
sendMessage(msg.content, msg.fileAttachments, msg.contexts)
1019+
await sendMessage(msg.content, msg.fileAttachments, msg.contexts)
10201020
},
10211021
[stopGeneration, sendMessage, setMessageQueue]
10221022
)

apps/sim/app/workspace/[workspaceId]/home/types.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,19 @@
11
import type { MothershipResourceType } from '@/lib/copilot/resource-types'
22
import type { ChatContext } from '@/stores/panel'
3-
import type { FileAttachmentForApi } from './components/user-input/user-input'
43

54
export type {
65
MothershipResource,
76
MothershipResourceType,
87
} from '@/lib/copilot/resource-types'
98

9+
export interface FileAttachmentForApi {
10+
id: string
11+
key: string
12+
filename: string
13+
media_type: string
14+
size: number
15+
}
16+
1017
export interface QueuedMessage {
1118
id: string
1219
content: string

0 commit comments

Comments
 (0)