@sentry/junior-plugin-api 0.100.0 → 0.102.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/README.md ADDED
@@ -0,0 +1,82 @@
1
+ # @sentry/junior-plugin-api
2
+
3
+ This package defines the public contract between Junior and code plugins. The
4
+ exported TypeScript types and runtime validators are authoritative.
5
+
6
+ ## Registration
7
+
8
+ Use `defineJuniorPlugin({ manifest, hooks, tasks, cli, model })`. A plugin name
9
+ is a lowercase identifier and is unique within the enabled app plugin set.
10
+
11
+ A plugin may instead be a declarative `plugin.yaml` package when it has no
12
+ host-executed hooks. Do not combine an inline manifest with a second YAML
13
+ definition for the same plugin.
14
+
15
+ ## Manifest
16
+
17
+ The manifest declares runtime metadata such as:
18
+
19
+ - plugin identity and description;
20
+ - skill roots and MCP tool sources;
21
+ - provider domains, grants, OAuth, API-header transformations, and safe command
22
+ environment placeholders;
23
+ - runtime dependencies and snapshot installation steps;
24
+ - configuration fields.
25
+
26
+ Manifest values are validated before runtime activation. Secret deployment
27
+ values remain host-only; sandbox-exposed command environment must be explicitly
28
+ safe.
29
+
30
+ ## Hooks
31
+
32
+ Plugins may contribute tools, prompt messages, lifecycle work, operational
33
+ reports, migrations, and other typed hook surfaces exported by this package.
34
+
35
+ - Hook context carries the active source, actor, conversation, plugin metadata,
36
+ database, logging, and only the host capabilities required by that hook.
37
+ - Prompt hooks return bounded structured prompt messages rather than mutate the
38
+ core prompt.
39
+ - Tool hooks return model-visible schemas aligned with their executor inputs.
40
+ - Host-owned structured model and embedding calls do not expose provider
41
+ credentials to plugins.
42
+
43
+ ## Durable Work
44
+
45
+ - Heartbeat hooks perform bounded periodic maintenance and must be safe to run
46
+ repeatedly.
47
+ - Background tasks are registered by name, receive validated parameters, and
48
+ execute through the host queue/callback lifecycle.
49
+ - `ctx.agent.dispatch` creates durable agent work with an explicit actor,
50
+ destination, source, metadata, and idempotency identity.
51
+ - Delegated credential subjects declare the narrow action that authorized them.
52
+ Core owns runtime bindings; scheduler task subjects are accepted only from the
53
+ scheduler plugin and are bound to the exact task id.
54
+ - Completed dispatch and task projections are durable plugin inputs, not an
55
+ invitation to inspect unrestricted conversation state.
56
+
57
+ ## Database
58
+
59
+ - Packaged migrations create plugin-owned tables through the host migration
60
+ runner.
61
+ - Generate migration artifacts from the package schema; do not hand-maintain a
62
+ second schema contract.
63
+ - Runtime hooks and CLI actions use host-provided `ctx.db`.
64
+ - Migrations are expand-first, deterministic, ordered by plugin name, and safe
65
+ to retry. A failure blocks upgrade rather than partially enabling the plugin.
66
+ - Cross-plugin or core-table access is a review boundary for trusted app code;
67
+ introduce a facade only when a concrete security or lifecycle boundary
68
+ requires it.
69
+
70
+ ## CLI
71
+
72
+ Code plugins may register one namespaced host CLI command with one or more
73
+ subcommands. Core command names win. Actions use the host action wrapper and
74
+ receive plugin metadata, configuration, database, safe output writers, and
75
+ logging—not model, Slack, sandbox, or provider credential context.
76
+
77
+ ## Security
78
+
79
+ Plugins and skills follow `../../policies/security.md`,
80
+ `../../policies/data-redaction.md`, and
81
+ `../../policies/provider-boundaries.md`. Skills explain capability use; they do
82
+ not bootstrap runtimes or credentials.
package/dist/index.js CHANGED
@@ -7,6 +7,9 @@ var exactActorUserIdSchema = z.string().min(1).refine(
7
7
  (value) => value === value.trim() && value.toLowerCase() !== "unknown"
8
8
  );
9
9
  var nonBlankStringSchema = z.string().refine((value) => value.trim().length > 0);
10
+ var exactNonBlankStringSchema = nonBlankStringSchema.refine(
11
+ (value) => value === value.trim()
12
+ );
10
13
  var platformSchema = z.enum(["slack", "local"]);
11
14
  var sourceTypeSchema = z.enum(["pub", "priv"]);
12
15
  var slackAddressSchema = z.object({
@@ -37,11 +40,22 @@ var sourceSchema = z.discriminatedUnion("platform", [
37
40
  slackSourceSchema,
38
41
  localSourceSchema
39
42
  ]);
40
- var pluginCredentialSubjectSchema = z.object({
41
- type: z.literal("user"),
42
- userId: exactActorUserIdSchema,
43
- allowedWhen: z.literal("private-direct-conversation")
44
- }).strict();
43
+ var pluginCredentialSubjectSchema = z.discriminatedUnion(
44
+ "allowedWhen",
45
+ [
46
+ z.object({
47
+ type: z.literal("user"),
48
+ userId: exactActorUserIdSchema,
49
+ allowedWhen: z.literal("private-direct-conversation")
50
+ }).strict(),
51
+ z.object({
52
+ type: z.literal("user"),
53
+ userId: exactActorUserIdSchema,
54
+ allowedWhen: z.literal("scheduled-task"),
55
+ taskId: exactNonBlankStringSchema
56
+ }).strict()
57
+ ]
58
+ );
45
59
  var actorProfileSchema = {
46
60
  email: nonBlankStringSchema.optional(),
47
61
  fullName: nonBlankStringSchema.optional(),
package/dist/schemas.d.ts CHANGED
@@ -65,11 +65,16 @@ export declare const sourceSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
65
65
  conversationId: z.ZodString;
66
66
  }, z.core.$strict>], "platform">;
67
67
  /** Stable user credential subject shape accepted from plugins. */
68
- export declare const pluginCredentialSubjectSchema: z.ZodObject<{
68
+ export declare const pluginCredentialSubjectSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
69
69
  type: z.ZodLiteral<"user">;
70
70
  userId: z.ZodString;
71
71
  allowedWhen: z.ZodLiteral<"private-direct-conversation">;
72
- }, z.core.$strict>;
72
+ }, z.core.$strict>, z.ZodObject<{
73
+ type: z.ZodLiteral<"user">;
74
+ userId: z.ZodString;
75
+ allowedWhen: z.ZodLiteral<"scheduled-task">;
76
+ taskId: z.ZodString;
77
+ }, z.core.$strict>], "allowedWhen">;
73
78
  export declare const slackActorSchema: z.ZodObject<{
74
79
  platform: z.ZodLiteral<"slack">;
75
80
  teamId: z.ZodString;
@@ -110,11 +115,16 @@ export declare const actorSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
110
115
  /** Plugin dispatch request accepted by Junior core. */
111
116
  export declare const dispatchOptionsSchema: z.ZodObject<{
112
117
  idempotencyKey: z.ZodPipe<z.ZodString, z.ZodString>;
113
- credentialSubject: z.ZodOptional<z.ZodObject<{
118
+ credentialSubject: z.ZodOptional<z.ZodDiscriminatedUnion<[z.ZodObject<{
114
119
  type: z.ZodLiteral<"user">;
115
120
  userId: z.ZodString;
116
121
  allowedWhen: z.ZodLiteral<"private-direct-conversation">;
117
- }, z.core.$strict>>;
122
+ }, z.core.$strict>, z.ZodObject<{
123
+ type: z.ZodLiteral<"user">;
124
+ userId: z.ZodString;
125
+ allowedWhen: z.ZodLiteral<"scheduled-task">;
126
+ taskId: z.ZodString;
127
+ }, z.core.$strict>], "allowedWhen">>;
118
128
  destination: z.ZodObject<{
119
129
  platform: z.ZodLiteral<"slack">;
120
130
  teamId: z.ZodString;
package/dist/tools.d.ts CHANGED
@@ -153,7 +153,9 @@ export interface SlackToolRegistrationHookContext {
153
153
  canCreateCanvas: boolean;
154
154
  canPostToChannel: boolean;
155
155
  };
156
- credentialSubject?: PluginCredentialSubject;
156
+ credentialSubject?: Extract<PluginCredentialSubject, {
157
+ allowedWhen: "private-direct-conversation";
158
+ }>;
157
159
  }
158
160
  interface BaseToolRegistrationHookContext extends PluginContext {
159
161
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sentry/junior-plugin-api",
3
- "version": "0.100.0",
3
+ "version": "0.102.0",
4
4
  "private": false,
5
5
  "publishConfig": {
6
6
  "access": "public"
package/src/schemas.ts CHANGED
@@ -15,6 +15,9 @@ const exactActorUserIdSchema = z
15
15
  export const nonBlankStringSchema = z
16
16
  .string()
17
17
  .refine((value) => value.trim().length > 0);
18
+ const exactNonBlankStringSchema = nonBlankStringSchema.refine(
19
+ (value) => value === value.trim(),
20
+ );
18
21
 
19
22
  /** Runtime platform names supported by plugin public contracts. */
20
23
  export const platformSchema = z.enum(["slack", "local"]);
@@ -72,13 +75,26 @@ export const sourceSchema = z.discriminatedUnion("platform", [
72
75
  ]);
73
76
 
74
77
  /** Stable user credential subject shape accepted from plugins. */
75
- export const pluginCredentialSubjectSchema = z
76
- .object({
77
- type: z.literal("user"),
78
- userId: exactActorUserIdSchema,
79
- allowedWhen: z.literal("private-direct-conversation"),
80
- })
81
- .strict();
78
+ export const pluginCredentialSubjectSchema = z.discriminatedUnion(
79
+ "allowedWhen",
80
+ [
81
+ z
82
+ .object({
83
+ type: z.literal("user"),
84
+ userId: exactActorUserIdSchema,
85
+ allowedWhen: z.literal("private-direct-conversation"),
86
+ })
87
+ .strict(),
88
+ z
89
+ .object({
90
+ type: z.literal("user"),
91
+ userId: exactActorUserIdSchema,
92
+ allowedWhen: z.literal("scheduled-task"),
93
+ taskId: exactNonBlankStringSchema,
94
+ })
95
+ .strict(),
96
+ ],
97
+ );
82
98
 
83
99
  /** Shared exact actor profile fields for platform-scoped actors. */
84
100
  const actorProfileSchema = {
package/src/tools.ts CHANGED
@@ -277,7 +277,10 @@ export interface SlackToolRegistrationHookContext {
277
277
  canCreateCanvas: boolean;
278
278
  canPostToChannel: boolean;
279
279
  };
280
- credentialSubject?: PluginCredentialSubject;
280
+ credentialSubject?: Extract<
281
+ PluginCredentialSubject,
282
+ { allowedWhen: "private-direct-conversation" }
283
+ >;
281
284
  }
282
285
 
283
286
  interface BaseToolRegistrationHookContext extends PluginContext {