zidane 6.6.3 → 7.0.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.
- package/dist/{acp-BQqhozmt.js → acp-Wr8l4IDI.js} +7 -180
- package/dist/acp-Wr8l4IDI.js.map +1 -0
- package/dist/acp-cli.js +6 -6
- package/dist/acp.d.ts +1 -1
- package/dist/acp.d.ts.map +1 -1
- package/dist/acp.js +2 -1
- package/dist/{agent-DTxH7RHW.js → agent-C-camKQW.js} +162 -12
- package/dist/agent-C-camKQW.js.map +1 -0
- package/dist/agent.d.ts +1 -1
- package/dist/agent.js +1 -1
- package/dist/{anthropic-DRNRnd6W.js → anthropic-BDOGzhtj.js} +3 -3
- package/dist/{anthropic-DRNRnd6W.js.map → anthropic-BDOGzhtj.js.map} +1 -1
- package/dist/{transcript-anchors-BjH-68k2.js → approvals-CqqxE5Vh.js} +4924 -275
- package/dist/approvals-CqqxE5Vh.js.map +1 -0
- package/dist/{auth-7rv6ZfWk.js → auth-BdwDROYg.js} +12 -8
- package/dist/{auth-7rv6ZfWk.js.map → auth-BdwDROYg.js.map} +1 -1
- package/dist/chat/pure.d.ts +221 -4
- package/dist/chat/pure.d.ts.map +1 -0
- package/dist/chat/pure.js +4 -2
- package/dist/chat.d.ts +6 -2911
- package/dist/chat.js +8 -261
- package/dist/{context-transport-D8yeGdpd.js → context-transport-BqYwzJYE.js} +2 -2
- package/dist/{context-transport-D8yeGdpd.js.map → context-transport-BqYwzJYE.js.map} +1 -1
- package/dist/contexts/daytona.d.ts +2 -1
- package/dist/contexts/daytona.d.ts.map +1 -1
- package/dist/contexts/daytona.js +14 -3
- package/dist/contexts/daytona.js.map +1 -1
- package/dist/contexts/e2b.d.ts +1 -1
- package/dist/contexts/e2b.js +1 -1
- package/dist/daemon-cli.d.ts +1 -0
- package/dist/daemon-cli.js +90 -0
- package/dist/daemon-cli.js.map +1 -0
- package/dist/eval.d.ts +1 -1
- package/dist/eval.js +1 -1
- package/dist/extensions.d.ts +2 -2
- package/dist/extensions.js +2 -2
- package/dist/headless.d.ts +1 -1
- package/dist/headless.js +4 -4
- package/dist/{index-D0O-QO7Z.d.ts → index-B-FSaM3_.d.ts} +2863 -2375
- package/dist/index-B-FSaM3_.d.ts.map +1 -0
- package/dist/index-DgdzXRPH.d.ts +3590 -0
- package/dist/index-DgdzXRPH.d.ts.map +1 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.js +14 -1179
- package/dist/ipc-CIv87xuH.js +331 -0
- package/dist/ipc-CIv87xuH.js.map +1 -0
- package/dist/ipc.d.ts +849 -0
- package/dist/ipc.d.ts.map +1 -0
- package/dist/ipc.js +4 -0
- package/dist/json-rpc-rSWMUh9b.js +192 -0
- package/dist/json-rpc-rSWMUh9b.js.map +1 -0
- package/dist/{logger-DBX9uYOw.js → logger--C1VQjwJ.js} +3 -13
- package/dist/logger--C1VQjwJ.js.map +1 -0
- package/dist/logs-view-CWG8aUAG.js +44 -0
- package/dist/logs-view-CWG8aUAG.js.map +1 -0
- package/dist/{mcp-CVtSQTWg.js → mcp-BIWa57eY.js} +3 -3
- package/dist/{mcp-CVtSQTWg.js.map → mcp-BIWa57eY.js.map} +1 -1
- package/dist/mcp.d.ts +1 -1
- package/dist/mcp.js +1 -1
- package/dist/{messages-CZMUuKzo.js → messages-21XfHxyF.js} +3 -3
- package/dist/{messages-CZMUuKzo.js.map → messages-21XfHxyF.js.map} +1 -1
- package/dist/{openai-compat-BoTi-9fd.js → openai-compat-DY-AKxCg.js} +2 -2
- package/dist/{openai-compat-BoTi-9fd.js.map → openai-compat-DY-AKxCg.js.map} +1 -1
- package/dist/output/stream-json.d.ts +1 -1
- package/dist/output/terminal.d.ts +1 -1
- package/dist/{plugins-onDvTHEm.js → plugins-B531Tz5b.js} +2 -2
- package/dist/{plugins-onDvTHEm.js.map → plugins-B531Tz5b.js.map} +1 -1
- package/dist/plugins.d.ts +1 -1
- package/dist/plugins.js +1 -1
- package/dist/presets.d.ts +1 -1
- package/dist/presets.js +1 -1
- package/dist/providers/anthropic.d.ts +1 -1
- package/dist/providers/anthropic.js +1 -1
- package/dist/providers/arcee.d.ts +1 -1
- package/dist/providers/arcee.js +1 -1
- package/dist/providers/baseten.d.ts +1 -1
- package/dist/providers/baseten.js +1 -1
- package/dist/providers/cerebras.d.ts +1 -1
- package/dist/providers/cerebras.js +1 -1
- package/dist/providers/local.d.ts +1 -1
- package/dist/providers/local.js +1 -1
- package/dist/providers/openai-compat.d.ts +1 -1
- package/dist/providers/openai-compat.js +1 -1
- package/dist/providers/openai.d.ts +1 -1
- package/dist/providers/openai.js +3 -3
- package/dist/providers/openrouter.d.ts +1 -1
- package/dist/providers/openrouter.js +1 -1
- package/dist/providers/xai.d.ts +1 -1
- package/dist/providers/xai.js +1 -1
- package/dist/{providers-CmhdtD7w.js → providers-DX91jwir.js} +2 -2
- package/dist/{providers-CmhdtD7w.js.map → providers-DX91jwir.js.map} +1 -1
- package/dist/providers.d.ts +1 -1
- package/dist/providers.js +3 -3
- package/dist/restate.d.ts +1 -1
- package/dist/restate.js +8 -8
- package/dist/restate.js.map +1 -1
- package/dist/server-DJqp9dIR.js +1317 -0
- package/dist/server-DJqp9dIR.js.map +1 -0
- package/dist/session/sqlite.d.ts +1 -1
- package/dist/session/sqlite.d.ts.map +1 -1
- package/dist/session/sqlite.js +42 -4
- package/dist/session/sqlite.js.map +1 -1
- package/dist/{session-CyRLSsVa.js → session-K3icbPH9.js} +8 -2
- package/dist/session-K3icbPH9.js.map +1 -0
- package/dist/session.d.ts +1 -1
- package/dist/session.js +2 -2
- package/dist/{skills-BMGH_KK1.js → skills-PJyiSRCp.js} +3 -21
- package/dist/skills-PJyiSRCp.js.map +1 -0
- package/dist/skills.d.ts +1 -1
- package/dist/skills.js +1 -1
- package/dist/src-DzzhE2YO.js +2461 -0
- package/dist/src-DzzhE2YO.js.map +1 -0
- package/dist/todo-edits-Dw2oO2ON.js +378 -0
- package/dist/todo-edits-Dw2oO2ON.js.map +1 -0
- package/dist/{tool-formatters-NrzD6Fkk.d.ts → tool-formatters-DO56YBBw.d.ts} +104 -4
- package/dist/tool-formatters-DO56YBBw.d.ts.map +1 -0
- package/dist/tools/fetch-url.d.ts +1 -1
- package/dist/tools/web-search.d.ts +1 -1
- package/dist/tools.d.ts +1 -1
- package/dist/tools.js +1 -1
- package/dist/{transcript-anchors-UhC58Tmj.d.ts → transcript-anchors-DXqWWGbq.d.ts} +53 -4
- package/dist/transcript-anchors-DXqWWGbq.d.ts.map +1 -0
- package/dist/tui.d.ts +94 -13
- package/dist/tui.d.ts.map +1 -1
- package/dist/tui.js +2241 -1009
- package/dist/tui.js.map +1 -1
- package/dist/{turn-operations-mMxDRgLY.js → turn-operations-CZLsNgw-.js} +896 -11
- package/dist/turn-operations-CZLsNgw-.js.map +1 -0
- package/dist/{turn-operations-Cuc9pwiB.d.ts → turn-operations-DKFYWP3O.d.ts} +501 -4
- package/dist/turn-operations-DKFYWP3O.d.ts.map +1 -0
- package/dist/{types-BIarq1qE.js → types-CWgENVLY.js} +24 -2
- package/dist/types-CWgENVLY.js.map +1 -0
- package/dist/types.d.ts +1 -1
- package/dist/types.js +1 -1
- package/dist/xml-D5HBhJle.js +22 -0
- package/dist/xml-D5HBhJle.js.map +1 -0
- package/docs/CHAT.md +39 -0
- package/docs/IPC.md +420 -0
- package/docs/TUI.md +62 -0
- package/package.json +8 -2
- package/dist/acp-BQqhozmt.js.map +0 -1
- package/dist/agent-DTxH7RHW.js.map +0 -1
- package/dist/chat.d.ts.map +0 -1
- package/dist/chat.js.map +0 -1
- package/dist/index-D0O-QO7Z.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/inline-autocomplete-D0MPvBaS.js +0 -596
- package/dist/inline-autocomplete-D0MPvBaS.js.map +0 -1
- package/dist/logger-DBX9uYOw.js.map +0 -1
- package/dist/login-CB23LyI1.js +0 -707
- package/dist/login-CB23LyI1.js.map +0 -1
- package/dist/session-CyRLSsVa.js.map +0 -1
- package/dist/skills-BMGH_KK1.js.map +0 -1
- package/dist/tool-formatters-NrzD6Fkk.d.ts.map +0 -1
- package/dist/transcript-anchors-BjH-68k2.js.map +0 -1
- package/dist/transcript-anchors-UhC58Tmj.d.ts.map +0 -1
- package/dist/turn-operations-Cuc9pwiB.d.ts.map +0 -1
- package/dist/turn-operations-mMxDRgLY.js.map +0 -1
- package/dist/types-BIarq1qE.js.map +0 -1
package/dist/index.js
CHANGED
|
@@ -1,1200 +1,35 @@
|
|
|
1
|
-
import { E as getModelCatalog, b as sanitizeToolSpecs, f as mapOAIFinishReason, j as setModelCatalog, l as classifyOpenAICompatError, m as openaiCompat, n as OpenAICompatHttpError, y as sanitizeToolSchema } from "./openai-compat-
|
|
2
|
-
import { c as
|
|
3
|
-
import { $ as installExtensionFromSpec, A as selectFilesFromSession, An as
|
|
1
|
+
import { E as getModelCatalog, b as sanitizeToolSpecs, f as mapOAIFinishReason, j as setModelCatalog, l as classifyOpenAICompatError, m as openaiCompat, n as OpenAICompatHttpError, y as sanitizeToolSchema } from "./openai-compat-DY-AKxCg.js";
|
|
2
|
+
import { c as toolOutputBudgetByteLength, l as toolOutputByteLength, u as toolResultToText } from "./types-CWgENVLY.js";
|
|
3
|
+
import { $ as installExtensionFromSpec, A as selectFilesFromSession, An as EXTENSION_BUS_MAX_PAYLOAD_BYTES, At as createSkillsReadTool, B as buildUpToCompactPrompt, Bn as stableStringify, Bt as matchModelEntries, C as resolveLegacySessionDir, Cn as coerceExtensionConfigInput, Ct as waitTask, D as resolveTasksDir, Dn as resolveExtensionConfigValue, E as resolveSessionDir, En as resolveExtensionConfig, Et as isSpawnTool, F as TRAILER, Fn as effectiveContextWindow, G as summaryToTurn, Gn as readStateKey, Gt as edit, H as anchorPreviewFor, Hn as hashContent, Ht as createInteractionTool, I as buildCompactPrompt, In as shouldAutoCompact, J as CompactPromptTooLongError, K as truncateHeadForPtlRetry, Kn as resolveReadStateMap, Kt as validateToolArgs, L as buildFromCompactPrompt, Ln as defaultRepeatGuardNormalize, Lt as multiEdit, M as compactConversation, Mt as createShellTool, N as BASE_INSTRUCTIONS, Nn as AUTO_COMPACT_MIN_GROWTH_FRACTION, O as buildPostCompactAttachments, On as sanitizeExtensionConfigActionPatch, Ot as createSkillsUseTool, P as NO_TOOLS_PREAMBLE, Pn as OUTPUT_RESERVE_TOKENS, Q as fetchExtensionSource, R as buildFullCompactPrompt, Rn as defaultRepeatGuardTracked, Rt as createModelSearchTool, S as resolveLegacyPersistDir, Sn as clampExtensionConfigNumber, T as resolvePersistDir, Tn as isValidExtensionConfigValue, Tt as createSpawnTool, U as sliceForCompaction, Un as hydrateReadStateFromSession, Ut as grep, V as ANCHOR_PREVIEW_MAX_CHARS, Vn as getReadState, W as stripImagesFromTurns, Wn as hydrateReadStateFromSessionAsync, Wt as glob, X as createExtensionPromptBridge, Y as EMPTY_EXTENSION_REGISTRY, Z as ExtensionInstallError, _ as buildPersistedStub, _n as parseExtensionScanPathEnv, a as stagedToolState, at as createExtensionHud, b as migrateSessionArtifactDirs, bt as basic_default, c as INTERRUPT_MESSAGE_FOR_TOOL_USE, ct as buildExtensionRegistry, d as TOOL_USE_SKIPPED_MESSAGE, dn as registerExtensionHostModules, dt as filterExtensionRegistry, et as listExtensionCandidates, f as applyCompactSummaryCutoff, fn as ENTRY_CANDIDATES, g as PERSISTENCE_PREVIEW_BYTES, gn as isExtensionDefinition, gt as createWorkspaceSurface, h as PERSISTED_STUB_PREFIX, hn as inlineLoadedExtension, ht as createExtensionHostRuntimeBridge, i as isToolStateOps, it as updateInstalledExtension, j as selectRecentFiles, jn as createExtensionBus, k as selectFilesFromReadState, kn as toWireConfigSchema, kt as createSkillsRunScriptTool, l as SHELL_CASCADE_CANCEL_MESSAGE, lt as composeExtensionPreset, m as renderStaleReadNotice, mn as discoverExtensions, mt as partitionExtensionCatalog, n as DEFAULT_MAX_VALUE_BYTES, nt as readExtensionInstallProvenance, o as normalizeProviders, ot as discoverAndBuildExtensionRegistry, p as collectNewlyStaleReadPaths, pn as defaultExtensionScanPaths, pt as mergeContributions, q as CompactInvalidInputError, r as createToolStateController, rt as removeInstalledExtension, s as resolveModelTargets, st as buildExtensionPreset, t as createAgent, tt as parseExtensionInstallSource, u as TOOL_USE_CANCELLED_MESSAGE, ut as disposeExtensionRegistry, v as cleanupPersistedSession, vn as scanExtensionDirectories, vt as definePreset, w as resolveMcpWarningsDir, wn as isValidExtensionConfigItem, xn as defineExtension, y as maybePersistToolResult, yt as basicTools, z as buildTailCompactPrompt, zn as normalizeShellCommand, zt as formatModelLine } from "./agent-C-camKQW.js";
|
|
4
|
+
import { A as zodToJsonSchema, F as parseCommandInvocation, I as localReliabilityBehavior, M as commandBlocksToContent, N as commandSteps, O as isStandardSchema, P as executeCommand, S as resolveInlineSuggestion, _ as resolveExtensionDocsDir, a as loginMcpServer, b as createPathAutocompleteProvider, c as SKILL_EDIT_METADATA_KEY, d as buildZidaneExtensionSkill, f as buildZidaneSkillEditSkill, g as readSkillEditMarker, h as extensionScaffold, i as createMetricsHooks, j as commandBlockToEvent, k as resolveSchemaInput, l as ZIDANE_EXTENSION_SKILL_NAME, m as extensionDirForCwd, n as createTracingHooks, o as startOAuthCallback, p as editSessionMetadata, r as createMutationValidationHooks, s as EXTENSION_EDIT_METADATA_KEY, t as GEN_AI_ATTRIBUTES, u as ZIDANE_SKILL_EDIT_SKILL_NAME, v as withZidaneExtensionSkill, w as generateStructuredData, x as patchInlineGhost, y as withZidaneSkillEditSkill } from "./src-DzzhE2YO.js";
|
|
4
5
|
import { n as estimateTokens, r as utf8ByteLength, t as BYTES_PER_TOKEN } from "./utils-ngQzYzZD.js";
|
|
5
6
|
import { r as createProcessContext, t as resolveDetachedTasksCapability } from "./contexts-BSFQVclW.js";
|
|
6
7
|
import { createSandboxContext } from "./contexts/sandbox.js";
|
|
7
8
|
import { a as AgentProviderError, c as CONTEXT_EXCEEDED_MESSAGE_PATTERNS, g as toTypedError, i as AgentLengthResumeExhaustedError, m as matchesContextExceeded, n as AgentBudgetExceededError, o as AgentToolNotAllowedError, r as AgentContextExceededError, s as AgentToolPairingError, t as AgentAbortedError, u as errorMessage } from "./errors-DKiMrOKq.js";
|
|
8
|
-
import { A as
|
|
9
|
-
import { a as PLUGIN_MCP_FILE, c as validatePluginManifest, d as isSupportedAgentPluginsVersion, f as parseSchemaId, i as PLUGIN_SKILLS_DIR, l as SUPPORTED_AGENT_PLUGINS_VERSIONS, n as defaultPluginDataRoot, o as expandPluginVars, r as loadAgentPlugin, s as parsePluginManifest, t as PLUGIN_MANIFEST_FILE, u as agentPluginsSchemaId } from "./plugins-
|
|
10
|
-
import {
|
|
9
|
+
import { A as isToolAllowedByUnion, D as IMPLICITLY_ALLOWED_SKILL_TOOLS, E as buildCatalog, F as validateSkillForWrite, I as validateSkillName, M as parseAllowedToolPattern, N as validateResourcePath, O as installAllowedToolsGate, P as validateResourcePathReal, T as parseSkillFile, a as interpolateShellCommands, c as SkillInstallError, d as parseSkillInstallSpec, f as readSkillProvenance, i as writeSkillsToDisk, j as matchesAllowedTool, k as createSkillActivationState, l as installSkillFromSpec, n as resolveSkills, o as stripShellInterpolations, r as writeSkillToDisk, t as defineSkill, u as listSkillCandidates, x as discoverSkills } from "./skills-PJyiSRCp.js";
|
|
10
|
+
import { a as PLUGIN_MCP_FILE, c as validatePluginManifest, d as isSupportedAgentPluginsVersion, f as parseSchemaId, i as PLUGIN_SKILLS_DIR, l as SUPPORTED_AGENT_PLUGINS_VERSIONS, n as defaultPluginDataRoot, o as expandPluginVars, r as loadAgentPlugin, s as parsePluginManifest, t as PLUGIN_MANIFEST_FILE, u as agentPluginsSchemaId } from "./plugins-B531Tz5b.js";
|
|
11
|
+
import { r as formatLogLine } from "./logs-view-CWG8aUAG.js";
|
|
12
|
+
import { a as createRingBufferSink, i as createLoggingHooks, o as fanoutSink, r as createLogger, s as jsonSink, t as consoleSink } from "./logger--C1VQjwJ.js";
|
|
11
13
|
import { n as originPinnedFetch } from "./origin-pinned-fetch-CqG8VZIq.js";
|
|
12
|
-
import { _ as hasAuthorizationHeader, a as expandEnvPlaceholders, c as normalizeMcpBlocks, d as resultToString, g as createMemoryMcpCredentialStore, h as McpOAuthProvider, l as normalizeMcpServers, n as connectMcpServers, o as expandMcpConfigEnv, u as resolveTransportConfig } from "./mcp-
|
|
14
|
+
import { _ as hasAuthorizationHeader, a as expandEnvPlaceholders, c as normalizeMcpBlocks, d as resultToString, g as createMemoryMcpCredentialStore, h as McpOAuthProvider, l as normalizeMcpServers, n as connectMcpServers, o as expandMcpConfigEnv, u as resolveTransportConfig } from "./mcp-BIWa57eY.js";
|
|
13
15
|
import { SYSTEM_PROMPT_BOUNDARY, appendDynamicSection, appendStaticSection, hasSystemPromptBoundary, joinSystemPrompt, renderSystemForWire, replaceDynamicSection, splitSystemPrompt } from "./prompt.js";
|
|
14
|
-
import { _ as toOpenAI, a as detectTurnInterruption, c as ensureToolResultPairing, d as fromOpenAI, f as reasoningWireAction, g as toAnthropic, h as sanitizeHistoryForProvider, i as autoDetectAndConvert, l as filterUnresolvedToolUses, n as SYNTHETIC_TOOL_RESULT_PLACEHOLDER, o as dropInvalidToolPairings, p as remintDuplicateToolCallIds, r as TOOL_USE_INTERRUPTED_MARKER, s as ensureEndsWithUserMessage, t as ORPHANED_TOOL_RESULT_MARKER, u as fromAnthropic, v as toWireMessages } from "./messages-
|
|
15
|
-
import { d as createMemoryStore, f as createFileMapStore, o as loadSession, t as createSession, u as createRemoteStore } from "./session-
|
|
16
|
+
import { _ as toOpenAI, a as detectTurnInterruption, c as ensureToolResultPairing, d as fromOpenAI, f as reasoningWireAction, g as toAnthropic, h as sanitizeHistoryForProvider, i as autoDetectAndConvert, l as filterUnresolvedToolUses, n as SYNTHETIC_TOOL_RESULT_PLACEHOLDER, o as dropInvalidToolPairings, p as remintDuplicateToolCallIds, r as TOOL_USE_INTERRUPTED_MARKER, s as ensureEndsWithUserMessage, t as ORPHANED_TOOL_RESULT_MARKER, u as fromAnthropic, v as toWireMessages } from "./messages-21XfHxyF.js";
|
|
17
|
+
import { d as createMemoryStore, f as createFileMapStore, o as loadSession, t as createSession, u as createRemoteStore } from "./session-K3icbPH9.js";
|
|
16
18
|
import { i as statsByModel, n as flattenTurns, r as formatTokenUsage } from "./stats-DAKBEKjc.js";
|
|
17
19
|
import { t as OperationTimeoutError } from "./timeout-CjOG2mea.js";
|
|
18
20
|
import { a as snapshotCacheDimensions, i as installCacheBreakLogger, n as fnv1a32, r as hashMessages, t as diffCacheDimensions } from "./cache-telemetry-ehVdWsg2.js";
|
|
19
|
-
import { a as generateStructuredData, d as zodToJsonSchema, f as commandBlockToEvent, g as parseCommandInvocation, h as executeCommand, l as isStandardSchema, m as commandSteps, n as patchInlineGhost, p as commandBlocksToContent, r as resolveInlineSuggestion, t as createPathAutocompleteProvider, u as resolveSchemaInput } from "./inline-autocomplete-D0MPvBaS.js";
|
|
20
21
|
import { s as resolveCompletionSubmit } from "./completion-core-BRo86R_L.js";
|
|
21
22
|
import { t as createRunSummaryCollector } from "./run-summary-BU_NgwUT.js";
|
|
22
23
|
import { headlessEventToJsonl, runHeadless, transcriptToOpenAIMessages } from "./headless.js";
|
|
23
24
|
import { EFFICIENCY_METRICS, EvalMetricError, artifactPath, buildEvalRunSummary, buildRegisteredEvals, buildTrajectory, clearRegisteredEvals, computeEvalTagScores, createEvalAgent, createEvalRunReporter, createReusableExecutionContext, defineEval, defineMetrics, efficiencyMetricValues, emitEfficiencyMetrics, fileContains, fileContentQuality, fileExists, fileExistsOneOf, finalizeEvalMetrics, formatEvalCaseSummary, formatEvalRunSummary, formatTrajectoryLine, functionalityMetric, llmJudge, normalizeMetric, registerEvalTests, relativeArtifactPath, runEvalCase, statusCompleted } from "./eval.js";
|
|
24
|
-
import {
|
|
25
|
-
import { n as anthropic, r as applyAnthropicCacheBreakpoints } from "./anthropic-DRNRnd6W.js";
|
|
25
|
+
import { n as anthropic, r as applyAnthropicCacheBreakpoints } from "./anthropic-BDOGzhtj.js";
|
|
26
26
|
import { a as readOAuthCredentials, c as writeOAuthCredentials, d as refreshAnthropicToken, f as refreshOpenAICodexToken, i as isOAuthAccessToken, l as getOAuthApiKey, n as credentialsFromParams, o as registerCustomOAuthProvider, p as registerOAuthProvider, r as extractRuntimeCredentials, s as resolveOAuthApiKey, t as credentialsFilePath, u as getOAuthProvider } from "./oauth-C4GvY_p1.js";
|
|
27
27
|
import { arcee } from "./providers/arcee.js";
|
|
28
28
|
import { baseten } from "./providers/baseten.js";
|
|
29
29
|
import { cerebras } from "./providers/cerebras.js";
|
|
30
|
-
import { r as mistral } from "./providers-
|
|
30
|
+
import { r as mistral } from "./providers-DX91jwir.js";
|
|
31
31
|
import { local } from "./providers/local.js";
|
|
32
32
|
import { openai } from "./providers/openai.js";
|
|
33
33
|
import { openrouter } from "./providers/openrouter.js";
|
|
34
34
|
import { xai } from "./providers/xai.js";
|
|
35
|
-
|
|
36
|
-
const DEFAULT_LOCAL_RELIABILITY = {
|
|
37
|
-
maxConcurrentTools: 3,
|
|
38
|
-
readFileDefaults: {
|
|
39
|
-
limit: 400,
|
|
40
|
-
maxBytes: 64 * 1024
|
|
41
|
-
},
|
|
42
|
-
toolOutputBudget: 32 * 1024,
|
|
43
|
-
textToolCallRescue: { mode: "steer" },
|
|
44
|
-
thinkingOverrunPolicy: {
|
|
45
|
-
mode: "steer-next-turn",
|
|
46
|
-
thresholdTokens: 2048
|
|
47
|
-
}
|
|
48
|
-
};
|
|
49
|
-
/**
|
|
50
|
-
* Opt-in behavior overlay for brittle/local OpenAI-compatible endpoints.
|
|
51
|
-
* Returns plain `AgentBehavior` so hosts can spread it before or after their
|
|
52
|
-
* own overrides; no built-in profile uses this helper by default.
|
|
53
|
-
*/
|
|
54
|
-
function localReliabilityBehavior(overrides = {}) {
|
|
55
|
-
return {
|
|
56
|
-
...DEFAULT_LOCAL_RELIABILITY,
|
|
57
|
-
...overrides,
|
|
58
|
-
readFileDefaults: {
|
|
59
|
-
...DEFAULT_LOCAL_RELIABILITY.readFileDefaults,
|
|
60
|
-
...overrides.readFileDefaults ?? {}
|
|
61
|
-
},
|
|
62
|
-
textToolCallRescue: overrides.textToolCallRescue ?? DEFAULT_LOCAL_RELIABILITY.textToolCallRescue,
|
|
63
|
-
thinkingOverrunPolicy: overrides.thinkingOverrunPolicy ?? DEFAULT_LOCAL_RELIABILITY.thinkingOverrunPolicy
|
|
64
|
-
};
|
|
65
|
-
}
|
|
66
|
-
//#endregion
|
|
67
|
-
//#region src/metrics.ts
|
|
68
|
-
function prefixed$1(prefix, name) {
|
|
69
|
-
return prefix ? `${prefix}${name}` : name;
|
|
70
|
-
}
|
|
71
|
-
/**
|
|
72
|
-
* Drop `undefined` entries before handing attributes to a metrics
|
|
73
|
-
* backend. OTel's `@opentelemetry/api` rejects `undefined` attribute
|
|
74
|
-
* values (and Prometheus / StatsD adapters silently mis-label them); the
|
|
75
|
-
* helper's own API surface allows `undefined` for ergonomic call sites
|
|
76
|
-
* (`{...(cond ? { foo } : {})}`-style spreads), so we strip here at the
|
|
77
|
-
* boundary.
|
|
78
|
-
*/
|
|
79
|
-
function mergeAttrs(base, extra) {
|
|
80
|
-
const out = {};
|
|
81
|
-
if (base) {
|
|
82
|
-
for (const [k, v] of Object.entries(base)) if (v !== void 0) out[k] = v;
|
|
83
|
-
}
|
|
84
|
-
for (const [k, v] of Object.entries(extra)) if (v !== void 0) out[k] = v;
|
|
85
|
-
return out;
|
|
86
|
-
}
|
|
87
|
-
/**
|
|
88
|
-
* Build a set of metrics hook handlers that can be installed on an agent.
|
|
89
|
-
*
|
|
90
|
-
* @example OpenTelemetry
|
|
91
|
-
* ```ts
|
|
92
|
-
* import { metrics } from '@opentelemetry/api'
|
|
93
|
-
* const meter = metrics.getMeter('zidane')
|
|
94
|
-
* const m = createMetricsHooks({ meter, baseAttributes: { service: 'tui' } })
|
|
95
|
-
* const uninstall = m.install(agent.hooks)
|
|
96
|
-
* try { await agent.run({ prompt }) }
|
|
97
|
-
* finally { uninstall() }
|
|
98
|
-
* ```
|
|
99
|
-
*/
|
|
100
|
-
function createMetricsHooks(options) {
|
|
101
|
-
const ns = options.namespace;
|
|
102
|
-
const base = options.baseAttributes;
|
|
103
|
-
const onError = options.onError ?? (() => {});
|
|
104
|
-
const make = {
|
|
105
|
-
counter: (name, opts) => safeFactory(() => options.meter.createCounter(prefixed$1(ns, name), opts), name, onError),
|
|
106
|
-
histogram: (name, opts) => safeFactory(() => options.meter.createHistogram(prefixed$1(ns, name), opts), name, onError),
|
|
107
|
-
upDown: (name, opts) => safeFactory(() => options.meter.createUpDownCounter(prefixed$1(ns, name), opts), name, onError)
|
|
108
|
-
};
|
|
109
|
-
const turnDuration = make.histogram("gen_ai.client.operation.duration", {
|
|
110
|
-
unit: "ms",
|
|
111
|
-
description: "Per-turn LLM operation duration."
|
|
112
|
-
});
|
|
113
|
-
const tokenUsage = make.histogram("gen_ai.client.token.usage", {
|
|
114
|
-
unit: "tokens",
|
|
115
|
-
description: "Per-turn token usage (tagged by gen_ai.token.type)."
|
|
116
|
-
});
|
|
117
|
-
const ttft = make.histogram("gen_ai.client.time_to_first_token", {
|
|
118
|
-
unit: "ms",
|
|
119
|
-
description: "Per-turn time to first token."
|
|
120
|
-
});
|
|
121
|
-
const toolDuration = make.histogram("gen_ai.tool.duration", {
|
|
122
|
-
unit: "ms",
|
|
123
|
-
description: "Native tool execution wall clock."
|
|
124
|
-
});
|
|
125
|
-
const toolOutput = make.histogram("gen_ai.tool.output_bytes", {
|
|
126
|
-
unit: "By",
|
|
127
|
-
description: "Native tool output bytes."
|
|
128
|
-
});
|
|
129
|
-
const mcpToolDuration = make.histogram("gen_ai.mcp.tool.duration", {
|
|
130
|
-
unit: "ms",
|
|
131
|
-
description: "MCP tool execution wall clock."
|
|
132
|
-
});
|
|
133
|
-
const mcpBootstrapDuration = make.histogram("gen_ai.mcp.bootstrap.duration", {
|
|
134
|
-
unit: "ms",
|
|
135
|
-
description: "MCP server bootstrap duration."
|
|
136
|
-
});
|
|
137
|
-
const runsStarted = make.counter("gen_ai.agent.runs", { description: "Runs started." });
|
|
138
|
-
const runsCompleted = make.counter("gen_ai.agent.runs.completed", { description: "Runs completed." });
|
|
139
|
-
const aborts = make.counter("gen_ai.agent.aborts", { description: "Run abort events." });
|
|
140
|
-
const toolCalls = make.counter("gen_ai.tool.calls", { description: "Tool dispatches (tagged by outcome)." });
|
|
141
|
-
const toolErrors = make.counter("gen_ai.tool.errors", { description: "Native tool errors." });
|
|
142
|
-
const mcpToolErrors = make.counter("gen_ai.mcp.tool.errors", { description: "MCP tool errors." });
|
|
143
|
-
const streamErrors = make.counter("gen_ai.stream.errors", { description: "Provider stream errors." });
|
|
144
|
-
const validationRejects = make.counter("gen_ai.validation.rejects", { description: "Tool input validation rejects." });
|
|
145
|
-
const validationCoercions = make.counter("gen_ai.validation.coercions", { description: "Tool input auto-coercions." });
|
|
146
|
-
const gateBlocks = make.counter("gen_ai.gate.blocks", { description: "Tool-gate refusals." });
|
|
147
|
-
const budgetExceeded = make.counter("gen_ai.budget.exceeded", { description: "Per-turn byte budget exceedances." });
|
|
148
|
-
const toolBudgetExceeded = make.counter("gen_ai.tool_budget.exceeded", { description: "Per-tool dispatch budget exceedances." });
|
|
149
|
-
const pairingRepairs = make.counter("gen_ai.pairing.repairs", { description: "Tool-pairing repair counts." });
|
|
150
|
-
const oauthRefreshes = make.counter("gen_ai.oauth.refreshes", { description: "Provider OAuth credential refreshes." });
|
|
151
|
-
const mcpErrors = make.counter("gen_ai.mcp.errors", { description: "MCP server errors." });
|
|
152
|
-
const mcpAuthRequired = make.counter("gen_ai.mcp.auth.required", { description: "MCP bootstrap blocked on missing auth." });
|
|
153
|
-
const costMeter = make.counter("gen_ai.cost_usd", {
|
|
154
|
-
unit: "USD",
|
|
155
|
-
description: "Cumulative cost across turns."
|
|
156
|
-
});
|
|
157
|
-
const runsActive = make.upDown("gen_ai.agent.runs.active", { description: "In-flight agent runs." });
|
|
158
|
-
return { install(hooks) {
|
|
159
|
-
const turnStart = /* @__PURE__ */ new Map();
|
|
160
|
-
const toolStart = /* @__PURE__ */ new Map();
|
|
161
|
-
const mcpStart = /* @__PURE__ */ new Map();
|
|
162
|
-
const unregisters = [];
|
|
163
|
-
const record = (instrument, value, attrs, kind) => {
|
|
164
|
-
if (!instrument) return;
|
|
165
|
-
try {
|
|
166
|
-
instrument.record(value, mergeAttrs(base, attrs));
|
|
167
|
-
} catch (err) {
|
|
168
|
-
try {
|
|
169
|
-
onError(kind, err);
|
|
170
|
-
} catch {}
|
|
171
|
-
}
|
|
172
|
-
};
|
|
173
|
-
const add = (instrument, value, attrs, kind) => {
|
|
174
|
-
if (!instrument) return;
|
|
175
|
-
try {
|
|
176
|
-
instrument.add(value, mergeAttrs(base, attrs));
|
|
177
|
-
} catch (err) {
|
|
178
|
-
try {
|
|
179
|
-
onError(kind, err);
|
|
180
|
-
} catch {}
|
|
181
|
-
}
|
|
182
|
-
};
|
|
183
|
-
unregisters.push(hooks.hook("agent:start", (ctx) => {
|
|
184
|
-
const attrs = {
|
|
185
|
-
"gen_ai.agent.depth": ctx.depth,
|
|
186
|
-
...ctx.agentName ? { "gen_ai.agent.name": ctx.agentName } : {}
|
|
187
|
-
};
|
|
188
|
-
add(runsStarted, 1, attrs, "runs");
|
|
189
|
-
add(runsActive, 1, attrs, "runs.active");
|
|
190
|
-
}));
|
|
191
|
-
unregisters.push(hooks.hook("agent:done", () => {
|
|
192
|
-
add(runsCompleted, 1, {}, "runs.completed");
|
|
193
|
-
add(runsActive, -1, {}, "runs.active");
|
|
194
|
-
turnStart.clear();
|
|
195
|
-
toolStart.clear();
|
|
196
|
-
mcpStart.clear();
|
|
197
|
-
}));
|
|
198
|
-
unregisters.push(hooks.hook("agent:abort", () => {
|
|
199
|
-
add(aborts, 1, {}, "aborts");
|
|
200
|
-
}));
|
|
201
|
-
unregisters.push(hooks.hook("turn:before", (ctx) => {
|
|
202
|
-
turnStart.set(ctx.turnId, Date.now());
|
|
203
|
-
}));
|
|
204
|
-
unregisters.push(hooks.hook("turn:after", (ctx) => {
|
|
205
|
-
const started = turnStart.get(ctx.turnId);
|
|
206
|
-
turnStart.delete(ctx.turnId);
|
|
207
|
-
const tagsBase = {
|
|
208
|
-
"gen_ai.operation.name": "chat",
|
|
209
|
-
...ctx.usage.modelId ? { "gen_ai.response.model": ctx.usage.modelId } : {},
|
|
210
|
-
...ctx.usage.finishReason ? { "gen_ai.response.finish_reason": ctx.usage.finishReason } : {}
|
|
211
|
-
};
|
|
212
|
-
if (typeof started === "number") record(turnDuration, Date.now() - started, tagsBase, "turn.duration");
|
|
213
|
-
if (typeof ctx.usage.timeToFirstTokenMs === "number") record(ttft, ctx.usage.timeToFirstTokenMs, tagsBase, "ttft");
|
|
214
|
-
record(tokenUsage, ctx.usage.input, {
|
|
215
|
-
...tagsBase,
|
|
216
|
-
"gen_ai.token.type": "input"
|
|
217
|
-
}, "token.input");
|
|
218
|
-
record(tokenUsage, ctx.usage.output, {
|
|
219
|
-
...tagsBase,
|
|
220
|
-
"gen_ai.token.type": "output"
|
|
221
|
-
}, "token.output");
|
|
222
|
-
if (typeof ctx.usage.cacheRead === "number" && ctx.usage.cacheRead > 0) record(tokenUsage, ctx.usage.cacheRead, {
|
|
223
|
-
...tagsBase,
|
|
224
|
-
"gen_ai.token.type": "cache_read"
|
|
225
|
-
}, "token.cache_read");
|
|
226
|
-
if (typeof ctx.usage.cacheCreation === "number" && ctx.usage.cacheCreation > 0) record(tokenUsage, ctx.usage.cacheCreation, {
|
|
227
|
-
...tagsBase,
|
|
228
|
-
"gen_ai.token.type": "cache_creation"
|
|
229
|
-
}, "token.cache_creation");
|
|
230
|
-
if (typeof ctx.usage.cost === "number" && ctx.usage.cost > 0) add(costMeter, ctx.usage.cost, tagsBase, "cost");
|
|
231
|
-
}));
|
|
232
|
-
unregisters.push(hooks.hook("stream:error", (ctx) => {
|
|
233
|
-
add(streamErrors, 1, {
|
|
234
|
-
"http.response.status_code": ctx.statusCode,
|
|
235
|
-
"error.type": ctx.err instanceof Error ? ctx.err.name : "unknown"
|
|
236
|
-
}, "stream.error");
|
|
237
|
-
}));
|
|
238
|
-
unregisters.push(hooks.hook("tool:before", (ctx) => {
|
|
239
|
-
toolStart.set(ctx.callId, Date.now());
|
|
240
|
-
}));
|
|
241
|
-
unregisters.push(hooks.hook("tool:after", (ctx) => {
|
|
242
|
-
const started = toolStart.get(ctx.callId);
|
|
243
|
-
toolStart.delete(ctx.callId);
|
|
244
|
-
const tags = { "gen_ai.tool.name": ctx.name };
|
|
245
|
-
if (typeof started === "number") record(toolDuration, Date.now() - started, tags, "tool.duration");
|
|
246
|
-
record(toolOutput, ctx.outputBytes, tags, "tool.output_bytes");
|
|
247
|
-
}));
|
|
248
|
-
unregisters.push(hooks.hook("tool:error", (ctx) => {
|
|
249
|
-
add(toolErrors, 1, {
|
|
250
|
-
"gen_ai.tool.name": ctx.name,
|
|
251
|
-
"error.type": ctx.error.name
|
|
252
|
-
}, "tool.errors");
|
|
253
|
-
}));
|
|
254
|
-
unregisters.push(hooks.hook("tool:cancelled", (ctx) => {
|
|
255
|
-
toolStart.delete(ctx.callId);
|
|
256
|
-
}));
|
|
257
|
-
unregisters.push(hooks.hook("tool:dispatched", (ctx) => {
|
|
258
|
-
add(toolCalls, 1, {
|
|
259
|
-
"gen_ai.tool.name": ctx.name,
|
|
260
|
-
"outcome": ctx.outcome
|
|
261
|
-
}, "tool.calls");
|
|
262
|
-
if (ctx.outcome === "gate-block") add(gateBlocks, 1, {
|
|
263
|
-
"gen_ai.tool.name": ctx.name,
|
|
264
|
-
...ctx.reason ? { reason: ctx.reason } : {}
|
|
265
|
-
}, "gate.blocks");
|
|
266
|
-
if (ctx.outcome === "unknown") toolStart.delete(ctx.callId);
|
|
267
|
-
}));
|
|
268
|
-
unregisters.push(hooks.hook("validation:reject", (ctx) => {
|
|
269
|
-
add(validationRejects, 1, { "gen_ai.tool.name": ctx.name }, "validation.rejects");
|
|
270
|
-
}));
|
|
271
|
-
unregisters.push(hooks.hook("validation:coerce", (ctx) => {
|
|
272
|
-
add(validationCoercions, 1, {
|
|
273
|
-
"gen_ai.tool.name": ctx.name,
|
|
274
|
-
"coercions": ctx.coercions.length
|
|
275
|
-
}, "validation.coercions");
|
|
276
|
-
}));
|
|
277
|
-
unregisters.push(hooks.hook("budget:exceeded", (ctx) => {
|
|
278
|
-
add(budgetExceeded, 1, {
|
|
279
|
-
bytes: ctx.bytes,
|
|
280
|
-
budget: ctx.budget
|
|
281
|
-
}, "budget.exceeded");
|
|
282
|
-
}));
|
|
283
|
-
unregisters.push(hooks.hook("tool-budget:exceeded", (ctx) => {
|
|
284
|
-
add(toolBudgetExceeded, 1, {
|
|
285
|
-
"gen_ai.tool.name": ctx.tool,
|
|
286
|
-
"mode": ctx.mode,
|
|
287
|
-
"count": ctx.count,
|
|
288
|
-
"max": ctx.max
|
|
289
|
-
}, "tool_budget.exceeded");
|
|
290
|
-
}));
|
|
291
|
-
unregisters.push(hooks.hook("pairing:repair", (ctx) => {
|
|
292
|
-
add(pairingRepairs, 1, { mode: ctx.mode }, "pairing.repairs");
|
|
293
|
-
}));
|
|
294
|
-
unregisters.push(hooks.hook("oauth:refresh", (ctx) => {
|
|
295
|
-
add(oauthRefreshes, 1, {
|
|
296
|
-
provider: ctx.provider,
|
|
297
|
-
source: ctx.source
|
|
298
|
-
}, "oauth.refreshes");
|
|
299
|
-
}));
|
|
300
|
-
unregisters.push(hooks.hook("mcp:tool:before", (ctx) => {
|
|
301
|
-
mcpStart.set(ctx.callId, Date.now());
|
|
302
|
-
}));
|
|
303
|
-
unregisters.push(hooks.hook("mcp:tool:after", (ctx) => {
|
|
304
|
-
const started = mcpStart.get(ctx.callId);
|
|
305
|
-
mcpStart.delete(ctx.callId);
|
|
306
|
-
const tags = {
|
|
307
|
-
"gen_ai.mcp.server": ctx.server,
|
|
308
|
-
"gen_ai.tool.name": ctx.displayName
|
|
309
|
-
};
|
|
310
|
-
if (typeof started === "number") record(mcpToolDuration, Date.now() - started, tags, "mcp.tool.duration");
|
|
311
|
-
}));
|
|
312
|
-
unregisters.push(hooks.hook("mcp:tool:error", (ctx) => {
|
|
313
|
-
mcpStart.delete(ctx.callId);
|
|
314
|
-
add(mcpToolErrors, 1, {
|
|
315
|
-
"gen_ai.mcp.server": ctx.server,
|
|
316
|
-
"gen_ai.tool.name": ctx.displayName,
|
|
317
|
-
"error.type": ctx.error.name
|
|
318
|
-
}, "mcp.tool.errors");
|
|
319
|
-
}));
|
|
320
|
-
unregisters.push(hooks.hook("mcp:bootstrap:end", (ctx) => {
|
|
321
|
-
record(mcpBootstrapDuration, ctx.durationMs, {
|
|
322
|
-
"gen_ai.mcp.server": ctx.name,
|
|
323
|
-
"ok": ctx.ok
|
|
324
|
-
}, "mcp.bootstrap.duration");
|
|
325
|
-
}));
|
|
326
|
-
unregisters.push(hooks.hook("mcp:error", (ctx) => {
|
|
327
|
-
add(mcpErrors, 1, {
|
|
328
|
-
"gen_ai.mcp.server": ctx.name,
|
|
329
|
-
"error.type": ctx.error.name
|
|
330
|
-
}, "mcp.errors");
|
|
331
|
-
}));
|
|
332
|
-
unregisters.push(hooks.hook("mcp:auth:required", (ctx) => {
|
|
333
|
-
add(mcpAuthRequired, 1, {
|
|
334
|
-
"gen_ai.mcp.server": ctx.name,
|
|
335
|
-
"transport": ctx.transport,
|
|
336
|
-
"reason": ctx.reason
|
|
337
|
-
}, "mcp.auth.required");
|
|
338
|
-
}));
|
|
339
|
-
let disposed = false;
|
|
340
|
-
return function uninstall() {
|
|
341
|
-
if (disposed) return;
|
|
342
|
-
disposed = true;
|
|
343
|
-
for (const un of unregisters) try {
|
|
344
|
-
un();
|
|
345
|
-
} catch {}
|
|
346
|
-
turnStart.clear();
|
|
347
|
-
toolStart.clear();
|
|
348
|
-
mcpStart.clear();
|
|
349
|
-
};
|
|
350
|
-
} };
|
|
351
|
-
}
|
|
352
|
-
/**
|
|
353
|
-
* Defensive factory wrapper — returns undefined when meter creation
|
|
354
|
-
* throws. Lets a half-broken meter (one unsupported instrument) still
|
|
355
|
-
* give partial metrics rather than collapsing the whole install.
|
|
356
|
-
*/
|
|
357
|
-
function safeFactory(factory, name, onError) {
|
|
358
|
-
try {
|
|
359
|
-
return factory();
|
|
360
|
-
} catch (err) {
|
|
361
|
-
try {
|
|
362
|
-
onError(`createInstrument:${name}`, err);
|
|
363
|
-
} catch {}
|
|
364
|
-
return;
|
|
365
|
-
}
|
|
366
|
-
}
|
|
367
|
-
//#endregion
|
|
368
|
-
//#region src/mutation-validation.ts
|
|
369
|
-
function defaultFailureMessage(failure) {
|
|
370
|
-
const changed = failure.batch.mutations.map((m) => `${m.displayName} ${String(m.input.path ?? m.callId)}`).join(", ");
|
|
371
|
-
const details = failure.result.message ?? failure.result.errors?.join("\n") ?? "Validation failed after the last file mutation.";
|
|
372
|
-
return `[Mutation validation failed${failure.failureCount > 1 ? ` (failure ${failure.failureCount})` : ""}] ${changed}\n${details}\nFix the validation errors with the smallest focused change.`;
|
|
373
|
-
}
|
|
374
|
-
function isSuccessfulMutation(outcome) {
|
|
375
|
-
return outcome === "created" || outcome === "updated" || outcome === "edited";
|
|
376
|
-
}
|
|
377
|
-
/**
|
|
378
|
-
* Build host-side hooks for post-mutation validation without changing the
|
|
379
|
-
* built-in edit/write tools. The helper only observes successful mutations
|
|
380
|
-
* reported through `tool:after.outcome`; validation commands and recovery
|
|
381
|
-
* prompts remain host policy.
|
|
382
|
-
*/
|
|
383
|
-
function createMutationValidationHooks(options) {
|
|
384
|
-
const pending = [];
|
|
385
|
-
let failureCount = 0;
|
|
386
|
-
const maxFailures = Math.max(1, Math.floor(options.maxFailuresPerRun ?? 2));
|
|
387
|
-
return {
|
|
388
|
-
"tool:after": (ctx) => {
|
|
389
|
-
if (!isSuccessfulMutation(ctx.outcome)) return;
|
|
390
|
-
pending.push({
|
|
391
|
-
turnId: ctx.turnId,
|
|
392
|
-
callId: ctx.callId,
|
|
393
|
-
tool: ctx.name,
|
|
394
|
-
displayName: ctx.displayName,
|
|
395
|
-
input: ctx.input,
|
|
396
|
-
outcome: ctx.outcome,
|
|
397
|
-
result: ctx.result
|
|
398
|
-
});
|
|
399
|
-
},
|
|
400
|
-
"tool-results:after": async (ctx) => {
|
|
401
|
-
if (pending.length === 0) return;
|
|
402
|
-
const mutations = pending.splice(0);
|
|
403
|
-
const batch = {
|
|
404
|
-
turnId: ctx.turnId,
|
|
405
|
-
mutations
|
|
406
|
-
};
|
|
407
|
-
let result;
|
|
408
|
-
try {
|
|
409
|
-
result = await options.validate(batch);
|
|
410
|
-
} catch (err) {
|
|
411
|
-
await options.onError?.(err, batch);
|
|
412
|
-
return;
|
|
413
|
-
}
|
|
414
|
-
if (!result || result.ok) return;
|
|
415
|
-
failureCount++;
|
|
416
|
-
if (failureCount > maxFailures) return;
|
|
417
|
-
const withoutMessage = {
|
|
418
|
-
batch,
|
|
419
|
-
result,
|
|
420
|
-
failureCount
|
|
421
|
-
};
|
|
422
|
-
const message = options.buildFailureMessage?.(withoutMessage) ?? defaultFailureMessage(withoutMessage);
|
|
423
|
-
await options.onFailure?.({
|
|
424
|
-
...withoutMessage,
|
|
425
|
-
message
|
|
426
|
-
});
|
|
427
|
-
},
|
|
428
|
-
"agent:done": () => {
|
|
429
|
-
pending.length = 0;
|
|
430
|
-
failureCount = 0;
|
|
431
|
-
}
|
|
432
|
-
};
|
|
433
|
-
}
|
|
434
|
-
//#endregion
|
|
435
|
-
//#region src/tracing.ts
|
|
436
|
-
/**
|
|
437
|
-
* Stable keys we emit unconditionally — present in BOTH Sentry and OTel
|
|
438
|
-
* conventions with identical semantics, so no `conventions` branching is
|
|
439
|
-
* needed at the call site.
|
|
440
|
-
*/
|
|
441
|
-
const GEN_AI = {
|
|
442
|
-
system: "gen_ai.system",
|
|
443
|
-
operationName: "gen_ai.operation.name",
|
|
444
|
-
requestModel: "gen_ai.request.model",
|
|
445
|
-
responseModel: "gen_ai.response.model",
|
|
446
|
-
responseFinishReasons: "gen_ai.response.finish_reasons",
|
|
447
|
-
responseId: "gen_ai.response.id",
|
|
448
|
-
responseStreaming: "gen_ai.response.streaming",
|
|
449
|
-
responseTokensPerSecond: "gen_ai.response.tokens_per_second",
|
|
450
|
-
responseTimeToFirstTokenSeconds: "gen_ai.response.time_to_first_token",
|
|
451
|
-
responseTimeToFirstTokenMs: "gen_ai.client.time_to_first_token",
|
|
452
|
-
usageInputTokens: "gen_ai.usage.input_tokens",
|
|
453
|
-
usageOutputTokens: "gen_ai.usage.output_tokens",
|
|
454
|
-
usageTotalTokens: "gen_ai.usage.total_tokens",
|
|
455
|
-
usageInputTokensCached: "gen_ai.usage.input_tokens.cached",
|
|
456
|
-
usageInputTokensCacheWrite: "gen_ai.usage.input_tokens.cache_write",
|
|
457
|
-
usageOutputTokensReasoning: "gen_ai.usage.output_tokens.reasoning",
|
|
458
|
-
usageCacheReadInputTokens: "gen_ai.usage.cache_read_input_tokens",
|
|
459
|
-
usageCacheCreationInputTokens: "gen_ai.usage.cache_creation_input_tokens",
|
|
460
|
-
usageReasoningTokens: "gen_ai.usage.reasoning_tokens",
|
|
461
|
-
costTotalTokens: "gen_ai.cost.total_tokens",
|
|
462
|
-
costInputTokens: "gen_ai.cost.input_tokens",
|
|
463
|
-
costOutputTokens: "gen_ai.cost.output_tokens",
|
|
464
|
-
usageCostUsd: "gen_ai.usage.cost_usd",
|
|
465
|
-
toolName: "gen_ai.tool.name",
|
|
466
|
-
toolDescription: "gen_ai.tool.description",
|
|
467
|
-
toolType: "gen_ai.tool.type",
|
|
468
|
-
toolCallId: "gen_ai.tool.call.id",
|
|
469
|
-
toolCallArguments: "gen_ai.tool.call.arguments",
|
|
470
|
-
toolCallResult: "gen_ai.tool.call.result",
|
|
471
|
-
toolMessage: "gen_ai.tool.message",
|
|
472
|
-
toolInputDeprecated: "gen_ai.tool.input",
|
|
473
|
-
toolOutputDeprecated: "gen_ai.tool.output",
|
|
474
|
-
requestMaxTokens: "gen_ai.request.max_tokens",
|
|
475
|
-
requestTemperature: "gen_ai.request.temperature",
|
|
476
|
-
requestTopP: "gen_ai.request.top_p",
|
|
477
|
-
requestTopK: "gen_ai.request.top_k",
|
|
478
|
-
requestSeed: "gen_ai.request.seed",
|
|
479
|
-
requestFrequencyPenalty: "gen_ai.request.frequency_penalty",
|
|
480
|
-
requestPresencePenalty: "gen_ai.request.presence_penalty",
|
|
481
|
-
inputMessages: "gen_ai.input.messages",
|
|
482
|
-
outputMessages: "gen_ai.output.messages",
|
|
483
|
-
systemInstructions: "gen_ai.system_instructions",
|
|
484
|
-
toolDefinitions: "gen_ai.tool.definitions",
|
|
485
|
-
agentName: "gen_ai.agent.name",
|
|
486
|
-
agentRunId: "gen_ai.agent.run.id",
|
|
487
|
-
agentParentRunId: "gen_ai.agent.parent_run.id",
|
|
488
|
-
agentDepth: "gen_ai.agent.depth",
|
|
489
|
-
pipelineName: "gen_ai.pipeline.name",
|
|
490
|
-
turn: "gen_ai.agent.turn",
|
|
491
|
-
mcpServer: "gen_ai.mcp.server",
|
|
492
|
-
mcpToolCount: "gen_ai.mcp.tool_count"
|
|
493
|
-
};
|
|
494
|
-
/** Compose namespace prefix once. */
|
|
495
|
-
function prefixed(namespace, name) {
|
|
496
|
-
return namespace ? `${namespace}/${name}` : name;
|
|
497
|
-
}
|
|
498
|
-
/** Drop undefined entries — tracers vary on how they render `undefined`. */
|
|
499
|
-
function compact(attrs) {
|
|
500
|
-
const out = {};
|
|
501
|
-
for (const [k, v] of Object.entries(attrs)) if (v !== void 0) out[k] = v;
|
|
502
|
-
return out;
|
|
503
|
-
}
|
|
504
|
-
function blockToParts(block) {
|
|
505
|
-
switch (block.type) {
|
|
506
|
-
case "text": return [{
|
|
507
|
-
type: "text",
|
|
508
|
-
content: typeof block.text === "string" ? block.text : ""
|
|
509
|
-
}];
|
|
510
|
-
case "image":
|
|
511
|
-
case "audio":
|
|
512
|
-
case "video":
|
|
513
|
-
case "document": return [{
|
|
514
|
-
type: "text",
|
|
515
|
-
content: "[Blob substitute]"
|
|
516
|
-
}];
|
|
517
|
-
case "tool_call": return [{
|
|
518
|
-
type: "tool_call",
|
|
519
|
-
...typeof block.name === "string" ? { name: block.name } : {},
|
|
520
|
-
...typeof block.id === "string" ? { call_id: block.id } : {},
|
|
521
|
-
arguments: safeJson(block.input)
|
|
522
|
-
}];
|
|
523
|
-
case "tool_result": {
|
|
524
|
-
const output = block.output;
|
|
525
|
-
const text = typeof output === "string" ? output : Array.isArray(output) ? output.map((b) => b.type === "image" || b.type === "audio" || b.type === "video" || b.type === "document" ? "[Blob substitute]" : b.text ?? "").join("\n") : "";
|
|
526
|
-
return [{
|
|
527
|
-
type: "tool_result",
|
|
528
|
-
...typeof block.callId === "string" ? { call_id: block.callId } : {},
|
|
529
|
-
content: text
|
|
530
|
-
}];
|
|
531
|
-
}
|
|
532
|
-
case "thinking": return [{
|
|
533
|
-
type: "reasoning",
|
|
534
|
-
content: typeof block.text === "string" ? block.text : ""
|
|
535
|
-
}];
|
|
536
|
-
default: return [];
|
|
537
|
-
}
|
|
538
|
-
}
|
|
539
|
-
function messageToSentry(msg) {
|
|
540
|
-
const parts = [];
|
|
541
|
-
for (const block of msg.content) parts.push(...blockToParts(block));
|
|
542
|
-
return {
|
|
543
|
-
role: msg.role,
|
|
544
|
-
parts
|
|
545
|
-
};
|
|
546
|
-
}
|
|
547
|
-
function safeJson(value) {
|
|
548
|
-
try {
|
|
549
|
-
return JSON.stringify(value ?? null);
|
|
550
|
-
} catch {
|
|
551
|
-
return "\"[unserializable]\"";
|
|
552
|
-
}
|
|
553
|
-
}
|
|
554
|
-
/**
|
|
555
|
-
* Stringify an array of `SessionMessage`s into Sentry's `gen_ai.input.messages`
|
|
556
|
-
* format. Each entry's role + content is mapped via `messageToSentry`.
|
|
557
|
-
* Returns `undefined` when the input is empty or unserializable.
|
|
558
|
-
*/
|
|
559
|
-
function stringifyMessages(messages) {
|
|
560
|
-
if (messages.length === 0) return void 0;
|
|
561
|
-
try {
|
|
562
|
-
const sentry = messages.map((m) => messageToSentry({
|
|
563
|
-
role: m.role,
|
|
564
|
-
content: m.content
|
|
565
|
-
}));
|
|
566
|
-
return JSON.stringify(sentry);
|
|
567
|
-
} catch {
|
|
568
|
-
return;
|
|
569
|
-
}
|
|
570
|
-
}
|
|
571
|
-
/**
|
|
572
|
-
* Stringify a `StreamOptions.tools` array into Sentry's
|
|
573
|
-
* `gen_ai.tool.definitions` format: `[{name, description?, parameters?}, …]`.
|
|
574
|
-
*
|
|
575
|
-
* The input is `unknown[]` because `StreamOptions.tools` carries the
|
|
576
|
-
* provider-formatted shape (Anthropic / OpenAI / OpenAI-compat all
|
|
577
|
-
* differ). We probe the three names that overlap (`name`, `description`,
|
|
578
|
-
* `inputSchema` / `parameters`) and degrade gracefully otherwise.
|
|
579
|
-
*/
|
|
580
|
-
function stringifyToolDefs(tools) {
|
|
581
|
-
if (!tools || tools.length === 0) return void 0;
|
|
582
|
-
try {
|
|
583
|
-
return JSON.stringify(tools.map((raw) => {
|
|
584
|
-
if (!raw || typeof raw !== "object") return { name: "anonymous" };
|
|
585
|
-
const t = raw;
|
|
586
|
-
const name = typeof t.name === "string" ? t.name : "anonymous";
|
|
587
|
-
const description = typeof t.description === "string" ? t.description : void 0;
|
|
588
|
-
const parameters = t.parameters ?? t.input_schema ?? t.inputSchema;
|
|
589
|
-
return {
|
|
590
|
-
name,
|
|
591
|
-
...description ? { description } : {},
|
|
592
|
-
...parameters !== void 0 ? { parameters } : {}
|
|
593
|
-
};
|
|
594
|
-
}));
|
|
595
|
-
} catch {
|
|
596
|
-
return;
|
|
597
|
-
}
|
|
598
|
-
}
|
|
599
|
-
/**
|
|
600
|
-
* Build the usage attribute set per the configured conventions. Sentry
|
|
601
|
-
* expects `input_tokens` to include cached, with `input_tokens.cached`
|
|
602
|
-
* + `input_tokens.cache_write` subkeys; OTel splits cache into
|
|
603
|
-
* separate top-level keys. `'both'` emits everything.
|
|
604
|
-
*/
|
|
605
|
-
function buildUsageAttrs(usage, conventions) {
|
|
606
|
-
const cacheRead = usage.cacheRead ?? 0;
|
|
607
|
-
const cacheWrite = usage.cacheCreation ?? 0;
|
|
608
|
-
const inputInclCache = usage.input + cacheRead + cacheWrite;
|
|
609
|
-
const totalTokens = inputInclCache + usage.output;
|
|
610
|
-
const wantSentry = conventions === "sentry" || conventions === "both";
|
|
611
|
-
const wantOtel = conventions === "otel" || conventions === "both";
|
|
612
|
-
const out = {
|
|
613
|
-
[GEN_AI.responseModel]: usage.modelId,
|
|
614
|
-
[GEN_AI.responseFinishReasons]: usage.finishReason ? [usage.finishReason] : void 0,
|
|
615
|
-
[GEN_AI.usageOutputTokens]: usage.output,
|
|
616
|
-
[GEN_AI.usageTotalTokens]: totalTokens
|
|
617
|
-
};
|
|
618
|
-
if (wantSentry) {
|
|
619
|
-
out[GEN_AI.usageInputTokens] = inputInclCache;
|
|
620
|
-
if (cacheRead > 0) out[GEN_AI.usageInputTokensCached] = cacheRead;
|
|
621
|
-
if (cacheWrite > 0) out[GEN_AI.usageInputTokensCacheWrite] = cacheWrite;
|
|
622
|
-
if (typeof usage.thinking === "number" && usage.thinking > 0) out[GEN_AI.usageOutputTokensReasoning] = usage.thinking;
|
|
623
|
-
if (typeof usage.cost === "number") out[GEN_AI.costTotalTokens] = usage.cost;
|
|
624
|
-
if (typeof usage.timeToFirstTokenMs === "number") out[GEN_AI.responseTimeToFirstTokenSeconds] = usage.timeToFirstTokenMs / 1e3;
|
|
625
|
-
}
|
|
626
|
-
if (wantOtel) {
|
|
627
|
-
if (!wantSentry) out[GEN_AI.usageInputTokens] = usage.input;
|
|
628
|
-
if (cacheRead > 0) out[GEN_AI.usageCacheReadInputTokens] = cacheRead;
|
|
629
|
-
if (cacheWrite > 0) out[GEN_AI.usageCacheCreationInputTokens] = cacheWrite;
|
|
630
|
-
if (typeof usage.thinking === "number" && usage.thinking > 0) out[GEN_AI.usageReasoningTokens] = usage.thinking;
|
|
631
|
-
if (typeof usage.cost === "number") out[GEN_AI.usageCostUsd] = usage.cost;
|
|
632
|
-
if (typeof usage.timeToFirstTokenMs === "number") out[GEN_AI.responseTimeToFirstTokenMs] = usage.timeToFirstTokenMs;
|
|
633
|
-
}
|
|
634
|
-
return out;
|
|
635
|
-
}
|
|
636
|
-
/**
|
|
637
|
-
* Build a set of tracing hook handlers that can be installed on an agent.
|
|
638
|
-
*
|
|
639
|
-
* @example Sentry
|
|
640
|
-
* ```ts
|
|
641
|
-
* const tracing = createTracingHooks({
|
|
642
|
-
* startSpan: (name, attrs) => Sentry.startInactiveSpan({ name, attributes: attrs }),
|
|
643
|
-
* })
|
|
644
|
-
* const uninstall = tracing.install(agent.hooks)
|
|
645
|
-
* try { await agent.run({ prompt }) }
|
|
646
|
-
* finally { uninstall() }
|
|
647
|
-
* ```
|
|
648
|
-
*
|
|
649
|
-
* @example OpenTelemetry with parent-context propagation
|
|
650
|
-
* ```ts
|
|
651
|
-
* import { trace, context, propagation } from '@opentelemetry/api'
|
|
652
|
-
*
|
|
653
|
-
* const tracer = trace.getTracer('zidane')
|
|
654
|
-
* const tracing = createTracingHooks({
|
|
655
|
-
* startSpan: (name, attrs, parentCtx) => {
|
|
656
|
-
* const ctx = parentCtx ? propagation.extract(context.active(), parentCtx) : context.active()
|
|
657
|
-
* return tracer.startSpan(name, { attributes: attrs }, ctx)
|
|
658
|
-
* },
|
|
659
|
-
* getActiveTraceContext: () => {
|
|
660
|
-
* const carrier: Record<string, string> = {}
|
|
661
|
-
* propagation.inject(context.active(), carrier)
|
|
662
|
-
* return carrier
|
|
663
|
-
* },
|
|
664
|
-
* })
|
|
665
|
-
* ```
|
|
666
|
-
*/
|
|
667
|
-
function createTracingHooks(options) {
|
|
668
|
-
const namespace = options.namespace;
|
|
669
|
-
const legacy = options.legacyAttributes ?? true;
|
|
670
|
-
const conventions = options.conventions ?? "sentry";
|
|
671
|
-
const wantSentry = conventions === "sentry" || conventions === "both";
|
|
672
|
-
const captureContent = options.captureMessageContent !== false;
|
|
673
|
-
const onError = options.onError ?? (() => {});
|
|
674
|
-
return { install(hooks) {
|
|
675
|
-
const runSpans = /* @__PURE__ */ new Map();
|
|
676
|
-
const turnSpans = /* @__PURE__ */ new Map();
|
|
677
|
-
const toolSpans = /* @__PURE__ */ new Map();
|
|
678
|
-
const mcpSpans = /* @__PURE__ */ new Map();
|
|
679
|
-
const spawnSpans = /* @__PURE__ */ new Map();
|
|
680
|
-
const bootstrapSpans = /* @__PURE__ */ new Map();
|
|
681
|
-
let activeSystem;
|
|
682
|
-
const turnTrack = /* @__PURE__ */ new Map();
|
|
683
|
-
let activeRunSpan;
|
|
684
|
-
function safeStartSpan(name, attrs, parentContext) {
|
|
685
|
-
try {
|
|
686
|
-
return options.startSpan(prefixed(namespace, name), compact(attrs), parentContext);
|
|
687
|
-
} catch (err) {
|
|
688
|
-
try {
|
|
689
|
-
onError("startSpan", err);
|
|
690
|
-
} catch {}
|
|
691
|
-
return;
|
|
692
|
-
}
|
|
693
|
-
}
|
|
694
|
-
function safeSetAttrs(span, attrs) {
|
|
695
|
-
if (!span?.setAttributes) return;
|
|
696
|
-
try {
|
|
697
|
-
span.setAttributes(compact(attrs));
|
|
698
|
-
} catch (err) {
|
|
699
|
-
try {
|
|
700
|
-
onError("setAttributes", err);
|
|
701
|
-
} catch {}
|
|
702
|
-
}
|
|
703
|
-
}
|
|
704
|
-
function safeEnd(map, key) {
|
|
705
|
-
const span = map.get(key);
|
|
706
|
-
if (!span) return;
|
|
707
|
-
try {
|
|
708
|
-
span.end();
|
|
709
|
-
} catch (err) {
|
|
710
|
-
try {
|
|
711
|
-
onError("end", err);
|
|
712
|
-
} catch {}
|
|
713
|
-
}
|
|
714
|
-
map.delete(key);
|
|
715
|
-
}
|
|
716
|
-
function endAll(map) {
|
|
717
|
-
for (const [, span] of map) try {
|
|
718
|
-
span.end();
|
|
719
|
-
} catch (err) {
|
|
720
|
-
try {
|
|
721
|
-
onError("end", err);
|
|
722
|
-
} catch {}
|
|
723
|
-
}
|
|
724
|
-
map.clear();
|
|
725
|
-
}
|
|
726
|
-
function safeAddEvent(span, name, attrs) {
|
|
727
|
-
if (!span) return;
|
|
728
|
-
if (typeof span.addEvent === "function") {
|
|
729
|
-
try {
|
|
730
|
-
span.addEvent(name, compact(attrs));
|
|
731
|
-
} catch (err) {
|
|
732
|
-
try {
|
|
733
|
-
onError("addEvent", err);
|
|
734
|
-
} catch {}
|
|
735
|
-
}
|
|
736
|
-
return;
|
|
737
|
-
}
|
|
738
|
-
safeSetAttrs(span, Object.fromEntries(Object.entries(compact(attrs)).map(([k, v]) => [`event.${name}.${k}`, v])));
|
|
739
|
-
}
|
|
740
|
-
function redact(kind, value, meta) {
|
|
741
|
-
if (typeof options.redact !== "function") return value;
|
|
742
|
-
try {
|
|
743
|
-
return options.redact(kind, value, meta);
|
|
744
|
-
} catch (err) {
|
|
745
|
-
try {
|
|
746
|
-
onError("redact", err);
|
|
747
|
-
} catch {}
|
|
748
|
-
return value;
|
|
749
|
-
}
|
|
750
|
-
}
|
|
751
|
-
const unregisters = [];
|
|
752
|
-
unregisters.push(hooks.hook("agent:start", (ctx) => {
|
|
753
|
-
activeSystem = ctx.providerName;
|
|
754
|
-
const span = safeStartSpan(`invoke_agent ${ctx.agentName && ctx.agentName.length > 0 ? ctx.agentName : "agent"}`, {
|
|
755
|
-
[GEN_AI.operationName]: "invoke_agent",
|
|
756
|
-
[GEN_AI.system]: activeSystem,
|
|
757
|
-
[GEN_AI.agentName]: ctx.agentName,
|
|
758
|
-
[GEN_AI.agentRunId]: ctx.runId,
|
|
759
|
-
[GEN_AI.agentParentRunId]: ctx.parentRunId,
|
|
760
|
-
[GEN_AI.agentDepth]: ctx.depth,
|
|
761
|
-
"sentry.op": "gen_ai.invoke_agent",
|
|
762
|
-
...legacy ? {
|
|
763
|
-
runId: ctx.runId,
|
|
764
|
-
parentRunId: ctx.parentRunId,
|
|
765
|
-
agentName: ctx.agentName,
|
|
766
|
-
depth: ctx.depth
|
|
767
|
-
} : {}
|
|
768
|
-
}, ctx.tracingContext);
|
|
769
|
-
if (span) {
|
|
770
|
-
runSpans.set(ctx.runId, span);
|
|
771
|
-
activeRunSpan = span;
|
|
772
|
-
}
|
|
773
|
-
}));
|
|
774
|
-
unregisters.push(hooks.hook("agent:done", (stats) => {
|
|
775
|
-
const usageAttrs = buildUsageAttrs({
|
|
776
|
-
input: stats.totalIn,
|
|
777
|
-
output: stats.totalOut,
|
|
778
|
-
cacheRead: stats.totalCacheRead,
|
|
779
|
-
cacheCreation: stats.totalCacheCreation,
|
|
780
|
-
cost: stats.cost,
|
|
781
|
-
timeToFirstTokenMs: stats.timeTillFirstTokenMs
|
|
782
|
-
}, conventions);
|
|
783
|
-
for (const [, span] of runSpans) safeSetAttrs(span, {
|
|
784
|
-
...usageAttrs,
|
|
785
|
-
[GEN_AI.turn]: stats.turns,
|
|
786
|
-
"gen_ai.agent.elapsed_ms": stats.elapsed,
|
|
787
|
-
...legacy ? {
|
|
788
|
-
totalIn: stats.totalIn,
|
|
789
|
-
totalOut: stats.totalOut,
|
|
790
|
-
totalCacheRead: stats.totalCacheRead,
|
|
791
|
-
totalCacheCreation: stats.totalCacheCreation,
|
|
792
|
-
cost: stats.cost,
|
|
793
|
-
turns: stats.turns,
|
|
794
|
-
elapsed: stats.elapsed
|
|
795
|
-
} : {}
|
|
796
|
-
});
|
|
797
|
-
endAll(runSpans);
|
|
798
|
-
endAll(turnSpans);
|
|
799
|
-
endAll(toolSpans);
|
|
800
|
-
endAll(mcpSpans);
|
|
801
|
-
endAll(spawnSpans);
|
|
802
|
-
endAll(bootstrapSpans);
|
|
803
|
-
activeRunSpan = void 0;
|
|
804
|
-
activeSystem = void 0;
|
|
805
|
-
turnTrack.clear();
|
|
806
|
-
}));
|
|
807
|
-
unregisters.push(hooks.hook("agent:abort", () => {
|
|
808
|
-
for (const [, span] of runSpans) safeSetAttrs(span, { "gen_ai.agent.status": "aborted" });
|
|
809
|
-
}));
|
|
810
|
-
unregisters.push(hooks.hook("turn:before", (ctx) => {
|
|
811
|
-
const requestedModel = ctx.options.model;
|
|
812
|
-
const baseAttrs = {
|
|
813
|
-
[GEN_AI.operationName]: "chat",
|
|
814
|
-
[GEN_AI.system]: activeSystem,
|
|
815
|
-
[GEN_AI.requestModel]: requestedModel,
|
|
816
|
-
[GEN_AI.turn]: ctx.turn,
|
|
817
|
-
[GEN_AI.responseStreaming]: true,
|
|
818
|
-
[GEN_AI.requestMaxTokens]: ctx.options.maxTokens,
|
|
819
|
-
"sentry.op": "gen_ai.chat",
|
|
820
|
-
"gen_ai.agent.turn_id": ctx.turnId,
|
|
821
|
-
...legacy ? {
|
|
822
|
-
turnId: ctx.turnId,
|
|
823
|
-
turn: ctx.turn
|
|
824
|
-
} : {}
|
|
825
|
-
};
|
|
826
|
-
if (captureContent) {
|
|
827
|
-
const systemText = ctx.options.system;
|
|
828
|
-
if (systemText) baseAttrs[GEN_AI.systemInstructions] = redact("system", systemText, {
|
|
829
|
-
turnId: ctx.turnId,
|
|
830
|
-
turn: ctx.turn
|
|
831
|
-
});
|
|
832
|
-
const inputMsgs = stringifyMessages(ctx.options.messages);
|
|
833
|
-
if (inputMsgs) baseAttrs[GEN_AI.inputMessages] = redact("prompt", inputMsgs, {
|
|
834
|
-
turnId: ctx.turnId,
|
|
835
|
-
turn: ctx.turn
|
|
836
|
-
});
|
|
837
|
-
const toolDefs = stringifyToolDefs(ctx.options.tools);
|
|
838
|
-
if (toolDefs) baseAttrs[GEN_AI.toolDefinitions] = toolDefs;
|
|
839
|
-
}
|
|
840
|
-
const span = safeStartSpan(`chat${requestedModel ? ` ${requestedModel}` : ""}`, baseAttrs);
|
|
841
|
-
if (span) {
|
|
842
|
-
turnSpans.set(ctx.turnId, span);
|
|
843
|
-
turnTrack.set(ctx.turnId, { startedAt: Date.now() });
|
|
844
|
-
}
|
|
845
|
-
}));
|
|
846
|
-
unregisters.push(hooks.hook("stream:start", (ctx) => {
|
|
847
|
-
safeAddEvent(turnSpans.get(ctx.turnId), "gen_ai.stream.start", { startedAt: ctx.startedAt });
|
|
848
|
-
}));
|
|
849
|
-
unregisters.push(hooks.hook("turn:after", (ctx) => {
|
|
850
|
-
const span = turnSpans.get(ctx.turnId);
|
|
851
|
-
const tracked = turnTrack.get(ctx.turnId);
|
|
852
|
-
turnTrack.delete(ctx.turnId);
|
|
853
|
-
let tokensPerSecond;
|
|
854
|
-
if (tracked && ctx.usage.output > 0) {
|
|
855
|
-
const elapsedMs = Date.now() - tracked.startedAt;
|
|
856
|
-
if (elapsedMs > 0) tokensPerSecond = ctx.usage.output / elapsedMs * 1e3;
|
|
857
|
-
}
|
|
858
|
-
const usageAttrs = buildUsageAttrs(ctx.usage, conventions);
|
|
859
|
-
const cumInputTokens = wantSentry ? ctx.cumulativeUsage.input + ctx.cumulativeUsage.cacheRead + ctx.cumulativeUsage.cacheCreation : ctx.cumulativeUsage.input;
|
|
860
|
-
const attrs = {
|
|
861
|
-
...usageAttrs,
|
|
862
|
-
[GEN_AI.responseTokensPerSecond]: tokensPerSecond,
|
|
863
|
-
"gen_ai.agent.cumulative.input_tokens": cumInputTokens,
|
|
864
|
-
"gen_ai.agent.cumulative.output_tokens": ctx.cumulativeUsage.output,
|
|
865
|
-
"gen_ai.agent.cumulative.total_tokens": cumInputTokens + ctx.cumulativeUsage.output,
|
|
866
|
-
"gen_ai.agent.cumulative.cache_read_input_tokens": ctx.cumulativeUsage.cacheRead,
|
|
867
|
-
"gen_ai.agent.cumulative.cache_creation_input_tokens": ctx.cumulativeUsage.cacheCreation,
|
|
868
|
-
"gen_ai.agent.cumulative.cost_usd": ctx.cumulativeUsage.cost,
|
|
869
|
-
"gen_ai.agent.cumulative.turns": ctx.cumulativeUsage.turns,
|
|
870
|
-
...legacy ? {
|
|
871
|
-
inputTokens: ctx.usage.input,
|
|
872
|
-
outputTokens: ctx.usage.output,
|
|
873
|
-
finishReason: ctx.usage.finishReason,
|
|
874
|
-
modelId: ctx.usage.modelId
|
|
875
|
-
} : {}
|
|
876
|
-
};
|
|
877
|
-
if (captureContent && ctx.message && ctx.message.role !== "system" && ctx.message.role !== "command") {
|
|
878
|
-
const outputMsgs = stringifyMessages([{
|
|
879
|
-
role: ctx.message.role,
|
|
880
|
-
content: ctx.message.content
|
|
881
|
-
}]);
|
|
882
|
-
if (outputMsgs) attrs[GEN_AI.outputMessages] = redact("stream-text", outputMsgs, {
|
|
883
|
-
turnId: ctx.turnId,
|
|
884
|
-
turn: ctx.turn
|
|
885
|
-
});
|
|
886
|
-
}
|
|
887
|
-
safeSetAttrs(span, attrs);
|
|
888
|
-
safeEnd(turnSpans, ctx.turnId);
|
|
889
|
-
}));
|
|
890
|
-
unregisters.push(hooks.hook("stream:error", (ctx) => {
|
|
891
|
-
const span = turnSpans.get(ctx.turnId);
|
|
892
|
-
const message = ctx.err instanceof Error ? ctx.err.message : String(ctx.err);
|
|
893
|
-
safeSetAttrs(span, {
|
|
894
|
-
"error.type": ctx.err instanceof Error ? ctx.err.name : "unknown",
|
|
895
|
-
"error.message": message,
|
|
896
|
-
"http.response.status_code": ctx.statusCode,
|
|
897
|
-
"gen_ai.request.id": ctx.requestId
|
|
898
|
-
});
|
|
899
|
-
safeAddEvent(span, "gen_ai.stream.error", {
|
|
900
|
-
"error.type": ctx.err instanceof Error ? ctx.err.name : "unknown",
|
|
901
|
-
"error.message": message,
|
|
902
|
-
"http.response.status_code": ctx.statusCode,
|
|
903
|
-
"gen_ai.request.id": ctx.requestId
|
|
904
|
-
});
|
|
905
|
-
}));
|
|
906
|
-
unregisters.push(hooks.hook("tool:before", (ctx) => {
|
|
907
|
-
const span = safeStartSpan(`execute_tool ${ctx.displayName}`, {
|
|
908
|
-
[GEN_AI.operationName]: "execute_tool",
|
|
909
|
-
[GEN_AI.system]: activeSystem,
|
|
910
|
-
[GEN_AI.toolName]: ctx.name,
|
|
911
|
-
[GEN_AI.toolType]: "function",
|
|
912
|
-
[GEN_AI.toolCallId]: ctx.callId,
|
|
913
|
-
"sentry.op": "gen_ai.execute_tool",
|
|
914
|
-
"gen_ai.tool.display_name": ctx.displayName,
|
|
915
|
-
"gen_ai.agent.turn_id": ctx.turnId,
|
|
916
|
-
"gen_ai.agent.depth": ctx.depth,
|
|
917
|
-
"gen_ai.agent.run.id": ctx.runId,
|
|
918
|
-
"gen_ai.agent.parent_run.id": ctx.parentRunId,
|
|
919
|
-
...legacy ? {
|
|
920
|
-
toolName: ctx.name,
|
|
921
|
-
displayName: ctx.displayName,
|
|
922
|
-
turnId: ctx.turnId,
|
|
923
|
-
callId: ctx.callId
|
|
924
|
-
} : {}
|
|
925
|
-
});
|
|
926
|
-
if (span) {
|
|
927
|
-
toolSpans.set(ctx.callId, span);
|
|
928
|
-
if (captureContent) try {
|
|
929
|
-
const redacted = redact("tool-input", JSON.stringify(ctx.input), {
|
|
930
|
-
toolName: ctx.name,
|
|
931
|
-
displayName: ctx.displayName,
|
|
932
|
-
callId: ctx.callId,
|
|
933
|
-
turnId: ctx.turnId
|
|
934
|
-
});
|
|
935
|
-
const attrs = {};
|
|
936
|
-
if (wantSentry) attrs[GEN_AI.toolCallArguments] = redacted;
|
|
937
|
-
if (conventions === "otel" || conventions === "both") attrs[GEN_AI.toolInputDeprecated] = redacted;
|
|
938
|
-
safeSetAttrs(span, attrs);
|
|
939
|
-
} catch {}
|
|
940
|
-
}
|
|
941
|
-
}));
|
|
942
|
-
unregisters.push(hooks.hook("tool:after", (ctx) => {
|
|
943
|
-
const span = toolSpans.get(ctx.callId);
|
|
944
|
-
safeSetAttrs(span, {
|
|
945
|
-
"gen_ai.tool.output_bytes": ctx.outputBytes,
|
|
946
|
-
"gen_ai.tool.coercions": ctx.coercions?.length ?? 0
|
|
947
|
-
});
|
|
948
|
-
if (captureContent && typeof ctx.result === "string") {
|
|
949
|
-
const redacted = redact("tool-result", ctx.result, {
|
|
950
|
-
toolName: ctx.name,
|
|
951
|
-
callId: ctx.callId
|
|
952
|
-
});
|
|
953
|
-
const attrs = {};
|
|
954
|
-
if (wantSentry) attrs[GEN_AI.toolCallResult] = redacted;
|
|
955
|
-
if (conventions === "otel" || conventions === "both") attrs[GEN_AI.toolOutputDeprecated] = redacted;
|
|
956
|
-
safeSetAttrs(span, attrs);
|
|
957
|
-
}
|
|
958
|
-
safeEnd(toolSpans, ctx.callId);
|
|
959
|
-
}));
|
|
960
|
-
unregisters.push(hooks.hook("tool:error", (ctx) => {
|
|
961
|
-
safeSetAttrs(toolSpans.get(ctx.callId), {
|
|
962
|
-
"error.type": ctx.error.name,
|
|
963
|
-
"error.message": ctx.error.message
|
|
964
|
-
});
|
|
965
|
-
safeEnd(toolSpans, ctx.callId);
|
|
966
|
-
}));
|
|
967
|
-
unregisters.push(hooks.hook("tool:dispatched", (ctx) => {
|
|
968
|
-
if (ctx.outcome === "gate-block") safeAddEvent(activeRunSpan, "gen_ai.gate.block", {
|
|
969
|
-
[GEN_AI.toolName]: ctx.name,
|
|
970
|
-
[GEN_AI.toolCallId]: ctx.callId,
|
|
971
|
-
reason: ctx.reason
|
|
972
|
-
});
|
|
973
|
-
else if (ctx.outcome === "gate-substitute") safeAddEvent(activeRunSpan, "gen_ai.gate.substitute", {
|
|
974
|
-
[GEN_AI.toolName]: ctx.name,
|
|
975
|
-
[GEN_AI.toolCallId]: ctx.callId
|
|
976
|
-
});
|
|
977
|
-
else if (ctx.outcome === "unknown") safeAddEvent(activeRunSpan, "gen_ai.tool.unknown", {
|
|
978
|
-
[GEN_AI.toolName]: ctx.name,
|
|
979
|
-
[GEN_AI.toolCallId]: ctx.callId
|
|
980
|
-
});
|
|
981
|
-
else if (ctx.outcome === "invalid-input") safeAddEvent(activeRunSpan, "gen_ai.tool.invalid_input", {
|
|
982
|
-
[GEN_AI.toolName]: ctx.name,
|
|
983
|
-
[GEN_AI.toolCallId]: ctx.callId
|
|
984
|
-
});
|
|
985
|
-
}));
|
|
986
|
-
unregisters.push(hooks.hook("validation:reject", (ctx) => {
|
|
987
|
-
safeAddEvent(activeRunSpan, "gen_ai.validation.reject", {
|
|
988
|
-
[GEN_AI.toolName]: ctx.name,
|
|
989
|
-
[GEN_AI.toolCallId]: ctx.callId,
|
|
990
|
-
reason: ctx.reason
|
|
991
|
-
});
|
|
992
|
-
}));
|
|
993
|
-
unregisters.push(hooks.hook("validation:coerce", (ctx) => {
|
|
994
|
-
safeAddEvent(activeRunSpan, "gen_ai.validation.coerce", {
|
|
995
|
-
[GEN_AI.toolName]: ctx.name,
|
|
996
|
-
[GEN_AI.toolCallId]: ctx.callId,
|
|
997
|
-
coercions: ctx.coercions
|
|
998
|
-
});
|
|
999
|
-
}));
|
|
1000
|
-
unregisters.push(hooks.hook("budget:exceeded", (ctx) => {
|
|
1001
|
-
safeAddEvent(activeRunSpan, "gen_ai.budget.exceeded", {
|
|
1002
|
-
turnId: ctx.turnId,
|
|
1003
|
-
bytes: ctx.bytes,
|
|
1004
|
-
budget: ctx.budget
|
|
1005
|
-
});
|
|
1006
|
-
}));
|
|
1007
|
-
unregisters.push(hooks.hook("tool-budget:exceeded", (ctx) => {
|
|
1008
|
-
safeAddEvent(activeRunSpan, "gen_ai.tool_budget.exceeded", {
|
|
1009
|
-
[GEN_AI.toolName]: ctx.tool,
|
|
1010
|
-
turnId: ctx.turnId,
|
|
1011
|
-
count: ctx.count,
|
|
1012
|
-
max: ctx.max,
|
|
1013
|
-
mode: ctx.mode
|
|
1014
|
-
});
|
|
1015
|
-
}));
|
|
1016
|
-
unregisters.push(hooks.hook("pairing:repair", (ctx) => {
|
|
1017
|
-
safeAddEvent(activeRunSpan, "gen_ai.pairing.repair", {
|
|
1018
|
-
mode: ctx.mode,
|
|
1019
|
-
callId: ctx.callId,
|
|
1020
|
-
turnId: ctx.turnId
|
|
1021
|
-
});
|
|
1022
|
-
}));
|
|
1023
|
-
unregisters.push(hooks.hook("oauth:refresh", (ctx) => {
|
|
1024
|
-
safeAddEvent(activeRunSpan, "gen_ai.oauth.refresh", {
|
|
1025
|
-
provider: ctx.provider,
|
|
1026
|
-
providerId: ctx.providerId,
|
|
1027
|
-
source: ctx.source
|
|
1028
|
-
});
|
|
1029
|
-
}));
|
|
1030
|
-
unregisters.push(hooks.hook("mcp:tool:before", (ctx) => {
|
|
1031
|
-
const span = safeStartSpan(`execute_tool ${ctx.server}.${ctx.tool}`, {
|
|
1032
|
-
[GEN_AI.operationName]: "execute_tool",
|
|
1033
|
-
[GEN_AI.system]: activeSystem,
|
|
1034
|
-
[GEN_AI.toolName]: ctx.displayName,
|
|
1035
|
-
[GEN_AI.toolType]: "extension",
|
|
1036
|
-
[GEN_AI.toolCallId]: ctx.callId,
|
|
1037
|
-
[GEN_AI.mcpServer]: ctx.server,
|
|
1038
|
-
"sentry.op": "gen_ai.execute_tool",
|
|
1039
|
-
"gen_ai.mcp.tool": ctx.tool,
|
|
1040
|
-
"gen_ai.agent.turn_id": ctx.turnId,
|
|
1041
|
-
"gen_ai.agent.run.id": ctx.runId,
|
|
1042
|
-
...legacy ? {
|
|
1043
|
-
server: ctx.server,
|
|
1044
|
-
tool: ctx.tool,
|
|
1045
|
-
displayName: ctx.displayName,
|
|
1046
|
-
turnId: ctx.turnId,
|
|
1047
|
-
callId: ctx.callId
|
|
1048
|
-
} : {}
|
|
1049
|
-
});
|
|
1050
|
-
if (span) {
|
|
1051
|
-
mcpSpans.set(ctx.callId, span);
|
|
1052
|
-
if (captureContent) try {
|
|
1053
|
-
const redacted = redact("mcp-tool-input", JSON.stringify(ctx.input), {
|
|
1054
|
-
server: ctx.server,
|
|
1055
|
-
tool: ctx.tool,
|
|
1056
|
-
callId: ctx.callId
|
|
1057
|
-
});
|
|
1058
|
-
const attrs = {};
|
|
1059
|
-
if (wantSentry) attrs[GEN_AI.toolCallArguments] = redacted;
|
|
1060
|
-
if (conventions === "otel" || conventions === "both") attrs[GEN_AI.toolInputDeprecated] = redacted;
|
|
1061
|
-
safeSetAttrs(span, attrs);
|
|
1062
|
-
} catch {}
|
|
1063
|
-
}
|
|
1064
|
-
}));
|
|
1065
|
-
unregisters.push(hooks.hook("mcp:tool:after", (ctx) => {
|
|
1066
|
-
const span = mcpSpans.get(ctx.callId);
|
|
1067
|
-
safeSetAttrs(span, { "gen_ai.tool.output_bytes": ctx.outputBytes });
|
|
1068
|
-
if (captureContent && typeof ctx.result === "string") {
|
|
1069
|
-
const redacted = redact("mcp-tool-result", ctx.result, {
|
|
1070
|
-
server: ctx.server,
|
|
1071
|
-
tool: ctx.tool,
|
|
1072
|
-
callId: ctx.callId
|
|
1073
|
-
});
|
|
1074
|
-
const attrs = {};
|
|
1075
|
-
if (wantSentry) attrs[GEN_AI.toolCallResult] = redacted;
|
|
1076
|
-
if (conventions === "otel" || conventions === "both") attrs[GEN_AI.toolOutputDeprecated] = redacted;
|
|
1077
|
-
safeSetAttrs(span, attrs);
|
|
1078
|
-
}
|
|
1079
|
-
safeEnd(mcpSpans, ctx.callId);
|
|
1080
|
-
}));
|
|
1081
|
-
unregisters.push(hooks.hook("mcp:tool:error", (ctx) => {
|
|
1082
|
-
safeSetAttrs(mcpSpans.get(ctx.callId), {
|
|
1083
|
-
"error.type": ctx.error.name,
|
|
1084
|
-
"error.message": ctx.error.message
|
|
1085
|
-
});
|
|
1086
|
-
safeEnd(mcpSpans, ctx.callId);
|
|
1087
|
-
}));
|
|
1088
|
-
unregisters.push(hooks.hook("mcp:bootstrap:start", (ctx) => {
|
|
1089
|
-
const span = safeStartSpan(`mcp.bootstrap ${ctx.name}`, {
|
|
1090
|
-
[GEN_AI.operationName]: "mcp.bootstrap",
|
|
1091
|
-
[GEN_AI.system]: activeSystem,
|
|
1092
|
-
[GEN_AI.mcpServer]: ctx.name,
|
|
1093
|
-
"gen_ai.mcp.transport": ctx.transport
|
|
1094
|
-
});
|
|
1095
|
-
if (span) bootstrapSpans.set(ctx.name, span);
|
|
1096
|
-
}));
|
|
1097
|
-
unregisters.push(hooks.hook("mcp:bootstrap:end", (ctx) => {
|
|
1098
|
-
const span = bootstrapSpans.get(ctx.name);
|
|
1099
|
-
const ok = ctx.ok;
|
|
1100
|
-
safeSetAttrs(span, {
|
|
1101
|
-
"gen_ai.mcp.bootstrap.duration_ms": ctx.durationMs,
|
|
1102
|
-
"gen_ai.mcp.bootstrap.ok": ok,
|
|
1103
|
-
...ok ? {
|
|
1104
|
-
[GEN_AI.mcpToolCount]: ctx.toolCount,
|
|
1105
|
-
"gen_ai.mcp.lazy": ctx.lazy,
|
|
1106
|
-
"gen_ai.mcp.cached": ctx.cached
|
|
1107
|
-
} : {
|
|
1108
|
-
"error.type": ctx.error.name,
|
|
1109
|
-
"error.message": ctx.error.message
|
|
1110
|
-
}
|
|
1111
|
-
});
|
|
1112
|
-
safeEnd(bootstrapSpans, ctx.name);
|
|
1113
|
-
}));
|
|
1114
|
-
unregisters.push(hooks.hook("mcp:auth:required", (ctx) => {
|
|
1115
|
-
safeAddEvent(bootstrapSpans.get(ctx.name) ?? activeRunSpan, "gen_ai.mcp.auth.required", {
|
|
1116
|
-
server: ctx.name,
|
|
1117
|
-
transport: ctx.transport,
|
|
1118
|
-
reason: ctx.reason
|
|
1119
|
-
});
|
|
1120
|
-
}));
|
|
1121
|
-
unregisters.push(hooks.hook("mcp:error", (ctx) => {
|
|
1122
|
-
safeAddEvent(activeRunSpan, "gen_ai.mcp.error", {
|
|
1123
|
-
"server": ctx.name,
|
|
1124
|
-
"error.type": ctx.error.name,
|
|
1125
|
-
"error.message": ctx.error.message
|
|
1126
|
-
});
|
|
1127
|
-
}));
|
|
1128
|
-
unregisters.push(hooks.hook("spawn:before", (ctx) => {
|
|
1129
|
-
const span = safeStartSpan(`handoff to ${ctx.task.length > 60 ? `${ctx.task.slice(0, 57)}…` : ctx.task}`, {
|
|
1130
|
-
[GEN_AI.operationName]: "handoff",
|
|
1131
|
-
[GEN_AI.system]: activeSystem,
|
|
1132
|
-
"sentry.op": "gen_ai.handoff",
|
|
1133
|
-
"gen_ai.agent.spawn.id": ctx.id,
|
|
1134
|
-
"gen_ai.agent.spawn.task": ctx.task,
|
|
1135
|
-
"gen_ai.agent.depth": ctx.depth
|
|
1136
|
-
});
|
|
1137
|
-
if (span) spawnSpans.set(ctx.id, span);
|
|
1138
|
-
if (typeof options.getActiveTraceContext === "function" && ctx.tracingContext) {
|
|
1139
|
-
let carrier;
|
|
1140
|
-
try {
|
|
1141
|
-
carrier = options.getActiveTraceContext();
|
|
1142
|
-
} catch (err) {
|
|
1143
|
-
try {
|
|
1144
|
-
onError("getActiveTraceContext", err);
|
|
1145
|
-
} catch {}
|
|
1146
|
-
}
|
|
1147
|
-
if (carrier) for (const [k, v] of Object.entries(carrier)) ctx.tracingContext[k] = v;
|
|
1148
|
-
}
|
|
1149
|
-
}));
|
|
1150
|
-
unregisters.push(hooks.hook("spawn:complete", (ctx) => {
|
|
1151
|
-
const span = spawnSpans.get(ctx.id);
|
|
1152
|
-
const childUsage = buildUsageAttrs({
|
|
1153
|
-
input: ctx.stats.totalIn,
|
|
1154
|
-
output: ctx.stats.totalOut,
|
|
1155
|
-
cacheRead: ctx.stats.totalCacheRead,
|
|
1156
|
-
cacheCreation: ctx.stats.totalCacheCreation,
|
|
1157
|
-
cost: ctx.stats.cost
|
|
1158
|
-
}, conventions);
|
|
1159
|
-
safeSetAttrs(span, {
|
|
1160
|
-
"gen_ai.agent.spawn.status": ctx.status ?? "completed",
|
|
1161
|
-
"gen_ai.agent.spawn.depth": ctx.depth,
|
|
1162
|
-
...childUsage
|
|
1163
|
-
});
|
|
1164
|
-
safeEnd(spawnSpans, ctx.id);
|
|
1165
|
-
}));
|
|
1166
|
-
unregisters.push(hooks.hook("spawn:error", (ctx) => {
|
|
1167
|
-
safeSetAttrs(spawnSpans.get(ctx.id), {
|
|
1168
|
-
"error.type": ctx.error.name,
|
|
1169
|
-
"error.message": ctx.error.message
|
|
1170
|
-
});
|
|
1171
|
-
safeEnd(spawnSpans, ctx.id);
|
|
1172
|
-
}));
|
|
1173
|
-
let disposed = false;
|
|
1174
|
-
return function uninstall() {
|
|
1175
|
-
if (disposed) return;
|
|
1176
|
-
disposed = true;
|
|
1177
|
-
for (const un of unregisters) try {
|
|
1178
|
-
un();
|
|
1179
|
-
} catch {}
|
|
1180
|
-
endAll(runSpans);
|
|
1181
|
-
endAll(turnSpans);
|
|
1182
|
-
endAll(toolSpans);
|
|
1183
|
-
endAll(mcpSpans);
|
|
1184
|
-
endAll(spawnSpans);
|
|
1185
|
-
endAll(bootstrapSpans);
|
|
1186
|
-
activeRunSpan = void 0;
|
|
1187
|
-
};
|
|
1188
|
-
} };
|
|
1189
|
-
}
|
|
1190
|
-
/**
|
|
1191
|
-
* OpenTelemetry Gen AI semantic-convention attribute keys used by the
|
|
1192
|
-
* built-in tracer. Exported so consumers integrating with raw OTel SDKs
|
|
1193
|
-
* (instead of going through `createTracingHooks`) can stay aligned with
|
|
1194
|
-
* the names the harness itself emits.
|
|
1195
|
-
*/
|
|
1196
|
-
const GEN_AI_ATTRIBUTES = GEN_AI;
|
|
1197
|
-
//#endregion
|
|
1198
|
-
export { ANCHOR_PREVIEW_MAX_CHARS, AUTO_COMPACT_MIN_GROWTH_FRACTION, AgentAbortedError, AgentBudgetExceededError, AgentContextExceededError, AgentLengthResumeExhaustedError, AgentProviderError, AgentToolNotAllowedError, AgentToolPairingError, BASE_INSTRUCTIONS, BYTES_PER_TOKEN, CONTEXT_EXCEEDED_MESSAGE_PATTERNS, CompactInvalidInputError, CompactPromptTooLongError, DEFAULT_MAX_VALUE_BYTES, EFFICIENCY_METRICS, EMPTY_EXTENSION_REGISTRY, ENTRY_CANDIDATES, EXTENSION_EDIT_METADATA_KEY, EvalMetricError, ExtensionInstallError, GEN_AI_ATTRIBUTES, IMPLICITLY_ALLOWED_SKILL_TOOLS, INTERRUPT_MESSAGE_FOR_TOOL_USE, McpOAuthProvider, NO_TOOLS_PREAMBLE, ORPHANED_TOOL_RESULT_MARKER, OUTPUT_RESERVE_TOKENS, OpenAICompatHttpError, OperationTimeoutError, PERSISTED_STUB_PREFIX, PERSISTENCE_PREVIEW_BYTES, PLUGIN_MANIFEST_FILE, PLUGIN_MCP_FILE, PLUGIN_SKILLS_DIR, SHELL_CASCADE_CANCEL_MESSAGE, SKILL_EDIT_METADATA_KEY, SUPPORTED_AGENT_PLUGINS_VERSIONS, SYNTHETIC_TOOL_RESULT_PLACEHOLDER, SYSTEM_PROMPT_BOUNDARY, SkillInstallError, TOOL_USE_CANCELLED_MESSAGE, TOOL_USE_INTERRUPTED_MARKER, TOOL_USE_SKIPPED_MESSAGE, TRAILER, ZIDANE_EXTENSION_SKILL_NAME, ZIDANE_SKILL_EDIT_SKILL_NAME, agentPluginsSchemaId, anchorPreviewFor, anthropic, appendDynamicSection, appendStaticSection, applyAnthropicCacheBreakpoints, applyCompactSummaryCutoff, arcee, artifactPath, autoDetectAndConvert, baseten, basic_default as basic, basicTools, buildCatalog, buildCompactPrompt, buildEvalRunSummary, buildExtensionPreset, buildExtensionRegistry, buildFromCompactPrompt, buildFullCompactPrompt, buildPersistedStub, buildPostCompactAttachments, buildRegisteredEvals, buildTailCompactPrompt, buildTrajectory, buildUpToCompactPrompt, buildZidaneExtensionSkill, buildZidaneSkillEditSkill, cerebras, clampExtensionConfigNumber, classifyOpenAICompatError, cleanupPersistedSession, clearRegisteredEvals, coerceExtensionConfigInput, collectNewlyStaleReadPaths, commandBlockToEvent, commandBlocksToContent, commandSteps, compactConversation, composeExtensionPreset, computeEvalTagScores, connectMcpServers, consoleSink, createAgent, createEvalAgent, createEvalRunReporter, createExtensionHostRuntimeBridge, createExtensionHud, createExtensionPromptBridge, createFileMapStore, createInteractionTool, createLogger, createLoggingHooks, createMemoryMcpCredentialStore, createMemoryStore, createMetricsHooks, createModelSearchTool, createMutationValidationHooks, createPathAutocompleteProvider, createProcessContext, createRemoteStore, createReusableExecutionContext, createRunSummaryCollector, createSandboxContext, createSession, createShellTool, createSkillActivationState, createSkillsReadTool, createSkillsRunScriptTool, createSkillsUseTool, createSpawnTool, createToolStateController, createTracingHooks, createWorkspaceSurface, credentialsFilePath, credentialsFromParams, defaultExtensionScanPaths, defaultPluginDataRoot, defaultRepeatGuardNormalize, defaultRepeatGuardTracked, defineEval, defineExtension, defineMetrics, definePreset, defineSkill, detectTurnInterruption, diffCacheDimensions, discoverAndBuildExtensionRegistry, discoverExtensions, discoverSkills, disposeExtensionRegistry, dropInvalidToolPairings, edit, editSessionMetadata, effectiveContextWindow, efficiencyMetricValues, emitEfficiencyMetrics, ensureEndsWithUserMessage, ensureToolResultPairing, errorMessage, estimateTokens, executeCommand, expandEnvPlaceholders, expandMcpConfigEnv, expandPluginVars, extensionDirForCwd, extensionScaffold, extractRuntimeCredentials, fetchExtensionSource, fileContains, fileContentQuality, fileExists, fileExistsOneOf, filterExtensionRegistry, filterUnresolvedToolUses, finalizeEvalMetrics, flattenTurns, fnv1a32, formatEvalCaseSummary, formatEvalRunSummary, formatModelLine, formatTokenUsage, formatTrajectoryLine, fromAnthropic, fromOpenAI, functionalityMetric, generateStructuredData, getModelCatalog, getOAuthApiKey, getOAuthProvider, getReadState, glob, grep, hasAuthorizationHeader, hasSystemPromptBoundary, hashContent, hashMessages, headlessEventToJsonl, hydrateReadStateFromSession, hydrateReadStateFromSessionAsync, inlineLoadedExtension, installAllowedToolsGate, installCacheBreakLogger, installExtensionFromSpec, installSkillFromSpec, interpolateShellCommands, isExtensionDefinition, isOAuthAccessToken, isSpawnTool, isStandardSchema, isSupportedAgentPluginsVersion, isToolAllowedByUnion, isToolStateOps, isValidExtensionConfigItem, isValidExtensionConfigValue, joinSystemPrompt, jsonSink, listExtensionCandidates, listSkillCandidates, llmJudge, loadAgentPlugin, loadSession, local, localReliabilityBehavior, loginMcpServer, mapOAIFinishReason, matchModelEntries, matchesAllowedTool, matchesContextExceeded, maybePersistToolResult, mergeContributions, migrateSessionArtifactDirs, mistral, multiEdit, normalizeMcpBlocks, normalizeMcpServers, normalizeMetric, normalizeProviders, normalizeShellCommand, openai, openaiCompat, openrouter, originPinnedFetch, parseAllowedToolPattern, parseCommandInvocation, parseExtensionInstallSource, parseExtensionScanPathEnv, parsePluginManifest, parseSchemaId, parseSkillFile, parseSkillInstallSpec, partitionExtensionCatalog, patchInlineGhost, readExtensionInstallProvenance, readOAuthCredentials, readSkillEditMarker, readSkillProvenance, readStateKey, reasoningWireAction, refreshAnthropicToken, refreshOpenAICodexToken, registerCustomOAuthProvider, registerEvalTests, registerExtensionHostModules, registerOAuthProvider, relativeArtifactPath, remintDuplicateToolCallIds, removeInstalledExtension, renderStaleReadNotice, renderSystemForWire, replaceDynamicSection, resolveCompletionSubmit, resolveDetachedTasksCapability, resolveExtensionConfig, resolveExtensionConfigValue, resolveExtensionDocsDir, resolveInlineSuggestion, resolveLegacyPersistDir, resolveLegacySessionDir, resolveMcpWarningsDir, resolveModelTargets, resolveOAuthApiKey, resolvePersistDir, resolveReadStateMap, resolveSchemaInput, resolveSessionDir, resolveSkills, resolveTasksDir, resolveTransportConfig, resultToString, runEvalCase, runHeadless, sanitizeExtensionConfigActionPatch, sanitizeHistoryForProvider, sanitizeToolSchema, sanitizeToolSpecs, scanExtensionDirectories, selectFilesFromReadState, selectFilesFromSession, selectRecentFiles, setModelCatalog, shouldAutoCompact, sliceForCompaction, snapshotCacheDimensions, splitSystemPrompt, stableStringify, stagedToolState, startOAuthCallback, statsByModel, statusCompleted, stripImagesFromTurns, stripShellInterpolations, summaryToTurn, toAnthropic, toOpenAI, toTypedError, toWireConfigSchema, toWireMessages, toolOutputBudgetByteLength, toolOutputByteLength, toolResultToText, transcriptToOpenAIMessages, truncateHeadForPtlRetry, updateInstalledExtension, utf8ByteLength, validatePluginManifest, validateResourcePath, validateResourcePathReal, validateSkillForWrite, validateSkillName, validateToolArgs, waitTask, withZidaneExtensionSkill, withZidaneSkillEditSkill, writeOAuthCredentials, writeSkillToDisk, writeSkillsToDisk, xai, zodToJsonSchema };
|
|
1199
|
-
|
|
1200
|
-
//# sourceMappingURL=index.js.map
|
|
35
|
+
export { ANCHOR_PREVIEW_MAX_CHARS, AUTO_COMPACT_MIN_GROWTH_FRACTION, AgentAbortedError, AgentBudgetExceededError, AgentContextExceededError, AgentLengthResumeExhaustedError, AgentProviderError, AgentToolNotAllowedError, AgentToolPairingError, BASE_INSTRUCTIONS, BYTES_PER_TOKEN, CONTEXT_EXCEEDED_MESSAGE_PATTERNS, CompactInvalidInputError, CompactPromptTooLongError, DEFAULT_MAX_VALUE_BYTES, EFFICIENCY_METRICS, EMPTY_EXTENSION_REGISTRY, ENTRY_CANDIDATES, EXTENSION_BUS_MAX_PAYLOAD_BYTES, EXTENSION_EDIT_METADATA_KEY, EvalMetricError, ExtensionInstallError, GEN_AI_ATTRIBUTES, IMPLICITLY_ALLOWED_SKILL_TOOLS, INTERRUPT_MESSAGE_FOR_TOOL_USE, McpOAuthProvider, NO_TOOLS_PREAMBLE, ORPHANED_TOOL_RESULT_MARKER, OUTPUT_RESERVE_TOKENS, OpenAICompatHttpError, OperationTimeoutError, PERSISTED_STUB_PREFIX, PERSISTENCE_PREVIEW_BYTES, PLUGIN_MANIFEST_FILE, PLUGIN_MCP_FILE, PLUGIN_SKILLS_DIR, SHELL_CASCADE_CANCEL_MESSAGE, SKILL_EDIT_METADATA_KEY, SUPPORTED_AGENT_PLUGINS_VERSIONS, SYNTHETIC_TOOL_RESULT_PLACEHOLDER, SYSTEM_PROMPT_BOUNDARY, SkillInstallError, TOOL_USE_CANCELLED_MESSAGE, TOOL_USE_INTERRUPTED_MARKER, TOOL_USE_SKIPPED_MESSAGE, TRAILER, ZIDANE_EXTENSION_SKILL_NAME, ZIDANE_SKILL_EDIT_SKILL_NAME, agentPluginsSchemaId, anchorPreviewFor, anthropic, appendDynamicSection, appendStaticSection, applyAnthropicCacheBreakpoints, applyCompactSummaryCutoff, arcee, artifactPath, autoDetectAndConvert, baseten, basic_default as basic, basicTools, buildCatalog, buildCompactPrompt, buildEvalRunSummary, buildExtensionPreset, buildExtensionRegistry, buildFromCompactPrompt, buildFullCompactPrompt, buildPersistedStub, buildPostCompactAttachments, buildRegisteredEvals, buildTailCompactPrompt, buildTrajectory, buildUpToCompactPrompt, buildZidaneExtensionSkill, buildZidaneSkillEditSkill, cerebras, clampExtensionConfigNumber, classifyOpenAICompatError, cleanupPersistedSession, clearRegisteredEvals, coerceExtensionConfigInput, collectNewlyStaleReadPaths, commandBlockToEvent, commandBlocksToContent, commandSteps, compactConversation, composeExtensionPreset, computeEvalTagScores, connectMcpServers, consoleSink, createAgent, createEvalAgent, createEvalRunReporter, createExtensionBus, createExtensionHostRuntimeBridge, createExtensionHud, createExtensionPromptBridge, createFileMapStore, createInteractionTool, createLogger, createLoggingHooks, createMemoryMcpCredentialStore, createMemoryStore, createMetricsHooks, createModelSearchTool, createMutationValidationHooks, createPathAutocompleteProvider, createProcessContext, createRemoteStore, createReusableExecutionContext, createRingBufferSink, createRunSummaryCollector, createSandboxContext, createSession, createShellTool, createSkillActivationState, createSkillsReadTool, createSkillsRunScriptTool, createSkillsUseTool, createSpawnTool, createToolStateController, createTracingHooks, createWorkspaceSurface, credentialsFilePath, credentialsFromParams, defaultExtensionScanPaths, defaultPluginDataRoot, defaultRepeatGuardNormalize, defaultRepeatGuardTracked, defineEval, defineExtension, defineMetrics, definePreset, defineSkill, detectTurnInterruption, diffCacheDimensions, discoverAndBuildExtensionRegistry, discoverExtensions, discoverSkills, disposeExtensionRegistry, dropInvalidToolPairings, edit, editSessionMetadata, effectiveContextWindow, efficiencyMetricValues, emitEfficiencyMetrics, ensureEndsWithUserMessage, ensureToolResultPairing, errorMessage, estimateTokens, executeCommand, expandEnvPlaceholders, expandMcpConfigEnv, expandPluginVars, extensionDirForCwd, extensionScaffold, extractRuntimeCredentials, fanoutSink, fetchExtensionSource, fileContains, fileContentQuality, fileExists, fileExistsOneOf, filterExtensionRegistry, filterUnresolvedToolUses, finalizeEvalMetrics, flattenTurns, fnv1a32, formatEvalCaseSummary, formatEvalRunSummary, formatLogLine, formatModelLine, formatTokenUsage, formatTrajectoryLine, fromAnthropic, fromOpenAI, functionalityMetric, generateStructuredData, getModelCatalog, getOAuthApiKey, getOAuthProvider, getReadState, glob, grep, hasAuthorizationHeader, hasSystemPromptBoundary, hashContent, hashMessages, headlessEventToJsonl, hydrateReadStateFromSession, hydrateReadStateFromSessionAsync, inlineLoadedExtension, installAllowedToolsGate, installCacheBreakLogger, installExtensionFromSpec, installSkillFromSpec, interpolateShellCommands, isExtensionDefinition, isOAuthAccessToken, isSpawnTool, isStandardSchema, isSupportedAgentPluginsVersion, isToolAllowedByUnion, isToolStateOps, isValidExtensionConfigItem, isValidExtensionConfigValue, joinSystemPrompt, jsonSink, listExtensionCandidates, listSkillCandidates, llmJudge, loadAgentPlugin, loadSession, local, localReliabilityBehavior, loginMcpServer, mapOAIFinishReason, matchModelEntries, matchesAllowedTool, matchesContextExceeded, maybePersistToolResult, mergeContributions, migrateSessionArtifactDirs, mistral, multiEdit, normalizeMcpBlocks, normalizeMcpServers, normalizeMetric, normalizeProviders, normalizeShellCommand, openai, openaiCompat, openrouter, originPinnedFetch, parseAllowedToolPattern, parseCommandInvocation, parseExtensionInstallSource, parseExtensionScanPathEnv, parsePluginManifest, parseSchemaId, parseSkillFile, parseSkillInstallSpec, partitionExtensionCatalog, patchInlineGhost, readExtensionInstallProvenance, readOAuthCredentials, readSkillEditMarker, readSkillProvenance, readStateKey, reasoningWireAction, refreshAnthropicToken, refreshOpenAICodexToken, registerCustomOAuthProvider, registerEvalTests, registerExtensionHostModules, registerOAuthProvider, relativeArtifactPath, remintDuplicateToolCallIds, removeInstalledExtension, renderStaleReadNotice, renderSystemForWire, replaceDynamicSection, resolveCompletionSubmit, resolveDetachedTasksCapability, resolveExtensionConfig, resolveExtensionConfigValue, resolveExtensionDocsDir, resolveInlineSuggestion, resolveLegacyPersistDir, resolveLegacySessionDir, resolveMcpWarningsDir, resolveModelTargets, resolveOAuthApiKey, resolvePersistDir, resolveReadStateMap, resolveSchemaInput, resolveSessionDir, resolveSkills, resolveTasksDir, resolveTransportConfig, resultToString, runEvalCase, runHeadless, sanitizeExtensionConfigActionPatch, sanitizeHistoryForProvider, sanitizeToolSchema, sanitizeToolSpecs, scanExtensionDirectories, selectFilesFromReadState, selectFilesFromSession, selectRecentFiles, setModelCatalog, shouldAutoCompact, sliceForCompaction, snapshotCacheDimensions, splitSystemPrompt, stableStringify, stagedToolState, startOAuthCallback, statsByModel, statusCompleted, stripImagesFromTurns, stripShellInterpolations, summaryToTurn, toAnthropic, toOpenAI, toTypedError, toWireConfigSchema, toWireMessages, toolOutputBudgetByteLength, toolOutputByteLength, toolResultToText, transcriptToOpenAIMessages, truncateHeadForPtlRetry, updateInstalledExtension, utf8ByteLength, validatePluginManifest, validateResourcePath, validateResourcePathReal, validateSkillForWrite, validateSkillName, validateToolArgs, waitTask, withZidaneExtensionSkill, withZidaneSkillEditSkill, writeOAuthCredentials, writeSkillToDisk, writeSkillsToDisk, xai, zodToJsonSchema };
|