Merge branch 'main' into enhance/update-dependencies

This commit is contained in:
blessedcoolant 2023-05-07 21:44:43 +12:00 committed by GitHub
commit b909bac0dc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 147 additions and 48 deletions

View File

@ -36,7 +36,7 @@ jobs:
--verbose --verbose
- name: deploy to gh-pages - name: deploy to gh-pages
if: ${{ github.ref == 'refs/heads/main' }} if: ${{ github.ref == 'refs/heads/v2.3' }}
run: | run: |
python -m \ python -m \
mkdocs gh-deploy \ mkdocs gh-deploy \

View File

@ -10,6 +10,7 @@ import ConditioningInputFieldComponent from './fields/ConditioningInputFieldComp
import ModelInputFieldComponent from './fields/ModelInputFieldComponent'; import ModelInputFieldComponent from './fields/ModelInputFieldComponent';
import NumberInputFieldComponent from './fields/NumberInputFieldComponent'; import NumberInputFieldComponent from './fields/NumberInputFieldComponent';
import StringInputFieldComponent from './fields/StringInputFieldComponent'; import StringInputFieldComponent from './fields/StringInputFieldComponent';
import ItemInputFieldComponent from './fields/ItemInputFieldComponent';
type InputFieldComponentProps = { type InputFieldComponentProps = {
nodeId: string; nodeId: string;
@ -115,6 +116,16 @@ const InputFieldComponent = (props: InputFieldComponentProps) => {
); );
} }
if (type === 'item' && template.type === 'item') {
return (
<ItemInputFieldComponent
nodeId={nodeId}
field={field}
template={template}
/>
);
}
return <Box p={2}>Unknown field type: {type}</Box>; return <Box p={2}>Unknown field type: {type}</Box>;
}; };

View File

@ -0,0 +1,17 @@
import {
ItemInputFieldTemplate,
ItemInputFieldValue,
} from 'features/nodes/types/types';
import { memo } from 'react';
import { FaAddressCard, FaList } from 'react-icons/fa';
import { FieldComponentProps } from './types';
const ItemInputFieldComponent = (
props: FieldComponentProps<ItemInputFieldValue, ItemInputFieldTemplate>
) => {
const { nodeId, field } = props;
return <FaAddressCard />;
};
export default memo(ItemInputFieldComponent);

View File

@ -14,6 +14,7 @@ export const FIELD_TYPE_MAP: Record<string, FieldType> = {
ConditioningField: 'conditioning', ConditioningField: 'conditioning',
model: 'model', model: 'model',
array: 'array', array: 'array',
item: 'item',
}; };
const COLOR_TOKEN_VALUE = 500; const COLOR_TOKEN_VALUE = 500;
@ -82,4 +83,10 @@ export const FIELDS: Record<FieldType, FieldUIConfig> = {
title: 'Array', title: 'Array',
description: 'TODO: Array type description.', description: 'TODO: Array type description.',
}, },
item: {
color: 'gray',
colorCssVar: getColorTokenCssVariable('gray'),
title: 'Collection Item',
description: 'TODO: Collection Item type description.',
},
}; };

View File

@ -58,7 +58,8 @@ export type FieldType =
| 'latents' | 'latents'
| 'conditioning' | 'conditioning'
| 'model' | 'model'
| 'array'; | 'array'
| 'item';
/** /**
* An input field is persisted across reloads as part of the user's local state. * An input field is persisted across reloads as part of the user's local state.
@ -78,7 +79,8 @@ export type InputFieldValue =
| ConditioningInputFieldValue | ConditioningInputFieldValue
| EnumInputFieldValue | EnumInputFieldValue
| ModelInputFieldValue | ModelInputFieldValue
| ArrayInputFieldValue; | ArrayInputFieldValue
| ItemInputFieldValue;
/** /**
* An input field template is generated on each page load from the OpenAPI schema. * An input field template is generated on each page load from the OpenAPI schema.
@ -96,7 +98,8 @@ export type InputFieldTemplate =
| ConditioningInputFieldTemplate | ConditioningInputFieldTemplate
| EnumInputFieldTemplate | EnumInputFieldTemplate
| ModelInputFieldTemplate | ModelInputFieldTemplate
| ArrayInputFieldTemplate; | ArrayInputFieldTemplate
| ItemInputFieldTemplate;
/** /**
* An output field is persisted across as part of the user's local state. * An output field is persisted across as part of the user's local state.
@ -185,6 +188,11 @@ export type ArrayInputFieldValue = FieldValueBase & {
value?: (string | number)[]; value?: (string | number)[];
}; };
export type ItemInputFieldValue = FieldValueBase & {
type: 'item';
value?: undefined;
};
export type InputFieldTemplateBase = { export type InputFieldTemplateBase = {
name: string; name: string;
title: string; title: string;
@ -255,10 +263,15 @@ export type ModelInputFieldTemplate = InputFieldTemplateBase & {
}; };
export type ArrayInputFieldTemplate = InputFieldTemplateBase & { export type ArrayInputFieldTemplate = InputFieldTemplateBase & {
default: (string | number)[]; default: [];
type: 'array'; type: 'array';
}; };
export type ItemInputFieldTemplate = InputFieldTemplateBase & {
default: undefined;
type: 'item';
};
/** /**
* JANKY CUSTOMISATION OF OpenAPI SCHEMA TYPES * JANKY CUSTOMISATION OF OpenAPI SCHEMA TYPES
*/ */

View File

@ -16,6 +16,8 @@ import {
OutputFieldTemplate, OutputFieldTemplate,
TypeHints, TypeHints,
FieldType, FieldType,
ArrayInputFieldTemplate,
ItemInputFieldTemplate,
} from '../types/types'; } from '../types/types';
export type BaseFieldProperties = 'name' | 'title' | 'description'; export type BaseFieldProperties = 'name' | 'title' | 'description';
@ -230,6 +232,36 @@ const buildEnumInputFieldTemplate = ({
return template; return template;
}; };
const buildArrayInputFieldTemplate = ({
schemaObject,
baseField,
}: BuildInputFieldArg): ArrayInputFieldTemplate => {
const template: ArrayInputFieldTemplate = {
...baseField,
type: 'array',
inputRequirement: 'always',
inputKind: 'direct',
default: [],
};
return template;
};
const buildItemInputFieldTemplate = ({
schemaObject,
baseField,
}: BuildInputFieldArg): ItemInputFieldTemplate => {
const template: ItemInputFieldTemplate = {
...baseField,
type: 'item',
inputRequirement: 'always',
inputKind: 'direct',
default: undefined,
};
return template;
};
export const getFieldType = ( export const getFieldType = (
schemaObject: OpenAPIV3.SchemaObject, schemaObject: OpenAPIV3.SchemaObject,
name: string, name: string,
@ -303,6 +335,12 @@ export const buildInputFieldTemplate = (
if (['boolean'].includes(fieldType)) { if (['boolean'].includes(fieldType)) {
return buildBooleanInputFieldTemplate({ schemaObject, baseField }); return buildBooleanInputFieldTemplate({ schemaObject, baseField });
} }
if (['array'].includes(fieldType)) {
return buildArrayInputFieldTemplate({ schemaObject, baseField });
}
if (['item'].includes(fieldType)) {
return buildItemInputFieldTemplate({ schemaObject, baseField });
}
return; return;
}; };

View File

@ -7,7 +7,7 @@ export const buildIterateNode = (): IterateInvocation => {
return { return {
id: nodeId, id: nodeId,
type: 'iterate', type: 'iterate',
collection: [], // collection: [],
index: 0, // index: 0,
}; };
}; };

View File

@ -13,7 +13,7 @@ import {
buildOutputFieldTemplates, buildOutputFieldTemplates,
} from './fieldTemplateBuilders'; } from './fieldTemplateBuilders';
const invocationDenylist = ['Graph', 'Collect', 'LoadImage']; const invocationDenylist = ['Graph', 'LoadImage'];
export const parseSchema = (openAPI: OpenAPIV3.Document) => { export const parseSchema = (openAPI: OpenAPIV3.Document) => {
// filter out non-invocation schemas, plus some tricky invocations for now // filter out non-invocation schemas, plus some tricky invocations for now
@ -32,16 +32,43 @@ export const parseSchema = (openAPI: OpenAPIV3.Document) => {
if (isInvocationSchemaObject(schema)) { if (isInvocationSchemaObject(schema)) {
const type = schema.properties.type.default; const type = schema.properties.type.default;
const title = const title = schema.ui?.title ?? schema.title.replace('Invocation', '');
schema.ui?.title ??
schema.title
.replace('Invocation', '')
.split(/(?=[A-Z])/) // split PascalCase into array
.join(' ');
const typeHints = schema.ui?.type_hints; const typeHints = schema.ui?.type_hints;
const inputs = reduce( const inputs: Record<string, InputFieldTemplate> = {};
if (type === 'collect') {
const itemProperty = schema.properties[
'item'
] as InvocationSchemaObject;
// Handle the special Collect node
inputs.item = {
type: 'item',
name: 'item',
description: itemProperty.description ?? '',
title: 'Collection Item',
inputKind: 'connection',
inputRequirement: 'always',
default: undefined,
};
} else if (type === 'iterate') {
const itemProperty = schema.properties[
'collection'
] as InvocationSchemaObject;
inputs.collection = {
type: 'array',
name: 'collection',
title: itemProperty.title ?? '',
default: [],
description: itemProperty.description ?? '',
inputRequirement: 'always',
inputKind: 'connection',
};
} else {
// All other nodes
reduce(
schema.properties, schema.properties,
(inputsAccumulator, property, propertyName) => { (inputsAccumulator, property, propertyName) => {
if ( if (
@ -49,32 +76,18 @@ export const parseSchema = (openAPI: OpenAPIV3.Document) => {
!['type', 'id'].includes(propertyName) && !['type', 'id'].includes(propertyName) &&
isSchemaObject(property) isSchemaObject(property)
) { ) {
let field: InputFieldTemplate | undefined; const field: InputFieldTemplate | undefined =
if (propertyName === 'collection') { buildInputFieldTemplate(property, propertyName, typeHints);
field = {
default: property.default ?? [],
name: 'collection',
title: property.title ?? '',
description: property.description ?? '',
type: 'array',
inputRequirement: 'always',
inputKind: 'connection',
};
} else {
field = buildInputFieldTemplate(
property,
propertyName,
typeHints
);
}
if (field) { if (field) {
inputsAccumulator[propertyName] = field; inputsAccumulator[propertyName] = field;
} }
} }
return inputsAccumulator; return inputsAccumulator;
}, },
{} as Record<string, InputFieldTemplate> inputs
); );
}
const rawOutput = (schema as InvocationSchemaObject).output; const rawOutput = (schema as InvocationSchemaObject).output;

View File

@ -107,7 +107,7 @@ const initialSystemState: SystemState = {
subscribedNodeIds: [], subscribedNodeIds: [],
wereModelsReceived: false, wereModelsReceived: false,
wasSchemaParsed: false, wasSchemaParsed: false,
consoleLogLevel: 'error', consoleLogLevel: 'debug',
shouldLogToConsole: true, shouldLogToConsole: true,
statusTranslationKey: 'common.statusDisconnected', statusTranslationKey: 'common.statusDisconnected',
canceledSession: '', canceledSession: '',