Merge branch 'main' into lstein/global-configuration

This commit is contained in:
Lincoln Stein 2023-05-07 07:52:46 -04:00 committed by GitHub
commit f28632980d
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
- name: deploy to gh-pages
if: ${{ github.ref == 'refs/heads/main' }}
if: ${{ github.ref == 'refs/heads/v2.3' }}
run: |
python -m \
mkdocs gh-deploy \

View File

@ -10,6 +10,7 @@ import ConditioningInputFieldComponent from './fields/ConditioningInputFieldComp
import ModelInputFieldComponent from './fields/ModelInputFieldComponent';
import NumberInputFieldComponent from './fields/NumberInputFieldComponent';
import StringInputFieldComponent from './fields/StringInputFieldComponent';
import ItemInputFieldComponent from './fields/ItemInputFieldComponent';
type InputFieldComponentProps = {
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>;
};

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',
model: 'model',
array: 'array',
item: 'item',
};
const COLOR_TOKEN_VALUE = 500;
@ -82,4 +83,10 @@ export const FIELDS: Record<FieldType, FieldUIConfig> = {
title: 'Array',
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'
| 'conditioning'
| 'model'
| 'array';
| 'array'
| 'item';
/**
* An input field is persisted across reloads as part of the user's local state.
@ -78,7 +79,8 @@ export type InputFieldValue =
| ConditioningInputFieldValue
| EnumInputFieldValue
| ModelInputFieldValue
| ArrayInputFieldValue;
| ArrayInputFieldValue
| ItemInputFieldValue;
/**
* An input field template is generated on each page load from the OpenAPI schema.
@ -96,7 +98,8 @@ export type InputFieldTemplate =
| ConditioningInputFieldTemplate
| EnumInputFieldTemplate
| ModelInputFieldTemplate
| ArrayInputFieldTemplate;
| ArrayInputFieldTemplate
| ItemInputFieldTemplate;
/**
* 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)[];
};
export type ItemInputFieldValue = FieldValueBase & {
type: 'item';
value?: undefined;
};
export type InputFieldTemplateBase = {
name: string;
title: string;
@ -255,10 +263,15 @@ export type ModelInputFieldTemplate = InputFieldTemplateBase & {
};
export type ArrayInputFieldTemplate = InputFieldTemplateBase & {
default: (string | number)[];
default: [];
type: 'array';
};
export type ItemInputFieldTemplate = InputFieldTemplateBase & {
default: undefined;
type: 'item';
};
/**
* JANKY CUSTOMISATION OF OpenAPI SCHEMA TYPES
*/

View File

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

View File

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

View File

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

View File

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