Fraser commited on
Commit
b78dca2
·
1 Parent(s): a8636b2
src/lib/components/PicletGenerator/PicletGenerator.svelte CHANGED
@@ -637,16 +637,14 @@ Create a concise visual description (1-3 sentences, max 100 words). Focus only o
637
  console.log('- stats:', cleanStats);
638
 
639
  // Convert to PicletInstance format and save as caught
640
- // Extract variation from objectAttributes (first attribute if any, otherwise undefined)
641
- const variation = workflowState.objectAttributes && workflowState.objectAttributes.length > 0
642
- ? workflowState.objectAttributes[0]
643
- : undefined;
644
 
645
  const picletInstance = await generatedDataToPicletInstance(
646
  picletData,
647
  workflowState.objectName || undefined,
648
- variation,
649
- workflowState.objectAttributes
650
  );
651
 
652
  const picletId = await savePicletInstance(picletInstance);
 
637
  console.log('- stats:', cleanStats);
638
 
639
  // Convert to PicletInstance format and save as caught
640
+ // Convert reactive Svelte state to plain values (removes Proxy wrapper for IndexedDB compatibility)
641
+ const plainAttributes = workflowState.objectAttributes ? [...workflowState.objectAttributes] : [];
 
 
642
 
643
  const picletInstance = await generatedDataToPicletInstance(
644
  picletData,
645
  workflowState.objectName || undefined,
646
+ plainAttributes,
647
+ workflowState.visualDetails || undefined
648
  );
649
 
650
  const picletId = await savePicletInstance(picletInstance);
src/lib/components/PicletGenerator/PicletResult.svelte CHANGED
@@ -34,15 +34,13 @@
34
  };
35
 
36
  // Create piclet instance asynchronously with discovery data
37
- const variation = workflowState.objectAttributes && workflowState.objectAttributes.length > 0
38
- ? workflowState.objectAttributes[0]
39
- : undefined;
40
 
41
  generatedDataToPicletInstance(
42
  picletData,
43
  workflowState.objectName || undefined,
44
- variation,
45
- workflowState.objectAttributes,
46
  workflowState.visualDetails || undefined
47
  ).then(instance => {
48
  picletInstance = { ...instance, id: 0 }; // Add temporary id for display
 
34
  };
35
 
36
  // Create piclet instance asynchronously with discovery data
37
+ // Convert reactive Svelte state to plain array
38
+ const plainAttributes = workflowState.objectAttributes ? [...workflowState.objectAttributes] : [];
 
39
 
40
  generatedDataToPicletInstance(
41
  picletData,
42
  workflowState.objectName || undefined,
43
+ plainAttributes,
 
44
  workflowState.visualDetails || undefined
45
  ).then(instance => {
46
  picletInstance = { ...instance, id: 0 }; // Add temporary id for display
src/lib/db/piclets.ts CHANGED
@@ -16,11 +16,16 @@ interface GeneratedPicletData {
16
  createdAt: Date;
17
  }
18
 
19
- // Convert generated piclet data to a PicletInstance
 
 
 
 
 
 
20
  export async function generatedDataToPicletInstance(
21
  data: GeneratedPicletData,
22
  objectName?: string,
23
- variation?: string,
24
  attributes?: string[],
25
  visualDetails?: string
26
  ): Promise<Omit<PicletInstance, 'id'>> {
@@ -33,8 +38,10 @@ export async function generatedDataToPicletInstance(
33
  // Map tier from stats to discovery rarity
34
  let tier: string = stats.tier || 'common';
35
 
36
- // Generate typeId using normalized object name + variation (or just object if variation is "canonical")
 
37
  const normalizedObjectName = objectName || stats.name;
 
38
  const typeId = generatePicletId(normalizedObjectName, variation && variation !== 'canonical' ? variation : undefined);
39
 
40
  return {
 
16
  createdAt: Date;
17
  }
18
 
19
+ /**
20
+ * Convert generated piclet data to a PicletInstance
21
+ * @param data - The generated piclet data with stats and images
22
+ * @param objectName - Optional normalized object name (e.g., "eiffel tower")
23
+ * @param attributes - Optional array of variation attributes (first item is the primary variation)
24
+ * @param visualDetails - Optional additional visual details
25
+ */
26
  export async function generatedDataToPicletInstance(
27
  data: GeneratedPicletData,
28
  objectName?: string,
 
29
  attributes?: string[],
30
  visualDetails?: string
31
  ): Promise<Omit<PicletInstance, 'id'>> {
 
38
  // Map tier from stats to discovery rarity
39
  let tier: string = stats.tier || 'common';
40
 
41
+ // Generate typeId using normalized object name + variation (first attribute if any)
42
+ // Variation is "canonical" if there are no attributes or if first attribute is "canonical"
43
  const normalizedObjectName = objectName || stats.name;
44
+ const variation = attributes && attributes.length > 0 ? attributes[0] : undefined;
45
  const typeId = generatePicletId(normalizedObjectName, variation && variation !== 'canonical' ? variation : undefined);
46
 
47
  return {