@zodic/shared 0.0.409 → 0.0.413

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 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,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zodic/shared",
3
- "version": "0.0.409",
3
+ "version": "0.0.413",
4
4
  "module": "index.ts",
5
5
  "type": "module",
6
6
  "publishConfig": {
@@ -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<
@@ -568,7 +568,7 @@ export type UserConceptData = {
568
568
  content: any[]; // From conceptsData.content (text, JSON-stringified array, parsed)
569
569
  images: {
570
570
  post: any[]; // From conceptsData.postImages (text, JSON-stringified array, parsed)
571
- framed: string[]; // From conceptsData.framedImages (url text)
571
+ framed: string[]; // From conceptsData.framedImages (url text)
572
572
  reel: any[]; // From conceptsData.reelImages (text, JSON-stringified array, parsed)
573
573
  };
574
574
  combinationString: string; // e.g., "sagittarius-aquarius-libra"
@@ -663,3 +663,84 @@ export interface ProductLabels {
663
663
  };
664
664
  }
665
665
 
666
+ // types/astro-engine.ts
667
+ export interface AstroEnginePoint {
668
+ name: string;
669
+ type: 'planet' | 'karmic_point' | 'arabic_part' | 'key_point';
670
+ sign: string;
671
+ full_degree: number;
672
+ norm_degree: number;
673
+ house: number;
674
+ speed: number;
675
+ is_retro: boolean;
676
+ }
677
+
678
+ export interface AstroEngineHouse {
679
+ house: number;
680
+ sign: string;
681
+ degree: number;
682
+ }
683
+
684
+ export interface AstroEngineAspect {
685
+ aspecting_planet: string;
686
+ aspected_planet: string;
687
+ type: string;
688
+ orb: number;
689
+ diff: number;
690
+ }
691
+
692
+ // Novos tipos para suportar a estrutura "features"
693
+ export interface AstroEngineStatItem {
694
+ name: string;
695
+ percentage: number;
696
+ }
697
+
698
+ export interface AstroEngineFeatures {
699
+ moon_phase: {
700
+ moon_phase_id: number;
701
+ moon_phase_name: string;
702
+ name: string; // slug, ex: "new_moon"
703
+ };
704
+ hemisphere: {
705
+ north_south: { id: number };
706
+ east_west: { id: number };
707
+ };
708
+ elements: {
709
+ elements: AstroEngineStatItem[];
710
+ dominant_element_id: number;
711
+ };
712
+ modes: {
713
+ modes: AstroEngineStatItem[];
714
+ dominant_mode_id: number;
715
+ };
716
+ }
717
+
718
+ // Novo tipo para o AstroDraw
719
+ export interface AstroEngineWheelData {
720
+ planets: Record<string, number[]>; // Ex: { "Sun": [120.5] }
721
+ cusps: number[];
722
+ }
723
+
724
+ // Root Response
725
+ export interface AstroEngineResponse {
726
+ // 'meta' foi removido e substituído por 'features' e props na raiz
727
+ features: AstroEngineFeatures;
728
+
729
+ is_diurnal: boolean;
730
+
731
+ wheel_data: AstroEngineWheelData;
732
+ wheel_svg: string | null; // Mantemos opcional caso volte a usar no futuro
733
+
734
+ points: Record<string, AstroEnginePoint>;
735
+ houses: AstroEngineHouse[];
736
+ aspects: AstroEngineAspect[];
737
+ }
738
+
739
+ // Input payload expected by the Python Container
740
+ export interface AstroEngineInput {
741
+ date: string; // "YYYY/MM/DD"
742
+ time: string; // "HH:MM" (UTC)
743
+ lat: number;
744
+ lon: number;
745
+ generate_wheel: boolean;
746
+ }