@sentry/junior 0.192.0 → 0.194.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 (97) hide show
  1. package/dist/{agent-hooks-3JY76L5X.js → agent-hooks-IDX764FD.js} +11 -11
  2. package/dist/api/conversations/aggregate.d.ts +2 -0
  3. package/dist/api/conversations/list.d.ts +1 -1
  4. package/dist/api/conversations/projection.d.ts +1 -1
  5. package/dist/api/locations/detail.d.ts +1 -1
  6. package/dist/api/schema/conversation.d.ts +3 -3
  7. package/dist/api/schema/location.d.ts +1 -1
  8. package/dist/api/schema/person.d.ts +1 -1
  9. package/dist/api/schema/task.d.ts +71 -8
  10. package/dist/api/schema.d.ts +2 -2
  11. package/dist/api/schema.js +3 -1
  12. package/dist/api.js +106 -187
  13. package/dist/app.js +55 -83
  14. package/dist/{catalog-runtime-5JVLWXRY.js → catalog-runtime-MICXEBLK.js} +4 -4
  15. package/dist/chat/agent/prompt.d.ts +1 -1
  16. package/dist/chat/agent/resume.d.ts +2 -0
  17. package/dist/chat/agent-dispatch/types.d.ts +2 -1
  18. package/dist/chat/agent-dispatch/validation.d.ts +1 -1
  19. package/dist/chat/agent-invocations/types.d.ts +24 -28
  20. package/dist/chat/config.d.ts +1 -0
  21. package/dist/chat/conversations/history.d.ts +4 -2
  22. package/dist/chat/event-tasks/tool-support.d.ts +10 -1
  23. package/dist/chat/plugins/agent-hooks.d.ts +2 -2
  24. package/dist/chat/prompt.d.ts +4 -5
  25. package/dist/chat/services/turn-limit.d.ts +11 -1
  26. package/dist/chat/services/turn-session-routing.d.ts +4 -3
  27. package/dist/chat/slack/{source-link.d.ts → location-url.d.ts} +1 -1
  28. package/dist/chat/slack/tool-support/context.d.ts +3 -6
  29. package/dist/chat/source.d.ts +4 -6
  30. package/dist/chat/task-execution/checkpoint.d.ts +2 -0
  31. package/dist/chat/task-execution/turn-cursor.d.ts +3 -0
  32. package/dist/chat/tasks/execution-stats.d.ts +13 -1
  33. package/dist/chat/tools/delete-event-task.d.ts +1 -1
  34. package/dist/chat/tools/types.d.ts +10 -9
  35. package/dist/chat/tools/update-event-task.d.ts +1 -1
  36. package/dist/chat/usage.d.ts +4 -0
  37. package/dist/{chunk-YRWGJ5OO.js → chunk-2NL3Y47F.js} +5 -5
  38. package/dist/{chunk-BGLMT6KP.js → chunk-53IEEFFP.js} +3 -3
  39. package/dist/{chunk-PXUBRZBU.js → chunk-6H2MKVV5.js} +1 -1
  40. package/dist/{chunk-47JFLZSF.js → chunk-73JEAQRT.js} +4 -4
  41. package/dist/{chunk-6LX6KV5C.js → chunk-7ANA7PBB.js} +3 -3
  42. package/dist/{chunk-AKR6W7VV.js → chunk-ADEACKAH.js} +82 -69
  43. package/dist/{chunk-YE6DVM43.js → chunk-AWZS5SVX.js} +8 -8
  44. package/dist/{chunk-BUTAWPUV.js → chunk-CCTYK5RH.js} +37 -31
  45. package/dist/{chunk-RWBZZMW6.js → chunk-CFGBKPWQ.js} +3 -3
  46. package/dist/{chunk-G4E5WIRL.js → chunk-E53C73ML.js} +4 -4
  47. package/dist/{chunk-3UJSII43.js → chunk-ELCYG6UU.js} +3 -3
  48. package/dist/{chunk-SSR6YBWW.js → chunk-ENWIHU54.js} +11 -7
  49. package/dist/{chunk-4CCQZHD3.js → chunk-F2KSURTJ.js} +11 -11
  50. package/dist/{chunk-7XO7PTZE.js → chunk-G35QGPO2.js} +1 -1
  51. package/dist/{chunk-4B4DQGOM.js → chunk-G4RARFNT.js} +101 -66
  52. package/dist/{chunk-Z4DNJI5F.js → chunk-GY5SEFVL.js} +5 -5
  53. package/dist/{chunk-KR5F3QSP.js → chunk-H4DCWLTR.js} +8 -8
  54. package/dist/{chunk-ARSUYYQG.js → chunk-IME5OW4Y.js} +1 -1
  55. package/dist/{chunk-3O2NXVGB.js → chunk-INTBMGNX.js} +23 -25
  56. package/dist/{chunk-4WIA45WD.js → chunk-IOGDKPVU.js} +1 -1
  57. package/dist/{chunk-EYNUOZCN.js → chunk-JOI3DHML.js} +1 -1
  58. package/dist/{chunk-5V4BAUCH.js → chunk-KNIAWMBU.js} +1 -1
  59. package/dist/{chunk-ITTEDZGY.js → chunk-NPO24LAN.js} +32 -25
  60. package/dist/{chunk-SZ2O3CGS.js → chunk-NWWDFHXP.js} +1 -1
  61. package/dist/{chunk-VF3EDS7P.js → chunk-OEQOAONV.js} +60 -29
  62. package/dist/{chunk-PYVGXGKC.js → chunk-P2P6MUQ4.js} +2 -2
  63. package/dist/{chunk-PXP2M32M.js → chunk-QMEF4Z7R.js} +6 -7
  64. package/dist/{chunk-OBN7UEQJ.js → chunk-RFE7DCZK.js} +24 -2
  65. package/dist/{chunk-6FCKJDKS.js → chunk-S7GX44BU.js} +1 -1
  66. package/dist/{chunk-4Z7B5WVV.js → chunk-U76RWMFR.js} +4 -2
  67. package/dist/{chunk-LRTEMMCZ.js → chunk-V4HXV5MY.js} +1 -1
  68. package/dist/{chunk-MB2CTEPD.js → chunk-VOB2DKO6.js} +174 -34
  69. package/dist/{chunk-EIYOABL4.js → chunk-WMJS5DDV.js} +12 -8
  70. package/dist/{chunk-FGYWKKTJ.js → chunk-WWXJUURQ.js} +1 -1
  71. package/dist/{chunk-3ADPXQBL.js → chunk-X76JVHQ4.js} +1 -1
  72. package/dist/{chunk-IBO4YFFZ.js → chunk-XLWZRHX5.js} +1 -1
  73. package/dist/{chunk-H5Q2T5VC.js → chunk-XND3J6AT.js} +1 -1
  74. package/dist/{chunk-4AFSQJD6.js → chunk-XRDSML3K.js} +3 -4
  75. package/dist/{chunk-EYIMZY5O.js → chunk-YSLIB7ER.js} +18 -3
  76. package/dist/cli/chat.js +33 -33
  77. package/dist/cli/check.js +5 -5
  78. package/dist/cli/plugins.js +12 -12
  79. package/dist/cli/snapshot-create.js +9 -9
  80. package/dist/cli/upgrade.js +6 -6
  81. package/dist/db/schema/agent-invocations.d.ts +16 -0
  82. package/dist/db/schema.d.ts +16 -0
  83. package/dist/{db-LRM6AP66.js → db-3IEVINAY.js} +6 -6
  84. package/dist/instrumentation.js +3 -3
  85. package/dist/nitro.js +6 -6
  86. package/dist/{oauth-callback-server-BKCDVYVH.js → oauth-callback-server-N7L2BB4L.js} +29 -29
  87. package/dist/{runner-RUXGS3E6.js → runner-PTTZV3WU.js} +21 -21
  88. package/dist/{skills-DXP2RCJF.js → skills-POMWS2RR.js} +5 -5
  89. package/dist/spawn-R75MXXKE.js +42 -0
  90. package/dist/task-runner-OQLRHADB.js +36 -0
  91. package/dist/{validation-F4KYLIF2.js → validation-U6LOMXR7.js} +5 -5
  92. package/dist/version.js +1 -1
  93. package/dist/{work-UUNMNSML.js → work-FHA3BS4L.js} +21 -21
  94. package/dist/{worker-PMIJ5NLD.js → worker-GR4UNVVP.js} +10 -10
  95. package/package.json +5 -5
  96. package/dist/spawn-HH7GH7XT.js +0 -42
  97. package/dist/task-runner-H5I7R3LJ.js +0 -36
@@ -1,6 +1,16 @@
1
- /** Terminal failure raised when one agent turn exhausts its slice budget. */
1
+ /** Terminal failure when one turn uses too many execution slices. */
2
2
  export declare class TurnSliceLimitExceededError extends Error {
3
3
  constructor(maxSlices: number);
4
4
  }
5
+ /** Terminal failure when one turn uses too many tool calls. */
6
+ export declare class TurnToolCallLimitExceededError extends Error {
7
+ constructor(maxToolCalls: number);
8
+ }
9
+ /** True when a turn hit a hard execution limit, including one Error.cause wrap. */
10
+ export declare function isTurnExecutionLimitExceededError(error: unknown): boolean;
11
+ /** Stop the turn when its tool-call count is past the limit. */
12
+ export declare function assertTurnToolCallLimit(toolCallCount: number, maxToolCalls: number): void;
5
13
  /** Explain a terminal turn execution limit with actionable recovery guidance. */
6
14
  export declare function buildTurnLimitResponse(eventId: string): string;
15
+ /** User-facing reply for a thrown turn error. */
16
+ export declare function buildTurnErrorResponse(error: unknown, eventId: string): string;
@@ -5,18 +5,19 @@
5
5
  * parent reads through that relation. Later Turns and mailbox wakes use the
6
6
  * same Destination so tools stay consistent for the whole Conversation.
7
7
  */
8
- import type { Destination, Source } from "@sentry/junior-plugin-api";
8
+ import type { Destination } from "@sentry/junior-plugin-api";
9
9
  import type { ConversationStore } from "@/chat/conversations/store";
10
10
  import type { Location } from "@/chat/conversations/location";
11
+ import type { SessionSource } from "@/chat/source";
11
12
  export interface TurnSessionRouting {
12
13
  destination: Destination;
13
14
  location?: Location;
14
15
  /** Present when the conversation already stores a session source. */
15
- source?: Source;
16
+ source?: SessionSource;
16
17
  }
17
18
  /** Conversation data with a required Destination and Source. */
18
19
  export type RequiredTurnSessionRouting = TurnSessionRouting & {
19
- source: Source;
20
+ source: SessionSource;
20
21
  };
21
22
  /**
22
23
  * Resolve the Conversation Location, Destination, and session Source.
@@ -4,7 +4,7 @@ export declare function parseSlackTeamDomain(value: unknown): string | undefined
4
4
  * Build a direct Slack archive URL for a thread when the workspace domain is
5
5
  * known. Omits a link rather than falling back to `app_redirect`.
6
6
  */
7
- export declare function buildSlackSourceUrl(args: {
7
+ export declare function buildSlackLocationUrl(args: {
8
8
  channelId: string;
9
9
  teamDomain: string;
10
10
  threadTs: string;
@@ -1,18 +1,15 @@
1
1
  import type { ToolRuntimeContext } from "@/chat/tools/types";
2
- import type { SlackDestination } from "@sentry/junior-plugin-api";
3
- import type { SlackSource } from "@sentry/junior-plugin-api";
4
2
  import type { SlackActor } from "@/chat/actor";
5
3
  import { type SlackChannelId, type SlackTeamId } from "@/chat/slack/ids";
6
4
  import { type SlackMessageTs } from "@/chat/slack/timestamp";
7
5
  export interface SlackToolContext {
8
- destination: SlackDestination;
9
- source: SlackSource;
10
6
  actor?: SlackActor;
11
7
  destinationChannelId: SlackChannelId;
8
+ locationChannelId: SlackChannelId;
9
+ messageChannelId?: SlackChannelId;
12
10
  messageTs?: SlackMessageTs;
13
- sourceChannelId: SlackChannelId;
14
11
  teamId: SlackTeamId;
15
12
  threadTs?: SlackMessageTs;
16
13
  }
17
- /** Resolve Slack-specific tool context from the active source/destination/actor. */
14
+ /** Resolve Slack tool context from the Conversation Location. */
18
15
  export declare function getSlackToolContext(context: ToolRuntimeContext): SlackToolContext | undefined;
@@ -1,5 +1,5 @@
1
1
  import { type Source } from "@sentry/junior-plugin-api";
2
- /** Source coordinates reduced to the stable locator for one conversation. */
2
+ /** Legacy provider Source fields stored on a Conversation. */
3
3
  export type SessionSource = Extract<Source, {
4
4
  kind: "web";
5
5
  }> | Extract<Source, {
@@ -8,11 +8,9 @@ export type SessionSource = Extract<Source, {
8
8
  kind: "slack";
9
9
  }>, "messageTs">;
10
10
  /**
11
- * Normalize a turn Source into the session-stable locator persisted on a
12
- * conversation. Drops per-message timestamps. Threaded Slack turns keep their
13
- * thread anchor; channel-level turns (scheduled/event dispatch) keep the
14
- * channel locator without inventing a threadTs.
11
+ * Normalize a Turn Source into legacy provider fields stored on a Conversation.
12
+ * System Sources do not contain a Conversation Location.
15
13
  */
16
14
  export declare function normalizeSessionSource(value: Source | undefined): SessionSource | undefined;
17
- /** Parse a serialized Source into the stable locator stored on a conversation. */
15
+ /** Parse a serialized Source into legacy provider fields stored on a Conversation. */
18
16
  export declare function parseSessionSource(value: unknown): SessionSource | undefined;
@@ -49,6 +49,8 @@ interface TurnCheckpointWrite {
49
49
  source?: Source;
50
50
  surface?: AgentTurnSurface;
51
51
  turnStartMessageIndex?: number;
52
+ /** Tool calls charged to this turn; survives history replacement. */
53
+ cumulativeToolCallCount?: number;
52
54
  trailingMessageProvenance?: ConversationMessageProvenance[];
53
55
  turnContexts?: PluginTurnContext[];
54
56
  durationMs?: number;
@@ -32,6 +32,8 @@ export interface TurnRecord {
32
32
  version: number;
33
33
  conversationId: string;
34
34
  cumulativeDurationMs: number;
35
+ /** Tool calls charged to this turn; survives history replacement. */
36
+ cumulativeToolCallCount?: number;
35
37
  cumulativeUsage?: AgentTurnUsage;
36
38
  dispatchId?: string;
37
39
  dispatchOutcome?: AgentDispatchOutcome;
@@ -86,6 +88,7 @@ export declare function upsertTurnRecord(args: {
86
88
  channelName?: string;
87
89
  conversationId: string;
88
90
  cumulativeDurationMs?: number;
91
+ cumulativeToolCallCount?: number;
89
92
  cumulativeUsage?: AgentTurnUsage;
90
93
  destination?: Destination;
91
94
  dispatchId?: string;
@@ -3,22 +3,34 @@ export declare const TASK_EXECUTION_TYPES: readonly ["scheduled", "event"];
3
3
  export declare const TASK_EXECUTION_STATUSES: readonly ["blocked", "completed", "failed"];
4
4
  export type TaskExecutionType = (typeof TASK_EXECUTION_TYPES)[number];
5
5
  export type TaskExecutionDay = {
6
+ costUsd: number;
6
7
  date: string;
7
8
  event: number;
8
9
  scheduled: number;
9
10
  };
11
+ export type TaskRunWindows = {
12
+ 1: number;
13
+ 7: number;
14
+ 30: number;
15
+ 90: number;
16
+ };
10
17
  export type TaskExecutionSummary = {
11
18
  lastConversationId?: string;
12
19
  lastExecutedAtMs?: number;
13
- runsLast7Days: number;
20
+ runs: TaskRunWindows;
14
21
  totalRuns: number;
15
22
  };
23
+ /** Empty run windows for tasks with no execution history. */
24
+ export declare function emptyTaskRunWindows(): TaskRunWindows;
16
25
  export type TaskExecutionRecord = {
17
26
  conversationId?: string;
27
+ costUsd?: number;
28
+ durationMs?: number;
18
29
  executedAt: string;
19
30
  executionId: string;
20
31
  status: TaskExecutionStatus;
21
32
  title?: string;
33
+ totalTokens?: number;
22
34
  };
23
35
  export type TaskRunRecord = TaskExecutionRecord & {
24
36
  kind: TaskExecutionType;
@@ -1,6 +1,6 @@
1
1
  import type { ResourceEventCatalog } from "@/chat/resource-events/catalog";
2
2
  import type { ToolRuntimeContext } from "@/chat/tools/types";
3
- /** Create the core tool that deletes an event task in this destination. */
3
+ /** Create the core tool that deletes an event task. */
4
4
  export declare function createDeleteEventTaskTool(context: ToolRuntimeContext, catalog: ResourceEventCatalog): Omit<import("./definition").AnyToolDefinition, "inputSchema" | "outputSchema" | "prepareArguments" | "execute"> & {
5
5
  inputSchema: import("./definition").JsonSchemaObject;
6
6
  outputSchema: import("./definition").JsonSchemaObject;
@@ -1,5 +1,5 @@
1
1
  import type { FileUpload } from "chat";
2
- import type { WebSource, ResourceEventSource, Destination, Identity, LocalDestination, LocalSource, PluginEgress, SlackDestination, SlackSource, Source, SystemActor, User } from "@sentry/junior-plugin-api";
2
+ import type { AgentInvocationSource, EventTaskSource, WebSource, ResourceEventSource, Destination, Identity, Location, LocalDestination, LocalSource, PluginDispatchSource, PluginEgress, SlackDestination, SlackSource, Source, ScheduledTaskSource, User } from "@sentry/junior-plugin-api";
3
3
  import type { McpToolManager } from "@/chat/mcp/tool-manager";
4
4
  import type { SandboxWorkspace } from "@/chat/sandbox/workspace";
5
5
  import type { AgentTurnSurface } from "@/chat/task-execution/checkpoint";
@@ -12,6 +12,7 @@ import type { GeneratedArtifactFileRef } from "@/chat/tools/sandbox/file-uploads
12
12
  import type { SpawnAgent } from "@/chat/agent/types";
13
13
  import type { AttachmentStorage } from "@/chat/attachments/storage";
14
14
  import type { Workspace } from "@/chat/workspaces/types";
15
+ import type { ConversationPrivacy } from "@/chat/conversation-privacy";
15
16
  interface HandoffControl {
16
17
  /** Non-empty catalog of configured targets. */
17
18
  profiles: readonly [ModelProfile, ...ModelProfile[]];
@@ -65,7 +66,11 @@ interface BaseToolRuntimeContext {
65
66
  */
66
67
  conversationId: string;
67
68
  /** Location associated with this Conversation. */
69
+ location?: Location;
70
+ /** Legacy Location identity used by memory and plugin contexts. */
68
71
  locationId?: string;
72
+ /** Stored Conversation visibility used by tools. */
73
+ conversationPrivacy?: ConversationPrivacy;
69
74
  /** Runtime-owned default outbound destination for this invocation. */
70
75
  destination: Destination;
71
76
  actor?: Actor;
@@ -99,24 +104,20 @@ interface LocalToolRuntimeContext extends BaseToolRuntimeContext {
99
104
  destination: LocalDestination;
100
105
  actor?: LocalActor;
101
106
  source: LocalSource;
102
- slack?: never;
103
107
  slackActionToken?: never;
104
108
  }
105
109
  interface WebToolRuntimeContext extends BaseToolRuntimeContext {
106
110
  destination: Destination;
107
111
  actor?: WebActor;
108
112
  source: WebSource;
109
- slack?: never;
110
113
  slackActionToken?: never;
111
114
  }
112
- interface ResourceEventToolRuntimeContext extends BaseToolRuntimeContext {
115
+ export type ToolRuntimeContext = LocalToolRuntimeContext | SlackToolRuntimeContext | WebToolRuntimeContext | (BaseToolRuntimeContext & {
113
116
  destination: Destination;
114
- actor?: SystemActor;
115
- source: ResourceEventSource;
116
- slack?: never;
117
+ actor?: Actor;
118
+ source: AgentInvocationSource | EventTaskSource | PluginDispatchSource | ResourceEventSource | ScheduledTaskSource;
117
119
  slackActionToken?: never;
118
- }
119
- export type ToolRuntimeContext = LocalToolRuntimeContext | ResourceEventToolRuntimeContext | SlackToolRuntimeContext | WebToolRuntimeContext;
120
+ });
120
121
  export interface ToolState {
121
122
  getOperationResult: <T>(operationKey: string) => T | undefined;
122
123
  setOperationResult: (operationKey: string, result: unknown) => void;
@@ -1,6 +1,6 @@
1
1
  import { type ResourceEventCatalog } from "@/chat/resource-events/catalog";
2
2
  import type { ToolRuntimeContext } from "@/chat/tools/types";
3
- /** Create the core tool that updates an event task in this destination. */
3
+ /** Create the core tool that updates an event task. */
4
4
  export declare function createUpdateEventTaskTool(context: ToolRuntimeContext, catalog: ResourceEventCatalog): Omit<import("./definition").AnyToolDefinition, "inputSchema" | "outputSchema" | "prepareArguments" | "execute"> & {
5
5
  inputSchema: import("./definition").JsonSchemaObject;
6
6
  outputSchema: import("./definition").JsonSchemaObject;
@@ -34,5 +34,9 @@ export declare const agentTurnUsageSchema: import("zod").ZodObject<{
34
34
  export type AgentTurnUsage = Usage;
35
35
  /** Return whether any token counter is present on a usage record. */
36
36
  export declare function hasAgentTurnUsage(usage: AgentTurnUsage | undefined): usage is AgentTurnUsage;
37
+ /** Estimated total USD cost from one usage record, when any cost field is present. */
38
+ export declare function agentTurnCostUsd(usage: AgentTurnUsage | undefined): number | undefined;
39
+ /** Total token count from one usage record, preferring component counters. */
40
+ export declare function agentTurnTotalTokens(usage: AgentTurnUsage | undefined): number | undefined;
37
41
  /** Aggregate token usage across slices without double-counting provider totals. */
38
42
  export declare function addAgentTurnUsage(...usages: Array<AgentTurnUsage | undefined>): AgentTurnUsage | undefined;
@@ -2,16 +2,16 @@ import {
2
2
  coerceThreadConversationState,
3
3
  getPersistedThreadState,
4
4
  persistThreadStateById
5
- } from "./chunk-Z4DNJI5F.js";
5
+ } from "./chunk-GY5SEFVL.js";
6
6
  import {
7
7
  clearPendingAuth,
8
8
  markTurnClosed,
9
9
  markTurnCompleted
10
- } from "./chunk-7XO7PTZE.js";
10
+ } from "./chunk-G35QGPO2.js";
11
11
  import {
12
12
  hydrateConversationMessages,
13
13
  markConversationMessage
14
- } from "./chunk-VF3EDS7P.js";
14
+ } from "./chunk-OEQOAONV.js";
15
15
  import {
16
16
  buildDeterministicTurnId
17
17
  } from "./chunk-DA2KGZZI.js";
@@ -20,13 +20,13 @@ import {
20
20
  findProviderError,
21
21
  getProviderErrorAttributes,
22
22
  getProviderErrorUserMessage
23
- } from "./chunk-4Z7B5WVV.js";
23
+ } from "./chunk-U76RWMFR.js";
24
24
  import {
25
25
  parseSlackMessageTs
26
26
  } from "./chunk-N7TMSOZH.js";
27
27
  import {
28
28
  buildTurnFailureResponse
29
- } from "./chunk-3ADPXQBL.js";
29
+ } from "./chunk-X76JVHQ4.js";
30
30
 
31
31
  // src/chat/runtime/delivered-turn-state.ts
32
32
  function buildDeliveredTurnStatePatch(args) {
@@ -1,12 +1,12 @@
1
1
  import {
2
2
  ConversationTurnLifecycleService
3
- } from "./chunk-PXUBRZBU.js";
3
+ } from "./chunk-6H2MKVV5.js";
4
4
  import {
5
5
  runAgentWithTimeout
6
- } from "./chunk-SSR6YBWW.js";
6
+ } from "./chunk-ENWIHU54.js";
7
7
  import {
8
8
  getConversationEventStore
9
- } from "./chunk-AKR6W7VV.js";
9
+ } from "./chunk-ADEACKAH.js";
10
10
 
11
11
  // src/chat/runtime/turn-execution.ts
12
12
  var AgentRunError = class extends Error {
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  getConversationEventStore
3
- } from "./chunk-AKR6W7VV.js";
3
+ } from "./chunk-ADEACKAH.js";
4
4
 
5
5
  // src/chat/conversations/turn-lifecycle.ts
6
6
  var ConversationTurnLifecycleService = class {
@@ -19,23 +19,23 @@ import {
19
19
  releaseConversationWork,
20
20
  requestAnotherSlice,
21
21
  startConversationWork
22
- } from "./chunk-G4E5WIRL.js";
22
+ } from "./chunk-E53C73ML.js";
23
23
  import {
24
24
  getTurnRequestDeadline
25
- } from "./chunk-SZ2O3CGS.js";
25
+ } from "./chunk-NWWDFHXP.js";
26
26
  import {
27
27
  ConversationQueueMessageRejectedError
28
28
  } from "./chunk-JAL3CH4G.js";
29
29
  import {
30
30
  getChatConfig,
31
31
  isProviderRetryError
32
- } from "./chunk-4Z7B5WVV.js";
32
+ } from "./chunk-U76RWMFR.js";
33
33
  import {
34
34
  logException,
35
35
  logInfo,
36
36
  logWarn,
37
37
  withLogContext
38
- } from "./chunk-3ADPXQBL.js";
38
+ } from "./chunk-X76JVHQ4.js";
39
39
 
40
40
  // src/chat/task-execution/worker.ts
41
41
  var CONVERSATION_WORK_DEFER_DELAY_MS = 15e3;
@@ -1,13 +1,13 @@
1
1
  import {
2
2
  toOptionalTrimmed
3
- } from "./chunk-4Z7B5WVV.js";
3
+ } from "./chunk-U76RWMFR.js";
4
4
  import {
5
5
  pluginCatalogRuntime
6
- } from "./chunk-FGYWKKTJ.js";
6
+ } from "./chunk-WWXJUURQ.js";
7
7
  import {
8
8
  setSpanAttributes,
9
9
  setSpanStatus
10
- } from "./chunk-3ADPXQBL.js";
10
+ } from "./chunk-X76JVHQ4.js";
11
11
 
12
12
  // src/chat/sandbox/paths.ts
13
13
  function normalizeWorkspaceRoot(input) {
@@ -8,7 +8,7 @@ import {
8
8
  juniorConversations,
9
9
  juniorIdentities,
10
10
  juniorUsers
11
- } from "./chunk-IBO4YFFZ.js";
11
+ } from "./chunk-XLWZRHX5.js";
12
12
  import {
13
13
  conversationEventDataSchema,
14
14
  decodeStoredConversationEvent,
@@ -20,7 +20,7 @@ import {
20
20
  } from "./chunk-VFUK3X5B.js";
21
21
  import {
22
22
  getChatConfig
23
- } from "./chunk-4Z7B5WVV.js";
23
+ } from "./chunk-U76RWMFR.js";
24
24
  import {
25
25
  parseActorUserId,
26
26
  parseSlackChannelReferenceId,
@@ -28,7 +28,7 @@ import {
28
28
  } from "./chunk-N7TMSOZH.js";
29
29
  import {
30
30
  normalizeIdentityEmail
31
- } from "./chunk-3ADPXQBL.js";
31
+ } from "./chunk-X76JVHQ4.js";
32
32
 
33
33
  // src/chat/conversations/sql/store.ts
34
34
  import { randomUUID as randomUUID2 } from "crypto";
@@ -271,7 +271,7 @@ function normalizeSessionSource(value) {
271
271
  conversationId: value.conversationId
272
272
  };
273
273
  }
274
- if (value.kind === "resource_event") {
274
+ if (value.kind === "resource_event" || value.kind === "scheduled_task" || value.kind === "event_task" || value.kind === "plugin_dispatch" || value.kind === "agent_invocation") {
275
275
  return void 0;
276
276
  }
277
277
  const threadTs = value.threadTs?.trim();
@@ -450,7 +450,9 @@ function locationForWrite(args) {
450
450
  }
451
451
  function locationFromRow(value, row, sessionSource) {
452
452
  if (value !== void 0 && value !== null) {
453
- return locationSchema.parse(value);
453
+ const location = locationSchema.parse(value);
454
+ const slackSource2 = !location.threadTs && sessionSource?.kind === "slack" && sessionSource.teamId === location.teamId && sessionSource.channelId === location.channelId ? sessionSource : void 0;
455
+ return slackSource2?.threadTs ? { ...location, threadTs: slackSource2.threadTs } : location;
454
456
  }
455
457
  if (!row || row.provider === "local") {
456
458
  return void 0;
@@ -1397,76 +1399,84 @@ var SqlConversationEventStore = class {
1397
1399
  (event) => newConversationEventSchema.parse(event)
1398
1400
  );
1399
1401
  if (parsed.length === 0) {
1400
- return;
1402
+ return [];
1401
1403
  }
1402
- await withConversationEventLock(this.executor, conversationId, async () => {
1403
- const existingKeys = parsed.map((event) => event.idempotencyKey).filter((key) => key !== void 0);
1404
- const persistedKeys = existingKeys.length === 0 ? /* @__PURE__ */ new Set() : new Set(
1405
- (await this.executor.db().select({ key: juniorConversationEvents.idempotencyKey }).from(juniorConversationEvents).where(
1406
- and6(
1407
- eq6(
1408
- juniorConversationEvents.conversationId,
1409
- conversationId
1410
- ),
1411
- inArray2(
1412
- juniorConversationEvents.idempotencyKey,
1413
- existingKeys
1404
+ return withConversationEventLock(
1405
+ this.executor,
1406
+ conversationId,
1407
+ async () => {
1408
+ const existingKeys = parsed.map((event) => event.idempotencyKey).filter((key) => key !== void 0);
1409
+ const persistedKeys = existingKeys.length === 0 ? /* @__PURE__ */ new Set() : new Set(
1410
+ (await this.executor.db().select({ key: juniorConversationEvents.idempotencyKey }).from(juniorConversationEvents).where(
1411
+ and6(
1412
+ eq6(
1413
+ juniorConversationEvents.conversationId,
1414
+ conversationId
1415
+ ),
1416
+ inArray2(
1417
+ juniorConversationEvents.idempotencyKey,
1418
+ existingKeys
1419
+ )
1414
1420
  )
1415
- )
1416
- )).flatMap((row) => row.key ? [row.key] : [])
1417
- );
1418
- const acceptedKeys = new Set(persistedKeys);
1419
- const pending = parsed.filter((event) => {
1420
- if (event.idempotencyKey === void 0) return true;
1421
- if (acceptedKeys.has(event.idempotencyKey)) return false;
1422
- acceptedKeys.add(event.idempotencyKey);
1423
- return true;
1424
- });
1425
- if (pending.length === 0) {
1426
- return;
1427
- }
1428
- const newestCreatedAtMs = Math.max(
1429
- ...pending.map((event) => event.createdAtMs)
1430
- );
1431
- await ensureConversationRow(
1432
- this.executor,
1433
- conversationId,
1434
- newestCreatedAtMs,
1435
- options
1436
- );
1437
- const cursor = await this.readCursor(conversationId);
1438
- const historyVersion = cursor.maxHistoryVersion ?? 0;
1439
- let seq = cursor.nextSeq;
1440
- const rows = [];
1441
- for (const event of pending) {
1442
- const actorIdentityId = await resolveEventActorIdentityId(
1443
- this.executor,
1444
- {
1445
- conversationId,
1446
- data: event.data,
1447
- nowMs: event.createdAtMs
1448
- }
1421
+ )).flatMap((row) => row.key ? [row.key] : [])
1449
1422
  );
1450
- rows.push(
1451
- insertFromEvent(
1452
- conversationId,
1453
- seq++,
1454
- historyVersion,
1455
- event,
1456
- actorIdentityId
1457
- )
1423
+ const acceptedKeys = new Set(persistedKeys);
1424
+ const pending = parsed.filter((event) => {
1425
+ if (event.idempotencyKey === void 0) return true;
1426
+ if (acceptedKeys.has(event.idempotencyKey)) return false;
1427
+ acceptedKeys.add(event.idempotencyKey);
1428
+ return true;
1429
+ });
1430
+ if (pending.length === 0) {
1431
+ return [];
1432
+ }
1433
+ const newestCreatedAtMs = Math.max(
1434
+ ...pending.map((event) => event.createdAtMs)
1458
1435
  );
1459
- if (actorIdentityId) {
1460
- await recordConversationParticipant(this.executor, {
1461
- actorIdentityId,
1462
- conversationId,
1463
- atMs: event.createdAtMs,
1464
- restoreArchive: eventUnarchivesConversation(event.data)
1465
- });
1436
+ await ensureConversationRow(
1437
+ this.executor,
1438
+ conversationId,
1439
+ newestCreatedAtMs,
1440
+ options
1441
+ );
1442
+ const cursor = await this.readCursor(conversationId);
1443
+ const historyVersion = cursor.maxHistoryVersion ?? 0;
1444
+ let seq = cursor.nextSeq;
1445
+ const rows = [];
1446
+ for (const event of pending) {
1447
+ const actorIdentityId = await resolveEventActorIdentityId(
1448
+ this.executor,
1449
+ {
1450
+ conversationId,
1451
+ data: event.data,
1452
+ nowMs: event.createdAtMs
1453
+ }
1454
+ );
1455
+ rows.push(
1456
+ insertFromEvent(
1457
+ conversationId,
1458
+ seq++,
1459
+ historyVersion,
1460
+ event,
1461
+ actorIdentityId
1462
+ )
1463
+ );
1464
+ if (actorIdentityId) {
1465
+ await recordConversationParticipant(this.executor, {
1466
+ actorIdentityId,
1467
+ conversationId,
1468
+ atMs: event.createdAtMs,
1469
+ restoreArchive: eventUnarchivesConversation(event.data)
1470
+ });
1471
+ }
1466
1472
  }
1473
+ await this.executor.db().insert(juniorConversationEvents).values(rows);
1474
+ return rows.map((row) => ({
1475
+ seq: row.seq,
1476
+ historyVersion: row.historyVersion
1477
+ }));
1467
1478
  }
1468
- await this.executor.db().insert(juniorConversationEvents).values(rows);
1469
- });
1479
+ );
1470
1480
  }
1471
1481
  async replaceHistory(conversationId, replacement) {
1472
1482
  const parsed = historyReplacementSchema.parse(replacement);
@@ -1484,6 +1494,9 @@ var SqlConversationEventStore = class {
1484
1494
  );
1485
1495
  });
1486
1496
  }
1497
+ async loadCurrentHistoryVersion(conversationId) {
1498
+ return (await this.readCursor(conversationId)).maxHistoryVersion ?? 0;
1499
+ }
1487
1500
  async loadCurrentHistory(conversationId) {
1488
1501
  const cursor = await this.readCursor(conversationId);
1489
1502
  if (cursor.maxHistoryVersion === null) {
@@ -1,32 +1,32 @@
1
1
  import {
2
2
  resolveBaseUrl
3
- } from "./chunk-SSR6YBWW.js";
3
+ } from "./chunk-ENWIHU54.js";
4
4
  import {
5
5
  createPluginLogger,
6
6
  getPlugins,
7
7
  getSlackClient,
8
8
  withSlackRetries
9
- } from "./chunk-BUTAWPUV.js";
9
+ } from "./chunk-CCTYK5RH.js";
10
10
  import {
11
11
  getDb,
12
12
  parseDestination
13
- } from "./chunk-AKR6W7VV.js";
13
+ } from "./chunk-ADEACKAH.js";
14
14
  import {
15
15
  sleep
16
- } from "./chunk-6LX6KV5C.js";
16
+ } from "./chunk-7ANA7PBB.js";
17
17
  import {
18
18
  acquireActiveLock,
19
19
  getStateAdapter
20
- } from "./chunk-LRTEMMCZ.js";
20
+ } from "./chunk-V4HXV5MY.js";
21
21
  import {
22
22
  pluginCatalogRuntime
23
- } from "./chunk-FGYWKKTJ.js";
23
+ } from "./chunk-WWXJUURQ.js";
24
24
  import {
25
25
  fetchWithBoundedOAuthErrorBodies
26
- } from "./chunk-6FCKJDKS.js";
26
+ } from "./chunk-S7GX44BU.js";
27
27
  import {
28
28
  isRecord
29
- } from "./chunk-3ADPXQBL.js";
29
+ } from "./chunk-X76JVHQ4.js";
30
30
 
31
31
  // src/chat/capabilities/router.ts
32
32
  var ProviderCredentialRouter = class {