@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,243 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { randomUUID } from 'node:crypto';
|
|
3
|
+
import type {
|
|
4
|
+
EventHandler,
|
|
5
|
+
HostToolDescriptor,
|
|
6
|
+
HostToolRequest,
|
|
7
|
+
HostToolService,
|
|
8
|
+
HostToolEvents,
|
|
9
|
+
HostToolSessionUpdate,
|
|
10
|
+
ToolExecuteResult,
|
|
11
|
+
} from '@/index';
|
|
12
|
+
import type { SdkAgentIdentity } from './identity';
|
|
13
|
+
import type { SdkRpc } from './peer';
|
|
14
|
+
import { GraphEvents } from '@/index';
|
|
15
|
+
|
|
16
|
+
const toolResultSchema = z.object({
|
|
17
|
+
id: z.string().uuid(),
|
|
18
|
+
result: z
|
|
19
|
+
.object({
|
|
20
|
+
toolCallId: z.string().min(1),
|
|
21
|
+
status: z.enum(['success', 'error']),
|
|
22
|
+
})
|
|
23
|
+
.passthrough(),
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
/** Local credentials/configuration are supplied by the authenticated host, never by the worker. */
|
|
27
|
+
export function createHostToolService(options: {
|
|
28
|
+
identity: Readonly<SdkAgentIdentity>;
|
|
29
|
+
tools: HostToolDescriptor[];
|
|
30
|
+
handler: EventHandler;
|
|
31
|
+
graph?: Parameters<EventHandler['handle']>[3];
|
|
32
|
+
configurable: Record<string, unknown>;
|
|
33
|
+
metadata?: Record<string, unknown>;
|
|
34
|
+
peer: { call: SdkRpc };
|
|
35
|
+
signal: AbortSignal;
|
|
36
|
+
}): (
|
|
37
|
+
data: unknown,
|
|
38
|
+
invocationSignal?: AbortSignal
|
|
39
|
+
) => Promise<ToolExecuteResult[]> {
|
|
40
|
+
const references = new Map(
|
|
41
|
+
options.tools.map((t) => [t.definition.name, t.reference])
|
|
42
|
+
);
|
|
43
|
+
return async (
|
|
44
|
+
data: unknown,
|
|
45
|
+
invocationSignal?: AbortSignal
|
|
46
|
+
): Promise<ToolExecuteResult[]> => {
|
|
47
|
+
const signal = invocationSignal
|
|
48
|
+
? AbortSignal.any([options.signal, invocationSignal])
|
|
49
|
+
: options.signal;
|
|
50
|
+
const envelope = z
|
|
51
|
+
.object({
|
|
52
|
+
id: z.string().uuid(),
|
|
53
|
+
incremental: z.boolean(),
|
|
54
|
+
request: z.object({
|
|
55
|
+
version: z.literal(1),
|
|
56
|
+
identity: z.record(z.string(), z.unknown()),
|
|
57
|
+
executingAgentId: z.string().optional(),
|
|
58
|
+
executionContext: z.unknown().optional(),
|
|
59
|
+
callerCapabilityProjection: z.unknown().optional(),
|
|
60
|
+
calls: z
|
|
61
|
+
.array(
|
|
62
|
+
z.object({
|
|
63
|
+
reference: z.string(),
|
|
64
|
+
call: z
|
|
65
|
+
.object({
|
|
66
|
+
id: z.string().min(1),
|
|
67
|
+
name: z.string(),
|
|
68
|
+
args: z.record(z.string(), z.unknown()),
|
|
69
|
+
})
|
|
70
|
+
.passthrough(),
|
|
71
|
+
})
|
|
72
|
+
)
|
|
73
|
+
.min(1),
|
|
74
|
+
}),
|
|
75
|
+
})
|
|
76
|
+
.parse(data);
|
|
77
|
+
const request = envelope.request as HostToolRequest;
|
|
78
|
+
for (const key of [
|
|
79
|
+
'runtimeId',
|
|
80
|
+
'agentId',
|
|
81
|
+
'runId',
|
|
82
|
+
'userId',
|
|
83
|
+
'tenantId',
|
|
84
|
+
'conversationId',
|
|
85
|
+
] as const)
|
|
86
|
+
if (request.identity[key] !== options.identity[key])
|
|
87
|
+
throw new Error('Host tool identity mismatch');
|
|
88
|
+
if (
|
|
89
|
+
request.executionContext !== undefined ||
|
|
90
|
+
(request.executingAgentId !== undefined &&
|
|
91
|
+
request.executingAgentId !== options.identity.agentId)
|
|
92
|
+
)
|
|
93
|
+
throw new Error('Host tool execution subject is unsupported');
|
|
94
|
+
const ids = new Set<string>();
|
|
95
|
+
for (const { call, reference } of request.calls) {
|
|
96
|
+
if (references.get(call.name) !== reference || ids.has(call.id))
|
|
97
|
+
throw new Error('Host tool capability mismatch');
|
|
98
|
+
ids.add(call.id);
|
|
99
|
+
}
|
|
100
|
+
signal.throwIfAborted();
|
|
101
|
+
const notifications: Promise<unknown>[] = [];
|
|
102
|
+
let active = true;
|
|
103
|
+
let resolve!: (results: ToolExecuteResult[]) => void;
|
|
104
|
+
let reject!: (error: Error) => void;
|
|
105
|
+
const result = new Promise<ToolExecuteResult[]>((yes, no) => {
|
|
106
|
+
resolve = yes;
|
|
107
|
+
reject = no;
|
|
108
|
+
});
|
|
109
|
+
// Install rejection handling before invoking a handler that may reject synchronously.
|
|
110
|
+
void result.catch(() => undefined);
|
|
111
|
+
const abort = (): void =>
|
|
112
|
+
reject(new Error('Host tool invocation cancelled'));
|
|
113
|
+
signal.addEventListener('abort', abort, { once: true });
|
|
114
|
+
try {
|
|
115
|
+
await options.handler.handle(
|
|
116
|
+
GraphEvents.ON_TOOL_EXECUTE,
|
|
117
|
+
{
|
|
118
|
+
toolCalls: request.calls.map((c) => c.call),
|
|
119
|
+
userId: options.identity.userId,
|
|
120
|
+
agentId: options.identity.agentId,
|
|
121
|
+
configurable: options.configurable,
|
|
122
|
+
metadata: options.metadata,
|
|
123
|
+
callerCapabilityProjection: request.callerCapabilityProjection,
|
|
124
|
+
signal,
|
|
125
|
+
resolve,
|
|
126
|
+
reject,
|
|
127
|
+
...(envelope.incremental
|
|
128
|
+
? {
|
|
129
|
+
onResult: (value: ToolExecuteResult): void => {
|
|
130
|
+
if (!active || signal.aborted) return;
|
|
131
|
+
if (!ids.has(value.toolCallId))
|
|
132
|
+
throw new Error('Invalid incremental tool receipt');
|
|
133
|
+
const notice = options.peer.call('tool.result', {
|
|
134
|
+
id: envelope.id,
|
|
135
|
+
result: value,
|
|
136
|
+
});
|
|
137
|
+
void notice.catch(() => undefined);
|
|
138
|
+
notifications.push(notice);
|
|
139
|
+
},
|
|
140
|
+
}
|
|
141
|
+
: {}),
|
|
142
|
+
},
|
|
143
|
+
options.metadata,
|
|
144
|
+
options.graph
|
|
145
|
+
);
|
|
146
|
+
// Handler settlement is the drain boundary: async cancellation cleanup may refresh
|
|
147
|
+
// sessions. Never publish a final receipt while that cleanup is still running.
|
|
148
|
+
signal.throwIfAborted();
|
|
149
|
+
const results = await result;
|
|
150
|
+
active = false;
|
|
151
|
+
await Promise.all(notifications);
|
|
152
|
+
signal.throwIfAborted();
|
|
153
|
+
return results;
|
|
154
|
+
} finally {
|
|
155
|
+
active = false;
|
|
156
|
+
signal.removeEventListener('abort', abort);
|
|
157
|
+
for (const { call } of request.calls) {
|
|
158
|
+
notifications.push(
|
|
159
|
+
options.peer.call('tool.session', {
|
|
160
|
+
id: envelope.id,
|
|
161
|
+
update: {
|
|
162
|
+
toolCallId: call.id,
|
|
163
|
+
context: {
|
|
164
|
+
codeSessionContext: call.codeSessionContext,
|
|
165
|
+
codeSessionBaselineId: call.codeSessionBaselineId,
|
|
166
|
+
retainCodeSessionInputs: call.retainCodeSessionInputs,
|
|
167
|
+
runtimeSessionHint: call.runtimeSessionHint,
|
|
168
|
+
},
|
|
169
|
+
},
|
|
170
|
+
})
|
|
171
|
+
);
|
|
172
|
+
}
|
|
173
|
+
await Promise.all(notifications);
|
|
174
|
+
signal.throwIfAborted();
|
|
175
|
+
}
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
export function createWorkerToolService(peer: { call: SdkRpc }): {
|
|
180
|
+
service: HostToolService;
|
|
181
|
+
accept: (data: unknown, kind?: 'result' | 'session') => null;
|
|
182
|
+
} {
|
|
183
|
+
const pending = new Map<
|
|
184
|
+
string,
|
|
185
|
+
{ events: HostToolEvents; signal?: AbortSignal }
|
|
186
|
+
>();
|
|
187
|
+
return {
|
|
188
|
+
service: {
|
|
189
|
+
version: 1,
|
|
190
|
+
invoke: async (request, signal, events): Promise<ToolExecuteResult[]> => {
|
|
191
|
+
signal?.throwIfAborted();
|
|
192
|
+
const id = randomUUID();
|
|
193
|
+
if (events) pending.set(id, { events, signal });
|
|
194
|
+
try {
|
|
195
|
+
return (await peer.call(
|
|
196
|
+
'tools',
|
|
197
|
+
{
|
|
198
|
+
id,
|
|
199
|
+
request,
|
|
200
|
+
incremental: Boolean(events?.onResult),
|
|
201
|
+
},
|
|
202
|
+
undefined,
|
|
203
|
+
signal
|
|
204
|
+
)) as ToolExecuteResult[];
|
|
205
|
+
} finally {
|
|
206
|
+
pending.delete(id);
|
|
207
|
+
}
|
|
208
|
+
},
|
|
209
|
+
},
|
|
210
|
+
accept: (data, kind = 'result'): null => {
|
|
211
|
+
if (kind === 'session') {
|
|
212
|
+
const value = z
|
|
213
|
+
.object({
|
|
214
|
+
id: z.string().uuid(),
|
|
215
|
+
update: z
|
|
216
|
+
.object({
|
|
217
|
+
toolCallId: z.string(),
|
|
218
|
+
context: z
|
|
219
|
+
.object({
|
|
220
|
+
codeSessionContext: z.unknown().optional(),
|
|
221
|
+
codeSessionBaselineId: z.string().optional(),
|
|
222
|
+
retainCodeSessionInputs: z.literal(true).optional(),
|
|
223
|
+
runtimeSessionHint: z.string().optional(),
|
|
224
|
+
})
|
|
225
|
+
.strict(),
|
|
226
|
+
})
|
|
227
|
+
.strict(),
|
|
228
|
+
})
|
|
229
|
+
.parse(data);
|
|
230
|
+
const events = pending.get(value.id);
|
|
231
|
+
if (!events) throw new Error('Unknown tool session invocation');
|
|
232
|
+
events.events.onSessionUpdate(value.update as HostToolSessionUpdate);
|
|
233
|
+
return null;
|
|
234
|
+
}
|
|
235
|
+
const value = toolResultSchema.parse(data);
|
|
236
|
+
const handler = pending.get(value.id);
|
|
237
|
+
if (!handler) throw new Error('Unknown tool result invocation');
|
|
238
|
+
if (handler.signal?.aborted !== true)
|
|
239
|
+
handler.events.onResult?.(value.result as ToolExecuteResult);
|
|
240
|
+
return null;
|
|
241
|
+
},
|
|
242
|
+
};
|
|
243
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
export { createRemoteSdkServer } from './server';
|
|
2
|
+
export { createRemoteSdkRun } from './client';
|
|
3
|
+
export { createRedisRuntimeJournal } from './recovery/redis';
|
|
4
|
+
export type { RemoteSdkServerOptions } from './server';
|
|
5
|
+
export type { SdkAgentIdentity } from './identity';
|
|
6
|
+
export type {
|
|
7
|
+
RemoteSdkFactoryInput,
|
|
8
|
+
RemoteSdkHostServices,
|
|
9
|
+
RemoteSdkOptions,
|
|
10
|
+
RemoteSdkResumeState,
|
|
11
|
+
RemoteSdkLimits,
|
|
12
|
+
RemoteSdkModelProfile,
|
|
13
|
+
} from './types';
|
|
14
|
+
export type { HostModelLifecycle, RemoteModelAttempt } from './admission';
|
|
15
|
+
export type {
|
|
16
|
+
RuntimeJournalRedis,
|
|
17
|
+
RuntimeJournalLimits,
|
|
18
|
+
} from './recovery/redis';
|
|
19
|
+
export type {
|
|
20
|
+
RuntimeJournal,
|
|
21
|
+
RuntimeJournalSession,
|
|
22
|
+
RuntimeJournalLease,
|
|
23
|
+
RuntimeJournalResult,
|
|
24
|
+
RuntimeJournalState,
|
|
25
|
+
RuntimeJournalFailure,
|
|
26
|
+
} from './recovery/journal';
|
|
27
|
+
export type { RuntimeRecoveryOptions } from './recovery/server';
|
|
28
|
+
export type { RemoteSdkRecoveryOptions } from './types';
|
|
29
|
+
export {
|
|
30
|
+
normalizeResumeRunStepIndices,
|
|
31
|
+
hydrateResumeRunSteps,
|
|
32
|
+
createContentIndexOffsetHandlers,
|
|
33
|
+
} from './resume';
|