@weirdfingers/boards 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +678 -0
- package/dist/index.d.mts +225 -2
- package/dist/index.d.ts +225 -2
- package/dist/index.js +155 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +150 -0
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -1
- package/src/hooks/useGenerators.ts +6 -2
- package/src/index.ts +5 -0
- package/src/types/generatorSchema.ts +187 -0
- package/src/utils/__tests__/schemaParser.test.ts +576 -0
- package/src/utils/schemaParser.ts +310 -0
package/dist/index.d.mts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
2
|
import React, { ReactNode } from 'react';
|
|
3
3
|
import * as urql from 'urql';
|
|
4
|
+
import { JSONSchema7, JSONSchema7Definition } from 'json-schema';
|
|
5
|
+
export { JSONSchema7 } from 'json-schema';
|
|
4
6
|
|
|
5
7
|
/**
|
|
6
8
|
* Core authentication types and interfaces.
|
|
@@ -470,8 +472,9 @@ interface Generator {
|
|
|
470
472
|
name: string;
|
|
471
473
|
description: string;
|
|
472
474
|
artifactType: ArtifactType;
|
|
473
|
-
inputSchema:
|
|
475
|
+
inputSchema: JSONSchema7;
|
|
474
476
|
}
|
|
477
|
+
|
|
475
478
|
interface UseGeneratorsOptions {
|
|
476
479
|
artifactType?: string;
|
|
477
480
|
}
|
|
@@ -482,6 +485,226 @@ interface GeneratorsHook {
|
|
|
482
485
|
}
|
|
483
486
|
declare function useGenerators(options?: UseGeneratorsOptions): GeneratorsHook;
|
|
484
487
|
|
|
488
|
+
/**
|
|
489
|
+
* Types for parsed generator input schemas.
|
|
490
|
+
*
|
|
491
|
+
* These types represent the structured output from parsing a JSON Schema
|
|
492
|
+
* that defines a generator's input parameters. They enable dynamic UI generation
|
|
493
|
+
* by categorizing schema properties into artifacts, prompts, and settings.
|
|
494
|
+
*/
|
|
495
|
+
/**
|
|
496
|
+
* Represents a slot for an artifact input (single or array).
|
|
497
|
+
*
|
|
498
|
+
* Artifact slots appear as UI elements that allow users to select
|
|
499
|
+
* existing artifacts from their board.
|
|
500
|
+
*/
|
|
501
|
+
interface ArtifactSlot {
|
|
502
|
+
/** Display name for the artifact slot (from schema title) */
|
|
503
|
+
name: string;
|
|
504
|
+
/** Field name used as the key in form data */
|
|
505
|
+
fieldName: string;
|
|
506
|
+
/** Type of artifact: 'audio', 'video', 'image', or 'text' */
|
|
507
|
+
artifactType: "audio" | "video" | "image" | "text";
|
|
508
|
+
/** Whether this field is required in the input schema */
|
|
509
|
+
required: boolean;
|
|
510
|
+
/** Description of what this artifact is used for */
|
|
511
|
+
description?: string;
|
|
512
|
+
/** Whether this slot accepts multiple artifacts (array) */
|
|
513
|
+
isArray: boolean;
|
|
514
|
+
/** Minimum number of items required (for arrays) */
|
|
515
|
+
minItems?: number;
|
|
516
|
+
/** Maximum number of items allowed (for arrays) */
|
|
517
|
+
maxItems?: number;
|
|
518
|
+
}
|
|
519
|
+
/**
|
|
520
|
+
* Represents the prompt field if present in the schema.
|
|
521
|
+
*
|
|
522
|
+
* The prompt is typically rendered as a textarea for user input.
|
|
523
|
+
*/
|
|
524
|
+
interface PromptField {
|
|
525
|
+
/** Field name (typically "prompt") */
|
|
526
|
+
fieldName: string;
|
|
527
|
+
/** Description of how the prompt is used */
|
|
528
|
+
description?: string;
|
|
529
|
+
/** Whether the prompt is required */
|
|
530
|
+
required: boolean;
|
|
531
|
+
/** Default value for the prompt */
|
|
532
|
+
default?: string;
|
|
533
|
+
}
|
|
534
|
+
/**
|
|
535
|
+
* A slider input for numeric values with min/max bounds.
|
|
536
|
+
*/
|
|
537
|
+
interface SliderField {
|
|
538
|
+
type: "slider";
|
|
539
|
+
/** Field name used as the key in form data */
|
|
540
|
+
fieldName: string;
|
|
541
|
+
/** Display title for the slider */
|
|
542
|
+
title: string;
|
|
543
|
+
/** Description of what this setting controls */
|
|
544
|
+
description?: string;
|
|
545
|
+
/** Minimum allowed value */
|
|
546
|
+
min: number;
|
|
547
|
+
/** Maximum allowed value */
|
|
548
|
+
max: number;
|
|
549
|
+
/** Step increment for the slider */
|
|
550
|
+
step?: number;
|
|
551
|
+
/** Default value */
|
|
552
|
+
default?: number;
|
|
553
|
+
/** Whether the value is an integer (vs float) */
|
|
554
|
+
isInteger: boolean;
|
|
555
|
+
}
|
|
556
|
+
/**
|
|
557
|
+
* A dropdown selector for enumerated string values.
|
|
558
|
+
*/
|
|
559
|
+
interface DropdownField {
|
|
560
|
+
type: "dropdown";
|
|
561
|
+
/** Field name used as the key in form data */
|
|
562
|
+
fieldName: string;
|
|
563
|
+
/** Display title for the dropdown */
|
|
564
|
+
title: string;
|
|
565
|
+
/** Description of what this setting controls */
|
|
566
|
+
description?: string;
|
|
567
|
+
/** Available options to select from */
|
|
568
|
+
options: string[];
|
|
569
|
+
/** Default selected option */
|
|
570
|
+
default?: string;
|
|
571
|
+
}
|
|
572
|
+
/**
|
|
573
|
+
* A text input field for string values.
|
|
574
|
+
*/
|
|
575
|
+
interface TextInputField {
|
|
576
|
+
type: "text";
|
|
577
|
+
/** Field name used as the key in form data */
|
|
578
|
+
fieldName: string;
|
|
579
|
+
/** Display title for the input */
|
|
580
|
+
title: string;
|
|
581
|
+
/** Description of what this setting is for */
|
|
582
|
+
description?: string;
|
|
583
|
+
/** Default value */
|
|
584
|
+
default?: string;
|
|
585
|
+
/** Regex pattern for validation */
|
|
586
|
+
pattern?: string;
|
|
587
|
+
}
|
|
588
|
+
/**
|
|
589
|
+
* A number input field for numeric values without slider constraints.
|
|
590
|
+
*/
|
|
591
|
+
interface NumberInputField {
|
|
592
|
+
type: "number";
|
|
593
|
+
/** Field name used as the key in form data */
|
|
594
|
+
fieldName: string;
|
|
595
|
+
/** Display title for the input */
|
|
596
|
+
title: string;
|
|
597
|
+
/** Description of what this setting is for */
|
|
598
|
+
description?: string;
|
|
599
|
+
/** Default value */
|
|
600
|
+
default?: number;
|
|
601
|
+
/** Minimum value (optional, for validation) */
|
|
602
|
+
min?: number;
|
|
603
|
+
/** Maximum value (optional, for validation) */
|
|
604
|
+
max?: number;
|
|
605
|
+
/** Whether the value must be an integer */
|
|
606
|
+
isInteger: boolean;
|
|
607
|
+
}
|
|
608
|
+
/**
|
|
609
|
+
* Union type for all possible settings field types.
|
|
610
|
+
*/
|
|
611
|
+
type SettingsField = SliderField | DropdownField | TextInputField | NumberInputField;
|
|
612
|
+
/**
|
|
613
|
+
* Complete parsed structure of a generator's input schema.
|
|
614
|
+
*
|
|
615
|
+
* This structure enables applications to build dynamic UIs that match
|
|
616
|
+
* the generator's input requirements.
|
|
617
|
+
*/
|
|
618
|
+
interface ParsedGeneratorSchema {
|
|
619
|
+
/** Artifact input slots (for selecting existing artifacts) */
|
|
620
|
+
artifactSlots: ArtifactSlot[];
|
|
621
|
+
/** The prompt field, if present in the schema */
|
|
622
|
+
promptField: PromptField | null;
|
|
623
|
+
/** Additional settings fields (sliders, dropdowns, etc.) */
|
|
624
|
+
settingsFields: SettingsField[];
|
|
625
|
+
}
|
|
626
|
+
|
|
627
|
+
/**
|
|
628
|
+
* Utilities for parsing generator JSON Schemas into structured data
|
|
629
|
+
* suitable for dynamic UI generation.
|
|
630
|
+
*/
|
|
631
|
+
|
|
632
|
+
/**
|
|
633
|
+
* Checks if a JSON Schema property references an artifact type.
|
|
634
|
+
*
|
|
635
|
+
* Artifacts are identified by $ref paths containing "Artifact" in their name,
|
|
636
|
+
* e.g., "#/$defs/AudioArtifact" or "#/$defs/VideoArtifact".
|
|
637
|
+
*
|
|
638
|
+
* @param property - The JSON Schema property to check
|
|
639
|
+
* @returns True if the property references an artifact type
|
|
640
|
+
*/
|
|
641
|
+
declare function isArtifactReference(property: JSONSchema7 | JSONSchema7Definition | undefined): boolean;
|
|
642
|
+
/**
|
|
643
|
+
* Extracts the artifact type from a $ref path.
|
|
644
|
+
*
|
|
645
|
+
* Examples:
|
|
646
|
+
* - "#/$defs/AudioArtifact" -> "audio"
|
|
647
|
+
* - "#/$defs/VideoArtifact" -> "video"
|
|
648
|
+
* - "#/$defs/ImageArtifact" -> "image"
|
|
649
|
+
* - "#/$defs/TextArtifact" -> "text"
|
|
650
|
+
*
|
|
651
|
+
* @param ref - The $ref string from the JSON Schema
|
|
652
|
+
* @returns The artifact type in lowercase
|
|
653
|
+
*/
|
|
654
|
+
declare function getArtifactType(ref: string): "audio" | "video" | "image" | "text";
|
|
655
|
+
/**
|
|
656
|
+
* Parses an artifact property into an ArtifactSlot structure.
|
|
657
|
+
*
|
|
658
|
+
* @param name - The property name from the schema
|
|
659
|
+
* @param property - The JSON Schema property definition
|
|
660
|
+
* @param required - Whether this field is in the required array
|
|
661
|
+
* @returns Parsed artifact slot information
|
|
662
|
+
*/
|
|
663
|
+
declare function parseArtifactSlot(name: string, property: JSONSchema7, required: boolean): ArtifactSlot;
|
|
664
|
+
/**
|
|
665
|
+
* Parses a settings field into its appropriate type (slider, dropdown, text, number).
|
|
666
|
+
*
|
|
667
|
+
* @param name - The property name from the schema
|
|
668
|
+
* @param property - The JSON Schema property definition
|
|
669
|
+
* @returns Parsed settings field information
|
|
670
|
+
*/
|
|
671
|
+
declare function parseSettingsField(name: string, property: JSONSchema7): SettingsField | null;
|
|
672
|
+
/**
|
|
673
|
+
* Parses a complete generator JSON Schema into structured data for UI generation.
|
|
674
|
+
*
|
|
675
|
+
* This function categorizes schema properties into:
|
|
676
|
+
* - Artifact slots (for selecting existing artifacts)
|
|
677
|
+
* - Prompt field (special text input for generation prompts)
|
|
678
|
+
* - Settings fields (sliders, dropdowns, text inputs, etc.)
|
|
679
|
+
*
|
|
680
|
+
* @param schema - The JSON Schema from the generator's inputSchema field
|
|
681
|
+
* @returns Parsed schema structure ready for dynamic UI generation
|
|
682
|
+
*
|
|
683
|
+
* @example
|
|
684
|
+
* ```typescript
|
|
685
|
+
* const generator = generators[0];
|
|
686
|
+
* const parsed = parseGeneratorSchema(generator.inputSchema);
|
|
687
|
+
*
|
|
688
|
+
* // Render artifact slots
|
|
689
|
+
* parsed.artifactSlots.forEach(slot => {
|
|
690
|
+
* console.log(`${slot.name}: ${slot.artifactType} (required: ${slot.required})`);
|
|
691
|
+
* });
|
|
692
|
+
*
|
|
693
|
+
* // Render prompt field
|
|
694
|
+
* if (parsed.promptField) {
|
|
695
|
+
* console.log(`Prompt: ${parsed.promptField.description}`);
|
|
696
|
+
* }
|
|
697
|
+
*
|
|
698
|
+
* // Render settings
|
|
699
|
+
* parsed.settingsFields.forEach(field => {
|
|
700
|
+
* if (field.type === 'slider') {
|
|
701
|
+
* console.log(`${field.title}: ${field.min} - ${field.max}`);
|
|
702
|
+
* }
|
|
703
|
+
* });
|
|
704
|
+
* ```
|
|
705
|
+
*/
|
|
706
|
+
declare function parseGeneratorSchema(schema: JSONSchema7): ParsedGeneratorSchema;
|
|
707
|
+
|
|
485
708
|
interface BoardsProviderProps {
|
|
486
709
|
children: ReactNode;
|
|
487
710
|
/**
|
|
@@ -505,4 +728,4 @@ declare function BoardsProvider({ children, apiUrl, graphqlUrl, subscriptionUrl,
|
|
|
505
728
|
|
|
506
729
|
declare const VERSION = "0.1.0";
|
|
507
730
|
|
|
508
|
-
export { ADD_BOARD_MEMBER, type ApiConfig, ArtifactType, type AuthContextValue, AuthProvider, type AuthProviderConfig, type AuthState$1 as AuthState, BOARD_FRAGMENT, BaseAuthProvider, BoardRole, BoardsProvider, CANCEL_GENERATION, CREATE_BOARD, CREATE_GENERATION, type CreateBoardInput, type CreateGenerationInput, DELETE_BOARD, GENERATION_FRAGMENT, GET_BOARD, GET_BOARDS, GET_CURRENT_USER, GET_GENERATION, GET_GENERATIONS, GET_GENERATORS, GenerationStatus, NoAuthProvider, REMOVE_BOARD_MEMBER, RETRY_GENERATION, type SignInOptions, UPDATE_BOARD, UPDATE_BOARD_MEMBER_ROLE, USER_FRAGMENT, type UpdateBoardInput, type User$1 as User, VERSION, createGraphQLClient, useApiConfig, useAuth, useAuthOptional, useBoard, useBoards, useGeneration, useGenerators };
|
|
731
|
+
export { ADD_BOARD_MEMBER, type ApiConfig, type ArtifactSlot, ArtifactType, type AuthContextValue, AuthProvider, type AuthProviderConfig, type AuthState$1 as AuthState, BOARD_FRAGMENT, BaseAuthProvider, BoardRole, BoardsProvider, CANCEL_GENERATION, CREATE_BOARD, CREATE_GENERATION, type CreateBoardInput, type CreateGenerationInput, DELETE_BOARD, type DropdownField, GENERATION_FRAGMENT, GET_BOARD, GET_BOARDS, GET_CURRENT_USER, GET_GENERATION, GET_GENERATIONS, GET_GENERATORS, GenerationStatus, type Generator, NoAuthProvider, type NumberInputField, type ParsedGeneratorSchema, type PromptField, REMOVE_BOARD_MEMBER, RETRY_GENERATION, type SettingsField, type SignInOptions, type SliderField, type TextInputField, UPDATE_BOARD, UPDATE_BOARD_MEMBER_ROLE, USER_FRAGMENT, type UpdateBoardInput, type User$1 as User, VERSION, createGraphQLClient, getArtifactType, isArtifactReference, parseArtifactSlot, parseGeneratorSchema, parseSettingsField, useApiConfig, useAuth, useAuthOptional, useBoard, useBoards, useGeneration, useGenerators };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
2
|
import React, { ReactNode } from 'react';
|
|
3
3
|
import * as urql from 'urql';
|
|
4
|
+
import { JSONSchema7, JSONSchema7Definition } from 'json-schema';
|
|
5
|
+
export { JSONSchema7 } from 'json-schema';
|
|
4
6
|
|
|
5
7
|
/**
|
|
6
8
|
* Core authentication types and interfaces.
|
|
@@ -470,8 +472,9 @@ interface Generator {
|
|
|
470
472
|
name: string;
|
|
471
473
|
description: string;
|
|
472
474
|
artifactType: ArtifactType;
|
|
473
|
-
inputSchema:
|
|
475
|
+
inputSchema: JSONSchema7;
|
|
474
476
|
}
|
|
477
|
+
|
|
475
478
|
interface UseGeneratorsOptions {
|
|
476
479
|
artifactType?: string;
|
|
477
480
|
}
|
|
@@ -482,6 +485,226 @@ interface GeneratorsHook {
|
|
|
482
485
|
}
|
|
483
486
|
declare function useGenerators(options?: UseGeneratorsOptions): GeneratorsHook;
|
|
484
487
|
|
|
488
|
+
/**
|
|
489
|
+
* Types for parsed generator input schemas.
|
|
490
|
+
*
|
|
491
|
+
* These types represent the structured output from parsing a JSON Schema
|
|
492
|
+
* that defines a generator's input parameters. They enable dynamic UI generation
|
|
493
|
+
* by categorizing schema properties into artifacts, prompts, and settings.
|
|
494
|
+
*/
|
|
495
|
+
/**
|
|
496
|
+
* Represents a slot for an artifact input (single or array).
|
|
497
|
+
*
|
|
498
|
+
* Artifact slots appear as UI elements that allow users to select
|
|
499
|
+
* existing artifacts from their board.
|
|
500
|
+
*/
|
|
501
|
+
interface ArtifactSlot {
|
|
502
|
+
/** Display name for the artifact slot (from schema title) */
|
|
503
|
+
name: string;
|
|
504
|
+
/** Field name used as the key in form data */
|
|
505
|
+
fieldName: string;
|
|
506
|
+
/** Type of artifact: 'audio', 'video', 'image', or 'text' */
|
|
507
|
+
artifactType: "audio" | "video" | "image" | "text";
|
|
508
|
+
/** Whether this field is required in the input schema */
|
|
509
|
+
required: boolean;
|
|
510
|
+
/** Description of what this artifact is used for */
|
|
511
|
+
description?: string;
|
|
512
|
+
/** Whether this slot accepts multiple artifacts (array) */
|
|
513
|
+
isArray: boolean;
|
|
514
|
+
/** Minimum number of items required (for arrays) */
|
|
515
|
+
minItems?: number;
|
|
516
|
+
/** Maximum number of items allowed (for arrays) */
|
|
517
|
+
maxItems?: number;
|
|
518
|
+
}
|
|
519
|
+
/**
|
|
520
|
+
* Represents the prompt field if present in the schema.
|
|
521
|
+
*
|
|
522
|
+
* The prompt is typically rendered as a textarea for user input.
|
|
523
|
+
*/
|
|
524
|
+
interface PromptField {
|
|
525
|
+
/** Field name (typically "prompt") */
|
|
526
|
+
fieldName: string;
|
|
527
|
+
/** Description of how the prompt is used */
|
|
528
|
+
description?: string;
|
|
529
|
+
/** Whether the prompt is required */
|
|
530
|
+
required: boolean;
|
|
531
|
+
/** Default value for the prompt */
|
|
532
|
+
default?: string;
|
|
533
|
+
}
|
|
534
|
+
/**
|
|
535
|
+
* A slider input for numeric values with min/max bounds.
|
|
536
|
+
*/
|
|
537
|
+
interface SliderField {
|
|
538
|
+
type: "slider";
|
|
539
|
+
/** Field name used as the key in form data */
|
|
540
|
+
fieldName: string;
|
|
541
|
+
/** Display title for the slider */
|
|
542
|
+
title: string;
|
|
543
|
+
/** Description of what this setting controls */
|
|
544
|
+
description?: string;
|
|
545
|
+
/** Minimum allowed value */
|
|
546
|
+
min: number;
|
|
547
|
+
/** Maximum allowed value */
|
|
548
|
+
max: number;
|
|
549
|
+
/** Step increment for the slider */
|
|
550
|
+
step?: number;
|
|
551
|
+
/** Default value */
|
|
552
|
+
default?: number;
|
|
553
|
+
/** Whether the value is an integer (vs float) */
|
|
554
|
+
isInteger: boolean;
|
|
555
|
+
}
|
|
556
|
+
/**
|
|
557
|
+
* A dropdown selector for enumerated string values.
|
|
558
|
+
*/
|
|
559
|
+
interface DropdownField {
|
|
560
|
+
type: "dropdown";
|
|
561
|
+
/** Field name used as the key in form data */
|
|
562
|
+
fieldName: string;
|
|
563
|
+
/** Display title for the dropdown */
|
|
564
|
+
title: string;
|
|
565
|
+
/** Description of what this setting controls */
|
|
566
|
+
description?: string;
|
|
567
|
+
/** Available options to select from */
|
|
568
|
+
options: string[];
|
|
569
|
+
/** Default selected option */
|
|
570
|
+
default?: string;
|
|
571
|
+
}
|
|
572
|
+
/**
|
|
573
|
+
* A text input field for string values.
|
|
574
|
+
*/
|
|
575
|
+
interface TextInputField {
|
|
576
|
+
type: "text";
|
|
577
|
+
/** Field name used as the key in form data */
|
|
578
|
+
fieldName: string;
|
|
579
|
+
/** Display title for the input */
|
|
580
|
+
title: string;
|
|
581
|
+
/** Description of what this setting is for */
|
|
582
|
+
description?: string;
|
|
583
|
+
/** Default value */
|
|
584
|
+
default?: string;
|
|
585
|
+
/** Regex pattern for validation */
|
|
586
|
+
pattern?: string;
|
|
587
|
+
}
|
|
588
|
+
/**
|
|
589
|
+
* A number input field for numeric values without slider constraints.
|
|
590
|
+
*/
|
|
591
|
+
interface NumberInputField {
|
|
592
|
+
type: "number";
|
|
593
|
+
/** Field name used as the key in form data */
|
|
594
|
+
fieldName: string;
|
|
595
|
+
/** Display title for the input */
|
|
596
|
+
title: string;
|
|
597
|
+
/** Description of what this setting is for */
|
|
598
|
+
description?: string;
|
|
599
|
+
/** Default value */
|
|
600
|
+
default?: number;
|
|
601
|
+
/** Minimum value (optional, for validation) */
|
|
602
|
+
min?: number;
|
|
603
|
+
/** Maximum value (optional, for validation) */
|
|
604
|
+
max?: number;
|
|
605
|
+
/** Whether the value must be an integer */
|
|
606
|
+
isInteger: boolean;
|
|
607
|
+
}
|
|
608
|
+
/**
|
|
609
|
+
* Union type for all possible settings field types.
|
|
610
|
+
*/
|
|
611
|
+
type SettingsField = SliderField | DropdownField | TextInputField | NumberInputField;
|
|
612
|
+
/**
|
|
613
|
+
* Complete parsed structure of a generator's input schema.
|
|
614
|
+
*
|
|
615
|
+
* This structure enables applications to build dynamic UIs that match
|
|
616
|
+
* the generator's input requirements.
|
|
617
|
+
*/
|
|
618
|
+
interface ParsedGeneratorSchema {
|
|
619
|
+
/** Artifact input slots (for selecting existing artifacts) */
|
|
620
|
+
artifactSlots: ArtifactSlot[];
|
|
621
|
+
/** The prompt field, if present in the schema */
|
|
622
|
+
promptField: PromptField | null;
|
|
623
|
+
/** Additional settings fields (sliders, dropdowns, etc.) */
|
|
624
|
+
settingsFields: SettingsField[];
|
|
625
|
+
}
|
|
626
|
+
|
|
627
|
+
/**
|
|
628
|
+
* Utilities for parsing generator JSON Schemas into structured data
|
|
629
|
+
* suitable for dynamic UI generation.
|
|
630
|
+
*/
|
|
631
|
+
|
|
632
|
+
/**
|
|
633
|
+
* Checks if a JSON Schema property references an artifact type.
|
|
634
|
+
*
|
|
635
|
+
* Artifacts are identified by $ref paths containing "Artifact" in their name,
|
|
636
|
+
* e.g., "#/$defs/AudioArtifact" or "#/$defs/VideoArtifact".
|
|
637
|
+
*
|
|
638
|
+
* @param property - The JSON Schema property to check
|
|
639
|
+
* @returns True if the property references an artifact type
|
|
640
|
+
*/
|
|
641
|
+
declare function isArtifactReference(property: JSONSchema7 | JSONSchema7Definition | undefined): boolean;
|
|
642
|
+
/**
|
|
643
|
+
* Extracts the artifact type from a $ref path.
|
|
644
|
+
*
|
|
645
|
+
* Examples:
|
|
646
|
+
* - "#/$defs/AudioArtifact" -> "audio"
|
|
647
|
+
* - "#/$defs/VideoArtifact" -> "video"
|
|
648
|
+
* - "#/$defs/ImageArtifact" -> "image"
|
|
649
|
+
* - "#/$defs/TextArtifact" -> "text"
|
|
650
|
+
*
|
|
651
|
+
* @param ref - The $ref string from the JSON Schema
|
|
652
|
+
* @returns The artifact type in lowercase
|
|
653
|
+
*/
|
|
654
|
+
declare function getArtifactType(ref: string): "audio" | "video" | "image" | "text";
|
|
655
|
+
/**
|
|
656
|
+
* Parses an artifact property into an ArtifactSlot structure.
|
|
657
|
+
*
|
|
658
|
+
* @param name - The property name from the schema
|
|
659
|
+
* @param property - The JSON Schema property definition
|
|
660
|
+
* @param required - Whether this field is in the required array
|
|
661
|
+
* @returns Parsed artifact slot information
|
|
662
|
+
*/
|
|
663
|
+
declare function parseArtifactSlot(name: string, property: JSONSchema7, required: boolean): ArtifactSlot;
|
|
664
|
+
/**
|
|
665
|
+
* Parses a settings field into its appropriate type (slider, dropdown, text, number).
|
|
666
|
+
*
|
|
667
|
+
* @param name - The property name from the schema
|
|
668
|
+
* @param property - The JSON Schema property definition
|
|
669
|
+
* @returns Parsed settings field information
|
|
670
|
+
*/
|
|
671
|
+
declare function parseSettingsField(name: string, property: JSONSchema7): SettingsField | null;
|
|
672
|
+
/**
|
|
673
|
+
* Parses a complete generator JSON Schema into structured data for UI generation.
|
|
674
|
+
*
|
|
675
|
+
* This function categorizes schema properties into:
|
|
676
|
+
* - Artifact slots (for selecting existing artifacts)
|
|
677
|
+
* - Prompt field (special text input for generation prompts)
|
|
678
|
+
* - Settings fields (sliders, dropdowns, text inputs, etc.)
|
|
679
|
+
*
|
|
680
|
+
* @param schema - The JSON Schema from the generator's inputSchema field
|
|
681
|
+
* @returns Parsed schema structure ready for dynamic UI generation
|
|
682
|
+
*
|
|
683
|
+
* @example
|
|
684
|
+
* ```typescript
|
|
685
|
+
* const generator = generators[0];
|
|
686
|
+
* const parsed = parseGeneratorSchema(generator.inputSchema);
|
|
687
|
+
*
|
|
688
|
+
* // Render artifact slots
|
|
689
|
+
* parsed.artifactSlots.forEach(slot => {
|
|
690
|
+
* console.log(`${slot.name}: ${slot.artifactType} (required: ${slot.required})`);
|
|
691
|
+
* });
|
|
692
|
+
*
|
|
693
|
+
* // Render prompt field
|
|
694
|
+
* if (parsed.promptField) {
|
|
695
|
+
* console.log(`Prompt: ${parsed.promptField.description}`);
|
|
696
|
+
* }
|
|
697
|
+
*
|
|
698
|
+
* // Render settings
|
|
699
|
+
* parsed.settingsFields.forEach(field => {
|
|
700
|
+
* if (field.type === 'slider') {
|
|
701
|
+
* console.log(`${field.title}: ${field.min} - ${field.max}`);
|
|
702
|
+
* }
|
|
703
|
+
* });
|
|
704
|
+
* ```
|
|
705
|
+
*/
|
|
706
|
+
declare function parseGeneratorSchema(schema: JSONSchema7): ParsedGeneratorSchema;
|
|
707
|
+
|
|
485
708
|
interface BoardsProviderProps {
|
|
486
709
|
children: ReactNode;
|
|
487
710
|
/**
|
|
@@ -505,4 +728,4 @@ declare function BoardsProvider({ children, apiUrl, graphqlUrl, subscriptionUrl,
|
|
|
505
728
|
|
|
506
729
|
declare const VERSION = "0.1.0";
|
|
507
730
|
|
|
508
|
-
export { ADD_BOARD_MEMBER, type ApiConfig, ArtifactType, type AuthContextValue, AuthProvider, type AuthProviderConfig, type AuthState$1 as AuthState, BOARD_FRAGMENT, BaseAuthProvider, BoardRole, BoardsProvider, CANCEL_GENERATION, CREATE_BOARD, CREATE_GENERATION, type CreateBoardInput, type CreateGenerationInput, DELETE_BOARD, GENERATION_FRAGMENT, GET_BOARD, GET_BOARDS, GET_CURRENT_USER, GET_GENERATION, GET_GENERATIONS, GET_GENERATORS, GenerationStatus, NoAuthProvider, REMOVE_BOARD_MEMBER, RETRY_GENERATION, type SignInOptions, UPDATE_BOARD, UPDATE_BOARD_MEMBER_ROLE, USER_FRAGMENT, type UpdateBoardInput, type User$1 as User, VERSION, createGraphQLClient, useApiConfig, useAuth, useAuthOptional, useBoard, useBoards, useGeneration, useGenerators };
|
|
731
|
+
export { ADD_BOARD_MEMBER, type ApiConfig, type ArtifactSlot, ArtifactType, type AuthContextValue, AuthProvider, type AuthProviderConfig, type AuthState$1 as AuthState, BOARD_FRAGMENT, BaseAuthProvider, BoardRole, BoardsProvider, CANCEL_GENERATION, CREATE_BOARD, CREATE_GENERATION, type CreateBoardInput, type CreateGenerationInput, DELETE_BOARD, type DropdownField, GENERATION_FRAGMENT, GET_BOARD, GET_BOARDS, GET_CURRENT_USER, GET_GENERATION, GET_GENERATIONS, GET_GENERATORS, GenerationStatus, type Generator, NoAuthProvider, type NumberInputField, type ParsedGeneratorSchema, type PromptField, REMOVE_BOARD_MEMBER, RETRY_GENERATION, type SettingsField, type SignInOptions, type SliderField, type TextInputField, UPDATE_BOARD, UPDATE_BOARD_MEMBER_ROLE, USER_FRAGMENT, type UpdateBoardInput, type User$1 as User, VERSION, createGraphQLClient, getArtifactType, isArtifactReference, parseArtifactSlot, parseGeneratorSchema, parseSettingsField, useApiConfig, useAuth, useAuthOptional, useBoard, useBoards, useGeneration, useGenerators };
|
package/dist/index.js
CHANGED
|
@@ -47,6 +47,11 @@ __export(index_exports, {
|
|
|
47
47
|
USER_FRAGMENT: () => USER_FRAGMENT,
|
|
48
48
|
VERSION: () => VERSION,
|
|
49
49
|
createGraphQLClient: () => createGraphQLClient,
|
|
50
|
+
getArtifactType: () => getArtifactType,
|
|
51
|
+
isArtifactReference: () => isArtifactReference,
|
|
52
|
+
parseArtifactSlot: () => parseArtifactSlot,
|
|
53
|
+
parseGeneratorSchema: () => parseGeneratorSchema,
|
|
54
|
+
parseSettingsField: () => parseSettingsField,
|
|
50
55
|
useApiConfig: () => useApiConfig,
|
|
51
56
|
useAuth: () => useAuth,
|
|
52
57
|
useAuthOptional: () => useAuthOptional,
|
|
@@ -1077,6 +1082,151 @@ function useGenerators(options = {}) {
|
|
|
1077
1082
|
};
|
|
1078
1083
|
}
|
|
1079
1084
|
|
|
1085
|
+
// src/utils/schemaParser.ts
|
|
1086
|
+
function isArtifactReference(property) {
|
|
1087
|
+
if (!property || typeof property === "boolean") {
|
|
1088
|
+
return false;
|
|
1089
|
+
}
|
|
1090
|
+
if (property.$ref && property.$ref.includes("Artifact")) {
|
|
1091
|
+
return true;
|
|
1092
|
+
}
|
|
1093
|
+
if (property.type === "array" && property.items && typeof property.items === "object" && !Array.isArray(property.items)) {
|
|
1094
|
+
const items = property.items;
|
|
1095
|
+
return !!(items.$ref && items.$ref.includes("Artifact"));
|
|
1096
|
+
}
|
|
1097
|
+
return false;
|
|
1098
|
+
}
|
|
1099
|
+
function getArtifactType(ref) {
|
|
1100
|
+
const match = ref.match(/(Audio|Video|Image|Text)Artifact/);
|
|
1101
|
+
if (match) {
|
|
1102
|
+
return match[1].toLowerCase();
|
|
1103
|
+
}
|
|
1104
|
+
return "image";
|
|
1105
|
+
}
|
|
1106
|
+
function parseArtifactSlot(name, property, required) {
|
|
1107
|
+
const title = property.title || name;
|
|
1108
|
+
const description = property.description;
|
|
1109
|
+
if (property.type === "array" && property.items) {
|
|
1110
|
+
const items = typeof property.items === "object" && !Array.isArray(property.items) ? property.items : void 0;
|
|
1111
|
+
const artifactType2 = items?.$ref ? getArtifactType(items.$ref) : "image";
|
|
1112
|
+
return {
|
|
1113
|
+
name: title,
|
|
1114
|
+
fieldName: name,
|
|
1115
|
+
artifactType: artifactType2,
|
|
1116
|
+
required,
|
|
1117
|
+
description,
|
|
1118
|
+
isArray: true,
|
|
1119
|
+
minItems: property.minItems,
|
|
1120
|
+
maxItems: property.maxItems
|
|
1121
|
+
};
|
|
1122
|
+
}
|
|
1123
|
+
const artifactType = property.$ref ? getArtifactType(property.$ref) : "image";
|
|
1124
|
+
return {
|
|
1125
|
+
name: title,
|
|
1126
|
+
fieldName: name,
|
|
1127
|
+
artifactType,
|
|
1128
|
+
required,
|
|
1129
|
+
description,
|
|
1130
|
+
isArray: false
|
|
1131
|
+
};
|
|
1132
|
+
}
|
|
1133
|
+
function isSlider(property) {
|
|
1134
|
+
return (property.type === "number" || property.type === "integer") && property.minimum !== void 0 && property.maximum !== void 0;
|
|
1135
|
+
}
|
|
1136
|
+
function parseSettingsField(name, property) {
|
|
1137
|
+
const title = property.title || name;
|
|
1138
|
+
const description = property.description;
|
|
1139
|
+
if (property.enum && Array.isArray(property.enum)) {
|
|
1140
|
+
const options = property.enum.map((val) => String(val));
|
|
1141
|
+
const defaultValue = property.default !== void 0 ? String(property.default) : void 0;
|
|
1142
|
+
return {
|
|
1143
|
+
type: "dropdown",
|
|
1144
|
+
fieldName: name,
|
|
1145
|
+
title,
|
|
1146
|
+
description,
|
|
1147
|
+
options,
|
|
1148
|
+
default: defaultValue
|
|
1149
|
+
};
|
|
1150
|
+
}
|
|
1151
|
+
if (isSlider(property)) {
|
|
1152
|
+
const isInteger = property.type === "integer";
|
|
1153
|
+
return {
|
|
1154
|
+
type: "slider",
|
|
1155
|
+
fieldName: name,
|
|
1156
|
+
title,
|
|
1157
|
+
description,
|
|
1158
|
+
min: property.minimum,
|
|
1159
|
+
max: property.maximum,
|
|
1160
|
+
step: property.multipleOf,
|
|
1161
|
+
default: property.default !== void 0 ? property.default : void 0,
|
|
1162
|
+
isInteger
|
|
1163
|
+
};
|
|
1164
|
+
}
|
|
1165
|
+
if (property.type === "number" || property.type === "integer") {
|
|
1166
|
+
const isInteger = property.type === "integer";
|
|
1167
|
+
return {
|
|
1168
|
+
type: "number",
|
|
1169
|
+
fieldName: name,
|
|
1170
|
+
title,
|
|
1171
|
+
description,
|
|
1172
|
+
default: property.default !== void 0 ? property.default : void 0,
|
|
1173
|
+
min: property.minimum,
|
|
1174
|
+
max: property.maximum,
|
|
1175
|
+
isInteger
|
|
1176
|
+
};
|
|
1177
|
+
}
|
|
1178
|
+
if (property.type === "string") {
|
|
1179
|
+
return {
|
|
1180
|
+
type: "text",
|
|
1181
|
+
fieldName: name,
|
|
1182
|
+
title,
|
|
1183
|
+
description,
|
|
1184
|
+
default: property.default !== void 0 ? String(property.default) : void 0,
|
|
1185
|
+
pattern: property.pattern
|
|
1186
|
+
};
|
|
1187
|
+
}
|
|
1188
|
+
return null;
|
|
1189
|
+
}
|
|
1190
|
+
function parseGeneratorSchema(schema) {
|
|
1191
|
+
const artifactSlots = [];
|
|
1192
|
+
const settingsFields = [];
|
|
1193
|
+
let promptField = null;
|
|
1194
|
+
if (!schema.properties) {
|
|
1195
|
+
return { artifactSlots, promptField, settingsFields };
|
|
1196
|
+
}
|
|
1197
|
+
const required = schema.required || [];
|
|
1198
|
+
for (const [name, propertyDef] of Object.entries(schema.properties)) {
|
|
1199
|
+
if (typeof propertyDef === "boolean") {
|
|
1200
|
+
continue;
|
|
1201
|
+
}
|
|
1202
|
+
const property = propertyDef;
|
|
1203
|
+
const isRequired = required.includes(name);
|
|
1204
|
+
if (isArtifactReference(property)) {
|
|
1205
|
+
const slot = parseArtifactSlot(name, property, isRequired);
|
|
1206
|
+
artifactSlots.push(slot);
|
|
1207
|
+
continue;
|
|
1208
|
+
}
|
|
1209
|
+
if (name === "prompt" && property.type === "string") {
|
|
1210
|
+
promptField = {
|
|
1211
|
+
fieldName: name,
|
|
1212
|
+
description: property.description,
|
|
1213
|
+
required: isRequired,
|
|
1214
|
+
default: property.default !== void 0 ? String(property.default) : void 0
|
|
1215
|
+
};
|
|
1216
|
+
continue;
|
|
1217
|
+
}
|
|
1218
|
+
const settingsField = parseSettingsField(name, property);
|
|
1219
|
+
if (settingsField) {
|
|
1220
|
+
settingsFields.push(settingsField);
|
|
1221
|
+
}
|
|
1222
|
+
}
|
|
1223
|
+
return {
|
|
1224
|
+
artifactSlots,
|
|
1225
|
+
promptField,
|
|
1226
|
+
settingsFields
|
|
1227
|
+
};
|
|
1228
|
+
}
|
|
1229
|
+
|
|
1080
1230
|
// src/providers/BoardsProvider.tsx
|
|
1081
1231
|
var import_urql7 = require("urql");
|
|
1082
1232
|
var import_jsx_runtime3 = require("react/jsx-runtime");
|
|
@@ -1136,6 +1286,11 @@ var VERSION = "0.1.0";
|
|
|
1136
1286
|
USER_FRAGMENT,
|
|
1137
1287
|
VERSION,
|
|
1138
1288
|
createGraphQLClient,
|
|
1289
|
+
getArtifactType,
|
|
1290
|
+
isArtifactReference,
|
|
1291
|
+
parseArtifactSlot,
|
|
1292
|
+
parseGeneratorSchema,
|
|
1293
|
+
parseSettingsField,
|
|
1139
1294
|
useApiConfig,
|
|
1140
1295
|
useAuth,
|
|
1141
1296
|
useAuthOptional,
|