beddel 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.
- package/README.md +297 -0
- package/dist/agents/agentRegistry.d.ts +68 -0
- package/dist/agents/agentRegistry.d.ts.map +1 -0
- package/dist/agents/agentRegistry.js +222 -0
- package/dist/agents/agentRegistry.js.map +1 -0
- package/dist/agents/formatter-agent.d.ts +10 -0
- package/dist/agents/formatter-agent.d.ts.map +1 -0
- package/dist/agents/formatter-agent.js +49 -0
- package/dist/agents/formatter-agent.js.map +1 -0
- package/dist/agents/genkit-agent.d.ts +12 -0
- package/dist/agents/genkit-agent.d.ts.map +1 -0
- package/dist/agents/genkit-agent.js +119 -0
- package/dist/agents/genkit-agent.js.map +1 -0
- package/dist/agents/i18n-messages.d.ts +17 -0
- package/dist/agents/i18n-messages.d.ts.map +1 -0
- package/dist/agents/i18n-messages.js +92 -0
- package/dist/agents/i18n-messages.js.map +1 -0
- package/dist/agents/index.d.ts +10 -0
- package/dist/agents/index.d.ts.map +1 -0
- package/dist/agents/index.js +26 -0
- package/dist/agents/index.js.map +1 -0
- package/dist/agents/pipeline.d.ts +15 -0
- package/dist/agents/pipeline.d.ts.map +1 -0
- package/dist/agents/pipeline.js +45 -0
- package/dist/agents/pipeline.js.map +1 -0
- package/dist/agents/schema-factory.d.ts +40 -0
- package/dist/agents/schema-factory.d.ts.map +1 -0
- package/dist/agents/schema-factory.js +121 -0
- package/dist/agents/schema-factory.js.map +1 -0
- package/dist/agents/translation-validators.d.ts +26 -0
- package/dist/agents/translation-validators.d.ts.map +1 -0
- package/dist/agents/translation-validators.js +77 -0
- package/dist/agents/translation-validators.js.map +1 -0
- package/dist/agents/translator-agents.d.ts +184 -0
- package/dist/agents/translator-agents.d.ts.map +1 -0
- package/dist/agents/translator-agents.js +613 -0
- package/dist/agents/translator-agents.js.map +1 -0
- package/dist/agents/types/translation.types.d.ts +100 -0
- package/dist/agents/types/translation.types.d.ts.map +1 -0
- package/dist/agents/types/translation.types.js +3 -0
- package/dist/agents/types/translation.types.js.map +1 -0
- package/dist/agents/validator-agent.d.ts +42 -0
- package/dist/agents/validator-agent.d.ts.map +1 -0
- package/dist/agents/validator-agent.js +122 -0
- package/dist/agents/validator-agent.js.map +1 -0
- package/dist/audit/auditTrail.d.ts +55 -0
- package/dist/audit/auditTrail.d.ts.map +1 -0
- package/dist/audit/auditTrail.js +93 -0
- package/dist/audit/auditTrail.js.map +1 -0
- package/dist/compliance/gdprEngine.d.ts +44 -0
- package/dist/compliance/gdprEngine.d.ts.map +1 -0
- package/dist/compliance/gdprEngine.js +178 -0
- package/dist/compliance/gdprEngine.js.map +1 -0
- package/dist/compliance/lgpdEngine.d.ts +51 -0
- package/dist/compliance/lgpdEngine.d.ts.map +1 -0
- package/dist/compliance/lgpdEngine.js +221 -0
- package/dist/compliance/lgpdEngine.js.map +1 -0
- package/dist/config.d.ts +78 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +77 -0
- package/dist/config.js.map +1 -0
- package/dist/errors.d.ts +17 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +40 -0
- package/dist/errors.js.map +1 -0
- package/dist/firebase/tenantManager.d.ts +84 -0
- package/dist/firebase/tenantManager.d.ts.map +1 -0
- package/dist/firebase/tenantManager.js +378 -0
- package/dist/firebase/tenantManager.js.map +1 -0
- package/dist/index.d.ts +36 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +118 -0
- package/dist/index.js.map +1 -0
- package/dist/integration/secure-yaml-runtime.d.ts +68 -0
- package/dist/integration/secure-yaml-runtime.d.ts.map +1 -0
- package/dist/integration/secure-yaml-runtime.js +245 -0
- package/dist/integration/secure-yaml-runtime.js.map +1 -0
- package/dist/parser/secure-yaml-parser.d.ts +62 -0
- package/dist/parser/secure-yaml-parser.d.ts.map +1 -0
- package/dist/parser/secure-yaml-parser.js +234 -0
- package/dist/parser/secure-yaml-parser.js.map +1 -0
- package/dist/performance/autoscaling.d.ts +100 -0
- package/dist/performance/autoscaling.d.ts.map +1 -0
- package/dist/performance/autoscaling.js +339 -0
- package/dist/performance/autoscaling.js.map +1 -0
- package/dist/performance/benchmark.d.ts +104 -0
- package/dist/performance/benchmark.d.ts.map +1 -0
- package/dist/performance/benchmark.js +514 -0
- package/dist/performance/benchmark.js.map +1 -0
- package/dist/performance/index.d.ts +14 -0
- package/dist/performance/index.d.ts.map +1 -0
- package/dist/performance/index.js +35 -0
- package/dist/performance/index.js.map +1 -0
- package/dist/performance/monitor.d.ts +126 -0
- package/dist/performance/monitor.d.ts.map +1 -0
- package/dist/performance/monitor.js +324 -0
- package/dist/performance/monitor.js.map +1 -0
- package/dist/performance/streaming.d.ts +82 -0
- package/dist/performance/streaming.d.ts.map +1 -0
- package/dist/performance/streaming.js +287 -0
- package/dist/performance/streaming.js.map +1 -0
- package/dist/runtime/audit.d.ts +240 -0
- package/dist/runtime/audit.d.ts.map +1 -0
- package/dist/runtime/audit.js +641 -0
- package/dist/runtime/audit.js.map +1 -0
- package/dist/runtime/declarativeAgentRuntime.d.ts +123 -0
- package/dist/runtime/declarativeAgentRuntime.d.ts.map +1 -0
- package/dist/runtime/declarativeAgentRuntime.js +576 -0
- package/dist/runtime/declarativeAgentRuntime.js.map +1 -0
- package/dist/runtime/isolatedRuntime.d.ts +119 -0
- package/dist/runtime/isolatedRuntime.d.ts.map +1 -0
- package/dist/runtime/isolatedRuntime.js +425 -0
- package/dist/runtime/isolatedRuntime.js.map +1 -0
- package/dist/runtime/schemaCompiler.d.ts +35 -0
- package/dist/runtime/schemaCompiler.d.ts.map +1 -0
- package/dist/runtime/schemaCompiler.js +151 -0
- package/dist/runtime/schemaCompiler.js.map +1 -0
- package/dist/runtime/simpleRuntime.d.ts +57 -0
- package/dist/runtime/simpleRuntime.d.ts.map +1 -0
- package/dist/runtime/simpleRuntime.js +187 -0
- package/dist/runtime/simpleRuntime.js.map +1 -0
- package/dist/security/dashboard.d.ts +89 -0
- package/dist/security/dashboard.d.ts.map +1 -0
- package/dist/security/dashboard.js +300 -0
- package/dist/security/dashboard.js.map +1 -0
- package/dist/security/hardening.d.ts +130 -0
- package/dist/security/hardening.d.ts.map +1 -0
- package/dist/security/hardening.js +414 -0
- package/dist/security/hardening.js.map +1 -0
- package/dist/security/index.d.ts +128 -0
- package/dist/security/index.d.ts.map +1 -0
- package/dist/security/index.js +353 -0
- package/dist/security/index.js.map +1 -0
- package/dist/security/monitor.d.ts +88 -0
- package/dist/security/monitor.d.ts.map +1 -0
- package/dist/security/monitor.js +356 -0
- package/dist/security/monitor.js.map +1 -0
- package/dist/security/scanner.d.ts +104 -0
- package/dist/security/scanner.d.ts.map +1 -0
- package/dist/security/scanner.js +298 -0
- package/dist/security/scanner.js.map +1 -0
- package/dist/security/score.d.ts +150 -0
- package/dist/security/score.d.ts.map +1 -0
- package/dist/security/score.js +983 -0
- package/dist/security/score.js.map +1 -0
- package/dist/security/test-security.d.ts +22 -0
- package/dist/security/test-security.d.ts.map +1 -0
- package/dist/security/test-security.js +154 -0
- package/dist/security/test-security.js.map +1 -0
- package/dist/security/threatDetector.d.ts +39 -0
- package/dist/security/threatDetector.d.ts.map +1 -0
- package/dist/security/threatDetector.js +354 -0
- package/dist/security/threatDetector.js.map +1 -0
- package/dist/security/validation.d.ts +69 -0
- package/dist/security/validation.d.ts.map +1 -0
- package/dist/security/validation.js +286 -0
- package/dist/security/validation.js.map +1 -0
- package/dist/server/api/clientsRoute.d.ts +9 -0
- package/dist/server/api/clientsRoute.d.ts.map +1 -0
- package/dist/server/api/clientsRoute.js +71 -0
- package/dist/server/api/clientsRoute.js.map +1 -0
- package/dist/server/api/endpointsRoute.d.ts +8 -0
- package/dist/server/api/endpointsRoute.d.ts.map +1 -0
- package/dist/server/api/endpointsRoute.js +76 -0
- package/dist/server/api/endpointsRoute.js.map +1 -0
- package/dist/server/api/graphql.d.ts +9 -0
- package/dist/server/api/graphql.d.ts.map +1 -0
- package/dist/server/api/graphql.js +180 -0
- package/dist/server/api/graphql.js.map +1 -0
- package/dist/server/errors.d.ts +19 -0
- package/dist/server/errors.d.ts.map +1 -0
- package/dist/server/errors.js +42 -0
- package/dist/server/errors.js.map +1 -0
- package/dist/server/index.d.ts +7 -0
- package/dist/server/index.d.ts.map +1 -0
- package/dist/server/index.js +24 -0
- package/dist/server/index.js.map +1 -0
- package/dist/server/kvStore.d.ts +27 -0
- package/dist/server/kvStore.d.ts.map +1 -0
- package/dist/server/kvStore.js +128 -0
- package/dist/server/kvStore.js.map +1 -0
- package/dist/server/runtimeSecurity.d.ts +28 -0
- package/dist/server/runtimeSecurity.d.ts.map +1 -0
- package/dist/server/runtimeSecurity.js +85 -0
- package/dist/server/runtimeSecurity.js.map +1 -0
- package/dist/server/types.d.ts +53 -0
- package/dist/server/types.d.ts.map +1 -0
- package/dist/server/types.js +8 -0
- package/dist/server/types.js.map +1 -0
- package/dist/types/executionContext.d.ts +16 -0
- package/dist/types/executionContext.d.ts.map +1 -0
- package/dist/types/executionContext.js +3 -0
- package/dist/types/executionContext.js.map +1 -0
- package/package.json +77 -0
- package/src/agents/agentRegistry.ts +272 -0
- package/src/agents/image-agent.yaml +86 -0
- package/src/agents/joker-agent.yaml +47 -0
- package/src/agents/translator-agent.yaml +80 -0
- package/src/audit/auditTrail.ts +134 -0
- package/src/compliance/gdprEngine.ts +209 -0
- package/src/compliance/lgpdEngine.ts +268 -0
- package/src/config.ts +179 -0
- package/src/errors.ts +35 -0
- package/src/firebase/tenantManager.ts +443 -0
- package/src/index.ts +125 -0
- package/src/integration/secure-yaml-runtime.ts +341 -0
- package/src/parser/secure-yaml-parser.ts +273 -0
- package/src/performance/autoscaling.ts +495 -0
- package/src/performance/benchmark.ts +644 -0
- package/src/performance/index.ts +34 -0
- package/src/performance/monitor.ts +469 -0
- package/src/performance/streaming.ts +317 -0
- package/src/runtime/audit.ts +907 -0
- package/src/runtime/declarativeAgentRuntime.ts +836 -0
- package/src/runtime/isolatedRuntime.ts +572 -0
- package/src/runtime/schemaCompiler.ts +228 -0
- package/src/runtime/simpleRuntime.ts +201 -0
- package/src/security/dashboard.ts +462 -0
- package/src/security/hardening.ts +560 -0
- package/src/security/index.ts +439 -0
- package/src/security/monitor.ts +490 -0
- package/src/security/scanner.ts +368 -0
- package/src/security/score.ts +1138 -0
- package/src/security/threatDetector.ts +481 -0
- package/src/security/validation.ts +365 -0
- package/src/server/api/clientsRoute.ts +92 -0
- package/src/server/api/endpointsRoute.ts +97 -0
- package/src/server/api/graphql.ts +249 -0
- package/src/server/errors.ts +38 -0
- package/src/server/index.ts +6 -0
- package/src/server/kvStore.ts +152 -0
- package/src/server/runtimeSecurity.ts +102 -0
- package/src/server/types.ts +60 -0
- package/src/types/executionContext.ts +16 -0
- package/tools/seed.ts +365 -0
- package/tools/test-endpoints.ts +174 -0
package/README.md
ADDED
|
@@ -0,0 +1,297 @@
|
|
|
1
|
+
# Beddel: Secure, Declarative, and Extensible Agent Runtimes
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/beddel)
|
|
4
|
+
[](https://github.com/botanarede/beddel-alpha/blob/main/LICENSE)
|
|
5
|
+
|
|
6
|
+
**Repos:** código-fonte em `https://github.com/botanarede/beddel-alpha` e app de exemplo Next.js em `https://github.com/botanarede/beddel-alpha-example`.
|
|
7
|
+
|
|
8
|
+
## Usage Exemplo
|
|
9
|
+
|
|
10
|
+
> Declaração YAML + interpretação segura para que quem visita o perfil do pacote no npm entenda o fluxo em poucos segundos.
|
|
11
|
+
|
|
12
|
+
```yaml
|
|
13
|
+
# joker-agent.yaml
|
|
14
|
+
agent:
|
|
15
|
+
id: joker
|
|
16
|
+
protocol: beddel-declarative-protocol/v2.0
|
|
17
|
+
metadata:
|
|
18
|
+
name: Joker Agent
|
|
19
|
+
schema:
|
|
20
|
+
input:
|
|
21
|
+
type: "object"
|
|
22
|
+
properties: {}
|
|
23
|
+
required: []
|
|
24
|
+
output:
|
|
25
|
+
type: "object"
|
|
26
|
+
properties:
|
|
27
|
+
response:
|
|
28
|
+
type: "string"
|
|
29
|
+
required: ["response"]
|
|
30
|
+
logic:
|
|
31
|
+
workflow:
|
|
32
|
+
- name: generate-joke
|
|
33
|
+
type: genkit-joke
|
|
34
|
+
action:
|
|
35
|
+
type: joke
|
|
36
|
+
prompt: "Conte uma piada curta e original que funcione para qualquer público."
|
|
37
|
+
result: jokerResult
|
|
38
|
+
|
|
39
|
+
- name: deliver-response
|
|
40
|
+
type: output-generator
|
|
41
|
+
action:
|
|
42
|
+
type: generate
|
|
43
|
+
output:
|
|
44
|
+
response: "$jokerResult.texto"
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
```typescript
|
|
48
|
+
import {
|
|
49
|
+
SecureYamlParser,
|
|
50
|
+
DeclarativeAgentInterpreter,
|
|
51
|
+
SecureYamlRuntime,
|
|
52
|
+
IsolatedRuntimeManager,
|
|
53
|
+
type ExecutionContext,
|
|
54
|
+
} from "beddel";
|
|
55
|
+
import { readFileSync } from "node:fs";
|
|
56
|
+
|
|
57
|
+
const yamlManifest = readFileSync("joker-agent.yaml", "utf8");
|
|
58
|
+
|
|
59
|
+
const parser = new SecureYamlParser({ filename: "joker-agent.yaml" });
|
|
60
|
+
const manifest = parser.parseSecure(yamlManifest); // FAILSAFE_SCHEMA + depth/size limits
|
|
61
|
+
|
|
62
|
+
const context: ExecutionContext = {
|
|
63
|
+
logs: [],
|
|
64
|
+
status: "running",
|
|
65
|
+
output: null,
|
|
66
|
+
log: console.log,
|
|
67
|
+
setOutput: (output) => (context.output = output),
|
|
68
|
+
setError: (err) => console.error(err),
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
const interpreter = new DeclarativeAgentInterpreter();
|
|
72
|
+
const agentResult = await interpreter.interpret({
|
|
73
|
+
yamlContent: yamlManifest,
|
|
74
|
+
input: {},
|
|
75
|
+
props: {
|
|
76
|
+
gemini_api_key: process.env.GEMINI_API_KEY ?? "",
|
|
77
|
+
},
|
|
78
|
+
context,
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
const secureRuntime = new SecureYamlRuntime(new IsolatedRuntimeManager());
|
|
82
|
+
const execution = await secureRuntime.parseYamlSecureRuntime(yamlManifest, {
|
|
83
|
+
tenantId: "tenant-42",
|
|
84
|
+
securityProfile: "tenant-isolated",
|
|
85
|
+
validateSecurity: true,
|
|
86
|
+
});
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
- `SecureYamlParser` garante o parsing estritamente FAILSAFE com validação de profundidade, tamanho e UTF-8.
|
|
90
|
+
- `DeclarativeAgentInterpreter` executa apenas steps declarativos (`output-generator`, `genkit-joke`, `genkit-translation`, `genkit-image`) e mantém toda a validação em Zod (sem `eval`/`Function`).
|
|
91
|
+
- `SecureYamlRuntime` conecta parser, scanner e `isolated-vm` para entregar auditoria, limites de tempo/memória e perfis multi-tenant.
|
|
92
|
+
|
|
93
|
+
Beddel is a security-first toolkit that combines:
|
|
94
|
+
|
|
95
|
+
- A hardened YAML parser that only exposes the YAML FAILSAFE schema.
|
|
96
|
+
- Multiple execution strategies powered by `isolated-vm`.
|
|
97
|
+
- Declarative agent utilities, compliance helpers, performance monitors, and Firebase multi-tenant orchestration.
|
|
98
|
+
|
|
99
|
+
### Declarative agents shipped with Gemini Flash helpers
|
|
100
|
+
|
|
101
|
+
The declarative runtime now exposes three Genkit-based helpers—`callGeminiFlashText`, `callGeminiFlashTranslation`, and `callGeminiFlashImage`—which proxy `generateText`/`generateImage` calls to `google("models/gemini-flash-latest")`. Each helper validates the presence of `props.gemini_api_key`, builds friendly prompts, and returns consistent metadata (`modelo_utilizado`, `tempo_processamento`, etc.).
|
|
102
|
+
|
|
103
|
+
| Agent | Method | Description | Inputs | Outputs | Required props |
|
|
104
|
+
| --- | --- | --- | --- | --- | --- |
|
|
105
|
+
| Joker Agent | `joker.execute` | Gera uma piada curta e original usando Gemini Flash. | — | `response` | `gemini_api_key` |
|
|
106
|
+
| Translator Agent | `translator.execute` | Traduz textos via Gemini Flash com Genkit. | `texto`, `idioma_origem`, `idioma_destino` | `texto_traduzido`, `metadados` | `gemini_api_key` |
|
|
107
|
+
| Image Generator Agent | `image.generate` | Cria imagens nos estilos `watercolor`, `neon` ou `sketch`. | `descricao`, `estilo`, `resolucao` | `image_url`, `image_base64`, `media_type`, `prompt_utilizado`, `metadados` | `gemini_api_key` |
|
|
108
|
+
|
|
109
|
+
> ⚠️ Todos os agentes embutidos dependem da prop `gemini_api_key`. Sem ela o runtime aborta a execução com uma mensagem amigável.
|
|
110
|
+
|
|
111
|
+
The code that backs this README lives under `packages/beddel/src` and is what the npm package exposes.
|
|
112
|
+
|
|
113
|
+
## Package map
|
|
114
|
+
|
|
115
|
+
| Capability | Entry point / module | Notes |
|
|
116
|
+
| --- | --- | --- |
|
|
117
|
+
| Secure YAML parsing | `SecureYamlParser` (`src/parser/secure-yaml-parser.ts`) | FAILSAFE schema, depth/size limits, UTF-8 validation, sync + async helpers. |
|
|
118
|
+
| Sandboxed execution | `IsolatedRuntimeManager`, `SimpleIsolatedRuntimeManager` (`src/runtime`) | Uses `isolated-vm` with configurable security profiles, pool management, metrics. |
|
|
119
|
+
| Declarative YAML interpretation | `DeclarativeAgentInterpreter`, `AgentRegistry` (`src/runtime/declarativeAgentRuntime.ts`, `src/agents/agentRegistry.ts`) | Executes YAML agents with variables plus `output-generator`, `genkit-joke`, `genkit-translation` e `genkit-image` steps (Gemini Flash). |
|
|
120
|
+
| Security posture | `SecurityScanner`, `ThreatDetectionEngine`, validation utilities (`src/security`) | Static scanning, scoring, and threat inference the rest of the package consumes. |
|
|
121
|
+
| Compliance & audit | `GDPRCompliance`, `LGPDCompliance`, `AuditTrail`, `AuditService` (`src/compliance`, `src/audit`, `src/runtime/audit.ts`) | Hash-based logging, anonymization helpers, compliance verification. |
|
|
122
|
+
| Performance & autoscaling | `PerformanceMonitor`, `AutoScaler`, benchmarking helpers (`src/performance`) | Track execution time/memory, raise violations, recommend scaling actions. |
|
|
123
|
+
| Firebase multi-tenancy | `MultiTenantFirebaseManager` (`src/firebase/tenantManager.ts`) | Per-tenant app bootstrap, isolation policies, audit logging hooks. |
|
|
124
|
+
|
|
125
|
+
Everything is re-exported via `src/index.ts`, so you can import from `beddel` directly.
|
|
126
|
+
|
|
127
|
+
## Installation
|
|
128
|
+
|
|
129
|
+
```bash
|
|
130
|
+
npm install beddel
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
Ensure Node.js 18+ (per `package.json`) and install optional peer dependencies you plan to use (e.g., `firebase-admin` is already included).
|
|
134
|
+
|
|
135
|
+
## Project-agnostic guarantees
|
|
136
|
+
|
|
137
|
+
- No upstream app files are required—the npm tarball only ships `dist/` and the audited TypeScript sources exported through `beddel`.
|
|
138
|
+
- `ExecutionContext` and every runtime type live inside the package, de-coupling consumers from any upstream monorepo or example app internals.
|
|
139
|
+
- No secrets, API tokens, or environment-specific constants are embedded in the code or build output; everything is configured via your own runtime props.
|
|
140
|
+
- Optional tools (Firebase, Upstash, benchmarking scripts) are defensive helpers; you decide which ones to instantiate depending on project size.
|
|
141
|
+
|
|
142
|
+
## Usage examples
|
|
143
|
+
|
|
144
|
+
### Parse YAML with strict fail-safes
|
|
145
|
+
|
|
146
|
+
```typescript
|
|
147
|
+
import { SecureYamlParser } from "beddel";
|
|
148
|
+
|
|
149
|
+
const parser = new SecureYamlParser({
|
|
150
|
+
maxDepth: 200,
|
|
151
|
+
filename: "agent-manifest",
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
const manifest = parser.parseSecure(`
|
|
155
|
+
agent:
|
|
156
|
+
id: joker
|
|
157
|
+
schema:
|
|
158
|
+
input: {}
|
|
159
|
+
output: {}
|
|
160
|
+
logic:
|
|
161
|
+
workflow:
|
|
162
|
+
- name: noop
|
|
163
|
+
type: output-generator
|
|
164
|
+
action:
|
|
165
|
+
type: generate
|
|
166
|
+
output:
|
|
167
|
+
response: "lol"
|
|
168
|
+
`);
|
|
169
|
+
|
|
170
|
+
console.log(manifest.agent.id); // joker
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
Behind the scenes, `SecureYamlParser` enforces depth, size, UTF-8, and allowed primitive types before returning the parsed object.
|
|
174
|
+
|
|
175
|
+
### Execute JavaScript in an isolate
|
|
176
|
+
|
|
177
|
+
```typescript
|
|
178
|
+
import { IsolatedRuntimeManager } from "beddel";
|
|
179
|
+
|
|
180
|
+
const runtimeManager = new IsolatedRuntimeManager();
|
|
181
|
+
|
|
182
|
+
const result = await runtimeManager.execute({
|
|
183
|
+
code: `
|
|
184
|
+
const secret = "sandboxed";
|
|
185
|
+
({ success: true, value: secret.length });
|
|
186
|
+
`,
|
|
187
|
+
securityProfile: "ultra-secure",
|
|
188
|
+
timeout: 2000,
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
if (!result.success) {
|
|
192
|
+
throw result.error;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
console.log(result.result); // { success: true, value: 9 }
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
The manager bootstraps `isolated-vm` contexts, strips dangerous globals (`require`, `eval`, timers), enforces memory/time limits, records metrics, and can emit audit/security signals.
|
|
199
|
+
|
|
200
|
+
### Interpret a declarative YAML agent
|
|
201
|
+
|
|
202
|
+
```typescript
|
|
203
|
+
import { DeclarativeAgentInterpreter } from "beddel";
|
|
204
|
+
import { readFileSync } from "node:fs";
|
|
205
|
+
import { join } from "node:path";
|
|
206
|
+
|
|
207
|
+
const interpreter = new DeclarativeAgentInterpreter();
|
|
208
|
+
const yamlContent = readFileSync(join(process.cwd(), "joker-agent.yaml"), "utf8");
|
|
209
|
+
|
|
210
|
+
const result = await interpreter.interpret({
|
|
211
|
+
yamlContent,
|
|
212
|
+
input: {},
|
|
213
|
+
props: {},
|
|
214
|
+
context: {
|
|
215
|
+
log: console.log,
|
|
216
|
+
setError: console.error,
|
|
217
|
+
},
|
|
218
|
+
});
|
|
219
|
+
|
|
220
|
+
console.log(result.response); // lol
|
|
221
|
+
```
|
|
222
|
+
|
|
223
|
+
Current interpreter capabilities:
|
|
224
|
+
|
|
225
|
+
- Validates protocol (`beddel-declarative-protocol/v2.0`), schema presence, workflow size.
|
|
226
|
+
- Supports string/number/boolean/object variables and literal/variable references.
|
|
227
|
+
- Executes `output-generator` workflow steps that map variables to response objects.
|
|
228
|
+
|
|
229
|
+
For projects that want auto-registration, instantiate `AgentRegistry` (bundled with the `joker` agent) and call `executeAgent("joker.execute", …)`.
|
|
230
|
+
|
|
231
|
+
### Automatic schema validation
|
|
232
|
+
|
|
233
|
+
Every declarative agent must now declare `schema.input` and `schema.output` blocks that map directly to Zod primitives (`string`, `number`, `boolean`), objects (with `properties` + `required` arrays), and arrays (via `items`). The runtime compiles those YAML definitions into Zod schemas through the `DeclarativeSchemaCompiler`, caches the result per manifest, and runs validation twice per execution:
|
|
234
|
+
|
|
235
|
+
- **Before workflow execution** – payloads that are missing required fields, contain unexpected properties (objects are `strict` by default), or provide the wrong primitive types raise a `DeclarativeSchemaValidationError` and call `ExecutionContext.setError`.
|
|
236
|
+
- **Before returning output** – the workflow result must match `schema.output`; mismatches are rejected, the error propagates through the same structured exception, and oversize payloads (>1 MB) are blocked.
|
|
237
|
+
|
|
238
|
+
Authors can opt into arrays by adding `type: "array"` + an `items` definition, mark optional fields by omitting them from `required`, and set `additionalProperties: true` only when extra keys should be allowed. Errors surface in GraphQL responses (and logs) as `Input validation failed: …` or `Output validation failed: …`, making it obvious which path failed.
|
|
239
|
+
|
|
240
|
+
### Parse + execute inside the secure runtime
|
|
241
|
+
|
|
242
|
+
Combine the parser, security scanner, and isolate manager through `SecureYamlRuntime`:
|
|
243
|
+
|
|
244
|
+
```typescript
|
|
245
|
+
import { SecureYamlRuntime, IsolatedRuntimeManager } from "beddel";
|
|
246
|
+
|
|
247
|
+
const runtime = new SecureYamlRuntime(new IsolatedRuntimeManager());
|
|
248
|
+
const { success, result } = await runtime.parseYamlSecureRuntime(someYamlString, {
|
|
249
|
+
tenantId: "tenant-123",
|
|
250
|
+
securityProfile: "tenant-isolated",
|
|
251
|
+
validateSecurity: true,
|
|
252
|
+
});
|
|
253
|
+
```
|
|
254
|
+
|
|
255
|
+
The helper performs pre-scan checks, runs within the requested profile, enforces performance targets, and produces audit hashes you can persist.
|
|
256
|
+
|
|
257
|
+
## Architectural reference
|
|
258
|
+
|
|
259
|
+
- `src/parser`: Secure YAML parsing primitives.
|
|
260
|
+
- `src/runtime`: `IsolatedRuntimeManager`, `SimpleIsolatedRuntimeManager`, auditing utilities, declarative interpreter, monitoring, and security hooks.
|
|
261
|
+
- `src/security`: Validation, scoring, threat detection, dashboards.
|
|
262
|
+
- `src/compliance`: GDPR/LGPD tooling, anonymization, export helpers.
|
|
263
|
+
- `src/performance`: Monitoring, autoscaling, streaming metrics.
|
|
264
|
+
- `src/firebase`: Tenant isolation via Firebase Admin SDK.
|
|
265
|
+
- `src/agents`: Registry helpers and sample `joker-agent.yaml`.
|
|
266
|
+
- `src/integration`: Glue code that wires parsing + runtime + scanner.
|
|
267
|
+
|
|
268
|
+
Every module is documented inline with TypeScript types to make IDE discovery straightforward.
|
|
269
|
+
|
|
270
|
+
## Development workflow
|
|
271
|
+
|
|
272
|
+
```bash
|
|
273
|
+
# Build the package
|
|
274
|
+
pnpm --filter beddel build
|
|
275
|
+
|
|
276
|
+
# Lint and test
|
|
277
|
+
pnpm --filter beddel lint
|
|
278
|
+
pnpm --filter beddel test
|
|
279
|
+
```
|
|
280
|
+
|
|
281
|
+
When contributing, keep README + `AGENTS.md` synchronized with any new exports or behavioral changes in `src`.
|
|
282
|
+
|
|
283
|
+
## Docs/beddel roadmap coverage
|
|
284
|
+
|
|
285
|
+
The product briefs under `docs/beddel` describe a richer future-state language/runtime. The current package intentionally ships a smaller, auditable subset. Notable gaps you will still find only in documentation:
|
|
286
|
+
|
|
287
|
+
- **Advanced declarative language constructs** (`map-filter-reduce` pipelines, state machines, rule engines, temporal conditions, and loop semantics) are not implemented yet—the interpreter only supports literal variables and `output-generator` steps.
|
|
288
|
+
- **Behavior marketplace & registry extensibility** (behaviors with versions, capabilities, restrictions, and monetization hooks) are not available. Only the bundled `joker` agent is registered by default.
|
|
289
|
+
- **Automatic behavioral integrations and external API pipelines** (`integrations`, `decisions`, `behaviors` blocks described in `docs/beddel/brief.md`) have no runtime support.
|
|
290
|
+
- **Marketplace/compliance automation flows** mentioned in the PRD (pre-built business behaviors, Firebase deployment recipes, global consent orchestration) are still roadmap items, even though compliance helpers exist as standalone utilities.
|
|
291
|
+
- **High-level orchestration features** like parallel execution controls, resource policies (per-step concurrency, retry semantics), and auto-generated documentation have not been wired into the runtime.
|
|
292
|
+
|
|
293
|
+
Use this section as a living checklist whenever you pull features from `docs/beddel` into the actual codebase.
|
|
294
|
+
|
|
295
|
+
## License
|
|
296
|
+
|
|
297
|
+
This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Agent Registry Service
|
|
3
|
+
* Manages registration and execution of declarative YAML agents
|
|
4
|
+
*/
|
|
5
|
+
import { ExecutionContext } from "../types/executionContext";
|
|
6
|
+
export interface AgentRegistration {
|
|
7
|
+
id: string;
|
|
8
|
+
name: string;
|
|
9
|
+
description: string;
|
|
10
|
+
protocol: string;
|
|
11
|
+
route: string;
|
|
12
|
+
requiredProps: string[];
|
|
13
|
+
yamlContent: string;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Agent Registry - Manages declarative agent registration and execution
|
|
17
|
+
*/
|
|
18
|
+
export declare class AgentRegistry {
|
|
19
|
+
private readonly agents;
|
|
20
|
+
constructor();
|
|
21
|
+
/**
|
|
22
|
+
* Register an agent
|
|
23
|
+
*/
|
|
24
|
+
registerAgent(agent: AgentRegistration): void;
|
|
25
|
+
/**
|
|
26
|
+
* Execute registered agent
|
|
27
|
+
*/
|
|
28
|
+
executeAgent(agentName: string, input: Record<string, any>, props: Record<string, string>, context: ExecutionContext): Promise<any>;
|
|
29
|
+
/**
|
|
30
|
+
* Get registered agent
|
|
31
|
+
*/
|
|
32
|
+
getAgent(agentName: string): AgentRegistration | undefined;
|
|
33
|
+
/**
|
|
34
|
+
* Get all registered agents
|
|
35
|
+
*/
|
|
36
|
+
getAllAgents(): AgentRegistration[];
|
|
37
|
+
/**
|
|
38
|
+
* Register built-in agents
|
|
39
|
+
*/
|
|
40
|
+
private registerBuiltinAgents;
|
|
41
|
+
/**
|
|
42
|
+
* Register Joker Agent
|
|
43
|
+
*/
|
|
44
|
+
private registerJokerAgent;
|
|
45
|
+
/**
|
|
46
|
+
* Register Translator Agent
|
|
47
|
+
*/
|
|
48
|
+
private registerTranslatorAgent;
|
|
49
|
+
/**
|
|
50
|
+
* Register Image Generator Agent
|
|
51
|
+
*/
|
|
52
|
+
private registerImageAgent;
|
|
53
|
+
/**
|
|
54
|
+
* Parse agent YAML content
|
|
55
|
+
*/
|
|
56
|
+
private parseAgentYaml;
|
|
57
|
+
/**
|
|
58
|
+
* Validate agent registration
|
|
59
|
+
*/
|
|
60
|
+
private validateAgent;
|
|
61
|
+
/**
|
|
62
|
+
* Resolve agent asset path when running in bundled runtimes
|
|
63
|
+
*/
|
|
64
|
+
private resolveAgentPath;
|
|
65
|
+
}
|
|
66
|
+
export declare const agentRegistry: AgentRegistry;
|
|
67
|
+
export default AgentRegistry;
|
|
68
|
+
//# sourceMappingURL=agentRegistry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agentRegistry.d.ts","sourceRoot":"","sources":["../../src/agents/agentRegistry.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAKH,OAAO,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAE7D,MAAM,WAAW,iBAAiB;IAChC,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;IACd,aAAa,EAAE,MAAM,EAAE,CAAC;IACxB,WAAW,EAAE,MAAM,CAAC;CACrB;AAED;;GAEG;AACH,qBAAa,aAAa;IACxB,OAAO,CAAC,QAAQ,CAAC,MAAM,CAA6C;;IAOpE;;OAEG;IACI,aAAa,CAAC,KAAK,EAAE,iBAAiB,GAAG,IAAI;IASpD;;OAEG;IACU,YAAY,CACvB,SAAS,EAAE,MAAM,EACjB,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAC1B,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EAC7B,OAAO,EAAE,gBAAgB,GACxB,OAAO,CAAC,GAAG,CAAC;IAkBf;;OAEG;IACI,QAAQ,CAAC,SAAS,EAAE,MAAM,GAAG,iBAAiB,GAAG,SAAS;IAIjE;;OAEG;IACI,YAAY,IAAI,iBAAiB,EAAE;IAI1C;;OAEG;IACH,OAAO,CAAC,qBAAqB;IAa7B;;OAEG;IACH,OAAO,CAAC,kBAAkB;IAwB1B;;OAEG;IACH,OAAO,CAAC,uBAAuB;IAqB/B;;OAEG;IACH,OAAO,CAAC,kBAAkB;IAqB1B;;OAEG;IACH,OAAO,CAAC,cAAc;IAmDtB;;OAEG;IACH,OAAO,CAAC,aAAa;IAcrB;;OAEG;IACH,OAAO,CAAC,gBAAgB;CAkBzB;AAGD,eAAO,MAAM,aAAa,eAAsB,CAAC;AAEjD,eAAe,aAAa,CAAC"}
|
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Agent Registry Service
|
|
4
|
+
* Manages registration and execution of declarative YAML agents
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.agentRegistry = exports.AgentRegistry = void 0;
|
|
8
|
+
const fs_1 = require("fs");
|
|
9
|
+
const path_1 = require("path");
|
|
10
|
+
const declarativeAgentRuntime_1 = require("../runtime/declarativeAgentRuntime");
|
|
11
|
+
/**
|
|
12
|
+
* Agent Registry - Manages declarative agent registration and execution
|
|
13
|
+
*/
|
|
14
|
+
class AgentRegistry {
|
|
15
|
+
constructor() {
|
|
16
|
+
this.agents = new Map();
|
|
17
|
+
// Register built-in agents on initialization
|
|
18
|
+
this.registerBuiltinAgents();
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Register an agent
|
|
22
|
+
*/
|
|
23
|
+
registerAgent(agent) {
|
|
24
|
+
// Validate agent
|
|
25
|
+
this.validateAgent(agent);
|
|
26
|
+
// Register the agent
|
|
27
|
+
this.agents.set(agent.name, agent);
|
|
28
|
+
console.log(`Agent registered: ${agent.name} (${agent.protocol})`);
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Execute registered agent
|
|
32
|
+
*/
|
|
33
|
+
async executeAgent(agentName, input, props, context) {
|
|
34
|
+
// Find agent
|
|
35
|
+
const agent = this.agents.get(agentName);
|
|
36
|
+
if (!agent) {
|
|
37
|
+
throw new Error(`Agent not found: ${agentName}`);
|
|
38
|
+
}
|
|
39
|
+
// Execute using declarative interpreter
|
|
40
|
+
const result = await declarativeAgentRuntime_1.declarativeInterpreter.interpret({
|
|
41
|
+
yamlContent: agent.yamlContent,
|
|
42
|
+
input,
|
|
43
|
+
props,
|
|
44
|
+
context,
|
|
45
|
+
});
|
|
46
|
+
return result;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Get registered agent
|
|
50
|
+
*/
|
|
51
|
+
getAgent(agentName) {
|
|
52
|
+
return this.agents.get(agentName);
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Get all registered agents
|
|
56
|
+
*/
|
|
57
|
+
getAllAgents() {
|
|
58
|
+
return Array.from(this.agents.values());
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Register built-in agents
|
|
62
|
+
*/
|
|
63
|
+
registerBuiltinAgents() {
|
|
64
|
+
try {
|
|
65
|
+
// Register Joker Agent
|
|
66
|
+
this.registerJokerAgent();
|
|
67
|
+
// Register Translator Agent
|
|
68
|
+
this.registerTranslatorAgent();
|
|
69
|
+
// Register Image Generator Agent
|
|
70
|
+
this.registerImageAgent();
|
|
71
|
+
}
|
|
72
|
+
catch (error) {
|
|
73
|
+
console.error("Failed to register built-in agents:", error);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Register Joker Agent
|
|
78
|
+
*/
|
|
79
|
+
registerJokerAgent() {
|
|
80
|
+
try {
|
|
81
|
+
// Get the Joker Agent YAML content
|
|
82
|
+
const jokerYamlPath = this.resolveAgentPath("joker-agent.yaml");
|
|
83
|
+
const yamlContent = (0, fs_1.readFileSync)(jokerYamlPath, "utf-8");
|
|
84
|
+
// Parse YAML to extract metadata
|
|
85
|
+
const agent = this.parseAgentYaml(yamlContent);
|
|
86
|
+
this.registerAgent({
|
|
87
|
+
id: agent.agent.id,
|
|
88
|
+
name: "joker.execute",
|
|
89
|
+
description: agent.metadata.description,
|
|
90
|
+
protocol: agent.agent.protocol,
|
|
91
|
+
route: agent.metadata.route || "/agents/joker",
|
|
92
|
+
requiredProps: ["gemini_api_key"],
|
|
93
|
+
yamlContent,
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
catch (error) {
|
|
97
|
+
console.error("Failed to register Joker Agent:", error);
|
|
98
|
+
throw error;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Register Translator Agent
|
|
103
|
+
*/
|
|
104
|
+
registerTranslatorAgent() {
|
|
105
|
+
try {
|
|
106
|
+
const translatorYamlPath = this.resolveAgentPath("translator-agent.yaml");
|
|
107
|
+
const yamlContent = (0, fs_1.readFileSync)(translatorYamlPath, "utf-8");
|
|
108
|
+
const agent = this.parseAgentYaml(yamlContent);
|
|
109
|
+
this.registerAgent({
|
|
110
|
+
id: agent.agent.id,
|
|
111
|
+
name: "translator.execute",
|
|
112
|
+
description: agent.metadata.description,
|
|
113
|
+
protocol: agent.agent.protocol,
|
|
114
|
+
route: agent.metadata.route || "/agents/translator",
|
|
115
|
+
requiredProps: ["gemini_api_key"],
|
|
116
|
+
yamlContent,
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
catch (error) {
|
|
120
|
+
console.error("Failed to register Translator Agent:", error);
|
|
121
|
+
throw error;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Register Image Generator Agent
|
|
126
|
+
*/
|
|
127
|
+
registerImageAgent() {
|
|
128
|
+
try {
|
|
129
|
+
const imageYamlPath = this.resolveAgentPath("image-agent.yaml");
|
|
130
|
+
const yamlContent = (0, fs_1.readFileSync)(imageYamlPath, "utf-8");
|
|
131
|
+
const agent = this.parseAgentYaml(yamlContent);
|
|
132
|
+
this.registerAgent({
|
|
133
|
+
id: agent.agent.id,
|
|
134
|
+
name: "image.generate",
|
|
135
|
+
description: agent.metadata.description,
|
|
136
|
+
protocol: agent.agent.protocol,
|
|
137
|
+
route: agent.metadata.route || "/agents/image",
|
|
138
|
+
requiredProps: ["gemini_api_key"],
|
|
139
|
+
yamlContent,
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
catch (error) {
|
|
143
|
+
console.error("Failed to register Image Agent:", error);
|
|
144
|
+
throw error;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Parse agent YAML content
|
|
149
|
+
*/
|
|
150
|
+
parseAgentYaml(yamlContent) {
|
|
151
|
+
// Simple validation - full parsing will be done by interpreter
|
|
152
|
+
if (!yamlContent.includes("agent:") || !yamlContent.includes("logic:")) {
|
|
153
|
+
throw new Error("Invalid agent YAML: missing required sections");
|
|
154
|
+
}
|
|
155
|
+
// Basic YAML parsing for metadata extraction
|
|
156
|
+
const lines = yamlContent.split("\n");
|
|
157
|
+
const metadata = {
|
|
158
|
+
agent: { id: "", protocol: "" },
|
|
159
|
+
metadata: { description: "", route: "" },
|
|
160
|
+
schema: { required: [] },
|
|
161
|
+
};
|
|
162
|
+
for (let i = 0; i < lines.length; i++) {
|
|
163
|
+
const line = lines[i].trim();
|
|
164
|
+
if (line.startsWith("id:") && metadata.agent.id === "") {
|
|
165
|
+
metadata.agent.id = line.split(":")[1].trim();
|
|
166
|
+
}
|
|
167
|
+
if (line.startsWith("protocol:") && metadata.agent.protocol === "") {
|
|
168
|
+
metadata.agent.protocol = line.split(":")[1].trim();
|
|
169
|
+
}
|
|
170
|
+
if (line.startsWith("description:") &&
|
|
171
|
+
metadata.metadata.description === "") {
|
|
172
|
+
metadata.metadata.description = line
|
|
173
|
+
.substring(line.indexOf(":") + 1)
|
|
174
|
+
.trim();
|
|
175
|
+
}
|
|
176
|
+
if (line.startsWith("route:") && metadata.metadata.route === "") {
|
|
177
|
+
metadata.metadata.route = line.split(":")[1].trim();
|
|
178
|
+
}
|
|
179
|
+
if (line.startsWith("required:") &&
|
|
180
|
+
metadata.schema.required.length === 0) {
|
|
181
|
+
// Parse required array
|
|
182
|
+
const requiredStr = line.substring(line.indexOf(":") + 1).trim();
|
|
183
|
+
metadata.schema.required = JSON.parse(requiredStr);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
return metadata;
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Validate agent registration
|
|
190
|
+
*/
|
|
191
|
+
validateAgent(agent) {
|
|
192
|
+
if (!agent.id || !agent.name || !agent.protocol) {
|
|
193
|
+
throw new Error("Invalid agent: missing required fields");
|
|
194
|
+
}
|
|
195
|
+
if (!agent.yamlContent || agent.yamlContent.length === 0) {
|
|
196
|
+
throw new Error("Invalid agent: missing YAML content");
|
|
197
|
+
}
|
|
198
|
+
if (!agent.protocol.startsWith("beddel-declarative-protocol")) {
|
|
199
|
+
throw new Error(`Unsupported protocol: ${agent.protocol}`);
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* Resolve agent asset path when running in bundled runtimes
|
|
204
|
+
*/
|
|
205
|
+
resolveAgentPath(filename) {
|
|
206
|
+
const candidatePaths = [
|
|
207
|
+
(0, path_1.join)(__dirname, filename),
|
|
208
|
+
(0, path_1.join)(process.cwd(), "packages", "beddel", "src", "agents", filename),
|
|
209
|
+
];
|
|
210
|
+
for (const path of candidatePaths) {
|
|
211
|
+
if ((0, fs_1.existsSync)(path)) {
|
|
212
|
+
return path;
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
throw new Error(`Unable to locate agent asset '${filename}' in paths: ${candidatePaths.join(", ")}`);
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
exports.AgentRegistry = AgentRegistry;
|
|
219
|
+
// Singleton instance
|
|
220
|
+
exports.agentRegistry = new AgentRegistry();
|
|
221
|
+
exports.default = AgentRegistry;
|
|
222
|
+
//# sourceMappingURL=agentRegistry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agentRegistry.js","sourceRoot":"","sources":["../../src/agents/agentRegistry.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,2BAA8C;AAC9C,+BAA4B;AAC5B,gFAA4E;AAa5E;;GAEG;AACH,MAAa,aAAa;IAGxB;QAFiB,WAAM,GAAmC,IAAI,GAAG,EAAE,CAAC;QAGlE,6CAA6C;QAC7C,IAAI,CAAC,qBAAqB,EAAE,CAAC;IAC/B,CAAC;IAED;;OAEG;IACI,aAAa,CAAC,KAAwB;QAC3C,iBAAiB;QACjB,IAAI,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;QAE1B,qBAAqB;QACrB,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;QACnC,OAAO,CAAC,GAAG,CAAC,qBAAqB,KAAK,CAAC,IAAI,KAAK,KAAK,CAAC,QAAQ,GAAG,CAAC,CAAC;IACrE,CAAC;IAED;;OAEG;IACI,KAAK,CAAC,YAAY,CACvB,SAAiB,EACjB,KAA0B,EAC1B,KAA6B,EAC7B,OAAyB;QAEzB,aAAa;QACb,MAAM,KAAK,GAAG,IAAI,CA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I,IAAI,cAAc,EAAE,CAAC;YAClC,IAAI,IAAA,eAAU,EAAC,IAAI,CAAC,EAAE,CAAC;gBACrB,OAAO,IAAI,CAAC;YACd,CAAC;QACH,CAAC;QAED,MAAM,IAAI,KAAK,CACb,iCAAiC,QAAQ,eAAe,cAAc,CAAC,IAAI,CACzE,IAAI,CACL,EAAE,CACJ,CAAC;IACJ,CAAC;CACF;AAnPD,sCAmPC;AAED,qBAAqB;AACR,QAAA,aAAa,GAAG,IAAI,aAAa,EAAE,CAAC;AAEjD,kBAAe,aAAa,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
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"}
|
|
@@ -0,0 +1,49 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"formatter-agent.js","sourceRoot":"","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