@sentry/junior 0.53.0 → 0.54.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 (222) hide show
  1. package/README.md +3 -2
  2. package/dist/api-reference.d.ts +7 -0
  3. package/dist/app.d.ts +5 -10
  4. package/dist/app.js +1934 -1658
  5. package/dist/build/copy-build-content.d.ts +4 -0
  6. package/dist/build/glob-to-regex.d.ts +2 -0
  7. package/dist/build/rolldown-workarounds.d.ts +14 -0
  8. package/dist/build/virtual-config.d.ts +4 -0
  9. package/dist/chat/app/factory.d.ts +10 -0
  10. package/dist/chat/app/production.d.ts +6 -0
  11. package/dist/chat/app/services.d.ts +17 -0
  12. package/dist/chat/capabilities/catalog.d.ts +16 -0
  13. package/dist/chat/capabilities/factory.d.ts +10 -0
  14. package/dist/chat/capabilities/jr-rpc-command.d.ts +26 -0
  15. package/dist/chat/capabilities/router.d.ts +19 -0
  16. package/dist/chat/coerce.d.ts +6 -0
  17. package/dist/chat/config.d.ts +46 -0
  18. package/dist/chat/configuration/defaults.d.ts +4 -0
  19. package/dist/chat/configuration/service.d.ts +2 -0
  20. package/dist/chat/configuration/types.d.ts +37 -0
  21. package/dist/chat/configuration/validation.d.ts +2 -0
  22. package/dist/chat/credentials/broker.d.ts +22 -0
  23. package/dist/chat/credentials/header-transforms.d.ts +3 -0
  24. package/dist/chat/credentials/oauth-scope.d.ts +4 -0
  25. package/dist/chat/credentials/state-adapter-token-store.d.ts +9 -0
  26. package/dist/chat/credentials/test-broker.d.ts +19 -0
  27. package/dist/chat/credentials/unlink-provider.d.ts +2 -0
  28. package/dist/chat/credentials/user-token-store.d.ts +11 -0
  29. package/dist/chat/discovery.d.ts +47 -0
  30. package/dist/chat/ingress/junior-chat.d.ts +26 -0
  31. package/dist/chat/ingress/message-changed.d.ts +50 -0
  32. package/dist/chat/ingress/message-router.d.ts +9 -0
  33. package/dist/chat/ingress/slash-command.d.ts +3 -0
  34. package/dist/chat/ingress/workspace-membership.d.ts +10 -0
  35. package/dist/chat/interruption-marker.d.ts +2 -0
  36. package/dist/chat/logging.d.ts +88 -0
  37. package/dist/chat/mcp/auth-store.d.ts +41 -0
  38. package/dist/chat/mcp/client.d.ts +34 -0
  39. package/dist/chat/mcp/errors.d.ts +8 -0
  40. package/dist/chat/mcp/oauth-provider.d.ts +27 -0
  41. package/dist/chat/mcp/oauth.d.ts +17 -0
  42. package/dist/chat/mcp/tool-manager.d.ts +60 -0
  43. package/dist/chat/oauth-flow.d.ts +45 -0
  44. package/dist/chat/optional-string.d.ts +5 -0
  45. package/dist/chat/pi/client.d.ts +49 -0
  46. package/dist/chat/pi/messages.d.ts +3 -0
  47. package/dist/chat/pi/traced-stream.d.ts +9 -0
  48. package/dist/chat/plugins/auth/api-headers-broker.d.ts +6 -0
  49. package/dist/chat/plugins/auth/auth-token-placeholder.d.ts +3 -0
  50. package/dist/chat/plugins/auth/github-app-broker.d.ts +4 -0
  51. package/dist/chat/plugins/auth/oauth-bearer-broker.d.ts +6 -0
  52. package/dist/chat/plugins/auth/oauth-request.d.ts +18 -0
  53. package/dist/chat/plugins/command-env.d.ts +3 -0
  54. package/dist/chat/plugins/manifest.d.ts +3 -0
  55. package/dist/chat/plugins/package-discovery.d.ts +14 -0
  56. package/dist/chat/plugins/registry.d.ts +23 -0
  57. package/dist/chat/plugins/types.d.ts +146 -0
  58. package/dist/chat/prompt.d.ts +39 -0
  59. package/dist/chat/queue/thread-message-dispatcher.d.ts +33 -0
  60. package/dist/chat/respond-helpers.d.ts +77 -0
  61. package/dist/chat/respond.d.ts +64 -0
  62. package/dist/chat/runtime/auth-pause-state.d.ts +11 -0
  63. package/dist/chat/runtime/delivered-turn-state.d.ts +15 -0
  64. package/dist/chat/runtime/dev-agent-trace.d.ts +1 -0
  65. package/dist/chat/runtime/processing-reaction.d.ts +25 -0
  66. package/dist/chat/runtime/reply-executor.d.ts +56 -0
  67. package/dist/chat/runtime/report-progress.d.ts +3 -0
  68. package/dist/chat/runtime/slack-resume.d.ts +50 -0
  69. package/dist/chat/runtime/slack-runtime.d.ts +100 -0
  70. package/dist/chat/runtime/thread-context.d.ts +22 -0
  71. package/dist/chat/runtime/thread-state.d.ts +28 -0
  72. package/dist/chat/runtime/turn-preparation.d.ts +43 -0
  73. package/dist/chat/runtime/turn-user-message.d.ts +12 -0
  74. package/dist/chat/runtime/turn.d.ts +69 -0
  75. package/dist/chat/sandbox/credentials.d.ts +11 -0
  76. package/dist/chat/sandbox/egress-oidc.d.ts +3 -0
  77. package/dist/chat/sandbox/egress-policy.d.ts +11 -0
  78. package/dist/chat/sandbox/egress-proxy.d.ts +10 -0
  79. package/dist/chat/sandbox/egress-session.d.ts +27 -0
  80. package/dist/chat/sandbox/errors.d.ts +12 -0
  81. package/dist/chat/sandbox/eval-gh-stub.d.ts +2 -0
  82. package/dist/chat/sandbox/eval-oauth-stub.d.ts +2 -0
  83. package/dist/chat/sandbox/eval-sentry-stub.d.ts +2 -0
  84. package/dist/chat/sandbox/fault-injection.d.ts +2 -0
  85. package/dist/chat/sandbox/http-error-details.d.ts +18 -0
  86. package/dist/chat/sandbox/noninteractive-command.d.ts +17 -0
  87. package/dist/chat/sandbox/paths.d.ts +5 -0
  88. package/dist/chat/sandbox/runtime-dependency-snapshots.d.ts +20 -0
  89. package/dist/chat/sandbox/sandbox.d.ts +52 -0
  90. package/dist/chat/sandbox/session.d.ts +53 -0
  91. package/dist/chat/sandbox/skill-sandbox.d.ts +42 -0
  92. package/dist/chat/sandbox/skill-sync.d.ts +17 -0
  93. package/dist/chat/sandbox/workspace.d.ts +55 -0
  94. package/dist/chat/sentry.d.ts +2 -0
  95. package/dist/chat/services/attachment-claims.d.ts +2 -0
  96. package/dist/chat/services/auth-pause-response.d.ts +2 -0
  97. package/dist/chat/services/auth-pause.d.ts +12 -0
  98. package/dist/chat/services/channel-intent.d.ts +2 -0
  99. package/dist/chat/services/conversation-memory.d.ts +33 -0
  100. package/dist/chat/services/mcp-auth-orchestration.d.ts +29 -0
  101. package/dist/chat/services/pending-auth.d.ts +27 -0
  102. package/dist/chat/services/plugin-auth-orchestration.d.ts +36 -0
  103. package/dist/chat/services/provider-default-config.d.ts +9 -0
  104. package/dist/chat/services/provider-retry.d.ts +6 -0
  105. package/dist/chat/services/reply-delivery-plan.d.ts +17 -0
  106. package/dist/chat/services/subscribed-decision.d.ts +63 -0
  107. package/dist/chat/services/subscribed-reply-policy.d.ts +23 -0
  108. package/dist/chat/services/timeout-resume.d.ts +17 -0
  109. package/dist/chat/services/turn-checkpoint.d.ts +74 -0
  110. package/dist/chat/services/turn-continuation-response.d.ts +2 -0
  111. package/dist/chat/services/turn-failure-response.d.ts +15 -0
  112. package/dist/chat/services/turn-result.d.ts +55 -0
  113. package/dist/chat/services/turn-thinking-level.d.ts +49 -0
  114. package/dist/chat/services/vision-context.d.ts +61 -0
  115. package/dist/chat/skills.d.ts +48 -0
  116. package/dist/chat/slack/adapter.d.ts +9 -0
  117. package/dist/chat/slack/app-home.d.ts +11 -0
  118. package/dist/chat/slack/assistant-thread/lifecycle.d.ts +13 -0
  119. package/dist/chat/slack/assistant-thread/status-render.d.ts +28 -0
  120. package/dist/chat/slack/assistant-thread/status-scheduler.d.ts +23 -0
  121. package/dist/chat/slack/assistant-thread/status-send.d.ts +31 -0
  122. package/dist/chat/slack/assistant-thread/status.d.ts +36 -0
  123. package/dist/chat/slack/assistant-thread/title.d.ts +28 -0
  124. package/dist/chat/slack/canvas-references.d.ts +2 -0
  125. package/dist/chat/slack/channel.d.ts +48 -0
  126. package/dist/chat/slack/client.d.ts +52 -0
  127. package/dist/chat/slack/context.d.ts +9 -0
  128. package/dist/chat/slack/emoji.d.ts +1 -0
  129. package/dist/chat/slack/errors.d.ts +6 -0
  130. package/dist/chat/slack/footer.d.ts +42 -0
  131. package/dist/chat/slack/legacy-attachments.d.ts +4 -0
  132. package/dist/chat/slack/message.d.ts +6 -0
  133. package/dist/chat/slack/mrkdwn.d.ts +12 -0
  134. package/dist/chat/slack/outbound.d.ts +57 -0
  135. package/dist/chat/slack/output.d.ts +54 -0
  136. package/dist/chat/slack/reply.d.ts +33 -0
  137. package/dist/chat/slack/status-format.d.ts +2 -0
  138. package/dist/chat/slack/turn-continuation-notice.d.ts +8 -0
  139. package/dist/chat/slack/user.d.ts +7 -0
  140. package/dist/chat/slack/users.d.ts +39 -0
  141. package/dist/chat/state/adapter.d.ts +9 -0
  142. package/dist/chat/state/artifacts.d.ts +29 -0
  143. package/dist/chat/state/conversation.d.ts +81 -0
  144. package/dist/chat/state/pi-session-message-store.d.ts +15 -0
  145. package/dist/chat/state/turn-id.d.ts +2 -0
  146. package/dist/chat/state/turn-session-store.d.ts +49 -0
  147. package/dist/chat/tools/advisor/session-store.d.ts +9 -0
  148. package/dist/chat/tools/advisor/tool.d.ts +33 -0
  149. package/dist/chat/tools/agent-tools.d.ts +9 -0
  150. package/dist/chat/tools/channel-capabilities.d.ts +11 -0
  151. package/dist/chat/tools/definition.d.ts +17 -0
  152. package/dist/chat/tools/execution/build-sandbox-input.d.ts +2 -0
  153. package/dist/chat/tools/execution/normalize-result.d.ts +6 -0
  154. package/dist/chat/tools/execution/tool-error-handler.d.ts +3 -0
  155. package/dist/chat/tools/execution/tool-input-error.d.ts +6 -0
  156. package/dist/chat/tools/idempotency.d.ts +1 -0
  157. package/dist/chat/tools/index.d.ts +5 -0
  158. package/dist/chat/tools/runtime/report-progress.d.ts +4 -0
  159. package/dist/chat/tools/sandbox/attach-file.d.ts +7 -0
  160. package/dist/chat/tools/sandbox/bash.d.ts +5 -0
  161. package/dist/chat/tools/sandbox/edit-file.d.ts +37 -0
  162. package/dist/chat/tools/sandbox/file-utils.d.ts +52 -0
  163. package/dist/chat/tools/sandbox/find-files.d.ts +24 -0
  164. package/dist/chat/tools/sandbox/grep.d.ts +33 -0
  165. package/dist/chat/tools/sandbox/list-dir.d.ts +22 -0
  166. package/dist/chat/tools/sandbox/read-file.d.ts +32 -0
  167. package/dist/chat/tools/sandbox/text-edits.d.ts +28 -0
  168. package/dist/chat/tools/sandbox/write-file.d.ts +5 -0
  169. package/dist/chat/tools/skill/call-mcp-tool.d.ts +7 -0
  170. package/dist/chat/tools/skill/load-skill.d.ts +22 -0
  171. package/dist/chat/tools/skill/mcp-tool-summary.d.ts +31 -0
  172. package/dist/chat/tools/skill/search-mcp-tools.d.ts +8 -0
  173. package/dist/chat/tools/slack/canvas-tools.d.ts +29 -0
  174. package/dist/chat/tools/slack/canvases.d.ts +45 -0
  175. package/dist/chat/tools/slack/channel-list-messages.d.ts +9 -0
  176. package/dist/chat/tools/slack/channel-post-message.d.ts +4 -0
  177. package/dist/chat/tools/slack/list-tools.d.ts +21 -0
  178. package/dist/chat/tools/slack/lists.d.ts +42 -0
  179. package/dist/chat/tools/slack/message-add-reaction.d.ts +4 -0
  180. package/dist/chat/tools/slack/slack-message-url.d.ts +18 -0
  181. package/dist/chat/tools/slack/thread-read.d.ts +9 -0
  182. package/dist/chat/tools/slack/user-lookup.d.ts +8 -0
  183. package/dist/chat/tools/system-time.d.ts +1 -0
  184. package/dist/chat/tools/types.d.ts +55 -0
  185. package/dist/chat/tools/web/constants.d.ts +6 -0
  186. package/dist/chat/tools/web/fetch-content.d.ts +23 -0
  187. package/dist/chat/tools/web/fetch-tool.d.ts +5 -0
  188. package/dist/chat/tools/web/image-generate.d.ts +4 -0
  189. package/dist/chat/tools/web/network.d.ts +6 -0
  190. package/dist/chat/tools/web/search.d.ts +5 -0
  191. package/dist/chat/turn-context-tag.d.ts +6 -0
  192. package/dist/chat/usage.d.ts +24 -0
  193. package/dist/chat/xml.d.ts +1 -0
  194. package/dist/{chunk-XPXD3FCE.js → chunk-5LUISFEY.js} +189 -35
  195. package/dist/{chunk-KCOKQLBF.js → chunk-7WTXNEPF.js} +120 -15
  196. package/dist/{chunk-ZNFNY53B.js → chunk-QCHPJ4FD.js} +2 -2
  197. package/dist/{chunk-Q3FDONU7.js → chunk-YITDDLS3.js} +34 -28
  198. package/dist/cli/check.js +3 -3
  199. package/dist/cli/init.js +1 -0
  200. package/dist/cli/snapshot-warmup.js +3 -3
  201. package/dist/handlers/diagnostics-dashboard.d.ts +2 -0
  202. package/dist/handlers/diagnostics.d.ts +2 -0
  203. package/dist/handlers/health.d.ts +4 -0
  204. package/dist/handlers/mcp-oauth-callback.d.ts +2 -0
  205. package/dist/handlers/oauth-callback.d.ts +2 -0
  206. package/dist/handlers/oauth-html.d.ts +2 -0
  207. package/dist/handlers/sandbox-egress-proxy.d.ts +4 -0
  208. package/dist/handlers/turn-resume.d.ts +3 -0
  209. package/dist/handlers/types.d.ts +2 -0
  210. package/dist/handlers/webhooks.d.ts +15 -0
  211. package/dist/instrumentation.d.ts +1 -3
  212. package/dist/nitro.d.ts +4 -7
  213. package/dist/nitro.js +112 -54
  214. package/dist/package-resolution.d.ts +13 -0
  215. package/dist/vercel.d.ts +2 -4
  216. package/package.json +25 -25
  217. package/dist/cli/check.d.ts +0 -8
  218. package/dist/cli/env.d.ts +0 -7
  219. package/dist/cli/init.d.ts +0 -3
  220. package/dist/cli/run.d.ts +0 -12
  221. package/dist/cli/snapshot-warmup.d.ts +0 -3
  222. package/dist/types-X_iCClPb.d.ts +0 -75
@@ -0,0 +1,77 @@
1
+ /**
2
+ * Pure helper functions used by the agent reply orchestration in respond.ts.
3
+ *
4
+ * These are extracted to reduce the size of the main orchestration module and
5
+ * make individual helpers independently testable.
6
+ */
7
+ import type { AssistantMessage, ToolResultMessage } from "@earendil-works/pi-ai";
8
+ import type { PiMessage } from "@/chat/pi/messages";
9
+ import type { Skill } from "@/chat/skills";
10
+ /** Extract conversation and session identifiers from correlation context. */
11
+ export declare function getSessionIdentifiers(context: {
12
+ correlation?: {
13
+ conversationId?: string;
14
+ threadId?: string;
15
+ turnId?: string;
16
+ runId?: string;
17
+ };
18
+ }): {
19
+ conversationId?: string;
20
+ sessionId?: string;
21
+ };
22
+ /** Detect polite execution deferral phrases that signal the model is stalling. */
23
+ export declare function isExecutionDeferralResponse(text: string): boolean;
24
+ /** Detect disclaimers about missing tool access. */
25
+ export declare function isToolAccessDisclaimerResponse(text: string): boolean;
26
+ /** True when the model produced an escape response instead of executing. */
27
+ export declare function isExecutionEscapeResponse(text: string): boolean;
28
+ /** Best-effort JSON extraction from text that may contain fenced blocks. */
29
+ export declare function parseJsonCandidate(text: string): unknown;
30
+ /** Check whether a parsed object looks like a raw tool call/result payload. */
31
+ export declare function isToolPayloadShape(payload: unknown): boolean;
32
+ /** Detect responses that are raw tool payloads leaked as text. */
33
+ export declare function isRawToolPayloadResponse(text: string): boolean;
34
+ /** Redact image data from prompt content parts for observability. */
35
+ export declare function toObservablePromptPart(part: {
36
+ type: "text";
37
+ text: string;
38
+ } | {
39
+ type: "image";
40
+ data: string;
41
+ mimeType: string;
42
+ }): Record<string, unknown>;
43
+ /** Truncate message text for log attributes. */
44
+ export declare function summarizeMessageText(text: string): string;
45
+ /**
46
+ * Put prior thread text before the current instruction when no Pi history
47
+ * exists. These are top-level sibling blocks in the user message.
48
+ */
49
+ export declare function buildUserTurnText(userInput: string, conversationContext?: string): string;
50
+ /** Encode a non-image attachment as base64 XML for the prompt. */
51
+ export declare function encodeNonImageAttachmentForPrompt(attachment: {
52
+ data: Buffer;
53
+ mediaType: string;
54
+ filename?: string;
55
+ }): string;
56
+ /** Type guard for Pi SDK tool result messages. */
57
+ export declare function isToolResultMessage(value: unknown): value is ToolResultMessage<any>;
58
+ /** Extract the tool name from a raw tool result message. */
59
+ export declare function normalizeToolNameFromResult(result: unknown): string | undefined;
60
+ /** Check whether a tool result carries an error flag. */
61
+ export declare function isToolResultError(result: unknown): boolean;
62
+ /** Type guard for Pi SDK assistant messages. */
63
+ export declare function isAssistantMessage(value: unknown): value is AssistantMessage;
64
+ /** Extract role string from a raw Pi message. */
65
+ export declare function getPiMessageRole(value: unknown): string | undefined;
66
+ /** Refresh volatile runtime context in a checkpoint before continuing Pi. */
67
+ export declare function refreshRuntimeTurnContext(messages: PiMessage[], turnContextPrompt: string): PiMessage[];
68
+ /** Remove volatile runtime context before using checkpoint messages as history. */
69
+ export declare function stripRuntimeTurnContext(messages: PiMessage[]): PiMessage[];
70
+ /** Concatenate text content parts from an assistant message. */
71
+ export declare function extractAssistantText(message: AssistantMessage): string;
72
+ /** Return assistant messages that belong to the terminal post-tool reply phase. */
73
+ export declare function getTerminalAssistantMessages(messages: readonly unknown[]): AssistantMessage[];
74
+ /** Upsert a skill into the active skills list by name. */
75
+ export declare function upsertActiveSkill(activeSkills: Skill[], next: Skill): void;
76
+ /** Remove trailing assistant messages before checkpointing. */
77
+ export declare function trimTrailingAssistantMessages(messages: PiMessage[]): PiMessage[];
@@ -0,0 +1,64 @@
1
+ import type { ChannelConfigurationService } from "@/chat/configuration/types";
2
+ import type { ThreadArtifactsState } from "@/chat/state/artifacts";
3
+ import type { ConversationPendingAuthState } from "@/chat/state/conversation";
4
+ import type { ImageGenerateToolDeps, WebFetchToolDeps, WebSearchToolDeps } from "@/chat/tools/types";
5
+ import type { PiMessage } from "@/chat/pi/messages";
6
+ import { type SandboxAcquiredState } from "@/chat/sandbox/sandbox";
7
+ import type { AssistantStatusSpec } from "@/chat/slack/assistant-thread/status";
8
+ import { type AssistantReply, type AgentTurnDiagnostics } from "@/chat/services/turn-result";
9
+ export type { AssistantReply, AgentTurnDiagnostics };
10
+ export interface ReplyRequestContext {
11
+ skillDirs?: string[];
12
+ requester?: {
13
+ userId?: string;
14
+ userName?: string;
15
+ fullName?: string;
16
+ };
17
+ correlation?: {
18
+ conversationId?: string;
19
+ threadId?: string;
20
+ turnId?: string;
21
+ runId?: string;
22
+ channelId?: string;
23
+ messageTs?: string;
24
+ threadTs?: string;
25
+ requesterId?: string;
26
+ };
27
+ toolChannelId?: string;
28
+ conversationContext?: string;
29
+ artifactState?: ThreadArtifactsState;
30
+ pendingAuth?: ConversationPendingAuthState;
31
+ configuration?: Record<string, unknown>;
32
+ /** Durable Pi transcript for this conversation, excluding ephemeral turn context. */
33
+ piMessages?: PiMessage[];
34
+ channelConfiguration?: ChannelConfigurationService;
35
+ userAttachments?: Array<{
36
+ data?: Buffer;
37
+ mediaType: string;
38
+ filename?: string;
39
+ promptText?: string;
40
+ }>;
41
+ inboundAttachmentCount?: number;
42
+ omittedImageAttachmentCount?: number;
43
+ sandbox?: {
44
+ sandboxId?: string;
45
+ sandboxDependencyProfileHash?: string;
46
+ };
47
+ onSandboxAcquired?: (sandbox: SandboxAcquiredState) => void | Promise<void>;
48
+ onArtifactStateUpdated?: (artifactState: ThreadArtifactsState) => void | Promise<void>;
49
+ toolOverrides?: {
50
+ imageGenerate?: ImageGenerateToolDeps;
51
+ webFetch?: WebFetchToolDeps;
52
+ webSearch?: WebSearchToolDeps;
53
+ };
54
+ onStatus?: (status: AssistantStatusSpec) => void | Promise<void>;
55
+ onAuthPending?: (pendingAuth: ConversationPendingAuthState) => void | Promise<void>;
56
+ onTextDelta?: (deltaText: string) => void | Promise<void>;
57
+ onAssistantMessageStart?: () => void | Promise<void>;
58
+ onToolInvocation?: (invocation: {
59
+ toolName: string;
60
+ params: Record<string, unknown>;
61
+ }) => void;
62
+ }
63
+ /** Run a full agent turn: discover skills, execute tools, and return the assistant reply. */
64
+ export declare function generateAssistantReply(messageText: string, context?: ReplyRequestContext): Promise<AssistantReply>;
@@ -0,0 +1,11 @@
1
+ import { type ThreadConversationState } from "@/chat/state/conversation";
2
+ /** Mark an auth-paused turn complete after private authorization link delivery. */
3
+ export declare function completeAuthPauseTurn(args: {
4
+ conversation: ThreadConversationState;
5
+ sessionId: string;
6
+ }): void;
7
+ /** Reload thread state, mark the auth pause as parked, and persist it. */
8
+ export declare function persistAuthPauseTurnState(args: {
9
+ sessionId: string;
10
+ threadStateId: string;
11
+ }): Promise<void>;
@@ -0,0 +1,15 @@
1
+ import type { AssistantReply } from "@/chat/respond";
2
+ import type { ThreadConversationState } from "@/chat/state/conversation";
3
+ import type { ThreadArtifactsState } from "@/chat/state/artifacts";
4
+ import { type ThreadStatePatch } from "@/chat/runtime/thread-state";
5
+ /** Build the canonical thread-state patch after final Slack delivery succeeds. */
6
+ export declare function buildDeliveredTurnStatePatch(args: {
7
+ artifactStatePatch?: Partial<ThreadArtifactsState>;
8
+ artifacts: ThreadArtifactsState;
9
+ conversation: ThreadConversationState;
10
+ reply: AssistantReply;
11
+ sessionId: string;
12
+ userMessageId?: string;
13
+ }): ThreadStatePatch & {
14
+ conversation: ThreadConversationState;
15
+ };
@@ -0,0 +1 @@
1
+ export declare function shouldEmitDevAgentTrace(): boolean;
@@ -0,0 +1,25 @@
1
+ import type { Message, Thread } from "chat";
2
+ /** Controls the automatic Slack processing reaction lifecycle for one message. */
3
+ export interface ProcessingReactionSession {
4
+ keep: () => void;
5
+ stop: () => Promise<void>;
6
+ }
7
+ /** Return true when a Slack reaction tool call should leave the processing reaction in place. */
8
+ export declare function shouldKeepProcessingReactionForToolInvocation(input: {
9
+ params: Record<string, unknown>;
10
+ toolName: string;
11
+ }): boolean;
12
+ /** Start Junior's automatic Slack processing reaction for one inbound message. */
13
+ export declare function startSlackProcessingReaction(args: {
14
+ logException: (error: unknown, eventName: string, context?: Record<string, unknown>, attributes?: Record<string, unknown>, body?: string) => string | undefined;
15
+ logContext: Record<string, unknown>;
16
+ message: Message;
17
+ thread: Thread;
18
+ }): Promise<ProcessingReactionSession>;
19
+ /** Start Junior's automatic Slack processing reaction for a known Slack message. */
20
+ export declare function startSlackProcessingReactionForMessage(args: {
21
+ channelId: string;
22
+ timestamp: string;
23
+ logException: (error: unknown, eventName: string, context?: Record<string, unknown>, attributes?: Record<string, unknown>, body?: string) => string | undefined;
24
+ logContext: Record<string, unknown>;
25
+ }): Promise<ProcessingReactionSession>;
@@ -0,0 +1,56 @@
1
+ import type { Message, Thread } from "chat";
2
+ import type { SlackAdapter } from "@chat-adapter/slack";
3
+ import { generateAssistantReply as generateAssistantReplyImpl } from "@/chat/respond";
4
+ import type { PreparedTurnState } from "@/chat/runtime/turn-preparation";
5
+ import { type ConversationMemoryService } from "@/chat/services/conversation-memory";
6
+ import { lookupSlackUser } from "@/chat/slack/user";
7
+ import type { TurnContinuationRequest } from "@/chat/services/timeout-resume";
8
+ export interface ReplyExecutorServices {
9
+ generateAssistantReply: typeof generateAssistantReplyImpl;
10
+ generateThreadTitle: ConversationMemoryService["generateThreadTitle"];
11
+ getAwaitingTurnContinuationRequest: (args: {
12
+ conversationId: string;
13
+ sessionId: string;
14
+ }) => Promise<TurnContinuationRequest | undefined>;
15
+ lookupSlackUser: typeof lookupSlackUser;
16
+ scheduleTurnTimeoutResume: (request: TurnContinuationRequest) => Promise<void>;
17
+ }
18
+ interface ReplyExecutorDeps {
19
+ getSlackAdapter: () => SlackAdapter;
20
+ resolveUserAttachments: (attachments: Message["attachments"] | undefined, context: {
21
+ threadId?: string;
22
+ requesterId?: string;
23
+ channelId?: string;
24
+ runId?: string;
25
+ conversation?: PreparedTurnState["conversation"];
26
+ messageTs?: string;
27
+ }) => Promise<Array<{
28
+ data?: Buffer;
29
+ mediaType: string;
30
+ filename?: string;
31
+ promptText?: string;
32
+ }>>;
33
+ prepareTurnState: (args: {
34
+ explicitMention: boolean;
35
+ message: Message;
36
+ thread: Thread;
37
+ userText: string;
38
+ context: {
39
+ threadId?: string;
40
+ requesterId?: string;
41
+ channelId?: string;
42
+ runId?: string;
43
+ };
44
+ }) => Promise<PreparedTurnState>;
45
+ services: ReplyExecutorServices;
46
+ }
47
+ export declare function createReplyToThread(deps: ReplyExecutorDeps): (thread: Thread, message: Message, options?: {
48
+ beforeFirstResponsePost?: () => Promise<void>;
49
+ explicitMention?: boolean;
50
+ onToolInvocation?: (invocation: {
51
+ params: Record<string, unknown>;
52
+ toolName: string;
53
+ }) => void;
54
+ preparedState?: PreparedTurnState;
55
+ }) => Promise<void>;
56
+ export {};
@@ -0,0 +1,3 @@
1
+ import type { AssistantStatusSpec } from "@/chat/slack/assistant-thread/status-render";
2
+ /** Convert a `reportProgress` tool payload into assistant status text. */
3
+ export declare function buildReportedProgressStatus(input: unknown): AssistantStatusSpec | undefined;
@@ -0,0 +1,50 @@
1
+ import { generateAssistantReply, type AssistantReply, type ReplyRequestContext } from "@/chat/respond";
2
+ /** Error raised when another worker already owns the resume lock. */
3
+ export declare class ResumeTurnBusyError extends Error {
4
+ constructor(lockKey: string);
5
+ }
6
+ interface ResumeSlackTurnArgs {
7
+ messageText: string;
8
+ channelId: string;
9
+ threadTs: string;
10
+ messageTs?: string;
11
+ replyContext?: ReplyRequestContext;
12
+ lockKey?: string;
13
+ initialText?: string;
14
+ generateReply?: typeof generateAssistantReply;
15
+ onSuccess?: (reply: AssistantReply) => Promise<void>;
16
+ onFailure?: (error: unknown) => Promise<void>;
17
+ onAuthPause?: (error: unknown) => Promise<void>;
18
+ onTimeoutPause?: (error: unknown) => Promise<void>;
19
+ onPostDeliveryCommitFailure?: (error: unknown) => Promise<void>;
20
+ beforeStart?: () => Promise<Partial<ResumeSlackTurnArgs> | false | void>;
21
+ replyTimeoutMs?: number;
22
+ }
23
+ /**
24
+ * Resume a paused Slack turn under the normal thread lock.
25
+ *
26
+ * Success is defined by final reply delivery, not only by successful assistant
27
+ * generation. If the final visible Slack post fails, the resumed turn is
28
+ * treated as failed so thread state does not claim the user saw a reply that
29
+ * never arrived.
30
+ */
31
+ export declare function resumeSlackTurn(args: ResumeSlackTurnArgs): Promise<void>;
32
+ /** Resume an OAuth-paused Slack request through the shared resume runner. */
33
+ export declare function resumeAuthorizedRequest(args: {
34
+ messageText: string;
35
+ channelId: string;
36
+ threadTs: string;
37
+ messageTs?: string;
38
+ connectedText: string;
39
+ replyContext?: ReplyRequestContext;
40
+ lockKey?: string;
41
+ generateReply?: typeof generateAssistantReply;
42
+ onSuccess?: (reply: AssistantReply) => Promise<void>;
43
+ onFailure?: (error: unknown) => Promise<void>;
44
+ onAuthPause?: (error: unknown) => Promise<void>;
45
+ onTimeoutPause?: (error: unknown) => Promise<void>;
46
+ onPostDeliveryCommitFailure?: (error: unknown) => Promise<void>;
47
+ beforeStart?: () => Promise<Partial<ResumeSlackTurnArgs> | false | void>;
48
+ replyTimeoutMs?: number;
49
+ }): Promise<void>;
50
+ export {};
@@ -0,0 +1,100 @@
1
+ import type { Message, Thread } from "chat";
2
+ import type { SubscribedReplyDecision } from "@/chat/services/subscribed-reply-policy";
3
+ export interface AssistantLifecycleEvent {
4
+ channelId: string;
5
+ context?: {
6
+ channelId?: string;
7
+ };
8
+ threadId: string;
9
+ threadTs: string;
10
+ userId?: string;
11
+ }
12
+ export interface ThreadContext {
13
+ channelId?: string;
14
+ requesterId?: string;
15
+ threadId?: string;
16
+ runId?: string;
17
+ }
18
+ export interface ReplyHooks {
19
+ beforeFirstResponsePost?: () => Promise<void>;
20
+ onToolInvocation?: (invocation: {
21
+ params: Record<string, unknown>;
22
+ toolName: string;
23
+ }) => void;
24
+ }
25
+ export interface SlackTurnRuntimeDependencies<TPreparedState> {
26
+ assistantUserName: string;
27
+ getChannelId: (thread: Thread, message: Message) => string | undefined;
28
+ getPreparedConversationContext: (preparedState: TPreparedState) => string | undefined;
29
+ getThreadId: (thread: Thread, message: Message) => string | undefined;
30
+ getRunId: (thread: Thread, message: Message) => string | undefined;
31
+ initializeAssistantThread: (event: {
32
+ channelId: string;
33
+ sourceChannelId?: string;
34
+ threadId: string;
35
+ threadTs: string;
36
+ }) => Promise<void>;
37
+ refreshAssistantThreadContext: (event: {
38
+ channelId: string;
39
+ sourceChannelId?: string;
40
+ threadId: string;
41
+ threadTs: string;
42
+ }) => Promise<void>;
43
+ logException: (error: unknown, eventName: string, context?: Record<string, unknown>, attributes?: Record<string, unknown>, body?: string) => string | undefined;
44
+ logWarn: (eventName: string, context?: Record<string, unknown>, attributes?: Record<string, unknown>, body?: string) => void;
45
+ modelId: string;
46
+ now: () => number;
47
+ recordSkippedSubscribedMessage: (args: {
48
+ completedAtMs: number;
49
+ decision: SubscribedReplyDecision;
50
+ message: Message;
51
+ thread: Thread;
52
+ userText: string;
53
+ }) => Promise<void>;
54
+ onSubscribedMessageSkipped: (args: {
55
+ completedAtMs: number;
56
+ decision: SubscribedReplyDecision;
57
+ message: Message;
58
+ preparedState?: TPreparedState;
59
+ thread: Thread;
60
+ }) => Promise<void>;
61
+ persistPreparedState: (args: {
62
+ preparedState: TPreparedState;
63
+ thread: Thread;
64
+ }) => Promise<void>;
65
+ prepareTurnState: (args: {
66
+ context: ThreadContext;
67
+ explicitMention: boolean;
68
+ message: Message;
69
+ thread: Thread;
70
+ userText: string;
71
+ }) => Promise<TPreparedState>;
72
+ replyToThread: (thread: Thread, message: Message, options?: {
73
+ beforeFirstResponsePost?: () => Promise<void>;
74
+ explicitMention?: boolean;
75
+ onToolInvocation?: (invocation: {
76
+ params: Record<string, unknown>;
77
+ toolName: string;
78
+ }) => void;
79
+ preparedState?: TPreparedState;
80
+ }) => Promise<void>;
81
+ decideSubscribedReply: (args: {
82
+ context: ThreadContext;
83
+ conversationContext?: string;
84
+ hasAttachments?: boolean;
85
+ isExplicitMention?: boolean;
86
+ rawText: string;
87
+ text: string;
88
+ }) => Promise<SubscribedReplyDecision>;
89
+ stripLeadingBotMention: (text: string, options: {
90
+ stripLeadingSlackMentionToken?: boolean;
91
+ }) => string;
92
+ withSpan: (name: string, op: string, context: Record<string, unknown>, callback: () => Promise<void>) => Promise<void>;
93
+ }
94
+ export interface SlackTurnRuntime<_TPreparedState, TAssistantEvent extends AssistantLifecycleEvent = AssistantLifecycleEvent> {
95
+ handleAssistantContextChanged: (event: TAssistantEvent) => Promise<void>;
96
+ handleAssistantThreadStarted: (event: TAssistantEvent) => Promise<void>;
97
+ handleNewMention: (thread: Thread, message: Message, hooks?: ReplyHooks) => Promise<void>;
98
+ handleSubscribedMessage: (thread: Thread, message: Message, hooks?: ReplyHooks) => Promise<void>;
99
+ }
100
+ export declare function createSlackTurnRuntime<TPreparedState, TAssistantEvent extends AssistantLifecycleEvent = AssistantLifecycleEvent>(deps: SlackTurnRuntimeDependencies<TPreparedState>): SlackTurnRuntime<TPreparedState, TAssistantEvent>;
@@ -0,0 +1,22 @@
1
+ import type { Message, Thread } from "chat";
2
+ export declare function stripLeadingBotMention(text: string, options?: {
3
+ stripLeadingSlackMentionToken?: boolean;
4
+ }): string;
5
+ export declare function getThreadId(thread: Thread, _message: Message): string | undefined;
6
+ export declare function getRunId(thread: Thread, message: Message): string | undefined;
7
+ export declare function getChannelId(thread: Thread, message: Message): string | undefined;
8
+ export declare function getThreadTs(threadId: string | undefined): string | undefined;
9
+ /**
10
+ * Resolve Slack assistant-thread API context for the current turn.
11
+ *
12
+ * Slack assistant-thread methods must use the live inbound thread context
13
+ * Slack provided on the current message. Slack's assistant utilities build
14
+ * `setStatus`/`setTitle` from `message.channel` plus `message.thread_ts ?? message.ts`
15
+ * for non-DM message events, while `message.im` still requires an explicit
16
+ * `thread_ts`. Do not synthesize assistant-thread roots from persisted state.
17
+ */
18
+ export declare function getAssistantThreadContext(message: Message): {
19
+ channelId: string;
20
+ threadTs: string;
21
+ } | undefined;
22
+ export declare function getMessageTs(message: Message): string | undefined;
@@ -0,0 +1,28 @@
1
+ import { type Thread } from "chat";
2
+ import type { ChannelConfigurationService } from "@/chat/configuration/types";
3
+ import type { ThreadConversationState } from "@/chat/state/conversation";
4
+ import { type ThreadArtifactsState } from "@/chat/state/artifacts";
5
+ export interface ThreadStatePatch {
6
+ artifacts?: ThreadArtifactsState;
7
+ conversation?: ThreadConversationState;
8
+ sandboxId?: string;
9
+ sandboxDependencyProfileHash?: string;
10
+ }
11
+ export interface PersistedSandboxState {
12
+ sandboxDependencyProfileHash?: string;
13
+ sandboxId?: string;
14
+ }
15
+ export declare function mergeArtifactsState(artifacts: ThreadArtifactsState, patch: Partial<ThreadArtifactsState> | undefined): ThreadArtifactsState;
16
+ /** Extract persisted sandbox metadata from thread state payload. */
17
+ export declare function getPersistedSandboxState(state: Record<string, unknown>): PersistedSandboxState;
18
+ /** Persist a thread-state patch through the Chat SDK thread interface. */
19
+ export declare function persistThreadState(thread: Thread, patch: ThreadStatePatch): Promise<void>;
20
+ /** Load the persisted state payload for a thread without requiring a Chat singleton. */
21
+ export declare function getPersistedThreadState(threadId: string): Promise<Record<string, unknown>>;
22
+ /** Load the persisted state payload for a channel without constructing a Chat channel. */
23
+ export declare function getPersistedChannelState(channelId: string): Promise<Record<string, unknown>>;
24
+ /** Persist a thread-state patch by thread id without constructing a Chat thread. */
25
+ export declare function persistThreadStateById(threadId: string, patch: ThreadStatePatch): Promise<void>;
26
+ export declare function getChannelConfigurationService(thread: Thread): ChannelConfigurationService;
27
+ /** Resolve a channel configuration service by channel id without a Chat thread. */
28
+ export declare function getChannelConfigurationServiceById(channelId: string): ChannelConfigurationService;
@@ -0,0 +1,43 @@
1
+ import type { Message, Thread } from "chat";
2
+ import type { ThreadConversationState } from "@/chat/state/conversation";
3
+ import { type ThreadArtifactsState } from "@/chat/state/artifacts";
4
+ import type { ChannelConfigurationService } from "@/chat/configuration/types";
5
+ export interface PreparedTurnState {
6
+ artifacts: ThreadArtifactsState;
7
+ configuration?: Record<string, unknown>;
8
+ channelConfiguration?: ChannelConfigurationService;
9
+ conversation: ThreadConversationState;
10
+ conversationContext?: string;
11
+ routingContext?: string;
12
+ sandboxId?: string;
13
+ sandboxDependencyProfileHash?: string;
14
+ userMessageId?: string;
15
+ }
16
+ export interface PrepareTurnStateDeps {
17
+ compactConversationIfNeeded: (conversation: ThreadConversationState, context: {
18
+ threadId?: string;
19
+ channelId?: string;
20
+ requesterId?: string;
21
+ runId?: string;
22
+ }) => Promise<void>;
23
+ hydrateConversationVisionContext: (conversation: ThreadConversationState, context: {
24
+ threadId?: string;
25
+ channelId?: string;
26
+ requesterId?: string;
27
+ runId?: string;
28
+ threadTs?: string;
29
+ }) => Promise<void>;
30
+ }
31
+ /** Build the turn-state preparer from injected conversation services. */
32
+ export declare function createPrepareTurnState(deps: PrepareTurnStateDeps): (args: {
33
+ explicitMention: boolean;
34
+ message: Message;
35
+ thread: Thread;
36
+ userText: string;
37
+ context: {
38
+ threadId?: string;
39
+ requesterId?: string;
40
+ channelId?: string;
41
+ runId?: string;
42
+ };
43
+ }) => Promise<PreparedTurnState>;
@@ -0,0 +1,12 @@
1
+ import type { ConversationMessage, ThreadConversationState } from "@/chat/state/conversation";
2
+ /** Return the user message for a persisted turn/session, if one exists. */
3
+ export declare function getTurnUserMessage(conversation: ThreadConversationState, sessionId: string): ConversationMessage | undefined;
4
+ /** Return the persisted user-message id for a turn/session, if one exists. */
5
+ export declare function getTurnUserMessageId(conversation: ThreadConversationState, sessionId: string): string | undefined;
6
+ /** Return the Slack timestamp for the user message that a resumed turn acts on. */
7
+ export declare function getTurnUserSlackMessageTs(message: ConversationMessage | undefined): string | undefined;
8
+ /** Rebuild attachment context for a resumed turn from the persisted user message. */
9
+ export declare function getTurnUserReplyAttachmentContext(message: ConversationMessage | undefined): {
10
+ inboundAttachmentCount?: number;
11
+ omittedImageAttachmentCount?: number;
12
+ };
@@ -0,0 +1,69 @@
1
+ import type { ThreadConversationState } from "@/chat/state/conversation";
2
+ import type { AuthorizationPauseDisposition, AuthorizationPauseKind } from "@/chat/services/auth-pause";
3
+ import type { TurnThinkingSelection } from "@/chat/services/turn-thinking-level";
4
+ import type { AgentTurnUsage } from "@/chat/usage";
5
+ export { buildDeterministicTurnId } from "@/chat/state/turn-id";
6
+ export type RetryableTurnReason = "mcp_auth_resume" | "plugin_auth_resume" | "turn_timeout_resume";
7
+ export interface RetryableTurnMetadata {
8
+ authDisposition?: AuthorizationPauseDisposition;
9
+ authDurationMs?: number;
10
+ authKind?: AuthorizationPauseKind;
11
+ authProvider?: string;
12
+ authThinkingLevel?: TurnThinkingSelection["thinkingLevel"];
13
+ authUsage?: AgentTurnUsage;
14
+ checkpointVersion?: number;
15
+ conversationId?: string;
16
+ sessionId?: string;
17
+ sliceId?: number;
18
+ }
19
+ /** Error indicating the turn can be retried (timeout or auth pause). */
20
+ export declare class RetryableTurnError extends Error {
21
+ readonly code = "retryable_turn";
22
+ readonly metadata?: RetryableTurnMetadata;
23
+ readonly reason: RetryableTurnReason;
24
+ constructor(reason: RetryableTurnReason, message: string, metadata?: RetryableTurnMetadata);
25
+ }
26
+ export declare function isRetryableTurnError(error: unknown, reason?: RetryableTurnReason): error is RetryableTurnError;
27
+ /** Mark a turn as the active turn in conversation state. */
28
+ export declare function startActiveTurn(args: {
29
+ conversation: ThreadConversationState;
30
+ nextTurnId: string;
31
+ updateConversationStats: (conversation: ThreadConversationState) => void;
32
+ }): void;
33
+ /**
34
+ * Close the active turn without marking a Pi session reusable for future
35
+ * history. Use this for auth handoffs and recovery replies that end the live
36
+ * turn but do not produce a completed Pi session.
37
+ */
38
+ export declare function markTurnClosed(args: {
39
+ conversation: ThreadConversationState;
40
+ nowMs: number;
41
+ sessionId?: string;
42
+ updateConversationStats: (conversation: ThreadConversationState) => void;
43
+ }): void;
44
+ /**
45
+ * Mark a turn as completed after final reply delivery succeeds and make its Pi
46
+ * session the reusable history source for the next turn.
47
+ */
48
+ export declare function markTurnCompleted(args: {
49
+ conversation: ThreadConversationState;
50
+ nowMs: number;
51
+ sessionId: string;
52
+ updateConversationStats: (conversation: ThreadConversationState) => void;
53
+ }): void;
54
+ /**
55
+ * Mark a turn as failed when execution or final user-visible reply delivery
56
+ * cannot be completed. If `sessionId` is provided, `activeTurnId` is only
57
+ * cleared when it still matches the failing turn.
58
+ */
59
+ export declare function markTurnFailed(args: {
60
+ conversation: ThreadConversationState;
61
+ nowMs: number;
62
+ sessionId?: string;
63
+ userMessageId?: string;
64
+ markConversationMessage: (conversation: ThreadConversationState, messageId: string | undefined, patch: {
65
+ replied?: boolean;
66
+ skippedReason?: string;
67
+ }) => void;
68
+ updateConversationStats: (conversation: ThreadConversationState) => void;
69
+ }): void;
@@ -0,0 +1,11 @@
1
+ interface VercelSandboxCredentials {
2
+ teamId: string;
3
+ projectId: string;
4
+ token: string;
5
+ }
6
+ /**
7
+ * Resolve explicit Vercel Sandbox credentials, or return undefined to let
8
+ * the SDK read ambient Vercel auth from its own environment detection.
9
+ */
10
+ export declare function getVercelSandboxCredentials(): VercelSandboxCredentials | undefined;
11
+ export {};
@@ -0,0 +1,3 @@
1
+ import { type JWTPayload } from "jose";
2
+ /** Verify Vercel signed this Sandbox firewall proxy request for the active VM session. */
3
+ export declare function verifyVercelSandboxOidcToken(token: string): Promise<JWTPayload>;
@@ -0,0 +1,11 @@
1
+ import type { NetworkPolicy } from "@vercel/sandbox";
2
+ /** Return whether an outbound host is covered by a sandbox egress domain rule. */
3
+ export declare function matchesSandboxEgressDomain(host: string, domain: string): boolean;
4
+ /** Resolve the plugin provider responsible for an outbound sandbox host. */
5
+ export declare function resolveSandboxEgressProviderForHost(host: string): string | undefined;
6
+ /** Build the policy that forwards provider requests back to Junior for credentials. */
7
+ export declare function buildSandboxEgressNetworkPolicy(input?: {
8
+ requesterToken?: string;
9
+ }): NetworkPolicy;
10
+ /** Resolve non-secret command environment values for registered sandbox providers. */
11
+ export declare function resolveSandboxCommandEnvironment(): Promise<Record<string, string>>;
@@ -0,0 +1,10 @@
1
+ import type { JWTPayload } from "jose";
2
+ interface ProxyDeps {
3
+ fetch?: typeof fetch;
4
+ verifyOidc?: (token: string) => Promise<JWTPayload>;
5
+ }
6
+ /** Return whether a request appears to be from the Vercel Sandbox egress proxy. */
7
+ export declare function isSandboxEgressForwardedRequest(request: Request): boolean;
8
+ /** Proxy one Vercel Sandbox firewall egress request through lazy credential injection. */
9
+ export declare function proxySandboxEgressRequest(request: Request, deps?: ProxyDeps): Promise<Response>;
10
+ export {};