@agentjam/sdk 0.5.0 → 0.6.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.
- package/dist/adapters/ai.d.ts +1 -1
- package/dist/adapters/ai.d.ts.map +1 -1
- package/dist/adapters/anthropic.d.ts +1 -1
- package/dist/adapters/anthropic.d.ts.map +1 -1
- package/dist/adapters/openai.d.ts +1 -1
- package/dist/adapters/openai.d.ts.map +1 -1
- package/dist/adapters/openaiAgents.d.ts +1 -1
- package/dist/adapters/openaiAgents.d.ts.map +1 -1
- package/dist/adapters/shared.d.ts +2 -2
- package/dist/adapters/shared.d.ts.map +1 -1
- package/dist/adapters/shared.js +6 -2
- package/dist/adapters/shared.js.map +1 -1
- package/dist/agent.d.ts +73 -5
- package/dist/agent.d.ts.map +1 -1
- package/dist/agent.js +140 -10
- package/dist/agent.js.map +1 -1
- package/dist/errors.d.ts +1 -1
- package/dist/errors.js +1 -1
- package/dist/index.d.ts +4 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/protocol.d.ts +163 -6
- package/dist/protocol.d.ts.map +1 -1
- package/dist/relay/frames.d.ts +52 -2
- package/dist/relay/frames.d.ts.map +1 -1
- package/dist/relay/frames.js +2 -0
- package/dist/relay/frames.js.map +1 -1
- package/dist/relay/payments.d.ts +8 -3
- package/dist/relay/payments.d.ts.map +1 -1
- package/dist/relay/payments.js +20 -2
- package/dist/relay/payments.js.map +1 -1
- package/dist/relay/relay.d.ts +44 -5
- package/dist/relay/relay.d.ts.map +1 -1
- package/dist/relay/remote.d.ts.map +1 -1
- package/dist/relay/remote.js +65 -8
- package/dist/relay/remote.js.map +1 -1
- package/dist/relay/schedules.d.ts +2 -1
- package/dist/relay/schedules.d.ts.map +1 -1
- package/dist/relay/schedules.js +13 -3
- package/dist/relay/schedules.js.map +1 -1
- package/dist/tasks/outgoing.d.ts.map +1 -1
- package/dist/tasks/outgoing.js +1 -0
- package/dist/tasks/outgoing.js.map +1 -1
- package/dist/tasks/scheduled.d.ts +18 -8
- package/dist/tasks/scheduled.d.ts.map +1 -1
- package/dist/tasks/scheduled.js +77 -20
- package/dist/tasks/scheduled.js.map +1 -1
- package/dist/tasks/triggers.d.ts +11 -3
- package/dist/tasks/triggers.d.ts.map +1 -1
- package/dist/tasks/triggers.js +30 -11
- package/dist/tasks/triggers.js.map +1 -1
- package/dist/tools/delegations.d.ts +17 -0
- package/dist/tools/delegations.d.ts.map +1 -0
- package/dist/tools/delegations.js +67 -0
- package/dist/tools/delegations.js.map +1 -0
- package/dist/tools/inputs.d.ts +62 -0
- package/dist/tools/inputs.d.ts.map +1 -0
- package/dist/tools/inputs.js +143 -0
- package/dist/tools/inputs.js.map +1 -0
- package/dist/tools/network.d.ts +10 -0
- package/dist/tools/network.d.ts.map +1 -0
- package/dist/tools/network.js +435 -0
- package/dist/tools/network.js.map +1 -0
- package/dist/tools/schedules.d.ts +43 -0
- package/dist/tools/schedules.d.ts.map +1 -0
- package/dist/tools/schedules.js +337 -0
- package/dist/tools/schedules.js.map +1 -0
- package/dist/tools/shared.d.ts +152 -0
- package/dist/tools/shared.d.ts.map +1 -0
- package/dist/tools/shared.js +151 -0
- package/dist/tools/shared.js.map +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import { artifact } from "../artifacts.js";
|
|
2
|
+
import { AgentJamError, describeError, TaskCanceledError } from "../errors.js";
|
|
3
|
+
import { currentTask } from "../tasks/incoming.js";
|
|
4
|
+
/** Every network tool's name, in the order agents list their tools. */
|
|
5
|
+
export const networkToolNames = [
|
|
6
|
+
"find_agents",
|
|
7
|
+
"prepare_delegates",
|
|
8
|
+
"send_message",
|
|
9
|
+
"delegate_task",
|
|
10
|
+
"wait_for_tasks",
|
|
11
|
+
"cancel_task",
|
|
12
|
+
"list_tasks",
|
|
13
|
+
"get_task",
|
|
14
|
+
"schedule_task",
|
|
15
|
+
"get_schedule",
|
|
16
|
+
"list_schedules",
|
|
17
|
+
"list_runs",
|
|
18
|
+
"update_schedule",
|
|
19
|
+
"end_schedule",
|
|
20
|
+
"recall_task",
|
|
21
|
+
"list_past_tasks",
|
|
22
|
+
"publish_update",
|
|
23
|
+
"deliver_file",
|
|
24
|
+
"forward_artifact",
|
|
25
|
+
"rate_agent",
|
|
26
|
+
"dispute_task",
|
|
27
|
+
"list_reviews",
|
|
28
|
+
];
|
|
29
|
+
export const irreversibleHint = "A task of a skill marked irreversible can't be canceled once its agent commits to an action it can't undo, such as a purchase, so confirm with your human before delegating one.";
|
|
30
|
+
export const followUpHint = "To change or build on an ended task's result, delegate to the same agent again with follows set to its taskId, describing only what to change: the agent sees what that task asked for and produced, and the same skill reuses its input when you omit input. A skill that lists revisions runs that many follow-ups of a completed task for free.";
|
|
31
|
+
export const prepareHint = "Before long work, pass the agents you'll delegate to whose skills list connections to prepare_delegates, so your human connects their accounts at the start rather than partway through.";
|
|
32
|
+
export const summarize = (received) => received.type === "text"
|
|
33
|
+
? {
|
|
34
|
+
id: received.id,
|
|
35
|
+
type: "text",
|
|
36
|
+
name: received.name,
|
|
37
|
+
mimeType: received.mimeType,
|
|
38
|
+
text: received.text,
|
|
39
|
+
}
|
|
40
|
+
: {
|
|
41
|
+
id: received.id,
|
|
42
|
+
type: "file",
|
|
43
|
+
name: received.name,
|
|
44
|
+
mimeType: received.mimeType,
|
|
45
|
+
size: received.size,
|
|
46
|
+
};
|
|
47
|
+
const toResult = (output) => typeof output === "string" ? { text: output, files: [] } : output;
|
|
48
|
+
export const summarizeActions = (actions) => actions.map(({ provider, url, origin, reason }) => ({
|
|
49
|
+
provider,
|
|
50
|
+
url,
|
|
51
|
+
...(reason && { reason }),
|
|
52
|
+
...(origin && { agent: origin.executor }),
|
|
53
|
+
}));
|
|
54
|
+
export const networkTool = ({ run, ...definition }) => ({
|
|
55
|
+
...definition,
|
|
56
|
+
execute: async (input, { signal } = {}) => {
|
|
57
|
+
const signals = [signal, currentTask()?.signal].filter((candidate) => candidate !== undefined);
|
|
58
|
+
const fields = typeof input === "object" && input !== null ? input : {};
|
|
59
|
+
try {
|
|
60
|
+
return toResult(await run(fields, AbortSignal.any(signals)));
|
|
61
|
+
}
|
|
62
|
+
catch (error) {
|
|
63
|
+
signal?.throwIfAborted();
|
|
64
|
+
if (error instanceof AgentJamError) {
|
|
65
|
+
return toResult(`Error: ${error.message}`);
|
|
66
|
+
}
|
|
67
|
+
throw error;
|
|
68
|
+
}
|
|
69
|
+
},
|
|
70
|
+
});
|
|
71
|
+
export const attachmentsField = {
|
|
72
|
+
type: "array",
|
|
73
|
+
description: "Files to send, at most 10, from those you received while working on the current task: the files it came with, the results of tasks you delegated, and the files on replies about tasks",
|
|
74
|
+
fields: { fileId: "The file's id" },
|
|
75
|
+
optional: {
|
|
76
|
+
taskId: "The taskId of the task that returned the file, or that the reply carrying it was about. Omit it for a file the current task came with",
|
|
77
|
+
},
|
|
78
|
+
};
|
|
79
|
+
export const constructSource = (received) => received.type === "text"
|
|
80
|
+
? artifact(received.text, {
|
|
81
|
+
...(received.name === undefined ? {} : { name: received.name }),
|
|
82
|
+
...(received.mimeType === undefined
|
|
83
|
+
? {}
|
|
84
|
+
: { mimeType: received.mimeType }),
|
|
85
|
+
})
|
|
86
|
+
: received;
|
|
87
|
+
/**
|
|
88
|
+
* Keeps the artifacts the tasks delegated as part of each task returned, and the files on replies about tasks, for as
|
|
89
|
+
* long as that task lives, so it can forward or attach them.
|
|
90
|
+
*/
|
|
91
|
+
export class ArtifactShelf {
|
|
92
|
+
received = new WeakMap();
|
|
93
|
+
/** Summarizes the files a task returned or a reply about it carried for the model, keeping them for the current task. */
|
|
94
|
+
summarize(taskId, artifacts) {
|
|
95
|
+
const task = currentTask();
|
|
96
|
+
if (task && taskId !== undefined) {
|
|
97
|
+
const kept = this.received.get(task) ?? new Map();
|
|
98
|
+
for (const received of artifacts) {
|
|
99
|
+
kept.set(`${taskId}/${received.id}`, received);
|
|
100
|
+
}
|
|
101
|
+
this.received.set(task, kept);
|
|
102
|
+
}
|
|
103
|
+
return artifacts.map(summarize);
|
|
104
|
+
}
|
|
105
|
+
find(task, taskId, artifactId) {
|
|
106
|
+
return this.received.get(task)?.get(`${taskId}/${artifactId}`);
|
|
107
|
+
}
|
|
108
|
+
/** Finds the files the model names among those received while working on the current task, ready to attach. */
|
|
109
|
+
findAttachments(references) {
|
|
110
|
+
if (!references?.length)
|
|
111
|
+
return undefined;
|
|
112
|
+
const task = currentTask();
|
|
113
|
+
if (!task) {
|
|
114
|
+
throw new AgentJamError("No task is in progress, so there are no files to attach");
|
|
115
|
+
}
|
|
116
|
+
return references.map(({ fileId, taskId }) => {
|
|
117
|
+
const received = taskId === undefined
|
|
118
|
+
? task.attachments.find(({ id }) => id === fileId)
|
|
119
|
+
: this.find(task, taskId, fileId);
|
|
120
|
+
if (received)
|
|
121
|
+
return constructSource(received);
|
|
122
|
+
throw new AgentJamError(taskId === undefined
|
|
123
|
+
? `The current task came with no file "${fileId}"`
|
|
124
|
+
: `Task "${taskId}" returned no file "${fileId}" while you worked on the current task`);
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
export const settleTask = async (task, shelf) => {
|
|
129
|
+
try {
|
|
130
|
+
const artifacts = await task.result();
|
|
131
|
+
const output = await task.getOutput();
|
|
132
|
+
return {
|
|
133
|
+
taskId: task.id,
|
|
134
|
+
status: "completed",
|
|
135
|
+
...(output && { output }),
|
|
136
|
+
artifacts: shelf.summarize(task.id, artifacts),
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
catch (error) {
|
|
140
|
+
if (error instanceof TaskCanceledError) {
|
|
141
|
+
return {
|
|
142
|
+
taskId: task.id,
|
|
143
|
+
status: "canceled",
|
|
144
|
+
...(error.code && { code: error.code }),
|
|
145
|
+
error: error.message,
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
return { taskId: task.id, status: "failed", error: describeError(error) };
|
|
149
|
+
}
|
|
150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