@picoflow/ezgraph 0.0.17 → 0.0.19

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 CHANGED
@@ -50,6 +50,32 @@ returns exactly one response:
50
50
  There is no per-turn context object, post-tool transition hook, synthetic tool
51
51
  result, or automatic outcome router to maintain.
52
52
 
53
+ ## Await child work inside a parent
54
+
55
+ Use `runNode()` with one or more registered targets when the parent needs their
56
+ results before choosing its next action:
57
+
58
+ ```ts
59
+ const [judge] = await this.runNode({ node: JudgeNode, input: { candidate } });
60
+ const [first, second] = await this.runNode(Child1Node, Child2Node);
61
+ ```
62
+
63
+ The parent resumes after the await with ordered readonly results. Each result
64
+ contains final child state, a discriminated `outcome`, and usage. Narrow
65
+ `outcome.kind === "taskResult"` to consume a typed judge verdict; text replies
66
+ use `kind: "reply"`. The child reads explicit JSON facts with
67
+ `this.getRunNodeInput<Input>()` and validates them before use.
68
+
69
+ Children execute through EZGraph's invocation lifecycle inside LangGraph tasks.
70
+ They own local state; the parent owns conversation history and routing. On full
71
+ success, child state and usage join the parent's staged update automatically.
72
+ Ordinary failures throw `RunNodeBatchError` after all children settle and join
73
+ no child business state from that batch. Known usage remains accounted for.
74
+
75
+ An active compiled LangGraph execution is required. The current default engine
76
+ does not configure a checkpointer, so scheduling alone supplies no restart
77
+ recovery. Nested child batches are not supported in this initial version.
78
+
53
79
  ## Define durable state
54
80
 
55
81
  Keep the node registry next to the graph. It is converted into the annotated
@@ -235,9 +261,10 @@ but they do not automatically exercise the managed LLM lifecycle.
235
261
 
236
262
  ## Supply input on node entry
237
263
 
238
- The protected synchronous `onEnter(langMessage, priorNode?)` hook runs once at
239
- the start of each `LlmNode` agent loop, before the first model call and before
240
- the empty-history seed. Model/tool rounds, retries, and alternate-model recovery
264
+ The protected `onEnter(langMessage, priorNode?)` hook accepts a synchronous
265
+ result or a Promise. EZGraph awaits it once at the start of each `LlmNode`
266
+ agent loop, before constructing the prompt, applying the empty-history seed,
267
+ and calling the model. Model/tool rounds, retries, and alternate-model recovery
241
268
  reuse its prepared input. A later node invocation calls it again, including a
242
269
  new user turn on the same node.
243
270
 
@@ -276,8 +303,91 @@ class BatchNode extends LlmNode<MyGraphState, { rows?: unknown[]; result?: strin
276
303
 
277
304
  Populate `BatchNode`'s local `rows` state before invoking the graph or node.
278
305
  This supplies batch data even when no external user message is present.
279
- Keep invocation data in node state or graph context; node instances are shared
280
- across sessions. An entry-hook error propagates as an application error.
306
+ For asynchronous preprocessing, override the same hook with `async`:
307
+
308
+ ```ts
309
+ // Application-provided lookup or preprocessing function.
310
+ declare function loadBatchFacts(rows: unknown[]): Promise<string>;
311
+
312
+ class PreparedBatchNode extends LlmNode<MyGraphState, { rows?: unknown[]; facts?: string }> {
313
+ getPrompt() { return `Process the supplied batch using: ${this.getState().facts ?? ""}`; }
314
+
315
+ protected override async onEnter(
316
+ langMessage: MessageTypes | null | undefined,
317
+ _priorNode?: string,
318
+ ): Promise<MessageTypes | null | undefined> {
319
+ const rows = this.getState().rows;
320
+ if (rows === undefined) return langMessage;
321
+ const facts = await loadBatchFacts(rows);
322
+ this.saveState({ facts });
323
+ return new HumanMessage(JSON.stringify(rows));
324
+ }
325
+ }
326
+ ```
327
+
328
+ Facts saved during entry are available to `getPrompt(state)` and `getState()`
329
+ when the prompt is built. Keep invocation data in node state or graph context;
330
+ node instances are shared across sessions. A thrown error or rejected Promise
331
+ propagates as an application error without model recovery. Cancellation is
332
+ checked before and after awaiting the hook; preprocessing that needs to stop
333
+ its own I/O should honor `currentTurnSignal()`.
334
+
335
+ ## Finalize successful work with onExit
336
+
337
+ The protected `onExit(context)` hook accepts `void` or `Promise<void>`. EZGraph
338
+ awaits it once per successful `LlmNode` invocation, after `onResponse()` where
339
+ applicable and after JSON completion validation or repair, before publishing
340
+ the node update or starting downstream nodes. A reply that keeps the same node
341
+ active also invokes it; it is not restricted to graph transitions.
342
+
343
+ The exported `LlmNodeExitContext<State, Output>` contains:
344
+
345
+ | Field | Meaning |
346
+ | --- | --- |
347
+ | `nodeId` | The executing node's stable ID. |
348
+ | `mode` | `"conversation"` or `"internal"`. |
349
+ | `state` | Current materialized invocation state, including staged entry, tool, and response writes. |
350
+ | `outcome` | Final semantic outcome after response handling and completion validation. |
351
+ | `usage` | Accumulated token usage for this invocation, not the session total. |
352
+
353
+ The exported `LlmNodeExitOutcome<Output>` is a discriminated union:
354
+
355
+ | `outcome.kind` | Additional fields |
356
+ | --- | --- |
357
+ | `reply` | `response: string`; ordinary text and `direct()` normalize to this outcome. |
358
+ | `taskResult` | `value: Output`; preserves the final typed task value. |
359
+ | `go` | `targets: readonly [string]`. |
360
+ | `fanout` | `targets: readonly [string, string, ...string[]]`. |
361
+ | `directTo` | `targets: readonly [string]` and `response: string`. |
362
+ | `finish` | `response: string`. |
363
+
364
+ Targets are resolved node IDs. `stay()` continues the loop and does not trigger
365
+ exit. Tool-selected routing and completion trigger exit even though they skip
366
+ `onResponse()`. Retries, rejected candidates, and intermediate tool rounds do
367
+ not trigger exit. Handled model failures do; unhandled errors and cancellation
368
+ skip it. Cancellation is checked before and after awaiting exit. An exit-hook
369
+ error propagates without model recovery and the invocation update is not published.
370
+
371
+ Inside a batch worker, use the hook to stage final facts:
372
+
373
+ ```ts
374
+ import type { LlmNodeExitContext } from "@picoflow/ezgraph";
375
+
376
+ protected override async onExit(
377
+ context: LlmNodeExitContext<MyGraphState, BatchResult>,
378
+ ): Promise<void> {
379
+ if (context.outcome.kind === "taskResult") {
380
+ const summary = await summarizeBatch(context.outcome.value);
381
+ this.saveState({ summary });
382
+ }
383
+ }
384
+ ```
385
+
386
+ The hook's return value does not change output or routing. Use `saveState()`
387
+ for final local writes and the existing response hooks/builders to select an
388
+ outcome. Internal workers retain their existing restriction to their own node
389
+ state and token usage. State remains staged during exit; this is not a session
390
+ persistence notification.
281
391
 
282
392
  ## Handle model failures
283
393
 
@@ -1 +1 @@
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
+ var p=Object.defineProperty;var i=(n,e)=>p(n,"name",{value:e,configurable:!0});import{GraphLlm as u}from"./graph-llm.config.js";import{GraphNodeRuntime as l}from"./graph-node.js";import{StateGraphExt as g}from"./state-graph-ext.js";import{assertEmptyResponseRetries as f,assertMaxAgentRounds as w,DEFAULT_LLM_POLICY as m,DEFAULT_MAX_AGENT_ROUNDS as y}from"./llm-runner.js";import{assertLlmTimeoutMs as E}from"./llm-gateway.js";import{assertGraphSchemaVersion as c,assertStableId as v,stableClassId as a}from"./stable-id.js";class d{static{i(this,"BaseGraph")}llmGateway;static id(){return this.name}static assertName(e){return d.assertId(e)}static assertId(e){return v(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=c(r.schemaVersion??1),this.migrations=M(r.migrations,this.schemaVersion),this.llmConfig=u.resolveConfig(r.llmConfig),this.requiresUserMessage=r.requiresUserMessage??!0,this.responseMode=r.responseMode??"chat",this.maxAgentRounds=w(r.maxAgentRounds??y),this.llmPolicy=R(r),this.endNode=r.endNode,this.runtime=new l(r.endNode,this.llmConfig,$(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().`)}),this.runtime.attachRunNodeResolver(s=>{const o=a(s,"graph node"),h=this.nodeMap.get(o);if(!h||h.constructor!==s)throw new Error(`runNode() target '${o}' must be registered in this graph.`);return h})}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 o=await s.migrate(r);if(o.graph.id!==this.id)throw new Error(`Graph '${this.id}' migration from schema version ${t} changed the persisted graph ID.`);r={...o,graph:{...o.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 g(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 R(n){const e=n.emptyResponseRecovery===void 0?m.emptyResponseRecovery:n.emptyResponseRecovery;return e&&f(e.retries),{...n.llmTimeoutMs===void 0?{}:{llmTimeoutMs:E(n.llmTimeoutMs)},emptyHistorySeed:n.emptyHistorySeed===void 0?m.emptyHistorySeed:n.emptyHistorySeed,emptyResponseRecovery:e}}i(R,"resolveLlmPolicy");function $(n){return Object.fromEntries((n??[]).map(([e,r])=>[a(e,"graph node"),r]))}i($,"historySpaceMap");function M(n,e){const r=new Map;let t;for(const s of n??[]){const o=c(s.from);if(o>=e)throw new Error(`A graph migration from version ${o} cannot target schema version ${e}.`);if(r.has(o))throw new Error(`More than one graph migration starts at version ${o}.`);if(t!==void 0&&o!==t+1)throw new Error(`Graph migrations must be ordered and contiguous; version ${t} must be followed by ${t+1}.`);r.set(o,s),t=o}return r}i(M,"migrationMap");export{d as BaseGraph};
@@ -1 +1 @@
1
- var k=Object.defineProperty;var n=(o,e)=>k(o,"name",{value:e,configurable:!0});import{Command as M,isCommand as v}from"@langchain/langgraph";import{SessionLogDecision as _,SessionLogWarning as m}from"../session-log.js";import{DecisionConfigurationError as L,DecisionTimeoutError as P,DecisionValidationError as h,addDecisionUsage as I,decisionUsage as U,emptyDecisionUsage as C}from"./decision-types.js";import{validateDecisionResult as R}from"./decision-validation.js";class G{static{n(this,"DecisionRunner")}static async run(e){e.callerSignal?.throwIfAborted();const i=performance.now();let t=0,a=C(),r,d,c;try{for(;;){t+=1;try{r=await x(e),d=r.model,c=r.requestId,a=I(a,U(N(r))),R(r,e.questions);break}catch(l){const s=D(l);if(e.callerSignal?.throwIfAborted(),A(s)||!(!(s instanceof h)&&(s.name==="TimeoutError"||e.provider.shouldRetry?.(s)===!0))||t>e.options.maxRetries)throw s;m({decision_retry:!0,node:e.nodeId,provider:e.provider.id,attempt:t+1}),await F(250,e.callerSignal)}}}catch(l){const s=D(l);if(e.callerSignal?.throwIfAborted(),A(s))throw s;const u=j(s);m({decision_fallback:u,node:e.nodeId,provider:e.provider.id});const w=y(e,{outcome:"fallback",failure:u,attempts:t,durationMs:performance.now()-i,usage:a,...d?{actualModel:d}:{},...c?{requestId:c}:{}});let g;try{g=await q(e.onError({nodeId:e.nodeId,provider:e.provider.id,model:e.options.model,failure:u,attempts:t,error:s,state:e.state}),e.callerSignal,"Decision fallback handler aborted.")}catch(T){throw w&&(w.outcome="fallback_handler_failed"),S(e,"fallback",t,a),T}return e.callerSignal?.throwIfAborted(),E(g,a)}e.callerSignal?.throwIfAborted();const f={provider:e.provider.id,model:r.model,durationMs:performance.now()-i,attempts:t,usage:r.usage??{},...r.requestId?{requestId:r.requestId}:{},request:e.conversation.request,priorRequests:[...e.conversation.priorRequests]},p=y(e,{outcome:"success",attempts:t,durationMs:f.durationMs,usage:a,actualModel:r.model,...r.requestId?{requestId:r.requestId}:{}});let b;try{b=await q(e.onDecision(r.answers,f,e.state),e.callerSignal,"Decision handler aborted.")}catch(l){throw p&&(p.outcome="decision_handler_failed"),S(e,"decision",t,a),l}return e.callerSignal?.throwIfAborted(),E(b,a)}}function y(o,e){return _({node:o.nodeId,provider:o.provider.id,configuredModel:o.options.model,...e})}n(y,"recordDecision");async function x(o){const e=new AbortController,i=setTimeout(()=>e.abort(new P),o.options.timeoutMs),t=o.callerSignal?AbortSignal.any([o.callerSignal,e.signal]):e.signal;let a=n(()=>{},"onAbort");try{t.throwIfAborted();const r=new Promise((c,f)=>{a=n(()=>f(t.reason??new Error("Decision call aborted.")),"onAbort"),t.addEventListener("abort",a,{once:!0})}),d=await Promise.race([o.provider.decide({model:o.options.model,state:o.providerState,questions:o.questions},{signal:t,timeoutMs:o.options.timeoutMs}),r]);return t.throwIfAborted(),d}finally{clearTimeout(i),t.removeEventListener("abort",a)}}n(x,"callProvider");function E(o,e){const i=v(o)?o.update??{}:o,t={...i,decisionUsage:I(i.decisionUsage,e)};return v(o)?new M({update:t,...o.goto===void 0?{}:{goto:o.goto},...o.graph===void 0?{}:{graph:o.graph},...o.resume===void 0?{}:{resume:o.resume}}):t}n(E,"withUsage");function F(o,e){return e?(e.throwIfAborted(),new Promise((i,t)=>{const a=setTimeout(()=>{e.removeEventListener("abort",r),i()},o),r=n(()=>{clearTimeout(a),t(e.reason??new Error("Decision retry aborted."))},"onAbort");e.addEventListener("abort",r,{once:!0})})):new Promise(i=>setTimeout(i,o))}n(F,"retryDelay");async function q(o,e,i){if(!e)return o;e.throwIfAborted();let t=n(()=>{},"onAbort");try{const a=new Promise((d,c)=>{t=n(()=>c(e.reason??new Error(i)),"onAbort"),e.addEventListener("abort",t,{once:!0})}),r=await Promise.race([Promise.resolve(o),a]);return e.throwIfAborted(),r}finally{e.removeEventListener("abort",t)}}n(q,"withCallerCancellation");function j(o){return o instanceof h?"validation":o.name==="TimeoutError"?"timeout":"provider"}n(j,"classifyFailure");function A(o){if(o instanceof L)return!0;const e=o.status;return e===401||e===403}n(A,"isConfigurationFailure");function D(o){return o instanceof Error?o:new Error(String(o))}n(D,"asError");function N(o){if(!o||typeof o!="object")return{};const e=o.usage;if(!e||typeof e!="object")return{};const i=e.inputTokens,t=e.outputTokens;return{...Number.isInteger(i)&&i>=0?{inputTokens:i}:{},...Number.isInteger(t)&&t>=0?{outputTokens:t}:{}}}n(N,"observedUsage");function S(o,e,i,t){m({decision_handler_failed:e,node:o.nodeId,provider:o.provider.id,model:o.options.model,attempts:i,observedDecisionUsage:t})}n(S,"logHandlerFailure");export{G as DecisionRunner};
1
+ var k=Object.defineProperty;var a=(o,e)=>k(o,"name",{value:e,configurable:!0});import{Command as M,isCommand as v}from"@langchain/langgraph";import{SessionLogDecision as _,SessionLogWarning as m}from"../session-log.js";import{DecisionConfigurationError as U,DecisionTimeoutError as L,DecisionValidationError as h,addDecisionUsage as I,decisionUsage as P,emptyDecisionUsage as R}from"./decision-types.js";import{validateDecisionResult as C}from"./decision-validation.js";import{observeRunNodeDecisionUsage as x}from"../node-invocation.js";class K{static{a(this,"DecisionRunner")}static async run(e){e.callerSignal?.throwIfAborted();const i=performance.now();let t=0,n=R(),r,d,c;try{for(;;){t+=1;try{r=await F(e),d=r.model,c=r.requestId,n=I(n,P(H(r))),x(n),C(r,e.questions);break}catch(l){const s=A(l);if(e.callerSignal?.throwIfAborted(),q(s)||!(!(s instanceof h)&&(s.name==="TimeoutError"||e.provider.shouldRetry?.(s)===!0))||t>e.options.maxRetries)throw s;m({decision_retry:!0,node:e.nodeId,provider:e.provider.id,attempt:t+1}),await N(250,e.callerSignal)}}}catch(l){const s=A(l);if(e.callerSignal?.throwIfAborted(),q(s))throw s;const u=j(s);m({decision_fallback:u,node:e.nodeId,provider:e.provider.id});const w=y(e,{outcome:"fallback",failure:u,attempts:t,durationMs:performance.now()-i,usage:n,...d?{actualModel:d}:{},...c?{requestId:c}:{}});let g;try{g=await D(e.onError({nodeId:e.nodeId,provider:e.provider.id,model:e.options.model,failure:u,attempts:t,error:s,state:e.state}),e.callerSignal,"Decision fallback handler aborted.")}catch(T){throw w&&(w.outcome="fallback_handler_failed"),S(e,"fallback",t,n),T}return e.callerSignal?.throwIfAborted(),E(g,n)}e.callerSignal?.throwIfAborted();const f={provider:e.provider.id,model:r.model,durationMs:performance.now()-i,attempts:t,usage:r.usage??{},...r.requestId?{requestId:r.requestId}:{},request:e.conversation.request,priorRequests:[...e.conversation.priorRequests]},p=y(e,{outcome:"success",attempts:t,durationMs:f.durationMs,usage:n,actualModel:r.model,...r.requestId?{requestId:r.requestId}:{}});let b;try{b=await D(e.onDecision(r.answers,f,e.state),e.callerSignal,"Decision handler aborted.")}catch(l){throw p&&(p.outcome="decision_handler_failed"),S(e,"decision",t,n),l}return e.callerSignal?.throwIfAborted(),E(b,n)}}function y(o,e){return _({node:o.nodeId,provider:o.provider.id,configuredModel:o.options.model,...e})}a(y,"recordDecision");async function F(o){const e=new AbortController,i=setTimeout(()=>e.abort(new L),o.options.timeoutMs),t=o.callerSignal?AbortSignal.any([o.callerSignal,e.signal]):e.signal;let n=a(()=>{},"onAbort");try{t.throwIfAborted();const r=new Promise((c,f)=>{n=a(()=>f(t.reason??new Error("Decision call aborted.")),"onAbort"),t.addEventListener("abort",n,{once:!0})}),d=await Promise.race([o.provider.decide({model:o.options.model,state:o.providerState,questions:o.questions},{signal:t,timeoutMs:o.options.timeoutMs}),r]);return t.throwIfAborted(),d}finally{clearTimeout(i),t.removeEventListener("abort",n)}}a(F,"callProvider");function E(o,e){const i=v(o)?o.update??{}:o,t={...i,decisionUsage:I(i.decisionUsage,e)};return v(o)?new M({update:t,...o.goto===void 0?{}:{goto:o.goto},...o.graph===void 0?{}:{graph:o.graph},...o.resume===void 0?{}:{resume:o.resume}}):t}a(E,"withUsage");function N(o,e){return e?(e.throwIfAborted(),new Promise((i,t)=>{const n=setTimeout(()=>{e.removeEventListener("abort",r),i()},o),r=a(()=>{clearTimeout(n),t(e.reason??new Error("Decision retry aborted."))},"onAbort");e.addEventListener("abort",r,{once:!0})})):new Promise(i=>setTimeout(i,o))}a(N,"retryDelay");async function D(o,e,i){if(!e)return o;e.throwIfAborted();let t=a(()=>{},"onAbort");try{const n=new Promise((d,c)=>{t=a(()=>c(e.reason??new Error(i)),"onAbort"),e.addEventListener("abort",t,{once:!0})}),r=await Promise.race([Promise.resolve(o),n]);return e.throwIfAborted(),r}finally{e.removeEventListener("abort",t)}}a(D,"withCallerCancellation");function j(o){return o instanceof h?"validation":o.name==="TimeoutError"?"timeout":"provider"}a(j,"classifyFailure");function q(o){if(o instanceof U)return!0;const e=o.status;return e===401||e===403}a(q,"isConfigurationFailure");function A(o){return o instanceof Error?o:new Error(String(o))}a(A,"asError");function H(o){if(!o||typeof o!="object")return{};const e=o.usage;if(!e||typeof e!="object")return{};const i=e.inputTokens,t=e.outputTokens;return{...Number.isInteger(i)&&i>=0?{inputTokens:i}:{},...Number.isInteger(t)&&t>=0?{outputTokens:t}:{}}}a(H,"observedUsage");function S(o,e,i,t){m({decision_handler_failed:e,node:o.nodeId,provider:o.provider.id,model:o.options.model,attempts:i,observedDecisionUsage:t})}a(S,"logHandlerFailure");export{K as DecisionRunner};
@@ -1 +1 @@
1
- const MG=m;(function(r,S){const Mh={r:0xe0,S:0xdb,X:0xc1,p:0xb4},Mj=m,X=r();while(!![]){try{const p=parseInt(Mj(0xa0))/0x1+parseInt(Mj(Mh.r))/0x2+parseInt(Mj(Mh.S))/0x3+parseInt(Mj(Mh.X))/0x4+-parseInt(Mj(0xce))/0x5+parseInt(Mj(0xd6))/0x6+parseInt(Mj(Mh.p))/0x7*(-parseInt(Mj(0xa3))/0x8);if(p===S)break;else X['push'](X['shift']());}catch(Z){X['push'](X['shift']());}}}(T,0x8258d));var P=Object['defineProperty'],y=(r,S)=>P(r,MG(0xc5),{'value':S,'configurable':!0x0});import{HumanMessage as e}from'@langchain/core/messages';function T(){const MI=['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'];T=function(){return MI;};return T();}function m(M,e){M=M-0x9d;const A=T();let v=A[M];if(m['pjzpNm']===undefined){var B=function(l){const q='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+/=';let z='',s='';for(let f=0x0,W,u,y=0x0;u=l['charAt'](y++);~u&&(W=f%0x4?W*0x40+u:u,f++%0x4)?z+=String['fromCharCode'](0xff&W>>(-0x2*f&0x6)):0x0){u=q['indexOf'](u);}for(let Q=0x0,g=z['length'];Q<g;Q++){s+='%'+('00'+z['charCodeAt'](Q)['toString'](0x10))['slice'](-0x2);}return decodeURIComponent(s);};m['bOrkSb']=B,m['wJSDQu']={},m['pjzpNm']=!![];}const i=A[0x0],j=M+i,G=m['wJSDQu'][j];return!G?(v=m['bOrkSb'](v),m['wJSDQu'][j]=v):v=G,v;}import{randomUUID as v}from'node:crypto';import{GraphRegistry as i,registeredGraphId as G,registeredGraphSchemaVersion as l}from'./graph-registry.js';import{LangChainLlmGateway as s}from'./langchain-llm-gateway.js';import{SessionLogError as f,createSessionLogs as W,drainSessionLogs as u,restoreSessionLogs as Q,withSessionLogs as g}from'./session-log.js';import{withTurnContext as o}from'./turn-context.js';import{SessionManager as h,SessionTurnError as Y,SESSION_BUSY as n,SESSION_COMPLETED as t}from'./persistence/session-manager.js';import{parseJsonObjectResponse as d}from'./json-response.js';import{DecisionProviderRegistry as K}from'./decision/decision-provider.js';class M{static{y(this,'GraphEngine');}[MG(0xe1)]=new i();[MG(0x9f)];[MG(0xa4)];['decisionProviders'];[MG(0xe2)]=new Set();constructor(r={}){const MY={r:0xc8,S:0xcf,X:0xcf,p:0xa4,Z:0xde},Ml=MG;this[Ml(0x9f)]=r[Ml(MY.r)]??new h(),this[Ml(MY.S)]=new K(r[Ml(MY.X)]??[]),this['llmGatewayFactory']=r[Ml(MY.p)]??(S=>new s(S,r[Ml(0xd5)]?{'providers':r[Ml(0xd5)]}:{})),this[Ml(MY.Z)](r['graphs']??[]);}static async[MG(0xca)](r={}){const MV={r:0xc0,S:0xc0,X:0xd5,p:0xcf},Mq=MG,S=await h[Mq(0xa2)](r['configManager']);return new M({'sessionManager':S,...r['llmGatewayFactory']?{'llmGatewayFactory':r[Mq(0xa4)]}:{},...r[Mq(MV.r)]?{'graphs':r[Mq(MV.S)]}:{},...r[Mq(MV.X)]?{'providers':r[Mq(0xd5)]}:{},...r[Mq(MV.p)]?{'decisionProviders':r['decisionProviders']}:{}});}[MG(0xde)](r){const MH={r:0xbe},Mn={r:0x9e,S:0xd0},Mz=MG,S=r[Mz(MH.r)](X=>{const Ms=Mz,p=new X(this[Ms(0xa4)](X[Ms(Mn.r)]()[Ms(0xe3)]));return p[Ms(Mn.S)]?.(Z=>this['decisionProviders'][Ms(0xe7)](Z)),p[Ms(0xba)],p;});return this[Mz(0xe1)]['register'](S),this;}[MG(0xaa)](){return this['registry']['names']();}[MG(0xe5)](r){const Md={r:0x9f},Mf=MG;return this[Mf(Md.r)]['getSession'](w(r));}async[MG(0xb9)](S){const MK={r:0xcc,S:0xdd,X:0xab,p:0xa5,Z:0xa6,I:0xe2,a:0xb5},MN={r:0x9f,S:0xac,X:0xb7,p:0xba,Z:0xa9,I:0xa9,a:0xa8,L:0xeb,c:0xa8,b:0xea,J:0x9f,D:0xc4,M0:0xc2,M1:0xba,M2:0xba,M3:0xd7,M4:0xb1,M5:0xbc,M6:0xa1,M7:0xda,M8:0x9d,M9:0xe9,MM:0xdf},MW=MG,X=this[MW(0xe1)][MW(0xb0)](S[MW(0xe4)]);if(!X)return{'status':0x190,'body':{'success':!0x1,'completed':!0x0,'message':'Graph\x20\x27'+(S['graphName']??'')+MW(MK.r)}};const p=typeof S[MW(MK.S)]==MW(0xc3)?S['userMessage'][MW(MK.X)]():void 0x0;if(X[MW(0xd8)]!==!0x1&&!p)return{'status':0x190,'body':{'success':!0x1,'completed':!0x1,'message':MW(0xc7)}};let Z;try{Z=S[MW(0xd2)]?w(S['sessionId']):v();}catch(D){return{'status':0x190,'body':{'success':!0x1,'completed':!0x1,'message':D instanceof Error?D[MW(0xaf)]:String(D)}};}const a=G(X),L=l(X),c={'graphId':a,'graphSchemaVersion':L,'llmConfig':X['llmConfig']},b=W();if(this['inflightSessions']['has'](Z))return this[MW(0xd4)](Z,n,MW(MK.p)+Z+MW(MK.Z));this[MW(MK.I)]['add'](Z);const J={'session':Z,...S[MW(0xb5)]===void 0x0?{}:{'signal':S[MW(MK.a)]}};return this['withTurnScope'](J,b,async()=>{const Mu=MW;let M0=!0x0,M1,M2;try{const M3=v(),M4=await this[Mu(MN.r)][Mu(MN.S)](Z,M3,c);M1=M3,M2=M4[Mu(0xd9)];const M5=M4[Mu(MN.X)][Mu(MN.p)][Mu(0xc9)]?M4[Mu(0xb7)]:void 0x0;M5&&M5[Mu(0xba)][Mu(0xa8)]!==L&&(M0=!0x1);const M6=M5?X[Mu(MN.Z)]?await X[Mu(MN.I)](M5):M5:void 0x0;if(M6&&M6[Mu(0xba)][Mu(MN.a)]!==L)throw new Error(Mu(MN.L)+a+Mu(0xbd)+M6[Mu(0xba)][Mu(MN.c)]+Mu(MN.b)+L+'.');M5&&M6&&M6['graph'][Mu(0xa8)]!==M5[Mu(0xba)][Mu(MN.a)]&&await this[Mu(MN.r)]['persistMigratedSession'](M6,{'owner':M3,'expectedRevision':M2}),M0=!0x0;const M7=M6?this[Mu(MN.r)][Mu(0xbf)](M6,a):void 0x0;if(M7?.[Mu(0xa1)])return await this[Mu(MN.J)][Mu(0xc6)](Z,M3,M2),this[Mu(0xae)](X[Mu(MN.D)],Z);const M8={...p?X[Mu(0xcd)](M7,new e(p)):M7??{},'config':{...M7?.[Mu(MN.M0)]??{},...S[Mu(0xc2)]??{}},'inputConsumed':!0x1,'response':''};let M9;if(X['graph'][Mu(0xd3)]){const MM=await X[Mu(MN.M1)][Mu(0xd3)](M8,{'streamMode':'values'});for await(const MT of MM){if(M9=MT,M9[Mu(0xe6)]!==!0x0)continue;const Mm=u(b);let Me;try{Me=await this['sessions']['saveState'](Z,M9,c,Mm,{'owner':M3,...M2===void 0x0?{}:{'expectedRevision':M2},'keepTurn':!0x0});}catch(MA){throw Q(b,Mm),MA;}M2=Me['revision'];}}else M9=await X[Mu(MN.M2)][Mu(MN.M3)](M8);if(!M9)throw new Error('Graph\x20\x27'+a+Mu(MN.M4));return await this[Mu(MN.r)][Mu(0xb2)](Z,M9,c,b,{'owner':M3,...M2===void 0x0?{}:{'expectedRevision':M2}}),X[Mu(0xc4)]===Mu(MN.M5)?this[Mu(0xdc)](Z,M9[Mu(0xcb)]):this['chatResult'](Z,M9[Mu(0xcb)],M9[Mu(MN.M6)]);}catch(Mv){if(Mv instanceof Y)return this['conflictResult'](Z,Mv[Mu(MN.M7)],Mv['message']);const MB=Mv instanceof Error?Mv['message']:String(Mv);if(f({'chat_service':MB}),M1)try{await this[Mu(0x9f)]['endFailedTurn'](Z,M1,c,M0?b:void 0x0,M2);}catch(Mi){console[Mu(MN.M8)](Mu(MN.M9),Mi);}return{'status':0x190,'session':Z,'body':{'success':!0x1,'completed':!0x1,'message':MB,'session':Z}};}finally{this['inflightSessions'][Mu(MN.MM)](Z);}});}[MG(0xe8)](r,S,X){return o(r,()=>g(S,X));}async[MG(0xb3)](r){const Mr={r:0xbb},My=MG;if(!r)return{'status':0x190,'body':{'success':!0x1,'message':My(Mr.r)}};try{const S=w(r);return await this['sessions'][My(0xb3)](S),{'status':0xc8,'body':{'success':!0x0,'session':S}};}catch(X){return{'status':0x190,'body':{'success':!0x1,'session':r,'message':X instanceof Error?X[My(0xaf)]:String(X)}};}}async[MG(0xad)](){const MQ=MG;await this[MQ(0x9f)][MQ(0xad)]();}['conflictResult'](r,S,X){return{'status':0x199,'session':r,'body':{'success':!0x1,'completed':!0x1,'message':X,'code':S,'session':r}};}[MG(0xae)](r,S){const MX={r:0xd4},Mg=MG,X='This\x20conversation\x20is\x20already\x20complete.';return r===Mg(0xbc)?this[Mg(MX.r)](S,t,X):this['chatResult'](S,X,!0x0);}[MG(0xdc)](r,S){const Mo=MG;return{'status':0xc8,'session':r,'contentType':Mo(0xb6),'body':d(S)};}[MG(0xb8)](r,S,X){return{'status':0xc8,'session':r,'body':{'success':!0x0,'completed':X,'message':S,'bot':S,'session':r}};}}function w(r){const MZ={r:0xd1},Mk=MG,S=r[Mk(0xab)]();if(!/^[A-Za-z0-9_-]{1,128}$/[Mk(MZ.r)](S))throw new Error('SESSION_ID\x20must\x20be\x201-128\x20letters,\x20numbers,\x20underscores,\x20or\x20hyphens.');return S;}y(w,MG(0xa7));export{M as GraphEngine};
1
+ const lE=h;(function(g,i){const ln={g:0xe0,i:0xdb,t:0xc1,d:0xb4},ls=h,t=g();while(!![]){try{const d=parseInt(ls(0xa0))/0x1+parseInt(ls(ln.g))/0x2+parseInt(ls(ln.i))/0x3+parseInt(ls(ln.t))/0x4+-parseInt(ls(0xce))/0x5+parseInt(ls(0xd6))/0x6+parseInt(ls(ln.d))/0x7*(-parseInt(ls(0xa3))/0x8);if(d===i)break;else t['push'](t['shift']());}catch(a){t['push'](t['shift']());}}}(l,0x8258d));var P=Object['defineProperty'],y=(g,i)=>P(g,lE(0xc5),{'value':i,'configurable':!0x0});import{HumanMessage as c}from'@langchain/core/messages';function l(){const lz=['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'];l=function(){return lz;};return l();}function h(c,e){c=c-0x9d;const r=l();let Q=r[c];if(h['pjzpNm']===undefined){var v=function(E){const D='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+/=';let A='',j='';for(let H=0x0,m,w,Z=0x0;w=E['charAt'](Z++);~w&&(m=H%0x4?m*0x40+w:w,H++%0x4)?A+=String['fromCharCode'](0xff&m>>(-0x2*H&0x6)):0x0){w=D['indexOf'](w);}for(let C=0x0,o=A['length'];C<o;C++){j+='%'+('00'+A['charCodeAt'](C)['toString'](0x10))['slice'](-0x2);}return decodeURIComponent(j);};h['bOrkSb']=v,h['wJSDQu']={},h['pjzpNm']=!![];}const G=r[0x0],I=c+G,s=h['wJSDQu'][I];return!s?(Q=h['bOrkSb'](Q),h['wJSDQu'][I]=Q):Q=s,Q;}import{randomUUID as e}from'node:crypto';import{GraphRegistry as r,registeredGraphId as Q,registeredGraphSchemaVersion as v}from'./graph-registry.js';import{LangChainLlmGateway as G}from'./langchain-llm-gateway.js';import{SessionLogError as I,createSessionLogs as s,drainSessionLogs as D,restoreSessionLogs as m,withSessionLogs as Z}from'./session-log.js';import{withTurnContext as o}from'./turn-context.js';import{SessionManager as L,SessionTurnError as b,SESSION_BUSY as n,SESSION_COMPLETED as f}from'./persistence/session-manager.js';import{parseJsonObjectResponse as u}from'./json-response.js';import{DecisionProviderRegistry as J}from'./decision/decision-provider.js';class M{static{y(this,'GraphEngine');}[lE(0xe1)]=new r();[lE(0x9f)];[lE(0xa4)];['decisionProviders'];[lE(0xe2)]=new Set();constructor(g={}){const lR={g:0xc8,i:0xcf,t:0xcf,d:0xa4,a:0xde},lD=lE;this[lD(0x9f)]=g[lD(lR.g)]??new L(),this[lD(lR.i)]=new J(g[lD(lR.t)]??[]),this['llmGatewayFactory']=g[lD(lR.d)]??(i=>new G(i,g[lD(0xd5)]?{'providers':g[lD(0xd5)]}:{})),this[lD(lR.a)](g['graphs']??[]);}static async[lE(0xca)](g={}){const lf={g:0xc0,i:0xc0,t:0xd5,d:0xcf},lA=lE,i=await L[lA(0xa2)](g['configManager']);return new M({'sessionManager':i,...g['llmGatewayFactory']?{'llmGatewayFactory':g[lA(0xa4)]}:{},...g[lA(lf.g)]?{'graphs':g[lA(lf.i)]}:{},...g[lA(lf.t)]?{'providers':g[lA(0xd5)]}:{},...g[lA(lf.d)]?{'decisionProviders':g['decisionProviders']}:{}});}[lE(0xde)](g){const lJ={g:0xbe},lu={g:0x9e,i:0xd0},lj=lE,i=g[lj(lJ.g)](d=>{const lH=lj,a=new d(this[lH(0xa4)](d[lH(lu.g)]()[lH(0xe3)]));return a[lH(lu.i)]?.(p=>this['decisionProviders'][lH(0xe7)](p)),a[lH(0xba)],a;});return this[lj(0xe1)]['register'](i),this;}[lE(0xaa)](){return this['registry']['names']();}[lE(0xe5)](g){const lN={g:0x9f},lm=lE;return this[lm(lN.g)]['getSession'](w(g));}async[lE(0xb9)](i){const li={g:0xcc,i:0xdd,t:0xab,d:0xa5,a:0xa6,p:0xe2,W:0xb5},lx={g:0x9f,i:0xac,t:0xb7,d:0xba,a:0xa9,p:0xa9,W:0xa8,Y:0xeb,X:0xa8,S:0xea,K:0x9f,T:0xc4,l0:0xc2,l1:0xba,l2:0xba,l3:0xd7,l4:0xb1,l5:0xbc,l6:0xa1,l7:0xda,l8:0x9d,l9:0xe9,ll:0xdf},lw=lE,a=this[lw(0xe1)][lw(0xb0)](i[lw(0xe4)]);if(!a)return{'status':0x190,'body':{'success':!0x1,'completed':!0x0,'message':'Graph\x20\x27'+(i['graphName']??'')+lw(li.g)}};const p=typeof i[lw(li.i)]==lw(0xc3)?i['userMessage'][lw(li.t)]():void 0x0;if(a[lw(0xd8)]!==!0x1&&!p)return{'status':0x190,'body':{'success':!0x1,'completed':!0x1,'message':lw(0xc7)}};let W;try{W=i[lw(0xd2)]?w(i['sessionId']):e();}catch(l0){return{'status':0x190,'body':{'success':!0x1,'completed':!0x1,'message':l0 instanceof Error?l0[lw(0xaf)]:String(l0)}};}const Y=Q(a),X=v(a),S={'graphId':Y,'graphSchemaVersion':X,'llmConfig':a['llmConfig']},K=s();if(this['inflightSessions']['has'](W))return this[lw(0xd4)](W,n,lw(li.d)+W+lw(li.a));this[lw(li.p)]['add'](W);const T={'session':W,...i[lw(0xb5)]===void 0x0?{}:{'signal':i[lw(li.W)]}};return this['withTurnScope'](T,K,async()=>{const lZ=lw;let l1=!0x0,l2,l3;try{const l4=e(),l5=await this[lZ(lx.g)][lZ(lx.i)](W,l4,S);l2=l4,l3=l5[lZ(0xd9)];const l6=l5[lZ(lx.t)][lZ(lx.d)][lZ(0xc9)]?l5[lZ(0xb7)]:void 0x0;l6&&l6[lZ(0xba)][lZ(0xa8)]!==X&&(l1=!0x1);const l7=l6?a[lZ(lx.a)]?await a[lZ(lx.p)](l6):l6:void 0x0;if(l7&&l7[lZ(0xba)][lZ(lx.W)]!==X)throw new Error(lZ(lx.Y)+Y+lZ(0xbd)+l7[lZ(0xba)][lZ(lx.X)]+lZ(lx.S)+X+'.');l6&&l7&&l7['graph'][lZ(0xa8)]!==l6[lZ(0xba)][lZ(lx.W)]&&await this[lZ(lx.g)]['persistMigratedSession'](l7,{'owner':l4,'expectedRevision':l3}),l1=!0x0;const l8=l7?this[lZ(lx.g)][lZ(0xbf)](l7,Y):void 0x0;if(l8?.[lZ(0xa1)])return await this[lZ(lx.K)][lZ(0xc6)](W,l4,l3),this[lZ(0xae)](a[lZ(lx.T)],W);const l9={...p?a[lZ(0xcd)](l8,new c(p)):l8??{},'config':{...l8?.[lZ(lx.l0)]??{},...i[lZ(0xc2)]??{}},'inputConsumed':!0x1,'response':''};let ll;if(a['graph'][lZ(0xd3)]){const lh=await a[lZ(lx.l1)][lZ(0xd3)](l9,{'streamMode':'values'});for await(const lc of lh){if(ll=lc,ll[lZ(0xe6)]!==!0x0)continue;const le=D(K);let lr;try{lr=await this['sessions']['saveState'](W,ll,S,le,{'owner':l4,...l3===void 0x0?{}:{'expectedRevision':l3},'keepTurn':!0x0});}catch(lQ){throw m(K,le),lQ;}l3=lr['revision'];}}else ll=await a[lZ(lx.l2)][lZ(lx.l3)](l9);if(!ll)throw new Error('Graph\x20\x27'+Y+lZ(lx.l4));return await this[lZ(lx.g)][lZ(0xb2)](W,ll,S,K,{'owner':l4,...l3===void 0x0?{}:{'expectedRevision':l3}}),a[lZ(0xc4)]===lZ(lx.l5)?this[lZ(0xdc)](W,ll[lZ(0xcb)]):this['chatResult'](W,ll[lZ(0xcb)],ll[lZ(lx.l6)]);}catch(lv){if(lv instanceof b)return this['conflictResult'](W,lv[lZ(lx.l7)],lv['message']);const lG=lv instanceof Error?lv['message']:String(lv);if(I({'chat_service':lG}),l2)try{await this[lZ(0x9f)]['endFailedTurn'](W,l2,S,l1?K:void 0x0,l3);}catch(lI){console[lZ(lx.l8)](lZ(lx.l9),lI);}return{'status':0x190,'session':W,'body':{'success':!0x1,'completed':!0x1,'message':lG,'session':W}};}finally{this['inflightSessions'][lZ(lx.ll)](W);}});}[lE(0xe8)](g,i,d){return o(g,()=>Z(i,d));}async[lE(0xb3)](g){const lV={g:0xbb},lC=lE;if(!g)return{'status':0x190,'body':{'success':!0x1,'message':lC(lV.g)}};try{const i=w(g);return await this['sessions'][lC(0xb3)](i),{'status':0xc8,'body':{'success':!0x0,'session':i}};}catch(t){return{'status':0x190,'body':{'success':!0x1,'session':g,'message':t instanceof Error?t[lC(0xaf)]:String(t)}};}}async[lE(0xad)](){const lo=lE;await this[lo(0x9f)][lo(0xad)]();}['conflictResult'](g,i,d){return{'status':0x199,'session':g,'body':{'success':!0x1,'completed':!0x1,'message':d,'code':i,'session':g}};}[lE(0xae)](g,i){const lk={g:0xd4},lL=lE,d='This\x20conversation\x20is\x20already\x20complete.';return g===lL(0xbc)?this[lL(lk.g)](i,f,d):this['chatResult'](i,d,!0x0);}[lE(0xdc)](g,i){const lq=lE;return{'status':0xc8,'session':g,'contentType':lq(0xb6),'body':u(i)};}[lE(0xb8)](g,i,d){return{'status':0xc8,'session':g,'body':{'success':!0x0,'completed':d,'message':i,'bot':i,'session':g}};}}function w(g){const lW={g:0xd1},lb=lE,i=g[lb(0xab)]();if(!/^[A-Za-z0-9_-]{1,128}$/[lb(lW.g)](i))throw new Error('SESSION_ID\x20must\x20be\x201-128\x20letters,\x20numbers,\x20underscores,\x20or\x20hyphens.');return i;}y(w,lE(0xa7));export{M as GraphEngine};
@@ -1 +1 @@
1
- var R=Object.defineProperty;var d=(r,e)=>R(r,"name",{value:e,configurable:!0});import"reflect-metadata";import{AIMessage as c,HumanMessage as T}from"@langchain/core/messages";import{Command as p,END as y,isCommand as u}from"@langchain/langgraph";import{GraphLlm as f}from"./graph-llm.config.js";import{GraphStateSupport as L}from"./graph-state-support.js";import{LlmRunner as O,DEFAULT_LLM_POLICY as I,DEFAULT_MAX_AGENT_ROUNDS as H,EmptyModelResponseError as k}from"./llm-runner.js";import{currentTurnSignal as x}from"./turn-context.js";import{combineGraphNodeUpdates as $}from"./node-outcome.js";import{parseJsonObjectResponse as N}from"./json-response.js";import{stableClassId as v}from"./stable-id.js";import{SessionLogWarning as b}from"./session-log.js";import{goTargetIds as A,isToolResponse as S,stay as M}from"./tool-response.js";import{invocationGraphState as G,hasNodeInvocation as P,invocationHistory as _,invocationNodeState as j,invocationUpdate as D,appendInvocationHistory as U,replaceInvocationNodeState as J,invocationContext as q,saveInvocationContext as F,replaceInvocationContext as W,saveInvocationNodeState as z,withNodeInvocation as X,invocationMode as Y,invocationPriorNode as B,invocationIsLocalOnly as K,assertInvocationWrite as g}from"./node-invocation.js";import{DecisionConfigurationError as Q,resolveDecisionOptions as V}from"./decision/decision-types.js";import{GRAPH_NODE_LOCAL_STATE as Ee}from"./node-outcome.js";const Z=Symbol("GRAPH_NODE_CLASS"),w=Symbol("graph-node-tool-handlers");function we(r){if(!r.trim())throw new Error("A tool handler requires a tool name.");return(e,t)=>{const o=Reflect.getOwnMetadata(w,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(w,o,e)}}d(we,"Tool");class E{static{d(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=v(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 i=this.runtime.requireTool(n.toolName),a=oe(t.args);if(!a.ok)return this.rejectToolCall(n.toolName,a.error);const s=i.schema.safeParse(a.value);if(!s.success)return this.rejectToolCall(n.toolName,ne(s.error));const h=s.data,l=this[n.methodName];if(!l)throw new Error(`Tool '${n.toolName}' is decorated on missing method '${String(n.methodName)}'.`);const m=await l.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}),M(JSON.stringify({accepted:!1,error:t}))}usesChatModel(){return!0}onInvalidJsonResponse(e){throw e.error}onEmptyModelResponse(e){throw new k(e.reason)}invoke=d((e,t={})=>this.runtime.withInvocation(this.id,e,async()=>{const o=this.resolveNodeResponse(await this.run(e)),n=te(o),i=await this.resolveJsonResponse(e,n);if(this.runtime.stageNodeEntries(i.nodes),i.context!==void 0&&this.runtime.stageContext(i.context),this.usesChatModel()){const s=this.runtime.resolveLlmConfig(this.getLlmConfig()),h=ee(s,this.runtime.resolveLlmConfig()),l=(e.nodes??{})[this.id];(!h||l?.model!==void 0)&&this.runtime.saveNode(this.id,{model:h?void 0:f.modelMetadata(s)})}const a=$(i,this.runtime.stagedUpdate());if(this.runtime.isLocalOnlyInvocation()&&(u(o)||Object.keys(a).some(s=>s!=="nodes"&&s!=="tokens")||Object.keys(a.nodes??{}).some(s=>s!==this.id)))throw new Error(`Internal LLM node '${this.id}' may publish only its own node state and token usage.`);return this.validateNodeResult(a,u(o)),u(o)?new p({update:a,...o.goto===void 0?{}:{goto:o.goto},...o.graph===void 0?{}:{graph:o.graph},...o.resume===void 0?{}:{resume:o.resume}}):a},t,this.managesLlmExecution()),"invoke");managesLlmExecution(){return!1}validateNodeResult(e,t){}obtainTools(e={}){return this.toolHandlers().filter(({toolName:t})=>this.includeTool(t,e)).map(({toolName:t})=>this.runtime.requireTool(t)).sort((t,o)=>t.name==="terminate_session"?1:o.name==="terminate_session"?-1:0)}validateTools(e={}){this.obtainTools(e)}includeTool(e,t){return!0}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.llmHistory(e),tools:this.obtainTools(),llmConfig:this.llmConfig(),executeTool:d(n=>this.handleTool(e,n,t),"executeTool"),maxAgentRounds:this.runtime.maxAgentRounds,emptyHistorySeed:this.runtime.llmPolicy.emptyHistorySeed,emptyResponseRecovery:this.runtime.llmPolicy.emptyResponseRecovery,callOptions:this.llmCallOptions()})}llmHistory(e){return this.history(e)}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 c(e)])}}complete(e){return{...this.runtime.complete(e),...this.historyUpdate([new c(e)])}}resolveNodeResponse(e){if(!S(e))return e;if(e.targets!==void 0&&e.kind!=="go")throw new Error("Multiple targets are only supported by fanout().");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"){const t=e.kind==="go"?A(e):void 0;if(t&&t.length>1)return new p({update:{response:"",inputConsumed:!0,completed:!1,...e.usage===void 0?{}:{tokens:e.usage}},goto:[...t]});if(!e.target)throw new Error(`Graph node '${this.id}' selected ${e.kind}() without a target.`);const o=t?.[0]??v(e.target,"graph node"),n=this.graph.historySpace(o);if(e.state&&this.graph.saveNodeState(e.target,e.state),e.message&&this.graph.appendHistory(n,[e.message]),e.kind==="directTo"){const i=C(this.id,e);return this.graph.appendHistory(n,[new c(i)]),new p({update:{currentNode:o,response:i,inputConsumed:!0,completed:!1,...e.usage===void 0?{}:{tokens:e.usage}},goto:y})}return new p({update:{currentNode:o,response:"",inputConsumed:!0,completed:!1,...e.usage===void 0?{}:{tokens:e.usage}},goto:o})}if(e.message)throw new Error(`Graph node '${this.id}' can only use withMessage() with go() or directTo().`);if(e.kind==="direct"){const t=C(this.id,e);return this.graph.appendHistory(this.historySpace(),[new c(t)]),new p({update:{currentNode:this.id,response:t,inputConsumed:!0,completed:!1,...e.usage===void 0?{}:{tokens:e.usage}},goto:y})}if(e.kind==="finish"){const t=C(this.id,e);return this.graph.appendHistory(this.historySpace(),[new c(t)]),new p({update:{...this.graph.complete(t),...e.usage===void 0?{}:{tokens:e.usage}},goto:y})}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 N(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)&&N(n.response??""),n}}toolHandlers(){let e=Object.getPrototypeOf(this);const t=[];for(;e&&e!==E.prototype;){const n=Reflect.getOwnMetadata(w,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 ee(r,e){return r.model===e.model&&JSON.stringify(f.parameters(r))===JSON.stringify(f.parameters(e))}d(ee,"sameLlmConfig");class Ce extends L{static{d(this,"GraphNodeRuntime")}defaultLlmConfig;historySpaces;responseMode;maxAgentRounds;llmPolicy;decisionOptions;decisionErrorHandler;llmLifecycle;assertContextChannel;tools=new Map;constructor(e,t,o={},n="chat",i=H,a=I,s={},h,l,m){super(e),this.defaultLlmConfig=t,this.historySpaces=o,this.responseMode=n,this.maxAgentRounds=i,this.llmPolicy=a,this.decisionOptions=s,this.decisionErrorHandler=h,this.llmLifecycle=l,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 f.resolveConfig(this.defaultLlmConfig,e)}resolveDecisionOptions(e={}){return V(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 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=>T.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.hasInvocation()&&g(this),this.responseUpdate(e)}complete(e){return this.hasInvocation()&&g(this),this.endUpdate(e)}withInvocation(e,t,o,n={},i=!1){return X(this,e,t,o,n,i)}invocationMode(){return Y(this)}priorNode(){return B(this)}isLocalOnlyInvocation(){return K(this)}nodeState(e){return j(this,e)}hasInvocation(){return P(this)}graphState(){return G(this)}getContext(){return q(this)}saveContext(e){g(this),this.assertContextChannel?.(),F(this,e)}stageContext(e){g(this),this.assertContextChannel?.(),W(this,e)}appendHistory(e,t){U(this,e,t)}invocationHistory(e){return _(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 z(this,e,t),{nodes:{[e]:this.nodeState(e)}}}saveNodeState(e,t){this.saveNode(v(e,"graph node"),t)}removeNode(e,...t){return this.saveNode(e,Object.fromEntries(t.map(o=>[o,void 0])))}}function te(r){if(!u(r))return r;if(Array.isArray(r.update))throw new Error("GraphNode Command updates must be state objects.");return r.update??{}}d(te,"commandUpdate");function C(r,e){if(!e.response?.trim())throw new Error(`Graph node '${r}' selected ${e.kind}() without a response.`);return e.response}d(C,"requireNodeResponse");function oe(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)}`}}}d(oe,"coerceToolArgs");function ne(r){return r.issues.map(e=>e.path.length>0?`${e.path.join(".")}: ${e.message}`:e.message).join("; ")}d(ne,"formatToolArgumentError");export{Z as GRAPH_NODE_CLASS,Ee as GRAPH_NODE_LOCAL_STATE,E as GraphNode,Ce as GraphNodeRuntime,we as Tool};
1
+ var O=Object.defineProperty;var a=(r,e)=>O(r,"name",{value:e,configurable:!0});import"reflect-metadata";import{AIMessage as u,HumanMessage as I}from"@langchain/core/messages";import{Command as c,END as y,isCommand as m}from"@langchain/langgraph";import{GraphLlm as f}from"./graph-llm.config.js";import{GraphStateSupport as L}from"./graph-state-support.js";import{LlmRunner as k,DEFAULT_LLM_POLICY as A,DEFAULT_MAX_AGENT_ROUNDS as H,EmptyModelResponseError as $}from"./llm-runner.js";import{currentTurnSignal as v}from"./turn-context.js";import{combineGraphNodeUpdates as w}from"./node-outcome.js";import{parseJsonObjectResponse as S}from"./json-response.js";import{stableClassId as N}from"./stable-id.js";import{SessionLogWarning as x}from"./session-log.js";import{goTargetIds as P,isToolResponse as E,stay as M}from"./tool-response.js";import{invocationGraphState as U,hasNodeInvocation as G,invocationHistory as _,invocationNodeState as j,invocationUpdate as D,appendInvocationHistory as J,replaceInvocationNodeState as q,invocationContext as z,saveInvocationContext as F,replaceInvocationContext as W,saveInvocationNodeState as B,withNodeInvocation as X,invocationMode as Y,invocationPriorNode as K,invocationIsLocalOnly as Q,assertInvocationWrite as g,invocationChildUpdate as V,invocationIsBatchChild as Z,recordRunNodeOutcome as ee,recordRunNodeUsage as T,runNodeInput as te}from"./node-invocation.js";import{runNodeTasks as oe}from"./run-node.js";import{addTokenUsage as ne}from"./token-usage.js";import{addDecisionUsage as re}from"./decision/decision-types.js";import{DecisionConfigurationError as ie,resolveDecisionOptions as se}from"./decision/decision-types.js";import{GRAPH_NODE_LOCAL_STATE as xe}from"./node-outcome.js";const ae=Symbol("GRAPH_NODE_CLASS"),C=Symbol("graph-node-tool-handlers");function ke(r){if(!r.trim())throw new Error("A tool handler requires a tool name.");return(e,t)=>{const o=Reflect.getOwnMetadata(C,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(C,o,e)}}a(ke,"Tool");class b{static{a(this,"GraphNode")}llmGateway;runtime;static[ae]=!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=N(o,"graph node")}get graph(){return this.runtime}runNode(...e){return this.runtime.runNode(e)}getRunNodeInput(){return te(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 s=this.runtime.requireTool(n.toolName),i=le(t.args);if(!i.ok)return this.rejectToolCall(n.toolName,i.error);const d=s.schema.safeParse(i.value);if(!d.success)return this.rejectToolCall(n.toolName,ce(d.error));const h=d.data,l=this[n.methodName];if(!l)throw new Error(`Tool '${n.toolName}' is decorated on missing method '${String(n.methodName)}'.`);const p=await l.call(this,h,o,e);if(E(p))return p;throw new Error(`Tool '${n.toolName}' on '${this.id}' must return a ToolResponse.`)}rejectToolCall(e,t){return x({tool_call:t,node:this.id,tool:e}),M(JSON.stringify({accepted:!1,error:t}))}usesChatModel(){return!0}onInvalidJsonResponse(e){throw e.error}onEmptyModelResponse(e){throw new $(e.reason)}invoke=a((e,t={})=>this.runtime.withInvocation(this.id,e,async()=>{const o=this.resolveNodeResponse(await this.run(e)),n=he(o);T(this.runtime,n);const s=await this.resolveJsonResponse(e,n);if(this.runtime.stageNodeEntries(s.nodes),s.context!==void 0&&this.runtime.stageContext(s.context),this.usesChatModel()){const d=this.runtime.resolveLlmConfig(this.getLlmConfig()),h=de(d,this.runtime.resolveLlmConfig()),l=(e.nodes??{})[this.id];(!h||l?.model!==void 0)&&this.runtime.saveNode(this.id,{model:h?void 0:f.modelMetadata(d)})}let i=w(s,this.runtime.stagedUpdate());return this.validatePublication(i,m(o)),i=this.withChildPublication(i),v()?.throwIfAborted(),await this.finalizeNodeResult(o,i),v()?.throwIfAborted(),i=w(s,this.runtime.stagedUpdate()),this.validatePublication(i,m(o)),i=this.withChildPublication(i),T(this.runtime,i),m(o)?new c({update:i,...o.goto===void 0?{}:{goto:o.goto},...o.graph===void 0?{}:{graph:o.graph},...o.resume===void 0?{}:{resume:o.resume}}):i},t,this.managesLlmExecution()),"invoke");withChildPublication(e){const t=V(this.runtime),o=w(t,e);return t.tokens&&(o.tokens=ne(e.tokens,t.tokens)),t.decisionUsage&&(o.decisionUsage=re(e.decisionUsage,t.decisionUsage)),o}finalizeNodeResult(e,t){}validatePublication(e,t){const o=Z(this.runtime);if(o&&e.nodes!==void 0&&(!e.nodes||typeof e.nodes!="object"||Array.isArray(e.nodes)||Object.values(e.nodes).some(n=>!n||typeof n!="object"||Array.isArray(n))))throw new Error(`runNode() child '${this.id}' must publish object-valued node state.`);if(this.runtime.isLocalOnlyInvocation()&&(t||Object.keys(e).some(n=>n!=="nodes"&&n!=="tokens"&&!(o&&n==="decisionUsage"))||Object.keys(e.nodes??{}).some(n=>n!==this.id)))throw new Error(`Internal LLM node '${this.id}' may publish only its own node state and token usage.`);this.validateNodeResult(e,t)}managesLlmExecution(){return!1}validateNodeResult(e,t){}obtainTools(e={}){return this.toolHandlers().filter(({toolName:t})=>this.includeTool(t,e)).map(({toolName:t})=>this.runtime.requireTool(t)).sort((t,o)=>t.name==="terminate_session"?1:o.name==="terminate_session"?-1:0)}validateTools(e={}){this.obtainTools(e)}includeTool(e,t){return!0}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 k(this.llmGateway).run({...o===void 0?{}:{lifecycle:o},systemPrompt:a(()=>(e=this.runtime.hasInvocation()?this.runtime.graphState():e,this.getPrompt(e)),"systemPrompt"),history:this.llmHistory(e),tools:this.obtainTools(),llmConfig:this.llmConfig(),executeTool:a(n=>this.handleTool(e,n,t),"executeTool"),maxAgentRounds:this.runtime.maxAgentRounds,emptyHistorySeed:this.runtime.llmPolicy.emptyHistorySeed,emptyResponseRecovery:this.runtime.llmPolicy.emptyResponseRecovery,callOptions:this.llmCallOptions()})}llmHistory(e){return this.history(e)}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 u(e)])}}complete(e){return{...this.runtime.complete(e),...this.historyUpdate([new u(e)])}}resolveNodeResponse(e){if(!E(e))return e;if(e.targets!==void 0&&e.kind!=="go")throw new Error("Multiple targets are only supported by fanout().");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"){const t=e.kind==="go"?P(e):void 0;if(t&&t.length>1)return new c({update:{response:"",inputConsumed:!0,completed:!1,...e.usage===void 0?{}:{tokens:e.usage}},goto:[...t]});if(!e.target)throw new Error(`Graph node '${this.id}' selected ${e.kind}() without a target.`);const o=t?.[0]??N(e.target,"graph node"),n=this.graph.historySpace(o);if(e.state&&this.graph.saveNodeState(e.target,e.state),e.message&&this.graph.appendHistory(n,[e.message]),e.kind==="directTo"){const s=R(this.id,e);return this.graph.appendHistory(n,[new u(s)]),new c({update:{currentNode:o,response:s,inputConsumed:!0,completed:!1,...e.usage===void 0?{}:{tokens:e.usage}},goto:y})}return new c({update:{currentNode:o,response:"",inputConsumed:!0,completed:!1,...e.usage===void 0?{}:{tokens:e.usage}},goto:o})}if(e.message)throw new Error(`Graph node '${this.id}' can only use withMessage() with go() or directTo().`);if(e.kind==="direct"){const t=R(this.id,e);return this.graph.appendHistory(this.historySpace(),[new u(t)]),new c({update:{currentNode:this.id,response:t,inputConsumed:!0,completed:!1,...e.usage===void 0?{}:{tokens:e.usage}},goto:y})}if(e.kind==="finish"){const t=R(this.id,e);return this.graph.appendHistory(this.historySpace(),[new u(t)]),new c({update:{...this.graph.complete(t),...e.usage===void 0?{}:{tokens:e.usage}},goto:y})}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 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)&&S(n.response??""),n}}toolHandlers(){let e=Object.getPrototypeOf(this);const t=[];for(;e&&e!==b.prototype;){const n=Reflect.getOwnMetadata(C,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 de(r,e){return r.model===e.model&&JSON.stringify(f.parameters(r))===JSON.stringify(f.parameters(e))}a(de,"sameLlmConfig");class Ae extends L{static{a(this,"GraphNodeRuntime")}defaultLlmConfig;historySpaces;responseMode;maxAgentRounds;llmPolicy;decisionOptions;decisionErrorHandler;llmLifecycle;assertContextChannel;runNodeResolver;attachRunNodeResolver(e){this.runNodeResolver=e}runNode(e){return oe({owner:this,graphState:a(()=>this.graphState(),"graphState"),resolve:a(t=>{if(!this.runNodeResolver)throw new Error("runNode() requires a graph's registered-node resolver.");return this.runNodeResolver(t)},"resolve")},e)}recordRunNodeOutcome(e){ee(this,e)}tools=new Map;constructor(e,t,o={},n="chat",s=H,i=A,d={},h,l,p){super(e),this.defaultLlmConfig=t,this.historySpaces=o,this.responseMode=n,this.maxAgentRounds=s,this.llmPolicy=i,this.decisionOptions=d,this.decisionErrorHandler=h,this.llmLifecycle=l,this.assertContextChannel=p}llmCallOptions(){const{llmTimeoutMs:e}=this.llmPolicy,t=v();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 f.resolveConfig(this.defaultLlmConfig,e)}resolveDecisionOptions(e={}){return se(this.decisionOptions,e)}decisionProviderResolver;attachDecisionProviderResolver(e){this.decisionProviderResolver=e}resolveDecisionProvider(e){if(!this.decisionProviderResolver)throw new ie(`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=>I.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.hasInvocation()&&g(this),this.responseUpdate(e)}complete(e){return this.hasInvocation()&&g(this),this.endUpdate(e)}withInvocation(e,t,o,n={},s=!1){return X(this,e,t,o,n,s)}invocationMode(){return Y(this)}priorNode(){return K(this)}isLocalOnlyInvocation(){return Q(this)}nodeState(e){return j(this,e)}hasInvocation(){return G(this)}graphState(){return U(this)}getContext(){return z(this)}saveContext(e){g(this),this.assertContextChannel?.(),F(this,e)}stageContext(e){g(this),this.assertContextChannel?.(),W(this,e)}appendHistory(e,t){J(this,e,t)}invocationHistory(e){return _(this,e)}stagedUpdate(){return D(this)}stageNodeEntries(e){for(const[t,o]of Object.entries(e??{}))!o||typeof o!="object"||Array.isArray(o)||q(this,t,o)}saveNode(e,t){return B(this,e,t),{nodes:{[e]:this.nodeState(e)}}}saveNodeState(e,t){this.saveNode(N(e,"graph node"),t)}removeNode(e,...t){return this.saveNode(e,Object.fromEntries(t.map(o=>[o,void 0])))}}function he(r){if(!m(r))return r;if(Array.isArray(r.update))throw new Error("GraphNode Command updates must be state objects.");return r.update??{}}a(he,"commandUpdate");function R(r,e){if(!e.response?.trim())throw new Error(`Graph node '${r}' selected ${e.kind}() without a response.`);return e.response}a(R,"requireNodeResponse");function le(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)}`}}}a(le,"coerceToolArgs");function ce(r){return r.issues.map(e=>e.path.length>0?`${e.path.join(".")}: ${e.message}`:e.message).join("; ")}a(ce,"formatToolArgumentError");export{ae as GRAPH_NODE_CLASS,xe as GRAPH_NODE_LOCAL_STATE,b as GraphNode,Ae as GraphNodeRuntime,ke as Tool};
@@ -1 +1 @@
1
- function M(){const r=['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'];M=function(){return r;};return M();}const n=T;(function(G,q){const d={G:0x17a,q:0x16b,z:0x178,W:0x166},V=T,z=G();while(!![]){try{const W=parseInt(V(0x173))/0x1+-parseInt(V(0x17c))/0x2+-parseInt(V(d.G))/0x3+-parseInt(V(d.q))/0x4+parseInt(V(d.z))/0x5+parseInt(V(d.W))/0x6*(parseInt(V(0x174))/0x7)+parseInt(V(0x16c))/0x8*(parseInt(V(0x175))/0x9);if(W===q)break;else z['push'](z['shift']());}catch(y){z['push'](z['shift']());}}}(M,0xb9e87));var s=Object['defineProperty'],l=(G,q)=>s(G,n(0x171),{'value':q,'configurable':!0x0});import{GraphLlm as e,ModelCatalog as A}from'./graph-llm.config.js';function T(m,e){m=m-0x165;const A=M();let v=A[m];if(T['uapbbH']===undefined){var B=function(l){const q='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+/=';let z='',s='';for(let f=0x0,W,u,y=0x0;u=l['charAt'](y++);~u&&(W=f%0x4?W*0x40+u:u,f++%0x4)?z+=String['fromCharCode'](0xff&W>>(-0x2*f&0x6)):0x0){u=q['indexOf'](u);}for(let Q=0x0,g=z['length'];Q<g;Q++){s+='%'+('00'+z['charCodeAt'](Q)['toString'](0x10))['slice'](-0x2);}return decodeURIComponent(s);};T['ujitrk']=B,T['tGlJwF']={},T['uapbbH']=!![];}const i=A[0x0],j=m+i,G=T['tGlJwF'][j];return!G?(v=T['ujitrk'](v),T['tGlJwF'][j]=v):v=G,v;}import{modelProviderAdapter as B}from'./model-provider.js';import{OPENAI_AUTH_PROVIDER as i,initializeOpenAIAuthProvider as j}from'./openai-auth-provider.js';function C(G,q=[]){const N={G:0x17e,q:0x17d,z:0x165,W:0x167,y:0x16d,Q:0x16e,o:0x170,k:0x16a,h:0x16e},H=n,z=e[H(N.G)](G),W=A[H(N.q)](z),y={};for(const [k,h]of Object[H(0x17f)](z[H(N.z)])){const Y=W[H(N.W)][k];Y!==null&&u(y,Y??k,h);}if(W[H(0x16e)]===i)return j(W[H(N.y)],y);const Q=B(W[H(N.Q)],q)??W[H(N.o)];return Q?Q[H(N.k)]({'provider':W[H(N.h)],'model':W[H(N.y)],'options':y}):{'model':W[H(N.y)],'options':{'modelProvider':W[H(0x16e)],...y}};}l(C,n(0x169));function u(G,q,z){const K={G:0x16f,q:0x17b,z:0x176,W:0x179},t=n,W=q[t(0x177)]('.');let y=G;for(const k of W[t(0x172)](0x0,-0x1)){const h=y[k];if(h===void 0x0){const Y={};y[k]=Y,y=Y;}else{if(typeof h==t(K.G)&&h!==null&&!Array[t(K.q)](h))y=h;else throw new Error(t(K.z)+q+'\x27\x20has\x20a\x20conflicting\x20path.');}}const Q=W['at'](-0x1);if(!Q)throw new Error(t(K.W));y[Q]=z;}l(u,n(0x168));export{C as langChainModelInitialization};
1
+ function h(){const V=['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'];h=function(){return V;};return h();}const R=e;(function(D,A){const x={D:0x17a,A:0x16b,j:0x178,H:0x166},n=e,j=D();while(!![]){try{const H=parseInt(n(0x173))/0x1+-parseInt(n(0x17c))/0x2+-parseInt(n(x.D))/0x3+-parseInt(n(x.A))/0x4+parseInt(n(x.j))/0x5+parseInt(n(x.H))/0x6*(parseInt(n(0x174))/0x7)+parseInt(n(0x16c))/0x8*(parseInt(n(0x175))/0x9);if(H===A)break;else j['push'](j['shift']());}catch(w){j['push'](j['shift']());}}}(h,0xb9e87));var s=Object['defineProperty'],l=(D,A)=>s(D,R(0x171),{'value':A,'configurable':!0x0});import{GraphLlm as r,ModelCatalog as Q}from'./graph-llm.config.js';function e(l,c){l=l-0x165;const r=h();let Q=r[l];if(e['uapbbH']===undefined){var v=function(E){const D='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+/=';let A='',j='';for(let H=0x0,m,w,Z=0x0;w=E['charAt'](Z++);~w&&(m=H%0x4?m*0x40+w:w,H++%0x4)?A+=String['fromCharCode'](0xff&m>>(-0x2*H&0x6)):0x0){w=D['indexOf'](w);}for(let C=0x0,o=A['length'];C<o;C++){j+='%'+('00'+A['charCodeAt'](C)['toString'](0x10))['slice'](-0x2);}return decodeURIComponent(j);};e['ujitrk']=v,e['tGlJwF']={},e['uapbbH']=!![];}const G=r[0x0],I=l+G,s=e['tGlJwF'][I];return!s?(Q=e['ujitrk'](Q),e['tGlJwF'][I]=Q):Q=s,Q;}import{modelProviderAdapter as G}from'./model-provider.js';import{OPENAI_AUTH_PROVIDER as I,initializeOpenAIAuthProvider as E}from'./openai-auth-provider.js';function C(D,A=[]){const i={D:0x17e,A:0x17d,j:0x165,H:0x167,w:0x16d,Z:0x16e,o:0x170,L:0x16a,q:0x16e},J=R,j=r[J(i.D)](D),H=Q[J(i.A)](j),w={};for(const [L,q]of Object[J(0x17f)](j[J(i.j)])){const b=H[J(i.H)][L];b!==null&&u(w,b??L,q);}if(H[J(0x16e)]===I)return E(H[J(i.w)],w);const Z=G(H[J(i.Z)],A)??H[J(i.o)];return Z?Z[J(i.L)]({'provider':H[J(i.q)],'model':H[J(i.w)],'options':w}):{'model':H[J(i.w)],'options':{'modelProvider':H[J(0x16e)],...w}};}l(C,R(0x169));function u(D,A,j){const O={D:0x16f,A:0x17b,j:0x176,H:0x179},N=R,H=A[N(0x177)]('.');let w=D;for(const L of H[N(0x172)](0x0,-0x1)){const q=w[L];if(q===void 0x0){const b={};w[L]=b,w=b;}else{if(typeof q==N(O.D)&&q!==null&&!Array[N(O.A)](q))w=q;else throw new Error(N(O.j)+A+'\x27\x20has\x20a\x20conflicting\x20path.');}}const Z=H['at'](-0x1);if(!Z)throw new Error(N(O.H));w[Z]=j;}l(u,R(0x168));export{C as langChainModelInitialization};
@@ -1 +1 @@
1
- var y=Object.defineProperty;var h=(a,e)=>y(a,"name",{value:e,configurable:!0});var k=function(a,e,t,o){var s=arguments.length,n=s<3?e:o===null?o=Object.getOwnPropertyDescriptor(e,t):o,i;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")n=Reflect.decorate(a,e,t,o);else for(var r=a.length-1;r>=0;r--)(i=a[r])&&(n=(s<3?i(n):s>3?i(e,t,n):i(e,t))||n);return s>3&&n&&Object.defineProperty(e,t,n),n},f=function(a,e){if(typeof Reflect=="object"&&typeof Reflect.metadata=="function")return Reflect.metadata(a,e)};import{AIMessage as p,HumanMessage as L}from"@langchain/core/messages";import{Command as d,END as m}from"@langchain/langgraph";import{Tool as v}from"./graph-node.js";import{LlmNodeBase as R}from"./llm-node-base.js";import{stableClassId as I}from"./stable-id.js";import{TerminateSessionNode as M}from"./terminate-session.node.js";import{go as E,goTargetIds as l,isToolResponse as T}from"./tool-response.js";import{addTokenUsage as u}from"./token-usage.js";import{currentTurnSignal as g}from"./turn-context.js";class _ extends R{static{h(this,"LlmNode")}onEnter(e,t){return e}llmLifecycle(){return{...super.llmLifecycle(),onEnter:h(e=>this.onEnter(e,this.graph.hasInvocation()?this.graph.priorNode():void 0),"onEnter")}}onResponse(e,t){}managesLlmExecution(){return!0}isInternal(){return this.graph.hasInvocation()&&this.graph.invocationMode()==="internal"}includeTool(e,t){return!((t.mode==="internal"||t.mode===void 0&&this.isInternal())&&e==="terminate_session")}llmHistory(e){return this.isInternal()?[]:super.llmHistory(e)}async handleTool(e,t,o){if(this.isInternal()&&t.name==="terminate_session")throw this.invalidInternalOutcome(t.name);const s=await super.handleTool(e,t,o);return this.validateOutcome(s),s}validateLlmRecovery(e){e&&typeof e=="object"&&e.kind!=="retry_with_model"&&this.validateOutcome(e)}validateOutcome(e){const t=["target","targets","state","message","messages"].some(o=>o in e);if(e.kind==="taskResult"&&(!("value"in e)||e.value===void 0||t||["response","feedback","cleanup"].some(o=>o in e)))throw new Error(`LLM node '${this.id}' requires a taskResult value without conversation effects.`);if(e.targets!==void 0&&e.kind!=="go")throw new Error("Multiple targets are only supported by fanout().");if(e.kind==="go"&&l(e),this.isInternal()&&(e.kind!=="stay"&&e.kind!=="taskResult"&&e.kind!=="direct"||t))throw this.invalidInternalOutcome(e.kind)}invalidInternalOutcome(e){return new Error(`Internal LLM node '${this.id}' cannot use '${e}'; its caller owns conversation routing and completion.`)}async endChat(e){return E(M).withMessage(new L({content:e.message?.trim()||"The user asked to end the conversation.",additional_kwargs:{ezgraphInternal:!0}}))}async run(e){const t=await this.runLlm(e,{}),o=t.toolResponse;if(o&&(this.validateOutcome(o),o.kind!=="taskResult"&&o.kind!=="direct"))return this.resolveToolResponse(t,o);const s=o?.kind==="taskResult"?o.value:t.response;if(o?.kind!=="taskResult"&&(typeof s!="string"||!s.trim()))throw new Error(`LLM node '${this.id}' stopped without a response or tool transition.`);g()?.throwIfAborted();const n=await this.onResponse(s,e);g()?.throwIfAborted();let i=n===void 0?s:n,r=u(t.usage,o?.usage);if(T(n)){if(this.validateOutcome(n),n.cleanup)throw new Error(`LLM node '${this.id}' may use cleanup only from a tool handler.`);if(n.feedback!==void 0||n.messages)throw new Error(`LLM node '${this.id}' may use tool feedback/messages only from a tool handler.`);if(n.message&&n.kind!=="go"&&n.kind!=="directTo")throw new Error(`LLM node '${this.id}' may use withMessage() only with go() or directTo().`);if(n.kind==="stay")throw new Error(`LLM node '${this.id}' may return stay() only from a tool handler.`);if(n.kind!=="taskResult"&&n.kind!=="direct")return this.resolveToolResponse({...t,usage:r,messages:n.response?this.responseMessages(t,n.response):t.messages},n);i=n.kind==="taskResult"?n.value:n.response,r=u(r,n.usage)}if(typeof i=="string"&&!i.trim())throw new Error(`LLM node '${this.id}' onResponse() produced no response.`);if(this.isInternal())return{tokens:r};const c=typeof i=="string"?i:JSON.stringify(i);if(!c?.trim())throw new Error(`LLM node '${this.id}' onResponse() produced no response.`);return new d({update:{currentNode:this.id,response:c,inputConsumed:!0,completed:!1,...this.historyUpdate(this.responseMessages(t,c)),tokens:r},goto:m})}responseMessages(e,t){const o=[...e.messages],s=o.at(-1);return s&&p.isInstance(s)&&e.response!==void 0?t!==e.response&&(o[o.length-1]=new p({content:t,...s.id===void 0?{}:{id:s.id}})):o.push(new p(t)),o}resolveToolResponse(e,t){const o=this.historyUpdate(e.messages),s=u(e.usage,t.usage);if(t.kind==="go"){const n=l(t);if(n.length>1)return new d({update:{inputConsumed:!0,response:"",completed:!1,...o,tokens:s},goto:[...n]});if(!t.target)throw new Error(`LLM node '${this.id}' selected go() without a target.`);const i=n[0];return t.state&&this.graph.saveNodeState(t.target,t.state),t.message&&this.graph.appendHistory(this.graph.historySpace(i),[t.message]),new d({update:{currentNode:i,inputConsumed:!0,response:"",completed:!1,...o,tokens:s},goto:i})}if(t.kind==="directTo"){if(!t.target)throw new Error(`LLM node '${this.id}' selected directTo() without a target.`);const n=I(t.target,"graph node"),i=this.graph.historySpace(n);t.state&&this.graph.saveNodeState(t.target,t.state),t.message&&this.graph.appendHistory(i,[t.message]);const r=w(this.id,t);return i!==this.historySpace()&&this.graph.appendHistory(i,[new p(r)]),new d({update:{currentNode:n,response:r,inputConsumed:!0,completed:!1,...o,tokens:s},goto:m})}if(t.kind==="finish")return new d({update:{...this.graph.complete(w(this.id,t)),...o,tokens:s},goto:m});throw new Error(`LLM node '${this.id}' cannot publish '${t.kind}' as a conversation result.`)}}k([v("terminate_session"),f("design:type",Function),f("design:paramtypes",[Object]),f("design:returntype",Promise)],_.prototype,"endChat",null);function w(a,e){if(!e.response?.trim())throw new Error(`LLM node '${a}' selected ${e.kind}() without a response.`);return e.response}h(w,"requireResponse");export{_ as LlmNode};
1
+ var R=Object.defineProperty;var h=(a,e)=>R(a,"name",{value:e,configurable:!0});var v=function(a,e,t,o){var s=arguments.length,n=s<3?e:o===null?o=Object.getOwnPropertyDescriptor(e,t):o,i;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")n=Reflect.decorate(a,e,t,o);else for(var r=a.length-1;r>=0;r--)(i=a[r])&&(n=(s<3?i(n):s>3?i(e,t,n):i(e,t))||n);return s>3&&n&&Object.defineProperty(e,t,n),n},u=function(a,e){if(typeof Reflect=="object"&&typeof Reflect.metadata=="function")return Reflect.metadata(a,e)};import{AIMessage as p,HumanMessage as L}from"@langchain/core/messages";import{Command as d,END as m}from"@langchain/langgraph";import{Tool as E}from"./graph-node.js";import{LlmNodeBase as O}from"./llm-node-base.js";import{stableClassId as M}from"./stable-id.js";import{TerminateSessionNode as I}from"./terminate-session.node.js";import{go as T,goTargetIds as g,isToolResponse as w}from"./tool-response.js";import{addTokenUsage as f,emptyTokenUsage as _}from"./token-usage.js";import{currentTurnSignal as k}from"./turn-context.js";class x extends O{static{h(this,"LlmNode")}exitOutcomes=new WeakMap;onEnter(e,t){return e}llmLifecycle(){return{...super.llmLifecycle(),onEnter:h(e=>this.onEnter(e,this.graph.hasInvocation()?this.graph.priorNode():void 0),"onEnter")}}onResponse(e,t){}onExit(e){}async finalizeNodeResult(e,t){const o=this.exitOutcomes.get(e);if(this.exitOutcomes.delete(e),!o)return;const s=o.kind==="finish"?t.completed===!0?{kind:"finish",response:t.response??o.response}:{kind:"reply",response:t.response??""}:o;await this.onExit({nodeId:this.id,mode:this.graph.invocationMode(),state:this.graph.graphState(),outcome:s,usage:{...t.tokens??_()}}),(s.kind==="reply"||s.kind==="taskResult")&&this.graph.recordRunNodeOutcome(s)}withExitOutcome(e,t){return this.exitOutcomes.set(e,t),e}managesLlmExecution(){return!0}isInternal(){return this.graph.hasInvocation()&&this.graph.invocationMode()==="internal"}includeTool(e,t){return!((t.mode==="internal"||t.mode===void 0&&this.isInternal())&&e==="terminate_session")}llmHistory(e){return this.isInternal()?[]:super.llmHistory(e)}async handleTool(e,t,o){if(this.isInternal()&&t.name==="terminate_session")throw this.invalidInternalOutcome(t.name);const s=await super.handleTool(e,t,o);return this.validateOutcome(s),s}validateLlmRecovery(e){e&&typeof e=="object"&&e.kind!=="retry_with_model"&&this.validateOutcome(e)}validateOutcome(e){const t=["target","targets","state","message","messages"].some(o=>o in e);if(e.kind==="taskResult"&&(!("value"in e)||e.value===void 0||t||["response","feedback","cleanup"].some(o=>o in e)))throw new Error(`LLM node '${this.id}' requires a taskResult value without conversation effects.`);if(e.targets!==void 0&&e.kind!=="go")throw new Error("Multiple targets are only supported by fanout().");if(e.kind==="go"&&g(e),this.isInternal()&&(e.kind!=="stay"&&e.kind!=="taskResult"&&e.kind!=="direct"||t))throw this.invalidInternalOutcome(e.kind)}invalidInternalOutcome(e){return new Error(`Internal LLM node '${this.id}' cannot use '${e}'; its caller owns conversation routing and completion.`)}async endChat(e){return T(I).withMessage(new L({content:e.message?.trim()||"The user asked to end the conversation.",additional_kwargs:{ezgraphInternal:!0}}))}async run(e){const t=await this.runLlm(e,{}),o=t.toolResponse;if(o&&(this.validateOutcome(o),o.kind!=="taskResult"&&o.kind!=="direct"))return this.resolveToolResponse(t,o);const s=o?.kind==="taskResult"?o.value:t.response;if(o?.kind!=="taskResult"&&(typeof s!="string"||!s.trim()))throw new Error(`LLM node '${this.id}' stopped without a response or tool transition.`);k()?.throwIfAborted();const n=await this.onResponse(s,e);k()?.throwIfAborted();let i=n===void 0?s:n,r=f(t.usage,o?.usage);if(w(n)){if(this.validateOutcome(n),n.cleanup)throw new Error(`LLM node '${this.id}' may use cleanup only from a tool handler.`);if(n.feedback!==void 0||n.messages)throw new Error(`LLM node '${this.id}' may use tool feedback/messages only from a tool handler.`);if(n.message&&n.kind!=="go"&&n.kind!=="directTo")throw new Error(`LLM node '${this.id}' may use withMessage() only with go() or directTo().`);if(n.kind==="stay")throw new Error(`LLM node '${this.id}' may return stay() only from a tool handler.`);if(n.kind!=="taskResult"&&n.kind!=="direct")return this.resolveToolResponse({...t,usage:r,messages:n.response?this.responseMessages(t,n.response):t.messages},n);i=n.kind==="taskResult"?n.value:n.response,r=f(r,n.usage)}if(typeof i=="string"&&!i.trim())throw new Error(`LLM node '${this.id}' onResponse() produced no response.`);const l=(w(n)?n.kind==="taskResult":n===void 0&&o?.kind==="taskResult")?{kind:"taskResult",value:i}:{kind:"reply",response:typeof i=="string"?i:JSON.stringify(i)};if(this.isInternal())return this.withExitOutcome({tokens:r},l);const c=typeof i=="string"?i:JSON.stringify(i);if(!c?.trim())throw new Error(`LLM node '${this.id}' onResponse() produced no response.`);return this.withExitOutcome(new d({update:{currentNode:this.id,response:c,inputConsumed:!0,completed:!1,...this.historyUpdate(this.responseMessages(t,c)),tokens:r},goto:m}),l)}responseMessages(e,t){const o=[...e.messages],s=o.at(-1);return s&&p.isInstance(s)&&e.response!==void 0?t!==e.response&&(o[o.length-1]=new p({content:t,...s.id===void 0?{}:{id:s.id}})):o.push(new p(t)),o}resolveToolResponse(e,t){const o=this.historyUpdate(e.messages),s=f(e.usage,t.usage);if(t.kind==="go"){const n=g(t);if(n.length>1)return this.withExitOutcome(new d({update:{inputConsumed:!0,response:"",completed:!1,...o,tokens:s},goto:[...n]}),{kind:"fanout",targets:n});if(!t.target)throw new Error(`LLM node '${this.id}' selected go() without a target.`);const i=n[0];return t.state&&this.graph.saveNodeState(t.target,t.state),t.message&&this.graph.appendHistory(this.graph.historySpace(i),[t.message]),this.withExitOutcome(new d({update:{currentNode:i,inputConsumed:!0,response:"",completed:!1,...o,tokens:s},goto:i}),{kind:"go",targets:[i]})}if(t.kind==="directTo"){if(!t.target)throw new Error(`LLM node '${this.id}' selected directTo() without a target.`);const n=M(t.target,"graph node"),i=this.graph.historySpace(n);t.state&&this.graph.saveNodeState(t.target,t.state),t.message&&this.graph.appendHistory(i,[t.message]);const r=y(this.id,t);return i!==this.historySpace()&&this.graph.appendHistory(i,[new p(r)]),this.withExitOutcome(new d({update:{currentNode:n,response:r,inputConsumed:!0,completed:!1,...o,tokens:s},goto:m}),{kind:"directTo",targets:[n],response:r})}if(t.kind==="finish"){const n=y(this.id,t);return this.withExitOutcome(new d({update:{...this.graph.complete(n),...o,tokens:s},goto:m}),{kind:"finish",response:n})}throw new Error(`LLM node '${this.id}' cannot publish '${t.kind}' as a conversation result.`)}}v([E("terminate_session"),u("design:type",Function),u("design:paramtypes",[Object]),u("design:returntype",Promise)],x.prototype,"endChat",null);function y(a,e){if(!e.response?.trim())throw new Error(`LLM node '${a}' selected ${e.kind}() without a response.`);return e.response}h(y,"requireResponse");export{x as LlmNode};
@@ -1 +1 @@
1
- const MC=m;(function(r,S){const Mb={r:0x110,S:0x10d,w:0x12f,R:0xef,p:0xfb,I:0x142,a:0xeb},MK=m,w=r();while(!![]){try{const R=parseInt(MK(0xfd))/0x1+-parseInt(MK(0x132))/0x2+-parseInt(MK(Mb.r))/0x3*(-parseInt(MK(Mb.S))/0x4)+-parseInt(MK(0x13f))/0x5+parseInt(MK(Mb.w))/0x6*(parseInt(MK(Mb.R))/0x7)+parseInt(MK(Mb.p))/0x8*(parseInt(MK(0xfe))/0x9)+parseInt(MK(Mb.I))/0xa*(parseInt(MK(Mb.a))/0xb);if(R===S)break;else w['push'](w['shift']());}catch(p){w['push'](w['shift']());}}}(T,0xbab1a));var K=Object[MC(0x11c)],l=(r,S)=>K(r,MC(0x112),{'value':S,'configurable':!0x0});import{setTimeout as e}from'node:timers/promises';import{GraphLlm as A,ModelCatalog as v}from'./graph-llm.config.js';import{LlmResponseBlockedError as B,LlmSetupError as i}from'./llm-lifecycle.js';import{AIMessage as z,HumanMessage as s,RemoveMessage as f,ToolMessage as W}from'@langchain/core/messages';import{addTokenUsage as u,emptyTokenUsage as y}from'./token-usage.js';import{goTargetIds as g,isToolResponse as o}from'./tool-response.js';import{describeStopReason as k,isRetryableStopReason as h,modelStopReason as n}from'./model-stop-reason.js';import{SessionLogWarning as t}from'./session-log.js';import{isOpenAIAuthConfig as d,openAIAuthMessageText as C}from'./openai-auth-provider.js';class de extends Error{static{l(this,MC(0x10b));}[MC(0x107)];constructor(r){const Mx={r:0x10b},Mr=MC;super('The\x20model\x20returned\x20an\x20empty\x20response\x20('+k(r)+').'),this[Mr(0x107)]=r,this[Mr(0x112)]=Mr(Mx.r);}}const ce=0x8;function T(){const TA=['zgv0ywLS','C3rHEq','yxbWBhLszwnVDMvYEq','ChjVBxb0qMXVy2TLzenVBNrLEhq','C29Tzq','CMv0CMLLCW','C2HVDwXKuMv0CNLmBg1fCNjVCG','Aw50zxjUywXiDw1HBK1LC3nHz2u','CMv0CNLxAxrOtw9KzwWOksbTyxKGyMuGCMv0DxjUzwqGB25SEsbVBMnLigLUigeGCMvJB3zLCNKGC2vXDwvUy2uU','y2XLyw51Ca','ChjVDMLKzxi','CMvZCg9UC2vFBwv0ywrHDge','ywnXDwLYzunHBMrPzgf0zq','ndK4Ew5svuXc','B2jQzwn0','y2f0zwDVCNK','mJK1ntiYnM51yKToqG','zw1WDhLFCMvZCg9UC2u','Aw52B2nHDgLVBKnVBMzPzW','Dgv4Da','zxzLCNK','u3rHCNq','B25mBg1fCNjVCG','BgvUz3rO','y2fUzgLKyxrL','BwvZC2fNzq','yxnZzxj0rw1WDhLszxnWB25ZzvjLDhjPzxm','C3rYAw5N','igfNzw50ihjVDw5KCY4','mtmZnZy3mgzxCLnLCq','y2HLy2TszxnWB25Zzq','Cg9W','mtbXwg1ZCeq','DMfSDwu','BgXTr2f0zxDHEq','Bwf4qwDLBNrsB3vUzhm','B3rOzxi','BwvZC2fNzvrLEhq','BwLU','C2fMzxr5x3jHDgLUz3m','AgfUzgXLqMXVy2TLza','teXnihjLy292zxj5ignHBM5VDcbYzxr1CM4GDg9VBc1VBMX5ihn0yxKOksWGy2XLyw51CcWGB3iGzMvLzgjHy2SU','qsb0B29SigjHDgnOihnLBgvJDgvKig1VCMuGDgHHBIbVBMuGDgvYBwLUywWGCMvZCg9UC2uGB3iGDhjHBNnPDgLVBI4','BgXTq29UzMLN','B25fBNrLCG','Axntyw1LqMfYzvrYyw5ZAxrPB24','ywrKAxrPB25HBf9RD2fYz3m','y2XLyw51Cef0DgfJAg1LBNrZ','Bw9KzwW','CgfYyw1Z','CMvMDxnHBa','C2L6zq','ywXSu2v0DgXLza','ndC3odi1n2Tizgn4Dq','y2fSBe9WDgLVBNm','CMvZCg9UC2vFCMvQzwn0zwq','A2LUza','mtCYnJL5zun1yum','Dg9VBf9JywXSCW','CMv0CNLxAxrOtw9KzwWOksbPCYbZDxbWB3j0zwqGB25SEsbIEsbVBKXSBuvYCM9YkcKU','C3rVCf9KzxrHAwXZ','zMvLzgjHy2S','zw1WDhLszxnWB25ZzvjLy292zxj5lNjLDhjPzxmGBxvZDcbIzsbHig5VBI1UzwDHDgL2zsbPBNrLz2vYoYbYzwnLAxzLzca','CMvWBgfJzufSBa','yMXVy2TLza','yxnZzxj0twf4qwDLBNrsB3vUzhm','CMvZB2X2zunVBMzPzW','zw1WDhLiAxn0B3j5u2vLza','y29UDgvUDa','nZiYmdG1nKjNqNnUsa','BwfW','nZC2m0fdAvjeEa','ou1ZuhfZDG','C3rHDgu','D2fPDezVCLjLDhj5','DgHYB3DjzKfIB3j0zwq','ChjVBxb0','yxr0zw1WDhnFzxHOyxvZDgvK','ChvZAa','BM9YBwfSAxPLuMvHC29U','CMf0Aw5NCW','CMvHC29U','BM9KzuLK','AgfZq2fUzgLKyxrLq29UDgvUDa','AgLZDg9YEq','rw1WDhLnB2rLBfjLC3bVBNnLrxjYB3i','y29TBw9Uq29UDgv4Da','ndi2odeYz0XuCwLz','zw1WDhLszxnWB25ZzvjLy292zxj5','BwvZC2fNzxm','mJDKtenkt28','B25mBg1cBg9JA2vK','BMfTzq','ywDLBNq','C2LNBMfS','zw50CMLLCW','DxnHz2u','Dg9VBc1JywXSlq','CMv0CNLFD2L0Af9TB2rLBa','yMXVy2TszwfZB24','CNvU','vgHLig1VzgvSihjLC3bVBNnLihDHCYbYzwPLy3rLzcbIEsbJAgvJA1jLC3bVBNnLkcKU','zgvMAw5LuhjVCgvYDhK','CMvZCg9UC2u','DhjPBq','AxnbCNjHEq','tgXTuNvUBMvY','C3rYAw5NAwz5'];T=function(){return TA;};return T();}function ue(r){if(!Number['isInteger'](r)||r<0x1)throw new Error('maxAgentRounds\x20must\x20be\x20a\x20positive\x20integer;\x20received\x20'+String(r)+'.');return r;}l(ue,MC(0xf7));const P=MC(0x137),$={'retries':0x2,'nudge':'Follow\x20the\x20system\x20prompt\x20and\x20respond\x20properly.\x20Use\x20the\x20required\x20tool\x20when\x20instructed.'};function pe(r){const MD={r:0xf4},MS=MC;if(!Number['isInteger'](r)||r<0x0)throw new Error(MS(MD.r)+String(r)+'.');return r;}l(pe,MC(0x13c));const Te={'emptyHistorySeed':P,'emptyResponseRecovery':$};class Ie{static{l(this,MC(0x120));}[MC(0x144)];constructor(r){const Mw=MC;this[Mw(0x144)]=r;}async[MC(0x11a)](I){const T4={r:0x114,S:0x10a,w:0x14e,R:0x141,p:0x139,I:0x104,a:0x145,c:0x127,O:0x14d,b:0x12e,x:0xf0,J:0x143,D:0x141,E:0x143,M0:0x123,M1:0x123,M2:0x14c,M3:0xf3,M4:0x117,M5:0x112,M6:0x104,M7:0x10f,M8:0x101,M9:0x11d,MM:0x13e,MT:0x151},T3={r:0xea,S:0xfc},T2={r:0x101,S:0xe7,w:0x144,R:0x113,p:0x128,I:0x116,a:0xf6,c:0x13a,O:0x12c,b:0xe8,x:0x143,J:0xf2,D:0x150,E:0xf2,M0:0x122,M1:0x143,M2:0x140,M3:0x143,M4:0x11b,M5:0x138,M6:0x103},T1={r:0x101,S:0x111},T0={r:0x118,S:0x12a,w:0x123,R:0x12b,p:0x11d,I:0x104},MX=MC,J=I[MX(0xec)]?.[MX(T4.r)];J?.[MX(0x101)]();const D=[...I[MX(T4.S)]],M0=[],M1=I['lifecycle'];if(M1?.[MX(T4.w)]){const Mi=D['at'](-0x1),Mj=Mi&&s['isInstance'](Mi)?Mi:void 0x0,MG=M1[MX(0x14e)](Mj);J?.['throwIfAborted'](),MG!==Mj&&(Mj&&(D[MX(T4.R)](),Mj['id']&&Mj['id']!==MG?.['id']&&M0[MX(0x104)](new f({'id':Mj['id']}))),MG&&(D[MX(0x104)](MG),M0[MX(0x104)](MG)));}const M2=I['emptyHistorySeed']===void 0x0?P:I[MX(0xf9)];if(D[MX(T4.p)]===0x0&&M2!==null){const Ml=G(M2);D[MX(T4.I)](Ml),M0['push'](Ml);}let M3=[],M4=y();const M5=ue(I[MX(T4.a)]??ce),M6=I[MX(0x10e)]===void 0x0?$:I[MX(0x10e)],M7=M6?pe(M6[MX(T4.c)]):0x0;let M8=0x0,M9=I[MX(T4.O)],MM=!0x1;const MT=l(()=>M1?A[MX(0xf8)](M9,{'params':{'retries':0x0}}):M9,MX(0x134)),Mm=l(()=>({'nodeId':M1[MX(0x108)],'provider':v['resolveModelDescriptor'](M9)[MX(0x12c)],'model':M9[MX(0xe6)],...J===void 0x0?{}:{'signal':J}}),MX(0x10c)),Me=l(async(Mq,Mz)=>{const MR=MX;if(J?.[MR(0x101)](),Mq===null)throw Mz;if(typeof Mq==MR(0x130)&&Mq['kind']===MR(T0.r)){if(MM)throw new Error(MR(T0.S),{'cause':Mz});M9=A['validateConfig'](Mq[MR(0xe6)]),MM=!0x0,M8=0x0;return;}const Ms=typeof Mq==MR(0x13d)?void 0x0:Mq;if(Ms&&(Ms[MR(0xee)]===MR(T0.w)||Ms[MR(T0.R)]||Ms[MR(0xf3)]!==void 0x0))throw new Error(MR(0x14b));const Mf=typeof Mq==MR(0x13d)?Mq:Ms?.[MR(T0.p)];return Ms?.['messages']&&M0[MR(T0.I)](...Ms['messages']),Mf!==void 0x0&&M0['push'](new z(Mf)),{'messages':M0,'usage':M4,'stoppedAfterTool':!0x1,...Mf===void 0x0?{}:{'response':Mf},...Ms===void 0x0?{}:{'toolResponse':Ms}};},MX(0x124)),MA=l(async(Mq,Mz)=>{const Mp=MX;J?.[Mp(T1.r)]();const Ms=await M1[Mp(T1.S)](Mq);if(J?.[Mp(0x101)](),typeof Ms=='object'&&Ms!==null&&Ms[Mp(0xee)]==='retry_with_model')throw new Error(Mp(0xf1));return await Me(Ms,new B(Mq,Mz));},MX(0x14a)),Mv=l(async()=>{const MZ=MX;let Mq=0x0;for(;;){J?.[MZ(T2.r)]();const Mz=MM?0x1:Number(M9[MZ(T2.S)]['retries'])+0x1;Mq+=0x1;let Ms;const Mf=MT();try{Ms=await this[MZ(T2.w)][MZ(T2.R)](I['systemPrompt'],D,I['tools'],Mf,I[MZ(0xec)]);}catch(Mg){if(J?.[MZ(0x101)](),!M1||Mg instanceof i)throw Mg;const Mo=he(Mg,Mm());if(Mo)return MA(Mo,Mg);const Mk=Mg instanceof Error?Mg:new Error(String(Mg)),Mh=M1[MZ(T2.p)]({...Mm(),'error':Mk,'attempt':Mq,'maxAttempts':Mz});if(J?.[MZ(0x101)](),Mh!==!0x1&&Mq<Mz){await q(J);continue;}const MY={...Mm(),'kind':'invocation_error','error':Mk,'attemptsMade':Mq,'maxAttempts':Mz,'stoppedBecause':Mh===!0x1?'retry_declined':MZ(0x103)},MV=await Me(await M1[MZ(0x138)](MY),Mk);if(MV)return MV;Mq=0x0;continue;}if(J?.['throwIfAborted'](),M4=u(M4,Ms[MZ(T2.I)]),!M1)return Ms;const MW=n(Ms['value']);if(MW[MZ(0x131)]===MZ(T2.a)||[MZ(0x146),'image_other']['includes'](L(MW[MZ(0x12c)]??'')))return MA({...Mm(),'phase':MZ(T2.c),'rawReason':MW[MZ(T2.O)]??MZ(0xe8),'reason':L(MW['provider']??MZ(T2.b)),...Array[MZ(0x11f)](MW['ratings'])?{'safetyRatings':MW[MZ(0x106)]}:{},...(Ms[MZ(T2.x)][MZ(0x12d)][MZ(T2.J)]??Ms[MZ(T2.x)][MZ(T2.D)][MZ(T2.E)]??MW[MZ(0x122)])===void 0x0?{}:{'providerDetails':Ms[MZ(0x143)][MZ(0x12d)]['stop_details']??Ms[MZ(0x143)][MZ(0x150)]['stop_details']??MW[MZ(T2.M0)]}});if(!Y(Ms[MZ(T2.M1)]))return Ms;const Mu=M1[MZ(T2.M2)](Ms[MZ(T2.M3)]);if(J?.[MZ(0x101)](),!Mu)return Ms;if(Mq<Mz){await q(J);continue;}const My=new Error(MZ(T2.M4)),MQ=await Me(await M1[MZ(T2.M5)]({...Mm(),'kind':MZ(0xed),'error':My,'attemptsMade':Mq,'maxAttempts':Mz,'stoppedBecause':MZ(T2.M6),'lastResponse':Ms[MZ(T2.M3)]}),My);if(MQ)return MQ;Mq=0x0;}},MX(T4.b));try{for(let Mq=0x0;Mq<M5;Mq+=0x1){const Mz=await Mv();if(!(MX(0x143)in Mz))return Mz;M0[MX(0x104)](Mz[MX(0x143)]),D[MX(T4.I)](Mz[MX(0x143)]);const Ms=Mz[MX(0x143)][MX(T4.x)]??[];if(Ms['length']===0x0){const Mu=ye(Mz[MX(T4.J)],M9);if(Mu[MX(0x11e)]()&&(!M1||Y(Mz[MX(0x143)])))return await MB(),{'messages':M0,'usage':M4,'response':Mu,'stoppedAfterTool':!0x1};const My=n(Mz[MX(T4.J)]),MQ=h(My)&&M6!==null&&M8<M7&&!MM&&(!M1||Mq+0x1<M5);if(t({'empty_model_response':k(My),'retried':MQ}),MQ&&M6){M8+=0x1,M0[MX(0x141)](),D[MX(T4.R)](),D[MX(0x104)](G(M6['nudge']));continue;}if(M1){M0[MX(T4.D)](),D['pop']();const Mg=new de(My),Mo=await Me(await M1['onLlmError']({...Mm(),'kind':MX(0x133),'error':Mg,'attemptsMade':M8+0x1,'maxAttempts':MM?0x1:Math[MX(0x148)](M7+0x1,M8+M5-Mq),'stoppedBecause':MX(0x103),'lastResponse':Mz[MX(T4.E)]}),Mg);if(Mo)return Mo;Mq-=0x1;continue;}return await MB(),{'messages':M0,'usage':M4,'response':Mu,'stoppedAfterTool':!0x1,'stopReason':My};}await MB();let Mf=!0x1,MW;try{for(const [Mk,Mh]of Ms[MX(0x115)]()){J?.['throwIfAborted']();const MY=await I['executeTool'](Mh);if(o(MY)){if(MY['kind']==='go'&&g(MY),MY['kind']!==MX(T4.M0)){if(MW&&MW['kind']!==MX(T4.M1)&&!fe(MW,MY))throw new Error(MX(T4.M2));MW=MY;}else MW||(MW=MY);const MV=new W({'content':MY[MX(T4.M3)]??'OK','tool_call_id':Mh['id']??MX(T4.M4)+Mq+'-'+Mk,'name':Mh[MX(T4.M5)]});M0[MX(T4.M6)](MV),D[MX(T4.I)](MV),MY[MX(0x10f)]&&(M0[MX(T4.M6)](...MY[MX(0x10f)]),D[MX(0x104)](...MY[MX(T4.M7)])),MY[MX(0x12b)]&&M3[MX(T4.M6)](MY['cleanup']),J?.[MX(T4.M8)](),Mf||=MY['kind']!==MX(T4.M0);continue;}}}catch(Mn){throw await MB(),Mn;}if(Mf){const MH=MW?.[MX(T4.M9)];if(MH){const Mt=new z(MH);M0[MX(0x104)](Mt),D[MX(0x104)](Mt);}return await MB(),{'messages':M0,'usage':M4,'stoppedAfterTool':!0x0,...MH?{'response':MH}:{},...MW?{'toolResponse':MW}:{}};}}throw await MB(),new Error('Conversation\x20exceeded\x20'+M5+MX(T4.MM));}finally{await MB();}async function MB(){const MI=MX,Md=M3;M3=[],await Promise[MI(T3.r)](Md[MI(T3.S)](MN=>MN()));}l(MB,MX(T4.MT));}}function fe(r,S){const T5={r:0xee,S:0x139,w:0xe9,R:0x13b,p:0x10f,I:0x12b},Ma=MC;if(r[Ma(T5.r)]!=='go'||S['kind']!=='go')return!0x1;const w=g(r),R=new Set(g(S));return w[Ma(T5.S)]===R[Ma(T5.w)]&&w[Ma(0x136)](p=>R['has'](p))&&r[Ma(0xff)]===void 0x0&&S[Ma(0xff)]===void 0x0&&r[Ma(0x13b)]===void 0x0&&S[Ma(T5.R)]===void 0x0&&r[Ma(0x10f)]===void 0x0&&S[Ma(T5.p)]===void 0x0&&r['cleanup']===void 0x0&&S[Ma(T5.I)]===void 0x0&&r['response']===void 0x0&&S[Ma(0x11d)]===void 0x0&&r['usage']===void 0x0&&S[Ma(0x116)]===void 0x0;}l(fe,MC(0x14f));function G(r){return new s({'content':r,'additional_kwargs':{'ezgraphInternal':!0x0}});}l(G,MC(0x129));function me(r){const T7={r:0xfa,S:0x121},MP=MC;return typeof r[MP(T7.r)]==MP(0x13d)?r['content']:JSON[MP(T7.S)](r[MP(0xfa)]);}l(me,MC(0x147));function ye(r,S){const T8={r:0xfa},MF=MC;return d(S)?C(r[MF(T8.r)]):me(r);}l(ye,'responseText');function L(r){const T9={r:0xf5},MU=MC;return r['trim']()['toLowerCase']()[MU(T9.r)]('-','_');}l(L,MC(0x105));function he(r,S){const TM={r:0x130,S:0x11e,w:0x149,R:0x102},ML=MC;if(!r||typeof r!=ML(TM.r))return null;const w=r,R=w[ML(0x119)]??w['block_reason'];if(typeof R!=ML(0x13d)||!R[ML(TM.S)]())return null;const p=w['safetyRatings']??w[ML(TM.w)];return{...S,'phase':ML(TM.R),'rawReason':R,'reason':L(R),...Array[ML(0x11f)](p)?{'safetyRatings':p}:{}};}l(he,MC(0x125));function Y(r){const TT={r:0xf0,S:0x139,w:0x126},Mc=MC;return r[Mc(TT.r)]?.[Mc(TT.S)]?!0x0:typeof r[Mc(0xfa)]=='string'?!!r['content']['trim']():r[Mc(0xfa)][Mc(TT.w)](S=>typeof S['text']=='string'&&!!S[Mc(0x135)][Mc(0x11e)]());}l(Y,MC(0x109));async function q(r){const Tm={r:0x101},MO=MC;try{await e(0x1f4,void 0x0,r?{'signal':r}:void 0x0);}catch(S){throw r?.[MO(Tm.r)](),S;}}function m(M,e){M=M-0xe6;const A=T();let v=A[M];if(m['FJKesf']===undefined){var B=function(l){const q='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+/=';let z='',s='';for(let f=0x0,W,u,y=0x0;u=l['charAt'](y++);~u&&(W=f%0x4?W*0x40+u:u,f++%0x4)?z+=String['fromCharCode'](0xff&W>>(-0x2*f&0x6)):0x0){u=q['indexOf'](u);}for(let Q=0x0,g=z['length'];Q<g;Q++){s+='%'+('00'+z['charCodeAt'](Q)['toString'](0x10))['slice'](-0x2);}return decodeURIComponent(s);};m['MmaGmy']=B,m['spNUTg']={},m['FJKesf']=!![];}const i=A[0x0],j=M+i,G=m['spNUTg'][j];return!G?(v=m['MmaGmy'](v),m['spNUTg'][j]=v):v=G,v;}l(q,MC(0x100));export{P as DEFAULT_EMPTY_HISTORY_SEED,$ as DEFAULT_EMPTY_RESPONSE_RECOVERY,Te as DEFAULT_LLM_POLICY,ce as DEFAULT_MAX_AGENT_ROUNDS,de as EmptyModelResponseError,Ie as LlmRunner,pe as assertEmptyResponseRetries,ue as assertMaxAgentRounds};
1
+ const lt=h;(function(x,i){const lT={x:0x1d9,i:0x217,O:0x1c9},lV=h,O=x();while(!![]){try{const t=-parseInt(lV(0x1de))/0x1+parseInt(lV(lT.x))/0x2+-parseInt(lV(0x1e8))/0x3+parseInt(lV(lT.i))/0x4+-parseInt(lV(0x1d6))/0x5+parseInt(lV(lT.O))/0x6*(parseInt(lV(0x1c6))/0x7)+parseInt(lV(0x22e))/0x8;if(t===i)break;else O['push'](O['shift']());}catch(k){O['push'](O['shift']());}}}(l,0x83962));var V=Object[lt(0x225)],d=(x,i)=>V(x,lt(0x1ef),{'value':i,'configurable':!0x0});import{setTimeout as c}from'node:timers/promises';import{GraphLlm as e,ModelCatalog as r}from'./graph-llm.config.js';import{LlmResponseBlockedError as v,LlmSetupError as I}from'./llm-lifecycle.js';import{AIMessage as s,HumanMessage as E,RemoveMessage as D,ToolMessage as A}from'@langchain/core/messages';import{addTokenUsage as m,emptyTokenUsage as w}from'./token-usage.js';import{goTargetIds as C,isToolResponse as o}from'./tool-response.js';import{describeStopReason as b,isRetryableStopReason as n,modelStopReason as R}from'./model-stop-reason.js';import{SessionLogWarning as f}from'./session-log.js';import{observeRunNodeUsage as u}from'./node-invocation.js';import{isOpenAIAuthConfig as J,openAIAuthMessageText as g}from'./openai-auth-provider.js';class ue extends Error{static{d(this,lt(0x20d));}[lt(0x1c3)];constructor(x){const lF={x:0x218,i:0x1c3},ld=lt;super(ld(lF.x)+b(x)+').'),this[ld(lF.i)]=x,this['name']=ld(0x20d);}}const pe=0x8;function fe(x){const h0={x:0x1e5,i:0x229},lk=lt;if(!Number[lk(h0.x)](x)||x<0x1)throw new Error(lk(h0.i)+String(x)+'.');return x;}d(fe,lt(0x1fc));const H=lt(0x22c),$={'retries':0x2,'nudge':lt(0x1eb)};function me(x){const la=lt;if(!Number[la(0x1e5)](x)||x<0x0)throw new Error(la(0x1c5)+String(x)+'.');return x;}d(me,'assertEmptyResponseRetries');const Le={'emptyHistorySeed':H,'emptyResponseRecovery':$};class Se{static{d(this,'LlmRunner');}[lt(0x20a)];constructor(x){const lp=lt;this[lp(0x20a)]=x;}async[lt(0x1d2)](B){const h7={x:0x1dd,i:0x21c,O:0x220,t:0x1f1,k:0x1ff,a:0x1d1,p:0x206,W:0x1db,z:0x214,B:0x1cf,y:0x226,S:0x228,K:0x1d0,T:0x208,l0:0x20e,l1:0x1d0,l2:0x1fd,l3:0x221,l4:0x224,l5:0x1e9,l6:0x1e9,l7:0x1f4,l8:0x1d1,l9:0x1f4,ll:0x1f4,lh:0x21a,lc:0x1e9,lr:0x201,lQ:0x1c8},h6={x:0x216},h5={x:0x220,i:0x1fb,O:0x1df,t:0x1cb,k:0x227,a:0x1e6,p:0x213,W:0x222,z:0x1fa,B:0x1d0,y:0x21b,S:0x1d0,K:0x21f,T:0x21b,l0:0x1fe,l1:0x1d0,l2:0x1da,l3:0x21b,l4:0x1fe,l5:0x1d5,l6:0x20c},h4={x:0x220,i:0x220,O:0x200,t:0x1dc},h3={x:0x20f,i:0x1e4,O:0x21a,t:0x1f4,k:0x1f4},lW=lt,K=B[lW(h7.x)]?.[lW(h7.i)];K?.[lW(h7.O)]();const l0=[...B[lW(0x204)]],l1=[],l2=B['lifecycle'];if(l2?.[lW(h7.t)]){const lE=l0['at'](-0x1),lD=lE&&E[lW(h7.k)](lE)?lE:void 0x0,lA=await l2['onEnter'](lD);K?.[lW(0x220)](),lA!==lD&&(lD&&(l0[lW(0x1cc)](),lD['id']&&lD['id']!==lA?.['id']&&l1['push'](new D({'id':lD['id']}))),lA&&(l0[lW(h7.a)](lA),l1[lW(0x1d1)](lA)));}const l3=typeof B[lW(h7.p)]==lW(h7.W)?B[lW(0x206)]():B['systemPrompt'];K?.[lW(h7.O)]();const l4=B['emptyHistorySeed']===void 0x0?H:B[lW(h7.z)];if(l0[lW(0x1e7)]===0x0&&l4!==null){const lj=G(l4);l0['push'](lj),l1['push'](lj);}let l5=[],l6=w();const l7=fe(B[lW(0x1f3)]??pe),l8=B['emptyResponseRecovery']===void 0x0?$:B[lW(h7.B)],l9=l8?me(l8[lW(h7.y)]):0x0;let ll=0x0,lh=B[lW(0x1cd)],lc=!0x1;const lr=d(()=>l2?e[lW(0x22f)](lh,{'params':{'retries':0x0}}):lh,'invocationConfig'),lQ=d(()=>({'nodeId':l2[lW(0x1c0)],'provider':r[lW(0x1c4)](lh)['provider'],'model':lh[lW(0x1ea)],...K===void 0x0?{}:{'signal':K}}),lW(h7.S)),lv=d(async(lH,lm)=>{const lz=lW;if(K?.[lz(0x220)](),lH===null)throw lm;if(typeof lH=='object'&&lH[lz(0x200)]===lz(0x1ec)){if(lc)throw new Error(lz(h3.x),{'cause':lm});lh=e[lz(0x1f5)](lH[lz(0x1ea)]),lc=!0x0,ll=0x0;return;}const lw=typeof lH==lz(h3.i)?void 0x0:lH;if(lw&&(lw['kind']==='stay'||lw[lz(h3.O)]||lw[lz(0x1d7)]!==void 0x0))throw new Error(lz(0x1d3));const lZ=typeof lH=='string'?lH:lw?.[lz(0x1c1)];return lw?.[lz(h3.t)]&&l1[lz(0x1d1)](...lw[lz(h3.k)]),lZ!==void 0x0&&l1['push'](new s(lZ)),{'messages':l1,'usage':l6,'stoppedAfterTool':!0x1,...lZ===void 0x0?{}:{'response':lZ},...lw===void 0x0?{}:{'toolResponse':lw}};},'applyRecovery'),lG=d(async(lH,lm)=>{const lP=lW;K?.[lP(h4.x)]();const lw=await l2[lP(0x22b)](lH);if(K?.[lP(h4.i)](),typeof lw==lP(0x21d)&&lw!==null&&lw[lP(h4.O)]===lP(0x1ec))throw new Error(lP(h4.t));return await lv(lw,new v(lH,lm));},lW(0x1f7)),lI=d(async()=>{const lY=lW;let lH=0x0;for(;;){K?.[lY(h5.x)]();const lm=lc?0x1:Number(lh[lY(h5.i)][lY(0x226)])+0x1;lH+=0x1;let lw;const lZ=lr();try{lw=await this['llmGateway'][lY(h5.O)](l3,l0,B['tools'],lZ,B[lY(0x1dd)]);}catch(lb){if(K?.[lY(0x220)](),!l2||lb instanceof I)throw lb;const ln=ge(lb,lQ());if(ln)return lG(ln,lb);const lR=lb instanceof Error?lb:new Error(String(lb)),lf=l2['shouldRetryLlmError']({...lQ(),'error':lR,'attempt':lH,'maxAttempts':lm});if(K?.[lY(0x220)](),lf!==!0x1&&lH<lm){await q(K);continue;}const lu={...lQ(),'kind':lY(h5.t),'error':lR,'attemptsMade':lH,'maxAttempts':lm,'stoppedBecause':lf===!0x1?lY(0x209):lY(0x210)},lJ=await lv(await l2[lY(0x221)](lu),lR);if(lJ)return lJ;lH=0x0;continue;}if(K?.[lY(0x220)](),l6=m(l6,lw['usage']),u(lw[lY(0x1ca)]),!l2)return lw;const lC=R(lw[lY(0x1d0)]);if(lC[lY(0x1ce)]==='blocked'||[lY(h5.k),lY(h5.a)]['includes'](L(lC['provider']??'')))return lG({...lQ(),'phase':'candidate','rawReason':lC[lY(h5.p)]??lY(0x222),'reason':L(lC['provider']??lY(h5.W)),...Array[lY(h5.z)](lC['ratings'])?{'safetyRatings':lC['ratings']}:{},...(lw[lY(h5.B)]['response_metadata'][lY(h5.y)]??lw[lY(h5.S)][lY(h5.K)][lY(h5.T)]??lC[lY(h5.l0)])===void 0x0?{}:{'providerDetails':lw[lY(h5.l1)][lY(h5.l2)][lY(h5.l3)]??lw[lY(h5.l1)][lY(h5.K)][lY(0x21b)]??lC[lY(h5.l4)]}});if(!Y(lw[lY(h5.l1)]))return lw;const lo=l2[lY(h5.l5)](lw['value']);if(K?.[lY(h5.x)](),!lo)return lw;if(lH<lm){await q(K);continue;}const lL=new Error(lY(0x1f9)),lq=await lv(await l2[lY(0x221)]({...lQ(),'kind':lY(h5.l6),'error':lL,'attemptsMade':lH,'maxAttempts':lm,'stoppedBecause':lY(0x210),'lastResponse':lw[lY(0x1d0)]}),lL);if(lq)return lq;lH=0x0;}},lW(0x22a));try{for(let lH=0x0;lH<l7;lH+=0x1){const lm=await lI();if(!(lW(h7.K)in lm))return lm;l1['push'](lm['value']),l0[lW(0x1d1)](lm[lW(h7.K)]);const lw=lm[lW(h7.K)][lW(h7.T)]??[];if(lw[lW(0x1e7)]===0x0){const lo=we(lm[lW(h7.K)],lh);if(lo[lW(h7.l0)]()&&(!l2||Y(lm['value'])))return await ls(),{'messages':l1,'usage':l6,'response':lo,'stoppedAfterTool':!0x1};const lL=R(lm[lW(h7.l1)]),lq=n(lL)&&l8!==null&&ll<l9&&!lc&&(!l2||lH+0x1<l7);if(f({'empty_model_response':b(lL),'retried':lq}),lq&&l8){ll+=0x1,l1['pop'](),l0['pop'](),l0[lW(h7.a)](G(l8[lW(h7.l2)]));continue;}if(l2){l1['pop'](),l0[lW(0x1cc)]();const lb=new ue(lL),ln=await lv(await l2[lW(h7.l3)]({...lQ(),'kind':lW(0x1ed),'error':lb,'attemptsMade':ll+0x1,'maxAttempts':lc?0x1:Math[lW(0x1f8)](l9+0x1,ll+l7-lH),'stoppedBecause':'attempts_exhausted','lastResponse':lm[lW(0x1d0)]}),lb);if(ln)return ln;lH-=0x1;continue;}return await ls(),{'messages':l1,'usage':l6,'response':lo,'stoppedAfterTool':!0x1,'stopReason':lL};}await ls();let lZ=!0x1,lC;try{for(const [lR,lf]of lw[lW(0x21e)]()){K?.[lW(0x220)]();const lu=await B[lW(h7.l4)](lf);if(o(lu)){if(lu[lW(0x200)]==='go'&&C(lu),lu['kind']!==lW(h7.l5)){if(lC&&lC[lW(0x200)]!==lW(h7.l6)&&!ye(lC,lu))throw new Error(lW(0x207));lC=lu;}else lC||(lC=lu);const lJ=new A({'content':lu[lW(0x1d7)]??'OK','tool_call_id':lf['id']??lW(0x1d4)+lH+'-'+lR,'name':lf[lW(0x1ef)]});l1['push'](lJ),l0['push'](lJ),lu[lW(h7.l7)]&&(l1[lW(h7.l8)](...lu[lW(h7.l9)]),l0['push'](...lu[lW(h7.ll)])),lu[lW(h7.lh)]&&l5[lW(0x1d1)](lu['cleanup']),K?.['throwIfAborted'](),lZ||=lu['kind']!==lW(h7.lc);continue;}}}catch(lg){throw await ls(),lg;}if(lZ){const lN=lC?.[lW(0x1c1)];if(lN){const lx=new s(lN);l1['push'](lx),l0[lW(h7.a)](lx);}return await ls(),{'messages':l1,'usage':l6,'stoppedAfterTool':!0x0,...lN?{'response':lN}:{},...lC?{'toolResponse':lC}:{}};}}throw await ls(),new Error(lW(h7.lr)+l7+lW(h7.lQ));}finally{await ls();}async function ls(){const lB=lW,li=l5;l5=[],await Promise[lB(h6.x)](li[lB(0x1ee)](lO=>lO()));}d(ls,'cleanupAttachments');}}function ye(x,i){const h8={x:0x200,i:0x1f2,O:0x219,t:0x1f4,k:0x21a,a:0x1c1,p:0x1ca},ly=lt;if(x[ly(h8.x)]!=='go'||i[ly(h8.x)]!=='go')return!0x1;const O=C(x),k=new Set(C(i));return O[ly(0x1e7)]===k[ly(h8.i)]&&O[ly(0x22d)](p=>k[ly(0x1e3)](p))&&x[ly(0x219)]===void 0x0&&i[ly(h8.O)]===void 0x0&&x['message']===void 0x0&&i['message']===void 0x0&&x[ly(0x1f4)]===void 0x0&&i[ly(h8.t)]===void 0x0&&x['cleanup']===void 0x0&&i[ly(h8.k)]===void 0x0&&x[ly(0x1c1)]===void 0x0&&i[ly(h8.a)]===void 0x0&&x['usage']===void 0x0&&i[ly(h8.p)]===void 0x0;}d(ye,lt(0x1d8));function G(x){return new E({'content':x,'additional_kwargs':{'ezgraphInternal':!0x0}});}d(G,lt(0x215));function he(x){const hl={x:0x1c7,i:0x1e4},lU=lt;return typeof x[lU(hl.x)]==lU(hl.i)?x[lU(0x1c7)]:JSON[lU(0x1f6)](x[lU(0x1c7)]);}d(he,lt(0x1e0));function we(x,i){return J(i)?g(x['content']):he(x);}d(we,lt(0x1e2));function L(x){const hc={x:0x212},lX=lt;return x['trim']()['toLowerCase']()[lX(hc.x)]('-','_');}function h(c,e){c=c-0x1c0;const r=l();let Q=r[c];if(h['lAqOKE']===undefined){var v=function(E){const D='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+/=';let A='',j='';for(let H=0x0,m,w,Z=0x0;w=E['charAt'](Z++);~w&&(m=H%0x4?m*0x40+w:w,H++%0x4)?A+=String['fromCharCode'](0xff&m>>(-0x2*H&0x6)):0x0){w=D['indexOf'](w);}for(let C=0x0,o=A['length'];C<o;C++){j+='%'+('00'+A['charCodeAt'](C)['toString'](0x10))['slice'](-0x2);}return decodeURIComponent(j);};h['ChChuV']=v,h['kDTAzo']={},h['lAqOKE']=!![];}const G=r[0x0],I=c+G,s=h['kDTAzo'][I];return!s?(Q=h['ChChuV'](Q),h['kDTAzo'][I]=Q):Q=s,Q;}function l(){const hG=['C2LNBMfS','B2jQzwn0','zw50CMLLCW','ywrKAxrPB25HBf9RD2fYz3m','DgHYB3DjzKfIB3j0zwq','B25mBg1fCNjVCG','CMvMDxnHBa','yMXVy2TFCMvHC29U','zxHLy3v0zvrVB2W','zgvMAw5LuhjVCgvYDhK','CMv0CMLLCW','B3rOzxi','y29TBw9Uq29UDgv4Da','Bwf4qwDLBNrsB3vUzhmGBxvZDcbIzsbHihbVC2L0AxzLigLUDgvNzxi7ihjLy2vPDMvKia','ywnXDwLYzunHBMrPzgf0zq','B25mBg1cBg9JA2vK','u3rHCNq','zxzLCNK','mtm3otKWngHRBKzxwq','CMvZB2X2zunVBMzPzW','BM9KzuLK','CMvZCg9UC2u','C2fMzxr5uMf0Aw5NCW','CMvHC29U','CMvZB2X2zu1VzgvSrgvZy3jPChrVCG','zw1WDhLszxnWB25ZzvjLy292zxj5lNjLDhjPzxmGBxvZDcbIzsbHig5VBI1UzwDHDgL2zsbPBNrLz2vYoYbYzwnLAxzLzca','mZm2n0vyz2fZyq','y29UDgvUDa','igfNzw50ihjVDw5KCY4','mte0mfrwCvHuzq','DxnHz2u','Aw52B2nHDgLVBL9LCNjVCG','Cg9W','BgXTq29UzMLN','y2f0zwDVCNK','zw1WDhLszxnWB25ZzvjLy292zxj5','DMfSDwu','ChvZAa','CNvU','teXnihjLy292zxj5ignHBM5VDcbYzxr1CM4GDg9VBc1VBMX5ihn0yxKOksWGy2XLyw51CcWGB3iGzMvLzgjHy2SU','Dg9VBc1JywXSlq','y2HLy2TszxnWB25Zzq','mJu5oti1A2HNtLzI','zMvLzgjHy2S','Axntyw1LqMfYzvrYyw5ZAxrPB24','otm2odi0CLr6uM1A','CMvZCg9UC2vFBwv0ywrHDge','zNvUy3rPB24','CMv0CNLxAxrOtw9KzwWOksbPCYbZDxbWB3j0zwqGB25SEsbIEsbVBKXSBuvYCM9YkcKU','y2fSBe9WDgLVBNm','nJu4mJqZBenoyLnO','ywDLBNq','BwvZC2fNzvrLEhq','yMXVy2TszwfZB24','CMvZCg9UC2vuzxH0','AgfZ','C3rYAw5N','AxnjBNrLz2vY','Aw1Hz2vFB3rOzxi','BgvUz3rO','nty1nZe5sKHuAevt','C3rHEq','Bw9KzwW','rM9SBg93ihrOzsbZExn0zw0GChjVBxb0igfUzcbYzxnWB25KihbYB3bLCMX5lIbvC2uGDgHLihjLCxvPCMvKihrVB2WGD2HLBIbPBNn0CNvJDgvKlG','CMv0CNLFD2L0Af9TB2rLBa','zw1WDhLFCMvZCg9UC2u','BwfW','BMfTzq','C2fMzxr5x3jHDgLUz3m','B25fBNrLCG','C2L6zq','Bwf4qwDLBNrsB3vUzhm','BwvZC2fNzxm','DMfSAwrHDgvdB25MAwC','C3rYAw5NAwz5','AgfUzgXLqMXVy2TLza','BwLU','vgHLig1VzgvSihjLC3bVBNnLihDHCYbYzwPLy3rLzcbIEsbJAgvJA1jLC3bVBNnLkcKU','AxnbCNjHEq','CgfYyw1Z','yxnZzxj0twf4qwDLBNrsB3vUzhm','BNvKz2u','zgv0ywLS','AxnjBNn0yw5Jzq','A2LUza','q29UDMvYC2f0Aw9Uigv4y2vLzgvKia','BM9YBwfSAxPLuMvHC29U','ChjVBxb0','AgLZDg9YEq','AgfZq2fUzgLKyxrLq29UDgvUDa','C3LZDgvTuhjVBxb0','qsb0B29SigjHDgnOihnLBgvJDgvKig1VCMuGDgHHBIbVBMuGDgvYBwLUywWGCMvZCg9UC2uGB3iGDhjHBNnPDgLVBI4','Dg9VBf9JywXSCW','CMv0CNLFzgvJBgLUzwq','BgXTr2f0zxDHEq','ChjVBxb0qMXVy2TLzenVBNrLEhq','CMvZCg9UC2vFCMvQzwn0zwq','rw1WDhLnB2rLBfjLC3bVBNnLrxjYB3i','DhjPBq','CMv0CNLxAxrOtw9KzwWOksbTyxKGyMuGCMv0DxjUzwqGB25SEsbVBMnLigLUigeGCMvJB3zLCNKGC2vXDwvUy2uU','yxr0zw1WDhnFzxHOyxvZDgvK','C29Tzq','CMvWBgfJzufSBa','ChjVDMLKzxi','zw1WDhLiAxn0B3j5u2vLza','Aw50zxjUywXiDw1HBK1LC3nHz2u','ywXSu2v0DgXLza','mJGYmtK1nNr5q211wG','vgHLig1VzgvSihjLDhvYBMvKigfUigvTChr5ihjLC3bVBNnLicG','C3rHDgu','y2XLyw51Ca','C3rVCf9KzxrHAwXZ'];l=function(){return hG;};return l();}d(L,lt(0x202));function ge(x,O){const hr={x:0x21d,i:0x1e1,O:0x223,t:0x20e,k:0x1c2,a:0x1fa},lM=lt;if(!x||typeof x!=lM(hr.x))return null;const k=x,p=k[lM(hr.i)]??k[lM(hr.O)];if(typeof p!='string'||!p[lM(hr.t)]())return null;const W=k[lM(hr.k)]??k[lM(0x1f0)];return{...O,'phase':lM(0x203),'rawReason':p,'reason':L(p),...Array[lM(hr.a)](W)?{'safetyRatings':W}:{}};}d(ge,lt(0x20b));function Y(x){const hQ={x:0x1c7,i:0x1c7},lS=lt;return x[lS(0x208)]?.[lS(0x1e7)]?!0x0:typeof x['content']==lS(0x1e4)?!!x[lS(hQ.x)][lS(0x20e)]():x[lS(hQ.i)][lS(0x211)](i=>typeof i['text']=='string'&&!!i['text'][lS(0x20e)]());}d(Y,lt(0x205));async function q(x){const hv={x:0x220},lK=lt;try{await c(0x1f4,void 0x0,x?{'signal':x}:void 0x0);}catch(i){throw x?.[lK(hv.x)](),i;}}d(q,'waitForRetry');export{H as DEFAULT_EMPTY_HISTORY_SEED,$ as DEFAULT_EMPTY_RESPONSE_RECOVERY,Le as DEFAULT_LLM_POLICY,pe as DEFAULT_MAX_AGENT_ROUNDS,ue as EmptyModelResponseError,Se as LlmRunner,me as assertEmptyResponseRetries,fe as assertMaxAgentRounds};
@@ -1 +1 @@
1
- var v=Object.defineProperty;var n=(o,t)=>v(o,"name",{value:t,configurable:!0});import{AsyncLocalStorage as p}from"node:async_hooks";import{messagesStateReducer as h}from"@langchain/langgraph";import{cloneJsonObject as a,readonlyContext as y}from"./graph-context.js";const u=new p;function N(o){return u.getStore()?.owner===o}n(N,"hasNodeInvocation");async function b(o,t,e,r,i={},f=!1){const s=u.getStore();if(i.mode!==void 0&&i.mode!=="conversation"&&i.mode!=="internal")throw new Error(`Invalid node invocation mode '${String(i.mode)}'.`);if(s&&i.mode==="conversation")throw new Error("A nested node cannot take ownership of the conversation.");const x=s?"internal":i.mode??"conversation";return u.run({owner:o,nodeId:t,state:e,nodes:{},histories:{},mode:x,...s?.owner===o?{priorNode:s.nodeId}:{},localStateOnly:x==="internal"&&(f||s?.localStateOnly===!0)},r)}n(b,"withNodeInvocation");function k(o){return c(o).mode}n(k,"invocationMode");function j(o){return c(o).localStateOnly}n(j,"invocationIsLocalOnly");function d(o,t){const e=c(o);if(e.localStateOnly&&t!==e.nodeId)throw new Error(`Internal LLM node '${e.nodeId}' may publish only its own node state and token usage.`)}n(d,"assertInvocationWrite");function w(o){return c(o).nodeId}n(w,"invocationNodeId");function C(o){return c(o).priorNode}n(C,"invocationPriorNode");function E(o){const t=c(o);return y(t.context??t.state.context??{})}n(E,"invocationContext");function L(o,t){d(o);const e=c(o),r=a(t,"Context patch");e.context={...a(e.context??e.state.context??{}),...r}}n(L,"saveInvocationContext");function A(o,t){d(o),c(o).context=a(t)}n(A,"replaceInvocationContext");function l(o,t){const e=c(o),r=e.nodes[t];return r?{...r}:{...(e.state.nodes??{})[t]??{}}}n(l,"invocationNodeState");function H(o,t,e){d(o,t);const r=l(o,t);for(const[i,f]of Object.entries(e))f===void 0?delete r[i]:r[i]=f;c(o).nodes[t]=r}n(H,"saveInvocationNodeState");function M(o,t,e){d(o,t),c(o).nodes[t]={...e}}n(M,"replaceInvocationNodeState");function $(o,t,e){d(o);const r=c(o);r.histories[t]=[...r.histories[t]??[],...e]}n($,"appendInvocationHistory");function m(o,t){const e=c(o);return h(e.state.histories?.[t]??[],e.histories[t]??[])}n(m,"invocationHistory");function q(o){const t=c(o),e={...t.state.nodes??{}};for(const i of Object.keys(t.nodes))e[i]=l(o,i);const r={...t.state.histories??{}};for(const i of Object.keys(t.histories))r[i]=m(o,i);return{...t.state,nodes:e,histories:r,context:a(t.context??t.state.context??{})}}n(q,"invocationGraphState");function G(o){const t=c(o);return{...t.context!==void 0?{context:a(t.context)}:{},...Object.keys(t.nodes).length>0?{nodes:t.nodes}:{},...Object.keys(t.histories).length>0?{histories:t.histories}:{}}}n(G,"invocationUpdate");function c(o){const t=u.getStore();if(!t||t.owner!==o)throw new Error("Node state can only be accessed during an active graph-node invocation.");return t}n(c,"requireInvocation");export{$ as appendInvocationHistory,d as assertInvocationWrite,N as hasNodeInvocation,E as invocationContext,q as invocationGraphState,m as invocationHistory,j as invocationIsLocalOnly,k as invocationMode,w as invocationNodeId,l as invocationNodeState,C as invocationPriorNode,G as invocationUpdate,A as replaceInvocationContext,M as replaceInvocationNodeState,L as saveInvocationContext,H as saveInvocationNodeState,b as withNodeInvocation};
1
+ var m=Object.defineProperty;var r=(t,e)=>m(t,"name",{value:e,configurable:!0});import{AsyncLocalStorage as x}from"node:async_hooks";import{messagesStateReducer as S}from"@langchain/langgraph";import{cloneJsonObject as h,readonlyContext as b}from"./graph-context.js";import{addTokenUsage as p}from"./token-usage.js";import{addDecisionUsage as N}from"./decision/decision-types.js";import{SessionLogWarning as y}from"./session-log.js";const g=new x,u=new x;function A(t,e){return u.run(t,e)}r(A,"withRunNodeExecution");function L(t,e){const o=u.getStore();o?.owner===t&&(o.outcome=e)}r(L,"recordRunNodeOutcome");function $(t){const e=u.getStore();e&&(e.usage=p(e.usage,t))}r($,"observeRunNodeUsage");function H(t){const e=u.getStore();e&&(e.decisionUsage={...t})}r(H,"observeRunNodeDecisionUsage");function M(t,e){const o=u.getStore();o?.owner===t&&(e.tokens&&(o.usage=p(void 0,e.tokens)),e.decisionUsage&&(o.decisionUsage=N(void 0,e.decisionUsage)))}r(M,"recordRunNodeUsage");function T(t){i(t);const e=u.getStore();return e?.owner===t?e.input:void 0}r(T,"runNodeInput");function W(t,e){const o=i(t);if(o.batchChild)throw new Error("A runNode() child cannot start a nested runNode() batch.");const s=new Set;for(const n of e){if(n===o.nodeId||o.ancestors.has(n)||s.has(n)||o.reservations.has(n))throw new Error(`runNode() target '${n}' is duplicated, active, or is the caller.`);s.add(n)}for(const n of e)o.reservations.add(n);return()=>{for(const n of e)o.reservations.delete(n)}}r(W,"reserveRunNodeTargets");function _(t){return i(t).nodeId}r(_,"currentInvocationNode");function q(t,e,o,s){const n=i(t);if(n.batchChild)throw new Error("A runNode() child cannot publish a child join.");for(const[a,c]of Object.entries(e)){if(!n.reservations.has(a))throw new Error(`Unreserved runNode() publication '${a}'.`);n.childNodes[a]=c,delete n.nodes[a]}n.childUsage=p(n.childUsage,o),n.childDecisionUsage=N(n.childDecisionUsage,s)}r(q,"joinRunNodeResults");function B(t){const e=i(t);return{...Object.keys(e.childNodes).length?{nodes:e.childNodes}:{},...e.childUsage?{tokens:e.childUsage}:{},...e.childDecisionUsage&&Object.values(e.childDecisionUsage).some(o=>o!==0)?{decisionUsage:e.childDecisionUsage}:{}}}r(B,"invocationChildUpdate");function G(t){return g.getStore()?.owner===t}r(G,"hasNodeInvocation");async function J(t,e,o,s,n={},a=!1){const c=g.getStore(),d=u.getStore();if(c?.batchChild)throw new Error("A runNode() child cannot invoke nested nodes.");if(d&&(d.owner!==t||d.nodeId!==e))throw new Error("runNode() task invoked an unexpected node.");if(n.mode!==void 0&&n.mode!=="conversation"&&n.mode!=="internal")throw new Error(`Invalid node invocation mode '${String(n.mode)}'.`);if(c&&n.mode==="conversation")throw new Error("A nested node cannot take ownership of the conversation.");const v=c?"internal":n.mode??"conversation";return g.run({owner:t,nodeId:e,state:o,nodes:{},histories:{},mode:v,...d?{priorNode:d.caller}:c?.owner===t?{priorNode:c.nodeId}:{},batchChild:d!==void 0,ancestors:c?.owner===t?new Set([...c.ancestors,c.nodeId]):new Set,reservations:new Set,childNodes:{},localStateOnly:d!==void 0||v==="internal"&&(a||c?.localStateOnly===!0)},async()=>{try{return await s()}catch(w){const f=i(t);throw(f.childUsage||f.childDecisionUsage)&&y({runNode_parent_failed:!0,node:e,...f.childUsage?{usage:f.childUsage}:{},...f.childDecisionUsage?{decisionUsage:f.childDecisionUsage}:{}}),w}})}r(J,"withNodeInvocation");function P(t){return i(t).mode}r(P,"invocationMode");function z(t){return i(t).localStateOnly}r(z,"invocationIsLocalOnly");function F(t){return i(t).batchChild}r(F,"invocationIsBatchChild");function l(t,e){const o=i(t);if(o.localStateOnly&&e!==o.nodeId)throw new Error(`Internal LLM node '${o.nodeId}' may publish only its own node state and token usage.`)}r(l,"assertInvocationWrite");function K(t){return i(t).nodeId}r(K,"invocationNodeId");function Q(t){return i(t).priorNode}r(Q,"invocationPriorNode");function V(t){const e=i(t);return b(e.context??e.state.context??{})}r(V,"invocationContext");function X(t,e){l(t);const o=i(t),s=h(e,"Context patch");o.context={...h(o.context??o.state.context??{}),...s}}r(X,"saveInvocationContext");function Y(t,e){l(t),i(t).context=h(e)}r(Y,"replaceInvocationContext");function U(t,e){const o=i(t),s=o.nodes[e];return s?{...s}:{...o.childNodes[e]??(o.state.nodes??{})[e]??{}}}r(U,"invocationNodeState");function Z(t,e,o){l(t,e);const s=U(t,e);for(const[n,a]of Object.entries(o))a===void 0?delete s[n]:s[n]=a;i(t).nodes[e]=s}r(Z,"saveInvocationNodeState");function ee(t,e,o){l(t,e),i(t).nodes[e]={...o}}r(ee,"replaceInvocationNodeState");function te(t,e,o){l(t);const s=i(t);s.histories[e]=[...s.histories[e]??[],...o]}r(te,"appendInvocationHistory");function I(t,e){const o=i(t);return S(o.state.histories?.[e]??[],o.histories[e]??[])}r(I,"invocationHistory");function oe(t){const e=i(t),o={...e.state.nodes??{}};Object.assign(o,e.childNodes);for(const n of Object.keys(e.nodes))o[n]=U(t,n);const s={...e.state.histories??{}};for(const n of Object.keys(e.histories))s[n]=I(t,n);return{...e.state,nodes:o,histories:s,context:h(e.context??e.state.context??{})}}r(oe,"invocationGraphState");function ne(t){const e=i(t);return{...e.context!==void 0?{context:h(e.context)}:{},...Object.keys(e.nodes).length>0?{nodes:e.nodes}:{},...Object.keys(e.histories).length>0?{histories:e.histories}:{}}}r(ne,"invocationUpdate");function i(t){const e=g.getStore();if(!e||e.owner!==t)throw new Error("Node state can only be accessed during an active graph-node invocation.");return e}r(i,"requireInvocation");export{te as appendInvocationHistory,l as assertInvocationWrite,_ as currentInvocationNode,G as hasNodeInvocation,B as invocationChildUpdate,V as invocationContext,oe as invocationGraphState,I as invocationHistory,F as invocationIsBatchChild,z as invocationIsLocalOnly,P as invocationMode,K as invocationNodeId,U as invocationNodeState,Q as invocationPriorNode,ne as invocationUpdate,q as joinRunNodeResults,H as observeRunNodeDecisionUsage,$ as observeRunNodeUsage,L as recordRunNodeOutcome,M as recordRunNodeUsage,Y as replaceInvocationContext,ee as replaceInvocationNodeState,W as reserveRunNodeTargets,T as runNodeInput,X as saveInvocationContext,Z as saveInvocationNodeState,J as withNodeInvocation,A as withRunNodeExecution};
@@ -1 +1 @@
1
- const My=m;(function(r,w){const T5={r:0xad,w:0xfd,R:0x125,Z:0xa6,a:0xce,L:0xe8},Mu=m,R=r();while(!![]){try{const Z=-parseInt(Mu(T5.r))/0x1*(-parseInt(Mu(0x10b))/0x2)+-parseInt(Mu(T5.w))/0x3+-parseInt(Mu(T5.R))/0x4*(parseInt(Mu(0xdc))/0x5)+-parseInt(Mu(T5.Z))/0x6*(parseInt(Mu(0xd6))/0x7)+-parseInt(Mu(0x122))/0x8+parseInt(Mu(T5.a))/0x9*(parseInt(Mu(T5.L))/0xa)+parseInt(Mu(0x99))/0xb*(parseInt(Mu(0xa8))/0xc);if(Z===w)break;else R['push'](R['shift']());}catch(a){R['push'](R['shift']());}}}(M,0x27bd1));var J=Object[My(0xc6)],c=(w,R)=>J(w,My(0xc9),{'value':R,'configurable':!0x0});import{mapChatMessagesToStoredMessages as e,mapStoredMessagesToChatMessages as A}from'@langchain/core/messages';import{BaseGraph as B}from'../base-graph.js';function M(){const TR=['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'];M=function(){return TR;};return M();}import{ConfigManager as i}from'../config-manager.js';import{GRAPH_END_NODE as l}from'../graph-state.js';import{cloneJsonObject as z}from'../graph-context.js';import{GraphLlm as s}from'../graph-llm.config.js';import{replaceNodeStates as u}from'../node-state.js';import{createSessionLogs as o}from'../session-log.js';import{emptyTokenUsage as k,normalizeTokenUsage as Y}from'../token-usage.js';import{assertGraphSchemaVersion as n}from'../stable-id.js';import{addDecisionUsage as H,emptyDecisionUsage as t,normalizeDecisionUsage as d}from'../decision/decision-types.js';const h=0x10,g=My(0xed),q=My(0xc2),Ce='SESSION_COMPLETED';class f extends Error{static{c(this,My(0xfa));}[My(0xb4)];constructor(r,w){const MQ=My;super(w),this[MQ(0xc9)]=MQ(0xfa),this[MQ(0xb4)]=r;}}class N{static{c(this,'SessionManager');}['container'];[My(0x103)];constructor(r=new V(),w=F()){const Mg=My;this['container']=r,this[Mg(0x103)]=w;}static async[My(0xf8)](r=new i()){const T8={r:0x119,w:0x9d,R:0x12c,Z:0x119,a:0xdb,L:0xa2,O:0x110,D:0x106,E:0x12a,M0:0x112,M1:0x136,M2:0xa7,M3:0xec,M4:0xd7,M5:0xd8,M6:0xdd,M7:0xe4,M8:0x119,M9:0x11a,MM:0xbd},Mo=My,M0=r[Mo(T8.r)]('SESSION_STORE','memory')[Mo(T8.w)]()['toLowerCase'](),M1=F(r['get'](Mo(T8.R)));if(M0==='memory')return new N(new V(),M1);if(M0===Mo(0xbe)){const {SqliteSessionDocumentContainer:Mj}=await import('./sqlite-session-document.container.js');return new N(new Mj(r[Mo(T8.Z)](Mo(0xb0),Mo(0xe1))),M1);}if(M0===Mo(0xa2)||M0==='mongo'){const MG=p(r,Mo(T8.a)),Ml=p(r,'MONGODB_NAME'),Mq=p(r,Mo(0x134));if(!MG||!Ml||!Mq)throw new Error('MongoDB\x20session\x20persistence\x20requires\x20MONGODB_URL,\x20MONGODB_NAME,\x20and\x20MONGODB_COLLECTION.');const [{MongoClient:Mz},{MongoDbSessionDocumentContainer:Ms}]=await Promise[Mo(0xe9)]([import(Mo(T8.L)),import('./mongodb-session-document.container.js')]),Mf=new Mz(MG);await Mf[Mo(0x115)]();const MW=Mf['db'](Ml)['collection'](Mq);return await MW['createIndex']({'id':0x1},{'unique':!0x0}),new N(new Ms(MW,Mf),M1);}if(M0!==Mo(0x10a)&&M0!==Mo(T8.O))throw new Error('Unsupported\x20SESSION_STORE\x20\x27'+M0+Mo(0x127));const M2=p(r,'COSMO_ENDPOINT','COSMOS_ENDPOINT','COSMODB_URL'),M3=p(r,Mo(T8.D),'COSMOS_KEY'),M4=p(r,Mo(T8.E)),M5=p(r,Mo(T8.M0)),M6=p(r,Mo(0xaf)),M7=p(r,Mo(T8.M1),'COSMOS_DATABASE',Mo(T8.M2))??Mo(T8.M3),M8=p(r,'COSMO_DB_SESSION_CONTAINER_ID',Mo(0xc5),Mo(T8.M4))??Mo(0x116);if(!M2||!M3&&(!M4||!M5||!M6))throw new Error(Mo(0xb3));const [{CosmosClient:M9},{ClientSecretCredential:MM}]=await Promise['all']([import(Mo(T8.M5)),import(Mo(T8.M6))]),MT=M3?new M9({'endpoint':M2,'key':M3}):new M9({'endpoint':M2,'aadCredentials':new MM(M4,M5,M6)}),{database:Mm}=await MT[Mo(T8.M7)][Mo(0x109)]({'id':M7}),Me=Number(r[Mo(T8.M8)](Mo(0xd5),Mo(0xa0))),{container:MA}=await Mm['containers'][Mo(0x109)]({'id':M8,'partitionKey':{'paths':['/id']},...Number[Mo(0x98)](Me)&&Me>0x0?{'throughput':Me}:{}}),{resource:Mv}=await MA[Mo(0xac)](),MB=Mv?.[Mo(0x13c)]?.[Mo(T8.M9)]??[];if(!MB[Mo(0xda)](Mo(0xf5)))throw new Error('Cosmos\x20container\x20\x27'+M8+'\x27\x20must\x20use\x20partition\x20key\x20/id;\x20found\x20'+(MB[Mo(0x145)](',\x20')||'none')+'.');const {CosmosSessionDocumentContainer:Mi}=await import(Mo(T8.MM));return new N(new Mi(MA,()=>MT[Mo(0x126)]()),M1);}async[My(0x128)](r){const T9={r:0x117,w:0x101},Mk=My,w=await this[Mk(T9.r)](r);return w?.[Mk(T9.w)]===h?w:void 0x0;}async[My(0x117)](r){const TM={r:0xe7},Mh=My;try{const {resource:w}=await this[Mh(TM.r)][Mh(0x13e)](r,r)[Mh(0xac)]();return w;}catch(R){if(G(R))return;throw R;}}async[My(0x108)](r,w,R){const TT={r:0xca,w:0x117,R:0x123,Z:0x103,a:0xa1,L:0x13d,O:0xcb,D:0xe7,E:0xd4,M0:0xff,M1:0xdf,M2:0xbb,M3:0xcb},MY=My,Z=B[MY(TT.r)](R[MY(0x11d)]),L=n(R[MY(0xe2)]),O=await this[MY(TT.w)](r);O&&O[MY(0x101)]===h&&T(O,Z);const D=new Date(),E={'owner':w,'expiresAt':new Date(D[MY(TT.R)]()+this[MY(TT.Z)])[MY(0xa1)]()};if(!O){const M1=this['placeholderDocument'](r,R,Z,L,E,D[MY(TT.a)]());if(await this['container'][MY(TT.L)]({'expectedRevision':null},M1)==='conflict')throw new f(g,MY(0xbb)+r+MY(TT.O));return{'kind':MY(0xff),'document':M1,'expectedRevision':M1['revision']};}if(O[MY(0x101)]!==h){const M2=this['placeholderDocument'](r,R,Z,L,E,D['toISOString']());if(await this[MY(TT.D)][MY(0x13d)]({'expectedRevision':S(O),'replaceIncompatible':!0x0},M2)===MY(TT.E))throw new f(g,MY(0xbb)+r+'\x27\x20is\x20already\x20processing\x20a\x20turn.');return{'kind':MY(TT.M0),'document':M2,'expectedRevision':M2[MY(0xb2)]};}if(K(O[MY(0xdf)])&&O[MY(TT.M1)]?.[MY(0x135)]!==w)throw new f(g,'Session\x20\x27'+r+MY(TT.O));const M0={...O,'revision':S(O)+0x1,'turn':E};if(await this['container']['compareAndSwap']({'expectedRevision':S(O),'requireFreeLease':!0x0,'allowOwner':w},M0)==='conflict')throw new f(g,MY(TT.M2)+r+MY(TT.M3));return{'kind':'leased','document':M0,'expectedRevision':S(M0)};}async[My(0x12b)](r,w){const MV=My,R=await this['getSession'](r);if(R)return this[MV(0x102)](R,w);}[My(0x102)](r,w){const Te={r:0x129,w:0x129,R:0xa5,Z:0x13a,a:0x114,L:0x11f,O:0xfc},Mn=My,R=B[Mn(0xca)](w);T(r,R);const {graph:Z}=r;if(!Z[Mn(Te.r)])return;const L=u({},Z[Mn(Te.w)]),O=ae(Z[Mn(Te.R)]);return{'currentNode':Z[Mn(0x9f)],'config':Z[Mn(Te.Z)]??{},'context':z(Z[Mn(Te.a)]===void 0x0?{}:Z['context']),'completed':r[Mn(Te.L)]===Mn(Te.O)||Z[Mn(0x9f)]===l,'nodes':L,'tokens':Y(r[Mn(0xab)]),'decisionUsage':d(r['decisionUsage']),'histories':O,'inputConsumed':!0x0,'response':''};}async[My(0xd9)](r,R,Z,L=o(),D={}){const TA={r:0xe2,w:0xa1,R:0x129,Z:0xfc,a:0x140,L:0xe0,O:0x11c,D:0x9f,E:0x114,M0:0x10f,M1:0x135,M2:0x13d,M3:0xd4,M4:0xbb,M5:0xcb},MH=My,M0=B[MH(0xca)](Z[MH(0x11d)]),M1=n(Z[MH(TA.r)]),M2=await this[MH(0x117)](r),M3=M2?.[MH(0x101)]===h?M2:void 0x0;M3&&(T(M3,M0),j(M3,M1));const M4=new Date()[MH(TA.w)](),M5=oe(u({},R[MH(TA.R)])),{tokens:M6,histories:M7}=R,M8=this[MH(0xc4)](M2,D),M9={'version':h,'id':r,'revision':M8===null?0x0:M8+0x1,'status':R[MH(TA.Z)]?'completed':'in_progress','tokens':Y(M6),'decisionUsage':d(R[MH(TA.a)]),'errors':[...M3?.[MH(0xe0)]??[],...L[MH(TA.L)]],'warnings':[...M3?.[MH(0xcd)]??[],...L[MH(0xcd)]],'decisions':[...M3?.['decisions']??[],...L[MH(TA.O)]],'graph':{'id':M0,'schemaVersion':M1,'currentNode':R[MH(TA.D)],'config':R[MH(0x13a)],'context':z(R[MH(TA.E)]===void 0x0?{}:R[MH(TA.E)]),'histories':se(M7),'model':s[MH(TA.M0)](Z[MH(0xf3)]),'nodes':M5},...D['keepTurn']&&M3?.[MH(0xdf)]?{'turn':{'owner':M3[MH(0xdf)][MH(TA.M1)],'expiresAt':new Date(Date[MH(0x130)]()+this[MH(0x103)])[MH(0xa1)]()}}:{},'createdAt':M3?.['createdAt']??M4,'modifiedAt':M4};if(await this['container'][MH(TA.M2)](this[MH(0x12e)](M2,D,M8),M9)===MH(TA.M3))throw new f(D['owner']?q:g,D[MH(0x135)]?MH(TA.M4)+r+MH(0xa3):MH(0xbb)+r+MH(TA.M5));return M9;}async['appendLogs'](r,w,R,Z={}){const Tv={r:0xe2,w:0x128,R:0x140,Z:0xe0,a:0x11c,L:0x9f,O:0x13a,D:0xa5,E:0x114,M0:0xf3,M1:0x131,M2:0x131,M3:0x141,M4:0x13d,M5:0x12e,M6:0x135,M7:0xbb,M8:0x12d},Mt=My,L=B[Mt(0xca)](R[Mt(0x11d)]),O=n(R[Mt(Tv.r)]),D=await this[Mt(Tv.w)](r);D&&(T(D,L),j(D,O));const E=new Date()['toISOString'](),M0=this[Mt(0xc4)](D,Z),M1={'version':h,'id':r,'revision':M0===null?0x0:M0+0x1,'status':w[Mt(0xe0)]['length']>0x0?Mt(0xaa):D?.['status']??'in_progress','tokens':D?.[Mt(0xab)]??k(),'decisionUsage':w[Mt(0x11c)][Mt(0xc8)]((M2,M3)=>H(M2,M3['usage']),d(D?.[Mt(Tv.R)])),'errors':[...D?.[Mt(Tv.Z)]??[],...w[Mt(0xe0)]],'warnings':[...D?.[Mt(0xcd)]??[],...w[Mt(0xcd)]],'decisions':[...D?.[Mt(Tv.a)]??[],...w[Mt(0x11c)]],'graph':{'id':L,'schemaVersion':O,...D?{'currentNode':D['graph'][Mt(Tv.L)],'config':D['graph'][Mt(Tv.O)]}:{},'histories':D?.[Mt(0x131)][Mt(Tv.D)]??{},'context':z(D?.['graph'][Mt(Tv.E)]===void 0x0?{}:D[Mt(0x131)]['context']),'model':s['modelMetadata'](R[Mt(Tv.M0)]),...D?.[Mt(Tv.M1)][Mt(0x129)]?{'nodes':D[Mt(Tv.M2)][Mt(0x129)]}:{}},'createdAt':D?.[Mt(Tv.M3)]??E,'modifiedAt':E};if(await this['container'][Mt(Tv.M4)](this[Mt(Tv.M5)](D,Z,M0),M1)==='conflict'){if(Z[Mt(Tv.M6)]){console['warn'](Mt(Tv.M7)+r+Mt(0xf0)+w[Mt(Tv.Z)]['length']+'\x20error(s)\x20and\x20'+w['warnings'][Mt(Tv.M8)]+Mt(0xe3));return;}throw new f(g,'Session\x20\x27'+r+Mt(0xcb));}return M1;}async['endFailedTurn'](r,w,R,Z,a){const TB={r:0xe0,w:0xcd,R:0x9c},Md=My;if(Z&&(Z[Md(TB.r)][Md(0x12d)]>0x0||Z[Md(TB.w)][Md(0x12d)]>0x0||Z[Md(0x11c)][Md(0x12d)]>0x0)){await this[Md(0xee)](r,Z,R,{'owner':w,...a!==void 0x0?{'expectedRevision':a}:{}});return;}await this[Md(TB.R)](r,w,a);}async[My(0x9c)](r,w,R){const Ti={r:0x135,w:0x13d},MN=My,Z=await this['getSession'](r);if(!Z||Z['turn']?.[MN(Ti.r)]!==w)return;const L=R??S(Z),{turn:O,...D}=Z,E={...D,'modifiedAt':new Date()['toISOString']()};await this[MN(0xe7)][MN(Ti.w)]({'expectedRevision':L,'requireOwner':w},E);}async[My(0x120)](r){const Tj={r:0xe7},MK=My;try{await this[MK(Tj.r)][MK(0x13e)](r,r)[MK(0x138)]();}catch(w){if(!G(w))throw w;}}async['persistMigratedSession'](r,w={}){const TG={r:0x100,w:0xc3,R:0x131,Z:0xeb,a:0x128,L:0xdf,O:0x114,D:0x141,E:0x141,M0:0xbb,M1:0xb8},MC=My;if(r['version']!==h)throw new Error(MC(TG.r)+r[MC(0x101)]+MC(TG.w)+h+'.');B[MC(0xca)](r[MC(0x131)]['id']),n(r[MC(TG.R)][MC(TG.Z)]);const R=await this[MC(TG.a)](r['id']),Z=w[MC(0x113)]??S(R||r),L=R?.[MC(0xdf)]??r[MC(TG.L)],O={...r,'graph':{...r['graph'],'context':z(r[MC(TG.R)][MC(TG.O)]===void 0x0?{}:r['graph']['context'])},'revision':Z,'createdAt':R?.[MC(TG.D)]??r[MC(TG.E)],'modifiedAt':R?.[MC(0xf6)]??r[MC(0xf6)],...L?{'turn':L}:{}};if(await this['container'][MC(0x13d)]({'expectedRevision':Z,...w[MC(0x135)]?{'requireOwner':w[MC(0x135)]}:{'requireFreeLease':!0x0}},O)===MC(0xd4))throw new f(w[MC(0x135)]?q:g,MC(TG.M0)+r['id']+MC(TG.M1));}async[My(0x13f)](){const Mr=My;await this['container'][Mr(0x13f)]?.();}[My(0xd3)](r,w,R,Z,L,O){const Tq={r:0x144},MS=My;return{'version':h,'id':r,'revision':0x0,'status':MS(Tq.r),'tokens':k(),'decisionUsage':t(),'errors':[],'warnings':[],'decisions':[],'graph':{'id':R,'schemaVersion':Z,'histories':{},'context':{},'model':s[MS(0x10f)](w[MS(0xf3)])},'turn':L,'createdAt':O,'modifiedAt':O};}['commitExpectedRevision'](r,w){const Tz={r:0x113},Mw=My;return w[Mw(Tz.r)]!==void 0x0?w[Mw(Tz.r)]:r?S(r):null;}[My(0x12e)](r,w,R){const Ts={r:0x135,w:0x101},MX=My;return w[MX(Ts.r)]?{'expectedRevision':R,'requireOwner':w['owner']}:r&&r[MX(Ts.w)]!==h?{'expectedRevision':R,'replaceIncompatible':!0x0}:{'expectedRevision':R,'requireFreeLease':!0x0};}}function p(w,...R){const MR=My;for(const Z of R){const a=w[MR(0x119)](Z);if(a)return a;}}c(p,My(0x107));function T(w,R){const TW={r:0x131,w:0xbb,R:0xfe,Z:0x13b},Mp=My;if(w[Mp(TW.r)]['id']!==R)throw new Error(Mp(TW.w)+w['id']+Mp(TW.R)+w['graph']['id']+'\x27,\x20not\x20\x27'+R+Mp(TW.Z));}c(T,My(0xf4));function j(w,R){const Tu={r:0x131,w:0xeb,R:0xfb,Z:0xb6,a:0x131,L:0xeb,O:0xea,D:0xae},MZ=My;if(w[MZ(Tu.r)][MZ(Tu.w)]!==R)throw new Error('Session\x20\x27'+w['id']+MZ(Tu.R)+w['graph']['id']+MZ(Tu.Z)+w[MZ(Tu.a)][MZ(Tu.L)]+MZ(Tu.O)+R+MZ(Tu.D));}c(j,My(0xde));function oe(w){const TQ={r:0x11e},Ty={r:0x121},MI=My;return Object[MI(0xc0)](Object[MI(0xd2)](w)[MI(TQ.r)](([R,Z])=>{const Ma=MI;if(!Z||typeof Z!=Ma(Ty.r))return[R,Z];const {toolTrace:a,...L}=Z;return[R,L];}));}c(oe,My(0x132));function ie(w){const Tg={r:0xef,w:0x12d,R:0xe5,Z:0xd1,a:0xcf,L:0xf7,O:0x111,D:0x12d,E:0xf9,M0:0x12d,M1:0xf9};return w['map'](R=>{const MP=m,Z={...R[MP(0xb1)]},a=R['type']==='ai'&&Array[MP(Tg.r)](Z[MP(0x111)])&&Z[MP(0x111)][MP(Tg.w)]>0x0?ce(Z[MP(0xe5)]):void 0x0,L=b(Z[MP(Tg.R)])&&Z[MP(0xe5)][MP(Tg.Z)]===!0x0;return delete Z[MP(0xe5)],(a||L)&&(Z['additional_kwargs']={...a?{'originalTextContentBlock':a}:{},...L?{'ezgraphInternal':!0x0}:{}}),delete Z[MP(Tg.a)],delete Z[MP(Tg.L)],R[MP(0xbc)]==='ai'&&(Array[MP(0xef)](Z[MP(Tg.O)])&&Z[MP(0x111)][MP(Tg.D)]===0x0&&delete Z[MP(Tg.O)],Array['isArray'](Z[MP(Tg.E)])&&Z[MP(0xf9)][MP(Tg.M0)]===0x0&&delete Z[MP(Tg.M1)]),{...R,'data':Z};});}c(ie,My(0x9a));function se(w){const Tk={r:0xd2,w:0x11e},MF=My;return Object[MF(0xc0)](Object[MF(Tk.r)](w)[MF(Tk.w)](([R,Z])=>[R,ie(e(Z))]));}c(se,My(0xa4));function ae(w={}){const Th={r:0xc0},MU=My;return Object[MU(Th.r)](Object[MU(0xd2)](w)[MU(0x11e)](([R,Z])=>[R,A(Z)]));}c(ae,My(0xa9));function ce(w){const TY={r:0x9e,w:0x133,R:0x9e},ML=My;if(!b(w))return;const R=w[ML(0x10d)];if(!(!b(R)||typeof R[ML(TY.r)]!=ML(0xc7)))return{...typeof R[ML(TY.w)]==ML(0xc7)?{'text':R['text']}:{},'thoughtSignature':R[ML(TY.R)],...R[ML(0xba)]===!0x0?{'thought':!0x0}:{}};}c(ce,My(0xf1));function b(w){const Mc=My;return w!==null&&typeof w==Mc(0x121)&&!Array['isArray'](w);}c(b,My(0x104));class V{static{c(this,My(0xb9));}[My(0x105)]=new Map();get[My(0x9b)](){const MO=My;return this[MO(0x105)][MO(0x9b)];}[My(0xbf)]={'upsert':c(async e=>{const TH={r:0x105},Mb=My,t=e;return this[Mb(TH.r)]['set'](t['id'],structuredClone(t)),{};},My(0x124))};async[My(0x13d)](r,w){const Tt={r:0x105},Mx=My,R=this[Mx(Tt.r)][Mx(0x119)](w['id']);return de(R,r)?(this['documents'][Mx(0x10e)](w['id'],structuredClone(w)),'ok'):'conflict';}[My(0x13e)](r,w){const TN={r:0x119,w:0xc1,R:0x11b},Td={r:0x105},ME=My;return{'read':c(async()=>{const MJ=m,R=this[MJ(Td.r)][MJ(0x119)](r);if(!R||R['id']!==w)throw Object[MJ(0xc1)](new Error('Not\x20found'),{'code':0x194});return{'resource':structuredClone(R)};},'read'),'delete':c(async()=>{const MD=m,R=this[MD(0x105)][MD(TN.r)](r);if(!R||R['id']!==w)throw Object[MD(TN.w)](new Error(MD(TN.R)),{'code':0x194});return this[MD(0x105)]['delete'](r),{};},ME(0x138))};}}function G(w){const T0=My;if(!w||typeof w!=T0(0x121))return!0x1;const R=w;return R[T0(0xb4)]===0x194||R[T0(0x12f)]===0x194;}c(G,My(0x139));function F(w=process.env.SESSION_TURN_LEASE_MS){const Tr={r:0x118},T1=My,R=Number(w??T1(Tr.r));return Number[T1(0x98)](R)&&R>0x0?R:0xea60;}function m(T,e){T=T-0x98;const A=M();let v=A[T];if(m['zZPXch']===undefined){var B=function(l){const q='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+/=';let z='',s='';for(let f=0x0,W,u,y=0x0;u=l['charAt'](y++);~u&&(W=f%0x4?W*0x40+u:u,f++%0x4)?z+=String['fromCharCode'](0xff&W>>(-0x2*f&0x6)):0x0){u=q['indexOf'](u);}for(let Q=0x0,g=z['length'];Q<g;Q++){s+='%'+('00'+z['charCodeAt'](Q)['toString'](0x10))['slice'](-0x2);}return decodeURIComponent(s);};m['quHhSI']=B,m['AkYZlF']={},m['zZPXch']=!![];}const i=A[0x0],j=T+i,G=m['AkYZlF'][j];return!G?(v=m['quHhSI'](v),m['AkYZlF'][j]=v):v=G,v;}c(F,My(0xe6));function S(w){const TS={r:0xb2},T2=My;return w?.[T2(TS.r)]??0x0;}c(S,My(0x142));function K(w,R=Date['now']()){const Tw={r:0x135,w:0xcc,R:0xb7},T3=My;if(!w?.[T3(Tw.r)]||!w[T3(0xb7)])return!0x1;const Z=Date[T3(Tw.w)](w[T3(Tw.R)]);return Number['isFinite'](Z)&&Z>R;}c(K,My(0xb5));function de(w,R,Z=Date[My(0x130)]()){const TX={r:0x113,w:0xdf,R:0xf2,Z:0xd0},T4=My;return R[T4(0x10c)]?w!==void 0x0&&w['version']!==h:R[T4(TX.r)]===null?w===void 0x0:!(!w||S(w)!==R[T4(0x113)]||R['requireOwner']&&w[T4(TX.w)]?.[T4(0x135)]!==R[T4(TX.R)]||R[T4(TX.Z)]&&K(w[T4(0xdf)],Z)&&w['turn']?.[T4(0x135)]!==R[T4(0x143)]);}c(de,My(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
+ const lC=e;(function(O,t){const h6={O:0xad,t:0xfd,d:0x125,k:0xa6,a:0xce,z:0xe8},lZ=e,d=O();while(!![]){try{const k=-parseInt(lZ(h6.O))/0x1*(-parseInt(lZ(0x10b))/0x2)+-parseInt(lZ(h6.t))/0x3+-parseInt(lZ(h6.d))/0x4*(parseInt(lZ(0xdc))/0x5)+-parseInt(lZ(h6.k))/0x6*(parseInt(lZ(0xd6))/0x7)+-parseInt(lZ(0x122))/0x8+parseInt(lZ(h6.a))/0x9*(parseInt(lZ(h6.z))/0xa)+parseInt(lZ(0x99))/0xb*(parseInt(lZ(0xa8))/0xc);if(k===t)break;else d['push'](d['shift']());}catch(a){d['push'](d['shift']());}}}(l,0x27bd1));var J=Object[lC(0xc6)],c=(O,t)=>J(O,lC(0xc9),{'value':t,'configurable':!0x0});import{mapChatMessagesToStoredMessages as r,mapStoredMessagesToChatMessages as s}from'@langchain/core/messages';import{BaseGraph as E}from'../base-graph.js';function l(){const ha=['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'];l=function(){return ha;};return l();}import{ConfigManager as D}from'../config-manager.js';import{GRAPH_END_NODE as A}from'../graph-state.js';import{cloneJsonObject as H}from'../graph-context.js';import{GraphLlm as m}from'../graph-llm.config.js';import{replaceNodeStates as w}from'../node-state.js';import{createSessionLogs as Z}from'../session-log.js';import{emptyTokenUsage as o,normalizeTokenUsage as L}from'../token-usage.js';import{assertGraphSchemaVersion as n}from'../stable-id.js';import{addDecisionUsage as R,emptyDecisionUsage as u,normalizeDecisionUsage as i}from'../decision/decision-types.js';const h=0x10,g=lC(0xed),q=lC(0xc2),Ce='SESSION_COMPLETED';class f extends Error{static{c(this,lC(0xfa));}[lC(0xb4)];constructor(O,d){const lo=lC;super(d),this[lo(0xc9)]=lo(0xfa),this[lo(0xb4)]=O;}}class N{static{c(this,'SessionManager');}['container'];[lC(0x103)];constructor(O=new V(),d=F()){const lL=lC;this['container']=O,this[lL(0x103)]=d;}static async[lC(0xf8)](l0=new D()){const h9={O:0x119,t:0x9d,d:0x12c,k:0x119,a:0xdb,z:0xa2,Y:0x110,B:0x106,M:0x12a,l0:0x112,l1:0x136,l2:0xa7,l3:0xec,l4:0xd7,l5:0xd8,l6:0xdd,l7:0xe4,l8:0x119,l9:0x11a,ll:0xbd},lq=lC,l1=l0[lq(h9.O)]('SESSION_STORE','memory')[lq(h9.t)]()['toLowerCase'](),l2=F(l0['get'](lq(h9.d)));if(l1==='memory')return new N(new V(),l2);if(l1===lq(0xbe)){const {SqliteSessionDocumentContainer:ls}=await import('./sqlite-session-document.container.js');return new N(new ls(l0[lq(h9.k)](lq(0xb0),lq(0xe1))),l2);}if(l1===lq(0xa2)||l1==='mongo'){const lE=p(l0,lq(h9.a)),lD=p(l0,'MONGODB_NAME'),lA=p(l0,lq(0x134));if(!lE||!lD||!lA)throw new Error('MongoDB\x20session\x20persistence\x20requires\x20MONGODB_URL,\x20MONGODB_NAME,\x20and\x20MONGODB_COLLECTION.');const [{MongoClient:lj},{MongoDbSessionDocumentContainer:lH}]=await Promise[lq(0xe9)]([import(lq(h9.z)),import('./mongodb-session-document.container.js')]),lm=new lj(lE);await lm[lq(0x115)]();const lw=lm['db'](lD)['collection'](lA);return await lw['createIndex']({'id':0x1},{'unique':!0x0}),new N(new lH(lw,lm),l2);}if(l1!==lq(0x10a)&&l1!==lq(h9.Y))throw new Error('Unsupported\x20SESSION_STORE\x20\x27'+l1+lq(0x127));const l3=p(l0,'COSMO_ENDPOINT','COSMOS_ENDPOINT','COSMODB_URL'),l4=p(l0,lq(h9.B),'COSMOS_KEY'),l5=p(l0,lq(h9.M)),l6=p(l0,lq(h9.l0)),l7=p(l0,lq(0xaf)),l8=p(l0,lq(h9.l1),'COSMOS_DATABASE',lq(h9.l2))??lq(h9.l3),l9=p(l0,'COSMO_DB_SESSION_CONTAINER_ID',lq(0xc5),lq(h9.l4))??lq(0x116);if(!l3||!l4&&(!l5||!l6||!l7))throw new Error(lq(0xb3));const [{CosmosClient:ll},{ClientSecretCredential:lh}]=await Promise['all']([import(lq(h9.l5)),import(lq(h9.l6))]),lc=l4?new ll({'endpoint':l3,'key':l4}):new ll({'endpoint':l3,'aadCredentials':new lh(l5,l6,l7)}),{database:le}=await lc[lq(h9.l7)][lq(0x109)]({'id':l8}),lr=Number(l0[lq(h9.l8)](lq(0xd5),lq(0xa0))),{container:lQ}=await le['containers'][lq(0x109)]({'id':l9,'partitionKey':{'paths':['/id']},...Number[lq(0x98)](lr)&&lr>0x0?{'throughput':lr}:{}}),{resource:lv}=await lQ[lq(0xac)](),lG=lv?.[lq(0x13c)]?.[lq(h9.l9)]??[];if(!lG[lq(0xda)](lq(0xf5)))throw new Error('Cosmos\x20container\x20\x27'+l9+'\x27\x20must\x20use\x20partition\x20key\x20/id;\x20found\x20'+(lG[lq(0x145)](',\x20')||'none')+'.');const {CosmosSessionDocumentContainer:lI}=await import(lq(h9.ll));return new N(new lI(lQ,()=>lc[lq(0x126)]()),l2);}async[lC(0x128)](O){const hl={O:0x117,t:0x101},lb=lC,d=await this[lb(hl.O)](O);return d?.[lb(hl.t)]===h?d:void 0x0;}async[lC(0x117)](O){const hh={O:0xe7},ln=lC;try{const {resource:d}=await this[ln(hh.O)][ln(0x13e)](O,O)[ln(0xac)]();return d;}catch(k){if(G(k))return;throw k;}}async[lC(0x108)](O,k,z){const hc={O:0xca,t:0x117,d:0x123,k:0x103,a:0xa1,z:0x13d,Y:0xcb,B:0xe7,M:0xd4,l0:0xff,l1:0xdf,l2:0xbb,l3:0xcb},lR=lC,Y=E[lR(hc.O)](z[lR(0x11d)]),B=n(z[lR(0xe2)]),M=await this[lR(hc.t)](O);M&&M[lR(0x101)]===h&&T(M,Y);const l0=new Date(),l1={'owner':k,'expiresAt':new Date(l0[lR(hc.d)]()+this[lR(hc.k)])[lR(0xa1)]()};if(!M){const l3=this['placeholderDocument'](O,z,Y,B,l1,l0[lR(hc.a)]());if(await this['container'][lR(hc.z)]({'expectedRevision':null},l3)==='conflict')throw new f(g,lR(0xbb)+O+lR(hc.Y));return{'kind':lR(0xff),'document':l3,'expectedRevision':l3['revision']};}if(M[lR(0x101)]!==h){const l4=this['placeholderDocument'](O,z,Y,B,l1,l0['toISOString']());if(await this[lR(hc.B)][lR(0x13d)]({'expectedRevision':S(M),'replaceIncompatible':!0x0},l4)===lR(hc.M))throw new f(g,lR(0xbb)+O+'\x27\x20is\x20already\x20processing\x20a\x20turn.');return{'kind':lR(hc.l0),'document':l4,'expectedRevision':l4[lR(0xb2)]};}if(K(M[lR(0xdf)])&&M[lR(hc.l1)]?.[lR(0x135)]!==k)throw new f(g,'Session\x20\x27'+O+lR(hc.Y));const l2={...M,'revision':S(M)+0x1,'turn':l1};if(await this['container']['compareAndSwap']({'expectedRevision':S(M),'requireFreeLease':!0x0,'allowOwner':k},l2)==='conflict')throw new f(g,lR(hc.l2)+O+lR(hc.l3));return{'kind':'leased','document':l2,'expectedRevision':S(l2)};}async[lC(0x12b)](O,d){const lf=lC,k=await this['getSession'](O);if(k)return this[lf(0x102)](k,d);}[lC(0x102)](O,d){const hr={O:0x129,t:0x129,d:0xa5,k:0x13a,a:0x114,z:0x11f,Y:0xfc},lu=lC,k=E[lu(0xca)](d);T(O,k);const {graph:z}=O;if(!z[lu(hr.O)])return;const Y=w({},z[lu(hr.t)]),B=ae(z[lu(hr.d)]);return{'currentNode':z[lu(0x9f)],'config':z[lu(hr.k)]??{},'context':H(z[lu(hr.a)]===void 0x0?{}:z['context']),'completed':O[lu(hr.z)]===lu(hr.Y)||z[lu(0x9f)]===A,'nodes':Y,'tokens':L(O[lu(0xab)]),'decisionUsage':i(O['decisionUsage']),'histories':B,'inputConsumed':!0x0,'response':''};}async[lC(0xd9)](k,z,Y,B=Z(),M={}){const hQ={O:0xe2,t:0xa1,d:0x129,k:0xfc,a:0x140,z:0xe0,Y:0x11c,B:0x9f,M:0x114,l0:0x10f,l1:0x135,l2:0x13d,l3:0xd4,l4:0xbb,l5:0xcb},lJ=lC,l0=E[lJ(0xca)](Y[lJ(0x11d)]),l1=n(Y[lJ(hQ.O)]),l2=await this[lJ(0x117)](k),l3=l2?.[lJ(0x101)]===h?l2:void 0x0;l3&&(T(l3,l0),j(l3,l1));const l4=new Date()[lJ(hQ.t)](),l5=oe(w({},z[lJ(hQ.d)])),{tokens:l6,histories:l7}=z,l8=this[lJ(0xc4)](l2,M),l9={'version':h,'id':k,'revision':l8===null?0x0:l8+0x1,'status':z[lJ(hQ.k)]?'completed':'in_progress','tokens':L(l6),'decisionUsage':i(z[lJ(hQ.a)]),'errors':[...l3?.[lJ(0xe0)]??[],...B[lJ(hQ.z)]],'warnings':[...l3?.[lJ(0xcd)]??[],...B[lJ(0xcd)]],'decisions':[...l3?.['decisions']??[],...B[lJ(hQ.Y)]],'graph':{'id':l0,'schemaVersion':l1,'currentNode':z[lJ(hQ.B)],'config':z[lJ(0x13a)],'context':H(z[lJ(hQ.M)]===void 0x0?{}:z[lJ(hQ.M)]),'histories':se(l7),'model':m[lJ(hQ.l0)](Y[lJ(0xf3)]),'nodes':l5},...M['keepTurn']&&l3?.[lJ(0xdf)]?{'turn':{'owner':l3[lJ(0xdf)][lJ(hQ.l1)],'expiresAt':new Date(Date[lJ(0x130)]()+this[lJ(0x103)])[lJ(0xa1)]()}}:{},'createdAt':l3?.['createdAt']??l4,'modifiedAt':l4};if(await this['container'][lJ(hQ.l2)](this[lJ(0x12e)](l2,M,l8),l9)===lJ(hQ.l3))throw new f(M['owner']?q:g,M[lJ(0x135)]?lJ(hQ.l4)+k+lJ(0xa3):lJ(0xbb)+k+lJ(hQ.l5));return l9;}async['appendLogs'](O,k,z,Y={}){const hv={O:0xe2,t:0x128,d:0x140,k:0xe0,a:0x11c,z:0x9f,Y:0x13a,B:0xa5,M:0x114,l0:0xf3,l1:0x131,l2:0x131,l3:0x141,l4:0x13d,l5:0x12e,l6:0x135,l7:0xbb,l8:0x12d},lg=lC,B=E[lg(0xca)](z[lg(0x11d)]),M=n(z[lg(hv.O)]),l0=await this[lg(hv.t)](O);l0&&(T(l0,B),j(l0,M));const l1=new Date()['toISOString'](),l2=this[lg(0xc4)](l0,Y),l3={'version':h,'id':O,'revision':l2===null?0x0:l2+0x1,'status':k[lg(0xe0)]['length']>0x0?lg(0xaa):l0?.['status']??'in_progress','tokens':l0?.[lg(0xab)]??o(),'decisionUsage':k[lg(0x11c)][lg(0xc8)]((l4,l5)=>R(l4,l5['usage']),i(l0?.[lg(hv.d)])),'errors':[...l0?.[lg(hv.k)]??[],...k[lg(0xe0)]],'warnings':[...l0?.[lg(0xcd)]??[],...k[lg(0xcd)]],'decisions':[...l0?.[lg(hv.a)]??[],...k[lg(0x11c)]],'graph':{'id':B,'schemaVersion':M,...l0?{'currentNode':l0['graph'][lg(hv.z)],'config':l0['graph'][lg(hv.Y)]}:{},'histories':l0?.[lg(0x131)][lg(hv.B)]??{},'context':H(l0?.['graph'][lg(hv.M)]===void 0x0?{}:l0[lg(0x131)]['context']),'model':m['modelMetadata'](z[lg(hv.l0)]),...l0?.[lg(hv.l1)][lg(0x129)]?{'nodes':l0[lg(hv.l2)][lg(0x129)]}:{}},'createdAt':l0?.[lg(hv.l3)]??l1,'modifiedAt':l1};if(await this['container'][lg(hv.l4)](this[lg(hv.l5)](l0,Y,l2),l3)==='conflict'){if(Y[lg(hv.l6)]){console['warn'](lg(hv.l7)+O+lg(0xf0)+k[lg(hv.k)]['length']+'\x20error(s)\x20and\x20'+k['warnings'][lg(hv.l8)]+lg(0xe3));return;}throw new f(g,'Session\x20\x27'+O+lg(0xcb));}return l3;}async['endFailedTurn'](O,d,k,a,z){const hG={O:0xe0,t:0xcd,d:0x9c},lN=lC;if(a&&(a[lN(hG.O)][lN(0x12d)]>0x0||a[lN(hG.t)][lN(0x12d)]>0x0||a[lN(0x11c)][lN(0x12d)]>0x0)){await this[lN(0xee)](O,a,k,{'owner':d,...z!==void 0x0?{'expectedRevision':z}:{}});return;}await this[lN(hG.d)](O,d,z);}async[lC(0x9c)](O,d,k){const hI={O:0x135,t:0x13d},lx=lC,z=await this['getSession'](O);if(!z||z['turn']?.[lx(hI.O)]!==d)return;const Y=k??S(z),{turn:B,...M}=z,l0={...M,'modifiedAt':new Date()['toISOString']()};await this[lx(0xe7)][lx(hI.t)]({'expectedRevision':Y,'requireOwner':d},l0);}async[lC(0x120)](O){const hs={O:0xe7},li=lC;try{await this[li(hs.O)][li(0x13e)](O,O)[li(0x138)]();}catch(d){if(!G(d))throw d;}}async['persistMigratedSession'](O,d={}){const hE={O:0x100,t:0xc3,d:0x131,k:0xeb,a:0x128,z:0xdf,Y:0x114,B:0x141,M:0x141,l0:0xbb,l1:0xb8},lO=lC;if(O['version']!==h)throw new Error(lO(hE.O)+O[lO(0x101)]+lO(hE.t)+h+'.');E[lO(0xca)](O[lO(0x131)]['id']),n(O[lO(hE.d)][lO(hE.k)]);const k=await this[lO(hE.a)](O['id']),z=d[lO(0x113)]??S(k||O),Y=k?.[lO(0xdf)]??O[lO(hE.z)],B={...O,'graph':{...O['graph'],'context':H(O[lO(hE.d)][lO(hE.Y)]===void 0x0?{}:O['graph']['context'])},'revision':z,'createdAt':k?.[lO(hE.B)]??O[lO(hE.M)],'modifiedAt':k?.[lO(0xf6)]??O[lO(0xf6)],...Y?{'turn':Y}:{}};if(await this['container'][lO(0x13d)]({'expectedRevision':z,...d[lO(0x135)]?{'requireOwner':d[lO(0x135)]}:{'requireFreeLease':!0x0}},B)===lO(0xd4))throw new f(d[lO(0x135)]?q:g,lO(hE.l0)+O['id']+lO(hE.l1));}async[lC(0x13f)](){const lV=lC;await this['container'][lV(0x13f)]?.();}[lC(0xd3)](O,d,k,z,Y,B){const hA={O:0x144},lt=lC;return{'version':h,'id':O,'revision':0x0,'status':lt(hA.O),'tokens':o(),'decisionUsage':u(),'errors':[],'warnings':[],'decisions':[],'graph':{'id':k,'schemaVersion':z,'histories':{},'context':{},'model':m[lt(0x10f)](d[lt(0xf3)])},'turn':Y,'createdAt':B,'modifiedAt':B};}['commitExpectedRevision'](O,d){const hj={O:0x113},ld=lC;return d[ld(hj.O)]!==void 0x0?d[ld(hj.O)]:O?S(O):null;}[lC(0x12e)](O,d,k){const hH={O:0x135,t:0x101},lk=lC;return d[lk(hH.O)]?{'expectedRevision':k,'requireOwner':d['owner']}:O&&O[lk(hH.t)]!==h?{'expectedRevision':k,'replaceIncompatible':!0x0}:{'expectedRevision':k,'requireFreeLease':!0x0};}}function p(O,...d){const la=lC;for(const k of d){const a=O[la(0x119)](k);if(a)return a;}}c(p,lC(0x107));function T(O,t){const hw={O:0x131,t:0xbb,d:0xfe,k:0x13b},lp=lC;if(O[lp(hw.O)]['id']!==t)throw new Error(lp(hw.t)+O['id']+lp(hw.d)+O['graph']['id']+'\x27,\x20not\x20\x27'+t+lp(hw.k));}c(T,lC(0xf4));function j(O,t){const hZ={O:0x131,t:0xeb,d:0xfb,k:0xb6,a:0x131,z:0xeb,Y:0xea,B:0xae},lW=lC;if(O[lW(hZ.O)][lW(hZ.t)]!==t)throw new Error('Session\x20\x27'+O['id']+lW(hZ.d)+O['graph']['id']+lW(hZ.k)+O[lW(hZ.a)][lW(hZ.z)]+lW(hZ.Y)+t+lW(hZ.B));}c(j,lC(0xde));function oe(O){const ho={O:0x11e},hC={O:0x121},lz=lC;return Object[lz(0xc0)](Object[lz(0xd2)](O)[lz(ho.O)](([d,k])=>{const lP=lz;if(!k||typeof k!=lP(hC.O))return[d,k];const {toolTrace:a,...z}=k;return[d,z];}));}c(oe,lC(0x132));function ie(O){const hL={O:0xef,t:0x12d,d:0xe5,k:0xd1,a:0xcf,z:0xf7,Y:0x111,B:0x12d,M:0xf9,l0:0x12d,l1:0xf9};return O['map'](d=>{const lY=e,k={...d[lY(0xb1)]},a=d['type']==='ai'&&Array[lY(hL.O)](k[lY(0x111)])&&k[lY(0x111)][lY(hL.t)]>0x0?ce(k[lY(0xe5)]):void 0x0,z=b(k[lY(hL.d)])&&k[lY(0xe5)][lY(hL.k)]===!0x0;return delete k[lY(0xe5)],(a||z)&&(k['additional_kwargs']={...a?{'originalTextContentBlock':a}:{},...z?{'ezgraphInternal':!0x0}:{}}),delete k[lY(hL.a)],delete k[lY(hL.z)],d[lY(0xbc)]==='ai'&&(Array[lY(0xef)](k[lY(hL.Y)])&&k[lY(0x111)][lY(hL.B)]===0x0&&delete k[lY(hL.Y)],Array['isArray'](k[lY(hL.M)])&&k[lY(0xf9)][lY(hL.l0)]===0x0&&delete k[lY(hL.l1)]),{...d,'data':k};});}c(ie,lC(0x9a));function se(O){const hb={O:0xd2,t:0x11e},lB=lC;return Object[lB(0xc0)](Object[lB(hb.O)](O)[lB(hb.t)](([d,k])=>[d,ie(r(k))]));}c(se,lC(0xa4));function ae(O={}){const hn={O:0xc0},ly=lC;return Object[ly(hn.O)](Object[ly(0xd2)](O)[ly(0x11e)](([d,k])=>[d,s(k)]));}c(ae,lC(0xa9));function ce(O){const hR={O:0x9e,t:0x133,d:0x9e},lU=lC;if(!b(O))return;const t=O[lU(0x10d)];if(!(!b(t)||typeof t[lU(hR.O)]!=lU(0xc7)))return{...typeof t[lU(hR.t)]==lU(0xc7)?{'text':t['text']}:{},'thoughtSignature':t[lU(hR.d)],...t[lU(0xba)]===!0x0?{'thought':!0x0}:{}};}c(ce,lC(0xf1));function b(O){const lX=lC;return O!==null&&typeof O==lX(0x121)&&!Array['isArray'](O);}c(b,lC(0x104));class V{static{c(this,lC(0xb9));}[lC(0x105)]=new Map();get[lC(0x9b)](){const lM=lC;return this[lM(0x105)][lM(0x9b)];}[lC(0xbf)]={'upsert':c(async e=>{const hJ={O:0x105},lS=lC,t=e;return this[lS(hJ.O)]['set'](t['id'],structuredClone(t)),{};},lC(0x124))};async[lC(0x13d)](O,d){const hg={O:0x105},lK=lC,k=this[lK(hg.O)][lK(0x119)](d['id']);return de(k,O)?(this['documents'][lK(0x10e)](d['id'],structuredClone(d)),'ok'):'conflict';}[lC(0x13e)](O,d){const hx={O:0x119,t:0xc1,d:0x11b},hN={O:0x105},h0=lC;return{'read':c(async()=>{const lT=e,k=this[lT(hN.O)][lT(0x119)](O);if(!k||k['id']!==d)throw Object[lT(0xc1)](new Error('Not\x20found'),{'code':0x194});return{'resource':structuredClone(k)};},'read'),'delete':c(async()=>{const lF=e,k=this[lF(0x105)][lF(hx.O)](O);if(!k||k['id']!==d)throw Object[lF(hx.t)](new Error(lF(hx.d)),{'code':0x194});return this[lF(0x105)]['delete'](O),{};},h0(0x138))};}}function G(O){const h1=lC;if(!O||typeof O!=h1(0x121))return!0x1;const t=O;return t[h1(0xb4)]===0x194||t[h1(0x12f)]===0x194;}c(G,lC(0x139));function F(O=process.env.SESSION_TURN_LEASE_MS){const hV={O:0x118},h2=lC,t=Number(O??h2(hV.O));return Number[h2(0x98)](t)&&t>0x0?t:0xea60;}function e(h,c){h=h-0x98;const r=l();let Q=r[h];if(e['zZPXch']===undefined){var v=function(E){const D='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+/=';let A='',j='';for(let H=0x0,m,w,Z=0x0;w=E['charAt'](Z++);~w&&(m=H%0x4?m*0x40+w:w,H++%0x4)?A+=String['fromCharCode'](0xff&m>>(-0x2*H&0x6)):0x0){w=D['indexOf'](w);}for(let C=0x0,o=A['length'];C<o;C++){j+='%'+('00'+A['charCodeAt'](C)['toString'](0x10))['slice'](-0x2);}return decodeURIComponent(j);};e['quHhSI']=v,e['AkYZlF']={},e['zZPXch']=!![];}const G=r[0x0],I=h+G,s=e['AkYZlF'][I];return!s?(Q=e['quHhSI'](Q),e['AkYZlF'][I]=Q):Q=s,Q;}c(F,lC(0xe6));function S(O){const ht={O:0xb2},h3=lC;return O?.[h3(ht.O)]??0x0;}c(S,lC(0x142));function K(O,d=Date['now']()){const hd={O:0x135,t:0xcc,d:0xb7},h4=lC;if(!O?.[h4(hd.O)]||!O[h4(0xb7)])return!0x1;const k=Date[h4(hd.t)](O[h4(hd.d)]);return Number['isFinite'](k)&&k>d;}c(K,lC(0xb5));function de(O,d,k=Date[lC(0x130)]()){const hk={O:0x113,t:0xdf,d:0xf2,k:0xd0},h5=lC;return d[h5(0x10c)]?O!==void 0x0&&O['version']!==h:d[h5(hk.O)]===null?O===void 0x0:!(!O||S(O)!==d[h5(0x113)]||d['requireOwner']&&O[h5(hk.t)]?.[h5(0x135)]!==d[h5(hk.d)]||d[h5(hk.k)]&&K(O[h5(0xdf)],k)&&O['turn']?.[h5(0x135)]!==d[h5(0x143)]);}c(de,lC(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};
@@ -0,0 +1 @@
1
+ var $=Object.defineProperty;var a=(n,e)=>$(n,"name",{value:e,configurable:!0});import{mapChatMessagesToStoredMessages as D,mapStoredMessagesToChatMessages as F}from"@langchain/core/messages";import{getConfig as J,getCurrentTaskInput as M,isCommand as B,isGraphBubbleUp as G,task as P}from"@langchain/langgraph";import{cloneJsonObject as f}from"./graph-context.js";import{addTokenUsage as x,emptyTokenUsage as I}from"./token-usage.js";import{addDecisionUsage as A,emptyDecisionUsage as y}from"./decision/decision-types.js";import{currentInvocationNode as V,joinRunNodeResults as R,reserveRunNodeTargets as W,withRunNodeExecution as H}from"./node-invocation.js";import{currentTurnContext as K,withTurnContext as Q}from"./turn-context.js";import{currentSessionLogs as X,SessionLogWarning as Y,withSessionLogs as Z}from"./session-log.js";import{stableClassId as q}from"./stable-id.js";const me=Symbol("RUN_NODE_OUTPUT");class ee extends Error{static{a(this,"RunNodeBatchError")}results;usage;decisionUsage;constructor(e){super(`runNode() failed: ${e.filter(t=>t.status==="rejected").map(t=>`${t.nodeId}: ${t.error.message}`).join("; ")}`),this.name="RunNodeBatchError",this.results=b(e),this.usage=Object.freeze(e.reduce((t,r)=>x(t,r.usage),I())),this.decisionUsage=Object.freeze(e.reduce((t,r)=>A(t,r.decisionUsage),y()))}}async function he(n,e){if(!e.length)throw new Error("runNode() requires at least one target.");const t=V(n.owner);try{M()}catch{throw new Error("runNode() requires an active LangGraph node or task; standalone invoke() is unsupported.")}const r=e.map(s=>{const i=typeof s=="object"&&s!==null&&"node"in s,u=i?s.node:s;if(!u||typeof u.id!="function")throw new Error("runNode() requires registered GraphNode classes.");const j=n.resolve(u),E=q(u,"graph node"),N=i&&s.input!==void 0?f({input:s.input},"runNode() input").input:void 0;return{node:j,nodeId:E,input:N}}),p=W(n.owner,r.map(s=>s.nodeId));try{const s=oe(n.graphState()),i=ne();i?.signal?.throwIfAborted();const u=X(),j=r.map(o=>({version:1,nodeId:o.nodeId,caller:t,state:f(s,"runNode() snapshot"),...o.input===void 0?{}:{input:o.input}})),E=r.map((o,d)=>P({name:`runNode:${o.nodeId}`,retry:{maxAttempts:1}},async h=>{const l={owner:n.owner,nodeId:h.nodeId,caller:h.caller,...h.input===void 0?{}:{input:b(h.input)},outcome:{kind:"state"},usage:I(),decisionUsage:y()},S=a(()=>H(l,async()=>{try{i?.signal?.throwIfAborted();const c=te(h.state),w=await o.node.invoke(c,{mode:"internal"});if(i?.signal?.throwIfAborted(),B(w))throw new Error(`runNode() child '${o.nodeId}' cannot route.`);const C=w.nodes?.[o.nodeId]??c.nodes[o.nodeId]??{},_=Object.fromEntries(Object.entries(C).filter(([,L])=>L!==void 0)),z={version:1,status:"fulfilled",nodeId:o.nodeId,state:_,outcome:l.outcome,usage:l.usage,decisionUsage:l.decisionUsage};return f(z,"runNode() task result")}catch(c){if(i?.signal?.throwIfAborted(),G(c)||c instanceof Error&&c.name==="AbortError")throw c;const w=c instanceof Error?c:new Error(String(c));return{version:1,status:"rejected",nodeId:o.nodeId,error:{name:w.name,message:w.message},usage:l.usage,decisionUsage:l.decisionUsage}}}),"invoke"),T=a(()=>u?Z(u,S):S(),"withLogs");return i?Q(i,T):T()})(j[d])),N=await Promise.allSettled(E);i?.signal?.throwIfAborted();const U=N.find(o=>o.status==="rejected");if(U)throw U.reason;const m=N.map((o,d)=>{const g=o.value;if(g.version!==1||g.nodeId!==r[d].nodeId)throw new Error("Incompatible runNode() task result.");return re(g)}),k=m.reduce((o,d)=>x(o,d.usage),I()),O=m.reduce((o,d)=>A(o,d.decisionUsage),y());if(m.some(o=>o.status==="rejected"))throw R(n.owner,{},k,O),Y({runNode_failed:!0,caller:t,usage:k,decisionUsage:O}),new ee(m.map(({version:o,...d})=>d));const v=m;return R(n.owner,Object.fromEntries(v.map(o=>[o.nodeId,f(o.state)])),k,O),b(v.map(({version:o,status:d,...g})=>g))}finally{p()}}a(he,"runNodeTasks");function ne(){const n=K(),e=J()?.signal,t=n?.signal&&e&&n.signal!==e?AbortSignal.any([n.signal,e]):n?.signal??e;return n||t?{session:n?.session??"runNode",...t?{signal:t}:{}}:void 0}a(ne,"taskTurnContext");function oe(n){const e=Object.fromEntries(Object.entries(n.histories??{}).map(([t,r])=>[t,JSON.parse(JSON.stringify(D(r),(p,s)=>{if(["function","symbol","bigint"].includes(typeof s)||typeof s=="number"&&!Number.isFinite(s))throw new TypeError("runNode() message snapshot contains a non-JSON value.");return s}))]));return f(Object.fromEntries(Object.entries({...n,histories:e}).filter(([,t])=>t!==void 0)),"runNode() graph snapshot")}a(oe,"serializeState");function te(n){const e=f(n,"runNode() graph snapshot"),t=Object.fromEntries(Object.entries(e.histories).map(([r,p])=>[r,F(p)]));return b({...e,histories:t})}a(te,"deserializeState");function b(n){if(n&&typeof n=="object"&&!Object.isFrozen(n)){for(const e of Object.values(n))b(e);Object.freeze(n)}return n}a(b,"freezeRunNodeValue");function re(n){const e=f(n,"runNode() restored task result"),t=a((r,p)=>p.every(s=>{const i=r[s];return typeof i=="number"&&Number.isFinite(i)&&i>=0}),"validUsage");if(!e.usage||!e.decisionUsage||!t(e.usage,Object.keys(I()))||!t(e.decisionUsage,Object.keys(y())))throw new Error("Invalid runNode() task usage.");if(e.status==="rejected"){if(!e.error||typeof e.error.name!="string"||typeof e.error.message!="string")throw new Error("Invalid runNode() task failure.")}else if(e.status==="fulfilled"){const r=e.outcome;if(!e.state||typeof e.state!="object"||Array.isArray(e.state)||!r||!(r.kind==="state"||r.kind==="taskResult"&&"value"in r||r.kind==="reply"&&typeof r.response=="string"))throw new Error("Invalid runNode() task success.")}else throw new Error("Invalid runNode() task status.");return e}a(re,"validateEnvelope");export{me as RUN_NODE_OUTPUT,ee as RunNodeBatchError,b as freezeRunNodeValue,he as runNodeTasks};
@@ -1 +1 @@
1
- var t=Object.defineProperty;var e=(n,r)=>t(n,"name",{value:r,configurable:!0});import{AsyncLocalStorage as c}from"node:async_hooks";const s=new c;function g(){return{errors:[],warnings:[],decisions:[]}}e(g,"createSessionLogs");function S(n){return{errors:n.errors.splice(0),warnings:n.warnings.splice(0),decisions:n.decisions.splice(0)}}e(S,"drainSessionLogs");function f(n,r){n.errors.unshift(...r.errors),n.warnings.unshift(...r.warnings),n.decisions.unshift(...r.decisions)}e(f,"restoreSessionLogs");function p(n,r){return s.run(n,r)}e(p,"withSessionLogs");function d(n,r=s.getStore()){i("errors",n,r)}e(d,"SessionLogError");function w(n,r=s.getStore()){i("warnings",n,r)}e(w,"SessionLogWarning");function L(n,r=s.getStore()){if(!r)return;const o={...n,createdAt:new Date().toISOString()};return r.decisions.push(o),o}e(L,"SessionLogDecision");function i(n,r,o){o&&o[n].push({...r,createdAt:new Date().toISOString()})}e(i,"appendLog");export{L as SessionLogDecision,d as SessionLogError,w as SessionLogWarning,g as createSessionLogs,S as drainSessionLogs,f as restoreSessionLogs,p as withSessionLogs};
1
+ var i=Object.defineProperty;var e=(n,r)=>i(n,"name",{value:r,configurable:!0});import{AsyncLocalStorage as c}from"node:async_hooks";const s=new c;function S(){return s.getStore()}e(S,"currentSessionLogs");function a(){return{errors:[],warnings:[],decisions:[]}}e(a,"createSessionLogs");function f(n){return{errors:n.errors.splice(0),warnings:n.warnings.splice(0),decisions:n.decisions.splice(0)}}e(f,"drainSessionLogs");function p(n,r){n.errors.unshift(...r.errors),n.warnings.unshift(...r.warnings),n.decisions.unshift(...r.decisions)}e(p,"restoreSessionLogs");function d(n,r){return s.run(n,r)}e(d,"withSessionLogs");function L(n,r=s.getStore()){t("errors",n,r)}e(L,"SessionLogError");function w(n,r=s.getStore()){t("warnings",n,r)}e(w,"SessionLogWarning");function x(n,r=s.getStore()){if(!r)return;const o={...n,createdAt:new Date().toISOString()};return r.decisions.push(o),o}e(x,"SessionLogDecision");function t(n,r,o){o&&o[n].push({...r,createdAt:new Date().toISOString()})}e(t,"appendLog");export{x as SessionLogDecision,L as SessionLogError,w as SessionLogWarning,a as createSessionLogs,S as currentSessionLogs,f as drainSessionLogs,p as restoreSessionLogs,d as withSessionLogs};
@@ -1 +1 @@
1
- const r=T;(function(f,W){const M9={f:0x1de,W:0x1ff,y:0x215,Q:0x200,o:0x1e6,k:0x1d7,h:0x21d,Y:0x20a},C=T,y=f();while(!![]){try{const Q=parseInt(C(M9.f))/0x1*(-parseInt(C(M9.W))/0x2)+parseInt(C(M9.y))/0x3+parseInt(C(M9.Q))/0x4*(parseInt(C(0x1f2))/0x5)+parseInt(C(M9.o))/0x6+parseInt(C(M9.k))/0x7+-parseInt(C(M9.h))/0x8*(-parseInt(C(M9.Y))/0x9)+-parseInt(C(0x20c))/0xa;if(Q===W)break;else y['push'](y['shift']());}catch(o){y['push'](y['shift']());}}}(M,0x339cf));var m=Object[r(0x1ed)],p=(f,W)=>m(f,'name',{'value':W,'configurable':!0x0});import{END as e,isCommand as A,START as v,StateGraph as B}from'@langchain/langgraph';import{GRAPH_NODE_CLASS as j,GraphNode as q}from'./graph-node.js';import{GRAPH_END_NODE as z}from'./graph-state.js';import{stableClassId as s}from'./stable-id.js';class x{static{p(this,'StateGraphExt');}['createGraphNode'];[r(0x1e5)];[r(0x1fa)];[r(0x1f0)]=new Set();[r(0x21f)]=new Map();['turnNodeIds'];[r(0x1ec)]=new Set();[r(0x1e2)]=new Map();constructor(f,W,y=z){const MM={f:0x1e5},S=r;this[S(0x21c)]=W,this[S(MM.f)]=y,this['graph']=new B(f);}['addNode'](f){const MT={f:0x21c,W:0x21c,y:0x21f,Q:0x1f0},X=r;if(!w(f))throw new Error('StateGraphExt\x20nodes\x20must\x20be\x20added\x20as\x20GraphNode\x20classes:\x20graph.addNode(MyNode).');if(!this[X(MT.f)])throw new Error('This\x20graph\x20has\x20no\x20GraphNode\x20factory.');const W=this[X(MT.W)](f),y=s(f,X(0x1dd));if(W['id']!==y)throw new Error(X(0x1db)+y+'\x27\x20returned\x20\x27'+W['id']+'\x27.');return this[X(MT.y)]['set'](y,f),this[X(0x21a)](W,[...this[X(MT.Q)],y,e]);}['nodes'](...W){const Me={f:0x1fc,W:0x21b,y:0x220,Q:0x217,o:0x21a},Mm={f:0x21e},R=r;if(!this[R(0x21c)])throw new Error(R(0x201));const y=W[R(0x209)](h=>{const Z=R;if(!w(h))throw new Error(Z(Mm.f));return s(h,Z(0x1dd));}),Q=y[R(Me.f)]((h,Y)=>y[R(0x204)](h)!==Y||this['addedNodeIds']['has'](h));if(Q)throw new Error(R(Me.W)+Q+R(0x1ef));const k=[...this[R(0x1f0)],...y,e];for(const [h,Y]of W[R(Me.y)]()){const V=this[R(0x21c)](Y),n=y[h];if(V['id']!==n)throw new Error(R(0x1db)+n+'\x27\x20returned\x20\x27'+V['id']+'\x27.');this[R(0x21f)][R(Me.Q)](n,Y),this[R(Me.o)](V,k);}return this;}[r(0x1d8)](...f){const a=r;return this[a(0x1f6)](...f),this['registerTurns'](...f),this;}[r(0x211)](...f){const Mv={f:0x1ee,W:0x21b,y:0x1f0},P=r;for(const W of f){if(!w(W))throw new Error(P(0x203));const y=s(W,P(0x1dd));if(this[P(0x1fe)]?.[P(Mv.f)](y))throw new Error(P(Mv.W)+y+'\x27\x20is\x20already\x20a\x20user-turn\x20entry.');this[P(Mv.y)]['has'](y)||this[P(0x1f6)](W),this['workerNodeIds'][P(0x206)](y);}return this;}['addEdge'](f,W){const MB={f:0x1fa,W:0x1d6},F=r,y=Array[F(0x1e3)](f)?f:[f];for(const k of y)this[F(0x1eb)](k);this[F(0x1d9)](W);const Q=y[F(0x209)](c);return this[F(MB.f)][F(0x208)](Q[F(MB.W)]===0x1?Q[0x0]:Q,c(W)),this;}['branch'](f,W){const Mi={f:0x1da},U=r,y=s(f,U(0x1dd)),Q=this[U(0x1e2)]['get'](y);if(!Q)throw new Error(U(0x21b)+y+U(0x1fb));return this[U(0x20f)](f,Q[U(0x20b)][U(Mi.f)](Q),W),this;}['branchBy'](W,y){const MG={f:0x1dd,W:0x1ee,y:0x1fc,Q:0x20f,o:0x209,k:0x1f8},Mj={f:0x210,W:0x1f1,y:0x1f3},L=r,Q=s(W,L(MG.f));if(!this[L(0x1e2)][L(MG.W)](Q))throw new Error('Graph\x20node\x20\x27'+Q+L(0x1fb));if(y['cases'][L(0x1d6)]===0x0)throw new Error(L(0x218));const k=y['cases']['map'](({when:n})=>this[L(0x214)](n)),h=k[L(MG.y)]((n,H)=>k['indexOf'](n)!==H);if(h)throw new Error(L(0x1e4)+h+'\x27.');const Y=k['map']((n,H)=>L(0x216)+H),V=L(0x1f8);return this[L(MG.Q)](W,n=>{const O=L,H=n[O(Mj.f)];if(typeof H!=O(Mj.W))throw new Error(O(0x21b)+Q+O(Mj.y));const K=k[O(0x204)](H);return K===-0x1?V:Y[K];},{...Object['fromEntries'](y[L(0x202)][L(MG.o)](({routeTo:n},H)=>[Y[H],n])),[V]:y[L(MG.k)]}),this;}[r(0x1e7)](...f){const Ml={f:0x20e,W:0x1f5,y:0x1e8,Q:0x209,o:0x1fe},J=r,W=f['map'](y=>s(y,J(0x1dd)));for(const y of W)if(this[J(0x1ec)][J(0x1ee)](y))throw new Error(J(0x21b)+y+'\x27\x20is\x20already\x20registered\x20as\x20internal\x20work.');if(f[J(Ml.f)](Q=>s(Q,'graph\x20node')===this[J(0x1e5)]))throw new Error(J(Ml.W)+this[J(0x1e5)]+J(Ml.y));return this[J(0x20f)](v,Q=>Q[J(0x210)],{...Object['fromEntries'](f[J(Ml.Q)](Q=>[s(Q,'graph\x20node'),Q])),[this['endNode']]:e}),this[J(Ml.o)]=new Set(W),this;}[r(0x212)](){const Mq={f:0x1e2,W:0x1df,y:0x1fa},D=r;for(const f of this[D(Mq.f)]['values']())f[D(Mq.W)]?.(this[D(0x1f7)](f['id']));return this[D(Mq.y)]['compile']();}[r(0x1f7)](f){const Mz={f:0x1ec,W:0x1e0,y:0x219},M0=r;return{'mode':this[M0(Mz.f)][M0(0x1ee)](f)||this[M0(0x1fe)]!==void 0x0&&!this[M0(0x1fe)]['has'](f)?M0(Mz.W):M0(Mz.y)};}[r(0x20f)](f,W,y){const Ms={f:0x1fa,W:0x1f4,y:0x220},M1=r;this[M1(0x1eb)](f);for(const Q of Object['values'](y))this['assertTarget'](Q);this[M1(Ms.f)][M1(Ms.W)](c(f),W,Object[M1(0x1f9)](Object[M1(Ms.y)](y)['map'](([k,h])=>[k,c(h)])));}[r(0x21a)](f,W){const MW={f:0x1f0,W:0x21b,y:0x1ef,Q:0x217},Mf={f:0x1f7,W:0x1d9},M2=r;if(this[M2(MW.f)][M2(0x1ee)](f['id']))throw new Error(M2(MW.W)+f['id']+M2(MW.y));return this[M2(0x1fa)][M2(0x205)](f['id'],async y=>{const M3=M2,Q=await f['invoke'](y,this[M3(Mf.f)](f['id']));if(A(Q)){const k=Array[M3(0x1e3)](Q[M3(0x20d)])?Q[M3(0x20d)]:Q[M3(0x20d)]===void 0x0?[]:[Q[M3(0x20d)]];for(const h of k)typeof h=='string'&&this[M3(Mf.W)](h);}return Q;},{'ends':[...new Set(W)]}),this[M2(0x1f0)][M2(0x206)](f['id']),this[M2(0x1e2)][M2(MW.Q)](f['id'],f),this;}[r(0x1eb)](f){const Mu={f:0x1e1},M4=r;c(f)!==v&&this[M4(0x207)](f,M4(Mu.f));}['assertTarget'](f){const My={f:0x207,W:0x1fd},M5=r;c(f)!==e&&this[M5(My.f)](f,M5(My.W));}[r(0x207)](f,W){const MQ={f:0x1f0},M6=r,y=c(f);if(!this[M6(MQ.f)][M6(0x1ee)](y))throw new Error(M6(0x213)+W+'\x20\x27'+y+M6(0x1fb));}[r(0x214)](f){const Mg={f:0x1f1,W:0x1ee,y:0x1dc,Q:0x1e9,o:0x1e5,k:0x1ea,h:0x1e5},M7=r;if(typeof f!=M7(Mg.f)){if(!w(f))throw new Error('branchBy()\x20selectors\x20must\x20be\x20GraphNode\x20classes\x20or\x20the\x20configured\x20terminal\x20state.');const W=s(f,'graph\x20node');if(!this[M7(0x1f0)][M7(Mg.W)](W))throw new Error(M7(Mg.y)+W+M7(Mg.Q));return W;}if(f!==this[M7(Mg.o)]&&!this['addedNodeIds'][M7(0x1ee)](f))throw new Error(M7(Mg.y)+f+M7(Mg.k)+this[M7(Mg.h)]+'\x27.');return f;}}function T(m,e){m=m-0x1d6;const A=M();let v=A[m];if(T['eVpIkl']===undefined){var B=function(l){const q='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+/=';let z='',s='';for(let f=0x0,W,u,y=0x0;u=l['charAt'](y++);~u&&(W=f%0x4?W*0x40+u:u,f++%0x4)?z+=String['fromCharCode'](0xff&W>>(-0x2*f&0x6)):0x0){u=q['indexOf'](u);}for(let Q=0x0,g=z['length'];Q<g;Q++){s+='%'+('00'+z['charCodeAt'](Q)['toString'](0x10))['slice'](-0x2);}return decodeURIComponent(s);};T['aoVAHY']=B,T['txctJP']={},T['eVpIkl']=!![];}const i=A[0x0],j=m+i,G=T['txctJP'][j];return!G?(v=T['aoVAHY'](v),T['txctJP'][j]=v):v=G,v;}function w(f){const W=f;return typeof f=='function'&&f!==null&&W[j]===!0x0&&W['prototype']instanceof q;}function M(){const Mh=['yMLUza','r3jHCgGGBM9KzsbMywn0B3j5igzVCIaN','q3vYCMvUDc1UB2rLihnLBgvJDg9YicC','z3jHCgGGBM9Kzq','otG4ndzWwNP1r0q','DMfSAwrHDgvuB29SCW','Aw50zxjUywW','C291CMnL','BM9KzuLUC3rHBMnLCW','AxnbCNjHEq','yNjHBMnOqNKOksbOyxmGBw9Yzsb0AgfUig9UzsbJyxnLigzVCIaN','zw5KtM9Kzq','otG0odeWvM1ZqKHX','CMvNAxn0zxjuDxjUCW','jYbPCYbYzxnLCNzLzcbIEsbtDgf0zuDYyxbOrxH0lNjLz2LZDgvYvhvYBNmOks4','jYbTDxn0igjLigfKzgvKigjLzM9YzsbPDcbPCYb1C2vKlG','jYbTDxn0igjLigfUigfKzgvKieDYyxbOtM9KzsbVCIb0AguGy29UzMLNDxjLzcb0zxjTAw5HBcbZDgf0zsaN','yxnZzxj0u291CMnL','D29YA2vYtM9KzuLKCW','zgvMAw5LuhjVCgvYDhK','AgfZ','jYbPCYbHBhjLywr5ihjLz2LZDgvYzwqU','ywrKzwroB2rLswrZ','C3rYAw5N','nwnMs3bqtW','jYbJyw5UB3qGyNjHBMnOihDPDgHVDxqGysbZDhjPBMCGy3vYCMvUDe5VzguU','ywrKq29UzgL0Aw9UywXfzgDLCW','vgHLihrLCM1PBMfSihn0yxrLicC','BM9Kzxm','Aw52B2nHDgLVBK9WDgLVBNm','B3rOzxj3AxnL','zNjVBuvUDhjPzxm','z3jHCgG','jYbTDxn0igjLigfKzgvKigjLzM9YzsbPDcbPCYbJB25Uzwn0zwqU','zMLUza','DgfYz2v0','DhvYBK5Vzgvjzhm','oe14wLD4qq','ode1mZa0swPuvxf3','vgHPCYbNCMfWAcbOyxmGBM8Gr3jHCgHoB2rLigzHy3rVCNKU','y2fZzxm','u3rHDgvhCMfWAev4Dcb3B3jRzxjZig11C3qGyMuGywrKzwqGyxmGr3jHCgHoB2rLignSyxnZzxmU','Aw5KzxHpzG','ywrKtM9Kzq','ywrK','yxnZzxj0qwrKzwroB2rL','ywrKrwrNzq','BwfW','ntrRtKffrvm','CM91Dgu','nJa2mtK1mhHOz3rcsW','z290BW','C29Tzq','ywrKq29UzgL0Aw9UywXfzgDL','y3vYCMvUDe5Vzgu','D29YA2vYCW','y29TCgLSzq','q29UzgL0Aw9UywWGB3iGzgLYzwn0igvKz2uG','y3vYCMvUDe5VzgvtzwXLy3rVCK5HBwu','nJmYnJe5s1Ptu3Px','y2fZztO','C2v0','yNjHBMnOqNKOksbYzxf1AxjLCYbHDcbSzwfZDcbVBMuGy2fZzs4','y29UDMvYC2f0Aw9U','CMvNAxn0zxjoB2rL','r3jHCgGGBM9KzsaN','y3jLyxrLr3jHCgHoB2rL','ntu5ndmYzu55CMzp','u3rHDgvhCMfWAev4DcbUB2rLCYbTDxn0igjLigfKzgvKigfZieDYyxbOtM9KzsbJBgfZC2vZoIbNCMfWAc5UB2rLCYHnEu5VzguPlG','BM9KzunSyxnZzxm','zw50CMLLCW','BgvUz3rO','mtuWmJa0nMnnywT6yq','CMvNAxn0zxjuDxjUtM9Kzxm','yxnZzxj0vgfYz2v0'];M=function(){return Mh;};return M();}p(w,'isGraphNodeClass');function c(f){const Mk={f:0x1f1},M8=r;return typeof f==M8(Mk.f)?f:s(f,M8(0x1dd));}p(c,'endpointId');export{x as StateGraphExt};
1
+ const W=e;(function(Z,C){const l9={Z:0x1de,C:0x1ff,o:0x215,L:0x200,q:0x1e6,n:0x1d7,R:0x21d,f:0x20a},a=e,o=Z();while(!![]){try{const L=parseInt(a(l9.Z))/0x1*(-parseInt(a(l9.C))/0x2)+parseInt(a(l9.o))/0x3+parseInt(a(l9.L))/0x4*(parseInt(a(0x1f2))/0x5)+parseInt(a(l9.q))/0x6+parseInt(a(l9.n))/0x7+-parseInt(a(l9.R))/0x8*(-parseInt(a(l9.f))/0x9)+-parseInt(a(0x20c))/0xa;if(L===C)break;else o['push'](o['shift']());}catch(q){o['push'](o['shift']());}}}(h,0x339cf));var m=Object[W(0x1ed)],p=(Z,C)=>m(Z,'name',{'value':C,'configurable':!0x0});import{END as r,isCommand as Q,START as v,StateGraph as s}from'@langchain/langgraph';import{GRAPH_NODE_CLASS as D,GraphNode as A}from'./graph-node.js';import{GRAPH_END_NODE as j}from'./graph-state.js';import{stableClassId as H}from'./stable-id.js';class x{static{p(this,'StateGraphExt');}['createGraphNode'];[W(0x1e5)];[W(0x1fa)];[W(0x1f0)]=new Set();[W(0x21f)]=new Map();['turnNodeIds'];[W(0x1ec)]=new Set();[W(0x1e2)]=new Map();constructor(Z,C,o=j){const ll={Z:0x1e5},z=W;this[z(0x21c)]=C,this[z(ll.Z)]=o,this['graph']=new s(Z);}['addNode'](Z){const lh={Z:0x21c,C:0x21c,o:0x21f,L:0x1f0},P=W;if(!w(Z))throw new Error('StateGraphExt\x20nodes\x20must\x20be\x20added\x20as\x20GraphNode\x20classes:\x20graph.addNode(MyNode).');if(!this[P(lh.Z)])throw new Error('This\x20graph\x20has\x20no\x20GraphNode\x20factory.');const C=this[P(lh.C)](Z),o=H(Z,P(0x1dd));if(C['id']!==o)throw new Error(P(0x1db)+o+'\x27\x20returned\x20\x27'+C['id']+'\x27.');return this[P(lh.o)]['set'](o,Z),this[P(0x21a)](C,[...this[P(lh.L)],o,r]);}['nodes'](...Z){const le={Z:0x1fc,C:0x21b,o:0x220,L:0x217,q:0x21a},lc={Z:0x21e},Y=W;if(!this[Y(0x21c)])throw new Error(Y(0x201));const C=Z[Y(0x209)](n=>{const B=Y;if(!w(n))throw new Error(B(lc.Z));return H(n,B(0x1dd));}),L=C[Y(le.Z)]((n,R)=>C[Y(0x204)](n)!==R||this['addedNodeIds']['has'](n));if(L)throw new Error(Y(le.C)+L+Y(0x1ef));const q=[...this[Y(0x1f0)],...C,r];for(const [n,R]of Z[Y(le.o)]()){const J=this[Y(0x21c)](R),N=C[n];if(J['id']!==N)throw new Error(Y(0x1db)+N+'\x27\x20returned\x20\x27'+J['id']+'\x27.');this[Y(0x21f)][Y(le.L)](N,R),this[Y(le.q)](J,q);}return this;}[W(0x1d8)](...Z){const y=W;return this[y(0x1f6)](...Z),this['registerTurns'](...Z),this;}[W(0x211)](...Z){const lQ={Z:0x1ee,C:0x21b,o:0x1f0},U=W;for(const C of Z){if(!w(C))throw new Error(U(0x203));const o=H(C,U(0x1dd));if(this[U(0x1fe)]?.[U(lQ.Z)](o))throw new Error(U(lQ.C)+o+'\x27\x20is\x20already\x20a\x20user-turn\x20entry.');this[U(lQ.o)]['has'](o)||this[U(0x1f6)](C),this['workerNodeIds'][U(0x206)](o);}return this;}['addEdge'](Z,C){const lv={Z:0x1fa,C:0x1d6},X=W,L=Array[X(0x1e3)](Z)?Z:[Z];for(const n of L)this[X(0x1eb)](n);this[X(0x1d9)](C);const q=L[X(0x209)](c);return this[X(lv.Z)][X(0x208)](q[X(lv.C)]===0x1?q[0x0]:q,c(C)),this;}['branch'](Z,C){const lG={Z:0x1da},M=W,L=H(Z,M(0x1dd)),q=this[M(0x1e2)]['get'](L);if(!q)throw new Error(M(0x21b)+L+M(0x1fb));return this[M(0x20f)](Z,q[M(0x20b)][M(lG.Z)](q),C),this;}['branchBy'](Z,C){const ls={Z:0x1dd,C:0x1ee,o:0x1fc,L:0x20f,q:0x209,n:0x1f8},lI={Z:0x210,C:0x1f1,o:0x1f3},S=W,L=H(Z,S(ls.Z));if(!this[S(0x1e2)][S(ls.C)](L))throw new Error('Graph\x20node\x20\x27'+L+S(0x1fb));if(C['cases'][S(0x1d6)]===0x0)throw new Error(S(0x218));const q=C['cases']['map'](({when:N})=>this[S(0x214)](N)),n=q[S(ls.o)]((N,O)=>q['indexOf'](N)!==O);if(n)throw new Error(S(0x1e4)+n+'\x27.');const R=q['map']((N,O)=>S(0x216)+O),J=S(0x1f8);return this[S(ls.L)](Z,O=>{const K=S,V=O[K(lI.Z)];if(typeof V!=K(lI.C))throw new Error(K(0x21b)+L+K(lI.o));const k=q[K(0x204)](V);return k===-0x1?J:R[k];},{...Object['fromEntries'](C[S(0x202)][S(ls.q)](({routeTo:N},O)=>[R[O],N])),[J]:C[S(ls.n)]}),this;}[W(0x1e7)](...Z){const lE={Z:0x20e,C:0x1f5,o:0x1e8,L:0x209,q:0x1fe},T=W,C=Z['map'](o=>H(o,T(0x1dd)));for(const o of C)if(this[T(0x1ec)][T(0x1ee)](o))throw new Error(T(0x21b)+o+'\x27\x20is\x20already\x20registered\x20as\x20internal\x20work.');if(Z[T(lE.Z)](L=>H(L,'graph\x20node')===this[T(0x1e5)]))throw new Error(T(lE.C)+this[T(0x1e5)]+T(lE.o));return this[T(0x20f)](v,L=>L[T(0x210)],{...Object['fromEntries'](Z[T(lE.L)](L=>[H(L,'graph\x20node'),L])),[this['endNode']]:r}),this[T(lE.q)]=new Set(C),this;}[W(0x212)](){const lD={Z:0x1e2,C:0x1df,o:0x1fa},F=W;for(const Z of this[F(lD.Z)]['values']())Z[F(lD.C)]?.(this[F(0x1f7)](Z['id']));return this[F(lD.o)]['compile']();}[W(0x1f7)](Z){const lA={Z:0x1ec,C:0x1e0,o:0x219},l0=W;return{'mode':this[l0(lA.Z)][l0(0x1ee)](Z)||this[l0(0x1fe)]!==void 0x0&&!this[l0(0x1fe)]['has'](Z)?l0(lA.C):l0(lA.o)};}[W(0x20f)](Z,C,L){const lj={Z:0x1fa,C:0x1f4,o:0x220},l1=W;this[l1(0x1eb)](Z);for(const q of Object['values'](L))this['assertTarget'](q);this[l1(lj.Z)][l1(lj.C)](c(Z),C,Object[l1(0x1f9)](Object[l1(lj.o)](L)['map'](([n,R])=>[n,c(R)])));}[W(0x21a)](Z,C){const lm={Z:0x1f0,C:0x21b,o:0x1ef,L:0x217},lH={Z:0x1f7,C:0x1d9},l2=W;if(this[l2(lm.Z)][l2(0x1ee)](Z['id']))throw new Error(l2(lm.C)+Z['id']+l2(lm.o));return this[l2(0x1fa)][l2(0x205)](Z['id'],async L=>{const l3=l2,q=await Z['invoke'](L,this[l3(lH.Z)](Z['id']));if(Q(q)){const n=Array[l3(0x1e3)](q[l3(0x20d)])?q[l3(0x20d)]:q[l3(0x20d)]===void 0x0?[]:[q[l3(0x20d)]];for(const R of n)typeof R=='string'&&this[l3(lH.C)](R);}return q;},{'ends':[...new Set(C)]}),this[l2(0x1f0)][l2(0x206)](Z['id']),this[l2(0x1e2)][l2(lm.L)](Z['id'],Z),this;}[W(0x1eb)](Z){const lw={Z:0x1e1},l4=W;c(Z)!==v&&this[l4(0x207)](Z,l4(lw.Z));}['assertTarget'](Z){const lZ={Z:0x207,C:0x1fd},l5=W;c(Z)!==r&&this[l5(lZ.Z)](Z,l5(lZ.C));}[W(0x207)](Z,C){const lC={Z:0x1f0},l6=W,o=c(Z);if(!this[l6(lC.Z)][l6(0x1ee)](o))throw new Error(l6(0x213)+C+'\x20\x27'+o+l6(0x1fb));}[W(0x214)](Z){const lo={Z:0x1f1,C:0x1ee,o:0x1dc,L:0x1e9,q:0x1e5,n:0x1ea,R:0x1e5},l7=W;if(typeof Z!=l7(lo.Z)){if(!w(Z))throw new Error('branchBy()\x20selectors\x20must\x20be\x20GraphNode\x20classes\x20or\x20the\x20configured\x20terminal\x20state.');const C=H(Z,'graph\x20node');if(!this[l7(0x1f0)][l7(lo.C)](C))throw new Error(l7(lo.o)+C+l7(lo.L));return C;}if(Z!==this[l7(lo.q)]&&!this['addedNodeIds'][l7(0x1ee)](Z))throw new Error(l7(lo.o)+Z+l7(lo.n)+this[l7(lo.R)]+'\x27.');return Z;}}function e(l,c){l=l-0x1d6;const r=h();let Q=r[l];if(e['eVpIkl']===undefined){var v=function(E){const D='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+/=';let A='',j='';for(let H=0x0,m,w,Z=0x0;w=E['charAt'](Z++);~w&&(m=H%0x4?m*0x40+w:w,H++%0x4)?A+=String['fromCharCode'](0xff&m>>(-0x2*H&0x6)):0x0){w=D['indexOf'](w);}for(let C=0x0,o=A['length'];C<o;C++){j+='%'+('00'+A['charCodeAt'](C)['toString'](0x10))['slice'](-0x2);}return decodeURIComponent(j);};e['aoVAHY']=v,e['txctJP']={},e['eVpIkl']=!![];}const G=r[0x0],I=l+G,s=e['txctJP'][I];return!s?(Q=e['aoVAHY'](Q),e['txctJP'][I]=Q):Q=s,Q;}function w(Z){const C=Z;return typeof Z=='function'&&Z!==null&&C[D]===!0x0&&C['prototype']instanceof A;}function h(){const lb=['yMLUza','r3jHCgGGBM9KzsbMywn0B3j5igzVCIaN','q3vYCMvUDc1UB2rLihnLBgvJDg9YicC','z3jHCgGGBM9Kzq','otG4ndzWwNP1r0q','DMfSAwrHDgvuB29SCW','Aw50zxjUywW','C291CMnL','BM9KzuLUC3rHBMnLCW','AxnbCNjHEq','yNjHBMnOqNKOksbOyxmGBw9Yzsb0AgfUig9UzsbJyxnLigzVCIaN','zw5KtM9Kzq','otG0odeWvM1ZqKHX','CMvNAxn0zxjuDxjUCW','jYbPCYbYzxnLCNzLzcbIEsbtDgf0zuDYyxbOrxH0lNjLz2LZDgvYvhvYBNmOks4','jYbTDxn0igjLigfKzgvKigjLzM9YzsbPDcbPCYb1C2vKlG','jYbTDxn0igjLigfUigfKzgvKieDYyxbOtM9KzsbVCIb0AguGy29UzMLNDxjLzcb0zxjTAw5HBcbZDgf0zsaN','yxnZzxj0u291CMnL','D29YA2vYtM9KzuLKCW','zgvMAw5LuhjVCgvYDhK','AgfZ','jYbPCYbHBhjLywr5ihjLz2LZDgvYzwqU','ywrKzwroB2rLswrZ','C3rYAw5N','nwnMs3bqtW','jYbJyw5UB3qGyNjHBMnOihDPDgHVDxqGysbZDhjPBMCGy3vYCMvUDe5VzguU','ywrKq29UzgL0Aw9UywXfzgDLCW','vgHLihrLCM1PBMfSihn0yxrLicC','BM9Kzxm','Aw52B2nHDgLVBK9WDgLVBNm','B3rOzxj3AxnL','zNjVBuvUDhjPzxm','z3jHCgG','jYbTDxn0igjLigfKzgvKigjLzM9YzsbPDcbPCYbJB25Uzwn0zwqU','zMLUza','DgfYz2v0','DhvYBK5Vzgvjzhm','oe14wLD4qq','ode1mZa0swPuvxf3','vgHPCYbNCMfWAcbOyxmGBM8Gr3jHCgHoB2rLigzHy3rVCNKU','y2fZzxm','u3rHDgvhCMfWAev4Dcb3B3jRzxjZig11C3qGyMuGywrKzwqGyxmGr3jHCgHoB2rLignSyxnZzxmU','Aw5KzxHpzG','ywrKtM9Kzq','ywrK','yxnZzxj0qwrKzwroB2rL','ywrKrwrNzq','BwfW','ntrRtKffrvm','CM91Dgu','nJa2mtK1mhHOz3rcsW','z290BW','C29Tzq','ywrKq29UzgL0Aw9UywXfzgDL','y3vYCMvUDe5Vzgu','D29YA2vYCW','y29TCgLSzq','q29UzgL0Aw9UywWGB3iGzgLYzwn0igvKz2uG','y3vYCMvUDe5VzgvtzwXLy3rVCK5HBwu','nJmYnJe5s1Ptu3Px','y2fZztO','C2v0','yNjHBMnOqNKOksbYzxf1AxjLCYbHDcbSzwfZDcbVBMuGy2fZzs4','y29UDMvYC2f0Aw9U','CMvNAxn0zxjoB2rL','r3jHCgGGBM9KzsaN','y3jLyxrLr3jHCgHoB2rL','ntu5ndmYzu55CMzp','u3rHDgvhCMfWAev4DcbUB2rLCYbTDxn0igjLigfKzgvKigfZieDYyxbOtM9KzsbJBgfZC2vZoIbNCMfWAc5UB2rLCYHnEu5VzguPlG','BM9KzunSyxnZzxm','zw50CMLLCW','BgvUz3rO','mtuWmJa0nMnnywT6yq','CMvNAxn0zxjuDxjUtM9Kzxm','yxnZzxj0vgfYz2v0'];h=function(){return lb;};return h();}p(w,'isGraphNodeClass');function c(Z){const lq={Z:0x1f1},l8=W;return typeof Z==l8(lq.Z)?Z:H(Z,l8(0x1dd));}p(c,'endpointId');export{x as StateGraphExt};
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- import{GraphContextChannel as r}from"./framework/graph-context.js";import{BaseGraph as s}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 x,assertLlmTimeoutMs as L}from"./framework/llm-gateway.js";import{LlmRunner as d,DEFAULT_LLM_POLICY as g,DEFAULT_EMPTY_HISTORY_SEED as D,DEFAULT_EMPTY_RESPONSE_RECOVERY as T,DEFAULT_MAX_AGENT_ROUNDS as R,EmptyModelResponseError as _,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,fanout as F,go as Y,isToolResponse as k,stay as H,taskResult as B}from"./framework/tool-response.js";import{GraphStateSupport as V}from"./framework/graph-state-support.js";import{GRAPH_END_NODE as w,createGraphStateAnnotation as z}from"./framework/graph-state.js";import{GraphRegistry as J}from"./framework/graph-registry.js";import{GraphEngine as X}from"./framework/graph-engine.js";import{ConfigManager as K}from"./framework/config-manager.js";import{StateGraphExt as $}from"./framework/state-graph-ext.js";import{TerminateSessionNode as oe}from"./framework/terminate-session.node.js";import{SessionLogError as te,SessionLogDecision as se,SessionLogWarning as ie,createSessionLogs as ne,drainSessionLogs as ae,restoreSessionLogs as me,withSessionLogs as pe}from"./framework/session-log.js";import{ProviderFileManager as Ee}from"./framework/llm-file.js";import{SessionManager as xe,SessionTurnError as Le,SESSION_BUSY as le,SESSION_CONFLICT as de,SESSION_COMPLETED as ge,SESSION_DOCUMENT_VERSION as De,MemorySessionDocumentContainer as Te,sessionTurnLeaseMs as Re,sessionRevision as _e,isLiveSessionTurn as ce,matchesSessionWritePredicate as Ce}from"./framework/persistence/session-manager.js";import{MongoDbSessionDocumentContainer as ue}from"./framework/persistence/mongodb-session-document.container.js";import{SqliteSessionDocumentContainer as Ne}from"./framework/persistence/sqlite-session-document.container.js";import{CosmosSessionDocumentContainer as Ie}from"./framework/persistence/cosmos-session-document.container.js";import{mergeNodeStates as Pe,replaceNodeStates as he}from"./framework/node-state.js";import{LangChainLlmGateway as ye}from"./framework/langchain-llm-gateway.js";import{ModelProvider as Fe}from"./framework/model-provider.js";import{langChainModelInitialization as ke}from"./framework/langchain-provider.adapter.js";import{GRAPH_LLM_PROVIDERS as Be,GRAPH_LLM_FAMILIES as be,GRAPH_LLM_CAPABILITIES as Ve,BUILT_IN_MODEL_CATALOG as We,GraphLlm as we,ModelCatalog as ze,ModelProviderRegistry as qe}from"./framework/graph-llm.config.js";import{addTokenUsage as Qe,emptyTokenUsage as Xe,modelExecution as je,normalizeTokenUsage as Ke,tokenUsageFromMessage as Ze}from"./framework/token-usage.js";import{DecisionNode as eo}from"./framework/decision/decision-node.js";import{DecisionRunner as ro}from"./framework/decision/decision-runner.js";import{DecisionProvider as so,DecisionProviderRegistry as io}from"./framework/decision/decision-provider.js";import{TypeSafeClassifierAdapter as ao}from"./framework/decision/typesafe-provider.js";import{DecisionConfigurationError as po,DecisionTimeoutError as So,DecisionValidationError as Eo,DEFAULT_DECISION_OPTIONS as fo,addDecisionUsage as xo,decisionUsage as Lo,emptyDecisionUsage as lo,normalizeDecisionUsage as go,resolveDecisionOptions as Do}from"./framework/decision/decision-types.js";import{assertJsonCompatible as Ro,validateDecisionQuestions as _o,validateDecisionResult as co}from"./framework/decision/decision-validation.js";import{retryWithModel as Mo,LlmResponseBlockedError as uo,LlmSetupError as Ao}from"./framework/llm-lifecycle.js";export{We as BUILT_IN_MODEL_CATALOG,s as BaseGraph,K as ConfigManager,Ie as CosmosSessionDocumentContainer,fo as DEFAULT_DECISION_OPTIONS,D as DEFAULT_EMPTY_HISTORY_SEED,T as DEFAULT_EMPTY_RESPONSE_RECOVERY,g as DEFAULT_LLM_POLICY,R as DEFAULT_MAX_AGENT_ROUNDS,po as DecisionConfigurationError,eo as DecisionNode,so as DecisionProvider,io as DecisionProviderRegistry,ro as DecisionRunner,So as DecisionTimeoutError,Eo as DecisionValidationError,_ as EmptyModelResponseError,w as GRAPH_END_NODE,Ve as GRAPH_LLM_CAPABILITIES,be as GRAPH_LLM_FAMILIES,Be as GRAPH_LLM_PROVIDERS,n as GRAPH_NODE_CLASS,r as GraphContextChannel,X as GraphEngine,we as GraphLlm,a as GraphNode,m as GraphNodeRuntime,J as GraphRegistry,V as GraphStateSupport,x as LLM_GATEWAY_FACTORY,ye as LangChainLlmGateway,E as LlmNode,uo as LlmResponseBlockedError,d as LlmRunner,Ao as LlmSetupError,Te as MemorySessionDocumentContainer,ze as ModelCatalog,Fe as ModelProvider,qe as ModelProviderRegistry,ue as MongoDbSessionDocumentContainer,Ee as ProviderFileManager,le as SESSION_BUSY,ge as SESSION_COMPLETED,de as SESSION_CONFLICT,De as SESSION_DOCUMENT_VERSION,se as SessionLogDecision,te as SessionLogError,ie as SessionLogWarning,xe as SessionManager,Le as SessionTurnError,Ne as SqliteSessionDocumentContainer,$ as StateGraphExt,oe as TerminateSessionNode,p as Tool,ao as TypeSafeClassifierAdapter,xo as addDecisionUsage,Qe as addTokenUsage,c as assertEmptyResponseRetries,Ro as assertJsonCompatible,L as assertLlmTimeoutMs,C as assertMaxAgentRounds,z as createGraphStateAnnotation,ne as createSessionLogs,I as currentTurnContext,G as currentTurnSignal,Lo as decisionUsage,u as describeStopReason,U as direct,y as directTo,ae as drainSessionLogs,lo as emptyDecisionUsage,Xe as emptyTokenUsage,F as fanout,v as finish,Y as go,ce as isLiveSessionTurn,A as isRetryableStopReason,k as isToolResponse,ke as langChainModelInitialization,Ce as matchesSessionWritePredicate,Pe as mergeNodeStates,je as modelExecution,N as modelStopReason,go as normalizeDecisionUsage,Ke as normalizeTokenUsage,he as replaceNodeStates,Do as resolveDecisionOptions,me as restoreSessionLogs,Mo as retryWithModel,_e as sessionRevision,Re as sessionTurnLeaseMs,H as stay,B as taskResult,Ze as tokenUsageFromMessage,_o as validateDecisionQuestions,co as validateDecisionResult,pe as withSessionLogs,P as withTurnContext};
1
+ import{GraphContextChannel as r}from"./framework/graph-context.js";import{RunNodeBatchError as s}from"./framework/run-node.js";import{BaseGraph as i}from"./framework/base-graph.js";import{GRAPH_NODE_CLASS as m,GraphNode as p,GraphNodeRuntime as S,Tool as E}from"./framework/graph-node.js";import{LlmNode as x}from"./framework/llm-node.js";import{LLM_GATEWAY_FACTORY as d,assertLlmTimeoutMs as l}from"./framework/llm-gateway.js";import{LlmRunner as D,DEFAULT_LLM_POLICY as R,DEFAULT_EMPTY_HISTORY_SEED as T,DEFAULT_EMPTY_RESPONSE_RECOVERY as _,DEFAULT_MAX_AGENT_ROUNDS as c,EmptyModelResponseError as u,assertEmptyResponseRetries as C,assertMaxAgentRounds as M}from"./framework/llm-runner.js";import{describeStopReason as N,isRetryableStopReason as O,modelStopReason as I}from"./framework/model-stop-reason.js";import{currentTurnContext as G,currentTurnSignal as P,withTurnContext as U}from"./framework/turn-context.js";import{direct as v,directTo as F,finish as Y,fanout as k,go as B,isToolResponse as H,stay as b,taskResult as V}from"./framework/tool-response.js";import{GraphStateSupport as w}from"./framework/graph-state-support.js";import{GRAPH_END_NODE as q,createGraphStateAnnotation as J}from"./framework/graph-state.js";import{GraphRegistry as X}from"./framework/graph-registry.js";import{GraphEngine as K}from"./framework/graph-engine.js";import{ConfigManager as $}from"./framework/config-manager.js";import{StateGraphExt as oe}from"./framework/state-graph-ext.js";import{TerminateSessionNode as te}from"./framework/terminate-session.node.js";import{SessionLogError as ne,SessionLogDecision as ie,SessionLogWarning as ae,createSessionLogs as me,drainSessionLogs as pe,restoreSessionLogs as Se,withSessionLogs as Ee}from"./framework/session-log.js";import{ProviderFileManager as xe}from"./framework/llm-file.js";import{SessionManager as de,SessionTurnError as le,SESSION_BUSY as ge,SESSION_CONFLICT as De,SESSION_COMPLETED as Re,SESSION_DOCUMENT_VERSION as Te,MemorySessionDocumentContainer as _e,sessionTurnLeaseMs as ce,sessionRevision as ue,isLiveSessionTurn as Ce,matchesSessionWritePredicate as Me}from"./framework/persistence/session-manager.js";import{MongoDbSessionDocumentContainer as Ne}from"./framework/persistence/mongodb-session-document.container.js";import{SqliteSessionDocumentContainer as Ie}from"./framework/persistence/sqlite-session-document.container.js";import{CosmosSessionDocumentContainer as Ge}from"./framework/persistence/cosmos-session-document.container.js";import{mergeNodeStates as Ue,replaceNodeStates as ye}from"./framework/node-state.js";import{LangChainLlmGateway as Fe}from"./framework/langchain-llm-gateway.js";import{ModelProvider as ke}from"./framework/model-provider.js";import{langChainModelInitialization as He}from"./framework/langchain-provider.adapter.js";import{GRAPH_LLM_PROVIDERS as Ve,GRAPH_LLM_FAMILIES as We,GRAPH_LLM_CAPABILITIES as we,BUILT_IN_MODEL_CATALOG as ze,GraphLlm as qe,ModelCatalog as Je,ModelProviderRegistry as Qe}from"./framework/graph-llm.config.js";import{addTokenUsage as je,emptyTokenUsage as Ke,modelExecution as Ze,normalizeTokenUsage as $e,tokenUsageFromMessage as eo}from"./framework/token-usage.js";import{DecisionNode as ro}from"./framework/decision/decision-node.js";import{DecisionRunner as so}from"./framework/decision/decision-runner.js";import{DecisionProvider as io,DecisionProviderRegistry as ao}from"./framework/decision/decision-provider.js";import{TypeSafeClassifierAdapter as po}from"./framework/decision/typesafe-provider.js";import{DecisionConfigurationError as Eo,DecisionTimeoutError as fo,DecisionValidationError as xo,DEFAULT_DECISION_OPTIONS as Lo,addDecisionUsage as lo,decisionUsage as go,emptyDecisionUsage as Do,normalizeDecisionUsage as Ro,resolveDecisionOptions as To}from"./framework/decision/decision-types.js";import{assertJsonCompatible as co,validateDecisionQuestions as uo,validateDecisionResult as Co}from"./framework/decision/decision-validation.js";import{retryWithModel as Ao,LlmResponseBlockedError as No,LlmSetupError as Oo}from"./framework/llm-lifecycle.js";export{ze as BUILT_IN_MODEL_CATALOG,i as BaseGraph,$ as ConfigManager,Ge as CosmosSessionDocumentContainer,Lo as DEFAULT_DECISION_OPTIONS,T as DEFAULT_EMPTY_HISTORY_SEED,_ as DEFAULT_EMPTY_RESPONSE_RECOVERY,R as DEFAULT_LLM_POLICY,c as DEFAULT_MAX_AGENT_ROUNDS,Eo as DecisionConfigurationError,ro as DecisionNode,io as DecisionProvider,ao as DecisionProviderRegistry,so as DecisionRunner,fo as DecisionTimeoutError,xo as DecisionValidationError,u as EmptyModelResponseError,q as GRAPH_END_NODE,we as GRAPH_LLM_CAPABILITIES,We as GRAPH_LLM_FAMILIES,Ve as GRAPH_LLM_PROVIDERS,m as GRAPH_NODE_CLASS,r as GraphContextChannel,K as GraphEngine,qe as GraphLlm,p as GraphNode,S as GraphNodeRuntime,X as GraphRegistry,w as GraphStateSupport,d as LLM_GATEWAY_FACTORY,Fe as LangChainLlmGateway,x as LlmNode,No as LlmResponseBlockedError,D as LlmRunner,Oo as LlmSetupError,_e as MemorySessionDocumentContainer,Je as ModelCatalog,ke as ModelProvider,Qe as ModelProviderRegistry,Ne as MongoDbSessionDocumentContainer,xe as ProviderFileManager,s as RunNodeBatchError,ge as SESSION_BUSY,Re as SESSION_COMPLETED,De as SESSION_CONFLICT,Te as SESSION_DOCUMENT_VERSION,ie as SessionLogDecision,ne as SessionLogError,ae as SessionLogWarning,de as SessionManager,le as SessionTurnError,Ie as SqliteSessionDocumentContainer,oe as StateGraphExt,te as TerminateSessionNode,E as Tool,po as TypeSafeClassifierAdapter,lo as addDecisionUsage,je as addTokenUsage,C as assertEmptyResponseRetries,co as assertJsonCompatible,l as assertLlmTimeoutMs,M as assertMaxAgentRounds,J as createGraphStateAnnotation,me as createSessionLogs,G as currentTurnContext,P as currentTurnSignal,go as decisionUsage,N as describeStopReason,v as direct,F as directTo,pe as drainSessionLogs,Do as emptyDecisionUsage,Ke as emptyTokenUsage,k as fanout,Y as finish,B as go,Ce as isLiveSessionTurn,O as isRetryableStopReason,H as isToolResponse,He as langChainModelInitialization,Me as matchesSessionWritePredicate,Ue as mergeNodeStates,Ze as modelExecution,I as modelStopReason,Ro as normalizeDecisionUsage,$e as normalizeTokenUsage,ye as replaceNodeStates,To as resolveDecisionOptions,Se as restoreSessionLogs,Ao as retryWithModel,ue as sessionRevision,ce as sessionTurnLeaseMs,b as stay,V as taskResult,eo as tokenUsageFromMessage,uo as validateDecisionQuestions,Co as validateDecisionResult,Ee as withSessionLogs,U as withTurnContext};
@@ -1,7 +1,8 @@
1
1
  export { GraphContextChannel, type DeepReadonly } from "../../src/framework/graph-context.js";
2
+ export { RunNodeBatchError, type RunNodeTarget, type RunNodeArgument, type RunNodeRequest, type RunNodeResult, type RunNodeResults, type RunNodeOutcome, type RunNodeFailure, type RunNodeSettlement, } from "../../src/framework/run-node.js";
2
3
  export { BaseGraph, type GraphDefinition, type GraphNodeConstructor, type GraphSchemaMigration, type HistorySpace, } from "../../src/framework/base-graph.js";
3
4
  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, type NodeInvocationOptions, } from "../../src/framework/graph-node.js";
4
- export { LlmNode, type LlmNodeRunResult, type LlmNodeResponse, type MessageTypes, } from "../../src/framework/llm-node.js";
5
+ export { LlmNode, type LlmNodeRunResult, type LlmNodeResponse, type LlmNodeExitContext, type LlmNodeExitOutcome, type MessageTypes, } from "../../src/framework/llm-node.js";
5
6
  export { LLM_GATEWAY_FACTORY, assertLlmTimeoutMs, type LlmCallOptions, type LlmGateway, type LlmGatewayFactory, type LlmGatewayTool, type LlmGatewayToolCall, } from "../../src/framework/llm-gateway.js";
6
7
  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";
7
8
  export { describeStopReason, isRetryableStopReason, modelStopReason, type ModelStopCategory, type ModelStopReason, } from "../../src/framework/model-stop-reason.js";
@@ -14,6 +14,7 @@ import type { ModelStopReason } from "./model-stop-reason.js";
14
14
  import { GRAPH_NODE_LOCAL_STATE, type GraphNodeLocalState, type GraphNodeTarget, type GraphNodeUpdate } from "./node-outcome.js";
15
15
  import { type ToolResponse } from "./tool-response.js";
16
16
  import { type NodeInvocationOptions } from "./node-invocation.js";
17
+ import { type RunNodeArgument, type RunNodeResults, type RunNodeTarget, type RunNodeOutcome } from "./run-node.js";
17
18
  export type { NodeInvocationOptions } from "./node-invocation.js";
18
19
  import { type DecisionConversation, type DecisionErrorContext, type DecisionOptions, type DecisionProviderAdapter, type ResolvedDecisionOptions } from "./decision/decision-types.js";
19
20
  export { GRAPH_NODE_LOCAL_STATE, type GraphNodeLocalState, type GraphNodeTarget, type GraphNodeUpdate, } from "./node-outcome.js";
@@ -45,6 +46,8 @@ export declare abstract class GraphNode<State extends GraphState, LocalState ext
45
46
  readonly id: string;
46
47
  constructor(llmGateway: LlmGateway, runtime: GraphNodeRuntime<State>);
47
48
  protected get graph(): GraphNodeRuntime<State>;
49
+ protected runNode<const Arguments extends readonly [RunNodeArgument, ...RunNodeArgument[]]>(...targets: Arguments): Promise<RunNodeResults<Arguments>>;
50
+ protected getRunNodeInput<Input>(): DeepReadonly<Input> | undefined;
48
51
  abstract getPrompt(state: State): string;
49
52
  defineTool(): readonly ToolDefinition[];
50
53
  getLlmConfig(): GraphLlmConfigOverride;
@@ -56,6 +59,9 @@ export declare abstract class GraphNode<State extends GraphState, LocalState ext
56
59
  protected onInvalidJsonResponse(context: InvalidJsonResponseContext<State>): GraphNodeUpdate<State> | Promise<GraphNodeUpdate<State>>;
57
60
  protected onEmptyModelResponse(context: EmptyModelResponseContext<State>): string | Promise<string>;
58
61
  readonly invoke: (state: State, options?: NodeInvocationOptions) => Promise<GraphNodeResult<State>>;
62
+ private withChildPublication;
63
+ protected finalizeNodeResult(_result: GraphNodeResult<State>, _update: GraphNodeUpdate<State>): void | Promise<void>;
64
+ private validatePublication;
59
65
  protected managesLlmExecution(): boolean;
60
66
  protected validateNodeResult(_update: GraphNodeUpdate<State>, _isCommand: boolean): void;
61
67
  obtainTools(options?: NodeInvocationOptions): readonly ToolDefinition[];
@@ -92,6 +98,16 @@ export declare class GraphNodeRuntime<State extends GraphState> extends GraphSta
92
98
  private readonly decisionErrorHandler?;
93
99
  readonly llmLifecycle?: GraphLlmLifecycle | undefined;
94
100
  private readonly assertContextChannel?;
101
+ private runNodeResolver?;
102
+ attachRunNodeResolver(resolve: (Node: RunNodeTarget) => GraphNode<State>): void;
103
+ runNode(targets: readonly RunNodeArgument[]): Promise<readonly Readonly<{
104
+ nodeId: string;
105
+ state: Record<string, unknown>;
106
+ outcome: RunNodeOutcome;
107
+ usage: import("./token-usage.js").TokenUsage;
108
+ decisionUsage: import("./decision/decision-types.js").DecisionUsage;
109
+ }>[]>;
110
+ recordRunNodeOutcome(outcome: RunNodeOutcome): void;
95
111
  private readonly tools;
96
112
  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);
97
113
  llmCallOptions(): LlmCallOptions;
@@ -54,7 +54,7 @@ export declare class LlmSetupError extends Error {
54
54
  }
55
55
  export type LlmLifecycle = Readonly<{
56
56
  nodeId: string;
57
- onEnter?(message: MessageTypes | null | undefined): MessageTypes | null | undefined;
57
+ onEnter?(message: MessageTypes | null | undefined): MessageTypes | null | undefined | Promise<MessageTypes | null | undefined>;
58
58
  checkResponse(response: string | object): boolean;
59
59
  onLlmBlocked(context: LlmBlockedContext): Promise<LlmBlockedResponse | null>;
60
60
  shouldRetryLlmError(context: LlmAttemptErrorContext): boolean | undefined;
@@ -1,19 +1,53 @@
1
1
  import { type BaseMessage } from "@langchain/core/messages";
2
2
  import type { ToolCall } from "@langchain/core/messages/tool";
3
3
  import type { LlmRunResult } from "./llm-runner.js";
4
- import { type GraphNodeResult, type NodeInvocationOptions } from "./graph-node.js";
4
+ import { type GraphNodeResult, type GraphNodeUpdate, type NodeInvocationOptions } from "./graph-node.js";
5
5
  import { LlmNodeBase } from "./llm-node-base.js";
6
6
  import type { GraphState } from "./graph-state.js";
7
7
  import { type ToolResponse } from "./tool-response.js";
8
+ import { type TokenUsage } from "./token-usage.js";
8
9
  import type { LlmErrorResponse, LlmLifecycle } from "./llm-lifecycle.js";
9
10
  import type { MessageTypes } from "./message-types.js";
11
+ import { RUN_NODE_OUTPUT } from "./run-node.js";
10
12
  export type { MessageTypes } from "./message-types.js";
11
13
  export type LlmNodeRunResult = LlmRunResult;
12
14
  export type LlmNodeResponse = void | string | ToolResponse;
15
+ export type LlmNodeExitOutcome<Output = string> = {
16
+ readonly kind: "reply";
17
+ readonly response: string;
18
+ } | {
19
+ readonly kind: "taskResult";
20
+ readonly value: Output;
21
+ } | {
22
+ readonly kind: "go";
23
+ readonly targets: readonly [string];
24
+ } | {
25
+ readonly kind: "fanout";
26
+ readonly targets: readonly [string, string, ...string[]];
27
+ } | {
28
+ readonly kind: "directTo";
29
+ readonly targets: readonly [string];
30
+ readonly response: string;
31
+ } | {
32
+ readonly kind: "finish";
33
+ readonly response: string;
34
+ };
35
+ export type LlmNodeExitContext<State extends GraphState, Output = string> = Readonly<{
36
+ nodeId: string;
37
+ mode: "conversation" | "internal";
38
+ state: Readonly<State>;
39
+ outcome: LlmNodeExitOutcome<Output>;
40
+ usage: TokenUsage;
41
+ }>;
13
42
  export declare abstract class LlmNode<State extends GraphState, LocalState extends object = Record<string, unknown>, Output = string> extends LlmNodeBase<State, LocalState> {
14
- protected onEnter(langMessage: MessageTypes | null | undefined, _priorNode?: string): MessageTypes | null | undefined;
43
+ readonly [RUN_NODE_OUTPUT]: Output;
44
+ private readonly exitOutcomes;
45
+ protected onEnter(langMessage: MessageTypes | null | undefined, _priorNode?: string): MessageTypes | null | undefined | Promise<MessageTypes | null | undefined>;
15
46
  protected llmLifecycle(): LlmLifecycle;
16
47
  protected onResponse(_response: string | Output, _state: State): LlmNodeResponse | Promise<LlmNodeResponse>;
48
+ protected onExit(_context: LlmNodeExitContext<State, Output>): void | Promise<void>;
49
+ protected finalizeNodeResult(result: GraphNodeResult<State>, update: GraphNodeUpdate<State>): Promise<void>;
50
+ private withExitOutcome;
17
51
  protected managesLlmExecution(): boolean;
18
52
  private isInternal;
19
53
  protected includeTool(name: string, options: NodeInvocationOptions): boolean;
@@ -38,7 +38,7 @@ export declare class LlmRunner {
38
38
  constructor(llmGateway: LlmGateway);
39
39
  run(options: {
40
40
  lifecycle?: LlmLifecycle;
41
- systemPrompt: string;
41
+ systemPrompt: string | (() => string);
42
42
  history: readonly BaseMessage[];
43
43
  tools: readonly LlmGatewayTool[];
44
44
  llmConfig: GraphLlmConfig;
@@ -1,13 +1,36 @@
1
1
  import type { BaseMessage } from "@langchain/core/messages";
2
2
  import type { GraphState } from "./graph-state.js";
3
3
  import { type DeepReadonly, type JsonObject } from "./graph-context.js";
4
+ import { type TokenUsage } from "./token-usage.js";
5
+ import { type DecisionUsage } from "./decision/decision-types.js";
6
+ import type { RunNodeOutcome } from "./run-node.js";
4
7
  export type NodeInvocationOptions = Readonly<{
5
8
  mode?: "conversation" | "internal";
6
9
  }>;
10
+ export type RunNodeExecution = {
11
+ owner: object;
12
+ nodeId: string;
13
+ caller: string;
14
+ input?: unknown;
15
+ outcome: RunNodeOutcome;
16
+ usage: TokenUsage;
17
+ decisionUsage: DecisionUsage;
18
+ };
19
+ export declare function withRunNodeExecution<T>(scope: RunNodeExecution, run: () => Promise<T>): Promise<T>;
20
+ export declare function recordRunNodeOutcome(owner: object, outcome: RunNodeOutcome): void;
21
+ export declare function observeRunNodeUsage(usage: TokenUsage): void;
22
+ export declare function observeRunNodeDecisionUsage(usage: DecisionUsage): void;
23
+ export declare function recordRunNodeUsage(owner: object, update: Partial<GraphState>): void;
24
+ export declare function runNodeInput<Input>(owner: object): DeepReadonly<Input> | undefined;
25
+ export declare function reserveRunNodeTargets(owner: object, ids: readonly string[]): () => void;
26
+ export declare function currentInvocationNode(owner: object): string;
27
+ export declare function joinRunNodeResults(owner: object, nodes: Record<string, Record<string, unknown>>, usage: TokenUsage, decisionUsage: DecisionUsage): void;
28
+ export declare function invocationChildUpdate<State extends GraphState>(owner: object): Partial<State>;
7
29
  export declare function hasNodeInvocation(owner: object): boolean;
8
30
  export declare function withNodeInvocation<State extends GraphState, Result>(owner: object, nodeId: string, state: State, run: () => Promise<Result>, options?: NodeInvocationOptions, managedLlm?: boolean): Promise<Result>;
9
31
  export declare function invocationMode(owner: object): "conversation" | "internal";
10
32
  export declare function invocationIsLocalOnly(owner: object): boolean;
33
+ export declare function invocationIsBatchChild(owner: object): boolean;
11
34
  export declare function assertInvocationWrite(owner: object, nodeId?: string): void;
12
35
  export declare function invocationNodeId(owner: object): string;
13
36
  export declare function invocationPriorNode(owner: object): string | undefined;
@@ -0,0 +1,76 @@
1
+ import type { GraphNode } from "./graph-node.js";
2
+ import type { GraphNodeClass } from "./state-graph-ext.js";
3
+ import type { GraphNodeLocalState, GraphNodeTarget } from "./node-outcome.js";
4
+ import type { NodeStateValue } from "./node-state.js";
5
+ import type { GraphState } from "./graph-state.js";
6
+ import { type DeepReadonly, type JsonValue } from "./graph-context.js";
7
+ import { type TokenUsage } from "./token-usage.js";
8
+ import { type DecisionUsage } from "./decision/decision-types.js";
9
+ export declare const RUN_NODE_OUTPUT: unique symbol;
10
+ export type RunNodeTarget = GraphNodeClass & GraphNodeTarget;
11
+ export type RunNodeRequest<Node extends RunNodeTarget = RunNodeTarget> = Readonly<{
12
+ node: Node;
13
+ input?: JsonValue;
14
+ }>;
15
+ export type RunNodeArgument = RunNodeTarget | RunNodeRequest;
16
+ export type RunNodeOutcome<Output = unknown> = Readonly<{
17
+ kind: "state";
18
+ }> | Readonly<{
19
+ kind: "reply";
20
+ response: string;
21
+ }> | Readonly<{
22
+ kind: "taskResult";
23
+ value: Output;
24
+ }>;
25
+ type TargetOf<Argument extends RunNodeArgument> = Argument extends RunNodeRequest<infer Node> ? Node : Argument;
26
+ type OutcomeOf<Node extends RunNodeTarget> = Node["prototype"] extends {
27
+ readonly [RUN_NODE_OUTPUT]: infer Output;
28
+ } ? Exclude<RunNodeOutcome<Output>, {
29
+ kind: "state";
30
+ }> : Readonly<{
31
+ kind: "state";
32
+ }>;
33
+ export type RunNodeResult<Node extends RunNodeTarget = RunNodeTarget> = Readonly<{
34
+ nodeId: string;
35
+ state: DeepReadonly<NodeStateValue<GraphNodeLocalState<Node>>>;
36
+ outcome: DeepReadonly<OutcomeOf<Node>>;
37
+ usage: Readonly<TokenUsage>;
38
+ decisionUsage: Readonly<DecisionUsage>;
39
+ }>;
40
+ export type RunNodeResults<Arguments extends readonly RunNodeArgument[]> = {
41
+ readonly [Index in keyof Arguments]: RunNodeResult<Extract<TargetOf<Arguments[Index]>, RunNodeTarget>>;
42
+ };
43
+ export type RunNodeFailure = Readonly<{
44
+ nodeId: string;
45
+ status: "rejected";
46
+ error: Readonly<{
47
+ name: string;
48
+ message: string;
49
+ }>;
50
+ usage: Readonly<TokenUsage>;
51
+ decisionUsage: Readonly<DecisionUsage>;
52
+ }>;
53
+ type Success = Readonly<{
54
+ nodeId: string;
55
+ state: Record<string, unknown>;
56
+ outcome: RunNodeOutcome;
57
+ usage: TokenUsage;
58
+ decisionUsage: DecisionUsage;
59
+ }>;
60
+ export type RunNodeSettlement = RunNodeFailure | DeepReadonly<Success & {
61
+ status: "fulfilled";
62
+ }>;
63
+ export declare class RunNodeBatchError extends Error {
64
+ readonly results: readonly RunNodeSettlement[];
65
+ readonly usage: Readonly<TokenUsage>;
66
+ readonly decisionUsage: Readonly<DecisionUsage>;
67
+ constructor(results: readonly RunNodeSettlement[]);
68
+ }
69
+ export type RunNodeHost<State extends GraphState> = Readonly<{
70
+ owner: object;
71
+ graphState(): State;
72
+ resolve(Node: RunNodeTarget): GraphNode<State>;
73
+ }>;
74
+ export declare function runNodeTasks<State extends GraphState>(host: RunNodeHost<State>, requests: readonly RunNodeArgument[]): Promise<readonly Success[]>;
75
+ export declare function freezeRunNodeValue<Value>(value: Value): Value;
76
+ export {};
@@ -32,6 +32,7 @@ export type DecisionAuditInput = {
32
32
  requestId?: string;
33
33
  usage: DecisionUsage;
34
34
  };
35
+ export declare function currentSessionLogs(): SessionLogs | undefined;
35
36
  export declare function createSessionLogs(): SessionLogs;
36
37
  export declare function drainSessionLogs(logs: SessionLogs): SessionLogs;
37
38
  export declare function restoreSessionLogs(logs: SessionLogs, drained: SessionLogs): void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@picoflow/ezgraph",
3
- "version": "0.0.17",
3
+ "version": "0.0.19",
4
4
  "description": "Provider-neutral graph primitives built on LangGraph and LangChain.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",