@sentry/junior 0.88.0 → 0.90.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 (158) hide show
  1. package/README.md +16 -5
  2. package/dist/{agent-hooks-RIJ5TSWP.js → agent-hooks-MXAF7RQL.js} +10 -10
  3. package/dist/api/people/list.js +8 -8
  4. package/dist/api/people/profile.js +8 -8
  5. package/dist/api-reference.d.ts +1 -1
  6. package/dist/app.js +716 -732
  7. package/dist/{catalog-runtime-MW7XERSU.js → catalog-runtime-DXE6NXHT.js} +5 -5
  8. package/dist/chat/agent/index.d.ts +4 -0
  9. package/dist/chat/agent/prompt.d.ts +78 -0
  10. package/dist/chat/{respond.d.ts → agent/request.d.ts} +98 -55
  11. package/dist/chat/agent/resume.d.ts +65 -0
  12. package/dist/chat/agent/sandbox.d.ts +15 -0
  13. package/dist/chat/agent/session.d.ts +20 -0
  14. package/dist/chat/agent/skills.d.ts +26 -0
  15. package/dist/chat/agent/tools.d.ts +78 -0
  16. package/dist/chat/agent-dispatch/runner.d.ts +3 -5
  17. package/dist/chat/app/production.d.ts +3 -1
  18. package/dist/chat/app/services.d.ts +1 -4
  19. package/dist/chat/logging.d.ts +2 -0
  20. package/dist/chat/mcp/tool-manager.d.ts +1 -6
  21. package/dist/chat/pi/messages.d.ts +18 -2
  22. package/dist/chat/pi/transcript.d.ts +31 -0
  23. package/dist/chat/plugins/agent-hooks.d.ts +2 -2
  24. package/dist/chat/prompt.d.ts +1 -1
  25. package/dist/chat/runtime/agent-continue-runner.d.ts +5 -5
  26. package/dist/chat/runtime/agent-run-outcome.d.ts +21 -0
  27. package/dist/chat/runtime/agent-runner.d.ts +11 -0
  28. package/dist/chat/runtime/delivered-turn-state.d.ts +2 -2
  29. package/dist/chat/runtime/generated-artifacts.d.ts +16 -0
  30. package/dist/chat/runtime/reply-executor.d.ts +2 -2
  31. package/dist/chat/runtime/slack-resume.d.ts +21 -12
  32. package/dist/chat/runtime/turn.d.ts +5 -39
  33. package/dist/chat/services/reply-delivery-plan.d.ts +0 -8
  34. package/dist/chat/services/turn-failure-response.d.ts +4 -4
  35. package/dist/chat/services/turn-result.d.ts +4 -7
  36. package/dist/chat/slack/channel.d.ts +9 -5
  37. package/dist/chat/slack/client.d.ts +3 -1
  38. package/dist/chat/slack/context.d.ts +17 -5
  39. package/dist/chat/slack/id-param.d.ts +25 -0
  40. package/dist/chat/slack/ids.d.ts +18 -4
  41. package/dist/chat/slack/outbound.d.ts +16 -0
  42. package/dist/chat/slack/output.d.ts +3 -3
  43. package/dist/chat/slack/reply.d.ts +4 -7
  44. package/dist/chat/slack/timestamp-param.d.ts +25 -0
  45. package/dist/chat/slack/tools/canvas/context.d.ts +18 -0
  46. package/dist/chat/slack/tools/canvas/create.d.ts +4 -0
  47. package/dist/chat/slack/tools/canvas/edit.d.ts +3 -0
  48. package/dist/chat/slack/tools/canvas/read.d.ts +6 -0
  49. package/dist/chat/slack/tools/canvas/write.d.ts +3 -0
  50. package/dist/chat/{tools/slack → slack/tools}/channel-access.d.ts +4 -3
  51. package/dist/chat/{tools → slack/tools}/channel-capabilities.d.ts +2 -0
  52. package/dist/chat/slack/tools/channel-list-messages.d.ts +3 -0
  53. package/dist/chat/{tools/slack → slack/tools}/context.d.ts +5 -4
  54. package/dist/chat/slack/tools/list/add-items.d.ts +3 -0
  55. package/dist/chat/{tools/slack/lists.d.ts → slack/tools/list/api.d.ts} +2 -1
  56. package/dist/chat/slack/tools/list/create.d.ts +3 -0
  57. package/dist/chat/slack/tools/list/get-items.d.ts +3 -0
  58. package/dist/chat/slack/tools/list/update-item.d.ts +3 -0
  59. package/dist/chat/slack/tools/message-add-reaction.d.ts +4 -0
  60. package/dist/chat/slack/tools/send-message.d.ts +11 -0
  61. package/dist/chat/{tools/slack → slack/tools}/slack-message-url.d.ts +5 -5
  62. package/dist/chat/slack/tools/thread-read.d.ts +6 -0
  63. package/dist/chat/slack/tools/user-lookup.d.ts +2 -0
  64. package/dist/chat/slack/users.d.ts +2 -1
  65. package/dist/chat/{services → slack}/vision-context.d.ts +4 -2
  66. package/dist/chat/state/session-log.d.ts +1 -1
  67. package/dist/chat/tool-exposure.d.ts +10 -0
  68. package/dist/chat/tool-support/catalog-tool-call.d.ts +10 -0
  69. package/dist/chat/{tools/execution → tool-support}/normalize-result.d.ts +4 -1
  70. package/dist/chat/{tools/agent-tools.d.ts → tool-support/pi-tool-adapter.d.ts} +3 -9
  71. package/dist/chat/tool-support/schema-summary.d.ts +2 -0
  72. package/dist/chat/{tools → tool-support}/skill/mcp-tool-summary.d.ts +0 -6
  73. package/dist/chat/tool-support/structured-result.d.ts +73 -0
  74. package/dist/chat/tool-support/text-range-result.d.ts +58 -0
  75. package/dist/chat/tool-support/tool-execution-report.d.ts +7 -0
  76. package/dist/chat/tool-support/zod-tool.d.ts +27 -0
  77. package/dist/chat/tools/advisor/tool.d.ts +9 -18
  78. package/dist/chat/tools/definition.d.ts +56 -9
  79. package/dist/chat/tools/execute-tool.d.ts +3 -0
  80. package/dist/chat/tools/index.d.ts +3 -2
  81. package/dist/chat/tools/resource-events.d.ts +3 -13
  82. package/dist/chat/tools/runtime/report-progress.d.ts +1 -3
  83. package/dist/chat/tools/sandbox/bash.d.ts +1 -4
  84. package/dist/chat/tools/sandbox/edit-file.d.ts +25 -7
  85. package/dist/chat/tools/sandbox/file-uploads.d.ts +30 -0
  86. package/dist/chat/tools/sandbox/file-utils.d.ts +10 -1
  87. package/dist/chat/tools/sandbox/find-files.d.ts +12 -11
  88. package/dist/chat/tools/sandbox/grep.d.ts +18 -12
  89. package/dist/chat/tools/sandbox/list-dir.d.ts +15 -7
  90. package/dist/chat/tools/sandbox/read-file.d.ts +2 -31
  91. package/dist/chat/tools/sandbox/write-file.d.ts +1 -4
  92. package/dist/chat/tools/search-tools.d.ts +4 -0
  93. package/dist/chat/tools/skill/call-mcp-tool.d.ts +1 -4
  94. package/dist/chat/tools/skill/load-skill.d.ts +4 -5
  95. package/dist/chat/tools/skill/search-mcp-tools.d.ts +1 -5
  96. package/dist/chat/tools/system-time.d.ts +1 -1
  97. package/dist/chat/tools/types.d.ts +15 -5
  98. package/dist/chat/tools/web/fetch-content.d.ts +4 -2
  99. package/dist/chat/tools/web/fetch-tool.d.ts +4 -4
  100. package/dist/chat/tools/web/image-generate.d.ts +4 -3
  101. package/dist/chat/tools/web/search.d.ts +1 -4
  102. package/dist/{chunk-4IXHIV37.js → chunk-2S7M37HY.js} +6 -8
  103. package/dist/{chunk-L7OHKDOX.js → chunk-3MPOMK3K.js} +58 -7
  104. package/dist/{chunk-V6XDCS3X.js → chunk-5GBUZI6M.js} +4 -4
  105. package/dist/{chunk-7ES37H6U.js → chunk-AN2437E3.js} +4 -4
  106. package/dist/chunk-AOISHLSF.js +747 -0
  107. package/dist/{chunk-NYJLQI42.js → chunk-BKSZL4QO.js} +11257 -11957
  108. package/dist/{chunk-XS6NLQPA.js → chunk-DACFZ5CI.js} +474 -33
  109. package/dist/chunk-GCWD2VHP.js +1216 -0
  110. package/dist/chunk-GHGPTPBL.js +53 -0
  111. package/dist/{chunk-S35CPNPT.js → chunk-HXL2ZV74.js} +40 -216
  112. package/dist/{chunk-PBV4ZIVM.js → chunk-IRRMABQD.js} +1 -1
  113. package/dist/{chunk-2DPZRS3B.js → chunk-IX76WFJV.js} +8 -8
  114. package/dist/{chunk-66NX7MNW.js → chunk-KC42JAAQ.js} +1 -1
  115. package/dist/chunk-LFLTJQVR.js +90 -0
  116. package/dist/{chunk-IATAYWFU.js → chunk-NW7AXDA5.js} +2 -2
  117. package/dist/{chunk-F22AM3OW.js → chunk-NYWPISSO.js} +1 -1
  118. package/dist/chunk-OB42YVAE.js +16 -0
  119. package/dist/chunk-ONFOWI2D.js +955 -0
  120. package/dist/chunk-PHZHJTCK.js +1062 -0
  121. package/dist/{chunk-6UPQ5GTJ.js → chunk-QCKGI74V.js} +7 -7
  122. package/dist/{chunk-YPAE5RH3.js → chunk-RS6ANWVT.js} +1 -1
  123. package/dist/{chunk-C5NCV3OB.js → chunk-TYUXD3FN.js} +1 -1
  124. package/dist/{chunk-KBFQXJL4.js → chunk-XP7F4LYB.js} +5 -7
  125. package/dist/{chunk-VMBZFPZM.js → chunk-ZUK7BL63.js} +187 -9
  126. package/dist/cli/chat.js +55 -40
  127. package/dist/cli/check.js +6 -6
  128. package/dist/cli/init.js +30 -36
  129. package/dist/cli/plugins.js +16 -16
  130. package/dist/cli/snapshot-warmup.js +9 -9
  131. package/dist/cli/upgrade.js +21 -21
  132. package/dist/db-CXI7PR5U.js +18 -0
  133. package/dist/handlers/agent-dispatch.d.ts +3 -3
  134. package/dist/handlers/mcp-oauth-callback.d.ts +3 -3
  135. package/dist/handlers/oauth-callback.d.ts +3 -3
  136. package/dist/instrumentation.js +6 -5
  137. package/dist/nitro.js +3 -7
  138. package/dist/reporting.js +23 -25
  139. package/dist/{runner-BCRF2FCI.js → runner-FKL3RAHA.js} +89 -77
  140. package/dist/{validation-FMJO3L5P.js → validation-I7GD2YWS.js} +6 -6
  141. package/package.json +6 -6
  142. package/dist/chat/respond-helpers.d.ts +0 -82
  143. package/dist/chat/services/attachment-claims.d.ts +0 -2
  144. package/dist/chat/services/channel-intent.d.ts +0 -2
  145. package/dist/chat/tools/sandbox/attach-file.d.ts +0 -7
  146. package/dist/chat/tools/slack/canvas-tools.d.ts +0 -30
  147. package/dist/chat/tools/slack/channel-list-messages.d.ts +0 -9
  148. package/dist/chat/tools/slack/channel-post-message.d.ts +0 -5
  149. package/dist/chat/tools/slack/list-tools.d.ts +0 -21
  150. package/dist/chat/tools/slack/message-add-reaction.d.ts +0 -5
  151. package/dist/chat/tools/slack/thread-read.d.ts +0 -12
  152. package/dist/chat/tools/slack/user-lookup.d.ts +0 -8
  153. package/dist/chunk-AHLSXMOU.js +0 -506
  154. package/dist/chunk-FTMXFBDC.js +0 -49
  155. package/dist/chunk-KBSLCOGE.js +0 -2226
  156. package/dist/chunk-KQKIA4CU.js +0 -186
  157. package/dist/db-37HOGLI7.js +0 -18
  158. /package/dist/chat/{tools/slack/canvases.d.ts → slack/tools/canvas/api.d.ts} +0 -0
@@ -1,11 +1,11 @@
1
1
  import {
2
2
  pluginCatalogRuntime
3
- } from "./chunk-KBFQXJL4.js";
4
- import "./chunk-KQKIA4CU.js";
5
- import "./chunk-6APU57E6.js";
6
- import "./chunk-VMBZFPZM.js";
7
- import "./chunk-FTMXFBDC.js";
3
+ } from "./chunk-XP7F4LYB.js";
4
+ import "./chunk-ZUK7BL63.js";
5
+ import "./chunk-OB42YVAE.js";
8
6
  import "./chunk-3DA7X2U3.js";
7
+ import "./chunk-6APU57E6.js";
8
+ import "./chunk-LFLTJQVR.js";
9
9
  import "./chunk-MLKGABMK.js";
10
10
  export {
11
11
  pluginCatalogRuntime
@@ -0,0 +1,4 @@
1
+ import type { AgentRunOutcome } from "@/chat/runtime/agent-run-outcome";
2
+ import { type AgentRunRequest } from "@/chat/agent/request";
3
+ /** Run a full agent turn: discover skills, execute tools, and return the assistant reply. */
4
+ export declare function executeAgentRun(request: AgentRunRequest): Promise<AgentRunOutcome>;
@@ -0,0 +1,78 @@
1
+ import type { PiMessage } from "@/chat/pi/messages";
2
+ import { type LogContext } from "@/chat/logging";
3
+ import { type ConversationPrivacy } from "@/chat/conversation-privacy";
4
+ import type { SkillInvocation, SkillMetadata } from "@/chat/skills";
5
+ import type { ActiveMcpCatalogSummary } from "@/chat/tool-support/skill/mcp-tool-summary";
6
+ import type { ToolRuntimeContext } from "@/chat/tools/types";
7
+ import type { AnyToolDefinition } from "@/chat/tools/definition";
8
+ import type { Requester } from "@/chat/requester";
9
+ import type { ThreadArtifactsState } from "@/chat/state/artifacts";
10
+ import type { AgentRunInput, AgentRunRouting, AgentRunSteeringMessage } from "@/chat/agent/request";
11
+ export type UserContentPart = {
12
+ type: "text";
13
+ text: string;
14
+ } | {
15
+ type: "image";
16
+ data: string;
17
+ mimeType: string;
18
+ };
19
+ /** User-turn content parts plus the plain-text blocks used for routing decisions. */
20
+ export interface PromptInput {
21
+ routerBlocks: string[];
22
+ userContentParts: UserContentPart[];
23
+ }
24
+ /** Fully assembled prompt state for one run slice. */
25
+ export interface PromptAssembly {
26
+ baseInstructions: string;
27
+ inputMessages: Array<{
28
+ role: string;
29
+ content: Record<string, unknown>[];
30
+ }>;
31
+ inputMessagesAttribute: string | undefined;
32
+ promptContentParts: UserContentPart[];
33
+ promptHistoryMessages: PiMessage[];
34
+ shouldPromptAgent: boolean;
35
+ }
36
+ /**
37
+ * Keep thread text separate from the canonical active task boundary.
38
+ */
39
+ export declare function buildUserTurnText(userInput: string, conversationContext?: string): string;
40
+ /** Encode a non-image attachment as base64 XML for the prompt. */
41
+ export declare function encodeNonImageAttachmentForPrompt(attachment: {
42
+ data: Buffer;
43
+ mediaType: string;
44
+ filename?: string;
45
+ }): string;
46
+ /** Redact image data from prompt content parts for observability. */
47
+ export declare function toObservablePromptPart(part: UserContentPart): Record<string, unknown>;
48
+ /** Build the prompt-facing user input, keeping router text aligned with Pi content. */
49
+ export declare function buildPromptInput(input: AgentRunInput): PromptInput;
50
+ /**
51
+ * Convert a mid-run user message into the Pi user message shape used for
52
+ * steering injection and parked-conversation session-log appends, so both
53
+ * paths store identical durable history.
54
+ */
55
+ export declare function buildSteeringPiMessage(message: AgentRunSteeringMessage): PiMessage;
56
+ /** Assemble prompt history, instructions, and telemetry input for one slice. */
57
+ export declare function assemblePrompt(args: {
58
+ activeMcpCatalogs: ActiveMcpCatalogSummary[];
59
+ actorRequester?: Requester;
60
+ artifactState?: ThreadArtifactsState;
61
+ availableSkills: SkillMetadata[];
62
+ configurationValues: Record<string, unknown>;
63
+ conversationPrivacy?: ConversationPrivacy;
64
+ existingSessionPiMessages?: PiMessage[];
65
+ existingTurnStartMessageIndex?: number;
66
+ invocation: SkillInvocation | null;
67
+ priorPiMessages?: PiMessage[];
68
+ resumedFromSessionRecord: boolean;
69
+ routing: AgentRunRouting;
70
+ spanContext: LogContext;
71
+ toolGuidance: Array<{
72
+ name: string;
73
+ promptGuidelines: AnyToolDefinition["promptGuidelines"];
74
+ promptSnippet: AnyToolDefinition["promptSnippet"];
75
+ }>;
76
+ toolRuntimeContext: ToolRuntimeContext;
77
+ userContentParts: UserContentPart[];
78
+ }): Promise<PromptAssembly>;
@@ -1,22 +1,51 @@
1
+ /**
2
+ * Agent run request contract.
3
+ *
4
+ * Groups the per-slice run request by the runtime role each field serves and
5
+ * owns interpretation of the routing group: requester derivation, surface
6
+ * inference, destination consistency checks, and session identifiers. Run
7
+ * phases consume these groups directly; callers build them at runtime
8
+ * boundaries.
9
+ */
1
10
  import type { Destination, Source } from "@sentry/junior-plugin-api";
2
11
  import type { ChannelConfigurationService } from "@/chat/configuration/types";
3
- import type { ThreadArtifactsState } from "@/chat/state/artifacts";
4
- import type { ConversationPendingAuthState } from "@/chat/state/conversation";
5
- import type { ImageGenerateToolDeps, WebFetchToolDeps, WebSearchToolDeps } from "@/chat/tools/types";
12
+ import type { CredentialContext } from "@/chat/credentials/context";
6
13
  import type { PiMessage } from "@/chat/pi/messages";
7
- import { type SandboxAcquiredState } from "@/chat/sandbox/sandbox";
14
+ import { type Requester } from "@/chat/requester";
15
+ import type { SandboxAcquiredState } from "@/chat/sandbox/sandbox";
8
16
  import type { SandboxEgressTracePropagationConfig } from "@/chat/sandbox/egress/tracing";
17
+ import type { AuthorizationFlowMode } from "@/chat/services/auth-pause";
9
18
  import type { AssistantStatusSpec } from "@/chat/slack/assistant-thread/status";
10
19
  import type { SlackConversationContext } from "@/chat/slack/conversation-context";
11
- import { type ToolExecutionReport } from "@/chat/tools/agent-tools";
12
- import { type AssistantReply, type AgentTurnDiagnostics } from "@/chat/services/turn-result";
20
+ import type { ThreadArtifactsState } from "@/chat/state/artifacts";
21
+ import type { ConversationPendingAuthState } from "@/chat/state/conversation";
13
22
  import type { AgentTurnSurface } from "@/chat/state/turn-session";
14
- import type { CredentialContext } from "@/chat/credentials/context";
15
- import { type Requester } from "@/chat/requester";
16
- import { type AuthorizationFlowMode } from "@/chat/services/auth-pause";
17
- export type { AssistantReply, AgentTurnDiagnostics };
18
- export interface ReplyRequestContext {
19
- skillDirs?: string[];
23
+ import type { ToolExecutionReport } from "@/chat/tool-support/tool-execution-report";
24
+ import type { ImageGenerateToolDeps, WebFetchToolDeps, WebSearchToolDeps } from "@/chat/tools/types";
25
+ export interface AgentRunAttachment {
26
+ data?: Buffer;
27
+ mediaType: string;
28
+ filename?: string;
29
+ promptText?: string;
30
+ }
31
+ export interface AgentRunSteeringMessage {
32
+ omittedImageAttachmentCount?: number;
33
+ text: string;
34
+ timestampMs?: number;
35
+ userAttachments?: AgentRunAttachment[];
36
+ }
37
+ /** Carries the user-visible content and prior transcript for one agent-run slice. */
38
+ export interface AgentRunInput {
39
+ messageText: string;
40
+ userAttachments?: AgentRunAttachment[];
41
+ inboundAttachmentCount?: number;
42
+ omittedImageAttachmentCount?: number;
43
+ /** Durable Pi transcript for this conversation, excluding ephemeral turn context. */
44
+ piMessages?: PiMessage[];
45
+ conversationContext?: string;
46
+ }
47
+ /** Carries identity and addressing needed to route tools, auth, and delivery. */
48
+ export interface AgentRunRouting {
20
49
  credentialContext?: CredentialContext;
21
50
  requester?: Requester;
22
51
  source: Source;
@@ -44,38 +73,38 @@ export interface ReplyRequestContext {
44
73
  requesterId?: string;
45
74
  };
46
75
  toolChannelId?: string;
47
- conversationContext?: string;
48
- artifactState?: ThreadArtifactsState;
49
- pendingAuth?: ConversationPendingAuthState;
50
- authorizationFlowMode?: AuthorizationFlowMode;
51
- configuration?: Record<string, unknown>;
52
- /** Durable Pi transcript for this conversation, excluding ephemeral turn context. */
53
- piMessages?: PiMessage[];
76
+ }
77
+ /** Carries execution limits and dependency overrides for one run slice. */
78
+ export interface AgentRunPolicy {
54
79
  /** Absolute wall-clock deadline for this host request, in milliseconds. */
55
80
  turnDeadlineAtMs?: number;
81
+ authorizationFlowMode?: AuthorizationFlowMode;
82
+ configuration?: Record<string, unknown>;
56
83
  channelConfiguration?: ChannelConfigurationService;
57
- userAttachments?: ReplyRequestAttachment[];
58
- inboundAttachmentCount?: number;
59
- omittedImageAttachmentCount?: number;
60
- sandbox?: {
61
- sandboxId?: string;
62
- sandboxDependencyProfileHash?: string;
63
- /** Per-turn override for app-owned sandbox egress trace propagation. */
64
- tracePropagation?: SandboxEgressTracePropagationConfig;
65
- };
66
- onSandboxAcquired?: (sandbox: SandboxAcquiredState) => void | Promise<void>;
67
- onArtifactStateUpdated?: (artifactState: ThreadArtifactsState) => void | Promise<void>;
68
- onInputCommitted?: () => void | Promise<void>;
84
+ skillDirs?: string[];
85
+ /** Per-slice override for app-owned sandbox egress trace propagation. */
86
+ sandboxTracePropagation?: SandboxEgressTracePropagationConfig;
69
87
  toolOverrides?: {
70
88
  imageGenerate?: ImageGenerateToolDeps;
71
89
  webFetch?: WebFetchToolDeps;
72
90
  webSearch?: WebSearchToolDeps;
73
91
  };
74
- onStatus?: (status: AssistantStatusSpec) => void | Promise<void>;
75
- drainSteeringMessages?: (accept: (messages: ReplySteeringMessage[]) => Promise<void>) => Promise<ReplySteeringMessage[]>;
76
- /** Return true when the durable worker should pause at the next Pi boundary. */
77
- shouldYield?: () => boolean;
78
- recordPendingAuth?: (pendingAuth: ConversationPendingAuthState) => void | Promise<void>;
92
+ }
93
+ /** Carries durable state snapshots already loaded by the caller. */
94
+ export interface AgentRunState {
95
+ artifactState?: ThreadArtifactsState;
96
+ pendingAuth?: ConversationPendingAuthState;
97
+ /** Persisted sandbox reuse state from prior slices of this conversation. */
98
+ sandbox?: {
99
+ sandboxId?: string;
100
+ sandboxDependencyProfileHash?: string;
101
+ };
102
+ }
103
+ /**
104
+ * Carries notification-only callbacks for streaming UI and status surfaces;
105
+ * their failures never affect the run.
106
+ */
107
+ export interface AgentRunObservers {
79
108
  onTextDelta?: (deltaText: string) => void | Promise<void>;
80
109
  onAssistantMessageStart?: () => void | Promise<void>;
81
110
  onToolInvocation?: (invocation: {
@@ -83,25 +112,39 @@ export interface ReplyRequestContext {
83
112
  params: Record<string, unknown>;
84
113
  }) => void | Promise<void>;
85
114
  onToolResult?: (result: ToolExecutionReport) => void | Promise<void>;
115
+ onStatus?: (status: AssistantStatusSpec) => void | Promise<void>;
86
116
  }
87
- export type AssistantReplyRequestContext = ReplyRequestContext;
88
- export interface ReplyRequestAttachment {
89
- data?: Buffer;
90
- mediaType: string;
91
- filename?: string;
92
- promptText?: string;
117
+ /** Carries durable-worker ports that commit or update resumable run state. */
118
+ export interface AgentRunDurability {
119
+ onInputCommitted?: () => void | Promise<void>;
120
+ /** Return true when the durable worker should pause at the next Pi boundary. */
121
+ shouldYield?: () => boolean;
122
+ drainSteeringMessages?: (accept: (messages: AgentRunSteeringMessage[]) => Promise<void>) => Promise<AgentRunSteeringMessage[]>;
123
+ recordPendingAuth?: (pendingAuth: ConversationPendingAuthState) => void | Promise<void>;
124
+ onSandboxAcquired?: (sandbox: SandboxAcquiredState) => void | Promise<void>;
125
+ onArtifactStateUpdated?: (artifactState: ThreadArtifactsState) => void | Promise<void>;
93
126
  }
94
- export interface ReplySteeringMessage {
95
- omittedImageAttachmentCount?: number;
96
- text: string;
97
- timestampMs?: number;
98
- userAttachments?: ReplyRequestAttachment[];
127
+ /** Groups the per-slice run request by the runtime role each field serves. */
128
+ export interface AgentRunRequest {
129
+ input: AgentRunInput;
130
+ routing: AgentRunRouting;
131
+ policy?: AgentRunPolicy;
132
+ state?: AgentRunState;
133
+ observers?: AgentRunObservers;
134
+ durability?: AgentRunDurability;
99
135
  }
100
- /**
101
- * Convert a mid-run user message into the Pi user message shape used for
102
- * steering injection and parked-conversation session-log appends, so both
103
- * paths store identical durable history.
104
- */
105
- export declare function buildSteeringPiMessage(message: ReplySteeringMessage): PiMessage;
106
- /** Run a full agent turn: discover skills, execute tools, and return the assistant reply. */
107
- export declare function generateAssistantReply(messageText: string, context: AssistantReplyRequestContext): Promise<AssistantReply>;
136
+ /** Extract conversation and session identifiers from correlation context. */
137
+ export declare function getSessionIdentifiers(routing: AgentRunRouting): {
138
+ conversationId?: string;
139
+ sessionId?: string;
140
+ };
141
+ /** Derive the acting requester, filling platform and team from the destination. */
142
+ export declare function requesterFromRouting(routing: AgentRunRouting): Requester | undefined;
143
+ /** Reject requester identities that do not belong to the active destination. */
144
+ export declare function assertRequesterDestinationMatch(routing: AgentRunRouting): void;
145
+ /** Reject legacy Slack correlation fields that conflict with the destination. */
146
+ export declare function assertCorrelationDestinationMatch(routing: AgentRunRouting): void;
147
+ /** Route tool side effects to the tool channel when one overrides the destination. */
148
+ export declare function toolInvocationDestination(routing: AgentRunRouting): Destination;
149
+ /** Infer the run surface when the caller did not state one. */
150
+ export declare function surfaceFromRouting(routing: AgentRunRouting): AgentTurnSurface | undefined;
@@ -0,0 +1,65 @@
1
+ /**
2
+ * Run resumability.
3
+ *
4
+ * Owns the durable state that lets a run slice stop without losing work:
5
+ * safe-boundary checkpoints, the durable input commit, resume snapshots, and
6
+ * persistence of the expected endings (cooperative yield, continuable
7
+ * timeout, auth pause) translated into `AgentRunOutcome` values so the
8
+ * executor's catch block stays a thin translation over genuine errors.
9
+ */
10
+ import type { Destination, Source } from "@sentry/junior-plugin-api";
11
+ import type { PiMessage } from "@/chat/pi/messages";
12
+ import { CooperativeTurnYieldError } from "@/chat/runtime/turn";
13
+ import type { AgentRunOutcome } from "@/chat/runtime/agent-run-outcome";
14
+ import type { AgentTurnSurface } from "@/chat/state/turn-session";
15
+ import type { Requester } from "@/chat/requester";
16
+ import { loadTurnSessionRecord, persistRunningSessionRecord } from "@/chat/services/turn-session-record";
17
+ import { type AgentTurnUsage } from "@/chat/usage";
18
+ import type { AgentRunDurability } from "@/chat/agent/request";
19
+ type LoadedSessionRecordState = Awaited<ReturnType<typeof loadTurnSessionRecord>>;
20
+ type SessionRecordLogContext = NonNullable<Parameters<typeof persistRunningSessionRecord>[0]["logContext"]>;
21
+ interface ResumeStateArgs {
22
+ channelName?: string;
23
+ destination: Destination;
24
+ durability: AgentRunDurability;
25
+ getLoadedSkillNames: () => string[];
26
+ logContext: SessionRecordLogContext;
27
+ recordActiveMcpProviders: () => Promise<void>;
28
+ requester?: Requester;
29
+ runSource: Source;
30
+ sessionConversationId?: string;
31
+ sessionId?: string;
32
+ sessionRecordState: LoadedSessionRecordState;
33
+ startedAtMs: number;
34
+ surface?: AgentTurnSurface;
35
+ }
36
+ interface ExpectedEndingTranslation {
37
+ outcome?: AgentRunOutcome;
38
+ }
39
+ /** Create the run's resume state: checkpoints, snapshots, and ending translation. */
40
+ export declare function createResumeState(args: ResumeStateArgs): {
41
+ readonly inputCommitted: boolean;
42
+ readonly beforeMessageCount: number;
43
+ readonly timedOut: boolean;
44
+ readonly cooperativeYieldError: CooperativeTurnYieldError | undefined;
45
+ setTurnStartMessageIndex(index: number | undefined): void;
46
+ setBeforeMessageCount(count: number): void;
47
+ captureResumeSnapshot(messages: PiMessage[]): void;
48
+ getResumeSnapshot(currentMessages: PiMessage[]): PiMessage[];
49
+ markTimedOut(): void;
50
+ commitInput(): Promise<void>;
51
+ persistSafeBoundary(messages: PiMessage[]): Promise<boolean>;
52
+ requireDurableInputCheckpoint(messages: PiMessage[]): Promise<boolean>;
53
+ yieldAtSafeBoundaryIfDue(currentMessages: PiMessage[]): void;
54
+ /**
55
+ * Persist the continuation for an expected run ending and translate it
56
+ * into an outcome; returns no outcome for genuine errors so the caller's
57
+ * error guards run.
58
+ */
59
+ translateExpectedEnding(args2: {
60
+ currentUsage?: AgentTurnUsage;
61
+ error: unknown;
62
+ }): Promise<ExpectedEndingTranslation>;
63
+ };
64
+ export type ResumeState = ReturnType<typeof createResumeState>;
65
+ export {};
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Run-scoped sandbox workspace.
3
+ *
4
+ * Exposes a stable workspace port to tools while deferring the actual
5
+ * sandbox boot until a tool first touches the filesystem or runs a command,
6
+ * and rebinding when the executor's sandbox identity changes mid-run.
7
+ */
8
+ import { type LogContext } from "@/chat/logging";
9
+ import type { SandboxExecutor } from "@/chat/sandbox/sandbox";
10
+ import type { SandboxWorkspace } from "@/chat/sandbox/workspace";
11
+ /** Create a lazy-boot workspace port bound to the run's sandbox executor. */
12
+ export declare function createLazySandboxWorkspace(args: {
13
+ executor: SandboxExecutor;
14
+ spanContext: LogContext;
15
+ }): SandboxWorkspace;
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Run session restore.
3
+ *
4
+ * Loads the persisted turn session projection for one run slice before the
5
+ * tool and prompt phases need it, resolving the durable conversation and
6
+ * session identifiers from routing.
7
+ */
8
+ import { loadTurnSessionRecord } from "@/chat/services/turn-session-record";
9
+ import { type AgentRunRouting } from "@/chat/agent/request";
10
+ type LoadedSessionRecordState = Awaited<ReturnType<typeof loadTurnSessionRecord>>;
11
+ /** Restore the persisted session projection for one run slice. */
12
+ export declare function restoreSessionRecord(routing: AgentRunRouting): Promise<{
13
+ existingSessionRecord: LoadedSessionRecordState["existingSessionRecord"];
14
+ currentSliceId: number;
15
+ resumedFromSessionRecord: boolean;
16
+ sessionConversationId?: string;
17
+ sessionId?: string;
18
+ sessionRecordState: LoadedSessionRecordState;
19
+ }>;
20
+ export {};
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Run-scoped skill discovery and restore.
3
+ *
4
+ * Discovers the skills available to one run slice and rehydrates active skill
5
+ * handles from durable Pi history and explicit invocation, so resumed slices
6
+ * keep the skill state the conversation already established.
7
+ */
8
+ import { type LogContext } from "@/chat/logging";
9
+ import { type Skill, type SkillMetadata } from "@/chat/skills";
10
+ import { SkillSandbox } from "@/chat/sandbox/skill-sandbox";
11
+ import type { PiMessage } from "@/chat/pi/messages";
12
+ /** Upsert a skill into the active skills list by name. */
13
+ export declare function upsertActiveSkill(activeSkills: Skill[], next: Skill): void;
14
+ /** Discover skills for one slice; emits the startup discovery summary once per process. */
15
+ export declare function discoverRunSkills(args: {
16
+ skillDirs?: string[];
17
+ spanContext: LogContext;
18
+ }): Promise<SkillMetadata[]>;
19
+ /** Rehydrate active skill handles from durable Pi history and explicit invocation. */
20
+ export declare function restoreSkillRuntime(args: {
21
+ activeSkills: Skill[];
22
+ invokedSkill: SkillMetadata | null;
23
+ priorPiMessages: PiMessage[] | undefined;
24
+ skillSandbox: SkillSandbox;
25
+ syncLoadedSkillNamesForResume: () => void;
26
+ }): Promise<void>;
@@ -0,0 +1,78 @@
1
+ /**
2
+ * Run tool wiring.
3
+ *
4
+ * Builds everything the agent can act through for one run slice: the sandbox
5
+ * executor and lazy workspace, MCP and plugin auth orchestration, MCP
6
+ * provider restoration from durable history, and the Pi-facing tool surfaces
7
+ * (agent tools plus the advisor's tool view). Auth pauses raised while
8
+ * restoring providers are thrown here so the run parks before prompting.
9
+ */
10
+ import type { AgentTool } from "@earendil-works/pi-agent-core";
11
+ import type { FileUpload } from "chat";
12
+ import { SkillSandbox } from "@/chat/sandbox/skill-sandbox";
13
+ import type { Skill, SkillMetadata } from "@/chat/skills";
14
+ import { type PluginHookRunner } from "@/chat/plugins/agent-hooks";
15
+ import { McpToolManager } from "@/chat/mcp/tool-manager";
16
+ import type { AnyToolDefinition } from "@/chat/tools/definition";
17
+ import type { ToolRuntimeContext } from "@/chat/tools/types";
18
+ import { type ActiveMcpCatalogSummary } from "@/chat/tool-support/skill/mcp-tool-summary";
19
+ import { type SandboxExecutor } from "@/chat/sandbox/sandbox";
20
+ import type { PiMessage } from "@/chat/pi/messages";
21
+ import type { LogContext } from "@/chat/logging";
22
+ import type { ConversationPrivacy } from "@/chat/conversation-privacy";
23
+ import type { Requester } from "@/chat/requester";
24
+ import type { ThreadArtifactsState } from "@/chat/state/artifacts";
25
+ import type { AuthorizationPauseError } from "@/chat/services/auth-pause";
26
+ import type { AgentTurnSurface } from "@/chat/state/turn-session";
27
+ import { type AgentRunDurability, type AgentRunObservers, type AgentRunPolicy, type AgentRunRouting, type AgentRunState } from "@/chat/agent/request";
28
+ import type { ResumeState } from "@/chat/agent/resume";
29
+ interface ToolWiringArgs {
30
+ abortAgent: () => void;
31
+ activeSkills: Skill[];
32
+ actorRequester?: Requester;
33
+ artifactStatePatch: Partial<ThreadArtifactsState>;
34
+ availableSkills: SkillMetadata[];
35
+ configurationValues: Record<string, unknown>;
36
+ connectedMcpProviders: Set<string>;
37
+ conversationPrivacy?: ConversationPrivacy;
38
+ durability: AgentRunDurability;
39
+ generatedFiles: FileUpload[];
40
+ invokedSkill: SkillMetadata | null;
41
+ observers: AgentRunObservers;
42
+ onSandboxMetadataChanged: (sandbox: {
43
+ sandboxId?: string;
44
+ sandboxDependencyProfileHash?: string;
45
+ }) => void;
46
+ policy: AgentRunPolicy;
47
+ preAgentPromptMessages: () => PiMessage[];
48
+ priorPiMessages: PiMessage[] | undefined;
49
+ recordConnectedMcpProvider: (provider: string) => Promise<void>;
50
+ resume: ResumeState;
51
+ routing: AgentRunRouting;
52
+ sessionConversationId?: string;
53
+ sessionId?: string;
54
+ skillSandbox: SkillSandbox;
55
+ spanContext: LogContext;
56
+ state: AgentRunState;
57
+ surface?: AgentTurnSurface;
58
+ syncLoadedSkillNamesForResume: () => void;
59
+ toolCalls: string[];
60
+ userInput: string;
61
+ }
62
+ export interface ToolWiring {
63
+ activeMcpCatalogs: ActiveMcpCatalogSummary[];
64
+ agentTools: AgentTool[];
65
+ getPendingAuthPause: () => AuthorizationPauseError | undefined;
66
+ mcpToolManager: McpToolManager;
67
+ pluginHooks: PluginHookRunner;
68
+ sandboxExecutor: SandboxExecutor;
69
+ toolGuidance: Array<{
70
+ name: string;
71
+ promptGuidelines: AnyToolDefinition["promptGuidelines"];
72
+ promptSnippet: AnyToolDefinition["promptSnippet"];
73
+ }>;
74
+ toolRuntimeContext: ToolRuntimeContext;
75
+ }
76
+ /** Wire sandbox, auth orchestration, MCP restoration, and Pi tool surfaces for one slice. */
77
+ export declare function wireAgentTools(args: ToolWiringArgs): Promise<ToolWiring>;
78
+ export {};
@@ -1,13 +1,11 @@
1
- import { generateAssistantReply as generateAssistantReplyImpl } from "@/chat/respond";
2
- import type { SandboxEgressTracePropagationConfig } from "@/chat/sandbox/egress/tracing";
1
+ import type { AgentRunner } from "@/chat/runtime/agent-runner";
3
2
  import { scheduleSessionCompletedPluginTasks } from "@/chat/plugins/task-runner";
4
3
  import { scheduleDispatchCallback } from "./signing";
5
4
  import type { DispatchCallback } from "./types";
6
5
  export interface AgentDispatchRunnerDeps {
7
- generateAssistantReply?: typeof generateAssistantReplyImpl;
6
+ agentRunner: AgentRunner;
8
7
  scheduleCallback?: typeof scheduleDispatchCallback;
9
8
  scheduleSessionCompletedPluginTasks?: typeof scheduleSessionCompletedPluginTasks;
10
- tracePropagation?: SandboxEgressTracePropagationConfig;
11
9
  }
12
10
  /** Run one serverless slice for a core-owned agent dispatch. */
13
- export declare function runAgentDispatchSlice(callback: DispatchCallback, deps?: AgentDispatchRunnerDeps): Promise<void>;
11
+ export declare function runAgentDispatchSlice(callback: DispatchCallback, deps: AgentDispatchRunnerDeps): Promise<void>;
@@ -1,5 +1,6 @@
1
1
  import type { SlackAdapter } from "@chat-adapter/slack";
2
2
  import { createSlackRuntime } from "@/chat/app/factory";
3
+ import type { AgentRunner } from "@/chat/runtime/agent-runner";
3
4
  import type { SlackWebhookServices } from "@/chat/ingress/slack-webhook";
4
5
  import type { VercelConversationWorkCallbackOptions } from "@/chat/task-execution/vercel-callback";
5
6
  import type { JuniorRuntimeServiceOverrides } from "@/chat/app/services";
@@ -17,6 +18,7 @@ export declare function createProductionSlackWebhookServices(options?: {
17
18
  /** Return production services for Slack webhook ingress. */
18
19
  export declare function getProductionSlackWebhookServices(): SlackWebhookServices;
19
20
  /** Return the production queue callback options for conversation work. */
20
- export declare function createProductionConversationWorkOptions(options?: {
21
+ export declare function createProductionConversationWorkOptions(options: {
22
+ agentRunner: AgentRunner;
21
23
  services?: JuniorRuntimeServiceOverrides;
22
24
  }): VercelConversationWorkCallbackOptions;
@@ -1,10 +1,9 @@
1
- import { generateAssistantReply as generateAssistantReplyImpl } from "@/chat/respond";
2
1
  import type { SandboxEgressTracePropagationConfig } from "@/chat/sandbox/egress/tracing";
3
2
  import { type ConversationMemoryDeps, type ConversationMemoryService } from "@/chat/services/conversation-memory";
4
3
  import { type ContextCompactor, type ContextCompactorDeps } from "@/chat/services/context-compaction";
5
4
  import { type SubscribedReplyPolicy, type SubscribedReplyPolicyDeps } from "@/chat/services/subscribed-reply-policy";
6
5
  import type { ReplyExecutorServices } from "@/chat/runtime/reply-executor";
7
- import { type VisionContextDeps, type VisionContextService } from "@/chat/services/vision-context";
6
+ import { type VisionContextDeps, type VisionContextService } from "@/chat/slack/vision-context";
8
7
  export interface JuniorRuntimeServices {
9
8
  conversationMemory: ConversationMemoryService;
10
9
  contextCompactor: ContextCompactor;
@@ -22,6 +21,4 @@ export interface JuniorRuntimeServiceOverrides {
22
21
  };
23
22
  visionContext?: Partial<VisionContextDeps>;
24
23
  }
25
- /** Apply app-owned sandbox egress trace config unless a turn overrides it. */
26
- export declare function withSandboxTracePropagation(generateReply: typeof generateAssistantReplyImpl, tracePropagation?: SandboxEgressTracePropagationConfig): typeof generateAssistantReplyImpl;
27
24
  export declare function createJuniorRuntimeServices(overrides?: JuniorRuntimeServiceOverrides): JuniorRuntimeServices;
@@ -39,6 +39,8 @@ interface SentryUserIdentity {
39
39
  }
40
40
  /** Normalize runtime finish reasons to the telemetry spelling we emit. */
41
41
  export declare function normalizeGenAiFinishReason(reason: string): string;
42
+ /** Truncate message text for log attributes. */
43
+ export declare function summarizeMessageText(text: string): string;
42
44
  export declare const log: {
43
45
  debug(eventName: string, attrs?: Record<string, unknown>, body?: string): void;
44
46
  info(eventName: string, attrs?: Record<string, unknown>, body?: string): void;
@@ -11,7 +11,7 @@ import type { OAuthClientProvider } from "@modelcontextprotocol/sdk/client/auth.
11
11
  import { type ConversationPrivacy } from "@/chat/conversation-privacy";
12
12
  import type { SkillMetadata } from "@/chat/skills";
13
13
  import type { PluginDefinition } from "@/chat/plugins/types";
14
- import { McpAuthorizationRequiredError, type PluginMcpToolCallResult } from "./client";
14
+ import { McpAuthorizationRequiredError } from "./client";
15
15
  export interface McpToolManagerOptions {
16
16
  authProviderFactory?: (plugin: PluginDefinition) => OAuthClientProvider | undefined | Promise<OAuthClientProvider | undefined>;
17
17
  fetch?: typeof fetch;
@@ -19,11 +19,6 @@ export interface McpToolManagerOptions {
19
19
  }
20
20
  export interface ManagedMcpToolResult {
21
21
  content: Array<TextContent | ImageContent>;
22
- details: {
23
- provider: string;
24
- tool: string;
25
- rawResult: PluginMcpToolCallResult;
26
- };
27
22
  }
28
23
  export interface ManagedMcpToolDescriptor {
29
24
  name: string;
@@ -1,3 +1,19 @@
1
- import type { AgentMessage } from "@earendil-works/pi-agent-core";
1
+ import { z } from "zod";
2
+ /** Permissive schema for durable Pi SDK messages whose content shape may evolve. */
3
+ export declare const piMessageSchema: z.ZodPipe<z.ZodObject<{
4
+ role: z.ZodString;
5
+ }, z.core.$loose>, z.ZodTransform<import("@earendil-works/pi-ai").UserMessage | import("@earendil-works/pi-ai").AssistantMessage | import("@earendil-works/pi-ai").ToolResultMessage<any> | import("@earendil-works/pi-agent-core").CustomMessage<unknown> | import("@earendil-works/pi-agent-core").BashExecutionMessage | import("@earendil-works/pi-agent-core").BranchSummaryMessage | import("@earendil-works/pi-agent-core").CompactionSummaryMessage, {
6
+ [x: string]: unknown;
7
+ role: string;
8
+ }>>;
2
9
  /** Durable Pi transcript message stored across turns. */
3
- export type PiMessage = AgentMessage;
10
+ export type PiMessage = z.output<typeof piMessageSchema>;
11
+ /** Reporting transcript entries only render messages with structured content parts. */
12
+ export declare const piContentMessageSchema: z.ZodPipe<z.ZodObject<{
13
+ content: z.ZodArray<z.ZodUnknown>;
14
+ role: z.ZodString;
15
+ }, z.core.$loose>, z.ZodTransform<import("@earendil-works/pi-ai").UserMessage | import("@earendil-works/pi-ai").AssistantMessage | import("@earendil-works/pi-ai").ToolResultMessage<any> | import("@earendil-works/pi-agent-core").CustomMessage<unknown> | import("@earendil-works/pi-agent-core").BashExecutionMessage | import("@earendil-works/pi-agent-core").BranchSummaryMessage | import("@earendil-works/pi-agent-core").CompactionSummaryMessage, {
16
+ [x: string]: unknown;
17
+ content: unknown[];
18
+ role: string;
19
+ }>>;
@@ -0,0 +1,31 @@
1
+ /**
2
+ * Pi transcript utilities.
3
+ *
4
+ * Shape predicates and durable-history manipulation for raw Pi messages,
5
+ * shared by the agent executor and the services that persist, trim, or
6
+ * summarize transcripts. Volatile runtime turn context (the
7
+ * `<runtime-turn-context>` bootstrap block) is stripped here so durable
8
+ * history never retains per-session runtime instructions as user text.
9
+ */
10
+ import type { AssistantMessage, ToolResultMessage } from "@earendil-works/pi-ai";
11
+ import type { PiMessage } from "@/chat/pi/messages";
12
+ /** Type guard for Pi SDK assistant messages. */
13
+ export declare function isAssistantMessage(value: unknown): value is AssistantMessage;
14
+ /** Type guard for Pi SDK tool result messages. */
15
+ export declare function isToolResultMessage(value: unknown): value is ToolResultMessage<any>;
16
+ /** Check whether a tool result carries an error flag. */
17
+ export declare function isToolResultError(result: unknown): boolean;
18
+ /** Extract the tool name from a raw tool result message. */
19
+ export declare function normalizeToolNameFromResult(result: unknown): string | undefined;
20
+ /** Extract role string from a raw Pi message. */
21
+ export declare function getPiMessageRole(value: unknown): string | undefined;
22
+ /** Concatenate text content parts from an assistant message. */
23
+ export declare function extractAssistantText(message: AssistantMessage): string;
24
+ /** Return assistant messages that belong to the terminal post-tool reply phase. */
25
+ export declare function getTerminalAssistantMessages(messages: readonly unknown[]): AssistantMessage[];
26
+ /** Remove trailing assistant messages before committing a resumable boundary. */
27
+ export declare function trimTrailingAssistantMessages(messages: PiMessage[]): PiMessage[];
28
+ /** Return whether Pi history already carries session bootstrap context. */
29
+ export declare function hasRuntimeTurnContext(messages: PiMessage[]): boolean;
30
+ /** Remove volatile runtime context before reusing messages as history. */
31
+ export declare function stripRuntimeTurnContext(messages: PiMessage[]): PiMessage[];