@sentry/junior 0.121.0 → 0.122.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 (64) hide show
  1. package/dist/{agent-hooks-CQDGDBCP.js → agent-hooks-HJMLQLCB.js} +8 -8
  2. package/dist/api.js +14 -14
  3. package/dist/app.js +604 -997
  4. package/dist/{catalog-runtime-AD3YNTTM.js → catalog-runtime-CYPZUYJD.js} +5 -5
  5. package/dist/chat/agent/index.d.ts +19 -2
  6. package/dist/chat/agent/request.d.ts +8 -8
  7. package/dist/chat/agent/resume.d.ts +1 -3
  8. package/dist/chat/agent/retry-usage.d.ts +8 -0
  9. package/dist/chat/agent/skills.d.ts +0 -9
  10. package/dist/chat/conversations/messages.d.ts +7 -0
  11. package/dist/chat/conversations/projection.d.ts +16 -0
  12. package/dist/chat/logging.d.ts +46 -13
  13. package/dist/chat/runtime/processing-reaction.d.ts +2 -4
  14. package/dist/chat/runtime/slack-runtime.d.ts +2 -2
  15. package/dist/chat/services/assistant-reply.d.ts +16 -0
  16. package/dist/chat/services/empty-output-continuation.d.ts +20 -0
  17. package/dist/chat/services/turn-failure-response.d.ts +1 -3
  18. package/dist/chat/services/turn-result.d.ts +0 -5
  19. package/dist/chat/services/turn-session-record.d.ts +0 -11
  20. package/dist/chat/tool-support/zod-tool.d.ts +11 -6
  21. package/dist/chat/tools/execute-tool.d.ts +1 -33
  22. package/dist/chat/tools/execution/tool-error-handler.d.ts +2 -2
  23. package/dist/chat/tools/query-conversation-events.d.ts +3 -1
  24. package/dist/chat/tools/sandbox/bash.d.ts +1 -33
  25. package/dist/chat/tools/sandbox/edit-file.d.ts +1 -33
  26. package/dist/chat/tools/sandbox/find-files.d.ts +1 -33
  27. package/dist/chat/tools/sandbox/grep.d.ts +1 -33
  28. package/dist/chat/tools/sandbox/list-dir.d.ts +1 -33
  29. package/dist/chat/tools/sandbox/read-file.d.ts +1 -33
  30. package/dist/chat/tools/sandbox/write-file.d.ts +1 -33
  31. package/dist/{chunk-IDXLBKPS.js → chunk-2RFM7STT.js} +11 -22
  32. package/dist/{chunk-XDRGYDED.js → chunk-32FPGM2V.js} +1 -1
  33. package/dist/{chunk-JZ47AFSH.js → chunk-4SPRQJOW.js} +37 -45
  34. package/dist/{chunk-KLUMVJRQ.js → chunk-4TGVC42X.js} +133 -206
  35. package/dist/{chunk-UXQ5XSA2.js → chunk-BDE5RZVF.js} +2 -2
  36. package/dist/{chunk-ITMEXX5H.js → chunk-CYW4M6IV.js} +4 -4
  37. package/dist/{chunk-254MFDOF.js → chunk-DOB5RVMH.js} +2 -2
  38. package/dist/{chunk-TRECK7RV.js → chunk-E5SRLZQV.js} +14 -29
  39. package/dist/{chunk-LE77HHF3.js → chunk-GFTZKOTP.js} +1 -1
  40. package/dist/{chunk-ET2SDCNV.js → chunk-GN6WW7WR.js} +16 -31
  41. package/dist/{chunk-D2EMOH3N.js → chunk-ISQYBTPG.js} +3 -3
  42. package/dist/{chunk-IK4QSS5H.js → chunk-L2KJ2GNL.js} +1 -1
  43. package/dist/{chunk-VWBKDPMQ.js → chunk-NIJG6G6X.js} +472 -684
  44. package/dist/{chunk-Z2XXPUZG.js → chunk-NNGYYGX5.js} +2061 -2015
  45. package/dist/{chunk-WUP7NWMP.js → chunk-OKUZIXQM.js} +1 -1
  46. package/dist/{chunk-HDFGNU5E.js → chunk-S7G34U75.js} +3 -1
  47. package/dist/{chunk-UURFXX66.js → chunk-TZVZCIYL.js} +1 -1
  48. package/dist/{chunk-7HYV7KFM.js → chunk-USKP7IM2.js} +49 -92
  49. package/dist/{chunk-JYDIBXFY.js → chunk-V6XPIKYA.js} +13 -19
  50. package/dist/{chunk-3DBMANUI.js → chunk-VCC7XFX2.js} +22 -45
  51. package/dist/cli/chat.js +22 -22
  52. package/dist/cli/check.js +6 -6
  53. package/dist/cli/plugins.js +11 -11
  54. package/dist/cli/snapshot-create.js +9 -9
  55. package/dist/cli/upgrade.js +6 -6
  56. package/dist/{db-7HQT2SXQ.js → db-E6O2DXUQ.js} +6 -6
  57. package/dist/instrumentation.js +3 -3
  58. package/dist/nitro.js +2 -2
  59. package/dist/{oauth-callback-server-VHTUCNHK.js → oauth-callback-server-6SCPUFFD.js} +15 -15
  60. package/dist/{runner-3ONPZRED.js → runner-JFKCMVVY.js} +62 -51
  61. package/dist/{skills-WGAYGGPA.js → skills-RD66F2OB.js} +6 -6
  62. package/dist/{validation-ZIWNBG4D.js → validation-XVRNX6IU.js} +6 -6
  63. package/dist/version.js +1 -1
  64. package/package.json +8 -8
@@ -1,17 +1,17 @@
1
1
  import {
2
2
  pluginCatalogRuntime
3
- } from "./chunk-WUP7NWMP.js";
4
- import "./chunk-ET2SDCNV.js";
3
+ } from "./chunk-OKUZIXQM.js";
4
+ import "./chunk-GN6WW7WR.js";
5
5
  import "./chunk-W3U3YQYI.js";
6
6
  import "./chunk-HZF5P5UN.js";
7
- import "./chunk-JZ47AFSH.js";
7
+ import "./chunk-4SPRQJOW.js";
8
8
  import "./chunk-OB42YVAE.js";
9
9
  import "./chunk-F3B2YJ76.js";
10
10
  import "./chunk-6GWA276C.js";
11
11
  import "./chunk-OOUNJNMR.js";
12
12
  import "./chunk-H4HBKISO.js";
13
- import "./chunk-IK4QSS5H.js";
14
- import "./chunk-D2EMOH3N.js";
13
+ import "./chunk-L2KJ2GNL.js";
14
+ import "./chunk-ISQYBTPG.js";
15
15
  import "./chunk-MLKGABMK.js";
16
16
  export {
17
17
  pluginCatalogRuntime
@@ -1,4 +1,21 @@
1
+ /**
2
+ * Agent executor.
3
+ *
4
+ * Composition root and execution loop for one agent run slice after
5
+ * runtime/ingress code has parsed and routed the request. Wires the phase
6
+ * modules (session restore, skills, tools, prompt, resume), runs the Pi agent
7
+ * with inline retry handling, and translates expected run endings into
8
+ * `AgentRunOutcome` values. It emits every completed, tool-free visible
9
+ * assistant message through the delivery port; the result carries diagnostics,
10
+ * artifacts, and transcript state for destination-owned completion.
11
+ */
12
+ import { type StreamFn } from "@earendil-works/pi-agent-core";
1
13
  import type { AgentRunOutcome } from "@/chat/runtime/agent-run-outcome";
2
14
  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>;
15
+ /**
16
+ * Run a full agent turn, optionally using a caller-provided model stream.
17
+ *
18
+ * The stream changes model output only; prompt assembly, persistence, tools,
19
+ * delivery, and completion still use the normal agent runtime.
20
+ */
21
+ export declare function executeAgentRun(request: AgentRunRequest, streamFn?: StreamFn): Promise<AgentRunOutcome>;
@@ -28,6 +28,7 @@ import type { ToolExecutionReport } from "@/chat/tool-support/tool-execution-rep
28
28
  import type { SlackActionToken } from "@/chat/slack/action-token";
29
29
  import type { TurnReasoningLevel } from "@/chat/reasoning-level";
30
30
  import type { ImageGenerateToolDeps, ViewImageToolDeps, WebFetchToolDeps, WebSearchToolDeps } from "@/chat/tools/types";
31
+ import type { AssistantMessage } from "@earendil-works/pi-ai";
31
32
  export interface AgentRunAttachment {
32
33
  data?: Buffer;
33
34
  mediaType: string;
@@ -126,14 +127,13 @@ export interface AgentRunObservers {
126
127
  onToolResult?: (result: ToolExecutionReport) => void | Promise<void>;
127
128
  onStatus?: (status: AssistantStatusSpec) => void | Promise<void>;
128
129
  }
129
- /** One completed tool-free assistant message ready for destination delivery. */
130
- export interface AgentAssistantMessage {
131
- text: string;
132
- }
133
- /** Delivers completed tool-free assistant messages in model order. */
134
- export interface AgentRunDelivery {
135
- onAssistantMessage: (message: AgentAssistantMessage) => void | Promise<void>;
136
- }
130
+ /**
131
+ * Delivers completed tool-free assistant messages in model order.
132
+ *
133
+ * The runner must commit the preceding agent boundary before invoking this
134
+ * port; the accepted reply transaction appends only this message.
135
+ */
136
+ export type AgentRunDelivery = (message: AssistantMessage) => void | Promise<void>;
137
137
  /** Resume the agent turn after a transient or ambiguous delivery failure. */
138
138
  export declare class RetryableDeliveryError extends Error {
139
139
  constructor(cause: unknown);
@@ -14,13 +14,12 @@ import { CooperativeTurnYieldError } from "@/chat/runtime/turn";
14
14
  import type { AgentRunOutcome } from "@/chat/runtime/agent-run-outcome";
15
15
  import type { AgentTurnSurface } from "@/chat/state/turn-session";
16
16
  import type { Actor } from "@/chat/actor";
17
- import { loadTurnSessionRecord, persistRunningSessionRecord } from "@/chat/services/turn-session-record";
17
+ import { loadTurnSessionRecord } from "@/chat/services/turn-session-record";
18
18
  import { type AuthorizationPauseError } from "@/chat/services/auth-pause";
19
19
  import { type AgentTurnUsage } from "@/chat/usage";
20
20
  import { type AgentRunDurability } from "@/chat/agent/request";
21
21
  import type { PluginTurnContext } from "@/chat/plugins/prompt";
22
22
  type LoadedSessionRecordState = Awaited<ReturnType<typeof loadTurnSessionRecord>>;
23
- type SessionRecordLogContext = NonNullable<Parameters<typeof persistRunningSessionRecord>[0]["logContext"]>;
24
23
  interface ResumeStateArgs {
25
24
  channelName?: string;
26
25
  destination: Destination;
@@ -28,7 +27,6 @@ interface ResumeStateArgs {
28
27
  durability: AgentRunDurability;
29
28
  getLoadedSkillNames: () => string[];
30
29
  getModelId: () => string;
31
- logContext: SessionRecordLogContext;
32
30
  getReasoningLevel: () => string | undefined;
33
31
  recordActiveMcpProviders: () => Promise<void>;
34
32
  actor?: Actor;
@@ -0,0 +1,8 @@
1
+ import type { PiMessage } from "@/chat/pi/messages";
2
+ import { type AgentTurnUsage } from "@/chat/usage";
3
+ /**
4
+ * Return usage discarded when a retry keeps an exact prefix of agent history.
5
+ *
6
+ * Retained messages stay in the next phase and must not be counted again here.
7
+ */
8
+ export declare function getDiscardedRetryUsage(messages: PiMessage[], retryMessages: PiMessage[]): AgentTurnUsage | undefined;
@@ -1,11 +1,3 @@
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
1
  import { type Skill, type SkillMetadata } from "@/chat/skills";
10
2
  import { SkillSandbox } from "@/chat/sandbox/skill-sandbox";
11
3
  import type { PiMessage } from "@/chat/pi/messages";
@@ -14,7 +6,6 @@ export declare function upsertActiveSkill(activeSkills: Skill[], next: Skill): v
14
6
  /** Discover skills for one slice; emits the startup discovery summary once per process. */
15
7
  export declare function discoverRunSkills(args: {
16
8
  skillDirs?: string[];
17
- spanContext: LogContext;
18
9
  }): Promise<SkillMetadata[]>;
19
10
  /** Rehydrate active skill handles from durable Pi history and explicit invocation. */
20
11
  export declare function restoreSkillRuntime(args: {
@@ -1,4 +1,5 @@
1
1
  import type { ConversationMessage, ThreadConversationState } from "@/chat/state/conversation";
2
+ import type { ConversationEventStore } from "./history";
2
3
  /** Author role of a visible conversation message. */
3
4
  export type ConversationMessageRole = "user" | "assistant" | "system";
4
5
  /** A source message to record; identity is `(conversationId, messageId)`. */
@@ -23,3 +24,9 @@ export declare function persistConversationMessages(args: {
23
24
  conversationId: string | undefined;
24
25
  repliedAtMs?: number;
25
26
  }): Promise<void>;
27
+ /** Append visible message facts through a caller-owned event-store transaction. */
28
+ export declare function appendConversationMessages(eventStore: ConversationEventStore, args: {
29
+ conversation: ThreadConversationState;
30
+ conversationId: string;
31
+ repliedAtMs?: number;
32
+ }): Promise<void>;
@@ -6,6 +6,8 @@ import { type PiConversationEventProjection, type PiConversationProjection } fro
6
6
  import type { ModelProfile } from "@/chat/model-profile";
7
7
  import type { TurnReasoningLevel } from "@/chat/reasoning-level";
8
8
  import type { PluginTurnContext } from "@/chat/plugins/prompt";
9
+ import type { ThreadConversationState } from "@/chat/state/conversation";
10
+ import type { AssistantMessage } from "@earendil-works/pi-ai";
9
11
  interface ScopedConversation {
10
12
  conversationId: string;
11
13
  }
@@ -63,6 +65,20 @@ export declare function commitMessages(args: {
63
65
  messages: PiMessage[];
64
66
  provenance: ConversationMessageProvenance[];
65
67
  }>;
68
+ /**
69
+ * Commit an accepted agent reply and its visible message in causal order.
70
+ *
71
+ * The destination has already accepted the reply. One transaction prevents
72
+ * reporting from observing the visible reply before the agent message that
73
+ * produced it.
74
+ */
75
+ export declare function commitAcceptedReply(args: {
76
+ agentMessage: AssistantMessage;
77
+ conversation: ThreadConversationState;
78
+ conversationMessageId: string;
79
+ conversationId: string;
80
+ repliedAtMs?: number;
81
+ }): Promise<void>;
66
82
  /** Record a successful MCP provider connection without duplicating the fact. */
67
83
  export declare function recordMcpProviderConnected(args: {
68
84
  conversationId: string;
@@ -20,22 +20,33 @@ interface SentryUserIdentity {
20
20
  export declare function normalizeGenAiFinishReason(reason: string): string;
21
21
  /** Truncate message text for log attributes. */
22
22
  export declare function summarizeMessageText(text: string): string;
23
+ /**
24
+ * Low-level adapter logger.
25
+ *
26
+ * Application runtime code should use the severity helpers below. This surface
27
+ * exists for adapters that must preserve an external free-form body.
28
+ */
23
29
  export declare const log: {
24
30
  debug(eventName: string, attrs?: Record<string, unknown>, body?: string): void;
25
31
  info(eventName: string, attrs?: Record<string, unknown>, body?: string): void;
26
32
  warn(eventName: string, attrs?: Record<string, unknown>, body?: string): void;
27
33
  error(eventName: string, attrs?: Record<string, unknown>, body?: string): void;
28
- exception(eventName: string, error: unknown, attrs?: Record<string, unknown>, body?: string, context?: LogContext): string | undefined;
34
+ exception(eventName: string, error: unknown, attrs?: Record<string, unknown>, body?: string): string | undefined;
29
35
  };
30
36
  /** Create a Chat SDK logger that routes records through Junior's logging backend. */
31
37
  export declare function createChatSdkLogger(): ChatSdkLogger;
32
- export declare function withLogContext<T>(context: LogContext, callback: () => Promise<T>): Promise<T>;
38
+ /**
39
+ * Run one operation with inherited correlation context.
40
+ *
41
+ * Call this at execution boundaries after reconstructing authoritative
42
+ * context. Nested application logs should not receive the same context again.
43
+ */
44
+ export declare function withLogContext<T>(context: LogContext, callback: () => T): T;
33
45
  export declare function getLogContextAttributes(): LogAttributes;
34
46
  /** Return inherited log context filtered to attributes valid for the span operation. */
35
47
  export declare function getLogContextAttributesForSpan(op: string): LogAttributes;
36
48
  export declare function registerLogRecordSink(sink: (record: EmittedLogRecord) => void): () => void;
37
49
  export declare function createLogContextFromRequest(request: Request, context?: Partial<LogContext>): LogContext;
38
- export declare function toSpanAttributes(context: LogContext): Record<string, string>;
39
50
  /** Attach filterable non-user context tags to Sentry. */
40
51
  export declare function setSentryTagsFromContext(context: LogContext): void;
41
52
  /** Bind actor identity to Sentry's native user fields. */
@@ -43,16 +54,38 @@ export declare function setSentryUser(identity: SentryUserIdentity | undefined):
43
54
  /** Attach scoped Sentry context for isolated exception capture. */
44
55
  export declare function setSentryScopeContext(scope: Sentry.Scope, context: LogContext): void;
45
56
  export type SetSpanAttributes = (attributes: Record<string, unknown>) => void;
46
- /** Capture an error to Sentry and emit an error log record. */
47
- export declare function captureException(error: unknown, context?: LogContext): void;
48
- /** Log an info-level structured event. */
49
- export declare function logInfo(eventName: string, context?: LogContext, attributes?: Record<string, unknown>, body?: string): void;
50
- /** Log a warning-level structured event. */
51
- export declare function logWarn(eventName: string, context?: LogContext, attributes?: Record<string, unknown>, body?: string): void;
52
- /** Log an error-level structured event. */
53
- export declare function logError(eventName: string, context?: LogContext, attributes?: Record<string, unknown>, body?: string): void;
54
- /** Log an error with exception capture; returns the Sentry event ID if available. */
55
- export declare function logException(error: unknown, eventName: string, context?: LogContext, attributes?: Record<string, unknown>, body?: string): string | undefined;
57
+ /**
58
+ * Capture an error using context already bound to the current operation.
59
+ */
60
+ export declare function captureException(error: unknown): void;
61
+ /**
62
+ * Emit an informational event with occurrence-specific attributes.
63
+ *
64
+ * Bind correlation context at the owning operation boundary instead of
65
+ * passing it here.
66
+ */
67
+ export declare function logInfo(eventName: string, attributes?: Record<string, unknown>): void;
68
+ /**
69
+ * Emit a warning event with occurrence-specific attributes.
70
+ *
71
+ * Bind correlation context at the owning operation boundary instead of
72
+ * passing it here.
73
+ */
74
+ export declare function logWarn(eventName: string, attributes?: Record<string, unknown>): void;
75
+ /**
76
+ * Emit an error event without capturing an exception.
77
+ *
78
+ * Use `logException` when an actual exception instance owns the failure.
79
+ */
80
+ export declare function logError(eventName: string, attributes?: Record<string, unknown>): void;
81
+ /**
82
+ * Emit an exception event and capture the exception with bound context.
83
+ *
84
+ * Exception event names should end in `.exception` when they describe a
85
+ * generic operation exception. Existing domain failure events may retain a
86
+ * `.failed` outcome when the event also covers non-exception failures.
87
+ */
88
+ export declare function logException(error: unknown, eventName: string, attributes?: Record<string, unknown>): string | undefined;
56
89
  /** Add context to the current operation and Sentry scope. */
57
90
  export declare function setTags(context?: LogContext): void;
58
91
  /** Create a LogContext from an incoming HTTP request. */
@@ -11,8 +11,7 @@ export interface ProcessingReactionSession {
11
11
  export declare function shouldKeepProcessingReactionForToolInvocation(input: TurnToolInvocation): boolean;
12
12
  /** Start Junior's automatic Slack processing reaction for one inbound message. */
13
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>;
14
+ logException: (error: unknown, eventName: string, attributes?: Record<string, unknown>) => string | undefined;
16
15
  message: Message;
17
16
  thread: Thread;
18
17
  }): Promise<ProcessingReactionSession>;
@@ -20,6 +19,5 @@ export declare function startSlackProcessingReaction(args: {
20
19
  export declare function startSlackProcessingReactionForMessage(args: {
21
20
  channelId: string;
22
21
  timestamp: SlackMessageTs;
23
- logException: (error: unknown, eventName: string, context?: Record<string, unknown>, attributes?: Record<string, unknown>, body?: string) => string | undefined;
24
- logContext: Record<string, unknown>;
22
+ logException: (error: unknown, eventName: string, attributes?: Record<string, unknown>) => string | undefined;
25
23
  }): Promise<ProcessingReactionSession>;
@@ -62,8 +62,8 @@ export interface SlackTurnRuntimeDependencies<TPreparedState> {
62
62
  threadId: string;
63
63
  threadTs: string;
64
64
  }) => Promise<void>;
65
- logException: (error: unknown, eventName: string, context?: Record<string, unknown>, attributes?: Record<string, unknown>, body?: string) => string | undefined;
66
- logWarn: (eventName: string, context?: Record<string, unknown>, attributes?: Record<string, unknown>, body?: string) => void;
65
+ logException: (error: unknown, eventName: string, attributes?: Record<string, unknown>) => string | undefined;
66
+ logWarn: (eventName: string, attributes?: Record<string, unknown>) => void;
67
67
  modelId: string;
68
68
  now: () => number;
69
69
  recordSkippedSteeringMessage: (args: {
@@ -0,0 +1,16 @@
1
+ import type { AssistantMessage } from "@earendil-works/pi-ai";
2
+ type ReplyDecision = {
3
+ kind: "deliver";
4
+ text: string;
5
+ } | {
6
+ kind: "empty";
7
+ } | {
8
+ kind: "suppress";
9
+ };
10
+ /** Remove provider reasoning wrappers while preserving fenced code examples. */
11
+ export declare function sanitizeAssistantText(text: string): string;
12
+ /** Decide whether one completed assistant message becomes a reply. */
13
+ export declare function decideReply(message: AssistantMessage): ReplyDecision;
14
+ /** Return destination-visible reply text when the message is deliverable. */
15
+ export declare function getAssistantReplyText(message: AssistantMessage): string | undefined;
16
+ export {};
@@ -0,0 +1,20 @@
1
+ import type { AssistantMessage } from "@earendil-works/pi-ai";
2
+ import type { PiMessage } from "@/chat/pi/messages";
3
+ type EmptyOutputContinuation = {
4
+ kind: "none";
5
+ } | {
6
+ kind: "retry";
7
+ messages: PiMessage[];
8
+ } | {
9
+ kind: "exhausted";
10
+ };
11
+ /**
12
+ * Decide whether empty assistant output gets one continuation after a
13
+ * history replacement.
14
+ */
15
+ export declare function nextEmptyOutputContinuation(args: {
16
+ attempt: number;
17
+ lastAssistant?: AssistantMessage;
18
+ messages: PiMessage[];
19
+ }): EmptyOutputContinuation;
20
+ export {};
@@ -1,6 +1,5 @@
1
- import type { LogContext } from "@/chat/logging";
2
1
  import type { AgentRunResult } from "@/chat/services/turn-result";
3
- type LogException = (error: unknown, eventName: string, context?: LogContext, attributes?: Record<string, unknown>, body?: string) => string | undefined;
2
+ type LogException = (error: unknown, eventName: string, attributes?: Record<string, unknown>) => string | undefined;
4
3
  /** Require captured turn failures to carry a real Sentry event reference. */
5
4
  export declare function requireTurnFailureEventId(eventId: string | undefined, eventName: string): string;
6
5
  /** Keep failed-turn Sentry captures and completion spans on the same keys. */
@@ -14,7 +13,6 @@ export interface FinalizedTurnFailure {
14
13
  export declare function finalizeFailedTurnReplyWithEvent(args: {
15
14
  reply: AgentRunResult;
16
15
  logException: LogException;
17
- context: LogContext;
18
16
  attributes?: Record<string, unknown>;
19
17
  }): FinalizedTurnFailure;
20
18
  /** Enforce one captured, event-ID-bearing failure response before delivery. */
@@ -1,10 +1,8 @@
1
- import type { LogContext } from "@/chat/logging";
2
1
  import type { PiMessage } from "@/chat/pi/messages";
3
2
  import type { TurnRoute } from "@/chat/services/turn-router";
4
3
  import type { AgentTurnUsage } from "@/chat/usage";
5
4
  import type { ThreadArtifactsState } from "@/chat/state/artifacts";
6
5
  import type { SandboxRef } from "@/chat/sandbox/ref";
7
- import { extractAssistantText } from "@/chat/pi/transcript";
8
6
  export interface AgentTurnDiagnostics {
9
7
  assistantMessageCount: number;
10
8
  durationMs?: number;
@@ -38,13 +36,10 @@ export interface TurnResultInput {
38
36
  durationMs?: number;
39
37
  generatedFileCount: number;
40
38
  shouldTrace: boolean;
41
- spanContext: LogContext;
42
39
  usage?: AgentTurnUsage;
43
40
  executionProfile: TurnRoute;
44
41
  assistantUserName?: string;
45
42
  modelId: string;
46
43
  }
47
- /** Return destination-visible text from one completed tool-free assistant message. */
48
- export declare function getAssistantMessageText(message: Parameters<typeof extractAssistantText>[0]): string | undefined;
49
44
  /** Process raw agent messages into a structured AgentRunResult. */
50
45
  export declare function buildTurnResult(input: TurnResultInput): AgentRunResult;
@@ -14,13 +14,6 @@ export interface TurnSessionState {
14
14
  currentSliceId: number;
15
15
  existingSessionRecord?: AgentTurnSessionRecord;
16
16
  }
17
- interface SessionRecordLogContext {
18
- threadId?: string;
19
- actorId?: string;
20
- channelId?: string;
21
- runId?: string;
22
- assistantUserName?: string;
23
- }
24
17
  /** Load turn session record state for a conversation/session pair. */
25
18
  export declare function loadTurnSessionRecord(ctx: TurnSessionContext): Promise<TurnSessionState>;
26
19
  /** Persist the latest safe in-progress boundary without scheduling continuation. */
@@ -36,7 +29,6 @@ export declare function persistRunningSessionRecord(args: {
36
29
  /** Provenance for trailing newly committed messages, such as steering. */
37
30
  trailingMessageProvenance?: ConversationMessageProvenance[];
38
31
  loadedSkillNames?: string[];
39
- logContext: SessionRecordLogContext;
40
32
  modelId: string;
41
33
  actor?: Actor;
42
34
  reasoningLevel?: string;
@@ -119,7 +111,6 @@ export declare function persistAuthPauseSessionRecord(args: {
119
111
  loadedSkillNames?: string[];
120
112
  modelId: string;
121
113
  errorMessage: string;
122
- logContext: SessionRecordLogContext;
123
114
  actor?: Actor;
124
115
  reasoningLevel?: string;
125
116
  surface?: AgentTurnSurface;
@@ -138,7 +129,6 @@ interface ContinuationRecordInput {
138
129
  loadedSkillNames?: string[];
139
130
  modelId: string;
140
131
  errorMessage: string;
141
- logContext: SessionRecordLogContext;
142
132
  actor?: Actor;
143
133
  reasoningLevel?: string;
144
134
  surface?: AgentTurnSurface;
@@ -164,7 +154,6 @@ export declare function persistYieldSessionRecord(args: {
164
154
  loadedSkillNames?: string[];
165
155
  modelId: string;
166
156
  errorMessage: string;
167
- logContext: SessionRecordLogContext;
168
157
  actor?: Actor;
169
158
  reasoningLevel?: string;
170
159
  surface?: AgentTurnSurface;
@@ -7,25 +7,30 @@ type ZodToolDefinitionBase<TInputSchema extends ZodTypeAny> = Pick<AnyToolDefini
7
7
  inputSchema: TInputSchema;
8
8
  prepareArguments?: (args: unknown) => z.input<TInputSchema>;
9
9
  };
10
- type StructuredToolExecuteResult<TOutputSchema extends ZodType<JuniorToolResult>> = z.input<TOutputSchema>;
10
+ type StructuredToolExecuteResult<TOutputSchema extends ZodType<JuniorToolResult>> = z.input<TOutputSchema> | StructuredToolResultEnvelope<z.input<TOutputSchema>>;
11
+ interface StructuredToolResultEnvelope<TDetails> {
12
+ content: Array<TextContent | ImageContent>;
13
+ details: TDetails;
14
+ }
11
15
  export interface ContentOnlyToolResult {
12
16
  content: Array<TextContent | ImageContent>;
13
17
  details?: never;
14
18
  }
15
- type StructuredZodToolDefinition<TInputSchema extends ZodTypeAny, TOutputSchema extends ZodType<JuniorToolResult>> = ZodToolDefinitionBase<TInputSchema> & {
19
+ type StructuredZodToolDefinition<TInputSchema extends ZodTypeAny, TOutputSchema extends ZodType<JuniorToolResult>, TExecuteResult extends StructuredToolExecuteResult<TOutputSchema>> = ZodToolDefinitionBase<TInputSchema> & {
16
20
  outputSchema: TOutputSchema;
17
21
  privateTraceResult?(result: z.output<TOutputSchema>): unknown;
18
- execute?: (input: z.output<TInputSchema>, options: ToolExecuteOptions) => Promise<StructuredToolExecuteResult<TOutputSchema>> | StructuredToolExecuteResult<TOutputSchema>;
22
+ execute?: (input: z.output<TInputSchema>, options: ToolExecuteOptions) => Promise<TExecuteResult> | TExecuteResult;
19
23
  };
20
24
  type ContentZodToolDefinition<TInputSchema extends ZodTypeAny> = ZodToolDefinitionBase<TInputSchema> & {
21
25
  outputSchema?: undefined;
22
26
  execute?: (input: z.output<TInputSchema>, options: ToolExecuteOptions) => Promise<ContentOnlyToolResult> | ContentOnlyToolResult;
23
27
  };
24
- type StructuredZodTool<TInputSchema extends ZodTypeAny, TOutputSchema extends ZodType<JuniorToolResult>> = Omit<AnyToolDefinition, "inputSchema" | "outputSchema" | "prepareArguments" | "execute"> & {
28
+ type ParsedStructuredToolExecuteResult<TOutputSchema extends ZodType<JuniorToolResult>, TExecuteResult> = TExecuteResult extends StructuredToolResultEnvelope<unknown> ? StructuredToolResultEnvelope<z.output<TOutputSchema>> : z.output<TOutputSchema>;
29
+ type StructuredZodTool<TInputSchema extends ZodTypeAny, TOutputSchema extends ZodType<JuniorToolResult>, TExecuteResult> = Omit<AnyToolDefinition, "inputSchema" | "outputSchema" | "prepareArguments" | "execute"> & {
25
30
  inputSchema: JsonSchemaObject;
26
31
  outputSchema: JsonSchemaObject;
27
32
  prepareArguments(args: unknown): z.output<TInputSchema>;
28
- execute?: (input: unknown, options: ToolExecuteOptions) => Promise<z.output<TOutputSchema>> | z.output<TOutputSchema>;
33
+ execute?: (input: unknown, options: ToolExecuteOptions) => Promise<ParsedStructuredToolExecuteResult<TOutputSchema, TExecuteResult>> | ParsedStructuredToolExecuteResult<TOutputSchema, TExecuteResult>;
29
34
  };
30
35
  type ContentZodTool<TInputSchema extends ZodTypeAny> = Omit<AnyToolDefinition, "inputSchema" | "outputSchema" | "prepareArguments" | "execute"> & {
31
36
  inputSchema: JsonSchemaObject;
@@ -36,6 +41,6 @@ type ContentZodTool<TInputSchema extends ZodTypeAny> = Omit<AnyToolDefinition, "
36
41
  /**
37
42
  * Define a Junior-owned tool with Zod input parsing and JSON Schema parameters.
38
43
  */
39
- export declare function zodTool<TInputSchema extends ZodTypeAny, TOutputSchema extends ZodType<JuniorToolResult>>(definition: StructuredZodToolDefinition<TInputSchema, TOutputSchema>): StructuredZodTool<TInputSchema, TOutputSchema>;
44
+ export declare function zodTool<TInputSchema extends ZodTypeAny, TOutputSchema extends ZodType<JuniorToolResult>, TExecuteResult extends StructuredToolExecuteResult<TOutputSchema>>(definition: StructuredZodToolDefinition<TInputSchema, TOutputSchema, TExecuteResult>): StructuredZodTool<TInputSchema, TOutputSchema, TExecuteResult>;
40
45
  export declare function zodTool<TInputSchema extends ZodTypeAny>(definition: ContentZodToolDefinition<TInputSchema>): ContentZodTool<TInputSchema>;
41
46
  export {};
@@ -7,37 +7,5 @@ export declare function createExecuteToolTool(): Omit<import("./definition").Any
7
7
  tool_name: string;
8
8
  arguments?: Record<string, unknown> | undefined;
9
9
  };
10
- execute?: ((input: unknown, options: import("./definition").ToolExecuteOptions) => {
11
- [x: string]: unknown;
12
- ok: boolean;
13
- status: "error" | "success";
14
- target?: string | undefined;
15
- data?: unknown;
16
- truncated?: boolean | undefined;
17
- continuation?: {
18
- arguments: Record<string, unknown>;
19
- reason?: string | undefined;
20
- } | undefined;
21
- error?: string | {
22
- kind: string;
23
- message: string;
24
- retryable?: boolean | undefined;
25
- } | undefined;
26
- } | Promise<{
27
- [x: string]: unknown;
28
- ok: boolean;
29
- status: "error" | "success";
30
- target?: string | undefined;
31
- data?: unknown;
32
- truncated?: boolean | undefined;
33
- continuation?: {
34
- arguments: Record<string, unknown>;
35
- reason?: string | undefined;
36
- } | undefined;
37
- error?: string | {
38
- kind: string;
39
- message: string;
40
- retryable?: boolean | undefined;
41
- } | undefined;
42
- }>) | undefined;
10
+ execute?: ((input: unknown, options: import("./definition").ToolExecuteOptions) => Promise<never>) | undefined;
43
11
  };
@@ -1,4 +1,4 @@
1
- import { type LogContext, type SetSpanAttributes } from "@/chat/logging";
1
+ import { type SetSpanAttributes } from "@/chat/logging";
2
2
  import type { ConversationPrivacy } from "@/chat/conversation-privacy";
3
3
  /** Handle tool execution errors: set span attributes, log, and rethrow. */
4
- export declare function handleToolExecutionError(error: unknown, toolName: string, toolCallId: string | undefined, shouldTrace: boolean, traceContext: LogContext, conversationPrivacy?: ConversationPrivacy, setExecutionSpanAttributes?: SetSpanAttributes): never;
4
+ export declare function handleToolExecutionError(error: unknown, toolName: string, toolCallId: string | undefined, shouldTrace: boolean, conversationPrivacy?: ConversationPrivacy, setExecutionSpanAttributes?: SetSpanAttributes): never;
@@ -1,6 +1,6 @@
1
1
  import { type KnownConversationEventType } from "@/chat/conversations/history";
2
2
  import type { ToolRuntimeContext } from "@/chat/tools/types";
3
- /** Create a deferred tool that returns a bounded raw conversation event page. */
3
+ /** Create a deferred tool that returns a bounded conversation event page. */
4
4
  export declare function createQueryConversationEventsTool(context: ToolRuntimeContext): Omit<import("./definition").AnyToolDefinition, "inputSchema" | "outputSchema" | "prepareArguments" | "execute"> & {
5
5
  inputSchema: import("./definition").JsonSchemaObject;
6
6
  outputSchema: import("./definition").JsonSchemaObject;
@@ -37,6 +37,7 @@ export declare function createQueryConversationEventsTool(context: ToolRuntimeCo
37
37
  message: string;
38
38
  retryable?: boolean | undefined;
39
39
  } | undefined;
40
+ omitted_event_count?: number | undefined;
40
41
  } | Promise<{
41
42
  [x: string]: unknown;
42
43
  ok: boolean;
@@ -63,6 +64,7 @@ export declare function createQueryConversationEventsTool(context: ToolRuntimeCo
63
64
  message: string;
64
65
  retryable?: boolean | undefined;
65
66
  } | undefined;
67
+ omitted_event_count?: number | undefined;
66
68
  }>) | undefined;
67
69
  };
68
70
  export type { KnownConversationEventType };
@@ -6,37 +6,5 @@ export declare function createBashTool(): Omit<import("../definition").AnyToolDe
6
6
  command: string;
7
7
  timeoutMs?: number | undefined;
8
8
  };
9
- execute?: ((input: unknown, options: import("../definition").ToolExecuteOptions) => {
10
- [x: string]: unknown;
11
- ok: boolean;
12
- status: "error" | "success";
13
- target?: string | undefined;
14
- data?: unknown;
15
- truncated?: boolean | undefined;
16
- continuation?: {
17
- arguments: Record<string, unknown>;
18
- reason?: string | undefined;
19
- } | undefined;
20
- error?: string | {
21
- kind: string;
22
- message: string;
23
- retryable?: boolean | undefined;
24
- } | undefined;
25
- } | Promise<{
26
- [x: string]: unknown;
27
- ok: boolean;
28
- status: "error" | "success";
29
- target?: string | undefined;
30
- data?: unknown;
31
- truncated?: boolean | undefined;
32
- continuation?: {
33
- arguments: Record<string, unknown>;
34
- reason?: string | undefined;
35
- } | undefined;
36
- error?: string | {
37
- kind: string;
38
- message: string;
39
- retryable?: boolean | undefined;
40
- } | undefined;
41
- }>) | undefined;
9
+ execute?: ((input: unknown, options: import("../definition").ToolExecuteOptions) => Promise<never>) | undefined;
42
10
  };
@@ -61,38 +61,6 @@ export declare function createEditFileTool(): Omit<import("../definition").AnyTo
61
61
  newText: string;
62
62
  }[];
63
63
  };
64
- execute?: ((input: unknown, options: import("../definition").ToolExecuteOptions) => {
65
- [x: string]: unknown;
66
- ok: boolean;
67
- status: "error" | "success";
68
- target?: string | undefined;
69
- data?: unknown;
70
- truncated?: boolean | undefined;
71
- continuation?: {
72
- arguments: Record<string, unknown>;
73
- reason?: string | undefined;
74
- } | undefined;
75
- error?: string | {
76
- kind: string;
77
- message: string;
78
- retryable?: boolean | undefined;
79
- } | undefined;
80
- } | Promise<{
81
- [x: string]: unknown;
82
- ok: boolean;
83
- status: "error" | "success";
84
- target?: string | undefined;
85
- data?: unknown;
86
- truncated?: boolean | undefined;
87
- continuation?: {
88
- arguments: Record<string, unknown>;
89
- reason?: string | undefined;
90
- } | undefined;
91
- error?: string | {
92
- kind: string;
93
- message: string;
94
- retryable?: boolean | undefined;
95
- } | undefined;
96
- }>) | undefined;
64
+ execute?: ((input: unknown, options: import("../definition").ToolExecuteOptions) => Promise<never>) | undefined;
97
65
  };
98
66
  export {};