@weirdfingers/boards 0.5.2 → 0.6.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.mjs CHANGED
@@ -574,6 +574,47 @@ var GENERATION_FRAGMENT = gql`
574
574
  completedAt
575
575
  }
576
576
  `;
577
+ var ARTIFACT_LINEAGE_FRAGMENT = gql`
578
+ fragment ArtifactLineageFragment on ArtifactLineage {
579
+ generationId
580
+ role
581
+ artifactType
582
+ }
583
+ `;
584
+ var ANCESTRY_NODE_FRAGMENT = gql`
585
+ ${GENERATION_FRAGMENT}
586
+ fragment AncestryNodeFragment on AncestryNode {
587
+ depth
588
+ role
589
+ generation {
590
+ ...GenerationFragment
591
+ }
592
+ parents {
593
+ depth
594
+ role
595
+ generation {
596
+ ...GenerationFragment
597
+ }
598
+ }
599
+ }
600
+ `;
601
+ var DESCENDANT_NODE_FRAGMENT = gql`
602
+ ${GENERATION_FRAGMENT}
603
+ fragment DescendantNodeFragment on DescendantNode {
604
+ depth
605
+ role
606
+ generation {
607
+ ...GenerationFragment
608
+ }
609
+ children {
610
+ depth
611
+ role
612
+ generation {
613
+ ...GenerationFragment
614
+ }
615
+ }
616
+ }
617
+ `;
577
618
  var GET_CURRENT_USER = gql`
578
619
  ${USER_FRAGMENT}
579
620
  query GetCurrentUser {
@@ -663,6 +704,36 @@ var GET_GENERATION = gql`
663
704
  }
664
705
  }
665
706
  `;
707
+ var GET_ANCESTRY = gql`
708
+ ${ANCESTRY_NODE_FRAGMENT}
709
+ query GetAncestry($id: UUID!, $maxDepth: Int = 25) {
710
+ generation(id: $id) {
711
+ ancestry(maxDepth: $maxDepth) {
712
+ ...AncestryNodeFragment
713
+ }
714
+ }
715
+ }
716
+ `;
717
+ var GET_DESCENDANTS = gql`
718
+ ${DESCENDANT_NODE_FRAGMENT}
719
+ query GetDescendants($id: UUID!, $maxDepth: Int = 25) {
720
+ generation(id: $id) {
721
+ descendants(maxDepth: $maxDepth) {
722
+ ...DescendantNodeFragment
723
+ }
724
+ }
725
+ }
726
+ `;
727
+ var GET_INPUT_ARTIFACTS = gql`
728
+ ${ARTIFACT_LINEAGE_FRAGMENT}
729
+ query GetInputArtifacts($id: UUID!) {
730
+ generation(id: $id) {
731
+ inputArtifacts {
732
+ ...ArtifactLineageFragment
733
+ }
734
+ }
735
+ }
736
+ `;
666
737
  var CREATE_BOARD = gql`
667
738
  ${BOARD_FRAGMENT}
668
739
  ${USER_FRAGMENT}
@@ -744,6 +815,14 @@ var RETRY_GENERATION = gql`
744
815
  }
745
816
  }
746
817
  `;
818
+ var UPLOAD_ARTIFACT_FROM_URL = gql`
819
+ ${GENERATION_FRAGMENT}
820
+ mutation UploadArtifactFromUrl($input: UploadArtifactInput!) {
821
+ uploadArtifact(input: $input) {
822
+ ...GenerationFragment
823
+ }
824
+ }
825
+ `;
747
826
  var BoardRole = /* @__PURE__ */ ((BoardRole2) => {
748
827
  BoardRole2["VIEWER"] = "VIEWER";
749
828
  BoardRole2["EDITOR"] = "EDITOR";
@@ -758,14 +837,14 @@ var GenerationStatus = /* @__PURE__ */ ((GenerationStatus2) => {
758
837
  GenerationStatus2["CANCELLED"] = "CANCELLED";
759
838
  return GenerationStatus2;
760
839
  })(GenerationStatus || {});
761
- var ArtifactType = /* @__PURE__ */ ((ArtifactType4) => {
762
- ArtifactType4["IMAGE"] = "image";
763
- ArtifactType4["VIDEO"] = "video";
764
- ArtifactType4["AUDIO"] = "audio";
765
- ArtifactType4["TEXT"] = "text";
766
- ArtifactType4["LORA"] = "lora";
767
- ArtifactType4["MODEL"] = "model";
768
- return ArtifactType4;
840
+ var ArtifactType = /* @__PURE__ */ ((ArtifactType5) => {
841
+ ArtifactType5["IMAGE"] = "IMAGE";
842
+ ArtifactType5["VIDEO"] = "VIDEO";
843
+ ArtifactType5["AUDIO"] = "AUDIO";
844
+ ArtifactType5["TEXT"] = "TEXT";
845
+ ArtifactType5["LORA"] = "LORA";
846
+ ArtifactType5["MODEL"] = "MODEL";
847
+ return ArtifactType5;
769
848
  })(ArtifactType || {});
770
849
 
771
850
  // src/hooks/useBoards.ts
@@ -1264,6 +1343,198 @@ function useGenerators(options = {}) {
1264
1343
  };
1265
1344
  }
1266
1345
 
1346
+ // src/hooks/useUpload.ts
1347
+ import { useCallback as useCallback6, useState as useState5 } from "react";
1348
+ import { useMutation as useMutation4 } from "urql";
1349
+ function useUpload() {
1350
+ const [isUploading, setIsUploading] = useState5(false);
1351
+ const [progress, setProgress] = useState5(0);
1352
+ const [error, setError] = useState5(null);
1353
+ const { apiUrl } = useApiConfig();
1354
+ const auth = useAuth();
1355
+ const [, uploadFromUrlMutation] = useMutation4(UPLOAD_ARTIFACT_FROM_URL);
1356
+ const upload = useCallback6(
1357
+ async (request) => {
1358
+ setError(null);
1359
+ setProgress(0);
1360
+ setIsUploading(true);
1361
+ try {
1362
+ if (typeof request.source === "string") {
1363
+ const result2 = await uploadFromUrlMutation({
1364
+ input: {
1365
+ boardId: request.boardId,
1366
+ artifactType: request.artifactType,
1367
+ fileUrl: request.source,
1368
+ userDescription: request.userDescription,
1369
+ parentGenerationId: request.parentGenerationId
1370
+ }
1371
+ });
1372
+ if (result2.error) {
1373
+ throw new Error(result2.error.message);
1374
+ }
1375
+ if (!result2.data?.uploadArtifact) {
1376
+ throw new Error("Upload failed");
1377
+ }
1378
+ setProgress(100);
1379
+ setIsUploading(false);
1380
+ return {
1381
+ id: result2.data.uploadArtifact.id,
1382
+ storageUrl: result2.data.uploadArtifact.storageUrl,
1383
+ thumbnailUrl: result2.data.uploadArtifact.thumbnailUrl,
1384
+ status: "completed",
1385
+ artifactType: result2.data.uploadArtifact.artifactType,
1386
+ generatorName: result2.data.uploadArtifact.generatorName
1387
+ };
1388
+ }
1389
+ const formData = new FormData();
1390
+ formData.append("board_id", request.boardId);
1391
+ formData.append("artifact_type", request.artifactType.toLowerCase());
1392
+ formData.append("file", request.source);
1393
+ if (request.userDescription) {
1394
+ formData.append("user_description", request.userDescription);
1395
+ }
1396
+ if (request.parentGenerationId) {
1397
+ formData.append("parent_generation_id", request.parentGenerationId);
1398
+ }
1399
+ const token = await auth.getToken();
1400
+ const headers = {};
1401
+ if (token) {
1402
+ headers.Authorization = `Bearer ${token}`;
1403
+ }
1404
+ const result = await new Promise((resolve, reject) => {
1405
+ const xhr = new XMLHttpRequest();
1406
+ xhr.upload.addEventListener("progress", (e) => {
1407
+ if (e.lengthComputable) {
1408
+ const percentComplete = e.loaded / e.total * 100;
1409
+ setProgress(percentComplete);
1410
+ }
1411
+ });
1412
+ xhr.addEventListener("load", () => {
1413
+ if (xhr.status === 200) {
1414
+ try {
1415
+ const data = JSON.parse(xhr.responseText);
1416
+ resolve({
1417
+ id: data.id,
1418
+ storageUrl: data.storageUrl,
1419
+ thumbnailUrl: data.thumbnailUrl,
1420
+ status: "completed",
1421
+ artifactType: data.artifactType,
1422
+ generatorName: data.generatorName
1423
+ });
1424
+ } catch (err) {
1425
+ reject(new Error("Failed to parse response"));
1426
+ }
1427
+ } else {
1428
+ try {
1429
+ const errorData = JSON.parse(xhr.responseText);
1430
+ reject(new Error(errorData.detail || `Upload failed: ${xhr.statusText}`));
1431
+ } catch {
1432
+ reject(new Error(`Upload failed: ${xhr.statusText}`));
1433
+ }
1434
+ }
1435
+ });
1436
+ xhr.addEventListener("error", () => {
1437
+ reject(new Error("Upload failed: Network error"));
1438
+ });
1439
+ xhr.addEventListener("abort", () => {
1440
+ reject(new Error("Upload cancelled"));
1441
+ });
1442
+ xhr.open("POST", `${apiUrl}/api/uploads/artifact`);
1443
+ Object.entries(headers).forEach(([key, value]) => {
1444
+ xhr.setRequestHeader(key, value);
1445
+ });
1446
+ xhr.send(formData);
1447
+ });
1448
+ setProgress(100);
1449
+ setIsUploading(false);
1450
+ return result;
1451
+ } catch (err) {
1452
+ const uploadError = err instanceof Error ? err : new Error("Upload failed");
1453
+ setError(uploadError);
1454
+ setIsUploading(false);
1455
+ setProgress(0);
1456
+ throw uploadError;
1457
+ }
1458
+ },
1459
+ [uploadFromUrlMutation, apiUrl, auth]
1460
+ );
1461
+ return {
1462
+ upload,
1463
+ isUploading,
1464
+ progress,
1465
+ error
1466
+ };
1467
+ }
1468
+
1469
+ // src/hooks/useLineage.ts
1470
+ import { useMemo as useMemo5 } from "react";
1471
+ import { useQuery as useQuery4 } from "urql";
1472
+ function useAncestry(generationId, options = {}) {
1473
+ const { maxDepth = 25, pause = false } = options;
1474
+ const [{ data, fetching, error }] = useQuery4({
1475
+ query: GET_ANCESTRY,
1476
+ variables: { id: generationId, maxDepth },
1477
+ pause
1478
+ });
1479
+ const ancestry = useMemo5(
1480
+ () => data?.generation?.ancestry || null,
1481
+ [data?.generation?.ancestry]
1482
+ );
1483
+ return {
1484
+ ancestry,
1485
+ loading: fetching,
1486
+ error: error ? new Error(error.message) : null
1487
+ };
1488
+ }
1489
+ function useDescendants(generationId, options = {}) {
1490
+ const { maxDepth = 25, pause = false } = options;
1491
+ const [{ data, fetching, error }] = useQuery4({
1492
+ query: GET_DESCENDANTS,
1493
+ variables: { id: generationId, maxDepth },
1494
+ pause
1495
+ });
1496
+ const descendants = useMemo5(
1497
+ () => data?.generation?.descendants || null,
1498
+ [data?.generation?.descendants]
1499
+ );
1500
+ return {
1501
+ descendants,
1502
+ loading: fetching,
1503
+ error: error ? new Error(error.message) : null
1504
+ };
1505
+ }
1506
+ function useInputArtifacts(generationId, options = {}) {
1507
+ const { pause = false } = options;
1508
+ const [{ data, fetching, error }] = useQuery4({
1509
+ query: GET_INPUT_ARTIFACTS,
1510
+ variables: { id: generationId },
1511
+ pause
1512
+ });
1513
+ const inputArtifacts = useMemo5(
1514
+ () => data?.generation?.inputArtifacts || [],
1515
+ [data?.generation?.inputArtifacts]
1516
+ );
1517
+ return {
1518
+ inputArtifacts,
1519
+ loading: fetching,
1520
+ error: error ? new Error(error.message) : null
1521
+ };
1522
+ }
1523
+ function useLineage(generationId, options = {}) {
1524
+ const ancestryResult = useAncestry(generationId, options);
1525
+ const descendantsResult = useDescendants(generationId, options);
1526
+ const inputArtifactsResult = useInputArtifacts(generationId, options);
1527
+ const loading = ancestryResult.loading || descendantsResult.loading || inputArtifactsResult.loading;
1528
+ const error = ancestryResult.error || descendantsResult.error || inputArtifactsResult.error;
1529
+ return {
1530
+ ancestry: ancestryResult.ancestry,
1531
+ descendants: descendantsResult.descendants,
1532
+ inputArtifacts: inputArtifactsResult.inputArtifacts,
1533
+ loading,
1534
+ error
1535
+ };
1536
+ }
1537
+
1267
1538
  // src/providers/BoardsProvider.tsx
1268
1539
  import { Provider as UrqlProvider } from "urql";
1269
1540
  import { jsx as jsx4 } from "react/jsx-runtime";
@@ -1296,6 +1567,8 @@ function BoardsProvider({
1296
1567
  var VERSION = "0.1.0";
1297
1568
  export {
1298
1569
  ADD_BOARD_MEMBER,
1570
+ ANCESTRY_NODE_FRAGMENT,
1571
+ ARTIFACT_LINEAGE_FRAGMENT,
1299
1572
  ArtifactType,
1300
1573
  AuthProvider,
1301
1574
  BOARD_FRAGMENT,
@@ -1306,13 +1579,17 @@ export {
1306
1579
  CREATE_BOARD,
1307
1580
  CREATE_GENERATION,
1308
1581
  DELETE_BOARD,
1582
+ DESCENDANT_NODE_FRAGMENT,
1309
1583
  GENERATION_FRAGMENT,
1584
+ GET_ANCESTRY,
1310
1585
  GET_BOARD,
1311
1586
  GET_BOARDS,
1312
1587
  GET_CURRENT_USER,
1588
+ GET_DESCENDANTS,
1313
1589
  GET_GENERATION,
1314
1590
  GET_GENERATIONS,
1315
1591
  GET_GENERATORS,
1592
+ GET_INPUT_ARTIFACTS,
1316
1593
  GenerationStatus,
1317
1594
  GeneratorSelectionProvider,
1318
1595
  NoAuthProvider,
@@ -1320,6 +1597,7 @@ export {
1320
1597
  RETRY_GENERATION,
1321
1598
  UPDATE_BOARD,
1322
1599
  UPDATE_BOARD_MEMBER_ROLE,
1600
+ UPLOAD_ARTIFACT_FROM_URL,
1323
1601
  USER_FRAGMENT,
1324
1602
  VERSION,
1325
1603
  createGraphQLClient,
@@ -1328,13 +1606,18 @@ export {
1328
1606
  parseArtifactSlot,
1329
1607
  parseGeneratorSchema,
1330
1608
  parseSettingsField,
1609
+ useAncestry,
1331
1610
  useApiConfig,
1332
1611
  useAuth,
1333
1612
  useAuthOptional,
1334
1613
  useBoard,
1335
1614
  useBoards,
1615
+ useDescendants,
1336
1616
  useGeneration,
1337
1617
  useGeneratorSelection,
1338
- useGenerators
1618
+ useGenerators,
1619
+ useInputArtifacts,
1620
+ useLineage,
1621
+ useUpload
1339
1622
  };
1340
1623
  //# sourceMappingURL=index.mjs.map