Files
sim/apps/sim/tools/params-resolver.ts
Vikhyath Mondreti 0fcd52683a improvement(tool-input): general abstraction to enrich agent context, reuse visibility helpers (#2872)
* add abstraction for schema enrichment, improve agent KB block experience for tags, fix visibility of subblocks

* cleanup code

* consolidate

* fix workflow tool react query

* fix deployed context propagation

* fix tests
2026-01-17 19:13:27 -08:00

47 lines
1.3 KiB
TypeScript

import {
buildCanonicalIndex,
type CanonicalIndex,
evaluateSubBlockCondition,
getCanonicalValues,
isCanonicalPair,
resolveCanonicalMode,
type SubBlockCondition,
} from '@/lib/workflows/subblocks/visibility'
import type { SubBlockConfig as BlockSubBlockConfig } from '@/blocks/types'
export {
buildCanonicalIndex,
type CanonicalIndex,
evaluateSubBlockCondition,
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
}