@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
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Task = exports.resetBackoffDuration = void 0;
|
|
4
|
+
const emitter_js_1 = require("../emitter.js");
|
|
5
|
+
const utils_js_1 = require("../utils.js");
|
|
6
|
+
const event_js_1 = require("../event.js");
|
|
7
|
+
exports.resetBackoffDuration = Symbol("resetBackoffDuration");
|
|
8
|
+
const backoffStartingDuration = 1_000;
|
|
9
|
+
const backoffMaxDuration = 60_000;
|
|
10
|
+
class Task extends emitter_js_1.Emitter {
|
|
11
|
+
subscribed = null;
|
|
12
|
+
backoff = null;
|
|
13
|
+
backoffDuration = 0;
|
|
14
|
+
strategy;
|
|
15
|
+
#metadata;
|
|
16
|
+
constructor(metadata, strategy) {
|
|
17
|
+
super();
|
|
18
|
+
this.strategy = strategy;
|
|
19
|
+
this.#metadata = metadata;
|
|
20
|
+
}
|
|
21
|
+
get subject() {
|
|
22
|
+
return this.strategy.subject;
|
|
23
|
+
}
|
|
24
|
+
get id() {
|
|
25
|
+
return this.#metadata.id;
|
|
26
|
+
}
|
|
27
|
+
get region() {
|
|
28
|
+
return this.#metadata.region;
|
|
29
|
+
}
|
|
30
|
+
get project() {
|
|
31
|
+
return this.#metadata.project;
|
|
32
|
+
}
|
|
33
|
+
get name() {
|
|
34
|
+
return this.#metadata.name;
|
|
35
|
+
}
|
|
36
|
+
get status() {
|
|
37
|
+
return this.#metadata.status;
|
|
38
|
+
}
|
|
39
|
+
get createdAt() {
|
|
40
|
+
return this.#metadata.createdAt;
|
|
41
|
+
}
|
|
42
|
+
get updatedAt() {
|
|
43
|
+
return this.#metadata.updatedAt;
|
|
44
|
+
}
|
|
45
|
+
getMessages(options) {
|
|
46
|
+
return this.strategy.getMessages(options);
|
|
47
|
+
}
|
|
48
|
+
isRunning() {
|
|
49
|
+
switch (this.status) {
|
|
50
|
+
case "queued":
|
|
51
|
+
case "running":
|
|
52
|
+
return true;
|
|
53
|
+
default:
|
|
54
|
+
return false;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
#subscribe() {
|
|
58
|
+
if (this.subscribed) {
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
const subscribed = new AbortController();
|
|
62
|
+
this.subscribed = subscribed; // subscribed ref
|
|
63
|
+
const isSubscribed = () => !subscribed.signal.aborted;
|
|
64
|
+
this.backoffDuration = backoffStartingDuration;
|
|
65
|
+
const cursor = new Date(0);
|
|
66
|
+
const emitted = new Set();
|
|
67
|
+
const pending = new Map();
|
|
68
|
+
void (async () => {
|
|
69
|
+
while (isSubscribed()) {
|
|
70
|
+
try {
|
|
71
|
+
const [metadata, messages] = await Promise.all([
|
|
72
|
+
this.strategy.getMetadata(),
|
|
73
|
+
this.strategy.getMessages({ after: cursor }),
|
|
74
|
+
]);
|
|
75
|
+
if (!isSubscribed()) {
|
|
76
|
+
break;
|
|
77
|
+
}
|
|
78
|
+
let hasChanges = false;
|
|
79
|
+
if (metadata.updatedAt > this.updatedAt) {
|
|
80
|
+
this.dispatchEvent(new event_js_1.TaskUpdateEvent());
|
|
81
|
+
hasChanges = true;
|
|
82
|
+
}
|
|
83
|
+
this.#metadata = metadata;
|
|
84
|
+
if (messages.length) {
|
|
85
|
+
for (const message of messages) {
|
|
86
|
+
if (emitted.has(message.id)) {
|
|
87
|
+
continue;
|
|
88
|
+
}
|
|
89
|
+
switch (message.type) {
|
|
90
|
+
case "agent-error":
|
|
91
|
+
emitted.add(message.id);
|
|
92
|
+
this.dispatchEvent(new event_js_1.TaskErrorEvent(message));
|
|
93
|
+
break;
|
|
94
|
+
case "tool-run": {
|
|
95
|
+
const { status } = message;
|
|
96
|
+
if (pending.get(message.id)?.status == status) {
|
|
97
|
+
// no change to the tool status
|
|
98
|
+
continue;
|
|
99
|
+
}
|
|
100
|
+
if (["pending", "running"].includes(status)) {
|
|
101
|
+
pending.set(message.id, message);
|
|
102
|
+
}
|
|
103
|
+
else {
|
|
104
|
+
emitted.add(message.id);
|
|
105
|
+
pending.delete(message.id);
|
|
106
|
+
}
|
|
107
|
+
this.dispatchEvent(new event_js_1.TaskMessageEvent(message));
|
|
108
|
+
break;
|
|
109
|
+
}
|
|
110
|
+
case "agent-message":
|
|
111
|
+
case "user-message":
|
|
112
|
+
hasChanges = true;
|
|
113
|
+
emitted.add(message.id);
|
|
114
|
+
this.dispatchEvent(new event_js_1.TaskMessageEvent(message));
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
let latest = messages.at(-1).createdAt;
|
|
118
|
+
for (const message of pending.values()) {
|
|
119
|
+
if (latest > message.createdAt) {
|
|
120
|
+
latest = message.createdAt;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
cursor.setTime(latest.getTime());
|
|
124
|
+
}
|
|
125
|
+
if (hasChanges) {
|
|
126
|
+
this.backoffDuration = backoffStartingDuration;
|
|
127
|
+
}
|
|
128
|
+
else if (!this.isRunning()) {
|
|
129
|
+
this.backoffDuration = Math.min(this.backoffDuration * 2, backoffMaxDuration);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
finally {
|
|
133
|
+
if (isSubscribed()) {
|
|
134
|
+
const backoff = new AbortController();
|
|
135
|
+
this.backoff = backoff;
|
|
136
|
+
await Promise.race([
|
|
137
|
+
(0, utils_js_1.delay)(this.backoffDuration),
|
|
138
|
+
(0, utils_js_1.abortPromise)(AbortSignal.any([subscribed.signal, backoff.signal])),
|
|
139
|
+
]);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
})();
|
|
144
|
+
}
|
|
145
|
+
unsubscribe() {
|
|
146
|
+
this.subscribed?.abort();
|
|
147
|
+
this.subscribed = null;
|
|
148
|
+
this.backoff?.abort();
|
|
149
|
+
this.backoff = null;
|
|
150
|
+
this.backoffDuration = 0;
|
|
151
|
+
}
|
|
152
|
+
[exports.resetBackoffDuration]() {
|
|
153
|
+
this.backoffDuration = backoffStartingDuration;
|
|
154
|
+
}
|
|
155
|
+
addEventListener(type, listener, options) {
|
|
156
|
+
this.#subscribe();
|
|
157
|
+
const signal = AbortSignal.any([
|
|
158
|
+
...(options && typeof options === "object" && options.signal
|
|
159
|
+
? [options.signal]
|
|
160
|
+
: []),
|
|
161
|
+
...(this.subscribed ? [this.subscribed.signal] : []),
|
|
162
|
+
]);
|
|
163
|
+
const capture = typeof options === "boolean"
|
|
164
|
+
? options
|
|
165
|
+
: Boolean(options?.capture);
|
|
166
|
+
const addOptions = Object.assign({}, options, { signal, capture });
|
|
167
|
+
super.addEventListener(type, listener, addOptions);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
exports.Task = Task;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { AnyTaskMessage } from "../message/task.js";
|
|
2
|
+
import { Client } from "../client.js";
|
|
3
|
+
import { Task, type TaskMetadata, type TaskStatus, type TaskStrategy } from "./task.js";
|
|
4
|
+
import type { Workforce } from "../workforce.js";
|
|
5
|
+
export declare class WorkforceStrategy implements TaskStrategy<Workforce> {
|
|
6
|
+
static get(id: string, workforce: Workforce, client?: Client): Promise<Task<Workforce>>;
|
|
7
|
+
static convertStatus(): TaskStatus;
|
|
8
|
+
private readonly id;
|
|
9
|
+
private readonly workforce;
|
|
10
|
+
private readonly client;
|
|
11
|
+
private constructor();
|
|
12
|
+
get subject(): Workforce;
|
|
13
|
+
getMessages({ after: _after }: {
|
|
14
|
+
after?: Date;
|
|
15
|
+
}): Promise<AnyTaskMessage[]>;
|
|
16
|
+
getMetadata(): Promise<TaskMetadata>;
|
|
17
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.WorkforceStrategy = void 0;
|
|
4
|
+
const client_js_1 = require("../client.js");
|
|
5
|
+
const task_js_1 = require("./task.js");
|
|
6
|
+
const agent_error_js_1 = require("../message/agent-error.js");
|
|
7
|
+
const agent_js_1 = require("../message/agent.js");
|
|
8
|
+
const tool_js_1 = require("../message/tool.js");
|
|
9
|
+
const user_js_1 = require("../message/user.js");
|
|
10
|
+
const workforce_agent_js_1 = require("../message/workforce-agent.js");
|
|
11
|
+
const workforce_agent_handover_js_1 = require("../message/workforce-agent-handover.js");
|
|
12
|
+
class WorkforceStrategy {
|
|
13
|
+
static async get(id, workforce, client = client_js_1.Client.default()) {
|
|
14
|
+
const subject = new this(id, workforce, client);
|
|
15
|
+
const metadata = await subject.getMetadata();
|
|
16
|
+
return new task_js_1.Task(metadata, subject);
|
|
17
|
+
}
|
|
18
|
+
static convertStatus() {
|
|
19
|
+
return "not-implemented";
|
|
20
|
+
}
|
|
21
|
+
id;
|
|
22
|
+
workforce;
|
|
23
|
+
client;
|
|
24
|
+
constructor(id, workforce, client) {
|
|
25
|
+
this.id = id;
|
|
26
|
+
this.workforce = workforce;
|
|
27
|
+
this.client = client;
|
|
28
|
+
}
|
|
29
|
+
get subject() {
|
|
30
|
+
return this.workforce;
|
|
31
|
+
}
|
|
32
|
+
async getMessages({ after: _after }) {
|
|
33
|
+
const { results } = await this.client.fetch(`/workforce/items/${this.workforce.id}/tasks/${this.id}/messages`, {
|
|
34
|
+
method: "POST",
|
|
35
|
+
body: JSON.stringify({
|
|
36
|
+
page_size: 1_000, // @todo: pagination
|
|
37
|
+
// @todo: cursor "before" :S
|
|
38
|
+
}),
|
|
39
|
+
});
|
|
40
|
+
return results.map((data) => {
|
|
41
|
+
switch (data.content.type) {
|
|
42
|
+
case "agent-error":
|
|
43
|
+
return new agent_error_js_1.AgentErrorMessage(data);
|
|
44
|
+
case "agent-message":
|
|
45
|
+
return new agent_js_1.AgentMessage(data);
|
|
46
|
+
case "tool-run":
|
|
47
|
+
return new tool_js_1.ToolMessage(data);
|
|
48
|
+
case "user-message":
|
|
49
|
+
return new user_js_1.UserMessage(data);
|
|
50
|
+
case "workforce-agent-run":
|
|
51
|
+
return new workforce_agent_js_1.WorkforceAgentMessage(data);
|
|
52
|
+
case "workforce-agent-handover":
|
|
53
|
+
return new workforce_agent_handover_js_1.WorkforceAgentHandoverMessage(data);
|
|
54
|
+
default:
|
|
55
|
+
throw new Error("unknown message response");
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
async getMetadata() {
|
|
60
|
+
const { metadata } = await this.client.fetch(`/workforce/tasks/${this.id}/metadata`);
|
|
61
|
+
return {
|
|
62
|
+
id: this.id,
|
|
63
|
+
region: this.client.region,
|
|
64
|
+
project: this.client.project,
|
|
65
|
+
name: metadata.title,
|
|
66
|
+
status: WorkforceStrategy.convertStatus(), // @todo: not implemented
|
|
67
|
+
createdAt: new Date(metadata.insert_date),
|
|
68
|
+
updatedAt: new Date(metadata.update_date),
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
exports.WorkforceStrategy = WorkforceStrategy;
|
package/script/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/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;
|
package/script/utils.d.ts
CHANGED
|
@@ -2,3 +2,4 @@ export declare function abortPromise(signal: AbortSignal, reject?: boolean): Pro
|
|
|
2
2
|
export declare function delay(timeout: number | (() => number)): Promise<void>;
|
|
3
3
|
export declare function cleanPath(path: string, version?: string): string;
|
|
4
4
|
export declare function randomUUID(): Promise<any>;
|
|
5
|
+
export declare function getFileExtension(filename: string): string;
|
package/script/utils.js
CHANGED
|
@@ -37,6 +37,7 @@ exports.abortPromise = abortPromise;
|
|
|
37
37
|
exports.delay = delay;
|
|
38
38
|
exports.cleanPath = cleanPath;
|
|
39
39
|
exports.randomUUID = randomUUID;
|
|
40
|
+
exports.getFileExtension = getFileExtension;
|
|
40
41
|
function abortPromise(signal, reject) {
|
|
41
42
|
return new Promise((res, rej) => signal.addEventListener("abort", () => reject ? rej() : res()));
|
|
42
43
|
}
|
|
@@ -54,3 +55,7 @@ async function randomUUID() {
|
|
|
54
55
|
const cryptoModule = await Promise.resolve().then(() => __importStar(require("node:crypto")));
|
|
55
56
|
return cryptoModule.randomUUID();
|
|
56
57
|
}
|
|
58
|
+
function getFileExtension(filename) {
|
|
59
|
+
const dot = filename.lastIndexOf(".");
|
|
60
|
+
return dot >= 0 ? filename.slice(dot + 1) : "";
|
|
61
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { Client } from "./client.js";
|
|
2
|
+
import type { Region } from "./region.js";
|
|
3
|
+
import { type Task } from "./task/task.js";
|
|
4
|
+
type WorkforceConfig = {
|
|
5
|
+
id: string;
|
|
6
|
+
workforce_metadata: {
|
|
7
|
+
name: string;
|
|
8
|
+
};
|
|
9
|
+
};
|
|
10
|
+
export declare class Workforce {
|
|
11
|
+
#private;
|
|
12
|
+
static get(id: string, client?: Client): Promise<Workforce>;
|
|
13
|
+
private readonly client;
|
|
14
|
+
constructor(config: WorkforceConfig, client: Client);
|
|
15
|
+
get id(): string;
|
|
16
|
+
get region(): Region;
|
|
17
|
+
get project(): string;
|
|
18
|
+
get name(): string;
|
|
19
|
+
getTask(id: string): Promise<Task<Workforce>>;
|
|
20
|
+
sendMessage(message: string, task?: Task<Workforce>): Promise<Task<Workforce>>;
|
|
21
|
+
}
|
|
22
|
+
export {};
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Workforce = void 0;
|
|
4
|
+
const client_js_1 = require("./client.js");
|
|
5
|
+
const task_js_1 = require("./task/task.js");
|
|
6
|
+
const workforce_strategy_js_1 = require("./task/workforce-strategy.js");
|
|
7
|
+
class Workforce {
|
|
8
|
+
static async get(id, client = client_js_1.Client.default()) {
|
|
9
|
+
const config = await client.fetch(`/workforce/items/${id}`);
|
|
10
|
+
return new Workforce(config, client);
|
|
11
|
+
}
|
|
12
|
+
client;
|
|
13
|
+
#config;
|
|
14
|
+
constructor(config, client) {
|
|
15
|
+
this.#config = config;
|
|
16
|
+
this.client = client;
|
|
17
|
+
}
|
|
18
|
+
get id() {
|
|
19
|
+
return this.#config.id;
|
|
20
|
+
}
|
|
21
|
+
get region() {
|
|
22
|
+
return this.client.region;
|
|
23
|
+
}
|
|
24
|
+
get project() {
|
|
25
|
+
return this.client.project;
|
|
26
|
+
}
|
|
27
|
+
get name() {
|
|
28
|
+
return this.#config.workforce_metadata.name;
|
|
29
|
+
}
|
|
30
|
+
async getTask(id) {
|
|
31
|
+
return await workforce_strategy_js_1.WorkforceStrategy.get(id, this, this.client);
|
|
32
|
+
}
|
|
33
|
+
async sendMessage(message, task) {
|
|
34
|
+
const { workforce_task_id: taskId } = await this.client.fetch("/workforce/trigger", {
|
|
35
|
+
method: "POST",
|
|
36
|
+
body: JSON.stringify({
|
|
37
|
+
workforce_id: this.id,
|
|
38
|
+
workforce_task_id: task?.id,
|
|
39
|
+
trigger: {
|
|
40
|
+
message: {
|
|
41
|
+
role: "user",
|
|
42
|
+
content: message,
|
|
43
|
+
attachments: [],
|
|
44
|
+
},
|
|
45
|
+
},
|
|
46
|
+
}),
|
|
47
|
+
});
|
|
48
|
+
if (task) {
|
|
49
|
+
task[task_js_1.resetBackoffDuration]();
|
|
50
|
+
}
|
|
51
|
+
return task ?? this.getTask(taskId);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
exports.Workforce = Workforce;
|
package/esm/task.d.ts
DELETED
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import { Agent } from "./agent.js";
|
|
2
|
-
import { Client } from "./client.js";
|
|
3
|
-
import { Emitter } from "./emitter.js";
|
|
4
|
-
import { AgentMessage } from "./message/agent.js";
|
|
5
|
-
import type { AnyTaskMessage } from "./message/task.js";
|
|
6
|
-
import { ToolMessage } from "./message/tool.js";
|
|
7
|
-
import { UserMessage } from "./message/user.js";
|
|
8
|
-
export type TaskState = "idle" | "starting-up" | "running" | "pending-approval" | "waiting-for-capacity" | "cancelled" | "timed-out" | "escalated" | "unrecoverable" | "paused" | "completed" | "errored-pending-approval" | "queued-for-approval" | "queued-for-rerun";
|
|
9
|
-
export type TaskStatus = "not-started" | "idle" | "queued" | "running" | "action" | "complete" | "error";
|
|
10
|
-
type TaskMetadata = {
|
|
11
|
-
knowledge_set: string;
|
|
12
|
-
insert_date: string;
|
|
13
|
-
update_date: string;
|
|
14
|
-
conversation: {
|
|
15
|
-
created_by_user_id: string;
|
|
16
|
-
state: TaskState;
|
|
17
|
-
title: string;
|
|
18
|
-
};
|
|
19
|
-
};
|
|
20
|
-
type TaskEventMap = {
|
|
21
|
-
start: {
|
|
22
|
-
status: TaskStatus;
|
|
23
|
-
};
|
|
24
|
-
status: {
|
|
25
|
-
status: TaskStatus;
|
|
26
|
-
};
|
|
27
|
-
message: {
|
|
28
|
-
message: AgentMessage | UserMessage;
|
|
29
|
-
};
|
|
30
|
-
update: {
|
|
31
|
-
message: ToolMessage;
|
|
32
|
-
};
|
|
33
|
-
};
|
|
34
|
-
export declare const resetSubscribeBackoff: unique symbol;
|
|
35
|
-
export declare class Task extends Emitter<TaskEventMap> {
|
|
36
|
-
#private;
|
|
37
|
-
static get(id: string, agentOrAgentId: Agent | string, client?: Client): Promise<Task>;
|
|
38
|
-
readonly agent: Agent;
|
|
39
|
-
protected readonly client: Client;
|
|
40
|
-
protected constructor(metadata: TaskMetadata, agent: Agent, client?: Client);
|
|
41
|
-
get id(): string;
|
|
42
|
-
get title(): string;
|
|
43
|
-
get status(): TaskStatus;
|
|
44
|
-
isRunning(): boolean;
|
|
45
|
-
getMessages({ from }?: {
|
|
46
|
-
from?: Date;
|
|
47
|
-
}): Promise<AnyTaskMessage[]>;
|
|
48
|
-
protected refresh(): Promise<void>;
|
|
49
|
-
[resetSubscribeBackoff](): void;
|
|
50
|
-
subscribe(): void;
|
|
51
|
-
protected isSubscribed(): boolean;
|
|
52
|
-
unsubscribe(): void;
|
|
53
|
-
addEventListener<K extends keyof TaskEventMap>(type: Extract<K, string>, listener: ((event: CustomEvent<TaskEventMap[K]>) => void) | {
|
|
54
|
-
handleEvent: (event: CustomEvent<TaskEventMap[K]>) => void;
|
|
55
|
-
} | null, options?: boolean | AddEventListenerOptions): void;
|
|
56
|
-
}
|
|
57
|
-
export {};
|