@sentry/junior-plugin-api 0.116.0 → 0.117.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/hooks.d.ts +2 -2
- package/dist/index.d.ts +1 -1
- package/dist/index.js +18 -0
- package/dist/prompt.d.ts +21 -0
- package/package.json +1 -1
- package/src/hooks.ts +5 -1
- package/src/index.ts +5 -0
- package/src/prompt.ts +48 -0
package/dist/hooks.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import type { EgressHookContext, EgressResponseHookContext, IssueCredentialHookContext, PluginCredentialResult, PluginGrant, PluginProviderAccount, ResolveOAuthAccountHookContext } from "./credentials";
|
|
2
2
|
import type { HeartbeatHookContext, HeartbeatResult, OperationalReportHookContext, ApiRouteRegistrationHookContext, PluginOperationalReportContent, PluginRoute, PluginRouteApp, RouteRegistrationHookContext, SlackConversationLink, SlackConversationLinkHookContext } from "./operations";
|
|
3
3
|
import type { BeforeToolExecuteHookContext, PluginToolDefinition, SandboxPrepareHookContext, ToolRegistrationHookContext } from "./tools";
|
|
4
|
-
import type { PromptMessage, SystemPromptContext, UserPromptContext } from "./prompt";
|
|
4
|
+
import type { PromptMessage, SystemPromptContext, UserPromptContext, UserPromptContribution } from "./prompt";
|
|
5
5
|
export interface PluginHooks {
|
|
6
6
|
systemPrompt?(ctx: SystemPromptContext): Promise<PromptMessage[]> | PromptMessage[];
|
|
7
|
-
userPrompt?(ctx: UserPromptContext): Promise<
|
|
7
|
+
userPrompt?(ctx: UserPromptContext): Promise<UserPromptContribution[] | undefined> | UserPromptContribution[] | undefined;
|
|
8
8
|
beforeToolExecute?(ctx: BeforeToolExecuteHookContext): Promise<void> | void;
|
|
9
9
|
grantForEgress?(ctx: EgressHookContext): Promise<PluginGrant | undefined> | PluginGrant | undefined;
|
|
10
10
|
heartbeat?(ctx: HeartbeatHookContext): Promise<HeartbeatResult | void> | HeartbeatResult | void;
|
package/dist/index.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ export * from "./annotations";
|
|
|
2
2
|
export * from "./schemas";
|
|
3
3
|
export * from "./context";
|
|
4
4
|
export * from "./state";
|
|
5
|
-
export { promptMessageSchema, type PromptMessage, type SystemPromptContext, type UserPromptContext, } from "./prompt";
|
|
5
|
+
export { definePromptContext, promptContextSchema, promptMessageSchema, type PromptContext, type PromptContextContribution, type PromptMessage, type SystemPromptContext, type UserPromptContribution, type UserPromptContext, } from "./prompt";
|
|
6
6
|
export * from "./dispatch";
|
|
7
7
|
export * from "./resource-events";
|
|
8
8
|
export * from "./tasks";
|
package/dist/index.js
CHANGED
|
@@ -198,9 +198,25 @@ function isSlackDestination(destination) {
|
|
|
198
198
|
|
|
199
199
|
// src/prompt.ts
|
|
200
200
|
import { z as z3 } from "zod";
|
|
201
|
+
var promptContextKindSchema = z3.string().trim().min(1).max(64).regex(/^[a-z][a-z0-9_-]*$/);
|
|
201
202
|
var promptMessageSchema = z3.object({
|
|
202
203
|
text: z3.string().trim().min(1).max(8e3)
|
|
203
204
|
}).strict();
|
|
205
|
+
var promptContextSchema = z3.object({
|
|
206
|
+
kind: promptContextKindSchema,
|
|
207
|
+
version: z3.number().int().positive(),
|
|
208
|
+
content: z3.record(z3.string(), z3.unknown())
|
|
209
|
+
}).strict();
|
|
210
|
+
function definePromptContext(definition) {
|
|
211
|
+
const identity = promptContextSchema.pick({ kind: true, version: true }).parse({ kind: definition.kind, version: definition.version });
|
|
212
|
+
return (content) => {
|
|
213
|
+
const parsed = definition.schema.parse(content);
|
|
214
|
+
return {
|
|
215
|
+
context: { ...identity, content: parsed },
|
|
216
|
+
renderPrompt: () => definition.renderPrompt(parsed)
|
|
217
|
+
};
|
|
218
|
+
};
|
|
219
|
+
}
|
|
204
220
|
|
|
205
221
|
// src/resource-events.ts
|
|
206
222
|
import { z as z4 } from "zod";
|
|
@@ -494,6 +510,7 @@ export {
|
|
|
494
510
|
createSlackSource,
|
|
495
511
|
defineJuniorPlugin,
|
|
496
512
|
definePluginTool,
|
|
513
|
+
definePromptContext,
|
|
497
514
|
destinationSchema,
|
|
498
515
|
destinationVisibilitySchema,
|
|
499
516
|
dispatchOptionsSchema,
|
|
@@ -520,6 +537,7 @@ export {
|
|
|
520
537
|
pluginToolContinuationSchema,
|
|
521
538
|
pluginToolErrorSchema,
|
|
522
539
|
pluginToolResultSchema,
|
|
540
|
+
promptContextSchema,
|
|
523
541
|
promptMessageSchema,
|
|
524
542
|
resourceEventSchema,
|
|
525
543
|
resourceLinkAnnotationSchema,
|
package/dist/prompt.d.ts
CHANGED
|
@@ -6,6 +6,27 @@ export declare const promptMessageSchema: z.ZodObject<{
|
|
|
6
6
|
}, z.core.$strict>;
|
|
7
7
|
/** Small plugin-owned prompt text block rendered by Junior core. */
|
|
8
8
|
export type PromptMessage = z.output<typeof promptMessageSchema>;
|
|
9
|
+
export declare const promptContextSchema: z.ZodObject<{
|
|
10
|
+
kind: z.ZodString;
|
|
11
|
+
version: z.ZodNumber;
|
|
12
|
+
content: z.ZodRecord<z.ZodString, z.ZodUnknown>;
|
|
13
|
+
}, z.core.$strict>;
|
|
14
|
+
/** Structured plugin context retained alongside its model-visible rendering. */
|
|
15
|
+
export type PromptContext = z.output<typeof promptContextSchema>;
|
|
16
|
+
/** Runtime contribution produced from one validated plugin context value. */
|
|
17
|
+
export interface PromptContextContribution {
|
|
18
|
+
context: PromptContext;
|
|
19
|
+
renderPrompt(): string;
|
|
20
|
+
}
|
|
21
|
+
/** Define one typed, versioned plugin context contribution. */
|
|
22
|
+
export declare function definePromptContext<TSchema extends z.ZodType<Record<string, unknown>>>(definition: {
|
|
23
|
+
kind: string;
|
|
24
|
+
version: number;
|
|
25
|
+
schema: TSchema;
|
|
26
|
+
renderPrompt(content: z.output<TSchema>): string;
|
|
27
|
+
}): (content: z.input<TSchema>) => PromptContextContribution;
|
|
28
|
+
/** One request-scoped plugin contribution to the model-visible user prompt. */
|
|
29
|
+
export type UserPromptContribution = PromptMessage | PromptContextContribution;
|
|
9
30
|
/** Stable platform context for plugin system prompt guidance. */
|
|
10
31
|
export type SystemPromptContext = Pick<PluginContext, "db" | "log" | "plugin"> & {
|
|
11
32
|
platform: Platform;
|
package/package.json
CHANGED
package/src/hooks.ts
CHANGED
|
@@ -29,6 +29,7 @@ import type {
|
|
|
29
29
|
PromptMessage,
|
|
30
30
|
SystemPromptContext,
|
|
31
31
|
UserPromptContext,
|
|
32
|
+
UserPromptContribution,
|
|
32
33
|
} from "./prompt";
|
|
33
34
|
|
|
34
35
|
export interface PluginHooks {
|
|
@@ -37,7 +38,10 @@ export interface PluginHooks {
|
|
|
37
38
|
): Promise<PromptMessage[]> | PromptMessage[];
|
|
38
39
|
userPrompt?(
|
|
39
40
|
ctx: UserPromptContext,
|
|
40
|
-
):
|
|
41
|
+
):
|
|
42
|
+
| Promise<UserPromptContribution[] | undefined>
|
|
43
|
+
| UserPromptContribution[]
|
|
44
|
+
| undefined;
|
|
41
45
|
beforeToolExecute?(ctx: BeforeToolExecuteHookContext): Promise<void> | void;
|
|
42
46
|
grantForEgress?(
|
|
43
47
|
ctx: EgressHookContext,
|
package/src/index.ts
CHANGED
|
@@ -3,9 +3,14 @@ export * from "./schemas";
|
|
|
3
3
|
export * from "./context";
|
|
4
4
|
export * from "./state";
|
|
5
5
|
export {
|
|
6
|
+
definePromptContext,
|
|
7
|
+
promptContextSchema,
|
|
6
8
|
promptMessageSchema,
|
|
9
|
+
type PromptContext,
|
|
10
|
+
type PromptContextContribution,
|
|
7
11
|
type PromptMessage,
|
|
8
12
|
type SystemPromptContext,
|
|
13
|
+
type UserPromptContribution,
|
|
9
14
|
type UserPromptContext,
|
|
10
15
|
} from "./prompt";
|
|
11
16
|
export * from "./dispatch";
|
package/src/prompt.ts
CHANGED
|
@@ -9,6 +9,13 @@ import type {
|
|
|
9
9
|
} from "./context";
|
|
10
10
|
import type { PluginState } from "./state";
|
|
11
11
|
|
|
12
|
+
const promptContextKindSchema = z
|
|
13
|
+
.string()
|
|
14
|
+
.trim()
|
|
15
|
+
.min(1)
|
|
16
|
+
.max(64)
|
|
17
|
+
.regex(/^[a-z][a-z0-9_-]*$/);
|
|
18
|
+
|
|
12
19
|
export const promptMessageSchema = z
|
|
13
20
|
.object({
|
|
14
21
|
text: z.string().trim().min(1).max(8_000),
|
|
@@ -18,6 +25,47 @@ export const promptMessageSchema = z
|
|
|
18
25
|
/** Small plugin-owned prompt text block rendered by Junior core. */
|
|
19
26
|
export type PromptMessage = z.output<typeof promptMessageSchema>;
|
|
20
27
|
|
|
28
|
+
export const promptContextSchema = z
|
|
29
|
+
.object({
|
|
30
|
+
kind: promptContextKindSchema,
|
|
31
|
+
version: z.number().int().positive(),
|
|
32
|
+
content: z.record(z.string(), z.unknown()),
|
|
33
|
+
})
|
|
34
|
+
.strict();
|
|
35
|
+
|
|
36
|
+
/** Structured plugin context retained alongside its model-visible rendering. */
|
|
37
|
+
export type PromptContext = z.output<typeof promptContextSchema>;
|
|
38
|
+
|
|
39
|
+
/** Runtime contribution produced from one validated plugin context value. */
|
|
40
|
+
export interface PromptContextContribution {
|
|
41
|
+
context: PromptContext;
|
|
42
|
+
renderPrompt(): string;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** Define one typed, versioned plugin context contribution. */
|
|
46
|
+
export function definePromptContext<
|
|
47
|
+
TSchema extends z.ZodType<Record<string, unknown>>,
|
|
48
|
+
>(definition: {
|
|
49
|
+
kind: string;
|
|
50
|
+
version: number;
|
|
51
|
+
schema: TSchema;
|
|
52
|
+
renderPrompt(content: z.output<TSchema>): string;
|
|
53
|
+
}): (content: z.input<TSchema>) => PromptContextContribution {
|
|
54
|
+
const identity = promptContextSchema
|
|
55
|
+
.pick({ kind: true, version: true })
|
|
56
|
+
.parse({ kind: definition.kind, version: definition.version });
|
|
57
|
+
return (content) => {
|
|
58
|
+
const parsed = definition.schema.parse(content);
|
|
59
|
+
return {
|
|
60
|
+
context: { ...identity, content: parsed },
|
|
61
|
+
renderPrompt: () => definition.renderPrompt(parsed),
|
|
62
|
+
};
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** One request-scoped plugin contribution to the model-visible user prompt. */
|
|
67
|
+
export type UserPromptContribution = PromptMessage | PromptContextContribution;
|
|
68
|
+
|
|
21
69
|
/** Stable platform context for plugin system prompt guidance. */
|
|
22
70
|
export type SystemPromptContext = Pick<
|
|
23
71
|
PluginContext,
|