@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/index.d.ts CHANGED
@@ -384,6 +384,77 @@ declare const orderQuoteSchema: z.ZodObject<{
384
384
  total_cost_without_shipping?: number | undefined;
385
385
  }>;
386
386
  type OrderQuote = z.infer<typeof orderQuoteSchema>;
387
+ declare const aiReviewSchema: z.ZodObject<{
388
+ ai_review_id: z.ZodString;
389
+ ai_review_text: z.ZodNullable<z.ZodString>;
390
+ start_processing_at: z.ZodNullable<z.ZodString>;
391
+ finished_processing_at: z.ZodNullable<z.ZodString>;
392
+ processing_error: z.ZodNullable<z.ZodAny>;
393
+ created_at: z.ZodString;
394
+ display_status: z.ZodEnum<["pending", "completed", "failed"]>;
395
+ }, "strip", z.ZodTypeAny, {
396
+ created_at: string;
397
+ ai_review_id: string;
398
+ ai_review_text: string | null;
399
+ start_processing_at: string | null;
400
+ finished_processing_at: string | null;
401
+ display_status: "pending" | "completed" | "failed";
402
+ processing_error?: any;
403
+ }, {
404
+ created_at: string;
405
+ ai_review_id: string;
406
+ ai_review_text: string | null;
407
+ start_processing_at: string | null;
408
+ finished_processing_at: string | null;
409
+ display_status: "pending" | "completed" | "failed";
410
+ processing_error?: any;
411
+ }>;
412
+ type AiReview = z.infer<typeof aiReviewSchema>;
413
+ declare const datasheetSchema: z.ZodObject<{
414
+ datasheet_id: z.ZodString;
415
+ chip_name: z.ZodString;
416
+ created_at: z.ZodString;
417
+ pin_information: z.ZodNullable<z.ZodArray<z.ZodObject<{
418
+ pin_number: z.ZodString;
419
+ name: z.ZodString;
420
+ description: z.ZodString;
421
+ capabilities: z.ZodArray<z.ZodString, "many">;
422
+ }, "strip", z.ZodTypeAny, {
423
+ name: string;
424
+ description: string;
425
+ pin_number: string;
426
+ capabilities: string[];
427
+ }, {
428
+ name: string;
429
+ description: string;
430
+ pin_number: string;
431
+ capabilities: string[];
432
+ }>, "many">>;
433
+ datasheet_pdf_urls: z.ZodNullable<z.ZodArray<z.ZodString, "many">>;
434
+ }, "strip", z.ZodTypeAny, {
435
+ created_at: string;
436
+ datasheet_id: string;
437
+ chip_name: string;
438
+ pin_information: {
439
+ name: string;
440
+ description: string;
441
+ pin_number: string;
442
+ capabilities: string[];
443
+ }[] | null;
444
+ datasheet_pdf_urls: string[] | null;
445
+ }, {
446
+ created_at: string;
447
+ datasheet_id: string;
448
+ chip_name: string;
449
+ pin_information: {
450
+ name: string;
451
+ description: string;
452
+ pin_number: string;
453
+ capabilities: string[];
454
+ }[] | null;
455
+ datasheet_pdf_urls: string[] | null;
456
+ }>;
457
+ type Datasheet = z.infer<typeof datasheetSchema>;
387
458
  declare const accountPackageSchema: z.ZodObject<{
388
459
  account_package_id: z.ZodString;
389
460
  account_id: z.ZodString;
@@ -445,11 +516,11 @@ declare const packageReleaseSchema: z.ZodObject<{
445
516
  package_release_id: string;
446
517
  created_at: string;
447
518
  version: string | null;
519
+ display_status: "error" | "pending" | "building" | "complete";
448
520
  package_id: string;
449
521
  is_locked: boolean;
450
522
  is_latest: boolean;
451
523
  has_transpiled: boolean;
452
- display_status: "error" | "pending" | "building" | "complete";
453
524
  transpilation_display_status: "error" | "pending" | "building" | "complete";
454
525
  transpilation_in_progress: boolean;
455
526
  transpilation_logs: any[];
@@ -459,6 +530,7 @@ declare const packageReleaseSchema: z.ZodObject<{
459
530
  circuit_json_build_logs: any[];
460
531
  circuit_json_build_is_stale: boolean;
461
532
  ai_review_requested: boolean;
533
+ ai_review_text?: string | null | undefined;
462
534
  commit_sha?: string | null | undefined;
463
535
  license?: string | null | undefined;
464
536
  circuit_json_build_error?: string | null | undefined;
@@ -470,7 +542,6 @@ declare const packageReleaseSchema: z.ZodObject<{
470
542
  transpilation_completed_at?: string | null | undefined;
471
543
  circuit_json_build_started_at?: string | null | undefined;
472
544
  circuit_json_build_completed_at?: string | null | undefined;
473
- ai_review_text?: string | null | undefined;
474
545
  ai_review_started_at?: string | null | undefined;
475
546
  ai_review_completed_at?: string | null | undefined;
476
547
  ai_review_error?: any;
@@ -482,6 +553,8 @@ declare const packageReleaseSchema: z.ZodObject<{
482
553
  package_id: string;
483
554
  is_locked: boolean;
484
555
  is_latest: boolean;
556
+ ai_review_text?: string | null | undefined;
557
+ display_status?: "error" | "pending" | "building" | "complete" | undefined;
485
558
  commit_sha?: string | null | undefined;
486
559
  license?: string | null | undefined;
487
560
  circuit_json_build_error?: string | null | undefined;
@@ -489,7 +562,6 @@ declare const packageReleaseSchema: z.ZodObject<{
489
562
  has_transpiled?: boolean | undefined;
490
563
  transpilation_error?: string | null | undefined;
491
564
  fs_sha?: string | null | undefined;
492
- display_status?: "error" | "pending" | "building" | "complete" | undefined;
493
565
  total_build_duration_ms?: number | null | undefined;
494
566
  transpilation_display_status?: "error" | "pending" | "building" | "complete" | undefined;
495
567
  transpilation_in_progress?: boolean | undefined;
@@ -503,7 +575,6 @@ declare const packageReleaseSchema: z.ZodObject<{
503
575
  circuit_json_build_completed_at?: string | null | undefined;
504
576
  circuit_json_build_logs?: any[] | undefined;
505
577
  circuit_json_build_is_stale?: boolean | undefined;
506
- ai_review_text?: string | null | undefined;
507
578
  ai_review_started_at?: string | null | undefined;
508
579
  ai_review_completed_at?: string | null | undefined;
509
580
  ai_review_error?: any;
@@ -765,11 +836,11 @@ declare const createDatabase: ({ seed }?: {
765
836
  package_release_id: string;
766
837
  created_at: string;
767
838
  version: string | null;
839
+ display_status: "error" | "pending" | "building" | "complete";
768
840
  package_id: string;
769
841
  is_locked: boolean;
770
842
  is_latest: boolean;
771
843
  has_transpiled: boolean;
772
- display_status: "error" | "pending" | "building" | "complete";
773
844
  transpilation_display_status: "error" | "pending" | "building" | "complete";
774
845
  transpilation_in_progress: boolean;
775
846
  transpilation_logs: any[];
@@ -779,6 +850,7 @@ declare const createDatabase: ({ seed }?: {
779
850
  circuit_json_build_logs: any[];
780
851
  circuit_json_build_is_stale: boolean;
781
852
  ai_review_requested: boolean;
853
+ ai_review_text?: string | null | undefined;
782
854
  commit_sha?: string | null | undefined;
783
855
  license?: string | null | undefined;
784
856
  circuit_json_build_error?: string | null | undefined;
@@ -790,7 +862,6 @@ declare const createDatabase: ({ seed }?: {
790
862
  transpilation_completed_at?: string | null | undefined;
791
863
  circuit_json_build_started_at?: string | null | undefined;
792
864
  circuit_json_build_completed_at?: string | null | undefined;
793
- ai_review_text?: string | null | undefined;
794
865
  ai_review_started_at?: string | null | undefined;
795
866
  ai_review_completed_at?: string | null | undefined;
796
867
  ai_review_error?: any;
@@ -973,7 +1044,28 @@ declare const createDatabase: ({ seed }?: {
973
1044
  }[];
974
1045
  total_cost_without_shipping: number;
975
1046
  }[];
976
- }, "addOrder" | "getOrderById" | "getOrderFilesByOrderId" | "addOrderQuote" | "getOrderQuoteById" | "getJlcpcbOrderStatesByOrderId" | "getJlcpcbOrderStepRunsByJlcpcbOrderStateId" | "updateOrder" | "addJlcpcbOrderState" | "updateJlcpcbOrderState" | "addOrderFile" | "getOrderFileById" | "addAccount" | "addAccountPackage" | "getAccountPackageById" | "updateAccountPackage" | "deleteAccountPackage" | "addSnippet" | "getLatestSnippets" | "getTrendingSnippets" | "getPackagesByAuthor" | "getSnippetByAuthorAndName" | "updateSnippet" | "getSnippetById" | "searchSnippets" | "searchPackages" | "deleteSnippet" | "addSession" | "getSessions" | "createLoginPage" | "getLoginPage" | "updateLoginPage" | "getAccount" | "updateAccount" | "createSession" | "addStar" | "removeStar" | "hasStarred" | "addPackage" | "updatePackage" | "getPackageById" | "getPackageReleaseById" | "addPackageRelease" | "updatePackageRelease" | "deletePackageFile" | "addPackageFile" | "updatePackageFile" | "getStarCount" | "getPackageFilesByReleaseId" | "updatePackageReleaseFsSha"> & {
1047
+ aiReviews: {
1048
+ created_at: string;
1049
+ ai_review_id: string;
1050
+ ai_review_text: string | null;
1051
+ start_processing_at: string | null;
1052
+ finished_processing_at: string | null;
1053
+ display_status: "pending" | "completed" | "failed";
1054
+ processing_error?: any;
1055
+ }[];
1056
+ datasheets: {
1057
+ created_at: string;
1058
+ datasheet_id: string;
1059
+ chip_name: string;
1060
+ pin_information: {
1061
+ name: string;
1062
+ description: string;
1063
+ pin_number: string;
1064
+ capabilities: string[];
1065
+ }[] | null;
1066
+ datasheet_pdf_urls: string[] | null;
1067
+ }[];
1068
+ }, "addOrder" | "getOrderById" | "getOrderFilesByOrderId" | "addOrderQuote" | "getOrderQuoteById" | "getJlcpcbOrderStatesByOrderId" | "getJlcpcbOrderStepRunsByJlcpcbOrderStateId" | "updateOrder" | "addJlcpcbOrderState" | "updateJlcpcbOrderState" | "addOrderFile" | "getOrderFileById" | "addAccount" | "addAccountPackage" | "getAccountPackageById" | "updateAccountPackage" | "deleteAccountPackage" | "addSnippet" | "getLatestSnippets" | "getTrendingSnippets" | "getPackagesByAuthor" | "getSnippetByAuthorAndName" | "updateSnippet" | "getSnippetById" | "searchSnippets" | "searchPackages" | "deleteSnippet" | "addSession" | "getSessions" | "createLoginPage" | "getLoginPage" | "updateLoginPage" | "getAccount" | "updateAccount" | "createSession" | "addStar" | "removeStar" | "hasStarred" | "addPackage" | "updatePackage" | "getPackageById" | "getPackageReleaseById" | "addPackageRelease" | "updatePackageRelease" | "deletePackageFile" | "addPackageFile" | "updatePackageFile" | "getStarCount" | "getPackageFilesByReleaseId" | "updatePackageReleaseFsSha" | "addAiReview" | "updateAiReview" | "getAiReviewById" | "listAiReviews" | "addDatasheet" | "getDatasheetById" | "updateDatasheet"> & {
977
1069
  addOrder: (order: Omit<Order, "order_id">) => Order;
978
1070
  getOrderById: (orderId: string) => Order | undefined;
979
1071
  getOrderFilesByOrderId: (orderId: string) => OrderFile[];
@@ -1051,6 +1143,15 @@ declare const createDatabase: ({ seed }?: {
1051
1143
  * Update fs_sha for a package release based on its files
1052
1144
  */
1053
1145
  updatePackageReleaseFsSha: (packageReleaseId: string) => void;
1146
+ addAiReview: (review: Omit<AiReview, "ai_review_id">) => AiReview;
1147
+ updateAiReview: (aiReviewId: string, updates: Partial<AiReview>) => AiReview | undefined;
1148
+ getAiReviewById: (aiReviewId: string) => AiReview | undefined;
1149
+ listAiReviews: () => AiReview[];
1150
+ addDatasheet: ({ chip_name }: {
1151
+ chip_name: string;
1152
+ }) => Datasheet;
1153
+ getDatasheetById: (datasheetId: string) => Datasheet | undefined;
1154
+ updateDatasheet: (datasheetId: string, updates: Partial<Datasheet>) => Datasheet | undefined;
1054
1155
  }> & Omit<{
1055
1156
  idCounter: number;
1056
1157
  snippets: {
@@ -1081,11 +1182,11 @@ declare const createDatabase: ({ seed }?: {
1081
1182
  package_release_id: string;
1082
1183
  created_at: string;
1083
1184
  version: string | null;
1185
+ display_status: "error" | "pending" | "building" | "complete";
1084
1186
  package_id: string;
1085
1187
  is_locked: boolean;
1086
1188
  is_latest: boolean;
1087
1189
  has_transpiled: boolean;
1088
- display_status: "error" | "pending" | "building" | "complete";
1089
1190
  transpilation_display_status: "error" | "pending" | "building" | "complete";
1090
1191
  transpilation_in_progress: boolean;
1091
1192
  transpilation_logs: any[];
@@ -1095,6 +1196,7 @@ declare const createDatabase: ({ seed }?: {
1095
1196
  circuit_json_build_logs: any[];
1096
1197
  circuit_json_build_is_stale: boolean;
1097
1198
  ai_review_requested: boolean;
1199
+ ai_review_text?: string | null | undefined;
1098
1200
  commit_sha?: string | null | undefined;
1099
1201
  license?: string | null | undefined;
1100
1202
  circuit_json_build_error?: string | null | undefined;
@@ -1106,7 +1208,6 @@ declare const createDatabase: ({ seed }?: {
1106
1208
  transpilation_completed_at?: string | null | undefined;
1107
1209
  circuit_json_build_started_at?: string | null | undefined;
1108
1210
  circuit_json_build_completed_at?: string | null | undefined;
1109
- ai_review_text?: string | null | undefined;
1110
1211
  ai_review_started_at?: string | null | undefined;
1111
1212
  ai_review_completed_at?: string | null | undefined;
1112
1213
  ai_review_error?: any;
@@ -1289,7 +1390,28 @@ declare const createDatabase: ({ seed }?: {
1289
1390
  }[];
1290
1391
  total_cost_without_shipping: number;
1291
1392
  }[];
1292
- }, "addOrder" | "getOrderById" | "getOrderFilesByOrderId" | "addOrderQuote" | "getOrderQuoteById" | "getJlcpcbOrderStatesByOrderId" | "getJlcpcbOrderStepRunsByJlcpcbOrderStateId" | "updateOrder" | "addJlcpcbOrderState" | "updateJlcpcbOrderState" | "addOrderFile" | "getOrderFileById" | "addAccount" | "addAccountPackage" | "getAccountPackageById" | "updateAccountPackage" | "deleteAccountPackage" | "addSnippet" | "getLatestSnippets" | "getTrendingSnippets" | "getPackagesByAuthor" | "getSnippetByAuthorAndName" | "updateSnippet" | "getSnippetById" | "searchSnippets" | "searchPackages" | "deleteSnippet" | "addSession" | "getSessions" | "createLoginPage" | "getLoginPage" | "updateLoginPage" | "getAccount" | "updateAccount" | "createSession" | "addStar" | "removeStar" | "hasStarred" | "addPackage" | "updatePackage" | "getPackageById" | "getPackageReleaseById" | "addPackageRelease" | "updatePackageRelease" | "deletePackageFile" | "addPackageFile" | "updatePackageFile" | "getStarCount" | "getPackageFilesByReleaseId" | "updatePackageReleaseFsSha"> & {
1393
+ aiReviews: {
1394
+ created_at: string;
1395
+ ai_review_id: string;
1396
+ ai_review_text: string | null;
1397
+ start_processing_at: string | null;
1398
+ finished_processing_at: string | null;
1399
+ display_status: "pending" | "completed" | "failed";
1400
+ processing_error?: any;
1401
+ }[];
1402
+ datasheets: {
1403
+ created_at: string;
1404
+ datasheet_id: string;
1405
+ chip_name: string;
1406
+ pin_information: {
1407
+ name: string;
1408
+ description: string;
1409
+ pin_number: string;
1410
+ capabilities: string[];
1411
+ }[] | null;
1412
+ datasheet_pdf_urls: string[] | null;
1413
+ }[];
1414
+ }, "addOrder" | "getOrderById" | "getOrderFilesByOrderId" | "addOrderQuote" | "getOrderQuoteById" | "getJlcpcbOrderStatesByOrderId" | "getJlcpcbOrderStepRunsByJlcpcbOrderStateId" | "updateOrder" | "addJlcpcbOrderState" | "updateJlcpcbOrderState" | "addOrderFile" | "getOrderFileById" | "addAccount" | "addAccountPackage" | "getAccountPackageById" | "updateAccountPackage" | "deleteAccountPackage" | "addSnippet" | "getLatestSnippets" | "getTrendingSnippets" | "getPackagesByAuthor" | "getSnippetByAuthorAndName" | "updateSnippet" | "getSnippetById" | "searchSnippets" | "searchPackages" | "deleteSnippet" | "addSession" | "getSessions" | "createLoginPage" | "getLoginPage" | "updateLoginPage" | "getAccount" | "updateAccount" | "createSession" | "addStar" | "removeStar" | "hasStarred" | "addPackage" | "updatePackage" | "getPackageById" | "getPackageReleaseById" | "addPackageRelease" | "updatePackageRelease" | "deletePackageFile" | "addPackageFile" | "updatePackageFile" | "getStarCount" | "getPackageFilesByReleaseId" | "updatePackageReleaseFsSha" | "addAiReview" | "updateAiReview" | "getAiReviewById" | "listAiReviews" | "addDatasheet" | "getDatasheetById" | "updateDatasheet"> & {
1293
1415
  addOrder: (order: Omit<Order, "order_id">) => Order;
1294
1416
  getOrderById: (orderId: string) => Order | undefined;
1295
1417
  getOrderFilesByOrderId: (orderId: string) => OrderFile[];
@@ -1367,6 +1489,15 @@ declare const createDatabase: ({ seed }?: {
1367
1489
  * Update fs_sha for a package release based on its files
1368
1490
  */
1369
1491
  updatePackageReleaseFsSha: (packageReleaseId: string) => void;
1492
+ addAiReview: (review: Omit<AiReview, "ai_review_id">) => AiReview;
1493
+ updateAiReview: (aiReviewId: string, updates: Partial<AiReview>) => AiReview | undefined;
1494
+ getAiReviewById: (aiReviewId: string) => AiReview | undefined;
1495
+ listAiReviews: () => AiReview[];
1496
+ addDatasheet: ({ chip_name }: {
1497
+ chip_name: string;
1498
+ }) => Datasheet;
1499
+ getDatasheetById: (datasheetId: string) => Datasheet | undefined;
1500
+ updateDatasheet: (datasheetId: string, updates: Partial<Datasheet>) => Datasheet | undefined;
1370
1501
  };
1371
1502
  type DbClient = ReturnType<typeof createDatabase>;
1372
1503
 
package/dist/index.js CHANGED
@@ -120,6 +120,28 @@ var orderQuoteSchema = z.object({
120
120
  shipping_options: z.array(shippingOptionSchema),
121
121
  total_cost_without_shipping: z.number().default(0)
122
122
  });
123
+ var aiReviewSchema = z.object({
124
+ ai_review_id: z.string().uuid(),
125
+ ai_review_text: z.string().nullable(),
126
+ start_processing_at: z.string().datetime().nullable(),
127
+ finished_processing_at: z.string().datetime().nullable(),
128
+ processing_error: z.any().nullable(),
129
+ created_at: z.string().datetime(),
130
+ display_status: z.enum(["pending", "completed", "failed"])
131
+ });
132
+ var datasheetPinInformationSchema = z.object({
133
+ pin_number: z.string(),
134
+ name: z.string(),
135
+ description: z.string(),
136
+ capabilities: z.array(z.string())
137
+ });
138
+ var datasheetSchema = z.object({
139
+ datasheet_id: z.string(),
140
+ chip_name: z.string(),
141
+ created_at: z.string(),
142
+ pin_information: datasheetPinInformationSchema.array().nullable(),
143
+ datasheet_pdf_urls: z.array(z.string()).nullable()
144
+ });
123
145
  var accountSnippetSchema = z.object({
124
146
  account_id: z.string(),
125
147
  snippet_id: z.string(),
@@ -264,7 +286,9 @@ var databaseSchema = z.object({
264
286
  accountPackages: z.array(accountPackageSchema).default([]),
265
287
  jlcpcbOrderState: z.array(jlcpcbOrderStateSchema).default([]),
266
288
  jlcpcbOrderStepRuns: z.array(jlcpcbOrderStepRunSchema).default([]),
267
- orderQuotes: z.array(orderQuoteSchema).default([])
289
+ orderQuotes: z.array(orderQuoteSchema).default([]),
290
+ aiReviews: z.array(aiReviewSchema).default([]),
291
+ datasheets: z.array(datasheetSchema).default([])
268
292
  });
269
293
 
270
294
  // fake-snippets-api/lib/db/autoload-dev-packages.ts
@@ -3049,6 +3073,71 @@ var initializer = combine(databaseSchema.parse({}), (set, get) => ({
3049
3073
  (pkg) => pkg.latest_package_release_id === packageReleaseId ? { ...pkg, latest_package_release_fs_sha: fsSha } : pkg
3050
3074
  )
3051
3075
  }));
3076
+ },
3077
+ addAiReview: (review) => {
3078
+ const base = aiReviewSchema.omit({ ai_review_id: true }).parse(review);
3079
+ const newReview = {
3080
+ ai_review_id: crypto.randomUUID(),
3081
+ ...base
3082
+ };
3083
+ set((state) => ({
3084
+ aiReviews: [...state.aiReviews, newReview],
3085
+ idCounter: state.idCounter + 1
3086
+ }));
3087
+ return newReview;
3088
+ },
3089
+ updateAiReview: (aiReviewId, updates) => {
3090
+ let updated;
3091
+ set((state) => {
3092
+ const index = state.aiReviews.findIndex(
3093
+ (ar) => ar.ai_review_id === aiReviewId
3094
+ );
3095
+ if (index === -1) return state;
3096
+ const aiReviews = [...state.aiReviews];
3097
+ aiReviews[index] = { ...aiReviews[index], ...updates };
3098
+ updated = aiReviews[index];
3099
+ return { ...state, aiReviews };
3100
+ });
3101
+ return updated;
3102
+ },
3103
+ getAiReviewById: (aiReviewId) => {
3104
+ const state = get();
3105
+ return state.aiReviews.find((ar) => ar.ai_review_id === aiReviewId);
3106
+ },
3107
+ listAiReviews: () => {
3108
+ const state = get();
3109
+ return state.aiReviews;
3110
+ },
3111
+ addDatasheet: ({ chip_name }) => {
3112
+ const newDatasheet = datasheetSchema.parse({
3113
+ datasheet_id: `datasheet_${Date.now()}`,
3114
+ chip_name,
3115
+ created_at: (/* @__PURE__ */ new Date()).toISOString(),
3116
+ pin_information: null,
3117
+ datasheet_pdf_urls: null
3118
+ });
3119
+ set((state) => ({
3120
+ datasheets: [...state.datasheets, newDatasheet]
3121
+ }));
3122
+ return newDatasheet;
3123
+ },
3124
+ getDatasheetById: (datasheetId) => {
3125
+ const state = get();
3126
+ return state.datasheets.find((d) => d.datasheet_id === datasheetId);
3127
+ },
3128
+ updateDatasheet: (datasheetId, updates) => {
3129
+ let updated;
3130
+ set((state) => {
3131
+ const index = state.datasheets.findIndex(
3132
+ (d) => d.datasheet_id === datasheetId
3133
+ );
3134
+ if (index === -1) return state;
3135
+ const datasheets = [...state.datasheets];
3136
+ datasheets[index] = { ...datasheets[index], ...updates };
3137
+ updated = datasheets[index];
3138
+ return { ...state, datasheets };
3139
+ });
3140
+ return updated;
3052
3141
  }
3053
3142
  }));
3054
3143