@picoflow/ezgraph 0.0.7 → 0.0.8
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 +77 -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 -0
- package/dist/framework/decision/decision-provider.js +1 -0
- package/dist/framework/decision/decision-runner.js +1 -0
- package/dist/framework/decision/decision-types.js +1 -0
- package/dist/framework/decision/decision-validation.js +1 -0
- package/dist/framework/decision/typesafe-provider.js +1 -0
- package/dist/framework/graph-engine.js +1 -1
- package/dist/framework/graph-node.js +1 -1
- package/dist/framework/graph-state.js +1 -1
- package/dist/framework/langchain-provider.adapter.js +1 -1
- package/dist/framework/persistence/session-manager.js +1 -1
- package/dist/framework/session-log.js +1 -1
- package/dist/framework/state-graph-ext.js +1 -1
- package/dist/framework/tool-response.js +1 -1
- package/dist/index.js +1 -1
- package/dist/testing/scripted-decisions.js +1 -0
- package/dist/testing/turn-harness.js +1 -1
- package/dist/testing.js +1 -1
- package/dist/types/npmlib/src/index.d.ts +9 -3
- package/dist/types/npmlib/src/testing.d.ts +1 -0
- package/dist/types/src/framework/base-graph.d.ts +23 -17
- package/dist/types/src/framework/conversation-node.d.ts +4 -4
- package/dist/types/src/framework/conversation-runner.d.ts +7 -7
- package/dist/types/src/framework/decision/decision-node.d.ts +17 -0
- package/dist/types/src/framework/decision/decision-provider.d.ts +14 -0
- package/dist/types/src/framework/decision/decision-runner.d.ts +18 -0
- package/dist/types/src/framework/decision/decision-types.d.ts +126 -0
- package/dist/types/src/framework/decision/decision-validation.d.ts +4 -0
- package/dist/types/src/framework/decision/typesafe-provider.d.ts +12 -0
- package/dist/types/src/framework/graph-engine.d.ts +4 -0
- package/dist/types/src/framework/graph-llm.config.d.ts +3 -3
- package/dist/types/src/framework/graph-node.d.ts +34 -22
- package/dist/types/src/framework/graph-registry.d.ts +8 -6
- package/dist/types/src/framework/graph-state-support.d.ts +1 -1
- package/dist/types/src/framework/graph-state.d.ts +6 -3
- package/dist/types/src/framework/langchain-provider.adapter.d.ts +2 -2
- package/dist/types/src/framework/llm-gateway.d.ts +4 -4
- package/dist/types/src/framework/model-stop-reason.d.ts +2 -2
- package/dist/types/src/framework/node-invocation.d.ts +2 -2
- package/dist/types/src/framework/node-outcome.d.ts +2 -2
- package/dist/types/src/framework/node-state.d.ts +1 -1
- package/dist/types/src/framework/openai-auth-provider.d.ts +1 -1
- package/dist/types/src/framework/persistence/session-manager.d.ts +3 -0
- package/dist/types/src/framework/session-log.d.ts +30 -0
- package/dist/types/src/framework/state-graph-ext.d.ts +3 -3
- package/dist/types/src/framework/token-usage.d.ts +2 -2
- package/dist/types/src/framework/tool-response.d.ts +7 -3
- package/dist/types/src/testing/scripted-decisions.d.ts +24 -0
- package/dist/types/src/testing/turn-harness.d.ts +2 -0
- package/package.json +11 -7
|
@@ -1 +1 @@
|
|
|
1
|
-
const
|
|
1
|
+
const A=e;(function(n,o){const K5={n:0xe8,o:0xc4,z:0xde,H:0x10f,t:0xc5,k:0x10d},U=e,z=n();while(!![]){try{const H=parseInt(U(K5.n))/0x1+parseInt(U(0x108))/0x2*(-parseInt(U(K5.o))/0x3)+parseInt(U(K5.z))/0x4*(-parseInt(U(0xd7))/0x5)+parseInt(U(K5.H))/0x6*(-parseInt(U(0xfa))/0x7)+parseInt(U(0xe2))/0x8*(-parseInt(U(0xcd))/0x9)+-parseInt(U(0xf3))/0xa*(-parseInt(U(K5.t))/0xb)+parseInt(U(K5.k))/0xc;if(H===o)break;else z['push'](z['shift']());}catch(t){z['push'](z['shift']());}}}(K,0x39347));var m=Object[A(0xc9)],p=(o,z)=>m(o,A(0xd8),{'value':z,'configurable':!0x0});import{END as j,isCommand as C,START as I,StateGraph as J}from'@langchain/langgraph';import{GRAPH_NODE_CLASS as F,GraphNode as V}from'./graph-node.js';function e(j,C){j=j-0xc3;const I=K();let J=I[j];if(e['uhJOwZ']===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['CPtMFs']=F,e['PUoJpy']={},e['uhJOwZ']=!![];}const V=I[0x0],m=j+V,h=e['PUoJpy'][m];return!h?(J=e['CPtMFs'](J),e['PUoJpy'][m]=J):J=h,J;}import{GRAPH_END_NODE as s}from'./graph-state.js';import{stableClassId as P}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(n,o,z=s){const r=A;this['createGraphNode']=o,this[r(0xdd)]=z,this[r(0xdc)]=new J(n);}[A(0xe3)](n){const K7={n:0xca,o:0xca,z:0x10e,H:0xd3},S=A;if(!g(n))throw new Error(S(0xcc));if(!this[S(K7.n)])throw new Error('This\x20graph\x20has\x20no\x20GraphNode\x20factory.');const o=this[S(K7.o)](n),z=P(n,'graph\x20node');if(o['id']!==z)throw new Error(S(K7.z)+z+S(K7.H)+o['id']+'\x27.');return this[S(0xfd)][S(0xd5)](z,n),this['registerNode'](o,[...this['addedNodeIds'],z,j]);}[A(0xea)](...n){const K9={n:0xca,o:0xec,z:0xf5,H:0xd3},K8={n:0xe6,o:0x101},f=A;if(!this[f(K9.n)])throw new Error('This\x20graph\x20has\x20no\x20GraphNode\x20factory.');const z=n['map'](q=>{const v=f;if(!g(q))throw new Error(v(K8.n));return P(q,v(K8.o));}),H=z['find']((q,D)=>z['indexOf'](q)!==D||this[f(0xe7)][f(0xd6)](q));if(H)throw new Error(f(K9.o)+H+f(K9.z));const k=[...this[f(0xe7)],...z,j];for(const [q,D]of n['entries']()){const M=this[f(0xca)](D),Q=z[q];if(M['id']!==Q)throw new Error(f(0x10e)+Q+f(K9.H)+M['id']+'\x27.');this['nodeClasses'][f(0xd5)](Q,D),this[f(0xd4)](M,k);}return this;}[A(0xee)](...n){const d=A;return this['nodes'](...n),this[d(0xdf)](...n),this;}[A(0xcf)](n,z){const Ke={n:0x100,o:0x103,z:0xcf},X=A,H=Array[X(Ke.n)](n)?n:[n];for(const q of H)this[X(0x10a)](q);this[X(0xf1)](z);const k=H[X(Ke.o)](c);return this['graph'][X(Ke.z)](k['length']===0x1?k[0x0]:k,c(z)),this;}[A(0xf0)](n,o){const Kj={n:0xf4},N=A,z=P(n,'graph\x20node'),H=this[N(0x107)][N(0x10c)](z);if(!H)throw new Error('Graph\x20node\x20\x27'+z+'\x27\x20must\x20be\x20added\x20before\x20it\x20is\x20connected.');return this[N(Kj.n)](n,H[N(0xf8)]['bind'](H),o),this;}[A(0xd9)](n,z){const KI={n:0xfc,o:0xf4,z:0x106,H:0x103},KC={n:0xef},R=A,H=P(n,R(0x101));if(!this['nodeInstances'][R(0xd6)](H))throw new Error(R(0xec)+H+R(0xc7));if(z[R(KI.n)][R(0xd0)]===0x0)throw new Error('branchBy()\x20requires\x20at\x20least\x20one\x20case.');const k=z[R(KI.n)]['map'](({when:Q})=>this['currentNodeSelectorName'](Q)),q=k[R(0xd1)]((Q,Z)=>k[R(0xe0)](Q)!==Z);if(q)throw new Error(R(0xe5)+q+'\x27.');const D=k['map']((Q,Z)=>R(0x10b)+Z),M='otherwise';return this[R(KI.o)](n,Q=>{const T=R,Z=Q[T(0xfe)];if(typeof Z!=T(KC.n))throw new Error(T(0xec)+H+T(0xf7));const O=k[T(0xe0)](Z);return O===-0x1?M:D[O];},{...Object[R(KI.z)](z['cases'][R(KI.H)](({routeTo:Q},Z)=>[D[Z],Q])),[M]:z[R(0xdb)]}),this;}['registerTurns'](...n){const KJ={n:0xf9,o:0x102,z:0x103},a=A;if(n[a(KJ.n)](o=>P(o,'graph\x20node')===this[a(0xdd)]))throw new Error(a(KJ.o)+this[a(0xdd)]+'\x27\x20is\x20reserved\x20by\x20StateGraphExt.registerTurns().');return this['addConditionalEdge'](I,o=>o[a(0xfe)],{...Object[a(0x106)](n[a(KJ.z)](o=>[P(o,a(0x101)),o])),[this[a(0xdd)]]:j}),this;}[A(0xda)](){const KF={n:0x107,o:0xcb,z:0xda},B=A;for(const n of this[B(KF.n)][B(KF.o)]())n['validateTools']?.();return this['graph'][B(KF.z)]();}['addConditionalEdge'](n,o,z){const KV={n:0xf1,o:0xce},W=A;this['assertSource'](n);for(const H of Object[W(0xcb)](z))this[W(KV.n)](H);this['graph'][W(0xe9)](c(n),o,Object['fromEntries'](Object[W(KV.o)](z)['map'](([k,q])=>[k,c(q)])));}[A(0xd4)](n,o){const Kh={n:0xec},Km={n:0xc3,o:0xc3,z:0xc3},Y=A;if(this[Y(0xe7)]['has'](n['id']))throw new Error(Y(Kh.n)+n['id']+'\x27\x20is\x20already\x20registered.');return this[Y(0xdc)]['addNode'](n['id'],async z=>{const L=Y,H=await n['invoke'](z);if(C(H)){const k=Array['isArray'](H['goto'])?H[L(Km.n)]:H[L(Km.o)]===void 0x0?[]:[H[L(Km.z)]];for(const q of k)typeof q=='string'&&this['assertTarget'](q);}return H;},{'ends':[...new Set(o)]}),this['addedNodeIds'][Y(0xd2)](n['id']),this['nodeInstances']['set'](n['id'],n),this;}[A(0x10a)](n){const Kc={n:0x104},i=A;c(n)!==I&&this[i(Kc.n)](n,i(0xe1));}['assertTarget'](n){const K0=A;c(n)!==j&&this['assertAddedNode'](n,K0(0xeb));}[A(0x104)](n,o){const KP={n:0xd6,o:0xfb},K1=A,z=c(n);if(!this['addedNodeIds'][K1(KP.n)](z))throw new Error(K1(KP.o)+o+'\x20\x27'+z+K1(0xc7));}[A(0xf2)](n){const Kn={n:0xef,o:0x101,z:0xf6,H:0xd6,t:0xe4},K2=A;if(typeof n!=K2(Kn.n)){if(!g(n))throw new Error(K2(0xff));const o=P(n,K2(Kn.o));if(!this['addedNodeIds'][K2(0xd6)](o))throw new Error(K2(Kn.z)+o+K2(0xc6));return o;}if(n!==this[K2(0xdd)]&&!this[K2(0xe7)][K2(Kn.H)](n))throw new Error(K2(0xf6)+n+K2(Kn.t)+this[K2(0xdd)]+'\x27.');return n;}}function g(o){const K3=A,z=o;return typeof o==K3(0x105)&&o!==null&&z[F]===!0x0&&z[K3(0xed)]instanceof V;}p(g,A(0x109));function c(o){const Kz={n:0xef},K4=A;return typeof o==K4(Kz.n)?o:P(o,'graph\x20node');}p(c,A(0xc8));export{x as StateGraphExt};function K(){const KH=['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'];K=function(){return KH;};return K();}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
var u=Object.defineProperty;var
|
|
1
|
+
var u=Object.defineProperty;var n=(e,r)=>u(e,"name",{value:r,configurable:!0});function f(e){return s({kind:"go",target:e})}n(f,"go");function l(e="OK"){return s({kind:"stay",feedback:e})}n(l,"stay");function c(e){return s({kind:"direct",response:o(e)})}n(c,"direct");function d(e,r){return s({kind:"directTo",target:e,response:o(r)})}n(d,"directTo");function p(e){return s({kind:"finish",response:o(e)})}n(p,"finish");function b(e){return!e||typeof e!="object"||!("kind"in e)?!1:["go","stay","direct","directTo","finish"].includes(String(e.kind))}n(b,"isToolResponse");function o(e){return typeof e=="string"?e:JSON.stringify(e)}n(o,"responseContent");function s(e){const r={...e},i=n(t=>s({...e,...t}),"derive");return Object.defineProperties(r,{withState:{enumerable:!1,value:n(t=>i({state:t}),"value")},withMessage:{enumerable:!1,value:n(t=>i({message:t}),"value")},withMessages:{enumerable:!1,value:n(t=>i({messages:t}),"value")},withCleanup:{enumerable:!1,value:n(t=>i({cleanup:t}),"value")},withToolFeedback:{enumerable:!1,value:n(t=>i({feedback:t}),"value")},withUsage:{enumerable:!1,value:n(t=>i({usage:t}),"value")}}),r}n(s,"createBuilder");export{c as direct,d as directTo,p as finish,f as go,b as isToolResponse,l as stay};
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{BaseGraph as r}from"./framework/base-graph.js";import{GRAPH_NODE_CLASS 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 T,DEFAULT_EMPTY_HISTORY_SEED as d,DEFAULT_EMPTY_RESPONSE_RECOVERY as g,DEFAULT_MAX_AGENT_ROUNDS as D,EmptyModelResponseError as _,assertEmptyResponseRetries as R,assertMaxAgentRounds as c}from"./framework/conversation-runner.js";import{describeStopReason as C,isRetryableStopReason as A,modelStopReason as M}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 v,isToolResponse as y,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 k}from"./framework/graph-state.js";import{GraphRegistry as w}from"./framework/graph-registry.js";import{GraphEngine as W}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 Te,sessionTurnLeaseMs as de,sessionRevision as ge,isLiveSessionTurn as De,matchesSessionWritePredicate as _e}from"./framework/persistence/session-manager.js";import{MongoDbSessionDocumentContainer as ce}from"./framework/persistence/mongodb-session-document.container.js";import{SqliteSessionDocumentContainer as Ce}from"./framework/persistence/sqlite-session-document.container.js";import{CosmosSessionDocumentContainer as Me}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 ve}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 Ve,GraphLlm as be,ModelCatalog as ke,ModelProviderRegistry as Be}from"./framework/graph-llm.config.js";import{addTokenUsage as ze,emptyTokenUsage as We,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";export{Ve as BUILT_IN_MODEL_CATALOG,r as BaseGraph,J as ConfigManager,m as ConversationNode,L as ConversationRunner,Me as CosmosSessionDocumentContainer,T as DEFAULT_CONVERSATION_POLICY,po as DEFAULT_DECISION_OPTIONS,d 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,_ 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,W 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,Te as MemorySessionDocumentContainer,ke as ModelCatalog,Ue as ModelProvider,Be as ModelProviderRegistry,ce 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,ze as addTokenUsage,R as assertEmptyResponseRetries,To as assertJsonCompatible,f as assertLlmTimeoutMs,c as assertMaxAgentRounds,k 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,We as emptyTokenUsage,h as finish,v as go,De as isLiveSessionTurn,A as isRetryableStopReason,y as isToolResponse,ve as langChainModelInitialization,_e as matchesSessionWritePredicate,Oe as mergeNodeStates,qe as modelExecution,M as modelStopReason,fo as normalizeDecisionUsage,Je as normalizeTokenUsage,ue as replaceNodeStates,xo as resolveDecisionOptions,te as restoreSessionLogs,ge as sessionRevision,de as sessionTurnLeaseMs,F as stay,Qe as tokenUsageFromMessage,go as validateDecisionQuestions,Do as validateDecisionResult,ie as withSessionLogs,I as withTurnContext};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var n=Object.defineProperty;var u=(t,e)=>n(t,"name",{value:e,configurable:!0});class i{static{u(this,"ScriptedDecisions")}id;turns=[];consumed=0;calls=[];constructor(e="typesafe"){this.id=e}answers(e,r={}){return this.turns.push({kind:"result",result:{model:r.model??"scripted-decision-model",answers:e,...r.usage?{usage:r.usage}:{},...r.requestId?{requestId:r.requestId}:{}}}),this}result(e){return this.turns.push({kind:"result",result:e}),this}fail(e){return this.turns.push({kind:"failure",error:typeof e=="string"?new Error(e):e}),this}get drained(){return this.consumed>=this.turns.length}get remaining(){return Math.max(0,this.turns.length-this.consumed)}async decide(e,r){this.calls.push({request:structuredClone(e),options:r}),r.signal.throwIfAborted();const s=this.turns[this.consumed];if(this.consumed+=1,!s)throw new Error("Scripted decision adapter has no queued result.");if(s.kind==="failure")throw s.error;return structuredClone(s.result)}shouldRetry(e){return e.name==="ScriptedTransientError"}}function h(t="typesafe"){return new i(t)}u(h,"scriptedDecisions");export{i as ScriptedDecisions,h as scriptedDecisions};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
var
|
|
1
|
+
var f=Object.defineProperty;var t=(e,n)=>f(e,"name",{value:n,configurable:!0});import{GraphEngine as h}from"../framework/graph-engine.js";import{SessionManager as l}from"../framework/persistence/session-manager.js";function b(e){const n=e.sessionManager??new l,{gateway:g}=e,d=new h({sessionManager:n,...g?{llmGatewayFactory:t(()=>g,"llmGatewayFactory")}:{},...e.decisions?{decisionProviders:Array.isArray(e.decisions)?e.decisions:[e.decisions]}:{}}).registerGraph([e.graph]),[a]=d.getGraphs();if(!a)throw new Error("The harness graph did not register.");const c=e.sessionId??`harness-${a}`,u=t(()=>n.getSession(c),"document");return{session:c,engine:d,document:u,async send(y,i){const r=await d.run({graphName:a,sessionId:c,...y===void 0?{}:{userMessage:y},...i?.config?{config:i.config}:{},...i?.signal?{signal:i.signal}:{}}),s=await u(),m=s?n.restoreSessionDocument(s,a):void 0,o=r.body;return{status:r.status,session:c,response:typeof o.message=="string"?o.message:"",completed:o.completed===!0,...typeof o.code=="string"?{code:o.code}:{},body:r.body,...r.contentType?{contentType:r.contentType}:{},...s?{document:s}:{},...m?{state:m}:{},...s?.graph.currentNode===void 0?{}:{currentNode:s.graph.currentNode},warnings:s?.warnings??[],errors:s?.errors??[]}},close:t(()=>n.close(),"close")}}t(b,"createTurnHarness");export{b as createTurnHarness};
|
package/dist/testing.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{ScriptedGateway as t,SCRIPTED_MODEL as
|
|
1
|
+
import{ScriptedGateway as t,SCRIPTED_MODEL as i,SCRIPTED_TOKEN_USAGE as o,scriptedGateway as s}from"./testing/scripted-gateway.js";import{createTurnHarness as p}from"./testing/turn-harness.js";import{ScriptedDecisions as D,scriptedDecisions as E}from"./testing/scripted-decisions.js";export{i as SCRIPTED_MODEL,o as SCRIPTED_TOKEN_USAGE,D as ScriptedDecisions,t as ScriptedGateway,p as createTurnHarness,E as scriptedDecisions,s as scriptedGateway};
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
export { BaseGraph, type GraphDefinition, type GraphNodeConstructor, type GraphSchemaMigration, type HistorySpace, } from "../../src/framework/base-graph.js";
|
|
2
|
-
export { GRAPH_NODE_CLASS, GraphNode, GraphNodeRuntime, Tool, type EmptyModelResponseContext, type GraphNodeUpdate, type GraphNodeResult, type InvalidJsonResponseContext, type ToolDefinition, type ToolInput, type GraphNodeLocalState, type GraphNodeTarget, } from "../../src/framework/graph-node.js";
|
|
2
|
+
export { GRAPH_NODE_CLASS, GraphNode, GraphNodeRuntime, Tool, type EmptyModelResponseContext, type GraphNodeUpdate, type GraphNodeResponse, type GraphNodeResult, type InvalidJsonResponseContext, type ToolDefinition, type ToolInput, type GraphNodeLocalState, type GraphNodeTarget, } from "../../src/framework/graph-node.js";
|
|
3
3
|
export { ConversationNode, type ConversationNodeRunResult, } from "../../src/framework/conversation-node.js";
|
|
4
4
|
export { LLM_GATEWAY_FACTORY, assertLlmTimeoutMs, type LlmCallOptions, type LlmGateway, type LlmGatewayFactory, type LlmGatewayTool, type LlmGatewayToolCall, } from "../../src/framework/llm-gateway.js";
|
|
5
5
|
export { ConversationRunner, DEFAULT_CONVERSATION_POLICY, DEFAULT_EMPTY_HISTORY_SEED, DEFAULT_EMPTY_RESPONSE_RECOVERY, DEFAULT_MAX_AGENT_ROUNDS, EmptyModelResponseError, assertEmptyResponseRetries, assertMaxAgentRounds, type ConversationPolicy, type ConversationRunResult, type EmptyResponseRecovery, } from "../../src/framework/conversation-runner.js";
|
|
6
6
|
export { describeStopReason, isRetryableStopReason, modelStopReason, type ModelStopCategory, type ModelStopReason, } from "../../src/framework/model-stop-reason.js";
|
|
7
7
|
export { currentTurnContext, currentTurnSignal, withTurnContext, type TurnContext, } from "../../src/framework/turn-context.js";
|
|
8
|
-
export { direct, finish, go, isToolResponse, stay, type ToolResponse, type ToolResponseBuilder, type ToolResponseKind, } from "../../src/framework/tool-response.js";
|
|
8
|
+
export { direct, directTo, finish, go, isToolResponse, stay, type ToolResponse, type ToolResponseBuilder, type ToolResponseKind, } from "../../src/framework/tool-response.js";
|
|
9
9
|
export { GraphStateSupport } from "../../src/framework/graph-state-support.js";
|
|
10
10
|
export { GRAPH_END_NODE, createGraphStateAnnotation, type GraphState, } from "../../src/framework/graph-state.js";
|
|
11
11
|
export { GraphRegistry, type RegisteredGraph, } from "../../src/framework/graph-registry.js";
|
|
@@ -13,7 +13,7 @@ export { GraphEngine, type GraphConstructor, type GraphEngineCreateOptions, type
|
|
|
13
13
|
export { ConfigManager, type ConfigManagerOptions, } from "../../src/framework/config-manager.js";
|
|
14
14
|
export { StateGraphExt, type CurrentNodeBranchOptions, type CurrentNodeSelector, type GraphEndpoint, type GraphNodeClass, type GraphNodeFactory, type RegisteredNode, } from "../../src/framework/state-graph-ext.js";
|
|
15
15
|
export { TerminateSessionNode } from "../../src/framework/terminate-session.node.js";
|
|
16
|
-
export { SessionLogError, SessionLogWarning, createSessionLogs, withSessionLogs, type SessionLogEntry, type SessionLogs, } from "../../src/framework/session-log.js";
|
|
16
|
+
export { SessionLogError, SessionLogDecision, SessionLogWarning, createSessionLogs, drainSessionLogs, restoreSessionLogs, withSessionLogs, type DecisionAuditEntry, type DecisionAuditInput, type DecisionAuditOutcome, type SessionLogEntry, type SessionLogs, } from "../../src/framework/session-log.js";
|
|
17
17
|
export { ProviderFileManager, type LlmFile, } from "../../src/framework/llm-file.js";
|
|
18
18
|
export { SessionManager, SessionTurnError, SESSION_BUSY, SESSION_CONFLICT, SESSION_COMPLETED, SESSION_DOCUMENT_VERSION, MemorySessionDocumentContainer, sessionTurnLeaseMs, sessionRevision, isLiveSessionTurn, matchesSessionWritePredicate, type SessionGraphMetadata, type SessionGraphDocument, type SessionGraphStatus, type SessionDocument, type SessionDocumentContainer, type SessionTurnLease, type SessionTurnCode, type SessionWritePredicate, type SessionWriteResult, type SessionWriteOptions, type BeginTurnResult, } from "../../src/framework/persistence/session-manager.js";
|
|
19
19
|
export { MongoDbSessionDocumentContainer } from "../../src/framework/persistence/mongodb-session-document.container.js";
|
|
@@ -25,3 +25,9 @@ export { ModelProvider, type BuiltInModelProviderConfigs, type CustomModelProvid
|
|
|
25
25
|
export { langChainModelInitialization, type LangChainModelInitialization, } from "../../src/framework/langchain-provider.adapter.js";
|
|
26
26
|
export { GRAPH_LLM_PROVIDERS, GRAPH_LLM_FAMILIES, GRAPH_LLM_CAPABILITIES, BUILT_IN_MODEL_CATALOG, GraphLlm, ModelCatalog, ModelProviderRegistry, type BuiltInGraphLlmConfig, type BuiltInModelId, type BuiltInModelParameters, type CommonModelParameters, type GraphLlmConfig, type GraphLlmConfigOverride, type GraphLlmCapability, type GraphLlmFamily, type GraphLlmModelMetadata, type GraphLlmParameters, type GraphLlmProvider, type GraphLlmRequiredCapabilities, type ModelCatalogDocument, type ModelParameterProfile, type ModelProviderAdapter, type ModelProviderInitialization, type OpenAIAuthReasoningParameters, type RuntimeGraphLlmConfig, } from "../../src/framework/graph-llm.config.js";
|
|
27
27
|
export { addTokenUsage, emptyTokenUsage, modelExecution, normalizeTokenUsage, tokenUsageFromMessage, type ModelExecution, type ModelResult, type TokenUsage, } from "../../src/framework/token-usage.js";
|
|
28
|
+
export { DecisionNode, } from "../../src/framework/decision/decision-node.js";
|
|
29
|
+
export { DecisionRunner, type DecisionRunOptions, } from "../../src/framework/decision/decision-runner.js";
|
|
30
|
+
export { DecisionProvider, DecisionProviderRegistry, type BuiltinDecisionProviderConfigs, } from "../../src/framework/decision/decision-provider.js";
|
|
31
|
+
export { TypeSafeClassifierAdapter, type TypeSafeProviderOptions, } from "../../src/framework/decision/typesafe-provider.js";
|
|
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
|
+
export { assertJsonCompatible, validateDecisionQuestions, validateDecisionResult, } from "../../src/framework/decision/decision-validation.js";
|
|
@@ -1,2 +1,3 @@
|
|
|
1
1
|
export { ScriptedGateway, SCRIPTED_MODEL, SCRIPTED_TOKEN_USAGE, scriptedGateway, type ScriptedCall, } from "../../src/testing/scripted-gateway.js";
|
|
2
2
|
export { createTurnHarness, type HarnessTurn, type TurnHarness, } from "../../src/testing/turn-harness.js";
|
|
3
|
+
export { ScriptedDecisions, scriptedDecisions, type ScriptedDecisionCall, } from "../../src/testing/scripted-decisions.js";
|
|
@@ -1,25 +1,29 @@
|
|
|
1
|
-
import { type GraphLlmConfig } from
|
|
2
|
-
import { HumanMessage } from
|
|
3
|
-
import type { LlmGateway } from
|
|
4
|
-
import { GraphNode, GraphNodeRuntime } from
|
|
5
|
-
import type { GraphState } from
|
|
6
|
-
import { StateGraphExt, type GraphNodeClass } from
|
|
7
|
-
import type { StateDefinitionInit } from
|
|
8
|
-
import type { SessionDocument } from
|
|
9
|
-
import { type ConversationPolicy } from
|
|
10
|
-
import type { GraphNodeLocalState, GraphNodeTarget } from
|
|
1
|
+
import { type GraphLlmConfig } from "./graph-llm.config.js";
|
|
2
|
+
import { HumanMessage } from "@langchain/core/messages";
|
|
3
|
+
import type { LlmGateway } from "./llm-gateway.js";
|
|
4
|
+
import { GraphNode, GraphNodeRuntime, type GraphNodeResponse } from "./graph-node.js";
|
|
5
|
+
import type { GraphState } from "./graph-state.js";
|
|
6
|
+
import { StateGraphExt, type GraphNodeClass } from "./state-graph-ext.js";
|
|
7
|
+
import type { StateDefinitionInit } from "@langchain/langgraph";
|
|
8
|
+
import type { SessionDocument } from "./persistence/session-manager.js";
|
|
9
|
+
import { type ConversationPolicy } from "./conversation-runner.js";
|
|
10
|
+
import type { GraphNodeLocalState, GraphNodeTarget } from "./node-outcome.js";
|
|
11
|
+
import type { DecisionOptions, DecisionErrorContext, DecisionProviderAdapter } from "./decision/decision-types.js";
|
|
11
12
|
export type HistorySpace = readonly [GraphNodeClass, string];
|
|
12
13
|
export type GraphSchemaMigration<State extends GraphState = GraphState> = Readonly<{
|
|
13
14
|
from: number;
|
|
14
15
|
migrate(sessionDoc: SessionDocument<State>): SessionDocument<State> | Promise<SessionDocument<State>>;
|
|
15
16
|
}>;
|
|
16
|
-
export type GraphDefinition<NodeId extends string = string, State extends GraphState = GraphState
|
|
17
|
+
export type GraphDefinition<NodeId extends string = string, State extends GraphState = GraphState & {
|
|
18
|
+
decisionUsage: NonNullable<GraphState["decisionUsage"]>;
|
|
19
|
+
}> = Readonly<{
|
|
17
20
|
llmConfig: GraphLlmConfig;
|
|
21
|
+
decisionConfig?: DecisionOptions;
|
|
18
22
|
endNode: NodeId;
|
|
19
23
|
schemaVersion?: number;
|
|
20
24
|
migrations?: readonly GraphSchemaMigration<State>[];
|
|
21
25
|
requiresUserMessage?: boolean;
|
|
22
|
-
responseMode?:
|
|
26
|
+
responseMode?: "chat" | "json";
|
|
23
27
|
historySpaces?: readonly HistorySpace[];
|
|
24
28
|
initialHistorySpace?: string;
|
|
25
29
|
maxAgentRounds?: number;
|
|
@@ -43,7 +47,7 @@ export declare abstract class BaseGraph<State extends GraphState> {
|
|
|
43
47
|
readonly schemaVersion: number;
|
|
44
48
|
readonly llmConfig: GraphLlmConfig;
|
|
45
49
|
readonly requiresUserMessage: boolean;
|
|
46
|
-
readonly responseMode:
|
|
50
|
+
readonly responseMode: "chat" | "json";
|
|
47
51
|
readonly maxAgentRounds: number;
|
|
48
52
|
readonly conversationPolicy: ConversationPolicy;
|
|
49
53
|
private compiledGraph?;
|
|
@@ -51,22 +55,24 @@ export declare abstract class BaseGraph<State extends GraphState> {
|
|
|
51
55
|
private readonly nodeMap;
|
|
52
56
|
private readonly endNode;
|
|
53
57
|
private readonly migrations;
|
|
54
|
-
protected constructor(llmGateway: LlmGateway, definition: GraphDefinition<State[
|
|
58
|
+
protected constructor(llmGateway: LlmGateway, definition: GraphDefinition<State["currentNode"], State>);
|
|
59
|
+
protected onDecisionError(_context: DecisionErrorContext<State>): GraphNodeResponse<State> | null | Promise<GraphNodeResponse<State> | null>;
|
|
60
|
+
attachDecisionProviderResolver(resolve: (id: string) => DecisionProviderAdapter): void;
|
|
55
61
|
get graph(): {
|
|
56
62
|
invoke(input: unknown): Promise<State>;
|
|
57
63
|
stream(input: unknown, options?: {
|
|
58
|
-
streamMode?:
|
|
64
|
+
streamMode?: "values";
|
|
59
65
|
}): Promise<AsyncIterable<State>>;
|
|
60
66
|
};
|
|
61
67
|
prepareInput(state: State | undefined, message: HumanMessage): Partial<State>;
|
|
62
68
|
saveNodeState<NodeClass extends GraphNodeTarget>(NodeClass: NodeClass, patch: Partial<GraphNodeLocalState<NodeClass>>): void;
|
|
63
69
|
restoreSessionDoc(sessionDoc: SessionDocument<State>): Promise<SessionDocument<State> | null>;
|
|
64
70
|
protected onRestoreSessionDoc(sessionDoc: SessionDocument<State>): Promise<SessionDocument<State> | null>;
|
|
65
|
-
protected idleMs(sessionDoc: Pick<SessionDocument,
|
|
71
|
+
protected idleMs(sessionDoc: Pick<SessionDocument, "modifiedAt">): number;
|
|
66
72
|
protected abstract buildGraph(): {
|
|
67
73
|
invoke(input: unknown): Promise<State>;
|
|
68
74
|
stream(input: unknown, options?: {
|
|
69
|
-
streamMode?:
|
|
75
|
+
streamMode?: "values";
|
|
70
76
|
}): Promise<AsyncIterable<State>>;
|
|
71
77
|
};
|
|
72
78
|
protected createStateGraph<StateDefinition extends StateDefinitionInit>(state: StateDefinition): StateGraphExt<StateDefinition>;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type { ConversationRunResult } from
|
|
2
|
-
import { GraphNode, type GraphNodeResult } from
|
|
3
|
-
import type { GraphState } from
|
|
4
|
-
import { type ToolResponse } from
|
|
1
|
+
import type { ConversationRunResult } from "./conversation-runner.js";
|
|
2
|
+
import { GraphNode, type GraphNodeResult } from "./graph-node.js";
|
|
3
|
+
import type { GraphState } from "./graph-state.js";
|
|
4
|
+
import { type ToolResponse } from "./tool-response.js";
|
|
5
5
|
export type ConversationNodeRunResult = ConversationRunResult;
|
|
6
6
|
export declare abstract class ConversationNode<State extends GraphState> extends GraphNode<State> {
|
|
7
7
|
protected endChat(input: {
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { type BaseMessage } from
|
|
2
|
-
import type { ToolCall } from
|
|
3
|
-
import type { GraphLlmConfig } from
|
|
4
|
-
import type { LlmCallOptions, LlmGateway, LlmGatewayTool } from
|
|
5
|
-
import { type TokenUsage } from
|
|
6
|
-
import { type ToolResponse } from
|
|
7
|
-
import { type ModelStopReason } from
|
|
1
|
+
import { type BaseMessage } from "@langchain/core/messages";
|
|
2
|
+
import type { ToolCall } from "@langchain/core/messages/tool";
|
|
3
|
+
import type { GraphLlmConfig } from "./graph-llm.config.js";
|
|
4
|
+
import type { LlmCallOptions, LlmGateway, LlmGatewayTool } from "./llm-gateway.js";
|
|
5
|
+
import { type TokenUsage } from "./token-usage.js";
|
|
6
|
+
import { type ToolResponse } from "./tool-response.js";
|
|
7
|
+
import { type ModelStopReason } from "./model-stop-reason.js";
|
|
8
8
|
export type ConversationRunResult = {
|
|
9
9
|
messages: BaseMessage[];
|
|
10
10
|
usage: TokenUsage;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { ConversationRunResult } from "../conversation-runner.js";
|
|
2
|
+
import { GraphNode, type GraphNodeResponse, type GraphNodeResult } from "../graph-node.js";
|
|
3
|
+
import type { GraphState } from "../graph-state.js";
|
|
4
|
+
import { type DecisionAnswers, type DecisionContext, type DecisionEvidence, type DecisionErrorContext, type DecisionOptions, type DecisionQuestionMap } from "./decision-types.js";
|
|
5
|
+
export declare abstract class DecisionNode<State extends GraphState, Questions extends DecisionQuestionMap = DecisionQuestionMap, LocalState extends object = Record<string, unknown>> extends GraphNode<State, LocalState> {
|
|
6
|
+
abstract defineQuestions(state: State): Questions;
|
|
7
|
+
getPrompt(_state: State): string;
|
|
8
|
+
protected getDecisionEvidence(_state: State): DecisionEvidence;
|
|
9
|
+
getDecisionConfig(): DecisionOptions;
|
|
10
|
+
abstract onDecision(answers: DecisionAnswers<Questions>, context: DecisionContext, state: State): GraphNodeResponse<State> | Promise<GraphNodeResponse<State>>;
|
|
11
|
+
protected onDecisionError(_context: DecisionErrorContext<State>): GraphNodeResponse<State> | null | Promise<GraphNodeResponse<State> | null>;
|
|
12
|
+
run(state: State): Promise<GraphNodeResult<State>>;
|
|
13
|
+
validateTools(): void;
|
|
14
|
+
private assertNoChatConfiguration;
|
|
15
|
+
protected usesChatModel(): boolean;
|
|
16
|
+
protected runConversation(_state: State, _context: Record<string, unknown>): Promise<ConversationRunResult>;
|
|
17
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { type DecisionProviderAdapter } from "./decision-types.js";
|
|
2
|
+
import { type TypeSafeProviderOptions } from "./typesafe-provider.js";
|
|
3
|
+
export type BuiltinDecisionProviderConfigs = Readonly<{
|
|
4
|
+
typesafe?: TypeSafeProviderOptions | undefined;
|
|
5
|
+
}>;
|
|
6
|
+
export declare class DecisionProvider {
|
|
7
|
+
private constructor();
|
|
8
|
+
static create(configs: BuiltinDecisionProviderConfigs): readonly DecisionProviderAdapter[];
|
|
9
|
+
}
|
|
10
|
+
export declare class DecisionProviderRegistry {
|
|
11
|
+
private readonly providers;
|
|
12
|
+
constructor(adapters?: readonly DecisionProviderAdapter[]);
|
|
13
|
+
resolve(id: string): DecisionProviderAdapter;
|
|
14
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { GraphState } from "../graph-state.js";
|
|
2
|
+
import type { GraphNodeResult } from "../graph-node.js";
|
|
3
|
+
import { type DecisionAnswers, type DecisionContext, type DecisionConversation, type DecisionErrorContext, type DecisionProviderAdapter, type DecisionQuestionMap, type DecisionState, type ResolvedDecisionOptions } from "./decision-types.js";
|
|
4
|
+
export type DecisionRunOptions<State extends GraphState, Questions extends DecisionQuestionMap> = Readonly<{
|
|
5
|
+
nodeId: string;
|
|
6
|
+
state: State;
|
|
7
|
+
conversation: DecisionConversation;
|
|
8
|
+
providerState: DecisionState;
|
|
9
|
+
questions: Questions;
|
|
10
|
+
provider: DecisionProviderAdapter;
|
|
11
|
+
options: ResolvedDecisionOptions;
|
|
12
|
+
callerSignal?: AbortSignal | undefined;
|
|
13
|
+
onDecision(answers: DecisionAnswers<Questions>, context: DecisionContext, state: State): GraphNodeResult<State> | Promise<GraphNodeResult<State>>;
|
|
14
|
+
onError(context: DecisionErrorContext<State>): GraphNodeResult<State> | Promise<GraphNodeResult<State>>;
|
|
15
|
+
}>;
|
|
16
|
+
export declare class DecisionRunner {
|
|
17
|
+
static run<State extends GraphState, Questions extends DecisionQuestionMap>(run: DecisionRunOptions<State, Questions>): Promise<GraphNodeResult<State>>;
|
|
18
|
+
}
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import type { GraphState } from "../graph-state.js";
|
|
2
|
+
export type JsonPrimitive = string | number | boolean | null;
|
|
3
|
+
export type JsonValue = JsonPrimitive | readonly JsonValue[] | {
|
|
4
|
+
readonly [key: string]: JsonValue;
|
|
5
|
+
};
|
|
6
|
+
export type JsonObject = Readonly<Record<string, JsonValue>>;
|
|
7
|
+
export type DecisionState = string | JsonObject | readonly JsonValue[];
|
|
8
|
+
export type DecisionConversation = Readonly<{
|
|
9
|
+
request: string;
|
|
10
|
+
priorRequests: readonly string[];
|
|
11
|
+
}>;
|
|
12
|
+
export type DecisionEvidence = JsonObject;
|
|
13
|
+
export type Choice = Readonly<{
|
|
14
|
+
type: "choice";
|
|
15
|
+
criteria: Readonly<Record<string, JsonValue>>;
|
|
16
|
+
instructions?: DecisionState;
|
|
17
|
+
}>;
|
|
18
|
+
export type Score = Readonly<{
|
|
19
|
+
type: "score";
|
|
20
|
+
criteria: readonly JsonValue[];
|
|
21
|
+
instructions?: DecisionState;
|
|
22
|
+
}>;
|
|
23
|
+
export type Noul = Readonly<{
|
|
24
|
+
type: "noul";
|
|
25
|
+
instructions?: DecisionState;
|
|
26
|
+
criteria?: Readonly<{
|
|
27
|
+
true?: JsonValue;
|
|
28
|
+
false?: JsonValue;
|
|
29
|
+
}>;
|
|
30
|
+
}>;
|
|
31
|
+
export type DecisionQuestion = Choice | Score | Noul;
|
|
32
|
+
export type DecisionQuestionMap = Readonly<Record<string, DecisionQuestion>>;
|
|
33
|
+
export type ChoiceAnswer<Label extends string = string> = {
|
|
34
|
+
type: "choice";
|
|
35
|
+
choice: Label;
|
|
36
|
+
probabilities: Record<Label, number>;
|
|
37
|
+
confidence: number;
|
|
38
|
+
};
|
|
39
|
+
export type ScoreAnswer = {
|
|
40
|
+
type: "score";
|
|
41
|
+
score: number;
|
|
42
|
+
legend: Record<string, JsonValue>;
|
|
43
|
+
probabilities: Record<string, number>;
|
|
44
|
+
confidence: number;
|
|
45
|
+
};
|
|
46
|
+
export type NoulAnswer = {
|
|
47
|
+
type: "noul";
|
|
48
|
+
noul: number;
|
|
49
|
+
};
|
|
50
|
+
export type DecisionAnswer = ChoiceAnswer | ScoreAnswer | NoulAnswer;
|
|
51
|
+
type AnswerFor<Question extends DecisionQuestion> = Question extends Choice ? ChoiceAnswer<Extract<keyof Question["criteria"], string>> : Question extends Score ? ScoreAnswer : NoulAnswer;
|
|
52
|
+
export type DecisionAnswers<Questions extends DecisionQuestionMap> = {
|
|
53
|
+
-readonly [Key in keyof Questions]: AnswerFor<Questions[Key]>;
|
|
54
|
+
};
|
|
55
|
+
export type DecisionTokenUsage = Readonly<{
|
|
56
|
+
inputTokens?: number;
|
|
57
|
+
outputTokens?: number;
|
|
58
|
+
}>;
|
|
59
|
+
export type DecisionUsage = {
|
|
60
|
+
calls: number;
|
|
61
|
+
inputTokens: number;
|
|
62
|
+
outputTokens: number;
|
|
63
|
+
totalTokens: number;
|
|
64
|
+
};
|
|
65
|
+
export declare function emptyDecisionUsage(): DecisionUsage;
|
|
66
|
+
export declare function normalizeDecisionUsage(usage?: Partial<DecisionUsage>): DecisionUsage;
|
|
67
|
+
export declare function addDecisionUsage(current: DecisionUsage | undefined, addition: DecisionUsage | undefined): DecisionUsage;
|
|
68
|
+
export declare function decisionUsage(usage?: DecisionTokenUsage): DecisionUsage;
|
|
69
|
+
export type DecisionOptions = Readonly<{
|
|
70
|
+
provider?: string;
|
|
71
|
+
model?: string;
|
|
72
|
+
timeoutMs?: number;
|
|
73
|
+
maxRetries?: number;
|
|
74
|
+
}>;
|
|
75
|
+
export type ResolvedDecisionOptions = Required<DecisionOptions>;
|
|
76
|
+
export declare const DEFAULT_DECISION_OPTIONS: ResolvedDecisionOptions;
|
|
77
|
+
export declare function resolveDecisionOptions(defaults?: DecisionOptions, overrides?: DecisionOptions): ResolvedDecisionOptions;
|
|
78
|
+
export type DecisionRequest = Readonly<{
|
|
79
|
+
model: string;
|
|
80
|
+
state: DecisionState;
|
|
81
|
+
questions: DecisionQuestionMap;
|
|
82
|
+
}>;
|
|
83
|
+
export type DecisionCallOptions = Readonly<{
|
|
84
|
+
signal: AbortSignal;
|
|
85
|
+
timeoutMs: number;
|
|
86
|
+
}>;
|
|
87
|
+
export type DecisionResult = Readonly<{
|
|
88
|
+
model: string;
|
|
89
|
+
answers: Record<string, DecisionAnswer>;
|
|
90
|
+
usage?: DecisionTokenUsage;
|
|
91
|
+
requestId?: string;
|
|
92
|
+
}>;
|
|
93
|
+
export type DecisionProviderAdapter = Readonly<{
|
|
94
|
+
id: string;
|
|
95
|
+
decide(input: DecisionRequest, options: DecisionCallOptions): Promise<DecisionResult>;
|
|
96
|
+
shouldRetry?(error: Error): boolean;
|
|
97
|
+
}>;
|
|
98
|
+
export type DecisionMetadata = Readonly<{
|
|
99
|
+
provider: string;
|
|
100
|
+
model: string;
|
|
101
|
+
durationMs: number;
|
|
102
|
+
attempts: number;
|
|
103
|
+
usage: DecisionTokenUsage;
|
|
104
|
+
requestId?: string;
|
|
105
|
+
}>;
|
|
106
|
+
export type DecisionContext = DecisionMetadata & DecisionConversation;
|
|
107
|
+
export type DecisionFailure = "configuration" | "provider" | "timeout" | "validation";
|
|
108
|
+
export type DecisionErrorContext<State extends GraphState = GraphState> = Readonly<{
|
|
109
|
+
nodeId: string;
|
|
110
|
+
provider: string;
|
|
111
|
+
model: string;
|
|
112
|
+
failure: DecisionFailure;
|
|
113
|
+
attempts: number;
|
|
114
|
+
error: Error;
|
|
115
|
+
state: Readonly<State>;
|
|
116
|
+
}>;
|
|
117
|
+
export declare class DecisionValidationError extends Error {
|
|
118
|
+
constructor(message: string);
|
|
119
|
+
}
|
|
120
|
+
export declare class DecisionConfigurationError extends Error {
|
|
121
|
+
constructor(message: string);
|
|
122
|
+
}
|
|
123
|
+
export declare class DecisionTimeoutError extends Error {
|
|
124
|
+
constructor(message?: string);
|
|
125
|
+
}
|
|
126
|
+
export {};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { type DecisionQuestionMap, type DecisionResult } from "./decision-types.js";
|
|
2
|
+
export declare function assertJsonCompatible(value: unknown, label: string): void;
|
|
3
|
+
export declare function validateDecisionQuestions(questions: DecisionQuestionMap): void;
|
|
4
|
+
export declare function validateDecisionResult(result: DecisionResult, questions: DecisionQuestionMap): void;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { type DecisionCallOptions, type DecisionProviderAdapter, type DecisionRequest, type DecisionResult } from "./decision-types.js";
|
|
2
|
+
export type TypeSafeProviderOptions = Readonly<{
|
|
3
|
+
apiKey?: string | undefined;
|
|
4
|
+
fetch?: typeof fetch | undefined;
|
|
5
|
+
}>;
|
|
6
|
+
export declare class TypeSafeClassifierAdapter implements DecisionProviderAdapter {
|
|
7
|
+
private readonly options;
|
|
8
|
+
readonly id = "typesafe";
|
|
9
|
+
constructor(options?: TypeSafeProviderOptions);
|
|
10
|
+
decide(input: DecisionRequest, options: DecisionCallOptions): Promise<DecisionResult>;
|
|
11
|
+
shouldRetry(error: Error): boolean;
|
|
12
|
+
}
|
|
@@ -5,6 +5,7 @@ import type { GraphState } from "./graph-state.js";
|
|
|
5
5
|
import type { RegisteredGraph } from "./graph-registry.js";
|
|
6
6
|
import type { RegisteredModelProviderAdapter } from "./model-provider.js";
|
|
7
7
|
import { SessionManager, type SessionDocument } from "./persistence/session-manager.js";
|
|
8
|
+
import type { DecisionProviderAdapter } from "./decision/decision-types.js";
|
|
8
9
|
export type GraphConstructor = {
|
|
9
10
|
new (llmGateway: LlmGateway): RegisteredGraph;
|
|
10
11
|
getGraphDefinition(): GraphDefinition;
|
|
@@ -14,12 +15,14 @@ export type GraphEngineOptions = Readonly<{
|
|
|
14
15
|
llmGatewayFactory?: LlmGatewayFactory;
|
|
15
16
|
graphs?: readonly GraphConstructor[];
|
|
16
17
|
providers?: readonly RegisteredModelProviderAdapter[];
|
|
18
|
+
decisionProviders?: readonly DecisionProviderAdapter[];
|
|
17
19
|
}>;
|
|
18
20
|
export type GraphEngineCreateOptions = Readonly<{
|
|
19
21
|
configManager?: ConfigManager;
|
|
20
22
|
llmGatewayFactory?: LlmGatewayFactory;
|
|
21
23
|
graphs?: readonly GraphConstructor[];
|
|
22
24
|
providers?: readonly RegisteredModelProviderAdapter[];
|
|
25
|
+
decisionProviders?: readonly DecisionProviderAdapter[];
|
|
23
26
|
}>;
|
|
24
27
|
export type RunResult = {
|
|
25
28
|
status: number;
|
|
@@ -38,6 +41,7 @@ export declare class GraphEngine {
|
|
|
38
41
|
private readonly registry;
|
|
39
42
|
private readonly sessions;
|
|
40
43
|
private readonly llmGatewayFactory;
|
|
44
|
+
private readonly decisionProviders;
|
|
41
45
|
private readonly inflightSessions;
|
|
42
46
|
constructor(options?: GraphEngineOptions);
|
|
43
47
|
static create(options?: GraphEngineCreateOptions): Promise<GraphEngine>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type { ModelProfile } from
|
|
2
|
-
import { type GraphLlmConfig, type GraphLlmFamily, type GraphLlmParameters } from
|
|
3
|
-
export { BUILT_IN_MODEL_CATALOG, GRAPH_LLM_CAPABILITIES, GRAPH_LLM_FAMILIES, GRAPH_LLM_PROVIDERS, ModelCatalog, ModelProviderRegistry, type AnthropicChatParameters, type AnthropicThinkingParameters, type BasicChatParameters, type BuiltInGraphLlmConfig, type BuiltInModelId, type BuiltInModelParameters, type CommonModelParameters, type GoogleChatParameters, type GraphLlmCapability, type GraphLlmConfig, type GraphLlmFamily, type GraphLlmParameters, type GraphLlmProvider, type GraphLlmRequiredCapabilities, type ModelCatalogDocument, type ModelParameterProfile, type ModelProviderAdapter, type ModelProviderInitialization, type OpenAIAuthReasoningParameters, type OpenAIChatParameters, type OpenAIReasoningParameters, type ResolvedModelDescriptor, type RuntimeGraphLlmConfig, } from
|
|
1
|
+
import type { ModelProfile } from "@langchain/core/language_models/profile";
|
|
2
|
+
import { type GraphLlmConfig, type GraphLlmFamily, type GraphLlmParameters } from "./model-catalog.js";
|
|
3
|
+
export { BUILT_IN_MODEL_CATALOG, GRAPH_LLM_CAPABILITIES, GRAPH_LLM_FAMILIES, GRAPH_LLM_PROVIDERS, ModelCatalog, ModelProviderRegistry, type AnthropicChatParameters, type AnthropicThinkingParameters, type BasicChatParameters, type BuiltInGraphLlmConfig, type BuiltInModelId, type BuiltInModelParameters, type CommonModelParameters, type GoogleChatParameters, type GraphLlmCapability, type GraphLlmConfig, type GraphLlmFamily, type GraphLlmParameters, type GraphLlmProvider, type GraphLlmRequiredCapabilities, type ModelCatalogDocument, type ModelParameterProfile, type ModelProviderAdapter, type ModelProviderInitialization, type OpenAIAuthReasoningParameters, type OpenAIChatParameters, type OpenAIReasoningParameters, type ResolvedModelDescriptor, type RuntimeGraphLlmConfig, } from "./model-catalog.js";
|
|
4
4
|
export type GraphLlmConfigOverride = GraphLlmConfig | Readonly<{
|
|
5
5
|
model?: never;
|
|
6
6
|
params?: Readonly<Record<string, unknown | null>>;
|