Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions apps/sim/app/api/mothership/chat/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ const MothershipMessageSchema = z.object({
'knowledge',
'templates',
'docs',
'table',
'file',
]),
label: z.string(),
chatId: z.string().optional(),
Expand All @@ -64,6 +66,8 @@ const MothershipMessageSchema = z.object({
blockIds: z.array(z.string()).optional(),
templateId: z.string().optional(),
executionId: z.string().optional(),
tableId: z.string().optional(),
fileId: z.string().optional(),
})
)
.optional(),
Expand Down Expand Up @@ -162,6 +166,17 @@ export async function POST(req: NextRequest) {
size: f.size,
})),
}),
...(contexts &&
contexts.length > 0 && {
contexts: contexts.map((c) => ({
kind: c.kind,
label: c.label,
...(c.workflowId && { workflowId: c.workflowId }),
...(c.knowledgeId && { knowledgeId: c.knowledgeId }),
...(c.tableId && { tableId: c.tableId }),
...(c.fileId && { fileId: c.fileId }),
})),
}),
}

const [updated] = await db
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ export { MessageContent } from './message-content'
export { MothershipView } from './mothership-view'
export { TemplatePrompts } from './template-prompts'
export { UserInput } from './user-input'
export { UserMessageContent } from './user-message-content'
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
'use client'

import { X } from 'lucide-react'
import { Badge } from '@/components/emcn'
import { Database, File as FileIcon, Table as TableIcon } from '@/components/emcn/icons'
import { WorkflowIcon } from '@/components/icons'
import { cn } from '@/lib/core/utils/cn'
import type { ChatContext } from '@/stores/panel'
import { useWorkflowRegistry } from '@/stores/workflows/registry/store'

interface ContextPillsProps {
contexts: ChatContext[]
onRemoveContext: (context: ChatContext) => void
}

function WorkflowPillIcon({ workflowId, className }: { workflowId: string; className?: string }) {
const color = useWorkflowRegistry((state) => state.workflows[workflowId]?.color ?? '#888')
return (
<div
className={cn('flex-shrink-0 rounded-[3px] border-[2px]', className)}
style={{
backgroundColor: color,
borderColor: `${color}60`,
backgroundClip: 'padding-box',
}}
/>
)
}

function getContextIcon(ctx: ChatContext) {
switch (ctx.kind) {
case 'workflow':
case 'current_workflow':
return (
<WorkflowPillIcon
workflowId={ctx.workflowId}
className='mr-[4px] h-[10px] w-[10px]'
/>
)
case 'workflow_block':
return (
<WorkflowPillIcon
workflowId={ctx.workflowId}
className='mr-[4px] h-[10px] w-[10px]'
/>
)
case 'knowledge':
return <Database className='mr-[4px] h-[10px] w-[10px] text-[var(--text-icon)]' />
case 'templates':
return <WorkflowIcon className='mr-[4px] h-[10px] w-[10px] text-[var(--text-icon)]' />
case 'past_chat':
return null
case 'logs':
return <FileIcon className='mr-[4px] h-[10px] w-[10px] text-[var(--text-icon)]' />
case 'blocks':
return <TableIcon className='mr-[4px] h-[10px] w-[10px] text-[var(--text-icon)]' />
case 'table':
return <TableIcon className='mr-[4px] h-[10px] w-[10px] text-[var(--text-icon)]' />
case 'file':
return <FileIcon className='mr-[4px] h-[10px] w-[10px] text-[var(--text-icon)]' />
case 'docs':
return <FileIcon className='mr-[4px] h-[10px] w-[10px] text-[var(--text-icon)]' />
default:
return null
}
}

export function ContextPills({ contexts, onRemoveContext }: ContextPillsProps) {
const visibleContexts = contexts.filter((c) => c.kind !== 'current_workflow')

if (visibleContexts.length === 0) {
return null
}

return (
<>
{visibleContexts.map((ctx, idx) => (
<Badge
key={`selctx-${idx}-${ctx.label}`}
variant='outline'
className='inline-flex items-center gap-1 rounded-[6px] px-2 py-[4.5px] text-xs leading-[12px]'
title={ctx.label}
>
{getContextIcon(ctx)}
<span className='max-w-[140px] truncate leading-[12px]'>{ctx.label}</span>
<button
type='button'
onClick={() => onRemoveContext(ctx)}
className='text-muted-foreground transition-colors hover:text-foreground'
title='Remove context'
aria-label='Remove context'
>
<X className='h-3 w-3' strokeWidth={1.75} />
</button>
</Badge>
))}
</>
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { ContextPills } from './context-pills'
Loading