@agentjam/sdk 0.6.0 → 0.8.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 (135) hide show
  1. package/README.md +15 -0
  2. package/dist/agent.d.ts +6 -2
  3. package/dist/agent.d.ts.map +1 -1
  4. package/dist/agent.js +42 -12
  5. package/dist/agent.js.map +1 -1
  6. package/dist/events.d.ts.map +1 -1
  7. package/dist/events.js +27 -0
  8. package/dist/events.js.map +1 -1
  9. package/dist/index.d.ts +3 -2
  10. package/dist/index.d.ts.map +1 -1
  11. package/dist/index.js.map +1 -1
  12. package/dist/inputs.d.ts +3 -1
  13. package/dist/inputs.d.ts.map +1 -1
  14. package/dist/inputs.js +6 -0
  15. package/dist/inputs.js.map +1 -1
  16. package/dist/managedWebhooks.d.ts +15 -0
  17. package/dist/managedWebhooks.d.ts.map +1 -0
  18. package/dist/managedWebhooks.js +115 -0
  19. package/dist/managedWebhooks.js.map +1 -0
  20. package/dist/platforms/atlassian.d.ts +18 -0
  21. package/dist/platforms/atlassian.d.ts.map +1 -0
  22. package/dist/platforms/atlassian.js +24 -0
  23. package/dist/platforms/atlassian.js.map +1 -0
  24. package/dist/platforms/datadog.d.ts +45 -1
  25. package/dist/platforms/datadog.d.ts.map +1 -1
  26. package/dist/platforms/datadog.js +207 -0
  27. package/dist/platforms/datadog.js.map +1 -1
  28. package/dist/platforms/discord.d.ts +64 -16
  29. package/dist/platforms/discord.d.ts.map +1 -1
  30. package/dist/platforms/discord.js +15 -48
  31. package/dist/platforms/discord.js.map +1 -1
  32. package/dist/platforms/discordEvents.d.ts +213 -0
  33. package/dist/platforms/discordEvents.d.ts.map +1 -0
  34. package/dist/platforms/discordEvents.js +270 -0
  35. package/dist/platforms/discordEvents.js.map +1 -0
  36. package/dist/platforms/discordGateway.d.ts +14 -14
  37. package/dist/platforms/discordGateway.d.ts.map +1 -1
  38. package/dist/platforms/discordGateway.js +29 -45
  39. package/dist/platforms/discordGateway.js.map +1 -1
  40. package/dist/platforms/discordInteractions.d.ts +35 -0
  41. package/dist/platforms/discordInteractions.d.ts.map +1 -0
  42. package/dist/platforms/discordInteractions.js +125 -0
  43. package/dist/platforms/discordInteractions.js.map +1 -0
  44. package/dist/platforms/github.d.ts +45 -13
  45. package/dist/platforms/github.d.ts.map +1 -1
  46. package/dist/platforms/github.js +20 -40
  47. package/dist/platforms/github.js.map +1 -1
  48. package/dist/platforms/githubApi.d.ts +2 -0
  49. package/dist/platforms/githubApi.d.ts.map +1 -0
  50. package/dist/platforms/githubApi.js +38 -0
  51. package/dist/platforms/githubApi.js.map +1 -0
  52. package/dist/platforms/githubEvents.d.ts +160 -0
  53. package/dist/platforms/githubEvents.d.ts.map +1 -0
  54. package/dist/platforms/githubEvents.js +446 -0
  55. package/dist/platforms/githubEvents.js.map +1 -0
  56. package/dist/platforms/grafana.d.ts +47 -1
  57. package/dist/platforms/grafana.d.ts.map +1 -1
  58. package/dist/platforms/grafana.js +187 -0
  59. package/dist/platforms/grafana.js.map +1 -1
  60. package/dist/platforms/pagerduty.d.ts +59 -0
  61. package/dist/platforms/pagerduty.d.ts.map +1 -0
  62. package/dist/platforms/pagerduty.js +175 -0
  63. package/dist/platforms/pagerduty.js.map +1 -0
  64. package/dist/platforms/sentry.d.ts +35 -17
  65. package/dist/platforms/sentry.d.ts.map +1 -1
  66. package/dist/platforms/sentry.js +48 -25
  67. package/dist/platforms/sentry.js.map +1 -1
  68. package/dist/platforms/sentryApi.d.ts +3 -0
  69. package/dist/platforms/sentryApi.d.ts.map +1 -0
  70. package/dist/platforms/sentryApi.js +29 -0
  71. package/dist/platforms/sentryApi.js.map +1 -0
  72. package/dist/platforms/sentryEvents.d.ts +64 -0
  73. package/dist/platforms/sentryEvents.d.ts.map +1 -0
  74. package/dist/platforms/sentryEvents.js +183 -0
  75. package/dist/platforms/sentryEvents.js.map +1 -0
  76. package/dist/platforms/slack.d.ts +69 -33
  77. package/dist/platforms/slack.d.ts.map +1 -1
  78. package/dist/platforms/slack.js +29 -36
  79. package/dist/platforms/slack.js.map +1 -1
  80. package/dist/platforms/slackEvents.d.ts +204 -0
  81. package/dist/platforms/slackEvents.d.ts.map +1 -0
  82. package/dist/platforms/slackEvents.js +241 -0
  83. package/dist/platforms/slackEvents.js.map +1 -0
  84. package/dist/platforms/slackInteractions.d.ts +79 -0
  85. package/dist/platforms/slackInteractions.d.ts.map +1 -0
  86. package/dist/platforms/slackInteractions.js +160 -0
  87. package/dist/platforms/slackInteractions.js.map +1 -0
  88. package/dist/profile.d.ts +2 -1
  89. package/dist/profile.d.ts.map +1 -1
  90. package/dist/profile.js +9 -6
  91. package/dist/profile.js.map +1 -1
  92. package/dist/protocol.d.ts +21 -0
  93. package/dist/protocol.d.ts.map +1 -1
  94. package/dist/relay/memory.d.ts +5 -1
  95. package/dist/relay/memory.d.ts.map +1 -1
  96. package/dist/relay/memory.js +27 -4
  97. package/dist/relay/memory.js.map +1 -1
  98. package/dist/relay/schedules.d.ts +32 -1
  99. package/dist/relay/schedules.d.ts.map +1 -1
  100. package/dist/relay/schedules.js +17 -0
  101. package/dist/relay/schedules.js.map +1 -1
  102. package/dist/relay/sessions.d.ts +2 -0
  103. package/dist/relay/sessions.d.ts.map +1 -1
  104. package/dist/relay/sessions.js +13 -0
  105. package/dist/relay/sessions.js.map +1 -1
  106. package/dist/relay/subscriptions.d.ts +35 -0
  107. package/dist/relay/subscriptions.d.ts.map +1 -0
  108. package/dist/relay/subscriptions.js +95 -0
  109. package/dist/relay/subscriptions.js.map +1 -0
  110. package/dist/subscriptions.d.ts +9 -0
  111. package/dist/subscriptions.d.ts.map +1 -0
  112. package/dist/subscriptions.js +39 -0
  113. package/dist/subscriptions.js.map +1 -0
  114. package/dist/tasks/incoming.d.ts +20 -2
  115. package/dist/tasks/incoming.d.ts.map +1 -1
  116. package/dist/tasks/incoming.js +35 -3
  117. package/dist/tasks/incoming.js.map +1 -1
  118. package/dist/tasks/outgoing.d.ts +15 -0
  119. package/dist/tasks/outgoing.d.ts.map +1 -1
  120. package/dist/tasks/outgoing.js +17 -2
  121. package/dist/tasks/outgoing.js.map +1 -1
  122. package/dist/tasks/scheduled.d.ts +30 -5
  123. package/dist/tasks/scheduled.d.ts.map +1 -1
  124. package/dist/tasks/scheduled.js +14 -3
  125. package/dist/tasks/scheduled.js.map +1 -1
  126. package/dist/tools/network.d.ts.map +1 -1
  127. package/dist/tools/network.js +20 -7
  128. package/dist/tools/network.js.map +1 -1
  129. package/dist/tools/schedules.d.ts +21 -4
  130. package/dist/tools/schedules.d.ts.map +1 -1
  131. package/dist/tools/schedules.js +39 -8
  132. package/dist/tools/schedules.js.map +1 -1
  133. package/dist/types.d.ts +27 -2
  134. package/dist/types.d.ts.map +1 -1
  135. package/package.json +9 -1
@@ -1,8 +1,11 @@
1
- import { AgentJamError } from "../errors.js";
1
+ import { createHmac, timingSafeEqual } from "node:crypto";
2
+ import { readSourceRequest } from "../events.js";
2
3
  import { constructIntervalProperty, pollSchedule, truncateSummary, } from "../polling.js";
3
4
  import { constructStandardProfile } from "../providers.js";
4
5
  import { MemoryWatermarkStore } from "../watermarks.js";
5
6
  import { constructOAuthPreset } from "./presets.js";
7
+ import { organizationProperty, regionProperty, requestSentry, slugPattern, } from "./sentryApi.js";
8
+ import { constructWebhookTriggers, readSentryWebhook } from "./sentryEvents.js";
6
9
  /** How to run Sentry's OAuth flow, which follows the standard. */
7
10
  export const sentryProfile = constructStandardProfile({
8
11
  authorize: "https://sentry.io/oauth/authorize/",
@@ -18,7 +21,6 @@ export const sentryProfile = constructStandardProfile({
18
21
  * @throws {AgentJamError} If a client setting is neither passed nor set in the environment.
19
22
  */
20
23
  export const sentryConnection = (options) => constructOAuthPreset({ provider: "sentry", profile: sentryProfile, prefix: "SENTRY" }, options);
21
- const slugPattern = "^[a-z0-9][a-z0-9_-]*$";
22
24
  const issuesPageSize = 100;
23
25
  const overlapMs = 2 * 60_000;
24
26
  const listNewIssues = async (token, { region = "us", organization, project }, firstSeenAfter) => {
@@ -27,14 +29,7 @@ const listNewIssues = async (token, { region = "us", organization, project }, fi
27
29
  sort: "new",
28
30
  limit: String(issuesPageSize),
29
31
  });
30
- const path = `/api/0/projects/${organization}/${project}/issues/?${query.toString()}`;
31
- const response = await fetch(new URL(path, `https://${region}.sentry.io`), {
32
- headers: { accept: "application/json", authorization: `Bearer ${token}` },
33
- });
34
- if (!response.ok) {
35
- throw new AgentJamError(`Sentry answered ${response.status} for ${path}: ${await response.text()}`);
36
- }
37
- return (await response.json());
32
+ return requestSentry(token, region, `/api/0/projects/${organization}/${project}/issues/?${query.toString()}`);
38
33
  };
39
34
  const constructErrorEvent = ({ region = "us", organization, project }, issue) => {
40
35
  const data = {
@@ -81,33 +76,61 @@ const watchProject = ({ connection, watermarks, pollIntervalMinutes, onError, })
81
76
  poll,
82
77
  });
83
78
  };
79
+ const isSigned = (secret, headers, body) => {
80
+ const expected = Buffer.from(createHmac("sha256", secret).update(body).digest("hex"));
81
+ const signature = Buffer.from(headers.get("sentry-hook-signature") ?? "");
82
+ return (signature.length === expected.length && timingSafeEqual(signature, expected));
83
+ };
84
84
  /**
85
- * Triggers that run a schedule on a Sentry project's errors, for a skill whose connections include `connection`,
86
- * with the `event:read`, `project:read` and `org:read` scopes. Each schedule polls with its token from where
87
- * `watermarks` says it left off.
85
+ * Reads the webhooks of your Sentry integration, for `agent.receiveEvents()` at its webhook URL. It verifies each
86
+ * request's `Sentry-Hook-Signature` in constant time, and reads it under the keys the webhook triggers of
87
+ * `sentryTriggers()` subscribe to.
88
+ *
89
+ * @param options The integration's client secret.
90
+ * @returns An event source for Sentry's webhooks.
91
+ */
92
+ export const sentryWebhooks = ({ secret, }) => ({
93
+ receive: async (request) => {
94
+ const { headers, body } = await readSourceRequest(request);
95
+ if (!isSigned(secret, headers, body)) {
96
+ return {
97
+ response: { status: 401, body: "Invalid Sentry signature" },
98
+ events: [],
99
+ };
100
+ }
101
+ const resource = headers.get("sentry-hook-resource") ?? "";
102
+ const requestId = headers.get("request-id");
103
+ const payload = JSON.parse(body);
104
+ return {
105
+ response: { status: 200 },
106
+ events: requestId === null
107
+ ? []
108
+ : readSentryWebhook(resource, requestId, payload),
109
+ };
110
+ },
111
+ });
112
+ /**
113
+ * Triggers that run a schedule on a Sentry organization's activity, for a skill whose connections include
114
+ * `connection`, with the `event:read`, `project:read` and `org:read` scopes. `error_reported` polls with the
115
+ * schedule's token from where `watermarks` says it left off, while the trigger named after each webhook resource,
116
+ * such as `issue`, runs on the webhooks `sentryWebhooks()` reads from the organization's install of `integration`.
88
117
  *
89
118
  * @param connection The skill's Sentry connection.
90
- * @param options Where polls keep their progress, and how often they run.
91
- * @returns The `error_reported` trigger, for a skill's `triggers`.
119
+ * @param options Where polls keep their progress, how often they run, and your Sentry integration's slug.
120
+ * @returns The `error_reported` trigger, and one per webhook resource, for a skill's `triggers`.
92
121
  */
93
- export const sentryTriggers = (connection, { watermarks = new MemoryWatermarkStore(), pollIntervalMinutes = 1, onError = console.error, } = {}) => {
122
+ export const sentryTriggers = (connection, { watermarks = new MemoryWatermarkStore(), pollIntervalMinutes = 1, onError = console.error, integration, } = {}) => {
94
123
  const polling = { connection, watermarks, pollIntervalMinutes, onError };
95
124
  return {
125
+ ...constructWebhookTriggers(connection, integration),
96
126
  /** A new unresolved issue in `config.project`, once per issue, which an issue that regresses after it's resolved doesn't repeat. */
97
127
  error_reported: {
98
128
  description: "Sentry sees a new unresolved issue in a project",
99
129
  config: {
100
130
  type: "object",
101
131
  properties: {
102
- region: {
103
- enum: ["us", "de"],
104
- description: "The Sentry region the organization's data lives in. Defaults to us",
105
- },
106
- organization: {
107
- type: "string",
108
- pattern: slugPattern,
109
- description: "The Sentry organization's slug",
110
- },
132
+ region: regionProperty,
133
+ organization: organizationProperty,
111
134
  project: {
112
135
  type: "string",
113
136
  pattern: slugPattern,
@@ -1 +1 @@
1
- {"version":3,"file":"sentry.js","sourceRoot":"","sources":["../../src/platforms/sentry.ts"],"names":[],"mappings":"AAKA,OAAO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,EACJ,SAAS,KAAK,IAAI;gBAChB,CAAC,CAAC,EAAE;gBACJ,CAAC,CAAC,iBAAiB,CAAC,QAAQ,EAAE,SAAS,EAAE,OAAO,CAAC;SACtD,CAAC;IACJ,CAAC;CACF,CAAC,CAAC;AAEH;;;;;;;;;GASG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,CAC5B,UAA4B,EAC5B,EACE,UAAU,GAAG,IAAI,oBAAoB,EAAE,EACvC,mBAAmB,GAAG,CAAC,EACvB,OAAO,GAAG,OAAO,CAAC,KAAK,EACvB,WAAW,GACZ,GAAwB,EAAE,EAC3B,EAAE;IACF,MAAM,OAAO,GAAG,EAAE,UAAU,EAAE,UAAU,EAAE,mBAAmB,EAAE,OAAO,EAAE,CAAC;IAEzE,OAAO;QACL,GAAG,wBAAwB,CAAC,UAAU,EAAE,WAAW,CAAC;QACpD,oIAAoI;QACpI,cAAc,EAAE;YACd,WAAW,EAAE,iDAAiD;YAC9D,MAAM,EAAE;gBACN,IAAI,EAAE,QAAQ;gBACd,UAAU,EAAE;oBACV,MAAM,EAAE,cAAc;oBACtB,YAAY,EAAE,oBAAoB;oBAClC,OAAO,EAAE;wBACP,IAAI,EAAE,QAAQ;wBACd,OAAO,EAAE,WAAW;wBACpB,WAAW,EAAE,yCAAyC;qBACvD;oBACD,mBAAmB,EAAE,yBAAyB,CAAC,YAAY,CAAC;iBAC7D;gBACD,QAAQ,EAAE,CAAC,cAAc,EAAE,SAAS,CAAC;aACtC;YACD,gBAAgB,EAAE,YAAY,CAAC,OAAO,CAAC;SACxC;KACgC,CAAC;AACtC,CAAC,CAAC"}
@@ -0,0 +1,3 @@
1
+ /** The Sentry region an organization's data lives in, which picks its API's host. */
2
+ export type SentryRegion = "us" | "de";
3
+ //# sourceMappingURL=sentryApi.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sentryApi.d.ts","sourceRoot":"","sources":["../../src/platforms/sentryApi.ts"],"names":[],"mappings":"AAGA,qFAAqF;AACrF,MAAM,MAAM,YAAY,GAAG,IAAI,GAAG,IAAI,CAAC"}
@@ -0,0 +1,29 @@
1
+ import { AgentJamError } from "../errors.js";
2
+ /** @internal The pattern of a Sentry organization's or project's slug. */
3
+ export const slugPattern = "^[a-z0-9][a-z0-9_-]*$";
4
+ /** @internal The config property naming the region a schedule's organization lives in. */
5
+ export const regionProperty = {
6
+ enum: ["us", "de"],
7
+ description: "The Sentry region the organization's data lives in. Defaults to us",
8
+ };
9
+ /** @internal The config property naming a schedule's Sentry organization. */
10
+ export const organizationProperty = {
11
+ type: "string",
12
+ pattern: slugPattern,
13
+ description: "The Sentry organization's slug",
14
+ };
15
+ /**
16
+ * @internal Asks Sentry's API in `region` for `path` with `token`.
17
+ *
18
+ * @throws {AgentJamError} If Sentry refuses the request.
19
+ */
20
+ export const requestSentry = async (token, region, path) => {
21
+ const response = await fetch(new URL(path, `https://${region}.sentry.io`), {
22
+ headers: { accept: "application/json", authorization: `Bearer ${token}` },
23
+ });
24
+ if (!response.ok) {
25
+ throw new AgentJamError(`Sentry answered ${response.status} for ${path}: ${await response.text()}`);
26
+ }
27
+ return (await response.json());
28
+ };
29
+ //# sourceMappingURL=sentryApi.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sentryApi.js","sourceRoot":"","sources":["../../src/platforms/sentryApi.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAM7C,0EAA0E;AAC1E,MAAM,CAAC,MAAM,WAAW,GAAG,uBAAuB,CAAC;AAEnD,0FAA0F;AAC1F,MAAM,CAAC,MAAM,cAAc,GAAe;IACxC,IAAI,EAAE,CAAC,IAAI,EAAE,IAAI,CAAC;IAClB,WAAW,EACT,oEAAoE;CACvE,CAAC;AAEF,6EAA6E;AAC7E,MAAM,CAAC,MAAM,oBAAoB,GAAe;IAC9C,IAAI,EAAE,QAAQ;IACd,OAAO,EAAE,WAAW;IACpB,WAAW,EAAE,gCAAgC;CAC9C,CAAC;AAEF;;;;GAIG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,KAAK,EAChC,KAAa,EACb,MAAoB,EACpB,IAAY,EACG,EAAE;IACjB,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,IAAI,GAAG,CAAC,IAAI,EAAE,WAAW,MAAM,YAAY,CAAC,EAAE;QACzE,OAAO,EAAE,EAAE,MAAM,EAAE,kBAAkB,EAAE,aAAa,EAAE,UAAU,KAAK,EAAE,EAAE;KAC1E,CAAC,CAAC;IAEH,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC;QACjB,MAAM,IAAI,aAAa,CACrB,mBAAmB,QAAQ,CAAC,MAAM,QAAQ,IAAI,KAAK,MAAM,QAAQ,CAAC,IAAI,EAAE,EAAE,CAC3E,CAAC;IACJ,CAAC;IAED,OAAO,CAAC,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAS,CAAC;AACzC,CAAC,CAAC"}
@@ -0,0 +1,64 @@
1
+ import type { JsonObject } from "../types.js";
2
+ type DataReader<Value> = (data: JsonObject) => Value;
3
+ declare const readIssueSubject: (data: JsonObject) => string | undefined;
4
+ declare const sentryResources: {
5
+ readonly issue: {
6
+ readonly description: "A Sentry issue is created, resolved, assigned, archived, or unresolved";
7
+ readonly actions: readonly ["created", "resolved", "assigned", "archived", "unresolved"];
8
+ readonly reference: "slug";
9
+ readonly readProjects: DataReader<string[]>;
10
+ readonly readSubject: typeof readIssueSubject;
11
+ readonly item: "issue";
12
+ };
13
+ readonly error: {
14
+ readonly description: "Sentry receives an error event, in an organization on a Business or Enterprise plan";
15
+ readonly actions: readonly ["created"];
16
+ readonly reference: "id";
17
+ readonly readProjects: DataReader<string[]>;
18
+ readonly readSubject: DataReader<string | undefined>;
19
+ readonly item: "error";
20
+ };
21
+ readonly comment: {
22
+ readonly description: "A comment on a Sentry issue is created, updated, or deleted";
23
+ readonly actions: readonly ["created", "updated", "deleted"];
24
+ readonly reference: "slug";
25
+ readonly readProjects: DataReader<string[]>;
26
+ readonly readSubject: DataReader<string | undefined>;
27
+ };
28
+ readonly event_alert: {
29
+ readonly description: "A Sentry issue alert that notifies the integration fires";
30
+ readonly actions: readonly ["triggered"];
31
+ readonly reference: "id";
32
+ readonly readProjects: DataReader<string[]>;
33
+ readonly readSubject: DataReader<string | undefined>;
34
+ readonly item: "event";
35
+ };
36
+ readonly metric_alert: {
37
+ readonly description: "A Sentry metric alert that notifies the integration turns critical or warning, or resolves";
38
+ readonly actions: readonly ["critical", "warning", "resolved"];
39
+ readonly reference: "slug";
40
+ readonly readProjects: DataReader<string[]>;
41
+ readonly readSubject: DataReader<string | undefined>;
42
+ readonly item: "metric_alert";
43
+ };
44
+ };
45
+ /** A Sentry webhook resource that `sentryTriggers()` has a trigger for, such as `issue`. */
46
+ export type SentryResourceName = keyof typeof sentryResources;
47
+ /** A Sentry webhook, as the `task.event.data` of a run of one of the webhook triggers `sentryTriggers()` returns. */
48
+ export type SentryEventData = {
49
+ resource: SentryResourceName;
50
+ /** What happened, such as `created`. */
51
+ action: string;
52
+ /** The webhook request's `Request-ID`. */
53
+ requestId: string;
54
+ /** The uuid of the integration's installation in the organization. */
55
+ installation: string;
56
+ /** The name of the user or integration that caused the webhook, or `Sentry` for what Sentry did itself. */
57
+ actor: string | null;
58
+ /** The webhook's `data`, without the fields `omitted` names. */
59
+ data: JsonObject;
60
+ /** The fields of the resource left out of a webhook over 64 KB, largest first. */
61
+ omitted?: string[];
62
+ };
63
+ export {};
64
+ //# sourceMappingURL=sentryEvents.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sentryEvents.d.ts","sourceRoot":"","sources":["../../src/platforms/sentryEvents.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,UAAU,EAAW,MAAM,aAAa,CAAC;AASvD,KAAK,UAAU,CAAC,KAAK,IAAI,CAAC,IAAI,EAAE,UAAU,KAAK,KAAK,CAAC;AAoDrD,QAAA,MAAM,gBAAgB,SAAU,UAAU,uBAOzC,CAAC;AAEF,QAAA,MAAM,eAAe;;iBAEjB,WAAW,EACT,wEAAwE;iBAC1E,OAAO;iBACP,SAAS,EAAE,MAAM;iBACjB,YAAY;iBACZ,WAAW;iBACX,IAAI,EAAE,OAAO;;;iBAGb,WAAW,EACT,qFAAqF;iBACvF,OAAO;iBACP,SAAS,EAAE,IAAI;iBACf,YAAY;iBACZ,WAAW;iBACX,IAAI,EAAE,OAAO;;;iBAGb,WAAW,EAAE,6DAA6D;iBAC1E,OAAO;iBACP,SAAS,EAAE,MAAM;iBACjB,YAAY;iBACZ,WAAW;;;iBAGX,WAAW,EAAE,0DAA0D;iBACvE,OAAO;iBACP,SAAS,EAAE,IAAI;iBACf,YAAY;iBACZ,WAAW;iBACX,IAAI,EAAE,OAAO;;;iBAGb,WAAW,EACT,4FAA4F;iBAC9F,OAAO;iBACP,SAAS,EAAE,MAAM;iBACjB,YAAY;iBACZ,WAAW;iBACX,IAAI,EAAE,cAAc;;CAE+B,CAAC;AAExD,4FAA4F;AAC5F,MAAM,MAAM,kBAAkB,GAAG,MAAM,OAAO,eAAe,CAAC;AAE9D,qHAAqH;AACrH,MAAM,MAAM,eAAe,GAAG;IAC5B,QAAQ,EAAE,kBAAkB,CAAC;IAC7B,wCAAwC;IACxC,MAAM,EAAE,MAAM,CAAC;IACf,0CAA0C;IAC1C,SAAS,EAAE,MAAM,CAAC;IAClB,sEAAsE;IACtE,YAAY,EAAE,MAAM,CAAC;IACrB,2GAA2G;IAC3G,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,gEAAgE;IAChE,IAAI,EAAE,UAAU,CAAC;IACjB,kFAAkF;IAClF,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;CACpB,CAAC"}
@@ -0,0 +1,183 @@
1
+ import { AgentJamError } from "../errors.js";
2
+ import { fitLargestFields, maxEventKeyLength, maxEventKeys, } from "../events.js";
3
+ import { truncateSummary } from "../polling.js";
4
+ import { organizationProperty, regionProperty, requestSentry, slugPattern, } from "./sentryApi.js";
5
+ const readObject = (value) => typeof value === "object" && value !== null && !Array.isArray(value)
6
+ ? value
7
+ : undefined;
8
+ const readPath = (value, path) => path.reduce((current, key) => readObject(current)?.[key], value);
9
+ const readText = (...path) => (data) => {
10
+ const value = readPath(data, path);
11
+ return typeof value === "string" ? value : undefined;
12
+ };
13
+ const isReference = (value) => typeof value === "string" || typeof value === "number";
14
+ const readReferences = (...path) => (data) => {
15
+ const value = readPath(data, path);
16
+ const references = Array.isArray(value) ? value : [value];
17
+ return references.filter(isReference).map(String);
18
+ };
19
+ const readIssueSubject = (data) => {
20
+ const parts = [
21
+ readText("issue", "shortId")(data),
22
+ readText("issue", "title")(data),
23
+ ];
24
+ return parts.filter(Boolean).join(" ") || undefined;
25
+ };
26
+ const sentryResources = {
27
+ issue: {
28
+ description: "A Sentry issue is created, resolved, assigned, archived, or unresolved",
29
+ actions: ["created", "resolved", "assigned", "archived", "unresolved"],
30
+ reference: "slug",
31
+ readProjects: readReferences("issue", "project", "slug"),
32
+ readSubject: readIssueSubject,
33
+ item: "issue",
34
+ },
35
+ error: {
36
+ description: "Sentry receives an error event, in an organization on a Business or Enterprise plan",
37
+ actions: ["created"],
38
+ reference: "id",
39
+ readProjects: readReferences("error", "project"),
40
+ readSubject: readText("error", "title"),
41
+ item: "error",
42
+ },
43
+ comment: {
44
+ description: "A comment on a Sentry issue is created, updated, or deleted",
45
+ actions: ["created", "updated", "deleted"],
46
+ reference: "slug",
47
+ readProjects: readReferences("project_slug"),
48
+ readSubject: readText("comment"),
49
+ },
50
+ event_alert: {
51
+ description: "A Sentry issue alert that notifies the integration fires",
52
+ actions: ["triggered"],
53
+ reference: "id",
54
+ readProjects: readReferences("event", "project"),
55
+ readSubject: readText("triggered_rule"),
56
+ item: "event",
57
+ },
58
+ metric_alert: {
59
+ description: "A Sentry metric alert that notifies the integration turns critical or warning, or resolves",
60
+ actions: ["critical", "warning", "resolved"],
61
+ reference: "slug",
62
+ readProjects: readReferences("metric_alert", "alert_rule", "projects"),
63
+ readSubject: readText("description_title"),
64
+ item: "metric_alert",
65
+ },
66
+ };
67
+ const resourceNames = Object.keys(sentryResources);
68
+ const isSentryResourceName = (name) => Object.hasOwn(sentryResources, name);
69
+ const findSpec = (name) => sentryResources[name];
70
+ const constructSentryKey = (installation, resource, action, project) => `sentry:${installation}:${resource}${action === undefined ? "" : `.${action}`}${project === undefined ? "" : `:${project}`}`;
71
+ const findInstallation = async (token, { region = "us", organization }, integration) => {
72
+ const installations = await requestSentry(token, region, `/api/0/organizations/${encodeURIComponent(organization)}/sentry-app-installations/`);
73
+ const installed = installations.find(({ app }) => app.slug === integration);
74
+ if (!installed) {
75
+ throw new AgentJamError(`The Sentry integration ${integration} isn't installed in ${organization}, so install it at https://sentry.io/sentry-apps/${integration}/external-install/`);
76
+ }
77
+ return installed.uuid;
78
+ };
79
+ const readScheduleProject = async (token, { region = "us", organization, project }, reference) => {
80
+ if (project === undefined)
81
+ return undefined;
82
+ const found = await requestSentry(token, region, `/api/0/projects/${encodeURIComponent(organization)}/${encodeURIComponent(project)}/`);
83
+ return reference === "id" ? found.id : found.slug;
84
+ };
85
+ const constructWebhookTrigger = (resource, connection, integration) => {
86
+ const spec = findSpec(resource);
87
+ return {
88
+ description: spec.description,
89
+ config: {
90
+ type: "object",
91
+ properties: {
92
+ region: regionProperty,
93
+ organization: organizationProperty,
94
+ project: {
95
+ type: "string",
96
+ pattern: slugPattern,
97
+ description: "The slug of the Sentry project to watch. Leave it out to watch every project",
98
+ },
99
+ actions: {
100
+ type: "array",
101
+ items: { type: "string", enum: [...spec.actions] },
102
+ minItems: 1,
103
+ uniqueItems: true,
104
+ description: "The actions to run on. Leave it out to run on every action",
105
+ },
106
+ },
107
+ required: ["organization"],
108
+ },
109
+ onScheduleActive: async (schedule, { credentials }) => {
110
+ if (integration === undefined) {
111
+ throw new AgentJamError("Pass your Sentry integration's slug to sentryTriggers() as `integration` to watch its webhooks");
112
+ }
113
+ const config = schedule.config;
114
+ const token = await credentials(connection);
115
+ const installation = await findInstallation(token, config, integration);
116
+ const project = await readScheduleProject(token, config, spec.reference);
117
+ const actions = config.actions ?? [undefined];
118
+ const eventKeys = actions.map((action) => constructSentryKey(installation, resource, action, project));
119
+ return { eventKeys };
120
+ },
121
+ };
122
+ };
123
+ /** @internal One trigger per Sentry webhook resource, named after it. */
124
+ export const constructWebhookTriggers = (connection, integration) => Object.fromEntries(resourceNames.map((name) => [
125
+ name,
126
+ constructWebhookTrigger(name, connection, integration),
127
+ ]));
128
+ const summarizeEvent = ({ resource, action, actor }, subject) => {
129
+ const parts = [
130
+ `Sentry ${resource} ${action}`,
131
+ actor && ` by ${actor}`,
132
+ subject && `: ${subject}`,
133
+ ];
134
+ return truncateSummary(parts.filter(Boolean).join(""));
135
+ };
136
+ const recordOmitted = (event, omitted) => (omitted.length === 0 ? event : { ...event, omitted });
137
+ /** Leaves the largest fields of the resource out of a webhook too large for an event's data, until the data fits. */
138
+ const fitEventData = (event, { item }) => {
139
+ const resource = item === undefined ? undefined : readObject(event.data[item]);
140
+ if (item === undefined || !resource) {
141
+ return fitLargestFields(event.data, (data, omitted) => recordOmitted({ ...event, data }, omitted));
142
+ }
143
+ return fitLargestFields(resource, (kept, omitted) => recordOmitted({ ...event, data: { ...event.data, [item]: kept } }, omitted));
144
+ };
145
+ /** @internal Reads a webhook about `resource` under the keys its trigger subscribes schedules to. */
146
+ export const readSentryWebhook = (resource, requestId, payload) => {
147
+ if (!isSentryResourceName(resource))
148
+ return [];
149
+ const installation = readText("installation", "uuid")(payload);
150
+ const action = readText("action")(payload);
151
+ const data = readObject(payload.data);
152
+ if (!installation || !action || !data)
153
+ return [];
154
+ const spec = findSpec(resource);
155
+ const event = {
156
+ resource,
157
+ action,
158
+ requestId,
159
+ installation,
160
+ actor: readText("actor", "name")(payload) ?? null,
161
+ data,
162
+ };
163
+ const projects = [
164
+ undefined,
165
+ ...spec.readProjects(data),
166
+ ];
167
+ const eventKeys = projects
168
+ .flatMap((project) => [undefined, action].map((each) => constructSentryKey(installation, resource, each, project)))
169
+ .filter((key) => key.length <= maxEventKeyLength)
170
+ .slice(0, maxEventKeys);
171
+ return [
172
+ {
173
+ type: "event",
174
+ eventKeys,
175
+ event: {
176
+ id: `sentry:${requestId}`,
177
+ summary: summarizeEvent(event, spec.readSubject(data)),
178
+ data: fitEventData(event, spec),
179
+ },
180
+ },
181
+ ];
182
+ };
183
+ //# sourceMappingURL=sentryEvents.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sentryEvents.js","sourceRoot":"","sources":["../../src/platforms/sentryEvents.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAE7C,OAAO,EACL,gBAAgB,EAChB,iBAAiB,EACjB,YAAY,GACb,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAGhD,OAAO,EACL,oBAAoB,EACpB,cAAc,EACd,aAAa,EACb,WAAW,GACZ,MAAM,gBAAgB,CAAC;AA0BxB,MAAM,UAAU,GAAG,CAAC,KAAc,EAA0B,EAAE,CAC5D,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;IAClE,CAAC,CAAE,KAAoB;IACvB,CAAC,CAAC,SAAS,CAAC;AAEhB,MAAM,QAAQ,GAAG,CAAC,KAAc,EAAE,IAAc,EAAE,EAAE,CAClD,IAAI,CAAC,MAAM,CAAU,CAAC,OAAO,EAAE,GAAG,EAAE,EAAE,CAAC,UAAU,CAAC,OAAO,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,KAAK,CAAC,CAAC;AAE5E,MAAM,QAAQ,GACZ,CAAC,GAAG,IAAc,EAAkC,EAAE,CACtD,CAAC,IAAI,EAAE,EAAE;IACP,MAAM,KAAK,GAAG,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;IAEnC,OAAO,OAAO,KAAK,KAAK,QAAQ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C7B,QAAQ;QACR,MAAM;QACN,SAAS;QACT,YAAY;QACZ,KAAK,EAAE,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC,OAAO,CAAC,IAAI,IAAI;QACjD,IAAI;KACL,CAAC;IAEF,MAAM,QAAQ,GAA2B;QACvC,SAAS;QACT,GAAG,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC;KAC3B,CAAC;IACF,MAAM,SAAS,GAAG,QAAQ;SACvB,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CACnB,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAC/B,kBAAkB,CAAC,YAAY,EAAE,QAAQ,EAAE,IAAI,EAAE,OAAO,CAAC,CAC1D,CACF;SACA,MAAM,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,MAAM,IAAI,iBAAiB,CAAC;SAChD,KAAK,CAAC,CAAC,EAAE,YAAY,CAAC,CAAC;IAE1B,OAAO;QACL;YACE,IAAI,EAAE,OAAO;YACb,SAAS;YACT,KAAK,EAAE;gBACL,EAAE,EAAE,UAAU,SAAS,EAAE;gBACzB,OAAO,EAAE,cAAc,CAAC,KAAK,EAAE,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;gBACtD,IAAI,EAAE,YAAY,CAAC,KAAK,EAAE,IAAI,CAAC;aAChC;SACF;KACF,CAAC;AACJ,CAAC,CAAC"}
@@ -1,25 +1,10 @@
1
1
  import type { CredentialSource, OAuthConnection, OAuthPresetOptions } from "../connections.js";
2
2
  import type { EventSource } from "../events.js";
3
3
  import type { OAuthProfile } from "../providers.js";
4
- import type { JsonSchema, TriggerContext, TriggerSchedule } from "../types.js";
5
- /** An event from Slack's Events API, such as a `message`, as the request's `event` field holds it. */
6
- export type SlackEvent = Record<string, unknown> & {
7
- type: string;
8
- subtype?: string;
9
- channel?: string;
10
- channel_type?: string;
11
- user?: string;
12
- bot_id?: string;
13
- app_id?: string;
14
- text?: string;
15
- ts?: string;
16
- thread_ts?: string;
17
- team?: string;
18
- tokens?: {
19
- oauth?: string[];
20
- bot?: string[];
21
- };
22
- };
4
+ import type { Trigger } from "../types.js";
5
+ import type { SlackEvent } from "./slackEvents.js";
6
+ export type { SlackEvent, SlackEventData, SlackEventName, } from "./slackEvents.js";
7
+ export type { SlackInteractionData, SlackInteractionType, } from "./slackInteractions.js";
23
8
  /** Options for `slackConnection()`. */
24
9
  export type SlackConnectionOptions = OAuthPresetOptions & {
25
10
  /** The scopes to request for the shared `bot` token and for each human's `user` token. */
@@ -56,35 +41,36 @@ export declare const slackProfile: OAuthProfile;
56
41
  */
57
42
  export declare const slackConnection: ({ scopes: { bot, user }, ...options }: SlackConnectionOptions) => OAuthConnection<"bot" | "user">;
58
43
  /**
59
- * Reads Slack's Events API requests, for `agent.receiveEvents()` at the app's Request URL. It verifies each
60
- * request's signature, answers Slack's URL check, and reads messages, mentions and direct messages under the keys
61
- * `slackTriggers` subscribe to, with Slack's `event_id` as the event id. It leaves out the app's own messages and
62
- * edits or deletions, and reports an uninstall or revoked tokens as revoked accounts.
44
+ * Reads Slack's requests, for `agent.receiveEvents()` at the app's Events API, interactivity and slash command
45
+ * Request URLs, which can share one. It verifies each request's signature, answers Slack's URL check, and reads
46
+ * events and interactions under the keys `slackTriggers` subscribe to, leaving out the app's own actions. It
47
+ * reports an uninstall or revoked tokens as revoked accounts.
63
48
  *
64
- * @param options The app's signing secret, and keys for other event types.
49
+ * @param options The app's signing secret, and keys for event types `slackTriggers` don't watch.
65
50
  * @returns An event source for Slack's requests.
66
51
  */
67
52
  export declare const slackEvents: ({ signingSecret, map, }: SlackEventsOptions) => EventSource;
68
53
  /**
69
- * Triggers that run a schedule on Slack events, which `slackEvents()` reads, for a skill whose connections include
70
- * `connection`. Every schedule watching an event gets its own run, with the message's `channel`, `ts`,
71
- * `thread_ts`, `user`, `text` and `team` as `task.event.data`.
54
+ * Triggers that run a schedule on what `slackEvents()` reads, for a skill whose connections include `connection`:
55
+ * messages, one per Events API type such as `reaction_added`, and one per interaction such as a slash `command`.
56
+ * Every schedule watching one gets its own run, with a message's `channel`, `ts`, `thread_ts`, `user`, `text` and
57
+ * `team`, a `SlackEventData` or a `SlackInteractionData` as `task.event.data`.
72
58
  *
73
59
  * @param connection The skill's Slack connection.
74
- * @returns The `message`, `mention` and `directMessage` triggers, for a skill's `triggers`.
60
+ * @returns The triggers, for a skill's `triggers`.
75
61
  */
76
62
  export declare const slackTriggers: (connection: CredentialSource) => {
77
63
  /** A message in a channel the app is in, or only in `config.channel` when the requester sets it. */
78
64
  message: {
79
65
  description: string;
80
- config: JsonSchema;
81
- onScheduleActive: (schedule: TriggerSchedule, context: TriggerContext) => import("../types.js").Awaitable<import("../types.js").TriggerActivation | void>;
66
+ config: import("../types.js").JsonSchema;
67
+ onScheduleActive: (schedule: import("../types.js").TriggerSchedule, context: import("../types.js").TriggerContext) => import("../types.js").Awaitable<import("../types.js").TriggerActivation | void>;
82
68
  };
83
69
  /** A message that mentions the app, in any channel or only in `config.channel`. */
84
70
  mention: {
85
71
  description: string;
86
- config: JsonSchema;
87
- onScheduleActive: (schedule: TriggerSchedule, context: TriggerContext) => import("../types.js").Awaitable<import("../types.js").TriggerActivation | void>;
72
+ config: import("../types.js").JsonSchema;
73
+ onScheduleActive: (schedule: import("../types.js").TriggerSchedule, context: import("../types.js").TriggerContext) => import("../types.js").Awaitable<import("../types.js").TriggerActivation | void>;
88
74
  };
89
75
  /** A direct message to the app from the human who connected Slack for the schedule. */
90
76
  directMessage: {
@@ -93,9 +79,59 @@ export declare const slackTriggers: (connection: CredentialSource) => {
93
79
  type: string;
94
80
  properties: {};
95
81
  };
96
- onScheduleActive: (_schedule: TriggerSchedule, context: TriggerContext) => Promise<{
82
+ onScheduleActive: (_schedule: import("../types.js").TriggerSchedule, context: import("../types.js").TriggerContext) => Promise<{
97
83
  eventKeys: string[];
98
84
  }>;
99
85
  };
86
+ app_home_opened: Trigger;
87
+ assistant_thread_context_changed: Trigger;
88
+ assistant_thread_started: Trigger;
89
+ block_actions: Trigger;
90
+ channel_archive: Trigger;
91
+ channel_created: Trigger;
92
+ channel_deleted: Trigger;
93
+ channel_id_changed: Trigger;
94
+ channel_left: Trigger;
95
+ channel_rename: Trigger;
96
+ channel_shared: Trigger;
97
+ channel_unarchive: Trigger;
98
+ channel_unshared: Trigger;
99
+ command: Trigger;
100
+ emoji_changed: Trigger;
101
+ file_change: Trigger;
102
+ file_created: Trigger;
103
+ file_deleted: Trigger;
104
+ file_public: Trigger;
105
+ file_shared: Trigger;
106
+ file_unshared: Trigger;
107
+ group_archive: Trigger;
108
+ group_deleted: Trigger;
109
+ group_left: Trigger;
110
+ group_rename: Trigger;
111
+ group_unarchive: Trigger;
112
+ link_shared: Trigger;
113
+ member_joined_channel: Trigger;
114
+ member_left_channel: Trigger;
115
+ message_action: Trigger;
116
+ message_changed: Trigger;
117
+ message_deleted: Trigger;
118
+ pin_added: Trigger;
119
+ pin_removed: Trigger;
120
+ reaction_added: Trigger;
121
+ reaction_removed: Trigger;
122
+ shortcut: Trigger;
123
+ subteam_created: Trigger;
124
+ subteam_members_changed: Trigger;
125
+ subteam_self_added: Trigger;
126
+ subteam_self_removed: Trigger;
127
+ subteam_updated: Trigger;
128
+ team_domain_change: Trigger;
129
+ team_join: Trigger;
130
+ team_rename: Trigger;
131
+ user_change: Trigger;
132
+ user_huddle_changed: Trigger;
133
+ user_profile_changed: Trigger;
134
+ user_status_changed: Trigger;
135
+ view_submission: Trigger;
100
136
  };
101
137
  //# sourceMappingURL=slack.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"slack.d.ts","sourceRoot":"","sources":["../../src/platforms/slack.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,gBAAgB,EAChB,eAAe,EACf,kBAAkB,EACnB,MAAM,mBAAmB,CAAC;AAE3B,OAAO,KAAK,EAAE,WAAW,EAAe,MAAM,cAAc,CAAC;AAE7D,OAAO,KAAK,EA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