@zodic/shared 0.0.250 β 0.0.252
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.
|
@@ -2012,22 +2012,30 @@ export class ConceptService {
|
|
|
2012
2012
|
}
|
|
2013
2013
|
|
|
2014
2014
|
async generateAstroReportContent(
|
|
2015
|
-
params:
|
|
2015
|
+
params:
|
|
2016
|
+
| AstroReportParams
|
|
2017
|
+
| { entityType: string; name: string; override?: boolean },
|
|
2016
2018
|
override: boolean = false
|
|
2017
2019
|
): Promise<void> {
|
|
2018
|
-
console.log(
|
|
2020
|
+
console.log(
|
|
2021
|
+
`π Generating content for ${JSON.stringify(
|
|
2022
|
+
params
|
|
2023
|
+
)}, override: ${override}`
|
|
2024
|
+
);
|
|
2019
2025
|
|
|
2020
2026
|
const db = drizzle(this.context.env.DB);
|
|
2021
2027
|
let table, whereClause;
|
|
2022
2028
|
|
|
2023
2029
|
let report: AstroReportRow | DescriptionTemplateRow;
|
|
2024
|
-
const isReport =
|
|
2030
|
+
const isReport = 'reportType' in params;
|
|
2025
2031
|
|
|
2026
2032
|
if (isReport) {
|
|
2027
2033
|
// Handle existing report types (sign, house, signInHouse, aspect, feature)
|
|
2028
2034
|
switch (params.reportType) {
|
|
2029
|
-
case
|
|
2030
|
-
console.log(
|
|
2035
|
+
case 'sign':
|
|
2036
|
+
console.log(
|
|
2037
|
+
`ποΈ Handling sign report: type=${params.type}, pointName=${params.pointName}, sign=${params.sign}`
|
|
2038
|
+
);
|
|
2031
2039
|
table = astroReports;
|
|
2032
2040
|
whereClause = and(
|
|
2033
2041
|
eq(astroReports.name, params.pointName),
|
|
@@ -2035,8 +2043,10 @@ export class ConceptService {
|
|
|
2035
2043
|
isNull(astroReports.house)
|
|
2036
2044
|
);
|
|
2037
2045
|
break;
|
|
2038
|
-
case
|
|
2039
|
-
console.log(
|
|
2046
|
+
case 'house':
|
|
2047
|
+
console.log(
|
|
2048
|
+
`ποΈ Handling house report: type=${params.type}, pointName=${params.pointName}, house=${params.house}`
|
|
2049
|
+
);
|
|
2040
2050
|
table = astroReports;
|
|
2041
2051
|
whereClause = and(
|
|
2042
2052
|
eq(astroReports.name, params.pointName),
|
|
@@ -2044,16 +2054,20 @@ export class ConceptService {
|
|
|
2044
2054
|
isNull(astroReports.sign)
|
|
2045
2055
|
);
|
|
2046
2056
|
break;
|
|
2047
|
-
case
|
|
2048
|
-
console.log(
|
|
2057
|
+
case 'signInHouse':
|
|
2058
|
+
console.log(
|
|
2059
|
+
`ποΈ Handling signInHouse report: sign=${params.sign}, houseNumber=${params.houseNumber}`
|
|
2060
|
+
);
|
|
2049
2061
|
table = houseReports;
|
|
2050
2062
|
whereClause = and(
|
|
2051
2063
|
eq(houseReports.sign, params.sign),
|
|
2052
2064
|
eq(houseReports.house, params.houseNumber)
|
|
2053
2065
|
);
|
|
2054
2066
|
break;
|
|
2055
|
-
case
|
|
2056
|
-
console.log(
|
|
2067
|
+
case 'aspect':
|
|
2068
|
+
console.log(
|
|
2069
|
+
`ποΈ Handling aspect report: aspectingPlanet=${params.aspectingPlanet}, aspectedPlanet=${params.aspectedPlanet}, aspectingType=${params.aspectingType}`
|
|
2070
|
+
);
|
|
2057
2071
|
table = aspectReports;
|
|
2058
2072
|
whereClause = and(
|
|
2059
2073
|
eq(aspectReports.aspectingPlanet, params.aspectingPlanet),
|
|
@@ -2061,29 +2075,46 @@ export class ConceptService {
|
|
|
2061
2075
|
eq(aspectReports.aspect, params.aspectingType)
|
|
2062
2076
|
);
|
|
2063
2077
|
break;
|
|
2064
|
-
case
|
|
2065
|
-
console.log(
|
|
2078
|
+
case 'feature':
|
|
2079
|
+
console.log(
|
|
2080
|
+
`ποΈ Handling feature report: featureType=${
|
|
2081
|
+
params.featureType
|
|
2082
|
+
}, ${JSON.stringify(params)}`
|
|
2083
|
+
);
|
|
2066
2084
|
table = astroFeatureReports;
|
|
2067
2085
|
let nameValue: string;
|
|
2068
|
-
if (params.featureType ===
|
|
2069
|
-
if (!(
|
|
2086
|
+
if (params.featureType === 'element') {
|
|
2087
|
+
if (!('subtype' in params))
|
|
2088
|
+
throw new Error('Missing subtype for element feature report');
|
|
2070
2089
|
switch (params.subtype) {
|
|
2071
|
-
case
|
|
2072
|
-
nameValue =
|
|
2090
|
+
case 'balanced':
|
|
2091
|
+
nameValue = 'balanced';
|
|
2073
2092
|
break;
|
|
2074
|
-
case
|
|
2075
|
-
if (!(
|
|
2093
|
+
case 'pure':
|
|
2094
|
+
if (!('dominantElement' in params))
|
|
2095
|
+
throw new Error(
|
|
2096
|
+
'Missing dominantElement for pure element report'
|
|
2097
|
+
);
|
|
2076
2098
|
nameValue = params.dominantElement;
|
|
2077
2099
|
break;
|
|
2078
|
-
case
|
|
2079
|
-
if (
|
|
2100
|
+
case 'preponderant_lacking':
|
|
2101
|
+
if (
|
|
2102
|
+
!('dominantElement' in params) ||
|
|
2103
|
+
!('lackingElement' in params)
|
|
2104
|
+
)
|
|
2105
|
+
throw new Error(
|
|
2106
|
+
'Missing dominantElement or lackingElement for preponderant_lacking element report'
|
|
2107
|
+
);
|
|
2080
2108
|
nameValue = `${params.dominantElement}-${params.lackingElement}`;
|
|
2081
2109
|
break;
|
|
2082
2110
|
default:
|
|
2083
|
-
throw new Error(
|
|
2111
|
+
throw new Error(
|
|
2112
|
+
`Unknown element subtype: ${(params as any).subtype}`
|
|
2113
|
+
);
|
|
2084
2114
|
}
|
|
2085
2115
|
} else {
|
|
2086
|
-
if (!(
|
|
2116
|
+
if (!('name' in params))
|
|
2117
|
+
throw new Error('Missing name for non-element feature report');
|
|
2087
2118
|
nameValue = params.name;
|
|
2088
2119
|
}
|
|
2089
2120
|
whereClause = and(
|
|
@@ -2094,22 +2125,36 @@ export class ConceptService {
|
|
|
2094
2125
|
default:
|
|
2095
2126
|
throw new Error(`Unknown report type: ${(params as any).reportType}`);
|
|
2096
2127
|
}
|
|
2097
|
-
report = await db
|
|
2128
|
+
report = (await db
|
|
2129
|
+
.select()
|
|
2130
|
+
.from(table as any)
|
|
2131
|
+
.where(whereClause)
|
|
2132
|
+
.get()) as AstroReportRow;
|
|
2098
2133
|
} else {
|
|
2099
2134
|
// Handle description templates
|
|
2100
|
-
console.log(
|
|
2135
|
+
console.log(
|
|
2136
|
+
`ποΈ Handling description template: entityType=${params.entityType}, name=${params.name}`
|
|
2137
|
+
);
|
|
2101
2138
|
table = astroDescriptionTemplates;
|
|
2102
2139
|
whereClause = and(
|
|
2103
2140
|
eq(astroDescriptionTemplates.entityType, params.entityType),
|
|
2104
2141
|
eq(astroDescriptionTemplates.name, params.name)
|
|
2105
2142
|
);
|
|
2106
|
-
report = await db
|
|
2143
|
+
report = (await db
|
|
2144
|
+
.select()
|
|
2145
|
+
.from(table as any)
|
|
2146
|
+
.where(whereClause)
|
|
2147
|
+
.get()) as DescriptionTemplateRow;
|
|
2107
2148
|
}
|
|
2108
2149
|
|
|
2109
2150
|
const id = report.id;
|
|
2110
2151
|
const hasContent = isReport
|
|
2111
|
-
? (report as AstroReportRow).enReport &&
|
|
2112
|
-
|
|
2152
|
+
? (report as AstroReportRow).enReport &&
|
|
2153
|
+
(report as AstroReportRow).ptReport
|
|
2154
|
+
: (report as DescriptionTemplateRow).enDescription !==
|
|
2155
|
+
'Pending generation' &&
|
|
2156
|
+
(report as DescriptionTemplateRow).ptDescription !==
|
|
2157
|
+
'Pendente de geraΓ§Γ£o';
|
|
2113
2158
|
|
|
2114
2159
|
if (!override && hasContent) {
|
|
2115
2160
|
console.log(`β‘ Content already exists for ${id}, skipping`);
|
|
@@ -2120,29 +2165,47 @@ export class ConceptService {
|
|
|
2120
2165
|
const maxAttempts = 2;
|
|
2121
2166
|
|
|
2122
2167
|
while (attempts < maxAttempts) {
|
|
2123
|
-
let phase =
|
|
2168
|
+
let phase = 'generation';
|
|
2124
2169
|
try {
|
|
2125
2170
|
attempts++;
|
|
2126
|
-
console.log(
|
|
2171
|
+
console.log(
|
|
2172
|
+
`π Attempt ${attempts} to generate ${
|
|
2173
|
+
isReport ? 'report' : 'description'
|
|
2174
|
+
} content for ${id}...`
|
|
2175
|
+
);
|
|
2127
2176
|
|
|
2128
2177
|
let messages: ChatMessages;
|
|
2129
2178
|
if (isReport) {
|
|
2130
|
-
messages = this.context
|
|
2179
|
+
messages = this.context
|
|
2180
|
+
.buildLLMMessages()
|
|
2181
|
+
.generateAstroReportContent({
|
|
2182
|
+
params: params as AstroReportParams,
|
|
2183
|
+
});
|
|
2131
2184
|
} else {
|
|
2132
2185
|
messages = this.generateDescriptionMessages(params);
|
|
2133
2186
|
}
|
|
2134
2187
|
|
|
2135
2188
|
console.log(`π¨ Sending messages to AI: ${JSON.stringify(messages)}`);
|
|
2136
|
-
const response = await this.context
|
|
2189
|
+
const response = await this.context
|
|
2190
|
+
.api()
|
|
2191
|
+
.callTogether.single(messages, {});
|
|
2137
2192
|
if (!response) {
|
|
2138
2193
|
throw new Error(`β AI returned an empty response for ${id}`);
|
|
2139
2194
|
}
|
|
2140
2195
|
|
|
2141
|
-
phase =
|
|
2142
|
-
console.log(
|
|
2196
|
+
phase = 'parsing';
|
|
2197
|
+
console.log(
|
|
2198
|
+
`π Received AI response for ${id}: ${response.slice(0, 200)}${
|
|
2199
|
+
response.length > 200 ? '...' : ''
|
|
2200
|
+
}`
|
|
2201
|
+
);
|
|
2143
2202
|
|
|
2144
2203
|
if (isReport) {
|
|
2145
|
-
const { enReport, ptReport } =
|
|
2204
|
+
const { enReport, ptReport } =
|
|
2205
|
+
await this.parseAstrologicalReportContent(
|
|
2206
|
+
(params as AstroReportParams).reportType,
|
|
2207
|
+
response
|
|
2208
|
+
);
|
|
2146
2209
|
console.log(`πΎ Storing report content for ${id}`);
|
|
2147
2210
|
await db
|
|
2148
2211
|
.update(table as any)
|
|
@@ -2153,7 +2216,8 @@ export class ConceptService {
|
|
|
2153
2216
|
.where(eq((table as any).id, id))
|
|
2154
2217
|
.run();
|
|
2155
2218
|
} else {
|
|
2156
|
-
const { enDescription, ptDescription } =
|
|
2219
|
+
const { enDescription, ptDescription } =
|
|
2220
|
+
await this.parseDescriptionContent(response);
|
|
2157
2221
|
console.log(`πΎ Storing description content for ${id}`);
|
|
2158
2222
|
await db
|
|
2159
2223
|
.update(table as any)
|
|
@@ -2165,12 +2229,19 @@ export class ConceptService {
|
|
|
2165
2229
|
.run();
|
|
2166
2230
|
}
|
|
2167
2231
|
|
|
2168
|
-
console.log(
|
|
2232
|
+
console.log(
|
|
2233
|
+
`β
${isReport ? 'Report' : 'Description'} content stored for ${id}`
|
|
2234
|
+
);
|
|
2169
2235
|
return;
|
|
2170
2236
|
} catch (error) {
|
|
2171
|
-
console.error(
|
|
2237
|
+
console.error(
|
|
2238
|
+
`β Attempt ${attempts} failed at phase: ${phase} for ${id}`,
|
|
2239
|
+
(error as Error).message
|
|
2240
|
+
);
|
|
2172
2241
|
|
|
2173
|
-
const failureKey = `failures:astro:${
|
|
2242
|
+
const failureKey = `failures:astro:${
|
|
2243
|
+
isReport ? (params as AstroReportParams).reportType : 'description'
|
|
2244
|
+
}:${id}`;
|
|
2174
2245
|
await this.context.kvConceptFailuresStore().put(
|
|
2175
2246
|
failureKey,
|
|
2176
2247
|
JSON.stringify({
|
|
@@ -2183,11 +2254,17 @@ export class ConceptService {
|
|
|
2183
2254
|
);
|
|
2184
2255
|
|
|
2185
2256
|
if (attempts >= maxAttempts) {
|
|
2186
|
-
console.error(
|
|
2187
|
-
|
|
2257
|
+
console.error(
|
|
2258
|
+
`π¨ All ${maxAttempts} attempts failed at phase ${phase} for ${id}`
|
|
2259
|
+
);
|
|
2260
|
+
throw new Error(
|
|
2261
|
+
`Failed to generate ${
|
|
2262
|
+
isReport ? 'report' : 'description'
|
|
2263
|
+
} for ${id} after ${maxAttempts} attempts`
|
|
2264
|
+
);
|
|
2188
2265
|
}
|
|
2189
2266
|
|
|
2190
|
-
console.log(
|
|
2267
|
+
console.log('π Retrying...');
|
|
2191
2268
|
await new Promise((resolve) => setTimeout(resolve, 2000));
|
|
2192
2269
|
}
|
|
2193
2270
|
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
CREATE TABLE `astro_description_templates` (
|
|
2
|
+
`id` text PRIMARY KEY NOT NULL,
|
|
3
|
+
`entity_type` text NOT NULL,
|
|
4
|
+
`name` text NOT NULL,
|
|
5
|
+
`en_name` text,
|
|
6
|
+
`pt_name` text,
|
|
7
|
+
`en_description` text NOT NULL,
|
|
8
|
+
`pt_description` text NOT NULL,
|
|
9
|
+
`created_at` integer DEFAULT CURRENT_TIMESTAMP,
|
|
10
|
+
`updated_at` integer DEFAULT CURRENT_TIMESTAMP
|
|
11
|
+
);
|
|
12
|
+
--> statement-breakpoint
|
|
13
|
+
CREATE INDEX `astro_description_templates_type_name_idx` ON `astro_description_templates` (`entity_type`,`name`);--> statement-breakpoint
|
|
14
|
+
ALTER TABLE `aspect_reports` ADD `description_template_id` text REFERENCES astro_description_templates(id);--> statement-breakpoint
|
|
15
|
+
CREATE INDEX `aspect_reports_description_template_idx` ON `aspect_reports` (`description_template_id`);--> statement-breakpoint
|
|
16
|
+
ALTER TABLE `aspect_reports` DROP COLUMN `en_description`;--> statement-breakpoint
|
|
17
|
+
ALTER TABLE `aspect_reports` DROP COLUMN `pt_description`;--> statement-breakpoint
|
|
18
|
+
ALTER TABLE `astro_feature_reports` ADD `description_template_id` text REFERENCES astro_description_templates(id);--> statement-breakpoint
|
|
19
|
+
CREATE INDEX `astro_feature_reports_description_template_idx` ON `astro_feature_reports` (`description_template_id`);--> statement-breakpoint
|
|
20
|
+
ALTER TABLE `astro_feature_reports` DROP COLUMN `en_description`;--> statement-breakpoint
|
|
21
|
+
ALTER TABLE `astro_feature_reports` DROP COLUMN `pt_description`;--> statement-breakpoint
|
|
22
|
+
ALTER TABLE `astro_reports` ADD `description_template_id` text REFERENCES astro_description_templates(id);--> statement-breakpoint
|
|
23
|
+
ALTER TABLE `astro_reports` DROP COLUMN `en_description`;--> statement-breakpoint
|
|
24
|
+
ALTER TABLE `astro_reports` DROP COLUMN `pt_description`;--> statement-breakpoint
|
|
25
|
+
ALTER TABLE `house_reports` ADD `description_template_id` text REFERENCES astro_description_templates(id);--> statement-breakpoint
|
|
26
|
+
CREATE INDEX `house_reports_description_template_idx` ON `house_reports` (`description_template_id`);--> statement-breakpoint
|
|
27
|
+
ALTER TABLE `house_reports` DROP COLUMN `en_description`;--> statement-breakpoint
|
|
28
|
+
ALTER TABLE `house_reports` DROP COLUMN `pt_description`;
|