@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.
Files changed (58) hide show
  1. package/README.md +422 -193
  2. package/esm/agent.d.ts +20 -8
  3. package/esm/agent.js +32 -12
  4. package/esm/client.d.ts +4 -8
  5. package/esm/client.js +11 -12
  6. package/esm/emitter.d.ts +16 -0
  7. package/esm/emitter.js +15 -0
  8. package/{script/events.d.ts → esm/event.d.ts} +10 -13
  9. package/esm/{events.js → event.js} +0 -6
  10. package/esm/message/agent-error.d.ts +6 -0
  11. package/esm/message/agent-error.js +3 -0
  12. package/esm/message/agent.d.ts +9 -0
  13. package/esm/message/agent.js +9 -0
  14. package/esm/message/task.d.ts +42 -0
  15. package/esm/message/task.js +38 -0
  16. package/esm/message/tool.d.ts +108 -0
  17. package/esm/message/tool.js +109 -0
  18. package/esm/message/user.d.ts +20 -0
  19. package/esm/message/user.js +19 -0
  20. package/esm/mod.d.ts +6 -3
  21. package/esm/mod.js +1 -0
  22. package/esm/task.d.ts +50 -18
  23. package/esm/task.js +228 -65
  24. package/esm/utils.d.ts +1 -5
  25. package/esm/utils.js +1 -13
  26. package/package.json +1 -1
  27. package/script/agent.d.ts +20 -8
  28. package/script/agent.js +32 -12
  29. package/script/client.d.ts +4 -8
  30. package/script/client.js +11 -12
  31. package/script/emitter.d.ts +16 -0
  32. package/script/emitter.js +19 -0
  33. package/{esm/events.d.ts → script/event.d.ts} +10 -13
  34. package/script/{events.js → event.js} +1 -8
  35. package/script/message/agent-error.d.ts +6 -0
  36. package/script/message/agent-error.js +7 -0
  37. package/script/message/agent.d.ts +9 -0
  38. package/script/message/agent.js +13 -0
  39. package/script/message/task.d.ts +42 -0
  40. package/script/message/task.js +42 -0
  41. package/script/message/tool.d.ts +108 -0
  42. package/script/message/tool.js +113 -0
  43. package/script/message/user.d.ts +20 -0
  44. package/script/message/user.js +23 -0
  45. package/script/mod.d.ts +6 -3
  46. package/script/mod.js +3 -1
  47. package/script/task.d.ts +50 -18
  48. package/script/task.js +228 -65
  49. package/script/utils.d.ts +1 -5
  50. package/script/utils.js +1 -14
  51. package/esm/agent-task.d.ts +0 -61
  52. package/esm/agent-task.js +0 -112
  53. package/esm/message.d.ts +0 -18
  54. package/esm/message.js +0 -18
  55. package/script/agent-task.d.ts +0 -61
  56. package/script/agent-task.js +0 -116
  57. package/script/message.d.ts +0 -18
  58. package/script/message.js +0 -22
package/README.md CHANGED
@@ -1,320 +1,549 @@
1
1
  # Relevance AI JavaScript SDK
2
2
 
3
- Build full-stack AI applications using our JavaScript SDK. This multi-environment
4
- SDK enables you to integrate, extend, or build end-to-end solutions on top of
5
- our powerful AI Workforce platform.
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
- > **Note:** The SDK is in active development and not all features are available
8
- > yet. Please refer to our roadmap for updates.
7
+ ## Description
9
8
 
10
- ## Quickstart
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
- ```js
13
- import { createClient, AU_REGION } from "@relevanceai/sdk";
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
- // Create a client with your credentials
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: "sk-abcdefghijklmnopqrstuvwxyz1234567890ABCDEFGHIJKL",
18
- region: AU_REGION,
19
- project: "12345678-90ab-cdef-1234-567890abcdef",
34
+ apiKey: process.env.RELEVANCE_API_KEY,
35
+ region: EU_REGION,
36
+ project: process.env.PROJECT_ID,
20
37
  });
21
38
 
22
- // Create a task for an agent
23
- const task = client.createTask({
24
- agent: "fedcba09-8765-4321-fedc-ba0987654321",
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
- // Send a message to the agent
28
- task.sendMessage(
29
- "What is the weather like in Sydney, Australia this weekend?"
30
- );
51
+ ## Installation
31
52
 
32
- // Listen for responses
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
- task.sendMessage("Thanks!");
38
-
39
- // Important: Stop listening when done to prevent memory leaks
40
- task.stopListening();
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
- ## Getting Started
67
+ ### Deno
45
68
 
46
- The JavaScript SDK is a stateless, event-driven toolkit that provides the
47
- flexibility to build any application you need. It sits on top of our API and
48
- offers a streamlined developer experience, making it easier for your apps to
49
- integrate with agents, tools, and workforces.
69
+ ```bash
70
+ deno add jsr:@relevanceai/sdk
71
+ ```
50
72
 
51
- This multi-environment library allows you to build wherever modern JavaScript
52
- runs:
73
+ Or import directly:
53
74
 
54
- - Node.js
55
- - Deno
56
- - Bun
57
- - Cloudflare Workers
58
- - Browser
75
+ ```typescript
76
+ import { createClient } from "jsr:@relevanceai/sdk";
77
+ ```
78
+
79
+ ### Cloudflare Workers
59
80
 
60
- ### Installation
81
+ ```bash
82
+ npm install @relevanceai/sdk@latest
83
+ ```
61
84
 
62
- Install the SDK for your environment:
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
- # Deno
69
- deno add jsr:@relevanceai/sdk
91
+ For bundlers that warn about `node:crypto`, create a shim:
70
92
 
71
- # Bun
72
- bun add @relevanceai/sdk@latest
93
+ ```javascript
94
+ // shims/crypto.js
95
+ export default window.crypto;
73
96
  ```
74
97
 
75
- #### Browser (CDN)
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
- If you are developing a frontend application and not using a bundler like
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
- "imports": {
85
- "@relevanceai/sdk": "https://esm.run/@relevanceai/sdk"
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
- ### Keys
122
+ ### Authentication
98
123
 
99
- To communicate with Relevance AI, you will need a key. Keys authenticate your
100
- requests and grant access to your project.
124
+ The SDK supports two authentication methods for different use cases:
101
125
 
102
- There are two types of keys: _API_ and _Embed_.
126
+ #### API Keys (Server-side)
103
127
 
104
- #### API Key
128
+ API keys grant full access to your project. Use these for server applications
129
+ and secure environments:
105
130
 
106
- API keys grant access to the entire project, including agents, tools, and
107
- workforces. This key is best used for server-side applications or protected web
108
- apps where third parties do not have access.
131
+ ```typescript
132
+ import { createClient, AU_REGION } from "@relevanceai/sdk";
109
133
 
110
- Using the default client `createClient({ apiKey, region, project })` will create
111
- an API Key for convenience. Alternatively, you can create a `Key` instance and
112
- pass it to the client.
134
+ const client = createClient({
135
+ apiKey: "sk-...",
136
+ region: AU_REGION,
137
+ project: "project-uuid",
138
+ });
139
+ ```
113
140
 
114
- ```js
115
- import { createClient, Key, AU_REGION } from "@relevanceai/sdk";
141
+ You can also create a Key instance explicitly:
116
142
 
117
- const apiKey = "sk-...";
118
- const region = AU_REGION;
119
- const project = "1234...";
143
+ ```typescript
144
+ import { Client, Key, AU_REGION } from "@relevanceai/sdk";
120
145
 
121
- const key = new Key({ apiKey, region, project });
122
- const client = createClient(key);
123
- ```
146
+ const key = new Key({
147
+ key: "sk-...",
148
+ region: AU_REGION,
149
+ project: "project-uuid",
150
+ });
124
151
 
125
- #### Embed Key
152
+ const client = new Client(key);
153
+ ```
126
154
 
127
- If you are developing a web app that allows third-party access, such as for your
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
- To get an embed key, specify which public resource you wish to scope it to. For
133
- example, to create an embed key for a publicly available agent in your project:
157
+ For public-facing applications, use embed keys which are scoped to a specific
158
+ public agent:
134
159
 
135
- ```js
136
- import { createClient, Key, AU_REGION } from "@relevanceai/sdk";
160
+ ```typescript
161
+ import { Key, createClient, US_REGION } from "@relevanceai/sdk";
137
162
 
138
- const region = AU_REGION;
139
- const project = "1234...";
140
- const agent = "abcd..."; // a *public* agent
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
- ### Clients
172
+ ### Fetching Agents
147
173
 
148
- A client is the main entry point for the SDK. It configures communication with
149
- Relevance AI and manages authentication.
174
+ Load agents before creating tasks:
150
175
 
151
- You can create multiple clients, which is useful for multi-project setups.
176
+ ```typescript
177
+ // Using default client
178
+ const agent = await Agent.get("agent-id");
152
179
 
153
- ```js
154
- import { Client, Key, AU_REGION } from "@relevanceai/sdk";
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
- const apiKey = "sk-...";
157
- const region = AU_REGION;
158
- const projectOne = "1234...";
159
- const projectTwo = "abcd...";
192
+ ### Sending Messages
160
193
 
161
- const oneKey = new Key({ apiKey, region, project: projectOne });
162
- const twoKey = new Key({ apiKey, region, project: projectTwo });
194
+ #### Create a New Task
163
195
 
164
- const oneClient = new Client(oneKey);
165
- const twoClient = new Client(twoKey);
166
- ```
196
+ Start a new conversation with an agent:
167
197
 
168
- #### Default client
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
- Typically, you will only need a single client. In this case, use the default
171
- client factory as shown in the quickstart:
203
+ #### Send to Existing Task
172
204
 
173
- ```js
174
- import { createClient, Client } from "@relevanceai/sdk";
205
+ Continue an existing conversation:
175
206
 
176
- const client = createClient({ apiKey, region, project });
207
+ ```typescript
208
+ // Get an existing task
209
+ const task = await agent.getTask("task-id");
177
210
 
178
- // elsewhere in your app
179
- Client.default();
211
+ // Send a follow-up message
212
+ await agent.sendMessage("What about tomorrow?", task);
180
213
  ```
181
214
 
182
- Attempting to create more than one default client will throw an error. Referencing
183
- the default client before creating one will also throw an error.
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
- ### Tasks
230
+ #### Listening for Events
186
231
 
187
- Whenever you run anything in Relevance AI, these are known as tasks. Tasks have
188
- a subject: an agent, tool, or workforce. You can send messages to these subjects,
189
- receive replies, and follow updates and errors.
232
+ ```typescript
233
+ // Listen for messages
234
+ task.addEventListener("message", ({ detail }) => {
235
+ const { message } = detail;
190
236
 
191
- > **Important:** Always call `task.stopListening()` when you're done with a task
192
- > to prevent memory leaks and clean up resources properly.
237
+ if (message.isAgent()) {
238
+ console.log("Agent:", message.text);
239
+ }
240
+ });
193
241
 
194
- #### Creating Tasks
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
- The easiest way to create a new task is to use the client's convenient method
197
- `createTask` and provide the subject ID.
252
+ // Listen for errors
253
+ task.addEventListener("error", ({ detail }) => {
254
+ console.error("Task error:", detail.message);
255
+ });
198
256
 
199
- ```js
200
- const agentId = "1234...";
201
- const task = client.createTask({ agent: agentId });
257
+ // Clean up when done
258
+ task.unsubscribe();
202
259
  ```
203
260
 
204
- #### Sending a Message
261
+ #### Managing Subscriptions
205
262
 
206
- Once you have a task instance, you can send messages to the subject using the
207
- `sendMessage()` method.
263
+ The SDK automatically starts listening when you add event listeners. Remember
264
+ to clean up:
208
265
 
209
- ```js
210
- task.sendMessage("How many letter r's are there in the word 'strawberry'?");
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
- Note that this call is not `async`. It sends the message and does not `await`
214
- a reply. This is intentional, as tasks are event-driven.
274
+ ### Advanced Usage
275
+
276
+ #### Default Client Pattern
215
277
 
216
- ### Events
278
+ Use a singleton client throughout your application:
217
279
 
218
- Tasks are event-driven and an application must listen to predefined events to
219
- manage the status and messages of a task.
280
+ ```typescript
281
+ // Initialize once at startup
282
+ createClient({ apiKey, region, project });
220
283
 
221
- Use `.addEventListener()` to listen for task events.
284
+ // Access anywhere in your app
285
+ import { Client } from "@relevanceai/sdk";
286
+ const client = Client.default();
287
+ ```
222
288
 
223
- ```js
224
- task.sendMessage("What came first; the chicken or the egg?");
289
+ #### Multiple Clients
225
290
 
226
- task.addEventListener("message", ({ detail }) => {
227
- const { message } = detail;
228
- console.log("> %s", message.text);
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
- Tasks dispatch `CustomEvent`. Event properties will be set in the `detail`
233
- field of the event. You can see the types of events for more information about
234
- the properties associated with different events.
316
+ ## Examples
317
+
318
+ For complete working examples, check out the `internal/examples` directory:
319
+
320
+ - **Deno Examples** (`internal/examples/deno/`):
235
321
 
236
- Remember to call `task.stopListening()` once you no longer need to listen to
237
- the task.
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
- The following events are available for agent subjects.
332
+ ## API Reference
242
333
 
243
- #### `start`
334
+ ### Client
244
335
 
245
- When a _new_ task starts.
336
+ ```typescript
337
+ class Client {
338
+ constructor(key: Key);
339
+ static default(): Client;
246
340
 
247
- **Details**
341
+ readonly key: Key;
342
+ readonly region: Region;
343
+ readonly project: string;
248
344
 
249
- ```ts
250
- interface StartEventDetails {
251
- id: string;
252
- status: TaskStatus;
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
- #### `status`
359
+ ### Key
360
+
361
+ ```typescript
362
+ class Key {
363
+ static async generateEmbedKey(options: GenerateEmbedKeyOptions): Promise<Key>;
257
364
 
258
- Whenever the task's _status_ changes.
365
+ constructor(options: CreateKeyOptions);
259
366
 
260
- > **Note:** this event does **not** fire for starting status. Use the `start`
261
- > event if you need the initial status.
367
+ readonly region: Region;
368
+ readonly project: string;
369
+ readonly agentId?: string;
370
+ readonly taskPrefix?: string;
262
371
 
263
- **Details**
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
- ```ts
266
- interface StatusEventDetails {
267
- status: TaskStatus;
385
+ interface GenerateEmbedKeyOptions {
386
+ region: Region;
387
+ project: string;
388
+ agentId: string;
268
389
  }
269
390
  ```
270
391
 
271
- ##### `update`
392
+ ### Agent
272
393
 
273
- A task has updated. This update will always be a tool for now but may expand in
274
- the future.
394
+ ```typescript
395
+ class Agent {
396
+ static async get(id: string, client?: Client): Promise<Agent>;
275
397
 
276
- **Details**
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
- ```ts
279
- interface UpdateEventDetails {
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
- #### `message`
412
+ ### Task
285
413
 
286
- A task has received a message.
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
- > **Note:** you will receive messages from _both_ subjects and users.
422
+ readonly id: string;
423
+ readonly title: string;
424
+ readonly status: TaskStatus;
425
+ readonly agent: Agent;
289
426
 
290
- **Details**
427
+ isRunning(): boolean;
428
+ getMessages(options?: { from?: Date }): Promise<AnyTaskMessage[]>;
429
+ subscribe(): void;
430
+ unsubscribe(): void;
291
431
 
292
- ```ts
293
- interface MessageEventDetails {
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
- #### `error`
446
+ ### Messages
447
+
448
+ ```typescript
449
+ abstract class TaskMessage {
450
+ readonly id: string;
451
+ readonly type: MessageType;
452
+ readonly createdAt: Date;
299
453
 
300
- Whenever the task has failed.
454
+ isAgent(): boolean;
455
+ }
301
456
 
302
- **Details**
457
+ class AgentMessage extends TaskMessage {
458
+ readonly text: string;
459
+ }
303
460
 
304
- ```ts
305
- interface ErrorEventDetails {
306
- error: TaskMessage<"error">;
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
- **Example**
474
+ ### Types
311
475
 
312
- ```js
313
- task.addEventListener("error", ({ detail }) => {
314
- const { error } = detail;
315
- console.error("Task failed:", error.text);
316
-
317
- // clean up
318
- task.stopListening();
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.