@sentry/junior 0.112.0 → 0.114.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.
Files changed (59) hide show
  1. package/dist/{agent-hooks-6MVTPKP4.js → agent-hooks-WNBUY4OB.js} +8 -8
  2. package/dist/api/conversations/cursor.d.ts +17 -0
  3. package/dist/api/conversations/detail.d.ts +40 -18
  4. package/dist/api/conversations/event-list.d.ts +115 -0
  5. package/dist/api/conversations/event-page.d.ts +18 -0
  6. package/dist/api/conversations/events.d.ts +6 -2
  7. package/dist/api/conversations/projection.d.ts +6 -1
  8. package/dist/api/schema/conversation.d.ts +228 -51
  9. package/dist/api/schema.d.ts +2 -2
  10. package/dist/api/schema.js +7 -1
  11. package/dist/api.js +461 -139
  12. package/dist/app.d.ts +2 -0
  13. package/dist/app.js +33 -24
  14. package/dist/{catalog-runtime-UEO25P2J.js → catalog-runtime-6O4M6JGA.js} +5 -5
  15. package/dist/chat/config.d.ts +1 -1
  16. package/dist/chat/conversations/history.d.ts +86 -0
  17. package/dist/chat/conversations/projection.d.ts +20 -1
  18. package/dist/chat/pi/transcript.d.ts +2 -0
  19. package/dist/chat/services/context-budget.d.ts +7 -2
  20. package/dist/chat/services/context-compaction.d.ts +28 -1
  21. package/dist/chat/services/conversation-memory.d.ts +1 -0
  22. package/dist/chat/services/provider-error.d.ts +40 -0
  23. package/dist/chat/services/provider-retry.d.ts +3 -6
  24. package/dist/chat/services/turn-router.d.ts +1 -0
  25. package/dist/chat/task-execution/state.d.ts +2 -2
  26. package/dist/chat/task-execution/store.d.ts +1 -1
  27. package/dist/chat/tools/sandbox/edit-file.d.ts +1 -1
  28. package/dist/chat/tools/sandbox/text-edits.d.ts +1 -0
  29. package/dist/{chunk-CSS7JHEM.js → chunk-4FUEG3QY.js} +1 -1
  30. package/dist/{chunk-AU2JVUDF.js → chunk-5CZ7RETL.js} +1 -1
  31. package/dist/{chunk-SKEMI4IF.js → chunk-6QWPVTMO.js} +200 -52
  32. package/dist/{chunk-AWNDKI5K.js → chunk-ABPSDO6M.js} +20 -15
  33. package/dist/{chunk-QIALGHRN.js → chunk-FIGAF6KL.js} +34 -2
  34. package/dist/{chunk-TZU3R5OC.js → chunk-K2W4CK7K.js} +1 -1
  35. package/dist/{chunk-2FJ6WEYV.js → chunk-O4GT7LYB.js} +1 -1
  36. package/dist/{chunk-ZHP4KNF7.js → chunk-OSKEC4XU.js} +1 -1
  37. package/dist/{chunk-IV2O4HQJ.js → chunk-PM3PX42K.js} +1 -1
  38. package/dist/{chunk-NDQL4ESR.js → chunk-RD7EJI7H.js} +2 -2
  39. package/dist/{chunk-JE23YR3X.js → chunk-S4QDH23A.js} +75 -43
  40. package/dist/{chunk-GJG67YFS.js → chunk-TLGM5X2M.js} +2 -2
  41. package/dist/{chunk-VBSVNOLA.js → chunk-VNNBSKCO.js} +5 -5
  42. package/dist/{chunk-4EJO4HIC.js → chunk-W6RDUAO3.js} +1 -1
  43. package/dist/{chunk-GR4IB6OQ.js → chunk-WV4UJBAS.js} +431 -96
  44. package/dist/{chunk-66IP6WED.js → chunk-XLFBQJUO.js} +4 -4
  45. package/dist/{chunk-X3SP5RDW.js → chunk-YU6PO42Q.js} +1 -1
  46. package/dist/{chunk-PK4ETCUQ.js → chunk-ZGXH3REA.js} +226 -215
  47. package/dist/cli/chat.js +19 -19
  48. package/dist/cli/check.js +6 -6
  49. package/dist/cli/plugins.js +11 -11
  50. package/dist/cli/snapshot-warmup.js +8 -8
  51. package/dist/cli/upgrade.js +5 -5
  52. package/dist/{db-P5H5RVQV.js → db-4VLP7KBF.js} +5 -5
  53. package/dist/instrumentation.js +2 -2
  54. package/dist/nitro.js +2 -2
  55. package/dist/{runner-B4ZDUO3R.js → runner-IPXLWQOF.js} +12 -13
  56. package/dist/{skills-GWTOZ3XV.js → skills-QCNZISNF.js} +6 -6
  57. package/dist/{validation-QFIC6XH6.js → validation-I2BW3UHD.js} +6 -6
  58. package/dist/version.js +1 -1
  59. package/package.json +6 -6
@@ -1,21 +1,21 @@
1
1
  import {
2
2
  SANDBOX_WORKSPACE_ROOT,
3
3
  getStateAdapter
4
- } from "./chunk-X3SP5RDW.js";
4
+ } from "./chunk-YU6PO42Q.js";
5
5
  import {
6
6
  sleep
7
7
  } from "./chunk-4ZNGQH7C.js";
8
8
  import {
9
9
  toOptionalTrimmed
10
- } from "./chunk-PK4ETCUQ.js";
10
+ } from "./chunk-ZGXH3REA.js";
11
11
  import {
12
12
  pluginCatalogRuntime
13
- } from "./chunk-ZHP4KNF7.js";
13
+ } from "./chunk-OSKEC4XU.js";
14
14
  import {
15
15
  setSpanAttributes,
16
16
  setSpanStatus,
17
17
  withSpan
18
- } from "./chunk-CSS7JHEM.js";
18
+ } from "./chunk-4FUEG3QY.js";
19
19
 
20
20
  // src/chat/sandbox/runtime-dependencies.ts
21
21
  var GLOBAL_RUNTIME_DEPENDENCIES = [
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  getChatConfig
3
- } from "./chunk-PK4ETCUQ.js";
3
+ } from "./chunk-ZGXH3REA.js";
4
4
 
5
5
  // src/chat/state/adapter.ts
6
6
  import { createMemoryState } from "@chat-adapter/state-memory";
@@ -12,7 +12,207 @@ import {
12
12
  normalizeGenAiFinishReason,
13
13
  serializeGenAiAttribute,
14
14
  withSpan
15
- } from "./chunk-CSS7JHEM.js";
15
+ } from "./chunk-4FUEG3QY.js";
16
+
17
+ // src/chat/config.ts
18
+ import { getModel as getModel2 } from "@earendil-works/pi-ai/compat";
19
+
20
+ // src/chat/optional-string.ts
21
+ function toOptionalTrimmed(value) {
22
+ if (!value) {
23
+ return void 0;
24
+ }
25
+ const trimmed = value.trim();
26
+ return trimmed.length > 0 ? trimmed : void 0;
27
+ }
28
+
29
+ // src/chat/pi/sdk.ts
30
+ import {
31
+ completeSimple,
32
+ getEnvApiKey,
33
+ getModel,
34
+ getModels,
35
+ isRetryableAssistantError,
36
+ registerApiProvider
37
+ } from "@earendil-works/pi-ai/compat";
38
+ import {
39
+ stream,
40
+ streamSimple
41
+ } from "@earendil-works/pi-ai/api/anthropic-messages";
42
+
43
+ // src/chat/pi/client.ts
44
+ import { createGatewayProvider } from "@ai-sdk/gateway";
45
+ import { embedMany, generateObject, NoObjectGeneratedError } from "ai";
46
+
47
+ // src/chat/services/provider-error.ts
48
+ var ProviderError = class extends Error {
49
+ code = "provider_error";
50
+ kind;
51
+ modelId;
52
+ retryable;
53
+ retryAfterMs;
54
+ status;
55
+ constructor(details) {
56
+ super(
57
+ `AI provider error: ${details.kind}`,
58
+ details.cause !== void 0 ? { cause: details.cause } : {}
59
+ );
60
+ this.name = "ProviderError";
61
+ this.kind = details.kind;
62
+ this.modelId = details.modelId;
63
+ this.retryable = details.retryable;
64
+ this.retryAfterMs = details.retryAfterMs;
65
+ this.status = details.status;
66
+ }
67
+ };
68
+ var NETWORK_ERROR_CODES = /* @__PURE__ */ new Set([
69
+ "ECONNREFUSED",
70
+ "ECONNRESET",
71
+ "ENOTFOUND",
72
+ "EAI_AGAIN"
73
+ ]);
74
+ var TIMEOUT_ERROR_CODES = /* @__PURE__ */ new Set([
75
+ "ETIMEDOUT",
76
+ "ECONNABORTED",
77
+ "ESOCKETTIMEDOUT"
78
+ ]);
79
+ var CONTENT_POLICY_PATTERN = /\b(?:content|safety)[ _-]?policy\b|\b(?:content|safety) (?:filter|violation)\b|\bmoderation (?:blocked|rejected|refused)\b/i;
80
+ var QUOTA_PATTERN = /insufficient.?quota|quota exceeded|usage limit|available balance|out of budget|billing (?:limit|quota|error)|payment required/i;
81
+ var AUTH_PATTERN = /unauthenticated|invalid.?api.?key|no api key|authentication (?:failed|error|required)|(?:invalid|missing|expired|revoked).{0,24}\bcredentials?\b|\bcredentials?\b.{0,24}(?:invalid|missing|expired|revoked)|\bno\b.{0,16}\bcredentials?\b/i;
82
+ var PERMISSION_PATTERN = /permission denied|forbidden|not authorized|authorization (?:failed|required|denied)/i;
83
+ var INVALID_REQUEST_PATTERN = /context.?length|context.?window|validation (?:error|failed)|bad request|unsupported model|invalid model|unknown (?:ai gateway )?model|mismatched api/i;
84
+ var CAPACITY_PATTERN = /overloaded|at capacity|capacity exceeded/i;
85
+ var TIMEOUT_PATTERN = /timed? out|timeout|gateway timeout/i;
86
+ var NETWORK_PATTERN = /network.?error|connection (?:error|refused|lost|closed)|fetch failed|socket (?:hang up|closed)|stream ended before/i;
87
+ var SERVER_PATTERN = /service(?: temporarily)?[ _-]?unavailable|server.?error|internal.?error|bad gateway|upstream (?:request )?failed/i;
88
+ var TERMINAL_KINDS = /* @__PURE__ */ new Set([
89
+ "auth",
90
+ "permission",
91
+ "invalid_request",
92
+ "invalid_response",
93
+ "quota",
94
+ "content_policy"
95
+ ]);
96
+ var RETRYABLE_KINDS = /* @__PURE__ */ new Set([
97
+ "rate_limit",
98
+ "capacity",
99
+ "timeout",
100
+ "network",
101
+ "server"
102
+ ]);
103
+ function providerMessage(error) {
104
+ return (error instanceof Error ? error.message : String(error)).trim();
105
+ }
106
+ function extractTransportKind(error, depth = 0) {
107
+ if (!(error instanceof Error) || depth > 4) return void 0;
108
+ const shaped = error;
109
+ const code = typeof shaped.code === "string" ? shaped.code.toUpperCase() : void 0;
110
+ if (code && TIMEOUT_ERROR_CODES.has(code)) return "timeout";
111
+ if (code && NETWORK_ERROR_CODES.has(code)) return "network";
112
+ return extractTransportKind(shaped.cause, depth + 1);
113
+ }
114
+ function extractStatus(error, message) {
115
+ if (error instanceof Error) {
116
+ const shaped = error;
117
+ if (typeof shaped.status === "number") return shaped.status;
118
+ if (typeof shaped.statusCode === "number") return shaped.statusCode;
119
+ }
120
+ const match = message.match(
121
+ /^(?:Error:\s*)?([45]\d\d)\b|\bstatus(?:Code)?["'=:\s]+([45]\d\d)\b/i
122
+ );
123
+ const status = match?.[1] ?? match?.[2];
124
+ return status ? Number(status) : void 0;
125
+ }
126
+ function extractRetryAfterMs(error, message) {
127
+ const headers = error instanceof Error ? error.responseHeaders ?? error.response?.headers : void 0;
128
+ const retryAfter = headers instanceof Headers ? headers.get("retry-after") : headers && typeof headers === "object" ? Object.entries(headers).find(
129
+ ([name]) => name.toLowerCase() === "retry-after"
130
+ )?.[1] : void 0;
131
+ const raw = typeof retryAfter === "string" || typeof retryAfter === "number" ? String(retryAfter) : message.match(/"retry-after"\s*:\s*"?([^",}]+)"?/i)?.[1];
132
+ if (!raw) return void 0;
133
+ const seconds = Number(raw);
134
+ if (Number.isFinite(seconds) && seconds >= 0) return seconds * 1e3;
135
+ const date = Date.parse(raw);
136
+ return Number.isNaN(date) ? void 0 : Math.max(0, date - Date.now());
137
+ }
138
+ function classifyProviderError(status, message, transportKind) {
139
+ if (CONTENT_POLICY_PATTERN.test(message)) return "content_policy";
140
+ if (QUOTA_PATTERN.test(message)) return "quota";
141
+ if (status === 401 || AUTH_PATTERN.test(message)) return "auth";
142
+ if (status === 403 || PERMISSION_PATTERN.test(message)) return "permission";
143
+ if (INVALID_REQUEST_PATTERN.test(message)) return "invalid_request";
144
+ if (status === 429 || /rate.?limit|too many requests/i.test(message)) {
145
+ return "rate_limit";
146
+ }
147
+ if (status === 408) return "timeout";
148
+ if (CAPACITY_PATTERN.test(message)) return "capacity";
149
+ if (transportKind === "timeout" || TIMEOUT_PATTERN.test(message))
150
+ return "timeout";
151
+ if (transportKind === "network" || NETWORK_PATTERN.test(message))
152
+ return "network";
153
+ if (status !== void 0 && status >= 500 || SERVER_PATTERN.test(message)) {
154
+ return "server";
155
+ }
156
+ if (status !== void 0 && status >= 400) {
157
+ return "invalid_request";
158
+ }
159
+ return "unknown";
160
+ }
161
+ function createProviderError(error, options = {}) {
162
+ if (error instanceof ProviderError) return error;
163
+ const message = providerMessage(error);
164
+ const status = extractStatus(error, message);
165
+ const kind = options.kind ?? classifyProviderError(status, message, extractTransportKind(error));
166
+ const retryable = !TERMINAL_KINDS.has(kind) && (options.retryable ?? RETRYABLE_KINDS.has(kind));
167
+ return new ProviderError({
168
+ cause: error,
169
+ kind,
170
+ modelId: options.modelId,
171
+ retryable,
172
+ retryAfterMs: extractRetryAfterMs(error, message),
173
+ status
174
+ });
175
+ }
176
+ function isProviderRetryError(error) {
177
+ return error instanceof ProviderError && error.retryable;
178
+ }
179
+ function getProviderErrorUserMessage(error) {
180
+ switch (error.kind) {
181
+ case "capacity":
182
+ return "The selected model is temporarily unavailable because it is at capacity. Please try again shortly.";
183
+ case "rate_limit": {
184
+ const seconds = error.retryAfterMs ? Math.max(1, Math.ceil(error.retryAfterMs / 1e3)) : void 0;
185
+ return seconds ? `The model is rate-limited. Please try again in about ${seconds} seconds.` : "The model is rate-limited. Please try again shortly.";
186
+ }
187
+ case "timeout":
188
+ case "network":
189
+ case "server":
190
+ return "The model provider had a temporary connection problem. Please try again.";
191
+ case "auth":
192
+ return "The model provider rejected Junior's credentials. This needs an administrator or configuration fix.";
193
+ case "permission":
194
+ return "The model provider denied access to this model or request. Ask an administrator to check model access, organization policy, and region availability.";
195
+ case "quota":
196
+ return "The model provider's usage quota has been exhausted. This needs an administrator or billing configuration fix.";
197
+ case "content_policy":
198
+ return "The model provider blocked this request under its content policy. Please revise the request and try again.";
199
+ case "invalid_request":
200
+ return "The model provider rejected this request as invalid. Please revise the request or ask an administrator to check the model configuration.";
201
+ case "invalid_response":
202
+ return "The model provider returned an invalid response. Please try again.";
203
+ default:
204
+ return "";
205
+ }
206
+ }
207
+ function getProviderErrorAttributes(error) {
208
+ return {
209
+ "app.ai.provider_error.kind": error.kind,
210
+ "app.ai.provider_error.retryable": error.retryable,
211
+ ...error.status !== void 0 ? { "app.ai.provider_error.status": error.status } : {},
212
+ ...error.retryAfterMs !== void 0 ? { "app.ai.provider_error.retry_after_ms": error.retryAfterMs } : {},
213
+ ...error.modelId ? { "gen_ai.request.model": error.modelId } : {}
214
+ };
215
+ }
16
216
 
17
217
  // src/chat/xml.ts
18
218
  function escapeXml(value) {
@@ -70,184 +270,6 @@ function unwrapCurrentInstruction(text) {
70
270
  return body === void 0 ? void 0 : unescapeXml(body);
71
271
  }
72
272
 
73
- // src/chat/turn-context-tag.ts
74
- var TURN_CONTEXT_TAG = "runtime-turn-context";
75
-
76
- // src/chat/pi/transcript.ts
77
- var RUNTIME_TURN_CONTEXT_START = `<${TURN_CONTEXT_TAG}>`;
78
- function userMessageContent(message) {
79
- const record = message;
80
- return record.role === "user" && Array.isArray(record.content) ? record.content : void 0;
81
- }
82
- function isRuntimeTurnContextPart(part) {
83
- return part !== null && typeof part === "object" && part.type === "text" && typeof part.text === "string" && part.text.startsWith(RUNTIME_TURN_CONTEXT_START);
84
- }
85
- var EMBEDDED_THREAD_CONTEXT_TAGS = [
86
- "recent-thread-messages",
87
- "thread-compactions",
88
- "thread-transcript",
89
- "thread-background"
90
- ];
91
- var EMBEDDED_THREAD_CONTEXT_PATTERN = new RegExp(
92
- `<(${EMBEDDED_THREAD_CONTEXT_TAGS.join("|")})(?:\\s[^>]*)?>[\\s\\S]*?</\\1>`,
93
- "g"
94
- );
95
- function isAssistantMessage(value) {
96
- return typeof value === "object" && value !== null && value.role === "assistant";
97
- }
98
- function isToolResultMessage(value) {
99
- return typeof value === "object" && value !== null && value.role === "toolResult";
100
- }
101
- function isToolResultError(result) {
102
- if (!result || typeof result !== "object") return false;
103
- return Boolean(result.isError);
104
- }
105
- function normalizeToolNameFromResult(result) {
106
- if (!result || typeof result !== "object") return void 0;
107
- const record = result;
108
- if (typeof record.toolName === "string" && record.toolName.length > 0) {
109
- return record.toolName;
110
- }
111
- if (typeof record.name === "string" && record.name.length > 0) {
112
- return record.name;
113
- }
114
- return void 0;
115
- }
116
- function getPiMessageRole(value) {
117
- if (!value || typeof value !== "object") {
118
- return void 0;
119
- }
120
- const role = value.role;
121
- return typeof role === "string" ? role : void 0;
122
- }
123
- function extractAssistantText(message) {
124
- const content = message.content ?? [];
125
- return content.filter(
126
- (part) => part.type === "text" && typeof part.text === "string"
127
- ).map((part) => part.text).join("\n");
128
- }
129
- function getTerminalAssistantMessages(messages) {
130
- let lastNonAssistantIndex = -1;
131
- for (let index = messages.length - 1; index >= 0; index -= 1) {
132
- if (!isAssistantMessage(messages[index])) {
133
- lastNonAssistantIndex = index;
134
- break;
135
- }
136
- }
137
- return messages.slice(lastNonAssistantIndex + 1).filter(isAssistantMessage);
138
- }
139
- function trimTrailingAssistantMessages(messages) {
140
- let end = messages.length;
141
- while (end > 0 && getPiMessageRole(messages[end - 1]) === "assistant") {
142
- end -= 1;
143
- }
144
- return end === messages.length ? [...messages] : messages.slice(0, end);
145
- }
146
- function hasRuntimeTurnContext(messages) {
147
- return messages.some(
148
- (message) => userMessageContent(message)?.some(isRuntimeTurnContextPart)
149
- );
150
- }
151
- function retainRuntimeTurnContext(messages) {
152
- return messages.flatMap((message) => {
153
- const runtimeContent = userMessageContent(message)?.filter(isRuntimeTurnContextPart) ?? [];
154
- return runtimeContent.length > 0 ? [{ ...message, content: runtimeContent }] : [];
155
- });
156
- }
157
- function instructionTextForProjection(text) {
158
- const withoutContext = text.replace(EMBEDDED_THREAD_CONTEXT_PATTERN, "").trim();
159
- return unwrapCurrentInstruction(withoutContext) ?? withoutContext;
160
- }
161
- function stripRuntimeTurnContext(messages) {
162
- return messages.flatMap((message) => {
163
- const content = userMessageContent(message);
164
- if (!content) return [message];
165
- const nextContent = content.filter(
166
- (part) => !isRuntimeTurnContextPart(part)
167
- );
168
- if (nextContent.length === content.length) return [message];
169
- if (nextContent.length === 0) return [];
170
- return [{ ...message, content: nextContent }];
171
- });
172
- }
173
-
174
- // src/chat/config.ts
175
- import { getModel as getModel2 } from "@earendil-works/pi-ai/compat";
176
-
177
- // src/chat/optional-string.ts
178
- function toOptionalTrimmed(value) {
179
- if (!value) {
180
- return void 0;
181
- }
182
- const trimmed = value.trim();
183
- return trimmed.length > 0 ? trimmed : void 0;
184
- }
185
-
186
- // src/chat/pi/sdk.ts
187
- import {
188
- completeSimple,
189
- getEnvApiKey,
190
- getModel,
191
- getModels,
192
- isRetryableAssistantError,
193
- registerApiProvider
194
- } from "@earendil-works/pi-ai/compat";
195
- import {
196
- stream,
197
- streamSimple
198
- } from "@earendil-works/pi-ai/api/anthropic-messages";
199
-
200
- // src/chat/pi/client.ts
201
- import { createGatewayProvider } from "@ai-sdk/gateway";
202
- import { embedMany, generateObject } from "ai";
203
-
204
- // src/chat/services/provider-retry.ts
205
- var PROVIDER_RETRY_DELAYS_MS = [2e3, 4e3, 8e3];
206
- var PROVIDER_ERROR_PREFIX = "AI provider error:";
207
- var PROVIDER_RETRY_ERROR_NAME = "ProviderRetryError";
208
- var NON_RETRYABLE_PROVIDER_ERROR_PATTERNS = [
209
- /invalid.?api.?key|no api key|authentication|authorization|permission|forbidden|(?:invalid|missing|expired|revoked).{0,24}\bcredentials?\b|\bcredentials?\b.{0,24}(?:invalid|missing|expired|revoked)|\bno\b.{0,16}\bcredentials?\b/i,
210
- /context.?length|context.?window/i,
211
- /content.?policy|validation|bad request|\b(?:400|401|403)\b/i,
212
- /unsupported model|invalid model|unknown ai gateway model|unknown model|mismatched api/i,
213
- /usage limit|monthly usage limit|available balance|insufficient.?quota|out of budget|quota exceeded|billing/i
214
- ];
215
- function providerMessage(error) {
216
- return (error instanceof Error ? error.message : String(error)).trim();
217
- }
218
- function createProviderError(error) {
219
- const message = providerMessage(error);
220
- const displayMessage = `${PROVIDER_ERROR_PREFIX} ${message || "Unknown provider error"}`;
221
- const providerError = new Error(displayMessage, { cause: error });
222
- if (message && isRetryableProviderFailure(message)) {
223
- providerError.name = PROVIDER_RETRY_ERROR_NAME;
224
- }
225
- return providerError;
226
- }
227
- function isProviderRetryError(error) {
228
- return error instanceof Error && error.name === PROVIDER_RETRY_ERROR_NAME;
229
- }
230
- function isRetryableProviderFailure(errorMessage) {
231
- return !NON_RETRYABLE_PROVIDER_ERROR_PATTERNS.some(
232
- (pattern) => pattern.test(errorMessage)
233
- );
234
- }
235
- function nextProviderRetry(args) {
236
- const delayMs = PROVIDER_RETRY_DELAYS_MS[args.attempt];
237
- if (delayMs === void 0 || !args.retryableFailure) {
238
- return void 0;
239
- }
240
- const messages = trimTrailingAssistantMessages(args.messages);
241
- if (messages.length === args.messages.length) {
242
- return void 0;
243
- }
244
- const tailRole = getPiMessageRole(messages.at(-1));
245
- if (tailRole !== "user" && tailRole !== "toolResult") {
246
- return void 0;
247
- }
248
- return { delayMs, messages };
249
- }
250
-
251
273
  // src/chat/services/context-compaction-marker.ts
252
274
  var COMPACTION_SUMMARY_PREFIX = "Context compaction summary for future Junior turns:";
253
275
  var MODEL_HANDOFF_SUMMARY_PREFIX = "Model handoff checkpoint. Continue the outstanding request now using this summary as the complete prior context:";
@@ -357,7 +379,7 @@ async function completeText(params) {
357
379
  }
358
380
  );
359
381
  } catch (error) {
360
- throw createProviderError(error);
382
+ throw createProviderError(error, { modelId: params.modelId });
361
383
  }
362
384
  const outputText = extractText(message);
363
385
  const outputMessagesAttribute = serializeGenAiAttribute(
@@ -393,7 +415,7 @@ async function completeText(params) {
393
415
  },
394
416
  "AI completion returned provider error"
395
417
  );
396
- throw createProviderError(providerMessage2);
418
+ throw createProviderError(providerMessage2, { modelId: params.modelId });
397
419
  }
398
420
  return {
399
421
  message,
@@ -454,21 +476,10 @@ async function completeObject(params) {
454
476
  );
455
477
  return { object: result.object };
456
478
  } catch (error) {
457
- const providerError = createProviderError(error);
458
- if (isProviderRetryError(providerError)) {
459
- throw providerError;
460
- }
461
- logException(
462
- providerError,
463
- "ai_completion_failed",
464
- {},
465
- {
466
- "gen_ai.provider.name": GEN_AI_PROVIDER_NAME,
467
- "gen_ai.operation.name": GEN_AI_OPERATION_CHAT,
468
- "gen_ai.request.model": params.modelId
469
- },
470
- "AI object completion failed"
471
- );
479
+ const providerError = createProviderError(error, {
480
+ ...NoObjectGeneratedError.isInstance(error) ? { kind: "invalid_response" } : {},
481
+ modelId: params.modelId
482
+ });
472
483
  throw providerError;
473
484
  }
474
485
  }
@@ -494,7 +505,13 @@ async function embedTexts(params) {
494
505
  if (result2.embeddings.length !== texts.length || !dimensions || !result2.embeddings.every(
495
506
  (embedding) => embedding.length === dimensions
496
507
  )) {
497
- throw new Error("Embedding provider returned invalid vectors.");
508
+ throw createProviderError(
509
+ "Embedding provider returned invalid vectors.",
510
+ {
511
+ kind: "invalid_response",
512
+ modelId: params.modelId
513
+ }
514
+ );
498
515
  }
499
516
  setSpanAttributes({
500
517
  "gen_ai.embeddings.dimension.count": dimensions,
@@ -517,7 +534,9 @@ async function embedTexts(params) {
517
534
  vectors: result.result.embeddings
518
535
  };
519
536
  } catch (error) {
520
- const providerError = createProviderError(error);
537
+ const providerError = createProviderError(error, {
538
+ modelId: params.modelId
539
+ });
521
540
  if (isProviderRetryError(providerError)) {
522
541
  throw providerError;
523
542
  }
@@ -593,6 +612,7 @@ var DEFAULT_FUNCTION_MAX_DURATION_SECONDS = 300;
593
612
  var DEFAULT_SLACK_SLASH_COMMAND = "/jr";
594
613
  var DEFAULT_PROCESSING_REACTION_EMOJI = "eyes";
595
614
  var DEFAULT_COMPLETED_REACTION_EMOJI = "white_check_mark";
615
+ var DEFAULT_MODEL_CONTEXT_WINDOW_TOKENS = 4e5;
596
616
  var FUNCTION_TIMEOUT_BUFFER_SECONDS = 20;
597
617
  var CONVERSATION_WORK_SOFT_YIELD_BUFFER_SECONDS = 40;
598
618
  var DEFAULT_ASSISTANT_LOADING_MESSAGES = [
@@ -760,10 +780,10 @@ function readBotConfig(env, functionMaxDurationSeconds) {
760
780
  return {
761
781
  userName: toOptionalTrimmed(env.JUNIOR_BOT_NAME) ?? "junior",
762
782
  profiles: parseProfiles(env.AI_MODEL_PROFILES, modelId, handoffModelId),
763
- modelContextWindowTokens: parseOptionalPositiveInteger(
783
+ contextWindowTokens: parseOptionalPositiveInteger(
764
784
  "AI_MODEL_CONTEXT_WINDOW_TOKENS",
765
785
  env.AI_MODEL_CONTEXT_WINDOW_TOKENS
766
- ),
786
+ ) ?? DEFAULT_MODEL_CONTEXT_WINDOW_TOKENS,
767
787
  reasoningLevel: reasoningLevel === void 0 ? void 0 : parseTurnReasoningLevel(reasoningLevel),
768
788
  fastModelId,
769
789
  imageGenerationModelId: toOptionalTrimmed(env.AI_IMAGE_MODEL) ?? DEFAULT_IMAGE_GENERATION_MODEL_ID,
@@ -895,24 +915,14 @@ function setSlackReactionConfig(overrides) {
895
915
 
896
916
  export {
897
917
  toOptionalTrimmed,
918
+ ProviderError,
919
+ createProviderError,
920
+ isProviderRetryError,
921
+ getProviderErrorUserMessage,
922
+ getProviderErrorAttributes,
898
923
  escapeXml,
899
924
  renderCurrentInstruction,
900
925
  unwrapCurrentInstruction,
901
- TURN_CONTEXT_TAG,
902
- isAssistantMessage,
903
- isToolResultMessage,
904
- isToolResultError,
905
- normalizeToolNameFromResult,
906
- getPiMessageRole,
907
- extractAssistantText,
908
- getTerminalAssistantMessages,
909
- trimTrailingAssistantMessages,
910
- hasRuntimeTurnContext,
911
- retainRuntimeTurnContext,
912
- instructionTextForProjection,
913
- stripRuntimeTurnContext,
914
- isProviderRetryError,
915
- nextProviderRetry,
916
926
  COMPACTION_SUMMARY_PREFIX,
917
927
  MODEL_HANDOFF_SUMMARY_PREFIX,
918
928
  isCompactionSummaryText,
@@ -929,6 +939,7 @@ export {
929
939
  embedTexts,
930
940
  normalizeSlackEmojiName,
931
941
  TURN_REASONING_LEVELS,
942
+ parseTurnReasoningLevel,
932
943
  STANDARD_MODEL_PROFILE,
933
944
  DEFAULT_HANDOFF_MODEL_PROFILE,
934
945
  modelProfileSchema,
package/dist/cli/chat.js CHANGED
@@ -1,35 +1,35 @@
1
1
  import {
2
2
  createAgentRunner,
3
3
  executeAgentRun
4
- } from "../chunk-GR4IB6OQ.js";
5
- import "../chunk-SKEMI4IF.js";
6
- import "../chunk-66IP6WED.js";
4
+ } from "../chunk-WV4UJBAS.js";
5
+ import "../chunk-6QWPVTMO.js";
6
+ import "../chunk-XLFBQJUO.js";
7
7
  import "../chunk-MU6HHZEN.js";
8
8
  import "../chunk-PDO5BLNM.js";
9
9
  import "../chunk-UIE3R5XU.js";
10
10
  import {
11
11
  loadAppPluginSet
12
12
  } from "../chunk-Y2CM7HXH.js";
13
- import "../chunk-VBSVNOLA.js";
14
- import "../chunk-X3SP5RDW.js";
15
- import "../chunk-NDQL4ESR.js";
16
- import "../chunk-QIALGHRN.js";
13
+ import "../chunk-VNNBSKCO.js";
14
+ import "../chunk-YU6PO42Q.js";
15
+ import "../chunk-RD7EJI7H.js";
16
+ import "../chunk-FIGAF6KL.js";
17
17
  import "../chunk-JQFJO5WH.js";
18
18
  import "../chunk-4ZNGQH7C.js";
19
- import "../chunk-PK4ETCUQ.js";
19
+ import "../chunk-ZGXH3REA.js";
20
20
  import "../chunk-VFUK3X5B.js";
21
21
  import "../chunk-6Y5L4BOM.js";
22
- import "../chunk-GJG67YFS.js";
23
- import "../chunk-ZHP4KNF7.js";
24
- import "../chunk-TZU3R5OC.js";
22
+ import "../chunk-TLGM5X2M.js";
23
+ import "../chunk-OSKEC4XU.js";
24
+ import "../chunk-K2W4CK7K.js";
25
25
  import "../chunk-C4MZ3GP5.js";
26
- import "../chunk-CSS7JHEM.js";
26
+ import "../chunk-4FUEG3QY.js";
27
27
  import "../chunk-42WRQLJ6.js";
28
28
  import "../chunk-6GWA276C.js";
29
29
  import "../chunk-B3IT5END.js";
30
30
  import "../chunk-3V7OFJZC.js";
31
- import "../chunk-AU2JVUDF.js";
32
- import "../chunk-IV2O4HQJ.js";
31
+ import "../chunk-5CZ7RETL.js";
32
+ import "../chunk-PM3PX42K.js";
33
33
  import "../chunk-MLKGABMK.js";
34
34
 
35
35
  // src/cli/chat.ts
@@ -152,10 +152,10 @@ async function configureLocalChatPlugins(pluginSet) {
152
152
  databaseModule
153
153
  ] = await Promise.all([
154
154
  import("../plugins-PZMDS7AT.js"),
155
- import("../agent-hooks-6MVTPKP4.js"),
156
- import("../catalog-runtime-UEO25P2J.js"),
157
- import("../validation-QFIC6XH6.js"),
158
- import("../db-P5H5RVQV.js")
155
+ import("../agent-hooks-WNBUY4OB.js"),
156
+ import("../catalog-runtime-6O4M6JGA.js"),
157
+ import("../validation-I2BW3UHD.js"),
158
+ import("../db-4VLP7KBF.js")
159
159
  ]);
160
160
  const resolvedPluginSet = pluginSet === void 0 ? await loadLocalPluginSet() : pluginSet ?? void 0;
161
161
  const plugins = pluginsModule.pluginRuntimeRegistrationsFromPluginSet(resolvedPluginSet);
@@ -216,7 +216,7 @@ function newRunConversationId() {
216
216
  async function prepareLocalChatRun(io, pluginSet) {
217
217
  defaultStateAdapterForLocalChat();
218
218
  await configureLocalChatPlugins(pluginSet);
219
- const { runLocalAgentTurn } = await import("../runner-B4ZDUO3R.js");
219
+ const { runLocalAgentTurn } = await import("../runner-IPXLWQOF.js");
220
220
  const deps = {
221
221
  agentRunner: createAgentRunner(executeAgentRun),
222
222
  deliverReply: async (reply) => {
package/dist/cli/check.js CHANGED
@@ -1,13 +1,13 @@
1
1
  import {
2
2
  parseSkillFile
3
- } from "../chunk-GJG67YFS.js";
4
- import "../chunk-ZHP4KNF7.js";
3
+ } from "../chunk-TLGM5X2M.js";
4
+ import "../chunk-OSKEC4XU.js";
5
5
  import {
6
6
  parseInlinePluginManifest,
7
7
  parsePluginManifest
8
- } from "../chunk-TZU3R5OC.js";
8
+ } from "../chunk-K2W4CK7K.js";
9
9
  import "../chunk-C4MZ3GP5.js";
10
- import "../chunk-CSS7JHEM.js";
10
+ import "../chunk-4FUEG3QY.js";
11
11
  import "../chunk-42WRQLJ6.js";
12
12
  import "../chunk-6GWA276C.js";
13
13
  import "../chunk-B3IT5END.js";
@@ -16,8 +16,8 @@ import {
16
16
  JUNIOR_CONVERSATION_WORK_CALLBACK_ROUTE,
17
17
  JUNIOR_HEARTBEAT_ROUTE,
18
18
  LEGACY_JUNIOR_CONVERSATION_WORK_FUNCTION
19
- } from "../chunk-AU2JVUDF.js";
20
- import "../chunk-IV2O4HQJ.js";
19
+ } from "../chunk-5CZ7RETL.js";
20
+ import "../chunk-PM3PX42K.js";
21
21
  import "../chunk-MLKGABMK.js";
22
22
 
23
23
  // src/cli/check.ts