@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.js CHANGED
@@ -21,6 +21,8 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
21
21
  var index_exports = {};
22
22
  __export(index_exports, {
23
23
  ADD_BOARD_MEMBER: () => ADD_BOARD_MEMBER,
24
+ ANCESTRY_NODE_FRAGMENT: () => ANCESTRY_NODE_FRAGMENT,
25
+ ARTIFACT_LINEAGE_FRAGMENT: () => ARTIFACT_LINEAGE_FRAGMENT,
24
26
  ArtifactType: () => ArtifactType,
25
27
  AuthProvider: () => AuthProvider,
26
28
  BOARD_FRAGMENT: () => BOARD_FRAGMENT,
@@ -31,13 +33,17 @@ __export(index_exports, {
31
33
  CREATE_BOARD: () => CREATE_BOARD,
32
34
  CREATE_GENERATION: () => CREATE_GENERATION,
33
35
  DELETE_BOARD: () => DELETE_BOARD,
36
+ DESCENDANT_NODE_FRAGMENT: () => DESCENDANT_NODE_FRAGMENT,
34
37
  GENERATION_FRAGMENT: () => GENERATION_FRAGMENT,
38
+ GET_ANCESTRY: () => GET_ANCESTRY,
35
39
  GET_BOARD: () => GET_BOARD,
36
40
  GET_BOARDS: () => GET_BOARDS,
37
41
  GET_CURRENT_USER: () => GET_CURRENT_USER,
42
+ GET_DESCENDANTS: () => GET_DESCENDANTS,
38
43
  GET_GENERATION: () => GET_GENERATION,
39
44
  GET_GENERATIONS: () => GET_GENERATIONS,
40
45
  GET_GENERATORS: () => GET_GENERATORS,
46
+ GET_INPUT_ARTIFACTS: () => GET_INPUT_ARTIFACTS,
41
47
  GenerationStatus: () => GenerationStatus,
42
48
  GeneratorSelectionProvider: () => GeneratorSelectionProvider,
43
49
  NoAuthProvider: () => NoAuthProvider,
@@ -45,6 +51,7 @@ __export(index_exports, {
45
51
  RETRY_GENERATION: () => RETRY_GENERATION,
46
52
  UPDATE_BOARD: () => UPDATE_BOARD,
47
53
  UPDATE_BOARD_MEMBER_ROLE: () => UPDATE_BOARD_MEMBER_ROLE,
54
+ UPLOAD_ARTIFACT_FROM_URL: () => UPLOAD_ARTIFACT_FROM_URL,
48
55
  USER_FRAGMENT: () => USER_FRAGMENT,
49
56
  VERSION: () => VERSION,
50
57
  createGraphQLClient: () => createGraphQLClient,
@@ -53,14 +60,19 @@ __export(index_exports, {
53
60
  parseArtifactSlot: () => parseArtifactSlot,
54
61
  parseGeneratorSchema: () => parseGeneratorSchema,
55
62
  parseSettingsField: () => parseSettingsField,
63
+ useAncestry: () => useAncestry,
56
64
  useApiConfig: () => useApiConfig,
57
65
  useAuth: () => useAuth,
58
66
  useAuthOptional: () => useAuthOptional,
59
67
  useBoard: () => useBoard,
60
68
  useBoards: () => useBoards,
69
+ useDescendants: () => useDescendants,
61
70
  useGeneration: () => useGeneration,
62
71
  useGeneratorSelection: () => useGeneratorSelection,
63
- useGenerators: () => useGenerators
72
+ useGenerators: () => useGenerators,
73
+ useInputArtifacts: () => useInputArtifacts,
74
+ useLineage: () => useLineage,
75
+ useUpload: () => useUpload
64
76
  });
65
77
  module.exports = __toCommonJS(index_exports);
66
78
 
@@ -634,6 +646,47 @@ var GENERATION_FRAGMENT = import_urql2.gql`
634
646
  completedAt
635
647
  }
636
648
  `;
649
+ var ARTIFACT_LINEAGE_FRAGMENT = import_urql2.gql`
650
+ fragment ArtifactLineageFragment on ArtifactLineage {
651
+ generationId
652
+ role
653
+ artifactType
654
+ }
655
+ `;
656
+ var ANCESTRY_NODE_FRAGMENT = import_urql2.gql`
657
+ ${GENERATION_FRAGMENT}
658
+ fragment AncestryNodeFragment on AncestryNode {
659
+ depth
660
+ role
661
+ generation {
662
+ ...GenerationFragment
663
+ }
664
+ parents {
665
+ depth
666
+ role
667
+ generation {
668
+ ...GenerationFragment
669
+ }
670
+ }
671
+ }
672
+ `;
673
+ var DESCENDANT_NODE_FRAGMENT = import_urql2.gql`
674
+ ${GENERATION_FRAGMENT}
675
+ fragment DescendantNodeFragment on DescendantNode {
676
+ depth
677
+ role
678
+ generation {
679
+ ...GenerationFragment
680
+ }
681
+ children {
682
+ depth
683
+ role
684
+ generation {
685
+ ...GenerationFragment
686
+ }
687
+ }
688
+ }
689
+ `;
637
690
  var GET_CURRENT_USER = import_urql2.gql`
638
691
  ${USER_FRAGMENT}
639
692
  query GetCurrentUser {
@@ -723,6 +776,36 @@ var GET_GENERATION = import_urql2.gql`
723
776
  }
724
777
  }
725
778
  `;
779
+ var GET_ANCESTRY = import_urql2.gql`
780
+ ${ANCESTRY_NODE_FRAGMENT}
781
+ query GetAncestry($id: UUID!, $maxDepth: Int = 25) {
782
+ generation(id: $id) {
783
+ ancestry(maxDepth: $maxDepth) {
784
+ ...AncestryNodeFragment
785
+ }
786
+ }
787
+ }
788
+ `;
789
+ var GET_DESCENDANTS = import_urql2.gql`
790
+ ${DESCENDANT_NODE_FRAGMENT}
791
+ query GetDescendants($id: UUID!, $maxDepth: Int = 25) {
792
+ generation(id: $id) {
793
+ descendants(maxDepth: $maxDepth) {
794
+ ...DescendantNodeFragment
795
+ }
796
+ }
797
+ }
798
+ `;
799
+ var GET_INPUT_ARTIFACTS = import_urql2.gql`
800
+ ${ARTIFACT_LINEAGE_FRAGMENT}
801
+ query GetInputArtifacts($id: UUID!) {
802
+ generation(id: $id) {
803
+ inputArtifacts {
804
+ ...ArtifactLineageFragment
805
+ }
806
+ }
807
+ }
808
+ `;
726
809
  var CREATE_BOARD = import_urql2.gql`
727
810
  ${BOARD_FRAGMENT}
728
811
  ${USER_FRAGMENT}
@@ -804,6 +887,14 @@ var RETRY_GENERATION = import_urql2.gql`
804
887
  }
805
888
  }
806
889
  `;
890
+ var UPLOAD_ARTIFACT_FROM_URL = import_urql2.gql`
891
+ ${GENERATION_FRAGMENT}
892
+ mutation UploadArtifactFromUrl($input: UploadArtifactInput!) {
893
+ uploadArtifact(input: $input) {
894
+ ...GenerationFragment
895
+ }
896
+ }
897
+ `;
807
898
  var BoardRole = /* @__PURE__ */ ((BoardRole2) => {
808
899
  BoardRole2["VIEWER"] = "VIEWER";
809
900
  BoardRole2["EDITOR"] = "EDITOR";
@@ -818,14 +909,14 @@ var GenerationStatus = /* @__PURE__ */ ((GenerationStatus2) => {
818
909
  GenerationStatus2["CANCELLED"] = "CANCELLED";
819
910
  return GenerationStatus2;
820
911
  })(GenerationStatus || {});
821
- var ArtifactType = /* @__PURE__ */ ((ArtifactType4) => {
822
- ArtifactType4["IMAGE"] = "image";
823
- ArtifactType4["VIDEO"] = "video";
824
- ArtifactType4["AUDIO"] = "audio";
825
- ArtifactType4["TEXT"] = "text";
826
- ArtifactType4["LORA"] = "lora";
827
- ArtifactType4["MODEL"] = "model";
828
- return ArtifactType4;
912
+ var ArtifactType = /* @__PURE__ */ ((ArtifactType5) => {
913
+ ArtifactType5["IMAGE"] = "IMAGE";
914
+ ArtifactType5["VIDEO"] = "VIDEO";
915
+ ArtifactType5["AUDIO"] = "AUDIO";
916
+ ArtifactType5["TEXT"] = "TEXT";
917
+ ArtifactType5["LORA"] = "LORA";
918
+ ArtifactType5["MODEL"] = "MODEL";
919
+ return ArtifactType5;
829
920
  })(ArtifactType || {});
830
921
 
831
922
  // src/hooks/useBoards.ts
@@ -1324,8 +1415,200 @@ function useGenerators(options = {}) {
1324
1415
  };
1325
1416
  }
1326
1417
 
1327
- // src/providers/BoardsProvider.tsx
1418
+ // src/hooks/useUpload.ts
1419
+ var import_react8 = require("react");
1328
1420
  var import_urql7 = require("urql");
1421
+ function useUpload() {
1422
+ const [isUploading, setIsUploading] = (0, import_react8.useState)(false);
1423
+ const [progress, setProgress] = (0, import_react8.useState)(0);
1424
+ const [error, setError] = (0, import_react8.useState)(null);
1425
+ const { apiUrl } = useApiConfig();
1426
+ const auth = useAuth();
1427
+ const [, uploadFromUrlMutation] = (0, import_urql7.useMutation)(UPLOAD_ARTIFACT_FROM_URL);
1428
+ const upload = (0, import_react8.useCallback)(
1429
+ async (request) => {
1430
+ setError(null);
1431
+ setProgress(0);
1432
+ setIsUploading(true);
1433
+ try {
1434
+ if (typeof request.source === "string") {
1435
+ const result2 = await uploadFromUrlMutation({
1436
+ input: {
1437
+ boardId: request.boardId,
1438
+ artifactType: request.artifactType,
1439
+ fileUrl: request.source,
1440
+ userDescription: request.userDescription,
1441
+ parentGenerationId: request.parentGenerationId
1442
+ }
1443
+ });
1444
+ if (result2.error) {
1445
+ throw new Error(result2.error.message);
1446
+ }
1447
+ if (!result2.data?.uploadArtifact) {
1448
+ throw new Error("Upload failed");
1449
+ }
1450
+ setProgress(100);
1451
+ setIsUploading(false);
1452
+ return {
1453
+ id: result2.data.uploadArtifact.id,
1454
+ storageUrl: result2.data.uploadArtifact.storageUrl,
1455
+ thumbnailUrl: result2.data.uploadArtifact.thumbnailUrl,
1456
+ status: "completed",
1457
+ artifactType: result2.data.uploadArtifact.artifactType,
1458
+ generatorName: result2.data.uploadArtifact.generatorName
1459
+ };
1460
+ }
1461
+ const formData = new FormData();
1462
+ formData.append("board_id", request.boardId);
1463
+ formData.append("artifact_type", request.artifactType.toLowerCase());
1464
+ formData.append("file", request.source);
1465
+ if (request.userDescription) {
1466
+ formData.append("user_description", request.userDescription);
1467
+ }
1468
+ if (request.parentGenerationId) {
1469
+ formData.append("parent_generation_id", request.parentGenerationId);
1470
+ }
1471
+ const token = await auth.getToken();
1472
+ const headers = {};
1473
+ if (token) {
1474
+ headers.Authorization = `Bearer ${token}`;
1475
+ }
1476
+ const result = await new Promise((resolve, reject) => {
1477
+ const xhr = new XMLHttpRequest();
1478
+ xhr.upload.addEventListener("progress", (e) => {
1479
+ if (e.lengthComputable) {
1480
+ const percentComplete = e.loaded / e.total * 100;
1481
+ setProgress(percentComplete);
1482
+ }
1483
+ });
1484
+ xhr.addEventListener("load", () => {
1485
+ if (xhr.status === 200) {
1486
+ try {
1487
+ const data = JSON.parse(xhr.responseText);
1488
+ resolve({
1489
+ id: data.id,
1490
+ storageUrl: data.storageUrl,
1491
+ thumbnailUrl: data.thumbnailUrl,
1492
+ status: "completed",
1493
+ artifactType: data.artifactType,
1494
+ generatorName: data.generatorName
1495
+ });
1496
+ } catch (err) {
1497
+ reject(new Error("Failed to parse response"));
1498
+ }
1499
+ } else {
1500
+ try {
1501
+ const errorData = JSON.parse(xhr.responseText);
1502
+ reject(new Error(errorData.detail || `Upload failed: ${xhr.statusText}`));
1503
+ } catch {
1504
+ reject(new Error(`Upload failed: ${xhr.statusText}`));
1505
+ }
1506
+ }
1507
+ });
1508
+ xhr.addEventListener("error", () => {
1509
+ reject(new Error("Upload failed: Network error"));
1510
+ });
1511
+ xhr.addEventListener("abort", () => {
1512
+ reject(new Error("Upload cancelled"));
1513
+ });
1514
+ xhr.open("POST", `${apiUrl}/api/uploads/artifact`);
1515
+ Object.entries(headers).forEach(([key, value]) => {
1516
+ xhr.setRequestHeader(key, value);
1517
+ });
1518
+ xhr.send(formData);
1519
+ });
1520
+ setProgress(100);
1521
+ setIsUploading(false);
1522
+ return result;
1523
+ } catch (err) {
1524
+ const uploadError = err instanceof Error ? err : new Error("Upload failed");
1525
+ setError(uploadError);
1526
+ setIsUploading(false);
1527
+ setProgress(0);
1528
+ throw uploadError;
1529
+ }
1530
+ },
1531
+ [uploadFromUrlMutation, apiUrl, auth]
1532
+ );
1533
+ return {
1534
+ upload,
1535
+ isUploading,
1536
+ progress,
1537
+ error
1538
+ };
1539
+ }
1540
+
1541
+ // src/hooks/useLineage.ts
1542
+ var import_react9 = require("react");
1543
+ var import_urql8 = require("urql");
1544
+ function useAncestry(generationId, options = {}) {
1545
+ const { maxDepth = 25, pause = false } = options;
1546
+ const [{ data, fetching, error }] = (0, import_urql8.useQuery)({
1547
+ query: GET_ANCESTRY,
1548
+ variables: { id: generationId, maxDepth },
1549
+ pause
1550
+ });
1551
+ const ancestry = (0, import_react9.useMemo)(
1552
+ () => data?.generation?.ancestry || null,
1553
+ [data?.generation?.ancestry]
1554
+ );
1555
+ return {
1556
+ ancestry,
1557
+ loading: fetching,
1558
+ error: error ? new Error(error.message) : null
1559
+ };
1560
+ }
1561
+ function useDescendants(generationId, options = {}) {
1562
+ const { maxDepth = 25, pause = false } = options;
1563
+ const [{ data, fetching, error }] = (0, import_urql8.useQuery)({
1564
+ query: GET_DESCENDANTS,
1565
+ variables: { id: generationId, maxDepth },
1566
+ pause
1567
+ });
1568
+ const descendants = (0, import_react9.useMemo)(
1569
+ () => data?.generation?.descendants || null,
1570
+ [data?.generation?.descendants]
1571
+ );
1572
+ return {
1573
+ descendants,
1574
+ loading: fetching,
1575
+ error: error ? new Error(error.message) : null
1576
+ };
1577
+ }
1578
+ function useInputArtifacts(generationId, options = {}) {
1579
+ const { pause = false } = options;
1580
+ const [{ data, fetching, error }] = (0, import_urql8.useQuery)({
1581
+ query: GET_INPUT_ARTIFACTS,
1582
+ variables: { id: generationId },
1583
+ pause
1584
+ });
1585
+ const inputArtifacts = (0, import_react9.useMemo)(
1586
+ () => data?.generation?.inputArtifacts || [],
1587
+ [data?.generation?.inputArtifacts]
1588
+ );
1589
+ return {
1590
+ inputArtifacts,
1591
+ loading: fetching,
1592
+ error: error ? new Error(error.message) : null
1593
+ };
1594
+ }
1595
+ function useLineage(generationId, options = {}) {
1596
+ const ancestryResult = useAncestry(generationId, options);
1597
+ const descendantsResult = useDescendants(generationId, options);
1598
+ const inputArtifactsResult = useInputArtifacts(generationId, options);
1599
+ const loading = ancestryResult.loading || descendantsResult.loading || inputArtifactsResult.loading;
1600
+ const error = ancestryResult.error || descendantsResult.error || inputArtifactsResult.error;
1601
+ return {
1602
+ ancestry: ancestryResult.ancestry,
1603
+ descendants: descendantsResult.descendants,
1604
+ inputArtifacts: inputArtifactsResult.inputArtifacts,
1605
+ loading,
1606
+ error
1607
+ };
1608
+ }
1609
+
1610
+ // src/providers/BoardsProvider.tsx
1611
+ var import_urql9 = require("urql");
1329
1612
  var import_jsx_runtime4 = require("react/jsx-runtime");
1330
1613
  function BoardsProvider({
1331
1614
  children,
@@ -1349,7 +1632,7 @@ function BoardsProvider({
1349
1632
  },
1350
1633
  tenantId
1351
1634
  });
1352
- return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(AuthProvider, { provider: authProvider, children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(ApiConfigProvider, { config: apiConfig, children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_urql7.Provider, { value: client, children }) }) });
1635
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(AuthProvider, { provider: authProvider, children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(ApiConfigProvider, { config: apiConfig, children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_urql9.Provider, { value: client, children }) }) });
1353
1636
  }
1354
1637
 
1355
1638
  // src/index.ts
@@ -1357,6 +1640,8 @@ var VERSION = "0.1.0";
1357
1640
  // Annotate the CommonJS export names for ESM import in node:
1358
1641
  0 && (module.exports = {
1359
1642
  ADD_BOARD_MEMBER,
1643
+ ANCESTRY_NODE_FRAGMENT,
1644
+ ARTIFACT_LINEAGE_FRAGMENT,
1360
1645
  ArtifactType,
1361
1646
  AuthProvider,
1362
1647
  BOARD_FRAGMENT,
@@ -1367,13 +1652,17 @@ var VERSION = "0.1.0";
1367
1652
  CREATE_BOARD,
1368
1653
  CREATE_GENERATION,
1369
1654
  DELETE_BOARD,
1655
+ DESCENDANT_NODE_FRAGMENT,
1370
1656
  GENERATION_FRAGMENT,
1657
+ GET_ANCESTRY,
1371
1658
  GET_BOARD,
1372
1659
  GET_BOARDS,
1373
1660
  GET_CURRENT_USER,
1661
+ GET_DESCENDANTS,
1374
1662
  GET_GENERATION,
1375
1663
  GET_GENERATIONS,
1376
1664
  GET_GENERATORS,
1665
+ GET_INPUT_ARTIFACTS,
1377
1666
  GenerationStatus,
1378
1667
  GeneratorSelectionProvider,
1379
1668
  NoAuthProvider,
@@ -1381,6 +1670,7 @@ var VERSION = "0.1.0";
1381
1670
  RETRY_GENERATION,
1382
1671
  UPDATE_BOARD,
1383
1672
  UPDATE_BOARD_MEMBER_ROLE,
1673
+ UPLOAD_ARTIFACT_FROM_URL,
1384
1674
  USER_FRAGMENT,
1385
1675
  VERSION,
1386
1676
  createGraphQLClient,
@@ -1389,13 +1679,18 @@ var VERSION = "0.1.0";
1389
1679
  parseArtifactSlot,
1390
1680
  parseGeneratorSchema,
1391
1681
  parseSettingsField,
1682
+ useAncestry,
1392
1683
  useApiConfig,
1393
1684
  useAuth,
1394
1685
  useAuthOptional,
1395
1686
  useBoard,
1396
1687
  useBoards,
1688
+ useDescendants,
1397
1689
  useGeneration,
1398
1690
  useGeneratorSelection,
1399
- useGenerators
1691
+ useGenerators,
1692
+ useInputArtifacts,
1693
+ useLineage,
1694
+ useUpload
1400
1695
  });
1401
1696
  //# sourceMappingURL=index.js.map