@librechat/agents 4.2.9 → 4.2.11
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/agents/AgentContext.cjs +32 -2
- package/dist/cjs/agents/AgentContext.cjs.map +1 -1
- package/dist/cjs/harness/fileBindings.cjs +93 -0
- package/dist/cjs/harness/fileBindings.cjs.map +1 -0
- package/dist/cjs/harness/fileService.cjs +141 -0
- package/dist/cjs/harness/fileService.cjs.map +1 -0
- package/dist/cjs/harness/fileStream.cjs +76 -0
- package/dist/cjs/harness/fileStream.cjs.map +1 -0
- package/dist/cjs/harness/files.cjs +106 -0
- package/dist/cjs/harness/files.cjs.map +1 -0
- package/dist/cjs/harness/index.cjs +3 -0
- package/dist/cjs/harness/index.cjs.map +1 -1
- package/dist/cjs/llm/google/utils/signatures.cjs +5 -3
- package/dist/cjs/llm/google/utils/signatures.cjs.map +1 -1
- package/dist/cjs/main.cjs +13 -0
- package/dist/cjs/runtime/admission.cjs +135 -0
- package/dist/cjs/runtime/admission.cjs.map +1 -0
- package/dist/cjs/runtime/checkpoint.cjs +40 -0
- package/dist/cjs/runtime/checkpoint.cjs.map +1 -0
- package/dist/cjs/runtime/client.cjs +435 -0
- package/dist/cjs/runtime/client.cjs.map +1 -0
- package/dist/cjs/runtime/files.cjs +301 -0
- package/dist/cjs/runtime/files.cjs.map +1 -0
- package/dist/cjs/runtime/hostTools.cjs +165 -0
- package/dist/cjs/runtime/hostTools.cjs.map +1 -0
- package/dist/cjs/runtime/index.cjs +11 -0
- package/dist/cjs/runtime/model.cjs +303 -0
- package/dist/cjs/runtime/model.cjs.map +1 -0
- package/dist/cjs/runtime/peer.cjs +209 -0
- package/dist/cjs/runtime/peer.cjs.map +1 -0
- package/dist/cjs/runtime/policy.cjs +77 -0
- package/dist/cjs/runtime/policy.cjs.map +1 -0
- package/dist/cjs/runtime/recovery/client.cjs +172 -0
- package/dist/cjs/runtime/recovery/client.cjs.map +1 -0
- package/dist/cjs/runtime/recovery/log.cjs +47 -0
- package/dist/cjs/runtime/recovery/log.cjs.map +1 -0
- package/dist/cjs/runtime/recovery/redis.cjs +239 -0
- package/dist/cjs/runtime/recovery/redis.cjs.map +1 -0
- package/dist/cjs/runtime/recovery/server.cjs +190 -0
- package/dist/cjs/runtime/recovery/server.cjs.map +1 -0
- package/dist/cjs/runtime/recovery/socket.cjs +298 -0
- package/dist/cjs/runtime/recovery/socket.cjs.map +1 -0
- package/dist/cjs/runtime/resume.cjs +115 -0
- package/dist/cjs/runtime/resume.cjs.map +1 -0
- package/dist/cjs/runtime/sealed.cjs +107 -0
- package/dist/cjs/runtime/sealed.cjs.map +1 -0
- package/dist/cjs/runtime/server.cjs +415 -0
- package/dist/cjs/runtime/server.cjs.map +1 -0
- package/dist/cjs/runtime/snapshot.cjs +61 -0
- package/dist/cjs/runtime/snapshot.cjs.map +1 -0
- package/dist/cjs/runtime/types.cjs +20 -0
- package/dist/cjs/runtime/types.cjs.map +1 -0
- package/dist/cjs/runtime/wire.cjs +84 -0
- package/dist/cjs/runtime/wire.cjs.map +1 -0
- package/dist/cjs/tools/BashProgrammaticToolCalling.cjs +3 -2
- package/dist/cjs/tools/BashProgrammaticToolCalling.cjs.map +1 -1
- package/dist/cjs/tools/ProgrammaticCallerPolicy.cjs +24 -1
- package/dist/cjs/tools/ProgrammaticCallerPolicy.cjs.map +1 -1
- package/dist/cjs/tools/ProgrammaticToolCalling.cjs +3 -2
- package/dist/cjs/tools/ProgrammaticToolCalling.cjs.map +1 -1
- package/dist/cjs/tools/local/LocalProgrammaticToolCalling.cjs +2 -1
- package/dist/cjs/tools/local/LocalProgrammaticToolCalling.cjs.map +1 -1
- package/dist/cjs/tools/subagent/SubagentExecutor.cjs +15 -3
- package/dist/cjs/tools/subagent/SubagentExecutor.cjs.map +1 -1
- package/dist/cjs/tools/subagent/childGraphConfig.cjs +13 -1
- package/dist/cjs/tools/subagent/childGraphConfig.cjs.map +1 -1
- package/dist/cjs/tools/subagent/hostArgs.cjs +2 -0
- package/dist/cjs/tools/subagent/hostArgs.cjs.map +1 -1
- package/dist/esm/agents/AgentContext.mjs +32 -2
- package/dist/esm/agents/AgentContext.mjs.map +1 -1
- package/dist/esm/harness/fileBindings.mjs +93 -0
- package/dist/esm/harness/fileBindings.mjs.map +1 -0
- package/dist/esm/harness/fileService.mjs +140 -0
- package/dist/esm/harness/fileService.mjs.map +1 -0
- package/dist/esm/harness/fileStream.mjs +76 -0
- package/dist/esm/harness/fileStream.mjs.map +1 -0
- package/dist/esm/harness/files.mjs +97 -0
- package/dist/esm/harness/files.mjs.map +1 -0
- package/dist/esm/harness/index.mjs +3 -0
- package/dist/esm/harness/index.mjs.map +1 -1
- package/dist/esm/llm/google/utils/signatures.mjs +5 -3
- package/dist/esm/llm/google/utils/signatures.mjs.map +1 -1
- package/dist/esm/main.mjs +5 -2
- package/dist/esm/runtime/admission.mjs +133 -0
- package/dist/esm/runtime/admission.mjs.map +1 -0
- package/dist/esm/runtime/checkpoint.mjs +39 -0
- package/dist/esm/runtime/checkpoint.mjs.map +1 -0
- package/dist/esm/runtime/client.mjs +432 -0
- package/dist/esm/runtime/client.mjs.map +1 -0
- package/dist/esm/runtime/files.mjs +299 -0
- package/dist/esm/runtime/files.mjs.map +1 -0
- package/dist/esm/runtime/hostTools.mjs +164 -0
- package/dist/esm/runtime/hostTools.mjs.map +1 -0
- package/dist/esm/runtime/index.mjs +5 -0
- package/dist/esm/runtime/model.mjs +301 -0
- package/dist/esm/runtime/model.mjs.map +1 -0
- package/dist/esm/runtime/peer.mjs +209 -0
- package/dist/esm/runtime/peer.mjs.map +1 -0
- package/dist/esm/runtime/policy.mjs +75 -0
- package/dist/esm/runtime/policy.mjs.map +1 -0
- package/dist/esm/runtime/recovery/client.mjs +172 -0
- package/dist/esm/runtime/recovery/client.mjs.map +1 -0
- package/dist/esm/runtime/recovery/log.mjs +46 -0
- package/dist/esm/runtime/recovery/log.mjs.map +1 -0
- package/dist/esm/runtime/recovery/redis.mjs +239 -0
- package/dist/esm/runtime/recovery/redis.mjs.map +1 -0
- package/dist/esm/runtime/recovery/server.mjs +189 -0
- package/dist/esm/runtime/recovery/server.mjs.map +1 -0
- package/dist/esm/runtime/recovery/socket.mjs +297 -0
- package/dist/esm/runtime/recovery/socket.mjs.map +1 -0
- package/dist/esm/runtime/resume.mjs +111 -0
- package/dist/esm/runtime/resume.mjs.map +1 -0
- package/dist/esm/runtime/sealed.mjs +106 -0
- package/dist/esm/runtime/sealed.mjs.map +1 -0
- package/dist/esm/runtime/server.mjs +413 -0
- package/dist/esm/runtime/server.mjs.map +1 -0
- package/dist/esm/runtime/snapshot.mjs +60 -0
- package/dist/esm/runtime/snapshot.mjs.map +1 -0
- package/dist/esm/runtime/types.mjs +19 -0
- package/dist/esm/runtime/types.mjs.map +1 -0
- package/dist/esm/runtime/wire.mjs +80 -0
- package/dist/esm/runtime/wire.mjs.map +1 -0
- package/dist/esm/tools/BashProgrammaticToolCalling.mjs +3 -2
- package/dist/esm/tools/BashProgrammaticToolCalling.mjs.map +1 -1
- package/dist/esm/tools/ProgrammaticCallerPolicy.mjs +24 -1
- package/dist/esm/tools/ProgrammaticCallerPolicy.mjs.map +1 -1
- package/dist/esm/tools/ProgrammaticToolCalling.mjs +3 -2
- package/dist/esm/tools/ProgrammaticToolCalling.mjs.map +1 -1
- package/dist/esm/tools/local/LocalProgrammaticToolCalling.mjs +2 -1
- package/dist/esm/tools/local/LocalProgrammaticToolCalling.mjs.map +1 -1
- package/dist/esm/tools/subagent/SubagentExecutor.mjs +15 -3
- package/dist/esm/tools/subagent/SubagentExecutor.mjs.map +1 -1
- package/dist/esm/tools/subagent/childGraphConfig.mjs +13 -1
- package/dist/esm/tools/subagent/childGraphConfig.mjs.map +1 -1
- package/dist/esm/tools/subagent/hostArgs.mjs +2 -1
- package/dist/esm/tools/subagent/hostArgs.mjs.map +1 -1
- package/dist/types/agents/AgentContext.d.ts +4 -4
- package/dist/types/agents/projection.d.ts +1 -1
- package/dist/types/events.d.ts +2 -2
- package/dist/types/graphs/Graph.d.ts +13 -13
- package/dist/types/graphs/MultiAgentGraph.d.ts +2 -2
- package/dist/types/graphs/acceptedModelResponse.d.ts +1 -1
- package/dist/types/graphs/createGraph.d.ts +4 -4
- package/dist/types/graphs/graphFactory.d.ts +1 -1
- package/dist/types/graphs/handoff.d.ts +1 -1
- package/dist/types/harness/fileBindings.d.ts +13 -0
- package/dist/types/harness/fileService.d.ts +37 -0
- package/dist/types/harness/fileStream.d.ts +7 -0
- package/dist/types/harness/files.d.ts +108 -0
- package/dist/types/harness/index.d.ts +8 -2
- package/dist/types/harness/model.d.ts +3 -3
- package/dist/types/harness/providerText.d.ts +2 -2
- package/dist/types/hitl/approvalReview.d.ts +1 -1
- package/dist/types/hitl/askUserQuestion.d.ts +1 -1
- package/dist/types/hitl/askUserQuestions.d.ts +1 -1
- package/dist/types/hitl/askUserQuestionsInterrupt.d.ts +1 -1
- package/dist/types/hooks/types.d.ts +2 -2
- package/dist/types/instrumentation.d.ts +1 -1
- package/dist/types/langfuse.d.ts +3 -3
- package/dist/types/langfuseConfig.d.ts +2 -2
- package/dist/types/langfuseRuntimeContext.d.ts +1 -1
- package/dist/types/langfuseRuntimeScope.d.ts +2 -2
- package/dist/types/langfuseSpanRegistry.d.ts +1 -1
- package/dist/types/langfuseToolOutputTracing.d.ts +3 -3
- package/dist/types/llm/anthropic/index.d.ts +1 -1
- package/dist/types/llm/bedrock/index.d.ts +1 -1
- package/dist/types/llm/bedrock/toolCache.d.ts +2 -2
- package/dist/types/llm/contextOverflowRecovery.d.ts +2 -2
- package/dist/types/llm/contextPressureMeter.d.ts +2 -2
- package/dist/types/llm/google/index.d.ts +1 -1
- package/dist/types/llm/init.d.ts +1 -1
- package/dist/types/llm/invoke.d.ts +9 -9
- package/dist/types/llm/mistral/index.d.ts +1 -1
- package/dist/types/llm/openai/index.d.ts +2 -2
- package/dist/types/llm/openrouter/index.d.ts +2 -2
- package/dist/types/llm/openrouter/toolCache.d.ts +2 -2
- package/dist/types/llm/prepareProviderRequest.d.ts +3 -3
- package/dist/types/llm/promptCacheTools.d.ts +1 -1
- package/dist/types/llm/providerRegistry.d.ts +1 -1
- package/dist/types/llm/providerTextBoundary.d.ts +2 -2
- package/dist/types/llm/providerTextControls.d.ts +1 -1
- package/dist/types/llm/providers.d.ts +2 -2
- package/dist/types/llm/request.d.ts +1 -1
- package/dist/types/llm/stream/chunkAdapters.d.ts +1 -1
- package/dist/types/llm/streamLimits.d.ts +1 -1
- package/dist/types/llm/truncation.d.ts +1 -1
- package/dist/types/llm/vertexai/index.d.ts +1 -1
- package/dist/types/messages/alternation.d.ts +1 -1
- package/dist/types/messages/anthropicToolCache.d.ts +2 -2
- package/dist/types/messages/assistantPhase.d.ts +3 -3
- package/dist/types/messages/budget.d.ts +1 -1
- package/dist/types/messages/cache.d.ts +1 -1
- package/dist/types/messages/contextPruning.d.ts +2 -2
- package/dist/types/messages/core.d.ts +1 -1
- package/dist/types/messages/fading.d.ts +1 -1
- package/dist/types/messages/format.d.ts +2 -2
- package/dist/types/messages/ids.d.ts +2 -2
- package/dist/types/messages/injected.d.ts +1 -1
- package/dist/types/messages/langchain.d.ts +1 -1
- package/dist/types/messages/prune.d.ts +4 -4
- package/dist/types/messages/recency.d.ts +1 -1
- package/dist/types/messages/toolResultTypes.d.ts +1 -1
- package/dist/types/openai/arguments.d.ts +1 -1
- package/dist/types/openai/index.d.ts +1 -1
- package/dist/types/openai/toolProjection.d.ts +1 -1
- package/dist/types/prompts/activityLabel.d.ts +2 -2
- package/dist/types/prompts/reasoningLabel.d.ts +1 -1
- package/dist/types/rerank/search.d.ts +1 -1
- package/dist/types/responses/index.d.ts +1 -1
- package/dist/types/run.d.ts +3 -3
- package/dist/types/runtime/admission.d.ts +30 -0
- package/dist/types/runtime/checkpoint.d.ts +14 -0
- package/dist/types/runtime/client.d.ts +12 -0
- package/dist/types/runtime/files.d.ts +75 -0
- package/dist/types/runtime/hostTools.d.ts +22 -0
- package/dist/types/runtime/identity.d.ts +2 -0
- package/dist/types/runtime/index.d.ts +12 -0
- package/dist/types/runtime/model.d.ts +42 -0
- package/dist/types/runtime/peer.d.ts +55 -0
- package/dist/types/runtime/policy.d.ts +43 -0
- package/dist/types/runtime/recovery/client.d.ts +12 -0
- package/dist/types/runtime/recovery/journal.d.ts +62 -0
- package/dist/types/runtime/recovery/log.d.ts +9 -0
- package/dist/types/runtime/recovery/redis.d.ts +17 -0
- package/dist/types/runtime/recovery/server.d.ts +37 -0
- package/dist/types/runtime/recovery/socket.d.ts +72 -0
- package/dist/types/runtime/resume.d.ts +66 -0
- package/dist/types/runtime/sealed.d.ts +19 -0
- package/dist/types/runtime/server.d.ts +21 -0
- package/dist/types/runtime/snapshot.d.ts +12 -0
- package/dist/types/runtime/types.d.ts +125 -0
- package/dist/types/runtime/wire.d.ts +3 -0
- package/dist/types/session/handlers.d.ts +1 -1
- package/dist/types/session/types.d.ts +1 -1
- package/dist/types/stream.d.ts +3 -3
- package/dist/types/summarization/index.d.ts +1 -1
- package/dist/types/summarization/input.d.ts +1 -1
- package/dist/types/summarization/node.d.ts +6 -6
- package/dist/types/summarization/retry.d.ts +2 -2
- package/dist/types/summarization/semanticIndex.d.ts +2 -2
- package/dist/types/summarization/toolBudget.d.ts +1 -1
- package/dist/types/summarization/usage.d.ts +1 -1
- package/dist/types/tools/ArtifactDelivery.d.ts +1 -1
- package/dist/types/tools/ArtifactTruncation.d.ts +1 -1
- package/dist/types/tools/BashExecutor.d.ts +2 -2
- package/dist/types/tools/BashProgrammaticToolCalling.d.ts +2 -2
- package/dist/types/tools/CallerCapabilities.d.ts +1 -1
- package/dist/types/tools/CodeExecutor.d.ts +4 -4
- package/dist/types/tools/CodeSessionFileSummary.d.ts +1 -1
- package/dist/types/tools/ProgrammaticCallerPolicy.d.ts +2 -1
- package/dist/types/tools/ProgrammaticToolCalling.d.ts +2 -2
- package/dist/types/tools/ReadFile.d.ts +1 -1
- package/dist/types/tools/SkillTool.d.ts +1 -1
- package/dist/types/tools/SubagentTool.d.ts +3 -3
- package/dist/types/tools/ToolNode.d.ts +5 -5
- package/dist/types/tools/ToolSearch.d.ts +2 -2
- package/dist/types/tools/cloudflare/CloudflareBridgeRuntime.d.ts +1 -1
- package/dist/types/tools/cloudflare/CloudflareProgrammaticToolCalling.d.ts +1 -1
- package/dist/types/tools/cloudflare/CloudflareSandboxExecutionEngine.d.ts +2 -2
- package/dist/types/tools/cloudflare/CloudflareSandboxTools.d.ts +1 -1
- package/dist/types/tools/diagnostics.d.ts +1 -1
- package/dist/types/tools/eagerEventExecution.d.ts +1 -1
- package/dist/types/tools/handlers.d.ts +3 -3
- package/dist/types/tools/intentArg.d.ts +1 -1
- package/dist/types/tools/local/CompileCheckTool.d.ts +2 -2
- package/dist/types/tools/local/FileCheckpointer.d.ts +1 -1
- package/dist/types/tools/local/LocalCodingTools.d.ts +2 -2
- package/dist/types/tools/local/LocalExecutionEngine.d.ts +1 -1
- package/dist/types/tools/local/LocalExecutionTools.d.ts +1 -1
- package/dist/types/tools/local/LocalProgrammaticToolCalling.d.ts +1 -1
- package/dist/types/tools/local/bashAst.d.ts +1 -1
- package/dist/types/tools/local/resolveLocalExecutionTools.d.ts +1 -1
- package/dist/types/tools/local/syntaxCheck.d.ts +1 -1
- package/dist/types/tools/ptcTimeout.d.ts +1 -1
- package/dist/types/tools/runStepResume.d.ts +1 -1
- package/dist/types/tools/schema.d.ts +1 -1
- package/dist/types/tools/search/anthropic.d.ts +1 -1
- package/dist/types/tools/skillCatalog.d.ts +1 -1
- package/dist/types/tools/subagent/InMemorySubagentTaskStore.d.ts +1 -1
- package/dist/types/tools/subagent/SubagentExecutor.d.ts +5 -5
- package/dist/types/tools/subagent/SubagentReplay.d.ts +3 -3
- package/dist/types/tools/subagent/childGraphConfig.d.ts +2 -2
- package/dist/types/tools/subagent/diagnostics.d.ts +2 -2
- package/dist/types/tools/subagent/hostArgs.d.ts +8 -2
- package/dist/types/tools/subagent/index.d.ts +1 -1
- package/dist/types/tools/toolBatchReplay.d.ts +3 -3
- package/dist/types/types/activityLabel.d.ts +2 -2
- package/dist/types/types/graph.d.ts +16 -13
- package/dist/types/types/llm.d.ts +9 -9
- package/dist/types/types/reasoningLabel.d.ts +1 -1
- package/dist/types/types/run.d.ts +8 -8
- package/dist/types/types/stream.d.ts +5 -5
- package/dist/types/types/summarize.d.ts +2 -2
- package/dist/types/types/tools.d.ts +8 -8
- package/dist/types/utils/errors.d.ts +1 -1
- package/dist/types/utils/events.d.ts +3 -3
- package/dist/types/utils/handlers.d.ts +3 -3
- package/dist/types/utils/llm.d.ts +2 -2
- package/dist/types/utils/llmConfig.d.ts +1 -1
- package/dist/types/utils/title.d.ts +1 -1
- package/dist/types/utils/toolSessions.d.ts +1 -1
- package/package.json +22 -3
- package/src/agents/AgentContext.ts +68 -2
- package/src/harness/fileBindings.ts +156 -0
- package/src/harness/fileService.ts +217 -0
- package/src/harness/fileStream.ts +99 -0
- package/src/harness/files.ts +185 -0
- package/src/harness/index.ts +24 -0
- package/src/llm/google/utils/signatures.ts +10 -3
- package/src/runtime/admission.ts +224 -0
- package/src/runtime/checkpoint.ts +66 -0
- package/src/runtime/client.ts +674 -0
- package/src/runtime/files.ts +503 -0
- package/src/runtime/hostTools.ts +243 -0
- package/src/runtime/identity.ts +3 -0
- package/src/runtime/index.ts +33 -0
- package/src/runtime/model.ts +452 -0
- package/src/runtime/peer.ts +262 -0
- package/src/runtime/policy.ts +150 -0
- package/src/runtime/recovery/client.ts +232 -0
- package/src/runtime/recovery/journal.ts +88 -0
- package/src/runtime/recovery/log.ts +70 -0
- package/src/runtime/recovery/redis.ts +342 -0
- package/src/runtime/recovery/server.ts +280 -0
- package/src/runtime/recovery/socket.ts +422 -0
- package/src/runtime/resume.ts +268 -0
- package/src/runtime/sealed.ts +144 -0
- package/src/runtime/server.ts +653 -0
- package/src/runtime/snapshot.ts +87 -0
- package/src/runtime/types.ts +184 -0
- package/src/runtime/wire.ts +96 -0
- package/src/tools/BashProgrammaticToolCalling.ts +5 -2
- package/src/tools/ProgrammaticCallerPolicy.ts +42 -3
- package/src/tools/ProgrammaticToolCalling.ts +4 -1
- package/src/tools/local/LocalProgrammaticToolCalling.ts +4 -0
- package/src/tools/subagent/SubagentExecutor.ts +98 -32
- package/src/tools/subagent/childGraphConfig.ts +33 -1
- package/src/tools/subagent/hostArgs.ts +7 -0
- package/src/tools/subagent/index.ts +1 -0
- package/src/types/graph.ts +6 -3
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
|
+
import type { HostFileStageRequest } from './files';
|
|
3
|
+
import { HostFileServiceError } from './files';
|
|
4
|
+
|
|
5
|
+
/** Single-consumer, bounded upload. Cleanup is owned by the operation, not the transport. */
|
|
6
|
+
export function createFileUpload(
|
|
7
|
+
source: AsyncIterable<Uint8Array>,
|
|
8
|
+
request: Pick<HostFileStageRequest, 'bytes' | 'sha256'>,
|
|
9
|
+
maxChunkBytes: number,
|
|
10
|
+
signal?: AbortSignal,
|
|
11
|
+
hash = false
|
|
12
|
+
): {
|
|
13
|
+
content: AsyncIterable<Uint8Array>;
|
|
14
|
+
finish: () => string | undefined;
|
|
15
|
+
close: () => Promise<void>;
|
|
16
|
+
} {
|
|
17
|
+
const iterator = source[Symbol.asyncIterator]();
|
|
18
|
+
let closing: Promise<void> | undefined;
|
|
19
|
+
let started = false;
|
|
20
|
+
let complete = false;
|
|
21
|
+
let bytes = 0;
|
|
22
|
+
const checksum = hash ? createHash('sha256') : undefined;
|
|
23
|
+
let sha256: string | undefined;
|
|
24
|
+
const close = (): Promise<void> => {
|
|
25
|
+
closing ??= Promise.resolve().then(async () => {
|
|
26
|
+
await iterator.return?.();
|
|
27
|
+
});
|
|
28
|
+
return closing;
|
|
29
|
+
};
|
|
30
|
+
async function* stream(): AsyncGenerator<Uint8Array> {
|
|
31
|
+
try {
|
|
32
|
+
for (;;) {
|
|
33
|
+
signal?.throwIfAborted();
|
|
34
|
+
const next = await iterator.next();
|
|
35
|
+
signal?.throwIfAborted();
|
|
36
|
+
if (next.done === true) break;
|
|
37
|
+
if (!(next.value instanceof Uint8Array) || next.value.byteLength === 0)
|
|
38
|
+
throw new HostFileServiceError('incompatible');
|
|
39
|
+
if (
|
|
40
|
+
next.value.byteLength > maxChunkBytes ||
|
|
41
|
+
next.value.byteLength > request.bytes - bytes
|
|
42
|
+
)
|
|
43
|
+
throw new HostFileServiceError('overflow');
|
|
44
|
+
const chunk = Uint8Array.from(next.value);
|
|
45
|
+
bytes += chunk.byteLength;
|
|
46
|
+
checksum?.update(chunk);
|
|
47
|
+
yield chunk;
|
|
48
|
+
}
|
|
49
|
+
if (bytes !== request.bytes)
|
|
50
|
+
throw new HostFileServiceError('incompatible');
|
|
51
|
+
sha256 = checksum?.digest('hex');
|
|
52
|
+
if (
|
|
53
|
+
sha256 !== undefined &&
|
|
54
|
+
request.sha256 !== undefined &&
|
|
55
|
+
sha256 !== request.sha256
|
|
56
|
+
)
|
|
57
|
+
throw new HostFileServiceError('conflict');
|
|
58
|
+
complete = true;
|
|
59
|
+
} finally {
|
|
60
|
+
await close();
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return {
|
|
64
|
+
content: {
|
|
65
|
+
[Symbol.asyncIterator](): AsyncIterator<Uint8Array> {
|
|
66
|
+
if (started || closing) throw new HostFileServiceError('incompatible');
|
|
67
|
+
started = true;
|
|
68
|
+
const generator = stream();
|
|
69
|
+
return {
|
|
70
|
+
next: (): Promise<IteratorResult<Uint8Array>> =>
|
|
71
|
+
closing
|
|
72
|
+
? closing.then(() => ({ done: true, value: undefined }))
|
|
73
|
+
: generator.next(),
|
|
74
|
+
return: async (): Promise<IteratorResult<Uint8Array>> => {
|
|
75
|
+
try {
|
|
76
|
+
return await generator.return(undefined);
|
|
77
|
+
} finally {
|
|
78
|
+
await close();
|
|
79
|
+
}
|
|
80
|
+
},
|
|
81
|
+
throw: async (
|
|
82
|
+
error: unknown
|
|
83
|
+
): Promise<IteratorResult<Uint8Array>> => {
|
|
84
|
+
try {
|
|
85
|
+
return await generator.throw(error);
|
|
86
|
+
} finally {
|
|
87
|
+
await close();
|
|
88
|
+
}
|
|
89
|
+
},
|
|
90
|
+
};
|
|
91
|
+
},
|
|
92
|
+
},
|
|
93
|
+
finish: (): string | undefined => {
|
|
94
|
+
if (!complete) throw new HostFileServiceError('incompatible');
|
|
95
|
+
return sha256;
|
|
96
|
+
},
|
|
97
|
+
close,
|
|
98
|
+
};
|
|
99
|
+
}
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { executionIdentitySchema } from './identity';
|
|
3
|
+
|
|
4
|
+
const reference = z
|
|
5
|
+
.string()
|
|
6
|
+
.min(1)
|
|
7
|
+
.max(512)
|
|
8
|
+
.refine((value) => value.trim().length > 0);
|
|
9
|
+
const count = z.number().int().nonnegative().max(Number.MAX_SAFE_INTEGER);
|
|
10
|
+
const digest = z.string().regex(/^[a-f0-9]{64}$/);
|
|
11
|
+
|
|
12
|
+
/** Opaque host references and immutable revisions, never filesystem paths or signed URLs. */
|
|
13
|
+
export const hostFileDescriptorSchema = z.object({
|
|
14
|
+
reference,
|
|
15
|
+
revision: reference,
|
|
16
|
+
filename: z.string().min(1).max(255),
|
|
17
|
+
mediaType: z.string().min(1).max(255),
|
|
18
|
+
bytes: count,
|
|
19
|
+
sha256: digest.optional(),
|
|
20
|
+
});
|
|
21
|
+
export type HostFileDescriptor = Readonly<
|
|
22
|
+
z.infer<typeof hostFileDescriptorSchema>
|
|
23
|
+
>;
|
|
24
|
+
|
|
25
|
+
export const hostFileServiceDescriptorSchema = z.object({
|
|
26
|
+
version: z.literal(1),
|
|
27
|
+
operations: z.array(z.enum(['read', 'stage', 'publish'])).max(3),
|
|
28
|
+
maxFileBytes: count.positive(),
|
|
29
|
+
maxChunkBytes: count.positive(),
|
|
30
|
+
});
|
|
31
|
+
export type HostFileServiceDescriptor = Readonly<
|
|
32
|
+
Omit<z.infer<typeof hostFileServiceDescriptorSchema>, 'operations'>
|
|
33
|
+
> & { readonly operations: readonly ('read' | 'stage' | 'publish')[] };
|
|
34
|
+
|
|
35
|
+
const request = z.object({
|
|
36
|
+
version: z.literal(1),
|
|
37
|
+
identity: executionIdentitySchema,
|
|
38
|
+
});
|
|
39
|
+
export const hostFileReadRequestSchema = request.extend({
|
|
40
|
+
reference,
|
|
41
|
+
revision: reference,
|
|
42
|
+
offset: count,
|
|
43
|
+
length: count.positive(),
|
|
44
|
+
});
|
|
45
|
+
export const hostFileStageRequestSchema = request.extend({
|
|
46
|
+
operationId: reference,
|
|
47
|
+
filename: z.string().min(1).max(255),
|
|
48
|
+
mediaType: z.string().min(1).max(255),
|
|
49
|
+
bytes: count,
|
|
50
|
+
sha256: digest.optional(),
|
|
51
|
+
});
|
|
52
|
+
export const hostFilePublishRequestSchema = request.extend({
|
|
53
|
+
operationId: reference,
|
|
54
|
+
reference,
|
|
55
|
+
revision: reference,
|
|
56
|
+
});
|
|
57
|
+
export type HostFileReadRequest = Readonly<
|
|
58
|
+
z.infer<typeof hostFileReadRequestSchema>
|
|
59
|
+
>;
|
|
60
|
+
export type HostFileStageRequest = Readonly<
|
|
61
|
+
z.infer<typeof hostFileStageRequestSchema>
|
|
62
|
+
>;
|
|
63
|
+
export type HostFilePublishRequest = Readonly<
|
|
64
|
+
z.infer<typeof hostFilePublishRequestSchema>
|
|
65
|
+
>;
|
|
66
|
+
export interface HostFileChunk {
|
|
67
|
+
readonly reference: string;
|
|
68
|
+
readonly revision: string;
|
|
69
|
+
readonly offset: number;
|
|
70
|
+
readonly data: Uint8Array;
|
|
71
|
+
}
|
|
72
|
+
export interface HostFilePublication {
|
|
73
|
+
readonly operationId: string;
|
|
74
|
+
readonly file: HostFileDescriptor;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Authenticate the transport separately. Each operation must authorize the bound identity,
|
|
79
|
+
* reference and revision against canonical host storage. Staging is private; only publish
|
|
80
|
+
* enters the host's native attachment/event pipeline. Mutations are never automatically retried.
|
|
81
|
+
*/
|
|
82
|
+
export interface HostFileService {
|
|
83
|
+
readonly version: 1;
|
|
84
|
+
read(
|
|
85
|
+
request: HostFileReadRequest,
|
|
86
|
+
signal?: AbortSignal
|
|
87
|
+
): Promise<HostFileChunk>;
|
|
88
|
+
stage(
|
|
89
|
+
request: HostFileStageRequest,
|
|
90
|
+
content: AsyncIterable<Uint8Array>,
|
|
91
|
+
signal?: AbortSignal
|
|
92
|
+
): Promise<HostFileDescriptor>;
|
|
93
|
+
publish(
|
|
94
|
+
request: HostFilePublishRequest,
|
|
95
|
+
signal?: AbortSignal
|
|
96
|
+
): Promise<HostFilePublication>;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
const codes = [
|
|
100
|
+
'incompatible',
|
|
101
|
+
'forbidden',
|
|
102
|
+
'conflict',
|
|
103
|
+
'overflow',
|
|
104
|
+
'cancelled',
|
|
105
|
+
'timeout',
|
|
106
|
+
'unavailable',
|
|
107
|
+
] as const;
|
|
108
|
+
export type HostFileErrorCode = (typeof codes)[number];
|
|
109
|
+
export class HostFileServiceError extends Error {
|
|
110
|
+
readonly code: HostFileErrorCode;
|
|
111
|
+
constructor(code: HostFileErrorCode) {
|
|
112
|
+
const safe = codes.includes(code) ? code : 'incompatible';
|
|
113
|
+
super(`Host file service: ${safe}`);
|
|
114
|
+
this.name = 'HostFileServiceError';
|
|
115
|
+
this.code = safe;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/** @internal Never forward adapter error text or abort reasons over the service boundary. */
|
|
120
|
+
export function normalizeHostFileError(
|
|
121
|
+
error: unknown,
|
|
122
|
+
signal?: AbortSignal
|
|
123
|
+
): HostFileServiceError {
|
|
124
|
+
try {
|
|
125
|
+
if (signal?.aborted === true) {
|
|
126
|
+
return new HostFileServiceError(
|
|
127
|
+
signal.reason instanceof HostFileServiceError &&
|
|
128
|
+
signal.reason.code === 'timeout'
|
|
129
|
+
? 'timeout'
|
|
130
|
+
: 'cancelled'
|
|
131
|
+
);
|
|
132
|
+
}
|
|
133
|
+
if (error instanceof HostFileServiceError)
|
|
134
|
+
return new HostFileServiceError(error.code);
|
|
135
|
+
} catch {
|
|
136
|
+
/** Adapter errors may contain throwing accessors; never expose them. */
|
|
137
|
+
}
|
|
138
|
+
return new HostFileServiceError('unavailable');
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/** @internal Snapshot only public metadata, dropping host-specific fields. */
|
|
142
|
+
export function checkedHostFile(value: HostFileDescriptor): HostFileDescriptor {
|
|
143
|
+
const parsed = hostFileDescriptorSchema.safeParse(value);
|
|
144
|
+
if (!parsed.success) throw new HostFileServiceError('incompatible');
|
|
145
|
+
return Object.freeze(parsed.data);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/** @internal Reject mismatched/stale ranges before bytes enter a graph. */
|
|
149
|
+
export function checkedHostFileChunk(
|
|
150
|
+
value: HostFileChunk,
|
|
151
|
+
input: HostFileReadRequest
|
|
152
|
+
): HostFileChunk {
|
|
153
|
+
if (
|
|
154
|
+
value.reference !== input.reference ||
|
|
155
|
+
value.revision !== input.revision ||
|
|
156
|
+
value.offset !== input.offset ||
|
|
157
|
+
!(value.data instanceof Uint8Array) ||
|
|
158
|
+
value.data.byteLength !== input.length
|
|
159
|
+
)
|
|
160
|
+
throw new HostFileServiceError('incompatible');
|
|
161
|
+
return {
|
|
162
|
+
reference: input.reference,
|
|
163
|
+
revision: input.revision,
|
|
164
|
+
offset: input.offset,
|
|
165
|
+
data: Uint8Array.from(value.data),
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/** @internal Negotiation validates limits before constructing any graph adapter. */
|
|
170
|
+
export function checkedHostFileService(
|
|
171
|
+
value: HostFileServiceDescriptor
|
|
172
|
+
): HostFileServiceDescriptor {
|
|
173
|
+
const parsed = hostFileServiceDescriptorSchema.safeParse(value);
|
|
174
|
+
if (
|
|
175
|
+
!parsed.success ||
|
|
176
|
+
parsed.data.maxChunkBytes > parsed.data.maxFileBytes ||
|
|
177
|
+
parsed.data.maxChunkBytes > Number.MAX_SAFE_INTEGER / 2 ||
|
|
178
|
+
new Set(parsed.data.operations).size !== parsed.data.operations.length
|
|
179
|
+
)
|
|
180
|
+
throw new HostFileServiceError('incompatible');
|
|
181
|
+
return Object.freeze({
|
|
182
|
+
...parsed.data,
|
|
183
|
+
operations: Object.freeze([...parsed.data.operations]),
|
|
184
|
+
});
|
|
185
|
+
}
|
package/src/harness/index.ts
CHANGED
|
@@ -229,3 +229,27 @@ export type {
|
|
|
229
229
|
|
|
230
230
|
export { createHostModelService, HostModelAdmission } from './modelService';
|
|
231
231
|
export type { HostModelLimits } from './modelService';
|
|
232
|
+
|
|
233
|
+
export { createHostFileService, HostFileAdmission } from './fileService';
|
|
234
|
+
export type { HostFileStore } from './fileService';
|
|
235
|
+
export { createHostFileBindings } from './fileBindings';
|
|
236
|
+
export type { HostFileBindings } from './fileBindings';
|
|
237
|
+
export {
|
|
238
|
+
HostFileServiceError,
|
|
239
|
+
hostFileDescriptorSchema,
|
|
240
|
+
hostFileServiceDescriptorSchema,
|
|
241
|
+
hostFileReadRequestSchema,
|
|
242
|
+
hostFileStageRequestSchema,
|
|
243
|
+
hostFilePublishRequestSchema,
|
|
244
|
+
} from './files';
|
|
245
|
+
export type {
|
|
246
|
+
HostFileDescriptor,
|
|
247
|
+
HostFileServiceDescriptor,
|
|
248
|
+
HostFileService,
|
|
249
|
+
HostFileReadRequest,
|
|
250
|
+
HostFileStageRequest,
|
|
251
|
+
HostFilePublishRequest,
|
|
252
|
+
HostFileChunk,
|
|
253
|
+
HostFilePublication,
|
|
254
|
+
HostFileErrorCode,
|
|
255
|
+
} from './files';
|
|
@@ -152,21 +152,28 @@ export function restoreGeminiReplayParts(
|
|
|
152
152
|
)
|
|
153
153
|
return undefined;
|
|
154
154
|
let text = '';
|
|
155
|
-
let contentReasoning
|
|
155
|
+
let contentReasoning: string | undefined;
|
|
156
156
|
if (typeof message.content === 'string') text = message.content;
|
|
157
157
|
else
|
|
158
158
|
for (const block of message.content) {
|
|
159
159
|
if (block.type === 'text' && typeof block.text === 'string')
|
|
160
160
|
text += block.text;
|
|
161
161
|
else if (block.type === 'thinking' && typeof block.thinking === 'string')
|
|
162
|
-
contentReasoning
|
|
162
|
+
contentReasoning = (contentReasoning ?? '') + block.thinking;
|
|
163
|
+
else if (
|
|
164
|
+
block.type === 'reasoning' &&
|
|
165
|
+
typeof block.reasoning === 'string'
|
|
166
|
+
)
|
|
167
|
+
contentReasoning = (contentReasoning ?? '') + block.reasoning;
|
|
163
168
|
else if (!('functionCall' in block)) return undefined;
|
|
164
169
|
}
|
|
165
|
-
let reasoning = contentReasoning;
|
|
170
|
+
let reasoning = contentReasoning ?? '';
|
|
166
171
|
if (typeof message.additional_kwargs.reasoning_content === 'string')
|
|
167
172
|
reasoning = message.additional_kwargs.reasoning_content;
|
|
168
173
|
if (typeof message.additional_kwargs.reasoning === 'string')
|
|
169
174
|
reasoning = message.additional_kwargs.reasoning;
|
|
175
|
+
if (contentReasoning != null && contentReasoning !== reasoning)
|
|
176
|
+
return undefined;
|
|
170
177
|
const calls = new Map(
|
|
171
178
|
(message.tool_calls ?? []).map((call) => [call.id, call])
|
|
172
179
|
);
|
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
3
|
+
import { ensureHandler } from '@langchain/core/callbacks/manager';
|
|
4
|
+
import type {
|
|
5
|
+
CallbackManagerForLLMRun,
|
|
6
|
+
Callbacks,
|
|
7
|
+
} from '@langchain/core/callbacks/manager';
|
|
8
|
+
import type { ChatResult, ChatGenerationChunk } from '@langchain/core/outputs';
|
|
9
|
+
import type { BaseCallbackHandler } from '@langchain/core/callbacks/base';
|
|
10
|
+
import type { BaseMessage } from '@langchain/core/messages';
|
|
11
|
+
import type { SdkRpc } from './peer';
|
|
12
|
+
import { HostChatModel, HostModelServiceError } from '@/index';
|
|
13
|
+
|
|
14
|
+
export interface RemoteModelAttempt {
|
|
15
|
+
nodeId: string;
|
|
16
|
+
modelId: string;
|
|
17
|
+
}
|
|
18
|
+
export const modelAttemptSchema: z.ZodType<RemoteModelAttempt> = z
|
|
19
|
+
.object({ nodeId: z.string().uuid(), modelId: z.string().uuid() })
|
|
20
|
+
.strict();
|
|
21
|
+
const invocationContextSchema = z
|
|
22
|
+
.object({ version: z.literal(1), runId: z.string().uuid() })
|
|
23
|
+
.strict();
|
|
24
|
+
/** Additive SDK capability: older SDKs keep the input-only model adapter during rollout. */
|
|
25
|
+
export const supportsModelInvocationContext: boolean =
|
|
26
|
+
Number(HostChatModel.invocationContextVersion) === 1;
|
|
27
|
+
const blocked = (): HostModelServiceError =>
|
|
28
|
+
new HostModelServiceError('blocked');
|
|
29
|
+
|
|
30
|
+
/** Run each iterator operation inside its scope; constructing an async generator does not enter it. */
|
|
31
|
+
async function* scopedStream<T, C>(
|
|
32
|
+
storage: AsyncLocalStorage<C>,
|
|
33
|
+
context: C,
|
|
34
|
+
source: () => AsyncIterable<T>
|
|
35
|
+
): AsyncGenerator<T> {
|
|
36
|
+
const iterator = storage.run(context, () => source()[Symbol.asyncIterator]());
|
|
37
|
+
try {
|
|
38
|
+
for (;;) {
|
|
39
|
+
const next = await storage.run(context, () => iterator.next());
|
|
40
|
+
if (next.done === true) return;
|
|
41
|
+
yield next.value;
|
|
42
|
+
}
|
|
43
|
+
} finally {
|
|
44
|
+
await storage.run(context, () => iterator.return?.());
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export interface HostModelLifecycle {
|
|
49
|
+
attach(callbacks: Callbacks | undefined): boolean;
|
|
50
|
+
readonly maxEntries: number;
|
|
51
|
+
failure(): Error | undefined;
|
|
52
|
+
invoke<T>(
|
|
53
|
+
context: RemoteModelAttempt | undefined,
|
|
54
|
+
operation: () => Promise<T>
|
|
55
|
+
): Promise<T>;
|
|
56
|
+
stream<T>(
|
|
57
|
+
context: RemoteModelAttempt | undefined,
|
|
58
|
+
operation: () => AsyncIterable<T>
|
|
59
|
+
): AsyncIterable<T>;
|
|
60
|
+
end(data: unknown): boolean;
|
|
61
|
+
dispose(): void;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export interface WorkerModelLifecycle {
|
|
65
|
+
callback: BaseCallbackHandler;
|
|
66
|
+
current(context?: unknown): RemoteModelAttempt | undefined;
|
|
67
|
+
model(options: ConstructorParameters<typeof HostChatModel>[0]): HostChatModel;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/** Only callbacks installed on this root execution can enroll a model attempt. No message text is relayed. */
|
|
71
|
+
export function createWorkerModelLifecycle(
|
|
72
|
+
agentId: string,
|
|
73
|
+
maxEntries: number,
|
|
74
|
+
peer: { call: SdkRpc }
|
|
75
|
+
): WorkerModelLifecycle {
|
|
76
|
+
const parents = new Map<string, string>();
|
|
77
|
+
const nodes = new Set<string>();
|
|
78
|
+
const models = new Map<string, RemoteModelAttempt>();
|
|
79
|
+
const attemptedNodes = new Set<string>();
|
|
80
|
+
const storage = new AsyncLocalStorage<RemoteModelAttempt | undefined>();
|
|
81
|
+
let admitted = false;
|
|
82
|
+
const budget = (): void => {
|
|
83
|
+
if (parents.size + nodes.size + models.size >= maxEntries) throw blocked();
|
|
84
|
+
};
|
|
85
|
+
const context = (
|
|
86
|
+
manager?: CallbackManagerForLLMRun
|
|
87
|
+
): RemoteModelAttempt | undefined => {
|
|
88
|
+
if (admitted) return undefined;
|
|
89
|
+
const value = manager && models.get(manager.runId);
|
|
90
|
+
if (!value) throw blocked();
|
|
91
|
+
attemptedNodes.add(value.nodeId);
|
|
92
|
+
return value;
|
|
93
|
+
};
|
|
94
|
+
const end = async (nodeId: string, completed: boolean): Promise<void> => {
|
|
95
|
+
parents.delete(nodeId);
|
|
96
|
+
nodes.delete(nodeId);
|
|
97
|
+
for (const [modelId, attempt] of models)
|
|
98
|
+
if (attempt.nodeId === nodeId) models.delete(modelId);
|
|
99
|
+
if (!attemptedNodes.delete(nodeId)) return;
|
|
100
|
+
const reply = z
|
|
101
|
+
.object({
|
|
102
|
+
version: z.literal(1),
|
|
103
|
+
ok: z.literal(true),
|
|
104
|
+
admitted: z.boolean(),
|
|
105
|
+
})
|
|
106
|
+
.parse(await peer.call('model.node.end', { nodeId, completed }));
|
|
107
|
+
if (reply.admitted) {
|
|
108
|
+
admitted = true;
|
|
109
|
+
parents.clear();
|
|
110
|
+
nodes.clear();
|
|
111
|
+
models.clear();
|
|
112
|
+
attemptedNodes.clear();
|
|
113
|
+
}
|
|
114
|
+
};
|
|
115
|
+
class CorrelatedHostModel extends HostChatModel {
|
|
116
|
+
override _generate(
|
|
117
|
+
messages: BaseMessage[],
|
|
118
|
+
options: this['ParsedCallOptions'],
|
|
119
|
+
manager?: CallbackManagerForLLMRun
|
|
120
|
+
): Promise<ChatResult> {
|
|
121
|
+
return storage.run(context(manager), () =>
|
|
122
|
+
super._generate(messages, options)
|
|
123
|
+
);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
override async *_streamResponseChunks(
|
|
127
|
+
messages: BaseMessage[],
|
|
128
|
+
options: this['ParsedCallOptions'],
|
|
129
|
+
manager?: CallbackManagerForLLMRun
|
|
130
|
+
): AsyncGenerator<ChatGenerationChunk> {
|
|
131
|
+
yield* scopedStream(storage, context(manager), () =>
|
|
132
|
+
super._streamResponseChunks(messages, options, manager)
|
|
133
|
+
);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
return {
|
|
137
|
+
current(context): RemoteModelAttempt | undefined {
|
|
138
|
+
if (admitted) return undefined;
|
|
139
|
+
if (supportsModelInvocationContext) {
|
|
140
|
+
const { runId } = invocationContextSchema.parse(context);
|
|
141
|
+
const attempt = models.get(runId);
|
|
142
|
+
if (!attempt) throw blocked();
|
|
143
|
+
attemptedNodes.add(attempt.nodeId);
|
|
144
|
+
return attempt;
|
|
145
|
+
}
|
|
146
|
+
const value = storage.getStore();
|
|
147
|
+
if (!value) throw blocked();
|
|
148
|
+
return value;
|
|
149
|
+
},
|
|
150
|
+
model: (options) =>
|
|
151
|
+
supportsModelInvocationContext
|
|
152
|
+
? new HostChatModel(options)
|
|
153
|
+
: new CorrelatedHostModel(options),
|
|
154
|
+
callback: ensureHandler({
|
|
155
|
+
name: 'librechat-remote-model-admission',
|
|
156
|
+
raiseError: true,
|
|
157
|
+
awaitHandlers: true,
|
|
158
|
+
handleChainStart: (
|
|
159
|
+
_chain,
|
|
160
|
+
_inputs,
|
|
161
|
+
runId,
|
|
162
|
+
parentRunId,
|
|
163
|
+
_tags,
|
|
164
|
+
metadata,
|
|
165
|
+
_type,
|
|
166
|
+
name
|
|
167
|
+
) => {
|
|
168
|
+
if (admitted) return;
|
|
169
|
+
budget();
|
|
170
|
+
if (parentRunId != null && parentRunId.length > 0)
|
|
171
|
+
parents.set(runId, parentRunId);
|
|
172
|
+
if (name === `agent=${agentId}` && metadata?.langgraph_node === name)
|
|
173
|
+
nodes.add(runId);
|
|
174
|
+
},
|
|
175
|
+
handleChatModelStart: (
|
|
176
|
+
_model,
|
|
177
|
+
_messages,
|
|
178
|
+
runId,
|
|
179
|
+
parentRunId,
|
|
180
|
+
_extra,
|
|
181
|
+
_tags,
|
|
182
|
+
metadata
|
|
183
|
+
) => {
|
|
184
|
+
if (admitted) return;
|
|
185
|
+
if (
|
|
186
|
+
metadata?.summarization === true ||
|
|
187
|
+
metadata?.agentId !== agentId ||
|
|
188
|
+
metadata.langgraph_node !== `agent=${agentId}`
|
|
189
|
+
)
|
|
190
|
+
return;
|
|
191
|
+
const seen = new Set<string>();
|
|
192
|
+
let parent = parentRunId;
|
|
193
|
+
while (parent != null && parent.length > 0 && !seen.has(parent)) {
|
|
194
|
+
if (nodes.has(parent)) {
|
|
195
|
+
budget();
|
|
196
|
+
models.set(runId, { nodeId: parent, modelId: runId });
|
|
197
|
+
return;
|
|
198
|
+
}
|
|
199
|
+
seen.add(parent);
|
|
200
|
+
parent = parents.get(parent);
|
|
201
|
+
}
|
|
202
|
+
},
|
|
203
|
+
handleChainEnd: async (output, runId) => {
|
|
204
|
+
if (admitted) return;
|
|
205
|
+
if (!nodes.has(runId)) {
|
|
206
|
+
parents.delete(runId);
|
|
207
|
+
return;
|
|
208
|
+
}
|
|
209
|
+
const result = output as {
|
|
210
|
+
messages?: unknown;
|
|
211
|
+
summarizationRequest?: unknown;
|
|
212
|
+
} | null;
|
|
213
|
+
await end(
|
|
214
|
+
runId,
|
|
215
|
+
Array.isArray(result?.messages) &&
|
|
216
|
+
result.messages.length > 0 &&
|
|
217
|
+
result.summarizationRequest == null
|
|
218
|
+
);
|
|
219
|
+
},
|
|
220
|
+
handleChainError: (_error, runId) =>
|
|
221
|
+
admitted ? undefined : end(runId, false),
|
|
222
|
+
}),
|
|
223
|
+
};
|
|
224
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import type { SdkRpc } from './peer';
|
|
2
|
+
import { BaseCheckpointSaver } from '@/index';
|
|
3
|
+
|
|
4
|
+
type Saver = BaseCheckpointSaver;
|
|
5
|
+
function checkpointConfig(
|
|
6
|
+
config: Parameters<Saver['getTuple']>[0]
|
|
7
|
+
): Parameters<Saver['getTuple']>[0] {
|
|
8
|
+
return {
|
|
9
|
+
configurable: Object.fromEntries(
|
|
10
|
+
Object.entries(config.configurable ?? {}).filter(
|
|
11
|
+
([key, value]) =>
|
|
12
|
+
(['thread_id', 'checkpoint_ns', 'checkpoint_id'].includes(key) ||
|
|
13
|
+
key.startsWith('__librechat_')) &&
|
|
14
|
+
(typeof value === 'string' ||
|
|
15
|
+
typeof value === 'number' ||
|
|
16
|
+
typeof value === 'boolean' ||
|
|
17
|
+
value == null)
|
|
18
|
+
)
|
|
19
|
+
),
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
/** The host retains its durable saver; the worker never receives database credentials. */
|
|
23
|
+
export class RemoteSdkCheckpointer extends BaseCheckpointSaver {
|
|
24
|
+
constructor(private readonly call: SdkRpc) {
|
|
25
|
+
super();
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
async getTuple(
|
|
29
|
+
...args: Parameters<Saver['getTuple']>
|
|
30
|
+
): ReturnType<Saver['getTuple']> {
|
|
31
|
+
return (await this.call('checkpoint.getTuple', [
|
|
32
|
+
checkpointConfig(args[0]),
|
|
33
|
+
])) as Awaited<ReturnType<Saver['getTuple']>>;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
async *list(...args: Parameters<Saver['list']>): ReturnType<Saver['list']> {
|
|
37
|
+
const tuples = (await this.call('checkpoint.list', [
|
|
38
|
+
checkpointConfig(args[0]),
|
|
39
|
+
args[1] && {
|
|
40
|
+
...args[1],
|
|
41
|
+
before: args[1].before ? checkpointConfig(args[1].before) : undefined,
|
|
42
|
+
},
|
|
43
|
+
])) as Awaited<ReturnType<Saver['getTuple']>>[];
|
|
44
|
+
for (const tuple of tuples) if (tuple != null) yield tuple;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
async put(...args: Parameters<Saver['put']>): ReturnType<Saver['put']> {
|
|
48
|
+
return (await this.call('checkpoint.put', [
|
|
49
|
+
checkpointConfig(args[0]),
|
|
50
|
+
...args.slice(1),
|
|
51
|
+
])) as Awaited<ReturnType<Saver['put']>>;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
async putWrites(
|
|
55
|
+
...args: Parameters<Saver['putWrites']>
|
|
56
|
+
): ReturnType<Saver['putWrites']> {
|
|
57
|
+
await this.call('checkpoint.putWrites', [
|
|
58
|
+
checkpointConfig(args[0]),
|
|
59
|
+
...args.slice(1),
|
|
60
|
+
]);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
async deleteThread(): Promise<void> {
|
|
64
|
+
throw new Error('Runtime checkpoint deletion is not permitted');
|
|
65
|
+
}
|
|
66
|
+
}
|