@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
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ProviderName } from '
|
|
1
|
+
import type { ProviderName } from '../types/index.js';
|
|
2
2
|
/** Walks the constructor chain for LangChain's `lc_name` serialization ids.
|
|
3
3
|
* Constructor identity is unusable across lazily loaded module formats — the
|
|
4
4
|
* CJS and ESM builds carry distinct classes — so guards match on the ids the
|
|
@@ -8,7 +8,7 @@ export declare function constructorChainHasLcName(model: unknown, names: Readonl
|
|
|
8
8
|
* `ChatOpenAI`/`AzureChatOpenAI`: only those classes declare the
|
|
9
9
|
* `LibreChatOpenAI`/`LibreChatAzureOpenAI` ids, their subclasses keep them in
|
|
10
10
|
* the chain, and upstream `@langchain/openai` classes never carry them. */
|
|
11
|
-
export declare function isLibreChatOpenAIModel(model: unknown): model is import('
|
|
11
|
+
export declare function isLibreChatOpenAIModel(model: unknown): model is import('../llm/openai/index.js').ChatOpenAI | import('../llm/openai/index.js').AzureChatOpenAI;
|
|
12
12
|
export declare function isOpenAILike(provider?: ProviderName): boolean;
|
|
13
13
|
export declare function isGoogleLike(provider?: ProviderName): boolean;
|
|
14
14
|
/** Returns true for native Anthropic or Bedrock running a Claude model. */
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import type { Runnable } from '@langchain/core/runnables';
|
|
2
|
-
import type * as t from '
|
|
2
|
+
import type * as t from '../types/index.js';
|
|
3
3
|
export declare const createTitleRunnable: (model: t.ChatModelInstance, _titlePrompt?: string) => Promise<Runnable>;
|
|
4
4
|
export declare const createCompletionTitleRunnable: (model: t.ChatModelInstance, titlePrompt?: string) => Promise<Runnable>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@librechat/agents",
|
|
3
|
-
"version": "4.2.
|
|
3
|
+
"version": "4.2.11",
|
|
4
4
|
"reova": {
|
|
5
5
|
"enabled": true,
|
|
6
6
|
"endpoint": "https://telemetry.reo.dev/data"
|
|
@@ -128,6 +128,11 @@
|
|
|
128
128
|
"types": "./dist/types/llm/openrouter/index.d.ts",
|
|
129
129
|
"import": "./dist/esm/llm/openrouter/index.mjs",
|
|
130
130
|
"require": "./dist/cjs/llm/openrouter/index.cjs"
|
|
131
|
+
},
|
|
132
|
+
"./runtime": {
|
|
133
|
+
"types": "./dist/types/runtime/index.d.ts",
|
|
134
|
+
"import": "./dist/esm/runtime/index.mjs",
|
|
135
|
+
"require": "./dist/cjs/runtime/index.cjs"
|
|
131
136
|
}
|
|
132
137
|
},
|
|
133
138
|
"typesVersions": {
|
|
@@ -176,6 +181,9 @@
|
|
|
176
181
|
],
|
|
177
182
|
"llm/openrouter": [
|
|
178
183
|
"./dist/types/llm/openrouter/index.d.ts"
|
|
184
|
+
],
|
|
185
|
+
"runtime": [
|
|
186
|
+
"dist/types/runtime/index.d.ts"
|
|
179
187
|
]
|
|
180
188
|
}
|
|
181
189
|
},
|
|
@@ -213,7 +221,7 @@
|
|
|
213
221
|
"scripts": {
|
|
214
222
|
"prepare": "node husky-setup.js",
|
|
215
223
|
"prepublishOnly": "npm run build",
|
|
216
|
-
"build": "tsdown &&
|
|
224
|
+
"build": "tsdown && npm run build:types",
|
|
217
225
|
"build:dev": "tsdown",
|
|
218
226
|
"typecheck": "node scripts/typecheck.ts",
|
|
219
227
|
"test:typecheck": "node --test scripts/typecheck.test.ts",
|
|
@@ -303,7 +311,9 @@
|
|
|
303
311
|
"format": "prettier --write .",
|
|
304
312
|
"audit": "npm audit --omit=dev",
|
|
305
313
|
"label:eval": "tsx -r dotenv/config ./src/scripts/activity-labels/run.ts",
|
|
306
|
-
"label:rescore": "node ./src/scripts/activity-labels/rescore.cjs"
|
|
314
|
+
"label:rescore": "node ./src/scripts/activity-labels/rescore.cjs",
|
|
315
|
+
"test:runtime-package": "node --test config/runtime-package.test.mjs",
|
|
316
|
+
"build:types": "tsc -p tsconfig.build.json && tsc-alias -p tsconfig.build.json"
|
|
307
317
|
},
|
|
308
318
|
"overrides": {
|
|
309
319
|
"@langchain/openai": "$@langchain/openai",
|
|
@@ -344,9 +354,13 @@
|
|
|
344
354
|
"@langfuse/langchain": "^5.10.1",
|
|
345
355
|
"@langfuse/otel": "^5.10.1",
|
|
346
356
|
"@langfuse/tracing": "^5.10.1",
|
|
357
|
+
"@opentelemetry/api": "^1.9.0",
|
|
347
358
|
"@opentelemetry/context-async-hooks": "^2.9.0",
|
|
359
|
+
"@opentelemetry/exporter-trace-otlp-http": "0.220.0",
|
|
360
|
+
"@opentelemetry/otlp-exporter-base": "0.220.0",
|
|
348
361
|
"@opentelemetry/sdk-node": "^0.220.0",
|
|
349
362
|
"@types/diff": "^7.0.2",
|
|
363
|
+
"@types/ws": "^8.18.1",
|
|
350
364
|
"ai-tokenizer": "^1.0.6",
|
|
351
365
|
"axios": "^1.20.0",
|
|
352
366
|
"cheerio": "^1.2.0",
|
|
@@ -354,6 +368,8 @@
|
|
|
354
368
|
"dotenv": "^16.4.7",
|
|
355
369
|
"eventsource-parser": "^3.1.1",
|
|
356
370
|
"https-proxy-agent": "^7.0.6",
|
|
371
|
+
"jsonwebtoken": "^9.0.0",
|
|
372
|
+
"lodash": "^4.17.23",
|
|
357
373
|
"mathjs": "^15.2.0",
|
|
358
374
|
"nanoid": "^3.3.18",
|
|
359
375
|
"okapibm25": "^1.4.1",
|
|
@@ -361,6 +377,7 @@
|
|
|
361
377
|
"reova": "^0.4.1",
|
|
362
378
|
"socks-proxy-agent": "^8.0.5",
|
|
363
379
|
"uuid": "^11.1.1",
|
|
380
|
+
"ws": "^8.21.0",
|
|
364
381
|
"zod": "4.6.7",
|
|
365
382
|
"zod-to-json-schema": "3.25.2"
|
|
366
383
|
},
|
|
@@ -379,6 +396,8 @@
|
|
|
379
396
|
"@langchain/langgraph-checkpoint-mongodb": "^1.4.1",
|
|
380
397
|
"@swc/core": "^1.6.13",
|
|
381
398
|
"@types/jest": "^30.0.0",
|
|
399
|
+
"@types/jsonwebtoken": "^9.0.0",
|
|
400
|
+
"@types/lodash": "^4.17.0",
|
|
382
401
|
"@types/node": "^24.13.1",
|
|
383
402
|
"@types/node-fetch": "^2.6.13",
|
|
384
403
|
"@types/yargs-parser": "^21.0.3",
|
|
@@ -57,7 +57,9 @@ import {
|
|
|
57
57
|
Providers,
|
|
58
58
|
} from '@/common';
|
|
59
59
|
import { isTokenCounterCacheCompatible } from '@/llm/tokenCounterCacheCompatibility';
|
|
60
|
+
import { normalizeToBashIdentifier } from '@/tools/BashProgrammaticToolCalling';
|
|
60
61
|
import { snapshotCompactionSemanticIndex } from '@/summarization/semanticIndex';
|
|
62
|
+
import { normalizeToPythonIdentifier } from '@/tools/ProgrammaticToolCalling';
|
|
61
63
|
import { createExactTokenCountCache } from '@/llm/contextPressureMeter';
|
|
62
64
|
import { markProviderTextInput } from '@/protection/providerTextInput';
|
|
63
65
|
import { buildSummaryCarrierText } from '@/summarization/shared';
|
|
@@ -81,6 +83,7 @@ type PromptCacheProvider = Providers.ANTHROPIC | Providers.OPENROUTER;
|
|
|
81
83
|
type ProgrammaticToolInstructionTarget = {
|
|
82
84
|
name: string;
|
|
83
85
|
codeGuidance: string;
|
|
86
|
+
runtimes: Array<'Bash' | 'Python'>;
|
|
84
87
|
executesDirectly: boolean;
|
|
85
88
|
};
|
|
86
89
|
|
|
@@ -680,12 +683,73 @@ export class AgentContext {
|
|
|
680
683
|
.map((name) => `\`${name}\``)
|
|
681
684
|
.join(
|
|
682
685
|
', '
|
|
683
|
-
)}. Every ${programmaticRunnerNames} call must include a \`tool_manifest\` containing the
|
|
686
|
+
)}. Every ${programmaticRunnerNames} call must include a \`tool_manifest\` containing the registered names or sandbox names used by its code; the manifest is validated before execution starts.`
|
|
684
687
|
: '';
|
|
688
|
+
const runtimes = new Set(
|
|
689
|
+
programmaticTools.flatMap((tool) => tool.runtimes)
|
|
690
|
+
);
|
|
691
|
+
const identifierOwners = new Map<string, string | null>();
|
|
692
|
+
for (const runtime of runtimes) {
|
|
693
|
+
const normalizeIdentifier =
|
|
694
|
+
runtime === 'Bash'
|
|
695
|
+
? normalizeToBashIdentifier
|
|
696
|
+
: normalizeToPythonIdentifier;
|
|
697
|
+
for (const toolDefs of [
|
|
698
|
+
capabilities.codeExecutionTools,
|
|
699
|
+
capabilities.directOnlyTools,
|
|
700
|
+
]) {
|
|
701
|
+
for (const toolDef of toolDefs) {
|
|
702
|
+
const key = `${runtime}:${normalizeIdentifier(toolDef.name)}`;
|
|
703
|
+
const owner = identifierOwners.get(key);
|
|
704
|
+
identifierOwners.set(
|
|
705
|
+
key,
|
|
706
|
+
owner === undefined || owner === toolDef.name ? toolDef.name : null
|
|
707
|
+
);
|
|
708
|
+
}
|
|
709
|
+
}
|
|
710
|
+
}
|
|
711
|
+
const sandboxNames: string[] = [];
|
|
712
|
+
const collidingNames: string[] = [];
|
|
713
|
+
for (const toolDef of capabilities.codeExecutionTools) {
|
|
714
|
+
const names: string[] = [];
|
|
715
|
+
const collisions: string[] = [];
|
|
716
|
+
for (const runtime of runtimes) {
|
|
717
|
+
const identifier =
|
|
718
|
+
runtime === 'Bash'
|
|
719
|
+
? normalizeToBashIdentifier(toolDef.name)
|
|
720
|
+
: normalizeToPythonIdentifier(toolDef.name);
|
|
721
|
+
if (identifier === toolDef.name) {
|
|
722
|
+
continue;
|
|
723
|
+
}
|
|
724
|
+
if (identifierOwners.get(`${runtime}:${identifier}`) !== toolDef.name) {
|
|
725
|
+
collisions.push(`${runtime} code \`${identifier}\``);
|
|
726
|
+
} else {
|
|
727
|
+
names.push(`${runtime} \`${identifier}\``);
|
|
728
|
+
}
|
|
729
|
+
}
|
|
730
|
+
if (names.length > 0) {
|
|
731
|
+
sandboxNames.push(`- \`${toolDef.name}\`: ${names.join('; ')}`);
|
|
732
|
+
}
|
|
733
|
+
if (collisions.length > 0) {
|
|
734
|
+
collidingNames.push(`- \`${toolDef.name}\`: ${collisions.join('; ')}`);
|
|
735
|
+
}
|
|
736
|
+
}
|
|
737
|
+
const sandboxNameGuidance =
|
|
738
|
+
sandboxNames.length === 0
|
|
739
|
+
? ''
|
|
740
|
+
: '\n\nUse sandbox names in both code and `tool_manifest` for the tools below; registered names are also accepted in `tool_manifest`:\n' +
|
|
741
|
+
sandboxNames.join('\n');
|
|
742
|
+
const collidingNameGuidance =
|
|
743
|
+
collidingNames.length === 0
|
|
744
|
+
? ''
|
|
745
|
+
: '\n\nFor colliding sandbox names, use registered names in `tool_manifest` and sandbox names in code. Select only one tool per sandbox name:\n' +
|
|
746
|
+
collidingNames.join('\n');
|
|
685
747
|
const boundary =
|
|
686
748
|
'\n\n' +
|
|
687
749
|
`Only these tools may be invoked inside ${programmaticRunnerNames}: ${quotedProgrammaticNames}.` +
|
|
688
|
-
directOnlyBoundary
|
|
750
|
+
directOnlyBoundary +
|
|
751
|
+
sandboxNameGuidance +
|
|
752
|
+
collidingNameGuidance;
|
|
689
753
|
|
|
690
754
|
if (programmaticOnlyTools.length === 0) {
|
|
691
755
|
return boundary;
|
|
@@ -730,6 +794,7 @@ export class AgentContext {
|
|
|
730
794
|
targets.push({
|
|
731
795
|
name: Constants.BASH_PROGRAMMATIC_TOOL_CALLING,
|
|
732
796
|
codeGuidance: 'Bash code',
|
|
797
|
+
runtimes: ['Bash'],
|
|
733
798
|
executesDirectly: this.isProgrammaticRunnerDirectlyBound(
|
|
734
799
|
Constants.BASH_PROGRAMMATIC_TOOL_CALLING
|
|
735
800
|
),
|
|
@@ -751,6 +816,7 @@ export class AgentContext {
|
|
|
751
816
|
codeGuidance: localDefault
|
|
752
817
|
? 'Bash code by default, or set `lang: "py"` to use Python code'
|
|
753
818
|
: 'Python code',
|
|
819
|
+
runtimes: localDefault ? ['Bash', 'Python'] : ['Python'],
|
|
754
820
|
executesDirectly: this.isProgrammaticRunnerDirectlyBound(
|
|
755
821
|
Constants.PROGRAMMATIC_TOOL_CALLING
|
|
756
822
|
),
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
HostFileDescriptor,
|
|
3
|
+
HostFileStageRequest,
|
|
4
|
+
HostFileReadRequest,
|
|
5
|
+
HostFilePublication,
|
|
6
|
+
HostFileServiceDescriptor,
|
|
7
|
+
HostFileService,
|
|
8
|
+
} from './files';
|
|
9
|
+
import type { ExecutionIdentity } from './identity';
|
|
10
|
+
import {
|
|
11
|
+
HostFileServiceError,
|
|
12
|
+
normalizeHostFileError,
|
|
13
|
+
checkedHostFile,
|
|
14
|
+
checkedHostFileChunk,
|
|
15
|
+
checkedHostFileService,
|
|
16
|
+
hostFileStageRequestSchema,
|
|
17
|
+
hostFilePublishRequestSchema,
|
|
18
|
+
} from './files';
|
|
19
|
+
import { snapshotExecutionIdentity } from './identity';
|
|
20
|
+
import { createFileUpload } from './fileStream';
|
|
21
|
+
|
|
22
|
+
export interface HostFileBindings {
|
|
23
|
+
read(
|
|
24
|
+
file: HostFileDescriptor,
|
|
25
|
+
signal?: AbortSignal
|
|
26
|
+
): AsyncIterable<Uint8Array>;
|
|
27
|
+
stage(
|
|
28
|
+
artifact: Omit<HostFileStageRequest, 'version' | 'identity'>,
|
|
29
|
+
content: AsyncIterable<Uint8Array>,
|
|
30
|
+
signal?: AbortSignal
|
|
31
|
+
): Promise<HostFileDescriptor>;
|
|
32
|
+
publish(
|
|
33
|
+
file: HostFileDescriptor,
|
|
34
|
+
operationId: string,
|
|
35
|
+
signal?: AbortSignal
|
|
36
|
+
): Promise<HostFilePublication>;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** Pull-based graph adapter; at most one range or upload chunk is requested at a time. */
|
|
40
|
+
export function createHostFileBindings(options: {
|
|
41
|
+
identity: Readonly<ExecutionIdentity>;
|
|
42
|
+
descriptor: HostFileServiceDescriptor;
|
|
43
|
+
service: HostFileService;
|
|
44
|
+
}): HostFileBindings {
|
|
45
|
+
const identity = snapshotExecutionIdentity(options.identity);
|
|
46
|
+
const descriptor = checkedHostFileService(options.descriptor);
|
|
47
|
+
const service = options.service;
|
|
48
|
+
if (Number(service.version) !== 1)
|
|
49
|
+
throw new HostFileServiceError('incompatible');
|
|
50
|
+
function allow(
|
|
51
|
+
operation: HostFileServiceDescriptor['operations'][number],
|
|
52
|
+
signal?: AbortSignal
|
|
53
|
+
): void {
|
|
54
|
+
if (!descriptor.operations.includes(operation))
|
|
55
|
+
throw new HostFileServiceError('forbidden');
|
|
56
|
+
if (signal?.aborted === true) throw new HostFileServiceError('cancelled');
|
|
57
|
+
}
|
|
58
|
+
return {
|
|
59
|
+
read: async function* (source, signal): AsyncGenerator<Uint8Array> {
|
|
60
|
+
try {
|
|
61
|
+
allow('read', signal);
|
|
62
|
+
const file = checkedHostFile(source);
|
|
63
|
+
if (file.bytes > descriptor.maxFileBytes)
|
|
64
|
+
throw new HostFileServiceError('overflow');
|
|
65
|
+
for (let offset = 0; offset < file.bytes; ) {
|
|
66
|
+
allow('read', signal);
|
|
67
|
+
const input: HostFileReadRequest = {
|
|
68
|
+
version: 1,
|
|
69
|
+
identity,
|
|
70
|
+
reference: file.reference,
|
|
71
|
+
revision: file.revision,
|
|
72
|
+
offset,
|
|
73
|
+
length: Math.min(descriptor.maxChunkBytes, file.bytes - offset),
|
|
74
|
+
};
|
|
75
|
+
const chunk = checkedHostFileChunk(
|
|
76
|
+
await service.read(input, signal),
|
|
77
|
+
input
|
|
78
|
+
);
|
|
79
|
+
allow('read', signal);
|
|
80
|
+
offset += chunk.data.byteLength;
|
|
81
|
+
yield chunk.data;
|
|
82
|
+
}
|
|
83
|
+
} catch (error) {
|
|
84
|
+
throw normalizeHostFileError(error, signal);
|
|
85
|
+
}
|
|
86
|
+
},
|
|
87
|
+
stage: async (artifact, content, signal): Promise<HostFileDescriptor> => {
|
|
88
|
+
try {
|
|
89
|
+
allow('stage', signal);
|
|
90
|
+
const parsed = hostFileStageRequestSchema.safeParse({
|
|
91
|
+
...artifact,
|
|
92
|
+
version: 1,
|
|
93
|
+
identity,
|
|
94
|
+
});
|
|
95
|
+
if (!parsed.success) throw new HostFileServiceError('incompatible');
|
|
96
|
+
if (parsed.data.bytes > descriptor.maxFileBytes)
|
|
97
|
+
throw new HostFileServiceError('overflow');
|
|
98
|
+
const upload = createFileUpload(
|
|
99
|
+
content,
|
|
100
|
+
parsed.data,
|
|
101
|
+
descriptor.maxChunkBytes,
|
|
102
|
+
signal
|
|
103
|
+
);
|
|
104
|
+
try {
|
|
105
|
+
const file = checkedHostFile(
|
|
106
|
+
await service.stage(parsed.data, upload.content, signal)
|
|
107
|
+
);
|
|
108
|
+
upload.finish();
|
|
109
|
+
allow('stage', signal);
|
|
110
|
+
if (
|
|
111
|
+
file.sha256 === undefined ||
|
|
112
|
+
file.bytes !== parsed.data.bytes ||
|
|
113
|
+
(parsed.data.sha256 !== undefined &&
|
|
114
|
+
file.sha256 !== parsed.data.sha256)
|
|
115
|
+
)
|
|
116
|
+
throw new HostFileServiceError('incompatible');
|
|
117
|
+
return file;
|
|
118
|
+
} finally {
|
|
119
|
+
/** The host retains admission until source cleanup settles. Do not delay
|
|
120
|
+
* a cancellation/timeout response on an uncooperative producer here. */
|
|
121
|
+
void upload.close().catch(() => undefined);
|
|
122
|
+
}
|
|
123
|
+
} catch (error) {
|
|
124
|
+
throw normalizeHostFileError(error, signal);
|
|
125
|
+
}
|
|
126
|
+
},
|
|
127
|
+
publish: async (
|
|
128
|
+
source,
|
|
129
|
+
operationId,
|
|
130
|
+
signal
|
|
131
|
+
): Promise<HostFilePublication> => {
|
|
132
|
+
try {
|
|
133
|
+
allow('publish', signal);
|
|
134
|
+
const file = checkedHostFile(source);
|
|
135
|
+
const parsed = hostFilePublishRequestSchema.safeParse({
|
|
136
|
+
version: 1,
|
|
137
|
+
identity,
|
|
138
|
+
operationId,
|
|
139
|
+
reference: file.reference,
|
|
140
|
+
revision: file.revision,
|
|
141
|
+
});
|
|
142
|
+
if (!parsed.success) throw new HostFileServiceError('incompatible');
|
|
143
|
+
const result = await service.publish(parsed.data, signal);
|
|
144
|
+
allow('publish', signal);
|
|
145
|
+
if (result.operationId !== operationId)
|
|
146
|
+
throw new HostFileServiceError('incompatible');
|
|
147
|
+
const published = checkedHostFile(result.file);
|
|
148
|
+
if (published.bytes > descriptor.maxFileBytes)
|
|
149
|
+
throw new HostFileServiceError('overflow');
|
|
150
|
+
return { operationId, file: published };
|
|
151
|
+
} catch (error) {
|
|
152
|
+
throw normalizeHostFileError(error, signal);
|
|
153
|
+
}
|
|
154
|
+
},
|
|
155
|
+
};
|
|
156
|
+
}
|
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
HostFileService,
|
|
3
|
+
HostFileChunk,
|
|
4
|
+
HostFileDescriptor,
|
|
5
|
+
HostFilePublication,
|
|
6
|
+
HostFileServiceDescriptor,
|
|
7
|
+
HostFileReadRequest,
|
|
8
|
+
HostFileStageRequest,
|
|
9
|
+
HostFilePublishRequest,
|
|
10
|
+
} from './files';
|
|
11
|
+
import type { ExecutionIdentity } from './identity';
|
|
12
|
+
import {
|
|
13
|
+
HostFileServiceError,
|
|
14
|
+
normalizeHostFileError,
|
|
15
|
+
checkedHostFile,
|
|
16
|
+
checkedHostFileChunk,
|
|
17
|
+
checkedHostFileService,
|
|
18
|
+
hostFileReadRequestSchema,
|
|
19
|
+
hostFileStageRequestSchema,
|
|
20
|
+
hostFilePublishRequestSchema,
|
|
21
|
+
} from './files';
|
|
22
|
+
import {
|
|
23
|
+
snapshotExecutionIdentity,
|
|
24
|
+
matchesExecutionIdentity,
|
|
25
|
+
} from './identity';
|
|
26
|
+
import { createFileUpload } from './fileStream';
|
|
27
|
+
|
|
28
|
+
function positive(value: number): void {
|
|
29
|
+
if (!Number.isSafeInteger(value) || value <= 0)
|
|
30
|
+
throw new HostFileServiceError('incompatible');
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** Share across bindings in the host's quota scope. Hung storage retains its slot and byte reservation. */
|
|
34
|
+
export class HostFileAdmission {
|
|
35
|
+
private operations = 0;
|
|
36
|
+
private bytes = 0;
|
|
37
|
+
private readonly maxConcurrentOperations: number;
|
|
38
|
+
private readonly maxBufferedBytes: number;
|
|
39
|
+
constructor(limits: {
|
|
40
|
+
maxConcurrentOperations: number;
|
|
41
|
+
maxBufferedBytes: number;
|
|
42
|
+
}) {
|
|
43
|
+
positive(limits.maxConcurrentOperations);
|
|
44
|
+
positive(limits.maxBufferedBytes);
|
|
45
|
+
this.maxConcurrentOperations = limits.maxConcurrentOperations;
|
|
46
|
+
this.maxBufferedBytes = limits.maxBufferedBytes;
|
|
47
|
+
}
|
|
48
|
+
snapshot(): Readonly<{ operations: number; reservedBytes: number }> {
|
|
49
|
+
return Object.freeze({
|
|
50
|
+
operations: this.operations,
|
|
51
|
+
reservedBytes: this.bytes,
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
/** @internal Reservations are released only when storage and input cleanup settle. */
|
|
55
|
+
acquire(bytes: number): () => void {
|
|
56
|
+
if (!Number.isSafeInteger(bytes) || bytes < 0)
|
|
57
|
+
throw new HostFileServiceError('incompatible');
|
|
58
|
+
if (
|
|
59
|
+
this.operations >= this.maxConcurrentOperations ||
|
|
60
|
+
bytes > this.maxBufferedBytes - this.bytes
|
|
61
|
+
)
|
|
62
|
+
throw new HostFileServiceError('overflow');
|
|
63
|
+
this.operations++;
|
|
64
|
+
this.bytes += bytes;
|
|
65
|
+
let released = false;
|
|
66
|
+
return () => {
|
|
67
|
+
if (released) return;
|
|
68
|
+
released = true;
|
|
69
|
+
this.operations--;
|
|
70
|
+
this.bytes -= bytes;
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* The host adapter owns canonical ACL/revision checks on every operation, durable operation-ID
|
|
77
|
+
* reconciliation, private staging/cleanup, and publication through the native file pipeline.
|
|
78
|
+
* A request identity is asserted against the authenticated binding before any adapter call.
|
|
79
|
+
*/
|
|
80
|
+
export type HostFileStore = Omit<HostFileService, 'version'>;
|
|
81
|
+
|
|
82
|
+
export function createHostFileService(options: {
|
|
83
|
+
identity: Readonly<ExecutionIdentity>;
|
|
84
|
+
descriptor: HostFileServiceDescriptor;
|
|
85
|
+
store: HostFileStore;
|
|
86
|
+
admission: HostFileAdmission;
|
|
87
|
+
timeoutMs: number;
|
|
88
|
+
/** Lifetime of the authenticated execution, independent of individual RPC cancellation. */
|
|
89
|
+
signal?: AbortSignal;
|
|
90
|
+
}): { descriptor: HostFileServiceDescriptor; service: HostFileService } {
|
|
91
|
+
const identity = snapshotExecutionIdentity(options.identity);
|
|
92
|
+
const descriptor = checkedHostFileService(options.descriptor);
|
|
93
|
+
const { store, admission, timeoutMs, signal: runSignal } = options;
|
|
94
|
+
positive(timeoutMs);
|
|
95
|
+
if (timeoutMs > 2147483647) throw new HostFileServiceError('incompatible');
|
|
96
|
+
|
|
97
|
+
function authorize(
|
|
98
|
+
operation: HostFileServiceDescriptor['operations'][number],
|
|
99
|
+
value: ExecutionIdentity
|
|
100
|
+
): void {
|
|
101
|
+
if (
|
|
102
|
+
!descriptor.operations.includes(operation) ||
|
|
103
|
+
!matchesExecutionIdentity(identity, value)
|
|
104
|
+
)
|
|
105
|
+
throw new HostFileServiceError('forbidden');
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
async function execute<T>(
|
|
109
|
+
bytes: number,
|
|
110
|
+
signal: AbortSignal | undefined,
|
|
111
|
+
work: (signal: AbortSignal) => Promise<T>
|
|
112
|
+
): Promise<T> {
|
|
113
|
+
const parent =
|
|
114
|
+
runSignal && signal
|
|
115
|
+
? AbortSignal.any([runSignal, signal])
|
|
116
|
+
: (runSignal ?? signal);
|
|
117
|
+
if (parent?.aborted === true) throw new HostFileServiceError('cancelled');
|
|
118
|
+
const release = admission.acquire(bytes);
|
|
119
|
+
const controller = new AbortController();
|
|
120
|
+
const cancel = (): void =>
|
|
121
|
+
controller.abort(new HostFileServiceError('cancelled'));
|
|
122
|
+
parent?.addEventListener('abort', cancel, { once: true });
|
|
123
|
+
const timer = setTimeout(
|
|
124
|
+
() => controller.abort(new HostFileServiceError('timeout')),
|
|
125
|
+
timeoutMs
|
|
126
|
+
);
|
|
127
|
+
timer.unref();
|
|
128
|
+
let onAbort = (): void => undefined;
|
|
129
|
+
const aborted = new Promise<never>((_resolve, reject) => {
|
|
130
|
+
onAbort = (): void =>
|
|
131
|
+
reject(normalizeHostFileError(undefined, controller.signal));
|
|
132
|
+
controller.signal.addEventListener('abort', onAbort, { once: true });
|
|
133
|
+
});
|
|
134
|
+
const pending = Promise.resolve()
|
|
135
|
+
.then(async () => {
|
|
136
|
+
controller.signal.throwIfAborted();
|
|
137
|
+
return work(controller.signal);
|
|
138
|
+
})
|
|
139
|
+
.finally(release);
|
|
140
|
+
try {
|
|
141
|
+
const result = await Promise.race([pending, aborted]);
|
|
142
|
+
controller.signal.throwIfAborted();
|
|
143
|
+
return result;
|
|
144
|
+
} catch (error) {
|
|
145
|
+
throw normalizeHostFileError(error, controller.signal);
|
|
146
|
+
} finally {
|
|
147
|
+
clearTimeout(timer);
|
|
148
|
+
parent?.removeEventListener('abort', cancel);
|
|
149
|
+
controller.signal.removeEventListener('abort', onAbort);
|
|
150
|
+
controller.abort();
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
return {
|
|
155
|
+
descriptor,
|
|
156
|
+
service: {
|
|
157
|
+
version: 1,
|
|
158
|
+
read: async (input, signal): Promise<HostFileChunk> => {
|
|
159
|
+
const parsed = hostFileReadRequestSchema.safeParse(input);
|
|
160
|
+
if (!parsed.success) throw new HostFileServiceError('incompatible');
|
|
161
|
+
const request: HostFileReadRequest = { ...parsed.data, identity };
|
|
162
|
+
authorize('read', parsed.data.identity);
|
|
163
|
+
if (
|
|
164
|
+
request.length > descriptor.maxChunkBytes ||
|
|
165
|
+
request.offset > descriptor.maxFileBytes - request.length
|
|
166
|
+
)
|
|
167
|
+
throw new HostFileServiceError('overflow');
|
|
168
|
+
return execute(request.length * 2, signal, async (active) =>
|
|
169
|
+
checkedHostFileChunk(await store.read(request, active), request)
|
|
170
|
+
);
|
|
171
|
+
},
|
|
172
|
+
stage: async (input, content, signal): Promise<HostFileDescriptor> => {
|
|
173
|
+
const parsed = hostFileStageRequestSchema.safeParse(input);
|
|
174
|
+
if (!parsed.success) throw new HostFileServiceError('incompatible');
|
|
175
|
+
authorize('stage', parsed.data.identity);
|
|
176
|
+
const request: HostFileStageRequest = { ...parsed.data, identity };
|
|
177
|
+
if (request.bytes > descriptor.maxFileBytes)
|
|
178
|
+
throw new HostFileServiceError('overflow');
|
|
179
|
+
return execute(descriptor.maxChunkBytes * 2, signal, async (active) => {
|
|
180
|
+
const upload = createFileUpload(
|
|
181
|
+
content,
|
|
182
|
+
request,
|
|
183
|
+
descriptor.maxChunkBytes,
|
|
184
|
+
active,
|
|
185
|
+
true
|
|
186
|
+
);
|
|
187
|
+
try {
|
|
188
|
+
const file = checkedHostFile(
|
|
189
|
+
await store.stage(request, upload.content, active)
|
|
190
|
+
);
|
|
191
|
+
const sha256 = upload.finish();
|
|
192
|
+
if (file.bytes !== request.bytes || file.sha256 !== sha256)
|
|
193
|
+
throw new HostFileServiceError('incompatible');
|
|
194
|
+
return file;
|
|
195
|
+
} finally {
|
|
196
|
+
await upload.close();
|
|
197
|
+
}
|
|
198
|
+
});
|
|
199
|
+
},
|
|
200
|
+
publish: async (input, signal): Promise<HostFilePublication> => {
|
|
201
|
+
const parsed = hostFilePublishRequestSchema.safeParse(input);
|
|
202
|
+
if (!parsed.success) throw new HostFileServiceError('incompatible');
|
|
203
|
+
authorize('publish', parsed.data.identity);
|
|
204
|
+
const request: HostFilePublishRequest = { ...parsed.data, identity };
|
|
205
|
+
return execute(0, signal, async (active) => {
|
|
206
|
+
const result = await store.publish(request, active);
|
|
207
|
+
if (result.operationId !== request.operationId)
|
|
208
|
+
throw new HostFileServiceError('incompatible');
|
|
209
|
+
const file = checkedHostFile(result.file);
|
|
210
|
+
if (file.bytes > descriptor.maxFileBytes)
|
|
211
|
+
throw new HostFileServiceError('overflow');
|
|
212
|
+
return { operationId: request.operationId, file };
|
|
213
|
+
});
|
|
214
|
+
},
|
|
215
|
+
},
|
|
216
|
+
};
|
|
217
|
+
}
|