@sentry/junior-plugin-api 0.314.0 → 0.315.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
@@ -24,12 +24,12 @@ export declare const objectFactsSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
24
24
  changes_requested: "changes_requested";
25
25
  required: "required";
26
26
  }>>;
27
- checks: z.ZodOptional<z.ZodObject<{
27
+ checks: z.ZodOptional<z.ZodUnion<readonly [z.ZodObject<{
28
28
  passed: z.ZodNumber;
29
29
  failed: z.ZodNumber;
30
30
  pending: z.ZodNumber;
31
- }, z.core.$strict>>;
32
- mergeable: z.ZodOptional<z.ZodBoolean>;
31
+ }, z.core.$strict>, z.ZodLiteral<"pending">]>>;
32
+ mergeable: z.ZodOptional<z.ZodUnion<readonly [z.ZodBoolean, z.ZodLiteral<"pending">]>>;
33
33
  changedFiles: z.ZodOptional<z.ZodNumber>;
34
34
  additions: z.ZodOptional<z.ZodNumber>;
35
35
  deletions: z.ZodOptional<z.ZodNumber>;
@@ -318,12 +318,12 @@ export declare const objectAnnotationSchema: z.ZodObject<{
318
318
  changes_requested: "changes_requested";
319
319
  required: "required";
320
320
  }>>;
321
- checks: z.ZodOptional<z.ZodObject<{
321
+ checks: z.ZodOptional<z.ZodUnion<readonly [z.ZodObject<{
322
322
  passed: z.ZodNumber;
323
323
  failed: z.ZodNumber;
324
324
  pending: z.ZodNumber;
325
- }, z.core.$strict>>;
326
- mergeable: z.ZodOptional<z.ZodBoolean>;
325
+ }, z.core.$strict>, z.ZodLiteral<"pending">]>>;
326
+ mergeable: z.ZodOptional<z.ZodUnion<readonly [z.ZodBoolean, z.ZodLiteral<"pending">]>>;
327
327
  changedFiles: z.ZodOptional<z.ZodNumber>;
328
328
  additions: z.ZodOptional<z.ZodNumber>;
329
329
  deletions: z.ZodOptional<z.ZodNumber>;
@@ -540,12 +540,12 @@ export declare const ownedObjectAnnotationSchema: z.ZodObject<{
540
540
  changes_requested: "changes_requested";
541
541
  required: "required";
542
542
  }>>;
543
- checks: z.ZodOptional<z.ZodObject<{
543
+ checks: z.ZodOptional<z.ZodUnion<readonly [z.ZodObject<{
544
544
  passed: z.ZodNumber;
545
545
  failed: z.ZodNumber;
546
546
  pending: z.ZodNumber;
547
- }, z.core.$strict>>;
548
- mergeable: z.ZodOptional<z.ZodBoolean>;
547
+ }, z.core.$strict>, z.ZodLiteral<"pending">]>>;
548
+ mergeable: z.ZodOptional<z.ZodUnion<readonly [z.ZodBoolean, z.ZodLiteral<"pending">]>>;
549
549
  changedFiles: z.ZodOptional<z.ZodNumber>;
550
550
  additions: z.ZodOptional<z.ZodNumber>;
551
551
  deletions: z.ZodOptional<z.ZodNumber>;
@@ -1049,6 +1049,12 @@ export declare const dispatchOptionsSchema: z.ZodObject<{
1049
1049
  export interface CacheEntry<T> {
1050
1050
  /** Omit to return the value without caching it, such as for an incomplete response. */
1051
1051
  ttlMs?: number;
1052
+ /**
1053
+ * Keep the value for a day after its TTL, and return it when a later load
1054
+ * throws, such as during a provider outage. Never set it on an answer
1055
+ * about access: access must expire with its TTL.
1056
+ */
1057
+ staleIfError?: boolean;
1052
1058
  /** Must survive JSON serialization. */
1053
1059
  value: T;
1054
1060
  }
@@ -1061,12 +1067,32 @@ export interface CacheEntry<T> {
1061
1067
  export interface PluginCache {
1062
1068
  /**
1063
1069
  * Return the cached value for `key`, or call `load` and cache its result.
1064
- * Concurrent callers share one load. A load that throws is not cached.
1070
+ * Concurrent callers share one load. A load that throws is not cached,
1071
+ * and it throws to the caller unless a `staleIfError` value is kept.
1065
1072
  * `refresh` ignores the cached value and replaces it.
1066
1073
  */
1074
+ /**
1075
+ * Return the fresh cached value of `key`, or `undefined` when there is
1076
+ * none. It never loads, so a caller can find the misses of many keys and
1077
+ * load them in one provider call.
1078
+ */
1079
+ get<T>(key: string): Promise<T | undefined>;
1067
1080
  getOrLoad<T>(key: string, load: () => Promise<CacheEntry<T>>, options?: {
1068
1081
  refresh?: boolean;
1069
1082
  }): Promise<T>;
1083
+ /**
1084
+ * Replace the cached value of `key` with the entry that `next` returns,
1085
+ * such as when a provider webhook carries the changed object. `next` gets
1086
+ * the cached value, also a stale one, or `undefined` when there is none.
1087
+ * Return nothing to keep the entry as it is. The entry's TTL, and its
1088
+ * `staleIfError` day, start again.
1089
+ */
1090
+ update<T>(key: string, next: (current: T | undefined) => CacheEntry<T> | undefined): Promise<void>;
1091
+ /**
1092
+ * Drop the cached value of `key`, so the next read loads it, such as when
1093
+ * a provider webhook says that the object moved.
1094
+ */
1095
+ delete(key: string): Promise<void>;
1070
1096
  }
1071
1097
  /** Runtime platform name without source or destination coordinates. */
1072
1098
  export type Platform = z.output<typeof platformSchema>;
@@ -1673,12 +1699,12 @@ export declare const conversationAnnotationInputSchema: z.ZodDiscriminatedUnion<
1673
1699
  changes_requested: "changes_requested";
1674
1700
  required: "required";
1675
1701
  }>>;
1676
- checks: z.ZodOptional<z.ZodObject<{
1702
+ checks: z.ZodOptional<z.ZodUnion<readonly [z.ZodObject<{
1677
1703
  passed: z.ZodNumber;
1678
1704
  failed: z.ZodNumber;
1679
1705
  pending: z.ZodNumber;
1680
- }, z.core.$strict>>;
1681
- mergeable: z.ZodOptional<z.ZodBoolean>;
1706
+ }, z.core.$strict>, z.ZodLiteral<"pending">]>>;
1707
+ mergeable: z.ZodOptional<z.ZodUnion<readonly [z.ZodBoolean, z.ZodLiteral<"pending">]>>;
1682
1708
  changedFiles: z.ZodOptional<z.ZodNumber>;
1683
1709
  additions: z.ZodOptional<z.ZodNumber>;
1684
1710
  deletions: z.ZodOptional<z.ZodNumber>;
@@ -1913,11 +1939,6 @@ export declare const conversationSidebarAnnotationSchema: z.ZodObject<{
1913
1939
  title: z.ZodOptional<z.ZodString>;
1914
1940
  url: z.ZodOptional<z.ZodString>;
1915
1941
  imageUrl: z.ZodOptional<z.ZodString>;
1916
- size: z.ZodOptional<z.ZodObject<{
1917
- changedFiles: z.ZodOptional<z.ZodNumber>;
1918
- additions: z.ZodOptional<z.ZodNumber>;
1919
- deletions: z.ZodOptional<z.ZodNumber>;
1920
- }, z.core.$strict>>;
1921
1942
  }, z.core.$strict>;
1922
1943
  export type ConversationSidebarAnnotation = z.output<typeof conversationSidebarAnnotationSchema>;
1923
1944
  export interface ConversationSidebarHookContext extends PluginContext {
@@ -1929,6 +1950,113 @@ export interface ConversationSidebarResult {
1929
1950
  /** Sidebar annotations in display order. Put the newest annotation first. */
1930
1951
  annotationsByConversationId: Record<string, ConversationSidebarAnnotation[]>;
1931
1952
  }
1953
+ export declare const codeChangeStateSchema: z.ZodEnum<{
1954
+ closed: "closed";
1955
+ merged: "merged";
1956
+ open: "open";
1957
+ }>;
1958
+ export type CodeChangeState = z.output<typeof codeChangeStateSchema>;
1959
+ export declare const codeChangeInputSchema: z.ZodObject<{
1960
+ closedAt: z.ZodOptional<z.ZodDate>;
1961
+ conversationIds: z.ZodDefault<z.ZodArray<z.ZodString>>;
1962
+ mergedAt: z.ZodOptional<z.ZodDate>;
1963
+ number: z.ZodNumber;
1964
+ openedAt: z.ZodDate;
1965
+ providerId: z.ZodString;
1966
+ repository: z.ZodObject<{
1967
+ name: z.ZodString;
1968
+ providerId: z.ZodString;
1969
+ }, z.core.$strict>;
1970
+ state: z.ZodEnum<{
1971
+ closed: "closed";
1972
+ merged: "merged";
1973
+ open: "open";
1974
+ }>;
1975
+ title: z.ZodOptional<z.ZodString>;
1976
+ updatedAt: z.ZodDate;
1977
+ }, z.core.$strict>;
1978
+ export type CodeChangeInput = z.input<typeof codeChangeInputSchema>;
1979
+ export declare const codeRepositoryInputSchema: z.ZodObject<{
1980
+ name: z.ZodString;
1981
+ providerId: z.ZodString;
1982
+ updatedAt: z.ZodDate;
1983
+ }, z.core.$strict>;
1984
+ export type CodeRepositoryInput = z.input<typeof codeRepositoryInputSchema>;
1985
+ export declare const codeChangeFilterSchema: z.ZodObject<{
1986
+ conversationIds: z.ZodOptional<z.ZodArray<z.ZodString>>;
1987
+ repository: z.ZodOptional<z.ZodObject<{
1988
+ name: z.ZodString;
1989
+ numbers: z.ZodOptional<z.ZodArray<z.ZodNumber>>;
1990
+ }, z.core.$strict>>;
1991
+ state: z.ZodOptional<z.ZodEnum<{
1992
+ closed: "closed";
1993
+ merged: "merged";
1994
+ open: "open";
1995
+ }>>;
1996
+ updatedBefore: z.ZodOptional<z.ZodDate>;
1997
+ }, z.core.$strict>;
1998
+ export type CodeChangeFilter = z.input<typeof codeChangeFilterSchema>;
1999
+ /** A code change of a plugin, as Junior's code records hold it now. */
2000
+ export interface CodeChange {
2001
+ closedAt: Date | undefined;
2002
+ conversationIds: string[];
2003
+ mergedAt: Date | undefined;
2004
+ number: number;
2005
+ providerId: string;
2006
+ repository: {
2007
+ name: string;
2008
+ providerId: string;
2009
+ };
2010
+ state: CodeChangeState;
2011
+ }
2012
+ /** A plugin's code changes in Junior's code records. */
2013
+ export interface PluginCodeChanges {
2014
+ associateConversations(input: {
2015
+ conversationIds: string[];
2016
+ providerId: string;
2017
+ }): Promise<void>;
2018
+ /**
2019
+ * Credit people as requesters of an existing code change: the person Work
2020
+ * owners of the Turns that opened or changed it. They add to the stored
2021
+ * ones, and a person's code changes include the ones that credit them.
2022
+ */
2023
+ associateRequesters(input: {
2024
+ identityIds: string[];
2025
+ providerId: string;
2026
+ }): Promise<void>;
2027
+ /**
2028
+ * List the code changes of this plugin that match every part of the
2029
+ * filter, oldest update first, in one read.
2030
+ */
2031
+ list(filter: CodeChangeFilter): Promise<CodeChange[]>;
2032
+ record(input: CodeChangeInput): Promise<void>;
2033
+ /**
2034
+ * Record the name of a repository that this plugin's code changes are in.
2035
+ * An older update does not move the name back.
2036
+ */
2037
+ recordRepository(input: CodeRepositoryInput): Promise<void>;
2038
+ /**
2039
+ * Record a push, review, or comment by a person on a code change. Junior
2040
+ * ignores activity on code changes that it did not record.
2041
+ */
2042
+ recordActivity(input: {
2043
+ at: Date;
2044
+ number: number;
2045
+ repositoryProviderId: string;
2046
+ }): Promise<void>;
2047
+ }
2048
+ /**
2049
+ * Build the web pages of a code plugin's repositories and code changes from
2050
+ * the repository name and the code change number, so Junior does not store
2051
+ * them.
2052
+ */
2053
+ export interface PluginCodeLinks {
2054
+ change(input: {
2055
+ number: number;
2056
+ repository: string;
2057
+ }): string;
2058
+ repository(name: string): string;
2059
+ }
1932
2060
  export declare const EVENT_SUMMARY_MAX_LENGTH = 4000;
1933
2061
  export declare const EVENT_TEXT_MAX_LENGTH = 8000;
1934
2062
  export declare const EVENT_DATA_MAX_KEYS = 32;
@@ -2642,12 +2770,12 @@ export declare const pluginToolOutputSchema: z.ZodObject<{
2642
2770
  changes_requested: "changes_requested";
2643
2771
  required: "required";
2644
2772
  }>>;
2645
- checks: z.ZodOptional<z.ZodObject<{
2773
+ checks: z.ZodOptional<z.ZodUnion<readonly [z.ZodObject<{
2646
2774
  passed: z.ZodNumber;
2647
2775
  failed: z.ZodNumber;
2648
2776
  pending: z.ZodNumber;
2649
- }, z.core.$strict>>;
2650
- mergeable: z.ZodOptional<z.ZodBoolean>;
2777
+ }, z.core.$strict>, z.ZodLiteral<"pending">]>>;
2778
+ mergeable: z.ZodOptional<z.ZodUnion<readonly [z.ZodBoolean, z.ZodLiteral<"pending">]>>;
2651
2779
  changedFiles: z.ZodOptional<z.ZodNumber>;
2652
2780
  additions: z.ZodOptional<z.ZodNumber>;
2653
2781
  deletions: z.ZodOptional<z.ZodNumber>;
@@ -3004,7 +3132,7 @@ export interface PluginConversationMatch {
3004
3132
  * working. idle: waits for a message. A failed Turn shows as idle.
3005
3133
  */
3006
3134
  status: "pending" | "running" | "paused" | "idle";
3007
- /** Summary of the latest Brief, when it has one. */
3135
+ /** Conversation summary, when it has one. */
3008
3136
  summary?: string;
3009
3137
  title?: string;
3010
3138
  /** ISO time of the latest activity. */
@@ -3073,6 +3201,8 @@ interface BaseToolRegistrationHookContext extends PluginContext {
3073
3201
  * started the root. Returns nothing when nobody did.
3074
3202
  */
3075
3203
  resolveWorkOwner(): Promise<PluginWorkOwner | undefined>;
3204
+ /** The plugin's code changes in Junior's code records. */
3205
+ codeChanges: PluginCodeChanges;
3076
3206
  /** Host-owned dashboard link to this conversation, when the dashboard is enabled. */
3077
3207
  conversationLink?: {
3078
3208
  url: string;
@@ -3201,6 +3331,11 @@ export declare function objectLinkFilterMatches(filter: ObjectLinkFilter, url: U
3201
3331
  * and then the longer match.
3202
3332
  */
3203
3333
  export declare function objectLinkFilterSpecificity(filter: ObjectLinkFilter): number[];
3334
+ /**
3335
+ * What `prefetch` did for one URL. `out_of_time`: the page's time ran out
3336
+ * before the object loaded, so its card shows only what the cache holds.
3337
+ */
3338
+ export type ObjectLinkPrefetchOutcome = "out_of_time";
3204
3339
  /** Trusted host context for one link resolution. */
3205
3340
  export interface ObjectLinkContext extends PluginContext {
3206
3341
  /**
@@ -3245,12 +3380,24 @@ export interface ObjectLinkContext extends PluginContext {
3245
3380
  * MCP.
3246
3381
  */
3247
3382
  viewerMcp: PluginViewerMcp;
3383
+ /**
3384
+ * What `prefetch` returned for this URL, in `canView` and `resolve` of
3385
+ * the same page read. Absent in every other read, such as an Attach, so
3386
+ * that read asks the provider as usual.
3387
+ */
3388
+ prefetchOutcome?: ObjectLinkPrefetchOutcome;
3248
3389
  }
3249
3390
  /**
3250
3391
  * One link type of a plugin. Junior calls `canView` first, and calls
3251
3392
  * `resolve` only when it returns true. Junior does not save the result.
3252
3393
  */
3253
3394
  export interface PluginObjectLinkDefinition {
3395
+ /**
3396
+ * Set false when `resolve` reads one cache entry per object that your
3397
+ * webhooks keep current. Junior then keeps no card copy per viewer, so a
3398
+ * change shows on the next read. `canView` still runs on each read.
3399
+ */
3400
+ cacheCards?: false;
3254
3401
  /**
3255
3402
  * Return whether `ctx.viewer` may see the object. Junior calls it before
3256
3403
  * each card read and again on each Attach. Return true for a public
@@ -3264,6 +3411,16 @@ export interface PluginObjectLinkDefinition {
3264
3411
  * one type, such as a GitHub issue URL that opens a pull request.
3265
3412
  */
3266
3413
  objectTypes: ObjectType[];
3414
+ /**
3415
+ * Load many objects into your cache in one provider call, such as one
3416
+ * query for a page of links. Junior calls it once with every URL of one
3417
+ * resolve that this link type claims, before `canView` and `resolve` run
3418
+ * for each URL as usual. Write only to the cache, and never return data:
3419
+ * the viewer may not see every object. Return the outcome of each URL
3420
+ * that its card read must know about, keyed by `url.href`. Junior passes
3421
+ * it to that URL's `canView` and `resolve` as `ctx.prefetchOutcome`.
3422
+ */
3423
+ prefetch?(ctx: ObjectLinkContext, urls: URL[]): Promise<ReadonlyMap<string, ObjectLinkPrefetchOutcome> | void>;
3267
3424
  /**
3268
3425
  * Read the card. Junior calls it only after `canView` returns true.
3269
3426
  * Return nothing for a missing object.
@@ -3284,67 +3441,6 @@ export interface PluginObjectLinkDefinition {
3284
3441
  */
3285
3442
  readTool?(object: ObjectAnnotation): string | undefined;
3286
3443
  }
3287
- export declare const codeChangeStateSchema: z.ZodEnum<{
3288
- closed: "closed";
3289
- merged: "merged";
3290
- open: "open";
3291
- }>;
3292
- export type CodeChangeState = z.output<typeof codeChangeStateSchema>;
3293
- export declare const codeChangeInputSchema: z.ZodObject<{
3294
- closedAt: z.ZodOptional<z.ZodDate>;
3295
- conversationIds: z.ZodDefault<z.ZodArray<z.ZodString>>;
3296
- draft: z.ZodOptional<z.ZodBoolean>;
3297
- mergedAt: z.ZodOptional<z.ZodDate>;
3298
- number: z.ZodNumber;
3299
- openedAt: z.ZodDate;
3300
- providerId: z.ZodString;
3301
- repository: z.ZodObject<{
3302
- name: z.ZodString;
3303
- providerId: z.ZodString;
3304
- }, z.core.$strict>;
3305
- size: z.ZodOptional<z.ZodObject<{
3306
- changedFiles: z.ZodOptional<z.ZodNumber>;
3307
- additions: z.ZodOptional<z.ZodNumber>;
3308
- deletions: z.ZodOptional<z.ZodNumber>;
3309
- }, z.core.$strict>>;
3310
- state: z.ZodEnum<{
3311
- closed: "closed";
3312
- merged: "merged";
3313
- open: "open";
3314
- }>;
3315
- title: z.ZodOptional<z.ZodString>;
3316
- updatedAt: z.ZodDate;
3317
- }, z.core.$strict>;
3318
- export type CodeChangeInput = z.input<typeof codeChangeInputSchema>;
3319
- /** Write code changes from a plugin to Junior's code records. */
3320
- export interface CodeChangePublisher {
3321
- associateConversations(input: {
3322
- conversationIds: string[];
3323
- providerId: string;
3324
- }): Promise<void>;
3325
- record(input: CodeChangeInput): Promise<void>;
3326
- /**
3327
- * Record a push, review, or comment by a person on a code change. Junior
3328
- * ignores activity on code changes that it did not record.
3329
- */
3330
- recordActivity(input: {
3331
- at: Date;
3332
- number: number;
3333
- repositoryProviderId: string;
3334
- }): Promise<void>;
3335
- }
3336
- /**
3337
- * Build the web pages of a code plugin's repositories and code changes from
3338
- * the repository name and the code change number, so Junior does not store
3339
- * them.
3340
- */
3341
- export interface PluginCodeLinks {
3342
- change(input: {
3343
- number: number;
3344
- repository: string;
3345
- }): string;
3346
- repository(name: string): string;
3347
- }
3348
3444
  /** Most entries in one batch, annotations and Inbox items together. */
3349
3445
  export declare const MAX_CONVERSATION_CHANGES = 100;
3350
3446
  /** Add or replace one annotation of this plugin on a Conversation. */
@@ -3533,8 +3629,12 @@ export declare function definePromptContext<TSchema extends z.ZodType<Record<str
3533
3629
  }): (content: z.input<TSchema>) => PromptContextContribution;
3534
3630
  /** One request-scoped plugin contribution to the model-visible user prompt. */
3535
3631
  type UserPromptContribution = PromptMessage | PromptContextContribution;
3536
- /** Stable platform context for plugin system prompt guidance. */
3537
- type SystemPromptContext = Pick<PluginContext, "db" | "log" | "plugin"> & {
3632
+ /**
3633
+ * What a plugin `systemPrompt` hook gets: the platform of the system prompts
3634
+ * that it adds to. It has no database or cache. A plugin that needs data does
3635
+ * its own I/O.
3636
+ */
3637
+ type SystemPromptBuildContext = Pick<PluginContext, "log" | "plugin"> & {
3538
3638
  platform: Platform;
3539
3639
  };
3540
3640
  /** One prompt context that this plugin gave an earlier Turn. */
@@ -4075,12 +4175,55 @@ export interface PluginTaskContext extends PluginContext {
4075
4175
  /** Events that this plugin emitted in the completed Turn, oldest first. */
4076
4176
  turnEvents: PluginTurnEventReader;
4077
4177
  }
4078
- /** Plugin task handler registered by name in a plugin manifest module. */
4079
- export interface PluginTaskDefinition {
4178
+ /** Task that Junior runs after each completed session. */
4179
+ export interface PluginSessionTaskDefinition {
4180
+ payload?: undefined;
4080
4181
  run(ctx: PluginTaskContext): Promise<void> | void;
4081
4182
  }
4183
+ /** Runtime context passed to one attempt of a task that `tasks.start` started. */
4184
+ export interface PluginStartedTaskContext<Payload = unknown> extends PluginContext {
4185
+ annotations: PluginConversationAnnotations;
4186
+ codeChanges: PluginCodeChanges;
4187
+ conversationChanges: PluginConversationChanges;
4188
+ /** Publishes the plugin's Events, as the heartbeat and routes do. */
4189
+ events: EventPublisher;
4190
+ /**
4191
+ * True on the last delivery that Junior makes. An attempt that throws
4192
+ * now is not run again, so a task that waits for a provider can write
4193
+ * its fallback instead.
4194
+ */
4195
+ lastDelivery: boolean;
4196
+ name: string;
4197
+ /** The payload from `tasks.start`, parsed with the task's `payload` schema. */
4198
+ payload: Payload;
4199
+ state: PluginState;
4200
+ }
4201
+ /**
4202
+ * Task that runs only when the plugin starts it with `tasks.start`. Junior
4203
+ * sends the payload as JSON in the queue message and parses it with
4204
+ * `payload` before each attempt. A failed attempt runs again later, a
4205
+ * bounded number of times.
4206
+ */
4207
+ export interface PluginStartedTaskDefinition<Schema extends z.ZodType = z.ZodType> {
4208
+ payload: Schema;
4209
+ run(ctx: PluginStartedTaskContext<z.output<Schema>>): Promise<void> | void;
4210
+ }
4211
+ /** Plugin task handler registered by name in a plugin manifest module. */
4212
+ export type PluginTaskDefinition = PluginSessionTaskDefinition | PluginStartedTaskDefinition;
4082
4213
  /** Task handlers keyed by the plugin-owned task name. */
4083
4214
  export type PluginTasks = Record<string, PluginTaskDefinition>;
4215
+ /** Input of `tasks.start`. */
4216
+ export declare const pluginTaskStartInputSchema: z.ZodObject<{
4217
+ key: z.ZodString;
4218
+ name: z.ZodString;
4219
+ delaySeconds: z.ZodOptional<z.ZodNumber>;
4220
+ payload: z.ZodUnknown;
4221
+ }, z.core.$strict>;
4222
+ export type PluginTaskStartInput = z.output<typeof pluginTaskStartInputSchema>;
4223
+ /** Starts this plugin's tasks on the plugin task queue. */
4224
+ export interface PluginTaskStarter {
4225
+ start(input: PluginTaskStartInput): Promise<void>;
4226
+ }
4084
4227
  /**
4085
4228
  * A code change title split by Conventional Commits, such as
4086
4229
  * `feat(api)!: Add retries`. The plugin that owns the code change parses it,
@@ -4172,6 +4315,8 @@ export interface PluginConversationInboxItems {
4172
4315
  export interface InboxItemAnsweredHookContext extends PluginContext {
4173
4316
  /** The label of the picked choice. */
4174
4317
  choice: string;
4318
+ /** Junior's native code index, as from a plugin route. */
4319
+ codeChanges: PluginCodeChanges;
4175
4320
  /** The Conversation that the item belongs to. */
4176
4321
  conversationId: string;
4177
4322
  /** The plugin's own dedupe key of the item. */
@@ -4212,7 +4357,7 @@ export interface HeartbeatHookContext extends PluginContext {
4212
4357
  /** Conversation annotations, as from a plugin route. */
4213
4358
  annotations: PluginConversationAnnotations;
4214
4359
  /** Junior's native code index, as from a plugin route. */
4215
- codeChanges: CodeChangePublisher;
4360
+ codeChanges: PluginCodeChanges;
4216
4361
  /** Annotation and Inbox item changes in one write, as from a plugin route. */
4217
4362
  conversationChanges: PluginConversationChanges;
4218
4363
  /** Host embedder bound to the configured embedding model. */
@@ -4223,11 +4368,15 @@ export interface HeartbeatHookContext extends PluginContext {
4223
4368
  /** Inbox items, as from a plugin route. */
4224
4369
  inboxItems: PluginConversationInboxItems;
4225
4370
  state: PluginState;
4371
+ /** Start this plugin's tasks, as from a plugin route. */
4372
+ tasks: PluginTaskStarter;
4226
4373
  }
4227
4374
  export interface HeartbeatResult {
4228
4375
  dispatchCount?: number;
4229
4376
  }
4230
4377
  export interface UnfinishedWorkHookContext extends PluginContext {
4378
+ /** Junior's native code index, as from a plugin route. */
4379
+ codeChanges: PluginCodeChanges;
4231
4380
  /**
4232
4381
  * Bounded conversation candidates selected by the host, with the child
4233
4382
  * conversations of candidate roots. Work in a child counts for its root.
@@ -4347,8 +4496,8 @@ export interface RouteRegistrationHookContext extends PluginContext {
4347
4496
  dispatchForIdentity(options: IdentityDispatchOptions): Promise<IdentityDispatchResult>;
4348
4497
  };
4349
4498
  annotations: PluginConversationAnnotations;
4350
- /** Provider-neutral write boundary for Junior's native code index. */
4351
- codeChanges: CodeChangePublisher;
4499
+ /** Provider-neutral boundary for Junior's native code index. */
4500
+ codeChanges: PluginCodeChanges;
4352
4501
  /** Annotation and Inbox item changes that readers must see together. */
4353
4502
  conversationChanges: PluginConversationChanges;
4354
4503
  /** Core-owned delivery boundary for provider webhook events. */
@@ -4357,6 +4506,11 @@ export interface RouteRegistrationHookContext extends PluginContext {
4357
4506
  inboxItems: PluginConversationInboxItems;
4358
4507
  /** Plugin-namespaced state, the same as in heartbeats. */
4359
4508
  state: PluginState;
4509
+ /**
4510
+ * Start a task with a `payload` schema from this plugin's `tasks`. Use it
4511
+ * when a write fails and must run again after the route returns.
4512
+ */
4513
+ tasks: PluginTaskStarter;
4360
4514
  users: {
4361
4515
  /**
4362
4516
  * Read one stored identity and the user it links to now, with every
@@ -4475,11 +4629,14 @@ export interface PluginHooks {
4475
4629
  conversationTitleContext?(ctx: ConversationTitleContextHookContext): Promise<string[] | undefined> | string[] | undefined;
4476
4630
  conversationSidebar?(ctx: ConversationSidebarHookContext): Promise<ConversationSidebarResult> | ConversationSidebarResult;
4477
4631
  /**
4478
- * Return static guidance for the system prompt. Return the same text for one
4479
- * deployment and platform, so the system prompt stays cacheable. Put text
4480
- * that changes per request in `userPrompt`.
4632
+ * Return static guidance for the system prompts of one platform. Junior
4633
+ * runs this hook once at build for each platform, uses its output in the
4634
+ * system prompt of every Prompt mode on that platform, and freezes it for
4635
+ * the deployment. So every Turn gets the same system prompt, and the model
4636
+ * provider can cache it. The hook may do I/O, but that I/O happens only at
4637
+ * build. Put text that changes per request in `userPrompt`.
4481
4638
  */
4482
- systemPrompt?(ctx: SystemPromptContext): Promise<PromptMessage[]> | PromptMessage[];
4639
+ systemPrompt?(ctx: SystemPromptBuildContext): Promise<PromptMessage[]> | PromptMessage[];
4483
4640
  /**
4484
4641
  * Return per-request context for a new prompt, such as recalled memories.
4485
4642
  * Junior runs this hook at the same time as Turn routing and sandbox setup,
@@ -4612,7 +4769,57 @@ export interface PluginOAuthBearerCredentials {
4612
4769
  domains: string[];
4613
4770
  type: "oauth-bearer";
4614
4771
  }
4615
- export type PluginCredentials = PluginOAuthBearerCredentials;
4772
+ /** Request header that carries a workload identity token. */
4773
+ export type PluginWorkloadIdentityHeader = "Authorization" | "Proxy-Authorization" | "X-Serverless-Authorization";
4774
+ /**
4775
+ * Google Cloud token that Junior mints for one service account.
4776
+ *
4777
+ * `service-account-jwt` signs a JWT with `iss` and `sub` set to the service
4778
+ * account (Identity-Aware Proxy accepts it). `id-token` mints a Google ID
4779
+ * token (Cloud Run accepts it). `access-token` mints an OAuth access token for
4780
+ * Google APIs.
4781
+ */
4782
+ export type PluginGcpWorkloadIdentityToken = {
4783
+ audience: string;
4784
+ token: "id-token";
4785
+ } | {
4786
+ audience: string;
4787
+ token: "service-account-jwt";
4788
+ } | {
4789
+ scopes: string[];
4790
+ token: "access-token";
4791
+ };
4792
+ /** Google Cloud workload identity federation through one service account. */
4793
+ export type PluginGcpWorkloadIdentityConfig = PluginGcpWorkloadIdentityToken & {
4794
+ /** Service account email that Junior impersonates. */
4795
+ serviceAccount: string;
4796
+ /** `projects/<number>/locations/global/workloadIdentityPools/<pool>/providers/<provider>`. */
4797
+ workloadIdentityProvider: string;
4798
+ };
4799
+ /** Microsoft Entra ID workload identity federation for one app registration. */
4800
+ export interface PluginAzureWorkloadIdentityConfig {
4801
+ clientId: string;
4802
+ /** Token scope, such as `api://<app>/.default`. */
4803
+ scope: string;
4804
+ tenantId: string;
4805
+ }
4806
+ /**
4807
+ * Bot credential that Junior mints on the host from the deployment's Vercel
4808
+ * OIDC token. Set exactly one of `gcp` or `azure`.
4809
+ */
4810
+ export type PluginWorkloadIdentityCredentials = {
4811
+ domains: string[];
4812
+ /** Defaults to `Authorization`. */
4813
+ header?: PluginWorkloadIdentityHeader;
4814
+ type: "workload-identity";
4815
+ } & ({
4816
+ azure?: never;
4817
+ gcp: PluginGcpWorkloadIdentityConfig;
4818
+ } | {
4819
+ azure: PluginAzureWorkloadIdentityConfig;
4820
+ gcp?: never;
4821
+ });
4822
+ export type PluginCredentials = PluginOAuthBearerCredentials | PluginWorkloadIdentityCredentials;
4616
4823
  export interface PluginNpmRuntimeDependency {
4617
4824
  package: string;
4618
4825
  type: "npm";
@@ -4898,4 +5105,4 @@ export declare function markdownText(node: MarkdownNode, options?: MarkdownTextO
4898
5105
  * each run of whitespace made one space.
4899
5106
  */
4900
5107
  export declare function markdownPlainText(text: string, options?: MarkdownTextOptions): string;
4901
- export type { PromptContext, PromptContextContribution, PromptHistory, PromptHistoryContext, PromptMessage, SystemPromptContext, UserPromptContext, UserPromptContribution };
5108
+ export type { PromptContext, PromptContextContribution, PromptHistory, PromptHistoryContext, PromptMessage, SystemPromptBuildContext, UserPromptContext, UserPromptContribution };
package/dist/index.js CHANGED
@@ -34,13 +34,17 @@ const objectFactsSchema = z.discriminatedUnion("type", [
34
34
  "approved",
35
35
  "changes_requested"
36
36
  ]).optional(),
37
- checks: z.strictObject({
37
+ /** `pending` while the provider counts the checks of a new head. */
38
+ checks: z.union([z.strictObject({
38
39
  passed: count,
39
40
  failed: count,
40
41
  pending: count
41
- }).optional(),
42
- /** False while an open change conflicts with its target branch. */
43
- mergeable: z.boolean().optional(),
42
+ }), z.literal("pending")]).optional(),
43
+ /**
44
+ * False while an open change conflicts with its target branch.
45
+ * `pending` while the provider computes it for a new head.
46
+ */
47
+ mergeable: z.union([z.boolean(), z.literal("pending")]).optional(),
44
48
  changedFiles: count.optional(),
45
49
  additions: count.optional(),
46
50
  deletions: count.optional(),
@@ -910,9 +914,7 @@ const conversationSidebarAnnotationSchema = z.object({
910
914
  label: z.string().trim().min(1).max(256),
911
915
  title: z.string().trim().min(1).max(512).optional(),
912
916
  url: httpUrlSchema.optional(),
913
- imageUrl: httpUrlSchema.optional(),
914
- /** A code change's size, so a card can show it without a live read. */
915
- size: codeChangeSizeSchema.optional()
917
+ imageUrl: httpUrlSchema.optional()
916
918
  }).strict();
917
919
  // src/code.ts
918
920
  const codeChangeStateSchema = z.enum([
@@ -923,11 +925,6 @@ const codeChangeStateSchema = z.enum([
923
925
  const codeChangeInputSchema = z.object({
924
926
  closedAt: z.date().optional(),
925
927
  conversationIds: z.array(z.string().min(1)).default([]),
926
- /**
927
- * Whether the code change is a draft. When omitted, Junior keeps the
928
- * stored value; a new code change is not a draft.
929
- */
930
- draft: z.boolean().optional(),
931
928
  mergedAt: z.date().optional(),
932
929
  number: z.number().int().positive(),
933
930
  openedAt: z.date(),
@@ -936,15 +933,28 @@ const codeChangeInputSchema = z.object({
936
933
  name: z.string().min(1),
937
934
  providerId: z.string().min(1)
938
935
  }).strict(),
939
- /**
940
- * The size as the provider counts it now. Junior keeps the stored value
941
- * of each part that is omitted.
942
- */
943
- size: codeChangeSizeSchema.optional(),
944
936
  state: codeChangeStateSchema,
945
937
  title: z.string().min(1).optional(),
946
938
  updatedAt: z.date()
947
939
  }).strict();
940
+ const codeRepositoryInputSchema = z.object({
941
+ name: z.string().min(1),
942
+ providerId: z.string().min(1),
943
+ /** When the provider had this name. */
944
+ updatedAt: z.date()
945
+ }).strict();
946
+ const codeChangeFilterSchema = z.object({
947
+ /** Code changes linked to any of these Conversations. */
948
+ conversationIds: z.array(z.string().min(1)).min(1).optional(),
949
+ repository: z.object({
950
+ /** The repository name. Junior matches it in any case. */
951
+ name: z.string().min(1),
952
+ numbers: z.array(z.number().int().positive()).min(1).optional()
953
+ }).strict().optional(),
954
+ state: codeChangeStateSchema.optional(),
955
+ /** Code changes whose last update is before this time. */
956
+ updatedBefore: z.date().optional()
957
+ }).strict();
948
958
  // src/conversation-changes.ts
949
959
  /** Most entries in one batch, annotations and Inbox items together. */
950
960
  const MAX_CONVERSATION_CHANGES = 100;
@@ -2299,6 +2309,20 @@ const pluginRunContextSchema = z.object({
2299
2309
  source: sourceSchema,
2300
2310
  transcript: z.array(pluginRunTranscriptEntrySchema)
2301
2311
  }).strict();
2312
+ /** Input of `tasks.start`. */
2313
+ const pluginTaskStartInputSchema = z.object({
2314
+ /**
2315
+ * One task per plugin and key while the queue keeps the message. A
2316
+ * second start with the key in that time does nothing.
2317
+ */
2318
+ key: nonBlankStringSchema.max(500),
2319
+ /** Name of a task with a `payload` schema in this plugin's `tasks`. */
2320
+ name: nonBlankStringSchema,
2321
+ /** Seconds before the first attempt. Without it, the task runs soon. */
2322
+ delaySeconds: z.number().int().positive().optional(),
2323
+ /** JSON value that the task's `payload` schema accepts. */
2324
+ payload: z.unknown()
2325
+ }).strict();
2302
2326
  // src/tools.ts
2303
2327
  /** Thrown when a plugin tool rejects invalid model or user input. */
2304
2328
  var PluginToolInputError = class extends Error {
@@ -2875,4 +2899,4 @@ const pluginUserPageInputSchema = z.object({
2875
2899
  limit: z.number().int().min(1).max(50),
2876
2900
  query: pluginUserPageQuerySchema
2877
2901
  }).strict();
2878
- export { EVENT_DATA_MAX_JSON_BYTES, EVENT_DATA_MAX_KEYS, EVENT_GUIDANCE_MAX_LENGTH, EVENT_SUMMARY_MAX_LENGTH, EVENT_TEXT_MAX_LENGTH, EgressAuthRequired, EgressPolicyDenied, MAX_CONVERSATION_CHANGES, OBJECT_FACTS_MAX_BYTES, OBJECT_SUMMARY_MAX_LENGTH, PluginToolInputError, REQUIRED_TOOL_ANNOTATION_KEYS, actorSchema, actorUserIdSchema, agentEventKeys, agentEventMatchKey, agentEventMatchSchema, anyResourceEvents, anyResourceMatchFields, codeChangeInputSchema, codeChangeSizeSchema, codeChangeStateSchema, conversationAnnotationInputSchema, conversationEventIconSchema, conversationEventPresentationSchema, conversationSidebarAnnotationSchema, conversationSidebarIconSchema, createEventSource, createLocalSource, createSlackSource, createWebSource, declaredEventKeys, decodeObjectImageRef, defineConversationEvent, defineJuniorPlugin, definePluginTool, definePromptContext, describeEventTrigger, destinationSchema, destinationVisibilitySchema, dispatchOptionsSchema, encodeObjectImageRef, enforceEgressPolicy, escapeClosingTag, escapeClosingTags, escapeTagText, escapeTagTextAndQuotes, eventAuthorSchema, eventAutomationSourceSchema, eventDataSchema, eventIdentifierSchema, eventInputSchema, eventMatchFieldSchema, eventMatchFieldsSchema, eventMatchFilterText, eventMatchSchema, eventMatches, eventPersonSchema, eventReachSchema, eventSchema, eventSourceSchema, eventTriggerChoices, eventTriggerFiltersText, eventTriggerProblems, eventTriggerText, eventTypeSchema, eventTypeText, eventsWithoutMatchField, findTag, findTags, formatDuration, getSourceKey, identityDispatchOptionsSchema, identitySchema, indentTagLines, isPluginModelCostEventName, isPrivateSource, isSlackDestination, localActorSchema, localDestinationSchema, localSourceSchema, locationSchema, markdownNodes, markdownPlainText, markdownText, mentionsTag, mergeEventMatchFields, missingToolAnnotationKeys, nonBlankStringSchema, normalizeEventIdentifier, normalizeEventMatch, objectAnnotationSchema, objectFactFields, objectFactsBytes, objectFactsMatchType, objectFactsSchema, objectIconPath, objectIconPaths, objectLinkFilterMatches, objectLinkFilterSchema, objectLinkFilterSpecificity, objectPresentation, objectSummary, objectTypeSchema, openingTag, ownedObjectAnnotationSchema, parentMessageSourceSchema, parseMarkdown, 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, readTag, renderEmptyTag, renderInlineTag, renderTag, replyAttributionSchema, resourceLinkAnnotationSchema, resourceTypeSchema, scheduledAutomationSourceSchema, slackActorSchema, slackDestinationSchema, slackLocationSchema, slackSourceSchema, sourceSchema, sourceVisibilitySchema, stableEventMatchKey, startsWithTag, stripTags, subscribableResourceSchema, systemActorSchema, tagJson, taskOutcomeSchema, toolApprovalModeSchema, unescapeClosingTag, unescapeClosingTags, unescapeTagText, userSchema, watchResultSchema, webActorSchema, webSourceSchema, withToolContext, zodTool };
2902
+ export { EVENT_DATA_MAX_JSON_BYTES, EVENT_DATA_MAX_KEYS, EVENT_GUIDANCE_MAX_LENGTH, EVENT_SUMMARY_MAX_LENGTH, EVENT_TEXT_MAX_LENGTH, EgressAuthRequired, EgressPolicyDenied, MAX_CONVERSATION_CHANGES, OBJECT_FACTS_MAX_BYTES, OBJECT_SUMMARY_MAX_LENGTH, PluginToolInputError, REQUIRED_TOOL_ANNOTATION_KEYS, actorSchema, actorUserIdSchema, agentEventKeys, agentEventMatchKey, agentEventMatchSchema, anyResourceEvents, anyResourceMatchFields, codeChangeFilterSchema, codeChangeInputSchema, codeChangeSizeSchema, codeChangeStateSchema, codeRepositoryInputSchema, conversationAnnotationInputSchema, conversationEventIconSchema, conversationEventPresentationSchema, conversationSidebarAnnotationSchema, conversationSidebarIconSchema, createEventSource, createLocalSource, createSlackSource, createWebSource, declaredEventKeys, decodeObjectImageRef, defineConversationEvent, defineJuniorPlugin, definePluginTool, definePromptContext, describeEventTrigger, destinationSchema, destinationVisibilitySchema, dispatchOptionsSchema, encodeObjectImageRef, enforceEgressPolicy, escapeClosingTag, escapeClosingTags, escapeTagText, escapeTagTextAndQuotes, eventAuthorSchema, eventAutomationSourceSchema, eventDataSchema, eventIdentifierSchema, eventInputSchema, eventMatchFieldSchema, eventMatchFieldsSchema, eventMatchFilterText, eventMatchSchema, eventMatches, eventPersonSchema, eventReachSchema, eventSchema, eventSourceSchema, eventTriggerChoices, eventTriggerFiltersText, eventTriggerProblems, eventTriggerText, eventTypeSchema, eventTypeText, eventsWithoutMatchField, findTag, findTags, formatDuration, getSourceKey, identityDispatchOptionsSchema, identitySchema, indentTagLines, isPluginModelCostEventName, isPrivateSource, isSlackDestination, localActorSchema, localDestinationSchema, localSourceSchema, locationSchema, markdownNodes, markdownPlainText, markdownText, mentionsTag, mergeEventMatchFields, missingToolAnnotationKeys, nonBlankStringSchema, normalizeEventIdentifier, normalizeEventMatch, objectAnnotationSchema, objectFactFields, objectFactsBytes, objectFactsMatchType, objectFactsSchema, objectIconPath, objectIconPaths, objectLinkFilterMatches, objectLinkFilterSchema, objectLinkFilterSpecificity, objectPresentation, objectSummary, objectTypeSchema, openingTag, ownedObjectAnnotationSchema, parentMessageSourceSchema, parseMarkdown, parseShellCommands, platformSchema, pluginApiRouteRequestContextSchema, pluginAuditAttributesSchema, pluginAuthorizationSchema, pluginCredentialHeaderTransformSchema, pluginCredentialLeaseSchema, pluginCredentialResultSchema, pluginCredentialSubjectSchema, pluginDispatchSourceSchema, pluginEventDeclarationSchema, pluginEventTypeSchema, pluginEventsSchema, pluginGrantSchema, pluginModelCostEventNames, pluginProviderAccountSchema, pluginRunContextSchema, pluginRunTranscriptEntrySchema, pluginRunTranscriptProvenanceSchema, pluginStoredTokensSchema, pluginTaskStartInputSchema, pluginToolContentSchema, pluginToolContinuationSchema, pluginToolOutputSchema, pluginToolReplySchema, pluginUserPageContentSchema, pluginUserPageCursorSchema, pluginUserPageFilterSchema, pluginUserPageInputSchema, pluginUserPageLinkSchema, pluginUserPageLinksSchema, pluginUserPageQuerySchema, promptContextSchema, promptMessageSchema, readTag, renderEmptyTag, renderInlineTag, renderTag, replyAttributionSchema, resourceLinkAnnotationSchema, resourceTypeSchema, scheduledAutomationSourceSchema, slackActorSchema, slackDestinationSchema, slackLocationSchema, slackSourceSchema, sourceSchema, sourceVisibilitySchema, stableEventMatchKey, startsWithTag, stripTags, subscribableResourceSchema, systemActorSchema, tagJson, taskOutcomeSchema, toolApprovalModeSchema, unescapeClosingTag, unescapeClosingTags, unescapeTagText, userSchema, watchResultSchema, webActorSchema, webSourceSchema, withToolContext, zodTool };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sentry/junior-plugin-api",
3
- "version": "0.314.0",
3
+ "version": "0.315.0",
4
4
  "private": false,
5
5
  "publishConfig": {
6
6
  "access": "public"