@sentry/junior 0.179.0 → 0.181.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 (137) hide show
  1. package/dist/{agent-hooks-32IDCLMW.js → agent-hooks-IQUW6ERD.js} +16 -18
  2. package/dist/api/schema/workspace.d.ts +2 -0
  3. package/dist/api/schema.js +1 -2
  4. package/dist/api.js +202 -199
  5. package/dist/app.d.ts +4 -0
  6. package/dist/app.js +300 -1259
  7. package/dist/catalog-runtime-PMQWNIXA.js +14 -0
  8. package/dist/chat/agent/sandbox.d.ts +0 -2
  9. package/dist/chat/api-turns/routing.d.ts +4 -0
  10. package/dist/chat/api-turns/work.d.ts +5 -0
  11. package/dist/chat/config.d.ts +5 -2
  12. package/dist/chat/configuration/defaults.d.ts +1 -1
  13. package/dist/chat/conversations/projection.d.ts +6 -4
  14. package/dist/chat/ingress/message-router.d.ts +3 -0
  15. package/dist/chat/model-profile.d.ts +8 -10
  16. package/dist/chat/pi/conversation-events.d.ts +3 -2
  17. package/dist/chat/plugins/agent-hooks.d.ts +1 -1
  18. package/dist/chat/plugins/task-queue.d.ts +40 -3
  19. package/dist/chat/plugins/task-runner.d.ts +1 -1
  20. package/dist/chat/queue/callback.d.ts +26 -0
  21. package/dist/chat/queue/sign.d.ts +30 -0
  22. package/dist/chat/sandbox/sandbox.d.ts +0 -2
  23. package/dist/chat/sandbox/session.d.ts +0 -2
  24. package/dist/chat/sandbox/skill-sync.d.ts +1 -1
  25. package/dist/chat/sandbox/snapshot/events.d.ts +23 -0
  26. package/dist/chat/sandbox/snapshot/job-callback.d.ts +5 -0
  27. package/dist/chat/sandbox/snapshot/job-queue.d.ts +26 -0
  28. package/dist/chat/sandbox/snapshot/job-runner.d.ts +11 -0
  29. package/dist/chat/sandbox/snapshot/not-ready-error.d.ts +6 -0
  30. package/dist/chat/sandbox/snapshot/workspace.d.ts +9 -3
  31. package/dist/chat/services/turn-router.d.ts +4 -3
  32. package/dist/chat/services/turn-session-routing.d.ts +1 -0
  33. package/dist/chat/task-execution/queue-signing.d.ts +10 -21
  34. package/dist/chat/task-execution/state.d.ts +48 -0
  35. package/dist/chat/task-execution/store.d.ts +28 -2
  36. package/dist/chat/task-execution/worker.d.ts +4 -1
  37. package/dist/chat/tools/handoff/tool.d.ts +1 -1
  38. package/dist/chat/tools/types.d.ts +2 -0
  39. package/dist/chat/workspaces/types.d.ts +2 -0
  40. package/dist/{chunk-Q5B3WTGG.js → chunk-3KCQEG6W.js} +42 -41
  41. package/dist/{chunk-XZY6G5YZ.js → chunk-3KSSALN4.js} +180 -87
  42. package/dist/{chunk-3AFVR5UC.js → chunk-3X55QRAG.js} +18 -16
  43. package/dist/{chunk-SLGGOASN.js → chunk-4IX32NSL.js} +46 -46
  44. package/dist/{chunk-6ZWRNC4D.js → chunk-6Y5B5PEX.js} +1 -1
  45. package/dist/chunk-7H2VZTWN.js +103 -0
  46. package/dist/{chunk-CGA4ERJ5.js → chunk-CEMMLV5L.js} +1 -1
  47. package/dist/{chunk-FIANEE7Z.js → chunk-CM5HNV2W.js} +6 -6
  48. package/dist/{chunk-TKB25A3L.js → chunk-CZYNWPWD.js} +2 -1
  49. package/dist/{chunk-3I7XE3PA.js → chunk-D6ZD7VXP.js} +49 -38
  50. package/dist/chunk-DKIJ2RP5.js +68 -0
  51. package/dist/{chunk-G2CAC4CV.js → chunk-DSA6WTRP.js} +74 -68
  52. package/dist/{chunk-OOUNJNMR.js → chunk-DWPN6SCH.js} +1 -1
  53. package/dist/{chunk-HQNE5APD.js → chunk-EBMRB6Z6.js} +100 -79
  54. package/dist/{chunk-ZQMG3CL5.js → chunk-EM7EECT5.js} +16 -16
  55. package/dist/{chunk-XSPSCWLH.js → chunk-ETJTXYHY.js} +4 -4
  56. package/dist/{chunk-FTGD2FBP.js → chunk-EU7KJDOG.js} +2 -2
  57. package/dist/{chunk-CJLBLELR.js → chunk-FWILPBVQ.js} +8 -61
  58. package/dist/{chunk-4GWXAILB.js → chunk-GPA3ZSYY.js} +1 -1
  59. package/dist/{chunk-U4TKB6F6.js → chunk-GREV5PJK.js} +108 -5
  60. package/dist/{chunk-KJLHIHFF.js → chunk-GWFRPQNP.js} +43 -230
  61. package/dist/{chunk-YFNAMRGE.js → chunk-HEBMSITT.js} +1 -1
  62. package/dist/chunk-HJ27A6YB.js +218 -0
  63. package/dist/{chunk-R5NWWYIS.js → chunk-HZHUMCNV.js} +5 -5
  64. package/dist/{chunk-RTRBYSF3.js → chunk-IJ6SS4WB.js} +1 -1
  65. package/dist/{chunk-B6ECUSVX.js → chunk-IKKETMQC.js} +8 -8
  66. package/dist/{chunk-R6U7N4FS.js → chunk-KKSVCHDO.js} +10 -3
  67. package/dist/{chunk-JMJNFEDC.js → chunk-KMBU4PJP.js} +9 -54
  68. package/dist/chunk-KQZX24QQ.js +164 -0
  69. package/dist/{chunk-GPLAT6H7.js → chunk-LCNPXLE7.js} +22 -18
  70. package/dist/{chunk-2HIPYNQI.js → chunk-LG5MYY6U.js} +33 -32
  71. package/dist/chunk-LZOQFC5F.js +209 -0
  72. package/dist/chunk-M3QYTBQ6.js +55 -0
  73. package/dist/{chunk-M63DETLL.js → chunk-N7TMSOZH.js} +6 -6
  74. package/dist/{chunk-FIDMHAO6.js → chunk-NQTA72Q3.js} +84 -274
  75. package/dist/{chunk-RZRYOLCE.js → chunk-PBKZQAUA.js} +2315 -1150
  76. package/dist/chunk-PEQXYSSE.js +45 -0
  77. package/dist/{chunk-3TM3FYLQ.js → chunk-PL57B6NC.js} +1 -1
  78. package/dist/{chunk-JT4WMD3C.js → chunk-PPYDHUEL.js} +144 -218
  79. package/dist/{chunk-5IRROPA5.js → chunk-Q2KY27IX.js} +129 -31
  80. package/dist/{chunk-VP4OVRDD.js → chunk-RNMASWLP.js} +69 -73
  81. package/dist/{chunk-FAS6AIMF.js → chunk-TDT2R77B.js} +8 -8
  82. package/dist/{chunk-TIEKUH4Q.js → chunk-TJHSAHQN.js} +4 -3
  83. package/dist/{chunk-H4HBKISO.js → chunk-TXKUKMVO.js} +1 -1
  84. package/dist/chunk-X6GDDWQH.js +60 -0
  85. package/dist/{chunk-GENV6KF2.js → chunk-XYTJUHRZ.js} +108 -76
  86. package/dist/cli/chat.js +47 -43
  87. package/dist/cli/check.js +13 -15
  88. package/dist/cli/env.js +0 -1
  89. package/dist/cli/init.js +0 -1
  90. package/dist/cli/main.js +2 -3
  91. package/dist/cli/plugins.js +18 -20
  92. package/dist/cli/run.js +0 -1
  93. package/dist/cli/snapshot-create.js +14 -16
  94. package/dist/cli/upgrade.js +16 -18
  95. package/dist/{conversation-work-KATFHLG3.js → conversation-work-VIOQ5ZF3.js} +0 -2
  96. package/dist/db/schema/snapshots.d.ts +17 -0
  97. package/dist/db/schema.d.ts +17 -0
  98. package/dist/{db-EJAV7JL6.js → db-QNPVCQPT.js} +8 -10
  99. package/dist/deployment.d.ts +1 -0
  100. package/dist/{discovery-GUFTFBTL.js → discovery-DWVDM7UK.js} +1 -2
  101. package/dist/{experimental-XVDOSRBS.js → experimental-SIJSRDJD.js} +0 -1
  102. package/dist/instrumentation.js +7 -9
  103. package/dist/nitro.js +39 -13
  104. package/dist/{oauth-callback-server-GAVSUBTQ.js → oauth-callback-server-KYMPJOTC.js} +34 -32
  105. package/dist/{oauth-relay-3ZU72UGL.js → oauth-relay-5XPVRPYB.js} +0 -1
  106. package/dist/{plugins-HW4VWW6G.js → plugins-YTYJMMJF.js} +1 -2
  107. package/dist/{runner-34JL64JF.js → runner-3RS2D2ZR.js} +39 -33
  108. package/dist/{sandbox-egress-signals-DXOOBSBI.js → sandbox-egress-signals-FIL7EGPR.js} +5 -6
  109. package/dist/{sentry-JMWTS32N.js → sentry-MB3NL3IR.js} +1 -2
  110. package/dist/skills-5B3Y6XX6.js +27 -0
  111. package/dist/spawn-VYARS3DU.js +37 -0
  112. package/dist/task-runner-4IXKKZHL.js +32 -0
  113. package/dist/validation-Q65QD27B.js +17 -0
  114. package/dist/vercel.js +0 -1
  115. package/dist/version.js +1 -2
  116. package/dist/work-DCMQWAAP.js +45 -0
  117. package/dist/worker-QL3CHLZL.js +22 -0
  118. package/migrations/0035_workspace_snapshot_size_bytes.sql +2 -0
  119. package/migrations/meta/0035_snapshot.json +3048 -0
  120. package/migrations/meta/_journal.json +7 -0
  121. package/package.json +7 -6
  122. package/dist/catalog-runtime-FBVA6WAQ.js +0 -16
  123. package/dist/chat/plugins/task-callback.d.ts +0 -5
  124. package/dist/chat/plugins/task-message.d.ts +0 -23
  125. package/dist/chat/plugins/task-signing.d.ts +0 -31
  126. package/dist/chat/sandbox/snapshot/waiting-error.d.ts +0 -15
  127. package/dist/chat/services/workspace-snapshot-wait.d.ts +0 -27
  128. package/dist/chunk-5I6ORJUY.js +0 -127
  129. package/dist/chunk-6GWA276C.js +0 -72
  130. package/dist/chunk-MLKGABMK.js +0 -9
  131. package/dist/chunk-UT6X7XN7.js +0 -51
  132. package/dist/chunk-WR76IVA5.js +0 -130
  133. package/dist/skills-U545HALM.js +0 -29
  134. package/dist/spawn-I2S4IDUQ.js +0 -37
  135. package/dist/validation-EVXVGA44.js +0 -19
  136. package/dist/work-QOAUPDBU.js +0 -45
  137. package/dist/worker-5GX2IKLZ.js +0 -24
@@ -1,12 +1,11 @@
1
1
  import {
2
- appendAndEnqueueInboundMessage
3
- } from "./chunk-5IRROPA5.js";
2
+ ConversationTurnLifecycleService
3
+ } from "./chunk-M3QYTBQ6.js";
4
4
  import {
5
- ConversationTurnLifecycleService,
6
5
  getPersistedSandboxState,
7
6
  getPersistedThreadState,
8
7
  persistThreadStateById
9
- } from "./chunk-CJLBLELR.js";
8
+ } from "./chunk-FWILPBVQ.js";
10
9
  import {
11
10
  AgentInvocationBusyError,
12
11
  AgentInvocationLimitError,
@@ -15,27 +14,32 @@ import {
15
14
  agentBindingSchema,
16
15
  agentInvocationSchema,
17
16
  createAgentInvocationSchema
18
- } from "./chunk-3AFVR5UC.js";
17
+ } from "./chunk-3X55QRAG.js";
18
+ import {
19
+ appendAndEnqueueInboundMessage
20
+ } from "./chunk-Q2KY27IX.js";
19
21
  import {
20
22
  TurnInputCommitLostError,
21
- failTurnRecord,
22
23
  getAssistantReplyText,
23
24
  getConversationTurnBoundaryError,
25
+ isTurnInputCommitLostError
26
+ } from "./chunk-HJ27A6YB.js";
27
+ import {
28
+ failTurnRecord,
24
29
  getTerminalAssistantMessages,
25
30
  getTurnRecord,
26
- isTurnInputCommitLostError,
27
31
  openConversationProjection,
28
32
  saveTurnCheckpoint
29
- } from "./chunk-FIDMHAO6.js";
33
+ } from "./chunk-NQTA72Q3.js";
30
34
  import {
31
35
  getConversationEventStore,
32
36
  getConversationStore,
33
37
  getSqlExecutor
34
- } from "./chunk-VP4OVRDD.js";
38
+ } from "./chunk-RNMASWLP.js";
35
39
  import {
36
40
  juniorAgentBindings,
37
41
  juniorAgentInvocations
38
- } from "./chunk-R6U7N4FS.js";
42
+ } from "./chunk-KKSVCHDO.js";
39
43
 
40
44
  // src/chat/agent-invocations/work.ts
41
45
  import { z } from "zod";
@@ -84,22 +88,22 @@ function bindingFromRow(row) {
84
88
  function invocationFromRow(row) {
85
89
  return agentInvocationSchema.parse({
86
90
  actor: row.actor,
87
- ...row.agentName ? { agentName: row.agentName } : {},
91
+ ...row.agentName ? { agentName: row.agentName } : void 0,
88
92
  childConversationId: row.childConversationId,
89
93
  createdAtMs: row.createdAt.getTime(),
90
- ...row.credentialContext ? { credentialContext: row.credentialContext } : {},
94
+ ...row.credentialContext ? { credentialContext: row.credentialContext } : void 0,
91
95
  destination: row.destination,
92
- ...row.destinationVisibility ? { destinationVisibility: row.destinationVisibility } : {},
93
- ...row.errorMessage !== null ? { errorMessage: row.errorMessage } : {},
96
+ ...row.destinationVisibility ? { destinationVisibility: row.destinationVisibility } : void 0,
97
+ ...row.errorMessage !== null ? { errorMessage: row.errorMessage } : void 0,
94
98
  input: row.input,
95
99
  invocationId: row.invocationId,
96
100
  mailboxStatus: row.mailboxStatus,
97
101
  parentConversationId: row.parentConversationId,
98
- ...row.reasoningLevel ? { reasoningLevel: row.reasoningLevel } : {},
99
- ...row.result !== null ? { result: row.result } : {},
102
+ ...row.reasoningLevel ? { reasoningLevel: row.reasoningLevel } : void 0,
103
+ ...row.result !== null ? { result: row.result } : void 0,
100
104
  source: row.source,
101
105
  status: row.status,
102
- ...row.terminalAt ? { terminalAtMs: row.terminalAt.getTime() } : {},
106
+ ...row.terminalAt ? { terminalAtMs: row.terminalAt.getTime() } : void 0,
103
107
  updatedAtMs: row.updatedAt.getTime()
104
108
  });
105
109
  }
@@ -619,7 +623,7 @@ function createAgentInvocationWorker(options) {
619
623
  destinationVisibility: invocation.destinationVisibility,
620
624
  ...failed ? {
621
625
  errorMessage: result.diagnostics.errorMessage ?? "Agent invocation failed"
622
- } : {},
626
+ } : void 0,
623
627
  messages: result.piMessages,
624
628
  actor: invocation.actor,
625
629
  source: invocation.source,
@@ -5,28 +5,28 @@ import {
5
5
  isDmChannel,
6
6
  normalizeSlackConversationId,
7
7
  withSlackRetries
8
- } from "./chunk-3I7XE3PA.js";
8
+ } from "./chunk-D6ZD7VXP.js";
9
9
  import {
10
10
  parseDestination
11
- } from "./chunk-VP4OVRDD.js";
11
+ } from "./chunk-RNMASWLP.js";
12
12
  import {
13
13
  getStateAdapter
14
- } from "./chunk-3TM3FYLQ.js";
14
+ } from "./chunk-PL57B6NC.js";
15
15
  import {
16
16
  normalizeSlackEmojiName
17
- } from "./chunk-GENV6KF2.js";
17
+ } from "./chunk-XYTJUHRZ.js";
18
18
  import {
19
19
  pluginCatalogRuntime
20
- } from "./chunk-YFNAMRGE.js";
20
+ } from "./chunk-HEBMSITT.js";
21
21
  import {
22
22
  parseSlackMessageTs,
23
23
  parseSlackUserId
24
- } from "./chunk-M63DETLL.js";
24
+ } from "./chunk-N7TMSOZH.js";
25
25
  import {
26
26
  isRecord,
27
27
  logInfo,
28
28
  logWarn
29
- } from "./chunk-HQNE5APD.js";
29
+ } from "./chunk-EBMRB6Z6.js";
30
30
 
31
31
  // src/chat/slack/outbound.ts
32
32
  var MAX_SLACK_MESSAGE_TEXT_CHARS = 4e4;
@@ -101,16 +101,17 @@ async function postSlackMessage(input) {
101
101
  unfurl_links: false,
102
102
  unfurl_media: false,
103
103
  ...input.blocks?.length ? {
104
+ // @ts-expect-error non-overlapping boundary cast; rule forbids as-unknown-as chains
104
105
  blocks: input.blocks
105
- } : {},
106
- ...threadTs ? { thread_ts: threadTs } : {}
106
+ } : void 0,
107
+ ...threadTs ? { thread_ts: threadTs } : void 0
107
108
  }),
108
109
  3,
109
110
  {
110
111
  action: "chat.postMessage",
111
112
  spanAttributes: {
112
113
  "app.slack.channel_id": channelId,
113
- ...threadTs ? { "app.slack.thread_ts": threadTs } : {}
114
+ ...threadTs ? { "app.slack.thread_ts": threadTs } : void 0
114
115
  }
115
116
  }
116
117
  );
@@ -125,7 +126,7 @@ async function postSlackMessage(input) {
125
126
  channelId,
126
127
  messageTs
127
128
  })
128
- } : {}
129
+ } : void 0
129
130
  };
130
131
  }
131
132
  async function postSlackEphemeralMessage(input) {
@@ -150,7 +151,7 @@ async function postSlackEphemeralMessage(input) {
150
151
  channel: channelId,
151
152
  user: userId,
152
153
  text,
153
- ...threadTs ? { thread_ts: threadTs } : {}
154
+ ...threadTs ? { thread_ts: threadTs } : void 0
154
155
  }),
155
156
  3,
156
157
  {
@@ -158,7 +159,7 @@ async function postSlackEphemeralMessage(input) {
158
159
  spanAttributes: {
159
160
  "app.slack.channel_id": channelId,
160
161
  "app.slack.user_id": userId,
161
- ...threadTs ? { "app.slack.thread_ts": threadTs } : {}
162
+ ...threadTs ? { "app.slack.thread_ts": threadTs } : void 0
162
163
  }
163
164
  }
164
165
  );
@@ -190,7 +191,7 @@ async function uploadFilesToConversation(input) {
190
191
  const response = await withSlackRetries(
191
192
  () => getSlackClient().filesUploadV2({
192
193
  channel_id: channelId,
193
- ...threadTs ? { thread_ts: threadTs } : {},
194
+ ...threadTs ? { thread_ts: threadTs } : void 0,
194
195
  file_uploads: fileUploads
195
196
  }),
196
197
  3,
@@ -198,7 +199,7 @@ async function uploadFilesToConversation(input) {
198
199
  action: "filesUploadV2",
199
200
  spanAttributes: {
200
201
  "app.slack.channel_id": channelId,
201
- ...threadTs ? { "app.slack.thread_ts": threadTs } : {}
202
+ ...threadTs ? { "app.slack.thread_ts": threadTs } : void 0
202
203
  }
203
204
  }
204
205
  );
@@ -534,14 +535,14 @@ function parseOAuthStatePayload(value) {
534
535
  return {
535
536
  userId: value.userId,
536
537
  provider: value.provider,
537
- ...actor?.success ? { actor: actor.data } : {},
538
- ...optionalString(value.channelId) ? { channelId: optionalString(value.channelId) } : {},
539
- ...destination ? { destination } : {},
540
- ...source?.success ? { source: source.data } : {},
541
- ...optionalString(value.threadTs) ? { threadTs: optionalString(value.threadTs) } : {},
542
- ...optionalString(value.resumeConversationId) ? { resumeConversationId: optionalString(value.resumeConversationId) } : {},
543
- ...optionalString(value.resumeSessionId) ? { resumeSessionId: optionalString(value.resumeSessionId) } : {},
544
- ...optionalString(value.scope) ? { scope: optionalString(value.scope) } : {}
538
+ ...actor?.success ? { actor: actor.data } : void 0,
539
+ ...optionalString(value.channelId) ? { channelId: optionalString(value.channelId) } : void 0,
540
+ ...destination ? { destination } : void 0,
541
+ ...source?.success ? { source: source.data } : void 0,
542
+ ...optionalString(value.threadTs) ? { threadTs: optionalString(value.threadTs) } : void 0,
543
+ ...optionalString(value.resumeConversationId) ? { resumeConversationId: optionalString(value.resumeConversationId) } : void 0,
544
+ ...optionalString(value.resumeSessionId) ? { resumeSessionId: optionalString(value.resumeSessionId) } : void 0,
545
+ ...optionalString(value.scope) ? { scope: optionalString(value.scope) } : void 0
545
546
  };
546
547
  }
547
548
  function formatProviderLabel(provider) {
@@ -657,14 +658,14 @@ async function startOAuthFlow(provider, input) {
657
658
  {
658
659
  userId: input.actorId,
659
660
  provider,
660
- ...input.actor ? { actor: input.actor } : {},
661
- ...input.channelId ? { channelId: input.channelId } : {},
662
- ...input.destination ? { destination: input.destination } : {},
663
- ...input.source ? { source: input.source } : {},
664
- ...input.threadTs ? { threadTs: input.threadTs } : {},
665
- ...input.resumeConversationId ? { resumeConversationId: input.resumeConversationId } : {},
666
- ...input.resumeSessionId ? { resumeSessionId: input.resumeSessionId } : {},
667
- ...requestedScope ? { scope: requestedScope } : {}
661
+ ...input.actor ? { actor: input.actor } : void 0,
662
+ ...input.channelId ? { channelId: input.channelId } : void 0,
663
+ ...input.destination ? { destination: input.destination } : void 0,
664
+ ...input.source ? { source: input.source } : void 0,
665
+ ...input.threadTs ? { threadTs: input.threadTs } : void 0,
666
+ ...input.resumeConversationId ? { resumeConversationId: input.resumeConversationId } : void 0,
667
+ ...input.resumeSessionId ? { resumeSessionId: input.resumeSessionId } : void 0,
668
+ ...requestedScope ? { scope: requestedScope } : void 0
668
669
  },
669
670
  OAUTH_STATE_TTL_MS
670
671
  );
@@ -684,7 +685,7 @@ async function startOAuthFlow(provider, input) {
684
685
  }
685
686
  logInfo("jr_rpc.oauth.started", {
686
687
  "app.credential.provider": provider,
687
- ...input.activeSkillName ? { "app.skill.name": input.activeSkillName } : {}
688
+ ...input.activeSkillName ? { "app.skill.name": input.activeSkillName } : void 0
688
689
  });
689
690
  const authorizationUrl = `${providerConfig.authorizeEndpoint}?${authorizeParams.toString()}`;
690
691
  const authorizationRequest = {
@@ -0,0 +1,209 @@
1
+ import {
2
+ coerceThreadConversationState,
3
+ getPersistedThreadState,
4
+ persistThreadStateById
5
+ } from "./chunk-FWILPBVQ.js";
6
+ import {
7
+ buildDeterministicTurnId,
8
+ clearPendingAuth,
9
+ markTurnClosed,
10
+ markTurnCompleted
11
+ } from "./chunk-HJ27A6YB.js";
12
+ import {
13
+ hydrateConversationMessages,
14
+ markConversationMessage
15
+ } from "./chunk-NQTA72Q3.js";
16
+ import {
17
+ ProviderError,
18
+ findProviderError,
19
+ getProviderErrorAttributes,
20
+ getProviderErrorUserMessage
21
+ } from "./chunk-XYTJUHRZ.js";
22
+ import {
23
+ parseSlackMessageTs
24
+ } from "./chunk-N7TMSOZH.js";
25
+ import {
26
+ buildTurnFailureResponse
27
+ } from "./chunk-EBMRB6Z6.js";
28
+
29
+ // src/chat/runtime/delivered-turn-state.ts
30
+ function buildDeliveredTurnStatePatch(args) {
31
+ const conversation = structuredClone(args.conversation);
32
+ clearPendingAuth(conversation, args.sessionId);
33
+ markConversationMessage(conversation, args.userMessageId, {
34
+ replied: true,
35
+ skippedReason: void 0
36
+ });
37
+ markTurnCompleted({
38
+ conversation,
39
+ nowMs: Date.now(),
40
+ sessionId: args.sessionId
41
+ });
42
+ return {
43
+ conversation,
44
+ sandboxRef: args.reply.sandboxRef
45
+ };
46
+ }
47
+
48
+ // src/chat/interruption-marker.ts
49
+ var INTERRUPTED_MARKER = "\n\n[Response interrupted before completion]";
50
+ function getInterruptionMarker() {
51
+ return INTERRUPTED_MARKER;
52
+ }
53
+
54
+ // src/chat/services/turn-failure-response.ts
55
+ function requireTurnFailureEventId(eventId, eventName) {
56
+ if (!eventId) {
57
+ throw new Error(`Sentry did not return an event ID for ${eventName}`);
58
+ }
59
+ return eventId;
60
+ }
61
+ function getExecutionFailureReason(reply) {
62
+ const errorMessage = reply.diagnostics.errorMessage?.trim();
63
+ if (errorMessage) {
64
+ return errorMessage;
65
+ }
66
+ if (reply.diagnostics.toolErrorCount > 0) {
67
+ return `${reply.diagnostics.toolErrorCount} tool result error(s)`;
68
+ }
69
+ if (reply.diagnostics.assistantMessageCount > 0) {
70
+ return "assistant returned no text";
71
+ }
72
+ return "empty assistant turn";
73
+ }
74
+ function getFailureCapture(reply) {
75
+ if (reply.diagnostics.outcome === "provider_error") {
76
+ const providerError = findProviderError(reply.diagnostics.providerError);
77
+ return {
78
+ eventName: "agent.turn.provider_error",
79
+ error: reply.diagnostics.providerError ?? new Error(
80
+ reply.diagnostics.errorMessage ?? "Provider error without explicit message"
81
+ ),
82
+ attributes: providerError ? getProviderErrorAttributes(providerError) : {},
83
+ body: "Agent turn failed with provider error"
84
+ };
85
+ }
86
+ const failureReason = getExecutionFailureReason(reply);
87
+ return {
88
+ eventName: "agent.turn.execution.failed",
89
+ error: new Error(`Agent turn execution failure: ${failureReason}`),
90
+ attributes: {
91
+ "app.ai.execution_failure_reason": failureReason
92
+ },
93
+ body: "Agent turn completed with execution failure"
94
+ };
95
+ }
96
+ function getAgentTurnDiagnosticsAttributes(reply) {
97
+ return {
98
+ "app.ai.outcome": reply.diagnostics.outcome,
99
+ "app.ai.assistant_messages": reply.diagnostics.assistantMessageCount,
100
+ "app.ai.tool_results": reply.diagnostics.toolResultCount,
101
+ "app.ai.tool_error_results": reply.diagnostics.toolErrorCount,
102
+ "app.ai.tool_call_count": reply.diagnostics.toolCalls.length,
103
+ "app.ai.used_primary_text": reply.diagnostics.usedPrimaryText,
104
+ ...reply.diagnostics.reasoningLevel ? {
105
+ "gen_ai.request.reasoning.level": reply.diagnostics.reasoningLevel
106
+ } : void 0,
107
+ ...reply.diagnostics.stopReason ? {
108
+ "gen_ai.response.finish_reasons": [reply.diagnostics.stopReason]
109
+ } : void 0,
110
+ ...reply.diagnostics.errorMessage && reply.diagnostics.outcome !== "provider_error" ? { "exception.message": reply.diagnostics.errorMessage } : void 0
111
+ };
112
+ }
113
+ function finalizeFailedTurnReplyWithEvent(args) {
114
+ if (args.reply.diagnostics.outcome === "success") {
115
+ return { reply: args.reply };
116
+ }
117
+ const capture = getFailureCapture(args.reply);
118
+ const eventId = requireTurnFailureEventId(
119
+ args.logException(capture.error, capture.eventName, {
120
+ ...getAgentTurnDiagnosticsAttributes(args.reply),
121
+ ...args.attributes,
122
+ ...capture.attributes
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);
129
+ return {
130
+ eventId,
131
+ reply: {
132
+ ...args.reply,
133
+ text: providerPartialText ? `${providerPartialText}${getInterruptionMarker()}` : failureText
134
+ }
135
+ };
136
+ }
137
+
138
+ // src/chat/runtime/turn-user-message.ts
139
+ function getTurnUserMessage(conversation, sessionId) {
140
+ for (let index = conversation.messages.length - 1; index >= 0; index -= 1) {
141
+ const message = conversation.messages[index];
142
+ if (message?.role !== "user") {
143
+ continue;
144
+ }
145
+ if (buildDeterministicTurnId(message.id) === sessionId) {
146
+ return message;
147
+ }
148
+ }
149
+ return void 0;
150
+ }
151
+ function getTurnUserMessageId(conversation, sessionId) {
152
+ return getTurnUserMessage(conversation, sessionId)?.id;
153
+ }
154
+ function getTurnUserSlackMessageTs(message) {
155
+ return parseSlackMessageTs(message?.meta?.slackTs);
156
+ }
157
+ function getTurnUserReplyAttachmentContext(message) {
158
+ const inboundAttachmentCount = message?.meta?.attachmentCount ?? 0;
159
+ const imageAttachmentCount = message?.meta?.imageAttachmentCount ?? 0;
160
+ const imagesHydrated = message?.meta?.imagesHydrated === true;
161
+ return {
162
+ ...inboundAttachmentCount > 0 ? { inboundAttachmentCount } : void 0,
163
+ ...!imagesHydrated && imageAttachmentCount > 0 ? { omittedImageAttachmentCount: imageAttachmentCount } : void 0
164
+ };
165
+ }
166
+
167
+ // src/chat/runtime/auth-pause-state.ts
168
+ function completeAuthPauseTurn(args) {
169
+ markConversationMessage(
170
+ args.conversation,
171
+ getTurnUserMessageId(args.conversation, args.sessionId),
172
+ {
173
+ replied: true,
174
+ skippedReason: void 0
175
+ }
176
+ );
177
+ markTurnClosed({
178
+ conversation: args.conversation,
179
+ nowMs: Date.now(),
180
+ sessionId: args.sessionId
181
+ });
182
+ }
183
+ async function persistAuthPauseTurnState(args) {
184
+ const currentState = await getPersistedThreadState(args.threadStateId);
185
+ const conversation = coerceThreadConversationState(currentState);
186
+ await hydrateConversationMessages({
187
+ conversation,
188
+ conversationId: args.threadStateId
189
+ });
190
+ completeAuthPauseTurn({
191
+ conversation,
192
+ sessionId: args.sessionId
193
+ });
194
+ await persistThreadStateById(args.threadStateId, { conversation });
195
+ }
196
+
197
+ export {
198
+ buildDeliveredTurnStatePatch,
199
+ getTurnUserMessage,
200
+ getTurnUserMessageId,
201
+ getTurnUserSlackMessageTs,
202
+ getTurnUserReplyAttachmentContext,
203
+ getInterruptionMarker,
204
+ requireTurnFailureEventId,
205
+ getAgentTurnDiagnosticsAttributes,
206
+ finalizeFailedTurnReplyWithEvent,
207
+ completeAuthPauseTurn,
208
+ persistAuthPauseTurnState
209
+ };
@@ -0,0 +1,55 @@
1
+ // src/chat/conversations/turn-lifecycle.ts
2
+ var ConversationTurnLifecycleService = class {
3
+ constructor(events) {
4
+ this.events = events;
5
+ }
6
+ events;
7
+ /** Record the turn start once after every input message is durable. */
8
+ async start(input) {
9
+ await this.events.append(input.conversationId, [
10
+ {
11
+ idempotencyKey: `turn:${input.turnId}:started`,
12
+ createdAtMs: input.createdAtMs,
13
+ data: {
14
+ type: "turn_started",
15
+ turnId: input.turnId,
16
+ inputMessageIds: input.inputMessageIds,
17
+ surface: input.surface
18
+ }
19
+ }
20
+ ]);
21
+ }
22
+ /** Record successful or intentional-silence completion once. */
23
+ async complete(input) {
24
+ await this.events.append(input.conversationId, [
25
+ {
26
+ idempotencyKey: `turn:${input.turnId}:terminal`,
27
+ createdAtMs: input.createdAtMs,
28
+ data: {
29
+ type: "turn_completed",
30
+ turnId: input.turnId,
31
+ outcome: input.outcome
32
+ }
33
+ }
34
+ ]);
35
+ }
36
+ /** Record a classified failure once without accepting raw error details. */
37
+ async fail(input) {
38
+ await this.events.append(input.conversationId, [
39
+ {
40
+ idempotencyKey: `turn:${input.turnId}:terminal`,
41
+ createdAtMs: input.createdAtMs,
42
+ data: {
43
+ type: "turn_failed",
44
+ turnId: input.turnId,
45
+ failureCode: input.failureCode,
46
+ ...input.eventId ? { eventId: input.eventId } : void 0
47
+ }
48
+ }
49
+ ]);
50
+ }
51
+ };
52
+
53
+ export {
54
+ ConversationTurnLifecycleService
55
+ };
@@ -138,15 +138,15 @@ function createActor(input, context) {
138
138
  }
139
139
  const canUseInputProfile = (!contextUserId || !inputUserId || contextUserId === inputUserId) && (platform !== "slack" || !contextTeamId || !inputTeamId || contextTeamId === inputTeamId);
140
140
  const actor = {
141
- ...canUseInputProfile && cleanActorEmail(input?.email) ? { email: cleanActorEmail(input?.email) } : {},
141
+ ...canUseInputProfile && cleanActorEmail(input?.email) ? { email: cleanActorEmail(input?.email) } : void 0,
142
142
  ...canUseInputProfile && cleanActorDisplayName(input?.fullName, actorUserId) ? {
143
143
  fullName: cleanActorDisplayName(input?.fullName, actorUserId)
144
- } : {},
144
+ } : void 0,
145
145
  platform,
146
146
  userId: actorUserId,
147
147
  ...canUseInputProfile && cleanActorDisplayName(input?.userName, actorUserId) ? {
148
148
  userName: cleanActorDisplayName(input?.userName, actorUserId)
149
- } : {}
149
+ } : void 0
150
150
  };
151
151
  if (platform === "slack") {
152
152
  return { ...actor, platform, teamId: actorTeamId };
@@ -193,11 +193,11 @@ function parseStoredSlackActor(value) {
193
193
  }
194
194
  function toStoredSlackActor(actor) {
195
195
  return {
196
- ...actor.email ? { email: actor.email } : {},
197
- ...actor.fullName ? { fullName: actor.fullName } : {},
196
+ ...actor.email ? { email: actor.email } : void 0,
197
+ ...actor.fullName ? { fullName: actor.fullName } : void 0,
198
198
  platform: actor.platform,
199
199
  slackUserId: actor.userId,
200
- ...actor.userName ? { slackUserName: actor.userName } : {},
200
+ ...actor.userName ? { slackUserName: actor.userName } : void 0,
201
201
  teamId: actor.teamId
202
202
  };
203
203
  }