@relevanceai/sdk 3.0.0-alpha.5 → 3.0.0-alpha.6

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 CHANGED
@@ -183,6 +183,15 @@ const client = createClient(embedKey);
183
183
  #### Loading agents
184
184
 
185
185
  ```typescript
186
+ // fetch all agents (with pagination)
187
+ const agents = await Agent.getAll({ pageSize: 20, page: 1 });
188
+
189
+ // fetch all agents with custom page size
190
+ const agents = await Agent.getAll({ pageSize: 50, page: 3 });
191
+
192
+ // fetch all agents using default options (pageSize: 20, page: 1)
193
+ const agents = await Agent.getAll();
194
+
186
195
  // using the default client
187
196
  const agent = await Agent.get("agent-id");
188
197
 
@@ -290,7 +299,7 @@ in the Relevance AI workforce platform.
290
299
 
291
300
  #### Available Events
292
301
 
293
- - **`updated`**: Whenever a subject has been updated.
302
+ - **`update`**: Whenever a subject has been update.
294
303
  - **`message`**: Unified event for all message types
295
304
  - **`error`**: Error notifications
296
305
 
@@ -337,6 +346,7 @@ createClient({ apiKey, region, project });
337
346
 
338
347
  // Access anywhere in your app
339
348
  import { Client } from "@relevanceai/sdk";
349
+
340
350
  const client = Client.default();
341
351
  ```
342
352
 
@@ -375,6 +385,7 @@ For complete working examples, check out the `internal/examples` directory:
375
385
 
376
386
  - (Agent) Creating tasks
377
387
  - (Agent) Getting a task
388
+ - (Agent) Getting all agents
378
389
  - (Agent) Getting all tasks
379
390
  - (Agent) Getting an agent
380
391
  - (Workforce) Creating a task
@@ -391,6 +402,7 @@ For complete working examples, check out the `internal/examples` directory:
391
402
  ```typescript
392
403
  class Client {
393
404
  constructor(key: Key);
405
+
394
406
  static default(): Client;
395
407
 
396
408
  readonly key: Key;
@@ -398,7 +410,9 @@ class Client {
398
410
  readonly project: string;
399
411
 
400
412
  isEmbedKey(): boolean;
413
+
401
414
  fetch<T>(endpoint: string, init?: RequestInit): Promise<T>;
415
+
402
416
  url(path: string): URL;
403
417
  }
404
418
 
@@ -425,7 +439,9 @@ class Key {
425
439
  readonly taskPrefix?: string;
426
440
 
427
441
  isEmbed(): boolean;
442
+
428
443
  fetchHeaders(): HeadersInit;
444
+
429
445
  toJSON(): CreateKeyOptions;
430
446
  }
431
447
 
@@ -450,6 +466,11 @@ interface GenerateEmbedKeyOptions {
450
466
  class Agent {
451
467
  static async get(id: string, client?: Client): Promise<Agent>;
452
468
 
469
+ static async getAll(
470
+ options?: GetAllOptions,
471
+ client?: Client
472
+ ): Promise<Agent[]>;
473
+
453
474
  readonly id: string;
454
475
  readonly name?: string;
455
476
  readonly description?: string;
@@ -492,6 +513,11 @@ interface GetTaskOptions {
492
513
  status?: TaskStatus[];
493
514
  };
494
515
  }
516
+
517
+ interface GetAllOptions {
518
+ pageSize?: number; // default: 20
519
+ page?: number; // default: 1
520
+ }
495
521
  ```
496
522
 
497
523
  ### Workforce
@@ -527,9 +553,11 @@ class Task<T extends Agent | Workforce = Agent> extends EventTarget {
527
553
  getMessages(options: { from: Date }): Promise<AnyTaskMessage[]>;
528
554
 
529
555
  subscribe(): void;
556
+
530
557
  unsubscribe(): void;
531
558
 
532
559
  addEventListener(type: string, listener: EventListener): void;
560
+
533
561
  removeEventListener(type: string, listener: EventListener): void;
534
562
  }
535
563
 
@@ -567,6 +595,11 @@ class UserMessage extends GenericMessage {
567
595
 
568
596
  class ToolMessage extends GenericMessage {
569
597
  readonly status: "cancelled" | "pending" | "running" | "completed" | "failed";
598
+ readonly tool?: Tool; // Available when message is from a tool (not subagent)
599
+ readonly toolOrAgentId: string; // ID of the tool or subagent
600
+
601
+ isSubAgent(): boolean; // Check if this is a subagent execution
602
+ subAgentTaskId: string | null; // Task ID if this is a subagent, null otherwise
570
603
  }
571
604
 
572
605
  class AgentErrorMessage extends GenericMessage {}
@@ -576,6 +609,20 @@ class WorkforceAgentMessage extends GenericMessage {}
576
609
  class WorkforceAgentHandoverMessage extends GenericMessage {}
577
610
  ```
578
611
 
612
+ ### Tool
613
+
614
+ ```typescript
615
+ class Tool {
616
+ readonly id: string;
617
+ readonly name: string;
618
+ readonly avatar?: string;
619
+ readonly description?: string;
620
+ readonly region: Region;
621
+ readonly project: string;
622
+ readonly parametersSchema: JSONSchema4;
623
+ }
624
+ ```
625
+
579
626
  ## Contributing
580
627
 
581
628
  We welcome contributions to improve the SDK. Please follow these guidelines:
package/esm/agent.d.ts CHANGED
@@ -4,6 +4,7 @@ import { Task, type TaskStatus } from "./task/task.js";
4
4
  export interface AgentConfig {
5
5
  agent_id: string;
6
6
  public: boolean;
7
+ project: string;
7
8
  name?: string;
8
9
  description?: string;
9
10
  emoji?: string;
@@ -39,9 +40,14 @@ type GetTaskOptions = {
39
40
  status?: TaskStatus[];
40
41
  };
41
42
  };
43
+ type GetAllOptions = {
44
+ pageSize?: number;
45
+ page?: number;
46
+ };
42
47
  export declare class Agent {
43
48
  #private;
44
49
  static get(id: string, client?: Client): Promise<Agent>;
50
+ static getAll({ page, pageSize, }?: GetAllOptions, client?: Client): Promise<Agent[]>;
45
51
  private readonly client;
46
52
  constructor(config: AgentConfig, client: Client);
47
53
  get id(): string;
package/esm/agent.js CHANGED
@@ -78,7 +78,7 @@ function statusToStates(status) {
78
78
  return ["errored-pending-approval", "timed-out", "unrecoverable"];
79
79
  }
80
80
  }
81
- function sortOptionsToParam(sort) {
81
+ function taskSortOptionsToParam(sort) {
82
82
  if ("createdAt" in sort) {
83
83
  return { insert_date: sort.createdAt };
84
84
  }
@@ -93,6 +93,16 @@ export class Agent {
93
93
  const config = await Agent.#fetchConfig(id, client);
94
94
  return new Agent(config, client);
95
95
  }
96
+ static async getAll({ page = 1, pageSize = 20, } = {}, client = Client.default()) {
97
+ const { results } = await client.fetch("/agents/list", {
98
+ method: "POST",
99
+ body: JSON.stringify({
100
+ page_size: pageSize,
101
+ page,
102
+ }),
103
+ });
104
+ return results.map((config) => new Agent(config, client));
105
+ }
96
106
  static #fetchConfig(agentId, client = Client.default()) {
97
107
  return client.fetch(`/agents/${agentId}/get`).then(({ agent }) => agent);
98
108
  }
@@ -109,7 +119,7 @@ export class Agent {
109
119
  return this.client.region;
110
120
  }
111
121
  get project() {
112
- return this.client.project;
122
+ return this.#config.project;
113
123
  }
114
124
  get name() {
115
125
  return this.#config.name;
@@ -149,7 +159,7 @@ export class Agent {
149
159
  }
150
160
  }
151
161
  }
152
- const sortParam = sortOptionsToParam(sort);
162
+ const sortParam = taskSortOptionsToParam(sort);
153
163
  const query = new URLSearchParams([
154
164
  ["filters", JSON.stringify(filtersParam)],
155
165
  ["sort", JSON.stringify([sortParam])],
@@ -204,6 +214,6 @@ export class Agent {
204
214
  if (task) {
205
215
  task[resetBackoffDuration]();
206
216
  }
207
- return task ?? this.getTask(res.conversation_id);
217
+ return task ?? await this.getTask(res.conversation_id);
208
218
  }
209
219
  }
package/esm/client.d.ts CHANGED
@@ -30,7 +30,7 @@ export declare class Client {
30
30
  get region(): Region;
31
31
  get project(): string;
32
32
  isEmbedKey(): boolean;
33
- fetch<T>(input: "/agents/trigger" | `/agents/${string}/get` | `/agents/${string}/tasks/${string}/metadata` | `/agents/${string}/tasks/${string}/view` | "/agents/conversations/list" | "/services/get_temporary_file_upload_url" | `/workforce/items/${string}` | `/workforce/tasks/${string}/metadata` | `/workforce/items/${string}/tasks/${string}/messages` | "/workforce/trigger", init?: RequestInit): Promise<T>;
33
+ fetch<T>(input: "/agents/trigger" | `/agents/${string}/get` | `/agents/${string}/tasks/${string}/metadata` | `/agents/${string}/tasks/${string}/view` | "/agents/conversations/list" | "/services/get_temporary_file_upload_url" | `/workforce/items/${string}` | `/workforce/tasks/${string}/metadata` | `/workforce/items/${string}/tasks/${string}/messages` | "/workforce/trigger" | "/agents/list", init?: RequestInit): Promise<T>;
34
34
  url(path: string): URL;
35
35
  uploadTempFile(file: File): Promise<Attachment>;
36
36
  }
package/esm/event.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import type { AgentErrorMessage } from "./message/agent-error.js";
2
2
  import type { AnyTaskMessage } from "./message/task.js";
3
- export declare class TaskUpdatedEvent extends CustomEvent<void> {
3
+ export declare class TaskUpdateEvent extends CustomEvent<void> {
4
4
  readonly type = "update";
5
5
  constructor();
6
6
  }
package/esm/event.js CHANGED
@@ -1,4 +1,4 @@
1
- export class TaskUpdatedEvent extends CustomEvent {
1
+ export class TaskUpdateEvent extends CustomEvent {
2
2
  type = "update";
3
3
  constructor() {
4
4
  super("update");
@@ -1,5 +1,7 @@
1
+ import type { JSONSchema4 } from "json-schema";
1
2
  import type { Region } from "../region.js";
2
- import { GenericMessage } from "./task.js";
3
+ import { GenericMessage, type TaskMessageData } from "./task.js";
4
+ import { Tool } from "../tool.js";
3
5
  type ToolState = "cancelled" | "error" | "finished" | "pending" | "running";
4
6
  export type ToolStatus = "cancelled" | "error" | "completed" | "pending" | "running";
5
7
  export interface ToolMessageContent {
@@ -21,13 +23,19 @@ export interface ToolMessageContent {
21
23
  step_name: string;
22
24
  }[];
23
25
  tool_config: {
24
- id: string;
25
- type: "tool" | "agent";
26
+ type: "agent" | "tool";
27
+ title: string;
28
+ description: string;
26
29
  region: Region;
27
30
  project: string;
31
+ id: string;
32
+ emoji?: string;
33
+ params_schema: JSONSchema4;
28
34
  };
29
35
  }
30
36
  export declare class ToolMessage extends GenericMessage<ToolMessageContent> {
37
+ readonly tool?: Tool;
38
+ constructor(message: TaskMessageData<ToolMessageContent>);
31
39
  /**
32
40
  * The tool status for _this_ message.
33
41
  *
@@ -57,11 +65,11 @@ export declare class ToolMessage extends GenericMessage<ToolMessageContent> {
57
65
  message: string;
58
66
  }[];
59
67
  /**
60
- * The tool's ID.
68
+ * The tool or agent ID.
61
69
  *
62
70
  * @property {string}
63
71
  */
64
- get toolId(): string;
72
+ get toolOrAgentId(): string;
65
73
  /**
66
74
  * The agent's ID, if a sub-agent.
67
75
  *
@@ -82,8 +90,8 @@ export declare class ToolMessage extends GenericMessage<ToolMessageContent> {
82
90
  */
83
91
  get region(): Region;
84
92
  /**
85
- * The task ID the sub-agent ran. Will be `null` if the tool message is not
86
- * a sub-agent.
93
+ * The task ID the subagent ran. Will be `null` if the tool message is not
94
+ * a subagent.
87
95
  *
88
96
  * @property {string}
89
97
  * @see {@link ToolMessage.isSubAgent}
@@ -1,5 +1,15 @@
1
1
  import { GenericMessage } from "./task.js";
2
+ import { Tool } from "../tool.js";
2
3
  export class ToolMessage extends GenericMessage {
4
+ tool;
5
+ constructor(message) {
6
+ super(message);
7
+ if (message.content.tool_config.type === "tool") {
8
+ const { id, ...config } = message.content.tool_config;
9
+ this.tool = new Tool({ studio_id: id, ...config });
10
+ }
11
+ // @todo: subagent
12
+ }
3
13
  /**
4
14
  * The tool status for _this_ message.
5
15
  *
@@ -48,11 +58,11 @@ export class ToolMessage extends GenericMessage {
48
58
  }));
49
59
  }
50
60
  /**
51
- * The tool's ID.
61
+ * The tool or agent ID.
52
62
  *
53
63
  * @property {string}
54
64
  */
55
- get toolId() {
65
+ get toolOrAgentId() {
56
66
  return this.message.content.tool_config.id;
57
67
  }
58
68
  /**
@@ -83,8 +93,8 @@ export class ToolMessage extends GenericMessage {
83
93
  return this.message.content.tool_config.region;
84
94
  }
85
95
  /**
86
- * The task ID the sub-agent ran. Will be `null` if the tool message is not
87
- * a sub-agent.
96
+ * The task ID the subagent ran. Will be `null` if the tool message is not
97
+ * a subagent.
88
98
  *
89
99
  * @property {string}
90
100
  * @see {@link ToolMessage.isSubAgent}
@@ -1,5 +1,10 @@
1
+ import type { Attachment } from "../client.js";
1
2
  import { GenericMessage } from "./task.js";
2
3
  export interface UserMessageContent {
4
+ attachments?: {
5
+ file_url: string;
6
+ file_name: string;
7
+ }[];
3
8
  type: "user-message";
4
9
  text: string;
5
10
  is_trigger_message: boolean;
@@ -17,4 +22,16 @@ export declare class UserMessage extends GenericMessage<UserMessageContent> {
17
22
  * @returns {boolean}
18
23
  */
19
24
  isTrigger(): boolean;
25
+ /**
26
+ * The attachments sent with the message.
27
+ *
28
+ * @property {Attachment[]}
29
+ */
30
+ get attachments(): Attachment[];
31
+ /**
32
+ * Returns if the message has attachments.
33
+ *
34
+ * @returns {boolean}
35
+ */
36
+ hasAttachments(): boolean;
20
37
  }
@@ -16,4 +16,23 @@ export class UserMessage extends GenericMessage {
16
16
  isTrigger() {
17
17
  return this.message.content.is_trigger_message;
18
18
  }
19
+ /**
20
+ * The attachments sent with the message.
21
+ *
22
+ * @property {Attachment[]}
23
+ */
24
+ get attachments() {
25
+ return (this.message.content.attachments?.map(({ file_name, file_url }) => ({
26
+ fileName: file_name,
27
+ fileUrl: file_url,
28
+ })) ?? []);
29
+ }
30
+ /**
31
+ * Returns if the message has attachments.
32
+ *
33
+ * @returns {boolean}
34
+ */
35
+ hasAttachments() {
36
+ return this.attachments.length > 0;
37
+ }
19
38
  }
package/esm/mod.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  export { Agent } from "./agent.js";
2
- export { Client, createClient } from "./client.js";
2
+ export { type Attachment, Client, createClient } from "./client.js";
3
3
  export { Key } from "./key.js";
4
4
  export { type Region, REGION_AU, REGION_EU, REGION_US } from "./region.js";
5
5
  export { Workforce } from "./workforce.js";
6
+ export type { Task } from "./task/task.js";
package/esm/task/task.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { Emitter } from "../emitter.js";
2
2
  import { abortPromise, delay } from "../utils.js";
3
- import { TaskErrorEvent, TaskMessageEvent, TaskUpdatedEvent, } from "../event.js";
3
+ import { TaskErrorEvent, TaskMessageEvent, TaskUpdateEvent, } from "../event.js";
4
4
  export const resetBackoffDuration = Symbol("resetBackoffDuration");
5
5
  const backoffStartingDuration = 1_000;
6
6
  const backoffMaxDuration = 60_000;
@@ -74,7 +74,7 @@ export class Task extends Emitter {
74
74
  }
75
75
  let hasChanges = false;
76
76
  if (metadata.updatedAt > this.updatedAt) {
77
- this.dispatchEvent(new TaskUpdatedEvent());
77
+ this.dispatchEvent(new TaskUpdateEvent());
78
78
  hasChanges = true;
79
79
  }
80
80
  this.#metadata = metadata;
package/esm/tool.d.ts ADDED
@@ -0,0 +1,22 @@
1
+ import type { Region } from "./region.js";
2
+ import type { JSONSchema4 } from "json-schema";
3
+ export type ToolConfig = {
4
+ region: Region;
5
+ project: string;
6
+ studio_id: string;
7
+ title: string;
8
+ description: string;
9
+ emoji?: string;
10
+ params_schema: JSONSchema4;
11
+ };
12
+ export declare class Tool {
13
+ #private;
14
+ constructor(config: ToolConfig);
15
+ get id(): string;
16
+ get region(): Region;
17
+ get project(): string;
18
+ get name(): string;
19
+ get avatar(): string | undefined;
20
+ get description(): string | undefined;
21
+ get parametersSchema(): JSONSchema4;
22
+ }
package/esm/tool.js ADDED
@@ -0,0 +1,27 @@
1
+ export class Tool {
2
+ #config;
3
+ constructor(config) {
4
+ this.#config = config;
5
+ }
6
+ get id() {
7
+ return this.#config.studio_id;
8
+ }
9
+ get region() {
10
+ return this.#config.region;
11
+ }
12
+ get project() {
13
+ return this.#config.project;
14
+ }
15
+ get name() {
16
+ return this.#config.title;
17
+ }
18
+ get avatar() {
19
+ return this.#config.emoji;
20
+ }
21
+ get description() {
22
+ return this.#config.description;
23
+ }
24
+ get parametersSchema() {
25
+ return this.#config.params_schema;
26
+ }
27
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@relevanceai/sdk",
3
- "version": "3.0.0-alpha.5",
3
+ "version": "3.0.0-alpha.6",
4
4
  "license": "MIT",
5
5
  "main": "./script/mod.js",
6
6
  "module": "./esm/mod.js",
@@ -11,5 +11,11 @@
11
11
  }
12
12
  },
13
13
  "scripts": {},
14
+ "dependencies": {
15
+ "json-schema": "^0.4.0"
16
+ },
17
+ "devDependencies": {
18
+ "@types/json-schema": "^7.0.15"
19
+ },
14
20
  "_generatedBy": "dnt@dev"
15
21
  }
package/script/agent.d.ts CHANGED
@@ -4,6 +4,7 @@ import { Task, type TaskStatus } from "./task/task.js";
4
4
  export interface AgentConfig {
5
5
  agent_id: string;
6
6
  public: boolean;
7
+ project: string;
7
8
  name?: string;
8
9
  description?: string;
9
10
  emoji?: string;
@@ -39,9 +40,14 @@ type GetTaskOptions = {
39
40
  status?: TaskStatus[];
40
41
  };
41
42
  };
43
+ type GetAllOptions = {
44
+ pageSize?: number;
45
+ page?: number;
46
+ };
42
47
  export declare class Agent {
43
48
  #private;
44
49
  static get(id: string, client?: Client): Promise<Agent>;
50
+ static getAll({ page, pageSize, }?: GetAllOptions, client?: Client): Promise<Agent[]>;
45
51
  private readonly client;
46
52
  constructor(config: AgentConfig, client: Client);
47
53
  get id(): string;
package/script/agent.js CHANGED
@@ -82,7 +82,7 @@ function statusToStates(status) {
82
82
  return ["errored-pending-approval", "timed-out", "unrecoverable"];
83
83
  }
84
84
  }
85
- function sortOptionsToParam(sort) {
85
+ function taskSortOptionsToParam(sort) {
86
86
  if ("createdAt" in sort) {
87
87
  return { insert_date: sort.createdAt };
88
88
  }
@@ -97,6 +97,16 @@ class Agent {
97
97
  const config = await Agent.#fetchConfig(id, client);
98
98
  return new Agent(config, client);
99
99
  }
100
+ static async getAll({ page = 1, pageSize = 20, } = {}, client = client_js_1.Client.default()) {
101
+ const { results } = await client.fetch("/agents/list", {
102
+ method: "POST",
103
+ body: JSON.stringify({
104
+ page_size: pageSize,
105
+ page,
106
+ }),
107
+ });
108
+ return results.map((config) => new Agent(config, client));
109
+ }
100
110
  static #fetchConfig(agentId, client = client_js_1.Client.default()) {
101
111
  return client.fetch(`/agents/${agentId}/get`).then(({ agent }) => agent);
102
112
  }
@@ -113,7 +123,7 @@ class Agent {
113
123
  return this.client.region;
114
124
  }
115
125
  get project() {
116
- return this.client.project;
126
+ return this.#config.project;
117
127
  }
118
128
  get name() {
119
129
  return this.#config.name;
@@ -153,7 +163,7 @@ class Agent {
153
163
  }
154
164
  }
155
165
  }
156
- const sortParam = sortOptionsToParam(sort);
166
+ const sortParam = taskSortOptionsToParam(sort);
157
167
  const query = new URLSearchParams([
158
168
  ["filters", JSON.stringify(filtersParam)],
159
169
  ["sort", JSON.stringify([sortParam])],
@@ -208,7 +218,7 @@ class Agent {
208
218
  if (task) {
209
219
  task[task_js_1.resetBackoffDuration]();
210
220
  }
211
- return task ?? this.getTask(res.conversation_id);
221
+ return task ?? await this.getTask(res.conversation_id);
212
222
  }
213
223
  }
214
224
  exports.Agent = Agent;
@@ -30,7 +30,7 @@ export declare class Client {
30
30
  get region(): Region;
31
31
  get project(): string;
32
32
  isEmbedKey(): boolean;
33
- fetch<T>(input: "/agents/trigger" | `/agents/${string}/get` | `/agents/${string}/tasks/${string}/metadata` | `/agents/${string}/tasks/${string}/view` | "/agents/conversations/list" | "/services/get_temporary_file_upload_url" | `/workforce/items/${string}` | `/workforce/tasks/${string}/metadata` | `/workforce/items/${string}/tasks/${string}/messages` | "/workforce/trigger", init?: RequestInit): Promise<T>;
33
+ fetch<T>(input: "/agents/trigger" | `/agents/${string}/get` | `/agents/${string}/tasks/${string}/metadata` | `/agents/${string}/tasks/${string}/view` | "/agents/conversations/list" | "/services/get_temporary_file_upload_url" | `/workforce/items/${string}` | `/workforce/tasks/${string}/metadata` | `/workforce/items/${string}/tasks/${string}/messages` | "/workforce/trigger" | "/agents/list", init?: RequestInit): Promise<T>;
34
34
  url(path: string): URL;
35
35
  uploadTempFile(file: File): Promise<Attachment>;
36
36
  }
package/script/event.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import type { AgentErrorMessage } from "./message/agent-error.js";
2
2
  import type { AnyTaskMessage } from "./message/task.js";
3
- export declare class TaskUpdatedEvent extends CustomEvent<void> {
3
+ export declare class TaskUpdateEvent extends CustomEvent<void> {
4
4
  readonly type = "update";
5
5
  constructor();
6
6
  }
package/script/event.js CHANGED
@@ -1,13 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.TaskErrorEvent = exports.TaskMessageEvent = exports.TaskUpdatedEvent = void 0;
4
- class TaskUpdatedEvent extends CustomEvent {
3
+ exports.TaskErrorEvent = exports.TaskMessageEvent = exports.TaskUpdateEvent = void 0;
4
+ class TaskUpdateEvent extends CustomEvent {
5
5
  type = "update";
6
6
  constructor() {
7
7
  super("update");
8
8
  }
9
9
  }
10
- exports.TaskUpdatedEvent = TaskUpdatedEvent;
10
+ exports.TaskUpdateEvent = TaskUpdateEvent;
11
11
  class TaskMessageEvent extends CustomEvent {
12
12
  type = "message";
13
13
  constructor(message) {
@@ -1,5 +1,7 @@
1
+ import type { JSONSchema4 } from "json-schema";
1
2
  import type { Region } from "../region.js";
2
- import { GenericMessage } from "./task.js";
3
+ import { GenericMessage, type TaskMessageData } from "./task.js";
4
+ import { Tool } from "../tool.js";
3
5
  type ToolState = "cancelled" | "error" | "finished" | "pending" | "running";
4
6
  export type ToolStatus = "cancelled" | "error" | "completed" | "pending" | "running";
5
7
  export interface ToolMessageContent {
@@ -21,13 +23,19 @@ export interface ToolMessageContent {
21
23
  step_name: string;
22
24
  }[];
23
25
  tool_config: {
24
- id: string;
25
- type: "tool" | "agent";
26
+ type: "agent" | "tool";
27
+ title: string;
28
+ description: string;
26
29
  region: Region;
27
30
  project: string;
31
+ id: string;
32
+ emoji?: string;
33
+ params_schema: JSONSchema4;
28
34
  };
29
35
  }
30
36
  export declare class ToolMessage extends GenericMessage<ToolMessageContent> {
37
+ readonly tool?: Tool;
38
+ constructor(message: TaskMessageData<ToolMessageContent>);
31
39
  /**
32
40
  * The tool status for _this_ message.
33
41
  *
@@ -57,11 +65,11 @@ export declare class ToolMessage extends GenericMessage<ToolMessageContent> {
57
65
  message: string;
58
66
  }[];
59
67
  /**
60
- * The tool's ID.
68
+ * The tool or agent ID.
61
69
  *
62
70
  * @property {string}
63
71
  */
64
- get toolId(): string;
72
+ get toolOrAgentId(): string;
65
73
  /**
66
74
  * The agent's ID, if a sub-agent.
67
75
  *
@@ -82,8 +90,8 @@ export declare class ToolMessage extends GenericMessage<ToolMessageContent> {
82
90
  */
83
91
  get region(): Region;
84
92
  /**
85
- * The task ID the sub-agent ran. Will be `null` if the tool message is not
86
- * a sub-agent.
93
+ * The task ID the subagent ran. Will be `null` if the tool message is not
94
+ * a subagent.
87
95
  *
88
96
  * @property {string}
89
97
  * @see {@link ToolMessage.isSubAgent}
@@ -2,7 +2,17 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ToolMessage = void 0;
4
4
  const task_js_1 = require("./task.js");
5
+ const tool_js_1 = require("../tool.js");
5
6
  class ToolMessage extends task_js_1.GenericMessage {
7
+ tool;
8
+ constructor(message) {
9
+ super(message);
10
+ if (message.content.tool_config.type === "tool") {
11
+ const { id, ...config } = message.content.tool_config;
12
+ this.tool = new tool_js_1.Tool({ studio_id: id, ...config });
13
+ }
14
+ // @todo: subagent
15
+ }
6
16
  /**
7
17
  * The tool status for _this_ message.
8
18
  *
@@ -51,11 +61,11 @@ class ToolMessage extends task_js_1.GenericMessage {
51
61
  }));
52
62
  }
53
63
  /**
54
- * The tool's ID.
64
+ * The tool or agent ID.
55
65
  *
56
66
  * @property {string}
57
67
  */
58
- get toolId() {
68
+ get toolOrAgentId() {
59
69
  return this.message.content.tool_config.id;
60
70
  }
61
71
  /**
@@ -86,8 +96,8 @@ class ToolMessage extends task_js_1.GenericMessage {
86
96
  return this.message.content.tool_config.region;
87
97
  }
88
98
  /**
89
- * The task ID the sub-agent ran. Will be `null` if the tool message is not
90
- * a sub-agent.
99
+ * The task ID the subagent ran. Will be `null` if the tool message is not
100
+ * a subagent.
91
101
  *
92
102
  * @property {string}
93
103
  * @see {@link ToolMessage.isSubAgent}
@@ -1,5 +1,10 @@
1
+ import type { Attachment } from "../client.js";
1
2
  import { GenericMessage } from "./task.js";
2
3
  export interface UserMessageContent {
4
+ attachments?: {
5
+ file_url: string;
6
+ file_name: string;
7
+ }[];
3
8
  type: "user-message";
4
9
  text: string;
5
10
  is_trigger_message: boolean;
@@ -17,4 +22,16 @@ export declare class UserMessage extends GenericMessage<UserMessageContent> {
17
22
  * @returns {boolean}
18
23
  */
19
24
  isTrigger(): boolean;
25
+ /**
26
+ * The attachments sent with the message.
27
+ *
28
+ * @property {Attachment[]}
29
+ */
30
+ get attachments(): Attachment[];
31
+ /**
32
+ * Returns if the message has attachments.
33
+ *
34
+ * @returns {boolean}
35
+ */
36
+ hasAttachments(): boolean;
20
37
  }
@@ -19,5 +19,24 @@ class UserMessage extends task_js_1.GenericMessage {
19
19
  isTrigger() {
20
20
  return this.message.content.is_trigger_message;
21
21
  }
22
+ /**
23
+ * The attachments sent with the message.
24
+ *
25
+ * @property {Attachment[]}
26
+ */
27
+ get attachments() {
28
+ return (this.message.content.attachments?.map(({ file_name, file_url }) => ({
29
+ fileName: file_name,
30
+ fileUrl: file_url,
31
+ })) ?? []);
32
+ }
33
+ /**
34
+ * Returns if the message has attachments.
35
+ *
36
+ * @returns {boolean}
37
+ */
38
+ hasAttachments() {
39
+ return this.attachments.length > 0;
40
+ }
22
41
  }
23
42
  exports.UserMessage = UserMessage;
package/script/mod.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  export { Agent } from "./agent.js";
2
- export { Client, createClient } from "./client.js";
2
+ export { type Attachment, Client, createClient } from "./client.js";
3
3
  export { Key } from "./key.js";
4
4
  export { type Region, REGION_AU, REGION_EU, REGION_US } from "./region.js";
5
5
  export { Workforce } from "./workforce.js";
6
+ export type { Task } from "./task/task.js";
@@ -77,7 +77,7 @@ class Task extends emitter_js_1.Emitter {
77
77
  }
78
78
  let hasChanges = false;
79
79
  if (metadata.updatedAt > this.updatedAt) {
80
- this.dispatchEvent(new event_js_1.TaskUpdatedEvent());
80
+ this.dispatchEvent(new event_js_1.TaskUpdateEvent());
81
81
  hasChanges = true;
82
82
  }
83
83
  this.#metadata = metadata;
@@ -0,0 +1,22 @@
1
+ import type { Region } from "./region.js";
2
+ import type { JSONSchema4 } from "json-schema";
3
+ export type ToolConfig = {
4
+ region: Region;
5
+ project: string;
6
+ studio_id: string;
7
+ title: string;
8
+ description: string;
9
+ emoji?: string;
10
+ params_schema: JSONSchema4;
11
+ };
12
+ export declare class Tool {
13
+ #private;
14
+ constructor(config: ToolConfig);
15
+ get id(): string;
16
+ get region(): Region;
17
+ get project(): string;
18
+ get name(): string;
19
+ get avatar(): string | undefined;
20
+ get description(): string | undefined;
21
+ get parametersSchema(): JSONSchema4;
22
+ }
package/script/tool.js ADDED
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Tool = void 0;
4
+ class Tool {
5
+ #config;
6
+ constructor(config) {
7
+ this.#config = config;
8
+ }
9
+ get id() {
10
+ return this.#config.studio_id;
11
+ }
12
+ get region() {
13
+ return this.#config.region;
14
+ }
15
+ get project() {
16
+ return this.#config.project;
17
+ }
18
+ get name() {
19
+ return this.#config.title;
20
+ }
21
+ get avatar() {
22
+ return this.#config.emoji;
23
+ }
24
+ get description() {
25
+ return this.#config.description;
26
+ }
27
+ get parametersSchema() {
28
+ return this.#config.params_schema;
29
+ }
30
+ }
31
+ exports.Tool = Tool;