briyah 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/.prettierrc +7 -7
- package/README.md +394 -0
- package/dist/server/src/ai/LLM/deepseek.service.js +1 -1
- package/dist/server/src/room/artifact-store.service.js +4 -4
- package/eslint.config.js +29 -29
- package/package.json +3 -2
- package/dist/ai/LLM/anthropic.module.d.ts +0 -2
- package/dist/ai/LLM/anthropic.module.js +0 -21
- package/dist/ai/LLM/anthropic.service.d.ts +0 -27
- package/dist/ai/LLM/anthropic.service.js +0 -329
- package/dist/ai/LLM/base-ai.service.d.ts +0 -45
- package/dist/ai/LLM/base-ai.service.js +0 -409
- package/dist/ai/LLM/deepseek.module.d.ts +0 -2
- package/dist/ai/LLM/deepseek.module.js +0 -21
- package/dist/ai/LLM/deepseek.service.d.ts +0 -15
- package/dist/ai/LLM/deepseek.service.js +0 -279
- package/dist/ai/LLM/fal.module.d.ts +0 -2
- package/dist/ai/LLM/fal.module.js +0 -21
- package/dist/ai/LLM/fal.service.d.ts +0 -17
- package/dist/ai/LLM/fal.service.js +0 -314
- package/dist/ai/LLM/googleai.module.d.ts +0 -2
- package/dist/ai/LLM/googleai.module.js +0 -21
- package/dist/ai/LLM/googleai.service.d.ts +0 -20
- package/dist/ai/LLM/googleai.service.js +0 -271
- package/dist/ai/LLM/grok.module.d.ts +0 -2
- package/dist/ai/LLM/grok.module.js +0 -21
- package/dist/ai/LLM/grok.service.d.ts +0 -14
- package/dist/ai/LLM/grok.service.js +0 -263
- package/dist/ai/LLM/mock.module.d.ts +0 -2
- package/dist/ai/LLM/mock.module.js +0 -21
- package/dist/ai/LLM/mock.service.d.ts +0 -13
- package/dist/ai/LLM/mock.service.js +0 -194
- package/dist/ai/LLM/openai.module.d.ts +0 -2
- package/dist/ai/LLM/openai.module.js +0 -21
- package/dist/ai/LLM/openai.service.d.ts +0 -21
- package/dist/ai/LLM/openai.service.js +0 -421
- package/dist/ai/LLM/together.module.d.ts +0 -2
- package/dist/ai/LLM/together.module.js +0 -21
- package/dist/ai/LLM/together.service.d.ts +0 -18
- package/dist/ai/LLM/together.service.js +0 -285
- package/dist/ai/LLM/vertexai.module.d.ts +0 -2
- package/dist/ai/LLM/vertexai.module.js +0 -21
- package/dist/ai/LLM/vertexai.service.d.ts +0 -17
- package/dist/ai/LLM/vertexai.service.js +0 -323
- package/dist/ai/agent-config.d.ts +0 -32
- package/dist/ai/agent-config.js +0 -2
- package/dist/ai/agent-factory.d.ts +0 -15
- package/dist/ai/agent-factory.js +0 -24
- package/dist/ai/agent-message.service.d.ts +0 -9
- package/dist/ai/agent-message.service.js +0 -56
- package/dist/ai/agent-store.module.d.ts +0 -2
- package/dist/ai/agent-store.module.js +0 -21
- package/dist/ai/agent-store.service.d.ts +0 -31
- package/dist/ai/agent-store.service.js +0 -352
- package/dist/ai/agent.d.ts +0 -75
- package/dist/ai/agent.js +0 -174
- package/dist/ai/ai-factory.module.d.ts +0 -2
- package/dist/ai/ai-factory.module.js +0 -40
- package/dist/ai/ai-factory.service.d.ts +0 -24
- package/dist/ai/ai-factory.service.js +0 -94
- package/dist/ai/artifact.module.d.ts +0 -2
- package/dist/ai/artifact.module.js +0 -22
- package/dist/ai/artifact.service.d.ts +0 -21
- package/dist/ai/artifact.service.js +0 -239
- package/dist/ai/attached-file.module.d.ts +0 -2
- package/dist/ai/attached-file.module.js +0 -22
- package/dist/ai/attached-file.service.d.ts +0 -35
- package/dist/ai/attached-file.service.js +0 -253
- package/dist/ai/model_prices.d.ts +0 -2
- package/dist/ai/model_prices.js +0 -54
- package/dist/ai/published-agents.service.d.ts +0 -13
- package/dist/ai/published-agents.service.js +0 -118
- package/dist/app/balance-message.service.d.ts +0 -8
- package/dist/app/balance-message.service.js +0 -45
- package/dist/app/balance.module.d.ts +0 -2
- package/dist/app/balance.module.js +0 -20
- package/dist/app/balance.service.d.ts +0 -18
- package/dist/app/balance.service.js +0 -158
- package/dist/app/stripe.controller.d.ts +0 -31
- package/dist/app/stripe.controller.js +0 -150
- package/dist/app/stripe.module.d.ts +0 -2
- package/dist/app/stripe.module.js +0 -22
- package/dist/app/stripe.service.d.ts +0 -28
- package/dist/app/stripe.service.js +0 -198
- package/dist/app/transaction.service.d.ts +0 -15
- package/dist/app/transaction.service.js +0 -139
- package/dist/app/user-service-factory.d.ts +0 -21
- package/dist/app/user-service-factory.js +0 -81
- package/dist/app/user-service-manager.d.ts +0 -28
- package/dist/app/user-service-manager.js +0 -102
- package/dist/app.controller.d.ts +0 -232
- package/dist/app.controller.js +0 -2536
- package/dist/app.module.d.ts +0 -2
- package/dist/app.module.js +0 -45
- package/dist/app.service.d.ts +0 -186
- package/dist/app.service.js +0 -1334
- package/dist/auth/agent-access.decorator.d.ts +0 -2
- package/dist/auth/agent-access.decorator.js +0 -10
- package/dist/auth/auth.controller.d.ts +0 -38
- package/dist/auth/auth.controller.js +0 -356
- package/dist/auth/auth.module.d.ts +0 -2
- package/dist/auth/auth.module.js +0 -55
- package/dist/auth/auth.service.d.ts +0 -14
- package/dist/auth/auth.service.js +0 -84
- package/dist/auth/dto/bot-login.dto.d.ts +0 -4
- package/dist/auth/dto/bot-login.dto.js +0 -2
- package/dist/auth/dto/password-reset.dto.d.ts +0 -11
- package/dist/auth/dto/password-reset.dto.js +0 -2
- package/dist/auth/dto/phone-login.dto.d.ts +0 -8
- package/dist/auth/dto/phone-login.dto.js +0 -2
- package/dist/auth/dto/phone-verification.dto.d.ts +0 -9
- package/dist/auth/dto/phone-verification.dto.js +0 -2
- package/dist/auth/jwt-auth.guard.d.ts +0 -13
- package/dist/auth/jwt-auth.guard.js +0 -143
- package/dist/auth/jwt.strategy.d.ts +0 -17
- package/dist/auth/jwt.strategy.js +0 -45
- package/dist/auth/phone-validation.service.d.ts +0 -7
- package/dist/auth/phone-validation.service.js +0 -50
- package/dist/auth/public.decorator.d.ts +0 -2
- package/dist/auth/public.decorator.js +0 -7
- package/dist/auth/rate-limit.service.d.ts +0 -16
- package/dist/auth/rate-limit.service.js +0 -84
- package/dist/auth/room-access.decorator.d.ts +0 -2
- package/dist/auth/room-access.decorator.js +0 -10
- package/dist/auth/scopes.decorator.d.ts +0 -2
- package/dist/auth/scopes.decorator.js +0 -7
- package/dist/auth/scopes.guard.d.ts +0 -9
- package/dist/auth/scopes.guard.js +0 -82
- package/dist/auth/session.guard.d.ts +0 -7
- package/dist/auth/session.guard.js +0 -55
- package/dist/auth/twilio.service.d.ts +0 -15
- package/dist/auth/twilio.service.js +0 -139
- package/dist/auth/users.service.d.ts +0 -24
- package/dist/auth/users.service.js +0 -149
- package/dist/common/errors.d.ts +0 -12
- package/dist/common/errors.js +0 -43
- package/dist/config/configuration.module.d.ts +0 -2
- package/dist/config/configuration.module.js +0 -20
- package/dist/config/configuration.service.d.ts +0 -26
- package/dist/config/configuration.service.js +0 -131
- package/dist/main.js +0 -15749
- package/dist/room/artifact-store.service.d.ts +0 -15
- package/dist/room/artifact-store.service.js +0 -226
- package/dist/room/artifact.d.ts +0 -6
- package/dist/room/artifact.js +0 -2
- package/dist/room/message.d.ts +0 -19
- package/dist/room/message.js +0 -70
- package/dist/room/published-rooms.service.d.ts +0 -12
- package/dist/room/published-rooms.service.js +0 -108
- package/dist/room/room-config.d.ts +0 -12
- package/dist/room/room-config.js +0 -2
- package/dist/room/room-factory.d.ts +0 -7
- package/dist/room/room-factory.js +0 -16
- package/dist/room/room-message.module.d.ts +0 -2
- package/dist/room/room-message.module.js +0 -21
- package/dist/room/room-message.service.d.ts +0 -8
- package/dist/room/room-message.service.js +0 -44
- package/dist/room/room-store.module.d.ts +0 -2
- package/dist/room/room-store.module.js +0 -25
- package/dist/room/room-store.service.d.ts +0 -38
- package/dist/room/room-store.service.js +0 -353
- package/dist/room/room.d.ts +0 -107
- package/dist/room/room.js +0 -833
- package/dist/sdk/briyah-config.d.ts +0 -13
- package/dist/sdk/briyah-config.js +0 -32
- package/dist/sdk/briyah.d.ts +0 -36
- package/dist/sdk/briyah.js +0 -122
- package/dist/sdk/index.d.ts +0 -6
- package/dist/sdk/index.js +0 -11
- package/dist/shared/shared.module.d.ts +0 -2
- package/dist/shared/shared.module.js +0 -46
- package/dist/story/story-message.service.d.ts +0 -10
- package/dist/story/story-message.service.js +0 -57
- package/dist/story/story-progress.service.d.ts +0 -8
- package/dist/story/story-progress.service.js +0 -44
- package/dist/story/story-store.module.d.ts +0 -2
- package/dist/story/story-store.module.js +0 -22
- package/dist/story/story-store.service.d.ts +0 -23
- package/dist/story/story-store.service.js +0 -392
- package/dist/story/story.service.d.ts +0 -94
- package/dist/story/story.service.js +0 -1797
package/.prettierrc
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
{
|
|
2
|
-
"singleQuote": true,
|
|
3
|
-
"trailingComma": "all",
|
|
4
|
-
"tabWidth": 4,
|
|
5
|
-
"semi": true,
|
|
6
|
-
"printWidth": 9999
|
|
7
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"singleQuote": true,
|
|
3
|
+
"trailingComma": "all",
|
|
4
|
+
"tabWidth": 4,
|
|
5
|
+
"semi": true,
|
|
6
|
+
"printWidth": 9999
|
|
7
|
+
}
|
package/README.md
ADDED
|
@@ -0,0 +1,394 @@
|
|
|
1
|
+
# Briyah SDK
|
|
2
|
+
|
|
3
|
+
The Briyah SDK provides a clean, easy-to-use interface for integrating the Briyah multi-agent AI system into your applications without requiring NestJS dependency injection setup.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install briyah
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
```typescript
|
|
12
|
+
import { Briyah } from 'briyah';
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Quick Start
|
|
16
|
+
|
|
17
|
+
```typescript
|
|
18
|
+
import { Briyah } from 'briyah';
|
|
19
|
+
|
|
20
|
+
// 1. Create and initialize Briyah instance
|
|
21
|
+
const briyah = new Briyah({
|
|
22
|
+
dataPath: './my-briyah-data',
|
|
23
|
+
userServiceCacheTimeoutMinutes: 30,
|
|
24
|
+
startingBalance: 10.00
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
await briyah.init();
|
|
28
|
+
|
|
29
|
+
// 2. Get user-specific service (userId managed by your app)
|
|
30
|
+
const appService = briyah.getAppService('user-123');
|
|
31
|
+
|
|
32
|
+
// 3. Use full Briyah functionality
|
|
33
|
+
const agent = appService.createAgent(
|
|
34
|
+
'Anthropic',
|
|
35
|
+
'Assistant',
|
|
36
|
+
'Assistant',
|
|
37
|
+
'A helpful AI assistant',
|
|
38
|
+
'claude-3-5-sonnet-20241022'
|
|
39
|
+
);
|
|
40
|
+
|
|
41
|
+
const result = await appService.processText(agent.id, 'Hello! How are you?');
|
|
42
|
+
console.log(result.result);
|
|
43
|
+
|
|
44
|
+
// 4. Cleanup when done
|
|
45
|
+
await briyah.shutdown();
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
## Configuration
|
|
49
|
+
|
|
50
|
+
### BriyahConfigOptions
|
|
51
|
+
|
|
52
|
+
```typescript
|
|
53
|
+
interface BriyahConfigOptions {
|
|
54
|
+
/**
|
|
55
|
+
* Base directory for Briyah data storage
|
|
56
|
+
* Default: './data' relative to process.cwd()
|
|
57
|
+
*/
|
|
58
|
+
dataPath?: string;
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Timeout in minutes for cached user services
|
|
62
|
+
* Default: 30 minutes
|
|
63
|
+
*/
|
|
64
|
+
userServiceCacheTimeoutMinutes?: number;
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Starting balance for new users (in dollars)
|
|
68
|
+
* Default: value from process.env.STARTING_BALANCE
|
|
69
|
+
*/
|
|
70
|
+
startingBalance?: number;
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Override environment variables
|
|
74
|
+
* Useful for testing or multi-instance configurations
|
|
75
|
+
*/
|
|
76
|
+
envOverrides?: Record<string, string>;
|
|
77
|
+
}
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
### Environment Variables
|
|
81
|
+
|
|
82
|
+
Briyah requires certain environment variables to be set:
|
|
83
|
+
|
|
84
|
+
**Required:**
|
|
85
|
+
- `STARTING_BALANCE` - Starting balance for new users (e.g., "10.00")
|
|
86
|
+
|
|
87
|
+
**LLM Provider API Keys** (at least one required):
|
|
88
|
+
- `ANTHROPIC_API_KEY` - For Claude models
|
|
89
|
+
- `OPENAI_API_KEY` - For GPT models
|
|
90
|
+
- `GOOGLE_VERTEX_PROJECT_ID` - For Google Vertex AI
|
|
91
|
+
- `XAI_API_KEY` - For Grok models
|
|
92
|
+
- `DEEPSEEK_API_KEY` - For DeepSeek models
|
|
93
|
+
- `TOGETHER_API_KEY` - For Together AI models
|
|
94
|
+
|
|
95
|
+
**Optional:**
|
|
96
|
+
- `SERVER_DATA_PATH` - Global default data path (overridden by constructor `dataPath`)
|
|
97
|
+
- `USER_SERVICE_CACHE_TIMEOUT_MINUTES` - Cache timeout (overridden by constructor option)
|
|
98
|
+
|
|
99
|
+
## API Reference
|
|
100
|
+
|
|
101
|
+
### Briyah Class
|
|
102
|
+
|
|
103
|
+
#### constructor(options?: BriyahConfigOptions)
|
|
104
|
+
|
|
105
|
+
Creates a new Briyah SDK instance.
|
|
106
|
+
|
|
107
|
+
```typescript
|
|
108
|
+
const briyah = new Briyah({
|
|
109
|
+
dataPath: './briyah-data',
|
|
110
|
+
startingBalance: 10.00
|
|
111
|
+
});
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
#### async init(): Promise\<void\>
|
|
115
|
+
|
|
116
|
+
Initializes the Briyah system. Must be called before using `getAppService()`.
|
|
117
|
+
|
|
118
|
+
```typescript
|
|
119
|
+
await briyah.init();
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
#### getAppService(userId: string): AppService
|
|
123
|
+
|
|
124
|
+
Gets the AppService instance for a specific user. The AppService provides full access to:
|
|
125
|
+
- Agent management
|
|
126
|
+
- Room conversations
|
|
127
|
+
- Story generation
|
|
128
|
+
- Text processing
|
|
129
|
+
- File attachments
|
|
130
|
+
|
|
131
|
+
```typescript
|
|
132
|
+
const appService = briyah.getAppService('user-123');
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
**Throws:** Error if `init()` has not been called.
|
|
136
|
+
|
|
137
|
+
#### removeUserService(userId: string): void
|
|
138
|
+
|
|
139
|
+
Manually removes a user's service from the cache. Useful for:
|
|
140
|
+
- Forcing a fresh AppService instance
|
|
141
|
+
- Cleaning up when a user logs out
|
|
142
|
+
|
|
143
|
+
```typescript
|
|
144
|
+
briyah.removeUserService('user-123');
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
#### getCacheStats()
|
|
148
|
+
|
|
149
|
+
Returns statistics about cached user services.
|
|
150
|
+
|
|
151
|
+
```typescript
|
|
152
|
+
const stats = briyah.getCacheStats();
|
|
153
|
+
console.log(`Cached users: ${stats.cachedUsers}`);
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
#### async shutdown(): Promise\<void\>
|
|
157
|
+
|
|
158
|
+
Shuts down the Briyah system and cleans up resources.
|
|
159
|
+
|
|
160
|
+
```typescript
|
|
161
|
+
await briyah.shutdown();
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
#### isInitialized(): boolean
|
|
165
|
+
|
|
166
|
+
Checks if Briyah has been initialized.
|
|
167
|
+
|
|
168
|
+
```typescript
|
|
169
|
+
if (briyah.isInitialized()) {
|
|
170
|
+
const appService = briyah.getAppService('user-123');
|
|
171
|
+
}
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
### AppService
|
|
175
|
+
|
|
176
|
+
The AppService provides full access to Briyah functionality.
|
|
177
|
+
|
|
178
|
+
**Common operations:**
|
|
179
|
+
|
|
180
|
+
```typescript
|
|
181
|
+
// Agent Management
|
|
182
|
+
const agent = appService.createAgent(provider, name, nickname, description, model);
|
|
183
|
+
const agents = await appService.listAgents();
|
|
184
|
+
await appService.deleteAgent(agentId);
|
|
185
|
+
|
|
186
|
+
// Room Management
|
|
187
|
+
const room = await appService.createRoom(name, goal, agentIds);
|
|
188
|
+
const rooms = await appService.listRooms();
|
|
189
|
+
await appService.sendRoomMessage(roomId, content, sender, action?);
|
|
190
|
+
|
|
191
|
+
// Story Management
|
|
192
|
+
const story = await appService.createStory(name, idea, userCharacterDesc, otherCharactersDesc, storyModel?);
|
|
193
|
+
await appService.progressStory(storyId);
|
|
194
|
+
|
|
195
|
+
// Text Processing
|
|
196
|
+
const result = await appService.processText(agentId, text);
|
|
197
|
+
|
|
198
|
+
// File Attachments
|
|
199
|
+
const attachment = await appService.attachDocument(agentId, fileName, fileData);
|
|
200
|
+
await appService.deleteAttachedFile(agentId, fileName); // by filename
|
|
201
|
+
await appService.deleteAttachedFileById(documentId); // by document ID
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
## Usage Examples
|
|
205
|
+
|
|
206
|
+
### Example 1: Multi-User Setup
|
|
207
|
+
|
|
208
|
+
```typescript
|
|
209
|
+
import { Briyah } from 'briyah';
|
|
210
|
+
|
|
211
|
+
// Initialize once at application startup
|
|
212
|
+
const briyah = new Briyah({
|
|
213
|
+
dataPath: './data/briyah',
|
|
214
|
+
startingBalance: 10.00
|
|
215
|
+
});
|
|
216
|
+
|
|
217
|
+
await briyah.init();
|
|
218
|
+
|
|
219
|
+
// In your route handler or service
|
|
220
|
+
async function handleUserRequest(userId: string, message: string) {
|
|
221
|
+
const appService = briyah.getAppService(userId);
|
|
222
|
+
|
|
223
|
+
// Each user gets their own isolated AppService
|
|
224
|
+
const agents = await appService.listAgents();
|
|
225
|
+
|
|
226
|
+
// ... process user request
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
// Cleanup at application shutdown
|
|
230
|
+
process.on('SIGINT', async () => {
|
|
231
|
+
await briyah.shutdown();
|
|
232
|
+
process.exit(0);
|
|
233
|
+
});
|
|
234
|
+
```
|
|
235
|
+
|
|
236
|
+
### Example 2: Custom Data Path
|
|
237
|
+
|
|
238
|
+
```typescript
|
|
239
|
+
import { Briyah } from 'briyah';
|
|
240
|
+
import path from 'path';
|
|
241
|
+
|
|
242
|
+
const briyah = new Briyah({
|
|
243
|
+
dataPath: path.join(__dirname, '..', 'user-data', 'briyah'),
|
|
244
|
+
userServiceCacheTimeoutMinutes: 60 // 1 hour cache
|
|
245
|
+
});
|
|
246
|
+
|
|
247
|
+
await briyah.init();
|
|
248
|
+
```
|
|
249
|
+
|
|
250
|
+
### Example 3: Testing Configuration
|
|
251
|
+
|
|
252
|
+
```typescript
|
|
253
|
+
import { Briyah } from 'briyah';
|
|
254
|
+
|
|
255
|
+
const testBriyah = new Briyah({
|
|
256
|
+
dataPath: './test-data',
|
|
257
|
+
startingBalance: 100.00,
|
|
258
|
+
userServiceCacheTimeoutMinutes: 5,
|
|
259
|
+
envOverrides: {
|
|
260
|
+
ANTHROPIC_API_KEY: process.env.TEST_ANTHROPIC_KEY,
|
|
261
|
+
OPENAI_API_KEY: process.env.TEST_OPENAI_KEY
|
|
262
|
+
}
|
|
263
|
+
});
|
|
264
|
+
|
|
265
|
+
await testBriyah.init();
|
|
266
|
+
|
|
267
|
+
// Run tests...
|
|
268
|
+
|
|
269
|
+
await testBriyah.shutdown();
|
|
270
|
+
```
|
|
271
|
+
|
|
272
|
+
### Example 4: Agent Creation and Text Processing
|
|
273
|
+
|
|
274
|
+
```typescript
|
|
275
|
+
const appService = briyah.getAppService('user-123');
|
|
276
|
+
|
|
277
|
+
// Create an agent
|
|
278
|
+
const agent = appService.createAgent(
|
|
279
|
+
'Anthropic', // provider
|
|
280
|
+
'Assistant', // name
|
|
281
|
+
'Assistant', // nickname
|
|
282
|
+
'Helpful AI', // description
|
|
283
|
+
'claude-3-5-sonnet-20241022' // model
|
|
284
|
+
);
|
|
285
|
+
|
|
286
|
+
console.log(`Created agent: ${agent.id}`);
|
|
287
|
+
|
|
288
|
+
// Process text with the agent
|
|
289
|
+
const result = await appService.processText(
|
|
290
|
+
agent.id,
|
|
291
|
+
'What is the capital of France?'
|
|
292
|
+
);
|
|
293
|
+
|
|
294
|
+
console.log(`Response: ${result.result}`);
|
|
295
|
+
console.log(`Cost: $${result.totalCost}`);
|
|
296
|
+
console.log(`Tokens: ${(result.totalInputTokens ?? 0) + (result.totalOutputTokens ?? 0)}`);
|
|
297
|
+
```
|
|
298
|
+
|
|
299
|
+
### Example 5: Multi-Agent Room Conversation
|
|
300
|
+
|
|
301
|
+
```typescript
|
|
302
|
+
const appService = briyah.getAppService('user-123');
|
|
303
|
+
|
|
304
|
+
// Create agents
|
|
305
|
+
const analyst = appService.createAgent('OpenAI', 'Analyst', 'Analyst', 'Data analyst', 'gpt-4');
|
|
306
|
+
const writer = appService.createAgent('Anthropic', 'Writer', 'Writer', 'Content writer', 'claude-3-5-sonnet-20241022');
|
|
307
|
+
|
|
308
|
+
// Create a room with both agents
|
|
309
|
+
const room = await appService.createRoom(
|
|
310
|
+
'Analysis Session',
|
|
311
|
+
'Analyze sales data and produce a written summary',
|
|
312
|
+
[analyst.id, writer.id]
|
|
313
|
+
);
|
|
314
|
+
|
|
315
|
+
// Send a message to start the conversation
|
|
316
|
+
await appService.sendRoomMessage(
|
|
317
|
+
room.roomId,
|
|
318
|
+
'Please analyze the sales data for Q4',
|
|
319
|
+
'Analyst',
|
|
320
|
+
'speak'
|
|
321
|
+
);
|
|
322
|
+
|
|
323
|
+
// The agents will automatically respond and interact
|
|
324
|
+
// Check room messages to see the conversation
|
|
325
|
+
const messages = await appService.getRoomMessages(room.roomId);
|
|
326
|
+
console.log(`Messages: ${messages.messages.length}`);
|
|
327
|
+
```
|
|
328
|
+
|
|
329
|
+
## Data Storage
|
|
330
|
+
|
|
331
|
+
Briyah stores data in the following structure:
|
|
332
|
+
|
|
333
|
+
```
|
|
334
|
+
{dataPath}/
|
|
335
|
+
├── common/ # Shared across all users
|
|
336
|
+
│ ├── creds/ # Service account credentials
|
|
337
|
+
│ ├── prices/ # LLM pricing data
|
|
338
|
+
│ ├── prompts/ # Global prompt templates
|
|
339
|
+
│ └── published-agents.json # Published agent mappings
|
|
340
|
+
└── user/
|
|
341
|
+
└── {userId}/ # Per-user data
|
|
342
|
+
├── prompts/ # User-specific prompts
|
|
343
|
+
├── upload/ # User file attachments
|
|
344
|
+
└── userconfig/ # User configuration files
|
|
345
|
+
├── agents.json # User's agents
|
|
346
|
+
├── rooms.json # User's rooms
|
|
347
|
+
├── stories.json # User's stories
|
|
348
|
+
└── balance.json # User's balance
|
|
349
|
+
```
|
|
350
|
+
|
|
351
|
+
## Multi-Instance Support
|
|
352
|
+
|
|
353
|
+
You can create multiple Briyah instances with different configurations:
|
|
354
|
+
|
|
355
|
+
```typescript
|
|
356
|
+
const briyah1 = new Briyah({ dataPath: './data1' });
|
|
357
|
+
const briyah2 = new Briyah({ dataPath: './data2' });
|
|
358
|
+
|
|
359
|
+
await briyah1.init();
|
|
360
|
+
await briyah2.init();
|
|
361
|
+
|
|
362
|
+
// Each instance has isolated data
|
|
363
|
+
const user1Service = briyah1.getAppService('user-123');
|
|
364
|
+
const user2Service = briyah2.getAppService('user-123');
|
|
365
|
+
// These are completely separate services with different data paths
|
|
366
|
+
```
|
|
367
|
+
|
|
368
|
+
**Note:** Singleton services (LLM providers, message emitters) are shared across all Briyah instances within the same process. This is safe because they are stateless or keyed by ID.
|
|
369
|
+
|
|
370
|
+
## Backward Compatibility
|
|
371
|
+
|
|
372
|
+
The Briyah SDK is fully backward compatible with the existing NestJS application. The NestJS app continues to work without any changes, while new applications can use the SDK for simplified integration.
|
|
373
|
+
|
|
374
|
+
## Troubleshooting
|
|
375
|
+
|
|
376
|
+
### "Must call init() before getAppService()"
|
|
377
|
+
|
|
378
|
+
Make sure to call `await briyah.init()` before calling `getAppService()`.
|
|
379
|
+
|
|
380
|
+
### "No LLM provider API keys configured"
|
|
381
|
+
|
|
382
|
+
Set at least one of the required API key environment variables (ANTHROPIC_API_KEY, OPENAI_API_KEY, etc.).
|
|
383
|
+
|
|
384
|
+
### "STARTING_BALANCE environment variable is required"
|
|
385
|
+
|
|
386
|
+
Set the `STARTING_BALANCE` environment variable or pass `startingBalance` in the constructor options.
|
|
387
|
+
|
|
388
|
+
### Cache not working as expected
|
|
389
|
+
|
|
390
|
+
Check the cache statistics with `getCacheStats()` and adjust `userServiceCacheTimeoutMinutes` in the constructor options.
|
|
391
|
+
|
|
392
|
+
## Support
|
|
393
|
+
|
|
394
|
+
For issues or questions, please refer to the main Briyah documentation or create an issue in the repository.
|
|
@@ -15,7 +15,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
15
15
|
exports.DeepSeekAiService = void 0;
|
|
16
16
|
const common_1 = require("@nestjs/common");
|
|
17
17
|
const deepseek_1 = require("@ai-sdk/deepseek");
|
|
18
|
-
const ai_1 = require("
|
|
18
|
+
const ai_1 = require("ai");
|
|
19
19
|
const base_ai_service_1 = require("./base-ai.service");
|
|
20
20
|
const zod_1 = require("zod");
|
|
21
21
|
const model_prices_1 = __importDefault(require("../model_prices"));
|
|
@@ -210,10 +210,10 @@ let ArtifactStoreService = ArtifactStoreService_1 = class ArtifactStoreService {
|
|
|
210
210
|
const viewersStr = artifact.viewers && artifact.viewers.length > 0
|
|
211
211
|
? artifact.viewers.join(', ')
|
|
212
212
|
: artifact.creator;
|
|
213
|
-
return `# name: ${artifact.name}
|
|
214
|
-
# creator: ${artifact.creator}
|
|
215
|
-
# viewers: ${viewersStr}
|
|
216
|
-
|
|
213
|
+
return `# name: ${artifact.name}
|
|
214
|
+
# creator: ${artifact.creator}
|
|
215
|
+
# viewers: ${viewersStr}
|
|
216
|
+
|
|
217
217
|
${artifact.body}`;
|
|
218
218
|
}
|
|
219
219
|
getArtifactFilePath(roomId, storageDir, sanitizedName) {
|
package/eslint.config.js
CHANGED
|
@@ -1,29 +1,29 @@
|
|
|
1
|
-
const tseslint = require('@typescript-eslint/eslint-plugin');
|
|
2
|
-
const tsparser = require('@typescript-eslint/parser');
|
|
3
|
-
|
|
4
|
-
module.exports = [
|
|
5
|
-
{
|
|
6
|
-
ignores: ['dist/**', 'node_modules/**', 'data/**', 'coverage/**'],
|
|
7
|
-
},
|
|
8
|
-
{
|
|
9
|
-
files: ['**/*.ts'],
|
|
10
|
-
languageOptions: {
|
|
11
|
-
parser: tsparser,
|
|
12
|
-
parserOptions: {
|
|
13
|
-
project: './tsconfig.json',
|
|
14
|
-
tsconfigRootDir: __dirname,
|
|
15
|
-
sourceType: 'module',
|
|
16
|
-
},
|
|
17
|
-
},
|
|
18
|
-
plugins: {
|
|
19
|
-
'@typescript-eslint': tseslint,
|
|
20
|
-
},
|
|
21
|
-
rules: {
|
|
22
|
-
...tseslint.configs['recommended'].rules,
|
|
23
|
-
'@typescript-eslint/interface-name-prefix': 'off',
|
|
24
|
-
'@typescript-eslint/explicit-function-return-type': 'off',
|
|
25
|
-
'@typescript-eslint/explicit-module-boundary-types': 'off',
|
|
26
|
-
'@typescript-eslint/no-explicit-any': 'off',
|
|
27
|
-
},
|
|
28
|
-
},
|
|
29
|
-
];
|
|
1
|
+
const tseslint = require('@typescript-eslint/eslint-plugin');
|
|
2
|
+
const tsparser = require('@typescript-eslint/parser');
|
|
3
|
+
|
|
4
|
+
module.exports = [
|
|
5
|
+
{
|
|
6
|
+
ignores: ['dist/**', 'node_modules/**', 'data/**', 'coverage/**'],
|
|
7
|
+
},
|
|
8
|
+
{
|
|
9
|
+
files: ['**/*.ts'],
|
|
10
|
+
languageOptions: {
|
|
11
|
+
parser: tsparser,
|
|
12
|
+
parserOptions: {
|
|
13
|
+
project: './tsconfig.json',
|
|
14
|
+
tsconfigRootDir: __dirname,
|
|
15
|
+
sourceType: 'module',
|
|
16
|
+
},
|
|
17
|
+
},
|
|
18
|
+
plugins: {
|
|
19
|
+
'@typescript-eslint': tseslint,
|
|
20
|
+
},
|
|
21
|
+
rules: {
|
|
22
|
+
...tseslint.configs['recommended'].rules,
|
|
23
|
+
'@typescript-eslint/interface-name-prefix': 'off',
|
|
24
|
+
'@typescript-eslint/explicit-function-return-type': 'off',
|
|
25
|
+
'@typescript-eslint/explicit-module-boundary-types': 'off',
|
|
26
|
+
'@typescript-eslint/no-explicit-any': 'off',
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "briyah",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.4",
|
|
4
4
|
"description": "Briyah multi-agent AI SDK",
|
|
5
5
|
"private": false,
|
|
6
6
|
"main": "dist/server/src/sdk/index.js",
|
|
@@ -15,7 +15,8 @@
|
|
|
15
15
|
"scripts": {
|
|
16
16
|
"prebuild": "rimraf dist",
|
|
17
17
|
"build": "nest build",
|
|
18
|
-
"build:sdk": "
|
|
18
|
+
"build:sdk": "rimraf dist && tsc -p tsconfig.build.json",
|
|
19
|
+
"publish:sdk": "npm run build:sdk && npm publish",
|
|
19
20
|
"prepublishOnly": "npm run build:sdk",
|
|
20
21
|
"format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
|
|
21
22
|
"start": "nest start",
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
-
};
|
|
8
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
exports.AnthropicAiModule = void 0;
|
|
10
|
-
const common_1 = require("@nestjs/common");
|
|
11
|
-
const anthropic_service_1 = require("./anthropic.service");
|
|
12
|
-
let AnthropicAiModule = class AnthropicAiModule {
|
|
13
|
-
};
|
|
14
|
-
exports.AnthropicAiModule = AnthropicAiModule;
|
|
15
|
-
exports.AnthropicAiModule = AnthropicAiModule = __decorate([
|
|
16
|
-
(0, common_1.Module)({
|
|
17
|
-
imports: [],
|
|
18
|
-
providers: [anthropic_service_1.AnthropicAiService],
|
|
19
|
-
exports: [anthropic_service_1.AnthropicAiService],
|
|
20
|
-
})
|
|
21
|
-
], AnthropicAiModule);
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { Anthropic } from '@anthropic-ai/sdk';
|
|
2
|
-
import { Agent } from '../agent';
|
|
3
|
-
import { BaseAiService } from './base-ai.service';
|
|
4
|
-
import { ConfigurationService } from '../../config/configuration.service';
|
|
5
|
-
import { AgentStoreService } from '../agent-store.service';
|
|
6
|
-
import { BalanceService } from '../../app/balance.service';
|
|
7
|
-
import { ArtifactService } from '../artifact.service';
|
|
8
|
-
import { ModelInfo } from '../../shared/types/app.types';
|
|
9
|
-
export declare class AnthropicAiService extends BaseAiService {
|
|
10
|
-
protected anthropic: Anthropic;
|
|
11
|
-
constructor();
|
|
12
|
-
createAgent(configService: ConfigurationService, agentStoreService: AgentStoreService, balanceService: BalanceService, artifactService: ArtifactService, agentName: string, agentNickname: string, description: string, promptFolder: string, modelName: string, storageDir?: string): Agent;
|
|
13
|
-
getServiceName(): string;
|
|
14
|
-
supportsImageGeneration(): boolean;
|
|
15
|
-
supportsPromptCaching(): boolean;
|
|
16
|
-
getCacheConfig(agent: Agent, cacheMessage: boolean): {
|
|
17
|
-
type: string;
|
|
18
|
-
ttl: string;
|
|
19
|
-
} | {
|
|
20
|
-
type: string;
|
|
21
|
-
ttl?: undefined;
|
|
22
|
-
};
|
|
23
|
-
fetchModelsFromApi(): Promise<ModelInfo[]>;
|
|
24
|
-
addToConversationHistory(agent: Agent, message: string, fromSelf?: boolean): void;
|
|
25
|
-
textPrompt(agent: Agent, prompt: string, jsonSchema?: any, saveResponse?: boolean, promptInstructions?: string, cacheConfig?: any, maxOutputChars?: number): Promise<any>;
|
|
26
|
-
private computeMessageCost;
|
|
27
|
-
}
|