@sentry/junior 0.183.0 → 0.185.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 (122) hide show
  1. package/dist/{agent-hooks-SNRBZYAU.js → agent-hooks-NGZQLL5O.js} +13 -11
  2. package/dist/api/acp/auth.d.ts +46 -0
  3. package/dist/api/acp/authorization-page.d.ts +11 -0
  4. package/dist/api/acp/conversations.d.ts +70 -0
  5. package/dist/api/acp/errors.d.ts +6 -0
  6. package/dist/api/acp/route.d.ts +16 -0
  7. package/dist/api/acp/schema.d.ts +115 -0
  8. package/dist/api/acp/sleep.d.ts +2 -0
  9. package/dist/api/acp/state.d.ts +22 -0
  10. package/dist/api/acp/transport.d.ts +113 -0
  11. package/dist/api/code/overview.d.ts +39 -0
  12. package/dist/api/locations/detail.d.ts +1 -1
  13. package/dist/api/people/code.d.ts +22 -0
  14. package/dist/api/schema/code.d.ts +46 -0
  15. package/dist/api/schema/conversation.d.ts +100 -20
  16. package/dist/api/schema/location.d.ts +1 -1
  17. package/dist/api/schema/person.d.ts +1 -1
  18. package/dist/api/schema.d.ts +4 -4
  19. package/dist/api/schema.js +12 -1
  20. package/dist/api.js +358 -76
  21. package/dist/app.d.ts +0 -4
  22. package/dist/app.js +2450 -493
  23. package/dist/{catalog-runtime-3I3JOIIH.js → catalog-runtime-AAEAO2RL.js} +4 -4
  24. package/dist/chat/api-turns/accepted-reply.d.ts +11 -0
  25. package/dist/chat/api-turns/cancellation.d.ts +3 -5
  26. package/dist/chat/api-turns/work.d.ts +4 -9
  27. package/dist/chat/app/conversation-work.d.ts +1 -1
  28. package/dist/chat/app/factory.d.ts +4 -0
  29. package/dist/chat/app/services.d.ts +4 -3
  30. package/dist/chat/conversations/history.d.ts +83 -9
  31. package/dist/chat/conversations/turn-lifecycle.d.ts +4 -3
  32. package/dist/chat/providers/slack/input.d.ts +32 -0
  33. package/dist/chat/{runtime → providers/slack}/processing-reaction.d.ts +6 -8
  34. package/dist/chat/{runtime/slack-resume.d.ts → providers/slack/resume.d.ts} +16 -19
  35. package/dist/chat/providers/slack/runtime.d.ts +1 -10
  36. package/dist/chat/providers/slack/turn.d.ts +11 -24
  37. package/dist/chat/resource-events/store.d.ts +1 -1
  38. package/dist/chat/resource-events/tool-support.d.ts +0 -5
  39. package/dist/chat/runtime/turn-execution.d.ts +7 -2
  40. package/dist/chat/sandbox/egress/credentials.d.ts +3 -3
  41. package/dist/chat/sandbox/egress/session.d.ts +5 -6
  42. package/dist/chat/scheduled-tasks/tool-support.d.ts +5 -5
  43. package/dist/chat/scheduled-tasks/tools/create.d.ts +2 -2
  44. package/dist/chat/scheduled-tasks/tools/delete.d.ts +2 -2
  45. package/dist/chat/scheduled-tasks/tools/list.d.ts +2 -2
  46. package/dist/chat/scheduled-tasks/tools/run-now.d.ts +2 -2
  47. package/dist/chat/scheduled-tasks/tools/update.d.ts +2 -2
  48. package/dist/chat/scheduled-tasks/types.d.ts +1 -1
  49. package/dist/chat/services/provider-retry.d.ts +2 -0
  50. package/dist/chat/services/turn-failure-response.d.ts +4 -0
  51. package/dist/chat/task-execution/paused-turn.d.ts +0 -2
  52. package/dist/chat/task-execution/state.d.ts +2 -2
  53. package/dist/chat/task-execution/store.d.ts +1 -1
  54. package/dist/chat/task-execution/turn-wake.d.ts +12 -0
  55. package/dist/chat/tool-support/action-review.d.ts +1 -1
  56. package/dist/chat/tools/resource-events.d.ts +1 -1
  57. package/dist/chat/tools/search-conversation-events.d.ts +1 -1
  58. package/dist/chat/tools/types.d.ts +1 -1
  59. package/dist/chat/tools/watch-resource-events.d.ts +2 -2
  60. package/dist/{chunk-2EPYYVJC.js → chunk-4HA36IWS.js} +9 -94
  61. package/dist/{chunk-WVIA7V3M.js → chunk-4K25ODAO.js} +27 -1
  62. package/dist/{chunk-V64JCZUV.js → chunk-4S47VHJR.js} +3 -3
  63. package/dist/{chunk-QZV76CM4.js → chunk-6DOAUXLD.js} +231 -198
  64. package/dist/{chunk-M3QYTBQ6.js → chunk-6Q7YZLCL.js} +2 -1
  65. package/dist/{chunk-W46NIB5H.js → chunk-7GAP2XG4.js} +2 -3
  66. package/dist/{chunk-EENQGEIP.js → chunk-7MHNIGHP.js} +1 -1
  67. package/dist/{chunk-AX3UDIMA.js → chunk-ABAX75GG.js} +10 -384
  68. package/dist/{chunk-KTXOGLNE.js → chunk-ATUWN6Z3.js} +2 -2
  69. package/dist/{chunk-3HJ4F4L7.js → chunk-C6TS47CQ.js} +4 -4
  70. package/dist/chunk-D4YV5TDV.js +45 -0
  71. package/dist/{chunk-HUK5XIZL.js → chunk-D63IUQQE.js} +4 -4
  72. package/dist/{chunk-WOKJRLM2.js → chunk-DAPC2HTM.js} +24 -6
  73. package/dist/{chunk-2ADFGSUS.js → chunk-EIJCPJOY.js} +1 -1
  74. package/dist/{chunk-X52ESOBP.js → chunk-EJYP3NQ4.js} +4 -4
  75. package/dist/{chunk-35PM4YY5.js → chunk-EWEH2PJW.js} +6 -6
  76. package/dist/{chunk-W5JMPEBO.js → chunk-FFHXG2FX.js} +13 -11
  77. package/dist/{chunk-FJMTMGBC.js → chunk-FTVMXDNN.js} +1 -1
  78. package/dist/chunk-GFBR4S3Q.js +406 -0
  79. package/dist/{chunk-E3OBGRHN.js → chunk-GJTIZQGJ.js} +1 -1
  80. package/dist/{chunk-IO6KFXYE.js → chunk-HJPC32TQ.js} +12 -50
  81. package/dist/{chunk-RF6J3DIO.js → chunk-INQHUE72.js} +84 -1
  82. package/dist/{chunk-LMNMMESF.js → chunk-LRI5IRGY.js} +19 -44
  83. package/dist/{chunk-6UXDTPEN.js → chunk-LVK4WJKM.js} +1 -1
  84. package/dist/{chunk-AYW7J6K4.js → chunk-MWOH6CIK.js} +178 -148
  85. package/dist/{chunk-LZBPGX5A.js → chunk-OMQ2J6F6.js} +1 -1
  86. package/dist/{chunk-G2B2XZQW.js → chunk-PNYJOEVV.js} +1 -1
  87. package/dist/{chunk-37IQ6DGU.js → chunk-QCT4226Q.js} +3 -3
  88. package/dist/{chunk-R767Y7QV.js → chunk-QZKHHG3B.js} +34 -8
  89. package/dist/{chunk-VOV3SCM3.js → chunk-TVVAMOLS.js} +2 -2
  90. package/dist/{chunk-56XONJPF.js → chunk-U4CTAVWN.js} +1 -1
  91. package/dist/{chunk-4WGFWHWP.js → chunk-UUULGCKK.js} +1 -1
  92. package/dist/{chunk-AHMWPFIW.js → chunk-VH4IU3UC.js} +928 -984
  93. package/dist/chunk-W7GCLNIV.js +58 -0
  94. package/dist/{chunk-24OJZ5OU.js → chunk-WLKWN4CD.js} +22 -12
  95. package/dist/{chunk-T5MTGX2E.js → chunk-X2SS6BF7.js} +201 -210
  96. package/dist/{chunk-SQHFVIMZ.js → chunk-X7NCJQAA.js} +1 -1
  97. package/dist/{chunk-PLZT45VC.js → chunk-Y5G23T2D.js} +5 -5
  98. package/dist/{chunk-3L7CWDQQ.js → chunk-ZIF2S464.js} +1 -1
  99. package/dist/{chunk-QI5JW5AG.js → chunk-ZKKGFUWM.js} +6 -6
  100. package/dist/cli/chat.js +35 -33
  101. package/dist/cli/check.js +5 -5
  102. package/dist/cli/plugins.js +14 -12
  103. package/dist/cli/snapshot-create.js +10 -9
  104. package/dist/cli/upgrade.js +7 -6
  105. package/dist/{db-K2VMNLHQ.js → db-TRJ77FAU.js} +8 -6
  106. package/dist/instrumentation.js +3 -3
  107. package/dist/nitro.js +7 -6
  108. package/dist/{oauth-callback-server-DZZMTKSS.js → oauth-callback-server-XD5SV3MS.js} +30 -27
  109. package/dist/{runner-IIAKWDXI.js → runner-KFX7NG6D.js} +24 -19
  110. package/dist/{skills-EXIQ7BP5.js → skills-J2AH26CW.js} +5 -5
  111. package/dist/spawn-VU3CSRI6.js +41 -0
  112. package/dist/task-runner-5JG3VIIY.js +34 -0
  113. package/dist/{validation-XUGIWBJF.js → validation-O5J4VOPF.js} +5 -5
  114. package/dist/version.js +1 -1
  115. package/dist/{work-G4RLJ634.js → work-ECPQTG3U.js} +24 -19
  116. package/dist/worker-RS3DXUDO.js +24 -0
  117. package/package.json +5 -6
  118. package/dist/app-adapter.d.ts +0 -85
  119. package/dist/chat/api-turns/adapter-conversations.d.ts +0 -15
  120. package/dist/spawn-ZR6OOEAN.js +0 -37
  121. package/dist/task-runner-C52HYCVD.js +0 -32
  122. package/dist/worker-R2JEHK67.js +0 -22
@@ -1,13 +1,13 @@
1
1
  import {
2
2
  toOptionalTrimmed
3
- } from "./chunk-LMNMMESF.js";
3
+ } from "./chunk-LRI5IRGY.js";
4
4
  import {
5
5
  pluginCatalogRuntime
6
- } from "./chunk-E3OBGRHN.js";
6
+ } from "./chunk-GJTIZQGJ.js";
7
7
  import {
8
8
  setSpanAttributes,
9
9
  setSpanStatus
10
- } from "./chunk-LZBPGX5A.js";
10
+ } from "./chunk-OMQ2J6F6.js";
11
11
 
12
12
  // src/chat/sandbox/paths.ts
13
13
  function normalizeWorkspaceRoot(input) {
@@ -591,7 +591,7 @@ function isAbortError(error) {
591
591
  if (!(candidate instanceof Error)) return false;
592
592
  if (candidate.name === "AbortError") return true;
593
593
  const message = candidate.message.toLowerCase();
594
- return message === "api turn cancelled" || message === "api turn canceled" || message.startsWith("executeagentrun timed out after");
594
+ return message.startsWith("executeagentrun timed out after");
595
595
  });
596
596
  }
597
597
  function isSandboxApiTransientError(error) {
@@ -7,23 +7,23 @@ import {
7
7
  import {
8
8
  formatProviderLabel,
9
9
  startOAuthFlow
10
- } from "./chunk-QI5JW5AG.js";
10
+ } from "./chunk-ZKKGFUWM.js";
11
11
  import {
12
12
  abandonReplacedPendingAuth,
13
13
  canReusePendingAuthLink
14
- } from "./chunk-56XONJPF.js";
14
+ } from "./chunk-U4CTAVWN.js";
15
15
  import {
16
16
  recordAuthorizationRequested
17
- } from "./chunk-24OJZ5OU.js";
17
+ } from "./chunk-WLKWN4CD.js";
18
18
  import {
19
19
  AGENT_INVOCATION_MAILBOX_STATUSES
20
- } from "./chunk-6UXDTPEN.js";
20
+ } from "./chunk-LVK4WJKM.js";
21
21
  import {
22
22
  TURN_REASONING_LEVELS
23
- } from "./chunk-LMNMMESF.js";
23
+ } from "./chunk-D4YV5TDV.js";
24
24
  import {
25
25
  pluginCatalogRuntime
26
- } from "./chunk-E3OBGRHN.js";
26
+ } from "./chunk-GJTIZQGJ.js";
27
27
  import {
28
28
  credentialContextSchema
29
29
  } from "./chunk-CEMMLV5L.js";
@@ -1,12 +1,12 @@
1
1
  import {
2
2
  coerceThreadConversationState,
3
3
  getPersistedThreadState
4
- } from "./chunk-PLZT45VC.js";
4
+ } from "./chunk-Y5G23T2D.js";
5
5
  import {
6
6
  pluginTaskId,
7
7
  pluginTaskParamsSchema,
8
8
  sendVercelPluginTask
9
- } from "./chunk-V64JCZUV.js";
9
+ } from "./chunk-4S47VHJR.js";
10
10
  import {
11
11
  getPiMessageRole,
12
12
  getTurnRecord,
@@ -16,7 +16,7 @@ import {
16
16
  isToolResultMessage,
17
17
  normalizeToolNameFromResult,
18
18
  stripRuntimeTurnContext
19
- } from "./chunk-24OJZ5OU.js";
19
+ } from "./chunk-WLKWN4CD.js";
20
20
  import {
21
21
  createPluginConversationEvents,
22
22
  createPluginEmbedder,
@@ -25,22 +25,24 @@ import {
25
25
  createPluginState,
26
26
  getPlugins,
27
27
  readActorIdentity
28
- } from "./chunk-AHMWPFIW.js";
28
+ } from "./chunk-VH4IU3UC.js";
29
29
  import {
30
30
  JUNIOR_THREAD_STATE_TTL_MS
31
31
  } from "./chunk-3Y47VMHV.js";
32
32
  import {
33
33
  getConversationStore,
34
- getDb,
35
- sameActorIdentity
36
- } from "./chunk-AX3UDIMA.js";
34
+ getDb
35
+ } from "./chunk-ABAX75GG.js";
37
36
  import {
38
37
  juniorConversations,
39
38
  juniorTaskExecutions
40
- } from "./chunk-6UXDTPEN.js";
39
+ } from "./chunk-LVK4WJKM.js";
41
40
  import {
42
41
  getStateAdapter
43
- } from "./chunk-G2B2XZQW.js";
42
+ } from "./chunk-PNYJOEVV.js";
43
+ import {
44
+ sameActorIdentity
45
+ } from "./chunk-GFBR4S3Q.js";
44
46
  import {
45
47
  credentialSubjectSchema
46
48
  } from "./chunk-CEMMLV5L.js";
@@ -49,14 +51,14 @@ import {
49
51
  } from "./chunk-N7TMSOZH.js";
50
52
  import {
51
53
  logWarn
52
- } from "./chunk-LZBPGX5A.js";
54
+ } from "./chunk-OMQ2J6F6.js";
53
55
 
54
56
  // src/chat/plugins/task-runner.ts
55
57
  import { pluginRunContextSchema } from "@sentry/junior-plugin-api";
56
58
 
57
59
  // src/chat/services/turn-session-routing.ts
58
60
  async function resolveTurnSessionRouting(args) {
59
- const conversationStore = args.conversationStore ?? (await import("./db-K2VMNLHQ.js")).getConversationStore();
61
+ const conversationStore = args.conversationStore ?? (await import("./db-TRJ77FAU.js")).getConversationStore();
60
62
  const conversation = await conversationStore.get({
61
63
  conversationId: args.conversationId
62
64
  });
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  FUNCTION_TIMEOUT_BUFFER_SECONDS,
3
3
  getChatConfig
4
- } from "./chunk-LMNMMESF.js";
4
+ } from "./chunk-LRI5IRGY.js";
5
5
 
6
6
  // src/chat/runtime/request-deadline.ts
7
7
  import { AsyncLocalStorage } from "async_hooks";
@@ -0,0 +1,406 @@
1
+ import {
2
+ TURN_REASONING_LEVELS,
3
+ modelProfileSchema
4
+ } from "./chunk-D4YV5TDV.js";
5
+
6
+ // src/chat/conversations/provenance.ts
7
+ import { actorSchema } from "@sentry/junior-plugin-api";
8
+ import { z } from "zod";
9
+ var conversationMessageAuthoritySchema = z.union([
10
+ z.literal("instruction"),
11
+ z.literal("context")
12
+ ]);
13
+ var conversationMessageProvenanceSchema = z.object({
14
+ authority: conversationMessageAuthoritySchema,
15
+ actor: actorSchema.optional()
16
+ }).strict();
17
+ function instructionProvenanceFor(actor) {
18
+ return actor ? { authority: "instruction", actor } : { authority: "instruction" };
19
+ }
20
+ var contextProvenance = {
21
+ authority: "context"
22
+ };
23
+ function actorIdentityKey(actor) {
24
+ if (actor.platform === "system") {
25
+ return `system ${actor.name}`;
26
+ }
27
+ return actor.platform === "slack" ? `slack\0${actor.teamId}\0${actor.userId}` : `${actor.platform}\0${actor.userId}`;
28
+ }
29
+ function sameActorIdentity(left, right) {
30
+ return Boolean(
31
+ left && right && actorIdentityKey(left) === actorIdentityKey(right)
32
+ );
33
+ }
34
+ function instructionActors(provenance) {
35
+ const seen = /* @__PURE__ */ new Set();
36
+ const actors = [];
37
+ for (const entry of provenance) {
38
+ if (entry.authority !== "instruction" || !entry.actor) {
39
+ continue;
40
+ }
41
+ const identity = actorIdentityKey(entry.actor);
42
+ if (seen.has(identity)) {
43
+ continue;
44
+ }
45
+ seen.add(identity);
46
+ actors.push(entry.actor);
47
+ }
48
+ return actors;
49
+ }
50
+
51
+ // src/chat/conversations/history.ts
52
+ import { z as z2 } from "zod";
53
+ var userMessageEventDataSchema = z2.object({
54
+ type: z2.literal("user_message"),
55
+ role: z2.never().optional(),
56
+ provenance: conversationMessageProvenanceSchema
57
+ }).passthrough();
58
+ var assistantMessageEventDataSchema = z2.object({
59
+ type: z2.literal("assistant_message"),
60
+ role: z2.never().optional()
61
+ }).passthrough();
62
+ var toolResultEventDataSchema = z2.object({
63
+ type: z2.literal("tool_result"),
64
+ role: z2.never().optional()
65
+ }).passthrough();
66
+ var agentHistoryItemSchema = z2.discriminatedUnion("type", [
67
+ userMessageEventDataSchema,
68
+ assistantMessageEventDataSchema,
69
+ toolResultEventDataSchema
70
+ ]);
71
+ var nativeReplacementHistoryItemSchema = z2.object({
72
+ item: agentHistoryItemSchema,
73
+ // Preserve the copied item's position when a turn resumes. Synthetic
74
+ // summary and handoff items have no source event.
75
+ sourceEventSeq: z2.number().int().nonnegative().optional()
76
+ }).strict();
77
+ var replacementHistorySchema = z2.array(nativeReplacementHistoryItemSchema);
78
+ var compactionDetailsSchema = z2.object({
79
+ reason: z2.literal("capacity"),
80
+ estimatedInputTokens: z2.number().int().nonnegative(),
81
+ replacementInputTokens: z2.number().int().nonnegative().optional(),
82
+ triggerTokens: z2.number().int().nonnegative(),
83
+ inputLimitTokens: z2.number().int().positive(),
84
+ inputMessageCount: z2.number().int().nonnegative(),
85
+ retainedMessageCount: z2.number().int().nonnegative(),
86
+ summaryChars: z2.number().int().nonnegative()
87
+ }).strict();
88
+ var historyReplacementEventDataSchema = z2.discriminatedUnion("type", [
89
+ z2.object({
90
+ type: z2.literal("handoff"),
91
+ modelProfile: modelProfileSchema,
92
+ modelId: z2.string().min(1),
93
+ reasoningLevel: z2.string().min(1).optional(),
94
+ triggeringToolCallId: z2.string().min(1).optional(),
95
+ summary: z2.string().min(1).optional(),
96
+ replacementHistory: replacementHistorySchema
97
+ }).strict(),
98
+ z2.object({
99
+ type: z2.literal("compaction"),
100
+ modelProfile: modelProfileSchema,
101
+ modelId: z2.string().min(1),
102
+ details: compactionDetailsSchema.optional(),
103
+ summary: z2.string().min(1).optional(),
104
+ replacementHistory: replacementHistorySchema
105
+ }).strict()
106
+ ]);
107
+ var historyReplacementSchema = z2.object({
108
+ data: historyReplacementEventDataSchema,
109
+ createdAtMs: z2.number().finite()
110
+ }).strict();
111
+ var mcpProviderConnectedEventDataSchema = z2.object({
112
+ type: z2.literal("mcp_provider_connected"),
113
+ provider: z2.string().min(1),
114
+ credentialSubjectId: z2.string().min(1)
115
+ }).strict();
116
+ var unownedMcpProviderConnectedEventDataSchema = z2.object({
117
+ type: z2.literal("mcp_provider_connected_unowned"),
118
+ provider: z2.string().min(1)
119
+ }).strict();
120
+ var authorizationKindSchema = z2.union([
121
+ z2.literal("plugin"),
122
+ z2.literal("mcp")
123
+ ]);
124
+ var authorizationRequestedEventDataSchema = z2.object({
125
+ type: z2.literal("authorization_requested"),
126
+ kind: authorizationKindSchema,
127
+ provider: z2.string().min(1),
128
+ actorId: z2.string().min(1),
129
+ authorizationId: z2.string().min(1),
130
+ delivery: z2.union([
131
+ z2.literal("private_link_sent"),
132
+ z2.literal("private_link_reused")
133
+ ])
134
+ }).strict();
135
+ var authorizationCompletedEventDataSchema = z2.object({
136
+ type: z2.literal("authorization_completed"),
137
+ kind: authorizationKindSchema,
138
+ provider: z2.string().min(1),
139
+ actorId: z2.string().min(1),
140
+ authorizationId: z2.string().min(1)
141
+ }).strict();
142
+ var toolExecutionStartedEventDataSchema = z2.object({
143
+ type: z2.literal("tool_execution_started"),
144
+ toolCallId: z2.string().min(1),
145
+ toolName: z2.string().min(1)
146
+ }).strict();
147
+ var guardianActionReviewedEventDataSchema = z2.object({
148
+ type: z2.literal("guardian_action_reviewed"),
149
+ turnId: z2.string().min(1),
150
+ toolCallId: z2.string().min(1),
151
+ toolName: z2.string().min(1),
152
+ costUsd: z2.number().finite().nonnegative().optional(),
153
+ decision: z2.enum(["allow", "ask", "deny"]),
154
+ riskLevel: z2.enum(["low", "medium", "high", "critical"]),
155
+ userAuthorization: z2.enum(["high", "medium", "low", "unknown"])
156
+ }).strict();
157
+ var conversationMessageRoleSchema = z2.union([
158
+ z2.literal("user"),
159
+ z2.literal("assistant"),
160
+ z2.literal("system")
161
+ ]);
162
+ var messageEventDataSchema = z2.object({
163
+ type: z2.literal("message"),
164
+ messageId: z2.string().min(1),
165
+ role: conversationMessageRoleSchema,
166
+ text: z2.string(),
167
+ authorIdentityId: z2.string().min(1).optional(),
168
+ meta: z2.record(z2.string(), z2.unknown()).optional()
169
+ }).strict();
170
+ var messageUpdatedEventDataSchema = messageEventDataSchema.extend({
171
+ type: z2.literal("message_updated")
172
+ });
173
+ var messageHandledEventDataSchema = z2.object({
174
+ type: z2.literal("message_handled"),
175
+ messageId: z2.string().min(1)
176
+ }).strict();
177
+ var messagesSummarizedEventDataSchema = z2.object({
178
+ type: z2.literal("messages_summarized"),
179
+ historyFromSeq: z2.number().int().nonnegative(),
180
+ compactions: z2.array(
181
+ z2.object({
182
+ coveredMessageCount: z2.number().int().nonnegative(),
183
+ createdAtMs: z2.number(),
184
+ id: z2.string().min(1),
185
+ summary: z2.string()
186
+ }).strict()
187
+ )
188
+ }).strict();
189
+ var conversationTurnSurfaceSchema = z2.enum([
190
+ "slack",
191
+ "api",
192
+ "scheduler",
193
+ "internal"
194
+ ]);
195
+ var conversationTurnFailureCodeSchema = z2.enum([
196
+ "agent_run_failed",
197
+ "delivery_failed",
198
+ "model_execution_failed",
199
+ "persistence_failed"
200
+ ]);
201
+ var conversationTurnFailureReasonSchema = z2.enum([
202
+ "auth",
203
+ "permission",
204
+ "rate_limit",
205
+ "capacity",
206
+ "timeout",
207
+ "network",
208
+ "server",
209
+ "invalid_request",
210
+ "invalid_response",
211
+ "quota",
212
+ "content_policy",
213
+ "unknown",
214
+ "empty_output",
215
+ "tool_errors",
216
+ "suppressed_output"
217
+ ]);
218
+ var turnStartedEventDataSchema = z2.object({
219
+ type: z2.literal("turn_started"),
220
+ turnId: z2.string().min(1),
221
+ inputMessageIds: z2.array(z2.string().min(1)).min(1),
222
+ surface: conversationTurnSurfaceSchema
223
+ }).strict().refine(
224
+ (data) => new Set(data.inputMessageIds).size === data.inputMessageIds.length,
225
+ "turn input message ids must be unique"
226
+ );
227
+ var turnRoutedEventDataSchema = z2.object({
228
+ type: z2.literal("turn_routed"),
229
+ turnId: z2.string().min(1),
230
+ modelProfile: modelProfileSchema,
231
+ modelId: z2.string().min(1),
232
+ costUsd: z2.number().finite().nonnegative().optional(),
233
+ reasoningLevel: z2.enum(TURN_REASONING_LEVELS),
234
+ confidence: z2.number().min(0).max(1).optional(),
235
+ source: z2.enum(["configured", "inherited", "router"])
236
+ }).strict();
237
+ var turnContextEventDataSchema = z2.object({
238
+ type: z2.literal("turn_context"),
239
+ turnId: z2.string().min(1),
240
+ pluginName: z2.string().min(1),
241
+ kind: z2.string().min(1).max(64),
242
+ version: z2.number().int().positive(),
243
+ content: z2.record(z2.string(), z2.unknown())
244
+ }).strict();
245
+ var structuredConversationEventDataSchema = z2.object({
246
+ type: z2.literal("structured_event"),
247
+ namespace: z2.string().regex(/^[a-z][a-z0-9-]*$/),
248
+ name: z2.string().regex(/^[a-z][a-z0-9_]*$/),
249
+ version: z2.number().int().positive(),
250
+ turnId: z2.string().min(1).optional(),
251
+ content: z2.record(z2.string(), z2.unknown())
252
+ }).strict();
253
+ var deliveredAttachmentSchema = z2.object({
254
+ id: z2.string().min(1),
255
+ filename: z2.string().min(1),
256
+ contentType: z2.string().min(1),
257
+ bytes: z2.number().int().nonnegative()
258
+ }).strict();
259
+ var attachmentsDeliveredEventDataSchema = z2.object({
260
+ type: z2.literal("attachments_delivered"),
261
+ attachments: z2.array(deliveredAttachmentSchema).min(1),
262
+ toolCallId: z2.string().min(1).optional(),
263
+ turnId: z2.string().min(1).optional()
264
+ }).strict();
265
+ var turnCompletedEventDataSchema = z2.object({
266
+ type: z2.literal("turn_completed"),
267
+ turnId: z2.string().min(1),
268
+ outcome: z2.enum(["success", "no_reply", "cancelled"])
269
+ }).strict();
270
+ var turnFailedEventDataSchema = z2.object({
271
+ type: z2.literal("turn_failed"),
272
+ turnId: z2.string().min(1),
273
+ failureCode: conversationTurnFailureCodeSchema,
274
+ failureReason: conversationTurnFailureReasonSchema.optional(),
275
+ eventId: z2.string().regex(/^[a-f0-9]{32}$/i).optional()
276
+ }).strict();
277
+ var subagentStartedEventDataSchema = z2.object({
278
+ type: z2.literal("subagent_started"),
279
+ subagentInvocationId: z2.string().min(1),
280
+ subagentKind: z2.string().min(1),
281
+ modelId: z2.string().min(1).optional(),
282
+ parentToolCallId: z2.string().min(1).optional(),
283
+ reasoningLevel: z2.string().min(1).optional(),
284
+ childConversationId: z2.string().min(1)
285
+ }).strict();
286
+ var subagentEndedEventDataSchema = z2.object({
287
+ type: z2.literal("subagent_ended"),
288
+ subagentInvocationId: z2.string().min(1),
289
+ outcome: z2.union([
290
+ z2.literal("success"),
291
+ z2.literal("error"),
292
+ z2.literal("aborted")
293
+ ]),
294
+ errorCode: z2.string().min(1).optional()
295
+ }).strict();
296
+ var appendableConversationEventDataSchema = z2.union([
297
+ messageEventDataSchema,
298
+ messageUpdatedEventDataSchema,
299
+ agentHistoryItemSchema,
300
+ mcpProviderConnectedEventDataSchema,
301
+ authorizationRequestedEventDataSchema,
302
+ authorizationCompletedEventDataSchema,
303
+ toolExecutionStartedEventDataSchema,
304
+ guardianActionReviewedEventDataSchema,
305
+ messageHandledEventDataSchema,
306
+ messagesSummarizedEventDataSchema,
307
+ turnStartedEventDataSchema,
308
+ turnContextEventDataSchema,
309
+ structuredConversationEventDataSchema,
310
+ attachmentsDeliveredEventDataSchema,
311
+ turnRoutedEventDataSchema,
312
+ turnCompletedEventDataSchema,
313
+ turnFailedEventDataSchema,
314
+ subagentStartedEventDataSchema,
315
+ subagentEndedEventDataSchema
316
+ ]);
317
+ var conversationEventDataSchema = z2.union([
318
+ appendableConversationEventDataSchema,
319
+ historyReplacementEventDataSchema,
320
+ unownedMcpProviderConnectedEventDataSchema
321
+ ]);
322
+ var KNOWN_CONVERSATION_EVENT_TYPES = [
323
+ "message",
324
+ "message_updated",
325
+ "user_message",
326
+ "assistant_message",
327
+ "tool_result",
328
+ "mcp_provider_connected",
329
+ "mcp_provider_connected_unowned",
330
+ "authorization_requested",
331
+ "authorization_completed",
332
+ "tool_execution_started",
333
+ "guardian_action_reviewed",
334
+ "message_handled",
335
+ "messages_summarized",
336
+ "turn_started",
337
+ "turn_context",
338
+ "structured_event",
339
+ "attachments_delivered",
340
+ "turn_routed",
341
+ "turn_completed",
342
+ "turn_failed",
343
+ "subagent_started",
344
+ "subagent_ended",
345
+ "handoff",
346
+ "compaction"
347
+ ];
348
+ var knownConversationEventTypeSchema = z2.enum(KNOWN_CONVERSATION_EVENT_TYPES);
349
+ var unknownConversationEventDataSchema = z2.object({
350
+ type: z2.literal("unknown"),
351
+ originalType: z2.string().min(1),
352
+ payload: z2.unknown()
353
+ }).strict();
354
+ var conversationEventEnvelopeSchema = z2.object({
355
+ schemaVersion: z2.number().int().nonnegative(),
356
+ seq: z2.number().int().nonnegative(),
357
+ historyVersion: z2.number().int().nonnegative(),
358
+ idempotencyKey: z2.string().min(1).optional(),
359
+ createdAtMs: z2.number().finite()
360
+ }).strict();
361
+ var conversationEventSchema = z2.union([
362
+ conversationEventEnvelopeSchema.extend({
363
+ schemaVersion: z2.literal(1),
364
+ data: conversationEventDataSchema
365
+ }),
366
+ conversationEventEnvelopeSchema.extend({
367
+ data: unknownConversationEventDataSchema
368
+ })
369
+ ]);
370
+ var storedConversationEventSchema = conversationEventEnvelopeSchema.extend({
371
+ type: z2.string().min(1),
372
+ payload: z2.unknown()
373
+ });
374
+ function decodeStoredConversationEvent(value) {
375
+ const stored = storedConversationEventSchema.parse(value);
376
+ const { type, payload, ...envelope } = stored;
377
+ const knownType = knownConversationEventTypeSchema.safeParse(type).success;
378
+ if (stored.schemaVersion === 1 && knownType) {
379
+ const data = typeof payload === "object" && payload !== null && !Array.isArray(payload) ? { ...payload, type } : { type };
380
+ return conversationEventSchema.parse({ ...envelope, data });
381
+ }
382
+ return conversationEventSchema.parse({
383
+ ...envelope,
384
+ data: { type: "unknown", originalType: type, payload }
385
+ });
386
+ }
387
+ var newConversationEventSchema = z2.object({
388
+ data: appendableConversationEventDataSchema,
389
+ idempotencyKey: z2.string().min(1).optional(),
390
+ createdAtMs: z2.number().finite()
391
+ }).strict();
392
+
393
+ export {
394
+ instructionProvenanceFor,
395
+ contextProvenance,
396
+ sameActorIdentity,
397
+ instructionActors,
398
+ agentHistoryItemSchema,
399
+ historyReplacementSchema,
400
+ conversationTurnFailureCodeSchema,
401
+ conversationTurnFailureReasonSchema,
402
+ conversationEventDataSchema,
403
+ KNOWN_CONVERSATION_EVENT_TYPES,
404
+ decodeStoredConversationEvent,
405
+ newConversationEventSchema
406
+ };
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  createPluginCatalogRuntime
3
- } from "./chunk-EENQGEIP.js";
3
+ } from "./chunk-7MHNIGHP.js";
4
4
 
5
5
  // src/chat/plugins/catalog-runtime.ts
6
6
  var pluginCatalogRuntime = createPluginCatalogRuntime();
@@ -1,11 +1,15 @@
1
+ import {
2
+ AgentRunError,
3
+ executeTurn
4
+ } from "./chunk-W7GCLNIV.js";
1
5
  import {
2
6
  ConversationTurnLifecycleService
3
- } from "./chunk-M3QYTBQ6.js";
7
+ } from "./chunk-6Q7YZLCL.js";
4
8
  import {
5
9
  getPersistedSandboxState,
6
10
  getPersistedThreadState,
7
11
  persistThreadStateById
8
- } from "./chunk-PLZT45VC.js";
12
+ } from "./chunk-Y5G23T2D.js";
9
13
  import {
10
14
  AgentInvocationBusyError,
11
15
  AgentInvocationLimitError,
@@ -14,78 +18,36 @@ import {
14
18
  agentBindingSchema,
15
19
  agentInvocationSchema,
16
20
  createAgentInvocationSchema
17
- } from "./chunk-35PM4YY5.js";
21
+ } from "./chunk-EWEH2PJW.js";
18
22
  import {
19
23
  appendAndEnqueueInboundMessage
20
- } from "./chunk-HUK5XIZL.js";
24
+ } from "./chunk-D63IUQQE.js";
21
25
  import {
22
26
  TurnInputCommitLostError,
23
27
  getAssistantReplyText,
24
28
  getConversationTurnBoundaryError,
25
29
  isTurnInputCommitLostError
26
- } from "./chunk-56XONJPF.js";
30
+ } from "./chunk-U4CTAVWN.js";
27
31
  import {
28
32
  failTurnRecord,
29
33
  getTerminalAssistantMessages,
30
34
  getTurnRecord,
31
35
  openConversationProjection,
32
36
  saveTurnCheckpoint
33
- } from "./chunk-24OJZ5OU.js";
37
+ } from "./chunk-WLKWN4CD.js";
34
38
  import {
35
39
  getConversationEventStore,
36
40
  getConversationStore,
37
41
  getSqlExecutor
38
- } from "./chunk-AX3UDIMA.js";
42
+ } from "./chunk-ABAX75GG.js";
39
43
  import {
40
44
  juniorAgentBindings,
41
45
  juniorAgentInvocations
42
- } from "./chunk-6UXDTPEN.js";
46
+ } from "./chunk-LVK4WJKM.js";
43
47
 
44
48
  // src/chat/agent-invocations/work.ts
45
49
  import { z } from "zod";
46
50
 
47
- // src/chat/runtime/turn-execution.ts
48
- var AgentRunError = class extends Error {
49
- constructor(cause) {
50
- super(cause instanceof Error ? cause.message : "Agent Run failed", {
51
- cause
52
- });
53
- this.name = "AgentRunError";
54
- }
55
- };
56
- async function executeTurn(agentRunner, run, saveResult) {
57
- let outcome;
58
- try {
59
- outcome = await agentRunner.run(run);
60
- } catch (error) {
61
- throw new AgentRunError(error);
62
- }
63
- if (outcome.status !== "completed") {
64
- return outcome;
65
- }
66
- const saved = await saveResult(outcome.result);
67
- const lifecycle = new ConversationTurnLifecycleService(
68
- getConversationEventStore()
69
- );
70
- const common = {
71
- conversationId: run.conversationId,
72
- createdAtMs: saved.finishedAtMs ?? Date.now(),
73
- turnId: run.turnId
74
- };
75
- if (saved.outcome === "failed") {
76
- await lifecycle.fail({
77
- ...common,
78
- failureCode: saved.failureCode
79
- });
80
- } else {
81
- await lifecycle.complete({
82
- ...common,
83
- outcome: saved.outcome
84
- });
85
- }
86
- return { status: "completed" };
87
- }
88
-
89
51
  // src/chat/agent-invocations/store.ts
90
52
  import { createHash } from "crypto";
91
53
  import { and, asc, count, eq, inArray } from "drizzle-orm";