@superdurable/dex-agents 0.3.0 → 0.5.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/README.md +598 -45
- package/dist/src/agent-context-compaction.d.ts +1 -1
- package/dist/src/agent-framework-runner.d.ts +210 -10
- package/dist/src/agent-framework-runner.js +30 -0
- package/dist/src/agent-framework-runner.js.map +1 -1
- package/dist/src/agent-local-directory-media-store.d.ts +111 -0
- package/dist/src/agent-local-directory-media-store.js +417 -0
- package/dist/src/agent-local-directory-media-store.js.map +1 -0
- package/dist/src/agent-media.d.ts +279 -0
- package/dist/src/agent-media.js +457 -0
- package/dist/src/agent-media.js.map +1 -0
- package/dist/src/agent-session-codecs.d.ts +3 -1
- package/dist/src/agent-session-codecs.js +53 -4
- package/dist/src/agent-session-codecs.js.map +1 -1
- package/dist/src/agent-session-failure.d.ts +4 -2
- package/dist/src/agent-session-failure.js +6 -2
- package/dist/src/agent-session-failure.js.map +1 -1
- package/dist/src/agent-session-flow-graph.d.ts +46 -0
- package/dist/src/agent-session-flow-graph.js +51 -0
- package/dist/src/agent-session-flow-graph.js.map +1 -1
- package/dist/src/agent-session-flow-graph.json +98 -81
- package/dist/src/agent-session-flow.d.ts +5 -3
- package/dist/src/agent-session-flow.js +10 -1
- package/dist/src/agent-session-flow.js.map +1 -1
- package/dist/src/agent-session-start.d.ts +1 -1
- package/dist/src/agent-session-start.js +2 -2
- package/dist/src/agent-session-start.js.map +1 -1
- package/dist/src/agent-session-steps.d.ts +9 -0
- package/dist/src/agent-session-steps.js +219 -34
- package/dist/src/agent-session-steps.js.map +1 -1
- package/dist/src/agent-session-tracer.js +1 -1
- package/dist/src/agent-session-tracer.js.map +1 -1
- package/dist/src/agent-session-transitions.d.ts +4 -0
- package/dist/src/agent-session-transitions.js +29 -1
- package/dist/src/agent-session-transitions.js.map +1 -1
- package/dist/src/agent-session-values.d.ts +112 -1
- package/dist/src/agent-session-values.js +6 -0
- package/dist/src/agent-session-values.js.map +1 -1
- package/dist/src/agent-session-wait-steps.js +17 -5
- package/dist/src/agent-session-wait-steps.js.map +1 -1
- package/dist/src/ai-sdk/ai-sdk-model-client.d.ts +15 -3
- package/dist/src/ai-sdk/ai-sdk-model-client.js +36 -7
- package/dist/src/ai-sdk/ai-sdk-model-client.js.map +1 -1
- package/dist/src/ai-sdk/index.d.ts +1 -1
- package/dist/src/ai-sdk/index.js +1 -1
- package/dist/src/ai-sdk/index.js.map +1 -1
- package/dist/src/{stepwise → builtin-loop}/agent-definition.d.ts +120 -5
- package/dist/src/builtin-loop/agent-definition.js.map +1 -0
- package/dist/src/builtin-loop/builtin-agent-session-flow.d.ts +69 -0
- package/dist/src/{stepwise/stepwise-agent-session-flow.js → builtin-loop/builtin-agent-session-flow.js} +15 -9
- package/dist/src/builtin-loop/builtin-agent-session-flow.js.map +1 -0
- package/dist/src/{stepwise/stepwise-agent-runner.d.ts → builtin-loop/builtin-loop-agent-runner.d.ts} +85 -26
- package/dist/src/{stepwise/stepwise-agent-runner.js → builtin-loop/builtin-loop-agent-runner.js} +320 -213
- package/dist/src/builtin-loop/builtin-loop-agent-runner.js.map +1 -0
- package/dist/src/{stepwise/stepwise-input-items.d.ts → builtin-loop/builtin-loop-input-items.d.ts} +7 -3
- package/dist/src/{stepwise/stepwise-input-items.js → builtin-loop/builtin-loop-input-items.js} +57 -10
- package/dist/src/builtin-loop/builtin-loop-input-items.js.map +1 -0
- package/dist/src/builtin-loop/function-tool.d.ts +282 -0
- package/dist/src/{stepwise → builtin-loop}/function-tool.js +63 -3
- package/dist/src/builtin-loop/function-tool.js.map +1 -0
- package/dist/src/builtin-loop/index.d.ts +8 -0
- package/dist/src/builtin-loop/index.js +13 -0
- package/dist/src/builtin-loop/index.js.map +1 -0
- package/dist/src/builtin-loop/json-schema-validation.js.map +1 -0
- package/dist/src/{stepwise → builtin-loop}/model-client.d.ts +36 -7
- package/dist/src/builtin-loop/model-client.js.map +1 -0
- package/dist/src/{stepwise → builtin-loop}/scripted-model-client.d.ts +8 -5
- package/dist/src/{stepwise → builtin-loop}/scripted-model-client.js +8 -5
- package/dist/src/builtin-loop/scripted-model-client.js.map +1 -0
- package/dist/src/{stepwise → builtin-loop}/tool-source.d.ts +13 -3
- package/dist/src/builtin-loop/tool-source.js.map +1 -0
- package/dist/src/connectors/connector-input-schema.d.ts +19 -0
- package/dist/src/connectors/connector-input-schema.js +228 -0
- package/dist/src/connectors/connector-input-schema.js.map +1 -0
- package/dist/src/connectors/connector-step-context.d.ts +94 -0
- package/dist/src/connectors/connector-step-context.js +180 -0
- package/dist/src/connectors/connector-step-context.js.map +1 -0
- package/dist/src/connectors/connector-tool-source.d.ts +401 -0
- package/dist/src/connectors/connector-tool-source.js +628 -0
- package/dist/src/connectors/connector-tool-source.js.map +1 -0
- package/dist/src/connectors/index.d.ts +3 -0
- package/dist/src/connectors/index.js +11 -0
- package/dist/src/connectors/index.js.map +1 -0
- package/dist/src/index.d.ts +7 -3
- package/dist/src/index.js +6 -3
- package/dist/src/index.js.map +1 -1
- package/dist/src/mcp/index.d.ts +1 -0
- package/dist/src/mcp/index.js +1 -0
- package/dist/src/mcp/index.js.map +1 -1
- package/dist/src/mcp/mcp-dex-conventions.d.ts +57 -0
- package/dist/src/mcp/mcp-dex-conventions.js +90 -0
- package/dist/src/mcp/mcp-dex-conventions.js.map +1 -0
- package/dist/src/mcp/mcp-image-content.d.ts +20 -0
- package/dist/src/mcp/mcp-image-content.js +82 -0
- package/dist/src/mcp/mcp-image-content.js.map +1 -0
- package/dist/src/mcp/mcp-tool-source.d.ts +178 -17
- package/dist/src/mcp/mcp-tool-source.js +237 -34
- package/dist/src/mcp/mcp-tool-source.js.map +1 -1
- package/dist/src/s3/index.d.ts +1 -0
- package/dist/src/s3/index.js +9 -0
- package/dist/src/s3/index.js.map +1 -0
- package/dist/src/s3/s3-media-store.d.ts +138 -0
- package/dist/src/s3/s3-media-store.js +255 -0
- package/dist/src/s3/s3-media-store.js.map +1 -0
- package/dist/src/stepwise/index.d.ts +41 -8
- package/dist/src/stepwise/index.js +35 -5
- package/dist/src/stepwise/index.js.map +1 -1
- package/dist/src/testing/agent-session-test-client.d.ts +6 -3
- package/dist/src/testing/agent-session-test-client.js +10 -3
- package/dist/src/testing/agent-session-test-client.js.map +1 -1
- package/dist/src/testing/scripted-model-client.d.ts +1 -1
- package/dist/src/testing/scripted-model-client.js +2 -2
- package/dist/src/testing/scripted-model-client.js.map +1 -1
- package/dist/src/tool-source-router.d.ts +211 -0
- package/dist/src/tool-source-router.js +380 -0
- package/dist/src/tool-source-router.js.map +1 -0
- package/dist/src/ui-stream/agent-event-json.d.ts +2 -1
- package/dist/src/ui-stream/agent-event-json.js +3 -1
- package/dist/src/ui-stream/agent-event-json.js.map +1 -1
- package/dist/src/ui-stream/agent-ui-messages.d.ts +11 -3
- package/dist/src/ui-stream/agent-ui-messages.js +29 -5
- package/dist/src/ui-stream/agent-ui-messages.js.map +1 -1
- package/package.json +25 -3
- package/dist/src/stepwise/agent-definition.js.map +0 -1
- package/dist/src/stepwise/function-tool.d.ts +0 -130
- package/dist/src/stepwise/function-tool.js.map +0 -1
- package/dist/src/stepwise/json-schema-validation.js.map +0 -1
- package/dist/src/stepwise/model-client.js.map +0 -1
- package/dist/src/stepwise/scripted-model-client.js.map +0 -1
- package/dist/src/stepwise/stepwise-agent-runner.js.map +0 -1
- package/dist/src/stepwise/stepwise-agent-session-flow.d.ts +0 -35
- package/dist/src/stepwise/stepwise-agent-session-flow.js.map +0 -1
- package/dist/src/stepwise/stepwise-input-items.js.map +0 -1
- package/dist/src/stepwise/tool-source.js.map +0 -1
- /package/dist/src/{stepwise → builtin-loop}/agent-definition.js +0 -0
- /package/dist/src/{stepwise → builtin-loop}/json-schema-validation.d.ts +0 -0
- /package/dist/src/{stepwise → builtin-loop}/json-schema-validation.js +0 -0
- /package/dist/src/{stepwise → builtin-loop}/model-client.js +0 -0
- /package/dist/src/{stepwise → builtin-loop}/tool-source.js +0 -0
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// Copyright (c) 2026 Super Durable, Inc.
|
|
2
|
+
//
|
|
3
|
+
// Licensed under the Sustainable Use License 1.0.
|
|
4
|
+
// You may not use this file except in compliance with the License.
|
|
5
|
+
// See the LICENSE file in the repository root.
|
|
6
|
+
//
|
|
7
|
+
// SPDX-License-Identifier: LicenseRef-Sustainable-Use-1.0
|
|
8
|
+
export { ConnectorToolSource, boundConnectorResult, classifyConnectorBranch, connectorNotSentRetryLater, connectorResultTruncatedNote, connectorTool, defaultConnectorResultMaxBytes, defaultConnectorSourceName, formatConnectorResult, } from "./connector-tool-source.js";
|
|
9
|
+
export { ConnectorStepContext } from "./connector-step-context.js";
|
|
10
|
+
export { checkConnectorInputSchema, findConnectorInputViolation } from "./connector-input-schema.js";
|
|
11
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/connectors/index.ts"],"names":[],"mappings":"AAAA,yCAAyC;AACzC,EAAE;AACF,kDAAkD;AAClD,mEAAmE;AACnE,+CAA+C;AAC/C,EAAE;AACF,0DAA0D;AAE1D,OAAO,EACL,mBAAmB,EACnB,oBAAoB,EACpB,uBAAuB,EACvB,0BAA0B,EAC1B,4BAA4B,EAC5B,aAAa,EACb,8BAA8B,EAC9B,0BAA0B,EAC1B,qBAAqB,GAQtB,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,oBAAoB,EAAgC,MAAM,6BAA6B,CAAC;AACjG,OAAO,EAAE,yBAAyB,EAAE,2BAA2B,EAAE,MAAM,6BAA6B,CAAC"}
|
package/dist/src/index.d.ts
CHANGED
|
@@ -1,15 +1,19 @@
|
|
|
1
1
|
export { builtInToolDefinitions, writeTodosCalledMoreThanOnce, type BuiltInTool, type BuiltInToolDefinition, } from "./agent-built-in-tools.js";
|
|
2
2
|
export { buildPlanExecutionMessage, buildPlanNote, noPlanNote, planStatusAfterWrite, planningTurnInstruction, planningTurnToolRejection, } from "./agent-plans.js";
|
|
3
3
|
export { buildContextSummaryNote, buildContextSummaryOmissionNote, buildContextSummaryPrompt, contextSummaryInstructions, contextSummaryNoteHeader, contextSummaryOutputTokens, contextSummaryRequest, contextSummaryTranscriptHeader, describeStoredMessage, estimateStoredInputTokens, estimateTextTokens, selectTurnBoundaryCutoff, type CompactionPolicy, type ContextSummaryRequest, type ContextSummaryResult, type ResolvedCompactionPolicy, } from "./agent-context-compaction.js";
|
|
4
|
-
export { ToolExecutionError, resolveToolPolicy, toolEffectFromMcpToolAnnotations, type AgentEventWriter, type AgentFrameworkRunner, type AgentTurnContext, type AgentTurnOutcome, type DeferredToolCall, type DeferredToolExecution, type DeferredToolOutcome, type McpToolAnnotations, type ModelCallMetadata, type ResolvedToolPolicy, type ToolExecutionResult, type ToolInputRequested, type ToolPolicy, type ToolTaskPending, type ToolTaskCancellation, type ToolTaskPoll, type ToolTaskPollOutcome, type ToolTaskStarted, type TurnCompleted, type ToolCallsRequested, } from "./agent-framework-runner.js";
|
|
4
|
+
export { ToolExecutionError, ToolOutcomeUnknownError, resolveToolPolicy, toolEffectFromMcpToolAnnotations, type AgentEventWriter, type AgentFrameworkRunner, type AgentTurnContext, type AgentTurnOutcome, type DeferredToolCall, type DeferredToolExecution, type DeferredToolOutcome, type McpToolAnnotations, type ModelCallMetadata, type ResolvedToolPolicy, type ToolExecutionResult, type ToolCallStepOptions, type ToolInputRequested, type ToolPolicy, type ToolTaskPending, type ToolTaskCancellation, type ToolTaskPoll, type ToolTaskPollOutcome, type ToolTaskStarted, type TurnCompleted, type TurnContinued, type ToolCallsRequested, } from "./agent-framework-runner.js";
|
|
5
|
+
export { LocalDirectoryMediaStore } from "./agent-local-directory-media-store.js";
|
|
6
|
+
export { ImageValidationError, InMemoryMediaStore, MediaStoreError, buildImageReference, collectTurnImages, detectImageMimeType, imageUri, loadImages, maxImageBytes, maxImageUriLength, maxImagesPerMessage, requireShortImageUris, requireStoreImageReference, supportedImageMimeTypes, validateImageReference, validateImageReferences, verifyImageBytes, type MediaStore, } from "./agent-media.js";
|
|
5
7
|
export { createAgentSessionFlow, type AgentSessionFlow, type AgentSessionOptions, type ResolvedAgentSessionOptions, } from "./agent-session-flow.js";
|
|
6
8
|
export { defaultAgentEventsCapacityBytes, messageSequenceKey, planExecutionKey, type AgentSessionPersistence, } from "./agent-session-persistence.js";
|
|
7
|
-
export { addAgentUsage, approvalDeadlinePassed, blankToolTaskId, buildTurnFailureNote, defaultQuestionDeclinedToolResult, defaultRejectionToolResult, describeToolCallOutcome, emptyAgentUsage, invalidToolTaskPollInterval, toolCallNotRunErrorPrefix, toolTaskAbandonedError, isFinalToolCallStatus, missingToolTaskPoller, outcomeUnknownToolResult, questionDeadlinePassed, toolCallCancelledBySteeringResult, toolCallCancelledByTurnCancellationResult, turnCancelledNoteHeader, turnFailureNoteFooter, turnFailureNoteHeader, turnSteeredNoteHeader, type AgentEvent, type AgentEventType, type AgentInterrupt, type AgentInterruptKind, type AgentInterruptResolution, type AgentMessage, type AgentMessageChunk, type AgentMessageChunkRange, type AgentMessageIndex, type AgentMessageRole, type AgentMessagesPage, type AgentPlan, type AgentPlanTask, type AgentSessionStartInput, type AgentSessionStatus, type AgentSnapshot, type AgentState, type AgentToolCall, type AgentToolCallRecord, type AgentToolCallRecordStatus, type AgentToolCallStatus, type AgentToolCallWaitingStatus, type AgentUsage, type AgentUserMessage, type AnswerQuestionRequest, type CancelTurnRequest, type DeleteQueuedMessageRequest, type ExecutePlanRequest, type CompactContextInput, type ContextSummary, type FrameworkMessage, type InteractionMode, type ListAgentMessagesInput, type PendingUserMessage, type PlanExecutionRequest, type PlanStatus, type PlanTaskStatus, type QuestionAnswer, type QuestionResolution, type ResolveInterruptInput, type SessionSettings, type TurnReplySequence, type TurnSessionSettings, type SteerUserMessageRequest, type ToolCallCancellation, type ToolCallCancellationReason, type ToolCallCompleted, type ToolEffect, type TurnCancellationRequest, type TurnControlKind, type TurnControlRequest, type UpdateSessionSettingsRequest, } from "./agent-session-values.js";
|
|
9
|
+
export { addAgentUsage, approvalDeadlinePassed, blankToolTaskId, buildTurnFailureNote, defaultQuestionDeclinedToolResult, defaultRejectionToolResult, describeToolCallOutcome, emptyAgentUsage, invalidToolTaskPollInterval, toolCallNotRunErrorPrefix, toolCallSkippedAfterWriteDetail, toolTaskAbandonedError, isFinalToolCallStatus, missingToolTaskPoller, outcomeUnknownToolResult, questionDeadlinePassed, toolCallCancelledBySteeringResult, toolCallCancelledByTurnCancellationResult, turnCancelledNoteHeader, turnFailureNoteFooter, turnFailureNoteHeader, turnSteeredNoteHeader, type AgentEvent, type AgentEventType, type AgentImageReference, type AgentInterrupt, type AgentInterruptKind, type AgentInterruptResolution, type AgentMessage, type AgentMessageChunk, type AgentMessageChunkRange, type AgentMessageIndex, type AgentMessageRole, type AgentMessagesPage, type AgentPlan, type AgentPlanTask, type AgentSessionStartInput, type AgentSessionStatus, type AgentSnapshot, type AgentState, type AgentToolCall, type AgentToolCallRecord, type AgentToolCallRecordStatus, type AgentToolCallStatus, type AgentToolCallWaitingStatus, type AgentUsage, type AgentUserMessage, type AnswerQuestionRequest, type CancelTurnRequest, type DeleteQueuedMessageRequest, type ExecutePlanRequest, type CompactContextInput, type ContextSummary, type FrameworkMessage, type InteractionMode, type ListAgentMessagesInput, type PendingUserMessage, type PlanExecutionRequest, type PlanStatus, type PlanTaskStatus, type QuestionAnswer, type QuestionResolution, type ResolveInterruptInput, type SessionSettings, type TurnReplySequence, type TurnSessionSettings, type SteerUserMessageRequest, type ToolCallCancellation, type ToolCallCancellationReason, type ToolCallCompleted, type ToolEffect, type TurnCancellationRequest, type TurnControlKind, type TurnControlRequest, type UpdateSessionSettingsRequest, } from "./agent-session-values.js";
|
|
8
10
|
export { MAX_SESSION_SETTINGS_BYTES, SESSION_SETTINGS_SIZE_TOLERANCE_BYTES, sessionSettingsSize, validateSessionSettings, } from "./agent-session-settings.js";
|
|
9
11
|
export type { ResolvedRunModelLimit, RunModelLimit } from "./agent-session-step-options.js";
|
|
10
12
|
export { modelCallRefusedErrorPrefix, spendLimitCallTimeoutMs, type ModelCallCheck, type ModelCallDecision, type ModelSpendLimit, type ModelUsageReport, } from "./agent-session-spend-limit.js";
|
|
11
13
|
export { AgentSessionFailedError, readAgentSnapshot, sendAgentUserMessage } from "./agent-session-failure.js";
|
|
12
|
-
export { renderSessionFlowGraph, type SessionFlowGraphOptions } from "./agent-session-flow-graph.js";
|
|
14
|
+
export { renderSessionFlowGraph, sessionFlowDefinitionDocument, type SessionFlowGraphOptions, } from "./agent-session-flow-graph.js";
|
|
13
15
|
export { agentSessionActiveStepSearchMode, startAgentSession } from "./agent-session-start.js";
|
|
14
16
|
export { invalidStartSessionSettingsReason } from "./agent-session-steps.js";
|
|
15
17
|
export { genAISemanticConventionsSchemaUrls, type AgentTracingOptions, type GenAISemanticConventionsVersion, type OpenTelemetryTracerProvider, type ResolvedAgentTracingOptions, } from "./agent-tracing-options.js";
|
|
18
|
+
export { ToolSourceRouter, defaultToolSourceListingTimeoutMs, type ListedSourceTool, type ToolSourceRouterOptions, } from "./tool-source-router.js";
|
|
19
|
+
export { type SourceToolDefinition, type ToolSource } from "./builtin-loop/tool-source.js";
|
package/dist/src/index.js
CHANGED
|
@@ -8,15 +8,18 @@
|
|
|
8
8
|
export { builtInToolDefinitions, writeTodosCalledMoreThanOnce, } from "./agent-built-in-tools.js";
|
|
9
9
|
export { buildPlanExecutionMessage, buildPlanNote, noPlanNote, planStatusAfterWrite, planningTurnInstruction, planningTurnToolRejection, } from "./agent-plans.js";
|
|
10
10
|
export { buildContextSummaryNote, buildContextSummaryOmissionNote, buildContextSummaryPrompt, contextSummaryInstructions, contextSummaryNoteHeader, contextSummaryOutputTokens, contextSummaryRequest, contextSummaryTranscriptHeader, describeStoredMessage, estimateStoredInputTokens, estimateTextTokens, selectTurnBoundaryCutoff, } from "./agent-context-compaction.js";
|
|
11
|
-
export { ToolExecutionError, resolveToolPolicy, toolEffectFromMcpToolAnnotations, } from "./agent-framework-runner.js";
|
|
11
|
+
export { ToolExecutionError, ToolOutcomeUnknownError, resolveToolPolicy, toolEffectFromMcpToolAnnotations, } from "./agent-framework-runner.js";
|
|
12
|
+
export { LocalDirectoryMediaStore } from "./agent-local-directory-media-store.js";
|
|
13
|
+
export { ImageValidationError, InMemoryMediaStore, MediaStoreError, buildImageReference, collectTurnImages, detectImageMimeType, imageUri, loadImages, maxImageBytes, maxImageUriLength, maxImagesPerMessage, requireShortImageUris, requireStoreImageReference, supportedImageMimeTypes, validateImageReference, validateImageReferences, verifyImageBytes, } from "./agent-media.js";
|
|
12
14
|
export { createAgentSessionFlow, } from "./agent-session-flow.js";
|
|
13
15
|
export { defaultAgentEventsCapacityBytes, messageSequenceKey, planExecutionKey, } from "./agent-session-persistence.js";
|
|
14
|
-
export { addAgentUsage, approvalDeadlinePassed, blankToolTaskId, buildTurnFailureNote, defaultQuestionDeclinedToolResult, defaultRejectionToolResult, describeToolCallOutcome, emptyAgentUsage, invalidToolTaskPollInterval, toolCallNotRunErrorPrefix, toolTaskAbandonedError, isFinalToolCallStatus, missingToolTaskPoller, outcomeUnknownToolResult, questionDeadlinePassed, toolCallCancelledBySteeringResult, toolCallCancelledByTurnCancellationResult, turnCancelledNoteHeader, turnFailureNoteFooter, turnFailureNoteHeader, turnSteeredNoteHeader, } from "./agent-session-values.js";
|
|
16
|
+
export { addAgentUsage, approvalDeadlinePassed, blankToolTaskId, buildTurnFailureNote, defaultQuestionDeclinedToolResult, defaultRejectionToolResult, describeToolCallOutcome, emptyAgentUsage, invalidToolTaskPollInterval, toolCallNotRunErrorPrefix, toolCallSkippedAfterWriteDetail, toolTaskAbandonedError, isFinalToolCallStatus, missingToolTaskPoller, outcomeUnknownToolResult, questionDeadlinePassed, toolCallCancelledBySteeringResult, toolCallCancelledByTurnCancellationResult, turnCancelledNoteHeader, turnFailureNoteFooter, turnFailureNoteHeader, turnSteeredNoteHeader, } from "./agent-session-values.js";
|
|
15
17
|
export { MAX_SESSION_SETTINGS_BYTES, SESSION_SETTINGS_SIZE_TOLERANCE_BYTES, sessionSettingsSize, validateSessionSettings, } from "./agent-session-settings.js";
|
|
16
18
|
export { modelCallRefusedErrorPrefix, spendLimitCallTimeoutMs, } from "./agent-session-spend-limit.js";
|
|
17
19
|
export { AgentSessionFailedError, readAgentSnapshot, sendAgentUserMessage } from "./agent-session-failure.js";
|
|
18
|
-
export { renderSessionFlowGraph } from "./agent-session-flow-graph.js";
|
|
20
|
+
export { renderSessionFlowGraph, sessionFlowDefinitionDocument, } from "./agent-session-flow-graph.js";
|
|
19
21
|
export { agentSessionActiveStepSearchMode, startAgentSession } from "./agent-session-start.js";
|
|
20
22
|
export { invalidStartSessionSettingsReason } from "./agent-session-steps.js";
|
|
21
23
|
export { genAISemanticConventionsSchemaUrls, } from "./agent-tracing-options.js";
|
|
24
|
+
export { ToolSourceRouter, defaultToolSourceListingTimeoutMs, } from "./tool-source-router.js";
|
|
22
25
|
//# sourceMappingURL=index.js.map
|
package/dist/src/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,yCAAyC;AACzC,EAAE;AACF,kDAAkD;AAClD,mEAAmE;AACnE,+CAA+C;AAC/C,EAAE;AACF,0DAA0D;AAE1D,OAAO,EACL,sBAAsB,EACtB,4BAA4B,GAG7B,MAAM,2BAA2B,CAAC;AACnC,OAAO,EACL,yBAAyB,EACzB,aAAa,EACb,UAAU,EACV,oBAAoB,EACpB,uBAAuB,EACvB,yBAAyB,GAC1B,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EACL,uBAAuB,EACvB,+BAA+B,EAC/B,yBAAyB,EACzB,0BAA0B,EAC1B,wBAAwB,EACxB,0BAA0B,EAC1B,qBAAqB,EACrB,8BAA8B,EAC9B,qBAAqB,EACrB,yBAAyB,EACzB,kBAAkB,EAClB,wBAAwB,GAKzB,MAAM,+BAA+B,CAAC;AACvC,OAAO,EACL,kBAAkB,EAClB,iBAAiB,EACjB,gCAAgC,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,yCAAyC;AACzC,EAAE;AACF,kDAAkD;AAClD,mEAAmE;AACnE,+CAA+C;AAC/C,EAAE;AACF,0DAA0D;AAE1D,OAAO,EACL,sBAAsB,EACtB,4BAA4B,GAG7B,MAAM,2BAA2B,CAAC;AACnC,OAAO,EACL,yBAAyB,EACzB,aAAa,EACb,UAAU,EACV,oBAAoB,EACpB,uBAAuB,EACvB,yBAAyB,GAC1B,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EACL,uBAAuB,EACvB,+BAA+B,EAC/B,yBAAyB,EACzB,0BAA0B,EAC1B,wBAAwB,EACxB,0BAA0B,EAC1B,qBAAqB,EACrB,8BAA8B,EAC9B,qBAAqB,EACrB,yBAAyB,EACzB,kBAAkB,EAClB,wBAAwB,GAKzB,MAAM,+BAA+B,CAAC;AACvC,OAAO,EACL,kBAAkB,EAClB,uBAAuB,EACvB,iBAAiB,EACjB,gCAAgC,GAuBjC,MAAM,6BAA6B,CAAC;AACrC,OAAO,EAAE,wBAAwB,EAAE,MAAM,wCAAwC,CAAC;AAClF,OAAO,EACL,oBAAoB,EACpB,kBAAkB,EAClB,eAAe,EACf,mBAAmB,EACnB,iBAAiB,EACjB,mBAAmB,EACnB,QAAQ,EACR,UAAU,EACV,aAAa,EACb,iBAAiB,EACjB,mBAAmB,EACnB,qBAAqB,EACrB,0BAA0B,EAC1B,uBAAuB,EACvB,sBAAsB,EACtB,uBAAuB,EACvB,gBAAgB,GAEjB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EACL,sBAAsB,GAIvB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EACL,+BAA+B,EAC/B,kBAAkB,EAClB,gBAAgB,GAEjB,MAAM,gCAAgC,CAAC;AACxC,OAAO,EACL,aAAa,EACb,sBAAsB,EACtB,eAAe,EACf,oBAAoB,EACpB,iCAAiC,EACjC,0BAA0B,EAC1B,uBAAuB,EACvB,eAAe,EACf,2BAA2B,EAC3B,yBAAyB,EACzB,+BAA+B,EAC/B,sBAAsB,EACtB,qBAAqB,EACrB,qBAAqB,EACrB,wBAAwB,EACxB,sBAAsB,EACtB,iCAAiC,EACjC,yCAAyC,EACzC,uBAAuB,EACvB,qBAAqB,EACrB,qBAAqB,EACrB,qBAAqB,GAsDtB,MAAM,2BAA2B,CAAC;AACnC,OAAO,EACL,0BAA0B,EAC1B,qCAAqC,EACrC,mBAAmB,EACnB,uBAAuB,GACxB,MAAM,6BAA6B,CAAC;AAErC,OAAO,EACL,2BAA2B,EAC3B,uBAAuB,GAKxB,MAAM,gCAAgC,CAAC;AACxC,OAAO,EAAE,uBAAuB,EAAE,iBAAiB,EAAE,oBAAoB,EAAE,MAAM,4BAA4B,CAAC;AAC9G,OAAO,EACL,sBAAsB,EACtB,6BAA6B,GAE9B,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAAE,gCAAgC,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAC/F,OAAO,EAAE,iCAAiC,EAAE,MAAM,0BAA0B,CAAC;AAC7E,OAAO,EACL,kCAAkC,GAKnC,MAAM,4BAA4B,CAAC;AACpC,OAAO,EACL,gBAAgB,EAChB,iCAAiC,GAGlC,MAAM,yBAAyB,CAAC"}
|
package/dist/src/mcp/index.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
export { type McpServerConfig, type McpStdioServerConfig, type McpStreamableHttpServerConfig, } from "./mcp-server-config.js";
|
|
2
|
+
export { mcpToolApprovalMetaKey, mcpToolApprovalRecommended, mcpToolEffectMetaKey, mcpToolOutcomeMetaKey, mcpToolOutcomeRejected, mcpToolOutcomeUnknown, } from "./mcp-dex-conventions.js";
|
|
2
3
|
export { mcpGetPromptToolName, mcpListResourcesAndPromptsToolName, mcpReadResourceToolName, } from "./mcp-resource-and-prompt-tools.js";
|
|
3
4
|
export { McpToolCallInterruptedError, McpToolListingError, McpToolSource, defaultMcpConnectionAttempts, defaultMcpConnectionTimeoutMs, defaultMcpListingFailureBackoffMs, defaultMcpListingTtlMs, defaultMcpRequestTimeoutMs, defaultMcpSourceName, defaultMcpTaskTtlMs, defaultMcpTaskWaitTimeoutMs, mcpIdempotencyKeyMetaKey, mcpTaskStatusEventType, mcpToolProgressEventType, type DeferredToolHandler, type McpTool, type McpToolCallOptions, type McpToolSourceOptions, } from "./mcp-tool-source.js";
|
package/dist/src/mcp/index.js
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
// See the LICENSE file in the repository root.
|
|
6
6
|
//
|
|
7
7
|
// SPDX-License-Identifier: LicenseRef-Sustainable-Use-1.0
|
|
8
|
+
export { mcpToolApprovalMetaKey, mcpToolApprovalRecommended, mcpToolEffectMetaKey, mcpToolOutcomeMetaKey, mcpToolOutcomeRejected, mcpToolOutcomeUnknown, } from "./mcp-dex-conventions.js";
|
|
8
9
|
export { mcpGetPromptToolName, mcpListResourcesAndPromptsToolName, mcpReadResourceToolName, } from "./mcp-resource-and-prompt-tools.js";
|
|
9
10
|
export { McpToolCallInterruptedError, McpToolListingError, McpToolSource, defaultMcpConnectionAttempts, defaultMcpConnectionTimeoutMs, defaultMcpListingFailureBackoffMs, defaultMcpListingTtlMs, defaultMcpRequestTimeoutMs, defaultMcpSourceName, defaultMcpTaskTtlMs, defaultMcpTaskWaitTimeoutMs, mcpIdempotencyKeyMetaKey, mcpTaskStatusEventType, mcpToolProgressEventType, } from "./mcp-tool-source.js";
|
|
10
11
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/mcp/index.ts"],"names":[],"mappings":"AAAA,yCAAyC;AACzC,EAAE;AACF,kDAAkD;AAClD,mEAAmE;AACnE,+CAA+C;AAC/C,EAAE;AACF,0DAA0D;AAO1D,OAAO,EACL,oBAAoB,EACpB,kCAAkC,EAClC,uBAAuB,GACxB,MAAM,oCAAoC,CAAC;AAC5C,OAAO,EACL,2BAA2B,EAC3B,mBAAmB,EACnB,aAAa,EACb,4BAA4B,EAC5B,6BAA6B,EAC7B,iCAAiC,EACjC,sBAAsB,EACtB,0BAA0B,EAC1B,oBAAoB,EACpB,mBAAmB,EACnB,2BAA2B,EAC3B,wBAAwB,EACxB,sBAAsB,EACtB,wBAAwB,GAKzB,MAAM,sBAAsB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/mcp/index.ts"],"names":[],"mappings":"AAAA,yCAAyC;AACzC,EAAE;AACF,kDAAkD;AAClD,mEAAmE;AACnE,+CAA+C;AAC/C,EAAE;AACF,0DAA0D;AAO1D,OAAO,EACL,sBAAsB,EACtB,0BAA0B,EAC1B,oBAAoB,EACpB,qBAAqB,EACrB,sBAAsB,EACtB,qBAAqB,GACtB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EACL,oBAAoB,EACpB,kCAAkC,EAClC,uBAAuB,GACxB,MAAM,oCAAoC,CAAC;AAC5C,OAAO,EACL,2BAA2B,EAC3B,mBAAmB,EACnB,aAAa,EACb,4BAA4B,EAC5B,6BAA6B,EAC7B,iCAAiC,EACjC,sBAAsB,EACtB,0BAA0B,EAC1B,oBAAoB,EACpB,mBAAmB,EACnB,2BAA2B,EAC3B,wBAAwB,EACxB,sBAAsB,EACtB,wBAAwB,GAKzB,MAAM,sBAAsB,CAAC"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import type { ToolEffect } from "../agent-session-values.js";
|
|
2
|
+
/**
|
|
3
|
+
* Tool definition `_meta` key that declares the tool's effect class.
|
|
4
|
+
*
|
|
5
|
+
* Its value is `"read"`, `"idempotent_write"`, or `"non_idempotent_write"`. See the package README,
|
|
6
|
+
* "Dex MCP conventions".
|
|
7
|
+
* @since 0.5.0
|
|
8
|
+
*/
|
|
9
|
+
export declare const mcpToolEffectMetaKey = "io.superdurable.dex/effect";
|
|
10
|
+
/**
|
|
11
|
+
* Tool definition `_meta` key that recommends approval of every call.
|
|
12
|
+
*
|
|
13
|
+
* Its only value is {@link mcpToolApprovalRecommended}. It applies only together with
|
|
14
|
+
* {@link mcpToolEffectMetaKey}.
|
|
15
|
+
* @since 0.5.0
|
|
16
|
+
*/
|
|
17
|
+
export declare const mcpToolApprovalMetaKey = "io.superdurable.dex/approval";
|
|
18
|
+
/**
|
|
19
|
+
* Tool result `_meta` key, or JSON-RPC `error.data._meta` key, that reports the call's outcome.
|
|
20
|
+
*
|
|
21
|
+
* Its value is {@link mcpToolOutcomeUnknown} or {@link mcpToolOutcomeRejected}.
|
|
22
|
+
* @since 0.5.0
|
|
23
|
+
*/
|
|
24
|
+
export declare const mcpToolOutcomeMetaKey = "io.superdurable.dex/outcome";
|
|
25
|
+
/**
|
|
26
|
+
* {@link mcpToolApprovalMetaKey} value: a person approves each call by default.
|
|
27
|
+
* @since 0.5.0
|
|
28
|
+
*/
|
|
29
|
+
export declare const mcpToolApprovalRecommended = "recommended";
|
|
30
|
+
/**
|
|
31
|
+
* {@link mcpToolOutcomeMetaKey} value: the call may or may not have taken effect.
|
|
32
|
+
*
|
|
33
|
+
* The session records `outcome_unknown` and never sends the call again.
|
|
34
|
+
* @since 0.5.0
|
|
35
|
+
*/
|
|
36
|
+
export declare const mcpToolOutcomeUnknown = "unknown";
|
|
37
|
+
/**
|
|
38
|
+
* {@link mcpToolOutcomeMetaKey} value: the call definitely did not take effect.
|
|
39
|
+
*
|
|
40
|
+
* The session records `failed` with the result's text.
|
|
41
|
+
* @since 0.5.0
|
|
42
|
+
*/
|
|
43
|
+
export declare const mcpToolOutcomeRejected = "rejected";
|
|
44
|
+
export declare const unknownOutcomeFallbackMessage = "the MCP server could not tell whether the tool took effect";
|
|
45
|
+
export declare const rejectedOutcomeFallbackMessage = "the MCP server rejected the call, so it did not take effect";
|
|
46
|
+
/** What a tool definition's Dex `_meta` keys declare; `effect` is `undefined` for a value outside the convention. */
|
|
47
|
+
export interface DexToolDeclaration {
|
|
48
|
+
readonly effect: ToolEffect | undefined;
|
|
49
|
+
readonly isApprovalRecommended: boolean;
|
|
50
|
+
}
|
|
51
|
+
export type DexToolOutcome = "unknown" | "rejected";
|
|
52
|
+
/** Returns the Dex declaration of a tool, or `undefined` when it has no effect key. */
|
|
53
|
+
export declare function readDexToolDeclaration(meta: Readonly<Record<string, unknown>> | undefined, serverName: string, mcpToolName: string): DexToolDeclaration | undefined;
|
|
54
|
+
/** Returns the outcome a result's or an error's `_meta` reports, or `undefined`. */
|
|
55
|
+
export declare function readDexToolOutcome(meta: unknown): DexToolOutcome | undefined;
|
|
56
|
+
/** Returns the outcome a JSON-RPC error's `data._meta` reports, or `undefined`. */
|
|
57
|
+
export declare function readDexErrorOutcome(errorData: unknown): DexToolOutcome | undefined;
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
// Copyright (c) 2026 Super Durable, Inc.
|
|
2
|
+
//
|
|
3
|
+
// Licensed under the Sustainable Use License 1.0.
|
|
4
|
+
// You may not use this file except in compliance with the License.
|
|
5
|
+
// See the LICENSE file in the repository root.
|
|
6
|
+
//
|
|
7
|
+
// SPDX-License-Identifier: LicenseRef-Sustainable-Use-1.0
|
|
8
|
+
/**
|
|
9
|
+
* Tool definition `_meta` key that declares the tool's effect class.
|
|
10
|
+
*
|
|
11
|
+
* Its value is `"read"`, `"idempotent_write"`, or `"non_idempotent_write"`. See the package README,
|
|
12
|
+
* "Dex MCP conventions".
|
|
13
|
+
* @since 0.5.0
|
|
14
|
+
*/
|
|
15
|
+
export const mcpToolEffectMetaKey = "io.superdurable.dex/effect";
|
|
16
|
+
/**
|
|
17
|
+
* Tool definition `_meta` key that recommends approval of every call.
|
|
18
|
+
*
|
|
19
|
+
* Its only value is {@link mcpToolApprovalRecommended}. It applies only together with
|
|
20
|
+
* {@link mcpToolEffectMetaKey}.
|
|
21
|
+
* @since 0.5.0
|
|
22
|
+
*/
|
|
23
|
+
export const mcpToolApprovalMetaKey = "io.superdurable.dex/approval";
|
|
24
|
+
/**
|
|
25
|
+
* Tool result `_meta` key, or JSON-RPC `error.data._meta` key, that reports the call's outcome.
|
|
26
|
+
*
|
|
27
|
+
* Its value is {@link mcpToolOutcomeUnknown} or {@link mcpToolOutcomeRejected}.
|
|
28
|
+
* @since 0.5.0
|
|
29
|
+
*/
|
|
30
|
+
export const mcpToolOutcomeMetaKey = "io.superdurable.dex/outcome";
|
|
31
|
+
/**
|
|
32
|
+
* {@link mcpToolApprovalMetaKey} value: a person approves each call by default.
|
|
33
|
+
* @since 0.5.0
|
|
34
|
+
*/
|
|
35
|
+
export const mcpToolApprovalRecommended = "recommended";
|
|
36
|
+
/**
|
|
37
|
+
* {@link mcpToolOutcomeMetaKey} value: the call may or may not have taken effect.
|
|
38
|
+
*
|
|
39
|
+
* The session records `outcome_unknown` and never sends the call again.
|
|
40
|
+
* @since 0.5.0
|
|
41
|
+
*/
|
|
42
|
+
export const mcpToolOutcomeUnknown = "unknown";
|
|
43
|
+
/**
|
|
44
|
+
* {@link mcpToolOutcomeMetaKey} value: the call definitely did not take effect.
|
|
45
|
+
*
|
|
46
|
+
* The session records `failed` with the result's text.
|
|
47
|
+
* @since 0.5.0
|
|
48
|
+
*/
|
|
49
|
+
export const mcpToolOutcomeRejected = "rejected";
|
|
50
|
+
export const unknownOutcomeFallbackMessage = "the MCP server could not tell whether the tool took effect";
|
|
51
|
+
export const rejectedOutcomeFallbackMessage = "the MCP server rejected the call, so it did not take effect";
|
|
52
|
+
const declarableEffects = new Set(["read", "idempotent_write", "non_idempotent_write"]);
|
|
53
|
+
/** Returns the Dex declaration of a tool, or `undefined` when it has no effect key. */
|
|
54
|
+
export function readDexToolDeclaration(meta, serverName, mcpToolName) {
|
|
55
|
+
if (meta === undefined || !Object.hasOwn(meta, mcpToolEffectMetaKey)) {
|
|
56
|
+
return undefined;
|
|
57
|
+
}
|
|
58
|
+
const effectValue = meta[mcpToolEffectMetaKey];
|
|
59
|
+
if (typeof effectValue !== "string" || !declarableEffects.has(effectValue)) {
|
|
60
|
+
console.warn(`MCP tool ${serverName}/${mcpToolName} declares the unknown effect ${JSON.stringify(effectValue)}; it gets the session's default effect`);
|
|
61
|
+
return { effect: undefined, isApprovalRecommended: false };
|
|
62
|
+
}
|
|
63
|
+
const hasApproval = Object.hasOwn(meta, mcpToolApprovalMetaKey);
|
|
64
|
+
const approval = meta[mcpToolApprovalMetaKey];
|
|
65
|
+
if (hasApproval && approval !== mcpToolApprovalRecommended) {
|
|
66
|
+
// Fail closed: any other approval value, null included, still asks a person.
|
|
67
|
+
console.warn(`MCP tool ${serverName}/${mcpToolName} declares the unknown approval ${JSON.stringify(approval)}; its calls wait for approval`);
|
|
68
|
+
}
|
|
69
|
+
return { effect: effectValue, isApprovalRecommended: hasApproval };
|
|
70
|
+
}
|
|
71
|
+
/** Returns the outcome a result's or an error's `_meta` reports, or `undefined`. */
|
|
72
|
+
export function readDexToolOutcome(meta) {
|
|
73
|
+
if (!isRecord(meta) || !Object.hasOwn(meta, mcpToolOutcomeMetaKey)) {
|
|
74
|
+
return undefined;
|
|
75
|
+
}
|
|
76
|
+
const outcome = meta[mcpToolOutcomeMetaKey];
|
|
77
|
+
if (outcome === mcpToolOutcomeUnknown || outcome === mcpToolOutcomeRejected) {
|
|
78
|
+
return outcome;
|
|
79
|
+
}
|
|
80
|
+
console.warn(`ignored the unknown MCP tool outcome ${JSON.stringify(outcome)}`);
|
|
81
|
+
return undefined;
|
|
82
|
+
}
|
|
83
|
+
/** Returns the outcome a JSON-RPC error's `data._meta` reports, or `undefined`. */
|
|
84
|
+
export function readDexErrorOutcome(errorData) {
|
|
85
|
+
return isRecord(errorData) ? readDexToolOutcome(errorData["_meta"]) : undefined;
|
|
86
|
+
}
|
|
87
|
+
function isRecord(value) {
|
|
88
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
89
|
+
}
|
|
90
|
+
//# sourceMappingURL=mcp-dex-conventions.js.map
|
|
@@ -0,0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C,SAAS,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;AAClF,CAAC;AAED,SAAS,QAAQ,CAAC,KAAc;IAC9B,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;AAC9E,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { CallToolResult } from "@modelcontextprotocol/sdk/types.js";
|
|
2
|
+
import { type ToolExecutionResult } from "../agent-framework-runner.js";
|
|
3
|
+
import { type MediaStore } from "../agent-media.js";
|
|
4
|
+
/** Reports whether a result carries at least one `image` content block. */
|
|
5
|
+
export declare function hasImageContent(result: CallToolResult): boolean;
|
|
6
|
+
/**
|
|
7
|
+
* Renders a failed result's text with `[image <n> omitted]` for each image block.
|
|
8
|
+
*
|
|
9
|
+
* The text becomes the record's `error`, so image bytes never reach session state.
|
|
10
|
+
*/
|
|
11
|
+
export declare function renderToolFailureText(result: CallToolResult): string;
|
|
12
|
+
/**
|
|
13
|
+
* Uploads a successful result's image blocks and returns the tool output with their references.
|
|
14
|
+
*
|
|
15
|
+
* Each image block becomes `[image <n>]` in the output text, `n` counting from 1 in `images` order. The caller
|
|
16
|
+
* passes only a result with image blocks.
|
|
17
|
+
* @throws {ToolExecutionError} When the result has more than {@link maxImagesPerMessage} images, or an image is not
|
|
18
|
+
* valid base64 or not an image the store accepts.
|
|
19
|
+
*/
|
|
20
|
+
export declare function storeToolResultImages(result: CallToolResult, store: MediaStore, toolName: string): Promise<ToolExecutionResult>;
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
// Copyright (c) 2026 Super Durable, Inc.
|
|
2
|
+
//
|
|
3
|
+
// Licensed under the Sustainable Use License 1.0.
|
|
4
|
+
// You may not use this file except in compliance with the License.
|
|
5
|
+
// See the LICENSE file in the repository root.
|
|
6
|
+
//
|
|
7
|
+
// SPDX-License-Identifier: LicenseRef-Sustainable-Use-1.0
|
|
8
|
+
import { ToolExecutionError } from "../agent-framework-runner.js";
|
|
9
|
+
import { ImageValidationError, maxImagesPerMessage } from "../agent-media.js";
|
|
10
|
+
import { serializeToolOutputJson } from "./mcp-resource-and-prompt-tools.js";
|
|
11
|
+
// Canonical padded base64, the same check as the Python core's.
|
|
12
|
+
const base64Pattern = /^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/;
|
|
13
|
+
/** Reports whether a result carries at least one `image` content block. */
|
|
14
|
+
export function hasImageContent(result) {
|
|
15
|
+
return result.content.some((block) => block.type === "image");
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Renders a failed result's text with `[image <n> omitted]` for each image block.
|
|
19
|
+
*
|
|
20
|
+
* The text becomes the record's `error`, so image bytes never reach session state.
|
|
21
|
+
*/
|
|
22
|
+
export function renderToolFailureText(result) {
|
|
23
|
+
let imageCount = 0;
|
|
24
|
+
return result.content
|
|
25
|
+
.map((block) => {
|
|
26
|
+
if (block.type === "text") {
|
|
27
|
+
return block.text;
|
|
28
|
+
}
|
|
29
|
+
if (block.type === "image") {
|
|
30
|
+
imageCount += 1;
|
|
31
|
+
return `[image ${imageCount} omitted]`;
|
|
32
|
+
}
|
|
33
|
+
return serializeToolOutputJson(block);
|
|
34
|
+
})
|
|
35
|
+
.join("\n");
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Uploads a successful result's image blocks and returns the tool output with their references.
|
|
39
|
+
*
|
|
40
|
+
* Each image block becomes `[image <n>]` in the output text, `n` counting from 1 in `images` order. The caller
|
|
41
|
+
* passes only a result with image blocks.
|
|
42
|
+
* @throws {ToolExecutionError} When the result has more than {@link maxImagesPerMessage} images, or an image is not
|
|
43
|
+
* valid base64 or not an image the store accepts.
|
|
44
|
+
*/
|
|
45
|
+
export async function storeToolResultImages(result, store, toolName) {
|
|
46
|
+
const imageCount = result.content.filter((block) => block.type === "image").length;
|
|
47
|
+
if (imageCount > maxImagesPerMessage) {
|
|
48
|
+
throw new ToolExecutionError(`MCP tool ${toolName} returned ${imageCount} images; a tool result carries at most ${maxImagesPerMessage}`);
|
|
49
|
+
}
|
|
50
|
+
const references = [];
|
|
51
|
+
const parts = [];
|
|
52
|
+
for (const block of result.content) {
|
|
53
|
+
if (block.type === "text") {
|
|
54
|
+
parts.push(block.text);
|
|
55
|
+
}
|
|
56
|
+
else if (block.type === "image") {
|
|
57
|
+
references.push(await storeImage(block, store, toolName, references.length + 1));
|
|
58
|
+
parts.push(`[image ${references.length}]`);
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
parts.push(serializeToolOutputJson(block));
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
return { output: parts.join("\n"), images: references };
|
|
65
|
+
}
|
|
66
|
+
async function storeImage(block, store, toolName, imageNumber) {
|
|
67
|
+
const data = typeof block.data === "string" && base64Pattern.test(block.data) ? Buffer.from(block.data, "base64") : undefined;
|
|
68
|
+
// Re-encoding refuses unused trailing bits, so one image has one accepted text.
|
|
69
|
+
if (data === undefined || data.toString("base64") !== block.data) {
|
|
70
|
+
throw new ToolExecutionError(`MCP tool ${toolName} returned image ${imageNumber}, which is not valid base64`);
|
|
71
|
+
}
|
|
72
|
+
try {
|
|
73
|
+
return await store.putImage(new Uint8Array(data));
|
|
74
|
+
}
|
|
75
|
+
catch (error) {
|
|
76
|
+
if (error instanceof ImageValidationError) {
|
|
77
|
+
throw new ToolExecutionError(`MCP tool ${toolName} returned image ${imageNumber}, which is not a supported image: ${error.message}`);
|
|
78
|
+
}
|
|
79
|
+
throw error;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
//# sourceMappingURL=mcp-image-content.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mcp-image-content.js","sourceRoot":"","sources":["../../../src/mcp/mcp-image-content.ts"],"names":[],"mappings":"AAAA,yCAAyC;AACzC,EAAE;AACF,kDA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