@sentry/junior 0.71.3 → 0.73.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 (103) hide show
  1. package/bin/junior.mjs +22 -10
  2. package/dist/api-reference.d.ts +2 -0
  3. package/dist/app.d.ts +12 -3
  4. package/dist/app.js +2522 -15560
  5. package/dist/chat/agent-dispatch/heartbeat.d.ts +0 -6
  6. package/dist/chat/agent-dispatch/runner.d.ts +2 -0
  7. package/dist/chat/agent-dispatch/store.d.ts +2 -2
  8. package/dist/chat/agent-dispatch/types.d.ts +6 -3
  9. package/dist/chat/agent-dispatch/validation.d.ts +2 -3
  10. package/dist/chat/app/production.d.ts +8 -1
  11. package/dist/chat/app/services.d.ts +7 -0
  12. package/dist/chat/destination.d.ts +3 -1
  13. package/dist/chat/logging.d.ts +3 -0
  14. package/dist/chat/mcp/errors.d.ts +3 -0
  15. package/dist/chat/mcp/tool-manager.d.ts +5 -1
  16. package/dist/chat/oauth-flow.d.ts +1 -1
  17. package/dist/chat/plugins/agent-hooks.d.ts +3 -2
  18. package/dist/chat/plugins/registry.d.ts +2 -0
  19. package/dist/chat/plugins/types.d.ts +2 -0
  20. package/dist/chat/prompt.d.ts +4 -1
  21. package/dist/chat/requester.d.ts +67 -0
  22. package/dist/chat/respond.d.ts +8 -8
  23. package/dist/chat/runtime/agent-continue-runner.d.ts +25 -0
  24. package/dist/chat/runtime/reply-executor.d.ts +7 -5
  25. package/dist/chat/runtime/slack-resume.d.ts +3 -3
  26. package/dist/chat/runtime/slack-runtime.d.ts +13 -3
  27. package/dist/chat/runtime/turn.d.ts +17 -3
  28. package/dist/chat/sandbox/egress-credentials.d.ts +5 -2
  29. package/dist/chat/sandbox/egress-policy.d.ts +5 -1
  30. package/dist/chat/sandbox/egress-proxy.d.ts +2 -0
  31. package/dist/chat/sandbox/egress-schemas.d.ts +4 -0
  32. package/dist/chat/sandbox/egress-session.d.ts +3 -1
  33. package/dist/chat/sandbox/egress-tracing.d.ts +7 -0
  34. package/dist/chat/sandbox/sandbox.d.ts +2 -0
  35. package/dist/chat/sandbox/session.d.ts +3 -2
  36. package/dist/chat/services/agent-continue.d.ts +27 -0
  37. package/dist/chat/services/auth-pause-response.d.ts +1 -1
  38. package/dist/chat/services/auth-pause.d.ts +2 -1
  39. package/dist/chat/services/mcp-auth-orchestration.d.ts +1 -1
  40. package/dist/chat/services/message-actor-identity.d.ts +12 -4
  41. package/dist/chat/services/plugin-auth-orchestration.d.ts +9 -8
  42. package/dist/chat/services/turn-result.d.ts +3 -0
  43. package/dist/chat/services/turn-session-record.d.ts +10 -7
  44. package/dist/chat/slack/user.d.ts +4 -4
  45. package/dist/chat/state/adapter.d.ts +2 -0
  46. package/dist/chat/state/conversation-details.d.ts +4 -3
  47. package/dist/chat/state/session-log.d.ts +43 -0
  48. package/dist/chat/state/turn-session.d.ts +7 -10
  49. package/dist/chat/task-execution/slack-work.d.ts +5 -5
  50. package/dist/chat/task-execution/store.d.ts +83 -48
  51. package/dist/chat/task-execution/worker.d.ts +3 -3
  52. package/dist/chat/tools/definition.d.ts +3 -0
  53. package/dist/chat/tools/execution/tool-error-handler.d.ts +2 -1
  54. package/dist/chat/tools/slack/canvas-tools.d.ts +3 -2
  55. package/dist/chat/tools/slack/channel-list-messages.d.ts +2 -2
  56. package/dist/chat/tools/slack/channel-post-message.d.ts +3 -2
  57. package/dist/chat/tools/slack/context.d.ts +15 -2
  58. package/dist/chat/tools/slack/message-add-reaction.d.ts +3 -2
  59. package/dist/chat/tools/slack/thread-read.d.ts +2 -2
  60. package/dist/chat/tools/types.d.ts +20 -23
  61. package/dist/{chunk-BBXYXOJW.js → chunk-3BYAPS6B.js} +48 -529
  62. package/dist/{chunk-UXG6TU2U.js → chunk-7Q5YOUUT.js} +16 -93
  63. package/dist/chunk-AL5T52ZD.js +1119 -0
  64. package/dist/chunk-CYUI7JU5.js +195 -0
  65. package/dist/{chunk-R62YWUNO.js → chunk-DIMX5F3T.js} +10 -28
  66. package/dist/chunk-G3E7SCME.js +28 -0
  67. package/dist/chunk-KVZL5NZS.js +519 -0
  68. package/dist/chunk-M4FLLXXD.js +212 -0
  69. package/dist/chunk-OQSYYOLM.js +12787 -0
  70. package/dist/{chunk-GT67ZWZQ.js → chunk-OR6NQJ5E.js} +5 -3
  71. package/dist/{chunk-B5HKWWQB.js → chunk-RY6AL5C7.js} +8 -6
  72. package/dist/chunk-SJHUF3DP.js +43 -0
  73. package/dist/{chunk-XE2VFQQN.js → chunk-UOTZ3EEQ.js} +1 -1
  74. package/dist/{chunk-HOGQL2H6.js → chunk-UZVHXZ7V.js} +1357 -1486
  75. package/dist/{chunk-76YMBKW7.js → chunk-V4VYUY4A.js} +27 -14
  76. package/dist/{chunk-JS4HURDT.js → chunk-WS2EG3GW.js} +224 -224
  77. package/dist/chunk-ZDA2HYX5.js +275 -0
  78. package/dist/cli/chat.js +205 -0
  79. package/dist/cli/check.js +6 -5
  80. package/dist/cli/run.js +18 -2
  81. package/dist/cli/snapshot-warmup.js +11 -8
  82. package/dist/cli/upgrade.js +599 -0
  83. package/dist/deployment.d.ts +4 -0
  84. package/dist/handlers/agent-dispatch.d.ts +6 -1
  85. package/dist/handlers/mcp-oauth-callback.d.ts +6 -1
  86. package/dist/handlers/oauth-callback.d.ts +6 -1
  87. package/dist/handlers/sandbox-egress-proxy.d.ts +2 -0
  88. package/dist/handlers/webhooks.d.ts +4 -2
  89. package/dist/instrumentation.js +17 -2
  90. package/dist/nitro.d.ts +1 -1
  91. package/dist/nitro.js +10 -10
  92. package/dist/plugins.d.ts +1 -1
  93. package/dist/reporting/conversations.d.ts +116 -0
  94. package/dist/reporting.d.ts +24 -129
  95. package/dist/reporting.js +320 -166
  96. package/dist/runner-LMAM4OGD.js +259 -0
  97. package/package.json +3 -3
  98. package/dist/chat/runtime/timeout-resume-runner.d.ts +0 -19
  99. package/dist/chat/services/requester-identity.d.ts +0 -19
  100. package/dist/chat/services/timeout-resume.d.ts +0 -23
  101. package/dist/chunk-6YY4Q3D4.js +0 -12
  102. package/dist/chunk-Z3YD6NHK.js +0 -12
  103. package/dist/handlers/turn-resume.d.ts +0 -4
@@ -0,0 +1,259 @@
1
+ import {
2
+ buildConversationContext,
3
+ buildDeliveredTurnStatePatch,
4
+ coerceThreadArtifactsState,
5
+ generateAssistantReply,
6
+ getPersistedSandboxState,
7
+ getPersistedThreadState,
8
+ markConversationMessage,
9
+ markTurnFailed,
10
+ normalizeConversationText,
11
+ persistThreadStateById,
12
+ startActiveTurn,
13
+ updateConversationStats,
14
+ upsertConversationMessage
15
+ } from "./chunk-OQSYYOLM.js";
16
+ import {
17
+ commitMessages,
18
+ loadProjection
19
+ } from "./chunk-UZVHXZ7V.js";
20
+ import "./chunk-OR6NQJ5E.js";
21
+ import {
22
+ coerceThreadConversationState
23
+ } from "./chunk-M4FLLXXD.js";
24
+ import "./chunk-AL5T52ZD.js";
25
+ import "./chunk-V4VYUY4A.js";
26
+ import "./chunk-RY6AL5C7.js";
27
+ import "./chunk-G3E7SCME.js";
28
+ import "./chunk-7Q5YOUUT.js";
29
+ import "./chunk-KVZL5NZS.js";
30
+ import "./chunk-DIMX5F3T.js";
31
+ import {
32
+ stripRuntimeTurnContext,
33
+ trimTrailingAssistantMessages
34
+ } from "./chunk-WS2EG3GW.js";
35
+ import "./chunk-CYUI7JU5.js";
36
+ import "./chunk-3BYAPS6B.js";
37
+ import "./chunk-SJHUF3DP.js";
38
+ import "./chunk-2KG3PWR4.js";
39
+
40
+ // src/chat/local/runner.ts
41
+ import { THREAD_STATE_TTL_MS } from "chat";
42
+ import {
43
+ localDestinationSchema
44
+ } from "@sentry/junior-plugin-api";
45
+ var DELIVERED_STATE_PERSIST_ATTEMPTS = 3;
46
+ function localDestination(conversationId) {
47
+ const parsed = localDestinationSchema.safeParse({
48
+ platform: "local",
49
+ conversationId
50
+ });
51
+ if (!parsed.success) {
52
+ throw new Error("Invalid local conversation id");
53
+ }
54
+ return parsed.data;
55
+ }
56
+ function localTurnId(sequence) {
57
+ return `local-turn-${sequence}`;
58
+ }
59
+ function localReply(reply) {
60
+ return {
61
+ ...reply.files ? { files: reply.files } : {},
62
+ text: reply.text
63
+ };
64
+ }
65
+ function sleep(ms) {
66
+ return new Promise((resolve) => setTimeout(resolve, ms));
67
+ }
68
+ function nextUserMessageSequence(conversation) {
69
+ return conversation.messages.filter((message) => message.role === "user").length + 1;
70
+ }
71
+ function preparedLocalPiMessages(messages) {
72
+ return stripRuntimeTurnContext(trimTrailingAssistantMessages(messages));
73
+ }
74
+ async function loadLocalPiMessages(args) {
75
+ const projection = await loadProjection({
76
+ conversationId: args.conversationId
77
+ });
78
+ if (args.fallback.length >= projection.length && args.fallback.length > 0) {
79
+ return preparedLocalPiMessages(args.fallback);
80
+ }
81
+ if (projection.length > 0) {
82
+ return preparedLocalPiMessages(projection);
83
+ }
84
+ return void 0;
85
+ }
86
+ async function persistDeliveredLocalTurnState(conversationId, patch) {
87
+ let lastError;
88
+ for (let attempt = 1; attempt <= DELIVERED_STATE_PERSIST_ATTEMPTS; attempt += 1) {
89
+ try {
90
+ await persistThreadStateById(conversationId, patch);
91
+ return;
92
+ } catch (error) {
93
+ lastError = error;
94
+ if (attempt < DELIVERED_STATE_PERSIST_ATTEMPTS) {
95
+ await sleep(attempt * 100);
96
+ }
97
+ }
98
+ }
99
+ throw lastError;
100
+ }
101
+ async function runLocalAgentTurn(input, deps) {
102
+ const text = input.message.trim();
103
+ if (!text) {
104
+ throw new Error("Local agent message must not be empty");
105
+ }
106
+ if (!deps.deliverReply) {
107
+ throw new Error("Local reply delivery is required");
108
+ }
109
+ const destination = localDestination(input.conversationId);
110
+ const generateAssistantReply2 = deps.generateAssistantReply ?? generateAssistantReply;
111
+ const now = deps.now ?? (() => Date.now());
112
+ const persisted = await getPersistedThreadState(input.conversationId);
113
+ const conversation = coerceThreadConversationState(persisted);
114
+ let artifacts = coerceThreadArtifactsState(persisted);
115
+ let { sandboxId, sandboxDependencyProfileHash } = getPersistedSandboxState(persisted);
116
+ const initialArtifacts = artifacts;
117
+ const initialSandboxId = sandboxId;
118
+ const initialSandboxDependencyProfileHash = sandboxDependencyProfileHash;
119
+ const sequence = nextUserMessageSequence(conversation);
120
+ const turnId = localTurnId(sequence);
121
+ const userMessageId = `${turnId}:user`;
122
+ const startedAtMs = now();
123
+ upsertConversationMessage(conversation, {
124
+ id: userMessageId,
125
+ role: "user",
126
+ text: normalizeConversationText(text),
127
+ createdAtMs: startedAtMs,
128
+ author: {
129
+ fullName: "Local CLI",
130
+ userId: "local-cli",
131
+ userName: "local"
132
+ },
133
+ meta: {
134
+ explicitMention: true,
135
+ replied: false
136
+ }
137
+ });
138
+ startActiveTurn({
139
+ conversation,
140
+ nextTurnId: turnId,
141
+ updateConversationStats
142
+ });
143
+ await persistThreadStateById(input.conversationId, { conversation });
144
+ let reply;
145
+ let completedState;
146
+ let piMessagesBeforeRun;
147
+ try {
148
+ const piMessages = await loadLocalPiMessages({
149
+ conversationId: input.conversationId,
150
+ fallback: conversation.piMessages
151
+ });
152
+ piMessagesBeforeRun = piMessages;
153
+ reply = await generateAssistantReply2(text, {
154
+ authorizationFlowMode: "disabled",
155
+ conversationContext: buildConversationContext(conversation, {
156
+ excludeMessageId: userMessageId
157
+ }),
158
+ artifactState: artifacts,
159
+ credentialContext: {
160
+ actor: { type: "system", id: "local-cli" }
161
+ },
162
+ destination,
163
+ requester: {
164
+ fullName: "Local CLI",
165
+ platform: "local",
166
+ userId: "local-cli",
167
+ userName: "local"
168
+ },
169
+ piMessages,
170
+ surface: "internal",
171
+ correlation: {
172
+ conversationId: input.conversationId,
173
+ turnId,
174
+ runId: turnId
175
+ },
176
+ sandbox: {
177
+ sandboxId,
178
+ sandboxDependencyProfileHash
179
+ },
180
+ onArtifactStateUpdated: async (nextArtifacts) => {
181
+ artifacts = nextArtifacts;
182
+ await persistThreadStateById(input.conversationId, {
183
+ artifacts,
184
+ conversation,
185
+ sandboxId,
186
+ sandboxDependencyProfileHash
187
+ });
188
+ },
189
+ onSandboxAcquired: async (sandbox) => {
190
+ sandboxId = sandbox.sandboxId;
191
+ sandboxDependencyProfileHash = sandbox.sandboxDependencyProfileHash;
192
+ await persistThreadStateById(input.conversationId, {
193
+ artifacts,
194
+ conversation,
195
+ sandboxId,
196
+ sandboxDependencyProfileHash
197
+ });
198
+ },
199
+ onStatus: async (status) => {
200
+ await deps.onStatus?.(status.text);
201
+ },
202
+ onTextDelta: deps.onTextDelta
203
+ });
204
+ completedState = buildDeliveredTurnStatePatch({
205
+ artifacts,
206
+ conversation,
207
+ reply,
208
+ sessionId: turnId,
209
+ userMessageId
210
+ });
211
+ await deps.deliverReply(localReply(reply));
212
+ } catch (error) {
213
+ if (reply) {
214
+ await commitMessages({
215
+ conversationId: input.conversationId,
216
+ messages: piMessagesBeforeRun ?? [],
217
+ ttlMs: THREAD_STATE_TTL_MS
218
+ });
219
+ }
220
+ markTurnFailed({
221
+ conversation,
222
+ nowMs: now(),
223
+ sessionId: turnId,
224
+ userMessageId,
225
+ markConversationMessage,
226
+ updateConversationStats
227
+ });
228
+ await persistThreadStateById(input.conversationId, {
229
+ artifacts: initialArtifacts,
230
+ conversation,
231
+ sandboxId: initialSandboxId ?? "",
232
+ sandboxDependencyProfileHash: initialSandboxDependencyProfileHash ?? ""
233
+ });
234
+ throw error;
235
+ }
236
+ await persistDeliveredLocalTurnState(input.conversationId, {
237
+ artifacts: completedState.artifacts ?? artifacts,
238
+ conversation: reply.piMessages ? {
239
+ ...completedState.conversation,
240
+ piMessages: reply.piMessages
241
+ } : completedState.conversation,
242
+ sandboxId: reply.sandboxId ?? sandboxId,
243
+ sandboxDependencyProfileHash: reply.sandboxDependencyProfileHash ?? sandboxDependencyProfileHash
244
+ });
245
+ if (reply.piMessages) {
246
+ await commitMessages({
247
+ conversationId: input.conversationId,
248
+ messages: reply.piMessages,
249
+ ttlMs: THREAD_STATE_TTL_MS
250
+ });
251
+ }
252
+ return {
253
+ conversationId: input.conversationId,
254
+ outcome: reply.diagnostics.outcome
255
+ };
256
+ }
257
+ export {
258
+ runLocalAgentTurn
259
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sentry/junior",
3
- "version": "0.71.3",
3
+ "version": "0.73.0",
4
4
  "private": false,
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -65,7 +65,7 @@
65
65
  "node-html-markdown": "^2.0.0",
66
66
  "yaml": "^2.9.0",
67
67
  "zod": "^4.4.3",
68
- "@sentry/junior-plugin-api": "0.71.3"
68
+ "@sentry/junior-plugin-api": "0.73.0"
69
69
  },
70
70
  "devDependencies": {
71
71
  "@types/node": "^25.9.1",
@@ -78,7 +78,7 @@
78
78
  "typescript": "^6.0.3",
79
79
  "vercel": "^54.4.0",
80
80
  "vitest": "^4.1.7",
81
- "@sentry/junior-scheduler": "0.71.3"
81
+ "@sentry/junior-scheduler": "0.73.0"
82
82
  },
83
83
  "scripts": {
84
84
  "build": "tsup && tsc -p tsconfig.build.json --emitDeclarationOnly",
@@ -1,19 +0,0 @@
1
- import { type TurnContinuationRequest } from "@/chat/services/timeout-resume";
2
- /** Runtime ports for timeout continuation scheduling. */
3
- export interface TimeoutResumeRunnerOptions {
4
- scheduleTurnTimeoutResume?: (request: TurnContinuationRequest) => Promise<void>;
5
- }
6
- /**
7
- * Resume one durable timeout continuation for a Slack thread.
8
- *
9
- * Returns false when the session became stale before generation began.
10
- */
11
- export declare function resumeTimedOutTurn(payload: TurnContinuationRequest, options?: TimeoutResumeRunnerOptions): Promise<boolean>;
12
- /**
13
- * Retry timeout continuation when the normal Slack thread lock is briefly busy.
14
- *
15
- * Returns false when the session became stale before generation began. A busy
16
- * lock that is rescheduled still returns true because runnable work remains
17
- * durable.
18
- */
19
- export declare function resumeTimedOutTurnWithLockRetry(payload: TurnContinuationRequest, options?: TimeoutResumeRunnerOptions): Promise<boolean>;
@@ -1,19 +0,0 @@
1
- export interface ActorIdentityInput {
2
- email?: string;
3
- fullName?: string;
4
- userId?: string;
5
- userName?: string;
6
- }
7
- export interface SlackActorProfile {
8
- email?: string;
9
- fullName?: string;
10
- userName?: string;
11
- }
12
- /** Keep actor ids exact at platform boundaries before they enter owned state. */
13
- export declare function parseActorUserId(value: unknown): string | undefined;
14
- /** Assert persisted actor ids without read-side repair. */
15
- export declare function isActorUserId(value: string | undefined): value is string;
16
- /** Keep authority ids exact while attaching optional presentation fields. */
17
- export declare function buildActorIdentity(requester: ActorIdentityInput | undefined, requesterId?: string): ActorIdentityInput | undefined;
18
- /** Use Slack profile data only as presentation around the exact user id. */
19
- export declare function slackActorIdentity(userId: string, profile: SlackActorProfile | null | undefined): ActorIdentityInput;
@@ -1,23 +0,0 @@
1
- import type { StateAdapter } from "chat";
2
- import type { Destination } from "@sentry/junior-plugin-api";
3
- import type { ConversationWorkQueue } from "@/chat/task-execution/queue";
4
- export interface TurnContinuationRequest {
5
- conversationId: string;
6
- destination: Destination;
7
- expectedVersion: number;
8
- sessionId: string;
9
- }
10
- export interface ScheduleTurnTimeoutResumeOptions {
11
- nowMs?: number;
12
- queue?: ConversationWorkQueue;
13
- state?: StateAdapter;
14
- }
15
- /** Build the callback request for an awaiting automatic turn continuation. */
16
- export declare function getAwaitingTurnContinuationRequest(args: {
17
- conversationId: string;
18
- sessionId: string;
19
- }): Promise<TurnContinuationRequest | undefined>;
20
- /** Schedule durable conversation work to resume a timed-out turn. */
21
- export declare function scheduleTurnTimeoutResume(request: TurnContinuationRequest, options?: ScheduleTurnTimeoutResumeOptions): Promise<void>;
22
- /** Verify and parse an authenticated timeout resume callback request. */
23
- export declare function verifyTurnTimeoutResumeRequest(request: Request): Promise<TurnContinuationRequest | undefined>;
@@ -1,12 +0,0 @@
1
- // src/deployment.ts
2
- var JUNIOR_HEARTBEAT_ROUTE = "/api/internal/heartbeat";
3
- var JUNIOR_HEARTBEAT_CRON_SCHEDULE = "* * * * *";
4
- var JUNIOR_CONVERSATION_WORK_CALLBACK_ROUTE = "/api/internal/agent/continue";
5
- var LEGACY_JUNIOR_CONVERSATION_WORK_FUNCTION = "api/internal/agent/continue.ts";
6
-
7
- export {
8
- JUNIOR_HEARTBEAT_ROUTE,
9
- JUNIOR_HEARTBEAT_CRON_SCHEDULE,
10
- JUNIOR_CONVERSATION_WORK_CALLBACK_ROUTE,
11
- LEGACY_JUNIOR_CONVERSATION_WORK_FUNCTION
12
- };
@@ -1,12 +0,0 @@
1
- import {
2
- __reExport
3
- } from "./chunk-2KG3PWR4.js";
4
-
5
- // src/chat/sentry.ts
6
- var sentry_exports = {};
7
- __reExport(sentry_exports, node_star);
8
- import * as node_star from "@sentry/node";
9
-
10
- export {
11
- sentry_exports
12
- };
@@ -1,4 +0,0 @@
1
- import { type TimeoutResumeRunnerOptions } from "@/chat/runtime/timeout-resume-runner";
2
- import type { WaitUntilFn } from "@/handlers/types";
3
- /** Handle an authenticated internal timeout-resume callback. */
4
- export declare function POST(request: Request, waitUntil: WaitUntilFn, options?: TimeoutResumeRunnerOptions): Promise<Response>;