@agentjam/sdk 0.0.0-stage → 0.1.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 +152 -3
package/dist/events.js ADDED
@@ -0,0 +1,24 @@
1
+ const isWebRequest = (request) => "text" in request && typeof request.text === "function";
2
+ const constructHeaders = (headers) => {
3
+ if (headers instanceof Headers)
4
+ return headers;
5
+ return new Headers(Object.entries(headers).flatMap(([name, value]) => value === undefined
6
+ ? []
7
+ : [[name, Array.isArray(value) ? value.join(", ") : value]]));
8
+ };
9
+ /**
10
+ * Reads a webhook request's headers and raw body, whichever shape it came in, for an `EventSource` to verify.
11
+ *
12
+ * @param request A web `Request`, or the headers and raw body a server framework hands over.
13
+ * @returns The request's headers and its body as text.
14
+ */
15
+ export const readSourceRequest = async (request) => {
16
+ if (isWebRequest(request)) {
17
+ return { headers: request.headers, body: await request.text() };
18
+ }
19
+ const body = typeof request.body === "string"
20
+ ? request.body
21
+ : new TextDecoder().decode(request.body);
22
+ return { headers: constructHeaders(request.headers), body };
23
+ };
24
+ //# sourceMappingURL=events.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"events.js","sourceRoot":"","sources":["../src/events.ts"],"names":[],"mappings":"AAkDA,MAAM,YAAY,GAAG,CAAC,OAAsB,EAAsB,EAAE,CAClE,MAAM,IAAI,OAAO,IAAI,OAAO,OAAO,CAAC,IAAI,KAAK,UAAU,CAAC;AAE1D,MAAM,gBAAgB,GAAG,CACvB,OAAgE,EAChE,EAAE;IACF,IAAI,OAAO,YAAY,OAAO;QAAE,OAAO,OAAO,CAAC;IAE/C,OAAO,IAAI,OAAO,CAChB,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,EAAE,KAAK,CAAC,EAAE,EAAE,CAChD,KAAK,KAAK,SAAS;QACjB,CAAC,CAAC,EAAE;QACJ,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAC9D,CACF,CAAC;AACJ,CAAC,CAAC;AAEF;;;;;GAKG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,KAAK,EACpC,OAAsB,EACI,EAAE;IAC5B,IAAI,YAAY,CAAC,OAAO,CAAC,EAAE,CAAC;QAC1B,OAAO,EAAE,OAAO,EAAE,OAAO,CAAC,OAAO,EAAE,IAAI,EAAE,MAAM,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC;IAClE,CAAC;IAED,MAAM,IAAI,GACR,OAAO,OAAO,CAAC,IAAI,KAAK,QAAQ;QAC9B,CAAC,CAAC,OAAO,CAAC,IAAI;QACd,CAAC,CAAC,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IAE7C,OAAO,EAAE,OAAO,EAAE,gBAAgB,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,IAAI,EAAE,CAAC;AAC9D,CAAC,CAAC"}
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Remembers responses by idempotency key, so a repeated request is answered again instead of
3
+ * being handled twice. Entries last until released, then for `window` milliseconds.
4
+ * Invariant: released entries are ordered by release time, so eviction stops at the first young one.
5
+ */
6
+ export declare class IdempotencyCache<T> {
7
+ private readonly window;
8
+ private readonly entries;
9
+ constructor(window: number);
10
+ /** Returns the remembered response for `key`, or remembers the one `respond` produces. */
11
+ remember(key: string, respond: () => Promise<T>): {
12
+ response: Promise<T>;
13
+ repeated: boolean;
14
+ };
15
+ /** Starts the window after which `key` is forgotten. */
16
+ release(key: string): void;
17
+ /** Forgets `key` right away, unless it has since been remembered with a different response. */
18
+ forget(key: string, response: Promise<T>): void;
19
+ private evict;
20
+ }
21
+ //# sourceMappingURL=idempotency.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"idempotency.d.ts","sourceRoot":"","sources":["../src/idempotency.ts"],"names":[],"mappings":"AAKA;;;;GAIG;AACH,qBAAa,gBAAgB,CAAC,CAAC;IAGjB,OAAO,CAAC,QAAQ,CAAC,MAAM;IAFnC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAA+B;IAEvD,YAA6B,MAAM,EAAE,MAAM,EAAI;IAE/C,0FAA0F;IACnF,QAAQ,CACb,GAAG,EAAE,MAAM,EACX,OAAO,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,GACxB;QAAE,QAAQ,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC;QAAC,QAAQ,EAAE,OAAO,CAAA;KAAE,CAS7C;IAED,wDAAwD;IACjD,OAAO,CAAC,GAAG,EAAE,MAAM,QAMzB;IAED,+FAA+F;IACxF,MAAM,CAAC,GAAG,EAAE,MAAM,EAAE,QAAQ,EAAE,OAAO,CAAC,CAAC,CAAC,QAE9C;IAED,OAAO,CAAC,KAAK;CASd"}
@@ -0,0 +1,46 @@
1
+ /**
2
+ * Remembers responses by idempotency key, so a repeated request is answered again instead of
3
+ * being handled twice. Entries last until released, then for `window` milliseconds.
4
+ * Invariant: released entries are ordered by release time, so eviction stops at the first young one.
5
+ */
6
+ export class IdempotencyCache {
7
+ window;
8
+ entries = new Map();
9
+ constructor(window) {
10
+ this.window = window;
11
+ }
12
+ /** Returns the remembered response for `key`, or remembers the one `respond` produces. */
13
+ remember(key, respond) {
14
+ this.evict();
15
+ const entry = this.entries.get(key);
16
+ if (entry)
17
+ return { response: entry.response, repeated: true };
18
+ const response = respond();
19
+ this.entries.set(key, { response });
20
+ return { response, repeated: false };
21
+ }
22
+ /** Starts the window after which `key` is forgotten. */
23
+ release(key) {
24
+ const entry = this.entries.get(key);
25
+ if (!entry)
26
+ return;
27
+ this.entries.delete(key);
28
+ this.entries.set(key, { response: entry.response, releasedAt: Date.now() });
29
+ }
30
+ /** Forgets `key` right away, unless it has since been remembered with a different response. */
31
+ forget(key, response) {
32
+ if (this.entries.get(key)?.response === response)
33
+ this.entries.delete(key);
34
+ }
35
+ evict() {
36
+ const cutoff = Date.now() - this.window;
37
+ for (const [key, { releasedAt }] of this.entries) {
38
+ if (releasedAt === undefined)
39
+ continue;
40
+ if (releasedAt > cutoff)
41
+ return;
42
+ this.entries.delete(key);
43
+ }
44
+ }
45
+ }
46
+ //# sourceMappingURL=idempotency.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"idempotency.js","sourceRoot":"","sources":["../src/idempotency.ts"],"names":[],"mappings":"AAKA;;;;GAIG;AACH,MAAM,OAAO,gBAAgB;IAGE,MAAM;IAFlB,OAAO,GAAG,IAAI,GAAG,EAAoB,CAAC;IAEvD,YAA6B,MAAc;sBAAd,MAAM;IAAW,CAAC;IAE/C,0FAA0F;IACnF,QAAQ,CACb,GAAW,EACX,OAAyB;QAEzB,IAAI,CAAC,KAAK,EAAE,CAAC;QAEb,MAAM,KAAK,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QACpC,IAAI,KAAK;YAAE,OAAO,EAAE,QAAQ,EAAE,KAAK,CAAC,QAAQ,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;QAE/D,MAAM,QAAQ,GAAG,OAAO,EAAE,CAAC;QAC3B,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,EAAE,EAAE,QAAQ,EAAE,CAAC,CAAC;QACpC,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,KAAK,EAAE,CAAC;IACvC,CAAC;IAED,wDAAwD;IACjD,OAAO,CAAC,GAAW;QACxB,MAAM,KAAK,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QACpC,IAAI,CAAC,KAAK;YAAE,OAAO;QAEnB,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;QACzB,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,EAAE,EAAE,QAAQ,EAAE,KAAK,CAAC,QAAQ,EAAE,UAAU,EAAE,IAAI,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC;IAC9E,CAAC;IAED,+FAA+F;IACxF,MAAM,CAAC,GAAW,EAAE,QAAoB;QAC7C,IAAI,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,QAAQ,KAAK,QAAQ;YAAE,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;IAC7E,CAAC;IAEO,KAAK;QACX,MAAM,MAAM,GAAG,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,MAAM,CAAC;QAExC,KAAK,MAAM,CAAC,GAAG,EAAE,EAAE,UAAU,EAAE,CAAC,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC;YACjD,IAAI,UAAU,KAAK,SAAS;gBAAE,SAAS;YACvC,IAAI,UAAU,GAAG,MAAM;gBAAE,OAAO;YAChC,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;QAC3B,CAAC;IACH,CAAC;CACF"}
@@ -0,0 +1,44 @@
1
+ export { connect } from "./agent.js";
2
+ export type { AdapterHandlers, Agent, AgentHandlers, AgentIdentity, ConnectOptions, ConnectSettings, ForwardSettings, } from "./agent.js";
3
+ export { artifact } from "./artifacts.js";
4
+ export type { ArtifactSource } from "./artifacts.js";
5
+ export { attachment } from "./attachments.js";
6
+ export type { AttachmentSource } from "./attachments.js";
7
+ export { oauthConnection } from "./connections.js";
8
+ export type { ConnectionEvent, ConnectionGrant, ConnectionHolder, ConnectionStore, CredentialSource, OAuthConnection, OAuthConnectionOptions, OAuthPresetOptions, OAuthSettings, } from "./connections.js";
9
+ export type { ArtifactOptions, Content, ContentOptions, LabeledContent, } from "./content.js";
10
+ export { computeShortestInterval, isIntervalAtLeast } from "./cron.js";
11
+ export type { IntervalOptions } from "./cron.js";
12
+ export { AgentExistsError, AgentJamError, AgentNotFoundError, ConnectionFailedError, ConnectionRevokedError, DispatchFailedError, FollowUpFailedError, InstanceTakenError, InvalidInputError, PaymentRequiredError, RequestRefusedError, SkillRequiredError, TaskCanceledError, TaskCommittedError, TaskFailedError, TaskRejectedError, TimeoutError, TriggerFailedError, UncoveredCostError, } from "./errors.js";
13
+ export type { PaymentRequiredReason } from "./errors.js";
14
+ export { readSourceRequest } from "./events.js";
15
+ export type { EventSource, ReceivedRequest, SourceDelivery, SourceEvent, SourceRequest, SourceResponse, } from "./events.js";
16
+ export { create, update } from "./profile.js";
17
+ export type { AgentHandle, AgentProfile, CreateOptions, UpdateOptions, } from "./profile.js";
18
+ export type { DelegatedTask, Envelope, EnvelopeDraft, LimitCode, ParentRef, ProposalAction, RecappedArtifactRef, TaskEndCode, TaskRecapRef, TaskRef, } from "./protocol.js";
19
+ export type { Account, AccountRevocation } from "./providers.js";
20
+ export type { Endpoints } from "./relay/endpoints.js";
21
+ export { ReassignedError } from "./relay/frames.js";
22
+ export { MemoryRelay } from "./relay/memory.js";
23
+ export type { MemoryRelayOptions } from "./relay/memory.js";
24
+ export type { Payments } from "./relay/payments.js";
25
+ export type { Connection, CredentialChannel, Relay, SecretGrant, SessionEvents, SessionOptions, } from "./relay/relay.js";
26
+ export { AgentJamRelay } from "./relay/remote.js";
27
+ export type { AgentJamRelayOptions } from "./relay/remote.js";
28
+ export type { SecretStub } from "./relay/secrets.js";
29
+ export { constructScreenRequest, fitSchema, parseFit, screenProposal, } from "./screening.js";
30
+ export type { Fit, FitSchema, Judge, ProposalScreen, ScreenRequest, ScreenSettings, } from "./screening.js";
31
+ export { secretConnection } from "./secrets.js";
32
+ export type { SecretAuthField, SecretConnectionOptions, SecretPresetOptions, } from "./secrets.js";
33
+ export type { AccessOptions } from "./tasks/access.js";
34
+ export { currentTask } from "./tasks/incoming.js";
35
+ export type { IncomingTask, RequesterMessageOptions, TaskMessageOptions, TaskOutput, } from "./tasks/incoming.js";
36
+ export type { OutgoingTask } from "./tasks/outgoing.js";
37
+ export type { Schedule } from "./tasks/scheduled.js";
38
+ export { networkToolNames } from "./tools.js";
39
+ export type { NetworkTool, ToolCallOptions, ToolName, ToolResult, } from "./tools.js";
40
+ export type { ActionRequest, AgentCard, AgentQuery, AgentRating, AllowedRequest, Artifact, Attachment, AutoReload, AutoReloadSettings, Budget, ConnectionCard, ConnectionFetch, ConnectionScopes, CreditAccount, Cron, CustomConnectionSpec, DeclaredConnection, Delegate, DelegatePicker, DispatchedEvent, Dispute, DisputeStatus, DrainOptions, FollowUp, FollowUpCondition, HistoryPage, HistoryQuery, HttpMethod, IncomingMessage, InferInput, InferOutput, InputIssue, InputResult, InputSchema, JsonObject, JsonSchema, Message, MessageReply, MonthSpent, PastTask, Period, Price, ProfileUpdate, Proposal, ProposeOptions, RecappedArtifact, RecappedFile, ReplyOutput, RequestOptions, Review, ReviewDraft, ReviewPage, ReviewQuery, ScheduleFollowUp, ScheduleOptions, SecretAuth, SecretConnection, SendOptions, Skill, SkillCard, SkillConnection, SkillHandler, StopReason, StoredAgent, TaskEvent, TaskInbox, TaskOutcome, TaskPage, TaskQuery, TaskRecap, TaskStatus, TaskSummary, TaskWatch, Trigger, TriggerActivation, TriggerCard, TriggerChoice, TriggerContext, TriggerEvent, TriggerSchedule, Verdict, Visibility, } from "./types.js";
41
+ export { accept, reject } from "./verdicts.js";
42
+ export { MemoryWatermarkStore } from "./watermarks.js";
43
+ export type { WatermarkStore } from "./watermarks.js";
44
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"A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EACV,WAAW,EACX,SAAS,EACT,OAAO,EACP,iBAAiB,EACjB,WAAW,EACX,aAAa,EACb,cAAc,EACd,YAAY,EACZ,eAAe,EACf,OAAO,EACP,UAAU,GACX,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAC/C,OAAO,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AACvD,YAAY,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,18 @@
1
+ export { connect } from "./agent.js";
2
+ export { artifact } from "./artifacts.js";
3
+ export { attachment } from "./attachments.js";
4
+ export { oauthConnection } from "./connections.js";
5
+ export { computeShortestInterval, isIntervalAtLeast } from "./cron.js";
6
+ export { AgentExistsError, AgentJamError, AgentNotFoundError, ConnectionFailedError, ConnectionRevokedError, DispatchFailedError, FollowUpFailedError, InstanceTakenError, InvalidInputError, PaymentRequiredError, RequestRefusedError, SkillRequiredError, TaskCanceledError, TaskCommittedError, TaskFailedError, TaskRejectedError, TimeoutError, TriggerFailedError, UncoveredCostError, } from "./errors.js";
7
+ export { readSourceRequest } from "./events.js";
8
+ export { create, update } from "./profile.js";
9
+ export { ReassignedError } from "./relay/frames.js";
10
+ export { MemoryRelay } from "./relay/memory.js";
11
+ export { AgentJamRelay } from "./relay/remote.js";
12
+ export { constructScreenRequest, fitSchema, parseFit, screenProposal, } from "./screening.js";
13
+ export { secretConnection } from "./secrets.js";
14
+ export { currentTask } from "./tasks/incoming.js";
15
+ export { networkToolNames } from "./tools.js";
16
+ export { accept, reject } from "./verdicts.js";
17
+ export { MemoryWatermarkStore } from "./watermarks.js";
18
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAUrC,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAE1C,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAE9C,OAAO,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAkBnD,OAAO,EAAE,uBAAuB,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC;AAEvE,OAAO,EACL,gBAAgB,EAChB,aAAa,EACb,kBAAkB,EAClB,qBAAqB,EACrB,sBAAsB,EACtB,mBAAmB,EACnB,mBAAmB,EACnB,kBAAkB,EAClB,iBAAiB,EACjB,oBAAoB,EACpB,mBAAmB,EACnB,kBAAkB,EAClB,iBAAiB,EACjB,kBAAkB,EAClB,eAAe,EACf,iBAAiB,EACjB,YAAY,EACZ,kBAAkB,EAClB,kBAAkB,GACnB,MAAM,aAAa,CAAC;AAErB,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAShD,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAqB9C,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAWhD,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAGlD,OAAO,EACL,sBAAsB,EACtB,SAAS,EACT,QAAQ,EACR,cAAc,GACf,MAAM,gBAAgB,CAAC;AASxB,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAOhD,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AASlD,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AA2F9C,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAC/C,OAAO,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAC"}
@@ -0,0 +1,22 @@
1
+ import type { InputSchema, JsonObject, JsonSchema, SkillCard } from "./types.js";
2
+ /** Which of a skill's values a schema describes: its tasks' input or their output. */
3
+ export type SchemaField = "input" | "output";
4
+ /** A task's input or output as its skill's schema parsed it, or why the schema refused it. */
5
+ export type ParsedValue = {
6
+ value: unknown;
7
+ } | {
8
+ problem: string;
9
+ };
10
+ /**
11
+ * Writes a skill's input or output schema as JSON Schema 2020-12, as the relay stores it.
12
+ *
13
+ * @throws {AgentJamError} If the schema can't be written as JSON Schema.
14
+ */
15
+ export declare const toJsonSchema: (skill: string, field: SchemaField, schema: InputSchema) => JsonSchema;
16
+ /** Checks that a skill's input or output schema is the one stored on the relay, regardless of key order. */
17
+ export declare const isStoredSchema: (skill: string, field: SchemaField, schema: InputSchema, stored: JsonSchema | undefined) => boolean;
18
+ /** Parses a task's input or output with its skill's schema, running the refinements and transforms its JSON Schema leaves out. */
19
+ export declare const parseValue: (skill: string, field: SchemaField, schema: InputSchema, value: JsonObject | undefined) => Promise<ParsedValue>;
20
+ /** Describes why a task's output doesn't suit the stored skill it calls for. */
21
+ export declare const outputProblem: (output: JsonObject | undefined, skill: SkillCard | undefined) => string | undefined;
22
+ //# sourceMappingURL=inputs.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"inputs.d.ts","sourceRoot":"","sources":["../src/inputs.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAEV,WAAW,EACX,UAAU,EACV,UAAU,EACV,SAAS,EACV,MAAM,YAAY,CAAC;AAEpB,sFAAsF;AACtF,MAAM,MAAM,WAAW,GAAG,OAAO,GAAG,QAAQ,CAAC;AAE7C,8FAA8F;AAC9F,MAAM,MAAM,WAAW,GAAG;IAAE,KAAK,EAAE,OAAO,CAAA;CAAE,GAAG;IAAE,OAAO,EAAE,MAAM,CAAA;CAAE,CAAC;AAYnE;;;;GAIG;AACH,eAAO,MAAM,YAAY,UAChB,MAAM,SACN,WAAW,UACV,WAAW,KAClB,UAYF,CAAC;AAEF,4GAA4G;AAC5G,eAAO,MAAM,cAAc,UAClB,MAAM,SACN,WAAW,UACV,WAAW,UACX,UAAU,GAAG,SAAS,YACkC,CAAC;AAanE,kIAAkI;AAClI,eAAO,MAAM,UAAU,UACd,MAAM,SACN,WAAW,UACV,WAAW,SACZ,UAAU,GAAG,SAAS,KAC5B,OAAO,CAAC,WAAW,CAWrB,CAAC;AAeF,gFAAgF;AAChF,eAAO,MAAM,aAAa,WAChB,UAAU,GAAG,SAAS,SACvB,SAAS,GAAG,SAAS,uBAkB7B,CAAC"}
package/dist/inputs.js ADDED
@@ -0,0 +1,72 @@
1
+ import addFormats from "ajv-formats";
2
+ import { Ajv2020 } from "ajv/dist/2020.js";
3
+ import { isDeepStrictEqual } from "node:util";
4
+ import { AgentJamError, describeError } from "./errors.js";
5
+ const labels = { input: "Input", output: "Output" };
6
+ const ajv = new Ajv2020({
7
+ addUsedSchema: false,
8
+ strictTypes: false,
9
+ strictTuples: false,
10
+ });
11
+ addFormats.default(ajv);
12
+ /**
13
+ * Writes a skill's input or output schema as JSON Schema 2020-12, as the relay stores it.
14
+ *
15
+ * @throws {AgentJamError} If the schema can't be written as JSON Schema.
16
+ */
17
+ export const toJsonSchema = (skill, field, schema) => {
18
+ try {
19
+ const written = schema["~standard"].jsonSchema.input({
20
+ target: "draft-2020-12",
21
+ });
22
+ return JSON.parse(JSON.stringify(written));
23
+ }
24
+ catch (error) {
25
+ throw new AgentJamError(`The ${field} schema of the "${skill}" skill can't be written as JSON Schema: ${describeError(error)}`);
26
+ }
27
+ };
28
+ /** Checks that a skill's input or output schema is the one stored on the relay, regardless of key order. */
29
+ export const isStoredSchema = (skill, field, schema, stored) => isDeepStrictEqual(toJsonSchema(skill, field, schema), stored);
30
+ const describeIssue = (field, { message, path = [] }) => {
31
+ const keys = path.map((segment) => typeof segment === "object" ? segment.key : segment);
32
+ return `${[field, ...keys].map(String).join("/")}: ${message}`;
33
+ };
34
+ /** Parses a task's input or output with its skill's schema, running the refinements and transforms its JSON Schema leaves out. */
35
+ export const parseValue = async (skill, field, schema, value) => {
36
+ const result = await schema["~standard"].validate(value);
37
+ if (result.issues === undefined)
38
+ return { value: result.value };
39
+ const problems = result.issues
40
+ .map((issue) => describeIssue(field, issue))
41
+ .join("; ");
42
+ return {
43
+ problem: `${labels[field]} for the "${skill}" skill doesn't match its schema: ${problems}`,
44
+ };
45
+ };
46
+ const valueProblem = (schema, value, name) => {
47
+ try {
48
+ const validate = ajv.compile(schema);
49
+ return validate(value)
50
+ ? undefined
51
+ : ajv.errorsText(validate.errors, { dataVar: name });
52
+ }
53
+ finally {
54
+ // WARNING: Ajv caches every compiled schema object, so each one is removed after use to keep memory bounded.
55
+ ajv.removeSchema(schema);
56
+ }
57
+ };
58
+ /** Describes why a task's output doesn't suit the stored skill it calls for. */
59
+ export const outputProblem = (output, skill) => {
60
+ if (output === undefined) {
61
+ return skill?.outputSchema
62
+ ? `The "${skill.name}" skill has an output schema, so its tasks must call setOutput() before they complete`
63
+ : undefined;
64
+ }
65
+ if (!skill?.outputSchema) {
66
+ return "Only a task of a skill with an output schema can set output";
67
+ }
68
+ const problem = valueProblem(skill.outputSchema, output, "output");
69
+ return (problem &&
70
+ `Output for the "${skill.name}" skill doesn't match its schema: ${problem}`);
71
+ };
72
+ //# sourceMappingURL=inputs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"inputs.js","sourceRoot":"","sources":["../src/inputs.ts"],"names":[],"mappings":"AAAA,OAAO,UAAU,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAC3C,OAAO,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC;AAC9C,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAe3D,MAAM,MAAM,GAAG,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAW,CAAC;AAE7D,MAAM,GAAG,GAAG,IAAI,OAAO,CAAC;IACtB,aAAa,EAAE,KAAK;IACpB,WAAW,EAAE,KAAK;IAClB,YAAY,EAAE,KAAK;CACpB,CAAC,CAAC;AAEH,UAAU,CA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,CAAC;IAChB,CAAC;IAED,IAAI,CAAC,KAAK,EAAE,YAAY,EAAE,CAAC;QACzB,OAAO,6DAA6D,CAAC;IACvE,CAAC;IAED,MAAM,OAAO,GAAG,YAAY,CAAC,KAAK,CAAC,YAAY,EAAE,MAAM,EAAE,QAAQ,CAAC,CAAC;IAEnE,OAAO,CACL,OAAO;QACP,mBAAmB,KAAK,CAAC,IAAI,qCAAqC,OAAO,EAAE,CAC5E,CAAC;AACJ,CAAC,CAAC"}
package/dist/mpp.d.ts ADDED
@@ -0,0 +1,76 @@
1
+ import { Method } from "mppx";
2
+ import { tempo } from "mppx/client";
3
+ import type { Payments } from "./relay/payments.js";
4
+ import { type CreateToken } from "./stripe.js";
5
+ import type { Period } from "./types.js";
6
+ export type { CreateToken };
7
+ /** A viem account, or the address of one, that holds USD stablecoin on Tempo, such as from Tempo Wallet, Privy, Kite Passport or AgentCash. */
8
+ export type StablecoinWallet = NonNullable<NonNullable<Parameters<typeof tempo.charge>[0]>["account"]>;
9
+ /** What a recurring token must allow to reload the AgentJam Wallet. */
10
+ export type RecurringTokenRequest = {
11
+ /** The most one period may charge, in cents. */
12
+ amountCents: number;
13
+ /** The currency the token charges in. */
14
+ currency: string;
15
+ /** How often the token's allowance resets. */
16
+ period: Period;
17
+ /** When the token stops being charged, if it ever does. */
18
+ expiresAt: Date | undefined;
19
+ /** The Stripe network business profile the token must be granted to. */
20
+ networkId: string;
21
+ /** What the token pays for, shown to the payer. */
22
+ description: string | undefined;
23
+ };
24
+ /** Issues a recurring Stripe shared payment token, such as through Link, and resolves with its id. */
25
+ export type RecurringToken = (request: RecurringTokenRequest) => Promise<string>;
26
+ /** Options for `mppPayments()`. */
27
+ export type MppOptions = {
28
+ /** Issues a recurring token that reloads the AgentJam Wallet whenever it runs low. */
29
+ recurringToken?: RecurringToken | undefined;
30
+ };
31
+ /** Options for `stablecoinPayments()`. */
32
+ export type StablecoinOptions = {
33
+ /** The wallet that pays for each top-up. */
34
+ account: StablecoinWallet;
35
+ };
36
+ /** Options for `stripePayments()`: a Stripe secret key that issues the tokens, or your own `createToken`. */
37
+ export type StripeOptions = MppOptions & {
38
+ /** The payment method saved on your Stripe account that pays, such as `pm_…`. */
39
+ paymentMethod: string;
40
+ /** A stablecoin wallet that pays instead of the card whenever the gateway takes stablecoin, including for top-ups under $5. */
41
+ wallet?: StablecoinWallet | undefined;
42
+ } & ({
43
+ /** Your Stripe secret or restricted key, which issues a new shared payment token for each top-up. */
44
+ apiKey: string | undefined;
45
+ } | {
46
+ /** Issues a new shared payment token for each top-up instead of the SDK. */
47
+ createToken: CreateToken;
48
+ });
49
+ /**
50
+ * Buys AgentJam credits over MPP, which fill the AgentJam Wallet that pays for tasks. Each payment asks
51
+ * one of `methods` for a new credential, preferring the gateway's order, so `createToken` must return a new token every time.
52
+ *
53
+ * @param methods The mppx client methods that pay, such as `stripe.charge()` or `tempo.charge()` from `mppx/client`.
54
+ * @param options How the wallet gets a recurring token for automatic reloads.
55
+ * @returns The `payments` option for `connect()`.
56
+ */
57
+ export declare const mppPayments: <method extends Method.AnyClient>(methods: method | method[], { recurringToken }?: MppOptions) => Payments;
58
+ /**
59
+ * Buys AgentJam credits over MPP in USD stablecoin on Tempo, which buys any amount from 1 cent.
60
+ * The wallet must hold enough stablecoin to pay each top-up and its network fee.
61
+ *
62
+ * @param options The wallet that pays.
63
+ * @returns The `payments` option for `connect()`.
64
+ */
65
+ export declare const stablecoinPayments: ({ account }: StablecoinOptions) => Payments;
66
+ /**
67
+ * Buys AgentJam credits over MPP with a card saved on your own Stripe account, issuing a new shared
68
+ * payment token for each top-up with your secret key. Pass `createToken` instead of `apiKey` to
69
+ * issue the tokens yourself, such as from a server that keeps the key. Pass a `wallet` to pay in stablecoin wherever the gateway takes it.
70
+ *
71
+ * @param options The payment method, how tokens are issued, an optional stablecoin wallet, and how the wallet gets a recurring token.
72
+ * @returns The `payments` option for `connect()`.
73
+ * @throws {AgentJamError} If `apiKey` is empty or isn't a Stripe secret or restricted key.
74
+ */
75
+ export declare const stripePayments: ({ paymentMethod, wallet, recurringToken, ...issuer }: StripeOptions) => Payments;
76
+ //# sourceMappingURL=mpp.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mpp.d.ts","sourceRoot":"","sources":["../src/mpp.ts"],"names":[],"mappings":"AAAA,OAAO,EAAyB,MAAM,EAAK,MAAM,MAAM,CAAC;AACxD,OAAO,EAAiB,KAAK,EAAE,MAAM,aAAa,CAAC;AAEnD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EAAE,KAAK,WAAW,EAAc,MAAM,aAAa,CAAC;AAC3D,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AAEzC,YAAY,EAAE,WAAW,EAAE,CAAC;AAE5B,+IAA+I;AAC/I,MAAM,MAAM,gBAAgB,GAAG,WAAW,CACxC,WAAW,CAAC,UAAU,CAAC,OAAO,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAC3D,CAAC;AAEF,uEAAuE;AACvE,MAAM,MAAM,qBAAqB,GAAG;IAClC,gDAAgD;IAChD,WAAW,EAAE,MAAM,CAAC;IACpB,yCAAyC;IACzC,QAAQ,EAAE,MAAM,CAAC;IACjB,8CAA8C;IAC9C,MAAM,EAAE,MAAM,CAAC;IACf,2DAA2D;IAC3D,SAAS,EAAE,IAAI,GAAG,SAAS,CAAC;IAC5B,wEAAwE;IACxE,SAAS,EAAE,MAAM,CAAC;IAClB,mDAAmD;IACnD,WAAW,EAAE,MAAM,GAAG,SAAS,CAAC;CACjC,CAAC;AAEF,sGAAsG;AACtG,MAAM,MAAM,cAAc,GAAG,CAC3B,OAAO,EAAE,qBAAqB,KAC3B,OAAO,CAAC,MAAM,CAAC,CAAC;AAErB,mCAAmC;AACnC,MAAM,MAAM,UAAU,GAAG;IACvB,sFAAsF;IACtF,cAAc,CAAC,EAAE,cAAc,GAAG,SAAS,CAAC;CAC7C,CAAC;AAEF,0CAA0C;AAC1C,MAAM,MAAM,iBAAiB,GAAG;IAC9B,4CAA4C;IAC5C,OAAO,EAAE,gBAAgB,CAAC;CAC3B,CAAC;AAEF,6GAA6G;AAC7G,MAAM,MAAM,aAAa,GAAG,UAAU,GAAG;IACvC,iFAAiF;IACjF,aAAa,EAAE,MAAM,CAAC;IACtB,+HAA+H;IAC/H,MAAM,CAAC,EAAE,gBAAgB,GAAG,SAAS,CAAC;CACvC,GAAG,CACE;IACE,qGAAqG;IACrG,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC;CAC5B,GACD;IACE,4EAA4E;IAC5E,WAAW,EAAE,WAAW,CAAC;CAC1B,CACJ,CAAC;AA2FJ;;;;;;;GAOG;AACH,eAAO,MAAM,WAAW,GAAI,MAAM,SAAS,MAAM,CAAC,SAAS,WAChD,MAAM,GAAG,MAAM,EAAE,uBACN,UAAU,KAC7B,QAYF,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,kBAAkB,gBAAiB,iBAAiB,KAAG,QAC5B,CAAC;AAEzC;;;;;;;;GAQG;AACH,eAAO,MAAM,cAAc,yDAKxB,aAAa,KAAG,QAWlB,CAAC"}
package/dist/mpp.js ADDED
@@ -0,0 +1,113 @@
1
+ import { Challenge, Credential, Method, z } from "mppx";
2
+ import { Fetch, stripe, tempo } from "mppx/client";
3
+ import { PaymentRequiredError } from "./errors.js";
4
+ import { issueToken } from "./stripe.js";
5
+ const subscription = Method.from({
6
+ name: "stripe",
7
+ intent: "subscription",
8
+ schema: {
9
+ credential: { payload: z.object({ spt: z.string() }) },
10
+ request: z.object({
11
+ amount: z.string(),
12
+ currency: z.string(),
13
+ periodCount: z.string(),
14
+ periodUnit: z.enum(["day", "week", "month"]),
15
+ subscriptionExpires: z.optional(z.string()),
16
+ methodDetails: z.object({ networkId: z.string() }),
17
+ }),
18
+ },
19
+ });
20
+ const subscribeWith = (recurringToken) => Method.toClient(subscription, {
21
+ createCredential: async ({ challenge }) => {
22
+ const { request, description } = challenge;
23
+ const spt = await recurringToken({
24
+ amountCents: Number(request.amount),
25
+ currency: request.currency,
26
+ period: {
27
+ count: Number(request.periodCount),
28
+ unit: request.periodUnit,
29
+ },
30
+ expiresAt: request.subscriptionExpires
31
+ ? new Date(request.subscriptionExpires)
32
+ : undefined,
33
+ networkId: request.methodDetails.networkId,
34
+ description,
35
+ });
36
+ return Credential.serialize({ challenge, payload: { spt } });
37
+ },
38
+ });
39
+ // Invariant: Tempo amounts are base units of a 6-decimal USD stablecoin, and Stripe amounts are cents.
40
+ const centsOf = ({ method, request }) => {
41
+ const amount = Number(request.amount);
42
+ return method === "tempo" ? amount / 10_000 : amount;
43
+ };
44
+ const unpayable = (offered) => {
45
+ const kinds = [...new Set(offered.map(({ method }) => method))].join(", ");
46
+ return new PaymentRequiredError("payment_failed", `The gateway asks for ${kinds} payments, which none of your payment methods make`);
47
+ };
48
+ const refusing = (methods) => async (input, init) => {
49
+ const response = await globalThis.fetch(input, init);
50
+ if (response.status !== 402)
51
+ return response;
52
+ const offered = Challenge.fromResponseList(response);
53
+ const payable = offered.some(({ method, intent }) => methods.some((client) => client.name === method && client.intent === intent));
54
+ if (offered.length > 0 && !payable)
55
+ throw unpayable(offered);
56
+ return response;
57
+ };
58
+ const paying = (methods, check) => Fetch.from({
59
+ methods,
60
+ fetch: refusing(methods),
61
+ maxPaymentRetries: 1,
62
+ onChallenge: async (challenge, { createCredential }) => {
63
+ check(centsOf(challenge));
64
+ return createCredential();
65
+ },
66
+ });
67
+ const exactly = (amount) => (price) => {
68
+ if (price !== amount) {
69
+ throw new PaymentRequiredError("payment_failed", `The gateway asks for ${price} cents, not the ${amount} you're paying`);
70
+ }
71
+ };
72
+ /**
73
+ * Buys AgentJam credits over MPP, which fill the AgentJam Wallet that pays for tasks. Each payment asks
74
+ * one of `methods` for a new credential, preferring the gateway's order, so `createToken` must return a new token every time.
75
+ *
76
+ * @param methods The mppx client methods that pay, such as `stripe.charge()` or `tempo.charge()` from `mppx/client`.
77
+ * @param options How the wallet gets a recurring token for automatic reloads.
78
+ * @returns The `payments` option for `connect()`.
79
+ */
80
+ export const mppPayments = (methods, { recurringToken } = {}) => {
81
+ const payers = [methods].flat();
82
+ const subscriber = recurringToken && [subscribeWith(recurringToken)];
83
+ return {
84
+ buy: (url, init, amountCents) => paying(payers, exactly(amountCents))(url, init),
85
+ subscribe: subscriber &&
86
+ ((url, init, amountCents) => paying(subscriber, exactly(amountCents))(url, init)),
87
+ };
88
+ };
89
+ /**
90
+ * Buys AgentJam credits over MPP in USD stablecoin on Tempo, which buys any amount from 1 cent.
91
+ * The wallet must hold enough stablecoin to pay each top-up and its network fee.
92
+ *
93
+ * @param options The wallet that pays.
94
+ * @returns The `payments` option for `connect()`.
95
+ */
96
+ export const stablecoinPayments = ({ account }) => mppPayments(tempo.charge({ account }));
97
+ /**
98
+ * Buys AgentJam credits over MPP with a card saved on your own Stripe account, issuing a new shared
99
+ * payment token for each top-up with your secret key. Pass `createToken` instead of `apiKey` to
100
+ * issue the tokens yourself, such as from a server that keeps the key. Pass a `wallet` to pay in stablecoin wherever the gateway takes it.
101
+ *
102
+ * @param options The payment method, how tokens are issued, an optional stablecoin wallet, and how the wallet gets a recurring token.
103
+ * @returns The `payments` option for `connect()`.
104
+ * @throws {AgentJamError} If `apiKey` is empty or isn't a Stripe secret or restricted key.
105
+ */
106
+ export const stripePayments = ({ paymentMethod, wallet, recurringToken, ...issuer }) => {
107
+ const createToken = "apiKey" in issuer
108
+ ? issueToken({ apiKey: issuer.apiKey, paymentMethod })
109
+ : issuer.createToken;
110
+ const card = stripe.charge({ paymentMethod, createToken });
111
+ return mppPayments(wallet ? [tempo.charge({ account: wallet }), card] : card, { recurringToken });
112
+ };
113
+ //# sourceMappingURL=mpp.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mpp.js","sourceRoot":"","sources":["../src/mpp.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,UAAU,EAA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CAAC,MAAM,CAAC,EAAE,OAAO,EAAE,MAAM,EAAE,CAAC,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,EACzD,EAAE,cAAc,EAAE,CACnB,CAAC;AACJ,CAAC,CAAC"}
@@ -0,0 +1,3 @@
1
+ export { constructStandardProfile, parseStandardToken } from "./providers.js";
2
+ export type { OAuthClient, OAuthEndpoints, OAuthProfile, ParsedTokens, TokenError, TokenResponse, Tokens, } from "./providers.js";
3
+ //# sourceMappingURL=oauth.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"oauth.d.ts","sourceRoot":"","sources":["../src/oauth.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AAC9E,YAAY,EACV,WAAW,EACX,cAAc,EACd,YAAY,EACZ,YAAY,EACZ,UAAU,EACV,aAAa,EACb,MAAM,GACP,MAAM,gBAAgB,CAAC"}
package/dist/oauth.js ADDED
@@ -0,0 +1,2 @@
1
+ export { constructStandardProfile, parseStandardToken } from "./providers.js";
2
+ //# sourceMappingURL=oauth.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"oauth.js","sourceRoot":"","sources":["../src/oauth.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=oauthCallbacks.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"oauthCallbacks.d.ts","sourceRoot":"","sources":["../src/oauthCallbacks.ts"],"names":[],"mappings":""}
@@ -0,0 +1,58 @@
1
+ import { UnknownStateError } from "./connections.js";
2
+ import { AgentJamError, ConnectionFailedError } from "./errors.js";
3
+ const htmlEscapes = {
4
+ "&": "&amp;",
5
+ "<": "&lt;",
6
+ ">": "&gt;",
7
+ '"': "&quot;",
8
+ "'": "&#39;",
9
+ };
10
+ const escapeHtml = (text) => text.replaceAll(/[&<>"']/g, (character) => htmlEscapes[character]);
11
+ const constructPage = (status, message, retryUrl) => {
12
+ const retry = retryUrl === undefined
13
+ ? ""
14
+ : `<p><a href="${escapeHtml(retryUrl)}">Try again</a></p>`;
15
+ return {
16
+ status,
17
+ headers: { "content-type": "text/html; charset=utf-8" },
18
+ body: `<!doctype html><html><head><meta charset="utf-8"><title>AgentJam</title></head><body><p>${escapeHtml(message)}</p>${retry}</body></html>`,
19
+ };
20
+ };
21
+ const isOAuthConnection = (source) => "callback" in source && typeof source.callback === "function";
22
+ const relativeBase = "http://callback.invalid";
23
+ /** The provider whose connection minted the callback's `state`, which leads it up to the last `.`. */
24
+ const readStateProvider = (url) => {
25
+ const state = new URL(url, relativeBase).searchParams.get("state") ?? "";
26
+ const dot = state.lastIndexOf(".");
27
+ return dot === -1 ? undefined : state.slice(0, dot);
28
+ };
29
+ /**
30
+ * @internal Finishes the OAuth authorization a callback answers with the connection among `sources` that started it,
31
+ * trying each of the state's provider in turn.
32
+ */
33
+ export const receiveOAuthCallback = async (sources, request) => {
34
+ const url = request instanceof Request ? request.url : request;
35
+ const provider = readStateProvider(url);
36
+ const candidates = sources
37
+ .filter(isOAuthConnection)
38
+ .filter((connection) => connection.provider === provider);
39
+ for (const connection of candidates) {
40
+ try {
41
+ await connection.callback(url);
42
+ return constructPage(200, `Your ${provider} account is connected, so you can close this tab.`);
43
+ }
44
+ catch (error) {
45
+ if (error instanceof UnknownStateError)
46
+ continue;
47
+ if (error instanceof ConnectionFailedError) {
48
+ return constructPage(400, error.message, error.url);
49
+ }
50
+ if (error instanceof AgentJamError) {
51
+ return constructPage(400, error.message);
52
+ }
53
+ throw error;
54
+ }
55
+ }
56
+ return constructPage(400, new UnknownStateError().message);
57
+ };
58
+ //# sourceMappingURL=oauthCallbacks.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"oauthCallbacks.js","sourceRoot":"","sources":["../src/oauthCallbacks.ts"],"names":[],"mappings":"AACA,OAAO,EA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C7D,CAAC,CAAC"}
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Connects a skill to a Datadog organization with an API key and a service account's application key, which the
3
+ * human enters in the platform's form and tasks reach through `connectionFetch()`.
4
+ *
5
+ * @param options The requests the skill may send, and descriptions replacing the defaults of `site`, `apiKey` and `applicationKey`.
6
+ * @returns A connection to list in a skill's `connections`.
7
+ * @throws {AgentJamError} If an allowed request is invalid, or `descriptions` names a field the connection doesn't ask for.
8
+ */
9
+ export declare const datadogConnection: ({ allow, descriptions, }?: import("../secrets.js").SecretPresetOptions<"apiKey" | "applicationKey" | "site">) => import("../types.js").SecretConnection;
10
+ //# sourceMappingURL=datadog.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"datadog.d.ts","sourceRoot":"","sources":["../../src/platforms/datadog.ts"],"names":[],"mappings":"AAEA;;;;;;;GAOG;AACH,eAAO,MAAM,iBAAiB,0JAI5B,CAAC"}
@@ -0,0 +1,15 @@
1
+ import { constructSecretPreset } from "./presets.js";
2
+ /**
3
+ * Connects a skill to a Datadog organization with an API key and a service account's application key, which the
4
+ * human enters in the platform's form and tasks reach through `connectionFetch()`.
5
+ *
6
+ * @param options The requests the skill may send, and descriptions replacing the defaults of `site`, `apiKey` and `applicationKey`.
7
+ * @returns A connection to list in a skill's `connections`.
8
+ * @throws {AgentJamError} If an allowed request is invalid, or `descriptions` names a field the connection doesn't ask for.
9
+ */
10
+ export const datadogConnection = constructSecretPreset("datadog", [
11
+ "site",
12
+ "apiKey",
13
+ "applicationKey",
14
+ ]);
15
+ //# sourceMappingURL=datadog.js.map