@relevanceai/sdk 3.0.0-alpha.4 → 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 +240 -98
- package/esm/agent.d.ts +47 -8
- package/esm/agent.js +161 -14
- package/esm/client.d.ts +6 -1
- package/esm/client.js +38 -4
- package/esm/event.d.ts +6 -25
- package/esm/event.js +4 -19
- package/esm/key.d.ts +1 -1
- package/esm/message/agent-error.d.ts +7 -2
- package/esm/message/agent-error.js +8 -2
- package/esm/message/agent.d.ts +2 -2
- package/esm/message/agent.js +2 -2
- package/esm/message/task.d.ts +25 -4
- package/esm/message/task.js +26 -2
- package/esm/message/tool.d.ts +30 -12
- package/esm/message/tool.js +46 -10
- package/esm/message/user.d.ts +19 -2
- package/esm/message/user.js +21 -2
- package/esm/message/workforce-agent-handover.d.ts +23 -0
- package/esm/message/workforce-agent-handover.js +3 -0
- package/esm/message/workforce-agent.d.ts +23 -0
- package/esm/message/workforce-agent.js +3 -0
- package/esm/mod.d.ts +3 -7
- package/esm/mod.js +1 -1
- package/esm/task/agent-strategy.d.ts +26 -0
- package/esm/task/agent-strategy.js +63 -0
- package/esm/task/task.d.ts +59 -0
- package/esm/task/task.js +166 -0
- package/esm/task/workforce-strategy.d.ts +17 -0
- package/esm/task/workforce-strategy.js +68 -0
- package/esm/tool.d.ts +22 -0
- package/esm/tool.js +27 -0
- package/esm/utils.d.ts +1 -0
- package/esm/utils.js +4 -0
- package/esm/workforce.d.ts +22 -0
- package/esm/workforce.js +50 -0
- package/package.json +7 -1
- package/script/agent.d.ts +47 -8
- package/script/agent.js +162 -14
- package/script/client.d.ts +6 -1
- package/script/client.js +37 -3
- package/script/event.d.ts +6 -25
- package/script/event.js +6 -23
- package/script/key.d.ts +1 -1
- package/script/message/agent-error.d.ts +7 -2
- package/script/message/agent-error.js +7 -1
- package/script/message/agent.d.ts +2 -2
- package/script/message/agent.js +1 -1
- package/script/message/task.d.ts +25 -4
- package/script/message/task.js +28 -4
- package/script/message/tool.d.ts +30 -12
- package/script/message/tool.js +45 -9
- package/script/message/user.d.ts +19 -2
- package/script/message/user.js +20 -1
- package/script/message/workforce-agent-handover.d.ts +23 -0
- package/script/message/workforce-agent-handover.js +7 -0
- package/script/message/workforce-agent.d.ts +23 -0
- package/script/message/workforce-agent.js +7 -0
- package/script/mod.d.ts +3 -7
- package/script/mod.js +3 -3
- package/script/task/agent-strategy.d.ts +26 -0
- package/script/task/agent-strategy.js +67 -0
- package/script/task/task.d.ts +59 -0
- package/script/task/task.js +170 -0
- package/script/task/workforce-strategy.d.ts +17 -0
- package/script/task/workforce-strategy.js +72 -0
- package/script/tool.d.ts +22 -0
- package/script/tool.js +31 -0
- package/script/utils.d.ts +1 -0
- package/script/utils.js +5 -0
- package/script/workforce.d.ts +22 -0
- package/script/workforce.js +54 -0
- package/esm/task.d.ts +0 -57
- package/esm/task.js +0 -259
- package/script/task.d.ts +0 -57
- package/script/task.js +0 -263
package/esm/agent.js
CHANGED
|
@@ -1,17 +1,113 @@
|
|
|
1
1
|
import { Client } from "./client.js";
|
|
2
|
-
import { resetSubscribeBackoff, Task } from "./task.js";
|
|
3
2
|
import { randomUUID } from "./utils.js";
|
|
3
|
+
import { AgentStrategy, } from "./task/agent-strategy.js";
|
|
4
|
+
import { resetBackoffDuration, Task } from "./task/task.js";
|
|
5
|
+
/**
|
|
6
|
+
* Converts an AgentTaskState to a simplified TaskStatus.
|
|
7
|
+
*
|
|
8
|
+
* @dev
|
|
9
|
+
* We want to simplify because our states are simplified in the UI and also
|
|
10
|
+
* some states have combined reasoning that the consumer does not need to care
|
|
11
|
+
* about. i.e. "queued-for-approval" "queued-for-rerun" should just be "queued".
|
|
12
|
+
*
|
|
13
|
+
* @param {AgentTaskState} state The agent task state to convert.
|
|
14
|
+
* @returns {TaskStatus} The simplified task status.
|
|
15
|
+
*/
|
|
16
|
+
export function stateToStatus(state) {
|
|
17
|
+
switch (state) {
|
|
18
|
+
case "paused":
|
|
19
|
+
return "paused";
|
|
20
|
+
case "idle":
|
|
21
|
+
return "idle";
|
|
22
|
+
case "starting-up":
|
|
23
|
+
case "waiting-for-capacity":
|
|
24
|
+
case "queued-for-approval":
|
|
25
|
+
case "queued-for-rerun":
|
|
26
|
+
return "queued";
|
|
27
|
+
case "running":
|
|
28
|
+
return "running";
|
|
29
|
+
case "pending-approval":
|
|
30
|
+
case "escalated":
|
|
31
|
+
return "action";
|
|
32
|
+
case "timed-out":
|
|
33
|
+
return "error";
|
|
34
|
+
case "cancelled":
|
|
35
|
+
return "cancelled";
|
|
36
|
+
case "completed":
|
|
37
|
+
return "completed";
|
|
38
|
+
case "unrecoverable":
|
|
39
|
+
case "errored-pending-approval":
|
|
40
|
+
return "error";
|
|
41
|
+
default:
|
|
42
|
+
throw new Error(`unhandled task state: ${state}`);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Reverses {@link stateToStatus} returning the group of task states a _simplified_
|
|
47
|
+
* status may relate to.
|
|
48
|
+
*
|
|
49
|
+
* @see {stateToStatus}
|
|
50
|
+
* @param {TaskStatus} status
|
|
51
|
+
* @returns {AgentTaskState[]}
|
|
52
|
+
*/
|
|
53
|
+
function statusToStates(status) {
|
|
54
|
+
switch (status) {
|
|
55
|
+
case "not-started":
|
|
56
|
+
// a special sdk-only status
|
|
57
|
+
return [];
|
|
58
|
+
case "idle":
|
|
59
|
+
return ["idle"];
|
|
60
|
+
case "paused":
|
|
61
|
+
return ["paused"];
|
|
62
|
+
case "queued":
|
|
63
|
+
return [
|
|
64
|
+
"starting-up",
|
|
65
|
+
"waiting-for-capacity",
|
|
66
|
+
"queued-for-approval",
|
|
67
|
+
"queued-for-rerun",
|
|
68
|
+
];
|
|
69
|
+
case "running":
|
|
70
|
+
return ["running"];
|
|
71
|
+
case "action":
|
|
72
|
+
return ["pending-approval", "escalated"];
|
|
73
|
+
case "completed":
|
|
74
|
+
return ["completed"];
|
|
75
|
+
case "cancelled":
|
|
76
|
+
return ["cancelled"];
|
|
77
|
+
case "error":
|
|
78
|
+
return ["errored-pending-approval", "timed-out", "unrecoverable"];
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
function taskSortOptionsToParam(sort) {
|
|
82
|
+
if ("createdAt" in sort) {
|
|
83
|
+
return { insert_date: sort.createdAt };
|
|
84
|
+
}
|
|
85
|
+
else if ("updatedAt" in sort) {
|
|
86
|
+
return { update_date: sort.updatedAt };
|
|
87
|
+
}
|
|
88
|
+
throw new Error("invalid sort option");
|
|
89
|
+
}
|
|
4
90
|
const taskPrefixDelimiter = "_-_";
|
|
5
91
|
export class Agent {
|
|
6
|
-
#config;
|
|
7
|
-
client;
|
|
8
92
|
static async get(id, client = Client.default()) {
|
|
9
93
|
const config = await Agent.#fetchConfig(id, client);
|
|
10
94
|
return new Agent(config, client);
|
|
11
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
|
+
}
|
|
12
106
|
static #fetchConfig(agentId, client = Client.default()) {
|
|
13
107
|
return client.fetch(`/agents/${agentId}/get`).then(({ agent }) => agent);
|
|
14
108
|
}
|
|
109
|
+
#config;
|
|
110
|
+
client;
|
|
15
111
|
constructor(config, client) {
|
|
16
112
|
this.client = client;
|
|
17
113
|
this.#config = config;
|
|
@@ -19,6 +115,12 @@ export class Agent {
|
|
|
19
115
|
get id() {
|
|
20
116
|
return this.#config.agent_id;
|
|
21
117
|
}
|
|
118
|
+
get region() {
|
|
119
|
+
return this.client.region;
|
|
120
|
+
}
|
|
121
|
+
get project() {
|
|
122
|
+
return this.#config.project;
|
|
123
|
+
}
|
|
22
124
|
get name() {
|
|
23
125
|
return this.#config.name;
|
|
24
126
|
}
|
|
@@ -34,16 +136,54 @@ export class Agent {
|
|
|
34
136
|
get updatedAt() {
|
|
35
137
|
return new Date(this.#config.update_date_);
|
|
36
138
|
}
|
|
37
|
-
get region() {
|
|
38
|
-
return this.client.region;
|
|
39
|
-
}
|
|
40
|
-
get project() {
|
|
41
|
-
return this.client.project;
|
|
42
|
-
}
|
|
43
139
|
getTask(taskId) {
|
|
44
|
-
return
|
|
140
|
+
return AgentStrategy.get(taskId, this, this.client);
|
|
45
141
|
}
|
|
46
|
-
async
|
|
142
|
+
async getTasks({ sort = { createdAt: "asc" }, pageSize = 100, page = 1, search, filter, } = {}) {
|
|
143
|
+
const filtersParam = [{
|
|
144
|
+
condition: "==",
|
|
145
|
+
condition_value: [this.id],
|
|
146
|
+
field: "conversation.agent_id",
|
|
147
|
+
filter_type: "exact_match",
|
|
148
|
+
}];
|
|
149
|
+
if (filter) {
|
|
150
|
+
for (const [field, value] of Object.entries(filter)) {
|
|
151
|
+
switch (field) {
|
|
152
|
+
case "status":
|
|
153
|
+
filtersParam.push({
|
|
154
|
+
condition: "==",
|
|
155
|
+
condition_value: value.flatMap((s) => statusToStates(s)),
|
|
156
|
+
field: "conversation.state",
|
|
157
|
+
filter_type: "exact_match",
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
const sortParam = taskSortOptionsToParam(sort);
|
|
163
|
+
const query = new URLSearchParams([
|
|
164
|
+
["filters", JSON.stringify(filtersParam)],
|
|
165
|
+
["sort", JSON.stringify([sortParam])],
|
|
166
|
+
["page_size", pageSize.toString()],
|
|
167
|
+
["page", page.toString()],
|
|
168
|
+
]);
|
|
169
|
+
if (search?.trim()) {
|
|
170
|
+
query.set("query", search.trim());
|
|
171
|
+
}
|
|
172
|
+
const { results } = await this.client.fetch(`/agents/conversations/list?${query.toString()}`);
|
|
173
|
+
return results.map(({ metadata }) => new Task({
|
|
174
|
+
id: metadata.knowledge_set,
|
|
175
|
+
region: this.client.region,
|
|
176
|
+
project: this.client.project,
|
|
177
|
+
name: metadata.conversation.title,
|
|
178
|
+
status: stateToStatus(metadata.conversation.state),
|
|
179
|
+
createdAt: new Date(metadata.insert_date),
|
|
180
|
+
updatedAt: new Date(metadata.update_date),
|
|
181
|
+
}, new AgentStrategy(metadata.knowledge_set, this, this.client)));
|
|
182
|
+
}
|
|
183
|
+
async sendMessage(message, attachOrTask, maybeTask) {
|
|
184
|
+
const hasAttachments = Array.isArray(attachOrTask);
|
|
185
|
+
const attachFiles = hasAttachments ? attachOrTask : [];
|
|
186
|
+
const task = hasAttachments ? maybeTask : attachOrTask;
|
|
47
187
|
let taskId;
|
|
48
188
|
// embed keys require a task prefixing for new tasks
|
|
49
189
|
if (!task && this.client.isEmbedKey()) {
|
|
@@ -52,6 +192,10 @@ export class Agent {
|
|
|
52
192
|
else if (task) {
|
|
53
193
|
taskId = task.id;
|
|
54
194
|
}
|
|
195
|
+
const attachments = [];
|
|
196
|
+
for (const item of attachFiles) {
|
|
197
|
+
attachments.push(item instanceof File ? await this.client.uploadTempFile(item) : item);
|
|
198
|
+
}
|
|
55
199
|
const res = await this.client.fetch("/agents/trigger", {
|
|
56
200
|
method: "POST",
|
|
57
201
|
body: JSON.stringify({
|
|
@@ -60,13 +204,16 @@ export class Agent {
|
|
|
60
204
|
message: {
|
|
61
205
|
role: "user",
|
|
62
206
|
content: message,
|
|
63
|
-
attachments:
|
|
207
|
+
attachments: attachments.map(({ fileName, fileUrl }) => ({
|
|
208
|
+
file_name: fileName,
|
|
209
|
+
file_url: fileUrl,
|
|
210
|
+
})),
|
|
64
211
|
},
|
|
65
212
|
}),
|
|
66
213
|
});
|
|
67
214
|
if (task) {
|
|
68
|
-
task[
|
|
215
|
+
task[resetBackoffDuration]();
|
|
69
216
|
}
|
|
70
|
-
return task ?? this.getTask(res.conversation_id);
|
|
217
|
+
return task ?? await this.getTask(res.conversation_id);
|
|
71
218
|
}
|
|
72
219
|
}
|
package/esm/client.d.ts
CHANGED
|
@@ -5,6 +5,10 @@ type CreateClientOptions = {
|
|
|
5
5
|
region: Region;
|
|
6
6
|
project: string;
|
|
7
7
|
};
|
|
8
|
+
export type Attachment = {
|
|
9
|
+
fileName: string;
|
|
10
|
+
fileUrl: string;
|
|
11
|
+
};
|
|
8
12
|
/**
|
|
9
13
|
* Creates and returns the _default_ client instance.
|
|
10
14
|
*
|
|
@@ -26,7 +30,8 @@ export declare class Client {
|
|
|
26
30
|
get region(): Region;
|
|
27
31
|
get project(): string;
|
|
28
32
|
isEmbedKey(): boolean;
|
|
29
|
-
fetch<T>(input: "/agents/trigger" | `/agents/${string}/get` | `/agents/${string}/tasks/${string}/metadata` | `/agents/${string}/tasks/${string}/view` | "/agents/conversations/list", 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>;
|
|
30
34
|
url(path: string): URL;
|
|
35
|
+
uploadTempFile(file: File): Promise<Attachment>;
|
|
31
36
|
}
|
|
32
37
|
export {};
|
package/esm/client.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { regionBaseURL } from "./region.js";
|
|
2
|
-
import { cleanPath } from "./utils.js";
|
|
2
|
+
import { cleanPath, getFileExtension } from "./utils.js";
|
|
3
3
|
import { Key } from "./key.js";
|
|
4
4
|
let defaultClient;
|
|
5
5
|
/**
|
|
@@ -50,11 +50,16 @@ export class Client {
|
|
|
50
50
|
}
|
|
51
51
|
async fetch(input, init) {
|
|
52
52
|
const url = this.url(input);
|
|
53
|
-
const
|
|
54
|
-
|
|
53
|
+
const reqInit = Object.assign({}, init, {
|
|
54
|
+
headers: {
|
|
55
|
+
...this.key.fetchHeaders(),
|
|
56
|
+
...init?.headers,
|
|
57
|
+
},
|
|
58
|
+
});
|
|
59
|
+
const response = await fetch(url, reqInit);
|
|
55
60
|
if (!response.ok) {
|
|
56
61
|
const body = await response.text();
|
|
57
|
-
console.error(
|
|
62
|
+
console.error("client#fetch(): request failed.", url, body, reqInit);
|
|
58
63
|
throw new Error(response.statusText);
|
|
59
64
|
}
|
|
60
65
|
return response.json();
|
|
@@ -65,4 +70,33 @@ export class Client {
|
|
|
65
70
|
}
|
|
66
71
|
return new URL(cleanPath(path), this.baseURL);
|
|
67
72
|
}
|
|
73
|
+
async uploadTempFile(file) {
|
|
74
|
+
const { upload_url: uploadUrl, download_url: downloadUrl } = await this
|
|
75
|
+
.fetch("/services/get_temporary_file_upload_url", {
|
|
76
|
+
method: "POST",
|
|
77
|
+
body: JSON.stringify({
|
|
78
|
+
filename: file.name,
|
|
79
|
+
extension: getFileExtension(file.name),
|
|
80
|
+
}),
|
|
81
|
+
});
|
|
82
|
+
let content = file.type;
|
|
83
|
+
if (file.type.startsWith("text/")) {
|
|
84
|
+
content += "; charset=utf-8"; // force utf-8 for text files
|
|
85
|
+
}
|
|
86
|
+
const response = await fetch(uploadUrl, {
|
|
87
|
+
method: "PUT",
|
|
88
|
+
body: file,
|
|
89
|
+
headers: {
|
|
90
|
+
"content-type": content,
|
|
91
|
+
"x-amz-tagging": "Expire=true",
|
|
92
|
+
},
|
|
93
|
+
});
|
|
94
|
+
if (!response.ok) {
|
|
95
|
+
throw new Error(response.statusText);
|
|
96
|
+
}
|
|
97
|
+
return {
|
|
98
|
+
fileName: file.name,
|
|
99
|
+
fileUrl: downloadUrl,
|
|
100
|
+
};
|
|
101
|
+
}
|
|
68
102
|
}
|
package/esm/event.d.ts
CHANGED
|
@@ -1,33 +1,14 @@
|
|
|
1
1
|
import type { AgentErrorMessage } from "./message/agent-error.js";
|
|
2
|
-
import type {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
export declare class TaskStartEvent extends CustomEvent<{
|
|
7
|
-
id: string;
|
|
8
|
-
status: TaskStatus;
|
|
9
|
-
}> {
|
|
10
|
-
readonly type = "start";
|
|
11
|
-
constructor(id: string, status: TaskStatus);
|
|
12
|
-
}
|
|
13
|
-
export declare class TaskStatusEvent extends CustomEvent<{
|
|
14
|
-
status: TaskStatus;
|
|
15
|
-
}> {
|
|
16
|
-
readonly type = "status";
|
|
17
|
-
constructor(status: TaskStatus);
|
|
2
|
+
import type { AnyTaskMessage } from "./message/task.js";
|
|
3
|
+
export declare class TaskUpdateEvent extends CustomEvent<void> {
|
|
4
|
+
readonly type = "update";
|
|
5
|
+
constructor();
|
|
18
6
|
}
|
|
19
7
|
export declare class TaskMessageEvent extends CustomEvent<{
|
|
20
|
-
message:
|
|
8
|
+
message: AnyTaskMessage;
|
|
21
9
|
}> {
|
|
22
10
|
readonly type = "message";
|
|
23
|
-
constructor(message:
|
|
24
|
-
isUserMessage(): boolean;
|
|
25
|
-
}
|
|
26
|
-
export declare class TaskUpdateEvent extends CustomEvent<{
|
|
27
|
-
message: ToolMessage;
|
|
28
|
-
}> {
|
|
29
|
-
readonly type = "update";
|
|
30
|
-
constructor(message: ToolMessage);
|
|
11
|
+
constructor(message: AnyTaskMessage);
|
|
31
12
|
}
|
|
32
13
|
export declare class TaskErrorEvent extends CustomEvent<{
|
|
33
14
|
message: AgentErrorMessage;
|
package/esm/event.js
CHANGED
|
@@ -1,13 +1,7 @@
|
|
|
1
|
-
export class
|
|
2
|
-
type = "
|
|
3
|
-
constructor(
|
|
4
|
-
super("
|
|
5
|
-
}
|
|
6
|
-
}
|
|
7
|
-
export class TaskStatusEvent extends CustomEvent {
|
|
8
|
-
type = "status";
|
|
9
|
-
constructor(status) {
|
|
10
|
-
super("status", { detail: { status } });
|
|
1
|
+
export class TaskUpdateEvent extends CustomEvent {
|
|
2
|
+
type = "update";
|
|
3
|
+
constructor() {
|
|
4
|
+
super("update");
|
|
11
5
|
}
|
|
12
6
|
}
|
|
13
7
|
export class TaskMessageEvent extends CustomEvent {
|
|
@@ -15,15 +9,6 @@ export class TaskMessageEvent extends CustomEvent {
|
|
|
15
9
|
constructor(message) {
|
|
16
10
|
super("message", { detail: { message } });
|
|
17
11
|
}
|
|
18
|
-
isUserMessage() {
|
|
19
|
-
return this.detail.message.type === "user-message";
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
export class TaskUpdateEvent extends CustomEvent {
|
|
23
|
-
type = "update";
|
|
24
|
-
constructor(message) {
|
|
25
|
-
super("update", { detail: { message } });
|
|
26
|
-
}
|
|
27
12
|
}
|
|
28
13
|
export class TaskErrorEvent extends CustomEvent {
|
|
29
14
|
type = "error";
|
package/esm/key.d.ts
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { GenericMessage } from "./task.js";
|
|
2
2
|
export interface AgentErrorMessageContent {
|
|
3
3
|
type: "agent-error";
|
|
4
|
+
errors: {
|
|
5
|
+
body: string;
|
|
6
|
+
}[];
|
|
4
7
|
}
|
|
5
|
-
export declare class AgentErrorMessage extends
|
|
8
|
+
export declare class AgentErrorMessage extends GenericMessage<AgentErrorMessageContent> {
|
|
9
|
+
get errors(): string[];
|
|
10
|
+
get lastError(): string;
|
|
6
11
|
}
|
|
@@ -1,3 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export class AgentErrorMessage extends
|
|
1
|
+
import { GenericMessage } from "./task.js";
|
|
2
|
+
export class AgentErrorMessage extends GenericMessage {
|
|
3
|
+
get errors() {
|
|
4
|
+
return this.message.content.errors.map((e) => e.body);
|
|
5
|
+
}
|
|
6
|
+
get lastError() {
|
|
7
|
+
return this.errors.at(-1);
|
|
8
|
+
}
|
|
3
9
|
}
|
package/esm/message/agent.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { GenericMessage } from "./task.js";
|
|
2
2
|
export interface AgentMessageContent {
|
|
3
3
|
type: "agent-message";
|
|
4
4
|
text: string;
|
|
5
5
|
}
|
|
6
|
-
export declare class AgentMessage extends
|
|
6
|
+
export declare class AgentMessage extends GenericMessage<AgentMessageContent> {
|
|
7
7
|
get text(): string;
|
|
8
8
|
get agentId(): string;
|
|
9
9
|
}
|
package/esm/message/agent.js
CHANGED
package/esm/message/task.d.ts
CHANGED
|
@@ -2,7 +2,10 @@ import type { AgentMessage } from "./agent.js";
|
|
|
2
2
|
import type { AgentErrorMessage } from "./agent-error.js";
|
|
3
3
|
import type { ToolMessage } from "./tool.js";
|
|
4
4
|
import type { UserMessage } from "./user.js";
|
|
5
|
-
|
|
5
|
+
import type { WorkforceAgentMessage } from "./workforce-agent.js";
|
|
6
|
+
import type { WorkforceAgentHandoverMessage } from "./workforce-agent-handover.js";
|
|
7
|
+
export type AnyTaskMessage = AgentMessage | AgentErrorMessage | ToolMessage | UserMessage | WorkforceAgentMessage | WorkforceAgentHandoverMessage;
|
|
8
|
+
export type TaskMessageType = AnyTaskMessage["type"];
|
|
6
9
|
interface MessageContent {
|
|
7
10
|
type: AnyTaskMessage["type"];
|
|
8
11
|
}
|
|
@@ -11,13 +14,13 @@ export interface TaskMessageData<C extends MessageContent = MessageContent> {
|
|
|
11
14
|
insert_date_: string;
|
|
12
15
|
content: C;
|
|
13
16
|
}
|
|
14
|
-
export declare abstract class
|
|
17
|
+
export declare abstract class GenericMessage<C extends MessageContent = MessageContent> {
|
|
15
18
|
protected readonly message: TaskMessageData<C>;
|
|
16
19
|
constructor(message: TaskMessageData<C>);
|
|
17
20
|
/**
|
|
18
21
|
* The task's message type.
|
|
19
22
|
*
|
|
20
|
-
* @property {
|
|
23
|
+
* @property {TaskMessageType}
|
|
21
24
|
*/
|
|
22
25
|
get type(): C["type"];
|
|
23
26
|
/**
|
|
@@ -37,6 +40,24 @@ export declare abstract class TaskMessage<C extends MessageContent = MessageCont
|
|
|
37
40
|
*
|
|
38
41
|
* @returns {boolean}
|
|
39
42
|
*/
|
|
40
|
-
isAgent():
|
|
43
|
+
isAgent(): this is AgentMessage;
|
|
44
|
+
/**
|
|
45
|
+
* Returns if the message is from a tool.
|
|
46
|
+
*
|
|
47
|
+
* @returns {boolean}
|
|
48
|
+
*/
|
|
49
|
+
isTool(): this is ToolMessage;
|
|
50
|
+
/**
|
|
51
|
+
* Returns if the message was sent from a user.
|
|
52
|
+
*
|
|
53
|
+
* @returns {boolean}
|
|
54
|
+
*/
|
|
55
|
+
isUser(): this is UserMessage;
|
|
56
|
+
/**
|
|
57
|
+
* Returns if the message was an error sent by the agent.
|
|
58
|
+
*
|
|
59
|
+
* @returns {boolean}
|
|
60
|
+
*/
|
|
61
|
+
isAgentError(): this is AgentErrorMessage;
|
|
41
62
|
}
|
|
42
63
|
export {};
|
package/esm/message/task.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export class
|
|
1
|
+
export class GenericMessage {
|
|
2
2
|
message;
|
|
3
3
|
constructor(message) {
|
|
4
4
|
this.message = message;
|
|
@@ -6,7 +6,7 @@ export class TaskMessage {
|
|
|
6
6
|
/**
|
|
7
7
|
* The task's message type.
|
|
8
8
|
*
|
|
9
|
-
* @property {
|
|
9
|
+
* @property {TaskMessageType}
|
|
10
10
|
*/
|
|
11
11
|
get type() {
|
|
12
12
|
return this.message.content.type;
|
|
@@ -35,4 +35,28 @@ export class TaskMessage {
|
|
|
35
35
|
isAgent() {
|
|
36
36
|
return this.type === "agent-message";
|
|
37
37
|
}
|
|
38
|
+
/**
|
|
39
|
+
* Returns if the message is from a tool.
|
|
40
|
+
*
|
|
41
|
+
* @returns {boolean}
|
|
42
|
+
*/
|
|
43
|
+
isTool() {
|
|
44
|
+
return this.type === "tool-run";
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Returns if the message was sent from a user.
|
|
48
|
+
*
|
|
49
|
+
* @returns {boolean}
|
|
50
|
+
*/
|
|
51
|
+
isUser() {
|
|
52
|
+
return this.type === "user-message";
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Returns if the message was an error sent by the agent.
|
|
56
|
+
*
|
|
57
|
+
* @returns {boolean}
|
|
58
|
+
*/
|
|
59
|
+
isAgentError() {
|
|
60
|
+
return this.type === "agent-error";
|
|
61
|
+
}
|
|
38
62
|
}
|
package/esm/message/tool.d.ts
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
|
+
import type { JSONSchema4 } from "json-schema";
|
|
1
2
|
import type { Region } from "../region.js";
|
|
2
|
-
import {
|
|
3
|
+
import { GenericMessage, type TaskMessageData } from "./task.js";
|
|
4
|
+
import { Tool } from "../tool.js";
|
|
5
|
+
type ToolState = "cancelled" | "error" | "finished" | "pending" | "running";
|
|
6
|
+
export type ToolStatus = "cancelled" | "error" | "completed" | "pending" | "running";
|
|
3
7
|
export interface ToolMessageContent {
|
|
4
8
|
type: "tool-run";
|
|
5
|
-
tool_run_state:
|
|
9
|
+
tool_run_state: ToolState;
|
|
6
10
|
output: Record<string, unknown> & {
|
|
7
11
|
_agent_conversation_details?: {
|
|
8
12
|
agent_id: string;
|
|
@@ -19,19 +23,25 @@ export interface ToolMessageContent {
|
|
|
19
23
|
step_name: string;
|
|
20
24
|
}[];
|
|
21
25
|
tool_config: {
|
|
22
|
-
|
|
23
|
-
|
|
26
|
+
type: "agent" | "tool";
|
|
27
|
+
title: string;
|
|
28
|
+
description: string;
|
|
24
29
|
region: Region;
|
|
25
30
|
project: string;
|
|
31
|
+
id: string;
|
|
32
|
+
emoji?: string;
|
|
33
|
+
params_schema: JSONSchema4;
|
|
26
34
|
};
|
|
27
35
|
}
|
|
28
|
-
export declare class ToolMessage extends
|
|
36
|
+
export declare class ToolMessage extends GenericMessage<ToolMessageContent> {
|
|
37
|
+
readonly tool?: Tool;
|
|
38
|
+
constructor(message: TaskMessageData<ToolMessageContent>);
|
|
29
39
|
/**
|
|
30
40
|
* The tool status for _this_ message.
|
|
31
41
|
*
|
|
32
|
-
* @property {
|
|
42
|
+
* @property {ToolStatus}
|
|
33
43
|
*/
|
|
34
|
-
get status():
|
|
44
|
+
get status(): ToolStatus;
|
|
35
45
|
/**
|
|
36
46
|
* Parameters used to call the tool.
|
|
37
47
|
*
|
|
@@ -55,16 +65,16 @@ export declare class ToolMessage extends TaskMessage<ToolMessageContent> {
|
|
|
55
65
|
message: string;
|
|
56
66
|
}[];
|
|
57
67
|
/**
|
|
58
|
-
* The tool
|
|
68
|
+
* The tool or agent ID.
|
|
59
69
|
*
|
|
60
70
|
* @property {string}
|
|
61
71
|
*/
|
|
62
|
-
get
|
|
72
|
+
get toolOrAgentId(): string;
|
|
63
73
|
/**
|
|
64
74
|
* The agent's ID, if a sub-agent.
|
|
65
75
|
*
|
|
66
76
|
* @property {string}
|
|
67
|
-
* @see {@link ToolMessage
|
|
77
|
+
* @see {@link ToolMessage#isSubAgent}
|
|
68
78
|
*/
|
|
69
79
|
get agentId(): string | null;
|
|
70
80
|
/**
|
|
@@ -80,8 +90,8 @@ export declare class ToolMessage extends TaskMessage<ToolMessageContent> {
|
|
|
80
90
|
*/
|
|
81
91
|
get region(): Region;
|
|
82
92
|
/**
|
|
83
|
-
* The task ID the
|
|
84
|
-
* a
|
|
93
|
+
* The task ID the subagent ran. Will be `null` if the tool message is not
|
|
94
|
+
* a subagent.
|
|
85
95
|
*
|
|
86
96
|
* @property {string}
|
|
87
97
|
* @see {@link ToolMessage.isSubAgent}
|
|
@@ -105,4 +115,12 @@ export declare class ToolMessage extends TaskMessage<ToolMessageContent> {
|
|
|
105
115
|
* @returns {boolean}
|
|
106
116
|
*/
|
|
107
117
|
hasErrors(): boolean;
|
|
118
|
+
/**
|
|
119
|
+
* Checks if the tool message is currently running. Note that pending tools
|
|
120
|
+
* are also classified as running as they are just scheduled for running.
|
|
121
|
+
*
|
|
122
|
+
* @returns {boolean}
|
|
123
|
+
*/
|
|
124
|
+
isRunning(): boolean;
|
|
108
125
|
}
|
|
126
|
+
export {};
|