beddel 0.1.0 → 0.2.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 (63) hide show
  1. package/CHANGELOG.md +58 -0
  2. package/LICENSE +21 -0
  3. package/README.md +446 -192
  4. package/dist/agents/agentRegistry.d.ts +26 -1
  5. package/dist/agents/agentRegistry.d.ts.map +1 -1
  6. package/dist/agents/agentRegistry.js +180 -1
  7. package/dist/agents/agentRegistry.js.map +1 -1
  8. package/dist/runtime/declarativeAgentRuntime.d.ts +4 -0
  9. package/dist/runtime/declarativeAgentRuntime.d.ts.map +1 -1
  10. package/dist/runtime/declarativeAgentRuntime.js +43 -0
  11. package/dist/runtime/declarativeAgentRuntime.js.map +1 -1
  12. package/dist/runtime/schemaCompiler.js +5 -4
  13. package/dist/runtime/schemaCompiler.js.map +1 -1
  14. package/package.json +6 -3
  15. package/src/agents/agentRegistry.ts +172 -2
  16. package/src/runtime/declarativeAgentRuntime.ts +71 -13
  17. package/src/runtime/schemaCompiler.ts +5 -5
  18. package/dist/agents/formatter-agent.d.ts +0 -10
  19. package/dist/agents/formatter-agent.d.ts.map +0 -1
  20. package/dist/agents/formatter-agent.js +0 -49
  21. package/dist/agents/formatter-agent.js.map +0 -1
  22. package/dist/agents/genkit-agent.d.ts +0 -12
  23. package/dist/agents/genkit-agent.d.ts.map +0 -1
  24. package/dist/agents/genkit-agent.js +0 -119
  25. package/dist/agents/genkit-agent.js.map +0 -1
  26. package/dist/agents/i18n-messages.d.ts +0 -17
  27. package/dist/agents/i18n-messages.d.ts.map +0 -1
  28. package/dist/agents/i18n-messages.js +0 -92
  29. package/dist/agents/i18n-messages.js.map +0 -1
  30. package/dist/agents/index.d.ts +0 -10
  31. package/dist/agents/index.d.ts.map +0 -1
  32. package/dist/agents/index.js +0 -26
  33. package/dist/agents/index.js.map +0 -1
  34. package/dist/agents/pipeline.d.ts +0 -15
  35. package/dist/agents/pipeline.d.ts.map +0 -1
  36. package/dist/agents/pipeline.js +0 -45
  37. package/dist/agents/pipeline.js.map +0 -1
  38. package/dist/agents/schema-factory.d.ts +0 -40
  39. package/dist/agents/schema-factory.d.ts.map +0 -1
  40. package/dist/agents/schema-factory.js +0 -121
  41. package/dist/agents/schema-factory.js.map +0 -1
  42. package/dist/agents/translation-validators.d.ts +0 -26
  43. package/dist/agents/translation-validators.d.ts.map +0 -1
  44. package/dist/agents/translation-validators.js +0 -77
  45. package/dist/agents/translation-validators.js.map +0 -1
  46. package/dist/agents/translator-agents.d.ts +0 -184
  47. package/dist/agents/translator-agents.d.ts.map +0 -1
  48. package/dist/agents/translator-agents.js +0 -613
  49. package/dist/agents/translator-agents.js.map +0 -1
  50. package/dist/agents/types/translation.types.d.ts +0 -100
  51. package/dist/agents/types/translation.types.d.ts.map +0 -1
  52. package/dist/agents/types/translation.types.js +0 -3
  53. package/dist/agents/types/translation.types.js.map +0 -1
  54. package/dist/agents/validator-agent.d.ts +0 -42
  55. package/dist/agents/validator-agent.d.ts.map +0 -1
  56. package/dist/agents/validator-agent.js +0 -122
  57. package/dist/agents/validator-agent.js.map +0 -1
  58. package/dist/security/test-security.d.ts +0 -22
  59. package/dist/security/test-security.d.ts.map +0 -1
  60. package/dist/security/test-security.js +0 -154
  61. package/dist/security/test-security.js.map +0 -1
  62. package/tools/seed.ts +0 -365
  63. package/tools/test-endpoints.ts +0 -174
@@ -3,7 +3,7 @@
3
3
  * Manages registration and execution of declarative YAML agents
4
4
  */
5
5
 
6
- import { existsSync, readFileSync } from "fs";
6
+ import { existsSync, readFileSync, readdirSync, statSync } from "fs";
7
7
  import { join } from "path";
8
8
  import { declarativeInterpreter } from "../runtime/declarativeAgentRuntime";
9
9
  import { ExecutionContext } from "../types/executionContext";
@@ -23,19 +23,35 @@ export interface AgentRegistration {
23
23
  */
24
24
  export class AgentRegistry {
25
25
  private readonly agents: Map<string, AgentRegistration> = new Map();
26
+ private readonly customFunctions: Map<string, Function> = new Map();
26
27
 
27
28
  constructor() {
28
29
  // Register built-in agents on initialization
29
30
  this.registerBuiltinAgents();
31
+
32
+ // Automatically load custom agents if running in Node.js environment
33
+ // This runs asynchronously in the background
34
+ if (typeof process !== 'undefined' && typeof process.cwd === 'function') {
35
+ this.loadCustomAgents().catch((error) => {
36
+ // Silently fail if custom agents can't be loaded
37
+ // This allows the registry to work even without custom agents
38
+ console.error('Failed to load custom agents during initialization:', error);
39
+ });
40
+ }
30
41
  }
31
42
 
32
43
  /**
33
44
  * Register an agent
34
45
  */
35
- public registerAgent(agent: AgentRegistration): void {
46
+ public registerAgent(agent: AgentRegistration, allowOverwrite = false): void {
36
47
  // Validate agent
37
48
  this.validateAgent(agent);
38
49
 
50
+ // Check if agent already exists
51
+ if (this.agents.has(agent.name) && allowOverwrite) {
52
+ console.warn(`⚠️ Overwriting existing agent: ${agent.name}`);
53
+ }
54
+
39
55
  // Register the agent
40
56
  this.agents.set(agent.name, agent);
41
57
  console.log(`Agent registered: ${agent.name} (${agent.protocol})`);
@@ -81,6 +97,108 @@ export class AgentRegistry {
81
97
  return Array.from(this.agents.values());
82
98
  }
83
99
 
100
+ /**
101
+ * Load custom agents from a specified directory
102
+ * @param customAgentsPath - Optional path to custom agents directory. Defaults to process.cwd()/agents
103
+ */
104
+ public async loadCustomAgents(customAgentsPath?: string): Promise<void> {
105
+ try {
106
+ // Determine the agents directory path
107
+ const agentsPath = customAgentsPath || join(process.cwd(), "agents");
108
+
109
+ // Check if directory exists
110
+ if (!existsSync(agentsPath)) {
111
+ console.log(`No custom agents directory found at: ${agentsPath}`);
112
+ return;
113
+ }
114
+
115
+ console.log(`🔍 Loading custom agents from: ${agentsPath}`);
116
+
117
+ // Discover all YAML files in the agents directory
118
+ const agentFiles = this.discoverCustomAgentFiles(agentsPath);
119
+
120
+ if (agentFiles.length === 0) {
121
+ console.log(`No custom agent YAML files found in: ${agentsPath}`);
122
+ }
123
+
124
+ // Register each custom agent
125
+ let successCount = 0;
126
+ for (const yamlPath of agentFiles) {
127
+ try {
128
+ this.registerCustomAgent(yamlPath);
129
+ successCount++;
130
+ } catch (error) {
131
+ console.error(`Failed to register custom agent from ${yamlPath}:`, error);
132
+ }
133
+ }
134
+
135
+ if (agentFiles.length > 0) {
136
+ console.log(`✅ Successfully loaded ${successCount}/${agentFiles.length} custom agents`);
137
+ }
138
+
139
+ // Load TypeScript implementations
140
+ await this.loadCustomFunctions(agentsPath);
141
+ } catch (error) {
142
+ console.error("Failed to load custom agents:", error);
143
+ }
144
+ }
145
+
146
+ /**
147
+ * Register a custom agent from a YAML file
148
+ */
149
+ private registerCustomAgent(yamlPath: string): void {
150
+ // Read YAML file
151
+ const yamlContent = readFileSync(yamlPath, "utf-8");
152
+
153
+ // Parse agent metadata
154
+ const agent = this.parseAgentYaml(yamlContent);
155
+
156
+ // Determine agent name from metadata or filename
157
+ const agentName = agent.metadata.route
158
+ ? agent.metadata.route.replace("/agents/", "") + ".execute"
159
+ : agent.agent.id + ".execute";
160
+
161
+ // Register the agent (allow overwriting built-ins)
162
+ this.registerAgent(
163
+ {
164
+ id: agent.agent.id,
165
+ name: agentName,
166
+ description: agent.metadata.description,
167
+ protocol: agent.agent.protocol,
168
+ route: agent.metadata.route || `/agents/${agent.agent.id}`,
169
+ requiredProps: agent.schema.required || ["gemini_api_key"],
170
+ yamlContent,
171
+ },
172
+ true // Allow overwriting
173
+ );
174
+ }
175
+
176
+ /**
177
+ * Discover all YAML files in the custom agents directory
178
+ */
179
+ private discoverCustomAgentFiles(agentsPath: string): string[] {
180
+ const yamlFiles: string[] = [];
181
+
182
+ const scanDirectory = (dirPath: string) => {
183
+ const entries = readdirSync(dirPath);
184
+
185
+ for (const entry of entries) {
186
+ const fullPath = join(dirPath, entry);
187
+ const stat = statSync(fullPath);
188
+
189
+ if (stat.isDirectory()) {
190
+ // Recursively scan subdirectories
191
+ scanDirectory(fullPath);
192
+ } else if (stat.isFile() && (entry.endsWith(".yaml") || entry.endsWith(".yml"))) {
193
+ yamlFiles.push(fullPath);
194
+ }
195
+ }
196
+ };
197
+
198
+ scanDirectory(agentsPath);
199
+ return yamlFiles;
200
+ }
201
+
84
202
  /**
85
203
  * Register built-in agents
86
204
  */
@@ -264,6 +382,58 @@ export class AgentRegistry {
264
382
  )}`
265
383
  );
266
384
  }
385
+
386
+ /**
387
+ * Load custom TypeScript function implementations from /agents directory
388
+ * @param agentsPath - Path to the agents directory
389
+ */
390
+ private async loadCustomFunctions(agentsPath: string): Promise<void> {
391
+ try {
392
+ const files = readdirSync(agentsPath);
393
+ let functionCount = 0;
394
+
395
+ for (const file of files) {
396
+ if (file.endsWith(".ts")) {
397
+ const modulePath = join(agentsPath, file);
398
+ try {
399
+ // Dynamic import of the custom agent module
400
+ const module = await import(modulePath);
401
+
402
+ // Register all exported functions with a namespaced key
403
+ // e.g., "my-agent/myFunction"
404
+ Object.keys(module).forEach((funcName) => {
405
+ if (typeof module[funcName] === "function") {
406
+ const key = `${file.replace(".ts", "")}/${funcName}`;
407
+ this.customFunctions.set(key, module[funcName]);
408
+ functionCount++;
409
+ console.log(`📦 Registered custom function: ${key}`);
410
+ }
411
+ });
412
+ } catch (err) {
413
+ console.error(
414
+ `Failed to load custom agent implementation ${file}:`,
415
+ err
416
+ );
417
+ }
418
+ }
419
+ }
420
+
421
+ if (functionCount > 0) {
422
+ console.log(`✅ Successfully loaded ${functionCount} custom function(s)`);
423
+ }
424
+ } catch (error) {
425
+ console.error("Failed to load custom functions:", error);
426
+ }
427
+ }
428
+
429
+ /**
430
+ * Get a custom function by its namespaced key
431
+ * @param name - Function name in format "agent-name/functionName"
432
+ * @returns The registered function or undefined
433
+ */
434
+ public getCustomFunction(name: string): Function | undefined {
435
+ return this.customFunctions.get(name);
436
+ }
267
437
  }
268
438
 
269
439
  // Singleton instance
@@ -8,6 +8,7 @@ import { experimental_generateImage, generateText } from "ai";
8
8
  import { createGoogleGenerativeAI } from "@ai-sdk/google";
9
9
  import { type ZodTypeAny } from "zod";
10
10
  import { ExecutionContext } from "../types/executionContext";
11
+ import { agentRegistry } from "../agents/agentRegistry";
11
12
  import {
12
13
  DeclarativeSchemaCompiler,
13
14
  DeclarativeSchemaValidationError,
@@ -263,6 +264,8 @@ export class DeclarativeAgentInterpreter {
263
264
  return this.executeGenkitTranslation(step, variables, options);
264
265
  case "genkit-image":
265
266
  return this.executeGenkitImage(step, variables, options);
267
+ case "custom-action":
268
+ return this.executeCustomAction(step, variables, options);
266
269
  default:
267
270
  throw new Error(`Unsupported workflow step type: ${step.type}`);
268
271
  }
@@ -421,7 +424,7 @@ export class DeclarativeAgentInterpreter {
421
424
 
422
425
  const promptTemplate =
423
426
  typeof step.action?.promptTemplate === "string" &&
424
- step.action.promptTemplate.trim().length > 0
427
+ step.action.promptTemplate.trim().length > 0
425
428
  ? step.action.promptTemplate
426
429
  : "Gere uma imagem detalhada no estilo {{estilo}} baseada na descrição: {{descricao}}";
427
430
 
@@ -455,6 +458,62 @@ export class DeclarativeAgentInterpreter {
455
458
  return imageResult;
456
459
  }
457
460
 
461
+ /**
462
+ * Execute custom action backed by TypeScript implementation
463
+ */
464
+ private async executeCustomAction(
465
+ step: any,
466
+ variables: Map<string, any>,
467
+ options: YamlAgentInterpreterOptions
468
+ ): Promise<any> {
469
+ const functionName = step.action?.function;
470
+ if (!functionName) {
471
+ throw new Error("Missing 'function' in custom-action");
472
+ }
473
+
474
+ options.context.log(`Custom action: Looking up function '${functionName}'`);
475
+
476
+ // Retrieve Code Implementation
477
+ const customFunc = agentRegistry.getCustomFunction(functionName);
478
+ if (!customFunc) {
479
+ throw new Error(
480
+ `Custom function '${functionName}' not found in registry. ` +
481
+ `Make sure the corresponding .ts file is in the /agents directory.`
482
+ );
483
+ }
484
+
485
+ // Prepare Arguments
486
+ const args = {
487
+ input: options.input,
488
+ variables: Object.fromEntries(variables),
489
+ action: step.action,
490
+ context: options.context,
491
+ };
492
+
493
+ options.context.log(`Custom action: Executing function '${functionName}'`);
494
+
495
+ // Execute Code
496
+ try {
497
+ const result = await customFunc(args);
498
+
499
+ // Save Result
500
+ if (step.action.result) {
501
+ variables.set(step.action.result, result);
502
+ options.context.log(
503
+ `Custom action: Saved result to variable '${step.action.result}'`
504
+ );
505
+ }
506
+
507
+ return result;
508
+ } catch (e) {
509
+ const errorMessage = e instanceof Error ? e.message : String(e);
510
+ options.context.log(`Custom action execution failed: ${errorMessage}`);
511
+ options.context.setError(errorMessage);
512
+ throw new Error(`Custom action execution failed: ${errorMessage}`);
513
+ }
514
+ }
515
+
516
+
458
517
  /**
459
518
  * Evaluate value expression
460
519
  */
@@ -594,8 +653,7 @@ export class DeclarativeAgentInterpreter {
594
653
 
595
654
  try {
596
655
  context.log(
597
- `Invoking Gemini Flash text helper (temperature=${temperature}, maxTokens=${
598
- typeof maxTokens === "number" ? maxTokens : "provider-default"
656
+ `Invoking Gemini Flash text helper (temperature=${temperature}, maxTokens=${typeof maxTokens === "number" ? maxTokens : "provider-default"
599
657
  })`
600
658
  );
601
659
  const generationOptions: Record<string, any> = {
@@ -611,11 +669,11 @@ export class DeclarativeAgentInterpreter {
611
669
  );
612
670
  const contentText = content
613
671
  ? content
614
- .map((part: any) =>
615
- typeof part?.text === "string" ? part.text : ""
616
- )
617
- .join(" ")
618
- .trim()
672
+ .map((part: any) =>
673
+ typeof part?.text === "string" ? part.text : ""
674
+ )
675
+ .join(" ")
676
+ .trim()
619
677
  : "";
620
678
  const finalText = (text || "").trim() || contentText || "";
621
679
  if (!finalText) {
@@ -721,11 +779,11 @@ Texto:
721
779
 
722
780
  const contentText = content
723
781
  ? content
724
- .map((part: any) =>
725
- typeof part?.text === "string" ? part.text : ""
726
- )
727
- .join(" ")
728
- .trim()
782
+ .map((part: any) =>
783
+ typeof part?.text === "string" ? part.text : ""
784
+ )
785
+ .join(" ")
786
+ .trim()
729
787
  : "";
730
788
  const translatedText = (text || "").trim() || contentText || "";
731
789
  if (!translatedText) {
@@ -133,14 +133,14 @@ export class DeclarativeSchemaCompiler {
133
133
  : childSchema.optional();
134
134
  }
135
135
 
136
- let objectSchema = z.object(shape);
136
+ const objectSchema = z.object(shape);
137
137
  if (definition.additionalProperties) {
138
- objectSchema = objectSchema.catchall(z.any());
138
+ // Allow additional properties
139
+ return objectSchema.passthrough() as ZodTypeAny;
139
140
  } else {
140
- objectSchema = objectSchema.strict();
141
+ // Reject additional properties (default behavior for strict validation)
142
+ return objectSchema.strict() as ZodTypeAny;
141
143
  }
142
-
143
- return objectSchema;
144
144
  }
145
145
 
146
146
  private buildArraySchema(
@@ -1,10 +0,0 @@
1
- import { TranslationResponse } from "./types/translation.types";
2
- /**
3
- * FormatterAgent para formatação e validação de saída
4
- */
5
- export default class FormatterAgent {
6
- private static readonly OUTPUT_SCHEMA;
7
- static formatOutput(data: TranslationResponse): TranslationResponse;
8
- }
9
- export { FormatterAgent };
10
- //# sourceMappingURL=formatter-agent.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"formatter-agent.d.ts","sourceRoot":"","sources":["../../src/agents/formatter-agent.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAE,MAAM,2BAA2B,CAAC;AAEhE;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,cAAc;IACjC,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,aAAa,CAQlC;IAEH,MAAM,CAAC,YAAY,CAAC,IAAI,EAAE,mBAAmB,GAAG,mBAAmB;CA+BpE;AAGD,OAAO,EAAE,cAAc,EAAE,CAAC"}
@@ -1,49 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.FormatterAgent = void 0;
4
- const zod_1 = require("zod");
5
- /**
6
- * FormatterAgent para formatação e validação de saída
7
- */
8
- class FormatterAgent {
9
- static formatOutput(data) {
10
- try {
11
- // Validação contra schema de saída
12
- const validated = this.OUTPUT_SCHEMA.parse(data);
13
- // Enriquecimento dos metadados
14
- const metadadosEnriquecidos = {
15
- ...validated.metadados,
16
- idiomas_suportados: validated.metadados.idiomas_suportados || [
17
- "pt",
18
- "en",
19
- "es",
20
- "fr",
21
- ],
22
- timestamp: new Date().toISOString(),
23
- versao_agent: "1.0.0",
24
- };
25
- return {
26
- texto_traduzido: validated.texto_traduzido,
27
- metadados: metadadosEnriquecidos,
28
- };
29
- }
30
- catch (error) {
31
- if (error instanceof zod_1.z.ZodError) {
32
- throw new Error(`Formato de saída inválido: ${error.issues[0]?.message}`);
33
- }
34
- throw error;
35
- }
36
- }
37
- }
38
- exports.FormatterAgent = FormatterAgent;
39
- FormatterAgent.OUTPUT_SCHEMA = zod_1.z.object({
40
- texto_traduzido: zod_1.z.string(),
41
- metadados: zod_1.z.object({
42
- modelo_utilizado: zod_1.z.string(),
43
- tempo_processamento: zod_1.z.number().min(0),
44
- confianca: zod_1.z.number().min(0).max(1),
45
- idiomas_suportados: zod_1.z.array(zod_1.z.string()).optional(),
46
- }),
47
- });
48
- exports.default = FormatterAgent;
49
- //# sourceMappingURL=formatter-agent.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"formatter-agent.js","sourceRoot":"","sources":["../../src/agents/formatter-agent.ts"],"names":[],"mappings":";;;AAAA,6BAAwB;AAGxB;;GAEG;AACH,MAAqB,cAAc;IAWjC,MAAM,CAAC,YAAY,CAAC,IAAyB;QAC3C,IAAI,CAAC;YACH,mCAAmC;YACnC,MAAM,SAAS,GAAG,IAAI,CAAC,aAAa,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;YAEjD,+BAA+B;YAC/B,MAAM,qBAAqB,GAAG;gBAC5B,GAAG,SAAS,CAAC,SAAS;gBACtB,kBAAkB,EAAE,SAAS,CAAC,SAAS,CAAC,kBAAkB,IAAI;oBAC5D,IAAI;oBACJ,IAAI;oBACJ,IAAI;oBACJ,IAAI;iBACL;gBACD,SAAS,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;gBACnC,YAAY,EAAE,OAAO;aACtB,CAAC;YAEF,OAAO;gBACL,eAAe,EAAE,SAAS,CAAC,eAAe;gBAC1C,SAAS,EAAE,qBAAqB;aACjC,CAAC;QACJ,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,IAAI,KAAK,YAAY,OAAC,CAAC,QAAQ,EAAE,CAAC;gBAChC,MAAM,IAAI,KAAK,CACb,8BAA+B,KAAa,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,CAClE,CAAC;YACJ,CAAC;YACD,MAAM,KAAK,CAAC;QACd,CAAC;IACH,CAAC;;AAIM,wCAAc;AA5CG,4BAAa,GAAG,OAAC,CAAC,MAAM,CAAC;IAC/C,eAAe,EAAE,OAAC,CAAC,MAAM,EAAE;IAC3B,SAAS,EAAE,OAAC,CAAC,MAAM,CAAC;QAClB,gBAAgB,EAAE,OAAC,CAAC,MAAM,EAAE;QAC5B,mBAAmB,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;QACtC,SAAS,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;QACnC,kBAAkB,EAAE,OAAC,CAAC,KAAK,CAAC,OAAC,CAAC,MAAM,EAAE,CAAC,CAAC,QAAQ,EAAE;KACnD,CAAC;CACH,CAAC,CAAC;kBATgB,cAAc"}
@@ -1,12 +0,0 @@
1
- import { TranslationRequest, TranslationResponse } from "./types/translation.types";
2
- /**
3
- * GenkitAgent parametrizado para integração com Genkit
4
- */
5
- export default class GenkitAgent {
6
- private static readonly IDIOMAS_SUPORTADOS;
7
- static processResource(resource: string, params: TranslationRequest): Promise<TranslationResponse>;
8
- private static handleTranslation;
9
- private static processBasicTranslation;
10
- }
11
- export { GenkitAgent };
12
- //# sourceMappingURL=genkit-agent.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"genkit-agent.d.ts","sourceRoot":"","sources":["../../src/agents/genkit-agent.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,kBAAkB,EAClB,mBAAmB,EACpB,MAAM,2BAA2B,CAAC;AAInC;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,WAAW;IAC9B,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,kBAAkB,CAA4B;WAEzD,eAAe,CAC1B,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,kBAAkB,GACzB,OAAO,CAAC,mBAAmB,CAAC;mBAeV,iBAAiB;IA+CtC,OAAO,CAAC,MAAM,CAAC,uBAAuB;CA0DvC;AAGD,OAAO,EAAE,WAAW,EAAE,CAAC"}
@@ -1,119 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.GenkitAgent = void 0;
7
- const validator_agent_1 = __importDefault(require("./validator-agent"));
8
- const validator_agent_2 = require("./validator-agent");
9
- /**
10
- * GenkitAgent parametrizado para integração com Genkit
11
- */
12
- class GenkitAgent {
13
- static async processResource(resource, params) {
14
- // Validação via validator-agent
15
- const validated = validator_agent_1.default.validateInput(validator_agent_2.translatorSchema, params);
16
- // Processamento baseado no recurso
17
- if (resource === "translate") {
18
- return this.handleTranslation(validated);
19
- }
20
- throw new Error(`Recurso não suportado: ${resource}`);
21
- }
22
- static async handleTranslation(request) {
23
- const startTime = Date.now();
24
- try {
25
- // Integração com Genkit (simulada - retorna JSON com 'translator: true')
26
- // TODO: Implementar chamada HTTP real ao endpoint interno do Genkit
27
- const genkitResponse = { translator: true };
28
- if (!genkitResponse.translator) {
29
- throw new Error("Falha na integração com Genkit");
30
- }
31
- // Cache TTL 3600s - simulação apenas com comentários
32
- // TODO: Implementar cache com TTL 3600s quando o sistema real for criado
33
- // Fallback entre modelos - preparação para implementação futura
34
- // TODO: Adicionar lógica de fallback quando múltiplos modelos estiverem disponíveis
35
- const textoTradu = this.processBasicTranslation(request);
36
- const tempoProcessamento = Date.now() - startTime;
37
- return {
38
- texto_traduzido: textoTradu,
39
- metadados: {
40
- modelo_utilizado: "beddel-fallback-translator",
41
- tempo_processamento: tempoProcessamento,
42
- confianca: 0.8,
43
- idiomas_suportados: this.IDIOMAS_SUPORTADOS,
44
- },
45
- };
46
- }
47
- catch (error) {
48
- const tempoProcessamento = Date.now() - startTime;
49
- console.error("Erro no GenkitAgent:", error);
50
- return {
51
- texto_traduzido: request.texto,
52
- metadados: {
53
- modelo_utilizado: "beddel-error-fallback",
54
- tempo_processamento: tempoProcessamento,
55
- confianca: 0.0,
56
- idiomas_suportados: this.IDIOMAS_SUPORTADOS,
57
- },
58
- };
59
- }
60
- }
61
- static processBasicTranslation(request) {
62
- // Implementação simples de fallback para prova de conceito
63
- const traducoes = new Map([
64
- [
65
- "pt",
66
- {
67
- olá: "hello",
68
- mundo: "world",
69
- "bom dia": "good morning",
70
- "boa tarde": "good afternoon",
71
- "boa noite": "good evening",
72
- },
73
- ],
74
- [
75
- "en",
76
- {
77
- hello: "olá",
78
- world: "mundo",
79
- "good morning": "bom dia",
80
- "good afternoon": "boa tarde",
81
- "good evening": "boa noite",
82
- },
83
- ],
84
- [
85
- "es",
86
- {
87
- hola: "hello",
88
- mundo: "world",
89
- },
90
- ],
91
- [
92
- "fr",
93
- {
94
- bonjour: "hello",
95
- monde: "world",
96
- },
97
- ],
98
- ]);
99
- if (request.idioma_origem === request.idioma_destino) {
100
- return request.texto;
101
- }
102
- const mapaTraducao = traducoes.get(request.idioma_origem);
103
- if (!mapaTraducao) {
104
- return request.texto;
105
- }
106
- let textoProcessado = request.texto;
107
- if (mapaTraducao) {
108
- Object.entries(mapaTraducao).forEach(([de, para]) => {
109
- const regex = new RegExp(de, "gi");
110
- textoProcessado = textoProcessado.replace(regex, para);
111
- });
112
- }
113
- return textoProcessado;
114
- }
115
- }
116
- exports.GenkitAgent = GenkitAgent;
117
- GenkitAgent.IDIOMAS_SUPORTADOS = ["pt", "en", "es", "fr"];
118
- exports.default = GenkitAgent;
119
- //# sourceMappingURL=genkit-agent.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file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AE,CAAC;YAClB,OAAO,OAAO,CAAC,KAAK,CAAC;QACvB,CAAC;QAED,IAAI,eAAe,GAAG,OAAO,CAAC,KAAK,CAAC;QACpC,IAAI,YAAY,EAAE,CAAC;YACjB,MAAM,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE,IAAI,CAAC,EAAE,EAAE;gBAClD,MAAM,KAAK,GAAG,IAAI,MAAM,CAAC,EAAE,EAAE,IAAI,CAAC,CAAC;gBACnC,eAAe,GAAG,eAAe,CAAC,OAAO,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;YACzD,CAAC,CAAC,CAAC;QACL,CAAC;QAED,OAAO,eAAe,CAAC;IACzB,CAAC;;AAIM,kCAAW;AAhIM,8BAAkB,GAAG,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;kBADnD,WAAW"}
@@ -1,17 +0,0 @@
1
- import { ValidationError } from "./types/translation.types";
2
- /**
3
- * Suporte de internacionalização para mensagens de erro
4
- */
5
- export default class I18nValidatorMessages {
6
- private static messages;
7
- /**
8
- * Obtém mensagem de erro localizada
9
- */
10
- static getLocalizedMessage(errorCode: string, language?: string): string;
11
- /**
12
- * Localiza erro de validação
13
- */
14
- static localizeValidationError(error: ValidationError, language?: string): ValidationError;
15
- }
16
- export { I18nValidatorMessages };
17
- //# sourceMappingURL=i18n-messages.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"i18n-messages.d.ts","sourceRoot":"","sources":["../../src/agents/i18n-messages.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;AAE5D;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,qBAAqB;IACxC,OAAO,CAAC,MAAM,CAAC,QAAQ,CA6DrB;IAEF;;OAEG;IACH,MAAM,CAAC,mBAAmB,CACxB,SAAS,EAAE,MAAM,EACjB,QAAQ,GAAE,MAAa,GACtB,MAAM;IAMT;;OAEG;IACH,MAAM,CAAC,uBAAuB,CAC5B,KAAK,EAAE,eAAe,EACtB,QAAQ,GAAE,MAAa,GACtB,eAAe;CAanB;AAGD,OAAO,EAAE,qBAAqB,EAAE,CAAC"}