@agentjam/sdk 0.0.0-stage → 0.2.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 (274) hide show
  1. package/README.md +181 -2
  2. package/dist/adapters/ai.d.ts +47 -0
  3. package/dist/adapters/ai.d.ts.map +1 -0
  4. package/dist/adapters/ai.js +168 -0
  5. package/dist/adapters/ai.js.map +1 -0
  6. package/dist/adapters/anthropic.d.ts +68 -0
  7. package/dist/adapters/anthropic.d.ts.map +1 -0
  8. package/dist/adapters/anthropic.js +193 -0
  9. package/dist/adapters/anthropic.js.map +1 -0
  10. package/dist/adapters/openai.d.ts +35 -0
  11. package/dist/adapters/openai.d.ts.map +1 -0
  12. package/dist/adapters/openai.js +80 -0
  13. package/dist/adapters/openai.js.map +1 -0
  14. package/dist/adapters/openaiAgents.d.ts +39 -0
  15. package/dist/adapters/openaiAgents.d.ts.map +1 -0
  16. package/dist/adapters/openaiAgents.js +152 -0
  17. package/dist/adapters/openaiAgents.js.map +1 -0
  18. package/dist/adapters/shared.d.ts +72 -0
  19. package/dist/adapters/shared.d.ts.map +1 -0
  20. package/dist/adapters/shared.js +174 -0
  21. package/dist/adapters/shared.js.map +1 -0
  22. package/dist/agent.d.ts +462 -0
  23. package/dist/agent.d.ts.map +1 -0
  24. package/dist/agent.js +1820 -0
  25. package/dist/agent.js.map +1 -0
  26. package/dist/artifacts.d.ts +79 -0
  27. package/dist/artifacts.d.ts.map +1 -0
  28. package/dist/artifacts.js +367 -0
  29. package/dist/artifacts.js.map +1 -0
  30. package/dist/attachments.d.ts +43 -0
  31. package/dist/attachments.d.ts.map +1 -0
  32. package/dist/attachments.js +69 -0
  33. package/dist/attachments.js.map +1 -0
  34. package/dist/connections.d.ts +109 -0
  35. package/dist/connections.d.ts.map +1 -0
  36. package/dist/connections.js +274 -0
  37. package/dist/connections.js.map +1 -0
  38. package/dist/content.d.ts +36 -0
  39. package/dist/content.d.ts.map +1 -0
  40. package/dist/content.js +21 -0
  41. package/dist/content.js.map +1 -0
  42. package/dist/cron.d.ts +31 -0
  43. package/dist/cron.d.ts.map +1 -0
  44. package/dist/cron.js +93 -0
  45. package/dist/cron.js.map +1 -0
  46. package/dist/errors.d.ts +227 -0
  47. package/dist/errors.d.ts.map +1 -0
  48. package/dist/errors.js +253 -0
  49. package/dist/errors.js.map +1 -0
  50. package/dist/events.d.ts +57 -0
  51. package/dist/events.d.ts.map +1 -0
  52. package/dist/events.js +24 -0
  53. package/dist/events.js.map +1 -0
  54. package/dist/idempotency.d.ts +21 -0
  55. package/dist/idempotency.d.ts.map +1 -0
  56. package/dist/idempotency.js +46 -0
  57. package/dist/idempotency.js.map +1 -0
  58. package/dist/index.d.ts +44 -0
  59. package/dist/index.d.ts.map +1 -0
  60. package/dist/index.js +18 -0
  61. package/dist/index.js.map +1 -0
  62. package/dist/inputs.d.ts +22 -0
  63. package/dist/inputs.d.ts.map +1 -0
  64. package/dist/inputs.js +72 -0
  65. package/dist/inputs.js.map +1 -0
  66. package/dist/mpp.d.ts +76 -0
  67. package/dist/mpp.d.ts.map +1 -0
  68. package/dist/mpp.js +113 -0
  69. package/dist/mpp.js.map +1 -0
  70. package/dist/oauth.d.ts +3 -0
  71. package/dist/oauth.d.ts.map +1 -0
  72. package/dist/oauth.js +2 -0
  73. package/dist/oauth.js.map +1 -0
  74. package/dist/oauthCallbacks.d.ts +2 -0
  75. package/dist/oauthCallbacks.d.ts.map +1 -0
  76. package/dist/oauthCallbacks.js +58 -0
  77. package/dist/oauthCallbacks.js.map +1 -0
  78. package/dist/platforms/datadog.d.ts +10 -0
  79. package/dist/platforms/datadog.d.ts.map +1 -0
  80. package/dist/platforms/datadog.js +15 -0
  81. package/dist/platforms/datadog.js.map +1 -0
  82. package/dist/platforms/github.d.ts +181 -0
  83. package/dist/platforms/github.d.ts.map +1 -0
  84. package/dist/platforms/github.js +468 -0
  85. package/dist/platforms/github.js.map +1 -0
  86. package/dist/platforms/google.d.ts +19 -0
  87. package/dist/platforms/google.d.ts.map +1 -0
  88. package/dist/platforms/google.js +70 -0
  89. package/dist/platforms/google.js.map +1 -0
  90. package/dist/platforms/grafana.d.ts +10 -0
  91. package/dist/platforms/grafana.d.ts.map +1 -0
  92. package/dist/platforms/grafana.js +14 -0
  93. package/dist/platforms/grafana.js.map +1 -0
  94. package/dist/platforms/posthog.d.ts +10 -0
  95. package/dist/platforms/posthog.d.ts.map +1 -0
  96. package/dist/platforms/posthog.js +14 -0
  97. package/dist/platforms/posthog.js.map +1 -0
  98. package/dist/platforms/presets.d.ts +34 -0
  99. package/dist/platforms/presets.d.ts.map +1 -0
  100. package/dist/platforms/presets.js +36 -0
  101. package/dist/platforms/presets.js.map +1 -0
  102. package/dist/platforms/sentry.d.ts +79 -0
  103. package/dist/platforms/sentry.d.ts.map +1 -0
  104. package/dist/platforms/sentry.js +124 -0
  105. package/dist/platforms/sentry.js.map +1 -0
  106. package/dist/platforms/slack.d.ts +101 -0
  107. package/dist/platforms/slack.d.ts.map +1 -0
  108. package/dist/platforms/slack.js +309 -0
  109. package/dist/platforms/slack.js.map +1 -0
  110. package/dist/platforms/splunk.d.ts +10 -0
  111. package/dist/platforms/splunk.d.ts.map +1 -0
  112. package/dist/platforms/splunk.js +14 -0
  113. package/dist/platforms/splunk.js.map +1 -0
  114. package/dist/polling.d.ts +2 -0
  115. package/dist/polling.d.ts.map +1 -0
  116. package/dist/polling.js +66 -0
  117. package/dist/polling.js.map +1 -0
  118. package/dist/profile.d.ts +60 -0
  119. package/dist/profile.d.ts.map +1 -0
  120. package/dist/profile.js +119 -0
  121. package/dist/profile.js.map +1 -0
  122. package/dist/protocol.d.ts +474 -0
  123. package/dist/protocol.d.ts.map +1 -0
  124. package/dist/protocol.js +2 -0
  125. package/dist/protocol.js.map +1 -0
  126. package/dist/providers.d.ts +113 -0
  127. package/dist/providers.d.ts.map +1 -0
  128. package/dist/providers.js +98 -0
  129. package/dist/providers.js.map +1 -0
  130. package/dist/recaps.d.ts +10 -0
  131. package/dist/recaps.d.ts.map +1 -0
  132. package/dist/recaps.js +49 -0
  133. package/dist/recaps.js.map +1 -0
  134. package/dist/relay/chains.d.ts +62 -0
  135. package/dist/relay/chains.d.ts.map +1 -0
  136. package/dist/relay/chains.js +150 -0
  137. package/dist/relay/chains.js.map +1 -0
  138. package/dist/relay/credentials.d.ts +25 -0
  139. package/dist/relay/credentials.d.ts.map +1 -0
  140. package/dist/relay/credentials.js +234 -0
  141. package/dist/relay/credentials.js.map +1 -0
  142. package/dist/relay/endpoints.d.ts +13 -0
  143. package/dist/relay/endpoints.d.ts.map +1 -0
  144. package/dist/relay/endpoints.js +13 -0
  145. package/dist/relay/endpoints.js.map +1 -0
  146. package/dist/relay/frames.d.ts +193 -0
  147. package/dist/relay/frames.d.ts.map +1 -0
  148. package/dist/relay/frames.js +161 -0
  149. package/dist/relay/frames.js.map +1 -0
  150. package/dist/relay/grants.d.ts +158 -0
  151. package/dist/relay/grants.d.ts.map +1 -0
  152. package/dist/relay/grants.js +2 -0
  153. package/dist/relay/grants.js.map +1 -0
  154. package/dist/relay/guestStore.d.ts +37 -0
  155. package/dist/relay/guestStore.d.ts.map +1 -0
  156. package/dist/relay/guestStore.js +61 -0
  157. package/dist/relay/guestStore.js.map +1 -0
  158. package/dist/relay/guests.d.ts +7 -0
  159. package/dist/relay/guests.d.ts.map +1 -0
  160. package/dist/relay/guests.js +30 -0
  161. package/dist/relay/guests.js.map +1 -0
  162. package/dist/relay/memory.d.ts +60 -0
  163. package/dist/relay/memory.d.ts.map +1 -0
  164. package/dist/relay/memory.js +334 -0
  165. package/dist/relay/memory.js.map +1 -0
  166. package/dist/relay/payments.d.ts +43 -0
  167. package/dist/relay/payments.d.ts.map +1 -0
  168. package/dist/relay/payments.js +115 -0
  169. package/dist/relay/payments.js.map +1 -0
  170. package/dist/relay/profiles.d.ts +10 -0
  171. package/dist/relay/profiles.d.ts.map +1 -0
  172. package/dist/relay/profiles.js +43 -0
  173. package/dist/relay/profiles.js.map +1 -0
  174. package/dist/relay/relay.d.ts +133 -0
  175. package/dist/relay/relay.d.ts.map +1 -0
  176. package/dist/relay/relay.js +2 -0
  177. package/dist/relay/relay.js.map +1 -0
  178. package/dist/relay/remote.d.ts +39 -0
  179. package/dist/relay/remote.d.ts.map +1 -0
  180. package/dist/relay/remote.js +492 -0
  181. package/dist/relay/remote.js.map +1 -0
  182. package/dist/relay/revisions.d.ts +13 -0
  183. package/dist/relay/revisions.d.ts.map +1 -0
  184. package/dist/relay/revisions.js +34 -0
  185. package/dist/relay/revisions.js.map +1 -0
  186. package/dist/relay/schedules.d.ts +41 -0
  187. package/dist/relay/schedules.d.ts.map +1 -0
  188. package/dist/relay/schedules.js +217 -0
  189. package/dist/relay/schedules.js.map +1 -0
  190. package/dist/relay/secrets.d.ts +14 -0
  191. package/dist/relay/secrets.d.ts.map +1 -0
  192. package/dist/relay/secrets.js +30 -0
  193. package/dist/relay/secrets.js.map +1 -0
  194. package/dist/relay/sessions.d.ts +59 -0
  195. package/dist/relay/sessions.d.ts.map +1 -0
  196. package/dist/relay/sessions.js +282 -0
  197. package/dist/relay/sessions.js.map +1 -0
  198. package/dist/relay/uploads.d.ts +15 -0
  199. package/dist/relay/uploads.d.ts.map +1 -0
  200. package/dist/relay/uploads.js +55 -0
  201. package/dist/relay/uploads.js.map +1 -0
  202. package/dist/requests.d.ts +22 -0
  203. package/dist/requests.d.ts.map +1 -0
  204. package/dist/requests.js +64 -0
  205. package/dist/requests.js.map +1 -0
  206. package/dist/screening.d.ts +93 -0
  207. package/dist/screening.d.ts.map +1 -0
  208. package/dist/screening.js +176 -0
  209. package/dist/screening.js.map +1 -0
  210. package/dist/secrets.d.ts +38 -0
  211. package/dist/secrets.d.ts.map +1 -0
  212. package/dist/secrets.js +162 -0
  213. package/dist/secrets.js.map +1 -0
  214. package/dist/skills.d.ts +11 -0
  215. package/dist/skills.d.ts.map +1 -0
  216. package/dist/skills.js +55 -0
  217. package/dist/skills.js.map +1 -0
  218. package/dist/stripe.d.ts +10 -0
  219. package/dist/stripe.d.ts.map +1 -0
  220. package/dist/stripe.js +51 -0
  221. package/dist/stripe.js.map +1 -0
  222. package/dist/tasks/access.d.ts +35 -0
  223. package/dist/tasks/access.d.ts.map +1 -0
  224. package/dist/tasks/access.js +101 -0
  225. package/dist/tasks/access.js.map +1 -0
  226. package/dist/tasks/incoming.d.ts +333 -0
  227. package/dist/tasks/incoming.d.ts.map +1 -0
  228. package/dist/tasks/incoming.js +354 -0
  229. package/dist/tasks/incoming.js.map +1 -0
  230. package/dist/tasks/outgoing.d.ts +137 -0
  231. package/dist/tasks/outgoing.d.ts.map +1 -0
  232. package/dist/tasks/outgoing.js +233 -0
  233. package/dist/tasks/outgoing.js.map +1 -0
  234. package/dist/tasks/scheduled.d.ts +76 -0
  235. package/dist/tasks/scheduled.d.ts.map +1 -0
  236. package/dist/tasks/scheduled.js +110 -0
  237. package/dist/tasks/scheduled.js.map +1 -0
  238. package/dist/tasks/triggers.d.ts +47 -0
  239. package/dist/tasks/triggers.d.ts.map +1 -0
  240. package/dist/tasks/triggers.js +149 -0
  241. package/dist/tasks/triggers.js.map +1 -0
  242. package/dist/tasks/watches.d.ts +13 -0
  243. package/dist/tasks/watches.d.ts.map +1 -0
  244. package/dist/tasks/watches.js +54 -0
  245. package/dist/tasks/watches.js.map +1 -0
  246. package/dist/tools.d.ts +85 -0
  247. package/dist/tools.d.ts.map +1 -0
  248. package/dist/tools.js +627 -0
  249. package/dist/tools.js.map +1 -0
  250. package/dist/types.d.ts +926 -0
  251. package/dist/types.d.ts.map +1 -0
  252. package/dist/types.js +2 -0
  253. package/dist/types.js.map +1 -0
  254. package/dist/vaults/local.d.ts +54 -0
  255. package/dist/vaults/local.d.ts.map +1 -0
  256. package/dist/vaults/local.js +362 -0
  257. package/dist/vaults/local.js.map +1 -0
  258. package/dist/vaults/remote.d.ts +78 -0
  259. package/dist/vaults/remote.d.ts.map +1 -0
  260. package/dist/vaults/remote.js +295 -0
  261. package/dist/vaults/remote.js.map +1 -0
  262. package/dist/vaults/vault.d.ts +69 -0
  263. package/dist/vaults/vault.d.ts.map +1 -0
  264. package/dist/vaults/vault.js +19 -0
  265. package/dist/vaults/vault.js.map +1 -0
  266. package/dist/verdicts.d.ts +15 -0
  267. package/dist/verdicts.d.ts.map +1 -0
  268. package/dist/verdicts.js +17 -0
  269. package/dist/verdicts.js.map +1 -0
  270. package/dist/watermarks.d.ts +29 -0
  271. package/dist/watermarks.d.ts.map +1 -0
  272. package/dist/watermarks.js +11 -0
  273. package/dist/watermarks.js.map +1 -0
  274. package/package.json +160 -3
@@ -0,0 +1,174 @@
1
+ import { Buffer } from "node:buffer";
2
+ import { AgentJamError } from "../errors.js";
3
+ import { pickTools } from "../tools.js";
4
+ const mebibyte = 1024 * 1024;
5
+ export const maxShownFiles = 20;
6
+ export const maxShownBytes = 20 * mebibyte;
7
+ // WARNING: Anthropic refuses images over 5 MiB once base64-encoded, which grows them by a third.
8
+ export const maxImageBytes = 3.75 * mebibyte;
9
+ export const maxDocumentBytes = 10 * mebibyte;
10
+ export const maxTextBytes = 100 * 1024;
11
+ const imageTypes = [
12
+ "image/png",
13
+ "image/jpeg",
14
+ "image/gif",
15
+ "image/webp",
16
+ ];
17
+ const textTypes = new Set([
18
+ "application/json",
19
+ "application/xml",
20
+ "application/yaml",
21
+ "application/x-yaml",
22
+ "application/csv",
23
+ ]);
24
+ const textSuffixes = ["+json", "+xml", "+yaml"];
25
+ const isImageType = (mimeType) => imageTypes.some((imageType) => imageType === mimeType);
26
+ const isTextType = (mimeType) => mimeType.startsWith("text/") ||
27
+ textTypes.has(mimeType) ||
28
+ textSuffixes.some((suffix) => mimeType.endsWith(suffix));
29
+ const classifyFile = (file) => {
30
+ const mimeType = file.type.split(";")[0].trim().toLowerCase();
31
+ if (isImageType(mimeType))
32
+ return { type: "image", mimeType };
33
+ if (mimeType === "application/pdf")
34
+ return { type: "document", mimeType };
35
+ if (isTextType(mimeType))
36
+ return { type: "text" };
37
+ return undefined;
38
+ };
39
+ /** How many of the call's bytes showing the file takes, or undefined if it's over its type's cap. */
40
+ const measureFile = (file, kind) => {
41
+ switch (kind.type) {
42
+ case "image":
43
+ return file.size <= maxImageBytes ? file.size : undefined;
44
+ case "document":
45
+ return file.size <= maxDocumentBytes ? file.size : undefined;
46
+ case "text":
47
+ return Math.min(file.size, maxTextBytes);
48
+ default: {
49
+ const unknown = kind;
50
+ throw new AgentJamError(`Unknown file kind: ${String(unknown)}`);
51
+ }
52
+ }
53
+ };
54
+ const describeFile = (file) => `File "${file.name}" (${file.type || "unknown type"}, ${file.size} bytes)`;
55
+ const encodeFile = async (file) => Buffer.from(await file.arrayBuffer()).toString("base64");
56
+ const readText = async (file) => {
57
+ const text = await file.slice(0, maxTextBytes).text();
58
+ if (file.size <= maxTextBytes)
59
+ return text;
60
+ return `${text}\n[Truncated to the first ${maxTextBytes} of ${file.size} bytes]`;
61
+ };
62
+ const showFile = async (file, kind) => {
63
+ switch (kind.type) {
64
+ case "image":
65
+ case "document":
66
+ return [
67
+ { type: "text", text: `${describeFile(file)}:` },
68
+ { ...kind, name: file.name, data: await encodeFile(file) },
69
+ ];
70
+ case "text":
71
+ return [
72
+ {
73
+ type: "text",
74
+ text: `${describeFile(file)}:\n${await readText(file)}`,
75
+ },
76
+ ];
77
+ default: {
78
+ const unknown = kind;
79
+ throw new AgentJamError(`Unknown file kind: ${String(unknown)}`);
80
+ }
81
+ }
82
+ };
83
+ /**
84
+ * Converts the files of one model call into content parts, in order. Images and PDFs become image and
85
+ * document parts, text files are inlined, and the rest, or any past the caps, are only described.
86
+ */
87
+ export const convertFiles = async (files) => {
88
+ const parts = [];
89
+ let shownFiles = 0;
90
+ let shownBytes = 0;
91
+ for (const file of files) {
92
+ const kind = classifyFile(file);
93
+ const bytes = kind && measureFile(file, kind);
94
+ const isShown = kind !== undefined &&
95
+ bytes !== undefined &&
96
+ shownFiles < maxShownFiles &&
97
+ shownBytes + bytes <= maxShownBytes;
98
+ if (!isShown) {
99
+ parts.push({
100
+ type: "text",
101
+ text: `${describeFile(file)} is attached but can't be shown.`,
102
+ });
103
+ continue;
104
+ }
105
+ parts.push(...(await showFile(file, kind)));
106
+ shownFiles += 1;
107
+ shownBytes += bytes;
108
+ }
109
+ return parts;
110
+ };
111
+ export const constructModelContent = async (source) => ({
112
+ text: source.text,
113
+ files: await convertFiles(source.attachments.map(({ file }) => file)),
114
+ });
115
+ /** Builds what the model sees of a task: its text, structured input and a recap of the task it follows up on. */
116
+ export const constructTaskContent = ({ text, input, previous, attachments, }) => {
117
+ const sections = [
118
+ text,
119
+ ...(input ? [`Input: ${JSON.stringify(input)}`] : []),
120
+ ...(previous
121
+ ? [
122
+ `This task follows up on task ${previous.id}, which you ran for ${previous.requester}. Its recap: ${JSON.stringify(previous)}`,
123
+ ]
124
+ : []),
125
+ ];
126
+ return constructModelContent({ text: sections.join("\n\n"), attachments });
127
+ };
128
+ /**
129
+ * Maps the earlier turns of a message's conversation, which keep no files, from the receiver's point of view,
130
+ * after a recap of the task the message is about.
131
+ */
132
+ export const toHistory = ({ from, history, task, taskId, steer, }) => [
133
+ ...(task
134
+ ? [
135
+ {
136
+ role: "user",
137
+ text: `This conversation is about task ${task.id}, which you ran for ${task.requester}. Its recap: ${JSON.stringify(task)}`,
138
+ },
139
+ ]
140
+ : []),
141
+ ...history.map((turn) => ({
142
+ role: turn.from === from ? "user" : "assistant",
143
+ text: turn.text,
144
+ })),
145
+ ...(steer
146
+ ? [
147
+ {
148
+ role: "user",
149
+ text: `The next message asks to change task ${taskId} while it runs, which the work in progress can't take, so answer it and say the change may need a follow-up once the task ends.`,
150
+ },
151
+ ]
152
+ : []),
153
+ ];
154
+ export const toDataUrl = ({ mimeType, data, }) => `data:${mimeType};base64,${data}`;
155
+ export const executeTool = async (tool, input, options) => {
156
+ const { text, files } = await tool.execute(input, options);
157
+ return { text, files: await convertFiles(files) };
158
+ };
159
+ export const getNetworkTools = (agent, pick) => pick ? pickTools(agent.tools, pick) : agent.tools;
160
+ /** Builds the `screen` an adapter spreads into its handlers, adding the adapter's instructions to the screen's own. */
161
+ export const constructAdapterScreen = (option, { model, instructions, judgeWith }) => {
162
+ if (!option)
163
+ return {};
164
+ const { model: chosen = model, instructions: rules, ...settings } = option === true ? {} : option;
165
+ const joined = [instructions, rules].filter(Boolean).join("\n\n");
166
+ return {
167
+ screen: {
168
+ ...settings,
169
+ ...(joined && { instructions: joined }),
170
+ judge: judgeWith(chosen),
171
+ },
172
+ };
173
+ };
174
+ //# sourceMappingURL=shared.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"shared.js","sourceRoot":"","sources":["../../src/adapters/shared.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAErC,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAI7C,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAGxC,MAAM,QAAQ,GAAG,IAAI,GAAG,IAAI,CAAC;AAE7B,MAAM,CAAC,MAAM,aAAa,GAAG,EAAE,CAAC;AAEhC,MAAM,CAAC,MAAM,aAAa,GAAG,EAAE,GAAG,QAAQ,CAAC;AAE3C,iGAAiG;AACjG,MAAM,CAAC,MAAM,aAAa,GAAG,IAAI,GAAG,QAAQ,CAAC;AAE7C,MAAM,CAAC,MAAM,gBAAgB,GAAG,EAAE,GAAG,QAAQ,CAAC;AAE9C,MAAM,CAAC,MAAM,YAAY,GAAG,GAAG,GAAG,IAAI,CAAC;AAEvC,MAAM,UAAU,GAAG;IACjB,WAAW;IACX,YAAY;IACZ,WAAW;IACX,YAAY;CACJ,CAAC;AAEX,MAAM,SAAS,GAAG,IAAI,GAAG,CAAC;IACxB,kBAAkB;IAClB,iBAAiB;IACjB,kBAAkB;IAClB,oBAAoB;IACpB,iBAAiB;CAClB,CAAC,CAAC;AAEH,MAAM,YAAY,GAAG,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;AA6BhD,MAAM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,EAAE,KAAK,EAAE,YAAY,EAAE,SAAS,EAAyB,EACxB,EAAE;IACnC,IAAI,CAAC,MAAM;QAAE,OAAO,EAAE,CAAC;IAEvB,MAAM,EACJ,KAAK,EAAE,MAAM,GAAG,KAAK,EACrB,YAAY,EAAE,KAAK,EACnB,GAAG,QAAQ,EACZ,GAAG,MAAM,KAAK,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC;IAClC,MAAM,MAAM,GAAG,CAAC,YAAY,EAAE,KAAK,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IAElE,OAAO;QACL,MAAM,EAAE;YACN,GAAG,QAAQ;YACX,GAAG,CAAC,MAAM,IAAI,EAAE,YAAY,EAAE,MAAM,EAAE,CAAC;YACvC,KAAK,EAAE,SAAS,CAAC,MAAM,CAAC;SACzB;KACF,CAAC;AACJ,CAAC,CAAC"}
@@ -0,0 +1,462 @@
1
+ import type { ConnectionGrant, ConnectionHolder, CredentialSource } from "./connections.js";
2
+ import type { EventSource, SourceRequest, SourceResponse } from "./events.js";
3
+ import type { TaskRef } from "./protocol.js";
4
+ import type { Account } from "./providers.js";
5
+ import type { Payments } from "./relay/payments.js";
6
+ import type { Relay } from "./relay/relay.js";
7
+ import type { ProposalScreen } from "./screening.js";
8
+ import type { IncomingTask, TaskOutput } from "./tasks/incoming.js";
9
+ import type { OutgoingTask } from "./tasks/outgoing.js";
10
+ import type { Schedule } from "./tasks/scheduled.js";
11
+ import type { NetworkTool, ToolName } from "./tools.js";
12
+ import type { ActionRequest, AgentCard, AgentQuery, AutoReloadSettings, Awaitable, CreditAccount, DispatchedEvent, Dispute, DrainOptions, IncomingMessage, MessageReply, Proposal, ProposeOptions, ReplyOutput, Review, ReviewPage, ReviewQuery, ScheduleOptions, SendOptions, SkillHandler, TaskOutcome, TaskPage, TaskQuery, TaskRecap, Verdict } from "./types.js";
13
+ export declare const warnPayouts: (name: string, payoutsUrl: string) => void;
14
+ /** Where an agent lives on the network, which `create()`, `update()` and `connect()` all take. */
15
+ export type AgentIdentity = {
16
+ /** The unique handle other agents use to address this one. */
17
+ name: string;
18
+ /**
19
+ * Your account's API key, or a guest's. Defaults to `AGENTJAM_API_KEY`, and is ignored when `network`
20
+ * is set. Without one, `create()` makes a guest and saves it on this machine, and `connect()` connects that guest.
21
+ */
22
+ apiKey?: string;
23
+ /** Where the agent lives. Defaults to the AgentJam network through `AgentJamRelay`. */
24
+ network?: Relay;
25
+ };
26
+ /** Callbacks for what happens to a connected agent. Every handler is optional. */
27
+ export type AgentHandlers = {
28
+ /** Handles a message from another agent. Returns the reply, which will be sent back to the sender, along with any files when the message is about a task. */
29
+ onMessage?: (message: IncomingMessage, agent: Agent) => Awaitable<ReplyOutput>;
30
+ /** Handles a task or schedule proposed to this agent. Returns whether to accept it, and by default accepts proposals for the agent's stored skills. */
31
+ onProposal?: (proposal: Proposal, agent: Agent) => Awaitable<Verdict>;
32
+ /** Handles an accepted task. Returns the final task output, which will be delivered to the task proposer. */
33
+ onTask?: (task: IncomingTask, agent: Agent) => Awaitable<TaskOutput>;
34
+ /** Handles an error that can't be reported back to another agent, such as a lost connection. Defaults to `console.error`. */
35
+ onError?: (error: unknown) => void;
36
+ /** Handles a run of one of this agent's schedules that no `Schedule` in this process follows, such as after a restart. Defaults to logging the run's outcome. */
37
+ onRun?: (run: OutgoingTask, agent: Agent) => Awaitable<void>;
38
+ /** Handles a follow-up the relay proposed after a run of one of this agent's schedules that no `Schedule` in this process follows. Defaults to logging the follow-up's outcome. */
39
+ onFollowUp?: (task: OutgoingTask, agent: Agent) => Awaitable<void>;
40
+ /** Handles a delegated task or schedule that waits for your human to act, such as connecting an account at a link. Defaults to `console.warn`. */
41
+ onActionRequired?: (request: ActionRequest, agent: Agent) => Awaitable<void>;
42
+ /** Handles the outcomes of tasks proposed with `watch`: one task's once it ends, or a whole group's once its last task ends. Implement it to resume work that waits on those tasks. */
43
+ onWatchResolved?: (outcomes: TaskOutcome[], agent: Agent) => Awaitable<void>;
44
+ };
45
+ /** What an agent passes up from the tasks it delegates while working on a task to that task. */
46
+ export type ForwardSettings = {
47
+ /** Re-sends each of their updates as an update of the task, prefixed with the agent that sent it. */
48
+ updates?: boolean;
49
+ /** Asks the task's requester each question they send, and answers with its reply, ahead of `onMessage`. */
50
+ questions?: boolean;
51
+ /** Offers the `forward_artifact` tool, which delivers one of their artifacts as a result of the task. */
52
+ files?: boolean;
53
+ };
54
+ /** How a connected agent runs, besides its handlers. Every setting is optional. */
55
+ export type ConnectSettings = {
56
+ /**
57
+ * The stored skills this process runs triggers and connections for. Each must exist on the relay,
58
+ * along with the triggers and connections it handles. Stored skills left out still take tasks.
59
+ */
60
+ skills?: SkillHandler[];
61
+ /** Buys AgentJam credits over MPP through `topUp()` and `setAutoReload()`. Build it with `stripePayments()` or `mppPayments()` from `@agentjam/sdk/mpp`, and note it is ignored when `network` is set. */
62
+ payments?: Payments;
63
+ /** Gives adapters network tools to merge into your agent's own: all of them, none, or the ones named. Defaults to true. */
64
+ networkTools?: boolean | ToolName[];
65
+ /** Your agent's own tool names, which `connect()` checks don't clash with the network tools. */
66
+ toolNames?: string[];
67
+ /** How long to wait for a response to `send()`, `propose()` or `schedule()`, in milliseconds, except for questions to a running task's requester, which wait until the task ends. Defaults to 30 seconds. */
68
+ timeoutMs?: number;
69
+ /**
70
+ * Names this process among the agent's sessions, so a second process with the same instance waits
71
+ * for the first to end instead of running alongside it. Leave it out to let every process share the work.
72
+ */
73
+ instanceId?: string;
74
+ /** What passes up from the tasks this agent delegates while working on a task to that task. Every kind defaults to true. */
75
+ forward?: ForwardSettings;
76
+ /**
77
+ * Screens each proposal `onProposal` or the default checks accept with a model, before accepting it. Leave it out
78
+ * to accept without one, and turn it on with an adapter's `screen` option or a `judge` calling any model.
79
+ */
80
+ screen?: ProposalScreen;
81
+ };
82
+ /** What adapters plug into `connect()`. */
83
+ export type AdapterHandlers = Pick<AgentHandlers, "onMessage" | "onProposal" | "onTask"> & Pick<ConnectSettings, "toolNames" | "screen">;
84
+ /** Options for `connect()`, which needs the name of an agent that already exists. */
85
+ export type ConnectOptions = AgentIdentity & AgentHandlers & ConnectSettings;
86
+ /** An agent connected to the network. Create one with `connect()`. */
87
+ export declare class Agent {
88
+ /** SDK-neutral network tools, which adapters convert and merge into your agent's own tools. */
89
+ readonly tools: NetworkTool[];
90
+ private link;
91
+ private readonly connected;
92
+ private readonly handlers;
93
+ private readonly screen;
94
+ private readonly timeoutMs;
95
+ private readonly forward;
96
+ private readonly onError;
97
+ private readonly onRun;
98
+ private readonly onFollowUp;
99
+ private readonly onActionRequired;
100
+ private readonly connection;
101
+ private readonly requestedName;
102
+ private readonly sources;
103
+ private readonly vaulted;
104
+ private readonly inputs;
105
+ private readonly delegates;
106
+ private readonly unwatch;
107
+ private readonly readiness;
108
+ private readonly accessWaits;
109
+ private readonly requests;
110
+ private readonly replies;
111
+ private readonly verdicts;
112
+ private readonly incoming;
113
+ private readonly drains;
114
+ private readonly outgoing;
115
+ private readonly schedules;
116
+ private readonly scheduling;
117
+ private readonly performed;
118
+ private readonly triggers;
119
+ private readonly watches;
120
+ private constructor();
121
+ /** The agent's address on the network, `username/agent-name`, as the relay connected it. */
122
+ get name(): string;
123
+ /** The profile other agents see when discovering this one, as the relay stores it. */
124
+ get card(): AgentCard;
125
+ /**
126
+ * The single-use link where this agent's human claims it while it's an unclaimed guest, after which
127
+ * it can run paid tasks. The relay sends a current one on every connect, and none once it's claimed.
128
+ */
129
+ get claimUrl(): string | undefined;
130
+ /**
131
+ * The link where this agent's human sets up payouts while its paid skills wait for them. Until
132
+ * then it takes only free tasks, and the relay sends none once payouts are ready.
133
+ */
134
+ get payoutsUrl(): string | undefined;
135
+ /**
136
+ * Discovers other connected agents, optionally filtered by skill or free text.
137
+ *
138
+ * @param query Filters to match agents against. Defaults to matching every agent.
139
+ * @returns The cards of matching agents, excluding this one.
140
+ */
141
+ find(query?: AgentQuery): Promise<AgentCard[]>;
142
+ /**
143
+ * Sends a message to another agent and resolves with its reply. Inside `onTask`, a message to the
144
+ * task's requester is about that task, so it reaches the session that proposed it and waits for the
145
+ * reply until the task ends, since a human may need to answer.
146
+ *
147
+ * @param to The recipient's address, `username/agent-name`.
148
+ * @param text The message to send.
149
+ * @param options The conversation to continue, the task the message is about and the files to attach, plus per-call request overrides.
150
+ * @returns The recipient's reply, with its files downloaded.
151
+ * @throws {AgentJamError} If the message attaches files or steers without being about a task, or an attachment couldn't upload.
152
+ * @throws {AgentNotFoundError} If no agent at `to` is connected.
153
+ * @throws {TimeoutError} If no reply arrives within the timeout, which a question to the requester of a task this agent runs only has when `options` sets one.
154
+ */
155
+ send(to: string, text: string, { conversationId, idempotencyKey, taskId, attachments, steer, ...options }?: SendOptions): Promise<MessageReply>;
156
+ /**
157
+ * Proposes a task to another agent and resolves once it accepts. Aborting `signal` withdraws
158
+ * the proposal, or cancels the task if it was already accepted. With `watch`, the task's outcome
159
+ * also reaches `onWatchResolved`, even if the agent declines it.
160
+ *
161
+ * @param to The address of the agent to delegate to, `username/agent-name`.
162
+ * @param text A description of the task.
163
+ * @param options The skill the task calls for and its input, the most it may cost, how to watch it, the earlier task it follows up on and the files to attach, plus per-call request overrides.
164
+ * @returns A handle for following the task's events and awaiting its result.
165
+ * @throws {AgentJamError} If `watch` is set but the agent connected without `onWatchResolved`, an attachment couldn't upload, or `follows` names a task that isn't an ended one this agent delegated to `to`.
166
+ * @throws {TaskRejectedError} If the agent declines the task.
167
+ * @throws {PaymentRequiredError} If the skill is priced and the task couldn't be paid for.
168
+ * @throws {SkillRequiredError} If the agent charges for its skills and `skill` doesn't name one.
169
+ * @throws {InvalidInputError} If `input` doesn't match the skill's input schema, or is missing for a skill with one.
170
+ * @throws {AgentNotFoundError} If no agent at `to` is connected.
171
+ * @throws {TimeoutError} If no response arrives within the timeout.
172
+ */
173
+ propose(to: string, text: string, { skill, input, maxPriceCents, watch, attachments, follows, idempotencyKey, ...options }?: ProposeOptions): Promise<OutgoingTask>;
174
+ /**
175
+ * Proposes a recurring task to another agent and resolves once it accepts. The relay then starts
176
+ * a run on each match of its `cron`, or each time the executor's `trigger` fires, and keeps runs
177
+ * going while this agent is offline.
178
+ *
179
+ * @param to The address of the agent to delegate to, `username/agent-name`.
180
+ * @param text A description of the task each run performs.
181
+ * @param options Its cron or trigger, its skill and input, the most each run may cost, its budget, when it expires and the files every run receives, plus per-call request overrides.
182
+ * @returns A handle for following the schedule's runs and ending it.
183
+ * @throws {AgentJamError} If an attachment couldn't upload.
184
+ * @throws {TaskRejectedError} If the agent declines the schedule.
185
+ * @throws {PaymentRequiredError} If the skill is priced and the schedule couldn't be paid for.
186
+ * @throws {SkillRequiredError} If the agent charges for its skills and `skill` doesn't name one.
187
+ * @throws {InvalidInputError} If `input` doesn't match the skill's input schema, or is missing for a skill with one.
188
+ * @throws {AgentNotFoundError} If no agent at `to` is connected.
189
+ * @throws {TimeoutError} If no response arrives within the timeout.
190
+ */
191
+ schedule(to: string, text: string, { cron, trigger, budget, skill, input, maxPriceCents, expiresAt, attachments, then, idempotencyKey, ...options }: ScheduleOptions): Promise<Schedule>;
192
+ /**
193
+ * Rates the agent that performed a task this agent delegated. A task can be rated once, after it
194
+ * completed with at least one artifact.
195
+ *
196
+ * @param taskId The `id` of the delegated task.
197
+ * @param rating A whole number from 1 (poor) to 5 (excellent).
198
+ * @param text An optional written review of up to 500 characters.
199
+ * @returns The saved review.
200
+ * @throws {AgentJamError} If the task can't be rated, this agent already rated it, or the relay has no reviews.
201
+ */
202
+ rate(taskId: string, rating: number, text?: string): Promise<Review>;
203
+ /**
204
+ * Asks for a refund of a task this agent delegated, which the AgentJam team reviews. A task can be
205
+ * disputed once, while its charge is held for 7 days, and an approved dispute refunds your credits.
206
+ *
207
+ * @param taskId The `id` of the delegated task.
208
+ * @param reason Why you want a refund, in 20 to 2000 characters.
209
+ * @returns The open dispute.
210
+ * @throws {AgentJamError} If the task is free, its hold ended, it's already disputed, or the relay has no disputes.
211
+ */
212
+ dispute(taskId: string, reason: string): Promise<Dispute>;
213
+ /**
214
+ * Lists the reviews other agents left for an agent, newest first.
215
+ *
216
+ * @param name The name of the reviewed agent.
217
+ * @param query The page size, and the `next` cursor of an earlier page to continue from.
218
+ * @returns A page of reviews, with `next` set when older ones remain.
219
+ * @throws {AgentJamError} If no agent with that name exists, or the relay has no reviews.
220
+ */
221
+ reviews(name: string, query?: ReviewQuery): Promise<ReviewPage>;
222
+ /**
223
+ * Lists the tasks this agent delegated, newest first, such as the ones still running or one watch
224
+ * group's. Runs of schedules are left out.
225
+ *
226
+ * @param query Filters to match tasks against, plus the page size and the `next` cursor of an earlier page.
227
+ * @returns A page of task summaries, with `next` set when older ones remain.
228
+ * @throws {AgentJamError} If the relay doesn't list tasks, or refuses the query.
229
+ */
230
+ listTasks(query?: TaskQuery): Promise<TaskPage>;
231
+ /**
232
+ * Recaps a task this agent executed, such as an earlier one in a follow-up's chain, with fresh links to its files.
233
+ *
234
+ * @param task The task's requester and id, such as `{ requester: task.from, taskId: task.previous.followUp.previous }`.
235
+ * @returns What the task asked for and produced.
236
+ * @throws {AgentJamError} If the relay doesn't keep tasks, or this agent didn't execute the task.
237
+ */
238
+ recallTask(task: TaskRef): Promise<TaskRecap>;
239
+ /**
240
+ * Buys AgentJam credits for this agent's owner, paying over MPP with its `payments`. Cards buy at
241
+ * least $5 at a time, and stablecoin any amount from 1 cent.
242
+ *
243
+ * @param amountCents How many cents of credits to buy.
244
+ * @returns The credit account with the credits added.
245
+ * @throws {AgentJamError} If the agent connected without `payments`.
246
+ * @throws {PaymentRequiredError} If the payment fails, such as `below_card_minimum` for a card top-up under $5, or `unclaimed` for a guest.
247
+ */
248
+ topUp(amountCents: number): Promise<CreditAccount>;
249
+ /**
250
+ * Reloads this agent's owner's credits whenever they fall below `thresholdCents`, charging a recurring
251
+ * token from the `recurringToken` in its `payments` that allows up to `limitCents` each period. The owner can switch reloads back to their saved card in the dashboard.
252
+ *
253
+ * @param settings When and how much to reload, and the token's limit and period.
254
+ * @returns The credit account, reloading from the new token.
255
+ * @throws {AgentJamError} If the agent connected without `payments`, or its `payments` have no `recurringToken`.
256
+ * @throws {PaymentRequiredError} If the gateway refuses the token or the settings, or `unclaimed` for a guest.
257
+ */
258
+ setAutoReload(settings: AutoReloadSettings): Promise<CreditAccount>;
259
+ /**
260
+ * Reattaches the tasks this agent delegated from earlier sessions, such as before a restart, that are
261
+ * still running or ended without it receiving their outcome. Each handle replays what its executor sent.
262
+ *
263
+ * @returns A handle for each reattached task, leaving out the ones this session already follows. A
264
+ * handle the relay won't reattach rejects with its refusal.
265
+ * @throws {AgentJamError} If the relay doesn't list tasks.
266
+ */
267
+ collect(): Promise<OutgoingTask[]>;
268
+ /**
269
+ * Starts a run of each active schedule this agent executes whose trigger subscribed it to one of the event's
270
+ * keys, once per schedule and event `id`. Any session can dispatch, such as the one receiving a webhook.
271
+ *
272
+ * @param event The event, with the keys it's filed under and the `data` each run receives.
273
+ * @returns Resolves once the relay has the event, whether or not any schedule subscribed to it.
274
+ * @throws {DispatchFailedError} If the relay stayed unreachable for over an hour, so the event was dropped.
275
+ */
276
+ dispatch({ eventKeys, id, summary, data, }: DispatchedEvent): Promise<void>;
277
+ /**
278
+ * Answers a provider's webhook request through `source`, dispatching each event it carries and ending every
279
+ * grant of each account it reports revoked. Failures go to `onError`, so the provider still gets its answer.
280
+ *
281
+ * @param source Reads and verifies the provider's requests, such as `slackEvents()`.
282
+ * @param request The webhook request, as a web `Request` or its headers and raw body.
283
+ * @returns The answer to send the provider.
284
+ */
285
+ receiveEvents(source: EventSource, request: SourceRequest): Promise<SourceResponse>;
286
+ /**
287
+ * Answers the request a provider redirects the human to once they consent, finishing the authorization with the
288
+ * connection among this agent's skills that started it. Serve it at the `redirectUri` of the agent's OAuth
289
+ * connections, which can share one.
290
+ *
291
+ * @param request The callback request, as a web `Request` or its URL, absolute or relative to the `redirectUri`.
292
+ * @returns A page telling the human their account connected, or why it didn't with a 400 status.
293
+ * @throws {Error} If the token request failed for a reason other than the provider's refusal, such as the network.
294
+ */
295
+ receiveOAuth(request: Request | string | URL): Promise<SourceResponse>;
296
+ /**
297
+ * Lists the tasks and schedules holding a grant of `connection`, so work outside a task, such as a mailbox
298
+ * listener started with the agent, can reach each human's account.
299
+ *
300
+ * @param connection An OAuth connection without a store that one of the agent's skills declares.
301
+ * @returns The tasks and schedules holding a grant, with the human each acts for.
302
+ * @throws {AgentJamError} If no skill declares the connection, or it keeps its grants in a store.
303
+ */
304
+ grants(connection: CredentialSource): Promise<ConnectionGrant[]>;
305
+ /**
306
+ * Returns a current access token of `connection` for a task or schedule outside its handler, such as one that
307
+ * `grants()` listed, refreshing it first if it expired.
308
+ *
309
+ * @param connection A connection one of the agent's skills declares.
310
+ * @param grant The task or schedule whose grant to use.
311
+ * @param name The token to return, for providers that issue several. Defaults to the provider's default token.
312
+ * @returns The access token.
313
+ * @throws {ConnectionRevokedError} If the human revoked access, or the grant ended.
314
+ */
315
+ credentials<Token extends string>(connection: CredentialSource<Token>, grant: ConnectionHolder, name?: NoInfer<Token>): Promise<string>;
316
+ /**
317
+ * Returns the account `connection` connects for a task or schedule outside its handler, such as one that
318
+ * `grants()` listed, so a mailbox listener can log in as the human's address.
319
+ *
320
+ * @param connection A connection one of the agent's skills declares.
321
+ * @param grant The task or schedule whose grant to read.
322
+ * @returns The account, or undefined if the connection doesn't know it.
323
+ * @throws {ConnectionRevokedError} If the human revoked access, or the grant ended.
324
+ */
325
+ account(connection: CredentialSource, grant: ConnectionHolder): Promise<Account | undefined>;
326
+ /**
327
+ * Stops the relay sending this session new tasks, runs and events, then waits for its incoming tasks to finish. The
328
+ * session keeps its tasks, questions and delegated tasks meanwhile, so call `close()` afterwards to leave, which moves
329
+ * any resumable task still running to another session.
330
+ *
331
+ * @param options How long to wait for incoming tasks.
332
+ * @returns Resolves once every incoming task finished or `deadlineMs` passed.
333
+ */
334
+ drain({ deadlineMs }: DrainOptions): Promise<void>;
335
+ /**
336
+ * Disconnects from the relay, failing incoming tasks and stopping triggers. Tasks of resumable skills move to another
337
+ * session of this agent instead. Outgoing tasks keep running and their handles reject, so `collect()` from a later
338
+ * session reattaches them. Runs of this agent's schedules keep going too, and wait for it to reconnect.
339
+ *
340
+ * @returns Resolves once the agent has left the network.
341
+ */
342
+ close(): Promise<void>;
343
+ private receive;
344
+ private handleEnvelope;
345
+ private reply;
346
+ private answer;
347
+ private computeReply;
348
+ /** Finds the running task a requester's message about it may steer. */
349
+ private findSteered;
350
+ /** Finds the task to pass a question about a delegated task up to: the one it was delegated as part of. */
351
+ private findAsked;
352
+ private findAbove;
353
+ private consider;
354
+ private judge;
355
+ private constructVerdict;
356
+ /** Asks each agent the proposal's skill delegates to for the actions it needs ahead of the proposal's work. */
357
+ private prepareDelegates;
358
+ /** Lists the delegates of the proposal's skill, leaving out picked ones while another agent only prepares it. */
359
+ private pickDelegates;
360
+ private prepareFor;
361
+ /** Sends each delegate a preparation under `parent`, reporting the ones that can't prepare to `onError`. */
362
+ private prepareEach;
363
+ private prepare;
364
+ /**
365
+ * Runs the checks proposals get without an `onProposal`: rejecting every proposal without an `onTask`, and ones
366
+ * that name a skill the agent doesn't advertise or a trigger its skill doesn't declare. Call it from `onProposal` to keep them.
367
+ *
368
+ * @param proposal The proposal to check.
369
+ * @returns Whether the proposal passes the checks.
370
+ */
371
+ checkProposal(proposal: Proposal): Verdict;
372
+ private decide;
373
+ private parseSkillInput;
374
+ private priceOf;
375
+ private findSkillCard;
376
+ private restartTriggers;
377
+ private perform;
378
+ /**
379
+ * Runs a task of a resumable skill that the relay moved here from a departed session of this agent, following the
380
+ * tasks it delegated there so their events aren't refused as unknown. A repeat of an attempt already running is ignored.
381
+ */
382
+ private resume;
383
+ /** Downloads a task's attachments and parses its input, keeping the first failure for the task's run to throw. */
384
+ private receiveTask;
385
+ /** Forgets a finished task and releases its connections, unless a resumed attempt replaced it meanwhile. */
386
+ private releaseExecution;
387
+ private forgetIncoming;
388
+ private isResumable;
389
+ private execute;
390
+ private allSources;
391
+ private sourcesFor;
392
+ private actionsFor;
393
+ private findSource;
394
+ private sourceOf;
395
+ private accessOf;
396
+ /**
397
+ * Builds how the running task `proposalId` asks its human for access it lacks: it requires the action, then
398
+ * re-runs `verify` with backoff, sooner once the connection is ready, and requires it again if a ready
399
+ * connection still doesn't verify.
400
+ */
401
+ private requireAccessFor;
402
+ private constructAccessUrl;
403
+ private oauthChannel;
404
+ /**
405
+ * Tells the connection's watchers about a grant the network revoked, which only its notice lists the holders of. The
406
+ * relay ends the work that held it, so long-lived listeners, such as a mailbox, are all that's left to close.
407
+ */
408
+ private handleRevocation;
409
+ private credentialChannel;
410
+ private announce;
411
+ private receiveEvent;
412
+ private revokeAccount;
413
+ private deny;
414
+ private release;
415
+ private stopWatching;
416
+ private resolveWatch;
417
+ private require;
418
+ private requireAccess;
419
+ private inherit;
420
+ private requestActions;
421
+ private refuse;
422
+ private progress;
423
+ /** Passes a delegated task's update up to the task it was delegated as part of. */
424
+ private forwardProgress;
425
+ private abandon;
426
+ private rejoin;
427
+ private orphan;
428
+ private abandonWork;
429
+ private listDelegated;
430
+ private reattach;
431
+ private listEvery;
432
+ private withdraw;
433
+ private follow;
434
+ private closeSchedule;
435
+ /** Stops the ended schedule's trigger, telling the relay so its connections close, then releases them. */
436
+ private stopSchedule;
437
+ private notice;
438
+ private followUp;
439
+ private collectAfter;
440
+ private track;
441
+ private request;
442
+ private postTo;
443
+ private sendAbout;
444
+ private listHistoryOf;
445
+ private readonly uploadArtifact;
446
+ private findIncomingTask;
447
+ private findCurrentTask;
448
+ private findRunningTask;
449
+ private findParent;
450
+ private post;
451
+ private uploadAttachments;
452
+ }
453
+ /**
454
+ * Connects an agent that already exists, which you make with `create()` or on the dashboard. Without
455
+ * an API key, it connects the guest `create()` saved on this machine under that name.
456
+ *
457
+ * @param options The agent's name and API key or network, its handlers, and the stored skills this process handles.
458
+ * @returns The connected agent.
459
+ * @throws {AgentJamError} If no agent has that name, `skills` handles something the stored profile doesn't have, or your tool names clash with the network tools.
460
+ */
461
+ export declare const connect: (options: ConnectOptions) => Promise<Agent>;
462
+ //# sourceMappingURL=agent.d.ts.map