@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,474 @@
1
+ import type { Budget, Cron, FollowUp, JsonObject, Message, ScheduleFollowUp, TaskStatus, TaskWatch, TriggerChoice } from "./types.js";
2
+ import type { ConnectionHolder } from "./vaults/vault.js";
3
+ type Routing = {
4
+ /** The sender's idempotency key: a repeated `id` from the same sender is the same envelope. */
5
+ id: string;
6
+ from: string;
7
+ to: string;
8
+ };
9
+ /** A task delegated further down a chain, by its requester and id, and the agent executing it. */
10
+ export type ActionOrigin = {
11
+ requester: string;
12
+ taskId: string;
13
+ executor: string;
14
+ };
15
+ /**
16
+ * Why a task's requester could fund no more of it, such as `reload_failed` once their wallet's auto-reload
17
+ * failed to charge their payment method, whether the relay canceled the task or refused its executor's commit.
18
+ */
19
+ export type LimitCode = "max_price_reached" | "cap_reached" | "insufficient_credits" | "reload_failed";
20
+ /** Why the relay ended a task itself, such as once the task it was part of ended. */
21
+ export type TaskEndCode = "action_expired" | "connection_revoked" | "parent_ended" | LimitCode;
22
+ /** What the requester's human must do before a proposal starts or goes on: connect their account with `provider` at `url`. */
23
+ export type ProposalAction = {
24
+ /** Marks an OAuth connection, or a secret connection whose credential the human enters in a form the platform hosts. */
25
+ kind: "oauth" | "credential_form";
26
+ /** The provider whose account the human connects. */
27
+ provider: string;
28
+ /** Where the human connects their account. */
29
+ url: string;
30
+ /** The task further down the chain that needs the action, when it's copied from one. */
31
+ origin?: ActionOrigin;
32
+ /** What the human must do there, set when the executor said, such as once a running task lost access it needs. */
33
+ reason?: string;
34
+ };
35
+ /** An action of a task further down a chain, copied onto each of the open tasks above it. */
36
+ export type CopiedAction = ProposalAction & {
37
+ status: "pending" | "completed";
38
+ origin: ActionOrigin;
39
+ };
40
+ /**
41
+ * A file attached to a proposal, or to a message about a task or its reply. Senders name only the
42
+ * `attachmentId` of an upload, and relays fill in the rest each time they deliver it.
43
+ */
44
+ export type AttachmentRef = {
45
+ attachmentId: string;
46
+ name?: string;
47
+ mimeType?: string;
48
+ size?: number;
49
+ /** Where to download the file, until the link expires. */
50
+ url?: string;
51
+ };
52
+ /** A task by its requester and id, such as the one a proposal is part of. */
53
+ export type TaskRef = {
54
+ requester: string;
55
+ taskId: string;
56
+ };
57
+ /** The latest artifact under each key of an earlier task, as a relay recaps it. */
58
+ export type RecappedArtifactRef = {
59
+ artifactId: string;
60
+ kind: "text" | "file";
61
+ name?: string;
62
+ mimeType?: string;
63
+ key?: string;
64
+ /** A text artifact's content, cut short when `truncated` is set. */
65
+ text?: string;
66
+ truncated?: boolean;
67
+ /** Where to download a stored file, until the link expires. */
68
+ url?: string;
69
+ size?: number;
70
+ };
71
+ /** What an earlier task asked for and produced, as a relay recaps it for the task's executor. */
72
+ export type TaskRecapRef = {
73
+ taskId: string;
74
+ requester: string;
75
+ text: string;
76
+ skill?: string;
77
+ input?: JsonObject;
78
+ attachments?: AttachmentRef[];
79
+ status: TaskStatus;
80
+ /** Why the task failed, when it did. */
81
+ error?: string;
82
+ /** The task's latest progress updates, oldest first. */
83
+ updates: string[];
84
+ /** The latest artifact under each key and every unkeyed one, newest first. */
85
+ artifacts: RecappedArtifactRef[];
86
+ /** The latest turns of the conversation about the task, oldest first, without their files. */
87
+ history: Message[];
88
+ followUp?: FollowUp;
89
+ createdAt: string;
90
+ endedAt?: string;
91
+ };
92
+ /** What a proposal is part of: the task its sender works on, or for a preparation, the pending schedule it answers. */
93
+ export type ParentRef = {
94
+ kind: "task" | "schedule";
95
+ requester: string;
96
+ id: string;
97
+ };
98
+ /** A task delegated to another agent: the agent running it and the task's id. */
99
+ export type DelegatedTask = {
100
+ to: string;
101
+ id: string;
102
+ };
103
+ type DistributiveOmit<T, K extends PropertyKey> = T extends unknown ? Omit<T, K> : never;
104
+ /**
105
+ * A single frame on the wire between two agents. Relays stamp `from` on every envelope and attach
106
+ * `history` to messages, and otherwise deliver envelopes unchanged, in per-sender order.
107
+ * Invariant: every envelope is JSON-serializable.
108
+ */
109
+ export type Envelope = Routing & ({
110
+ type: "message";
111
+ conversationId: string;
112
+ /** The task the sender and recipient share that this message is about, which pins it to the session working on it. */
113
+ taskId?: string;
114
+ text: string;
115
+ /** The files the sender attaches, which only a message about a task may carry. */
116
+ attachments?: AttachmentRef[];
117
+ /** Marks a requester's message about its running task as a change for the work in progress. */
118
+ steer?: true;
119
+ /** The conversation's earlier answered turns, attached by the relay. */
120
+ history: Message[];
121
+ /** A recap of the task the message is about, attached by the relay when the recipient executes it. */
122
+ task?: TaskRecapRef;
123
+ } | {
124
+ type: "reply";
125
+ replyTo: string;
126
+ text: string;
127
+ /** The files the replier attaches, which only a reply to a message about a task may carry. */
128
+ attachments?: AttachmentRef[];
129
+ } | {
130
+ type: "error";
131
+ replyTo: string;
132
+ error: string;
133
+ } | {
134
+ type: "task.propose";
135
+ text: string;
136
+ skill?: string;
137
+ /** The structured input the relay validates against the skill's input schema. */
138
+ input?: JsonObject;
139
+ /** The most the requester will pay, in cents, which may be a fraction of a cent. */
140
+ maxPriceCents?: number;
141
+ /** Makes the proposal a schedule, which runs the task on each match of the cron after it's accepted. */
142
+ cron?: Cron;
143
+ /** Makes the proposal a schedule, which runs the task each time the executor fires this trigger. */
144
+ trigger?: TriggerChoice;
145
+ /** Caps a schedule's runs each period. */
146
+ budget?: Budget;
147
+ /** A task the relay proposes to another agent after each completed run of the schedule that meets its condition. */
148
+ then?: ScheduleFollowUp;
149
+ /** When a schedule stops running, as an ISO 8601 timestamp. */
150
+ expiresAt?: string;
151
+ /** How the requester follows the task's outcome. */
152
+ watch?: TaskWatch;
153
+ /** The files the requester sends with the proposal. */
154
+ attachments?: AttachmentRef[];
155
+ /** What the relay holds from the requester for a priced task, in cents, set by the relay before delivering it. */
156
+ heldCents?: number;
157
+ /**
158
+ * The task the sender is working on that this proposal is part of. Only a preparation may name a pending
159
+ * schedule instead.
160
+ */
161
+ parent?: ParentRef;
162
+ /**
163
+ * Marks a preparation: a free task under `parent`, a pending schedule or open task the sender executes, that only
164
+ * collects the actions `skill` needs ahead of the parent's work and never runs the skill.
165
+ */
166
+ prepare?: true;
167
+ /** The human whose request started the proposal's chain, as their email or `guest:<agent>`, set by the relay before delivering it. */
168
+ principal?: string;
169
+ /** An ended task the sender requested from the same executor that this one-off proposal follows up on. */
170
+ follows?: string;
171
+ /** A recap of the task named by `follows`, set by the relay before delivering it. */
172
+ previous?: TaskRecapRef;
173
+ /** Marks a task of a resumable skill that the relay moved from a departed session of the executor, set by the relay. */
174
+ resumed?: true;
175
+ /** Which attempt at a resumed task this is, 2 for its first resumption, set by the relay. */
176
+ attempt?: number;
177
+ /** The open tasks a resumed task delegated before it moved, set by the relay. */
178
+ children?: DelegatedTask[];
179
+ }
180
+ /** Accepts the proposal `replyTo`, whose `id` becomes the task's `taskId`. */
181
+ | {
182
+ type: "task.accept";
183
+ replyTo: string;
184
+ }
185
+ /**
186
+ * Accepts the proposal `replyTo` once the requester's human takes every action, each completed by a
187
+ * `connection.ready`. The relay ends the proposal if they don't within an hour.
188
+ */
189
+ | {
190
+ type: "task.require";
191
+ replyTo: string;
192
+ actions: ProposalAction[];
193
+ } | {
194
+ type: "task.reject";
195
+ replyTo: string;
196
+ reason: string;
197
+ } | {
198
+ type: "task.update";
199
+ taskId: string;
200
+ text: string;
201
+ } | {
202
+ type: "task.artifact";
203
+ taskId: string;
204
+ artifactId: string;
205
+ kind: "text" | "file";
206
+ name?: string;
207
+ mimeType?: string;
208
+ /** The stable key a later delivery with the same key replaces this artifact under, sent with every chunk. */
209
+ key?: string;
210
+ /** The key's revision within the task, which relays number from 1 in the order deliveries start. */
211
+ revision?: number;
212
+ chunk: string;
213
+ last: boolean;
214
+ /** The upload holding the whole file, which only a file's empty last chunk may name. */
215
+ uploadId?: string;
216
+ /** Where to download the whole artifact. Relays send it in place of the chunks of a stored file. */
217
+ url?: string;
218
+ }
219
+ /** Sent by the executor of an irreversible skill's task before an action it can't undo, after which the requester can't cancel the task. */
220
+ | {
221
+ type: "task.commit";
222
+ taskId: string;
223
+ /** The task's whole cost so far in cents, which may be a fraction of a cent, for skills priced at cost plus a markup, which caps what it's charged. */
224
+ costCents?: number;
225
+ } | {
226
+ type: "task.complete";
227
+ taskId: string;
228
+ /** What the task cost the executor, in cents, which may be a fraction of a cent, for skills priced at cost plus a markup. */
229
+ costCents?: number;
230
+ /** The task's structured output, which matches its skill's `outputSchema`. */
231
+ output?: JsonObject;
232
+ /** Set by the relay: what the requester was charged for the task, in cents, once its payment settled. */
233
+ chargedCents?: number;
234
+ } | {
235
+ type: "task.fail";
236
+ taskId: string;
237
+ error: string;
238
+ /** Set by the relay when it ends the task itself, such as once its actions expire, a connection is revoked, the task it was part of ended, or its requester can fund no more of it. */
239
+ code?: TaskEndCode;
240
+ /** Set by the executor when the task failed because the relay refused its commit, naming why. */
241
+ uncovered?: LimitCode;
242
+ /** Set by the relay: what the requester was charged for the task, in cents, once its payment settled. */
243
+ chargedCents?: number;
244
+ } | {
245
+ type: "task.cancel";
246
+ taskId: string;
247
+ reason?: string;
248
+ /** Set by the relay when it ends the task itself. */
249
+ code?: TaskEndCode;
250
+ }
251
+ /** Sent by the relay on behalf of `from`, the requester, once what it holds for the cost-plus task `taskId` changed. */
252
+ | {
253
+ type: "task.budget";
254
+ taskId: string;
255
+ heldCents: number;
256
+ }
257
+ /**
258
+ * Sent by the relay on behalf of `from`, the executor, whenever the actions of the open tasks it delegated
259
+ * as part of task `taskId` change, with every one copied onto the task until the task needing it ends.
260
+ */
261
+ | {
262
+ type: "task.actions";
263
+ taskId: string;
264
+ actions: CopiedAction[];
265
+ }
266
+ /**
267
+ * Sent by the relay on behalf of `from` once one of its sessions has left the network. Without
268
+ * `abandoned`, every message, task and schedule proposal with `from` counts as abandoned.
269
+ */
270
+ | {
271
+ type: "disconnect";
272
+ /** The ids of the messages, tasks and schedule proposals that session left unfinished. */
273
+ abandoned?: string[];
274
+ } | {
275
+ type: "schedule.end";
276
+ scheduleId: string;
277
+ reason?: string;
278
+ /** Set by the relay when it ends the schedule itself. */
279
+ code?: "expired" | "payment_failed" | "connection_revoked" | "action_expired";
280
+ }
281
+ /** Sent by the executor once the requester's human connected `provider` for the proposal `proposalId`, completing that action. */
282
+ | {
283
+ type: "connection.ready";
284
+ proposalId: string;
285
+ provider: string;
286
+ /** Set by the relay when it completes a schedule's copy of an action of the preparation `origin`. */
287
+ origin?: ActionOrigin;
288
+ }
289
+ /**
290
+ * Sent by the executor once the running task `proposalId` lacks access it needs, such as a repository the human
291
+ * didn't grant. The task waits on the human to act at `url` until a `connection.ready`, or ends within an hour.
292
+ */
293
+ | {
294
+ type: "connection.required";
295
+ proposalId: string;
296
+ provider: string;
297
+ url: string;
298
+ /** What the human must do at `url`. */
299
+ reason: string;
300
+ }
301
+ /** Sent by the executor once it lost access to `principal`'s `provider` account, which ends every task and schedule the requester delegated for them that uses it. */
302
+ | {
303
+ type: "connection.revoked";
304
+ provider: string;
305
+ principal: string;
306
+ reason?: string;
307
+ /** Set by the relay when it tells the executor the network revoked a grant it held, naming the work that held it. */
308
+ holders?: ConnectionHolder[];
309
+ }
310
+ /** Sent by the relay on behalf of `from`, the requester, once `principal`'s human stored a credential for the secret connection with `provider` that proposal `proposalId` needs. */
311
+ | {
312
+ type: "connection.stored";
313
+ proposalId: string;
314
+ principal: string;
315
+ provider: string;
316
+ }
317
+ /** Sent by the relay on behalf of `from`, the requester, once a trigger schedule `to` executes is active, so its trigger can start. */
318
+ | {
319
+ type: "schedule.start";
320
+ scheduleId: string;
321
+ /** The human whose request started the schedule's chain, set by the relay. */
322
+ principal?: string;
323
+ text: string;
324
+ skill: string;
325
+ trigger: string;
326
+ config: Record<string, unknown>;
327
+ input?: JsonObject;
328
+ expiresAt?: string;
329
+ /** The files the requester sent with the schedule's proposal. */
330
+ attachments?: AttachmentRef[];
331
+ }
332
+ /** Sent by the relay on behalf of `from`, the requester, to the session of `to` that watched trigger schedule `scheduleId` once it hands the schedule to another session, which gets a `schedule.start`. */
333
+ | {
334
+ type: "schedule.handover";
335
+ scheduleId: string;
336
+ }
337
+ /** Sent by the relay on behalf of `from`, the requester, when it gives up on charging for event `eventId` that `to` fired, so no run started. */
338
+ | {
339
+ type: "trigger.failed";
340
+ scheduleId: string;
341
+ eventId: string;
342
+ error: string;
343
+ }
344
+ /** Sent by the relay on behalf of `from`, the follow-up's agent, once run `runId` of schedule `scheduleId` completed and met its follow-up's condition: before it proposes the follow-up `taskId`, or once it couldn't. */
345
+ | ({
346
+ type: "schedule.followup";
347
+ scheduleId: string;
348
+ runId: string;
349
+ skill: string;
350
+ } & ({
351
+ taskId: string;
352
+ error?: undefined;
353
+ } | {
354
+ error: string;
355
+ taskId?: undefined;
356
+ }))
357
+ /** Sent by the relay to both parties when a schedule's run `taskId` starts, `from` the requester `to` the executor. */
358
+ | {
359
+ type: "task.recur";
360
+ scheduleId: string;
361
+ taskId: string;
362
+ /** The run's number, starting from 1. */
363
+ run: number;
364
+ /** The human whose request started the schedule's chain, set by the relay. */
365
+ principal?: string;
366
+ text: string;
367
+ skill?: string;
368
+ input?: JsonObject;
369
+ /** The `id` of the trigger event that started the run. */
370
+ eventId?: string;
371
+ summary?: string;
372
+ /** The trigger event's data, which the relay sends to the executor only. */
373
+ eventData?: JsonObject;
374
+ /** The files the requester sent with the schedule's proposal. */
375
+ attachments?: AttachmentRef[];
376
+ /** What the relay holds from the requester for a priced run, in cents, set by the relay before delivering it to the executor. */
377
+ heldCents?: number;
378
+ });
379
+ /** An envelope the relay handles itself instead of delivering, addressed `to` the other party of the schedule. */
380
+ type RelayDraft = Omit<Routing, "from"> & ({
381
+ type: "collect";
382
+ scheduleId: string;
383
+ /** The run to mark as collected. Without it, collects the schedule's ending. */
384
+ taskId?: string;
385
+ }
386
+ /** Starts a run of the trigger schedule `scheduleId` that `to` requested, once per `eventId`. */
387
+ | {
388
+ type: "trigger.fire";
389
+ scheduleId: string;
390
+ eventId: string;
391
+ summary: string;
392
+ data?: JsonObject;
393
+ }
394
+ /** Subscribes the trigger schedule `scheduleId` that `to` requested to `eventKeys`, replacing the keys it had. */
395
+ | {
396
+ type: "trigger.subscribe";
397
+ scheduleId: string;
398
+ eventKeys: string[];
399
+ }
400
+ /** Reports that the trigger of the ended schedule `scheduleId` that `to` requested stopped, so its connections can close. */
401
+ | {
402
+ type: "trigger.stopped";
403
+ scheduleId: string;
404
+ }
405
+ /** Moves the task `taskId` this agent delegated to `to` to the sending session, which receives everything the task sent so far. */
406
+ | {
407
+ type: "task.reattach";
408
+ taskId: string;
409
+ }
410
+ /** Reports the whole cost so far, in cents, of the cost-plus task `taskId` this agent runs for `to`. */
411
+ | {
412
+ type: "task.cost";
413
+ taskId: string;
414
+ costCents: number;
415
+ });
416
+ /** Starts a run of each active trigger schedule the sender executes that subscribed to one of `eventKeys`, once per schedule and `eventId`. */
417
+ type DispatchDraft = Pick<Routing, "id"> & {
418
+ type: "trigger.dispatch";
419
+ eventKeys: string[];
420
+ eventId: string;
421
+ summary: string;
422
+ data?: JsonObject;
423
+ };
424
+ /** Stops the relay sending the sender's session new tasks, runs and events, while it keeps the work it has. */
425
+ type DrainDraft = Pick<Routing, "id"> & {
426
+ type: "session.drain";
427
+ };
428
+ /** An envelope as an agent sends it, before the relay stamps `from` and attaches `history` and recaps. */
429
+ export type EnvelopeDraft = DistributiveOmit<Envelope, "from" | "history" | "task" | "previous"> | RelayDraft | DispatchDraft | DrainDraft;
430
+ /** A draft addressed `to` another agent, which every draft but a dispatch or drain is. */
431
+ export type AddressedDraft = Exclude<EnvelopeDraft, DispatchDraft | DrainDraft>;
432
+ /** A draft's contents, without the routing fields the sender fills in. */
433
+ export type DraftBody = DistributiveOmit<AddressedDraft, "id" | "to">;
434
+ /** An envelope's contents, without its routing fields. */
435
+ export type Body<T extends Envelope> = DistributiveOmit<T, keyof Routing>;
436
+ /** An envelope answering an earlier request, identified by `replyTo`. */
437
+ export type Reply = Extract<Envelope, {
438
+ replyTo: string;
439
+ }>;
440
+ export type TaskEnvelope = Extract<Envelope, {
441
+ type: "task.update" | "task.artifact" | "task.commit" | "task.complete" | "task.fail";
442
+ }>;
443
+ export type CostReport = Extract<DraftBody, {
444
+ type: "task.cost";
445
+ }>;
446
+ export type ArtifactEnvelope = Extract<Envelope, {
447
+ type: "task.artifact";
448
+ }>;
449
+ export type CancelEnvelope = Extract<Envelope, {
450
+ type: "task.cancel";
451
+ }>;
452
+ export type ScheduleEndEnvelope = Extract<Envelope, {
453
+ type: "schedule.end";
454
+ }>;
455
+ export type ScheduleStartEnvelope = Extract<Envelope, {
456
+ type: "schedule.start";
457
+ }>;
458
+ export type RecurEnvelope = Extract<Envelope, {
459
+ type: "task.recur";
460
+ }>;
461
+ export type FollowUpEnvelope = Extract<Envelope, {
462
+ type: "schedule.followup";
463
+ }>;
464
+ export type RequireEnvelope = Extract<Envelope, {
465
+ type: "task.require";
466
+ }>;
467
+ export type ActionsEnvelope = Extract<Envelope, {
468
+ type: "task.actions";
469
+ }>;
470
+ export type AccessEnvelope = Extract<Envelope, {
471
+ type: "connection.required";
472
+ }>;
473
+ export {};
474
+ //# sourceMappingURL=protocol.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"protocol.d.ts","sourceRoot":"","sources":["../src/protocol.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,MAAM,EACN,IAAI,EACJ,QAAQ,EACR,UAAU,EACV,OAAO,EACP,gBAAgB,EAChB,UAAU,EACV,SAAS,EACT,aAAa,EACd,MAAM,YAAY,CAAC;AACpB,OAAO,KAAK,EAAE,gBAAgB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CAAC;AAE5E,MAAM,MAAM,cAAc,GAAG,OAAO,CAAC,QAAQ,EAAE;IAAE,IAAI,EAAE,aAAa,CAAA;CAAE,CAAC,CAAC;AAExE,MAAM,MAAM,mBAAmB,GAAG,OAAO,CAAC,QAAQ,EAAE;IAAE,IAAI,EAAE,cAAc,CAAA;CAAE,CAAC,CAAC;AAE9E,MAAM,MAAM,qBAAqB,GAAG,OAAO,CACzC,QAAQ,EACR;IAAE,IAAI,EAAE,gBAAgB,CAAA;CAAE,CAC3B,CAAC;AAEF,MAAM,MAAM,aAAa,GAAG,OAAO,CAAC,QAAQ,EAAE;IAAE,IAAI,EAAE,YAAY,CAAA;CAAE,CAAC,CAAC;AAEtE,MAAM,MAAM,gBAAgB,GAAG,OAAO,CAAC,QAAQ,EAAE;IAAE,IAAI,EAAE,mBAAmB,CAAA;CAAE,CAAC,CAAC;AAEhF,MAAM,MAAM,eAAe,GAAG,OAAO,CAAC,QAAQ,EAAE;IAAE,IAAI,EAAE,cAAc,CAAA;CAAE,CAAC,CAAC;AAE1E,MAAM,MAAM,eAAe,GAAG,OAAO,CAAC,QAAQ,EAAE;IAAE,IAAI,EAAE,cAAc,CAAA;CAAE,CAAC,CAAC;AAE1E,MAAM,MAAM,cAAc,GAAG,OAAO,CAAC,QAAQ,EAAE;IAAE,IAAI,EAAE,qBAAqB,CAAA;CAAE,CAAC,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=protocol.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"protocol.js","sourceRoot":"","sources":["../src/protocol.ts"],"names":[],"mappings":""}
@@ -0,0 +1,113 @@
1
+ /** A provider's OAuth 2.0 endpoints, plus extra `params` for its authorization URL. */
2
+ export type OAuthEndpoints = {
3
+ /** The URL where the human grants access. */
4
+ authorize: string;
5
+ /** The URL that exchanges codes and refresh tokens for access tokens. */
6
+ token: string;
7
+ /** The URL that revokes a token, if the provider has one. */
8
+ revoke?: string;
9
+ /** Extra query parameters for the authorization URL. */
10
+ params?: Record<string, string>;
11
+ };
12
+ /** An access token, with the refresh token that renews it if the provider issued one. */
13
+ export type Tokens = {
14
+ accessToken: string;
15
+ refreshToken?: string;
16
+ /** When the access token expires, in milliseconds since the epoch. */
17
+ expiresAt?: number;
18
+ };
19
+ /** The client credentials the provider issued to the executor. */
20
+ export type OAuthClient = {
21
+ clientId: string;
22
+ clientSecret: string;
23
+ };
24
+ /** A token endpoint's JSON response, as the provider sent it. */
25
+ export type TokenResponse = Record<string, unknown>;
26
+ /** Why the provider refused a token request. */
27
+ export type TokenError = {
28
+ /** The provider's error code, such as `invalid_grant`. */
29
+ code: string;
30
+ /** The provider's explanation, if it sent one. */
31
+ description?: string;
32
+ };
33
+ /** The account a grant connects, such as a Slack workspace, which several humans can connect. */
34
+ export type Account = {
35
+ /** The account's id with the provider, such as a workspace id or an email. */
36
+ id: string;
37
+ /** The provider's id for the person who authorized, when several people can connect the same account. */
38
+ subject?: string;
39
+ /** A name for the account a human would recognize. */
40
+ name?: string;
41
+ /** Whatever else the provider's profile reads from the token response, such as a bot's user id. */
42
+ details?: Record<string, unknown>;
43
+ };
44
+ /** An account that lost access with the provider, such as a Slack workspace that uninstalled the app. */
45
+ export type AccountRevocation = {
46
+ /** The account's id with the provider. */
47
+ id: string;
48
+ /** The person whose access ended, or undefined when it ended for everyone who connected the account. */
49
+ subject?: string;
50
+ /** Why access ended, shown to the requesters whose tasks and schedules it ends. */
51
+ reason: string;
52
+ };
53
+ /** The tokens a token response issued. */
54
+ export type ParsedTokens = {
55
+ /** The tokens issued, keyed by name. A provider that issues one token names it `default`. */
56
+ tokens: Record<string, Tokens>;
57
+ /** The scopes granted to each token. A token left out is granted every scope requested for it. */
58
+ scopes?: Record<string, string[]>;
59
+ /** The account the tokens are for, if the response says. */
60
+ account?: Account;
61
+ };
62
+ /**
63
+ * How to run a provider's OAuth 2.0 flow. Each platform's preset, such as `githubConnection()`, runs its own, and
64
+ * `constructStandardProfile()` builds one for any provider that follows the standard, which a spread can adjust.
65
+ */
66
+ export type OAuthProfile = {
67
+ endpoints: OAuthEndpoints;
68
+ /** Whether authorizations send a PKCE challenge and code exchanges its verifier. */
69
+ pkce: boolean;
70
+ /** The token that list-form scopes are requested for, and that `credentials()` returns unless told another. */
71
+ defaultToken: string;
72
+ /** The tokens every human who connects the same account shares, which are revoked only once none of them uses the account. */
73
+ sharedTokens: string[];
74
+ /** Invariant: maps a scope to every scope it implies, including the ones its implied scopes imply. */
75
+ impliedScopes: Record<string, string[]>;
76
+ /** The token error codes that mean the human revoked access or the grant expired. */
77
+ lostGrantErrors: string[];
78
+ /** Returns the authorization URL's query parameters that request each token's `scopes`, plus any the provider needs. */
79
+ constructAuthorizeParams: (scopes: Record<string, string[]>) => Record<string, string>;
80
+ /** Reads the tokens out of a successful token response, keeping `previous` values the response leaves out. */
81
+ parseTokens: (body: TokenResponse, previous?: Record<string, Tokens>) => ParsedTokens;
82
+ /** Returns why the provider refused a token request, or undefined if it succeeded. */
83
+ readError: (response: Response, body: TokenResponse) => TokenError | undefined;
84
+ /** Asks the provider which account `tokens` reach, for a code exchange whose response doesn't name it. */
85
+ fetchAccount?: (tokens: Tokens) => Promise<Account>;
86
+ /** Revokes one of a grant's tokens, and throws if the provider refuses. Resolves without revoking when the provider can't. */
87
+ revokeTokens: (tokens: Tokens, client: OAuthClient) => Promise<void>;
88
+ /** Returns where a human who already connected changes what the executor reaches, such as which repositories, for providers with such a page. */
89
+ constructAccessUrl?: (client: OAuthClient) => string;
90
+ };
91
+ /** The name of the only token a standard provider issues. */
92
+ export declare const defaultToken = "default";
93
+ export declare const postForm: (url: string, form: Record<string, string>, headers?: Record<string, string>) => Promise<Response>;
94
+ export declare const parseScopes: (scope: string) => string[];
95
+ /**
96
+ * Reads an access token, its refresh token and its expiry from a token response's standard fields, such as
97
+ * `access_token`. Custom profiles reuse it for each token a response nests, such as Slack's user token.
98
+ *
99
+ * @param body The token response, or the object nested in it that holds one token.
100
+ * @param previous The token's earlier values, whose refresh token is kept when the response leaves it out.
101
+ * @returns The token.
102
+ * @throws {AgentJamError} If the response has no access token.
103
+ */
104
+ export declare const parseStandardToken: (body: TokenResponse, previous?: Tokens) => Tokens;
105
+ /**
106
+ * Builds the profile of a provider that follows the OAuth 2.0 standard, with PKCE, space-separated scopes and
107
+ * RFC 7009 revocation. Spread it to adjust a hook, such as `{ ...constructStandardProfile(endpoints), pkce: false }`.
108
+ *
109
+ * @param endpoints The provider's endpoints.
110
+ * @returns The provider's profile.
111
+ */
112
+ export declare const constructStandardProfile: (endpoints: OAuthEndpoints) => OAuthProfile;
113
+ //# sourceMappingURL=providers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"providers.d.ts","sourceRoot":"","sources":["../src/providers.ts"],"names":[],"mappings":"AAEA,uFAAuF;AACvF,MAAM,MAAM,cAAc,GAAG;IAC3B,6CAA6C;IAC7C,SAAS,EAAE,MAAM,CAAC;IAClB,yEAAyE;IACzE,KAAK,EAAE,MAAM,CAAC;IACd,6DAA6D;IAC7D,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,wDAAwD;IACxD,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACjC,CAAC;AAEF,yFAAyF;AACzF,MAAM,MAAM,MAAM,GAAG;IACnB,WAAW,EAAE,MAAM,CAAC;IACpB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,sEAAsE;IACtE,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF,kEAAkE;AAClE,MAAM,MAAM,WAAW,GAAG;IAAE,QAAQ,EAAE,MAAM,CAAC;IAAC,YAAY,EAAE,MAAM,CAAA;CAAE,CAAC;AAErE,iEAAiE;AACjE,MAAM,MAAM,aAAa,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAEpD,gDAAgD;AAChD,MAAM,MAAM,UAAU,GAAG;IACvB,0DAA0D;IAC1D,IAAI,EAAE,MAAM,CAAC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