|
| 1 | +import { Combobox, Label } from '@sim/emcn' |
| 2 | +import type { CanonicalMode } from '@/lib/workflows/subblocks/visibility' |
| 3 | +import type { StoredTool } from '@/lib/workflows/tool-input/types' |
| 4 | +import { CanonicalModeToggle } from '@/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/editor/components/sub-block/components/canonical-mode-toggle' |
| 5 | +import { ShortInput } from '@/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/editor/components/sub-block/components/short-input' |
| 6 | + |
| 7 | +interface ToolUsageControlProps { |
| 8 | + blockId: string |
| 9 | + aggregateSubBlockId: string |
| 10 | + toolIndex: number |
| 11 | + tool: StoredTool |
| 12 | + mode: CanonicalMode |
| 13 | + supportsForce: boolean |
| 14 | + disabled: boolean |
| 15 | + onFixedChange: (value: NonNullable<StoredTool['usageControl']>) => void |
| 16 | + onExpressionChange: (value: string) => void |
| 17 | + onModeToggle: () => void |
| 18 | +} |
| 19 | + |
| 20 | +const MODE_OPTIONS = [ |
| 21 | + { |
| 22 | + value: 'auto', |
| 23 | + label: 'Auto', |
| 24 | + suffixElement: <span className='text-[var(--text-tertiary)]'>(model decides)</span>, |
| 25 | + }, |
| 26 | + { |
| 27 | + value: 'force', |
| 28 | + label: 'Force', |
| 29 | + suffixElement: <span className='text-[var(--text-tertiary)]'>(always use)</span>, |
| 30 | + }, |
| 31 | + { |
| 32 | + value: 'none', |
| 33 | + label: 'None', |
| 34 | + suffixElement: <span className='text-[var(--text-tertiary)]'>(disable tool)</span>, |
| 35 | + }, |
| 36 | +] as const |
| 37 | + |
| 38 | +export function ToolUsageControl({ |
| 39 | + blockId, |
| 40 | + aggregateSubBlockId, |
| 41 | + toolIndex, |
| 42 | + tool, |
| 43 | + mode, |
| 44 | + supportsForce, |
| 45 | + disabled, |
| 46 | + onFixedChange, |
| 47 | + onExpressionChange, |
| 48 | + onModeToggle, |
| 49 | +}: ToolUsageControlProps) { |
| 50 | + return ( |
| 51 | + <div className='subblock-content flex w-full min-w-0 flex-col gap-2.5'> |
| 52 | + <div className='flex items-center justify-between gap-1.5 pl-0.5'> |
| 53 | + <Label>Permission Mode</Label> |
| 54 | + <CanonicalModeToggle mode={mode} disabled={disabled} onToggle={onModeToggle} /> |
| 55 | + </div> |
| 56 | + {mode === 'advanced' ? ( |
| 57 | + <ShortInput |
| 58 | + blockId={blockId} |
| 59 | + subBlockId={aggregateSubBlockId} |
| 60 | + config={{ |
| 61 | + id: 'usageControlExpression', |
| 62 | + title: 'Permission Mode', |
| 63 | + type: 'short-input', |
| 64 | + }} |
| 65 | + value={tool.usageControlExpression ?? ''} |
| 66 | + onChange={onExpressionChange} |
| 67 | + placeholder='"auto", "force", or "none"' |
| 68 | + disabled={disabled} |
| 69 | + workflowSearchValuePath={[toolIndex, 'usageControlExpression']} |
| 70 | + /> |
| 71 | + ) : ( |
| 72 | + <Combobox |
| 73 | + options={MODE_OPTIONS.map((option) => ({ |
| 74 | + ...option, |
| 75 | + disabled: option.value === 'force' && !supportsForce, |
| 76 | + suffixElement: |
| 77 | + option.value === 'force' && !supportsForce ? ( |
| 78 | + <span className='text-[var(--text-tertiary)]'>(not supported by model)</span> |
| 79 | + ) : ( |
| 80 | + option.suffixElement |
| 81 | + ), |
| 82 | + onSelect: () => onFixedChange(option.value), |
| 83 | + }))} |
| 84 | + value={tool.usageControl ?? 'auto'} |
| 85 | + disabled={disabled} |
| 86 | + aria-label='Permission Mode' |
| 87 | + /> |
| 88 | + )} |
| 89 | + </div> |
| 90 | + ) |
| 91 | +} |
0 commit comments