@zodic/shared 0.0.408 → 0.0.412
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/api/index.ts +40 -0
- package/app/services/ConceptService.ts +57 -55
- package/package.json +1 -1
- package/types/scopes/cloudflare.ts +3 -0
- package/types/scopes/generic.ts +44 -0
package/app/api/index.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import OpenAI from 'openai';
|
|
2
2
|
import {
|
|
3
|
+
AstroEngineInput,
|
|
4
|
+
AstroEngineResponse,
|
|
3
5
|
BackendBindings,
|
|
4
6
|
BatchInputItem,
|
|
5
7
|
ChatGPTBatchResponse,
|
|
@@ -639,6 +641,44 @@ export const Api = (env: BackendBindings) => ({
|
|
|
639
641
|
},
|
|
640
642
|
},
|
|
641
643
|
|
|
644
|
+
callAstroEngine: {
|
|
645
|
+
calculateFullChart: async (payload: AstroEngineInput): Promise<AstroEngineResponse> => {
|
|
646
|
+
// Verifica se o binding existe (segurança para não quebrar em dev local se não tiver configurado)
|
|
647
|
+
if (!env.ASTRO_API) {
|
|
648
|
+
console.error("❌ ASTRO_API binding não encontrado via Service Binding");
|
|
649
|
+
throw new Error("Configuração de ambiente inválida: ASTRO_API ausente");
|
|
650
|
+
}
|
|
651
|
+
|
|
652
|
+
console.log(`🌌 [ENGINE] Chamando Python Container via Service Binding`);
|
|
653
|
+
|
|
654
|
+
try {
|
|
655
|
+
// AQUI ESTÁ A DIFERENÇA: Usamos o fetch DO BINDING, não o global.
|
|
656
|
+
// O hostname 'http://astro-engine' é ignorado pelo binding, só o path importa.
|
|
657
|
+
const response = await env.ASTRO_API.fetch('http://astro-engine/calculate-full-chart', {
|
|
658
|
+
method: 'POST',
|
|
659
|
+
headers: {
|
|
660
|
+
'Content-Type': 'application/json',
|
|
661
|
+
// Não precisa de Authorization header pois é comunicação interna segura
|
|
662
|
+
},
|
|
663
|
+
body: JSON.stringify(payload),
|
|
664
|
+
});
|
|
665
|
+
|
|
666
|
+
if (!response.ok) {
|
|
667
|
+
const errorText = await response.text();
|
|
668
|
+
console.error(`❌ [ENGINE ERROR] Status: ${response.status} - ${errorText}`);
|
|
669
|
+
throw new Error(`Erro no motor astrológico: ${response.status}`);
|
|
670
|
+
}
|
|
671
|
+
|
|
672
|
+
// O Python retorna exatamente o JSON que definimos
|
|
673
|
+
return (await response.json()) as AstroEngineResponse;
|
|
674
|
+
|
|
675
|
+
} catch (err: any) {
|
|
676
|
+
console.error('❌ [ENGINE FATAL] Falha ao conectar no Container Python:', err.message);
|
|
677
|
+
throw err;
|
|
678
|
+
}
|
|
679
|
+
},
|
|
680
|
+
},
|
|
681
|
+
|
|
642
682
|
callTimezone: async ({
|
|
643
683
|
lat,
|
|
644
684
|
lon,
|
|
@@ -1,8 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
KVNamespaceListKey,
|
|
3
|
-
KVNamespaceListResult,
|
|
4
|
-
} from '@cloudflare/workers-types';
|
|
5
|
-
import { and, eq, inArray, isNull, sql } from 'drizzle-orm';
|
|
1
|
+
import { and, eq, inArray, isNull } from 'drizzle-orm';
|
|
6
2
|
import { drizzle } from 'drizzle-orm/d1';
|
|
7
3
|
import { inject, injectable } from 'inversify';
|
|
8
4
|
import 'reflect-metadata';
|
|
@@ -27,14 +23,9 @@ import {
|
|
|
27
23
|
ControlNetConfig,
|
|
28
24
|
DescriptionTemplateRow,
|
|
29
25
|
} from '../../types';
|
|
30
|
-
import {
|
|
31
|
-
KVConcept,
|
|
32
|
-
sizes,
|
|
33
|
-
StructuredConceptContent,
|
|
34
|
-
} from '../../types/scopes/legacy';
|
|
26
|
+
import { sizes, StructuredConceptContent } from '../../types/scopes/legacy';
|
|
35
27
|
import { astroPrompts } from '../../utils/astroPrompts';
|
|
36
28
|
import { leonardoInitImages } from '../../utils/initImages';
|
|
37
|
-
import { buildConceptKVKey } from '../../utils/KVKeysBuilders';
|
|
38
29
|
import { AppContext } from '../base/AppContext';
|
|
39
30
|
|
|
40
31
|
@injectable()
|
|
@@ -902,7 +893,6 @@ export class ConceptService {
|
|
|
902
893
|
* Fetch and initialize a KVConcept object if not present.
|
|
903
894
|
*/
|
|
904
895
|
|
|
905
|
-
|
|
906
896
|
async generateAstroReportContent(
|
|
907
897
|
params:
|
|
908
898
|
| AstroReportParams
|
|
@@ -1662,7 +1652,7 @@ export class ConceptService {
|
|
|
1662
1652
|
|
|
1663
1653
|
async queueUserConcepts(userId: string): Promise<void> {
|
|
1664
1654
|
console.log(
|
|
1665
|
-
`[${new Date().toISOString()}] 🔧 Starting queueing of user concepts for user ${userId}`
|
|
1655
|
+
`[${new Date().toISOString()}] 🔧 Starting queueing of user concepts data for user ${userId}`
|
|
1666
1656
|
);
|
|
1667
1657
|
|
|
1668
1658
|
const lang = await this.getLang(userId);
|
|
@@ -1671,7 +1661,7 @@ export class ConceptService {
|
|
|
1671
1661
|
);
|
|
1672
1662
|
|
|
1673
1663
|
const db = this.context.drizzle();
|
|
1674
|
-
const {
|
|
1664
|
+
const { conceptsData } = schema;
|
|
1675
1665
|
|
|
1676
1666
|
// Fetch all available concepts
|
|
1677
1667
|
const concepts = await this.getAllConcepts();
|
|
@@ -1726,52 +1716,55 @@ export class ConceptService {
|
|
|
1726
1716
|
`[${new Date().toISOString()}] 🔗 Generated combination string for ${conceptSlug}: ${combinationString}`
|
|
1727
1717
|
);
|
|
1728
1718
|
|
|
1729
|
-
//
|
|
1730
|
-
const
|
|
1731
|
-
|
|
1732
|
-
|
|
1733
|
-
|
|
1734
|
-
|
|
1735
|
-
|
|
1736
|
-
|
|
1737
|
-
|
|
1738
|
-
|
|
1739
|
-
|
|
1740
|
-
|
|
1741
|
-
const existingUserConcept = await db
|
|
1742
|
-
.select({ conceptCombinationId: userConcepts.conceptCombinationId })
|
|
1743
|
-
.from(userConcepts)
|
|
1719
|
+
// Check conceptData completion
|
|
1720
|
+
const [conceptDataEntry] = await db
|
|
1721
|
+
.select({
|
|
1722
|
+
name: conceptsData.name,
|
|
1723
|
+
description: conceptsData.description,
|
|
1724
|
+
content: conceptsData.content,
|
|
1725
|
+
poem: conceptsData.poem,
|
|
1726
|
+
postImages: conceptsData.postImages,
|
|
1727
|
+
framedImages: conceptsData.framedImages,
|
|
1728
|
+
reelImages: conceptsData.reelImages,
|
|
1729
|
+
})
|
|
1730
|
+
.from(conceptsData)
|
|
1744
1731
|
.where(
|
|
1745
1732
|
and(
|
|
1746
|
-
eq(
|
|
1747
|
-
eq(
|
|
1733
|
+
eq(conceptsData.conceptSlug, conceptSlug),
|
|
1734
|
+
eq(conceptsData.combination, combinationString),
|
|
1735
|
+
eq(conceptsData.language, lang)
|
|
1748
1736
|
)
|
|
1749
1737
|
)
|
|
1750
1738
|
.limit(1)
|
|
1751
1739
|
.execute();
|
|
1752
1740
|
|
|
1753
|
-
|
|
1754
|
-
|
|
1755
|
-
|
|
1756
|
-
|
|
1757
|
-
|
|
1758
|
-
|
|
1759
|
-
|
|
1760
|
-
|
|
1761
|
-
|
|
1762
|
-
|
|
1763
|
-
updatedAt: sql`CURRENT_TIMESTAMP`,
|
|
1764
|
-
})
|
|
1765
|
-
.execute();
|
|
1766
|
-
console.log(
|
|
1767
|
-
`[${new Date().toISOString()}] ✅ Inserted new user concept with ID: ${userConceptId} for ${conceptSlug}`
|
|
1768
|
-
);
|
|
1769
|
-
} else {
|
|
1741
|
+
const isComplete = await this.checkConceptCompletion(
|
|
1742
|
+
conceptSlug as Concept,
|
|
1743
|
+
combinationString,
|
|
1744
|
+
lang
|
|
1745
|
+
);
|
|
1746
|
+
console.log(
|
|
1747
|
+
`[${new Date().toISOString()}] ✅ Checked completion status: ${isComplete} for ${conceptSlug}:${combinationString}`
|
|
1748
|
+
);
|
|
1749
|
+
|
|
1750
|
+
if (conceptDataEntry && isComplete) {
|
|
1770
1751
|
console.log(
|
|
1771
|
-
`[${new Date().toISOString()}]
|
|
1752
|
+
`[${new Date().toISOString()}] ✅ Concept data already complete for ${conceptSlug}:${combinationString}, skipping queue`
|
|
1772
1753
|
);
|
|
1754
|
+
continue; // Skip to the next concept if data is complete
|
|
1773
1755
|
}
|
|
1774
1756
|
|
|
1757
|
+
// Create or retrieve conceptCombination
|
|
1758
|
+
const conceptCombinationId = await this.getOrCreateConceptCombination(
|
|
1759
|
+
conceptId,
|
|
1760
|
+
combinationString,
|
|
1761
|
+
planets,
|
|
1762
|
+
userSigns
|
|
1763
|
+
);
|
|
1764
|
+
console.log(
|
|
1765
|
+
`[${new Date().toISOString()}] ✅ Created/Retrieved concept combination ID for ${conceptSlug}: ${conceptCombinationId}`
|
|
1766
|
+
);
|
|
1767
|
+
|
|
1775
1768
|
// Queue the generation
|
|
1776
1769
|
const queuePayload = {
|
|
1777
1770
|
userId,
|
|
@@ -1784,14 +1777,23 @@ export class ConceptService {
|
|
|
1784
1777
|
`[${new Date().toISOString()}] ✅ Queue Payload for ${conceptSlug}:`,
|
|
1785
1778
|
queuePayload
|
|
1786
1779
|
);
|
|
1787
|
-
|
|
1780
|
+
|
|
1781
|
+
try {
|
|
1782
|
+
await this.context.env.CONCEPT_GENERATION_QUEUE.send(queuePayload);
|
|
1783
|
+
console.log(
|
|
1784
|
+
`[${new Date().toISOString()}] ⏳ Queued concept generation for ${conceptSlug}:${combinationString}`
|
|
1785
|
+
);
|
|
1786
|
+
} catch (error) {
|
|
1787
|
+
console.log(
|
|
1788
|
+
`[${new Date().toISOString()}] Failed to queue concept generation for ${conceptSlug}:${combinationString}: Error ${
|
|
1789
|
+
(error as Error).message
|
|
1790
|
+
}`
|
|
1791
|
+
);
|
|
1792
|
+
}
|
|
1793
|
+
|
|
1788
1794
|
console.log(
|
|
1789
|
-
`[${new Date().toISOString()}]
|
|
1795
|
+
`[${new Date().toISOString()}] ✅ Completed queueing all concepts data for user ${userId}`
|
|
1790
1796
|
);
|
|
1791
1797
|
}
|
|
1792
|
-
|
|
1793
|
-
console.log(
|
|
1794
|
-
`[${new Date().toISOString()}] ✅ Completed queueing all concepts for user ${userId}`
|
|
1795
|
-
);
|
|
1796
1798
|
}
|
|
1797
1799
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
Ai,
|
|
3
3
|
D1Database,
|
|
4
|
+
Fetcher,
|
|
4
5
|
KVNamespace,
|
|
5
6
|
Queue,
|
|
6
7
|
R2Bucket,
|
|
@@ -59,6 +60,7 @@ export type CentralBindings = {
|
|
|
59
60
|
ASAAS_API_KEY: string;
|
|
60
61
|
|
|
61
62
|
API_BASE_URL: string;
|
|
63
|
+
ASTRO_API: Fetcher;
|
|
62
64
|
};
|
|
63
65
|
|
|
64
66
|
export type Variables = {
|
|
@@ -105,6 +107,7 @@ export type BackendBindings = Env &
|
|
|
105
107
|
| 'ASAAS_API_KEY'
|
|
106
108
|
| 'ASAAS_API_URL'
|
|
107
109
|
| 'PAYMENT_QUEUE'
|
|
110
|
+
| 'ASTRO_API'
|
|
108
111
|
>;
|
|
109
112
|
|
|
110
113
|
export type BackendCtx = Context<
|
package/types/scopes/generic.ts
CHANGED
|
@@ -663,3 +663,47 @@ export interface ProductLabels {
|
|
|
663
663
|
};
|
|
664
664
|
}
|
|
665
665
|
|
|
666
|
+
// types/astro-engine.ts
|
|
667
|
+
|
|
668
|
+
export interface AstroEnginePoint {
|
|
669
|
+
name: string;
|
|
670
|
+
type: 'planet' | 'karmic_point' | 'arabic_part' | 'key_point';
|
|
671
|
+
sign: string;
|
|
672
|
+
full_degree: number;
|
|
673
|
+
norm_degree: number;
|
|
674
|
+
house: number;
|
|
675
|
+
speed: number;
|
|
676
|
+
is_retro: boolean;
|
|
677
|
+
}
|
|
678
|
+
|
|
679
|
+
export interface AstroEngineHouse {
|
|
680
|
+
house: number;
|
|
681
|
+
sign: string;
|
|
682
|
+
degree: number;
|
|
683
|
+
}
|
|
684
|
+
|
|
685
|
+
export interface AstroEngineAspect {
|
|
686
|
+
aspecting_planet: string;
|
|
687
|
+
aspected_planet: string;
|
|
688
|
+
type: string;
|
|
689
|
+
orb: number;
|
|
690
|
+
diff: number;
|
|
691
|
+
}
|
|
692
|
+
|
|
693
|
+
export interface AstroEngineResponse {
|
|
694
|
+
meta: {
|
|
695
|
+
is_diurnal: boolean;
|
|
696
|
+
sun_house: number;
|
|
697
|
+
};
|
|
698
|
+
points: Record<string, AstroEnginePoint>;
|
|
699
|
+
houses: AstroEngineHouse[];
|
|
700
|
+
aspects: AstroEngineAspect[];
|
|
701
|
+
}
|
|
702
|
+
|
|
703
|
+
// Input payload expected by the Python Container
|
|
704
|
+
export interface AstroEngineInput {
|
|
705
|
+
date: string; // "YYYY/MM/DD"
|
|
706
|
+
time: string; // "HH:MM" (UTC)
|
|
707
|
+
lat: number;
|
|
708
|
+
lon: number;
|
|
709
|
+
}
|