mirror of
https://github.com/simstudioai/sim.git
synced 2026-04-06 03:00:16 -04:00
Var improvements
This commit is contained in:
@@ -208,7 +208,7 @@ export function DebugPanel() {
|
||||
|
||||
// Compute accessible output variables for the focused block with tag-style references
|
||||
const outputVariableEntries = useMemo(() => {
|
||||
if (!focusedBlockId) return [] as Array<{ ref: string; value: any }>
|
||||
if (!focusedBlockId) return [] as Array<{ ref: string; value: any; resolved: boolean }>
|
||||
|
||||
const normalizeBlockName = (name: string) => (name || '').replace(/\s+/g, '').toLowerCase()
|
||||
const getSubBlockValue = (blockId: string, property: string): any => {
|
||||
@@ -301,40 +301,45 @@ export function DebugPanel() {
|
||||
// Always allow referencing the starter block
|
||||
if (starterId && starterId !== focusedBlockId) accessibleIds.add(starterId)
|
||||
|
||||
const entries: Array<{ ref: string; value: any }> = []
|
||||
const entries: Array<{ ref: string; value: any; resolved: boolean }> = []
|
||||
|
||||
for (const id of accessibleIds) {
|
||||
const blk = blockById.get(id)
|
||||
if (!blk) continue
|
||||
|
||||
const allowedPathsSet = new Set<string>(getAccessiblePathsForBlock(id))
|
||||
if (allowedPathsSet.size === 0) continue
|
||||
const allowedPaths = getAccessiblePathsForBlock(id)
|
||||
if (allowedPaths.length === 0) continue
|
||||
|
||||
const displayName = getDisplayName(blk)
|
||||
const normalizedName = normalizeBlockName(displayName)
|
||||
|
||||
const executedOutput = debugContext?.blockStates.get(id)?.output || {}
|
||||
const isExecuted = debugContext?.blockStates.get(id)?.executed || false
|
||||
|
||||
// Flatten executed outputs and include only those matching allowed paths
|
||||
const flatten = (obj: any, prefix = ''): Array<{ path: string; value: any }> => {
|
||||
if (obj == null || typeof obj !== 'object') return []
|
||||
const items: Array<{ path: string; value: any }> = []
|
||||
for (const [k, v] of Object.entries(obj)) {
|
||||
const current = prefix ? `${prefix}.${k}` : k
|
||||
if (v && typeof v === 'object' && !Array.isArray(v)) {
|
||||
// include the object level only if explicitly allowed
|
||||
if (allowedPathsSet.has(current)) items.push({ path: current, value: v })
|
||||
items.push(...flatten(v, current))
|
||||
} else {
|
||||
if (allowedPathsSet.has(current)) items.push({ path: current, value: v })
|
||||
// For each allowed path, create an entry
|
||||
for (const path of allowedPaths) {
|
||||
const ref = `<${normalizedName}.${path}>`
|
||||
|
||||
// Try to get the value from executed output
|
||||
const getValue = (obj: any, pathStr: string): { value: any; found: boolean } => {
|
||||
const parts = pathStr.split('.')
|
||||
let current = obj
|
||||
for (const part of parts) {
|
||||
if (current && typeof current === 'object' && part in current) {
|
||||
current = current[part]
|
||||
} else {
|
||||
return { value: undefined, found: false }
|
||||
}
|
||||
}
|
||||
return { value: current, found: true }
|
||||
}
|
||||
return items
|
||||
}
|
||||
|
||||
const executedPairs = flatten(executedOutput)
|
||||
for (const { path, value } of executedPairs) {
|
||||
entries.push({ ref: `<${normalizedName}.${path}>`, value })
|
||||
const { value, found } = getValue(executedOutput, path)
|
||||
entries.push({
|
||||
ref,
|
||||
value: found ? value : undefined,
|
||||
resolved: isExecuted && found
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -346,8 +351,8 @@ export function DebugPanel() {
|
||||
// Filter output variables based on whether they're referenced in the input
|
||||
const filteredOutputVariables = useMemo(() => {
|
||||
if (!scopedVariables) {
|
||||
// When not scoped, return all available variables (all resolved)
|
||||
return outputVariableEntries.map(entry => ({ ...entry, resolved: true }))
|
||||
// When not scoped, return all available variables from outputVariableEntries
|
||||
return outputVariableEntries
|
||||
}
|
||||
|
||||
// Get the JSON string of visible subblock values to search for references
|
||||
@@ -372,10 +377,10 @@ export function DebugPanel() {
|
||||
for (const ref of referencedVars) {
|
||||
const available = availableVarsMap.get(ref)
|
||||
if (available) {
|
||||
// Variable is resolved (has a value)
|
||||
result.push({ ...available, resolved: true })
|
||||
// Variable exists in accessible scope
|
||||
result.push(available)
|
||||
} else {
|
||||
// Variable is unresolved (referenced but no value yet)
|
||||
// Variable is referenced but not in accessible scope (shouldn't reach this block)
|
||||
result.push({ ref, value: undefined, resolved: false })
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user