@picoflow/ezgraph 0.0.8 → 0.0.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +67 -0
- package/dist/framework/base-graph.js +1 -1
- package/dist/framework/conversation-node.js +1 -1
- package/dist/framework/conversation-runner.js +1 -1
- package/dist/framework/decision/decision-node.js +1 -1
- package/dist/framework/graph-engine.js +1 -1
- package/dist/framework/graph-node.js +1 -1
- package/dist/framework/langchain-llm-gateway.js +1 -1
- package/dist/framework/langchain-provider.adapter.js +1 -1
- package/dist/framework/llm-lifecycle.js +1 -0
- package/dist/framework/model-stop-reason.js +1 -1
- package/dist/framework/persistence/session-manager.js +1 -1
- package/dist/framework/state-graph-ext.js +1 -1
- package/dist/index.js +1 -1
- package/dist/types/npmlib/src/index.d.ts +1 -0
- package/dist/types/src/framework/base-graph.d.ts +4 -0
- package/dist/types/src/framework/conversation-node.d.ts +6 -0
- package/dist/types/src/framework/conversation-runner.d.ts +2 -0
- package/dist/types/src/framework/decision/decision-node.d.ts +1 -1
- package/dist/types/src/framework/graph-node.d.ts +4 -1
- package/dist/types/src/framework/llm-lifecycle.d.ts +61 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -128,6 +128,73 @@ For deterministic policy that needs state owned by another node, read
|
|
|
128
128
|
`this.graph.graphState()`. To write another node's channel, use
|
|
129
129
|
`this.graph.saveNodeState(TargetNode, patch)`.
|
|
130
130
|
|
|
131
|
+
## Handle model failures
|
|
132
|
+
|
|
133
|
+
`ConversationNode` supports the same response/error hooks as PicoFlow. The
|
|
134
|
+
three error hooks also exist on `BaseGraph` as graph-wide fallback policy:
|
|
135
|
+
|
|
136
|
+
| Hook | Behavior |
|
|
137
|
+
| --- | --- |
|
|
138
|
+
| `checkResponse(candidate)` | Receives the raw AI message before tool dispatch or acceptance. `true` rejects and retries; `false` accepts. Node-only. |
|
|
139
|
+
| `onLlmBlocked(context)` | Handles prompt blocks and blocked candidates, including candidates with text or tools. Node first, then graph on `null`; two `null` results propagate `LlmResponseBlockedError`. |
|
|
140
|
+
| `shouldRetryLlmError(context)` | Controls retries for thrown invocation errors. Node first, then graph on `undefined`, then the configured retry budget. `false` stops immediately. |
|
|
141
|
+
| `onLlmError(context)` | Handles terminal `invocation_error`, `empty_response`, or `response_rejected` failures. Node first, then graph on `null`; two `null` results propagate the failure. |
|
|
142
|
+
|
|
143
|
+
Contexts identify `nodeId`, provider and model. Ordinary error contexts also
|
|
144
|
+
include attempt counts and the stop cause; rejected/empty contexts retain
|
|
145
|
+
`lastResponse`. Cancellation is checked around hooks. Blocks bypass ordinary
|
|
146
|
+
retry/error hooks; setup, tool-handler, and hook exceptions propagate.
|
|
147
|
+
`MAX_TOKENS` is not a safety block: partial content can be accepted, while an
|
|
148
|
+
empty truncated response enters `onLlmError()` without a corrective nudge.
|
|
149
|
+
|
|
150
|
+
```ts
|
|
151
|
+
import {
|
|
152
|
+
ConversationNode,
|
|
153
|
+
direct,
|
|
154
|
+
type LlmBlockedContext,
|
|
155
|
+
type LlmErrorContext,
|
|
156
|
+
type LlmErrorResponse,
|
|
157
|
+
} from "@picoflow/ezgraph";
|
|
158
|
+
|
|
159
|
+
class SupportNode extends ConversationNode<SupportState> {
|
|
160
|
+
getPrompt(): string { return "Help the customer with their request."; }
|
|
161
|
+
|
|
162
|
+
override async onLlmBlocked(_context: LlmBlockedContext) {
|
|
163
|
+
return direct("I cannot help with that request.");
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
override async onLlmError(context: LlmErrorContext): Promise<LlmErrorResponse | null> {
|
|
167
|
+
if (context.kind === "invocation_error") {
|
|
168
|
+
return direct("The service is unavailable. Please try again.");
|
|
169
|
+
}
|
|
170
|
+
return null; // Offer the failure to BaseGraph.onLlmError().
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
Recovery hooks may return fixed text or `direct()`, `directTo()`, `go()`, or
|
|
176
|
+
`finish()`. `stay()`, tool feedback, and cleanup remain tool-only.
|
|
177
|
+
`onLlmError()` may also return `retryWithModel(ModelCatalog.model(...))` to
|
|
178
|
+
select one temporary alternate model. The alternate stays active through tool
|
|
179
|
+
follow-up, receives one attempt per call regardless of its `params.retries`,
|
|
180
|
+
and never changes the node's configured model for later turns. A second
|
|
181
|
+
alternate in the same recovery sequence is rejected. Completed tool effects
|
|
182
|
+
and their feedback remain in place; newly generated tool calls still execute
|
|
183
|
+
normally, so applications should keep side effects idempotent.
|
|
184
|
+
|
|
185
|
+
For conversational nodes, `params.retries` remains an **additional** retry
|
|
186
|
+
count: `2` allows three attempts for invocation errors or rejected candidates.
|
|
187
|
+
The runner supplies `retries: 0` to each gateway call to prevent nested SDK
|
|
188
|
+
retries. Retries wait 500 ms and honor cancellation. Empty candidates retain
|
|
189
|
+
`emptyResponseRecovery` and its nudge budget, bounded by `maxAgentRounds`.
|
|
190
|
+
Model retries happen within a round; accepted tool turns advance the agent
|
|
191
|
+
loop. Token usage includes rejected and empty candidates.
|
|
192
|
+
|
|
193
|
+
These hooks are wired into `ConversationNode`'s shared loop. Plain `GraphNode`
|
|
194
|
+
and direct gateway calls retain their existing behavior, including
|
|
195
|
+
`GraphNode.onEmptyModelResponse()`. Typed `DecisionNode` validation and
|
|
196
|
+
`onDecisionError()` remain separate.
|
|
197
|
+
|
|
131
198
|
## Add typed decisions with Jev
|
|
132
199
|
|
|
133
200
|
EZGraph supports [Jev](https://typesafe.ai/) through LangChain's optional
|
|
@@ -1 +1 @@
|
|
|
1
|
-
var
|
|
1
|
+
var c=Object.defineProperty;var n=(o,e)=>c(o,"name",{value:e,configurable:!0});import{GraphLlm as p}from"./graph-llm.config.js";import{GraphNodeRuntime as l}from"./graph-node.js";import{StateGraphExt as u}from"./state-graph-ext.js";import{assertEmptyResponseRetries as g,assertMaxAgentRounds as 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 a}from"./stable-id.js";class d{static{n(this,"BaseGraph")}llmGateway;static id(){return this.name}static assertName(e){return d.assertId(e)}static assertId(e){return v(e,"graph")}name;id;schemaVersion;llmConfig;requiresUserMessage;responseMode;maxAgentRounds;conversationPolicy;compiledGraph;runtime;nodeMap=new Map;endNode;migrations;constructor(e,r){this.llmGateway=e;const t=new.target;this.name=t.name,this.id=a(t,"graph"),this.schemaVersion=m(r.schemaVersion??1),this.migrations=M(r.migrations,this.schemaVersion),this.llmConfig=p.resolveConfig(r.llmConfig),this.requiresUserMessage=r.requiresUserMessage??!0,this.responseMode=r.responseMode??"chat",this.maxAgentRounds=y(r.maxAgentRounds??w),this.conversationPolicy=R(r),this.endNode=r.endNode,this.runtime=new l(r.endNode,this.llmConfig,E(r.historySpaces),r.initialHistorySpace,this.responseMode,this.maxAgentRounds,this.conversationPolicy,r.decisionConfig,s=>this.onDecisionError(s),{onLlmBlocked:n(s=>this.onLlmBlocked(s),"onLlmBlocked"),shouldRetryLlmError:n(s=>this.shouldRetryLlmError(s),"shouldRetryLlmError"),onLlmError:n(s=>this.onLlmError(s),"onLlmError")})}async onLlmBlocked(e){return null}shouldRetryLlmError(e){}async onLlmError(e){return null}onDecisionError(e){return null}attachDecisionProviderResolver(e){this.runtime.attachDecisionProviderResolver(e)}get graph(){return this.compiledGraph??=this.buildGraph()}prepareInput(e,r){const t=this.runtime.historySpace(e?.currentNode);return{...e??{},histories:{...e?.histories??{},[t]:[...e?.histories[t]??[],r]}}}saveNodeState(e,r){this.runtime.saveNode(a(e,"graph node"),r)}async restoreSessionDoc(e){if(e.graph.id!==this.id)throw new Error(`Session '${e.id}' belongs to graph '${e.graph.id}', not '${this.id}'. Start a new session to run a different graph.`);if(e.graph.schemaVersion>this.schemaVersion)throw new Error(`Session '${e.id}' uses graph '${this.id}' schema version ${e.graph.schemaVersion}, but this runtime supports version ${this.schemaVersion}.`);let r=e;for(;r.graph.schemaVersion<this.schemaVersion;){const t=r.graph.schemaVersion,s=this.migrations.get(t);if(!s)throw new Error(`Graph '${this.id}' has no migration from schema version ${t} to ${t+1}.`);const i=await s.migrate(r);if(i.graph.id!==this.id)throw new Error(`Graph '${this.id}' migration from schema version ${t} changed the persisted graph ID.`);r={...i,graph:{...i.graph,schemaVersion:t+1}}}return await this.onRestoreSessionDoc(r)}async onRestoreSessionDoc(e){return e}idleMs(e){const r=Date.parse(e.modifiedAt);return Number.isFinite(r)?Date.now()-r:0}createStateGraph(e){return new u(e,(r=>this.createNode(r)),this.endNode)}createNode(e){const r=new e(this.llmGateway,this.runtime),t=a(e,"graph node");if(r.id!==t)throw new Error(`Graph node factory for '${t}' constructs '${r.id}'.`);if(this.nodeMap.has(r.id))throw new Error(`Graph node '${r.id}' is already registered.`);return this.nodeMap.set(r.id,r),this.runtime.registerTools(r.id,r.defineTool()),Object.freeze(r),r}}function R(o){const e=o.emptyResponseRecovery===void 0?h.emptyResponseRecovery:o.emptyResponseRecovery;return e&&g(e.retries),{...o.llmTimeoutMs===void 0?{}:{llmTimeoutMs:f(o.llmTimeoutMs)},emptyHistorySeed:o.emptyHistorySeed===void 0?h.emptyHistorySeed:o.emptyHistorySeed,emptyResponseRecovery:e}}n(R,"resolveConversationPolicy");function E(o){return Object.fromEntries((o??[]).map(([e,r])=>[a(e,"graph node"),r]))}n(E,"historySpaceMap");function M(o,e){const r=new Map;let t;for(const s of o??[]){const i=m(s.from);if(i>=e)throw new Error(`A graph migration from version ${i} cannot target schema version ${e}.`);if(r.has(i))throw new Error(`More than one graph migration starts at version ${i}.`);if(t!==void 0&&i!==t+1)throw new Error(`Graph migrations must be ordered and contiguous; version ${t} must be followed by ${t+1}.`);r.set(i,s),t=i}return r}n(M,"migrationMap");export{d as BaseGraph};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
var m=Object.defineProperty;var
|
|
1
|
+
var m=Object.defineProperty;var a=(n,t)=>m(n,"name",{value:t,configurable:!0});var g=function(n,t,e,r){var s=arguments.length,o=s<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,e):r,i;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")o=Reflect.decorate(n,t,e,r);else for(var d=n.length-1;d>=0;d--)(i=n[d])&&(o=(s<3?i(o):s>3?i(t,e,o):i(t,e))||o);return s>3&&o&&Object.defineProperty(t,e,o),o},l=function(n,t){if(typeof Reflect=="object"&&typeof Reflect.metadata=="function")return Reflect.metadata(n,t)};import{AIMessage as u,HumanMessage as w}from"@langchain/core/messages";import{Command as h,END as p}from"@langchain/langgraph";import{GraphNode as y,Tool as R}from"./graph-node.js";import{stableClassId as f}from"./stable-id.js";import{TerminateSessionNode as v}from"./terminate-session.node.js";import{go as L}from"./tool-response.js";import{addTokenUsage as k}from"./token-usage.js";class b extends y{static{a(this,"ConversationNode")}checkResponse(t){return!1}async onLlmBlocked(t){return null}shouldRetryLlmError(t){}async onLlmError(t){return null}conversationLlmLifecycle(){return{nodeId:this.id,checkResponse:a(t=>this.checkResponse(t),"checkResponse"),shouldRetryLlmError:a(t=>{t.signal?.throwIfAborted();const e=this.shouldRetryLlmError(t);t.signal?.throwIfAborted();const r=e===void 0?this.graph.llmLifecycle?.shouldRetryLlmError(t):e;return t.signal?.throwIfAborted(),r},"shouldRetryLlmError"),onLlmBlocked:a(async t=>{t.signal?.throwIfAborted();let e=await this.onLlmBlocked(t);return t.signal?.throwIfAborted(),e===null&&(e=await this.graph.llmLifecycle?.onLlmBlocked(t)??null,t.signal?.throwIfAborted()),e},"onLlmBlocked"),onLlmError:a(async t=>{t.signal?.throwIfAborted();let e=await this.onLlmError(t);return t.signal?.throwIfAborted(),e===null&&(e=await this.graph.llmLifecycle?.onLlmError(t)??null,t.signal?.throwIfAborted()),e},"onLlmError")}}async endChat(t){return L(v).withMessage(new w({content:t.message?.trim()||"The user asked to end the conversation.",additional_kwargs:{ezgraphInternal:!0}}))}async run(t){const e=await this.runConversation(t,{});if(e.toolResponse)return this.resolveToolResponse(e,e.toolResponse);const r=e.response;if(!r?.trim())throw new Error(`Conversation node '${this.id}' stopped without a response or tool transition.`);return new h({update:{currentNode:this.id,response:r,inputConsumed:!0,completed:!1,...this.historyUpdate(e.messages),tokens:e.usage},goto:p})}resolveToolResponse(t,e){const r=this.historyUpdate(t.messages),s=k(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 h({update:{currentNode:o,inputConsumed:!0,response:"",completed:!1,...r,tokens:s},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 d=c(this.id,e);return i!==this.historySpace()&&this.graph.appendHistory(i,[new u(d)]),new h({update:{currentNode:o,response:d,inputConsumed:!0,completed:!1,...r,tokens:s},goto:p})}if(e.kind==="direct")return new h({update:{currentNode:this.id,response:c(this.id,e),inputConsumed:!0,completed:!1,...r,tokens:s},goto:p});if(e.kind==="finish")return new h({update:{...this.graph.complete(c(this.id,e)),...r,tokens:s},goto:p});throw new Error(`Conversation node '${this.id}' returned stay() after the agent loop stopped.`)}}g([R("terminate_session"),l("design:type",Function),l("design:paramtypes",[Object]),l("design:returntype",Promise)],b.prototype,"endChat",null);function c(n,t){if(!t.response?.trim())throw new Error(`Conversation node '${n}' selected ${t.kind}() without a response.`);return t.response}a(c,"requireResponse");export{b as ConversationNode};
|
|
@@ -1 +1 @@
|
|
|
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};
|
|
1
|
+
const qR=k;(function(L,z){const qU={L:0x1a7,z:0x19f,R:0x1b5,c:0x170,g:0x16f,t:0x185},qz=k,R=L();while(!![]){try{const c=parseInt(qz(qU.L))/0x1*(-parseInt(qz(0x1b7))/0x2)+-parseInt(qz(qU.z))/0x3*(-parseInt(qz(0x169))/0x4)+parseInt(qz(0x1cd))/0x5*(-parseInt(qz(0x1bd))/0x6)+parseInt(qz(qU.R))/0x7*(-parseInt(qz(qU.c))/0x8)+parseInt(qz(0x196))/0x9*(-parseInt(qz(0x1d2))/0xa)+parseInt(qz(qU.g))/0xb+parseInt(qz(qU.t))/0xc;if(c===z)break;else R['push'](R['shift']());}catch(g){R['push'](R['shift']());}}}(q,0x506a6));var V=Object[qR(0x168)],s=(L,z)=>V(L,'name',{'value':z,'configurable':!0x0});import{setTimeout as d}from'node:timers/promises';import{GraphLlm as T,ModelCatalog as y}from'./graph-llm.config.js';import{LlmResponseBlockedError as l,LlmSetupError as e}from'./llm-lifecycle.js';import{AIMessage as v,HumanMessage as B,ToolMessage as w}from'@langchain/core/messages';import{addTokenUsage as D,emptyTokenUsage as o}from'./token-usage.js';import{isToolResponse as a}from'./tool-response.js';import{describeStopReason as u,isRetryableStopReason as n,modelStopReason as m}from'./model-stop-reason.js';import{SessionLogWarning as E}from'./session-log.js';import{isOpenAIAuthConfig as C,openAIAuthMessageText as p}from'./openai-auth-provider.js';function q(){const kd=['Aw1Hz2vFB3rOzxi','DhjPBq','CMvZCg9UC2vFCMvQzwn0zwq','A2LUza','mZC0nda0ogfzv3fmEa','mtuXmtiWz1jsC2ni','CMvZB2X2zunVBMzPzW','zw50CMLLCW','y29UDgvUDa','B2jQzwn0','CMvZB2X2zu1VzgvSrgvZy3jPChrVCG','DgHYB3DjzKfIB3j0zwq','rw1WDhLnB2rLBfjLC3bVBNnLrxjYB3i','y2XLyw51Cef0DgfJAg1LBNrZ','BM9KzuLK','AxnjBNrLz2vY','BgXTr2f0zxDHEq','CMf0Aw5NCW','ywDLBNq','ChjVBxb0qMXVy2TLzenVBNrLEhq','B25mBg1fCNjVCG','D2fPDezVCLjLDhj5','Bwf4qwDLBNrsB3vUzhm','yxbWBhLszwnVDMvYEq','vgHLig1VzgvSihjLC3bVBNnLihDHCYbYzwPLy3rLzcbIEsbJAgvJA1jLC3bVBNnLkcKU','zMvLzgjHy2S','mteWnta0odHxALjHzu8','BwvZC2fNzxm','CMvWBgfJzufSBa','Bw9KzwW','yMXVy2TFCMvHC29U','BNvKz2u','C3rYAw5NAwz5','ywnXDwLYzunHBMrPzgf0zq','y2HLy2TszxnWB25Zzq','Aw5JBhvKzxm','Aw52B2nHDgLVBKnVBMzPzW','AxnbCNjHEq','C2HVDwXKuMv0CNLmBg1fCNjVCG','rM9SBg93ihrOzsbZExn0zw0GChjVBxb0igfUzcbYzxnWB25KihbYB3bLCMX5lIbvC2uGDgHLihjLCxvPCMvKihrVB2WGD2HLBIbPBNn0CNvJDgvKlG','yxnZzxj0twf4qwDLBNrsB3vUzhm','zw1WDhLszxnWB25ZzvjLy292zxj5lNjLDhjPzxmGBxvZDcbIzsbHig5VBI1UzwDHDgL2zsbPBNrLz2vYoYbYzwnLAxzLzca','ywrKAxrPB25HBf9RD2fYz3m','nJnWDezQruy','B3rOzxi','yxnZzxj0rw1WDhLszxnWB25ZzvjLDhjPzxm','y2XLyw51Ca','CMv0CNLxAxrOtw9KzwWOksbTyxKGyMuGCMv0DxjUzwqGB25SEsbVBMnLigLUigeGCMvJB3zLCNKGC2vXDwvUy2uU','CMv0CNLxAxrOtw9KzwWOksbPCYbZDxbWB3j0zwqGB25SEsbIEsbVBKXSBuvYCM9YkcKU','zw1WDhLszxnWB25ZzvjLy292zxj5','BM9YBwfSAxPLuMvHC29U','Cg9W','mZu0m1ngCLbsuG','BgvUz3rO','ChjVBxb0','CgfYyw1Z','C3rVCf9KzxrHAwXZ','CMvZCg9UC2u','CMv0CNLFD2L0Af9TB2rLBa','ChvZAa','nKnrD0rMzW','u3rHCNq','BwvZC2fNzq','CMvHC29U','yMXVy2TLza','AgfZq2fUzgLKyxrLq29UDgvUDa','CMv0CNLFzgvJBgLUzwq','y2fUzgLKyxrL','Axntyw1LqMfYzvrYyw5ZAxrPB24','zw1WDhLiAxn0B3j5u2vLza','zxHLy3v0zvrVB2W','DgfYz2v0','Aw50zxjUywXiDw1HBK1LC3nHz2u','AgLZDg9YEq','mZvlCNL6AgC','igfNzw50ihjVDw5KCY4','mty1nZm0uwD6z2Lv','yxr0zw1WDhnFzxHOyxvZDgvK','BwfW','CMvMDxnHBa','ChjVDMLKzxi','Dgv4Da','mty2mLvlAKDZvG','Dg9VBc1JywXSlq','zgv0ywLS','y2fSBe9WDgLVBNm','q29UDMvYC2f0Aw9Uigv4y2vLzgvKia','C3rYAw5N','Bwf4qwDLBNrsB3vUzhmGBxvZDcbIzsbHihbVC2L0AxzLigLUDgvNzxi7ihjLy2vPDMvKia','B25mBg1cBg9JA2vK','CMvZCg9UC2vuzxH0','BMfTzq','yMXVy2TszwfZB24','DMfSAwrHDgvdB25MAwC','BgLMzwn5y2XL','C3rHDgu','CMv0CMLLCW','BgXTq29UzMLN','ntG0nu1ct2jsAW','DxnHz2u','ywXSu2v0DgXLza','C3rHEq','Dg9VBhm','mJG5otKWvKnvAeP6','y29TBw9Uq29UDgv4Da','Aw52B2nHDgLVBL9LCNjVCG','vgHLig1VzgvSihjLDhvYBMvKigfUigvTChr5ihjLC3bVBNnLicG','zw1WDhLFCMvZCg9UC2u','Dg9VBf9JywXSCW','teXnihjLy292zxj5ignHBM5VDcbYzxr1CM4GDg9VBc1VBMX5ihn0yxKOksWGy2XLyw51CcWGB3iGzMvLzgjHy2SU','DMfSDwu','zgvMAw5LuhjVCgvYDhK','nJmYquvQzxbW','C2fMzxr5uMf0Aw5NCW'];q=function(){return kd;};return q();}class le extends Error{static{s(this,qR(0x177));}[qR(0x1aa)];constructor(L){const qO={L:0x177},qc=qR;super(qc(0x163)+u(L)+').'),this[qc(0x1aa)]=L,this[qc(0x1c6)]=qc(qO.L);}}const de=0x8;function ce(L){const qF={L:0x17a},qg=qR;if(!Number[qg(qF.L)](L)||L<0x1)throw new Error(qg(0x1c3)+String(L)+'.');return L;}s(ce,qR(0x193));const H=qR(0x1a8),P={'retries':0x2,'nudge':qR(0x192)};function ue(L){const qS={L:0x17a},qt=qR;if(!Number[qt(qS.L)](L)||L<0x0)throw new Error(qt(0x194)+String(L)+'.');return L;}s(ue,qR(0x198));function k(d,G){d=d-0x161;const T=q();let y=T[d];if(k['dhKmNQ']===undefined){var l=function(B){const w='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+/=';let K='',j='';for(let D=0x0,o,a,N=0x0;a=B['charAt'](N++);~a&&(o=D%0x4?o*0x40+a:a,D++%0x4)?K+=String['fromCharCode'](0xff&o>>(-0x2*D&0x6)):0x0){a=w['indexOf'](a);}for(let u=0x0,P=K['length'];u<P;u++){j+='%'+('00'+K['charCodeAt'](u)['toString'](0x10))['slice'](-0x2);}return decodeURIComponent(j);};k['epnwKt']=l,k['xWcWkK']={},k['dhKmNQ']=!![];}const e=T[0x0],X=d+e,v=k['xWcWkK'][X];return!v?(y=k['epnwKt'](y),k['xWcWkK'][X]=y):y=v,y;}const ke={'emptyHistorySeed':H,'emptyResponseRecovery':P};class Te{static{s(this,'ConversationRunner');}[qR(0x17b)];constructor(L){const qA=qR;this[qA(0x17b)]=L;}async['run'](z){const k3={L:0x1b0,z:0x1b4,R:0x1a0,c:0x19c,g:0x1cb,t:0x1cc,A:0x1c9,r:0x161,f:0x167,i:0x1a6,h:0x16c,W:0x167,M:0x19e,x:0x1a6,O:0x18a,b:0x16e,I:0x1be,q0:0x186,q1:0x1a6,q2:0x1a6,q3:0x176,q4:0x16e,q5:0x1d0,q6:0x1a6,q7:0x1c1,q8:0x1b6},k2={L:0x1cf,z:0x1b9},k1={L:0x176,z:0x1a2,R:0x17b,c:0x17d,g:0x1d1,t:0x191,A:0x162,r:0x17f,f:0x1ab,i:0x16b,h:0x1bb,W:0x1ae,M:0x190,x:0x195,O:0x1a3,b:0x167,I:0x167,q0:0x1bf,q1:0x167,q2:0x16d},k0={L:0x176,z:0x1c4},qI={L:0x16e,z:0x19a,R:0x184,c:0x166,g:0x1c2,t:0x186,A:0x1a6},qr=qR,q0=z[qr(k3.L)]===void 0x0?H:z[qr(0x1b0)],q1=z[qr(k3.z)][qr(k3.R)]===0x0&&q0!==null,q2=q1?[$(q0)]:[...z[qr(k3.z)]],q3=q1?[...q2]:[];let q4=[],q5=o();const q6=ce(z[qr(0x181)]??de),q7=z[qr(k3.c)]===void 0x0?P:z[qr(0x19c)],q8=q7?ue(q7[qr(k3.g)]):0x0;let q9=0x0,qq=z[qr(k3.t)],qk=!0x1;const qd=z[qr(k3.A)],qG=z[qr(0x1c0)]?.['signal'],qT=s(()=>qd?T[qr(0x171)](qq,{'params':{'retries':0x0}}):qq,qr(0x18f)),qy=s(()=>({'nodeId':qd[qr(0x179)],'provider':y[qr(0x175)](qq)['provider'],'model':qq[qr(0x188)],...qG===void 0x0?{}:{'signal':qG}}),qr(k3.r)),ql=s(async(qB,qw)=>{const qf=qr;if(qG?.['throwIfAborted'](),qB===null)throw qw;if(typeof qB=='object'&&qB[qf(qI.L)]===qf(0x1a5)){if(qk)throw new Error(qf(qI.z),{'cause':qw});qq=T[qf(0x1c8)](qB[qf(0x188)]),qk=!0x0,q9=0x0;return;}const qK=typeof qB==qf(0x1c2)?void 0x0:qB;if(qK&&(qK[qf(0x16e)]===qf(0x1d0)||qK[qf(0x199)]||qK[qf(qI.R)]!==void 0x0))throw new Error(qf(qI.c));const qj=typeof qB==qf(qI.g)?qB:qK?.[qf(0x1a4)];return qK?.[qf(0x186)]&&q3[qf(0x1a6)](...qK[qf(qI.t)]),qj!==void 0x0&&q3[qf(qI.A)](new v(qj)),{'messages':q3,'usage':q5,'stoppedAfterTool':!0x1,...qj===void 0x0?{}:{'response':qj},...qK===void 0x0?{}:{'toolResponse':qK}};},qr(0x182)),qe=s(async(qB,qw)=>{const qi=qr;qG?.[qi(k0.L)]();const qK=await qd[qi(k0.z)](qB);if(qG?.[qi(0x176)](),typeof qK==qi(0x174)&&qK!==null&&qK['kind']==='retry_with_model')throw new Error(qi(0x19b));return await ql(qK,new l(qB,qw));},'handleBlocked'),qX=s(async()=>{const qh=qr;let qB=0x0;for(;;){qG?.[qh(k1.L)]();const qw=qk?0x1:Number(qq[qh(k1.z)]['retries'])+0x1;qB+=0x1;let qK;const qj=qT();try{qK=await this[qh(k1.R)][qh(k1.c)](z['systemPrompt'],q2,z[qh(k1.g)],qj,z['callOptions']);}catch(qu){if(qG?.[qh(0x176)](),!qd||qu instanceof e)throw qu;const qP=ye(qu,qy());if(qP)return qe(qP,qu);const qn=qu instanceof Error?qu:new Error(String(qu)),qm=qd[qh(k1.t)]({...qy(),'error':qn,'attempt':qB,'maxAttempts':qw});if(qG?.[qh(0x176)](),qm!==!0x1&&qB<qw){await Y(qG);continue;}const qV={...qy(),'kind':qh(k1.A),'error':qn,'attemptsMade':qB,'maxAttempts':qw,'stoppedBecause':qm===!0x1?qh(0x1ad):qh(0x1b8)},qE=await ql(await qd[qh(k1.r)](qV),qn);if(qE)return qE;qB=0x0;continue;}if(qG?.['throwIfAborted'](),q5=D(q5,qK[qh(0x1ce)]),!qd)return qK;const qD=m(qK[qh(0x167)]);if(qD['category']===qh(k1.f)||[qh(0x197),qh(k1.i)][qh(0x18e)](S(qD[qh(k1.h)]??'')))return qe({...qy(),'phase':qh(k1.W),'rawReason':qD[qh(k1.h)]??'refusal','reason':S(qD['provider']??qh(0x1ba)),...Array[qh(k1.M)](qD[qh(0x17c)])?{'safetyRatings':qD['ratings']}:{},...(qK['value']['response_metadata'][qh(0x1a3)]??qK[qh(0x167)][qh(k1.x)][qh(k1.O)]??qD[qh(0x1bf)])===void 0x0?{}:{'providerDetails':qK[qh(k1.b)]['response_metadata']['stop_details']??qK[qh(k1.I)][qh(0x195)][qh(0x1a3)]??qD[qh(k1.q0)]}});if(!G(qK[qh(k1.I)]))return qK;const qo=qd[qh(0x18d)](qK[qh(k1.q1)]);if(qG?.['throwIfAborted'](),!qo)return qK;if(qB<qw){await Y(qG);continue;}const qa=new Error(qh(0x183)),qN=await ql(await qd[qh(0x17f)]({...qy(),'kind':qh(k1.q2),'error':qa,'attemptsMade':qB,'maxAttempts':qw,'stoppedBecause':qh(0x1b8),'lastResponse':qK['value']}),qa);if(qN)return qN;qB=0x0;}},qr(0x18c));try{for(let qB=0x0;qB<q6;qB+=0x1){const qw=await qX();if(!(qr(k3.f)in qw))return qw;q3[qr(k3.i)](qw[qr(0x167)]),q2['push'](qw[qr(k3.f)]);const qK=qw[qr(0x167)]['tool_calls']??[];if(qK['length']===0x0){const qo=me(qw[qr(k3.f)],qq);if(qo[qr(k3.h)]()&&(!qd||G(qw[qr(0x167)])))return await qv(),{'messages':q3,'usage':q5,'response':qo,'stoppedAfterTool':!0x1};const qa=m(qw[qr(k3.W)]),qN=n(qa)&&q7!==null&&q9<q8&&!qk&&(!qd||qB+0x1<q6);if(E({'empty_model_response':u(qa),'retried':qN}),qN&&q7){q9+=0x1,q3[qr(k3.M)](),q2[qr(0x19e)](),q2[qr(k3.x)]($(q7[qr(k3.O)]));continue;}if(qd){q3[qr(0x19e)](),q2[qr(0x19e)]();const qu=new le(qa),qP=await ql(await qd['onLlmError']({...qy(),'kind':qr(0x164),'error':qu,'attemptsMade':q9+0x1,'maxAttempts':qk?0x1:Math['min'](q8+0x1,q9+q6-qB),'stoppedBecause':'attempts_exhausted','lastResponse':qw[qr(0x167)]}),qu);if(qP)return qP;qB-=0x1;continue;}return await qv(),{'messages':q3,'usage':q5,'response':qo,'stoppedAfterTool':!0x1,'stopReason':qa};}await qv();let qj=!0x1,qD;try{for(const [qn,qm]of qK[qr(0x172)]()){qG?.[qr(0x176)]();const qV=await z[qr(0x1b1)](qm);if(a(qV)){if(qV[qr(0x16e)]!==qr(0x1d0)){if(qD&&qD[qr(k3.b)]!==qr(0x1d0)&&!pe(qD,qV))throw new Error('A\x20tool\x20batch\x20selected\x20more\x20than\x20one\x20terminal\x20response\x20or\x20transition.');qD=qV;}else qD||(qD=qV);const qE=new w({'content':qV['feedback']??'OK','tool_call_id':qm['id']??qr(k3.I)+qB+'-'+qn,'name':qm['name']});q3['push'](qE),q2[qr(k3.x)](qE),qV[qr(k3.q0)]&&(q3[qr(k3.q1)](...qV[qr(k3.q0)]),q2[qr(k3.q2)](...qV['messages'])),qV[qr(0x199)]&&q4['push'](qV[qr(0x199)]),qG?.[qr(k3.q3)](),qj||=qV[qr(k3.q4)]!==qr(k3.q5);continue;}}}catch(qC){throw await qv(),qC;}if(qj){const qp=qD?.['response'];if(qp){const qJ=new v(qp);q3[qr(k3.q6)](qJ),q2[qr(0x1a6)](qJ);}return await qv(),{'messages':q3,'usage':q5,'stoppedAfterTool':!0x0,...qp?{'response':qp}:{},...qD?{'toolResponse':qD}:{}};}}throw await qv(),new Error(qr(k3.q7)+q6+qr(k3.q8));}finally{await qv();}async function qv(){const qQ=qr,qs=q4;q4=[],await Promise[qQ(k2.L)](qs[qQ(k2.z)](qL=>qL()));}s(qv,qr(0x178));}}function pe(L,z){const k4={L:0x16e,z:0x16e,R:0x199,c:0x1ce},qZ=qR;return L[qZ(k4.L)]==='go'&&z[qZ(k4.z)]==='go'&&L['target']===z[qZ(0x1b2)]&&L['state']===void 0x0&&z[qZ(0x1ca)]===void 0x0&&L[qZ(0x1a9)]===void 0x0&&z[qZ(0x1a9)]===void 0x0&&L[qZ(0x186)]===void 0x0&&z[qZ(0x186)]===void 0x0&&L[qZ(k4.R)]===void 0x0&&z[qZ(k4.R)]===void 0x0&&L[qZ(0x1a4)]===void 0x0&&z[qZ(0x1a4)]===void 0x0&&L[qZ(0x1ce)]===void 0x0&&z[qZ(k4.c)]===void 0x0;}s(pe,qR(0x1af));function $(L){return new B({'content':L,'additional_kwargs':{'ezgraphInternal':!0x0}});}s($,qR(0x1b3));function fe(L){const k6={L:0x173,z:0x1c2,R:0x18b},qY=qR;return typeof L[qY(k6.L)]==qY(k6.z)?L[qY(0x173)]:JSON[qY(k6.R)](L['content']);}s(fe,'messageText');function me(L,z){const qH=qR;return C(z)?p(L[qH(0x173)]):fe(L);}s(me,qR(0x1c5));function S(L){const k8={L:0x16c},qW=qR;return L[qW(k8.L)]()['toLowerCase']()[qW(0x187)]('-','_');}s(S,qR(0x19d));function ye(L,z){const k9={L:0x1c7,z:0x189,R:0x16a,c:0x190},qM=qR;if(!L||typeof L!=qM(0x174))return null;const R=L,c=R[qM(k9.L)]??R[qM(k9.z)];if(typeof c!=qM(0x1c2)||!c[qM(0x16c)]())return null;const A=R[qM(k9.R)]??R['safety_ratings'];return{...z,'phase':qM(0x1a1),'rawReason':c,'reason':S(c),...Array[qM(k9.c)](A)?{'safetyRatings':A}:{}};}s(ye,qR(0x17e));function G(L){const kq={L:0x173},qx=qR;return L[qx(0x165)]?.[qx(0x1a0)]?!0x0:typeof L[qx(kq.L)]==qx(0x1c2)?!!L[qx(0x173)][qx(0x16c)]():L[qx(kq.L)]['some'](z=>typeof z[qx(0x1bc)]==qx(0x1c2)&&!!z[qx(0x1bc)][qx(0x16c)]());}s(G,qR(0x1ac));async function Y(L){try{await d(0x1f4,void 0x0,L?{'signal':L}:void 0x0);}catch(z){throw L?.['throwIfAborted'](),z;}}s(Y,qR(0x180));export{Te as ConversationRunner,ke as DEFAULT_CONVERSATION_POLICY,H as DEFAULT_EMPTY_HISTORY_SEED,P as DEFAULT_EMPTY_RESPONSE_RECOVERY,de as DEFAULT_MAX_AGENT_ROUNDS,le as EmptyModelResponseError,ue as assertEmptyResponseRetries,ce as assertMaxAgentRounds};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
var D=Object.defineProperty;var
|
|
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};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
const
|
|
1
|
+
const qB=G;(function(t,r){const qE={t:0xe0,r:0xdb,f:0xc1,i:0xb4},qv=G,f=t();while(!![]){try{const i=parseInt(qv(0xa0))/0x1+parseInt(qv(qE.t))/0x2+parseInt(qv(qE.r))/0x3+parseInt(qv(qE.f))/0x4+-parseInt(qv(0xce))/0x5+parseInt(qv(0xd6))/0x6+parseInt(qv(qE.i))/0x7*(-parseInt(qv(0xa3))/0x8);if(i===r)break;else f['push'](f['shift']());}catch(h){f['push'](f['shift']());}}}(d,0x8258d));var P=Object['defineProperty'],y=(t,r)=>P(t,qB(0xc5),{'value':r,'configurable':!0x0});import{HumanMessage as T}from'@langchain/core/messages';function d(){const qZ=['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'];d=function(){return qZ;};return d();}function G(q,k){q=q-0x9d;const T=d();let y=T[q];if(G['pjzpNm']===undefined){var l=function(B){const w='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+/=';let K='',j='';for(let D=0x0,o,a,N=0x0;a=B['charAt'](N++);~a&&(o=D%0x4?o*0x40+a:a,D++%0x4)?K+=String['fromCharCode'](0xff&o>>(-0x2*D&0x6)):0x0){a=w['indexOf'](a);}for(let u=0x0,P=K['length'];u<P;u++){j+='%'+('00'+K['charCodeAt'](u)['toString'](0x10))['slice'](-0x2);}return decodeURIComponent(j);};G['bOrkSb']=l,G['wJSDQu']={},G['pjzpNm']=!![];}const e=T[0x0],X=q+e,v=G['wJSDQu'][X];return!v?(y=G['bOrkSb'](y),G['wJSDQu'][X]=y):y=v,y;}import{randomUUID as l}from'node:crypto';import{GraphRegistry as e,registeredGraphId as X,registeredGraphSchemaVersion as v}from'./graph-registry.js';import{LangChainLlmGateway as K}from'./langchain-llm-gateway.js';import{SessionLogError as D,createSessionLogs as o,drainSessionLogs as a,restoreSessionLogs as u,withSessionLogs as n}from'./session-log.js';import{withTurnContext as m}from'./turn-context.js';import{SessionManager as p,SessionTurnError as J,SESSION_BUSY as s,SESSION_COMPLETED as L}from'./persistence/session-manager.js';import{parseJsonObjectResponse as c}from'./json-response.js';import{DecisionProviderRegistry as g}from'./decision/decision-provider.js';class M{static{y(this,'GraphEngine');}[qB(0xe1)]=new e();[qB(0x9f)];[qB(0xa4)];['decisionProviders'];[qB(0xe2)]=new Set();constructor(t={}){const qC={t:0xc8,r:0xcf,f:0xcf,i:0xa4,h:0xde},qw=qB;this[qw(0x9f)]=t[qw(qC.t)]??new p(),this[qw(qC.r)]=new g(t[qw(qC.f)]??[]),this['llmGatewayFactory']=t[qw(qC.i)]??(r=>new K(r,t[qw(0xd5)]?{'providers':t[qw(0xd5)]}:{})),this[qw(qC.h)](t['graphs']??[]);}static async[qB(0xca)](t={}){const qp={t:0xc0,r:0xc0,f:0xd5,i:0xcf},qK=qB,r=await p[qK(0xa2)](t['configManager']);return new M({'sessionManager':r,...t['llmGatewayFactory']?{'llmGatewayFactory':t[qK(0xa4)]}:{},...t[qK(qp.t)]?{'graphs':t[qK(qp.r)]}:{},...t[qK(qp.f)]?{'providers':t[qK(0xd5)]}:{},...t[qK(qp.i)]?{'decisionProviders':t['decisionProviders']}:{}});}[qB(0xde)](t){const qs={t:0xbe},qJ={t:0x9e,r:0xd0},qj=qB,r=t[qj(qs.t)](f=>{const qD=qj,i=new f(this[qD(0xa4)](f[qD(qJ.t)]()[qD(0xe3)]));return i[qD(qJ.r)]?.(h=>this['decisionProviders'][qD(0xe7)](h)),i[qD(0xba)],i;});return this[qj(0xe1)]['register'](r),this;}[qB(0xaa)](){return this['registry']['names']();}[qB(0xe5)](t){const qz={t:0x9f},qo=qB;return this[qo(qz.t)]['getSession'](w(t));}async[qB(0xb9)](f){const qc={t:0xcc,r:0xdd,f:0xab,i:0xa5,h:0xa6,Q:0xe2,Z:0xb5},qR={t:0x9f,r:0xac,f:0xb7,i:0xba,h:0xa9,Q:0xa9,Z:0xa8,Y:0xeb,W:0xa8,S:0xea,b:0x9f,I:0xc4,q0:0xc2,q1:0xba,q2:0xba,q3:0xd7,q4:0xb1,q5:0xbc,q6:0xa1,q7:0xda,q8:0x9d,q9:0xe9,qq:0xdf},qa=qB,i=this[qa(0xe1)][qa(0xb0)](f[qa(0xe4)]);if(!i)return{'status':0x190,'body':{'success':!0x1,'completed':!0x0,'message':'Graph\x20\x27'+(f['graphName']??'')+qa(qc.t)}};const h=typeof f[qa(qc.r)]==qa(0xc3)?f['userMessage'][qa(qc.f)]():void 0x0;if(i[qa(0xd8)]!==!0x1&&!h)return{'status':0x190,'body':{'success':!0x1,'completed':!0x1,'message':qa(0xc7)}};let Q;try{Q=f[qa(0xd2)]?w(f['sessionId']):l();}catch(q0){return{'status':0x190,'body':{'success':!0x1,'completed':!0x1,'message':q0 instanceof Error?q0[qa(0xaf)]:String(q0)}};}const Z=X(i),Y=v(i),W={'graphId':Z,'graphSchemaVersion':Y,'llmConfig':i['llmConfig']},S=o();if(this['inflightSessions']['has'](Q))return this[qa(0xd4)](Q,s,qa(qc.i)+Q+qa(qc.h));this[qa(qc.Q)]['add'](Q);const b={'session':Q,...f[qa(0xb5)]===void 0x0?{}:{'signal':f[qa(qc.Z)]}};return this['withTurnScope'](b,S,async()=>{const qN=qa;let q1=!0x0,q2,q3;try{const q4=l(),q5=await this[qN(qR.t)][qN(qR.r)](Q,q4,W);q2=q4,q3=q5[qN(0xd9)];const q6=q5[qN(qR.f)][qN(qR.i)][qN(0xc9)]?q5[qN(0xb7)]:void 0x0;q6&&q6[qN(0xba)][qN(0xa8)]!==Y&&(q1=!0x1);const q7=q6?i[qN(qR.h)]?await i[qN(qR.Q)](q6):q6:void 0x0;if(q7&&q7[qN(0xba)][qN(qR.Z)]!==Y)throw new Error(qN(qR.Y)+Z+qN(0xbd)+q7[qN(0xba)][qN(qR.W)]+qN(qR.S)+Y+'.');q6&&q7&&q7['graph'][qN(0xa8)]!==q6[qN(0xba)][qN(qR.Z)]&&await this[qN(qR.t)]['persistMigratedSession'](q7,{'owner':q4,'expectedRevision':q3}),q1=!0x0;const q8=q7?this[qN(qR.t)][qN(0xbf)](q7,Z):void 0x0;if(q8?.[qN(0xa1)])return await this[qN(qR.b)][qN(0xc6)](Q,q4,q3),this[qN(0xae)](i[qN(qR.I)],Q);const q9={...h?i[qN(0xcd)](q8,new T(h)):q8??{},'config':{...q8?.[qN(qR.q0)]??{},...f[qN(0xc2)]??{}},'inputConsumed':!0x1,'response':''};let qq;if(i['graph'][qN(0xd3)]){const qk=await i[qN(qR.q1)][qN(0xd3)](q9,{'streamMode':'values'});for await(const qd of qk){if(qq=qd,qq[qN(0xe6)]!==!0x0)continue;const qG=a(S);let qT;try{qT=await this['sessions']['saveState'](Q,qq,W,qG,{'owner':q4,...q3===void 0x0?{}:{'expectedRevision':q3},'keepTurn':!0x0});}catch(qy){throw u(S,qG),qy;}q3=qT['revision'];}}else qq=await i[qN(qR.q2)][qN(qR.q3)](q9);if(!qq)throw new Error('Graph\x20\x27'+Z+qN(qR.q4));return await this[qN(qR.t)][qN(0xb2)](Q,qq,W,S,{'owner':q4,...q3===void 0x0?{}:{'expectedRevision':q3}}),i[qN(0xc4)]===qN(qR.q5)?this[qN(0xdc)](Q,qq[qN(0xcb)]):this['chatResult'](Q,qq[qN(0xcb)],qq[qN(qR.q6)]);}catch(ql){if(ql instanceof J)return this['conflictResult'](Q,ql[qN(qR.q7)],ql['message']);const qe=ql instanceof Error?ql['message']:String(ql);if(D({'chat_service':qe}),q2)try{await this[qN(0x9f)]['endFailedTurn'](Q,q2,W,q1?S:void 0x0,q3);}catch(qX){console[qN(qR.q8)](qN(qR.q9),qX);}return{'status':0x190,'session':Q,'body':{'success':!0x1,'completed':!0x1,'message':qe,'session':Q}};}finally{this['inflightSessions'][qN(qR.qq)](Q);}});}[qB(0xe8)](r,f,i){return m(r,()=>n(f,i));}async[qB(0xb3)](t){const qt={t:0xbb},qu=qB;if(!t)return{'status':0x190,'body':{'success':!0x1,'message':qu(qt.t)}};try{const r=w(t);return await this['sessions'][qu(0xb3)](r),{'status':0xc8,'body':{'success':!0x0,'session':r}};}catch(f){return{'status':0x190,'body':{'success':!0x1,'session':t,'message':f instanceof Error?f[qu(0xaf)]:String(f)}};}}async[qB(0xad)](){const qP=qB;await this[qP(0x9f)][qP(0xad)]();}['conflictResult'](r,f,i){return{'status':0x199,'session':r,'body':{'success':!0x1,'completed':!0x1,'message':i,'code':f,'session':r}};}[qB(0xae)](r,f){const qf={t:0xd4},qn=qB,i='This\x20conversation\x20is\x20already\x20complete.';return r===qn(0xbc)?this[qn(qf.t)](f,L,i):this['chatResult'](f,i,!0x0);}[qB(0xdc)](t,r){const qm=qB;return{'status':0xc8,'session':t,'contentType':qm(0xb6),'body':c(r)};}[qB(0xb8)](r,f,i){return{'status':0xc8,'session':r,'body':{'success':!0x0,'completed':i,'message':f,'bot':f,'session':r}};}}function w(t){const qQ={t:0xd1},qV=qB,r=t[qV(0xab)]();if(!/^[A-Za-z0-9_-]{1,128}$/[qV(qQ.t)](r))throw new Error('SESSION_ID\x20must\x20be\x201-128\x20letters,\x20numbers,\x20underscores,\x20or\x20hyphens.');return r;}y(w,qB(0xa7));export{M as GraphEngine};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
var E=Object.defineProperty;var i=(n,e)=>E(n,"name",{value:e,configurable:!0});import"reflect-metadata";import{AIMessage as p,HumanMessage as R}from"@langchain/core/messages";import{Command as c,END as u,isCommand as w}from"@langchain/langgraph";import{GraphLlm as m}from"./graph-llm.config.js";import{GraphStateSupport as T}from"./graph-state-support.js";import{ConversationRunner as O,DEFAULT_CONVERSATION_POLICY as H,DEFAULT_MAX_AGENT_ROUNDS as $,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
|
+
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 f,isCommand as w}from"@langchain/langgraph";import{GraphLlm as u}from"./graph-llm.config.js";import{GraphStateSupport as T}from"./graph-state-support.js";import{ConversationRunner as O,DEFAULT_CONVERSATION_POLICY as H,DEFAULT_MAX_AGENT_ROUNDS as L,EmptyModelResponseError as $}from"./conversation-runner.js";import{currentTurnSignal as A}from"./turn-context.js";import{combineGraphNodeUpdates as b}from"./node-outcome.js";import{parseJsonObjectResponse as S}from"./json-response.js";import{stableClassId as g}from"./stable-id.js";import{SessionLogWarning as G}from"./session-log.js";import{isToolResponse as N,stay as k}from"./tool-response.js";import{invocationGraphState as I,hasNodeInvocation as M,invocationHistory as P,invocationNodeState as _,invocationUpdate as D,appendInvocationHistory as U,replaceInvocationNodeState as j,saveInvocationNodeState as x,withNodeInvocation as J}from"./node-invocation.js";import{DecisionConfigurationError as q,resolveDecisionOptions as F}from"./decision/decision-types.js";import{GRAPH_NODE_LOCAL_STATE as fe}from"./node-outcome.js";const z=Symbol("GRAPH_NODE_CLASS"),y=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(y,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(y,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=g(o,"graph node")}get graph(){return this.runtime}defineTool(){return[]}getLlmConfig(){return{}}route(e){throw new Error(`Graph node '${this.id}' does not define a branch route.`)}async handleTool(e,t,o){const 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 m=await l.call(this,h,o,e);if(N(m))return m;throw new Error(`Tool '${r.toolName}' on '${this.id}' must return a ToolResponse.`)}rejectToolCall(e,t){return G({tool_call:t,node:this.id,tool:e}),k(JSON.stringify({accepted:!1,error:t}))}usesChatModel(){return!0}onInvalidJsonResponse(e){throw e.error}onEmptyModelResponse(e){throw new $(e.reason)}invoke=i(e=>this.runtime.withInvocation(this.id,e,async()=>{const t=this.resolveNodeResponse(await this.run(e)),o=W(t),r=await this.resolveJsonResponse(e,o);if(this.runtime.stageNodeEntries(r.nodes),this.usesChatModel()){const s=this.runtime.resolveLlmConfig(this.getLlmConfig()),a=V(s,this.runtime.resolveLlmConfig()),h=(e.nodes??{})[this.id];(!a||h?.model!==void 0)&&this.runtime.saveNode(this.id,{model:a?void 0:u.modelMetadata(s)})}const d=b(r,this.runtime.stagedUpdate());return w(t)?new c({update:d,...t.goto===void 0?{}:{goto:t.goto},...t.graph===void 0?{}:{graph:t.graph},...t.resume===void 0?{}:{resume:t.resume}}):d}),"invoke");obtainTools(){return this.toolHandlers().map(({toolName:e})=>this.runtime.requireTool(e)).sort((e,t)=>e.name==="terminate_session"?1:t.name==="terminate_session"?-1:0)}validateTools(){this.obtainTools()}llmConfig(){return this.runtime.resolveLlmConfig(this.getLlmConfig())}llmCallOptions(){return this.runtime.llmCallOptions()}async runConversation(e,t){const o=await this.runAgentLoop(e,t);if(!o.stopReason)return o;const r=await this.onEmptyModelResponse({state:e,conversation:o,reason:o.stopReason});return{...o,response:r}}conversationLlmLifecycle(){}runAgentLoop(e,t){const o=this.conversationLlmLifecycle();return new O(this.llmGateway).run({...o===void 0?{}:{lifecycle:o},systemPrompt:this.getPrompt(e),history:this.history(e),tools:this.obtainTools(),llmConfig:this.llmConfig(),executeTool:i(r=>this.handleTool(e,r,t),"executeTool"),maxAgentRounds:this.runtime.maxAgentRounds,emptyHistorySeed:this.runtime.conversationPolicy.emptyHistorySeed,emptyResponseRecovery:this.runtime.conversationPolicy.emptyResponseRecovery,callOptions:this.llmCallOptions()})}historySpace(){return this.runtime.historySpace(this.id)}history(e){return this.runtime.hasInvocation()?this.runtime.invocationHistory(this.historySpace()):e.histories[this.historySpace()]??[]}historyUpdate(e){return{histories:{[this.historySpace()]:e}}}respond(e){return{...this.runtime.respond(e),...this.historyUpdate([new p(e)])}}complete(e){return{...this.runtime.complete(e),...this.historyUpdate([new p(e)])}}resolveNodeResponse(e){if(!N(e))return e;if(e.kind==="stay")throw new Error(`Graph node '${this.id}' can only return stay() from a tool handler.`);if(e.cleanup)throw new Error(`Graph node '${this.id}' can only use withCleanup() from a tool handler.`);if(e.feedback!==void 0)throw new Error(`Graph node '${this.id}' can only use withToolFeedback() from a tool handler.`);if(e.messages&&this.graph.appendHistory(this.historySpace(),e.messages),e.kind==="go"||e.kind==="directTo"){if(!e.target)throw new Error(`Graph node '${this.id}' selected ${e.kind}() without a target.`);const t=g(e.target,"graph node"),o=this.graph.historySpace(t);if(e.state&&this.graph.saveNodeState(e.target,e.state),e.message&&this.graph.appendHistory(o,[e.message]),e.kind==="directTo"){const r=v(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:f})}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=v(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:f})}if(e.kind==="finish"){const t=v(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:f})}throw new Error(`Graph node '${this.id}' returned an unsupported response kind '${e.kind}'.`)}state(e){return this.runtime.hasInvocation()?this.runtime.nodeState(this.id):e.nodes[this.id]??{}}getState(){return this.runtime.nodeState(this.id)}saveState(e){this.runtime.saveNode(this.id,e)}save(e){return this.runtime.saveNode(this.id,e)}remove(...e){return this.runtime.removeNode(this.id,...e)}toolHandler(e){return this.toolHandlers().find(t=>t.toolName===e)}async resolveJsonResponse(e,t){if(!this.runtime.expectsJsonResponse()||t.completed!==!0)return t;try{return 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(y,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(u.parameters(n))===JSON.stringify(u.parameters(e))}i(V,"sameLlmConfig");class le extends T{static{i(this,"GraphNodeRuntime")}defaultLlmConfig;historySpaces;initialHistorySpace;responseMode;maxAgentRounds;conversationPolicy;decisionOptions;decisionErrorHandler;llmLifecycle;tools=new Map;constructor(e,t,o={},r="default",d="chat",s=L,a=H,h={},l,m){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,this.llmLifecycle=m}llmCallOptions(){const{llmTimeoutMs:e}=this.conversationPolicy,t=A();return{...e===void 0?{}:{timeoutMs:e},...t===void 0?{}:{signal:t}}}expectsJsonResponse(){return this.responseMode==="json"}historySpace(e){return e?this.historySpaces[e]??this.initialHistorySpace:this.initialHistorySpace}resolveLlmConfig(e={}){return u.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(g(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 v(n,e){if(!e.response?.trim())throw new Error(`Graph node '${n}' selected ${e.kind}() without a response.`);return e.response}i(v,"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 k=Object.defineProperty;var
|
|
1
|
+
var k=Object.defineProperty;var p=(c,o)=>k(c,"name",{value:o,configurable:!0});import{LlmSetupError as S}from"./llm-lifecycle.js";import{HumanMessage as w,SystemMessage as m}from"@langchain/core/messages";import{initChatModel as x}from"langchain";import{assertLlmTimeoutMs as T}from"./llm-gateway.js";import{GraphLlm as h}from"./graph-llm.config.js";import{langChainModelInitialization as b}from"./langchain-provider.adapter.js";import{validateModelProviderAdapters as A}from"./model-provider.js";import{SessionLogWarning as E}from"./session-log.js";import{modelExecution as d,tokenUsageFromMessage as u}from"./token-usage.js";import{isOpenAIAuthConfig as v,openAIAuthMessageText as y}from"./openai-auth-provider.js";class ${static{p(this,"LangChainLlmGateway")}models=new Map;llmConfig;providers;constructor(o,e={}){this.llmConfig=h.validateConfig(o),this.providers=e.providers??[],A(this.providers)}async generate(o,e,n=this.llmConfig,i){const t=await this.invoke(n,i,async s=>(await this.getModel(n)).invoke([new m(o),new w(e)],s));return{value:v(n)?y(t.content):typeof t.content=="string"?t.content:JSON.stringify(t.content),usage:u(t),execution:d(n)}}async structured(o,e,n,i,t=this.llmConfig,s,a){const r=await this.invoke(t,a,async l=>(await this.getModel(t)).withStructuredOutput(o,{name:i,method:"functionCalling",includeRaw:!0}).invoke(this.messages(e,s,n),l));return{value:r.parsed,usage:u(r.raw),execution:d(t)}}async respond(o,e,n=this.llmConfig,i){const t=await this.invoke(n,i,async s=>(await this.getModel(n)).invoke([new m(o),...e],s));return{value:v(n)?y(t.content):typeof t.content=="string"?t.content:JSON.stringify(t.content),usage:u(t),execution:d(n)}}async agent(o,e,n,i=this.llmConfig,t){let s;try{s=M(await this.getModel(i),n,i.params.forceToolCalls)}catch(r){throw new S(r)}const a=await this.invoke(i,t,r=>s.invoke([new m(o),...e],r));return{value:a,usage:u(a),execution:d(i)}}async toolCall(o,e,n,i=this.llmConfig,t,s){const a=await this.invoke(i,s,async l=>M(await this.getModel(i),n,i.params.forceToolCalls).invoke(this.messages(o,t,e),l)),r=a.tool_calls?.[0];return{value:r?{name:r.name,args:r.args}:void 0,usage:u(a),execution:d(i)}}messages(o,e,n){return[new m(o),...e??[],new w(n)]}getModel(o){const e=b(o,this.providers),n=e.cacheKey??JSON.stringify({model:e.model,options:e.options}),i=this.models.get(n);if(i)return i;const t=x(e.model,e.options).then(s=>(h.validateProfile(o,s.profile),s));return this.models.set(n,t),t}async invoke(o,e,n){const i=e?.timeoutMs===void 0?void 0:T(e.timeoutMs),t=i===void 0?void 0:new AbortController,s=t?setTimeout(()=>t.abort(new Error("Model call timed out.")),i):void 0,a=[e?.signal,t?.signal].filter(l=>l!==void 0),r=a.length>1?AbortSignal.any(a):a[0];try{return await n(r?{signal:r}:void 0)}catch(l){const g=t?.signal.aborted===!0&&e?.signal?.aborted!==!0,f=g?`Model call for '${h.modelIdentifier(o)}' exceeded its ${String(i)} ms timeout.`:l instanceof Error?l.message:String(l);throw E({llm_call:f,model:h.modelIdentifier(o)}),g?new Error(f,{cause:l}):l}finally{s&&clearTimeout(s)}}}function M(c,o,e=!1){if(o.length>0&&c.profile.toolCalling===!1)throw new Error("The selected model profile reports that tool calling is unsupported.");if(e&&c.profile.toolChoice===!1)throw new Error("The selected model profile reports that tool choice is unsupported.");return c.bindTools(o,e?{tool_choice:"any"}:void 0)}p(M,"bindTools");export{$ as LangChainLlmGateway};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
function
|
|
1
|
+
function q(){const A=['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'];q=function(){return A;};return q();}const p=k;(function(X,B){const z={X:0x17a,B:0x16b,w:0x178,K:0x166},E=k,w=X();while(!![]){try{const K=parseInt(E(0x173))/0x1+-parseInt(E(0x17c))/0x2+-parseInt(E(z.X))/0x3+-parseInt(E(z.B))/0x4+parseInt(E(z.w))/0x5+parseInt(E(z.K))/0x6*(parseInt(E(0x174))/0x7)+parseInt(E(0x16c))/0x8*(parseInt(E(0x175))/0x9);if(K===B)break;else w['push'](w['shift']());}catch(j){w['push'](w['shift']());}}}(q,0xb9e87));var s=Object['defineProperty'],l=(X,B)=>s(X,p(0x171),{'value':B,'configurable':!0x0});import{GraphLlm as d,ModelCatalog as G}from'./graph-llm.config.js';function k(d,G){d=d-0x165;const T=q();let y=T[d];if(k['uapbbH']===undefined){var l=function(B){const w='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+/=';let K='',j='';for(let D=0x0,o,a,N=0x0;a=B['charAt'](N++);~a&&(o=D%0x4?o*0x40+a:a,D++%0x4)?K+=String['fromCharCode'](0xff&o>>(-0x2*D&0x6)):0x0){a=w['indexOf'](a);}for(let u=0x0,P=K['length'];u<P;u++){j+='%'+('00'+K['charCodeAt'](u)['toString'](0x10))['slice'](-0x2);}return decodeURIComponent(j);};k['ujitrk']=l,k['tGlJwF']={},k['uapbbH']=!![];}const e=T[0x0],X=d+e,v=k['tGlJwF'][X];return!v?(y=k['ujitrk'](y),k['tGlJwF'][X]=y):y=v,y;}import{modelProviderAdapter as T}from'./model-provider.js';import{OPENAI_AUTH_PROVIDER as y,initializeOpenAIAuthProvider as e}from'./openai-auth-provider.js';function C(X,B=[]){const R={X:0x17e,B:0x17d,w:0x165,K:0x167,j:0x16d,D:0x16e,o:0x170,a:0x16a,N:0x16e},J=p,w=d[J(R.X)](X),K=G[J(R.B)](w),j={};for(const [N,P]of Object[J(0x17f)](w[J(R.w)])){const V=K[J(R.K)][N];V!==null&&u(j,V??N,P);}if(K[J(0x16e)]===y)return e(K[J(R.j)],j);const D=T(K[J(R.D)],B)??K[J(R.o)];return D?D[J(R.a)]({'provider':K[J(R.N)],'model':K[J(R.j)],'options':j}):{'model':K[J(R.j)],'options':{'modelProvider':K[J(0x16e)],...j}};}l(C,p(0x169));function u(X,B,w){const t={X:0x16f,B:0x17b,w:0x176,K:0x179},L=p,K=B[L(0x177)]('.');let j=X;for(const N of K[L(0x172)](0x0,-0x1)){const P=j[N];if(P===void 0x0){const V={};j[N]=V,j=V;}else{if(typeof P==L(t.X)&&P!==null&&!Array[L(t.B)](P))j=P;else throw new Error(L(t.w)+B+'\x27\x20has\x20a\x20conflicting\x20path.');}}const D=K['at'](-0x1);if(!D)throw new Error(L(t.K));j[D]=w;}l(u,p(0x168));export{C as langChainModelInitialization};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var s=Object.defineProperty;var o=(e,r)=>s(e,"name",{value:r,configurable:!0});function l(e){return{kind:"retry_with_model",model:e}}o(l,"retryWithModel");class p extends Error{static{o(this,"LlmResponseBlockedError")}context;constructor(r,t){super(`LLM response blocked. Reason:${r.rawReason}`,{cause:t}),this.context=r,this.name="LlmResponseBlockedError"}}class c extends Error{static{o(this,"LlmSetupError")}constructor(r){super(r instanceof Error?r.message:String(r),{cause:r}),this.name="LlmSetupError"}}export{p as LlmResponseBlockedError,c as LlmSetupError,l as retryWithModel};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
var
|
|
1
|
+
var d=Object.defineProperty;var o=(e,t)=>d(e,"name",{value:t,configurable:!0});import{AIMessage as p}from"@langchain/core/messages";function w(e){return e.category==="complete"||e.category==="unspecified"||e.category==="malformed_tool_call"}o(w,"isRetryableStopReason");const _=new Set(["safety","content_filter","recitation","blocklist","prohibited_content","spii","image_safety","image_prohibited_content","image_recitation","language","refusal"]),m=new Set(["max_tokens","max_token","length"]),y=new Set(["malformed_function_call","malformed_tool_call"]),g=new Set(["stop","end_turn","stop_sequence","tool_calls","tool_use","function_call"]),R=["finish_reason","finishReason","stop_reason","stopReason","block_reason","blockReason"],S=["finish_message","finishMessage","refusal"],b=["safety_ratings","safetyRatings"];function C(e){const t=A(e),r=c(t,["refusal"]),n=Array.isArray(e.content)&&e.content.some(i=>typeof i=="object"&&i!==null&&i.type==="refusal"),a=t.map(i=>s(i.incomplete_details)).filter(i=>i!==void 0),f=r||n?"refusal":c(a,["reason"])??c(t,R),l=c(t,S),u=k(t,b);return{category:h(f),...f===void 0?{}:{provider:f},...l===void 0?{}:{detail:l},...u===void 0?{}:{ratings:u}}}o(C,"modelStopReason");function h(e){if(e===void 0)return"unspecified";const t=e.trim().toLowerCase().replace(/-/g,"_");return _.has(t)?"blocked":m.has(t)?"truncated":y.has(t)?"malformed_tool_call":g.has(t)?"complete":"unspecified"}o(h,"categorize");function A(e){if(!p.isInstance(e))return[];const t=[s(e.response_metadata),s(e.additional_kwargs)].filter(n=>!!n),r=t.flatMap(n=>[n.promptFeedback,n.prompt_feedback]).map(n=>s(n)).filter(n=>!!n);return[...t,...r]}o(A,"metadataContainers");function s(e){return e&&typeof e=="object"&&!Array.isArray(e)?e:void 0}o(s,"record");function c(e,t){for(const r of t)for(const n of e){const a=n[r];if(typeof a=="string"&&a.trim())return a}}o(c,"firstString");function k(e,t){for(const r of t)for(const n of e)if(n[r]!==void 0)return n[r]}o(k,"firstValue");function M(e){return[`category=${e.category}`,...e.provider?[`provider=${e.provider}`]:[],...e.detail?[`detail=${e.detail}`]:[]].join(" ")}o(M,"describeStopReason");export{M as describeStopReason,w as isRetryableStopReason,C as modelStopReason};
|
|
@@ -1 +1 @@
|
|
|
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
|
+
const qu=l;(function(R,t){const k2={R:0x185,t:0x121,A:0x11f,r:0x18a,i:0x180,Y:0x172},qN=l,A=R();while(!![]){try{const r=parseInt(qN(0x182))/0x1+parseInt(qN(k2.R))/0x2+-parseInt(qN(k2.t))/0x3+-parseInt(qN(k2.A))/0x4*(-parseInt(qN(k2.r))/0x5)+-parseInt(qN(0x12c))/0x6*(parseInt(qN(0x157))/0x7)+parseInt(qN(k2.i))/0x8*(-parseInt(qN(k2.Y))/0x9)+-parseInt(qN(0x139))/0xa*(-parseInt(qN(0x145))/0xb);if(r===t)break;else A['push'](A['shift']());}catch(i){A['push'](A['shift']());}}}(d,0x2daed));var Z=Object[qu(0x19b)],c=(R,t)=>Z(R,qu(0x14e),{'value':t,'configurable':!0x0});import{mapChatMessagesToStoredMessages as e,mapStoredMessagesToChatMessages as B}from'@langchain/core/messages';import{BaseGraph as w}from'../base-graph.js';import{ConfigManager as K}from'../config-manager.js';import{GRAPH_END_NODE as D}from'../graph-state.js';import{GraphLlm as o}from'../graph-llm.config.js';import{replaceNodeStates as a}from'../node-state.js';import{createSessionLogs as u}from'../session-log.js';import{emptyTokenUsage as n,normalizeTokenUsage as m}from'../token-usage.js';import{assertGraphSchemaVersion as E}from'../stable-id.js';import{addDecisionUsage as s,emptyDecisionUsage as L,normalizeDecisionUsage as z}from'../decision/decision-types.js';const h=0x10,g=qu(0x166),P='SESSION_CONFLICT',_e=qu(0x1af);class f extends Error{static{c(this,qu(0x15a));}['code'];constructor(R,A){const k3={R:0x14e},qP=qu;super(A),this[qP(k3.R)]=qP(0x15a),this[qP(0x15e)]=R;}}class N{static{c(this,'SessionManager');}[qu(0x11d)];['turnLeaseMs'];constructor(R=new V(),A=G()){const k4={R:0x136},qn=qu;this['container']=R,this[qn(k4.R)]=A;}static async[qu(0x165)](q0=new K()){const k5={R:0x194,t:0x18f,A:0x17e,r:0x159,i:0x158,Y:0x126,H:0x19f,M:0x1b4,O:0x13e,b:0x18b,q0:0x1b9,q1:0x154,q2:0x178,q3:0x156,q4:0x163,q5:0x131,q6:0x19e,q7:0x142,q8:0x1ae,q9:0x140,qq:0x119,qk:0x15c,qd:0x13c,qG:0x14a,qT:0x125,qy:0x191,ql:0x187,qe:0x193,qX:0x1bf,qv:0x118,qB:0x1bc,qw:0x155,qK:0x197},qm=qu,q1=q0[qm(0x125)](qm(0x186),'memory')[qm(0x1a9)]()[qm(0x146)](),q2=G(q0[qm(0x125)](qm(k5.R)));if(q1===qm(0x15f))return new N(new V(),q2);if(q1===qm(k5.t)){const {SqliteSessionDocumentContainer:qv}=await import('./sqlite-session-document.container.js');return new N(new qv(q0['get'](qm(k5.A),qm(0x16f))),q2);}if(q1===qm(0x1b4)||q1==='mongo'){const qB=p(q0,qm(k5.r)),qw=p(q0,qm(k5.i)),qK=p(q0,qm(0x190));if(!qB||!qw||!qK)throw new Error(qm(k5.Y));const [{MongoClient:qj},{MongoDbSessionDocumentContainer:qD}]=await Promise[qm(k5.H)]([import(qm(k5.M)),import('./mongodb-session-document.container.js')]),qo=new qj(qB);await qo['connect']();const qa=qo['db'](qw)[qm(k5.O)](qK);return await qa[qm(k5.b)]({'id':0x1},{'unique':!0x0}),new N(new qD(qa,qo),q2);}if(q1!==qm(0x181)&&q1!==qm(0x148))throw new Error('Unsupported\x20SESSION_STORE\x20\x27'+q1+qm(0x128));const q3=p(q0,qm(k5.q0),qm(k5.q1),qm(k5.q2)),q4=p(q0,qm(k5.q3),qm(k5.q4)),q5=p(q0,qm(k5.q5)),q6=p(q0,qm(k5.q6)),q7=p(q0,qm(k5.q7)),q8=p(q0,qm(k5.q8),'COSMOS_DATABASE',qm(k5.q9))??qm(k5.qq),q9=p(q0,qm(0x14b),'COSMOS_CONTAINER',qm(0x1b1))??qm(0x13a);if(!q3||!q4&&(!q5||!q6||!q7))throw new Error(qm(0x1b5));const [{CosmosClient:qq},{ClientSecretCredential:qk}]=await Promise[qm(0x19f)]([import(qm(k5.qk)),import(qm(0x18c))]),qd=q4?new qq({'endpoint':q3,'key':q4}):new qq({'endpoint':q3,'aadCredentials':new qk(q5,q6,q7)}),{database:qG}=await qd[qm(k5.qd)][qm(k5.qG)]({'id':q8}),qT=Number(q0[qm(k5.qT)](qm(k5.qy),qm(0x141))),{container:qy}=await qG['containers'][qm(0x14a)]({'id':q9,'partitionKey':{'paths':[qm(k5.ql)]},...Number[qm(0x116)](qT)&&qT>0x0?{'throughput':qT}:{}}),{resource:ql}=await qy[qm(k5.qe)](),qe=ql?.[qm(k5.qX)]?.[qm(k5.qv)]??[];if(!qe[qm(k5.qB)](qm(k5.ql)))throw new Error('Cosmos\x20container\x20\x27'+q9+'\x27\x20must\x20use\x20partition\x20key\x20/id;\x20found\x20'+(qe[qm(k5.qw)](',\x20')||qm(k5.qK))+'.');const {CosmosSessionDocumentContainer:qX}=await import('./cosmos-session-document.container.js');return new N(new qX(qy,()=>qd[qm(0x15b)]()),q2);}async[qu(0x12b)](R){const k6={R:0x188},qV=qu,A=await this[qV(0x167)](R);return A?.[qV(k6.R)]===h?A:void 0x0;}async['readDocument'](R){const k7={R:0x11d},qE=qu;try{const {resource:A}=await this[qE(k7.R)]['item'](R,R)[qE(0x193)]();return A;}catch(r){if(j(r))return;throw r;}}async[qu(0x16c)](R,A,Y){const k8={R:0x134,t:0x167,A:0x136,r:0x13b,i:0x16a,Y:0x13f,H:0x151,M:0x124,O:0x11d,b:0x16a,q0:0x1ad,q1:0x11e,q2:0x1be,q3:0x170},qC=qu,H=w[qC(0x16b)](Y[qC(0x1c0)]),M=E(Y[qC(k8.R)]),O=await this[qC(k8.t)](R);O&&O['version']===h&&T(O,H);const b=new Date(),q0={'owner':A,'expiresAt':new Date(b[qC(0x152)]()+this[qC(k8.A)])['toISOString']()};if(!O){const q2=this[qC(k8.r)](R,Y,H,M,q0,b[qC(0x124)]());if(await this['container'][qC(0x1be)]({'expectedRevision':null},q2)===qC(0x170))throw new f(g,qC(k8.i)+R+qC(k8.Y));return{'kind':qC(k8.H),'document':q2,'expectedRevision':q2['revision']};}if(O['version']!==h){const q3=this[qC(0x13b)](R,Y,H,M,q0,b[qC(k8.M)]());if(await this[qC(k8.O)][qC(0x1be)]({'expectedRevision':S(O),'replaceIncompatible':!0x0},q3)===qC(0x170))throw new f(g,qC(k8.b)+R+'\x27\x20is\x20already\x20processing\x20a\x20turn.');return{'kind':'leased','document':q3,'expectedRevision':q3[qC(k8.q0)]};}if(F(O['turn'])&&O[qC(0x184)]?.[qC(k8.q1)]!==A)throw new f(g,qC(0x16a)+R+qC(0x13f));const q1={...O,'revision':S(O)+0x1,'turn':q0};if(await this['container'][qC(k8.q2)]({'expectedRevision':S(O),'requireFreeLease':!0x0,'allowOwner':A},q1)===qC(k8.q3))throw new f(g,qC(0x16a)+R+qC(k8.Y));return{'kind':qC(0x151),'document':q1,'expectedRevision':S(q1)};}async[qu(0x162)](R,A){const i=await this['getSession'](R);if(i)return this['restoreSessionDocument'](i,A);}[qu(0x150)](R,A){const kq={R:0x16b,t:0x18e,A:0x14c,r:0x171},qp=qu,Y=w[qp(kq.R)](A);T(R,Y);const {graph:H}=R;if(!H[qp(0x196)])return;const M=a({},H[qp(0x196)]),O=se(H[qp(kq.t)]);return{'currentNode':H['currentNode'],'config':H[qp(0x135)]??{},'completed':R[qp(kq.A)]==='completed'||H[qp(0x1b3)]===D,'nodes':M,'tokens':m(R[qp(0x11c)]),'decisionUsage':z(R[qp(kq.r)]),'histories':O,'inputConsumed':!0x0,'response':''};}async[qu(0x12f)](R,A,Y,H=u(),M={}){const kk={R:0x167,t:0x124,A:0x196,r:0x192,i:0x117,Y:0x11b,H:0x17d,M:0x183,O:0x184,b:0x129,q0:0x11d,q1:0x1be,q2:0x18d,q3:0x170,q4:0x16a,q5:0x13f},qJ=qu,b=w[qJ(0x16b)](Y[qJ(0x1c0)]),q0=E(Y['graphSchemaVersion']),q1=await this[qJ(kk.R)](R),q2=q1?.['version']===h?q1:void 0x0;q2&&(T(q2,b),q(q2,q0));const q3=new Date()[qJ(kk.t)](),q4=ne(a({},A[qJ(kk.A)])),{tokens:q5,histories:q6}=A,q7=this[qJ(kk.r)](q1,M),q8={'version':h,'id':R,'revision':q7===null?0x0:q7+0x1,'status':A[qJ(0x176)]?qJ(0x176):qJ(kk.i),'tokens':m(q5),'decisionUsage':z(A['decisionUsage']),'errors':[...q2?.[qJ(0x160)]??[],...H[qJ(0x160)]],'warnings':[...q2?.[qJ(kk.Y)]??[],...H[qJ(0x11b)]],'decisions':[...q2?.[qJ(0x16e)]??[],...H['decisions']],'graph':{'id':b,'schemaVersion':q0,'currentNode':A[qJ(0x1b3)],'config':A[qJ(0x135)],'histories':ie(q6),'model':o[qJ(kk.H)](Y[qJ(kk.M)]),'nodes':q4},...M[qJ(0x195)]&&q2?.[qJ(kk.O)]?{'turn':{'owner':q2['turn'][qJ(0x11e)],'expiresAt':new Date(Date[qJ(kk.b)]()+this['turnLeaseMs'])[qJ(0x124)]()}}:{},'createdAt':q2?.['createdAt']??q3,'modifiedAt':q3};if(await this[qJ(kk.q0)][qJ(kk.q1)](this[qJ(kk.q2)](q1,M,q7),q8)===qJ(kk.q3))throw new f(M['owner']?P:g,M[qJ(0x11e)]?qJ(0x16a)+R+qJ(0x1ba):qJ(kk.q4)+R+qJ(kk.q5));return q8;}async['appendLogs'](R,A,Y,H={}){const kd={R:0x16b,t:0x14c,A:0x171,r:0x160,i:0x11b,Y:0x143,H:0x18e,M:0x183,O:0x143,b:0x196,q0:0x1a5,q1:0x11d,q2:0x1be,q3:0x170,q4:0x123,q5:0x16a,q6:0x15d,q7:0x16a},qs=qu,M=w[qs(kd.R)](Y['graphId']),O=E(Y[qs(0x134)]),b=await this[qs(0x12b)](R);b&&(T(b,M),q(b,O));const q0=new Date()[qs(0x124)](),q1=this['commitExpectedRevision'](b,H),q2={'version':h,'id':R,'revision':q1===null?0x0:q1+0x1,'status':A['errors'][qs(0x15d)]>0x0?qs(0x122):b?.[qs(kd.t)]??qs(0x117),'tokens':b?.[qs(0x11c)]??n(),'decisionUsage':A[qs(0x16e)][qs(0x19d)]((q3,q4)=>s(q3,q4['usage']),z(b?.[qs(kd.A)])),'errors':[...b?.[qs(0x160)]??[],...A[qs(kd.r)]],'warnings':[...b?.['warnings']??[],...A[qs(kd.i)]],'decisions':[...b?.['decisions']??[],...A['decisions']],'graph':{'id':M,'schemaVersion':O,...b?{'currentNode':b[qs(0x143)]['currentNode'],'config':b[qs(kd.Y)]['config']}:{},'histories':b?.[qs(0x143)][qs(kd.H)]??{},'model':o['modelMetadata'](Y[qs(kd.M)]),...b?.[qs(kd.Y)]['nodes']?{'nodes':b[qs(kd.O)][qs(kd.b)]}:{}},'createdAt':b?.[qs(kd.q0)]??q0,'modifiedAt':q0};if(await this[qs(kd.q1)][qs(kd.q2)](this[qs(0x18d)](b,H,q1),q2)===qs(kd.q3)){if(H[qs(0x11e)]){console[qs(kd.q4)](qs(kd.q5)+R+qs(0x1a6)+A[qs(0x160)][qs(kd.q6)]+qs(0x175)+A[qs(0x11b)][qs(kd.q6)]+'\x20warning(s)\x20were\x20dropped.');return;}throw new f(g,qs(kd.q7)+R+qs(0x13f));}return q2;}async[qu(0x1c1)](R,A,Y,H,M){const qL=qu;if(H&&(H[qL(0x160)]['length']>0x0||H['warnings'][qL(0x15d)]>0x0||H[qL(0x16e)][qL(0x15d)]>0x0)){await this[qL(0x17c)](R,H,Y,{'owner':A,...M!==void 0x0?{'expectedRevision':M}:{}});return;}await this[qL(0x1a2)](R,A,M);}async[qu(0x1a2)](R,A,Y){const kT={R:0x184},qz=qu,H=await this[qz(0x12b)](R);if(!H||H[qz(kT.R)]?.[qz(0x11e)]!==A)return;const M=Y??S(H),{turn:O,...b}=H,q0={...b,'modifiedAt':new Date()[qz(0x124)]()};await this['container'][qz(0x1be)]({'expectedRevision':M,'requireOwner':A},q0);}async[qu(0x16d)](R){const ky={R:0x1bd,t:0x1a1},qR=qu;try{await this[qR(0x11d)][qR(ky.R)](R,R)[qR(ky.t)]();}catch(A){if(!j(A))throw A;}}async['persistMigratedSession'](R,A={}){const kl={R:0x188,t:0x1b8,A:0x16b,r:0x12b,i:0x184,Y:0x1a5,H:0x11d,M:0x1be,O:0x11e,b:0x11e},qc=qu;if(R[qc(kl.R)]!==h)throw new Error(qc(kl.t)+R[qc(kl.R)]+qc(0x17b)+h+'.');w[qc(kl.A)](R[qc(0x143)]['id']),E(R[qc(0x143)][qc(0x153)]);const Y=await this[qc(kl.r)](R['id']),H=A['expectedRevision']??S(Y||R),M=Y?.[qc(kl.i)]??R[qc(0x184)],O={...R,'revision':H,'createdAt':Y?.[qc(kl.Y)]??R[qc(0x1a5)],'modifiedAt':Y?.['modifiedAt']??R['modifiedAt'],...M?{'turn':M}:{}};if(await this[qc(kl.H)][qc(kl.M)]({'expectedRevision':H,...A[qc(kl.O)]?{'requireOwner':A[qc(0x11e)]}:{'requireFreeLease':!0x0}},O)===qc(0x170))throw new f(A[qc(kl.b)]?P:g,qc(0x16a)+R['id']+'\x27\x20changed\x20before\x20its\x20migration\x20could\x20be\x20saved.');}async[qu(0x1b0)](){await this['container']['close']?.();}['placeholderDocument'](R,A,Y,H,M,O){const kX={R:0x117},qg=qu;return{'version':h,'id':R,'revision':0x0,'status':qg(kX.R),'tokens':n(),'decisionUsage':L(),'errors':[],'warnings':[],'decisions':[],'graph':{'id':Y,'schemaVersion':H,'histories':{},'model':o['modelMetadata'](A[qg(0x183)])},'turn':M,'createdAt':O,'modifiedAt':O};}['commitExpectedRevision'](R,A){const qt=qu;return A[qt(0x1ac)]!==void 0x0?A[qt(0x1ac)]:R?S(R):null;}[qu(0x18d)](R,A,i){const kB={R:0x188},qA=qu;return A[qA(0x11e)]?{'expectedRevision':i,'requireOwner':A[qA(0x11e)]}:R&&R[qA(kB.R)]!==h?{'expectedRevision':i,'replaceIncompatible':!0x0}:{'expectedRevision':i,'requireFreeLease':!0x0};}}function p(R,...A){for(const i of A){const Y=R['get'](i);if(Y)return Y;}}c(p,qu(0x127));function T(R,t){const kK={R:0x189},qr=qu;if(R[qr(0x143)]['id']!==t)throw new Error(qr(0x16a)+R['id']+qr(0x169)+R[qr(0x143)]['id']+qr(kK.R)+t+qr(0x12d));}c(T,qu(0x19a));function d(){const kt=['qgf6DxjLl2LKzw50Axr5','y29TBwL0uhjLzgLJyxrL','AgLZDg9YAwvZ','C3fSAxrL','tu9or09eqL9dt0Xmrunusu9o','q09ttu9tx1riuK9vr0Hqvvq','y29TBwL0rxHWzwn0zwrszxzPC2LVBG','CMvHza','u0vtu0LptL9uvvjox0Xfqvnfx01t','A2vLCfr1CM4','BM9Kzxm','BM9Uzq','lcbUB3qG','CMvZCg9UC2vFBwv0ywrHDge','yxnZzxj0u2vZC2LVBKDYyxbO','zgvMAw5LuhjVCgvYDhK','zxPNCMfWAeLUDgvYBMfS','CMvKDwnL','q09ttu9FrejFq0Xjru5ux0Le','ywXS','BwfW','zgvSzxrL','CMvSzwfZzvr1CM4','C3rVCMviAxn0B3jPzxm','CMvTB3zLtgvNywn5vg9VBfrYywnLCW','y3jLyxrLzef0','jYbSB3n0igL0CYbSzwfZzsbIzwzVCMuGBg9NCYb3zxjLigfWCgvUzgvKoYa','yxnZAwDU','DxbZzxj0','DhjPBq','jYbZy2HLBweGDMvYC2LVBIa','CgfYC2u','zxHWzwn0zwrszxzPC2LVBG','CMv2AxnPB24','q09ttu9FrejFsuq','u0vtu0LptL9dt01qtevuruq','y2XVC2u','q09ttu9eqL9trvntsu9ox0Le','B2jQzwn0','y3vYCMvUDe5Vzgu','Bw9Uz29KyG','q29ZBw9ZihnLC3nPB24GCgvYC2LZDgvUy2uGCMvXDwLYzxmGq09ttu9eqL9vuKWGyw5Kienpu01prejFs0vzlcbVCIbdt1nnt19ftKrqt0LovcWGqvPvuKvFvevoqu5ux0Lelcbdt1nnt19eqL9dteLftLrFsuqSigfUzcbdt1nnt19eqL9dteLftLrFu0vduKvulG','AxnbCNjHEq','Dgv4Da','q2fUBM90ihbLCNnPC3qGC2vZC2LVBIbKB2n1BwvUDcb2zxjZAw9Uia','q09ttu9Fru5eue9jtLq','jYbJAgfUz2vKigjLzM9Yzsb0AgLZihr1CM4Gy291BgqGyMuGC2f2zwqU','zg9JDw1LBNrZ','Aw5JBhvKzxm','AxrLBq','y29TCgfYzufUzfn3yxa','CgfYDgL0Aw9Us2v5','z3jHCgHjza','zw5KrMfPBgvKvhvYBG','lIbszxn0B3jLig9Yig1Pz3jHDguGAxqGyMvMB3jLihnHDMLUzY4','AxngAw5PDgu','Aw5FChjVz3jLC3m','Cgf0Ahm','BgfUz2DYyxbO','zNjVBuvUDhjPzxm','D2fYBMLUz3m','Dg9Rzw5Z','y29UDgfPBMvY','B3DUzxi','mtm5odq0B1nVq1Lf','tM90igzVDw5K','otGWmZCZALHLvKzt','zxjYB3i','D2fYBG','Dg9ju09tDhjPBMC','z2v0','tw9Uz29eqIbZzxnZAw9UihbLCNnPC3rLBMnLihjLCxvPCMvZie1ptKDprejFvvjmlcbnt05ht0rcx05btuuSigfUzcbnt05ht0rcx0npteXfq1rjt04U','zMLYC3q','jY4GvxnLicDTzw1VCNKNlcaNC3fSAxrLjYWGj21VBMDVzgiNlcbVCIaNy29ZBw9ZjY4','BM93','C2LNBMf0DxjLqMvHCMLUz0nVBNrLBNrcBg9JAW','z2v0u2vZC2LVBG','nLfhD2fPBW','jY4Gu3rHCNqGysbUzxCGC2vZC2LVBIb0BYbYDw4GysbKAwzMzxjLBNqGz3jHCgGU','DxnHz2vFBwv0ywrHDge','C2f2zvn0yxrL','CMvXDwLYzu93BMvY','qvPvuKvFvevoqu5ux0Le','y29TCgfJDfn0B3jLze1LC3nHz2vZ','twvTB3j5u2vZC2LVBKrVy3vTzw50q29UDgfPBMvY','z3jHCgHty2HLBwfwzxjZAw9U','y29UzMLN','DhvYBKXLyxnLtxm','CMvWBgfJzuLUy29TCgf0AwjSzq','Aw52ywXPzf90B29Sx2nHBgXZ','mtbnBKDXvey','C2vZC2LVBNm','CgXHy2vOB2XKzxjeB2n1BwvUDa','zgf0ywjHC2vZ','AxnmAxzLu2vZC2LVBLr1CM4','y29SBgvJDgLVBG','jYbPCYbHBhjLywr5ihbYB2nLC3nPBMCGysb0DxjUlG','q09ttu9eqL9jra','ndaW','q09ttu9FrejFq0Xjru5ux1nfq1jfva','z3jHCgG','C2L6zq','ntm2nJCXm0vksejuvq','Dg9mB3DLCKnHC2u','ywXSB3DpD25LCG','y29ZBw9Zzgi','C2v0','y3jLyxrLswzoB3rfEgLZDhm','q09ttu9FrejFu0vtu0LptL9dt05uquLorvjFsuq','C3rHDhvZ','nJaWmda','BMfTzq','DgHVDwDODa','CMvZDg9YzvnLC3nPB25eB2n1BwvUDa','BgvHC2vK','z2v0vgLTzq','C2nOzw1HvMvYC2LVBG','q09ttu9tx0vorfbpsu5u','AM9PBG','q09ttu9eqL9lrvK','mtGZnJy5nuzxzK5KuW','tu9or09eqL9oqu1f','tu9or09eqL9vuKW','u2vZC2LVBLr1CM5fCNjVCG','zgLZCg9Zzq','qgf6DxjLl2nVC21VCW','BgvUz3rO','y29Kzq','BwvTB3j5','zxjYB3jZ','DhLWzq','CMvZDg9Yzvn0yxrL','q09ttu9tx0Tfwq','DgHVDwDODfnPz25HDhvYzq','zNjVBunVBMzPzW','u0vtu0LptL9cvvnz','CMvHzerVy3vTzw50','zw50CMLLCW','jYbIzwXVBMDZihrVigDYyxbOicC','u2vZC2LVBIaN','yxnZzxj0swq','yMvNAw5uDxjU','zgvSzxrLu2vZC2LVBG','zgvJAxnPB25Z','lI9KyxrHl3nLC3nPB25ZlNnXBgL0zq','y29UzMXPy3q','zgvJAxnPB25vC2fNzq','ovnzEgPoAq','Dg9VBf9JywXSCW','AxnoB3rgB3vUza','igvYCM9YkhmPigfUzca','y29TCgXLDgvK','zxHWAxjLC0f0','q09ttu9eqL9vuKW','AxrLBxm','AxnszwnVCMq','oYbLEhbLy3rLzca','yxbWzw5Ktg9NCW','Bw9KzwXnzxrHzgf0yq','u1fmsvrfx0rcx1bbveG','ywrKAxrPB25HBf9RD2fYz3m','mZK4ntm2ExffzunM','y29ZBw9Z','odm2nJrfu2vZDfO','BgXTq29UzMLN','DhvYBG','mtu5nte2Ag1Tq1H1','u0vtu0LptL9tve9srq','l2LK','DMvYC2LVBG','jYWGBM90icC','mJvkzNrVENa','y3jLyxrLsw5KzxG'];d=function(){return kt;};return d();}function q(R,t){const kj={R:0x143,t:0x16a,A:0x1aa,r:0x153,i:0x1c2},qf=qu;if(R[qf(kj.R)]['schemaVersion']!==t)throw new Error(qf(kj.t)+R['id']+'\x27\x20uses\x20graph\x20\x27'+R[qf(0x143)]['id']+qf(kj.A)+R['graph'][qf(kj.r)]+qf(0x198)+t+qf(kj.i));}function l(q,k){q=q-0x116;const G=d();let T=G[q];if(l['iLIAun']===undefined){var y=function(B){const w='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+/=';let K='',j='';for(let D=0x0,o,a,N=0x0;a=B['charAt'](N++);~a&&(o=D%0x4?o*0x40+a:a,D++%0x4)?K+=String['fromCharCode'](0xff&o>>(-0x2*D&0x6)):0x0){a=w['indexOf'](a);}for(let u=0x0,P=K['length'];u<P;u++){j+='%'+('00'+K['charCodeAt'](u)['toString'](0x10))['slice'](-0x2);}return decodeURIComponent(j);};l['NebsVu']=y,l['KBVcIO']={},l['iLIAun']=!![];}const e=G[0x0],X=q+e,v=l['KBVcIO'][X];return!v?(T=l['NebsVu'](T),l['KBVcIO'][X]=T):T=v,T;}c(q,'assertSessionGraphSchema');function ne(R){const ko={R:0x11a,t:0x1a0},kD={R:0x1b2},qi=qu;return Object[qi(ko.R)](Object[qi(0x168)](R)[qi(ko.t)](([A,i])=>{const qh=qi;if(!i||typeof i!=qh(kD.R))return[A,i];const {toolTrace:Y,...H}=i;return[A,H];}));}c(ne,qu(0x1a4));function oe(R){const ka={R:0x17f,t:0x19c,A:0x199,r:0x12e,i:0x161,Y:0x173,H:0x173,M:0x15d,O:0x1b6,b:0x138,q0:0x138};return R['map'](A=>{const qQ=l,r={...A['data']},Y=A[qQ(0x161)]==='ai'&&Array['isArray'](r[qQ(0x173)])&&r['tool_calls'][qQ(0x15d)]>0x0?ae(r['additional_kwargs']):void 0x0,H=v(r[qQ(0x17f)])&&r[qQ(ka.R)][qQ(ka.t)]===!0x0;return delete r['additional_kwargs'],(Y||H)&&(r[qQ(ka.R)]={...Y?{'originalTextContentBlock':Y}:{},...H?{'ezgraphInternal':!0x0}:{}}),delete r[qQ(ka.A)],delete r[qQ(ka.r)],A[qQ(ka.i)]==='ai'&&(Array[qQ(0x1b6)](r[qQ(ka.Y)])&&r[qQ(ka.H)][qQ(ka.M)]===0x0&&delete r['tool_calls'],Array[qQ(ka.O)](r['invalid_tool_calls'])&&r[qQ(ka.b)]['length']===0x0&&delete r[qQ(ka.q0)]),{...A,'data':r};});}c(oe,qu(0x132));function ie(R){const qZ=qu;return Object[qZ(0x11a)](Object['entries'](R)[qZ(0x1a0)](([A,r])=>[A,oe(e(r))]));}c(ie,qu(0x1a3));function se(R={}){const kP={R:0x168},qY=qu;return Object[qY(0x11a)](Object[qY(kP.R)](R)[qY(0x1a0)](([A,r])=>[A,B(r)]));}c(se,'restoreHistories');function ae(R){const kn={R:0x164,t:0x164,A:0x14f},qH=qu;if(!v(R))return;const t=R['originalTextContentBlock'];if(!(!v(t)||typeof t[qH(kn.R)]!='string'))return{...typeof t[qH(0x1b7)]=='string'?{'text':t['text']}:{},'thoughtSignature':t[qH(kn.t)],...t[qH(kn.A)]===!0x0?{'thought':!0x0}:{}};}c(ae,qu(0x12a));function v(R){const km={R:0x1b6},qW=qu;return R!==null&&typeof R==qW(0x1b2)&&!Array[qW(km.R)](R);}c(v,qu(0x17a));class V{static{c(this,qu(0x133));}[qu(0x1bb)]=new Map();get[qu(0x144)](){const qM=qu;return this[qM(0x1bb)]['size'];}[qu(0x179)]={'upsert':c(async e=>{const kE={R:0x1bb},qx=qu,t=e;return this[qx(kE.R)]['set'](t['id'],structuredClone(t)),{};},qu(0x1a8))};async[qu(0x1be)](R,A){const kC={R:0x125,t:0x170},qU=qu,i=this['documents'][qU(kC.R)](A['id']);return ce(i,R)?(this[qU(0x1bb)][qU(0x149)](A['id'],structuredClone(A)),'ok'):qU(kC.t);}['item'](R,A){const kJ={R:0x1bb,t:0x1a1},kp={R:0x125},qF=qu;return{'read':c(async()=>{const qO=l,i=this['documents'][qO(kp.R)](R);if(!i||i['id']!==A)throw Object[qO(0x1a7)](new Error(qO(0x120)),{'code':0x194});return{'resource':structuredClone(i)};},qF(0x193)),'delete':c(async()=>{const qS=qF,i=this[qS(kJ.R)][qS(0x125)](R);if(!i||i['id']!==A)throw Object['assign'](new Error(qS(0x120)),{'code':0x194});return this[qS(0x1bb)][qS(kJ.t)](R),{};},qF(0x1a1))};}}function j(R){const kL={R:0x1b2,t:0x15e},qb=qu;if(!R||typeof R!=qb(kL.R))return!0x1;const t=R;return t[qb(kL.t)]===0x194||t['statusCode']===0x194;}c(j,qu(0x174));function G(R=process.env.SESSION_TURN_LEASE_MS){const qI=qu,t=Number(R??qI(0x14d));return Number[qI(0x116)](t)&&t>0x0?t:0xea60;}c(G,'sessionTurnLeaseMs');function S(R){return R?.['revision']??0x0;}c(S,'sessionRevision');function F(R,A=Date[qu(0x129)]()){const kc={R:0x177,t:0x116},k0=qu;if(!R?.[k0(0x11e)]||!R[k0(0x177)])return!0x1;const r=Date[k0(0x1ab)](R[k0(kc.R)]);return Number[k0(kc.t)](r)&&r>A;}c(F,qu(0x13d));function ce(R,A,r=Date[qu(0x129)]()){const kg={R:0x1ac,t:0x130},k1=qu;return A[k1(0x137)]?R!==void 0x0&&R[k1(0x188)]!==h:A[k1(kg.R)]===null?R===void 0x0:!(!R||S(R)!==A['expectedRevision']||A[k1(kg.t)]&&R[k1(0x184)]?.[k1(0x11e)]!==A['requireOwner']||A['requireFreeLease']&&F(R[k1(0x184)],r)&&R['turn']?.['owner']!==A[k1(0x147)]);}c(ce,'matchesSessionWritePredicate');export{V as MemorySessionDocumentContainer,g as SESSION_BUSY,_e as SESSION_COMPLETED,P as SESSION_CONFLICT,h as SESSION_DOCUMENT_VERSION,N as SessionManager,f as SessionTurnError,F as isLiveSessionTurn,ce as matchesSessionWritePredicate,S as sessionRevision,G as sessionTurnLeaseMs};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
const A=
|
|
1
|
+
const A=k;(function(D,o){const q6={D:0xe8,o:0xc4,a:0xde,N:0x10f,P:0xc5,n:0x10d},t=k,a=D();while(!![]){try{const N=parseInt(t(q6.D))/0x1+parseInt(t(0x108))/0x2*(-parseInt(t(q6.o))/0x3)+parseInt(t(q6.a))/0x4*(-parseInt(t(0xd7))/0x5)+parseInt(t(q6.N))/0x6*(-parseInt(t(0xfa))/0x7)+parseInt(t(0xe2))/0x8*(-parseInt(t(0xcd))/0x9)+-parseInt(t(0xf3))/0xa*(-parseInt(t(q6.P))/0xb)+parseInt(t(q6.n))/0xc;if(N===o)break;else a['push'](a['shift']());}catch(P){a['push'](a['shift']());}}}(q,0x39347));var m=Object[A(0xc9)],p=(D,o)=>m(D,A(0xd8),{'value':o,'configurable':!0x0});import{END as d,isCommand as T,START as e,StateGraph as X}from'@langchain/langgraph';import{GRAPH_NODE_CLASS as v,GraphNode as B}from'./graph-node.js';function k(d,G){d=d-0xc3;const T=q();let y=T[d];if(k['uhJOwZ']===undefined){var l=function(B){const w='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+/=';let K='',j='';for(let D=0x0,o,a,N=0x0;a=B['charAt'](N++);~a&&(o=D%0x4?o*0x40+a:a,D++%0x4)?K+=String['fromCharCode'](0xff&o>>(-0x2*D&0x6)):0x0){a=w['indexOf'](a);}for(let u=0x0,P=K['length'];u<P;u++){j+='%'+('00'+K['charCodeAt'](u)['toString'](0x10))['slice'](-0x2);}return decodeURIComponent(j);};k['CPtMFs']=l,k['PUoJpy']={},k['uhJOwZ']=!![];}const e=T[0x0],X=d+e,v=k['PUoJpy'][X];return!v?(y=k['CPtMFs'](y),k['PUoJpy'][X]=y):y=v,y;}import{GRAPH_END_NODE as K}from'./graph-state.js';import{stableClassId as j}from'./stable-id.js';class x{static{p(this,'StateGraphExt');}[A(0xca)];[A(0xdd)];[A(0xdc)];[A(0xe7)]=new Set();[A(0xfd)]=new Map();[A(0x107)]=new Map();constructor(D,o,a=K){const r=A;this['createGraphNode']=o,this[r(0xdd)]=a,this[r(0xdc)]=new X(D);}[A(0xe3)](D){const q8={D:0xca,o:0xca,a:0x10e,N:0xd3},f=A;if(!g(D))throw new Error(f(0xcc));if(!this[f(q8.D)])throw new Error('This\x20graph\x20has\x20no\x20GraphNode\x20factory.');const o=this[f(q8.o)](D),a=j(D,'graph\x20node');if(o['id']!==a)throw new Error(f(q8.a)+a+f(q8.N)+o['id']+'\x27.');return this[f(0xfd)][f(0xd5)](a,D),this['registerNode'](o,[...this['addedNodeIds'],a,d]);}[A(0xea)](...D){const qq={D:0xca,o:0xec,a:0xf5,N:0xd3},q9={D:0xe6,o:0x101},i=A;if(!this[i(qq.D)])throw new Error('This\x20graph\x20has\x20no\x20GraphNode\x20factory.');const N=D['map'](V=>{const Q=i;if(!g(V))throw new Error(Q(q9.D));return j(V,Q(q9.o));}),P=N['find']((V,C)=>N['indexOf'](V)!==C||this[i(0xe7)][i(0xd6)](V));if(P)throw new Error(i(qq.o)+P+i(qq.a));const n=[...this[i(0xe7)],...N,d];for(const [V,C]of D['entries']()){const J=this[i(0xca)](C),L=N[V];if(J['id']!==L)throw new Error(i(0x10e)+L+i(qq.N)+J['id']+'\x27.');this['nodeClasses'][i(0xd5)](L,C),this[i(0xd4)](J,n);}return this;}[A(0xee)](...D){const Z=A;return this['nodes'](...D),this[Z(0xdf)](...D),this;}[A(0xcf)](D,a){const qd={D:0x100,o:0x103,a:0xcf},Y=A,N=Array[Y(qd.D)](D)?D:[D];for(const n of N)this[Y(0x10a)](n);this[Y(0xf1)](a);const P=N[Y(qd.o)](c);return this['graph'][Y(qd.a)](P['length']===0x1?P[0x0]:P,c(a)),this;}[A(0xf0)](D,o){const qG={D:0xf4},H=A,a=j(D,'graph\x20node'),N=this[H(0x107)][H(0x10c)](a);if(!N)throw new Error('Graph\x20node\x20\x27'+a+'\x27\x20must\x20be\x20added\x20before\x20it\x20is\x20connected.');return this[H(qG.D)](D,N[H(0xf8)]['bind'](N),o),this;}[A(0xd9)](D,N){const qy={D:0xfc,o:0xf4,a:0x106,N:0x103},qT={D:0xef},W=A,P=j(D,W(0x101));if(!this['nodeInstances'][W(0xd6)](P))throw new Error(W(0xec)+P+W(0xc7));if(N[W(qy.D)][W(0xd0)]===0x0)throw new Error('branchBy()\x20requires\x20at\x20least\x20one\x20case.');const n=N[W(qy.D)]['map'](({when:L})=>this['currentNodeSelectorName'](L)),V=n[W(0xd1)]((L,z)=>n[W(0xe0)](L)!==z);if(V)throw new Error(W(0xe5)+V+'\x27.');const C=n['map']((L,z)=>W(0x10b)+z),J='otherwise';return this[W(qy.o)](D,L=>{const M=W,z=L[M(0xfe)];if(typeof z!=M(qT.D))throw new Error(M(0xec)+P+M(0xf7));const R=n[M(0xe0)](z);return R===-0x1?J:C[R];},{...Object[W(qy.a)](N['cases'][W(qy.N)](({routeTo:L},z)=>[C[z],L])),[J]:N[W(0xdb)]}),this;}['registerTurns'](...D){const ql={D:0xf9,o:0x102,a:0x103},U=A;if(D[U(ql.D)](o=>j(o,'graph\x20node')===this[U(0xdd)]))throw new Error(U(ql.o)+this[U(0xdd)]+'\x27\x20is\x20reserved\x20by\x20StateGraphExt.registerTurns().');return this['addConditionalEdge'](e,o=>o[U(0xfe)],{...Object[U(0x106)](D[U(ql.a)](o=>[j(o,U(0x101)),o])),[this[U(0xdd)]]:d}),this;}[A(0xda)](){const qe={D:0x107,o:0xcb,a:0xda},O=A;for(const D of this[O(qe.D)][O(qe.o)]())D['validateTools']?.();return this['graph'][O(qe.a)]();}['addConditionalEdge'](D,o,a){const qX={D:0xf1,o:0xce},F=A;this['assertSource'](D);for(const N of Object[F(0xcb)](a))this[F(qX.D)](N);this['graph'][F(0xe9)](c(D),o,Object['fromEntries'](Object[F(qX.o)](a)['map'](([P,n])=>[P,c(n)])));}[A(0xd4)](D,o){const qB={D:0xec},qv={D:0xc3,o:0xc3,a:0xc3},S=A;if(this[S(0xe7)]['has'](D['id']))throw new Error(S(qB.D)+D['id']+'\x27\x20is\x20already\x20registered.');return this[S(0xdc)]['addNode'](D['id'],async N=>{const I=S,P=await D['invoke'](N);if(T(P)){const n=Array['isArray'](P['goto'])?P[I(qv.D)]:P[I(qv.o)]===void 0x0?[]:[P[I(qv.a)]];for(const V of n)typeof V=='string'&&this['assertTarget'](V);}return P;},{'ends':[...new Set(o)]}),this['addedNodeIds'][S(0xd2)](D['id']),this['nodeInstances']['set'](D['id'],D),this;}[A(0x10a)](D){const qw={D:0x104},q0=A;c(D)!==e&&this[q0(qw.D)](D,q0(0xe1));}['assertTarget'](D){const q1=A;c(D)!==d&&this['assertAddedNode'](D,q1(0xeb));}[A(0x104)](D,o){const qj={D:0xd6,o:0xfb},q2=A,a=c(D);if(!this['addedNodeIds'][q2(qj.D)](a))throw new Error(q2(qj.o)+o+'\x20\x27'+a+q2(0xc7));}[A(0xf2)](D){const qD={D:0xef,o:0x101,a:0xf6,N:0xd6,P:0xe4},q3=A;if(typeof D!=q3(qD.D)){if(!g(D))throw new Error(q3(0xff));const o=j(D,q3(qD.o));if(!this['addedNodeIds'][q3(0xd6)](o))throw new Error(q3(qD.a)+o+q3(0xc6));return o;}if(D!==this[q3(0xdd)]&&!this[q3(0xe7)][q3(qD.N)](D))throw new Error(q3(0xf6)+D+q3(qD.P)+this[q3(0xdd)]+'\x27.');return D;}}function g(D){const q4=A,o=D;return typeof D==q4(0x105)&&D!==null&&o[v]===!0x0&&o[q4(0xed)]instanceof B;}p(g,A(0x109));function c(D){const qa={D:0xef},q5=A;return typeof D==q5(qa.D)?D:j(D,'graph\x20node');}p(c,A(0xc8));export{x as StateGraphExt};function q(){const qN=['BMfTzq','yNjHBMnOqNK','y29TCgLSzq','B3rOzxj3AxnL','z3jHCgG','zw5KtM9Kzq','mZmXmLntELbvvW','CMvNAxn0zxjuDxjUCW','Aw5KzxHpzG','C291CMnL','mtzqzxrltfa','ywrKtM9Kzq','jYbTDxn0igjLigfUigfKzgvKieDYyxbOtM9KzsbVCIb0AguGy29UzMLNDxjLzcb0zxjTAw5HBcbZDgf0zsaN','yNjHBMnOqNKOksbOyxmGBw9Yzsb0AgfUig9UzsbJyxnLigzVCIaN','u3rHDgvhCMfWAev4DcbUB2rLCYbTDxn0igjLigfKzgvKigfZieDYyxbOtM9KzsbJBgfZC2vZoIbNCMfWAc5UB2rLCYHnEu5VzguPlG','ywrKzwroB2rLswrZ','mJu5mJuWwNLwt0fb','ywrKq29UzgL0Aw9UywXfzgDLCW','BM9Kzxm','DgfYz2v0','r3jHCgGGBM9KzsaN','ChjVDg90ExbL','CMvNAxn0zxjuDxjUtM9Kzxm','C3rYAw5N','yNjHBMnO','yxnZzxj0vgfYz2v0','y3vYCMvUDe5VzgvtzwXLy3rVCK5HBwu','mtuXmeXbEhL1uq','ywrKq29UzgL0Aw9UywXfzgDL','jYbPCYbHBhjLywr5ihjLz2LZDgvYzwqU','q3vYCMvUDc1UB2rLihnLBgvJDg9YicC','jYbJyw5UB3qGyNjHBMnOihDPDgHVDxqGysbZDhjPBMCGy3vYCMvUDe5VzguU','CM91Dgu','C29Tzq','ntzhCKzws2K','q29UzgL0Aw9UywWGB3iGzgLYzwn0igvKz2uG','y2fZzxm','BM9KzunSyxnZzxm','y3vYCMvUDe5Vzgu','yNjHBMnOqNKOksbZzwXLy3rVCNmGBxvZDcbIzsbhCMfWAe5VzguGy2XHC3nLCYbVCIb0AguGy29UzMLNDxjLzcb0zxjTAw5HBcbZDgf0zs4','AxnbCNjHEq','z3jHCgGGBM9Kzq','vgHLihrLCM1PBMfSihn0yxrLicC','BwfW','yxnZzxj0qwrKzwroB2rL','zNvUy3rPB24','zNjVBuvUDhjPzxm','BM9KzuLUC3rHBMnLCW','mtmWofrzD3DYCW','AxnhCMfWAe5VzgvdBgfZCW','yxnZzxj0u291CMnL','y2fZztO','z2v0','nteXmZmYmg1dDKPdtW','r3jHCgGGBM9KzsbMywn0B3j5igzVCIaN','mJu4ndHMuu95ww8','z290BW','nJi3DNHeyNnq','mJeWndnKyLHfr0W','jYbTDxn0igjLigfKzgvKigjLzM9YzsbPDcbPCYb1C2vKlG','jYbTDxn0igjLigfKzgvKigjLzM9YzsbPDcbPCYbJB25Uzwn0zwqU','zw5KCg9PBNrjza','zgvMAw5LuhjVCgvYDhK','y3jLyxrLr3jHCgHoB2rL','DMfSDwvZ','u3rHDgvhCMfWAev4DcbUB2rLCYbTDxn0igjLigfKzgvKigfZieDYyxbOtM9KzsbJBgfZC2vZoIbNCMfWAc5HzgroB2rLke15tM9KzsKU','mtG2mJy2n2ritNruCq','zw50CMLLCW','ywrKrwrNzq','BgvUz3rO','zMLUza','ywrK','jYbYzxr1CM5LzcaN','CMvNAxn0zxjoB2rL','C2v0','AgfZ','otm1vgPyBfb0'];q=function(){return qN;};return q();}
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{BaseGraph as r}from"./framework/base-graph.js";import{GRAPH_NODE_CLASS as t,GraphNode as i,GraphNodeRuntime as n,Tool as a}from"./framework/graph-node.js";import{ConversationNode as m}from"./framework/conversation-node.js";import{LLM_GATEWAY_FACTORY as E,assertLlmTimeoutMs as f}from"./framework/llm-gateway.js";import{ConversationRunner as L,DEFAULT_CONVERSATION_POLICY as
|
|
1
|
+
import{BaseGraph as r}from"./framework/base-graph.js";import{GRAPH_NODE_CLASS as t,GraphNode as i,GraphNodeRuntime as n,Tool as a}from"./framework/graph-node.js";import{ConversationNode as m}from"./framework/conversation-node.js";import{LLM_GATEWAY_FACTORY as E,assertLlmTimeoutMs as f}from"./framework/llm-gateway.js";import{ConversationRunner as L,DEFAULT_CONVERSATION_POLICY as d,DEFAULT_EMPTY_HISTORY_SEED as T,DEFAULT_EMPTY_RESPONSE_RECOVERY as g,DEFAULT_MAX_AGENT_ROUNDS as D,EmptyModelResponseError as l,assertEmptyResponseRetries as R,assertMaxAgentRounds as _}from"./framework/conversation-runner.js";import{describeStopReason as C,isRetryableStopReason as M,modelStopReason as A}from"./framework/model-stop-reason.js";import{currentTurnContext as O,currentTurnSignal as u,withTurnContext as I}from"./framework/turn-context.js";import{direct as G,directTo as U,finish as h,go as y,isToolResponse as v,stay as F}from"./framework/tool-response.js";import{GraphStateSupport as H}from"./framework/graph-state-support.js";import{GRAPH_END_NODE as B,createGraphStateAnnotation as V}from"./framework/graph-state.js";import{GraphRegistry as W}from"./framework/graph-registry.js";import{GraphEngine as z}from"./framework/graph-engine.js";import{ConfigManager as J}from"./framework/config-manager.js";import{StateGraphExt as X}from"./framework/state-graph-ext.js";import{TerminateSessionNode as K}from"./framework/terminate-session.node.js";import{SessionLogError as $,SessionLogDecision as ee,SessionLogWarning as oe,createSessionLogs as re,drainSessionLogs as se,restoreSessionLogs as te,withSessionLogs as ie}from"./framework/session-log.js";import{ProviderFileManager as ae}from"./framework/llm-file.js";import{SessionManager as me,SessionTurnError as Se,SESSION_BUSY as Ee,SESSION_CONFLICT as fe,SESSION_COMPLETED as xe,SESSION_DOCUMENT_VERSION as Le,MemorySessionDocumentContainer as de,sessionTurnLeaseMs as Te,sessionRevision as ge,isLiveSessionTurn as De,matchesSessionWritePredicate as le}from"./framework/persistence/session-manager.js";import{MongoDbSessionDocumentContainer as _e}from"./framework/persistence/mongodb-session-document.container.js";import{SqliteSessionDocumentContainer as Ce}from"./framework/persistence/sqlite-session-document.container.js";import{CosmosSessionDocumentContainer as Ae}from"./framework/persistence/cosmos-session-document.container.js";import{mergeNodeStates as Oe,replaceNodeStates as ue}from"./framework/node-state.js";import{LangChainLlmGateway as Pe}from"./framework/langchain-llm-gateway.js";import{ModelProvider as Ue}from"./framework/model-provider.js";import{langChainModelInitialization as ye}from"./framework/langchain-provider.adapter.js";import{GRAPH_LLM_PROVIDERS as Fe,GRAPH_LLM_FAMILIES as Ye,GRAPH_LLM_CAPABILITIES as He,BUILT_IN_MODEL_CATALOG as ke,GraphLlm as Be,ModelCatalog as Ve,ModelProviderRegistry as be}from"./framework/graph-llm.config.js";import{addTokenUsage as we,emptyTokenUsage as ze,modelExecution as qe,normalizeTokenUsage as Je,tokenUsageFromMessage as Qe}from"./framework/token-usage.js";import{DecisionNode as je}from"./framework/decision/decision-node.js";import{DecisionRunner as Ze}from"./framework/decision/decision-runner.js";import{DecisionProvider as eo,DecisionProviderRegistry as oo}from"./framework/decision/decision-provider.js";import{TypeSafeClassifierAdapter as so}from"./framework/decision/typesafe-provider.js";import{DecisionConfigurationError as io,DecisionTimeoutError as no,DecisionValidationError as ao,DEFAULT_DECISION_OPTIONS as po,addDecisionUsage as mo,decisionUsage as So,emptyDecisionUsage as Eo,normalizeDecisionUsage as fo,resolveDecisionOptions as xo}from"./framework/decision/decision-types.js";import{assertJsonCompatible as To,validateDecisionQuestions as go,validateDecisionResult as Do}from"./framework/decision/decision-validation.js";import{retryWithModel as Ro,LlmResponseBlockedError as _o,LlmSetupError as co}from"./framework/llm-lifecycle.js";export{ke as BUILT_IN_MODEL_CATALOG,r as BaseGraph,J as ConfigManager,m as ConversationNode,L as ConversationRunner,Ae as CosmosSessionDocumentContainer,d as DEFAULT_CONVERSATION_POLICY,po as DEFAULT_DECISION_OPTIONS,T as DEFAULT_EMPTY_HISTORY_SEED,g as DEFAULT_EMPTY_RESPONSE_RECOVERY,D as DEFAULT_MAX_AGENT_ROUNDS,io as DecisionConfigurationError,je as DecisionNode,eo as DecisionProvider,oo as DecisionProviderRegistry,Ze as DecisionRunner,no as DecisionTimeoutError,ao as DecisionValidationError,l as EmptyModelResponseError,B as GRAPH_END_NODE,He as GRAPH_LLM_CAPABILITIES,Ye as GRAPH_LLM_FAMILIES,Fe as GRAPH_LLM_PROVIDERS,t as GRAPH_NODE_CLASS,z as GraphEngine,Be as GraphLlm,i as GraphNode,n as GraphNodeRuntime,W as GraphRegistry,H as GraphStateSupport,E as LLM_GATEWAY_FACTORY,Pe as LangChainLlmGateway,_o as LlmResponseBlockedError,co as LlmSetupError,de as MemorySessionDocumentContainer,Ve as ModelCatalog,Ue as ModelProvider,be as ModelProviderRegistry,_e as MongoDbSessionDocumentContainer,ae as ProviderFileManager,Ee as SESSION_BUSY,xe as SESSION_COMPLETED,fe as SESSION_CONFLICT,Le as SESSION_DOCUMENT_VERSION,ee as SessionLogDecision,$ as SessionLogError,oe as SessionLogWarning,me as SessionManager,Se as SessionTurnError,Ce as SqliteSessionDocumentContainer,X as StateGraphExt,K as TerminateSessionNode,a as Tool,so as TypeSafeClassifierAdapter,mo as addDecisionUsage,we as addTokenUsage,R as assertEmptyResponseRetries,To as assertJsonCompatible,f as assertLlmTimeoutMs,_ as assertMaxAgentRounds,V as createGraphStateAnnotation,re as createSessionLogs,O as currentTurnContext,u as currentTurnSignal,So as decisionUsage,C as describeStopReason,G as direct,U as directTo,se as drainSessionLogs,Eo as emptyDecisionUsage,ze as emptyTokenUsage,h as finish,y as go,De as isLiveSessionTurn,M as isRetryableStopReason,v as isToolResponse,ye as langChainModelInitialization,le as matchesSessionWritePredicate,Oe as mergeNodeStates,qe as modelExecution,A as modelStopReason,fo as normalizeDecisionUsage,Je as normalizeTokenUsage,ue as replaceNodeStates,xo as resolveDecisionOptions,te as restoreSessionLogs,Ro as retryWithModel,ge as sessionRevision,Te as sessionTurnLeaseMs,F as stay,Qe as tokenUsageFromMessage,go as validateDecisionQuestions,Do as validateDecisionResult,ie as withSessionLogs,I as withTurnContext};
|
|
@@ -31,3 +31,4 @@ export { DecisionProvider, DecisionProviderRegistry, type BuiltinDecisionProvide
|
|
|
31
31
|
export { TypeSafeClassifierAdapter, type TypeSafeProviderOptions, } from "../../src/framework/decision/typesafe-provider.js";
|
|
32
32
|
export { DecisionConfigurationError, DecisionTimeoutError, DecisionValidationError, DEFAULT_DECISION_OPTIONS, addDecisionUsage, decisionUsage, emptyDecisionUsage, normalizeDecisionUsage, resolveDecisionOptions, type Choice, type ChoiceAnswer, type DecisionAnswer, type DecisionAnswers, type DecisionCallOptions, type DecisionContext, type DecisionConversation, type DecisionEvidence, type DecisionErrorContext, type DecisionFailure, type DecisionMetadata, type DecisionOptions, type DecisionProviderAdapter, type DecisionQuestion, type DecisionQuestionMap, type DecisionRequest, type DecisionResult, type DecisionState, type DecisionTokenUsage, type DecisionUsage, type JsonObject, type JsonPrimitive, type JsonValue, type Noul, type NoulAnswer, type ResolvedDecisionOptions, type Score, type ScoreAnswer, } from "../../src/framework/decision/decision-types.js";
|
|
33
33
|
export { assertJsonCompatible, validateDecisionQuestions, validateDecisionResult, } from "../../src/framework/decision/decision-validation.js";
|
|
34
|
+
export { retryWithModel, LlmResponseBlockedError, LlmSetupError, type LlmAttemptErrorContext, type LlmBlockedContext, type LlmBlockedResponse, type LlmErrorContext, type LlmErrorResponse, type RetryWithModelResponse, type ConversationLlmLifecycle, type GraphLlmLifecycle, } from "../../src/framework/llm-lifecycle.js";
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { LlmAttemptErrorContext, LlmBlockedContext, LlmBlockedResponse, LlmErrorContext, LlmErrorResponse } from "./llm-lifecycle.js";
|
|
1
2
|
import { type GraphLlmConfig } from "./graph-llm.config.js";
|
|
2
3
|
import { HumanMessage } from "@langchain/core/messages";
|
|
3
4
|
import type { LlmGateway } from "./llm-gateway.js";
|
|
@@ -56,6 +57,9 @@ export declare abstract class BaseGraph<State extends GraphState> {
|
|
|
56
57
|
private readonly endNode;
|
|
57
58
|
private readonly migrations;
|
|
58
59
|
protected constructor(llmGateway: LlmGateway, definition: GraphDefinition<State["currentNode"], State>);
|
|
60
|
+
onLlmBlocked(_context: LlmBlockedContext): Promise<LlmBlockedResponse | null>;
|
|
61
|
+
shouldRetryLlmError(_context: LlmAttemptErrorContext): boolean | undefined;
|
|
62
|
+
onLlmError(_context: LlmErrorContext): Promise<LlmErrorResponse | null>;
|
|
59
63
|
protected onDecisionError(_context: DecisionErrorContext<State>): GraphNodeResponse<State> | null | Promise<GraphNodeResponse<State> | null>;
|
|
60
64
|
attachDecisionProviderResolver(resolve: (id: string) => DecisionProviderAdapter): void;
|
|
61
65
|
get graph(): {
|
|
@@ -1,9 +1,15 @@
|
|
|
1
|
+
import type { ConversationLlmLifecycle, LlmAttemptErrorContext, LlmBlockedContext, LlmBlockedResponse, LlmErrorContext, LlmErrorResponse } from "./llm-lifecycle.js";
|
|
1
2
|
import type { ConversationRunResult } from "./conversation-runner.js";
|
|
2
3
|
import { GraphNode, type GraphNodeResult } from "./graph-node.js";
|
|
3
4
|
import type { GraphState } from "./graph-state.js";
|
|
4
5
|
import { type ToolResponse } from "./tool-response.js";
|
|
5
6
|
export type ConversationNodeRunResult = ConversationRunResult;
|
|
6
7
|
export declare abstract class ConversationNode<State extends GraphState> extends GraphNode<State> {
|
|
8
|
+
checkResponse(_llmResult: string | object): boolean;
|
|
9
|
+
onLlmBlocked(_context: LlmBlockedContext): Promise<LlmBlockedResponse | null>;
|
|
10
|
+
shouldRetryLlmError(_context: LlmAttemptErrorContext): boolean | undefined;
|
|
11
|
+
onLlmError(_context: LlmErrorContext): Promise<LlmErrorResponse | null>;
|
|
12
|
+
protected conversationLlmLifecycle(): ConversationLlmLifecycle;
|
|
7
13
|
protected endChat(input: {
|
|
8
14
|
message?: string;
|
|
9
15
|
}): Promise<ToolResponse>;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type ConversationLlmLifecycle } from "./llm-lifecycle.js";
|
|
1
2
|
import { type BaseMessage } from "@langchain/core/messages";
|
|
2
3
|
import type { ToolCall } from "@langchain/core/messages/tool";
|
|
3
4
|
import type { GraphLlmConfig } from "./graph-llm.config.js";
|
|
@@ -36,6 +37,7 @@ export declare class ConversationRunner {
|
|
|
36
37
|
private readonly llmGateway;
|
|
37
38
|
constructor(llmGateway: LlmGateway);
|
|
38
39
|
run(options: {
|
|
40
|
+
lifecycle?: ConversationLlmLifecycle;
|
|
39
41
|
systemPrompt: string;
|
|
40
42
|
history: readonly BaseMessage[];
|
|
41
43
|
tools: readonly LlmGatewayTool[];
|
|
@@ -5,7 +5,7 @@ import { type DecisionAnswers, type DecisionContext, type DecisionEvidence, type
|
|
|
5
5
|
export declare abstract class DecisionNode<State extends GraphState, Questions extends DecisionQuestionMap = DecisionQuestionMap, LocalState extends object = Record<string, unknown>> extends GraphNode<State, LocalState> {
|
|
6
6
|
abstract defineQuestions(state: State): Questions;
|
|
7
7
|
getPrompt(_state: State): string;
|
|
8
|
-
protected
|
|
8
|
+
protected getDecisionFacts(_state: State): DecisionEvidence;
|
|
9
9
|
getDecisionConfig(): DecisionOptions;
|
|
10
10
|
abstract onDecision(answers: DecisionAnswers<Questions>, context: DecisionContext, state: State): GraphNodeResponse<State> | Promise<GraphNodeResponse<State>>;
|
|
11
11
|
protected onDecisionError(_context: DecisionErrorContext<State>): GraphNodeResponse<State> | null | Promise<GraphNodeResponse<State> | null>;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { ConversationLlmLifecycle, GraphLlmLifecycle } from "./llm-lifecycle.js";
|
|
1
2
|
import type { GraphState } from "./graph-state.js";
|
|
2
3
|
import type { LlmCallOptions, LlmGateway, LlmGatewayTool } from "./llm-gateway.js";
|
|
3
4
|
import "reflect-metadata";
|
|
@@ -57,6 +58,7 @@ export declare abstract class GraphNode<State extends GraphState, LocalState ext
|
|
|
57
58
|
protected llmConfig(): GraphLlmConfig;
|
|
58
59
|
protected llmCallOptions(): LlmCallOptions;
|
|
59
60
|
protected runConversation(state: State, context: ToolContext): Promise<ConversationRunResult>;
|
|
61
|
+
protected conversationLlmLifecycle(): ConversationLlmLifecycle | undefined;
|
|
60
62
|
private runAgentLoop;
|
|
61
63
|
protected historySpace(): string;
|
|
62
64
|
protected history(state: Pick<State, "histories">): BaseMessage[];
|
|
@@ -82,8 +84,9 @@ export declare class GraphNodeRuntime<State extends GraphState> extends GraphSta
|
|
|
82
84
|
readonly conversationPolicy: ConversationPolicy;
|
|
83
85
|
private readonly decisionOptions;
|
|
84
86
|
private readonly decisionErrorHandler?;
|
|
87
|
+
readonly llmLifecycle?: GraphLlmLifecycle | undefined;
|
|
85
88
|
private readonly tools;
|
|
86
|
-
constructor(endNode: State["currentNode"], defaultLlmConfig: GraphLlmConfig, historySpaces?: Readonly<Record<string, string>>, initialHistorySpace?: string, responseMode?: "chat" | "json", maxAgentRounds?: number, conversationPolicy?: ConversationPolicy, decisionOptions?: DecisionOptions, decisionErrorHandler?: ((context: DecisionErrorContext<State>) => GraphNodeResponse<State> | null | Promise<GraphNodeResponse<State> | null>) | undefined);
|
|
89
|
+
constructor(endNode: State["currentNode"], defaultLlmConfig: GraphLlmConfig, historySpaces?: Readonly<Record<string, string>>, initialHistorySpace?: string, responseMode?: "chat" | "json", maxAgentRounds?: number, conversationPolicy?: ConversationPolicy, decisionOptions?: DecisionOptions, decisionErrorHandler?: ((context: DecisionErrorContext<State>) => GraphNodeResponse<State> | null | Promise<GraphNodeResponse<State> | null>) | undefined, llmLifecycle?: GraphLlmLifecycle | undefined);
|
|
87
90
|
llmCallOptions(): LlmCallOptions;
|
|
88
91
|
expectsJsonResponse(): boolean;
|
|
89
92
|
historySpace(currentNode?: string): string;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import type { AIMessage } from "@langchain/core/messages";
|
|
2
|
+
import type { GraphLlmConfig } from "./graph-llm.config.js";
|
|
3
|
+
import type { ToolResponse } from "./tool-response.js";
|
|
4
|
+
export type LlmAttemptErrorContext = Readonly<{
|
|
5
|
+
nodeId: string;
|
|
6
|
+
provider: string;
|
|
7
|
+
model: string;
|
|
8
|
+
error: Error;
|
|
9
|
+
attempt: number;
|
|
10
|
+
maxAttempts: number;
|
|
11
|
+
signal?: AbortSignal;
|
|
12
|
+
}>;
|
|
13
|
+
export type LlmErrorContext = Readonly<{
|
|
14
|
+
nodeId: string;
|
|
15
|
+
provider: string;
|
|
16
|
+
model: string;
|
|
17
|
+
error: Error;
|
|
18
|
+
attemptsMade: number;
|
|
19
|
+
maxAttempts: number;
|
|
20
|
+
signal?: AbortSignal;
|
|
21
|
+
} & ({
|
|
22
|
+
kind: "invocation_error";
|
|
23
|
+
stoppedBecause: "retry_declined" | "attempts_exhausted";
|
|
24
|
+
} | {
|
|
25
|
+
kind: "empty_response" | "response_rejected";
|
|
26
|
+
stoppedBecause: "attempts_exhausted";
|
|
27
|
+
lastResponse: AIMessage;
|
|
28
|
+
})>;
|
|
29
|
+
export type LlmBlockedContext = Readonly<{
|
|
30
|
+
nodeId: string;
|
|
31
|
+
provider: string;
|
|
32
|
+
model: string;
|
|
33
|
+
reason: string;
|
|
34
|
+
rawReason: string;
|
|
35
|
+
phase: "prompt" | "candidate";
|
|
36
|
+
safetyRatings?: unknown[];
|
|
37
|
+
providerDetails?: unknown;
|
|
38
|
+
signal?: AbortSignal;
|
|
39
|
+
}>;
|
|
40
|
+
export type LlmBlockedResponse = string | ToolResponse;
|
|
41
|
+
export type RetryWithModelResponse = Readonly<{
|
|
42
|
+
kind: "retry_with_model";
|
|
43
|
+
model: GraphLlmConfig;
|
|
44
|
+
}>;
|
|
45
|
+
export type LlmErrorResponse = LlmBlockedResponse | RetryWithModelResponse;
|
|
46
|
+
export declare function retryWithModel(model: GraphLlmConfig): RetryWithModelResponse;
|
|
47
|
+
export declare class LlmResponseBlockedError extends Error {
|
|
48
|
+
readonly context: LlmBlockedContext;
|
|
49
|
+
constructor(context: LlmBlockedContext, cause?: unknown);
|
|
50
|
+
}
|
|
51
|
+
export declare class LlmSetupError extends Error {
|
|
52
|
+
constructor(cause: unknown);
|
|
53
|
+
}
|
|
54
|
+
export type ConversationLlmLifecycle = Readonly<{
|
|
55
|
+
nodeId: string;
|
|
56
|
+
checkResponse(response: string | object): boolean;
|
|
57
|
+
onLlmBlocked(context: LlmBlockedContext): Promise<LlmBlockedResponse | null>;
|
|
58
|
+
shouldRetryLlmError(context: LlmAttemptErrorContext): boolean | undefined;
|
|
59
|
+
onLlmError(context: LlmErrorContext): Promise<LlmErrorResponse | null>;
|
|
60
|
+
}>;
|
|
61
|
+
export type GraphLlmLifecycle = Pick<ConversationLlmLifecycle, "onLlmBlocked" | "shouldRetryLlmError" | "onLlmError">;
|