@librechat/agents 4.2.6 → 4.2.7
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/README.md +1 -0
- package/dist/cjs/harness/index.cjs +2 -0
- package/dist/cjs/harness/index.cjs.map +1 -1
- package/dist/cjs/harness/model.cjs +244 -0
- package/dist/cjs/harness/model.cjs.map +1 -0
- package/dist/cjs/harness/modelService.cjs +361 -0
- package/dist/cjs/harness/modelService.cjs.map +1 -0
- package/dist/cjs/harness/modelStreamCallbacks.cjs +102 -0
- package/dist/cjs/harness/modelStreamCallbacks.cjs.map +1 -0
- package/dist/cjs/harness/providerText.cjs +6 -1
- package/dist/cjs/harness/providerText.cjs.map +1 -1
- package/dist/cjs/llm/invoke.cjs +3 -18
- package/dist/cjs/llm/invoke.cjs.map +1 -1
- package/dist/cjs/llm/modelCallbackRun.cjs +26 -0
- package/dist/cjs/llm/modelCallbackRun.cjs.map +1 -0
- package/dist/cjs/main.cjs +10 -0
- package/dist/cjs/protection/providerText.cjs +68 -14
- package/dist/cjs/protection/providerText.cjs.map +1 -1
- package/dist/cjs/protection/providerTextAdmission.cjs +56 -0
- package/dist/cjs/protection/providerTextAdmission.cjs.map +1 -0
- package/dist/esm/harness/index.mjs +2 -0
- package/dist/esm/harness/index.mjs.map +1 -1
- package/dist/esm/harness/model.mjs +241 -0
- package/dist/esm/harness/model.mjs.map +1 -0
- package/dist/esm/harness/modelService.mjs +360 -0
- package/dist/esm/harness/modelService.mjs.map +1 -0
- package/dist/esm/harness/modelStreamCallbacks.mjs +102 -0
- package/dist/esm/harness/modelStreamCallbacks.mjs.map +1 -0
- package/dist/esm/harness/providerText.mjs +7 -2
- package/dist/esm/harness/providerText.mjs.map +1 -1
- package/dist/esm/llm/invoke.mjs +3 -18
- package/dist/esm/llm/invoke.mjs.map +1 -1
- package/dist/esm/llm/modelCallbackRun.mjs +26 -0
- package/dist/esm/llm/modelCallbackRun.mjs.map +1 -0
- package/dist/esm/main.mjs +5 -2
- package/dist/esm/protection/providerText.mjs +66 -15
- package/dist/esm/protection/providerText.mjs.map +1 -1
- package/dist/esm/protection/providerTextAdmission.mjs +56 -0
- package/dist/esm/protection/providerTextAdmission.mjs.map +1 -0
- package/dist/types/harness/index.d.ts +4 -0
- package/dist/types/harness/model.d.ts +104 -0
- package/dist/types/harness/modelService.d.ts +50 -0
- package/dist/types/harness/modelStreamCallbacks.d.ts +11 -0
- package/dist/types/harness/providerText.d.ts +5 -0
- package/dist/types/index.d.ts +4 -2
- package/dist/types/llm/modelCallbackRun.d.ts +9 -0
- package/dist/types/protection/providerText.d.ts +15 -1
- package/dist/types/protection/providerTextAdmission.d.ts +29 -0
- package/package.json +1 -1
- package/src/harness/index.ts +12 -0
- package/src/harness/model.ts +392 -0
- package/src/harness/modelService.ts +560 -0
- package/src/harness/modelStreamCallbacks.ts +137 -0
- package/src/harness/providerText.ts +13 -1
- package/src/index.ts +9 -0
- package/src/llm/invoke.ts +3 -72
- package/src/llm/modelCallbackRun.ts +77 -0
- package/src/protection/providerText.ts +93 -14
- package/src/protection/providerTextAdmission.ts +86 -0
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { ChatGenerationChunk } from '@langchain/core/outputs';
|
|
3
|
+
import { BaseChatModel } from '@langchain/core/language_models/chat_models';
|
|
4
|
+
import { convertToOpenAITool } from '@langchain/core/utils/function_calling';
|
|
5
|
+
import type { BaseChatModelCallOptions, BindToolsInput } from '@langchain/core/language_models/chat_models';
|
|
6
|
+
import type { AIMessage, AIMessageChunk, BaseMessage } from '@langchain/core/messages';
|
|
7
|
+
import type { BaseLanguageModelInput } from '@langchain/core/language_models/base';
|
|
8
|
+
import type { CallbackManagerForLLMRun } from '@langchain/core/callbacks/manager';
|
|
9
|
+
import type { Runnable } from '@langchain/core/runnables';
|
|
10
|
+
import type { ChatResult } from '@langchain/core/outputs';
|
|
11
|
+
import type { ExecutionIdentity } from './identity';
|
|
12
|
+
import { PreparedSubagentError } from '@/tools/preparedSubagents';
|
|
13
|
+
import { StreamLimitExceededError } from '@/llm/streamLimits';
|
|
14
|
+
type FunctionTool = ReturnType<typeof convertToOpenAITool>;
|
|
15
|
+
/** Public configuration only. The authenticated host owns the actual model, credentials and callbacks. */
|
|
16
|
+
export interface HostModelDescriptor {
|
|
17
|
+
readonly version: 1;
|
|
18
|
+
readonly reference: string;
|
|
19
|
+
readonly provider: string;
|
|
20
|
+
readonly model: string;
|
|
21
|
+
readonly streaming: boolean;
|
|
22
|
+
readonly tools: readonly FunctionTool[];
|
|
23
|
+
}
|
|
24
|
+
export declare const hostModelDescriptorSchema: z.ZodObject<{
|
|
25
|
+
version: z.ZodLiteral<1>;
|
|
26
|
+
reference: z.ZodString;
|
|
27
|
+
provider: z.ZodString;
|
|
28
|
+
model: z.ZodString;
|
|
29
|
+
streaming: z.ZodBoolean;
|
|
30
|
+
tools: z.ZodArray<z.ZodObject<{
|
|
31
|
+
type: z.ZodLiteral<"function">;
|
|
32
|
+
function: z.ZodObject<{
|
|
33
|
+
name: z.ZodString;
|
|
34
|
+
description: z.ZodOptional<z.ZodString>;
|
|
35
|
+
parameters: z.ZodRecord<z.ZodString, z.ZodUnknown>;
|
|
36
|
+
strict: z.ZodOptional<z.ZodNullable<z.ZodBoolean>>;
|
|
37
|
+
}, z.core.$loose>;
|
|
38
|
+
}, z.core.$loose>>;
|
|
39
|
+
}, z.core.$strip>;
|
|
40
|
+
export type HostModelToolChoice = {
|
|
41
|
+
readonly mode: 'auto' | 'none' | 'required';
|
|
42
|
+
} | {
|
|
43
|
+
readonly mode: 'tool';
|
|
44
|
+
readonly name: string;
|
|
45
|
+
};
|
|
46
|
+
export interface HostModelRequest {
|
|
47
|
+
readonly version: 1;
|
|
48
|
+
readonly identity: Readonly<ExecutionIdentity>;
|
|
49
|
+
readonly reference: string;
|
|
50
|
+
readonly messages: readonly BaseMessage[];
|
|
51
|
+
readonly toolNames: readonly string[];
|
|
52
|
+
readonly toolChoice?: HostModelToolChoice;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Host implementations authenticate identity/reference and authorize every selected tool.
|
|
56
|
+
* They invoke an already configured model through its public invoke/stream APIs, keeping
|
|
57
|
+
* credentials, model parameters, input/output protection and callbacks host-side. Streams are
|
|
58
|
+
* pull-based: transports must preserve backpressure, cancellation and native message metadata.
|
|
59
|
+
*/
|
|
60
|
+
export interface HostModelService {
|
|
61
|
+
readonly version: 1;
|
|
62
|
+
invoke(request: HostModelRequest, signal?: AbortSignal): Promise<AIMessage>;
|
|
63
|
+
stream(request: HostModelRequest, signal?: AbortSignal): AsyncIterable<AIMessageChunk>;
|
|
64
|
+
}
|
|
65
|
+
export type HostModelErrorCode = 'incompatible' | 'forbidden' | 'blocked' | 'overflow' | 'timeout' | 'cancelled' | 'unavailable';
|
|
66
|
+
export declare class HostModelServiceError extends Error {
|
|
67
|
+
readonly code: HostModelErrorCode;
|
|
68
|
+
constructor(code: HostModelErrorCode);
|
|
69
|
+
}
|
|
70
|
+
export declare function normalizeHostModelError(error: unknown, signal?: AbortSignal): HostModelServiceError | StreamLimitExceededError | PreparedSubagentError;
|
|
71
|
+
interface HostModelCallOptions extends BaseChatModelCallOptions {
|
|
72
|
+
hostToolNames?: string[];
|
|
73
|
+
tool_choice?: string | {
|
|
74
|
+
type: 'function';
|
|
75
|
+
function: {
|
|
76
|
+
name: string;
|
|
77
|
+
};
|
|
78
|
+
} | {
|
|
79
|
+
type: 'tool';
|
|
80
|
+
name: string;
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
/** Native LangChain model facade; no provider/model options or credentials cross to the host. */
|
|
84
|
+
export declare class HostChatModel extends BaseChatModel<HostModelCallOptions> {
|
|
85
|
+
private readonly identity;
|
|
86
|
+
private readonly descriptor;
|
|
87
|
+
private readonly service;
|
|
88
|
+
private readonly schemas;
|
|
89
|
+
constructor(options: {
|
|
90
|
+
identity: Readonly<ExecutionIdentity>;
|
|
91
|
+
descriptor: HostModelDescriptor;
|
|
92
|
+
service: HostModelService;
|
|
93
|
+
});
|
|
94
|
+
_llmType(): string;
|
|
95
|
+
get callKeys(): string[];
|
|
96
|
+
getLsParams(): ReturnType<BaseChatModel['getLsParams']>;
|
|
97
|
+
_identifyingParams(): Pick<HostModelDescriptor, 'provider' | 'model' | 'reference'>;
|
|
98
|
+
bindTools(tools: BindToolsInput[], kwargs?: Partial<HostModelCallOptions>): Runnable<BaseLanguageModelInput, AIMessageChunk, HostModelCallOptions>;
|
|
99
|
+
private validateTools;
|
|
100
|
+
private request;
|
|
101
|
+
_generate(messages: BaseMessage[], options: this['ParsedCallOptions']): Promise<ChatResult>;
|
|
102
|
+
_streamResponseChunks(messages: BaseMessage[], options: this['ParsedCallOptions'], runManager?: CallbackManagerForLLMRun): AsyncGenerator<ChatGenerationChunk>;
|
|
103
|
+
}
|
|
104
|
+
export {};
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import type { BaseChatModel } from '@langchain/core/language_models/chat_models';
|
|
2
|
+
import type { RunnableConfig } from '@langchain/core/runnables';
|
|
3
|
+
import type { HostModelDescriptor, HostModelService } from './model';
|
|
4
|
+
import type { ExecutionIdentity } from './identity';
|
|
5
|
+
interface ModelLease {
|
|
6
|
+
charge(bytes: number): void;
|
|
7
|
+
retain(): void;
|
|
8
|
+
release(): void;
|
|
9
|
+
}
|
|
10
|
+
/** Shared host scope; admission remains charged until provider work and iterator cleanup settle. */
|
|
11
|
+
export declare class HostModelAdmission {
|
|
12
|
+
private calls;
|
|
13
|
+
private bytes;
|
|
14
|
+
private retainedCalls;
|
|
15
|
+
private retainedBytes;
|
|
16
|
+
private readonly maxConcurrentCalls;
|
|
17
|
+
private readonly maxRequestBytes;
|
|
18
|
+
constructor(limits: {
|
|
19
|
+
maxConcurrentCalls: number;
|
|
20
|
+
maxRequestBytes: number;
|
|
21
|
+
});
|
|
22
|
+
snapshot(): Readonly<{
|
|
23
|
+
calls: number;
|
|
24
|
+
requestBytes: number;
|
|
25
|
+
retainedCalls: number;
|
|
26
|
+
retainedRequestBytes: number;
|
|
27
|
+
}>;
|
|
28
|
+
/** @internal The binding owns this lease; transports cannot release outstanding provider work. */
|
|
29
|
+
acquire(bytes: number): ModelLease;
|
|
30
|
+
}
|
|
31
|
+
export interface HostModelLimits {
|
|
32
|
+
readonly timeoutMs: number;
|
|
33
|
+
readonly maxRequestBytes: number;
|
|
34
|
+
/** Cumulative serialized native-message bytes, including metadata and tool chunks. */
|
|
35
|
+
readonly maxResponseBytes: number;
|
|
36
|
+
}
|
|
37
|
+
/** Binds native model execution to one authenticated execution; transport authentication remains external. */
|
|
38
|
+
export declare function createHostModelService(options: {
|
|
39
|
+
identity: Readonly<ExecutionIdentity>;
|
|
40
|
+
descriptor: HostModelDescriptor;
|
|
41
|
+
model: BaseChatModel;
|
|
42
|
+
admission: HostModelAdmission;
|
|
43
|
+
limits: HostModelLimits;
|
|
44
|
+
/** Trusted host configuration only. Worker config is never merged into it. */
|
|
45
|
+
config?: RunnableConfig;
|
|
46
|
+
}): {
|
|
47
|
+
descriptor: HostModelDescriptor;
|
|
48
|
+
service: HostModelService;
|
|
49
|
+
};
|
|
50
|
+
export {};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { AIMessageChunk } from '@langchain/core/messages';
|
|
2
|
+
import type { UsageMetadata } from '@langchain/core/messages';
|
|
3
|
+
import type { RunnableConfig } from '@langchain/core/runnables';
|
|
4
|
+
import type { HostModelErrorCode } from './model';
|
|
5
|
+
/** Observes native completion; only synthesizes an end when iterator return bypasses it. */
|
|
6
|
+
export declare function modelStreamCallbacks(model: object, config: RunnableConfig): {
|
|
7
|
+
config: RunnableConfig;
|
|
8
|
+
observe(chunk: AIMessageChunk): void;
|
|
9
|
+
observeUsage(usage: UsageMetadata | undefined): void;
|
|
10
|
+
finish(reason: HostModelErrorCode): Promise<void>;
|
|
11
|
+
};
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { ProviderTextAdmission } from '@/protection/providerTextAdmission';
|
|
1
2
|
import type { ProviderTextProtection } from '@/protection/providerText';
|
|
2
3
|
import type { ExecutionIdentity } from './identity';
|
|
3
4
|
/** Host-owned limits, negotiated before executing a graph. Contains no credentials or callbacks. */
|
|
@@ -16,6 +17,10 @@ export interface HostProviderTextService {
|
|
|
16
17
|
export declare function createHostProviderTextService(options: {
|
|
17
18
|
identity: Readonly<ExecutionIdentity>;
|
|
18
19
|
policy: ProviderTextProtection;
|
|
20
|
+
/** Reuse a host-owned scope for all bindings sharing a tenant or runtime quota. */
|
|
21
|
+
admission?: ProviderTextAdmission;
|
|
22
|
+
/** Host inspection deadline; cannot extend the policy's model-attempt timeout. */
|
|
23
|
+
inspectionTimeoutMs?: number;
|
|
19
24
|
}): {
|
|
20
25
|
descriptor: HostProviderTextDescriptor;
|
|
21
26
|
service: HostProviderTextService;
|
package/dist/types/index.d.ts
CHANGED
|
@@ -62,8 +62,10 @@ export { DEFAULT_MAX_TOOL_CALL_ARG_BYTES, StreamLimitExceededError, resolveStrea
|
|
|
62
62
|
export type { StreamedToolCallArgTally, ResolvedStreamLimits, StreamLimitState, StreamLimitKind, } from './llm/streamLimits';
|
|
63
63
|
export * from './decisions';
|
|
64
64
|
export * from './rerank';
|
|
65
|
-
export { PROVIDER_TEXT_PROTECTION_VERSION, ProviderTextProtectionError, } from './protection/providerText';
|
|
66
|
-
export type { ProviderTextProtection, ProviderTextProtectionResult, ProviderTextProtectionErrorCode, } from './protection/providerText';
|
|
65
|
+
export { PROVIDER_TEXT_PROTECTION_VERSION, ProviderTextProtectionError, serializeProviderTextProtectionError, deserializeProviderTextProtectionError, } from './protection/providerText';
|
|
66
|
+
export type { ProviderTextProtection, ProviderTextProtectionResult, ProviderTextProtectionErrorCode, ProviderTextProtectionFailure, } from './protection/providerText';
|
|
67
67
|
export { GEMINI_PARTS, GEMINI_REPLAY_UNSUPPORTED, captureGeminiReplayParts, restoreGeminiReplayParts, isGeminiReplayParts, } from './llm/google/utils/signatures';
|
|
68
68
|
export type { GeminiReplayPart } from './llm/google/utils/signatures';
|
|
69
69
|
export * from './harness';
|
|
70
|
+
export { ProviderTextAdmission } from './protection/providerTextAdmission';
|
|
71
|
+
export type { ProviderTextAdmissionLimits, ProviderTextAdmissionSnapshot, } from './protection/providerTextAdmission';
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { CallbackManagerForLLMRun } from '@langchain/core/callbacks/manager';
|
|
2
|
+
import type { RunnableConfig } from '@langchain/core/runnables';
|
|
3
|
+
export interface ModelCallbackRunContext {
|
|
4
|
+
parentRunId?: string;
|
|
5
|
+
tags?: string[];
|
|
6
|
+
metadata?: RunnableConfig['metadata'];
|
|
7
|
+
}
|
|
8
|
+
/** Reconstructs the actual native run for early closes, including model-level callback sources. */
|
|
9
|
+
export declare function getModelCallbackRunManager(runId: string, config?: RunnableConfig, model?: unknown, observed?: ModelCallbackRunContext): Promise<CallbackManagerForLLMRun | undefined>;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { ProviderTextAdmission } from './providerTextAdmission';
|
|
1
2
|
export declare const PROVIDER_TEXT_PROTECTION_VERSION = 1;
|
|
2
3
|
export type ProviderTextProtectionErrorCode = 'blocked' | 'unavailable' | 'timeout' | 'overflow' | 'cancelled' | 'unsupported' | 'incompatible';
|
|
3
4
|
export type ProviderTextProtectionResult = {
|
|
@@ -46,7 +47,19 @@ export declare function createProviderTextRestartCancellation(): ProviderTextPro
|
|
|
46
47
|
export declare function isProviderTextRestartCancellation(error: unknown): boolean;
|
|
47
48
|
/** Provider smoothing must stay lazy while the release boundary owns raw text. */
|
|
48
49
|
export declare function isProtectedProviderTextSignal(signal?: AbortSignal): boolean;
|
|
50
|
+
export type ProviderTextProtectionFailure = Extract<ProviderTextProtectionResult, {
|
|
51
|
+
ok: false;
|
|
52
|
+
}>;
|
|
53
|
+
/** Safe wire failure, including errors raised by a separate CJS/ESM copy of the SDK. */
|
|
54
|
+
export declare function serializeProviderTextProtectionError(error: unknown): ProviderTextProtectionFailure;
|
|
55
|
+
/** Decode only an authenticated host's failure envelope; unknown versions/codes fail closed. */
|
|
56
|
+
export declare function deserializeProviderTextProtectionError(failure: unknown): ProviderTextProtectionError;
|
|
57
|
+
export declare function validateProviderTextTimeout(timeoutMs: number): void;
|
|
49
58
|
export declare function validateProviderTextProtection(policy: ProviderTextProtection): void;
|
|
59
|
+
export interface ProviderTextAttemptOptions {
|
|
60
|
+
readonly timeoutMs?: number;
|
|
61
|
+
readonly admission?: ProviderTextAdmission;
|
|
62
|
+
}
|
|
50
63
|
/** A lease stays charged while a cancellation-ignoring producer/handler still owns raw text. */
|
|
51
64
|
export declare class ProviderTextAttempt {
|
|
52
65
|
private readonly policy;
|
|
@@ -61,7 +74,8 @@ export declare class ProviderTextAttempt {
|
|
|
61
74
|
private readonly timer;
|
|
62
75
|
private readonly abort;
|
|
63
76
|
private finished;
|
|
64
|
-
|
|
77
|
+
private readonly admission?;
|
|
78
|
+
constructor(policy: ProviderTextProtection, parent?: AbortSignal | undefined, options?: ProviderTextAttemptOptions);
|
|
65
79
|
get signal(): AbortSignal;
|
|
66
80
|
check(): void;
|
|
67
81
|
private charge;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
export interface ProviderTextAdmissionLimits {
|
|
2
|
+
readonly maxConcurrentInspections: number;
|
|
3
|
+
readonly maxBufferedBytes: number;
|
|
4
|
+
}
|
|
5
|
+
export interface ProviderTextAdmissionSnapshot {
|
|
6
|
+
readonly inspections: number;
|
|
7
|
+
readonly bufferedBytes: number;
|
|
8
|
+
/** Finished callers whose inspectors have not settled. Included in the totals above. */
|
|
9
|
+
readonly retainedInspections: number;
|
|
10
|
+
readonly retainedBytes: number;
|
|
11
|
+
}
|
|
12
|
+
/** Internal ownership lease; only the attempt that acquires it may release it. */
|
|
13
|
+
export interface ProviderTextAdmissionLease {
|
|
14
|
+
charge(bytes: number): void;
|
|
15
|
+
retain(): void;
|
|
16
|
+
release(): void;
|
|
17
|
+
}
|
|
18
|
+
/** Host-owned admission scope. Reuse across bindings/reconnects belonging to the same quota. */
|
|
19
|
+
export declare class ProviderTextAdmission {
|
|
20
|
+
private readonly limits;
|
|
21
|
+
private inspections;
|
|
22
|
+
private bufferedBytes;
|
|
23
|
+
private retainedInspections;
|
|
24
|
+
private retainedBytes;
|
|
25
|
+
constructor(limits: ProviderTextAdmissionLimits);
|
|
26
|
+
snapshot(): Readonly<ProviderTextAdmissionSnapshot>;
|
|
27
|
+
/** @internal Acquired by ProviderTextAttempt, never by a transport caller. */
|
|
28
|
+
acquire(): ProviderTextAdmissionLease;
|
|
29
|
+
}
|
package/package.json
CHANGED
package/src/harness/index.ts
CHANGED
|
@@ -216,3 +216,15 @@ export type {
|
|
|
216
216
|
HostProviderTextRequest,
|
|
217
217
|
HostProviderTextService,
|
|
218
218
|
} from './providerText';
|
|
219
|
+
|
|
220
|
+
export { HostChatModel, HostModelServiceError } from './model';
|
|
221
|
+
export type {
|
|
222
|
+
HostModelDescriptor,
|
|
223
|
+
HostModelRequest,
|
|
224
|
+
HostModelService,
|
|
225
|
+
HostModelToolChoice,
|
|
226
|
+
HostModelErrorCode,
|
|
227
|
+
} from './model';
|
|
228
|
+
|
|
229
|
+
export { createHostModelService, HostModelAdmission } from './modelService';
|
|
230
|
+
export type { HostModelLimits } from './modelService';
|