@zodic/shared 0.0.241 → 0.0.243

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.
@@ -2,7 +2,7 @@ import {
2
2
  KVNamespaceListKey,
3
3
  KVNamespaceListResult,
4
4
  } from '@cloudflare/workers-types';
5
- import { and, eq, inArray, sql } from 'drizzle-orm';
5
+ import { and, eq, inArray, isNull, sql } from 'drizzle-orm';
6
6
  import { drizzle } from 'drizzle-orm/d1';
7
7
  import { inject, injectable } from 'inversify';
8
8
  import 'reflect-metadata';
@@ -2010,42 +2010,49 @@ export class ConceptService {
2010
2010
  params: AstroReportParams,
2011
2011
  override: boolean = false
2012
2012
  ): Promise<void> {
2013
- console.log(
2014
- `🚀 Generating report content for ${JSON.stringify(
2015
- params
2016
- )}, override: ${override}`
2017
- );
2013
+ console.log(`🚀 Generating report content for ${JSON.stringify(params)}, override: ${override}`);
2018
2014
 
2019
2015
  const db = drizzle(this.context.env.DB);
2020
- let table, idField, whereClause;
2016
+ let table, whereClause;
2021
2017
 
2022
- // Determine table and ID
2018
+ // Determine table and where clause
2023
2019
  switch (params.reportType) {
2024
- case 'sign':
2025
- case 'house':
2020
+ case "sign":
2026
2021
  table = astroReports;
2027
- idField =
2028
- params.reportType === 'sign'
2029
- ? sql`SELECT id FROM astro_reports WHERE name = ${params.pointName} AND sign = ${params.sign} AND house IS NULL`
2030
- : sql`SELECT id FROM astro_reports WHERE name = ${params.pointName} AND house = ${params.house} AND sign IS NULL`;
2022
+ whereClause = and(
2023
+ eq(astroReports.name, params.pointName),
2024
+ eq(astroReports.sign, params.sign),
2025
+ isNull(astroReports.house)
2026
+ );
2031
2027
  break;
2032
- case 'signInHouse':
2028
+ case "house":
2029
+ table = astroReports;
2030
+ whereClause = and(
2031
+ eq(astroReports.name, params.pointName),
2032
+ eq(astroReports.house, params.house),
2033
+ isNull(astroReports.sign)
2034
+ );
2035
+ break;
2036
+ case "signInHouse":
2033
2037
  table = houseReports;
2034
- idField = sql`SELECT id FROM house_reports WHERE sign = ${params.sign} AND house = ${params.houseNumber}`;
2038
+ whereClause = and(
2039
+ eq(houseReports.sign, params.sign),
2040
+ eq(houseReports.house, params.houseNumber)
2041
+ );
2035
2042
  break;
2036
- case 'aspect':
2043
+ case "aspect":
2037
2044
  table = aspectReports;
2038
- idField = sql`SELECT id FROM aspect_reports WHERE aspecting_planet = ${params.aspectingPlanet} AND aspected_planet = ${params.aspectedPlanet} AND aspect = ${params.aspectingType}`;
2045
+ whereClause = and(
2046
+ eq(aspectReports.aspectingPlanet, params.aspectingPlanet),
2047
+ eq(aspectReports.aspectedPlanet, params.aspectedPlanet),
2048
+ eq(aspectReports.aspect, params.aspectingType)
2049
+ );
2039
2050
  break;
2040
2051
  default:
2041
2052
  throw new Error(`Unknown report type: ${(params as any).reportType}`);
2042
2053
  }
2043
2054
 
2044
- const report = await db
2045
- .select()
2046
- .from(table)
2047
- .where(sql`${idField}`)
2048
- .get();
2055
+ const report = await db.select().from(table).where(whereClause).get();
2049
2056
  if (!report) {
2050
2057
  throw new Error(`❌ No report found for ${JSON.stringify(params)}`);
2051
2058
  }
@@ -2062,30 +2069,21 @@ export class ConceptService {
2062
2069
  const maxAttempts = 2;
2063
2070
 
2064
2071
  while (attempts < maxAttempts) {
2065
- let phase = 'generation';
2072
+ let phase = "generation";
2066
2073
  try {
2067
2074
  attempts++;
2068
2075
  console.log(`🔄 Attempt ${attempts} to generate report content...`);
2069
2076
 
2070
- // Use buildLLMMessages().generateAstroReportContent
2071
- const messages = this.context
2072
- .buildLLMMessages()
2073
- .generateAstroReportContent({ params });
2077
+ const messages = this.context.buildLLMMessages().generateAstroReportContent({ params });
2074
2078
 
2075
- const response = await this.context
2076
- .api()
2077
- .callTogether.single(messages, {});
2079
+ const response = await this.context.api().callTogether.single(messages, {});
2078
2080
  if (!response) {
2079
2081
  throw new Error(`❌ AI returned an empty response`);
2080
2082
  }
2081
2083
 
2082
- phase = 'parsing';
2084
+ phase = "parsing";
2083
2085
 
2084
- const { enReport, ptReport } =
2085
- await this.parseAstrologicalReportContent(
2086
- params.reportType,
2087
- response
2088
- );
2086
+ const { enReport, ptReport } = await this.parseAstrologicalReportContent(params.reportType, response);
2089
2087
 
2090
2088
  console.log(`💾 Storing report content for ${id}`);
2091
2089
  await db
@@ -2100,10 +2098,7 @@ export class ConceptService {
2100
2098
  console.log(`✅ Report content stored for ${id}`);
2101
2099
  return;
2102
2100
  } catch (error) {
2103
- console.error(
2104
- `❌ Attempt ${attempts} failed at phase: ${phase}`,
2105
- (error as Error).message
2106
- );
2101
+ console.error(`❌ Attempt ${attempts} failed at phase: ${phase}`, (error as Error).message);
2107
2102
 
2108
2103
  const failureKey = `failures:astro:${params.reportType}:${id}`;
2109
2104
  await this.context.kvConceptFailuresStore().put(
@@ -2118,15 +2113,11 @@ export class ConceptService {
2118
2113
  );
2119
2114
 
2120
2115
  if (attempts >= maxAttempts) {
2121
- console.error(
2122
- `🚨 All ${maxAttempts} attempts failed at phase ${phase}`
2123
- );
2124
- throw new Error(
2125
- `Failed to generate content after ${maxAttempts} attempts`
2126
- );
2116
+ console.error(`🚨 All ${maxAttempts} attempts failed at phase ${phase}`);
2117
+ throw new Error(`Failed to generate content after ${maxAttempts} attempts`);
2127
2118
  }
2128
2119
 
2129
- console.log('🔁 Retrying...');
2120
+ console.log("🔁 Retrying...");
2130
2121
  await new Promise((resolve) => setTimeout(resolve, 2000));
2131
2122
  }
2132
2123
  }
@@ -2187,21 +2178,21 @@ export class ConceptService {
2187
2178
  const languageSections = response
2188
2179
  .split(/--\s*(EN|PT)\s*\n/)
2189
2180
  .filter(Boolean);
2190
-
2181
+
2191
2182
  for (let i = 0; i < languageSections.length; i += 2) {
2192
2183
  const language = languageSections[i].trim();
2193
2184
  const content = languageSections[i + 1]?.trim();
2194
2185
  if (!content || !language.match(/^(EN|PT)$/)) continue;
2195
-
2186
+
2196
2187
  const report: AstrologicalReport = {
2197
2188
  language,
2198
2189
  title: [],
2199
2190
  sections: {},
2200
2191
  };
2201
-
2192
+
2202
2193
  const lines = content.split('\n').map((line) => line.trim());
2203
2194
  let currentSection = '';
2204
-
2195
+
2205
2196
  for (const line of lines) {
2206
2197
  if (line.startsWith('### ') && report.title.length === 0) {
2207
2198
  report.title.push({
@@ -2210,19 +2201,18 @@ export class ConceptService {
2210
2201
  });
2211
2202
  continue;
2212
2203
  }
2213
-
2204
+
2214
2205
  if (line.startsWith('#### ')) {
2215
2206
  currentSection = cleanText(line.replace('#### ', '').trim());
2216
- report.sections[currentSection] =
2217
- report.sections[currentSection] || [];
2207
+ report.sections[currentSection] = report.sections[currentSection] || [];
2218
2208
  continue;
2219
2209
  }
2220
-
2210
+
2221
2211
  if (!line || !currentSection) continue;
2222
-
2212
+
2223
2213
  if (line.match(/^\d+\.\s/) || line.startsWith('- ')) {
2224
2214
  const listItem = line.replace(/^\d+\.\s|- /, '').trim();
2225
- const boldMatch = listItem.match(/^\*\*(.+?)\*\*:\s*(.+)$/);
2215
+ const boldMatch = listItem.match(/^\*\*(.+?)\*\*[:\s]*(.+)$/); // Updated regex
2226
2216
  if (boldMatch) {
2227
2217
  report.sections[currentSection].push({
2228
2218
  type: 'bullet-point',
@@ -2237,16 +2227,16 @@ export class ConceptService {
2237
2227
  }
2238
2228
  continue;
2239
2229
  }
2240
-
2230
+
2241
2231
  report.sections[currentSection].push({
2242
2232
  type: 'p',
2243
2233
  content: cleanText(line),
2244
2234
  });
2245
2235
  }
2246
-
2236
+
2247
2237
  reports.push(report);
2248
2238
  }
2249
-
2239
+
2250
2240
  return reports;
2251
2241
  }
2252
2242
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zodic/shared",
3
- "version": "0.0.241",
3
+ "version": "0.0.243",
4
4
  "module": "index.ts",
5
5
  "type": "module",
6
6
  "publishConfig": {