@picoflow/ezgraph 0.0.7 → 0.0.9

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.
Files changed (54) hide show
  1. package/README.md +77 -0
  2. package/dist/framework/base-graph.js +1 -1
  3. package/dist/framework/conversation-node.js +1 -1
  4. package/dist/framework/conversation-runner.js +1 -1
  5. package/dist/framework/decision/decision-node.js +1 -0
  6. package/dist/framework/decision/decision-provider.js +1 -0
  7. package/dist/framework/decision/decision-runner.js +1 -0
  8. package/dist/framework/decision/decision-types.js +1 -0
  9. package/dist/framework/decision/decision-validation.js +1 -0
  10. package/dist/framework/decision/typesafe-provider.js +1 -0
  11. package/dist/framework/graph-engine.js +1 -1
  12. package/dist/framework/graph-node.js +1 -1
  13. package/dist/framework/graph-state.js +1 -1
  14. package/dist/framework/langchain-provider.adapter.js +1 -1
  15. package/dist/framework/persistence/session-manager.js +1 -1
  16. package/dist/framework/session-log.js +1 -1
  17. package/dist/framework/state-graph-ext.js +1 -1
  18. package/dist/framework/tool-response.js +1 -1
  19. package/dist/index.js +1 -1
  20. package/dist/testing/scripted-decisions.js +1 -0
  21. package/dist/testing/turn-harness.js +1 -1
  22. package/dist/testing.js +1 -1
  23. package/dist/types/npmlib/src/index.d.ts +9 -3
  24. package/dist/types/npmlib/src/testing.d.ts +1 -0
  25. package/dist/types/src/framework/base-graph.d.ts +23 -17
  26. package/dist/types/src/framework/conversation-node.d.ts +4 -4
  27. package/dist/types/src/framework/conversation-runner.d.ts +7 -7
  28. package/dist/types/src/framework/decision/decision-node.d.ts +17 -0
  29. package/dist/types/src/framework/decision/decision-provider.d.ts +14 -0
  30. package/dist/types/src/framework/decision/decision-runner.d.ts +18 -0
  31. package/dist/types/src/framework/decision/decision-types.d.ts +126 -0
  32. package/dist/types/src/framework/decision/decision-validation.d.ts +4 -0
  33. package/dist/types/src/framework/decision/typesafe-provider.d.ts +12 -0
  34. package/dist/types/src/framework/graph-engine.d.ts +4 -0
  35. package/dist/types/src/framework/graph-llm.config.d.ts +3 -3
  36. package/dist/types/src/framework/graph-node.d.ts +34 -22
  37. package/dist/types/src/framework/graph-registry.d.ts +8 -6
  38. package/dist/types/src/framework/graph-state-support.d.ts +1 -1
  39. package/dist/types/src/framework/graph-state.d.ts +6 -3
  40. package/dist/types/src/framework/langchain-provider.adapter.d.ts +2 -2
  41. package/dist/types/src/framework/llm-gateway.d.ts +4 -4
  42. package/dist/types/src/framework/model-stop-reason.d.ts +2 -2
  43. package/dist/types/src/framework/node-invocation.d.ts +2 -2
  44. package/dist/types/src/framework/node-outcome.d.ts +2 -2
  45. package/dist/types/src/framework/node-state.d.ts +1 -1
  46. package/dist/types/src/framework/openai-auth-provider.d.ts +1 -1
  47. package/dist/types/src/framework/persistence/session-manager.d.ts +3 -0
  48. package/dist/types/src/framework/session-log.d.ts +30 -0
  49. package/dist/types/src/framework/state-graph-ext.d.ts +3 -3
  50. package/dist/types/src/framework/token-usage.d.ts +2 -2
  51. package/dist/types/src/framework/tool-response.d.ts +7 -3
  52. package/dist/types/src/testing/scripted-decisions.d.ts +24 -0
  53. package/dist/types/src/testing/turn-harness.d.ts +2 -0
  54. package/package.json +11 -7
package/README.md CHANGED
@@ -43,6 +43,7 @@ returns exactly one response:
43
43
  | `stay(feedback)` | Validation failed; continue collecting in the current node. |
44
44
  | `go(TargetNode)` | Enter another registered conversational node now. |
45
45
  | `direct(content)` | Return exact code-owned content, such as a policy decision, price table, or ticket ID. |
46
+ | `directTo(TargetNode, content)` | Return exact content and make the target the next user-turn node. |
46
47
  | `finish(content)` | Return exact final content and complete the conversation. |
47
48
 
48
49
  There is no per-turn context object, post-tool transition hook, synthetic tool
@@ -117,11 +118,87 @@ export class CityNode extends ConversationNode<WeatherGraphStateType> {
117
118
  Use `go(TargetNode).withState({ ... })` when a transition also initializes the
118
119
  target node's state. Use `withMessages()` for real model-visible messages or
119
120
  attachments, and `withCleanup()` for cleanup tied to that tool result.
121
+ When a custom `GraphNode.run()` makes its own model call, attach that call's
122
+ token delta with `.withUsage(conversation.usage)` so a `go()` or response
123
+ builder preserves the session's LLM accounting.
124
+ Use `directTo(TargetNode, content)` when the current handler should answer now
125
+ and defer the target until the next user turn.
120
126
 
121
127
  For deterministic policy that needs state owned by another node, read
122
128
  `this.graph.graphState()`. To write another node's channel, use
123
129
  `this.graph.saveNodeState(TargetNode, patch)`.
124
130
 
131
+ ## Add typed decisions with Jev
132
+
133
+ EZGraph supports [Jev](https://typesafe.ai/) through LangChain's optional
134
+ `@langchain/typesafe` package. Use a provider-neutral `DecisionNode` when a
135
+ workflow needs a bounded classification or review rather than generated text.
136
+ Jev returns typed Choice, Score, and Noul answers; your application keeps
137
+ thresholds, routing, authorization, and side effects in code.
138
+
139
+ ```bash
140
+ npm install @langchain/typesafe
141
+ ```
142
+
143
+ ```ts
144
+ import {
145
+ DecisionNode,
146
+ DecisionProvider,
147
+ GraphEngine,
148
+ go,
149
+ type DecisionAnswers,
150
+ type DecisionQuestionMap,
151
+ } from "@picoflow/ezgraph";
152
+
153
+ const TRIAGE = {
154
+ route: {
155
+ type: "choice",
156
+ criteria: {
157
+ billing: "Invoice or refund question",
158
+ technical: "Failure requiring diagnosis",
159
+ unclear: "Missing indispensable detail",
160
+ },
161
+ },
162
+ urgent: {
163
+ type: "noul",
164
+ instructions: "Is a production operation currently blocked?",
165
+ },
166
+ } as const satisfies DecisionQuestionMap;
167
+
168
+ class TriageNode extends DecisionNode<SupportGraphStateType, typeof TRIAGE> {
169
+ defineQuestions() {
170
+ return TRIAGE;
171
+ }
172
+
173
+ override getPrompt() {
174
+ return "Classify the latest support request.";
175
+ }
176
+
177
+ onDecision(answers: DecisionAnswers<typeof TRIAGE>) {
178
+ if (answers.route.confidence < 0.75) return go(ClarifyNode);
179
+ if (answers.urgent.noul >= 0.9) return go(SpecialistNode);
180
+ return answers.route.choice === "billing"
181
+ ? go(BillingPolicyNode)
182
+ : go(QuickAnswerNode);
183
+ }
184
+ }
185
+
186
+ const decisionProviders = DecisionProvider.create({
187
+ typesafe: { apiKey: process.env.TYPESAFE_API_KEY },
188
+ });
189
+
190
+ const engine = await GraphEngine.create({
191
+ graphs: [SupportGraph],
192
+ decisionProviders,
193
+ });
194
+ ```
195
+
196
+ The default decision configuration uses provider `typesafe` and model
197
+ `jev-latest`; graphs or individual nodes can override the model, timeout, and
198
+ bounded retry count. Provider registration is explicit, and a missing Jev
199
+ provider, package, or credential fails clearly instead of falling back to a
200
+ chat model. Decision usage is persisted separately from chat-model tokens.
201
+
125
202
  ## Build and register the graph
126
203
 
127
204
  Register conversational nodes explicitly. Tool-returned `go()` responses choose
@@ -1 +1 @@
1
- var d=Object.defineProperty;var a=(t,r)=>d(t,"name",{value:r,configurable:!0});import{GraphLlm as c}from"./graph-llm.config.js";import{GraphNodeRuntime as g}from"./graph-node.js";import{StateGraphExt as u}from"./state-graph-ext.js";import{assertEmptyResponseRetries as l,assertMaxAgentRounds as y,DEFAULT_CONVERSATION_POLICY as h,DEFAULT_MAX_AGENT_ROUNDS as w}from"./conversation-runner.js";import{assertLlmTimeoutMs as f}from"./llm-gateway.js";import{assertGraphSchemaVersion as m,assertStableId as v,stableClassId as n}from"./stable-id.js";class p{static{a(this,"BaseGraph")}llmGateway;static id(){return this.name}static assertName(r){return p.assertId(r)}static assertId(r){return v(r,"graph")}name;id;schemaVersion;llmConfig;requiresUserMessage;responseMode;maxAgentRounds;conversationPolicy;compiledGraph;runtime;nodeMap=new Map;endNode;migrations;constructor(r,e){this.llmGateway=r;const s=new.target;this.name=s.name,this.id=n(s,"graph"),this.schemaVersion=m(e.schemaVersion??1),this.migrations=R(e.migrations,this.schemaVersion),this.llmConfig=c.resolveConfig(e.llmConfig),this.requiresUserMessage=e.requiresUserMessage??!0,this.responseMode=e.responseMode??"chat",this.maxAgentRounds=y(e.maxAgentRounds??w),this.conversationPolicy=M(e),this.endNode=e.endNode,this.runtime=new g(e.endNode,this.llmConfig,S(e.historySpaces),e.initialHistorySpace,this.responseMode,this.maxAgentRounds,this.conversationPolicy)}get graph(){return this.compiledGraph??=this.buildGraph()}prepareInput(r,e){const s=this.runtime.historySpace(r?.currentNode);return{...r??{},histories:{...r?.histories??{},[s]:[...r?.histories[s]??[],e]}}}saveNodeState(r,e){this.runtime.saveNode(n(r,"graph node"),e)}async restoreSessionDoc(r){if(r.graph.id!==this.id)throw new Error(`Session '${r.id}' belongs to graph '${r.graph.id}', not '${this.id}'. Start a new session to run a different graph.`);if(r.graph.schemaVersion>this.schemaVersion)throw new Error(`Session '${r.id}' uses graph '${this.id}' schema version ${r.graph.schemaVersion}, but this runtime supports version ${this.schemaVersion}.`);let e=r;for(;e.graph.schemaVersion<this.schemaVersion;){const s=e.graph.schemaVersion,i=this.migrations.get(s);if(!i)throw new Error(`Graph '${this.id}' has no migration from schema version ${s} to ${s+1}.`);const o=await i.migrate(e);if(o.graph.id!==this.id)throw new Error(`Graph '${this.id}' migration from schema version ${s} changed the persisted graph ID.`);e={...o,graph:{...o.graph,schemaVersion:s+1}}}return await this.onRestoreSessionDoc(e)}async onRestoreSessionDoc(r){return r}idleMs(r){const e=Date.parse(r.modifiedAt);return Number.isFinite(e)?Date.now()-e:0}createStateGraph(r){return new u(r,(e=>this.createNode(e)),this.endNode)}createNode(r){const e=new r(this.llmGateway,this.runtime),s=n(r,"graph node");if(e.id!==s)throw new Error(`Graph node factory for '${s}' constructs '${e.id}'.`);if(this.nodeMap.has(e.id))throw new Error(`Graph node '${e.id}' is already registered.`);return this.nodeMap.set(e.id,e),this.runtime.registerTools(e.id,e.defineTool()),Object.freeze(e),e}}function M(t){const r=t.emptyResponseRecovery===void 0?h.emptyResponseRecovery:t.emptyResponseRecovery;return r&&l(r.retries),{...t.llmTimeoutMs===void 0?{}:{llmTimeoutMs:f(t.llmTimeoutMs)},emptyHistorySeed:t.emptyHistorySeed===void 0?h.emptyHistorySeed:t.emptyHistorySeed,emptyResponseRecovery:r}}a(M,"resolveConversationPolicy");function S(t){return Object.fromEntries((t??[]).map(([r,e])=>[n(r,"graph node"),e]))}a(S,"historySpaceMap");function R(t,r){const e=new Map;let s;for(const i of t??[]){const o=m(i.from);if(o>=r)throw new Error(`A graph migration from version ${o} cannot target schema version ${r}.`);if(e.has(o))throw new Error(`More than one graph migration starts at version ${o}.`);if(s!==void 0&&o!==s+1)throw new Error(`Graph migrations must be ordered and contiguous; version ${s} must be followed by ${s+1}.`);e.set(o,i),s=o}return e}a(R,"migrationMap");export{p as BaseGraph};
1
+ var d=Object.defineProperty;var a=(t,r)=>d(t,"name",{value:r,configurable:!0});import{GraphLlm as c}from"./graph-llm.config.js";import{GraphNodeRuntime as u}from"./graph-node.js";import{StateGraphExt as g}from"./state-graph-ext.js";import{assertEmptyResponseRetries as l,assertMaxAgentRounds as y,DEFAULT_CONVERSATION_POLICY as h,DEFAULT_MAX_AGENT_ROUNDS as w}from"./conversation-runner.js";import{assertLlmTimeoutMs as f}from"./llm-gateway.js";import{assertGraphSchemaVersion as m,assertStableId as v,stableClassId as n}from"./stable-id.js";class p{static{a(this,"BaseGraph")}llmGateway;static id(){return this.name}static assertName(r){return p.assertId(r)}static assertId(r){return v(r,"graph")}name;id;schemaVersion;llmConfig;requiresUserMessage;responseMode;maxAgentRounds;conversationPolicy;compiledGraph;runtime;nodeMap=new Map;endNode;migrations;constructor(r,e){this.llmGateway=r;const s=new.target;this.name=s.name,this.id=n(s,"graph"),this.schemaVersion=m(e.schemaVersion??1),this.migrations=S(e.migrations,this.schemaVersion),this.llmConfig=c.resolveConfig(e.llmConfig),this.requiresUserMessage=e.requiresUserMessage??!0,this.responseMode=e.responseMode??"chat",this.maxAgentRounds=y(e.maxAgentRounds??w),this.conversationPolicy=M(e),this.endNode=e.endNode,this.runtime=new u(e.endNode,this.llmConfig,R(e.historySpaces),e.initialHistorySpace,this.responseMode,this.maxAgentRounds,this.conversationPolicy,e.decisionConfig,i=>this.onDecisionError(i))}onDecisionError(r){return null}attachDecisionProviderResolver(r){this.runtime.attachDecisionProviderResolver(r)}get graph(){return this.compiledGraph??=this.buildGraph()}prepareInput(r,e){const s=this.runtime.historySpace(r?.currentNode);return{...r??{},histories:{...r?.histories??{},[s]:[...r?.histories[s]??[],e]}}}saveNodeState(r,e){this.runtime.saveNode(n(r,"graph node"),e)}async restoreSessionDoc(r){if(r.graph.id!==this.id)throw new Error(`Session '${r.id}' belongs to graph '${r.graph.id}', not '${this.id}'. Start a new session to run a different graph.`);if(r.graph.schemaVersion>this.schemaVersion)throw new Error(`Session '${r.id}' uses graph '${this.id}' schema version ${r.graph.schemaVersion}, but this runtime supports version ${this.schemaVersion}.`);let e=r;for(;e.graph.schemaVersion<this.schemaVersion;){const s=e.graph.schemaVersion,i=this.migrations.get(s);if(!i)throw new Error(`Graph '${this.id}' has no migration from schema version ${s} to ${s+1}.`);const o=await i.migrate(e);if(o.graph.id!==this.id)throw new Error(`Graph '${this.id}' migration from schema version ${s} changed the persisted graph ID.`);e={...o,graph:{...o.graph,schemaVersion:s+1}}}return await this.onRestoreSessionDoc(e)}async onRestoreSessionDoc(r){return r}idleMs(r){const e=Date.parse(r.modifiedAt);return Number.isFinite(e)?Date.now()-e:0}createStateGraph(r){return new g(r,(e=>this.createNode(e)),this.endNode)}createNode(r){const e=new r(this.llmGateway,this.runtime),s=n(r,"graph node");if(e.id!==s)throw new Error(`Graph node factory for '${s}' constructs '${e.id}'.`);if(this.nodeMap.has(e.id))throw new Error(`Graph node '${e.id}' is already registered.`);return this.nodeMap.set(e.id,e),this.runtime.registerTools(e.id,e.defineTool()),Object.freeze(e),e}}function M(t){const r=t.emptyResponseRecovery===void 0?h.emptyResponseRecovery:t.emptyResponseRecovery;return r&&l(r.retries),{...t.llmTimeoutMs===void 0?{}:{llmTimeoutMs:f(t.llmTimeoutMs)},emptyHistorySeed:t.emptyHistorySeed===void 0?h.emptyHistorySeed:t.emptyHistorySeed,emptyResponseRecovery:r}}a(M,"resolveConversationPolicy");function R(t){return Object.fromEntries((t??[]).map(([r,e])=>[n(r,"graph node"),e]))}a(R,"historySpaceMap");function S(t,r){const e=new Map;let s;for(const i of t??[]){const o=m(i.from);if(o>=r)throw new Error(`A graph migration from version ${o} cannot target schema version ${r}.`);if(e.has(o))throw new Error(`More than one graph migration starts at version ${o}.`);if(s!==void 0&&o!==s+1)throw new Error(`Graph migrations must be ordered and contiguous; version ${s} must be followed by ${s+1}.`);e.set(o,i),s=o}return e}a(S,"migrationMap");export{p as BaseGraph};
@@ -1 +1 @@
1
- var c=Object.defineProperty;var d=(n,t)=>c(n,"name",{value:t,configurable:!0});var u=function(n,t,e,o){var s=arguments.length,r=s<3?t:o===null?o=Object.getOwnPropertyDescriptor(t,e):o,i;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")r=Reflect.decorate(n,t,e,o);else for(var p=n.length-1;p>=0;p--)(i=n[p])&&(r=(s<3?i(r):s>3?i(t,e,r):i(t,e))||r);return s>3&&r&&Object.defineProperty(t,e,r),r},h=function(n,t){if(typeof Reflect=="object"&&typeof Reflect.metadata=="function")return Reflect.metadata(n,t)};import{HumanMessage as g}from"@langchain/core/messages";import{Command as a,END as f}from"@langchain/langgraph";import{GraphNode as l,Tool as w}from"./graph-node.js";import{stableClassId as y}from"./stable-id.js";import{TerminateSessionNode as C}from"./terminate-session.node.js";import{go as v}from"./tool-response.js";class R extends l{static{d(this,"ConversationNode")}async endChat(t){return v(C).withMessage(new g(t.message?.trim()||"The user asked to end the conversation."))}async run(t){const e=await this.runConversation(t,{});if(e.toolResponse)return this.resolveToolResponse(e,e.toolResponse);const o=e.response;if(!o?.trim())throw new Error(`Conversation node '${this.id}' stopped without a response or tool transition.`);return new a({update:{currentNode:this.id,response:o,inputConsumed:!0,completed:!1,...this.historyUpdate(e.messages),tokens:e.usage},goto:f})}resolveToolResponse(t,e){const o=this.historyUpdate(t.messages);if(e.kind==="go"){if(!e.target)throw new Error(`Conversation node '${this.id}' selected go() without a target.`);const s=y(e.target,"graph node");return e.state&&this.graph.saveNodeState(e.target,e.state),e.message&&this.graph.appendHistory(this.graph.historySpace(s),[e.message]),new a({update:{currentNode:s,inputConsumed:!0,response:"",completed:!1,...o,tokens:t.usage},goto:s})}if(e.kind==="direct")return new a({update:{currentNode:this.id,response:m(this.id,e),inputConsumed:!0,completed:!1,...o,tokens:t.usage},goto:f});if(e.kind==="finish")return new a({update:{...this.graph.complete(m(this.id,e)),...o,tokens:t.usage},goto:f});throw new Error(`Conversation node '${this.id}' returned stay() after the agent loop stopped.`)}}u([w("terminate_session"),h("design:type",Function),h("design:paramtypes",[Object]),h("design:returntype",Promise)],R.prototype,"endChat",null);function m(n,t){if(!t.response?.trim())throw new Error(`Conversation node '${n}' selected ${t.kind}() without a response.`);return t.response}d(m,"requireResponse");export{R as ConversationNode};
1
+ var m=Object.defineProperty;var h=(s,t)=>m(s,"name",{value:t,configurable:!0});var u=function(s,t,e,n){var r=arguments.length,o=r<3?t:n===null?n=Object.getOwnPropertyDescriptor(t,e):n,i;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")o=Reflect.decorate(s,t,e,n);else for(var a=s.length-1;a>=0;a--)(i=s[a])&&(o=(r<3?i(o):r>3?i(t,e,o):i(t,e))||o);return r>3&&o&&Object.defineProperty(t,e,o),o},c=function(s,t){if(typeof Reflect=="object"&&typeof Reflect.metadata=="function")return Reflect.metadata(s,t)};import{AIMessage as w,HumanMessage as y}from"@langchain/core/messages";import{Command as d,END as p}from"@langchain/langgraph";import{GraphNode as l,Tool as v}from"./graph-node.js";import{stableClassId as f}from"./stable-id.js";import{TerminateSessionNode as C}from"./terminate-session.node.js";import{go as R}from"./tool-response.js";import{addTokenUsage as N}from"./token-usage.js";class _ extends l{static{h(this,"ConversationNode")}async endChat(t){return R(C).withMessage(new y({content:t.message?.trim()||"The user asked to end the conversation.",additional_kwargs:{ezgraphInternal:!0}}))}async run(t){const e=await this.runConversation(t,{});if(e.toolResponse)return this.resolveToolResponse(e,e.toolResponse);const n=e.response;if(!n?.trim())throw new Error(`Conversation node '${this.id}' stopped without a response or tool transition.`);return new d({update:{currentNode:this.id,response:n,inputConsumed:!0,completed:!1,...this.historyUpdate(e.messages),tokens:e.usage},goto:p})}resolveToolResponse(t,e){const n=this.historyUpdate(t.messages),r=N(t.usage,e.usage);if(e.kind==="go"){if(!e.target)throw new Error(`Conversation node '${this.id}' selected go() without a target.`);const o=f(e.target,"graph node");return e.state&&this.graph.saveNodeState(e.target,e.state),e.message&&this.graph.appendHistory(this.graph.historySpace(o),[e.message]),new d({update:{currentNode:o,inputConsumed:!0,response:"",completed:!1,...n,tokens:r},goto:o})}if(e.kind==="directTo"){if(!e.target)throw new Error(`Conversation node '${this.id}' selected directTo() without a target.`);const o=f(e.target,"graph node"),i=this.graph.historySpace(o);e.state&&this.graph.saveNodeState(e.target,e.state),e.message&&this.graph.appendHistory(i,[e.message]);const a=g(this.id,e);return i!==this.historySpace()&&this.graph.appendHistory(i,[new w(a)]),new d({update:{currentNode:o,response:a,inputConsumed:!0,completed:!1,...n,tokens:r},goto:p})}if(e.kind==="direct")return new d({update:{currentNode:this.id,response:g(this.id,e),inputConsumed:!0,completed:!1,...n,tokens:r},goto:p});if(e.kind==="finish")return new d({update:{...this.graph.complete(g(this.id,e)),...n,tokens:r},goto:p});throw new Error(`Conversation node '${this.id}' returned stay() after the agent loop stopped.`)}}u([v("terminate_session"),c("design:type",Function),c("design:paramtypes",[Object]),c("design:returntype",Promise)],_.prototype,"endChat",null);function g(s,t){if(!t.response?.trim())throw new Error(`Conversation node '${s}' selected ${t.kind}() without a response.`);return t.response}h(g,"requireResponse");export{_ as ConversationNode};
@@ -1 +1 @@
1
- const hJ=m;(function(r,A){const hp={r:0x1b2,A:0x1b5,c:0x1c8,a:0x1ad,V:0x1a6,t:0x1cb},he=m,c=r();while(!![]){try{const a=parseInt(he(hp.r))/0x1*(parseInt(he(0x1a2))/0x2)+parseInt(he(hp.A))/0x3*(-parseInt(he(hp.c))/0x4)+-parseInt(he(hp.a))/0x5*(-parseInt(he(hp.V))/0x6)+-parseInt(he(0x1c9))/0x7+parseInt(he(0x1cf))/0x8*(parseInt(he(0x1c0))/0x9)+parseInt(he(0x1b8))/0xa+parseInt(he(0x1be))/0xb*(parseInt(he(hp.t))/0xc);if(a===A)break;else c['push'](c['shift']());}catch(V){c['push'](c['shift']());}}}(h,0x8cecd));var v=Object[hJ(0x1b4)],p=(r,A)=>v(r,hJ(0x1b0),{'value':A,'configurable':!0x0});import{AIMessage as Z,HumanMessage as d,ToolMessage as B}from'@langchain/core/messages';import{addTokenUsage as E,emptyTokenUsage as f}from'./token-usage.js';import{isToolResponse as Q}from'./tool-response.js';import{describeStopReason as n,isRetryableStopReason as w,modelStopReason as e}from'./model-stop-reason.js';import{SessionLogWarning as J}from'./session-log.js';import{isOpenAIAuthConfig as u,openAIAuthMessageText as W}from'./openai-auth-provider.js';class X extends Error{static{p(this,'EmptyModelResponseError');}[hJ(0x1ba)];constructor(r){const hu=hJ;super(hu(0x1bc)+n(r)+').'),this['reason']=r,this[hu(0x1b0)]=hu(0x1c7);}}function h(){const hL=['BMfTzq','CMv0CMLLCW','mZqWotm3sNLJtvPr','AxnjBNrLz2vY','zgvMAw5LuhjVCgvYDhK','mJiZodnSsw9KrKO','Dg9VBc1JywXSlq','yxnZzxj0twf4qwDLBNrsB3vUzhm','mZm4ndK5mhHHDhb3wG','u3rHCNq','CMvHC29U','C3LZDgvTuhjVBxb0','vgHLig1VzgvSihjLDhvYBMvKigfUigvTChr5ihjLC3bVBNnLicG','AgLZDg9YEq','mJm2mZLYtKDxvMy','zw1WDhLiAxn0B3j5u2vLza','mtHowvrOAgS','CMvZCg9UC2u','DMfSDwu','zw1WDhLszxnWB25ZzvjLy292zxj5','C3rYAw5NAwz5','y2fSBe9WDgLVBNm','BgXTr2f0zxDHEq','rw1WDhLnB2rLBfjLC3bVBNnLrxjYB3i','mJeYDhbiA2Xi','nZq2ndKWnuPcC0XLyW','ChvZAa','mJy2ngfLAfnoDW','Bwf4qwDLBNrsB3vUzhmGBxvZDcbIzsbHihbVC2L0AxzLigLUDgvNzxi7ihjLy2vPDMvKia','ywDLBNq','BNvKz2u','ntGXntjUwNn0vvy','CNvU','DhjPBq','y29UDgvUDa','ywXSu2v0DgXLza','igfNzw50ihjVDw5KCY4','C3rHEq','Cg9W','BwfW','BgXTq29UzMLN','q29UDMvYC2f0Aw9Uigv4y2vLzgvKia','mNPcCKLzrq','zw1WDhLszxnWB25ZzvjLy292zxj5lNjLDhjPzxmGBxvZDcbIzsbHig5VBI1UzwDHDgL2zsbPBNrLz2vYoYbYzwnLAxzLzca','zxHLy3v0zvrVB2W','zw50CMLLCW','ntiWode1mgjwtgDpAW','y2XLyw51Ca','BgvUz3rO','qsb0B29SigjHDgnOihnLBgvJDgvKig1VCMuGDgHHBIbVBMuGDgvYBwLUywWGCMvZCg9UC2uGB3iGDhjHBNnPDgLVBI4','zMvLzgjHy2S','DxnHz2u','Dg9VBhm','nvHMEvzTra','A2LUza','rM9SBg93ihrOzsbZExn0zw0GChjVBxb0igfUzcbYzxnWB25KihbYB3bLCMX5lIbvC2uGDgHLihjLCxvPCMvKihrVB2WGD2HLBIbPBNn0CNvJDgvKlG'];h=function(){return hL;};return h();}function m(T,N){T=T-0x19d;const U=h();let Z=U[T];if(m['FARvlc']===undefined){var d=function(C){const Q='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+/=';let n='',w='';for(let Y=0x0,x,e,J=0x0;e=C['charAt'](J++);~e&&(x=Y%0x4?x*0x40+e:e,Y++%0x4)?n+=String['fromCharCode'](0xff&x>>(-0x2*Y&0x6)):0x0){e=Q['indexOf'](e);}for(let u=0x0,D=n['length'];u<D;u++){w+='%'+('00'+n['charCodeAt'](u)['toString'](0x10))['slice'](-0x2);}return decodeURIComponent(w);};m['vWmfno']=d,m['XkoHyf']={},m['FARvlc']=!![];}const B=U[0x0],E=T+B,f=m['XkoHyf'][E];return!f?(Z=m['vWmfno'](Z),m['XkoHyf'][E]=Z):Z=f,Z;}const $=0x8;function F(r){const hA={r:0x1cc},hD=hJ;if(!Number[hD(0x1b3)](r)||r<0x1)throw new Error(hD(hA.r)+String(r)+'.');return r;}p(F,hJ(0x1b7));const S=hJ(0x1b9),_={'retries':0x2,'nudge':hJ(0x1af)};function H(r){const hc={r:0x1b3},hW=hJ;if(!Number[hW(hc.r)](r)||r<0x0)throw new Error(hW(0x1a3)+String(r)+'.');return r;}p(H,'assertEmptyResponseRetries');const j={'emptyHistorySeed':S,'emptyResponseRecovery':_};class z{static{p(this,'ConversationRunner');}['llmGateway'];constructor(r){const ha={r:0x1c6},hk=hJ;this[hk(ha.r)]=r;}async[hJ(0x1d0)](V){const hS={r:0x1bd,A:0x1c3,c:0x1b1,a:0x1ac,V:0x1c5,t:0x1d3,g:0x19f,o:0x1a0,q:0x1c2,l:0x1d2,G:0x19e,i:0x1ce,y:0x1a4,R:0x1ae,K:0x19d,s:0x1aa,M:0x1ca,h0:0x1a7,h1:0x1ae,h2:0x1c1},hV={r:0x1d3},hz=hJ,t=V[hz(0x1bf)]===void 0x0?S:V[hz(0x1bf)],q=V[hz(hS.r)][hz(0x1a8)]===0x0&&t!==null,G=q?[new d(t)]:[...V[hz(0x1bd)]],K=q?[...G]:[];let h0=[],h1=f();const h2=F(V['maxAgentRounds']??$),h3=V[hz(hS.A)]===void 0x0?_:V['emptyResponseRecovery'],h4=h3?H(h3[hz(hS.c)]):0x0;let h5=0x0;for(let h7=0x0;h7<h2;h7+=0x1){let h8;try{h8=await this[hz(0x1c6)][hz(0x1cd)](V[hz(0x1bb)],G,V[hz(hS.a)],V['llmConfig'],V[hz(hS.V)]);}catch(hT){const hN=h0;throw h0=[],await Promise[hz(hS.t)](hN[hz(hS.g)](hU=>hU())),hT;}h1=E(h1,h8[hz(0x1ab)]),K[hz(0x1ca)](h8[hz(0x1c2)]),G['push'](h8['value']);const h9=h8['value']['tool_calls']??[];if(h9['length']===0x0){const hU=u(V[hz(hS.o)])?W(h8[hz(hS.q)][hz(hS.l)]):Y(h8[hz(hS.q)]);if(hU[hz(0x1d1)]())return await h6(),{'messages':K,'usage':h1,'response':hU,'stoppedAfterTool':!0x1};const hZ=e(h8['value']),hd=w(hZ)&&h3!==null&&h5<h4;if(J({'empty_model_response':n(hZ),'retried':hd}),hd&&h3){h5+=0x1,K[hz(hS.G)](),G[hz(0x19e)](),G[hz(0x1ca)](new d(h3[hz(hS.i)]));continue;}return await h6(),{'messages':K,'usage':h1,'response':hU,'stoppedAfterTool':!0x1,'stopReason':hZ};}await h6();let hh=!0x1,hm;try{for(const [hB,hE]of h9[hz(0x1a5)]()){const hf=await V[hz(hS.y)](hE);if(Q(hf)){if(hf[hz(hS.R)]!=='stay'){if(hm&&hm[hz(0x1ae)]!==hz(hS.K))throw new Error(hz(0x1a9));hm=hf;}else hm||(hm=hf);const hC=new B({'content':hf[hz(hS.s)]??'OK','tool_call_id':hE['id']??hz(0x1b6)+h7+'-'+hB,'name':hE[hz(0x1b0)]});K[hz(hS.M)](hC),G[hz(0x1ca)](hC),hf['messages']&&(K[hz(0x1ca)](...hf['messages']),G[hz(0x1ca)](...hf['messages'])),hf['cleanup']&&h0[hz(0x1ca)](hf[hz(hS.h0)]),hh||=hf[hz(hS.h1)]!==hz(hS.K);continue;}}}catch(hQ){throw await h6(),hQ;}if(hh){const hn=hm?.[hz(hS.h2)];if(hn){const hw=new Z(hn);K[hz(hS.M)](hw),G[hz(0x1ca)](hw);}return await h6(),{'messages':K,'usage':h1,'stoppedAfterTool':!0x0,...hn?{'response':hn}:{},...hm?{'toolResponse':hm}:{}};}}throw await h6(),new Error(hz(0x1a1)+h2+hz(0x1d4));async function h6(){const hr=hz,hY=h0;h0=[],await Promise[hr(hV.r)](hY['map'](hx=>hx()));}p(h6,'cleanupAttachments');}}function Y(r){const hj={r:0x1d2,A:0x1c4},hb=hJ;return typeof r['content']=='string'?r[hb(hj.r)]:JSON[hb(hj.A)](r['content']);}p(Y,'messageText');export{z as ConversationRunner,j as DEFAULT_CONVERSATION_POLICY,S as DEFAULT_EMPTY_HISTORY_SEED,_ as DEFAULT_EMPTY_RESPONSE_RECOVERY,$ as DEFAULT_MAX_AGENT_ROUNDS,X as EmptyModelResponseError,H as assertEmptyResponseRetries,F as assertMaxAgentRounds};
1
+ function K(){const KN=['DgfYz2v0','AgLZDg9YEq','C3rHEq','Bwf4qwDLBNrsB3vUzhmGBxvZDcbIzsbHihbVC2L0AxzLigLUDgvNzxi7ihjLy2vPDMvKia','u3rHCNq','ChvZAa','mZq2mZG3oenpBuLvqW','zxHLy3v0zvrVB2W','BwvZC2fNzvrLEhq','CMvHC29U','C3LZDgvTuhjVBxb0','BMfTzq','CNvU','Axntyw1LqMfYzvrYyw5ZAxrPB24','y2fSBe9WDgLVBNm','zw50CMLLCW','ywXSu2v0DgXLza','y29UDgvUDa','Cg9W','zw1WDhLiAxn0B3j5u2vLza','Dg9VBhm','Dg9VBc1JywXSlq','mtK3mta4uwjct0vt','C3rHDgu','Bwf4qwDLBNrsB3vUzhm','ntKWodi4menwv01ctq','q29UDMvYC2f0Aw9Uigv4y2vLzgvKia','yxnZzxj0rw1WDhLszxnWB25ZzvjLDhjPzxm','zw1WDhLszxnWB25ZzvjLy292zxj5','BNvKz2u','rw1WDhLnB2rLBfjLC3bVBNnLrxjYB3i','BwvZC2fNzq','ywDLBNq','ndj3D0rzsvO','DhjPBq','Aw50zxjUywXiDw1HBK1LC3nHz2u','zMvLzgjHy2S','otG3mZbgvgnkvNu','DxnHz2u','yxnZzxj0twf4qwDLBNrsB3vUzhm','AxnjBNrLz2vY','nJy2mdi4rvLxsvbk','CMvZCg9UC2u','BgvUz3rO','zgvMAw5LuhjVCgvYDhK','q29UDMvYC2f0Aw9UuNvUBMvY','BwfW','ndq0nZa2nvnJAMv6sa','ndKZnteYEuDVywHq','BgXTr2f0zxDHEq','BwvZC2fNzxm','zw1WDhLszxnWB25ZzvjLy292zxj5lNjLDhjPzxmGBxvZDcbIzsbHig5VBI1UzwDHDgL2zsbPBNrLz2vYoYbYzwnLAxzLzca','DMfSDwu','ovP3Aw1srW','y2XLyw51Ca','BgXTq29UzMLN','A2LUza'];K=function(){return KN;};return K();}const Kq=e;(function(M,u){const KA={M:0x197,u:0x193,A:0x19d,r:0x187},Kk=e,A=M();while(!![]){try{const r=-parseInt(Kk(KA.M))/0x1+parseInt(Kk(KA.u))/0x2+parseInt(Kk(0x18f))/0x3*(parseInt(Kk(0x184))/0x4)+-parseInt(Kk(KA.A))/0x5+parseInt(Kk(0x174))/0x6+parseInt(Kk(KA.r))/0x7+parseInt(Kk(0x19e))/0x8*(-parseInt(Kk(0x16a))/0x9);if(r===u)break;else A['push'](A['shift']());}catch(f){A['push'](A['shift']());}}}(K,0x84aea));var v=Object[Kq(0x19a)],i=(M,u)=>v(M,'name',{'value':u,'configurable':!0x0});import{AIMessage as J,HumanMessage as V,ToolMessage as m}from'@langchain/core/messages';import{addTokenUsage as h,emptyTokenUsage as c}from'./token-usage.js';import{isToolResponse as s}from'./tool-response.js';import{describeStopReason as n,isRetryableStopReason as o,modelStopReason as z}from'./model-stop-reason.js';import{SessionLogWarning as t}from'./session-log.js';import{isOpenAIAuthConfig as E,openAIAuthMessageText as q}from'./openai-auth-provider.js';class j extends Error{static{i(this,Kq(0x18c));}[Kq(0x177)];constructor(M){const Kx={M:0x179},KD=Kq;super('The\x20model\x20returned\x20an\x20empty\x20response\x20('+n(M)+').'),this['reason']=M,this[KD(Kx.M)]='EmptyModelResponseError';}}const $=0x8;function F(M){const Kr={M:0x196,u:0x171},KM=Kq;if(!Number[KM(Kr.M)](M)||M<0x1)throw new Error(KM(Kr.u)+String(M)+'.');return M;}function e(j,C){j=j-0x168;const I=K();let J=I[j];if(e['ZMOyaa']===undefined){var F=function(c){const s='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+/=';let P='',n='';for(let o=0x0,z,H,t=0x0;H=c['charAt'](t++);~H&&(z=o%0x4?z*0x40+H:H,o++%0x4)?P+=String['fromCharCode'](0xff&z>>(-0x2*o&0x6)):0x0){H=s['indexOf'](H);}for(let E=0x0,q=P['length'];E<q;E++){n+='%'+('00'+P['charCodeAt'](E)['toString'](0x10))['slice'](-0x2);}return decodeURIComponent(n);};e['MLcmJN']=F,e['BemBlG']={},e['ZMOyaa']=!![];}const V=I[0x0],m=j+V,h=e['BemBlG'][m];return!h?(J=e['MLcmJN'](J),e['BemBlG'][m]=J):J=h,J;}i(F,Kq(0x195));const x=Kq(0x172),S={'retries':0x2,'nudge':'Follow\x20the\x20system\x20prompt\x20and\x20respond\x20properly.\x20Use\x20the\x20required\x20tool\x20when\x20instructed.'};function Y(M){const KS={M:0x168},KQ=Kq;if(!Number['isInteger'](M)||M<0x0)throw new Error(KQ(KS.M)+String(M)+'.');return M;}i(Y,Kq(0x189));const Q={'emptyHistorySeed':x,'emptyResponseRecovery':S};class Z{static{i(this,Kq(0x19b));}[Kq(0x19f)];constructor(M){const KZ=Kq;this[KZ(0x19f)]=M;}async[Kq(0x17a)](X){const Kd={M:0x181,u:0x16f,A:0x16f,r:0x186,f:0x182,d:0x173,y:0x169,X:0x17f,w:0x190,R:0x18b,g:0x17d,p:0x16d,a:0x16d,W:0x170,l:0x192,K0:0x1a0,K1:0x16b,K2:0x170,K3:0x173,K4:0x173},Kv={M:0x19c},KO=Kq,W=X[KO(0x181)]===void 0x0?x:X[KO(Kd.M)],K0=X[KO(Kd.u)][KO(0x199)]===0x0&&W!==null,K1=K0?[_(W)]:[...X[KO(Kd.A)]],K2=K0?[...K1]:[];let K3=[],K4=c();const K5=F(X[KO(Kd.r)]??$),K6=X['emptyResponseRecovery']===void 0x0?S:X[KO(0x18a)],K7=K6?Y(K6['retries']):0x0;let K8=0x0;for(let KK=0x0;KK<K5;KK+=0x1){let Ke;try{Ke=await this['llmGateway'][KO(0x18e)](X[KO(0x178)],K1,X[KO(Kd.f)],X['llmConfig'],X[KO(0x17c)]);}catch(KJ){const KF=K3;throw K3=[],await Promise[KO(0x17e)](KF['map'](KV=>KV())),KJ;}K4=h(K4,Ke['usage']),K2[KO(0x173)](Ke[KO(0x169)]),K1[KO(Kd.d)](Ke[KO(Kd.y)]);const Kj=Ke['value']['tool_calls']??[];if(Kj[KO(0x199)]===0x0){const KV=E(X[KO(0x16c)])?q(Ke[KO(0x169)][KO(Kd.X)]):B(Ke[KO(0x169)]);if(KV[KO(Kd.w)]())return await K9(),{'messages':K2,'usage':K4,'response':KV,'stoppedAfterTool':!0x1};const Km=z(Ke[KO(0x169)]),Kh=o(Km)&&K6!==null&&K8<K7;if(t({'empty_model_response':n(Km),'retried':Kh}),Kh&&K6){K8+=0x1,K2[KO(0x180)](),K1['pop'](),K1['push'](_(K6[KO(Kd.R)]));continue;}return await K9(),{'messages':K2,'usage':K4,'response':KV,'stoppedAfterTool':!0x1,'stopReason':Km};}await K9();let KC=!0x1,KI;try{for(const [Kc,Ks]of Kj[KO(Kd.g)]()){const KP=await X[KO(0x175)](Ks);if(s(KP)){if(KP[KO(Kd.p)]!=='stay'){if(KI&&KI[KO(Kd.a)]!==KO(Kd.W)&&!G(KI,KP))throw new Error('A\x20tool\x20batch\x20selected\x20more\x20than\x20one\x20terminal\x20response\x20or\x20transition.');KI=KP;}else KI||(KI=KP);const Kn=new m({'content':KP[KO(Kd.l)]??'OK','tool_call_id':Ks['id']??KO(0x183)+KK+'-'+Kc,'name':Ks[KO(0x179)]});K2[KO(0x173)](Kn),K1['push'](Kn),KP['messages']&&(K2['push'](...KP[KO(Kd.K0)]),K1['push'](...KP[KO(0x1a0)])),KP[KO(0x16b)]&&K3[KO(0x173)](KP[KO(Kd.K1)]),KC||=KP['kind']!==KO(Kd.K2);continue;}}}catch(Ko){throw await K9(),Ko;}if(KC){const Kz=KI?.['response'];if(Kz){const KH=new J(Kz);K2[KO(Kd.K3)](KH),K1[KO(Kd.K4)](KH);}return await K9(),{'messages':K2,'usage':K4,'stoppedAfterTool':!0x0,...Kz?{'response':Kz}:{},...KI?{'toolResponse':KI}:{}};}}throw await K9(),new Error(KO(0x188)+K5+'\x20agent\x20rounds.');async function K9(){const Kb=KO,Kt=K3;K3=[],await Promise[Kb(0x17e)](Kt[Kb(Kv.M)](KE=>KE()));}i(K9,'cleanupAttachments');}}function G(M,u){const Ky={M:0x16d,u:0x1a0,A:0x198,r:0x194},Ku=Kq;return M[Ku(0x16d)]==='go'&&u[Ku(Ky.M)]==='go'&&M['target']===u[Ku(0x16e)]&&M[Ku(0x185)]===void 0x0&&u[Ku(0x185)]===void 0x0&&M[Ku(0x18d)]===void 0x0&&u[Ku(0x18d)]===void 0x0&&M[Ku(Ky.u)]===void 0x0&&u['messages']===void 0x0&&M[Ku(0x16b)]===void 0x0&&u[Ku(0x16b)]===void 0x0&&M[Ku(0x198)]===void 0x0&&u[Ku(Ky.A)]===void 0x0&&M[Ku(Ky.r)]===void 0x0&&u['usage']===void 0x0;}i(G,Kq(0x17b));function _(M){return new V({'content':M,'additional_kwargs':{'ezgraphInternal':!0x0}});}i(_,Kq(0x191));function B(M){const Kw={M:0x17f},KU=Kq;return typeof M[KU(Kw.M)]=='string'?M[KU(0x17f)]:JSON['stringify'](M[KU(0x17f)]);}i(B,Kq(0x176));export{Z as ConversationRunner,Q as DEFAULT_CONVERSATION_POLICY,x as DEFAULT_EMPTY_HISTORY_SEED,S as DEFAULT_EMPTY_RESPONSE_RECOVERY,$ as DEFAULT_MAX_AGENT_ROUNDS,j as EmptyModelResponseError,Y as assertEmptyResponseRetries,F as assertMaxAgentRounds};
@@ -0,0 +1 @@
1
+ var D=Object.defineProperty;var r=(a,o)=>D(a,"name",{value:o,configurable:!0});import{GraphNode as m}from"../graph-node.js";import{currentTurnSignal as v}from"../turn-context.js";import{DecisionRunner as C}from"./decision-runner.js";import{assertJsonCompatible as w,validateDecisionQuestions as g}from"./decision-validation.js";class y extends m{static{r(this,"DecisionNode")}getPrompt(o){return""}getDecisionFacts(o){return{}}getDecisionConfig(){return{}}onDecisionError(o){return null}async run(o){this.assertNoChatConfiguration();const s=v();s?.throwIfAborted();const h=this.graph.resolveDecisionOptions(this.getDecisionConfig()),f=this.graph.resolveDecisionProvider(h.provider),l=structuredClone(this.defineQuestions(o));g(l);const u=this.getPrompt(o).trim(),p=Object.fromEntries(Object.entries(l).map(([e,t])=>[e,{...t,...u?{instructions:[u,...t.instructions===void 0?[]:[t.instructions]]}:{}}]));g(p);const n=this.graph.getConversation(this.historySpace()),c=structuredClone(this.getDecisionFacts(o));if("request"in c||"priorRequests"in c)throw new Error("getDecisionFacts() cannot replace framework-owned request or priorRequests.");const d={...c,request:n.request,priorRequests:[...n.priorRequests]};return w(d,"Decision input"),C.run({nodeId:this.id,state:o,conversation:n,providerState:d,questions:p,provider:f,options:h,callerSignal:s,onDecision:r(async(e,t,i)=>this.resolveNodeResponse(await this.onDecision(e,t,i)),"onDecision"),onError:r(async e=>{const i=await this.onDecisionError(e)??await this.graph.handleDecisionError(e);if(i===null)throw e.error;return this.resolveNodeResponse(i)},"onError")})}validateTools(){this.assertNoChatConfiguration();const o=this.graph.resolveDecisionOptions(this.getDecisionConfig());this.graph.resolveDecisionProvider(o.provider)}assertNoChatConfiguration(){const o=this.defineTool(),s=this.obtainTools();if(o.length>0||s.length>0)throw new Error("DecisionNode cannot configure chat tools.");if(Object.keys(this.getLlmConfig()).length>0)throw new Error("DecisionNode uses getDecisionConfig(), not a chat model configuration.")}usesChatModel(){return!1}async runConversation(o,s){throw new Error("DecisionNode does not run the conversational model loop.")}}export{y as DecisionNode};
@@ -0,0 +1 @@
1
+ var n=Object.defineProperty;var t=(s,e)=>n(s,"name",{value:e,configurable:!0});import{DecisionConfigurationError as o}from"./decision-types.js";import{TypeSafeClassifierAdapter as p}from"./typesafe-provider.js";class v{static{t(this,"DecisionProvider")}constructor(){}static create(e){const r=[];return Object.hasOwn(e,"typesafe")&&r.push(new p(e.typesafe)),r}}class f{static{t(this,"DecisionProviderRegistry")}providers=new Map;constructor(e=[]){for(const r of e){const i=r.id.trim();if(!i)throw new o("Decision provider IDs must be non-empty.");if(i!==r.id)throw new o(`Decision provider ID '${r.id}' cannot have leading or trailing whitespace.`);if(this.providers.has(i))throw new o(`Decision provider '${i}' is already registered.`);this.providers.set(i,r)}}resolve(e){const r=this.providers.get(e);if(!r)throw new o(`Decision provider '${e}' is not registered.`);return r}}export{v as DecisionProvider,f as DecisionProviderRegistry};
@@ -0,0 +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};
@@ -0,0 +1 @@
1
+ var c=Object.defineProperty;var n=(o,t)=>c(o,"name",{value:t,configurable:!0});function l(){return{calls:0,inputTokens:0,outputTokens:0,totalTokens:0}}n(l,"emptyDecisionUsage");function u(o){const t=o??{},e=i(t.inputTokens),r=i(t.outputTokens);return{calls:i(t.calls),inputTokens:e,outputTokens:r,totalTokens:e+r}}n(u,"normalizeDecisionUsage");function m(o,t){const e=u(o),r=u(t);return{calls:e.calls+r.calls,inputTokens:e.inputTokens+r.inputTokens,outputTokens:e.outputTokens+r.outputTokens,totalTokens:e.totalTokens+r.totalTokens}}n(m,"addDecisionUsage");function T(o={}){const t=i(o.inputTokens),e=i(o.outputTokens);return{calls:1,inputTokens:t,outputTokens:e,totalTokens:t+e}}n(T,"decisionUsage");function i(o){return Number.isInteger(o)&&(o??-1)>=0?o??0:0}n(i,"nonnegativeInteger");const a={provider:"typesafe",model:"jev-latest",timeoutMs:3e4,maxRetries:0};function d(o={},t={}){const e={...a,...o,...t};if(typeof e.provider!="string"||typeof e.model!="string"||!e.provider.trim()||!e.model.trim())throw new s("Decision provider and model must be non-empty.");if(!Number.isInteger(e.timeoutMs)||e.timeoutMs<1)throw new s(`Decision timeoutMs must be a positive integer; received ${String(e.timeoutMs)}.`);if(!Number.isInteger(e.maxRetries)||e.maxRetries<0)throw new s(`Decision maxRetries must be a non-negative integer; received ${String(e.maxRetries)}.`);return{...e,provider:e.provider.trim(),model:e.model.trim()}}n(d,"resolveDecisionOptions");class k extends Error{static{n(this,"DecisionValidationError")}constructor(t){super(t),this.name="DecisionValidationError"}}class s extends Error{static{n(this,"DecisionConfigurationError")}constructor(t){super(t),this.name="DecisionConfigurationError"}}class g extends Error{static{n(this,"DecisionTimeoutError")}constructor(t="Decision call timed out."){super(t),this.name="TimeoutError"}}export{a as DEFAULT_DECISION_OPTIONS,s as DecisionConfigurationError,g as DecisionTimeoutError,k as DecisionValidationError,m as addDecisionUsage,T as decisionUsage,l as emptyDecisionUsage,u as normalizeDecisionUsage,d as resolveDecisionOptions};
@@ -0,0 +1 @@
1
+ var y=Object.defineProperty;var a=(t,i)=>y(t,"name",{value:i,configurable:!0});import{z as e}from"zod";import{DecisionValidationError as c}from"./decision-types.js";const o=e.lazy(()=>e.union([e.string(),e.number(),e.boolean(),e.null(),e.array(o),e.record(e.string(),o)])),u=e.union([e.string(),e.record(e.string(),o),e.array(o)]),g=e.discriminatedUnion("type",[e.object({type:e.literal("choice"),criteria:e.record(e.string(),o).refine(t=>Object.keys(t).length>0&&Object.keys(t).every(i=>i.trim().length>0)),instructions:u.optional()}).strict(),e.object({type:e.literal("score"),criteria:e.array(o).min(2),instructions:u.optional()}).strict(),e.object({type:e.literal("noul"),criteria:e.object({true:o.optional(),false:o.optional()}).strict().optional(),instructions:u.optional()}).strict().refine(t=>t.instructions!==void 0||t.criteria!==void 0)]),l=e.number().min(0).max(1),h=e.discriminatedUnion("type",[e.object({type:e.literal("choice"),choice:e.string(),probabilities:e.record(e.string(),l),confidence:l}).strict(),e.object({type:e.literal("score"),score:e.number().nonnegative(),legend:e.record(e.string(),o),probabilities:e.record(e.string(),l),confidence:l}).strict(),e.object({type:e.literal("noul"),noul:l}).strict()]),m=e.object({model:e.string().min(1),answers:e.record(e.string(),h),usage:e.object({inputTokens:e.number().int().nonnegative().optional(),outputTokens:e.number().int().nonnegative().optional()}).strict().optional(),requestId:e.string().optional()}).strict();function w(t,i){if(!o.safeParse(t).success)throw new c(`${i} must contain only JSON values.`)}a(w,"assertJsonCompatible");function k(t){if(w(t,"Decision questions"),!t||Object.keys(t).length===0)throw new c("At least one decision question is required.");for(const[i,s]of Object.entries(t))if(!i.trim()||!g.safeParse(s).success)throw new c(`Invalid decision question '${i}'.`)}a(k,"validateDecisionQuestions");function $(t,i){if(!m.safeParse(t).success||!p(t.answers,Object.keys(i)))throw new c("Decision response does not match the registered questions.");for(const[s,r]of Object.entries(i)){const n=t.answers[s];if(!n||n.type!==r.type)throw new c(`Wrong decision answer type for '${s}'.`);if(n.type==="choice"&&r.type==="choice"&&(!Object.hasOwn(r.criteria,n.choice)||!p(n.probabilities,Object.keys(r.criteria))))throw new c(`Unknown or missing choice for '${s}'.`);if(n.type==="score"&&r.type==="score"){const b=r.criteria.map((d,f)=>String(f));if(n.score>r.criteria.length-1||!p(n.probabilities,b)||!p(n.legend,b))throw new c(`Invalid score range or legend for '${s}'.`)}if(n.type!=="noul"&&Math.abs(Object.values(n.probabilities).reduce((b,d)=>b+d,0)-1)>.02)throw new c(`Invalid probability distribution for '${s}'.`)}}a($,"validateDecisionResult");function p(t,i){return Object.keys(t).length===i.length&&i.every(r=>Object.hasOwn(t,r))}a(p,"sameKeys");export{w as assertJsonCompatible,k as validateDecisionQuestions,$ as validateDecisionResult};
@@ -0,0 +1 @@
1
+ var c=Object.defineProperty;var i=(o,e)=>c(o,"name",{value:e,configurable:!0});import{DecisionConfigurationError as u}from"./decision-types.js";class T{static{i(this,"TypeSafeClassifierAdapter")}options;id="typesafe";constructor(e={}){this.options=e}async decide(e,t){const n=this.options.apiKey??process.env.TYPESAFE_API_KEY;if(!n)throw new u("TypeSafe decision provider requires TYPESAFE_API_KEY or an explicit apiKey.");let r;try{({TypeSafeClassifier:r}=await import("@langchain/typesafe"))}catch(a){throw d(a)?new u("TypeSafe decision provider requires the optional '@langchain/typesafe' package."):a}const s=await new r({apiKey:n,...this.options.fetch===void 0?{}:{fetch:this.options.fetch},model:e.model,questions:structuredClone(e.questions),maxRetries:0,timeout:t.timeoutMs,dangerouslyAllowBrowser:!1}).invoke(structuredClone(e.state),{signal:t.signal});return{model:s.model,answers:s.answers,usage:{...s.usage.inputTokens===void 0?{}:{inputTokens:s.usage.inputTokens},...s.usage.outputTokens===void 0?{}:{outputTokens:s.usage.outputTokens}},...s.requestId?{requestId:s.requestId}:{}}}shouldRetry(e){const t=e.status;return t===408||t===429||t!==void 0&&t>=500||["TypeSafeAPIConnectionError","TypeSafeAPITimeoutError","TimeoutError"].includes(e.name)}}function d(o){return o instanceof Error?o.code==="ERR_MODULE_NOT_FOUND"&&o.message.includes("@langchain/typesafe"):!1}i(d,"isMissingTypeSafePackage");export{T as TypeSafeClassifierAdapter};
@@ -1 +1 @@
1
- const hU=m;(function(A,c){const he={A:0xf7,c:0x131,a:0xfc,S:0x120,t:0xf4,g:0xfb,o:0x11f},hN=m,a=A();while(!![]){try{const S=-parseInt(hN(0xee))/0x1*(-parseInt(hN(he.A))/0x2)+-parseInt(hN(he.c))/0x3+parseInt(hN(he.a))/0x4*(-parseInt(hN(he.S))/0x5)+-parseInt(hN(he.t))/0x6+parseInt(hN(0x10f))/0x7*(parseInt(hN(he.g))/0x8)+-parseInt(hN(0x101))/0x9*(parseInt(hN(he.o))/0xa)+parseInt(hN(0x112))/0xb;if(S===c)break;else a['push'](a['shift']());}catch(t){a['push'](a['shift']());}}}(h,0x63be7));function m(T,N){T=T-0xed;const U=h();let Z=U[T];if(m['kpBgIi']===undefined){var d=function(C){const Q='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+/=';let n='',w='';for(let Y=0x0,x,e,J=0x0;e=C['charAt'](J++);~e&&(x=Y%0x4?x*0x40+e:e,Y++%0x4)?n+=String['fromCharCode'](0xff&x>>(-0x2*Y&0x6)):0x0){e=Q['indexOf'](e);}for(let u=0x0,D=n['length'];u<D;u++){w+='%'+('00'+n['charCodeAt'](u)['toString'](0x10))['slice'](-0x2);}return decodeURIComponent(w);};m['oLnleT']=d,m['EnHFIY']={},m['kpBgIi']=!![];}const B=U[0x0],E=T+B,f=m['EnHFIY'][E];return!f?(Z=m['oLnleT'](Z),m['EnHFIY'][E]=Z):Z=f,Z;}var C=Object[hU(0x106)],y=(A,c)=>C(A,'name',{'value':c,'configurable':!0x0});import{HumanMessage as T}from'@langchain/core/messages';import{randomUUID as Z}from'node:crypto';import{GraphRegistry as d,registeredGraphId as B,registeredGraphSchemaVersion as f}from'./graph-registry.js';import{LangChainLlmGateway as Q}from'./langchain-llm-gateway.js';import{SessionLogError as n,createSessionLogs as Y,withSessionLogs as e}from'./session-log.js';import{withTurnContext as J}from'./turn-context.js';function h(){const hj=['D2L0Afr1CM5ty29Wzq','zw5KrMfPBgvKvhvYBG','C2nOzw1HvMvYC2LVBG','mta1otC5mNfwy2XWsa','mtC2vM1Oz25n','DxnLCK1LC3nHz2uGBxvZDcbIzsbHig5VBI1LBxb0EsbZDhjPBMCU','z3jHCgHoyw1L','z2v0u2vZC2LVBG','z3jHCgHZ','mZmZmJK3tKjJrLHu','C2f2zvn0yxrL','CMvSzwfZzvr1CM4','z3jHCgG','CMvNAxn0zxi','zgvMAw5LuhjVCgvYDhK','BM9Kzxm','C2LNBMfS','DhjPBq','zgvSzxrL','Aw52B2TL','CMv2AxnPB24','u0vtu0LptL9jrcbTDxn0igjLideTmti4igXLDhrLCNmSig51BwjLCNmSihvUzgvYC2nVCMvZlcbVCIbOExbOzw5ZlG','BgXTq29UzMLN','ndjyBgzOr0C','CMvZCg9UC2vnB2rL','DxnLCK1LC3nHz2u','mtmZmdaXntvzA1fUDNi','zgvSzxrLu2vZC2LVBG','y29UzMLNtwfUywDLCG','BgXTr2f0zxDHEuzHy3rVCNK','ChjLCgfYzuLUChv0','zxjYB3i','r3jHCgGGjW','ChjVDMLKzxjZ','CMvZCg9UC2u','jYbYzxn0B3jLihjLDhvYBMvKihnJAgvTysb2zxjZAw9Uia','y29UzMXPy3rszxn1Bhq','y29TCgXLDgvKu2vZC2LVBLjLC3vSDa','Aw5MBgLNAhrtzxnZAw9UCW','ntb0vNHOzKq','odeWodblqLzrC0m','jYbPCYbUB3qGCMvNAxn0zxjLzc4','z2v0r3jHCgHZ','DMfSAwrHDgvtzxnZAw9Uswq','CgvYC2LZDe1Pz3jHDgvKu2vZC2LVBG','y2HHDfjLC3vSDa','CMvNAxn0CNK','y2XVC2u','DMfSDwvZ','zxHWzwn0zwrszxzPC2LVBG','CMvZDg9YzvnLC3nPB25eB2m','DgvZDa','AgfZ','zg9JDw1LBNq','vgHPCYbJB252zxjZyxrPB24GAxmGywXYzwfKEsbJB21WBgv0zs4','C2vZC2LVBNm','C2vZC2LVBK1HBMfNzxi','mtKXnJu3ngnVB25StW','BwvZC2fNzq','zNjVBunVBMzPzW','CMvZDg9YzvnLC3nPB25eB2n1BwvUDa','y29UzMLN','odmYmwruCfzpzW','ANnVBG','jYbPCYbHBhjLywr5ihbYB2nLC3nPBMCGysb0DxjUlG','y29TCgXLDgvK','C3rYzwfT','r3jHCgHfBMDPBMu','mZK5mtGYneXYsMfQwq','C2vZC2LVBKLK','ANnVBLjLC3vSDa','mtq2rMn3tMPv'];h=function(){return hj;};return h();}import{SessionManager as u,SessionTurnError as W,SESSION_BUSY as z,SESSION_COMPLETED as r}from'./persistence/session-manager.js';import{parseJsonObjectResponse as p}from'./json-response.js';class M{static{y(this,hU(0xf3));}['registry']=new d();[hU(0x12f)];[hU(0x115)];[hU(0x11e)]=new Set();constructor(A={}){const hJ={A:0x115},hZ=hU;this['sessions']=A[hZ(0x130)]??new u(),this[hZ(0x115)]=A[hZ(hJ.A)]??(c=>new Q(c,A[hZ(0x119)]?{'providers':A[hZ(0x119)]}:{})),this['registerGraph'](A[hZ(0x100)]??[]);}static async['create'](A={}){const hu={A:0x133,c:0x114,a:0x115,S:0x100},hd=hU,c=await u[hd(hu.A)](A[hd(hu.c)]);return new M({'sessionManager':c,...A[hd(0x115)]?{'llmGatewayFactory':A[hd(hu.a)]}:{},...A[hd(hu.S)]?{'graphs':A[hd(0x100)]}:{},...A[hd(0x119)]?{'providers':A[hd(0x119)]}:{}});}['registerGraph'](A){const hD={A:0x126},hB=hU,c=A['map'](a=>new a(this[hB(0x115)](a['getGraphDefinition']()[hB(0x10e)])));return this[hB(hD.A)][hB(0x105)](c),this;}[hU(0x122)](){const hW={A:0x126},hE=hU;return this[hE(hW.A)]['names']();}[hU(0xff)](A){const hk={A:0xff},hf=hU;return this[hf(0x12f)][hf(hk.A)](w(A));}async['run'](A){const hr={A:0x118,c:0x121,a:0x109,S:0xfd,t:0xf0,g:0x11e},hz={A:0x104,c:0x107,a:0x12d,S:0xfa,t:0x12a,g:0xfa,o:0x11b,q:0x124,l:0x134,i:0xf1,P:0x11d,R:0x128,K:0x102,H:0x10b,s:0x110,v:0xef,I:0x11a,X:0xf1,h0:0x132,h1:0x12f,h2:0xf9,h3:0x11e,h4:0x10a},hC=hU,c=this[hC(0x126)]['get'](A[hC(0xfe)]);if(!c)return{'status':0x190,'body':{'success':!0x1,'completed':!0x0,'message':hC(hr.A)+(A['graphName']??'')+hC(hr.c)}};const a=typeof A[hC(0x111)]=='string'?A[hC(0x111)][hC(hr.a)]():void 0x0;if(c['requiresUserMessage']!==!0x1&&!a)return{'status':0x190,'body':{'success':!0x1,'completed':!0x1,'message':hC(hr.S)}};let S;try{S=A[hC(0xf5)]?w(A[hC(0xf5)]):Z();}catch(K){return{'status':0x190,'body':{'success':!0x1,'completed':!0x1,'message':K instanceof Error?K[hC(0x132)]:String(K)}};}const o=B(c),q=f(c),l={'graphId':o,'graphSchemaVersion':q,'llmConfig':c['llmConfig']},i=Y();if(this['inflightSessions'][hC(0x12c)](S))return this[hC(0x11c)](S,z,'Session\x20\x27'+S+hC(hr.t));this[hC(hr.g)]['add'](S);const P={'session':S,...A['signal']===void 0x0?{}:{'signal':A[hC(0x108)]}};return this[hC(0xf8)](P,i,async()=>{const hQ=hC;let H=!0x0,X,h0;try{const h1=Z(),h2=await this['sessions']['beginTurn'](S,h1,l);X=h1,h0=h2[hQ(0x129)];const h3=h2[hQ(0x12d)][hQ(hz.A)][hQ(hz.c)]?h2[hQ(hz.a)]:void 0x0;h3&&h3['graph'][hQ(hz.S)]!==q&&(H=!0x1);const h4=h3?c[hQ(hz.t)]?await c[hQ(0x12a)](h3):h3:void 0x0;if(h4&&h4['graph'][hQ(hz.g)]!==q)throw new Error('Graph\x20\x27'+o+hQ(hz.o)+h4[hQ(0x104)][hQ(0xfa)]+';\x20expected\x20'+q+'.');h3&&h4&&h4[hQ(0x104)]['schemaVersion']!==h3['graph']['schemaVersion']&&await this[hQ(0x12f)][hQ(hz.q)](h4,{'owner':h1,'expectedRevision':h0}),H=!0x0;const h5=h4?this[hQ(0x12f)][hQ(hz.l)](h4,o):void 0x0;if(h5?.[hQ(hz.i)])return await this[hQ(0x12f)][hQ(0x103)](S,h1,h0),this[hQ(hz.P)](c[hQ(0x110)],S);const h6={...a?c[hQ(0x116)](h5,new T(a)):h5??{},'config':{...h5?.[hQ(0xed)]??{},...A['config']??{}},'inputConsumed':!0x1,'response':''};let h7;if(c['graph'][hQ(0xf2)]){const h8=await c['graph'][hQ(0xf2)](h6,{'streamMode':hQ(hz.R)});for await(const h9 of h8){if(h7=h9,h7['inputConsumed']!==!0x0)continue;h0=(await this[hQ(0x12f)][hQ(hz.K)](S,h7,l,Y(),{'owner':h1,...h0===void 0x0?{}:{'expectedRevision':h0},'keepTurn':!0x0}))[hQ(0x10c)];}}else h7=await c['graph'][hQ(hz.H)](h6);if(!h7)throw new Error('Graph\x20\x27'+o+'\x27\x20completed\x20without\x20producing\x20state.');return await this[hQ(0x12f)][hQ(0x102)](S,h7,l,i,{'owner':h1,...h0===void 0x0?{}:{'expectedRevision':h0}}),c[hQ(hz.s)]===hQ(hz.v)?this['jsonResult'](S,h7['response']):this[hQ(0x125)](S,h7[hQ(hz.I)],h7[hQ(hz.X)]);}catch(hh){if(hh instanceof W)return this[hQ(0x11c)](S,hh['code'],hh['message']);const hm=hh instanceof Error?hh[hQ(hz.h0)]:String(hh);if(n({'chat_service':hm}),X)try{await this[hQ(hz.h1)][hQ(hz.h2)](S,X,l,H?i:void 0x0,h0);}catch(hT){console[hQ(0x117)]('Unable\x20to\x20persist\x20session\x20error\x20log:',hT);}return{'status':0x190,'session':S,'body':{'success':!0x1,'completed':!0x1,'message':hm,'session':S}};}finally{this[hQ(hz.h3)][hQ(hz.h4)](S);}});}[hU(0xf8)](A,c,a){return J(A,()=>e(c,a));}async['deleteSession'](A){const hp={A:0x113,c:0x132},hn=hU;if(!A)return{'status':0x190,'body':{'success':!0x1,'message':'SESSION_ID\x20is\x20required.'}};try{const c=w(A);return await this['sessions'][hn(hp.A)](c),{'status':0xc8,'body':{'success':!0x0,'session':c}};}catch(a){return{'status':0x190,'body':{'success':!0x1,'session':A,'message':a instanceof Error?a[hn(hp.c)]:String(a)}};}}async[hU(0x127)](){const hF={A:0x12f},hw=hU;await this[hw(hF.A)]['close']();}['conflictResult'](A,c,a){return{'status':0x199,'session':A,'body':{'success':!0x1,'completed':!0x1,'message':a,'code':c,'session':A}};}[hU(0x11d)](A,c){const hY=hU,a=hY(0x12e);return A===hY(0xef)?this['conflictResult'](c,r,a):this[hY(0x125)](c,a,!0x0);}[hU(0xf6)](A,c){return{'status':0xc8,'session':A,'contentType':'application/json','body':p(c)};}['chatResult'](A,c,a){return{'status':0xc8,'session':A,'body':{'success':!0x0,'completed':a,'message':c,'bot':c,'session':A}};}}function w(A){const hS={A:0x12b,c:0x10d},hx=hU,c=A[hx(0x109)]();if(!/^[A-Za-z0-9_-]{1,128}$/[hx(hS.A)](c))throw new Error(hx(hS.c));return c;}y(w,hU(0x123));export{M as GraphEngine};
1
+ const Kc=e;(function(d,X){const KQ={d:0xe0,X:0xdb,T:0xc1,g:0xb4},Kh=e,T=d();while(!![]){try{const g=parseInt(Kh(0xa0))/0x1+parseInt(Kh(KQ.d))/0x2+parseInt(Kh(KQ.X))/0x3+parseInt(Kh(KQ.T))/0x4+-parseInt(Kh(0xce))/0x5+parseInt(Kh(0xd6))/0x6+parseInt(Kh(KQ.g))/0x7*(-parseInt(Kh(0xa3))/0x8);if(g===X)break;else T['push'](T['shift']());}catch(p){T['push'](T['shift']());}}}(K,0x8258d));var P=Object['defineProperty'],y=(d,X)=>P(d,Kc(0xc5),{'value':X,'configurable':!0x0});import{HumanMessage as I}from'@langchain/core/messages';function K(){const KR=['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'];K=function(){return KR;};return K();}function e(j,C){j=j-0x9d;const I=K();let J=I[j];if(e['pjzpNm']===undefined){var F=function(c){const s='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+/=';let P='',n='';for(let o=0x0,z,H,t=0x0;H=c['charAt'](t++);~H&&(z=o%0x4?z*0x40+H:H,o++%0x4)?P+=String['fromCharCode'](0xff&z>>(-0x2*o&0x6)):0x0){H=s['indexOf'](H);}for(let E=0x0,q=P['length'];E<q;E++){n+='%'+('00'+P['charCodeAt'](E)['toString'](0x10))['slice'](-0x2);}return decodeURIComponent(n);};e['bOrkSb']=F,e['wJSDQu']={},e['pjzpNm']=!![];}const V=I[0x0],m=j+V,h=e['wJSDQu'][m];return!h?(J=e['bOrkSb'](J),e['wJSDQu'][m]=J):J=h,J;}import{randomUUID as J}from'node:crypto';import{GraphRegistry as m,registeredGraphId as h,registeredGraphSchemaVersion as c}from'./graph-registry.js';import{LangChainLlmGateway as s}from'./langchain-llm-gateway.js';import{SessionLogError as n,createSessionLogs as o,drainSessionLogs as t,restoreSessionLogs as D,withSessionLogs as Q}from'./session-log.js';import{withTurnContext as Z}from'./turn-context.js';import{SessionManager as b,SessionTurnError as u,SESSION_BUSY as r,SESSION_COMPLETED as S}from'./persistence/session-manager.js';import{parseJsonObjectResponse as f}from'./json-response.js';import{DecisionProviderRegistry as v}from'./decision/decision-provider.js';class M{static{y(this,'GraphEngine');}[Kc(0xe1)]=new m();[Kc(0x9f)];[Kc(0xa4)];['decisionProviders'];[Kc(0xe2)]=new Set();constructor(d={}){const KZ={d:0xc8,X:0xcf,T:0xcf,g:0xa4,p:0xde},Ks=Kc;this[Ks(0x9f)]=d[Ks(KZ.d)]??new b(),this[Ks(KZ.X)]=new v(d[Ks(KZ.T)]??[]),this['llmGatewayFactory']=d[Ks(KZ.g)]??(X=>new s(X,d[Ks(0xd5)]?{'providers':d[Ks(0xd5)]}:{})),this[Ks(KZ.p)](d['graphs']??[]);}static async[Kc(0xca)](d={}){const KO={d:0xc0,X:0xc0,T:0xd5,g:0xcf},KP=Kc,X=await b[KP(0xa2)](d['configManager']);return new M({'sessionManager':X,...d['llmGatewayFactory']?{'llmGatewayFactory':d[KP(0xa4)]}:{},...d[KP(KO.d)]?{'graphs':d[KP(KO.X)]}:{},...d[KP(KO.T)]?{'providers':d[KP(0xd5)]}:{},...d[KP(KO.g)]?{'decisionProviders':d['decisionProviders']}:{}});}[Kc(0xde)](d){const Ku={d:0xbe},Kb={d:0x9e,X:0xd0},Kn=Kc,X=d[Kn(Ku.d)](T=>{const Ko=Kn,g=new T(this[Ko(0xa4)](T[Ko(Kb.d)]()[Ko(0xe3)]));return g[Ko(Kb.X)]?.(p=>this['decisionProviders'][Ko(0xe7)](p)),g[Ko(0xba)],g;});return this[Kn(0xe1)]['register'](X),this;}[Kc(0xaa)](){return this['registry']['names']();}[Kc(0xe5)](d){const KA={d:0x9f},Kz=Kc;return this[Kz(KA.d)]['getSession'](w(d));}async[Kc(0xb9)](X){const Kr={d:0xcc,X:0xdd,T:0xab,g:0xa5,p:0xa6,a:0xe2,G:0xb5},Kx={d:0x9f,X:0xac,T:0xb7,g:0xba,p:0xa9,a:0xa9,G:0xa8,W:0xeb,Y:0xa8,L:0xea,i:0x9f,l:0xc4,K0:0xc2,K1:0xba,K2:0xba,K3:0xd7,K4:0xb1,K5:0xbc,K6:0xa1,K7:0xda,K8:0x9d,K9:0xe9,KK:0xdf},KH=Kc,T=this[KH(0xe1)][KH(0xb0)](X[KH(0xe4)]);if(!T)return{'status':0x190,'body':{'success':!0x1,'completed':!0x0,'message':'Graph\x20\x27'+(X['graphName']??'')+KH(Kr.d)}};const p=typeof X[KH(Kr.X)]==KH(0xc3)?X['userMessage'][KH(Kr.T)]():void 0x0;if(T[KH(0xd8)]!==!0x1&&!p)return{'status':0x190,'body':{'success':!0x1,'completed':!0x1,'message':KH(0xc7)}};let a;try{a=X[KH(0xd2)]?w(X['sessionId']):J();}catch(K0){return{'status':0x190,'body':{'success':!0x1,'completed':!0x1,'message':K0 instanceof Error?K0[KH(0xaf)]:String(K0)}};}const G=h(T),W=c(T),Y={'graphId':G,'graphSchemaVersion':W,'llmConfig':T['llmConfig']},L=o();if(this['inflightSessions']['has'](a))return this[KH(0xd4)](a,r,KH(Kr.g)+a+KH(Kr.p));this[KH(Kr.a)]['add'](a);const i={'session':a,...X[KH(0xb5)]===void 0x0?{}:{'signal':X[KH(Kr.G)]}};return this['withTurnScope'](i,L,async()=>{const Kt=KH;let K1=!0x0,K2,K3;try{const K4=J(),K5=await this[Kt(Kx.d)][Kt(Kx.X)](a,K4,Y);K2=K4,K3=K5[Kt(0xd9)];const K6=K5[Kt(Kx.T)][Kt(Kx.g)][Kt(0xc9)]?K5[Kt(0xb7)]:void 0x0;K6&&K6[Kt(0xba)][Kt(0xa8)]!==W&&(K1=!0x1);const K7=K6?T[Kt(Kx.p)]?await T[Kt(Kx.a)](K6):K6:void 0x0;if(K7&&K7[Kt(0xba)][Kt(Kx.G)]!==W)throw new Error(Kt(Kx.W)+G+Kt(0xbd)+K7[Kt(0xba)][Kt(Kx.Y)]+Kt(Kx.L)+W+'.');K6&&K7&&K7['graph'][Kt(0xa8)]!==K6[Kt(0xba)][Kt(Kx.G)]&&await this[Kt(Kx.d)]['persistMigratedSession'](K7,{'owner':K4,'expectedRevision':K3}),K1=!0x0;const K8=K7?this[Kt(Kx.d)][Kt(0xbf)](K7,G):void 0x0;if(K8?.[Kt(0xa1)])return await this[Kt(Kx.i)][Kt(0xc6)](a,K4,K3),this[Kt(0xae)](T[Kt(Kx.l)],a);const K9={...p?T[Kt(0xcd)](K8,new I(p)):K8??{},'config':{...K8?.[Kt(Kx.K0)]??{},...X[Kt(0xc2)]??{}},'inputConsumed':!0x1,'response':''};let KK;if(T['graph'][Kt(0xd3)]){const Ke=await T[Kt(Kx.K1)][Kt(0xd3)](K9,{'streamMode':'values'});for await(const Kj of Ke){if(KK=Kj,KK[Kt(0xe6)]!==!0x0)continue;const KC=t(L);let KI;try{KI=await this['sessions']['saveState'](a,KK,Y,KC,{'owner':K4,...K3===void 0x0?{}:{'expectedRevision':K3},'keepTurn':!0x0});}catch(KJ){throw D(L,KC),KJ;}K3=KI['revision'];}}else KK=await T[Kt(Kx.K2)][Kt(Kx.K3)](K9);if(!KK)throw new Error('Graph\x20\x27'+G+Kt(Kx.K4));return await this[Kt(Kx.d)][Kt(0xb2)](a,KK,Y,L,{'owner':K4,...K3===void 0x0?{}:{'expectedRevision':K3}}),T[Kt(0xc4)]===Kt(Kx.K5)?this[Kt(0xdc)](a,KK[Kt(0xcb)]):this['chatResult'](a,KK[Kt(0xcb)],KK[Kt(Kx.K6)]);}catch(KF){if(KF instanceof u)return this['conflictResult'](a,KF[Kt(Kx.K7)],KF['message']);const KV=KF instanceof Error?KF['message']:String(KF);if(n({'chat_service':KV}),K2)try{await this[Kt(0x9f)]['endFailedTurn'](a,K2,Y,K1?L:void 0x0,K3);}catch(Km){console[Kt(Kx.K8)](Kt(Kx.K9),Km);}return{'status':0x190,'session':a,'body':{'success':!0x1,'completed':!0x1,'message':KV,'session':a}};}finally{this['inflightSessions'][Kt(Kx.KK)](a);}});}[Kc(0xe8)](d,X,T){return Z(d,()=>Q(X,T));}async[Kc(0xb3)](d){const Kf={d:0xbb},KE=Kc;if(!d)return{'status':0x190,'body':{'success':!0x1,'message':KE(Kf.d)}};try{const X=w(d);return await this['sessions'][KE(0xb3)](X),{'status':0xc8,'body':{'success':!0x0,'session':X}};}catch(T){return{'status':0x190,'body':{'success':!0x1,'session':d,'message':T instanceof Error?T[KE(0xaf)]:String(T)}};}}async[Kc(0xad)](){const Kk=Kc;await this[Kk(0x9f)][Kk(0xad)]();}['conflictResult'](d,X,T){return{'status':0x199,'session':d,'body':{'success':!0x1,'completed':!0x1,'message':T,'code':X,'session':d}};}[Kc(0xae)](d,X){const Ky={d:0xd4},Kq=Kc,T='This\x20conversation\x20is\x20already\x20complete.';return d===Kq(0xbc)?this[Kq(Ky.d)](X,S,T):this['chatResult'](X,T,!0x0);}[Kc(0xdc)](d,X){const KD=Kc;return{'status':0xc8,'session':d,'contentType':KD(0xb6),'body':f(X)};}[Kc(0xb8)](d,X,T){return{'status':0xc8,'session':d,'body':{'success':!0x0,'completed':T,'message':X,'bot':X,'session':d}};}}function w(d){const KN={d:0xd1},KM=Kc,X=d[KM(0xab)]();if(!/^[A-Za-z0-9_-]{1,128}$/[KM(KN.d)](X))throw new Error('SESSION_ID\x20must\x20be\x201-128\x20letters,\x20numbers,\x20underscores,\x20or\x20hyphens.');return X;}y(w,Kc(0xa7));export{M as GraphEngine};
@@ -1 +1 @@
1
- var S=Object.defineProperty;var s=(n,e)=>S(n,"name",{value:e,configurable:!0});import"reflect-metadata";import{AIMessage as c}from"@langchain/core/messages";import{Command as w,isCommand as f}from"@langchain/langgraph";import{GraphLlm as d}from"./graph-llm.config.js";import{GraphStateSupport as N}from"./graph-state-support.js";import{ConversationRunner as C,DEFAULT_CONVERSATION_POLICY as T,DEFAULT_MAX_AGENT_ROUNDS as R,EmptyModelResponseError as E}from"./conversation-runner.js";import{currentTurnSignal as O}from"./turn-context.js";import{combineGraphNodeUpdates as A}from"./node-outcome.js";import{parseJsonObjectResponse as g}from"./json-response.js";import{stableClassId as y}from"./stable-id.js";import{SessionLogWarning as L}from"./session-log.js";import{isToolResponse as H,stay as b}from"./tool-response.js";import{invocationGraphState as I,hasNodeInvocation as G,invocationHistory as M,invocationNodeState as $,invocationUpdate as U,appendInvocationHistory as _,replaceInvocationNodeState as j,saveInvocationNodeState as P,withNodeInvocation as x}from"./node-invocation.js";import{GRAPH_NODE_LOCAL_STATE as le}from"./node-outcome.js";const J=Symbol("GRAPH_NODE_CLASS"),m=Symbol("graph-node-tool-handlers");function se(n){if(!n.trim())throw new Error("A tool handler requires a tool name.");return(e,t)=>{const o=Reflect.getOwnMetadata(m,e)??[];if(o.some(r=>r.toolName===n))throw new Error(`Tool '${n}' already has a handler.`);o.push({toolName:n,methodName:t}),Reflect.defineMetadata(m,o,e)}}s(se,"Tool");class v{static{s(this,"GraphNode")}llmGateway;runtime;static[J]=!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=y(o,"graph node")}get graph(){return this.runtime}defineTool(){return[]}getLlmConfig(){return{}}route(e){throw new Error(`Graph node '${this.id}' does not define a branch route.`)}async handleTool(e,t,o){const r=this.toolHandler(t.name);if(!r)return this.rejectToolCall(t.name,`Unsupported tool '${t.name}'.`);const h=this.runtime.requireTool(r.toolName),i=q(t.args);if(!i.ok)return this.rejectToolCall(r.toolName,i.error);const a=h.schema.safeParse(i.value);if(!a.success)return this.rejectToolCall(r.toolName,F(a.error));const l=a.data,p=this[r.methodName];if(!p)throw new Error(`Tool '${r.toolName}' is decorated on missing method '${String(r.methodName)}'.`);const u=await p.call(this,l,o,e);if(H(u))return u;throw new Error(`Tool '${r.toolName}' on '${this.id}' must return a ToolResponse.`)}rejectToolCall(e,t){return L({tool_call:t,node:this.id,tool:e}),b(JSON.stringify({accepted:!1,error:t}))}onInvalidJsonResponse(e){throw e.error}onEmptyModelResponse(e){throw new E(e.reason)}invoke=s(e=>this.runtime.withInvocation(this.id,e,async()=>{const t=await this.run(e),o=k(t),r=await this.resolveJsonResponse(e,o);this.runtime.stageNodeEntries(r.nodes);const h=this.runtime.resolveLlmConfig(this.getLlmConfig()),i=D(h,this.runtime.resolveLlmConfig()),a=(e.nodes??{})[this.id];(!i||a?.model!==void 0)&&this.runtime.saveNode(this.id,{model:i?void 0:d.modelMetadata(h)});const l=A(r,this.runtime.stagedUpdate());return f(t)?new w({update:l,...t.goto===void 0?{}:{goto:t.goto},...t.graph===void 0?{}:{graph:t.graph},...t.resume===void 0?{}:{resume:t.resume}}):l}),"invoke");obtainTools(){return this.toolHandlers().map(({toolName:e})=>this.runtime.requireTool(e)).sort((e,t)=>e.name==="terminate_session"?1:t.name==="terminate_session"?-1:0)}validateTools(){this.obtainTools()}llmConfig(){return this.runtime.resolveLlmConfig(this.getLlmConfig())}llmCallOptions(){return this.runtime.llmCallOptions()}async runConversation(e,t){const o=await this.runAgentLoop(e,t);if(!o.stopReason)return o;const r=await this.onEmptyModelResponse({state:e,conversation:o,reason:o.stopReason});return{...o,response:r}}runAgentLoop(e,t){return new C(this.llmGateway).run({systemPrompt:this.getPrompt(e),history:this.history(e),tools:this.obtainTools(),llmConfig:this.llmConfig(),executeTool:s(o=>this.handleTool(e,o,t),"executeTool"),maxAgentRounds:this.runtime.maxAgentRounds,emptyHistorySeed:this.runtime.conversationPolicy.emptyHistorySeed,emptyResponseRecovery:this.runtime.conversationPolicy.emptyResponseRecovery,callOptions:this.llmCallOptions()})}historySpace(){return this.runtime.historySpace(this.id)}history(e){return this.runtime.hasInvocation()?this.runtime.invocationHistory(this.historySpace()):e.histories[this.historySpace()]??[]}historyUpdate(e){return{histories:{[this.historySpace()]:e}}}respond(e){return{...this.runtime.respond(e),...this.historyUpdate([new c(e)])}}complete(e){return{...this.runtime.complete(e),...this.historyUpdate([new c(e)])}}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 g(t.response??""),t}catch(o){const r=await this.onInvalidJsonResponse({state:e,update:t,response:t.response??"",error:o instanceof Error?o:new Error(String(o))});return(r.completed===!0||r.response)&&g(r.response??""),r}}toolHandlers(){let e=Object.getPrototypeOf(this);const t=[];for(;e&&e!==v.prototype;){const r=Reflect.getOwnMetadata(m,e)??[];t.push(...r),e=Object.getPrototypeOf(e)}const o=new Set;for(const r of t){if(o.has(r.toolName))throw new Error(`Graph node '${this.id}' has more than one handler for tool '${r.toolName}'.`);o.add(r.toolName)}return t}}function D(n,e){return n.model===e.model&&JSON.stringify(d.parameters(n))===JSON.stringify(d.parameters(e))}s(D,"sameLlmConfig");class ie extends N{static{s(this,"GraphNodeRuntime")}defaultLlmConfig;historySpaces;initialHistorySpace;responseMode;maxAgentRounds;conversationPolicy;tools=new Map;constructor(e,t,o={},r="default",h="chat",i=R,a=T){super(e),this.defaultLlmConfig=t,this.historySpaces=o,this.initialHistorySpace=r,this.responseMode=h,this.maxAgentRounds=i,this.conversationPolicy=a}llmCallOptions(){const{llmTimeoutMs:e}=this.conversationPolicy,t=O();return{...e===void 0?{}:{timeoutMs:e},...t===void 0?{}:{signal:t}}}expectsJsonResponse(){return this.responseMode==="json"}historySpace(e){return e?this.historySpaces[e]??this.initialHistorySpace:this.initialHistorySpace}resolveLlmConfig(e={}){return d.resolveConfig(this.defaultLlmConfig,e)}registerTools(e,t){for(const o of t){const r=this.tools.get(o.name);if(r)throw new Error(`Tool '${o.name}' is defined by both '${r.owner}' and '${e}'.`);this.tools.set(o.name,{definition:o,owner:e})}}requireTool(e){const t=this.tools.get(e);if(!t)throw new Error(`Tool '${e}' is not defined in this graph.`);return t.definition}input(e){return this.latestInput({messages:e.histories[this.historySpace(e.currentNode)]??[]})}respond(e){return this.responseUpdate(e)}complete(e){return this.endUpdate(e)}withInvocation(e,t,o){return x(this,e,t,o)}nodeState(e){return $(this,e)}hasInvocation(){return G(this)}graphState(){return I(this)}appendHistory(e,t){_(this,e,t)}invocationHistory(e){return M(this,e)}stagedUpdate(){return U(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 P(this,e,t),{nodes:{[e]:this.nodeState(e)}}}saveNodeState(e,t){this.saveNode(y(e,"graph node"),t)}removeNode(e,...t){return this.saveNode(e,Object.fromEntries(t.map(o=>[o,void 0])))}}function k(n){if(!f(n))return n;if(Array.isArray(n.update))throw new Error("GraphNode Command updates must be state objects.");return n.update??{}}s(k,"commandUpdate");function q(n){if(typeof n!="string")return{ok:!0,value:n};try{return{ok:!0,value:JSON.parse(n)}}catch(e){return{ok:!1,error:`Tool arguments were not valid JSON: ${e instanceof Error?e.message:String(e)}`}}}s(q,"coerceToolArgs");function F(n){return n.issues.map(e=>e.path.length>0?`${e.path.join(".")}: ${e.message}`:e.message).join("; ")}s(F,"formatToolArgumentError");export{J as GRAPH_NODE_CLASS,le as GRAPH_NODE_LOCAL_STATE,v as GraphNode,ie as GraphNodeRuntime,se as Tool};
1
+ var E=Object.defineProperty;var i=(n,e)=>E(n,"name",{value:e,configurable:!0});import"reflect-metadata";import{AIMessage as p,HumanMessage as R}from"@langchain/core/messages";import{Command as c,END as u,isCommand as w}from"@langchain/langgraph";import{GraphLlm as m}from"./graph-llm.config.js";import{GraphStateSupport as T}from"./graph-state-support.js";import{ConversationRunner as O,DEFAULT_CONVERSATION_POLICY as H,DEFAULT_MAX_AGENT_ROUNDS as $,EmptyModelResponseError as A}from"./conversation-runner.js";import{currentTurnSignal as b}from"./turn-context.js";import{combineGraphNodeUpdates as G}from"./node-outcome.js";import{parseJsonObjectResponse as S}from"./json-response.js";import{stableClassId as f}from"./stable-id.js";import{SessionLogWarning as k}from"./session-log.js";import{isToolResponse as N,stay as L}from"./tool-response.js";import{invocationGraphState as I,hasNodeInvocation as M,invocationHistory as P,invocationNodeState as _,invocationUpdate as D,appendInvocationHistory as U,replaceInvocationNodeState as j,saveInvocationNodeState as x,withNodeInvocation as J}from"./node-invocation.js";import{DecisionConfigurationError as q,resolveDecisionOptions as F}from"./decision/decision-types.js";import{GRAPH_NODE_LOCAL_STATE as fe}from"./node-outcome.js";const z=Symbol("GRAPH_NODE_CLASS"),g=Symbol("graph-node-tool-handlers");function ce(n){if(!n.trim())throw new Error("A tool handler requires a tool name.");return(e,t)=>{const o=Reflect.getOwnMetadata(g,e)??[];if(o.some(r=>r.toolName===n))throw new Error(`Tool '${n}' already has a handler.`);o.push({toolName:n,methodName:t}),Reflect.defineMetadata(g,o,e)}}i(ce,"Tool");class C{static{i(this,"GraphNode")}llmGateway;runtime;static[z]=!0;static id(){return this.name}name;id;constructor(e,t){this.llmGateway=e,this.runtime=t;const o=new.target;this.name=o.name,this.id=f(o,"graph node")}get graph(){return this.runtime}defineTool(){return[]}getLlmConfig(){return{}}route(e){throw new Error(`Graph node '${this.id}' does not define a branch route.`)}async handleTool(e,t,o){const r=this.toolHandler(t.name);if(!r)return this.rejectToolCall(t.name,`Unsupported tool '${t.name}'.`);const d=this.runtime.requireTool(r.toolName),s=X(t.args);if(!s.ok)return this.rejectToolCall(r.toolName,s.error);const a=d.schema.safeParse(s.value);if(!a.success)return this.rejectToolCall(r.toolName,Y(a.error));const h=a.data,l=this[r.methodName];if(!l)throw new Error(`Tool '${r.toolName}' is decorated on missing method '${String(r.methodName)}'.`);const v=await l.call(this,h,o,e);if(N(v))return v;throw new Error(`Tool '${r.toolName}' on '${this.id}' must return a ToolResponse.`)}rejectToolCall(e,t){return k({tool_call:t,node:this.id,tool:e}),L(JSON.stringify({accepted:!1,error:t}))}usesChatModel(){return!0}onInvalidJsonResponse(e){throw e.error}onEmptyModelResponse(e){throw new A(e.reason)}invoke=i(e=>this.runtime.withInvocation(this.id,e,async()=>{const t=this.resolveNodeResponse(await this.run(e)),o=W(t),r=await this.resolveJsonResponse(e,o);if(this.runtime.stageNodeEntries(r.nodes),this.usesChatModel()){const s=this.runtime.resolveLlmConfig(this.getLlmConfig()),a=V(s,this.runtime.resolveLlmConfig()),h=(e.nodes??{})[this.id];(!a||h?.model!==void 0)&&this.runtime.saveNode(this.id,{model:a?void 0:m.modelMetadata(s)})}const d=G(r,this.runtime.stagedUpdate());return w(t)?new c({update:d,...t.goto===void 0?{}:{goto:t.goto},...t.graph===void 0?{}:{graph:t.graph},...t.resume===void 0?{}:{resume:t.resume}}):d}),"invoke");obtainTools(){return this.toolHandlers().map(({toolName:e})=>this.runtime.requireTool(e)).sort((e,t)=>e.name==="terminate_session"?1:t.name==="terminate_session"?-1:0)}validateTools(){this.obtainTools()}llmConfig(){return this.runtime.resolveLlmConfig(this.getLlmConfig())}llmCallOptions(){return this.runtime.llmCallOptions()}async runConversation(e,t){const o=await this.runAgentLoop(e,t);if(!o.stopReason)return o;const r=await this.onEmptyModelResponse({state:e,conversation:o,reason:o.stopReason});return{...o,response:r}}runAgentLoop(e,t){return new O(this.llmGateway).run({systemPrompt:this.getPrompt(e),history:this.history(e),tools:this.obtainTools(),llmConfig:this.llmConfig(),executeTool:i(o=>this.handleTool(e,o,t),"executeTool"),maxAgentRounds:this.runtime.maxAgentRounds,emptyHistorySeed:this.runtime.conversationPolicy.emptyHistorySeed,emptyResponseRecovery:this.runtime.conversationPolicy.emptyResponseRecovery,callOptions:this.llmCallOptions()})}historySpace(){return this.runtime.historySpace(this.id)}history(e){return this.runtime.hasInvocation()?this.runtime.invocationHistory(this.historySpace()):e.histories[this.historySpace()]??[]}historyUpdate(e){return{histories:{[this.historySpace()]:e}}}respond(e){return{...this.runtime.respond(e),...this.historyUpdate([new p(e)])}}complete(e){return{...this.runtime.complete(e),...this.historyUpdate([new p(e)])}}resolveNodeResponse(e){if(!N(e))return e;if(e.kind==="stay")throw new Error(`Graph node '${this.id}' can only return stay() from a tool handler.`);if(e.cleanup)throw new Error(`Graph node '${this.id}' can only use withCleanup() from a tool handler.`);if(e.feedback!==void 0)throw new Error(`Graph node '${this.id}' can only use withToolFeedback() from a tool handler.`);if(e.messages&&this.graph.appendHistory(this.historySpace(),e.messages),e.kind==="go"||e.kind==="directTo"){if(!e.target)throw new Error(`Graph node '${this.id}' selected ${e.kind}() without a target.`);const t=f(e.target,"graph node"),o=this.graph.historySpace(t);if(e.state&&this.graph.saveNodeState(e.target,e.state),e.message&&this.graph.appendHistory(o,[e.message]),e.kind==="directTo"){const r=y(this.id,e);return this.graph.appendHistory(o,[new p(r)]),new c({update:{currentNode:t,response:r,inputConsumed:!0,completed:!1,...e.usage===void 0?{}:{tokens:e.usage}},goto:u})}return new c({update:{currentNode:t,response:"",inputConsumed:!0,completed:!1,...e.usage===void 0?{}:{tokens:e.usage}},goto:t})}if(e.message)throw new Error(`Graph node '${this.id}' can only use withMessage() with go() or directTo().`);if(e.kind==="direct"){const t=y(this.id,e);return this.graph.appendHistory(this.historySpace(),[new p(t)]),new c({update:{currentNode:this.id,response:t,inputConsumed:!0,completed:!1,...e.usage===void 0?{}:{tokens:e.usage}},goto:u})}if(e.kind==="finish"){const t=y(this.id,e);return this.graph.appendHistory(this.historySpace(),[new p(t)]),new c({update:{...this.graph.complete(t),...e.usage===void 0?{}:{tokens:e.usage}},goto:u})}throw new Error(`Graph node '${this.id}' returned an unsupported response kind '${e.kind}'.`)}state(e){return this.runtime.hasInvocation()?this.runtime.nodeState(this.id):e.nodes[this.id]??{}}getState(){return this.runtime.nodeState(this.id)}saveState(e){this.runtime.saveNode(this.id,e)}save(e){return this.runtime.saveNode(this.id,e)}remove(...e){return this.runtime.removeNode(this.id,...e)}toolHandler(e){return this.toolHandlers().find(t=>t.toolName===e)}async resolveJsonResponse(e,t){if(!this.runtime.expectsJsonResponse()||t.completed!==!0)return t;try{return S(t.response??""),t}catch(o){const r=await this.onInvalidJsonResponse({state:e,update:t,response:t.response??"",error:o instanceof Error?o:new Error(String(o))});return(r.completed===!0||r.response)&&S(r.response??""),r}}toolHandlers(){let e=Object.getPrototypeOf(this);const t=[];for(;e&&e!==C.prototype;){const r=Reflect.getOwnMetadata(g,e)??[];t.push(...r),e=Object.getPrototypeOf(e)}const o=new Set;for(const r of t){if(o.has(r.toolName))throw new Error(`Graph node '${this.id}' has more than one handler for tool '${r.toolName}'.`);o.add(r.toolName)}return t}}function V(n,e){return n.model===e.model&&JSON.stringify(m.parameters(n))===JSON.stringify(m.parameters(e))}i(V,"sameLlmConfig");class le extends T{static{i(this,"GraphNodeRuntime")}defaultLlmConfig;historySpaces;initialHistorySpace;responseMode;maxAgentRounds;conversationPolicy;decisionOptions;decisionErrorHandler;tools=new Map;constructor(e,t,o={},r="default",d="chat",s=$,a=H,h={},l){super(e),this.defaultLlmConfig=t,this.historySpaces=o,this.initialHistorySpace=r,this.responseMode=d,this.maxAgentRounds=s,this.conversationPolicy=a,this.decisionOptions=h,this.decisionErrorHandler=l}llmCallOptions(){const{llmTimeoutMs:e}=this.conversationPolicy,t=b();return{...e===void 0?{}:{timeoutMs:e},...t===void 0?{}:{signal:t}}}expectsJsonResponse(){return this.responseMode==="json"}historySpace(e){return e?this.historySpaces[e]??this.initialHistorySpace:this.initialHistorySpace}resolveLlmConfig(e={}){return m.resolveConfig(this.defaultLlmConfig,e)}resolveDecisionOptions(e={}){return F(this.decisionOptions,e)}decisionProviderResolver;attachDecisionProviderResolver(e){this.decisionProviderResolver=e}resolveDecisionProvider(e){if(!this.decisionProviderResolver)throw new q(`Decision provider '${e}' cannot be resolved before the graph is attached to an engine.`);return this.decisionProviderResolver(e)}async handleDecisionError(e){return await this.decisionErrorHandler?.(e)??null}registerTools(e,t){for(const o of t){const r=this.tools.get(o.name);if(r)throw new Error(`Tool '${o.name}' is defined by both '${r.owner}' and '${e}'.`);this.tools.set(o.name,{definition:o,owner:e})}}requireTool(e){const t=this.tools.get(e);if(!t)throw new Error(`Tool '${e}' is not defined in this graph.`);return t.definition}input(e){return this.latestInput({messages:e.histories[this.historySpace(e.currentNode)]??[]})}getConversation(e){const o=(this.hasInvocation()?this.invocationHistory(e):[]).filter(r=>R.isInstance(r)&&r.additional_kwargs?.ezgraphInternal!==!0).map(r=>typeof r.content=="string"?r.content:JSON.stringify(r.content));return{request:o.at(-1)??"",priorRequests:o.slice(-5,-1)}}respond(e){return this.responseUpdate(e)}complete(e){return this.endUpdate(e)}withInvocation(e,t,o){return J(this,e,t,o)}nodeState(e){return _(this,e)}hasInvocation(){return M(this)}graphState(){return I(this)}appendHistory(e,t){U(this,e,t)}invocationHistory(e){return P(this,e)}stagedUpdate(){return D(this)}stageNodeEntries(e){for(const[t,o]of Object.entries(e??{}))!o||typeof o!="object"||Array.isArray(o)||j(this,t,o)}saveNode(e,t){return x(this,e,t),{nodes:{[e]:this.nodeState(e)}}}saveNodeState(e,t){this.saveNode(f(e,"graph node"),t)}removeNode(e,...t){return this.saveNode(e,Object.fromEntries(t.map(o=>[o,void 0])))}}function W(n){if(!w(n))return n;if(Array.isArray(n.update))throw new Error("GraphNode Command updates must be state objects.");return n.update??{}}i(W,"commandUpdate");function y(n,e){if(!e.response?.trim())throw new Error(`Graph node '${n}' selected ${e.kind}() without a response.`);return e.response}i(y,"requireNodeResponse");function X(n){if(typeof n!="string")return{ok:!0,value:n};try{return{ok:!0,value:JSON.parse(n)}}catch(e){return{ok:!1,error:`Tool arguments were not valid JSON: ${e instanceof Error?e.message:String(e)}`}}}i(X,"coerceToolArgs");function Y(n){return n.issues.map(e=>e.path.length>0?`${e.path.join(".")}: ${e.message}`:e.message).join("; ")}i(Y,"formatToolArgumentError");export{z as GRAPH_NODE_CLASS,fe as GRAPH_NODE_LOCAL_STATE,C as GraphNode,le as GraphNodeRuntime,ce as Tool};
@@ -1 +1 @@
1
- var c=Object.defineProperty;var e=(u,n)=>c(u,"name",{value:n,configurable:!0});import{Annotation as o,messagesStateReducer as s}from"@langchain/langgraph";import{replaceNodeStates as a}from"./node-state.js";import{addTokenUsage as f,emptyTokenUsage as m}from"./token-usage.js";const k="end";function A(u,n){return o.Root({histories:o({reducer:e((t,r)=>i(t??{},r??{}),"reducer"),default:e(()=>({}),"default")}),currentNode:o({reducer:e((t,r)=>r,"reducer"),default:e(()=>u,"default")}),config:o({reducer:e((t,r)=>({...t,...r}),"reducer"),default:e(()=>({}),"default")}),nodes:o({reducer:a,default:e(()=>n?n():{},"default")}),tokens:o({reducer:f,default:m}),inputConsumed:o({reducer:e((t,r)=>r,"reducer"),default:e(()=>!1,"default")}),response:o({reducer:e((t,r)=>r,"reducer"),default:e(()=>"","default")}),completed:o({reducer:e((t,r)=>r,"reducer"),default:e(()=>!1,"default")})})}e(A,"createGraphStateAnnotation");function i(u,n){const t={...u};for(const[r,d]of Object.entries(n))t[r]=s(t[r]??[],d);return t}e(i,"mergeHistories");export{k as GRAPH_END_NODE,A as createGraphStateAnnotation};
1
+ var u=Object.defineProperty;var e=(d,n)=>u(d,"name",{value:n,configurable:!0});import{Annotation as o,messagesStateReducer as c}from"@langchain/langgraph";import{replaceNodeStates as a}from"./node-state.js";import{addTokenUsage as f,emptyTokenUsage as i}from"./token-usage.js";import{addDecisionUsage as m,emptyDecisionUsage as p}from"./decision/decision-types.js";const A="end";function N(d,n){return o.Root({histories:o({reducer:e((t,r)=>l(t??{},r??{}),"reducer"),default:e(()=>({}),"default")}),currentNode:o({reducer:e((t,r)=>r,"reducer"),default:e(()=>d,"default")}),config:o({reducer:e((t,r)=>({...t,...r}),"reducer"),default:e(()=>({}),"default")}),nodes:o({reducer:a,default:e(()=>n?n():{},"default")}),tokens:o({reducer:f,default:i}),decisionUsage:o({reducer:m,default:p}),inputConsumed:o({reducer:e((t,r)=>r,"reducer"),default:e(()=>!1,"default")}),response:o({reducer:e((t,r)=>r,"reducer"),default:e(()=>"","default")}),completed:o({reducer:e((t,r)=>r,"reducer"),default:e(()=>!1,"default")})})}e(N,"createGraphStateAnnotation");function l(d,n){const t={...d};for(const[r,s]of Object.entries(n))t[r]=c(t[r]??[],s);return t}e(l,"mergeHistories");export{A as GRAPH_END_NODE,N as createGraphStateAnnotation};
@@ -1 +1 @@
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=T;(function(E,Q){const F={E:0x17a,Q:0x16b,n:0x178,w:0x166},z=T,n=E();while(!![]){try{const w=parseInt(z(0x173))/0x1+-parseInt(z(0x17c))/0x2+-parseInt(z(F.E))/0x3+-parseInt(z(F.Q))/0x4+parseInt(z(F.n))/0x5+parseInt(z(F.w))/0x6*(parseInt(z(0x174))/0x7)+parseInt(z(0x16c))/0x8*(parseInt(z(0x175))/0x9);if(w===Q)break;else n['push'](n['shift']());}catch(Y){n['push'](n['shift']());}}}(h,0xb9e87));var s=Object['defineProperty'],l=(E,Q)=>s(E,r(0x171),{'value':Q,'configurable':!0x0});import{GraphLlm as N,ModelCatalog as U}from'./graph-llm.config.js';function T(m,N){m=m-0x165;const U=h();let Z=U[m];if(T['uapbbH']===undefined){var d=function(C){const Q='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+/=';let n='',w='';for(let Y=0x0,x,e,J=0x0;e=C['charAt'](J++);~e&&(x=Y%0x4?x*0x40+e:e,Y++%0x4)?n+=String['fromCharCode'](0xff&x>>(-0x2*Y&0x6)):0x0){e=Q['indexOf'](e);}for(let u=0x0,D=n['length'];u<D;u++){w+='%'+('00'+n['charCodeAt'](u)['toString'](0x10))['slice'](-0x2);}return decodeURIComponent(w);};T['ujitrk']=d,T['tGlJwF']={},T['uapbbH']=!![];}const B=U[0x0],E=m+B,f=T['tGlJwF'][E];return!f?(Z=T['ujitrk'](Z),T['tGlJwF'][E]=Z):Z=f,Z;}import{modelProviderAdapter as Z}from'./model-provider.js';import{OPENAI_AUTH_PROVIDER as d,initializeOpenAIAuthProvider as B}from'./openai-auth-provider.js';function C(E,Q=[]){const A={E:0x17e,Q:0x17d,n:0x165,w:0x167,Y:0x16d,x:0x16e,e:0x170,J:0x16a,D:0x16e},b=r,w=N[b(A.E)](E),Y=U[b(A.Q)](w),x={};for(const [D,W]of Object[b(0x17f)](w[b(A.n)])){const k=Y[b(A.w)][D];k!==null&&u(x,k??D,W);}if(Y[b(0x16e)]===d)return B(Y[b(A.Y)],x);const J=Z(Y[b(A.x)],Q)??Y[b(A.e)];return J?J[b(A.J)]({'provider':Y[b(A.D)],'model':Y[b(A.Y)],'options':x}):{'model':Y[b(A.Y)],'options':{'modelProvider':Y[b(0x16e)],...x}};}l(C,r(0x169));function u(E,Q,w){const a={E:0x16f,Q:0x17b,n:0x176,w:0x179},p=r,Y=Q[p(0x177)]('.');let x=E;for(const D of Y[p(0x172)](0x0,-0x1)){const W=x[D];if(W===void 0x0){const k={};x[D]=k,x=k;}else{if(typeof W==p(a.E)&&W!==null&&!Array[p(a.Q)](W))x=W;else throw new Error(p(a.n)+Q+'\x27\x20has\x20a\x20conflicting\x20path.');}}const J=Y['at'](-0x1);if(!J)throw new Error(p(a.w));x[J]=w;}l(u,r(0x168));export{C as langChainModelInitialization};
1
+ function K(){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'];K=function(){return r;};return K();}const Z=e;(function(h,P){const U={h:0x17a,P:0x16b,n:0x178,o:0x166},Q=e,n=h();while(!![]){try{const o=parseInt(Q(0x173))/0x1+-parseInt(Q(0x17c))/0x2+-parseInt(Q(U.h))/0x3+-parseInt(Q(U.P))/0x4+parseInt(Q(U.n))/0x5+parseInt(Q(U.o))/0x6*(parseInt(Q(0x174))/0x7)+parseInt(Q(0x16c))/0x8*(parseInt(Q(0x175))/0x9);if(o===P)break;else n['push'](n['shift']());}catch(z){n['push'](n['shift']());}}}(K,0xb9e87));var s=Object['defineProperty'],l=(h,P)=>s(h,Z(0x171),{'value':P,'configurable':!0x0});import{GraphLlm as j,ModelCatalog as I}from'./graph-llm.config.js';function e(j,C){j=j-0x165;const I=K();let J=I[j];if(e['uapbbH']===undefined){var F=function(c){const s='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+/=';let P='',n='';for(let o=0x0,z,H,t=0x0;H=c['charAt'](t++);~H&&(z=o%0x4?z*0x40+H:H,o++%0x4)?P+=String['fromCharCode'](0xff&z>>(-0x2*o&0x6)):0x0){H=s['indexOf'](H);}for(let E=0x0,q=P['length'];E<q;E++){n+='%'+('00'+P['charCodeAt'](E)['toString'](0x10))['slice'](-0x2);}return decodeURIComponent(n);};e['ujitrk']=F,e['tGlJwF']={},e['uapbbH']=!![];}const V=I[0x0],m=j+V,h=e['tGlJwF'][m];return!h?(J=e['ujitrk'](J),e['tGlJwF'][m]=J):J=h,J;}import{modelProviderAdapter as J}from'./model-provider.js';import{OPENAI_AUTH_PROVIDER as F,initializeOpenAIAuthProvider as V}from'./openai-auth-provider.js';function C(h,P=[]){const A={h:0x17e,P:0x17d,n:0x165,o:0x167,z:0x16d,H:0x16e,t:0x170,E:0x16a,k:0x16e},O=Z,z=j[O(A.h)](h),H=I[O(A.P)](z),E={};for(const [q,D]of Object[O(0x17f)](z[O(A.n)])){const M=H[O(A.o)][q];M!==null&&u(E,M??q,D);}if(H[O(0x16e)]===F)return V(H[O(A.z)],E);const k=J(H[O(A.H)],P)??H[O(A.t)];return k?k[O(A.E)]({'provider':H[O(A.k)],'model':H[O(A.z)],'options':E}):{'model':H[O(A.z)],'options':{'modelProvider':H[O(0x16e)],...E}};}l(C,Z(0x169));function u(h,P,z){const x={h:0x16f,P:0x17b,n:0x176,o:0x179},b=Z,H=P[b(0x177)]('.');let E=h;for(const q of H[b(0x172)](0x0,-0x1)){const D=E[q];if(D===void 0x0){const M={};E[q]=M,E=M;}else{if(typeof D==b(x.h)&&D!==null&&!Array[b(x.P)](D))E=D;else throw new Error(b(x.n)+P+'\x27\x20has\x20a\x20conflicting\x20path.');}}const k=H['at'](-0x1);if(!k)throw new Error(b(x.o));E[k]=z;}l(u,Z(0x168));export{C as langChainModelInitialization};
@@ -1 +1 @@
1
- const hu=d;(function(S,L){const m6={S:0x1d9,L:0x1ef,t:0x1cb,g:0x224,o:0x1f3,l:0x1cd,O:0x1da},hJ=d,t=S();while(!![]){try{const g=-parseInt(hJ(m6.S))/0x1+-parseInt(hJ(0x1d7))/0x2*(parseInt(hJ(m6.L))/0x3)+-parseInt(hJ(m6.t))/0x4+-parseInt(hJ(0x220))/0x5+-parseInt(hJ(m6.g))/0x6*(-parseInt(hJ(m6.o))/0x7)+parseInt(hJ(0x1a8))/0x8*(parseInt(hJ(m6.l))/0x9)+parseInt(hJ(m6.O))/0xa*(parseInt(hJ(0x228))/0xb);if(g===L)break;else t['push'](t['shift']());}catch(o){t['push'](t['shift']());}}}(N,0x71173));var z=Object[hu(0x1a0)],c=(S,L)=>z(S,'name',{'value':L,'configurable':!0x0});import{mapChatMessagesToStoredMessages as n,mapStoredMessagesToChatMessages as Y}from'@langchain/core/messages';import{BaseGraph as x}from'../base-graph.js';import{ConfigManager as e}from'../config-manager.js';import{GRAPH_END_NODE as u}from'../graph-state.js';import{GraphLlm as D}from'../graph-llm.config.js';import{replaceNodeStates as r}from'../node-state.js';import{createSessionLogs as b}from'../session-log.js';import{emptyTokenUsage as F,normalizeTokenUsage as A}from'../token-usage.js';import{assertGraphSchemaVersion as a}from'../stable-id.js';const h=0x10,w=hu(0x1fb),$='SESSION_CONFLICT',we=hu(0x1b9);class f extends Error{static{c(this,'SessionTurnError');}[hu(0x1fd)];constructor(S,L){const m7={S:0x22d},hD=hu;super(L),this[hD(0x1b2)]=hD(m7.S),this['code']=S;}}class C{static{c(this,'SessionManager');}[hu(0x23e)];[hu(0x20d)];constructor(S=new q(),L=j()){const m8={S:0x20d},hW=hu;this['container']=S,this[hW(m8.S)]=L;}static async[hu(0x1af)](h0=new e()){const m9={S:0x206,L:0x20c,t:0x1e8,g:0x245,o:0x1dd,l:0x1e1,O:0x241,i:0x225,K:0x218,H:0x1fc,s:0x1b8,v:0x1a2,M:0x1d4,h0:0x1eb,h1:0x1c9,h2:0x1d0,h3:0x23d,h4:0x21a,h5:0x211,h6:0x235,h7:0x233,h8:0x1ed,h9:0x1e9,hh:0x242,hm:0x1c0,hT:0x210},hk=hu,h1=h0[hk(0x1e8)](hk(m9.S),'memory')[hk(m9.L)]()['toLowerCase'](),h2=j(h0[hk(m9.t)](hk(m9.g)));if(h1===hk(0x202))return new C(new q(),h2);if(h1===hk(0x205)){const {SqliteSessionDocumentContainer:hf}=await import(hk(m9.o));return new C(new hf(h0['get'](hk(m9.l),'./data/sessions.sqlite')),h2);}if(h1===hk(m9.O)||h1===hk(0x1f2)){const hC=p(h0,'MONGODB_URL'),hQ=p(h0,hk(0x22a)),hn=p(h0,'MONGODB_COLLECTION');if(!hC||!hQ||!hn)throw new Error(hk(m9.i));const [{MongoClient:hw},{MongoDbSessionDocumentContainer:hY}]=await Promise[hk(m9.K)]([import(hk(0x241)),import('./mongodb-session-document.container.js')]),hx=new hw(hC);await hx[hk(0x1c8)]();const he=hx['db'](hQ)[hk(m9.H)](hn);return await he['createIndex']({'id':0x1},{'unique':!0x0}),new C(new hY(he,hx),h2);}if(h1!==hk(0x1c2)&&h1!==hk(0x232))throw new Error('Unsupported\x20SESSION_STORE\x20\x27'+h1+hk(m9.s));const h3=p(h0,hk(m9.v),hk(m9.M),'COSMODB_URL'),h4=p(h0,hk(m9.h0),hk(m9.h1)),h5=p(h0,hk(m9.h2)),h6=p(h0,hk(m9.h3)),h7=p(h0,'COSMO_DB_CLIENT_SECRET'),h8=p(h0,hk(m9.h4),hk(m9.h5),'COSMODB_ID')??'langgraph',h9=p(h0,hk(m9.h6),hk(0x22e),hk(0x212))??'sessions';if(!h3||!h4&&(!h5||!h6||!h7))throw new Error(hk(0x1f4));const [{CosmosClient:hh},{ClientSecretCredential:hm}]=await Promise[hk(m9.K)]([import(hk(0x215)),import(hk(0x1a1))]),hT=h4?new hh({'endpoint':h3,'key':h4}):new hh({'endpoint':h3,'aadCredentials':new hm(h5,h6,h7)}),{database:hN}=await hT[hk(0x237)][hk(0x1ae)]({'id':h8}),hU=Number(h0[hk(m9.t)](hk(0x1bf),'400')),{container:hZ}=await hN['containers'][hk(0x1ae)]({'id':h9,'partitionKey':{'paths':[hk(m9.h7)]},...Number[hk(0x1d5)](hU)&&hU>0x0?{'throughput':hU}:{}}),{resource:hd}=await hZ[hk(m9.h8)](),hB=hd?.[hk(m9.h9)]?.[hk(m9.hh)]??[];if(!hB[hk(m9.hm)]('/id'))throw new Error(hk(m9.hT)+h9+hk(0x219)+(hB[hk(0x1ce)](',\x20')||hk(0x1a6))+'.');const {CosmosSessionDocumentContainer:hE}=await import('./cosmos-session-document.container.js');return new C(new hE(hZ,()=>hT[hk(0x1f6)]()),h2);}async[hu(0x23b)](S){const hz=hu,L=await this['readDocument'](S);return L?.[hz(0x223)]===h?L:void 0x0;}async[hu(0x20b)](S){const mm={S:0x23e,L:0x1b4,t:0x1ed},hr=hu;try{const {resource:L}=await this[hr(mm.S)][hr(mm.L)](S,S)[hr(mm.t)]();return L;}catch(g){if(V(g))return;throw g;}}async[hu(0x1cf)](S,L,g){const mT={S:0x1c3,L:0x23e,t:0x23c,g:0x21c,o:0x1aa,l:0x223,O:0x1ca,i:0x1ca,K:0x243,H:0x1c1},hb=hu,O=x['assertId'](g[hb(0x1db)]),K=a(g['graphSchemaVersion']),H=await this[hb(0x20b)](S);H&&H['version']===h&&y(H,O);const v=new Date(),M={'owner':L,'expiresAt':new Date(v['getTime']()+this[hb(0x20d)])[hb(mT.S)]()};if(!H){const h1=this['placeholderDocument'](S,g,O,K,M,v[hb(mT.S)]());if(await this[hb(mT.L)]['compareAndSwap']({'expectedRevision':null},h1)===hb(mT.t))throw new f(w,hb(mT.g)+S+'\x27\x20is\x20already\x20processing\x20a\x20turn.');return{'kind':hb(mT.o),'document':h1,'expectedRevision':h1[hb(0x1ba)]};}if(H[hb(mT.l)]!==h){const h2=this[hb(0x1d2)](S,g,O,K,M,v['toISOString']());if(await this[hb(0x23e)][hb(0x1c1)]({'expectedRevision':m(H),'replaceIncompatible':!0x0},h2)==='conflict')throw new f(w,'Session\x20\x27'+S+'\x27\x20is\x20already\x20processing\x20a\x20turn.');return{'kind':hb(0x1aa),'document':h2,'expectedRevision':h2['revision']};}if(G(H[hb(mT.O)])&&H[hb(mT.i)]?.[hb(0x209)]!==L)throw new f(w,hb(0x21c)+S+hb(mT.K));const h0={...H,'revision':m(H)+0x1,'turn':M,'modifiedAt':v[hb(0x1c3)]()};if(await this['container'][hb(mT.H)]({'expectedRevision':m(H),'requireFreeLease':!0x0,'allowOwner':L},h0)==='conflict')throw new f(w,hb(0x21c)+S+hb(mT.K));return{'kind':hb(0x1aa),'document':h0,'expectedRevision':m(h0)};}async['restoreState'](S,L){const hp=hu,g=await this['getSession'](S);if(g)return this[hp(0x239)](g,L);}[hu(0x239)](S,L){const mU={S:0x1a5,L:0x1a5,t:0x1ac,g:0x1c5},hF=hu,g=x['assertId'](L);y(S,g);const {graph:l}=S;if(!l[hF(mU.S)])return;const O=r({},l[hF(mU.L)]),i=ne(l[hF(0x23a)]);return{'currentNode':l[hF(0x231)],'config':l['config']??{},'completed':S['status']===hF(mU.t)||l['currentNode']===u,'nodes':O,'tokens':A(S[hF(mU.g)]),'histories':i,'inputConsumed':!0x0,'response':''};}async['saveState'](L,K,H,v=b(),M={}){const mZ={S:0x1c7,L:0x1b6,t:0x20b,g:0x223,o:0x1a3,l:0x1ac,O:0x229,i:0x229,K:0x1ad,H:0x1b1,s:0x1ca,v:0x22c,M:0x20d,h0:0x1c3,h1:0x23e,h2:0x209,h3:0x209,h4:0x243},hA=hu,h0=x[hA(mZ.S)](H[hA(0x1db)]),h1=a(H[hA(mZ.L)]),h2=await this[hA(mZ.t)](L),h3=h2?.[hA(mZ.g)]===h?h2:void 0x0;h3&&(y(h3,h0),U(h3,h1));const h4=new Date()[hA(0x1c3)](),h5=ee(r({},K[hA(0x1a5)])),{tokens:h6,histories:h7}=K,h8=this[hA(mZ.o)](h2,M),h9={'version':h,'id':L,'revision':h8===null?0x0:h8+0x1,'status':K[hA(mZ.l)]?hA(mZ.l):hA(0x1e2),'tokens':A(h6),'errors':[...h3?.[hA(mZ.O)]??[],...v[hA(mZ.i)]],'warnings':[...h3?.['warnings']??[],...v[hA(mZ.K)]],'graph':{'id':h0,'schemaVersion':h1,'currentNode':K['currentNode'],'config':K[hA(mZ.H)],'histories':re(h7),'model':D[hA(0x221)](H['llmConfig']),'nodes':h5},...M[hA(0x216)]&&h3?.[hA(mZ.s)]?{'turn':{'owner':h3[hA(0x1ca)][hA(0x209)],'expiresAt':new Date(Date[hA(mZ.v)]()+this[hA(mZ.M)])[hA(mZ.h0)]()}}:{},'createdAt':h3?.[hA(0x1dc)]??h4,'modifiedAt':h4};if(await this[hA(mZ.h1)][hA(0x1c1)](this['commitPredicate'](h2,M,h8),h9)===hA(0x23c))throw new f(M[hA(mZ.h2)]?$:w,M[hA(mZ.h3)]?hA(0x21c)+L+'\x27\x20changed\x20before\x20this\x20turn\x20could\x20be\x20saved.':hA(0x21c)+L+hA(mZ.h4));return h9;}async[hu(0x22b)](L,g,l,O={}){const md={S:0x1c7,L:0x1b6,t:0x23b,g:0x1c3,o:0x1a3,l:0x1ff,O:0x1d8,i:0x1e7,K:0x1c5,H:0x1b1,s:0x23a,v:0x221,M:0x1b5,h0:0x23e,h1:0x23f,h2:0x23c,h3:0x209,h4:0x1b3,h5:0x208,h6:0x21c,h7:0x243},hc=hu,K=x[hc(md.S)](l[hc(0x1db)]),H=a(l[hc(md.L)]),v=await this[hc(md.t)](L);v&&(y(v,K),U(v,H));const M=new Date()[hc(md.g)](),h0=this[hc(md.o)](v,O),h1={'version':h,'id':L,'revision':h0===null?0x0:h0+0x1,'status':g[hc(0x229)][hc(md.l)]>0x0?hc(md.O):v?.[hc(md.i)]??hc(0x1e2),'tokens':v?.[hc(md.K)]??F(),'errors':[...v?.[hc(0x229)]??[],...g[hc(0x229)]],'warnings':[...v?.[hc(0x1ad)]??[],...g[hc(0x1ad)]],'graph':{'id':K,'schemaVersion':H,...v?{'currentNode':v[hc(0x1a4)][hc(0x231)],'config':v[hc(0x1a4)][hc(md.H)]}:{},'histories':v?.['graph'][hc(md.s)]??{},'model':D[hc(md.v)](l[hc(md.M)]),...v?.['graph'][hc(0x1a5)]?{'nodes':v['graph'][hc(0x1a5)]}:{}},'createdAt':v?.[hc(0x1dc)]??M,'modifiedAt':M};if(await this[hc(md.h0)][hc(0x1c1)](this[hc(md.h1)](v,O,h0),h1)===hc(md.h2)){if(O[hc(md.h3)]){console[hc(md.h4)]('Session\x20\x27'+L+'\x27\x20lost\x20its\x20lease\x20before\x20logs\x20were\x20appended;\x20'+g[hc(0x229)][hc(0x1ff)]+hc(md.h5)+g['warnings'][hc(0x1ff)]+hc(0x1f8));return;}throw new f(w,hc(md.h6)+L+hc(md.h7));}return h1;}async[hu(0x217)](S,L,g,l,O){const mB={S:0x22b,L:0x20e},ha=hu;if(l&&(l['errors']['length']>0x0||l['warnings'][ha(0x1ff)]>0x0)){await this[ha(mB.S)](S,l,g,{'owner':L,...O!==void 0x0?{'expectedRevision':O}:{}});return;}await this[ha(mB.L)](S,L,O);}async[hu(0x20e)](S,L,g){const hV=hu,l=await this[hV(0x23b)](S);if(!l||l['turn']?.['owner']!==L)return;const O=g??m(l),{turn:K,...H}=l,v={...H,'modifiedAt':new Date()[hV(0x1c3)]()};await this[hV(0x23e)]['compareAndSwap']({'expectedRevision':O,'requireOwner':L},v);}async[hu(0x1be)](S){const hS=hu;try{await this['container']['item'](S,S)[hS(0x203)]();}catch(L){if(!V(L))throw L;}}async[hu(0x1e4)](S,L={}){const mC={S:0x227,L:0x1a4,t:0x1e3,g:0x1ca,o:0x1dc,l:0x23e,O:0x1c1,i:0x209,K:0x23c,H:0x21c},hj=hu;if(S['version']!==h)throw new Error(hj(0x236)+S[hj(0x223)]+hj(mC.S)+h+'.');x[hj(0x1c7)](S[hj(mC.L)]['id']),a(S[hj(0x1a4)][hj(0x214)]);const g=await this['getSession'](S['id']),l=L[hj(mC.t)]??m(g||S),O=g?.[hj(mC.g)]??S['turn'],i={...S,'revision':l,'createdAt':g?.[hj(mC.o)]??S[hj(0x1dc)],'modifiedAt':g?.[hj(0x1c4)]??S[hj(0x1c4)],...O?{'turn':O}:{}};if(await this[hj(mC.l)][hj(mC.O)]({'expectedRevision':l,...L[hj(0x209)]?{'requireOwner':L[hj(mC.i)]}:{'requireFreeLease':!0x0}},i)===hj(mC.K))throw new f(L[hj(mC.i)]?$:w,hj(mC.H)+S['id']+hj(0x200));}async[hu(0x204)](){const mQ={S:0x204},hL=hu;await this[hL(0x23e)][hL(mQ.S)]?.();}[hu(0x1d2)](S,L,g,l,O,i){return{'version':h,'id':S,'revision':0x0,'status':'in_progress','tokens':F(),'errors':[],'warnings':[],'graph':{'id':g,'schemaVersion':l,'histories':{},'model':D['modelMetadata'](L['llmConfig'])},'turn':O,'createdAt':i,'modifiedAt':i};}[hu(0x1a3)](S,L){const mw={S:0x1e3},ht=hu;return L[ht(mw.S)]!==void 0x0?L[ht(0x1e3)]:S?m(S):null;}[hu(0x23f)](S,L,g){const mY={S:0x209},hg=hu;return L[hg(mY.S)]?{'expectedRevision':g,'requireOwner':L[hg(mY.S)]}:S&&S[hg(0x223)]!==h?{'expectedRevision':g,'replaceIncompatible':!0x0}:{'expectedRevision':g,'requireFreeLease':!0x0};}}function p(S,...L){const mx={S:0x1e8},ho=hu;for(const g of L){const o=S[ho(mx.S)](g);if(o)return o;}}c(p,hu(0x21f));function y(S,L){const me={S:0x1a4,L:0x230},hq=hu;if(S[hq(0x1a4)]['id']!==L)throw new Error(hq(0x21c)+S['id']+hq(0x1de)+S[hq(me.S)]['id']+'\x27,\x20not\x20\x27'+L+hq(me.L));}c(y,hu(0x21d));function U(S,L){const mJ={S:0x1a4,L:0x21c,t:0x1e6,g:0x1f7,o:0x1a7,l:0x1ab},hl=hu;if(S[hl(mJ.S)][hl(0x214)]!==L)throw new Error(hl(mJ.L)+S['id']+hl(mJ.t)+S['graph']['id']+hl(mJ.g)+S[hl(mJ.S)]['schemaVersion']+hl(mJ.o)+L+hl(mJ.l));}c(U,hu(0x1f9));function ee(S){const mD={S:0x22f},mu={S:0x1d6},hO=hu;return Object[hO(0x226)](Object['entries'](S)[hO(mD.S)](([L,g])=>{const hG=hO;if(!g||typeof g!=hG(mu.S))return[L,g];const {toolTrace:l,...O}=g;return[L,O];}));}function N(){const mq=['CMvHzerVy3vTzw50','DhjPBq','DhvYBKXLyxnLtxm','CMvSzwfZzvr1CM4','ywXSB3DpD25LCG','q29ZBw9ZignVBNrHAw5LCIaN','q09ttu9tx0rbvefcqvnf','q09ttu9eqL9trvntsu9ox0Le','DxnHz2vFBwv0ywrHDge','C2nOzw1HvMvYC2LVBG','qgf6DxjLl2nVC21VCW','A2vLCfr1CM4','zw5KrMfPBgvKvhvYBG','ywXS','jYbTDxn0ihvZzsbWyxj0AxrPB24GA2v5ic9PzdSGzM91BMqG','q09ttu9FrejFsuq','nJaWmda','u2vZC2LVBIaN','yxnZzxj0u2vZC2LVBKDYyxbO','zxHWAxjLC0f0','zMLYC3q','mZy4ndyWme9sB3Hbsq','Bw9KzwXnzxrHzgf0yq','AxnbCNjHEq','DMvYC2LVBG','mJu2nty2EhLMqw1j','tw9Uz29eqIbZzxnZAw9UihbLCNnPC3rLBMnLihjLCxvPCMvZie1ptKDprejFvvjmlcbnt05ht0rcx05btuuSigfUzcbnt05ht0rcx0npteXfq1rjt04U','zNjVBuvUDhjPzxm','oYbLEhbLy3rLzca','mtf5DKfOALC','zxjYB3jZ','tu9or09eqL9oqu1f','yxbWzw5Ktg9NCW','BM93','u2vZC2LVBLr1CM5fCNjVCG','q09ttu9tx0nptLrbsu5fuG','BwfW','jY4Gu3rHCNqGysbUzxCGC2vZC2LVBIb0BYbYDw4GysbKAwzMzxjLBNqGz3jHCgGU','y3vYCMvUDe5Vzgu','y29ZBw9Zzgi','l2LK','AxnoB3rgB3vUza','q09ttu9FrejFu0vtu0LptL9dt05uquLorvjFsuq','q2fUBM90ihbLCNnPC3qGC2vZC2LVBIbKB2n1BwvUDcb2zxjZAw9Uia','zgf0ywjHC2vZ','zgf0yq','CMvZDg9YzvnLC3nPB25eB2n1BwvUDa','AgLZDg9YAwvZ','z2v0u2vZC2LVBG','y29UzMXPy3q','q09ttu9FrejFq0Xjru5ux0Le','y29UDgfPBMvY','y29TBwL0uhjLzgLJyxrL','Dg9VBf9JywXSCW','Bw9Uz29KyG','Cgf0Ahm','jYbPCYbHBhjLywr5ihbYB2nLC3nPBMCGysb0DxjUlG','Dgv4Da','u0vtu0LptL9uvvjox0Xfqvnfx01t','zgvMAw5LuhjVCgvYDhK','qgf6DxjLl2LKzw50Axr5','q09ttu9Fru5eue9jtLq','y29TBwL0rxHWzwn0zwrszxzPC2LVBG','z3jHCgG','BM9Kzxm','BM9Uzq','lcbUB3qG','nteYmdCYmgf5D0DnuG','AxrLBxm','BgvHC2vK','lIbszxn0B3jLig9Yig1Pz3jHDguGAxqGyMvMB3jLihnHDMLUzY4','y29TCgXLDgvK','D2fYBMLUz3m','y3jLyxrLswzoB3rfEgLZDhm','zNjVBunVBMzPzW','CMvTB3zLtgvNywn5vg9VBfrYywnLCW','y29UzMLN','BMfTzq','D2fYBG','AxrLBq','BgXTq29UzMLN','z3jHCgHty2HLBwfwzxjZAw9U','CgfYC2u','jY4GvxnLicDTzw1VCNKNlcaNC3fSAxrLjYWGj21VBMDVzgiNlcbVCIaNy29ZBw9ZjY4','u0vtu0LptL9dt01qtevuruq','CMv2AxnPB24','Aw52ywXPzf90B29Sx2nHBgXZ','Bwf0y2HLC1nLC3nPB25xCML0zvbYzwrPy2f0zq','DgHVDwDODa','zgvSzxrLu2vZC2LVBG','q09ttu9tx1riuK9vr0Hqvvq','Aw5JBhvKzxm','y29TCgfYzufUzfn3yxa','y29ZBw9Z','Dg9ju09tDhjPBMC','Bw9KAwzPzwrbDa','Dg9Rzw5Z','DhLWzq','yxnZzxj0swq','y29UBMvJDa','q09ttu9tx0Tfwq','DhvYBG','mZeYnJKWnejdwwLIvW','C3rHDhvZq29Kzq','oxL6EgHQCq','AM9PBG','yMvNAw5uDxjU','qvPvuKvFvevoqu5ux0Le','tM90igzVDw5K','CgXHy2vOB2XKzxjeB2n1BwvUDa','C2L6zq','q09ttu9tx0vorfbpsu5u','AxngAw5PDgu','B2jQzwn0','mNPzCfHSyG','zxjYB3i','otm2otv5DwPewfG','mtG2otuZmtb2wgPRzvq','z3jHCgHjza','y3jLyxrLzef0','lI9ZCwXPDguTC2vZC2LVBI1KB2n1BwvUDc5JB250ywLUzxiUANm','jYbIzwXVBMDZihrVigDYyxbOicC','CMvZDg9YzuHPC3rVCMLLCW','C2LNBMf0DxjLqMvHCMLUz0nVBNrLBNrcBg9JAW','u1fmsvrfx0rcx1bbveG','Aw5FChjVz3jLC3m','zxHWzwn0zwrszxzPC2LVBG','CgvYC2LZDe1Pz3jHDgvKu2vZC2LVBG','C2v0','jYb1C2vZigDYyxbOicC','C3rHDhvZ','z2v0','CgfYDgL0Aw9Us2v5','yxnZAwDU','q09ttu9eqL9lrvK','B3jPz2LUywXuzxH0q29UDgvUDejSB2nR','CMvHza','zg9JDw1LBNrZ','mJa3mtG4mxvyCevjyG','ywrKAxrPB25HBf9RD2fYz3m','DxbZzxj0','Bw9Uz28','ndj1BxDpCKK','q29ZBw9ZihnLC3nPB24GCgvYC2LZDgvUy2uGCMvXDwLYzxmGq09ttu9eqL9vuKWGyw5Kienpu01prejFs0vzlcbVCIbdt1nnt19ftKrqt0LovcWGqvPvuKvFvevoqu5ux0Lelcbdt1nnt19eqL9dteLftLrFsuqSigfUzcbdt1nnt19eqL9dteLftLrFu0vduKvulG','C2vZC2LVBLjLDMLZAw9U','zgLZCg9Zzq','jYbZy2HLBweGDMvYC2LVBIa','ihDHCM5PBMCOCYKGD2vYzsbKCM9WCgvKlG','yxnZzxj0u2vZC2LVBKDYyxbOu2nOzw1H','CMvWBgfJzuLUy29TCgf0AwjSzq','u0vtu0LptL9cvvnz','y29SBgvJDgLVBG','y29Kzq','DgHVDwDODfnPz25HDhvYzq','BgvUz3rO','jYbJAgfUz2vKigjLzM9YzsbPDhmGBwLNCMf0Aw9UignVDwXKigjLihnHDMvKlG','zw50CMLLCW','BwvTB3j5','zgvSzxrL','y2XVC2u','C3fSAxrL','u0vtu0LptL9tve9srq','AxnszwnVCMq','igvYCM9YkhmPigfUzca','B3DUzxi','y29TCgfJDfn0B3jLze1LC3nHz2vZ'];N=function(){return mq;};return N();}c(ee,hu(0x1b0));function te(S){const mW={S:0x238,L:0x222,t:0x1f0,g:0x213,o:0x240,l:0x1ff,O:0x240,i:0x222,K:0x1bb},hi=hu;return S[hi(0x22f)](L=>{const hy=hi,g={...L[hy(mW.S)]},l=L['type']==='ai'&&Array[hy(mW.L)](g[hy(0x240)])&&g['tool_calls']['length']>0x0?oe(g[hy(mW.t)]):void 0x0;return delete g['additional_kwargs'],l&&(g[hy(0x1f0)]={'originalTextContentBlock':l}),delete g['response_metadata'],delete g[hy(mW.g)],L[hy(0x1c6)]==='ai'&&(Array[hy(mW.L)](g['tool_calls'])&&g[hy(mW.o)][hy(mW.l)]===0x0&&delete g[hy(mW.O)],Array[hy(mW.i)](g[hy(mW.K)])&&g[hy(0x1bb)][hy(0x1ff)]===0x0&&delete g['invalid_tool_calls']),{...L,'data':g};});}c(te,hu(0x20a));function re(S){const mz={S:0x226,L:0x22f},hP=hu;return Object[hP(mz.S)](Object['entries'](S)[hP(mz.L)](([L,g])=>[L,te(n(g))]));}c(re,'storeHistories');function ne(S={}){const hR=hu;return Object[hR(0x226)](Object[hR(0x201)](S)[hR(0x22f)](([L,g])=>[L,Y(g)]));}c(ne,hu(0x1df));function oe(S){const hK=hu;if(!P(S))return;const L=S[hK(0x1ec)];if(!(!P(L)||typeof L['thoughtSignature']!='string'))return{...typeof L[hK(0x244)]=='string'?{'text':L[hK(0x244)]}:{},'thoughtSignature':L[hK(0x1fe)],...L[hK(0x1bd)]===!0x0?{'thought':!0x0}:{}};}c(oe,hu(0x1e0));function P(S){const mp={S:0x1d6},hH=hu;return S!==null&&typeof S==hH(mp.S)&&!Array['isArray'](S);}c(P,hu(0x207));class q{static{c(this,'MemorySessionDocumentContainer');}[hu(0x1ee)]=new Map();get[hu(0x1d3)](){const mF={S:0x1ee},hs=hu;return this[hs(mF.S)][hs(0x1d3)];}[hu(0x1a9)]={'upsert':c(async e=>{const mA={S:0x1ee},hv=hu,t=e;return this[hv(mA.S)][hv(0x1e5)](t['id'],structuredClone(t)),{};},hu(0x1f1))};async[hu(0x1c1)](S,L){const hI=hu,g=this[hI(0x1ee)][hI(0x1e8)](L['id']);return ie(g,S)?(this[hI(0x1ee)]['set'](L['id'],structuredClone(L)),'ok'):hI(0x23c);}[hu(0x1b4)](S,L){const mS={S:0x203},mV={S:0x1ea,L:0x1d1},ma={S:0x1e8,L:0x1ea},hM=hu;return{'read':c(async()=>{const hX=d,g=this['documents'][hX(ma.S)](S);if(!g||g['id']!==L)throw Object[hX(ma.L)](new Error('Not\x20found'),{'code':0x194});return{'resource':structuredClone(g)};},hM(0x1ed)),'delete':c(async()=>{const m0=hM,g=this[m0(0x1ee)][m0(0x1e8)](S);if(!g||g['id']!==L)throw Object[m0(mV.S)](new Error(m0(mV.L)),{'code':0x194});return this[m0(0x1ee)][m0(0x203)](S),{};},hM(mS.S))};}}function V(S){const m1=hu;if(!S||typeof S!=m1(0x1d6))return!0x1;const L=S;return L[m1(0x1fd)]===0x194||L[m1(0x1cc)]===0x194;}c(V,hu(0x234));function j(S=process.env.SESSION_TURN_LEASE_MS){const mL={S:0x21b,L:0x1d5},m2=hu,L=Number(S??m2(mL.S));return Number[m2(mL.L)](L)&&L>0x0?L:0xea60;}c(j,'sessionTurnLeaseMs');function m(S){const m3=hu;return S?.[m3(0x1ba)]??0x0;}c(m,hu(0x1f5));function G(S,L=Date[hu(0x22c)]()){const mg={S:0x1b7},m4=hu;if(!S?.[m4(0x209)]||!S[m4(0x21e)])return!0x1;const g=Date[m4(mg.S)](S[m4(0x21e)]);return Number[m4(0x1d5)](g)&&g>L;}c(G,'isLiveSessionTurn');function d(h,m){h=h-0x1a0;const T=N();let U=T[h];if(d['JBIzjs']===undefined){var Z=function(C){const Q='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+/=';let n='',w='';for(let Y=0x0,x,e,J=0x0;e=C['charAt'](J++);~e&&(x=Y%0x4?x*0x40+e:e,Y++%0x4)?n+=String['fromCharCode'](0xff&x>>(-0x2*Y&0x6)):0x0){e=Q['indexOf'](e);}for(let u=0x0,D=n['length'];u<D;u++){w+='%'+('00'+n['charCodeAt'](u)['toString'](0x10))['slice'](-0x2);}return decodeURIComponent(w);};d['KmuqMm']=Z,d['UpVtOL']={},d['JBIzjs']=!![];}const B=T[0x0],E=h+B,f=d['UpVtOL'][E];return!f?(U=d['KmuqMm'](U),d['UpVtOL'][E]=U):U=f,U;}function ie(S,L,g=Date[hu(0x22c)]()){const mo={S:0x1fa,L:0x1e3,t:0x1ca,g:0x20f},m5=hu;return L[m5(mo.S)]?S!==void 0x0&&S[m5(0x223)]!==h:L[m5(0x1e3)]===null?S===void 0x0:!(!S||m(S)!==L[m5(mo.L)]||L['requireOwner']&&S[m5(mo.t)]?.['owner']!==L['requireOwner']||L['requireFreeLease']&&G(S['turn'],g)&&S[m5(0x1ca)]?.[m5(0x209)]!==L[m5(mo.g)]);}c(ie,hu(0x1bc));export{q as MemorySessionDocumentContainer,w as SESSION_BUSY,we as SESSION_COMPLETED,$ as SESSION_CONFLICT,h as SESSION_DOCUMENT_VERSION,C as SessionManager,f as SessionTurnError,G as isLiveSessionTurn,ie as matchesSessionWritePredicate,m as sessionRevision,j as sessionTurnLeaseMs};
1
+ const KE=e;(function(r,d){const e2={r:0x185,d:0x121,w:0x11f,R:0x18a,a:0x180,B:0x172},Kt=e,w=r();while(!![]){try{const R=parseInt(Kt(0x182))/0x1+parseInt(Kt(e2.r))/0x2+-parseInt(Kt(e2.d))/0x3+-parseInt(Kt(e2.w))/0x4*(-parseInt(Kt(e2.R))/0x5)+-parseInt(Kt(0x12c))/0x6*(parseInt(Kt(0x157))/0x7)+parseInt(Kt(e2.a))/0x8*(-parseInt(Kt(e2.B))/0x9)+-parseInt(Kt(0x139))/0xa*(-parseInt(Kt(0x145))/0xb);if(R===d)break;else w['push'](w['shift']());}catch(a){w['push'](w['shift']());}}}(K,0x2daed));var Z=Object[KE(0x19b)],c=(r,d)=>Z(r,KE(0x14e),{'value':d,'configurable':!0x0});import{mapChatMessagesToStoredMessages as m,mapStoredMessagesToChatMessages as s}from'@langchain/core/messages';import{BaseGraph as n}from'../base-graph.js';import{ConfigManager as o}from'../config-manager.js';import{GRAPH_END_NODE as z}from'../graph-state.js';import{GraphLlm as H}from'../graph-llm.config.js';import{replaceNodeStates as t}from'../node-state.js';import{createSessionLogs as E}from'../session-log.js';import{emptyTokenUsage as D,normalizeTokenUsage as M}from'../token-usage.js';import{assertGraphSchemaVersion as O}from'../stable-id.js';import{addDecisionUsage as b,emptyDecisionUsage as u,normalizeDecisionUsage as A}from'../decision/decision-types.js';const h=0x10,g=KE(0x166),P='SESSION_CONFLICT',_e=KE(0x1af);class f extends Error{static{c(this,KE(0x15a));}['code'];constructor(r,d){const e3={r:0x14e},Kk=KE;super(d),this[Kk(e3.r)]=Kk(0x15a),this[Kk(0x15e)]=r;}}class N{static{c(this,'SessionManager');}[KE(0x11d)];['turnLeaseMs'];constructor(r=new V(),d=G()){const e4={r:0x136},Kq=KE;this['container']=r,this[Kq(e4.r)]=d;}static async[KE(0x165)](K0=new o()){const e5={r:0x194,d:0x18f,w:0x17e,R:0x159,a:0x158,B:0x126,Y:0x19f,L:0x1b4,i:0x13e,l:0x18b,K0:0x1b9,K1:0x154,K2:0x178,K3:0x156,K4:0x163,K5:0x131,K6:0x19e,K7:0x142,K8:0x1ae,K9:0x140,KK:0x119,Ke:0x15c,Kj:0x13c,KC:0x14a,KI:0x125,KJ:0x191,KF:0x187,KV:0x193,Km:0x1bf,Kh:0x118,Kc:0x1bc,Ks:0x155,KP:0x197},KD=KE,K1=K0[KD(0x125)](KD(0x186),'memory')[KD(0x1a9)]()[KD(0x146)](),K2=G(K0[KD(0x125)](KD(e5.r)));if(K1===KD(0x15f))return new N(new V(),K2);if(K1===KD(e5.d)){const {SqliteSessionDocumentContainer:Kh}=await import('./sqlite-session-document.container.js');return new N(new Kh(K0['get'](KD(e5.w),KD(0x16f))),K2);}if(K1===KD(0x1b4)||K1==='mongo'){const Kc=p(K0,KD(e5.R)),Ks=p(K0,KD(e5.a)),KP=p(K0,KD(0x190));if(!Kc||!Ks||!KP)throw new Error(KD(e5.B));const [{MongoClient:Kn},{MongoDbSessionDocumentContainer:Ko}]=await Promise[KD(e5.Y)]([import(KD(e5.L)),import('./mongodb-session-document.container.js')]),Kz=new Kn(Kc);await Kz['connect']();const KH=Kz['db'](Ks)[KD(e5.i)](KP);return await KH[KD(e5.l)]({'id':0x1},{'unique':!0x0}),new N(new Ko(KH,Kz),K2);}if(K1!==KD(0x181)&&K1!==KD(0x148))throw new Error('Unsupported\x20SESSION_STORE\x20\x27'+K1+KD(0x128));const K3=p(K0,KD(e5.K0),KD(e5.K1),KD(e5.K2)),K4=p(K0,KD(e5.K3),KD(e5.K4)),K5=p(K0,KD(e5.K5)),K6=p(K0,KD(e5.K6)),K7=p(K0,KD(e5.K7)),K8=p(K0,KD(e5.K8),'COSMOS_DATABASE',KD(e5.K9))??KD(e5.KK),K9=p(K0,KD(0x14b),'COSMOS_CONTAINER',KD(0x1b1))??KD(0x13a);if(!K3||!K4&&(!K5||!K6||!K7))throw new Error(KD(0x1b5));const [{CosmosClient:KK},{ClientSecretCredential:Ke}]=await Promise[KD(0x19f)]([import(KD(e5.Ke)),import(KD(0x18c))]),Kj=K4?new KK({'endpoint':K3,'key':K4}):new KK({'endpoint':K3,'aadCredentials':new Ke(K5,K6,K7)}),{database:KC}=await Kj[KD(e5.Kj)][KD(e5.KC)]({'id':K8}),KI=Number(K0[KD(e5.KI)](KD(e5.KJ),KD(0x141))),{container:KJ}=await KC['containers'][KD(0x14a)]({'id':K9,'partitionKey':{'paths':[KD(e5.KF)]},...Number[KD(0x116)](KI)&&KI>0x0?{'throughput':KI}:{}}),{resource:KF}=await KJ[KD(e5.KV)](),KV=KF?.[KD(e5.Km)]?.[KD(e5.Kh)]??[];if(!KV[KD(e5.Kc)](KD(e5.KF)))throw new Error('Cosmos\x20container\x20\x27'+K9+'\x27\x20must\x20use\x20partition\x20key\x20/id;\x20found\x20'+(KV[KD(e5.Ks)](',\x20')||KD(e5.KP))+'.');const {CosmosSessionDocumentContainer:Km}=await import('./cosmos-session-document.container.js');return new N(new Km(KJ,()=>Kj[KD(0x15b)]()),K2);}async[KE(0x12b)](r){const e6={r:0x188},KM=KE,d=await this[KM(0x167)](r);return d?.[KM(e6.r)]===h?d:void 0x0;}async['readDocument'](r){const e7={r:0x11d},KQ=KE;try{const {resource:d}=await this[KQ(e7.r)]['item'](r,r)[KQ(0x193)]();return d;}catch(w){if(j(w))return;throw w;}}async[KE(0x16c)](w,R,B){const e8={r:0x134,d:0x167,w:0x136,R:0x13b,a:0x16a,B:0x13f,Y:0x151,L:0x124,i:0x11d,l:0x16a,K0:0x1ad,K1:0x11e,K2:0x1be,K3:0x170},KZ=KE,Y=n[KZ(0x16b)](B[KZ(0x1c0)]),L=O(B[KZ(e8.r)]),K0=await this[KZ(e8.d)](w);K0&&K0['version']===h&&T(K0,Y);const K1=new Date(),K2={'owner':R,'expiresAt':new Date(K1[KZ(0x152)]()+this[KZ(e8.w)])['toISOString']()};if(!K0){const K4=this[KZ(e8.R)](w,B,Y,L,K2,K1[KZ(0x124)]());if(await this['container'][KZ(0x1be)]({'expectedRevision':null},K4)===KZ(0x170))throw new f(g,KZ(e8.a)+w+KZ(e8.B));return{'kind':KZ(e8.Y),'document':K4,'expectedRevision':K4['revision']};}if(K0['version']!==h){const K5=this[KZ(0x13b)](w,B,Y,L,K2,K1[KZ(e8.L)]());if(await this[KZ(e8.i)][KZ(0x1be)]({'expectedRevision':S(K0),'replaceIncompatible':!0x0},K5)===KZ(0x170))throw new f(g,KZ(e8.l)+w+'\x27\x20is\x20already\x20processing\x20a\x20turn.');return{'kind':'leased','document':K5,'expectedRevision':K5[KZ(e8.K0)]};}if(F(K0['turn'])&&K0[KZ(0x184)]?.[KZ(e8.K1)]!==R)throw new f(g,KZ(0x16a)+w+KZ(0x13f));const K3={...K0,'revision':S(K0)+0x1,'turn':K2};if(await this['container'][KZ(e8.K2)]({'expectedRevision':S(K0),'requireFreeLease':!0x0,'allowOwner':R},K3)===KZ(e8.K3))throw new f(g,KZ(0x16a)+w+KZ(e8.B));return{'kind':KZ(0x151),'document':K3,'expectedRevision':S(K3)};}async[KE(0x162)](d,w){const R=await this['getSession'](d);if(R)return this['restoreSessionDocument'](R,w);}[KE(0x150)](d,w){const eK={r:0x16b,d:0x18e,w:0x14c,R:0x171},KO=KE,R=n[KO(eK.r)](w);T(d,R);const {graph:B}=d;if(!B[KO(0x196)])return;const Y=t({},B[KO(0x196)]),L=se(B[KO(eK.d)]);return{'currentNode':B['currentNode'],'config':B[KO(0x135)]??{},'completed':d[KO(eK.w)]==='completed'||B[KO(0x1b3)]===z,'nodes':Y,'tokens':M(d[KO(0x11c)]),'decisionUsage':A(d[KO(eK.R)]),'histories':L,'inputConsumed':!0x0,'response':''};}async[KE(0x12f)](R,B,Y,L=E(),K0={}){const ej={r:0x167,d:0x124,w:0x196,R:0x192,a:0x117,B:0x11b,Y:0x17d,L:0x183,i:0x184,l:0x129,K0:0x11d,K1:0x1be,K2:0x18d,K3:0x170,K4:0x16a,K5:0x13f},Kb=KE,K1=n[Kb(0x16b)](Y[Kb(0x1c0)]),K2=O(Y['graphSchemaVersion']),K3=await this[Kb(ej.r)](R),K4=K3?.['version']===h?K3:void 0x0;K4&&(T(K4,K1),q(K4,K2));const K5=new Date()[Kb(ej.d)](),K6=ne(t({},B[Kb(ej.w)])),{tokens:K7,histories:K8}=B,K9=this[Kb(ej.R)](K3,K0),KK={'version':h,'id':R,'revision':K9===null?0x0:K9+0x1,'status':B[Kb(0x176)]?Kb(0x176):Kb(ej.a),'tokens':M(K7),'decisionUsage':A(B['decisionUsage']),'errors':[...K4?.[Kb(0x160)]??[],...L[Kb(0x160)]],'warnings':[...K4?.[Kb(ej.B)]??[],...L[Kb(0x11b)]],'decisions':[...K4?.[Kb(0x16e)]??[],...L['decisions']],'graph':{'id':K1,'schemaVersion':K2,'currentNode':B[Kb(0x1b3)],'config':B[Kb(0x135)],'histories':ie(K8),'model':H[Kb(ej.Y)](Y[Kb(ej.L)]),'nodes':K6},...K0[Kb(0x195)]&&K4?.[Kb(ej.i)]?{'turn':{'owner':K4['turn'][Kb(0x11e)],'expiresAt':new Date(Date[Kb(ej.l)]()+this['turnLeaseMs'])[Kb(0x124)]()}}:{},'createdAt':K4?.['createdAt']??K5,'modifiedAt':K5};if(await this[Kb(ej.K0)][Kb(ej.K1)](this[Kb(ej.K2)](K3,K0,K9),KK)===Kb(ej.K3))throw new f(K0['owner']?P:g,K0[Kb(0x11e)]?Kb(0x16a)+R+Kb(0x1ba):Kb(ej.K4)+R+Kb(ej.K5));return KK;}async['appendLogs'](w,R,B,Y={}){const eC={r:0x16b,d:0x14c,w:0x171,R:0x160,a:0x11b,B:0x143,Y:0x18e,L:0x183,i:0x143,l:0x196,K0:0x1a5,K1:0x11d,K2:0x1be,K3:0x170,K4:0x123,K5:0x16a,K6:0x15d,K7:0x16a},Ku=KE,L=n[Ku(eC.r)](B['graphId']),l=O(B[Ku(0x134)]),K0=await this[Ku(0x12b)](w);K0&&(T(K0,L),q(K0,l));const K1=new Date()[Ku(0x124)](),K2=this['commitExpectedRevision'](K0,Y),K3={'version':h,'id':w,'revision':K2===null?0x0:K2+0x1,'status':R['errors'][Ku(0x15d)]>0x0?Ku(0x122):K0?.[Ku(eC.d)]??Ku(0x117),'tokens':K0?.[Ku(0x11c)]??D(),'decisionUsage':R[Ku(0x16e)][Ku(0x19d)]((K4,K5)=>b(K4,K5['usage']),A(K0?.[Ku(eC.w)])),'errors':[...K0?.[Ku(0x160)]??[],...R[Ku(eC.R)]],'warnings':[...K0?.['warnings']??[],...R[Ku(eC.a)]],'decisions':[...K0?.['decisions']??[],...R['decisions']],'graph':{'id':L,'schemaVersion':l,...K0?{'currentNode':K0[Ku(0x143)]['currentNode'],'config':K0[Ku(eC.B)]['config']}:{},'histories':K0?.[Ku(0x143)][Ku(eC.Y)]??{},'model':H['modelMetadata'](B[Ku(eC.L)]),...K0?.[Ku(eC.B)]['nodes']?{'nodes':K0[Ku(eC.i)][Ku(eC.l)]}:{}},'createdAt':K0?.[Ku(eC.K0)]??K1,'modifiedAt':K1};if(await this[Ku(eC.K1)][Ku(eC.K2)](this[Ku(0x18d)](K0,Y,K2),K3)===Ku(eC.K3)){if(Y[Ku(0x11e)]){console[Ku(eC.K4)](Ku(eC.K5)+w+Ku(0x1a6)+R[Ku(0x160)][Ku(eC.K6)]+Ku(0x175)+R[Ku(0x11b)][Ku(eC.K6)]+'\x20warning(s)\x20were\x20dropped.');return;}throw new f(g,Ku(eC.K7)+w+Ku(0x13f));}return K3;}async[KE(0x1c1)](d,w,R,a,B){const KU=KE;if(a&&(a[KU(0x160)]['length']>0x0||a['warnings'][KU(0x15d)]>0x0||a[KU(0x16e)][KU(0x15d)]>0x0)){await this[KU(0x17c)](d,a,R,{'owner':w,...B!==void 0x0?{'expectedRevision':B}:{}});return;}await this[KU(0x1a2)](d,w,B);}async[KE(0x1a2)](d,w,R){const eJ={r:0x184},KA=KE,B=await this[KA(0x12b)](d);if(!B||B[KA(eJ.r)]?.[KA(0x11e)]!==w)return;const Y=R??S(B),{turn:L,...l}=B,K0={...l,'modifiedAt':new Date()[KA(0x124)]()};await this['container'][KA(0x1be)]({'expectedRevision':Y,'requireOwner':w},K0);}async[KE(0x16d)](r){const eF={r:0x1bd,d:0x1a1},Kx=KE;try{await this[Kx(0x11d)][Kx(eF.r)](r,r)[Kx(eF.d)]();}catch(d){if(!j(d))throw d;}}async['persistMigratedSession'](d,w={}){const eV={r:0x188,d:0x1b8,w:0x16b,R:0x12b,a:0x184,B:0x1a5,Y:0x11d,L:0x1be,i:0x11e,l:0x11e},Kr=KE;if(d[Kr(eV.r)]!==h)throw new Error(Kr(eV.d)+d[Kr(eV.r)]+Kr(0x17b)+h+'.');n[Kr(eV.w)](d[Kr(0x143)]['id']),O(d[Kr(0x143)][Kr(0x153)]);const R=await this[Kr(eV.R)](d['id']),B=w['expectedRevision']??S(R||d),Y=R?.[Kr(eV.a)]??d[Kr(0x184)],L={...d,'revision':B,'createdAt':R?.[Kr(eV.B)]??d[Kr(0x1a5)],'modifiedAt':R?.['modifiedAt']??d['modifiedAt'],...Y?{'turn':Y}:{}};if(await this[Kr(eV.Y)][Kr(eV.L)]({'expectedRevision':B,...w[Kr(eV.i)]?{'requireOwner':w[Kr(0x11e)]}:{'requireFreeLease':!0x0}},L)===Kr(0x170))throw new f(w[Kr(eV.l)]?P:g,Kr(0x16a)+d['id']+'\x27\x20changed\x20before\x20its\x20migration\x20could\x20be\x20saved.');}async[KE(0x1b0)](){await this['container']['close']?.();}['placeholderDocument'](d,w,R,B,Y,L){const eh={r:0x117},KS=KE;return{'version':h,'id':d,'revision':0x0,'status':KS(eh.r),'tokens':D(),'decisionUsage':u(),'errors':[],'warnings':[],'decisions':[],'graph':{'id':R,'schemaVersion':B,'histories':{},'model':H['modelMetadata'](w[KS(0x183)])},'turn':Y,'createdAt':L,'modifiedAt':L};}['commitExpectedRevision'](r,d){const Kf=KE;return d[Kf(0x1ac)]!==void 0x0?d[Kf(0x1ac)]:r?S(r):null;}[KE(0x18d)](d,w,R){const es={r:0x188},Kv=KE;return w[Kv(0x11e)]?{'expectedRevision':R,'requireOwner':w[Kv(0x11e)]}:d&&d[Kv(es.r)]!==h?{'expectedRevision':R,'replaceIncompatible':!0x0}:{'expectedRevision':R,'requireFreeLease':!0x0};}}function p(d,...w){for(const R of w){const a=d['get'](R);if(a)return a;}}c(p,KE(0x127));function T(r,d){const en={r:0x189},Kd=KE;if(r[Kd(0x143)]['id']!==d)throw new Error(Kd(0x16a)+r['id']+Kd(0x169)+r[Kd(0x143)]['id']+Kd(en.r)+d+Kd(0x12d));}c(T,KE(0x19a));function K(){const ev=['qgf6DxjLl2LKzw50Axr5','y29TBwL0uhjLzgLJyxrL','AgLZDg9YAwvZ','C3fSAxrL','tu9or09eqL9dt0Xmrunusu9o','q09ttu9tx1riuK9vr0Hqvvq','y29TBwL0rxHWzwn0zwrszxzPC2LVBG','CMvHza','u0vtu0LptL9uvvjox0Xfqvnfx01t','A2vLCfr1CM4','BM9Kzxm','BM9Uzq','lcbUB3qG','CMvZCg9UC2vFBwv0ywrHDge','yxnZzxj0u2vZC2LVBKDYyxbO','zgvMAw5LuhjVCgvYDhK','zxPNCMfWAeLUDgvYBMfS','CMvKDwnL','q09ttu9FrejFq0Xjru5ux0Le','ywXS','BwfW','zgvSzxrL','CMvSzwfZzvr1CM4','C3rVCMviAxn0B3jPzxm','CMvTB3zLtgvNywn5vg9VBfrYywnLCW','y3jLyxrLzef0','jYbSB3n0igL0CYbSzwfZzsbIzwzVCMuGBg9NCYb3zxjLigfWCgvUzgvKoYa','yxnZAwDU','DxbZzxj0','DhjPBq','jYbZy2HLBweGDMvYC2LVBIa','CgfYC2u','zxHWzwn0zwrszxzPC2LVBG','CMv2AxnPB24','q09ttu9FrejFsuq','u0vtu0LptL9dt01qtevuruq','y2XVC2u','q09ttu9eqL9trvntsu9ox0Le','B2jQzwn0','y3vYCMvUDe5Vzgu','Bw9Uz29KyG','q29ZBw9ZihnLC3nPB24GCgvYC2LZDgvUy2uGCMvXDwLYzxmGq09ttu9eqL9vuKWGyw5Kienpu01prejFs0vzlcbVCIbdt1nnt19ftKrqt0LovcWGqvPvuKvFvevoqu5ux0Lelcbdt1nnt19eqL9dteLftLrFsuqSigfUzcbdt1nnt19eqL9dteLftLrFu0vduKvulG','AxnbCNjHEq','Dgv4Da','q2fUBM90ihbLCNnPC3qGC2vZC2LVBIbKB2n1BwvUDcb2zxjZAw9Uia','q09ttu9Fru5eue9jtLq','jYbJAgfUz2vKigjLzM9Yzsb0AgLZihr1CM4Gy291BgqGyMuGC2f2zwqU','zg9JDw1LBNrZ','Aw5JBhvKzxm','AxrLBq','y29TCgfYzufUzfn3yxa','CgfYDgL0Aw9Us2v5','z3jHCgHjza','zw5KrMfPBgvKvhvYBG','lIbszxn0B3jLig9Yig1Pz3jHDguGAxqGyMvMB3jLihnHDMLUzY4','AxngAw5PDgu','Aw5FChjVz3jLC3m','Cgf0Ahm','BgfUz2DYyxbO','zNjVBuvUDhjPzxm','D2fYBMLUz3m','Dg9Rzw5Z','y29UDgfPBMvY','B3DUzxi','mtm5odq0B1nVq1Lf','tM90igzVDw5K','otGWmZCZALHLvKzt','zxjYB3i','D2fYBG','Dg9ju09tDhjPBMC','z2v0','tw9Uz29eqIbZzxnZAw9UihbLCNnPC3rLBMnLihjLCxvPCMvZie1ptKDprejFvvjmlcbnt05ht0rcx05btuuSigfUzcbnt05ht0rcx0npteXfq1rjt04U','zMLYC3q','jY4GvxnLicDTzw1VCNKNlcaNC3fSAxrLjYWGj21VBMDVzgiNlcbVCIaNy29ZBw9ZjY4','BM93','C2LNBMf0DxjLqMvHCMLUz0nVBNrLBNrcBg9JAW','z2v0u2vZC2LVBG','nLfhD2fPBW','jY4Gu3rHCNqGysbUzxCGC2vZC2LVBIb0BYbYDw4GysbKAwzMzxjLBNqGz3jHCgGU','DxnHz2vFBwv0ywrHDge','C2f2zvn0yxrL','CMvXDwLYzu93BMvY','qvPvuKvFvevoqu5ux0Le','y29TCgfJDfn0B3jLze1LC3nHz2vZ','twvTB3j5u2vZC2LVBKrVy3vTzw50q29UDgfPBMvY','z3jHCgHty2HLBwfwzxjZAw9U','y29UzMLN','DhvYBKXLyxnLtxm','CMvWBgfJzuLUy29TCgf0AwjSzq','Aw52ywXPzf90B29Sx2nHBgXZ','mtbnBKDXvey','C2vZC2LVBNm','CgXHy2vOB2XKzxjeB2n1BwvUDa','zgf0ywjHC2vZ','AxnmAxzLu2vZC2LVBLr1CM4','y29SBgvJDgLVBG','jYbPCYbHBhjLywr5ihbYB2nLC3nPBMCGysb0DxjUlG','q09ttu9eqL9jra','ndaW','q09ttu9FrejFq0Xjru5ux1nfq1jfva','z3jHCgG','C2L6zq','ntm2nJCXm0vksejuvq','Dg9mB3DLCKnHC2u','ywXSB3DpD25LCG','y29ZBw9Zzgi','C2v0','y3jLyxrLswzoB3rfEgLZDhm','q09ttu9FrejFu0vtu0LptL9dt05uquLorvjFsuq','C3rHDhvZ','nJaWmda','BMfTzq','DgHVDwDODa','CMvZDg9YzvnLC3nPB25eB2n1BwvUDa','BgvHC2vK','z2v0vgLTzq','C2nOzw1HvMvYC2LVBG','q09ttu9tx0vorfbpsu5u','AM9PBG','q09ttu9eqL9lrvK','mtGZnJy5nuzxzK5KuW','tu9or09eqL9oqu1f','tu9or09eqL9vuKW','u2vZC2LVBLr1CM5fCNjVCG','zgLZCg9Zzq','qgf6DxjLl2nVC21VCW','BgvUz3rO','y29Kzq','BwvTB3j5','zxjYB3jZ','DhLWzq','CMvZDg9Yzvn0yxrL','q09ttu9tx0Tfwq','DgHVDwDODfnPz25HDhvYzq','zNjVBunVBMzPzW','u0vtu0LptL9cvvnz','CMvHzerVy3vTzw50','zw50CMLLCW','jYbIzwXVBMDZihrVigDYyxbOicC','u2vZC2LVBIaN','yxnZzxj0swq','yMvNAw5uDxjU','zgvSzxrLu2vZC2LVBG','zgvJAxnPB25Z','lI9KyxrHl3nLC3nPB25ZlNnXBgL0zq','y29UzMXPy3q','zgvJAxnPB25vC2fNzq','ovnzEgPoAq','Dg9VBf9JywXSCW','AxnoB3rgB3vUza','igvYCM9YkhmPigfUzca','y29TCgXLDgvK','zxHWAxjLC0f0','q09ttu9eqL9vuKW','AxrLBxm','AxnszwnVCMq','oYbLEhbLy3rLzca','yxbWzw5Ktg9NCW','Bw9KzwXnzxrHzgf0yq','u1fmsvrfx0rcx1bbveG','ywrKAxrPB25HBf9RD2fYz3m','mZK4ntm2ExffzunM','y29ZBw9Z','odm2nJrfu2vZDfO','BgXTq29UzMLN','DhvYBG','mtu5nte2Ag1Tq1H1','u0vtu0LptL9tve9srq','l2LK','DMvYC2LVBG','jYWGBM90icC','mJvkzNrVENa','y3jLyxrLsw5KzxG'];K=function(){return ev;};return K();}function q(r,d){const eo={r:0x143,d:0x16a,w:0x1aa,R:0x153,a:0x1c2},Ky=KE;if(r[Ky(eo.r)]['schemaVersion']!==d)throw new Error(Ky(eo.d)+r['id']+'\x27\x20uses\x20graph\x20\x27'+r[Ky(0x143)]['id']+Ky(eo.w)+r['graph'][Ky(eo.R)]+Ky(0x198)+d+Ky(eo.a));}function e(j,C){j=j-0x116;const I=K();let J=I[j];if(e['iLIAun']===undefined){var F=function(c){const s='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+/=';let P='',n='';for(let o=0x0,z,H,t=0x0;H=c['charAt'](t++);~H&&(z=o%0x4?z*0x40+H:H,o++%0x4)?P+=String['fromCharCode'](0xff&z>>(-0x2*o&0x6)):0x0){H=s['indexOf'](H);}for(let E=0x0,q=P['length'];E<q;E++){n+='%'+('00'+P['charCodeAt'](E)['toString'](0x10))['slice'](-0x2);}return decodeURIComponent(n);};e['NebsVu']=F,e['KBVcIO']={},e['iLIAun']=!![];}const V=I[0x0],m=j+V,h=e['KBVcIO'][m];return!h?(J=e['NebsVu'](J),e['KBVcIO'][m]=J):J=h,J;}c(q,'assertSessionGraphSchema');function ne(r){const eH={r:0x11a,d:0x1a0},ez={r:0x1b2},KX=KE;return Object[KX(eH.r)](Object[KX(0x168)](r)[KX(eH.d)](([d,w])=>{const Kw=KX;if(!w||typeof w!=Kw(ez.r))return[d,w];const {toolTrace:R,...a}=w;return[d,a];}));}c(ne,KE(0x1a4));function oe(r){const et={r:0x17f,d:0x19c,w:0x199,R:0x12e,a:0x161,B:0x173,Y:0x173,L:0x15d,i:0x1b6,l:0x138,K0:0x138};return r['map'](d=>{const KN=e,w={...d['data']},R=d[KN(0x161)]==='ai'&&Array['isArray'](w[KN(0x173)])&&w['tool_calls'][KN(0x15d)]>0x0?ae(w['additional_kwargs']):void 0x0,a=v(w[KN(0x17f)])&&w[KN(et.r)][KN(et.d)]===!0x0;return delete w['additional_kwargs'],(R||a)&&(w[KN(et.r)]={...R?{'originalTextContentBlock':R}:{},...a?{'ezgraphInternal':!0x0}:{}}),delete w[KN(et.w)],delete w[KN(et.R)],d[KN(et.a)]==='ai'&&(Array[KN(0x1b6)](w[KN(et.B)])&&w[KN(et.Y)][KN(et.L)]===0x0&&delete w['tool_calls'],Array[KN(et.i)](w['invalid_tool_calls'])&&w[KN(et.l)]['length']===0x0&&delete w[KN(et.K0)]),{...d,'data':w};});}c(oe,KE(0x132));function ie(r){const KR=KE;return Object[KR(0x11a)](Object['entries'](r)[KR(0x1a0)](([d,w])=>[d,oe(m(w))]));}c(ie,KE(0x1a3));function se(r={}){const eq={r:0x168},KT=KE;return Object[KT(0x11a)](Object[KT(eq.r)](r)[KT(0x1a0)](([d,w])=>[d,s(w)]));}c(se,'restoreHistories');function ae(r){const eD={r:0x164,d:0x164,w:0x14f},Kg=KE;if(!v(r))return;const d=r['originalTextContentBlock'];if(!(!v(d)||typeof d[Kg(eD.r)]!='string'))return{...typeof d[Kg(0x1b7)]=='string'?{'text':d['text']}:{},'thoughtSignature':d[Kg(eD.d)],...d[Kg(eD.w)]===!0x0?{'thought':!0x0}:{}};}c(ae,KE(0x12a));function v(r){const eM={r:0x1b6},Kp=KE;return r!==null&&typeof r==Kp(0x1b2)&&!Array[Kp(eM.r)](r);}c(v,KE(0x17a));class V{static{c(this,KE(0x133));}[KE(0x1bb)]=new Map();get[KE(0x144)](){const Ka=KE;return this[Ka(0x1bb)]['size'];}[KE(0x179)]={'upsert':c(async e=>{const eZ={r:0x1bb},KB=KE,t=e;return this[KB(eZ.r)]['set'](t['id'],structuredClone(t)),{};},KE(0x1a8))};async[KE(0x1be)](d,w){const eO={r:0x125,d:0x170},KG=KE,R=this['documents'][KG(eO.r)](w['id']);return ce(R,d)?(this[KG(0x1bb)][KG(0x149)](w['id'],structuredClone(w)),'ok'):KG(eO.d);}['item'](r,d){const eu={r:0x1bb,d:0x1a1},eb={r:0x125},KY=KE;return{'read':c(async()=>{const KW=e,w=this['documents'][KW(eb.r)](r);if(!w||w['id']!==d)throw Object[KW(0x1a7)](new Error(KW(0x120)),{'code':0x194});return{'resource':structuredClone(w)};},KY(0x193)),'delete':c(async()=>{const KL=KY,w=this[KL(eu.r)][KL(0x125)](r);if(!w||w['id']!==d)throw Object['assign'](new Error(KL(0x120)),{'code':0x194});return this[KL(0x1bb)][KL(eu.d)](r),{};},KY(0x1a1))};}}function j(r){const eA={r:0x1b2,d:0x15e},Ki=KE;if(!r||typeof r!=Ki(eA.r))return!0x1;const d=r;return d[Ki(eA.d)]===0x194||d['statusCode']===0x194;}c(j,KE(0x174));function G(r=process.env.SESSION_TURN_LEASE_MS){const Kl=KE,d=Number(r??Kl(0x14d));return Number[Kl(0x116)](d)&&d>0x0?d:0xea60;}c(G,'sessionTurnLeaseMs');function S(r){return r?.['revision']??0x0;}c(S,'sessionRevision');function F(r,d=Date[KE(0x129)]()){const eS={r:0x177,d:0x116},e0=KE;if(!r?.[e0(0x11e)]||!r[e0(0x177)])return!0x1;const w=Date[e0(0x1ab)](r[e0(eS.r)]);return Number[e0(eS.d)](w)&&w>d;}c(F,KE(0x13d));function ce(r,d,w=Date[KE(0x129)]()){const ef={r:0x1ac,d:0x130},e1=KE;return d[e1(0x137)]?r!==void 0x0&&r[e1(0x188)]!==h:d[e1(ef.r)]===null?r===void 0x0:!(!r||S(r)!==d['expectedRevision']||d[e1(ef.d)]&&r[e1(0x184)]?.[e1(0x11e)]!==d['requireOwner']||d['requireFreeLease']&&F(r[e1(0x184)],w)&&r['turn']?.['owner']!==d[e1(0x147)]);}c(ce,'matchesSessionWritePredicate');export{V as MemorySessionDocumentContainer,g as SESSION_BUSY,_e as SESSION_COMPLETED,P as SESSION_CONFLICT,h as SESSION_DOCUMENT_VERSION,N as SessionManager,f as SessionTurnError,F as isLiveSessionTurn,ce as matchesSessionWritePredicate,S as sessionRevision,G as sessionTurnLeaseMs};
@@ -1 +1 @@
1
- var i=Object.defineProperty;var o=(n,r)=>i(n,"name",{value:r,configurable:!0});import{AsyncLocalStorage as g}from"node:async_hooks";const e=new g;function u(){return{errors:[],warnings:[]}}o(u,"createSessionLogs");function S(n,r){return e.run(n,r)}o(S,"withSessionLogs");function p(n,r=e.getStore()){s("errors",n,r)}o(p,"SessionLogError");function f(n,r=e.getStore()){s("warnings",n,r)}o(f,"SessionLogWarning");function s(n,r,t){t&&t[n].push({...r,createdAt:new Date().toISOString()})}o(s,"appendLog");export{p as SessionLogError,f as SessionLogWarning,u as createSessionLogs,S as withSessionLogs};
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};