langfn 0.0.1
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 +32 -0
- package/dist/chunk-6NDYO7WC.js +131 -0
- package/dist/chunk-IDYTII3W.js +47 -0
- package/dist/chunk-LIUWQ4NY.js +49 -0
- package/dist/chunk-MHMMFGVC.js +60 -0
- package/dist/chunk-MLKGABMK.js +9 -0
- package/dist/index.d.ts +666 -0
- package/dist/index.js +1174 -0
- package/dist/openai-4W5RU3CU.js +7 -0
- package/dist/openai-LHMGJO6V.js +7 -0
- package/dist/react-EKLNOUM4.js +7 -0
- package/dist/sse-4Y3LCWWO.js +13 -0
- package/dist/tool_agent-OA4BZHA6.js +7 -0
- package/package.json +63 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,666 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { Adapter } from '@superfunctions/db';
|
|
3
|
+
import { Route } from '@superfunctions/http';
|
|
4
|
+
|
|
5
|
+
interface ToolContext {
|
|
6
|
+
metadata: Record<string, any>;
|
|
7
|
+
}
|
|
8
|
+
interface ToolConfig<T extends z.ZodType> {
|
|
9
|
+
name: string;
|
|
10
|
+
description: string;
|
|
11
|
+
schema: T;
|
|
12
|
+
execute: (args: z.infer<T>, context: ToolContext) => Promise<any>;
|
|
13
|
+
}
|
|
14
|
+
declare class Tool<T extends z.ZodType, R = any> {
|
|
15
|
+
readonly name: string;
|
|
16
|
+
readonly description: string;
|
|
17
|
+
readonly schema: T;
|
|
18
|
+
private readonly _execute;
|
|
19
|
+
constructor(config: ToolConfig<T>);
|
|
20
|
+
json_schema(): any;
|
|
21
|
+
run(args: any, context?: ToolContext): Promise<R>;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
type Role = "system" | "user" | "assistant" | "tool";
|
|
25
|
+
interface Message {
|
|
26
|
+
role: Role;
|
|
27
|
+
content: string;
|
|
28
|
+
name?: string;
|
|
29
|
+
tool_call_id?: string;
|
|
30
|
+
}
|
|
31
|
+
interface ToolCall {
|
|
32
|
+
id: string;
|
|
33
|
+
name: string;
|
|
34
|
+
arguments: Record<string, any>;
|
|
35
|
+
}
|
|
36
|
+
interface TokenUsage {
|
|
37
|
+
prompt_tokens: number;
|
|
38
|
+
completion_tokens: number;
|
|
39
|
+
total_tokens?: number;
|
|
40
|
+
}
|
|
41
|
+
interface Cost {
|
|
42
|
+
prompt: number;
|
|
43
|
+
completion: number;
|
|
44
|
+
total: number;
|
|
45
|
+
currency: string;
|
|
46
|
+
}
|
|
47
|
+
interface ChatRequest {
|
|
48
|
+
messages: Message[];
|
|
49
|
+
tools?: any[];
|
|
50
|
+
tool_choice?: string | object;
|
|
51
|
+
metadata?: Record<string, any>;
|
|
52
|
+
}
|
|
53
|
+
interface ChatResponse {
|
|
54
|
+
message: Message;
|
|
55
|
+
tool_calls?: ToolCall[];
|
|
56
|
+
usage?: TokenUsage;
|
|
57
|
+
cost?: Cost;
|
|
58
|
+
trace_id?: string;
|
|
59
|
+
raw?: any;
|
|
60
|
+
}
|
|
61
|
+
interface CompletionRequest {
|
|
62
|
+
prompt: string;
|
|
63
|
+
metadata?: Record<string, any>;
|
|
64
|
+
}
|
|
65
|
+
interface CompletionResponse {
|
|
66
|
+
content: string;
|
|
67
|
+
usage?: TokenUsage;
|
|
68
|
+
cost?: Cost;
|
|
69
|
+
trace_id?: string;
|
|
70
|
+
raw?: any;
|
|
71
|
+
}
|
|
72
|
+
type StreamEvent = ContentEvent | EndEvent | ErrorEvent;
|
|
73
|
+
interface ContentEvent {
|
|
74
|
+
type: "content";
|
|
75
|
+
content: string;
|
|
76
|
+
delta: string;
|
|
77
|
+
trace_id?: string;
|
|
78
|
+
}
|
|
79
|
+
interface EndEvent {
|
|
80
|
+
type: "end";
|
|
81
|
+
finish_reason: string;
|
|
82
|
+
trace_id?: string;
|
|
83
|
+
}
|
|
84
|
+
interface ErrorEvent {
|
|
85
|
+
type: "error";
|
|
86
|
+
error: any;
|
|
87
|
+
trace_id?: string;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
interface ToolAgentResult {
|
|
91
|
+
messages: Message[];
|
|
92
|
+
output: string;
|
|
93
|
+
}
|
|
94
|
+
declare class ToolAgent {
|
|
95
|
+
private options;
|
|
96
|
+
constructor(options: {
|
|
97
|
+
lang: LangFn;
|
|
98
|
+
tools: Tool<any, any>[];
|
|
99
|
+
max_iterations?: number;
|
|
100
|
+
});
|
|
101
|
+
run(prompt: string, options?: {
|
|
102
|
+
system?: string;
|
|
103
|
+
}): Promise<ToolAgentResult>;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
interface ReActResult {
|
|
107
|
+
messages: Message[];
|
|
108
|
+
output: string;
|
|
109
|
+
}
|
|
110
|
+
declare class ReActAgent {
|
|
111
|
+
private options;
|
|
112
|
+
constructor(options: {
|
|
113
|
+
model: LangFn;
|
|
114
|
+
tools: Tool<any, any>[];
|
|
115
|
+
max_iterations?: number;
|
|
116
|
+
system_prompt?: string;
|
|
117
|
+
});
|
|
118
|
+
run(prompt: string): Promise<ReActResult>;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
declare abstract class ChatModel {
|
|
122
|
+
abstract provider: string;
|
|
123
|
+
abstract model: string;
|
|
124
|
+
abstract complete(request: CompletionRequest): Promise<CompletionResponse>;
|
|
125
|
+
abstract chat(request: ChatRequest): Promise<ChatResponse>;
|
|
126
|
+
abstract stream(request: CompletionRequest): AsyncIterable<StreamEvent>;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
declare class StructuredOutput<T extends z.ZodType> {
|
|
130
|
+
private readonly schema;
|
|
131
|
+
constructor(schema: T);
|
|
132
|
+
parse(text: string): z.infer<T>;
|
|
133
|
+
getSchema(): any;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
interface LangFnConfig {
|
|
137
|
+
model: ChatModel;
|
|
138
|
+
observability?: {
|
|
139
|
+
enabled?: boolean;
|
|
140
|
+
watchfn?: any;
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
declare class LangFn {
|
|
144
|
+
private model;
|
|
145
|
+
private config;
|
|
146
|
+
constructor(config: LangFnConfig);
|
|
147
|
+
complete<T extends z.ZodType>(prompt: string, options?: {
|
|
148
|
+
metadata?: Record<string, any>;
|
|
149
|
+
structured?: StructuredOutput<T>;
|
|
150
|
+
}): Promise<CompletionResponse & {
|
|
151
|
+
parsed?: z.infer<T>;
|
|
152
|
+
}>;
|
|
153
|
+
chat<T extends z.ZodType>(messages: Message[], options?: {
|
|
154
|
+
tools?: Tool<any, any>[];
|
|
155
|
+
tool_choice?: string | object;
|
|
156
|
+
metadata?: Record<string, any>;
|
|
157
|
+
structured?: StructuredOutput<T>;
|
|
158
|
+
}): Promise<ChatResponse & {
|
|
159
|
+
parsed?: z.infer<T>;
|
|
160
|
+
}>;
|
|
161
|
+
feedback(traceId: string, options: {
|
|
162
|
+
rating: number;
|
|
163
|
+
comment?: string;
|
|
164
|
+
metadata?: Record<string, any>;
|
|
165
|
+
}): Promise<void>;
|
|
166
|
+
stream(prompt: string, options?: {
|
|
167
|
+
metadata?: Record<string, any>;
|
|
168
|
+
}): AsyncIterable<StreamEvent>;
|
|
169
|
+
streamSSE(prompt: string): AsyncIterable<string>;
|
|
170
|
+
completeBatch(prompts: string[], options?: {
|
|
171
|
+
concurrency?: number;
|
|
172
|
+
metadata?: Record<string, any>;
|
|
173
|
+
}): Promise<CompletionResponse[]>;
|
|
174
|
+
embed(texts: string | string[]): Promise<number[] | number[][]>;
|
|
175
|
+
createReactAgent(tools: Tool<any, any>[], options?: {
|
|
176
|
+
max_iterations?: number;
|
|
177
|
+
system_prompt?: string;
|
|
178
|
+
}): Promise<ReActAgent>;
|
|
179
|
+
createToolAgent(tools: Tool<any, any>[], options?: {
|
|
180
|
+
max_iterations?: number;
|
|
181
|
+
}): Promise<ToolAgent>;
|
|
182
|
+
}
|
|
183
|
+
declare function langfn(config: LangFnConfig): LangFn;
|
|
184
|
+
|
|
185
|
+
type Step<TIn, TOut> = (input: TIn) => Promise<TOut>;
|
|
186
|
+
declare class Chain<TIn, TOut> {
|
|
187
|
+
private readonly _run;
|
|
188
|
+
constructor(_run: (input: TIn) => Promise<TOut>);
|
|
189
|
+
run(input: TIn): Promise<TOut>;
|
|
190
|
+
static sequential<T = any>(steps: Step<any, any>[]): Chain<any, any>;
|
|
191
|
+
static parallel<T = any>(steps: Step<T, any>[]): Chain<T, any[]>;
|
|
192
|
+
static mapReduce<T = any, TMap = any, TReduce = any>(options: {
|
|
193
|
+
map: (input: T) => Promise<TMap>;
|
|
194
|
+
reduce: (inputs: TMap[]) => Promise<TReduce>;
|
|
195
|
+
}): Chain<T[], TReduce>;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
type index$c_Chain<TIn, TOut> = Chain<TIn, TOut>;
|
|
199
|
+
declare const index$c_Chain: typeof Chain;
|
|
200
|
+
type index$c_Step<TIn, TOut> = Step<TIn, TOut>;
|
|
201
|
+
declare namespace index$c {
|
|
202
|
+
export { index$c_Chain as Chain, type index$c_Step as Step };
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
declare class MockChatModel extends ChatModel {
|
|
206
|
+
private responses;
|
|
207
|
+
provider: string;
|
|
208
|
+
model: string;
|
|
209
|
+
constructor(responses?: string[]);
|
|
210
|
+
complete(request: CompletionRequest): Promise<CompletionResponse>;
|
|
211
|
+
chat(request: ChatRequest): Promise<ChatResponse>;
|
|
212
|
+
stream(request: CompletionRequest): AsyncIterable<StreamEvent>;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
interface OpenAIConfig {
|
|
216
|
+
apiKey: string;
|
|
217
|
+
model?: string;
|
|
218
|
+
baseUrl?: string;
|
|
219
|
+
organization?: string;
|
|
220
|
+
project?: string;
|
|
221
|
+
}
|
|
222
|
+
declare class OpenAIChatModel extends ChatModel {
|
|
223
|
+
provider: string;
|
|
224
|
+
model: string;
|
|
225
|
+
private apiKey;
|
|
226
|
+
private baseUrl;
|
|
227
|
+
private organization?;
|
|
228
|
+
private project?;
|
|
229
|
+
constructor(config: OpenAIConfig);
|
|
230
|
+
private fetch;
|
|
231
|
+
complete(request: CompletionRequest): Promise<CompletionResponse>;
|
|
232
|
+
chat(request: ChatRequest): Promise<ChatResponse>;
|
|
233
|
+
stream(request: CompletionRequest): AsyncIterable<StreamEvent>;
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
interface AnthropicConfig {
|
|
237
|
+
apiKey: string;
|
|
238
|
+
model?: string;
|
|
239
|
+
baseUrl?: string;
|
|
240
|
+
version?: string;
|
|
241
|
+
}
|
|
242
|
+
declare class AnthropicChatModel extends ChatModel {
|
|
243
|
+
provider: string;
|
|
244
|
+
model: string;
|
|
245
|
+
private apiKey;
|
|
246
|
+
private baseUrl;
|
|
247
|
+
private version;
|
|
248
|
+
constructor(config: AnthropicConfig);
|
|
249
|
+
private fetch;
|
|
250
|
+
complete(request: CompletionRequest): Promise<CompletionResponse>;
|
|
251
|
+
chat(request: ChatRequest): Promise<ChatResponse>;
|
|
252
|
+
stream(request: CompletionRequest): AsyncIterable<StreamEvent>;
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
interface OllamaConfig {
|
|
256
|
+
model?: string;
|
|
257
|
+
baseUrl?: string;
|
|
258
|
+
}
|
|
259
|
+
declare class OllamaChatModel extends ChatModel {
|
|
260
|
+
provider: string;
|
|
261
|
+
model: string;
|
|
262
|
+
private baseUrl;
|
|
263
|
+
constructor(config?: OllamaConfig);
|
|
264
|
+
private fetch;
|
|
265
|
+
complete(request: CompletionRequest): Promise<CompletionResponse>;
|
|
266
|
+
chat(request: ChatRequest): Promise<ChatResponse>;
|
|
267
|
+
stream(request: CompletionRequest): AsyncIterable<StreamEvent>;
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
type index$b_AnthropicChatModel = AnthropicChatModel;
|
|
271
|
+
declare const index$b_AnthropicChatModel: typeof AnthropicChatModel;
|
|
272
|
+
type index$b_AnthropicConfig = AnthropicConfig;
|
|
273
|
+
type index$b_ChatModel = ChatModel;
|
|
274
|
+
declare const index$b_ChatModel: typeof ChatModel;
|
|
275
|
+
type index$b_MockChatModel = MockChatModel;
|
|
276
|
+
declare const index$b_MockChatModel: typeof MockChatModel;
|
|
277
|
+
type index$b_OllamaChatModel = OllamaChatModel;
|
|
278
|
+
declare const index$b_OllamaChatModel: typeof OllamaChatModel;
|
|
279
|
+
type index$b_OllamaConfig = OllamaConfig;
|
|
280
|
+
type index$b_OpenAIChatModel = OpenAIChatModel;
|
|
281
|
+
declare const index$b_OpenAIChatModel: typeof OpenAIChatModel;
|
|
282
|
+
type index$b_OpenAIConfig = OpenAIConfig;
|
|
283
|
+
declare namespace index$b {
|
|
284
|
+
export { index$b_AnthropicChatModel as AnthropicChatModel, type index$b_AnthropicConfig as AnthropicConfig, index$b_ChatModel as ChatModel, index$b_MockChatModel as MockChatModel, index$b_OllamaChatModel as OllamaChatModel, type index$b_OllamaConfig as OllamaConfig, index$b_OpenAIChatModel as OpenAIChatModel, type index$b_OpenAIConfig as OpenAIConfig };
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
declare const CalculatorTool: Tool<z.ZodObject<{
|
|
288
|
+
expression: z.ZodString;
|
|
289
|
+
}, "strip", z.ZodTypeAny, {
|
|
290
|
+
expression: string;
|
|
291
|
+
}, {
|
|
292
|
+
expression: string;
|
|
293
|
+
}>, any>;
|
|
294
|
+
|
|
295
|
+
declare const ApiCallTool: Tool<z.ZodObject<{
|
|
296
|
+
url: z.ZodString;
|
|
297
|
+
method: z.ZodDefault<z.ZodString>;
|
|
298
|
+
headers: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
299
|
+
body: z.ZodOptional<z.ZodAny>;
|
|
300
|
+
}, "strip", z.ZodTypeAny, {
|
|
301
|
+
method: string;
|
|
302
|
+
url: string;
|
|
303
|
+
headers?: Record<string, string> | undefined;
|
|
304
|
+
body?: any;
|
|
305
|
+
}, {
|
|
306
|
+
url: string;
|
|
307
|
+
method?: string | undefined;
|
|
308
|
+
headers?: Record<string, string> | undefined;
|
|
309
|
+
body?: any;
|
|
310
|
+
}>, any>;
|
|
311
|
+
|
|
312
|
+
declare const index$a_ApiCallTool: typeof ApiCallTool;
|
|
313
|
+
declare const index$a_CalculatorTool: typeof CalculatorTool;
|
|
314
|
+
type index$a_Tool<T extends z.ZodType, R = any> = Tool<T, R>;
|
|
315
|
+
declare const index$a_Tool: typeof Tool;
|
|
316
|
+
type index$a_ToolConfig<T extends z.ZodType> = ToolConfig<T>;
|
|
317
|
+
type index$a_ToolContext = ToolContext;
|
|
318
|
+
declare namespace index$a {
|
|
319
|
+
export { index$a_ApiCallTool as ApiCallTool, index$a_CalculatorTool as CalculatorTool, index$a_Tool as Tool, type index$a_ToolConfig as ToolConfig, type index$a_ToolContext as ToolContext };
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
type index$9_ReActAgent = ReActAgent;
|
|
323
|
+
declare const index$9_ReActAgent: typeof ReActAgent;
|
|
324
|
+
type index$9_ReActResult = ReActResult;
|
|
325
|
+
type index$9_ToolAgent = ToolAgent;
|
|
326
|
+
declare const index$9_ToolAgent: typeof ToolAgent;
|
|
327
|
+
type index$9_ToolAgentResult = ToolAgentResult;
|
|
328
|
+
declare namespace index$9 {
|
|
329
|
+
export { index$9_ReActAgent as ReActAgent, type index$9_ReActResult as ReActResult, index$9_ToolAgent as ToolAgent, type index$9_ToolAgentResult as ToolAgentResult };
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
declare const END = "__end__";
|
|
333
|
+
type NodeFn<TState> = (state: TState) => Promise<TState>;
|
|
334
|
+
type RouteFn<TState> = (state: TState) => string;
|
|
335
|
+
declare class CompiledGraph<TState> {
|
|
336
|
+
private readonly config;
|
|
337
|
+
constructor(config: {
|
|
338
|
+
initialState: TState;
|
|
339
|
+
nodes: Map<string, NodeFn<TState>>;
|
|
340
|
+
edges: Map<string, string>;
|
|
341
|
+
conditionalEdges: Map<string, RouteFn<TState>>;
|
|
342
|
+
entrypoint: string;
|
|
343
|
+
});
|
|
344
|
+
invoke(state?: Partial<TState>, options?: {
|
|
345
|
+
maxSteps?: number;
|
|
346
|
+
}): Promise<TState>;
|
|
347
|
+
}
|
|
348
|
+
declare class StateGraph<TState> {
|
|
349
|
+
private readonly initialState;
|
|
350
|
+
private nodes;
|
|
351
|
+
private edges;
|
|
352
|
+
private conditionalEdges;
|
|
353
|
+
private entrypoint?;
|
|
354
|
+
constructor(initialState: TState);
|
|
355
|
+
addNode(name: string, fn: NodeFn<TState>): this;
|
|
356
|
+
addEdge(from: string, to: string): this;
|
|
357
|
+
addConditionalEdge(from: string, router: RouteFn<TState>): this;
|
|
358
|
+
setEntryPoint(name: string): this;
|
|
359
|
+
compile(): CompiledGraph<TState>;
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
type index$8_CompiledGraph<TState> = CompiledGraph<TState>;
|
|
363
|
+
declare const index$8_CompiledGraph: typeof CompiledGraph;
|
|
364
|
+
declare const index$8_END: typeof END;
|
|
365
|
+
type index$8_NodeFn<TState> = NodeFn<TState>;
|
|
366
|
+
type index$8_RouteFn<TState> = RouteFn<TState>;
|
|
367
|
+
type index$8_StateGraph<TState> = StateGraph<TState>;
|
|
368
|
+
declare const index$8_StateGraph: typeof StateGraph;
|
|
369
|
+
declare namespace index$8 {
|
|
370
|
+
export { index$8_CompiledGraph as CompiledGraph, index$8_END as END, type index$8_NodeFn as NodeFn, type index$8_RouteFn as RouteFn, index$8_StateGraph as StateGraph };
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
interface PromptVariables {
|
|
374
|
+
[key: string]: string | number | boolean;
|
|
375
|
+
}
|
|
376
|
+
declare class PromptTemplate {
|
|
377
|
+
private readonly config;
|
|
378
|
+
constructor(config: {
|
|
379
|
+
template: string;
|
|
380
|
+
variables?: string[];
|
|
381
|
+
});
|
|
382
|
+
format(variables: PromptVariables): string;
|
|
383
|
+
}
|
|
384
|
+
interface ChatMessageTemplate {
|
|
385
|
+
role: "system" | "user" | "assistant";
|
|
386
|
+
content: string;
|
|
387
|
+
}
|
|
388
|
+
declare class ChatPromptTemplate {
|
|
389
|
+
private readonly config;
|
|
390
|
+
constructor(config: {
|
|
391
|
+
messages: ChatMessageTemplate[];
|
|
392
|
+
});
|
|
393
|
+
format(variables: PromptVariables): any[];
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
interface PromptRecord {
|
|
397
|
+
id: string;
|
|
398
|
+
name: string;
|
|
399
|
+
version: string;
|
|
400
|
+
template: string;
|
|
401
|
+
variables: string[];
|
|
402
|
+
description?: string;
|
|
403
|
+
tags: string[];
|
|
404
|
+
createdAt: number;
|
|
405
|
+
updatedAt: number;
|
|
406
|
+
}
|
|
407
|
+
declare class PromptRegistry {
|
|
408
|
+
private readonly db;
|
|
409
|
+
private tableName;
|
|
410
|
+
constructor(db: Adapter);
|
|
411
|
+
save(name: string, prompt: PromptTemplate, options: {
|
|
412
|
+
version: string;
|
|
413
|
+
description?: string;
|
|
414
|
+
tags?: string[];
|
|
415
|
+
}): Promise<void>;
|
|
416
|
+
load(name: string, options?: {
|
|
417
|
+
version?: string;
|
|
418
|
+
}): Promise<PromptTemplate | null>;
|
|
419
|
+
list(tags?: string[]): Promise<PromptRecord[]>;
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
interface FewShotExample {
|
|
423
|
+
input: string;
|
|
424
|
+
output: string;
|
|
425
|
+
}
|
|
426
|
+
declare class FewShotPrompt {
|
|
427
|
+
private readonly config;
|
|
428
|
+
constructor(config: {
|
|
429
|
+
prefix: string;
|
|
430
|
+
examples: FewShotExample[];
|
|
431
|
+
suffix: string;
|
|
432
|
+
inputVariables: string[];
|
|
433
|
+
exampleSeparator?: string;
|
|
434
|
+
});
|
|
435
|
+
format(variables: Record<string, any>): string;
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
type index$7_ChatMessageTemplate = ChatMessageTemplate;
|
|
439
|
+
type index$7_ChatPromptTemplate = ChatPromptTemplate;
|
|
440
|
+
declare const index$7_ChatPromptTemplate: typeof ChatPromptTemplate;
|
|
441
|
+
type index$7_FewShotExample = FewShotExample;
|
|
442
|
+
type index$7_FewShotPrompt = FewShotPrompt;
|
|
443
|
+
declare const index$7_FewShotPrompt: typeof FewShotPrompt;
|
|
444
|
+
type index$7_PromptRecord = PromptRecord;
|
|
445
|
+
type index$7_PromptRegistry = PromptRegistry;
|
|
446
|
+
declare const index$7_PromptRegistry: typeof PromptRegistry;
|
|
447
|
+
type index$7_PromptTemplate = PromptTemplate;
|
|
448
|
+
declare const index$7_PromptTemplate: typeof PromptTemplate;
|
|
449
|
+
type index$7_PromptVariables = PromptVariables;
|
|
450
|
+
declare namespace index$7 {
|
|
451
|
+
export { type index$7_ChatMessageTemplate as ChatMessageTemplate, index$7_ChatPromptTemplate as ChatPromptTemplate, type index$7_FewShotExample as FewShotExample, index$7_FewShotPrompt as FewShotPrompt, type index$7_PromptRecord as PromptRecord, index$7_PromptRegistry as PromptRegistry, index$7_PromptTemplate as PromptTemplate, type index$7_PromptVariables as PromptVariables };
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
declare class BufferMemory {
|
|
455
|
+
private messages;
|
|
456
|
+
private maxMessages;
|
|
457
|
+
constructor(options?: {
|
|
458
|
+
maxMessages?: number;
|
|
459
|
+
});
|
|
460
|
+
add(message: Message): Promise<void>;
|
|
461
|
+
extend(messages: Message[]): Promise<void>;
|
|
462
|
+
get(): Promise<Message[]>;
|
|
463
|
+
clear(): Promise<void>;
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
declare class SummaryMemory {
|
|
467
|
+
private readonly lang;
|
|
468
|
+
private messages;
|
|
469
|
+
private summary?;
|
|
470
|
+
private maxTokens;
|
|
471
|
+
private summaryPrompt;
|
|
472
|
+
constructor(lang: LangFn, options?: {
|
|
473
|
+
maxTokens?: number;
|
|
474
|
+
summaryPrompt?: string;
|
|
475
|
+
});
|
|
476
|
+
add(message: Message): Promise<void>;
|
|
477
|
+
private summarize;
|
|
478
|
+
get(): Promise<Message[]>;
|
|
479
|
+
clear(): Promise<void>;
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
type index$6_BufferMemory = BufferMemory;
|
|
483
|
+
declare const index$6_BufferMemory: typeof BufferMemory;
|
|
484
|
+
type index$6_SummaryMemory = SummaryMemory;
|
|
485
|
+
declare const index$6_SummaryMemory: typeof SummaryMemory;
|
|
486
|
+
declare namespace index$6 {
|
|
487
|
+
export { index$6_BufferMemory as BufferMemory, index$6_SummaryMemory as SummaryMemory };
|
|
488
|
+
}
|
|
489
|
+
|
|
490
|
+
interface Document {
|
|
491
|
+
content: string;
|
|
492
|
+
metadata: Record<string, any>;
|
|
493
|
+
score?: number;
|
|
494
|
+
}
|
|
495
|
+
declare abstract class Embeddings {
|
|
496
|
+
abstract embedQuery(text: string): Promise<number[]>;
|
|
497
|
+
abstract embedDocuments(texts: string[]): Promise<number[][]>;
|
|
498
|
+
}
|
|
499
|
+
declare abstract class VectorStore {
|
|
500
|
+
abstract addDocuments(documents: Document[]): Promise<void>;
|
|
501
|
+
abstract search(query: string, options?: {
|
|
502
|
+
k?: number;
|
|
503
|
+
filter?: Record<string, any>;
|
|
504
|
+
}): Promise<Document[]>;
|
|
505
|
+
}
|
|
506
|
+
declare abstract class Retriever {
|
|
507
|
+
abstract getRelevantDocuments(query: string): Promise<Document[]>;
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
interface OpenAIEmbeddingsConfig {
|
|
511
|
+
apiKey: string;
|
|
512
|
+
model?: string;
|
|
513
|
+
baseUrl?: string;
|
|
514
|
+
}
|
|
515
|
+
declare class OpenAIEmbeddings extends Embeddings {
|
|
516
|
+
private apiKey;
|
|
517
|
+
private model;
|
|
518
|
+
private baseUrl;
|
|
519
|
+
constructor(config: OpenAIEmbeddingsConfig);
|
|
520
|
+
embedQuery(text: string): Promise<number[]>;
|
|
521
|
+
embedDocuments(texts: string[]): Promise<number[][]>;
|
|
522
|
+
}
|
|
523
|
+
|
|
524
|
+
declare class InMemoryVectorStore extends VectorStore {
|
|
525
|
+
private readonly embeddings;
|
|
526
|
+
private documents;
|
|
527
|
+
private vectors;
|
|
528
|
+
constructor(embeddings: Embeddings);
|
|
529
|
+
addDocuments(documents: Document[]): Promise<void>;
|
|
530
|
+
search(query: string, options?: {
|
|
531
|
+
k?: number;
|
|
532
|
+
filter?: Record<string, any>;
|
|
533
|
+
}): Promise<Document[]>;
|
|
534
|
+
private cosineSimilarity;
|
|
535
|
+
}
|
|
536
|
+
|
|
537
|
+
interface DocumentRecord {
|
|
538
|
+
id: string;
|
|
539
|
+
content: string;
|
|
540
|
+
embedding: number[];
|
|
541
|
+
metadata: Record<string, any>;
|
|
542
|
+
namespace: string;
|
|
543
|
+
createdAt: number;
|
|
544
|
+
}
|
|
545
|
+
declare class DbVectorStore extends VectorStore {
|
|
546
|
+
private readonly db;
|
|
547
|
+
private readonly embeddings;
|
|
548
|
+
private readonly namespace;
|
|
549
|
+
private tableName;
|
|
550
|
+
constructor(db: Adapter, embeddings: Embeddings, namespace?: string);
|
|
551
|
+
addDocuments(documents: Document[]): Promise<void>;
|
|
552
|
+
search(query: string, options?: {
|
|
553
|
+
k?: number;
|
|
554
|
+
filter?: Record<string, any>;
|
|
555
|
+
}): Promise<Document[]>;
|
|
556
|
+
private cosineSimilarity;
|
|
557
|
+
}
|
|
558
|
+
|
|
559
|
+
type index$5_DbVectorStore = DbVectorStore;
|
|
560
|
+
declare const index$5_DbVectorStore: typeof DbVectorStore;
|
|
561
|
+
type index$5_Document = Document;
|
|
562
|
+
type index$5_DocumentRecord = DocumentRecord;
|
|
563
|
+
type index$5_Embeddings = Embeddings;
|
|
564
|
+
declare const index$5_Embeddings: typeof Embeddings;
|
|
565
|
+
type index$5_InMemoryVectorStore = InMemoryVectorStore;
|
|
566
|
+
declare const index$5_InMemoryVectorStore: typeof InMemoryVectorStore;
|
|
567
|
+
type index$5_OpenAIEmbeddings = OpenAIEmbeddings;
|
|
568
|
+
declare const index$5_OpenAIEmbeddings: typeof OpenAIEmbeddings;
|
|
569
|
+
type index$5_OpenAIEmbeddingsConfig = OpenAIEmbeddingsConfig;
|
|
570
|
+
type index$5_Retriever = Retriever;
|
|
571
|
+
declare const index$5_Retriever: typeof Retriever;
|
|
572
|
+
type index$5_VectorStore = VectorStore;
|
|
573
|
+
declare const index$5_VectorStore: typeof VectorStore;
|
|
574
|
+
declare namespace index$5 {
|
|
575
|
+
export { index$5_DbVectorStore as DbVectorStore, type index$5_Document as Document, type index$5_DocumentRecord as DocumentRecord, index$5_Embeddings as Embeddings, index$5_InMemoryVectorStore as InMemoryVectorStore, index$5_OpenAIEmbeddings as OpenAIEmbeddings, type index$5_OpenAIEmbeddingsConfig as OpenAIEmbeddingsConfig, index$5_Retriever as Retriever, index$5_VectorStore as VectorStore };
|
|
576
|
+
}
|
|
577
|
+
|
|
578
|
+
declare class ResponseCache {
|
|
579
|
+
private readonly db;
|
|
580
|
+
private readonly ttl;
|
|
581
|
+
private tableName;
|
|
582
|
+
constructor(db: Adapter, ttl?: number);
|
|
583
|
+
private generateKey;
|
|
584
|
+
get(prompt: string, model: string, provider: string, metadata?: Record<string, any>): Promise<any | null>;
|
|
585
|
+
set(prompt: string, model: string, provider: string, value: any, metadata?: Record<string, any>): Promise<void>;
|
|
586
|
+
}
|
|
587
|
+
|
|
588
|
+
type index$4_ResponseCache = ResponseCache;
|
|
589
|
+
declare const index$4_ResponseCache: typeof ResponseCache;
|
|
590
|
+
declare namespace index$4 {
|
|
591
|
+
export { index$4_ResponseCache as ResponseCache };
|
|
592
|
+
}
|
|
593
|
+
|
|
594
|
+
declare function countTokens(text: string, model?: string): number;
|
|
595
|
+
declare function countMessagesTokens(messages: any[], model?: string): number;
|
|
596
|
+
|
|
597
|
+
declare const index$3_countMessagesTokens: typeof countMessagesTokens;
|
|
598
|
+
declare const index$3_countTokens: typeof countTokens;
|
|
599
|
+
declare namespace index$3 {
|
|
600
|
+
export { index$3_countMessagesTokens as countMessagesTokens, index$3_countTokens as countTokens };
|
|
601
|
+
}
|
|
602
|
+
|
|
603
|
+
interface TraceSpanOptions {
|
|
604
|
+
name: string;
|
|
605
|
+
metadata?: Record<string, any>;
|
|
606
|
+
}
|
|
607
|
+
declare class Tracer {
|
|
608
|
+
private watch;
|
|
609
|
+
constructor(options?: {
|
|
610
|
+
watch?: any;
|
|
611
|
+
});
|
|
612
|
+
trace<T>(name: string, metadata: Record<string, any>, fn: () => Promise<T>): Promise<T>;
|
|
613
|
+
}
|
|
614
|
+
|
|
615
|
+
interface TraceRecord {
|
|
616
|
+
id: string;
|
|
617
|
+
startTime: number;
|
|
618
|
+
endTime: number;
|
|
619
|
+
model: string;
|
|
620
|
+
provider: string;
|
|
621
|
+
input: string;
|
|
622
|
+
output: string;
|
|
623
|
+
tokens: TokenUsage;
|
|
624
|
+
latency: number;
|
|
625
|
+
cost?: Cost;
|
|
626
|
+
metadata: Record<string, any>;
|
|
627
|
+
userId?: string;
|
|
628
|
+
}
|
|
629
|
+
declare class TraceStorage {
|
|
630
|
+
private readonly db;
|
|
631
|
+
private tableName;
|
|
632
|
+
constructor(db: Adapter);
|
|
633
|
+
save(trace: TraceRecord): Promise<void>;
|
|
634
|
+
findMany(options?: {
|
|
635
|
+
limit?: number;
|
|
636
|
+
offset?: number;
|
|
637
|
+
model?: string;
|
|
638
|
+
provider?: string;
|
|
639
|
+
}): Promise<TraceRecord[]>;
|
|
640
|
+
findOne(id: string): Promise<TraceRecord | null>;
|
|
641
|
+
}
|
|
642
|
+
|
|
643
|
+
type index$2_TraceRecord = TraceRecord;
|
|
644
|
+
type index$2_TraceSpanOptions = TraceSpanOptions;
|
|
645
|
+
type index$2_TraceStorage = TraceStorage;
|
|
646
|
+
declare const index$2_TraceStorage: typeof TraceStorage;
|
|
647
|
+
type index$2_Tracer = Tracer;
|
|
648
|
+
declare const index$2_Tracer: typeof Tracer;
|
|
649
|
+
declare namespace index$2 {
|
|
650
|
+
export { type index$2_TraceRecord as TraceRecord, type index$2_TraceSpanOptions as TraceSpanOptions, index$2_TraceStorage as TraceStorage, index$2_Tracer as Tracer };
|
|
651
|
+
}
|
|
652
|
+
|
|
653
|
+
declare function createLangFnRouter(lang: LangFn): Route[];
|
|
654
|
+
|
|
655
|
+
declare const index$1_createLangFnRouter: typeof createLangFnRouter;
|
|
656
|
+
declare namespace index$1 {
|
|
657
|
+
export { index$1_createLangFnRouter as createLangFnRouter };
|
|
658
|
+
}
|
|
659
|
+
|
|
660
|
+
type index_StructuredOutput<T extends z.ZodType> = StructuredOutput<T>;
|
|
661
|
+
declare const index_StructuredOutput: typeof StructuredOutput;
|
|
662
|
+
declare namespace index {
|
|
663
|
+
export { index_StructuredOutput as StructuredOutput };
|
|
664
|
+
}
|
|
665
|
+
|
|
666
|
+
export { Chain, ChatModel, type ChatRequest, type ChatResponse, type CompletionRequest, type CompletionResponse, type ContentEvent, type Cost, type EndEvent, type ErrorEvent, LangFn, type LangFnConfig, type Message, type Role, type Step, type StreamEvent, type TokenUsage, Tool, type ToolCall, type ToolConfig, type ToolContext, index$9 as agents, index$8 as graph, index$1 as http, langfn, index$6 as memory, index$b as models, index$2 as observability, index$c as orchestration, index$7 as prompts, index$5 as rag, index$4 as storage, index as structured, index$a as tools, index$3 as utils };
|