@zodic/shared 0.0.241 → 0.0.242
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.
- package/app/services/ConceptService.ts +39 -48
- package/package.json +1 -1
|
@@ -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,
|
|
2016
|
+
let table, whereClause;
|
|
2021
2017
|
|
|
2022
|
-
// Determine table and
|
|
2018
|
+
// Determine table and where clause
|
|
2023
2019
|
switch (params.reportType) {
|
|
2024
|
-
case
|
|
2025
|
-
case 'house':
|
|
2020
|
+
case "sign":
|
|
2026
2021
|
table = astroReports;
|
|
2027
|
-
|
|
2028
|
-
params.
|
|
2029
|
-
|
|
2030
|
-
|
|
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
|
|
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
|
-
|
|
2038
|
+
whereClause = and(
|
|
2039
|
+
eq(houseReports.sign, params.sign),
|
|
2040
|
+
eq(houseReports.house, params.houseNumber)
|
|
2041
|
+
);
|
|
2035
2042
|
break;
|
|
2036
|
-
case
|
|
2043
|
+
case "aspect":
|
|
2037
2044
|
table = aspectReports;
|
|
2038
|
-
|
|
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 =
|
|
2072
|
+
let phase = "generation";
|
|
2066
2073
|
try {
|
|
2067
2074
|
attempts++;
|
|
2068
2075
|
console.log(`🔄 Attempt ${attempts} to generate report content...`);
|
|
2069
2076
|
|
|
2070
|
-
|
|
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 =
|
|
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
|
-
|
|
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(
|
|
2120
|
+
console.log("🔁 Retrying...");
|
|
2130
2121
|
await new Promise((resolve) => setTimeout(resolve, 2000));
|
|
2131
2122
|
}
|
|
2132
2123
|
}
|