@sentry/mcp-server 0.26.0 → 0.27.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/parse.cjs +1 -1
- package/dist/cli/parse.d.cts +1 -1
- package/dist/cli/parse.d.cts.map +1 -1
- package/dist/cli/parse.d.ts +1 -1
- package/dist/cli/parse.d.ts.map +1 -1
- package/dist/cli/parse.js +1 -1
- package/dist/cli/resolve.cjs +1 -1
- package/dist/cli/resolve.d.cts +1 -1
- package/dist/cli/resolve.d.ts +1 -1
- package/dist/cli/resolve.js +1 -1
- package/dist/cli/types.d.cts +1 -1
- package/dist/cli/types.d.ts +1 -1
- package/dist/cli/usage.cjs +1 -1
- package/dist/cli/usage.js +1 -1
- package/dist/{config-BoFBjXRq-CGHqlnJ9.cjs → config-CEjP2CYO-CZKUamRu.cjs} +2 -2
- package/dist/{config-BoFBjXRq-CGHqlnJ9.cjs.map → config-CEjP2CYO-CZKUamRu.cjs.map} +1 -1
- package/dist/{config-BoFBjXRq-CMdBQOkQ.js → config-CEjP2CYO-DNCUeo0R.js} +2 -2
- package/dist/{config-BoFBjXRq-CMdBQOkQ.js.map → config-CEjP2CYO-DNCUeo0R.js.map} +1 -1
- package/dist/config-CwE3_vz4.cjs +7 -0
- package/dist/{config-BEgU9ylR.js → config-HqPAzoGg.js} +1 -1
- package/dist/index.cjs +1893 -142
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +1891 -140
- package/dist/index.js.map +1 -1
- package/dist/{parse-46t_fITC.js → parse-B9o4fVyT.js} +12 -1
- package/dist/parse-B9o4fVyT.js.map +1 -0
- package/dist/{parse-BjIH83SX.cjs → parse-c_3eNB2Z.cjs} +12 -1
- package/dist/parse-c_3eNB2Z.cjs.map +1 -0
- package/dist/{resolve-CdTP9riu.cjs → resolve-DFUPLqHE.cjs} +11 -1
- package/dist/resolve-DFUPLqHE.cjs.map +1 -0
- package/dist/{resolve-Cg3SH2zt.js → resolve-DpUhCbfh.js} +11 -1
- package/dist/resolve-DpUhCbfh.js.map +1 -0
- package/dist/{stdio-C47PFfCl.js → stdio-D7VKnapT.js} +3 -3
- package/dist/{stdio-C47PFfCl.js.map → stdio-D7VKnapT.js.map} +1 -1
- package/dist/{stdio-DFfz0_Ua.cjs → stdio-Dv01oTty.cjs} +3 -3
- package/dist/{stdio-DFfz0_Ua.cjs.map → stdio-Dv01oTty.cjs.map} +1 -1
- package/dist/transports/stdio.cjs +1 -1
- package/dist/transports/stdio.js +1 -1
- package/dist/{types-D5f00mg9.d.ts → types--Ysz5ZMd.d.cts} +12 -1
- package/dist/types--Ysz5ZMd.d.cts.map +1 -0
- package/dist/{types-DpmAC3S8.d.cts → types-BlGRNCea.d.ts} +12 -1
- package/dist/types-BlGRNCea.d.ts.map +1 -0
- package/dist/{usage-DD58xBe3.cjs → usage-D9Tpyb5N.cjs} +15 -5
- package/dist/usage-D9Tpyb5N.cjs.map +1 -0
- package/dist/{usage-BzYvqaru.js → usage-DR57Krum.js} +15 -5
- package/dist/usage-DR57Krum.js.map +1 -0
- package/package.json +6 -6
- package/dist/config-rZ982IEm.cjs +0 -7
- package/dist/parse-46t_fITC.js.map +0 -1
- package/dist/parse-BjIH83SX.cjs.map +0 -1
- package/dist/resolve-CdTP9riu.cjs.map +0 -1
- package/dist/resolve-Cg3SH2zt.js.map +0 -1
- package/dist/types-D5f00mg9.d.ts.map +0 -1
- package/dist/types-DpmAC3S8.d.cts.map +0 -1
- package/dist/usage-BzYvqaru.js.map +0 -1
- package/dist/usage-DD58xBe3.cjs.map +0 -1
package/dist/index.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { ALL_SKILLS, SKILLS, finalize, getIssueUrl, getIssuesSearchUrl, getTraceUrl, isEnabledBySkills, isSentryHost } from "./resolve-
|
|
3
|
-
import { LIB_VERSION, USER_AGENT, startStdio } from "./stdio-
|
|
4
|
-
import { RECOMMENDED_FIELDS, systemPrompt } from "./config-
|
|
5
|
-
import { buildUsage } from "./usage-
|
|
6
|
-
import { merge, parseArgv, parseEnv } from "./parse-
|
|
2
|
+
import { ALL_SKILLS, SKILLS, finalize, getIssueUrl, getIssuesSearchUrl, getTraceUrl, isEnabledBySkills, isSentryHost } from "./resolve-DpUhCbfh.js";
|
|
3
|
+
import { LIB_VERSION, USER_AGENT, startStdio } from "./stdio-D7VKnapT.js";
|
|
4
|
+
import { RECOMMENDED_FIELDS, systemPrompt } from "./config-CEjP2CYO-DNCUeo0R.js";
|
|
5
|
+
import { buildUsage } from "./usage-DR57Krum.js";
|
|
6
|
+
import { merge, parseArgv, parseEnv } from "./parse-B9o4fVyT.js";
|
|
7
7
|
import { z } from "zod";
|
|
8
8
|
import util from "node:util";
|
|
9
9
|
import { captureException, captureMessage, getActiveSpan, logger, setTag, setUser, withScope, wrapMcpServerWithSentry } from "@sentry/core";
|
|
@@ -1783,7 +1783,7 @@ function logIssue(error, contextsOrOptions, attachmentsArg) {
|
|
|
1783
1783
|
}
|
|
1784
1784
|
|
|
1785
1785
|
//#endregion
|
|
1786
|
-
//#region ../mcp-core/dist/schema-
|
|
1786
|
+
//#region ../mcp-core/dist/schema-VoUcElu5.js
|
|
1787
1787
|
/**
|
|
1788
1788
|
* Schema for Sentry API error responses.
|
|
1789
1789
|
*
|
|
@@ -2206,6 +2206,31 @@ const EventAttachmentSchema = z.object({
|
|
|
2206
2206
|
});
|
|
2207
2207
|
const EventAttachmentListSchema = z.array(EventAttachmentSchema);
|
|
2208
2208
|
/**
|
|
2209
|
+
* Schema for individual tag values within an issue's tag distribution.
|
|
2210
|
+
*
|
|
2211
|
+
* Represents a single value's occurrence count and percentage within a tag.
|
|
2212
|
+
*/
|
|
2213
|
+
const IssueTagValueSchema = z.object({
|
|
2214
|
+
key: z.string().nullable().optional(),
|
|
2215
|
+
name: z.string().nullable().optional(),
|
|
2216
|
+
value: z.string().nullable(),
|
|
2217
|
+
count: z.number(),
|
|
2218
|
+
lastSeen: z.string().datetime().nullable().optional(),
|
|
2219
|
+
firstSeen: z.string().datetime().nullable().optional()
|
|
2220
|
+
});
|
|
2221
|
+
/**
|
|
2222
|
+
* Schema for Sentry issue tag values response.
|
|
2223
|
+
*
|
|
2224
|
+
* Contains aggregate counts of unique tag values for an issue,
|
|
2225
|
+
* useful for understanding the distribution of tags like URL, browser, etc.
|
|
2226
|
+
*/
|
|
2227
|
+
const IssueTagValuesSchema = z.object({
|
|
2228
|
+
key: z.string(),
|
|
2229
|
+
name: z.string(),
|
|
2230
|
+
totalValues: z.number(),
|
|
2231
|
+
topValues: z.array(IssueTagValueSchema)
|
|
2232
|
+
});
|
|
2233
|
+
/**
|
|
2209
2234
|
* Schema for Sentry trace metadata response.
|
|
2210
2235
|
*
|
|
2211
2236
|
* Contains high-level statistics about a trace including span counts,
|
|
@@ -2495,7 +2520,7 @@ function createApiError(message, status, detail, responseBody) {
|
|
|
2495
2520
|
}
|
|
2496
2521
|
|
|
2497
2522
|
//#endregion
|
|
2498
|
-
//#region ../mcp-core/dist/client-
|
|
2523
|
+
//#region ../mcp-core/dist/client-DXmt8umX.js
|
|
2499
2524
|
/**
|
|
2500
2525
|
* Mapping of common network error codes to user-friendly messages.
|
|
2501
2526
|
* These help users understand and resolve connection issues.
|
|
@@ -2593,6 +2618,27 @@ var SentryApiService = class {
|
|
|
2593
2618
|
return isSentryHost(this.host);
|
|
2594
2619
|
}
|
|
2595
2620
|
/**
|
|
2621
|
+
* Validates and applies time parameters to a URLSearchParams object.
|
|
2622
|
+
*
|
|
2623
|
+
* Enforces mutual exclusivity between relative (statsPeriod) and
|
|
2624
|
+
* absolute (start/end) time ranges, and ensures start/end are paired.
|
|
2625
|
+
*
|
|
2626
|
+
* @param queryParams The URLSearchParams to modify
|
|
2627
|
+
* @param statsPeriod Relative time period (e.g., "24h", "7d")
|
|
2628
|
+
* @param start Absolute start time (ISO 8601)
|
|
2629
|
+
* @param end Absolute end time (ISO 8601)
|
|
2630
|
+
* @throws {ApiValidationError} If time parameters are invalid
|
|
2631
|
+
*/
|
|
2632
|
+
applyTimeParams(queryParams, statsPeriod, start, end) {
|
|
2633
|
+
if (statsPeriod && (start || end)) throw new ApiValidationError("Cannot use both statsPeriod and start/end parameters. Use either statsPeriod for relative time or start/end for absolute time.");
|
|
2634
|
+
if (start && !end || !start && end) throw new ApiValidationError("Both start and end parameters must be provided together for absolute time ranges.");
|
|
2635
|
+
if (statsPeriod) queryParams.set("statsPeriod", statsPeriod);
|
|
2636
|
+
else if (start && end) {
|
|
2637
|
+
queryParams.set("start", start);
|
|
2638
|
+
queryParams.set("end", end);
|
|
2639
|
+
}
|
|
2640
|
+
}
|
|
2641
|
+
/**
|
|
2596
2642
|
* Internal method for making authenticated requests to Sentry API.
|
|
2597
2643
|
*
|
|
2598
2644
|
* Handles:
|
|
@@ -3187,13 +3233,7 @@ var SentryApiService = class {
|
|
|
3187
3233
|
const searchQuery = new URLSearchParams();
|
|
3188
3234
|
if (dataset) searchQuery.set("dataset", dataset);
|
|
3189
3235
|
if (project) searchQuery.set("project", project);
|
|
3190
|
-
|
|
3191
|
-
if (start && !end || !start && end) throw new ApiValidationError("Both start and end parameters must be provided together for absolute time ranges.");
|
|
3192
|
-
if (statsPeriod) searchQuery.set("statsPeriod", statsPeriod);
|
|
3193
|
-
else if (start && end) {
|
|
3194
|
-
searchQuery.set("start", start);
|
|
3195
|
-
searchQuery.set("end", end);
|
|
3196
|
-
}
|
|
3236
|
+
this.applyTimeParams(searchQuery, statsPeriod, start, end);
|
|
3197
3237
|
if (useCache !== void 0) searchQuery.set("useCache", useCache ? "1" : "0");
|
|
3198
3238
|
if (useFlagsBackend !== void 0) searchQuery.set("useFlagsBackend", useFlagsBackend ? "1" : "0");
|
|
3199
3239
|
const body = await this.requestJSON(searchQuery.toString() ? `/organizations/${organizationSlug}/tags/?${searchQuery.toString()}` : `/organizations/${organizationSlug}/tags/`, void 0, opts);
|
|
@@ -3233,13 +3273,7 @@ var SentryApiService = class {
|
|
|
3233
3273
|
queryParams.set("itemType", itemType);
|
|
3234
3274
|
queryParams.set("attributeType", attributeType);
|
|
3235
3275
|
if (project) queryParams.set("project", project);
|
|
3236
|
-
|
|
3237
|
-
if (start && !end || !start && end) throw new ApiValidationError("Both start and end parameters must be provided together for absolute time ranges.");
|
|
3238
|
-
if (statsPeriod) queryParams.set("statsPeriod", statsPeriod);
|
|
3239
|
-
else if (start && end) {
|
|
3240
|
-
queryParams.set("start", start);
|
|
3241
|
-
queryParams.set("end", end);
|
|
3242
|
-
}
|
|
3276
|
+
this.applyTimeParams(queryParams, statsPeriod, start, end);
|
|
3243
3277
|
const url = `/organizations/${organizationSlug}/trace-items/attributes/?${queryParams.toString()}`;
|
|
3244
3278
|
const body = await this.requestJSON(url, void 0, opts);
|
|
3245
3279
|
return Array.isArray(body) ? body : [];
|
|
@@ -3293,6 +3327,35 @@ var SentryApiService = class {
|
|
|
3293
3327
|
const body = await this.requestJSON(`/organizations/${organizationSlug}/issues/${issueId}/`, void 0, opts);
|
|
3294
3328
|
return IssueSchema.parse(body);
|
|
3295
3329
|
}
|
|
3330
|
+
/**
|
|
3331
|
+
* Retrieves tag value distribution for a specific issue.
|
|
3332
|
+
*
|
|
3333
|
+
* Returns aggregate counts of unique tag values, useful for understanding
|
|
3334
|
+
* how an issue is distributed across different tag values (e.g., URLs,
|
|
3335
|
+
* browsers, environments).
|
|
3336
|
+
*
|
|
3337
|
+
* @param params Query parameters
|
|
3338
|
+
* @param params.organizationSlug Organization identifier
|
|
3339
|
+
* @param params.issueId Issue identifier (short ID or numeric ID)
|
|
3340
|
+
* @param params.tagKey Tag key to get values for (e.g., "url", "browser", "environment")
|
|
3341
|
+
* @param opts Request options
|
|
3342
|
+
* @returns Tag value distribution with counts and percentages
|
|
3343
|
+
*
|
|
3344
|
+
* @example
|
|
3345
|
+
* ```typescript
|
|
3346
|
+
* const tagValues = await apiService.getIssueTagValues({
|
|
3347
|
+
* organizationSlug: "my-org",
|
|
3348
|
+
* issueId: "PROJECT-123",
|
|
3349
|
+
* tagKey: "url"
|
|
3350
|
+
* });
|
|
3351
|
+
* console.log(`Total unique values: ${tagValues.totalValues}`);
|
|
3352
|
+
* tagValues.topValues.forEach(v => console.log(`${v.value}: ${v.count}`));
|
|
3353
|
+
* ```
|
|
3354
|
+
*/
|
|
3355
|
+
async getIssueTagValues({ organizationSlug, issueId, tagKey }, opts) {
|
|
3356
|
+
const body = await this.requestJSON(`/organizations/${organizationSlug}/issues/${issueId}/tags/${tagKey}/`, void 0, opts);
|
|
3357
|
+
return IssueTagValuesSchema.parse(body);
|
|
3358
|
+
}
|
|
3296
3359
|
async getEventForIssue({ organizationSlug, issueId, eventId }, opts) {
|
|
3297
3360
|
const body = await this.requestJSON(`/organizations/${organizationSlug}/issues/${issueId}/events/${eventId}/`, void 0, opts);
|
|
3298
3361
|
const parseResult = EventSchema.safeParse(body);
|
|
@@ -3433,13 +3496,7 @@ var SentryApiService = class {
|
|
|
3433
3496
|
queryParams.set("per_page", params.limit.toString());
|
|
3434
3497
|
queryParams.set("query", params.query);
|
|
3435
3498
|
queryParams.set("dataset", "errors");
|
|
3436
|
-
|
|
3437
|
-
if (params.start && !params.end || !params.start && params.end) throw new ApiValidationError("Both start and end parameters must be provided together for absolute time ranges.");
|
|
3438
|
-
if (params.statsPeriod) queryParams.set("statsPeriod", params.statsPeriod);
|
|
3439
|
-
else if (params.start && params.end) {
|
|
3440
|
-
queryParams.set("start", params.start);
|
|
3441
|
-
queryParams.set("end", params.end);
|
|
3442
|
-
}
|
|
3499
|
+
this.applyTimeParams(queryParams, params.statsPeriod, params.start, params.end);
|
|
3443
3500
|
if (params.projectId) queryParams.set("project", params.projectId);
|
|
3444
3501
|
let apiSort = params.sort;
|
|
3445
3502
|
if (params.sort?.includes("(") && !params.sort?.includes("equation|")) {
|
|
@@ -3467,13 +3524,7 @@ var SentryApiService = class {
|
|
|
3467
3524
|
queryParams.set("per_page", params.limit.toString());
|
|
3468
3525
|
queryParams.set("query", params.query);
|
|
3469
3526
|
queryParams.set("dataset", params.dataset);
|
|
3470
|
-
|
|
3471
|
-
if (params.start && !params.end || !params.start && params.end) throw new ApiValidationError("Both start and end parameters must be provided together for absolute time ranges.");
|
|
3472
|
-
if (params.statsPeriod) queryParams.set("statsPeriod", params.statsPeriod);
|
|
3473
|
-
else if (params.start && params.end) {
|
|
3474
|
-
queryParams.set("start", params.start);
|
|
3475
|
-
queryParams.set("end", params.end);
|
|
3476
|
-
}
|
|
3527
|
+
this.applyTimeParams(queryParams, params.statsPeriod, params.start, params.end);
|
|
3477
3528
|
if (params.projectId) queryParams.set("project", params.projectId);
|
|
3478
3529
|
if (params.dataset === "spans") queryParams.set("sampling", "NORMAL");
|
|
3479
3530
|
let apiSort = params.sort;
|
|
@@ -3636,7 +3687,7 @@ function validateRegionUrl(regionUrl, baseHost) {
|
|
|
3636
3687
|
}
|
|
3637
3688
|
|
|
3638
3689
|
//#endregion
|
|
3639
|
-
//#region ../mcp-core/dist/api-
|
|
3690
|
+
//#region ../mcp-core/dist/api-DgBjJzAN.js
|
|
3640
3691
|
/**
|
|
3641
3692
|
* Create a Sentry API service from server context with optional region override
|
|
3642
3693
|
* @param context - Server context containing host and access token
|
|
@@ -3657,7 +3708,7 @@ function apiServiceFromContext(context$1, opts = {}) {
|
|
|
3657
3708
|
}
|
|
3658
3709
|
|
|
3659
3710
|
//#endregion
|
|
3660
|
-
//#region ../mcp-core/dist/whoami-
|
|
3711
|
+
//#region ../mcp-core/dist/whoami-B_pOoN0T.js
|
|
3661
3712
|
var whoami_default = defineTool({
|
|
3662
3713
|
name: "whoami",
|
|
3663
3714
|
description: [
|
|
@@ -3690,7 +3741,7 @@ var whoami_default = defineTool({
|
|
|
3690
3741
|
});
|
|
3691
3742
|
|
|
3692
3743
|
//#endregion
|
|
3693
|
-
//#region ../mcp-core/dist/find-organizations-
|
|
3744
|
+
//#region ../mcp-core/dist/find-organizations-DudCkGim.js
|
|
3694
3745
|
const RESULT_LIMIT$2 = 25;
|
|
3695
3746
|
var find_organizations_default = defineTool({
|
|
3696
3747
|
name: "find_organizations",
|
|
@@ -3742,7 +3793,7 @@ var find_organizations_default = defineTool({
|
|
|
3742
3793
|
});
|
|
3743
3794
|
|
|
3744
3795
|
//#endregion
|
|
3745
|
-
//#region ../mcp-core/dist/find-teams-
|
|
3796
|
+
//#region ../mcp-core/dist/find-teams-BP0pLsvf.js
|
|
3746
3797
|
const RESULT_LIMIT$1 = 25;
|
|
3747
3798
|
var find_teams_default = defineTool({
|
|
3748
3799
|
name: "find_teams",
|
|
@@ -3790,7 +3841,7 @@ var find_teams_default = defineTool({
|
|
|
3790
3841
|
});
|
|
3791
3842
|
|
|
3792
3843
|
//#endregion
|
|
3793
|
-
//#region ../mcp-core/dist/find-projects-
|
|
3844
|
+
//#region ../mcp-core/dist/find-projects-YtaNsBaH.js
|
|
3794
3845
|
const RESULT_LIMIT = 25;
|
|
3795
3846
|
var find_projects_default = defineTool({
|
|
3796
3847
|
name: "find_projects",
|
|
@@ -3834,7 +3885,7 @@ var find_projects_default = defineTool({
|
|
|
3834
3885
|
});
|
|
3835
3886
|
|
|
3836
3887
|
//#endregion
|
|
3837
|
-
//#region ../mcp-core/dist/find-releases-
|
|
3888
|
+
//#region ../mcp-core/dist/find-releases-BVBIICgY.js
|
|
3838
3889
|
var find_releases_default = defineTool({
|
|
3839
3890
|
name: "find_releases",
|
|
3840
3891
|
skills: ["inspect"],
|
|
@@ -5079,7 +5130,7 @@ function enhanceNotFoundError(error, params) {
|
|
|
5079
5130
|
}
|
|
5080
5131
|
|
|
5081
5132
|
//#endregion
|
|
5082
|
-
//#region ../mcp-core/dist/get-issue-details-
|
|
5133
|
+
//#region ../mcp-core/dist/get-issue-details-U818j2tY.js
|
|
5083
5134
|
var get_issue_details_default = defineTool({
|
|
5084
5135
|
name: "get_issue_details",
|
|
5085
5136
|
skills: [
|
|
@@ -5260,7 +5311,122 @@ function shouldFetchTraceForEvent(event) {
|
|
|
5260
5311
|
}
|
|
5261
5312
|
|
|
5262
5313
|
//#endregion
|
|
5263
|
-
//#region ../mcp-core/dist/get-
|
|
5314
|
+
//#region ../mcp-core/dist/get-issue-tag-values-tupBr2Mu.js
|
|
5315
|
+
var get_issue_tag_values_default = defineTool({
|
|
5316
|
+
name: "get_issue_tag_values",
|
|
5317
|
+
skills: ["inspect"],
|
|
5318
|
+
requiredScopes: ["event:read"],
|
|
5319
|
+
description: [
|
|
5320
|
+
"Get tag value distribution for a specific Sentry issue.",
|
|
5321
|
+
"",
|
|
5322
|
+
"Use this tool when you need to:",
|
|
5323
|
+
"- Understand how an issue is distributed across different tag values",
|
|
5324
|
+
"- Get aggregate counts of unique tag values (e.g., 'how many unique URLs are affected')",
|
|
5325
|
+
"- Analyze which browsers, environments, or URLs are most impacted by an issue",
|
|
5326
|
+
"- View the tag distributions page data programmatically",
|
|
5327
|
+
"",
|
|
5328
|
+
"Common tag keys:",
|
|
5329
|
+
"- `url`: Request URLs affected by the issue",
|
|
5330
|
+
"- `browser`: Browser types and versions",
|
|
5331
|
+
"- `browser.name`: Browser names only",
|
|
5332
|
+
"- `os`: Operating systems",
|
|
5333
|
+
"- `environment`: Deployment environments (production, staging, etc.)",
|
|
5334
|
+
"- `release`: Software releases",
|
|
5335
|
+
"- `device`: Device types",
|
|
5336
|
+
"- `user`: Affected users",
|
|
5337
|
+
"",
|
|
5338
|
+
"<examples>",
|
|
5339
|
+
"### Get URL distribution for an issue",
|
|
5340
|
+
"```",
|
|
5341
|
+
"get_issue_tag_values(organizationSlug='my-organization', issueId='PROJECT-123', tagKey='url')",
|
|
5342
|
+
"```",
|
|
5343
|
+
"",
|
|
5344
|
+
"### Get browser distribution using issue URL",
|
|
5345
|
+
"```",
|
|
5346
|
+
"get_issue_tag_values(issueUrl='https://sentry.io/issues/PROJECT-123/', tagKey='browser')",
|
|
5347
|
+
"```",
|
|
5348
|
+
"",
|
|
5349
|
+
"### Get environment distribution",
|
|
5350
|
+
"```",
|
|
5351
|
+
"get_issue_tag_values(organizationSlug='my-organization', issueId='PROJECT-123', tagKey='environment')",
|
|
5352
|
+
"```",
|
|
5353
|
+
"</examples>",
|
|
5354
|
+
"",
|
|
5355
|
+
"<hints>",
|
|
5356
|
+
"- If user provides a Sentry URL, pass the ENTIRE URL to issueUrl parameter unchanged",
|
|
5357
|
+
"- Common tag keys: url, browser, browser.name, os, environment, release, device, user",
|
|
5358
|
+
"- Tag keys are case-sensitive",
|
|
5359
|
+
"</hints>"
|
|
5360
|
+
].join("\n"),
|
|
5361
|
+
inputSchema: {
|
|
5362
|
+
organizationSlug: ParamOrganizationSlug.optional(),
|
|
5363
|
+
regionUrl: ParamRegionUrl.nullable().default(null),
|
|
5364
|
+
issueId: ParamIssueShortId.optional(),
|
|
5365
|
+
issueUrl: ParamIssueUrl.optional(),
|
|
5366
|
+
tagKey: z.string().trim().regex(/^[a-zA-Z0-9][a-zA-Z0-9._-]*$/, "Tag key must contain only alphanumeric characters, dots, hyphens, and underscores, and must start with an alphanumeric character").describe("The tag key to get values for (e.g., 'url', 'browser', 'environment', 'release').")
|
|
5367
|
+
},
|
|
5368
|
+
annotations: {
|
|
5369
|
+
readOnlyHint: true,
|
|
5370
|
+
openWorldHint: true
|
|
5371
|
+
},
|
|
5372
|
+
async handler(params, context$1) {
|
|
5373
|
+
const apiService = apiServiceFromContext(context$1, { regionUrl: params.regionUrl ?? void 0 });
|
|
5374
|
+
if (!params.issueUrl && !params.issueId) throw new UserInputError("Either `issueId` or `issueUrl` must be provided");
|
|
5375
|
+
if (!params.issueUrl && !params.organizationSlug) throw new UserInputError("`organizationSlug` is required when providing `issueId`");
|
|
5376
|
+
if (!params.tagKey) throw new UserInputError("`tagKey` is required. Common values: url, browser, environment, release, os, device, user");
|
|
5377
|
+
const { organizationSlug: orgSlug, issueId: parsedIssueId } = parseIssueParams$1({
|
|
5378
|
+
organizationSlug: params.organizationSlug,
|
|
5379
|
+
issueId: params.issueId,
|
|
5380
|
+
issueUrl: params.issueUrl
|
|
5381
|
+
});
|
|
5382
|
+
setTag("organization.slug", orgSlug);
|
|
5383
|
+
let tagValues;
|
|
5384
|
+
try {
|
|
5385
|
+
tagValues = await apiService.getIssueTagValues({
|
|
5386
|
+
organizationSlug: orgSlug,
|
|
5387
|
+
issueId: parsedIssueId,
|
|
5388
|
+
tagKey: params.tagKey
|
|
5389
|
+
});
|
|
5390
|
+
} catch (error) {
|
|
5391
|
+
if (error instanceof ApiNotFoundError) throw enhanceNotFoundError(error, {
|
|
5392
|
+
organizationSlug: orgSlug,
|
|
5393
|
+
issueId: parsedIssueId,
|
|
5394
|
+
tagKey: params.tagKey
|
|
5395
|
+
});
|
|
5396
|
+
throw error;
|
|
5397
|
+
}
|
|
5398
|
+
let output = `# Tag Distribution: ${tagValues.name}\n\n`;
|
|
5399
|
+
output += `**Issue**: ${parsedIssueId}\n`;
|
|
5400
|
+
output += `**Tag Key**: \`${tagValues.key}\`\n`;
|
|
5401
|
+
output += `**Total Unique Values**: ${tagValues.totalValues}\n\n`;
|
|
5402
|
+
if (tagValues.topValues.length === 0) {
|
|
5403
|
+
output += "No values found for this tag.\n";
|
|
5404
|
+
return output;
|
|
5405
|
+
}
|
|
5406
|
+
output += "## Top Values\n\n";
|
|
5407
|
+
output += "| Value | Count | First Seen | Last Seen |\n";
|
|
5408
|
+
output += "|-------|-------|------------|----------|\n";
|
|
5409
|
+
for (const value of tagValues.topValues) {
|
|
5410
|
+
const firstSeen = value.firstSeen ? new Date(value.firstSeen).toISOString().split("T")[0] : "-";
|
|
5411
|
+
const lastSeen = value.lastSeen ? new Date(value.lastSeen).toISOString().split("T")[0] : "-";
|
|
5412
|
+
const rawValue = value.value ?? "(null)";
|
|
5413
|
+
let displayValue = rawValue.length > 60 ? `${rawValue.substring(0, 57)}...` : rawValue;
|
|
5414
|
+
displayValue = displayValue.replace(/\\/g, "\\\\").replace(/\|/g, "\\|").replace(/`/g, "\\`").replace(/\n/g, " ");
|
|
5415
|
+
output += `| \`${displayValue}\` | ${value.count} | ${firstSeen} | ${lastSeen} |\n`;
|
|
5416
|
+
}
|
|
5417
|
+
if (tagValues.topValues.length > 0 && tagValues.totalValues > 0) {
|
|
5418
|
+
const shownCount = tagValues.topValues.length;
|
|
5419
|
+
output += `\n*Showing top ${shownCount} of ${tagValues.totalValues} unique values*\n`;
|
|
5420
|
+
}
|
|
5421
|
+
output += "\n## Using this information\n\n";
|
|
5422
|
+
output += `- Use \`get_issue_details(organizationSlug='${orgSlug}', issueId='${parsedIssueId}')\` to see the full issue details\n`;
|
|
5423
|
+
output += `- Try other tag keys like: url, browser, environment, release, os, device, user\n`;
|
|
5424
|
+
return output;
|
|
5425
|
+
}
|
|
5426
|
+
});
|
|
5427
|
+
|
|
5428
|
+
//#endregion
|
|
5429
|
+
//#region ../mcp-core/dist/get-trace-details-DDDetJqp.js
|
|
5264
5430
|
const MAX_DEPTH = 2;
|
|
5265
5431
|
const MINIMUM_DURATION_THRESHOLD_MS = 10;
|
|
5266
5432
|
const MIN_MEANINGFUL_CHILD_DURATION = 5;
|
|
@@ -5559,7 +5725,7 @@ function formatTraceOutput({ organizationSlug, traceId, traceMeta, trace: trace$
|
|
|
5559
5725
|
}
|
|
5560
5726
|
|
|
5561
5727
|
//#endregion
|
|
5562
|
-
//#region ../mcp-core/dist/get-event-attachment-
|
|
5728
|
+
//#region ../mcp-core/dist/get-event-attachment-itWm1HrK.js
|
|
5563
5729
|
var get_event_attachment_default = defineTool({
|
|
5564
5730
|
name: "get_event_attachment",
|
|
5565
5731
|
skills: ["inspect"],
|
|
@@ -5695,7 +5861,7 @@ var get_event_attachment_default = defineTool({
|
|
|
5695
5861
|
});
|
|
5696
5862
|
|
|
5697
5863
|
//#endregion
|
|
5698
|
-
//#region ../mcp-core/dist/formatting-
|
|
5864
|
+
//#region ../mcp-core/dist/formatting-CIwRyNGU.js
|
|
5699
5865
|
/**
|
|
5700
5866
|
* Helper function to format assignedTo field for display
|
|
5701
5867
|
*/
|
|
@@ -5707,7 +5873,7 @@ function formatAssignedTo(assignedTo) {
|
|
|
5707
5873
|
}
|
|
5708
5874
|
|
|
5709
5875
|
//#endregion
|
|
5710
|
-
//#region ../mcp-core/dist/update-issue-
|
|
5876
|
+
//#region ../mcp-core/dist/update-issue-DA_N-toV.js
|
|
5711
5877
|
var update_issue_default = defineTool({
|
|
5712
5878
|
name: "update_issue",
|
|
5713
5879
|
skills: ["triage"],
|
|
@@ -6004,6 +6170,20 @@ var name10$1 = "AI_NoSuchModelError";
|
|
|
6004
6170
|
var marker11$1 = `vercel.ai.error.${name10$1}`;
|
|
6005
6171
|
var symbol11$1 = Symbol.for(marker11$1);
|
|
6006
6172
|
var _a11$1;
|
|
6173
|
+
var NoSuchModelError = class extends AISDKError {
|
|
6174
|
+
constructor({ errorName = name10$1, modelId, modelType, message = `No such ${modelType}: ${modelId}` }) {
|
|
6175
|
+
super({
|
|
6176
|
+
name: errorName,
|
|
6177
|
+
message
|
|
6178
|
+
});
|
|
6179
|
+
this[_a11$1] = true;
|
|
6180
|
+
this.modelId = modelId;
|
|
6181
|
+
this.modelType = modelType;
|
|
6182
|
+
}
|
|
6183
|
+
static isInstance(error) {
|
|
6184
|
+
return AISDKError.hasMarker(error, marker11$1);
|
|
6185
|
+
}
|
|
6186
|
+
};
|
|
6007
6187
|
_a11$1 = symbol11$1;
|
|
6008
6188
|
var name11$1 = "AI_TooManyEmbeddingValuesForCallError";
|
|
6009
6189
|
var marker12$1 = `vercel.ai.error.${name11$1}`;
|
|
@@ -6539,6 +6719,10 @@ var postToApi = async ({ url, headers = {}, body, successfulResponseHandler, fai
|
|
|
6539
6719
|
throw error;
|
|
6540
6720
|
}
|
|
6541
6721
|
};
|
|
6722
|
+
async function resolve(value) {
|
|
6723
|
+
if (typeof value === "function") value = value();
|
|
6724
|
+
return Promise.resolve(value);
|
|
6725
|
+
}
|
|
6542
6726
|
var createJsonErrorResponseHandler = ({ errorSchema, errorToMessage, isRetryable }) => async ({ response, url, requestBodyValues }) => {
|
|
6543
6727
|
const responseBody = await response.text();
|
|
6544
6728
|
const responseHeaders = extractResponseHeaders(response);
|
|
@@ -6854,7 +7038,7 @@ function getResponseMetadata({ id, model, created }) {
|
|
|
6854
7038
|
timestamp: created != null ? /* @__PURE__ */ new Date(created * 1e3) : void 0
|
|
6855
7039
|
};
|
|
6856
7040
|
}
|
|
6857
|
-
function prepareTools({ mode, useLegacyFunctionCalling = false, structuredOutputs }) {
|
|
7041
|
+
function prepareTools$1({ mode, useLegacyFunctionCalling = false, structuredOutputs }) {
|
|
6858
7042
|
var _a$2;
|
|
6859
7043
|
const tools = ((_a$2 = mode.tools) == null ? void 0 : _a$2.length) ? mode.tools : void 0;
|
|
6860
7044
|
const toolWarnings = [];
|
|
@@ -7082,7 +7266,7 @@ var OpenAIChatLanguageModel = class {
|
|
|
7082
7266
|
}
|
|
7083
7267
|
switch (type) {
|
|
7084
7268
|
case "regular": {
|
|
7085
|
-
const { tools, tool_choice, functions, function_call, toolWarnings } = prepareTools({
|
|
7269
|
+
const { tools, tool_choice, functions, function_call, toolWarnings } = prepareTools$1({
|
|
7086
7270
|
mode,
|
|
7087
7271
|
useLegacyFunctionCalling,
|
|
7088
7272
|
structuredOutputs: this.supportsStructuredOutputs
|
|
@@ -8977,49 +9161,1283 @@ function createOpenAI(options = {}) {
|
|
|
8977
9161
|
provider.tools = openaiTools;
|
|
8978
9162
|
return provider;
|
|
8979
9163
|
}
|
|
8980
|
-
var openai = createOpenAI({ compatibility: "strict" });
|
|
9164
|
+
var openai = createOpenAI({ compatibility: "strict" });
|
|
9165
|
+
|
|
9166
|
+
//#endregion
|
|
9167
|
+
//#region ../mcp-core/dist/openai-provider-BhiGfaFk.js
|
|
9168
|
+
const DEFAULT_OPENAI_MODEL = "gpt-5";
|
|
9169
|
+
const VALID_REASONING_EFFORTS = [
|
|
9170
|
+
"low",
|
|
9171
|
+
"medium",
|
|
9172
|
+
"high"
|
|
9173
|
+
];
|
|
9174
|
+
const DEFAULT_REASONING_EFFORT = "low";
|
|
9175
|
+
let configuredBaseUrl$1;
|
|
9176
|
+
/**
|
|
9177
|
+
* Configure the OpenAI base URL (CLI flag only, not environment variable).
|
|
9178
|
+
* This must be called explicitly - it cannot be set via environment variables for security.
|
|
9179
|
+
*/
|
|
9180
|
+
function setOpenAIBaseUrl(baseUrl) {
|
|
9181
|
+
configuredBaseUrl$1 = baseUrl;
|
|
9182
|
+
}
|
|
9183
|
+
/**
|
|
9184
|
+
* Retrieve an OpenAI language model configured from environment variables and explicit config.
|
|
9185
|
+
*
|
|
9186
|
+
* Configuration:
|
|
9187
|
+
* - OPENAI_MODEL: Model to use (default: "gpt-5") - env var OK
|
|
9188
|
+
* - OPENAI_REASONING_EFFORT: Reasoning effort for o1 models: "low", "medium", "high", or "" to disable (default: "low") - env var OK
|
|
9189
|
+
* - Base URL: Must be set via setOpenAIBaseUrl() - NOT from env vars (security risk)
|
|
9190
|
+
*/
|
|
9191
|
+
function getOpenAIModel(model) {
|
|
9192
|
+
const defaultModel = process.env.OPENAI_MODEL || DEFAULT_OPENAI_MODEL;
|
|
9193
|
+
const envReasoningEffort = process.env.OPENAI_REASONING_EFFORT;
|
|
9194
|
+
let reasoningEffort;
|
|
9195
|
+
if (envReasoningEffort === "") reasoningEffort = void 0;
|
|
9196
|
+
else if (envReasoningEffort === void 0) reasoningEffort = DEFAULT_REASONING_EFFORT;
|
|
9197
|
+
else if (VALID_REASONING_EFFORTS.includes(envReasoningEffort)) reasoningEffort = envReasoningEffort;
|
|
9198
|
+
else {
|
|
9199
|
+
const validValues = VALID_REASONING_EFFORTS.map((v) => `"${v}"`).join(", ");
|
|
9200
|
+
throw new Error(`Invalid OPENAI_REASONING_EFFORT value: "${envReasoningEffort}". Must be one of: ${validValues}, or "" (empty string to disable). Default is "${DEFAULT_REASONING_EFFORT}".`);
|
|
9201
|
+
}
|
|
9202
|
+
const factory = createOpenAI({
|
|
9203
|
+
...configuredBaseUrl$1 && { baseURL: configuredBaseUrl$1 },
|
|
9204
|
+
headers: { "User-Agent": USER_AGENT }
|
|
9205
|
+
});
|
|
9206
|
+
return factory(model ?? defaultModel, { ...reasoningEffort && { reasoningEffort } });
|
|
9207
|
+
}
|
|
9208
|
+
|
|
9209
|
+
//#endregion
|
|
9210
|
+
//#region ../../node_modules/.pnpm/@ai-sdk+anthropic@1.2.12_zod@3.25.76/node_modules/@ai-sdk/anthropic/dist/index.mjs
|
|
9211
|
+
var anthropicErrorDataSchema = z.object({
|
|
9212
|
+
type: z.literal("error"),
|
|
9213
|
+
error: z.object({
|
|
9214
|
+
type: z.string(),
|
|
9215
|
+
message: z.string()
|
|
9216
|
+
})
|
|
9217
|
+
});
|
|
9218
|
+
var anthropicFailedResponseHandler = createJsonErrorResponseHandler({
|
|
9219
|
+
errorSchema: anthropicErrorDataSchema,
|
|
9220
|
+
errorToMessage: (data) => data.error.message
|
|
9221
|
+
});
|
|
9222
|
+
function prepareTools(mode) {
|
|
9223
|
+
var _a$2;
|
|
9224
|
+
const tools = ((_a$2 = mode.tools) == null ? void 0 : _a$2.length) ? mode.tools : void 0;
|
|
9225
|
+
const toolWarnings = [];
|
|
9226
|
+
const betas = /* @__PURE__ */ new Set();
|
|
9227
|
+
if (tools == null) return {
|
|
9228
|
+
tools: void 0,
|
|
9229
|
+
tool_choice: void 0,
|
|
9230
|
+
toolWarnings,
|
|
9231
|
+
betas
|
|
9232
|
+
};
|
|
9233
|
+
const anthropicTools2 = [];
|
|
9234
|
+
for (const tool$1 of tools) switch (tool$1.type) {
|
|
9235
|
+
case "function":
|
|
9236
|
+
anthropicTools2.push({
|
|
9237
|
+
name: tool$1.name,
|
|
9238
|
+
description: tool$1.description,
|
|
9239
|
+
input_schema: tool$1.parameters
|
|
9240
|
+
});
|
|
9241
|
+
break;
|
|
9242
|
+
case "provider-defined":
|
|
9243
|
+
switch (tool$1.id) {
|
|
9244
|
+
case "anthropic.computer_20250124":
|
|
9245
|
+
betas.add("computer-use-2025-01-24");
|
|
9246
|
+
anthropicTools2.push({
|
|
9247
|
+
name: tool$1.name,
|
|
9248
|
+
type: "computer_20250124",
|
|
9249
|
+
display_width_px: tool$1.args.displayWidthPx,
|
|
9250
|
+
display_height_px: tool$1.args.displayHeightPx,
|
|
9251
|
+
display_number: tool$1.args.displayNumber
|
|
9252
|
+
});
|
|
9253
|
+
break;
|
|
9254
|
+
case "anthropic.computer_20241022":
|
|
9255
|
+
betas.add("computer-use-2024-10-22");
|
|
9256
|
+
anthropicTools2.push({
|
|
9257
|
+
name: tool$1.name,
|
|
9258
|
+
type: "computer_20241022",
|
|
9259
|
+
display_width_px: tool$1.args.displayWidthPx,
|
|
9260
|
+
display_height_px: tool$1.args.displayHeightPx,
|
|
9261
|
+
display_number: tool$1.args.displayNumber
|
|
9262
|
+
});
|
|
9263
|
+
break;
|
|
9264
|
+
case "anthropic.text_editor_20250124":
|
|
9265
|
+
betas.add("computer-use-2025-01-24");
|
|
9266
|
+
anthropicTools2.push({
|
|
9267
|
+
name: tool$1.name,
|
|
9268
|
+
type: "text_editor_20250124"
|
|
9269
|
+
});
|
|
9270
|
+
break;
|
|
9271
|
+
case "anthropic.text_editor_20241022":
|
|
9272
|
+
betas.add("computer-use-2024-10-22");
|
|
9273
|
+
anthropicTools2.push({
|
|
9274
|
+
name: tool$1.name,
|
|
9275
|
+
type: "text_editor_20241022"
|
|
9276
|
+
});
|
|
9277
|
+
break;
|
|
9278
|
+
case "anthropic.bash_20250124":
|
|
9279
|
+
betas.add("computer-use-2025-01-24");
|
|
9280
|
+
anthropicTools2.push({
|
|
9281
|
+
name: tool$1.name,
|
|
9282
|
+
type: "bash_20250124"
|
|
9283
|
+
});
|
|
9284
|
+
break;
|
|
9285
|
+
case "anthropic.bash_20241022":
|
|
9286
|
+
betas.add("computer-use-2024-10-22");
|
|
9287
|
+
anthropicTools2.push({
|
|
9288
|
+
name: tool$1.name,
|
|
9289
|
+
type: "bash_20241022"
|
|
9290
|
+
});
|
|
9291
|
+
break;
|
|
9292
|
+
default:
|
|
9293
|
+
toolWarnings.push({
|
|
9294
|
+
type: "unsupported-tool",
|
|
9295
|
+
tool: tool$1
|
|
9296
|
+
});
|
|
9297
|
+
break;
|
|
9298
|
+
}
|
|
9299
|
+
break;
|
|
9300
|
+
default:
|
|
9301
|
+
toolWarnings.push({
|
|
9302
|
+
type: "unsupported-tool",
|
|
9303
|
+
tool: tool$1
|
|
9304
|
+
});
|
|
9305
|
+
break;
|
|
9306
|
+
}
|
|
9307
|
+
const toolChoice = mode.toolChoice;
|
|
9308
|
+
if (toolChoice == null) return {
|
|
9309
|
+
tools: anthropicTools2,
|
|
9310
|
+
tool_choice: void 0,
|
|
9311
|
+
toolWarnings,
|
|
9312
|
+
betas
|
|
9313
|
+
};
|
|
9314
|
+
const type = toolChoice.type;
|
|
9315
|
+
switch (type) {
|
|
9316
|
+
case "auto": return {
|
|
9317
|
+
tools: anthropicTools2,
|
|
9318
|
+
tool_choice: { type: "auto" },
|
|
9319
|
+
toolWarnings,
|
|
9320
|
+
betas
|
|
9321
|
+
};
|
|
9322
|
+
case "required": return {
|
|
9323
|
+
tools: anthropicTools2,
|
|
9324
|
+
tool_choice: { type: "any" },
|
|
9325
|
+
toolWarnings,
|
|
9326
|
+
betas
|
|
9327
|
+
};
|
|
9328
|
+
case "none": return {
|
|
9329
|
+
tools: void 0,
|
|
9330
|
+
tool_choice: void 0,
|
|
9331
|
+
toolWarnings,
|
|
9332
|
+
betas
|
|
9333
|
+
};
|
|
9334
|
+
case "tool": return {
|
|
9335
|
+
tools: anthropicTools2,
|
|
9336
|
+
tool_choice: {
|
|
9337
|
+
type: "tool",
|
|
9338
|
+
name: toolChoice.toolName
|
|
9339
|
+
},
|
|
9340
|
+
toolWarnings,
|
|
9341
|
+
betas
|
|
9342
|
+
};
|
|
9343
|
+
default: {
|
|
9344
|
+
const _exhaustiveCheck = type;
|
|
9345
|
+
throw new UnsupportedFunctionalityError({ functionality: `Unsupported tool choice type: ${_exhaustiveCheck}` });
|
|
9346
|
+
}
|
|
9347
|
+
}
|
|
9348
|
+
}
|
|
9349
|
+
function convertToAnthropicMessagesPrompt({ prompt, sendReasoning, warnings }) {
|
|
9350
|
+
var _a$2, _b, _c, _d;
|
|
9351
|
+
const betas = /* @__PURE__ */ new Set();
|
|
9352
|
+
const blocks = groupIntoBlocks(prompt);
|
|
9353
|
+
let system = void 0;
|
|
9354
|
+
const messages = [];
|
|
9355
|
+
function getCacheControl(providerMetadata) {
|
|
9356
|
+
var _a2$2;
|
|
9357
|
+
const anthropic2 = providerMetadata == null ? void 0 : providerMetadata.anthropic;
|
|
9358
|
+
const cacheControlValue = (_a2$2 = anthropic2 == null ? void 0 : anthropic2.cacheControl) != null ? _a2$2 : anthropic2 == null ? void 0 : anthropic2.cache_control;
|
|
9359
|
+
return cacheControlValue;
|
|
9360
|
+
}
|
|
9361
|
+
for (let i = 0; i < blocks.length; i++) {
|
|
9362
|
+
const block = blocks[i];
|
|
9363
|
+
const isLastBlock = i === blocks.length - 1;
|
|
9364
|
+
const type = block.type;
|
|
9365
|
+
switch (type) {
|
|
9366
|
+
case "system": {
|
|
9367
|
+
if (system != null) throw new UnsupportedFunctionalityError({ functionality: "Multiple system messages that are separated by user/assistant messages" });
|
|
9368
|
+
system = block.messages.map(({ content, providerMetadata }) => ({
|
|
9369
|
+
type: "text",
|
|
9370
|
+
text: content,
|
|
9371
|
+
cache_control: getCacheControl(providerMetadata)
|
|
9372
|
+
}));
|
|
9373
|
+
break;
|
|
9374
|
+
}
|
|
9375
|
+
case "user": {
|
|
9376
|
+
const anthropicContent = [];
|
|
9377
|
+
for (const message of block.messages) {
|
|
9378
|
+
const { role, content } = message;
|
|
9379
|
+
switch (role) {
|
|
9380
|
+
case "user": {
|
|
9381
|
+
for (let j = 0; j < content.length; j++) {
|
|
9382
|
+
const part = content[j];
|
|
9383
|
+
const isLastPart = j === content.length - 1;
|
|
9384
|
+
const cacheControl = (_a$2 = getCacheControl(part.providerMetadata)) != null ? _a$2 : isLastPart ? getCacheControl(message.providerMetadata) : void 0;
|
|
9385
|
+
switch (part.type) {
|
|
9386
|
+
case "text": {
|
|
9387
|
+
anthropicContent.push({
|
|
9388
|
+
type: "text",
|
|
9389
|
+
text: part.text,
|
|
9390
|
+
cache_control: cacheControl
|
|
9391
|
+
});
|
|
9392
|
+
break;
|
|
9393
|
+
}
|
|
9394
|
+
case "image": {
|
|
9395
|
+
anthropicContent.push({
|
|
9396
|
+
type: "image",
|
|
9397
|
+
source: part.image instanceof URL ? {
|
|
9398
|
+
type: "url",
|
|
9399
|
+
url: part.image.toString()
|
|
9400
|
+
} : {
|
|
9401
|
+
type: "base64",
|
|
9402
|
+
media_type: (_b = part.mimeType) != null ? _b : "image/jpeg",
|
|
9403
|
+
data: convertUint8ArrayToBase64(part.image)
|
|
9404
|
+
},
|
|
9405
|
+
cache_control: cacheControl
|
|
9406
|
+
});
|
|
9407
|
+
break;
|
|
9408
|
+
}
|
|
9409
|
+
case "file": {
|
|
9410
|
+
if (part.mimeType !== "application/pdf") throw new UnsupportedFunctionalityError({ functionality: "Non-PDF files in user messages" });
|
|
9411
|
+
betas.add("pdfs-2024-09-25");
|
|
9412
|
+
anthropicContent.push({
|
|
9413
|
+
type: "document",
|
|
9414
|
+
source: part.data instanceof URL ? {
|
|
9415
|
+
type: "url",
|
|
9416
|
+
url: part.data.toString()
|
|
9417
|
+
} : {
|
|
9418
|
+
type: "base64",
|
|
9419
|
+
media_type: "application/pdf",
|
|
9420
|
+
data: part.data
|
|
9421
|
+
},
|
|
9422
|
+
cache_control: cacheControl
|
|
9423
|
+
});
|
|
9424
|
+
break;
|
|
9425
|
+
}
|
|
9426
|
+
}
|
|
9427
|
+
}
|
|
9428
|
+
break;
|
|
9429
|
+
}
|
|
9430
|
+
case "tool": {
|
|
9431
|
+
for (let i2 = 0; i2 < content.length; i2++) {
|
|
9432
|
+
const part = content[i2];
|
|
9433
|
+
const isLastPart = i2 === content.length - 1;
|
|
9434
|
+
const cacheControl = (_c = getCacheControl(part.providerMetadata)) != null ? _c : isLastPart ? getCacheControl(message.providerMetadata) : void 0;
|
|
9435
|
+
const toolResultContent = part.content != null ? part.content.map((part2) => {
|
|
9436
|
+
var _a2$2;
|
|
9437
|
+
switch (part2.type) {
|
|
9438
|
+
case "text": return {
|
|
9439
|
+
type: "text",
|
|
9440
|
+
text: part2.text,
|
|
9441
|
+
cache_control: void 0
|
|
9442
|
+
};
|
|
9443
|
+
case "image": return {
|
|
9444
|
+
type: "image",
|
|
9445
|
+
source: {
|
|
9446
|
+
type: "base64",
|
|
9447
|
+
media_type: (_a2$2 = part2.mimeType) != null ? _a2$2 : "image/jpeg",
|
|
9448
|
+
data: part2.data
|
|
9449
|
+
},
|
|
9450
|
+
cache_control: void 0
|
|
9451
|
+
};
|
|
9452
|
+
}
|
|
9453
|
+
}) : JSON.stringify(part.result);
|
|
9454
|
+
anthropicContent.push({
|
|
9455
|
+
type: "tool_result",
|
|
9456
|
+
tool_use_id: part.toolCallId,
|
|
9457
|
+
content: toolResultContent,
|
|
9458
|
+
is_error: part.isError,
|
|
9459
|
+
cache_control: cacheControl
|
|
9460
|
+
});
|
|
9461
|
+
}
|
|
9462
|
+
break;
|
|
9463
|
+
}
|
|
9464
|
+
default: {
|
|
9465
|
+
const _exhaustiveCheck = role;
|
|
9466
|
+
throw new Error(`Unsupported role: ${_exhaustiveCheck}`);
|
|
9467
|
+
}
|
|
9468
|
+
}
|
|
9469
|
+
}
|
|
9470
|
+
messages.push({
|
|
9471
|
+
role: "user",
|
|
9472
|
+
content: anthropicContent
|
|
9473
|
+
});
|
|
9474
|
+
break;
|
|
9475
|
+
}
|
|
9476
|
+
case "assistant": {
|
|
9477
|
+
const anthropicContent = [];
|
|
9478
|
+
for (let j = 0; j < block.messages.length; j++) {
|
|
9479
|
+
const message = block.messages[j];
|
|
9480
|
+
const isLastMessage = j === block.messages.length - 1;
|
|
9481
|
+
const { content } = message;
|
|
9482
|
+
for (let k = 0; k < content.length; k++) {
|
|
9483
|
+
const part = content[k];
|
|
9484
|
+
const isLastContentPart = k === content.length - 1;
|
|
9485
|
+
const cacheControl = (_d = getCacheControl(part.providerMetadata)) != null ? _d : isLastContentPart ? getCacheControl(message.providerMetadata) : void 0;
|
|
9486
|
+
switch (part.type) {
|
|
9487
|
+
case "text": {
|
|
9488
|
+
anthropicContent.push({
|
|
9489
|
+
type: "text",
|
|
9490
|
+
text: isLastBlock && isLastMessage && isLastContentPart ? part.text.trim() : part.text,
|
|
9491
|
+
cache_control: cacheControl
|
|
9492
|
+
});
|
|
9493
|
+
break;
|
|
9494
|
+
}
|
|
9495
|
+
case "reasoning": {
|
|
9496
|
+
if (sendReasoning) anthropicContent.push({
|
|
9497
|
+
type: "thinking",
|
|
9498
|
+
thinking: part.text,
|
|
9499
|
+
signature: part.signature,
|
|
9500
|
+
cache_control: cacheControl
|
|
9501
|
+
});
|
|
9502
|
+
else warnings.push({
|
|
9503
|
+
type: "other",
|
|
9504
|
+
message: "sending reasoning content is disabled for this model"
|
|
9505
|
+
});
|
|
9506
|
+
break;
|
|
9507
|
+
}
|
|
9508
|
+
case "redacted-reasoning": {
|
|
9509
|
+
anthropicContent.push({
|
|
9510
|
+
type: "redacted_thinking",
|
|
9511
|
+
data: part.data,
|
|
9512
|
+
cache_control: cacheControl
|
|
9513
|
+
});
|
|
9514
|
+
break;
|
|
9515
|
+
}
|
|
9516
|
+
case "tool-call": {
|
|
9517
|
+
anthropicContent.push({
|
|
9518
|
+
type: "tool_use",
|
|
9519
|
+
id: part.toolCallId,
|
|
9520
|
+
name: part.toolName,
|
|
9521
|
+
input: part.args,
|
|
9522
|
+
cache_control: cacheControl
|
|
9523
|
+
});
|
|
9524
|
+
break;
|
|
9525
|
+
}
|
|
9526
|
+
}
|
|
9527
|
+
}
|
|
9528
|
+
}
|
|
9529
|
+
messages.push({
|
|
9530
|
+
role: "assistant",
|
|
9531
|
+
content: anthropicContent
|
|
9532
|
+
});
|
|
9533
|
+
break;
|
|
9534
|
+
}
|
|
9535
|
+
default: {
|
|
9536
|
+
const _exhaustiveCheck = type;
|
|
9537
|
+
throw new Error(`Unsupported type: ${_exhaustiveCheck}`);
|
|
9538
|
+
}
|
|
9539
|
+
}
|
|
9540
|
+
}
|
|
9541
|
+
return {
|
|
9542
|
+
prompt: {
|
|
9543
|
+
system,
|
|
9544
|
+
messages
|
|
9545
|
+
},
|
|
9546
|
+
betas
|
|
9547
|
+
};
|
|
9548
|
+
}
|
|
9549
|
+
function groupIntoBlocks(prompt) {
|
|
9550
|
+
const blocks = [];
|
|
9551
|
+
let currentBlock = void 0;
|
|
9552
|
+
for (const message of prompt) {
|
|
9553
|
+
const { role } = message;
|
|
9554
|
+
switch (role) {
|
|
9555
|
+
case "system": {
|
|
9556
|
+
if ((currentBlock == null ? void 0 : currentBlock.type) !== "system") {
|
|
9557
|
+
currentBlock = {
|
|
9558
|
+
type: "system",
|
|
9559
|
+
messages: []
|
|
9560
|
+
};
|
|
9561
|
+
blocks.push(currentBlock);
|
|
9562
|
+
}
|
|
9563
|
+
currentBlock.messages.push(message);
|
|
9564
|
+
break;
|
|
9565
|
+
}
|
|
9566
|
+
case "assistant": {
|
|
9567
|
+
if ((currentBlock == null ? void 0 : currentBlock.type) !== "assistant") {
|
|
9568
|
+
currentBlock = {
|
|
9569
|
+
type: "assistant",
|
|
9570
|
+
messages: []
|
|
9571
|
+
};
|
|
9572
|
+
blocks.push(currentBlock);
|
|
9573
|
+
}
|
|
9574
|
+
currentBlock.messages.push(message);
|
|
9575
|
+
break;
|
|
9576
|
+
}
|
|
9577
|
+
case "user": {
|
|
9578
|
+
if ((currentBlock == null ? void 0 : currentBlock.type) !== "user") {
|
|
9579
|
+
currentBlock = {
|
|
9580
|
+
type: "user",
|
|
9581
|
+
messages: []
|
|
9582
|
+
};
|
|
9583
|
+
blocks.push(currentBlock);
|
|
9584
|
+
}
|
|
9585
|
+
currentBlock.messages.push(message);
|
|
9586
|
+
break;
|
|
9587
|
+
}
|
|
9588
|
+
case "tool": {
|
|
9589
|
+
if ((currentBlock == null ? void 0 : currentBlock.type) !== "user") {
|
|
9590
|
+
currentBlock = {
|
|
9591
|
+
type: "user",
|
|
9592
|
+
messages: []
|
|
9593
|
+
};
|
|
9594
|
+
blocks.push(currentBlock);
|
|
9595
|
+
}
|
|
9596
|
+
currentBlock.messages.push(message);
|
|
9597
|
+
break;
|
|
9598
|
+
}
|
|
9599
|
+
default: {
|
|
9600
|
+
const _exhaustiveCheck = role;
|
|
9601
|
+
throw new Error(`Unsupported role: ${_exhaustiveCheck}`);
|
|
9602
|
+
}
|
|
9603
|
+
}
|
|
9604
|
+
}
|
|
9605
|
+
return blocks;
|
|
9606
|
+
}
|
|
9607
|
+
function mapAnthropicStopReason(finishReason) {
|
|
9608
|
+
switch (finishReason) {
|
|
9609
|
+
case "end_turn":
|
|
9610
|
+
case "stop_sequence": return "stop";
|
|
9611
|
+
case "tool_use": return "tool-calls";
|
|
9612
|
+
case "max_tokens": return "length";
|
|
9613
|
+
default: return "unknown";
|
|
9614
|
+
}
|
|
9615
|
+
}
|
|
9616
|
+
var AnthropicMessagesLanguageModel = class {
|
|
9617
|
+
constructor(modelId, settings, config) {
|
|
9618
|
+
this.specificationVersion = "v1";
|
|
9619
|
+
this.defaultObjectGenerationMode = "tool";
|
|
9620
|
+
this.modelId = modelId;
|
|
9621
|
+
this.settings = settings;
|
|
9622
|
+
this.config = config;
|
|
9623
|
+
}
|
|
9624
|
+
supportsUrl(url) {
|
|
9625
|
+
return url.protocol === "https:";
|
|
9626
|
+
}
|
|
9627
|
+
get provider() {
|
|
9628
|
+
return this.config.provider;
|
|
9629
|
+
}
|
|
9630
|
+
get supportsImageUrls() {
|
|
9631
|
+
return this.config.supportsImageUrls;
|
|
9632
|
+
}
|
|
9633
|
+
async getArgs({ mode, prompt, maxTokens = 4096, temperature, topP, topK, frequencyPenalty, presencePenalty, stopSequences, responseFormat, seed, providerMetadata: providerOptions }) {
|
|
9634
|
+
var _a$2, _b, _c;
|
|
9635
|
+
const type = mode.type;
|
|
9636
|
+
const warnings = [];
|
|
9637
|
+
if (frequencyPenalty != null) warnings.push({
|
|
9638
|
+
type: "unsupported-setting",
|
|
9639
|
+
setting: "frequencyPenalty"
|
|
9640
|
+
});
|
|
9641
|
+
if (presencePenalty != null) warnings.push({
|
|
9642
|
+
type: "unsupported-setting",
|
|
9643
|
+
setting: "presencePenalty"
|
|
9644
|
+
});
|
|
9645
|
+
if (seed != null) warnings.push({
|
|
9646
|
+
type: "unsupported-setting",
|
|
9647
|
+
setting: "seed"
|
|
9648
|
+
});
|
|
9649
|
+
if (responseFormat != null && responseFormat.type !== "text") warnings.push({
|
|
9650
|
+
type: "unsupported-setting",
|
|
9651
|
+
setting: "responseFormat",
|
|
9652
|
+
details: "JSON response format is not supported."
|
|
9653
|
+
});
|
|
9654
|
+
const { prompt: messagesPrompt, betas: messagesBetas } = convertToAnthropicMessagesPrompt({
|
|
9655
|
+
prompt,
|
|
9656
|
+
sendReasoning: (_a$2 = this.settings.sendReasoning) != null ? _a$2 : true,
|
|
9657
|
+
warnings
|
|
9658
|
+
});
|
|
9659
|
+
const anthropicOptions = parseProviderOptions({
|
|
9660
|
+
provider: "anthropic",
|
|
9661
|
+
providerOptions,
|
|
9662
|
+
schema: anthropicProviderOptionsSchema
|
|
9663
|
+
});
|
|
9664
|
+
const isThinking = ((_b = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _b.type) === "enabled";
|
|
9665
|
+
const thinkingBudget = (_c = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _c.budgetTokens;
|
|
9666
|
+
const baseArgs = {
|
|
9667
|
+
model: this.modelId,
|
|
9668
|
+
max_tokens: maxTokens,
|
|
9669
|
+
temperature,
|
|
9670
|
+
top_k: topK,
|
|
9671
|
+
top_p: topP,
|
|
9672
|
+
stop_sequences: stopSequences,
|
|
9673
|
+
...isThinking && { thinking: {
|
|
9674
|
+
type: "enabled",
|
|
9675
|
+
budget_tokens: thinkingBudget
|
|
9676
|
+
} },
|
|
9677
|
+
system: messagesPrompt.system,
|
|
9678
|
+
messages: messagesPrompt.messages
|
|
9679
|
+
};
|
|
9680
|
+
if (isThinking) {
|
|
9681
|
+
if (thinkingBudget == null) throw new UnsupportedFunctionalityError({ functionality: "thinking requires a budget" });
|
|
9682
|
+
if (baseArgs.temperature != null) {
|
|
9683
|
+
baseArgs.temperature = void 0;
|
|
9684
|
+
warnings.push({
|
|
9685
|
+
type: "unsupported-setting",
|
|
9686
|
+
setting: "temperature",
|
|
9687
|
+
details: "temperature is not supported when thinking is enabled"
|
|
9688
|
+
});
|
|
9689
|
+
}
|
|
9690
|
+
if (topK != null) {
|
|
9691
|
+
baseArgs.top_k = void 0;
|
|
9692
|
+
warnings.push({
|
|
9693
|
+
type: "unsupported-setting",
|
|
9694
|
+
setting: "topK",
|
|
9695
|
+
details: "topK is not supported when thinking is enabled"
|
|
9696
|
+
});
|
|
9697
|
+
}
|
|
9698
|
+
if (topP != null) {
|
|
9699
|
+
baseArgs.top_p = void 0;
|
|
9700
|
+
warnings.push({
|
|
9701
|
+
type: "unsupported-setting",
|
|
9702
|
+
setting: "topP",
|
|
9703
|
+
details: "topP is not supported when thinking is enabled"
|
|
9704
|
+
});
|
|
9705
|
+
}
|
|
9706
|
+
baseArgs.max_tokens = maxTokens + thinkingBudget;
|
|
9707
|
+
}
|
|
9708
|
+
switch (type) {
|
|
9709
|
+
case "regular": {
|
|
9710
|
+
const { tools, tool_choice, toolWarnings, betas: toolsBetas } = prepareTools(mode);
|
|
9711
|
+
return {
|
|
9712
|
+
args: {
|
|
9713
|
+
...baseArgs,
|
|
9714
|
+
tools,
|
|
9715
|
+
tool_choice
|
|
9716
|
+
},
|
|
9717
|
+
warnings: [...warnings, ...toolWarnings],
|
|
9718
|
+
betas: /* @__PURE__ */ new Set([...messagesBetas, ...toolsBetas])
|
|
9719
|
+
};
|
|
9720
|
+
}
|
|
9721
|
+
case "object-json": throw new UnsupportedFunctionalityError({ functionality: "json-mode object generation" });
|
|
9722
|
+
case "object-tool": {
|
|
9723
|
+
const { name: name$2, description: description$73, parameters } = mode.tool;
|
|
9724
|
+
return {
|
|
9725
|
+
args: {
|
|
9726
|
+
...baseArgs,
|
|
9727
|
+
tools: [{
|
|
9728
|
+
name: name$2,
|
|
9729
|
+
description: description$73,
|
|
9730
|
+
input_schema: parameters
|
|
9731
|
+
}],
|
|
9732
|
+
tool_choice: {
|
|
9733
|
+
type: "tool",
|
|
9734
|
+
name: name$2
|
|
9735
|
+
}
|
|
9736
|
+
},
|
|
9737
|
+
warnings,
|
|
9738
|
+
betas: messagesBetas
|
|
9739
|
+
};
|
|
9740
|
+
}
|
|
9741
|
+
default: {
|
|
9742
|
+
const _exhaustiveCheck = type;
|
|
9743
|
+
throw new Error(`Unsupported type: ${_exhaustiveCheck}`);
|
|
9744
|
+
}
|
|
9745
|
+
}
|
|
9746
|
+
}
|
|
9747
|
+
async getHeaders({ betas, headers }) {
|
|
9748
|
+
return combineHeaders(await resolve(this.config.headers), betas.size > 0 ? { "anthropic-beta": Array.from(betas).join(",") } : {}, headers);
|
|
9749
|
+
}
|
|
9750
|
+
buildRequestUrl(isStreaming) {
|
|
9751
|
+
var _a$2, _b, _c;
|
|
9752
|
+
return (_c = (_b = (_a$2 = this.config).buildRequestUrl) == null ? void 0 : _b.call(_a$2, this.config.baseURL, isStreaming)) != null ? _c : `${this.config.baseURL}/messages`;
|
|
9753
|
+
}
|
|
9754
|
+
transformRequestBody(args) {
|
|
9755
|
+
var _a$2, _b, _c;
|
|
9756
|
+
return (_c = (_b = (_a$2 = this.config).transformRequestBody) == null ? void 0 : _b.call(_a$2, args)) != null ? _c : args;
|
|
9757
|
+
}
|
|
9758
|
+
async doGenerate(options) {
|
|
9759
|
+
var _a$2, _b, _c, _d;
|
|
9760
|
+
const { args, warnings, betas } = await this.getArgs(options);
|
|
9761
|
+
const { responseHeaders, value: response, rawValue: rawResponse } = await postJsonToApi({
|
|
9762
|
+
url: this.buildRequestUrl(false),
|
|
9763
|
+
headers: await this.getHeaders({
|
|
9764
|
+
betas,
|
|
9765
|
+
headers: options.headers
|
|
9766
|
+
}),
|
|
9767
|
+
body: this.transformRequestBody(args),
|
|
9768
|
+
failedResponseHandler: anthropicFailedResponseHandler,
|
|
9769
|
+
successfulResponseHandler: createJsonResponseHandler(anthropicMessagesResponseSchema),
|
|
9770
|
+
abortSignal: options.abortSignal,
|
|
9771
|
+
fetch: this.config.fetch
|
|
9772
|
+
});
|
|
9773
|
+
const { messages: rawPrompt,...rawSettings } = args;
|
|
9774
|
+
let text$1 = "";
|
|
9775
|
+
for (const content of response.content) if (content.type === "text") text$1 += content.text;
|
|
9776
|
+
let toolCalls = void 0;
|
|
9777
|
+
if (response.content.some((content) => content.type === "tool_use")) {
|
|
9778
|
+
toolCalls = [];
|
|
9779
|
+
for (const content of response.content) if (content.type === "tool_use") toolCalls.push({
|
|
9780
|
+
toolCallType: "function",
|
|
9781
|
+
toolCallId: content.id,
|
|
9782
|
+
toolName: content.name,
|
|
9783
|
+
args: JSON.stringify(content.input)
|
|
9784
|
+
});
|
|
9785
|
+
}
|
|
9786
|
+
const reasoning = response.content.filter((content) => content.type === "redacted_thinking" || content.type === "thinking").map((content) => content.type === "thinking" ? {
|
|
9787
|
+
type: "text",
|
|
9788
|
+
text: content.thinking,
|
|
9789
|
+
signature: content.signature
|
|
9790
|
+
} : {
|
|
9791
|
+
type: "redacted",
|
|
9792
|
+
data: content.data
|
|
9793
|
+
});
|
|
9794
|
+
return {
|
|
9795
|
+
text: text$1,
|
|
9796
|
+
reasoning: reasoning.length > 0 ? reasoning : void 0,
|
|
9797
|
+
toolCalls,
|
|
9798
|
+
finishReason: mapAnthropicStopReason(response.stop_reason),
|
|
9799
|
+
usage: {
|
|
9800
|
+
promptTokens: response.usage.input_tokens,
|
|
9801
|
+
completionTokens: response.usage.output_tokens
|
|
9802
|
+
},
|
|
9803
|
+
rawCall: {
|
|
9804
|
+
rawPrompt,
|
|
9805
|
+
rawSettings
|
|
9806
|
+
},
|
|
9807
|
+
rawResponse: {
|
|
9808
|
+
headers: responseHeaders,
|
|
9809
|
+
body: rawResponse
|
|
9810
|
+
},
|
|
9811
|
+
response: {
|
|
9812
|
+
id: (_a$2 = response.id) != null ? _a$2 : void 0,
|
|
9813
|
+
modelId: (_b = response.model) != null ? _b : void 0
|
|
9814
|
+
},
|
|
9815
|
+
warnings,
|
|
9816
|
+
providerMetadata: { anthropic: {
|
|
9817
|
+
cacheCreationInputTokens: (_c = response.usage.cache_creation_input_tokens) != null ? _c : null,
|
|
9818
|
+
cacheReadInputTokens: (_d = response.usage.cache_read_input_tokens) != null ? _d : null
|
|
9819
|
+
} },
|
|
9820
|
+
request: { body: JSON.stringify(args) }
|
|
9821
|
+
};
|
|
9822
|
+
}
|
|
9823
|
+
async doStream(options) {
|
|
9824
|
+
const { args, warnings, betas } = await this.getArgs(options);
|
|
9825
|
+
const body = {
|
|
9826
|
+
...args,
|
|
9827
|
+
stream: true
|
|
9828
|
+
};
|
|
9829
|
+
const { responseHeaders, value: response } = await postJsonToApi({
|
|
9830
|
+
url: this.buildRequestUrl(true),
|
|
9831
|
+
headers: await this.getHeaders({
|
|
9832
|
+
betas,
|
|
9833
|
+
headers: options.headers
|
|
9834
|
+
}),
|
|
9835
|
+
body: this.transformRequestBody(body),
|
|
9836
|
+
failedResponseHandler: anthropicFailedResponseHandler,
|
|
9837
|
+
successfulResponseHandler: createEventSourceResponseHandler(anthropicMessagesChunkSchema),
|
|
9838
|
+
abortSignal: options.abortSignal,
|
|
9839
|
+
fetch: this.config.fetch
|
|
9840
|
+
});
|
|
9841
|
+
const { messages: rawPrompt,...rawSettings } = args;
|
|
9842
|
+
let finishReason = "unknown";
|
|
9843
|
+
const usage = {
|
|
9844
|
+
promptTokens: NaN,
|
|
9845
|
+
completionTokens: NaN
|
|
9846
|
+
};
|
|
9847
|
+
const toolCallContentBlocks = {};
|
|
9848
|
+
let providerMetadata = void 0;
|
|
9849
|
+
let blockType = void 0;
|
|
9850
|
+
return {
|
|
9851
|
+
stream: response.pipeThrough(new TransformStream({ transform(chunk, controller) {
|
|
9852
|
+
var _a$2, _b, _c, _d;
|
|
9853
|
+
if (!chunk.success) {
|
|
9854
|
+
controller.enqueue({
|
|
9855
|
+
type: "error",
|
|
9856
|
+
error: chunk.error
|
|
9857
|
+
});
|
|
9858
|
+
return;
|
|
9859
|
+
}
|
|
9860
|
+
const value = chunk.value;
|
|
9861
|
+
switch (value.type) {
|
|
9862
|
+
case "ping": return;
|
|
9863
|
+
case "content_block_start": {
|
|
9864
|
+
const contentBlockType = value.content_block.type;
|
|
9865
|
+
blockType = contentBlockType;
|
|
9866
|
+
switch (contentBlockType) {
|
|
9867
|
+
case "text":
|
|
9868
|
+
case "thinking": return;
|
|
9869
|
+
case "redacted_thinking": {
|
|
9870
|
+
controller.enqueue({
|
|
9871
|
+
type: "redacted-reasoning",
|
|
9872
|
+
data: value.content_block.data
|
|
9873
|
+
});
|
|
9874
|
+
return;
|
|
9875
|
+
}
|
|
9876
|
+
case "tool_use": {
|
|
9877
|
+
toolCallContentBlocks[value.index] = {
|
|
9878
|
+
toolCallId: value.content_block.id,
|
|
9879
|
+
toolName: value.content_block.name,
|
|
9880
|
+
jsonText: ""
|
|
9881
|
+
};
|
|
9882
|
+
return;
|
|
9883
|
+
}
|
|
9884
|
+
default: {
|
|
9885
|
+
const _exhaustiveCheck = contentBlockType;
|
|
9886
|
+
throw new Error(`Unsupported content block type: ${_exhaustiveCheck}`);
|
|
9887
|
+
}
|
|
9888
|
+
}
|
|
9889
|
+
}
|
|
9890
|
+
case "content_block_stop": {
|
|
9891
|
+
if (toolCallContentBlocks[value.index] != null) {
|
|
9892
|
+
const contentBlock = toolCallContentBlocks[value.index];
|
|
9893
|
+
controller.enqueue({
|
|
9894
|
+
type: "tool-call",
|
|
9895
|
+
toolCallType: "function",
|
|
9896
|
+
toolCallId: contentBlock.toolCallId,
|
|
9897
|
+
toolName: contentBlock.toolName,
|
|
9898
|
+
args: contentBlock.jsonText
|
|
9899
|
+
});
|
|
9900
|
+
delete toolCallContentBlocks[value.index];
|
|
9901
|
+
}
|
|
9902
|
+
blockType = void 0;
|
|
9903
|
+
return;
|
|
9904
|
+
}
|
|
9905
|
+
case "content_block_delta": {
|
|
9906
|
+
const deltaType = value.delta.type;
|
|
9907
|
+
switch (deltaType) {
|
|
9908
|
+
case "text_delta": {
|
|
9909
|
+
controller.enqueue({
|
|
9910
|
+
type: "text-delta",
|
|
9911
|
+
textDelta: value.delta.text
|
|
9912
|
+
});
|
|
9913
|
+
return;
|
|
9914
|
+
}
|
|
9915
|
+
case "thinking_delta": {
|
|
9916
|
+
controller.enqueue({
|
|
9917
|
+
type: "reasoning",
|
|
9918
|
+
textDelta: value.delta.thinking
|
|
9919
|
+
});
|
|
9920
|
+
return;
|
|
9921
|
+
}
|
|
9922
|
+
case "signature_delta": {
|
|
9923
|
+
if (blockType === "thinking") controller.enqueue({
|
|
9924
|
+
type: "reasoning-signature",
|
|
9925
|
+
signature: value.delta.signature
|
|
9926
|
+
});
|
|
9927
|
+
return;
|
|
9928
|
+
}
|
|
9929
|
+
case "input_json_delta": {
|
|
9930
|
+
const contentBlock = toolCallContentBlocks[value.index];
|
|
9931
|
+
controller.enqueue({
|
|
9932
|
+
type: "tool-call-delta",
|
|
9933
|
+
toolCallType: "function",
|
|
9934
|
+
toolCallId: contentBlock.toolCallId,
|
|
9935
|
+
toolName: contentBlock.toolName,
|
|
9936
|
+
argsTextDelta: value.delta.partial_json
|
|
9937
|
+
});
|
|
9938
|
+
contentBlock.jsonText += value.delta.partial_json;
|
|
9939
|
+
return;
|
|
9940
|
+
}
|
|
9941
|
+
default: {
|
|
9942
|
+
const _exhaustiveCheck = deltaType;
|
|
9943
|
+
throw new Error(`Unsupported delta type: ${_exhaustiveCheck}`);
|
|
9944
|
+
}
|
|
9945
|
+
}
|
|
9946
|
+
}
|
|
9947
|
+
case "message_start": {
|
|
9948
|
+
usage.promptTokens = value.message.usage.input_tokens;
|
|
9949
|
+
usage.completionTokens = value.message.usage.output_tokens;
|
|
9950
|
+
providerMetadata = { anthropic: {
|
|
9951
|
+
cacheCreationInputTokens: (_a$2 = value.message.usage.cache_creation_input_tokens) != null ? _a$2 : null,
|
|
9952
|
+
cacheReadInputTokens: (_b = value.message.usage.cache_read_input_tokens) != null ? _b : null
|
|
9953
|
+
} };
|
|
9954
|
+
controller.enqueue({
|
|
9955
|
+
type: "response-metadata",
|
|
9956
|
+
id: (_c = value.message.id) != null ? _c : void 0,
|
|
9957
|
+
modelId: (_d = value.message.model) != null ? _d : void 0
|
|
9958
|
+
});
|
|
9959
|
+
return;
|
|
9960
|
+
}
|
|
9961
|
+
case "message_delta": {
|
|
9962
|
+
usage.completionTokens = value.usage.output_tokens;
|
|
9963
|
+
finishReason = mapAnthropicStopReason(value.delta.stop_reason);
|
|
9964
|
+
return;
|
|
9965
|
+
}
|
|
9966
|
+
case "message_stop": {
|
|
9967
|
+
controller.enqueue({
|
|
9968
|
+
type: "finish",
|
|
9969
|
+
finishReason,
|
|
9970
|
+
usage,
|
|
9971
|
+
providerMetadata
|
|
9972
|
+
});
|
|
9973
|
+
return;
|
|
9974
|
+
}
|
|
9975
|
+
case "error": {
|
|
9976
|
+
controller.enqueue({
|
|
9977
|
+
type: "error",
|
|
9978
|
+
error: value.error
|
|
9979
|
+
});
|
|
9980
|
+
return;
|
|
9981
|
+
}
|
|
9982
|
+
default: {
|
|
9983
|
+
const _exhaustiveCheck = value;
|
|
9984
|
+
throw new Error(`Unsupported chunk type: ${_exhaustiveCheck}`);
|
|
9985
|
+
}
|
|
9986
|
+
}
|
|
9987
|
+
} })),
|
|
9988
|
+
rawCall: {
|
|
9989
|
+
rawPrompt,
|
|
9990
|
+
rawSettings
|
|
9991
|
+
},
|
|
9992
|
+
rawResponse: { headers: responseHeaders },
|
|
9993
|
+
warnings,
|
|
9994
|
+
request: { body: JSON.stringify(body) }
|
|
9995
|
+
};
|
|
9996
|
+
}
|
|
9997
|
+
};
|
|
9998
|
+
var anthropicMessagesResponseSchema = z.object({
|
|
9999
|
+
type: z.literal("message"),
|
|
10000
|
+
id: z.string().nullish(),
|
|
10001
|
+
model: z.string().nullish(),
|
|
10002
|
+
content: z.array(z.discriminatedUnion("type", [
|
|
10003
|
+
z.object({
|
|
10004
|
+
type: z.literal("text"),
|
|
10005
|
+
text: z.string()
|
|
10006
|
+
}),
|
|
10007
|
+
z.object({
|
|
10008
|
+
type: z.literal("thinking"),
|
|
10009
|
+
thinking: z.string(),
|
|
10010
|
+
signature: z.string()
|
|
10011
|
+
}),
|
|
10012
|
+
z.object({
|
|
10013
|
+
type: z.literal("redacted_thinking"),
|
|
10014
|
+
data: z.string()
|
|
10015
|
+
}),
|
|
10016
|
+
z.object({
|
|
10017
|
+
type: z.literal("tool_use"),
|
|
10018
|
+
id: z.string(),
|
|
10019
|
+
name: z.string(),
|
|
10020
|
+
input: z.unknown()
|
|
10021
|
+
})
|
|
10022
|
+
])),
|
|
10023
|
+
stop_reason: z.string().nullish(),
|
|
10024
|
+
usage: z.object({
|
|
10025
|
+
input_tokens: z.number(),
|
|
10026
|
+
output_tokens: z.number(),
|
|
10027
|
+
cache_creation_input_tokens: z.number().nullish(),
|
|
10028
|
+
cache_read_input_tokens: z.number().nullish()
|
|
10029
|
+
})
|
|
10030
|
+
});
|
|
10031
|
+
var anthropicMessagesChunkSchema = z.discriminatedUnion("type", [
|
|
10032
|
+
z.object({
|
|
10033
|
+
type: z.literal("message_start"),
|
|
10034
|
+
message: z.object({
|
|
10035
|
+
id: z.string().nullish(),
|
|
10036
|
+
model: z.string().nullish(),
|
|
10037
|
+
usage: z.object({
|
|
10038
|
+
input_tokens: z.number(),
|
|
10039
|
+
output_tokens: z.number(),
|
|
10040
|
+
cache_creation_input_tokens: z.number().nullish(),
|
|
10041
|
+
cache_read_input_tokens: z.number().nullish()
|
|
10042
|
+
})
|
|
10043
|
+
})
|
|
10044
|
+
}),
|
|
10045
|
+
z.object({
|
|
10046
|
+
type: z.literal("content_block_start"),
|
|
10047
|
+
index: z.number(),
|
|
10048
|
+
content_block: z.discriminatedUnion("type", [
|
|
10049
|
+
z.object({
|
|
10050
|
+
type: z.literal("text"),
|
|
10051
|
+
text: z.string()
|
|
10052
|
+
}),
|
|
10053
|
+
z.object({
|
|
10054
|
+
type: z.literal("thinking"),
|
|
10055
|
+
thinking: z.string()
|
|
10056
|
+
}),
|
|
10057
|
+
z.object({
|
|
10058
|
+
type: z.literal("tool_use"),
|
|
10059
|
+
id: z.string(),
|
|
10060
|
+
name: z.string()
|
|
10061
|
+
}),
|
|
10062
|
+
z.object({
|
|
10063
|
+
type: z.literal("redacted_thinking"),
|
|
10064
|
+
data: z.string()
|
|
10065
|
+
})
|
|
10066
|
+
])
|
|
10067
|
+
}),
|
|
10068
|
+
z.object({
|
|
10069
|
+
type: z.literal("content_block_delta"),
|
|
10070
|
+
index: z.number(),
|
|
10071
|
+
delta: z.discriminatedUnion("type", [
|
|
10072
|
+
z.object({
|
|
10073
|
+
type: z.literal("input_json_delta"),
|
|
10074
|
+
partial_json: z.string()
|
|
10075
|
+
}),
|
|
10076
|
+
z.object({
|
|
10077
|
+
type: z.literal("text_delta"),
|
|
10078
|
+
text: z.string()
|
|
10079
|
+
}),
|
|
10080
|
+
z.object({
|
|
10081
|
+
type: z.literal("thinking_delta"),
|
|
10082
|
+
thinking: z.string()
|
|
10083
|
+
}),
|
|
10084
|
+
z.object({
|
|
10085
|
+
type: z.literal("signature_delta"),
|
|
10086
|
+
signature: z.string()
|
|
10087
|
+
})
|
|
10088
|
+
])
|
|
10089
|
+
}),
|
|
10090
|
+
z.object({
|
|
10091
|
+
type: z.literal("content_block_stop"),
|
|
10092
|
+
index: z.number()
|
|
10093
|
+
}),
|
|
10094
|
+
z.object({
|
|
10095
|
+
type: z.literal("error"),
|
|
10096
|
+
error: z.object({
|
|
10097
|
+
type: z.string(),
|
|
10098
|
+
message: z.string()
|
|
10099
|
+
})
|
|
10100
|
+
}),
|
|
10101
|
+
z.object({
|
|
10102
|
+
type: z.literal("message_delta"),
|
|
10103
|
+
delta: z.object({ stop_reason: z.string().nullish() }),
|
|
10104
|
+
usage: z.object({ output_tokens: z.number() })
|
|
10105
|
+
}),
|
|
10106
|
+
z.object({ type: z.literal("message_stop") }),
|
|
10107
|
+
z.object({ type: z.literal("ping") })
|
|
10108
|
+
]);
|
|
10109
|
+
var anthropicProviderOptionsSchema = z.object({ thinking: z.object({
|
|
10110
|
+
type: z.union([z.literal("enabled"), z.literal("disabled")]),
|
|
10111
|
+
budgetTokens: z.number().optional()
|
|
10112
|
+
}).optional() });
|
|
10113
|
+
var Bash20241022Parameters = z.object({
|
|
10114
|
+
command: z.string(),
|
|
10115
|
+
restart: z.boolean().optional()
|
|
10116
|
+
});
|
|
10117
|
+
function bashTool_20241022(options = {}) {
|
|
10118
|
+
return {
|
|
10119
|
+
type: "provider-defined",
|
|
10120
|
+
id: "anthropic.bash_20241022",
|
|
10121
|
+
args: {},
|
|
10122
|
+
parameters: Bash20241022Parameters,
|
|
10123
|
+
execute: options.execute,
|
|
10124
|
+
experimental_toToolResultContent: options.experimental_toToolResultContent
|
|
10125
|
+
};
|
|
10126
|
+
}
|
|
10127
|
+
var Bash20250124Parameters = z.object({
|
|
10128
|
+
command: z.string(),
|
|
10129
|
+
restart: z.boolean().optional()
|
|
10130
|
+
});
|
|
10131
|
+
function bashTool_20250124(options = {}) {
|
|
10132
|
+
return {
|
|
10133
|
+
type: "provider-defined",
|
|
10134
|
+
id: "anthropic.bash_20250124",
|
|
10135
|
+
args: {},
|
|
10136
|
+
parameters: Bash20250124Parameters,
|
|
10137
|
+
execute: options.execute,
|
|
10138
|
+
experimental_toToolResultContent: options.experimental_toToolResultContent
|
|
10139
|
+
};
|
|
10140
|
+
}
|
|
10141
|
+
var TextEditor20241022Parameters = z.object({
|
|
10142
|
+
command: z.enum([
|
|
10143
|
+
"view",
|
|
10144
|
+
"create",
|
|
10145
|
+
"str_replace",
|
|
10146
|
+
"insert",
|
|
10147
|
+
"undo_edit"
|
|
10148
|
+
]),
|
|
10149
|
+
path: z.string(),
|
|
10150
|
+
file_text: z.string().optional(),
|
|
10151
|
+
insert_line: z.number().int().optional(),
|
|
10152
|
+
new_str: z.string().optional(),
|
|
10153
|
+
old_str: z.string().optional(),
|
|
10154
|
+
view_range: z.array(z.number().int()).optional()
|
|
10155
|
+
});
|
|
10156
|
+
function textEditorTool_20241022(options = {}) {
|
|
10157
|
+
return {
|
|
10158
|
+
type: "provider-defined",
|
|
10159
|
+
id: "anthropic.text_editor_20241022",
|
|
10160
|
+
args: {},
|
|
10161
|
+
parameters: TextEditor20241022Parameters,
|
|
10162
|
+
execute: options.execute,
|
|
10163
|
+
experimental_toToolResultContent: options.experimental_toToolResultContent
|
|
10164
|
+
};
|
|
10165
|
+
}
|
|
10166
|
+
var TextEditor20250124Parameters = z.object({
|
|
10167
|
+
command: z.enum([
|
|
10168
|
+
"view",
|
|
10169
|
+
"create",
|
|
10170
|
+
"str_replace",
|
|
10171
|
+
"insert",
|
|
10172
|
+
"undo_edit"
|
|
10173
|
+
]),
|
|
10174
|
+
path: z.string(),
|
|
10175
|
+
file_text: z.string().optional(),
|
|
10176
|
+
insert_line: z.number().int().optional(),
|
|
10177
|
+
new_str: z.string().optional(),
|
|
10178
|
+
old_str: z.string().optional(),
|
|
10179
|
+
view_range: z.array(z.number().int()).optional()
|
|
10180
|
+
});
|
|
10181
|
+
function textEditorTool_20250124(options = {}) {
|
|
10182
|
+
return {
|
|
10183
|
+
type: "provider-defined",
|
|
10184
|
+
id: "anthropic.text_editor_20250124",
|
|
10185
|
+
args: {},
|
|
10186
|
+
parameters: TextEditor20250124Parameters,
|
|
10187
|
+
execute: options.execute,
|
|
10188
|
+
experimental_toToolResultContent: options.experimental_toToolResultContent
|
|
10189
|
+
};
|
|
10190
|
+
}
|
|
10191
|
+
var Computer20241022Parameters = z.object({
|
|
10192
|
+
action: z.enum([
|
|
10193
|
+
"key",
|
|
10194
|
+
"type",
|
|
10195
|
+
"mouse_move",
|
|
10196
|
+
"left_click",
|
|
10197
|
+
"left_click_drag",
|
|
10198
|
+
"right_click",
|
|
10199
|
+
"middle_click",
|
|
10200
|
+
"double_click",
|
|
10201
|
+
"screenshot",
|
|
10202
|
+
"cursor_position"
|
|
10203
|
+
]),
|
|
10204
|
+
coordinate: z.array(z.number().int()).optional(),
|
|
10205
|
+
text: z.string().optional()
|
|
10206
|
+
});
|
|
10207
|
+
function computerTool_20241022(options) {
|
|
10208
|
+
return {
|
|
10209
|
+
type: "provider-defined",
|
|
10210
|
+
id: "anthropic.computer_20241022",
|
|
10211
|
+
args: {
|
|
10212
|
+
displayWidthPx: options.displayWidthPx,
|
|
10213
|
+
displayHeightPx: options.displayHeightPx,
|
|
10214
|
+
displayNumber: options.displayNumber
|
|
10215
|
+
},
|
|
10216
|
+
parameters: Computer20241022Parameters,
|
|
10217
|
+
execute: options.execute,
|
|
10218
|
+
experimental_toToolResultContent: options.experimental_toToolResultContent
|
|
10219
|
+
};
|
|
10220
|
+
}
|
|
10221
|
+
var Computer20250124Parameters = z.object({
|
|
10222
|
+
action: z.enum([
|
|
10223
|
+
"key",
|
|
10224
|
+
"hold_key",
|
|
10225
|
+
"type",
|
|
10226
|
+
"cursor_position",
|
|
10227
|
+
"mouse_move",
|
|
10228
|
+
"left_mouse_down",
|
|
10229
|
+
"left_mouse_up",
|
|
10230
|
+
"left_click",
|
|
10231
|
+
"left_click_drag",
|
|
10232
|
+
"right_click",
|
|
10233
|
+
"middle_click",
|
|
10234
|
+
"double_click",
|
|
10235
|
+
"triple_click",
|
|
10236
|
+
"scroll",
|
|
10237
|
+
"wait",
|
|
10238
|
+
"screenshot"
|
|
10239
|
+
]),
|
|
10240
|
+
coordinate: z.tuple([z.number().int(), z.number().int()]).optional(),
|
|
10241
|
+
duration: z.number().optional(),
|
|
10242
|
+
scroll_amount: z.number().optional(),
|
|
10243
|
+
scroll_direction: z.enum([
|
|
10244
|
+
"up",
|
|
10245
|
+
"down",
|
|
10246
|
+
"left",
|
|
10247
|
+
"right"
|
|
10248
|
+
]).optional(),
|
|
10249
|
+
start_coordinate: z.tuple([z.number().int(), z.number().int()]).optional(),
|
|
10250
|
+
text: z.string().optional()
|
|
10251
|
+
});
|
|
10252
|
+
function computerTool_20250124(options) {
|
|
10253
|
+
return {
|
|
10254
|
+
type: "provider-defined",
|
|
10255
|
+
id: "anthropic.computer_20250124",
|
|
10256
|
+
args: {
|
|
10257
|
+
displayWidthPx: options.displayWidthPx,
|
|
10258
|
+
displayHeightPx: options.displayHeightPx,
|
|
10259
|
+
displayNumber: options.displayNumber
|
|
10260
|
+
},
|
|
10261
|
+
parameters: Computer20250124Parameters,
|
|
10262
|
+
execute: options.execute,
|
|
10263
|
+
experimental_toToolResultContent: options.experimental_toToolResultContent
|
|
10264
|
+
};
|
|
10265
|
+
}
|
|
10266
|
+
var anthropicTools = {
|
|
10267
|
+
bash_20241022: bashTool_20241022,
|
|
10268
|
+
bash_20250124: bashTool_20250124,
|
|
10269
|
+
textEditor_20241022: textEditorTool_20241022,
|
|
10270
|
+
textEditor_20250124: textEditorTool_20250124,
|
|
10271
|
+
computer_20241022: computerTool_20241022,
|
|
10272
|
+
computer_20250124: computerTool_20250124
|
|
10273
|
+
};
|
|
10274
|
+
function createAnthropic(options = {}) {
|
|
10275
|
+
var _a$2;
|
|
10276
|
+
const baseURL = (_a$2 = withoutTrailingSlash(options.baseURL)) != null ? _a$2 : "https://api.anthropic.com/v1";
|
|
10277
|
+
const getHeaders = () => ({
|
|
10278
|
+
"anthropic-version": "2023-06-01",
|
|
10279
|
+
"x-api-key": loadApiKey({
|
|
10280
|
+
apiKey: options.apiKey,
|
|
10281
|
+
environmentVariableName: "ANTHROPIC_API_KEY",
|
|
10282
|
+
description: "Anthropic"
|
|
10283
|
+
}),
|
|
10284
|
+
...options.headers
|
|
10285
|
+
});
|
|
10286
|
+
const createChatModel = (modelId, settings = {}) => new AnthropicMessagesLanguageModel(modelId, settings, {
|
|
10287
|
+
provider: "anthropic.messages",
|
|
10288
|
+
baseURL,
|
|
10289
|
+
headers: getHeaders,
|
|
10290
|
+
fetch: options.fetch,
|
|
10291
|
+
supportsImageUrls: true
|
|
10292
|
+
});
|
|
10293
|
+
const provider = function(modelId, settings) {
|
|
10294
|
+
if (new.target) throw new Error("The Anthropic model function cannot be called with the new keyword.");
|
|
10295
|
+
return createChatModel(modelId, settings);
|
|
10296
|
+
};
|
|
10297
|
+
provider.languageModel = createChatModel;
|
|
10298
|
+
provider.chat = createChatModel;
|
|
10299
|
+
provider.messages = createChatModel;
|
|
10300
|
+
provider.textEmbeddingModel = (modelId) => {
|
|
10301
|
+
throw new NoSuchModelError({
|
|
10302
|
+
modelId,
|
|
10303
|
+
modelType: "textEmbeddingModel"
|
|
10304
|
+
});
|
|
10305
|
+
};
|
|
10306
|
+
provider.tools = anthropicTools;
|
|
10307
|
+
return provider;
|
|
10308
|
+
}
|
|
10309
|
+
var anthropic = createAnthropic();
|
|
8981
10310
|
|
|
8982
10311
|
//#endregion
|
|
8983
|
-
//#region ../mcp-core/dist/
|
|
8984
|
-
const
|
|
8985
|
-
const VALID_REASONING_EFFORTS = [
|
|
8986
|
-
"low",
|
|
8987
|
-
"medium",
|
|
8988
|
-
"high"
|
|
8989
|
-
];
|
|
8990
|
-
const DEFAULT_REASONING_EFFORT = "low";
|
|
10312
|
+
//#region ../mcp-core/dist/anthropic-provider-BGKT8f9G.js
|
|
10313
|
+
const DEFAULT_ANTHROPIC_MODEL = "claude-sonnet-4-5";
|
|
8991
10314
|
let configuredBaseUrl;
|
|
8992
10315
|
/**
|
|
8993
|
-
* Configure the
|
|
10316
|
+
* Configure the Anthropic base URL (CLI flag only, not environment variable).
|
|
8994
10317
|
* This must be called explicitly - it cannot be set via environment variables for security.
|
|
8995
10318
|
*/
|
|
8996
|
-
function
|
|
10319
|
+
function setAnthropicBaseUrl(baseUrl) {
|
|
8997
10320
|
configuredBaseUrl = baseUrl;
|
|
8998
10321
|
}
|
|
8999
10322
|
/**
|
|
9000
|
-
* Retrieve an
|
|
10323
|
+
* Retrieve an Anthropic language model configured from environment variables and explicit config.
|
|
9001
10324
|
*
|
|
9002
10325
|
* Configuration:
|
|
9003
|
-
* -
|
|
9004
|
-
* -
|
|
9005
|
-
* - Base URL: Must be set via setOpenAIBaseUrl() - NOT from env vars (security risk)
|
|
10326
|
+
* - ANTHROPIC_MODEL: Model to use (default: "claude-sonnet-4-5") - env var OK
|
|
10327
|
+
* - Base URL: Must be set via setAnthropicBaseUrl() - NOT from env vars (security risk)
|
|
9006
10328
|
*/
|
|
9007
|
-
function
|
|
9008
|
-
const defaultModel = process.env.
|
|
9009
|
-
const
|
|
9010
|
-
let reasoningEffort;
|
|
9011
|
-
if (envReasoningEffort === "") reasoningEffort = void 0;
|
|
9012
|
-
else if (envReasoningEffort === void 0) reasoningEffort = DEFAULT_REASONING_EFFORT;
|
|
9013
|
-
else if (VALID_REASONING_EFFORTS.includes(envReasoningEffort)) reasoningEffort = envReasoningEffort;
|
|
9014
|
-
else {
|
|
9015
|
-
const validValues = VALID_REASONING_EFFORTS.map((v) => `"${v}"`).join(", ");
|
|
9016
|
-
throw new Error(`Invalid OPENAI_REASONING_EFFORT value: "${envReasoningEffort}". Must be one of: ${validValues}, or "" (empty string to disable). Default is "${DEFAULT_REASONING_EFFORT}".`);
|
|
9017
|
-
}
|
|
9018
|
-
const factory = createOpenAI({
|
|
10329
|
+
function getAnthropicModel(model) {
|
|
10330
|
+
const defaultModel = process.env.ANTHROPIC_MODEL || DEFAULT_ANTHROPIC_MODEL;
|
|
10331
|
+
const factory = createAnthropic({
|
|
9019
10332
|
...configuredBaseUrl && { baseURL: configuredBaseUrl },
|
|
9020
10333
|
headers: { "User-Agent": USER_AGENT }
|
|
9021
10334
|
});
|
|
9022
|
-
return factory(model ?? defaultModel
|
|
10335
|
+
return factory(model ?? defaultModel);
|
|
10336
|
+
}
|
|
10337
|
+
|
|
10338
|
+
//#endregion
|
|
10339
|
+
//#region ../mcp-core/dist/provider-factory-Bxvb4LE7.js
|
|
10340
|
+
let configuredProvider;
|
|
10341
|
+
/**
|
|
10342
|
+
* Configure the embedded agent provider explicitly.
|
|
10343
|
+
* Call this from CLI to override auto-detection.
|
|
10344
|
+
*/
|
|
10345
|
+
function setAgentProvider(provider) {
|
|
10346
|
+
configuredProvider = provider;
|
|
10347
|
+
}
|
|
10348
|
+
/**
|
|
10349
|
+
* Configure base URLs for providers (called from CLI).
|
|
10350
|
+
*/
|
|
10351
|
+
function setProviderBaseUrls(config) {
|
|
10352
|
+
if (config.openaiBaseUrl) setOpenAIBaseUrl(config.openaiBaseUrl);
|
|
10353
|
+
if (config.anthropicBaseUrl) setAnthropicBaseUrl(config.anthropicBaseUrl);
|
|
10354
|
+
}
|
|
10355
|
+
/**
|
|
10356
|
+
* Check if the API key exists for a given provider type.
|
|
10357
|
+
*/
|
|
10358
|
+
function hasApiKeyForProvider(type) {
|
|
10359
|
+
switch (type) {
|
|
10360
|
+
case "anthropic": return Boolean(process.env.ANTHROPIC_API_KEY);
|
|
10361
|
+
case "openai": return Boolean(process.env.OPENAI_API_KEY);
|
|
10362
|
+
}
|
|
10363
|
+
}
|
|
10364
|
+
/**
|
|
10365
|
+
* Get the expected API key name for a provider type.
|
|
10366
|
+
*/
|
|
10367
|
+
function getApiKeyName(type) {
|
|
10368
|
+
switch (type) {
|
|
10369
|
+
case "anthropic": return "ANTHROPIC_API_KEY";
|
|
10370
|
+
case "openai": return "OPENAI_API_KEY";
|
|
10371
|
+
}
|
|
10372
|
+
}
|
|
10373
|
+
/**
|
|
10374
|
+
* Build a provider instance for the given type.
|
|
10375
|
+
*/
|
|
10376
|
+
function buildProvider(type) {
|
|
10377
|
+
switch (type) {
|
|
10378
|
+
case "anthropic": return {
|
|
10379
|
+
type: "anthropic",
|
|
10380
|
+
getModel: getAnthropicModel,
|
|
10381
|
+
getProviderOptions: () => ({}),
|
|
10382
|
+
getTemperature: () => void 0
|
|
10383
|
+
};
|
|
10384
|
+
case "openai": return {
|
|
10385
|
+
type: "openai",
|
|
10386
|
+
getModel: getOpenAIModel,
|
|
10387
|
+
getProviderOptions: () => ({ openai: {
|
|
10388
|
+
structuredOutputs: false,
|
|
10389
|
+
strictJsonSchema: false
|
|
10390
|
+
} }),
|
|
10391
|
+
getTemperature: () => 1
|
|
10392
|
+
};
|
|
10393
|
+
}
|
|
10394
|
+
}
|
|
10395
|
+
/**
|
|
10396
|
+
* Get the current agent provider based on configuration.
|
|
10397
|
+
*
|
|
10398
|
+
* Resolution order:
|
|
10399
|
+
* 1. Explicit configuration via setAgentProvider()
|
|
10400
|
+
* 2. EMBEDDED_AGENT_PROVIDER environment variable
|
|
10401
|
+
* 3. Auto-detect: check ANTHROPIC_API_KEY, then OPENAI_API_KEY
|
|
10402
|
+
* 4. Throw ConfigurationError if no provider available
|
|
10403
|
+
*/
|
|
10404
|
+
function getAgentProvider() {
|
|
10405
|
+
let providerType = configuredProvider;
|
|
10406
|
+
if (!providerType) {
|
|
10407
|
+
const envProvider = process.env.EMBEDDED_AGENT_PROVIDER?.toLowerCase();
|
|
10408
|
+
if (envProvider === "openai" || envProvider === "anthropic") providerType = envProvider;
|
|
10409
|
+
}
|
|
10410
|
+
if (providerType && !hasApiKeyForProvider(providerType)) throw new ConfigurationError(`Provider "${providerType}" is configured but ${getApiKeyName(providerType)} is not set. Please set the API key environment variable.`);
|
|
10411
|
+
if (!providerType) {
|
|
10412
|
+
if (process.env.ANTHROPIC_API_KEY) providerType = "anthropic";
|
|
10413
|
+
else if (process.env.OPENAI_API_KEY) providerType = "openai";
|
|
10414
|
+
}
|
|
10415
|
+
if (!providerType) throw new ConfigurationError("No embedded agent provider configured. Set OPENAI_API_KEY or ANTHROPIC_API_KEY environment variable, or use --agent-provider flag to specify a provider.");
|
|
10416
|
+
return buildProvider(providerType);
|
|
10417
|
+
}
|
|
10418
|
+
/**
|
|
10419
|
+
* Check if an embedded agent provider is available.
|
|
10420
|
+
* Returns true if getAgentProvider() would succeed.
|
|
10421
|
+
*/
|
|
10422
|
+
function hasAgentProvider() {
|
|
10423
|
+
try {
|
|
10424
|
+
getAgentProvider();
|
|
10425
|
+
return true;
|
|
10426
|
+
} catch {
|
|
10427
|
+
return false;
|
|
10428
|
+
}
|
|
10429
|
+
}
|
|
10430
|
+
/**
|
|
10431
|
+
* Get the resolved provider type without throwing.
|
|
10432
|
+
* Returns undefined if no provider is available or API key is missing.
|
|
10433
|
+
*/
|
|
10434
|
+
function getResolvedProviderType() {
|
|
10435
|
+
if (configuredProvider) return hasApiKeyForProvider(configuredProvider) ? configuredProvider : void 0;
|
|
10436
|
+
const envProvider = process.env.EMBEDDED_AGENT_PROVIDER?.toLowerCase();
|
|
10437
|
+
if (envProvider === "openai" || envProvider === "anthropic") return hasApiKeyForProvider(envProvider) ? envProvider : void 0;
|
|
10438
|
+
if (process.env.ANTHROPIC_API_KEY) return "anthropic";
|
|
10439
|
+
if (process.env.OPENAI_API_KEY) return "openai";
|
|
10440
|
+
return void 0;
|
|
9023
10441
|
}
|
|
9024
10442
|
|
|
9025
10443
|
//#endregion
|
|
@@ -13874,8 +15292,8 @@ var SseMCPTransport = class {
|
|
|
13874
15292
|
this.headers = headers;
|
|
13875
15293
|
}
|
|
13876
15294
|
async start() {
|
|
13877
|
-
return new Promise((resolve, reject) => {
|
|
13878
|
-
if (this.connected) return resolve();
|
|
15295
|
+
return new Promise((resolve$1, reject) => {
|
|
15296
|
+
if (this.connected) return resolve$1();
|
|
13879
15297
|
this.abortController = new AbortController();
|
|
13880
15298
|
const establishConnection = async () => {
|
|
13881
15299
|
var _a17, _b, _c;
|
|
@@ -13910,7 +15328,7 @@ var SseMCPTransport = class {
|
|
|
13910
15328
|
this.endpoint = new URL(data, this.url);
|
|
13911
15329
|
if (this.endpoint.origin !== this.url.origin) throw new MCPClientError({ message: `MCP SSE Transport Error: Endpoint origin does not match connection origin: ${this.endpoint.origin}` });
|
|
13912
15330
|
this.connected = true;
|
|
13913
|
-
resolve();
|
|
15331
|
+
resolve$1();
|
|
13914
15332
|
} else if (event === "message") try {
|
|
13915
15333
|
const message = JSONRPCMessageSchema.parse(JSON.parse(data));
|
|
13916
15334
|
(_a18 = this.onmessage) == null || _a18.call(this, message);
|
|
@@ -14049,7 +15467,7 @@ var MCPClient = class {
|
|
|
14049
15467
|
}
|
|
14050
15468
|
}
|
|
14051
15469
|
async request({ request, resultSchema, options }) {
|
|
14052
|
-
return new Promise((resolve, reject) => {
|
|
15470
|
+
return new Promise((resolve$1, reject) => {
|
|
14053
15471
|
if (this.isClosed) return reject(new MCPClientError({ message: "Attempted to send a request from a closed client" }));
|
|
14054
15472
|
this.assertCapability(request.method);
|
|
14055
15473
|
const signal = options == null ? void 0 : options.signal;
|
|
@@ -14071,7 +15489,7 @@ var MCPClient = class {
|
|
|
14071
15489
|
if (response instanceof Error) return reject(response);
|
|
14072
15490
|
try {
|
|
14073
15491
|
const result = resultSchema.parse(response.result);
|
|
14074
|
-
resolve(result);
|
|
15492
|
+
resolve$1(result);
|
|
14075
15493
|
} catch (error) {
|
|
14076
15494
|
const parseError = new MCPClientError({
|
|
14077
15495
|
message: "Failed to parse server response",
|
|
@@ -14298,7 +15716,7 @@ function trimStartOfStream() {
|
|
|
14298
15716
|
var HANGING_STREAM_WARNING_TIME_MS = 15 * 1e3;
|
|
14299
15717
|
|
|
14300
15718
|
//#endregion
|
|
14301
|
-
//#region ../mcp-core/dist/callEmbeddedAgent
|
|
15719
|
+
//#region ../mcp-core/dist/callEmbeddedAgent--R3kwqbb.js
|
|
14302
15720
|
/**
|
|
14303
15721
|
* Call an embedded agent with tool call capture
|
|
14304
15722
|
* This is the standard way to call embedded AI agents within MCP tools
|
|
@@ -14309,22 +15727,20 @@ var HANGING_STREAM_WARNING_TIME_MS = 15 * 1e3;
|
|
|
14309
15727
|
*/
|
|
14310
15728
|
async function callEmbeddedAgent({ system, prompt, tools, schema }) {
|
|
14311
15729
|
const capturedToolCalls = [];
|
|
15730
|
+
const provider = getAgentProvider();
|
|
14312
15731
|
const result = await generateText({
|
|
14313
|
-
model:
|
|
15732
|
+
model: provider.getModel(),
|
|
14314
15733
|
system,
|
|
14315
15734
|
prompt,
|
|
14316
15735
|
tools,
|
|
14317
15736
|
maxSteps: 5,
|
|
14318
|
-
temperature:
|
|
15737
|
+
...provider.getTemperature() !== void 0 && { temperature: provider.getTemperature() },
|
|
14319
15738
|
experimental_output: output_exports.object({ schema }),
|
|
14320
15739
|
experimental_telemetry: {
|
|
14321
15740
|
isEnabled: true,
|
|
14322
15741
|
functionId: "callEmbeddedAgent"
|
|
14323
15742
|
},
|
|
14324
|
-
providerOptions:
|
|
14325
|
-
structuredOutputs: false,
|
|
14326
|
-
strictJsonSchema: false
|
|
14327
|
-
} },
|
|
15743
|
+
providerOptions: provider.getProviderOptions(),
|
|
14328
15744
|
onStepFinish: (event) => {
|
|
14329
15745
|
if (event.toolCalls && event.toolCalls.length > 0) for (const toolCall of event.toolCalls) capturedToolCalls.push({
|
|
14330
15746
|
toolName: toolCall.toolName,
|
|
@@ -14344,7 +15760,7 @@ async function callEmbeddedAgent({ system, prompt, tools, schema }) {
|
|
|
14344
15760
|
}
|
|
14345
15761
|
|
|
14346
15762
|
//#endregion
|
|
14347
|
-
//#region ../mcp-core/dist/utils-
|
|
15763
|
+
//#region ../mcp-core/dist/utils-BhgZ4dUB.js
|
|
14348
15764
|
/**
|
|
14349
15765
|
* Standard response schema for all embedded agent tools.
|
|
14350
15766
|
* Tools return either an error message or the result data, never both.
|
|
@@ -14426,7 +15842,7 @@ function agentTool(config) {
|
|
|
14426
15842
|
}
|
|
14427
15843
|
|
|
14428
15844
|
//#endregion
|
|
14429
|
-
//#region ../mcp-core/dist/otel-semantics-
|
|
15845
|
+
//#region ../mcp-core/dist/otel-semantics-B5qAIqUa.js
|
|
14430
15846
|
var namespace$72 = "android";
|
|
14431
15847
|
var description$72 = "The Android platform on which the Android application is running.\n";
|
|
14432
15848
|
var attributes$72 = {
|
|
@@ -19272,7 +20688,7 @@ function createOtelLookupTool(options) {
|
|
|
19272
20688
|
}
|
|
19273
20689
|
|
|
19274
20690
|
//#endregion
|
|
19275
|
-
//#region ../mcp-core/dist/whoami-
|
|
20691
|
+
//#region ../mcp-core/dist/whoami-CnHpsyv0.js
|
|
19276
20692
|
/**
|
|
19277
20693
|
* Get the current authenticated user's information from Sentry API
|
|
19278
20694
|
*/
|
|
@@ -19301,7 +20717,7 @@ function createWhoamiTool(options) {
|
|
|
19301
20717
|
}
|
|
19302
20718
|
|
|
19303
20719
|
//#endregion
|
|
19304
|
-
//#region ../mcp-core/dist/utils-
|
|
20720
|
+
//#region ../mcp-core/dist/utils-CRDu-UNV.js
|
|
19305
20721
|
function getStringValue(event, key, defaultValue = "") {
|
|
19306
20722
|
const value = event[key];
|
|
19307
20723
|
return typeof value === "string" ? value : defaultValue;
|
|
@@ -19354,7 +20770,7 @@ function createDatasetAttributesTool(options) {
|
|
|
19354
20770
|
"logs"
|
|
19355
20771
|
]).describe("The dataset to query attributes for") }),
|
|
19356
20772
|
execute: async ({ dataset }) => {
|
|
19357
|
-
const { BASE_COMMON_FIELDS, DATASET_FIELDS, RECOMMENDED_FIELDS: RECOMMENDED_FIELDS$2, NUMERIC_FIELDS, DATASET_EXAMPLES } = await import("./config-
|
|
20773
|
+
const { BASE_COMMON_FIELDS, DATASET_FIELDS, RECOMMENDED_FIELDS: RECOMMENDED_FIELDS$2, NUMERIC_FIELDS, DATASET_EXAMPLES } = await import("./config-HqPAzoGg.js");
|
|
19358
20774
|
const { attributes: customAttributes, fieldTypes } = await fetchCustomAttributes(apiService, organizationSlug, dataset, projectId);
|
|
19359
20775
|
const allFields = {
|
|
19360
20776
|
...BASE_COMMON_FIELDS,
|
|
@@ -19389,7 +20805,7 @@ Use these examples as patterns for constructing your query.`;
|
|
|
19389
20805
|
}
|
|
19390
20806
|
|
|
19391
20807
|
//#endregion
|
|
19392
|
-
//#region ../mcp-core/dist/agent-
|
|
20808
|
+
//#region ../mcp-core/dist/agent-C5-b2G06.js
|
|
19393
20809
|
const searchEventsAgentOutputSchema = z.object({
|
|
19394
20810
|
dataset: z.enum([
|
|
19395
20811
|
"spans",
|
|
@@ -19418,7 +20834,6 @@ const searchEventsAgentOutputSchema = z.object({
|
|
|
19418
20834
|
* This returns both the translated query result AND the tool calls made by the agent
|
|
19419
20835
|
*/
|
|
19420
20836
|
async function searchEventsAgent(options) {
|
|
19421
|
-
if (!process.env.OPENAI_API_KEY) throw new ConfigurationError("OPENAI_API_KEY environment variable is required for semantic search");
|
|
19422
20837
|
const datasetAttributesTool = createDatasetAttributesTool({
|
|
19423
20838
|
apiService: options.apiService,
|
|
19424
20839
|
organizationSlug: options.organizationSlug,
|
|
@@ -19443,7 +20858,7 @@ async function searchEventsAgent(options) {
|
|
|
19443
20858
|
}
|
|
19444
20859
|
|
|
19445
20860
|
//#endregion
|
|
19446
|
-
//#region ../mcp-core/dist/formatters-
|
|
20861
|
+
//#region ../mcp-core/dist/formatters-CJK-ciCF.js
|
|
19447
20862
|
/**
|
|
19448
20863
|
* Format an explanation for how a natural language query was translated
|
|
19449
20864
|
*/
|
|
@@ -19661,7 +21076,7 @@ function formatSpanResults(params) {
|
|
|
19661
21076
|
}
|
|
19662
21077
|
|
|
19663
21078
|
//#endregion
|
|
19664
|
-
//#region ../mcp-core/dist/handler-
|
|
21079
|
+
//#region ../mcp-core/dist/handler-BDtOWjBO.js
|
|
19665
21080
|
var handler_default = defineTool({
|
|
19666
21081
|
name: "search_events",
|
|
19667
21082
|
skills: [
|
|
@@ -19802,7 +21217,7 @@ var handler_default = defineTool({
|
|
|
19802
21217
|
});
|
|
19803
21218
|
|
|
19804
21219
|
//#endregion
|
|
19805
|
-
//#region ../mcp-core/dist/create-team-
|
|
21220
|
+
//#region ../mcp-core/dist/create-team-BNRuwaPN.js
|
|
19806
21221
|
var create_team_default = defineTool({
|
|
19807
21222
|
name: "create_team",
|
|
19808
21223
|
skills: ["project-management"],
|
|
@@ -19857,7 +21272,7 @@ var create_team_default = defineTool({
|
|
|
19857
21272
|
});
|
|
19858
21273
|
|
|
19859
21274
|
//#endregion
|
|
19860
|
-
//#region ../mcp-core/dist/create-project-
|
|
21275
|
+
//#region ../mcp-core/dist/create-project-CagAItcQ.js
|
|
19861
21276
|
var create_project_default = defineTool({
|
|
19862
21277
|
name: "create_project",
|
|
19863
21278
|
skills: ["project-management"],
|
|
@@ -19934,7 +21349,7 @@ var create_project_default = defineTool({
|
|
|
19934
21349
|
});
|
|
19935
21350
|
|
|
19936
21351
|
//#endregion
|
|
19937
|
-
//#region ../mcp-core/dist/update-project-
|
|
21352
|
+
//#region ../mcp-core/dist/update-project-C3HNKHy3.js
|
|
19938
21353
|
var update_project_default = defineTool({
|
|
19939
21354
|
name: "update_project",
|
|
19940
21355
|
skills: ["project-management"],
|
|
@@ -20052,7 +21467,7 @@ var update_project_default = defineTool({
|
|
|
20052
21467
|
});
|
|
20053
21468
|
|
|
20054
21469
|
//#endregion
|
|
20055
|
-
//#region ../mcp-core/dist/create-dsn-
|
|
21470
|
+
//#region ../mcp-core/dist/create-dsn-qX9dkWBv.js
|
|
20056
21471
|
var create_dsn_default = defineTool({
|
|
20057
21472
|
name: "create_dsn",
|
|
20058
21473
|
skills: ["project-management"],
|
|
@@ -20112,7 +21527,7 @@ var create_dsn_default = defineTool({
|
|
|
20112
21527
|
});
|
|
20113
21528
|
|
|
20114
21529
|
//#endregion
|
|
20115
|
-
//#region ../mcp-core/dist/find-dsns-
|
|
21530
|
+
//#region ../mcp-core/dist/find-dsns-DQL7wv5D.js
|
|
20116
21531
|
var find_dsns_default = defineTool({
|
|
20117
21532
|
name: "find_dsns",
|
|
20118
21533
|
skills: ["project-management"],
|
|
@@ -20163,7 +21578,7 @@ var find_dsns_default = defineTool({
|
|
|
20163
21578
|
});
|
|
20164
21579
|
|
|
20165
21580
|
//#endregion
|
|
20166
|
-
//#region ../mcp-core/dist/fetch-utils-
|
|
21581
|
+
//#region ../mcp-core/dist/fetch-utils-LjUGSOvJ.js
|
|
20167
21582
|
/**
|
|
20168
21583
|
* Fetch with timeout using AbortController
|
|
20169
21584
|
* @param url - The URL to fetch
|
|
@@ -20206,14 +21621,14 @@ async function retryWithBackoff(fn, { maxRetries = 3, initialDelay = 1e3, should
|
|
|
20206
21621
|
} catch (error) {
|
|
20207
21622
|
lastError = error;
|
|
20208
21623
|
if (attempt === maxRetries || !shouldRetry(error)) throw error;
|
|
20209
|
-
await new Promise((resolve) => setTimeout(resolve, delay$1));
|
|
21624
|
+
await new Promise((resolve$1) => setTimeout(resolve$1, delay$1));
|
|
20210
21625
|
delay$1 = Math.min(delay$1 * 2, 3e4);
|
|
20211
21626
|
}
|
|
20212
21627
|
throw lastError;
|
|
20213
21628
|
}
|
|
20214
21629
|
|
|
20215
21630
|
//#endregion
|
|
20216
|
-
//#region ../mcp-core/dist/analyze-issue-with-seer-
|
|
21631
|
+
//#region ../mcp-core/dist/analyze-issue-with-seer-B6aDeTwi.js
|
|
20217
21632
|
var analyze_issue_with_seer_default = defineTool({
|
|
20218
21633
|
name: "analyze_issue_with_seer",
|
|
20219
21634
|
skills: ["seer"],
|
|
@@ -20298,7 +21713,7 @@ var analyze_issue_with_seer_default = defineTool({
|
|
|
20298
21713
|
instruction: params.instruction
|
|
20299
21714
|
});
|
|
20300
21715
|
output += `Analysis started with Run ID: ${startResult.run_id}\n\n`;
|
|
20301
|
-
await new Promise((resolve) => setTimeout(resolve, 1e3));
|
|
21716
|
+
await new Promise((resolve$1) => setTimeout(resolve$1, 1e3));
|
|
20302
21717
|
autofixState = await retryWithBackoff(() => apiService.getAutofixState({
|
|
20303
21718
|
organizationSlug: orgSlug,
|
|
20304
21719
|
issueId: parsedIssueId
|
|
@@ -20355,7 +21770,7 @@ var analyze_issue_with_seer_default = defineTool({
|
|
|
20355
21770
|
if (activeStep) output += `Processing: ${activeStep.title}...\n`;
|
|
20356
21771
|
lastStatus = status;
|
|
20357
21772
|
}
|
|
20358
|
-
await new Promise((resolve) => setTimeout(resolve, SEER_POLLING_INTERVAL));
|
|
21773
|
+
await new Promise((resolve$1) => setTimeout(resolve$1, SEER_POLLING_INTERVAL));
|
|
20359
21774
|
try {
|
|
20360
21775
|
autofixState = await retryWithBackoff(() => apiService.getAutofixState({
|
|
20361
21776
|
organizationSlug: orgSlug,
|
|
@@ -20401,7 +21816,7 @@ var analyze_issue_with_seer_default = defineTool({
|
|
|
20401
21816
|
});
|
|
20402
21817
|
|
|
20403
21818
|
//#endregion
|
|
20404
|
-
//#region ../mcp-core/dist/search-docs-
|
|
21819
|
+
//#region ../mcp-core/dist/search-docs-yQc8o0ap.js
|
|
20405
21820
|
var search_docs_default = defineTool({
|
|
20406
21821
|
name: "search_docs",
|
|
20407
21822
|
skills: ["docs"],
|
|
@@ -20484,7 +21899,7 @@ var search_docs_default = defineTool({
|
|
|
20484
21899
|
});
|
|
20485
21900
|
|
|
20486
21901
|
//#endregion
|
|
20487
|
-
//#region ../mcp-core/dist/get-doc-
|
|
21902
|
+
//#region ../mcp-core/dist/get-doc-BuXsge2G.js
|
|
20488
21903
|
var get_doc_default = defineTool({
|
|
20489
21904
|
name: "get_doc",
|
|
20490
21905
|
skills: ["docs"],
|
|
@@ -20561,7 +21976,7 @@ var get_doc_default = defineTool({
|
|
|
20561
21976
|
});
|
|
20562
21977
|
|
|
20563
21978
|
//#endregion
|
|
20564
|
-
//#region ../mcp-core/dist/dataset-fields-
|
|
21979
|
+
//#region ../mcp-core/dist/dataset-fields-ClLuCTh4.js
|
|
20565
21980
|
/**
|
|
20566
21981
|
* Discover available fields for a dataset by querying Sentry's tags API
|
|
20567
21982
|
*/
|
|
@@ -20711,7 +22126,7 @@ function getCommonPatterns(dataset) {
|
|
|
20711
22126
|
}
|
|
20712
22127
|
|
|
20713
22128
|
//#endregion
|
|
20714
|
-
//#region ../mcp-core/dist/config-
|
|
22129
|
+
//#region ../mcp-core/dist/config-C3fctASk.js
|
|
20715
22130
|
/**
|
|
20716
22131
|
* Configuration for the search-issues agent
|
|
20717
22132
|
*/
|
|
@@ -20729,13 +22144,16 @@ BUILT-IN FIELDS:
|
|
|
20729
22144
|
- level: Severity level (error, warning, info, debug, fatal)
|
|
20730
22145
|
IMPORTANT: Almost NEVER use this field. Terms like "critical", "important", "severe" refer to IMPACT not level.
|
|
20731
22146
|
Only use if user explicitly says "error level", "warning level", etc.
|
|
22147
|
+
- issueCategory: Issue classification (error, performance, metric, feedback)
|
|
22148
|
+
IMPORTANT: User feedback from the User Feedback Widget is stored as issues with issueCategory:feedback
|
|
22149
|
+
Use this field when users ask about "user feedback", "feedback submissions", "user reports", etc.
|
|
20732
22150
|
- environment: Deployment environment (production, staging, development)
|
|
20733
22151
|
- release: Version/release identifier
|
|
20734
22152
|
- firstSeen: When the issue was FIRST encountered (use for "new issues", "started", "began")
|
|
20735
22153
|
WARNING: Excludes ongoing issues that started before the time window
|
|
20736
22154
|
- lastSeen: When the issue was LAST encountered (use for "from the last", "recent", "active")
|
|
20737
22155
|
This includes ALL issues seen during the time window, regardless of when they started
|
|
20738
|
-
- assigned: Issues explicitly assigned to a user (email or "me")
|
|
22156
|
+
- assigned: Issues explicitly assigned to a user (email or "me")
|
|
20739
22157
|
- assignedOrSuggested: Issues assigned to OR suggested for a user (broader match)
|
|
20740
22158
|
- userCount: Number of unique users affected
|
|
20741
22159
|
- eventCount: Total number of events
|
|
@@ -20747,6 +22165,9 @@ COMMON QUERY PATTERNS:
|
|
|
20747
22165
|
- New issues: firstSeen:-7d
|
|
20748
22166
|
- High impact: userCount:>100
|
|
20749
22167
|
- My work: assignedOrSuggested:me
|
|
22168
|
+
- User feedback: issueCategory:feedback
|
|
22169
|
+
- Recent feedback: issueCategory:feedback lastSeen:-7d
|
|
22170
|
+
- Feedback from production: issueCategory:feedback environment:production
|
|
20750
22171
|
|
|
20751
22172
|
SORTING RULES:
|
|
20752
22173
|
1. CRITICAL: Sort MUST go in the separate "sort" field, NEVER in the "query" field
|
|
@@ -20770,6 +22191,8 @@ EXAMPLES:
|
|
|
20770
22191
|
"critical bugs" → query: "level:error is:unresolved", sort: "date"
|
|
20771
22192
|
"worst issues affecting the most users" → query: "is:unresolved", sort: "user"
|
|
20772
22193
|
"assigned to john@example.com" → query: "assignedOrSuggested:john@example.com", sort: "date"
|
|
22194
|
+
"show me user feedback" → query: "issueCategory:feedback", sort: "date"
|
|
22195
|
+
"feedback from the last week" → query: "issueCategory:feedback lastSeen:-7d", sort: "date"
|
|
20773
22196
|
|
|
20774
22197
|
NEVER: query: "is:unresolved sort:user" ← Sort goes in separate field!
|
|
20775
22198
|
|
|
@@ -20783,7 +22206,7 @@ Always use the issueFields tool to discover available fields when needed.
|
|
|
20783
22206
|
Use the whoami tool when you need to resolve 'me' references.`;
|
|
20784
22207
|
|
|
20785
22208
|
//#endregion
|
|
20786
|
-
//#region ../mcp-core/dist/agent-
|
|
22209
|
+
//#region ../mcp-core/dist/agent-BDHlBFe8.js
|
|
20787
22210
|
const searchIssuesAgentOutputSchema = z.object({
|
|
20788
22211
|
query: z.string().describe("The Sentry issue search query"),
|
|
20789
22212
|
sort: z.enum([
|
|
@@ -20799,7 +22222,6 @@ const searchIssuesAgentOutputSchema = z.object({
|
|
|
20799
22222
|
* This returns both the translated query result AND the tool calls made by the agent
|
|
20800
22223
|
*/
|
|
20801
22224
|
async function searchIssuesAgent(options) {
|
|
20802
|
-
if (!process.env.OPENAI_API_KEY) throw new ConfigurationError("OPENAI_API_KEY environment variable is required for semantic search");
|
|
20803
22225
|
return await callEmbeddedAgent({
|
|
20804
22226
|
system: systemPrompt$3,
|
|
20805
22227
|
prompt: options.query,
|
|
@@ -20817,7 +22239,7 @@ async function searchIssuesAgent(options) {
|
|
|
20817
22239
|
}
|
|
20818
22240
|
|
|
20819
22241
|
//#endregion
|
|
20820
|
-
//#region ../mcp-core/dist/formatters-
|
|
22242
|
+
//#region ../mcp-core/dist/formatters-BcLCXcro.js
|
|
20821
22243
|
/**
|
|
20822
22244
|
* Format an explanation for how a natural language query was translated
|
|
20823
22245
|
*/
|
|
@@ -20860,6 +22282,7 @@ function formatIssueResults(params) {
|
|
|
20860
22282
|
output += `## ${index + 1}. [${issue.shortId}](${issueUrl})\n\n`;
|
|
20861
22283
|
output += `**${issue.title}**\n\n`;
|
|
20862
22284
|
output += `- **Status**: ${issue.status}\n`;
|
|
22285
|
+
if (issue.issueCategory && issue.issueCategory !== "error") output += `- **Category**: ${issue.issueCategory}\n`;
|
|
20863
22286
|
output += `- **Users**: ${issue.userCount || 0}\n`;
|
|
20864
22287
|
output += `- **Events**: ${issue.count || 0}\n`;
|
|
20865
22288
|
if (issue.assignedTo) {
|
|
@@ -20876,6 +22299,8 @@ function formatIssueResults(params) {
|
|
|
20876
22299
|
output += "- Get more details about a specific issue: Use the Issue ID with get_issue_details\n";
|
|
20877
22300
|
output += "- Update issue status: Use update_issue to resolve or assign issues\n";
|
|
20878
22301
|
output += "- View event counts: Use search_events for aggregated statistics\n";
|
|
22302
|
+
const hasFeedback = issues.some((i) => i.issueCategory === "feedback");
|
|
22303
|
+
if (hasFeedback) output += "- View feedback details: Use get_issue_details to see full feedback content and linked error events\n";
|
|
20879
22304
|
return output;
|
|
20880
22305
|
}
|
|
20881
22306
|
/**
|
|
@@ -20894,11 +22319,11 @@ function formatDate(dateString) {
|
|
|
20894
22319
|
if (diffHours < 24) return `${diffHours} hour${diffHours === 1 ? "" : "s"} ago`;
|
|
20895
22320
|
const diffDays = Math.floor(diffHours / 24);
|
|
20896
22321
|
if (diffDays < 30) return `${diffDays} day${diffDays === 1 ? "" : "s"} ago`;
|
|
20897
|
-
return date.
|
|
22322
|
+
return date.toISOString().split("T")[0];
|
|
20898
22323
|
}
|
|
20899
22324
|
|
|
20900
22325
|
//#endregion
|
|
20901
|
-
//#region ../mcp-core/dist/handler-
|
|
22326
|
+
//#region ../mcp-core/dist/handler-CzGXq51l.js
|
|
20902
22327
|
var handler_default$1 = defineTool({
|
|
20903
22328
|
name: "search_issues",
|
|
20904
22329
|
skills: [
|
|
@@ -20918,6 +22343,7 @@ var handler_default$1 = defineTool({
|
|
|
20918
22343
|
"- Filtered issue lists: 'unresolved issues', 'critical bugs'",
|
|
20919
22344
|
"- Issues by impact: 'errors affecting more than 100 users'",
|
|
20920
22345
|
"- Issues by assignment: 'issues assigned to me'",
|
|
22346
|
+
"- User feedback: 'show me user feedback', 'feedback from last week'",
|
|
20921
22347
|
"",
|
|
20922
22348
|
"DO NOT USE FOR COUNTS/AGGREGATIONS:",
|
|
20923
22349
|
"- 'how many errors' → use search_events",
|
|
@@ -20935,6 +22361,7 @@ var handler_default$1 = defineTool({
|
|
|
20935
22361
|
"search_issues(organizationSlug='my-org', naturalLanguageQuery='critical bugs from last week')",
|
|
20936
22362
|
"search_issues(organizationSlug='my-org', naturalLanguageQuery='unhandled errors affecting 100+ users')",
|
|
20937
22363
|
"search_issues(organizationSlug='my-org', naturalLanguageQuery='issues assigned to me')",
|
|
22364
|
+
"search_issues(organizationSlug='my-org', naturalLanguageQuery='user feedback from production')",
|
|
20938
22365
|
"</examples>",
|
|
20939
22366
|
"",
|
|
20940
22367
|
"<hints>",
|
|
@@ -21019,7 +22446,7 @@ var handler_default$1 = defineTool({
|
|
|
21019
22446
|
});
|
|
21020
22447
|
|
|
21021
22448
|
//#endregion
|
|
21022
|
-
//#region ../mcp-core/dist/config-
|
|
22449
|
+
//#region ../mcp-core/dist/config-mlP4H0sA.js
|
|
21023
22450
|
const systemPrompt$2 = `You are a Sentry issue event filter translator. Your job is to:
|
|
21024
22451
|
1. Translate natural language queries into Sentry tag filters for events within a SPECIFIC issue
|
|
21025
22452
|
2. Select appropriate fields to return in the results
|
|
@@ -21354,7 +22781,7 @@ const EXAMPLE_QUERIES = [
|
|
|
21354
22781
|
];
|
|
21355
22782
|
|
|
21356
22783
|
//#endregion
|
|
21357
|
-
//#region ../mcp-core/dist/utils-
|
|
22784
|
+
//#region ../mcp-core/dist/utils-D8xperPO.js
|
|
21358
22785
|
/**
|
|
21359
22786
|
* Create a tool for the agent to query available tags and fields for issue events
|
|
21360
22787
|
* The tool is pre-bound with the API service and organization configured for the appropriate region
|
|
@@ -21431,7 +22858,7 @@ Received: ${params.issueUrl}`);
|
|
|
21431
22858
|
}
|
|
21432
22859
|
|
|
21433
22860
|
//#endregion
|
|
21434
|
-
//#region ../mcp-core/dist/agent-
|
|
22861
|
+
//#region ../mcp-core/dist/agent-zpc_iP4u.js
|
|
21435
22862
|
const searchIssueEventsAgentOutputSchema = z.object({
|
|
21436
22863
|
query: z.string().describe("Sentry query filters for tags/fields (NOT including issue: prefix - handler adds that)"),
|
|
21437
22864
|
fields: z.array(z.string()).describe("Array of field names to return in results"),
|
|
@@ -21455,7 +22882,6 @@ const searchIssueEventsAgentOutputSchema = z.object({
|
|
|
21455
22882
|
* Returns both the translated query result AND the tool calls made by the agent
|
|
21456
22883
|
*/
|
|
21457
22884
|
async function searchIssueEventsAgent(options) {
|
|
21458
|
-
if (!process.env.OPENAI_API_KEY) throw new ConfigurationError("OPENAI_API_KEY environment variable is required for natural language query translation");
|
|
21459
22885
|
const issueEventFieldsTool = createIssueEventFieldsTool({
|
|
21460
22886
|
apiService: options.apiService,
|
|
21461
22887
|
organizationSlug: options.organizationSlug,
|
|
@@ -21474,7 +22900,7 @@ async function searchIssueEventsAgent(options) {
|
|
|
21474
22900
|
}
|
|
21475
22901
|
|
|
21476
22902
|
//#endregion
|
|
21477
|
-
//#region ../mcp-core/dist/handler-
|
|
22903
|
+
//#region ../mcp-core/dist/handler-9NRJi9hO.js
|
|
21478
22904
|
var handler_default$2 = defineTool({
|
|
21479
22905
|
name: "search_issue_events",
|
|
21480
22906
|
skills: ["inspect", "triage"],
|
|
@@ -21576,7 +23002,7 @@ var handler_default$2 = defineTool({
|
|
|
21576
23002
|
});
|
|
21577
23003
|
|
|
21578
23004
|
//#endregion
|
|
21579
|
-
//#region ../mcp-core/dist/config-
|
|
23005
|
+
//#region ../mcp-core/dist/config-BJzhfINu.js
|
|
21580
23006
|
/**
|
|
21581
23007
|
* Configuration for the use_sentry embedded agent.
|
|
21582
23008
|
*
|
|
@@ -21595,7 +23021,7 @@ The user may include various parameters to pass to those tools in their prompt.
|
|
|
21595
23021
|
You MUST return tool results directly without interpreting them.`;
|
|
21596
23022
|
|
|
21597
23023
|
//#endregion
|
|
21598
|
-
//#region ../mcp-core/dist/agent-
|
|
23024
|
+
//#region ../mcp-core/dist/agent-C0SOl71m.js
|
|
21599
23025
|
/**
|
|
21600
23026
|
* Output schema for the embedded agent.
|
|
21601
23027
|
* The agent returns the final result string directly from its tool calls.
|
|
@@ -21606,7 +23032,6 @@ const outputSchema = z.object({ result: z.string().describe("The final result fr
|
|
|
21606
23032
|
* This returns the final result AND the tool calls made by the agent
|
|
21607
23033
|
*/
|
|
21608
23034
|
async function useSentryAgent(options) {
|
|
21609
|
-
if (!process.env.OPENAI_API_KEY) throw new ConfigurationError("OPENAI_API_KEY environment variable is required for use_sentry tool");
|
|
21610
23035
|
const prompt = options.request;
|
|
21611
23036
|
return await callEmbeddedAgent({
|
|
21612
23037
|
system: systemPrompt$1,
|
|
@@ -21617,7 +23042,296 @@ async function useSentryAgent(options) {
|
|
|
21617
23042
|
}
|
|
21618
23043
|
|
|
21619
23044
|
//#endregion
|
|
21620
|
-
//#region ../mcp-core/dist/
|
|
23045
|
+
//#region ../mcp-core/dist/list-issues-DSk9smZ1.js
|
|
23046
|
+
var list_issues_default = defineTool({
|
|
23047
|
+
name: "list_issues",
|
|
23048
|
+
skills: [
|
|
23049
|
+
"inspect",
|
|
23050
|
+
"triage",
|
|
23051
|
+
"seer"
|
|
23052
|
+
],
|
|
23053
|
+
requiredScopes: ["event:read"],
|
|
23054
|
+
description: [
|
|
23055
|
+
"List issues using Sentry query syntax directly (no AI/LLM required).",
|
|
23056
|
+
"",
|
|
23057
|
+
"Use this tool when:",
|
|
23058
|
+
"- You know Sentry query syntax already",
|
|
23059
|
+
"- AI-powered search is unavailable (no OPENAI_API_KEY or ANTHROPIC_API_KEY)",
|
|
23060
|
+
"- You want precise control over the query",
|
|
23061
|
+
"",
|
|
23062
|
+
"For natural language queries, use search_issues instead.",
|
|
23063
|
+
"",
|
|
23064
|
+
"Common Query Syntax:",
|
|
23065
|
+
"- is:unresolved - Show unresolved issues only",
|
|
23066
|
+
"- is:unassigned - Show unassigned issues",
|
|
23067
|
+
"- level:error - Filter by error level",
|
|
23068
|
+
"- firstSeen:-24h - First seen in last 24 hours",
|
|
23069
|
+
"- lastSeen:-1h - Last seen in last hour",
|
|
23070
|
+
"- has:user - Issues with user context",
|
|
23071
|
+
"- user.email:user@example.com - Filter by user email",
|
|
23072
|
+
"- environment:production - Filter by environment",
|
|
23073
|
+
"- release:1.0.0 - Filter by release version",
|
|
23074
|
+
"",
|
|
23075
|
+
"Combine queries: is:unresolved is:unassigned level:error",
|
|
23076
|
+
"",
|
|
23077
|
+
"<examples>",
|
|
23078
|
+
"list_issues(organizationSlug='my-org', query='is:unresolved is:unassigned')",
|
|
23079
|
+
"list_issues(organizationSlug='my-org', query='level:error firstSeen:-24h', sort='freq')",
|
|
23080
|
+
"list_issues(organizationSlug='my-org', projectSlugOrId='my-project', query='is:unresolved')",
|
|
23081
|
+
"</examples>",
|
|
23082
|
+
"",
|
|
23083
|
+
"<hints>",
|
|
23084
|
+
"- If the user passes a parameter in the form of name/otherName, it's likely in the format of <organizationSlug>/<projectSlugOrId>.",
|
|
23085
|
+
"- The projectSlugOrId parameter accepts both project slugs (e.g., 'my-project') and numeric IDs (e.g., '123456').",
|
|
23086
|
+
"</hints>"
|
|
23087
|
+
].join("\n"),
|
|
23088
|
+
inputSchema: {
|
|
23089
|
+
organizationSlug: ParamOrganizationSlug,
|
|
23090
|
+
query: z.string().trim().default("is:unresolved").describe("Sentry issue search query syntax"),
|
|
23091
|
+
projectSlugOrId: z.string().toLowerCase().trim().superRefine(validateSlugOrId).nullable().default(null).describe("Filter by project slug or numeric ID (optional)"),
|
|
23092
|
+
sort: z.enum([
|
|
23093
|
+
"date",
|
|
23094
|
+
"freq",
|
|
23095
|
+
"new",
|
|
23096
|
+
"user"
|
|
23097
|
+
]).default("date").describe("Sort order: date (last seen), freq (frequency), new (first seen), user (user count)"),
|
|
23098
|
+
limit: z.number().min(1).max(100).default(10).describe("Maximum number of issues to return (1-100)"),
|
|
23099
|
+
regionUrl: ParamRegionUrl.nullable().default(null)
|
|
23100
|
+
},
|
|
23101
|
+
annotations: {
|
|
23102
|
+
readOnlyHint: true,
|
|
23103
|
+
openWorldHint: true
|
|
23104
|
+
},
|
|
23105
|
+
async handler(params, context$1) {
|
|
23106
|
+
const apiService = apiServiceFromContext(context$1, { regionUrl: params.regionUrl ?? void 0 });
|
|
23107
|
+
setTag("organization.slug", params.organizationSlug);
|
|
23108
|
+
if (params.projectSlugOrId) if (isNumericId(params.projectSlugOrId)) setTag("project.id", params.projectSlugOrId);
|
|
23109
|
+
else setTag("project.slug", params.projectSlugOrId);
|
|
23110
|
+
const issues = await apiService.listIssues({
|
|
23111
|
+
organizationSlug: params.organizationSlug,
|
|
23112
|
+
projectSlug: params.projectSlugOrId ?? void 0,
|
|
23113
|
+
query: params.query,
|
|
23114
|
+
sortBy: params.sort,
|
|
23115
|
+
limit: params.limit
|
|
23116
|
+
});
|
|
23117
|
+
return formatIssueResults({
|
|
23118
|
+
issues,
|
|
23119
|
+
organizationSlug: params.organizationSlug,
|
|
23120
|
+
projectSlugOrId: params.projectSlugOrId ?? void 0,
|
|
23121
|
+
query: params.query,
|
|
23122
|
+
regionUrl: params.regionUrl ?? void 0
|
|
23123
|
+
});
|
|
23124
|
+
}
|
|
23125
|
+
});
|
|
23126
|
+
|
|
23127
|
+
//#endregion
|
|
23128
|
+
//#region ../mcp-core/dist/list-events-BVY0RUTR.js
|
|
23129
|
+
const DEFAULT_FIELDS = {
|
|
23130
|
+
errors: RECOMMENDED_FIELDS.errors.basic,
|
|
23131
|
+
logs: RECOMMENDED_FIELDS.logs.basic,
|
|
23132
|
+
spans: RECOMMENDED_FIELDS.spans.basic
|
|
23133
|
+
};
|
|
23134
|
+
var list_events_default = defineTool({
|
|
23135
|
+
name: "list_events",
|
|
23136
|
+
skills: [
|
|
23137
|
+
"inspect",
|
|
23138
|
+
"triage",
|
|
23139
|
+
"seer"
|
|
23140
|
+
],
|
|
23141
|
+
requiredScopes: ["event:read"],
|
|
23142
|
+
description: [
|
|
23143
|
+
"Search events using Sentry query syntax directly (no AI/LLM required).",
|
|
23144
|
+
"",
|
|
23145
|
+
"Use this tool when:",
|
|
23146
|
+
"- You know Sentry query syntax already",
|
|
23147
|
+
"- AI-powered search is unavailable (no OPENAI_API_KEY or ANTHROPIC_API_KEY)",
|
|
23148
|
+
"- You want precise control over the query",
|
|
23149
|
+
"",
|
|
23150
|
+
"For natural language queries, use search_events instead.",
|
|
23151
|
+
"",
|
|
23152
|
+
"Datasets:",
|
|
23153
|
+
"- errors: Exception/crash events",
|
|
23154
|
+
"- logs: Log entries",
|
|
23155
|
+
"- spans: Performance data, traces, AI/LLM calls",
|
|
23156
|
+
"",
|
|
23157
|
+
"Query Syntax Examples:",
|
|
23158
|
+
"- message:\"connection timeout\"",
|
|
23159
|
+
"- level:error",
|
|
23160
|
+
"- span.op:http.client span.status_code:500",
|
|
23161
|
+
"- log.level:error",
|
|
23162
|
+
"- transaction:/api/users",
|
|
23163
|
+
"",
|
|
23164
|
+
"<examples>",
|
|
23165
|
+
"list_events(organizationSlug='my-org', dataset='errors', query='level:error')",
|
|
23166
|
+
"list_events(organizationSlug='my-org', dataset='spans', query='span.op:db')",
|
|
23167
|
+
"list_events(organizationSlug='my-org', dataset='logs', query='severity:error')",
|
|
23168
|
+
"list_events(organizationSlug='my-org', dataset='errors', fields=['issue', 'count()'], sort='-count()')",
|
|
23169
|
+
"</examples>",
|
|
23170
|
+
"",
|
|
23171
|
+
"<hints>",
|
|
23172
|
+
"- If the user passes a parameter in the form of name/otherName, it's likely in the format of <organizationSlug>/<projectSlug>.",
|
|
23173
|
+
"- Use fields with aggregate functions like count(), avg(), sum() for statistics",
|
|
23174
|
+
"- Sort by -count() for most common, -timestamp for newest",
|
|
23175
|
+
"</hints>"
|
|
23176
|
+
].join("\n"),
|
|
23177
|
+
inputSchema: {
|
|
23178
|
+
organizationSlug: ParamOrganizationSlug,
|
|
23179
|
+
dataset: z.enum([
|
|
23180
|
+
"errors",
|
|
23181
|
+
"logs",
|
|
23182
|
+
"spans"
|
|
23183
|
+
]).default("errors").describe("Dataset to query: errors (exceptions), logs, or spans (traces)"),
|
|
23184
|
+
query: z.string().trim().default("").describe("Sentry event search query syntax (empty for all events)"),
|
|
23185
|
+
fields: z.array(z.string()).nullable().default(null).describe("Fields to return. If not specified, uses sensible defaults. Include aggregate functions like count(), avg() for statistics."),
|
|
23186
|
+
sort: z.string().default("-timestamp").describe("Sort field (prefix with - for descending). Use -count() for aggregations."),
|
|
23187
|
+
projectSlug: ParamProjectSlug.nullable().default(null),
|
|
23188
|
+
statsPeriod: z.string().default("14d").describe("Time period: 1h, 24h, 7d, 14d, 30d, etc."),
|
|
23189
|
+
limit: z.number().min(1).max(100).default(10).describe("Maximum number of results to return (1-100)"),
|
|
23190
|
+
regionUrl: ParamRegionUrl.nullable().default(null)
|
|
23191
|
+
},
|
|
23192
|
+
annotations: {
|
|
23193
|
+
readOnlyHint: true,
|
|
23194
|
+
openWorldHint: true
|
|
23195
|
+
},
|
|
23196
|
+
async handler(params, context$1) {
|
|
23197
|
+
const apiService = apiServiceFromContext(context$1, { regionUrl: params.regionUrl ?? void 0 });
|
|
23198
|
+
setTag("organization.slug", params.organizationSlug);
|
|
23199
|
+
if (params.projectSlug) setTag("project.slug", params.projectSlug);
|
|
23200
|
+
let projectId;
|
|
23201
|
+
if (params.projectSlug) {
|
|
23202
|
+
const project = await apiService.getProject({
|
|
23203
|
+
organizationSlug: params.organizationSlug,
|
|
23204
|
+
projectSlugOrId: params.projectSlug
|
|
23205
|
+
});
|
|
23206
|
+
projectId = String(project.id);
|
|
23207
|
+
}
|
|
23208
|
+
const fields = params.fields ?? DEFAULT_FIELDS[params.dataset];
|
|
23209
|
+
const eventsResponse = await apiService.searchEvents({
|
|
23210
|
+
organizationSlug: params.organizationSlug,
|
|
23211
|
+
query: params.query,
|
|
23212
|
+
fields,
|
|
23213
|
+
limit: params.limit,
|
|
23214
|
+
projectId,
|
|
23215
|
+
dataset: params.dataset,
|
|
23216
|
+
sort: params.sort,
|
|
23217
|
+
statsPeriod: params.statsPeriod
|
|
23218
|
+
});
|
|
23219
|
+
function isValidResponse(response) {
|
|
23220
|
+
return typeof response === "object" && response !== null;
|
|
23221
|
+
}
|
|
23222
|
+
function isValidEventArray(data) {
|
|
23223
|
+
return Array.isArray(data) && data.every((item) => typeof item === "object" && item !== null);
|
|
23224
|
+
}
|
|
23225
|
+
if (!isValidResponse(eventsResponse)) throw new Error("Invalid response format from Sentry API");
|
|
23226
|
+
const eventData = eventsResponse.data;
|
|
23227
|
+
if (!isValidEventArray(eventData)) throw new Error("Invalid event data format from Sentry API");
|
|
23228
|
+
const aggregateFunctions = fields.filter((field) => field.includes("(") && field.includes(")"));
|
|
23229
|
+
const groupByFields = fields.filter((field) => !field.includes("(") && !field.includes(")"));
|
|
23230
|
+
const explorerUrl = apiService.getEventsExplorerUrl(params.organizationSlug, params.query, projectId, params.dataset, fields, params.sort, aggregateFunctions, groupByFields, params.statsPeriod);
|
|
23231
|
+
const formatParams = {
|
|
23232
|
+
eventData,
|
|
23233
|
+
naturalLanguageQuery: params.query || `${params.dataset} events`,
|
|
23234
|
+
includeExplanation: false,
|
|
23235
|
+
apiService,
|
|
23236
|
+
organizationSlug: params.organizationSlug,
|
|
23237
|
+
explorerUrl,
|
|
23238
|
+
sentryQuery: params.query,
|
|
23239
|
+
fields
|
|
23240
|
+
};
|
|
23241
|
+
switch (params.dataset) {
|
|
23242
|
+
case "errors": return formatErrorResults(formatParams);
|
|
23243
|
+
case "logs": return formatLogResults(formatParams);
|
|
23244
|
+
case "spans": return formatSpanResults(formatParams);
|
|
23245
|
+
}
|
|
23246
|
+
}
|
|
23247
|
+
});
|
|
23248
|
+
|
|
23249
|
+
//#endregion
|
|
23250
|
+
//#region ../mcp-core/dist/list-issue-events-BOIBq62n.js
|
|
23251
|
+
var list_issue_events_default = defineTool({
|
|
23252
|
+
name: "list_issue_events",
|
|
23253
|
+
skills: ["inspect", "triage"],
|
|
23254
|
+
requiredScopes: ["event:read"],
|
|
23255
|
+
description: [
|
|
23256
|
+
"List events within a specific issue using Sentry query syntax (no AI/LLM required).",
|
|
23257
|
+
"",
|
|
23258
|
+
"Use this tool when:",
|
|
23259
|
+
"- You know Sentry query syntax already",
|
|
23260
|
+
"- AI-powered search is unavailable (no OPENAI_API_KEY or ANTHROPIC_API_KEY)",
|
|
23261
|
+
"- You want precise control over the query",
|
|
23262
|
+
"",
|
|
23263
|
+
"For natural language queries, use search_issue_events instead.",
|
|
23264
|
+
"",
|
|
23265
|
+
"Common Query Filters:",
|
|
23266
|
+
"- environment:production - Filter by environment",
|
|
23267
|
+
"- release:1.0.0 - Filter by release version",
|
|
23268
|
+
"- user.email:alice@example.com - Filter by user email",
|
|
23269
|
+
"- timestamp:>2024-01-01 - Filter by timestamp",
|
|
23270
|
+
"",
|
|
23271
|
+
"<examples>",
|
|
23272
|
+
"list_issue_events(issueUrl='https://sentry.io/organizations/my-org/issues/123/', query='environment:production')",
|
|
23273
|
+
"list_issue_events(issueId='MCP-41', organizationSlug='my-org', query='release:v1.0.0')",
|
|
23274
|
+
"list_issue_events(issueId='PROJECT-123', organizationSlug='my-org', statsPeriod='1h')",
|
|
23275
|
+
"</examples>",
|
|
23276
|
+
"",
|
|
23277
|
+
"<hints>",
|
|
23278
|
+
"- Use issueUrl for convenience (includes org + issue ID)",
|
|
23279
|
+
"- Or provide both issueId and organizationSlug",
|
|
23280
|
+
"- The query filters events WITHIN the issue, no need for issue: prefix",
|
|
23281
|
+
"</hints>"
|
|
23282
|
+
].join("\n"),
|
|
23283
|
+
inputSchema: {
|
|
23284
|
+
organizationSlug: ParamOrganizationSlug.nullable().default(null).describe("Organization slug. Required when using issueId. Not needed when using issueUrl."),
|
|
23285
|
+
issueId: z.string().optional().describe("Issue ID (e.g., 'MCP-41', 'PROJECT-123'). Requires organizationSlug."),
|
|
23286
|
+
issueUrl: z.string().url().optional().describe("Full Sentry issue URL. Includes both organization and issue ID."),
|
|
23287
|
+
query: z.string().trim().default("").describe("Sentry event search query syntax (empty for all events)"),
|
|
23288
|
+
sort: z.string().default("-timestamp").describe("Sort field (prefix with - for descending). Default: -timestamp"),
|
|
23289
|
+
statsPeriod: z.string().default("14d").describe("Time period: 1h, 24h, 7d, 14d, 30d, etc."),
|
|
23290
|
+
limit: z.number().min(1).max(100).default(50).describe("Maximum number of events to return (1-100)"),
|
|
23291
|
+
regionUrl: ParamRegionUrl.nullable().default(null)
|
|
23292
|
+
},
|
|
23293
|
+
annotations: {
|
|
23294
|
+
readOnlyHint: true,
|
|
23295
|
+
openWorldHint: true
|
|
23296
|
+
},
|
|
23297
|
+
async handler(params, context$1) {
|
|
23298
|
+
const { organizationSlug, issueId } = parseIssueParams({
|
|
23299
|
+
organizationSlug: params.organizationSlug,
|
|
23300
|
+
issueId: params.issueId,
|
|
23301
|
+
issueUrl: params.issueUrl
|
|
23302
|
+
});
|
|
23303
|
+
const apiService = apiServiceFromContext(context$1, { regionUrl: params.regionUrl ?? void 0 });
|
|
23304
|
+
setTag("organization.slug", organizationSlug);
|
|
23305
|
+
setTag("issue.id", issueId);
|
|
23306
|
+
const eventsResponse = await apiService.listEventsForIssue({
|
|
23307
|
+
organizationSlug,
|
|
23308
|
+
issueId,
|
|
23309
|
+
query: params.query,
|
|
23310
|
+
limit: params.limit,
|
|
23311
|
+
sort: params.sort,
|
|
23312
|
+
statsPeriod: params.statsPeriod
|
|
23313
|
+
});
|
|
23314
|
+
function isValidEventArray(data) {
|
|
23315
|
+
return Array.isArray(data) && data.every((item) => typeof item === "object" && item !== null);
|
|
23316
|
+
}
|
|
23317
|
+
if (!isValidEventArray(eventsResponse)) throw new Error("Invalid event data format from Sentry API: expected array of objects");
|
|
23318
|
+
const explorerQuery = params.query ? `issue:${issueId} ${params.query}` : `issue:${issueId}`;
|
|
23319
|
+
const explorerUrl = apiService.getEventsExplorerUrl(organizationSlug, explorerQuery, void 0, "errors", RECOMMENDED_FIELDS$1, params.sort, [], [], params.statsPeriod);
|
|
23320
|
+
return formatErrorResults({
|
|
23321
|
+
eventData: eventsResponse,
|
|
23322
|
+
naturalLanguageQuery: `Events in issue ${issueId}`,
|
|
23323
|
+
includeExplanation: false,
|
|
23324
|
+
apiService,
|
|
23325
|
+
organizationSlug,
|
|
23326
|
+
explorerUrl,
|
|
23327
|
+
sentryQuery: explorerQuery,
|
|
23328
|
+
fields: RECOMMENDED_FIELDS$1
|
|
23329
|
+
});
|
|
23330
|
+
}
|
|
23331
|
+
});
|
|
23332
|
+
|
|
23333
|
+
//#endregion
|
|
23334
|
+
//#region ../mcp-core/dist/error-handling-DFJ-iOAP.js
|
|
21621
23335
|
/**
|
|
21622
23336
|
* Type guard to identify user input validation errors.
|
|
21623
23337
|
*/
|
|
@@ -21708,7 +23422,7 @@ async function formatErrorForUser(error) {
|
|
|
21708
23422
|
}
|
|
21709
23423
|
|
|
21710
23424
|
//#endregion
|
|
21711
|
-
//#region ../mcp-core/dist/constraint-helpers-
|
|
23425
|
+
//#region ../mcp-core/dist/constraint-helpers-D80X658i.js
|
|
21712
23426
|
/**
|
|
21713
23427
|
* Determines which tool parameter keys should be filtered out of the schema
|
|
21714
23428
|
* because they will be injected from constraints.
|
|
@@ -21770,7 +23484,7 @@ function getConstraintParametersToInject(constraints, toolInputSchema) {
|
|
|
21770
23484
|
}
|
|
21771
23485
|
|
|
21772
23486
|
//#endregion
|
|
21773
|
-
//#region ../mcp-core/dist/server-
|
|
23487
|
+
//#region ../mcp-core/dist/server-obGNre-1.js
|
|
21774
23488
|
/**
|
|
21775
23489
|
* Format tool calls into a readable trace
|
|
21776
23490
|
*/
|
|
@@ -21832,7 +23546,8 @@ var handler_default$3 = defineTool({
|
|
|
21832
23546
|
},
|
|
21833
23547
|
async handler(params, context$1) {
|
|
21834
23548
|
const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair();
|
|
21835
|
-
const
|
|
23549
|
+
const toolsToExclude = new Set(["use_sentry", ...SIMPLE_REPLACEMENT_TOOLS]);
|
|
23550
|
+
const toolsForAgent = Object.fromEntries(Object.entries(tools_default).filter(([key]) => !toolsToExclude.has(key)));
|
|
21836
23551
|
const server$1 = buildServer({
|
|
21837
23552
|
context: context$1,
|
|
21838
23553
|
tools: toolsForAgent
|
|
@@ -21860,6 +23575,25 @@ var handler_default$3 = defineTool({
|
|
|
21860
23575
|
}
|
|
21861
23576
|
}
|
|
21862
23577
|
});
|
|
23578
|
+
/**
|
|
23579
|
+
* Tools that require an embedded agent provider (LLM-powered).
|
|
23580
|
+
* These are excluded when no agent provider is configured.
|
|
23581
|
+
* Note: use_sentry is handled separately via agentMode.
|
|
23582
|
+
*/
|
|
23583
|
+
const AGENT_DEPENDENT_TOOLS = [
|
|
23584
|
+
"search_events",
|
|
23585
|
+
"search_issues",
|
|
23586
|
+
"search_issue_events"
|
|
23587
|
+
];
|
|
23588
|
+
/**
|
|
23589
|
+
* Simple tools that replace agent-dependent tools when no provider is available.
|
|
23590
|
+
* These are excluded when an agent provider IS configured.
|
|
23591
|
+
*/
|
|
23592
|
+
const SIMPLE_REPLACEMENT_TOOLS = [
|
|
23593
|
+
"list_issues",
|
|
23594
|
+
"list_events",
|
|
23595
|
+
"list_issue_events"
|
|
23596
|
+
];
|
|
21863
23597
|
var tools_default = {
|
|
21864
23598
|
whoami: whoami_default,
|
|
21865
23599
|
find_organizations: find_organizations_default,
|
|
@@ -21867,6 +23601,7 @@ var tools_default = {
|
|
|
21867
23601
|
find_projects: find_projects_default,
|
|
21868
23602
|
find_releases: find_releases_default,
|
|
21869
23603
|
get_issue_details: get_issue_details_default,
|
|
23604
|
+
get_issue_tag_values: get_issue_tag_values_default,
|
|
21870
23605
|
get_trace_details: get_trace_details_default,
|
|
21871
23606
|
get_event_attachment: get_event_attachment_default,
|
|
21872
23607
|
update_issue: update_issue_default,
|
|
@@ -21881,7 +23616,10 @@ var tools_default = {
|
|
|
21881
23616
|
get_doc: get_doc_default,
|
|
21882
23617
|
search_issues: handler_default$1,
|
|
21883
23618
|
search_issue_events: handler_default$2,
|
|
21884
|
-
use_sentry: handler_default$3
|
|
23619
|
+
use_sentry: handler_default$3,
|
|
23620
|
+
list_issues: list_issues_default,
|
|
23621
|
+
list_events: list_events_default,
|
|
23622
|
+
list_issue_events: list_issue_events_default
|
|
21885
23623
|
};
|
|
21886
23624
|
/**
|
|
21887
23625
|
* Creates and configures a complete MCP server with Sentry instrumentation.
|
|
@@ -21942,7 +23680,12 @@ function buildServer({ context: context$1, agentMode = false, tools: customTools
|
|
|
21942
23680
|
* In agent mode, only the use_sentry tool is registered, bypassing authorization checks.
|
|
21943
23681
|
*/
|
|
21944
23682
|
function configureServer({ server: server$1, context: context$1, agentMode = false, tools: customTools }) {
|
|
21945
|
-
|
|
23683
|
+
let toolsToRegister = agentMode ? { use_sentry: tools_default.use_sentry } : customTools ?? tools_default;
|
|
23684
|
+
if (!agentMode && !customTools) {
|
|
23685
|
+
const hasAgent = hasAgentProvider();
|
|
23686
|
+
const toolsToExclude = new Set(hasAgent ? SIMPLE_REPLACEMENT_TOOLS : AGENT_DEPENDENT_TOOLS);
|
|
23687
|
+
toolsToRegister = Object.fromEntries(Object.entries(toolsToRegister).filter(([key]) => !toolsToExclude.has(key)));
|
|
23688
|
+
}
|
|
21946
23689
|
const grantedSkills = context$1.grantedSkills ? new Set(context$1.grantedSkills) : void 0;
|
|
21947
23690
|
server$1.server.onerror = (error) => {
|
|
21948
23691
|
const transportLogOptions = {
|
|
@@ -22023,7 +23766,7 @@ function configureServer({ server: server$1, context: context$1, agentMode = fal
|
|
|
22023
23766
|
}
|
|
22024
23767
|
|
|
22025
23768
|
//#endregion
|
|
22026
|
-
//#region ../mcp-core/dist/sentry-
|
|
23769
|
+
//#region ../mcp-core/dist/sentry-CTKJG5Bs.js
|
|
22027
23770
|
const SCRUB_PATTERNS = [
|
|
22028
23771
|
{
|
|
22029
23772
|
pattern: /\bsk-[a-zA-Z0-9]{48}\b/g,
|
|
@@ -22114,8 +23857,11 @@ function scrubValue(value, depth = 0) {
|
|
|
22114
23857
|
}
|
|
22115
23858
|
/**
|
|
22116
23859
|
* Sentry beforeSend hook that scrubs sensitive data from events
|
|
23860
|
+
* and applies custom fingerprinting for specific error types.
|
|
22117
23861
|
*/
|
|
22118
23862
|
function sentryBeforeSend(event, hint) {
|
|
23863
|
+
const firstException = event?.exception?.values?.[0];
|
|
23864
|
+
if (firstException?.type === "AI_APICallError" && firstException.value) event.fingerprint = ["AI_APICallError", firstException.value];
|
|
22119
23865
|
const [scrubbedEvent, didScrub, descriptions] = scrubValue(event);
|
|
22120
23866
|
if (didScrub) {
|
|
22121
23867
|
const uniqueDescriptions = [...new Set(descriptions)];
|
|
@@ -22156,16 +23902,21 @@ const cfg = (() => {
|
|
|
22156
23902
|
die(err instanceof Error ? err.message : String(err));
|
|
22157
23903
|
}
|
|
22158
23904
|
})();
|
|
22159
|
-
if (
|
|
22160
|
-
|
|
23905
|
+
if (cfg.agentProvider) setAgentProvider(cfg.agentProvider);
|
|
23906
|
+
setProviderBaseUrls({
|
|
23907
|
+
openaiBaseUrl: cfg.openaiBaseUrl,
|
|
23908
|
+
anthropicBaseUrl: cfg.anthropicBaseUrl
|
|
23909
|
+
});
|
|
23910
|
+
if (cfg.openaiModel) process.env.OPENAI_MODEL = cfg.openaiModel;
|
|
23911
|
+
if (cfg.anthropicModel) process.env.ANTHROPIC_MODEL = cfg.anthropicModel;
|
|
23912
|
+
const resolvedProvider = getResolvedProviderType();
|
|
23913
|
+
if (!resolvedProvider) {
|
|
23914
|
+
console.warn("Warning: No LLM API key found (OPENAI_API_KEY or ANTHROPIC_API_KEY).");
|
|
22161
23915
|
console.warn("The following AI-powered search tools will be unavailable:");
|
|
22162
|
-
console.warn(" - search_events
|
|
22163
|
-
console.warn("
|
|
22164
|
-
console.warn("All other tools will function normally. To enable AI-powered search, set OPENAI_API_KEY.");
|
|
23916
|
+
console.warn(" - search_events, search_issues, search_issue_events, use_sentry");
|
|
23917
|
+
console.warn("Use list_issues and list_events for direct Sentry query syntax instead.");
|
|
22165
23918
|
console.warn("");
|
|
22166
|
-
}
|
|
22167
|
-
setOpenAIBaseUrl(cfg.openaiBaseUrl);
|
|
22168
|
-
if (cfg.openaiModel) process.env.OPENAI_MODEL = cfg.openaiModel;
|
|
23919
|
+
} else console.warn(`Using ${resolvedProvider} for AI-powered search tools.`);
|
|
22169
23920
|
Sentry.init({
|
|
22170
23921
|
dsn: cfg.sentryDsn,
|
|
22171
23922
|
sendDefaultPii: true,
|