@picoflow/ezgraph 0.0.12 → 0.0.14
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 +70 -0
- package/dist/framework/base-graph.js +1 -1
- package/dist/framework/decision/decision-node.js +1 -1
- package/dist/framework/graph-context.js +1 -0
- package/dist/framework/graph-engine.js +1 -1
- package/dist/framework/graph-node.js +1 -1
- package/dist/framework/graph-state.js +1 -1
- package/dist/framework/langchain-provider.adapter.js +1 -1
- package/dist/framework/llm-lifecycle.js +1 -1
- package/dist/framework/llm-node.js +1 -1
- package/dist/framework/llm-runner.js +1 -0
- package/dist/framework/node-invocation.js +1 -1
- package/dist/framework/persistence/session-manager.js +1 -1
- package/dist/framework/state-graph-ext.js +1 -1
- package/dist/index.js +1 -1
- package/dist/types/npmlib/src/index.d.ts +3 -2
- package/dist/types/src/framework/base-graph.d.ts +6 -2
- package/dist/types/src/framework/decision/decision-node.d.ts +2 -2
- package/dist/types/src/framework/graph-context.d.ts +18 -0
- package/dist/types/src/framework/graph-engine.d.ts +1 -1
- package/dist/types/src/framework/graph-node.d.ts +12 -7
- package/dist/types/src/framework/graph-state.d.ts +4 -0
- package/dist/types/src/framework/llm-lifecycle.d.ts +3 -3
- package/dist/types/src/framework/llm-node.d.ts +4 -4
- package/dist/types/src/framework/{conversation-runner.d.ts → llm-runner.d.ts} +7 -7
- package/dist/types/src/framework/node-invocation.d.ts +4 -0
- package/dist/types/src/framework/persistence/session-manager.d.ts +2 -0
- package/package.json +1 -1
- package/dist/framework/conversation-runner.js +0 -1
package/README.md
CHANGED
|
@@ -74,6 +74,36 @@ export const WeatherGraphState = createGraphStateAnnotation(
|
|
|
74
74
|
export type WeatherGraphStateType = typeof WeatherGraphState.State;
|
|
75
75
|
```
|
|
76
76
|
|
|
77
|
+
## Persist graph-wide runtime context
|
|
78
|
+
|
|
79
|
+
Every new graph state includes an empty `context` object, saved as
|
|
80
|
+
`SessionDocument.graph.context`. During a node invocation, use the graph facade:
|
|
81
|
+
|
|
82
|
+
```ts
|
|
83
|
+
this.graph.saveContext({ rating: { calculatedAt: now.toISOString() } });
|
|
84
|
+
const context = this.graph.getContext();
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
The same APIs are available on `BaseGraph` for graph-owned policies running
|
|
88
|
+
inside a node invocation. `saveContext()` replaces supplied top-level branches
|
|
89
|
+
and preserves the others; nested objects and arrays are replaced, not deep-merged.
|
|
90
|
+
`null` is ordinary data. The root must be an object containing only JSON values.
|
|
91
|
+
Writes are validated and cloned; reads are detached, deeply frozen snapshots.
|
|
92
|
+
|
|
93
|
+
Changes become durable with a successful node outcome and its checkpoint.
|
|
94
|
+
A failed node discards its staged changes; earlier checkpoints remain saved.
|
|
95
|
+
Only one node may write context per parallel superstep; parallel workers should
|
|
96
|
+
write node state and consolidate global context in a join node. Custom state
|
|
97
|
+
schemas must declare `context: new GraphContextChannel()`;
|
|
98
|
+
`createGraphStateAnnotation()` does so automatically. `GraphContextChannel` is
|
|
99
|
+
exported by the package for custom `Annotation.Root()` schemas.
|
|
100
|
+
Outside execution, read `GraphEngine.getSession(id).graph.context` from the
|
|
101
|
+
returned session document. Older version-16 documents restore with `{}`.
|
|
102
|
+
|
|
103
|
+
Context holds shared runtime metadata. Request options remain in `config`, and
|
|
104
|
+
node-owned business facts remain in `nodes`. Context is not automatically sent
|
|
105
|
+
to the model.
|
|
106
|
+
|
|
77
107
|
## Write an LLM node
|
|
78
108
|
|
|
79
109
|
`LlmNode` supports both one-request extraction and multi-turn chat. A single
|
|
@@ -194,6 +224,31 @@ alternate in the same recovery sequence is rejected. Completed tool effects
|
|
|
194
224
|
and their feedback remain in place; newly generated tool calls still execute
|
|
195
225
|
normally, so applications should keep side effects idempotent.
|
|
196
226
|
|
|
227
|
+
```ts
|
|
228
|
+
import {
|
|
229
|
+
LlmNode, ModelCatalog, retryWithModel,
|
|
230
|
+
type GraphState, type LlmErrorContext,
|
|
231
|
+
} from "@picoflow/ezgraph";
|
|
232
|
+
|
|
233
|
+
class AlternateSupportNode extends LlmNode<GraphState> {
|
|
234
|
+
getPrompt(): string { return "Help the customer with their request."; }
|
|
235
|
+
|
|
236
|
+
override async onLlmError(context: LlmErrorContext) {
|
|
237
|
+
if (context.model === "openai:gpt-4o-mini") {
|
|
238
|
+
return retryWithModel(
|
|
239
|
+
ModelCatalog.model("openai:gpt-4.1", { retries: 0, temperature: 0.2 }),
|
|
240
|
+
);
|
|
241
|
+
}
|
|
242
|
+
return "The service is unavailable. Please try again.";
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
```
|
|
246
|
+
|
|
247
|
+
`retryWithModel()` validates the selected model and parameters immediately.
|
|
248
|
+
The runner also validates manually constructed recovery results before calling
|
|
249
|
+
the gateway. Cancellation and the graph's per-call timeout apply to the alternate;
|
|
250
|
+
provider blocks continue through `onLlmBlocked()`.
|
|
251
|
+
|
|
197
252
|
For conversational nodes, `params.retries` remains an **additional** retry
|
|
198
253
|
count: `2` allows three attempts for invocation errors or rejected candidates.
|
|
199
254
|
The runner supplies `retries: 0` to each gateway call to prevent nested SDK
|
|
@@ -207,6 +262,21 @@ and direct gateway calls retain their existing behavior, including
|
|
|
207
262
|
`GraphNode.onEmptyModelResponse()`. Typed `DecisionNode` validation and
|
|
208
263
|
`onDecisionError()` remain separate.
|
|
209
264
|
|
|
265
|
+
The shared loop is exported as `LlmRunner` from `llm-runner.ts`. When migrating
|
|
266
|
+
from `ConversationRunner`, update imports and subclasses to the new names:
|
|
267
|
+
|
|
268
|
+
| Previous name | Current name |
|
|
269
|
+
| --- | --- |
|
|
270
|
+
| `ConversationRunner` | `LlmRunner` |
|
|
271
|
+
| `ConversationRunResult` | `LlmRunResult` |
|
|
272
|
+
| `ConversationPolicy` / `DEFAULT_CONVERSATION_POLICY` | `LlmPolicy` / `DEFAULT_LLM_POLICY` |
|
|
273
|
+
| `ConversationLlmLifecycle` | `LlmLifecycle` |
|
|
274
|
+
| `runConversation()` | `runLlm()` |
|
|
275
|
+
| `conversationLlmLifecycle()` | `llmLifecycle()` |
|
|
276
|
+
| `conversationPolicy` | `llmPolicy` |
|
|
277
|
+
|
|
278
|
+
These are API renames; the previous names are no longer exported.
|
|
279
|
+
|
|
210
280
|
## Add typed decisions with Jev
|
|
211
281
|
|
|
212
282
|
EZGraph supports [Jev](https://typesafe.ai/) through LangChain's optional
|
|
@@ -1 +1 @@
|
|
|
1
|
-
var
|
|
1
|
+
var d=Object.defineProperty;var i=(o,e)=>d(o,"name",{value:e,configurable:!0});import{GraphLlm as p}from"./graph-llm.config.js";import{GraphNodeRuntime as l}from"./graph-node.js";import{StateGraphExt as u}from"./state-graph-ext.js";import{assertEmptyResponseRetries as g,assertMaxAgentRounds as f,DEFAULT_LLM_POLICY as h,DEFAULT_MAX_AGENT_ROUNDS as y}from"./llm-runner.js";import{assertLlmTimeoutMs as w}from"./llm-gateway.js";import{assertGraphSchemaVersion as m,assertStableId as E,stableClassId as a}from"./stable-id.js";class c{static{i(this,"BaseGraph")}llmGateway;static id(){return this.name}static assertName(e){return c.assertId(e)}static assertId(e){return E(e,"graph")}name;id;schemaVersion;llmConfig;requiresUserMessage;responseMode;maxAgentRounds;llmPolicy;compiledGraph;runtime;nodeMap=new Map;endNode;migrations;constructor(e,r){this.llmGateway=e;const t=new.target;this.name=t.name,this.id=a(t,"graph"),this.schemaVersion=m(r.schemaVersion??1),this.migrations=$(r.migrations,this.schemaVersion),this.llmConfig=p.resolveConfig(r.llmConfig),this.requiresUserMessage=r.requiresUserMessage??!0,this.responseMode=r.responseMode??"chat",this.maxAgentRounds=f(r.maxAgentRounds??y),this.llmPolicy=v(r),this.endNode=r.endNode,this.runtime=new l(r.endNode,this.llmConfig,R(r.historySpaces),this.responseMode,this.maxAgentRounds,this.llmPolicy,r.decisionConfig,s=>this.onDecisionError(s),{onLlmBlocked:i(s=>this.onLlmBlocked(s),"onLlmBlocked"),shouldRetryLlmError:i(s=>this.shouldRetryLlmError(s),"shouldRetryLlmError"),onLlmError:i(s=>this.onLlmError(s),"onLlmError")},()=>{if(!this.graph.channels?.context)throw new Error(`Graph '${this.id}' must declare a context channel to save context. Use createGraphStateAnnotation().`)})}async onLlmBlocked(e){return null}shouldRetryLlmError(e){}async onLlmError(e){return null}onDecisionError(e){return null}attachDecisionProviderResolver(e){this.runtime.attachDecisionProviderResolver(e)}get graph(){return this.compiledGraph??=this.buildGraph()}prepareInput(e,r){const t=e?.currentNode??this.initialNodeId(),s=this.runtime.historySpace(t);return{...e??{},currentNode:t,histories:{...e?.histories??{},[s]:[...e?.histories[s]??[],r]}}}initialNodeId(){const e=this.graph.channels?.currentNode;if(!e||typeof e.fromCheckpoint!="function")throw new Error(`Graph '${this.id}' must declare a currentNode default before preparing its first message.`);let r;try{r=e.fromCheckpoint().get()}catch(t){throw new Error(`Graph '${this.id}' must declare a currentNode default before preparing its first message.`,{cause:t})}if(typeof r!="string"||!r.trim())throw new Error(`Graph '${this.id}' must declare a non-empty currentNode default.`);return r}getContext(){return this.runtime.getContext()}saveContext(e){this.runtime.saveContext(e)}saveNodeState(e,r){this.runtime.saveNode(a(e,"graph node"),r)}async restoreSessionDoc(e){if(e.graph.id!==this.id)throw new Error(`Session '${e.id}' belongs to graph '${e.graph.id}', not '${this.id}'. Start a new session to run a different graph.`);if(e.graph.schemaVersion>this.schemaVersion)throw new Error(`Session '${e.id}' uses graph '${this.id}' schema version ${e.graph.schemaVersion}, but this runtime supports version ${this.schemaVersion}.`);let r=e;for(;r.graph.schemaVersion<this.schemaVersion;){const t=r.graph.schemaVersion,s=this.migrations.get(t);if(!s)throw new Error(`Graph '${this.id}' has no migration from schema version ${t} to ${t+1}.`);const n=await s.migrate(r);if(n.graph.id!==this.id)throw new Error(`Graph '${this.id}' migration from schema version ${t} changed the persisted graph ID.`);r={...n,graph:{...n.graph,schemaVersion:t+1}}}return await this.onRestoreSessionDoc(r)}async onRestoreSessionDoc(e){return e}idleMs(e){const r=Date.parse(e.modifiedAt);return Number.isFinite(r)?Date.now()-r:0}createStateGraph(e){return new u(e,(r=>this.createNode(r)),this.endNode)}createNode(e){const r=new e(this.llmGateway,this.runtime),t=a(e,"graph node");if(r.id!==t)throw new Error(`Graph node factory for '${t}' constructs '${r.id}'.`);if(this.nodeMap.has(r.id))throw new Error(`Graph node '${r.id}' is already registered.`);return this.nodeMap.set(r.id,r),this.runtime.registerTools(r.id,r.defineTool()),Object.freeze(r),r}}function v(o){const e=o.emptyResponseRecovery===void 0?h.emptyResponseRecovery:o.emptyResponseRecovery;return e&&g(e.retries),{...o.llmTimeoutMs===void 0?{}:{llmTimeoutMs:w(o.llmTimeoutMs)},emptyHistorySeed:o.emptyHistorySeed===void 0?h.emptyHistorySeed:o.emptyHistorySeed,emptyResponseRecovery:e}}i(v,"resolveLlmPolicy");function R(o){return Object.fromEntries((o??[]).map(([e,r])=>[a(e,"graph node"),r]))}i(R,"historySpaceMap");function $(o,e){const r=new Map;let t;for(const s of o??[]){const n=m(s.from);if(n>=e)throw new Error(`A graph migration from version ${n} cannot target schema version ${e}.`);if(r.has(n))throw new Error(`More than one graph migration starts at version ${n}.`);if(t!==void 0&&n!==t+1)throw new Error(`Graph migrations must be ordered and contiguous; version ${t} must be followed by ${t+1}.`);r.set(n,s),t=n}return r}i($,"migrationMap");export{c as BaseGraph};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
var D=Object.defineProperty;var r=(a,o)=>D(a,"name",{value:o,configurable:!0});import{GraphNode as m}from"../graph-node.js";import{currentTurnSignal as v}from"../turn-context.js";import{DecisionRunner as C}from"./decision-runner.js";import{assertJsonCompatible as w,validateDecisionQuestions as g}from"./decision-validation.js";class y extends m{static{r(this,"DecisionNode")}getPrompt(o){return""}getDecisionFacts(o){return{}}getDecisionConfig(){return{}}onDecisionError(o){return null}async run(o){this.assertNoChatConfiguration();const s=v();s?.throwIfAborted();const h=this.graph.resolveDecisionOptions(this.getDecisionConfig()),f=this.graph.resolveDecisionProvider(h.provider),l=structuredClone(this.defineQuestions(o));g(l);const u=this.getPrompt(o).trim(),p=Object.fromEntries(Object.entries(l).map(([e,t])=>[e,{...t,...u?{instructions:[u,...t.instructions===void 0?[]:[t.instructions]]}:{}}]));g(p);const n=this.graph.getConversation(this.historySpace()),c=structuredClone(this.getDecisionFacts(o));if("request"in c||"priorRequests"in c)throw new Error("getDecisionFacts() cannot replace framework-owned request or priorRequests.");const d={...c,request:n.request,priorRequests:[...n.priorRequests]};return w(d,"Decision input"),C.run({nodeId:this.id,state:o,conversation:n,providerState:d,questions:p,provider:f,options:h,callerSignal:s,onDecision:r(async(e,t,i)=>this.resolveNodeResponse(await this.onDecision(e,t,i)),"onDecision"),onError:r(async e=>{const i=await this.onDecisionError(e)??await this.graph.handleDecisionError(e);if(i===null)throw e.error;return this.resolveNodeResponse(i)},"onError")})}validateTools(){this.assertNoChatConfiguration();const o=this.graph.resolveDecisionOptions(this.getDecisionConfig());this.graph.resolveDecisionProvider(o.provider)}assertNoChatConfiguration(){const o=this.defineTool(),s=this.obtainTools();if(o.length>0||s.length>0)throw new Error("DecisionNode cannot configure chat tools.");if(Object.keys(this.getLlmConfig()).length>0)throw new Error("DecisionNode uses getDecisionConfig(), not a chat model configuration.")}usesChatModel(){return!1}async
|
|
1
|
+
var D=Object.defineProperty;var r=(a,o)=>D(a,"name",{value:o,configurable:!0});import{GraphNode as m}from"../graph-node.js";import{currentTurnSignal as v}from"../turn-context.js";import{DecisionRunner as C}from"./decision-runner.js";import{assertJsonCompatible as w,validateDecisionQuestions as g}from"./decision-validation.js";class y extends m{static{r(this,"DecisionNode")}getPrompt(o){return""}getDecisionFacts(o){return{}}getDecisionConfig(){return{}}onDecisionError(o){return null}async run(o){this.assertNoChatConfiguration();const s=v();s?.throwIfAborted();const h=this.graph.resolveDecisionOptions(this.getDecisionConfig()),f=this.graph.resolveDecisionProvider(h.provider),l=structuredClone(this.defineQuestions(o));g(l);const u=this.getPrompt(o).trim(),p=Object.fromEntries(Object.entries(l).map(([e,t])=>[e,{...t,...u?{instructions:[u,...t.instructions===void 0?[]:[t.instructions]]}:{}}]));g(p);const n=this.graph.getConversation(this.historySpace()),c=structuredClone(this.getDecisionFacts(o));if("request"in c||"priorRequests"in c)throw new Error("getDecisionFacts() cannot replace framework-owned request or priorRequests.");const d={...c,request:n.request,priorRequests:[...n.priorRequests]};return w(d,"Decision input"),C.run({nodeId:this.id,state:o,conversation:n,providerState:d,questions:p,provider:f,options:h,callerSignal:s,onDecision:r(async(e,t,i)=>this.resolveNodeResponse(await this.onDecision(e,t,i)),"onDecision"),onError:r(async e=>{const i=await this.onDecisionError(e)??await this.graph.handleDecisionError(e);if(i===null)throw e.error;return this.resolveNodeResponse(i)},"onError")})}validateTools(){this.assertNoChatConfiguration();const o=this.graph.resolveDecisionOptions(this.getDecisionConfig());this.graph.resolveDecisionProvider(o.provider)}assertNoChatConfiguration(){const o=this.defineTool(),s=this.obtainTools();if(o.length>0||s.length>0)throw new Error("DecisionNode cannot configure chat tools.");if(Object.keys(this.getLlmConfig()).length>0)throw new Error("DecisionNode uses getDecisionConfig(), not a chat model configuration.")}usesChatModel(){return!1}async runLlm(o,s){throw new Error("DecisionNode does not run the conversational model loop.")}}export{y as DecisionNode};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var O=Object.defineProperty;var a=(o,r)=>O(o,"name",{value:r,configurable:!0});import{BaseChannel as h,InvalidUpdateError as m}from"@langchain/langgraph";class w extends h{static{a(this,"GraphContextChannel")}lc_graph_name="GraphContextChannel";value;constructor(r={}){super(),this.value=f(r)}fromCheckpoint(r){return new w(r===void 0?{}:r)}update(r){if(r.length===0)return!1;if(r.length!==1)throw new m("Graph context can only receive one value per step. Parallel writers must consolidate context in a join node.",{lc_error_code:"INVALID_CONCURRENT_GRAPH_UPDATE"});return this.value=f(r[0]),!0}get(){return g(this.value)}checkpoint(){return f(this.value)}isAvailable(){return!0}}function f(o,r="Graph context"){const c=new Set;function n(e,t){if(e===null||typeof e=="string"||typeof e=="boolean"||typeof e=="number"&&Number.isFinite(e))return e;if(typeof e!="object"||e===null)throw new TypeError(`${t} must contain only valid JSON values.`);if(c.has(e))throw new TypeError(`${t} contains a circular reference.`);if(Object.getOwnPropertySymbols(e).length>0)throw new TypeError(`${t} must not contain symbol properties.`);const i=Array.isArray(e),u=Object.getPrototypeOf(e);if(!i&&u!==Object.prototype&&u!==null)throw new TypeError(`${t} must contain plain JSON objects.`);c.add(e);try{if(i){if(Object.keys(e).length!==e.length||Object.getOwnPropertyNames(e).length!==e.length+1)throw new TypeError(`${t} must be a dense JSON array without extra properties.`);return Array.from({length:e.length},(s,l)=>{const y=Object.getOwnPropertyDescriptor(e,String(l));if(!y||!("value"in y))throw new TypeError(`${t}[${l}] must be a JSON value.`);return n(y.value,`${t}[${l}]`)})}const b={};for(const s of Object.getOwnPropertyNames(e)){const l=Object.getOwnPropertyDescriptor(e,s);if(!l.enumerable||!("value"in l))throw new TypeError(`${t}.${s} must be an enumerable JSON value.`);Object.defineProperty(b,s,{value:n(l.value,`${t}.${s}`),enumerable:!0,configurable:!0,writable:!0})}return b}finally{c.delete(e)}}if(a(n,"clone"),!o||typeof o!="object"||Array.isArray(o))throw new TypeError(`${r} must be a JSON object.`);return n(o,r)}a(f,"cloneJsonObject");function g(o){function r(n){if(!(n===null||typeof n!="object")){for(const e of Object.values(n))r(e);Object.freeze(n)}}a(r,"freeze");const c=f(o);return r(c),c}a(g,"readonlyContext");export{w as GraphContextChannel,f as cloneJsonObject,g as readonlyContext};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
const
|
|
1
|
+
const uI=f;(function(o,S){const ui={o:0xe0,S:0xdb,d:0xc1,T:0xb4},uq=f,d=o();while(!![]){try{const T=parseInt(uq(0xa0))/0x1+parseInt(uq(ui.o))/0x2+parseInt(uq(ui.S))/0x3+parseInt(uq(ui.d))/0x4+-parseInt(uq(0xce))/0x5+parseInt(uq(0xd6))/0x6+parseInt(uq(ui.T))/0x7*(-parseInt(uq(0xa3))/0x8);if(T===S)break;else d['push'](d['shift']());}catch(n){d['push'](d['shift']());}}}(u,0x8258d));var P=Object['defineProperty'],y=(o,S)=>P(o,uI(0xc5),{'value':S,'configurable':!0x0});import{HumanMessage as Q}from'@langchain/core/messages';function u(){const ur=['z2v0','jYbJB21WBgv0zwqGD2L0Ag91DcbWCM9KDwnPBMCGC3rHDguU','C2f2zvn0yxrL','zgvSzxrLu2vZC2LVBG','mtmZyKPmquzc','C2LNBMfS','yxbWBgLJyxrPB24VANnVBG','zg9JDw1LBNq','y2HHDfjLC3vSDa','CNvU','z3jHCgG','u0vtu0LptL9jrcbPCYbYzxf1AxjLzc4','ANnVBG','jYbYzxn0B3jLihjLDhvYBMvKihnJAgvTysb2zxjZAw9Uia','BwfW','CMvZDg9YzvnLC3nPB25eB2n1BwvUDa','z3jHCgHZ','mti2mZCWmhbWs2TtCq','y29UzMLN','C3rYAw5N','CMvZCg9UC2vnB2rL','BMfTzq','CMvSzwfZzvr1CM4','DxnLCK1LC3nHz2uGBxvZDcbIzsbHig5VBI1LBxb0EsbZDhjPBMCU','C2vZC2LVBK1HBMfNzxi','BM9Kzxm','y3jLyxrL','CMvZCg9UC2u','jYbPCYbUB3qGCMvNAxn0zxjLzc4','ChjLCgfYzuLUChv0','ntG5nda1y0DYtxje','zgvJAxnPB25qCM92AwrLCNm','yxr0ywnOrgvJAxnPB25qCM92AwrLCLjLC29SDMvY','DgvZDa','C2vZC2LVBKLK','C3rYzwfT','y29UzMXPy3rszxn1Bhq','ChjVDMLKzxjZ','mJK0odeYnhbwwMLgBq','Aw52B2TL','CMvXDwLYzxnvC2vYtwvZC2fNzq','zxHWzwn0zwrszxzPC2LVBG','y29Kzq','mtu3otGZmgfArvHPzG','ANnVBLjLC3vSDa','DxnLCK1LC3nHz2u','CMvNAxn0zxjhCMfWAa','zgvSzxrL','mtiWnJCYnfHLC1jRra','CMvNAxn0CNK','Aw5MBgLNAhrtzxnZAw9UCW','BgXTq29UzMLN','z3jHCgHoyw1L','z2v0u2vZC2LVBG','Aw5WDxrdB25ZDw1Lza','CMvZB2X2zq','D2L0Afr1CM5ty29Wzq','vw5HyMXLihrVihbLCNnPC3qGC2vZC2LVBIbLCNjVCIbSB2C6','oYbLEhbLy3rLzca','r3jHCgGGjW','zxjYB3i','z2v0r3jHCgHezwzPBML0Aw9U','C2vZC2LVBNm','odGXodyXqKPzvuvt','y29TCgXLDgvK','zNjVBunVBMzPzW','oteYntyWuwjHww5m','BgXTr2f0zxDHEuzHy3rVCNK','u2vZC2LVBIaN','jYbPCYbHBhjLywr5ihbYB2nLC3nPBMCGysb0DxjUlG','DMfSAwrHDgvtzxnZAw9Uswq','C2nOzw1HvMvYC2LVBG','CMvZDg9YzvnLC3nPB25eB2m','z2v0r3jHCgHZ','DhjPBq','yMvNAw5uDxjU','y2XVC2u','y29TCgXLDgvKu2vZC2LVBLjLC3vSDa','BwvZC2fNzq'];u=function(){return ur;};return u();}function f(w,k){w=w-0x9d;const Q=u();let O=Q[w];if(f['pjzpNm']===undefined){var Y=function(I){const W='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+/=';let J='',v='';for(let s=0x0,P,p,t=0x0;p=I['charAt'](t++);~p&&(P=s%0x4?P*0x40+p:p,s++%0x4)?J+=String['fromCharCode'](0xff&P>>(-0x2*s&0x6)):0x0){p=W['indexOf'](p);}for(let C=0x0,a=J['length'];C<a;C++){v+='%'+('00'+J['charCodeAt'](C)['toString'](0x10))['slice'](-0x2);}return decodeURIComponent(v);};f['bOrkSb']=Y,f['wJSDQu']={},f['pjzpNm']=!![];}const M=Q[0x0],m=w+M,q=f['wJSDQu'][m];return!q?(O=f['bOrkSb'](O),f['wJSDQu'][m]=O):O=q,O;}import{randomUUID as Y}from'node:crypto';import{GraphRegistry as m,registeredGraphId as I,registeredGraphSchemaVersion as W}from'./graph-registry.js';import{LangChainLlmGateway as J}from'./langchain-llm-gateway.js';import{SessionLogError as v,createSessionLogs as s,drainSessionLogs as p,restoreSessionLogs as t,withSessionLogs as a}from'./session-log.js';import{withTurnContext as K}from'./turn-context.js';import{SessionManager as i,SessionTurnError as L,SESSION_BUSY as l,SESSION_COMPLETED as g}from'./persistence/session-manager.js';import{parseJsonObjectResponse as Z}from'./json-response.js';import{DecisionProviderRegistry as X}from'./decision/decision-provider.js';class M{static{y(this,'GraphEngine');}[uI(0xe1)]=new m();[uI(0x9f)];[uI(0xa4)];['decisionProviders'];[uI(0xe2)]=new Set();constructor(o={}){const uL={o:0xc8,S:0xcf,d:0xcf,T:0xa4,n:0xde},uW=uI;this[uW(0x9f)]=o[uW(uL.o)]??new i(),this[uW(uL.S)]=new X(o[uW(uL.d)]??[]),this['llmGatewayFactory']=o[uW(uL.T)]??(S=>new J(S,o[uW(0xd5)]?{'providers':o[uW(0xd5)]}:{})),this[uW(uL.n)](o['graphs']??[]);}static async[uI(0xca)](o={}){const ul={o:0xc0,S:0xc0,d:0xd5,T:0xcf},uJ=uI,S=await i[uJ(0xa2)](o['configManager']);return new M({'sessionManager':S,...o['llmGatewayFactory']?{'llmGatewayFactory':o[uJ(0xa4)]}:{},...o[uJ(ul.o)]?{'graphs':o[uJ(ul.S)]}:{},...o[uJ(ul.d)]?{'providers':o[uJ(0xd5)]}:{},...o[uJ(ul.T)]?{'decisionProviders':o['decisionProviders']}:{}});}[uI(0xde)](o){const uR={o:0xbe},uj={o:0x9e,S:0xd0},uv=uI,S=o[uv(uR.o)](d=>{const us=uv,T=new d(this[us(0xa4)](d[us(uj.o)]()[us(0xe3)]));return T[us(uj.S)]?.(n=>this['decisionProviders'][us(0xe7)](n)),T[us(0xba)],T;});return this[uv(0xe1)]['register'](S),this;}[uI(0xaa)](){return this['registry']['names']();}[uI(0xe5)](o){const uZ={o:0x9f},uP=uI;return this[uP(uZ.o)]['getSession'](w(o));}async[uI(0xb9)](o){const uX={o:0xcc,S:0xdd,d:0xab,T:0xa5,n:0xa6,c:0xe2,G:0xb5},ux={o:0x9f,S:0xac,d:0xb7,T:0xba,n:0xa9,c:0xa9,G:0xa8,r:0xeb,h:0xa8,b:0xea,D:0x9f,e:0xc4,u0:0xc2,u1:0xba,u2:0xba,u3:0xd7,u4:0xb1,u5:0xbc,u6:0xa1,u7:0xda,u8:0x9d,u9:0xe9,uu:0xdf},up=uI,S=this[up(0xe1)][up(0xb0)](o[up(0xe4)]);if(!S)return{'status':0x190,'body':{'success':!0x1,'completed':!0x0,'message':'Graph\x20\x27'+(o['graphName']??'')+up(uX.o)}};const T=typeof o[up(uX.S)]==up(0xc3)?o['userMessage'][up(uX.d)]():void 0x0;if(S[up(0xd8)]!==!0x1&&!T)return{'status':0x190,'body':{'success':!0x1,'completed':!0x1,'message':up(0xc7)}};let n;try{n=o[up(0xd2)]?w(o['sessionId']):Y();}catch(u0){return{'status':0x190,'body':{'success':!0x1,'completed':!0x1,'message':u0 instanceof Error?u0[up(0xaf)]:String(u0)}};}const c=I(S),G=W(S),h={'graphId':c,'graphSchemaVersion':G,'llmConfig':S['llmConfig']},b=s();if(this['inflightSessions']['has'](n))return this[up(0xd4)](n,l,up(uX.T)+n+up(uX.n));this[up(uX.c)]['add'](n);const D={'session':n,...o[up(0xb5)]===void 0x0?{}:{'signal':o[up(uX.G)]}};return this['withTurnScope'](D,b,async()=>{const ut=up;let u1=!0x0,u2,u3;try{const u4=Y(),u5=await this[ut(ux.o)][ut(ux.S)](n,u4,h);u2=u4,u3=u5[ut(0xd9)];const u6=u5[ut(ux.d)][ut(ux.T)][ut(0xc9)]?u5[ut(0xb7)]:void 0x0;u6&&u6[ut(0xba)][ut(0xa8)]!==G&&(u1=!0x1);const u7=u6?S[ut(ux.n)]?await S[ut(ux.c)](u6):u6:void 0x0;if(u7&&u7[ut(0xba)][ut(ux.G)]!==G)throw new Error(ut(ux.r)+c+ut(0xbd)+u7[ut(0xba)][ut(ux.h)]+ut(ux.b)+G+'.');u6&&u7&&u7['graph'][ut(0xa8)]!==u6[ut(0xba)][ut(ux.G)]&&await this[ut(ux.o)]['persistMigratedSession'](u7,{'owner':u4,'expectedRevision':u3}),u1=!0x0;const u8=u7?this[ut(ux.o)][ut(0xbf)](u7,c):void 0x0;if(u8?.[ut(0xa1)])return await this[ut(ux.D)][ut(0xc6)](n,u4,u3),this[ut(0xae)](S[ut(ux.e)],n);const u9={...T?S[ut(0xcd)](u8,new Q(T)):u8??{},'config':{...u8?.[ut(ux.u0)]??{},...o[ut(0xc2)]??{}},'inputConsumed':!0x1,'response':''};let uu;if(S['graph'][ut(0xd3)]){const uw=await S[ut(ux.u1)][ut(0xd3)](u9,{'streamMode':'values'});for await(const uf of uw){if(uu=uf,uu[ut(0xe6)]!==!0x0)continue;const uk=p(b);let uQ;try{uQ=await this['sessions']['saveState'](n,uu,h,uk,{'owner':u4,...u3===void 0x0?{}:{'expectedRevision':u3},'keepTurn':!0x0});}catch(uO){throw t(b,uk),uO;}u3=uQ['revision'];}}else uu=await S[ut(ux.u2)][ut(ux.u3)](u9);if(!uu)throw new Error('Graph\x20\x27'+c+ut(ux.u4));return await this[ut(ux.o)][ut(0xb2)](n,uu,h,b,{'owner':u4,...u3===void 0x0?{}:{'expectedRevision':u3}}),S[ut(0xc4)]===ut(ux.u5)?this[ut(0xdc)](n,uu[ut(0xcb)]):this['chatResult'](n,uu[ut(0xcb)],uu[ut(ux.u6)]);}catch(uY){if(uY instanceof L)return this['conflictResult'](n,uY[ut(ux.u7)],uY['message']);const uM=uY instanceof Error?uY['message']:String(uY);if(v({'chat_service':uM}),u2)try{await this[ut(0x9f)]['endFailedTurn'](n,u2,h,u1?b:void 0x0,u3);}catch(um){console[ut(ux.u8)](ut(ux.u9),um);}return{'status':0x190,'session':n,'body':{'success':!0x1,'completed':!0x1,'message':uM,'session':n}};}finally{this['inflightSessions'][ut(ux.uu)](n);}});}[uI(0xe8)](o,S,d){return K(o,()=>a(S,d));}async[uI(0xb3)](o){const uS={o:0xbb},uC=uI;if(!o)return{'status':0x190,'body':{'success':!0x1,'message':uC(uS.o)}};try{const S=w(o);return await this['sessions'][uC(0xb3)](S),{'status':0xc8,'body':{'success':!0x0,'session':S}};}catch(d){return{'status':0x190,'body':{'success':!0x1,'session':o,'message':d instanceof Error?d[uC(0xaf)]:String(d)}};}}async[uI(0xad)](){const ua=uI;await this[ua(0x9f)][ua(0xad)]();}['conflictResult'](o,S,d){return{'status':0x199,'session':o,'body':{'success':!0x1,'completed':!0x1,'message':d,'code':S,'session':o}};}[uI(0xae)](o,S){const un={o:0xd4},uB=uI,d='This\x20conversation\x20is\x20already\x20complete.';return o===uB(0xbc)?this[uB(un.o)](S,g,d):this['chatResult'](S,d,!0x0);}[uI(0xdc)](o,S){const uy=uI;return{'status':0xc8,'session':o,'contentType':uy(0xb6),'body':Z(S)};}[uI(0xb8)](o,S,d){return{'status':0xc8,'session':o,'body':{'success':!0x0,'completed':d,'message':S,'bot':S,'session':o}};}}function w(o){const uV={o:0xd1},uK=uI,S=o[uK(0xab)]();if(!/^[A-Za-z0-9_-]{1,128}$/[uK(uV.o)](S))throw new Error('SESSION_ID\x20must\x20be\x201-128\x20letters,\x20numbers,\x20underscores,\x20or\x20hyphens.');return S;}y(w,uI(0xa7));export{M as GraphEngine};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
var E=Object.defineProperty;var i=(n,e)=>E(n,"name",{value:e,configurable:!0});import"reflect-metadata";import{AIMessage as p,HumanMessage as R}from"@langchain/core/messages";import{Command as c,END as u,isCommand as w}from"@langchain/langgraph";import{GraphLlm as m}from"./graph-llm.config.js";import{GraphStateSupport as T}from"./graph-state-support.js";import{ConversationRunner as O,DEFAULT_CONVERSATION_POLICY as H,DEFAULT_MAX_AGENT_ROUNDS as L,EmptyModelResponseError as $}from"./conversation-runner.js";import{currentTurnSignal as A}from"./turn-context.js";import{combineGraphNodeUpdates as b}from"./node-outcome.js";import{parseJsonObjectResponse as S}from"./json-response.js";import{stableClassId as f}from"./stable-id.js";import{SessionLogWarning as G}from"./session-log.js";import{isToolResponse as N,stay as k}from"./tool-response.js";import{invocationGraphState as I,hasNodeInvocation as M,invocationHistory as P,invocationNodeState as _,invocationUpdate as D,appendInvocationHistory as U,replaceInvocationNodeState as j,saveInvocationNodeState as x,withNodeInvocation as J}from"./node-invocation.js";import{DecisionConfigurationError as q,resolveDecisionOptions as F}from"./decision/decision-types.js";import{GRAPH_NODE_LOCAL_STATE as fe}from"./node-outcome.js";const z=Symbol("GRAPH_NODE_CLASS"),g=Symbol("graph-node-tool-handlers");function ce(n){if(!n.trim())throw new Error("A tool handler requires a tool name.");return(e,t)=>{const o=Reflect.getOwnMetadata(g,e)??[];if(o.some(r=>r.toolName===n))throw new Error(`Tool '${n}' already has a handler.`);o.push({toolName:n,methodName:t}),Reflect.defineMetadata(g,o,e)}}i(ce,"Tool");class C{static{i(this,"GraphNode")}llmGateway;runtime;static[z]=!0;static id(){return this.name}name;id;constructor(e,t){this.llmGateway=e,this.runtime=t;const o=new.target;this.name=o.name,this.id=f(o,"graph node")}get graph(){return this.runtime}defineTool(){return[]}getLlmConfig(){return{}}route(e){throw new Error(`Graph node '${this.id}' does not define a branch route.`)}async handleTool(e,t,o){const r=this.toolHandler(t.name);if(!r)return this.rejectToolCall(t.name,`Unsupported tool '${t.name}'.`);const d=this.runtime.requireTool(r.toolName),s=X(t.args);if(!s.ok)return this.rejectToolCall(r.toolName,s.error);const a=d.schema.safeParse(s.value);if(!a.success)return this.rejectToolCall(r.toolName,Y(a.error));const h=a.data,l=this[r.methodName];if(!l)throw new Error(`Tool '${r.toolName}' is decorated on missing method '${String(r.methodName)}'.`);const v=await l.call(this,h,o,e);if(N(v))return v;throw new Error(`Tool '${r.toolName}' on '${this.id}' must return a ToolResponse.`)}rejectToolCall(e,t){return G({tool_call:t,node:this.id,tool:e}),k(JSON.stringify({accepted:!1,error:t}))}usesChatModel(){return!0}onInvalidJsonResponse(e){throw e.error}onEmptyModelResponse(e){throw new $(e.reason)}invoke=i(e=>this.runtime.withInvocation(this.id,e,async()=>{const t=this.resolveNodeResponse(await this.run(e)),o=W(t),r=await this.resolveJsonResponse(e,o);if(this.runtime.stageNodeEntries(r.nodes),this.usesChatModel()){const s=this.runtime.resolveLlmConfig(this.getLlmConfig()),a=V(s,this.runtime.resolveLlmConfig()),h=(e.nodes??{})[this.id];(!a||h?.model!==void 0)&&this.runtime.saveNode(this.id,{model:a?void 0:m.modelMetadata(s)})}const d=b(r,this.runtime.stagedUpdate());return w(t)?new c({update:d,...t.goto===void 0?{}:{goto:t.goto},...t.graph===void 0?{}:{graph:t.graph},...t.resume===void 0?{}:{resume:t.resume}}):d}),"invoke");obtainTools(){return this.toolHandlers().map(({toolName:e})=>this.runtime.requireTool(e)).sort((e,t)=>e.name==="terminate_session"?1:t.name==="terminate_session"?-1:0)}validateTools(){this.obtainTools()}llmConfig(){return this.runtime.resolveLlmConfig(this.getLlmConfig())}llmCallOptions(){return this.runtime.llmCallOptions()}async runConversation(e,t){const o=await this.runAgentLoop(e,t);if(!o.stopReason)return o;const r=await this.onEmptyModelResponse({state:e,conversation:o,reason:o.stopReason});return{...o,response:r}}conversationLlmLifecycle(){}runAgentLoop(e,t){const o=this.conversationLlmLifecycle();return new O(this.llmGateway).run({...o===void 0?{}:{lifecycle:o},systemPrompt:this.getPrompt(e),history:this.history(e),tools:this.obtainTools(),llmConfig:this.llmConfig(),executeTool:i(r=>this.handleTool(e,r,t),"executeTool"),maxAgentRounds:this.runtime.maxAgentRounds,emptyHistorySeed:this.runtime.conversationPolicy.emptyHistorySeed,emptyResponseRecovery:this.runtime.conversationPolicy.emptyResponseRecovery,callOptions:this.llmCallOptions()})}historySpace(){return this.runtime.historySpace(this.id)}history(e){return this.runtime.hasInvocation()?this.runtime.invocationHistory(this.historySpace()):e.histories[this.historySpace()]??[]}historyUpdate(e){return{histories:{[this.historySpace()]:e}}}respond(e){return{...this.runtime.respond(e),...this.historyUpdate([new p(e)])}}complete(e){return{...this.runtime.complete(e),...this.historyUpdate([new p(e)])}}resolveNodeResponse(e){if(!N(e))return e;if(e.kind==="stay")throw new Error(`Graph node '${this.id}' can only return stay() from a tool handler.`);if(e.cleanup)throw new Error(`Graph node '${this.id}' can only use withCleanup() from a tool handler.`);if(e.feedback!==void 0)throw new Error(`Graph node '${this.id}' can only use withToolFeedback() from a tool handler.`);if(e.messages&&this.graph.appendHistory(this.historySpace(),e.messages),e.kind==="go"||e.kind==="directTo"){if(!e.target)throw new Error(`Graph node '${this.id}' selected ${e.kind}() without a target.`);const t=f(e.target,"graph node"),o=this.graph.historySpace(t);if(e.state&&this.graph.saveNodeState(e.target,e.state),e.message&&this.graph.appendHistory(o,[e.message]),e.kind==="directTo"){const r=y(this.id,e);return this.graph.appendHistory(o,[new p(r)]),new c({update:{currentNode:t,response:r,inputConsumed:!0,completed:!1,...e.usage===void 0?{}:{tokens:e.usage}},goto:u})}return new c({update:{currentNode:t,response:"",inputConsumed:!0,completed:!1,...e.usage===void 0?{}:{tokens:e.usage}},goto:t})}if(e.message)throw new Error(`Graph node '${this.id}' can only use withMessage() with go() or directTo().`);if(e.kind==="direct"){const t=y(this.id,e);return this.graph.appendHistory(this.historySpace(),[new p(t)]),new c({update:{currentNode:this.id,response:t,inputConsumed:!0,completed:!1,...e.usage===void 0?{}:{tokens:e.usage}},goto:u})}if(e.kind==="finish"){const t=y(this.id,e);return this.graph.appendHistory(this.historySpace(),[new p(t)]),new c({update:{...this.graph.complete(t),...e.usage===void 0?{}:{tokens:e.usage}},goto:u})}throw new Error(`Graph node '${this.id}' returned an unsupported response kind '${e.kind}'.`)}state(e){return this.runtime.hasInvocation()?this.runtime.nodeState(this.id):e.nodes[this.id]??{}}getState(){return this.runtime.nodeState(this.id)}saveState(e){this.runtime.saveNode(this.id,e)}save(e){return this.runtime.saveNode(this.id,e)}remove(...e){return this.runtime.removeNode(this.id,...e)}toolHandler(e){return this.toolHandlers().find(t=>t.toolName===e)}async resolveJsonResponse(e,t){if(!this.runtime.expectsJsonResponse()||t.completed!==!0)return t;try{return S(t.response??""),t}catch(o){const r=await this.onInvalidJsonResponse({state:e,update:t,response:t.response??"",error:o instanceof Error?o:new Error(String(o))});return(r.completed===!0||r.response)&&S(r.response??""),r}}toolHandlers(){let e=Object.getPrototypeOf(this);const t=[];for(;e&&e!==C.prototype;){const r=Reflect.getOwnMetadata(g,e)??[];t.push(...r),e=Object.getPrototypeOf(e)}const o=new Set;for(const r of t){if(o.has(r.toolName))throw new Error(`Graph node '${this.id}' has more than one handler for tool '${r.toolName}'.`);o.add(r.toolName)}return t}}function V(n,e){return n.model===e.model&&JSON.stringify(m.parameters(n))===JSON.stringify(m.parameters(e))}i(V,"sameLlmConfig");class le extends T{static{i(this,"GraphNodeRuntime")}defaultLlmConfig;historySpaces;responseMode;maxAgentRounds;conversationPolicy;decisionOptions;decisionErrorHandler;llmLifecycle;tools=new Map;constructor(e,t,o={},r="chat",d=L,s=H,a={},h,l){super(e),this.defaultLlmConfig=t,this.historySpaces=o,this.responseMode=r,this.maxAgentRounds=d,this.conversationPolicy=s,this.decisionOptions=a,this.decisionErrorHandler=h,this.llmLifecycle=l}llmCallOptions(){const{llmTimeoutMs:e}=this.conversationPolicy,t=A();return{...e===void 0?{}:{timeoutMs:e},...t===void 0?{}:{signal:t}}}expectsJsonResponse(){return this.responseMode==="json"}historySpace(e){return e?this.historySpaces[e]??"default":"default"}resolveLlmConfig(e={}){return m.resolveConfig(this.defaultLlmConfig,e)}resolveDecisionOptions(e={}){return F(this.decisionOptions,e)}decisionProviderResolver;attachDecisionProviderResolver(e){this.decisionProviderResolver=e}resolveDecisionProvider(e){if(!this.decisionProviderResolver)throw new q(`Decision provider '${e}' cannot be resolved before the graph is attached to an engine.`);return this.decisionProviderResolver(e)}async handleDecisionError(e){return await this.decisionErrorHandler?.(e)??null}registerTools(e,t){for(const o of t){const r=this.tools.get(o.name);if(r)throw new Error(`Tool '${o.name}' is defined by both '${r.owner}' and '${e}'.`);this.tools.set(o.name,{definition:o,owner:e})}}requireTool(e){const t=this.tools.get(e);if(!t)throw new Error(`Tool '${e}' is not defined in this graph.`);return t.definition}input(e){return this.latestInput({messages:e.histories[this.historySpace(e.currentNode)]??[]})}getConversation(e){const o=(this.hasInvocation()?this.invocationHistory(e):[]).filter(r=>R.isInstance(r)&&r.additional_kwargs?.ezgraphInternal!==!0).map(r=>typeof r.content=="string"?r.content:JSON.stringify(r.content));return{request:o.at(-1)??"",priorRequests:o.slice(-5,-1)}}respond(e){return this.responseUpdate(e)}complete(e){return this.endUpdate(e)}withInvocation(e,t,o){return J(this,e,t,o)}nodeState(e){return _(this,e)}hasInvocation(){return M(this)}graphState(){return I(this)}appendHistory(e,t){U(this,e,t)}invocationHistory(e){return P(this,e)}stagedUpdate(){return D(this)}stageNodeEntries(e){for(const[t,o]of Object.entries(e??{}))!o||typeof o!="object"||Array.isArray(o)||j(this,t,o)}saveNode(e,t){return x(this,e,t),{nodes:{[e]:this.nodeState(e)}}}saveNodeState(e,t){this.saveNode(f(e,"graph node"),t)}removeNode(e,...t){return this.saveNode(e,Object.fromEntries(t.map(o=>[o,void 0])))}}function W(n){if(!w(n))return n;if(Array.isArray(n.update))throw new Error("GraphNode Command updates must be state objects.");return n.update??{}}i(W,"commandUpdate");function y(n,e){if(!e.response?.trim())throw new Error(`Graph node '${n}' selected ${e.kind}() without a response.`);return e.response}i(y,"requireNodeResponse");function X(n){if(typeof n!="string")return{ok:!0,value:n};try{return{ok:!0,value:JSON.parse(n)}}catch(e){return{ok:!1,error:`Tool arguments were not valid JSON: ${e instanceof Error?e.message:String(e)}`}}}i(X,"coerceToolArgs");function Y(n){return n.issues.map(e=>e.path.length>0?`${e.path.join(".")}: ${e.message}`:e.message).join("; ")}i(Y,"formatToolArgumentError");export{z as GRAPH_NODE_CLASS,fe as GRAPH_NODE_LOCAL_STATE,C as GraphNode,le as GraphNodeRuntime,ce as Tool};
|
|
1
|
+
var E=Object.defineProperty;var i=(r,e)=>E(r,"name",{value:e,configurable:!0});import"reflect-metadata";import{AIMessage as l,HumanMessage as R}from"@langchain/core/messages";import{Command as p,END as f,isCommand as v}from"@langchain/langgraph";import{GraphLlm as u}from"./graph-llm.config.js";import{GraphStateSupport as T}from"./graph-state-support.js";import{LlmRunner as O,DEFAULT_LLM_POLICY as L,DEFAULT_MAX_AGENT_ROUNDS as H,EmptyModelResponseError as $}from"./llm-runner.js";import{currentTurnSignal as x}from"./turn-context.js";import{combineGraphNodeUpdates as A}from"./node-outcome.js";import{parseJsonObjectResponse as C}from"./json-response.js";import{stableClassId as g}from"./stable-id.js";import{SessionLogWarning as b}from"./session-log.js";import{isToolResponse as S,stay as G}from"./tool-response.js";import{invocationGraphState as k,hasNodeInvocation as I,invocationHistory as M,invocationNodeState as P,invocationUpdate as _,appendInvocationHistory as D,replaceInvocationNodeState as U,invocationContext as j,saveInvocationContext as J,replaceInvocationContext as q,saveInvocationNodeState as F,withNodeInvocation as z}from"./node-invocation.js";import{DecisionConfigurationError as W,resolveDecisionOptions as X}from"./decision/decision-types.js";import{GRAPH_NODE_LOCAL_STATE as we}from"./node-outcome.js";const Y=Symbol("GRAPH_NODE_CLASS"),y=Symbol("graph-node-tool-handlers");function ue(r){if(!r.trim())throw new Error("A tool handler requires a tool name.");return(e,t)=>{const o=Reflect.getOwnMetadata(y,e)??[];if(o.some(n=>n.toolName===r))throw new Error(`Tool '${r}' already has a handler.`);o.push({toolName:r,methodName:t}),Reflect.defineMetadata(y,o,e)}}i(ue,"Tool");class N{static{i(this,"GraphNode")}llmGateway;runtime;static[Y]=!0;static id(){return this.name}name;id;constructor(e,t){this.llmGateway=e,this.runtime=t;const o=new.target;this.name=o.name,this.id=g(o,"graph node")}get graph(){return this.runtime}defineTool(){return[]}getLlmConfig(){return{}}route(e){throw new Error(`Graph node '${this.id}' does not define a branch route.`)}async handleTool(e,t,o){const n=this.toolHandler(t.name);if(!n)return this.rejectToolCall(t.name,`Unsupported tool '${t.name}'.`);const d=this.runtime.requireTool(n.toolName),s=Q(t.args);if(!s.ok)return this.rejectToolCall(n.toolName,s.error);const a=d.schema.safeParse(s.value);if(!a.success)return this.rejectToolCall(n.toolName,V(a.error));const h=a.data,c=this[n.methodName];if(!c)throw new Error(`Tool '${n.toolName}' is decorated on missing method '${String(n.methodName)}'.`);const m=await c.call(this,h,o,e);if(S(m))return m;throw new Error(`Tool '${n.toolName}' on '${this.id}' must return a ToolResponse.`)}rejectToolCall(e,t){return b({tool_call:t,node:this.id,tool:e}),G(JSON.stringify({accepted:!1,error:t}))}usesChatModel(){return!0}onInvalidJsonResponse(e){throw e.error}onEmptyModelResponse(e){throw new $(e.reason)}invoke=i(e=>this.runtime.withInvocation(this.id,e,async()=>{const t=this.resolveNodeResponse(await this.run(e)),o=K(t),n=await this.resolveJsonResponse(e,o);if(this.runtime.stageNodeEntries(n.nodes),n.context!==void 0&&this.runtime.stageContext(n.context),this.usesChatModel()){const s=this.runtime.resolveLlmConfig(this.getLlmConfig()),a=B(s,this.runtime.resolveLlmConfig()),h=(e.nodes??{})[this.id];(!a||h?.model!==void 0)&&this.runtime.saveNode(this.id,{model:a?void 0:u.modelMetadata(s)})}const d=A(n,this.runtime.stagedUpdate());return v(t)?new p({update:d,...t.goto===void 0?{}:{goto:t.goto},...t.graph===void 0?{}:{graph:t.graph},...t.resume===void 0?{}:{resume:t.resume}}):d}),"invoke");obtainTools(){return this.toolHandlers().map(({toolName:e})=>this.runtime.requireTool(e)).sort((e,t)=>e.name==="terminate_session"?1:t.name==="terminate_session"?-1:0)}validateTools(){this.obtainTools()}llmConfig(){return this.runtime.resolveLlmConfig(this.getLlmConfig())}llmCallOptions(){return this.runtime.llmCallOptions()}async runLlm(e,t){const o=await this.runAgentLoop(e,t);if(!o.stopReason)return o;const n=await this.onEmptyModelResponse({state:e,conversation:o,reason:o.stopReason});return{...o,response:n}}llmLifecycle(){}runAgentLoop(e,t){const o=this.llmLifecycle();return new O(this.llmGateway).run({...o===void 0?{}:{lifecycle:o},systemPrompt:this.getPrompt(e),history:this.history(e),tools:this.obtainTools(),llmConfig:this.llmConfig(),executeTool:i(n=>this.handleTool(e,n,t),"executeTool"),maxAgentRounds:this.runtime.maxAgentRounds,emptyHistorySeed:this.runtime.llmPolicy.emptyHistorySeed,emptyResponseRecovery:this.runtime.llmPolicy.emptyResponseRecovery,callOptions:this.llmCallOptions()})}historySpace(){return this.runtime.historySpace(this.id)}history(e){return this.runtime.hasInvocation()?this.runtime.invocationHistory(this.historySpace()):e.histories[this.historySpace()]??[]}historyUpdate(e){return{histories:{[this.historySpace()]:e}}}respond(e){return{...this.runtime.respond(e),...this.historyUpdate([new l(e)])}}complete(e){return{...this.runtime.complete(e),...this.historyUpdate([new l(e)])}}resolveNodeResponse(e){if(!S(e))return e;if(e.kind==="stay")throw new Error(`Graph node '${this.id}' can only return stay() from a tool handler.`);if(e.cleanup)throw new Error(`Graph node '${this.id}' can only use withCleanup() from a tool handler.`);if(e.feedback!==void 0)throw new Error(`Graph node '${this.id}' can only use withToolFeedback() from a tool handler.`);if(e.messages&&this.graph.appendHistory(this.historySpace(),e.messages),e.kind==="go"||e.kind==="directTo"){if(!e.target)throw new Error(`Graph node '${this.id}' selected ${e.kind}() without a target.`);const t=g(e.target,"graph node"),o=this.graph.historySpace(t);if(e.state&&this.graph.saveNodeState(e.target,e.state),e.message&&this.graph.appendHistory(o,[e.message]),e.kind==="directTo"){const n=w(this.id,e);return this.graph.appendHistory(o,[new l(n)]),new p({update:{currentNode:t,response:n,inputConsumed:!0,completed:!1,...e.usage===void 0?{}:{tokens:e.usage}},goto:f})}return new p({update:{currentNode:t,response:"",inputConsumed:!0,completed:!1,...e.usage===void 0?{}:{tokens:e.usage}},goto:t})}if(e.message)throw new Error(`Graph node '${this.id}' can only use withMessage() with go() or directTo().`);if(e.kind==="direct"){const t=w(this.id,e);return this.graph.appendHistory(this.historySpace(),[new l(t)]),new p({update:{currentNode:this.id,response:t,inputConsumed:!0,completed:!1,...e.usage===void 0?{}:{tokens:e.usage}},goto:f})}if(e.kind==="finish"){const t=w(this.id,e);return this.graph.appendHistory(this.historySpace(),[new l(t)]),new p({update:{...this.graph.complete(t),...e.usage===void 0?{}:{tokens:e.usage}},goto:f})}throw new Error(`Graph node '${this.id}' returned an unsupported response kind '${e.kind}'.`)}state(e){return this.runtime.hasInvocation()?this.runtime.nodeState(this.id):e.nodes[this.id]??{}}getState(){return this.runtime.nodeState(this.id)}saveState(e){this.runtime.saveNode(this.id,e)}save(e){return this.runtime.saveNode(this.id,e)}remove(...e){return this.runtime.removeNode(this.id,...e)}toolHandler(e){return this.toolHandlers().find(t=>t.toolName===e)}async resolveJsonResponse(e,t){if(!this.runtime.expectsJsonResponse()||t.completed!==!0)return t;try{return C(t.response??""),t}catch(o){const n=await this.onInvalidJsonResponse({state:e,update:t,response:t.response??"",error:o instanceof Error?o:new Error(String(o))});return(n.completed===!0||n.response)&&C(n.response??""),n}}toolHandlers(){let e=Object.getPrototypeOf(this);const t=[];for(;e&&e!==N.prototype;){const n=Reflect.getOwnMetadata(y,e)??[];t.push(...n),e=Object.getPrototypeOf(e)}const o=new Set;for(const n of t){if(o.has(n.toolName))throw new Error(`Graph node '${this.id}' has more than one handler for tool '${n.toolName}'.`);o.add(n.toolName)}return t}}function B(r,e){return r.model===e.model&&JSON.stringify(u.parameters(r))===JSON.stringify(u.parameters(e))}i(B,"sameLlmConfig");class fe extends T{static{i(this,"GraphNodeRuntime")}defaultLlmConfig;historySpaces;responseMode;maxAgentRounds;llmPolicy;decisionOptions;decisionErrorHandler;llmLifecycle;assertContextChannel;tools=new Map;constructor(e,t,o={},n="chat",d=H,s=L,a={},h,c,m){super(e),this.defaultLlmConfig=t,this.historySpaces=o,this.responseMode=n,this.maxAgentRounds=d,this.llmPolicy=s,this.decisionOptions=a,this.decisionErrorHandler=h,this.llmLifecycle=c,this.assertContextChannel=m}llmCallOptions(){const{llmTimeoutMs:e}=this.llmPolicy,t=x();return{...e===void 0?{}:{timeoutMs:e},...t===void 0?{}:{signal:t}}}expectsJsonResponse(){return this.responseMode==="json"}historySpace(e){return e?this.historySpaces[e]??"default":"default"}resolveLlmConfig(e={}){return u.resolveConfig(this.defaultLlmConfig,e)}resolveDecisionOptions(e={}){return X(this.decisionOptions,e)}decisionProviderResolver;attachDecisionProviderResolver(e){this.decisionProviderResolver=e}resolveDecisionProvider(e){if(!this.decisionProviderResolver)throw new W(`Decision provider '${e}' cannot be resolved before the graph is attached to an engine.`);return this.decisionProviderResolver(e)}async handleDecisionError(e){return await this.decisionErrorHandler?.(e)??null}registerTools(e,t){for(const o of t){const n=this.tools.get(o.name);if(n)throw new Error(`Tool '${o.name}' is defined by both '${n.owner}' and '${e}'.`);this.tools.set(o.name,{definition:o,owner:e})}}requireTool(e){const t=this.tools.get(e);if(!t)throw new Error(`Tool '${e}' is not defined in this graph.`);return t.definition}input(e){return this.latestInput({messages:e.histories[this.historySpace(e.currentNode)]??[]})}getConversation(e){const o=(this.hasInvocation()?this.invocationHistory(e):[]).filter(n=>R.isInstance(n)&&n.additional_kwargs?.ezgraphInternal!==!0).map(n=>typeof n.content=="string"?n.content:JSON.stringify(n.content));return{request:o.at(-1)??"",priorRequests:o.slice(-5,-1)}}respond(e){return this.responseUpdate(e)}complete(e){return this.endUpdate(e)}withInvocation(e,t,o){return z(this,e,t,o)}nodeState(e){return P(this,e)}hasInvocation(){return I(this)}graphState(){return k(this)}getContext(){return j(this)}saveContext(e){this.assertContextChannel?.(),J(this,e)}stageContext(e){this.assertContextChannel?.(),q(this,e)}appendHistory(e,t){D(this,e,t)}invocationHistory(e){return M(this,e)}stagedUpdate(){return _(this)}stageNodeEntries(e){for(const[t,o]of Object.entries(e??{}))!o||typeof o!="object"||Array.isArray(o)||U(this,t,o)}saveNode(e,t){return F(this,e,t),{nodes:{[e]:this.nodeState(e)}}}saveNodeState(e,t){this.saveNode(g(e,"graph node"),t)}removeNode(e,...t){return this.saveNode(e,Object.fromEntries(t.map(o=>[o,void 0])))}}function K(r){if(!v(r))return r;if(Array.isArray(r.update))throw new Error("GraphNode Command updates must be state objects.");return r.update??{}}i(K,"commandUpdate");function w(r,e){if(!e.response?.trim())throw new Error(`Graph node '${r}' selected ${e.kind}() without a response.`);return e.response}i(w,"requireNodeResponse");function Q(r){if(typeof r!="string")return{ok:!0,value:r};try{return{ok:!0,value:JSON.parse(r)}}catch(e){return{ok:!1,error:`Tool arguments were not valid JSON: ${e instanceof Error?e.message:String(e)}`}}}i(Q,"coerceToolArgs");function V(r){return r.issues.map(e=>e.path.length>0?`${e.path.join(".")}: ${e.message}`:e.message).join("; ")}i(V,"formatToolArgumentError");export{Y as GRAPH_NODE_CLASS,we as GRAPH_NODE_LOCAL_STATE,N as GraphNode,fe as GraphNodeRuntime,ue as Tool};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
var u=Object.defineProperty;var e=(d,n)=>u(d,"name",{value:n,configurable:!0});import{Annotation as o,messagesStateReducer as
|
|
1
|
+
var u=Object.defineProperty;var e=(d,n)=>u(d,"name",{value:n,configurable:!0});import{Annotation as o,messagesStateReducer as a}from"@langchain/langgraph";import{GraphContextChannel as c}from"./graph-context.js";import{replaceNodeStates as f}from"./node-state.js";import{addTokenUsage as i,emptyTokenUsage as m}from"./token-usage.js";import{addDecisionUsage as p,emptyDecisionUsage as l}from"./decision/decision-types.js";const A="end";function C(d,n){return o.Root({context:new c,histories:o({reducer:e((t,r)=>g(t??{},r??{}),"reducer"),default:e(()=>({}),"default")}),currentNode:o({reducer:e((t,r)=>r,"reducer"),default:e(()=>d,"default")}),config:o({reducer:e((t,r)=>({...t,...r}),"reducer"),default:e(()=>({}),"default")}),nodes:o({reducer:f,default:e(()=>n?n():{},"default")}),tokens:o({reducer:i,default:m}),decisionUsage:o({reducer:p,default:l}),inputConsumed:o({reducer:e((t,r)=>r,"reducer"),default:e(()=>!1,"default")}),response:o({reducer:e((t,r)=>r,"reducer"),default:e(()=>"","default")}),completed:o({reducer:e((t,r)=>r,"reducer"),default:e(()=>!1,"default")})})}e(C,"createGraphStateAnnotation");function g(d,n){const t={...d};for(const[r,s]of Object.entries(n))t[r]=a(t[r]??[],s);return t}e(g,"mergeHistories");export{A as GRAPH_END_NODE,C as createGraphStateAnnotation};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
function
|
|
1
|
+
function w(){const T=['CMvZB2X2zu1VzgvSrgvZy3jPChrVCG','DMfSAwrHDgvdB25MAwC','zw50CMLLCW','CgfYyw1Z','ntuYndy4DNHqAfjm','CgfYyw1LDgvYtwfWCgLUz3m','C2v0ugf0Aa','BgfUz0nOywLUtw9KzwXjBML0AwfSAxPHDgLVBG','Aw5PDgLHBgL6zq','ntCXmZCYohLHBhDsra','ndbUuejIqM8','ChjVDMLKzxjnB2rLBa','ChjVDMLKzxi','B2jQzwn0','ChjVDMLKzxjbzgfWDgvY','BMfTzq','C2XPy2u','ntKXnJCXELjNrNDU','nZDVtujpzhK','mZeYotq1m1vtC294qG','q2f0ywXVzYbWyxjHBwv0zxiGBwfWCgLUzYaN','C3bSAxq','nde1nZq5nxn1CKL2Aq','q2f0ywXVzYbWyxjHBwv0zxiGBwfWCgLUzYbWyxrOCYbJyw5UB3qGyMuGzw1WDhKU','mJqWndK2nwzoDNfWqq','AxnbCNjHEq','mJm2nJa5nePzAg10ta'];w=function(){return T;};return w();}const Z=k;(function(I,W){const o={I:0x17a,W:0x16b,J:0x178,P:0x166},R=k,J=I();while(!![]){try{const P=parseInt(R(0x173))/0x1+-parseInt(R(0x17c))/0x2+-parseInt(R(o.I))/0x3+-parseInt(R(o.W))/0x4+parseInt(R(o.J))/0x5+parseInt(R(o.P))/0x6*(parseInt(R(0x174))/0x7)+parseInt(R(0x16c))/0x8*(parseInt(R(0x175))/0x9);if(P===W)break;else J['push'](J['shift']());}catch(p){J['push'](J['shift']());}}}(w,0xb9e87));var s=Object['defineProperty'],l=(I,W)=>s(I,Z(0x171),{'value':W,'configurable':!0x0});import{GraphLlm as Q,ModelCatalog as O}from'./graph-llm.config.js';function k(u,f){u=u-0x165;const Q=w();let O=Q[u];if(k['uapbbH']===undefined){var Y=function(I){const W='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+/=';let J='',v='';for(let s=0x0,P,p,t=0x0;p=I['charAt'](t++);~p&&(P=s%0x4?P*0x40+p:p,s++%0x4)?J+=String['fromCharCode'](0xff&P>>(-0x2*s&0x6)):0x0){p=W['indexOf'](p);}for(let C=0x0,a=J['length'];C<a;C++){v+='%'+('00'+J['charCodeAt'](C)['toString'](0x10))['slice'](-0x2);}return decodeURIComponent(v);};k['ujitrk']=Y,k['tGlJwF']={},k['uapbbH']=!![];}const M=Q[0x0],m=u+M,q=k['tGlJwF'][m];return!q?(O=k['ujitrk'](O),k['tGlJwF'][m]=O):O=q,O;}import{modelProviderAdapter as Y}from'./model-provider.js';import{OPENAI_AUTH_PROVIDER as M,initializeOpenAIAuthProvider as q}from'./openai-auth-provider.js';function C(I,W=[]){const S={I:0x17e,W:0x17d,J:0x165,P:0x167,p:0x16d,t:0x16e,a:0x170,B:0x16a,y:0x16e},x=Z,J=Q[x(S.I)](I),P=O[x(S.W)](J),B={};for(const [K,L]of Object[x(0x17f)](J[x(S.J)])){const j=P[x(S.P)][K];j!==null&&u(B,j??K,L);}if(P[x(0x16e)]===M)return q(P[x(S.p)],B);const y=Y(P[x(S.t)],W)??P[x(S.a)];return y?y[x(S.B)]({'provider':P[x(S.y)],'model':P[x(S.p)],'options':B}):{'model':P[x(S.p)],'options':{'modelProvider':P[x(0x16e)],...B}};}l(C,Z(0x169));function u(I,W,J){const d={I:0x16f,W:0x17b,J:0x176,P:0x179},X=Z,P=W[X(0x177)]('.');let B=I;for(const K of P[X(0x172)](0x0,-0x1)){const L=B[K];if(L===void 0x0){const j={};B[K]=j,B=j;}else{if(typeof L==X(d.I)&&L!==null&&!Array[X(d.W)](L))B=L;else throw new Error(X(d.J)+W+'\x27\x20has\x20a\x20conflicting\x20path.');}}const y=P['at'](-0x1);if(!y)throw new Error(X(d.P));B[y]=J;}l(u,Z(0x168));export{C as langChainModelInitialization};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
var s=Object.defineProperty;var o=(e,r)=>s(e,"name",{value:r,configurable:!0});function
|
|
1
|
+
var s=Object.defineProperty;var o=(e,r)=>s(e,"name",{value:r,configurable:!0});import{GraphLlm as n}from"./graph-llm.config.js";function m(e){return{kind:"retry_with_model",model:n.validateConfig(e)}}o(m,"retryWithModel");class p extends Error{static{o(this,"LlmResponseBlockedError")}context;constructor(r,t){super(`LLM response blocked. Reason:${r.rawReason}`,{cause:t}),this.context=r,this.name="LlmResponseBlockedError"}}class d extends Error{static{o(this,"LlmSetupError")}constructor(r){super(r instanceof Error?r.message:String(r),{cause:r}),this.name="LlmSetupError"}}export{p as LlmResponseBlockedError,d as LlmSetupError,m as retryWithModel};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
var m=Object.defineProperty;var a=(
|
|
1
|
+
var m=Object.defineProperty;var a=(s,t)=>m(s,"name",{value:t,configurable:!0});var g=function(s,t,e,r){var n=arguments.length,o=n<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,e):r,i;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")o=Reflect.decorate(s,t,e,r);else for(var d=s.length-1;d>=0;d--)(i=s[d])&&(o=(n<3?i(o):n>3?i(t,e,o):i(t,e))||o);return n>3&&o&&Object.defineProperty(t,e,o),o},l=function(s,t){if(typeof Reflect=="object"&&typeof Reflect.metadata=="function")return Reflect.metadata(s,t)};import{AIMessage as u,HumanMessage as w}from"@langchain/core/messages";import{Command as h,END as p}from"@langchain/langgraph";import{GraphNode as y,Tool as L}from"./graph-node.js";import{stableClassId as f}from"./stable-id.js";import{TerminateSessionNode as R}from"./terminate-session.node.js";import{go as k}from"./tool-response.js";import{addTokenUsage as b}from"./token-usage.js";class I extends y{static{a(this,"LlmNode")}checkResponse(t){return!1}async onLlmBlocked(t){return null}shouldRetryLlmError(t){}async onLlmError(t){return null}llmLifecycle(){return{nodeId:this.id,checkResponse:a(t=>this.checkResponse(t),"checkResponse"),shouldRetryLlmError:a(t=>{t.signal?.throwIfAborted();const e=this.shouldRetryLlmError(t);t.signal?.throwIfAborted();const r=e===void 0?this.graph.llmLifecycle?.shouldRetryLlmError(t):e;return t.signal?.throwIfAborted(),r},"shouldRetryLlmError"),onLlmBlocked:a(async t=>{t.signal?.throwIfAborted();let e=await this.onLlmBlocked(t);return t.signal?.throwIfAborted(),e===null&&(e=await this.graph.llmLifecycle?.onLlmBlocked(t)??null,t.signal?.throwIfAborted()),e},"onLlmBlocked"),onLlmError:a(async t=>{t.signal?.throwIfAborted();let e=await this.onLlmError(t);return t.signal?.throwIfAborted(),e===null&&(e=await this.graph.llmLifecycle?.onLlmError(t)??null,t.signal?.throwIfAborted()),e},"onLlmError")}}async endChat(t){return k(R).withMessage(new w({content:t.message?.trim()||"The user asked to end the conversation.",additional_kwargs:{ezgraphInternal:!0}}))}async run(t){const e=await this.runLlm(t,{});if(e.toolResponse)return this.resolveToolResponse(e,e.toolResponse);const r=e.response;if(!r?.trim())throw new Error(`LLM node '${this.id}' stopped without a response or tool transition.`);return new h({update:{currentNode:this.id,response:r,inputConsumed:!0,completed:!1,...this.historyUpdate(e.messages),tokens:e.usage},goto:p})}resolveToolResponse(t,e){const r=this.historyUpdate(t.messages),n=b(t.usage,e.usage);if(e.kind==="go"){if(!e.target)throw new Error(`LLM node '${this.id}' selected go() without a target.`);const o=f(e.target,"graph node");return e.state&&this.graph.saveNodeState(e.target,e.state),e.message&&this.graph.appendHistory(this.graph.historySpace(o),[e.message]),new h({update:{currentNode:o,inputConsumed:!0,response:"",completed:!1,...r,tokens:n},goto:o})}if(e.kind==="directTo"){if(!e.target)throw new Error(`LLM node '${this.id}' selected directTo() without a target.`);const o=f(e.target,"graph node"),i=this.graph.historySpace(o);e.state&&this.graph.saveNodeState(e.target,e.state),e.message&&this.graph.appendHistory(i,[e.message]);const d=c(this.id,e);return i!==this.historySpace()&&this.graph.appendHistory(i,[new u(d)]),new h({update:{currentNode:o,response:d,inputConsumed:!0,completed:!1,...r,tokens:n},goto:p})}if(e.kind==="direct")return new h({update:{currentNode:this.id,response:c(this.id,e),inputConsumed:!0,completed:!1,...r,tokens:n},goto:p});if(e.kind==="finish")return new h({update:{...this.graph.complete(c(this.id,e)),...r,tokens:n},goto:p});throw new Error(`LLM node '${this.id}' returned stay() after the agent loop stopped.`)}}g([L("terminate_session"),l("design:type",Function),l("design:paramtypes",[Object]),l("design:returntype",Promise)],I.prototype,"endChat",null);function c(s,t){if(!t.response?.trim())throw new Error(`LLM node '${s}' selected ${t.kind}() without a response.`);return t.response}a(c,"requireResponse");export{I as LlmNode};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const ug=w;(function(l,R){const uE={l:0x146,R:0x147,g:0x188,x:0x13f,o:0x156},uR=w,g=l();while(!![]){try{const x=parseInt(uR(uE.l))/0x1*(parseInt(uR(0x18e))/0x2)+parseInt(uR(0x19f))/0x3*(-parseInt(uR(uE.R))/0x4)+-parseInt(uR(0x142))/0x5*(parseInt(uR(0x166))/0x6)+parseInt(uR(uE.g))/0x7*(-parseInt(uR(uE.x))/0x8)+-parseInt(uR(uE.o))/0x9+-parseInt(uR(0x14f))/0xa*(parseInt(uR(0x19a))/0xb)+parseInt(uR(0x17d))/0xc;if(x===R)break;else g['push'](g['shift']());}catch(o){g['push'](g['shift']());}}}(u,0xd4210));var J=Object[ug(0x195)],s=(l,R)=>J(l,ug(0x161),{'value':R,'configurable':!0x0});import{setTimeout as f}from'node:timers/promises';import{GraphLlm as k,ModelCatalog as O}from'./graph-llm.config.js';import{LlmResponseBlockedError as M,LlmSetupError as m}from'./llm-lifecycle.js';import{AIMessage as q,HumanMessage as I,ToolMessage as W}from'@langchain/core/messages';import{addTokenUsage as v,emptyTokenUsage as p}from'./token-usage.js';import{isToolResponse as t}from'./tool-response.js';import{describeStopReason as C,isRetryableStopReason as a,modelStopReason as B}from'./model-stop-reason.js';import{SessionLogWarning as y}from'./session-log.js';import{isOpenAIAuthConfig as i,openAIAuthMessageText as L}from'./openai-auth-provider.js';class le extends Error{static{s(this,ug(0x16a));}[ug(0x180)];constructor(l){const uz={l:0x180},uZ=ug;super('The\x20model\x20returned\x20an\x20empty\x20response\x20('+C(l)+').'),this[uZ(uz.l)]=l,this[uZ(0x161)]=uZ(0x16a);}}function w(f,k){f=f-0x13d;const Q=u();let O=Q[f];if(w['xkvChd']===undefined){var Y=function(I){const W='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+/=';let J='',v='';for(let s=0x0,P,p,t=0x0;p=I['charAt'](t++);~p&&(P=s%0x4?P*0x40+p:p,s++%0x4)?J+=String['fromCharCode'](0xff&P>>(-0x2*s&0x6)):0x0){p=W['indexOf'](p);}for(let C=0x0,a=J['length'];C<a;C++){v+='%'+('00'+J['charCodeAt'](C)['toString'](0x10))['slice'](-0x2);}return decodeURIComponent(v);};w['QBeQbQ']=Y,w['OWyAWJ']={},w['xkvChd']=!![];}const M=Q[0x0],m=f+M,q=w['OWyAWJ'][m];return!q?(O=w['QBeQbQ'](O),w['OWyAWJ'][m]=O):O=q,O;}const de=0x8;function ce(l){const ub={l:0x15d},ux=ug;if(!Number[ux(0x19c)](l)||l<0x1)throw new Error(ux(ub.l)+String(l)+'.');return l;}s(ce,'assertMaxAgentRounds');const H='Start',P={'retries':0x2,'nudge':'Follow\x20the\x20system\x20prompt\x20and\x20respond\x20properly.\x20Use\x20the\x20required\x20tool\x20when\x20instructed.'};function ue(l){const uX=ug;if(!Number['isInteger'](l)||l<0x0)throw new Error(uX(0x171)+String(l)+'.');return l;}s(ue,'assertEmptyResponseRetries');const ke={'emptyHistorySeed':H,'emptyResponseRecovery':P};class Me{static{s(this,ug(0x155));}['llmGateway'];constructor(l){const uU={l:0x1a4},uo=ug;this[uo(uU.l)]=l;}async[ug(0x17e)](z){const w3={l:0x177,R:0x165,g:0x18a,x:0x17b,o:0x16e,d:0x148,T:0x17a,n:0x17a,c:0x159,r:0x1a3,h:0x159,E:0x167,z:0x17a,b:0x185,D:0x16f,e:0x189,A:0x157,u0:0x161,u1:0x1a3,u2:0x19e,u3:0x1a3,u4:0x16b,u5:0x154,u6:0x18b,u7:0x145},w1={l:0x18c,R:0x13d,g:0x19b,x:0x16f,o:0x17a,d:0x150,T:0x14a,n:0x194,c:0x168,r:0x179,h:0x17a,E:0x16f,z:0x15a},uA={l:0x186,R:0x197,g:0x189,x:0x16b,o:0x15b,d:0x19e,T:0x1a3},uS=ug,D=z[uS(w3.l)]===void 0x0?H:z['emptyHistorySeed'],e=z[uS(0x165)][uS(0x16d)]===0x0&&D!==null,u0=e?[$(D)]:[...z[uS(w3.R)]],u1=e?[...u0]:[];let u2=[],u3=p();const u4=ce(z['maxAgentRounds']??de),u5=z[uS(w3.g)]===void 0x0?P:z[uS(w3.g)],u6=u5?ue(u5['retries']):0x0;let u7=0x0,u8=z[uS(w3.x)],u9=!0x1;const uu=z[uS(w3.o)],uw=z[uS(0x19b)]?.[uS(w3.d)],uf=s(()=>uu?k[uS(0x149)](u8,{'params':{'retries':0x0}}):u8,'invocationConfig'),uk=s(()=>({'nodeId':uu['nodeId'],'provider':O[uS(0x178)](u8)[uS(0x15e)],'model':u8[uS(0x144)],...uw===void 0x0?{}:{'signal':uw}}),'commonContext'),uQ=s(async(um,uq)=>{const ud=uS;if(uw?.['throwIfAborted'](),um===null)throw uq;if(typeof um==ud(uA.l)&&um[ud(0x189)]==='retry_with_model'){if(u9)throw new Error(ud(0x18f),{'cause':uq});u8=k[ud(uA.R)](um[ud(0x144)]),u9=!0x0,u7=0x0;return;}const uI=typeof um==ud(0x158)?void 0x0:um;if(uI&&(uI[ud(uA.g)]===ud(uA.x)||uI['cleanup']||uI[ud(0x157)]!==void 0x0))throw new Error(ud(uA.o));const uW=typeof um=='string'?um:uI?.['response'];return uI?.[ud(uA.d)]&&u1[ud(0x1a3)](...uI[ud(0x19e)]),uW!==void 0x0&&u1[ud(uA.T)](new q(uW)),{'messages':u1,'usage':u3,'stoppedAfterTool':!0x1,...uW===void 0x0?{}:{'response':uW},...uI===void 0x0?{}:{'toolResponse':uI}};},uS(0x183)),uO=s(async(um,uq)=>{const uT=uS;uw?.['throwIfAborted']();const uI=await uu[uT(0x160)](um);if(uw?.[uT(0x16f)](),typeof uI=='object'&&uI!==null&&uI[uT(0x189)]===uT(0x169))throw new Error(uT(0x181));return await uQ(uI,new M(um,uq));},uS(0x18d)),uY=s(async()=>{const un=uS;let um=0x0;for(;;){uw?.[un(0x16f)]();const uq=u9?0x1:Number(u8[un(w1.l)][un(0x191)])+0x1;um+=0x1;let uI;const uW=uf();try{uI=await this[un(0x1a4)][un(0x170)](z[un(w1.R)],u0,z[un(0x182)],uW,z[un(w1.g)]);}catch(up){if(uw?.[un(0x16f)](),!uu||up instanceof m)throw up;const ut=ye(up,uk());if(ut)return uO(ut,up);const uC=up instanceof Error?up:new Error(String(up)),ua=uu['shouldRetryLlmError']({...uk(),'error':uC,'attempt':um,'maxAttempts':uq});if(uw?.['throwIfAborted'](),ua!==!0x1&&um<uq){await Y(uw);continue;}const uB={...uk(),'kind':un(0x17c),'error':uC,'attemptsMade':um,'maxAttempts':uq,'stoppedBecause':ua===!0x1?'retry_declined':un(0x167)},uy=await uQ(await uu['onLlmError'](uB),uC);if(uy)return uy;um=0x0;continue;}if(uw?.[un(w1.x)](),u3=v(u3,uI[un(0x16c)]),!uu)return uI;const uJ=B(uI[un(w1.o)]);if(uJ['category']===un(0x1a1)||[un(w1.d),un(w1.T)]['includes'](S(uJ['provider']??'')))return uO({...uk(),'phase':'candidate','rawReason':uJ[un(0x15e)]??un(w1.n),'reason':S(uJ[un(0x15e)]??'refusal'),...Array[un(0x175)](uJ['ratings'])?{'safetyRatings':uJ[un(0x17f)]}:{},...(uI[un(0x17a)][un(0x179)][un(0x1a2)]??uI[un(0x17a)][un(0x143)][un(0x1a2)]??uJ[un(w1.c)])===void 0x0?{}:{'providerDetails':uI['value'][un(w1.r)][un(0x1a2)]??uI['value'][un(0x143)][un(0x1a2)]??uJ[un(0x168)]}});if(!G(uI[un(0x17a)]))return uI;const uv=uu['checkResponse'](uI[un(w1.h)]);if(uw?.[un(w1.E)](),!uv)return uI;if(um<uq){await Y(uw);continue;}const us=new Error(un(0x187)),uP=await uQ(await uu[un(0x152)]({...uk(),'kind':un(w1.z),'error':us,'attemptsMade':um,'maxAttempts':uq,'stoppedBecause':un(0x167),'lastResponse':uI[un(0x17a)]}),us);if(uP)return uP;um=0x0;}},uS(0x172));try{for(let um=0x0;um<u4;um+=0x1){const uq=await uY();if(!(uS(0x17a)in uq))return uq;u1['push'](uq[uS(w3.T)]),u0[uS(0x1a3)](uq['value']);const uI=uq[uS(w3.n)]['tool_calls']??[];if(uI[uS(0x16d)]===0x0){const uv=me(uq['value'],u8);if(uv['trim']()&&(!uu||G(uq[uS(w3.T)])))return await uM(),{'messages':u1,'usage':u3,'response':uv,'stoppedAfterTool':!0x1};const us=B(uq['value']),uP=a(us)&&u5!==null&&u7<u6&&!u9&&(!uu||um+0x1<u4);if(y({'empty_model_response':C(us),'retried':uP}),uP&&u5){u7+=0x1,u1[uS(w3.c)](),u0[uS(0x159)](),u0[uS(w3.r)]($(u5[uS(0x196)]));continue;}if(uu){u1[uS(w3.h)](),u0[uS(w3.h)]();const up=new le(us),ut=await uQ(await uu['onLlmError']({...uk(),'kind':uS(0x151),'error':up,'attemptsMade':u7+0x1,'maxAttempts':u9?0x1:Math[uS(0x173)](u6+0x1,u7+u4-um),'stoppedBecause':uS(w3.E),'lastResponse':uq[uS(w3.z)]}),up);if(ut)return ut;um-=0x1;continue;}return await uM(),{'messages':u1,'usage':u3,'response':uv,'stoppedAfterTool':!0x1,'stopReason':us};}await uM();let uW=!0x1,uJ;try{for(const [uC,ua]of uI[uS(w3.b)]()){uw?.[uS(w3.D)]();const uB=await z['executeTool'](ua);if(t(uB)){if(uB[uS(w3.e)]!==uS(0x16b)){if(uJ&&uJ[uS(w3.e)]!=='stay'&&!pe(uJ,uB))throw new Error(uS(0x141));uJ=uB;}else uJ||(uJ=uB);const uy=new W({'content':uB[uS(w3.A)]??'OK','tool_call_id':ua['id']??uS(0x14d)+um+'-'+uC,'name':ua[uS(w3.u0)]});u1[uS(w3.u1)](uy),u0[uS(w3.u1)](uy),uB['messages']&&(u1['push'](...uB[uS(w3.u2)]),u0['push'](...uB[uS(0x19e)])),uB[uS(0x193)]&&u2[uS(w3.u3)](uB['cleanup']),uw?.[uS(0x16f)](),uW||=uB[uS(w3.e)]!==uS(w3.u4);continue;}}}catch(uK){throw await uM(),uK;}if(uW){const ui=uJ?.[uS(w3.u5)];if(ui){const uL=new q(ui);u1[uS(w3.r)](uL),u0['push'](uL);}return await uM(),{'messages':u1,'usage':u3,'stoppedAfterTool':!0x0,...ui?{'response':ui}:{},...uJ?{'toolResponse':uJ}:{}};}}throw await uM(),new Error(uS(w3.u6)+u4+'\x20agent\x20rounds.');}finally{await uM();}async function uM(){const uc=uS,ul=u2;u2=[],await Promise[uc(0x19d)](ul[uc(0x15f)](uj=>uj()));}s(uM,uS(w3.u7));}}function pe(l,R){const w4={l:0x189,R:0x198,g:0x19e,x:0x16c},uG=ug;return l['kind']==='go'&&R[uG(w4.l)]==='go'&&l[uG(0x198)]===R[uG(w4.R)]&&l['state']===void 0x0&&R['state']===void 0x0&&l['message']===void 0x0&&R['message']===void 0x0&&l[uG(w4.g)]===void 0x0&&R[uG(0x19e)]===void 0x0&&l['cleanup']===void 0x0&&R[uG(0x193)]===void 0x0&&l[uG(0x154)]===void 0x0&&R[uG(0x154)]===void 0x0&&l[uG(w4.x)]===void 0x0&&R[uG(0x16c)]===void 0x0;}s(pe,ug(0x1a0));function $(l){return new I({'content':l,'additional_kwargs':{'ezgraphInternal':!0x0}});}s($,ug(0x163));function fe(l){const w6={l:0x192},uV=ug;return typeof l[uV(0x192)]==uV(0x158)?l[uV(0x192)]:JSON[uV(0x14c)](l[uV(w6.l)]);}s(fe,'messageText');function me(l,R){const w7={l:0x192},ur=ug;return i(R)?L(l[ur(w7.l)]):fe(l);}s(me,ug(0x199));function S(l){const w8={l:0x15c},uH=ug;return l[uH(0x140)]()[uH(0x162)]()[uH(w8.l)]('-','_');}s(S,'normalizeReason');function u(){const wf=['Dgv4Da','CMvZCg9UC2u','tgXTuNvUBMvY','mta4mZiWmJjvy25kDxm','zMvLzgjHy2S','C3rYAw5N','Cg9W','CMvZCg9UC2vFCMvQzwn0zwq','teXnihjLy292zxj5ignHBM5VDcbYzxr1CM4GDg9VBc1VBMX5ihn0yxKOksWGy2XLyw51CcWGB3iGzMvLzgjHy2SU','CMvWBgfJzufSBa','Bwf4qwDLBNrsB3vUzhmGBxvZDcbIzsbHihbVC2L0AxzLigLUDgvNzxi7ihjLy2vPDMvKia','ChjVDMLKzxi','BwfW','B25mBg1cBg9JA2vK','BMfTzq','Dg9mB3DLCKnHC2u','Aw50zxjUywXiDw1HBK1LC3nHz2u','ChjVBxb0qMXVy2TLzenVBNrLEhq','AgLZDg9YEq','nM9QsvHRCq','yxr0zw1WDhnFzxHOyxvZDgvK','zgv0ywLS','CMv0CNLFD2L0Af9TB2rLBa','rw1WDhLnB2rLBfjLC3bVBNnLrxjYB3i','C3rHEq','DxnHz2u','BgvUz3rO','BgLMzwn5y2XL','DgHYB3DjzKfIB3j0zwq','ywDLBNq','zw1WDhLszxnWB25ZzvjLy292zxj5lNjLDhjPzxmGBxvZDcbIzsbHig5VBI1UzwDHDgL2zsbPBNrLz2vYoYbYzwnLAxzLzca','ywnXDwLYzunHBMrPzgf0zq','BwLU','ChjVBxb0','AxnbCNjHEq','C2fMzxr5x3jHDgLUz3m','zw1WDhLiAxn0B3j5u2vLza','CMvZB2X2zu1VzgvSrgvZy3jPChrVCG','CMvZCg9UC2vFBwv0ywrHDge','DMfSDwu','BgXTq29UzMLN','Aw52B2nHDgLVBL9LCNjVCG','ndKWoduZodHcDw14ww8','CNvU','CMf0Aw5NCW','CMvHC29U','CMv0CNLxAxrOtw9KzwWOksbPCYbZDxbWB3j0zwqGB25SEsbIEsbVBKXSBuvYCM9YkcKU','Dg9VBhm','yxbWBhLszwnVDMvYEq','AgfZq2fUzgLKyxrLq29UDgvUDa','zw50CMLLCW','B2jQzwn0','vgHLig1VzgvSihjLC3bVBNnLihDHCYbYzwPLy3rLzcbIEsbJAgvJA1jLC3bVBNnLkcKU','mJf2se9Jvgu','A2LUza','zw1WDhLszxnWB25ZzvjLy292zxj5','q29UDMvYC2f0Aw9Uigv4y2vLzgvKia','CgfYyw1Z','AgfUzgXLqMXVy2TLza','nM9nAvPbra','CMv0CNLxAxrOtw9KzwWOksbTyxKGyMuGCMv0DxjUzwqGB25SEsbVBMnLigLUigeGCMvJB3zLCNKGC2vXDwvUy2uU','Dg9VBf9JywXSCW','CMv0CMLLCW','y29UDgvUDa','y2XLyw51Ca','CMvMDxnHBa','zgvMAw5LuhjVCgvYDhK','BNvKz2u','DMfSAwrHDgvdB25MAwC','DgfYz2v0','CMvZCg9UC2vuzxH0','mJmXntaZognjExn4BW','y2fSBe9WDgLVBNm','AxnjBNrLz2vY','ywXSu2v0DgXLza','BwvZC2fNzxm','mtG2mdq4uwj1qvn0','Axntyw1LqMfYzvrYyw5ZAxrPB24','yMXVy2TLza','C3rVCf9KzxrHAwXZ','ChvZAa','BgXTr2f0zxDHEq','C3LZDgvTuhjVBxb0','C29Tzq','mJa2otC3nKDWvMrzvq','DhjPBq','qsb0B29SigjHDgnOihnLBgvJDgvKig1VCMuGDgHHBIbVBMuGDgvYBwLUywWGCMvZCg9UC2uGB3iGDhjHBNnPDgLVBI4','mZqYnZe0nurez3HoEq','ywrKAxrPB25HBf9RD2fYz3m','Bw9KzwW','y2XLyw51Cef0DgfJAg1LBNrZ','ntaWndqYwKjJz25w','otjPCKzlswS','C2LNBMfS','CMvZB2X2zunVBMzPzW','Aw1Hz2vFB3rOzxi','yMXVy2TFCMvHC29U','C3rYAw5NAwz5','Dg9VBc1JywXSlq','yMXVy2TszwfZB24','mZbvsNv3tfa','B3rOzxi','zw1WDhLFCMvZCg9UC2u','B25mBg1fCNjVCG'];u=function(){return wf;};return u();}function ye(l,R){const w9={l:0x14e,R:0x176,g:0x174,x:0x175},uN=ug;if(!l||typeof l!=uN(0x186))return null;const x=l,o=x[uN(w9.l)]??x[uN(0x14b)];if(typeof o!=uN(0x158)||!o[uN(0x140)]())return null;const d=x['safetyRatings']??x[uN(w9.R)];return{...R,'phase':uN(w9.g),'rawReason':o,'reason':S(o),...Array[uN(w9.x)](d)?{'safetyRatings':d}:{}};}s(ye,ug(0x164));function G(l){const wu={l:0x190,R:0x192,g:0x158},uh=ug;return l[uh(wu.l)]?.[uh(0x16d)]?!0x0:typeof l[uh(wu.R)]==uh(wu.g)?!!l['content'][uh(0x140)]():l[uh(wu.R)][uh(0x13e)](R=>typeof R[uh(0x153)]==uh(0x158)&&!!R[uh(0x153)][uh(0x140)]());}s(G,ug(0x184));async function Y(l){const ww={l:0x16f},uF=ug;try{await f(0x1f4,void 0x0,l?{'signal':l}:void 0x0);}catch(R){throw l?.[uF(ww.l)](),R;}}s(Y,'waitForRetry');export{H as DEFAULT_EMPTY_HISTORY_SEED,P as DEFAULT_EMPTY_RESPONSE_RECOVERY,ke as DEFAULT_LLM_POLICY,de as DEFAULT_MAX_AGENT_ROUNDS,le as EmptyModelResponseError,Me as LlmRunner,ue as assertEmptyResponseRetries,ce as assertMaxAgentRounds};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
var
|
|
1
|
+
var u=Object.defineProperty;var r=(o,t)=>u(o,"name",{value:t,configurable:!0});import{AsyncLocalStorage as x}from"node:async_hooks";import{messagesStateReducer as p}from"@langchain/langgraph";import{cloneJsonObject as c,readonlyContext as v}from"./graph-context.js";const a=new x;function S(o){return a.getStore()?.owner===o}r(S,"hasNodeInvocation");function b(o,t,e,n){return a.run({owner:o,nodeId:t,state:e,nodes:{},histories:{}},n)}r(b,"withNodeInvocation");function m(o){return s(o).nodeId}r(m,"invocationNodeId");function N(o){const t=s(o);return v(t.context??t.state.context??{})}r(N,"invocationContext");function j(o,t){const e=s(o),n=c(t,"Context patch");e.context={...c(e.context??e.state.context??{}),...n}}r(j,"saveInvocationContext");function O(o,t){s(o).context=c(t)}r(O,"replaceInvocationContext");function f(o,t){const e=s(o),n=e.nodes[t];return n?{...n}:{...(e.state.nodes??{})[t]??{}}}r(f,"invocationNodeState");function k(o,t,e){const n=f(o,t);for(const[i,d]of Object.entries(e))d===void 0?delete n[i]:n[i]=d;s(o).nodes[t]=n}r(k,"saveInvocationNodeState");function C(o,t,e){s(o).nodes[t]={...e}}r(C,"replaceInvocationNodeState");function w(o,t,e){const n=s(o);n.histories[t]=[...n.histories[t]??[],...e]}r(w,"appendInvocationHistory");function h(o,t){const e=s(o);return p(e.state.histories?.[t]??[],e.histories[t]??[])}r(h,"invocationHistory");function H(o){const t=s(o),e={...t.state.nodes??{}};for(const i of Object.keys(t.nodes))e[i]=f(o,i);const n={...t.state.histories??{}};for(const i of Object.keys(t.histories))n[i]=h(o,i);return{...t.state,nodes:e,histories:n,context:c(t.context??t.state.context??{})}}r(H,"invocationGraphState");function q(o){const t=s(o);return{...t.context!==void 0?{context:c(t.context)}:{},...Object.keys(t.nodes).length>0?{nodes:t.nodes}:{},...Object.keys(t.histories).length>0?{histories:t.histories}:{}}}r(q,"invocationUpdate");function s(o){const t=a.getStore();if(!t||t.owner!==o)throw new Error("Node state can only be accessed during an active graph-node invocation.");return t}r(s,"requireInvocation");export{w as appendInvocationHistory,S as hasNodeInvocation,N as invocationContext,H as invocationGraphState,h as invocationHistory,m as invocationNodeId,f as invocationNodeState,q as invocationUpdate,O as replaceInvocationContext,C as replaceInvocationNodeState,j as saveInvocationContext,k as saveInvocationNodeState,b as withNodeInvocation};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
const qu=l;(function(R,t){const k2={R:0x185,t:0x121,A:0x11f,r:0x18a,i:0x180,Y:0x172},qN=l,A=R();while(!![]){try{const r=parseInt(qN(0x182))/0x1+parseInt(qN(k2.R))/0x2+-parseInt(qN(k2.t))/0x3+-parseInt(qN(k2.A))/0x4*(-parseInt(qN(k2.r))/0x5)+-parseInt(qN(0x12c))/0x6*(parseInt(qN(0x157))/0x7)+parseInt(qN(k2.i))/0x8*(-parseInt(qN(k2.Y))/0x9)+-parseInt(qN(0x139))/0xa*(-parseInt(qN(0x145))/0xb);if(r===t)break;else A['push'](A['shift']());}catch(i){A['push'](A['shift']());}}}(d,0x2daed));var Z=Object[qu(0x19b)],c=(R,t)=>Z(R,qu(0x14e),{'value':t,'configurable':!0x0});import{mapChatMessagesToStoredMessages as e,mapStoredMessagesToChatMessages as B}from'@langchain/core/messages';import{BaseGraph as w}from'../base-graph.js';import{ConfigManager as K}from'../config-manager.js';import{GRAPH_END_NODE as D}from'../graph-state.js';import{GraphLlm as o}from'../graph-llm.config.js';import{replaceNodeStates as a}from'../node-state.js';import{createSessionLogs as u}from'../session-log.js';import{emptyTokenUsage as n,normalizeTokenUsage as m}from'../token-usage.js';import{assertGraphSchemaVersion as E}from'../stable-id.js';import{addDecisionUsage as s,emptyDecisionUsage as L,normalizeDecisionUsage as z}from'../decision/decision-types.js';const h=0x10,g=qu(0x166),P='SESSION_CONFLICT',_e=qu(0x1af);class f extends Error{static{c(this,qu(0x15a));}['code'];constructor(R,A){const k3={R:0x14e},qP=qu;super(A),this[qP(k3.R)]=qP(0x15a),this[qP(0x15e)]=R;}}class N{static{c(this,'SessionManager');}[qu(0x11d)];['turnLeaseMs'];constructor(R=new V(),A=G()){const k4={R:0x136},qn=qu;this['container']=R,this[qn(k4.R)]=A;}static async[qu(0x165)](q0=new K()){const k5={R:0x194,t:0x18f,A:0x17e,r:0x159,i:0x158,Y:0x126,H:0x19f,M:0x1b4,O:0x13e,b:0x18b,q0:0x1b9,q1:0x154,q2:0x178,q3:0x156,q4:0x163,q5:0x131,q6:0x19e,q7:0x142,q8:0x1ae,q9:0x140,qq:0x119,qk:0x15c,qd:0x13c,qG:0x14a,qT:0x125,qy:0x191,ql:0x187,qe:0x193,qX:0x1bf,qv:0x118,qB:0x1bc,qw:0x155,qK:0x197},qm=qu,q1=q0[qm(0x125)](qm(0x186),'memory')[qm(0x1a9)]()[qm(0x146)](),q2=G(q0[qm(0x125)](qm(k5.R)));if(q1===qm(0x15f))return new N(new V(),q2);if(q1===qm(k5.t)){const {SqliteSessionDocumentContainer:qv}=await import('./sqlite-session-document.container.js');return new N(new qv(q0['get'](qm(k5.A),qm(0x16f))),q2);}if(q1===qm(0x1b4)||q1==='mongo'){const qB=p(q0,qm(k5.r)),qw=p(q0,qm(k5.i)),qK=p(q0,qm(0x190));if(!qB||!qw||!qK)throw new Error(qm(k5.Y));const [{MongoClient:qj},{MongoDbSessionDocumentContainer:qD}]=await Promise[qm(k5.H)]([import(qm(k5.M)),import('./mongodb-session-document.container.js')]),qo=new qj(qB);await qo['connect']();const qa=qo['db'](qw)[qm(k5.O)](qK);return await qa[qm(k5.b)]({'id':0x1},{'unique':!0x0}),new N(new qD(qa,qo),q2);}if(q1!==qm(0x181)&&q1!==qm(0x148))throw new Error('Unsupported\x20SESSION_STORE\x20\x27'+q1+qm(0x128));const q3=p(q0,qm(k5.q0),qm(k5.q1),qm(k5.q2)),q4=p(q0,qm(k5.q3),qm(k5.q4)),q5=p(q0,qm(k5.q5)),q6=p(q0,qm(k5.q6)),q7=p(q0,qm(k5.q7)),q8=p(q0,qm(k5.q8),'COSMOS_DATABASE',qm(k5.q9))??qm(k5.qq),q9=p(q0,qm(0x14b),'COSMOS_CONTAINER',qm(0x1b1))??qm(0x13a);if(!q3||!q4&&(!q5||!q6||!q7))throw new Error(qm(0x1b5));const [{CosmosClient:qq},{ClientSecretCredential:qk}]=await Promise[qm(0x19f)]([import(qm(k5.qk)),import(qm(0x18c))]),qd=q4?new qq({'endpoint':q3,'key':q4}):new qq({'endpoint':q3,'aadCredentials':new qk(q5,q6,q7)}),{database:qG}=await qd[qm(k5.qd)][qm(k5.qG)]({'id':q8}),qT=Number(q0[qm(k5.qT)](qm(k5.qy),qm(0x141))),{container:qy}=await qG['containers'][qm(0x14a)]({'id':q9,'partitionKey':{'paths':[qm(k5.ql)]},...Number[qm(0x116)](qT)&&qT>0x0?{'throughput':qT}:{}}),{resource:ql}=await qy[qm(k5.qe)](),qe=ql?.[qm(k5.qX)]?.[qm(k5.qv)]??[];if(!qe[qm(k5.qB)](qm(k5.ql)))throw new Error('Cosmos\x20container\x20\x27'+q9+'\x27\x20must\x20use\x20partition\x20key\x20/id;\x20found\x20'+(qe[qm(k5.qw)](',\x20')||qm(k5.qK))+'.');const {CosmosSessionDocumentContainer:qX}=await import('./cosmos-session-document.container.js');return new N(new qX(qy,()=>qd[qm(0x15b)]()),q2);}async[qu(0x12b)](R){const k6={R:0x188},qV=qu,A=await this[qV(0x167)](R);return A?.[qV(k6.R)]===h?A:void 0x0;}async['readDocument'](R){const k7={R:0x11d},qE=qu;try{const {resource:A}=await this[qE(k7.R)]['item'](R,R)[qE(0x193)]();return A;}catch(r){if(j(r))return;throw r;}}async[qu(0x16c)](R,A,Y){const k8={R:0x134,t:0x167,A:0x136,r:0x13b,i:0x16a,Y:0x13f,H:0x151,M:0x124,O:0x11d,b:0x16a,q0:0x1ad,q1:0x11e,q2:0x1be,q3:0x170},qC=qu,H=w[qC(0x16b)](Y[qC(0x1c0)]),M=E(Y[qC(k8.R)]),O=await this[qC(k8.t)](R);O&&O['version']===h&&T(O,H);const b=new Date(),q0={'owner':A,'expiresAt':new Date(b[qC(0x152)]()+this[qC(k8.A)])['toISOString']()};if(!O){const q2=this[qC(k8.r)](R,Y,H,M,q0,b[qC(0x124)]());if(await this['container'][qC(0x1be)]({'expectedRevision':null},q2)===qC(0x170))throw new f(g,qC(k8.i)+R+qC(k8.Y));return{'kind':qC(k8.H),'document':q2,'expectedRevision':q2['revision']};}if(O['version']!==h){const q3=this[qC(0x13b)](R,Y,H,M,q0,b[qC(k8.M)]());if(await this[qC(k8.O)][qC(0x1be)]({'expectedRevision':S(O),'replaceIncompatible':!0x0},q3)===qC(0x170))throw new f(g,qC(k8.b)+R+'\x27\x20is\x20already\x20processing\x20a\x20turn.');return{'kind':'leased','document':q3,'expectedRevision':q3[qC(k8.q0)]};}if(F(O['turn'])&&O[qC(0x184)]?.[qC(k8.q1)]!==A)throw new f(g,qC(0x16a)+R+qC(0x13f));const q1={...O,'revision':S(O)+0x1,'turn':q0};if(await this['container'][qC(k8.q2)]({'expectedRevision':S(O),'requireFreeLease':!0x0,'allowOwner':A},q1)===qC(k8.q3))throw new f(g,qC(0x16a)+R+qC(k8.Y));return{'kind':qC(0x151),'document':q1,'expectedRevision':S(q1)};}async[qu(0x162)](R,A){const i=await this['getSession'](R);if(i)return this['restoreSessionDocument'](i,A);}[qu(0x150)](R,A){const kq={R:0x16b,t:0x18e,A:0x14c,r:0x171},qp=qu,Y=w[qp(kq.R)](A);T(R,Y);const {graph:H}=R;if(!H[qp(0x196)])return;const M=a({},H[qp(0x196)]),O=se(H[qp(kq.t)]);return{'currentNode':H['currentNode'],'config':H[qp(0x135)]??{},'completed':R[qp(kq.A)]==='completed'||H[qp(0x1b3)]===D,'nodes':M,'tokens':m(R[qp(0x11c)]),'decisionUsage':z(R[qp(kq.r)]),'histories':O,'inputConsumed':!0x0,'response':''};}async[qu(0x12f)](R,A,Y,H=u(),M={}){const kk={R:0x167,t:0x124,A:0x196,r:0x192,i:0x117,Y:0x11b,H:0x17d,M:0x183,O:0x184,b:0x129,q0:0x11d,q1:0x1be,q2:0x18d,q3:0x170,q4:0x16a,q5:0x13f},qJ=qu,b=w[qJ(0x16b)](Y[qJ(0x1c0)]),q0=E(Y['graphSchemaVersion']),q1=await this[qJ(kk.R)](R),q2=q1?.['version']===h?q1:void 0x0;q2&&(T(q2,b),q(q2,q0));const q3=new Date()[qJ(kk.t)](),q4=ne(a({},A[qJ(kk.A)])),{tokens:q5,histories:q6}=A,q7=this[qJ(kk.r)](q1,M),q8={'version':h,'id':R,'revision':q7===null?0x0:q7+0x1,'status':A[qJ(0x176)]?qJ(0x176):qJ(kk.i),'tokens':m(q5),'decisionUsage':z(A['decisionUsage']),'errors':[...q2?.[qJ(0x160)]??[],...H[qJ(0x160)]],'warnings':[...q2?.[qJ(kk.Y)]??[],...H[qJ(0x11b)]],'decisions':[...q2?.[qJ(0x16e)]??[],...H['decisions']],'graph':{'id':b,'schemaVersion':q0,'currentNode':A[qJ(0x1b3)],'config':A[qJ(0x135)],'histories':ie(q6),'model':o[qJ(kk.H)](Y[qJ(kk.M)]),'nodes':q4},...M[qJ(0x195)]&&q2?.[qJ(kk.O)]?{'turn':{'owner':q2['turn'][qJ(0x11e)],'expiresAt':new Date(Date[qJ(kk.b)]()+this['turnLeaseMs'])[qJ(0x124)]()}}:{},'createdAt':q2?.['createdAt']??q3,'modifiedAt':q3};if(await this[qJ(kk.q0)][qJ(kk.q1)](this[qJ(kk.q2)](q1,M,q7),q8)===qJ(kk.q3))throw new f(M['owner']?P:g,M[qJ(0x11e)]?qJ(0x16a)+R+qJ(0x1ba):qJ(kk.q4)+R+qJ(kk.q5));return q8;}async['appendLogs'](R,A,Y,H={}){const kd={R:0x16b,t:0x14c,A:0x171,r:0x160,i:0x11b,Y:0x143,H:0x18e,M:0x183,O:0x143,b:0x196,q0:0x1a5,q1:0x11d,q2:0x1be,q3:0x170,q4:0x123,q5:0x16a,q6:0x15d,q7:0x16a},qs=qu,M=w[qs(kd.R)](Y['graphId']),O=E(Y[qs(0x134)]),b=await this[qs(0x12b)](R);b&&(T(b,M),q(b,O));const q0=new Date()[qs(0x124)](),q1=this['commitExpectedRevision'](b,H),q2={'version':h,'id':R,'revision':q1===null?0x0:q1+0x1,'status':A['errors'][qs(0x15d)]>0x0?qs(0x122):b?.[qs(kd.t)]??qs(0x117),'tokens':b?.[qs(0x11c)]??n(),'decisionUsage':A[qs(0x16e)][qs(0x19d)]((q3,q4)=>s(q3,q4['usage']),z(b?.[qs(kd.A)])),'errors':[...b?.[qs(0x160)]??[],...A[qs(kd.r)]],'warnings':[...b?.['warnings']??[],...A[qs(kd.i)]],'decisions':[...b?.['decisions']??[],...A['decisions']],'graph':{'id':M,'schemaVersion':O,...b?{'currentNode':b[qs(0x143)]['currentNode'],'config':b[qs(kd.Y)]['config']}:{},'histories':b?.[qs(0x143)][qs(kd.H)]??{},'model':o['modelMetadata'](Y[qs(kd.M)]),...b?.[qs(kd.Y)]['nodes']?{'nodes':b[qs(kd.O)][qs(kd.b)]}:{}},'createdAt':b?.[qs(kd.q0)]??q0,'modifiedAt':q0};if(await this[qs(kd.q1)][qs(kd.q2)](this[qs(0x18d)](b,H,q1),q2)===qs(kd.q3)){if(H[qs(0x11e)]){console[qs(kd.q4)](qs(kd.q5)+R+qs(0x1a6)+A[qs(0x160)][qs(kd.q6)]+qs(0x175)+A[qs(0x11b)][qs(kd.q6)]+'\x20warning(s)\x20were\x20dropped.');return;}throw new f(g,qs(kd.q7)+R+qs(0x13f));}return q2;}async[qu(0x1c1)](R,A,Y,H,M){const qL=qu;if(H&&(H[qL(0x160)]['length']>0x0||H['warnings'][qL(0x15d)]>0x0||H[qL(0x16e)][qL(0x15d)]>0x0)){await this[qL(0x17c)](R,H,Y,{'owner':A,...M!==void 0x0?{'expectedRevision':M}:{}});return;}await this[qL(0x1a2)](R,A,M);}async[qu(0x1a2)](R,A,Y){const kT={R:0x184},qz=qu,H=await this[qz(0x12b)](R);if(!H||H[qz(kT.R)]?.[qz(0x11e)]!==A)return;const M=Y??S(H),{turn:O,...b}=H,q0={...b,'modifiedAt':new Date()[qz(0x124)]()};await this['container'][qz(0x1be)]({'expectedRevision':M,'requireOwner':A},q0);}async[qu(0x16d)](R){const ky={R:0x1bd,t:0x1a1},qR=qu;try{await this[qR(0x11d)][qR(ky.R)](R,R)[qR(ky.t)]();}catch(A){if(!j(A))throw A;}}async['persistMigratedSession'](R,A={}){const kl={R:0x188,t:0x1b8,A:0x16b,r:0x12b,i:0x184,Y:0x1a5,H:0x11d,M:0x1be,O:0x11e,b:0x11e},qc=qu;if(R[qc(kl.R)]!==h)throw new Error(qc(kl.t)+R[qc(kl.R)]+qc(0x17b)+h+'.');w[qc(kl.A)](R[qc(0x143)]['id']),E(R[qc(0x143)][qc(0x153)]);const Y=await this[qc(kl.r)](R['id']),H=A['expectedRevision']??S(Y||R),M=Y?.[qc(kl.i)]??R[qc(0x184)],O={...R,'revision':H,'createdAt':Y?.[qc(kl.Y)]??R[qc(0x1a5)],'modifiedAt':Y?.['modifiedAt']??R['modifiedAt'],...M?{'turn':M}:{}};if(await this[qc(kl.H)][qc(kl.M)]({'expectedRevision':H,...A[qc(kl.O)]?{'requireOwner':A[qc(0x11e)]}:{'requireFreeLease':!0x0}},O)===qc(0x170))throw new f(A[qc(kl.b)]?P:g,qc(0x16a)+R['id']+'\x27\x20changed\x20before\x20its\x20migration\x20could\x20be\x20saved.');}async[qu(0x1b0)](){await this['container']['close']?.();}['placeholderDocument'](R,A,Y,H,M,O){const kX={R:0x117},qg=qu;return{'version':h,'id':R,'revision':0x0,'status':qg(kX.R),'tokens':n(),'decisionUsage':L(),'errors':[],'warnings':[],'decisions':[],'graph':{'id':Y,'schemaVersion':H,'histories':{},'model':o['modelMetadata'](A[qg(0x183)])},'turn':M,'createdAt':O,'modifiedAt':O};}['commitExpectedRevision'](R,A){const qt=qu;return A[qt(0x1ac)]!==void 0x0?A[qt(0x1ac)]:R?S(R):null;}[qu(0x18d)](R,A,i){const kB={R:0x188},qA=qu;return A[qA(0x11e)]?{'expectedRevision':i,'requireOwner':A[qA(0x11e)]}:R&&R[qA(kB.R)]!==h?{'expectedRevision':i,'replaceIncompatible':!0x0}:{'expectedRevision':i,'requireFreeLease':!0x0};}}function p(R,...A){for(const i of A){const Y=R['get'](i);if(Y)return Y;}}c(p,qu(0x127));function T(R,t){const kK={R:0x189},qr=qu;if(R[qr(0x143)]['id']!==t)throw new Error(qr(0x16a)+R['id']+qr(0x169)+R[qr(0x143)]['id']+qr(kK.R)+t+qr(0x12d));}c(T,qu(0x19a));function d(){const kt=['qgf6DxjLl2LKzw50Axr5','y29TBwL0uhjLzgLJyxrL','AgLZDg9YAwvZ','C3fSAxrL','tu9or09eqL9dt0Xmrunusu9o','q09ttu9tx1riuK9vr0Hqvvq','y29TBwL0rxHWzwn0zwrszxzPC2LVBG','CMvHza','u0vtu0LptL9uvvjox0Xfqvnfx01t','A2vLCfr1CM4','BM9Kzxm','BM9Uzq','lcbUB3qG','CMvZCg9UC2vFBwv0ywrHDge','yxnZzxj0u2vZC2LVBKDYyxbO','zgvMAw5LuhjVCgvYDhK','zxPNCMfWAeLUDgvYBMfS','CMvKDwnL','q09ttu9FrejFq0Xjru5ux0Le','ywXS','BwfW','zgvSzxrL','CMvSzwfZzvr1CM4','C3rVCMviAxn0B3jPzxm','CMvTB3zLtgvNywn5vg9VBfrYywnLCW','y3jLyxrLzef0','jYbSB3n0igL0CYbSzwfZzsbIzwzVCMuGBg9NCYb3zxjLigfWCgvUzgvKoYa','yxnZAwDU','DxbZzxj0','DhjPBq','jYbZy2HLBweGDMvYC2LVBIa','CgfYC2u','zxHWzwn0zwrszxzPC2LVBG','CMv2AxnPB24','q09ttu9FrejFsuq','u0vtu0LptL9dt01qtevuruq','y2XVC2u','q09ttu9eqL9trvntsu9ox0Le','B2jQzwn0','y3vYCMvUDe5Vzgu','Bw9Uz29KyG','q29ZBw9ZihnLC3nPB24GCgvYC2LZDgvUy2uGCMvXDwLYzxmGq09ttu9eqL9vuKWGyw5Kienpu01prejFs0vzlcbVCIbdt1nnt19ftKrqt0LovcWGqvPvuKvFvevoqu5ux0Lelcbdt1nnt19eqL9dteLftLrFsuqSigfUzcbdt1nnt19eqL9dteLftLrFu0vduKvulG','AxnbCNjHEq','Dgv4Da','q2fUBM90ihbLCNnPC3qGC2vZC2LVBIbKB2n1BwvUDcb2zxjZAw9Uia','q09ttu9Fru5eue9jtLq','jYbJAgfUz2vKigjLzM9Yzsb0AgLZihr1CM4Gy291BgqGyMuGC2f2zwqU','zg9JDw1LBNrZ','Aw5JBhvKzxm','AxrLBq','y29TCgfYzufUzfn3yxa','CgfYDgL0Aw9Us2v5','z3jHCgHjza','zw5KrMfPBgvKvhvYBG','lIbszxn0B3jLig9Yig1Pz3jHDguGAxqGyMvMB3jLihnHDMLUzY4','AxngAw5PDgu','Aw5FChjVz3jLC3m','Cgf0Ahm','BgfUz2DYyxbO','zNjVBuvUDhjPzxm','D2fYBMLUz3m','Dg9Rzw5Z','y29UDgfPBMvY','B3DUzxi','mtm5odq0B1nVq1Lf','tM90igzVDw5K','otGWmZCZALHLvKzt','zxjYB3i','D2fYBG','Dg9ju09tDhjPBMC','z2v0','tw9Uz29eqIbZzxnZAw9UihbLCNnPC3rLBMnLihjLCxvPCMvZie1ptKDprejFvvjmlcbnt05ht0rcx05btuuSigfUzcbnt05ht0rcx0npteXfq1rjt04U','zMLYC3q','jY4GvxnLicDTzw1VCNKNlcaNC3fSAxrLjYWGj21VBMDVzgiNlcbVCIaNy29ZBw9ZjY4','BM93','C2LNBMf0DxjLqMvHCMLUz0nVBNrLBNrcBg9JAW','z2v0u2vZC2LVBG','nLfhD2fPBW','jY4Gu3rHCNqGysbUzxCGC2vZC2LVBIb0BYbYDw4GysbKAwzMzxjLBNqGz3jHCgGU','DxnHz2vFBwv0ywrHDge','C2f2zvn0yxrL','CMvXDwLYzu93BMvY','qvPvuKvFvevoqu5ux0Le','y29TCgfJDfn0B3jLze1LC3nHz2vZ','twvTB3j5u2vZC2LVBKrVy3vTzw50q29UDgfPBMvY','z3jHCgHty2HLBwfwzxjZAw9U','y29UzMLN','DhvYBKXLyxnLtxm','CMvWBgfJzuLUy29TCgf0AwjSzq','Aw52ywXPzf90B29Sx2nHBgXZ','mtbnBKDXvey','C2vZC2LVBNm','CgXHy2vOB2XKzxjeB2n1BwvUDa','zgf0ywjHC2vZ','AxnmAxzLu2vZC2LVBLr1CM4','y29SBgvJDgLVBG','jYbPCYbHBhjLywr5ihbYB2nLC3nPBMCGysb0DxjUlG','q09ttu9eqL9jra','ndaW','q09ttu9FrejFq0Xjru5ux1nfq1jfva','z3jHCgG','C2L6zq','ntm2nJCXm0vksejuvq','Dg9mB3DLCKnHC2u','ywXSB3DpD25LCG','y29ZBw9Zzgi','C2v0','y3jLyxrLswzoB3rfEgLZDhm','q09ttu9FrejFu0vtu0LptL9dt05uquLorvjFsuq','C3rHDhvZ','nJaWmda','BMfTzq','DgHVDwDODa','CMvZDg9YzvnLC3nPB25eB2n1BwvUDa','BgvHC2vK','z2v0vgLTzq','C2nOzw1HvMvYC2LVBG','q09ttu9tx0vorfbpsu5u','AM9PBG','q09ttu9eqL9lrvK','mtGZnJy5nuzxzK5KuW','tu9or09eqL9oqu1f','tu9or09eqL9vuKW','u2vZC2LVBLr1CM5fCNjVCG','zgLZCg9Zzq','qgf6DxjLl2nVC21VCW','BgvUz3rO','y29Kzq','BwvTB3j5','zxjYB3jZ','DhLWzq','CMvZDg9Yzvn0yxrL','q09ttu9tx0Tfwq','DgHVDwDODfnPz25HDhvYzq','zNjVBunVBMzPzW','u0vtu0LptL9cvvnz','CMvHzerVy3vTzw50','zw50CMLLCW','jYbIzwXVBMDZihrVigDYyxbOicC','u2vZC2LVBIaN','yxnZzxj0swq','yMvNAw5uDxjU','zgvSzxrLu2vZC2LVBG','zgvJAxnPB25Z','lI9KyxrHl3nLC3nPB25ZlNnXBgL0zq','y29UzMXPy3q','zgvJAxnPB25vC2fNzq','ovnzEgPoAq','Dg9VBf9JywXSCW','AxnoB3rgB3vUza','igvYCM9YkhmPigfUzca','y29TCgXLDgvK','zxHWAxjLC0f0','q09ttu9eqL9vuKW','AxrLBxm','AxnszwnVCMq','oYbLEhbLy3rLzca','yxbWzw5Ktg9NCW','Bw9KzwXnzxrHzgf0yq','u1fmsvrfx0rcx1bbveG','ywrKAxrPB25HBf9RD2fYz3m','mZK4ntm2ExffzunM','y29ZBw9Z','odm2nJrfu2vZDfO','BgXTq29UzMLN','DhvYBG','mtu5nte2Ag1Tq1H1','u0vtu0LptL9tve9srq','l2LK','DMvYC2LVBG','jYWGBM90icC','mJvkzNrVENa','y3jLyxrLsw5KzxG'];d=function(){return kt;};return d();}function q(R,t){const kj={R:0x143,t:0x16a,A:0x1aa,r:0x153,i:0x1c2},qf=qu;if(R[qf(kj.R)]['schemaVersion']!==t)throw new Error(qf(kj.t)+R['id']+'\x27\x20uses\x20graph\x20\x27'+R[qf(0x143)]['id']+qf(kj.A)+R['graph'][qf(kj.r)]+qf(0x198)+t+qf(kj.i));}function l(q,k){q=q-0x116;const G=d();let T=G[q];if(l['iLIAun']===undefined){var y=function(B){const w='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+/=';let K='',j='';for(let D=0x0,o,a,N=0x0;a=B['charAt'](N++);~a&&(o=D%0x4?o*0x40+a:a,D++%0x4)?K+=String['fromCharCode'](0xff&o>>(-0x2*D&0x6)):0x0){a=w['indexOf'](a);}for(let u=0x0,P=K['length'];u<P;u++){j+='%'+('00'+K['charCodeAt'](u)['toString'](0x10))['slice'](-0x2);}return decodeURIComponent(j);};l['NebsVu']=y,l['KBVcIO']={},l['iLIAun']=!![];}const e=G[0x0],X=q+e,v=l['KBVcIO'][X];return!v?(T=l['NebsVu'](T),l['KBVcIO'][X]=T):T=v,T;}c(q,'assertSessionGraphSchema');function ne(R){const ko={R:0x11a,t:0x1a0},kD={R:0x1b2},qi=qu;return Object[qi(ko.R)](Object[qi(0x168)](R)[qi(ko.t)](([A,i])=>{const qh=qi;if(!i||typeof i!=qh(kD.R))return[A,i];const {toolTrace:Y,...H}=i;return[A,H];}));}c(ne,qu(0x1a4));function oe(R){const ka={R:0x17f,t:0x19c,A:0x199,r:0x12e,i:0x161,Y:0x173,H:0x173,M:0x15d,O:0x1b6,b:0x138,q0:0x138};return R['map'](A=>{const qQ=l,r={...A['data']},Y=A[qQ(0x161)]==='ai'&&Array['isArray'](r[qQ(0x173)])&&r['tool_calls'][qQ(0x15d)]>0x0?ae(r['additional_kwargs']):void 0x0,H=v(r[qQ(0x17f)])&&r[qQ(ka.R)][qQ(ka.t)]===!0x0;return delete r['additional_kwargs'],(Y||H)&&(r[qQ(ka.R)]={...Y?{'originalTextContentBlock':Y}:{},...H?{'ezgraphInternal':!0x0}:{}}),delete r[qQ(ka.A)],delete r[qQ(ka.r)],A[qQ(ka.i)]==='ai'&&(Array[qQ(0x1b6)](r[qQ(ka.Y)])&&r[qQ(ka.H)][qQ(ka.M)]===0x0&&delete r['tool_calls'],Array[qQ(ka.O)](r['invalid_tool_calls'])&&r[qQ(ka.b)]['length']===0x0&&delete r[qQ(ka.q0)]),{...A,'data':r};});}c(oe,qu(0x132));function ie(R){const qZ=qu;return Object[qZ(0x11a)](Object['entries'](R)[qZ(0x1a0)](([A,r])=>[A,oe(e(r))]));}c(ie,qu(0x1a3));function se(R={}){const kP={R:0x168},qY=qu;return Object[qY(0x11a)](Object[qY(kP.R)](R)[qY(0x1a0)](([A,r])=>[A,B(r)]));}c(se,'restoreHistories');function ae(R){const kn={R:0x164,t:0x164,A:0x14f},qH=qu;if(!v(R))return;const t=R['originalTextContentBlock'];if(!(!v(t)||typeof t[qH(kn.R)]!='string'))return{...typeof t[qH(0x1b7)]=='string'?{'text':t['text']}:{},'thoughtSignature':t[qH(kn.t)],...t[qH(kn.A)]===!0x0?{'thought':!0x0}:{}};}c(ae,qu(0x12a));function v(R){const km={R:0x1b6},qW=qu;return R!==null&&typeof R==qW(0x1b2)&&!Array[qW(km.R)](R);}c(v,qu(0x17a));class V{static{c(this,qu(0x133));}[qu(0x1bb)]=new Map();get[qu(0x144)](){const qM=qu;return this[qM(0x1bb)]['size'];}[qu(0x179)]={'upsert':c(async e=>{const kE={R:0x1bb},qx=qu,t=e;return this[qx(kE.R)]['set'](t['id'],structuredClone(t)),{};},qu(0x1a8))};async[qu(0x1be)](R,A){const kC={R:0x125,t:0x170},qU=qu,i=this['documents'][qU(kC.R)](A['id']);return ce(i,R)?(this[qU(0x1bb)][qU(0x149)](A['id'],structuredClone(A)),'ok'):qU(kC.t);}['item'](R,A){const kJ={R:0x1bb,t:0x1a1},kp={R:0x125},qF=qu;return{'read':c(async()=>{const qO=l,i=this['documents'][qO(kp.R)](R);if(!i||i['id']!==A)throw Object[qO(0x1a7)](new Error(qO(0x120)),{'code':0x194});return{'resource':structuredClone(i)};},qF(0x193)),'delete':c(async()=>{const qS=qF,i=this[qS(kJ.R)][qS(0x125)](R);if(!i||i['id']!==A)throw Object['assign'](new Error(qS(0x120)),{'code':0x194});return this[qS(0x1bb)][qS(kJ.t)](R),{};},qF(0x1a1))};}}function j(R){const kL={R:0x1b2,t:0x15e},qb=qu;if(!R||typeof R!=qb(kL.R))return!0x1;const t=R;return t[qb(kL.t)]===0x194||t['statusCode']===0x194;}c(j,qu(0x174));function G(R=process.env.SESSION_TURN_LEASE_MS){const qI=qu,t=Number(R??qI(0x14d));return Number[qI(0x116)](t)&&t>0x0?t:0xea60;}c(G,'sessionTurnLeaseMs');function S(R){return R?.['revision']??0x0;}c(S,'sessionRevision');function F(R,A=Date[qu(0x129)]()){const kc={R:0x177,t:0x116},k0=qu;if(!R?.[k0(0x11e)]||!R[k0(0x177)])return!0x1;const r=Date[k0(0x1ab)](R[k0(kc.R)]);return Number[k0(kc.t)](r)&&r>A;}c(F,qu(0x13d));function ce(R,A,r=Date[qu(0x129)]()){const kg={R:0x1ac,t:0x130},k1=qu;return A[k1(0x137)]?R!==void 0x0&&R[k1(0x188)]!==h:A[k1(kg.R)]===null?R===void 0x0:!(!R||S(R)!==A['expectedRevision']||A[k1(kg.t)]&&R[k1(0x184)]?.[k1(0x11e)]!==A['requireOwner']||A['requireFreeLease']&&F(R[k1(0x184)],r)&&R['turn']?.['owner']!==A[k1(0x147)]);}c(ce,'matchesSessionWritePredicate');export{V as MemorySessionDocumentContainer,g as SESSION_BUSY,_e as SESSION_COMPLETED,P as SESSION_CONFLICT,h as SESSION_DOCUMENT_VERSION,N as SessionManager,f as SessionTurnError,F as isLiveSessionTurn,ce as matchesSessionWritePredicate,S as sessionRevision,G as sessionTurnLeaseMs};
|
|
1
|
+
const ut=w;(function(d,n){const w5={d:0xad,n:0xfd,r:0x125,H:0xa6,E:0xce,z:0xe8},up=w,r=d();while(!![]){try{const H=-parseInt(up(w5.d))/0x1*(-parseInt(up(0x10b))/0x2)+-parseInt(up(w5.n))/0x3+-parseInt(up(w5.r))/0x4*(parseInt(up(0xdc))/0x5)+-parseInt(up(w5.H))/0x6*(parseInt(up(0xd6))/0x7)+-parseInt(up(0x122))/0x8+parseInt(up(w5.E))/0x9*(parseInt(up(w5.z))/0xa)+parseInt(up(0x99))/0xb*(parseInt(up(0xa8))/0xc);if(H===n)break;else r['push'](r['shift']());}catch(E){r['push'](r['shift']());}}}(u,0x27bd1));var J=Object[ut(0xc6)],c=(d,n)=>J(d,ut(0xc9),{'value':n,'configurable':!0x0});import{mapChatMessagesToStoredMessages as k,mapStoredMessagesToChatMessages as O}from'@langchain/core/messages';import{BaseGraph as Y}from'../base-graph.js';function u(){const wn=['CMvSzwfZzvr1CM4','DhjPBq','DgHVDwDODfnPz25HDhvYzq','y3vYCMvUDe5Vzgu','ndaW','Dg9ju09tDhjPBMC','Bw9Uz29KyG','jYbJAgfUz2vKigjLzM9Yzsb0AgLZihr1CM4Gy291BgqGyMuGC2f2zwqU','C3rVCMviAxn0B3jPzxm','AgLZDg9YAwvZ','mtyXmtq0nhLWs1DLEq','q09ttu9eqL9jra','mZm2mJG5mMTtveTHDq','CMvZDg9YzuHPC3rVCMLLCW','zxjYB3i','Dg9Rzw5Z','CMvHza','ntK0nJHzwhrsu2u','lIbszxn0B3jLig9Yig1Pz3jHDguGAxqGyMvMB3jLihnHDMLUzY4','q09ttu9FrejFq0Xjru5ux1nfq1jfva','u1fmsvrfx0rcx1bbveG','zgf0yq','CMv2AxnPB24','q29ZBw9ZihnLC3nPB24GCgvYC2LZDgvUy2uGCMvXDwLYzxmGq09ttu9eqL9vuKWGyw5Kienpu01prejFs0vzlcbVCIbdt1nnt19ftKrqt0LovcWGqvPvuKvFvevoqu5ux0Lelcbdt1nnt19eqL9dteLftLrFsuqSigfUzcbdt1nnt19eqL9dteLftLrFu0vduKvulG','y29Kzq','AxnmAxzLu2vZC2LVBLr1CM4','jYbZy2HLBweGDMvYC2LVBIa','zxHWAxjLC0f0','jYbJAgfUz2vKigjLzM9YzsbPDhmGBwLNCMf0Aw9UignVDwXKigjLihnHDMvKlG','twvTB3j5u2vZC2LVBKrVy3vTzw50q29UDgfPBMvY','DgHVDwDODa','u2vZC2LVBIaN','DhLWzq','lI9JB3nTB3mTC2vZC2LVBI1KB2n1BwvUDc5JB250ywLUzxiUANm','C3fSAxrL','AxrLBxm','zNjVBuvUDhjPzxm','yxnZAwDU','u0vtu0LptL9dt05gteLdva','oYbLEhbLy3rLzca','y29TBwL0rxHWzwn0zwrszxzPC2LVBG','q09ttu9tx0nptLrbsu5fuG','zgvMAw5LuhjVCgvYDhK','C3rYAw5N','CMvKDwnL','BMfTzq','yxnZzxj0swq','jYbPCYbHBhjLywr5ihbYB2nLC3nPBMCGysb0DxjUlG','CgfYC2u','D2fYBMLUz3m','nte4nerotgHcBq','CMvZCg9UC2vFBwv0ywrHDge','CMvXDwLYzuzYzwvmzwfZzq','zxPNCMfWAeLUDgvYBMfS','zw50CMLLCW','CgXHy2vOB2XKzxjeB2n1BwvUDa','y29UzMXPy3q','q09ttu9tx1riuK9vr0Hqvvq','n29TvvLjwG','q09ttu9eqL9trvntsu9ox0Le','qgf6DxjLl2nVC21VCW','C2f2zvn0yxrL','Aw5JBhvKzxm','tu9or09eqL9vuKW','nw92sfz6uW','qgf6DxjLl2LKzw50Axr5','yxnZzxj0u2vZC2LVBKDYyxbOu2nOzw1H','DhvYBG','zxjYB3jZ','lI9KyxrHl3nLC3nPB25ZlNnXBgL0zq','z3jHCgHty2HLBwfwzxjZAw9U','ihDHCM5PBMCOCYKGD2vYzsbKCM9WCgvKlG','zgf0ywjHC2vZ','ywrKAxrPB25HBf9RD2fYz3m','C2vZC2LVBLr1CM5mzwfZzu1Z','y29UDgfPBMvY','nti5meD6twLVAa','ywXS','lcbUB3qG','C2nOzw1HvMvYC2LVBG','BgfUz2DYyxbO','u0vtu0LptL9cvvnz','yxbWzw5Ktg9NCW','AxnbCNjHEq','jYbSB3n0igL0CYbSzwfZzsbIzwzVCMuGBg9NCYb3zxjLigfWCgvUzgvKoYa','C2LNBMf0DxjLqMvHCMLUz0nVBNrLBNrcBg9JAW','CMvXDwLYzu93BMvY','BgXTq29UzMLN','yxnZzxj0u2vZC2LVBKDYyxbO','l2LK','Bw9KAwzPzwrbDa','DxnHz2vFBwv0ywrHDge','zNjVBunVBMzPzW','Aw52ywXPzf90B29Sx2nHBgXZ','u2vZC2LVBLr1CM5fCNjVCG','jYb1C2vZigDYyxbOicC','y29TCgXLDgvK','mtC4otKYA3HSq3bk','jYbIzwXVBMDZihrVigDYyxbOicC','BgvHC2vK','q2fUBM90ihbLCNnPC3qGC2vZC2LVBIbKB2n1BwvUDcb2zxjZAw9Uia','DMvYC2LVBG','CMvZDg9YzvnLC3nPB25eB2n1BwvUDa','DhvYBKXLyxnLtxm','AxnszwnVCMq','zg9JDw1LBNrZ','q09ttu9eqL9lrvK','zMLYC3q','yMvNAw5uDxjU','y3jLyxrLswzoB3rfEgLZDhm','y29ZBw9Z','nNPfDeHQwa','CMvWBgfJzuLUy29TCgf0AwjSzq','B3jPz2LUywXuzxH0q29UDgvUDejSB2nR','C2v0','Bw9KzwXnzxrHzgf0yq','y29ZBw9Zzgi','Dg9VBf9JywXSCW','q09ttu9FrejFq0Xjru5ux0Le','zxHWzwn0zwrszxzPC2LVBG','y29UDgv4Da','y29UBMvJDa','C2vZC2LVBNm','CMvHzerVy3vTzw50','nJaWmda','z2v0','Cgf0Ahm','tM90igzVDw5K','zgvJAxnPB25Z','z3jHCgHjza','BwfW','C3rHDhvZ','zgvSzxrLu2vZC2LVBG','B2jQzwn0','mZu4mtuYsvfetg9P','z2v0vgLTzq','DxbZzxj0','oteWmJKYBNjPz0fp','zgLZCg9Zzq','jY4GvxnLicDTzw1VCNKNlcaNC3fSAxrLjYWGj21VBMDVzgiNlcbVCIaNy29ZBw9ZjY4','z2v0u2vZC2LVBG','BM9Kzxm','qvPvuKvFvevoqu5ux0Le','CMvZDg9Yzvn0yxrL','u0vtu0LptL9uvvjox0Xfqvnfx01t','BgvUz3rO','y29TBwL0uhjLzgLJyxrL','C3rHDhvZq29Kzq','BM93','z3jHCgG','CMvTB3zLtgvNywn5vg9VBfrYywnLCW','Dgv4Da','tu9or09eqL9dt0Xmrunusu9o','B3DUzxi','q09ttu9FrejFsuq','Bwf0y2HLC1nLC3nPB25xCML0zvbYzwrPy2f0zq','zgvSzxrL','AxnoB3rgB3vUza','y29UzMLN','jY4Gu3rHCNqGysbUzxCGC2vZC2LVBIb0BYbYDw4GysbKAwzMzxjLBNqGz3jHCgGU','CgfYDgL0Aw9Us2v5','y29TCgfYzufUzfn3yxa','AxrLBq','y2XVC2u','zgvJAxnPB25vC2fNzq','y3jLyxrLzef0','C2vZC2LVBLjLDMLZAw9U','ywXSB3DpD25LCG','Aw5FChjVz3jLC3m','AM9PBG','AxngAw5PDgu','mtfnAKDzEgO','y29TCgfJDfn0B3jLze1LC3nHz2vZ','C2L6zq'];u=function(){return wn;};return u();}import{ConfigManager as M}from'../config-manager.js';import{GRAPH_END_NODE as m}from'../graph-state.js';import{cloneJsonObject as s}from'../graph-context.js';import{GraphLlm as t}from'../graph-llm.config.js';import{replaceNodeStates as a}from'../node-state.js';import{createSessionLogs as B}from'../session-log.js';import{emptyTokenUsage as i,normalizeTokenUsage as L}from'../token-usage.js';import{assertGraphSchemaVersion as l}from'../stable-id.js';import{addDecisionUsage as R,emptyDecisionUsage as Z,normalizeDecisionUsage as o}from'../decision/decision-types.js';const h=0x10,g=ut(0xed),q=ut(0xc2),Ce='SESSION_COMPLETED';class f extends Error{static{c(this,ut(0xfa));}[ut(0xb4)];constructor(d,n){const uC=ut;super(n),this[uC(0xc9)]=uC(0xfa),this[uC(0xb4)]=d;}}class N{static{c(this,'SessionManager');}['container'];[ut(0x103)];constructor(d=new V(),n=F()){const ua=ut;this['container']=d,this[ua(0x103)]=n;}static async[ut(0xf8)](r=new M()){const w8={d:0x119,n:0x9d,r:0x12c,H:0x119,E:0xdb,z:0xa2,D:0x110,e:0x106,A:0x12a,u0:0x112,u1:0x136,u2:0xa7,u3:0xec,u4:0xd7,u5:0xd8,u6:0xdd,u7:0xe4,u8:0x119,u9:0x11a,uu:0xbd},uB=ut,u0=r[uB(w8.d)]('SESSION_STORE','memory')[uB(w8.n)]()['toLowerCase'](),u1=F(r['get'](uB(w8.r)));if(u0==='memory')return new N(new V(),u1);if(u0===uB(0xbe)){const {SqliteSessionDocumentContainer:um}=await import('./sqlite-session-document.container.js');return new N(new um(r[uB(w8.H)](uB(0xb0),uB(0xe1))),u1);}if(u0===uB(0xa2)||u0==='mongo'){const uq=p(r,uB(w8.E)),uI=p(r,'MONGODB_NAME'),uW=p(r,uB(0x134));if(!uq||!uI||!uW)throw new Error('MongoDB\x20session\x20persistence\x20requires\x20MONGODB_URL,\x20MONGODB_NAME,\x20and\x20MONGODB_COLLECTION.');const [{MongoClient:uJ},{MongoDbSessionDocumentContainer:uv}]=await Promise[uB(0xe9)]([import(uB(w8.z)),import('./mongodb-session-document.container.js')]),us=new uJ(uq);await us[uB(0x115)]();const uP=us['db'](uI)['collection'](uW);return await uP['createIndex']({'id':0x1},{'unique':!0x0}),new N(new uv(uP,us),u1);}if(u0!==uB(0x10a)&&u0!==uB(w8.D))throw new Error('Unsupported\x20SESSION_STORE\x20\x27'+u0+uB(0x127));const u2=p(r,'COSMO_ENDPOINT','COSMOS_ENDPOINT','COSMODB_URL'),u3=p(r,uB(w8.e),'COSMOS_KEY'),u4=p(r,uB(w8.A)),u5=p(r,uB(w8.u0)),u6=p(r,uB(0xaf)),u7=p(r,uB(w8.u1),'COSMOS_DATABASE',uB(w8.u2))??uB(w8.u3),u8=p(r,'COSMO_DB_SESSION_CONTAINER_ID',uB(0xc5),uB(w8.u4))??uB(0x116);if(!u2||!u3&&(!u4||!u5||!u6))throw new Error(uB(0xb3));const [{CosmosClient:u9},{ClientSecretCredential:uu}]=await Promise['all']([import(uB(w8.u5)),import(uB(w8.u6))]),uw=u3?new u9({'endpoint':u2,'key':u3}):new u9({'endpoint':u2,'aadCredentials':new uu(u4,u5,u6)}),{database:uf}=await uw[uB(w8.u7)][uB(0x109)]({'id':u7}),uk=Number(r[uB(w8.u8)](uB(0xd5),uB(0xa0))),{container:uQ}=await uf['containers'][uB(0x109)]({'id':u8,'partitionKey':{'paths':['/id']},...Number[uB(0x98)](uk)&&uk>0x0?{'throughput':uk}:{}}),{resource:uO}=await uQ[uB(0xac)](),uY=uO?.[uB(0x13c)]?.[uB(w8.u9)]??[];if(!uY[uB(0xda)](uB(0xf5)))throw new Error('Cosmos\x20container\x20\x27'+u8+'\x27\x20must\x20use\x20partition\x20key\x20/id;\x20found\x20'+(uY[uB(0x145)](',\x20')||'none')+'.');const {CosmosSessionDocumentContainer:uM}=await import(uB(w8.uu));return new N(new uM(uQ,()=>uw[uB(0x126)]()),u1);}async[ut(0x128)](d){const w9={d:0x117,n:0x101},uy=ut,n=await this[uy(w9.d)](d);return n?.[uy(w9.n)]===h?n:void 0x0;}async[ut(0x117)](d){const wu={d:0xe7},uK=ut;try{const {resource:n}=await this[uK(wu.d)][uK(0x13e)](d,d)[uK(0xac)]();return n;}catch(r){if(G(r))return;throw r;}}async[ut(0x108)](r,H,E){const ww={d:0xca,n:0x117,r:0x123,H:0x103,E:0xa1,z:0x13d,D:0xcb,e:0xe7,A:0xd4,u0:0xff,u1:0xdf,u2:0xbb,u3:0xcb},ui=ut,z=Y[ui(ww.d)](E[ui(0x11d)]),D=l(E[ui(0xe2)]),A=await this[ui(ww.n)](r);A&&A[ui(0x101)]===h&&T(A,z);const u0=new Date(),u1={'owner':H,'expiresAt':new Date(u0[ui(ww.r)]()+this[ui(ww.H)])[ui(0xa1)]()};if(!A){const u3=this['placeholderDocument'](r,E,z,D,u1,u0[ui(ww.E)]());if(await this['container'][ui(ww.z)]({'expectedRevision':null},u3)==='conflict')throw new f(g,ui(0xbb)+r+ui(ww.D));return{'kind':ui(0xff),'document':u3,'expectedRevision':u3['revision']};}if(A[ui(0x101)]!==h){const u4=this['placeholderDocument'](r,E,z,D,u1,u0['toISOString']());if(await this[ui(ww.e)][ui(0x13d)]({'expectedRevision':S(A),'replaceIncompatible':!0x0},u4)===ui(ww.A))throw new f(g,ui(0xbb)+r+'\x27\x20is\x20already\x20processing\x20a\x20turn.');return{'kind':ui(ww.u0),'document':u4,'expectedRevision':u4[ui(0xb2)]};}if(K(A[ui(0xdf)])&&A[ui(ww.u1)]?.[ui(0x135)]!==H)throw new f(g,'Session\x20\x27'+r+ui(ww.D));const u2={...A,'revision':S(A)+0x1,'turn':u1};if(await this['container']['compareAndSwap']({'expectedRevision':S(A),'requireFreeLease':!0x0,'allowOwner':H},u2)==='conflict')throw new f(g,ui(ww.u2)+r+ui(ww.u3));return{'kind':'leased','document':u2,'expectedRevision':S(u2)};}async[ut(0x12b)](d,r){const uL=ut,H=await this['getSession'](d);if(H)return this[uL(0x102)](H,r);}[ut(0x102)](d,r){const wk={d:0x129,n:0x129,r:0xa5,H:0x13a,E:0x114,z:0x11f,D:0xfc},ul=ut,H=Y[ul(0xca)](r);T(d,H);const {graph:E}=d;if(!E[ul(wk.d)])return;const z=a({},E[ul(wk.n)]),D=ae(E[ul(wk.r)]);return{'currentNode':E[ul(0x9f)],'config':E[ul(wk.H)]??{},'context':s(E[ul(wk.E)]===void 0x0?{}:E['context']),'completed':d[ul(wk.z)]===ul(wk.D)||E[ul(0x9f)]===m,'nodes':z,'tokens':L(d[ul(0xab)]),'decisionUsage':o(d['decisionUsage']),'histories':D,'inputConsumed':!0x0,'response':''};}async[ut(0xd9)](r,H,z,D=B(),A={}){const wQ={d:0xe2,n:0xa1,r:0x129,H:0xfc,E:0x140,z:0xe0,D:0x11c,e:0x9f,A:0x114,u0:0x10f,u1:0x135,u2:0x13d,u3:0xd4,u4:0xbb,u5:0xcb},uj=ut,u0=Y[uj(0xca)](z[uj(0x11d)]),u1=l(z[uj(wQ.d)]),u2=await this[uj(0x117)](r),u3=u2?.[uj(0x101)]===h?u2:void 0x0;u3&&(T(u3,u0),j(u3,u1));const u4=new Date()[uj(wQ.n)](),u5=oe(a({},H[uj(wQ.r)])),{tokens:u6,histories:u7}=H,u8=this[uj(0xc4)](u2,A),u9={'version':h,'id':r,'revision':u8===null?0x0:u8+0x1,'status':H[uj(wQ.H)]?'completed':'in_progress','tokens':L(u6),'decisionUsage':o(H[uj(wQ.E)]),'errors':[...u3?.[uj(0xe0)]??[],...D[uj(wQ.z)]],'warnings':[...u3?.[uj(0xcd)]??[],...D[uj(0xcd)]],'decisions':[...u3?.['decisions']??[],...D[uj(wQ.D)]],'graph':{'id':u0,'schemaVersion':u1,'currentNode':H[uj(wQ.e)],'config':H[uj(0x13a)],'context':s(H[uj(wQ.A)]===void 0x0?{}:H[uj(wQ.A)]),'histories':se(u7),'model':t[uj(wQ.u0)](z[uj(0xf3)]),'nodes':u5},...A['keepTurn']&&u3?.[uj(0xdf)]?{'turn':{'owner':u3[uj(0xdf)][uj(wQ.u1)],'expiresAt':new Date(Date[uj(0x130)]()+this[uj(0x103)])[uj(0xa1)]()}}:{},'createdAt':u3?.['createdAt']??u4,'modifiedAt':u4};if(await this['container'][uj(wQ.u2)](this[uj(0x12e)](u2,A,u8),u9)===uj(wQ.u3))throw new f(A['owner']?q:g,A[uj(0x135)]?uj(wQ.u4)+r+uj(0xa3):uj(0xbb)+r+uj(wQ.u5));return u9;}async['appendLogs'](r,H,E,z={}){const wO={d:0xe2,n:0x128,r:0x140,H:0xe0,E:0x11c,z:0x9f,D:0x13a,e:0xa5,A:0x114,u0:0xf3,u1:0x131,u2:0x131,u3:0x141,u4:0x13d,u5:0x12e,u6:0x135,u7:0xbb,u8:0x12d},uR=ut,D=Y[uR(0xca)](E[uR(0x11d)]),A=l(E[uR(wO.d)]),u0=await this[uR(wO.n)](r);u0&&(T(u0,D),j(u0,A));const u1=new Date()['toISOString'](),u2=this[uR(0xc4)](u0,z),u3={'version':h,'id':r,'revision':u2===null?0x0:u2+0x1,'status':H[uR(0xe0)]['length']>0x0?uR(0xaa):u0?.['status']??'in_progress','tokens':u0?.[uR(0xab)]??i(),'decisionUsage':H[uR(0x11c)][uR(0xc8)]((u4,u5)=>R(u4,u5['usage']),o(u0?.[uR(wO.r)])),'errors':[...u0?.[uR(wO.H)]??[],...H[uR(0xe0)]],'warnings':[...u0?.[uR(0xcd)]??[],...H[uR(0xcd)]],'decisions':[...u0?.[uR(wO.E)]??[],...H[uR(0x11c)]],'graph':{'id':D,'schemaVersion':A,...u0?{'currentNode':u0['graph'][uR(wO.z)],'config':u0['graph'][uR(wO.D)]}:{},'histories':u0?.[uR(0x131)][uR(wO.e)]??{},'context':s(u0?.['graph'][uR(wO.A)]===void 0x0?{}:u0[uR(0x131)]['context']),'model':t['modelMetadata'](E[uR(wO.u0)]),...u0?.[uR(wO.u1)][uR(0x129)]?{'nodes':u0[uR(wO.u2)][uR(0x129)]}:{}},'createdAt':u0?.[uR(wO.u3)]??u1,'modifiedAt':u1};if(await this['container'][uR(wO.u4)](this[uR(wO.u5)](u0,z,u2),u3)==='conflict'){if(z[uR(wO.u6)]){console['warn'](uR(wO.u7)+r+uR(0xf0)+H[uR(wO.H)]['length']+'\x20error(s)\x20and\x20'+H['warnings'][uR(wO.u8)]+uR(0xe3));return;}throw new f(g,'Session\x20\x27'+r+uR(0xcb));}return u3;}async['endFailedTurn'](d,r,H,E,z){const wY={d:0xe0,n:0xcd,r:0x9c},ug=ut;if(E&&(E[ug(wY.d)][ug(0x12d)]>0x0||E[ug(wY.n)][ug(0x12d)]>0x0||E[ug(0x11c)][ug(0x12d)]>0x0)){await this[ug(0xee)](d,E,H,{'owner':r,...z!==void 0x0?{'expectedRevision':z}:{}});return;}await this[ug(wY.r)](d,r,z);}async[ut(0x9c)](d,r,H){const wM={d:0x135,n:0x13d},uZ=ut,E=await this['getSession'](d);if(!E||E['turn']?.[uZ(wM.d)]!==r)return;const z=H??S(E),{turn:D,...A}=E,u0={...A,'modifiedAt':new Date()['toISOString']()};await this[uZ(0xe7)][uZ(wM.n)]({'expectedRevision':z,'requireOwner':r},u0);}async[ut(0x120)](d){const wm={d:0xe7},ux=ut;try{await this[ux(wm.d)][ux(0x13e)](d,d)[ux(0x138)]();}catch(n){if(!G(n))throw n;}}async['persistMigratedSession'](d,r={}){const wq={d:0x100,n:0xc3,r:0x131,H:0xeb,E:0x128,z:0xdf,D:0x114,e:0x141,A:0x141,u0:0xbb,u1:0xb8},uX=ut;if(d['version']!==h)throw new Error(uX(wq.d)+d[uX(0x101)]+uX(wq.n)+h+'.');Y[uX(0xca)](d[uX(0x131)]['id']),l(d[uX(wq.r)][uX(wq.H)]);const H=await this[uX(wq.E)](d['id']),E=r[uX(0x113)]??S(H||d),z=H?.[uX(0xdf)]??d[uX(wq.z)],D={...d,'graph':{...d['graph'],'context':s(d[uX(wq.r)][uX(wq.D)]===void 0x0?{}:d['graph']['context'])},'revision':E,'createdAt':H?.[uX(wq.e)]??d[uX(wq.A)],'modifiedAt':H?.[uX(0xf6)]??d[uX(0xf6)],...z?{'turn':z}:{}};if(await this['container'][uX(0x13d)]({'expectedRevision':E,...r[uX(0x135)]?{'requireOwner':r[uX(0x135)]}:{'requireFreeLease':!0x0}},D)===uX(0xd4))throw new f(r[uX(0x135)]?q:g,uX(wq.u0)+d['id']+uX(wq.u1));}async[ut(0x13f)](){const uo=ut;await this['container'][uo(0x13f)]?.();}[ut(0xd3)](d,r,H,E,z,D){const wW={d:0x144},uS=ut;return{'version':h,'id':d,'revision':0x0,'status':uS(wW.d),'tokens':i(),'decisionUsage':Z(),'errors':[],'warnings':[],'decisions':[],'graph':{'id':H,'schemaVersion':E,'histories':{},'context':{},'model':t[uS(0x10f)](r[uS(0xf3)])},'turn':z,'createdAt':D,'modifiedAt':D};}['commitExpectedRevision'](d,n){const wJ={d:0x113},ud=ut;return n[ud(wJ.d)]!==void 0x0?n[ud(wJ.d)]:d?S(d):null;}[ut(0x12e)](d,r,H){const wv={d:0x135,n:0x101},uT=ut;return r[uT(wv.d)]?{'expectedRevision':H,'requireOwner':r['owner']}:d&&d[uT(wv.n)]!==h?{'expectedRevision':H,'replaceIncompatible':!0x0}:{'expectedRevision':H,'requireFreeLease':!0x0};}}function p(d,...H){const un=ut;for(const E of H){const z=d[un(0x119)](E);if(z)return z;}}c(p,ut(0x107));function T(d,n){const wP={d:0x131,n:0xbb,r:0xfe,H:0x13b},uc=ut;if(d[uc(wP.d)]['id']!==n)throw new Error(uc(wP.n)+d['id']+uc(wP.r)+d['graph']['id']+'\x27,\x20not\x20\x27'+n+uc(wP.H));}c(T,ut(0xf4));function j(d,n){const wp={d:0x131,n:0xeb,r:0xfb,H:0xb6,E:0x131,z:0xeb,D:0xea,e:0xae},uG=ut;if(d[uG(wp.d)][uG(wp.n)]!==n)throw new Error('Session\x20\x27'+d['id']+uG(wp.r)+d['graph']['id']+uG(wp.H)+d[uG(wp.E)][uG(wp.z)]+uG(wp.D)+n+uG(wp.e));}c(j,ut(0xde));function oe(d){const wC={d:0x11e},wt={d:0x121},uV=ut;return Object[uV(0xc0)](Object[uV(0xd2)](d)[uV(wC.d)](([H,E])=>{const ur=uV;if(!E||typeof E!=ur(wt.d))return[H,E];const {toolTrace:z,...D}=E;return[H,D];}));}c(oe,ut(0x132));function ie(d){const wa={d:0xef,n:0x12d,r:0xe5,H:0xd1,E:0xcf,z:0xf7,D:0x111,e:0x12d,A:0xf9,u0:0x12d,u1:0xf9};return d['map'](n=>{const uH=w,H={...n[uH(0xb1)]},E=n['type']==='ai'&&Array[uH(wa.d)](H[uH(0x111)])&&H[uH(0x111)][uH(wa.n)]>0x0?ce(H[uH(0xe5)]):void 0x0,z=b(H[uH(wa.r)])&&H[uH(0xe5)][uH(wa.H)]===!0x0;return delete H[uH(0xe5)],(E||z)&&(H['additional_kwargs']={...E?{'originalTextContentBlock':E}:{},...z?{'ezgraphInternal':!0x0}:{}}),delete H[uH(wa.E)],delete H[uH(wa.z)],n[uH(0xbc)]==='ai'&&(Array[uH(0xef)](H[uH(wa.D)])&&H[uH(0x111)][uH(wa.e)]===0x0&&delete H[uH(wa.D)],Array['isArray'](H[uH(wa.A)])&&H[uH(0xf9)][uH(wa.u0)]===0x0&&delete H[uH(wa.u1)]),{...n,'data':H};});}c(ie,ut(0x9a));function se(d){const wy={d:0xd2,n:0x11e},uN=ut;return Object[uN(0xc0)](Object[uN(wy.d)](d)[uN(wy.n)](([n,H])=>[n,ie(k(H))]));}c(se,ut(0xa4));function ae(d={}){const wK={d:0xc0},uh=ut;return Object[uh(wK.d)](Object[uh(0xd2)](d)[uh(0x11e)](([n,H])=>[n,O(H)]));}c(ae,ut(0xa9));function ce(d){const wi={d:0x9e,n:0x133,r:0x9e},uF=ut;if(!b(d))return;const n=d[uF(0x10d)];if(!(!b(n)||typeof n[uF(wi.d)]!=uF(0xc7)))return{...typeof n[uF(wi.n)]==uF(0xc7)?{'text':n['text']}:{},'thoughtSignature':n[uF(wi.r)],...n[uF(0xba)]===!0x0?{'thought':!0x0}:{}};}c(ce,ut(0xf1));function b(d){const uE=ut;return d!==null&&typeof d==uE(0x121)&&!Array['isArray'](d);}c(b,ut(0x104));class V{static{c(this,ut(0xb9));}[ut(0x105)]=new Map();get[ut(0x9b)](){const uz=ut;return this[uz(0x105)][uz(0x9b)];}[ut(0xbf)]={'upsert':c(async e=>{const wj={d:0x105},ub=ut,t=e;return this[ub(wj.d)]['set'](t['id'],structuredClone(t)),{};},ut(0x124))};async[ut(0x13d)](d,r){const wR={d:0x105},uD=ut,H=this[uD(wR.d)][uD(0x119)](r['id']);return de(H,d)?(this['documents'][uD(0x10e)](r['id'],structuredClone(r)),'ok'):'conflict';}[ut(0x13e)](d,n){const wZ={d:0x119,n:0xc1,r:0x11b},wg={d:0x105},uA=ut;return{'read':c(async()=>{const uU=w,r=this[uU(wg.d)][uU(0x119)](d);if(!r||r['id']!==n)throw Object[uU(0xc1)](new Error('Not\x20found'),{'code':0x194});return{'resource':structuredClone(r)};},'read'),'delete':c(async()=>{const ue=w,r=this[ue(0x105)][ue(wZ.d)](d);if(!r||r['id']!==n)throw Object[ue(wZ.n)](new Error(ue(wZ.r)),{'code':0x194});return this[ue(0x105)]['delete'](d),{};},uA(0x138))};}}function G(d){const w0=ut;if(!d||typeof d!=w0(0x121))return!0x1;const n=d;return n[w0(0xb4)]===0x194||n[w0(0x12f)]===0x194;}c(G,ut(0x139));function F(d=process.env.SESSION_TURN_LEASE_MS){const wo={d:0x118},w1=ut,n=Number(d??w1(wo.d));return Number[w1(0x98)](n)&&n>0x0?n:0xea60;}function w(f,k){f=f-0x98;const Q=u();let O=Q[f];if(w['zZPXch']===undefined){var Y=function(I){const W='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+/=';let J='',v='';for(let s=0x0,P,p,t=0x0;p=I['charAt'](t++);~p&&(P=s%0x4?P*0x40+p:p,s++%0x4)?J+=String['fromCharCode'](0xff&P>>(-0x2*s&0x6)):0x0){p=W['indexOf'](p);}for(let C=0x0,a=J['length'];C<a;C++){v+='%'+('00'+J['charCodeAt'](C)['toString'](0x10))['slice'](-0x2);}return decodeURIComponent(v);};w['quHhSI']=Y,w['AkYZlF']={},w['zZPXch']=!![];}const M=Q[0x0],m=f+M,q=w['AkYZlF'][m];return!q?(O=w['quHhSI'](O),w['AkYZlF'][m]=O):O=q,O;}c(F,ut(0xe6));function S(d){const wS={d:0xb2},w2=ut;return d?.[w2(wS.d)]??0x0;}c(S,ut(0x142));function K(d,n=Date['now']()){const wd={d:0x135,n:0xcc,r:0xb7},w3=ut;if(!d?.[w3(wd.d)]||!d[w3(0xb7)])return!0x1;const H=Date[w3(wd.n)](d[w3(wd.r)]);return Number['isFinite'](H)&&H>n;}c(K,ut(0xb5));function de(d,n,H=Date[ut(0x130)]()){const wT={d:0x113,n:0xdf,r:0xf2,H:0xd0},w4=ut;return n[w4(0x10c)]?d!==void 0x0&&d['version']!==h:n[w4(wT.d)]===null?d===void 0x0:!(!d||S(d)!==n[w4(0x113)]||n['requireOwner']&&d[w4(wT.n)]?.[w4(0x135)]!==n[w4(wT.r)]||n[w4(wT.H)]&&K(d[w4(0xdf)],H)&&d['turn']?.[w4(0x135)]!==n[w4(0x143)]);}c(de,ut(0x137));export{V as MemorySessionDocumentContainer,g as SESSION_BUSY,Ce as SESSION_COMPLETED,q as SESSION_CONFLICT,h as SESSION_DOCUMENT_VERSION,N as SessionManager,f as SessionTurnError,K as isLiveSessionTurn,de as matchesSessionWritePredicate,S as sessionRevision,F as sessionTurnLeaseMs};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
const
|
|
1
|
+
const X=k;(function(v,s){const u5={v:0xe8,s:0xc4,P:0xde,t:0x10f,C:0xc5,a:0x10d},Z=k,P=v();while(!![]){try{const t=parseInt(Z(u5.v))/0x1+parseInt(Z(0x108))/0x2*(-parseInt(Z(u5.s))/0x3)+parseInt(Z(u5.P))/0x4*(-parseInt(Z(0xd7))/0x5)+parseInt(Z(u5.t))/0x6*(-parseInt(Z(0xfa))/0x7)+parseInt(Z(0xe2))/0x8*(-parseInt(Z(0xcd))/0x9)+-parseInt(Z(0xf3))/0xa*(-parseInt(Z(u5.C))/0xb)+parseInt(Z(u5.a))/0xc;if(t===s)break;else P['push'](P['shift']());}catch(C){P['push'](P['shift']());}}}(f,0x39347));var m=Object[X(0xc9)],p=(v,s)=>m(v,X(0xd8),{'value':s,'configurable':!0x0});import{END as Q,isCommand as O,START as Y,StateGraph as M}from'@langchain/langgraph';import{GRAPH_NODE_CLASS as q,GraphNode as I}from'./graph-node.js';function k(u,w){u=u-0xc3;const Q=f();let O=Q[u];if(k['uhJOwZ']===undefined){var Y=function(I){const W='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+/=';let J='',v='';for(let s=0x0,P,p,t=0x0;p=I['charAt'](t++);~p&&(P=s%0x4?P*0x40+p:p,s++%0x4)?J+=String['fromCharCode'](0xff&P>>(-0x2*s&0x6)):0x0){p=W['indexOf'](p);}for(let C=0x0,a=J['length'];C<a;C++){v+='%'+('00'+J['charCodeAt'](C)['toString'](0x10))['slice'](-0x2);}return decodeURIComponent(v);};k['CPtMFs']=Y,k['PUoJpy']={},k['uhJOwZ']=!![];}const M=Q[0x0],m=u+M,q=k['PUoJpy'][m];return!q?(O=k['CPtMFs'](O),k['PUoJpy'][m]=O):O=q,O;}import{GRAPH_END_NODE as W}from'./graph-state.js';import{stableClassId as J}from'./stable-id.js';class x{static{p(this,'StateGraphExt');}[X(0xca)];[X(0xdd)];[X(0xdc)];[X(0xe7)]=new Set();[X(0xfd)]=new Map();[X(0x107)]=new Map();constructor(v,s,P=W){const o=X;this['createGraphNode']=s,this[o(0xdd)]=P,this[o(0xdc)]=new M(v);}[X(0xe3)](v){const u7={v:0xca,s:0xca,P:0x10e,t:0xd3},S=X;if(!g(v))throw new Error(S(0xcc));if(!this[S(u7.v)])throw new Error('This\x20graph\x20has\x20no\x20GraphNode\x20factory.');const s=this[S(u7.s)](v),P=J(v,'graph\x20node');if(s['id']!==P)throw new Error(S(u7.P)+P+S(u7.t)+s['id']+'\x27.');return this[S(0xfd)][S(0xd5)](P,v),this['registerNode'](s,[...this['addedNodeIds'],P,Q]);}[X(0xea)](...v){const u9={v:0xca,s:0xec,P:0xf5,t:0xd3},u8={v:0xe6,s:0x101},d=X;if(!this[d(u9.v)])throw new Error('This\x20graph\x20has\x20no\x20GraphNode\x20factory.');const P=v['map'](K=>{const T=d;if(!g(K))throw new Error(T(u8.v));return J(K,T(u8.s));}),C=P['find']((K,i)=>P['indexOf'](K)!==i||this[d(0xe7)][d(0xd6)](K));if(C)throw new Error(d(u9.s)+C+d(u9.P));const B=[...this[d(0xe7)],...P,Q];for(const [K,i]of v['entries']()){const L=this[d(0xca)](i),j=P[K];if(L['id']!==j)throw new Error(d(0x10e)+j+d(u9.t)+L['id']+'\x27.');this['nodeClasses'][d(0xd5)](j,i),this[d(0xd4)](L,B);}return this;}[X(0xee)](...v){const n=X;return this['nodes'](...v),this[n(0xdf)](...v),this;}[X(0xcf)](v,s){const uw={v:0x100,s:0x103,P:0xcf},V=X,P=Array[V(uw.v)](v)?v:[v];for(const a of P)this[V(0x10a)](a);this[V(0xf1)](s);const C=P[V(uw.s)](c);return this['graph'][V(uw.P)](C['length']===0x1?C[0x0]:C,c(s)),this;}[X(0xf0)](v,s){const uf={v:0xf4},r=X,P=J(v,'graph\x20node'),C=this[r(0x107)][r(0x10c)](P);if(!C)throw new Error('Graph\x20node\x20\x27'+P+'\x27\x20must\x20be\x20added\x20before\x20it\x20is\x20connected.');return this[r(uf.v)](v,C[r(0xf8)]['bind'](C),s),this;}[X(0xd9)](v,s){const uQ={v:0xfc,s:0xf4,P:0x106,t:0x103},uk={v:0xef},H=X,P=J(v,H(0x101));if(!this['nodeInstances'][H(0xd6)](P))throw new Error(H(0xec)+P+H(0xc7));if(s[H(uQ.v)][H(0xd0)]===0x0)throw new Error('branchBy()\x20requires\x20at\x20least\x20one\x20case.');const C=s[H(uQ.v)]['map'](({when:L})=>this['currentNodeSelectorName'](L)),B=C[H(0xd1)]((L,j)=>C[H(0xe0)](L)!==j);if(B)throw new Error(H(0xe5)+B+'\x27.');const K=C['map']((L,j)=>H(0x10b)+j),i='otherwise';return this[H(uQ.s)](v,L=>{const N=H,j=L[N(0xfe)];if(typeof j!=N(uk.v))throw new Error(N(0xec)+P+N(0xf7));const R=C[N(0xe0)](j);return R===-0x1?i:K[R];},{...Object[H(uQ.P)](s['cases'][H(uQ.t)](({routeTo:L},j)=>[K[j],L])),[i]:s[H(0xdb)]}),this;}['registerTurns'](...v){const uO={v:0xf9,s:0x102,P:0x103},F=X;if(v[F(uO.v)](s=>J(s,'graph\x20node')===this[F(0xdd)]))throw new Error(F(uO.s)+this[F(0xdd)]+'\x27\x20is\x20reserved\x20by\x20StateGraphExt.registerTurns().');return this['addConditionalEdge'](Y,s=>s[F(0xfe)],{...Object[F(0x106)](v[F(uO.P)](s=>[J(s,F(0x101)),s])),[this[F(0xdd)]]:Q}),this;}[X(0xda)](){const uY={v:0x107,s:0xcb,P:0xda},z=X;for(const v of this[z(uY.v)][z(uY.s)]())v['validateTools']?.();return this['graph'][z(uY.P)]();}['addConditionalEdge'](v,s,P){const uM={v:0xf1,s:0xce},D=X;this['assertSource'](v);for(const C of Object[D(0xcb)](P))this[D(uM.v)](C);this['graph'][D(0xe9)](c(v),s,Object['fromEntries'](Object[D(uM.s)](P)['map'](([a,B])=>[a,c(B)])));}[X(0xd4)](v,s){const uq={v:0xec},um={v:0xc3,s:0xc3,P:0xc3},U=X;if(this[U(0xe7)]['has'](v['id']))throw new Error(U(uq.v)+v['id']+'\x27\x20is\x20already\x20registered.');return this[U(0xdc)]['addNode'](v['id'],async P=>{const e=U,C=await v['invoke'](P);if(O(C)){const B=Array['isArray'](C['goto'])?C[e(um.v)]:C[e(um.s)]===void 0x0?[]:[C[e(um.P)]];for(const K of B)typeof K=='string'&&this['assertTarget'](K);}return C;},{'ends':[...new Set(s)]}),this['addedNodeIds'][U(0xd2)](v['id']),this['nodeInstances']['set'](v['id'],v),this;}[X(0x10a)](v){const uI={v:0x104},A=X;c(v)!==Y&&this[A(uI.v)](v,A(0xe1));}['assertTarget'](v){const u0=X;c(v)!==Q&&this['assertAddedNode'](v,u0(0xeb));}[X(0x104)](v,s){const uJ={v:0xd6,s:0xfb},u1=X,P=c(v);if(!this['addedNodeIds'][u1(uJ.v)](P))throw new Error(u1(uJ.s)+s+'\x20\x27'+P+u1(0xc7));}[X(0xf2)](v){const uv={v:0xef,s:0x101,P:0xf6,t:0xd6,C:0xe4},u2=X;if(typeof v!=u2(uv.v)){if(!g(v))throw new Error(u2(0xff));const s=J(v,u2(uv.s));if(!this['addedNodeIds'][u2(0xd6)](s))throw new Error(u2(uv.P)+s+u2(0xc6));return s;}if(v!==this[u2(0xdd)]&&!this[u2(0xe7)][u2(uv.t)](v))throw new Error(u2(0xf6)+v+u2(uv.C)+this[u2(0xdd)]+'\x27.');return v;}}function g(v){const u3=X,s=v;return typeof v==u3(0x105)&&v!==null&&s[q]===!0x0&&s[u3(0xed)]instanceof I;}p(g,X(0x109));function c(v){const uP={v:0xef},u4=X;return typeof v==u4(uP.v)?v:J(v,'graph\x20node');}p(c,X(0xc8));export{x as StateGraphExt};function f(){const up=['BMfTzq','yNjHBMnOqNK','y29TCgLSzq','B3rOzxj3AxnL','z3jHCgG','zw5KtM9Kzq','mZmXmLntELbvvW','CMvNAxn0zxjuDxjUCW','Aw5KzxHpzG','C291CMnL','mtzqzxrltfa','ywrKtM9Kzq','jYbTDxn0igjLigfUigfKzgvKieDYyxbOtM9KzsbVCIb0AguGy29UzMLNDxjLzcb0zxjTAw5HBcbZDgf0zsaN','yNjHBMnOqNKOksbOyxmGBw9Yzsb0AgfUig9UzsbJyxnLigzVCIaN','u3rHDgvhCMfWAev4DcbUB2rLCYbTDxn0igjLigfKzgvKigfZieDYyxbOtM9KzsbJBgfZC2vZoIbNCMfWAc5UB2rLCYHnEu5VzguPlG','ywrKzwroB2rLswrZ','mJu5mJuWwNLwt0fb','ywrKq29UzgL0Aw9UywXfzgDLCW','BM9Kzxm','DgfYz2v0','r3jHCgGGBM9KzsaN','ChjVDg90ExbL','CMvNAxn0zxjuDxjUtM9Kzxm','C3rYAw5N','yNjHBMnO','yxnZzxj0vgfYz2v0','y3vYCMvUDe5VzgvtzwXLy3rVCK5HBwu','mtuXmeXbEhL1uq','ywrKq29UzgL0Aw9UywXfzgDL','jYbPCYbHBhjLywr5ihjLz2LZDgvYzwqU','q3vYCMvUDc1UB2rLihnLBgvJDg9YicC','jYbJyw5UB3qGyNjHBMnOihDPDgHVDxqGysbZDhjPBMCGy3vYCMvUDe5VzguU','CM91Dgu','C29Tzq','ntzhCKzws2K','q29UzgL0Aw9UywWGB3iGzgLYzwn0igvKz2uG','y2fZzxm','BM9KzunSyxnZzxm','y3vYCMvUDe5Vzgu','yNjHBMnOqNKOksbZzwXLy3rVCNmGBxvZDcbIzsbhCMfWAe5VzguGy2XHC3nLCYbVCIb0AguGy29UzMLNDxjLzcb0zxjTAw5HBcbZDgf0zs4','AxnbCNjHEq','z3jHCgGGBM9Kzq','vgHLihrLCM1PBMfSihn0yxrLicC','BwfW','yxnZzxj0qwrKzwroB2rL','zNvUy3rPB24','zNjVBuvUDhjPzxm','BM9KzuLUC3rHBMnLCW','mtmWofrzD3DYCW','AxnhCMfWAe5VzgvdBgfZCW','yxnZzxj0u291CMnL','y2fZztO','z2v0','nteXmZmYmg1dDKPdtW','r3jHCgGGBM9KzsbMywn0B3j5igzVCIaN','mJu4ndHMuu95ww8','z290BW','nJi3DNHeyNnq','mJeWndnKyLHfr0W','jYbTDxn0igjLigfKzgvKigjLzM9YzsbPDcbPCYb1C2vKlG','jYbTDxn0igjLigfKzgvKigjLzM9YzsbPDcbPCYbJB25Uzwn0zwqU','zw5KCg9PBNrjza','zgvMAw5LuhjVCgvYDhK','y3jLyxrLr3jHCgHoB2rL','DMfSDwvZ','u3rHDgvhCMfWAev4DcbUB2rLCYbTDxn0igjLigfKzgvKigfZieDYyxbOtM9KzsbJBgfZC2vZoIbNCMfWAc5HzgroB2rLke15tM9KzsKU','mtG2mJy2n2ritNruCq','zw50CMLLCW','ywrKrwrNzq','BgvUz3rO','zMLUza','ywrK','jYbYzxr1CM5LzcaN','CMvNAxn0zxjoB2rL','C2v0','AgfZ','otm1vgPyBfb0'];f=function(){return up;};return f();}
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{GraphContextChannel as r}from"./framework/graph-context.js";import{BaseGraph as t}from"./framework/base-graph.js";import{GRAPH_NODE_CLASS as n,GraphNode as a,GraphNodeRuntime as m,Tool as p}from"./framework/graph-node.js";import{LlmNode as E}from"./framework/llm-node.js";import{LLM_GATEWAY_FACTORY as L,assertLlmTimeoutMs as f}from"./framework/llm-gateway.js";import{LlmRunner as l,DEFAULT_LLM_POLICY as g,DEFAULT_EMPTY_HISTORY_SEED as D,DEFAULT_EMPTY_RESPONSE_RECOVERY as T,DEFAULT_MAX_AGENT_ROUNDS as _,EmptyModelResponseError as R,assertEmptyResponseRetries as c,assertMaxAgentRounds as C}from"./framework/llm-runner.js";import{describeStopReason as u,isRetryableStopReason as A,modelStopReason as N}from"./framework/model-stop-reason.js";import{currentTurnContext as I,currentTurnSignal as G,withTurnContext as P}from"./framework/turn-context.js";import{direct as U,directTo as y,finish as v,go as F,isToolResponse as Y,stay as H}from"./framework/tool-response.js";import{GraphStateSupport as B}from"./framework/graph-state-support.js";import{GRAPH_END_NODE as V,createGraphStateAnnotation as W}from"./framework/graph-state.js";import{GraphRegistry as z}from"./framework/graph-registry.js";import{GraphEngine as J}from"./framework/graph-engine.js";import{ConfigManager as X}from"./framework/config-manager.js";import{StateGraphExt as K}from"./framework/state-graph-ext.js";import{TerminateSessionNode as $}from"./framework/terminate-session.node.js";import{SessionLogError as oe,SessionLogDecision as re,SessionLogWarning as se,createSessionLogs as te,drainSessionLogs as ie,restoreSessionLogs as ne,withSessionLogs as ae}from"./framework/session-log.js";import{ProviderFileManager as pe}from"./framework/llm-file.js";import{SessionManager as Ee,SessionTurnError as xe,SESSION_BUSY as Le,SESSION_CONFLICT as fe,SESSION_COMPLETED as de,SESSION_DOCUMENT_VERSION as le,MemorySessionDocumentContainer as ge,sessionTurnLeaseMs as De,sessionRevision as Te,isLiveSessionTurn as _e,matchesSessionWritePredicate as Re}from"./framework/persistence/session-manager.js";import{MongoDbSessionDocumentContainer as Ce}from"./framework/persistence/mongodb-session-document.container.js";import{SqliteSessionDocumentContainer as ue}from"./framework/persistence/sqlite-session-document.container.js";import{CosmosSessionDocumentContainer as Ne}from"./framework/persistence/cosmos-session-document.container.js";import{mergeNodeStates as Ie,replaceNodeStates as Ge}from"./framework/node-state.js";import{LangChainLlmGateway as he}from"./framework/langchain-llm-gateway.js";import{ModelProvider as ye}from"./framework/model-provider.js";import{langChainModelInitialization as Fe}from"./framework/langchain-provider.adapter.js";import{GRAPH_LLM_PROVIDERS as He,GRAPH_LLM_FAMILIES as ke,GRAPH_LLM_CAPABILITIES as Be,BUILT_IN_MODEL_CATALOG as be,GraphLlm as Ve,ModelCatalog as We,ModelProviderRegistry as we}from"./framework/graph-llm.config.js";import{addTokenUsage as qe,emptyTokenUsage as Je,modelExecution as Qe,normalizeTokenUsage as Xe,tokenUsageFromMessage as je}from"./framework/token-usage.js";import{DecisionNode as Ze}from"./framework/decision/decision-node.js";import{DecisionRunner as eo}from"./framework/decision/decision-runner.js";import{DecisionProvider as ro,DecisionProviderRegistry as so}from"./framework/decision/decision-provider.js";import{TypeSafeClassifierAdapter as io}from"./framework/decision/typesafe-provider.js";import{DecisionConfigurationError as ao,DecisionTimeoutError as mo,DecisionValidationError as po,DEFAULT_DECISION_OPTIONS as So,addDecisionUsage as Eo,decisionUsage as xo,emptyDecisionUsage as Lo,normalizeDecisionUsage as fo,resolveDecisionOptions as lo}from"./framework/decision/decision-types.js";import{assertJsonCompatible as Do,validateDecisionQuestions as To,validateDecisionResult as _o}from"./framework/decision/decision-validation.js";import{retryWithModel as co,LlmResponseBlockedError as Co,LlmSetupError as Mo}from"./framework/llm-lifecycle.js";export{be as BUILT_IN_MODEL_CATALOG,t as BaseGraph,X as ConfigManager,Ne as CosmosSessionDocumentContainer,So as DEFAULT_DECISION_OPTIONS,D as DEFAULT_EMPTY_HISTORY_SEED,T as DEFAULT_EMPTY_RESPONSE_RECOVERY,g as DEFAULT_LLM_POLICY,_ as DEFAULT_MAX_AGENT_ROUNDS,ao as DecisionConfigurationError,Ze as DecisionNode,ro as DecisionProvider,so as DecisionProviderRegistry,eo as DecisionRunner,mo as DecisionTimeoutError,po as DecisionValidationError,R as EmptyModelResponseError,V as GRAPH_END_NODE,Be as GRAPH_LLM_CAPABILITIES,ke as GRAPH_LLM_FAMILIES,He as GRAPH_LLM_PROVIDERS,n as GRAPH_NODE_CLASS,r as GraphContextChannel,J as GraphEngine,Ve as GraphLlm,a as GraphNode,m as GraphNodeRuntime,z as GraphRegistry,B as GraphStateSupport,L as LLM_GATEWAY_FACTORY,he as LangChainLlmGateway,E as LlmNode,Co as LlmResponseBlockedError,l as LlmRunner,Mo as LlmSetupError,ge as MemorySessionDocumentContainer,We as ModelCatalog,ye as ModelProvider,we as ModelProviderRegistry,Ce as MongoDbSessionDocumentContainer,pe as ProviderFileManager,Le as SESSION_BUSY,de as SESSION_COMPLETED,fe as SESSION_CONFLICT,le as SESSION_DOCUMENT_VERSION,re as SessionLogDecision,oe as SessionLogError,se as SessionLogWarning,Ee as SessionManager,xe as SessionTurnError,ue as SqliteSessionDocumentContainer,K as StateGraphExt,$ as TerminateSessionNode,p as Tool,io as TypeSafeClassifierAdapter,Eo as addDecisionUsage,qe as addTokenUsage,c as assertEmptyResponseRetries,Do as assertJsonCompatible,f as assertLlmTimeoutMs,C as assertMaxAgentRounds,W as createGraphStateAnnotation,te as createSessionLogs,I as currentTurnContext,G as currentTurnSignal,xo as decisionUsage,u as describeStopReason,U as direct,y as directTo,ie as drainSessionLogs,Lo as emptyDecisionUsage,Je as emptyTokenUsage,v as finish,F as go,_e as isLiveSessionTurn,A as isRetryableStopReason,Y as isToolResponse,Fe as langChainModelInitialization,Re as matchesSessionWritePredicate,Ie as mergeNodeStates,Qe as modelExecution,N as modelStopReason,fo as normalizeDecisionUsage,Xe as normalizeTokenUsage,Ge as replaceNodeStates,lo as resolveDecisionOptions,ne as restoreSessionLogs,co as retryWithModel,Te as sessionRevision,De as sessionTurnLeaseMs,H as stay,je as tokenUsageFromMessage,To as validateDecisionQuestions,_o as validateDecisionResult,ae as withSessionLogs,P as withTurnContext};
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
+
export { GraphContextChannel, type DeepReadonly } from "../../src/framework/graph-context.js";
|
|
1
2
|
export { BaseGraph, type GraphDefinition, type GraphNodeConstructor, type GraphSchemaMigration, type HistorySpace, } from "../../src/framework/base-graph.js";
|
|
2
3
|
export { GRAPH_NODE_CLASS, GraphNode, GraphNodeRuntime, Tool, type EmptyModelResponseContext, type GraphNodeUpdate, type GraphNodeResponse, type GraphNodeResult, type InvalidJsonResponseContext, type ToolDefinition, type ToolInput, type GraphNodeLocalState, type GraphNodeTarget, } from "../../src/framework/graph-node.js";
|
|
3
4
|
export { LlmNode, type LlmNodeRunResult, } from "../../src/framework/llm-node.js";
|
|
4
5
|
export { LLM_GATEWAY_FACTORY, assertLlmTimeoutMs, type LlmCallOptions, type LlmGateway, type LlmGatewayFactory, type LlmGatewayTool, type LlmGatewayToolCall, } from "../../src/framework/llm-gateway.js";
|
|
5
|
-
export {
|
|
6
|
+
export { LlmRunner, DEFAULT_LLM_POLICY, DEFAULT_EMPTY_HISTORY_SEED, DEFAULT_EMPTY_RESPONSE_RECOVERY, DEFAULT_MAX_AGENT_ROUNDS, EmptyModelResponseError, assertEmptyResponseRetries, assertMaxAgentRounds, type LlmPolicy, type LlmRunResult, type EmptyResponseRecovery, } from "../../src/framework/llm-runner.js";
|
|
6
7
|
export { describeStopReason, isRetryableStopReason, modelStopReason, type ModelStopCategory, type ModelStopReason, } from "../../src/framework/model-stop-reason.js";
|
|
7
8
|
export { currentTurnContext, currentTurnSignal, withTurnContext, type TurnContext, } from "../../src/framework/turn-context.js";
|
|
8
9
|
export { direct, directTo, finish, go, isToolResponse, stay, type ToolResponse, type ToolResponseBuilder, type ToolResponseKind, } from "../../src/framework/tool-response.js";
|
|
@@ -31,4 +32,4 @@ export { DecisionProvider, DecisionProviderRegistry, type BuiltinDecisionProvide
|
|
|
31
32
|
export { TypeSafeClassifierAdapter, type TypeSafeProviderOptions, } from "../../src/framework/decision/typesafe-provider.js";
|
|
32
33
|
export { DecisionConfigurationError, DecisionTimeoutError, DecisionValidationError, DEFAULT_DECISION_OPTIONS, addDecisionUsage, decisionUsage, emptyDecisionUsage, normalizeDecisionUsage, resolveDecisionOptions, type Choice, type ChoiceAnswer, type DecisionAnswer, type DecisionAnswers, type DecisionCallOptions, type DecisionContext, type DecisionConversation, type DecisionEvidence, type DecisionErrorContext, type DecisionFailure, type DecisionMetadata, type DecisionOptions, type DecisionProviderAdapter, type DecisionQuestion, type DecisionQuestionMap, type DecisionRequest, type DecisionResult, type DecisionState, type DecisionTokenUsage, type DecisionUsage, type JsonObject, type JsonPrimitive, type JsonValue, type Noul, type NoulAnswer, type ResolvedDecisionOptions, type Score, type ScoreAnswer, } from "../../src/framework/decision/decision-types.js";
|
|
33
34
|
export { assertJsonCompatible, validateDecisionQuestions, validateDecisionResult, } from "../../src/framework/decision/decision-validation.js";
|
|
34
|
-
export { retryWithModel, LlmResponseBlockedError, LlmSetupError, type LlmAttemptErrorContext, type LlmBlockedContext, type LlmBlockedResponse, type LlmErrorContext, type LlmErrorResponse, type RetryWithModelResponse, type
|
|
35
|
+
export { retryWithModel, LlmResponseBlockedError, LlmSetupError, type LlmAttemptErrorContext, type LlmBlockedContext, type LlmBlockedResponse, type LlmErrorContext, type LlmErrorResponse, type RetryWithModelResponse, type LlmLifecycle, type GraphLlmLifecycle, } from "../../src/framework/llm-lifecycle.js";
|
|
@@ -7,7 +7,8 @@ import type { GraphState } from "./graph-state.js";
|
|
|
7
7
|
import { StateGraphExt, type GraphNodeClass } from "./state-graph-ext.js";
|
|
8
8
|
import type { StateDefinitionInit } from "@langchain/langgraph";
|
|
9
9
|
import type { SessionDocument } from "./persistence/session-manager.js";
|
|
10
|
-
import {
|
|
10
|
+
import type { DeepReadonly, JsonObject } from "./graph-context.js";
|
|
11
|
+
import { type LlmPolicy } from "./llm-runner.js";
|
|
11
12
|
import type { GraphNodeLocalState, GraphNodeTarget } from "./node-outcome.js";
|
|
12
13
|
import type { DecisionOptions, DecisionErrorContext, DecisionProviderAdapter } from "./decision/decision-types.js";
|
|
13
14
|
export type HistorySpace = readonly [GraphNodeClass, string];
|
|
@@ -16,6 +17,7 @@ export type GraphSchemaMigration<State extends GraphState = GraphState> = Readon
|
|
|
16
17
|
migrate(sessionDoc: SessionDocument<State>): SessionDocument<State> | Promise<SessionDocument<State>>;
|
|
17
18
|
}>;
|
|
18
19
|
export type GraphDefinition<NodeId extends string = string, State extends GraphState = GraphState & {
|
|
20
|
+
context: JsonObject;
|
|
19
21
|
decisionUsage: NonNullable<GraphState["decisionUsage"]>;
|
|
20
22
|
}> = Readonly<{
|
|
21
23
|
llmConfig: GraphLlmConfig;
|
|
@@ -49,7 +51,7 @@ export declare abstract class BaseGraph<State extends GraphState> {
|
|
|
49
51
|
readonly requiresUserMessage: boolean;
|
|
50
52
|
readonly responseMode: "chat" | "json";
|
|
51
53
|
readonly maxAgentRounds: number;
|
|
52
|
-
readonly
|
|
54
|
+
readonly llmPolicy: LlmPolicy;
|
|
53
55
|
private compiledGraph?;
|
|
54
56
|
protected readonly runtime: GraphNodeRuntime<State>;
|
|
55
57
|
private readonly nodeMap;
|
|
@@ -69,6 +71,8 @@ export declare abstract class BaseGraph<State extends GraphState> {
|
|
|
69
71
|
};
|
|
70
72
|
prepareInput(state: State | undefined, message: HumanMessage): Partial<State>;
|
|
71
73
|
private initialNodeId;
|
|
74
|
+
getContext(): DeepReadonly<JsonObject>;
|
|
75
|
+
saveContext(patch: JsonObject): void;
|
|
72
76
|
saveNodeState<NodeClass extends GraphNodeTarget>(NodeClass: NodeClass, patch: Partial<GraphNodeLocalState<NodeClass>>): void;
|
|
73
77
|
restoreSessionDoc(sessionDoc: SessionDocument<State>): Promise<SessionDocument<State> | null>;
|
|
74
78
|
protected onRestoreSessionDoc(sessionDoc: SessionDocument<State>): Promise<SessionDocument<State> | null>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { LlmRunResult } from "../llm-runner.js";
|
|
2
2
|
import { GraphNode, type GraphNodeResponse, type GraphNodeResult } from "../graph-node.js";
|
|
3
3
|
import type { GraphState } from "../graph-state.js";
|
|
4
4
|
import { type DecisionAnswers, type DecisionContext, type DecisionEvidence, type DecisionErrorContext, type DecisionOptions, type DecisionQuestionMap } from "./decision-types.js";
|
|
@@ -13,5 +13,5 @@ export declare abstract class DecisionNode<State extends GraphState, Questions e
|
|
|
13
13
|
validateTools(): void;
|
|
14
14
|
private assertNoChatConfiguration;
|
|
15
15
|
protected usesChatModel(): boolean;
|
|
16
|
-
protected
|
|
16
|
+
protected runLlm(_state: State, _context: Record<string, unknown>): Promise<LlmRunResult>;
|
|
17
17
|
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { JsonObject } from "./decision/decision-types.js";
|
|
2
|
+
import { BaseChannel } from "@langchain/langgraph";
|
|
3
|
+
export type { JsonValue, JsonObject } from "./decision/decision-types.js";
|
|
4
|
+
export type DeepReadonly<T> = T extends readonly (infer Item)[] ? readonly DeepReadonly<Item>[] : T extends object ? {
|
|
5
|
+
readonly [Key in keyof T]: DeepReadonly<T[Key]>;
|
|
6
|
+
} : T;
|
|
7
|
+
export declare class GraphContextChannel extends BaseChannel<JsonObject, JsonObject, JsonObject> {
|
|
8
|
+
lc_graph_name: string;
|
|
9
|
+
private value;
|
|
10
|
+
constructor(initial?: JsonObject);
|
|
11
|
+
fromCheckpoint(checkpoint?: JsonObject): this;
|
|
12
|
+
update(values: JsonObject[]): boolean;
|
|
13
|
+
get(): JsonObject;
|
|
14
|
+
checkpoint(): JsonObject;
|
|
15
|
+
isAvailable(): boolean;
|
|
16
|
+
}
|
|
17
|
+
export declare function cloneJsonObject(value: unknown, label?: string): JsonObject;
|
|
18
|
+
export declare function readonlyContext(value: unknown): DeepReadonly<JsonObject>;
|
|
@@ -8,7 +8,7 @@ import { SessionManager, type SessionDocument } from "./persistence/session-mana
|
|
|
8
8
|
import type { DecisionProviderAdapter } from "./decision/decision-types.js";
|
|
9
9
|
export type GraphConstructor = {
|
|
10
10
|
new (llmGateway: LlmGateway): RegisteredGraph;
|
|
11
|
-
getGraphDefinition(): GraphDefinition
|
|
11
|
+
getGraphDefinition(): GraphDefinition<string, GraphState>;
|
|
12
12
|
};
|
|
13
13
|
export type GraphEngineOptions = Readonly<{
|
|
14
14
|
sessionManager?: SessionManager;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { LlmLifecycle, GraphLlmLifecycle } from "./llm-lifecycle.js";
|
|
2
2
|
import type { GraphState } from "./graph-state.js";
|
|
3
|
+
import type { DeepReadonly, JsonObject } from "./graph-context.js";
|
|
3
4
|
import type { LlmCallOptions, LlmGateway, LlmGatewayTool } from "./llm-gateway.js";
|
|
4
5
|
import "reflect-metadata";
|
|
5
6
|
import { type BaseMessage } from "@langchain/core/messages";
|
|
@@ -8,7 +9,7 @@ import { Command } from "@langchain/langgraph";
|
|
|
8
9
|
import { type GraphLlmConfig, type GraphLlmConfigOverride } from "./graph-llm.config.js";
|
|
9
10
|
import type { NodeStateValue } from "./node-state.js";
|
|
10
11
|
import { GraphStateSupport } from "./graph-state-support.js";
|
|
11
|
-
import { type
|
|
12
|
+
import { type LlmPolicy, type LlmRunResult } from "./llm-runner.js";
|
|
12
13
|
import type { ModelStopReason } from "./model-stop-reason.js";
|
|
13
14
|
import { GRAPH_NODE_LOCAL_STATE, type GraphNodeLocalState, type GraphNodeTarget, type GraphNodeUpdate } from "./node-outcome.js";
|
|
14
15
|
import { type ToolResponse } from "./tool-response.js";
|
|
@@ -26,7 +27,7 @@ export type InvalidJsonResponseContext<State extends GraphState> = Readonly<{
|
|
|
26
27
|
}>;
|
|
27
28
|
export type EmptyModelResponseContext<State extends GraphState> = Readonly<{
|
|
28
29
|
state: Readonly<State>;
|
|
29
|
-
conversation: Readonly<
|
|
30
|
+
conversation: Readonly<LlmRunResult>;
|
|
30
31
|
reason: ModelStopReason;
|
|
31
32
|
}>;
|
|
32
33
|
export declare const GRAPH_NODE_CLASS: unique symbol;
|
|
@@ -57,8 +58,8 @@ export declare abstract class GraphNode<State extends GraphState, LocalState ext
|
|
|
57
58
|
validateTools(): void;
|
|
58
59
|
protected llmConfig(): GraphLlmConfig;
|
|
59
60
|
protected llmCallOptions(): LlmCallOptions;
|
|
60
|
-
protected
|
|
61
|
-
protected
|
|
61
|
+
protected runLlm(state: State, context: ToolContext): Promise<LlmRunResult>;
|
|
62
|
+
protected llmLifecycle(): LlmLifecycle | undefined;
|
|
62
63
|
private runAgentLoop;
|
|
63
64
|
protected historySpace(): string;
|
|
64
65
|
protected history(state: Pick<State, "histories">): BaseMessage[];
|
|
@@ -80,12 +81,13 @@ export declare class GraphNodeRuntime<State extends GraphState> extends GraphSta
|
|
|
80
81
|
private readonly historySpaces;
|
|
81
82
|
private readonly responseMode;
|
|
82
83
|
readonly maxAgentRounds: number;
|
|
83
|
-
readonly
|
|
84
|
+
readonly llmPolicy: LlmPolicy;
|
|
84
85
|
private readonly decisionOptions;
|
|
85
86
|
private readonly decisionErrorHandler?;
|
|
86
87
|
readonly llmLifecycle?: GraphLlmLifecycle | undefined;
|
|
88
|
+
private readonly assertContextChannel?;
|
|
87
89
|
private readonly tools;
|
|
88
|
-
constructor(endNode: State["currentNode"], defaultLlmConfig: GraphLlmConfig, historySpaces?: Readonly<Record<string, string>>, responseMode?: "chat" | "json", maxAgentRounds?: number,
|
|
90
|
+
constructor(endNode: State["currentNode"], defaultLlmConfig: GraphLlmConfig, historySpaces?: Readonly<Record<string, string>>, responseMode?: "chat" | "json", maxAgentRounds?: number, llmPolicy?: LlmPolicy, decisionOptions?: DecisionOptions, decisionErrorHandler?: ((context: DecisionErrorContext<State>) => GraphNodeResponse<State> | null | Promise<GraphNodeResponse<State> | null>) | undefined, llmLifecycle?: GraphLlmLifecycle | undefined, assertContextChannel?: (() => void) | undefined);
|
|
89
91
|
llmCallOptions(): LlmCallOptions;
|
|
90
92
|
expectsJsonResponse(): boolean;
|
|
91
93
|
historySpace(currentNode?: string): string;
|
|
@@ -113,6 +115,9 @@ export declare class GraphNodeRuntime<State extends GraphState> extends GraphSta
|
|
|
113
115
|
nodeState(nodeName: string): Record<string, unknown>;
|
|
114
116
|
hasInvocation(): boolean;
|
|
115
117
|
graphState(): State;
|
|
118
|
+
getContext(): DeepReadonly<JsonObject>;
|
|
119
|
+
saveContext(patch: JsonObject): void;
|
|
120
|
+
stageContext(context: JsonObject): void;
|
|
116
121
|
appendHistory(space: string, messages: readonly BaseMessage[]): void;
|
|
117
122
|
invocationHistory(space: string): BaseMessage[];
|
|
118
123
|
stagedUpdate(): GraphNodeUpdate<State>;
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import type { BaseMessage } from "@langchain/core/messages";
|
|
2
|
+
import { GraphContextChannel } from "./graph-context.js";
|
|
3
|
+
import type { JsonObject } from "./graph-context.js";
|
|
2
4
|
import { type GraphNodeStates } from "./node-state.js";
|
|
3
5
|
import { type TokenUsage } from "./token-usage.js";
|
|
4
6
|
import { type DecisionUsage } from "./decision/decision-types.js";
|
|
@@ -7,6 +9,7 @@ export type GraphState<CurrentNode extends string = string, Nodes extends object
|
|
|
7
9
|
histories: Record<string, BaseMessage[]>;
|
|
8
10
|
currentNode: CurrentNode;
|
|
9
11
|
config: Record<string, unknown>;
|
|
12
|
+
context?: JsonObject;
|
|
10
13
|
nodes: Nodes;
|
|
11
14
|
tokens: TokenUsage;
|
|
12
15
|
decisionUsage?: DecisionUsage;
|
|
@@ -15,6 +18,7 @@ export type GraphState<CurrentNode extends string = string, Nodes extends object
|
|
|
15
18
|
completed: boolean;
|
|
16
19
|
};
|
|
17
20
|
export declare function createGraphStateAnnotation<CurrentNode extends string = string, Nodes extends object = GraphNodeStates>(defaultCurrentNode: string, createInitialNodes?: () => Nodes): import("@langchain/langgraph").AnnotationRoot<{
|
|
21
|
+
context: GraphContextChannel;
|
|
18
22
|
histories: import("@langchain/langgraph").BaseChannel<Record<string, BaseMessage<import("@langchain/core/messages").MessageStructure<import("@langchain/core/messages").MessageToolSet>, import("@langchain/core/messages").MessageType>[]>, Record<string, BaseMessage<import("@langchain/core/messages").MessageStructure<import("@langchain/core/messages").MessageToolSet>, import("@langchain/core/messages").MessageType>[]> | import("@langchain/langgraph").OverwriteValue<Record<string, BaseMessage<import("@langchain/core/messages").MessageStructure<import("@langchain/core/messages").MessageToolSet>, import("@langchain/core/messages").MessageType>[]>>, unknown>;
|
|
19
23
|
currentNode: import("@langchain/langgraph").BaseChannel<CurrentNode, CurrentNode | import("@langchain/langgraph").OverwriteValue<CurrentNode>, unknown>;
|
|
20
24
|
config: import("@langchain/langgraph").BaseChannel<Record<string, unknown>, Record<string, unknown> | import("@langchain/langgraph").OverwriteValue<Record<string, unknown>>, unknown>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { AIMessage } from "@langchain/core/messages";
|
|
2
|
-
import type
|
|
2
|
+
import { type GraphLlmConfig } from "./graph-llm.config.js";
|
|
3
3
|
import type { ToolResponse } from "./tool-response.js";
|
|
4
4
|
export type LlmAttemptErrorContext = Readonly<{
|
|
5
5
|
nodeId: string;
|
|
@@ -51,11 +51,11 @@ export declare class LlmResponseBlockedError extends Error {
|
|
|
51
51
|
export declare class LlmSetupError extends Error {
|
|
52
52
|
constructor(cause: unknown);
|
|
53
53
|
}
|
|
54
|
-
export type
|
|
54
|
+
export type LlmLifecycle = Readonly<{
|
|
55
55
|
nodeId: string;
|
|
56
56
|
checkResponse(response: string | object): boolean;
|
|
57
57
|
onLlmBlocked(context: LlmBlockedContext): Promise<LlmBlockedResponse | null>;
|
|
58
58
|
shouldRetryLlmError(context: LlmAttemptErrorContext): boolean | undefined;
|
|
59
59
|
onLlmError(context: LlmErrorContext): Promise<LlmErrorResponse | null>;
|
|
60
60
|
}>;
|
|
61
|
-
export type GraphLlmLifecycle = Pick<
|
|
61
|
+
export type GraphLlmLifecycle = Pick<LlmLifecycle, "onLlmBlocked" | "shouldRetryLlmError" | "onLlmError">;
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type {
|
|
1
|
+
import type { LlmLifecycle, LlmAttemptErrorContext, LlmBlockedContext, LlmBlockedResponse, LlmErrorContext, LlmErrorResponse } from "./llm-lifecycle.js";
|
|
2
|
+
import type { LlmRunResult } from "./llm-runner.js";
|
|
3
3
|
import { GraphNode, type GraphNodeResult } from "./graph-node.js";
|
|
4
4
|
import type { GraphState } from "./graph-state.js";
|
|
5
5
|
import { type ToolResponse } from "./tool-response.js";
|
|
6
|
-
export type LlmNodeRunResult =
|
|
6
|
+
export type LlmNodeRunResult = LlmRunResult;
|
|
7
7
|
export declare abstract class LlmNode<State extends GraphState> extends GraphNode<State> {
|
|
8
8
|
checkResponse(_llmResult: string | object): boolean;
|
|
9
9
|
onLlmBlocked(_context: LlmBlockedContext): Promise<LlmBlockedResponse | null>;
|
|
10
10
|
shouldRetryLlmError(_context: LlmAttemptErrorContext): boolean | undefined;
|
|
11
11
|
onLlmError(_context: LlmErrorContext): Promise<LlmErrorResponse | null>;
|
|
12
|
-
protected
|
|
12
|
+
protected llmLifecycle(): LlmLifecycle;
|
|
13
13
|
protected endChat(input: {
|
|
14
14
|
message?: string;
|
|
15
15
|
}): Promise<ToolResponse>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type
|
|
1
|
+
import { type LlmLifecycle } from "./llm-lifecycle.js";
|
|
2
2
|
import { type BaseMessage } from "@langchain/core/messages";
|
|
3
3
|
import type { ToolCall } from "@langchain/core/messages/tool";
|
|
4
4
|
import type { GraphLlmConfig } from "./graph-llm.config.js";
|
|
@@ -6,7 +6,7 @@ import type { LlmCallOptions, LlmGateway, LlmGatewayTool } from "./llm-gateway.j
|
|
|
6
6
|
import { type TokenUsage } from "./token-usage.js";
|
|
7
7
|
import { type ToolResponse } from "./tool-response.js";
|
|
8
8
|
import { type ModelStopReason } from "./model-stop-reason.js";
|
|
9
|
-
export type
|
|
9
|
+
export type LlmRunResult = {
|
|
10
10
|
messages: BaseMessage[];
|
|
11
11
|
usage: TokenUsage;
|
|
12
12
|
response?: string;
|
|
@@ -27,17 +27,17 @@ export type EmptyResponseRecovery = Readonly<{
|
|
|
27
27
|
}>;
|
|
28
28
|
export declare const DEFAULT_EMPTY_RESPONSE_RECOVERY: EmptyResponseRecovery;
|
|
29
29
|
export declare function assertEmptyResponseRetries(value: number): number;
|
|
30
|
-
export type
|
|
30
|
+
export type LlmPolicy = Readonly<{
|
|
31
31
|
llmTimeoutMs?: number;
|
|
32
32
|
emptyHistorySeed: string | null;
|
|
33
33
|
emptyResponseRecovery: EmptyResponseRecovery | null;
|
|
34
34
|
}>;
|
|
35
|
-
export declare const
|
|
36
|
-
export declare class
|
|
35
|
+
export declare const DEFAULT_LLM_POLICY: LlmPolicy;
|
|
36
|
+
export declare class LlmRunner {
|
|
37
37
|
private readonly llmGateway;
|
|
38
38
|
constructor(llmGateway: LlmGateway);
|
|
39
39
|
run(options: {
|
|
40
|
-
lifecycle?:
|
|
40
|
+
lifecycle?: LlmLifecycle;
|
|
41
41
|
systemPrompt: string;
|
|
42
42
|
history: readonly BaseMessage[];
|
|
43
43
|
tools: readonly LlmGatewayTool[];
|
|
@@ -47,5 +47,5 @@ export declare class ConversationRunner {
|
|
|
47
47
|
emptyHistorySeed?: string | null;
|
|
48
48
|
emptyResponseRecovery?: EmptyResponseRecovery | null;
|
|
49
49
|
callOptions?: LlmCallOptions;
|
|
50
|
-
}): Promise<
|
|
50
|
+
}): Promise<LlmRunResult>;
|
|
51
51
|
}
|
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
import type { BaseMessage } from "@langchain/core/messages";
|
|
2
2
|
import type { GraphState } from "./graph-state.js";
|
|
3
|
+
import { type DeepReadonly, type JsonObject } from "./graph-context.js";
|
|
3
4
|
export declare function hasNodeInvocation(owner: object): boolean;
|
|
4
5
|
export declare function withNodeInvocation<State extends GraphState, Result>(owner: object, nodeId: string, state: State, run: () => Promise<Result>): Promise<Result>;
|
|
5
6
|
export declare function invocationNodeId(owner: object): string;
|
|
7
|
+
export declare function invocationContext(owner: object): DeepReadonly<JsonObject>;
|
|
8
|
+
export declare function saveInvocationContext(owner: object, patch: JsonObject): void;
|
|
9
|
+
export declare function replaceInvocationContext(owner: object, context: JsonObject): void;
|
|
6
10
|
export declare function invocationNodeState(owner: object, nodeId: string): Record<string, unknown>;
|
|
7
11
|
export declare function saveInvocationNodeState(owner: object, nodeId: string, patch: Record<string, unknown>): void;
|
|
8
12
|
export declare function replaceInvocationNodeState(owner: object, nodeId: string, value: Record<string, unknown>): void;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { type StoredMessage } from '@langchain/core/messages';
|
|
2
2
|
import { ConfigManager } from '../config-manager.js';
|
|
3
3
|
import { type GraphState } from '../graph-state.js';
|
|
4
|
+
import { type JsonObject } from '../graph-context.js';
|
|
4
5
|
import { type GraphLlmConfig, type GraphLlmModelMetadata } from '../graph-llm.config.js';
|
|
5
6
|
import { type SessionLogs } from '../session-log.js';
|
|
6
7
|
import { type TokenUsage } from '../token-usage.js';
|
|
@@ -42,6 +43,7 @@ export type SessionGraphDocument<State extends GraphState = GraphState> = {
|
|
|
42
43
|
schemaVersion: number;
|
|
43
44
|
currentNode?: State['currentNode'];
|
|
44
45
|
config?: State['config'];
|
|
46
|
+
context?: JsonObject;
|
|
45
47
|
histories: Record<string, StoredMessage[]>;
|
|
46
48
|
nodes?: State['nodes'];
|
|
47
49
|
model: GraphLlmModelMetadata;
|
package/package.json
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
const qR=k;(function(L,z){const qU={L:0x1a7,z:0x19f,R:0x1b5,c:0x170,g:0x16f,t:0x185},qz=k,R=L();while(!![]){try{const c=parseInt(qz(qU.L))/0x1*(-parseInt(qz(0x1b7))/0x2)+-parseInt(qz(qU.z))/0x3*(-parseInt(qz(0x169))/0x4)+parseInt(qz(0x1cd))/0x5*(-parseInt(qz(0x1bd))/0x6)+parseInt(qz(qU.R))/0x7*(-parseInt(qz(qU.c))/0x8)+parseInt(qz(0x196))/0x9*(-parseInt(qz(0x1d2))/0xa)+parseInt(qz(qU.g))/0xb+parseInt(qz(qU.t))/0xc;if(c===z)break;else R['push'](R['shift']());}catch(g){R['push'](R['shift']());}}}(q,0x506a6));var V=Object[qR(0x168)],s=(L,z)=>V(L,'name',{'value':z,'configurable':!0x0});import{setTimeout as d}from'node:timers/promises';import{GraphLlm as T,ModelCatalog as y}from'./graph-llm.config.js';import{LlmResponseBlockedError as l,LlmSetupError as e}from'./llm-lifecycle.js';import{AIMessage as v,HumanMessage as B,ToolMessage as w}from'@langchain/core/messages';import{addTokenUsage as D,emptyTokenUsage as o}from'./token-usage.js';import{isToolResponse as a}from'./tool-response.js';import{describeStopReason as u,isRetryableStopReason as n,modelStopReason as m}from'./model-stop-reason.js';import{SessionLogWarning as E}from'./session-log.js';import{isOpenAIAuthConfig as C,openAIAuthMessageText as p}from'./openai-auth-provider.js';function q(){const kd=['Aw1Hz2vFB3rOzxi','DhjPBq','CMvZCg9UC2vFCMvQzwn0zwq','A2LUza','mZC0nda0ogfzv3fmEa','mtuXmtiWz1jsC2ni','CMvZB2X2zunVBMzPzW','zw50CMLLCW','y29UDgvUDa','B2jQzwn0','CMvZB2X2zu1VzgvSrgvZy3jPChrVCG','DgHYB3DjzKfIB3j0zwq','rw1WDhLnB2rLBfjLC3bVBNnLrxjYB3i','y2XLyw51Cef0DgfJAg1LBNrZ','BM9KzuLK','AxnjBNrLz2vY','BgXTr2f0zxDHEq','CMf0Aw5NCW','ywDLBNq','ChjVBxb0qMXVy2TLzenVBNrLEhq','B25mBg1fCNjVCG','D2fPDezVCLjLDhj5','Bwf4qwDLBNrsB3vUzhm','yxbWBhLszwnVDMvYEq','vgHLig1VzgvSihjLC3bVBNnLihDHCYbYzwPLy3rLzcbIEsbJAgvJA1jLC3bVBNnLkcKU','zMvLzgjHy2S','mteWnta0odHxALjHzu8','BwvZC2fNzxm','CMvWBgfJzufSBa','Bw9KzwW','yMXVy2TFCMvHC29U','BNvKz2u','C3rYAw5NAwz5','ywnXDwLYzunHBMrPzgf0zq','y2HLy2TszxnWB25Zzq','Aw5JBhvKzxm','Aw52B2nHDgLVBKnVBMzPzW','AxnbCNjHEq','C2HVDwXKuMv0CNLmBg1fCNjVCG','rM9SBg93ihrOzsbZExn0zw0GChjVBxb0igfUzcbYzxnWB25KihbYB3bLCMX5lIbvC2uGDgHLihjLCxvPCMvKihrVB2WGD2HLBIbPBNn0CNvJDgvKlG','yxnZzxj0twf4qwDLBNrsB3vUzhm','zw1WDhLszxnWB25ZzvjLy292zxj5lNjLDhjPzxmGBxvZDcbIzsbHig5VBI1UzwDHDgL2zsbPBNrLz2vYoYbYzwnLAxzLzca','ywrKAxrPB25HBf9RD2fYz3m','nJnWDezQruy','B3rOzxi','yxnZzxj0rw1WDhLszxnWB25ZzvjLDhjPzxm','y2XLyw51Ca','CMv0CNLxAxrOtw9KzwWOksbTyxKGyMuGCMv0DxjUzwqGB25SEsbVBMnLigLUigeGCMvJB3zLCNKGC2vXDwvUy2uU','CMv0CNLxAxrOtw9KzwWOksbPCYbZDxbWB3j0zwqGB25SEsbIEsbVBKXSBuvYCM9YkcKU','zw1WDhLszxnWB25ZzvjLy292zxj5','BM9YBwfSAxPLuMvHC29U','Cg9W','mZu0m1ngCLbsuG','BgvUz3rO','ChjVBxb0','CgfYyw1Z','C3rVCf9KzxrHAwXZ','CMvZCg9UC2u','CMv0CNLFD2L0Af9TB2rLBa','ChvZAa','nKnrD0rMzW','u3rHCNq','BwvZC2fNzq','CMvHC29U','yMXVy2TLza','AgfZq2fUzgLKyxrLq29UDgvUDa','CMv0CNLFzgvJBgLUzwq','y2fUzgLKyxrL','Axntyw1LqMfYzvrYyw5ZAxrPB24','zw1WDhLiAxn0B3j5u2vLza','zxHLy3v0zvrVB2W','DgfYz2v0','Aw50zxjUywXiDw1HBK1LC3nHz2u','AgLZDg9YEq','mZvlCNL6AgC','igfNzw50ihjVDw5KCY4','mty1nZm0uwD6z2Lv','yxr0zw1WDhnFzxHOyxvZDgvK','BwfW','CMvMDxnHBa','ChjVDMLKzxi','Dgv4Da','mty2mLvlAKDZvG','Dg9VBc1JywXSlq','zgv0ywLS','y2fSBe9WDgLVBNm','q29UDMvYC2f0Aw9Uigv4y2vLzgvKia','C3rYAw5N','Bwf4qwDLBNrsB3vUzhmGBxvZDcbIzsbHihbVC2L0AxzLigLUDgvNzxi7ihjLy2vPDMvKia','B25mBg1cBg9JA2vK','CMvZCg9UC2vuzxH0','BMfTzq','yMXVy2TszwfZB24','DMfSAwrHDgvdB25MAwC','BgLMzwn5y2XL','C3rHDgu','CMv0CMLLCW','BgXTq29UzMLN','ntG0nu1ct2jsAW','DxnHz2u','ywXSu2v0DgXLza','C3rHEq','Dg9VBhm','mJG5otKWvKnvAeP6','y29TBw9Uq29UDgv4Da','Aw52B2nHDgLVBL9LCNjVCG','vgHLig1VzgvSihjLDhvYBMvKigfUigvTChr5ihjLC3bVBNnLicG','zw1WDhLFCMvZCg9UC2u','Dg9VBf9JywXSCW','teXnihjLy292zxj5ignHBM5VDcbYzxr1CM4GDg9VBc1VBMX5ihn0yxKOksWGy2XLyw51CcWGB3iGzMvLzgjHy2SU','DMfSDwu','zgvMAw5LuhjVCgvYDhK','nJmYquvQzxbW','C2fMzxr5uMf0Aw5NCW'];q=function(){return kd;};return q();}class le extends Error{static{s(this,qR(0x177));}[qR(0x1aa)];constructor(L){const qO={L:0x177},qc=qR;super(qc(0x163)+u(L)+').'),this[qc(0x1aa)]=L,this[qc(0x1c6)]=qc(qO.L);}}const de=0x8;function ce(L){const qF={L:0x17a},qg=qR;if(!Number[qg(qF.L)](L)||L<0x1)throw new Error(qg(0x1c3)+String(L)+'.');return L;}s(ce,qR(0x193));const H=qR(0x1a8),P={'retries':0x2,'nudge':qR(0x192)};function ue(L){const qS={L:0x17a},qt=qR;if(!Number[qt(qS.L)](L)||L<0x0)throw new Error(qt(0x194)+String(L)+'.');return L;}s(ue,qR(0x198));function k(d,G){d=d-0x161;const T=q();let y=T[d];if(k['dhKmNQ']===undefined){var l=function(B){const w='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+/=';let K='',j='';for(let D=0x0,o,a,N=0x0;a=B['charAt'](N++);~a&&(o=D%0x4?o*0x40+a:a,D++%0x4)?K+=String['fromCharCode'](0xff&o>>(-0x2*D&0x6)):0x0){a=w['indexOf'](a);}for(let u=0x0,P=K['length'];u<P;u++){j+='%'+('00'+K['charCodeAt'](u)['toString'](0x10))['slice'](-0x2);}return decodeURIComponent(j);};k['epnwKt']=l,k['xWcWkK']={},k['dhKmNQ']=!![];}const e=T[0x0],X=d+e,v=k['xWcWkK'][X];return!v?(y=k['epnwKt'](y),k['xWcWkK'][X]=y):y=v,y;}const ke={'emptyHistorySeed':H,'emptyResponseRecovery':P};class Te{static{s(this,'ConversationRunner');}[qR(0x17b)];constructor(L){const qA=qR;this[qA(0x17b)]=L;}async['run'](z){const k3={L:0x1b0,z:0x1b4,R:0x1a0,c:0x19c,g:0x1cb,t:0x1cc,A:0x1c9,r:0x161,f:0x167,i:0x1a6,h:0x16c,W:0x167,M:0x19e,x:0x1a6,O:0x18a,b:0x16e,I:0x1be,q0:0x186,q1:0x1a6,q2:0x1a6,q3:0x176,q4:0x16e,q5:0x1d0,q6:0x1a6,q7:0x1c1,q8:0x1b6},k2={L:0x1cf,z:0x1b9},k1={L:0x176,z:0x1a2,R:0x17b,c:0x17d,g:0x1d1,t:0x191,A:0x162,r:0x17f,f:0x1ab,i:0x16b,h:0x1bb,W:0x1ae,M:0x190,x:0x195,O:0x1a3,b:0x167,I:0x167,q0:0x1bf,q1:0x167,q2:0x16d},k0={L:0x176,z:0x1c4},qI={L:0x16e,z:0x19a,R:0x184,c:0x166,g:0x1c2,t:0x186,A:0x1a6},qr=qR,q0=z[qr(k3.L)]===void 0x0?H:z[qr(0x1b0)],q1=z[qr(k3.z)][qr(k3.R)]===0x0&&q0!==null,q2=q1?[$(q0)]:[...z[qr(k3.z)]],q3=q1?[...q2]:[];let q4=[],q5=o();const q6=ce(z[qr(0x181)]??de),q7=z[qr(k3.c)]===void 0x0?P:z[qr(0x19c)],q8=q7?ue(q7[qr(k3.g)]):0x0;let q9=0x0,qq=z[qr(k3.t)],qk=!0x1;const qd=z[qr(k3.A)],qG=z[qr(0x1c0)]?.['signal'],qT=s(()=>qd?T[qr(0x171)](qq,{'params':{'retries':0x0}}):qq,qr(0x18f)),qy=s(()=>({'nodeId':qd[qr(0x179)],'provider':y[qr(0x175)](qq)['provider'],'model':qq[qr(0x188)],...qG===void 0x0?{}:{'signal':qG}}),qr(k3.r)),ql=s(async(qB,qw)=>{const qf=qr;if(qG?.['throwIfAborted'](),qB===null)throw qw;if(typeof qB=='object'&&qB[qf(qI.L)]===qf(0x1a5)){if(qk)throw new Error(qf(qI.z),{'cause':qw});qq=T[qf(0x1c8)](qB[qf(0x188)]),qk=!0x0,q9=0x0;return;}const qK=typeof qB==qf(0x1c2)?void 0x0:qB;if(qK&&(qK[qf(0x16e)]===qf(0x1d0)||qK[qf(0x199)]||qK[qf(qI.R)]!==void 0x0))throw new Error(qf(qI.c));const qj=typeof qB==qf(qI.g)?qB:qK?.[qf(0x1a4)];return qK?.[qf(0x186)]&&q3[qf(0x1a6)](...qK[qf(qI.t)]),qj!==void 0x0&&q3[qf(qI.A)](new v(qj)),{'messages':q3,'usage':q5,'stoppedAfterTool':!0x1,...qj===void 0x0?{}:{'response':qj},...qK===void 0x0?{}:{'toolResponse':qK}};},qr(0x182)),qe=s(async(qB,qw)=>{const qi=qr;qG?.[qi(k0.L)]();const qK=await qd[qi(k0.z)](qB);if(qG?.[qi(0x176)](),typeof qK==qi(0x174)&&qK!==null&&qK['kind']==='retry_with_model')throw new Error(qi(0x19b));return await ql(qK,new l(qB,qw));},'handleBlocked'),qX=s(async()=>{const qh=qr;let qB=0x0;for(;;){qG?.[qh(k1.L)]();const qw=qk?0x1:Number(qq[qh(k1.z)]['retries'])+0x1;qB+=0x1;let qK;const qj=qT();try{qK=await this[qh(k1.R)][qh(k1.c)](z['systemPrompt'],q2,z[qh(k1.g)],qj,z['callOptions']);}catch(qu){if(qG?.[qh(0x176)](),!qd||qu instanceof e)throw qu;const qP=ye(qu,qy());if(qP)return qe(qP,qu);const qn=qu instanceof Error?qu:new Error(String(qu)),qm=qd[qh(k1.t)]({...qy(),'error':qn,'attempt':qB,'maxAttempts':qw});if(qG?.[qh(0x176)](),qm!==!0x1&&qB<qw){await Y(qG);continue;}const qV={...qy(),'kind':qh(k1.A),'error':qn,'attemptsMade':qB,'maxAttempts':qw,'stoppedBecause':qm===!0x1?qh(0x1ad):qh(0x1b8)},qE=await ql(await qd[qh(k1.r)](qV),qn);if(qE)return qE;qB=0x0;continue;}if(qG?.['throwIfAborted'](),q5=D(q5,qK[qh(0x1ce)]),!qd)return qK;const qD=m(qK[qh(0x167)]);if(qD['category']===qh(k1.f)||[qh(0x197),qh(k1.i)][qh(0x18e)](S(qD[qh(k1.h)]??'')))return qe({...qy(),'phase':qh(k1.W),'rawReason':qD[qh(k1.h)]??'refusal','reason':S(qD['provider']??qh(0x1ba)),...Array[qh(k1.M)](qD[qh(0x17c)])?{'safetyRatings':qD['ratings']}:{},...(qK['value']['response_metadata'][qh(0x1a3)]??qK[qh(0x167)][qh(k1.x)][qh(k1.O)]??qD[qh(0x1bf)])===void 0x0?{}:{'providerDetails':qK[qh(k1.b)]['response_metadata']['stop_details']??qK[qh(k1.I)][qh(0x195)][qh(0x1a3)]??qD[qh(k1.q0)]}});if(!G(qK[qh(k1.I)]))return qK;const qo=qd[qh(0x18d)](qK[qh(k1.q1)]);if(qG?.['throwIfAborted'](),!qo)return qK;if(qB<qw){await Y(qG);continue;}const qa=new Error(qh(0x183)),qN=await ql(await qd[qh(0x17f)]({...qy(),'kind':qh(k1.q2),'error':qa,'attemptsMade':qB,'maxAttempts':qw,'stoppedBecause':qh(0x1b8),'lastResponse':qK['value']}),qa);if(qN)return qN;qB=0x0;}},qr(0x18c));try{for(let qB=0x0;qB<q6;qB+=0x1){const qw=await qX();if(!(qr(k3.f)in qw))return qw;q3[qr(k3.i)](qw[qr(0x167)]),q2['push'](qw[qr(k3.f)]);const qK=qw[qr(0x167)]['tool_calls']??[];if(qK['length']===0x0){const qo=me(qw[qr(k3.f)],qq);if(qo[qr(k3.h)]()&&(!qd||G(qw[qr(0x167)])))return await qv(),{'messages':q3,'usage':q5,'response':qo,'stoppedAfterTool':!0x1};const qa=m(qw[qr(k3.W)]),qN=n(qa)&&q7!==null&&q9<q8&&!qk&&(!qd||qB+0x1<q6);if(E({'empty_model_response':u(qa),'retried':qN}),qN&&q7){q9+=0x1,q3[qr(k3.M)](),q2[qr(0x19e)](),q2[qr(k3.x)]($(q7[qr(k3.O)]));continue;}if(qd){q3[qr(0x19e)](),q2[qr(0x19e)]();const qu=new le(qa),qP=await ql(await qd['onLlmError']({...qy(),'kind':qr(0x164),'error':qu,'attemptsMade':q9+0x1,'maxAttempts':qk?0x1:Math['min'](q8+0x1,q9+q6-qB),'stoppedBecause':'attempts_exhausted','lastResponse':qw[qr(0x167)]}),qu);if(qP)return qP;qB-=0x1;continue;}return await qv(),{'messages':q3,'usage':q5,'response':qo,'stoppedAfterTool':!0x1,'stopReason':qa};}await qv();let qj=!0x1,qD;try{for(const [qn,qm]of qK[qr(0x172)]()){qG?.[qr(0x176)]();const qV=await z[qr(0x1b1)](qm);if(a(qV)){if(qV[qr(0x16e)]!==qr(0x1d0)){if(qD&&qD[qr(k3.b)]!==qr(0x1d0)&&!pe(qD,qV))throw new Error('A\x20tool\x20batch\x20selected\x20more\x20than\x20one\x20terminal\x20response\x20or\x20transition.');qD=qV;}else qD||(qD=qV);const qE=new w({'content':qV['feedback']??'OK','tool_call_id':qm['id']??qr(k3.I)+qB+'-'+qn,'name':qm['name']});q3['push'](qE),q2[qr(k3.x)](qE),qV[qr(k3.q0)]&&(q3[qr(k3.q1)](...qV[qr(k3.q0)]),q2[qr(k3.q2)](...qV['messages'])),qV[qr(0x199)]&&q4['push'](qV[qr(0x199)]),qG?.[qr(k3.q3)](),qj||=qV[qr(k3.q4)]!==qr(k3.q5);continue;}}}catch(qC){throw await qv(),qC;}if(qj){const qp=qD?.['response'];if(qp){const qJ=new v(qp);q3[qr(k3.q6)](qJ),q2[qr(0x1a6)](qJ);}return await qv(),{'messages':q3,'usage':q5,'stoppedAfterTool':!0x0,...qp?{'response':qp}:{},...qD?{'toolResponse':qD}:{}};}}throw await qv(),new Error(qr(k3.q7)+q6+qr(k3.q8));}finally{await qv();}async function qv(){const qQ=qr,qs=q4;q4=[],await Promise[qQ(k2.L)](qs[qQ(k2.z)](qL=>qL()));}s(qv,qr(0x178));}}function pe(L,z){const k4={L:0x16e,z:0x16e,R:0x199,c:0x1ce},qZ=qR;return L[qZ(k4.L)]==='go'&&z[qZ(k4.z)]==='go'&&L['target']===z[qZ(0x1b2)]&&L['state']===void 0x0&&z[qZ(0x1ca)]===void 0x0&&L[qZ(0x1a9)]===void 0x0&&z[qZ(0x1a9)]===void 0x0&&L[qZ(0x186)]===void 0x0&&z[qZ(0x186)]===void 0x0&&L[qZ(k4.R)]===void 0x0&&z[qZ(k4.R)]===void 0x0&&L[qZ(0x1a4)]===void 0x0&&z[qZ(0x1a4)]===void 0x0&&L[qZ(0x1ce)]===void 0x0&&z[qZ(k4.c)]===void 0x0;}s(pe,qR(0x1af));function $(L){return new B({'content':L,'additional_kwargs':{'ezgraphInternal':!0x0}});}s($,qR(0x1b3));function fe(L){const k6={L:0x173,z:0x1c2,R:0x18b},qY=qR;return typeof L[qY(k6.L)]==qY(k6.z)?L[qY(0x173)]:JSON[qY(k6.R)](L['content']);}s(fe,'messageText');function me(L,z){const qH=qR;return C(z)?p(L[qH(0x173)]):fe(L);}s(me,qR(0x1c5));function S(L){const k8={L:0x16c},qW=qR;return L[qW(k8.L)]()['toLowerCase']()[qW(0x187)]('-','_');}s(S,qR(0x19d));function ye(L,z){const k9={L:0x1c7,z:0x189,R:0x16a,c:0x190},qM=qR;if(!L||typeof L!=qM(0x174))return null;const R=L,c=R[qM(k9.L)]??R[qM(k9.z)];if(typeof c!=qM(0x1c2)||!c[qM(0x16c)]())return null;const A=R[qM(k9.R)]??R['safety_ratings'];return{...z,'phase':qM(0x1a1),'rawReason':c,'reason':S(c),...Array[qM(k9.c)](A)?{'safetyRatings':A}:{}};}s(ye,qR(0x17e));function G(L){const kq={L:0x173},qx=qR;return L[qx(0x165)]?.[qx(0x1a0)]?!0x0:typeof L[qx(kq.L)]==qx(0x1c2)?!!L[qx(0x173)][qx(0x16c)]():L[qx(kq.L)]['some'](z=>typeof z[qx(0x1bc)]==qx(0x1c2)&&!!z[qx(0x1bc)][qx(0x16c)]());}s(G,qR(0x1ac));async function Y(L){try{await d(0x1f4,void 0x0,L?{'signal':L}:void 0x0);}catch(z){throw L?.['throwIfAborted'](),z;}}s(Y,qR(0x180));export{Te as ConversationRunner,ke as DEFAULT_CONVERSATION_POLICY,H as DEFAULT_EMPTY_HISTORY_SEED,P as DEFAULT_EMPTY_RESPONSE_RECOVERY,de as DEFAULT_MAX_AGENT_ROUNDS,le as EmptyModelResponseError,ue as assertEmptyResponseRetries,ce as assertMaxAgentRounds};
|