beddel 1.0.2 β 1.0.4
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 +46 -11
- package/dist/agents/assistant-bedrock.yaml +19 -0
- package/dist/agents/assistant-openrouter.yaml +16 -0
- package/dist/agents/assistant.yaml +16 -0
- package/dist/agents/index.d.ts +24 -0
- package/dist/agents/index.d.ts.map +1 -0
- package/dist/agents/index.js +39 -0
- package/dist/agents/multi-step-assistant.yaml +67 -0
- package/dist/agents/text-generator.yaml +27 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/primitives/call-agent.d.ts +28 -0
- package/dist/primitives/call-agent.d.ts.map +1 -0
- package/dist/primitives/call-agent.js +79 -0
- package/dist/primitives/chat.d.ts +26 -0
- package/dist/primitives/chat.d.ts.map +1 -0
- package/dist/primitives/chat.js +63 -0
- package/dist/primitives/index.d.ts +9 -15
- package/dist/primitives/index.d.ts.map +1 -1
- package/dist/primitives/index.js +24 -34
- package/dist/primitives/llm-core.d.ts +45 -0
- package/dist/primitives/llm-core.d.ts.map +1 -0
- package/dist/primitives/llm-core.js +43 -0
- package/dist/primitives/llm.d.ts +12 -41
- package/dist/primitives/llm.d.ts.map +1 -1
- package/dist/primitives/llm.js +27 -133
- package/dist/providers/index.d.ts.map +1 -1
- package/dist/providers/index.js +23 -2
- package/dist/server/handler.d.ts +3 -0
- package/dist/server/handler.d.ts.map +1 -1
- package/dist/server/handler.js +39 -14
- package/docs/architecture/api-reference.md +134 -102
- package/docs/architecture/components.md +130 -133
- package/docs/architecture/core-workflows.md +146 -129
- package/docs/architecture/high-level-architecture.md +19 -12
- package/docs/architecture/source-tree.md +60 -34
- package/package.json +7 -2
- package/src/agents/assistant-bedrock.yaml +19 -0
- package/src/agents/assistant-openrouter.yaml +16 -0
- package/src/agents/assistant.yaml +16 -0
- package/src/agents/index.ts +47 -0
- package/src/agents/multi-step-assistant.yaml +67 -0
- package/src/agents/text-generator.yaml +27 -0
- package/src/index.ts +9 -0
- package/src/primitives/call-agent.ts +108 -0
- package/src/primitives/chat.ts +84 -0
- package/src/primitives/index.ts +25 -38
- package/src/primitives/llm-core.ts +77 -0
- package/src/primitives/llm.ts +28 -178
- package/src/providers/index.ts +19 -0
- package/src/server/handler.ts +50 -17
package/README.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# Beddel Protocol
|
|
2
2
|
|
|
3
3
|
[](LICENSE)
|
|
4
|
-
[](https://www.npmjs.com/package/beddel)
|
|
5
5
|
[](https://www.typescriptlang.org/)
|
|
6
6
|
[](https://sdk.vercel.ai/)
|
|
7
7
|
|
|
@@ -10,11 +10,12 @@
|
|
|
10
10
|
## Features
|
|
11
11
|
|
|
12
12
|
- π **Sequential Pipeline Execution** β Define workflows as YAML, execute steps in order
|
|
13
|
-
- π **Native Streaming** β First-class `streamText` support with `useChat` compatibility
|
|
13
|
+
- π **Native Streaming** β First-class `streamText` support via `chat` primitive with `useChat` compatibility
|
|
14
14
|
- π **Extensible Primitives** β Register custom step types, tools, and callbacks
|
|
15
15
|
- π **Security First** β YAML parsing with `FAILSAFE_SCHEMA` prevents code execution
|
|
16
16
|
- π¦ **Bundle Separation** β Three entry points for server, client, and full API access
|
|
17
|
-
- π **Multi-Provider** β Built-in support for Google Gemini and
|
|
17
|
+
- π **Multi-Provider** β Built-in support for Google Gemini, Amazon Bedrock, and OpenRouter (400+ models)
|
|
18
|
+
- π **Semantic Primitives** β `chat` for streaming frontend, `llm` for blocking workflows
|
|
18
19
|
|
|
19
20
|
## Installation
|
|
20
21
|
|
|
@@ -51,11 +52,10 @@ metadata:
|
|
|
51
52
|
|
|
52
53
|
workflow:
|
|
53
54
|
- id: "chat-interaction"
|
|
54
|
-
type: "
|
|
55
|
+
type: "chat"
|
|
55
56
|
config:
|
|
56
57
|
provider: "google"
|
|
57
58
|
model: "gemini-2.0-flash-exp"
|
|
58
|
-
stream: true
|
|
59
59
|
system: "You are a helpful assistant."
|
|
60
60
|
messages: "$input.messages"
|
|
61
61
|
```
|
|
@@ -71,17 +71,34 @@ metadata:
|
|
|
71
71
|
|
|
72
72
|
workflow:
|
|
73
73
|
- id: "chat"
|
|
74
|
-
type: "
|
|
74
|
+
type: "chat"
|
|
75
75
|
config:
|
|
76
76
|
provider: "bedrock"
|
|
77
77
|
model: "us.meta.llama3-2-1b-instruct-v1:0"
|
|
78
|
-
stream: true
|
|
79
78
|
system: |
|
|
80
79
|
You are a helpful, friendly assistant. Be concise and direct.
|
|
81
80
|
Answer in the same language the user writes to you.
|
|
82
81
|
messages: "$input.messages"
|
|
83
82
|
```
|
|
84
83
|
|
|
84
|
+
#### Example 3: OpenRouter (400+ Models)
|
|
85
|
+
|
|
86
|
+
```yaml
|
|
87
|
+
# src/agents/assistant-openrouter.yaml
|
|
88
|
+
metadata:
|
|
89
|
+
name: "OpenRouter Assistant"
|
|
90
|
+
version: "1.0.0"
|
|
91
|
+
|
|
92
|
+
workflow:
|
|
93
|
+
- id: "chat"
|
|
94
|
+
type: "chat"
|
|
95
|
+
config:
|
|
96
|
+
provider: "openrouter"
|
|
97
|
+
model: "qwen/qwen3-14b:free" # or any model from openrouter.ai/models
|
|
98
|
+
system: "You are a helpful assistant."
|
|
99
|
+
messages: "$input.messages"
|
|
100
|
+
```
|
|
101
|
+
|
|
85
102
|
### 3. Set Environment Variables
|
|
86
103
|
|
|
87
104
|
```bash
|
|
@@ -94,6 +111,9 @@ AWS_BEARER_TOKEN_BEDROCK=your_bedrock_api_key
|
|
|
94
111
|
# Or use standard AWS credentials:
|
|
95
112
|
# AWS_ACCESS_KEY_ID=your_access_key
|
|
96
113
|
# AWS_SECRET_ACCESS_KEY=your_secret_key
|
|
114
|
+
|
|
115
|
+
# For OpenRouter
|
|
116
|
+
OPENROUTER_API_KEY=your_openrouter_api_key
|
|
97
117
|
```
|
|
98
118
|
|
|
99
119
|
### 4. Use with React (useChat)
|
|
@@ -128,6 +148,7 @@ export default function Chat() {
|
|
|
128
148
|
|----------|----------------------|---------------|
|
|
129
149
|
| `google` | `GEMINI_API_KEY` | `gemini-1.5-flash` |
|
|
130
150
|
| `bedrock` | `AWS_REGION`, `AWS_BEARER_TOKEN_BEDROCK` (or AWS credentials) | `anthropic.claude-3-haiku-20240307-v1:0` |
|
|
151
|
+
| `openrouter` | `OPENROUTER_API_KEY` | `qwen/qwen3-14b:free` |
|
|
131
152
|
|
|
132
153
|
> **Note:** The Bedrock provider requires `AWS_REGION` to be set (defaults to `us-east-1` if not provided).
|
|
133
154
|
|
|
@@ -188,10 +209,9 @@ metadata:
|
|
|
188
209
|
|
|
189
210
|
workflow:
|
|
190
211
|
- id: "step-1"
|
|
191
|
-
type: "llm"
|
|
212
|
+
type: "chat" # or "llm" for non-streaming workflows
|
|
192
213
|
config:
|
|
193
214
|
model: "gemini-2.0-flash-exp"
|
|
194
|
-
stream: true
|
|
195
215
|
system: "System prompt"
|
|
196
216
|
messages: "$input.messages"
|
|
197
217
|
tools:
|
|
@@ -200,6 +220,15 @@ workflow:
|
|
|
200
220
|
result: "stepOutput"
|
|
201
221
|
```
|
|
202
222
|
|
|
223
|
+
### Primitive Types
|
|
224
|
+
|
|
225
|
+
| Type | Behavior | Use Case |
|
|
226
|
+
|------|----------|----------|
|
|
227
|
+
| `chat` | Always streaming, converts UIMessage | Frontend chat interfaces (`useChat`) |
|
|
228
|
+
| `llm` | Never streaming, returns complete result | Multi-step workflows, variable passing |
|
|
229
|
+
| `call-agent` | Invokes another agent | Sub-agent orchestration |
|
|
230
|
+
| `output-generator` | JSON template transform | Structured output generation |
|
|
231
|
+
|
|
203
232
|
### Variable Resolution
|
|
204
233
|
|
|
205
234
|
| Pattern | Description | Example |
|
|
@@ -220,8 +249,9 @@ Beddel is fully compatible with Vercel AI SDK v6:
|
|
|
220
249
|
|
|
221
250
|
- **Frontend:** `useChat` sends `UIMessage[]` with `{ parts: [...] }` format
|
|
222
251
|
- **Backend:** `streamText`/`generateText` expects `ModelMessage[]` with `{ content: ... }`
|
|
223
|
-
- **Automatic Conversion:** `convertToModelMessages()`
|
|
224
|
-
- **Streaming:** `toUIMessageStreamResponse()`
|
|
252
|
+
- **Automatic Conversion:** `chat` primitive uses `convertToModelMessages()` to bridge the gap
|
|
253
|
+
- **Streaming:** `chat` primitive returns `toUIMessageStreamResponse()` for `useChat`
|
|
254
|
+
- **Blocking:** `llm` primitive uses `generateText()` for workflow steps
|
|
225
255
|
|
|
226
256
|
## Technology Stack
|
|
227
257
|
|
|
@@ -232,6 +262,7 @@ Beddel is fully compatible with Vercel AI SDK v6:
|
|
|
232
262
|
| AI Core | `ai` | 6.x |
|
|
233
263
|
| AI Provider | `@ai-sdk/google` | 3.x |
|
|
234
264
|
| AI Provider | `@ai-sdk/amazon-bedrock` | 4.x |
|
|
265
|
+
| AI Provider | `@ai-sdk/openai` | 1.x |
|
|
235
266
|
| Validation | `zod` | 3.x |
|
|
236
267
|
| YAML Parser | `js-yaml` | 4.x |
|
|
237
268
|
|
|
@@ -244,6 +275,10 @@ Detailed documentation is available in [`docs/`](./docs/):
|
|
|
244
275
|
- [Core Workflows](./docs/architecture/core-workflows.md)
|
|
245
276
|
- [High-Level Architecture](./docs/architecture/high-level-architecture.md)
|
|
246
277
|
|
|
278
|
+
## Newsletter
|
|
279
|
+
|
|
280
|
+
[](https://beddelprotocol.substack.com/subscribe)
|
|
281
|
+
|
|
247
282
|
## License
|
|
248
283
|
|
|
249
284
|
[MIT](LICENSE)
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# Built-in Bedrock Assistant
|
|
2
|
+
# Uses Meta Llama 3.2 1B - lightweight and cheap model on Bedrock
|
|
3
|
+
|
|
4
|
+
metadata:
|
|
5
|
+
name: "Bedrock Assistant"
|
|
6
|
+
version: "1.0.0"
|
|
7
|
+
description: "Simple assistant using Llama 3.2 1B (lightweight)"
|
|
8
|
+
builtin: true
|
|
9
|
+
|
|
10
|
+
workflow:
|
|
11
|
+
- id: "chat"
|
|
12
|
+
type: "chat"
|
|
13
|
+
config:
|
|
14
|
+
provider: "bedrock"
|
|
15
|
+
model: "us.meta.llama3-2-1b-instruct-v1:0"
|
|
16
|
+
system: |
|
|
17
|
+
You are a helpful, friendly assistant. Be concise and direct.
|
|
18
|
+
Answer in the same language the user writes to you.
|
|
19
|
+
messages: "$input.messages"
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# Built-in OpenRouter Assistant
|
|
2
|
+
# Uses OpenRouter for access to 400+ models
|
|
3
|
+
|
|
4
|
+
metadata:
|
|
5
|
+
name: "OpenRouter Assistant"
|
|
6
|
+
version: "1.0.0"
|
|
7
|
+
builtin: true
|
|
8
|
+
|
|
9
|
+
workflow:
|
|
10
|
+
- id: "chat-interaction"
|
|
11
|
+
type: "chat"
|
|
12
|
+
config:
|
|
13
|
+
provider: "openrouter"
|
|
14
|
+
model: "qwen/qwen3-coder:free"
|
|
15
|
+
system: "You are a helpful assistant."
|
|
16
|
+
messages: "$input.messages"
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# Built-in Streaming Assistant
|
|
2
|
+
# Uses Google Gemini for fast, streaming responses
|
|
3
|
+
|
|
4
|
+
metadata:
|
|
5
|
+
name: "Streaming Assistant"
|
|
6
|
+
version: "1.0.0"
|
|
7
|
+
builtin: true
|
|
8
|
+
|
|
9
|
+
workflow:
|
|
10
|
+
- id: "chat-interaction"
|
|
11
|
+
type: "chat"
|
|
12
|
+
config:
|
|
13
|
+
provider: "google"
|
|
14
|
+
model: "gemini-2.0-flash-exp"
|
|
15
|
+
system: "You are a helpful assistant."
|
|
16
|
+
messages: "$input.messages"
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Built-in Agents Registry
|
|
3
|
+
*
|
|
4
|
+
* Lists all agents bundled with the beddel package.
|
|
5
|
+
* These are available automatically without user configuration.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* List of built-in agent IDs available in the package
|
|
9
|
+
*/
|
|
10
|
+
export declare const BUILTIN_AGENTS: readonly ["assistant", "assistant-bedrock", "assistant-openrouter", "text-generator", "multi-step-assistant"];
|
|
11
|
+
export type BuiltinAgentId = typeof BUILTIN_AGENTS[number];
|
|
12
|
+
/**
|
|
13
|
+
* Get the absolute path to the built-in agents directory
|
|
14
|
+
*/
|
|
15
|
+
export declare function getBuiltinAgentsPath(): string;
|
|
16
|
+
/**
|
|
17
|
+
* Check if an agent ID is a built-in agent
|
|
18
|
+
*/
|
|
19
|
+
export declare function isBuiltinAgent(agentId: string): agentId is BuiltinAgentId;
|
|
20
|
+
/**
|
|
21
|
+
* Get the full path to a built-in agent YAML file
|
|
22
|
+
*/
|
|
23
|
+
export declare function getBuiltinAgentPath(agentId: BuiltinAgentId): string;
|
|
24
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/agents/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AASH;;GAEG;AACH,eAAO,MAAM,cAAc,+GAMjB,CAAC;AAEX,MAAM,MAAM,cAAc,GAAG,OAAO,cAAc,CAAC,MAAM,CAAC,CAAC;AAE3D;;GAEG;AACH,wBAAgB,oBAAoB,IAAI,MAAM,CAE7C;AAED;;GAEG;AACH,wBAAgB,cAAc,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,IAAI,cAAc,CAEzE;AAED;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,cAAc,GAAG,MAAM,CAEnE"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Built-in Agents Registry
|
|
3
|
+
*
|
|
4
|
+
* Lists all agents bundled with the beddel package.
|
|
5
|
+
* These are available automatically without user configuration.
|
|
6
|
+
*/
|
|
7
|
+
import { fileURLToPath } from 'url';
|
|
8
|
+
import { dirname, join } from 'path';
|
|
9
|
+
// Get the directory where built-in agents are located
|
|
10
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
11
|
+
const __dirname = dirname(__filename);
|
|
12
|
+
/**
|
|
13
|
+
* List of built-in agent IDs available in the package
|
|
14
|
+
*/
|
|
15
|
+
export const BUILTIN_AGENTS = [
|
|
16
|
+
'assistant',
|
|
17
|
+
'assistant-bedrock',
|
|
18
|
+
'assistant-openrouter',
|
|
19
|
+
'text-generator',
|
|
20
|
+
'multi-step-assistant',
|
|
21
|
+
];
|
|
22
|
+
/**
|
|
23
|
+
* Get the absolute path to the built-in agents directory
|
|
24
|
+
*/
|
|
25
|
+
export function getBuiltinAgentsPath() {
|
|
26
|
+
return __dirname;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Check if an agent ID is a built-in agent
|
|
30
|
+
*/
|
|
31
|
+
export function isBuiltinAgent(agentId) {
|
|
32
|
+
return BUILTIN_AGENTS.includes(agentId);
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Get the full path to a built-in agent YAML file
|
|
36
|
+
*/
|
|
37
|
+
export function getBuiltinAgentPath(agentId) {
|
|
38
|
+
return join(__dirname, `${agentId}.yaml`);
|
|
39
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
# Multi-Step Text Analyzer
|
|
2
|
+
# Pipeline: Generate Text β Extract Entities β Classify Sentiment β Structured Summary
|
|
3
|
+
|
|
4
|
+
metadata:
|
|
5
|
+
name: "Multi-Step Text Analyzer"
|
|
6
|
+
version: "1.0.0"
|
|
7
|
+
builtin: true
|
|
8
|
+
description: "4-step pipeline demonstrating variable passing between steps"
|
|
9
|
+
|
|
10
|
+
workflow:
|
|
11
|
+
# Step 1: Generate sample text using text-generator agent
|
|
12
|
+
# Input: { messages: [{ role: "user", content: "Generate 200 chars about space exploration" }] }
|
|
13
|
+
- id: "generate-text"
|
|
14
|
+
type: "call-agent"
|
|
15
|
+
config:
|
|
16
|
+
agentId: "text-generator"
|
|
17
|
+
input:
|
|
18
|
+
messages: "$input.messages"
|
|
19
|
+
result: "generatedText"
|
|
20
|
+
|
|
21
|
+
# Step 2: Extract entities and topics from the generated text
|
|
22
|
+
- id: "extract-entities"
|
|
23
|
+
type: "llm"
|
|
24
|
+
config:
|
|
25
|
+
provider: "google"
|
|
26
|
+
model: "gemini-2.0-flash-exp"
|
|
27
|
+
system: |
|
|
28
|
+
You are an entity extraction specialist. Analyze the given text and extract:
|
|
29
|
+
- Named entities (people, places, organizations, dates)
|
|
30
|
+
- Main topics/themes
|
|
31
|
+
- Key concepts
|
|
32
|
+
|
|
33
|
+
Output ONLY valid JSON (no markdown, no explanation):
|
|
34
|
+
{"entities":{"people":[],"places":[],"organizations":[],"dates":[]},"topics":[],"concepts":[]}
|
|
35
|
+
messages:
|
|
36
|
+
- role: "user"
|
|
37
|
+
content: "$stepResult.generatedText.generatedText.text"
|
|
38
|
+
result: "entities"
|
|
39
|
+
|
|
40
|
+
# Step 3: Classify sentiment of the text
|
|
41
|
+
- id: "classify-sentiment"
|
|
42
|
+
type: "llm"
|
|
43
|
+
config:
|
|
44
|
+
provider: "google"
|
|
45
|
+
model: "gemini-2.0-flash-exp"
|
|
46
|
+
system: |
|
|
47
|
+
You are a sentiment analysis expert. Analyze the emotional tone of the text.
|
|
48
|
+
|
|
49
|
+
Output ONLY valid JSON (no markdown, no explanation):
|
|
50
|
+
{"overall":"positive|negative|neutral|mixed","confidence":0.8,"emotions":["joy"],"tone":"formal"}
|
|
51
|
+
messages:
|
|
52
|
+
- role: "user"
|
|
53
|
+
content: "$stepResult.generatedText.generatedText.text"
|
|
54
|
+
result: "sentiment"
|
|
55
|
+
|
|
56
|
+
# Step 4: Generate structured summary combining all analysis
|
|
57
|
+
- id: "final-summary"
|
|
58
|
+
type: "output-generator"
|
|
59
|
+
config:
|
|
60
|
+
template:
|
|
61
|
+
originalText: "$stepResult.generatedText.generatedText.text"
|
|
62
|
+
entities: "$stepResult.entities.text"
|
|
63
|
+
sentiment: "$stepResult.sentiment.text"
|
|
64
|
+
pipeline:
|
|
65
|
+
steps: 4
|
|
66
|
+
status: "completed"
|
|
67
|
+
result: "finalReport"
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# Text Generator Agent
|
|
2
|
+
# Generates text based on length and subject parameters
|
|
3
|
+
# Uses lightweight model for efficiency
|
|
4
|
+
|
|
5
|
+
metadata:
|
|
6
|
+
name: "Text Generator"
|
|
7
|
+
version: "1.0.0"
|
|
8
|
+
builtin: true
|
|
9
|
+
description: "Generates text with specified length and subject"
|
|
10
|
+
|
|
11
|
+
workflow:
|
|
12
|
+
- id: "generate-text"
|
|
13
|
+
type: "llm"
|
|
14
|
+
config:
|
|
15
|
+
provider: "google"
|
|
16
|
+
model: "gemini-2.0-flash-exp"
|
|
17
|
+
system: |
|
|
18
|
+
You are a text generator. Generate creative, coherent text based on the given parameters.
|
|
19
|
+
|
|
20
|
+
RULES:
|
|
21
|
+
- Generate approximately the requested number of characters (can vary Β±20%)
|
|
22
|
+
- Stay focused on the given subject/theme
|
|
23
|
+
- Write in a natural, engaging style
|
|
24
|
+
- Output ONLY the generated text, no explanations or meta-commentary
|
|
25
|
+
- Do not use markdown formatting unless specifically requested
|
|
26
|
+
messages: "$input.messages"
|
|
27
|
+
result: "generatedText"
|
package/dist/index.d.ts
CHANGED
|
@@ -16,5 +16,7 @@ export { toolRegistry, registerTool } from './tools';
|
|
|
16
16
|
export type { ToolImplementation } from './tools';
|
|
17
17
|
export { providerRegistry, registerProvider, createModel } from './providers';
|
|
18
18
|
export type { ProviderImplementation, ProviderConfig } from './providers';
|
|
19
|
+
export { BUILTIN_AGENTS, getBuiltinAgentsPath, getBuiltinAgentPath, isBuiltinAgent } from './agents';
|
|
20
|
+
export type { BuiltinAgentId } from './agents';
|
|
19
21
|
export type { ParsedYaml, WorkflowStep, StepConfig, YamlMetadata, ExecutionContext, PrimitiveHandler, } from './types';
|
|
20
22
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAGH,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AACnD,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAC5D,OAAO,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AAIvD,OAAO,EAAE,eAAe,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AAGlE,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACrD,YAAY,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAGlD,OAAO,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC9E,YAAY,EAAE,sBAAsB,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAG1E,YAAY,EACR,UAAU,EACV,YAAY,EACZ,UAAU,EACV,YAAY,EACZ,gBAAgB,EAChB,gBAAgB,GACnB,MAAM,SAAS,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAGH,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AACnD,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAC5D,OAAO,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AAIvD,OAAO,EAAE,eAAe,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AAGlE,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACrD,YAAY,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAGlD,OAAO,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC9E,YAAY,EAAE,sBAAsB,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAG1E,OAAO,EACH,cAAc,EACd,oBAAoB,EACpB,mBAAmB,EACnB,cAAc,EACjB,MAAM,UAAU,CAAC;AAClB,YAAY,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAG/C,YAAY,EACR,UAAU,EACV,YAAY,EACZ,UAAU,EACV,YAAY,EACZ,gBAAgB,EAChB,gBAAgB,GACnB,MAAM,SAAS,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -18,3 +18,5 @@ export { handlerRegistry, registerPrimitive } from './primitives';
|
|
|
18
18
|
export { toolRegistry, registerTool } from './tools';
|
|
19
19
|
// Providers registry (for custom LLM provider registration)
|
|
20
20
|
export { providerRegistry, registerProvider, createModel } from './providers';
|
|
21
|
+
// Built-in agents registry
|
|
22
|
+
export { BUILTIN_AGENTS, getBuiltinAgentsPath, getBuiltinAgentPath, isBuiltinAgent } from './agents';
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Beddel Protocol - Call Agent Primitive
|
|
3
|
+
*
|
|
4
|
+
* Enables recursive workflow execution by calling other agents.
|
|
5
|
+
* This primitive loads and executes another agent's workflow,
|
|
6
|
+
* passing input and returning the result.
|
|
7
|
+
*
|
|
8
|
+
* Server-only: Uses loadYaml and WorkflowExecutor.
|
|
9
|
+
*/
|
|
10
|
+
import type { PrimitiveHandler } from '../types';
|
|
11
|
+
/**
|
|
12
|
+
* Call Agent Primitive Handler
|
|
13
|
+
*
|
|
14
|
+
* Loads another agent's YAML and executes its workflow.
|
|
15
|
+
*
|
|
16
|
+
* IMPORTANT: If the called agent returns a Response (streaming),
|
|
17
|
+
* this primitive will return that Response, causing the parent
|
|
18
|
+
* workflow to also return immediately.
|
|
19
|
+
*
|
|
20
|
+
* For multi-step workflows, ensure called agents use stream: false
|
|
21
|
+
* so their results can be captured and passed to subsequent steps.
|
|
22
|
+
*
|
|
23
|
+
* @param config - Step configuration (agentId, input)
|
|
24
|
+
* @param context - Execution context with input and variables
|
|
25
|
+
* @returns Result from called agent (Response or Record)
|
|
26
|
+
*/
|
|
27
|
+
export declare const callAgentPrimitive: PrimitiveHandler;
|
|
28
|
+
//# sourceMappingURL=call-agent.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"call-agent.d.ts","sourceRoot":"","sources":["../../src/primitives/call-agent.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAgC,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAwD/E;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,kBAAkB,EAAE,gBAyBhC,CAAC"}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Beddel Protocol - Call Agent Primitive
|
|
3
|
+
*
|
|
4
|
+
* Enables recursive workflow execution by calling other agents.
|
|
5
|
+
* This primitive loads and executes another agent's workflow,
|
|
6
|
+
* passing input and returning the result.
|
|
7
|
+
*
|
|
8
|
+
* Server-only: Uses loadYaml and WorkflowExecutor.
|
|
9
|
+
*/
|
|
10
|
+
import { loadYaml } from '../core/parser';
|
|
11
|
+
import { WorkflowExecutor } from '../core/workflow';
|
|
12
|
+
import { resolveVariables } from '../core/variable-resolver';
|
|
13
|
+
import { join } from 'path';
|
|
14
|
+
import { access } from 'fs/promises';
|
|
15
|
+
import { getBuiltinAgentsPath } from '../agents';
|
|
16
|
+
/**
|
|
17
|
+
* Check if a file exists at the given path
|
|
18
|
+
*/
|
|
19
|
+
async function fileExists(path) {
|
|
20
|
+
try {
|
|
21
|
+
await access(path);
|
|
22
|
+
return true;
|
|
23
|
+
}
|
|
24
|
+
catch {
|
|
25
|
+
return false;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Resolve agent path with fallback chain:
|
|
30
|
+
* 1. User agents (agentsPath) - allows override
|
|
31
|
+
* 2. Built-in agents (package) - fallback
|
|
32
|
+
*/
|
|
33
|
+
async function resolveAgentPath(agentId, agentsPath) {
|
|
34
|
+
// 1. First: try user agents
|
|
35
|
+
const userPath = join(process.cwd(), agentsPath, `${agentId}.yaml`);
|
|
36
|
+
if (await fileExists(userPath)) {
|
|
37
|
+
return userPath;
|
|
38
|
+
}
|
|
39
|
+
// 2. Fallback: built-in agents from package
|
|
40
|
+
const builtinPath = join(getBuiltinAgentsPath(), `${agentId}.yaml`);
|
|
41
|
+
if (await fileExists(builtinPath)) {
|
|
42
|
+
return builtinPath;
|
|
43
|
+
}
|
|
44
|
+
throw new Error(`[Beddel] Agent not found: ${agentId}`);
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Call Agent Primitive Handler
|
|
48
|
+
*
|
|
49
|
+
* Loads another agent's YAML and executes its workflow.
|
|
50
|
+
*
|
|
51
|
+
* IMPORTANT: If the called agent returns a Response (streaming),
|
|
52
|
+
* this primitive will return that Response, causing the parent
|
|
53
|
+
* workflow to also return immediately.
|
|
54
|
+
*
|
|
55
|
+
* For multi-step workflows, ensure called agents use stream: false
|
|
56
|
+
* so their results can be captured and passed to subsequent steps.
|
|
57
|
+
*
|
|
58
|
+
* @param config - Step configuration (agentId, input)
|
|
59
|
+
* @param context - Execution context with input and variables
|
|
60
|
+
* @returns Result from called agent (Response or Record)
|
|
61
|
+
*/
|
|
62
|
+
export const callAgentPrimitive = async (config, context) => {
|
|
63
|
+
const callConfig = config;
|
|
64
|
+
if (!callConfig.agentId) {
|
|
65
|
+
throw new Error('[Beddel] call-agent requires agentId in config');
|
|
66
|
+
}
|
|
67
|
+
// Resolve the input to pass to the agent
|
|
68
|
+
const agentInput = callConfig.input
|
|
69
|
+
? resolveVariables(callConfig.input, context)
|
|
70
|
+
: context.input;
|
|
71
|
+
// Resolve agent path
|
|
72
|
+
const agentsPath = callConfig.agentsPath || 'src/agents';
|
|
73
|
+
const agentPath = await resolveAgentPath(callConfig.agentId, agentsPath);
|
|
74
|
+
// Load and execute the agent
|
|
75
|
+
const yaml = await loadYaml(agentPath);
|
|
76
|
+
const executor = new WorkflowExecutor(yaml);
|
|
77
|
+
const result = await executor.execute(agentInput);
|
|
78
|
+
return result;
|
|
79
|
+
};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Beddel Protocol - Chat Primitive
|
|
3
|
+
*
|
|
4
|
+
* Primitive for frontend chat interfaces using useChat hook.
|
|
5
|
+
* ALWAYS streams responses for responsive UX.
|
|
6
|
+
* Expects UIMessage format (with 'parts' array) and converts to ModelMessage.
|
|
7
|
+
*
|
|
8
|
+
* Use this primitive when:
|
|
9
|
+
* - Input comes from useChat frontend hook
|
|
10
|
+
* - You need streaming responses to the client
|
|
11
|
+
*
|
|
12
|
+
* Server-only: Uses Vercel AI SDK Core.
|
|
13
|
+
*/
|
|
14
|
+
import type { PrimitiveHandler } from '../types';
|
|
15
|
+
/**
|
|
16
|
+
* Chat Primitive Handler
|
|
17
|
+
*
|
|
18
|
+
* Converts UIMessage[] (from useChat) to ModelMessage[] and streams response.
|
|
19
|
+
* Always uses streaming mode for responsive frontend UX.
|
|
20
|
+
*
|
|
21
|
+
* @param config - Step configuration from YAML
|
|
22
|
+
* @param context - Execution context with input and variables
|
|
23
|
+
* @returns Response (always streaming)
|
|
24
|
+
*/
|
|
25
|
+
export declare const chatPrimitive: PrimitiveHandler;
|
|
26
|
+
//# sourceMappingURL=chat.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chat.d.ts","sourceRoot":"","sources":["../../src/primitives/chat.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAQH,OAAO,KAAK,EAAgC,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAK/E;;;;;;;;;GASG;AACH,eAAO,MAAM,aAAa,EAAE,gBA2C3B,CAAC"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Beddel Protocol - Chat Primitive
|
|
3
|
+
*
|
|
4
|
+
* Primitive for frontend chat interfaces using useChat hook.
|
|
5
|
+
* ALWAYS streams responses for responsive UX.
|
|
6
|
+
* Expects UIMessage format (with 'parts' array) and converts to ModelMessage.
|
|
7
|
+
*
|
|
8
|
+
* Use this primitive when:
|
|
9
|
+
* - Input comes from useChat frontend hook
|
|
10
|
+
* - You need streaming responses to the client
|
|
11
|
+
*
|
|
12
|
+
* Server-only: Uses Vercel AI SDK Core.
|
|
13
|
+
*/
|
|
14
|
+
import { streamText, convertToModelMessages, stepCountIs, } from 'ai';
|
|
15
|
+
import { resolveVariables } from '../core/variable-resolver';
|
|
16
|
+
import { createModel } from '../providers';
|
|
17
|
+
import { mapTools, callbackRegistry } from './llm-core';
|
|
18
|
+
/**
|
|
19
|
+
* Chat Primitive Handler
|
|
20
|
+
*
|
|
21
|
+
* Converts UIMessage[] (from useChat) to ModelMessage[] and streams response.
|
|
22
|
+
* Always uses streaming mode for responsive frontend UX.
|
|
23
|
+
*
|
|
24
|
+
* @param config - Step configuration from YAML
|
|
25
|
+
* @param context - Execution context with input and variables
|
|
26
|
+
* @returns Response (always streaming)
|
|
27
|
+
*/
|
|
28
|
+
export const chatPrimitive = async (config, context) => {
|
|
29
|
+
const llmConfig = config;
|
|
30
|
+
const model = createModel(llmConfig.provider || 'google', {
|
|
31
|
+
model: llmConfig.model || 'gemini-1.5-flash',
|
|
32
|
+
});
|
|
33
|
+
// Resolve and convert UIMessage to ModelMessage
|
|
34
|
+
const uiMessages = resolveVariables(llmConfig.messages, context);
|
|
35
|
+
const messages = await convertToModelMessages(uiMessages);
|
|
36
|
+
const hasTools = llmConfig.tools && llmConfig.tools.length > 0;
|
|
37
|
+
const tools = hasTools ? mapTools(llmConfig.tools) : undefined;
|
|
38
|
+
const result = streamText({
|
|
39
|
+
model,
|
|
40
|
+
messages,
|
|
41
|
+
system: llmConfig.system,
|
|
42
|
+
stopWhen: hasTools ? stepCountIs(5) : undefined,
|
|
43
|
+
tools,
|
|
44
|
+
onFinish: async ({ text, finishReason, usage, totalUsage, steps, response }) => {
|
|
45
|
+
if (llmConfig.onFinish) {
|
|
46
|
+
const callback = callbackRegistry[llmConfig.onFinish];
|
|
47
|
+
if (callback) {
|
|
48
|
+
await callback({ text, finishReason, usage, totalUsage, steps, response });
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
onError: ({ error }) => {
|
|
53
|
+
if (llmConfig.onError) {
|
|
54
|
+
const callback = callbackRegistry[llmConfig.onError];
|
|
55
|
+
if (callback) {
|
|
56
|
+
callback({ error });
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
console.error('[Beddel] Stream error:', error);
|
|
60
|
+
},
|
|
61
|
+
});
|
|
62
|
+
return result.toUIMessageStreamResponse();
|
|
63
|
+
};
|
|
@@ -3,35 +3,29 @@
|
|
|
3
3
|
*
|
|
4
4
|
* This registry maps step types to their handler implementations.
|
|
5
5
|
* Following Expansion Pack Pattern from BMAD-METHODβ’ for extensibility.
|
|
6
|
-
* See: https://github.com/bmadcode/bmad-method
|
|
7
6
|
*
|
|
8
7
|
* Server-only: Handlers may use Node.js APIs and external services.
|
|
9
8
|
*/
|
|
10
9
|
import type { PrimitiveHandler } from '../types';
|
|
11
|
-
export {
|
|
10
|
+
export { registerCallback, callbackRegistry } from './llm-core';
|
|
11
|
+
export { chatPrimitive } from './chat';
|
|
12
|
+
export { llmPrimitive } from './llm';
|
|
13
|
+
export { callAgentPrimitive } from './call-agent';
|
|
12
14
|
/**
|
|
13
15
|
* Registry of primitive handlers keyed by step type.
|
|
14
16
|
*
|
|
15
|
-
*
|
|
16
|
-
* - '
|
|
17
|
-
* - '
|
|
18
|
-
* - '
|
|
17
|
+
* Primitives:
|
|
18
|
+
* - 'chat': Frontend chat interface (UIMessage with 'parts' β converts to ModelMessage)
|
|
19
|
+
* - 'llm': Workflow/API calls (ModelMessage with 'content' β direct use)
|
|
20
|
+
* - 'output-generator': Deterministic variable mapping
|
|
21
|
+
* - 'call-agent': Sub-agent invocation
|
|
19
22
|
*/
|
|
20
23
|
export declare const handlerRegistry: Record<string, PrimitiveHandler>;
|
|
21
24
|
/**
|
|
22
25
|
* Register a custom primitive handler in the registry.
|
|
23
|
-
* Allows consumers to extend Beddel with domain-specific primitives.
|
|
24
26
|
*
|
|
25
27
|
* @param type - Step type identifier (e.g., 'my-custom-primitive')
|
|
26
28
|
* @param handler - PrimitiveHandler function
|
|
27
|
-
*
|
|
28
|
-
* @example
|
|
29
|
-
* import { registerPrimitive } from 'beddel';
|
|
30
|
-
*
|
|
31
|
-
* registerPrimitive('http-fetch', async (config, context) => {
|
|
32
|
-
* const response = await fetch(config.url);
|
|
33
|
-
* return { data: await response.json() };
|
|
34
|
-
* });
|
|
35
29
|
*/
|
|
36
30
|
export declare function registerPrimitive(type: string, handler: PrimitiveHandler): void;
|
|
37
31
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/primitives/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/primitives/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,gBAAgB,EAAgC,MAAM,UAAU,CAAC;AAO/E,OAAO,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAChE,OAAO,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAC;AACvC,OAAO,EAAE,YAAY,EAAE,MAAM,OAAO,CAAC;AACrC,OAAO,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAElD;;;;;;;;GAQG;AACH,eAAO,MAAM,eAAe,EAAE,MAAM,CAAC,MAAM,EAAE,gBAAgB,CA0B5D,CAAC;AAEF;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,gBAAgB,GAAG,IAAI,CAK/E"}
|