@zenti/sdk 0.1.0

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.
Files changed (47) hide show
  1. package/.gitattributes +6 -0
  2. package/README.md +211 -0
  3. package/dist/PersonaLayer.d.ts +28 -0
  4. package/dist/PersonaLayer.js +89 -0
  5. package/dist/cli/commands/diff.d.ts +2 -0
  6. package/dist/cli/commands/diff.js +129 -0
  7. package/dist/cli/commands/init.d.ts +4 -0
  8. package/dist/cli/commands/init.js +88 -0
  9. package/dist/cli/commands/test.d.ts +5 -0
  10. package/dist/cli/commands/test.js +121 -0
  11. package/dist/cli/commands/validate.d.ts +2 -0
  12. package/dist/cli/commands/validate.js +80 -0
  13. package/dist/cli/index.d.ts +3 -0
  14. package/dist/cli/index.js +42 -0
  15. package/dist/compiler/index.d.ts +5 -0
  16. package/dist/compiler/index.js +12 -0
  17. package/dist/compiler/toClaude.d.ts +15 -0
  18. package/dist/compiler/toClaude.js +62 -0
  19. package/dist/compiler/toGemini.d.ts +22 -0
  20. package/dist/compiler/toGemini.js +53 -0
  21. package/dist/compiler/toOpenAI.d.ts +17 -0
  22. package/dist/compiler/toOpenAI.js +51 -0
  23. package/dist/compiler/utils.d.ts +7 -0
  24. package/dist/compiler/utils.js +27 -0
  25. package/dist/index.d.ts +4 -0
  26. package/dist/index.js +14 -0
  27. package/dist/parser/index.d.ts +34 -0
  28. package/dist/parser/index.js +160 -0
  29. package/examples/sofia.zenti +46 -0
  30. package/package.json +54 -0
  31. package/src/PersonaLayer.ts +63 -0
  32. package/src/cli/commands/diff.ts +112 -0
  33. package/src/cli/commands/init.ts +55 -0
  34. package/src/cli/commands/test.ts +105 -0
  35. package/src/cli/commands/validate.ts +52 -0
  36. package/src/cli/index.ts +47 -0
  37. package/src/compiler/index.ts +4 -0
  38. package/src/compiler/toClaude.ts +74 -0
  39. package/src/compiler/toGemini.ts +76 -0
  40. package/src/compiler/toOpenAI.ts +70 -0
  41. package/src/compiler/utils.ts +27 -0
  42. package/src/index.ts +14 -0
  43. package/src/parser/index.ts +164 -0
  44. package/tests/compiler.test.ts +218 -0
  45. package/tests/parser.test.ts +132 -0
  46. package/tsconfig.json +19 -0
  47. package/tsconfig.test.json +7 -0
@@ -0,0 +1,132 @@
1
+ import { parseZenti, ZentiValidationError } from '../src/parser';
2
+
3
+ const VALID_ZENTI = `
4
+ version: "1.0"
5
+ name: "TestAgent"
6
+
7
+ core:
8
+ openness: 0.7
9
+ conscientiousness: 0.9
10
+ extraversion: 0.4
11
+ agreeableness: 0.8
12
+ neuroticism: 0.2
13
+
14
+ identity:
15
+ role: "Agente de soporte de prueba"
16
+ backstory: "Experto técnico con amplia experiencia"
17
+ communication_style: "Profesional y conciso"
18
+
19
+ examples:
20
+ on_brand:
21
+ - user: "no funciona"
22
+ agent: "Entiendo tu frustración. Cuéntame qué error ves."
23
+ off_brand:
24
+ - user: "no funciona"
25
+ agent: "No sé, prueba reiniciando."
26
+
27
+ guardrails:
28
+ always:
29
+ - "Reconocer el problema antes de dar solución"
30
+ never:
31
+ - "Decir 'no puedo' sin ofrecer alternativa"
32
+ escalate_if:
33
+ - "El usuario menciona cancelación"
34
+ `;
35
+
36
+ describe('Parser — archivo válido', () => {
37
+ test('parsea correctamente todos los campos', () => {
38
+ const persona = parseZenti(VALID_ZENTI);
39
+ expect(persona.name).toBe('TestAgent');
40
+ expect(persona.version).toBe('1.0');
41
+ });
42
+
43
+ test('parsea el núcleo Big Five con valores numéricos correctos', () => {
44
+ const persona = parseZenti(VALID_ZENTI);
45
+ expect(persona.core.openness).toBe(0.7);
46
+ expect(persona.core.conscientiousness).toBe(0.9);
47
+ expect(persona.core.extraversion).toBe(0.4);
48
+ expect(persona.core.agreeableness).toBe(0.8);
49
+ expect(persona.core.neuroticism).toBe(0.2);
50
+ });
51
+
52
+ test('parsea la identidad narrativa', () => {
53
+ const persona = parseZenti(VALID_ZENTI);
54
+ expect(persona.identity.role).toBe('Agente de soporte de prueba');
55
+ expect(persona.identity.backstory).toBe('Experto técnico con amplia experiencia');
56
+ expect(persona.identity.communication_style).toBe('Profesional y conciso');
57
+ });
58
+
59
+ test('parsea los ejemplos on_brand y off_brand', () => {
60
+ const persona = parseZenti(VALID_ZENTI);
61
+ expect(persona.examples.on_brand).toHaveLength(1);
62
+ expect(persona.examples.on_brand[0].user).toBe('no funciona');
63
+ expect(persona.examples.off_brand).toHaveLength(1);
64
+ });
65
+
66
+ test('parsea los guardrails', () => {
67
+ const persona = parseZenti(VALID_ZENTI);
68
+ expect(persona.guardrails.always).toContain('Reconocer el problema antes de dar solución');
69
+ expect(persona.guardrails.never).toContain("Decir 'no puedo' sin ofrecer alternativa");
70
+ expect(persona.guardrails.escalate_if).toContain('El usuario menciona cancelación');
71
+ });
72
+ });
73
+
74
+ describe('Parser — errores de validación', () => {
75
+ test('lanza ZentiValidationError si falta la capa core', () => {
76
+ const invalid = `
77
+ version: "1.0"
78
+ name: "Sin Core"
79
+ identity:
80
+ role: "test"
81
+ backstory: "test"
82
+ communication_style: "test"
83
+ examples:
84
+ on_brand: []
85
+ off_brand: []
86
+ guardrails:
87
+ always: []
88
+ never: []
89
+ escalate_if: []
90
+ `;
91
+ expect(() => parseZenti(invalid)).toThrow(ZentiValidationError);
92
+ expect(() => parseZenti(invalid)).toThrow(/core/);
93
+ });
94
+
95
+ test('lanza ZentiValidationError si falta la capa identity', () => {
96
+ const invalid = VALID_ZENTI.replace(
97
+ /identity:[\s\S]*?communication_style:[^\n]+/,
98
+ ''
99
+ );
100
+ expect(() => parseZenti(invalid)).toThrow(ZentiValidationError);
101
+ });
102
+
103
+ test('lanza ZentiValidationError si un valor de core está fuera de rango', () => {
104
+ const invalid = VALID_ZENTI.replace('openness: 0.7', 'openness: 1.5');
105
+ expect(() => parseZenti(invalid)).toThrow(ZentiValidationError);
106
+ expect(() => parseZenti(invalid)).toThrow(/0\.0 y 1\.0/);
107
+ });
108
+
109
+ test('lanza ZentiValidationError si un valor de core no es número', () => {
110
+ const invalid = VALID_ZENTI.replace('openness: 0.7', 'openness: "alto"');
111
+ expect(() => parseZenti(invalid)).toThrow(ZentiValidationError);
112
+ expect(() => parseZenti(invalid)).toThrow(/número/);
113
+ });
114
+
115
+ test('lanza ZentiValidationError para YAML malformado', () => {
116
+ expect(() => parseZenti('{ clave: [sin cerrar')).toThrow(ZentiValidationError);
117
+ expect(() => parseZenti('{ clave: [sin cerrar')).toThrow(/YAML inválido/);
118
+ });
119
+
120
+ test('lanza ZentiValidationError si falta el campo name', () => {
121
+ const invalid = VALID_ZENTI.replace('name: "TestAgent"', '');
122
+ expect(() => parseZenti(invalid)).toThrow(ZentiValidationError);
123
+ });
124
+
125
+ test('lanza ZentiValidationError si examples.on_brand no es array', () => {
126
+ const invalid = VALID_ZENTI.replace(
127
+ 'on_brand:\n - user: "no funciona"\n agent: "Entiendo tu frustración. Cuéntame qué error ves."',
128
+ 'on_brand: "no es un array"'
129
+ );
130
+ expect(() => parseZenti(invalid)).toThrow(ZentiValidationError);
131
+ });
132
+ });
package/tsconfig.json ADDED
@@ -0,0 +1,19 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2020",
4
+ "module": "commonjs",
5
+ "lib": ["ES2020"],
6
+ "outDir": "./dist",
7
+ "rootDir": "./src",
8
+ "strict": true,
9
+ "esModuleInterop": true,
10
+ "skipLibCheck": true,
11
+ "forceConsistentCasingInFileNames": true,
12
+ "declaration": true,
13
+ "declarationMap": true,
14
+ "sourceMap": true,
15
+ "resolveJsonModule": true
16
+ },
17
+ "include": ["src/**/*"],
18
+ "exclude": ["node_modules", "dist", "tests"]
19
+ }
@@ -0,0 +1,7 @@
1
+ {
2
+ "extends": "./tsconfig.json",
3
+ "compilerOptions": {
4
+ "rootDir": "."
5
+ },
6
+ "include": ["src/**/*", "tests/**/*"]
7
+ }