@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,150 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import type {
|
|
3
|
+
HostProviderTextDescriptor,
|
|
4
|
+
ProviderTextProtectionErrorCode,
|
|
5
|
+
ProviderTextProtection,
|
|
6
|
+
HostProviderTextRequest,
|
|
7
|
+
} from '@/index';
|
|
8
|
+
import type {
|
|
9
|
+
RemoteSdkHostServices,
|
|
10
|
+
RemoteSdkStart,
|
|
11
|
+
RemoteSdkLimits,
|
|
12
|
+
} from './types';
|
|
13
|
+
import type { SdkAgentIdentity } from './identity';
|
|
14
|
+
import type { SdkRpc } from './peer';
|
|
15
|
+
import {
|
|
16
|
+
createHostProviderTextProtection,
|
|
17
|
+
serializeProviderTextProtectionError,
|
|
18
|
+
deserializeProviderTextProtectionError,
|
|
19
|
+
ProviderTextProtectionError,
|
|
20
|
+
} from '@/index';
|
|
21
|
+
import { createPolicyReceiver, createPolicySender } from './sealed';
|
|
22
|
+
|
|
23
|
+
export const policyDescriptorSchema = z
|
|
24
|
+
.object({
|
|
25
|
+
version: z.literal(1),
|
|
26
|
+
publicKey: z.string().length(60),
|
|
27
|
+
limits: z
|
|
28
|
+
.object({
|
|
29
|
+
version: z.literal(1),
|
|
30
|
+
timeoutMs: z.number().int().positive().max(2_147_483_647),
|
|
31
|
+
maxAttemptBytes: z
|
|
32
|
+
.number()
|
|
33
|
+
.int()
|
|
34
|
+
.positive()
|
|
35
|
+
.max(Number.MAX_SAFE_INTEGER),
|
|
36
|
+
maxBufferedBytes: z
|
|
37
|
+
.number()
|
|
38
|
+
.int()
|
|
39
|
+
.positive()
|
|
40
|
+
.max(Number.MAX_SAFE_INTEGER),
|
|
41
|
+
})
|
|
42
|
+
.strict(),
|
|
43
|
+
})
|
|
44
|
+
.strict();
|
|
45
|
+
|
|
46
|
+
/** Only sanitized failures and approved canonical text enter the peer's reply/logging path. */
|
|
47
|
+
export function createHostPolicyChannel(
|
|
48
|
+
providerText: NonNullable<RemoteSdkHostServices['providerText']>,
|
|
49
|
+
limits: RemoteSdkLimits
|
|
50
|
+
): {
|
|
51
|
+
descriptor: {
|
|
52
|
+
version: 1;
|
|
53
|
+
publicKey: string;
|
|
54
|
+
limits: HostProviderTextDescriptor;
|
|
55
|
+
};
|
|
56
|
+
dispose: () => void;
|
|
57
|
+
inspect: (
|
|
58
|
+
data: unknown,
|
|
59
|
+
signal?: AbortSignal
|
|
60
|
+
) => Promise<
|
|
61
|
+
| {
|
|
62
|
+
readonly version: 1;
|
|
63
|
+
readonly ok: false;
|
|
64
|
+
readonly error: {
|
|
65
|
+
readonly code: ProviderTextProtectionErrorCode;
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
| { version: 1; ok: true; content: string }
|
|
69
|
+
>;
|
|
70
|
+
} {
|
|
71
|
+
const receiver = createPolicyReceiver(limits.maxFrameBytes);
|
|
72
|
+
return {
|
|
73
|
+
descriptor: {
|
|
74
|
+
version: 1 as const,
|
|
75
|
+
publicKey: receiver.publicKey,
|
|
76
|
+
limits: providerText.descriptor,
|
|
77
|
+
},
|
|
78
|
+
dispose: receiver.dispose,
|
|
79
|
+
inspect: async (
|
|
80
|
+
data: unknown,
|
|
81
|
+
signal?: AbortSignal
|
|
82
|
+
): Promise<
|
|
83
|
+
| {
|
|
84
|
+
readonly version: 1;
|
|
85
|
+
readonly ok: false;
|
|
86
|
+
readonly error: {
|
|
87
|
+
readonly code: ProviderTextProtectionErrorCode;
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
| { version: 1; ok: true; content: string }
|
|
91
|
+
> => {
|
|
92
|
+
try {
|
|
93
|
+
let request: HostProviderTextRequest;
|
|
94
|
+
try {
|
|
95
|
+
request = JSON.parse(receiver.open(data)) as HostProviderTextRequest;
|
|
96
|
+
} catch {
|
|
97
|
+
throw new ProviderTextProtectionError('incompatible');
|
|
98
|
+
}
|
|
99
|
+
const content = await providerText.service.inspect(request, signal);
|
|
100
|
+
return { version: 1 as const, ok: true as const, content };
|
|
101
|
+
} catch (error) {
|
|
102
|
+
return serializeProviderTextProtectionError(error);
|
|
103
|
+
}
|
|
104
|
+
},
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
export function createWorkerProviderTextPolicy(options: {
|
|
109
|
+
descriptor: NonNullable<RemoteSdkStart['providerText']>;
|
|
110
|
+
identity: Readonly<SdkAgentIdentity>;
|
|
111
|
+
peer: { call: SdkRpc };
|
|
112
|
+
limits: RemoteSdkLimits;
|
|
113
|
+
}): ProviderTextProtection {
|
|
114
|
+
const descriptor = policyDescriptorSchema.parse(options.descriptor);
|
|
115
|
+
const seal = createPolicySender(
|
|
116
|
+
descriptor.publicKey,
|
|
117
|
+
options.limits.maxFrameBytes
|
|
118
|
+
);
|
|
119
|
+
return createHostProviderTextProtection({
|
|
120
|
+
identity: options.identity,
|
|
121
|
+
descriptor: descriptor.limits,
|
|
122
|
+
service: {
|
|
123
|
+
version: 1,
|
|
124
|
+
inspect: async (request, signal) => {
|
|
125
|
+
let payload: ReturnType<typeof seal>;
|
|
126
|
+
try {
|
|
127
|
+
payload = seal(JSON.stringify(request));
|
|
128
|
+
} catch {
|
|
129
|
+
throw new ProviderTextProtectionError('overflow');
|
|
130
|
+
}
|
|
131
|
+
const result = await options.peer.call(
|
|
132
|
+
'policy.providerText',
|
|
133
|
+
payload,
|
|
134
|
+
options.limits.maxRunMs,
|
|
135
|
+
signal
|
|
136
|
+
);
|
|
137
|
+
const success = z
|
|
138
|
+
.object({
|
|
139
|
+
version: z.literal(1),
|
|
140
|
+
ok: z.literal(true),
|
|
141
|
+
content: z.string(),
|
|
142
|
+
})
|
|
143
|
+
.safeParse(result);
|
|
144
|
+
if (!success.success)
|
|
145
|
+
throw deserializeProviderTextProtectionError(result);
|
|
146
|
+
return success.data.content;
|
|
147
|
+
},
|
|
148
|
+
},
|
|
149
|
+
});
|
|
150
|
+
}
|
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { WebSocket } from 'ws';
|
|
3
|
+
import { randomUUID } from 'node:crypto';
|
|
4
|
+
import type { RemoteSdkLimits, RemoteSdkRecoveryOptions } from '../types';
|
|
5
|
+
import type { RecoveryClaim } from './server';
|
|
6
|
+
import {
|
|
7
|
+
RecoverySocket,
|
|
8
|
+
createMemoryRecoveryLog,
|
|
9
|
+
RECOVERY_HEADER_BYTES,
|
|
10
|
+
} from './socket';
|
|
11
|
+
|
|
12
|
+
export async function connectRecoveringSdkSocket(options: {
|
|
13
|
+
url: string;
|
|
14
|
+
token: (claim: RecoveryClaim) => string;
|
|
15
|
+
generation?: string;
|
|
16
|
+
limits: RemoteSdkLimits;
|
|
17
|
+
recovery: RemoteSdkRecoveryOptions;
|
|
18
|
+
signal?: AbortSignal;
|
|
19
|
+
onError?: (error: unknown) => void;
|
|
20
|
+
}): Promise<RecoverySocket> {
|
|
21
|
+
const { limits, recovery } = options;
|
|
22
|
+
if (
|
|
23
|
+
[
|
|
24
|
+
recovery.maxDisconnectMs,
|
|
25
|
+
recovery.retryDelayMs,
|
|
26
|
+
recovery.maxJournalBytes,
|
|
27
|
+
].some((v) => !Number.isSafeInteger(v) || v <= 0)
|
|
28
|
+
)
|
|
29
|
+
throw new Error('Invalid SDK recovery configuration');
|
|
30
|
+
if (recovery.maxDisconnectMs >= limits.rpcTimeoutMs)
|
|
31
|
+
throw new Error('SDK recovery window must be shorter than the RPC timeout');
|
|
32
|
+
for (const [owner, route] of Object.entries(recovery.routes ?? {})) {
|
|
33
|
+
const url = new URL(route);
|
|
34
|
+
if (
|
|
35
|
+
!owner ||
|
|
36
|
+
owner.length > 128 ||
|
|
37
|
+
url.username ||
|
|
38
|
+
url.password ||
|
|
39
|
+
url.search ||
|
|
40
|
+
url.hash ||
|
|
41
|
+
(url.protocol !== 'wss:' &&
|
|
42
|
+
!(
|
|
43
|
+
url.protocol === 'ws:' &&
|
|
44
|
+
['localhost', '127.0.0.1', '[::1]'].includes(url.hostname)
|
|
45
|
+
))
|
|
46
|
+
)
|
|
47
|
+
throw new Error('Invalid SDK recovery owner route');
|
|
48
|
+
}
|
|
49
|
+
let ownerId: string | undefined;
|
|
50
|
+
const sessionId = randomUUID();
|
|
51
|
+
let connected = false;
|
|
52
|
+
let connecting = false;
|
|
53
|
+
let deadline = Date.now() + recovery.maxDisconnectMs;
|
|
54
|
+
let retry: ReturnType<typeof setTimeout> | undefined;
|
|
55
|
+
let current: WebSocket | undefined;
|
|
56
|
+
let resolve!: (socket: RecoverySocket) => void;
|
|
57
|
+
let reject!: (error: Error) => void;
|
|
58
|
+
const first = new Promise<RecoverySocket>((yes, no) => {
|
|
59
|
+
resolve = yes;
|
|
60
|
+
reject = no;
|
|
61
|
+
});
|
|
62
|
+
const report = (error: unknown): void => {
|
|
63
|
+
try {
|
|
64
|
+
options.onError?.(error);
|
|
65
|
+
} catch {
|
|
66
|
+
/* Trusted diagnostics only. */
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
const failed = (error: unknown): void => {
|
|
70
|
+
report(error);
|
|
71
|
+
reject(new Error('SDK runtime recovery failed'));
|
|
72
|
+
socket.terminate();
|
|
73
|
+
};
|
|
74
|
+
const schedule = (): void => {
|
|
75
|
+
if (socket.readyState !== WebSocket.OPEN || retry || connecting) return;
|
|
76
|
+
if (Date.now() >= deadline) {
|
|
77
|
+
failed(new Error('SDK runtime recovery window expired'));
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
retry = setTimeout(
|
|
81
|
+
() => {
|
|
82
|
+
retry = undefined;
|
|
83
|
+
void connect();
|
|
84
|
+
},
|
|
85
|
+
Math.min(recovery.retryDelayMs, deadline - Date.now())
|
|
86
|
+
);
|
|
87
|
+
};
|
|
88
|
+
const socket = new RecoverySocket({
|
|
89
|
+
log: createMemoryRecoveryLog(recovery.maxJournalBytes),
|
|
90
|
+
maxFrameBytes: limits.maxFrameBytes,
|
|
91
|
+
maxBufferedBytes: limits.maxBufferedBytes,
|
|
92
|
+
onDisconnect: (): void => {
|
|
93
|
+
deadline = Date.now() + recovery.maxDisconnectMs;
|
|
94
|
+
schedule();
|
|
95
|
+
},
|
|
96
|
+
onFailure: failed,
|
|
97
|
+
});
|
|
98
|
+
socket.once('close', () => {
|
|
99
|
+
clearTimeout(retry);
|
|
100
|
+
current?.terminate();
|
|
101
|
+
options.signal?.removeEventListener('abort', initialAbort);
|
|
102
|
+
reject(new Error('SDK runtime recovery closed'));
|
|
103
|
+
});
|
|
104
|
+
const initialAbort = (): void => {
|
|
105
|
+
if (connected) return;
|
|
106
|
+
reject(
|
|
107
|
+
Object.assign(new Error('SDK runtime connection cancelled'), {
|
|
108
|
+
name: 'AbortError',
|
|
109
|
+
})
|
|
110
|
+
);
|
|
111
|
+
socket.terminate();
|
|
112
|
+
};
|
|
113
|
+
options.signal?.addEventListener('abort', initialAbort, { once: true });
|
|
114
|
+
const connect = async (): Promise<void> => {
|
|
115
|
+
if (socket.readyState !== WebSocket.OPEN || connecting) return;
|
|
116
|
+
connecting = true;
|
|
117
|
+
const wire = new WebSocket(
|
|
118
|
+
ownerId != null && ownerId.length > 0
|
|
119
|
+
? recovery.routes![ownerId]
|
|
120
|
+
: options.url,
|
|
121
|
+
{
|
|
122
|
+
headers: {
|
|
123
|
+
Authorization: `Bearer ${options.token({ sessionId, after: socket.cursor, resume: connected, ownerId, generation: options.generation })}`,
|
|
124
|
+
},
|
|
125
|
+
handshakeTimeout: Math.min(
|
|
126
|
+
limits.connectTimeoutMs,
|
|
127
|
+
Math.max(1, deadline - Date.now())
|
|
128
|
+
),
|
|
129
|
+
maxPayload: limits.maxFrameBytes + RECOVERY_HEADER_BYTES,
|
|
130
|
+
followRedirects: false,
|
|
131
|
+
}
|
|
132
|
+
);
|
|
133
|
+
current = wire;
|
|
134
|
+
let handoff: (() => void) | undefined;
|
|
135
|
+
const early: WebSocket.RawData[] = [];
|
|
136
|
+
let earlyBytes = 0;
|
|
137
|
+
try {
|
|
138
|
+
const ready = await new Promise<{
|
|
139
|
+
connection: string;
|
|
140
|
+
received: number;
|
|
141
|
+
ownerId?: string;
|
|
142
|
+
}>((yes, no) => {
|
|
143
|
+
const timer = setTimeout(
|
|
144
|
+
() => no(new Error('SDK recovery handshake timed out')),
|
|
145
|
+
Math.min(limits.connectTimeoutMs, Math.max(1, deadline - Date.now()))
|
|
146
|
+
);
|
|
147
|
+
const cleanup = (keepMessage = false): void => {
|
|
148
|
+
clearTimeout(timer);
|
|
149
|
+
if (!keepMessage) wire.removeListener('message', message);
|
|
150
|
+
wire.removeListener('close', closed);
|
|
151
|
+
wire.removeListener('error', closed);
|
|
152
|
+
};
|
|
153
|
+
const closed = (): void => {
|
|
154
|
+
cleanup();
|
|
155
|
+
no(new Error('SDK recovery handshake failed'));
|
|
156
|
+
};
|
|
157
|
+
let readySeen = false;
|
|
158
|
+
const message = (raw: WebSocket.RawData): void => {
|
|
159
|
+
if (readySeen) {
|
|
160
|
+
earlyBytes += Buffer.byteLength(raw.toString());
|
|
161
|
+
if (earlyBytes > limits.maxBufferedBytes) wire.terminate();
|
|
162
|
+
else early.push(raw);
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
try {
|
|
166
|
+
const frame = z
|
|
167
|
+
.object({
|
|
168
|
+
version: z.literal(1),
|
|
169
|
+
kind: z.literal('ready'),
|
|
170
|
+
ownerId: z.string().min(1).max(128).optional(),
|
|
171
|
+
sessionId: z.literal(sessionId),
|
|
172
|
+
connection: z.string().uuid(),
|
|
173
|
+
received: z
|
|
174
|
+
.number()
|
|
175
|
+
.int()
|
|
176
|
+
.nonnegative()
|
|
177
|
+
.max(Number.MAX_SAFE_INTEGER),
|
|
178
|
+
})
|
|
179
|
+
.parse(JSON.parse(raw.toString()));
|
|
180
|
+
readySeen = true;
|
|
181
|
+
cleanup(true);
|
|
182
|
+
handoff = (): WebSocket => wire.removeListener('message', message);
|
|
183
|
+
yes(frame);
|
|
184
|
+
} catch {
|
|
185
|
+
cleanup();
|
|
186
|
+
no(new Error('Invalid SDK recovery handshake'));
|
|
187
|
+
}
|
|
188
|
+
};
|
|
189
|
+
wire.on('message', message);
|
|
190
|
+
wire.once('close', closed);
|
|
191
|
+
wire.once('error', closed);
|
|
192
|
+
});
|
|
193
|
+
if (wire.readyState !== WebSocket.OPEN)
|
|
194
|
+
throw new Error('SDK recovery handshake closed');
|
|
195
|
+
if (Number(socket.readyState) !== WebSocket.OPEN) {
|
|
196
|
+
wire.terminate();
|
|
197
|
+
return;
|
|
198
|
+
}
|
|
199
|
+
if (
|
|
200
|
+
(ownerId != null && ownerId.length > 0 && ready.ownerId !== ownerId) ||
|
|
201
|
+
(ready.ownerId != null &&
|
|
202
|
+
ready.ownerId.length > 0 &&
|
|
203
|
+
!Object.prototype.hasOwnProperty.call(
|
|
204
|
+
recovery.routes ?? {},
|
|
205
|
+
ready.ownerId
|
|
206
|
+
)) ||
|
|
207
|
+
(recovery.routes &&
|
|
208
|
+
(ready.ownerId == null || ready.ownerId.length === 0))
|
|
209
|
+
) {
|
|
210
|
+
failed(new Error('SDK recovery owner route unavailable'));
|
|
211
|
+
return;
|
|
212
|
+
}
|
|
213
|
+
ownerId = ready.ownerId;
|
|
214
|
+
connected = true;
|
|
215
|
+
options.signal?.removeEventListener('abort', initialAbort);
|
|
216
|
+
socket.attach(wire, ready.connection, ready.received);
|
|
217
|
+
handoff?.();
|
|
218
|
+
for (const raw of early) wire.emit('message', raw);
|
|
219
|
+
resolve(socket);
|
|
220
|
+
} catch (error) {
|
|
221
|
+
handoff?.();
|
|
222
|
+
wire.terminate();
|
|
223
|
+
report(error);
|
|
224
|
+
} finally {
|
|
225
|
+
connecting = false;
|
|
226
|
+
if (!socket.hasWire) schedule();
|
|
227
|
+
}
|
|
228
|
+
};
|
|
229
|
+
if (options.signal?.aborted === true) initialAbort();
|
|
230
|
+
else void connect();
|
|
231
|
+
return first;
|
|
232
|
+
}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/** Durable wire frames, independent of SDK objects, sockets, and browser rendering. */
|
|
2
|
+
export interface RuntimeJournalLease {
|
|
3
|
+
owner: string;
|
|
4
|
+
epoch: number;
|
|
5
|
+
}
|
|
6
|
+
export interface RuntimeJournalSession {
|
|
7
|
+
sessionId: string;
|
|
8
|
+
/** Hash of verified runtime/agent/run/caller/tenant/thread/generation identity, never a request-body authority. */
|
|
9
|
+
scope: string;
|
|
10
|
+
}
|
|
11
|
+
export type RuntimeJournalFailure =
|
|
12
|
+
| 'missing'
|
|
13
|
+
| 'scope_mismatch'
|
|
14
|
+
| 'fenced'
|
|
15
|
+
| 'closed'
|
|
16
|
+
| 'limit'
|
|
17
|
+
| 'cursor_ahead'
|
|
18
|
+
| 'batch_conflict'
|
|
19
|
+
| 'already_exists';
|
|
20
|
+
export type RuntimeJournalResult<T> =
|
|
21
|
+
| { ok: true; value: T }
|
|
22
|
+
| { ok: false; error: { code: RuntimeJournalFailure } };
|
|
23
|
+
export type RuntimeJournalState =
|
|
24
|
+
| 'open'
|
|
25
|
+
| 'completed'
|
|
26
|
+
| 'failed'
|
|
27
|
+
| 'cancelled'
|
|
28
|
+
| 'paused';
|
|
29
|
+
export interface RuntimeJournalPage {
|
|
30
|
+
state: RuntimeJournalState;
|
|
31
|
+
started: boolean;
|
|
32
|
+
head: number;
|
|
33
|
+
acknowledged: number;
|
|
34
|
+
frames: Array<{ sequence: number; payload: string }>;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Acknowledgements never evict frames: a replacement connection may need the full prefix.
|
|
38
|
+
* Expiration/limits bound retention. A claimed session with started=true MUST NOT start a
|
|
39
|
+
* second SDK Run; execution adoption needs a separate, explicit recovery protocol.
|
|
40
|
+
* Session IDs are single-use. A missing/expired replay session must fail, not silently
|
|
41
|
+
* create another execution. Store durability depends on the deployment persistence policy.
|
|
42
|
+
*/
|
|
43
|
+
export interface RuntimeJournal {
|
|
44
|
+
readonly leaseMs: number;
|
|
45
|
+
readonly maxBatchFrames: number;
|
|
46
|
+
readonly maxBatchBytes?: number;
|
|
47
|
+
/** Privileged lifecycle cleanup; callers must authenticate deletion authority before storage access. */
|
|
48
|
+
purge(session: RuntimeJournalSession): Promise<RuntimeJournalResult<null>>;
|
|
49
|
+
create(
|
|
50
|
+
session: RuntimeJournalSession,
|
|
51
|
+
owner: string
|
|
52
|
+
): Promise<RuntimeJournalResult<RuntimeJournalLease>>;
|
|
53
|
+
claim(
|
|
54
|
+
session: RuntimeJournalSession,
|
|
55
|
+
owner: string
|
|
56
|
+
): Promise<RuntimeJournalResult<RuntimeJournalLease & { started: boolean }>>;
|
|
57
|
+
renew(
|
|
58
|
+
session: RuntimeJournalSession,
|
|
59
|
+
lease: RuntimeJournalLease
|
|
60
|
+
): Promise<RuntimeJournalResult<null>>;
|
|
61
|
+
markStarted(
|
|
62
|
+
session: RuntimeJournalSession,
|
|
63
|
+
lease: RuntimeJournalLease
|
|
64
|
+
): Promise<RuntimeJournalResult<{ first: boolean }>>;
|
|
65
|
+
append(
|
|
66
|
+
session: RuntimeJournalSession,
|
|
67
|
+
lease: RuntimeJournalLease,
|
|
68
|
+
batchId: string,
|
|
69
|
+
payloads: readonly string[],
|
|
70
|
+
terminal?: Exclude<RuntimeJournalState, 'open'>
|
|
71
|
+
): Promise<RuntimeJournalResult<{ first: number; last: number }>>;
|
|
72
|
+
acknowledge(
|
|
73
|
+
session: RuntimeJournalSession,
|
|
74
|
+
lease: RuntimeJournalLease,
|
|
75
|
+
sequence: number
|
|
76
|
+
): Promise<RuntimeJournalResult<{ acknowledged: number }>>;
|
|
77
|
+
read(
|
|
78
|
+
session: RuntimeJournalSession,
|
|
79
|
+
after: number,
|
|
80
|
+
limit: number
|
|
81
|
+
): Promise<RuntimeJournalResult<RuntimeJournalPage>>;
|
|
82
|
+
finish(
|
|
83
|
+
session: RuntimeJournalSession,
|
|
84
|
+
lease: RuntimeJournalLease,
|
|
85
|
+
state: Exclude<RuntimeJournalState, 'open'>,
|
|
86
|
+
head: number
|
|
87
|
+
): Promise<RuntimeJournalResult<null>>;
|
|
88
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
RuntimeJournal,
|
|
3
|
+
RuntimeJournalLease,
|
|
4
|
+
RuntimeJournalSession,
|
|
5
|
+
RuntimeJournalResult,
|
|
6
|
+
RuntimeJournalState,
|
|
7
|
+
} from './journal';
|
|
8
|
+
import type { RecoveryLog } from './socket';
|
|
9
|
+
export function journalValue<T>(result: RuntimeJournalResult<T>): T {
|
|
10
|
+
if (!result.ok) throw new Error(`SDK recovery journal ${result.error.code}`);
|
|
11
|
+
return result.value;
|
|
12
|
+
}
|
|
13
|
+
export function createJournalRecoveryLog(options: {
|
|
14
|
+
journal: RuntimeJournal;
|
|
15
|
+
session: RuntimeJournalSession;
|
|
16
|
+
lease?: RuntimeJournalLease;
|
|
17
|
+
head: number;
|
|
18
|
+
}): RecoveryLog {
|
|
19
|
+
let head = options.head;
|
|
20
|
+
const { journal, session, lease } = options;
|
|
21
|
+
const appendBatch = async (
|
|
22
|
+
id: string,
|
|
23
|
+
payloads: string[]
|
|
24
|
+
): Promise<{ first: number; last: number }> => {
|
|
25
|
+
if (!lease) throw new Error('SDK recovery journal is read only');
|
|
26
|
+
let terminal: Exclude<RuntimeJournalState, 'open'> | undefined;
|
|
27
|
+
for (const payload of payloads) {
|
|
28
|
+
const entry = JSON.parse(payload) as { kind: string; payload: string };
|
|
29
|
+
if (entry.kind !== 'data') continue;
|
|
30
|
+
if (terminal) throw new Error('SDK frames follow a terminal receipt');
|
|
31
|
+
const frame = JSON.parse(entry.payload) as {
|
|
32
|
+
type?: string;
|
|
33
|
+
data?: { interrupt?: { $sdk?: string } };
|
|
34
|
+
};
|
|
35
|
+
if (frame.type === 'error') terminal = 'failed';
|
|
36
|
+
if (frame.type === 'done')
|
|
37
|
+
terminal =
|
|
38
|
+
frame.data?.interrupt != null &&
|
|
39
|
+
frame.data.interrupt.$sdk !== 'undefined'
|
|
40
|
+
? 'paused'
|
|
41
|
+
: 'completed';
|
|
42
|
+
}
|
|
43
|
+
const range = journalValue(
|
|
44
|
+
await journal.append(session, lease, id, payloads, terminal)
|
|
45
|
+
);
|
|
46
|
+
head = range.last;
|
|
47
|
+
return range;
|
|
48
|
+
};
|
|
49
|
+
return {
|
|
50
|
+
head: () => head,
|
|
51
|
+
maxBatchFrames:
|
|
52
|
+
(journal.maxBatchBytes ?? 0) > 0 ? journal.maxBatchFrames : 1,
|
|
53
|
+
maxBatchBytes: journal.maxBatchBytes,
|
|
54
|
+
appendBatch,
|
|
55
|
+
append: async (id, payload) => (await appendBatch(id, [payload])).last,
|
|
56
|
+
read: async (after): Promise<{ sequence: number; payload: string }[]> => {
|
|
57
|
+
const page = journalValue(
|
|
58
|
+
await journal.read(session, after, journal.maxBatchFrames)
|
|
59
|
+
);
|
|
60
|
+
head = page.head;
|
|
61
|
+
return page.frames;
|
|
62
|
+
},
|
|
63
|
+
acknowledge: async (sequence): Promise<void> => {
|
|
64
|
+
if (sequence > head) throw new Error('SDK recovery cursor is ahead');
|
|
65
|
+
if (!lease) return;
|
|
66
|
+
const result = await journal.acknowledge(session, lease, sequence);
|
|
67
|
+
if (!result.ok && result.error.code !== 'closed') journalValue(result);
|
|
68
|
+
},
|
|
69
|
+
};
|
|
70
|
+
}
|