@sentry/junior-plugin-api 0.300.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.
package/dist/index.d.ts CHANGED
@@ -860,29 +860,6 @@ export declare function isPrivateSource(source: Source): boolean;
860
860
  export declare function getSourceKey(source: Source): string | undefined;
861
861
  /** Narrow a runtime destination to the Slack-specific address shape. */
862
862
  export declare function isSlackDestination(destination: Destination | undefined): destination is SlackDestination;
863
- /** How Junior fetches one image. */
864
- export interface ImageFetch {
865
- /**
866
- * Request headers, such as the plugin's credential. Junior sends them only
867
- * to the origin of `url`, not after a redirect to another origin.
868
- */
869
- headers?: Record<string, string>;
870
- url: string;
871
- }
872
- /** Trusted host context for one image read. */
873
- export interface ImageSourceContext extends PluginContext {
874
- /** The signed-in person who sees the image. */
875
- viewer: User;
876
- }
877
- /**
878
- * Images that a plugin serves through the Junior image proxy. `resolve`
879
- * checks that the viewer may see the image and returns how to fetch it.
880
- * Return nothing when the viewer cannot see it. Junior checks the address,
881
- * the type, and the size of each image, and caches it for every viewer.
882
- */
883
- export interface PluginImageSource {
884
- resolve(ctx: ImageSourceContext, ref: string): Promise<ImageFetch | undefined>;
885
- }
886
863
  declare const pluginGrantAccessSchema: z.ZodUnion<readonly [z.ZodLiteral<"read">, z.ZodLiteral<"write">]>;
887
864
  /** Runtime schema for provider authorization a plugin may request. */
888
865
  export declare const pluginAuthorizationSchema: z.ZodObject<{
@@ -2262,6 +2239,13 @@ interface BaseToolRegistrationHookContext extends PluginContext {
2262
2239
  * Junior knows it, else the install default. Always returns a timezone.
2263
2240
  */
2264
2241
  resolveTimezone(): Promise<string>;
2242
+ /**
2243
+ * Rewrite Slack mention syntax in every string of `value`, such as a tool
2244
+ * input that goes to `provider`. A Slack user becomes `@handle` of their
2245
+ * linked `provider` account, or else their name. Markdown code stays as
2246
+ * written. Call it before you send model text out.
2247
+ */
2248
+ replaceSlackMentions<T>(value: T, provider: string): Promise<T>;
2265
2249
  };
2266
2250
  userText?: string;
2267
2251
  workspaces: PluginWorkspaceToolContext;
@@ -2270,6 +2254,62 @@ export type ToolRegistrationHookContext = BaseToolRegistrationHookContext & Invo
2270
2254
  /** Slack tool details when the Conversation has a Slack Location. */
2271
2255
  slack?: SlackToolRegistrationHookContext;
2272
2256
  };
2257
+ /** How Junior fetches one image. */
2258
+ export interface ImageFetch {
2259
+ /**
2260
+ * Request headers, such as the plugin's credential. Junior sends them only
2261
+ * to the origin of `url`, not after a redirect to another origin.
2262
+ */
2263
+ headers?: Record<string, string>;
2264
+ /**
2265
+ * Return the address to fetch instead of `url`, such as a short-lived
2266
+ * signed URL that the plugin reads through egress. Junior calls it only
2267
+ * when it fetches the image, not when it serves a cached copy, and sends
2268
+ * no `headers` to it. `url` stays the identity of the cached image.
2269
+ * Return nothing when the image is gone.
2270
+ */
2271
+ location?: () => Promise<string | undefined>;
2272
+ url: string;
2273
+ }
2274
+ /** Trusted host context for one image read. */
2275
+ export interface ImageSourceContext extends PluginContext {
2276
+ /**
2277
+ * Provider egress as a system Actor. It gets only credentials that the
2278
+ * plugin owns, such as an app, and never the viewer's credentials. Check
2279
+ * that the viewer may see the image before you fetch it.
2280
+ */
2281
+ egress: PluginEgress;
2282
+ /** The signed-in person who sees the image. */
2283
+ viewer: User;
2284
+ }
2285
+ /**
2286
+ * Images that a plugin serves through the Junior image proxy. `resolve`
2287
+ * checks that the viewer may see the image and returns how to fetch it.
2288
+ * Return nothing when the viewer cannot see it. Junior checks the address,
2289
+ * the type, and the size of each image, and caches it for every viewer.
2290
+ * The preview images of the plugin's object annotations come with refs from
2291
+ * `encodeObjectImageRef`.
2292
+ */
2293
+ export interface PluginImageSource {
2294
+ resolve(ctx: ImageSourceContext, ref: string): Promise<ImageFetch | undefined>;
2295
+ }
2296
+ declare const objectImageRefSchema: z.ZodObject<{
2297
+ key: z.ZodString;
2298
+ url: z.ZodString;
2299
+ }, z.core.$strict>;
2300
+ /**
2301
+ * One preview image of an object annotation, such as `previewImageUrls` of a
2302
+ * code change. `key` is the annotation key, so the plugin can check that the
2303
+ * viewer may see that object.
2304
+ */
2305
+ export type ObjectImageRef = z.output<typeof objectImageRefSchema>;
2306
+ /** Return the image source ref of one object preview image. */
2307
+ export declare function encodeObjectImageRef(image: ObjectImageRef): string;
2308
+ /**
2309
+ * Return the object preview image of an image source ref, or nothing when
2310
+ * the ref names another kind of image.
2311
+ */
2312
+ export declare function decodeObjectImageRef(ref: string): ObjectImageRef | undefined;
2273
2313
  /** Which URLs a link type claims. Give at most one path field. */
2274
2314
  export declare const objectLinkFilterSchema: z.ZodObject<{
2275
2315
  scheme: z.ZodOptional<z.ZodEnum<{
@@ -2300,17 +2340,36 @@ export interface ObjectLinkContext extends PluginContext {
2300
2340
  * you return it.
2301
2341
  */
2302
2342
  egress: PluginEgress;
2343
+ /**
2344
+ * Return the Junior person card of the one known person with this
2345
+ * provider account, or undefined. Return it for a profile link of that
2346
+ * account, so the card shows the person and not only the account.
2347
+ */
2348
+ findPerson(account: {
2349
+ handle: string;
2350
+ provider: string;
2351
+ }): Promise<ObjectAnnotation | undefined>;
2303
2352
  /** The signed-in person who sees the card. */
2304
2353
  viewer: User;
2305
2354
  }
2306
2355
  /**
2307
- * One link type of a plugin. Return nothing when the viewer cannot read the
2308
- * object, so the card does not show that it exists. Junior does not save the
2309
- * result.
2356
+ * One link type of a plugin. Junior calls `canView` first, and calls
2357
+ * `resolve` only when it returns true. Junior does not save the result.
2310
2358
  */
2311
2359
  export interface PluginObjectLinkDefinition {
2360
+ /**
2361
+ * Return whether `ctx.viewer` may see the object. Junior calls it before
2362
+ * each card read and again on each Attach. Return true for a public
2363
+ * object. Return false when you cannot tell, so the card does not show
2364
+ * that the object exists.
2365
+ */
2366
+ canView(ctx: ObjectLinkContext, url: URL): Promise<boolean>;
2312
2367
  filters: ObjectLinkFilter[];
2313
2368
  objectType: ObjectType;
2369
+ /**
2370
+ * Read the card. Junior calls it only after `canView` returns true.
2371
+ * Return nothing for a missing object.
2372
+ */
2314
2373
  resolve(ctx: ObjectLinkContext, url: URL): Promise<ObjectAnnotation | undefined>;
2315
2374
  /**
2316
2375
  * The plugin tool that reads the object live, such as `readGoogleFile`.
@@ -3156,6 +3215,32 @@ export declare function enforceEgressPolicy(input: {
3156
3215
  export declare function parseShellCommands(text: string): string[][];
3157
3216
  /** Input for a pure Markdown rewrite before destination delivery formatting. */
3158
3217
  export interface FormatMarkdownHookContext {
3218
+ /**
3219
+ * String config values of this plugin for the Conversation's Location, by
3220
+ * short key, over install defaults. Runtime notices get install defaults.
3221
+ */
3222
+ config: Record<string, string>;
3223
+ /**
3224
+ * Return the destination's mention of the one known person who has this
3225
+ * provider account, or undefined. Core resolves the `@handle` words in
3226
+ * `text` before the hook runs. Insert the result as is. Only Slack text
3227
+ * gets mentions: Slack syntax never goes to another place.
3228
+ */
3229
+ mention(account: {
3230
+ provider: string;
3231
+ handle: string;
3232
+ }): string | undefined;
3233
+ /**
3234
+ * Where the text shows: a Slack message, or the dashboard (`web`). The
3235
+ * dashboard shows a bare object link as a card, so keep bare links there.
3236
+ */
3237
+ platform: "slack" | "web";
3238
+ /**
3239
+ * The provider that wrote the text or that it went to, such as `github`
3240
+ * for a GitHub Event or a comment posted to GitHub. In that text, every
3241
+ * `@name` is an account of that provider. Undefined for chat replies.
3242
+ */
3243
+ provider?: string;
3159
3244
  text: string;
3160
3245
  }
3161
3246
  /** First human message of a new Conversation, given before title generation. */
package/dist/index.js CHANGED
@@ -29,8 +29,9 @@ const objectFactsSchema = z.discriminatedUnion("type", [
29
29
  additions: count.optional(),
30
30
  deletions: count.optional(),
31
31
  /**
32
- * Public images from the description that the dashboard can show. The
33
- * 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.
34
35
  */
35
36
  previewImageUrls: z.array(z.url({ protocol: /^https?$/ }).max(512)).min(1).optional()
36
37
  }),
@@ -335,6 +336,30 @@ const objectIconPaths = {
335
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"],
336
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"]
337
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
+ }
338
363
  // src/object-links.ts
339
364
  /**
340
365
  * Link types: URLs that a plugin or core can show as object cards.
@@ -1999,7 +2024,7 @@ function validateObjectLinks(name, links) {
1999
2024
  if (links === void 0) return;
2000
2025
  if (!Array.isArray(links)) throw new Error(`Junior plugin "${name}" objectLinks must be an array.`);
2001
2026
  for (const link of links) {
2002
- 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.`);
2003
2028
  for (const filter of link.filters) {
2004
2029
  const parsed = objectLinkFilterSchema.safeParse(filter);
2005
2030
  if (!parsed.success) throw new Error(`Junior plugin "${name}" has an invalid ${link.objectType} link filter.`, { cause: parsed.error });
@@ -2084,4 +2109,4 @@ const pluginUserPageInputSchema = z.object({
2084
2109
  limit: z.number().int().min(1).max(50),
2085
2110
  query: pluginUserPageQuerySchema
2086
2111
  }).strict();
2087
- 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, 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, 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 };
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.300.0",
3
+ "version": "0.301.0",
4
4
  "private": false,
5
5
  "publishConfig": {
6
6
  "access": "public"