@sentry/junior 0.184.0 → 0.186.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 (129) hide show
  1. package/dist/{agent-hooks-XTZVALGQ.js → agent-hooks-4B3Z4WRK.js} +13 -11
  2. package/dist/api/acp/schema.d.ts +20 -2
  3. package/dist/api/code/overview.d.ts +39 -0
  4. package/dist/api/locations/detail.d.ts +1 -1
  5. package/dist/api/people/code.d.ts +22 -0
  6. package/dist/api/schema/code.d.ts +46 -0
  7. package/dist/api/schema/conversation.d.ts +108 -20
  8. package/dist/api/schema/location.d.ts +1 -1
  9. package/dist/api/schema/person.d.ts +1 -1
  10. package/dist/api/schema.d.ts +4 -4
  11. package/dist/api/schema.js +12 -1
  12. package/dist/api.js +368 -78
  13. package/dist/app.js +1412 -538
  14. package/dist/{catalog-runtime-5357XR4F.js → catalog-runtime-AFJCAOHC.js} +4 -4
  15. package/dist/chat/api-turns/accepted-reply.d.ts +11 -0
  16. package/dist/chat/api-turns/cancellation.d.ts +3 -5
  17. package/dist/chat/api-turns/mailbox-input.d.ts +7 -0
  18. package/dist/chat/api-turns/routing.d.ts +18 -3
  19. package/dist/chat/api-turns/work.d.ts +4 -9
  20. package/dist/chat/app/conversation-work.d.ts +1 -1
  21. package/dist/chat/app/factory.d.ts +4 -0
  22. package/dist/chat/app/services.d.ts +4 -3
  23. package/dist/chat/conversations/history.d.ts +83 -9
  24. package/dist/chat/conversations/turn-lifecycle.d.ts +6 -3
  25. package/dist/chat/providers/slack/input.d.ts +32 -0
  26. package/dist/chat/{runtime → providers/slack}/processing-reaction.d.ts +6 -8
  27. package/dist/chat/{runtime/slack-resume.d.ts → providers/slack/resume.d.ts} +16 -19
  28. package/dist/chat/providers/slack/runtime.d.ts +1 -12
  29. package/dist/chat/providers/slack/turn.d.ts +10 -25
  30. package/dist/chat/resource-events/actor.d.ts +7 -2
  31. package/dist/chat/resource-events/app-publisher.d.ts +18 -0
  32. package/dist/chat/resource-events/catalog.d.ts +19 -0
  33. package/dist/chat/resource-events/ingest.d.ts +0 -1
  34. package/dist/chat/resource-events/notification.d.ts +28 -3
  35. package/dist/chat/resource-events/runtime-catalog.d.ts +7 -2
  36. package/dist/chat/resource-events/store.d.ts +2 -14
  37. package/dist/chat/resource-events/tool-support.d.ts +0 -5
  38. package/dist/chat/resource-events/workspace.d.ts +7 -3
  39. package/dist/chat/runtime/turn-execution.d.ts +7 -2
  40. package/dist/chat/sandbox/egress/credentials.d.ts +5 -4
  41. package/dist/chat/sandbox/egress/session.d.ts +10 -11
  42. package/dist/chat/sandbox/errors.d.ts +1 -1
  43. package/dist/chat/sandbox/ref.d.ts +1 -1
  44. package/dist/chat/sandbox/snapshot/events.d.ts +8 -1
  45. package/dist/chat/sandbox/snapshot/not-ready-error.d.ts +6 -1
  46. package/dist/chat/scheduled-tasks/tool-support.d.ts +5 -5
  47. package/dist/chat/scheduled-tasks/tools/create.d.ts +2 -2
  48. package/dist/chat/scheduled-tasks/tools/delete.d.ts +2 -2
  49. package/dist/chat/scheduled-tasks/tools/list.d.ts +2 -2
  50. package/dist/chat/scheduled-tasks/tools/run-now.d.ts +2 -2
  51. package/dist/chat/scheduled-tasks/tools/update.d.ts +2 -2
  52. package/dist/chat/scheduled-tasks/types.d.ts +1 -1
  53. package/dist/chat/sentry-links.d.ts +2 -0
  54. package/dist/chat/services/provider-retry.d.ts +2 -0
  55. package/dist/chat/services/turn-failure-response.d.ts +4 -0
  56. package/dist/chat/services/turn-session-routing.d.ts +20 -5
  57. package/dist/chat/task-execution/paused-turn.d.ts +0 -2
  58. package/dist/chat/task-execution/slack-resource-event.d.ts +47 -0
  59. package/dist/chat/task-execution/slack-work.d.ts +0 -21
  60. package/dist/chat/task-execution/state.d.ts +2 -2
  61. package/dist/chat/task-execution/store.d.ts +1 -1
  62. package/dist/chat/task-execution/turn-wake.d.ts +12 -0
  63. package/dist/chat/tool-support/action-review.d.ts +1 -1
  64. package/dist/chat/tools/event-tasks.d.ts +1 -1
  65. package/dist/chat/tools/resource-events.d.ts +2 -2
  66. package/dist/chat/tools/search-conversation-events.d.ts +1 -1
  67. package/dist/chat/tools/types.d.ts +1 -1
  68. package/dist/chat/tools/watch-resource-events.d.ts +2 -2
  69. package/dist/{chunk-Z3QAXJR7.js → chunk-2IBDVE62.js} +12 -9
  70. package/dist/{chunk-4RONS3WR.js → chunk-2U7EPTRZ.js} +11 -5
  71. package/dist/{chunk-3S7ULUWW.js → chunk-3CVEE6LA.js} +1 -1
  72. package/dist/{chunk-IZDYYYGP.js → chunk-43LODHJM.js} +24 -384
  73. package/dist/{chunk-LHXIZLFF.js → chunk-64WF2GQ3.js} +1 -1
  74. package/dist/{chunk-YKX6MTLU.js → chunk-7EOWT62G.js} +1 -1
  75. package/dist/{chunk-UBOIHNTH.js → chunk-7EU4YSZ4.js} +362 -188
  76. package/dist/{chunk-UF6BUA5W.js → chunk-ACGWTJ74.js} +3 -3
  77. package/dist/{chunk-6UDPINOX.js → chunk-AD64YMEC.js} +19 -44
  78. package/dist/{chunk-MLSQX2EX.js → chunk-BRKB5R7P.js} +1 -1
  79. package/dist/{chunk-E57WPXWY.js → chunk-CM6RTYSO.js} +5 -5
  80. package/dist/{chunk-MAPJFUMV.js → chunk-CV5CPRVG.js} +3 -3
  81. package/dist/chunk-D4YV5TDV.js +45 -0
  82. package/dist/{chunk-HIPUIPJM.js → chunk-DHYZ4VKG.js} +383 -254
  83. package/dist/{chunk-DUKIDPF6.js → chunk-DOP3FIQC.js} +1 -1
  84. package/dist/{chunk-BT53RIGJ.js → chunk-EWRPUXE3.js} +12 -50
  85. package/dist/{chunk-BHYRYYLY.js → chunk-FFYDRLXW.js} +1 -1
  86. package/dist/chunk-GFBR4S3Q.js +406 -0
  87. package/dist/chunk-GQMQCY7H.js +58 -0
  88. package/dist/{chunk-JNO2GUDS.js → chunk-GSB3NTNS.js} +926 -1856
  89. package/dist/{chunk-2ZQPVX7C.js → chunk-H7X2G2KS.js} +25 -12
  90. package/dist/{chunk-WQFEWULF.js → chunk-HKFLRIBD.js} +2 -2
  91. package/dist/{chunk-SHJK75Z2.js → chunk-HWXP6RHG.js} +38 -4
  92. package/dist/{chunk-RF6J3DIO.js → chunk-INQHUE72.js} +84 -1
  93. package/dist/{chunk-4CNDGK25.js → chunk-JFPY6XFF.js} +911 -993
  94. package/dist/{chunk-6WGC3SO4.js → chunk-MCLWOBPN.js} +80 -18
  95. package/dist/{chunk-PJPRXO2T.js → chunk-NRMAOGRS.js} +1 -1
  96. package/dist/{chunk-ACPDVEJO.js → chunk-O6GQO7VP.js} +201 -218
  97. package/dist/{chunk-M5YWNMTE.js → chunk-OZG7E22Y.js} +24 -6
  98. package/dist/{chunk-WVIA7V3M.js → chunk-PFAZSRGR.js} +29 -1
  99. package/dist/{chunk-LCP4EDKR.js → chunk-PZZOGHVR.js} +14 -4
  100. package/dist/{chunk-QABCY33S.js → chunk-QBL2AVFF.js} +2 -2
  101. package/dist/{chunk-FKEZZMXS.js → chunk-QU3URVWG.js} +9 -94
  102. package/dist/{chunk-M3QYTBQ6.js → chunk-STOCCPWH.js} +11 -2
  103. package/dist/{chunk-K7VDC2QW.js → chunk-TXLBLGNQ.js} +6 -6
  104. package/dist/{chunk-JA43DV4Y.js → chunk-VOGOTEW7.js} +1 -1
  105. package/dist/{chunk-HUXFMDBZ.js → chunk-VQIWBJOP.js} +1 -1
  106. package/dist/{chunk-JM2COLGC.js → chunk-VQZYIVYN.js} +6 -6
  107. package/dist/{chunk-BCHYQS4B.js → chunk-VXL2LBPK.js} +1 -1
  108. package/dist/{chunk-6VOYP4M6.js → chunk-YXSBZRP7.js} +1 -1
  109. package/dist/cli/chat.js +35 -33
  110. package/dist/cli/check.js +5 -5
  111. package/dist/cli/plugins.js +14 -12
  112. package/dist/cli/snapshot-create.js +10 -9
  113. package/dist/cli/upgrade.js +7 -6
  114. package/dist/{db-MA52H62H.js → db-7XL4UPAE.js} +8 -6
  115. package/dist/instrumentation.js +3 -3
  116. package/dist/nitro.js +7 -6
  117. package/dist/{oauth-callback-server-DXGHKN6S.js → oauth-callback-server-RAOYHWDI.js} +30 -27
  118. package/dist/{runner-4IXUAQNK.js → runner-KMPBWRPM.js} +24 -19
  119. package/dist/{skills-X3DY7AXO.js → skills-IPCALGLQ.js} +5 -5
  120. package/dist/spawn-OSOWTMBG.js +41 -0
  121. package/dist/task-runner-IQNBA3RY.js +34 -0
  122. package/dist/{validation-Z6JXSTJS.js → validation-BSRCCX6N.js} +5 -5
  123. package/dist/version.js +1 -1
  124. package/dist/{work-OKWRFBDW.js → work-T6UFTOJY.js} +24 -19
  125. package/dist/worker-L35OG7VA.js +24 -0
  126. package/package.json +5 -5
  127. package/dist/spawn-43WGS6CH.js +0 -37
  128. package/dist/task-runner-VDRKITPV.js +0 -32
  129. package/dist/worker-B236AE72.js +0 -22
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  getChatConfig
3
- } from "./chunk-6UDPINOX.js";
3
+ } from "./chunk-AD64YMEC.js";
4
4
 
5
5
  // src/chat/state/adapter.ts
6
6
  import { createMemoryState } from "@chat-adapter/state-memory";
@@ -1,11 +1,15 @@
1
+ import {
2
+ AgentRunError,
3
+ executeTurn
4
+ } from "./chunk-GQMQCY7H.js";
1
5
  import {
2
6
  ConversationTurnLifecycleService
3
- } from "./chunk-M3QYTBQ6.js";
7
+ } from "./chunk-STOCCPWH.js";
4
8
  import {
5
9
  getPersistedSandboxState,
6
10
  getPersistedThreadState,
7
11
  persistThreadStateById
8
- } from "./chunk-E57WPXWY.js";
12
+ } from "./chunk-CM6RTYSO.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-K7VDC2QW.js";
21
+ } from "./chunk-TXLBLGNQ.js";
18
22
  import {
19
23
  appendAndEnqueueInboundMessage
20
- } from "./chunk-Z3QAXJR7.js";
24
+ } from "./chunk-2IBDVE62.js";
21
25
  import {
22
26
  TurnInputCommitLostError,
23
27
  getAssistantReplyText,
24
28
  getConversationTurnBoundaryError,
25
29
  isTurnInputCommitLostError
26
- } from "./chunk-JA43DV4Y.js";
30
+ } from "./chunk-VOGOTEW7.js";
27
31
  import {
28
32
  failTurnRecord,
29
33
  getTerminalAssistantMessages,
30
34
  getTurnRecord,
31
35
  openConversationProjection,
32
36
  saveTurnCheckpoint
33
- } from "./chunk-2ZQPVX7C.js";
37
+ } from "./chunk-H7X2G2KS.js";
34
38
  import {
35
39
  getConversationEventStore,
36
40
  getConversationStore,
37
41
  getSqlExecutor
38
- } from "./chunk-IZDYYYGP.js";
42
+ } from "./chunk-43LODHJM.js";
39
43
  import {
40
44
  juniorAgentBindings,
41
45
  juniorAgentInvocations
42
- } from "./chunk-BCHYQS4B.js";
46
+ } from "./chunk-VXL2LBPK.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";
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  logWarn
3
- } from "./chunk-3S7ULUWW.js";
3
+ } from "./chunk-3CVEE6LA.js";
4
4
 
5
5
  // src/chat/conversation-privacy.ts
6
6
  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
+ };
@@ -0,0 +1,58 @@
1
+ import {
2
+ ConversationTurnLifecycleService
3
+ } from "./chunk-STOCCPWH.js";
4
+ import {
5
+ runAgentWithTimeout
6
+ } from "./chunk-INQHUE72.js";
7
+ import {
8
+ getConversationEventStore
9
+ } from "./chunk-43LODHJM.js";
10
+
11
+ // src/chat/runtime/turn-execution.ts
12
+ var AgentRunError = class extends Error {
13
+ constructor(cause) {
14
+ super(cause instanceof Error ? cause.message : "Agent Run failed", {
15
+ cause
16
+ });
17
+ this.name = "AgentRunError";
18
+ }
19
+ };
20
+ async function executeTurn(agentRunner, run, saveResult, timeoutMs) {
21
+ let outcome;
22
+ try {
23
+ outcome = await runAgentWithTimeout(agentRunner, run, timeoutMs);
24
+ } catch (error) {
25
+ throw new AgentRunError(error);
26
+ }
27
+ if (outcome.status !== "completed") {
28
+ return outcome;
29
+ }
30
+ const saved = await saveResult(outcome.result);
31
+ const lifecycle = new ConversationTurnLifecycleService(
32
+ getConversationEventStore()
33
+ );
34
+ const common = {
35
+ conversationId: run.conversationId,
36
+ createdAtMs: saved.finishedAtMs ?? Date.now(),
37
+ turnId: run.turnId
38
+ };
39
+ if (saved.outcome === "failed") {
40
+ await lifecycle.fail({
41
+ ...common,
42
+ ...saved.eventId ? { eventId: saved.eventId } : void 0,
43
+ failureCode: saved.failureCode,
44
+ ...saved.failureReason ? { failureReason: saved.failureReason } : void 0
45
+ });
46
+ } else {
47
+ await lifecycle.complete({
48
+ ...common,
49
+ outcome: saved.outcome
50
+ });
51
+ }
52
+ return { status: "completed" };
53
+ }
54
+
55
+ export {
56
+ AgentRunError,
57
+ executeTurn
58
+ };