@relevanceai/sdk 2.0.1 → 3.0.0-alpha.0

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.
Files changed (60) hide show
  1. package/esm/agent-task.d.ts +61 -0
  2. package/esm/agent-task.js +112 -0
  3. package/esm/agent.d.ts +17 -0
  4. package/esm/agent.js +52 -0
  5. package/esm/client.d.ts +36 -0
  6. package/esm/client.js +69 -0
  7. package/esm/events.d.ts +40 -0
  8. package/esm/events.js +39 -0
  9. package/esm/key.d.ts +86 -0
  10. package/esm/key.js +121 -0
  11. package/esm/message.d.ts +18 -0
  12. package/esm/message.js +18 -0
  13. package/esm/mod.d.ts +7 -0
  14. package/esm/mod.js +4 -0
  15. package/esm/package.json +3 -0
  16. package/esm/region.d.ts +5 -0
  17. package/esm/region.js +6 -0
  18. package/esm/task.d.ts +25 -0
  19. package/esm/task.js +96 -0
  20. package/esm/utils.d.ts +8 -0
  21. package/esm/utils.js +29 -0
  22. package/package.json +11 -36
  23. package/LICENSE +0 -21
  24. package/README.md +0 -121
  25. package/dist-cjs/generated/VecDBApi.js +0 -1682
  26. package/dist-cjs/generated/_VecDBApiSchemaTypes.js +0 -3
  27. package/dist-cjs/generated/index.js +0 -17
  28. package/dist-cjs/index.js +0 -18
  29. package/dist-cjs/services/discovery/Dataset.js +0 -126
  30. package/dist-cjs/services/discovery/index.js +0 -159
  31. package/dist-cjs/services/index.js +0 -18
  32. package/dist-cjs/services/vecdb/Dataset.js +0 -137
  33. package/dist-cjs/services/vecdb/index.js +0 -137
  34. package/dist-cjs/shared/BaseClient.js +0 -35
  35. package/dist-cjs/shared/generate.js +0 -90
  36. package/dist-cjs/shared/serviceConfigs.js +0 -10
  37. package/dist-es/generated/VecDBApi.js +0 -2579
  38. package/dist-es/generated/_VecDBApiSchemaTypes.js +0 -2
  39. package/dist-es/generated/index.js +0 -1
  40. package/dist-es/index.js +0 -2
  41. package/dist-es/services/discovery/Dataset.js +0 -126
  42. package/dist-es/services/discovery/index.js +0 -159
  43. package/dist-es/services/index.js +0 -2
  44. package/dist-es/services/vecdb/Dataset.js +0 -356
  45. package/dist-es/services/vecdb/index.js +0 -184
  46. package/dist-es/shared/BaseClient.js +0 -82
  47. package/dist-es/shared/generate.js +0 -224
  48. package/dist-es/shared/serviceConfigs.js +0 -7
  49. package/dist-types/generated/VecDBApi.d.ts +0 -632
  50. package/dist-types/generated/_VecDBApiSchemaTypes.d.ts +0 -22299
  51. package/dist-types/generated/index.d.ts +0 -1
  52. package/dist-types/index.d.ts +0 -2
  53. package/dist-types/services/discovery/Dataset.d.ts +0 -0
  54. package/dist-types/services/discovery/index.d.ts +0 -0
  55. package/dist-types/services/index.d.ts +0 -1
  56. package/dist-types/services/vecdb/Dataset.d.ts +0 -52
  57. package/dist-types/services/vecdb/index.d.ts +0 -44
  58. package/dist-types/shared/BaseClient.d.ts +0 -28
  59. package/dist-types/shared/generate.d.ts +0 -1
  60. package/dist-types/shared/serviceConfigs.d.ts +0 -8
@@ -0,0 +1,61 @@
1
+ import type { Agent } from "./agent.js";
2
+ import { TaskMessage } from "./message.js";
3
+ import { Task, type TaskStatus } from "./task.js";
4
+ type AgentTaskEvents = {
5
+ start: {
6
+ status: TaskStatus;
7
+ };
8
+ status: {
9
+ status: TaskStatus;
10
+ };
11
+ message: {
12
+ message: TaskMessage<"agent-message" | "user-message">;
13
+ };
14
+ update: {
15
+ message: TaskMessage<"tool-run">;
16
+ };
17
+ };
18
+ export type AgentTaskState = "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";
19
+ /**
20
+ * AgentTask represents a conversation task with an AI agent. It extends the
21
+ * base Task class with agent-specific functionality for sending messages and
22
+ * retrieving conversation history.
23
+ *
24
+ * @see {@link Task} for the base task functionality.
25
+ * @see {@link Agent} for the agent this task is associated with.
26
+ *
27
+ * @class AgentTask
28
+ * @extends Task<Agent, AgentTaskEvents>
29
+ */
30
+ export declare class AgentTask extends Task<Agent, AgentTaskEvents> {
31
+ /**
32
+ * Sends a message to the agent. This method triggers the agent with the
33
+ * message and updates the task ID if this is the first message.
34
+ *
35
+ * Note: This method is asynchronous but doesn't return a promise. Use event
36
+ * listeners to track the response.
37
+ *
38
+ * @param {string} message
39
+ */
40
+ sendMessage(message: string): void;
41
+ /**
42
+ * Fetches the current status of the task from the API.
43
+ *
44
+ * @returns {Promise<TaskStatus>} The current task status.
45
+ * @throws {Error} if the agent or task ID is missing.
46
+ */
47
+ fetchStatus(): Promise<TaskStatus>;
48
+ /**
49
+ * Fetches messages from the conversation.
50
+ *
51
+ * @param {Object} [options] Optional fetch options.
52
+ * @param {Date} [options.from] Fetch messages after this timestamp.
53
+ *
54
+ * @returns {Promise<TaskMessage[]>} Array of messages in ascending order.
55
+ * @throws {Error} if the agent or task ID is missing.
56
+ */
57
+ fetchMessages({ from }?: {
58
+ from?: Date;
59
+ }): Promise<TaskMessage[]>;
60
+ }
61
+ export {};
@@ -0,0 +1,112 @@
1
+ import { TaskMessage } from "./message.js";
2
+ import { Task } from "./task.js";
3
+ /**
4
+ * Converts an AgentTaskState to a simplified TaskStatus.
5
+ *
6
+ * @internal
7
+ *
8
+ * @param {AgentTaskState} state The agent task state to convert.
9
+ * @returns {TaskStatus} The simplified task status.
10
+ */
11
+ function stateToStatus(state) {
12
+ switch (state) {
13
+ case "paused":
14
+ case "idle":
15
+ return "idle";
16
+ case "starting-up":
17
+ case "waiting-for-capacity":
18
+ case "queued-for-approval":
19
+ case "queued-for-rerun":
20
+ return "queued";
21
+ case "running":
22
+ return "running";
23
+ case "pending-approval":
24
+ case "escalated":
25
+ return "action";
26
+ case "timed-out":
27
+ return "error";
28
+ case "cancelled":
29
+ case "completed":
30
+ return "complete";
31
+ case "unrecoverable":
32
+ case "errored-pending-approval":
33
+ return "error";
34
+ default:
35
+ throw new Error(`unhandled task state: ${state}`);
36
+ }
37
+ }
38
+ /**
39
+ * AgentTask represents a conversation task with an AI agent. It extends the
40
+ * base Task class with agent-specific functionality for sending messages and
41
+ * retrieving conversation history.
42
+ *
43
+ * @see {@link Task} for the base task functionality.
44
+ * @see {@link Agent} for the agent this task is associated with.
45
+ *
46
+ * @class AgentTask
47
+ * @extends Task<Agent, AgentTaskEvents>
48
+ */
49
+ export class AgentTask extends Task {
50
+ /**
51
+ * Sends a message to the agent. This method triggers the agent with the
52
+ * message and updates the task ID if this is the first message.
53
+ *
54
+ * Note: This method is asynchronous but doesn't return a promise. Use event
55
+ * listeners to track the response.
56
+ *
57
+ * @param {string} message
58
+ */
59
+ sendMessage(message) {
60
+ this.subject.trigger(message, this.id || undefined).then(({ id, state }) => {
61
+ // started
62
+ if (!this.id) {
63
+ this.setId(id, stateToStatus(state));
64
+ }
65
+ });
66
+ }
67
+ /**
68
+ * Fetches the current status of the task from the API.
69
+ *
70
+ * @returns {Promise<TaskStatus>} The current task status.
71
+ * @throws {Error} if the agent or task ID is missing.
72
+ */
73
+ async fetchStatus() {
74
+ if (!this.subject.id) {
75
+ throw new Error("expecting agent id");
76
+ }
77
+ if (!this.id) {
78
+ return "not-started";
79
+ }
80
+ const url = `/agents/${this.subject.id}/tasks/${this.id}/metadata`;
81
+ const res = await this.client.fetch(url);
82
+ return stateToStatus(res.metadata.conversation.state);
83
+ }
84
+ /**
85
+ * Fetches messages from the conversation.
86
+ *
87
+ * @param {Object} [options] Optional fetch options.
88
+ * @param {Date} [options.from] Fetch messages after this timestamp.
89
+ *
90
+ * @returns {Promise<TaskMessage[]>} Array of messages in ascending order.
91
+ * @throws {Error} if the agent or task ID is missing.
92
+ */
93
+ async fetchMessages({ from = new Date(0) } = {}) {
94
+ if (!this.subject.id) {
95
+ throw new Error("expecting agent id");
96
+ }
97
+ if (!this.id) {
98
+ throw new Error("expecting task id");
99
+ }
100
+ const url = `/agents/${this.subject.id}/tasks/${this.id}/view`;
101
+ const res = await this.client.fetch(url, {
102
+ method: "POST",
103
+ body: JSON.stringify({
104
+ cursor: {
105
+ after: from.toISOString(),
106
+ },
107
+ }),
108
+ });
109
+ // message should be in ascending order
110
+ return res.results.reverse().map((data) => new TaskMessage(data));
111
+ }
112
+ }
package/esm/agent.d.ts ADDED
@@ -0,0 +1,17 @@
1
+ import type { AgentTaskState } from "./agent-task.js";
2
+ import { Client } from "./client.js";
3
+ export declare class Agent {
4
+ #private;
5
+ private readonly client;
6
+ static fetch(agentId: string, cli?: Client): Promise<Agent>;
7
+ private constructor();
8
+ get id(): string;
9
+ get name(): string | undefined;
10
+ get description(): string | undefined;
11
+ get avatar(): string | undefined;
12
+ isPublic(): boolean;
13
+ trigger(message: string, taskId?: string): Promise<{
14
+ id: string;
15
+ state: AgentTaskState;
16
+ }>;
17
+ }
package/esm/agent.js ADDED
@@ -0,0 +1,52 @@
1
+ import { Client } from "./client.js";
2
+ import { randomUUID } from "./utils.js";
3
+ const taskPrefixDelimiter = "_-_";
4
+ export class Agent {
5
+ #config;
6
+ client;
7
+ static async fetch(agentId, cli = Client.default()) {
8
+ const config = await cli.fetch(`/agents/${agentId}/get`);
9
+ return new Agent(config.agent, cli);
10
+ }
11
+ constructor(config, client) {
12
+ this.#config = config;
13
+ this.client = client;
14
+ }
15
+ get id() {
16
+ return this.#config.agent_id;
17
+ }
18
+ get name() {
19
+ return this.#config.name;
20
+ }
21
+ get description() {
22
+ return this.#config.description;
23
+ }
24
+ get avatar() {
25
+ return this.#config.emoji;
26
+ }
27
+ isPublic() {
28
+ return this.#config.public;
29
+ }
30
+ async trigger(message, taskId) {
31
+ // embed keys require a task prefixing for new tasks
32
+ if (!taskId && this.client.isEmbedKey()) {
33
+ taskId = [this.client.key.taskPrefix, await randomUUID()].join(taskPrefixDelimiter);
34
+ }
35
+ const res = await this.client.fetch("/agents/trigger", {
36
+ method: "POST",
37
+ body: JSON.stringify({
38
+ agent_id: this.#config.agent_id,
39
+ conversation_id: taskId,
40
+ message: {
41
+ role: "user",
42
+ content: message,
43
+ attachments: [], // @todo
44
+ },
45
+ }),
46
+ });
47
+ return {
48
+ id: res.conversation_id,
49
+ state: res.state,
50
+ };
51
+ }
52
+ }
@@ -0,0 +1,36 @@
1
+ import { Agent } from "./agent.js";
2
+ import { type Region } from "./region.js";
3
+ import { AgentTask } from "./agent-task.js";
4
+ import { Key } from "./key.js";
5
+ type CreateClientOptions = {
6
+ apiKey: string;
7
+ region: Region;
8
+ project: string;
9
+ };
10
+ /**
11
+ * Creates and returns the _default_ client instance.
12
+ *
13
+ * @throws {Error} if a default client already exists.
14
+ * @see {Client.default}
15
+ */
16
+ export declare function createClient(keyOrOptions: Key | CreateClientOptions): Client;
17
+ export declare class Client {
18
+ /**
19
+ * Returns the _default_ client instance.
20
+ *
21
+ * @throws {Error} if there is no default client.
22
+ * @see {createClient}
23
+ */
24
+ static default(): Client;
25
+ readonly key: Key;
26
+ private readonly baseURL;
27
+ constructor(key: Key);
28
+ get region(): Region;
29
+ get project(): string;
30
+ isEmbedKey(): boolean;
31
+ createTask({ agent }: {
32
+ agent: string | Agent;
33
+ }): Promise<AgentTask>;
34
+ fetch<T>(input: `/agents/trigger` | `/agents/${string}/get` | `/agents/${string}/tasks/${string}/metadata` | `/agents/${string}/tasks/${string}/view`, init?: RequestInit): Promise<T>;
35
+ }
36
+ export {};
package/esm/client.js ADDED
@@ -0,0 +1,69 @@
1
+ import { Agent } from "./agent.js";
2
+ import { regionBaseURL } from "./region.js";
3
+ import { AgentTask } from "./agent-task.js";
4
+ import { cleanPath } from "./utils.js";
5
+ import { Key } from "./key.js";
6
+ let defaultClient;
7
+ /**
8
+ * Creates and returns the _default_ client instance.
9
+ *
10
+ * @throws {Error} if a default client already exists.
11
+ * @see {Client.default}
12
+ */
13
+ export function createClient(keyOrOptions) {
14
+ if (defaultClient) {
15
+ throw new Error("default client already exists");
16
+ }
17
+ const key = keyOrOptions instanceof Key ? keyOrOptions : new Key({
18
+ key: keyOrOptions.apiKey,
19
+ region: keyOrOptions.region,
20
+ project: keyOrOptions.project,
21
+ });
22
+ defaultClient = new Client(key);
23
+ return defaultClient;
24
+ }
25
+ export class Client {
26
+ /**
27
+ * Returns the _default_ client instance.
28
+ *
29
+ * @throws {Error} if there is no default client.
30
+ * @see {createClient}
31
+ */
32
+ static default() {
33
+ if (!defaultClient) {
34
+ throw new Error("no default client");
35
+ }
36
+ return defaultClient;
37
+ }
38
+ key;
39
+ baseURL;
40
+ constructor(key) {
41
+ this.key = key;
42
+ this.baseURL = regionBaseURL(this.key.region);
43
+ }
44
+ get region() {
45
+ return this.key.region;
46
+ }
47
+ get project() {
48
+ return this.key.project;
49
+ }
50
+ isEmbedKey() {
51
+ return this.key.isEmbed();
52
+ }
53
+ async createTask({ agent }) {
54
+ if (agent) {
55
+ return new AgentTask(typeof agent === "string" ? await Agent.fetch(agent) : agent, undefined, this);
56
+ }
57
+ throw new Error("task not implemented");
58
+ }
59
+ async fetch(input, init) {
60
+ const url = new URL(cleanPath(input), this.baseURL);
61
+ const headers = new Headers(this.key.fetchHeaders());
62
+ const response = await fetch(url, Object.assign({ headers }, init));
63
+ if (!response.ok) {
64
+ console.error(url, init, headers);
65
+ throw new Error(response.statusText);
66
+ }
67
+ return response.json();
68
+ }
69
+ }
@@ -0,0 +1,40 @@
1
+ import type { TaskMessage } from "./message.js";
2
+ import type { TaskStatus } from "./task.js";
3
+ export declare class TaskStartEvent extends CustomEvent<{
4
+ id: string;
5
+ status: TaskStatus;
6
+ }> {
7
+ readonly type = "start";
8
+ constructor(id: string, status: TaskStatus);
9
+ }
10
+ export declare class TaskStatusEvent extends CustomEvent<{
11
+ status: TaskStatus;
12
+ }> {
13
+ readonly type = "status";
14
+ constructor(status: TaskStatus);
15
+ }
16
+ export declare class TaskMessageEvent extends CustomEvent<{
17
+ message: TaskMessage;
18
+ }> {
19
+ readonly type = "message";
20
+ constructor(message: TaskMessage);
21
+ isUserMessage(): boolean;
22
+ }
23
+ export declare class TaskUpdateEvent extends CustomEvent<{
24
+ message: TaskMessage;
25
+ }> {
26
+ readonly type = "update";
27
+ constructor(message: TaskMessage);
28
+ }
29
+ export declare class TaskActionEvent extends CustomEvent<{
30
+ message: TaskMessage;
31
+ }> {
32
+ readonly type = "action";
33
+ constructor(message: TaskMessage);
34
+ }
35
+ export declare class TaskErrorEvent extends CustomEvent<{
36
+ message: TaskMessage;
37
+ }> {
38
+ readonly type = "error";
39
+ constructor(message: TaskMessage);
40
+ }
package/esm/events.js ADDED
@@ -0,0 +1,39 @@
1
+ export class TaskStartEvent extends CustomEvent {
2
+ type = "start";
3
+ constructor(id, status) {
4
+ super("start", { detail: { id, status } });
5
+ }
6
+ }
7
+ export class TaskStatusEvent extends CustomEvent {
8
+ type = "status";
9
+ constructor(status) {
10
+ super("status", { detail: { status } });
11
+ }
12
+ }
13
+ export class TaskMessageEvent extends CustomEvent {
14
+ type = "message";
15
+ constructor(message) {
16
+ super("message", { detail: { message } });
17
+ }
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
+ }
28
+ export class TaskActionEvent extends CustomEvent {
29
+ type = "action";
30
+ constructor(message) {
31
+ super("action", { detail: { message } });
32
+ }
33
+ }
34
+ export class TaskErrorEvent extends CustomEvent {
35
+ type = "error";
36
+ constructor(message) {
37
+ super("error", { detail: { message } });
38
+ }
39
+ }
package/esm/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/esm/key.js ADDED
@@ -0,0 +1,121 @@
1
+ import { regionBaseURL } from "./region.js";
2
+ import { cleanPath } from "./utils.js";
3
+ /**
4
+ * Key is used to authenticate requests for the {@link Client}. A Key can be
5
+ * either a _full_ key or an _embed_ key.
6
+ *
7
+ * A full key has access to SDK features. An embed key is scoped to a specific
8
+ * agent and is only used to create and interact with tasks for that agent.
9
+ *
10
+ * @see {@link Key.generateEmbedKey} to generate an embed key for a specific agent.
11
+ *
12
+ * @class Key
13
+ */
14
+ export class Key {
15
+ /**
16
+ * Generates an embed key for the specified agent. The embed key can then be
17
+ * used to create a {@link Client} instance that can create and interact with
18
+ * tasks for that agent.
19
+ *
20
+ * @throws {Error} if the request to generate an embed key fails.
21
+ *
22
+ * @param {GenerateEmbedKeyOptions} options The generation options.
23
+ *
24
+ * @returns {Promise<Key>}
25
+ */
26
+ static async generateEmbedKey({ region, project, agentId, }) {
27
+ const embedKeyURL = new URL(cleanPath("/agents/get_embed_key"), regionBaseURL(region));
28
+ const response = await fetch(embedKeyURL, {
29
+ method: "POST",
30
+ body: JSON.stringify({ agent_id: agentId, project }),
31
+ });
32
+ if (!response.ok) {
33
+ throw new Error("failed to fetch embed key", { cause: response });
34
+ }
35
+ const { embed_key: embedKey, conversation_prefix: taskPrefix } = await response.json();
36
+ return new Key({
37
+ key: embedKey,
38
+ region,
39
+ project,
40
+ agentId,
41
+ taskPrefix,
42
+ });
43
+ }
44
+ /**
45
+ * The region the key is scoped to.
46
+ *
47
+ * @property {string} region
48
+ */
49
+ region;
50
+ /**
51
+ * The project the key is scoped to.
52
+ *
53
+ * @property {string} project
54
+ */
55
+ project;
56
+ /**
57
+ * The API key used for authentication.
58
+ *
59
+ * @private
60
+ * @property {string} key
61
+ */
62
+ #key;
63
+ /**
64
+ * The agent ID the embed key is scoped to. This is `undefined` for full
65
+ * keys.
66
+ *
67
+ * @property {string | undefined} agentId
68
+ */
69
+ agentId;
70
+ /**
71
+ * The task prefix used to namespace tasks created with the embed key. This
72
+ * is `undefined` for full keys.
73
+ *
74
+ * @property {string | undefined} taskPrefix
75
+ */
76
+ taskPrefix;
77
+ /**
78
+ * Creates a new {@link Key} instance with the provided options.
79
+ *
80
+ * @param {CreateKeyOptions} options
81
+ */
82
+ constructor({ key, region, project, agentId, taskPrefix }) {
83
+ this.#key = key;
84
+ this.region = region;
85
+ this.project = project;
86
+ this.agentId = agentId;
87
+ this.taskPrefix = taskPrefix;
88
+ }
89
+ /**
90
+ * Returns whether the key is an embed key.
91
+ *
92
+ * @returns {boolean}
93
+ */
94
+ isEmbed() {
95
+ return (this.agentId !== undefined && this.taskPrefix !== undefined);
96
+ }
97
+ /**
98
+ * Returns the headers required for authenticating requests with this key.
99
+ *
100
+ * @returns {HeadersInit}
101
+ */
102
+ fetchHeaders() {
103
+ return {
104
+ Authorization: `${this.project}:${this.#key}`,
105
+ };
106
+ }
107
+ /**
108
+ * Returns a JSON representation of the key.
109
+ *
110
+ * @returns {CreateKeyOptions}
111
+ */
112
+ toJSON() {
113
+ return {
114
+ key: this.#key,
115
+ region: this.region,
116
+ project: this.project,
117
+ agentId: this.agentId,
118
+ taskPrefix: this.taskPrefix,
119
+ };
120
+ }
121
+ }
@@ -0,0 +1,18 @@
1
+ type TaskMessageType = "user-message" | "agent-message" | "tool-run" | "agent-error";
2
+ export type MessageData = {
3
+ item_id: string;
4
+ insert_date_: string;
5
+ content: {
6
+ type: TaskMessageType;
7
+ text: string;
8
+ };
9
+ };
10
+ export declare class TaskMessage<T extends TaskMessageType = TaskMessageType> {
11
+ #private;
12
+ constructor(data: MessageData);
13
+ get id(): string;
14
+ get type(): T;
15
+ get createdAt(): Date;
16
+ get text(): string;
17
+ }
18
+ export {};
package/esm/message.js ADDED
@@ -0,0 +1,18 @@
1
+ export class TaskMessage {
2
+ #data;
3
+ constructor(data) {
4
+ this.#data = data;
5
+ }
6
+ get id() {
7
+ return this.#data.item_id;
8
+ }
9
+ get type() {
10
+ return this.#data.content.type;
11
+ }
12
+ get createdAt() {
13
+ return new Date(this.#data.insert_date_);
14
+ }
15
+ get text() {
16
+ return this.#data.content.text;
17
+ }
18
+ }
package/esm/mod.d.ts ADDED
@@ -0,0 +1,7 @@
1
+ export { Agent } from "./agent.js";
2
+ export { Client, createClient } from "./client.js";
3
+ export { Key } from "./key.js";
4
+ export { type Region, REGION_AU, REGION_EU, REGION_US } from "./region.js";
5
+ export type { AgentTask } from "./agent-task.js";
6
+ export type { TaskMessage } from "./message.js";
7
+ export type { Task, TaskStatus } from "./task.js";
package/esm/mod.js ADDED
@@ -0,0 +1,4 @@
1
+ export { Agent } from "./agent.js";
2
+ export { Client, createClient } from "./client.js";
3
+ export { Key } from "./key.js";
4
+ export { REGION_AU, REGION_EU, REGION_US } from "./region.js";