@sentry/junior 0.89.0 → 0.91.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 (159) hide show
  1. package/dist/{agent-hooks-RIJ5TSWP.js → agent-hooks-MXAF7RQL.js} +10 -10
  2. package/dist/api/people/list.js +8 -8
  3. package/dist/api/people/profile.js +8 -8
  4. package/dist/api-reference.d.ts +1 -1
  5. package/dist/app.js +797 -745
  6. package/dist/{catalog-runtime-MW7XERSU.js → catalog-runtime-DXE6NXHT.js} +5 -5
  7. package/dist/chat/agent/index.d.ts +4 -0
  8. package/dist/chat/agent/prompt.d.ts +78 -0
  9. package/dist/chat/{respond.d.ts → agent/request.d.ts} +106 -55
  10. package/dist/chat/agent/resume.d.ts +65 -0
  11. package/dist/chat/agent/sandbox.d.ts +15 -0
  12. package/dist/chat/agent/session.d.ts +20 -0
  13. package/dist/chat/agent/skills.d.ts +26 -0
  14. package/dist/chat/agent/tools.d.ts +78 -0
  15. package/dist/chat/agent-dispatch/runner.d.ts +3 -5
  16. package/dist/chat/app/production.d.ts +3 -1
  17. package/dist/chat/app/services.d.ts +1 -4
  18. package/dist/chat/current-instruction.d.ts +5 -3
  19. package/dist/chat/logging.d.ts +2 -0
  20. package/dist/chat/mcp/tool-manager.d.ts +1 -6
  21. package/dist/chat/oauth-authorization-message.d.ts +6 -0
  22. package/dist/chat/pi/messages.d.ts +18 -2
  23. package/dist/chat/pi/transcript.d.ts +31 -0
  24. package/dist/chat/plugins/agent-hooks.d.ts +2 -2
  25. package/dist/chat/prompt.d.ts +1 -1
  26. package/dist/chat/runtime/agent-continue-runner.d.ts +5 -5
  27. package/dist/chat/runtime/agent-run-outcome.d.ts +21 -0
  28. package/dist/chat/runtime/agent-runner.d.ts +11 -0
  29. package/dist/chat/runtime/delivered-turn-state.d.ts +2 -2
  30. package/dist/chat/runtime/generated-artifacts.d.ts +16 -0
  31. package/dist/chat/runtime/reply-executor.d.ts +2 -2
  32. package/dist/chat/runtime/slack-resume.d.ts +21 -12
  33. package/dist/chat/runtime/turn.d.ts +5 -39
  34. package/dist/chat/services/reply-delivery-plan.d.ts +0 -8
  35. package/dist/chat/services/turn-failure-response.d.ts +4 -4
  36. package/dist/chat/services/turn-result.d.ts +4 -7
  37. package/dist/chat/slack/channel.d.ts +9 -5
  38. package/dist/chat/slack/client.d.ts +3 -1
  39. package/dist/chat/slack/context.d.ts +17 -5
  40. package/dist/chat/slack/id-param.d.ts +25 -0
  41. package/dist/chat/slack/ids.d.ts +18 -4
  42. package/dist/chat/slack/mrkdwn.d.ts +6 -0
  43. package/dist/chat/slack/outbound.d.ts +16 -0
  44. package/dist/chat/slack/output.d.ts +3 -3
  45. package/dist/chat/slack/reply.d.ts +4 -7
  46. package/dist/chat/slack/timestamp-param.d.ts +25 -0
  47. package/dist/chat/slack/tools/canvas/context.d.ts +18 -0
  48. package/dist/chat/slack/tools/canvas/create.d.ts +4 -0
  49. package/dist/chat/slack/tools/canvas/edit.d.ts +3 -0
  50. package/dist/chat/slack/tools/canvas/read.d.ts +6 -0
  51. package/dist/chat/slack/tools/canvas/write.d.ts +3 -0
  52. package/dist/chat/{tools/slack → slack/tools}/channel-access.d.ts +4 -3
  53. package/dist/chat/{tools → slack/tools}/channel-capabilities.d.ts +2 -0
  54. package/dist/chat/slack/tools/channel-list-messages.d.ts +3 -0
  55. package/dist/chat/{tools/slack → slack/tools}/context.d.ts +5 -4
  56. package/dist/chat/slack/tools/list/add-items.d.ts +3 -0
  57. package/dist/chat/{tools/slack/lists.d.ts → slack/tools/list/api.d.ts} +2 -1
  58. package/dist/chat/slack/tools/list/create.d.ts +3 -0
  59. package/dist/chat/slack/tools/list/get-items.d.ts +3 -0
  60. package/dist/chat/slack/tools/list/update-item.d.ts +3 -0
  61. package/dist/chat/slack/tools/message-add-reaction.d.ts +4 -0
  62. package/dist/chat/slack/tools/send-message.d.ts +11 -0
  63. package/dist/chat/{tools/slack → slack/tools}/slack-message-url.d.ts +5 -5
  64. package/dist/chat/slack/tools/thread-read.d.ts +6 -0
  65. package/dist/chat/slack/tools/user-lookup.d.ts +2 -0
  66. package/dist/chat/slack/users.d.ts +2 -1
  67. package/dist/chat/{services → slack}/vision-context.d.ts +4 -2
  68. package/dist/chat/state/session-log.d.ts +1 -1
  69. package/dist/chat/tool-exposure.d.ts +10 -0
  70. package/dist/chat/tool-support/catalog-tool-call.d.ts +10 -0
  71. package/dist/chat/{tools/execution → tool-support}/normalize-result.d.ts +4 -1
  72. package/dist/chat/{tools/agent-tools.d.ts → tool-support/pi-tool-adapter.d.ts} +3 -9
  73. package/dist/chat/tool-support/schema-summary.d.ts +2 -0
  74. package/dist/chat/{tools → tool-support}/skill/mcp-tool-summary.d.ts +0 -6
  75. package/dist/chat/tool-support/structured-result.d.ts +73 -0
  76. package/dist/chat/tool-support/text-range-result.d.ts +58 -0
  77. package/dist/chat/tool-support/tool-execution-report.d.ts +7 -0
  78. package/dist/chat/tool-support/zod-tool.d.ts +27 -0
  79. package/dist/chat/tools/advisor/tool.d.ts +9 -18
  80. package/dist/chat/tools/definition.d.ts +56 -9
  81. package/dist/chat/tools/execute-tool.d.ts +3 -0
  82. package/dist/chat/tools/index.d.ts +3 -2
  83. package/dist/chat/tools/resource-events.d.ts +3 -13
  84. package/dist/chat/tools/runtime/report-progress.d.ts +1 -3
  85. package/dist/chat/tools/sandbox/bash.d.ts +1 -4
  86. package/dist/chat/tools/sandbox/edit-file.d.ts +25 -7
  87. package/dist/chat/tools/sandbox/file-uploads.d.ts +30 -0
  88. package/dist/chat/tools/sandbox/file-utils.d.ts +10 -1
  89. package/dist/chat/tools/sandbox/find-files.d.ts +12 -11
  90. package/dist/chat/tools/sandbox/grep.d.ts +18 -12
  91. package/dist/chat/tools/sandbox/list-dir.d.ts +15 -7
  92. package/dist/chat/tools/sandbox/read-file.d.ts +2 -31
  93. package/dist/chat/tools/sandbox/write-file.d.ts +1 -4
  94. package/dist/chat/tools/search-tools.d.ts +4 -0
  95. package/dist/chat/tools/skill/call-mcp-tool.d.ts +1 -4
  96. package/dist/chat/tools/skill/load-skill.d.ts +4 -5
  97. package/dist/chat/tools/skill/search-mcp-tools.d.ts +1 -5
  98. package/dist/chat/tools/system-time.d.ts +1 -1
  99. package/dist/chat/tools/types.d.ts +15 -5
  100. package/dist/chat/tools/web/fetch-content.d.ts +4 -2
  101. package/dist/chat/tools/web/fetch-tool.d.ts +4 -4
  102. package/dist/chat/tools/web/image-generate.d.ts +4 -3
  103. package/dist/chat/tools/web/search.d.ts +1 -4
  104. package/dist/{chunk-4IXHIV37.js → chunk-2S7M37HY.js} +6 -8
  105. package/dist/{chunk-L7OHKDOX.js → chunk-3MPOMK3K.js} +58 -7
  106. package/dist/{chunk-V6XDCS3X.js → chunk-5GBUZI6M.js} +4 -4
  107. package/dist/{chunk-7ES37H6U.js → chunk-AN2437E3.js} +4 -4
  108. package/dist/chunk-AOISHLSF.js +747 -0
  109. package/dist/{chunk-XS6NLQPA.js → chunk-DACFZ5CI.js} +474 -33
  110. package/dist/chunk-GCWD2VHP.js +1216 -0
  111. package/dist/chunk-GHGPTPBL.js +53 -0
  112. package/dist/{chunk-S35CPNPT.js → chunk-HXL2ZV74.js} +40 -216
  113. package/dist/{chunk-PBV4ZIVM.js → chunk-IRRMABQD.js} +1 -1
  114. package/dist/{chunk-2DPZRS3B.js → chunk-IX76WFJV.js} +8 -8
  115. package/dist/{chunk-66NX7MNW.js → chunk-KC42JAAQ.js} +1 -1
  116. package/dist/chunk-LFLTJQVR.js +90 -0
  117. package/dist/{chunk-IATAYWFU.js → chunk-NW7AXDA5.js} +2 -2
  118. package/dist/{chunk-F22AM3OW.js → chunk-NYWPISSO.js} +1 -1
  119. package/dist/chunk-OB42YVAE.js +16 -0
  120. package/dist/chunk-ONFOWI2D.js +955 -0
  121. package/dist/chunk-PIB4EOW6.js +1093 -0
  122. package/dist/{chunk-6UPQ5GTJ.js → chunk-QCKGI74V.js} +7 -7
  123. package/dist/{chunk-YPAE5RH3.js → chunk-RS6ANWVT.js} +1 -1
  124. package/dist/{chunk-C5NCV3OB.js → chunk-TYUXD3FN.js} +1 -1
  125. package/dist/{chunk-KBFQXJL4.js → chunk-XP7F4LYB.js} +5 -7
  126. package/dist/{chunk-NYJLQI42.js → chunk-ZGDTBSQ7.js} +11191 -11891
  127. package/dist/{chunk-VMBZFPZM.js → chunk-ZUK7BL63.js} +187 -9
  128. package/dist/cli/chat.js +55 -40
  129. package/dist/cli/check.js +6 -6
  130. package/dist/cli/plugins.js +16 -16
  131. package/dist/cli/snapshot-warmup.js +9 -9
  132. package/dist/cli/upgrade.js +21 -21
  133. package/dist/db-CXI7PR5U.js +18 -0
  134. package/dist/handlers/agent-dispatch.d.ts +3 -3
  135. package/dist/handlers/mcp-oauth-callback.d.ts +3 -3
  136. package/dist/handlers/oauth-callback.d.ts +3 -3
  137. package/dist/instrumentation.js +6 -5
  138. package/dist/nitro.js +3 -7
  139. package/dist/reporting.js +23 -25
  140. package/dist/{runner-BCRF2FCI.js → runner-FKL3RAHA.js} +89 -77
  141. package/dist/{validation-FMJO3L5P.js → validation-I7GD2YWS.js} +6 -6
  142. package/package.json +5 -5
  143. package/dist/chat/respond-helpers.d.ts +0 -82
  144. package/dist/chat/services/attachment-claims.d.ts +0 -2
  145. package/dist/chat/services/channel-intent.d.ts +0 -2
  146. package/dist/chat/tools/sandbox/attach-file.d.ts +0 -7
  147. package/dist/chat/tools/slack/canvas-tools.d.ts +0 -30
  148. package/dist/chat/tools/slack/channel-list-messages.d.ts +0 -9
  149. package/dist/chat/tools/slack/channel-post-message.d.ts +0 -5
  150. package/dist/chat/tools/slack/list-tools.d.ts +0 -21
  151. package/dist/chat/tools/slack/message-add-reaction.d.ts +0 -5
  152. package/dist/chat/tools/slack/thread-read.d.ts +0 -12
  153. package/dist/chat/tools/slack/user-lookup.d.ts +0 -8
  154. package/dist/chunk-AHLSXMOU.js +0 -506
  155. package/dist/chunk-FTMXFBDC.js +0 -49
  156. package/dist/chunk-KBSLCOGE.js +0 -2226
  157. package/dist/chunk-KQKIA4CU.js +0 -186
  158. package/dist/db-37HOGLI7.js +0 -18
  159. /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, AgentRunInstructionActor, 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, actor?: AgentRunInstructionActor): 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,59 @@
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 AgentRunInstructionActor {
32
+ authorId?: string;
33
+ authorName?: string;
34
+ slackTs?: string;
35
+ }
36
+ export interface AgentRunSteeringMessage {
37
+ actor?: AgentRunInstructionActor;
38
+ omittedImageAttachmentCount?: number;
39
+ text: string;
40
+ timestampMs?: number;
41
+ userAttachments?: AgentRunAttachment[];
42
+ }
43
+ /** Carries the user-visible content and prior transcript for one agent-run slice. */
44
+ export interface AgentRunInput {
45
+ actor?: AgentRunInstructionActor;
46
+ includeConversationContextWithPiMessages?: boolean;
47
+ messageText: string;
48
+ userAttachments?: AgentRunAttachment[];
49
+ inboundAttachmentCount?: number;
50
+ omittedImageAttachmentCount?: number;
51
+ /** Durable Pi transcript for this conversation, excluding ephemeral turn context. */
52
+ piMessages?: PiMessage[];
53
+ conversationContext?: string;
54
+ }
55
+ /** Carries identity and addressing needed to route tools, auth, and delivery. */
56
+ export interface AgentRunRouting {
20
57
  credentialContext?: CredentialContext;
21
58
  requester?: Requester;
22
59
  source: Source;
@@ -44,38 +81,38 @@ export interface ReplyRequestContext {
44
81
  requesterId?: string;
45
82
  };
46
83
  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[];
84
+ }
85
+ /** Carries execution limits and dependency overrides for one run slice. */
86
+ export interface AgentRunPolicy {
54
87
  /** Absolute wall-clock deadline for this host request, in milliseconds. */
55
88
  turnDeadlineAtMs?: number;
89
+ authorizationFlowMode?: AuthorizationFlowMode;
90
+ configuration?: Record<string, unknown>;
56
91
  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>;
92
+ skillDirs?: string[];
93
+ /** Per-slice override for app-owned sandbox egress trace propagation. */
94
+ sandboxTracePropagation?: SandboxEgressTracePropagationConfig;
69
95
  toolOverrides?: {
70
96
  imageGenerate?: ImageGenerateToolDeps;
71
97
  webFetch?: WebFetchToolDeps;
72
98
  webSearch?: WebSearchToolDeps;
73
99
  };
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>;
100
+ }
101
+ /** Carries durable state snapshots already loaded by the caller. */
102
+ export interface AgentRunState {
103
+ artifactState?: ThreadArtifactsState;
104
+ pendingAuth?: ConversationPendingAuthState;
105
+ /** Persisted sandbox reuse state from prior slices of this conversation. */
106
+ sandbox?: {
107
+ sandboxId?: string;
108
+ sandboxDependencyProfileHash?: string;
109
+ };
110
+ }
111
+ /**
112
+ * Carries notification-only callbacks for streaming UI and status surfaces;
113
+ * their failures never affect the run.
114
+ */
115
+ export interface AgentRunObservers {
79
116
  onTextDelta?: (deltaText: string) => void | Promise<void>;
80
117
  onAssistantMessageStart?: () => void | Promise<void>;
81
118
  onToolInvocation?: (invocation: {
@@ -83,25 +120,39 @@ export interface ReplyRequestContext {
83
120
  params: Record<string, unknown>;
84
121
  }) => void | Promise<void>;
85
122
  onToolResult?: (result: ToolExecutionReport) => void | Promise<void>;
123
+ onStatus?: (status: AssistantStatusSpec) => void | Promise<void>;
86
124
  }
87
- export type AssistantReplyRequestContext = ReplyRequestContext;
88
- export interface ReplyRequestAttachment {
89
- data?: Buffer;
90
- mediaType: string;
91
- filename?: string;
92
- promptText?: string;
125
+ /** Carries durable-worker ports that commit or update resumable run state. */
126
+ export interface AgentRunDurability {
127
+ onInputCommitted?: () => void | Promise<void>;
128
+ /** Return true when the durable worker should pause at the next Pi boundary. */
129
+ shouldYield?: () => boolean;
130
+ drainSteeringMessages?: (accept: (messages: AgentRunSteeringMessage[]) => Promise<void>) => Promise<AgentRunSteeringMessage[]>;
131
+ recordPendingAuth?: (pendingAuth: ConversationPendingAuthState) => void | Promise<void>;
132
+ onSandboxAcquired?: (sandbox: SandboxAcquiredState) => void | Promise<void>;
133
+ onArtifactStateUpdated?: (artifactState: ThreadArtifactsState) => void | Promise<void>;
93
134
  }
94
- export interface ReplySteeringMessage {
95
- omittedImageAttachmentCount?: number;
96
- text: string;
97
- timestampMs?: number;
98
- userAttachments?: ReplyRequestAttachment[];
135
+ /** Groups the per-slice run request by the runtime role each field serves. */
136
+ export interface AgentRunRequest {
137
+ input: AgentRunInput;
138
+ routing: AgentRunRouting;
139
+ policy?: AgentRunPolicy;
140
+ state?: AgentRunState;
141
+ observers?: AgentRunObservers;
142
+ durability?: AgentRunDurability;
99
143
  }
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>;
144
+ /** Extract conversation and session identifiers from correlation context. */
145
+ export declare function getSessionIdentifiers(routing: AgentRunRouting): {
146
+ conversationId?: string;
147
+ sessionId?: string;
148
+ };
149
+ /** Derive the acting requester, filling platform and team from the destination. */
150
+ export declare function requesterFromRouting(routing: AgentRunRouting): Requester | undefined;
151
+ /** Reject requester identities that do not belong to the active destination. */
152
+ export declare function assertRequesterDestinationMatch(routing: AgentRunRouting): void;
153
+ /** Reject legacy Slack correlation fields that conflict with the destination. */
154
+ export declare function assertCorrelationDestinationMatch(routing: AgentRunRouting): void;
155
+ /** Route tool side effects to the tool channel when one overrides the destination. */
156
+ export declare function toolInvocationDestination(routing: AgentRunRouting): Destination;
157
+ /** Infer the run surface when the caller did not state one. */
158
+ 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;
@@ -1,6 +1,8 @@
1
1
  /** Render the active user task in a stable prompt boundary. */
2
- export declare function renderCurrentInstruction(instruction: string): string;
3
- /** Read the exact body from a standalone current-task prompt boundary. */
4
- export declare function extractCurrentInstructionBody(text: string): string | undefined;
2
+ export declare function renderCurrentInstruction(instruction: string, attrs?: {
3
+ authorId?: string;
4
+ authorName?: string;
5
+ slackTs?: string;
6
+ }): string;
5
7
  /** Recover display text from the internal current-task prompt boundary. */
6
8
  export declare function unwrapCurrentInstruction(text: string): string | undefined;
@@ -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;
@@ -0,0 +1,6 @@
1
+ /** Format the private OAuth authorization prompt for Slack delivery. */
2
+ export declare function formatOAuthAuthorizationMessage(args: {
3
+ authorizationUrl: string;
4
+ label: string;
5
+ completionText: string;
6
+ }): 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
+ }>>;