mirror of
https://github.com/simstudioai/sim.git
synced 2026-02-12 15:34:58 -05:00
Replace 17+ individual SyncWrapper components with a single centralized ToolSubBlockRenderer that bridges the subblock store with StoredTool.params via synthetic store keys. This reduces ~1000 lines of duplicated wrapper code and ensures tool-input renders subblock components identically to the standalone SubBlock path. - Add ToolSubBlockRenderer with bidirectional store sync - Add basic/advanced mode toggle (ArrowLeftRight) using collaborative functions - Add dependsOn gating via useDependsOnGate (fields disable instead of hiding) - Add paramVisibility field to SubBlockConfig for tool-input visibility control - Pass canonicalModeOverrides through getSubBlocksForToolInput - Show (optional) label for non-user-only fields (LLM can inject at runtime) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
51 lines
1.4 KiB
TypeScript
51 lines
1.4 KiB
TypeScript
import {
|
|
buildCanonicalIndex,
|
|
type CanonicalIndex,
|
|
type CanonicalModeOverrides,
|
|
evaluateSubBlockCondition,
|
|
getCanonicalValues,
|
|
isCanonicalPair,
|
|
resolveCanonicalMode,
|
|
type SubBlockCondition,
|
|
} from '@/lib/workflows/subblocks/visibility'
|
|
import type { SubBlockConfig as BlockSubBlockConfig } from '@/blocks/types'
|
|
|
|
export {
|
|
buildCanonicalIndex,
|
|
type CanonicalIndex,
|
|
type CanonicalModeOverrides,
|
|
evaluateSubBlockCondition,
|
|
isCanonicalPair,
|
|
resolveCanonicalMode,
|
|
type SubBlockCondition,
|
|
}
|
|
|
|
export interface ToolParamContext {
|
|
blockType: string
|
|
subBlocks: BlockSubBlockConfig[]
|
|
canonicalIndex: CanonicalIndex
|
|
values: Record<string, unknown>
|
|
}
|
|
|
|
/**
|
|
* Build preview context values for selectors that need dependency resolution.
|
|
* Resolves canonical values so selectors get the correct credential/dependency values.
|
|
*/
|
|
export function buildPreviewContextValues(
|
|
params: Record<string, unknown>,
|
|
context: ToolParamContext
|
|
): Record<string, unknown> {
|
|
const result: Record<string, unknown> = { ...params }
|
|
|
|
for (const [canonicalId, group] of Object.entries(context.canonicalIndex.groupsById)) {
|
|
if (isCanonicalPair(group)) {
|
|
const mode = resolveCanonicalMode(group, context.values)
|
|
const { basicValue, advancedValue } = getCanonicalValues(group, context.values)
|
|
result[canonicalId] =
|
|
mode === 'advanced' ? (advancedValue ?? basicValue) : (basicValue ?? advancedValue)
|
|
}
|
|
}
|
|
|
|
return result
|
|
}
|