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.
- package/CHANGELOG.md +58 -0
- package/LICENSE +21 -0
- package/README.md +446 -192
- package/dist/agents/agentRegistry.d.ts +26 -1
- package/dist/agents/agentRegistry.d.ts.map +1 -1
- package/dist/agents/agentRegistry.js +180 -1
- package/dist/agents/agentRegistry.js.map +1 -1
- package/dist/runtime/declarativeAgentRuntime.d.ts +4 -0
- package/dist/runtime/declarativeAgentRuntime.d.ts.map +1 -1
- package/dist/runtime/declarativeAgentRuntime.js +43 -0
- package/dist/runtime/declarativeAgentRuntime.js.map +1 -1
- package/dist/runtime/schemaCompiler.js +5 -4
- package/dist/runtime/schemaCompiler.js.map +1 -1
- package/package.json +6 -3
- package/src/agents/agentRegistry.ts +172 -2
- package/src/runtime/declarativeAgentRuntime.ts +71 -13
- package/src/runtime/schemaCompiler.ts +5 -5
- package/dist/agents/formatter-agent.d.ts +0 -10
- package/dist/agents/formatter-agent.d.ts.map +0 -1
- package/dist/agents/formatter-agent.js +0 -49
- package/dist/agents/formatter-agent.js.map +0 -1
- package/dist/agents/genkit-agent.d.ts +0 -12
- package/dist/agents/genkit-agent.d.ts.map +0 -1
- package/dist/agents/genkit-agent.js +0 -119
- package/dist/agents/genkit-agent.js.map +0 -1
- package/dist/agents/i18n-messages.d.ts +0 -17
- package/dist/agents/i18n-messages.d.ts.map +0 -1
- package/dist/agents/i18n-messages.js +0 -92
- package/dist/agents/i18n-messages.js.map +0 -1
- package/dist/agents/index.d.ts +0 -10
- package/dist/agents/index.d.ts.map +0 -1
- package/dist/agents/index.js +0 -26
- package/dist/agents/index.js.map +0 -1
- package/dist/agents/pipeline.d.ts +0 -15
- package/dist/agents/pipeline.d.ts.map +0 -1
- package/dist/agents/pipeline.js +0 -45
- package/dist/agents/pipeline.js.map +0 -1
- package/dist/agents/schema-factory.d.ts +0 -40
- package/dist/agents/schema-factory.d.ts.map +0 -1
- package/dist/agents/schema-factory.js +0 -121
- package/dist/agents/schema-factory.js.map +0 -1
- package/dist/agents/translation-validators.d.ts +0 -26
- package/dist/agents/translation-validators.d.ts.map +0 -1
- package/dist/agents/translation-validators.js +0 -77
- package/dist/agents/translation-validators.js.map +0 -1
- package/dist/agents/translator-agents.d.ts +0 -184
- package/dist/agents/translator-agents.d.ts.map +0 -1
- package/dist/agents/translator-agents.js +0 -613
- package/dist/agents/translator-agents.js.map +0 -1
- package/dist/agents/types/translation.types.d.ts +0 -100
- package/dist/agents/types/translation.types.d.ts.map +0 -1
- package/dist/agents/types/translation.types.js +0 -3
- package/dist/agents/types/translation.types.js.map +0 -1
- package/dist/agents/validator-agent.d.ts +0 -42
- package/dist/agents/validator-agent.d.ts.map +0 -1
- package/dist/agents/validator-agent.js +0 -122
- package/dist/agents/validator-agent.js.map +0 -1
- package/dist/security/test-security.d.ts +0 -22
- package/dist/security/test-security.d.ts.map +0 -1
- package/dist/security/test-security.js +0 -154
- package/dist/security/test-security.js.map +0 -1
- package/tools/seed.ts +0 -365
- package/tools/test-endpoints.ts +0 -174
package/README.md
CHANGED
|
@@ -1,297 +1,551 @@
|
|
|
1
|
-
# Beddel
|
|
1
|
+
# Beddel
|
|
2
|
+
|
|
3
|
+
**Secure, Declarative, and Extensible Agent Runtime**
|
|
2
4
|
|
|
3
5
|
[](https://www.npmjs.com/package/beddel)
|
|
4
6
|
[](https://github.com/botanarede/beddel-alpha/blob/main/LICENSE)
|
|
5
7
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
## Usage Exemplo
|
|
8
|
+
Beddel is a security-first toolkit for building and running declarative YAML agents with enterprise-grade isolation, automatic schema validation, and extensible architecture.
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
## Quick Start
|
|
11
11
|
|
|
12
12
|
```yaml
|
|
13
|
-
#
|
|
13
|
+
# agents/my-agent.yaml
|
|
14
14
|
agent:
|
|
15
|
-
id:
|
|
15
|
+
id: my-agent
|
|
16
|
+
version: 1.0.0
|
|
16
17
|
protocol: beddel-declarative-protocol/v2.0
|
|
18
|
+
|
|
17
19
|
metadata:
|
|
18
|
-
name:
|
|
20
|
+
name: "My Custom Agent"
|
|
21
|
+
description: "A simple custom agent"
|
|
22
|
+
route: "/agents/my-agent"
|
|
23
|
+
|
|
19
24
|
schema:
|
|
20
25
|
input:
|
|
21
26
|
type: "object"
|
|
22
|
-
properties:
|
|
23
|
-
|
|
27
|
+
properties:
|
|
28
|
+
message:
|
|
29
|
+
type: "string"
|
|
30
|
+
required: ["message"]
|
|
24
31
|
output:
|
|
25
32
|
type: "object"
|
|
26
33
|
properties:
|
|
27
34
|
response:
|
|
28
35
|
type: "string"
|
|
29
36
|
required: ["response"]
|
|
37
|
+
|
|
30
38
|
logic:
|
|
31
39
|
workflow:
|
|
32
|
-
- name:
|
|
33
|
-
type: genkit-joke
|
|
40
|
+
- name: "process"
|
|
41
|
+
type: "genkit-joke"
|
|
34
42
|
action:
|
|
35
|
-
type: joke
|
|
36
|
-
prompt: "
|
|
37
|
-
result:
|
|
43
|
+
type: "joke"
|
|
44
|
+
prompt: "{{message}}"
|
|
45
|
+
result: "result"
|
|
38
46
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
type: generate
|
|
43
|
-
output:
|
|
44
|
-
response: "$jokerResult.texto"
|
|
47
|
+
output:
|
|
48
|
+
schema:
|
|
49
|
+
response: "$result.texto"
|
|
45
50
|
```
|
|
46
51
|
|
|
47
52
|
```typescript
|
|
48
|
-
import {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
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
|
-
};
|
|
53
|
+
import { agentRegistry } from "beddel";
|
|
54
|
+
|
|
55
|
+
// Execute the agent
|
|
56
|
+
const result = await agentRegistry.executeAgent(
|
|
57
|
+
"my-agent.execute",
|
|
58
|
+
{ message: "Hello world" },
|
|
59
|
+
{ gemini_api_key: process.env.GEMINI_API_KEY },
|
|
60
|
+
context
|
|
61
|
+
);
|
|
62
|
+
```
|
|
70
63
|
|
|
71
|
-
|
|
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
|
-
});
|
|
64
|
+
## Installation
|
|
80
65
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
tenantId: "tenant-42",
|
|
84
|
-
securityProfile: "tenant-isolated",
|
|
85
|
-
validateSecurity: true,
|
|
86
|
-
});
|
|
66
|
+
```bash
|
|
67
|
+
npm install beddel
|
|
87
68
|
```
|
|
88
69
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
70
|
+
Requires Node.js 18+.
|
|
71
|
+
|
|
72
|
+
---
|
|
73
|
+
|
|
74
|
+
## Architecture Overview
|
|
92
75
|
|
|
93
|
-
|
|
76
|
+
```
|
|
77
|
+
┌─────────────────────────────────────────────────────────────────────┐
|
|
78
|
+
│ Beddel Runtime │
|
|
79
|
+
│ │
|
|
80
|
+
│ ┌──────────────────────────────────────────────────────────────┐ │
|
|
81
|
+
│ │ Agent Registry │ │
|
|
82
|
+
│ │ │ │
|
|
83
|
+
│ │ ┌─────────────────┐ ┌────────────────────────────────┐ │ │
|
|
84
|
+
│ │ │ Built-in │ │ Custom Agents │ │ │
|
|
85
|
+
│ │ │ Agents │ │ /agents/*.yaml │ │ │
|
|
86
|
+
│ │ │ │ │ │ │ │
|
|
87
|
+
│ │ │ • joker │ │ Automatically discovered │ │ │
|
|
88
|
+
│ │ │ • translator │ │ and registered at startup │ │ │
|
|
89
|
+
│ │ │ • image │ │ │ │ │
|
|
90
|
+
│ │ └─────────────────┘ └────────────────────────────────┘ │ │
|
|
91
|
+
│ │ │ │
|
|
92
|
+
│ │ Priority: Custom Agents > Built-in Agents │ │
|
|
93
|
+
│ └──────────────────────────────────────────────────────────────┘ │
|
|
94
|
+
│ │ │
|
|
95
|
+
│ ▼ │
|
|
96
|
+
│ ┌──────────────────────────────────────────────────────────────┐ │
|
|
97
|
+
│ │ Declarative Agent Interpreter │ │
|
|
98
|
+
│ │ │ │
|
|
99
|
+
│ │ • YAML Parsing (FAILSAFE schema) │ │
|
|
100
|
+
│ │ • Schema Validation (Zod) │ │
|
|
101
|
+
│ │ • Workflow Execution │ │
|
|
102
|
+
│ │ • Genkit Integration (Gemini Flash) │ │
|
|
103
|
+
│ └──────────────────────────────────────────────────────────────┘ │
|
|
104
|
+
│ │ │
|
|
105
|
+
│ ▼ │
|
|
106
|
+
│ ┌──────────────────────────────────────────────────────────────┐ │
|
|
107
|
+
│ │ Secure Runtime (isolated-vm) │ │
|
|
108
|
+
│ │ │ │
|
|
109
|
+
│ │ • Memory limits • V8 isolate │ │
|
|
110
|
+
│ │ • Execution timeouts • No Node.js access │ │
|
|
111
|
+
│ │ • Audit logging • Multi-tenant isolation │ │
|
|
112
|
+
│ └──────────────────────────────────────────────────────────────┘ │
|
|
113
|
+
└─────────────────────────────────────────────────────────────────────┘
|
|
114
|
+
```
|
|
94
115
|
|
|
95
|
-
|
|
96
|
-
- Multiple execution strategies powered by `isolated-vm`.
|
|
97
|
-
- Declarative agent utilities, compliance helpers, performance monitors, and Firebase multi-tenant orchestration.
|
|
116
|
+
---
|
|
98
117
|
|
|
99
|
-
|
|
118
|
+
## Custom Agents
|
|
100
119
|
|
|
101
|
-
|
|
120
|
+
Beddel supports custom agents that you define in your application's `/agents` directory. Custom agents are automatically discovered and registered at startup.
|
|
102
121
|
|
|
103
|
-
|
|
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` |
|
|
122
|
+
### Directory Structure
|
|
108
123
|
|
|
109
|
-
|
|
124
|
+
```
|
|
125
|
+
your-app/
|
|
126
|
+
├── agents/ # Custom agents directory
|
|
127
|
+
│ ├── my-agent.yaml # Simple YAML-only agent
|
|
128
|
+
│ ├── my-chat.yaml # Agent with TypeScript code-behind
|
|
129
|
+
│ ├── my-chat.ts # TypeScript implementation
|
|
130
|
+
│ ├── calculator/
|
|
131
|
+
│ │ └── calculator.yaml # Agent in subdirectory
|
|
132
|
+
│ └── translator-custom/
|
|
133
|
+
│ └── translator-custom.yaml # Override built-in
|
|
134
|
+
│
|
|
135
|
+
└── packages/beddel/src/agents/ # Built-in agents (package)
|
|
136
|
+
├── joker-agent.yaml
|
|
137
|
+
├── translator-agent.yaml
|
|
138
|
+
└── image-agent.yaml
|
|
139
|
+
```
|
|
110
140
|
|
|
111
|
-
|
|
141
|
+
### Agent Loading Flow
|
|
112
142
|
|
|
113
|
-
|
|
143
|
+
```
|
|
144
|
+
┌─────────────────────────────────────────────────────────────┐
|
|
145
|
+
│ Agent Loading Sequence │
|
|
146
|
+
│ │
|
|
147
|
+
│ 1. AgentRegistry constructor() │
|
|
148
|
+
│ │ │
|
|
149
|
+
│ ├──▶ 2. registerBuiltinAgents() │
|
|
150
|
+
│ │ ├── joker.execute │
|
|
151
|
+
│ │ ├── translator.execute │
|
|
152
|
+
│ │ └── image.generate │
|
|
153
|
+
│ │ │
|
|
154
|
+
│ └──▶ 3. loadCustomAgents() │
|
|
155
|
+
│ │ │
|
|
156
|
+
│ ├── Recursively scans /agents/**/*.yaml │
|
|
157
|
+
│ │ └── Registers each agent │
|
|
158
|
+
│ │ └── Custom agents override built-ins │
|
|
159
|
+
│ │ │
|
|
160
|
+
│ └── Scans /agents/**/*.ts │
|
|
161
|
+
│ └── Dynamically imports TypeScript modules │
|
|
162
|
+
│ └── Registers exported functions │
|
|
163
|
+
│ │
|
|
164
|
+
│ Priority: Custom Agents > Built-in Agents │
|
|
165
|
+
└─────────────────────────────────────────────────────────────┘
|
|
166
|
+
```
|
|
114
167
|
|
|
115
|
-
|
|
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. |
|
|
168
|
+
### Creating a Custom Agent
|
|
124
169
|
|
|
125
|
-
|
|
170
|
+
1. **Create the YAML file** in `/agents`:
|
|
126
171
|
|
|
127
|
-
|
|
172
|
+
```yaml
|
|
173
|
+
# agents/greeting.yaml
|
|
174
|
+
agent:
|
|
175
|
+
id: greeting
|
|
176
|
+
version: 1.0.0
|
|
177
|
+
protocol: beddel-declarative-protocol/v2.0
|
|
128
178
|
|
|
129
|
-
|
|
130
|
-
|
|
179
|
+
metadata:
|
|
180
|
+
name: "Greeting Agent"
|
|
181
|
+
description: "Generates personalized greetings"
|
|
182
|
+
category: "utility"
|
|
183
|
+
route: "/agents/greeting"
|
|
184
|
+
|
|
185
|
+
schema:
|
|
186
|
+
input:
|
|
187
|
+
type: "object"
|
|
188
|
+
properties:
|
|
189
|
+
name:
|
|
190
|
+
type: "string"
|
|
191
|
+
minLength: 1
|
|
192
|
+
maxLength: 100
|
|
193
|
+
required: ["name"]
|
|
194
|
+
|
|
195
|
+
output:
|
|
196
|
+
type: "object"
|
|
197
|
+
properties:
|
|
198
|
+
greeting:
|
|
199
|
+
type: "string"
|
|
200
|
+
required: ["greeting"]
|
|
201
|
+
|
|
202
|
+
logic:
|
|
203
|
+
workflow:
|
|
204
|
+
- name: "generate-greeting"
|
|
205
|
+
type: "genkit-joke"
|
|
206
|
+
action:
|
|
207
|
+
type: "joke"
|
|
208
|
+
prompt: "Create a warm, friendly greeting for {{name}}"
|
|
209
|
+
result: "greetingResult"
|
|
210
|
+
|
|
211
|
+
output:
|
|
212
|
+
schema:
|
|
213
|
+
greeting: "$greetingResult.texto"
|
|
131
214
|
```
|
|
132
215
|
|
|
133
|
-
|
|
216
|
+
2. **The agent is automatically registered** when your application starts.
|
|
134
217
|
|
|
135
|
-
|
|
218
|
+
3. **Execute via GraphQL or directly**:
|
|
136
219
|
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
220
|
+
```graphql
|
|
221
|
+
mutation {
|
|
222
|
+
executeMethod(
|
|
223
|
+
methodName: "greeting.execute"
|
|
224
|
+
params: { name: "Alice" }
|
|
225
|
+
props: { gemini_api_key: "your-api-key" }
|
|
226
|
+
) {
|
|
227
|
+
success
|
|
228
|
+
data
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
```
|
|
232
|
+
|
|
233
|
+
### Custom Agents with TypeScript Code-Behind
|
|
141
234
|
|
|
142
|
-
|
|
235
|
+
For more complex logic, create custom agents with TypeScript implementations:
|
|
143
236
|
|
|
144
|
-
|
|
237
|
+
#### 1. Create the TypeScript implementation:
|
|
145
238
|
|
|
146
239
|
```typescript
|
|
147
|
-
|
|
240
|
+
// agents/my-chat.ts
|
|
241
|
+
export const chatHandler = async ({ input, variables, context }) => {
|
|
242
|
+
// Full TypeScript power available here
|
|
243
|
+
context.log("Processing chat message with custom TypeScript logic");
|
|
244
|
+
|
|
245
|
+
const message = input.message || "";
|
|
246
|
+
const history = input.messages || [];
|
|
247
|
+
|
|
248
|
+
// Add user message to history
|
|
249
|
+
history.push({ role: "user", content: message });
|
|
250
|
+
|
|
251
|
+
// Your custom logic here - call external APIs, use Beddel helpers, etc.
|
|
252
|
+
const response = `Processed: "${message}"`;
|
|
253
|
+
|
|
254
|
+
history.push({ role: "assistant", content: response });
|
|
255
|
+
|
|
256
|
+
return {
|
|
257
|
+
response,
|
|
258
|
+
history,
|
|
259
|
+
timestamp: new Date().toISOString()
|
|
260
|
+
};
|
|
261
|
+
};
|
|
262
|
+
```
|
|
148
263
|
|
|
149
|
-
|
|
150
|
-
maxDepth: 200,
|
|
151
|
-
filename: "agent-manifest",
|
|
152
|
-
});
|
|
264
|
+
#### 2. Create the YAML configuration:
|
|
153
265
|
|
|
154
|
-
|
|
266
|
+
```yaml
|
|
267
|
+
# agents/my-chat.yaml
|
|
155
268
|
agent:
|
|
156
|
-
id:
|
|
269
|
+
id: my-chat
|
|
270
|
+
version: 1.0.0
|
|
271
|
+
protocol: beddel-declarative-protocol/v2.0
|
|
272
|
+
|
|
273
|
+
metadata:
|
|
274
|
+
name: "Custom Chat Agent"
|
|
275
|
+
description: "Chat agent with TypeScript code-behind"
|
|
276
|
+
route: "/agents/my-chat"
|
|
277
|
+
|
|
157
278
|
schema:
|
|
158
|
-
input:
|
|
159
|
-
|
|
279
|
+
input:
|
|
280
|
+
type: "object"
|
|
281
|
+
properties:
|
|
282
|
+
message:
|
|
283
|
+
type: "string"
|
|
284
|
+
minLength: 1
|
|
285
|
+
required: ["message"]
|
|
286
|
+
|
|
287
|
+
output:
|
|
288
|
+
type: "object"
|
|
289
|
+
properties:
|
|
290
|
+
response:
|
|
291
|
+
type: "string"
|
|
292
|
+
required: ["response"]
|
|
293
|
+
|
|
160
294
|
logic:
|
|
161
295
|
workflow:
|
|
162
|
-
- name:
|
|
163
|
-
type:
|
|
296
|
+
- name: process
|
|
297
|
+
type: custom-action
|
|
164
298
|
action:
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
response: "lol"
|
|
168
|
-
`);
|
|
299
|
+
function: "my-chat/chatHandler" # Format: filename/exportedFunctionName
|
|
300
|
+
result: response
|
|
169
301
|
|
|
170
|
-
|
|
302
|
+
output:
|
|
303
|
+
schema:
|
|
304
|
+
response: "$response.response"
|
|
171
305
|
```
|
|
172
306
|
|
|
173
|
-
|
|
307
|
+
#### 3. Function Arguments
|
|
174
308
|
|
|
175
|
-
|
|
309
|
+
Custom functions receive a standardized arguments object:
|
|
176
310
|
|
|
177
311
|
```typescript
|
|
178
|
-
|
|
312
|
+
{
|
|
313
|
+
input: Record<string, any>, // Validated input from the request
|
|
314
|
+
variables: Record<string, any>, // Current workflow variables
|
|
315
|
+
action: Record<string, any>, // Action configuration from YAML
|
|
316
|
+
context: ExecutionContext // Logging and error handling
|
|
317
|
+
}
|
|
318
|
+
```
|
|
179
319
|
|
|
180
|
-
|
|
320
|
+
### Overriding Built-in Agents
|
|
181
321
|
|
|
182
|
-
|
|
183
|
-
code: `
|
|
184
|
-
const secret = "sandboxed";
|
|
185
|
-
({ success: true, value: secret.length });
|
|
186
|
-
`,
|
|
187
|
-
securityProfile: "ultra-secure",
|
|
188
|
-
timeout: 2000,
|
|
189
|
-
});
|
|
322
|
+
Create a custom agent with the same route to override a built-in:
|
|
190
323
|
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
324
|
+
```yaml
|
|
325
|
+
# agents/joker-custom.yaml
|
|
326
|
+
agent:
|
|
327
|
+
id: joker
|
|
328
|
+
protocol: beddel-declarative-protocol/v2.0
|
|
194
329
|
|
|
195
|
-
|
|
330
|
+
metadata:
|
|
331
|
+
route: "/agents/joker" # Same route overrides built-in
|
|
332
|
+
# ... your custom implementation
|
|
196
333
|
```
|
|
197
334
|
|
|
198
|
-
|
|
335
|
+
---
|
|
336
|
+
|
|
337
|
+
## Built-in Agents
|
|
199
338
|
|
|
200
|
-
|
|
339
|
+
| Agent | Method | Description | Required Props |
|
|
340
|
+
|-------|--------|-------------|----------------|
|
|
341
|
+
| **Joker** | `joker.execute` | Generates short, original jokes | `gemini_api_key` |
|
|
342
|
+
| **Translator** | `translator.execute` | Translates text between languages | `gemini_api_key` |
|
|
343
|
+
| **Image Generator** | `image.generate` | Creates images (watercolor, neon, sketch) | `gemini_api_key` |
|
|
344
|
+
|
|
345
|
+
### Joker Agent
|
|
201
346
|
|
|
202
347
|
```typescript
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
348
|
+
const result = await agentRegistry.executeAgent(
|
|
349
|
+
"joker.execute",
|
|
350
|
+
{},
|
|
351
|
+
{ gemini_api_key: "..." },
|
|
352
|
+
context
|
|
353
|
+
);
|
|
354
|
+
// Returns: { response: "Why did the..." }
|
|
355
|
+
```
|
|
356
|
+
|
|
357
|
+
### Translator Agent
|
|
358
|
+
|
|
359
|
+
```typescript
|
|
360
|
+
const result = await agentRegistry.executeAgent(
|
|
361
|
+
"translator.execute",
|
|
362
|
+
{
|
|
363
|
+
texto: "Hello, world!",
|
|
364
|
+
idioma_origem: "en",
|
|
365
|
+
idioma_destino: "pt"
|
|
217
366
|
},
|
|
218
|
-
}
|
|
367
|
+
{ gemini_api_key: "..." },
|
|
368
|
+
context
|
|
369
|
+
);
|
|
370
|
+
// Returns: { texto_traduzido: "Olá, mundo!", metadados: {...} }
|
|
371
|
+
```
|
|
372
|
+
|
|
373
|
+
### Image Generator Agent
|
|
219
374
|
|
|
220
|
-
|
|
375
|
+
```typescript
|
|
376
|
+
const result = await agentRegistry.executeAgent(
|
|
377
|
+
"image.generate",
|
|
378
|
+
{
|
|
379
|
+
descricao: "A sunset over mountains",
|
|
380
|
+
estilo: "watercolor",
|
|
381
|
+
resolucao: "1024x1024"
|
|
382
|
+
},
|
|
383
|
+
{ gemini_api_key: "..." },
|
|
384
|
+
context
|
|
385
|
+
);
|
|
386
|
+
// Returns: { image_url, image_base64, media_type, ... }
|
|
221
387
|
```
|
|
222
388
|
|
|
223
|
-
|
|
389
|
+
---
|
|
224
390
|
|
|
225
|
-
|
|
226
|
-
- Supports string/number/boolean/object variables and literal/variable references.
|
|
227
|
-
- Executes `output-generator` workflow steps that map variables to response objects.
|
|
391
|
+
## Core Components
|
|
228
392
|
|
|
229
|
-
|
|
393
|
+
### Package Map
|
|
230
394
|
|
|
231
|
-
|
|
395
|
+
| Capability | Module | Description |
|
|
396
|
+
|------------|--------|-------------|
|
|
397
|
+
| **YAML Parsing** | `SecureYamlParser` | FAILSAFE schema, depth/size limits, UTF-8 validation |
|
|
398
|
+
| **Sandboxed Execution** | `IsolatedRuntimeManager` | `isolated-vm` with security profiles |
|
|
399
|
+
| **Agent Interpretation** | `DeclarativeAgentInterpreter` | Executes YAML agents with Genkit |
|
|
400
|
+
| **Agent Registry** | `AgentRegistry` | Manages built-in and custom agents |
|
|
401
|
+
| **Security** | `SecurityScanner`, `ThreatDetectionEngine` | Static scanning, scoring |
|
|
402
|
+
| **Compliance** | `GDPRCompliance`, `LGPDCompliance` | Audit, anonymization |
|
|
403
|
+
| **Performance** | `PerformanceMonitor`, `AutoScaler` | Metrics, scaling |
|
|
404
|
+
| **Multi-tenancy** | `MultiTenantFirebaseManager` | Firebase tenant isolation |
|
|
232
405
|
|
|
233
|
-
|
|
406
|
+
### Secure YAML Parsing
|
|
234
407
|
|
|
235
|
-
|
|
236
|
-
|
|
408
|
+
```typescript
|
|
409
|
+
import { SecureYamlParser } from "beddel";
|
|
237
410
|
|
|
238
|
-
|
|
411
|
+
const parser = new SecureYamlParser({
|
|
412
|
+
maxDepth: 200,
|
|
413
|
+
filename: "agent-manifest",
|
|
414
|
+
});
|
|
239
415
|
|
|
240
|
-
|
|
416
|
+
const manifest = parser.parseSecure(yamlContent);
|
|
417
|
+
```
|
|
241
418
|
|
|
242
|
-
|
|
419
|
+
### Sandboxed Execution
|
|
243
420
|
|
|
244
421
|
```typescript
|
|
245
|
-
import {
|
|
422
|
+
import { IsolatedRuntimeManager } from "beddel";
|
|
423
|
+
|
|
424
|
+
const runtime = new IsolatedRuntimeManager();
|
|
246
425
|
|
|
247
|
-
const
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
validateSecurity: true,
|
|
426
|
+
const result = await runtime.execute({
|
|
427
|
+
code: `({ value: 42 })`,
|
|
428
|
+
securityProfile: "ultra-secure",
|
|
429
|
+
timeout: 2000,
|
|
252
430
|
});
|
|
253
431
|
```
|
|
254
432
|
|
|
255
|
-
|
|
433
|
+
### Agent Registry API
|
|
256
434
|
|
|
257
|
-
|
|
435
|
+
```typescript
|
|
436
|
+
import { agentRegistry } from "beddel";
|
|
258
437
|
|
|
259
|
-
|
|
260
|
-
|
|
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.
|
|
438
|
+
// Get all registered agents
|
|
439
|
+
const agents = agentRegistry.getAllAgents();
|
|
267
440
|
|
|
268
|
-
|
|
441
|
+
// Get a specific agent
|
|
442
|
+
const agent = agentRegistry.getAgent("joker.execute");
|
|
269
443
|
|
|
270
|
-
|
|
444
|
+
// Execute an agent
|
|
445
|
+
const result = await agentRegistry.executeAgent(
|
|
446
|
+
"joker.execute",
|
|
447
|
+
input,
|
|
448
|
+
props,
|
|
449
|
+
context
|
|
450
|
+
);
|
|
271
451
|
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
452
|
+
// Load custom agents from a specific path
|
|
453
|
+
agentRegistry.loadCustomAgents("/path/to/custom/agents");
|
|
454
|
+
```
|
|
275
455
|
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
456
|
+
---
|
|
457
|
+
|
|
458
|
+
## Schema Validation
|
|
459
|
+
|
|
460
|
+
All agents must declare `schema.input` and `schema.output` blocks. The runtime compiles these into Zod schemas and validates:
|
|
461
|
+
|
|
462
|
+
- **Before execution**: Input must match `schema.input`
|
|
463
|
+
- **After execution**: Output must match `schema.output`
|
|
464
|
+
|
|
465
|
+
```yaml
|
|
466
|
+
schema:
|
|
467
|
+
input:
|
|
468
|
+
type: "object"
|
|
469
|
+
properties:
|
|
470
|
+
name:
|
|
471
|
+
type: "string"
|
|
472
|
+
minLength: 1
|
|
473
|
+
maxLength: 100
|
|
474
|
+
age:
|
|
475
|
+
type: "number"
|
|
476
|
+
required: ["name"]
|
|
477
|
+
|
|
478
|
+
output:
|
|
479
|
+
type: "object"
|
|
480
|
+
properties:
|
|
481
|
+
greeting:
|
|
482
|
+
type: "string"
|
|
483
|
+
required: ["greeting"]
|
|
484
|
+
```
|
|
485
|
+
|
|
486
|
+
Supported types: `string`, `number`, `boolean`, `object`, `array`
|
|
487
|
+
|
|
488
|
+
---
|
|
489
|
+
|
|
490
|
+
## Security
|
|
491
|
+
|
|
492
|
+
### Multi-Layer Security Model
|
|
493
|
+
|
|
494
|
+
1. **Parser Layer**: FAILSAFE schema, size limits, sanitization
|
|
495
|
+
2. **Runtime Layer**: V8 isolate, memory limits, timeouts
|
|
496
|
+
3. **Application Layer**: Authentication, rate limiting, tenant isolation
|
|
497
|
+
|
|
498
|
+
### Security Profiles
|
|
499
|
+
|
|
500
|
+
```typescript
|
|
501
|
+
const result = await runtime.execute({
|
|
502
|
+
code: userCode,
|
|
503
|
+
securityProfile: "tenant-isolated", // ultra-secure | tenant-isolated
|
|
504
|
+
timeout: 5000,
|
|
505
|
+
memoryLimit: 128,
|
|
506
|
+
});
|
|
279
507
|
```
|
|
280
508
|
|
|
281
|
-
|
|
509
|
+
---
|
|
282
510
|
|
|
283
|
-
##
|
|
511
|
+
## Project Structure
|
|
284
512
|
|
|
285
|
-
|
|
513
|
+
```
|
|
514
|
+
src/
|
|
515
|
+
├── agents/ # Agent registry and built-in agents
|
|
516
|
+
│ ├── agentRegistry.ts # Agent management
|
|
517
|
+
│ ├── joker-agent.yaml # Built-in: Joker
|
|
518
|
+
│ ├── translator-agent.yaml
|
|
519
|
+
│ └── image-agent.yaml
|
|
520
|
+
├── parser/ # Secure YAML parsing
|
|
521
|
+
├── runtime/ # Execution environments
|
|
522
|
+
│ ├── isolatedRuntime.ts
|
|
523
|
+
│ ├── declarativeAgentRuntime.ts
|
|
524
|
+
│ └── schemaCompiler.ts
|
|
525
|
+
├── security/ # Scanning and threat detection
|
|
526
|
+
├── compliance/ # GDPR/LGPD utilities
|
|
527
|
+
├── performance/ # Monitoring and autoscaling
|
|
528
|
+
├── firebase/ # Multi-tenant management
|
|
529
|
+
└── index.ts # Public exports
|
|
530
|
+
```
|
|
286
531
|
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
532
|
+
---
|
|
533
|
+
|
|
534
|
+
## Development
|
|
535
|
+
|
|
536
|
+
```bash
|
|
537
|
+
# Build
|
|
538
|
+
pnpm --filter beddel build
|
|
539
|
+
|
|
540
|
+
# Test
|
|
541
|
+
pnpm --filter beddel test
|
|
542
|
+
|
|
543
|
+
# Lint
|
|
544
|
+
pnpm --filter beddel lint
|
|
545
|
+
```
|
|
292
546
|
|
|
293
|
-
|
|
547
|
+
---
|
|
294
548
|
|
|
295
549
|
## License
|
|
296
550
|
|
|
297
|
-
|
|
551
|
+
MIT License. See [LICENSE](LICENSE) for details.
|