@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/src/tools.ts ADDED
@@ -0,0 +1,144 @@
1
+ import type {
2
+ PluginContext,
3
+ LocalInvocationContext,
4
+ PluginEmbedder,
5
+ PluginModel,
6
+ Requester,
7
+ SlackInvocationContext,
8
+ } from "./context";
9
+ import type { PluginCredentialSubject } from "./credentials";
10
+ import type { PluginState } from "./state";
11
+
12
+ export interface PluginEnv {
13
+ get(key: string): string | undefined;
14
+ set(key: string, value: string): void;
15
+ }
16
+
17
+ export interface PluginDecision {
18
+ deny(message: string): void;
19
+ replaceInput(input: Record<string, unknown>): void;
20
+ }
21
+
22
+ /** Thrown when a plugin tool rejects invalid model or user input. */
23
+ export class PluginToolInputError extends Error {
24
+ constructor(message: string, options?: { cause?: unknown }) {
25
+ super(message, options);
26
+ this.name = "PluginToolInputError";
27
+ }
28
+ }
29
+
30
+ export interface PluginSandbox {
31
+ juniorRoot: string;
32
+ root: string;
33
+ readFile(path: string): Promise<Uint8Array | null>;
34
+ run(input: {
35
+ args?: string[];
36
+ cmd: string;
37
+ cwd?: string;
38
+ env?: Record<string, string>;
39
+ sudo?: boolean;
40
+ }): Promise<{
41
+ exitCode: number;
42
+ stderr: string;
43
+ stdout: string;
44
+ }>;
45
+ writeFile(input: {
46
+ content: string | Uint8Array;
47
+ mode?: number;
48
+ path: string;
49
+ }): Promise<void>;
50
+ }
51
+
52
+ export interface SandboxPrepareHookContext extends PluginContext {
53
+ requester?: Requester;
54
+ sandbox: PluginSandbox;
55
+ }
56
+
57
+ export interface BeforeToolExecuteHookContext extends PluginContext {
58
+ decision: PluginDecision;
59
+ env: PluginEnv;
60
+ requester?: Requester;
61
+ tool: {
62
+ input: Record<string, unknown>;
63
+ name: string;
64
+ };
65
+ }
66
+
67
+ export interface PluginToolExecuteOptions {
68
+ /**
69
+ * @deprecated Internal compatibility escape hatch for legacy tool bridges.
70
+ * Plugin tools should use typed input fields and runtime hook context instead.
71
+ */
72
+ experimental_context?: unknown;
73
+ /** Stable runtime tool-call id; durable create tools should derive idempotency keys from it. */
74
+ toolCallId?: string;
75
+ }
76
+
77
+ export type PluginToolExecute<TInput = unknown> = {
78
+ bivarianceHack(
79
+ input: TInput,
80
+ options: PluginToolExecuteOptions,
81
+ ): Promise<unknown> | unknown;
82
+ }["bivarianceHack"];
83
+
84
+ export interface PluginToolDefinition<TInput = unknown> {
85
+ annotations?: unknown;
86
+ description: string;
87
+ executionMode?: unknown;
88
+ inputSchema: unknown;
89
+ prepareArguments?: (args: unknown) => unknown;
90
+ /**
91
+ * @deprecated Put tool-selection and usage guidance directly in `description`
92
+ * and parameter descriptions. Retained for compatibility; may be removed in a
93
+ * future major version.
94
+ */
95
+ promptGuidelines?: string[];
96
+ /**
97
+ * @deprecated Put tool-selection and usage guidance directly in `description`
98
+ * and parameter descriptions. Retained for compatibility; may be removed in a
99
+ * future major version.
100
+ */
101
+ promptSnippet?: string;
102
+ execute?: PluginToolExecute<TInput>;
103
+ }
104
+
105
+ export interface SlackToolRegistrationHookContext {
106
+ /**
107
+ * Capabilities of the source Slack conversation exposed to this plugin.
108
+ * Recomputed from `source.channelId`, not from `destination`.
109
+ */
110
+ channelCapabilities: {
111
+ canAddReactions: boolean;
112
+ canCreateCanvas: boolean;
113
+ canPostToChannel: boolean;
114
+ };
115
+ credentialSubject?: PluginCredentialSubject;
116
+ }
117
+
118
+ interface BaseToolRegistrationHookContext extends PluginContext {
119
+ /**
120
+ * Opaque Junior conversation/session identity for this turn.
121
+ * Interactive Slack turns use `slack:{channelId}:{threadTs}`.
122
+ * Scheduled/API turns use an internal id such as `agent-dispatch:{id}`.
123
+ * Do not parse as Slack unless the value starts with `slack:`.
124
+ */
125
+ conversationId?: string;
126
+ embedder: PluginEmbedder;
127
+ model: PluginModel;
128
+ state: PluginState;
129
+ userText?: string;
130
+ }
131
+
132
+ interface SlackToolRegistrationContext
133
+ extends BaseToolRegistrationHookContext, SlackInvocationContext {
134
+ slack: SlackToolRegistrationHookContext;
135
+ }
136
+
137
+ interface LocalToolRegistrationContext
138
+ extends BaseToolRegistrationHookContext, LocalInvocationContext {
139
+ slack?: never;
140
+ }
141
+
142
+ export type ToolRegistrationHookContext =
143
+ | LocalToolRegistrationContext
144
+ | SlackToolRegistrationContext;