@sentry/junior-plugin-api 0.274.0 → 0.276.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -974,6 +974,8 @@ export interface PluginConversationEventCostDay {
974
974
  export interface PluginConversationEventRecord {
975
975
  content: Record<string, unknown>;
976
976
  createdAt: string;
977
+ /** Turn that emitted the event. Events from outside a Turn have none. */
978
+ turnId?: string;
977
979
  version: number;
978
980
  }
979
981
  /** Read events owned by the current plugin namespace after Conversation access checks. */
@@ -1123,6 +1125,17 @@ export declare const eventMatchFieldsSchema: z.ZodRecord<z.ZodString, z.ZodObjec
1123
1125
  }, z.core.$strict>>;
1124
1126
  /** Exact trusted values required before a watch or event automation runs. */
1125
1127
  export declare const eventMatchSchema: z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodBoolean, z.ZodNumber, z.ZodString, z.ZodArray<z.ZodUnion<readonly [z.ZodNumber, z.ZodString]>>]>>;
1128
+ /**
1129
+ * A match as tool inputs and results write it. Each key is the snake_case
1130
+ * name of a declared field: `pullRequest` is `pull_request`.
1131
+ */
1132
+ export declare const agentEventMatchSchema: z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodBoolean, z.ZodNumber, z.ZodString, z.ZodArray<z.ZodUnion<readonly [z.ZodNumber, z.ZodString]>>]>>;
1133
+ /** Name a declared filter as tool inputs and results write it. */
1134
+ export declare function agentEventMatchKey(key: string): string;
1135
+ /** Copy event data or a saved match with snake_case keys, for the agent. */
1136
+ export declare function agentEventKeys<T>(match: Readonly<Record<string, T>>): Record<string, T>;
1137
+ /** Copy a tool-input match with the keys that its plugin declares. */
1138
+ export declare function declaredEventKeys<T>(match: Readonly<Record<string, T>>): Record<string, T>;
1126
1139
  export type EventMatch = z.output<typeof eventMatchSchema>;
1127
1140
  export type EventMatchFields = z.output<typeof eventMatchFieldsSchema>;
1128
1141
  /**
@@ -1245,6 +1258,10 @@ export declare const pluginEventsSchema: z.ZodObject<{
1245
1258
  }, z.core.$strict>>;
1246
1259
  isEnabled: z.ZodOptional<z.ZodFunction<z.ZodTuple<readonly [], null>, z.ZodBoolean>>;
1247
1260
  normalizeIdentifier: z.ZodOptional<z.ZodFunction<z.ZodTuple<readonly [z.ZodString], null>, z.ZodString>>;
1261
+ resourceUrl: z.ZodOptional<z.ZodFunction<z.ZodTuple<readonly [z.ZodObject<{
1262
+ identifier: z.ZodString;
1263
+ resourceType: z.ZodString;
1264
+ }, z.core.$strip>], null>, z.ZodOptional<z.ZodString>>>;
1248
1265
  }, z.core.$strict>;
1249
1266
  export type PluginEventType = z.output<typeof pluginEventTypeSchema>;
1250
1267
  export type PluginEvents = z.output<typeof pluginEventsSchema>;
@@ -1255,8 +1272,8 @@ export declare const subscribableResourceSchema: z.ZodObject<{
1255
1272
  label: z.ZodString;
1256
1273
  match: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodBoolean, z.ZodNumber, z.ZodString, z.ZodArray<z.ZodUnion<readonly [z.ZodNumber, z.ZodString]>>]>>>;
1257
1274
  namespace: z.ZodString;
1258
- suggestedEvents: z.ZodOptional<z.ZodArray<z.ZodString>>;
1259
- supportedEvents: z.ZodArray<z.ZodString>;
1275
+ suggested_events: z.ZodOptional<z.ZodArray<z.ZodString>>;
1276
+ supported_events: z.ZodArray<z.ZodString>;
1260
1277
  type: z.ZodString;
1261
1278
  }, z.core.$strict>;
1262
1279
  export type SubscribableResource = z.output<typeof subscribableResourceSchema>;
@@ -1430,7 +1447,8 @@ export declare function eventTriggerChoices(source: EventTriggerSource, selectio
1430
1447
  * A selection with no resource type can use only events whose reach is not
1431
1448
  * `"resource"`, with the filters of every resource type, and must set one of
1432
1449
  * the filters that the reach of each selected event names.
1433
- * Set `inputKeys` for the agent, so messages name the `match.<key>` input.
1450
+ * Set `inputKeys` for the agent, so messages name the snake_case
1451
+ * `match.<key>` input.
1434
1452
  */
1435
1453
  export declare function eventTriggerProblems(source: EventTriggerSource, selection: EventTriggerSelection, options?: {
1436
1454
  inputKeys?: boolean;
package/dist/index.js CHANGED
@@ -670,6 +670,7 @@ const eventDataSchema = z.record(z.string(), z.unknown()).superRefine((value, co
670
670
  const eventTypeSchema = z.string().regex(/^[a-z][a-z0-9_-]*(?:\.[a-z][a-z0-9_-]*)+$/).describe("Canonical dotted event type, such as issue.closed or pull_request.review.changes_requested.");
671
671
  const resourceTypeSchema = z.string().regex(/^[a-z][a-z0-9_]*$/).describe("Canonical plugin-defined resource type, such as issue or pull_request.");
672
672
  const EVENT_MATCH_FIELD_NAME = /^[a-z][a-zA-Z0-9]*$/;
673
+ const AGENT_EVENT_MATCH_KEY = /^[a-z][a-z0-9]*(?:_[a-z][a-z0-9]*)*$/;
673
674
  /** One exact value a watch or event automation may require on trusted event data. */
674
675
  const eventMatchFieldSchema = z.object({
675
676
  kind: z.enum([
@@ -718,26 +719,53 @@ const eventMatchFieldsSchema = z.record(z.string().regex(EVENT_MATCH_FIELD_NAME)
718
719
  message: `Event match keys may include at most 32 keys.`
719
720
  });
720
721
  });
721
- /** Exact trusted values required before a watch or event automation runs. */
722
- const eventMatchSchema = z.record(z.string().regex(EVENT_MATCH_FIELD_NAME), z.union([
723
- z.boolean(),
724
- z.number().finite(),
725
- z.string().min(1),
726
- z.array(z.union([z.number().finite(), z.string().min(1)])).min(1)
727
- ])).superRefine((match, context) => {
728
- if (Object.keys(match).length > 32) context.addIssue({
729
- code: "custom",
730
- message: `Event match may include at most 32 keys.`
731
- });
732
- for (const [key, value] of Object.entries(match)) {
733
- if (!Array.isArray(value)) continue;
734
- if (value.some((entry) => typeof entry === "boolean")) context.addIssue({
722
+ function matchSchema(keyPattern) {
723
+ return z.record(z.string().regex(keyPattern), z.union([
724
+ z.boolean(),
725
+ z.number().finite(),
726
+ z.string().min(1),
727
+ z.array(z.union([z.number().finite(), z.string().min(1)])).min(1)
728
+ ])).superRefine((match, context) => {
729
+ if (Object.keys(match).length > 32) context.addIssue({
735
730
  code: "custom",
736
- message: `Event match field "${key}" cannot use a boolean list.`,
737
- path: [key]
731
+ message: `Event match may include at most 32 keys.`
738
732
  });
739
- }
740
- });
733
+ for (const [key, value] of Object.entries(match)) {
734
+ if (!Array.isArray(value)) continue;
735
+ if (value.some((entry) => typeof entry === "boolean")) context.addIssue({
736
+ code: "custom",
737
+ message: `Event match field "${key}" cannot use a boolean list.`,
738
+ path: [key]
739
+ });
740
+ }
741
+ });
742
+ }
743
+ /** Exact trusted values required before a watch or event automation runs. */
744
+ const eventMatchSchema = matchSchema(EVENT_MATCH_FIELD_NAME);
745
+ /**
746
+ * A match as tool inputs and results write it. Each key is the snake_case
747
+ * name of a declared field: `pullRequest` is `pull_request`.
748
+ */
749
+ const agentEventMatchSchema = matchSchema(AGENT_EVENT_MATCH_KEY);
750
+ /** Name a declared filter as tool inputs and results write it. */
751
+ function agentEventMatchKey(key) {
752
+ return key.replace(/[A-Z]/g, (letter) => `_${letter.toLowerCase()}`);
753
+ }
754
+ /** Name a tool-input filter as its plugin declares it. */
755
+ function declaredEventMatchKey(key) {
756
+ return key.replace(/_([a-z])/g, (_, letter) => letter.toUpperCase());
757
+ }
758
+ function renameMatchKeys(match, rename) {
759
+ return Object.fromEntries(Object.entries(match).map(([key, value]) => [rename(key), value]));
760
+ }
761
+ /** Copy event data or a saved match with snake_case keys, for the agent. */
762
+ function agentEventKeys(match) {
763
+ return renameMatchKeys(match, agentEventMatchKey);
764
+ }
765
+ /** Copy a tool-input match with the keys that its plugin declares. */
766
+ function declaredEventKeys(match) {
767
+ return renameMatchKeys(match, declaredEventMatchKey);
768
+ }
741
769
  function sameValues(left, right) {
742
770
  return left?.length === right?.length && (left ?? []).every((value) => right?.includes(value));
743
771
  }
@@ -923,6 +951,17 @@ const pluginEventsSchema = z.object({
923
951
  normalizeIdentifier: z.function({
924
952
  input: [z.string()],
925
953
  output: z.string()
954
+ }).optional(),
955
+ /**
956
+ * The web page of one watched resource, so people can open it. Returns
957
+ * undefined when the resource has no page.
958
+ */
959
+ resourceUrl: z.function({
960
+ input: [z.object({
961
+ identifier: z.string(),
962
+ resourceType: z.string()
963
+ })],
964
+ output: z.string().optional()
926
965
  }).optional()
927
966
  }).strict().superRefine((registration, context) => {
928
967
  const seen = /* @__PURE__ */ new Set();
@@ -986,13 +1025,13 @@ const subscribableResourceSchema = z.object({
986
1025
  label: z.string().min(1),
987
1026
  /**
988
1027
  * Filters that select the events of this resource in an event automation
989
- * trigger, such as `{ repo, pullRequest }`. A Watch uses `identifier`.
1028
+ * trigger, such as `{ repo, pull_request }`. A Watch uses `identifier`.
990
1029
  * Missing when event automations cannot use this resource.
991
1030
  */
992
- match: eventMatchSchema.optional(),
1031
+ match: agentEventMatchSchema.optional(),
993
1032
  namespace: z.string().min(1),
994
- suggestedEvents: z.array(eventTypeSchema).optional(),
995
- supportedEvents: z.array(eventTypeSchema),
1033
+ suggested_events: z.array(eventTypeSchema).optional(),
1034
+ supported_events: z.array(eventTypeSchema),
996
1035
  type: resourceTypeSchema
997
1036
  }).strict();
998
1037
  /** Result returned after a temporary watch is created. */
@@ -1035,6 +1074,14 @@ const eventInputSchema = z.object({
1035
1074
  }).strict();
1036
1075
  const eventSchema = eventInputSchema.extend({ namespace: z.string().min(1) });
1037
1076
  // src/event-triggers.ts
1077
+ /**
1078
+ * The one check for the events and filters that an event automation trigger
1079
+ * or a Watch selects.
1080
+ *
1081
+ * Core runs it before it saves an event automation or creates a Watch, and to
1082
+ * find saved triggers that can no longer work. The dashboard runs it in the
1083
+ * editor, so all of them use the same rules.
1084
+ */
1038
1085
  /** The events of a source that a trigger with no identifier can select. */
1039
1086
  function anyResourceEvents(source) {
1040
1087
  return Object.entries(source.events).filter(([, declaration]) => declaration.reach !== "resource").map(([eventType]) => eventType).sort();
@@ -1047,6 +1094,10 @@ function kindWords(kind) {
1047
1094
  if (kind === "number") return "a number";
1048
1095
  return "text";
1049
1096
  }
1097
+ /** Name filters as the agent writes them when messages are for tool input. */
1098
+ function filterKeyName(options) {
1099
+ return (key) => options.inputKeys ? agentEventMatchKey(key) : key;
1100
+ }
1050
1101
  /** Return the selected events that never set one filter field. */
1051
1102
  function eventsWithoutMatchField(field, events) {
1052
1103
  const setBy = field.events;
@@ -1108,7 +1159,8 @@ function eventTriggerChoices(source, selection) {
1108
1159
  * A selection with no resource type can use only events whose reach is not
1109
1160
  * `"resource"`, with the filters of every resource type, and must set one of
1110
1161
  * the filters that the reach of each selected event names.
1111
- * Set `inputKeys` for the agent, so messages name the `match.<key>` input.
1162
+ * Set `inputKeys` for the agent, so messages name the snake_case
1163
+ * `match.<key>` input.
1112
1164
  */
1113
1165
  function eventTriggerProblems(source, selection, options = {}) {
1114
1166
  if (source.resourceTypes.length === 0) return [{
@@ -1117,7 +1169,8 @@ function eventTriggerProblems(source, selection, options = {}) {
1117
1169
  }];
1118
1170
  const scope = selectionScope(source, selection);
1119
1171
  if ("reason" in scope) return [scope];
1120
- const filterName = (key) => options.inputKeys ? `Filter "${key}" (match.${key})` : `Filter "${key}"`;
1172
+ const name = filterKeyName(options);
1173
+ const filterName = (key) => options.inputKeys ? `Filter "${name(key)}" (match.${name(key)})` : `Filter "${key}"`;
1121
1174
  const problems = [];
1122
1175
  const events = selection.events.filter((eventType) => scope.events.includes(eventType));
1123
1176
  for (const eventType of selection.events) {
@@ -1131,7 +1184,7 @@ function eventTriggerProblems(source, selection, options = {}) {
1131
1184
  message: `"${eventType}" is not an event for this ${scope.owner}. Use one of: ${quoted(scope.events)}.`
1132
1185
  });
1133
1186
  }
1134
- const fieldNames = Object.keys(scope.fields);
1187
+ const fieldNames = Object.keys(scope.fields).map(name);
1135
1188
  for (const [key, value] of Object.entries(selection.match ?? {})) {
1136
1189
  const filter = filterName(key);
1137
1190
  const field = scope.fields[key];
@@ -1174,11 +1227,12 @@ function requiredFilterProblems(source, events, selection, options) {
1174
1227
  entry.events.push(eventType);
1175
1228
  missing.set(key, entry);
1176
1229
  }
1177
- const inputKey = (filter) => options.inputKeys ? ` (match.${filter})` : "";
1230
+ const name = filterKeyName(options);
1231
+ const inputKey = (filter) => options.inputKeys ? ` (match.${name(filter)})` : "";
1178
1232
  return [...missing.values()].map(({ anyOf, events: requiredBy }) => ({
1179
1233
  reason: "filter_required",
1180
1234
  field: anyOf[0],
1181
- message: anyOf.length === 1 ? `This trigger needs a "${anyOf[0]}" filter${inputKey(anyOf[0])}, because ${quoted(requiredBy)} cannot run for every resource.` : `This trigger needs one of these filters: ${anyOf.map((filter) => `"${filter}"${inputKey(filter)}`).join(", ")}, because ${quoted(requiredBy)} cannot run for every resource.`
1235
+ message: anyOf.length === 1 ? `This trigger needs a "${name(anyOf[0])}" filter${inputKey(anyOf[0])}, because ${quoted(requiredBy)} cannot run for every resource.` : `This trigger needs one of these filters: ${anyOf.map((filter) => `"${name(filter)}"${inputKey(filter)}`).join(", ")}, because ${quoted(requiredBy)} cannot run for every resource.`
1182
1236
  }));
1183
1237
  }
1184
1238
  /** Write one event type in plain words: `pull_request.opened` is "pull request opened". */
@@ -1733,4 +1787,4 @@ const pluginUserPageInputSchema = z.object({
1733
1787
  limit: z.number().int().min(1).max(50),
1734
1788
  query: pluginUserPageQuerySchema
1735
1789
  }).strict();
1736
- export { EVENT_DATA_MAX_JSON_BYTES, EVENT_DATA_MAX_KEYS, EVENT_GUIDANCE_MAX_LENGTH, EVENT_SUMMARY_MAX_LENGTH, EVENT_TEXT_MAX_LENGTH, EgressAuthRequired, EgressPolicyDenied, PluginToolInputError, REQUIRED_TOOL_ANNOTATION_KEYS, actorSchema, actorUserIdSchema, agentInvocationSourceSchema, anyResourceEvents, anyResourceMatchFields, codeChangeInputSchema, codeChangeStateSchema, conversationAnnotationInputSchema, conversationEventIconSchema, conversationEventPresentationSchema, conversationSidebarAnnotationSchema, conversationSidebarIconSchema, createEventSource, createLocalSource, createSlackSource, createWebSource, defineConversationEvent, defineJuniorPlugin, definePluginTool, definePromptContext, describeEventTrigger, destinationSchema, destinationVisibilitySchema, dispatchOptionsSchema, enforceEgressPolicy, eventAutomationSourceSchema, eventDataSchema, eventIdentifierSchema, eventInputSchema, eventMatchFieldSchema, eventMatchFieldsSchema, eventMatchFilterText, eventMatchSchema, eventMatches, eventPersonSchema, eventReachSchema, eventSchema, eventSourceSchema, eventTriggerChoices, eventTriggerFiltersText, eventTriggerProblems, eventTriggerText, eventTypeSchema, eventTypeText, eventsWithoutMatchField, getSourceKey, identitySchema, isPrivateSource, isSlackDestination, localActorSchema, localDestinationSchema, localSourceSchema, locationSchema, mergeEventMatchFields, missingToolAnnotationKeys, nonBlankStringSchema, normalizeEventIdentifier, normalizeEventMatch, objectAnnotationSchema, objectFactFields, objectFactsSchema, objectIconPath, objectIconPaths, objectPresentation, objectTypeSchema, ownedObjectAnnotationSchema, parseShellCommands, platformSchema, pluginApiRouteRequestContextSchema, pluginAuthorizationSchema, pluginCredentialHeaderTransformSchema, pluginCredentialLeaseSchema, pluginCredentialResultSchema, pluginCredentialSubjectSchema, pluginDispatchSourceSchema, pluginEventDeclarationSchema, pluginEventTypeSchema, pluginEventsSchema, pluginGrantSchema, pluginProviderAccountSchema, pluginRunContextSchema, pluginRunTranscriptEntrySchema, pluginRunTranscriptProvenanceSchema, pluginStoredTokensSchema, pluginToolContentSchema, pluginToolContinuationSchema, pluginToolOutputSchema, pluginUserPageContentSchema, pluginUserPageCursorSchema, pluginUserPageFilterSchema, pluginUserPageInputSchema, pluginUserPageLinkSchema, pluginUserPageLinksSchema, pluginUserPageQuerySchema, promptContextSchema, promptMessageSchema, replyAttributionSchema, resourceLinkAnnotationSchema, resourceTypeSchema, scheduledAutomationSourceSchema, slackActorSchema, slackDestinationSchema, slackLocationSchema, slackSourceSchema, sourceSchema, sourceVisibilitySchema, stableEventMatchKey, subscribableResourceSchema, systemActorSchema, taskOutcomeSchema, toolApprovalModeSchema, userSchema, watchResultSchema, webActorSchema, webSourceSchema, zodTool };
1790
+ export { EVENT_DATA_MAX_JSON_BYTES, EVENT_DATA_MAX_KEYS, EVENT_GUIDANCE_MAX_LENGTH, EVENT_SUMMARY_MAX_LENGTH, EVENT_TEXT_MAX_LENGTH, EgressAuthRequired, EgressPolicyDenied, PluginToolInputError, REQUIRED_TOOL_ANNOTATION_KEYS, actorSchema, actorUserIdSchema, agentEventKeys, agentEventMatchKey, agentEventMatchSchema, agentInvocationSourceSchema, anyResourceEvents, anyResourceMatchFields, codeChangeInputSchema, codeChangeStateSchema, conversationAnnotationInputSchema, conversationEventIconSchema, conversationEventPresentationSchema, conversationSidebarAnnotationSchema, conversationSidebarIconSchema, createEventSource, createLocalSource, createSlackSource, createWebSource, declaredEventKeys, defineConversationEvent, defineJuniorPlugin, definePluginTool, definePromptContext, describeEventTrigger, destinationSchema, destinationVisibilitySchema, dispatchOptionsSchema, enforceEgressPolicy, eventAutomationSourceSchema, eventDataSchema, eventIdentifierSchema, eventInputSchema, eventMatchFieldSchema, eventMatchFieldsSchema, eventMatchFilterText, eventMatchSchema, eventMatches, eventPersonSchema, eventReachSchema, eventSchema, eventSourceSchema, eventTriggerChoices, eventTriggerFiltersText, eventTriggerProblems, eventTriggerText, eventTypeSchema, eventTypeText, eventsWithoutMatchField, getSourceKey, identitySchema, isPrivateSource, isSlackDestination, localActorSchema, localDestinationSchema, localSourceSchema, locationSchema, mergeEventMatchFields, missingToolAnnotationKeys, nonBlankStringSchema, normalizeEventIdentifier, normalizeEventMatch, objectAnnotationSchema, objectFactFields, objectFactsSchema, objectIconPath, objectIconPaths, objectPresentation, objectTypeSchema, ownedObjectAnnotationSchema, parseShellCommands, platformSchema, pluginApiRouteRequestContextSchema, pluginAuthorizationSchema, pluginCredentialHeaderTransformSchema, pluginCredentialLeaseSchema, pluginCredentialResultSchema, pluginCredentialSubjectSchema, pluginDispatchSourceSchema, pluginEventDeclarationSchema, pluginEventTypeSchema, pluginEventsSchema, pluginGrantSchema, pluginProviderAccountSchema, pluginRunContextSchema, pluginRunTranscriptEntrySchema, pluginRunTranscriptProvenanceSchema, pluginStoredTokensSchema, pluginToolContentSchema, pluginToolContinuationSchema, pluginToolOutputSchema, pluginUserPageContentSchema, pluginUserPageCursorSchema, pluginUserPageFilterSchema, pluginUserPageInputSchema, pluginUserPageLinkSchema, pluginUserPageLinksSchema, pluginUserPageQuerySchema, promptContextSchema, promptMessageSchema, replyAttributionSchema, resourceLinkAnnotationSchema, resourceTypeSchema, scheduledAutomationSourceSchema, slackActorSchema, slackDestinationSchema, slackLocationSchema, slackSourceSchema, sourceSchema, sourceVisibilitySchema, stableEventMatchKey, subscribableResourceSchema, systemActorSchema, taskOutcomeSchema, toolApprovalModeSchema, userSchema, watchResultSchema, webActorSchema, webSourceSchema, zodTool };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sentry/junior-plugin-api",
3
- "version": "0.274.0",
3
+ "version": "0.276.0",
4
4
  "private": false,
5
5
  "publishConfig": {
6
6
  "access": "public"