@librechat/agents 4.2.12 → 4.2.13
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/cjs/graphs/Graph.cjs +11 -3
- package/dist/cjs/graphs/Graph.cjs.map +1 -1
- package/dist/cjs/llm/anthropic/index.cjs +4 -3
- package/dist/cjs/llm/anthropic/index.cjs.map +1 -1
- package/dist/cjs/llm/anthropic/utils/container.cjs +37 -0
- package/dist/cjs/llm/anthropic/utils/container.cjs.map +1 -0
- package/dist/cjs/llm/anthropic/utils/message_inputs.cjs +25 -23
- package/dist/cjs/llm/anthropic/utils/message_inputs.cjs.map +1 -1
- package/dist/cjs/llm/anthropic/utils/message_outputs.cjs +15 -21
- package/dist/cjs/llm/anthropic/utils/message_outputs.cjs.map +1 -1
- package/dist/cjs/llm/anthropic/utils/stream_events.cjs +16 -14
- package/dist/cjs/llm/anthropic/utils/stream_events.cjs.map +1 -1
- package/dist/cjs/llm/bedrock/index.cjs +1 -1
- package/dist/cjs/llm/bedrock/index.cjs.map +1 -1
- package/dist/cjs/llm/bedrock/toolCache.cjs +1 -1
- package/dist/cjs/llm/bedrock/utils/message_inputs.cjs +19 -13
- package/dist/cjs/llm/bedrock/utils/message_inputs.cjs.map +1 -1
- package/dist/cjs/llm/google/utils/common.cjs +59 -13
- package/dist/cjs/llm/google/utils/common.cjs.map +1 -1
- package/dist/cjs/llm/init.cjs +12 -2
- package/dist/cjs/llm/init.cjs.map +1 -1
- package/dist/cjs/llm/openai/index.cjs +1 -1
- package/dist/cjs/llm/openrouter/toolCache.cjs +1 -1
- package/dist/cjs/llm/prepareProviderRequest.cjs +1 -1
- package/dist/cjs/main.cjs +6 -3
- package/dist/cjs/messages/alternation.cjs +1 -1
- package/dist/cjs/messages/anthropicServerTools.cjs +20 -0
- package/dist/cjs/messages/anthropicServerTools.cjs.map +1 -0
- package/dist/cjs/messages/budget.cjs +1 -1
- package/dist/cjs/messages/core.cjs +3 -2
- package/dist/cjs/messages/core.cjs.map +1 -1
- package/dist/cjs/messages/format.cjs +2 -2
- package/dist/cjs/messages/index.cjs +1 -1
- package/dist/cjs/messages/prune.cjs +1 -1
- package/dist/cjs/messages/recency.cjs +1 -1
- package/dist/cjs/messages/toolResultTypes.cjs +21 -45
- package/dist/cjs/messages/toolResultTypes.cjs.map +1 -1
- package/dist/cjs/protection/providerText.cjs +4 -0
- package/dist/cjs/protection/providerText.cjs.map +1 -1
- package/dist/cjs/protection/toolResult.cjs +119 -0
- package/dist/cjs/protection/toolResult.cjs.map +1 -0
- package/dist/cjs/run.cjs +7 -1
- package/dist/cjs/run.cjs.map +1 -1
- package/dist/cjs/runtime/client.cjs +2 -0
- package/dist/cjs/runtime/client.cjs.map +1 -1
- package/dist/cjs/stream.cjs +1 -0
- package/dist/cjs/stream.cjs.map +1 -1
- package/dist/cjs/summarization/node.cjs +1 -1
- package/dist/cjs/tools/ToolNode.cjs +46 -13
- package/dist/cjs/tools/ToolNode.cjs.map +1 -1
- package/dist/cjs/tools/search/content.cjs +163 -42
- package/dist/cjs/tools/search/content.cjs.map +1 -1
- package/dist/cjs/tools/subagent/SubagentExecutor.cjs +4 -0
- package/dist/cjs/tools/subagent/SubagentExecutor.cjs.map +1 -1
- package/dist/cjs/utils/tokens.cjs +7 -2
- package/dist/cjs/utils/tokens.cjs.map +1 -1
- package/dist/esm/graphs/Graph.mjs +11 -3
- package/dist/esm/graphs/Graph.mjs.map +1 -1
- package/dist/esm/llm/anthropic/index.mjs +4 -3
- package/dist/esm/llm/anthropic/index.mjs.map +1 -1
- package/dist/esm/llm/anthropic/utils/container.mjs +37 -0
- package/dist/esm/llm/anthropic/utils/container.mjs.map +1 -0
- package/dist/esm/llm/anthropic/utils/message_inputs.mjs +25 -23
- package/dist/esm/llm/anthropic/utils/message_inputs.mjs.map +1 -1
- package/dist/esm/llm/anthropic/utils/message_outputs.mjs +15 -21
- package/dist/esm/llm/anthropic/utils/message_outputs.mjs.map +1 -1
- package/dist/esm/llm/anthropic/utils/stream_events.mjs +16 -14
- package/dist/esm/llm/anthropic/utils/stream_events.mjs.map +1 -1
- package/dist/esm/llm/bedrock/index.mjs +2 -2
- package/dist/esm/llm/bedrock/index.mjs.map +1 -1
- package/dist/esm/llm/bedrock/toolCache.mjs +1 -1
- package/dist/esm/llm/bedrock/utils/message_inputs.mjs +19 -14
- package/dist/esm/llm/bedrock/utils/message_inputs.mjs.map +1 -1
- package/dist/esm/llm/google/utils/common.mjs +59 -13
- package/dist/esm/llm/google/utils/common.mjs.map +1 -1
- package/dist/esm/llm/init.mjs +12 -2
- package/dist/esm/llm/init.mjs.map +1 -1
- package/dist/esm/llm/openai/index.mjs +1 -1
- package/dist/esm/llm/openrouter/toolCache.mjs +1 -1
- package/dist/esm/llm/prepareProviderRequest.mjs +1 -1
- package/dist/esm/main.mjs +5 -4
- package/dist/esm/messages/alternation.mjs +1 -1
- package/dist/esm/messages/anthropicServerTools.mjs +18 -0
- package/dist/esm/messages/anthropicServerTools.mjs.map +1 -0
- package/dist/esm/messages/budget.mjs +1 -1
- package/dist/esm/messages/core.mjs +3 -2
- package/dist/esm/messages/core.mjs.map +1 -1
- package/dist/esm/messages/format.mjs +2 -2
- package/dist/esm/messages/index.mjs +1 -1
- package/dist/esm/messages/prune.mjs +1 -1
- package/dist/esm/messages/recency.mjs +1 -1
- package/dist/esm/messages/toolResultTypes.mjs +21 -45
- package/dist/esm/messages/toolResultTypes.mjs.map +1 -1
- package/dist/esm/protection/providerText.mjs +4 -1
- package/dist/esm/protection/providerText.mjs.map +1 -1
- package/dist/esm/protection/toolResult.mjs +114 -0
- package/dist/esm/protection/toolResult.mjs.map +1 -0
- package/dist/esm/run.mjs +7 -1
- package/dist/esm/run.mjs.map +1 -1
- package/dist/esm/runtime/client.mjs +2 -0
- package/dist/esm/runtime/client.mjs.map +1 -1
- package/dist/esm/stream.mjs +1 -0
- package/dist/esm/stream.mjs.map +1 -1
- package/dist/esm/summarization/node.mjs +1 -1
- package/dist/esm/tools/ToolNode.mjs +46 -13
- package/dist/esm/tools/ToolNode.mjs.map +1 -1
- package/dist/esm/tools/search/content.mjs +163 -42
- package/dist/esm/tools/search/content.mjs.map +1 -1
- package/dist/esm/tools/subagent/SubagentExecutor.mjs +4 -0
- package/dist/esm/tools/subagent/SubagentExecutor.mjs.map +1 -1
- package/dist/esm/utils/tokens.mjs +7 -2
- package/dist/esm/utils/tokens.mjs.map +1 -1
- package/dist/types/common/index.d.ts +2 -2
- package/dist/types/decisions/breaker.d.ts +2 -2
- package/dist/types/decisions/core.d.ts +13 -13
- package/dist/types/decisions/dialect.d.ts +1 -1
- package/dist/types/decisions/http.d.ts +2 -2
- package/dist/types/decisions/index.d.ts +5 -5
- package/dist/types/decisions/node.d.ts +2 -2
- package/dist/types/decisions/presets.d.ts +2 -2
- package/dist/types/decisions/probe.d.ts +1 -1
- package/dist/types/decisions/questions.d.ts +1 -1
- package/dist/types/decisions/structuredChat.d.ts +2 -2
- package/dist/types/decisions/transport.d.ts +1 -1
- package/dist/types/eventActor/EventActorExecutor.d.ts +1 -1
- package/dist/types/eventActor/index.d.ts +2 -2
- package/dist/types/graphs/Graph.d.ts +4 -2
- package/dist/types/graphs/MultiAgentGraph.d.ts +1 -1
- package/dist/types/graphs/applyGraphRuntimeConfig.d.ts +1 -1
- package/dist/types/graphs/graphFactory.d.ts +1 -1
- package/dist/types/graphs/index.d.ts +5 -5
- package/dist/types/harness/fileBindings.d.ts +2 -2
- package/dist/types/harness/fileService.d.ts +2 -2
- package/dist/types/harness/fileStream.d.ts +1 -1
- package/dist/types/harness/index.d.ts +15 -15
- package/dist/types/harness/model.d.ts +1 -1
- package/dist/types/harness/modelService.d.ts +2 -2
- package/dist/types/harness/modelStreamCallbacks.d.ts +1 -1
- package/dist/types/harness/providerText.d.ts +1 -1
- package/dist/types/hitl/index.d.ts +3 -3
- package/dist/types/hooks/HookRegistry.d.ts +1 -1
- package/dist/types/hooks/createToolPolicyHook.d.ts +1 -1
- package/dist/types/hooks/createWorkspacePolicyHook.d.ts +1 -1
- package/dist/types/hooks/executeHooks.d.ts +2 -2
- package/dist/types/hooks/index.d.ts +11 -11
- package/dist/types/index.d.ts +62 -60
- package/dist/types/langchain/index.d.ts +8 -8
- package/dist/types/llm/anthropic/utils/container.d.ts +4 -0
- package/dist/types/llm/anthropic/utils/message_inputs.d.ts +1 -1
- package/dist/types/llm/anthropic/utils/message_outputs.d.ts +1 -1
- package/dist/types/llm/anthropic/utils/stream_events.d.ts +1 -1
- package/dist/types/llm/bedrock/index.d.ts +2 -3
- package/dist/types/llm/bedrock/utils/harmony.d.ts +1 -1
- package/dist/types/llm/bedrock/utils/index.d.ts +2 -2
- package/dist/types/llm/bedrock/utils/message_inputs.d.ts +3 -12
- package/dist/types/llm/bedrock/utils/message_outputs.d.ts +1 -1
- package/dist/types/llm/google/index.d.ts +2 -2
- package/dist/types/llm/google/utils/common.d.ts +1 -1
- package/dist/types/llm/google/utils/tools.d.ts +1 -1
- package/dist/types/llm/openai/index.d.ts +1 -1
- package/dist/types/llm/providerRegistry.d.ts +1 -1
- package/dist/types/llm/providers.d.ts +1 -1
- package/dist/types/messages/anthropicServerTools.d.ts +13 -0
- package/dist/types/messages/contextPruning.d.ts +1 -1
- package/dist/types/messages/core.d.ts +4 -4
- package/dist/types/messages/format.d.ts +1 -1
- package/dist/types/messages/index.d.ts +21 -21
- package/dist/types/messages/prune.d.ts +1 -1
- package/dist/types/openai/index.d.ts +2 -2
- package/dist/types/openai/toolProjection.d.ts +1 -1
- package/dist/types/prompts/index.d.ts +2 -2
- package/dist/types/protection/providerText.d.ts +3 -1
- package/dist/types/protection/toolResult.d.ts +69 -0
- package/dist/types/provider-registration.d.ts +1 -1
- package/dist/types/rerank/bm25.d.ts +1 -1
- package/dist/types/rerank/core.d.ts +17 -17
- package/dist/types/rerank/crossEncoder.d.ts +3 -3
- package/dist/types/rerank/fallback.d.ts +1 -1
- package/dist/types/rerank/index.d.ts +2 -2
- package/dist/types/rerank/outcome.d.ts +2 -2
- package/dist/types/rerank/pin.d.ts +2 -2
- package/dist/types/rerank/search.d.ts +1 -1
- package/dist/types/rerank/systemone.d.ts +4 -4
- package/dist/types/rerank/types.d.ts +1 -1
- package/dist/types/run.d.ts +1 -0
- package/dist/types/runtime/admission.d.ts +1 -1
- package/dist/types/runtime/checkpoint.d.ts +1 -1
- package/dist/types/runtime/client.d.ts +2 -2
- package/dist/types/runtime/files.d.ts +3 -3
- package/dist/types/runtime/hostTools.d.ts +2 -2
- package/dist/types/runtime/index.d.ts +12 -12
- package/dist/types/runtime/model.d.ts +5 -5
- package/dist/types/runtime/policy.d.ts +3 -3
- package/dist/types/runtime/recovery/client.d.ts +3 -3
- package/dist/types/runtime/recovery/log.d.ts +2 -2
- package/dist/types/runtime/recovery/redis.d.ts +1 -1
- package/dist/types/runtime/recovery/server.d.ts +3 -3
- package/dist/types/runtime/resume.d.ts +1 -1
- package/dist/types/runtime/server.d.ts +3 -3
- package/dist/types/runtime/snapshot.d.ts +1 -1
- package/dist/types/runtime/types.d.ts +2 -2
- package/dist/types/session/AgentSession.d.ts +2 -2
- package/dist/types/session/JsonlSessionStore.d.ts +1 -1
- package/dist/types/session/deriveMessages.d.ts +1 -1
- package/dist/types/session/handlers.d.ts +1 -1
- package/dist/types/session/index.d.ts +7 -7
- package/dist/types/session/messageSerialization.d.ts +1 -1
- package/dist/types/session/sessionProjection.d.ts +3 -3
- package/dist/types/summarization/index.d.ts +2 -2
- package/dist/types/tools/BashProgrammaticToolCalling.d.ts +1 -1
- package/dist/types/tools/GitHubCompare.d.ts +6 -6
- package/dist/types/tools/ProgrammaticToolCalling.d.ts +1 -1
- package/dist/types/tools/ReadFile.d.ts +6 -6
- package/dist/types/tools/SkillTool.d.ts +6 -6
- package/dist/types/tools/ToolNode.d.ts +5 -1
- package/dist/types/tools/cloudflare/index.d.ts +4 -4
- package/dist/types/tools/local/FileCheckpointer.d.ts +1 -1
- package/dist/types/tools/local/LocalExecutionEngine.d.ts +1 -1
- package/dist/types/tools/local/attachments.d.ts +1 -1
- package/dist/types/tools/local/index.d.ts +12 -12
- package/dist/types/tools/search/anthropic.d.ts +1 -1
- package/dist/types/tools/search/content.d.ts +38 -1
- package/dist/types/tools/search/crw-scraper.d.ts +1 -1
- package/dist/types/tools/search/crw-search.d.ts +1 -1
- package/dist/types/tools/search/firecrawl.d.ts +1 -1
- package/dist/types/tools/search/format.d.ts +1 -1
- package/dist/types/tools/search/highlights.d.ts +1 -1
- package/dist/types/tools/search/index.d.ts +3 -3
- package/dist/types/tools/search/keenable-scraper.d.ts +1 -1
- package/dist/types/tools/search/keenable-search.d.ts +1 -1
- package/dist/types/tools/search/metrics.d.ts +1 -1
- package/dist/types/tools/search/rerankers.d.ts +1 -1
- package/dist/types/tools/search/schema.d.ts +6 -6
- package/dist/types/tools/search/search.d.ts +1 -1
- package/dist/types/tools/search/serper-scraper.d.ts +1 -1
- package/dist/types/tools/search/tavily-scraper.d.ts +1 -1
- package/dist/types/tools/search/tavily-search.d.ts +1 -1
- package/dist/types/tools/search/tool.d.ts +3 -3
- package/dist/types/tools/search/types.d.ts +2 -2
- package/dist/types/tools/search/utils.d.ts +3 -3
- package/dist/types/tools/subagent/SubagentExecutionRegistry.d.ts +1 -1
- package/dist/types/tools/subagent/SubagentExecutor.d.ts +6 -3
- package/dist/types/tools/subagent/diagnostics.d.ts +1 -1
- package/dist/types/tools/subagent/index.d.ts +7 -7
- package/dist/types/types/attachments.d.ts +1 -1
- package/dist/types/types/graph.d.ts +4 -1
- package/dist/types/types/index.d.ts +14 -14
- package/dist/types/types/llm.d.ts +2 -2
- package/dist/types/types/run.d.ts +3 -1
- package/dist/types/types/subagentTasks.d.ts +2 -2
- package/dist/types/types/tools.d.ts +6 -3
- package/dist/types/utils/index.d.ts +10 -10
- package/dist/types/utils/tokens.d.ts +1 -0
- package/package.json +3 -2
- package/src/graphs/Graph.ts +22 -0
- package/src/index.ts +8 -0
- package/src/llm/anthropic/index.ts +11 -3
- package/src/llm/anthropic/utils/container.ts +63 -0
- package/src/llm/anthropic/utils/message_inputs.ts +57 -51
- package/src/llm/anthropic/utils/message_outputs.ts +12 -39
- package/src/llm/anthropic/utils/stream_events.ts +17 -12
- package/src/llm/bedrock/index.ts +7 -5
- package/src/llm/bedrock/utils/message_inputs.ts +28 -35
- package/src/llm/google/utils/common.ts +88 -36
- package/src/llm/init.ts +35 -3
- package/src/messages/anthropicServerTools.ts +24 -0
- package/src/messages/core.ts +12 -11
- package/src/messages/toolResultTypes.ts +80 -88
- package/src/protection/providerText.ts +127 -40
- package/src/protection/toolResult.ts +272 -0
- package/src/run.ts +15 -4
- package/src/runtime/client.ts +3 -0
- package/src/stream.ts +5 -0
- package/src/tools/ToolNode.ts +112 -17
- package/src/tools/search/content.ts +282 -62
- package/src/tools/subagent/SubagentExecutor.ts +6 -0
- package/src/types/graph.ts +3 -0
- package/src/types/run.ts +3 -0
- package/src/types/tools.ts +3 -0
- package/src/utils/tokens.ts +28 -2
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import { performance } from 'node:perf_hooks';
|
|
2
|
-
import type {
|
|
2
|
+
import type {
|
|
3
|
+
ProviderTextAdmission,
|
|
4
|
+
ProviderTextAdmissionLease,
|
|
5
|
+
} from './providerTextAdmission';
|
|
3
6
|
import { PreparedSubagentError } from '@/tools/preparedSubagents';
|
|
4
7
|
import { StreamLimitExceededError } from '@/llm/streamLimits';
|
|
5
8
|
|
|
@@ -72,14 +75,28 @@ export function createProviderTextRestartCancellation(): ProviderTextProtectionE
|
|
|
72
75
|
}
|
|
73
76
|
|
|
74
77
|
export function isProviderTextRestartCancellation(error: unknown): boolean {
|
|
75
|
-
return
|
|
78
|
+
return (
|
|
79
|
+
error instanceof ProviderTextProtectionError &&
|
|
80
|
+
restartCancellations.has(error)
|
|
81
|
+
);
|
|
76
82
|
}
|
|
77
83
|
|
|
78
|
-
function protectionAbortError(
|
|
84
|
+
function protectionAbortError(
|
|
85
|
+
parent?: AbortSignal
|
|
86
|
+
):
|
|
87
|
+
| ProviderTextProtectionError
|
|
88
|
+
| StreamLimitExceededError
|
|
89
|
+
| PreparedSubagentError {
|
|
79
90
|
const reason: unknown = parent?.reason;
|
|
80
|
-
if (
|
|
91
|
+
if (
|
|
92
|
+
reason instanceof StreamLimitExceededError ||
|
|
93
|
+
reason instanceof PreparedSubagentError
|
|
94
|
+
)
|
|
95
|
+
return reason;
|
|
81
96
|
if (reason instanceof ProviderTextProtectionError) {
|
|
82
|
-
return isProviderTextRestartCancellation(reason)
|
|
97
|
+
return isProviderTextRestartCancellation(reason)
|
|
98
|
+
? reason
|
|
99
|
+
: new ProviderTextProtectionError(reason.code);
|
|
83
100
|
}
|
|
84
101
|
return new ProviderTextProtectionError('cancelled');
|
|
85
102
|
}
|
|
@@ -102,19 +119,34 @@ const errorCodes = new Set<ProviderTextProtectionErrorCode>([
|
|
|
102
119
|
'incompatible',
|
|
103
120
|
]);
|
|
104
121
|
|
|
105
|
-
export type ProviderTextProtectionFailure = Extract<
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
122
|
+
export type ProviderTextProtectionFailure = Extract<
|
|
123
|
+
ProviderTextProtectionResult,
|
|
124
|
+
{ ok: false }
|
|
125
|
+
>;
|
|
126
|
+
|
|
127
|
+
function isProtectionErrorCode(
|
|
128
|
+
code: unknown
|
|
129
|
+
): code is ProviderTextProtectionErrorCode {
|
|
130
|
+
return (
|
|
131
|
+
typeof code === 'string' && (errorCodes as ReadonlySet<string>).has(code)
|
|
132
|
+
);
|
|
109
133
|
}
|
|
110
134
|
|
|
111
135
|
/** Safe wire failure, including errors raised by a separate CJS/ESM copy of the SDK. */
|
|
112
|
-
export function serializeProviderTextProtectionError(
|
|
136
|
+
export function serializeProviderTextProtectionError(
|
|
137
|
+
error: unknown
|
|
138
|
+
): ProviderTextProtectionFailure {
|
|
113
139
|
let code: ProviderTextProtectionErrorCode = 'unavailable';
|
|
114
140
|
try {
|
|
115
|
-
if (
|
|
116
|
-
|
|
117
|
-
|
|
141
|
+
if (
|
|
142
|
+
error != null &&
|
|
143
|
+
typeof error === 'object' &&
|
|
144
|
+
'name' in error &&
|
|
145
|
+
error.name === 'ProviderTextProtectionError' &&
|
|
146
|
+
'code' in error &&
|
|
147
|
+
isProtectionErrorCode(error.code)
|
|
148
|
+
)
|
|
149
|
+
code = error.code;
|
|
118
150
|
} catch {
|
|
119
151
|
// Never serialize arbitrary exception messages, stacks, causes, or getters.
|
|
120
152
|
}
|
|
@@ -122,13 +154,23 @@ export function serializeProviderTextProtectionError(error: unknown): ProviderTe
|
|
|
122
154
|
}
|
|
123
155
|
|
|
124
156
|
/** Decode only an authenticated host's failure envelope; unknown versions/codes fail closed. */
|
|
125
|
-
export function deserializeProviderTextProtectionError(
|
|
157
|
+
export function deserializeProviderTextProtectionError(
|
|
158
|
+
failure: unknown
|
|
159
|
+
): ProviderTextProtectionError {
|
|
126
160
|
try {
|
|
127
|
-
if (
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
161
|
+
if (
|
|
162
|
+
failure != null &&
|
|
163
|
+
typeof failure === 'object' &&
|
|
164
|
+
'version' in failure &&
|
|
165
|
+
failure.version === 1 &&
|
|
166
|
+
'ok' in failure &&
|
|
167
|
+
failure.ok === false &&
|
|
168
|
+
'error' in failure &&
|
|
169
|
+
failure.error != null &&
|
|
170
|
+
typeof failure.error === 'object' &&
|
|
171
|
+
'code' in failure.error &&
|
|
172
|
+
isProtectionErrorCode(failure.error.code)
|
|
173
|
+
) {
|
|
132
174
|
return new ProviderTextProtectionError(failure.error.code);
|
|
133
175
|
}
|
|
134
176
|
} catch {
|
|
@@ -138,7 +180,11 @@ export function deserializeProviderTextProtectionError(failure: unknown): Provid
|
|
|
138
180
|
}
|
|
139
181
|
|
|
140
182
|
export function validateProviderTextTimeout(timeoutMs: number): void {
|
|
141
|
-
if (
|
|
183
|
+
if (
|
|
184
|
+
!Number.isSafeInteger(timeoutMs) ||
|
|
185
|
+
timeoutMs <= 0 ||
|
|
186
|
+
timeoutMs > 2_147_483_647
|
|
187
|
+
)
|
|
142
188
|
throw new ProviderTextProtectionError('incompatible');
|
|
143
189
|
}
|
|
144
190
|
|
|
@@ -146,8 +192,7 @@ export function validateProviderTextProtection(
|
|
|
146
192
|
policy: ProviderTextProtection
|
|
147
193
|
): void {
|
|
148
194
|
const version: number = policy.version;
|
|
149
|
-
if (version !== 1)
|
|
150
|
-
throw new ProviderTextProtectionError('incompatible');
|
|
195
|
+
if (version !== 1) throw new ProviderTextProtectionError('incompatible');
|
|
151
196
|
if (
|
|
152
197
|
typeof policy.inspect !== 'function' ||
|
|
153
198
|
typeof policy.classify !== 'function'
|
|
@@ -209,9 +254,12 @@ export class ProviderTextAttempt {
|
|
|
209
254
|
this.charge(512);
|
|
210
255
|
parent?.addEventListener('abort', this.abort, { once: true });
|
|
211
256
|
this.check();
|
|
212
|
-
this.timer = setTimeout(
|
|
213
|
-
|
|
214
|
-
|
|
257
|
+
this.timer = setTimeout(
|
|
258
|
+
() => {
|
|
259
|
+
this.controller.abort(new ProviderTextProtectionError('timeout'));
|
|
260
|
+
},
|
|
261
|
+
Math.min(timeoutMs, policy.timeoutMs)
|
|
262
|
+
);
|
|
215
263
|
this.timer.unref();
|
|
216
264
|
protectedSignals.add(this.signal);
|
|
217
265
|
} catch (error) {
|
|
@@ -223,7 +271,12 @@ export class ProviderTextAttempt {
|
|
|
223
271
|
} catch {
|
|
224
272
|
// Malformed transport signals must not prevent admission rollback.
|
|
225
273
|
}
|
|
226
|
-
if (
|
|
274
|
+
if (
|
|
275
|
+
error instanceof ProviderTextProtectionError ||
|
|
276
|
+
error instanceof StreamLimitExceededError ||
|
|
277
|
+
error instanceof PreparedSubagentError
|
|
278
|
+
)
|
|
279
|
+
throw error;
|
|
227
280
|
throw new ProviderTextProtectionError('incompatible');
|
|
228
281
|
}
|
|
229
282
|
}
|
|
@@ -235,8 +288,7 @@ export class ProviderTextAttempt {
|
|
|
235
288
|
check(): void {
|
|
236
289
|
if (this.finished) throw new ProviderTextProtectionError('incompatible');
|
|
237
290
|
if (this.signal.aborted) throw this.signal.reason;
|
|
238
|
-
if (this.parent?.aborted === true)
|
|
239
|
-
throw protectionAbortError(this.parent);
|
|
291
|
+
if (this.parent?.aborted === true) throw protectionAbortError(this.parent);
|
|
240
292
|
if (performance.now() >= this.deadline) {
|
|
241
293
|
this.controller.abort(new ProviderTextProtectionError('timeout'));
|
|
242
294
|
throw this.signal.reason;
|
|
@@ -263,7 +315,8 @@ export class ProviderTextAttempt {
|
|
|
263
315
|
|
|
264
316
|
append(text: string, cumulativeReplay = false): void {
|
|
265
317
|
this.check();
|
|
266
|
-
if (cumulativeReplay && this.hasCandidatePrefix(text))
|
|
318
|
+
if (cumulativeReplay && this.hasCandidatePrefix(text))
|
|
319
|
+
text = text.slice(this.textLength);
|
|
267
320
|
if (!text) return;
|
|
268
321
|
const bytes = text.length * 2;
|
|
269
322
|
this.charge(bytes * 2 + 64);
|
|
@@ -283,7 +336,10 @@ export class ProviderTextAttempt {
|
|
|
283
336
|
}
|
|
284
337
|
|
|
285
338
|
matchesText(text: string): boolean {
|
|
286
|
-
return
|
|
339
|
+
return (
|
|
340
|
+
text.length === this.textLength &&
|
|
341
|
+
(text.length === 0 || this.hasCandidatePrefix(text))
|
|
342
|
+
);
|
|
287
343
|
}
|
|
288
344
|
|
|
289
345
|
retain(bytes: number): void {
|
|
@@ -310,8 +366,14 @@ export class ProviderTextAttempt {
|
|
|
310
366
|
this.pending.delete(work);
|
|
311
367
|
};
|
|
312
368
|
void work.then(
|
|
313
|
-
(value) => {
|
|
314
|
-
|
|
369
|
+
(value) => {
|
|
370
|
+
settle();
|
|
371
|
+
resolve(value);
|
|
372
|
+
},
|
|
373
|
+
(error: Error) => {
|
|
374
|
+
settle();
|
|
375
|
+
reject(error);
|
|
376
|
+
}
|
|
315
377
|
);
|
|
316
378
|
});
|
|
317
379
|
}
|
|
@@ -340,7 +402,9 @@ export class ProviderTextAttempt {
|
|
|
340
402
|
} catch (error) {
|
|
341
403
|
this.check();
|
|
342
404
|
if (isProviderTextRestartCancellation(error)) throw error;
|
|
343
|
-
throw deserializeProviderTextProtectionError(
|
|
405
|
+
throw deserializeProviderTextProtectionError(
|
|
406
|
+
serializeProviderTextProtectionError(error)
|
|
407
|
+
);
|
|
344
408
|
}
|
|
345
409
|
this.check();
|
|
346
410
|
const canonical = validateResult(result);
|
|
@@ -375,10 +439,21 @@ export class ProviderTextAttempt {
|
|
|
375
439
|
interface UncheckedResult {
|
|
376
440
|
version?: number;
|
|
377
441
|
ok?: boolean;
|
|
378
|
-
value?: {
|
|
442
|
+
value?: {
|
|
443
|
+
content?: string;
|
|
444
|
+
replacements?: number;
|
|
445
|
+
categories?: readonly { category?: string; count?: number }[];
|
|
446
|
+
};
|
|
379
447
|
error?: { code?: ProviderTextProtectionErrorCode };
|
|
380
448
|
}
|
|
381
449
|
|
|
450
|
+
/** Returns the canonical text of a host inspection result, or throws its failure code. */
|
|
451
|
+
export function readProviderTextResult(
|
|
452
|
+
result: ProviderTextProtectionResult
|
|
453
|
+
): string {
|
|
454
|
+
return validateResult(result);
|
|
455
|
+
}
|
|
456
|
+
|
|
382
457
|
function validateResult(result: UncheckedResult | undefined): string {
|
|
383
458
|
try {
|
|
384
459
|
if (result?.version !== 1 || typeof result.ok !== 'boolean') {
|
|
@@ -386,14 +461,26 @@ function validateResult(result: UncheckedResult | undefined): string {
|
|
|
386
461
|
}
|
|
387
462
|
if (!result.ok) {
|
|
388
463
|
const code = result.error?.code;
|
|
389
|
-
throw new ProviderTextProtectionError(
|
|
464
|
+
throw new ProviderTextProtectionError(
|
|
465
|
+
code != null && errorCodes.has(code) ? code : 'incompatible'
|
|
466
|
+
);
|
|
390
467
|
}
|
|
391
468
|
const value = result.value;
|
|
392
|
-
if (
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
469
|
+
if (
|
|
470
|
+
typeof value?.content !== 'string' ||
|
|
471
|
+
typeof value.replacements !== 'number' ||
|
|
472
|
+
!Number.isSafeInteger(value.replacements) ||
|
|
473
|
+
value.replacements < 0 ||
|
|
474
|
+
!Array.isArray(value.categories) ||
|
|
475
|
+
value.categories.length > 32 ||
|
|
476
|
+
value.categories.some(
|
|
477
|
+
(entry) =>
|
|
478
|
+
typeof entry.category !== 'string' ||
|
|
479
|
+
typeof entry.count !== 'number' ||
|
|
480
|
+
!Number.isSafeInteger(entry.count) ||
|
|
481
|
+
entry.count <= 0
|
|
482
|
+
)
|
|
483
|
+
) {
|
|
397
484
|
throw new ProviderTextProtectionError('incompatible');
|
|
398
485
|
}
|
|
399
486
|
return value.content;
|
|
@@ -0,0 +1,272 @@
|
|
|
1
|
+
import { ToolMessage } from '@langchain/core/messages';
|
|
2
|
+
import type {
|
|
3
|
+
ProviderTextProtection,
|
|
4
|
+
ProviderTextProtectionResult,
|
|
5
|
+
ProviderTextProtectionErrorCode,
|
|
6
|
+
} from './providerText';
|
|
7
|
+
import type { ToolExecuteResult } from '@/types/tools';
|
|
8
|
+
import {
|
|
9
|
+
ProviderTextAttempt,
|
|
10
|
+
readProviderTextResult,
|
|
11
|
+
ProviderTextProtectionError,
|
|
12
|
+
validateProviderTextProtection,
|
|
13
|
+
} from './providerText';
|
|
14
|
+
import { PreparedSubagentError } from '@/tools/preparedSubagents';
|
|
15
|
+
import { cloneToolMessageWithContent } from '@/utils/toolContent';
|
|
16
|
+
import { StreamLimitExceededError } from '@/llm/streamLimits';
|
|
17
|
+
|
|
18
|
+
export const TOOL_RESULT_PROTECTION_VERSION = 1;
|
|
19
|
+
|
|
20
|
+
export type ToolResultProtectionResult = ProviderTextProtectionResult;
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Host inspection of the text returned by selected tools. Default off.
|
|
24
|
+
*
|
|
25
|
+
* The SDK calls `inspect` on a selected tool's text before anything else reads
|
|
26
|
+
* it: hooks, completion events, the output reference registry, checkpoints and
|
|
27
|
+
* the model all receive the inspected text. A failed inspection ends the run
|
|
28
|
+
* with a {@link ToolResultProtectionError}.
|
|
29
|
+
*
|
|
30
|
+
* Trust boundary: the tool's text is untrusted data; code running in the host
|
|
31
|
+
* process is trusted. Tools, hooks, event handlers, callbacks and checkpoint
|
|
32
|
+
* savers are not defended against, text they author is not inspected, and
|
|
33
|
+
* history the host supplies is the host's to have inspected. Tracing observes
|
|
34
|
+
* a selected tool's raw result; redact those tools with the tracing
|
|
35
|
+
* configuration.
|
|
36
|
+
*
|
|
37
|
+
* Selected tools must return plain text. A structured result, an artifact or a
|
|
38
|
+
* `Command` fails as `unsupported`. Selected tools are not offered to
|
|
39
|
+
* programmatic tool calling, are not started eagerly, and cannot be client
|
|
40
|
+
* delegated. Unselected tools are untouched.
|
|
41
|
+
*/
|
|
42
|
+
export interface ToolResultProtection {
|
|
43
|
+
readonly version: 1;
|
|
44
|
+
readonly toolNames: readonly string[];
|
|
45
|
+
readonly timeoutMs: number;
|
|
46
|
+
readonly maxAttemptBytes: number;
|
|
47
|
+
/** Shared across all inspections using this policy, including child graphs. */
|
|
48
|
+
readonly maxBufferedBytes: number;
|
|
49
|
+
readonly classify: (content: string) => 'prose' | 'unsupported';
|
|
50
|
+
readonly inspect: (input: {
|
|
51
|
+
readonly version: 1;
|
|
52
|
+
readonly content: string;
|
|
53
|
+
readonly toolName: string;
|
|
54
|
+
readonly toolCallId: string;
|
|
55
|
+
readonly target: {
|
|
56
|
+
readonly source: 'tool_argument';
|
|
57
|
+
readonly field: 'output';
|
|
58
|
+
readonly provenance: 'tool';
|
|
59
|
+
readonly outcome: ToolResultOutcome;
|
|
60
|
+
};
|
|
61
|
+
readonly signal: AbortSignal;
|
|
62
|
+
}) => ToolResultProtectionResult | Promise<ToolResultProtectionResult>;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export class ToolResultProtectionError extends ProviderTextProtectionError {
|
|
66
|
+
constructor(code: ProviderTextProtectionErrorCode) {
|
|
67
|
+
super(code);
|
|
68
|
+
this.name = 'ToolResultProtectionError';
|
|
69
|
+
this.message = `Tool result protection: ${this.code}`;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export type ToolResultOutcome = 'success' | 'error';
|
|
74
|
+
|
|
75
|
+
export interface ToolResultCall {
|
|
76
|
+
readonly name: string;
|
|
77
|
+
readonly id: string;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/** A validated policy. One per policy object, so every graph of a run shares its byte budget. */
|
|
81
|
+
export interface ToolResultGate {
|
|
82
|
+
readonly policy: ToolResultProtection;
|
|
83
|
+
readonly toolNames: ReadonlySet<string>;
|
|
84
|
+
readonly budget: ProviderTextProtection;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
const gates = new WeakMap<ToolResultProtection, ToolResultGate>();
|
|
88
|
+
|
|
89
|
+
/** Budget accounting only: tool text is never released through the provider-text path. */
|
|
90
|
+
const rejectProviderRelease = (): ProviderTextProtectionResult => ({
|
|
91
|
+
version: 1,
|
|
92
|
+
ok: false,
|
|
93
|
+
error: { code: 'incompatible' },
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
/** Run-level safety aborts keep their identity; nothing else carries text out of an inspection. */
|
|
97
|
+
function toToolResultError(error: unknown): Error {
|
|
98
|
+
if (
|
|
99
|
+
error instanceof ToolResultProtectionError ||
|
|
100
|
+
error instanceof StreamLimitExceededError ||
|
|
101
|
+
error instanceof PreparedSubagentError
|
|
102
|
+
) {
|
|
103
|
+
return error;
|
|
104
|
+
}
|
|
105
|
+
return new ToolResultProtectionError(
|
|
106
|
+
error instanceof ProviderTextProtectionError ? error.code : 'unavailable'
|
|
107
|
+
);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
function hasValidToolNames(toolNames: readonly string[]): boolean {
|
|
111
|
+
return (
|
|
112
|
+
Array.isArray(toolNames) &&
|
|
113
|
+
toolNames.length > 0 &&
|
|
114
|
+
toolNames.every((name) => typeof name === 'string' && name.trim() !== '')
|
|
115
|
+
);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
export function createToolResultGate(
|
|
119
|
+
policy: ToolResultProtection
|
|
120
|
+
): ToolResultGate {
|
|
121
|
+
const existing = gates.get(policy);
|
|
122
|
+
if (existing != null) {
|
|
123
|
+
return existing;
|
|
124
|
+
}
|
|
125
|
+
if (typeof policy.inspect !== 'function') {
|
|
126
|
+
throw new ToolResultProtectionError('unavailable');
|
|
127
|
+
}
|
|
128
|
+
if (!hasValidToolNames(policy.toolNames)) {
|
|
129
|
+
throw new ToolResultProtectionError('incompatible');
|
|
130
|
+
}
|
|
131
|
+
const budget: ProviderTextProtection = {
|
|
132
|
+
version: policy.version,
|
|
133
|
+
timeoutMs: policy.timeoutMs,
|
|
134
|
+
maxAttemptBytes: policy.maxAttemptBytes,
|
|
135
|
+
maxBufferedBytes: policy.maxBufferedBytes,
|
|
136
|
+
classify: policy.classify,
|
|
137
|
+
inspect: rejectProviderRelease,
|
|
138
|
+
};
|
|
139
|
+
try {
|
|
140
|
+
validateProviderTextProtection(budget);
|
|
141
|
+
} catch (error) {
|
|
142
|
+
throw toToolResultError(error);
|
|
143
|
+
}
|
|
144
|
+
const gate: ToolResultGate = {
|
|
145
|
+
policy,
|
|
146
|
+
toolNames: new Set(policy.toolNames),
|
|
147
|
+
budget,
|
|
148
|
+
};
|
|
149
|
+
gates.set(policy, gate);
|
|
150
|
+
return gate;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/** Returns the inspected text, or throws; the raw text and inspector errors never leave. */
|
|
154
|
+
export async function inspectToolText(
|
|
155
|
+
gate: ToolResultGate,
|
|
156
|
+
call: ToolResultCall,
|
|
157
|
+
content: string,
|
|
158
|
+
outcome: ToolResultOutcome,
|
|
159
|
+
signal?: AbortSignal
|
|
160
|
+
): Promise<string> {
|
|
161
|
+
if (content === '') {
|
|
162
|
+
return content;
|
|
163
|
+
}
|
|
164
|
+
let attempt: ProviderTextAttempt | undefined;
|
|
165
|
+
try {
|
|
166
|
+
attempt = new ProviderTextAttempt(gate.budget, signal);
|
|
167
|
+
const inspection = attempt;
|
|
168
|
+
inspection.append(content);
|
|
169
|
+
if (gate.policy.classify(content) !== 'prose') {
|
|
170
|
+
throw new ToolResultProtectionError('unsupported');
|
|
171
|
+
}
|
|
172
|
+
const result = await inspection.wait(
|
|
173
|
+
(async (): Promise<ToolResultProtectionResult> =>
|
|
174
|
+
gate.policy.inspect({
|
|
175
|
+
version: 1,
|
|
176
|
+
content,
|
|
177
|
+
toolName: call.name,
|
|
178
|
+
toolCallId: call.id,
|
|
179
|
+
target: {
|
|
180
|
+
source: 'tool_argument',
|
|
181
|
+
field: 'output',
|
|
182
|
+
provenance: 'tool',
|
|
183
|
+
outcome,
|
|
184
|
+
},
|
|
185
|
+
signal: inspection.signal,
|
|
186
|
+
}))()
|
|
187
|
+
);
|
|
188
|
+
inspection.check();
|
|
189
|
+
const inspected = readProviderTextResult(result);
|
|
190
|
+
inspection.retain(inspected.length * 2);
|
|
191
|
+
return inspected;
|
|
192
|
+
} catch (error) {
|
|
193
|
+
throw toToolResultError(
|
|
194
|
+
attempt?.signal.aborted === true ? attempt.signal.reason : error
|
|
195
|
+
);
|
|
196
|
+
} finally {
|
|
197
|
+
attempt?.finish();
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
/** Inspects what a selected in-process tool returned. */
|
|
202
|
+
export async function inspectToolOutput(
|
|
203
|
+
gate: ToolResultGate,
|
|
204
|
+
call: ToolResultCall,
|
|
205
|
+
output: unknown,
|
|
206
|
+
signal?: AbortSignal
|
|
207
|
+
): Promise<ToolMessage | string> {
|
|
208
|
+
if (typeof output === 'string') {
|
|
209
|
+
return inspectToolText(gate, call, output, 'success', signal);
|
|
210
|
+
}
|
|
211
|
+
if (
|
|
212
|
+
!ToolMessage.isInstance(output) ||
|
|
213
|
+
output.artifact != null ||
|
|
214
|
+
typeof output.content !== 'string'
|
|
215
|
+
) {
|
|
216
|
+
throw new ToolResultProtectionError('unsupported');
|
|
217
|
+
}
|
|
218
|
+
const content = await inspectToolText(
|
|
219
|
+
gate,
|
|
220
|
+
call,
|
|
221
|
+
output.content,
|
|
222
|
+
output.status === 'error' ? 'error' : 'success',
|
|
223
|
+
signal
|
|
224
|
+
);
|
|
225
|
+
return content === output.content
|
|
226
|
+
? output
|
|
227
|
+
: cloneToolMessageWithContent(output, content);
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
/** Inspects what the host returned for a selected tool call. */
|
|
231
|
+
export async function inspectToolExecuteResult(
|
|
232
|
+
gate: ToolResultGate,
|
|
233
|
+
call: ToolResultCall,
|
|
234
|
+
result: ToolExecuteResult,
|
|
235
|
+
signal?: AbortSignal
|
|
236
|
+
): Promise<ToolExecuteResult> {
|
|
237
|
+
if (result.artifact != null) {
|
|
238
|
+
throw new ToolResultProtectionError('unsupported');
|
|
239
|
+
}
|
|
240
|
+
if (result.status === 'error') {
|
|
241
|
+
if (result.errorMessage == null) {
|
|
242
|
+
return { ...result, content: '' };
|
|
243
|
+
}
|
|
244
|
+
if (typeof result.errorMessage !== 'string') {
|
|
245
|
+
throw new ToolResultProtectionError('unsupported');
|
|
246
|
+
}
|
|
247
|
+
return {
|
|
248
|
+
...result,
|
|
249
|
+
content: '',
|
|
250
|
+
errorMessage: await inspectToolText(
|
|
251
|
+
gate,
|
|
252
|
+
call,
|
|
253
|
+
result.errorMessage,
|
|
254
|
+
'error',
|
|
255
|
+
signal
|
|
256
|
+
),
|
|
257
|
+
};
|
|
258
|
+
}
|
|
259
|
+
if (typeof result.content !== 'string') {
|
|
260
|
+
throw new ToolResultProtectionError('unsupported');
|
|
261
|
+
}
|
|
262
|
+
return {
|
|
263
|
+
...result,
|
|
264
|
+
content: await inspectToolText(
|
|
265
|
+
gate,
|
|
266
|
+
call,
|
|
267
|
+
result.content,
|
|
268
|
+
'success',
|
|
269
|
+
signal
|
|
270
|
+
),
|
|
271
|
+
};
|
|
272
|
+
}
|
package/src/run.ts
CHANGED
|
@@ -112,6 +112,7 @@ import { ProviderTextProtectionError } from '@/protection/providerText';
|
|
|
112
112
|
import { LANGFUSE_OPERATION_METADATA_KEY } from '@/langfuseOperation';
|
|
113
113
|
import { createTokenCounter, encodingForModel } from '@/utils/tokens';
|
|
114
114
|
import { stampSyntheticProviderMessage } from '@/messages/provenance';
|
|
115
|
+
import { ToolResultProtectionError } from '@/protection/toolResult';
|
|
115
116
|
import { isOpenAILike, isLibreChatOpenAIModel } from '@/utils/llm';
|
|
116
117
|
import { executeHooks, mergeAggregatedHookResults } from '@/hooks';
|
|
117
118
|
import { convertInjectedMessages } from '@/messages/injected';
|
|
@@ -397,9 +398,7 @@ async function resolveCompletedSegmentConfig(
|
|
|
397
398
|
);
|
|
398
399
|
}
|
|
399
400
|
|
|
400
|
-
function getFirstPersistedInterrupt(
|
|
401
|
-
snapshot: InterruptStateSnapshot
|
|
402
|
-
):
|
|
401
|
+
function getFirstPersistedInterrupt(snapshot: InterruptStateSnapshot):
|
|
403
402
|
| {
|
|
404
403
|
id: string;
|
|
405
404
|
value: unknown;
|
|
@@ -511,6 +510,7 @@ export class Run<_T extends t.BaseGraphState> {
|
|
|
511
510
|
private preemption?: t.StreamPreemption;
|
|
512
511
|
private maxStopContinuations: number;
|
|
513
512
|
private providerTextProtection?: t.StandardGraphInput['providerTextProtection'];
|
|
513
|
+
private toolResultProtection?: t.StandardGraphInput['toolResultProtection'];
|
|
514
514
|
private resolveAttachment?: t.StandardGraphInput['resolveAttachment'];
|
|
515
515
|
private streamLimits?: t.StreamLimits;
|
|
516
516
|
private subagentTasks?: t.SubagentTaskConfig;
|
|
@@ -616,6 +616,7 @@ export class Run<_T extends t.BaseGraphState> {
|
|
|
616
616
|
);
|
|
617
617
|
this.streamLimits = config.streamLimits;
|
|
618
618
|
this.providerTextProtection = config.providerTextProtection;
|
|
619
|
+
this.toolResultProtection = config.toolResultProtection;
|
|
619
620
|
this.resolveAttachment = config.resolveAttachment;
|
|
620
621
|
|
|
621
622
|
if (!config.graphConfig) {
|
|
@@ -627,6 +628,12 @@ export class Run<_T extends t.BaseGraphState> {
|
|
|
627
628
|
) {
|
|
628
629
|
throw new ProviderTextProtectionError('incompatible');
|
|
629
630
|
}
|
|
631
|
+
if (
|
|
632
|
+
'toolResultProtection' in config.graphConfig &&
|
|
633
|
+
config.graphConfig.toolResultProtection != null
|
|
634
|
+
) {
|
|
635
|
+
throw new ToolResultProtectionError('incompatible');
|
|
636
|
+
}
|
|
630
637
|
|
|
631
638
|
/** Handle different graph types */
|
|
632
639
|
if (config.graphConfig.type === 'multi-agent') {
|
|
@@ -727,6 +734,7 @@ export class Run<_T extends t.BaseGraphState> {
|
|
|
727
734
|
preemption: this.preemption,
|
|
728
735
|
streamLimits: this.streamLimits,
|
|
729
736
|
providerTextProtection: this.providerTextProtection,
|
|
737
|
+
toolResultProtection: this.toolResultProtection,
|
|
730
738
|
resolveAttachment: this.resolveAttachment,
|
|
731
739
|
toolExecution: this.toolExecution,
|
|
732
740
|
clientDelegatedToolNames: this.clientDelegatedToolNames,
|
|
@@ -776,6 +784,7 @@ export class Run<_T extends t.BaseGraphState> {
|
|
|
776
784
|
preemption: this.preemption,
|
|
777
785
|
streamLimits: this.streamLimits,
|
|
778
786
|
providerTextProtection: this.providerTextProtection,
|
|
787
|
+
toolResultProtection: this.toolResultProtection,
|
|
779
788
|
resolveAttachment: this.resolveAttachment,
|
|
780
789
|
toolExecution: this.toolExecution,
|
|
781
790
|
},
|
|
@@ -3082,7 +3091,9 @@ export class Run<_T extends t.BaseGraphState> {
|
|
|
3082
3091
|
reasoningChainOptions.runName ?? REASONING_LABEL_TRACE_NAME;
|
|
3083
3092
|
const reasoningTags = ['librechat', 'reasoning-label', 'reasoning-step'];
|
|
3084
3093
|
const reasoningRunLangfuse = withoutSkillsAvailable(this.langfuse);
|
|
3085
|
-
const reasoningLangfuseOverlay = withoutSkillsAvailable(
|
|
3094
|
+
const reasoningLangfuseOverlay = withoutSkillsAvailable(
|
|
3095
|
+
reasoningContext?.langfuse
|
|
3096
|
+
);
|
|
3086
3097
|
const reasoningLangfuseConfig = resolveLangfuseConfig(
|
|
3087
3098
|
reasoningRunLangfuse,
|
|
3088
3099
|
reasoningLangfuseOverlay
|
package/src/runtime/client.ts
CHANGED
|
@@ -27,6 +27,7 @@ import type { RecoveryClaim } from './recovery/server';
|
|
|
27
27
|
import type { SdkAgentIdentity } from './identity';
|
|
28
28
|
import {
|
|
29
29
|
Run,
|
|
30
|
+
ToolResultProtectionError,
|
|
30
31
|
executeHooks,
|
|
31
32
|
GraphEvents,
|
|
32
33
|
HOOK_EVENTS,
|
|
@@ -64,6 +65,8 @@ export async function createRemoteSdkRun({
|
|
|
64
65
|
throw new Error(
|
|
65
66
|
'Remote SDK client-owned tools require a supported ownership adapter'
|
|
66
67
|
);
|
|
68
|
+
if (config.toolResultProtection != null)
|
|
69
|
+
throw new ToolResultProtectionError('unsupported');
|
|
67
70
|
if (config.providerTextProtection && !hostServices?.providerText)
|
|
68
71
|
throw new Error(
|
|
69
72
|
'Remote SDK provider protection requires a supported policy adapter'
|
package/src/stream.ts
CHANGED
|
@@ -194,6 +194,11 @@ function isEagerExecutionExcludedTool(
|
|
|
194
194
|
if (excluded != null && excluded.includes(name)) {
|
|
195
195
|
return true;
|
|
196
196
|
}
|
|
197
|
+
// A protected result must be inspected before its completion is published,
|
|
198
|
+
// which only the committed ToolNode path guarantees.
|
|
199
|
+
if (graph.toolResultProtection?.toolNames.includes(name) === true) {
|
|
200
|
+
return true;
|
|
201
|
+
}
|
|
197
202
|
// Run-scoped circuit breaker: once a prestart for this tool diverged from
|
|
198
203
|
// the final request ("changed after eager execution started"), stop
|
|
199
204
|
// prestarting it so the model's retry executes normally instead of
|