@sentry/junior 0.9.1 → 0.9.3

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/bin/junior.mjs CHANGED
@@ -6,14 +6,20 @@ import { fileURLToPath, pathToFileURL } from "node:url";
6
6
 
7
7
  const { positionals } = parseArgs({
8
8
  allowPositionals: true,
9
- strict: false
9
+ strict: false,
10
10
  });
11
11
 
12
12
  const command = positionals[0];
13
13
 
14
14
  async function loadCliFunction(moduleName, exportName, unavailableMessage) {
15
15
  const currentFile = fileURLToPath(import.meta.url);
16
- const modulePath = path.join(path.dirname(currentFile), "..", "dist", "cli", `${moduleName}.js`);
16
+ const modulePath = path.join(
17
+ path.dirname(currentFile),
18
+ "..",
19
+ "dist",
20
+ "cli",
21
+ `${moduleName}.js`,
22
+ );
17
23
  const moduleUrl = pathToFileURL(modulePath).href;
18
24
  const loadedModule = await import(moduleUrl);
19
25
  if (typeof loadedModule[exportName] !== "function") {
@@ -22,17 +28,30 @@ async function loadCliFunction(moduleName, exportName, unavailableMessage) {
22
28
  return loadedModule[exportName];
23
29
  }
24
30
 
31
+ async function loadCliEnvFiles() {
32
+ const loadCliEnvFilesFn = await loadCliFunction(
33
+ "env",
34
+ "loadCliEnvFiles",
35
+ "CLI env loader is unavailable; reinstall @sentry/junior and retry.",
36
+ );
37
+ loadCliEnvFilesFn(process.cwd());
38
+ }
39
+
25
40
  async function runSnapshotCreate() {
26
41
  const runSnapshotCreateFn = await loadCliFunction(
27
42
  "snapshot-warmup",
28
43
  "runSnapshotCreate",
29
- "Snapshot create module is unavailable; reinstall @sentry/junior and retry."
44
+ "Snapshot create module is unavailable; reinstall @sentry/junior and retry.",
30
45
  );
31
46
  await runSnapshotCreateFn();
32
47
  }
33
48
 
34
49
  async function runInit(dir) {
35
- const runInitFn = await loadCliFunction("init", "runInit", "Init module is unavailable; reinstall @sentry/junior and retry.");
50
+ const runInitFn = await loadCliFunction(
51
+ "init",
52
+ "runInit",
53
+ "Init module is unavailable; reinstall @sentry/junior and retry.",
54
+ );
36
55
  await runInitFn(dir);
37
56
  }
38
57
 
@@ -40,21 +59,22 @@ async function runCheck(dir) {
40
59
  const runCheckFn = await loadCliFunction(
41
60
  "check",
42
61
  "runCheck",
43
- "Check module is unavailable; reinstall @sentry/junior and retry."
62
+ "Check module is unavailable; reinstall @sentry/junior and retry.",
44
63
  );
45
64
  await runCheckFn(dir);
46
65
  }
47
66
 
48
67
  async function main() {
68
+ await loadCliEnvFiles();
49
69
  const runCli = await loadCliFunction(
50
70
  "run",
51
71
  "runCli",
52
- "CLI dispatcher module is unavailable; reinstall @sentry/junior and retry."
72
+ "CLI dispatcher module is unavailable; reinstall @sentry/junior and retry.",
53
73
  );
54
74
  const exitCode = await runCli(positionals, {
55
75
  runInit,
56
76
  runSnapshotCreate,
57
- runCheck
77
+ runCheck,
58
78
  });
59
79
  if (exitCode !== 0) {
60
80
  process.exit(exitCode);
@@ -6,6 +6,15 @@ import {
6
6
  withSpan
7
7
  } from "./chunk-ZW4OVKF5.js";
8
8
 
9
+ // src/chat/optional-string.ts
10
+ function toOptionalTrimmed(value) {
11
+ if (!value) {
12
+ return void 0;
13
+ }
14
+ const trimmed = value.trim();
15
+ return trimmed.length > 0 ? trimmed : void 0;
16
+ }
17
+
9
18
  // src/chat/config.ts
10
19
  var MIN_AGENT_TURN_TIMEOUT_MS = 10 * 1e3;
11
20
  var DEFAULT_AGENT_TURN_TIMEOUT_MS = 12 * 60 * 1e3;
@@ -35,13 +44,6 @@ function resolveMaxTurnTimeoutMs(queueCallbackMaxDurationSeconds) {
35
44
  const budgetSeconds = queueCallbackMaxDurationSeconds - TURN_TIMEOUT_BUFFER_SECONDS;
36
45
  return Math.max(MIN_AGENT_TURN_TIMEOUT_MS, budgetSeconds * 1e3);
37
46
  }
38
- function toOptionalTrimmed(value) {
39
- if (!value) {
40
- return void 0;
41
- }
42
- const trimmed = value.trim();
43
- return trimmed.length > 0 ? trimmed : void 0;
44
- }
45
47
  function readBotConfig(env) {
46
48
  const queueCallbackMaxDurationSeconds = resolveQueueCallbackMaxDurationSeconds(env);
47
49
  const maxTurnTimeoutMs = resolveMaxTurnTimeoutMs(
@@ -236,28 +238,13 @@ async function runNonInteractiveCommand(runner, input) {
236
238
  }
237
239
 
238
240
  // src/chat/sandbox/credentials.ts
239
- function toOptionalTrimmed2(value) {
240
- if (!value) {
241
- return void 0;
242
- }
243
- const trimmed = value.trim();
244
- return trimmed.length > 0 ? trimmed : void 0;
245
- }
246
241
  function getVercelSandboxCredentials() {
247
- const token = toOptionalTrimmed2(process.env.VERCEL_TOKEN);
248
- const teamId = toOptionalTrimmed2(process.env.VERCEL_TEAM_ID);
249
- const projectId = toOptionalTrimmed2(process.env.VERCEL_PROJECT_ID);
242
+ const token = toOptionalTrimmed(process.env.VERCEL_TOKEN);
243
+ const teamId = toOptionalTrimmed(process.env.VERCEL_TEAM_ID);
244
+ const projectId = toOptionalTrimmed(process.env.VERCEL_PROJECT_ID);
250
245
  if (token && teamId && projectId) {
251
246
  return { token, teamId, projectId };
252
247
  }
253
- if (toOptionalTrimmed2(process.env.VERCEL_OIDC_TOKEN)) {
254
- return void 0;
255
- }
256
- if (token || teamId || projectId) {
257
- throw new Error(
258
- "Missing Vercel Sandbox credentials: set VERCEL_TOKEN, VERCEL_TEAM_ID, and VERCEL_PROJECT_ID together, or provide VERCEL_OIDC_TOKEN."
259
- );
260
- }
261
248
  return void 0;
262
249
  }
263
250
 
@@ -818,6 +805,7 @@ function isSnapshotMissingError(error) {
818
805
  }
819
806
 
820
807
  export {
808
+ toOptionalTrimmed,
821
809
  botConfig,
822
810
  getSlackBotToken,
823
811
  getSlackSigningSecret,
@@ -25,8 +25,9 @@ import {
25
25
  isSnapshotMissingError,
26
26
  resolveRuntimeDependencySnapshot,
27
27
  runNonInteractiveCommand,
28
- sandboxSkillDir
29
- } from "./chunk-7GLBFSWP.js";
28
+ sandboxSkillDir,
29
+ toOptionalTrimmed
30
+ } from "./chunk-HRA2FXYH.js";
30
31
  import {
31
32
  CredentialUnavailableError,
32
33
  createPluginBroker,
@@ -846,24 +847,10 @@ var GATEWAY_PROVIDER = "vercel-ai-gateway";
846
847
  var GEN_AI_PROVIDER_NAME = GATEWAY_PROVIDER;
847
848
  var GEN_AI_OPERATION_CHAT = "chat";
848
849
  var MISSING_GATEWAY_CREDENTIALS_ERROR = "Missing AI gateway credentials (AI_GATEWAY_API_KEY or VERCEL_OIDC_TOKEN)";
849
- function toOptionalTrimmed(value) {
850
- if (!value) {
851
- return void 0;
852
- }
853
- const trimmed = value.trim();
854
- return trimmed.length > 0 ? trimmed : void 0;
855
- }
856
- function isVercelRuntime() {
857
- return process.env.VERCEL === "1" || Boolean(process.env.VERCEL_ENV) || Boolean(process.env.VERCEL_REGION);
858
- }
859
850
  function getGatewayApiKey() {
860
- const explicitApiKey = toOptionalTrimmed(getEnvApiKey("vercel-ai-gateway"));
861
- if (explicitApiKey) {
862
- return explicitApiKey;
863
- }
864
- if (!isVercelRuntime()) {
865
- return void 0;
866
- }
851
+ return toOptionalTrimmed(getEnvApiKey("vercel-ai-gateway")) ?? toOptionalTrimmed(process.env.VERCEL_OIDC_TOKEN);
852
+ }
853
+ function getPiGatewayApiKeyOverride() {
867
854
  return toOptionalTrimmed(process.env.VERCEL_OIDC_TOKEN);
868
855
  }
869
856
  function extractText(message) {
@@ -930,18 +917,7 @@ function parseJsonCandidate(text) {
930
917
  }
931
918
  }
932
919
  function resolveGatewayModel(modelId) {
933
- let models;
934
- try {
935
- models = getModels(GATEWAY_PROVIDER);
936
- } catch (error) {
937
- const message = error instanceof Error ? error.message : String(error);
938
- if (message.includes('missing "key" field')) {
939
- throw new Error(
940
- "Invalid AI gateway credentials: Vercel API did not return a key. Set AI_GATEWAY_API_KEY, or ensure VERCEL_OIDC_TOKEN is valid in a Vercel runtime."
941
- );
942
- }
943
- throw error;
944
- }
920
+ const models = getModels(GATEWAY_PROVIDER);
945
921
  const matched = models.find((model) => model.id === modelId);
946
922
  if (!matched) {
947
923
  throw new Error(`Unknown AI Gateway model id: ${modelId}`);
@@ -950,18 +926,15 @@ function resolveGatewayModel(modelId) {
950
926
  }
951
927
  async function completeText(params) {
952
928
  const startedAt = Date.now();
953
- if (!getGatewayApiKey()) {
954
- throw new Error(MISSING_GATEWAY_CREDENTIALS_ERROR);
955
- }
956
929
  const model = resolveGatewayModel(params.modelId);
957
- const apiKey = getGatewayApiKey();
930
+ const apiKey = getPiGatewayApiKeyOverride();
958
931
  const requestMessagesAttribute = serializeGenAiAttribute(params.messages);
959
932
  const startAttributes = {
960
933
  "gen_ai.provider.name": GEN_AI_PROVIDER_NAME,
961
934
  "gen_ai.operation.name": GEN_AI_OPERATION_CHAT,
962
935
  "gen_ai.request.model": params.modelId,
963
936
  ...requestMessagesAttribute ? { "gen_ai.input.messages": requestMessagesAttribute } : {},
964
- "app.ai.auth_mode": apiKey ? "api_key" : "ambient"
937
+ "app.ai.auth_mode": apiKey ? "oidc" : "api_key"
965
938
  };
966
939
  setSpanAttributes(startAttributes);
967
940
  const message = await completeSimple(
@@ -4507,11 +4480,9 @@ function createImageGenerateTool(hooks, deps = {}) {
4507
4480
  }),
4508
4481
  execute: async ({ prompt }) => {
4509
4482
  const fetchImpl = deps.fetch ?? fetch;
4510
- const apiKey = process.env.AI_GATEWAY_API_KEY ?? process.env.VERCEL_OIDC_TOKEN;
4483
+ const apiKey = getGatewayApiKey();
4511
4484
  if (!apiKey) {
4512
- throw new Error(
4513
- "Missing AI gateway credentials (AI_GATEWAY_API_KEY or VERCEL_OIDC_TOKEN)"
4514
- );
4485
+ throw new Error(MISSING_GATEWAY_CREDENTIALS_ERROR);
4515
4486
  }
4516
4487
  const model = process.env.AI_IMAGE_MODEL ?? DEFAULT_IMAGE_MODEL;
4517
4488
  const enrichedPrompt = await enrichImagePrompt(prompt);
@@ -6306,7 +6277,7 @@ function formatSearchFailure(error) {
6306
6277
  }
6307
6278
  function isNonRetryableSearchFailure(message) {
6308
6279
  const normalized = message.toLowerCase();
6309
- return normalized.includes("missing ai gateway credentials");
6280
+ return normalized.includes("missing ai gateway credentials") || normalized.includes("authentication failed");
6310
6281
  }
6311
6282
  function isTimeoutSearchFailure(message) {
6312
6283
  return /timed out/i.test(message);
@@ -6331,14 +6302,8 @@ function createWebSearchTool() {
6331
6302
  execute: async ({ query, max_results }) => {
6332
6303
  const maxResults = max_results ?? 3;
6333
6304
  try {
6334
- const apiKey = getGatewayApiKey();
6335
- if (!apiKey) {
6336
- throw new Error(
6337
- "Missing AI gateway credentials (AI_GATEWAY_API_KEY or VERCEL_OIDC_TOKEN)"
6338
- );
6339
- }
6340
6305
  const model = process.env.AI_WEB_SEARCH_MODEL ?? process.env.AI_FAST_MODEL ?? process.env.AI_MODEL ?? DEFAULT_SEARCH_MODEL;
6341
- const provider = createGatewayProvider({ apiKey });
6306
+ const provider = createGatewayProvider();
6342
6307
  const response = await withTimeout(
6343
6308
  (async () => {
6344
6309
  try {
@@ -9165,24 +9130,6 @@ async function generateAssistantReply(messageText, context = {}) {
9165
9130
  userInput,
9166
9131
  context.conversationContext
9167
9132
  );
9168
- if (!getGatewayApiKey()) {
9169
- const providerError = "Missing AI gateway credentials (AI_GATEWAY_API_KEY or VERCEL_OIDC_TOKEN)";
9170
- return {
9171
- text: `Error: ${providerError}`,
9172
- sandboxId: sandboxExecutor.getSandboxId(),
9173
- sandboxDependencyProfileHash: sandboxExecutor.getDependencyProfileHash(),
9174
- diagnostics: {
9175
- outcome: "provider_error",
9176
- modelId: botConfig.modelId,
9177
- assistantMessageCount: 0,
9178
- toolCalls: [],
9179
- toolResultCount: 0,
9180
- toolErrorCount: 0,
9181
- usedPrimaryText: false,
9182
- errorMessage: providerError
9183
- }
9184
- };
9185
- }
9186
9133
  timeoutResumeMessages = [];
9187
9134
  pendingMcpAuthorizationPause = void 0;
9188
9135
  const generatedFiles = [];
@@ -9387,7 +9334,7 @@ async function generateAssistantReply(messageText, context = {}) {
9387
9334
  }
9388
9335
  );
9389
9336
  agent = new Agent({
9390
- getApiKey: () => getGatewayApiKey(),
9337
+ getApiKey: () => getPiGatewayApiKeyOverride(),
9391
9338
  initialState: {
9392
9339
  systemPrompt: baseInstructions,
9393
9340
  model: resolveGatewayModel(botConfig.modelId),
@@ -12,7 +12,7 @@ import {
12
12
  import { after } from "next/server";
13
13
  import * as Sentry from "@sentry/nextjs";
14
14
  async function loadBot() {
15
- const { bot } = await import("./production-PPQEQOPO.js");
15
+ const { bot } = await import("./production-BGZNVORK.js");
16
16
  return bot;
17
17
  }
18
18
  async function POST(request, context) {
@@ -7,11 +7,11 @@ import {
7
7
  getThreadMessageTopic,
8
8
  removeReactionFromMessage,
9
9
  slackRuntime
10
- } from "./chunk-JNHYSCAO.js";
10
+ } from "./chunk-LWHXDHIN.js";
11
11
  import {
12
12
  getConnectedStateContext,
13
13
  getStateAdapter
14
- } from "./chunk-7GLBFSWP.js";
14
+ } from "./chunk-HRA2FXYH.js";
15
15
  import {
16
16
  createRequestContext,
17
17
  logError,
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  disconnectStateAdapter,
3
3
  resolveRuntimeDependencySnapshot
4
- } from "../chunk-7GLBFSWP.js";
4
+ } from "../chunk-HRA2FXYH.js";
5
5
  import {
6
6
  getPluginProviders,
7
7
  getPluginRuntimeDependencies,
@@ -1,9 +1,9 @@
1
1
  import {
2
2
  POST
3
- } from "../chunk-UPCIISWE.js";
4
- import "../chunk-JNHYSCAO.js";
3
+ } from "../chunk-XHISVOAJ.js";
4
+ import "../chunk-LWHXDHIN.js";
5
5
  import "../chunk-VM3CPAZF.js";
6
- import "../chunk-7GLBFSWP.js";
6
+ import "../chunk-HRA2FXYH.js";
7
7
  import "../chunk-ZBWWHP6Q.js";
8
8
  import "../chunk-KCLEEKYX.js";
9
9
  import "../chunk-ZW4OVKF5.js";
@@ -1,9 +1,9 @@
1
1
  import {
2
2
  POST as POST2
3
- } from "../chunk-T7BIFBYH.js";
3
+ } from "../chunk-PEJ6SSW4.js";
4
4
  import {
5
5
  POST
6
- } from "../chunk-UPCIISWE.js";
6
+ } from "../chunk-XHISVOAJ.js";
7
7
  import {
8
8
  buildConversationContext,
9
9
  buildSlackOutputMessage,
@@ -31,7 +31,7 @@ import {
31
31
  updateConversationStats,
32
32
  uploadFilesToThread,
33
33
  upsertConversationMessage
34
- } from "../chunk-JNHYSCAO.js";
34
+ } from "../chunk-LWHXDHIN.js";
35
35
  import {
36
36
  GET
37
37
  } from "../chunk-4RBEYCOG.js";
@@ -39,7 +39,7 @@ import "../chunk-VM3CPAZF.js";
39
39
  import {
40
40
  botConfig,
41
41
  getStateAdapter
42
- } from "../chunk-7GLBFSWP.js";
42
+ } from "../chunk-HRA2FXYH.js";
43
43
  import {
44
44
  buildOAuthTokenRequest,
45
45
  getPluginOAuthConfig,
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  POST
3
- } from "../chunk-T7BIFBYH.js";
3
+ } from "../chunk-PEJ6SSW4.js";
4
4
  import "../chunk-ZW4OVKF5.js";
5
5
  export {
6
6
  POST
@@ -2,9 +2,9 @@ import {
2
2
  bot,
3
3
  createNormalizingStream,
4
4
  slackRuntime
5
- } from "./chunk-JNHYSCAO.js";
5
+ } from "./chunk-LWHXDHIN.js";
6
6
  import "./chunk-VM3CPAZF.js";
7
- import "./chunk-7GLBFSWP.js";
7
+ import "./chunk-HRA2FXYH.js";
8
8
  import "./chunk-ZBWWHP6Q.js";
9
9
  import "./chunk-KCLEEKYX.js";
10
10
  import "./chunk-ZW4OVKF5.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sentry/junior",
3
- "version": "0.9.1",
3
+ "version": "0.9.3",
4
4
  "private": false,
5
5
  "publishConfig": {
6
6
  "access": "public"