@sentry/junior 0.114.0 → 0.116.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 (147) hide show
  1. package/dist/{agent-hooks-WNBUY4OB.js → agent-hooks-67NFITDH.js} +13 -12
  2. package/dist/api/conversations/detail.d.ts +20 -0
  3. package/dist/api/conversations/event-list.d.ts +2 -0
  4. package/dist/api/conversations/event-page.d.ts +1 -1
  5. package/dist/api/conversations/events.d.ts +1 -1
  6. package/dist/api/health.d.ts +7 -0
  7. package/dist/api/people/profile.d.ts +2 -2
  8. package/dist/api/people/shared.d.ts +1 -1
  9. package/dist/api/personal-tokens/create.d.ts +11 -0
  10. package/dist/api/personal-tokens/list.d.ts +12 -0
  11. package/dist/api/personal-tokens/revoke.d.ts +5 -0
  12. package/dist/api/personal-tokens/routes.d.ts +4 -0
  13. package/dist/api/plugin-reports.d.ts +62 -0
  14. package/dist/api/plugins.d.ts +8 -0
  15. package/dist/api/route.d.ts +1 -1
  16. package/dist/api/runtime.d.ts +24 -0
  17. package/dist/api/schema/conversation.d.ts +26 -0
  18. package/dist/api/schema/person.d.ts +3 -3
  19. package/dist/api/schema/personal-token.d.ts +38 -0
  20. package/dist/api/schema.d.ts +4 -2
  21. package/dist/api/schema.js +19 -7
  22. package/dist/api/skills.d.ts +6 -0
  23. package/dist/api.d.ts +1 -0
  24. package/dist/api.js +285 -121
  25. package/dist/app.js +1957 -5677
  26. package/dist/catalog-runtime-CWZY6GTH.js +18 -0
  27. package/dist/chat/agent/request.d.ts +7 -0
  28. package/dist/chat/agent/resume.d.ts +1 -0
  29. package/dist/chat/agent/sandbox.d.ts +3 -0
  30. package/dist/chat/agent/tools.d.ts +3 -0
  31. package/dist/chat/agent-dispatch/context.d.ts +2 -0
  32. package/dist/chat/agent-dispatch/heartbeat.d.ts +11 -5
  33. package/dist/chat/agent-dispatch/signing.d.ts +14 -5
  34. package/dist/chat/agent-dispatch/store.d.ts +36 -15
  35. package/dist/chat/agent-dispatch/types.d.ts +23 -10
  36. package/dist/chat/agent-dispatch/work.d.ts +58 -0
  37. package/dist/chat/app/factory.d.ts +12 -3
  38. package/dist/chat/config.d.ts +2 -0
  39. package/dist/chat/conversations/history.d.ts +291 -290
  40. package/dist/chat/conversations/projection.d.ts +2 -2
  41. package/dist/chat/local/credential-sync.d.ts +5 -0
  42. package/dist/chat/local/oauth-relay.d.ts +4 -0
  43. package/dist/chat/mcp/oauth.d.ts +1 -0
  44. package/dist/chat/mcp/tool-manager.d.ts +2 -1
  45. package/dist/chat/oauth-authorization.d.ts +17 -0
  46. package/dist/chat/oauth-flow.d.ts +9 -0
  47. package/dist/chat/pi/conversation-events.d.ts +6 -2
  48. package/dist/chat/plugins/annotations.d.ts +8 -0
  49. package/dist/chat/plugins/registry.d.ts +0 -3
  50. package/dist/chat/plugins/types.d.ts +0 -2
  51. package/dist/chat/runtime/agent-continue-runner.d.ts +4 -0
  52. package/dist/chat/runtime/reply-executor.d.ts +6 -1
  53. package/dist/chat/runtime/slack-resume.d.ts +5 -1
  54. package/dist/chat/runtime/turn-input.d.ts +3 -0
  55. package/dist/chat/sandbox/egress/schemas.d.ts +46 -0
  56. package/dist/chat/sandbox/egress/signals.d.ts +9 -0
  57. package/dist/chat/sandbox/sandbox.d.ts +4 -1
  58. package/dist/chat/sandbox/session.d.ts +2 -11
  59. package/dist/chat/sandbox/workspace.d.ts +10 -2
  60. package/dist/chat/sentry-payload-filter.d.ts +4 -4
  61. package/dist/chat/services/mcp-auth-orchestration.d.ts +5 -3
  62. package/dist/chat/services/plugin-auth-orchestration.d.ts +2 -0
  63. package/dist/chat/services/turn-session-record.d.ts +14 -1
  64. package/dist/chat/slack/dispatch-turn.d.ts +25 -0
  65. package/dist/chat/slack/message-control.d.ts +2 -0
  66. package/dist/chat/slack/oauth-authorization-message.d.ts +3 -0
  67. package/dist/chat/state/turn-session.d.ts +11 -0
  68. package/dist/chat/task-execution/slack-work.d.ts +2 -0
  69. package/dist/chat/tool-support/text-range-result.d.ts +3 -0
  70. package/dist/chat/tool-support/zod-tool.d.ts +2 -1
  71. package/dist/chat/tools/definition.d.ts +3 -5
  72. package/dist/chat/tools/query-conversation-events.d.ts +68 -0
  73. package/dist/chat/tools/sandbox/file-utils.d.ts +8 -1
  74. package/dist/chat/tools/sandbox/find-files.d.ts +2 -1
  75. package/dist/chat/tools/sandbox/grep.d.ts +2 -1
  76. package/dist/{chunk-OSKEC4XU.js → chunk-25GU5B5E.js} +1 -1
  77. package/dist/{chunk-XLFBQJUO.js → chunk-3H45VOBZ.js} +32 -7
  78. package/dist/{chunk-4FUEG3QY.js → chunk-3JOGUT46.js} +4 -16
  79. package/dist/chunk-4CODA7P5.js +43 -0
  80. package/dist/{chunk-O4GT7LYB.js → chunk-4DD6AOCG.js} +3 -43
  81. package/dist/{chunk-YU6PO42Q.js → chunk-53ZKTQO6.js} +1 -1
  82. package/dist/{chunk-WV4UJBAS.js → chunk-5UNB623T.js} +1282 -2536
  83. package/dist/{chunk-TLGM5X2M.js → chunk-6RQ5GCWH.js} +2 -2
  84. package/dist/{chunk-MIAKQNYX.js → chunk-6ZK6FZIV.js} +1 -1
  85. package/dist/{chunk-W6RDUAO3.js → chunk-BXLS3I4W.js} +1 -1
  86. package/dist/{chunk-RD7EJI7H.js → chunk-CI3VK7X5.js} +69 -3
  87. package/dist/chunk-DIB4GX3G.js +8 -0
  88. package/dist/{chunk-42WRQLJ6.js → chunk-F3B2YJ76.js} +0 -14
  89. package/dist/chunk-FA6POGLH.js +70 -0
  90. package/dist/{chunk-6Y5L4BOM.js → chunk-FXOYURO4.js} +5 -3
  91. package/dist/chunk-HDSDCEPK.js +80 -0
  92. package/dist/{chunk-C4MZ3GP5.js → chunk-HZF5P5UN.js} +1 -1
  93. package/dist/{chunk-K2W4CK7K.js → chunk-JZPQ5K4V.js} +10 -129
  94. package/dist/{chunk-FIGAF6KL.js → chunk-KBNDFU6J.js} +108 -38
  95. package/dist/{chunk-PM3PX42K.js → chunk-MGH5ADQS.js} +1 -2
  96. package/dist/{chunk-5CZ7RETL.js → chunk-N7TMYLF2.js} +1 -1
  97. package/dist/chunk-OB42YVAE.js +16 -0
  98. package/dist/{chunk-6QWPVTMO.js → chunk-OF5FODBL.js} +125 -23
  99. package/dist/{chunk-2ZTTXTSZ.js → chunk-PE44LDDQ.js} +9 -4
  100. package/dist/chunk-PGKWXHYJ.js +1870 -0
  101. package/dist/{chunk-ZGXH3REA.js → chunk-PZGPCOSD.js} +12 -2
  102. package/dist/{chunk-JQFJO5WH.js → chunk-RXRQJF7Y.js} +74 -17
  103. package/dist/{chunk-S4QDH23A.js → chunk-TC4ZEM2D.js} +113 -79
  104. package/dist/{chunk-ABPSDO6M.js → chunk-UEVLIYK5.js} +234 -165
  105. package/dist/chunk-VKZ6WVAY.js +4318 -0
  106. package/dist/{chunk-VNNBSKCO.js → chunk-VZCSLYCE.js} +22 -7
  107. package/dist/chunk-W3U3YQYI.js +71 -0
  108. package/dist/{chunk-SG5WAA7H.js → chunk-WKU7TY22.js} +0 -3
  109. package/dist/cli/chat.js +74 -42
  110. package/dist/cli/check.js +10 -8
  111. package/dist/cli/init.js +1 -0
  112. package/dist/cli/plugins.js +18 -16
  113. package/dist/cli/snapshot-warmup.js +13 -11
  114. package/dist/cli/upgrade.js +12 -10
  115. package/dist/db/schema/api-tokens.d.ts +160 -0
  116. package/dist/db/schema/conversation-annotations.d.ts +142 -0
  117. package/dist/db/schema.d.ts +305 -1
  118. package/dist/{db-4VLP7KBF.js → db-57FHVGGQ.js} +9 -8
  119. package/dist/handlers/agent-dispatch.d.ts +7 -3
  120. package/dist/handlers/sandbox-egress-signals.d.ts +4 -0
  121. package/dist/instrumentation.js +72 -4
  122. package/dist/nitro.js +5 -5
  123. package/dist/oauth-callback-server-PAQRPXZX.js +231 -0
  124. package/dist/oauth-relay-3ZU72UGL.js +9 -0
  125. package/dist/personal-tokens/store.d.ts +27 -0
  126. package/dist/{plugins-PZMDS7AT.js → plugins-IUJA4VBU.js} +1 -1
  127. package/dist/reporting-schema.d.ts +10 -4
  128. package/dist/reporting.d.ts +5 -5
  129. package/dist/{runner-IPXLWQOF.js → runner-4ISZYJEX.js} +141 -74
  130. package/dist/sandbox-egress-signals-CDFAP67O.js +75 -0
  131. package/dist/{skills-QCNZISNF.js → skills-UE2KXQMB.js} +10 -8
  132. package/dist/validation-PO5LHTJT.js +21 -0
  133. package/dist/version.js +1 -1
  134. package/migrations/0008_sticky_rage.sql +14 -0
  135. package/migrations/0009_slippery_harrier.sql +12 -0
  136. package/migrations/0010_native_conversation_history.sql +142 -0
  137. package/migrations/meta/0008_snapshot.json +1076 -0
  138. package/migrations/meta/0009_snapshot.json +1146 -0
  139. package/migrations/meta/0010_snapshot.json +1190 -0
  140. package/migrations/meta/_journal.json +22 -1
  141. package/package.json +6 -7
  142. package/dist/catalog-runtime-6O4M6JGA.js +0 -16
  143. package/dist/chat/agent-dispatch/runner.d.ts +0 -13
  144. package/dist/chat/capabilities/catalog.d.ts +0 -16
  145. package/dist/chat/oauth-authorization-message.d.ts +0 -6
  146. package/dist/validation-I2BW3UHD.js +0 -19
  147. package/dist/{chunk-KNFROR7R.js → chunk-5I6ORJUY.js} +1 -1
@@ -2,8 +2,9 @@ import {
2
2
  pluginTaskId,
3
3
  pluginTaskParamsSchema,
4
4
  sendVercelPluginTask
5
- } from "./chunk-KNFROR7R.js";
5
+ } from "./chunk-5I6ORJUY.js";
6
6
  import {
7
+ buildDeterministicTurnId,
7
8
  clearPendingAuth,
8
9
  coerceThreadConversationState,
9
10
  getAgentTurnSessionRecord,
@@ -15,178 +16,65 @@ import {
15
16
  isToolResultError,
16
17
  isToolResultMessage,
17
18
  markConversationMessage,
19
+ markTurnClosed,
18
20
  markTurnCompleted,
19
21
  mergeArtifactsState,
20
22
  normalizeToolNameFromResult,
23
+ persistThreadStateById,
21
24
  stripRuntimeTurnContext,
22
25
  updateConversationStats
23
- } from "./chunk-6QWPVTMO.js";
26
+ } from "./chunk-OF5FODBL.js";
24
27
  import {
25
28
  createPluginEmbedder,
26
29
  createPluginLogger,
27
30
  createPluginModel,
28
31
  createPluginState,
29
32
  getPlugins
30
- } from "./chunk-VNNBSKCO.js";
33
+ } from "./chunk-VZCSLYCE.js";
31
34
  import {
32
35
  getStateAdapter
33
- } from "./chunk-YU6PO42Q.js";
36
+ } from "./chunk-53ZKTQO6.js";
34
37
  import {
35
38
  getDb
36
- } from "./chunk-FIGAF6KL.js";
39
+ } from "./chunk-KBNDFU6J.js";
37
40
  import {
38
41
  ProviderError,
39
42
  getProviderErrorAttributes,
40
43
  getProviderErrorUserMessage
41
- } from "./chunk-ZGXH3REA.js";
44
+ } from "./chunk-PZGPCOSD.js";
42
45
  import {
43
46
  buildTurnFailureResponse
44
- } from "./chunk-4FUEG3QY.js";
47
+ } from "./chunk-3JOGUT46.js";
45
48
  import {
46
49
  parseSlackMessageTs
47
- } from "./chunk-42WRQLJ6.js";
50
+ } from "./chunk-F3B2YJ76.js";
48
51
 
49
- // src/chat/services/turn-failure-response.ts
50
- function requireTurnFailureEventId(eventId, eventName) {
51
- if (!eventId) {
52
- throw new Error(`Sentry did not return an event ID for ${eventName}`);
53
- }
54
- return eventId;
55
- }
56
- function getExecutionFailureReason(reply) {
57
- const errorMessage = reply.diagnostics.errorMessage?.trim();
58
- if (errorMessage) {
59
- return errorMessage;
60
- }
61
- if (reply.diagnostics.toolErrorCount > 0) {
62
- return `${reply.diagnostics.toolErrorCount} tool result error(s)`;
63
- }
64
- if (reply.diagnostics.assistantMessageCount > 0) {
65
- return "assistant returned no text";
66
- }
67
- return "empty assistant turn";
68
- }
69
- function getFailureCapture(reply) {
70
- if (reply.diagnostics.outcome === "provider_error") {
71
- return {
72
- eventName: "agent_turn_provider_error",
73
- error: reply.diagnostics.providerError ?? new Error(
74
- reply.diagnostics.errorMessage ?? "Provider error without explicit message"
75
- ),
76
- attributes: reply.diagnostics.providerError instanceof ProviderError ? getProviderErrorAttributes(reply.diagnostics.providerError) : {},
77
- body: "Agent turn failed with provider error"
78
- };
79
- }
80
- const failureReason = getExecutionFailureReason(reply);
81
- return {
82
- eventName: "agent_turn_execution_failure",
83
- error: new Error(`Agent turn execution failure: ${failureReason}`),
84
- attributes: {
85
- "app.ai.execution_failure_reason": failureReason
86
- },
87
- body: "Agent turn completed with execution failure"
88
- };
89
- }
90
- function getAgentTurnDiagnosticsAttributes(reply) {
91
- return {
92
- "app.ai.outcome": reply.diagnostics.outcome,
93
- "app.ai.assistant_messages": reply.diagnostics.assistantMessageCount,
94
- "app.ai.tool_results": reply.diagnostics.toolResultCount,
95
- "app.ai.tool_error_results": reply.diagnostics.toolErrorCount,
96
- "app.ai.tool_call_count": reply.diagnostics.toolCalls.length,
97
- "app.ai.used_primary_text": reply.diagnostics.usedPrimaryText,
98
- ...reply.diagnostics.reasoningLevel ? {
99
- "gen_ai.request.reasoning.level": reply.diagnostics.reasoningLevel
100
- } : {},
101
- ...reply.diagnostics.stopReason ? {
102
- "gen_ai.response.finish_reasons": [reply.diagnostics.stopReason]
103
- } : {},
104
- ...reply.diagnostics.errorMessage && reply.diagnostics.outcome !== "provider_error" ? { "exception.message": reply.diagnostics.errorMessage } : {}
52
+ // src/chat/runtime/delivered-turn-state.ts
53
+ function buildDeliveredTurnStatePatch(args) {
54
+ const conversation = structuredClone(args.conversation);
55
+ const artifactStatePatch = {
56
+ ...args.reply.artifactStatePatch ?? {},
57
+ ...args.artifactStatePatch ?? {}
105
58
  };
106
- }
107
- function finalizeFailedTurnReplyWithEvent(args) {
108
- if (args.reply.diagnostics.outcome === "success") {
109
- return { reply: args.reply };
110
- }
111
- const capture = getFailureCapture(args.reply);
112
- const eventId = requireTurnFailureEventId(
113
- args.logException(
114
- capture.error,
115
- capture.eventName,
116
- args.context,
117
- {
118
- ...getAgentTurnDiagnosticsAttributes(args.reply),
119
- ...args.attributes,
120
- ...capture.attributes
121
- },
122
- capture.body
123
- ),
124
- capture.eventName
125
- );
126
- const providerPartialText = args.reply.diagnostics.outcome === "provider_error" && args.reply.diagnostics.assistantMessageCount > 0 ? args.reply.text.trim() : "";
127
- const providerUserMessage = args.reply.diagnostics.providerError instanceof ProviderError ? getProviderErrorUserMessage(args.reply.diagnostics.providerError) : "";
128
- const failureText = providerUserMessage ? `${providerUserMessage} Reference: \`event_id=${eventId}\`.` : buildTurnFailureResponse(eventId);
59
+ const artifacts = Object.keys(artifactStatePatch).length > 0 ? mergeArtifactsState(args.artifacts, artifactStatePatch) : void 0;
60
+ clearPendingAuth(conversation, args.sessionId);
61
+ markConversationMessage(conversation, args.userMessageId, {
62
+ replied: true,
63
+ skippedReason: void 0
64
+ });
65
+ markTurnCompleted({
66
+ conversation,
67
+ nowMs: Date.now(),
68
+ sessionId: args.sessionId,
69
+ updateConversationStats
70
+ });
129
71
  return {
130
- eventId,
131
- reply: {
132
- ...args.reply,
133
- text: providerPartialText ? `${providerPartialText}${getInterruptionMarker()}` : failureText
134
- }
72
+ artifacts,
73
+ conversation,
74
+ sandboxRef: args.reply.sandboxRef
135
75
  };
136
76
  }
137
77
 
138
- // src/chat/conversations/turn-lifecycle.ts
139
- var ConversationTurnLifecycleService = class {
140
- constructor(events) {
141
- this.events = events;
142
- }
143
- events;
144
- /** Record the turn start once after every input message is durable. */
145
- async start(input) {
146
- await this.events.append(input.conversationId, [
147
- {
148
- idempotencyKey: `turn:${input.turnId}:started`,
149
- createdAtMs: input.createdAtMs,
150
- data: {
151
- type: "turn_started",
152
- turnId: input.turnId,
153
- inputMessageIds: input.inputMessageIds,
154
- surface: input.surface
155
- }
156
- }
157
- ]);
158
- }
159
- /** Record successful or intentional-silence completion once. */
160
- async complete(input) {
161
- await this.events.append(input.conversationId, [
162
- {
163
- idempotencyKey: `turn:${input.turnId}:terminal`,
164
- createdAtMs: input.createdAtMs,
165
- data: {
166
- type: "turn_completed",
167
- turnId: input.turnId,
168
- outcome: input.outcome
169
- }
170
- }
171
- ]);
172
- }
173
- /** Record a classified failure once without accepting raw error details. */
174
- async fail(input) {
175
- await this.events.append(input.conversationId, [
176
- {
177
- idempotencyKey: `turn:${input.turnId}:terminal`,
178
- createdAtMs: input.createdAtMs,
179
- data: {
180
- type: "turn_failed",
181
- turnId: input.turnId,
182
- failureCode: input.failureCode,
183
- ...input.eventId ? { eventId: input.eventId } : {}
184
- }
185
- }
186
- ]);
187
- }
188
- };
189
-
190
78
  // src/chat/plugins/task-runner.ts
191
79
  import {
192
80
  isPrivateSource,
@@ -497,38 +385,219 @@ async function processPluginTask(message, options = {}) {
497
385
  });
498
386
  }
499
387
 
500
- // src/chat/runtime/delivered-turn-state.ts
501
- function buildDeliveredTurnStatePatch(args) {
502
- const conversation = structuredClone(args.conversation);
503
- const artifactStatePatch = {
504
- ...args.reply.artifactStatePatch ?? {},
505
- ...args.artifactStatePatch ?? {}
388
+ // src/chat/services/turn-failure-response.ts
389
+ function requireTurnFailureEventId(eventId, eventName) {
390
+ if (!eventId) {
391
+ throw new Error(`Sentry did not return an event ID for ${eventName}`);
392
+ }
393
+ return eventId;
394
+ }
395
+ function getExecutionFailureReason(reply) {
396
+ const errorMessage = reply.diagnostics.errorMessage?.trim();
397
+ if (errorMessage) {
398
+ return errorMessage;
399
+ }
400
+ if (reply.diagnostics.toolErrorCount > 0) {
401
+ return `${reply.diagnostics.toolErrorCount} tool result error(s)`;
402
+ }
403
+ if (reply.diagnostics.assistantMessageCount > 0) {
404
+ return "assistant returned no text";
405
+ }
406
+ return "empty assistant turn";
407
+ }
408
+ function getFailureCapture(reply) {
409
+ if (reply.diagnostics.outcome === "provider_error") {
410
+ return {
411
+ eventName: "agent_turn_provider_error",
412
+ error: reply.diagnostics.providerError ?? new Error(
413
+ reply.diagnostics.errorMessage ?? "Provider error without explicit message"
414
+ ),
415
+ attributes: reply.diagnostics.providerError instanceof ProviderError ? getProviderErrorAttributes(reply.diagnostics.providerError) : {},
416
+ body: "Agent turn failed with provider error"
417
+ };
418
+ }
419
+ const failureReason = getExecutionFailureReason(reply);
420
+ return {
421
+ eventName: "agent_turn_execution_failure",
422
+ error: new Error(`Agent turn execution failure: ${failureReason}`),
423
+ attributes: {
424
+ "app.ai.execution_failure_reason": failureReason
425
+ },
426
+ body: "Agent turn completed with execution failure"
506
427
  };
507
- const artifacts = Object.keys(artifactStatePatch).length > 0 ? mergeArtifactsState(args.artifacts, artifactStatePatch) : void 0;
508
- clearPendingAuth(conversation, args.sessionId);
509
- markConversationMessage(conversation, args.userMessageId, {
510
- replied: true,
511
- skippedReason: void 0
512
- });
513
- markTurnCompleted({
514
- conversation,
428
+ }
429
+ function getAgentTurnDiagnosticsAttributes(reply) {
430
+ return {
431
+ "app.ai.outcome": reply.diagnostics.outcome,
432
+ "app.ai.assistant_messages": reply.diagnostics.assistantMessageCount,
433
+ "app.ai.tool_results": reply.diagnostics.toolResultCount,
434
+ "app.ai.tool_error_results": reply.diagnostics.toolErrorCount,
435
+ "app.ai.tool_call_count": reply.diagnostics.toolCalls.length,
436
+ "app.ai.used_primary_text": reply.diagnostics.usedPrimaryText,
437
+ ...reply.diagnostics.reasoningLevel ? {
438
+ "gen_ai.request.reasoning.level": reply.diagnostics.reasoningLevel
439
+ } : {},
440
+ ...reply.diagnostics.stopReason ? {
441
+ "gen_ai.response.finish_reasons": [reply.diagnostics.stopReason]
442
+ } : {},
443
+ ...reply.diagnostics.errorMessage && reply.diagnostics.outcome !== "provider_error" ? { "exception.message": reply.diagnostics.errorMessage } : {}
444
+ };
445
+ }
446
+ function finalizeFailedTurnReplyWithEvent(args) {
447
+ if (args.reply.diagnostics.outcome === "success") {
448
+ return { reply: args.reply };
449
+ }
450
+ const capture = getFailureCapture(args.reply);
451
+ const eventId = requireTurnFailureEventId(
452
+ args.logException(
453
+ capture.error,
454
+ capture.eventName,
455
+ args.context,
456
+ {
457
+ ...getAgentTurnDiagnosticsAttributes(args.reply),
458
+ ...args.attributes,
459
+ ...capture.attributes
460
+ },
461
+ capture.body
462
+ ),
463
+ capture.eventName
464
+ );
465
+ const providerPartialText = args.reply.diagnostics.outcome === "provider_error" && args.reply.diagnostics.assistantMessageCount > 0 ? args.reply.text.trim() : "";
466
+ const providerUserMessage = args.reply.diagnostics.providerError instanceof ProviderError ? getProviderErrorUserMessage(args.reply.diagnostics.providerError) : "";
467
+ const failureText = providerUserMessage ? `${providerUserMessage} Reference: \`event_id=${eventId}\`.` : buildTurnFailureResponse(eventId);
468
+ return {
469
+ eventId,
470
+ reply: {
471
+ ...args.reply,
472
+ text: providerPartialText ? `${providerPartialText}${getInterruptionMarker()}` : failureText
473
+ }
474
+ };
475
+ }
476
+
477
+ // src/chat/conversations/turn-lifecycle.ts
478
+ var ConversationTurnLifecycleService = class {
479
+ constructor(events) {
480
+ this.events = events;
481
+ }
482
+ events;
483
+ /** Record the turn start once after every input message is durable. */
484
+ async start(input) {
485
+ await this.events.append(input.conversationId, [
486
+ {
487
+ idempotencyKey: `turn:${input.turnId}:started`,
488
+ createdAtMs: input.createdAtMs,
489
+ data: {
490
+ type: "turn_started",
491
+ turnId: input.turnId,
492
+ inputMessageIds: input.inputMessageIds,
493
+ surface: input.surface
494
+ }
495
+ }
496
+ ]);
497
+ }
498
+ /** Record successful or intentional-silence completion once. */
499
+ async complete(input) {
500
+ await this.events.append(input.conversationId, [
501
+ {
502
+ idempotencyKey: `turn:${input.turnId}:terminal`,
503
+ createdAtMs: input.createdAtMs,
504
+ data: {
505
+ type: "turn_completed",
506
+ turnId: input.turnId,
507
+ outcome: input.outcome
508
+ }
509
+ }
510
+ ]);
511
+ }
512
+ /** Record a classified failure once without accepting raw error details. */
513
+ async fail(input) {
514
+ await this.events.append(input.conversationId, [
515
+ {
516
+ idempotencyKey: `turn:${input.turnId}:terminal`,
517
+ createdAtMs: input.createdAtMs,
518
+ data: {
519
+ type: "turn_failed",
520
+ turnId: input.turnId,
521
+ failureCode: input.failureCode,
522
+ ...input.eventId ? { eventId: input.eventId } : {}
523
+ }
524
+ }
525
+ ]);
526
+ }
527
+ };
528
+
529
+ // src/chat/runtime/turn-user-message.ts
530
+ function getTurnUserMessage(conversation, sessionId) {
531
+ for (let index = conversation.messages.length - 1; index >= 0; index -= 1) {
532
+ const message = conversation.messages[index];
533
+ if (message?.role !== "user") {
534
+ continue;
535
+ }
536
+ if (buildDeterministicTurnId(message.id) === sessionId) {
537
+ return message;
538
+ }
539
+ }
540
+ return void 0;
541
+ }
542
+ function getTurnUserMessageId(conversation, sessionId) {
543
+ return getTurnUserMessage(conversation, sessionId)?.id;
544
+ }
545
+ function getTurnUserSlackMessageTs(message) {
546
+ return parseSlackMessageTs(message?.meta?.slackTs);
547
+ }
548
+ function getTurnUserReplyAttachmentContext(message) {
549
+ const inboundAttachmentCount = message?.meta?.attachmentCount ?? 0;
550
+ const imageAttachmentCount = message?.meta?.imageAttachmentCount ?? 0;
551
+ const imagesHydrated = message?.meta?.imagesHydrated === true;
552
+ return {
553
+ ...inboundAttachmentCount > 0 ? { inboundAttachmentCount } : {},
554
+ ...!imagesHydrated && imageAttachmentCount > 0 ? { omittedImageAttachmentCount: imageAttachmentCount } : {}
555
+ };
556
+ }
557
+
558
+ // src/chat/runtime/auth-pause-state.ts
559
+ function completeAuthPauseTurn(args) {
560
+ markConversationMessage(
561
+ args.conversation,
562
+ getTurnUserMessageId(args.conversation, args.sessionId),
563
+ {
564
+ replied: true,
565
+ skippedReason: void 0
566
+ }
567
+ );
568
+ markTurnClosed({
569
+ conversation: args.conversation,
515
570
  nowMs: Date.now(),
516
571
  sessionId: args.sessionId,
517
572
  updateConversationStats
518
573
  });
519
- return {
520
- artifacts,
574
+ }
575
+ async function persistAuthPauseTurnState(args) {
576
+ const currentState = await getPersistedThreadState(args.threadStateId);
577
+ const conversation = coerceThreadConversationState(currentState);
578
+ await hydrateConversationMessages({
521
579
  conversation,
522
- sandboxRef: args.reply.sandboxRef
523
- };
580
+ conversationId: args.threadStateId
581
+ });
582
+ completeAuthPauseTurn({
583
+ conversation,
584
+ sessionId: args.sessionId
585
+ });
586
+ await persistThreadStateById(args.threadStateId, { conversation });
524
587
  }
525
588
 
526
589
  export {
590
+ buildDeliveredTurnStatePatch,
591
+ getTurnUserMessage,
592
+ getTurnUserMessageId,
593
+ getTurnUserSlackMessageTs,
594
+ getTurnUserReplyAttachmentContext,
595
+ scheduleSessionCompletedPluginTasks,
596
+ processPluginTask,
527
597
  requireTurnFailureEventId,
528
598
  getAgentTurnDiagnosticsAttributes,
529
599
  finalizeFailedTurnReplyWithEvent,
530
600
  ConversationTurnLifecycleService,
531
- scheduleSessionCompletedPluginTasks,
532
- processPluginTask,
533
- buildDeliveredTurnStatePatch
601
+ completeAuthPauseTurn,
602
+ persistAuthPauseTurnState
534
603
  };