@librechat/agents 4.2.10 → 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/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/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/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/index.d.ts +2 -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 +1 -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 +2 -2
- 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 +10 -10
- 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/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
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
3
|
+
import { ensureHandler } from '@langchain/core/callbacks/manager';
|
|
4
|
+
import type {
|
|
5
|
+
CallbackManagerForLLMRun,
|
|
6
|
+
Callbacks,
|
|
7
|
+
} from '@langchain/core/callbacks/manager';
|
|
8
|
+
import type { ChatResult, ChatGenerationChunk } from '@langchain/core/outputs';
|
|
9
|
+
import type { BaseCallbackHandler } from '@langchain/core/callbacks/base';
|
|
10
|
+
import type { BaseMessage } from '@langchain/core/messages';
|
|
11
|
+
import type { SdkRpc } from './peer';
|
|
12
|
+
import { HostChatModel, HostModelServiceError } from '@/index';
|
|
13
|
+
|
|
14
|
+
export interface RemoteModelAttempt {
|
|
15
|
+
nodeId: string;
|
|
16
|
+
modelId: string;
|
|
17
|
+
}
|
|
18
|
+
export const modelAttemptSchema: z.ZodType<RemoteModelAttempt> = z
|
|
19
|
+
.object({ nodeId: z.string().uuid(), modelId: z.string().uuid() })
|
|
20
|
+
.strict();
|
|
21
|
+
const invocationContextSchema = z
|
|
22
|
+
.object({ version: z.literal(1), runId: z.string().uuid() })
|
|
23
|
+
.strict();
|
|
24
|
+
/** Additive SDK capability: older SDKs keep the input-only model adapter during rollout. */
|
|
25
|
+
export const supportsModelInvocationContext: boolean =
|
|
26
|
+
Number(HostChatModel.invocationContextVersion) === 1;
|
|
27
|
+
const blocked = (): HostModelServiceError =>
|
|
28
|
+
new HostModelServiceError('blocked');
|
|
29
|
+
|
|
30
|
+
/** Run each iterator operation inside its scope; constructing an async generator does not enter it. */
|
|
31
|
+
async function* scopedStream<T, C>(
|
|
32
|
+
storage: AsyncLocalStorage<C>,
|
|
33
|
+
context: C,
|
|
34
|
+
source: () => AsyncIterable<T>
|
|
35
|
+
): AsyncGenerator<T> {
|
|
36
|
+
const iterator = storage.run(context, () => source()[Symbol.asyncIterator]());
|
|
37
|
+
try {
|
|
38
|
+
for (;;) {
|
|
39
|
+
const next = await storage.run(context, () => iterator.next());
|
|
40
|
+
if (next.done === true) return;
|
|
41
|
+
yield next.value;
|
|
42
|
+
}
|
|
43
|
+
} finally {
|
|
44
|
+
await storage.run(context, () => iterator.return?.());
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export interface HostModelLifecycle {
|
|
49
|
+
attach(callbacks: Callbacks | undefined): boolean;
|
|
50
|
+
readonly maxEntries: number;
|
|
51
|
+
failure(): Error | undefined;
|
|
52
|
+
invoke<T>(
|
|
53
|
+
context: RemoteModelAttempt | undefined,
|
|
54
|
+
operation: () => Promise<T>
|
|
55
|
+
): Promise<T>;
|
|
56
|
+
stream<T>(
|
|
57
|
+
context: RemoteModelAttempt | undefined,
|
|
58
|
+
operation: () => AsyncIterable<T>
|
|
59
|
+
): AsyncIterable<T>;
|
|
60
|
+
end(data: unknown): boolean;
|
|
61
|
+
dispose(): void;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export interface WorkerModelLifecycle {
|
|
65
|
+
callback: BaseCallbackHandler;
|
|
66
|
+
current(context?: unknown): RemoteModelAttempt | undefined;
|
|
67
|
+
model(options: ConstructorParameters<typeof HostChatModel>[0]): HostChatModel;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/** Only callbacks installed on this root execution can enroll a model attempt. No message text is relayed. */
|
|
71
|
+
export function createWorkerModelLifecycle(
|
|
72
|
+
agentId: string,
|
|
73
|
+
maxEntries: number,
|
|
74
|
+
peer: { call: SdkRpc }
|
|
75
|
+
): WorkerModelLifecycle {
|
|
76
|
+
const parents = new Map<string, string>();
|
|
77
|
+
const nodes = new Set<string>();
|
|
78
|
+
const models = new Map<string, RemoteModelAttempt>();
|
|
79
|
+
const attemptedNodes = new Set<string>();
|
|
80
|
+
const storage = new AsyncLocalStorage<RemoteModelAttempt | undefined>();
|
|
81
|
+
let admitted = false;
|
|
82
|
+
const budget = (): void => {
|
|
83
|
+
if (parents.size + nodes.size + models.size >= maxEntries) throw blocked();
|
|
84
|
+
};
|
|
85
|
+
const context = (
|
|
86
|
+
manager?: CallbackManagerForLLMRun
|
|
87
|
+
): RemoteModelAttempt | undefined => {
|
|
88
|
+
if (admitted) return undefined;
|
|
89
|
+
const value = manager && models.get(manager.runId);
|
|
90
|
+
if (!value) throw blocked();
|
|
91
|
+
attemptedNodes.add(value.nodeId);
|
|
92
|
+
return value;
|
|
93
|
+
};
|
|
94
|
+
const end = async (nodeId: string, completed: boolean): Promise<void> => {
|
|
95
|
+
parents.delete(nodeId);
|
|
96
|
+
nodes.delete(nodeId);
|
|
97
|
+
for (const [modelId, attempt] of models)
|
|
98
|
+
if (attempt.nodeId === nodeId) models.delete(modelId);
|
|
99
|
+
if (!attemptedNodes.delete(nodeId)) return;
|
|
100
|
+
const reply = z
|
|
101
|
+
.object({
|
|
102
|
+
version: z.literal(1),
|
|
103
|
+
ok: z.literal(true),
|
|
104
|
+
admitted: z.boolean(),
|
|
105
|
+
})
|
|
106
|
+
.parse(await peer.call('model.node.end', { nodeId, completed }));
|
|
107
|
+
if (reply.admitted) {
|
|
108
|
+
admitted = true;
|
|
109
|
+
parents.clear();
|
|
110
|
+
nodes.clear();
|
|
111
|
+
models.clear();
|
|
112
|
+
attemptedNodes.clear();
|
|
113
|
+
}
|
|
114
|
+
};
|
|
115
|
+
class CorrelatedHostModel extends HostChatModel {
|
|
116
|
+
override _generate(
|
|
117
|
+
messages: BaseMessage[],
|
|
118
|
+
options: this['ParsedCallOptions'],
|
|
119
|
+
manager?: CallbackManagerForLLMRun
|
|
120
|
+
): Promise<ChatResult> {
|
|
121
|
+
return storage.run(context(manager), () =>
|
|
122
|
+
super._generate(messages, options)
|
|
123
|
+
);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
override async *_streamResponseChunks(
|
|
127
|
+
messages: BaseMessage[],
|
|
128
|
+
options: this['ParsedCallOptions'],
|
|
129
|
+
manager?: CallbackManagerForLLMRun
|
|
130
|
+
): AsyncGenerator<ChatGenerationChunk> {
|
|
131
|
+
yield* scopedStream(storage, context(manager), () =>
|
|
132
|
+
super._streamResponseChunks(messages, options, manager)
|
|
133
|
+
);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
return {
|
|
137
|
+
current(context): RemoteModelAttempt | undefined {
|
|
138
|
+
if (admitted) return undefined;
|
|
139
|
+
if (supportsModelInvocationContext) {
|
|
140
|
+
const { runId } = invocationContextSchema.parse(context);
|
|
141
|
+
const attempt = models.get(runId);
|
|
142
|
+
if (!attempt) throw blocked();
|
|
143
|
+
attemptedNodes.add(attempt.nodeId);
|
|
144
|
+
return attempt;
|
|
145
|
+
}
|
|
146
|
+
const value = storage.getStore();
|
|
147
|
+
if (!value) throw blocked();
|
|
148
|
+
return value;
|
|
149
|
+
},
|
|
150
|
+
model: (options) =>
|
|
151
|
+
supportsModelInvocationContext
|
|
152
|
+
? new HostChatModel(options)
|
|
153
|
+
: new CorrelatedHostModel(options),
|
|
154
|
+
callback: ensureHandler({
|
|
155
|
+
name: 'librechat-remote-model-admission',
|
|
156
|
+
raiseError: true,
|
|
157
|
+
awaitHandlers: true,
|
|
158
|
+
handleChainStart: (
|
|
159
|
+
_chain,
|
|
160
|
+
_inputs,
|
|
161
|
+
runId,
|
|
162
|
+
parentRunId,
|
|
163
|
+
_tags,
|
|
164
|
+
metadata,
|
|
165
|
+
_type,
|
|
166
|
+
name
|
|
167
|
+
) => {
|
|
168
|
+
if (admitted) return;
|
|
169
|
+
budget();
|
|
170
|
+
if (parentRunId != null && parentRunId.length > 0)
|
|
171
|
+
parents.set(runId, parentRunId);
|
|
172
|
+
if (name === `agent=${agentId}` && metadata?.langgraph_node === name)
|
|
173
|
+
nodes.add(runId);
|
|
174
|
+
},
|
|
175
|
+
handleChatModelStart: (
|
|
176
|
+
_model,
|
|
177
|
+
_messages,
|
|
178
|
+
runId,
|
|
179
|
+
parentRunId,
|
|
180
|
+
_extra,
|
|
181
|
+
_tags,
|
|
182
|
+
metadata
|
|
183
|
+
) => {
|
|
184
|
+
if (admitted) return;
|
|
185
|
+
if (
|
|
186
|
+
metadata?.summarization === true ||
|
|
187
|
+
metadata?.agentId !== agentId ||
|
|
188
|
+
metadata.langgraph_node !== `agent=${agentId}`
|
|
189
|
+
)
|
|
190
|
+
return;
|
|
191
|
+
const seen = new Set<string>();
|
|
192
|
+
let parent = parentRunId;
|
|
193
|
+
while (parent != null && parent.length > 0 && !seen.has(parent)) {
|
|
194
|
+
if (nodes.has(parent)) {
|
|
195
|
+
budget();
|
|
196
|
+
models.set(runId, { nodeId: parent, modelId: runId });
|
|
197
|
+
return;
|
|
198
|
+
}
|
|
199
|
+
seen.add(parent);
|
|
200
|
+
parent = parents.get(parent);
|
|
201
|
+
}
|
|
202
|
+
},
|
|
203
|
+
handleChainEnd: async (output, runId) => {
|
|
204
|
+
if (admitted) return;
|
|
205
|
+
if (!nodes.has(runId)) {
|
|
206
|
+
parents.delete(runId);
|
|
207
|
+
return;
|
|
208
|
+
}
|
|
209
|
+
const result = output as {
|
|
210
|
+
messages?: unknown;
|
|
211
|
+
summarizationRequest?: unknown;
|
|
212
|
+
} | null;
|
|
213
|
+
await end(
|
|
214
|
+
runId,
|
|
215
|
+
Array.isArray(result?.messages) &&
|
|
216
|
+
result.messages.length > 0 &&
|
|
217
|
+
result.summarizationRequest == null
|
|
218
|
+
);
|
|
219
|
+
},
|
|
220
|
+
handleChainError: (_error, runId) =>
|
|
221
|
+
admitted ? undefined : end(runId, false),
|
|
222
|
+
}),
|
|
223
|
+
};
|
|
224
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import type { SdkRpc } from './peer';
|
|
2
|
+
import { BaseCheckpointSaver } from '@/index';
|
|
3
|
+
|
|
4
|
+
type Saver = BaseCheckpointSaver;
|
|
5
|
+
function checkpointConfig(
|
|
6
|
+
config: Parameters<Saver['getTuple']>[0]
|
|
7
|
+
): Parameters<Saver['getTuple']>[0] {
|
|
8
|
+
return {
|
|
9
|
+
configurable: Object.fromEntries(
|
|
10
|
+
Object.entries(config.configurable ?? {}).filter(
|
|
11
|
+
([key, value]) =>
|
|
12
|
+
(['thread_id', 'checkpoint_ns', 'checkpoint_id'].includes(key) ||
|
|
13
|
+
key.startsWith('__librechat_')) &&
|
|
14
|
+
(typeof value === 'string' ||
|
|
15
|
+
typeof value === 'number' ||
|
|
16
|
+
typeof value === 'boolean' ||
|
|
17
|
+
value == null)
|
|
18
|
+
)
|
|
19
|
+
),
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
/** The host retains its durable saver; the worker never receives database credentials. */
|
|
23
|
+
export class RemoteSdkCheckpointer extends BaseCheckpointSaver {
|
|
24
|
+
constructor(private readonly call: SdkRpc) {
|
|
25
|
+
super();
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
async getTuple(
|
|
29
|
+
...args: Parameters<Saver['getTuple']>
|
|
30
|
+
): ReturnType<Saver['getTuple']> {
|
|
31
|
+
return (await this.call('checkpoint.getTuple', [
|
|
32
|
+
checkpointConfig(args[0]),
|
|
33
|
+
])) as Awaited<ReturnType<Saver['getTuple']>>;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
async *list(...args: Parameters<Saver['list']>): ReturnType<Saver['list']> {
|
|
37
|
+
const tuples = (await this.call('checkpoint.list', [
|
|
38
|
+
checkpointConfig(args[0]),
|
|
39
|
+
args[1] && {
|
|
40
|
+
...args[1],
|
|
41
|
+
before: args[1].before ? checkpointConfig(args[1].before) : undefined,
|
|
42
|
+
},
|
|
43
|
+
])) as Awaited<ReturnType<Saver['getTuple']>>[];
|
|
44
|
+
for (const tuple of tuples) if (tuple != null) yield tuple;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
async put(...args: Parameters<Saver['put']>): ReturnType<Saver['put']> {
|
|
48
|
+
return (await this.call('checkpoint.put', [
|
|
49
|
+
checkpointConfig(args[0]),
|
|
50
|
+
...args.slice(1),
|
|
51
|
+
])) as Awaited<ReturnType<Saver['put']>>;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
async putWrites(
|
|
55
|
+
...args: Parameters<Saver['putWrites']>
|
|
56
|
+
): ReturnType<Saver['putWrites']> {
|
|
57
|
+
await this.call('checkpoint.putWrites', [
|
|
58
|
+
checkpointConfig(args[0]),
|
|
59
|
+
...args.slice(1),
|
|
60
|
+
]);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
async deleteThread(): Promise<void> {
|
|
64
|
+
throw new Error('Runtime checkpoint deletion is not permitted');
|
|
65
|
+
}
|
|
66
|
+
}
|