@23blocks/block-jarvis 3.0.0 → 3.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 +313 -0
- package/package.json +1 -1
package/README.md
ADDED
|
@@ -0,0 +1,313 @@
|
|
|
1
|
+
# @23blocks/block-jarvis
|
|
2
|
+
|
|
3
|
+
Jarvis block for the 23blocks SDK - AI assistant, agents, prompts, and workflows.
|
|
4
|
+
|
|
5
|
+
[](https://www.npmjs.com/package/@23blocks/block-jarvis)
|
|
6
|
+
[](https://opensource.org/licenses/MIT)
|
|
7
|
+
|
|
8
|
+
## Installation
|
|
9
|
+
|
|
10
|
+
```bash
|
|
11
|
+
npm install @23blocks/block-jarvis @23blocks/transport-http
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
## Overview
|
|
15
|
+
|
|
16
|
+
This package provides AI assistant and automation functionality including:
|
|
17
|
+
|
|
18
|
+
- **Agents** - AI agent management with chat and completion
|
|
19
|
+
- **Prompts** - Prompt templates and execution
|
|
20
|
+
- **Workflows** - Multi-step AI workflows
|
|
21
|
+
- **Conversations** - Conversation management
|
|
22
|
+
- **AI Models** - Model configuration
|
|
23
|
+
- **Entities & Clusters** - Entity-based AI interactions
|
|
24
|
+
- **Mail Templates** - AI-powered email templates
|
|
25
|
+
|
|
26
|
+
## Quick Start
|
|
27
|
+
|
|
28
|
+
```typescript
|
|
29
|
+
import { createHttpTransport } from '@23blocks/transport-http';
|
|
30
|
+
import { createJarvisBlock } from '@23blocks/block-jarvis';
|
|
31
|
+
|
|
32
|
+
const transport = createHttpTransport({
|
|
33
|
+
baseUrl: 'https://api.yourapp.com',
|
|
34
|
+
headers: () => {
|
|
35
|
+
const token = localStorage.getItem('access_token');
|
|
36
|
+
return token ? { Authorization: `Bearer ${token}` } : {};
|
|
37
|
+
},
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
const jarvis = createJarvisBlock(transport, {
|
|
41
|
+
apiKey: 'your-api-key',
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
// Chat with an agent
|
|
45
|
+
const response = await jarvis.agents.chat('agent-id', {
|
|
46
|
+
message: 'Hello, how can you help me today?',
|
|
47
|
+
conversationId: 'conv-123',
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
console.log(response.message);
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
## Services
|
|
54
|
+
|
|
55
|
+
### agents - AI Agent Management
|
|
56
|
+
|
|
57
|
+
```typescript
|
|
58
|
+
// List agents
|
|
59
|
+
const { data: agents } = await jarvis.agents.list();
|
|
60
|
+
|
|
61
|
+
// Get agent by ID
|
|
62
|
+
const agent = await jarvis.agents.get('agent-id');
|
|
63
|
+
|
|
64
|
+
// Create agent
|
|
65
|
+
const newAgent = await jarvis.agents.create({
|
|
66
|
+
name: 'Customer Support',
|
|
67
|
+
description: 'Handles customer inquiries',
|
|
68
|
+
systemPrompt: 'You are a helpful customer support assistant...',
|
|
69
|
+
modelId: 'model-id',
|
|
70
|
+
temperature: 0.7,
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
// Chat with agent
|
|
74
|
+
const chatResponse = await jarvis.agents.chat('agent-id', {
|
|
75
|
+
message: 'What are your business hours?',
|
|
76
|
+
conversationId: 'conv-id',
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
// Complete text
|
|
80
|
+
const completion = await jarvis.agents.complete('agent-id', {
|
|
81
|
+
prompt: 'Write a product description for...',
|
|
82
|
+
maxTokens: 200,
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
// Update agent
|
|
86
|
+
await jarvis.agents.update('agent-id', {
|
|
87
|
+
temperature: 0.5,
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
// Delete agent
|
|
91
|
+
await jarvis.agents.delete('agent-id');
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
### prompts - Prompt Templates
|
|
95
|
+
|
|
96
|
+
```typescript
|
|
97
|
+
// List prompts
|
|
98
|
+
const { data: prompts } = await jarvis.prompts.list();
|
|
99
|
+
|
|
100
|
+
// Get prompt by ID
|
|
101
|
+
const prompt = await jarvis.prompts.get('prompt-id');
|
|
102
|
+
|
|
103
|
+
// Create prompt
|
|
104
|
+
const newPrompt = await jarvis.prompts.create({
|
|
105
|
+
name: 'Product Description',
|
|
106
|
+
template: 'Write a compelling product description for {{product_name}}...',
|
|
107
|
+
variables: ['product_name', 'features', 'target_audience'],
|
|
108
|
+
category: 'marketing',
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
// Execute prompt
|
|
112
|
+
const result = await jarvis.prompts.execute({
|
|
113
|
+
promptId: 'prompt-id',
|
|
114
|
+
variables: {
|
|
115
|
+
product_name: 'Smart Watch X',
|
|
116
|
+
features: 'heart rate monitor, GPS, waterproof',
|
|
117
|
+
target_audience: 'fitness enthusiasts',
|
|
118
|
+
},
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
// Test prompt
|
|
122
|
+
const testResult = await jarvis.prompts.test({
|
|
123
|
+
promptId: 'prompt-id',
|
|
124
|
+
variables: { product_name: 'Test Product' },
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
// Update prompt
|
|
128
|
+
await jarvis.prompts.update('prompt-id', {
|
|
129
|
+
template: 'Updated template...',
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
// Delete prompt
|
|
133
|
+
await jarvis.prompts.delete('prompt-id');
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
### workflows - AI Workflows
|
|
137
|
+
|
|
138
|
+
```typescript
|
|
139
|
+
// List workflows
|
|
140
|
+
const { data: workflows } = await jarvis.workflows.list();
|
|
141
|
+
|
|
142
|
+
// Get workflow by ID
|
|
143
|
+
const workflow = await jarvis.workflows.get('workflow-id');
|
|
144
|
+
|
|
145
|
+
// Create workflow
|
|
146
|
+
const newWorkflow = await jarvis.workflows.create({
|
|
147
|
+
name: 'Content Generation Pipeline',
|
|
148
|
+
description: 'Generates and refines content',
|
|
149
|
+
trigger: 'manual',
|
|
150
|
+
steps: [
|
|
151
|
+
{ name: 'Generate', promptId: 'prompt-1', order: 1 },
|
|
152
|
+
{ name: 'Review', agentId: 'agent-1', order: 2 },
|
|
153
|
+
{ name: 'Refine', promptId: 'prompt-2', order: 3 },
|
|
154
|
+
],
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
// Run workflow
|
|
158
|
+
const run = await jarvis.workflows.run({
|
|
159
|
+
workflowId: 'workflow-id',
|
|
160
|
+
input: { topic: 'AI in healthcare' },
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
// Get workflow execution
|
|
164
|
+
const execution = await jarvis.executions.get('execution-id');
|
|
165
|
+
console.log(execution.status, execution.output);
|
|
166
|
+
|
|
167
|
+
// Update workflow
|
|
168
|
+
await jarvis.workflows.update('workflow-id', {
|
|
169
|
+
name: 'Updated Pipeline',
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
// Delete workflow
|
|
173
|
+
await jarvis.workflows.delete('workflow-id');
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
### conversations - Conversation Management
|
|
177
|
+
|
|
178
|
+
```typescript
|
|
179
|
+
// List conversations
|
|
180
|
+
const { data: conversations } = await jarvis.conversations.list({
|
|
181
|
+
userId: 'user-id',
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
// Get conversation by ID
|
|
185
|
+
const conversation = await jarvis.conversations.get('conv-id');
|
|
186
|
+
|
|
187
|
+
// Create conversation
|
|
188
|
+
const newConv = await jarvis.conversations.create({
|
|
189
|
+
agentId: 'agent-id',
|
|
190
|
+
userId: 'user-id',
|
|
191
|
+
title: 'Support Chat',
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
// Send message
|
|
195
|
+
const response = await jarvis.conversations.sendMessage({
|
|
196
|
+
conversationId: 'conv-id',
|
|
197
|
+
content: 'I need help with my order',
|
|
198
|
+
});
|
|
199
|
+
|
|
200
|
+
// Delete conversation
|
|
201
|
+
await jarvis.conversations.delete('conv-id');
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
### aiModels - Model Configuration
|
|
205
|
+
|
|
206
|
+
```typescript
|
|
207
|
+
// List available models
|
|
208
|
+
const { data: models } = await jarvis.aiModels.list();
|
|
209
|
+
|
|
210
|
+
// Get model by ID
|
|
211
|
+
const model = await jarvis.aiModels.get('model-id');
|
|
212
|
+
|
|
213
|
+
// Create model configuration
|
|
214
|
+
const newModel = await jarvis.aiModels.create({
|
|
215
|
+
name: 'GPT-4 Turbo',
|
|
216
|
+
provider: 'openai',
|
|
217
|
+
modelId: 'gpt-4-turbo',
|
|
218
|
+
maxTokens: 4096,
|
|
219
|
+
temperature: 0.7,
|
|
220
|
+
});
|
|
221
|
+
|
|
222
|
+
// Update model
|
|
223
|
+
await jarvis.aiModels.update('model-id', {
|
|
224
|
+
temperature: 0.5,
|
|
225
|
+
});
|
|
226
|
+
|
|
227
|
+
// Delete model
|
|
228
|
+
await jarvis.aiModels.delete('model-id');
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
### entities - Entity-Based AI
|
|
232
|
+
|
|
233
|
+
```typescript
|
|
234
|
+
// Register entity for AI interactions
|
|
235
|
+
const entity = await jarvis.entities.register({
|
|
236
|
+
entityType: 'product',
|
|
237
|
+
entityId: 'prod-123',
|
|
238
|
+
name: 'Product X',
|
|
239
|
+
context: { category: 'electronics', price: 299 },
|
|
240
|
+
});
|
|
241
|
+
|
|
242
|
+
// Create context for entity
|
|
243
|
+
const context = await jarvis.entities.createContext({
|
|
244
|
+
entityId: 'entity-id',
|
|
245
|
+
systemPrompt: 'You are an expert on this product...',
|
|
246
|
+
});
|
|
247
|
+
|
|
248
|
+
// Send message about entity
|
|
249
|
+
const response = await jarvis.entities.sendMessage({
|
|
250
|
+
entityId: 'entity-id',
|
|
251
|
+
contextId: 'context-id',
|
|
252
|
+
message: 'What are the key features?',
|
|
253
|
+
});
|
|
254
|
+
|
|
255
|
+
// Query entity files
|
|
256
|
+
const fileResponse = await jarvis.entities.queryFile({
|
|
257
|
+
entityId: 'entity-id',
|
|
258
|
+
fileId: 'file-id',
|
|
259
|
+
question: 'Summarize the document',
|
|
260
|
+
});
|
|
261
|
+
```
|
|
262
|
+
|
|
263
|
+
### mailTemplates - Email Templates
|
|
264
|
+
|
|
265
|
+
```typescript
|
|
266
|
+
// List mail templates
|
|
267
|
+
const { data: templates } = await jarvis.mailTemplates.list();
|
|
268
|
+
|
|
269
|
+
// Create template
|
|
270
|
+
const newTemplate = await jarvis.mailTemplates.create({
|
|
271
|
+
name: 'Welcome Email',
|
|
272
|
+
subject: 'Welcome to {{company_name}}!',
|
|
273
|
+
body: 'Hi {{user_name}}, welcome to our platform...',
|
|
274
|
+
variables: ['company_name', 'user_name'],
|
|
275
|
+
});
|
|
276
|
+
|
|
277
|
+
// Update template
|
|
278
|
+
await jarvis.mailTemplates.update('template-id', {
|
|
279
|
+
body: 'Updated content...',
|
|
280
|
+
});
|
|
281
|
+
|
|
282
|
+
// Delete template
|
|
283
|
+
await jarvis.mailTemplates.delete('template-id');
|
|
284
|
+
```
|
|
285
|
+
|
|
286
|
+
## Types
|
|
287
|
+
|
|
288
|
+
```typescript
|
|
289
|
+
import type {
|
|
290
|
+
Agent,
|
|
291
|
+
Prompt,
|
|
292
|
+
Workflow,
|
|
293
|
+
Conversation,
|
|
294
|
+
AIModel,
|
|
295
|
+
Entity,
|
|
296
|
+
MailTemplate,
|
|
297
|
+
ChatRequest,
|
|
298
|
+
ChatResponse,
|
|
299
|
+
ExecutePromptRequest,
|
|
300
|
+
RunWorkflowRequest,
|
|
301
|
+
RunWorkflowResponse,
|
|
302
|
+
} from '@23blocks/block-jarvis';
|
|
303
|
+
```
|
|
304
|
+
|
|
305
|
+
## Related Packages
|
|
306
|
+
|
|
307
|
+
- [`@23blocks/angular`](https://www.npmjs.com/package/@23blocks/angular) - Angular integration
|
|
308
|
+
- [`@23blocks/react`](https://www.npmjs.com/package/@23blocks/react) - React integration
|
|
309
|
+
- [`@23blocks/sdk`](https://www.npmjs.com/package/@23blocks/sdk) - Full SDK package
|
|
310
|
+
|
|
311
|
+
## License
|
|
312
|
+
|
|
313
|
+
MIT - Copyright (c) 2024 23blocks
|
package/package.json
CHANGED