@sentry/junior-plugin-api 0.299.0 → 0.301.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 (3) hide show
  1. package/dist/index.d.ts +1373 -1131
  2. package/dist/index.js +92 -4
  3. package/package.json +2 -2
package/dist/index.js CHANGED
@@ -2,10 +2,14 @@ import * as z from "zod";
2
2
  // src/object-facts.ts
3
3
  const text = z.string().trim().min(1).max(160);
4
4
  const count = z.number().int().nonnegative();
5
+ /** The longest object summary, in UTF-16 code units. */
6
+ const OBJECT_SUMMARY_MAX_LENGTH = 280;
7
+ const summary = z.string().trim().min(1).max(280);
5
8
  /** Small, provider-neutral facts. Missing values mean unknown, not success. */
6
9
  const objectFactsSchema = z.discriminatedUnion("type", [
7
10
  z.strictObject({
8
11
  type: z.literal("code_change"),
12
+ summary: summary.optional(),
9
13
  author: text.optional(),
10
14
  sourceBranch: text.optional(),
11
15
  targetBranch: text.optional(),
@@ -25,13 +29,15 @@ const objectFactsSchema = z.discriminatedUnion("type", [
25
29
  additions: count.optional(),
26
30
  deletions: count.optional(),
27
31
  /**
28
- * Public images from the description that the dashboard can show. The
29
- * 4 KiB facts limit sets how many fit.
32
+ * Images from the description. The dashboard loads them through the
33
+ * Junior image route, and the plugin's `images` source checks each
34
+ * viewer. The 4 KiB facts limit sets how many fit.
30
35
  */
31
36
  previewImageUrls: z.array(z.url({ protocol: /^https?$/ }).max(512)).min(1).optional()
32
37
  }),
33
38
  z.strictObject({
34
39
  type: z.literal("task"),
40
+ summary: summary.optional(),
35
41
  assignees: z.array(text).max(5).optional(),
36
42
  priority: text.optional(),
37
43
  project: text.optional(),
@@ -41,6 +47,7 @@ const objectFactsSchema = z.discriminatedUnion("type", [
41
47
  }),
42
48
  z.strictObject({
43
49
  type: z.literal("deployment"),
50
+ summary: summary.optional(),
44
51
  project: text.optional(),
45
52
  environment: text.optional(),
46
53
  revision: text.optional(),
@@ -48,28 +55,65 @@ const objectFactsSchema = z.discriminatedUnion("type", [
48
55
  }),
49
56
  z.strictObject({
50
57
  type: z.literal("calendar_event"),
58
+ summary: summary.optional(),
51
59
  when: text.optional(),
52
60
  attendees: z.array(text).max(5).optional()
53
61
  }),
54
62
  z.strictObject({
55
63
  type: z.literal("conversation"),
64
+ summary: summary.optional(),
56
65
  participants: z.array(text).max(5).optional(),
57
66
  lastActivityAt: z.iso.datetime({ offset: true }).optional()
58
67
  }),
68
+ z.strictObject({
69
+ type: z.literal("document"),
70
+ summary: summary.optional(),
71
+ owner: text.optional(),
72
+ modifiedAt: z.iso.datetime({ offset: true }).optional()
73
+ }),
59
74
  z.strictObject({
60
75
  type: z.literal("message"),
76
+ summary: summary.optional(),
61
77
  channel: text.optional(),
62
78
  author: text.optional(),
63
79
  sentAt: z.iso.datetime({ offset: true }).optional()
64
80
  }),
81
+ z.strictObject({
82
+ type: z.literal("web_page"),
83
+ summary: summary.optional(),
84
+ siteName: text.optional(),
85
+ author: text.optional(),
86
+ thumbnailUrl: z.string().max(4e3).regex(/^\/api\/images\/[\w-]+\.[\w-]+\?w=\d+$/).optional()
87
+ }),
65
88
  z.strictObject({
66
89
  type: z.literal("person"),
90
+ summary: summary.optional(),
67
91
  email: text.optional(),
68
92
  slackHandle: text.optional(),
69
93
  githubHandle: z.string().regex(/^[A-Za-z0-9][A-Za-z0-9_-]{0,99}$/).optional(),
70
94
  avatarUrl: z.string().max(500).regex(/^\/api\/people\/avatars\/[^/?#]+(\?v=[\w-]+)?$/).optional()
71
95
  })
72
96
  ]);
97
+ /**
98
+ * Make an object summary from plain text. Join whitespace and cut overlong
99
+ * text at a word, with an ellipsis. Empty text gives no summary.
100
+ */
101
+ function objectSummary(text) {
102
+ const words = text.split(/\s+/).filter(Boolean);
103
+ const joined = words.join(" ");
104
+ if (joined.length <= 280) return joined || void 0;
105
+ let cut = "";
106
+ for (const word of words) {
107
+ const next = cut ? `${cut} ${word}` : word;
108
+ if (next.length >= 280) break;
109
+ cut = next;
110
+ }
111
+ if (!cut) {
112
+ cut = joined.slice(0, 279);
113
+ if (/[\ud800-\udbff]$/.test(cut)) cut = cut.slice(0, -1);
114
+ }
115
+ return `${cut}…`;
116
+ }
73
117
  /** Show at most four card attributes, in priority order, on every surface. */
74
118
  function objectFactFields(facts) {
75
119
  if (!facts) return [];
@@ -112,6 +156,13 @@ function objectFactFields(facts) {
112
156
  timeStyle: "short"
113
157
  }));
114
158
  break;
159
+ case "document":
160
+ add("owner", "Owner", facts.owner);
161
+ add("modifiedAt", "Modified", facts.modifiedAt && new Date(facts.modifiedAt).toLocaleString(void 0, {
162
+ dateStyle: "medium",
163
+ timeStyle: "short"
164
+ }));
165
+ break;
115
166
  case "message":
116
167
  add("channel", "Channel", facts.channel);
117
168
  add("author", "Author", facts.author);
@@ -120,6 +171,10 @@ function objectFactFields(facts) {
120
171
  timeStyle: "short"
121
172
  }));
122
173
  break;
174
+ case "web_page":
175
+ add("siteName", "Site", facts.siteName);
176
+ add("author", "Author", facts.author);
177
+ break;
123
178
  case "person":
124
179
  add("email", "Email", facts.email);
125
180
  add("slackHandle", "Slack", facts.slackHandle && `@${facts.slackHandle}`);
@@ -137,7 +192,9 @@ const objectTypeSchema = z.enum([
137
192
  "calendar_event",
138
193
  "conversation",
139
194
  "person",
195
+ "document",
140
196
  "message",
197
+ "web_page",
141
198
  "item"
142
199
  ]);
143
200
  const objectTypeLabels = {
@@ -148,7 +205,9 @@ const objectTypeLabels = {
148
205
  calendar_event: "Calendar event",
149
206
  conversation: "Conversation",
150
207
  person: "Person",
208
+ document: "Document",
151
209
  message: "Message",
210
+ web_page: "Web page",
152
211
  item: "Item"
153
212
  };
154
213
  /** Resolve identity and state without replacing the type icon with a warning. */
@@ -163,7 +222,9 @@ function objectPresentation(object) {
163
222
  calendar_event: "calendar",
164
223
  conversation: "comment-discussion",
165
224
  person: "person",
225
+ document: "file",
166
226
  message: "comment",
227
+ web_page: "globe",
167
228
  item: "package"
168
229
  }[type];
169
230
  let tone = type === "automation" ? "info" : "neutral";
@@ -270,9 +331,35 @@ const objectIconPaths = {
270
331
  calendar: ["M4.75 0a.75.75 0 0 1 .75.75V2h5V.75a.75.75 0 0 1 1.5 0V2h1.25c.966 0 1.75.784 1.75 1.75v10.5A1.75 1.75 0 0 1 13.25 16H2.75A1.75 1.75 0 0 1 1 14.25V3.75C1 2.784 1.784 2 2.75 2H4V.75A.75.75 0 0 1 4.75 0ZM2.5 7.5v6.75c0 .138.112.25.25.25h10.5a.25.25 0 0 0 .25-.25V7.5Zm10.75-4H2.75a.25.25 0 0 0-.25.25V6h11V3.75a.25.25 0 0 0-.25-.25Z"],
271
332
  "comment-discussion": ["M1.75 1h8.5c.966 0 1.75.784 1.75 1.75v5.5A1.75 1.75 0 0 1 10.25 10H7.061l-2.574 2.573A1.458 1.458 0 0 1 2 11.543V10h-.25A1.75 1.75 0 0 1 0 8.25v-5.5C0 1.784.784 1 1.75 1ZM1.5 2.75v5.5c0 .138.112.25.25.25h1a.75.75 0 0 1 .75.75v2.19l2.72-2.72a.749.749 0 0 1 .53-.22h3.5a.25.25 0 0 0 .25-.25v-5.5a.25.25 0 0 0-.25-.25h-8.5a.25.25 0 0 0-.25.25Zm13 2a.25.25 0 0 0-.25-.25h-.5a.75.75 0 0 1 0-1.5h.5c.966 0 1.75.784 1.75 1.75v5.5A1.75 1.75 0 0 1 14.25 12H14v1.543a1.458 1.458 0 0 1-2.487 1.03L9.22 12.28a.749.749 0 0 1 .326-1.275.749.749 0 0 1 .734.215l2.22 2.22v-2.19a.75.75 0 0 1 .75-.75h1a.25.25 0 0 0 .25-.25Z"],
272
333
  person: ["M10.561 8.073a6.005 6.005 0 0 1 3.432 5.142.75.75 0 1 1-1.498.07 4.5 4.5 0 0 0-8.99 0 .75.75 0 0 1-1.498-.07 6.004 6.004 0 0 1 3.431-5.142 3.999 3.999 0 1 1 5.123 0ZM10.5 5a2.5 2.5 0 1 0-5 0 2.5 2.5 0 0 0 5 0Z"],
334
+ file: ["M2 1.75C2 .784 2.784 0 3.75 0h6.586c.464 0 .909.184 1.237.513l2.914 2.914c.329.328.513.773.513 1.237v9.586A1.75 1.75 0 0 1 13.25 16h-9.5A1.75 1.75 0 0 1 2 14.25Zm1.75-.25a.25.25 0 0 0-.25.25v12.5c0 .138.112.25.25.25h9.5a.25.25 0 0 0 .25-.25V6h-2.75A1.75 1.75 0 0 1 9 4.25V1.5Zm6.75.062V4.25c0 .138.112.25.25.25h2.688l-.011-.013-2.914-2.914-.013-.011Z"],
273
335
  comment: ["M1 2.75C1 1.784 1.784 1 2.75 1h10.5c.966 0 1.75.784 1.75 1.75v7.5A1.75 1.75 0 0 1 13.25 12H9.06l-2.573 2.573A1.458 1.458 0 0 1 4 13.543V12H2.75A1.75 1.75 0 0 1 1 10.25Zm1.75-.25a.25.25 0 0 0-.25.25v7.5c0 .138.112.25.25.25h2a.75.75 0 0 1 .75.75v2.19l2.72-2.72a.749.749 0 0 1 .53-.22h4.5a.25.25 0 0 0 .25-.25v-7.5a.25.25 0 0 0-.25-.25Z"],
336
+ globe: ["M8 0a8 8 0 1 1 0 16A8 8 0 0 1 8 0ZM5.78 8.75a9.64 9.64 0 0 0 1.363 4.177c.255.426.542.832.857 1.215.245-.296.551-.705.857-1.215A9.64 9.64 0 0 0 10.22 8.75Zm4.44-1.5a9.64 9.64 0 0 0-1.363-4.177c-.307-.51-.612-.919-.857-1.215a9.927 9.927 0 0 0-.857 1.215A9.64 9.64 0 0 0 5.78 7.25Zm-5.944 1.5H1.543a6.507 6.507 0 0 0 4.666 5.5c-.123-.181-.24-.365-.352-.552-.715-1.192-1.437-2.874-1.581-4.948Zm-2.733-1.5h2.733c.144-2.074.866-3.756 1.58-4.948.12-.197.237-.381.353-.552a6.507 6.507 0 0 0-4.666 5.5Zm10.181 1.5c-.144 2.074-.866 3.756-1.58 4.948-.12.197-.237.381-.353.552a6.507 6.507 0 0 0 4.666-5.5Zm2.733-1.5a6.507 6.507 0 0 0-4.666-5.5c.123.181.24.365.353.552.714 1.192 1.436 2.874 1.58 4.948Z"],
274
337
  package: ["m8.878.392 5.25 3.045c.54.314.872.89.872 1.514v6.098a1.75 1.75 0 0 1-.872 1.514l-5.25 3.045a1.75 1.75 0 0 1-1.756 0l-5.25-3.045A1.75 1.75 0 0 1 1 11.049V4.951c0-.624.332-1.201.872-1.514L7.122.392a1.75 1.75 0 0 1 1.756 0ZM7.875 1.69l-4.63 2.685L8 7.133l4.755-2.758-4.63-2.685a.248.248 0 0 0-.25 0ZM2.5 5.677v5.372c0 .09.047.171.125.216l4.625 2.683V8.432Zm6.25 8.271 4.625-2.683a.25.25 0 0 0 .125-.216V5.677L8.75 8.432Z"]
275
338
  };
339
+ // src/images.ts
340
+ const objectImageRefSchema = z.object({
341
+ key: z.string().min(1),
342
+ url: z.string().min(1)
343
+ }).strict();
344
+ /** Return the image source ref of one object preview image. */
345
+ function encodeObjectImageRef(image) {
346
+ return JSON.stringify({
347
+ key: image.key,
348
+ url: image.url
349
+ });
350
+ }
351
+ /**
352
+ * Return the object preview image of an image source ref, or nothing when
353
+ * the ref names another kind of image.
354
+ */
355
+ function decodeObjectImageRef(ref) {
356
+ try {
357
+ const parsed = objectImageRefSchema.safeParse(JSON.parse(ref));
358
+ return parsed.success ? parsed.data : void 0;
359
+ } catch {
360
+ return;
361
+ }
362
+ }
276
363
  // src/object-links.ts
277
364
  /**
278
365
  * Link types: URLs that a plugin or core can show as object cards.
@@ -1912,6 +1999,7 @@ function defineJuniorPlugin(plugin) {
1912
1999
  if (!parsed.success) throw new Error(`Junior plugin "${name}" events is invalid.`, { cause: parsed.error });
1913
2000
  }
1914
2001
  validateObjectLinks(name, plugin.objectLinks);
2002
+ if (plugin.images !== void 0 && typeof plugin.images.resolve !== "function") throw new Error(`Junior plugin "${name}" images must have a resolve function.`);
1915
2003
  const conversationEventIds = /* @__PURE__ */ new Set();
1916
2004
  for (const event of plugin.conversationEvents ?? []) {
1917
2005
  if (!event || typeof event !== "object" && typeof event !== "function" || typeof event.parse !== "function" || typeof event.renderEvent !== "function") throw new Error(`Junior plugin "${name}" conversation event definitions must be created with defineConversationEvent().`);
@@ -1936,7 +2024,7 @@ function validateObjectLinks(name, links) {
1936
2024
  if (links === void 0) return;
1937
2025
  if (!Array.isArray(links)) throw new Error(`Junior plugin "${name}" objectLinks must be an array.`);
1938
2026
  for (const link of links) {
1939
- if (!objectTypeSchema.safeParse(link?.objectType).success || typeof link.resolve !== "function" || !Array.isArray(link.filters) || link.filters.length === 0) throw new Error(`Junior plugin "${name}" object links need an objectType, filters, and a resolve function.`);
2027
+ if (!objectTypeSchema.safeParse(link?.objectType).success || typeof link.canView !== "function" || typeof link.resolve !== "function" || !Array.isArray(link.filters) || link.filters.length === 0) throw new Error(`Junior plugin "${name}" object links need an objectType, filters, a canView function, and a resolve function.`);
1940
2028
  for (const filter of link.filters) {
1941
2029
  const parsed = objectLinkFilterSchema.safeParse(filter);
1942
2030
  if (!parsed.success) throw new Error(`Junior plugin "${name}" has an invalid ${link.objectType} link filter.`, { cause: parsed.error });
@@ -2021,4 +2109,4 @@ const pluginUserPageInputSchema = z.object({
2021
2109
  limit: z.number().int().min(1).max(50),
2022
2110
  query: pluginUserPageQuerySchema
2023
2111
  }).strict();
2024
- export { EVENT_DATA_MAX_JSON_BYTES, EVENT_DATA_MAX_KEYS, EVENT_GUIDANCE_MAX_LENGTH, EVENT_SUMMARY_MAX_LENGTH, EVENT_TEXT_MAX_LENGTH, EgressAuthRequired, EgressPolicyDenied, OBJECT_FACTS_MAX_BYTES, 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, isPluginModelCostEventName, isPrivateSource, isSlackDestination, localActorSchema, localDestinationSchema, localSourceSchema, locationSchema, mergeEventMatchFields, missingToolAnnotationKeys, nonBlankStringSchema, normalizeEventIdentifier, normalizeEventMatch, objectAnnotationSchema, objectFactFields, objectFactsBytes, objectFactsMatchType, objectFactsSchema, objectIconPath, objectIconPaths, objectLinkFilterMatches, objectLinkFilterSchema, objectLinkFilterSpecificity, objectPresentation, objectTypeSchema, ownedObjectAnnotationSchema, parseShellCommands, platformSchema, pluginApiRouteRequestContextSchema, pluginAuditAttributesSchema, pluginAuthorizationSchema, pluginCredentialHeaderTransformSchema, pluginCredentialLeaseSchema, pluginCredentialResultSchema, pluginCredentialSubjectSchema, pluginDispatchSourceSchema, pluginEventDeclarationSchema, pluginEventTypeSchema, pluginEventsSchema, pluginGrantSchema, pluginModelCostEventNames, pluginProviderAccountSchema, pluginRunContextSchema, pluginRunTranscriptEntrySchema, pluginRunTranscriptProvenanceSchema, pluginStoredTokensSchema, pluginToolContentSchema, pluginToolContinuationSchema, pluginToolOutputSchema, pluginToolReplySchema, 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 };
2112
+ export { EVENT_DATA_MAX_JSON_BYTES, EVENT_DATA_MAX_KEYS, EVENT_GUIDANCE_MAX_LENGTH, EVENT_SUMMARY_MAX_LENGTH, EVENT_TEXT_MAX_LENGTH, EgressAuthRequired, EgressPolicyDenied, OBJECT_FACTS_MAX_BYTES, OBJECT_SUMMARY_MAX_LENGTH, 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, decodeObjectImageRef, defineConversationEvent, defineJuniorPlugin, definePluginTool, definePromptContext, describeEventTrigger, destinationSchema, destinationVisibilitySchema, dispatchOptionsSchema, encodeObjectImageRef, enforceEgressPolicy, eventAutomationSourceSchema, eventDataSchema, eventIdentifierSchema, eventInputSchema, eventMatchFieldSchema, eventMatchFieldsSchema, eventMatchFilterText, eventMatchSchema, eventMatches, eventPersonSchema, eventReachSchema, eventSchema, eventSourceSchema, eventTriggerChoices, eventTriggerFiltersText, eventTriggerProblems, eventTriggerText, eventTypeSchema, eventTypeText, eventsWithoutMatchField, getSourceKey, identitySchema, isPluginModelCostEventName, isPrivateSource, isSlackDestination, localActorSchema, localDestinationSchema, localSourceSchema, locationSchema, mergeEventMatchFields, missingToolAnnotationKeys, nonBlankStringSchema, normalizeEventIdentifier, normalizeEventMatch, objectAnnotationSchema, objectFactFields, objectFactsBytes, objectFactsMatchType, objectFactsSchema, objectIconPath, objectIconPaths, objectLinkFilterMatches, objectLinkFilterSchema, objectLinkFilterSpecificity, objectPresentation, objectSummary, objectTypeSchema, ownedObjectAnnotationSchema, parseShellCommands, platformSchema, pluginApiRouteRequestContextSchema, pluginAuditAttributesSchema, pluginAuthorizationSchema, pluginCredentialHeaderTransformSchema, pluginCredentialLeaseSchema, pluginCredentialResultSchema, pluginCredentialSubjectSchema, pluginDispatchSourceSchema, pluginEventDeclarationSchema, pluginEventTypeSchema, pluginEventsSchema, pluginGrantSchema, pluginModelCostEventNames, pluginProviderAccountSchema, pluginRunContextSchema, pluginRunTranscriptEntrySchema, pluginRunTranscriptProvenanceSchema, pluginStoredTokensSchema, pluginToolContentSchema, pluginToolContinuationSchema, pluginToolOutputSchema, pluginToolReplySchema, 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.299.0",
3
+ "version": "0.301.0",
4
4
  "private": false,
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -23,7 +23,7 @@
23
23
  ],
24
24
  "dependencies": {
25
25
  "commander": "^14.0.3",
26
- "zod": "^4.5.4"
26
+ "zod": "^4.6.7"
27
27
  },
28
28
  "devDependencies": {
29
29
  "@oxlint/plugins": "1.79.0",