@relevanceai/sdk 3.0.0-alpha.1 → 3.0.0-alpha.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +422 -193
- package/esm/agent.d.ts +20 -8
- package/esm/agent.js +32 -12
- package/esm/client.d.ts +4 -8
- package/esm/client.js +11 -12
- package/esm/emitter.d.ts +16 -0
- package/esm/emitter.js +15 -0
- package/esm/{events.d.ts → event.d.ts} +10 -13
- package/esm/{events.js → event.js} +0 -6
- package/esm/message/agent-error.d.ts +6 -0
- package/esm/message/agent-error.js +3 -0
- package/esm/message/agent.d.ts +9 -0
- package/esm/message/agent.js +9 -0
- package/esm/message/task.d.ts +42 -0
- package/esm/message/task.js +38 -0
- package/esm/message/tool.d.ts +108 -0
- package/esm/message/tool.js +109 -0
- package/esm/message/user.d.ts +20 -0
- package/esm/message/user.js +19 -0
- package/esm/mod.d.ts +6 -3
- package/esm/mod.js +1 -0
- package/esm/task.d.ts +50 -18
- package/esm/task.js +228 -65
- package/esm/utils.d.ts +1 -5
- package/esm/utils.js +1 -13
- package/package.json +4 -2
- package/script/agent.d.ts +29 -0
- package/script/agent.js +76 -0
- package/script/client.d.ts +32 -0
- package/script/client.js +73 -0
- package/script/emitter.d.ts +16 -0
- package/script/emitter.js +19 -0
- package/script/event.d.ts +37 -0
- package/script/event.js +41 -0
- package/script/key.d.ts +86 -0
- package/script/key.js +125 -0
- package/script/message/agent-error.d.ts +6 -0
- package/script/message/agent-error.js +7 -0
- package/script/message/agent.d.ts +9 -0
- package/script/message/agent.js +13 -0
- package/script/message/task.d.ts +42 -0
- package/script/message/task.js +42 -0
- package/script/message/tool.d.ts +108 -0
- package/script/message/tool.js +113 -0
- package/script/message/user.d.ts +20 -0
- package/script/message/user.js +23 -0
- package/script/mod.d.ts +10 -0
- package/script/mod.js +16 -0
- package/script/package.json +3 -0
- package/script/region.d.ts +5 -0
- package/script/region.js +10 -0
- package/script/task.d.ts +57 -0
- package/script/task.js +263 -0
- package/script/utils.d.ts +4 -0
- package/script/utils.js +56 -0
- package/esm/agent-task.d.ts +0 -61
- package/esm/agent-task.js +0 -112
- package/esm/message.d.ts +0 -18
- package/esm/message.js +0 -18
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export type EventMap = Record<string, unknown>;
|
|
2
|
+
/**
|
|
3
|
+
* Emitter
|
|
4
|
+
*
|
|
5
|
+
* Abstraction for type-assisting event targets.
|
|
6
|
+
*
|
|
7
|
+
* @internal
|
|
8
|
+
*/
|
|
9
|
+
export declare abstract class Emitter<M extends EventMap = Record<string, never>> extends EventTarget {
|
|
10
|
+
addEventListener<K extends keyof M>(type: Extract<K, string>, listener: ((event: CustomEvent<M[K]>) => void) | {
|
|
11
|
+
handleEvent: (event: CustomEvent<M[K]>) => void;
|
|
12
|
+
} | null, options?: boolean | AddEventListenerOptions): void;
|
|
13
|
+
removeEventListener<K extends keyof M>(type: Extract<K, string>, listener: ((event: CustomEvent<M[K]>) => void) | {
|
|
14
|
+
handleEvent: (event: CustomEvent<M[K]>) => void;
|
|
15
|
+
} | null, options?: boolean | AddEventListenerOptions): void;
|
|
16
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Emitter = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Emitter
|
|
6
|
+
*
|
|
7
|
+
* Abstraction for type-assisting event targets.
|
|
8
|
+
*
|
|
9
|
+
* @internal
|
|
10
|
+
*/
|
|
11
|
+
class Emitter extends EventTarget {
|
|
12
|
+
addEventListener(type, listener, options) {
|
|
13
|
+
super.addEventListener(type, listener, options);
|
|
14
|
+
}
|
|
15
|
+
removeEventListener(type, listener, options) {
|
|
16
|
+
super.removeEventListener(type, listener, options);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
exports.Emitter = Emitter;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { AgentErrorMessage } from "./message/agent-error.js";
|
|
2
|
+
import type { AgentMessage } from "./message/agent.js";
|
|
3
|
+
import type { ToolMessage } from "./message/tool.js";
|
|
4
|
+
import type { UserMessage } from "./message/user.js";
|
|
5
|
+
import type { TaskStatus } from "./task.js";
|
|
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);
|
|
18
|
+
}
|
|
19
|
+
export declare class TaskMessageEvent extends CustomEvent<{
|
|
20
|
+
message: AgentMessage | UserMessage;
|
|
21
|
+
}> {
|
|
22
|
+
readonly type = "message";
|
|
23
|
+
constructor(message: AgentMessage | UserMessage);
|
|
24
|
+
isUserMessage(): boolean;
|
|
25
|
+
}
|
|
26
|
+
export declare class TaskUpdateEvent extends CustomEvent<{
|
|
27
|
+
message: ToolMessage;
|
|
28
|
+
}> {
|
|
29
|
+
readonly type = "update";
|
|
30
|
+
constructor(message: ToolMessage);
|
|
31
|
+
}
|
|
32
|
+
export declare class TaskErrorEvent extends CustomEvent<{
|
|
33
|
+
message: AgentErrorMessage;
|
|
34
|
+
}> {
|
|
35
|
+
readonly type = "error";
|
|
36
|
+
constructor(message: AgentErrorMessage);
|
|
37
|
+
}
|
package/script/event.js
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TaskErrorEvent = exports.TaskUpdateEvent = exports.TaskMessageEvent = exports.TaskStatusEvent = exports.TaskStartEvent = void 0;
|
|
4
|
+
class TaskStartEvent extends CustomEvent {
|
|
5
|
+
type = "start";
|
|
6
|
+
constructor(id, status) {
|
|
7
|
+
super("start", { detail: { id, status } });
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
exports.TaskStartEvent = TaskStartEvent;
|
|
11
|
+
class TaskStatusEvent extends CustomEvent {
|
|
12
|
+
type = "status";
|
|
13
|
+
constructor(status) {
|
|
14
|
+
super("status", { detail: { status } });
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
exports.TaskStatusEvent = TaskStatusEvent;
|
|
18
|
+
class TaskMessageEvent extends CustomEvent {
|
|
19
|
+
type = "message";
|
|
20
|
+
constructor(message) {
|
|
21
|
+
super("message", { detail: { message } });
|
|
22
|
+
}
|
|
23
|
+
isUserMessage() {
|
|
24
|
+
return this.detail.message.type === "user-message";
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
exports.TaskMessageEvent = TaskMessageEvent;
|
|
28
|
+
class TaskUpdateEvent extends CustomEvent {
|
|
29
|
+
type = "update";
|
|
30
|
+
constructor(message) {
|
|
31
|
+
super("update", { detail: { message } });
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
exports.TaskUpdateEvent = TaskUpdateEvent;
|
|
35
|
+
class TaskErrorEvent extends CustomEvent {
|
|
36
|
+
type = "error";
|
|
37
|
+
constructor(message) {
|
|
38
|
+
super("error", { detail: { message } });
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
exports.TaskErrorEvent = TaskErrorEvent;
|
package/script/key.d.ts
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import type { Region } from "./mod.js";
|
|
2
|
+
type CreateKeyOptions = {
|
|
3
|
+
key: string;
|
|
4
|
+
region: Region;
|
|
5
|
+
project: string;
|
|
6
|
+
agentId?: string;
|
|
7
|
+
taskPrefix?: string;
|
|
8
|
+
};
|
|
9
|
+
type GenerateEmbedKeyOptions = Omit<CreateKeyOptions, "key" | "taskPrefix">;
|
|
10
|
+
/**
|
|
11
|
+
* Key is used to authenticate requests for the {@link Client}. A Key can be
|
|
12
|
+
* either a _full_ key or an _embed_ key.
|
|
13
|
+
*
|
|
14
|
+
* A full key has access to SDK features. An embed key is scoped to a specific
|
|
15
|
+
* agent and is only used to create and interact with tasks for that agent.
|
|
16
|
+
*
|
|
17
|
+
* @see {@link Key.generateEmbedKey} to generate an embed key for a specific agent.
|
|
18
|
+
*
|
|
19
|
+
* @class Key
|
|
20
|
+
*/
|
|
21
|
+
export declare class Key {
|
|
22
|
+
#private;
|
|
23
|
+
/**
|
|
24
|
+
* Generates an embed key for the specified agent. The embed key can then be
|
|
25
|
+
* used to create a {@link Client} instance that can create and interact with
|
|
26
|
+
* tasks for that agent.
|
|
27
|
+
*
|
|
28
|
+
* @throws {Error} if the request to generate an embed key fails.
|
|
29
|
+
*
|
|
30
|
+
* @param {GenerateEmbedKeyOptions} options The generation options.
|
|
31
|
+
*
|
|
32
|
+
* @returns {Promise<Key>}
|
|
33
|
+
*/
|
|
34
|
+
static generateEmbedKey({ region, project, agentId, }: GenerateEmbedKeyOptions): Promise<Key>;
|
|
35
|
+
/**
|
|
36
|
+
* The region the key is scoped to.
|
|
37
|
+
*
|
|
38
|
+
* @property {string} region
|
|
39
|
+
*/
|
|
40
|
+
readonly region: Region;
|
|
41
|
+
/**
|
|
42
|
+
* The project the key is scoped to.
|
|
43
|
+
*
|
|
44
|
+
* @property {string} project
|
|
45
|
+
*/
|
|
46
|
+
readonly project: string;
|
|
47
|
+
/**
|
|
48
|
+
* The agent ID the embed key is scoped to. This is `undefined` for full
|
|
49
|
+
* keys.
|
|
50
|
+
*
|
|
51
|
+
* @property {string | undefined} agentId
|
|
52
|
+
*/
|
|
53
|
+
readonly agentId: string | undefined;
|
|
54
|
+
/**
|
|
55
|
+
* The task prefix used to namespace tasks created with the embed key. This
|
|
56
|
+
* is `undefined` for full keys.
|
|
57
|
+
*
|
|
58
|
+
* @property {string | undefined} taskPrefix
|
|
59
|
+
*/
|
|
60
|
+
readonly taskPrefix: string | undefined;
|
|
61
|
+
/**
|
|
62
|
+
* Creates a new {@link Key} instance with the provided options.
|
|
63
|
+
*
|
|
64
|
+
* @param {CreateKeyOptions} options
|
|
65
|
+
*/
|
|
66
|
+
constructor({ key, region, project, agentId, taskPrefix }: CreateKeyOptions);
|
|
67
|
+
/**
|
|
68
|
+
* Returns whether the key is an embed key.
|
|
69
|
+
*
|
|
70
|
+
* @returns {boolean}
|
|
71
|
+
*/
|
|
72
|
+
isEmbed(): boolean;
|
|
73
|
+
/**
|
|
74
|
+
* Returns the headers required for authenticating requests with this key.
|
|
75
|
+
*
|
|
76
|
+
* @returns {HeadersInit}
|
|
77
|
+
*/
|
|
78
|
+
fetchHeaders(): HeadersInit;
|
|
79
|
+
/**
|
|
80
|
+
* Returns a JSON representation of the key.
|
|
81
|
+
*
|
|
82
|
+
* @returns {CreateKeyOptions}
|
|
83
|
+
*/
|
|
84
|
+
toJSON(): CreateKeyOptions;
|
|
85
|
+
}
|
|
86
|
+
export {};
|
package/script/key.js
ADDED
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Key = void 0;
|
|
4
|
+
const region_js_1 = require("./region.js");
|
|
5
|
+
const utils_js_1 = require("./utils.js");
|
|
6
|
+
/**
|
|
7
|
+
* Key is used to authenticate requests for the {@link Client}. A Key can be
|
|
8
|
+
* either a _full_ key or an _embed_ key.
|
|
9
|
+
*
|
|
10
|
+
* A full key has access to SDK features. An embed key is scoped to a specific
|
|
11
|
+
* agent and is only used to create and interact with tasks for that agent.
|
|
12
|
+
*
|
|
13
|
+
* @see {@link Key.generateEmbedKey} to generate an embed key for a specific agent.
|
|
14
|
+
*
|
|
15
|
+
* @class Key
|
|
16
|
+
*/
|
|
17
|
+
class Key {
|
|
18
|
+
/**
|
|
19
|
+
* Generates an embed key for the specified agent. The embed key can then be
|
|
20
|
+
* used to create a {@link Client} instance that can create and interact with
|
|
21
|
+
* tasks for that agent.
|
|
22
|
+
*
|
|
23
|
+
* @throws {Error} if the request to generate an embed key fails.
|
|
24
|
+
*
|
|
25
|
+
* @param {GenerateEmbedKeyOptions} options The generation options.
|
|
26
|
+
*
|
|
27
|
+
* @returns {Promise<Key>}
|
|
28
|
+
*/
|
|
29
|
+
static async generateEmbedKey({ region, project, agentId, }) {
|
|
30
|
+
const embedKeyURL = new URL((0, utils_js_1.cleanPath)("/agents/get_embed_key"), (0, region_js_1.regionBaseURL)(region));
|
|
31
|
+
const response = await fetch(embedKeyURL, {
|
|
32
|
+
method: "POST",
|
|
33
|
+
body: JSON.stringify({ agent_id: agentId, project }),
|
|
34
|
+
});
|
|
35
|
+
if (!response.ok) {
|
|
36
|
+
throw new Error("failed to fetch embed key", { cause: response });
|
|
37
|
+
}
|
|
38
|
+
const { embed_key: embedKey, conversation_prefix: taskPrefix } = await response.json();
|
|
39
|
+
return new Key({
|
|
40
|
+
key: embedKey,
|
|
41
|
+
region,
|
|
42
|
+
project,
|
|
43
|
+
agentId,
|
|
44
|
+
taskPrefix,
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* The region the key is scoped to.
|
|
49
|
+
*
|
|
50
|
+
* @property {string} region
|
|
51
|
+
*/
|
|
52
|
+
region;
|
|
53
|
+
/**
|
|
54
|
+
* The project the key is scoped to.
|
|
55
|
+
*
|
|
56
|
+
* @property {string} project
|
|
57
|
+
*/
|
|
58
|
+
project;
|
|
59
|
+
/**
|
|
60
|
+
* The API key used for authentication.
|
|
61
|
+
*
|
|
62
|
+
* @private
|
|
63
|
+
* @property {string} key
|
|
64
|
+
*/
|
|
65
|
+
#key;
|
|
66
|
+
/**
|
|
67
|
+
* The agent ID the embed key is scoped to. This is `undefined` for full
|
|
68
|
+
* keys.
|
|
69
|
+
*
|
|
70
|
+
* @property {string | undefined} agentId
|
|
71
|
+
*/
|
|
72
|
+
agentId;
|
|
73
|
+
/**
|
|
74
|
+
* The task prefix used to namespace tasks created with the embed key. This
|
|
75
|
+
* is `undefined` for full keys.
|
|
76
|
+
*
|
|
77
|
+
* @property {string | undefined} taskPrefix
|
|
78
|
+
*/
|
|
79
|
+
taskPrefix;
|
|
80
|
+
/**
|
|
81
|
+
* Creates a new {@link Key} instance with the provided options.
|
|
82
|
+
*
|
|
83
|
+
* @param {CreateKeyOptions} options
|
|
84
|
+
*/
|
|
85
|
+
constructor({ key, region, project, agentId, taskPrefix }) {
|
|
86
|
+
this.#key = key;
|
|
87
|
+
this.region = region;
|
|
88
|
+
this.project = project;
|
|
89
|
+
this.agentId = agentId;
|
|
90
|
+
this.taskPrefix = taskPrefix;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Returns whether the key is an embed key.
|
|
94
|
+
*
|
|
95
|
+
* @returns {boolean}
|
|
96
|
+
*/
|
|
97
|
+
isEmbed() {
|
|
98
|
+
return (this.agentId !== undefined && this.taskPrefix !== undefined);
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Returns the headers required for authenticating requests with this key.
|
|
102
|
+
*
|
|
103
|
+
* @returns {HeadersInit}
|
|
104
|
+
*/
|
|
105
|
+
fetchHeaders() {
|
|
106
|
+
return {
|
|
107
|
+
Authorization: `${this.project}:${this.#key}`,
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Returns a JSON representation of the key.
|
|
112
|
+
*
|
|
113
|
+
* @returns {CreateKeyOptions}
|
|
114
|
+
*/
|
|
115
|
+
toJSON() {
|
|
116
|
+
return {
|
|
117
|
+
key: this.#key,
|
|
118
|
+
region: this.region,
|
|
119
|
+
project: this.project,
|
|
120
|
+
agentId: this.agentId,
|
|
121
|
+
taskPrefix: this.taskPrefix,
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
exports.Key = Key;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AgentErrorMessage = void 0;
|
|
4
|
+
const task_js_1 = require("./task.js");
|
|
5
|
+
class AgentErrorMessage extends task_js_1.TaskMessage {
|
|
6
|
+
}
|
|
7
|
+
exports.AgentErrorMessage = AgentErrorMessage;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AgentMessage = void 0;
|
|
4
|
+
const task_js_1 = require("./task.js");
|
|
5
|
+
class AgentMessage extends task_js_1.TaskMessage {
|
|
6
|
+
get text() {
|
|
7
|
+
return this.message.content.text;
|
|
8
|
+
}
|
|
9
|
+
get agentId() {
|
|
10
|
+
return "";
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
exports.AgentMessage = AgentMessage;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { AgentMessage } from "./agent.js";
|
|
2
|
+
import type { AgentErrorMessage } from "./agent-error.js";
|
|
3
|
+
import type { ToolMessage } from "./tool.js";
|
|
4
|
+
import type { UserMessage } from "./user.js";
|
|
5
|
+
export type AnyTaskMessage = AgentMessage | AgentErrorMessage | ToolMessage | UserMessage;
|
|
6
|
+
interface MessageContent {
|
|
7
|
+
type: AnyTaskMessage["type"];
|
|
8
|
+
}
|
|
9
|
+
export interface TaskMessageData<C extends MessageContent = MessageContent> {
|
|
10
|
+
item_id: string;
|
|
11
|
+
insert_date_: string;
|
|
12
|
+
content: C;
|
|
13
|
+
}
|
|
14
|
+
export declare abstract class TaskMessage<C extends MessageContent = MessageContent> {
|
|
15
|
+
protected readonly message: TaskMessageData<C>;
|
|
16
|
+
constructor(message: TaskMessageData<C>);
|
|
17
|
+
/**
|
|
18
|
+
* The task's message type.
|
|
19
|
+
*
|
|
20
|
+
* @property {"agent-error" | "agent-message" | "tool-run" | "user-message"}
|
|
21
|
+
*/
|
|
22
|
+
get type(): C["type"];
|
|
23
|
+
/**
|
|
24
|
+
* The task message ID. Used for referencing the message.
|
|
25
|
+
*
|
|
26
|
+
* @property {string}
|
|
27
|
+
*/
|
|
28
|
+
get id(): string;
|
|
29
|
+
/**
|
|
30
|
+
* The time the task was created.
|
|
31
|
+
*
|
|
32
|
+
* @property {Date}
|
|
33
|
+
*/
|
|
34
|
+
get createdAt(): Date;
|
|
35
|
+
/**
|
|
36
|
+
* Returns if the message was sent from the agent.
|
|
37
|
+
*
|
|
38
|
+
* @returns {boolean}
|
|
39
|
+
*/
|
|
40
|
+
isAgent(): boolean;
|
|
41
|
+
}
|
|
42
|
+
export {};
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TaskMessage = void 0;
|
|
4
|
+
class TaskMessage {
|
|
5
|
+
message;
|
|
6
|
+
constructor(message) {
|
|
7
|
+
this.message = message;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* The task's message type.
|
|
11
|
+
*
|
|
12
|
+
* @property {"agent-error" | "agent-message" | "tool-run" | "user-message"}
|
|
13
|
+
*/
|
|
14
|
+
get type() {
|
|
15
|
+
return this.message.content.type;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* The task message ID. Used for referencing the message.
|
|
19
|
+
*
|
|
20
|
+
* @property {string}
|
|
21
|
+
*/
|
|
22
|
+
get id() {
|
|
23
|
+
return this.message.item_id;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* The time the task was created.
|
|
27
|
+
*
|
|
28
|
+
* @property {Date}
|
|
29
|
+
*/
|
|
30
|
+
get createdAt() {
|
|
31
|
+
return new Date(this.message.insert_date_);
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Returns if the message was sent from the agent.
|
|
35
|
+
*
|
|
36
|
+
* @returns {boolean}
|
|
37
|
+
*/
|
|
38
|
+
isAgent() {
|
|
39
|
+
return this.type === "agent-message";
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
exports.TaskMessage = TaskMessage;
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import type { Region } from "../region.js";
|
|
2
|
+
import { TaskMessage } from "./task.js";
|
|
3
|
+
export interface ToolMessageContent {
|
|
4
|
+
type: "tool-run";
|
|
5
|
+
tool_run_state: "cancelled" | "error" | "finished" | "pending" | "running";
|
|
6
|
+
output: Record<string, unknown> & {
|
|
7
|
+
_agent_conversation_details?: {
|
|
8
|
+
agent_id: string;
|
|
9
|
+
conversation_id: string;
|
|
10
|
+
};
|
|
11
|
+
};
|
|
12
|
+
params: {
|
|
13
|
+
resolved?: Record<string, unknown>;
|
|
14
|
+
valid: boolean;
|
|
15
|
+
};
|
|
16
|
+
errors: {
|
|
17
|
+
body: string;
|
|
18
|
+
raw: string;
|
|
19
|
+
step_name: string;
|
|
20
|
+
}[];
|
|
21
|
+
tool_config: {
|
|
22
|
+
id: string;
|
|
23
|
+
type: "tool" | "agent";
|
|
24
|
+
region: Region;
|
|
25
|
+
project: string;
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
export declare class ToolMessage extends TaskMessage<ToolMessageContent> {
|
|
29
|
+
/**
|
|
30
|
+
* The tool status for _this_ message.
|
|
31
|
+
*
|
|
32
|
+
* @property {"cancelled" | "error" | "finished" | "pending" | "running"}
|
|
33
|
+
*/
|
|
34
|
+
get status(): "cancelled" | "error" | "finished" | "pending" | "running";
|
|
35
|
+
/**
|
|
36
|
+
* Parameters used to call the tool.
|
|
37
|
+
*
|
|
38
|
+
* @property {object}
|
|
39
|
+
*/
|
|
40
|
+
get params(): Record<string, unknown> | null;
|
|
41
|
+
/**
|
|
42
|
+
* The tool's output. Will be `null` if the status is **not** "finished".
|
|
43
|
+
*
|
|
44
|
+
* @property {object|null}
|
|
45
|
+
*/
|
|
46
|
+
get output(): Record<string, unknown> | null;
|
|
47
|
+
/**
|
|
48
|
+
* Tool errors.
|
|
49
|
+
*
|
|
50
|
+
* @property {array}
|
|
51
|
+
* @see {@link ToolMessage#hasErrors}
|
|
52
|
+
*/
|
|
53
|
+
get errors(): {
|
|
54
|
+
stepName: string;
|
|
55
|
+
message: string;
|
|
56
|
+
}[];
|
|
57
|
+
/**
|
|
58
|
+
* The tool's ID.
|
|
59
|
+
*
|
|
60
|
+
* @property {string}
|
|
61
|
+
*/
|
|
62
|
+
get toolId(): string;
|
|
63
|
+
/**
|
|
64
|
+
* The agent's ID, if a sub-agent.
|
|
65
|
+
*
|
|
66
|
+
* @property {string}
|
|
67
|
+
* @see {@link ToolMessage.isSubAgent}
|
|
68
|
+
*/
|
|
69
|
+
get agentId(): string | null;
|
|
70
|
+
/**
|
|
71
|
+
* The tool/agent's corresponding project.
|
|
72
|
+
*
|
|
73
|
+
* @property {string}
|
|
74
|
+
*/
|
|
75
|
+
get project(): string;
|
|
76
|
+
/**
|
|
77
|
+
* The tool/agent's corresponding region.
|
|
78
|
+
*
|
|
79
|
+
* @property {Region}
|
|
80
|
+
*/
|
|
81
|
+
get region(): Region;
|
|
82
|
+
/**
|
|
83
|
+
* The task ID the sub-agent ran. Will be `null` if the tool message is not
|
|
84
|
+
* a sub-agent.
|
|
85
|
+
*
|
|
86
|
+
* @property {string}
|
|
87
|
+
* @see {@link ToolMessage.isSubAgent}
|
|
88
|
+
*/
|
|
89
|
+
get subAgentTaskId(): string | null;
|
|
90
|
+
/**
|
|
91
|
+
* Checks if the tool message came from a sub-agent.
|
|
92
|
+
*
|
|
93
|
+
* @returns {boolean}
|
|
94
|
+
*/
|
|
95
|
+
isSubAgent(): boolean;
|
|
96
|
+
/**
|
|
97
|
+
* Checks if the tool call parameters where valid.
|
|
98
|
+
*
|
|
99
|
+
* @returns {boolean}
|
|
100
|
+
*/
|
|
101
|
+
areParamsValid(): boolean;
|
|
102
|
+
/**
|
|
103
|
+
* Returns if the tool message has any errors.
|
|
104
|
+
*
|
|
105
|
+
* @returns {boolean}
|
|
106
|
+
*/
|
|
107
|
+
hasErrors(): boolean;
|
|
108
|
+
}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ToolMessage = void 0;
|
|
4
|
+
const task_js_1 = require("./task.js");
|
|
5
|
+
class ToolMessage extends task_js_1.TaskMessage {
|
|
6
|
+
/**
|
|
7
|
+
* The tool status for _this_ message.
|
|
8
|
+
*
|
|
9
|
+
* @property {"cancelled" | "error" | "finished" | "pending" | "running"}
|
|
10
|
+
*/
|
|
11
|
+
get status() {
|
|
12
|
+
return this.message.content.tool_run_state;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Parameters used to call the tool.
|
|
16
|
+
*
|
|
17
|
+
* @property {object}
|
|
18
|
+
*/
|
|
19
|
+
get params() {
|
|
20
|
+
return this.message.content.params.resolved ?? null;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* The tool's output. Will be `null` if the status is **not** "finished".
|
|
24
|
+
*
|
|
25
|
+
* @property {object|null}
|
|
26
|
+
*/
|
|
27
|
+
get output() {
|
|
28
|
+
return this.status === "finished" ? this.message.content.output : null;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Tool errors.
|
|
32
|
+
*
|
|
33
|
+
* @property {array}
|
|
34
|
+
* @see {@link ToolMessage#hasErrors}
|
|
35
|
+
*/
|
|
36
|
+
get errors() {
|
|
37
|
+
return this.message.content.errors.map((e) => ({
|
|
38
|
+
stepName: e.step_name,
|
|
39
|
+
message: e.body,
|
|
40
|
+
}));
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* The tool's ID.
|
|
44
|
+
*
|
|
45
|
+
* @property {string}
|
|
46
|
+
*/
|
|
47
|
+
get toolId() {
|
|
48
|
+
return this.message.content.tool_config.id;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* The agent's ID, if a sub-agent.
|
|
52
|
+
*
|
|
53
|
+
* @property {string}
|
|
54
|
+
* @see {@link ToolMessage.isSubAgent}
|
|
55
|
+
*/
|
|
56
|
+
get agentId() {
|
|
57
|
+
return this.isSubAgent()
|
|
58
|
+
? this.message.content.output._agent_conversation_details?.agent_id
|
|
59
|
+
: null;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* The tool/agent's corresponding project.
|
|
63
|
+
*
|
|
64
|
+
* @property {string}
|
|
65
|
+
*/
|
|
66
|
+
get project() {
|
|
67
|
+
return this.message.content.tool_config.project;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* The tool/agent's corresponding region.
|
|
71
|
+
*
|
|
72
|
+
* @property {Region}
|
|
73
|
+
*/
|
|
74
|
+
get region() {
|
|
75
|
+
return this.message.content.tool_config.region;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* The task ID the sub-agent ran. Will be `null` if the tool message is not
|
|
79
|
+
* a sub-agent.
|
|
80
|
+
*
|
|
81
|
+
* @property {string}
|
|
82
|
+
* @see {@link ToolMessage.isSubAgent}
|
|
83
|
+
*/
|
|
84
|
+
get subAgentTaskId() {
|
|
85
|
+
return this.message.content.output._agent_conversation_details
|
|
86
|
+
?.conversation_id ?? null;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Checks if the tool message came from a sub-agent.
|
|
90
|
+
*
|
|
91
|
+
* @returns {boolean}
|
|
92
|
+
*/
|
|
93
|
+
isSubAgent() {
|
|
94
|
+
return this.message.content.tool_config.type === "agent";
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Checks if the tool call parameters where valid.
|
|
98
|
+
*
|
|
99
|
+
* @returns {boolean}
|
|
100
|
+
*/
|
|
101
|
+
areParamsValid() {
|
|
102
|
+
return this.message.content.params.valid;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Returns if the tool message has any errors.
|
|
106
|
+
*
|
|
107
|
+
* @returns {boolean}
|
|
108
|
+
*/
|
|
109
|
+
hasErrors() {
|
|
110
|
+
return this.message.content.errors.length > 0;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
exports.ToolMessage = ToolMessage;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { TaskMessage } from "./task.js";
|
|
2
|
+
export interface UserMessageContent {
|
|
3
|
+
type: "user-message";
|
|
4
|
+
text: string;
|
|
5
|
+
is_trigger_message: boolean;
|
|
6
|
+
}
|
|
7
|
+
export declare class UserMessage extends TaskMessage<UserMessageContent> {
|
|
8
|
+
/**
|
|
9
|
+
* The message as text sent.
|
|
10
|
+
*
|
|
11
|
+
* @property {string} text
|
|
12
|
+
*/
|
|
13
|
+
get text(): string;
|
|
14
|
+
/**
|
|
15
|
+
* Returns if the message triggered a subject.
|
|
16
|
+
*
|
|
17
|
+
* @returns {boolean}
|
|
18
|
+
*/
|
|
19
|
+
isTrigger(): boolean;
|
|
20
|
+
}
|