mirror of
https://github.com/invoke-ai/InvokeAI
synced 2024-08-30 20:32:17 +00:00
Temp fix for is intermediate switch for l2i
This commit is contained in:
parent
531bc40d3f
commit
761fc4beb8
@ -13,7 +13,12 @@ import {
|
|||||||
buildOutputFieldTemplates,
|
buildOutputFieldTemplates,
|
||||||
} from './fieldTemplateBuilders';
|
} from './fieldTemplateBuilders';
|
||||||
|
|
||||||
const RESERVED_FIELD_NAMES = ['id', 'type', 'is_intermediate', 'metadata'];
|
const getReservedFieldNames = (type: string): string[] => {
|
||||||
|
if (type === 'l2i') {
|
||||||
|
return ['id', 'type', 'metadata'];
|
||||||
|
}
|
||||||
|
return ['id', 'type', 'is_intermediate', 'metadata'];
|
||||||
|
};
|
||||||
|
|
||||||
const invocationDenylist = [
|
const invocationDenylist = [
|
||||||
'Graph',
|
'Graph',
|
||||||
@ -21,11 +26,11 @@ const invocationDenylist = [
|
|||||||
'MetadataAccumulatorInvocation',
|
'MetadataAccumulatorInvocation',
|
||||||
];
|
];
|
||||||
|
|
||||||
export const parseSchema = (openAPI: OpenAPIV3.Document) => {
|
export const parseSchema = (
|
||||||
// filter out non-invocation schemas, plus some tricky invocations for now
|
openAPI: OpenAPIV3.Document
|
||||||
|
): Record<string, InvocationTemplate> => {
|
||||||
const filteredSchemas = filter(
|
const filteredSchemas = filter(
|
||||||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
openAPI.components?.schemas,
|
||||||
openAPI.components!.schemas,
|
|
||||||
(schema, key) =>
|
(schema, key) =>
|
||||||
key.includes('Invocation') &&
|
key.includes('Invocation') &&
|
||||||
!key.includes('InvocationOutput') &&
|
!key.includes('InvocationOutput') &&
|
||||||
@ -35,21 +40,17 @@ export const parseSchema = (openAPI: OpenAPIV3.Document) => {
|
|||||||
const invocations = filteredSchemas.reduce<
|
const invocations = filteredSchemas.reduce<
|
||||||
Record<string, InvocationTemplate>
|
Record<string, InvocationTemplate>
|
||||||
>((acc, schema) => {
|
>((acc, schema) => {
|
||||||
// only want SchemaObjects
|
|
||||||
if (isInvocationSchemaObject(schema)) {
|
if (isInvocationSchemaObject(schema)) {
|
||||||
const type = schema.properties.type.default;
|
const type = schema.properties.type.default;
|
||||||
|
const RESERVED_FIELD_NAMES = getReservedFieldNames(type);
|
||||||
|
|
||||||
const title = schema.ui?.title ?? schema.title.replace('Invocation', '');
|
const title = schema.ui?.title ?? schema.title.replace('Invocation', '');
|
||||||
|
|
||||||
const typeHints = schema.ui?.type_hints;
|
const typeHints = schema.ui?.type_hints;
|
||||||
|
|
||||||
const inputs: Record<string, InputFieldTemplate> = {};
|
const inputs: Record<string, InputFieldTemplate> = {};
|
||||||
|
|
||||||
if (type === 'collect') {
|
if (type === 'collect') {
|
||||||
const itemProperty = schema.properties[
|
const itemProperty = schema.properties.item as InvocationSchemaObject;
|
||||||
'item'
|
|
||||||
] as InvocationSchemaObject;
|
|
||||||
// Handle the special Collect node
|
|
||||||
inputs.item = {
|
inputs.item = {
|
||||||
type: 'item',
|
type: 'item',
|
||||||
name: 'item',
|
name: 'item',
|
||||||
@ -60,10 +61,8 @@ export const parseSchema = (openAPI: OpenAPIV3.Document) => {
|
|||||||
default: undefined,
|
default: undefined,
|
||||||
};
|
};
|
||||||
} else if (type === 'iterate') {
|
} else if (type === 'iterate') {
|
||||||
const itemProperty = schema.properties[
|
const itemProperty = schema.properties
|
||||||
'collection'
|
.collection as InvocationSchemaObject;
|
||||||
] as InvocationSchemaObject;
|
|
||||||
|
|
||||||
inputs.collection = {
|
inputs.collection = {
|
||||||
type: 'array',
|
type: 'array',
|
||||||
name: 'collection',
|
name: 'collection',
|
||||||
@ -74,18 +73,18 @@ export const parseSchema = (openAPI: OpenAPIV3.Document) => {
|
|||||||
inputKind: 'connection',
|
inputKind: 'connection',
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
// All other nodes
|
|
||||||
reduce(
|
reduce(
|
||||||
schema.properties,
|
schema.properties,
|
||||||
(inputsAccumulator, property, propertyName) => {
|
(inputsAccumulator, property, propertyName) => {
|
||||||
if (
|
if (
|
||||||
// `type` and `id` are not valid inputs/outputs
|
|
||||||
!RESERVED_FIELD_NAMES.includes(propertyName) &&
|
!RESERVED_FIELD_NAMES.includes(propertyName) &&
|
||||||
isSchemaObject(property)
|
isSchemaObject(property)
|
||||||
) {
|
) {
|
||||||
const field: InputFieldTemplate | undefined =
|
const field = buildInputFieldTemplate(
|
||||||
buildInputFieldTemplate(property, propertyName, typeHints);
|
property,
|
||||||
|
propertyName,
|
||||||
|
typeHints
|
||||||
|
);
|
||||||
if (field) {
|
if (field) {
|
||||||
inputsAccumulator[propertyName] = field;
|
inputsAccumulator[propertyName] = field;
|
||||||
}
|
}
|
||||||
@ -97,22 +96,17 @@ export const parseSchema = (openAPI: OpenAPIV3.Document) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const rawOutput = (schema as InvocationSchemaObject).output;
|
const rawOutput = (schema as InvocationSchemaObject).output;
|
||||||
|
|
||||||
let outputs: Record<string, OutputFieldTemplate>;
|
let outputs: Record<string, OutputFieldTemplate>;
|
||||||
|
|
||||||
// some special handling is needed for collect, iterate and range nodes
|
|
||||||
if (type === 'iterate') {
|
if (type === 'iterate') {
|
||||||
// this is guaranteed to be a SchemaObject
|
const iterationOutput = openAPI.components?.schemas?.[
|
||||||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
||||||
const iterationOutput = openAPI.components!.schemas![
|
|
||||||
'IterateInvocationOutput'
|
'IterateInvocationOutput'
|
||||||
] as OpenAPIV3.SchemaObject;
|
] as OpenAPIV3.SchemaObject;
|
||||||
|
|
||||||
outputs = {
|
outputs = {
|
||||||
item: {
|
item: {
|
||||||
name: 'item',
|
name: 'item',
|
||||||
title: iterationOutput.title ?? '',
|
title: iterationOutput?.title ?? '',
|
||||||
description: iterationOutput.description ?? '',
|
description: iterationOutput?.description ?? '',
|
||||||
type: 'array',
|
type: 'array',
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user