@sentry/junior 0.53.0 → 0.55.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 (239) hide show
  1. package/README.md +4 -3
  2. package/dist/api-reference.d.ts +7 -0
  3. package/dist/app.d.ts +14 -12
  4. package/dist/app.js +12977 -10333
  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/agent-dispatch/context.d.ts +6 -0
  10. package/dist/chat/agent-dispatch/heartbeat.d.ts +14 -0
  11. package/dist/chat/agent-dispatch/runner.d.ts +9 -0
  12. package/dist/chat/agent-dispatch/signing.d.ts +5 -0
  13. package/dist/chat/agent-dispatch/store.d.ts +29 -0
  14. package/dist/chat/agent-dispatch/types.d.ts +57 -0
  15. package/dist/chat/agent-dispatch/validation.d.ts +3 -0
  16. package/dist/chat/app/factory.d.ts +10 -0
  17. package/dist/chat/app/production.d.ts +6 -0
  18. package/dist/chat/app/services.d.ts +17 -0
  19. package/dist/chat/capabilities/catalog.d.ts +16 -0
  20. package/dist/chat/capabilities/factory.d.ts +10 -0
  21. package/dist/chat/capabilities/jr-rpc-command.d.ts +26 -0
  22. package/dist/chat/capabilities/router.d.ts +19 -0
  23. package/dist/chat/coerce.d.ts +6 -0
  24. package/dist/chat/config.d.ts +47 -0
  25. package/dist/chat/configuration/defaults.d.ts +4 -0
  26. package/dist/chat/configuration/service.d.ts +2 -0
  27. package/dist/chat/configuration/types.d.ts +37 -0
  28. package/dist/chat/configuration/validation.d.ts +2 -0
  29. package/dist/chat/credentials/broker.d.ts +22 -0
  30. package/dist/chat/credentials/header-transforms.d.ts +3 -0
  31. package/dist/chat/credentials/oauth-scope.d.ts +4 -0
  32. package/dist/chat/credentials/state-adapter-token-store.d.ts +9 -0
  33. package/dist/chat/credentials/unlink-provider.d.ts +2 -0
  34. package/dist/chat/credentials/user-token-store.d.ts +11 -0
  35. package/dist/chat/discovery.d.ts +47 -0
  36. package/dist/chat/ingress/junior-chat.d.ts +26 -0
  37. package/dist/chat/ingress/message-changed.d.ts +50 -0
  38. package/dist/chat/ingress/message-router.d.ts +9 -0
  39. package/dist/chat/ingress/slash-command.d.ts +3 -0
  40. package/dist/chat/ingress/workspace-membership.d.ts +9 -0
  41. package/dist/chat/interruption-marker.d.ts +2 -0
  42. package/dist/chat/logging.d.ts +90 -0
  43. package/dist/chat/mcp/auth-store.d.ts +41 -0
  44. package/dist/chat/mcp/client.d.ts +34 -0
  45. package/dist/chat/mcp/errors.d.ts +8 -0
  46. package/dist/chat/mcp/oauth-provider.d.ts +27 -0
  47. package/dist/chat/mcp/oauth.d.ts +17 -0
  48. package/dist/chat/mcp/tool-manager.d.ts +60 -0
  49. package/dist/chat/oauth-flow.d.ts +45 -0
  50. package/dist/chat/optional-string.d.ts +5 -0
  51. package/dist/chat/pi/client.d.ts +49 -0
  52. package/dist/chat/pi/messages.d.ts +3 -0
  53. package/dist/chat/pi/traced-stream.d.ts +9 -0
  54. package/dist/chat/plugins/agent-hooks.d.ts +32 -0
  55. package/dist/chat/plugins/auth/api-headers-broker.d.ts +6 -0
  56. package/dist/chat/plugins/auth/auth-token-placeholder.d.ts +3 -0
  57. package/dist/chat/plugins/auth/github-app-broker.d.ts +4 -0
  58. package/dist/chat/plugins/auth/oauth-bearer-broker.d.ts +6 -0
  59. package/dist/chat/plugins/auth/oauth-request.d.ts +18 -0
  60. package/dist/chat/plugins/command-env.d.ts +3 -0
  61. package/dist/chat/plugins/logging.d.ts +3 -0
  62. package/dist/chat/plugins/manifest.d.ts +3 -0
  63. package/dist/chat/plugins/package-discovery.d.ts +14 -0
  64. package/dist/chat/plugins/registry.d.ts +23 -0
  65. package/dist/chat/plugins/state.d.ts +3 -0
  66. package/dist/chat/plugins/types.d.ts +146 -0
  67. package/dist/chat/prompt.d.ts +39 -0
  68. package/dist/chat/queue/thread-message-dispatcher.d.ts +33 -0
  69. package/dist/chat/respond-helpers.d.ts +77 -0
  70. package/dist/chat/respond.d.ts +75 -0
  71. package/dist/chat/runtime/auth-pause-state.d.ts +11 -0
  72. package/dist/chat/runtime/delivered-turn-state.d.ts +15 -0
  73. package/dist/chat/runtime/dev-agent-trace.d.ts +1 -0
  74. package/dist/chat/runtime/processing-reaction.d.ts +25 -0
  75. package/dist/chat/runtime/reply-executor.d.ts +56 -0
  76. package/dist/chat/runtime/report-progress.d.ts +3 -0
  77. package/dist/chat/runtime/slack-resume.d.ts +50 -0
  78. package/dist/chat/runtime/slack-runtime.d.ts +100 -0
  79. package/dist/chat/runtime/thread-context.d.ts +24 -0
  80. package/dist/chat/runtime/thread-state.d.ts +28 -0
  81. package/dist/chat/runtime/turn-preparation.d.ts +43 -0
  82. package/dist/chat/runtime/turn-user-message.d.ts +12 -0
  83. package/dist/chat/runtime/turn.d.ts +69 -0
  84. package/dist/chat/sandbox/credentials.d.ts +11 -0
  85. package/dist/chat/sandbox/egress-oidc.d.ts +3 -0
  86. package/dist/chat/sandbox/egress-policy.d.ts +11 -0
  87. package/dist/chat/sandbox/egress-proxy.d.ts +17 -0
  88. package/dist/chat/sandbox/egress-session.d.ts +27 -0
  89. package/dist/chat/sandbox/errors.d.ts +12 -0
  90. package/dist/chat/sandbox/http-error-details.d.ts +18 -0
  91. package/dist/chat/sandbox/noninteractive-command.d.ts +17 -0
  92. package/dist/chat/sandbox/paths.d.ts +5 -0
  93. package/dist/chat/sandbox/runtime-dependency-snapshots.d.ts +20 -0
  94. package/dist/chat/sandbox/sandbox.d.ts +54 -0
  95. package/dist/chat/sandbox/session.d.ts +54 -0
  96. package/dist/chat/sandbox/skill-sandbox.d.ts +42 -0
  97. package/dist/chat/sandbox/skill-sync.d.ts +16 -0
  98. package/dist/chat/sandbox/workspace.d.ts +55 -0
  99. package/dist/chat/scheduler/cadence.d.ts +24 -0
  100. package/dist/chat/scheduler/plugin.d.ts +2 -0
  101. package/dist/chat/scheduler/prompt.d.ts +7 -0
  102. package/dist/chat/scheduler/store.d.ts +49 -0
  103. package/dist/chat/scheduler/types.d.ts +86 -0
  104. package/dist/chat/sentry.d.ts +2 -0
  105. package/dist/chat/services/attachment-claims.d.ts +2 -0
  106. package/dist/chat/services/auth-pause-response.d.ts +2 -0
  107. package/dist/chat/services/auth-pause.d.ts +19 -0
  108. package/dist/chat/services/channel-intent.d.ts +2 -0
  109. package/dist/chat/services/conversation-memory.d.ts +33 -0
  110. package/dist/chat/services/mcp-auth-orchestration.d.ts +30 -0
  111. package/dist/chat/services/pending-auth.d.ts +27 -0
  112. package/dist/chat/services/plugin-auth-orchestration.d.ts +37 -0
  113. package/dist/chat/services/provider-default-config.d.ts +9 -0
  114. package/dist/chat/services/provider-retry.d.ts +6 -0
  115. package/dist/chat/services/reply-delivery-plan.d.ts +17 -0
  116. package/dist/chat/services/subscribed-decision.d.ts +63 -0
  117. package/dist/chat/services/subscribed-reply-policy.d.ts +23 -0
  118. package/dist/chat/services/timeout-resume.d.ts +17 -0
  119. package/dist/chat/services/turn-checkpoint.d.ts +74 -0
  120. package/dist/chat/services/turn-continuation-response.d.ts +2 -0
  121. package/dist/chat/services/turn-failure-response.d.ts +15 -0
  122. package/dist/chat/services/turn-result.d.ts +55 -0
  123. package/dist/chat/services/turn-thinking-level.d.ts +49 -0
  124. package/dist/chat/services/vision-context.d.ts +61 -0
  125. package/dist/chat/skills.d.ts +48 -0
  126. package/dist/chat/slack/adapter.d.ts +9 -0
  127. package/dist/chat/slack/app-home.d.ts +11 -0
  128. package/dist/chat/slack/assistant-thread/lifecycle.d.ts +13 -0
  129. package/dist/chat/slack/assistant-thread/status-render.d.ts +28 -0
  130. package/dist/chat/slack/assistant-thread/status-scheduler.d.ts +23 -0
  131. package/dist/chat/slack/assistant-thread/status-send.d.ts +31 -0
  132. package/dist/chat/slack/assistant-thread/status.d.ts +36 -0
  133. package/dist/chat/slack/assistant-thread/title.d.ts +28 -0
  134. package/dist/chat/slack/canvas-references.d.ts +2 -0
  135. package/dist/chat/slack/channel.d.ts +48 -0
  136. package/dist/chat/slack/client.d.ts +52 -0
  137. package/dist/chat/slack/context.d.ts +9 -0
  138. package/dist/chat/slack/emoji.d.ts +1 -0
  139. package/dist/chat/slack/errors.d.ts +6 -0
  140. package/dist/chat/slack/footer.d.ts +42 -0
  141. package/dist/chat/slack/ids.d.ts +4 -0
  142. package/dist/chat/slack/legacy-attachments.d.ts +4 -0
  143. package/dist/chat/slack/message.d.ts +6 -0
  144. package/dist/chat/slack/mrkdwn.d.ts +12 -0
  145. package/dist/chat/slack/outbound.d.ts +57 -0
  146. package/dist/chat/slack/output.d.ts +54 -0
  147. package/dist/chat/slack/reply.d.ts +33 -0
  148. package/dist/chat/slack/status-format.d.ts +2 -0
  149. package/dist/chat/slack/turn-continuation-notice.d.ts +8 -0
  150. package/dist/chat/slack/user.d.ts +8 -0
  151. package/dist/chat/slack/users.d.ts +39 -0
  152. package/dist/chat/slack/workspace-context.d.ts +4 -0
  153. package/dist/chat/state/adapter.d.ts +9 -0
  154. package/dist/chat/state/artifacts.d.ts +29 -0
  155. package/dist/chat/state/conversation.d.ts +81 -0
  156. package/dist/chat/state/pi-session-message-store.d.ts +15 -0
  157. package/dist/chat/state/turn-id.d.ts +2 -0
  158. package/dist/chat/state/turn-session-store.d.ts +49 -0
  159. package/dist/chat/tools/advisor/session-store.d.ts +9 -0
  160. package/dist/chat/tools/advisor/tool.d.ts +33 -0
  161. package/dist/chat/tools/agent-tools.d.ts +10 -0
  162. package/dist/chat/tools/channel-capabilities.d.ts +11 -0
  163. package/dist/chat/tools/definition.d.ts +17 -0
  164. package/dist/chat/tools/execution/build-sandbox-input.d.ts +2 -0
  165. package/dist/chat/tools/execution/normalize-result.d.ts +6 -0
  166. package/dist/chat/tools/execution/tool-error-handler.d.ts +3 -0
  167. package/dist/chat/tools/execution/tool-input-error.d.ts +6 -0
  168. package/dist/chat/tools/idempotency.d.ts +1 -0
  169. package/dist/chat/tools/index.d.ts +5 -0
  170. package/dist/chat/tools/runtime/report-progress.d.ts +4 -0
  171. package/dist/chat/tools/sandbox/attach-file.d.ts +7 -0
  172. package/dist/chat/tools/sandbox/bash.d.ts +5 -0
  173. package/dist/chat/tools/sandbox/edit-file.d.ts +37 -0
  174. package/dist/chat/tools/sandbox/file-utils.d.ts +52 -0
  175. package/dist/chat/tools/sandbox/find-files.d.ts +24 -0
  176. package/dist/chat/tools/sandbox/grep.d.ts +33 -0
  177. package/dist/chat/tools/sandbox/list-dir.d.ts +22 -0
  178. package/dist/chat/tools/sandbox/read-file.d.ts +32 -0
  179. package/dist/chat/tools/sandbox/text-edits.d.ts +28 -0
  180. package/dist/chat/tools/sandbox/write-file.d.ts +5 -0
  181. package/dist/chat/tools/skill/call-mcp-tool.d.ts +7 -0
  182. package/dist/chat/tools/skill/load-skill.d.ts +22 -0
  183. package/dist/chat/tools/skill/mcp-tool-summary.d.ts +31 -0
  184. package/dist/chat/tools/skill/search-mcp-tools.d.ts +8 -0
  185. package/dist/chat/tools/slack/canvas-tools.d.ts +29 -0
  186. package/dist/chat/tools/slack/canvases.d.ts +45 -0
  187. package/dist/chat/tools/slack/channel-list-messages.d.ts +9 -0
  188. package/dist/chat/tools/slack/channel-post-message.d.ts +4 -0
  189. package/dist/chat/tools/slack/list-tools.d.ts +21 -0
  190. package/dist/chat/tools/slack/lists.d.ts +42 -0
  191. package/dist/chat/tools/slack/message-add-reaction.d.ts +4 -0
  192. package/dist/chat/tools/slack/schedule-tools.d.ts +29 -0
  193. package/dist/chat/tools/slack/slack-message-url.d.ts +18 -0
  194. package/dist/chat/tools/slack/thread-read.d.ts +9 -0
  195. package/dist/chat/tools/slack/user-lookup.d.ts +8 -0
  196. package/dist/chat/tools/system-time.d.ts +1 -0
  197. package/dist/chat/tools/types.d.ts +61 -0
  198. package/dist/chat/tools/web/constants.d.ts +6 -0
  199. package/dist/chat/tools/web/fetch-content.d.ts +23 -0
  200. package/dist/chat/tools/web/fetch-tool.d.ts +5 -0
  201. package/dist/chat/tools/web/image-generate.d.ts +4 -0
  202. package/dist/chat/tools/web/network.d.ts +6 -0
  203. package/dist/chat/tools/web/search.d.ts +5 -0
  204. package/dist/chat/turn-context-tag.d.ts +6 -0
  205. package/dist/chat/usage.d.ts +24 -0
  206. package/dist/chat/xml.d.ts +1 -0
  207. package/dist/{chunk-XPXD3FCE.js → chunk-5LUISFEY.js} +189 -35
  208. package/dist/{chunk-ZNFNY53B.js → chunk-D3G3YOU4.js} +2 -2
  209. package/dist/chunk-SCQPBJAU.js +21 -0
  210. package/dist/{chunk-Q3FDONU7.js → chunk-TTUY467K.js} +47 -37
  211. package/dist/{chunk-KCOKQLBF.js → chunk-XI3CFWTA.js} +168 -15
  212. package/dist/cli/check.js +3 -3
  213. package/dist/cli/init.js +6 -1
  214. package/dist/cli/snapshot-warmup.js +3 -3
  215. package/dist/handlers/agent-dispatch.d.ts +3 -0
  216. package/dist/handlers/diagnostics-dashboard.d.ts +2 -0
  217. package/dist/handlers/diagnostics.d.ts +2 -0
  218. package/dist/handlers/health.d.ts +4 -0
  219. package/dist/handlers/heartbeat.d.ts +3 -0
  220. package/dist/handlers/mcp-oauth-callback.d.ts +2 -0
  221. package/dist/handlers/oauth-callback.d.ts +2 -0
  222. package/dist/handlers/oauth-html.d.ts +2 -0
  223. package/dist/handlers/sandbox-egress-proxy.d.ts +9 -0
  224. package/dist/handlers/turn-resume.d.ts +3 -0
  225. package/dist/handlers/types.d.ts +2 -0
  226. package/dist/handlers/webhooks.d.ts +15 -0
  227. package/dist/instrumentation.d.ts +1 -3
  228. package/dist/nitro.d.ts +4 -7
  229. package/dist/nitro.js +112 -54
  230. package/dist/package-resolution.d.ts +13 -0
  231. package/dist/vercel.d.ts +2 -4
  232. package/dist/vercel.js +3 -12
  233. package/package.json +32 -26
  234. package/dist/cli/check.d.ts +0 -8
  235. package/dist/cli/env.d.ts +0 -7
  236. package/dist/cli/init.d.ts +0 -3
  237. package/dist/cli/run.d.ts +0 -12
  238. package/dist/cli/snapshot-warmup.d.ts +0 -3
  239. package/dist/types-X_iCClPb.d.ts +0 -75
@@ -0,0 +1,90 @@
1
+ import type { Logger as ChatSdkLogger } from "chat";
2
+ import * as Sentry from "@/chat/sentry";
3
+ import type { AgentTurnUsage } from "@/chat/usage";
4
+ type Primitive = string | number | boolean;
5
+ type AttributeValue = Primitive | string[];
6
+ export type LogAttributes = Record<string, AttributeValue>;
7
+ export type LogLevel = "debug" | "info" | "warn" | "error";
8
+ export interface EmittedLogRecord {
9
+ attributes: LogAttributes;
10
+ body: string;
11
+ eventName: string;
12
+ level: LogLevel;
13
+ }
14
+ export interface LogContext {
15
+ conversationId?: string;
16
+ platform?: string;
17
+ requestId?: string;
18
+ slackThreadId?: string;
19
+ slackUserId?: string;
20
+ slackUserName?: string;
21
+ slackChannelId?: string;
22
+ runId?: string;
23
+ actorType?: string;
24
+ actorId?: string;
25
+ assistantUserName?: string;
26
+ modelId?: string;
27
+ skillName?: string;
28
+ httpMethod?: string;
29
+ httpPath?: string;
30
+ urlFull?: string;
31
+ userAgent?: string;
32
+ }
33
+ export declare const log: {
34
+ debug(eventName: string, attrs?: Record<string, unknown>, body?: string): void;
35
+ info(eventName: string, attrs?: Record<string, unknown>, body?: string): void;
36
+ warn(eventName: string, attrs?: Record<string, unknown>, body?: string): void;
37
+ error(eventName: string, attrs?: Record<string, unknown>, body?: string): void;
38
+ exception(eventName: string, error: unknown, attrs?: Record<string, unknown>, body?: string): string | undefined;
39
+ };
40
+ /** Create a Chat SDK logger that routes records through Junior's logging backend. */
41
+ export declare function createChatSdkLogger(): ChatSdkLogger;
42
+ export declare function withLogContext<T>(context: LogContext, callback: () => Promise<T>): Promise<T>;
43
+ export declare function setLogContext(context: LogContext): void;
44
+ export declare function getLogContextAttributes(): LogAttributes;
45
+ export declare function registerLogRecordSink(sink: (record: EmittedLogRecord) => void): () => void;
46
+ export declare function createLogContextFromRequest(request: Request, context?: Partial<LogContext>): LogContext;
47
+ export declare function toSpanAttributes(context: LogContext): Record<string, string>;
48
+ export declare function setSentryTagsFromContext(context: LogContext): void;
49
+ export declare function setSentryScopeContext(scope: Sentry.Scope, context: LogContext): void;
50
+ /** Capture an error to Sentry and emit an error log record. */
51
+ export declare function captureException(error: unknown, context?: LogContext): void;
52
+ /** Log an info-level structured event. */
53
+ export declare function logInfo(eventName: string, context?: LogContext, attributes?: Record<string, unknown>, body?: string): void;
54
+ /** Log a warning-level structured event. */
55
+ export declare function logWarn(eventName: string, context?: LogContext, attributes?: Record<string, unknown>, body?: string): void;
56
+ /** Log an error-level structured event. */
57
+ export declare function logError(eventName: string, context?: LogContext, attributes?: Record<string, unknown>, body?: string): void;
58
+ /** Log an error with exception capture; returns the Sentry event ID if available. */
59
+ export declare function logException(error: unknown, eventName: string, context?: LogContext, attributes?: Record<string, unknown>, body?: string): string | undefined;
60
+ /** Set log context and Sentry tags for the current scope. */
61
+ export declare function setTags(context?: LogContext): void;
62
+ /** Create a LogContext from an incoming HTTP request. */
63
+ export declare function createRequestContext(request: Request, context?: Partial<LogContext>): LogContext;
64
+ /** Run a callback within a scoped log context. */
65
+ export declare function withContext<T>(context: LogContext, callback: () => Promise<T>): Promise<T>;
66
+ /** Run a callback within a Sentry span and scoped log context. */
67
+ export declare function withSpan<T>(name: string, op: string, context: LogContext, callback: () => Promise<T>, attributes?: Record<string, unknown>): Promise<T>;
68
+ /** Set attributes on the currently active Sentry span. */
69
+ export declare function setSpanAttributes(attributes: Record<string, unknown>): void;
70
+ /** Set the status of the currently active Sentry span. */
71
+ export declare function setSpanStatus(status: "ok" | "error"): void;
72
+ /** Capture an exception within an isolated Sentry scope. */
73
+ export declare function captureExceptionInScope(error: unknown, context?: LogContext): void;
74
+ /** Return the trace ID from the active Sentry span, if any. */
75
+ export declare function getActiveTraceId(): string | undefined;
76
+ /** Build the static user-facing response for a failed turn. */
77
+ export declare function buildTurnFailureResponse(eventId: string): string;
78
+ /** Serialize an AI model response value into a truncated log attribute. */
79
+ export declare function serializeGenAiAttribute(value: unknown, maxChars?: number): string | undefined;
80
+ /**
81
+ * Sum pi-ai `Usage` counters across every source into an `AgentTurnUsage`.
82
+ *
83
+ * Callers pass every assistant message produced during a turn so the result
84
+ * reflects the aggregate usage for the entire turn rather than a single model
85
+ * call. Sources without a recognized usage record contribute nothing.
86
+ */
87
+ export declare function extractGenAiUsageSummary(...sources: unknown[]): AgentTurnUsage;
88
+ /** Extract GenAI token usage attributes from AI provider usage metadata for tracing. */
89
+ export declare function extractGenAiUsageAttributes(...sources: unknown[]): Partial<Record<"gen_ai.usage.input_tokens" | "gen_ai.usage.output_tokens" | "gen_ai.usage.cache_read.input_tokens" | "gen_ai.usage.cache_creation.input_tokens", number>>;
90
+ export {};
@@ -0,0 +1,41 @@
1
+ import type { OAuthClientInformationMixed, OAuthTokens } from "@modelcontextprotocol/sdk/shared/auth.js";
2
+ import type { OAuthDiscoveryState } from "@modelcontextprotocol/sdk/client/auth.js";
3
+ import type { ThreadArtifactsState } from "@/chat/state/artifacts";
4
+ export interface McpAuthSessionState {
5
+ authSessionId: string;
6
+ provider: string;
7
+ userId: string;
8
+ conversationId: string;
9
+ sessionId: string;
10
+ userMessage: string;
11
+ channelId?: string;
12
+ threadTs?: string;
13
+ toolChannelId?: string;
14
+ configuration?: Record<string, unknown>;
15
+ artifactState?: ThreadArtifactsState;
16
+ authorizationUrl?: string;
17
+ codeVerifier?: string;
18
+ createdAtMs: number;
19
+ updatedAtMs: number;
20
+ }
21
+ export interface McpStoredOAuthCredentials {
22
+ clientInformation?: OAuthClientInformationMixed;
23
+ discoveryState?: OAuthDiscoveryState;
24
+ tokens?: OAuthTokens;
25
+ }
26
+ export interface McpServerSessionState {
27
+ sessionId: string;
28
+ updatedAtMs: number;
29
+ }
30
+ export declare function getMcpAuthSession(authSessionId: string): Promise<McpAuthSessionState | undefined>;
31
+ export declare function putMcpAuthSession(session: McpAuthSessionState, ttlMs?: number): Promise<void>;
32
+ export declare function patchMcpAuthSession(authSessionId: string, patch: Partial<McpAuthSessionState>): Promise<McpAuthSessionState>;
33
+ export declare function deleteMcpAuthSession(authSessionId: string): Promise<void>;
34
+ export declare function deleteMcpAuthSessionsForUserProvider(userId: string, provider: string): Promise<void>;
35
+ export declare function getLatestMcpAuthSessionForUserProvider(userId: string, provider: string): Promise<McpAuthSessionState | undefined>;
36
+ export declare function getMcpStoredOAuthCredentials(userId: string, provider: string): Promise<McpStoredOAuthCredentials | undefined>;
37
+ export declare function putMcpStoredOAuthCredentials(userId: string, provider: string, value: McpStoredOAuthCredentials, ttlMs?: number): Promise<void>;
38
+ export declare function deleteMcpStoredOAuthCredentials(userId: string, provider: string): Promise<void>;
39
+ export declare function getMcpServerSessionId(userId: string, provider: string): Promise<string | undefined>;
40
+ export declare function putMcpServerSessionId(userId: string, provider: string, sessionId: string, ttlMs?: number): Promise<void>;
41
+ export declare function deleteMcpServerSessionId(userId: string, provider: string): Promise<void>;
@@ -0,0 +1,34 @@
1
+ import { Client } from "@modelcontextprotocol/sdk/client";
2
+ import { type OAuthClientProvider } from "@modelcontextprotocol/sdk/client/auth.js";
3
+ import type { PluginDefinition } from "@/chat/plugins/types";
4
+ type ListedTool = Awaited<ReturnType<Client["listTools"]>>["tools"][number];
5
+ type ToolCallResult = Awaited<ReturnType<Client["callTool"]>>;
6
+ export declare class McpAuthorizationRequiredError extends Error {
7
+ readonly provider: string;
8
+ constructor(provider: string, message: string);
9
+ }
10
+ export interface PluginMcpClientOptions {
11
+ authProvider?: OAuthClientProvider;
12
+ fetch?: typeof fetch;
13
+ }
14
+ export declare class PluginMcpClient {
15
+ private readonly plugin;
16
+ private readonly options;
17
+ private client?;
18
+ private lastAttemptedTransportSessionId?;
19
+ private transport?;
20
+ private listedTools?;
21
+ constructor(plugin: PluginDefinition, options?: PluginMcpClientOptions);
22
+ listTools(): Promise<ListedTool[]>;
23
+ callTool(name: string, args: Record<string, unknown> | undefined): Promise<ToolCallResult>;
24
+ close(): Promise<void>;
25
+ private withSessionRecovery;
26
+ private getClient;
27
+ private wrapAuth;
28
+ private shouldResetMissingSession;
29
+ private disposeClient;
30
+ private getStoredTransportSessionId;
31
+ private clearStoredTransportSessionId;
32
+ private syncTransportSessionId;
33
+ }
34
+ export type { ListedTool as PluginMcpListedTool, ToolCallResult as PluginMcpToolCallResult, };
@@ -0,0 +1,8 @@
1
+ /** Thrown when an MCP tool returns an error result. */
2
+ export declare class McpToolError extends Error {
3
+ constructor(message: string);
4
+ }
5
+ /** Return the OpenTelemetry error.type value for MCP-aware tool failures. */
6
+ export declare function getMcpAwareErrorType(error: unknown, fallback: string): string;
7
+ /** Return the display-safe error message for MCP-aware tool failures. */
8
+ export declare function getMcpAwareErrorMessage(error: unknown): string;
@@ -0,0 +1,27 @@
1
+ import type { OAuthClientInformationMixed, OAuthClientMetadata, OAuthTokens } from "@modelcontextprotocol/sdk/shared/auth.js";
2
+ import type { OAuthClientProvider, OAuthDiscoveryState } from "@modelcontextprotocol/sdk/client/auth.js";
3
+ import { type McpAuthSessionState } from "./auth-store";
4
+ export declare class StateBackedMcpOAuthClientProvider implements OAuthClientProvider {
5
+ readonly authSessionId: string;
6
+ private readonly callbackUrl;
7
+ private readonly sessionContext?;
8
+ readonly clientMetadata: OAuthClientMetadata;
9
+ constructor(authSessionId: string, callbackUrl: string, sessionContext?: Omit<McpAuthSessionState, "authSessionId" | "authorizationUrl" | "codeVerifier" | "createdAtMs" | "updatedAtMs"> | undefined);
10
+ get redirectUrl(): string;
11
+ state(): Promise<string>;
12
+ clientInformation(): Promise<OAuthClientInformationMixed | undefined>;
13
+ saveClientInformation(clientInformation: OAuthClientInformationMixed): Promise<void>;
14
+ tokens(): Promise<OAuthTokens | undefined>;
15
+ saveTokens(tokens: OAuthTokens): Promise<void>;
16
+ redirectToAuthorization(authorizationUrl: URL): Promise<void>;
17
+ saveCodeVerifier(codeVerifier: string): Promise<void>;
18
+ codeVerifier(): Promise<string>;
19
+ saveDiscoveryState(state: OAuthDiscoveryState): Promise<void>;
20
+ discoveryState(): Promise<OAuthDiscoveryState | undefined>;
21
+ invalidateCredentials(scope: "all" | "client" | "tokens" | "verifier" | "discovery"): Promise<void>;
22
+ getMcpServerSessionId(): Promise<string | undefined>;
23
+ saveMcpServerSessionId(sessionId: string | undefined): Promise<void>;
24
+ private getCredentialContext;
25
+ private ensureSession;
26
+ private requireSession;
27
+ }
@@ -0,0 +1,17 @@
1
+ import type { ThreadArtifactsState } from "@/chat/state/artifacts";
2
+ import { type McpAuthSessionState } from "./auth-store";
3
+ import { StateBackedMcpOAuthClientProvider } from "./oauth-provider";
4
+ export declare function getMcpOAuthCallbackPath(provider: string): string;
5
+ export declare function createMcpOAuthClientProvider(input: {
6
+ provider: string;
7
+ conversationId: string;
8
+ sessionId: string;
9
+ userId: string;
10
+ userMessage: string;
11
+ channelId?: string;
12
+ threadTs?: string;
13
+ toolChannelId?: string;
14
+ configuration?: Record<string, unknown>;
15
+ artifactState?: ThreadArtifactsState;
16
+ }): Promise<StateBackedMcpOAuthClientProvider>;
17
+ export declare function finalizeMcpAuthorization(provider: string, authSessionId: string, authorizationCode: string): Promise<McpAuthSessionState>;
@@ -0,0 +1,60 @@
1
+ import type { ImageContent, TextContent } from "@earendil-works/pi-ai";
2
+ import type { OAuthClientProvider } from "@modelcontextprotocol/sdk/client/auth.js";
3
+ import type { SkillMetadata } from "@/chat/skills";
4
+ import type { PluginDefinition } from "@/chat/plugins/types";
5
+ import { McpAuthorizationRequiredError, type PluginMcpToolCallResult } from "./client";
6
+ export interface McpToolManagerOptions {
7
+ authProviderFactory?: (plugin: PluginDefinition) => OAuthClientProvider | undefined | Promise<OAuthClientProvider | undefined>;
8
+ fetch?: typeof fetch;
9
+ onAuthorizationRequired?: (provider: string, error: McpAuthorizationRequiredError) => Promise<boolean | void> | boolean | void;
10
+ }
11
+ export interface ManagedMcpToolResult {
12
+ content: Array<TextContent | ImageContent>;
13
+ details: {
14
+ provider: string;
15
+ tool: string;
16
+ rawResult: PluginMcpToolCallResult;
17
+ };
18
+ }
19
+ export interface ManagedMcpToolDescriptor {
20
+ name: string;
21
+ rawName: string;
22
+ title?: string;
23
+ description: string;
24
+ parameters: Record<string, unknown>;
25
+ outputSchema?: Record<string, unknown>;
26
+ annotations?: Record<string, unknown>;
27
+ provider: string;
28
+ }
29
+ type ActiveMcpSkillScope = Pick<SkillMetadata, "pluginProvider">;
30
+ type ActiveMcpSkill = Pick<SkillMetadata, "name" | "pluginProvider">;
31
+ export interface ManagedMcpTool extends ManagedMcpToolDescriptor {
32
+ execute: (args: Record<string, unknown>) => Promise<ManagedMcpToolResult>;
33
+ }
34
+ export declare class McpToolManager {
35
+ private readonly options;
36
+ private readonly pluginsByProvider;
37
+ private readonly activeProviders;
38
+ private readonly authorizationPendingProviders;
39
+ private readonly clientsByProvider;
40
+ private readonly toolsByProvider;
41
+ constructor(plugins: PluginDefinition[], options?: McpToolManagerOptions);
42
+ getActiveProviders(): string[];
43
+ activateForSkill(skill: ActiveMcpSkill): Promise<boolean>;
44
+ activateProvider(provider: string): Promise<boolean>;
45
+ close(): Promise<void>;
46
+ getActiveToolCatalog(skills: ActiveMcpSkillScope[], options?: {
47
+ provider?: string;
48
+ }): ManagedMcpToolDescriptor[];
49
+ private filterListedTools;
50
+ private getClient;
51
+ private toManagedTool;
52
+ private handleAuthorizationRequired;
53
+ /** Return all active ManagedMcpTool objects for the given skill scope. */
54
+ getResolvedActiveTools(skills: ActiveMcpSkillScope[], options?: {
55
+ provider?: string;
56
+ }): ManagedMcpTool[];
57
+ private resolveProviderTools;
58
+ private toToolDescriptor;
59
+ }
60
+ export {};
@@ -0,0 +1,45 @@
1
+ import type { ChannelConfigurationService } from "@/chat/configuration/types";
2
+ type PrivateDeliveryResult = "in_context" | "fallback_dm" | false;
3
+ export type OAuthStatePayload = {
4
+ userId: string;
5
+ provider: string;
6
+ channelId?: string;
7
+ threadTs?: string;
8
+ pendingMessage?: string;
9
+ configuration?: Record<string, unknown>;
10
+ resumeConversationId?: string;
11
+ resumeSessionId?: string;
12
+ };
13
+ type OAuthFlowInput = {
14
+ requesterId: string;
15
+ channelId?: string;
16
+ threadTs?: string;
17
+ userMessage?: string;
18
+ channelConfiguration?: ChannelConfigurationService;
19
+ activeSkillName?: string;
20
+ resumeConversationId?: string;
21
+ resumeSessionId?: string;
22
+ };
23
+ /** Capitalize the first letter of a provider name for display. */
24
+ export declare function formatProviderLabel(provider: string): string;
25
+ /** Resolve the public base URL from environment variables (JUNIOR_BASE_URL or Vercel). */
26
+ export declare function resolveBaseUrl(): string | undefined;
27
+ /**
28
+ * Authorization links must only be visible to the requesting user.
29
+ * Try in-context private delivery first, then fall back to a DM.
30
+ */
31
+ export declare function deliverPrivateMessage(input: {
32
+ channelId?: string;
33
+ threadTs?: string;
34
+ userId: string;
35
+ text: string;
36
+ }): Promise<PrivateDeliveryResult>;
37
+ /** Initiate an OAuth authorization code flow for a provider and deliver the auth link to the user. */
38
+ export declare function startOAuthFlow(provider: string, input: OAuthFlowInput): Promise<{
39
+ ok: false;
40
+ error: string;
41
+ } | {
42
+ ok: true;
43
+ delivery: PrivateDeliveryResult;
44
+ }>;
45
+ export {};
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Normalize optional env-style strings so blank values do not masquerade as
3
+ * configured inputs.
4
+ */
5
+ export declare function toOptionalTrimmed(value: string | undefined): string | undefined;
@@ -0,0 +1,49 @@
1
+ import { type Message, type Model, type ThinkingLevel } from "@earendil-works/pi-ai";
2
+ import type { ZodTypeAny, z } from "zod";
3
+ export declare const GEN_AI_PROVIDER_NAME: "vercel-ai-gateway";
4
+ export declare const MISSING_GATEWAY_CREDENTIALS_ERROR = "Missing AI gateway credentials (AI_GATEWAY_API_KEY or VERCEL_OIDC_TOKEN)";
5
+ /**
6
+ * Resolve the documented AI Gateway env credentials for the paths that need
7
+ * the bearer token string directly.
8
+ */
9
+ export declare function getGatewayApiKey(): string | undefined;
10
+ /**
11
+ * Let pi-ai read AI_GATEWAY_API_KEY from env itself and only override the
12
+ * token when auth comes from VERCEL_OIDC_TOKEN.
13
+ */
14
+ export declare function getPiGatewayApiKeyOverride(): string | undefined;
15
+ /**
16
+ * Look up a gateway model by id. Throws `Unknown AI Gateway model id: …` if
17
+ * the id is not in pi-ai's registry — callers at the config boundary can use
18
+ * this to fail fast at startup instead of mid-turn.
19
+ */
20
+ export declare function resolveGatewayModel(modelId: string): Model<any>;
21
+ /** Execute a direct chat completion inside a dedicated `gen_ai.chat` span. */
22
+ export declare function completeText(params: {
23
+ modelId: string;
24
+ system?: string;
25
+ messages: Message[];
26
+ thinkingLevel?: ThinkingLevel;
27
+ temperature?: number;
28
+ maxTokens?: number;
29
+ signal?: AbortSignal;
30
+ metadata?: Record<string, unknown>;
31
+ }): Promise<{
32
+ message: import("@earendil-works/pi-ai").AssistantMessage;
33
+ text: string;
34
+ }>;
35
+ /** Execute a schema-constrained completion using the traced text path above. */
36
+ export declare function completeObject<TSchema extends ZodTypeAny>(params: {
37
+ modelId: string;
38
+ schema: TSchema;
39
+ system?: string;
40
+ prompt: string;
41
+ thinkingLevel?: ThinkingLevel;
42
+ temperature?: number;
43
+ maxTokens?: number;
44
+ signal?: AbortSignal;
45
+ metadata?: Record<string, unknown>;
46
+ }): Promise<{
47
+ object: z.infer<TSchema>;
48
+ text: string;
49
+ }>;
@@ -0,0 +1,3 @@
1
+ import type { AgentMessage } from "@earendil-works/pi-agent-core";
2
+ /** Durable Pi transcript message stored across turns. */
3
+ export type PiMessage = AgentMessage;
@@ -0,0 +1,9 @@
1
+ import type { StreamFn } from "@earendil-works/pi-agent-core";
2
+ /**
3
+ * Wraps pi-ai's `streamSimple` so each LLM call inside a pi-agent-core agent
4
+ * loop produces its own `gen_ai.chat` Sentry span. The returned function is
5
+ * passed to `new Agent({ streamFn: ... })` and runs once per loop iteration.
6
+ *
7
+ * The base argument exists so tests can inject a stub stream function.
8
+ */
9
+ export declare function createTracedStreamFn(base?: StreamFn): StreamFn;
@@ -0,0 +1,32 @@
1
+ import type { AgentPluginRequester, JuniorPlugin } from "@sentry/junior-plugin-api";
2
+ import type { ToolDefinition } from "@/chat/tools/definition";
3
+ import type { ToolRuntimeContext } from "@/chat/tools/types";
4
+ import type { SandboxInstance } from "@/chat/sandbox/workspace";
5
+ /** Signal that a trusted plugin intentionally denied a tool execution. */
6
+ export declare class AgentPluginHookDeniedError extends Error {
7
+ constructor(message: string);
8
+ }
9
+ export interface ToolHookInput {
10
+ input: Record<string, unknown>;
11
+ name: string;
12
+ }
13
+ export interface ToolHookResult {
14
+ env: Record<string, string>;
15
+ input: Record<string, unknown>;
16
+ }
17
+ export interface AgentPluginHookRunner {
18
+ beforeToolExecute(input: ToolHookInput): Promise<ToolHookResult>;
19
+ prepareSandbox(sandbox: SandboxInstance): Promise<void>;
20
+ }
21
+ /** Validate trusted plugin identity before it can affect process-wide hooks. */
22
+ export declare function validateAgentPlugins(plugins: JuniorPlugin[]): void;
23
+ /** Replace trusted agent plugins and return the previous list for rollback. */
24
+ export declare function setAgentPlugins(plugins: JuniorPlugin[]): JuniorPlugin[];
25
+ /** Return the current trusted agent plugins without exposing mutable state. */
26
+ export declare function getAgentPlugins(): JuniorPlugin[];
27
+ /** Collect turn-scoped tools exposed by trusted plugins. */
28
+ export declare function getAgentPluginTools(context: ToolRuntimeContext): Record<string, ToolDefinition<any>>;
29
+ /** Create one runner over trusted agent plugins registered by the app. */
30
+ export declare function createAgentPluginHookRunner(input?: {
31
+ requester?: AgentPluginRequester;
32
+ }): AgentPluginHookRunner;
@@ -0,0 +1,6 @@
1
+ import type { CredentialBroker, CredentialHeaderTransform } from "@/chat/credentials/broker";
2
+ import type { PluginManifest } from "@/chat/plugins/types";
3
+ /** Resolve plugin-level API headers into sandbox header transforms. */
4
+ export declare function resolveApiHeaderTransforms(manifest: PluginManifest): CredentialHeaderTransform[];
5
+ /** Issue host-managed API header transforms backed by deployment env vars. */
6
+ export declare function createApiHeadersBroker(manifest: PluginManifest): CredentialBroker;
@@ -0,0 +1,3 @@
1
+ import type { GitHubAppCredentials, OAuthBearerCredentials } from "../types";
2
+ /** Resolve the non-secret sandbox token placeholder for token-backed credentials. */
3
+ export declare function resolveAuthTokenPlaceholder(credentials: OAuthBearerCredentials | GitHubAppCredentials): string;
@@ -0,0 +1,4 @@
1
+ import type { CredentialBroker } from "@/chat/credentials/broker";
2
+ import type { GitHubAppCredentials, PluginManifest } from "../types";
3
+ /** Create a broker that keeps GitHub App tokens on the host while authorizing provider traffic. */
4
+ export declare function createGitHubAppBroker(manifest: PluginManifest, credentials: GitHubAppCredentials): CredentialBroker;
@@ -0,0 +1,6 @@
1
+ import type { CredentialBroker } from "@/chat/credentials/broker";
2
+ import type { UserTokenStore } from "@/chat/credentials/user-token-store";
3
+ import type { OAuthBearerCredentials, PluginManifest } from "../types";
4
+ export declare function createOAuthBearerBroker(manifest: PluginManifest, credentials: OAuthBearerCredentials, deps: {
5
+ userTokenStore: UserTokenStore;
6
+ }): CredentialBroker;
@@ -0,0 +1,18 @@
1
+ type OAuthTokenRequestInput = {
2
+ clientId: string;
3
+ clientSecret: string;
4
+ payload: Record<string, string>;
5
+ tokenAuthMethod?: "body" | "basic";
6
+ tokenExtraHeaders?: Record<string, string>;
7
+ };
8
+ export declare function buildOAuthTokenRequest(input: OAuthTokenRequestInput): {
9
+ headers: Record<string, string>;
10
+ body: BodyInit;
11
+ };
12
+ export declare function parseOAuthTokenResponse(data: Record<string, unknown>, fallbackScope?: string): {
13
+ accessToken: string;
14
+ refreshToken: string;
15
+ expiresAt?: number;
16
+ scope?: string;
17
+ };
18
+ export {};
@@ -0,0 +1,3 @@
1
+ import type { PluginManifest } from "@/chat/plugins/types";
2
+ /** Resolve non-secret sandbox command env declared by a plugin manifest. */
3
+ export declare function resolvePluginCommandEnv(manifest: PluginManifest): Record<string, string>;
@@ -0,0 +1,3 @@
1
+ import type { AgentPluginLogger } from "@sentry/junior-plugin-api";
2
+ /** Create the host logger exposed to trusted plugin hooks. */
3
+ export declare function createAgentPluginLogger(plugin: string): AgentPluginLogger;
@@ -0,0 +1,3 @@
1
+ import type { PluginConfig, PluginManifest } from "./types";
2
+ /** Parse one plugin manifest after applying install-level plugin config. */
3
+ export declare function parsePluginManifest(raw: string, dir: string, config?: PluginConfig): PluginManifest;
@@ -0,0 +1,14 @@
1
+ export interface InstalledPluginPackageContent {
2
+ packageNames: string[];
3
+ manifestRoots: string[];
4
+ skillRoots: string[];
5
+ tracingIncludes: string[];
6
+ }
7
+ /** Normalize and validate configured plugin package names. */
8
+ export declare function normalizePluginPackageNames(packageNames: unknown): string[];
9
+ export interface DiscoverInstalledPluginPackageContentOptions {
10
+ nodeModulesDirs?: string[];
11
+ packageNames?: unknown;
12
+ }
13
+ /** Discover plugin package content from explicitly declared package names. */
14
+ export declare function discoverInstalledPluginPackageContent(cwd?: string, options?: DiscoverInstalledPluginPackageContentOptions): InstalledPluginPackageContent;
@@ -0,0 +1,23 @@
1
+ import type { CapabilityProviderDefinition } from "@/chat/capabilities/catalog";
2
+ import type { CredentialBroker } from "@/chat/credentials/broker";
3
+ import { type InstalledPluginPackageContent } from "./package-discovery";
4
+ import type { PluginBrokerDeps, PluginConfig, PluginDefinition, OAuthProviderConfig, PluginRuntimeDependency, PluginRuntimePostinstallCommand } from "./types";
5
+ /** Set install-wide plugin configuration and return the previous value for rollback. */
6
+ export declare function setPluginConfig(config: PluginConfig | undefined): PluginConfig | undefined;
7
+ /** Return installed plugin package content from the active plugin configuration. */
8
+ export declare function getPluginPackageContent(): InstalledPluginPackageContent;
9
+ /** Return the current plugin catalog signature used for cache invalidation. */
10
+ export declare function getPluginCatalogSignature(): string;
11
+ export declare function getPluginCapabilityProviders(): CapabilityProviderDefinition[];
12
+ export declare function getPluginProviders(): PluginDefinition[];
13
+ export declare function getPluginMcpProviders(): PluginDefinition[];
14
+ export declare function getPluginRuntimeDependencies(): PluginRuntimeDependency[];
15
+ export declare function getPluginRuntimePostinstall(): PluginRuntimePostinstallCommand[];
16
+ export declare function getPluginOAuthConfig(provider: string): OAuthProviderConfig | undefined;
17
+ export declare function getPluginSkillRoots(): string[];
18
+ export declare function getPluginForSkillPath(skillPath: string): PluginDefinition | undefined;
19
+ export declare function getPluginDefinition(provider: string): PluginDefinition | undefined;
20
+ export declare function isPluginProvider(provider: string): boolean;
21
+ export declare function isPluginCapability(capability: string): boolean;
22
+ export declare function isPluginConfigKey(key: string): boolean;
23
+ export declare function createPluginBroker(provider: string, deps: PluginBrokerDeps): CredentialBroker;
@@ -0,0 +1,3 @@
1
+ import type { AgentPluginState } from "@sentry/junior-plugin-api";
2
+ /** Create a durable state namespace scoped to one trusted plugin. */
3
+ export declare function createPluginState(plugin: string): AgentPluginState;