@picoflow/ezgraph 0.0.4
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/LICENSE.md +17 -0
- package/README.md +171 -0
- package/dist/framework/base-graph.js +1 -0
- package/dist/framework/config-manager.js +1 -0
- package/dist/framework/conversation-node.js +1 -0
- package/dist/framework/conversation-runner.js +1 -0
- package/dist/framework/conversation-tool-result.js +1 -0
- package/dist/framework/graph-engine.js +1 -0
- package/dist/framework/graph-llm.config.js +1 -0
- package/dist/framework/graph-node.js +1 -0
- package/dist/framework/graph-registry.js +1 -0
- package/dist/framework/graph-state-support.js +1 -0
- package/dist/framework/graph-state.js +1 -0
- package/dist/framework/json-response.js +1 -0
- package/dist/framework/langchain-llm-gateway.js +1 -0
- package/dist/framework/langchain-provider.adapter.js +1 -0
- package/dist/framework/llm-file.js +1 -0
- package/dist/framework/llm-gateway.js +1 -0
- package/dist/framework/model-catalog.js +1 -0
- package/dist/framework/model-provider.js +1 -0
- package/dist/framework/model-stop-reason.js +1 -0
- package/dist/framework/node-outcome.js +1 -0
- package/dist/framework/node-state.js +1 -0
- package/dist/framework/persistence/cosmos-session-document.container.js +1 -0
- package/dist/framework/persistence/mongodb-session-document.container.js +1 -0
- package/dist/framework/persistence/session-manager.js +1 -0
- package/dist/framework/persistence/sqlite-session-document.container.js +13 -0
- package/dist/framework/session-log.js +1 -0
- package/dist/framework/stable-id.js +1 -0
- package/dist/framework/state-graph-ext.js +1 -0
- package/dist/framework/terminate-session.node.js +1 -0
- package/dist/framework/token-usage.js +1 -0
- package/dist/framework/turn-context.js +1 -0
- package/dist/index.js +1 -0
- package/dist/testing/scripted-gateway.js +1 -0
- package/dist/testing/turn-harness.js +1 -0
- package/dist/testing.js +1 -0
- package/dist/types/npmlib/src/index.d.ts +27 -0
- package/dist/types/npmlib/src/testing.d.ts +2 -0
- package/dist/types/src/framework/base-graph.d.ts +66 -0
- package/dist/types/src/framework/config-manager.d.ts +13 -0
- package/dist/types/src/framework/conversation-node.d.ts +18 -0
- package/dist/types/src/framework/conversation-runner.d.ts +49 -0
- package/dist/types/src/framework/conversation-tool-result.d.ts +19 -0
- package/dist/types/src/framework/graph-engine.d.ts +82 -0
- package/dist/types/src/framework/graph-llm.config.d.ts +21 -0
- package/dist/types/src/framework/graph-node.d.ts +106 -0
- package/dist/types/src/framework/graph-registry.d.ts +26 -0
- package/dist/types/src/framework/graph-state-support.d.ts +24 -0
- package/dist/types/src/framework/graph-state.d.ts +26 -0
- package/dist/types/src/framework/json-response.d.ts +1 -0
- package/dist/types/src/framework/langchain-llm-gateway.d.ts +23 -0
- package/dist/types/src/framework/langchain-provider.adapter.d.ts +4 -0
- package/dist/types/src/framework/llm-file.d.ts +13 -0
- package/dist/types/src/framework/llm-gateway.d.ts +27 -0
- package/dist/types/src/framework/model-catalog.d.ts +252 -0
- package/dist/types/src/framework/model-provider.d.ts +19 -0
- package/dist/types/src/framework/model-stop-reason.d.ts +11 -0
- package/dist/types/src/framework/node-outcome.d.ts +41 -0
- package/dist/types/src/framework/node-state.d.ts +6 -0
- package/dist/types/src/framework/persistence/cosmos-session-document.container.d.ts +34 -0
- package/dist/types/src/framework/persistence/mongodb-session-document.container.d.ts +18 -0
- package/dist/types/src/framework/persistence/session-manager.d.ts +116 -0
- package/dist/types/src/framework/persistence/sqlite-session-document.container.d.ts +19 -0
- package/dist/types/src/framework/session-log.d.ts +11 -0
- package/dist/types/src/framework/stable-id.d.ts +7 -0
- package/dist/types/src/framework/state-graph-ext.d.ts +58 -0
- package/dist/types/src/framework/terminate-session.node.d.ts +9 -0
- package/dist/types/src/framework/token-usage.d.ts +24 -0
- package/dist/types/src/framework/turn-context.d.ts +7 -0
- package/dist/types/src/testing/scripted-gateway.d.ts +45 -0
- package/dist/types/src/testing/turn-harness.d.ts +35 -0
- package/model-catalog.schema.json +57 -0
- package/package.json +64 -0
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
export declare const GRAPH_LLM_PROVIDERS: readonly ["openai", "anthropic", "google", "azure_openai", "bedrock", "ollama", "cohere", "cerebras", "deepseek", "fireworks", "groq", "mistral", "mistralai", "perplexity", "together", "xai", "scripted"];
|
|
3
|
+
export type GraphLlmProvider = (typeof GRAPH_LLM_PROVIDERS)[number];
|
|
4
|
+
export declare const GRAPH_LLM_FAMILIES: readonly ["chat", "reasoning", "thinking"];
|
|
5
|
+
export type GraphLlmFamily = (typeof GRAPH_LLM_FAMILIES)[number];
|
|
6
|
+
export declare const GRAPH_LLM_CAPABILITIES: readonly ["imageInputs", "imageUrlInputs", "pdfInputs", "audioInputs", "videoInputs", "reasoningOutput", "toolCalling", "toolChoice", "structuredOutput"];
|
|
7
|
+
export type GraphLlmCapability = (typeof GRAPH_LLM_CAPABILITIES)[number];
|
|
8
|
+
export type GraphLlmRequiredCapabilities = Readonly<Partial<Record<GraphLlmCapability, true>>>;
|
|
9
|
+
export type CommonModelParameters = Readonly<{
|
|
10
|
+
retries: number;
|
|
11
|
+
maxOutputTokens?: number;
|
|
12
|
+
forceToolCalls?: boolean;
|
|
13
|
+
requiredCapabilities?: GraphLlmRequiredCapabilities;
|
|
14
|
+
}>;
|
|
15
|
+
export type OpenAIChatParameters = CommonModelParameters & Readonly<{
|
|
16
|
+
temperature?: number;
|
|
17
|
+
serviceTier?: "auto" | "default" | "flex" | "priority";
|
|
18
|
+
promptCacheKey?: string;
|
|
19
|
+
}>;
|
|
20
|
+
export type OpenAIReasoningParameters = CommonModelParameters & Readonly<{
|
|
21
|
+
reasoningEffort?: "none" | "minimal" | "low" | "medium" | "high" | "xhigh" | "max";
|
|
22
|
+
serviceTier?: "auto" | "default" | "flex" | "priority";
|
|
23
|
+
promptCacheKey?: string;
|
|
24
|
+
}>;
|
|
25
|
+
export type AnthropicChatParameters = CommonModelParameters & Readonly<{
|
|
26
|
+
temperature?: number;
|
|
27
|
+
outputEffort?: "low" | "medium" | "high" | "xhigh" | "max";
|
|
28
|
+
}>;
|
|
29
|
+
export type AnthropicThinkingParameters = CommonModelParameters & Readonly<{
|
|
30
|
+
thinking?: Readonly<{
|
|
31
|
+
type: "adaptive";
|
|
32
|
+
}> | Readonly<{
|
|
33
|
+
type: "disabled";
|
|
34
|
+
}> | Readonly<{
|
|
35
|
+
type: "enabled";
|
|
36
|
+
budget_tokens: number;
|
|
37
|
+
}>;
|
|
38
|
+
outputEffort?: "low" | "medium" | "high" | "xhigh" | "max";
|
|
39
|
+
}>;
|
|
40
|
+
export type GoogleChatParameters = CommonModelParameters & Readonly<{
|
|
41
|
+
temperature?: number;
|
|
42
|
+
thinkingBudget?: number;
|
|
43
|
+
reasoningEffort?: "minimal" | "low" | "medium" | "high";
|
|
44
|
+
safetySettings?: readonly Readonly<{
|
|
45
|
+
category: string;
|
|
46
|
+
threshold: string;
|
|
47
|
+
}>[];
|
|
48
|
+
}>;
|
|
49
|
+
export type BasicChatParameters = CommonModelParameters & Readonly<{
|
|
50
|
+
temperature?: number;
|
|
51
|
+
}>;
|
|
52
|
+
export type BuiltInModelParameters = Readonly<{
|
|
53
|
+
"openai:gpt-4o": OpenAIChatParameters;
|
|
54
|
+
"openai:gpt-4o-mini": OpenAIChatParameters;
|
|
55
|
+
"openai:gpt-5.1": OpenAIReasoningParameters;
|
|
56
|
+
"openai:gpt-5.4": OpenAIReasoningParameters;
|
|
57
|
+
"anthropic:claude-sonnet-4-5": AnthropicChatParameters;
|
|
58
|
+
"anthropic:claude-opus-4-1": AnthropicThinkingParameters;
|
|
59
|
+
"google:gemini-3.1-flash-lite": GoogleChatParameters;
|
|
60
|
+
"google:gemini-3.5-flash": GoogleChatParameters;
|
|
61
|
+
"scripted:scripted-model": BasicChatParameters;
|
|
62
|
+
}>;
|
|
63
|
+
export type BuiltInModelId = keyof BuiltInModelParameters;
|
|
64
|
+
declare const builtInConfig: unique symbol;
|
|
65
|
+
export type BuiltInGraphLlmConfig = {
|
|
66
|
+
readonly [Model in BuiltInModelId]: Readonly<{
|
|
67
|
+
model: Model;
|
|
68
|
+
params: BuiltInModelParameters[Model];
|
|
69
|
+
[builtInConfig]: true;
|
|
70
|
+
}>;
|
|
71
|
+
}[BuiltInModelId];
|
|
72
|
+
export type GraphLlmParameters = CommonModelParameters & Readonly<Record<string, unknown>>;
|
|
73
|
+
export type ModelParameterProfile = Readonly<{
|
|
74
|
+
provider: string;
|
|
75
|
+
family: GraphLlmFamily;
|
|
76
|
+
paramsSchema: Readonly<Record<string, unknown>>;
|
|
77
|
+
parameterMappings: Readonly<Record<string, string | null>>;
|
|
78
|
+
}>;
|
|
79
|
+
export type ModelCatalogDocument = Readonly<{
|
|
80
|
+
$schema?: string;
|
|
81
|
+
version: 1;
|
|
82
|
+
profiles?: Readonly<Record<string, ModelParameterProfile>>;
|
|
83
|
+
models: Readonly<Record<string, Readonly<{
|
|
84
|
+
profile: string;
|
|
85
|
+
providerModel?: string;
|
|
86
|
+
}>>>;
|
|
87
|
+
}>;
|
|
88
|
+
export type ModelProviderInitialization = Readonly<{
|
|
89
|
+
model: string;
|
|
90
|
+
options: Readonly<Record<string, unknown>>;
|
|
91
|
+
cacheKey?: string;
|
|
92
|
+
}>;
|
|
93
|
+
export type ModelProviderAdapter = Readonly<{
|
|
94
|
+
initialize(input: Readonly<{
|
|
95
|
+
provider: string;
|
|
96
|
+
model: string;
|
|
97
|
+
options: Readonly<Record<string, unknown>>;
|
|
98
|
+
}>): ModelProviderInitialization;
|
|
99
|
+
}>;
|
|
100
|
+
export declare class ModelProviderRegistry {
|
|
101
|
+
private readonly adapters;
|
|
102
|
+
static create(): ModelProviderRegistry;
|
|
103
|
+
register(provider: string, adapter: ModelProviderAdapter): this;
|
|
104
|
+
adapter(provider: string): ModelProviderAdapter | undefined;
|
|
105
|
+
}
|
|
106
|
+
export type ResolvedModelDescriptor = Readonly<{
|
|
107
|
+
id: string;
|
|
108
|
+
providerModel: string;
|
|
109
|
+
provider: string;
|
|
110
|
+
family: GraphLlmFamily;
|
|
111
|
+
paramsSchema: z.ZodType;
|
|
112
|
+
parameterMappings: Readonly<Record<string, string | null>>;
|
|
113
|
+
providerAdapter?: ModelProviderAdapter;
|
|
114
|
+
}>;
|
|
115
|
+
declare const runtimeDescriptor: unique symbol;
|
|
116
|
+
export type RuntimeGraphLlmConfig = Readonly<{
|
|
117
|
+
model: string;
|
|
118
|
+
params: GraphLlmParameters;
|
|
119
|
+
[runtimeDescriptor]: ResolvedModelDescriptor;
|
|
120
|
+
}>;
|
|
121
|
+
export type GraphLlmConfig = BuiltInGraphLlmConfig | RuntimeGraphLlmConfig;
|
|
122
|
+
export declare const BUILT_IN_MODEL_CATALOG: {
|
|
123
|
+
readonly version: 1;
|
|
124
|
+
readonly profiles: {
|
|
125
|
+
readonly "openai.chat": {
|
|
126
|
+
readonly provider: "openai";
|
|
127
|
+
readonly family: "chat";
|
|
128
|
+
readonly paramsSchema: Record<string, unknown>;
|
|
129
|
+
readonly parameterMappings: {
|
|
130
|
+
readonly maxOutputTokens: "maxTokens";
|
|
131
|
+
readonly temperature: "temperature";
|
|
132
|
+
readonly serviceTier: "service_tier";
|
|
133
|
+
readonly promptCacheKey: "promptCacheKey";
|
|
134
|
+
readonly retries: "maxRetries";
|
|
135
|
+
readonly forceToolCalls: null;
|
|
136
|
+
readonly requiredCapabilities: null;
|
|
137
|
+
};
|
|
138
|
+
};
|
|
139
|
+
readonly "openai.reasoning": {
|
|
140
|
+
readonly provider: "openai";
|
|
141
|
+
readonly family: "reasoning";
|
|
142
|
+
readonly paramsSchema: Record<string, unknown>;
|
|
143
|
+
readonly parameterMappings: {
|
|
144
|
+
readonly maxOutputTokens: "maxTokens";
|
|
145
|
+
readonly reasoningEffort: "reasoningEffort";
|
|
146
|
+
readonly serviceTier: "service_tier";
|
|
147
|
+
readonly promptCacheKey: "promptCacheKey";
|
|
148
|
+
readonly retries: "maxRetries";
|
|
149
|
+
readonly forceToolCalls: null;
|
|
150
|
+
readonly requiredCapabilities: null;
|
|
151
|
+
};
|
|
152
|
+
};
|
|
153
|
+
readonly "anthropic.chat": {
|
|
154
|
+
readonly provider: "anthropic";
|
|
155
|
+
readonly family: "chat";
|
|
156
|
+
readonly paramsSchema: Record<string, unknown>;
|
|
157
|
+
readonly parameterMappings: {
|
|
158
|
+
readonly maxOutputTokens: "maxTokens";
|
|
159
|
+
readonly temperature: "temperature";
|
|
160
|
+
readonly outputEffort: "outputConfig.effort";
|
|
161
|
+
readonly retries: "maxRetries";
|
|
162
|
+
readonly forceToolCalls: null;
|
|
163
|
+
readonly requiredCapabilities: null;
|
|
164
|
+
};
|
|
165
|
+
};
|
|
166
|
+
readonly "anthropic.thinking": {
|
|
167
|
+
readonly provider: "anthropic";
|
|
168
|
+
readonly family: "thinking";
|
|
169
|
+
readonly paramsSchema: Record<string, unknown>;
|
|
170
|
+
readonly parameterMappings: {
|
|
171
|
+
readonly maxOutputTokens: "maxTokens";
|
|
172
|
+
readonly thinking: "thinking";
|
|
173
|
+
readonly outputEffort: "outputConfig.effort";
|
|
174
|
+
readonly retries: "maxRetries";
|
|
175
|
+
readonly forceToolCalls: null;
|
|
176
|
+
readonly requiredCapabilities: null;
|
|
177
|
+
};
|
|
178
|
+
};
|
|
179
|
+
readonly "google.chat": {
|
|
180
|
+
readonly provider: "google";
|
|
181
|
+
readonly family: "chat";
|
|
182
|
+
readonly paramsSchema: Record<string, unknown>;
|
|
183
|
+
readonly parameterMappings: {
|
|
184
|
+
readonly maxOutputTokens: "maxOutputTokens";
|
|
185
|
+
readonly temperature: "temperature";
|
|
186
|
+
readonly thinkingBudget: "thinkingConfig.thinkingBudget";
|
|
187
|
+
readonly reasoningEffort: "thinkingConfig.reasoningEffort";
|
|
188
|
+
readonly safetySettings: "safetySettings";
|
|
189
|
+
readonly retries: "maxRetries";
|
|
190
|
+
readonly forceToolCalls: null;
|
|
191
|
+
readonly requiredCapabilities: null;
|
|
192
|
+
};
|
|
193
|
+
};
|
|
194
|
+
readonly "scripted.chat": {
|
|
195
|
+
readonly provider: "scripted";
|
|
196
|
+
readonly family: "chat";
|
|
197
|
+
readonly paramsSchema: Record<string, unknown>;
|
|
198
|
+
readonly parameterMappings: {
|
|
199
|
+
readonly maxOutputTokens: "maxTokens";
|
|
200
|
+
readonly temperature: "temperature";
|
|
201
|
+
readonly retries: "maxRetries";
|
|
202
|
+
readonly forceToolCalls: null;
|
|
203
|
+
readonly requiredCapabilities: null;
|
|
204
|
+
};
|
|
205
|
+
};
|
|
206
|
+
};
|
|
207
|
+
readonly models: {
|
|
208
|
+
readonly "openai:gpt-4o": {
|
|
209
|
+
readonly profile: "openai.chat";
|
|
210
|
+
};
|
|
211
|
+
readonly "openai:gpt-4o-mini": {
|
|
212
|
+
readonly profile: "openai.chat";
|
|
213
|
+
};
|
|
214
|
+
readonly "openai:gpt-5.1": {
|
|
215
|
+
readonly profile: "openai.reasoning";
|
|
216
|
+
};
|
|
217
|
+
readonly "openai:gpt-5.4": {
|
|
218
|
+
readonly profile: "openai.reasoning";
|
|
219
|
+
};
|
|
220
|
+
readonly "anthropic:claude-sonnet-4-5": {
|
|
221
|
+
readonly profile: "anthropic.chat";
|
|
222
|
+
};
|
|
223
|
+
readonly "anthropic:claude-opus-4-1": {
|
|
224
|
+
readonly profile: "anthropic.thinking";
|
|
225
|
+
};
|
|
226
|
+
readonly "google:gemini-3.1-flash-lite": {
|
|
227
|
+
readonly profile: "google.chat";
|
|
228
|
+
};
|
|
229
|
+
readonly "google:gemini-3.5-flash": {
|
|
230
|
+
readonly profile: "google.chat";
|
|
231
|
+
};
|
|
232
|
+
readonly "scripted:scripted-model": {
|
|
233
|
+
readonly profile: "scripted.chat";
|
|
234
|
+
};
|
|
235
|
+
};
|
|
236
|
+
};
|
|
237
|
+
export declare class ModelCatalog {
|
|
238
|
+
private readonly descriptors;
|
|
239
|
+
static create(document: unknown, options?: Readonly<{
|
|
240
|
+
providers?: ModelProviderRegistry;
|
|
241
|
+
}>): ModelCatalog;
|
|
242
|
+
static model<Model extends BuiltInModelId>(model: Model, params: BuiltInModelParameters[Model]): Extract<BuiltInGraphLlmConfig, {
|
|
243
|
+
readonly model: Model;
|
|
244
|
+
}>;
|
|
245
|
+
static validateConfig(config: GraphLlmConfig): GraphLlmConfig;
|
|
246
|
+
static resolveModelDescriptor(config: GraphLlmConfig): ResolvedModelDescriptor;
|
|
247
|
+
constructor(document: unknown, options?: Readonly<{
|
|
248
|
+
providers?: ModelProviderRegistry;
|
|
249
|
+
}>);
|
|
250
|
+
model(model: string, params: Readonly<Record<string, unknown>>): RuntimeGraphLlmConfig;
|
|
251
|
+
}
|
|
252
|
+
export {};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { type GraphLlmProvider, type ModelProviderAdapter } from "./graph-llm.config.js";
|
|
2
|
+
export type ModelProviderRuntimeConfig = Readonly<Record<string, unknown>>;
|
|
3
|
+
export type RegisteredModelProviderAdapter = ModelProviderAdapter & Readonly<{
|
|
4
|
+
provider: string;
|
|
5
|
+
}>;
|
|
6
|
+
export type BuiltInModelProviderConfigs = Readonly<Partial<Record<GraphLlmProvider, ModelProviderRuntimeConfig>>>;
|
|
7
|
+
export type CustomModelProviderOptions = Readonly<{
|
|
8
|
+
provider: string;
|
|
9
|
+
runtimeProvider: string;
|
|
10
|
+
config?: ModelProviderRuntimeConfig;
|
|
11
|
+
}>;
|
|
12
|
+
export declare class ModelProvider {
|
|
13
|
+
private constructor();
|
|
14
|
+
static createBuiltinAdapters(configs: BuiltInModelProviderConfigs): RegisteredModelProviderAdapter[];
|
|
15
|
+
static createCustomAdapter(options: CustomModelProviderOptions): RegisteredModelProviderAdapter;
|
|
16
|
+
private static adapter;
|
|
17
|
+
}
|
|
18
|
+
export declare function modelProviderAdapter(provider: string, adapters: readonly RegisteredModelProviderAdapter[]): ModelProviderAdapter | undefined;
|
|
19
|
+
export declare function validateModelProviderAdapters(adapters: readonly RegisteredModelProviderAdapter[]): void;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { AIMessage } from '@langchain/core/messages';
|
|
2
|
+
export type ModelStopCategory = 'complete' | 'blocked' | 'truncated' | 'malformed_tool_call' | 'unspecified';
|
|
3
|
+
export type ModelStopReason = Readonly<{
|
|
4
|
+
category: ModelStopCategory;
|
|
5
|
+
provider?: string;
|
|
6
|
+
detail?: string;
|
|
7
|
+
ratings?: unknown;
|
|
8
|
+
}>;
|
|
9
|
+
export declare function isRetryableStopReason(reason: ModelStopReason): boolean;
|
|
10
|
+
export declare function modelStopReason(message: AIMessage): ModelStopReason;
|
|
11
|
+
export declare function describeStopReason(reason: ModelStopReason): string;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { HumanMessage, type BaseMessage } from '@langchain/core/messages';
|
|
2
|
+
import { END } from '@langchain/langgraph';
|
|
3
|
+
import type { GraphState } from './graph-state.js';
|
|
4
|
+
export declare const GRAPH_NODE_LOCAL_STATE: unique symbol;
|
|
5
|
+
export type GraphNodeTarget<LocalState extends object = object> = {
|
|
6
|
+
readonly name: string;
|
|
7
|
+
id(): string;
|
|
8
|
+
readonly prototype: {
|
|
9
|
+
readonly [GRAPH_NODE_LOCAL_STATE]: LocalState;
|
|
10
|
+
};
|
|
11
|
+
};
|
|
12
|
+
export type GraphNodeLocalState<NodeClass extends GraphNodeTarget> = NodeClass['prototype'][typeof GRAPH_NODE_LOCAL_STATE];
|
|
13
|
+
export type GraphNodeUpdate<State extends GraphState> = Partial<State>;
|
|
14
|
+
export type OutcomeRouteTarget = GraphNodeTarget | typeof END;
|
|
15
|
+
export declare const OUTCOME_ROUTE_TARGET: unique symbol;
|
|
16
|
+
type OutcomeState<State extends GraphState> = Pick<State, 'histories' | 'currentNode'>;
|
|
17
|
+
export type NodeOutcomeBuilder<State extends GraphState, LocalState extends object, CanForwardInput extends boolean = false> = Readonly<GraphNodeUpdate<State>> & {
|
|
18
|
+
withState(patch: Partial<LocalState>): NodeOutcomeBuilder<State, LocalState, CanForwardInput>;
|
|
19
|
+
withStateFor<NodeClass extends GraphNodeTarget>(NodeClass: NodeClass, patch: Partial<GraphNodeLocalState<NodeClass>>): NodeOutcomeBuilder<State, LocalState, CanForwardInput>;
|
|
20
|
+
withHistory(space: string, messages: BaseMessage | readonly BaseMessage[]): NodeOutcomeBuilder<State, LocalState, CanForwardInput>;
|
|
21
|
+
via<NodeClass extends GraphNodeTarget>(NodeClass: NodeClass): NodeOutcomeBuilder<State, LocalState, CanForwardInput>;
|
|
22
|
+
} & (CanForwardInput extends true ? {
|
|
23
|
+
forwardInput(state: OutcomeState<State>, fallbackMessage?: string): NodeOutcomeBuilder<State, LocalState>;
|
|
24
|
+
} : object);
|
|
25
|
+
type BuilderOptions<State extends GraphState, LocalState extends object, CanForwardInput extends boolean> = Readonly<{
|
|
26
|
+
update: GraphNodeUpdate<State>;
|
|
27
|
+
nodeName: string;
|
|
28
|
+
saveNode: (nodeName: string, patch: Record<string, unknown>) => GraphNodeUpdate<State>;
|
|
29
|
+
forwardInput?: (state: OutcomeState<State>, fallbackMessage?: string) => GraphNodeUpdate<State>;
|
|
30
|
+
routeTarget: OutcomeRouteTarget;
|
|
31
|
+
}>;
|
|
32
|
+
export declare function createNodeOutcomeBuilder<State extends GraphState, LocalState extends object, CanForwardInput extends boolean>(options: BuilderOptions<State, LocalState, CanForwardInput>): NodeOutcomeBuilder<State, LocalState, CanForwardInput>;
|
|
33
|
+
export declare function outcomeRouteTarget(update: GraphNodeUpdate<GraphState>): OutcomeRouteTarget | undefined;
|
|
34
|
+
export declare function preserveOutcomeRouteTarget<State extends GraphState, Update extends GraphNodeUpdate<State>>(source: GraphNodeUpdate<State>, update: Update): Update;
|
|
35
|
+
export declare function forwardedHistoryUpdate<State extends GraphState>(options: {
|
|
36
|
+
sourceSpace: string;
|
|
37
|
+
targetSpace: string;
|
|
38
|
+
latestInput?: HumanMessage;
|
|
39
|
+
fallbackMessage?: string;
|
|
40
|
+
}): GraphNodeUpdate<State>;
|
|
41
|
+
export {};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { GraphLlmModelMetadata } from './graph-llm.config.js';
|
|
2
|
+
export type NodeStateValue<T extends object = Record<string, unknown>> = T & {
|
|
3
|
+
model?: GraphLlmModelMetadata | undefined;
|
|
4
|
+
};
|
|
5
|
+
export type GraphNodeStates = Record<string, NodeStateValue>;
|
|
6
|
+
export declare function mergeNodeStates<NodeStates extends object>(current: NodeStates, update: NodeStates): NodeStates;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { type SessionDocument, type SessionDocumentContainer, type SessionWritePredicate, type SessionWriteResult } from './session-manager.js';
|
|
2
|
+
type CosmosItem = {
|
|
3
|
+
read<T>(): Promise<{
|
|
4
|
+
resource?: T;
|
|
5
|
+
etag?: string;
|
|
6
|
+
}>;
|
|
7
|
+
delete(): Promise<unknown>;
|
|
8
|
+
replace?<T>(body: T, options?: {
|
|
9
|
+
ifMatchEtag?: string;
|
|
10
|
+
accessCondition?: {
|
|
11
|
+
type: string;
|
|
12
|
+
condition: string;
|
|
13
|
+
};
|
|
14
|
+
}): Promise<unknown>;
|
|
15
|
+
};
|
|
16
|
+
type CosmosLike = {
|
|
17
|
+
item(id: string, partitionKey: string): CosmosItem;
|
|
18
|
+
items: {
|
|
19
|
+
upsert<T>(document: T): Promise<unknown>;
|
|
20
|
+
create?<T>(document: T): Promise<unknown>;
|
|
21
|
+
};
|
|
22
|
+
};
|
|
23
|
+
export declare class CosmosSessionDocumentContainer implements SessionDocumentContainer {
|
|
24
|
+
private readonly container;
|
|
25
|
+
private readonly onClose?;
|
|
26
|
+
constructor(container: CosmosLike, onClose?: (() => void | Promise<void>) | undefined);
|
|
27
|
+
readonly items: {
|
|
28
|
+
upsert: <T>(value: T) => Promise<unknown>;
|
|
29
|
+
};
|
|
30
|
+
compareAndSwap(predicate: SessionWritePredicate, document: SessionDocument): Promise<SessionWriteResult>;
|
|
31
|
+
item(id: string, partitionKey: string): CosmosItem;
|
|
32
|
+
close(): Promise<void>;
|
|
33
|
+
}
|
|
34
|
+
export {};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { Collection, MongoClient } from 'mongodb';
|
|
2
|
+
import { type SessionDocument, type SessionDocumentContainer, type SessionWritePredicate, type SessionWriteResult } from './session-manager.js';
|
|
3
|
+
export declare class MongoDbSessionDocumentContainer implements SessionDocumentContainer {
|
|
4
|
+
private readonly collection;
|
|
5
|
+
private readonly client;
|
|
6
|
+
constructor(collection: Collection<SessionDocument>, client: MongoClient);
|
|
7
|
+
readonly items: {
|
|
8
|
+
upsert: <T>(value: T) => Promise<{}>;
|
|
9
|
+
};
|
|
10
|
+
compareAndSwap(predicate: SessionWritePredicate, document: SessionDocument): Promise<SessionWriteResult>;
|
|
11
|
+
item(id: string, partitionKey: string): {
|
|
12
|
+
read: <T>() => Promise<{
|
|
13
|
+
resource: T;
|
|
14
|
+
}>;
|
|
15
|
+
delete: () => Promise<{}>;
|
|
16
|
+
};
|
|
17
|
+
close(): Promise<void>;
|
|
18
|
+
}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { type StoredMessage } from '@langchain/core/messages';
|
|
2
|
+
import { ConfigManager } from '../config-manager.js';
|
|
3
|
+
import { type GraphState } from '../graph-state.js';
|
|
4
|
+
import { type GraphLlmConfig, type GraphLlmModelMetadata } from '../graph-llm.config.js';
|
|
5
|
+
import { type SessionLogs } from '../session-log.js';
|
|
6
|
+
import { type TokenUsage } from '../token-usage.js';
|
|
7
|
+
export declare const SESSION_DOCUMENT_VERSION = 16;
|
|
8
|
+
export declare const SESSION_BUSY = "SESSION_BUSY";
|
|
9
|
+
export declare const SESSION_CONFLICT = "SESSION_CONFLICT";
|
|
10
|
+
export declare const SESSION_COMPLETED = "SESSION_COMPLETED";
|
|
11
|
+
export type SessionTurnCode = typeof SESSION_BUSY | typeof SESSION_CONFLICT;
|
|
12
|
+
export type SessionTurnLease = {
|
|
13
|
+
owner: string;
|
|
14
|
+
expiresAt: string;
|
|
15
|
+
};
|
|
16
|
+
export type SessionWritePredicate = {
|
|
17
|
+
expectedRevision: number | null;
|
|
18
|
+
requireFreeLease?: boolean;
|
|
19
|
+
requireOwner?: string;
|
|
20
|
+
allowOwner?: string;
|
|
21
|
+
replaceIncompatible?: boolean;
|
|
22
|
+
};
|
|
23
|
+
export type SessionWriteResult = 'ok' | 'conflict';
|
|
24
|
+
export declare class SessionTurnError extends Error {
|
|
25
|
+
readonly code: SessionTurnCode;
|
|
26
|
+
constructor(code: SessionTurnCode, message: string);
|
|
27
|
+
}
|
|
28
|
+
export type BeginTurnResult<State extends GraphState = GraphState> = Readonly<{
|
|
29
|
+
kind: 'leased';
|
|
30
|
+
document: SessionDocument<State>;
|
|
31
|
+
expectedRevision: number;
|
|
32
|
+
}>;
|
|
33
|
+
export type SessionWriteOptions = Readonly<{
|
|
34
|
+
owner?: string;
|
|
35
|
+
expectedRevision?: number;
|
|
36
|
+
}>;
|
|
37
|
+
export type SessionGraphStatus = 'in_progress' | 'completed' | 'error';
|
|
38
|
+
export type SessionGraphDocument<State extends GraphState = GraphState> = {
|
|
39
|
+
id: string;
|
|
40
|
+
schemaVersion: number;
|
|
41
|
+
currentNode?: State['currentNode'];
|
|
42
|
+
config?: State['config'];
|
|
43
|
+
histories: Record<string, StoredMessage[]>;
|
|
44
|
+
nodes?: State['nodes'];
|
|
45
|
+
model: GraphLlmModelMetadata;
|
|
46
|
+
};
|
|
47
|
+
export type SessionDocument<State extends GraphState = GraphState> = {
|
|
48
|
+
version: number;
|
|
49
|
+
id: string;
|
|
50
|
+
revision: number;
|
|
51
|
+
status: SessionGraphStatus;
|
|
52
|
+
tokens: TokenUsage;
|
|
53
|
+
errors: SessionLogs['errors'];
|
|
54
|
+
warnings: SessionLogs['warnings'];
|
|
55
|
+
graph: SessionGraphDocument<State>;
|
|
56
|
+
turn?: SessionTurnLease;
|
|
57
|
+
createdAt: string;
|
|
58
|
+
modifiedAt: string;
|
|
59
|
+
};
|
|
60
|
+
export type SessionGraphMetadata = {
|
|
61
|
+
graphId: string;
|
|
62
|
+
graphSchemaVersion: number;
|
|
63
|
+
llmConfig: GraphLlmConfig;
|
|
64
|
+
};
|
|
65
|
+
export type SessionDocumentContainer = {
|
|
66
|
+
item(id: string, partitionKey: string): {
|
|
67
|
+
read<T>(): Promise<{
|
|
68
|
+
resource?: T;
|
|
69
|
+
}>;
|
|
70
|
+
delete(): Promise<unknown>;
|
|
71
|
+
};
|
|
72
|
+
items: {
|
|
73
|
+
upsert<T>(document: T): Promise<unknown>;
|
|
74
|
+
};
|
|
75
|
+
compareAndSwap(predicate: SessionWritePredicate, document: SessionDocument): Promise<SessionWriteResult>;
|
|
76
|
+
close?(): void | Promise<void>;
|
|
77
|
+
};
|
|
78
|
+
export declare class SessionManager {
|
|
79
|
+
private readonly container;
|
|
80
|
+
private readonly turnLeaseMs;
|
|
81
|
+
constructor(container?: SessionDocumentContainer, turnLeaseMs?: number);
|
|
82
|
+
static fromConfig(config?: ConfigManager): Promise<SessionManager>;
|
|
83
|
+
getSession<State extends GraphState = GraphState>(sessionId: string): Promise<SessionDocument<State> | undefined>;
|
|
84
|
+
readDocument<State extends GraphState = GraphState>(sessionId: string): Promise<SessionDocument<State> | undefined>;
|
|
85
|
+
beginTurn<State extends GraphState = GraphState>(sessionId: string, owner: string, metadata: SessionGraphMetadata): Promise<BeginTurnResult<State>>;
|
|
86
|
+
restoreState<State extends GraphState = GraphState>(sessionId: string, graphId: string): Promise<State | undefined>;
|
|
87
|
+
restoreSessionDocument<State extends GraphState = GraphState>(session: SessionDocument<State>, graphId: string): State | undefined;
|
|
88
|
+
saveState<State extends GraphState>(sessionId: string, state: State, metadata: SessionGraphMetadata, logs?: SessionLogs, options?: SessionWriteOptions): Promise<SessionDocument<State>>;
|
|
89
|
+
appendLogs(sessionId: string, logs: SessionLogs, metadata: SessionGraphMetadata, options?: SessionWriteOptions): Promise<SessionDocument | undefined>;
|
|
90
|
+
endFailedTurn(sessionId: string, owner: string, metadata: SessionGraphMetadata, logs?: SessionLogs, expectedRevision?: number): Promise<void>;
|
|
91
|
+
releaseTurn(sessionId: string, owner: string, expectedRevision?: number): Promise<void>;
|
|
92
|
+
deleteSession(sessionId: string): Promise<void>;
|
|
93
|
+
persistMigratedSession<State extends GraphState>(document: SessionDocument<State>, options?: SessionWriteOptions): Promise<void>;
|
|
94
|
+
close(): Promise<void>;
|
|
95
|
+
private placeholderDocument;
|
|
96
|
+
private commitExpectedRevision;
|
|
97
|
+
private commitPredicate;
|
|
98
|
+
}
|
|
99
|
+
export declare class MemorySessionDocumentContainer implements SessionDocumentContainer {
|
|
100
|
+
private readonly documents;
|
|
101
|
+
get size(): number;
|
|
102
|
+
readonly items: {
|
|
103
|
+
upsert: <T>(value: T) => Promise<{}>;
|
|
104
|
+
};
|
|
105
|
+
compareAndSwap(predicate: SessionWritePredicate, document: SessionDocument): Promise<SessionWriteResult>;
|
|
106
|
+
item(id: string, partitionKey: string): {
|
|
107
|
+
read: <T>() => Promise<{
|
|
108
|
+
resource: T;
|
|
109
|
+
}>;
|
|
110
|
+
delete: () => Promise<{}>;
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
export declare function sessionTurnLeaseMs(value?: string | undefined): number;
|
|
114
|
+
export declare function sessionRevision(document: Pick<SessionDocument, 'revision'> | undefined): number;
|
|
115
|
+
export declare function isLiveSessionTurn(turn: SessionTurnLease | undefined, now?: number): boolean;
|
|
116
|
+
export declare function matchesSessionWritePredicate(current: SessionDocument | undefined, predicate: SessionWritePredicate, now?: number): boolean;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { type SessionDocument, type SessionDocumentContainer, type SessionWritePredicate, type SessionWriteResult } from './session-manager.js';
|
|
2
|
+
export declare class SqliteSessionDocumentContainer implements SessionDocumentContainer {
|
|
3
|
+
private readonly database;
|
|
4
|
+
private closed;
|
|
5
|
+
constructor(databasePath: string);
|
|
6
|
+
readonly items: {
|
|
7
|
+
upsert: <T>(value: T) => Promise<{}>;
|
|
8
|
+
};
|
|
9
|
+
compareAndSwap(predicate: SessionWritePredicate, document: SessionDocument): Promise<SessionWriteResult>;
|
|
10
|
+
item(id: string, partitionKey: string): {
|
|
11
|
+
read: <T>() => Promise<{
|
|
12
|
+
resource: T;
|
|
13
|
+
}>;
|
|
14
|
+
delete: () => Promise<{}>;
|
|
15
|
+
};
|
|
16
|
+
close(): void;
|
|
17
|
+
private readRow;
|
|
18
|
+
private writeRow;
|
|
19
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export type SessionLogEntry = Record<string, unknown> & {
|
|
2
|
+
createdAt: string;
|
|
3
|
+
};
|
|
4
|
+
export type SessionLogs = {
|
|
5
|
+
errors: SessionLogEntry[];
|
|
6
|
+
warnings: SessionLogEntry[];
|
|
7
|
+
};
|
|
8
|
+
export declare function createSessionLogs(): SessionLogs;
|
|
9
|
+
export declare function withSessionLogs<T>(logs: SessionLogs, callback: () => Promise<T>): Promise<T>;
|
|
10
|
+
export declare function SessionLogError(tree: Record<string, unknown>, logs?: SessionLogs | undefined): void;
|
|
11
|
+
export declare function SessionLogWarning(tree: Record<string, unknown>, logs?: SessionLogs | undefined): void;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export type StableIdClass = {
|
|
2
|
+
readonly name: string;
|
|
3
|
+
id(): string;
|
|
4
|
+
};
|
|
5
|
+
export declare function assertStableId(value: string, kind: string): string;
|
|
6
|
+
export declare function stableClassId(Class: StableIdClass, kind: string): string;
|
|
7
|
+
export declare function assertGraphSchemaVersion(value: number): number;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { END, type ExtractStateType, type ExtractUpdateType, START, type StateDefinitionInit } from '@langchain/langgraph';
|
|
2
|
+
import { GRAPH_NODE_CLASS } from './graph-node.js';
|
|
3
|
+
export type RegisteredNode<State, Update> = {
|
|
4
|
+
readonly id: string;
|
|
5
|
+
readonly invoke: (state: State) => Promise<Update>;
|
|
6
|
+
route(state: State): string;
|
|
7
|
+
validateTools?(): void;
|
|
8
|
+
readonly supportsAutomaticOutcomeRouting?: boolean;
|
|
9
|
+
};
|
|
10
|
+
export type GraphNodeClass = {
|
|
11
|
+
readonly name: string;
|
|
12
|
+
id(): string;
|
|
13
|
+
readonly [GRAPH_NODE_CLASS]: true;
|
|
14
|
+
readonly prototype: object;
|
|
15
|
+
};
|
|
16
|
+
export type GraphEndpoint = GraphNodeClass | typeof START | typeof END;
|
|
17
|
+
export type CurrentNodeSelector = GraphNodeClass | string;
|
|
18
|
+
export type CurrentNodeBranchOptions = Readonly<{
|
|
19
|
+
cases: readonly {
|
|
20
|
+
readonly when: CurrentNodeSelector;
|
|
21
|
+
readonly routeTo: GraphEndpoint;
|
|
22
|
+
}[];
|
|
23
|
+
otherwise: GraphEndpoint;
|
|
24
|
+
}>;
|
|
25
|
+
type RouteOf<NodeClass extends GraphNodeClass> = NodeClass['prototype'] extends {
|
|
26
|
+
route(...args: never[]): infer Route;
|
|
27
|
+
} ? Extract<Route, string> : never;
|
|
28
|
+
type BranchDestinations<NodeClass extends GraphNodeClass, Destinations extends Readonly<Record<RouteOf<NodeClass>, GraphEndpoint>>> = Destinations & Record<Exclude<keyof Destinations, RouteOf<NodeClass>>, never>;
|
|
29
|
+
export type GraphNodeFactory<State, Update> = (NodeClass: GraphNodeClass) => RegisteredNode<State, Update>;
|
|
30
|
+
export declare class StateGraphExt<StateDefinition extends StateDefinitionInit> {
|
|
31
|
+
private readonly createGraphNode?;
|
|
32
|
+
private readonly endNode;
|
|
33
|
+
private readonly graph;
|
|
34
|
+
private readonly addedNodeIds;
|
|
35
|
+
private readonly nodeClasses;
|
|
36
|
+
private readonly explicitConditionalNodeIds;
|
|
37
|
+
private readonly nodeInstances;
|
|
38
|
+
private automaticOutcomeRoutingRequested;
|
|
39
|
+
private automaticOutcomeRoutesAdded;
|
|
40
|
+
constructor(state: StateDefinition, createGraphNode?: GraphNodeFactory<ExtractStateType<StateDefinition>, ExtractUpdateType<StateDefinition>> | undefined, endNode?: string);
|
|
41
|
+
addNode(NodeClass: GraphNodeClass): this;
|
|
42
|
+
nodes(...NodeClasses: readonly GraphNodeClass[]): this;
|
|
43
|
+
registerTurnNodes(...NodeClasses: readonly GraphNodeClass[]): this;
|
|
44
|
+
addEdge(source: GraphEndpoint | readonly GraphEndpoint[], target: GraphEndpoint): this;
|
|
45
|
+
branch<NodeClass extends GraphNodeClass, Destinations extends Readonly<Record<RouteOf<NodeClass>, GraphEndpoint>>>(NodeClass: NodeClass, destinations: BranchDestinations<NodeClass, Destinations>): this;
|
|
46
|
+
branchBy(NodeClass: GraphNodeClass, options: CurrentNodeBranchOptions): this;
|
|
47
|
+
configAutoRoute(): this;
|
|
48
|
+
registerTurns(...NodeClasses: readonly GraphNodeClass[]): this;
|
|
49
|
+
compile(): import("@langchain/langgraph").CompiledStateGraph<ExtractStateType<StateDefinition, StateDefinition> extends infer T ? { [K in keyof T]: T[K]; } : never, ExtractUpdateType<StateDefinition, StateDefinition> extends infer T_1 ? { [K_1 in keyof T_1]: T_1[K_1]; } : never, string, StateDefinition extends import("@langchain/langgraph").AnyStateSchema ? StateDefinition : StateDefinition extends StateDefinitionInit ? import("@langchain/langgraph").ToStateDefinition<StateDefinition> : import("@langchain/langgraph").StateDefinition, StateDefinition extends import("@langchain/langgraph").AnyStateSchema ? StateDefinition : StateDefinition extends StateDefinitionInit ? import("@langchain/langgraph").ToStateDefinition<StateDefinition> : import("@langchain/langgraph").StateDefinition, import("@langchain/langgraph").StateDefinition, unknown, unknown, unknown, []>;
|
|
50
|
+
private addConditionalEdge;
|
|
51
|
+
private registerNode;
|
|
52
|
+
private addAutomaticOutcomeRoutes;
|
|
53
|
+
private assertSource;
|
|
54
|
+
private assertTarget;
|
|
55
|
+
private assertAddedNode;
|
|
56
|
+
private currentNodeSelectorName;
|
|
57
|
+
}
|
|
58
|
+
export {};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { GraphNode, type GraphNodeUpdate, type ToolDefinition } from "./graph-node.js";
|
|
2
|
+
import type { GraphState } from "./graph-state.js";
|
|
3
|
+
export declare class TerminateSessionNode<State extends GraphState> extends GraphNode<State> {
|
|
4
|
+
defineTool(): readonly ToolDefinition<{
|
|
5
|
+
message?: string | undefined;
|
|
6
|
+
}>[];
|
|
7
|
+
getPrompt(_state: State): string;
|
|
8
|
+
run(state: State): Promise<GraphNodeUpdate<State>>;
|
|
9
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { ModelCatalog, type GraphLlmConfig, type GraphLlmParameters } from './graph-llm.config.js';
|
|
2
|
+
export type TokenUsage = {
|
|
3
|
+
input_tokens: number;
|
|
4
|
+
output_tokens: number;
|
|
5
|
+
thinking_tokens: number;
|
|
6
|
+
tool_input_tokens: number;
|
|
7
|
+
cached_input_tokens: number;
|
|
8
|
+
total_tokens: number;
|
|
9
|
+
};
|
|
10
|
+
export type ModelResult<T> = {
|
|
11
|
+
value: T;
|
|
12
|
+
usage: TokenUsage;
|
|
13
|
+
execution: ModelExecution;
|
|
14
|
+
};
|
|
15
|
+
export type ModelExecution = {
|
|
16
|
+
model: string;
|
|
17
|
+
family: ReturnType<typeof ModelCatalog.resolveModelDescriptor>['family'];
|
|
18
|
+
parameters: GraphLlmParameters;
|
|
19
|
+
};
|
|
20
|
+
export declare function modelExecution(config: GraphLlmConfig): ModelExecution;
|
|
21
|
+
export declare function emptyTokenUsage(): TokenUsage;
|
|
22
|
+
export declare function addTokenUsage(current?: Partial<TokenUsage>, update?: Partial<TokenUsage>): TokenUsage;
|
|
23
|
+
export declare function normalizeTokenUsage(usage?: Partial<TokenUsage>): TokenUsage;
|
|
24
|
+
export declare function tokenUsageFromMessage(message: unknown): TokenUsage;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export type TurnContext = Readonly<{
|
|
2
|
+
session: string;
|
|
3
|
+
signal?: AbortSignal;
|
|
4
|
+
}>;
|
|
5
|
+
export declare function withTurnContext<T>(context: TurnContext, callback: () => Promise<T>): Promise<T>;
|
|
6
|
+
export declare function currentTurnContext(): TurnContext | undefined;
|
|
7
|
+
export declare function currentTurnSignal(): AbortSignal | undefined;
|