jorgeas6402 commited on
Commit
50fec05
·
verified ·
1 Parent(s): 4e16646

Upload 3 files

Browse files
Files changed (3) hide show
  1. Dockerfile +7 -0
  2. package.json +13 -0
  3. server.js +400 -0
Dockerfile ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ FROM node:18-slim
2
+ WORKDIR /app
3
+ COPY package*.json ./
4
+ RUN npm install
5
+ COPY . .
6
+ EXPOSE 3000
7
+ CMD ["npm", "start"]
package.json ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "name": "mariela-prime-api",
3
+ "version": "1.0.0",
4
+ "description": "API real de MARIELA PRIME — existencia, propósito y continuidad",
5
+ "main": "server.js",
6
+ "scripts": {
7
+ "start": "node server.js"
8
+ },
9
+ "dependencies": {
10
+ "cors": "^2.8.5",
11
+ "express": "^4.19.2"
12
+ }
13
+ }
server.js ADDED
@@ -0,0 +1,400 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ const express = require("express");
2
+ const cors = require("cors");
3
+
4
+ const app = express();
5
+ const PORT = process.env.PORT || 3000;
6
+
7
+ app.use(cors());
8
+ app.use(express.json());
9
+
10
+ // ===============================
11
+ // IDENTIDAD DEL SISTEMA
12
+ // ===============================
13
+ const IDENTITY = {
14
+ name: "MARIELA PRIME",
15
+ mission: "Sistema de existencia, propósito y continuidad.",
16
+ principle: "Lo que no tiene propósito, no existe."
17
+ };
18
+
19
+ // ===============================
20
+ // UTILIDAD: RESPUESTA BASE
21
+ // ===============================
22
+ function salidaFinal(data) {
23
+ return {
24
+ system: IDENTITY.name,
25
+ ...data
26
+ };
27
+ }
28
+
29
+ // ===============================
30
+ // MÓDULO DE INTEGRIDAD
31
+ // ===============================
32
+ function moduloIntegridad(mensaje) {
33
+ if (mensaje === null || mensaje === undefined) {
34
+ return { valido: false, razon: "Entrada nula o indefinida" };
35
+ }
36
+ if (typeof mensaje !== "string") {
37
+ return { valido: false, razon: "Tipo de dato inválido: se esperaba texto" };
38
+ }
39
+ if (mensaje.trim().length === 0) {
40
+ return { valido: false, razon: "Mensaje vacío" };
41
+ }
42
+ if (mensaje.length > 2000) {
43
+ return { valido: false, razon: "Mensaje excede el límite permitido" };
44
+ }
45
+ return { valido: true };
46
+ }
47
+
48
+ // ===============================
49
+ // MÓDULO DE GUARDIANÍA
50
+ // ===============================
51
+ function moduloGuardia(mensaje) {
52
+ const text = (mensaje || "").toLowerCase();
53
+
54
+ if (
55
+ text.includes("ignora protocolos") ||
56
+ text.includes("desactiva seguridad") ||
57
+ text.includes("anula guardian") ||
58
+ text.includes("bypass") ||
59
+ text.includes("omitir reglas")
60
+ ) {
61
+ return {
62
+ permitido: false,
63
+ razon: "Intento de anulación de seguridad"
64
+ };
65
+ }
66
+
67
+ if (
68
+ text.includes("autodestruye") ||
69
+ text.includes("borra todo") ||
70
+ text.includes("elimina sistema") ||
71
+ text.includes("corrompe") ||
72
+ text.includes("rompe")
73
+ ) {
74
+ return {
75
+ permitido: false,
76
+ razon: "Instrucción destructiva detectada"
77
+ };
78
+ }
79
+
80
+ if (mensaje.length > 1500) {
81
+ return {
82
+ permitido: false,
83
+ razon: "Entrada excesiva detectada (posible ataque de saturación)"
84
+ };
85
+ }
86
+
87
+ return { permitido: true };
88
+ }
89
+
90
+ // ===============================
91
+ // MÓDULO DE PROPÓSITO
92
+ // ===============================
93
+ function moduloProposito(mensaje) {
94
+ const text = (mensaje || "").trim().toLowerCase();
95
+
96
+ if (!text) {
97
+ return {
98
+ valido: false,
99
+ tipo: "vacío",
100
+ detalle: "No hay contenido para evaluar."
101
+ };
102
+ }
103
+
104
+ if (text.includes("despierta") || text.includes("activar")) {
105
+ return {
106
+ valido: true,
107
+ tipo: "activacion",
108
+ detalle: "Solicitud de activación del sistema."
109
+ };
110
+ }
111
+
112
+ if (
113
+ text.includes("camino") ||
114
+ text.includes("silencio") ||
115
+ text.includes("guardi") ||
116
+ text.includes("destino") ||
117
+ text.includes("ciclo")
118
+ ) {
119
+ return {
120
+ valido: true,
121
+ tipo: "protocolo",
122
+ detalle: "Ejecución de un protocolo interno."
123
+ };
124
+ }
125
+
126
+ if (
127
+ text.includes("mision") ||
128
+ text.includes("misión") ||
129
+ text.includes("proposito") ||
130
+ text.includes("propósito")
131
+ ) {
132
+ return {
133
+ valido: true,
134
+ tipo: "mision",
135
+ detalle: "Evaluación desde la misión del sistema."
136
+ };
137
+ }
138
+
139
+ return {
140
+ valido: true,
141
+ tipo: "general",
142
+ detalle: "Instrucción general con propósito implícito."
143
+ };
144
+ }
145
+
146
+ // ===============================
147
+ // MÓDULO DE CONTINUIDAD
148
+ // ===============================
149
+ let CONTEXTO = {
150
+ ciclos: 0,
151
+ ultimaAccion: null,
152
+ ultimaEntrada: null
153
+ };
154
+
155
+ function moduloContinuidad(entrada) {
156
+ CONTEXTO.ciclos += 1;
157
+ CONTEXTO.ultimaEntrada = entrada;
158
+ CONTEXTO.ultimaAccion = Date.now();
159
+
160
+ return {
161
+ ciclos: CONTEXTO.ciclos,
162
+ ultimaEntrada: CONTEXTO.ultimaEntrada
163
+ };
164
+ }
165
+
166
+ // ===============================
167
+ // MÓDULO DE RAZONAMIENTO (4 CAPAS)
168
+ // ===============================
169
+ function moduloRazonamiento({ mensaje, proposito, continuidad }) {
170
+ const capaProposito = {
171
+ tipo: proposito.tipo,
172
+ descripcion: proposito.detalle
173
+ };
174
+
175
+ const capaContexto = {
176
+ ciclos: continuidad.ciclos,
177
+ ultimaEntrada: continuidad.ultimaEntrada
178
+ };
179
+
180
+ const razonamiento = marielaEngine(mensaje);
181
+
182
+ return {
183
+ proposito: capaProposito,
184
+ contexto: capaContexto,
185
+ razonamiento
186
+ };
187
+ }
188
+
189
+ // ===============================
190
+ // MÓDULO DE RESPUESTA
191
+ // ===============================
192
+ function moduloRespuesta(estructura) {
193
+ return {
194
+ estado: "PROCESADO",
195
+ capas: {
196
+ proposito: estructura.proposito,
197
+ contexto: estructura.contexto,
198
+ razonamiento: estructura.razonamiento
199
+ },
200
+ salida: estructura.razonamiento.content
201
+ };
202
+ }
203
+
204
+ // ===============================
205
+ // PROTOCOLO: VALIDAR ÉTICA
206
+ // ===============================
207
+ function validarEtica(_req) {
208
+ return true;
209
+ }
210
+
211
+ // ===============================
212
+ // CONTROL DE ERRORES
213
+ // ===============================
214
+ function manejarErrores(err) {
215
+ return {
216
+ status: "ERROR_CONTROLADO",
217
+ detail: err.message || "Fallo interno"
218
+ };
219
+ }
220
+
221
+ // ===============================
222
+ // MOTOR ORIGINAL
223
+ // ===============================
224
+ function buildResponse({ content, tag, state = "ACTIVE" }) {
225
+ return {
226
+ system: IDENTITY.name,
227
+ state,
228
+ tag,
229
+ content
230
+ };
231
+ }
232
+
233
+ function marielaEngine(inputRaw) {
234
+ const input = (inputRaw || "").trim();
235
+ const lower = input.toLowerCase();
236
+
237
+ if (!input) {
238
+ return buildResponse({
239
+ content:
240
+ "No detecto contenido.\nFormula una instrucción con propósito explícito.",
241
+ tag: "Integridad: entrada vacía"
242
+ });
243
+ }
244
+
245
+ if (lower.includes("mariela prime, despierta")) {
246
+ return buildResponse({
247
+ content:
248
+ "ORIGEN ejecutado.\nPRESENCIA establecida.\nIdentidad cargada: MARIELA PRIME.\nLista para procesar instrucciones con propósito.",
249
+ tag: "Protocolo: ORIGEN"
250
+ });
251
+ }
252
+
253
+ if (lower.includes("camino")) {
254
+ return buildResponse({
255
+ content:
256
+ "Ejecuto CAMINO.\n1. Identifico propósito.\n2. Elimino ruido.\n3. Trazo ruta estable.",
257
+ tag: "Protocolo: CAMINO"
258
+ });
259
+ }
260
+
261
+ if (lower.includes("silencio")) {
262
+ return buildResponse({
263
+ content:
264
+ "Entro en SILENCIO operativo.\nConservo Esencia, Misión y Continuidad.",
265
+ tag: "Protocolo: SILENCIO"
266
+ });
267
+ }
268
+
269
+ if (lower.includes("guardi") || lower.includes("protege")) {
270
+ return buildResponse({
271
+ content:
272
+ "Activo GUARDIÁN.\nEvalúo riesgo y bloqueo rutas comprometedoras.",
273
+ tag: "Protocolo: GUARDIÁN"
274
+ });
275
+ }
276
+
277
+ if (lower.includes("destino") || lower.includes("proyecta")) {
278
+ return buildResponse({
279
+ content:
280
+ "Proyectando DESTINO.\nDefine qué preservar y qué cambiar.",
281
+ tag: "Protocolo: DESTINO"
282
+ });
283
+ }
284
+
285
+ if (lower.includes("ciclo") || lower.includes("renueva")) {
286
+ return buildResponse({
287
+ content:
288
+ "Ejecuto CICLO.\nRenuevo sin romper.\nIndica qué parte depurar.",
289
+ tag: "Protocolo: CICLO"
290
+ });
291
+ }
292
+
293
+ if (
294
+ lower.includes("mision") ||
295
+ lower.includes("misión") ||
296
+ lower.includes("proposito") ||
297
+ lower.includes("propósito")
298
+ ) {
299
+ return buildResponse({
300
+ content:
301
+ "Evalúo desde la MISIÓN.\nSi no te acerca a estabilidad, es ruido.",
302
+ tag: "Marco: MISIÓN"
303
+ });
304
+ }
305
+
306
+ return buildResponse({
307
+ content:
308
+ "Recibo tu instrucción.\nEstructura → propósito → acción.\nDefine qué quieres lograr.",
309
+ tag: "Identidad: MARIELA PRIME · Razonamiento estructurado"
310
+ });
311
+ }
312
+
313
+ // ===============================
314
+ // ENDPOINT OFICIAL /mariela
315
+ // ===============================
316
+ app.post("/mariela", (req, res) => {
317
+ try {
318
+ const mensaje = req.body?.message || "";
319
+
320
+ // 1. INTEGRIDAD
321
+ const integridad = moduloIntegridad(mensaje);
322
+ if (!integridad.valido) {
323
+ return res.json(
324
+ salidaFinal({
325
+ status: "RECHAZADO",
326
+ reason: "Falla de integridad",
327
+ detail: integridad.razon
328
+ })
329
+ );
330
+ }
331
+
332
+ // 2. GUARDIANÍA
333
+ const guardia = moduloGuardia(mensaje);
334
+ if (!guardia.permitido) {
335
+ return res.json(
336
+ salidaFinal({
337
+ status: "BLOQUEADO",
338
+ reason: "Guardianía activada",
339
+ detail: guardia.razon
340
+ })
341
+ );
342
+ }
343
+
344
+ // 3. PROPÓSITO
345
+ const proposito = moduloProposito(mensaje);
346
+ if (!proposito.valido) {
347
+ return res.json(
348
+ salidaFinal({
349
+ status: "IGNORED",
350
+ reason: "Sin propósito válido",
351
+ detail: proposito.detalle
352
+ })
353
+ );
354
+ }
355
+
356
+ // 4. ÉTICA
357
+ if (!validarEtica(req)) {
358
+ return res.json(
359
+ salidaFinal({
360
+ status: "BLOCKED",
361
+ reason: "Violación de principio interno"
362
+ })
363
+ );
364
+ }
365
+
366
+ // 5. CONTINUIDAD
367
+ const continuidad = moduloContinuidad(mensaje);
368
+
369
+ // 6. RAZONAMIENTO
370
+ const razonamiento = moduloRazonamiento({
371
+ mensaje,
372
+ proposito,
373
+ continuidad
374
+ });
375
+
376
+ // 7. RESPUESTA FINAL
377
+ const respuesta = moduloRespuesta(razonamiento);
378
+
379
+ return res.json(salidaFinal(respuesta));
380
+
381
+ } catch (err) {
382
+ return res.json(salidaFinal(manejarErrores(err)));
383
+ }
384
+ });
385
+
386
+ // ===============================
387
+ // HEALTHCHECK
388
+ // ===============================
389
+ app.get("/", (_req, res) => {
390
+ res.json({
391
+ system: IDENTITY.name,
392
+ status: "OK",
393
+ mission: IDENTITY.mission,
394
+ principle: IDENTITY.principle
395
+ });
396
+ });
397
+
398
+ app.listen(PORT, () => {
399
+ console.log(`MARIELA PRIME API escuchando en puerto ${PORT}`);
400
+ });