@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/script/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/script/message/task.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
class
|
|
3
|
+
exports.GenericMessage = void 0;
|
|
4
|
+
class GenericMessage {
|
|
5
5
|
message;
|
|
6
6
|
constructor(message) {
|
|
7
7
|
this.message = message;
|
|
@@ -9,7 +9,7 @@ class TaskMessage {
|
|
|
9
9
|
/**
|
|
10
10
|
* The task's message type.
|
|
11
11
|
*
|
|
12
|
-
* @property {
|
|
12
|
+
* @property {TaskMessageType}
|
|
13
13
|
*/
|
|
14
14
|
get type() {
|
|
15
15
|
return this.message.content.type;
|
|
@@ -38,5 +38,29 @@ class TaskMessage {
|
|
|
38
38
|
isAgent() {
|
|
39
39
|
return this.type === "agent-message";
|
|
40
40
|
}
|
|
41
|
+
/**
|
|
42
|
+
* Returns if the message is from a tool.
|
|
43
|
+
*
|
|
44
|
+
* @returns {boolean}
|
|
45
|
+
*/
|
|
46
|
+
isTool() {
|
|
47
|
+
return this.type === "tool-run";
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Returns if the message was sent from a user.
|
|
51
|
+
*
|
|
52
|
+
* @returns {boolean}
|
|
53
|
+
*/
|
|
54
|
+
isUser() {
|
|
55
|
+
return this.type === "user-message";
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Returns if the message was an error sent by the agent.
|
|
59
|
+
*
|
|
60
|
+
* @returns {boolean}
|
|
61
|
+
*/
|
|
62
|
+
isAgentError() {
|
|
63
|
+
return this.type === "agent-error";
|
|
64
|
+
}
|
|
41
65
|
}
|
|
42
|
-
exports.
|
|
66
|
+
exports.GenericMessage = GenericMessage;
|
package/script/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 {};
|
package/script/message/tool.js
CHANGED
|
@@ -2,14 +2,35 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ToolMessage = void 0;
|
|
4
4
|
const task_js_1 = require("./task.js");
|
|
5
|
-
|
|
5
|
+
const tool_js_1 = require("../tool.js");
|
|
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
|
*
|
|
9
|
-
* @property {
|
|
19
|
+
* @property {ToolStatus}
|
|
10
20
|
*/
|
|
21
|
+
// deno-lint-ignore getter-return
|
|
11
22
|
get status() {
|
|
12
|
-
|
|
23
|
+
const status = this.message.content.tool_run_state;
|
|
24
|
+
switch (status) {
|
|
25
|
+
case "cancelled":
|
|
26
|
+
case "pending":
|
|
27
|
+
case "running":
|
|
28
|
+
case "error":
|
|
29
|
+
return status;
|
|
30
|
+
// agents and tools have different end statuses, align them
|
|
31
|
+
case "finished":
|
|
32
|
+
return "completed";
|
|
33
|
+
}
|
|
13
34
|
}
|
|
14
35
|
/**
|
|
15
36
|
* Parameters used to call the tool.
|
|
@@ -25,7 +46,7 @@ class ToolMessage extends task_js_1.TaskMessage {
|
|
|
25
46
|
* @property {object|null}
|
|
26
47
|
*/
|
|
27
48
|
get output() {
|
|
28
|
-
return this.status === "
|
|
49
|
+
return this.status === "completed" ? this.message.content.output : null;
|
|
29
50
|
}
|
|
30
51
|
/**
|
|
31
52
|
* Tool errors.
|
|
@@ -40,18 +61,18 @@ class ToolMessage extends task_js_1.TaskMessage {
|
|
|
40
61
|
}));
|
|
41
62
|
}
|
|
42
63
|
/**
|
|
43
|
-
* The tool
|
|
64
|
+
* The tool or agent ID.
|
|
44
65
|
*
|
|
45
66
|
* @property {string}
|
|
46
67
|
*/
|
|
47
|
-
get
|
|
68
|
+
get toolOrAgentId() {
|
|
48
69
|
return this.message.content.tool_config.id;
|
|
49
70
|
}
|
|
50
71
|
/**
|
|
51
72
|
* The agent's ID, if a sub-agent.
|
|
52
73
|
*
|
|
53
74
|
* @property {string}
|
|
54
|
-
* @see {@link ToolMessage
|
|
75
|
+
* @see {@link ToolMessage#isSubAgent}
|
|
55
76
|
*/
|
|
56
77
|
get agentId() {
|
|
57
78
|
return this.isSubAgent()
|
|
@@ -75,8 +96,8 @@ class ToolMessage extends task_js_1.TaskMessage {
|
|
|
75
96
|
return this.message.content.tool_config.region;
|
|
76
97
|
}
|
|
77
98
|
/**
|
|
78
|
-
* The task ID the
|
|
79
|
-
* a
|
|
99
|
+
* The task ID the subagent ran. Will be `null` if the tool message is not
|
|
100
|
+
* a subagent.
|
|
80
101
|
*
|
|
81
102
|
* @property {string}
|
|
82
103
|
* @see {@link ToolMessage.isSubAgent}
|
|
@@ -109,5 +130,20 @@ class ToolMessage extends task_js_1.TaskMessage {
|
|
|
109
130
|
hasErrors() {
|
|
110
131
|
return this.message.content.errors.length > 0;
|
|
111
132
|
}
|
|
133
|
+
/**
|
|
134
|
+
* Checks if the tool message is currently running. Note that pending tools
|
|
135
|
+
* are also classified as running as they are just scheduled for running.
|
|
136
|
+
*
|
|
137
|
+
* @returns {boolean}
|
|
138
|
+
*/
|
|
139
|
+
isRunning() {
|
|
140
|
+
switch (this.status) {
|
|
141
|
+
case "pending":
|
|
142
|
+
case "running":
|
|
143
|
+
return true;
|
|
144
|
+
default:
|
|
145
|
+
return false;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
112
148
|
}
|
|
113
149
|
exports.ToolMessage = ToolMessage;
|
package/script/message/user.d.ts
CHANGED
|
@@ -1,10 +1,15 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { Attachment } from "../client.js";
|
|
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;
|
|
6
11
|
}
|
|
7
|
-
export declare class UserMessage extends
|
|
12
|
+
export declare class UserMessage extends GenericMessage<UserMessageContent> {
|
|
8
13
|
/**
|
|
9
14
|
* The message as text sent.
|
|
10
15
|
*
|
|
@@ -17,4 +22,16 @@ export declare class UserMessage extends TaskMessage<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
|
}
|
package/script/message/user.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.UserMessage = void 0;
|
|
4
4
|
const task_js_1 = require("./task.js");
|
|
5
|
-
class UserMessage extends task_js_1.
|
|
5
|
+
class UserMessage extends task_js_1.GenericMessage {
|
|
6
6
|
/**
|
|
7
7
|
* The message as text sent.
|
|
8
8
|
*
|
|
@@ -19,5 +19,24 @@ class UserMessage extends task_js_1.TaskMessage {
|
|
|
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;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { GenericMessage } from "./task.js";
|
|
2
|
+
export interface WorkforceAgentHandoverMessageContent {
|
|
3
|
+
type: "workforce-agent-handover";
|
|
4
|
+
task_details?: {
|
|
5
|
+
project: string;
|
|
6
|
+
region: string;
|
|
7
|
+
conversation_id: string;
|
|
8
|
+
};
|
|
9
|
+
agent_details: {
|
|
10
|
+
agent_id: string;
|
|
11
|
+
project: string;
|
|
12
|
+
region: string;
|
|
13
|
+
name?: string;
|
|
14
|
+
emoji?: string;
|
|
15
|
+
description?: string;
|
|
16
|
+
deleted_reason?: "entity_deleted";
|
|
17
|
+
};
|
|
18
|
+
trigger: {
|
|
19
|
+
message: string;
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
export declare class WorkforceAgentHandoverMessage extends GenericMessage<WorkforceAgentHandoverMessageContent> {
|
|
23
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.WorkforceAgentHandoverMessage = void 0;
|
|
4
|
+
const task_js_1 = require("./task.js");
|
|
5
|
+
class WorkforceAgentHandoverMessage extends task_js_1.GenericMessage {
|
|
6
|
+
}
|
|
7
|
+
exports.WorkforceAgentHandoverMessage = WorkforceAgentHandoverMessage;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { AgentTaskState } from "../agent.js";
|
|
2
|
+
import { GenericMessage } from "./task.js";
|
|
3
|
+
export interface WorkforceAgentMessageContent {
|
|
4
|
+
type: "workforce-agent-run";
|
|
5
|
+
task_details: {
|
|
6
|
+
project: string;
|
|
7
|
+
region: string;
|
|
8
|
+
conversation_id: string;
|
|
9
|
+
finished_state?: AgentTaskState;
|
|
10
|
+
current_state?: AgentTaskState;
|
|
11
|
+
};
|
|
12
|
+
agent_details?: {
|
|
13
|
+
agent_id: string;
|
|
14
|
+
project: string;
|
|
15
|
+
region: string;
|
|
16
|
+
name?: string;
|
|
17
|
+
emoji?: string;
|
|
18
|
+
description?: string;
|
|
19
|
+
deleted_reason?: "entity_deleted";
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
export declare class WorkforceAgentMessage extends GenericMessage<WorkforceAgentMessageContent> {
|
|
23
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.WorkforceAgentMessage = void 0;
|
|
4
|
+
const task_js_1 = require("./task.js");
|
|
5
|
+
class WorkforceAgentMessage extends task_js_1.GenericMessage {
|
|
6
|
+
}
|
|
7
|
+
exports.WorkforceAgentMessage = WorkforceAgentMessage;
|
package/script/mod.d.ts
CHANGED
|
@@ -1,10 +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
|
-
export {
|
|
6
|
-
export type {
|
|
7
|
-
export type { AgentMessage } from "./message/agent.js";
|
|
8
|
-
export type { ToolMessage } from "./message/tool.js";
|
|
9
|
-
export type { UserMessage } from "./message/user.js";
|
|
10
|
-
export type { AnyTaskMessage } from "./message/task.js";
|
|
5
|
+
export { Workforce } from "./workforce.js";
|
|
6
|
+
export type { Task } from "./task/task.js";
|
package/script/mod.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.Workforce = exports.REGION_US = exports.REGION_EU = exports.REGION_AU = exports.Key = exports.createClient = exports.Client = exports.Agent = void 0;
|
|
4
4
|
var agent_js_1 = require("./agent.js");
|
|
5
5
|
Object.defineProperty(exports, "Agent", { enumerable: true, get: function () { return agent_js_1.Agent; } });
|
|
6
6
|
var client_js_1 = require("./client.js");
|
|
@@ -12,5 +12,5 @@ var region_js_1 = require("./region.js");
|
|
|
12
12
|
Object.defineProperty(exports, "REGION_AU", { enumerable: true, get: function () { return region_js_1.REGION_AU; } });
|
|
13
13
|
Object.defineProperty(exports, "REGION_EU", { enumerable: true, get: function () { return region_js_1.REGION_EU; } });
|
|
14
14
|
Object.defineProperty(exports, "REGION_US", { enumerable: true, get: function () { return region_js_1.REGION_US; } });
|
|
15
|
-
var
|
|
16
|
-
Object.defineProperty(exports, "
|
|
15
|
+
var workforce_js_1 = require("./workforce.js");
|
|
16
|
+
Object.defineProperty(exports, "Workforce", { enumerable: true, get: function () { return workforce_js_1.Workforce; } });
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { type Agent, type AgentTaskState } from "../agent.js";
|
|
2
|
+
import { Client } from "../client.js";
|
|
3
|
+
import type { AnyTaskMessage } from "../message/task.js";
|
|
4
|
+
import { Task, type TaskMetadata, type TaskStrategy } from "./task.js";
|
|
5
|
+
export type AgentTaskMetadata = {
|
|
6
|
+
knowledge_set: string;
|
|
7
|
+
insert_date: string;
|
|
8
|
+
update_date: string;
|
|
9
|
+
conversation: {
|
|
10
|
+
created_by_user_id: string;
|
|
11
|
+
state: AgentTaskState;
|
|
12
|
+
title: string;
|
|
13
|
+
};
|
|
14
|
+
};
|
|
15
|
+
export declare class AgentStrategy implements TaskStrategy<Agent> {
|
|
16
|
+
static get(id: string, agent: Agent, client?: Client): Promise<Task<Agent>>;
|
|
17
|
+
private readonly id;
|
|
18
|
+
private readonly agent;
|
|
19
|
+
private readonly client;
|
|
20
|
+
constructor(id: string, agent: Agent, client: Client);
|
|
21
|
+
get subject(): Agent;
|
|
22
|
+
getMetadata(): Promise<TaskMetadata>;
|
|
23
|
+
getMessages({ after }?: {
|
|
24
|
+
after?: Date;
|
|
25
|
+
}): Promise<AnyTaskMessage[]>;
|
|
26
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AgentStrategy = void 0;
|
|
4
|
+
const agent_js_1 = require("../agent.js");
|
|
5
|
+
const client_js_1 = require("../client.js");
|
|
6
|
+
const agent_error_js_1 = require("../message/agent-error.js");
|
|
7
|
+
const agent_js_2 = require("../message/agent.js");
|
|
8
|
+
const tool_js_1 = require("../message/tool.js");
|
|
9
|
+
const user_js_1 = require("../message/user.js");
|
|
10
|
+
const task_js_1 = require("./task.js");
|
|
11
|
+
class AgentStrategy {
|
|
12
|
+
static async get(id, agent, client = client_js_1.Client.default()) {
|
|
13
|
+
const subject = new this(id, agent, client);
|
|
14
|
+
return new task_js_1.Task(await subject.getMetadata(), subject);
|
|
15
|
+
}
|
|
16
|
+
id;
|
|
17
|
+
agent;
|
|
18
|
+
client;
|
|
19
|
+
constructor(id, agent, client) {
|
|
20
|
+
this.id = id;
|
|
21
|
+
this.agent = agent;
|
|
22
|
+
this.client = client;
|
|
23
|
+
}
|
|
24
|
+
get subject() {
|
|
25
|
+
return this.agent;
|
|
26
|
+
}
|
|
27
|
+
async getMetadata() {
|
|
28
|
+
const { metadata } = await this.client.fetch(`/agents/${this.agent.id}/tasks/${this.id}/metadata`);
|
|
29
|
+
return {
|
|
30
|
+
id: this.id,
|
|
31
|
+
region: this.client.region,
|
|
32
|
+
project: this.client.project,
|
|
33
|
+
name: metadata.conversation.title,
|
|
34
|
+
status: (0, agent_js_1.stateToStatus)(metadata.conversation.state),
|
|
35
|
+
createdAt: new Date(metadata.insert_date),
|
|
36
|
+
updatedAt: new Date(metadata.update_date),
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
async getMessages({ after = new Date(0) } = {}) {
|
|
40
|
+
const url = `/agents/${this.agent.id}/tasks/${this.id}/view`;
|
|
41
|
+
const res = await this.client.fetch(url, {
|
|
42
|
+
method: "POST",
|
|
43
|
+
body: JSON.stringify({
|
|
44
|
+
page_size: 1_000, // @todo: pagination
|
|
45
|
+
cursor: {
|
|
46
|
+
after: after.toISOString(),
|
|
47
|
+
},
|
|
48
|
+
}),
|
|
49
|
+
});
|
|
50
|
+
// message should be in ascending order
|
|
51
|
+
return res.results.reverse().map((data) => {
|
|
52
|
+
switch (data.content.type) {
|
|
53
|
+
case "agent-error":
|
|
54
|
+
return new agent_error_js_1.AgentErrorMessage(data);
|
|
55
|
+
case "agent-message":
|
|
56
|
+
return new agent_js_2.AgentMessage(data);
|
|
57
|
+
case "tool-run":
|
|
58
|
+
return new tool_js_1.ToolMessage(data);
|
|
59
|
+
case "user-message":
|
|
60
|
+
return new user_js_1.UserMessage(data);
|
|
61
|
+
default:
|
|
62
|
+
throw new Error("unknown message response");
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
exports.AgentStrategy = AgentStrategy;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { Emitter } from "../emitter.js";
|
|
2
|
+
import type { AnyTaskMessage } from "../message/task.js";
|
|
3
|
+
import type { Region } from "../region.js";
|
|
4
|
+
import type { Workforce } from "../workforce.js";
|
|
5
|
+
import type { Agent } from "../agent.js";
|
|
6
|
+
import type { AgentErrorMessage } from "../message/agent-error.js";
|
|
7
|
+
export type TaskStatus = "not-started" | "idle" | "paused" | "queued" | "running" | "action" | "completed" | "cancelled" | "error";
|
|
8
|
+
export interface TaskMetadata {
|
|
9
|
+
id: string;
|
|
10
|
+
region: Region;
|
|
11
|
+
project: string;
|
|
12
|
+
status: TaskStatus;
|
|
13
|
+
name: string;
|
|
14
|
+
createdAt: Date;
|
|
15
|
+
updatedAt: Date;
|
|
16
|
+
}
|
|
17
|
+
type TaskEventMap = {
|
|
18
|
+
updated: undefined;
|
|
19
|
+
message: {
|
|
20
|
+
message: AnyTaskMessage;
|
|
21
|
+
};
|
|
22
|
+
error: {
|
|
23
|
+
message: AgentErrorMessage;
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
export interface TaskStrategy<S> {
|
|
27
|
+
subject: S;
|
|
28
|
+
getMessages(options?: {
|
|
29
|
+
after?: Date;
|
|
30
|
+
}): Promise<AnyTaskMessage[]>;
|
|
31
|
+
getMetadata(): Promise<TaskMetadata>;
|
|
32
|
+
}
|
|
33
|
+
export declare const resetBackoffDuration: unique symbol;
|
|
34
|
+
export declare class Task<S extends Agent | Workforce, E extends TaskEventMap = TaskEventMap> extends Emitter<E> {
|
|
35
|
+
#private;
|
|
36
|
+
private subscribed;
|
|
37
|
+
private backoff;
|
|
38
|
+
private backoffDuration;
|
|
39
|
+
private readonly strategy;
|
|
40
|
+
constructor(metadata: TaskMetadata, strategy: TaskStrategy<S>);
|
|
41
|
+
get subject(): S;
|
|
42
|
+
get id(): string;
|
|
43
|
+
get region(): Region;
|
|
44
|
+
get project(): string;
|
|
45
|
+
get name(): string;
|
|
46
|
+
get status(): TaskStatus;
|
|
47
|
+
get createdAt(): Date;
|
|
48
|
+
get updatedAt(): Date;
|
|
49
|
+
getMessages(options?: {
|
|
50
|
+
after?: Date;
|
|
51
|
+
}): Promise<AnyTaskMessage[]>;
|
|
52
|
+
isRunning(): boolean;
|
|
53
|
+
unsubscribe(): void;
|
|
54
|
+
[resetBackoffDuration](): void;
|
|
55
|
+
addEventListener<K extends keyof E>(type: Extract<K, string>, listener: ((event: CustomEvent<E[K]>) => void) | {
|
|
56
|
+
handleEvent: (event: CustomEvent<E[K]>) => void;
|
|
57
|
+
} | null, options?: boolean | AddEventListenerOptions): void;
|
|
58
|
+
}
|
|
59
|
+
export {};
|