@sentry/junior-plugin-api 0.74.1 → 0.76.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/cli.d.ts ADDED
@@ -0,0 +1,39 @@
1
+ /**
2
+ * Public Commander-based CLI contract for plugin-owned admin commands.
3
+ * Junior owns the root command, plugin namespaces, context injection, and exit
4
+ * normalization; plugins only configure subcommands under their namespace.
5
+ */
6
+ import type { Command } from "commander";
7
+ import type { PluginContext } from "./context";
8
+ export interface PluginCliIo {
9
+ writeError(text: string): Promise<void> | void;
10
+ writeOutput(text: string): Promise<void> | void;
11
+ }
12
+ export interface PluginCliActionCommand {
13
+ name: string;
14
+ summary: string;
15
+ }
16
+ /** Host/admin context exposed to plugin-owned CLI command actions. */
17
+ export interface PluginCliActionContext extends Pick<PluginContext, "db" | "log" | "plugin"> {
18
+ command: PluginCliActionCommand;
19
+ io: PluginCliIo;
20
+ }
21
+ /** Plugin action callback wrapped by the Junior host for context and exit codes. */
22
+ export type PluginCliActionHandler<Args extends unknown[] = unknown[]> = (ctx: PluginCliActionContext, ...args: Args) => Promise<number | void> | number | void;
23
+ export interface PluginCliHost {
24
+ /** Wrap a Commander action so Junior can inject context and normalize exits. */
25
+ action<Args extends unknown[]>(handler: PluginCliActionHandler<Args>): (...args: Args) => Promise<void>;
26
+ }
27
+ /** Plugin-owned top-level CLI command registration. */
28
+ export interface PluginCliCommandDefinition {
29
+ /** Configure subcommands under the host-created top-level namespace. */
30
+ configure(command: Command, junior: PluginCliHost): void;
31
+ /** Unique host-level command namespace owned by this plugin. */
32
+ name: string;
33
+ /** One-line summary used in generated command help. */
34
+ summary: string;
35
+ }
36
+ /** Plugin-owned CLI command catalog. */
37
+ export interface PluginCliDefinition {
38
+ commands: PluginCliCommandDefinition[];
39
+ }
@@ -0,0 +1,97 @@
1
+ import { z } from "zod";
2
+ import type { ZodTypeAny } from "zod";
3
+ import { destinationSchema, localRequesterSchema, platformSchema, requesterSchema, slackRequesterSchema, sourceSchema } from "./schemas";
4
+ /** Runtime platform name without source or destination coordinates. */
5
+ export type Platform = z.output<typeof platformSchema>;
6
+ export type Requester = z.output<typeof requesterSchema>;
7
+ export type SlackRequester = z.output<typeof slackRequesterSchema>;
8
+ export type LocalRequester = z.output<typeof localRequesterSchema>;
9
+ export type Source = z.output<typeof sourceSchema>;
10
+ export type SlackSource = Extract<Source, {
11
+ platform: "slack";
12
+ }>;
13
+ export type LocalSource = Extract<Source, {
14
+ platform: "local";
15
+ }>;
16
+ export type SourceType = Source["type"];
17
+ export type Destination = z.output<typeof destinationSchema>;
18
+ export type SlackDestination = Extract<Destination, {
19
+ platform: "slack";
20
+ }>;
21
+ export type LocalDestination = Extract<Destination, {
22
+ platform: "local";
23
+ }>;
24
+ export interface PluginMetadata {
25
+ name: string;
26
+ }
27
+ export interface PluginLogger {
28
+ error(message: string, metadata?: Record<string, unknown>): void;
29
+ info(message: string, metadata?: Record<string, unknown>): void;
30
+ warn(message: string, metadata?: Record<string, unknown>): void;
31
+ }
32
+ export interface PluginModel {
33
+ /** Run a host-owned structured model call without exposing provider credentials. */
34
+ completeObject<TSchema extends ZodTypeAny>(input: {
35
+ maxTokens?: number;
36
+ prompt: string;
37
+ schema: TSchema;
38
+ system?: string;
39
+ }): Promise<{
40
+ object: z.infer<TSchema>;
41
+ }>;
42
+ }
43
+ export interface PluginEmbedder {
44
+ /** Embed plugin-owned text for derived retrieval without exposing provider credentials. */
45
+ embedTexts(input: {
46
+ texts: string[];
47
+ }): Promise<{
48
+ dimensions: number;
49
+ model: string;
50
+ provider: string;
51
+ vectors: number[][];
52
+ }>;
53
+ }
54
+ export interface PluginContext {
55
+ /** Shared Drizzle database connection for plugin runtime code. */
56
+ db: unknown;
57
+ log: PluginLogger;
58
+ plugin: PluginMetadata;
59
+ }
60
+ interface BaseInvocationContext {
61
+ /**
62
+ * Opaque Junior conversation/session identity for this invocation.
63
+ * Interactive Slack turns use `slack:{channelId}:{threadTs}`.
64
+ */
65
+ conversationId?: string;
66
+ }
67
+ export interface SlackInvocationContext extends BaseInvocationContext {
68
+ /** Runtime-owned default outbound destination for this invocation. */
69
+ destination: SlackDestination;
70
+ requester?: SlackRequester;
71
+ /** Runtime-owned source where the invocation came from. */
72
+ source: SlackSource;
73
+ }
74
+ export interface LocalInvocationContext extends BaseInvocationContext {
75
+ /** Runtime-owned default outbound destination for this invocation. */
76
+ destination: LocalDestination;
77
+ requester?: LocalRequester;
78
+ /** Runtime-owned source where the invocation came from. */
79
+ source: LocalSource;
80
+ }
81
+ export type InvocationContext = LocalInvocationContext | SlackInvocationContext;
82
+ /** Build a normalized Slack source from runtime-owned Slack coordinates. */
83
+ export declare function createSlackSource(input: {
84
+ channelId: string;
85
+ messageTs?: string;
86
+ teamId: string;
87
+ threadTs?: string;
88
+ }): SlackSource;
89
+ /** Build a normalized local source from a local conversation id. */
90
+ export declare function createLocalSource(conversationId: string): LocalSource;
91
+ /** Return whether a source is private to a person or restricted group. */
92
+ export declare function isPrivateSource(source: Source): boolean;
93
+ /** Return the stable source identity used for idempotency and attribution. */
94
+ export declare function getSourceKey(source: Source): string | undefined;
95
+ /** Narrow a runtime destination to the Slack-specific address shape. */
96
+ export declare function isSlackDestination(destination: Destination | undefined): destination is SlackDestination;
97
+ export {};
@@ -0,0 +1,167 @@
1
+ import { z } from "zod";
2
+ import type { PluginContext } from "./context";
3
+ import { pluginCredentialSubjectSchema } from "./schemas";
4
+ declare const pluginGrantAccessSchema: z.ZodUnion<readonly [z.ZodLiteral<"read">, z.ZodLiteral<"write">]>;
5
+ /** Runtime schema for provider authorization a plugin may request. */
6
+ export declare const pluginAuthorizationSchema: z.ZodObject<{
7
+ provider: z.ZodString;
8
+ scope: z.ZodOptional<z.ZodString>;
9
+ type: z.ZodLiteral<"oauth">;
10
+ }, z.core.$strict>;
11
+ /** Runtime schema for a provider account attached to stored OAuth tokens. */
12
+ export declare const pluginProviderAccountSchema: z.ZodObject<{
13
+ id: z.ZodString;
14
+ label: z.ZodOptional<z.ZodString>;
15
+ url: z.ZodOptional<z.ZodString>;
16
+ }, z.core.$strict>;
17
+ /** Runtime schema for OAuth tokens stored by the host for plugin credentials. */
18
+ export declare const pluginStoredTokensSchema: z.ZodObject<{
19
+ account: z.ZodOptional<z.ZodObject<{
20
+ id: z.ZodString;
21
+ label: z.ZodOptional<z.ZodString>;
22
+ url: z.ZodOptional<z.ZodString>;
23
+ }, z.core.$strict>>;
24
+ accessToken: z.ZodString;
25
+ expiresAt: z.ZodOptional<z.ZodNumber>;
26
+ refreshToken: z.ZodString;
27
+ refreshTokenExpiresAt: z.ZodOptional<z.ZodNumber>;
28
+ scope: z.ZodOptional<z.ZodString>;
29
+ }, z.core.$strict>;
30
+ /** Runtime schema for a plugin-defined outbound credential grant. */
31
+ export declare const pluginGrantSchema: z.ZodObject<{
32
+ access: z.ZodUnion<readonly [z.ZodLiteral<"read">, z.ZodLiteral<"write">]>;
33
+ name: z.ZodString;
34
+ reason: z.ZodOptional<z.ZodString>;
35
+ requirements: z.ZodOptional<z.ZodArray<z.ZodString>>;
36
+ }, z.core.$strict>;
37
+ /** Runtime schema for plugin-issued header mutations. */
38
+ export declare const pluginCredentialHeaderTransformSchema: z.ZodObject<{
39
+ domain: z.ZodString;
40
+ headers: z.ZodRecord<z.ZodString, z.ZodString>;
41
+ }, z.core.$strict>;
42
+ /** Runtime schema for a short-lived plugin-issued credential lease. */
43
+ export declare const pluginCredentialLeaseSchema: z.ZodObject<{
44
+ account: z.ZodOptional<z.ZodObject<{
45
+ id: z.ZodString;
46
+ label: z.ZodOptional<z.ZodString>;
47
+ url: z.ZodOptional<z.ZodString>;
48
+ }, z.core.$strict>>;
49
+ authorization: z.ZodOptional<z.ZodObject<{
50
+ provider: z.ZodString;
51
+ scope: z.ZodOptional<z.ZodString>;
52
+ type: z.ZodLiteral<"oauth">;
53
+ }, z.core.$strict>>;
54
+ expiresAt: z.ZodString;
55
+ headerTransforms: z.ZodArray<z.ZodObject<{
56
+ domain: z.ZodString;
57
+ headers: z.ZodRecord<z.ZodString, z.ZodString>;
58
+ }, z.core.$strict>>;
59
+ }, z.core.$strict>;
60
+ /** Runtime schema for the result returned by a plugin credential hook. */
61
+ export declare const pluginCredentialResultSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
62
+ lease: z.ZodObject<{
63
+ account: z.ZodOptional<z.ZodObject<{
64
+ id: z.ZodString;
65
+ label: z.ZodOptional<z.ZodString>;
66
+ url: z.ZodOptional<z.ZodString>;
67
+ }, z.core.$strict>>;
68
+ authorization: z.ZodOptional<z.ZodObject<{
69
+ provider: z.ZodString;
70
+ scope: z.ZodOptional<z.ZodString>;
71
+ type: z.ZodLiteral<"oauth">;
72
+ }, z.core.$strict>>;
73
+ expiresAt: z.ZodString;
74
+ headerTransforms: z.ZodArray<z.ZodObject<{
75
+ domain: z.ZodString;
76
+ headers: z.ZodRecord<z.ZodString, z.ZodString>;
77
+ }, z.core.$strict>>;
78
+ }, z.core.$strict>;
79
+ type: z.ZodLiteral<"lease">;
80
+ }, z.core.$strict>, z.ZodObject<{
81
+ authorization: z.ZodOptional<z.ZodObject<{
82
+ provider: z.ZodString;
83
+ scope: z.ZodOptional<z.ZodString>;
84
+ type: z.ZodLiteral<"oauth">;
85
+ }, z.core.$strict>>;
86
+ message: z.ZodString;
87
+ type: z.ZodLiteral<"needed">;
88
+ }, z.core.$strict>, z.ZodObject<{
89
+ message: z.ZodString;
90
+ type: z.ZodLiteral<"unavailable">;
91
+ }, z.core.$strict>], "type">;
92
+ export type PluginCredentialSubject = z.output<typeof pluginCredentialSubjectSchema>;
93
+ export type PluginGrantAccess = z.output<typeof pluginGrantAccessSchema>;
94
+ /** Provider authorization Junior can start when a plugin-owned grant is missing. */
95
+ export type PluginAuthorization = z.output<typeof pluginAuthorizationSchema>;
96
+ /** Interrupt sandbox egress so Junior can start provider authorization. */
97
+ export declare class EgressAuthRequired extends Error {
98
+ authorization?: PluginAuthorization;
99
+ constructor(message: string, options?: {
100
+ authorization?: PluginAuthorization;
101
+ cause?: unknown;
102
+ });
103
+ }
104
+ /** Provider account identity resolved by a plugin OAuth hook. */
105
+ export type PluginProviderAccount = z.output<typeof pluginProviderAccountSchema>;
106
+ /** Plugin-defined grant required before Junior can forward one outbound request. */
107
+ export type PluginGrant = z.output<typeof pluginGrantSchema>;
108
+ /** Request details available while selecting the grant for sandbox egress. */
109
+ export interface PluginEgressRequest {
110
+ /** Capped request body text when the host exposes it for provider-specific grant classification. */
111
+ bodyText?: string;
112
+ method: string;
113
+ url: string;
114
+ }
115
+ export interface EgressHookContext extends PluginContext {
116
+ request: PluginEgressRequest;
117
+ }
118
+ export interface PluginEgressResponse {
119
+ /** Snapshot of upstream response headers; mutations do not affect pass-through. */
120
+ headers: Headers;
121
+ readText(maxBytes: number): Promise<string | undefined>;
122
+ status: number;
123
+ }
124
+ export interface EgressResponseHookContext extends PluginContext {
125
+ grant: PluginGrant;
126
+ permissionDenied(message: string): void;
127
+ request: Omit<PluginEgressRequest, "bodyText">;
128
+ response: PluginEgressResponse;
129
+ }
130
+ /** Header mutations a plugin-issued credential lease may apply to owned domains. */
131
+ export type PluginCredentialHeaderTransform = z.output<typeof pluginCredentialHeaderTransformSchema>;
132
+ /** Short-lived credential headers issued by a plugin for a selected grant. */
133
+ export type PluginCredentialLease = z.output<typeof pluginCredentialLeaseSchema>;
134
+ export type PluginCredentialResult = z.output<typeof pluginCredentialResultSchema>;
135
+ export type PluginCredentialActor = {
136
+ type: "system";
137
+ id: string;
138
+ } | {
139
+ type: "user";
140
+ userId: string;
141
+ };
142
+ export interface PluginResolvedCredentialUser {
143
+ type: "user";
144
+ userId: string;
145
+ }
146
+ export type PluginStoredTokens = z.output<typeof pluginStoredTokensSchema>;
147
+ export interface PluginUserTokenSlot {
148
+ get(): Promise<PluginStoredTokens | undefined>;
149
+ set(tokens: PluginStoredTokens): Promise<void>;
150
+ /** Run token refresh work after the host has serialized this user/provider slot, or throw after a bounded wait. */
151
+ withRefresh<T>(callback: () => Promise<T>): Promise<T>;
152
+ userId: string;
153
+ }
154
+ export interface PluginTokenStore {
155
+ credentialSubject?: PluginUserTokenSlot;
156
+ currentUser?: PluginUserTokenSlot;
157
+ }
158
+ export interface ResolveOAuthAccountHookContext extends PluginContext {
159
+ tokens: PluginStoredTokens;
160
+ }
161
+ export interface IssueCredentialHookContext extends PluginContext {
162
+ actor: PluginCredentialActor;
163
+ credentialSubject?: PluginResolvedCredentialUser;
164
+ grant: PluginGrant;
165
+ tokens: PluginTokenStore;
166
+ }
167
+ export {};
@@ -0,0 +1,13 @@
1
+ import { z } from "zod";
2
+ import { dispatchOptionsSchema } from "./schemas";
3
+ export type DispatchOptions = z.output<typeof dispatchOptionsSchema>;
4
+ export interface DispatchResult {
5
+ id: string;
6
+ status: "created" | "already_exists";
7
+ }
8
+ export interface Dispatch {
9
+ errorMessage?: string;
10
+ id: string;
11
+ resultMessageTs?: string;
12
+ status: "pending" | "running" | "awaiting_resume" | "completed" | "failed" | "blocked";
13
+ }
@@ -0,0 +1,20 @@
1
+ import type { EgressHookContext, EgressResponseHookContext, IssueCredentialHookContext, PluginCredentialResult, PluginGrant, PluginProviderAccount, ResolveOAuthAccountHookContext } from "./credentials";
2
+ import type { HeartbeatHookContext, HeartbeatResult, OperationalReportHookContext, PluginOperationalReportContent, PluginRoute, RouteRegistrationHookContext, SlackConversationLink, SlackConversationLinkHookContext, StorageMigrationContext, StorageMigrationResult } from "./operations";
3
+ import type { BeforeToolExecuteHookContext, PluginToolDefinition, SandboxPrepareHookContext, ToolRegistrationHookContext } from "./tools";
4
+ import type { PromptMessage, SystemPromptContext, UserPromptContext } from "./prompt";
5
+ export interface PluginHooks {
6
+ systemPrompt?(ctx: SystemPromptContext): Promise<PromptMessage[]> | PromptMessage[];
7
+ userPrompt?(ctx: UserPromptContext): Promise<PromptMessage[] | undefined> | PromptMessage[] | undefined;
8
+ beforeToolExecute?(ctx: BeforeToolExecuteHookContext): Promise<void> | void;
9
+ grantForEgress?(ctx: EgressHookContext): Promise<PluginGrant | undefined> | PluginGrant | undefined;
10
+ heartbeat?(ctx: HeartbeatHookContext): Promise<HeartbeatResult | void> | HeartbeatResult | void;
11
+ issueCredential?(ctx: IssueCredentialHookContext): Promise<PluginCredentialResult> | PluginCredentialResult;
12
+ onEgressResponse?(ctx: EgressResponseHookContext): Promise<void> | void;
13
+ operationalReport?(ctx: OperationalReportHookContext): Promise<PluginOperationalReportContent | undefined> | PluginOperationalReportContent | undefined;
14
+ resolveOAuthAccount?(ctx: ResolveOAuthAccountHookContext): Promise<PluginProviderAccount | undefined> | PluginProviderAccount | undefined;
15
+ routes?(ctx: RouteRegistrationHookContext): PluginRoute[];
16
+ sandboxPrepare?(ctx: SandboxPrepareHookContext): Promise<void> | void;
17
+ slackConversationLink?(ctx: SlackConversationLinkHookContext): SlackConversationLink | undefined;
18
+ tools?(ctx: ToolRegistrationHookContext): Record<string, PluginToolDefinition>;
19
+ migrateStorage?(ctx: StorageMigrationContext): Promise<StorageMigrationResult | undefined> | StorageMigrationResult | undefined;
20
+ }