@sentry/junior 0.158.0 → 0.160.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 (69) hide show
  1. package/dist/{agent-hooks-BOWFTDE5.js → agent-hooks-U6R3O2V4.js} +10 -10
  2. package/dist/api/conversations/cancel-pending-messages.d.ts +4 -0
  3. package/dist/api/conversations/events.d.ts +1 -1
  4. package/dist/api/schema/conversation.d.ts +45 -0
  5. package/dist/api/schema.d.ts +2 -2
  6. package/dist/api/schema.js +5 -1
  7. package/dist/api.js +96 -23
  8. package/dist/app.js +32 -32
  9. package/dist/{catalog-runtime-7GZ25WTR.js → catalog-runtime-HIDNHGOP.js} +5 -5
  10. package/dist/chat/conversations/history.d.ts +35 -2
  11. package/dist/chat/conversations/projection.d.ts +13 -0
  12. package/dist/chat/slack/mrkdwn.d.ts +2 -1
  13. package/dist/chat/slack/tools/send-files.d.ts +2 -2
  14. package/dist/chat/task-execution/state.d.ts +10 -0
  15. package/dist/chat/task-execution/store.d.ts +11 -0
  16. package/dist/chat/tool-support/action-review.d.ts +5 -4
  17. package/dist/chat/tools/search-conversation-events.d.ts +1 -1
  18. package/dist/{chunk-BNFGY66A.js → chunk-2MK6S2UA.js} +1 -1
  19. package/dist/{chunk-YEZS4TEY.js → chunk-2SFMRMDV.js} +1 -1
  20. package/dist/{chunk-4XJ2WSTI.js → chunk-3AHIB66R.js} +5 -5
  21. package/dist/{chunk-EQ6Y37MD.js → chunk-42E7432W.js} +1 -1
  22. package/dist/{chunk-SSU65ZTZ.js → chunk-472VVYYV.js} +1 -1
  23. package/dist/{chunk-VURJ2NSF.js → chunk-4UO3UAW7.js} +1 -1
  24. package/dist/{chunk-DTVTBZNP.js → chunk-56TFPTZU.js} +1 -1
  25. package/dist/{chunk-FA32YRZ3.js → chunk-756F567I.js} +5 -5
  26. package/dist/{chunk-UJ6N32ZM.js → chunk-BGVQGEKB.js} +4 -4
  27. package/dist/{chunk-UQJO35BP.js → chunk-FJR66CQT.js} +4 -4
  28. package/dist/{chunk-A7EDLNGU.js → chunk-FKMWPA4A.js} +55 -4
  29. package/dist/{chunk-6GJCOUTA.js → chunk-HDPH4CHJ.js} +1 -1
  30. package/dist/{chunk-FAJ6SMEE.js → chunk-J77DLAPE.js} +2 -2
  31. package/dist/{chunk-AF4PHIP6.js → chunk-JQZIUESN.js} +41 -10
  32. package/dist/{chunk-RCIKTZZF.js → chunk-LNUZXEEI.js} +1 -1
  33. package/dist/{chunk-EXITAVHO.js → chunk-M5HCOMDR.js} +90 -35
  34. package/dist/{chunk-KAFYW3O6.js → chunk-MBDWMEO6.js} +10 -10
  35. package/dist/{chunk-ROOTB7J7.js → chunk-OUAZDZTZ.js} +2 -2
  36. package/dist/{chunk-4JAOLUDB.js → chunk-P7W3ZL5J.js} +35 -6
  37. package/dist/{chunk-3A7VXSPJ.js → chunk-PVIM2RWO.js} +8 -8
  38. package/dist/{chunk-SAJPQLTY.js → chunk-PZUJPPON.js} +1 -1
  39. package/dist/{chunk-4Q6QVTKA.js → chunk-RJGRXDA7.js} +5 -5
  40. package/dist/{chunk-C3FYJZSA.js → chunk-RLOXMHLA.js} +40 -4
  41. package/dist/{chunk-UPPU3FQU.js → chunk-TBRJGMTO.js} +1 -1
  42. package/dist/{chunk-JEXQQLEC.js → chunk-TPFOVXRB.js} +18 -18
  43. package/dist/{chunk-NOEERHHR.js → chunk-U26KRMYX.js} +6 -6
  44. package/dist/{chunk-PHQDXC27.js → chunk-UNDTW2PY.js} +1 -1
  45. package/dist/{chunk-IEM3GFXL.js → chunk-URPLKXLG.js} +9 -9
  46. package/dist/{chunk-CZCMFRUQ.js → chunk-UYUS4L6F.js} +22 -0
  47. package/dist/{chunk-X4BLYIMV.js → chunk-WACYTIIK.js} +6 -6
  48. package/dist/{chunk-LUSAAJJA.js → chunk-XPX3DYG7.js} +2 -2
  49. package/dist/{chunk-IXYGGJRA.js → chunk-YPMDNE7R.js} +1 -1
  50. package/dist/{chunk-KSZXVR5G.js → chunk-ZNBGWMVQ.js} +1 -1
  51. package/dist/cli/chat.js +30 -30
  52. package/dist/cli/check.js +6 -6
  53. package/dist/cli/plugins.js +13 -13
  54. package/dist/cli/snapshot-create.js +9 -9
  55. package/dist/cli/upgrade.js +7 -7
  56. package/dist/{db-HFWTPYT7.js → db-2JKT3BB5.js} +7 -7
  57. package/dist/instrumentation.js +4 -4
  58. package/dist/nitro.js +2 -2
  59. package/dist/{oauth-callback-server-J3NW4QL5.js → oauth-callback-server-7MC2UMQC.js} +23 -23
  60. package/dist/{runner-CL6QHML5.js → runner-GUU4G7XO.js} +13 -13
  61. package/dist/{skills-WZWKZIFQ.js → skills-7NW5N3VM.js} +6 -6
  62. package/dist/spawn-WGK4W3XF.js +37 -0
  63. package/dist/{validation-4HVSSLJV.js → validation-AQLI6N2C.js} +6 -6
  64. package/dist/version.js +1 -1
  65. package/dist/{work-UF4KXPVG.js → work-FLFK5XNU.js} +17 -17
  66. package/dist/worker-KSJIRBQJ.js +24 -0
  67. package/package.json +5 -5
  68. package/dist/spawn-TQJWADG4.js +0 -37
  69. package/dist/worker-HI7I2W2U.js +0 -24
@@ -307,6 +307,16 @@ export declare const conversationEventDataSchema: z.ZodUnion<readonly [z.ZodUnio
307
307
  version: z.ZodNumber;
308
308
  turnId: z.ZodOptional<z.ZodString>;
309
309
  content: z.ZodRecord<z.ZodString, z.ZodUnknown>;
310
+ }, z.core.$strict>, z.ZodObject<{
311
+ type: z.ZodLiteral<"attachments_delivered">;
312
+ attachments: z.ZodArray<z.ZodObject<{
313
+ id: z.ZodString;
314
+ filename: z.ZodString;
315
+ contentType: z.ZodString;
316
+ bytes: z.ZodNumber;
317
+ }, z.core.$strict>>;
318
+ toolCallId: z.ZodOptional<z.ZodString>;
319
+ turnId: z.ZodOptional<z.ZodString>;
310
320
  }, z.core.$strict>, z.ZodObject<{
311
321
  type: z.ZodLiteral<"turn_routed">;
312
322
  turnId: z.ZodString;
@@ -463,7 +473,7 @@ export declare const conversationEventDataSchema: z.ZodUnion<readonly [z.ZodUnio
463
473
  /** One durable conversation event's validated data. */
464
474
  export type ConversationEventData = z.output<typeof conversationEventDataSchema>;
465
475
  /** Event type names recognized by current readers and observational queries. */
466
- export declare const KNOWN_CONVERSATION_EVENT_TYPES: readonly ["message", "message_updated", "user_message", "assistant_message", "tool_result", "mcp_provider_connected", "mcp_provider_connected_unowned", "authorization_requested", "authorization_completed", "tool_execution_started", "guardian_action_reviewed", "message_handled", "messages_summarized", "turn_started", "turn_context", "structured_event", "turn_routed", "turn_completed", "turn_failed", "subagent_started", "subagent_ended", "handoff", "compaction"];
476
+ export declare const KNOWN_CONVERSATION_EVENT_TYPES: readonly ["message", "message_updated", "user_message", "assistant_message", "tool_result", "mcp_provider_connected", "mcp_provider_connected_unowned", "authorization_requested", "authorization_completed", "tool_execution_started", "guardian_action_reviewed", "message_handled", "messages_summarized", "turn_started", "turn_context", "structured_event", "attachments_delivered", "turn_routed", "turn_completed", "turn_failed", "subagent_started", "subagent_ended", "handoff", "compaction"];
467
477
  /** One known durable conversation event type name. */
468
478
  export type KnownConversationEventType = (typeof KNOWN_CONVERSATION_EVENT_TYPES)[number];
469
479
  declare const unknownConversationEventDataSchema: z.ZodObject<{
@@ -612,6 +622,16 @@ export declare const conversationEventSchema: z.ZodUnion<readonly [z.ZodObject<{
612
622
  version: z.ZodNumber;
613
623
  turnId: z.ZodOptional<z.ZodString>;
614
624
  content: z.ZodRecord<z.ZodString, z.ZodUnknown>;
625
+ }, z.core.$strict>, z.ZodObject<{
626
+ type: z.ZodLiteral<"attachments_delivered">;
627
+ attachments: z.ZodArray<z.ZodObject<{
628
+ id: z.ZodString;
629
+ filename: z.ZodString;
630
+ contentType: z.ZodString;
631
+ bytes: z.ZodNumber;
632
+ }, z.core.$strict>>;
633
+ toolCallId: z.ZodOptional<z.ZodString>;
634
+ turnId: z.ZodOptional<z.ZodString>;
615
635
  }, z.core.$strict>, z.ZodObject<{
616
636
  type: z.ZodLiteral<"turn_routed">;
617
637
  turnId: z.ZodString;
@@ -940,6 +960,16 @@ export declare const newConversationEventSchema: z.ZodObject<{
940
960
  version: z.ZodNumber;
941
961
  turnId: z.ZodOptional<z.ZodString>;
942
962
  content: z.ZodRecord<z.ZodString, z.ZodUnknown>;
963
+ }, z.core.$strict>, z.ZodObject<{
964
+ type: z.ZodLiteral<"attachments_delivered">;
965
+ attachments: z.ZodArray<z.ZodObject<{
966
+ id: z.ZodString;
967
+ filename: z.ZodString;
968
+ contentType: z.ZodString;
969
+ bytes: z.ZodNumber;
970
+ }, z.core.$strict>>;
971
+ toolCallId: z.ZodOptional<z.ZodString>;
972
+ turnId: z.ZodOptional<z.ZodString>;
943
973
  }, z.core.$strict>, z.ZodObject<{
944
974
  type: z.ZodLiteral<"turn_routed">;
945
975
  turnId: z.ZodString;
@@ -1016,7 +1046,10 @@ export interface ConversationEventPage {
1016
1046
  }
1017
1047
  /** Persist and read the canonical per-conversation event log. */
1018
1048
  export interface ConversationEventStore {
1019
- /** Append events atomically, optionally preserving conversation activity. */
1049
+ /**
1050
+ * Append events atomically, optionally preserving conversation activity.
1051
+ * Archive clears only for human user activity, not every non-preserve write.
1052
+ */
1020
1053
  append(conversationId: string, events: NewConversationEvent[], options?: {
1021
1054
  activity?: "preserve";
1022
1055
  }): Promise<void>;
@@ -170,6 +170,19 @@ export declare function recordToolExecutionStarted(args: {
170
170
  toolCallId: string;
171
171
  toolName: string;
172
172
  }): Promise<void>;
173
+ /** Record files delivered for humans without adding them to Pi replay. */
174
+ export declare function recordAttachmentsDelivered(args: {
175
+ attachments: Array<{
176
+ bytes: number;
177
+ contentType: string;
178
+ filename: string;
179
+ id: string;
180
+ }>;
181
+ conversationId: string;
182
+ createdAtMs?: number;
183
+ toolCallId?: string;
184
+ turnId?: string;
185
+ }): Promise<void>;
173
186
  /** Record one privacy-safe Guardian decision before the reviewed action continues. */
174
187
  export declare function recordGuardianActionReviewed(args: {
175
188
  conversationId: string;
@@ -11,7 +11,8 @@ export declare function ensureBlockSpacing(text: string): string;
11
11
  * or `{ type: "markdown" }` blocks.
12
12
  *
13
13
  * Pre-wraps bare URLs as Slack explicit links to prevent Slack's auto-linker
14
- * from consuming adjacent formatting markers. Slack reply delivery owns
14
+ * from consuming adjacent formatting markers. Also turns unambiguous GitHub
15
+ * `owner/repo#number` mentions into Markdown links. Slack reply delivery owns
15
16
  * chunking and continuation markers separately.
16
17
  */
17
18
  export declare function normalizeSlackReplyMarkdown(text: string): string;
@@ -25,7 +25,7 @@ export declare function createSendFilesTool(context: SlackToolContext, state: To
25
25
  [x: string]: unknown;
26
26
  attachment_refs: {
27
27
  id: string;
28
- name: string;
28
+ filename: string;
29
29
  }[];
30
30
  target?: string | undefined;
31
31
  truncated?: boolean | undefined;
@@ -39,7 +39,7 @@ export declare function createSendFilesTool(context: SlackToolContext, state: To
39
39
  [x: string]: unknown;
40
40
  attachment_refs: {
41
41
  id: string;
42
- name: string;
42
+ filename: string;
43
43
  }[];
44
44
  target?: string | undefined;
45
45
  truncated?: boolean | undefined;
@@ -256,6 +256,16 @@ export declare function ackMessages(args: {
256
256
  nowMs?: number;
257
257
  state?: StateAdapter;
258
258
  }): Promise<boolean>;
259
+ /** Cancel human-facing pending mailbox rows without requiring a worker lease. */
260
+ export declare function cancelHumanFacingPendingMessages(args: {
261
+ conversationId: string;
262
+ inboundMessageIds?: readonly string[];
263
+ receivedBeforeMs?: number;
264
+ nowMs?: number;
265
+ state?: StateAdapter;
266
+ }): Promise<{
267
+ cancelledInboundMessageIds: string[];
268
+ }>;
259
269
  /** Mark the leased conversation as needing another queue-delivered slice. */
260
270
  export declare function requestAnotherSlice(args: {
261
271
  conversationId: string;
@@ -136,6 +136,17 @@ export declare function ackMessages(args: {
136
136
  nowMs?: number;
137
137
  state?: StateAdapter;
138
138
  }): Promise<boolean>;
139
+ /** Cancel human-facing pending mailbox rows without requiring a worker lease. */
140
+ export declare function cancelHumanFacingPendingMessages(args: {
141
+ conversationId: string;
142
+ inboundMessageIds?: readonly string[];
143
+ receivedBeforeMs?: number;
144
+ conversationStore?: ConversationStore;
145
+ nowMs?: number;
146
+ state?: StateAdapter;
147
+ }): Promise<{
148
+ cancelledInboundMessageIds: string[];
149
+ }>;
139
150
  /** Mark the leased conversation as needing another queue-delivered slice. */
140
151
  export declare function requestAnotherSlice(args: {
141
152
  conversationId: string;
@@ -4,7 +4,7 @@
4
4
  * Deterministic host checks establish authority before the model evaluates
5
5
  * untrusted action evidence.
6
6
  */
7
- import type { Destination, Source, ToolAnnotations } from "@sentry/junior-plugin-api";
7
+ import { type Destination, type Source, type ToolAnnotations } from "@sentry/junior-plugin-api";
8
8
  import type { Actor } from "@/chat/actor";
9
9
  import type { CredentialContext } from "@/chat/credentials/context";
10
10
  import type { AnyToolDefinition } from "@/chat/tools/definition";
@@ -111,6 +111,7 @@ export declare class ToolActionRejectedError extends Error {
111
111
  readonly riskLevel?: ToolActionReviewDecision["riskLevel"];
112
112
  readonly userAuthorization?: ToolActionReviewDecision["userAuthorization"];
113
113
  constructor(decision: Exclude<ToolActionDecision, "allow">, reason: string, assessment?: Partial<Pick<ToolActionReviewDecision, "riskLevel" | "userAuthorization">> & {
114
+ instructions?: string;
114
115
  reviewedAction?: ToolActionPriorRejection;
115
116
  });
116
117
  }
@@ -120,7 +121,7 @@ export declare class ToolActionReviewUnavailableError extends Error {
120
121
  cause?: unknown;
121
122
  });
122
123
  }
123
- /** The execution slice exceeded its bounded sequence of rejected actions. */
124
+ /** Telemetry-only marker when action review exhausts consecutive rejections. */
124
125
  export declare class ToolActionReviewLimitError extends Error {
125
126
  constructor();
126
127
  }
@@ -133,8 +134,8 @@ export declare function createToolActionReview(options: {
133
134
  toolName: string;
134
135
  decision: ToolActionReviewDecision;
135
136
  }): Promise<void>;
136
- /** Escalate terminal review failures to the owning agent-run boundary. */
137
- onFatal(error: ToolActionReviewUnavailableError | ToolActionReviewLimitError): void;
137
+ /** Escalate unavailable review to the owning agent-run boundary. */
138
+ onFatal(error: ToolActionReviewUnavailableError): void;
138
139
  priorRejections?: ToolActionPriorRejection[];
139
140
  reviewer: ToolActionReviewer;
140
141
  }): ToolActionReview;
@@ -9,7 +9,7 @@ export declare function createSearchConversationEventsTool(context: ToolRuntimeC
9
9
  after_seq?: number | null | undefined;
10
10
  before_seq?: number | null | undefined;
11
11
  limit?: number | null | undefined;
12
- types?: ("message" | "message_handled" | "assistant_message" | "turn_routed" | "guardian_action_reviewed" | "turn_context" | "structured_event" | "compaction" | "handoff" | "user_message" | "tool_result" | "mcp_provider_connected" | "mcp_provider_connected_unowned" | "authorization_requested" | "authorization_completed" | "tool_execution_started" | "message_updated" | "messages_summarized" | "turn_started" | "turn_completed" | "turn_failed" | "subagent_started" | "subagent_ended")[] | null | undefined;
12
+ types?: ("message" | "message_handled" | "assistant_message" | "turn_routed" | "guardian_action_reviewed" | "turn_context" | "structured_event" | "attachments_delivered" | "compaction" | "handoff" | "user_message" | "tool_result" | "mcp_provider_connected" | "mcp_provider_connected_unowned" | "authorization_requested" | "authorization_completed" | "tool_execution_started" | "message_updated" | "messages_summarized" | "turn_started" | "turn_completed" | "turn_failed" | "subagent_started" | "subagent_ended")[] | null | undefined;
13
13
  };
14
14
  execute?: ((input: unknown, options: import("./definition").ToolExecuteOptions) => {
15
15
  [x: string]: unknown;
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  createAndEnqueueAgentInvocation
3
- } from "./chunk-X4BLYIMV.js";
3
+ } from "./chunk-WACYTIIK.js";
4
4
  import {
5
5
  actorFromRun,
6
6
  toolInvocationDestination
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  createPluginCatalogRuntime
3
- } from "./chunk-EQ6Y37MD.js";
3
+ } from "./chunk-42E7432W.js";
4
4
 
5
5
  // src/chat/plugins/catalog-runtime.ts
6
6
  var pluginCatalogRuntime = createPluginCatalogRuntime();
@@ -1,18 +1,18 @@
1
1
  import {
2
2
  persistConversationMessages
3
- } from "./chunk-C3FYJZSA.js";
3
+ } from "./chunk-RLOXMHLA.js";
4
4
  import {
5
5
  JUNIOR_THREAD_STATE_TTL_MS
6
6
  } from "./chunk-3Y47VMHV.js";
7
7
  import {
8
8
  getDb
9
- } from "./chunk-AF4PHIP6.js";
9
+ } from "./chunk-JQZIUESN.js";
10
10
  import {
11
11
  juniorLocationConfigurations
12
- } from "./chunk-VURJ2NSF.js";
12
+ } from "./chunk-4UO3UAW7.js";
13
13
  import {
14
14
  getStateAdapter
15
- } from "./chunk-PHQDXC27.js";
15
+ } from "./chunk-UNDTW2PY.js";
16
16
  import {
17
17
  juniorDestinations
18
18
  } from "./chunk-VFUK3X5B.js";
@@ -20,7 +20,7 @@ import {
20
20
  isRecord,
21
21
  toOptionalNumber,
22
22
  toOptionalString
23
- } from "./chunk-KSZXVR5G.js";
23
+ } from "./chunk-ZNBGWMVQ.js";
24
24
 
25
25
  // src/chat/conversations/turn-lifecycle.ts
26
26
  var ConversationTurnLifecycleService = class {
@@ -5,7 +5,7 @@ import {
5
5
  logInfo,
6
6
  logWarn,
7
7
  setSpanAttributes
8
- } from "./chunk-KSZXVR5G.js";
8
+ } from "./chunk-ZNBGWMVQ.js";
9
9
  import {
10
10
  discoverInstalledPluginPackageContent,
11
11
  normalizePluginPackageNames
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  getStateAdapter
3
- } from "./chunk-PHQDXC27.js";
3
+ } from "./chunk-UNDTW2PY.js";
4
4
  import {
5
5
  getClient
6
6
  } from "./chunk-6GWA276C.js";
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  DEFAULT_SQL_STATEMENT_TIMEOUT_MS
3
- } from "./chunk-FAJ6SMEE.js";
3
+ } from "./chunk-J77DLAPE.js";
4
4
  import {
5
5
  juniorDestinations,
6
6
  timestamptz
@@ -5,7 +5,7 @@ import {
5
5
  } from "./chunk-V7YE4WCP.js";
6
6
  import {
7
7
  toOptionalString
8
- } from "./chunk-KSZXVR5G.js";
8
+ } from "./chunk-ZNBGWMVQ.js";
9
9
 
10
10
  // src/chat/slack/context.ts
11
11
  import { z } from "zod";
@@ -4,7 +4,7 @@ import {
4
4
  import {
5
5
  formatProviderLabel,
6
6
  startOAuthFlow
7
- } from "./chunk-4JAOLUDB.js";
7
+ } from "./chunk-P7W3ZL5J.js";
8
8
  import {
9
9
  parseSandboxEgressAuthRequiredSignal
10
10
  } from "./chunk-7MA4HV4W.js";
@@ -12,16 +12,16 @@ import {
12
12
  abandonReplacedPendingAuth,
13
13
  canReusePendingAuthLink,
14
14
  recordAuthorizationRequested
15
- } from "./chunk-C3FYJZSA.js";
15
+ } from "./chunk-RLOXMHLA.js";
16
16
  import {
17
17
  AGENT_INVOCATION_MAILBOX_STATUSES
18
- } from "./chunk-VURJ2NSF.js";
18
+ } from "./chunk-4UO3UAW7.js";
19
19
  import {
20
20
  TURN_REASONING_LEVELS
21
- } from "./chunk-FAJ6SMEE.js";
21
+ } from "./chunk-J77DLAPE.js";
22
22
  import {
23
23
  pluginCatalogRuntime
24
- } from "./chunk-YEZS4TEY.js";
24
+ } from "./chunk-2SFMRMDV.js";
25
25
  import {
26
26
  credentialContextSchema
27
27
  } from "./chunk-BDUENQD3.js";
@@ -4,18 +4,18 @@ import {
4
4
  } from "./chunk-EM225ITJ.js";
5
5
  import {
6
6
  getStateAdapter
7
- } from "./chunk-PHQDXC27.js";
7
+ } from "./chunk-UNDTW2PY.js";
8
8
  import {
9
9
  toOptionalTrimmed
10
- } from "./chunk-FAJ6SMEE.js";
10
+ } from "./chunk-J77DLAPE.js";
11
11
  import {
12
12
  pluginCatalogRuntime
13
- } from "./chunk-YEZS4TEY.js";
13
+ } from "./chunk-2SFMRMDV.js";
14
14
  import {
15
15
  setSpanAttributes,
16
16
  setSpanStatus,
17
17
  withSpan
18
- } from "./chunk-KSZXVR5G.js";
18
+ } from "./chunk-ZNBGWMVQ.js";
19
19
 
20
20
  // src/chat/sandbox/resources.ts
21
21
  var configuredResources;
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  getTurnRequestDeadline
3
- } from "./chunk-RCIKTZZF.js";
3
+ } from "./chunk-LNUZXEEI.js";
4
4
  import {
5
5
  CONVERSATION_WORK_CHECK_IN_INTERVAL_MS,
6
6
  CONVERSATION_WORK_MAX_RETRIES,
@@ -21,20 +21,20 @@ import {
21
21
  releaseConversationWork,
22
22
  requestAnotherSlice,
23
23
  startConversationWork
24
- } from "./chunk-A7EDLNGU.js";
24
+ } from "./chunk-FKMWPA4A.js";
25
25
  import {
26
26
  ConversationQueueMessageRejectedError
27
27
  } from "./chunk-JAL3CH4G.js";
28
28
  import {
29
29
  getChatConfig,
30
30
  isProviderRetryError
31
- } from "./chunk-FAJ6SMEE.js";
31
+ } from "./chunk-J77DLAPE.js";
32
32
  import {
33
33
  logException,
34
34
  logInfo,
35
35
  logWarn,
36
36
  withLogContext
37
- } from "./chunk-KSZXVR5G.js";
37
+ } from "./chunk-ZNBGWMVQ.js";
38
38
 
39
39
  // src/chat/task-execution/worker.ts
40
40
  var CONVERSATION_WORK_DEFER_DELAY_MS = 15e3;
@@ -8,14 +8,14 @@ import {
8
8
  getConversationStore,
9
9
  parseDestination,
10
10
  sameDestination
11
- } from "./chunk-AF4PHIP6.js";
11
+ } from "./chunk-JQZIUESN.js";
12
12
  import {
13
13
  getDefaultRedisStateAdapterFor,
14
14
  getStateAdapter
15
- } from "./chunk-PHQDXC27.js";
15
+ } from "./chunk-UNDTW2PY.js";
16
16
  import {
17
17
  getChatConfig
18
- } from "./chunk-FAJ6SMEE.js";
18
+ } from "./chunk-J77DLAPE.js";
19
19
  import {
20
20
  parseStoredSlackActor
21
21
  } from "./chunk-V7YE4WCP.js";
@@ -23,7 +23,7 @@ import {
23
23
  isRecord,
24
24
  toOptionalNumber,
25
25
  toOptionalString
26
- } from "./chunk-KSZXVR5G.js";
26
+ } from "./chunk-ZNBGWMVQ.js";
27
27
 
28
28
  // src/chat/task-execution/state.ts
29
29
  import { randomUUID } from "crypto";
@@ -984,6 +984,49 @@ async function ackMessages(args) {
984
984
  return true;
985
985
  });
986
986
  }
987
+ async function cancelHumanFacingPendingMessages(args) {
988
+ const nowMs = args.nowMs ?? now();
989
+ const requestedIds = args.inboundMessageIds === void 0 ? void 0 : new Set(args.inboundMessageIds);
990
+ return await withConversationMutation(args, async (state, lock) => {
991
+ const current = await readConversation(state, args.conversationId);
992
+ if (!current) {
993
+ return { cancelledInboundMessageIds: [] };
994
+ }
995
+ const cancelledInboundMessageIds = [];
996
+ const pendingMessages2 = [];
997
+ for (const message of current.execution.pendingMessages) {
998
+ const isHumanFacing = message.source === "web" || message.source === "slack";
999
+ const isRequested = requestedIds === void 0 || requestedIds.has(message.inboundMessageId);
1000
+ const isInSnapshot = args.receivedBeforeMs === void 0 || message.receivedAtMs <= args.receivedBeforeMs;
1001
+ if (isHumanFacing && isRequested && isInSnapshot) {
1002
+ cancelledInboundMessageIds.push(message.inboundMessageId);
1003
+ continue;
1004
+ }
1005
+ pendingMessages2.push(message);
1006
+ }
1007
+ if (cancelledInboundMessageIds.length === 0) {
1008
+ return { cancelledInboundMessageIds };
1009
+ }
1010
+ const becomesIdle = current.execution.status === "pending" && pendingMessages2.length === 0;
1011
+ await writeConversation(
1012
+ state,
1013
+ lock,
1014
+ withExecutionUpdate(
1015
+ current,
1016
+ {
1017
+ ...current.execution,
1018
+ lastEnqueuedAtMs: pendingMessages2.length === 0 ? void 0 : current.execution.lastEnqueuedAtMs,
1019
+ pendingMessages: pendingMessages2,
1020
+ retryCount: becomesIdle ? 0 : current.execution.retryCount,
1021
+ runId: becomesIdle ? void 0 : current.execution.runId,
1022
+ status: becomesIdle ? "idle" : current.execution.status
1023
+ },
1024
+ nowMs
1025
+ )
1026
+ );
1027
+ return { cancelledInboundMessageIds };
1028
+ });
1029
+ }
987
1030
  async function requestAnotherSlice(args) {
988
1031
  const nowMs = args.nowMs ?? now();
989
1032
  return await withConversationMutation(args, async (state, lock) => {
@@ -1451,6 +1494,13 @@ async function ackMessages2(args) {
1451
1494
  await recordExecutionMetadata(args);
1452
1495
  return result;
1453
1496
  }
1497
+ async function cancelHumanFacingPendingMessages2(args) {
1498
+ const result = await cancelHumanFacingPendingMessages(args);
1499
+ if (result.cancelledInboundMessageIds.length > 0) {
1500
+ await recordExecutionMetadata(args);
1501
+ }
1502
+ return result;
1503
+ }
1454
1504
  async function requestAnotherSlice2(args) {
1455
1505
  const result = await requestAnotherSlice(args);
1456
1506
  await recordExecutionMetadata(args);
@@ -1516,6 +1566,7 @@ export {
1516
1566
  checkInConversationWork2 as checkInConversationWork,
1517
1567
  drainConversationMailbox2 as drainConversationMailbox,
1518
1568
  ackMessages2 as ackMessages,
1569
+ cancelHumanFacingPendingMessages2 as cancelHumanFacingPendingMessages,
1519
1570
  requestAnotherSlice2 as requestAnotherSlice,
1520
1571
  beginConversationResume2 as beginConversationResume,
1521
1572
  releaseConversationWork2 as releaseConversationWork,
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  JUNIOR_VERSION
3
- } from "./chunk-IXYGGJRA.js";
3
+ } from "./chunk-YPMDNE7R.js";
4
4
 
5
5
  // src/deployment.ts
6
6
  var JUNIOR_HEARTBEAT_ROUTE = "/api/internal/heartbeat";
@@ -3,7 +3,7 @@ import {
3
3
  toCanonicalInputMessage,
4
4
  toCanonicalOutputMessage,
5
5
  toGenAiMessagesTraceAttributes
6
- } from "./chunk-UPPU3FQU.js";
6
+ } from "./chunk-TBRJGMTO.js";
7
7
  import {
8
8
  extractGenAiUsageAttributes,
9
9
  logException,
@@ -11,7 +11,7 @@ import {
11
11
  normalizeGenAiFinishReason,
12
12
  serializeGenAiAttribute,
13
13
  withSpan
14
- } from "./chunk-KSZXVR5G.js";
14
+ } from "./chunk-ZNBGWMVQ.js";
15
15
 
16
16
  // src/chat/services/provider-error.ts
17
17
  var ProviderError = class extends Error {
@@ -6,12 +6,12 @@ import {
6
6
  juniorConversations,
7
7
  juniorIdentities,
8
8
  juniorUsers
9
- } from "./chunk-VURJ2NSF.js";
9
+ } from "./chunk-4UO3UAW7.js";
10
10
  import {
11
11
  TURN_REASONING_LEVELS,
12
12
  getChatConfig,
13
13
  modelProfileSchema
14
- } from "./chunk-FAJ6SMEE.js";
14
+ } from "./chunk-J77DLAPE.js";
15
15
  import {
16
16
  juniorDestinations
17
17
  } from "./chunk-VFUK3X5B.js";
@@ -22,7 +22,7 @@ import {
22
22
  } from "./chunk-V7YE4WCP.js";
23
23
  import {
24
24
  normalizeIdentityEmail
25
- } from "./chunk-KSZXVR5G.js";
25
+ } from "./chunk-ZNBGWMVQ.js";
26
26
 
27
27
  // src/chat/conversations/sql/store.ts
28
28
  import { randomUUID as randomUUID2 } from "crypto";
@@ -1266,6 +1266,18 @@ var structuredConversationEventDataSchema = z3.object({
1266
1266
  turnId: z3.string().min(1).optional(),
1267
1267
  content: z3.record(z3.string(), z3.unknown())
1268
1268
  }).strict();
1269
+ var deliveredAttachmentSchema = z3.object({
1270
+ id: z3.string().min(1),
1271
+ filename: z3.string().min(1),
1272
+ contentType: z3.string().min(1),
1273
+ bytes: z3.number().int().nonnegative()
1274
+ }).strict();
1275
+ var attachmentsDeliveredEventDataSchema = z3.object({
1276
+ type: z3.literal("attachments_delivered"),
1277
+ attachments: z3.array(deliveredAttachmentSchema).min(1),
1278
+ toolCallId: z3.string().min(1).optional(),
1279
+ turnId: z3.string().min(1).optional()
1280
+ }).strict();
1269
1281
  var turnCompletedEventDataSchema = z3.object({
1270
1282
  type: z3.literal("turn_completed"),
1271
1283
  turnId: z3.string().min(1),
@@ -1310,6 +1322,7 @@ var appendableConversationEventDataSchema = z3.union([
1310
1322
  turnStartedEventDataSchema,
1311
1323
  turnContextEventDataSchema,
1312
1324
  structuredConversationEventDataSchema,
1325
+ attachmentsDeliveredEventDataSchema,
1313
1326
  turnRoutedEventDataSchema,
1314
1327
  turnCompletedEventDataSchema,
1315
1328
  turnFailedEventDataSchema,
@@ -1338,6 +1351,7 @@ var KNOWN_CONVERSATION_EVENT_TYPES = [
1338
1351
  "turn_started",
1339
1352
  "turn_context",
1340
1353
  "structured_event",
1354
+ "attachments_delivered",
1341
1355
  "turn_routed",
1342
1356
  "turn_completed",
1343
1357
  "turn_failed",
@@ -1608,6 +1622,29 @@ var messageHistoryEventTypes = [
1608
1622
  "message_updated",
1609
1623
  "message_handled"
1610
1624
  ];
1625
+ var HUMAN_INSTRUCTION_PLATFORMS = /* @__PURE__ */ new Set(["slack", "local", "web"]);
1626
+ function eventUnarchivesConversation(data) {
1627
+ if (data.type === "user_message") {
1628
+ const provenance = data.provenance;
1629
+ if (provenance.authority !== "instruction") return false;
1630
+ const platform = provenance.actor?.platform;
1631
+ return platform === void 0 || HUMAN_INSTRUCTION_PLATFORMS.has(platform);
1632
+ }
1633
+ if (data.type !== "message") {
1634
+ return false;
1635
+ }
1636
+ if (data.role !== "user") return false;
1637
+ const meta = data.meta;
1638
+ if (!meta) return true;
1639
+ if (typeof meta.eventType === "string" && meta.eventType.length > 0) {
1640
+ return false;
1641
+ }
1642
+ const author = meta.author;
1643
+ if (author && typeof author === "object" && !Array.isArray(author) && author.isBot === true) {
1644
+ return false;
1645
+ }
1646
+ return true;
1647
+ }
1611
1648
  function insertFromEvent(conversationId, seq, historyVersion, event, actorIdentityId) {
1612
1649
  const stripped = stripPayloadAuthorIdentityId(event.data);
1613
1650
  const { type, ...payload } = conversationEventDataSchema.parse(stripped);
@@ -1691,7 +1728,7 @@ var SqlConversationEventStore = class {
1691
1728
  newestCreatedAtMs,
1692
1729
  options
1693
1730
  );
1694
- if (options.activity !== "preserve") {
1731
+ if (options.activity !== "preserve" && pending.some((event) => eventUnarchivesConversation(event.data))) {
1695
1732
  await this.executor.db().update(juniorConversations).set({ archivedAt: null }).where(
1696
1733
  and6(
1697
1734
  eq6(juniorConversations.conversationId, conversationId),
@@ -1736,12 +1773,6 @@ var SqlConversationEventStore = class {
1736
1773
  const parsed = historyReplacementSchema.parse(replacement);
1737
1774
  await withConversationEventLock(this.executor, conversationId, async () => {
1738
1775
  await ensureConversationRow(this.executor, conversationId, Date.now());
1739
- await this.executor.db().update(juniorConversations).set({ archivedAt: null }).where(
1740
- and6(
1741
- eq6(juniorConversations.conversationId, conversationId),
1742
- isNotNull(juniorConversations.archivedAt)
1743
- )
1744
- );
1745
1776
  const cursor = await this.readCursor(conversationId);
1746
1777
  const historyVersion = (cursor.maxHistoryVersion ?? 0) + 1;
1747
1778
  await this.executor.db().insert(juniorConversationEvents).values(
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  FUNCTION_TIMEOUT_BUFFER_SECONDS,
3
3
  getChatConfig
4
- } from "./chunk-FAJ6SMEE.js";
4
+ } from "./chunk-J77DLAPE.js";
5
5
 
6
6
  // src/chat/runtime/request-deadline.ts
7
7
  import { AsyncLocalStorage } from "async_hooks";