@sentry/junior-plugin-api 0.198.0 → 0.200.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 +2025 -19
- package/package.json +4 -5
- package/dist/annotations.d.ts +0 -75
- package/dist/cli.d.ts +0 -39
- package/dist/code.d.ts +0 -37
- package/dist/context.d.ts +0 -158
- package/dist/conversation-events.d.ts +0 -80
- package/dist/credentials.d.ts +0 -184
- package/dist/dispatch.d.ts +0 -16
- package/dist/egress-policy.d.ts +0 -9
- package/dist/hooks.d.ts +0 -43
- package/dist/manifest.d.ts +0 -76
- package/dist/operations.d.ts +0 -153
- package/dist/prompt.d.ts +0 -56
- package/dist/registration.d.ts +0 -28
- package/dist/resource-events.d.ts +0 -128
- package/dist/schemas.d.ts +0 -261
- package/dist/state.d.ts +0 -10
- package/dist/tasks.d.ts +0 -250
- package/dist/tools.d.ts +0 -351
- package/dist/user-pages.d.ts +0 -97
- package/src/annotations.ts +0 -78
- package/src/cli.ts +0 -54
- package/src/code.ts +0 -37
- package/src/context.ts +0 -241
- package/src/conversation-events.ts +0 -136
- package/src/credentials.ts +0 -221
- package/src/dispatch.ts +0 -31
- package/src/egress-policy.ts +0 -15
- package/src/hooks.ts +0 -118
- package/src/index.ts +0 -29
- package/src/manifest.ts +0 -89
- package/src/operations.ts +0 -199
- package/src/prompt.ts +0 -99
- package/src/registration.ts +0 -173
- package/src/resource-events.ts +0 -320
- package/src/schemas.ts +0 -348
- package/src/state.ts +0 -15
- package/src/tasks.ts +0 -105
- package/src/tools.ts +0 -579
- package/src/user-pages.ts +0 -130
package/src/tasks.ts
DELETED
|
@@ -1,105 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Public plugin background-task contracts.
|
|
3
|
-
*
|
|
4
|
-
* Plugins register small task handlers. Junior core owns scheduling, delivery,
|
|
5
|
-
* retries, and the bounded run projection.
|
|
6
|
-
*/
|
|
7
|
-
import { z } from "zod";
|
|
8
|
-
import type { PluginConversationEvents } from "./conversation-events";
|
|
9
|
-
import type { PluginContext, PluginEmbedder, PluginModel } from "./context";
|
|
10
|
-
import { destinationSchema, actorSchema, sourceSchema } from "./schemas";
|
|
11
|
-
import type { PluginState } from "./state";
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Runtime-owned provenance for a transcript message: whether it is a durable
|
|
15
|
-
* instruction or ambient context, plus the actor identity when known. Missing
|
|
16
|
-
* provenance on an entry means unattributed context.
|
|
17
|
-
*/
|
|
18
|
-
export const pluginRunTranscriptProvenanceSchema = z
|
|
19
|
-
.object({
|
|
20
|
-
authority: z.enum(["instruction", "context"]),
|
|
21
|
-
actor: actorSchema.optional(),
|
|
22
|
-
})
|
|
23
|
-
.strict();
|
|
24
|
-
|
|
25
|
-
/** One normalized transcript entry from the completed run exposed to plugin tasks. */
|
|
26
|
-
export const pluginRunTranscriptEntrySchema = z.discriminatedUnion("type", [
|
|
27
|
-
z
|
|
28
|
-
.object({
|
|
29
|
-
type: z.literal("message"),
|
|
30
|
-
role: z.enum(["user", "assistant"]),
|
|
31
|
-
text: z.string().min(1),
|
|
32
|
-
provenance: pluginRunTranscriptProvenanceSchema.optional(),
|
|
33
|
-
isRunActor: z.boolean().optional(),
|
|
34
|
-
})
|
|
35
|
-
.strict(),
|
|
36
|
-
z
|
|
37
|
-
.object({
|
|
38
|
-
type: z.literal("toolResult"),
|
|
39
|
-
toolName: z.string().min(1),
|
|
40
|
-
isError: z.boolean(),
|
|
41
|
-
text: z.string().min(1).optional(),
|
|
42
|
-
})
|
|
43
|
-
.strict(),
|
|
44
|
-
]);
|
|
45
|
-
|
|
46
|
-
export type PluginRunTranscriptProvenance = z.output<
|
|
47
|
-
typeof pluginRunTranscriptProvenanceSchema
|
|
48
|
-
>;
|
|
49
|
-
|
|
50
|
-
/** Runtime-owned completed-run projection exposed to plugin tasks. */
|
|
51
|
-
export const pluginRunContextSchema = z
|
|
52
|
-
.object({
|
|
53
|
-
/** User linked to the Actor, when known. */
|
|
54
|
-
actorUserId: z.string().min(1).optional(),
|
|
55
|
-
completedAtMs: z.number().finite(),
|
|
56
|
-
conversationId: z.string().min(1),
|
|
57
|
-
destination: destinationSchema,
|
|
58
|
-
/** Location associated with this Conversation. */
|
|
59
|
-
locationId: z.string().min(1).optional(),
|
|
60
|
-
/**
|
|
61
|
-
* All distinct actors annotated on this run's committed instruction-authority
|
|
62
|
-
* messages, in first-seen order. Attribution provenance only, never an
|
|
63
|
-
* authority source: a plugin must not treat membership here as credential,
|
|
64
|
-
* subject, or scope ownership. Derived from full-run provenance, so it can
|
|
65
|
-
* exceed the actors visible in the transcript slice. Usually `[run.actor]`;
|
|
66
|
-
* possibly empty for system runs with no human instructions.
|
|
67
|
-
*/
|
|
68
|
-
actors: z.array(actorSchema),
|
|
69
|
-
/**
|
|
70
|
-
* The single actor this run executes as. Absent only for actor-less legacy
|
|
71
|
-
* system records, so authority-sensitive plugins must fail closed.
|
|
72
|
-
*/
|
|
73
|
-
actor: actorSchema.optional(),
|
|
74
|
-
runId: z.string().min(1),
|
|
75
|
-
source: sourceSchema,
|
|
76
|
-
transcript: z.array(pluginRunTranscriptEntrySchema),
|
|
77
|
-
})
|
|
78
|
-
.strict();
|
|
79
|
-
|
|
80
|
-
export type PluginRunTranscriptEntry = z.output<
|
|
81
|
-
typeof pluginRunTranscriptEntrySchema
|
|
82
|
-
>;
|
|
83
|
-
|
|
84
|
-
export type PluginRunContext = z.output<typeof pluginRunContextSchema>;
|
|
85
|
-
|
|
86
|
-
/** Runtime context passed to a plugin-owned background task. */
|
|
87
|
-
export interface PluginTaskContext extends PluginContext {
|
|
88
|
-
embedder: PluginEmbedder;
|
|
89
|
-
events: PluginConversationEvents;
|
|
90
|
-
id: string;
|
|
91
|
-
model: PluginModel;
|
|
92
|
-
name: string;
|
|
93
|
-
run: {
|
|
94
|
-
load(): Promise<PluginRunContext>;
|
|
95
|
-
};
|
|
96
|
-
state: PluginState;
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
/** Plugin task handler registered by name in a plugin manifest module. */
|
|
100
|
-
export interface PluginTaskDefinition {
|
|
101
|
-
run(ctx: PluginTaskContext): Promise<void> | void;
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
/** Task handlers keyed by the plugin-owned task name. */
|
|
105
|
-
export type PluginTasks = Record<string, PluginTaskDefinition>;
|
package/src/tools.ts
DELETED
|
@@ -1,579 +0,0 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
Actor,
|
|
3
|
-
Identity,
|
|
4
|
-
InvocationContext,
|
|
5
|
-
PluginContext,
|
|
6
|
-
PluginEmbedder,
|
|
7
|
-
PluginModel,
|
|
8
|
-
User,
|
|
9
|
-
} from "./context";
|
|
10
|
-
import type { PluginCredentialSubject } from "./credentials";
|
|
11
|
-
import type { PluginAnnotations } from "./annotations";
|
|
12
|
-
import type { SlackConversationLink } from "./operations";
|
|
13
|
-
import type {
|
|
14
|
-
ResourceEventSubscriptionResult,
|
|
15
|
-
SubscribableResource,
|
|
16
|
-
} from "./resource-events";
|
|
17
|
-
import type { PluginState } from "./state";
|
|
18
|
-
import { z, type ZodTypeAny } from "zod";
|
|
19
|
-
|
|
20
|
-
export interface PluginEnv {
|
|
21
|
-
get(key: string): string | undefined;
|
|
22
|
-
set(key: string, value: string): void;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export interface PluginDecision {
|
|
26
|
-
deny(message: string): void;
|
|
27
|
-
replaceInput(input: Record<string, unknown>): void;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
/** Thrown when a plugin tool rejects invalid model or user input. */
|
|
31
|
-
export class PluginToolInputError extends Error {
|
|
32
|
-
constructor(message: string, options?: { cause?: unknown }) {
|
|
33
|
-
super(message, options);
|
|
34
|
-
this.name = "PluginToolInputError";
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
export interface PluginSandbox {
|
|
39
|
-
juniorRoot: string;
|
|
40
|
-
root: string;
|
|
41
|
-
readFile(path: string): Promise<Uint8Array | null>;
|
|
42
|
-
run(input: {
|
|
43
|
-
args?: string[];
|
|
44
|
-
cmd: string;
|
|
45
|
-
cwd?: string;
|
|
46
|
-
env?: Record<string, string>;
|
|
47
|
-
signal?: AbortSignal;
|
|
48
|
-
sudo?: boolean;
|
|
49
|
-
}): Promise<{
|
|
50
|
-
exitCode: number;
|
|
51
|
-
stderr: string;
|
|
52
|
-
stdout: string;
|
|
53
|
-
}>;
|
|
54
|
-
writeFile(input: {
|
|
55
|
-
content: string | Uint8Array;
|
|
56
|
-
mode?: number;
|
|
57
|
-
path: string;
|
|
58
|
-
}): Promise<void>;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
export interface PluginEgress {
|
|
62
|
-
/**
|
|
63
|
-
* Fetch a provider URL with host-owned credentials.
|
|
64
|
-
*
|
|
65
|
-
* The runtime selects and injects credentials for `provider`; plugin code
|
|
66
|
-
* owns the request shape and response handling. `operation` names the
|
|
67
|
-
* provider action for grant selection and diagnostics.
|
|
68
|
-
*/
|
|
69
|
-
fetch(input: {
|
|
70
|
-
operation: string;
|
|
71
|
-
provider: string;
|
|
72
|
-
request: Request;
|
|
73
|
-
}): Promise<Response>;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
export const pluginToolContentSchema = z.discriminatedUnion("type", [
|
|
77
|
-
z.object({ type: z.literal("text"), text: z.string() }).strict(),
|
|
78
|
-
z
|
|
79
|
-
.object({
|
|
80
|
-
type: z.literal("image"),
|
|
81
|
-
data: z.string(),
|
|
82
|
-
mimeType: z.string(),
|
|
83
|
-
})
|
|
84
|
-
.strict(),
|
|
85
|
-
]);
|
|
86
|
-
|
|
87
|
-
/** Model-visible content returned by a plugin tool. */
|
|
88
|
-
export type PluginToolContent = z.output<typeof pluginToolContentSchema>;
|
|
89
|
-
|
|
90
|
-
/** Pi-native projection with model-facing content and canonical runtime details. */
|
|
91
|
-
export interface PluginToolOutputEnvelope<TDetails = unknown> {
|
|
92
|
-
content: PluginToolContent[];
|
|
93
|
-
details: TDetails;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
export type PluginMcpContent = PluginToolContent;
|
|
97
|
-
|
|
98
|
-
/** Successful raw provider result returned to a plugin-owned wrapper tool. */
|
|
99
|
-
export type PluginMcpToolSuccess = {
|
|
100
|
-
content: PluginMcpContent[];
|
|
101
|
-
status: "success";
|
|
102
|
-
structuredContent?: unknown;
|
|
103
|
-
};
|
|
104
|
-
|
|
105
|
-
/** Handled provider authorization pause with no provider result to consume. */
|
|
106
|
-
export type PluginMcpAuthorizationPending = {
|
|
107
|
-
status: "authorization_pending";
|
|
108
|
-
};
|
|
109
|
-
|
|
110
|
-
/** Definitive provider rejection; transport and session failures still throw. */
|
|
111
|
-
export type PluginMcpToolError = {
|
|
112
|
-
message: string;
|
|
113
|
-
status: "error";
|
|
114
|
-
};
|
|
115
|
-
|
|
116
|
-
export type PluginMcpToolResult =
|
|
117
|
-
| PluginMcpAuthorizationPending
|
|
118
|
-
| PluginMcpToolError
|
|
119
|
-
| PluginMcpToolSuccess;
|
|
120
|
-
|
|
121
|
-
/** Access to this plugin's hosted MCP provider without exposing credentials. */
|
|
122
|
-
export interface PluginMcp {
|
|
123
|
-
/**
|
|
124
|
-
* Call a provider tool declared in `wrappedTools`.
|
|
125
|
-
*
|
|
126
|
-
* The host activates the provider when needed. Successful calls return the
|
|
127
|
-
* provider's original content, provider rejections return an error result,
|
|
128
|
-
* and authorization pauses return no tool content. Transport failures throw.
|
|
129
|
-
*/
|
|
130
|
-
callTool(input: {
|
|
131
|
-
arguments?: Record<string, unknown>;
|
|
132
|
-
name: string;
|
|
133
|
-
toolCallId?: string;
|
|
134
|
-
}): Promise<PluginMcpToolResult>;
|
|
135
|
-
/**
|
|
136
|
-
* Activate the provider before wrapper-owned state changes.
|
|
137
|
-
*
|
|
138
|
-
* Ordinary wrappers can call `callTool` directly. Durable mutation wrappers
|
|
139
|
-
* may prepare first so an initial authorization pause happens before they
|
|
140
|
-
* record pending work.
|
|
141
|
-
*/
|
|
142
|
-
prepare(): Promise<"authorization_pending" | "ready">;
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
/**
|
|
146
|
-
* Provider-owned, repeatable repository preparation for a Workspace Sandbox.
|
|
147
|
-
* Implementations should refresh complete checkouts and replace missing or
|
|
148
|
-
* partial ones.
|
|
149
|
-
*/
|
|
150
|
-
export interface WorkspacePrepareHookContext extends PluginContext {
|
|
151
|
-
repos: Array<{
|
|
152
|
-
path: string;
|
|
153
|
-
repo: string;
|
|
154
|
-
}>;
|
|
155
|
-
sandbox: PluginSandbox;
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
export interface SandboxPrepareHookContext extends PluginContext {
|
|
159
|
-
actor?: Actor;
|
|
160
|
-
sandbox: PluginSandbox;
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
export interface BeforeToolExecuteHookContext extends PluginContext {
|
|
164
|
-
decision: PluginDecision;
|
|
165
|
-
env: PluginEnv;
|
|
166
|
-
actor?: Actor;
|
|
167
|
-
/** All actors who contributed instructions to the run so far; see `multi-actor-runs.md`. */
|
|
168
|
-
actors?: Actor[];
|
|
169
|
-
tool: {
|
|
170
|
-
input: Record<string, unknown>;
|
|
171
|
-
name: string;
|
|
172
|
-
};
|
|
173
|
-
/**
|
|
174
|
-
* Resolve the current actor's stored identity and linked user.
|
|
175
|
-
* Same contract as tool registration; used for commit attribution.
|
|
176
|
-
*/
|
|
177
|
-
users: {
|
|
178
|
-
resolveActor(): Promise<{ identity: Identity; user?: User } | undefined>;
|
|
179
|
-
};
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
/**
|
|
183
|
-
* Context for post-success MCP tool processing.
|
|
184
|
-
*
|
|
185
|
-
* Runs after a hosted MCP tool succeeds on the model-facing path. Use for
|
|
186
|
-
* junior-owned side effects such as conversation annotations without replacing
|
|
187
|
-
* the provider tool contract.
|
|
188
|
-
*/
|
|
189
|
-
export interface AfterMcpToolHookContext extends PluginContext {
|
|
190
|
-
/**
|
|
191
|
-
* Opaque Junior conversation/session identity for this turn.
|
|
192
|
-
* Interactive Slack turns use `slack:{channelId}:{threadTs}`.
|
|
193
|
-
*/
|
|
194
|
-
conversationId?: string;
|
|
195
|
-
annotations?: PluginAnnotations;
|
|
196
|
-
result: {
|
|
197
|
-
structuredContent?: unknown;
|
|
198
|
-
};
|
|
199
|
-
tool: {
|
|
200
|
-
arguments: Record<string, unknown>;
|
|
201
|
-
/** Provider-local MCP tool name, for example `save_issue`. */
|
|
202
|
-
name: string;
|
|
203
|
-
};
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
export interface PluginToolExecuteOptions {
|
|
207
|
-
/**
|
|
208
|
-
* @deprecated Internal compatibility escape hatch for legacy tool bridges.
|
|
209
|
-
* Plugin tools should use typed input fields and runtime hook context instead.
|
|
210
|
-
*/
|
|
211
|
-
experimental_context?: unknown;
|
|
212
|
-
/** Abort when the owning agent tool call is cancelled or times out. */
|
|
213
|
-
signal?: AbortSignal;
|
|
214
|
-
/** Stable runtime tool-call id; durable create tools should derive idempotency keys from it. */
|
|
215
|
-
toolCallId?: string;
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
export const pluginToolContinuationSchema = z
|
|
219
|
-
.object({
|
|
220
|
-
arguments: z.record(z.string(), z.unknown()),
|
|
221
|
-
reason: z.string().min(1).optional(),
|
|
222
|
-
})
|
|
223
|
-
.strict();
|
|
224
|
-
|
|
225
|
-
/** Shared optional fields for canonical plugin tool outputs. */
|
|
226
|
-
export const pluginToolOutputSchema = z
|
|
227
|
-
.object({
|
|
228
|
-
target: z.string().min(1).optional(),
|
|
229
|
-
truncated: z.boolean().optional(),
|
|
230
|
-
continuation: pluginToolContinuationSchema.optional(),
|
|
231
|
-
})
|
|
232
|
-
.passthrough();
|
|
233
|
-
|
|
234
|
-
export type PluginToolOutput = z.output<typeof pluginToolOutputSchema>;
|
|
235
|
-
|
|
236
|
-
export type PluginToolExecute<TInput = unknown, TOutput = unknown> = {
|
|
237
|
-
bivarianceHack(
|
|
238
|
-
input: TInput,
|
|
239
|
-
options: PluginToolExecuteOptions,
|
|
240
|
-
): Promise<TOutput> | TOutput;
|
|
241
|
-
}["bivarianceHack"];
|
|
242
|
-
|
|
243
|
-
/**
|
|
244
|
-
* Tool-declared approval mode.
|
|
245
|
-
*
|
|
246
|
-
* `auto` delegates to core policy, `review` enters Guardian review, and
|
|
247
|
-
* `approve` permits execution without review. Plugin tool helpers normalize
|
|
248
|
-
* omission to `auto`.
|
|
249
|
-
*
|
|
250
|
-
* Core resolves the effective mode immediately before execution.
|
|
251
|
-
*/
|
|
252
|
-
export const toolApprovalModeSchema = z.enum(["auto", "review", "approve"]);
|
|
253
|
-
|
|
254
|
-
export type ToolApprovalMode = z.output<typeof toolApprovalModeSchema>;
|
|
255
|
-
|
|
256
|
-
/**
|
|
257
|
-
* Reviewer signals describing a tool's side-effect behavior.
|
|
258
|
-
*
|
|
259
|
-
* These hints follow the MCP tool annotation contract. Guardian may use
|
|
260
|
-
* them as signals, but they never grant authority or override deterministic
|
|
261
|
-
* authorization.
|
|
262
|
-
*/
|
|
263
|
-
export interface ToolAnnotations {
|
|
264
|
-
[key: string]: unknown;
|
|
265
|
-
destructiveHint?: boolean;
|
|
266
|
-
idempotentHint?: boolean;
|
|
267
|
-
openWorldHint?: boolean;
|
|
268
|
-
readOnlyHint?: boolean;
|
|
269
|
-
title?: string;
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
export const REQUIRED_TOOL_ANNOTATION_KEYS = [
|
|
273
|
-
"destructiveHint",
|
|
274
|
-
"idempotentHint",
|
|
275
|
-
"openWorldHint",
|
|
276
|
-
"readOnlyHint",
|
|
277
|
-
] as const;
|
|
278
|
-
|
|
279
|
-
export type RequiredToolAnnotationKey =
|
|
280
|
-
(typeof REQUIRED_TOOL_ANNOTATION_KEYS)[number];
|
|
281
|
-
|
|
282
|
-
/** Return behavioral annotation keys that a tool did not declare. */
|
|
283
|
-
export function missingToolAnnotationKeys(
|
|
284
|
-
annotations: ToolAnnotations | undefined,
|
|
285
|
-
): RequiredToolAnnotationKey[] {
|
|
286
|
-
return REQUIRED_TOOL_ANNOTATION_KEYS.filter(
|
|
287
|
-
(key) => typeof annotations?.[key] !== "boolean",
|
|
288
|
-
);
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
/**
|
|
292
|
-
* Canonical approval metadata declared by core and plugin tools.
|
|
293
|
-
*/
|
|
294
|
-
export interface ToolApprovalMetadata<TInput = unknown> {
|
|
295
|
-
/** Optional declared approval mode; the owning tool boundary selects defaults. */
|
|
296
|
-
approvalMode?: ToolApprovalMode;
|
|
297
|
-
annotations?: ToolAnnotations;
|
|
298
|
-
/**
|
|
299
|
-
* Describe the reviewed semantic action for the review request.
|
|
300
|
-
*
|
|
301
|
-
* Core owns authoritative tool, actor, source, destination, conversation,
|
|
302
|
-
* credential, and input data. This description adds domain-specific context
|
|
303
|
-
* only and is never an authorization grant.
|
|
304
|
-
*/
|
|
305
|
-
describeProposal?(input: TInput): string;
|
|
306
|
-
}
|
|
307
|
-
|
|
308
|
-
export interface PluginToolDefinition<
|
|
309
|
-
TInput = unknown,
|
|
310
|
-
TOutput = unknown,
|
|
311
|
-
TExecuteOutput = TOutput,
|
|
312
|
-
> extends ToolApprovalMetadata<TInput> {
|
|
313
|
-
description: string;
|
|
314
|
-
executionMode?: unknown;
|
|
315
|
-
inputSchema: unknown;
|
|
316
|
-
outputSchema?: unknown;
|
|
317
|
-
/**
|
|
318
|
-
* Select result fields that are safe to retain in private traces.
|
|
319
|
-
* Returning `undefined` suppresses private result capture.
|
|
320
|
-
*/
|
|
321
|
-
privateTraceResult?(result: TOutput): unknown;
|
|
322
|
-
prepareArguments?: (args: unknown) => TInput;
|
|
323
|
-
/**
|
|
324
|
-
* @deprecated Put tool-selection and usage guidance directly in `description`
|
|
325
|
-
* and parameter descriptions. Retained for compatibility; may be removed in a
|
|
326
|
-
* future major version.
|
|
327
|
-
*/
|
|
328
|
-
promptGuidelines?: string[];
|
|
329
|
-
/**
|
|
330
|
-
* @deprecated Put tool-selection and usage guidance directly in `description`
|
|
331
|
-
* and parameter descriptions. Retained for compatibility; may be removed in a
|
|
332
|
-
* future major version.
|
|
333
|
-
*/
|
|
334
|
-
promptSnippet?: string;
|
|
335
|
-
execute?: PluginToolExecute<TInput, TExecuteOutput>;
|
|
336
|
-
}
|
|
337
|
-
|
|
338
|
-
type ZodPluginToolDefinition<
|
|
339
|
-
TInputSchema extends ZodTypeAny,
|
|
340
|
-
TOutputSchema extends ZodTypeAny,
|
|
341
|
-
TExecuteResult extends
|
|
342
|
-
| z.input<TOutputSchema>
|
|
343
|
-
| PluginToolOutputEnvelope<z.input<TOutputSchema>>,
|
|
344
|
-
> = Omit<
|
|
345
|
-
PluginToolDefinition<z.output<TInputSchema>, z.output<TOutputSchema>>,
|
|
346
|
-
"inputSchema" | "outputSchema" | "prepareArguments" | "execute"
|
|
347
|
-
> & {
|
|
348
|
-
inputSchema: TInputSchema;
|
|
349
|
-
outputSchema: TOutputSchema;
|
|
350
|
-
prepareArguments?: (args: unknown) => z.input<TInputSchema>;
|
|
351
|
-
execute?: (
|
|
352
|
-
input: z.output<TInputSchema>,
|
|
353
|
-
options: PluginToolExecuteOptions,
|
|
354
|
-
) => Promise<TExecuteResult> | TExecuteResult;
|
|
355
|
-
};
|
|
356
|
-
|
|
357
|
-
type ParsedPluginToolExecuteResult<TOutputSchema extends ZodTypeAny, TResult> =
|
|
358
|
-
TResult extends PluginToolOutputEnvelope<unknown>
|
|
359
|
-
? PluginToolOutputEnvelope<z.output<TOutputSchema>>
|
|
360
|
-
: z.output<TOutputSchema>;
|
|
361
|
-
|
|
362
|
-
function isPluginToolOutputEnvelope(
|
|
363
|
-
value: unknown,
|
|
364
|
-
): value is PluginToolOutputEnvelope<unknown> {
|
|
365
|
-
return (
|
|
366
|
-
value !== null &&
|
|
367
|
-
typeof value === "object" &&
|
|
368
|
-
Array.isArray((value as { content?: unknown }).content) &&
|
|
369
|
-
"details" in value
|
|
370
|
-
);
|
|
371
|
-
}
|
|
372
|
-
|
|
373
|
-
function formatZodPath(path: readonly PropertyKey[]): string {
|
|
374
|
-
return path.length > 0 ? path.map(String).join(".") : "root";
|
|
375
|
-
}
|
|
376
|
-
|
|
377
|
-
function formatPluginToolInputError(error: z.ZodError): string {
|
|
378
|
-
const details = error.issues
|
|
379
|
-
.slice(0, 5)
|
|
380
|
-
.map((issue) => `${formatZodPath(issue.path)}: ${issue.message}`)
|
|
381
|
-
.join("; ");
|
|
382
|
-
return `Invalid tool arguments: ${details || "input did not match schema"}`;
|
|
383
|
-
}
|
|
384
|
-
|
|
385
|
-
function parsePluginToolInput<TInputSchema extends ZodTypeAny>(
|
|
386
|
-
schema: TInputSchema,
|
|
387
|
-
args: unknown,
|
|
388
|
-
): z.output<TInputSchema> {
|
|
389
|
-
const result = schema.safeParse(args);
|
|
390
|
-
if (!result.success) {
|
|
391
|
-
throw new PluginToolInputError(formatPluginToolInputError(result.error), {
|
|
392
|
-
cause: result.error,
|
|
393
|
-
});
|
|
394
|
-
}
|
|
395
|
-
return result.data;
|
|
396
|
-
}
|
|
397
|
-
|
|
398
|
-
function createZodTool<
|
|
399
|
-
TInputSchema extends ZodTypeAny,
|
|
400
|
-
TOutputSchema extends ZodTypeAny,
|
|
401
|
-
TExecuteResult extends
|
|
402
|
-
| z.input<TOutputSchema>
|
|
403
|
-
| PluginToolOutputEnvelope<z.input<TOutputSchema>>,
|
|
404
|
-
>(
|
|
405
|
-
definition: ZodPluginToolDefinition<
|
|
406
|
-
TInputSchema,
|
|
407
|
-
TOutputSchema,
|
|
408
|
-
TExecuteResult
|
|
409
|
-
>,
|
|
410
|
-
helperName: "definePluginTool" | "zodTool",
|
|
411
|
-
): PluginToolDefinition<
|
|
412
|
-
z.output<TInputSchema>,
|
|
413
|
-
z.output<TOutputSchema>,
|
|
414
|
-
ParsedPluginToolExecuteResult<TOutputSchema, TExecuteResult>
|
|
415
|
-
> {
|
|
416
|
-
const { inputSchema, outputSchema, prepareArguments, execute, ...tool } =
|
|
417
|
-
definition;
|
|
418
|
-
let modelInputSchema: unknown;
|
|
419
|
-
let modelOutputSchema: unknown;
|
|
420
|
-
try {
|
|
421
|
-
modelInputSchema = z.toJSONSchema(inputSchema);
|
|
422
|
-
} catch (error) {
|
|
423
|
-
throw new TypeError(
|
|
424
|
-
`${helperName}() inputSchema must be representable as JSON Schema.`,
|
|
425
|
-
{ cause: error },
|
|
426
|
-
);
|
|
427
|
-
}
|
|
428
|
-
try {
|
|
429
|
-
modelOutputSchema = z.toJSONSchema(outputSchema);
|
|
430
|
-
} catch (error) {
|
|
431
|
-
throw new TypeError(
|
|
432
|
-
`${helperName}() outputSchema must be representable as JSON Schema.`,
|
|
433
|
-
{ cause: error },
|
|
434
|
-
);
|
|
435
|
-
}
|
|
436
|
-
return {
|
|
437
|
-
...tool,
|
|
438
|
-
approvalMode: tool.approvalMode ?? "auto",
|
|
439
|
-
inputSchema: modelInputSchema,
|
|
440
|
-
outputSchema: modelOutputSchema,
|
|
441
|
-
prepareArguments(args) {
|
|
442
|
-
return parsePluginToolInput(
|
|
443
|
-
inputSchema,
|
|
444
|
-
prepareArguments ? prepareArguments(args) : args,
|
|
445
|
-
);
|
|
446
|
-
},
|
|
447
|
-
...(execute
|
|
448
|
-
? {
|
|
449
|
-
async execute(input, options) {
|
|
450
|
-
const result = await execute(
|
|
451
|
-
input as z.output<TInputSchema>,
|
|
452
|
-
options,
|
|
453
|
-
);
|
|
454
|
-
if (isPluginToolOutputEnvelope(result)) {
|
|
455
|
-
return {
|
|
456
|
-
content: z.array(pluginToolContentSchema).parse(result.content),
|
|
457
|
-
details: outputSchema.parse(result.details),
|
|
458
|
-
};
|
|
459
|
-
}
|
|
460
|
-
return outputSchema.parse(result);
|
|
461
|
-
},
|
|
462
|
-
}
|
|
463
|
-
: undefined),
|
|
464
|
-
} as PluginToolDefinition<
|
|
465
|
-
z.output<TInputSchema>,
|
|
466
|
-
z.output<TOutputSchema>,
|
|
467
|
-
ParsedPluginToolExecuteResult<TOutputSchema, TExecuteResult>
|
|
468
|
-
>;
|
|
469
|
-
}
|
|
470
|
-
|
|
471
|
-
/** Define a plugin tool with Zod input parsing and validated structured results. */
|
|
472
|
-
export function zodTool<
|
|
473
|
-
TInputSchema extends ZodTypeAny,
|
|
474
|
-
TOutputSchema extends ZodTypeAny,
|
|
475
|
-
TExecuteResult extends
|
|
476
|
-
| z.input<TOutputSchema>
|
|
477
|
-
| PluginToolOutputEnvelope<z.input<TOutputSchema>>,
|
|
478
|
-
>(
|
|
479
|
-
definition: ZodPluginToolDefinition<
|
|
480
|
-
TInputSchema,
|
|
481
|
-
TOutputSchema,
|
|
482
|
-
TExecuteResult
|
|
483
|
-
>,
|
|
484
|
-
): PluginToolDefinition<
|
|
485
|
-
z.output<TInputSchema>,
|
|
486
|
-
z.output<TOutputSchema>,
|
|
487
|
-
ParsedPluginToolExecuteResult<TOutputSchema, TExecuteResult>
|
|
488
|
-
> {
|
|
489
|
-
return createZodTool(definition, "zodTool");
|
|
490
|
-
}
|
|
491
|
-
|
|
492
|
-
/** Define a plugin tool with Zod input parsing and the structured result contract. */
|
|
493
|
-
export function definePluginTool<
|
|
494
|
-
TInputSchema extends ZodTypeAny,
|
|
495
|
-
TOutputSchema extends ZodTypeAny,
|
|
496
|
-
TExecuteResult extends
|
|
497
|
-
| z.input<TOutputSchema>
|
|
498
|
-
| PluginToolOutputEnvelope<z.input<TOutputSchema>>,
|
|
499
|
-
>(
|
|
500
|
-
definition: ZodPluginToolDefinition<
|
|
501
|
-
TInputSchema,
|
|
502
|
-
TOutputSchema,
|
|
503
|
-
TExecuteResult
|
|
504
|
-
>,
|
|
505
|
-
): PluginToolDefinition<
|
|
506
|
-
z.output<TInputSchema>,
|
|
507
|
-
z.output<TOutputSchema>,
|
|
508
|
-
ParsedPluginToolExecuteResult<TOutputSchema, TExecuteResult>
|
|
509
|
-
> {
|
|
510
|
-
return createZodTool(definition, "definePluginTool");
|
|
511
|
-
}
|
|
512
|
-
|
|
513
|
-
export interface SlackToolRegistrationHookContext {
|
|
514
|
-
/**
|
|
515
|
-
* What Slack tools can do in the Conversation Location.
|
|
516
|
-
* Computed from Location, not from Source or Destination.
|
|
517
|
-
*/
|
|
518
|
-
channelCapabilities: {
|
|
519
|
-
canAddReactions: boolean;
|
|
520
|
-
canCreateCanvas: boolean;
|
|
521
|
-
canPostToChannel: boolean;
|
|
522
|
-
};
|
|
523
|
-
/** Host-owned link to this conversation, preferring the dashboard when enabled. */
|
|
524
|
-
conversationLink?: SlackConversationLink;
|
|
525
|
-
credentialSubject?: Extract<
|
|
526
|
-
PluginCredentialSubject,
|
|
527
|
-
{ allowedWhen: "private-direct-conversation" }
|
|
528
|
-
>;
|
|
529
|
-
}
|
|
530
|
-
|
|
531
|
-
export interface PluginResourceEventToolContext {
|
|
532
|
-
/** Whether this invocation can create a working resource subscription. */
|
|
533
|
-
canSubscribe: boolean;
|
|
534
|
-
/** Create a temporary resource subscription for the current conversation. */
|
|
535
|
-
subscribe(input: {
|
|
536
|
-
events: string[];
|
|
537
|
-
intent: string;
|
|
538
|
-
resource: SubscribableResource;
|
|
539
|
-
}): Promise<ResourceEventSubscriptionResult>;
|
|
540
|
-
}
|
|
541
|
-
|
|
542
|
-
export interface PluginWorkspaceToolContext {
|
|
543
|
-
/** Find named Workspaces that include one provider repository. */
|
|
544
|
-
findByRepository(input: {
|
|
545
|
-
provider: string;
|
|
546
|
-
repo: string;
|
|
547
|
-
}): Promise<string[]>;
|
|
548
|
-
}
|
|
549
|
-
|
|
550
|
-
interface BaseToolRegistrationHookContext extends PluginContext {
|
|
551
|
-
/**
|
|
552
|
-
* Opaque Junior conversation/session identity for this turn.
|
|
553
|
-
* Interactive Slack turns use `slack:{channelId}:{threadTs}`.
|
|
554
|
-
* Scheduled/web turns use an internal id such as `agent-dispatch:{id}`.
|
|
555
|
-
* Do not parse as Slack unless the value starts with `slack:`.
|
|
556
|
-
*/
|
|
557
|
-
conversationId?: string;
|
|
558
|
-
annotations?: PluginAnnotations;
|
|
559
|
-
embedder: PluginEmbedder;
|
|
560
|
-
egress: PluginEgress;
|
|
561
|
-
mcp?: PluginMcp;
|
|
562
|
-
model: PluginModel;
|
|
563
|
-
resourceEvents: PluginResourceEventToolContext;
|
|
564
|
-
/** Sandbox filesystem and command capability for plugin-owned workspace tools. */
|
|
565
|
-
sandbox: PluginSandbox;
|
|
566
|
-
state: PluginState;
|
|
567
|
-
users: {
|
|
568
|
-
/** Resolve the current actor's stored identity and linked user. */
|
|
569
|
-
resolveActor(): Promise<{ identity: Identity; user?: User } | undefined>;
|
|
570
|
-
};
|
|
571
|
-
userText?: string;
|
|
572
|
-
workspaces: PluginWorkspaceToolContext;
|
|
573
|
-
}
|
|
574
|
-
|
|
575
|
-
export type ToolRegistrationHookContext = BaseToolRegistrationHookContext &
|
|
576
|
-
InvocationContext & {
|
|
577
|
-
/** Slack tool details when the Conversation has a Slack Location. */
|
|
578
|
-
slack?: SlackToolRegistrationHookContext;
|
|
579
|
-
};
|