diff --git a/frontend/src/lib/components/copilot/chat/core.ts b/frontend/src/lib/components/copilot/chat/core.ts index f3b2dd9f94..f9a5cb3426 100644 --- a/frontend/src/lib/components/copilot/chat/core.ts +++ b/frontend/src/lib/components/copilot/chat/core.ts @@ -1,6 +1,6 @@ import { ResourceService } from '$lib/gen/services.gen' import type { ResourceType, ScriptLang } from '$lib/gen/types.gen' -import { capitalize, toCamel } from '$lib/utils' +import { capitalize, isObject, toCamel } from '$lib/utils' import { get, type Writable } from 'svelte/store' import { getCompletion } from '../lib' import { compile, phpCompile, pythonCompile } from '../utils' @@ -16,9 +16,12 @@ import { scriptLangToEditorLang } from '$lib/scripts' import { getDbSchemas } from '$lib/components/apps/components/display/dbtable/utils' export function formatResourceTypes( - resourceTypes: ResourceType[], + allResourceTypes: ResourceType[], lang: 'python3' | 'php' | 'bun' | 'deno' | 'nativets' | 'bunnative' ) { + const resourceTypes = allResourceTypes.filter( + (rt) => isObject(rt.schema) && 'properties' in rt.schema && isObject(rt.schema.properties) + ) if (lang === 'python3') { const result = resourceTypes.map((resourceType) => { return `class ${resourceType.name}(TypedDict):\n${pythonCompile(resourceType.schema as any)}` @@ -33,15 +36,11 @@ export function formatResourceTypes( return '\n' + result.join('\n\n') } else { let resultStr = 'namespace RT {\n' - const result = resourceTypes - .filter( - (resourceType) => Boolean(resourceType.schema) && typeof resourceType.schema === 'object' - ) - .map((resourceType) => { - return ` type ${toCamel(capitalize(resourceType.name))} = ${compile( - resourceType.schema as any - ).replaceAll('\n', '\n ')}` - }) + const result = resourceTypes.map((resourceType) => { + return ` type ${toCamel(capitalize(resourceType.name))} = ${compile( + resourceType.schema as any + ).replaceAll('\n', '\n ')}` + }) return resultStr + result.join('\n\n') + '\n}' } }