@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.cjs
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
const require_chunk = require('./chunk-DoeelZqw.cjs');
|
|
3
|
-
const require_resolve = require('./resolve-
|
|
4
|
-
const require_stdio = require('./stdio-
|
|
5
|
-
const
|
|
6
|
-
const require_usage = require('./usage-
|
|
7
|
-
const require_parse = require('./parse-
|
|
3
|
+
const require_resolve = require('./resolve-DFUPLqHE.cjs');
|
|
4
|
+
const require_stdio = require('./stdio-Dv01oTty.cjs');
|
|
5
|
+
const require_config_CEjP2CYO = require('./config-CEjP2CYO-CZKUamRu.cjs');
|
|
6
|
+
const require_usage = require('./usage-D9Tpyb5N.cjs');
|
|
7
|
+
const require_parse = require('./parse-c_3eNB2Z.cjs');
|
|
8
8
|
const zod = require_chunk.__toESM(require("zod"));
|
|
9
9
|
const node_util = require_chunk.__toESM(require("node:util"));
|
|
10
10
|
const __sentry_core = require_chunk.__toESM(require("@sentry/core"));
|
|
@@ -1752,7 +1752,7 @@ function logIssue(error, contextsOrOptions, attachmentsArg) {
|
|
|
1752
1752
|
}
|
|
1753
1753
|
|
|
1754
1754
|
//#endregion
|
|
1755
|
-
//#region ../mcp-core/dist/schema-
|
|
1755
|
+
//#region ../mcp-core/dist/schema-VoUcElu5.js
|
|
1756
1756
|
/**
|
|
1757
1757
|
* Schema for Sentry API error responses.
|
|
1758
1758
|
*
|
|
@@ -2175,6 +2175,31 @@ const EventAttachmentSchema = zod.z.object({
|
|
|
2175
2175
|
});
|
|
2176
2176
|
const EventAttachmentListSchema = zod.z.array(EventAttachmentSchema);
|
|
2177
2177
|
/**
|
|
2178
|
+
* Schema for individual tag values within an issue's tag distribution.
|
|
2179
|
+
*
|
|
2180
|
+
* Represents a single value's occurrence count and percentage within a tag.
|
|
2181
|
+
*/
|
|
2182
|
+
const IssueTagValueSchema = zod.z.object({
|
|
2183
|
+
key: zod.z.string().nullable().optional(),
|
|
2184
|
+
name: zod.z.string().nullable().optional(),
|
|
2185
|
+
value: zod.z.string().nullable(),
|
|
2186
|
+
count: zod.z.number(),
|
|
2187
|
+
lastSeen: zod.z.string().datetime().nullable().optional(),
|
|
2188
|
+
firstSeen: zod.z.string().datetime().nullable().optional()
|
|
2189
|
+
});
|
|
2190
|
+
/**
|
|
2191
|
+
* Schema for Sentry issue tag values response.
|
|
2192
|
+
*
|
|
2193
|
+
* Contains aggregate counts of unique tag values for an issue,
|
|
2194
|
+
* useful for understanding the distribution of tags like URL, browser, etc.
|
|
2195
|
+
*/
|
|
2196
|
+
const IssueTagValuesSchema = zod.z.object({
|
|
2197
|
+
key: zod.z.string(),
|
|
2198
|
+
name: zod.z.string(),
|
|
2199
|
+
totalValues: zod.z.number(),
|
|
2200
|
+
topValues: zod.z.array(IssueTagValueSchema)
|
|
2201
|
+
});
|
|
2202
|
+
/**
|
|
2178
2203
|
* Schema for Sentry trace metadata response.
|
|
2179
2204
|
*
|
|
2180
2205
|
* Contains high-level statistics about a trace including span counts,
|
|
@@ -2464,7 +2489,7 @@ function createApiError(message, status, detail, responseBody) {
|
|
|
2464
2489
|
}
|
|
2465
2490
|
|
|
2466
2491
|
//#endregion
|
|
2467
|
-
//#region ../mcp-core/dist/client-
|
|
2492
|
+
//#region ../mcp-core/dist/client-DXmt8umX.js
|
|
2468
2493
|
/**
|
|
2469
2494
|
* Mapping of common network error codes to user-friendly messages.
|
|
2470
2495
|
* These help users understand and resolve connection issues.
|
|
@@ -2562,6 +2587,27 @@ var SentryApiService = class {
|
|
|
2562
2587
|
return require_resolve.isSentryHost(this.host);
|
|
2563
2588
|
}
|
|
2564
2589
|
/**
|
|
2590
|
+
* Validates and applies time parameters to a URLSearchParams object.
|
|
2591
|
+
*
|
|
2592
|
+
* Enforces mutual exclusivity between relative (statsPeriod) and
|
|
2593
|
+
* absolute (start/end) time ranges, and ensures start/end are paired.
|
|
2594
|
+
*
|
|
2595
|
+
* @param queryParams The URLSearchParams to modify
|
|
2596
|
+
* @param statsPeriod Relative time period (e.g., "24h", "7d")
|
|
2597
|
+
* @param start Absolute start time (ISO 8601)
|
|
2598
|
+
* @param end Absolute end time (ISO 8601)
|
|
2599
|
+
* @throws {ApiValidationError} If time parameters are invalid
|
|
2600
|
+
*/
|
|
2601
|
+
applyTimeParams(queryParams, statsPeriod, start, end) {
|
|
2602
|
+
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.");
|
|
2603
|
+
if (start && !end || !start && end) throw new ApiValidationError("Both start and end parameters must be provided together for absolute time ranges.");
|
|
2604
|
+
if (statsPeriod) queryParams.set("statsPeriod", statsPeriod);
|
|
2605
|
+
else if (start && end) {
|
|
2606
|
+
queryParams.set("start", start);
|
|
2607
|
+
queryParams.set("end", end);
|
|
2608
|
+
}
|
|
2609
|
+
}
|
|
2610
|
+
/**
|
|
2565
2611
|
* Internal method for making authenticated requests to Sentry API.
|
|
2566
2612
|
*
|
|
2567
2613
|
* Handles:
|
|
@@ -3156,13 +3202,7 @@ var SentryApiService = class {
|
|
|
3156
3202
|
const searchQuery = new URLSearchParams();
|
|
3157
3203
|
if (dataset) searchQuery.set("dataset", dataset);
|
|
3158
3204
|
if (project) searchQuery.set("project", project);
|
|
3159
|
-
|
|
3160
|
-
if (start && !end || !start && end) throw new ApiValidationError("Both start and end parameters must be provided together for absolute time ranges.");
|
|
3161
|
-
if (statsPeriod) searchQuery.set("statsPeriod", statsPeriod);
|
|
3162
|
-
else if (start && end) {
|
|
3163
|
-
searchQuery.set("start", start);
|
|
3164
|
-
searchQuery.set("end", end);
|
|
3165
|
-
}
|
|
3205
|
+
this.applyTimeParams(searchQuery, statsPeriod, start, end);
|
|
3166
3206
|
if (useCache !== void 0) searchQuery.set("useCache", useCache ? "1" : "0");
|
|
3167
3207
|
if (useFlagsBackend !== void 0) searchQuery.set("useFlagsBackend", useFlagsBackend ? "1" : "0");
|
|
3168
3208
|
const body = await this.requestJSON(searchQuery.toString() ? `/organizations/${organizationSlug}/tags/?${searchQuery.toString()}` : `/organizations/${organizationSlug}/tags/`, void 0, opts);
|
|
@@ -3202,13 +3242,7 @@ var SentryApiService = class {
|
|
|
3202
3242
|
queryParams.set("itemType", itemType);
|
|
3203
3243
|
queryParams.set("attributeType", attributeType);
|
|
3204
3244
|
if (project) queryParams.set("project", project);
|
|
3205
|
-
|
|
3206
|
-
if (start && !end || !start && end) throw new ApiValidationError("Both start and end parameters must be provided together for absolute time ranges.");
|
|
3207
|
-
if (statsPeriod) queryParams.set("statsPeriod", statsPeriod);
|
|
3208
|
-
else if (start && end) {
|
|
3209
|
-
queryParams.set("start", start);
|
|
3210
|
-
queryParams.set("end", end);
|
|
3211
|
-
}
|
|
3245
|
+
this.applyTimeParams(queryParams, statsPeriod, start, end);
|
|
3212
3246
|
const url = `/organizations/${organizationSlug}/trace-items/attributes/?${queryParams.toString()}`;
|
|
3213
3247
|
const body = await this.requestJSON(url, void 0, opts);
|
|
3214
3248
|
return Array.isArray(body) ? body : [];
|
|
@@ -3262,6 +3296,35 @@ var SentryApiService = class {
|
|
|
3262
3296
|
const body = await this.requestJSON(`/organizations/${organizationSlug}/issues/${issueId}/`, void 0, opts);
|
|
3263
3297
|
return IssueSchema.parse(body);
|
|
3264
3298
|
}
|
|
3299
|
+
/**
|
|
3300
|
+
* Retrieves tag value distribution for a specific issue.
|
|
3301
|
+
*
|
|
3302
|
+
* Returns aggregate counts of unique tag values, useful for understanding
|
|
3303
|
+
* how an issue is distributed across different tag values (e.g., URLs,
|
|
3304
|
+
* browsers, environments).
|
|
3305
|
+
*
|
|
3306
|
+
* @param params Query parameters
|
|
3307
|
+
* @param params.organizationSlug Organization identifier
|
|
3308
|
+
* @param params.issueId Issue identifier (short ID or numeric ID)
|
|
3309
|
+
* @param params.tagKey Tag key to get values for (e.g., "url", "browser", "environment")
|
|
3310
|
+
* @param opts Request options
|
|
3311
|
+
* @returns Tag value distribution with counts and percentages
|
|
3312
|
+
*
|
|
3313
|
+
* @example
|
|
3314
|
+
* ```typescript
|
|
3315
|
+
* const tagValues = await apiService.getIssueTagValues({
|
|
3316
|
+
* organizationSlug: "my-org",
|
|
3317
|
+
* issueId: "PROJECT-123",
|
|
3318
|
+
* tagKey: "url"
|
|
3319
|
+
* });
|
|
3320
|
+
* console.log(`Total unique values: ${tagValues.totalValues}`);
|
|
3321
|
+
* tagValues.topValues.forEach(v => console.log(`${v.value}: ${v.count}`));
|
|
3322
|
+
* ```
|
|
3323
|
+
*/
|
|
3324
|
+
async getIssueTagValues({ organizationSlug, issueId, tagKey }, opts) {
|
|
3325
|
+
const body = await this.requestJSON(`/organizations/${organizationSlug}/issues/${issueId}/tags/${tagKey}/`, void 0, opts);
|
|
3326
|
+
return IssueTagValuesSchema.parse(body);
|
|
3327
|
+
}
|
|
3265
3328
|
async getEventForIssue({ organizationSlug, issueId, eventId }, opts) {
|
|
3266
3329
|
const body = await this.requestJSON(`/organizations/${organizationSlug}/issues/${issueId}/events/${eventId}/`, void 0, opts);
|
|
3267
3330
|
const parseResult = EventSchema.safeParse(body);
|
|
@@ -3402,13 +3465,7 @@ var SentryApiService = class {
|
|
|
3402
3465
|
queryParams.set("per_page", params.limit.toString());
|
|
3403
3466
|
queryParams.set("query", params.query);
|
|
3404
3467
|
queryParams.set("dataset", "errors");
|
|
3405
|
-
|
|
3406
|
-
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.");
|
|
3407
|
-
if (params.statsPeriod) queryParams.set("statsPeriod", params.statsPeriod);
|
|
3408
|
-
else if (params.start && params.end) {
|
|
3409
|
-
queryParams.set("start", params.start);
|
|
3410
|
-
queryParams.set("end", params.end);
|
|
3411
|
-
}
|
|
3468
|
+
this.applyTimeParams(queryParams, params.statsPeriod, params.start, params.end);
|
|
3412
3469
|
if (params.projectId) queryParams.set("project", params.projectId);
|
|
3413
3470
|
let apiSort = params.sort;
|
|
3414
3471
|
if (params.sort?.includes("(") && !params.sort?.includes("equation|")) {
|
|
@@ -3436,13 +3493,7 @@ var SentryApiService = class {
|
|
|
3436
3493
|
queryParams.set("per_page", params.limit.toString());
|
|
3437
3494
|
queryParams.set("query", params.query);
|
|
3438
3495
|
queryParams.set("dataset", params.dataset);
|
|
3439
|
-
|
|
3440
|
-
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.");
|
|
3441
|
-
if (params.statsPeriod) queryParams.set("statsPeriod", params.statsPeriod);
|
|
3442
|
-
else if (params.start && params.end) {
|
|
3443
|
-
queryParams.set("start", params.start);
|
|
3444
|
-
queryParams.set("end", params.end);
|
|
3445
|
-
}
|
|
3496
|
+
this.applyTimeParams(queryParams, params.statsPeriod, params.start, params.end);
|
|
3446
3497
|
if (params.projectId) queryParams.set("project", params.projectId);
|
|
3447
3498
|
if (params.dataset === "spans") queryParams.set("sampling", "NORMAL");
|
|
3448
3499
|
let apiSort = params.sort;
|
|
@@ -3605,7 +3656,7 @@ function validateRegionUrl(regionUrl, baseHost) {
|
|
|
3605
3656
|
}
|
|
3606
3657
|
|
|
3607
3658
|
//#endregion
|
|
3608
|
-
//#region ../mcp-core/dist/api-
|
|
3659
|
+
//#region ../mcp-core/dist/api-DgBjJzAN.js
|
|
3609
3660
|
/**
|
|
3610
3661
|
* Create a Sentry API service from server context with optional region override
|
|
3611
3662
|
* @param context - Server context containing host and access token
|
|
@@ -3626,7 +3677,7 @@ function apiServiceFromContext(context$1, opts = {}) {
|
|
|
3626
3677
|
}
|
|
3627
3678
|
|
|
3628
3679
|
//#endregion
|
|
3629
|
-
//#region ../mcp-core/dist/whoami-
|
|
3680
|
+
//#region ../mcp-core/dist/whoami-B_pOoN0T.js
|
|
3630
3681
|
var whoami_default = defineTool({
|
|
3631
3682
|
name: "whoami",
|
|
3632
3683
|
description: [
|
|
@@ -3659,7 +3710,7 @@ var whoami_default = defineTool({
|
|
|
3659
3710
|
});
|
|
3660
3711
|
|
|
3661
3712
|
//#endregion
|
|
3662
|
-
//#region ../mcp-core/dist/find-organizations-
|
|
3713
|
+
//#region ../mcp-core/dist/find-organizations-DudCkGim.js
|
|
3663
3714
|
const RESULT_LIMIT$2 = 25;
|
|
3664
3715
|
var find_organizations_default = defineTool({
|
|
3665
3716
|
name: "find_organizations",
|
|
@@ -3711,7 +3762,7 @@ var find_organizations_default = defineTool({
|
|
|
3711
3762
|
});
|
|
3712
3763
|
|
|
3713
3764
|
//#endregion
|
|
3714
|
-
//#region ../mcp-core/dist/find-teams-
|
|
3765
|
+
//#region ../mcp-core/dist/find-teams-BP0pLsvf.js
|
|
3715
3766
|
const RESULT_LIMIT$1 = 25;
|
|
3716
3767
|
var find_teams_default = defineTool({
|
|
3717
3768
|
name: "find_teams",
|
|
@@ -3759,7 +3810,7 @@ var find_teams_default = defineTool({
|
|
|
3759
3810
|
});
|
|
3760
3811
|
|
|
3761
3812
|
//#endregion
|
|
3762
|
-
//#region ../mcp-core/dist/find-projects-
|
|
3813
|
+
//#region ../mcp-core/dist/find-projects-YtaNsBaH.js
|
|
3763
3814
|
const RESULT_LIMIT = 25;
|
|
3764
3815
|
var find_projects_default = defineTool({
|
|
3765
3816
|
name: "find_projects",
|
|
@@ -3803,7 +3854,7 @@ var find_projects_default = defineTool({
|
|
|
3803
3854
|
});
|
|
3804
3855
|
|
|
3805
3856
|
//#endregion
|
|
3806
|
-
//#region ../mcp-core/dist/find-releases-
|
|
3857
|
+
//#region ../mcp-core/dist/find-releases-BVBIICgY.js
|
|
3807
3858
|
var find_releases_default = defineTool({
|
|
3808
3859
|
name: "find_releases",
|
|
3809
3860
|
skills: ["inspect"],
|
|
@@ -5048,7 +5099,7 @@ function enhanceNotFoundError(error, params) {
|
|
|
5048
5099
|
}
|
|
5049
5100
|
|
|
5050
5101
|
//#endregion
|
|
5051
|
-
//#region ../mcp-core/dist/get-issue-details-
|
|
5102
|
+
//#region ../mcp-core/dist/get-issue-details-U818j2tY.js
|
|
5052
5103
|
var get_issue_details_default = defineTool({
|
|
5053
5104
|
name: "get_issue_details",
|
|
5054
5105
|
skills: [
|
|
@@ -5229,7 +5280,122 @@ function shouldFetchTraceForEvent(event) {
|
|
|
5229
5280
|
}
|
|
5230
5281
|
|
|
5231
5282
|
//#endregion
|
|
5232
|
-
//#region ../mcp-core/dist/get-
|
|
5283
|
+
//#region ../mcp-core/dist/get-issue-tag-values-tupBr2Mu.js
|
|
5284
|
+
var get_issue_tag_values_default = defineTool({
|
|
5285
|
+
name: "get_issue_tag_values",
|
|
5286
|
+
skills: ["inspect"],
|
|
5287
|
+
requiredScopes: ["event:read"],
|
|
5288
|
+
description: [
|
|
5289
|
+
"Get tag value distribution for a specific Sentry issue.",
|
|
5290
|
+
"",
|
|
5291
|
+
"Use this tool when you need to:",
|
|
5292
|
+
"- Understand how an issue is distributed across different tag values",
|
|
5293
|
+
"- Get aggregate counts of unique tag values (e.g., 'how many unique URLs are affected')",
|
|
5294
|
+
"- Analyze which browsers, environments, or URLs are most impacted by an issue",
|
|
5295
|
+
"- View the tag distributions page data programmatically",
|
|
5296
|
+
"",
|
|
5297
|
+
"Common tag keys:",
|
|
5298
|
+
"- `url`: Request URLs affected by the issue",
|
|
5299
|
+
"- `browser`: Browser types and versions",
|
|
5300
|
+
"- `browser.name`: Browser names only",
|
|
5301
|
+
"- `os`: Operating systems",
|
|
5302
|
+
"- `environment`: Deployment environments (production, staging, etc.)",
|
|
5303
|
+
"- `release`: Software releases",
|
|
5304
|
+
"- `device`: Device types",
|
|
5305
|
+
"- `user`: Affected users",
|
|
5306
|
+
"",
|
|
5307
|
+
"<examples>",
|
|
5308
|
+
"### Get URL distribution for an issue",
|
|
5309
|
+
"```",
|
|
5310
|
+
"get_issue_tag_values(organizationSlug='my-organization', issueId='PROJECT-123', tagKey='url')",
|
|
5311
|
+
"```",
|
|
5312
|
+
"",
|
|
5313
|
+
"### Get browser distribution using issue URL",
|
|
5314
|
+
"```",
|
|
5315
|
+
"get_issue_tag_values(issueUrl='https://sentry.io/issues/PROJECT-123/', tagKey='browser')",
|
|
5316
|
+
"```",
|
|
5317
|
+
"",
|
|
5318
|
+
"### Get environment distribution",
|
|
5319
|
+
"```",
|
|
5320
|
+
"get_issue_tag_values(organizationSlug='my-organization', issueId='PROJECT-123', tagKey='environment')",
|
|
5321
|
+
"```",
|
|
5322
|
+
"</examples>",
|
|
5323
|
+
"",
|
|
5324
|
+
"<hints>",
|
|
5325
|
+
"- If user provides a Sentry URL, pass the ENTIRE URL to issueUrl parameter unchanged",
|
|
5326
|
+
"- Common tag keys: url, browser, browser.name, os, environment, release, device, user",
|
|
5327
|
+
"- Tag keys are case-sensitive",
|
|
5328
|
+
"</hints>"
|
|
5329
|
+
].join("\n"),
|
|
5330
|
+
inputSchema: {
|
|
5331
|
+
organizationSlug: ParamOrganizationSlug.optional(),
|
|
5332
|
+
regionUrl: ParamRegionUrl.nullable().default(null),
|
|
5333
|
+
issueId: ParamIssueShortId.optional(),
|
|
5334
|
+
issueUrl: ParamIssueUrl.optional(),
|
|
5335
|
+
tagKey: zod.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').")
|
|
5336
|
+
},
|
|
5337
|
+
annotations: {
|
|
5338
|
+
readOnlyHint: true,
|
|
5339
|
+
openWorldHint: true
|
|
5340
|
+
},
|
|
5341
|
+
async handler(params, context$1) {
|
|
5342
|
+
const apiService = apiServiceFromContext(context$1, { regionUrl: params.regionUrl ?? void 0 });
|
|
5343
|
+
if (!params.issueUrl && !params.issueId) throw new UserInputError("Either `issueId` or `issueUrl` must be provided");
|
|
5344
|
+
if (!params.issueUrl && !params.organizationSlug) throw new UserInputError("`organizationSlug` is required when providing `issueId`");
|
|
5345
|
+
if (!params.tagKey) throw new UserInputError("`tagKey` is required. Common values: url, browser, environment, release, os, device, user");
|
|
5346
|
+
const { organizationSlug: orgSlug, issueId: parsedIssueId } = parseIssueParams$1({
|
|
5347
|
+
organizationSlug: params.organizationSlug,
|
|
5348
|
+
issueId: params.issueId,
|
|
5349
|
+
issueUrl: params.issueUrl
|
|
5350
|
+
});
|
|
5351
|
+
(0, __sentry_core.setTag)("organization.slug", orgSlug);
|
|
5352
|
+
let tagValues;
|
|
5353
|
+
try {
|
|
5354
|
+
tagValues = await apiService.getIssueTagValues({
|
|
5355
|
+
organizationSlug: orgSlug,
|
|
5356
|
+
issueId: parsedIssueId,
|
|
5357
|
+
tagKey: params.tagKey
|
|
5358
|
+
});
|
|
5359
|
+
} catch (error) {
|
|
5360
|
+
if (error instanceof ApiNotFoundError) throw enhanceNotFoundError(error, {
|
|
5361
|
+
organizationSlug: orgSlug,
|
|
5362
|
+
issueId: parsedIssueId,
|
|
5363
|
+
tagKey: params.tagKey
|
|
5364
|
+
});
|
|
5365
|
+
throw error;
|
|
5366
|
+
}
|
|
5367
|
+
let output = `# Tag Distribution: ${tagValues.name}\n\n`;
|
|
5368
|
+
output += `**Issue**: ${parsedIssueId}\n`;
|
|
5369
|
+
output += `**Tag Key**: \`${tagValues.key}\`\n`;
|
|
5370
|
+
output += `**Total Unique Values**: ${tagValues.totalValues}\n\n`;
|
|
5371
|
+
if (tagValues.topValues.length === 0) {
|
|
5372
|
+
output += "No values found for this tag.\n";
|
|
5373
|
+
return output;
|
|
5374
|
+
}
|
|
5375
|
+
output += "## Top Values\n\n";
|
|
5376
|
+
output += "| Value | Count | First Seen | Last Seen |\n";
|
|
5377
|
+
output += "|-------|-------|------------|----------|\n";
|
|
5378
|
+
for (const value of tagValues.topValues) {
|
|
5379
|
+
const firstSeen = value.firstSeen ? new Date(value.firstSeen).toISOString().split("T")[0] : "-";
|
|
5380
|
+
const lastSeen = value.lastSeen ? new Date(value.lastSeen).toISOString().split("T")[0] : "-";
|
|
5381
|
+
const rawValue = value.value ?? "(null)";
|
|
5382
|
+
let displayValue = rawValue.length > 60 ? `${rawValue.substring(0, 57)}...` : rawValue;
|
|
5383
|
+
displayValue = displayValue.replace(/\\/g, "\\\\").replace(/\|/g, "\\|").replace(/`/g, "\\`").replace(/\n/g, " ");
|
|
5384
|
+
output += `| \`${displayValue}\` | ${value.count} | ${firstSeen} | ${lastSeen} |\n`;
|
|
5385
|
+
}
|
|
5386
|
+
if (tagValues.topValues.length > 0 && tagValues.totalValues > 0) {
|
|
5387
|
+
const shownCount = tagValues.topValues.length;
|
|
5388
|
+
output += `\n*Showing top ${shownCount} of ${tagValues.totalValues} unique values*\n`;
|
|
5389
|
+
}
|
|
5390
|
+
output += "\n## Using this information\n\n";
|
|
5391
|
+
output += `- Use \`get_issue_details(organizationSlug='${orgSlug}', issueId='${parsedIssueId}')\` to see the full issue details\n`;
|
|
5392
|
+
output += `- Try other tag keys like: url, browser, environment, release, os, device, user\n`;
|
|
5393
|
+
return output;
|
|
5394
|
+
}
|
|
5395
|
+
});
|
|
5396
|
+
|
|
5397
|
+
//#endregion
|
|
5398
|
+
//#region ../mcp-core/dist/get-trace-details-DDDetJqp.js
|
|
5233
5399
|
const MAX_DEPTH = 2;
|
|
5234
5400
|
const MINIMUM_DURATION_THRESHOLD_MS = 10;
|
|
5235
5401
|
const MIN_MEANINGFUL_CHILD_DURATION = 5;
|
|
@@ -5528,7 +5694,7 @@ function formatTraceOutput({ organizationSlug, traceId, traceMeta, trace: trace$
|
|
|
5528
5694
|
}
|
|
5529
5695
|
|
|
5530
5696
|
//#endregion
|
|
5531
|
-
//#region ../mcp-core/dist/get-event-attachment-
|
|
5697
|
+
//#region ../mcp-core/dist/get-event-attachment-itWm1HrK.js
|
|
5532
5698
|
var get_event_attachment_default = defineTool({
|
|
5533
5699
|
name: "get_event_attachment",
|
|
5534
5700
|
skills: ["inspect"],
|
|
@@ -5664,7 +5830,7 @@ var get_event_attachment_default = defineTool({
|
|
|
5664
5830
|
});
|
|
5665
5831
|
|
|
5666
5832
|
//#endregion
|
|
5667
|
-
//#region ../mcp-core/dist/formatting-
|
|
5833
|
+
//#region ../mcp-core/dist/formatting-CIwRyNGU.js
|
|
5668
5834
|
/**
|
|
5669
5835
|
* Helper function to format assignedTo field for display
|
|
5670
5836
|
*/
|
|
@@ -5676,7 +5842,7 @@ function formatAssignedTo(assignedTo) {
|
|
|
5676
5842
|
}
|
|
5677
5843
|
|
|
5678
5844
|
//#endregion
|
|
5679
|
-
//#region ../mcp-core/dist/update-issue-
|
|
5845
|
+
//#region ../mcp-core/dist/update-issue-DA_N-toV.js
|
|
5680
5846
|
var update_issue_default = defineTool({
|
|
5681
5847
|
name: "update_issue",
|
|
5682
5848
|
skills: ["triage"],
|
|
@@ -5973,6 +6139,20 @@ var name10$1 = "AI_NoSuchModelError";
|
|
|
5973
6139
|
var marker11$1 = `vercel.ai.error.${name10$1}`;
|
|
5974
6140
|
var symbol11$1 = Symbol.for(marker11$1);
|
|
5975
6141
|
var _a11$1;
|
|
6142
|
+
var NoSuchModelError = class extends AISDKError {
|
|
6143
|
+
constructor({ errorName = name10$1, modelId, modelType, message = `No such ${modelType}: ${modelId}` }) {
|
|
6144
|
+
super({
|
|
6145
|
+
name: errorName,
|
|
6146
|
+
message
|
|
6147
|
+
});
|
|
6148
|
+
this[_a11$1] = true;
|
|
6149
|
+
this.modelId = modelId;
|
|
6150
|
+
this.modelType = modelType;
|
|
6151
|
+
}
|
|
6152
|
+
static isInstance(error) {
|
|
6153
|
+
return AISDKError.hasMarker(error, marker11$1);
|
|
6154
|
+
}
|
|
6155
|
+
};
|
|
5976
6156
|
_a11$1 = symbol11$1;
|
|
5977
6157
|
var name11$1 = "AI_TooManyEmbeddingValuesForCallError";
|
|
5978
6158
|
var marker12$1 = `vercel.ai.error.${name11$1}`;
|
|
@@ -6508,6 +6688,10 @@ var postToApi = async ({ url, headers = {}, body, successfulResponseHandler, fai
|
|
|
6508
6688
|
throw error;
|
|
6509
6689
|
}
|
|
6510
6690
|
};
|
|
6691
|
+
async function resolve(value) {
|
|
6692
|
+
if (typeof value === "function") value = value();
|
|
6693
|
+
return Promise.resolve(value);
|
|
6694
|
+
}
|
|
6511
6695
|
var createJsonErrorResponseHandler = ({ errorSchema, errorToMessage, isRetryable }) => async ({ response, url, requestBodyValues }) => {
|
|
6512
6696
|
const responseBody = await response.text();
|
|
6513
6697
|
const responseHeaders = extractResponseHeaders(response);
|
|
@@ -6823,7 +7007,7 @@ function getResponseMetadata({ id, model, created }) {
|
|
|
6823
7007
|
timestamp: created != null ? /* @__PURE__ */ new Date(created * 1e3) : void 0
|
|
6824
7008
|
};
|
|
6825
7009
|
}
|
|
6826
|
-
function prepareTools({ mode, useLegacyFunctionCalling = false, structuredOutputs }) {
|
|
7010
|
+
function prepareTools$1({ mode, useLegacyFunctionCalling = false, structuredOutputs }) {
|
|
6827
7011
|
var _a$2;
|
|
6828
7012
|
const tools = ((_a$2 = mode.tools) == null ? void 0 : _a$2.length) ? mode.tools : void 0;
|
|
6829
7013
|
const toolWarnings = [];
|
|
@@ -7051,7 +7235,7 @@ var OpenAIChatLanguageModel = class {
|
|
|
7051
7235
|
}
|
|
7052
7236
|
switch (type) {
|
|
7053
7237
|
case "regular": {
|
|
7054
|
-
const { tools, tool_choice, functions, function_call, toolWarnings } = prepareTools({
|
|
7238
|
+
const { tools, tool_choice, functions, function_call, toolWarnings } = prepareTools$1({
|
|
7055
7239
|
mode,
|
|
7056
7240
|
useLegacyFunctionCalling,
|
|
7057
7241
|
structuredOutputs: this.supportsStructuredOutputs
|
|
@@ -8946,49 +9130,1283 @@ function createOpenAI(options = {}) {
|
|
|
8946
9130
|
provider.tools = openaiTools;
|
|
8947
9131
|
return provider;
|
|
8948
9132
|
}
|
|
8949
|
-
var openai = createOpenAI({ compatibility: "strict" });
|
|
9133
|
+
var openai = createOpenAI({ compatibility: "strict" });
|
|
9134
|
+
|
|
9135
|
+
//#endregion
|
|
9136
|
+
//#region ../mcp-core/dist/openai-provider-BhiGfaFk.js
|
|
9137
|
+
const DEFAULT_OPENAI_MODEL = "gpt-5";
|
|
9138
|
+
const VALID_REASONING_EFFORTS = [
|
|
9139
|
+
"low",
|
|
9140
|
+
"medium",
|
|
9141
|
+
"high"
|
|
9142
|
+
];
|
|
9143
|
+
const DEFAULT_REASONING_EFFORT = "low";
|
|
9144
|
+
let configuredBaseUrl$1;
|
|
9145
|
+
/**
|
|
9146
|
+
* Configure the OpenAI base URL (CLI flag only, not environment variable).
|
|
9147
|
+
* This must be called explicitly - it cannot be set via environment variables for security.
|
|
9148
|
+
*/
|
|
9149
|
+
function setOpenAIBaseUrl(baseUrl) {
|
|
9150
|
+
configuredBaseUrl$1 = baseUrl;
|
|
9151
|
+
}
|
|
9152
|
+
/**
|
|
9153
|
+
* Retrieve an OpenAI language model configured from environment variables and explicit config.
|
|
9154
|
+
*
|
|
9155
|
+
* Configuration:
|
|
9156
|
+
* - OPENAI_MODEL: Model to use (default: "gpt-5") - env var OK
|
|
9157
|
+
* - OPENAI_REASONING_EFFORT: Reasoning effort for o1 models: "low", "medium", "high", or "" to disable (default: "low") - env var OK
|
|
9158
|
+
* - Base URL: Must be set via setOpenAIBaseUrl() - NOT from env vars (security risk)
|
|
9159
|
+
*/
|
|
9160
|
+
function getOpenAIModel(model) {
|
|
9161
|
+
const defaultModel = process.env.OPENAI_MODEL || DEFAULT_OPENAI_MODEL;
|
|
9162
|
+
const envReasoningEffort = process.env.OPENAI_REASONING_EFFORT;
|
|
9163
|
+
let reasoningEffort;
|
|
9164
|
+
if (envReasoningEffort === "") reasoningEffort = void 0;
|
|
9165
|
+
else if (envReasoningEffort === void 0) reasoningEffort = DEFAULT_REASONING_EFFORT;
|
|
9166
|
+
else if (VALID_REASONING_EFFORTS.includes(envReasoningEffort)) reasoningEffort = envReasoningEffort;
|
|
9167
|
+
else {
|
|
9168
|
+
const validValues = VALID_REASONING_EFFORTS.map((v) => `"${v}"`).join(", ");
|
|
9169
|
+
throw new Error(`Invalid OPENAI_REASONING_EFFORT value: "${envReasoningEffort}". Must be one of: ${validValues}, or "" (empty string to disable). Default is "${DEFAULT_REASONING_EFFORT}".`);
|
|
9170
|
+
}
|
|
9171
|
+
const factory = createOpenAI({
|
|
9172
|
+
...configuredBaseUrl$1 && { baseURL: configuredBaseUrl$1 },
|
|
9173
|
+
headers: { "User-Agent": require_stdio.USER_AGENT }
|
|
9174
|
+
});
|
|
9175
|
+
return factory(model ?? defaultModel, { ...reasoningEffort && { reasoningEffort } });
|
|
9176
|
+
}
|
|
9177
|
+
|
|
9178
|
+
//#endregion
|
|
9179
|
+
//#region ../../node_modules/.pnpm/@ai-sdk+anthropic@1.2.12_zod@3.25.76/node_modules/@ai-sdk/anthropic/dist/index.mjs
|
|
9180
|
+
var anthropicErrorDataSchema = zod.z.object({
|
|
9181
|
+
type: zod.z.literal("error"),
|
|
9182
|
+
error: zod.z.object({
|
|
9183
|
+
type: zod.z.string(),
|
|
9184
|
+
message: zod.z.string()
|
|
9185
|
+
})
|
|
9186
|
+
});
|
|
9187
|
+
var anthropicFailedResponseHandler = createJsonErrorResponseHandler({
|
|
9188
|
+
errorSchema: anthropicErrorDataSchema,
|
|
9189
|
+
errorToMessage: (data) => data.error.message
|
|
9190
|
+
});
|
|
9191
|
+
function prepareTools(mode) {
|
|
9192
|
+
var _a$2;
|
|
9193
|
+
const tools = ((_a$2 = mode.tools) == null ? void 0 : _a$2.length) ? mode.tools : void 0;
|
|
9194
|
+
const toolWarnings = [];
|
|
9195
|
+
const betas = /* @__PURE__ */ new Set();
|
|
9196
|
+
if (tools == null) return {
|
|
9197
|
+
tools: void 0,
|
|
9198
|
+
tool_choice: void 0,
|
|
9199
|
+
toolWarnings,
|
|
9200
|
+
betas
|
|
9201
|
+
};
|
|
9202
|
+
const anthropicTools2 = [];
|
|
9203
|
+
for (const tool$1 of tools) switch (tool$1.type) {
|
|
9204
|
+
case "function":
|
|
9205
|
+
anthropicTools2.push({
|
|
9206
|
+
name: tool$1.name,
|
|
9207
|
+
description: tool$1.description,
|
|
9208
|
+
input_schema: tool$1.parameters
|
|
9209
|
+
});
|
|
9210
|
+
break;
|
|
9211
|
+
case "provider-defined":
|
|
9212
|
+
switch (tool$1.id) {
|
|
9213
|
+
case "anthropic.computer_20250124":
|
|
9214
|
+
betas.add("computer-use-2025-01-24");
|
|
9215
|
+
anthropicTools2.push({
|
|
9216
|
+
name: tool$1.name,
|
|
9217
|
+
type: "computer_20250124",
|
|
9218
|
+
display_width_px: tool$1.args.displayWidthPx,
|
|
9219
|
+
display_height_px: tool$1.args.displayHeightPx,
|
|
9220
|
+
display_number: tool$1.args.displayNumber
|
|
9221
|
+
});
|
|
9222
|
+
break;
|
|
9223
|
+
case "anthropic.computer_20241022":
|
|
9224
|
+
betas.add("computer-use-2024-10-22");
|
|
9225
|
+
anthropicTools2.push({
|
|
9226
|
+
name: tool$1.name,
|
|
9227
|
+
type: "computer_20241022",
|
|
9228
|
+
display_width_px: tool$1.args.displayWidthPx,
|
|
9229
|
+
display_height_px: tool$1.args.displayHeightPx,
|
|
9230
|
+
display_number: tool$1.args.displayNumber
|
|
9231
|
+
});
|
|
9232
|
+
break;
|
|
9233
|
+
case "anthropic.text_editor_20250124":
|
|
9234
|
+
betas.add("computer-use-2025-01-24");
|
|
9235
|
+
anthropicTools2.push({
|
|
9236
|
+
name: tool$1.name,
|
|
9237
|
+
type: "text_editor_20250124"
|
|
9238
|
+
});
|
|
9239
|
+
break;
|
|
9240
|
+
case "anthropic.text_editor_20241022":
|
|
9241
|
+
betas.add("computer-use-2024-10-22");
|
|
9242
|
+
anthropicTools2.push({
|
|
9243
|
+
name: tool$1.name,
|
|
9244
|
+
type: "text_editor_20241022"
|
|
9245
|
+
});
|
|
9246
|
+
break;
|
|
9247
|
+
case "anthropic.bash_20250124":
|
|
9248
|
+
betas.add("computer-use-2025-01-24");
|
|
9249
|
+
anthropicTools2.push({
|
|
9250
|
+
name: tool$1.name,
|
|
9251
|
+
type: "bash_20250124"
|
|
9252
|
+
});
|
|
9253
|
+
break;
|
|
9254
|
+
case "anthropic.bash_20241022":
|
|
9255
|
+
betas.add("computer-use-2024-10-22");
|
|
9256
|
+
anthropicTools2.push({
|
|
9257
|
+
name: tool$1.name,
|
|
9258
|
+
type: "bash_20241022"
|
|
9259
|
+
});
|
|
9260
|
+
break;
|
|
9261
|
+
default:
|
|
9262
|
+
toolWarnings.push({
|
|
9263
|
+
type: "unsupported-tool",
|
|
9264
|
+
tool: tool$1
|
|
9265
|
+
});
|
|
9266
|
+
break;
|
|
9267
|
+
}
|
|
9268
|
+
break;
|
|
9269
|
+
default:
|
|
9270
|
+
toolWarnings.push({
|
|
9271
|
+
type: "unsupported-tool",
|
|
9272
|
+
tool: tool$1
|
|
9273
|
+
});
|
|
9274
|
+
break;
|
|
9275
|
+
}
|
|
9276
|
+
const toolChoice = mode.toolChoice;
|
|
9277
|
+
if (toolChoice == null) return {
|
|
9278
|
+
tools: anthropicTools2,
|
|
9279
|
+
tool_choice: void 0,
|
|
9280
|
+
toolWarnings,
|
|
9281
|
+
betas
|
|
9282
|
+
};
|
|
9283
|
+
const type = toolChoice.type;
|
|
9284
|
+
switch (type) {
|
|
9285
|
+
case "auto": return {
|
|
9286
|
+
tools: anthropicTools2,
|
|
9287
|
+
tool_choice: { type: "auto" },
|
|
9288
|
+
toolWarnings,
|
|
9289
|
+
betas
|
|
9290
|
+
};
|
|
9291
|
+
case "required": return {
|
|
9292
|
+
tools: anthropicTools2,
|
|
9293
|
+
tool_choice: { type: "any" },
|
|
9294
|
+
toolWarnings,
|
|
9295
|
+
betas
|
|
9296
|
+
};
|
|
9297
|
+
case "none": return {
|
|
9298
|
+
tools: void 0,
|
|
9299
|
+
tool_choice: void 0,
|
|
9300
|
+
toolWarnings,
|
|
9301
|
+
betas
|
|
9302
|
+
};
|
|
9303
|
+
case "tool": return {
|
|
9304
|
+
tools: anthropicTools2,
|
|
9305
|
+
tool_choice: {
|
|
9306
|
+
type: "tool",
|
|
9307
|
+
name: toolChoice.toolName
|
|
9308
|
+
},
|
|
9309
|
+
toolWarnings,
|
|
9310
|
+
betas
|
|
9311
|
+
};
|
|
9312
|
+
default: {
|
|
9313
|
+
const _exhaustiveCheck = type;
|
|
9314
|
+
throw new UnsupportedFunctionalityError({ functionality: `Unsupported tool choice type: ${_exhaustiveCheck}` });
|
|
9315
|
+
}
|
|
9316
|
+
}
|
|
9317
|
+
}
|
|
9318
|
+
function convertToAnthropicMessagesPrompt({ prompt, sendReasoning, warnings }) {
|
|
9319
|
+
var _a$2, _b, _c, _d;
|
|
9320
|
+
const betas = /* @__PURE__ */ new Set();
|
|
9321
|
+
const blocks = groupIntoBlocks(prompt);
|
|
9322
|
+
let system = void 0;
|
|
9323
|
+
const messages = [];
|
|
9324
|
+
function getCacheControl(providerMetadata) {
|
|
9325
|
+
var _a2$2;
|
|
9326
|
+
const anthropic2 = providerMetadata == null ? void 0 : providerMetadata.anthropic;
|
|
9327
|
+
const cacheControlValue = (_a2$2 = anthropic2 == null ? void 0 : anthropic2.cacheControl) != null ? _a2$2 : anthropic2 == null ? void 0 : anthropic2.cache_control;
|
|
9328
|
+
return cacheControlValue;
|
|
9329
|
+
}
|
|
9330
|
+
for (let i = 0; i < blocks.length; i++) {
|
|
9331
|
+
const block = blocks[i];
|
|
9332
|
+
const isLastBlock = i === blocks.length - 1;
|
|
9333
|
+
const type = block.type;
|
|
9334
|
+
switch (type) {
|
|
9335
|
+
case "system": {
|
|
9336
|
+
if (system != null) throw new UnsupportedFunctionalityError({ functionality: "Multiple system messages that are separated by user/assistant messages" });
|
|
9337
|
+
system = block.messages.map(({ content, providerMetadata }) => ({
|
|
9338
|
+
type: "text",
|
|
9339
|
+
text: content,
|
|
9340
|
+
cache_control: getCacheControl(providerMetadata)
|
|
9341
|
+
}));
|
|
9342
|
+
break;
|
|
9343
|
+
}
|
|
9344
|
+
case "user": {
|
|
9345
|
+
const anthropicContent = [];
|
|
9346
|
+
for (const message of block.messages) {
|
|
9347
|
+
const { role, content } = message;
|
|
9348
|
+
switch (role) {
|
|
9349
|
+
case "user": {
|
|
9350
|
+
for (let j = 0; j < content.length; j++) {
|
|
9351
|
+
const part = content[j];
|
|
9352
|
+
const isLastPart = j === content.length - 1;
|
|
9353
|
+
const cacheControl = (_a$2 = getCacheControl(part.providerMetadata)) != null ? _a$2 : isLastPart ? getCacheControl(message.providerMetadata) : void 0;
|
|
9354
|
+
switch (part.type) {
|
|
9355
|
+
case "text": {
|
|
9356
|
+
anthropicContent.push({
|
|
9357
|
+
type: "text",
|
|
9358
|
+
text: part.text,
|
|
9359
|
+
cache_control: cacheControl
|
|
9360
|
+
});
|
|
9361
|
+
break;
|
|
9362
|
+
}
|
|
9363
|
+
case "image": {
|
|
9364
|
+
anthropicContent.push({
|
|
9365
|
+
type: "image",
|
|
9366
|
+
source: part.image instanceof URL ? {
|
|
9367
|
+
type: "url",
|
|
9368
|
+
url: part.image.toString()
|
|
9369
|
+
} : {
|
|
9370
|
+
type: "base64",
|
|
9371
|
+
media_type: (_b = part.mimeType) != null ? _b : "image/jpeg",
|
|
9372
|
+
data: convertUint8ArrayToBase64(part.image)
|
|
9373
|
+
},
|
|
9374
|
+
cache_control: cacheControl
|
|
9375
|
+
});
|
|
9376
|
+
break;
|
|
9377
|
+
}
|
|
9378
|
+
case "file": {
|
|
9379
|
+
if (part.mimeType !== "application/pdf") throw new UnsupportedFunctionalityError({ functionality: "Non-PDF files in user messages" });
|
|
9380
|
+
betas.add("pdfs-2024-09-25");
|
|
9381
|
+
anthropicContent.push({
|
|
9382
|
+
type: "document",
|
|
9383
|
+
source: part.data instanceof URL ? {
|
|
9384
|
+
type: "url",
|
|
9385
|
+
url: part.data.toString()
|
|
9386
|
+
} : {
|
|
9387
|
+
type: "base64",
|
|
9388
|
+
media_type: "application/pdf",
|
|
9389
|
+
data: part.data
|
|
9390
|
+
},
|
|
9391
|
+
cache_control: cacheControl
|
|
9392
|
+
});
|
|
9393
|
+
break;
|
|
9394
|
+
}
|
|
9395
|
+
}
|
|
9396
|
+
}
|
|
9397
|
+
break;
|
|
9398
|
+
}
|
|
9399
|
+
case "tool": {
|
|
9400
|
+
for (let i2 = 0; i2 < content.length; i2++) {
|
|
9401
|
+
const part = content[i2];
|
|
9402
|
+
const isLastPart = i2 === content.length - 1;
|
|
9403
|
+
const cacheControl = (_c = getCacheControl(part.providerMetadata)) != null ? _c : isLastPart ? getCacheControl(message.providerMetadata) : void 0;
|
|
9404
|
+
const toolResultContent = part.content != null ? part.content.map((part2) => {
|
|
9405
|
+
var _a2$2;
|
|
9406
|
+
switch (part2.type) {
|
|
9407
|
+
case "text": return {
|
|
9408
|
+
type: "text",
|
|
9409
|
+
text: part2.text,
|
|
9410
|
+
cache_control: void 0
|
|
9411
|
+
};
|
|
9412
|
+
case "image": return {
|
|
9413
|
+
type: "image",
|
|
9414
|
+
source: {
|
|
9415
|
+
type: "base64",
|
|
9416
|
+
media_type: (_a2$2 = part2.mimeType) != null ? _a2$2 : "image/jpeg",
|
|
9417
|
+
data: part2.data
|
|
9418
|
+
},
|
|
9419
|
+
cache_control: void 0
|
|
9420
|
+
};
|
|
9421
|
+
}
|
|
9422
|
+
}) : JSON.stringify(part.result);
|
|
9423
|
+
anthropicContent.push({
|
|
9424
|
+
type: "tool_result",
|
|
9425
|
+
tool_use_id: part.toolCallId,
|
|
9426
|
+
content: toolResultContent,
|
|
9427
|
+
is_error: part.isError,
|
|
9428
|
+
cache_control: cacheControl
|
|
9429
|
+
});
|
|
9430
|
+
}
|
|
9431
|
+
break;
|
|
9432
|
+
}
|
|
9433
|
+
default: {
|
|
9434
|
+
const _exhaustiveCheck = role;
|
|
9435
|
+
throw new Error(`Unsupported role: ${_exhaustiveCheck}`);
|
|
9436
|
+
}
|
|
9437
|
+
}
|
|
9438
|
+
}
|
|
9439
|
+
messages.push({
|
|
9440
|
+
role: "user",
|
|
9441
|
+
content: anthropicContent
|
|
9442
|
+
});
|
|
9443
|
+
break;
|
|
9444
|
+
}
|
|
9445
|
+
case "assistant": {
|
|
9446
|
+
const anthropicContent = [];
|
|
9447
|
+
for (let j = 0; j < block.messages.length; j++) {
|
|
9448
|
+
const message = block.messages[j];
|
|
9449
|
+
const isLastMessage = j === block.messages.length - 1;
|
|
9450
|
+
const { content } = message;
|
|
9451
|
+
for (let k = 0; k < content.length; k++) {
|
|
9452
|
+
const part = content[k];
|
|
9453
|
+
const isLastContentPart = k === content.length - 1;
|
|
9454
|
+
const cacheControl = (_d = getCacheControl(part.providerMetadata)) != null ? _d : isLastContentPart ? getCacheControl(message.providerMetadata) : void 0;
|
|
9455
|
+
switch (part.type) {
|
|
9456
|
+
case "text": {
|
|
9457
|
+
anthropicContent.push({
|
|
9458
|
+
type: "text",
|
|
9459
|
+
text: isLastBlock && isLastMessage && isLastContentPart ? part.text.trim() : part.text,
|
|
9460
|
+
cache_control: cacheControl
|
|
9461
|
+
});
|
|
9462
|
+
break;
|
|
9463
|
+
}
|
|
9464
|
+
case "reasoning": {
|
|
9465
|
+
if (sendReasoning) anthropicContent.push({
|
|
9466
|
+
type: "thinking",
|
|
9467
|
+
thinking: part.text,
|
|
9468
|
+
signature: part.signature,
|
|
9469
|
+
cache_control: cacheControl
|
|
9470
|
+
});
|
|
9471
|
+
else warnings.push({
|
|
9472
|
+
type: "other",
|
|
9473
|
+
message: "sending reasoning content is disabled for this model"
|
|
9474
|
+
});
|
|
9475
|
+
break;
|
|
9476
|
+
}
|
|
9477
|
+
case "redacted-reasoning": {
|
|
9478
|
+
anthropicContent.push({
|
|
9479
|
+
type: "redacted_thinking",
|
|
9480
|
+
data: part.data,
|
|
9481
|
+
cache_control: cacheControl
|
|
9482
|
+
});
|
|
9483
|
+
break;
|
|
9484
|
+
}
|
|
9485
|
+
case "tool-call": {
|
|
9486
|
+
anthropicContent.push({
|
|
9487
|
+
type: "tool_use",
|
|
9488
|
+
id: part.toolCallId,
|
|
9489
|
+
name: part.toolName,
|
|
9490
|
+
input: part.args,
|
|
9491
|
+
cache_control: cacheControl
|
|
9492
|
+
});
|
|
9493
|
+
break;
|
|
9494
|
+
}
|
|
9495
|
+
}
|
|
9496
|
+
}
|
|
9497
|
+
}
|
|
9498
|
+
messages.push({
|
|
9499
|
+
role: "assistant",
|
|
9500
|
+
content: anthropicContent
|
|
9501
|
+
});
|
|
9502
|
+
break;
|
|
9503
|
+
}
|
|
9504
|
+
default: {
|
|
9505
|
+
const _exhaustiveCheck = type;
|
|
9506
|
+
throw new Error(`Unsupported type: ${_exhaustiveCheck}`);
|
|
9507
|
+
}
|
|
9508
|
+
}
|
|
9509
|
+
}
|
|
9510
|
+
return {
|
|
9511
|
+
prompt: {
|
|
9512
|
+
system,
|
|
9513
|
+
messages
|
|
9514
|
+
},
|
|
9515
|
+
betas
|
|
9516
|
+
};
|
|
9517
|
+
}
|
|
9518
|
+
function groupIntoBlocks(prompt) {
|
|
9519
|
+
const blocks = [];
|
|
9520
|
+
let currentBlock = void 0;
|
|
9521
|
+
for (const message of prompt) {
|
|
9522
|
+
const { role } = message;
|
|
9523
|
+
switch (role) {
|
|
9524
|
+
case "system": {
|
|
9525
|
+
if ((currentBlock == null ? void 0 : currentBlock.type) !== "system") {
|
|
9526
|
+
currentBlock = {
|
|
9527
|
+
type: "system",
|
|
9528
|
+
messages: []
|
|
9529
|
+
};
|
|
9530
|
+
blocks.push(currentBlock);
|
|
9531
|
+
}
|
|
9532
|
+
currentBlock.messages.push(message);
|
|
9533
|
+
break;
|
|
9534
|
+
}
|
|
9535
|
+
case "assistant": {
|
|
9536
|
+
if ((currentBlock == null ? void 0 : currentBlock.type) !== "assistant") {
|
|
9537
|
+
currentBlock = {
|
|
9538
|
+
type: "assistant",
|
|
9539
|
+
messages: []
|
|
9540
|
+
};
|
|
9541
|
+
blocks.push(currentBlock);
|
|
9542
|
+
}
|
|
9543
|
+
currentBlock.messages.push(message);
|
|
9544
|
+
break;
|
|
9545
|
+
}
|
|
9546
|
+
case "user": {
|
|
9547
|
+
if ((currentBlock == null ? void 0 : currentBlock.type) !== "user") {
|
|
9548
|
+
currentBlock = {
|
|
9549
|
+
type: "user",
|
|
9550
|
+
messages: []
|
|
9551
|
+
};
|
|
9552
|
+
blocks.push(currentBlock);
|
|
9553
|
+
}
|
|
9554
|
+
currentBlock.messages.push(message);
|
|
9555
|
+
break;
|
|
9556
|
+
}
|
|
9557
|
+
case "tool": {
|
|
9558
|
+
if ((currentBlock == null ? void 0 : currentBlock.type) !== "user") {
|
|
9559
|
+
currentBlock = {
|
|
9560
|
+
type: "user",
|
|
9561
|
+
messages: []
|
|
9562
|
+
};
|
|
9563
|
+
blocks.push(currentBlock);
|
|
9564
|
+
}
|
|
9565
|
+
currentBlock.messages.push(message);
|
|
9566
|
+
break;
|
|
9567
|
+
}
|
|
9568
|
+
default: {
|
|
9569
|
+
const _exhaustiveCheck = role;
|
|
9570
|
+
throw new Error(`Unsupported role: ${_exhaustiveCheck}`);
|
|
9571
|
+
}
|
|
9572
|
+
}
|
|
9573
|
+
}
|
|
9574
|
+
return blocks;
|
|
9575
|
+
}
|
|
9576
|
+
function mapAnthropicStopReason(finishReason) {
|
|
9577
|
+
switch (finishReason) {
|
|
9578
|
+
case "end_turn":
|
|
9579
|
+
case "stop_sequence": return "stop";
|
|
9580
|
+
case "tool_use": return "tool-calls";
|
|
9581
|
+
case "max_tokens": return "length";
|
|
9582
|
+
default: return "unknown";
|
|
9583
|
+
}
|
|
9584
|
+
}
|
|
9585
|
+
var AnthropicMessagesLanguageModel = class {
|
|
9586
|
+
constructor(modelId, settings, config) {
|
|
9587
|
+
this.specificationVersion = "v1";
|
|
9588
|
+
this.defaultObjectGenerationMode = "tool";
|
|
9589
|
+
this.modelId = modelId;
|
|
9590
|
+
this.settings = settings;
|
|
9591
|
+
this.config = config;
|
|
9592
|
+
}
|
|
9593
|
+
supportsUrl(url) {
|
|
9594
|
+
return url.protocol === "https:";
|
|
9595
|
+
}
|
|
9596
|
+
get provider() {
|
|
9597
|
+
return this.config.provider;
|
|
9598
|
+
}
|
|
9599
|
+
get supportsImageUrls() {
|
|
9600
|
+
return this.config.supportsImageUrls;
|
|
9601
|
+
}
|
|
9602
|
+
async getArgs({ mode, prompt, maxTokens = 4096, temperature, topP, topK, frequencyPenalty, presencePenalty, stopSequences, responseFormat, seed, providerMetadata: providerOptions }) {
|
|
9603
|
+
var _a$2, _b, _c;
|
|
9604
|
+
const type = mode.type;
|
|
9605
|
+
const warnings = [];
|
|
9606
|
+
if (frequencyPenalty != null) warnings.push({
|
|
9607
|
+
type: "unsupported-setting",
|
|
9608
|
+
setting: "frequencyPenalty"
|
|
9609
|
+
});
|
|
9610
|
+
if (presencePenalty != null) warnings.push({
|
|
9611
|
+
type: "unsupported-setting",
|
|
9612
|
+
setting: "presencePenalty"
|
|
9613
|
+
});
|
|
9614
|
+
if (seed != null) warnings.push({
|
|
9615
|
+
type: "unsupported-setting",
|
|
9616
|
+
setting: "seed"
|
|
9617
|
+
});
|
|
9618
|
+
if (responseFormat != null && responseFormat.type !== "text") warnings.push({
|
|
9619
|
+
type: "unsupported-setting",
|
|
9620
|
+
setting: "responseFormat",
|
|
9621
|
+
details: "JSON response format is not supported."
|
|
9622
|
+
});
|
|
9623
|
+
const { prompt: messagesPrompt, betas: messagesBetas } = convertToAnthropicMessagesPrompt({
|
|
9624
|
+
prompt,
|
|
9625
|
+
sendReasoning: (_a$2 = this.settings.sendReasoning) != null ? _a$2 : true,
|
|
9626
|
+
warnings
|
|
9627
|
+
});
|
|
9628
|
+
const anthropicOptions = parseProviderOptions({
|
|
9629
|
+
provider: "anthropic",
|
|
9630
|
+
providerOptions,
|
|
9631
|
+
schema: anthropicProviderOptionsSchema
|
|
9632
|
+
});
|
|
9633
|
+
const isThinking = ((_b = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _b.type) === "enabled";
|
|
9634
|
+
const thinkingBudget = (_c = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _c.budgetTokens;
|
|
9635
|
+
const baseArgs = {
|
|
9636
|
+
model: this.modelId,
|
|
9637
|
+
max_tokens: maxTokens,
|
|
9638
|
+
temperature,
|
|
9639
|
+
top_k: topK,
|
|
9640
|
+
top_p: topP,
|
|
9641
|
+
stop_sequences: stopSequences,
|
|
9642
|
+
...isThinking && { thinking: {
|
|
9643
|
+
type: "enabled",
|
|
9644
|
+
budget_tokens: thinkingBudget
|
|
9645
|
+
} },
|
|
9646
|
+
system: messagesPrompt.system,
|
|
9647
|
+
messages: messagesPrompt.messages
|
|
9648
|
+
};
|
|
9649
|
+
if (isThinking) {
|
|
9650
|
+
if (thinkingBudget == null) throw new UnsupportedFunctionalityError({ functionality: "thinking requires a budget" });
|
|
9651
|
+
if (baseArgs.temperature != null) {
|
|
9652
|
+
baseArgs.temperature = void 0;
|
|
9653
|
+
warnings.push({
|
|
9654
|
+
type: "unsupported-setting",
|
|
9655
|
+
setting: "temperature",
|
|
9656
|
+
details: "temperature is not supported when thinking is enabled"
|
|
9657
|
+
});
|
|
9658
|
+
}
|
|
9659
|
+
if (topK != null) {
|
|
9660
|
+
baseArgs.top_k = void 0;
|
|
9661
|
+
warnings.push({
|
|
9662
|
+
type: "unsupported-setting",
|
|
9663
|
+
setting: "topK",
|
|
9664
|
+
details: "topK is not supported when thinking is enabled"
|
|
9665
|
+
});
|
|
9666
|
+
}
|
|
9667
|
+
if (topP != null) {
|
|
9668
|
+
baseArgs.top_p = void 0;
|
|
9669
|
+
warnings.push({
|
|
9670
|
+
type: "unsupported-setting",
|
|
9671
|
+
setting: "topP",
|
|
9672
|
+
details: "topP is not supported when thinking is enabled"
|
|
9673
|
+
});
|
|
9674
|
+
}
|
|
9675
|
+
baseArgs.max_tokens = maxTokens + thinkingBudget;
|
|
9676
|
+
}
|
|
9677
|
+
switch (type) {
|
|
9678
|
+
case "regular": {
|
|
9679
|
+
const { tools, tool_choice, toolWarnings, betas: toolsBetas } = prepareTools(mode);
|
|
9680
|
+
return {
|
|
9681
|
+
args: {
|
|
9682
|
+
...baseArgs,
|
|
9683
|
+
tools,
|
|
9684
|
+
tool_choice
|
|
9685
|
+
},
|
|
9686
|
+
warnings: [...warnings, ...toolWarnings],
|
|
9687
|
+
betas: /* @__PURE__ */ new Set([...messagesBetas, ...toolsBetas])
|
|
9688
|
+
};
|
|
9689
|
+
}
|
|
9690
|
+
case "object-json": throw new UnsupportedFunctionalityError({ functionality: "json-mode object generation" });
|
|
9691
|
+
case "object-tool": {
|
|
9692
|
+
const { name: name$2, description: description$73, parameters } = mode.tool;
|
|
9693
|
+
return {
|
|
9694
|
+
args: {
|
|
9695
|
+
...baseArgs,
|
|
9696
|
+
tools: [{
|
|
9697
|
+
name: name$2,
|
|
9698
|
+
description: description$73,
|
|
9699
|
+
input_schema: parameters
|
|
9700
|
+
}],
|
|
9701
|
+
tool_choice: {
|
|
9702
|
+
type: "tool",
|
|
9703
|
+
name: name$2
|
|
9704
|
+
}
|
|
9705
|
+
},
|
|
9706
|
+
warnings,
|
|
9707
|
+
betas: messagesBetas
|
|
9708
|
+
};
|
|
9709
|
+
}
|
|
9710
|
+
default: {
|
|
9711
|
+
const _exhaustiveCheck = type;
|
|
9712
|
+
throw new Error(`Unsupported type: ${_exhaustiveCheck}`);
|
|
9713
|
+
}
|
|
9714
|
+
}
|
|
9715
|
+
}
|
|
9716
|
+
async getHeaders({ betas, headers }) {
|
|
9717
|
+
return combineHeaders(await resolve(this.config.headers), betas.size > 0 ? { "anthropic-beta": Array.from(betas).join(",") } : {}, headers);
|
|
9718
|
+
}
|
|
9719
|
+
buildRequestUrl(isStreaming) {
|
|
9720
|
+
var _a$2, _b, _c;
|
|
9721
|
+
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`;
|
|
9722
|
+
}
|
|
9723
|
+
transformRequestBody(args) {
|
|
9724
|
+
var _a$2, _b, _c;
|
|
9725
|
+
return (_c = (_b = (_a$2 = this.config).transformRequestBody) == null ? void 0 : _b.call(_a$2, args)) != null ? _c : args;
|
|
9726
|
+
}
|
|
9727
|
+
async doGenerate(options) {
|
|
9728
|
+
var _a$2, _b, _c, _d;
|
|
9729
|
+
const { args, warnings, betas } = await this.getArgs(options);
|
|
9730
|
+
const { responseHeaders, value: response, rawValue: rawResponse } = await postJsonToApi({
|
|
9731
|
+
url: this.buildRequestUrl(false),
|
|
9732
|
+
headers: await this.getHeaders({
|
|
9733
|
+
betas,
|
|
9734
|
+
headers: options.headers
|
|
9735
|
+
}),
|
|
9736
|
+
body: this.transformRequestBody(args),
|
|
9737
|
+
failedResponseHandler: anthropicFailedResponseHandler,
|
|
9738
|
+
successfulResponseHandler: createJsonResponseHandler(anthropicMessagesResponseSchema),
|
|
9739
|
+
abortSignal: options.abortSignal,
|
|
9740
|
+
fetch: this.config.fetch
|
|
9741
|
+
});
|
|
9742
|
+
const { messages: rawPrompt,...rawSettings } = args;
|
|
9743
|
+
let text$1 = "";
|
|
9744
|
+
for (const content of response.content) if (content.type === "text") text$1 += content.text;
|
|
9745
|
+
let toolCalls = void 0;
|
|
9746
|
+
if (response.content.some((content) => content.type === "tool_use")) {
|
|
9747
|
+
toolCalls = [];
|
|
9748
|
+
for (const content of response.content) if (content.type === "tool_use") toolCalls.push({
|
|
9749
|
+
toolCallType: "function",
|
|
9750
|
+
toolCallId: content.id,
|
|
9751
|
+
toolName: content.name,
|
|
9752
|
+
args: JSON.stringify(content.input)
|
|
9753
|
+
});
|
|
9754
|
+
}
|
|
9755
|
+
const reasoning = response.content.filter((content) => content.type === "redacted_thinking" || content.type === "thinking").map((content) => content.type === "thinking" ? {
|
|
9756
|
+
type: "text",
|
|
9757
|
+
text: content.thinking,
|
|
9758
|
+
signature: content.signature
|
|
9759
|
+
} : {
|
|
9760
|
+
type: "redacted",
|
|
9761
|
+
data: content.data
|
|
9762
|
+
});
|
|
9763
|
+
return {
|
|
9764
|
+
text: text$1,
|
|
9765
|
+
reasoning: reasoning.length > 0 ? reasoning : void 0,
|
|
9766
|
+
toolCalls,
|
|
9767
|
+
finishReason: mapAnthropicStopReason(response.stop_reason),
|
|
9768
|
+
usage: {
|
|
9769
|
+
promptTokens: response.usage.input_tokens,
|
|
9770
|
+
completionTokens: response.usage.output_tokens
|
|
9771
|
+
},
|
|
9772
|
+
rawCall: {
|
|
9773
|
+
rawPrompt,
|
|
9774
|
+
rawSettings
|
|
9775
|
+
},
|
|
9776
|
+
rawResponse: {
|
|
9777
|
+
headers: responseHeaders,
|
|
9778
|
+
body: rawResponse
|
|
9779
|
+
},
|
|
9780
|
+
response: {
|
|
9781
|
+
id: (_a$2 = response.id) != null ? _a$2 : void 0,
|
|
9782
|
+
modelId: (_b = response.model) != null ? _b : void 0
|
|
9783
|
+
},
|
|
9784
|
+
warnings,
|
|
9785
|
+
providerMetadata: { anthropic: {
|
|
9786
|
+
cacheCreationInputTokens: (_c = response.usage.cache_creation_input_tokens) != null ? _c : null,
|
|
9787
|
+
cacheReadInputTokens: (_d = response.usage.cache_read_input_tokens) != null ? _d : null
|
|
9788
|
+
} },
|
|
9789
|
+
request: { body: JSON.stringify(args) }
|
|
9790
|
+
};
|
|
9791
|
+
}
|
|
9792
|
+
async doStream(options) {
|
|
9793
|
+
const { args, warnings, betas } = await this.getArgs(options);
|
|
9794
|
+
const body = {
|
|
9795
|
+
...args,
|
|
9796
|
+
stream: true
|
|
9797
|
+
};
|
|
9798
|
+
const { responseHeaders, value: response } = await postJsonToApi({
|
|
9799
|
+
url: this.buildRequestUrl(true),
|
|
9800
|
+
headers: await this.getHeaders({
|
|
9801
|
+
betas,
|
|
9802
|
+
headers: options.headers
|
|
9803
|
+
}),
|
|
9804
|
+
body: this.transformRequestBody(body),
|
|
9805
|
+
failedResponseHandler: anthropicFailedResponseHandler,
|
|
9806
|
+
successfulResponseHandler: createEventSourceResponseHandler(anthropicMessagesChunkSchema),
|
|
9807
|
+
abortSignal: options.abortSignal,
|
|
9808
|
+
fetch: this.config.fetch
|
|
9809
|
+
});
|
|
9810
|
+
const { messages: rawPrompt,...rawSettings } = args;
|
|
9811
|
+
let finishReason = "unknown";
|
|
9812
|
+
const usage = {
|
|
9813
|
+
promptTokens: NaN,
|
|
9814
|
+
completionTokens: NaN
|
|
9815
|
+
};
|
|
9816
|
+
const toolCallContentBlocks = {};
|
|
9817
|
+
let providerMetadata = void 0;
|
|
9818
|
+
let blockType = void 0;
|
|
9819
|
+
return {
|
|
9820
|
+
stream: response.pipeThrough(new TransformStream({ transform(chunk, controller) {
|
|
9821
|
+
var _a$2, _b, _c, _d;
|
|
9822
|
+
if (!chunk.success) {
|
|
9823
|
+
controller.enqueue({
|
|
9824
|
+
type: "error",
|
|
9825
|
+
error: chunk.error
|
|
9826
|
+
});
|
|
9827
|
+
return;
|
|
9828
|
+
}
|
|
9829
|
+
const value = chunk.value;
|
|
9830
|
+
switch (value.type) {
|
|
9831
|
+
case "ping": return;
|
|
9832
|
+
case "content_block_start": {
|
|
9833
|
+
const contentBlockType = value.content_block.type;
|
|
9834
|
+
blockType = contentBlockType;
|
|
9835
|
+
switch (contentBlockType) {
|
|
9836
|
+
case "text":
|
|
9837
|
+
case "thinking": return;
|
|
9838
|
+
case "redacted_thinking": {
|
|
9839
|
+
controller.enqueue({
|
|
9840
|
+
type: "redacted-reasoning",
|
|
9841
|
+
data: value.content_block.data
|
|
9842
|
+
});
|
|
9843
|
+
return;
|
|
9844
|
+
}
|
|
9845
|
+
case "tool_use": {
|
|
9846
|
+
toolCallContentBlocks[value.index] = {
|
|
9847
|
+
toolCallId: value.content_block.id,
|
|
9848
|
+
toolName: value.content_block.name,
|
|
9849
|
+
jsonText: ""
|
|
9850
|
+
};
|
|
9851
|
+
return;
|
|
9852
|
+
}
|
|
9853
|
+
default: {
|
|
9854
|
+
const _exhaustiveCheck = contentBlockType;
|
|
9855
|
+
throw new Error(`Unsupported content block type: ${_exhaustiveCheck}`);
|
|
9856
|
+
}
|
|
9857
|
+
}
|
|
9858
|
+
}
|
|
9859
|
+
case "content_block_stop": {
|
|
9860
|
+
if (toolCallContentBlocks[value.index] != null) {
|
|
9861
|
+
const contentBlock = toolCallContentBlocks[value.index];
|
|
9862
|
+
controller.enqueue({
|
|
9863
|
+
type: "tool-call",
|
|
9864
|
+
toolCallType: "function",
|
|
9865
|
+
toolCallId: contentBlock.toolCallId,
|
|
9866
|
+
toolName: contentBlock.toolName,
|
|
9867
|
+
args: contentBlock.jsonText
|
|
9868
|
+
});
|
|
9869
|
+
delete toolCallContentBlocks[value.index];
|
|
9870
|
+
}
|
|
9871
|
+
blockType = void 0;
|
|
9872
|
+
return;
|
|
9873
|
+
}
|
|
9874
|
+
case "content_block_delta": {
|
|
9875
|
+
const deltaType = value.delta.type;
|
|
9876
|
+
switch (deltaType) {
|
|
9877
|
+
case "text_delta": {
|
|
9878
|
+
controller.enqueue({
|
|
9879
|
+
type: "text-delta",
|
|
9880
|
+
textDelta: value.delta.text
|
|
9881
|
+
});
|
|
9882
|
+
return;
|
|
9883
|
+
}
|
|
9884
|
+
case "thinking_delta": {
|
|
9885
|
+
controller.enqueue({
|
|
9886
|
+
type: "reasoning",
|
|
9887
|
+
textDelta: value.delta.thinking
|
|
9888
|
+
});
|
|
9889
|
+
return;
|
|
9890
|
+
}
|
|
9891
|
+
case "signature_delta": {
|
|
9892
|
+
if (blockType === "thinking") controller.enqueue({
|
|
9893
|
+
type: "reasoning-signature",
|
|
9894
|
+
signature: value.delta.signature
|
|
9895
|
+
});
|
|
9896
|
+
return;
|
|
9897
|
+
}
|
|
9898
|
+
case "input_json_delta": {
|
|
9899
|
+
const contentBlock = toolCallContentBlocks[value.index];
|
|
9900
|
+
controller.enqueue({
|
|
9901
|
+
type: "tool-call-delta",
|
|
9902
|
+
toolCallType: "function",
|
|
9903
|
+
toolCallId: contentBlock.toolCallId,
|
|
9904
|
+
toolName: contentBlock.toolName,
|
|
9905
|
+
argsTextDelta: value.delta.partial_json
|
|
9906
|
+
});
|
|
9907
|
+
contentBlock.jsonText += value.delta.partial_json;
|
|
9908
|
+
return;
|
|
9909
|
+
}
|
|
9910
|
+
default: {
|
|
9911
|
+
const _exhaustiveCheck = deltaType;
|
|
9912
|
+
throw new Error(`Unsupported delta type: ${_exhaustiveCheck}`);
|
|
9913
|
+
}
|
|
9914
|
+
}
|
|
9915
|
+
}
|
|
9916
|
+
case "message_start": {
|
|
9917
|
+
usage.promptTokens = value.message.usage.input_tokens;
|
|
9918
|
+
usage.completionTokens = value.message.usage.output_tokens;
|
|
9919
|
+
providerMetadata = { anthropic: {
|
|
9920
|
+
cacheCreationInputTokens: (_a$2 = value.message.usage.cache_creation_input_tokens) != null ? _a$2 : null,
|
|
9921
|
+
cacheReadInputTokens: (_b = value.message.usage.cache_read_input_tokens) != null ? _b : null
|
|
9922
|
+
} };
|
|
9923
|
+
controller.enqueue({
|
|
9924
|
+
type: "response-metadata",
|
|
9925
|
+
id: (_c = value.message.id) != null ? _c : void 0,
|
|
9926
|
+
modelId: (_d = value.message.model) != null ? _d : void 0
|
|
9927
|
+
});
|
|
9928
|
+
return;
|
|
9929
|
+
}
|
|
9930
|
+
case "message_delta": {
|
|
9931
|
+
usage.completionTokens = value.usage.output_tokens;
|
|
9932
|
+
finishReason = mapAnthropicStopReason(value.delta.stop_reason);
|
|
9933
|
+
return;
|
|
9934
|
+
}
|
|
9935
|
+
case "message_stop": {
|
|
9936
|
+
controller.enqueue({
|
|
9937
|
+
type: "finish",
|
|
9938
|
+
finishReason,
|
|
9939
|
+
usage,
|
|
9940
|
+
providerMetadata
|
|
9941
|
+
});
|
|
9942
|
+
return;
|
|
9943
|
+
}
|
|
9944
|
+
case "error": {
|
|
9945
|
+
controller.enqueue({
|
|
9946
|
+
type: "error",
|
|
9947
|
+
error: value.error
|
|
9948
|
+
});
|
|
9949
|
+
return;
|
|
9950
|
+
}
|
|
9951
|
+
default: {
|
|
9952
|
+
const _exhaustiveCheck = value;
|
|
9953
|
+
throw new Error(`Unsupported chunk type: ${_exhaustiveCheck}`);
|
|
9954
|
+
}
|
|
9955
|
+
}
|
|
9956
|
+
} })),
|
|
9957
|
+
rawCall: {
|
|
9958
|
+
rawPrompt,
|
|
9959
|
+
rawSettings
|
|
9960
|
+
},
|
|
9961
|
+
rawResponse: { headers: responseHeaders },
|
|
9962
|
+
warnings,
|
|
9963
|
+
request: { body: JSON.stringify(body) }
|
|
9964
|
+
};
|
|
9965
|
+
}
|
|
9966
|
+
};
|
|
9967
|
+
var anthropicMessagesResponseSchema = zod.z.object({
|
|
9968
|
+
type: zod.z.literal("message"),
|
|
9969
|
+
id: zod.z.string().nullish(),
|
|
9970
|
+
model: zod.z.string().nullish(),
|
|
9971
|
+
content: zod.z.array(zod.z.discriminatedUnion("type", [
|
|
9972
|
+
zod.z.object({
|
|
9973
|
+
type: zod.z.literal("text"),
|
|
9974
|
+
text: zod.z.string()
|
|
9975
|
+
}),
|
|
9976
|
+
zod.z.object({
|
|
9977
|
+
type: zod.z.literal("thinking"),
|
|
9978
|
+
thinking: zod.z.string(),
|
|
9979
|
+
signature: zod.z.string()
|
|
9980
|
+
}),
|
|
9981
|
+
zod.z.object({
|
|
9982
|
+
type: zod.z.literal("redacted_thinking"),
|
|
9983
|
+
data: zod.z.string()
|
|
9984
|
+
}),
|
|
9985
|
+
zod.z.object({
|
|
9986
|
+
type: zod.z.literal("tool_use"),
|
|
9987
|
+
id: zod.z.string(),
|
|
9988
|
+
name: zod.z.string(),
|
|
9989
|
+
input: zod.z.unknown()
|
|
9990
|
+
})
|
|
9991
|
+
])),
|
|
9992
|
+
stop_reason: zod.z.string().nullish(),
|
|
9993
|
+
usage: zod.z.object({
|
|
9994
|
+
input_tokens: zod.z.number(),
|
|
9995
|
+
output_tokens: zod.z.number(),
|
|
9996
|
+
cache_creation_input_tokens: zod.z.number().nullish(),
|
|
9997
|
+
cache_read_input_tokens: zod.z.number().nullish()
|
|
9998
|
+
})
|
|
9999
|
+
});
|
|
10000
|
+
var anthropicMessagesChunkSchema = zod.z.discriminatedUnion("type", [
|
|
10001
|
+
zod.z.object({
|
|
10002
|
+
type: zod.z.literal("message_start"),
|
|
10003
|
+
message: zod.z.object({
|
|
10004
|
+
id: zod.z.string().nullish(),
|
|
10005
|
+
model: zod.z.string().nullish(),
|
|
10006
|
+
usage: zod.z.object({
|
|
10007
|
+
input_tokens: zod.z.number(),
|
|
10008
|
+
output_tokens: zod.z.number(),
|
|
10009
|
+
cache_creation_input_tokens: zod.z.number().nullish(),
|
|
10010
|
+
cache_read_input_tokens: zod.z.number().nullish()
|
|
10011
|
+
})
|
|
10012
|
+
})
|
|
10013
|
+
}),
|
|
10014
|
+
zod.z.object({
|
|
10015
|
+
type: zod.z.literal("content_block_start"),
|
|
10016
|
+
index: zod.z.number(),
|
|
10017
|
+
content_block: zod.z.discriminatedUnion("type", [
|
|
10018
|
+
zod.z.object({
|
|
10019
|
+
type: zod.z.literal("text"),
|
|
10020
|
+
text: zod.z.string()
|
|
10021
|
+
}),
|
|
10022
|
+
zod.z.object({
|
|
10023
|
+
type: zod.z.literal("thinking"),
|
|
10024
|
+
thinking: zod.z.string()
|
|
10025
|
+
}),
|
|
10026
|
+
zod.z.object({
|
|
10027
|
+
type: zod.z.literal("tool_use"),
|
|
10028
|
+
id: zod.z.string(),
|
|
10029
|
+
name: zod.z.string()
|
|
10030
|
+
}),
|
|
10031
|
+
zod.z.object({
|
|
10032
|
+
type: zod.z.literal("redacted_thinking"),
|
|
10033
|
+
data: zod.z.string()
|
|
10034
|
+
})
|
|
10035
|
+
])
|
|
10036
|
+
}),
|
|
10037
|
+
zod.z.object({
|
|
10038
|
+
type: zod.z.literal("content_block_delta"),
|
|
10039
|
+
index: zod.z.number(),
|
|
10040
|
+
delta: zod.z.discriminatedUnion("type", [
|
|
10041
|
+
zod.z.object({
|
|
10042
|
+
type: zod.z.literal("input_json_delta"),
|
|
10043
|
+
partial_json: zod.z.string()
|
|
10044
|
+
}),
|
|
10045
|
+
zod.z.object({
|
|
10046
|
+
type: zod.z.literal("text_delta"),
|
|
10047
|
+
text: zod.z.string()
|
|
10048
|
+
}),
|
|
10049
|
+
zod.z.object({
|
|
10050
|
+
type: zod.z.literal("thinking_delta"),
|
|
10051
|
+
thinking: zod.z.string()
|
|
10052
|
+
}),
|
|
10053
|
+
zod.z.object({
|
|
10054
|
+
type: zod.z.literal("signature_delta"),
|
|
10055
|
+
signature: zod.z.string()
|
|
10056
|
+
})
|
|
10057
|
+
])
|
|
10058
|
+
}),
|
|
10059
|
+
zod.z.object({
|
|
10060
|
+
type: zod.z.literal("content_block_stop"),
|
|
10061
|
+
index: zod.z.number()
|
|
10062
|
+
}),
|
|
10063
|
+
zod.z.object({
|
|
10064
|
+
type: zod.z.literal("error"),
|
|
10065
|
+
error: zod.z.object({
|
|
10066
|
+
type: zod.z.string(),
|
|
10067
|
+
message: zod.z.string()
|
|
10068
|
+
})
|
|
10069
|
+
}),
|
|
10070
|
+
zod.z.object({
|
|
10071
|
+
type: zod.z.literal("message_delta"),
|
|
10072
|
+
delta: zod.z.object({ stop_reason: zod.z.string().nullish() }),
|
|
10073
|
+
usage: zod.z.object({ output_tokens: zod.z.number() })
|
|
10074
|
+
}),
|
|
10075
|
+
zod.z.object({ type: zod.z.literal("message_stop") }),
|
|
10076
|
+
zod.z.object({ type: zod.z.literal("ping") })
|
|
10077
|
+
]);
|
|
10078
|
+
var anthropicProviderOptionsSchema = zod.z.object({ thinking: zod.z.object({
|
|
10079
|
+
type: zod.z.union([zod.z.literal("enabled"), zod.z.literal("disabled")]),
|
|
10080
|
+
budgetTokens: zod.z.number().optional()
|
|
10081
|
+
}).optional() });
|
|
10082
|
+
var Bash20241022Parameters = zod.z.object({
|
|
10083
|
+
command: zod.z.string(),
|
|
10084
|
+
restart: zod.z.boolean().optional()
|
|
10085
|
+
});
|
|
10086
|
+
function bashTool_20241022(options = {}) {
|
|
10087
|
+
return {
|
|
10088
|
+
type: "provider-defined",
|
|
10089
|
+
id: "anthropic.bash_20241022",
|
|
10090
|
+
args: {},
|
|
10091
|
+
parameters: Bash20241022Parameters,
|
|
10092
|
+
execute: options.execute,
|
|
10093
|
+
experimental_toToolResultContent: options.experimental_toToolResultContent
|
|
10094
|
+
};
|
|
10095
|
+
}
|
|
10096
|
+
var Bash20250124Parameters = zod.z.object({
|
|
10097
|
+
command: zod.z.string(),
|
|
10098
|
+
restart: zod.z.boolean().optional()
|
|
10099
|
+
});
|
|
10100
|
+
function bashTool_20250124(options = {}) {
|
|
10101
|
+
return {
|
|
10102
|
+
type: "provider-defined",
|
|
10103
|
+
id: "anthropic.bash_20250124",
|
|
10104
|
+
args: {},
|
|
10105
|
+
parameters: Bash20250124Parameters,
|
|
10106
|
+
execute: options.execute,
|
|
10107
|
+
experimental_toToolResultContent: options.experimental_toToolResultContent
|
|
10108
|
+
};
|
|
10109
|
+
}
|
|
10110
|
+
var TextEditor20241022Parameters = zod.z.object({
|
|
10111
|
+
command: zod.z.enum([
|
|
10112
|
+
"view",
|
|
10113
|
+
"create",
|
|
10114
|
+
"str_replace",
|
|
10115
|
+
"insert",
|
|
10116
|
+
"undo_edit"
|
|
10117
|
+
]),
|
|
10118
|
+
path: zod.z.string(),
|
|
10119
|
+
file_text: zod.z.string().optional(),
|
|
10120
|
+
insert_line: zod.z.number().int().optional(),
|
|
10121
|
+
new_str: zod.z.string().optional(),
|
|
10122
|
+
old_str: zod.z.string().optional(),
|
|
10123
|
+
view_range: zod.z.array(zod.z.number().int()).optional()
|
|
10124
|
+
});
|
|
10125
|
+
function textEditorTool_20241022(options = {}) {
|
|
10126
|
+
return {
|
|
10127
|
+
type: "provider-defined",
|
|
10128
|
+
id: "anthropic.text_editor_20241022",
|
|
10129
|
+
args: {},
|
|
10130
|
+
parameters: TextEditor20241022Parameters,
|
|
10131
|
+
execute: options.execute,
|
|
10132
|
+
experimental_toToolResultContent: options.experimental_toToolResultContent
|
|
10133
|
+
};
|
|
10134
|
+
}
|
|
10135
|
+
var TextEditor20250124Parameters = zod.z.object({
|
|
10136
|
+
command: zod.z.enum([
|
|
10137
|
+
"view",
|
|
10138
|
+
"create",
|
|
10139
|
+
"str_replace",
|
|
10140
|
+
"insert",
|
|
10141
|
+
"undo_edit"
|
|
10142
|
+
]),
|
|
10143
|
+
path: zod.z.string(),
|
|
10144
|
+
file_text: zod.z.string().optional(),
|
|
10145
|
+
insert_line: zod.z.number().int().optional(),
|
|
10146
|
+
new_str: zod.z.string().optional(),
|
|
10147
|
+
old_str: zod.z.string().optional(),
|
|
10148
|
+
view_range: zod.z.array(zod.z.number().int()).optional()
|
|
10149
|
+
});
|
|
10150
|
+
function textEditorTool_20250124(options = {}) {
|
|
10151
|
+
return {
|
|
10152
|
+
type: "provider-defined",
|
|
10153
|
+
id: "anthropic.text_editor_20250124",
|
|
10154
|
+
args: {},
|
|
10155
|
+
parameters: TextEditor20250124Parameters,
|
|
10156
|
+
execute: options.execute,
|
|
10157
|
+
experimental_toToolResultContent: options.experimental_toToolResultContent
|
|
10158
|
+
};
|
|
10159
|
+
}
|
|
10160
|
+
var Computer20241022Parameters = zod.z.object({
|
|
10161
|
+
action: zod.z.enum([
|
|
10162
|
+
"key",
|
|
10163
|
+
"type",
|
|
10164
|
+
"mouse_move",
|
|
10165
|
+
"left_click",
|
|
10166
|
+
"left_click_drag",
|
|
10167
|
+
"right_click",
|
|
10168
|
+
"middle_click",
|
|
10169
|
+
"double_click",
|
|
10170
|
+
"screenshot",
|
|
10171
|
+
"cursor_position"
|
|
10172
|
+
]),
|
|
10173
|
+
coordinate: zod.z.array(zod.z.number().int()).optional(),
|
|
10174
|
+
text: zod.z.string().optional()
|
|
10175
|
+
});
|
|
10176
|
+
function computerTool_20241022(options) {
|
|
10177
|
+
return {
|
|
10178
|
+
type: "provider-defined",
|
|
10179
|
+
id: "anthropic.computer_20241022",
|
|
10180
|
+
args: {
|
|
10181
|
+
displayWidthPx: options.displayWidthPx,
|
|
10182
|
+
displayHeightPx: options.displayHeightPx,
|
|
10183
|
+
displayNumber: options.displayNumber
|
|
10184
|
+
},
|
|
10185
|
+
parameters: Computer20241022Parameters,
|
|
10186
|
+
execute: options.execute,
|
|
10187
|
+
experimental_toToolResultContent: options.experimental_toToolResultContent
|
|
10188
|
+
};
|
|
10189
|
+
}
|
|
10190
|
+
var Computer20250124Parameters = zod.z.object({
|
|
10191
|
+
action: zod.z.enum([
|
|
10192
|
+
"key",
|
|
10193
|
+
"hold_key",
|
|
10194
|
+
"type",
|
|
10195
|
+
"cursor_position",
|
|
10196
|
+
"mouse_move",
|
|
10197
|
+
"left_mouse_down",
|
|
10198
|
+
"left_mouse_up",
|
|
10199
|
+
"left_click",
|
|
10200
|
+
"left_click_drag",
|
|
10201
|
+
"right_click",
|
|
10202
|
+
"middle_click",
|
|
10203
|
+
"double_click",
|
|
10204
|
+
"triple_click",
|
|
10205
|
+
"scroll",
|
|
10206
|
+
"wait",
|
|
10207
|
+
"screenshot"
|
|
10208
|
+
]),
|
|
10209
|
+
coordinate: zod.z.tuple([zod.z.number().int(), zod.z.number().int()]).optional(),
|
|
10210
|
+
duration: zod.z.number().optional(),
|
|
10211
|
+
scroll_amount: zod.z.number().optional(),
|
|
10212
|
+
scroll_direction: zod.z.enum([
|
|
10213
|
+
"up",
|
|
10214
|
+
"down",
|
|
10215
|
+
"left",
|
|
10216
|
+
"right"
|
|
10217
|
+
]).optional(),
|
|
10218
|
+
start_coordinate: zod.z.tuple([zod.z.number().int(), zod.z.number().int()]).optional(),
|
|
10219
|
+
text: zod.z.string().optional()
|
|
10220
|
+
});
|
|
10221
|
+
function computerTool_20250124(options) {
|
|
10222
|
+
return {
|
|
10223
|
+
type: "provider-defined",
|
|
10224
|
+
id: "anthropic.computer_20250124",
|
|
10225
|
+
args: {
|
|
10226
|
+
displayWidthPx: options.displayWidthPx,
|
|
10227
|
+
displayHeightPx: options.displayHeightPx,
|
|
10228
|
+
displayNumber: options.displayNumber
|
|
10229
|
+
},
|
|
10230
|
+
parameters: Computer20250124Parameters,
|
|
10231
|
+
execute: options.execute,
|
|
10232
|
+
experimental_toToolResultContent: options.experimental_toToolResultContent
|
|
10233
|
+
};
|
|
10234
|
+
}
|
|
10235
|
+
var anthropicTools = {
|
|
10236
|
+
bash_20241022: bashTool_20241022,
|
|
10237
|
+
bash_20250124: bashTool_20250124,
|
|
10238
|
+
textEditor_20241022: textEditorTool_20241022,
|
|
10239
|
+
textEditor_20250124: textEditorTool_20250124,
|
|
10240
|
+
computer_20241022: computerTool_20241022,
|
|
10241
|
+
computer_20250124: computerTool_20250124
|
|
10242
|
+
};
|
|
10243
|
+
function createAnthropic(options = {}) {
|
|
10244
|
+
var _a$2;
|
|
10245
|
+
const baseURL = (_a$2 = withoutTrailingSlash(options.baseURL)) != null ? _a$2 : "https://api.anthropic.com/v1";
|
|
10246
|
+
const getHeaders = () => ({
|
|
10247
|
+
"anthropic-version": "2023-06-01",
|
|
10248
|
+
"x-api-key": loadApiKey({
|
|
10249
|
+
apiKey: options.apiKey,
|
|
10250
|
+
environmentVariableName: "ANTHROPIC_API_KEY",
|
|
10251
|
+
description: "Anthropic"
|
|
10252
|
+
}),
|
|
10253
|
+
...options.headers
|
|
10254
|
+
});
|
|
10255
|
+
const createChatModel = (modelId, settings = {}) => new AnthropicMessagesLanguageModel(modelId, settings, {
|
|
10256
|
+
provider: "anthropic.messages",
|
|
10257
|
+
baseURL,
|
|
10258
|
+
headers: getHeaders,
|
|
10259
|
+
fetch: options.fetch,
|
|
10260
|
+
supportsImageUrls: true
|
|
10261
|
+
});
|
|
10262
|
+
const provider = function(modelId, settings) {
|
|
10263
|
+
if (new.target) throw new Error("The Anthropic model function cannot be called with the new keyword.");
|
|
10264
|
+
return createChatModel(modelId, settings);
|
|
10265
|
+
};
|
|
10266
|
+
provider.languageModel = createChatModel;
|
|
10267
|
+
provider.chat = createChatModel;
|
|
10268
|
+
provider.messages = createChatModel;
|
|
10269
|
+
provider.textEmbeddingModel = (modelId) => {
|
|
10270
|
+
throw new NoSuchModelError({
|
|
10271
|
+
modelId,
|
|
10272
|
+
modelType: "textEmbeddingModel"
|
|
10273
|
+
});
|
|
10274
|
+
};
|
|
10275
|
+
provider.tools = anthropicTools;
|
|
10276
|
+
return provider;
|
|
10277
|
+
}
|
|
10278
|
+
var anthropic = createAnthropic();
|
|
8950
10279
|
|
|
8951
10280
|
//#endregion
|
|
8952
|
-
//#region ../mcp-core/dist/
|
|
8953
|
-
const
|
|
8954
|
-
const VALID_REASONING_EFFORTS = [
|
|
8955
|
-
"low",
|
|
8956
|
-
"medium",
|
|
8957
|
-
"high"
|
|
8958
|
-
];
|
|
8959
|
-
const DEFAULT_REASONING_EFFORT = "low";
|
|
10281
|
+
//#region ../mcp-core/dist/anthropic-provider-BGKT8f9G.js
|
|
10282
|
+
const DEFAULT_ANTHROPIC_MODEL = "claude-sonnet-4-5";
|
|
8960
10283
|
let configuredBaseUrl;
|
|
8961
10284
|
/**
|
|
8962
|
-
* Configure the
|
|
10285
|
+
* Configure the Anthropic base URL (CLI flag only, not environment variable).
|
|
8963
10286
|
* This must be called explicitly - it cannot be set via environment variables for security.
|
|
8964
10287
|
*/
|
|
8965
|
-
function
|
|
10288
|
+
function setAnthropicBaseUrl(baseUrl) {
|
|
8966
10289
|
configuredBaseUrl = baseUrl;
|
|
8967
10290
|
}
|
|
8968
10291
|
/**
|
|
8969
|
-
* Retrieve an
|
|
10292
|
+
* Retrieve an Anthropic language model configured from environment variables and explicit config.
|
|
8970
10293
|
*
|
|
8971
10294
|
* Configuration:
|
|
8972
|
-
* -
|
|
8973
|
-
* -
|
|
8974
|
-
* - Base URL: Must be set via setOpenAIBaseUrl() - NOT from env vars (security risk)
|
|
10295
|
+
* - ANTHROPIC_MODEL: Model to use (default: "claude-sonnet-4-5") - env var OK
|
|
10296
|
+
* - Base URL: Must be set via setAnthropicBaseUrl() - NOT from env vars (security risk)
|
|
8975
10297
|
*/
|
|
8976
|
-
function
|
|
8977
|
-
const defaultModel = process.env.
|
|
8978
|
-
const
|
|
8979
|
-
let reasoningEffort;
|
|
8980
|
-
if (envReasoningEffort === "") reasoningEffort = void 0;
|
|
8981
|
-
else if (envReasoningEffort === void 0) reasoningEffort = DEFAULT_REASONING_EFFORT;
|
|
8982
|
-
else if (VALID_REASONING_EFFORTS.includes(envReasoningEffort)) reasoningEffort = envReasoningEffort;
|
|
8983
|
-
else {
|
|
8984
|
-
const validValues = VALID_REASONING_EFFORTS.map((v) => `"${v}"`).join(", ");
|
|
8985
|
-
throw new Error(`Invalid OPENAI_REASONING_EFFORT value: "${envReasoningEffort}". Must be one of: ${validValues}, or "" (empty string to disable). Default is "${DEFAULT_REASONING_EFFORT}".`);
|
|
8986
|
-
}
|
|
8987
|
-
const factory = createOpenAI({
|
|
10298
|
+
function getAnthropicModel(model) {
|
|
10299
|
+
const defaultModel = process.env.ANTHROPIC_MODEL || DEFAULT_ANTHROPIC_MODEL;
|
|
10300
|
+
const factory = createAnthropic({
|
|
8988
10301
|
...configuredBaseUrl && { baseURL: configuredBaseUrl },
|
|
8989
10302
|
headers: { "User-Agent": require_stdio.USER_AGENT }
|
|
8990
10303
|
});
|
|
8991
|
-
return factory(model ?? defaultModel
|
|
10304
|
+
return factory(model ?? defaultModel);
|
|
10305
|
+
}
|
|
10306
|
+
|
|
10307
|
+
//#endregion
|
|
10308
|
+
//#region ../mcp-core/dist/provider-factory-Bxvb4LE7.js
|
|
10309
|
+
let configuredProvider;
|
|
10310
|
+
/**
|
|
10311
|
+
* Configure the embedded agent provider explicitly.
|
|
10312
|
+
* Call this from CLI to override auto-detection.
|
|
10313
|
+
*/
|
|
10314
|
+
function setAgentProvider(provider) {
|
|
10315
|
+
configuredProvider = provider;
|
|
10316
|
+
}
|
|
10317
|
+
/**
|
|
10318
|
+
* Configure base URLs for providers (called from CLI).
|
|
10319
|
+
*/
|
|
10320
|
+
function setProviderBaseUrls(config) {
|
|
10321
|
+
if (config.openaiBaseUrl) setOpenAIBaseUrl(config.openaiBaseUrl);
|
|
10322
|
+
if (config.anthropicBaseUrl) setAnthropicBaseUrl(config.anthropicBaseUrl);
|
|
10323
|
+
}
|
|
10324
|
+
/**
|
|
10325
|
+
* Check if the API key exists for a given provider type.
|
|
10326
|
+
*/
|
|
10327
|
+
function hasApiKeyForProvider(type) {
|
|
10328
|
+
switch (type) {
|
|
10329
|
+
case "anthropic": return Boolean(process.env.ANTHROPIC_API_KEY);
|
|
10330
|
+
case "openai": return Boolean(process.env.OPENAI_API_KEY);
|
|
10331
|
+
}
|
|
10332
|
+
}
|
|
10333
|
+
/**
|
|
10334
|
+
* Get the expected API key name for a provider type.
|
|
10335
|
+
*/
|
|
10336
|
+
function getApiKeyName(type) {
|
|
10337
|
+
switch (type) {
|
|
10338
|
+
case "anthropic": return "ANTHROPIC_API_KEY";
|
|
10339
|
+
case "openai": return "OPENAI_API_KEY";
|
|
10340
|
+
}
|
|
10341
|
+
}
|
|
10342
|
+
/**
|
|
10343
|
+
* Build a provider instance for the given type.
|
|
10344
|
+
*/
|
|
10345
|
+
function buildProvider(type) {
|
|
10346
|
+
switch (type) {
|
|
10347
|
+
case "anthropic": return {
|
|
10348
|
+
type: "anthropic",
|
|
10349
|
+
getModel: getAnthropicModel,
|
|
10350
|
+
getProviderOptions: () => ({}),
|
|
10351
|
+
getTemperature: () => void 0
|
|
10352
|
+
};
|
|
10353
|
+
case "openai": return {
|
|
10354
|
+
type: "openai",
|
|
10355
|
+
getModel: getOpenAIModel,
|
|
10356
|
+
getProviderOptions: () => ({ openai: {
|
|
10357
|
+
structuredOutputs: false,
|
|
10358
|
+
strictJsonSchema: false
|
|
10359
|
+
} }),
|
|
10360
|
+
getTemperature: () => 1
|
|
10361
|
+
};
|
|
10362
|
+
}
|
|
10363
|
+
}
|
|
10364
|
+
/**
|
|
10365
|
+
* Get the current agent provider based on configuration.
|
|
10366
|
+
*
|
|
10367
|
+
* Resolution order:
|
|
10368
|
+
* 1. Explicit configuration via setAgentProvider()
|
|
10369
|
+
* 2. EMBEDDED_AGENT_PROVIDER environment variable
|
|
10370
|
+
* 3. Auto-detect: check ANTHROPIC_API_KEY, then OPENAI_API_KEY
|
|
10371
|
+
* 4. Throw ConfigurationError if no provider available
|
|
10372
|
+
*/
|
|
10373
|
+
function getAgentProvider() {
|
|
10374
|
+
let providerType = configuredProvider;
|
|
10375
|
+
if (!providerType) {
|
|
10376
|
+
const envProvider = process.env.EMBEDDED_AGENT_PROVIDER?.toLowerCase();
|
|
10377
|
+
if (envProvider === "openai" || envProvider === "anthropic") providerType = envProvider;
|
|
10378
|
+
}
|
|
10379
|
+
if (providerType && !hasApiKeyForProvider(providerType)) throw new ConfigurationError(`Provider "${providerType}" is configured but ${getApiKeyName(providerType)} is not set. Please set the API key environment variable.`);
|
|
10380
|
+
if (!providerType) {
|
|
10381
|
+
if (process.env.ANTHROPIC_API_KEY) providerType = "anthropic";
|
|
10382
|
+
else if (process.env.OPENAI_API_KEY) providerType = "openai";
|
|
10383
|
+
}
|
|
10384
|
+
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.");
|
|
10385
|
+
return buildProvider(providerType);
|
|
10386
|
+
}
|
|
10387
|
+
/**
|
|
10388
|
+
* Check if an embedded agent provider is available.
|
|
10389
|
+
* Returns true if getAgentProvider() would succeed.
|
|
10390
|
+
*/
|
|
10391
|
+
function hasAgentProvider() {
|
|
10392
|
+
try {
|
|
10393
|
+
getAgentProvider();
|
|
10394
|
+
return true;
|
|
10395
|
+
} catch {
|
|
10396
|
+
return false;
|
|
10397
|
+
}
|
|
10398
|
+
}
|
|
10399
|
+
/**
|
|
10400
|
+
* Get the resolved provider type without throwing.
|
|
10401
|
+
* Returns undefined if no provider is available or API key is missing.
|
|
10402
|
+
*/
|
|
10403
|
+
function getResolvedProviderType() {
|
|
10404
|
+
if (configuredProvider) return hasApiKeyForProvider(configuredProvider) ? configuredProvider : void 0;
|
|
10405
|
+
const envProvider = process.env.EMBEDDED_AGENT_PROVIDER?.toLowerCase();
|
|
10406
|
+
if (envProvider === "openai" || envProvider === "anthropic") return hasApiKeyForProvider(envProvider) ? envProvider : void 0;
|
|
10407
|
+
if (process.env.ANTHROPIC_API_KEY) return "anthropic";
|
|
10408
|
+
if (process.env.OPENAI_API_KEY) return "openai";
|
|
10409
|
+
return void 0;
|
|
8992
10410
|
}
|
|
8993
10411
|
|
|
8994
10412
|
//#endregion
|
|
@@ -13843,8 +15261,8 @@ var SseMCPTransport = class {
|
|
|
13843
15261
|
this.headers = headers;
|
|
13844
15262
|
}
|
|
13845
15263
|
async start() {
|
|
13846
|
-
return new Promise((resolve, reject) => {
|
|
13847
|
-
if (this.connected) return resolve();
|
|
15264
|
+
return new Promise((resolve$1, reject) => {
|
|
15265
|
+
if (this.connected) return resolve$1();
|
|
13848
15266
|
this.abortController = new AbortController();
|
|
13849
15267
|
const establishConnection = async () => {
|
|
13850
15268
|
var _a17, _b, _c;
|
|
@@ -13879,7 +15297,7 @@ var SseMCPTransport = class {
|
|
|
13879
15297
|
this.endpoint = new URL(data, this.url);
|
|
13880
15298
|
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}` });
|
|
13881
15299
|
this.connected = true;
|
|
13882
|
-
resolve();
|
|
15300
|
+
resolve$1();
|
|
13883
15301
|
} else if (event === "message") try {
|
|
13884
15302
|
const message = JSONRPCMessageSchema.parse(JSON.parse(data));
|
|
13885
15303
|
(_a18 = this.onmessage) == null || _a18.call(this, message);
|
|
@@ -14018,7 +15436,7 @@ var MCPClient = class {
|
|
|
14018
15436
|
}
|
|
14019
15437
|
}
|
|
14020
15438
|
async request({ request, resultSchema, options }) {
|
|
14021
|
-
return new Promise((resolve, reject) => {
|
|
15439
|
+
return new Promise((resolve$1, reject) => {
|
|
14022
15440
|
if (this.isClosed) return reject(new MCPClientError({ message: "Attempted to send a request from a closed client" }));
|
|
14023
15441
|
this.assertCapability(request.method);
|
|
14024
15442
|
const signal = options == null ? void 0 : options.signal;
|
|
@@ -14040,7 +15458,7 @@ var MCPClient = class {
|
|
|
14040
15458
|
if (response instanceof Error) return reject(response);
|
|
14041
15459
|
try {
|
|
14042
15460
|
const result = resultSchema.parse(response.result);
|
|
14043
|
-
resolve(result);
|
|
15461
|
+
resolve$1(result);
|
|
14044
15462
|
} catch (error) {
|
|
14045
15463
|
const parseError = new MCPClientError({
|
|
14046
15464
|
message: "Failed to parse server response",
|
|
@@ -14267,7 +15685,7 @@ function trimStartOfStream() {
|
|
|
14267
15685
|
var HANGING_STREAM_WARNING_TIME_MS = 15 * 1e3;
|
|
14268
15686
|
|
|
14269
15687
|
//#endregion
|
|
14270
|
-
//#region ../mcp-core/dist/callEmbeddedAgent
|
|
15688
|
+
//#region ../mcp-core/dist/callEmbeddedAgent--R3kwqbb.js
|
|
14271
15689
|
/**
|
|
14272
15690
|
* Call an embedded agent with tool call capture
|
|
14273
15691
|
* This is the standard way to call embedded AI agents within MCP tools
|
|
@@ -14278,22 +15696,20 @@ var HANGING_STREAM_WARNING_TIME_MS = 15 * 1e3;
|
|
|
14278
15696
|
*/
|
|
14279
15697
|
async function callEmbeddedAgent({ system, prompt, tools, schema }) {
|
|
14280
15698
|
const capturedToolCalls = [];
|
|
15699
|
+
const provider = getAgentProvider();
|
|
14281
15700
|
const result = await generateText({
|
|
14282
|
-
model:
|
|
15701
|
+
model: provider.getModel(),
|
|
14283
15702
|
system,
|
|
14284
15703
|
prompt,
|
|
14285
15704
|
tools,
|
|
14286
15705
|
maxSteps: 5,
|
|
14287
|
-
temperature:
|
|
15706
|
+
...provider.getTemperature() !== void 0 && { temperature: provider.getTemperature() },
|
|
14288
15707
|
experimental_output: output_exports.object({ schema }),
|
|
14289
15708
|
experimental_telemetry: {
|
|
14290
15709
|
isEnabled: true,
|
|
14291
15710
|
functionId: "callEmbeddedAgent"
|
|
14292
15711
|
},
|
|
14293
|
-
providerOptions:
|
|
14294
|
-
structuredOutputs: false,
|
|
14295
|
-
strictJsonSchema: false
|
|
14296
|
-
} },
|
|
15712
|
+
providerOptions: provider.getProviderOptions(),
|
|
14297
15713
|
onStepFinish: (event) => {
|
|
14298
15714
|
if (event.toolCalls && event.toolCalls.length > 0) for (const toolCall of event.toolCalls) capturedToolCalls.push({
|
|
14299
15715
|
toolName: toolCall.toolName,
|
|
@@ -14313,7 +15729,7 @@ async function callEmbeddedAgent({ system, prompt, tools, schema }) {
|
|
|
14313
15729
|
}
|
|
14314
15730
|
|
|
14315
15731
|
//#endregion
|
|
14316
|
-
//#region ../mcp-core/dist/utils-
|
|
15732
|
+
//#region ../mcp-core/dist/utils-BhgZ4dUB.js
|
|
14317
15733
|
/**
|
|
14318
15734
|
* Standard response schema for all embedded agent tools.
|
|
14319
15735
|
* Tools return either an error message or the result data, never both.
|
|
@@ -14395,7 +15811,7 @@ function agentTool(config) {
|
|
|
14395
15811
|
}
|
|
14396
15812
|
|
|
14397
15813
|
//#endregion
|
|
14398
|
-
//#region ../mcp-core/dist/otel-semantics-
|
|
15814
|
+
//#region ../mcp-core/dist/otel-semantics-B5qAIqUa.js
|
|
14399
15815
|
var namespace$72 = "android";
|
|
14400
15816
|
var description$72 = "The Android platform on which the Android application is running.\n";
|
|
14401
15817
|
var attributes$72 = {
|
|
@@ -19241,7 +20657,7 @@ function createOtelLookupTool(options) {
|
|
|
19241
20657
|
}
|
|
19242
20658
|
|
|
19243
20659
|
//#endregion
|
|
19244
|
-
//#region ../mcp-core/dist/whoami-
|
|
20660
|
+
//#region ../mcp-core/dist/whoami-CnHpsyv0.js
|
|
19245
20661
|
/**
|
|
19246
20662
|
* Get the current authenticated user's information from Sentry API
|
|
19247
20663
|
*/
|
|
@@ -19270,7 +20686,7 @@ function createWhoamiTool(options) {
|
|
|
19270
20686
|
}
|
|
19271
20687
|
|
|
19272
20688
|
//#endregion
|
|
19273
|
-
//#region ../mcp-core/dist/utils-
|
|
20689
|
+
//#region ../mcp-core/dist/utils-CRDu-UNV.js
|
|
19274
20690
|
function getStringValue(event, key, defaultValue = "") {
|
|
19275
20691
|
const value = event[key];
|
|
19276
20692
|
return typeof value === "string" ? value : defaultValue;
|
|
@@ -19323,7 +20739,7 @@ function createDatasetAttributesTool(options) {
|
|
|
19323
20739
|
"logs"
|
|
19324
20740
|
]).describe("The dataset to query attributes for") }),
|
|
19325
20741
|
execute: async ({ dataset }) => {
|
|
19326
|
-
const { BASE_COMMON_FIELDS, DATASET_FIELDS, RECOMMENDED_FIELDS: RECOMMENDED_FIELDS$2, NUMERIC_FIELDS, DATASET_EXAMPLES } = await Promise.resolve().then(() => require("./config-
|
|
20742
|
+
const { BASE_COMMON_FIELDS, DATASET_FIELDS, RECOMMENDED_FIELDS: RECOMMENDED_FIELDS$2, NUMERIC_FIELDS, DATASET_EXAMPLES } = await Promise.resolve().then(() => require("./config-CwE3_vz4.cjs"));
|
|
19327
20743
|
const { attributes: customAttributes, fieldTypes } = await fetchCustomAttributes(apiService, organizationSlug, dataset, projectId);
|
|
19328
20744
|
const allFields = {
|
|
19329
20745
|
...BASE_COMMON_FIELDS,
|
|
@@ -19358,7 +20774,7 @@ Use these examples as patterns for constructing your query.`;
|
|
|
19358
20774
|
}
|
|
19359
20775
|
|
|
19360
20776
|
//#endregion
|
|
19361
|
-
//#region ../mcp-core/dist/agent-
|
|
20777
|
+
//#region ../mcp-core/dist/agent-C5-b2G06.js
|
|
19362
20778
|
const searchEventsAgentOutputSchema = zod.z.object({
|
|
19363
20779
|
dataset: zod.z.enum([
|
|
19364
20780
|
"spans",
|
|
@@ -19387,7 +20803,6 @@ const searchEventsAgentOutputSchema = zod.z.object({
|
|
|
19387
20803
|
* This returns both the translated query result AND the tool calls made by the agent
|
|
19388
20804
|
*/
|
|
19389
20805
|
async function searchEventsAgent(options) {
|
|
19390
|
-
if (!process.env.OPENAI_API_KEY) throw new ConfigurationError("OPENAI_API_KEY environment variable is required for semantic search");
|
|
19391
20806
|
const datasetAttributesTool = createDatasetAttributesTool({
|
|
19392
20807
|
apiService: options.apiService,
|
|
19393
20808
|
organizationSlug: options.organizationSlug,
|
|
@@ -19400,7 +20815,7 @@ async function searchEventsAgent(options) {
|
|
|
19400
20815
|
});
|
|
19401
20816
|
const whoamiTool = createWhoamiTool({ apiService: options.apiService });
|
|
19402
20817
|
return await callEmbeddedAgent({
|
|
19403
|
-
system:
|
|
20818
|
+
system: require_config_CEjP2CYO.systemPrompt,
|
|
19404
20819
|
prompt: options.query,
|
|
19405
20820
|
tools: {
|
|
19406
20821
|
datasetAttributes: datasetAttributesTool,
|
|
@@ -19412,7 +20827,7 @@ async function searchEventsAgent(options) {
|
|
|
19412
20827
|
}
|
|
19413
20828
|
|
|
19414
20829
|
//#endregion
|
|
19415
|
-
//#region ../mcp-core/dist/formatters-
|
|
20830
|
+
//#region ../mcp-core/dist/formatters-CJK-ciCF.js
|
|
19416
20831
|
/**
|
|
19417
20832
|
* Format an explanation for how a natural language query was translated
|
|
19418
20833
|
*/
|
|
@@ -19630,7 +21045,7 @@ function formatSpanResults(params) {
|
|
|
19630
21045
|
}
|
|
19631
21046
|
|
|
19632
21047
|
//#endregion
|
|
19633
|
-
//#region ../mcp-core/dist/handler-
|
|
21048
|
+
//#region ../mcp-core/dist/handler-BDtOWjBO.js
|
|
19634
21049
|
var handler_default = defineTool({
|
|
19635
21050
|
name: "search_events",
|
|
19636
21051
|
skills: [
|
|
@@ -19710,7 +21125,7 @@ var handler_default = defineTool({
|
|
|
19710
21125
|
});
|
|
19711
21126
|
const parsed = agentResult.result;
|
|
19712
21127
|
const dataset = parsed.dataset;
|
|
19713
|
-
const recommendedFields =
|
|
21128
|
+
const recommendedFields = require_config_CEjP2CYO.RECOMMENDED_FIELDS[dataset];
|
|
19714
21129
|
if (!parsed.sort) throw new UserInputError(`Search Events Agent response missing required 'sort' parameter. Received: ${JSON.stringify(parsed, null, 2)}. The agent must specify how to sort results (e.g., '-timestamp' for newest first, '-count()' for highest count).`);
|
|
19715
21130
|
const sentryQuery = parsed.query || "";
|
|
19716
21131
|
const requestedFields = parsed.fields || [];
|
|
@@ -19771,7 +21186,7 @@ var handler_default = defineTool({
|
|
|
19771
21186
|
});
|
|
19772
21187
|
|
|
19773
21188
|
//#endregion
|
|
19774
|
-
//#region ../mcp-core/dist/create-team-
|
|
21189
|
+
//#region ../mcp-core/dist/create-team-BNRuwaPN.js
|
|
19775
21190
|
var create_team_default = defineTool({
|
|
19776
21191
|
name: "create_team",
|
|
19777
21192
|
skills: ["project-management"],
|
|
@@ -19826,7 +21241,7 @@ var create_team_default = defineTool({
|
|
|
19826
21241
|
});
|
|
19827
21242
|
|
|
19828
21243
|
//#endregion
|
|
19829
|
-
//#region ../mcp-core/dist/create-project-
|
|
21244
|
+
//#region ../mcp-core/dist/create-project-CagAItcQ.js
|
|
19830
21245
|
var create_project_default = defineTool({
|
|
19831
21246
|
name: "create_project",
|
|
19832
21247
|
skills: ["project-management"],
|
|
@@ -19903,7 +21318,7 @@ var create_project_default = defineTool({
|
|
|
19903
21318
|
});
|
|
19904
21319
|
|
|
19905
21320
|
//#endregion
|
|
19906
|
-
//#region ../mcp-core/dist/update-project-
|
|
21321
|
+
//#region ../mcp-core/dist/update-project-C3HNKHy3.js
|
|
19907
21322
|
var update_project_default = defineTool({
|
|
19908
21323
|
name: "update_project",
|
|
19909
21324
|
skills: ["project-management"],
|
|
@@ -20021,7 +21436,7 @@ var update_project_default = defineTool({
|
|
|
20021
21436
|
});
|
|
20022
21437
|
|
|
20023
21438
|
//#endregion
|
|
20024
|
-
//#region ../mcp-core/dist/create-dsn-
|
|
21439
|
+
//#region ../mcp-core/dist/create-dsn-qX9dkWBv.js
|
|
20025
21440
|
var create_dsn_default = defineTool({
|
|
20026
21441
|
name: "create_dsn",
|
|
20027
21442
|
skills: ["project-management"],
|
|
@@ -20081,7 +21496,7 @@ var create_dsn_default = defineTool({
|
|
|
20081
21496
|
});
|
|
20082
21497
|
|
|
20083
21498
|
//#endregion
|
|
20084
|
-
//#region ../mcp-core/dist/find-dsns-
|
|
21499
|
+
//#region ../mcp-core/dist/find-dsns-DQL7wv5D.js
|
|
20085
21500
|
var find_dsns_default = defineTool({
|
|
20086
21501
|
name: "find_dsns",
|
|
20087
21502
|
skills: ["project-management"],
|
|
@@ -20132,7 +21547,7 @@ var find_dsns_default = defineTool({
|
|
|
20132
21547
|
});
|
|
20133
21548
|
|
|
20134
21549
|
//#endregion
|
|
20135
|
-
//#region ../mcp-core/dist/fetch-utils-
|
|
21550
|
+
//#region ../mcp-core/dist/fetch-utils-LjUGSOvJ.js
|
|
20136
21551
|
/**
|
|
20137
21552
|
* Fetch with timeout using AbortController
|
|
20138
21553
|
* @param url - The URL to fetch
|
|
@@ -20175,14 +21590,14 @@ async function retryWithBackoff(fn, { maxRetries = 3, initialDelay = 1e3, should
|
|
|
20175
21590
|
} catch (error) {
|
|
20176
21591
|
lastError = error;
|
|
20177
21592
|
if (attempt === maxRetries || !shouldRetry(error)) throw error;
|
|
20178
|
-
await new Promise((resolve) => setTimeout(resolve, delay$1));
|
|
21593
|
+
await new Promise((resolve$1) => setTimeout(resolve$1, delay$1));
|
|
20179
21594
|
delay$1 = Math.min(delay$1 * 2, 3e4);
|
|
20180
21595
|
}
|
|
20181
21596
|
throw lastError;
|
|
20182
21597
|
}
|
|
20183
21598
|
|
|
20184
21599
|
//#endregion
|
|
20185
|
-
//#region ../mcp-core/dist/analyze-issue-with-seer-
|
|
21600
|
+
//#region ../mcp-core/dist/analyze-issue-with-seer-B6aDeTwi.js
|
|
20186
21601
|
var analyze_issue_with_seer_default = defineTool({
|
|
20187
21602
|
name: "analyze_issue_with_seer",
|
|
20188
21603
|
skills: ["seer"],
|
|
@@ -20267,7 +21682,7 @@ var analyze_issue_with_seer_default = defineTool({
|
|
|
20267
21682
|
instruction: params.instruction
|
|
20268
21683
|
});
|
|
20269
21684
|
output += `Analysis started with Run ID: ${startResult.run_id}\n\n`;
|
|
20270
|
-
await new Promise((resolve) => setTimeout(resolve, 1e3));
|
|
21685
|
+
await new Promise((resolve$1) => setTimeout(resolve$1, 1e3));
|
|
20271
21686
|
autofixState = await retryWithBackoff(() => apiService.getAutofixState({
|
|
20272
21687
|
organizationSlug: orgSlug,
|
|
20273
21688
|
issueId: parsedIssueId
|
|
@@ -20324,7 +21739,7 @@ var analyze_issue_with_seer_default = defineTool({
|
|
|
20324
21739
|
if (activeStep) output += `Processing: ${activeStep.title}...\n`;
|
|
20325
21740
|
lastStatus = status;
|
|
20326
21741
|
}
|
|
20327
|
-
await new Promise((resolve) => setTimeout(resolve, SEER_POLLING_INTERVAL));
|
|
21742
|
+
await new Promise((resolve$1) => setTimeout(resolve$1, SEER_POLLING_INTERVAL));
|
|
20328
21743
|
try {
|
|
20329
21744
|
autofixState = await retryWithBackoff(() => apiService.getAutofixState({
|
|
20330
21745
|
organizationSlug: orgSlug,
|
|
@@ -20370,7 +21785,7 @@ var analyze_issue_with_seer_default = defineTool({
|
|
|
20370
21785
|
});
|
|
20371
21786
|
|
|
20372
21787
|
//#endregion
|
|
20373
|
-
//#region ../mcp-core/dist/search-docs-
|
|
21788
|
+
//#region ../mcp-core/dist/search-docs-yQc8o0ap.js
|
|
20374
21789
|
var search_docs_default = defineTool({
|
|
20375
21790
|
name: "search_docs",
|
|
20376
21791
|
skills: ["docs"],
|
|
@@ -20453,7 +21868,7 @@ var search_docs_default = defineTool({
|
|
|
20453
21868
|
});
|
|
20454
21869
|
|
|
20455
21870
|
//#endregion
|
|
20456
|
-
//#region ../mcp-core/dist/get-doc-
|
|
21871
|
+
//#region ../mcp-core/dist/get-doc-BuXsge2G.js
|
|
20457
21872
|
var get_doc_default = defineTool({
|
|
20458
21873
|
name: "get_doc",
|
|
20459
21874
|
skills: ["docs"],
|
|
@@ -20530,7 +21945,7 @@ var get_doc_default = defineTool({
|
|
|
20530
21945
|
});
|
|
20531
21946
|
|
|
20532
21947
|
//#endregion
|
|
20533
|
-
//#region ../mcp-core/dist/dataset-fields-
|
|
21948
|
+
//#region ../mcp-core/dist/dataset-fields-ClLuCTh4.js
|
|
20534
21949
|
/**
|
|
20535
21950
|
* Discover available fields for a dataset by querying Sentry's tags API
|
|
20536
21951
|
*/
|
|
@@ -20680,7 +22095,7 @@ function getCommonPatterns(dataset) {
|
|
|
20680
22095
|
}
|
|
20681
22096
|
|
|
20682
22097
|
//#endregion
|
|
20683
|
-
//#region ../mcp-core/dist/config-
|
|
22098
|
+
//#region ../mcp-core/dist/config-C3fctASk.js
|
|
20684
22099
|
/**
|
|
20685
22100
|
* Configuration for the search-issues agent
|
|
20686
22101
|
*/
|
|
@@ -20698,13 +22113,16 @@ BUILT-IN FIELDS:
|
|
|
20698
22113
|
- level: Severity level (error, warning, info, debug, fatal)
|
|
20699
22114
|
IMPORTANT: Almost NEVER use this field. Terms like "critical", "important", "severe" refer to IMPACT not level.
|
|
20700
22115
|
Only use if user explicitly says "error level", "warning level", etc.
|
|
22116
|
+
- issueCategory: Issue classification (error, performance, metric, feedback)
|
|
22117
|
+
IMPORTANT: User feedback from the User Feedback Widget is stored as issues with issueCategory:feedback
|
|
22118
|
+
Use this field when users ask about "user feedback", "feedback submissions", "user reports", etc.
|
|
20701
22119
|
- environment: Deployment environment (production, staging, development)
|
|
20702
22120
|
- release: Version/release identifier
|
|
20703
22121
|
- firstSeen: When the issue was FIRST encountered (use for "new issues", "started", "began")
|
|
20704
22122
|
WARNING: Excludes ongoing issues that started before the time window
|
|
20705
22123
|
- lastSeen: When the issue was LAST encountered (use for "from the last", "recent", "active")
|
|
20706
22124
|
This includes ALL issues seen during the time window, regardless of when they started
|
|
20707
|
-
- assigned: Issues explicitly assigned to a user (email or "me")
|
|
22125
|
+
- assigned: Issues explicitly assigned to a user (email or "me")
|
|
20708
22126
|
- assignedOrSuggested: Issues assigned to OR suggested for a user (broader match)
|
|
20709
22127
|
- userCount: Number of unique users affected
|
|
20710
22128
|
- eventCount: Total number of events
|
|
@@ -20716,6 +22134,9 @@ COMMON QUERY PATTERNS:
|
|
|
20716
22134
|
- New issues: firstSeen:-7d
|
|
20717
22135
|
- High impact: userCount:>100
|
|
20718
22136
|
- My work: assignedOrSuggested:me
|
|
22137
|
+
- User feedback: issueCategory:feedback
|
|
22138
|
+
- Recent feedback: issueCategory:feedback lastSeen:-7d
|
|
22139
|
+
- Feedback from production: issueCategory:feedback environment:production
|
|
20719
22140
|
|
|
20720
22141
|
SORTING RULES:
|
|
20721
22142
|
1. CRITICAL: Sort MUST go in the separate "sort" field, NEVER in the "query" field
|
|
@@ -20739,6 +22160,8 @@ EXAMPLES:
|
|
|
20739
22160
|
"critical bugs" → query: "level:error is:unresolved", sort: "date"
|
|
20740
22161
|
"worst issues affecting the most users" → query: "is:unresolved", sort: "user"
|
|
20741
22162
|
"assigned to john@example.com" → query: "assignedOrSuggested:john@example.com", sort: "date"
|
|
22163
|
+
"show me user feedback" → query: "issueCategory:feedback", sort: "date"
|
|
22164
|
+
"feedback from the last week" → query: "issueCategory:feedback lastSeen:-7d", sort: "date"
|
|
20742
22165
|
|
|
20743
22166
|
NEVER: query: "is:unresolved sort:user" ← Sort goes in separate field!
|
|
20744
22167
|
|
|
@@ -20752,7 +22175,7 @@ Always use the issueFields tool to discover available fields when needed.
|
|
|
20752
22175
|
Use the whoami tool when you need to resolve 'me' references.`;
|
|
20753
22176
|
|
|
20754
22177
|
//#endregion
|
|
20755
|
-
//#region ../mcp-core/dist/agent-
|
|
22178
|
+
//#region ../mcp-core/dist/agent-BDHlBFe8.js
|
|
20756
22179
|
const searchIssuesAgentOutputSchema = zod.z.object({
|
|
20757
22180
|
query: zod.z.string().describe("The Sentry issue search query"),
|
|
20758
22181
|
sort: zod.z.enum([
|
|
@@ -20768,7 +22191,6 @@ const searchIssuesAgentOutputSchema = zod.z.object({
|
|
|
20768
22191
|
* This returns both the translated query result AND the tool calls made by the agent
|
|
20769
22192
|
*/
|
|
20770
22193
|
async function searchIssuesAgent(options) {
|
|
20771
|
-
if (!process.env.OPENAI_API_KEY) throw new ConfigurationError("OPENAI_API_KEY environment variable is required for semantic search");
|
|
20772
22194
|
return await callEmbeddedAgent({
|
|
20773
22195
|
system: systemPrompt$3,
|
|
20774
22196
|
prompt: options.query,
|
|
@@ -20786,7 +22208,7 @@ async function searchIssuesAgent(options) {
|
|
|
20786
22208
|
}
|
|
20787
22209
|
|
|
20788
22210
|
//#endregion
|
|
20789
|
-
//#region ../mcp-core/dist/formatters-
|
|
22211
|
+
//#region ../mcp-core/dist/formatters-BcLCXcro.js
|
|
20790
22212
|
/**
|
|
20791
22213
|
* Format an explanation for how a natural language query was translated
|
|
20792
22214
|
*/
|
|
@@ -20829,6 +22251,7 @@ function formatIssueResults(params) {
|
|
|
20829
22251
|
output += `## ${index + 1}. [${issue.shortId}](${issueUrl})\n\n`;
|
|
20830
22252
|
output += `**${issue.title}**\n\n`;
|
|
20831
22253
|
output += `- **Status**: ${issue.status}\n`;
|
|
22254
|
+
if (issue.issueCategory && issue.issueCategory !== "error") output += `- **Category**: ${issue.issueCategory}\n`;
|
|
20832
22255
|
output += `- **Users**: ${issue.userCount || 0}\n`;
|
|
20833
22256
|
output += `- **Events**: ${issue.count || 0}\n`;
|
|
20834
22257
|
if (issue.assignedTo) {
|
|
@@ -20845,6 +22268,8 @@ function formatIssueResults(params) {
|
|
|
20845
22268
|
output += "- Get more details about a specific issue: Use the Issue ID with get_issue_details\n";
|
|
20846
22269
|
output += "- Update issue status: Use update_issue to resolve or assign issues\n";
|
|
20847
22270
|
output += "- View event counts: Use search_events for aggregated statistics\n";
|
|
22271
|
+
const hasFeedback = issues.some((i) => i.issueCategory === "feedback");
|
|
22272
|
+
if (hasFeedback) output += "- View feedback details: Use get_issue_details to see full feedback content and linked error events\n";
|
|
20848
22273
|
return output;
|
|
20849
22274
|
}
|
|
20850
22275
|
/**
|
|
@@ -20863,11 +22288,11 @@ function formatDate(dateString) {
|
|
|
20863
22288
|
if (diffHours < 24) return `${diffHours} hour${diffHours === 1 ? "" : "s"} ago`;
|
|
20864
22289
|
const diffDays = Math.floor(diffHours / 24);
|
|
20865
22290
|
if (diffDays < 30) return `${diffDays} day${diffDays === 1 ? "" : "s"} ago`;
|
|
20866
|
-
return date.
|
|
22291
|
+
return date.toISOString().split("T")[0];
|
|
20867
22292
|
}
|
|
20868
22293
|
|
|
20869
22294
|
//#endregion
|
|
20870
|
-
//#region ../mcp-core/dist/handler-
|
|
22295
|
+
//#region ../mcp-core/dist/handler-CzGXq51l.js
|
|
20871
22296
|
var handler_default$1 = defineTool({
|
|
20872
22297
|
name: "search_issues",
|
|
20873
22298
|
skills: [
|
|
@@ -20887,6 +22312,7 @@ var handler_default$1 = defineTool({
|
|
|
20887
22312
|
"- Filtered issue lists: 'unresolved issues', 'critical bugs'",
|
|
20888
22313
|
"- Issues by impact: 'errors affecting more than 100 users'",
|
|
20889
22314
|
"- Issues by assignment: 'issues assigned to me'",
|
|
22315
|
+
"- User feedback: 'show me user feedback', 'feedback from last week'",
|
|
20890
22316
|
"",
|
|
20891
22317
|
"DO NOT USE FOR COUNTS/AGGREGATIONS:",
|
|
20892
22318
|
"- 'how many errors' → use search_events",
|
|
@@ -20904,6 +22330,7 @@ var handler_default$1 = defineTool({
|
|
|
20904
22330
|
"search_issues(organizationSlug='my-org', naturalLanguageQuery='critical bugs from last week')",
|
|
20905
22331
|
"search_issues(organizationSlug='my-org', naturalLanguageQuery='unhandled errors affecting 100+ users')",
|
|
20906
22332
|
"search_issues(organizationSlug='my-org', naturalLanguageQuery='issues assigned to me')",
|
|
22333
|
+
"search_issues(organizationSlug='my-org', naturalLanguageQuery='user feedback from production')",
|
|
20907
22334
|
"</examples>",
|
|
20908
22335
|
"",
|
|
20909
22336
|
"<hints>",
|
|
@@ -20988,7 +22415,7 @@ var handler_default$1 = defineTool({
|
|
|
20988
22415
|
});
|
|
20989
22416
|
|
|
20990
22417
|
//#endregion
|
|
20991
|
-
//#region ../mcp-core/dist/config-
|
|
22418
|
+
//#region ../mcp-core/dist/config-mlP4H0sA.js
|
|
20992
22419
|
const systemPrompt$2 = `You are a Sentry issue event filter translator. Your job is to:
|
|
20993
22420
|
1. Translate natural language queries into Sentry tag filters for events within a SPECIFIC issue
|
|
20994
22421
|
2. Select appropriate fields to return in the results
|
|
@@ -21323,7 +22750,7 @@ const EXAMPLE_QUERIES = [
|
|
|
21323
22750
|
];
|
|
21324
22751
|
|
|
21325
22752
|
//#endregion
|
|
21326
|
-
//#region ../mcp-core/dist/utils-
|
|
22753
|
+
//#region ../mcp-core/dist/utils-D8xperPO.js
|
|
21327
22754
|
/**
|
|
21328
22755
|
* Create a tool for the agent to query available tags and fields for issue events
|
|
21329
22756
|
* The tool is pre-bound with the API service and organization configured for the appropriate region
|
|
@@ -21400,7 +22827,7 @@ Received: ${params.issueUrl}`);
|
|
|
21400
22827
|
}
|
|
21401
22828
|
|
|
21402
22829
|
//#endregion
|
|
21403
|
-
//#region ../mcp-core/dist/agent-
|
|
22830
|
+
//#region ../mcp-core/dist/agent-zpc_iP4u.js
|
|
21404
22831
|
const searchIssueEventsAgentOutputSchema = zod.z.object({
|
|
21405
22832
|
query: zod.z.string().describe("Sentry query filters for tags/fields (NOT including issue: prefix - handler adds that)"),
|
|
21406
22833
|
fields: zod.z.array(zod.z.string()).describe("Array of field names to return in results"),
|
|
@@ -21424,7 +22851,6 @@ const searchIssueEventsAgentOutputSchema = zod.z.object({
|
|
|
21424
22851
|
* Returns both the translated query result AND the tool calls made by the agent
|
|
21425
22852
|
*/
|
|
21426
22853
|
async function searchIssueEventsAgent(options) {
|
|
21427
|
-
if (!process.env.OPENAI_API_KEY) throw new ConfigurationError("OPENAI_API_KEY environment variable is required for natural language query translation");
|
|
21428
22854
|
const issueEventFieldsTool = createIssueEventFieldsTool({
|
|
21429
22855
|
apiService: options.apiService,
|
|
21430
22856
|
organizationSlug: options.organizationSlug,
|
|
@@ -21443,7 +22869,7 @@ async function searchIssueEventsAgent(options) {
|
|
|
21443
22869
|
}
|
|
21444
22870
|
|
|
21445
22871
|
//#endregion
|
|
21446
|
-
//#region ../mcp-core/dist/handler-
|
|
22872
|
+
//#region ../mcp-core/dist/handler-9NRJi9hO.js
|
|
21447
22873
|
var handler_default$2 = defineTool({
|
|
21448
22874
|
name: "search_issue_events",
|
|
21449
22875
|
skills: ["inspect", "triage"],
|
|
@@ -21545,7 +22971,7 @@ var handler_default$2 = defineTool({
|
|
|
21545
22971
|
});
|
|
21546
22972
|
|
|
21547
22973
|
//#endregion
|
|
21548
|
-
//#region ../mcp-core/dist/config-
|
|
22974
|
+
//#region ../mcp-core/dist/config-BJzhfINu.js
|
|
21549
22975
|
/**
|
|
21550
22976
|
* Configuration for the use_sentry embedded agent.
|
|
21551
22977
|
*
|
|
@@ -21564,7 +22990,7 @@ The user may include various parameters to pass to those tools in their prompt.
|
|
|
21564
22990
|
You MUST return tool results directly without interpreting them.`;
|
|
21565
22991
|
|
|
21566
22992
|
//#endregion
|
|
21567
|
-
//#region ../mcp-core/dist/agent-
|
|
22993
|
+
//#region ../mcp-core/dist/agent-C0SOl71m.js
|
|
21568
22994
|
/**
|
|
21569
22995
|
* Output schema for the embedded agent.
|
|
21570
22996
|
* The agent returns the final result string directly from its tool calls.
|
|
@@ -21575,7 +23001,6 @@ const outputSchema = zod.z.object({ result: zod.z.string().describe("The final r
|
|
|
21575
23001
|
* This returns the final result AND the tool calls made by the agent
|
|
21576
23002
|
*/
|
|
21577
23003
|
async function useSentryAgent(options) {
|
|
21578
|
-
if (!process.env.OPENAI_API_KEY) throw new ConfigurationError("OPENAI_API_KEY environment variable is required for use_sentry tool");
|
|
21579
23004
|
const prompt = options.request;
|
|
21580
23005
|
return await callEmbeddedAgent({
|
|
21581
23006
|
system: systemPrompt$1,
|
|
@@ -21586,7 +23011,296 @@ async function useSentryAgent(options) {
|
|
|
21586
23011
|
}
|
|
21587
23012
|
|
|
21588
23013
|
//#endregion
|
|
21589
|
-
//#region ../mcp-core/dist/
|
|
23014
|
+
//#region ../mcp-core/dist/list-issues-DSk9smZ1.js
|
|
23015
|
+
var list_issues_default = defineTool({
|
|
23016
|
+
name: "list_issues",
|
|
23017
|
+
skills: [
|
|
23018
|
+
"inspect",
|
|
23019
|
+
"triage",
|
|
23020
|
+
"seer"
|
|
23021
|
+
],
|
|
23022
|
+
requiredScopes: ["event:read"],
|
|
23023
|
+
description: [
|
|
23024
|
+
"List issues using Sentry query syntax directly (no AI/LLM required).",
|
|
23025
|
+
"",
|
|
23026
|
+
"Use this tool when:",
|
|
23027
|
+
"- You know Sentry query syntax already",
|
|
23028
|
+
"- AI-powered search is unavailable (no OPENAI_API_KEY or ANTHROPIC_API_KEY)",
|
|
23029
|
+
"- You want precise control over the query",
|
|
23030
|
+
"",
|
|
23031
|
+
"For natural language queries, use search_issues instead.",
|
|
23032
|
+
"",
|
|
23033
|
+
"Common Query Syntax:",
|
|
23034
|
+
"- is:unresolved - Show unresolved issues only",
|
|
23035
|
+
"- is:unassigned - Show unassigned issues",
|
|
23036
|
+
"- level:error - Filter by error level",
|
|
23037
|
+
"- firstSeen:-24h - First seen in last 24 hours",
|
|
23038
|
+
"- lastSeen:-1h - Last seen in last hour",
|
|
23039
|
+
"- has:user - Issues with user context",
|
|
23040
|
+
"- user.email:user@example.com - Filter by user email",
|
|
23041
|
+
"- environment:production - Filter by environment",
|
|
23042
|
+
"- release:1.0.0 - Filter by release version",
|
|
23043
|
+
"",
|
|
23044
|
+
"Combine queries: is:unresolved is:unassigned level:error",
|
|
23045
|
+
"",
|
|
23046
|
+
"<examples>",
|
|
23047
|
+
"list_issues(organizationSlug='my-org', query='is:unresolved is:unassigned')",
|
|
23048
|
+
"list_issues(organizationSlug='my-org', query='level:error firstSeen:-24h', sort='freq')",
|
|
23049
|
+
"list_issues(organizationSlug='my-org', projectSlugOrId='my-project', query='is:unresolved')",
|
|
23050
|
+
"</examples>",
|
|
23051
|
+
"",
|
|
23052
|
+
"<hints>",
|
|
23053
|
+
"- If the user passes a parameter in the form of name/otherName, it's likely in the format of <organizationSlug>/<projectSlugOrId>.",
|
|
23054
|
+
"- The projectSlugOrId parameter accepts both project slugs (e.g., 'my-project') and numeric IDs (e.g., '123456').",
|
|
23055
|
+
"</hints>"
|
|
23056
|
+
].join("\n"),
|
|
23057
|
+
inputSchema: {
|
|
23058
|
+
organizationSlug: ParamOrganizationSlug,
|
|
23059
|
+
query: zod.z.string().trim().default("is:unresolved").describe("Sentry issue search query syntax"),
|
|
23060
|
+
projectSlugOrId: zod.z.string().toLowerCase().trim().superRefine(validateSlugOrId).nullable().default(null).describe("Filter by project slug or numeric ID (optional)"),
|
|
23061
|
+
sort: zod.z.enum([
|
|
23062
|
+
"date",
|
|
23063
|
+
"freq",
|
|
23064
|
+
"new",
|
|
23065
|
+
"user"
|
|
23066
|
+
]).default("date").describe("Sort order: date (last seen), freq (frequency), new (first seen), user (user count)"),
|
|
23067
|
+
limit: zod.z.number().min(1).max(100).default(10).describe("Maximum number of issues to return (1-100)"),
|
|
23068
|
+
regionUrl: ParamRegionUrl.nullable().default(null)
|
|
23069
|
+
},
|
|
23070
|
+
annotations: {
|
|
23071
|
+
readOnlyHint: true,
|
|
23072
|
+
openWorldHint: true
|
|
23073
|
+
},
|
|
23074
|
+
async handler(params, context$1) {
|
|
23075
|
+
const apiService = apiServiceFromContext(context$1, { regionUrl: params.regionUrl ?? void 0 });
|
|
23076
|
+
(0, __sentry_core.setTag)("organization.slug", params.organizationSlug);
|
|
23077
|
+
if (params.projectSlugOrId) if (isNumericId(params.projectSlugOrId)) (0, __sentry_core.setTag)("project.id", params.projectSlugOrId);
|
|
23078
|
+
else (0, __sentry_core.setTag)("project.slug", params.projectSlugOrId);
|
|
23079
|
+
const issues = await apiService.listIssues({
|
|
23080
|
+
organizationSlug: params.organizationSlug,
|
|
23081
|
+
projectSlug: params.projectSlugOrId ?? void 0,
|
|
23082
|
+
query: params.query,
|
|
23083
|
+
sortBy: params.sort,
|
|
23084
|
+
limit: params.limit
|
|
23085
|
+
});
|
|
23086
|
+
return formatIssueResults({
|
|
23087
|
+
issues,
|
|
23088
|
+
organizationSlug: params.organizationSlug,
|
|
23089
|
+
projectSlugOrId: params.projectSlugOrId ?? void 0,
|
|
23090
|
+
query: params.query,
|
|
23091
|
+
regionUrl: params.regionUrl ?? void 0
|
|
23092
|
+
});
|
|
23093
|
+
}
|
|
23094
|
+
});
|
|
23095
|
+
|
|
23096
|
+
//#endregion
|
|
23097
|
+
//#region ../mcp-core/dist/list-events-BVY0RUTR.js
|
|
23098
|
+
const DEFAULT_FIELDS = {
|
|
23099
|
+
errors: require_config_CEjP2CYO.RECOMMENDED_FIELDS.errors.basic,
|
|
23100
|
+
logs: require_config_CEjP2CYO.RECOMMENDED_FIELDS.logs.basic,
|
|
23101
|
+
spans: require_config_CEjP2CYO.RECOMMENDED_FIELDS.spans.basic
|
|
23102
|
+
};
|
|
23103
|
+
var list_events_default = defineTool({
|
|
23104
|
+
name: "list_events",
|
|
23105
|
+
skills: [
|
|
23106
|
+
"inspect",
|
|
23107
|
+
"triage",
|
|
23108
|
+
"seer"
|
|
23109
|
+
],
|
|
23110
|
+
requiredScopes: ["event:read"],
|
|
23111
|
+
description: [
|
|
23112
|
+
"Search events using Sentry query syntax directly (no AI/LLM required).",
|
|
23113
|
+
"",
|
|
23114
|
+
"Use this tool when:",
|
|
23115
|
+
"- You know Sentry query syntax already",
|
|
23116
|
+
"- AI-powered search is unavailable (no OPENAI_API_KEY or ANTHROPIC_API_KEY)",
|
|
23117
|
+
"- You want precise control over the query",
|
|
23118
|
+
"",
|
|
23119
|
+
"For natural language queries, use search_events instead.",
|
|
23120
|
+
"",
|
|
23121
|
+
"Datasets:",
|
|
23122
|
+
"- errors: Exception/crash events",
|
|
23123
|
+
"- logs: Log entries",
|
|
23124
|
+
"- spans: Performance data, traces, AI/LLM calls",
|
|
23125
|
+
"",
|
|
23126
|
+
"Query Syntax Examples:",
|
|
23127
|
+
"- message:\"connection timeout\"",
|
|
23128
|
+
"- level:error",
|
|
23129
|
+
"- span.op:http.client span.status_code:500",
|
|
23130
|
+
"- log.level:error",
|
|
23131
|
+
"- transaction:/api/users",
|
|
23132
|
+
"",
|
|
23133
|
+
"<examples>",
|
|
23134
|
+
"list_events(organizationSlug='my-org', dataset='errors', query='level:error')",
|
|
23135
|
+
"list_events(organizationSlug='my-org', dataset='spans', query='span.op:db')",
|
|
23136
|
+
"list_events(organizationSlug='my-org', dataset='logs', query='severity:error')",
|
|
23137
|
+
"list_events(organizationSlug='my-org', dataset='errors', fields=['issue', 'count()'], sort='-count()')",
|
|
23138
|
+
"</examples>",
|
|
23139
|
+
"",
|
|
23140
|
+
"<hints>",
|
|
23141
|
+
"- If the user passes a parameter in the form of name/otherName, it's likely in the format of <organizationSlug>/<projectSlug>.",
|
|
23142
|
+
"- Use fields with aggregate functions like count(), avg(), sum() for statistics",
|
|
23143
|
+
"- Sort by -count() for most common, -timestamp for newest",
|
|
23144
|
+
"</hints>"
|
|
23145
|
+
].join("\n"),
|
|
23146
|
+
inputSchema: {
|
|
23147
|
+
organizationSlug: ParamOrganizationSlug,
|
|
23148
|
+
dataset: zod.z.enum([
|
|
23149
|
+
"errors",
|
|
23150
|
+
"logs",
|
|
23151
|
+
"spans"
|
|
23152
|
+
]).default("errors").describe("Dataset to query: errors (exceptions), logs, or spans (traces)"),
|
|
23153
|
+
query: zod.z.string().trim().default("").describe("Sentry event search query syntax (empty for all events)"),
|
|
23154
|
+
fields: zod.z.array(zod.z.string()).nullable().default(null).describe("Fields to return. If not specified, uses sensible defaults. Include aggregate functions like count(), avg() for statistics."),
|
|
23155
|
+
sort: zod.z.string().default("-timestamp").describe("Sort field (prefix with - for descending). Use -count() for aggregations."),
|
|
23156
|
+
projectSlug: ParamProjectSlug.nullable().default(null),
|
|
23157
|
+
statsPeriod: zod.z.string().default("14d").describe("Time period: 1h, 24h, 7d, 14d, 30d, etc."),
|
|
23158
|
+
limit: zod.z.number().min(1).max(100).default(10).describe("Maximum number of results to return (1-100)"),
|
|
23159
|
+
regionUrl: ParamRegionUrl.nullable().default(null)
|
|
23160
|
+
},
|
|
23161
|
+
annotations: {
|
|
23162
|
+
readOnlyHint: true,
|
|
23163
|
+
openWorldHint: true
|
|
23164
|
+
},
|
|
23165
|
+
async handler(params, context$1) {
|
|
23166
|
+
const apiService = apiServiceFromContext(context$1, { regionUrl: params.regionUrl ?? void 0 });
|
|
23167
|
+
(0, __sentry_core.setTag)("organization.slug", params.organizationSlug);
|
|
23168
|
+
if (params.projectSlug) (0, __sentry_core.setTag)("project.slug", params.projectSlug);
|
|
23169
|
+
let projectId;
|
|
23170
|
+
if (params.projectSlug) {
|
|
23171
|
+
const project = await apiService.getProject({
|
|
23172
|
+
organizationSlug: params.organizationSlug,
|
|
23173
|
+
projectSlugOrId: params.projectSlug
|
|
23174
|
+
});
|
|
23175
|
+
projectId = String(project.id);
|
|
23176
|
+
}
|
|
23177
|
+
const fields = params.fields ?? DEFAULT_FIELDS[params.dataset];
|
|
23178
|
+
const eventsResponse = await apiService.searchEvents({
|
|
23179
|
+
organizationSlug: params.organizationSlug,
|
|
23180
|
+
query: params.query,
|
|
23181
|
+
fields,
|
|
23182
|
+
limit: params.limit,
|
|
23183
|
+
projectId,
|
|
23184
|
+
dataset: params.dataset,
|
|
23185
|
+
sort: params.sort,
|
|
23186
|
+
statsPeriod: params.statsPeriod
|
|
23187
|
+
});
|
|
23188
|
+
function isValidResponse(response) {
|
|
23189
|
+
return typeof response === "object" && response !== null;
|
|
23190
|
+
}
|
|
23191
|
+
function isValidEventArray(data) {
|
|
23192
|
+
return Array.isArray(data) && data.every((item) => typeof item === "object" && item !== null);
|
|
23193
|
+
}
|
|
23194
|
+
if (!isValidResponse(eventsResponse)) throw new Error("Invalid response format from Sentry API");
|
|
23195
|
+
const eventData = eventsResponse.data;
|
|
23196
|
+
if (!isValidEventArray(eventData)) throw new Error("Invalid event data format from Sentry API");
|
|
23197
|
+
const aggregateFunctions = fields.filter((field) => field.includes("(") && field.includes(")"));
|
|
23198
|
+
const groupByFields = fields.filter((field) => !field.includes("(") && !field.includes(")"));
|
|
23199
|
+
const explorerUrl = apiService.getEventsExplorerUrl(params.organizationSlug, params.query, projectId, params.dataset, fields, params.sort, aggregateFunctions, groupByFields, params.statsPeriod);
|
|
23200
|
+
const formatParams = {
|
|
23201
|
+
eventData,
|
|
23202
|
+
naturalLanguageQuery: params.query || `${params.dataset} events`,
|
|
23203
|
+
includeExplanation: false,
|
|
23204
|
+
apiService,
|
|
23205
|
+
organizationSlug: params.organizationSlug,
|
|
23206
|
+
explorerUrl,
|
|
23207
|
+
sentryQuery: params.query,
|
|
23208
|
+
fields
|
|
23209
|
+
};
|
|
23210
|
+
switch (params.dataset) {
|
|
23211
|
+
case "errors": return formatErrorResults(formatParams);
|
|
23212
|
+
case "logs": return formatLogResults(formatParams);
|
|
23213
|
+
case "spans": return formatSpanResults(formatParams);
|
|
23214
|
+
}
|
|
23215
|
+
}
|
|
23216
|
+
});
|
|
23217
|
+
|
|
23218
|
+
//#endregion
|
|
23219
|
+
//#region ../mcp-core/dist/list-issue-events-BOIBq62n.js
|
|
23220
|
+
var list_issue_events_default = defineTool({
|
|
23221
|
+
name: "list_issue_events",
|
|
23222
|
+
skills: ["inspect", "triage"],
|
|
23223
|
+
requiredScopes: ["event:read"],
|
|
23224
|
+
description: [
|
|
23225
|
+
"List events within a specific issue using Sentry query syntax (no AI/LLM required).",
|
|
23226
|
+
"",
|
|
23227
|
+
"Use this tool when:",
|
|
23228
|
+
"- You know Sentry query syntax already",
|
|
23229
|
+
"- AI-powered search is unavailable (no OPENAI_API_KEY or ANTHROPIC_API_KEY)",
|
|
23230
|
+
"- You want precise control over the query",
|
|
23231
|
+
"",
|
|
23232
|
+
"For natural language queries, use search_issue_events instead.",
|
|
23233
|
+
"",
|
|
23234
|
+
"Common Query Filters:",
|
|
23235
|
+
"- environment:production - Filter by environment",
|
|
23236
|
+
"- release:1.0.0 - Filter by release version",
|
|
23237
|
+
"- user.email:alice@example.com - Filter by user email",
|
|
23238
|
+
"- timestamp:>2024-01-01 - Filter by timestamp",
|
|
23239
|
+
"",
|
|
23240
|
+
"<examples>",
|
|
23241
|
+
"list_issue_events(issueUrl='https://sentry.io/organizations/my-org/issues/123/', query='environment:production')",
|
|
23242
|
+
"list_issue_events(issueId='MCP-41', organizationSlug='my-org', query='release:v1.0.0')",
|
|
23243
|
+
"list_issue_events(issueId='PROJECT-123', organizationSlug='my-org', statsPeriod='1h')",
|
|
23244
|
+
"</examples>",
|
|
23245
|
+
"",
|
|
23246
|
+
"<hints>",
|
|
23247
|
+
"- Use issueUrl for convenience (includes org + issue ID)",
|
|
23248
|
+
"- Or provide both issueId and organizationSlug",
|
|
23249
|
+
"- The query filters events WITHIN the issue, no need for issue: prefix",
|
|
23250
|
+
"</hints>"
|
|
23251
|
+
].join("\n"),
|
|
23252
|
+
inputSchema: {
|
|
23253
|
+
organizationSlug: ParamOrganizationSlug.nullable().default(null).describe("Organization slug. Required when using issueId. Not needed when using issueUrl."),
|
|
23254
|
+
issueId: zod.z.string().optional().describe("Issue ID (e.g., 'MCP-41', 'PROJECT-123'). Requires organizationSlug."),
|
|
23255
|
+
issueUrl: zod.z.string().url().optional().describe("Full Sentry issue URL. Includes both organization and issue ID."),
|
|
23256
|
+
query: zod.z.string().trim().default("").describe("Sentry event search query syntax (empty for all events)"),
|
|
23257
|
+
sort: zod.z.string().default("-timestamp").describe("Sort field (prefix with - for descending). Default: -timestamp"),
|
|
23258
|
+
statsPeriod: zod.z.string().default("14d").describe("Time period: 1h, 24h, 7d, 14d, 30d, etc."),
|
|
23259
|
+
limit: zod.z.number().min(1).max(100).default(50).describe("Maximum number of events to return (1-100)"),
|
|
23260
|
+
regionUrl: ParamRegionUrl.nullable().default(null)
|
|
23261
|
+
},
|
|
23262
|
+
annotations: {
|
|
23263
|
+
readOnlyHint: true,
|
|
23264
|
+
openWorldHint: true
|
|
23265
|
+
},
|
|
23266
|
+
async handler(params, context$1) {
|
|
23267
|
+
const { organizationSlug, issueId } = parseIssueParams({
|
|
23268
|
+
organizationSlug: params.organizationSlug,
|
|
23269
|
+
issueId: params.issueId,
|
|
23270
|
+
issueUrl: params.issueUrl
|
|
23271
|
+
});
|
|
23272
|
+
const apiService = apiServiceFromContext(context$1, { regionUrl: params.regionUrl ?? void 0 });
|
|
23273
|
+
(0, __sentry_core.setTag)("organization.slug", organizationSlug);
|
|
23274
|
+
(0, __sentry_core.setTag)("issue.id", issueId);
|
|
23275
|
+
const eventsResponse = await apiService.listEventsForIssue({
|
|
23276
|
+
organizationSlug,
|
|
23277
|
+
issueId,
|
|
23278
|
+
query: params.query,
|
|
23279
|
+
limit: params.limit,
|
|
23280
|
+
sort: params.sort,
|
|
23281
|
+
statsPeriod: params.statsPeriod
|
|
23282
|
+
});
|
|
23283
|
+
function isValidEventArray(data) {
|
|
23284
|
+
return Array.isArray(data) && data.every((item) => typeof item === "object" && item !== null);
|
|
23285
|
+
}
|
|
23286
|
+
if (!isValidEventArray(eventsResponse)) throw new Error("Invalid event data format from Sentry API: expected array of objects");
|
|
23287
|
+
const explorerQuery = params.query ? `issue:${issueId} ${params.query}` : `issue:${issueId}`;
|
|
23288
|
+
const explorerUrl = apiService.getEventsExplorerUrl(organizationSlug, explorerQuery, void 0, "errors", RECOMMENDED_FIELDS$1, params.sort, [], [], params.statsPeriod);
|
|
23289
|
+
return formatErrorResults({
|
|
23290
|
+
eventData: eventsResponse,
|
|
23291
|
+
naturalLanguageQuery: `Events in issue ${issueId}`,
|
|
23292
|
+
includeExplanation: false,
|
|
23293
|
+
apiService,
|
|
23294
|
+
organizationSlug,
|
|
23295
|
+
explorerUrl,
|
|
23296
|
+
sentryQuery: explorerQuery,
|
|
23297
|
+
fields: RECOMMENDED_FIELDS$1
|
|
23298
|
+
});
|
|
23299
|
+
}
|
|
23300
|
+
});
|
|
23301
|
+
|
|
23302
|
+
//#endregion
|
|
23303
|
+
//#region ../mcp-core/dist/error-handling-DFJ-iOAP.js
|
|
21590
23304
|
/**
|
|
21591
23305
|
* Type guard to identify user input validation errors.
|
|
21592
23306
|
*/
|
|
@@ -21677,7 +23391,7 @@ async function formatErrorForUser(error) {
|
|
|
21677
23391
|
}
|
|
21678
23392
|
|
|
21679
23393
|
//#endregion
|
|
21680
|
-
//#region ../mcp-core/dist/constraint-helpers-
|
|
23394
|
+
//#region ../mcp-core/dist/constraint-helpers-D80X658i.js
|
|
21681
23395
|
/**
|
|
21682
23396
|
* Determines which tool parameter keys should be filtered out of the schema
|
|
21683
23397
|
* because they will be injected from constraints.
|
|
@@ -21739,7 +23453,7 @@ function getConstraintParametersToInject(constraints, toolInputSchema) {
|
|
|
21739
23453
|
}
|
|
21740
23454
|
|
|
21741
23455
|
//#endregion
|
|
21742
|
-
//#region ../mcp-core/dist/server-
|
|
23456
|
+
//#region ../mcp-core/dist/server-obGNre-1.js
|
|
21743
23457
|
/**
|
|
21744
23458
|
* Format tool calls into a readable trace
|
|
21745
23459
|
*/
|
|
@@ -21801,7 +23515,8 @@ var handler_default$3 = defineTool({
|
|
|
21801
23515
|
},
|
|
21802
23516
|
async handler(params, context$1) {
|
|
21803
23517
|
const [clientTransport, serverTransport] = __modelcontextprotocol_sdk_inMemory_js.InMemoryTransport.createLinkedPair();
|
|
21804
|
-
const
|
|
23518
|
+
const toolsToExclude = new Set(["use_sentry", ...SIMPLE_REPLACEMENT_TOOLS]);
|
|
23519
|
+
const toolsForAgent = Object.fromEntries(Object.entries(tools_default).filter(([key]) => !toolsToExclude.has(key)));
|
|
21805
23520
|
const server$1 = buildServer({
|
|
21806
23521
|
context: context$1,
|
|
21807
23522
|
tools: toolsForAgent
|
|
@@ -21829,6 +23544,25 @@ var handler_default$3 = defineTool({
|
|
|
21829
23544
|
}
|
|
21830
23545
|
}
|
|
21831
23546
|
});
|
|
23547
|
+
/**
|
|
23548
|
+
* Tools that require an embedded agent provider (LLM-powered).
|
|
23549
|
+
* These are excluded when no agent provider is configured.
|
|
23550
|
+
* Note: use_sentry is handled separately via agentMode.
|
|
23551
|
+
*/
|
|
23552
|
+
const AGENT_DEPENDENT_TOOLS = [
|
|
23553
|
+
"search_events",
|
|
23554
|
+
"search_issues",
|
|
23555
|
+
"search_issue_events"
|
|
23556
|
+
];
|
|
23557
|
+
/**
|
|
23558
|
+
* Simple tools that replace agent-dependent tools when no provider is available.
|
|
23559
|
+
* These are excluded when an agent provider IS configured.
|
|
23560
|
+
*/
|
|
23561
|
+
const SIMPLE_REPLACEMENT_TOOLS = [
|
|
23562
|
+
"list_issues",
|
|
23563
|
+
"list_events",
|
|
23564
|
+
"list_issue_events"
|
|
23565
|
+
];
|
|
21832
23566
|
var tools_default = {
|
|
21833
23567
|
whoami: whoami_default,
|
|
21834
23568
|
find_organizations: find_organizations_default,
|
|
@@ -21836,6 +23570,7 @@ var tools_default = {
|
|
|
21836
23570
|
find_projects: find_projects_default,
|
|
21837
23571
|
find_releases: find_releases_default,
|
|
21838
23572
|
get_issue_details: get_issue_details_default,
|
|
23573
|
+
get_issue_tag_values: get_issue_tag_values_default,
|
|
21839
23574
|
get_trace_details: get_trace_details_default,
|
|
21840
23575
|
get_event_attachment: get_event_attachment_default,
|
|
21841
23576
|
update_issue: update_issue_default,
|
|
@@ -21850,7 +23585,10 @@ var tools_default = {
|
|
|
21850
23585
|
get_doc: get_doc_default,
|
|
21851
23586
|
search_issues: handler_default$1,
|
|
21852
23587
|
search_issue_events: handler_default$2,
|
|
21853
|
-
use_sentry: handler_default$3
|
|
23588
|
+
use_sentry: handler_default$3,
|
|
23589
|
+
list_issues: list_issues_default,
|
|
23590
|
+
list_events: list_events_default,
|
|
23591
|
+
list_issue_events: list_issue_events_default
|
|
21854
23592
|
};
|
|
21855
23593
|
/**
|
|
21856
23594
|
* Creates and configures a complete MCP server with Sentry instrumentation.
|
|
@@ -21911,7 +23649,12 @@ function buildServer({ context: context$1, agentMode = false, tools: customTools
|
|
|
21911
23649
|
* In agent mode, only the use_sentry tool is registered, bypassing authorization checks.
|
|
21912
23650
|
*/
|
|
21913
23651
|
function configureServer({ server: server$1, context: context$1, agentMode = false, tools: customTools }) {
|
|
21914
|
-
|
|
23652
|
+
let toolsToRegister = agentMode ? { use_sentry: tools_default.use_sentry } : customTools ?? tools_default;
|
|
23653
|
+
if (!agentMode && !customTools) {
|
|
23654
|
+
const hasAgent = hasAgentProvider();
|
|
23655
|
+
const toolsToExclude = new Set(hasAgent ? SIMPLE_REPLACEMENT_TOOLS : AGENT_DEPENDENT_TOOLS);
|
|
23656
|
+
toolsToRegister = Object.fromEntries(Object.entries(toolsToRegister).filter(([key]) => !toolsToExclude.has(key)));
|
|
23657
|
+
}
|
|
21915
23658
|
const grantedSkills = context$1.grantedSkills ? new Set(context$1.grantedSkills) : void 0;
|
|
21916
23659
|
server$1.server.onerror = (error) => {
|
|
21917
23660
|
const transportLogOptions = {
|
|
@@ -21992,7 +23735,7 @@ function configureServer({ server: server$1, context: context$1, agentMode = fal
|
|
|
21992
23735
|
}
|
|
21993
23736
|
|
|
21994
23737
|
//#endregion
|
|
21995
|
-
//#region ../mcp-core/dist/sentry-
|
|
23738
|
+
//#region ../mcp-core/dist/sentry-CTKJG5Bs.js
|
|
21996
23739
|
const SCRUB_PATTERNS = [
|
|
21997
23740
|
{
|
|
21998
23741
|
pattern: /\bsk-[a-zA-Z0-9]{48}\b/g,
|
|
@@ -22083,8 +23826,11 @@ function scrubValue(value, depth = 0) {
|
|
|
22083
23826
|
}
|
|
22084
23827
|
/**
|
|
22085
23828
|
* Sentry beforeSend hook that scrubs sensitive data from events
|
|
23829
|
+
* and applies custom fingerprinting for specific error types.
|
|
22086
23830
|
*/
|
|
22087
23831
|
function sentryBeforeSend(event, hint) {
|
|
23832
|
+
const firstException = event?.exception?.values?.[0];
|
|
23833
|
+
if (firstException?.type === "AI_APICallError" && firstException.value) event.fingerprint = ["AI_APICallError", firstException.value];
|
|
22088
23834
|
const [scrubbedEvent, didScrub, descriptions] = scrubValue(event);
|
|
22089
23835
|
if (didScrub) {
|
|
22090
23836
|
const uniqueDescriptions = [...new Set(descriptions)];
|
|
@@ -22125,16 +23871,21 @@ const cfg = (() => {
|
|
|
22125
23871
|
die(err instanceof Error ? err.message : String(err));
|
|
22126
23872
|
}
|
|
22127
23873
|
})();
|
|
22128
|
-
if (
|
|
22129
|
-
|
|
23874
|
+
if (cfg.agentProvider) setAgentProvider(cfg.agentProvider);
|
|
23875
|
+
setProviderBaseUrls({
|
|
23876
|
+
openaiBaseUrl: cfg.openaiBaseUrl,
|
|
23877
|
+
anthropicBaseUrl: cfg.anthropicBaseUrl
|
|
23878
|
+
});
|
|
23879
|
+
if (cfg.openaiModel) process.env.OPENAI_MODEL = cfg.openaiModel;
|
|
23880
|
+
if (cfg.anthropicModel) process.env.ANTHROPIC_MODEL = cfg.anthropicModel;
|
|
23881
|
+
const resolvedProvider = getResolvedProviderType();
|
|
23882
|
+
if (!resolvedProvider) {
|
|
23883
|
+
console.warn("Warning: No LLM API key found (OPENAI_API_KEY or ANTHROPIC_API_KEY).");
|
|
22130
23884
|
console.warn("The following AI-powered search tools will be unavailable:");
|
|
22131
|
-
console.warn(" - search_events
|
|
22132
|
-
console.warn("
|
|
22133
|
-
console.warn("All other tools will function normally. To enable AI-powered search, set OPENAI_API_KEY.");
|
|
23885
|
+
console.warn(" - search_events, search_issues, search_issue_events, use_sentry");
|
|
23886
|
+
console.warn("Use list_issues and list_events for direct Sentry query syntax instead.");
|
|
22134
23887
|
console.warn("");
|
|
22135
|
-
}
|
|
22136
|
-
setOpenAIBaseUrl(cfg.openaiBaseUrl);
|
|
22137
|
-
if (cfg.openaiModel) process.env.OPENAI_MODEL = cfg.openaiModel;
|
|
23888
|
+
} else console.warn(`Using ${resolvedProvider} for AI-powered search tools.`);
|
|
22138
23889
|
__sentry_node.init({
|
|
22139
23890
|
dsn: cfg.sentryDsn,
|
|
22140
23891
|
sendDefaultPii: true,
|