@relevanceai/sdk 3.0.0-alpha.2 → 3.0.0-alpha.3
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 +422 -193
- package/esm/agent.d.ts +20 -8
- package/esm/agent.js +32 -12
- package/esm/client.d.ts +4 -8
- package/esm/client.js +11 -12
- package/esm/emitter.d.ts +16 -0
- package/esm/emitter.js +15 -0
- package/{script/events.d.ts → esm/event.d.ts} +10 -13
- package/esm/{events.js → event.js} +0 -6
- package/esm/message/agent-error.d.ts +6 -0
- package/esm/message/agent-error.js +3 -0
- package/esm/message/agent.d.ts +9 -0
- package/esm/message/agent.js +9 -0
- package/esm/message/task.d.ts +42 -0
- package/esm/message/task.js +38 -0
- package/esm/message/tool.d.ts +108 -0
- package/esm/message/tool.js +109 -0
- package/esm/message/user.d.ts +20 -0
- package/esm/message/user.js +19 -0
- package/esm/mod.d.ts +6 -3
- package/esm/mod.js +1 -0
- package/esm/task.d.ts +50 -18
- package/esm/task.js +228 -65
- package/esm/utils.d.ts +1 -5
- package/esm/utils.js +1 -13
- package/package.json +1 -1
- package/script/agent.d.ts +20 -8
- package/script/agent.js +32 -12
- package/script/client.d.ts +4 -8
- package/script/client.js +11 -12
- package/script/emitter.d.ts +16 -0
- package/script/emitter.js +19 -0
- package/{esm/events.d.ts → script/event.d.ts} +10 -13
- package/script/{events.js → event.js} +1 -8
- package/script/message/agent-error.d.ts +6 -0
- package/script/message/agent-error.js +7 -0
- package/script/message/agent.d.ts +9 -0
- package/script/message/agent.js +13 -0
- package/script/message/task.d.ts +42 -0
- package/script/message/task.js +42 -0
- package/script/message/tool.d.ts +108 -0
- package/script/message/tool.js +113 -0
- package/script/message/user.d.ts +20 -0
- package/script/message/user.js +23 -0
- package/script/mod.d.ts +6 -3
- package/script/mod.js +3 -1
- package/script/task.d.ts +50 -18
- package/script/task.js +228 -65
- package/script/utils.d.ts +1 -5
- package/script/utils.js +1 -14
- package/esm/agent-task.d.ts +0 -61
- package/esm/agent-task.js +0 -112
- package/esm/message.d.ts +0 -18
- package/esm/message.js +0 -18
- package/script/agent-task.d.ts +0 -61
- package/script/agent-task.js +0 -116
- package/script/message.d.ts +0 -18
- package/script/message.js +0 -22
package/README.md
CHANGED
|
@@ -1,320 +1,549 @@
|
|
|
1
1
|
# Relevance AI JavaScript SDK
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
A comprehensive JavaScript/TypeScript SDK for building AI-powered applications
|
|
4
|
+
with Relevance AI's workforce platform. Build, deploy, and scale AI agents
|
|
5
|
+
across any JavaScript runtime.
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
> yet. Please refer to our roadmap for updates.
|
|
7
|
+
## Description
|
|
9
8
|
|
|
10
|
-
|
|
9
|
+
The Relevance AI JavaScript SDK provides a unified interface for integrating
|
|
10
|
+
AI agents into your applications. Whether you're building server-side
|
|
11
|
+
applications, browser-based interfaces, or edge computing solutions, this SDK
|
|
12
|
+
delivers consistent, type-safe access to Relevance AI's powerful agent
|
|
13
|
+
ecosystem.
|
|
11
14
|
|
|
12
|
-
|
|
13
|
-
|
|
15
|
+
### Key Features
|
|
16
|
+
|
|
17
|
+
- **Universal Compatibility**: Works seamlessly across Node.js, Deno, Bun,
|
|
18
|
+
Cloudflare Workers, and browsers
|
|
19
|
+
- **Event-Driven Architecture**: Real-time updates via native EventTarget API
|
|
20
|
+
- **Type Safety**: Full TypeScript support with comprehensive type definitions
|
|
21
|
+
- **Multi-Client Support**: Manage multiple projects and authentication scopes
|
|
22
|
+
simultaneously
|
|
23
|
+
- **Zero Dependencies**: Built on web standards for minimal footprint
|
|
24
|
+
|
|
25
|
+
## Quick Start
|
|
26
|
+
|
|
27
|
+
Get up and running with AI agents in under 5 minutes:
|
|
14
28
|
|
|
15
|
-
|
|
29
|
+
```typescript
|
|
30
|
+
import { Agent, createClient, EU_REGION } from "@relevanceai/sdk";
|
|
31
|
+
|
|
32
|
+
// Initialize client with your credentials
|
|
16
33
|
const client = createClient({
|
|
17
|
-
apiKey:
|
|
18
|
-
region:
|
|
19
|
-
project:
|
|
34
|
+
apiKey: process.env.RELEVANCE_API_KEY,
|
|
35
|
+
region: EU_REGION,
|
|
36
|
+
project: process.env.PROJECT_ID,
|
|
20
37
|
});
|
|
21
38
|
|
|
22
|
-
//
|
|
23
|
-
const
|
|
24
|
-
|
|
39
|
+
// Load an agent and start a conversation
|
|
40
|
+
const agent = await Agent.get("agent-id");
|
|
41
|
+
const task = await agent.sendMessage("Hello, how can you help me today?");
|
|
42
|
+
|
|
43
|
+
// Listen for agent responses
|
|
44
|
+
task.addEventListener("message", ({ detail: { message } }) => {
|
|
45
|
+
if (message.isAgent()) {
|
|
46
|
+
console.log("Agent:", message.text);
|
|
47
|
+
}
|
|
25
48
|
});
|
|
49
|
+
```
|
|
26
50
|
|
|
27
|
-
|
|
28
|
-
task.sendMessage(
|
|
29
|
-
"What is the weather like in Sydney, Australia this weekend?"
|
|
30
|
-
);
|
|
51
|
+
## Installation
|
|
31
52
|
|
|
32
|
-
|
|
33
|
-
task.addEventListener("message", ({ detail }) => {
|
|
34
|
-
const { message } = detail;
|
|
35
|
-
console.log(message.text);
|
|
53
|
+
Choose the installation method for your runtime:
|
|
36
54
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
55
|
+
### Node.js / Bun
|
|
56
|
+
|
|
57
|
+
```bash
|
|
58
|
+
npm install @relevanceai/sdk@latest
|
|
59
|
+
# or
|
|
60
|
+
yarn add @relevanceai/sdk@latest
|
|
61
|
+
# or
|
|
62
|
+
pnpm add @relevanceai/sdk@latest
|
|
63
|
+
# or
|
|
64
|
+
bun add @relevanceai/sdk@latest
|
|
42
65
|
```
|
|
43
66
|
|
|
44
|
-
|
|
67
|
+
### Deno
|
|
45
68
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
integrate with agents, tools, and workforces.
|
|
69
|
+
```bash
|
|
70
|
+
deno add jsr:@relevanceai/sdk
|
|
71
|
+
```
|
|
50
72
|
|
|
51
|
-
|
|
52
|
-
runs:
|
|
73
|
+
Or import directly:
|
|
53
74
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
75
|
+
```typescript
|
|
76
|
+
import { createClient } from "jsr:@relevanceai/sdk";
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
### Cloudflare Workers
|
|
59
80
|
|
|
60
|
-
|
|
81
|
+
```bash
|
|
82
|
+
npm install @relevanceai/sdk@latest
|
|
83
|
+
```
|
|
61
84
|
|
|
62
|
-
|
|
85
|
+
### Browser (with bundler)
|
|
63
86
|
|
|
64
87
|
```bash
|
|
65
|
-
# Node.js / Cloudflare Workers / Browser (with bundler)
|
|
66
88
|
npm install @relevanceai/sdk@latest
|
|
89
|
+
```
|
|
67
90
|
|
|
68
|
-
|
|
69
|
-
deno add jsr:@relevanceai/sdk
|
|
91
|
+
For bundlers that warn about `node:crypto`, create a shim:
|
|
70
92
|
|
|
71
|
-
|
|
72
|
-
|
|
93
|
+
```javascript
|
|
94
|
+
// shims/crypto.js
|
|
95
|
+
export default window.crypto;
|
|
73
96
|
```
|
|
74
97
|
|
|
75
|
-
|
|
98
|
+
Configure your bundler to use the shim:
|
|
99
|
+
|
|
100
|
+
- [Vite configuration](https://vite.dev/config/shared-options.html#resolve-alias)
|
|
101
|
+
- [Webpack configuration](https://webpack.js.org/configuration/resolve/#resolvealias)
|
|
102
|
+
- [Rollup configuration](https://www.npmjs.com/package/@rollup/plugin-alias)
|
|
76
103
|
|
|
77
|
-
|
|
78
|
-
[Vite](https://vite.dev) or [Webpack](https://webpack.js.org), you can use the
|
|
79
|
-
CDN version directly:
|
|
104
|
+
### Browser (CDN)
|
|
80
105
|
|
|
81
106
|
```html
|
|
82
107
|
<script type="importmap">
|
|
83
|
-
{
|
|
84
|
-
|
|
85
|
-
|
|
108
|
+
{
|
|
109
|
+
"imports": {
|
|
110
|
+
"@relevanceai/sdk": "https://esm.run/@relevanceai/sdk"
|
|
111
|
+
}
|
|
86
112
|
}
|
|
87
|
-
}
|
|
88
113
|
</script>
|
|
89
114
|
<script type="module">
|
|
90
|
-
import { createClient } from "@relevanceai/sdk";
|
|
91
|
-
//
|
|
115
|
+
import { createClient } from "@relevanceai/sdk";
|
|
116
|
+
// Your code here
|
|
92
117
|
</script>
|
|
93
118
|
```
|
|
94
119
|
|
|
95
120
|
## Usage
|
|
96
121
|
|
|
97
|
-
###
|
|
122
|
+
### Authentication
|
|
98
123
|
|
|
99
|
-
|
|
100
|
-
requests and grant access to your project.
|
|
124
|
+
The SDK supports two authentication methods for different use cases:
|
|
101
125
|
|
|
102
|
-
|
|
126
|
+
#### API Keys (Server-side)
|
|
103
127
|
|
|
104
|
-
|
|
128
|
+
API keys grant full access to your project. Use these for server applications
|
|
129
|
+
and secure environments:
|
|
105
130
|
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
apps where third parties do not have access.
|
|
131
|
+
```typescript
|
|
132
|
+
import { createClient, AU_REGION } from "@relevanceai/sdk";
|
|
109
133
|
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
134
|
+
const client = createClient({
|
|
135
|
+
apiKey: "sk-...",
|
|
136
|
+
region: AU_REGION,
|
|
137
|
+
project: "project-uuid",
|
|
138
|
+
});
|
|
139
|
+
```
|
|
113
140
|
|
|
114
|
-
|
|
115
|
-
import { createClient, Key, AU_REGION } from "@relevanceai/sdk";
|
|
141
|
+
You can also create a Key instance explicitly:
|
|
116
142
|
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
const project = "1234...";
|
|
143
|
+
```typescript
|
|
144
|
+
import { Client, Key, AU_REGION } from "@relevanceai/sdk";
|
|
120
145
|
|
|
121
|
-
const key = new Key({
|
|
122
|
-
|
|
123
|
-
|
|
146
|
+
const key = new Key({
|
|
147
|
+
key: "sk-...",
|
|
148
|
+
region: AU_REGION,
|
|
149
|
+
project: "project-uuid",
|
|
150
|
+
});
|
|
124
151
|
|
|
125
|
-
|
|
152
|
+
const client = new Client(key);
|
|
153
|
+
```
|
|
126
154
|
|
|
127
|
-
|
|
128
|
-
customers, it's best to share resources from the Relevance AI platform. This
|
|
129
|
-
makes them available for public use and requires an embed key scoped only to
|
|
130
|
-
that resource.
|
|
155
|
+
#### Embed Keys (Client-side)
|
|
131
156
|
|
|
132
|
-
|
|
133
|
-
|
|
157
|
+
For public-facing applications, use embed keys which are scoped to a specific
|
|
158
|
+
public agent:
|
|
134
159
|
|
|
135
|
-
```
|
|
136
|
-
import {
|
|
160
|
+
```typescript
|
|
161
|
+
import { Key, createClient, US_REGION } from "@relevanceai/sdk";
|
|
137
162
|
|
|
138
|
-
const
|
|
139
|
-
|
|
140
|
-
|
|
163
|
+
const embedKey = await Key.generateEmbedKey({
|
|
164
|
+
region: US_REGION,
|
|
165
|
+
project: "project-uuid",
|
|
166
|
+
agentId: "public-agent-id", // Must be a public agent
|
|
167
|
+
});
|
|
141
168
|
|
|
142
|
-
const embedKey = await Key.generateEmbedKey({ region, project, agent });
|
|
143
169
|
const client = createClient(embedKey);
|
|
144
170
|
```
|
|
145
171
|
|
|
146
|
-
###
|
|
172
|
+
### Fetching Agents
|
|
147
173
|
|
|
148
|
-
|
|
149
|
-
Relevance AI and manages authentication.
|
|
174
|
+
Load agents before creating tasks:
|
|
150
175
|
|
|
151
|
-
|
|
176
|
+
```typescript
|
|
177
|
+
// Using default client
|
|
178
|
+
const agent = await Agent.get("agent-id");
|
|
152
179
|
|
|
153
|
-
|
|
154
|
-
|
|
180
|
+
// Using specific client
|
|
181
|
+
const customClient = createClient({
|
|
182
|
+
/* config */
|
|
183
|
+
});
|
|
184
|
+
const agent = await Agent.get("agent-id", customClient);
|
|
185
|
+
|
|
186
|
+
// Access agent properties
|
|
187
|
+
console.log(agent.name);
|
|
188
|
+
console.log(agent.avatar);
|
|
189
|
+
console.log(agent.description);
|
|
190
|
+
```
|
|
155
191
|
|
|
156
|
-
|
|
157
|
-
const region = AU_REGION;
|
|
158
|
-
const projectOne = "1234...";
|
|
159
|
-
const projectTwo = "abcd...";
|
|
192
|
+
### Sending Messages
|
|
160
193
|
|
|
161
|
-
|
|
162
|
-
const twoKey = new Key({ apiKey, region, project: projectTwo });
|
|
194
|
+
#### Create a New Task
|
|
163
195
|
|
|
164
|
-
|
|
165
|
-
const twoClient = new Client(twoKey);
|
|
166
|
-
```
|
|
196
|
+
Start a new conversation with an agent:
|
|
167
197
|
|
|
168
|
-
|
|
198
|
+
```typescript
|
|
199
|
+
const agent = await Agent.get("agent-id");
|
|
200
|
+
const task = await agent.sendMessage("What's the weather like today?");
|
|
201
|
+
```
|
|
169
202
|
|
|
170
|
-
|
|
171
|
-
client factory as shown in the quickstart:
|
|
203
|
+
#### Send to Existing Task
|
|
172
204
|
|
|
173
|
-
|
|
174
|
-
import { createClient, Client } from "@relevanceai/sdk";
|
|
205
|
+
Continue an existing conversation:
|
|
175
206
|
|
|
176
|
-
|
|
207
|
+
```typescript
|
|
208
|
+
// Get an existing task
|
|
209
|
+
const task = await agent.getTask("task-id");
|
|
177
210
|
|
|
178
|
-
//
|
|
179
|
-
|
|
211
|
+
// Send a follow-up message
|
|
212
|
+
await agent.sendMessage("What about tomorrow?", task);
|
|
180
213
|
```
|
|
181
214
|
|
|
182
|
-
|
|
183
|
-
|
|
215
|
+
Note: `sendMessage` returns once the message is sent and doesn't wait for a
|
|
216
|
+
response. Use event listeners to handle responses.
|
|
217
|
+
|
|
218
|
+
### Event Handling
|
|
219
|
+
|
|
220
|
+
Tasks use an event-driven architecture for real-time updates:
|
|
221
|
+
|
|
222
|
+
#### Available Events
|
|
223
|
+
|
|
224
|
+
- **`start`**: Task initialization
|
|
225
|
+
- **`status`**: Status changes (queued, running, complete, error)
|
|
226
|
+
- **`message`**: New messages from agent or user
|
|
227
|
+
- **`update`**: Tool execution updates
|
|
228
|
+
- **`error`**: Error notifications
|
|
184
229
|
|
|
185
|
-
|
|
230
|
+
#### Listening for Events
|
|
186
231
|
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
232
|
+
```typescript
|
|
233
|
+
// Listen for messages
|
|
234
|
+
task.addEventListener("message", ({ detail }) => {
|
|
235
|
+
const { message } = detail;
|
|
190
236
|
|
|
191
|
-
|
|
192
|
-
|
|
237
|
+
if (message.isAgent()) {
|
|
238
|
+
console.log("Agent:", message.text);
|
|
239
|
+
}
|
|
240
|
+
});
|
|
193
241
|
|
|
194
|
-
|
|
242
|
+
// Listen for status changes
|
|
243
|
+
task.addEventListener("status", ({ detail }) => {
|
|
244
|
+
console.log("Status changed to:", detail.status);
|
|
245
|
+
});
|
|
246
|
+
|
|
247
|
+
// Listen for tool updates
|
|
248
|
+
task.addEventListener("update", ({ detail }) => {
|
|
249
|
+
console.log("Tool update:", detail.message);
|
|
250
|
+
});
|
|
195
251
|
|
|
196
|
-
|
|
197
|
-
|
|
252
|
+
// Listen for errors
|
|
253
|
+
task.addEventListener("error", ({ detail }) => {
|
|
254
|
+
console.error("Task error:", detail.message);
|
|
255
|
+
});
|
|
198
256
|
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
const task = client.createTask({ agent: agentId });
|
|
257
|
+
// Clean up when done
|
|
258
|
+
task.unsubscribe();
|
|
202
259
|
```
|
|
203
260
|
|
|
204
|
-
####
|
|
261
|
+
#### Managing Subscriptions
|
|
205
262
|
|
|
206
|
-
|
|
207
|
-
|
|
263
|
+
The SDK automatically starts listening when you add event listeners. Remember
|
|
264
|
+
to clean up:
|
|
208
265
|
|
|
209
|
-
```
|
|
210
|
-
|
|
266
|
+
```typescript
|
|
267
|
+
// Start listening (called automatically with addEventListener)
|
|
268
|
+
task.subscribe();
|
|
269
|
+
|
|
270
|
+
// Stop listening and clean up
|
|
271
|
+
task.unsubscribe();
|
|
211
272
|
```
|
|
212
273
|
|
|
213
|
-
|
|
214
|
-
|
|
274
|
+
### Advanced Usage
|
|
275
|
+
|
|
276
|
+
#### Default Client Pattern
|
|
215
277
|
|
|
216
|
-
|
|
278
|
+
Use a singleton client throughout your application:
|
|
217
279
|
|
|
218
|
-
|
|
219
|
-
|
|
280
|
+
```typescript
|
|
281
|
+
// Initialize once at startup
|
|
282
|
+
createClient({ apiKey, region, project });
|
|
220
283
|
|
|
221
|
-
|
|
284
|
+
// Access anywhere in your app
|
|
285
|
+
import { Client } from "@relevanceai/sdk";
|
|
286
|
+
const client = Client.default();
|
|
287
|
+
```
|
|
222
288
|
|
|
223
|
-
|
|
224
|
-
task.sendMessage("What came first; the chicken or the egg?");
|
|
289
|
+
#### Multiple Clients
|
|
225
290
|
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
291
|
+
Manage multiple projects or authentication scopes:
|
|
292
|
+
|
|
293
|
+
```typescript
|
|
294
|
+
import { Client, Key, EU_REGION } from "@relevanceai/sdk";
|
|
295
|
+
|
|
296
|
+
const projectOneKey = new Key({
|
|
297
|
+
key: "sk-project1",
|
|
298
|
+
region: EU_REGION,
|
|
299
|
+
project: "project-1-id",
|
|
300
|
+
});
|
|
301
|
+
|
|
302
|
+
const projectTwoKey = new Key({
|
|
303
|
+
key: "sk-project2",
|
|
304
|
+
region: EU_REGION,
|
|
305
|
+
project: "project-2-id",
|
|
229
306
|
});
|
|
307
|
+
|
|
308
|
+
const clientOne = new Client(projectOneKey);
|
|
309
|
+
const clientTwo = new Client(projectTwoKey);
|
|
310
|
+
|
|
311
|
+
// Use different clients for different agents
|
|
312
|
+
const agentOne = await Agent.get("agent-1", clientOne);
|
|
313
|
+
const agentTwo = await Agent.get("agent-2", clientTwo);
|
|
230
314
|
```
|
|
231
315
|
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
316
|
+
## Examples
|
|
317
|
+
|
|
318
|
+
For complete working examples, check out the `internal/examples` directory:
|
|
319
|
+
|
|
320
|
+
- **Deno Examples** (`internal/examples/deno/`):
|
|
235
321
|
|
|
236
|
-
|
|
237
|
-
|
|
322
|
+
- Client setup and configuration
|
|
323
|
+
- Creating and managing tasks
|
|
324
|
+
- Fetching agent information
|
|
325
|
+
- Retrieving existing tasks
|
|
238
326
|
|
|
239
|
-
|
|
327
|
+
- **Browser Example** (`internal/examples/browser/`):
|
|
328
|
+
- Full chat application with Preact
|
|
329
|
+
- Real-time message handling
|
|
330
|
+
- UI components for agent interactions
|
|
240
331
|
|
|
241
|
-
|
|
332
|
+
## API Reference
|
|
242
333
|
|
|
243
|
-
|
|
334
|
+
### Client
|
|
244
335
|
|
|
245
|
-
|
|
336
|
+
```typescript
|
|
337
|
+
class Client {
|
|
338
|
+
constructor(key: Key);
|
|
339
|
+
static default(): Client;
|
|
246
340
|
|
|
247
|
-
|
|
341
|
+
readonly key: Key;
|
|
342
|
+
readonly region: Region;
|
|
343
|
+
readonly project: string;
|
|
248
344
|
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
345
|
+
isEmbedKey(): boolean;
|
|
346
|
+
fetch<T>(endpoint: string, init?: RequestInit): Promise<T>;
|
|
347
|
+
url(path: string): URL;
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
function createClient(keyOrOptions: Key | CreateClientOptions): Client;
|
|
351
|
+
|
|
352
|
+
interface CreateClientOptions {
|
|
353
|
+
apiKey: string;
|
|
354
|
+
region: Region;
|
|
355
|
+
project: string;
|
|
253
356
|
}
|
|
254
357
|
```
|
|
255
358
|
|
|
256
|
-
|
|
359
|
+
### Key
|
|
360
|
+
|
|
361
|
+
```typescript
|
|
362
|
+
class Key {
|
|
363
|
+
static async generateEmbedKey(options: GenerateEmbedKeyOptions): Promise<Key>;
|
|
257
364
|
|
|
258
|
-
|
|
365
|
+
constructor(options: CreateKeyOptions);
|
|
259
366
|
|
|
260
|
-
|
|
261
|
-
|
|
367
|
+
readonly region: Region;
|
|
368
|
+
readonly project: string;
|
|
369
|
+
readonly agentId?: string;
|
|
370
|
+
readonly taskPrefix?: string;
|
|
262
371
|
|
|
263
|
-
|
|
372
|
+
isEmbed(): boolean;
|
|
373
|
+
fetchHeaders(): HeadersInit;
|
|
374
|
+
toJSON(): CreateKeyOptions;
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
interface CreateKeyOptions {
|
|
378
|
+
key: string;
|
|
379
|
+
region: Region;
|
|
380
|
+
project: string;
|
|
381
|
+
agentId?: string;
|
|
382
|
+
taskPrefix?: string;
|
|
383
|
+
}
|
|
264
384
|
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
385
|
+
interface GenerateEmbedKeyOptions {
|
|
386
|
+
region: Region;
|
|
387
|
+
project: string;
|
|
388
|
+
agentId: string;
|
|
268
389
|
}
|
|
269
390
|
```
|
|
270
391
|
|
|
271
|
-
|
|
392
|
+
### Agent
|
|
272
393
|
|
|
273
|
-
|
|
274
|
-
|
|
394
|
+
```typescript
|
|
395
|
+
class Agent {
|
|
396
|
+
static async get(id: string, client?: Client): Promise<Agent>;
|
|
275
397
|
|
|
276
|
-
|
|
398
|
+
readonly id: string;
|
|
399
|
+
readonly name?: string;
|
|
400
|
+
readonly description?: string;
|
|
401
|
+
readonly avatar?: string;
|
|
402
|
+
readonly createdAt: Date;
|
|
403
|
+
readonly updatedAt: Date;
|
|
404
|
+
readonly region: Region;
|
|
405
|
+
readonly project: string;
|
|
277
406
|
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
update: TaskMessage<"tool">;
|
|
407
|
+
getTask(taskId: string): Promise<Task>;
|
|
408
|
+
sendMessage(message: string, task?: Task): Promise<Task>;
|
|
281
409
|
}
|
|
282
410
|
```
|
|
283
411
|
|
|
284
|
-
|
|
412
|
+
### Task
|
|
285
413
|
|
|
286
|
-
|
|
414
|
+
```typescript
|
|
415
|
+
class Task extends EventTarget {
|
|
416
|
+
static async get(
|
|
417
|
+
id: string,
|
|
418
|
+
agentOrAgentId: Agent | string,
|
|
419
|
+
client?: Client
|
|
420
|
+
): Promise<Task>;
|
|
287
421
|
|
|
288
|
-
|
|
422
|
+
readonly id: string;
|
|
423
|
+
readonly title: string;
|
|
424
|
+
readonly status: TaskStatus;
|
|
425
|
+
readonly agent: Agent;
|
|
289
426
|
|
|
290
|
-
|
|
427
|
+
isRunning(): boolean;
|
|
428
|
+
getMessages(options?: { from?: Date }): Promise<AnyTaskMessage[]>;
|
|
429
|
+
subscribe(): void;
|
|
430
|
+
unsubscribe(): void;
|
|
291
431
|
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
message: TaskMessage<"agent" | "user">;
|
|
432
|
+
addEventListener(type: string, listener: EventListener): void;
|
|
433
|
+
removeEventListener(type: string, listener: EventListener): void;
|
|
295
434
|
}
|
|
435
|
+
|
|
436
|
+
type TaskStatus =
|
|
437
|
+
| "not-started"
|
|
438
|
+
| "idle"
|
|
439
|
+
| "queued"
|
|
440
|
+
| "running"
|
|
441
|
+
| "action"
|
|
442
|
+
| "complete"
|
|
443
|
+
| "error";
|
|
296
444
|
```
|
|
297
445
|
|
|
298
|
-
|
|
446
|
+
### Messages
|
|
447
|
+
|
|
448
|
+
```typescript
|
|
449
|
+
abstract class TaskMessage {
|
|
450
|
+
readonly id: string;
|
|
451
|
+
readonly type: MessageType;
|
|
452
|
+
readonly createdAt: Date;
|
|
299
453
|
|
|
300
|
-
|
|
454
|
+
isAgent(): boolean;
|
|
455
|
+
}
|
|
301
456
|
|
|
302
|
-
|
|
457
|
+
class AgentMessage extends TaskMessage {
|
|
458
|
+
readonly text: string;
|
|
459
|
+
}
|
|
303
460
|
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
461
|
+
class UserMessage extends TaskMessage {
|
|
462
|
+
readonly text: string;
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
class ToolMessage extends TaskMessage {
|
|
466
|
+
readonly status: "pending" | "running" | "completed" | "failed";
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
class AgentErrorMessage extends TaskMessage {
|
|
470
|
+
readonly error: string;
|
|
307
471
|
}
|
|
308
472
|
```
|
|
309
473
|
|
|
310
|
-
|
|
474
|
+
### Types
|
|
311
475
|
|
|
312
|
-
```
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
476
|
+
```typescript
|
|
477
|
+
type Region = "us" | "eu" | "au";
|
|
478
|
+
|
|
479
|
+
const US_REGION: Region = "us";
|
|
480
|
+
const EU_REGION: Region = "eu";
|
|
481
|
+
const AU_REGION: Region = "au";
|
|
482
|
+
```
|
|
483
|
+
|
|
484
|
+
## Contributing
|
|
485
|
+
|
|
486
|
+
We welcome contributions to improve the SDK. Please follow these guidelines:
|
|
487
|
+
|
|
488
|
+
### Development Setup
|
|
489
|
+
|
|
490
|
+
1. Clone the repository
|
|
491
|
+
2. Install Deno (primary development environment)
|
|
492
|
+
|
|
493
|
+
```bash
|
|
494
|
+
# Build npm package
|
|
495
|
+
deno run dnt
|
|
320
496
|
```
|
|
497
|
+
|
|
498
|
+
### Code Style
|
|
499
|
+
|
|
500
|
+
- Use TypeScript for all code
|
|
501
|
+
- Follow existing patterns and conventions
|
|
502
|
+
- Maintain 80-character line width where practical
|
|
503
|
+
- Write clear, concise commit messages
|
|
504
|
+
|
|
505
|
+
### Submitting Changes
|
|
506
|
+
|
|
507
|
+
1. Fork the repository
|
|
508
|
+
2. Create a feature branch
|
|
509
|
+
3. Make your changes
|
|
510
|
+
4. Submit a pull request with clear description
|
|
511
|
+
|
|
512
|
+
## Roadmap
|
|
513
|
+
|
|
514
|
+
### Current
|
|
515
|
+
|
|
516
|
+
- [x] Core client functionality
|
|
517
|
+
- [x] Agent and task creation
|
|
518
|
+
- [x] Event-driven messaging
|
|
519
|
+
- [x] Multi-environment support
|
|
520
|
+
|
|
521
|
+
### Upcoming Features
|
|
522
|
+
|
|
523
|
+
- [ ] Streaming responses
|
|
524
|
+
- [ ] File upload support
|
|
525
|
+
- [ ] Enhanced error recovery
|
|
526
|
+
- [ ] Agent and task management
|
|
527
|
+
- [ ] Workforce support
|
|
528
|
+
- [ ] Tool support
|
|
529
|
+
|
|
530
|
+
### Future Considerations (2.0)
|
|
531
|
+
|
|
532
|
+
- [ ] WebSocket support for real-time updates
|
|
533
|
+
- [ ] Offline queue management
|
|
534
|
+
- [ ] Tool building architecture
|
|
535
|
+
- [ ] Voice modality
|
|
536
|
+
|
|
537
|
+
## Support
|
|
538
|
+
|
|
539
|
+
- **Issues**: [GitHub Issues](https://github.com/RelevanceAI/relevance-js-sdk/issues)
|
|
540
|
+
- **Community**: [Discord Server](https://discord.gg/relevanceai)
|
|
541
|
+
|
|
542
|
+
## License
|
|
543
|
+
|
|
544
|
+
MIT License. See [LICENSE](./LICENSE) for details.
|
|
545
|
+
|
|
546
|
+
## Security
|
|
547
|
+
|
|
548
|
+
For security vulnerabilities, please email security@relevanceai.com directly
|
|
549
|
+
rather than using public issue trackers.
|