fix(ui): Projection ref params now filter objects by matching type

- RefCombobox infers object_type from param name when not explicitly set
- e.g. param 'agent' automatically shows only agent-type objects
- Also fixed engine type signature to preserve object_type in params

小橘 🍊(NEKO Team)
This commit is contained in:
小橘 2026-04-13 09:13:38 +00:00
parent 0c22885f4a
commit bd4b79bd7b
3 changed files with 35 additions and 22 deletions

View File

@ -478,7 +478,7 @@ export async function createProjectionDef(
db: D1Database,
name: string,
sources: Array<{ event_def: string; bindings: Record<string, string>; expression: string }>,
params: Record<string, { type: 'ref' }>,
params: Record<string, { type: 'ref'; object_type?: string }>,
valueSchema: { type: string },
initialValue: any,
): Promise<{ name: string; hash: string }> {

File diff suppressed because one or more lines are too long

View File

@ -150,6 +150,7 @@ export default function Projections() {
objects={objects}
objectsByType={objectsByType}
objectType={schema.object_type}
paramName={key}
/>
) : (
<input
@ -232,29 +233,41 @@ function RefCombobox({
objects,
objectsByType,
objectType,
paramName,
}: {
value: string
onChange: (v: string) => void
objects: Array<{ id: string; type: string }>
objectsByType: Record<string, string[]>
objectType?: string
paramName?: string
}) {
const [query, setQuery] = useState('')
// Filter objects by object_type if specified
// Filter objects by object_type if specified, or infer from param name
// Convention: param name often matches the object type (e.g. param "agent" → type "agent")
const effectiveObjectType = useMemo(() => {
if (objectType) return objectType
if (paramName) {
const types = new Set(objects.map(o => o.type))
if (types.has(paramName)) return paramName
}
return undefined
}, [objectType, paramName, objects])
const relevantObjects = useMemo(() => {
if (!objectType) return objects
return objects.filter((o) => o.type === objectType)
}, [objects, objectType])
if (!effectiveObjectType) return objects
return objects.filter((o) => o.type === effectiveObjectType)
}, [objects, effectiveObjectType])
const relevantByType = useMemo(() => {
if (!objectType) return objectsByType
if (!effectiveObjectType) return objectsByType
const filtered: Record<string, string[]> = {}
if (objectsByType[objectType]) {
filtered[objectType] = objectsByType[objectType]
if (objectsByType[effectiveObjectType]) {
filtered[effectiveObjectType] = objectsByType[effectiveObjectType]
}
return filtered
}, [objectsByType, objectType])
}, [objectsByType, effectiveObjectType])
const filtered = useMemo(() => {
if (!query) return relevantObjects