only_ever_generator 6.0.1 → 6.0.3

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 (43) hide show
  1. package/dist/bootstrap/app.d.ts.map +1 -1
  2. package/dist/bootstrap/app.js +0 -5
  3. package/dist/bootstrap/app.js.map +1 -1
  4. package/dist/card_gen/generate_cards.d.ts.map +1 -1
  5. package/dist/card_gen/generate_cards.js +4 -7
  6. package/dist/card_gen/generate_cards.js.map +1 -1
  7. package/dist/helper/schema_helper/build_card_schema.d.ts +1 -0
  8. package/dist/helper/schema_helper/build_card_schema.d.ts.map +1 -1
  9. package/dist/helper/schema_helper/build_card_schema.js +29 -1
  10. package/dist/helper/schema_helper/build_card_schema.js.map +1 -1
  11. package/dist/helper/schema_helper/build_classify_summarize_schema.d.ts.map +1 -1
  12. package/dist/helper/schema_helper/build_classify_summarize_schema.js +4 -1
  13. package/dist/helper/schema_helper/build_classify_summarize_schema.js.map +1 -1
  14. package/dist/helper/schema_helper/build_concept_facts_schema.d.ts.map +1 -1
  15. package/dist/helper/schema_helper/build_concept_facts_schema.js +4 -1
  16. package/dist/helper/schema_helper/build_concept_facts_schema.js.map +1 -1
  17. package/dist/index.js +63 -60
  18. package/dist/index.js.map +1 -1
  19. package/dist/typology_gen/generate_concept_facts.d.ts.map +1 -1
  20. package/dist/typology_gen/generate_concept_facts.js +10 -1
  21. package/dist/typology_gen/generate_concept_facts.js.map +1 -1
  22. package/dist/typology_gen/generate_typology.d.ts.map +1 -1
  23. package/dist/typology_gen/generate_typology.js +13 -0
  24. package/dist/typology_gen/generate_typology.js.map +1 -1
  25. package/dist/utils/distributed_quote_restoration.d.ts +31 -0
  26. package/dist/utils/distributed_quote_restoration.d.ts.map +1 -0
  27. package/dist/utils/distributed_quote_restoration.js +69 -0
  28. package/dist/utils/distributed_quote_restoration.js.map +1 -0
  29. package/dist/utils/sanitize_strings.d.ts +32 -0
  30. package/dist/utils/sanitize_strings.d.ts.map +1 -0
  31. package/dist/utils/sanitize_strings.js +61 -0
  32. package/dist/utils/sanitize_strings.js.map +1 -0
  33. package/package.json +1 -1
  34. package/src/bootstrap/app.ts +0 -5
  35. package/src/card_gen/generate_cards.ts +8 -8
  36. package/src/helper/schema_helper/build_card_schema.ts +20 -0
  37. package/src/helper/schema_helper/build_classify_summarize_schema.ts +5 -1
  38. package/src/helper/schema_helper/build_concept_facts_schema.ts +5 -1
  39. package/src/index.ts +61 -60
  40. package/src/typology_gen/generate_concept_facts.ts +18 -1
  41. package/src/typology_gen/generate_typology.ts +23 -0
  42. package/src/utils/distributed_quote_restoration.ts +80 -0
  43. package/src/utils/sanitize_strings.ts +65 -0
@@ -0,0 +1,65 @@
1
+ /**
2
+ * Utility functions for sanitizing strings for OpenAI structured outputs
3
+ * and restoring them back to their original form without requiring original mapping
4
+ */
5
+
6
+ // Use a unique, reversible encoding for quotes
7
+ const QUOTE_PLACEHOLDER = "___QUOTE___";
8
+
9
+ /**
10
+ * Sanitizes an array of strings by replacing quotes with a safe placeholder
11
+ * This approach is stateless and doesn't require storing mappings
12
+ * @param strings - Array of strings to sanitize
13
+ * @returns Array of sanitized strings
14
+ */
15
+ export function sanitizeStringsForSchema(strings: string[]): string[] {
16
+ return strings.map((str) => str.replace(/"/g, QUOTE_PLACEHOLDER));
17
+ }
18
+
19
+ /**
20
+ * Restores quotes in a string by replacing placeholders with actual quotes
21
+ * This works without needing the original mapping
22
+ * @param sanitizedString - String with quote placeholders
23
+ * @returns Original string with quotes restored
24
+ */
25
+ export function restoreQuotesInString(sanitizedString: string): string {
26
+ return sanitizedString.replace(new RegExp(QUOTE_PLACEHOLDER, "g"), '"');
27
+ }
28
+
29
+ /**
30
+ * Recursively restores quotes in an object's string values
31
+ * This works across Lambda functions without requiring original context
32
+ * @param obj - Object to process
33
+ * @returns Object with quotes restored
34
+ */
35
+ export function restoreQuotesInObject(obj: any): any {
36
+ if (typeof obj === "string") {
37
+ return restoreQuotesInString(obj);
38
+ }
39
+
40
+ if (Array.isArray(obj)) {
41
+ return obj.map((item) => restoreQuotesInObject(item));
42
+ }
43
+
44
+ if (obj && typeof obj === "object") {
45
+ const result: any = {};
46
+ for (const [key, value] of Object.entries(obj)) {
47
+ result[key] = restoreQuotesInObject(value);
48
+ }
49
+ return result;
50
+ }
51
+
52
+ return obj;
53
+ }
54
+
55
+ /**
56
+ * Legacy function signature for backward compatibility
57
+ * Now ignores the originalMapping parameter since it's not needed
58
+ * @deprecated Use restoreQuotesInObject(obj) instead
59
+ */
60
+ export function restoreQuotesInObjectLegacy(
61
+ obj: any,
62
+ originalMapping?: Map<string, string>
63
+ ): any {
64
+ return restoreQuotesInObject(obj);
65
+ }