@weirdfingers/boards 0.4.0 → 0.5.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/dist/index.d.mts +180 -142
- package/dist/index.d.ts +180 -142
- package/dist/index.js +283 -185
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +279 -183
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/config/GeneratorSelectionContext.tsx +163 -0
- package/src/graphql/operations.ts +2 -2
- package/src/hooks/useBoard.ts +9 -2
- 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,
|
|
@@ -364,7 +598,7 @@ var GET_BOARD = gql`
|
|
|
364
598
|
${BOARD_FRAGMENT}
|
|
365
599
|
${USER_FRAGMENT}
|
|
366
600
|
${GENERATION_FRAGMENT}
|
|
367
|
-
query GetBoard($id: UUID
|
|
601
|
+
query GetBoard($id: UUID!, $limit: Int, $offset: Int) {
|
|
368
602
|
board(id: $id) {
|
|
369
603
|
...BoardFragment
|
|
370
604
|
owner {
|
|
@@ -384,7 +618,7 @@ var GET_BOARD = gql`
|
|
|
384
618
|
...UserFragment
|
|
385
619
|
}
|
|
386
620
|
}
|
|
387
|
-
generations(limit:
|
|
621
|
+
generations(limit: $limit, offset: $offset) {
|
|
388
622
|
...GenerationFragment
|
|
389
623
|
}
|
|
390
624
|
}
|
|
@@ -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,13 +840,18 @@ 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
|
-
function useBoard(boardId) {
|
|
845
|
+
function useBoard(boardId, options) {
|
|
612
846
|
const { user } = useAuth();
|
|
613
847
|
const [{ data, fetching, error }, reexecuteQuery] = useQuery2({
|
|
614
848
|
query: GET_BOARD,
|
|
615
|
-
variables: {
|
|
849
|
+
variables: {
|
|
850
|
+
id: boardId,
|
|
851
|
+
limit: options?.limit ?? 100,
|
|
852
|
+
// Default to 100 generations
|
|
853
|
+
offset: options?.offset ?? 0
|
|
854
|
+
},
|
|
616
855
|
pause: !boardId,
|
|
617
856
|
requestPolicy: "cache-and-network"
|
|
618
857
|
// Always fetch fresh data while showing cached data
|
|
@@ -622,9 +861,9 @@ function useBoard(boardId) {
|
|
|
622
861
|
const [, addMemberMutation] = useMutation2(ADD_BOARD_MEMBER);
|
|
623
862
|
const [, updateMemberRoleMutation] = useMutation2(UPDATE_BOARD_MEMBER_ROLE);
|
|
624
863
|
const [, removeMemberMutation] = useMutation2(REMOVE_BOARD_MEMBER);
|
|
625
|
-
const board =
|
|
626
|
-
const members =
|
|
627
|
-
const permissions =
|
|
864
|
+
const board = useMemo3(() => data?.board || null, [data?.board]);
|
|
865
|
+
const members = useMemo3(() => board?.members || [], [board?.members]);
|
|
866
|
+
const permissions = useMemo3(() => {
|
|
628
867
|
if (!board || !user) {
|
|
629
868
|
return {
|
|
630
869
|
canEdit: false,
|
|
@@ -653,7 +892,7 @@ function useBoard(boardId) {
|
|
|
653
892
|
// Even viewers can export
|
|
654
893
|
};
|
|
655
894
|
}, [board, user, members]);
|
|
656
|
-
const updateBoard =
|
|
895
|
+
const updateBoard = useCallback4(
|
|
657
896
|
async (updates) => {
|
|
658
897
|
if (!boardId) {
|
|
659
898
|
throw new Error("Board ID is required");
|
|
@@ -672,7 +911,7 @@ function useBoard(boardId) {
|
|
|
672
911
|
},
|
|
673
912
|
[boardId, updateBoardMutation]
|
|
674
913
|
);
|
|
675
|
-
const deleteBoard =
|
|
914
|
+
const deleteBoard = useCallback4(async () => {
|
|
676
915
|
if (!boardId) {
|
|
677
916
|
throw new Error("Board ID is required");
|
|
678
917
|
}
|
|
@@ -684,7 +923,7 @@ function useBoard(boardId) {
|
|
|
684
923
|
throw new Error("Failed to delete board");
|
|
685
924
|
}
|
|
686
925
|
}, [boardId, deleteBoardMutation]);
|
|
687
|
-
const addMember =
|
|
926
|
+
const addMember = useCallback4(
|
|
688
927
|
async (email, role) => {
|
|
689
928
|
if (!boardId) {
|
|
690
929
|
throw new Error("Board ID is required");
|
|
@@ -705,7 +944,7 @@ function useBoard(boardId) {
|
|
|
705
944
|
},
|
|
706
945
|
[boardId, addMemberMutation, reexecuteQuery]
|
|
707
946
|
);
|
|
708
|
-
const removeMember =
|
|
947
|
+
const removeMember = useCallback4(
|
|
709
948
|
async (memberId) => {
|
|
710
949
|
const result = await removeMemberMutation({ id: memberId });
|
|
711
950
|
if (result.error) {
|
|
@@ -718,7 +957,7 @@ function useBoard(boardId) {
|
|
|
718
957
|
},
|
|
719
958
|
[removeMemberMutation, reexecuteQuery]
|
|
720
959
|
);
|
|
721
|
-
const updateMemberRole =
|
|
960
|
+
const updateMemberRole = useCallback4(
|
|
722
961
|
async (memberId, role) => {
|
|
723
962
|
const result = await updateMemberRoleMutation({
|
|
724
963
|
id: memberId,
|
|
@@ -735,19 +974,19 @@ function useBoard(boardId) {
|
|
|
735
974
|
},
|
|
736
975
|
[updateMemberRoleMutation, reexecuteQuery]
|
|
737
976
|
);
|
|
738
|
-
const generateShareLink =
|
|
977
|
+
const generateShareLink = useCallback4(
|
|
739
978
|
async (_options) => {
|
|
740
979
|
throw new Error("Share links not implemented yet");
|
|
741
980
|
},
|
|
742
981
|
[]
|
|
743
982
|
);
|
|
744
|
-
const revokeShareLink =
|
|
983
|
+
const revokeShareLink = useCallback4(
|
|
745
984
|
async (_linkId) => {
|
|
746
985
|
throw new Error("Share link revocation not implemented yet");
|
|
747
986
|
},
|
|
748
987
|
[]
|
|
749
988
|
);
|
|
750
|
-
const refresh =
|
|
989
|
+
const refresh = useCallback4(async () => {
|
|
751
990
|
await reexecuteQuery({ requestPolicy: "network-only" });
|
|
752
991
|
}, [reexecuteQuery]);
|
|
753
992
|
return {
|
|
@@ -768,15 +1007,15 @@ function useBoard(boardId) {
|
|
|
768
1007
|
}
|
|
769
1008
|
|
|
770
1009
|
// src/hooks/useGeneration.ts
|
|
771
|
-
import { useCallback as
|
|
1010
|
+
import { useCallback as useCallback5, useState as useState4, useEffect as useEffect2, useRef } from "react";
|
|
772
1011
|
import { fetchEventSource } from "@microsoft/fetch-event-source";
|
|
773
1012
|
import { useMutation as useMutation3 } from "urql";
|
|
774
1013
|
function useGeneration() {
|
|
775
|
-
const [progress, setProgress] =
|
|
776
|
-
const [result, setResult] =
|
|
777
|
-
const [error, setError] =
|
|
778
|
-
const [isGenerating, setIsGenerating] =
|
|
779
|
-
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([]);
|
|
780
1019
|
const { apiUrl } = useApiConfig();
|
|
781
1020
|
const auth = useAuth();
|
|
782
1021
|
const abortControllers = useRef(/* @__PURE__ */ new Map());
|
|
@@ -791,7 +1030,7 @@ function useGeneration() {
|
|
|
791
1030
|
abortControllers.current.clear();
|
|
792
1031
|
};
|
|
793
1032
|
}, []);
|
|
794
|
-
const connectToSSE =
|
|
1033
|
+
const connectToSSE = useCallback5(
|
|
795
1034
|
async (jobId) => {
|
|
796
1035
|
const existingController = abortControllers.current.get(jobId);
|
|
797
1036
|
if (existingController) {
|
|
@@ -895,7 +1134,7 @@ function useGeneration() {
|
|
|
895
1134
|
},
|
|
896
1135
|
[apiUrl, auth]
|
|
897
1136
|
);
|
|
898
|
-
const submit =
|
|
1137
|
+
const submit = useCallback5(
|
|
899
1138
|
async (request) => {
|
|
900
1139
|
setError(null);
|
|
901
1140
|
setProgress(null);
|
|
@@ -947,7 +1186,7 @@ function useGeneration() {
|
|
|
947
1186
|
},
|
|
948
1187
|
[createGenerationMutation, connectToSSE]
|
|
949
1188
|
);
|
|
950
|
-
const cancel =
|
|
1189
|
+
const cancel = useCallback5(
|
|
951
1190
|
async (jobId) => {
|
|
952
1191
|
try {
|
|
953
1192
|
const result2 = await cancelGenerationMutation({ id: jobId });
|
|
@@ -969,7 +1208,7 @@ function useGeneration() {
|
|
|
969
1208
|
},
|
|
970
1209
|
[cancelGenerationMutation]
|
|
971
1210
|
);
|
|
972
|
-
const retry =
|
|
1211
|
+
const retry = useCallback5(
|
|
973
1212
|
async (jobId) => {
|
|
974
1213
|
try {
|
|
975
1214
|
setError(null);
|
|
@@ -992,7 +1231,7 @@ function useGeneration() {
|
|
|
992
1231
|
},
|
|
993
1232
|
[retryGenerationMutation, connectToSSE]
|
|
994
1233
|
);
|
|
995
|
-
const clearHistory =
|
|
1234
|
+
const clearHistory = useCallback5(() => {
|
|
996
1235
|
setHistory([]);
|
|
997
1236
|
}, []);
|
|
998
1237
|
return {
|
|
@@ -1009,7 +1248,7 @@ function useGeneration() {
|
|
|
1009
1248
|
}
|
|
1010
1249
|
|
|
1011
1250
|
// src/hooks/useGenerators.ts
|
|
1012
|
-
import { useMemo as
|
|
1251
|
+
import { useMemo as useMemo4 } from "react";
|
|
1013
1252
|
import { useQuery as useQuery3 } from "urql";
|
|
1014
1253
|
function useGenerators(options = {}) {
|
|
1015
1254
|
const { artifactType } = options;
|
|
@@ -1017,7 +1256,7 @@ function useGenerators(options = {}) {
|
|
|
1017
1256
|
query: GET_GENERATORS,
|
|
1018
1257
|
variables: artifactType ? { artifactType } : {}
|
|
1019
1258
|
});
|
|
1020
|
-
const generators =
|
|
1259
|
+
const generators = useMemo4(() => data?.generators || [], [data?.generators]);
|
|
1021
1260
|
return {
|
|
1022
1261
|
generators,
|
|
1023
1262
|
loading: fetching,
|
|
@@ -1025,154 +1264,9 @@ function useGenerators(options = {}) {
|
|
|
1025
1264
|
};
|
|
1026
1265
|
}
|
|
1027
1266
|
|
|
1028
|
-
// src/utils/schemaParser.ts
|
|
1029
|
-
function isArtifactReference(property) {
|
|
1030
|
-
if (!property || typeof property === "boolean") {
|
|
1031
|
-
return false;
|
|
1032
|
-
}
|
|
1033
|
-
if (property.$ref && property.$ref.includes("Artifact")) {
|
|
1034
|
-
return true;
|
|
1035
|
-
}
|
|
1036
|
-
if (property.type === "array" && property.items && typeof property.items === "object" && !Array.isArray(property.items)) {
|
|
1037
|
-
const items = property.items;
|
|
1038
|
-
return !!(items.$ref && items.$ref.includes("Artifact"));
|
|
1039
|
-
}
|
|
1040
|
-
return false;
|
|
1041
|
-
}
|
|
1042
|
-
function getArtifactType(ref) {
|
|
1043
|
-
const match = ref.match(/(Audio|Video|Image|Text)Artifact/);
|
|
1044
|
-
if (match) {
|
|
1045
|
-
return match[1].toLowerCase();
|
|
1046
|
-
}
|
|
1047
|
-
return "image";
|
|
1048
|
-
}
|
|
1049
|
-
function parseArtifactSlot(name, property, required) {
|
|
1050
|
-
const title = property.title || name;
|
|
1051
|
-
const description = property.description;
|
|
1052
|
-
if (property.type === "array" && property.items) {
|
|
1053
|
-
const items = typeof property.items === "object" && !Array.isArray(property.items) ? property.items : void 0;
|
|
1054
|
-
const artifactType2 = items?.$ref ? getArtifactType(items.$ref) : "image";
|
|
1055
|
-
return {
|
|
1056
|
-
name: title,
|
|
1057
|
-
fieldName: name,
|
|
1058
|
-
artifactType: artifactType2,
|
|
1059
|
-
required,
|
|
1060
|
-
description,
|
|
1061
|
-
isArray: true,
|
|
1062
|
-
minItems: property.minItems,
|
|
1063
|
-
maxItems: property.maxItems
|
|
1064
|
-
};
|
|
1065
|
-
}
|
|
1066
|
-
const artifactType = property.$ref ? getArtifactType(property.$ref) : "image";
|
|
1067
|
-
return {
|
|
1068
|
-
name: title,
|
|
1069
|
-
fieldName: name,
|
|
1070
|
-
artifactType,
|
|
1071
|
-
required,
|
|
1072
|
-
description,
|
|
1073
|
-
isArray: false
|
|
1074
|
-
};
|
|
1075
|
-
}
|
|
1076
|
-
function isSlider(property) {
|
|
1077
|
-
return (property.type === "number" || property.type === "integer") && property.minimum !== void 0 && property.maximum !== void 0;
|
|
1078
|
-
}
|
|
1079
|
-
function parseSettingsField(name, property) {
|
|
1080
|
-
const title = property.title || name;
|
|
1081
|
-
const description = property.description;
|
|
1082
|
-
if (property.enum && Array.isArray(property.enum)) {
|
|
1083
|
-
const options = property.enum.map((val) => String(val));
|
|
1084
|
-
const defaultValue = property.default !== void 0 ? String(property.default) : void 0;
|
|
1085
|
-
return {
|
|
1086
|
-
type: "dropdown",
|
|
1087
|
-
fieldName: name,
|
|
1088
|
-
title,
|
|
1089
|
-
description,
|
|
1090
|
-
options,
|
|
1091
|
-
default: defaultValue
|
|
1092
|
-
};
|
|
1093
|
-
}
|
|
1094
|
-
if (isSlider(property)) {
|
|
1095
|
-
const isInteger = property.type === "integer";
|
|
1096
|
-
return {
|
|
1097
|
-
type: "slider",
|
|
1098
|
-
fieldName: name,
|
|
1099
|
-
title,
|
|
1100
|
-
description,
|
|
1101
|
-
min: property.minimum,
|
|
1102
|
-
max: property.maximum,
|
|
1103
|
-
step: property.multipleOf,
|
|
1104
|
-
default: property.default !== void 0 ? property.default : void 0,
|
|
1105
|
-
isInteger
|
|
1106
|
-
};
|
|
1107
|
-
}
|
|
1108
|
-
if (property.type === "number" || property.type === "integer") {
|
|
1109
|
-
const isInteger = property.type === "integer";
|
|
1110
|
-
return {
|
|
1111
|
-
type: "number",
|
|
1112
|
-
fieldName: name,
|
|
1113
|
-
title,
|
|
1114
|
-
description,
|
|
1115
|
-
default: property.default !== void 0 ? property.default : void 0,
|
|
1116
|
-
min: property.minimum,
|
|
1117
|
-
max: property.maximum,
|
|
1118
|
-
isInteger
|
|
1119
|
-
};
|
|
1120
|
-
}
|
|
1121
|
-
if (property.type === "string") {
|
|
1122
|
-
return {
|
|
1123
|
-
type: "text",
|
|
1124
|
-
fieldName: name,
|
|
1125
|
-
title,
|
|
1126
|
-
description,
|
|
1127
|
-
default: property.default !== void 0 ? String(property.default) : void 0,
|
|
1128
|
-
pattern: property.pattern
|
|
1129
|
-
};
|
|
1130
|
-
}
|
|
1131
|
-
return null;
|
|
1132
|
-
}
|
|
1133
|
-
function parseGeneratorSchema(schema) {
|
|
1134
|
-
const artifactSlots = [];
|
|
1135
|
-
const settingsFields = [];
|
|
1136
|
-
let promptField = null;
|
|
1137
|
-
if (!schema.properties) {
|
|
1138
|
-
return { artifactSlots, promptField, settingsFields };
|
|
1139
|
-
}
|
|
1140
|
-
const required = schema.required || [];
|
|
1141
|
-
for (const [name, propertyDef] of Object.entries(schema.properties)) {
|
|
1142
|
-
if (typeof propertyDef === "boolean") {
|
|
1143
|
-
continue;
|
|
1144
|
-
}
|
|
1145
|
-
const property = propertyDef;
|
|
1146
|
-
const isRequired = required.includes(name);
|
|
1147
|
-
if (isArtifactReference(property)) {
|
|
1148
|
-
const slot = parseArtifactSlot(name, property, isRequired);
|
|
1149
|
-
artifactSlots.push(slot);
|
|
1150
|
-
continue;
|
|
1151
|
-
}
|
|
1152
|
-
if (name === "prompt" && property.type === "string") {
|
|
1153
|
-
promptField = {
|
|
1154
|
-
fieldName: name,
|
|
1155
|
-
description: property.description,
|
|
1156
|
-
required: isRequired,
|
|
1157
|
-
default: property.default !== void 0 ? String(property.default) : void 0
|
|
1158
|
-
};
|
|
1159
|
-
continue;
|
|
1160
|
-
}
|
|
1161
|
-
const settingsField = parseSettingsField(name, property);
|
|
1162
|
-
if (settingsField) {
|
|
1163
|
-
settingsFields.push(settingsField);
|
|
1164
|
-
}
|
|
1165
|
-
}
|
|
1166
|
-
return {
|
|
1167
|
-
artifactSlots,
|
|
1168
|
-
promptField,
|
|
1169
|
-
settingsFields
|
|
1170
|
-
};
|
|
1171
|
-
}
|
|
1172
|
-
|
|
1173
1267
|
// src/providers/BoardsProvider.tsx
|
|
1174
1268
|
import { Provider as UrqlProvider } from "urql";
|
|
1175
|
-
import { jsx as
|
|
1269
|
+
import { jsx as jsx4 } from "react/jsx-runtime";
|
|
1176
1270
|
function BoardsProvider({
|
|
1177
1271
|
children,
|
|
1178
1272
|
apiUrl,
|
|
@@ -1195,7 +1289,7 @@ function BoardsProvider({
|
|
|
1195
1289
|
},
|
|
1196
1290
|
tenantId
|
|
1197
1291
|
});
|
|
1198
|
-
return /* @__PURE__ */
|
|
1292
|
+
return /* @__PURE__ */ jsx4(AuthProvider, { provider: authProvider, children: /* @__PURE__ */ jsx4(ApiConfigProvider, { config: apiConfig, children: /* @__PURE__ */ jsx4(UrqlProvider, { value: client, children }) }) });
|
|
1199
1293
|
}
|
|
1200
1294
|
|
|
1201
1295
|
// src/index.ts
|
|
@@ -1220,6 +1314,7 @@ export {
|
|
|
1220
1314
|
GET_GENERATIONS,
|
|
1221
1315
|
GET_GENERATORS,
|
|
1222
1316
|
GenerationStatus,
|
|
1317
|
+
GeneratorSelectionProvider,
|
|
1223
1318
|
NoAuthProvider,
|
|
1224
1319
|
REMOVE_BOARD_MEMBER,
|
|
1225
1320
|
RETRY_GENERATION,
|
|
@@ -1239,6 +1334,7 @@ export {
|
|
|
1239
1334
|
useBoard,
|
|
1240
1335
|
useBoards,
|
|
1241
1336
|
useGeneration,
|
|
1337
|
+
useGeneratorSelection,
|
|
1242
1338
|
useGenerators
|
|
1243
1339
|
};
|
|
1244
1340
|
//# sourceMappingURL=index.mjs.map
|