@tscircuit/fake-snippets 0.0.83 → 0.0.85

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.
Files changed (37) hide show
  1. package/README.md +5 -2
  2. package/bun-tests/fake-snippets-api/routes/ai_reviews/create.test.ts +12 -0
  3. package/bun-tests/fake-snippets-api/routes/ai_reviews/get.test.ts +16 -0
  4. package/bun-tests/fake-snippets-api/routes/ai_reviews/list.test.ts +14 -0
  5. package/bun-tests/fake-snippets-api/routes/ai_reviews/process_review.test.ts +16 -0
  6. package/bun-tests/fake-snippets-api/routes/datasheets/create.test.ts +15 -0
  7. package/bun-tests/fake-snippets-api/routes/datasheets/get.test.ts +17 -0
  8. package/bun-tests/fake-snippets-api/routes/datasheets/process_all_datasheets.test.ts +21 -0
  9. package/bun-tests/fake-snippets-api/routes/datasheets/run_async_tasks.test.ts +18 -0
  10. package/bun.lock +26 -37
  11. package/dist/bundle.js +694 -422
  12. package/dist/index.d.ts +141 -10
  13. package/dist/index.js +90 -1
  14. package/dist/schema.d.ts +211 -13
  15. package/dist/schema.js +28 -1
  16. package/fake-snippets-api/lib/db/db-client.ts +76 -0
  17. package/fake-snippets-api/lib/db/schema.ts +29 -0
  18. package/fake-snippets-api/routes/api/_fake/ai_reviews/process_review.ts +31 -0
  19. package/fake-snippets-api/routes/api/_fake/datasheets/process_all_datasheets.ts +37 -0
  20. package/fake-snippets-api/routes/api/_fake/run_async_tasks.ts +12 -0
  21. package/fake-snippets-api/routes/api/ai_reviews/create.ts +22 -0
  22. package/fake-snippets-api/routes/api/ai_reviews/get.ts +24 -0
  23. package/fake-snippets-api/routes/api/ai_reviews/list.ts +14 -0
  24. package/fake-snippets-api/routes/api/datasheets/create.ts +18 -0
  25. package/fake-snippets-api/routes/api/datasheets/get.ts +25 -0
  26. package/package.json +4 -3
  27. package/src/ContextProviders.tsx +1 -1
  28. package/src/components/Header2.tsx +8 -18
  29. package/src/components/SearchComponent.tsx +46 -8
  30. package/src/components/ViewSnippetHeader.tsx +9 -6
  31. package/src/components/dialogs/edit-package-details-dialog.tsx +5 -10
  32. package/src/hooks/use-fork-package-mutation.ts +4 -3
  33. package/src/hooks/use-sign-in.ts +10 -8
  34. package/src/hooks/useFileManagement.ts +74 -12
  35. package/src/hooks/useForkPackageMutation.ts +2 -1
  36. package/src/hooks/useForkSnippetMutation.ts +2 -1
  37. package/src/pages/authorize.tsx +164 -8
package/dist/schema.d.ts CHANGED
@@ -489,6 +489,93 @@ declare const orderQuoteSchema: z.ZodObject<{
489
489
  total_cost_without_shipping?: number | undefined;
490
490
  }>;
491
491
  type OrderQuote = z.infer<typeof orderQuoteSchema>;
492
+ declare const aiReviewSchema: z.ZodObject<{
493
+ ai_review_id: z.ZodString;
494
+ ai_review_text: z.ZodNullable<z.ZodString>;
495
+ start_processing_at: z.ZodNullable<z.ZodString>;
496
+ finished_processing_at: z.ZodNullable<z.ZodString>;
497
+ processing_error: z.ZodNullable<z.ZodAny>;
498
+ created_at: z.ZodString;
499
+ display_status: z.ZodEnum<["pending", "completed", "failed"]>;
500
+ }, "strip", z.ZodTypeAny, {
501
+ created_at: string;
502
+ ai_review_id: string;
503
+ ai_review_text: string | null;
504
+ start_processing_at: string | null;
505
+ finished_processing_at: string | null;
506
+ display_status: "pending" | "completed" | "failed";
507
+ processing_error?: any;
508
+ }, {
509
+ created_at: string;
510
+ ai_review_id: string;
511
+ ai_review_text: string | null;
512
+ start_processing_at: string | null;
513
+ finished_processing_at: string | null;
514
+ display_status: "pending" | "completed" | "failed";
515
+ processing_error?: any;
516
+ }>;
517
+ type AiReview = z.infer<typeof aiReviewSchema>;
518
+ declare const datasheetPinInformationSchema: z.ZodObject<{
519
+ pin_number: z.ZodString;
520
+ name: z.ZodString;
521
+ description: z.ZodString;
522
+ capabilities: z.ZodArray<z.ZodString, "many">;
523
+ }, "strip", z.ZodTypeAny, {
524
+ name: string;
525
+ description: string;
526
+ pin_number: string;
527
+ capabilities: string[];
528
+ }, {
529
+ name: string;
530
+ description: string;
531
+ pin_number: string;
532
+ capabilities: string[];
533
+ }>;
534
+ declare const datasheetSchema: z.ZodObject<{
535
+ datasheet_id: z.ZodString;
536
+ chip_name: z.ZodString;
537
+ created_at: z.ZodString;
538
+ pin_information: z.ZodNullable<z.ZodArray<z.ZodObject<{
539
+ pin_number: z.ZodString;
540
+ name: z.ZodString;
541
+ description: z.ZodString;
542
+ capabilities: z.ZodArray<z.ZodString, "many">;
543
+ }, "strip", z.ZodTypeAny, {
544
+ name: string;
545
+ description: string;
546
+ pin_number: string;
547
+ capabilities: string[];
548
+ }, {
549
+ name: string;
550
+ description: string;
551
+ pin_number: string;
552
+ capabilities: string[];
553
+ }>, "many">>;
554
+ datasheet_pdf_urls: z.ZodNullable<z.ZodArray<z.ZodString, "many">>;
555
+ }, "strip", z.ZodTypeAny, {
556
+ created_at: string;
557
+ datasheet_id: string;
558
+ chip_name: string;
559
+ pin_information: {
560
+ name: string;
561
+ description: string;
562
+ pin_number: string;
563
+ capabilities: string[];
564
+ }[] | null;
565
+ datasheet_pdf_urls: string[] | null;
566
+ }, {
567
+ created_at: string;
568
+ datasheet_id: string;
569
+ chip_name: string;
570
+ pin_information: {
571
+ name: string;
572
+ description: string;
573
+ pin_number: string;
574
+ capabilities: string[];
575
+ }[] | null;
576
+ datasheet_pdf_urls: string[] | null;
577
+ }>;
578
+ type Datasheet = z.infer<typeof datasheetSchema>;
492
579
  declare const accountSnippetSchema: z.ZodObject<{
493
580
  account_id: z.ZodString;
494
581
  snippet_id: z.ZodString;
@@ -570,11 +657,11 @@ declare const packageReleaseSchema: z.ZodObject<{
570
657
  package_release_id: string;
571
658
  created_at: string;
572
659
  version: string | null;
660
+ display_status: "error" | "pending" | "building" | "complete";
573
661
  package_id: string;
574
662
  is_locked: boolean;
575
663
  is_latest: boolean;
576
664
  has_transpiled: boolean;
577
- display_status: "error" | "pending" | "building" | "complete";
578
665
  transpilation_display_status: "error" | "pending" | "building" | "complete";
579
666
  transpilation_in_progress: boolean;
580
667
  transpilation_logs: any[];
@@ -584,6 +671,7 @@ declare const packageReleaseSchema: z.ZodObject<{
584
671
  circuit_json_build_logs: any[];
585
672
  circuit_json_build_is_stale: boolean;
586
673
  ai_review_requested: boolean;
674
+ ai_review_text?: string | null | undefined;
587
675
  commit_sha?: string | null | undefined;
588
676
  license?: string | null | undefined;
589
677
  circuit_json_build_error?: string | null | undefined;
@@ -595,7 +683,6 @@ declare const packageReleaseSchema: z.ZodObject<{
595
683
  transpilation_completed_at?: string | null | undefined;
596
684
  circuit_json_build_started_at?: string | null | undefined;
597
685
  circuit_json_build_completed_at?: string | null | undefined;
598
- ai_review_text?: string | null | undefined;
599
686
  ai_review_started_at?: string | null | undefined;
600
687
  ai_review_completed_at?: string | null | undefined;
601
688
  ai_review_error?: any;
@@ -607,6 +694,8 @@ declare const packageReleaseSchema: z.ZodObject<{
607
694
  package_id: string;
608
695
  is_locked: boolean;
609
696
  is_latest: boolean;
697
+ ai_review_text?: string | null | undefined;
698
+ display_status?: "error" | "pending" | "building" | "complete" | undefined;
610
699
  commit_sha?: string | null | undefined;
611
700
  license?: string | null | undefined;
612
701
  circuit_json_build_error?: string | null | undefined;
@@ -614,7 +703,6 @@ declare const packageReleaseSchema: z.ZodObject<{
614
703
  has_transpiled?: boolean | undefined;
615
704
  transpilation_error?: string | null | undefined;
616
705
  fs_sha?: string | null | undefined;
617
- display_status?: "error" | "pending" | "building" | "complete" | undefined;
618
706
  total_build_duration_ms?: number | null | undefined;
619
707
  transpilation_display_status?: "error" | "pending" | "building" | "complete" | undefined;
620
708
  transpilation_in_progress?: boolean | undefined;
@@ -628,7 +716,6 @@ declare const packageReleaseSchema: z.ZodObject<{
628
716
  circuit_json_build_completed_at?: string | null | undefined;
629
717
  circuit_json_build_logs?: any[] | undefined;
630
718
  circuit_json_build_is_stale?: boolean | undefined;
631
- ai_review_text?: string | null | undefined;
632
719
  ai_review_started_at?: string | null | undefined;
633
720
  ai_review_completed_at?: string | null | undefined;
634
721
  ai_review_error?: any;
@@ -967,11 +1054,11 @@ declare const databaseSchema: z.ZodObject<{
967
1054
  package_release_id: string;
968
1055
  created_at: string;
969
1056
  version: string | null;
1057
+ display_status: "error" | "pending" | "building" | "complete";
970
1058
  package_id: string;
971
1059
  is_locked: boolean;
972
1060
  is_latest: boolean;
973
1061
  has_transpiled: boolean;
974
- display_status: "error" | "pending" | "building" | "complete";
975
1062
  transpilation_display_status: "error" | "pending" | "building" | "complete";
976
1063
  transpilation_in_progress: boolean;
977
1064
  transpilation_logs: any[];
@@ -981,6 +1068,7 @@ declare const databaseSchema: z.ZodObject<{
981
1068
  circuit_json_build_logs: any[];
982
1069
  circuit_json_build_is_stale: boolean;
983
1070
  ai_review_requested: boolean;
1071
+ ai_review_text?: string | null | undefined;
984
1072
  commit_sha?: string | null | undefined;
985
1073
  license?: string | null | undefined;
986
1074
  circuit_json_build_error?: string | null | undefined;
@@ -992,7 +1080,6 @@ declare const databaseSchema: z.ZodObject<{
992
1080
  transpilation_completed_at?: string | null | undefined;
993
1081
  circuit_json_build_started_at?: string | null | undefined;
994
1082
  circuit_json_build_completed_at?: string | null | undefined;
995
- ai_review_text?: string | null | undefined;
996
1083
  ai_review_started_at?: string | null | undefined;
997
1084
  ai_review_completed_at?: string | null | undefined;
998
1085
  ai_review_error?: any;
@@ -1004,6 +1091,8 @@ declare const databaseSchema: z.ZodObject<{
1004
1091
  package_id: string;
1005
1092
  is_locked: boolean;
1006
1093
  is_latest: boolean;
1094
+ ai_review_text?: string | null | undefined;
1095
+ display_status?: "error" | "pending" | "building" | "complete" | undefined;
1007
1096
  commit_sha?: string | null | undefined;
1008
1097
  license?: string | null | undefined;
1009
1098
  circuit_json_build_error?: string | null | undefined;
@@ -1011,7 +1100,6 @@ declare const databaseSchema: z.ZodObject<{
1011
1100
  has_transpiled?: boolean | undefined;
1012
1101
  transpilation_error?: string | null | undefined;
1013
1102
  fs_sha?: string | null | undefined;
1014
- display_status?: "error" | "pending" | "building" | "complete" | undefined;
1015
1103
  total_build_duration_ms?: number | null | undefined;
1016
1104
  transpilation_display_status?: "error" | "pending" | "building" | "complete" | undefined;
1017
1105
  transpilation_in_progress?: boolean | undefined;
@@ -1025,7 +1113,6 @@ declare const databaseSchema: z.ZodObject<{
1025
1113
  circuit_json_build_completed_at?: string | null | undefined;
1026
1114
  circuit_json_build_logs?: any[] | undefined;
1027
1115
  circuit_json_build_is_stale?: boolean | undefined;
1028
- ai_review_text?: string | null | undefined;
1029
1116
  ai_review_started_at?: string | null | undefined;
1030
1117
  ai_review_completed_at?: string | null | undefined;
1031
1118
  ai_review_error?: any;
@@ -1595,6 +1682,75 @@ declare const databaseSchema: z.ZodObject<{
1595
1682
  bare_pcb_cost?: number | undefined;
1596
1683
  total_cost_without_shipping?: number | undefined;
1597
1684
  }>, "many">>;
1685
+ aiReviews: z.ZodDefault<z.ZodArray<z.ZodObject<{
1686
+ ai_review_id: z.ZodString;
1687
+ ai_review_text: z.ZodNullable<z.ZodString>;
1688
+ start_processing_at: z.ZodNullable<z.ZodString>;
1689
+ finished_processing_at: z.ZodNullable<z.ZodString>;
1690
+ processing_error: z.ZodNullable<z.ZodAny>;
1691
+ created_at: z.ZodString;
1692
+ display_status: z.ZodEnum<["pending", "completed", "failed"]>;
1693
+ }, "strip", z.ZodTypeAny, {
1694
+ created_at: string;
1695
+ ai_review_id: string;
1696
+ ai_review_text: string | null;
1697
+ start_processing_at: string | null;
1698
+ finished_processing_at: string | null;
1699
+ display_status: "pending" | "completed" | "failed";
1700
+ processing_error?: any;
1701
+ }, {
1702
+ created_at: string;
1703
+ ai_review_id: string;
1704
+ ai_review_text: string | null;
1705
+ start_processing_at: string | null;
1706
+ finished_processing_at: string | null;
1707
+ display_status: "pending" | "completed" | "failed";
1708
+ processing_error?: any;
1709
+ }>, "many">>;
1710
+ datasheets: z.ZodDefault<z.ZodArray<z.ZodObject<{
1711
+ datasheet_id: z.ZodString;
1712
+ chip_name: z.ZodString;
1713
+ created_at: z.ZodString;
1714
+ pin_information: z.ZodNullable<z.ZodArray<z.ZodObject<{
1715
+ pin_number: z.ZodString;
1716
+ name: z.ZodString;
1717
+ description: z.ZodString;
1718
+ capabilities: z.ZodArray<z.ZodString, "many">;
1719
+ }, "strip", z.ZodTypeAny, {
1720
+ name: string;
1721
+ description: string;
1722
+ pin_number: string;
1723
+ capabilities: string[];
1724
+ }, {
1725
+ name: string;
1726
+ description: string;
1727
+ pin_number: string;
1728
+ capabilities: string[];
1729
+ }>, "many">>;
1730
+ datasheet_pdf_urls: z.ZodNullable<z.ZodArray<z.ZodString, "many">>;
1731
+ }, "strip", z.ZodTypeAny, {
1732
+ created_at: string;
1733
+ datasheet_id: string;
1734
+ chip_name: string;
1735
+ pin_information: {
1736
+ name: string;
1737
+ description: string;
1738
+ pin_number: string;
1739
+ capabilities: string[];
1740
+ }[] | null;
1741
+ datasheet_pdf_urls: string[] | null;
1742
+ }, {
1743
+ created_at: string;
1744
+ datasheet_id: string;
1745
+ chip_name: string;
1746
+ pin_information: {
1747
+ name: string;
1748
+ description: string;
1749
+ pin_number: string;
1750
+ capabilities: string[];
1751
+ }[] | null;
1752
+ datasheet_pdf_urls: string[] | null;
1753
+ }>, "many">>;
1598
1754
  }, "strip", z.ZodTypeAny, {
1599
1755
  idCounter: number;
1600
1756
  snippets: {
@@ -1625,11 +1781,11 @@ declare const databaseSchema: z.ZodObject<{
1625
1781
  package_release_id: string;
1626
1782
  created_at: string;
1627
1783
  version: string | null;
1784
+ display_status: "error" | "pending" | "building" | "complete";
1628
1785
  package_id: string;
1629
1786
  is_locked: boolean;
1630
1787
  is_latest: boolean;
1631
1788
  has_transpiled: boolean;
1632
- display_status: "error" | "pending" | "building" | "complete";
1633
1789
  transpilation_display_status: "error" | "pending" | "building" | "complete";
1634
1790
  transpilation_in_progress: boolean;
1635
1791
  transpilation_logs: any[];
@@ -1639,6 +1795,7 @@ declare const databaseSchema: z.ZodObject<{
1639
1795
  circuit_json_build_logs: any[];
1640
1796
  circuit_json_build_is_stale: boolean;
1641
1797
  ai_review_requested: boolean;
1798
+ ai_review_text?: string | null | undefined;
1642
1799
  commit_sha?: string | null | undefined;
1643
1800
  license?: string | null | undefined;
1644
1801
  circuit_json_build_error?: string | null | undefined;
@@ -1650,7 +1807,6 @@ declare const databaseSchema: z.ZodObject<{
1650
1807
  transpilation_completed_at?: string | null | undefined;
1651
1808
  circuit_json_build_started_at?: string | null | undefined;
1652
1809
  circuit_json_build_completed_at?: string | null | undefined;
1653
- ai_review_text?: string | null | undefined;
1654
1810
  ai_review_started_at?: string | null | undefined;
1655
1811
  ai_review_completed_at?: string | null | undefined;
1656
1812
  ai_review_error?: any;
@@ -1833,6 +1989,27 @@ declare const databaseSchema: z.ZodObject<{
1833
1989
  }[];
1834
1990
  total_cost_without_shipping: number;
1835
1991
  }[];
1992
+ aiReviews: {
1993
+ created_at: string;
1994
+ ai_review_id: string;
1995
+ ai_review_text: string | null;
1996
+ start_processing_at: string | null;
1997
+ finished_processing_at: string | null;
1998
+ display_status: "pending" | "completed" | "failed";
1999
+ processing_error?: any;
2000
+ }[];
2001
+ datasheets: {
2002
+ created_at: string;
2003
+ datasheet_id: string;
2004
+ chip_name: string;
2005
+ pin_information: {
2006
+ name: string;
2007
+ description: string;
2008
+ pin_number: string;
2009
+ capabilities: string[];
2010
+ }[] | null;
2011
+ datasheet_pdf_urls: string[] | null;
2012
+ }[];
1836
2013
  }, {
1837
2014
  idCounter?: number | undefined;
1838
2015
  snippets?: {
@@ -1866,6 +2043,8 @@ declare const databaseSchema: z.ZodObject<{
1866
2043
  package_id: string;
1867
2044
  is_locked: boolean;
1868
2045
  is_latest: boolean;
2046
+ ai_review_text?: string | null | undefined;
2047
+ display_status?: "error" | "pending" | "building" | "complete" | undefined;
1869
2048
  commit_sha?: string | null | undefined;
1870
2049
  license?: string | null | undefined;
1871
2050
  circuit_json_build_error?: string | null | undefined;
@@ -1873,7 +2052,6 @@ declare const databaseSchema: z.ZodObject<{
1873
2052
  has_transpiled?: boolean | undefined;
1874
2053
  transpilation_error?: string | null | undefined;
1875
2054
  fs_sha?: string | null | undefined;
1876
- display_status?: "error" | "pending" | "building" | "complete" | undefined;
1877
2055
  total_build_duration_ms?: number | null | undefined;
1878
2056
  transpilation_display_status?: "error" | "pending" | "building" | "complete" | undefined;
1879
2057
  transpilation_in_progress?: boolean | undefined;
@@ -1887,7 +2065,6 @@ declare const databaseSchema: z.ZodObject<{
1887
2065
  circuit_json_build_completed_at?: string | null | undefined;
1888
2066
  circuit_json_build_logs?: any[] | undefined;
1889
2067
  circuit_json_build_is_stale?: boolean | undefined;
1890
- ai_review_text?: string | null | undefined;
1891
2068
  ai_review_started_at?: string | null | undefined;
1892
2069
  ai_review_completed_at?: string | null | undefined;
1893
2070
  ai_review_error?: any;
@@ -2071,7 +2248,28 @@ declare const databaseSchema: z.ZodObject<{
2071
2248
  bare_pcb_cost?: number | undefined;
2072
2249
  total_cost_without_shipping?: number | undefined;
2073
2250
  }[] | undefined;
2251
+ aiReviews?: {
2252
+ created_at: string;
2253
+ ai_review_id: string;
2254
+ ai_review_text: string | null;
2255
+ start_processing_at: string | null;
2256
+ finished_processing_at: string | null;
2257
+ display_status: "pending" | "completed" | "failed";
2258
+ processing_error?: any;
2259
+ }[] | undefined;
2260
+ datasheets?: {
2261
+ created_at: string;
2262
+ datasheet_id: string;
2263
+ chip_name: string;
2264
+ pin_information: {
2265
+ name: string;
2266
+ description: string;
2267
+ pin_number: string;
2268
+ capabilities: string[];
2269
+ }[] | null;
2270
+ datasheet_pdf_urls: string[] | null;
2271
+ }[] | undefined;
2074
2272
  }>;
2075
2273
  type DatabaseSchema = z.infer<typeof databaseSchema>;
2076
2274
 
2077
- export { type Account, type AccountPackage, type AccountSnippet, type DatabaseSchema, type JlcpcbOrderState, type JlcpcbOrderStepRun, type LoginPage, type Order, type OrderFile, type OrderQuote, type Package, type PackageFile, type PackageRelease, type QuotedComponent, type Session, type ShippingOption, type Snippet, accountPackageSchema, accountSchema, accountSnippetSchema, databaseSchema, errorResponseSchema, errorSchema, jlcpcbOrderStateSchema, jlcpcbOrderStepRunSchema, loginPageSchema, orderFileSchema, orderQuoteSchema, orderSchema, packageFileSchema, packageReleaseSchema, packageSchema, quotedComponentSchema, sessionSchema, shippingInfoSchema, snippetSchema };
2275
+ export { type Account, type AccountPackage, type AccountSnippet, type AiReview, type DatabaseSchema, type Datasheet, type JlcpcbOrderState, type JlcpcbOrderStepRun, type LoginPage, type Order, type OrderFile, type OrderQuote, type Package, type PackageFile, type PackageRelease, type QuotedComponent, type Session, type ShippingOption, type Snippet, accountPackageSchema, accountSchema, accountSnippetSchema, aiReviewSchema, databaseSchema, datasheetPinInformationSchema, datasheetSchema, errorResponseSchema, errorSchema, jlcpcbOrderStateSchema, jlcpcbOrderStepRunSchema, loginPageSchema, orderFileSchema, orderQuoteSchema, orderSchema, packageFileSchema, packageReleaseSchema, packageSchema, quotedComponentSchema, sessionSchema, shippingInfoSchema, snippetSchema };
package/dist/schema.js CHANGED
@@ -115,6 +115,28 @@ var orderQuoteSchema = z.object({
115
115
  shipping_options: z.array(shippingOptionSchema),
116
116
  total_cost_without_shipping: z.number().default(0)
117
117
  });
118
+ var aiReviewSchema = z.object({
119
+ ai_review_id: z.string().uuid(),
120
+ ai_review_text: z.string().nullable(),
121
+ start_processing_at: z.string().datetime().nullable(),
122
+ finished_processing_at: z.string().datetime().nullable(),
123
+ processing_error: z.any().nullable(),
124
+ created_at: z.string().datetime(),
125
+ display_status: z.enum(["pending", "completed", "failed"])
126
+ });
127
+ var datasheetPinInformationSchema = z.object({
128
+ pin_number: z.string(),
129
+ name: z.string(),
130
+ description: z.string(),
131
+ capabilities: z.array(z.string())
132
+ });
133
+ var datasheetSchema = z.object({
134
+ datasheet_id: z.string(),
135
+ chip_name: z.string(),
136
+ created_at: z.string(),
137
+ pin_information: datasheetPinInformationSchema.array().nullable(),
138
+ datasheet_pdf_urls: z.array(z.string()).nullable()
139
+ });
118
140
  var accountSnippetSchema = z.object({
119
141
  account_id: z.string(),
120
142
  snippet_id: z.string(),
@@ -259,13 +281,18 @@ var databaseSchema = z.object({
259
281
  accountPackages: z.array(accountPackageSchema).default([]),
260
282
  jlcpcbOrderState: z.array(jlcpcbOrderStateSchema).default([]),
261
283
  jlcpcbOrderStepRuns: z.array(jlcpcbOrderStepRunSchema).default([]),
262
- orderQuotes: z.array(orderQuoteSchema).default([])
284
+ orderQuotes: z.array(orderQuoteSchema).default([]),
285
+ aiReviews: z.array(aiReviewSchema).default([]),
286
+ datasheets: z.array(datasheetSchema).default([])
263
287
  });
264
288
  export {
265
289
  accountPackageSchema,
266
290
  accountSchema,
267
291
  accountSnippetSchema,
292
+ aiReviewSchema,
268
293
  databaseSchema,
294
+ datasheetPinInformationSchema,
295
+ datasheetSchema,
269
296
  errorResponseSchema,
270
297
  errorSchema,
271
298
  jlcpcbOrderStateSchema,
@@ -16,6 +16,10 @@ import {
16
16
  type PackageFile,
17
17
  type PackageRelease,
18
18
  packageReleaseSchema,
19
+ type AiReview,
20
+ aiReviewSchema,
21
+ type Datasheet,
22
+ datasheetSchema,
19
23
  type Session,
20
24
  type Snippet,
21
25
  databaseSchema,
@@ -1338,4 +1342,76 @@ const initializer = combine(databaseSchema.parse({}), (set, get) => ({
1338
1342
  ),
1339
1343
  }))
1340
1344
  },
1345
+
1346
+ addAiReview: (review: Omit<AiReview, "ai_review_id">): AiReview => {
1347
+ const base = aiReviewSchema.omit({ ai_review_id: true }).parse(review)
1348
+ const newReview = {
1349
+ ai_review_id: crypto.randomUUID(),
1350
+ ...base,
1351
+ }
1352
+ set((state) => ({
1353
+ aiReviews: [...state.aiReviews, newReview],
1354
+ idCounter: state.idCounter + 1,
1355
+ }))
1356
+ return newReview
1357
+ },
1358
+ updateAiReview: (
1359
+ aiReviewId: string,
1360
+ updates: Partial<AiReview>,
1361
+ ): AiReview | undefined => {
1362
+ let updated: AiReview | undefined
1363
+ set((state) => {
1364
+ const index = state.aiReviews.findIndex(
1365
+ (ar) => ar.ai_review_id === aiReviewId,
1366
+ )
1367
+ if (index === -1) return state
1368
+ const aiReviews = [...state.aiReviews]
1369
+ aiReviews[index] = { ...aiReviews[index], ...updates }
1370
+ updated = aiReviews[index]
1371
+ return { ...state, aiReviews }
1372
+ })
1373
+ return updated
1374
+ },
1375
+ getAiReviewById: (aiReviewId: string): AiReview | undefined => {
1376
+ const state = get()
1377
+ return state.aiReviews.find((ar) => ar.ai_review_id === aiReviewId)
1378
+ },
1379
+ listAiReviews: (): AiReview[] => {
1380
+ const state = get()
1381
+ return state.aiReviews
1382
+ },
1383
+ addDatasheet: ({ chip_name }: { chip_name: string }): Datasheet => {
1384
+ const newDatasheet = datasheetSchema.parse({
1385
+ datasheet_id: `datasheet_${Date.now()}`,
1386
+ chip_name,
1387
+ created_at: new Date().toISOString(),
1388
+ pin_information: null,
1389
+ datasheet_pdf_urls: null,
1390
+ })
1391
+ set((state) => ({
1392
+ datasheets: [...state.datasheets, newDatasheet],
1393
+ }))
1394
+ return newDatasheet
1395
+ },
1396
+ getDatasheetById: (datasheetId: string): Datasheet | undefined => {
1397
+ const state = get()
1398
+ return state.datasheets.find((d) => d.datasheet_id === datasheetId)
1399
+ },
1400
+ updateDatasheet: (
1401
+ datasheetId: string,
1402
+ updates: Partial<Datasheet>,
1403
+ ): Datasheet | undefined => {
1404
+ let updated: Datasheet | undefined
1405
+ set((state) => {
1406
+ const index = state.datasheets.findIndex(
1407
+ (d) => d.datasheet_id === datasheetId,
1408
+ )
1409
+ if (index === -1) return state
1410
+ const datasheets = [...state.datasheets]
1411
+ datasheets[index] = { ...datasheets[index], ...updates }
1412
+ updated = datasheets[index]
1413
+ return { ...state, datasheets }
1414
+ })
1415
+ return updated
1416
+ },
1341
1417
  }))
@@ -138,6 +138,33 @@ export const orderQuoteSchema = z.object({
138
138
  })
139
139
  export type OrderQuote = z.infer<typeof orderQuoteSchema>
140
140
 
141
+ export const aiReviewSchema = z.object({
142
+ ai_review_id: z.string().uuid(),
143
+ ai_review_text: z.string().nullable(),
144
+ start_processing_at: z.string().datetime().nullable(),
145
+ finished_processing_at: z.string().datetime().nullable(),
146
+ processing_error: z.any().nullable(),
147
+ created_at: z.string().datetime(),
148
+ display_status: z.enum(["pending", "completed", "failed"]),
149
+ })
150
+ export type AiReview = z.infer<typeof aiReviewSchema>
151
+
152
+ export const datasheetPinInformationSchema = z.object({
153
+ pin_number: z.string(),
154
+ name: z.string(),
155
+ description: z.string(),
156
+ capabilities: z.array(z.string()),
157
+ })
158
+
159
+ export const datasheetSchema = z.object({
160
+ datasheet_id: z.string(),
161
+ chip_name: z.string(),
162
+ created_at: z.string(),
163
+ pin_information: datasheetPinInformationSchema.array().nullable(),
164
+ datasheet_pdf_urls: z.array(z.string()).nullable(),
165
+ })
166
+ export type Datasheet = z.infer<typeof datasheetSchema>
167
+
141
168
  // TODO: Remove this schema after migration to accountPackages is complete
142
169
  export const accountSnippetSchema = z.object({
143
170
  account_id: z.string(),
@@ -314,5 +341,7 @@ export const databaseSchema = z.object({
314
341
  jlcpcbOrderState: z.array(jlcpcbOrderStateSchema).default([]),
315
342
  jlcpcbOrderStepRuns: z.array(jlcpcbOrderStepRunSchema).default([]),
316
343
  orderQuotes: z.array(orderQuoteSchema).default([]),
344
+ aiReviews: z.array(aiReviewSchema).default([]),
345
+ datasheets: z.array(datasheetSchema).default([]),
317
346
  })
318
347
  export type DatabaseSchema = z.infer<typeof databaseSchema>
@@ -0,0 +1,31 @@
1
+ import { withRouteSpec } from "fake-snippets-api/lib/middleware/with-winter-spec"
2
+ import { z } from "zod"
3
+ import { aiReviewSchema } from "fake-snippets-api/lib/db/schema"
4
+
5
+ export default withRouteSpec({
6
+ methods: ["POST"],
7
+ auth: "session",
8
+ jsonBody: z.object({
9
+ ai_review_id: z.string(),
10
+ }),
11
+ jsonResponse: z.object({
12
+ ai_review: aiReviewSchema,
13
+ }),
14
+ })(async (req, ctx) => {
15
+ const { ai_review_id } = req.jsonBody
16
+ const existing = ctx.db.getAiReviewById(ai_review_id)
17
+ if (!existing) {
18
+ return ctx.error(404, {
19
+ error_code: "ai_review_not_found",
20
+ message: "AI review not found",
21
+ })
22
+ }
23
+ const now = new Date().toISOString()
24
+ const updated = ctx.db.updateAiReview(ai_review_id, {
25
+ ai_review_text: "Placeholder AI Review",
26
+ start_processing_at: existing.start_processing_at ?? now,
27
+ finished_processing_at: now,
28
+ display_status: "completed",
29
+ })!
30
+ return ctx.json({ ai_review: updated })
31
+ })
@@ -0,0 +1,37 @@
1
+ import { datasheetSchema } from "fake-snippets-api/lib/db/schema"
2
+ import { withRouteSpec } from "fake-snippets-api/lib/middleware/with-winter-spec"
3
+ import { z } from "zod"
4
+
5
+ export const processAllDatasheets = (ctx: any) => {
6
+ const processed = [] as z.infer<typeof datasheetSchema>[]
7
+ ctx.db.datasheets.forEach((ds: any) => {
8
+ if (!ds.pin_information || !ds.datasheet_pdf_urls) {
9
+ const updated = ctx.db.updateDatasheet(ds.datasheet_id, {
10
+ pin_information: [
11
+ {
12
+ pin_number: "1",
13
+ name: "PIN1",
14
+ description: "Placeholder pin",
15
+ capabilities: ["digital"],
16
+ },
17
+ ],
18
+ datasheet_pdf_urls: ["https://example.com/datasheet.pdf"],
19
+ })
20
+ processed.push(updated!)
21
+ } else {
22
+ processed.push(ds)
23
+ }
24
+ })
25
+ return processed
26
+ }
27
+
28
+ export default withRouteSpec({
29
+ methods: ["POST"],
30
+ auth: "none",
31
+ jsonResponse: z.object({
32
+ datasheets: datasheetSchema.array(),
33
+ }),
34
+ })(async (req, ctx) => {
35
+ const datasheets = processAllDatasheets(ctx)
36
+ return ctx.json({ datasheets })
37
+ })
@@ -0,0 +1,12 @@
1
+ import { withRouteSpec } from "fake-snippets-api/lib/middleware/with-winter-spec"
2
+ import { z } from "zod"
3
+ import { processAllDatasheets } from "./datasheets/process_all_datasheets"
4
+
5
+ export default withRouteSpec({
6
+ methods: ["GET"],
7
+ auth: "none",
8
+ jsonResponse: z.object({ ok: z.boolean() }),
9
+ })(async (req, ctx) => {
10
+ processAllDatasheets(ctx)
11
+ return ctx.json({ ok: true })
12
+ })
@@ -0,0 +1,22 @@
1
+ import { withRouteSpec } from "fake-snippets-api/lib/middleware/with-winter-spec"
2
+ import { z } from "zod"
3
+ import { aiReviewSchema } from "fake-snippets-api/lib/db/schema"
4
+
5
+ export default withRouteSpec({
6
+ methods: ["POST"],
7
+ auth: "session",
8
+ jsonResponse: z.object({
9
+ ai_review: aiReviewSchema,
10
+ }),
11
+ })(async (req, ctx) => {
12
+ const ai_review = ctx.db.addAiReview({
13
+ ai_review_text: null,
14
+ start_processing_at: null,
15
+ finished_processing_at: null,
16
+ processing_error: null,
17
+ created_at: new Date().toISOString(),
18
+ display_status: "pending",
19
+ })
20
+
21
+ return ctx.json({ ai_review })
22
+ })