@weirdfingers/boards 0.4.1 → 0.5.1
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/dist/index.d.mts +176 -141
- package/dist/index.d.ts +176 -141
- package/dist/index.js +274 -181
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +270 -179
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/config/GeneratorSelectionContext.tsx +163 -0
- package/src/index.ts +4 -0
package/dist/index.mjs
CHANGED
|
@@ -205,6 +205,240 @@ function useApiConfig() {
|
|
|
205
205
|
return context;
|
|
206
206
|
}
|
|
207
207
|
|
|
208
|
+
// src/config/GeneratorSelectionContext.tsx
|
|
209
|
+
import { createContext as createContext3, useContext as useContext3, useState as useState2, useCallback as useCallback2, useMemo } from "react";
|
|
210
|
+
|
|
211
|
+
// src/utils/schemaParser.ts
|
|
212
|
+
function isArtifactReference(property) {
|
|
213
|
+
if (!property || typeof property === "boolean") {
|
|
214
|
+
return false;
|
|
215
|
+
}
|
|
216
|
+
if (property.$ref && property.$ref.includes("Artifact")) {
|
|
217
|
+
return true;
|
|
218
|
+
}
|
|
219
|
+
if (property.type === "array" && property.items && typeof property.items === "object" && !Array.isArray(property.items)) {
|
|
220
|
+
const items = property.items;
|
|
221
|
+
return !!(items.$ref && items.$ref.includes("Artifact"));
|
|
222
|
+
}
|
|
223
|
+
return false;
|
|
224
|
+
}
|
|
225
|
+
function getArtifactType(ref) {
|
|
226
|
+
const match = ref.match(/(Audio|Video|Image|Text)Artifact/);
|
|
227
|
+
if (match) {
|
|
228
|
+
return match[1].toLowerCase();
|
|
229
|
+
}
|
|
230
|
+
return "image";
|
|
231
|
+
}
|
|
232
|
+
function parseArtifactSlot(name, property, required) {
|
|
233
|
+
const title = property.title || name;
|
|
234
|
+
const description = property.description;
|
|
235
|
+
if (property.type === "array" && property.items) {
|
|
236
|
+
const items = typeof property.items === "object" && !Array.isArray(property.items) ? property.items : void 0;
|
|
237
|
+
const artifactType2 = items?.$ref ? getArtifactType(items.$ref) : "image";
|
|
238
|
+
return {
|
|
239
|
+
name: title,
|
|
240
|
+
fieldName: name,
|
|
241
|
+
artifactType: artifactType2,
|
|
242
|
+
required,
|
|
243
|
+
description,
|
|
244
|
+
isArray: true,
|
|
245
|
+
minItems: property.minItems,
|
|
246
|
+
maxItems: property.maxItems
|
|
247
|
+
};
|
|
248
|
+
}
|
|
249
|
+
const artifactType = property.$ref ? getArtifactType(property.$ref) : "image";
|
|
250
|
+
return {
|
|
251
|
+
name: title,
|
|
252
|
+
fieldName: name,
|
|
253
|
+
artifactType,
|
|
254
|
+
required,
|
|
255
|
+
description,
|
|
256
|
+
isArray: false
|
|
257
|
+
};
|
|
258
|
+
}
|
|
259
|
+
function isSlider(property) {
|
|
260
|
+
return (property.type === "number" || property.type === "integer") && property.minimum !== void 0 && property.maximum !== void 0;
|
|
261
|
+
}
|
|
262
|
+
function parseSettingsField(name, property) {
|
|
263
|
+
const title = property.title || name;
|
|
264
|
+
const description = property.description;
|
|
265
|
+
if (property.enum && Array.isArray(property.enum)) {
|
|
266
|
+
const options = property.enum.map((val) => String(val));
|
|
267
|
+
const defaultValue = property.default !== void 0 ? String(property.default) : void 0;
|
|
268
|
+
return {
|
|
269
|
+
type: "dropdown",
|
|
270
|
+
fieldName: name,
|
|
271
|
+
title,
|
|
272
|
+
description,
|
|
273
|
+
options,
|
|
274
|
+
default: defaultValue
|
|
275
|
+
};
|
|
276
|
+
}
|
|
277
|
+
if (isSlider(property)) {
|
|
278
|
+
const isInteger = property.type === "integer";
|
|
279
|
+
return {
|
|
280
|
+
type: "slider",
|
|
281
|
+
fieldName: name,
|
|
282
|
+
title,
|
|
283
|
+
description,
|
|
284
|
+
min: property.minimum,
|
|
285
|
+
max: property.maximum,
|
|
286
|
+
step: property.multipleOf,
|
|
287
|
+
default: property.default !== void 0 ? property.default : void 0,
|
|
288
|
+
isInteger
|
|
289
|
+
};
|
|
290
|
+
}
|
|
291
|
+
if (property.type === "number" || property.type === "integer") {
|
|
292
|
+
const isInteger = property.type === "integer";
|
|
293
|
+
return {
|
|
294
|
+
type: "number",
|
|
295
|
+
fieldName: name,
|
|
296
|
+
title,
|
|
297
|
+
description,
|
|
298
|
+
default: property.default !== void 0 ? property.default : void 0,
|
|
299
|
+
min: property.minimum,
|
|
300
|
+
max: property.maximum,
|
|
301
|
+
isInteger
|
|
302
|
+
};
|
|
303
|
+
}
|
|
304
|
+
if (property.type === "string") {
|
|
305
|
+
return {
|
|
306
|
+
type: "text",
|
|
307
|
+
fieldName: name,
|
|
308
|
+
title,
|
|
309
|
+
description,
|
|
310
|
+
default: property.default !== void 0 ? String(property.default) : void 0,
|
|
311
|
+
pattern: property.pattern
|
|
312
|
+
};
|
|
313
|
+
}
|
|
314
|
+
return null;
|
|
315
|
+
}
|
|
316
|
+
function parseGeneratorSchema(schema) {
|
|
317
|
+
const artifactSlots = [];
|
|
318
|
+
const settingsFields = [];
|
|
319
|
+
let promptField = null;
|
|
320
|
+
if (!schema.properties) {
|
|
321
|
+
return { artifactSlots, promptField, settingsFields };
|
|
322
|
+
}
|
|
323
|
+
const required = schema.required || [];
|
|
324
|
+
for (const [name, propertyDef] of Object.entries(schema.properties)) {
|
|
325
|
+
if (typeof propertyDef === "boolean") {
|
|
326
|
+
continue;
|
|
327
|
+
}
|
|
328
|
+
const property = propertyDef;
|
|
329
|
+
const isRequired = required.includes(name);
|
|
330
|
+
if (isArtifactReference(property)) {
|
|
331
|
+
const slot = parseArtifactSlot(name, property, isRequired);
|
|
332
|
+
artifactSlots.push(slot);
|
|
333
|
+
continue;
|
|
334
|
+
}
|
|
335
|
+
if (name === "prompt" && property.type === "string") {
|
|
336
|
+
promptField = {
|
|
337
|
+
fieldName: name,
|
|
338
|
+
description: property.description,
|
|
339
|
+
required: isRequired,
|
|
340
|
+
default: property.default !== void 0 ? String(property.default) : void 0
|
|
341
|
+
};
|
|
342
|
+
continue;
|
|
343
|
+
}
|
|
344
|
+
const settingsField = parseSettingsField(name, property);
|
|
345
|
+
if (settingsField) {
|
|
346
|
+
settingsFields.push(settingsField);
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
return {
|
|
350
|
+
artifactSlots,
|
|
351
|
+
promptField,
|
|
352
|
+
settingsFields
|
|
353
|
+
};
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
// src/config/GeneratorSelectionContext.tsx
|
|
357
|
+
import { jsx as jsx3 } from "react/jsx-runtime";
|
|
358
|
+
var GeneratorSelectionContext = createContext3(null);
|
|
359
|
+
function GeneratorSelectionProvider({
|
|
360
|
+
children
|
|
361
|
+
}) {
|
|
362
|
+
const [selectedGenerator, setSelectedGenerator] = useState2(null);
|
|
363
|
+
const [selectedArtifacts, setSelectedArtifacts] = useState2(/* @__PURE__ */ new Map());
|
|
364
|
+
const parsedSchema = useMemo(() => {
|
|
365
|
+
if (!selectedGenerator) {
|
|
366
|
+
return null;
|
|
367
|
+
}
|
|
368
|
+
try {
|
|
369
|
+
return parseGeneratorSchema(selectedGenerator.inputSchema);
|
|
370
|
+
} catch (error) {
|
|
371
|
+
console.error("Failed to parse generator schema:", error);
|
|
372
|
+
return null;
|
|
373
|
+
}
|
|
374
|
+
}, [selectedGenerator]);
|
|
375
|
+
const artifactSlots = useMemo(() => {
|
|
376
|
+
if (!parsedSchema) {
|
|
377
|
+
return [];
|
|
378
|
+
}
|
|
379
|
+
return parsedSchema.artifactSlots.map((slot) => ({
|
|
380
|
+
fieldName: slot.fieldName,
|
|
381
|
+
artifactType: slot.artifactType,
|
|
382
|
+
required: slot.required
|
|
383
|
+
}));
|
|
384
|
+
}, [parsedSchema]);
|
|
385
|
+
const canArtifactBeAdded = useCallback2((artifactType) => {
|
|
386
|
+
if (!artifactSlots.length) {
|
|
387
|
+
return false;
|
|
388
|
+
}
|
|
389
|
+
return artifactSlots.some(
|
|
390
|
+
(slot) => slot.artifactType.toLowerCase() === artifactType.toLowerCase() && !selectedArtifacts.has(slot.fieldName)
|
|
391
|
+
);
|
|
392
|
+
}, [artifactSlots, selectedArtifacts]);
|
|
393
|
+
const addArtifactToSlot = useCallback2((artifact) => {
|
|
394
|
+
if (!artifactSlots.length) {
|
|
395
|
+
return false;
|
|
396
|
+
}
|
|
397
|
+
const compatibleSlot = artifactSlots.find(
|
|
398
|
+
(slot) => slot.artifactType.toLowerCase() === artifact.artifactType.toLowerCase() && !selectedArtifacts.has(slot.fieldName)
|
|
399
|
+
);
|
|
400
|
+
if (!compatibleSlot) {
|
|
401
|
+
return false;
|
|
402
|
+
}
|
|
403
|
+
const newArtifacts = new Map(selectedArtifacts);
|
|
404
|
+
newArtifacts.set(compatibleSlot.fieldName, artifact);
|
|
405
|
+
setSelectedArtifacts(newArtifacts);
|
|
406
|
+
return true;
|
|
407
|
+
}, [artifactSlots, selectedArtifacts]);
|
|
408
|
+
const removeArtifactFromSlot = useCallback2((slotName) => {
|
|
409
|
+
const newArtifacts = new Map(selectedArtifacts);
|
|
410
|
+
newArtifacts.delete(slotName);
|
|
411
|
+
setSelectedArtifacts(newArtifacts);
|
|
412
|
+
}, [selectedArtifacts]);
|
|
413
|
+
const clearAllArtifacts = useCallback2(() => {
|
|
414
|
+
setSelectedArtifacts(/* @__PURE__ */ new Map());
|
|
415
|
+
}, []);
|
|
416
|
+
const handleSetSelectedGenerator = useCallback2((generator) => {
|
|
417
|
+
setSelectedGenerator(generator);
|
|
418
|
+
setSelectedArtifacts(/* @__PURE__ */ new Map());
|
|
419
|
+
}, []);
|
|
420
|
+
const value = {
|
|
421
|
+
selectedGenerator,
|
|
422
|
+
setSelectedGenerator: handleSetSelectedGenerator,
|
|
423
|
+
parsedSchema,
|
|
424
|
+
artifactSlots,
|
|
425
|
+
canArtifactBeAdded,
|
|
426
|
+
selectedArtifacts,
|
|
427
|
+
setSelectedArtifacts,
|
|
428
|
+
addArtifactToSlot,
|
|
429
|
+
removeArtifactFromSlot,
|
|
430
|
+
clearAllArtifacts
|
|
431
|
+
};
|
|
432
|
+
return /* @__PURE__ */ jsx3(GeneratorSelectionContext.Provider, { value, children });
|
|
433
|
+
}
|
|
434
|
+
function useGeneratorSelection() {
|
|
435
|
+
const context = useContext3(GeneratorSelectionContext);
|
|
436
|
+
if (!context) {
|
|
437
|
+
throw new Error("useGeneratorSelection must be used within GeneratorSelectionProvider");
|
|
438
|
+
}
|
|
439
|
+
return context;
|
|
440
|
+
}
|
|
441
|
+
|
|
208
442
|
// src/graphql/client.ts
|
|
209
443
|
import {
|
|
210
444
|
createClient,
|
|
@@ -535,19 +769,19 @@ var ArtifactType = /* @__PURE__ */ ((ArtifactType4) => {
|
|
|
535
769
|
})(ArtifactType || {});
|
|
536
770
|
|
|
537
771
|
// src/hooks/useBoards.ts
|
|
538
|
-
import { useCallback as
|
|
772
|
+
import { useCallback as useCallback3, useMemo as useMemo2, useState as useState3 } from "react";
|
|
539
773
|
import { useQuery, useMutation } from "urql";
|
|
540
774
|
function useBoards(options = {}) {
|
|
541
775
|
const { limit = 50, offset = 0 } = options;
|
|
542
|
-
const [searchQuery, setSearchQuery] =
|
|
776
|
+
const [searchQuery, setSearchQuery] = useState3("");
|
|
543
777
|
const [{ data, fetching, error }, reexecuteQuery] = useQuery({
|
|
544
778
|
query: GET_BOARDS,
|
|
545
779
|
variables: { limit, offset }
|
|
546
780
|
});
|
|
547
781
|
const [, createBoardMutation] = useMutation(CREATE_BOARD);
|
|
548
782
|
const [, deleteBoardMutation] = useMutation(DELETE_BOARD);
|
|
549
|
-
const boards =
|
|
550
|
-
const createBoard =
|
|
783
|
+
const boards = useMemo2(() => data?.myBoards || [], [data?.myBoards]);
|
|
784
|
+
const createBoard = useCallback3(
|
|
551
785
|
async (input) => {
|
|
552
786
|
const result = await createBoardMutation({ input });
|
|
553
787
|
if (result.error) {
|
|
@@ -561,7 +795,7 @@ function useBoards(options = {}) {
|
|
|
561
795
|
},
|
|
562
796
|
[createBoardMutation, reexecuteQuery]
|
|
563
797
|
);
|
|
564
|
-
const deleteBoard =
|
|
798
|
+
const deleteBoard = useCallback3(
|
|
565
799
|
async (boardId) => {
|
|
566
800
|
const result = await deleteBoardMutation({ id: boardId });
|
|
567
801
|
if (result.error) {
|
|
@@ -574,7 +808,7 @@ function useBoards(options = {}) {
|
|
|
574
808
|
},
|
|
575
809
|
[deleteBoardMutation, reexecuteQuery]
|
|
576
810
|
);
|
|
577
|
-
const searchBoards =
|
|
811
|
+
const searchBoards = useCallback3(
|
|
578
812
|
async (query) => {
|
|
579
813
|
setSearchQuery(query);
|
|
580
814
|
return new Promise((resolve) => {
|
|
@@ -589,7 +823,7 @@ function useBoards(options = {}) {
|
|
|
589
823
|
},
|
|
590
824
|
[boards]
|
|
591
825
|
);
|
|
592
|
-
const refresh =
|
|
826
|
+
const refresh = useCallback3(async () => {
|
|
593
827
|
await reexecuteQuery({ requestPolicy: "network-only" });
|
|
594
828
|
}, [reexecuteQuery]);
|
|
595
829
|
return {
|
|
@@ -606,7 +840,7 @@ function useBoards(options = {}) {
|
|
|
606
840
|
}
|
|
607
841
|
|
|
608
842
|
// src/hooks/useBoard.ts
|
|
609
|
-
import { useCallback as
|
|
843
|
+
import { useCallback as useCallback4, useMemo as useMemo3 } from "react";
|
|
610
844
|
import { useQuery as useQuery2, useMutation as useMutation2 } from "urql";
|
|
611
845
|
function useBoard(boardId, options) {
|
|
612
846
|
const { user } = useAuth();
|
|
@@ -627,9 +861,9 @@ function useBoard(boardId, options) {
|
|
|
627
861
|
const [, addMemberMutation] = useMutation2(ADD_BOARD_MEMBER);
|
|
628
862
|
const [, updateMemberRoleMutation] = useMutation2(UPDATE_BOARD_MEMBER_ROLE);
|
|
629
863
|
const [, removeMemberMutation] = useMutation2(REMOVE_BOARD_MEMBER);
|
|
630
|
-
const board =
|
|
631
|
-
const members =
|
|
632
|
-
const permissions =
|
|
864
|
+
const board = useMemo3(() => data?.board || null, [data?.board]);
|
|
865
|
+
const members = useMemo3(() => board?.members || [], [board?.members]);
|
|
866
|
+
const permissions = useMemo3(() => {
|
|
633
867
|
if (!board || !user) {
|
|
634
868
|
return {
|
|
635
869
|
canEdit: false,
|
|
@@ -658,7 +892,7 @@ function useBoard(boardId, options) {
|
|
|
658
892
|
// Even viewers can export
|
|
659
893
|
};
|
|
660
894
|
}, [board, user, members]);
|
|
661
|
-
const updateBoard =
|
|
895
|
+
const updateBoard = useCallback4(
|
|
662
896
|
async (updates) => {
|
|
663
897
|
if (!boardId) {
|
|
664
898
|
throw new Error("Board ID is required");
|
|
@@ -677,7 +911,7 @@ function useBoard(boardId, options) {
|
|
|
677
911
|
},
|
|
678
912
|
[boardId, updateBoardMutation]
|
|
679
913
|
);
|
|
680
|
-
const deleteBoard =
|
|
914
|
+
const deleteBoard = useCallback4(async () => {
|
|
681
915
|
if (!boardId) {
|
|
682
916
|
throw new Error("Board ID is required");
|
|
683
917
|
}
|
|
@@ -689,7 +923,7 @@ function useBoard(boardId, options) {
|
|
|
689
923
|
throw new Error("Failed to delete board");
|
|
690
924
|
}
|
|
691
925
|
}, [boardId, deleteBoardMutation]);
|
|
692
|
-
const addMember =
|
|
926
|
+
const addMember = useCallback4(
|
|
693
927
|
async (email, role) => {
|
|
694
928
|
if (!boardId) {
|
|
695
929
|
throw new Error("Board ID is required");
|
|
@@ -710,7 +944,7 @@ function useBoard(boardId, options) {
|
|
|
710
944
|
},
|
|
711
945
|
[boardId, addMemberMutation, reexecuteQuery]
|
|
712
946
|
);
|
|
713
|
-
const removeMember =
|
|
947
|
+
const removeMember = useCallback4(
|
|
714
948
|
async (memberId) => {
|
|
715
949
|
const result = await removeMemberMutation({ id: memberId });
|
|
716
950
|
if (result.error) {
|
|
@@ -723,7 +957,7 @@ function useBoard(boardId, options) {
|
|
|
723
957
|
},
|
|
724
958
|
[removeMemberMutation, reexecuteQuery]
|
|
725
959
|
);
|
|
726
|
-
const updateMemberRole =
|
|
960
|
+
const updateMemberRole = useCallback4(
|
|
727
961
|
async (memberId, role) => {
|
|
728
962
|
const result = await updateMemberRoleMutation({
|
|
729
963
|
id: memberId,
|
|
@@ -740,19 +974,19 @@ function useBoard(boardId, options) {
|
|
|
740
974
|
},
|
|
741
975
|
[updateMemberRoleMutation, reexecuteQuery]
|
|
742
976
|
);
|
|
743
|
-
const generateShareLink =
|
|
977
|
+
const generateShareLink = useCallback4(
|
|
744
978
|
async (_options) => {
|
|
745
979
|
throw new Error("Share links not implemented yet");
|
|
746
980
|
},
|
|
747
981
|
[]
|
|
748
982
|
);
|
|
749
|
-
const revokeShareLink =
|
|
983
|
+
const revokeShareLink = useCallback4(
|
|
750
984
|
async (_linkId) => {
|
|
751
985
|
throw new Error("Share link revocation not implemented yet");
|
|
752
986
|
},
|
|
753
987
|
[]
|
|
754
988
|
);
|
|
755
|
-
const refresh =
|
|
989
|
+
const refresh = useCallback4(async () => {
|
|
756
990
|
await reexecuteQuery({ requestPolicy: "network-only" });
|
|
757
991
|
}, [reexecuteQuery]);
|
|
758
992
|
return {
|
|
@@ -773,15 +1007,15 @@ function useBoard(boardId, options) {
|
|
|
773
1007
|
}
|
|
774
1008
|
|
|
775
1009
|
// src/hooks/useGeneration.ts
|
|
776
|
-
import { useCallback as
|
|
1010
|
+
import { useCallback as useCallback5, useState as useState4, useEffect as useEffect2, useRef } from "react";
|
|
777
1011
|
import { fetchEventSource } from "@microsoft/fetch-event-source";
|
|
778
1012
|
import { useMutation as useMutation3 } from "urql";
|
|
779
1013
|
function useGeneration() {
|
|
780
|
-
const [progress, setProgress] =
|
|
781
|
-
const [result, setResult] =
|
|
782
|
-
const [error, setError] =
|
|
783
|
-
const [isGenerating, setIsGenerating] =
|
|
784
|
-
const [history, setHistory] =
|
|
1014
|
+
const [progress, setProgress] = useState4(null);
|
|
1015
|
+
const [result, setResult] = useState4(null);
|
|
1016
|
+
const [error, setError] = useState4(null);
|
|
1017
|
+
const [isGenerating, setIsGenerating] = useState4(false);
|
|
1018
|
+
const [history, setHistory] = useState4([]);
|
|
785
1019
|
const { apiUrl } = useApiConfig();
|
|
786
1020
|
const auth = useAuth();
|
|
787
1021
|
const abortControllers = useRef(/* @__PURE__ */ new Map());
|
|
@@ -796,7 +1030,7 @@ function useGeneration() {
|
|
|
796
1030
|
abortControllers.current.clear();
|
|
797
1031
|
};
|
|
798
1032
|
}, []);
|
|
799
|
-
const connectToSSE =
|
|
1033
|
+
const connectToSSE = useCallback5(
|
|
800
1034
|
async (jobId) => {
|
|
801
1035
|
const existingController = abortControllers.current.get(jobId);
|
|
802
1036
|
if (existingController) {
|
|
@@ -900,7 +1134,7 @@ function useGeneration() {
|
|
|
900
1134
|
},
|
|
901
1135
|
[apiUrl, auth]
|
|
902
1136
|
);
|
|
903
|
-
const submit =
|
|
1137
|
+
const submit = useCallback5(
|
|
904
1138
|
async (request) => {
|
|
905
1139
|
setError(null);
|
|
906
1140
|
setProgress(null);
|
|
@@ -952,7 +1186,7 @@ function useGeneration() {
|
|
|
952
1186
|
},
|
|
953
1187
|
[createGenerationMutation, connectToSSE]
|
|
954
1188
|
);
|
|
955
|
-
const cancel =
|
|
1189
|
+
const cancel = useCallback5(
|
|
956
1190
|
async (jobId) => {
|
|
957
1191
|
try {
|
|
958
1192
|
const result2 = await cancelGenerationMutation({ id: jobId });
|
|
@@ -974,7 +1208,7 @@ function useGeneration() {
|
|
|
974
1208
|
},
|
|
975
1209
|
[cancelGenerationMutation]
|
|
976
1210
|
);
|
|
977
|
-
const retry =
|
|
1211
|
+
const retry = useCallback5(
|
|
978
1212
|
async (jobId) => {
|
|
979
1213
|
try {
|
|
980
1214
|
setError(null);
|
|
@@ -997,7 +1231,7 @@ function useGeneration() {
|
|
|
997
1231
|
},
|
|
998
1232
|
[retryGenerationMutation, connectToSSE]
|
|
999
1233
|
);
|
|
1000
|
-
const clearHistory =
|
|
1234
|
+
const clearHistory = useCallback5(() => {
|
|
1001
1235
|
setHistory([]);
|
|
1002
1236
|
}, []);
|
|
1003
1237
|
return {
|
|
@@ -1014,7 +1248,7 @@ function useGeneration() {
|
|
|
1014
1248
|
}
|
|
1015
1249
|
|
|
1016
1250
|
// src/hooks/useGenerators.ts
|
|
1017
|
-
import { useMemo as
|
|
1251
|
+
import { useMemo as useMemo4 } from "react";
|
|
1018
1252
|
import { useQuery as useQuery3 } from "urql";
|
|
1019
1253
|
function useGenerators(options = {}) {
|
|
1020
1254
|
const { artifactType } = options;
|
|
@@ -1022,7 +1256,7 @@ function useGenerators(options = {}) {
|
|
|
1022
1256
|
query: GET_GENERATORS,
|
|
1023
1257
|
variables: artifactType ? { artifactType } : {}
|
|
1024
1258
|
});
|
|
1025
|
-
const generators =
|
|
1259
|
+
const generators = useMemo4(() => data?.generators || [], [data?.generators]);
|
|
1026
1260
|
return {
|
|
1027
1261
|
generators,
|
|
1028
1262
|
loading: fetching,
|
|
@@ -1030,154 +1264,9 @@ function useGenerators(options = {}) {
|
|
|
1030
1264
|
};
|
|
1031
1265
|
}
|
|
1032
1266
|
|
|
1033
|
-
// src/utils/schemaParser.ts
|
|
1034
|
-
function isArtifactReference(property) {
|
|
1035
|
-
if (!property || typeof property === "boolean") {
|
|
1036
|
-
return false;
|
|
1037
|
-
}
|
|
1038
|
-
if (property.$ref && property.$ref.includes("Artifact")) {
|
|
1039
|
-
return true;
|
|
1040
|
-
}
|
|
1041
|
-
if (property.type === "array" && property.items && typeof property.items === "object" && !Array.isArray(property.items)) {
|
|
1042
|
-
const items = property.items;
|
|
1043
|
-
return !!(items.$ref && items.$ref.includes("Artifact"));
|
|
1044
|
-
}
|
|
1045
|
-
return false;
|
|
1046
|
-
}
|
|
1047
|
-
function getArtifactType(ref) {
|
|
1048
|
-
const match = ref.match(/(Audio|Video|Image|Text)Artifact/);
|
|
1049
|
-
if (match) {
|
|
1050
|
-
return match[1].toLowerCase();
|
|
1051
|
-
}
|
|
1052
|
-
return "image";
|
|
1053
|
-
}
|
|
1054
|
-
function parseArtifactSlot(name, property, required) {
|
|
1055
|
-
const title = property.title || name;
|
|
1056
|
-
const description = property.description;
|
|
1057
|
-
if (property.type === "array" && property.items) {
|
|
1058
|
-
const items = typeof property.items === "object" && !Array.isArray(property.items) ? property.items : void 0;
|
|
1059
|
-
const artifactType2 = items?.$ref ? getArtifactType(items.$ref) : "image";
|
|
1060
|
-
return {
|
|
1061
|
-
name: title,
|
|
1062
|
-
fieldName: name,
|
|
1063
|
-
artifactType: artifactType2,
|
|
1064
|
-
required,
|
|
1065
|
-
description,
|
|
1066
|
-
isArray: true,
|
|
1067
|
-
minItems: property.minItems,
|
|
1068
|
-
maxItems: property.maxItems
|
|
1069
|
-
};
|
|
1070
|
-
}
|
|
1071
|
-
const artifactType = property.$ref ? getArtifactType(property.$ref) : "image";
|
|
1072
|
-
return {
|
|
1073
|
-
name: title,
|
|
1074
|
-
fieldName: name,
|
|
1075
|
-
artifactType,
|
|
1076
|
-
required,
|
|
1077
|
-
description,
|
|
1078
|
-
isArray: false
|
|
1079
|
-
};
|
|
1080
|
-
}
|
|
1081
|
-
function isSlider(property) {
|
|
1082
|
-
return (property.type === "number" || property.type === "integer") && property.minimum !== void 0 && property.maximum !== void 0;
|
|
1083
|
-
}
|
|
1084
|
-
function parseSettingsField(name, property) {
|
|
1085
|
-
const title = property.title || name;
|
|
1086
|
-
const description = property.description;
|
|
1087
|
-
if (property.enum && Array.isArray(property.enum)) {
|
|
1088
|
-
const options = property.enum.map((val) => String(val));
|
|
1089
|
-
const defaultValue = property.default !== void 0 ? String(property.default) : void 0;
|
|
1090
|
-
return {
|
|
1091
|
-
type: "dropdown",
|
|
1092
|
-
fieldName: name,
|
|
1093
|
-
title,
|
|
1094
|
-
description,
|
|
1095
|
-
options,
|
|
1096
|
-
default: defaultValue
|
|
1097
|
-
};
|
|
1098
|
-
}
|
|
1099
|
-
if (isSlider(property)) {
|
|
1100
|
-
const isInteger = property.type === "integer";
|
|
1101
|
-
return {
|
|
1102
|
-
type: "slider",
|
|
1103
|
-
fieldName: name,
|
|
1104
|
-
title,
|
|
1105
|
-
description,
|
|
1106
|
-
min: property.minimum,
|
|
1107
|
-
max: property.maximum,
|
|
1108
|
-
step: property.multipleOf,
|
|
1109
|
-
default: property.default !== void 0 ? property.default : void 0,
|
|
1110
|
-
isInteger
|
|
1111
|
-
};
|
|
1112
|
-
}
|
|
1113
|
-
if (property.type === "number" || property.type === "integer") {
|
|
1114
|
-
const isInteger = property.type === "integer";
|
|
1115
|
-
return {
|
|
1116
|
-
type: "number",
|
|
1117
|
-
fieldName: name,
|
|
1118
|
-
title,
|
|
1119
|
-
description,
|
|
1120
|
-
default: property.default !== void 0 ? property.default : void 0,
|
|
1121
|
-
min: property.minimum,
|
|
1122
|
-
max: property.maximum,
|
|
1123
|
-
isInteger
|
|
1124
|
-
};
|
|
1125
|
-
}
|
|
1126
|
-
if (property.type === "string") {
|
|
1127
|
-
return {
|
|
1128
|
-
type: "text",
|
|
1129
|
-
fieldName: name,
|
|
1130
|
-
title,
|
|
1131
|
-
description,
|
|
1132
|
-
default: property.default !== void 0 ? String(property.default) : void 0,
|
|
1133
|
-
pattern: property.pattern
|
|
1134
|
-
};
|
|
1135
|
-
}
|
|
1136
|
-
return null;
|
|
1137
|
-
}
|
|
1138
|
-
function parseGeneratorSchema(schema) {
|
|
1139
|
-
const artifactSlots = [];
|
|
1140
|
-
const settingsFields = [];
|
|
1141
|
-
let promptField = null;
|
|
1142
|
-
if (!schema.properties) {
|
|
1143
|
-
return { artifactSlots, promptField, settingsFields };
|
|
1144
|
-
}
|
|
1145
|
-
const required = schema.required || [];
|
|
1146
|
-
for (const [name, propertyDef] of Object.entries(schema.properties)) {
|
|
1147
|
-
if (typeof propertyDef === "boolean") {
|
|
1148
|
-
continue;
|
|
1149
|
-
}
|
|
1150
|
-
const property = propertyDef;
|
|
1151
|
-
const isRequired = required.includes(name);
|
|
1152
|
-
if (isArtifactReference(property)) {
|
|
1153
|
-
const slot = parseArtifactSlot(name, property, isRequired);
|
|
1154
|
-
artifactSlots.push(slot);
|
|
1155
|
-
continue;
|
|
1156
|
-
}
|
|
1157
|
-
if (name === "prompt" && property.type === "string") {
|
|
1158
|
-
promptField = {
|
|
1159
|
-
fieldName: name,
|
|
1160
|
-
description: property.description,
|
|
1161
|
-
required: isRequired,
|
|
1162
|
-
default: property.default !== void 0 ? String(property.default) : void 0
|
|
1163
|
-
};
|
|
1164
|
-
continue;
|
|
1165
|
-
}
|
|
1166
|
-
const settingsField = parseSettingsField(name, property);
|
|
1167
|
-
if (settingsField) {
|
|
1168
|
-
settingsFields.push(settingsField);
|
|
1169
|
-
}
|
|
1170
|
-
}
|
|
1171
|
-
return {
|
|
1172
|
-
artifactSlots,
|
|
1173
|
-
promptField,
|
|
1174
|
-
settingsFields
|
|
1175
|
-
};
|
|
1176
|
-
}
|
|
1177
|
-
|
|
1178
1267
|
// src/providers/BoardsProvider.tsx
|
|
1179
1268
|
import { Provider as UrqlProvider } from "urql";
|
|
1180
|
-
import { jsx as
|
|
1269
|
+
import { jsx as jsx4 } from "react/jsx-runtime";
|
|
1181
1270
|
function BoardsProvider({
|
|
1182
1271
|
children,
|
|
1183
1272
|
apiUrl,
|
|
@@ -1200,7 +1289,7 @@ function BoardsProvider({
|
|
|
1200
1289
|
},
|
|
1201
1290
|
tenantId
|
|
1202
1291
|
});
|
|
1203
|
-
return /* @__PURE__ */
|
|
1292
|
+
return /* @__PURE__ */ jsx4(AuthProvider, { provider: authProvider, children: /* @__PURE__ */ jsx4(ApiConfigProvider, { config: apiConfig, children: /* @__PURE__ */ jsx4(UrqlProvider, { value: client, children }) }) });
|
|
1204
1293
|
}
|
|
1205
1294
|
|
|
1206
1295
|
// src/index.ts
|
|
@@ -1225,6 +1314,7 @@ export {
|
|
|
1225
1314
|
GET_GENERATIONS,
|
|
1226
1315
|
GET_GENERATORS,
|
|
1227
1316
|
GenerationStatus,
|
|
1317
|
+
GeneratorSelectionProvider,
|
|
1228
1318
|
NoAuthProvider,
|
|
1229
1319
|
REMOVE_BOARD_MEMBER,
|
|
1230
1320
|
RETRY_GENERATION,
|
|
@@ -1244,6 +1334,7 @@ export {
|
|
|
1244
1334
|
useBoard,
|
|
1245
1335
|
useBoards,
|
|
1246
1336
|
useGeneration,
|
|
1337
|
+
useGeneratorSelection,
|
|
1247
1338
|
useGenerators
|
|
1248
1339
|
};
|
|
1249
1340
|
//# sourceMappingURL=index.mjs.map
|