@picoflow/ezgraph 0.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (74) hide show
  1. package/LICENSE.md +17 -0
  2. package/README.md +171 -0
  3. package/dist/framework/base-graph.js +1 -0
  4. package/dist/framework/config-manager.js +1 -0
  5. package/dist/framework/conversation-node.js +1 -0
  6. package/dist/framework/conversation-runner.js +1 -0
  7. package/dist/framework/conversation-tool-result.js +1 -0
  8. package/dist/framework/graph-engine.js +1 -0
  9. package/dist/framework/graph-llm.config.js +1 -0
  10. package/dist/framework/graph-node.js +1 -0
  11. package/dist/framework/graph-registry.js +1 -0
  12. package/dist/framework/graph-state-support.js +1 -0
  13. package/dist/framework/graph-state.js +1 -0
  14. package/dist/framework/json-response.js +1 -0
  15. package/dist/framework/langchain-llm-gateway.js +1 -0
  16. package/dist/framework/langchain-provider.adapter.js +1 -0
  17. package/dist/framework/llm-file.js +1 -0
  18. package/dist/framework/llm-gateway.js +1 -0
  19. package/dist/framework/model-catalog.js +1 -0
  20. package/dist/framework/model-provider.js +1 -0
  21. package/dist/framework/model-stop-reason.js +1 -0
  22. package/dist/framework/node-outcome.js +1 -0
  23. package/dist/framework/node-state.js +1 -0
  24. package/dist/framework/persistence/cosmos-session-document.container.js +1 -0
  25. package/dist/framework/persistence/mongodb-session-document.container.js +1 -0
  26. package/dist/framework/persistence/session-manager.js +1 -0
  27. package/dist/framework/persistence/sqlite-session-document.container.js +13 -0
  28. package/dist/framework/session-log.js +1 -0
  29. package/dist/framework/stable-id.js +1 -0
  30. package/dist/framework/state-graph-ext.js +1 -0
  31. package/dist/framework/terminate-session.node.js +1 -0
  32. package/dist/framework/token-usage.js +1 -0
  33. package/dist/framework/turn-context.js +1 -0
  34. package/dist/index.js +1 -0
  35. package/dist/testing/scripted-gateway.js +1 -0
  36. package/dist/testing/turn-harness.js +1 -0
  37. package/dist/testing.js +1 -0
  38. package/dist/types/npmlib/src/index.d.ts +27 -0
  39. package/dist/types/npmlib/src/testing.d.ts +2 -0
  40. package/dist/types/src/framework/base-graph.d.ts +66 -0
  41. package/dist/types/src/framework/config-manager.d.ts +13 -0
  42. package/dist/types/src/framework/conversation-node.d.ts +18 -0
  43. package/dist/types/src/framework/conversation-runner.d.ts +49 -0
  44. package/dist/types/src/framework/conversation-tool-result.d.ts +19 -0
  45. package/dist/types/src/framework/graph-engine.d.ts +82 -0
  46. package/dist/types/src/framework/graph-llm.config.d.ts +21 -0
  47. package/dist/types/src/framework/graph-node.d.ts +106 -0
  48. package/dist/types/src/framework/graph-registry.d.ts +26 -0
  49. package/dist/types/src/framework/graph-state-support.d.ts +24 -0
  50. package/dist/types/src/framework/graph-state.d.ts +26 -0
  51. package/dist/types/src/framework/json-response.d.ts +1 -0
  52. package/dist/types/src/framework/langchain-llm-gateway.d.ts +23 -0
  53. package/dist/types/src/framework/langchain-provider.adapter.d.ts +4 -0
  54. package/dist/types/src/framework/llm-file.d.ts +13 -0
  55. package/dist/types/src/framework/llm-gateway.d.ts +27 -0
  56. package/dist/types/src/framework/model-catalog.d.ts +252 -0
  57. package/dist/types/src/framework/model-provider.d.ts +19 -0
  58. package/dist/types/src/framework/model-stop-reason.d.ts +11 -0
  59. package/dist/types/src/framework/node-outcome.d.ts +41 -0
  60. package/dist/types/src/framework/node-state.d.ts +6 -0
  61. package/dist/types/src/framework/persistence/cosmos-session-document.container.d.ts +34 -0
  62. package/dist/types/src/framework/persistence/mongodb-session-document.container.d.ts +18 -0
  63. package/dist/types/src/framework/persistence/session-manager.d.ts +116 -0
  64. package/dist/types/src/framework/persistence/sqlite-session-document.container.d.ts +19 -0
  65. package/dist/types/src/framework/session-log.d.ts +11 -0
  66. package/dist/types/src/framework/stable-id.d.ts +7 -0
  67. package/dist/types/src/framework/state-graph-ext.d.ts +58 -0
  68. package/dist/types/src/framework/terminate-session.node.d.ts +9 -0
  69. package/dist/types/src/framework/token-usage.d.ts +24 -0
  70. package/dist/types/src/framework/turn-context.d.ts +7 -0
  71. package/dist/types/src/testing/scripted-gateway.d.ts +45 -0
  72. package/dist/types/src/testing/turn-harness.d.ts +35 -0
  73. package/model-catalog.schema.json +57 -0
  74. package/package.json +64 -0
package/LICENSE.md ADDED
@@ -0,0 +1,17 @@
1
+ # EZGraph Commercial Runtime License
2
+
3
+ Licensor: picoflow LLC
4
+ Licensed Work: ezgraph (including its TypeScript source code, compiled JavaScript, and type definitions)
5
+
6
+ ## 1. Grant of License
7
+ The Licensor hereby grants you the right to copy, modify, create derivative works,
8
+ distribute, and make available the Licensed Work. However, you may only do so under the
9
+ Use Limitations set forth below.
10
+
11
+ ## 2. Use Limitations
12
+ Your use of the Licensed Work is permitted for any purpose, EXCEPT THAT you may not:
13
+ 1. Provide the Licensed Work to third parties as a hosted or managed service, where the
14
+ service competes with the Licensed Work or provides substantial parts of the Licensed
15
+ Work's core functionality to users.
16
+ 2. Repackage, re-license, or redistribute the Licensed Work as a software development kit (SDK),
17
+ developer library, or plugin framework competing directly with the Licensed Work.
package/README.md ADDED
@@ -0,0 +1,171 @@
1
+ # ezgraph
2
+
3
+ ezgraph is a pre-release library of provider-neutral graph primitives built on
4
+ LangGraph and LangChain. It is implemented as plain TypeScript and does not
5
+ require an application framework or dependency-injection container.
6
+
7
+ Learn more, including the tutorials and developer guide, at the [EZGraph
8
+ website](https://www.picoflow.io/ezgraph/).
9
+
10
+ ## Usage
11
+
12
+ ~~~ts
13
+ import { ConfigManager, GraphEngine } from "ezgraph";
14
+ import { DemoGraph } from "./demo-graph.js";
15
+
16
+ const config = new ConfigManager(); // reads .env, then process.env
17
+ const engine = await GraphEngine.create({
18
+ configManager: config,
19
+ graphs: [DemoGraph],
20
+ });
21
+
22
+ const result = await engine.run({
23
+ graphName: "DemoGraph",
24
+ userMessage: "Hello",
25
+ });
26
+ ~~~
27
+
28
+ Graph and node IDs default to their class names, so existing declarations need
29
+ no identity boilerplate. If a class is renamed, preserve its persisted identity
30
+ with an override:
31
+
32
+ ~~~ts
33
+ export class MyWeatherNode extends GraphNode<DemoGraphState> {
34
+ static override id() {
35
+ return "WeatherNode";
36
+ }
37
+ }
38
+ ~~~
39
+
40
+ References that intentionally select a node identity should likewise use
41
+ `WeatherNode.id()` rather than `WeatherNode.name`, including the initial node
42
+ passed to `createGraphStateAnnotation`. Existing `nodes(...)`, `registerTurns(...)`,
43
+ `addEdge(...)`, and `advance(...)` calls remain unchanged. `branchBy(...)`
44
+ cases use `{ when: selector, routeTo: destination }` objects.
45
+
46
+ Every graph has an independent persisted schema version. Version 1 is the
47
+ default; set `schemaVersion` and provide ordered migrations in the graph
48
+ definition only when its persisted state shape changes.
49
+
50
+ Conversational stages extend `ConversationNode` and return semantic outcomes
51
+ instead of manually coordinating graph protocol fields:
52
+
53
+ ~~~ts
54
+ protected nextStep(state, context, conversation) {
55
+ if (conversation.quitRequested) return this.quit(conversation);
56
+ if (context.complete) {
57
+ return this.advance(NextNode, conversation)
58
+ .withState({ value: context.value });
59
+ }
60
+ return this.stay(conversation).withState({ value: context.value });
61
+ }
62
+ ~~~
63
+
64
+ Use `finish(response, conversation)` for terminal responses. Outcome builders
65
+ automatically coordinate history, tokens, response, input consumption, and the
66
+ persisted resume node. `toolResult(output).withContext(...)` provides typed
67
+ per-turn tool effects, and `branchBy(...)` keeps conditional
68
+ topology in the graph without a repetitive `route()` method. See
69
+ `docs/conversation-node-outcomes.md` in the source repository for the complete
70
+ contract.
71
+
72
+ For conversation graphs, call `graph.configAutoRoute()` to route semantic
73
+ outcomes automatically: `stay()` ends the current invocation, `advance()`
74
+ continues at its target, `quit()` continues at `TerminateSessionNode`, and
75
+ `finish()` ends it. Use `.via(WorkerNode)` to run a registered worker first
76
+ without changing the outcome's durable `currentNode`. `branchBy(SourceNode,
77
+ ...)` remains available when a source needs explicit topology and takes
78
+ precedence over automatic routing for that source.
79
+
80
+ `GraphEngine` uses in-memory session persistence by default, so the shorter
81
+ `new GraphEngine().registerGraph([DemoGraph])` form works without configuration.
82
+ Set `SESSION_STORE` to `sqlite`, `mongodb`, or `cosmos` when durable persistence
83
+ is needed.
84
+
85
+ ## Model catalog
86
+
87
+ Built-in models use `ModelCatalog.model`, which correlates each model ID with its legal
88
+ parameters at compile time and validates the same contract at runtime:
89
+
90
+ ~~~ts
91
+ import { ModelCatalog } from "ezgraph";
92
+
93
+ const llmConfig = ModelCatalog.model("openai:gpt-5.4", {
94
+ retries: 3,
95
+ reasoningEffort: "medium",
96
+ forceToolCalls: true,
97
+ });
98
+ ~~~
99
+
100
+ For a model released after the installed EZGraph version, load an application
101
+ JSON catalog at startup and use its resolver. Catalog construction validates
102
+ the profile, JSON Schema, parameter mappings, provider/model relationship, and
103
+ references. `catalog.model(...)` then validates parameters and returns a
104
+ branded runtime configuration; an arbitrary object cannot bypass the catalog.
105
+
106
+ ~~~ts
107
+ import modelCatalogJson from "./model-catalog.json" with { type: "json" };
108
+ import { ModelCatalog } from "ezgraph";
109
+
110
+ const catalog = ModelCatalog.create(modelCatalogJson);
111
+ const llmConfig = catalog.model("openai:future-model", {
112
+ retries: 3,
113
+ reasoningEffort: "medium",
114
+ });
115
+ ~~~
116
+
117
+ The complete JSON format is published as
118
+ `ezgraph/model-catalog.schema.json`. Built-in entries cannot be replaced by an
119
+ application catalog. A full node model configuration replaces the graph model;
120
+ `{ params: { temperature: 0.5 } }` patches the current model and `null` removes
121
+ an inherited optional parameter.
122
+
123
+ Providers absent from EZGraph and LangChain require application code because
124
+ JSON cannot safely contain constructors or credentials. Register an initializer
125
+ and pass the registry when creating the catalog:
126
+
127
+ ~~~ts
128
+ import { ModelCatalog, ModelProviderRegistry } from "ezgraph";
129
+
130
+ const providers = ModelProviderRegistry.create().register("glm", {
131
+ initialize({ model, options }) {
132
+ return {
133
+ model,
134
+ options: {
135
+ modelProvider: "openai",
136
+ ...options,
137
+ apiKey: process.env.GLM_API_KEY,
138
+ configuration: { baseURL: "https://api.z.ai/api/paas/v4" },
139
+ },
140
+ cacheKey: JSON.stringify({ provider: "glm", model, options }),
141
+ };
142
+ },
143
+ });
144
+
145
+ const catalog = ModelCatalog.create(modelCatalogJson, { providers });
146
+ ~~~
147
+
148
+ The catalog rejects an unregistered custom provider during startup. Provider
149
+ credentials are initializer concerns and are never persisted in model metadata.
150
+
151
+ ## Development
152
+
153
+ From the repository root:
154
+
155
+ ~~~sh
156
+ npm ci
157
+ npm run build:npmlib
158
+ npm run build:locallib
159
+ ~~~
160
+
161
+ `build:npmlib` creates `staging/npm`, the publishable ESM package. Its bundle
162
+ is minified, keeps public runtime names, and deliberately contains no source
163
+ map or source files. `build:locallib` creates `staging/lib`, a local-only package
164
+ that retains the framework TypeScript source and an unbundled, source-mapped
165
+ runtime for debugging through the sibling demo. Re-run `build:locallib` after
166
+ framework changes.
167
+
168
+ ## Distribution status
169
+
170
+ EZGraph is distributed under the EZGraph Commercial Runtime License. See
171
+ `LICENSE.md` in the published package for the applicable production-use terms.
@@ -0,0 +1 @@
1
+ var d=Object.defineProperty;var a=(t,r)=>d(t,"name",{value:r,configurable:!0});import{GraphLlm as c}from"./graph-llm.config.js";import{GraphNodeRuntime as g}from"./graph-node.js";import{StateGraphExt as u}from"./state-graph-ext.js";import{assertEmptyResponseRetries as l,assertMaxAgentRounds as y,DEFAULT_CONVERSATION_POLICY as h,DEFAULT_MAX_AGENT_ROUNDS as w}from"./conversation-runner.js";import{assertLlmTimeoutMs as f}from"./llm-gateway.js";import{assertGraphSchemaVersion as m,assertStableId as M,stableClassId as n}from"./stable-id.js";class p{static{a(this,"BaseGraph")}llmGateway;static id(){return this.name}static assertName(r){return p.assertId(r)}static assertId(r){return M(r,"graph")}name;id;schemaVersion;llmConfig;requiresUserMessage;responseMode;maxAgentRounds;conversationPolicy;compiledGraph;runtime;nodeMap=new Map;endNode;migrations;constructor(r,e){this.llmGateway=r;const s=new.target;this.name=s.name,this.id=n(s,"graph"),this.schemaVersion=m(e.schemaVersion??1),this.migrations=S(e.migrations,this.schemaVersion),this.llmConfig=c.resolveConfig(e.llmConfig),this.requiresUserMessage=e.requiresUserMessage??!0,this.responseMode=e.responseMode??"chat",this.maxAgentRounds=y(e.maxAgentRounds??w),this.conversationPolicy=v(e),this.endNode=e.endNode,this.runtime=new g(e.endNode,this.llmConfig,R(e.historySpaces),e.initialHistorySpace,this.responseMode,this.maxAgentRounds,this.conversationPolicy)}get graph(){return this.compiledGraph??=this.buildGraph()}prepareInput(r,e){const s=this.runtime.historySpace(r?.currentNode);return{...r??{},histories:{...r?.histories??{},[s]:[...r?.histories[s]??[],e]}}}async restoreSessionDoc(r){if(r.graph.id!==this.id)throw new Error(`Session '${r.id}' belongs to graph '${r.graph.id}', not '${this.id}'. Start a new session to run a different graph.`);if(r.graph.schemaVersion>this.schemaVersion)throw new Error(`Session '${r.id}' uses graph '${this.id}' schema version ${r.graph.schemaVersion}, but this runtime supports version ${this.schemaVersion}.`);let e=r;for(;e.graph.schemaVersion<this.schemaVersion;){const s=e.graph.schemaVersion,i=this.migrations.get(s);if(!i)throw new Error(`Graph '${this.id}' has no migration from schema version ${s} to ${s+1}.`);const o=await i.migrate(e);if(o.graph.id!==this.id)throw new Error(`Graph '${this.id}' migration from schema version ${s} changed the persisted graph ID.`);e={...o,graph:{...o.graph,schemaVersion:s+1}}}return await this.onRestoreSessionDoc(e)}async onRestoreSessionDoc(r){return r}idleMs(r){const e=Date.parse(r.modifiedAt);return Number.isFinite(e)?Date.now()-e:0}createStateGraph(r){return new u(r,(e=>this.createNode(e)),this.endNode)}createNode(r){const e=new r(this.llmGateway,this.runtime),s=n(r,"graph node");if(e.id!==s)throw new Error(`Graph node factory for '${s}' constructs '${e.id}'.`);if(this.nodeMap.has(e.id))throw new Error(`Graph node '${e.id}' is already registered.`);return this.nodeMap.set(e.id,e),this.runtime.registerTools(e.id,e.defineTool()),Object.freeze(e),e}}function v(t){const r=t.emptyResponseRecovery===void 0?h.emptyResponseRecovery:t.emptyResponseRecovery;return r&&l(r.retries),{...t.llmTimeoutMs===void 0?{}:{llmTimeoutMs:f(t.llmTimeoutMs)},emptyHistorySeed:t.emptyHistorySeed===void 0?h.emptyHistorySeed:t.emptyHistorySeed,emptyResponseRecovery:r}}a(v,"resolveConversationPolicy");function R(t){return Object.fromEntries((t??[]).map(([r,e])=>[n(r,"graph node"),e]))}a(R,"historySpaceMap");function S(t,r){const e=new Map;let s;for(const i of t??[]){const o=m(i.from);if(o>=r)throw new Error(`A graph migration from version ${o} cannot target schema version ${r}.`);if(e.has(o))throw new Error(`More than one graph migration starts at version ${o}.`);if(s!==void 0&&o!==s+1)throw new Error(`Graph migrations must be ordered and contiguous; version ${s} must be followed by ${s+1}.`);e.set(o,i),s=o}return e}a(S,"migrationMap");export{p as BaseGraph};
@@ -0,0 +1 @@
1
+ var s=Object.defineProperty;var t=(n,e)=>s(n,"name",{value:e,configurable:!0});import{config as o}from"dotenv";class v{static{t(this,"ConfigManager")}values;constructor(e={}){const r={};if(!e.ignoreEnvFile){const i=o({path:e.envFilePath??".env",processEnv:r,quiet:!0});if(i.error&&!u(i.error))throw i.error}this.values={...r,...e.environment??process.env,...e.values}}get(e,r){return this.values[e]??r}require(e){const r=this.get(e);if(!r)throw new Error(`Configuration value '${e}' is required.`);return r}}function u(n){return n.code==="ENOENT"}t(u,"isMissingFile");export{v as ConfigManager};
@@ -0,0 +1 @@
1
+ var f=Object.defineProperty;var c=(n,e)=>f(n,"name",{value:e,configurable:!0});var p=function(n,e,t,r){var o=arguments.length,s=o<3?e:r===null?r=Object.getOwnPropertyDescriptor(e,t):r,i;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")s=Reflect.decorate(n,e,t,r);else for(var a=n.length-1;a>=0;a--)(i=n[a])&&(s=(o<3?i(s):o>3?i(e,t,s):i(e,t))||s);return o>3&&s&&Object.defineProperty(e,t,s),s},u=function(n,e){if(typeof Reflect=="object"&&typeof Reflect.metadata=="function")return Reflect.metadata(n,e)};import{GraphNode as l,Tool as h}from"./graph-node.js";import{TerminateSessionNode as d}from"./terminate-session.node.js";class m extends l{static{c(this,"ConversationNode")}quitRequests=new WeakSet;supportsAutomaticOutcomeRouting=!0;async endChat(e,t){return this.quitRequests.add(t),{output:{message:e.message?.trim()||"Of course. This conversation is now complete."},stopAfterBatch:!0}}quit(e){return this.transition(d,e,!1)}async run(e){const t=this.createContext(e),r=await this.runConversation(e,t);return this.nextStep(e,t,r)}async runConversation(e,t){this.quitRequests.delete(t);try{return{...await super.runConversation(e,t),quitRequested:this.quitRequests.has(t)}}finally{this.quitRequests.delete(t)}}}p([h("terminate_session"),u("design:type",Function),u("design:paramtypes",[Object,Object]),u("design:returntype",Promise)],m.prototype,"endChat",null);export{m as ConversationNode};
@@ -0,0 +1 @@
1
+ const UB=K;(function(E,a){const UG={E:0x1d6,a:0x1cb,q:0x1b3,R:0x1ad,z:0x1b9,F:0x1bc},UA=K,q=E();while(!![]){try{const R=parseInt(UA(UG.E))/0x1*(-parseInt(UA(0x1c1))/0x2)+-parseInt(UA(UG.a))/0x3+-parseInt(UA(0x1c3))/0x4*(parseInt(UA(UG.q))/0x5)+-parseInt(UA(0x1b7))/0x6+-parseInt(UA(UG.R))/0x7+-parseInt(UA(0x1c6))/0x8*(-parseInt(UA(UG.z))/0x9)+parseInt(UA(UG.F))/0xa*(parseInt(UA(0x1b0))/0xb);if(R===a)break;else q['push'](q['shift']());}catch(z){q['push'](q['shift']());}}}(c,0x3a36d));var v=Object[UB(0x1c5)],p=(E,a)=>v(E,UB(0x1d1),{'value':a,'configurable':!0x0});import{HumanMessage as h,ToolMessage as g}from'@langchain/core/messages';import{addTokenUsage as f,emptyTokenUsage as u}from'./token-usage.js';import{describeStopReason as G,isRetryableStopReason as V,modelStopReason as e}from'./model-stop-reason.js';import{SessionLogWarning as d}from'./session-log.js';class k extends Error{static{p(this,UB(0x1bb));}[UB(0x1d7)];constructor(E){const UK=UB;super(UK(0x1b5)+G(E)+').'),this['reason']=E,this['name']=UK(0x1bb);}}const P=0x8;function K(U,M){U=U-0x1ac;const T=c();let C=T[U];if(K['VHduzc']===undefined){var D=function(g){const f='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+/=';let x='',u='';for(let v=0x0,G,V,e=0x0;V=g['charAt'](e++);~V&&(G=v%0x4?G*0x40+V:V,v++%0x4)?x+=String['fromCharCode'](0xff&G>>(-0x2*v&0x6)):0x0){V=f['indexOf'](V);}for(let O=0x0,d=x['length'];O<d;O++){u+='%'+('00'+x['charCodeAt'](O)['toString'](0x10))['slice'](-0x2);}return decodeURIComponent(u);};K['EoGUqK']=D,K['HnwWdm']={},K['VHduzc']=!![];}const A=T[0x0],B=U+A,h=K['HnwWdm'][B];return!h?(C=K['EoGUqK'](C),K['HnwWdm'][B]=C):C=h,C;}function D(E){const Uh=UB;if(!Number[Uh(0x1ba)](E)||E<0x1)throw new Error(Uh(0x1be)+String(E)+'.');return E;}p(D,UB(0x1c9));const T='Start',A={'retries':0x2,'nudge':UB(0x1db)};function L(E){const Ug=UB;if(!Number[Ug(0x1ba)](E)||E<0x0)throw new Error(Ug(0x1d8)+String(E)+'.');return E;}p(L,UB(0x1bd));const B={'emptyHistorySeed':T,'emptyResponseRecovery':A};function c(){const Ua=['BgXTq29UzMLN','zw1WDhLszxnWB25ZzvjLy292zxj5','DMfSDwu','zw50CMLLCW','mZzwsgTIBxq','CMvHC29U','zw1WDhLszxnWB25ZzvjLy292zxj5lNjLDhjPzxmGBxvZDcbIzsbHig5VBI1UzwDHDgL2zsbPBNrLz2vYoYbYzwnLAxzLzca','q29UDMvYC2f0Aw9Uigv4y2vLzgvKia','CNvU','rM9SBg93ihrOzsbZExn0zw0GChjVBxb0igfUzcbYzxnWB25KihbYB3bLCMX5lIbvC2uGDgHLihjLCxvPCMvKihrVB2WGD2HLBIbPBNn0CNvJDgvKlG','BgvUz3rO','CMv0CMLLCW','y2XLyw51Ca','Cg9W','zxHLy3v0zvrVB2W','mtK3ndy1mvjHBKXKEq','C3rYAw5NAwz5','AgLZDg9YEq','mJGXmJi2z0HiDNbM','BwvZC2fNzvrLEhq','B3v0Chv0','mZbXshflzhm','zw1WDhLiAxn0B3j5u2vLza','vgHLig1VzgvSihjLDhvYBMvKigfUigvTChr5ihjLC3bVBNnLicG','y29UDgvUDa','mtK0ntiYnfbsyxLXDG','DxnHz2u','nJq0ndLiAhPKtwm','AxnjBNrLz2vY','rw1WDhLnB2rLBfjLC3bVBNnLrxjYB3i','nJCWr1rvAwfQ','yxnZzxj0rw1WDhLszxnWB25ZzvjLDhjPzxm','Bwf4qwDLBNrsB3vUzhmGBxvZDcbIzsbHihbVC2L0AxzLigLUDgvNzxi7ihjLy2vPDMvKia','BgXTr2f0zxDHEq','igfNzw50ihjVDw5KCY4','mJq0odHxr1jSvuK','BwfW','mJKZodiWuKfOwxfx','BwvZC2fNzxm','zgvMAw5LuhjVCgvYDhK','mZKYAfDhBLbP','ChvZAa','y2fSBe9WDgLVBNm','yxnZzxj0twf4qwDLBNrsB3vUzhm','BNvKz2u','mtaXmJy2nwH3tvf2vG','q29UDMvYC2f0Aw9UuNvUBMvY','y2XLyw51Cef0DgfJAg1LBNrZ','C3rVCefMDgvYqMf0y2G','Bwf4qwDLBNrsB3vUzhm','Dg9VBhm','BMfTzq'];c=function(){return Ua;};return c();}class J{static{p(this,UB(0x1cc));}[UB(0x1bf)];constructor(E){const Uf=UB;this[Uf(0x1bf)]=E;}async[UB(0x1da)](q){const UE={E:0x1b4,a:0x1af,q:0x1cf,R:0x1d3,z:0x1d2,F:0x1c2,Q:0x1c7,W:0x1d4,H:0x1dc,i:0x1df,Z:0x1ca,w:0x1d5,j:0x1b2,n:0x1c7,t:0x1cd},Ux=UB,z=q[Ux(0x1b4)]===void 0x0?T:q[Ux(UE.E)],F=q[Ux(UE.a)][Ux(0x1dc)]===0x0&&z!==null,Q=F?[new h(z)]:[...q[Ux(UE.a)]],W=F?[...Q]:[];let H=[],Z=u();const j=D(q[Ux(UE.q)]??P),t=q[Ux(UE.R)]===void 0x0?A:q['emptyResponseRecovery'],Y=t?L(t[Ux(0x1dd)]):0x0;let X=0x0;for(let U0=0x0;U0<j;U0+=0x1){let U1;try{U1=await this['llmGateway']['agent'](q['systemPrompt'],Q,q[Ux(0x1d0)],q[Ux(UE.z)],q[Ux(0x1c8)]);}catch(U4){const U5=H;throw H=[],await Promise['allSettled'](U5[Ux(UE.F)](U6=>U6())),U4;}Z=f(Z,U1[Ux(0x1b8)]),W[Ux(UE.Q)](U1[Ux(0x1d4)]),Q['push'](U1[Ux(UE.W)]);const U2=U1[Ux(0x1d4)]['tool_calls']??[];if(U2[Ux(UE.H)]===0x0){const U6=$(U1[Ux(0x1d4)]);if(U6['trim']())return await I(),{'messages':W,'usage':Z,'response':U6,'stoppedAfterTool':!0x1};const U7=e(U1[Ux(0x1d4)]),U8=V(U7)&&t!==null&&X<Y;if(d({'empty_model_response':G(U7),'retried':U8}),U8&&t){X+=0x1,W[Ux(0x1df)](),Q[Ux(UE.i)](),Q['push'](new h(t[Ux(UE.Z)]));continue;}return await I(),{'messages':W,'usage':Z,'response':U6,'stoppedAfterTool':!0x1,'stopReason':U7};}await I();let U3=!0x1;try{for(const [U9,UU]of U2[Ux(UE.w)]()){const UM=await q[Ux(0x1ac)](UU),UT=new g({'content':JSON['stringify'](UM[Ux(UE.j)]),'tool_call_id':UU['id']??'tool-call-'+U0+'-'+U9,'name':UU[Ux(0x1d1)]});W[Ux(0x1c7)](UT),Q[Ux(0x1c7)](UT),UM[Ux(0x1c4)]&&(W[Ux(UE.n)](...UM['messages']),Q[Ux(UE.n)](...UM['messages'])),UM['cleanup']&&H[Ux(UE.Q)](UM[Ux(0x1de)]),U3||=UM[Ux(0x1ce)]===!0x0;}}catch(UC){throw await I(),UC;}if(U3)return await I(),{'messages':W,'usage':Z,'stoppedAfterTool':!0x0};}throw await I(),new Error(Ux(0x1d9)+j+Ux(0x1c0));async function I(){const Uu=Ux,UD=H;H=[],await Promise['allSettled'](UD[Uu(0x1c2)](Uc=>Uc()));}p(I,Ux(UE.t));}}function $(E){const Uk={E:0x1b6,a:0x1ae},Uv=UB;return typeof E[Uv(Uk.E)]=='string'?E['content']:JSON[Uv(Uk.a)](E[Uv(0x1b6)]);}p($,UB(0x1b1));export{J as ConversationRunner,B as DEFAULT_CONVERSATION_POLICY,T as DEFAULT_EMPTY_HISTORY_SEED,A as DEFAULT_EMPTY_RESPONSE_RECOVERY,P as DEFAULT_MAX_AGENT_ROUNDS,k as EmptyModelResponseError,L as assertEmptyResponseRetries,D as assertMaxAgentRounds};
@@ -0,0 +1 @@
1
+ var i=Object.defineProperty;var n=(o,t)=>i(o,"name",{value:t,configurable:!0});const u=Symbol("TOOL_RESULT_EFFECTS");function p(o){return l({output:o},{context:[],stops:[]})}n(p,"createConversationToolResult");function b(o,t){const s=o[u];if(!s)return o;for(const e of s.context){const r=typeof e=="function"?e(t):e;if(!r||typeof r!="object"||Array.isArray(r))throw new Error("withContext() must produce an object patch.");Object.assign(t,r)}const a=s.stops.some(e=>typeof e=="function"?e(t):e);return{...o,...a?{stopAfterBatch:!0}:{}}}n(b,"resolveConversationToolResult");function l(o,t){const s={...o},a=n((e,r=t)=>l({...o,...e},r),"derive");return Object.defineProperties(s,{[u]:{enumerable:!1,value:t},withContext:{enumerable:!1,value:n(e=>a({},{...t,context:[...t.context,e]}),"value")},withMessages:{enumerable:!1,value:n(e=>{const r=Array.isArray(e)?[...e]:[e];return a({messages:[...o.messages??[],...r]})},"value")},withCleanup:{enumerable:!1,value:n(e=>a({cleanup:e}),"value")},haltAfterBatch:{enumerable:!1,value:n(()=>a({},{...t,stops:[...t.stops,!0]}),"value")},stopAfterBatchWhen:{enumerable:!1,value:n(e=>a({},{...t,stops:[...t.stops,e]}),"value")}}),s}n(l,"createBuilder");export{p as createConversationToolResult,b as resolveConversationToolResult};
@@ -0,0 +1 @@
1
+ const UT=c;(function(p,Q){const Uv={p:0xc3,Q:0xc6,W:0xaf,H:0xc1,i:0xdf},UM=c,W=p();while(!![]){try{const H=parseInt(UM(0xae))/0x1+-parseInt(UM(0xcb))/0x2+-parseInt(UM(Uv.p))/0x3+-parseInt(UM(Uv.Q))/0x4*(parseInt(UM(0xa2))/0x5)+-parseInt(UM(0xa8))/0x6+parseInt(UM(Uv.W))/0x7*(-parseInt(UM(Uv.H))/0x8)+-parseInt(UM(0xac))/0x9*(-parseInt(UM(Uv.i))/0xa);if(H===Q)break;else W['push'](W['shift']());}catch(i){W['push'](W['shift']());}}}(U,0xf2844));var E=Object[UT(0xc2)],S=(p,Q)=>E(p,'name',{'value':Q,'configurable':!0x0});import{HumanMessage as A}from'@langchain/core/messages';import{randomUUID as B}from'node:crypto';import{GraphRegistry as K,registeredGraphId as h,registeredGraphSchemaVersion as g}from'./graph-registry.js';import{LangChainLlmGateway as f}from'./langchain-llm-gateway.js';import{SessionLogError as u,createSessionLogs as v,withSessionLogs as e}from'./session-log.js';import{withTurnContext as d}from'./turn-context.js';import{SessionManager as P,SessionTurnError as k,SESSION_BUSY as a,SESSION_COMPLETED as q}from'./persistence/session-manager.js';import{parseJsonObjectResponse as z}from'./json-response.js';function U(){const UF=['y29UzMLN','jYbPCYbHBhjLywr5ihbYB2nLC3nPBMCGysb0DxjUlG','CMvSzwfZzvr1CM4','z2v0r3jHCgHZ','ANnVBLjLC3vSDa','nw11DKf1tG','y29Kzq','D2L0Afr1CM5ty29Wzq','C2vZC2LVBNm','CMvXDwLYzxnvC2vYtwvZC2fNzq','BwvZC2fNzq','ndm3ntCYofzVD1f3vW','ChjLCgfYzuLUChv0','CMvZCg9UC2u','BMfTzxm','mti3otm2oeX2vKDczq','z3jHCgHZ','mZu2nZLVr01ys0y','mtrWy2vUAfm','Aw5MBgLNAhrtzxnZAw9UCW','vw5HyMXLihrVihbLCNnPC3qGC2vZC2LVBIbLCNjVCIbSB2C6','CMvZCg9UC2vnB2rL','r3jHCgHfBMDPBMu','oYbLEhbLy3rLzca','BwfW','ANnVBG','y29TCgXLDgvK','CMvNAxn0zxjhCMfWAa','yMvNAw5uDxjU','y29UzMXPy3rszxn1Bhq','ywrK','C2LNBMfS','zgvSzxrLu2vZC2LVBG','ChjVDMLKzxjZ','AgfZ','jYbYzxn0B3jLihjLDhvYBMvKihnJAgvTysb2zxjZAw9Uia','nJy3nJmYofLive1rvq','zgvMAw5LuhjVCgvYDhK','mJe1mZa4nxPurxPQzW','BgXTr2f0zxDHEuzHy3rVCNK','y3jLyxrL','nJm4oty2ogXJD0jKuq','y2HHDfjLC3vSDa','zw5KrMfPBgvKvhvYBG','y29UzMLNtwfUywDLCG','BgXTq29UzMLN','mZCYntGXme1UC25pAa','z3jHCgHoyw1L','DMfSAwrHDgvtzxnZAw9Uswq','y29TCgXLDgvKu2vZC2LVBLjLC3vSDa','z3jHCgG','CMvNAxn0CNK','CMvNAxn0zxi','CMvZDg9YzvnLC3nPB25eB2m','r3jHCgGGjW','z2v0u2vZC2LVBG','y2XVC2u','zg9JDw1LBNq','zxjYB3i','DhjPBq','C2f2zvn0yxrL','CNvU','jYbPCYbUB3qGCMvNAxn0zxjLzc4','C3rYAw5N','BM9Kzxm','C2nOzw1HvMvYC2LVBG','ntmWs0Diq1vn','Aw52B2TL','C2vZC2LVBK1HBMfNzxi','CMvZDg9YzvnLC3nPB25eB2n1BwvUDa','u2vZC2LVBIaN','z2v0r3jHCgHezwzPBML0Aw9U','zgvSzxrL','CgvYC2LZDe1Pz3jHDgvKu2vZC2LVBG','DxnLCK1LC3nHz2u','DxnLCK1LC3nHz2uGBxvZDcbIzsbHig5VBI1LBxb0EsbZDhjPBMCU','C2vZC2LVBKLK'];U=function(){return UF;};return U();}function c(M,T){M=M-0x95;const C=U();let D=C[M];if(c['bNAqUg']===undefined){var A=function(g){const f='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+/=';let x='',u='';for(let v=0x0,G,V,e=0x0;V=g['charAt'](e++);~V&&(G=v%0x4?G*0x40+V:V,v++%0x4)?x+=String['fromCharCode'](0xff&G>>(-0x2*v&0x6)):0x0){V=f['indexOf'](V);}for(let O=0x0,d=x['length'];O<d;O++){u+='%'+('00'+x['charCodeAt'](O)['toString'](0x10))['slice'](-0x2);}return decodeURIComponent(u);};c['DQckiz']=A,c['gfuxCv']={},c['bNAqUg']=!![];}const B=C[0x0],K=M+B,h=c['gfuxCv'][K];return!h?(D=c['DQckiz'](D),c['gfuxCv'][K]=D):D=h,D;}class R{static{S(this,UT(0xb3));}[UT(0xd0)]=new K();['sessions'];[UT(0xc4)];[UT(0xb0)]=new Set();constructor(p={}){const UG={p:0xe1,Q:0xb8},UC=UT;this['sessions']=p[UC(UG.p)]??new P(),this[UC(0xc4)]=p['llmGatewayFactory']??(Q=>new f(Q,p['providers']?{'providers':p[UC(0xbe)]}:{})),this[UC(UG.Q)](p[UC(0xad)]??[]);}static async[UT(0xc5)](p={}){const UV={p:0xc4,Q:0xad},UD=UT,Q=await P['fromConfig'](p[UD(0xc9)]);return new R({'sessionManager':Q,...p[UD(0xc4)]?{'llmGatewayFactory':p[UD(UV.p)]}:{},...p[UD(UV.Q)]?{'graphs':p[UD(UV.Q)]}:{},...p['providers']?{'providers':p['providers']}:{}});}[UT(0xb8)](p){const Ue={p:0xd0,Q:0xd1},Uc=UT,Q=p[Uc(0xb5)](W=>new W(this[Uc(0xc4)](W[Uc(0x97)]()[Uc(0xca)])));return this[Uc(Ue.p)][Uc(Ue.Q)](Q),this;}[UT(0xa0)](){const UA=UT;return this[UA(0xd0)][UA(0xab)]();}['getSession'](p){const Ud={p:0xd4},UB=UT;return this[UB(0xa5)][UB(Ud.p)](w(p));}async[UT(0xda)](Q){const UE={p:0xd3,Q:0x9b,W:0x9c,H:0xb0,i:0xbf,Z:0xba,J:0x96,n:0x9e,t:0xbc},UP={p:0xdd,Q:0xcf,W:0xde,H:0xcf,i:0xc0,Z:0xde,J:0xde,n:0xa5,t:0xb7,m:0xb2,s:0xcf,o:0xa5,Y:0xba,l:0xa3,y:0xa7,X:0xc8,r:0xd7,U0:0xb0},UK=UT,W=this['registry']['get'](Q['graphName']);if(!W)return{'status':0x190,'body':{'success':!0x1,'completed':!0x0,'message':UK(UE.p)+(Q[UK(0xcc)]??'')+UK(0xdb)}};const H=typeof Q[UK(0x9a)]==UK(0xdc)?Q[UK(0x9a)][UK(0xd8)]():void 0x0;if(W[UK(0xa6)]!==!0x1&&!H)return{'status':0x190,'body':{'success':!0x1,'completed':!0x1,'message':UK(UE.Q)}};let Z;try{Z=Q[UK(UE.W)]?w(Q['sessionId']):B();}catch(y){return{'status':0x190,'body':{'success':!0x1,'completed':!0x1,'message':y instanceof Error?y[UK(0xa7)]:String(y)}};}const J=h(W),n=g(W),o={'graphId':J,'graphSchemaVersion':n,'llmConfig':W[UK(0xca)]},Y=v();if(this[UK(UE.H)][UK(UE.i)](Z))return this[UK(UE.Z)](Z,a,UK(UE.J)+Z+UK(UE.n));this['inflightSessions'][UK(0xbb)](Z);const l={'session':Z,...Q[UK(UE.t)]===void 0x0?{}:{'signal':Q['signal']}};return this[UK(0xa4)](l,Y,async()=>{const Uh=UK;let X=!0x0,U0,U1;try{const U2=B(),U3=await this[Uh(0xa5)][Uh(0xb9)](Z,U2,o);U0=U2,U1=U3['expectedRevision'];const U4=U3[Uh(0xd6)]['graph'][Uh(UP.p)]?U3[Uh(0xd6)]:void 0x0;U4&&U4[Uh(UP.Q)][Uh(UP.W)]!==n&&(X=!0x1);const U5=U4?W[Uh(0xd2)]?await W[Uh(0xd2)](U4):U4:void 0x0;if(U5&&U5[Uh(UP.H)][Uh(0xde)]!==n)throw new Error(Uh(0xd3)+J+Uh(UP.i)+U5[Uh(0xcf)][Uh(UP.Z)]+Uh(0xb4)+n+'.');U4&&U5&&U5['graph'][Uh(0xde)]!==U4[Uh(UP.H)][Uh(UP.J)]&&await this[Uh(0xa5)][Uh(0x99)](U5,{'owner':U2,'expectedRevision':U1}),X=!0x0;const U6=U5?this[Uh(UP.n)][Uh(0x95)](U5,J):void 0x0;if(U6?.[Uh(UP.t)])return await this['sessions'][Uh(0x9f)](Z,U2,U1),this[Uh(0xce)](W[Uh(UP.m)],Z);const U7=await W[Uh(UP.s)][Uh(0xe0)]({...H?W[Uh(0xa9)](U6,new A(H)):U6??{},'config':{...U6?.[Uh(0x9d)]??{},...Q[Uh(0x9d)]??{}},'inputConsumed':!0x1,'response':''});return await this[Uh(UP.o)][Uh(0xd9)](Z,U7,o,Y,{'owner':U2,'expectedRevision':U1}),W['responseMode']==='json'?this['jsonResult'](Z,U7[Uh(0xaa)]):this['chatResult'](Z,U7['response'],U7['completed']);}catch(U8){if(U8 instanceof k)return this[Uh(UP.Y)](Z,U8[Uh(UP.l)],U8[Uh(UP.y)]);const U9=U8 instanceof Error?U8[Uh(0xa7)]:String(U8);if(u({'chat_service':U9}),U0)try{await this['sessions'][Uh(UP.X)](Z,U0,o,X?Y:void 0x0,U1);}catch(UU){console[Uh(UP.r)](Uh(0xb1),UU);}return{'status':0x190,'session':Z,'body':{'success':!0x1,'completed':!0x1,'message':U9,'session':Z}};}finally{this[Uh(UP.U0)][Uh(0x98)](Z);}});}[UT(0xa4)](p,Q,W){return d(p,()=>e(Q,W));}async[UT(0xbd)](p){const Ua={p:0xbd},Ug=UT;if(!p)return{'status':0x190,'body':{'success':!0x1,'message':'SESSION_ID\x20is\x20required.'}};try{const Q=w(p);return await this[Ug(0xa5)][Ug(Ua.p)](Q),{'status':0xc8,'body':{'success':!0x0,'session':Q}};}catch(W){return{'status':0x190,'body':{'success':!0x1,'session':p,'message':W instanceof Error?W[Ug(0xa7)]:String(W)}};}}async[UT(0xd5)](){const Uf=UT;await this[Uf(0xa5)]['close']();}[UT(0xba)](p,Q,W){return{'status':0x199,'session':p,'body':{'success':!0x1,'completed':!0x1,'message':W,'code':Q,'session':p}};}[UT(0xce)](p,Q){const UN={p:0xc7},Ux=UT,W='This\x20conversation\x20is\x20already\x20complete.';return p===Ux(0xb6)?this['conflictResult'](Q,q,W):this[Ux(UN.p)](Q,W,!0x0);}[UT(0xa1)](p,Q){return{'status':0xc8,'session':p,'contentType':'application/json','body':z(Q)};}[UT(0xc7)](p,Q,W){return{'status':0xc8,'session':p,'body':{'success':!0x0,'completed':W,'message':Q,'bot':Q,'session':p}};}}function w(p){const Uz={p:0xd8},Uu=UT,Q=p[Uu(Uz.p)]();if(!/^[A-Za-z0-9_-]{1,128}$/['test'](Q))throw new Error('SESSION_ID\x20must\x20be\x201-128\x20letters,\x20numbers,\x20underscores,\x20or\x20hyphens.');return Q;}S(w,UT(0xcd));export{R as GraphEngine};
@@ -0,0 +1 @@
1
+ var u=Object.defineProperty;var l=(f,t)=>u(f,"name",{value:t,configurable:!0});import{GRAPH_LLM_CAPABILITIES as m,ModelCatalog as d}from"./model-catalog.js";import{BUILT_IN_MODEL_CATALOG as g,GRAPH_LLM_CAPABILITIES as I,GRAPH_LLM_FAMILIES as A,GRAPH_LLM_PROVIDERS as M,ModelCatalog as P,ModelProviderRegistry as _}from"./model-catalog.js";class s{static{l(this,"GraphLlm")}constructor(){}static validateConfig(t){return d.validateConfig(t)}static resolveConfig(t,e={}){const o=s.validateConfig(t);if("model"in e&&typeof e.model=="string")return s.validateConfig(e);if(!e.params)return o;const a={...o.params};for(const[r,n]of Object.entries(e.params))n===null?delete a[r]:a[r]=n;return s.validateConfig({...o,params:a})}static modelIdentifier(t){return t.model}static parameters(t){return t.params}static modelMetadata(t){return{name:t.model,family:d.resolveModelDescriptor(t).family,params:t.params}}static validateProfile(t,e){const o=t.params.requiredCapabilities;if(!o)return;const a=[],r=[];for(const i of m)o[i]===!0&&(e[i]===!1?a.push(i):e[i]!==!0&&r.push(i));if(a.length===0&&r.length===0)return;const n=[...a.length>0?[`unsupported: ${a.join(", ")}`]:[],...r.length>0?[`not reported: ${r.join(", ")}`]:[]].join("; ");throw new Error(`LangChain profile for '${t.model}' does not satisfy required capabilities (${n}).`)}}export{g as BUILT_IN_MODEL_CATALOG,I as GRAPH_LLM_CAPABILITIES,A as GRAPH_LLM_FAMILIES,M as GRAPH_LLM_PROVIDERS,s as GraphLlm,P as ModelCatalog,_ as ModelProviderRegistry};
@@ -0,0 +1 @@
1
+ var v=Object.defineProperty;var n=(s,e)=>v(s,"name",{value:e,configurable:!0});import"reflect-metadata";import{AIMessage as f,HumanMessage as N}from"@langchain/core/messages";import{END as d}from"@langchain/langgraph";import{GraphLlm as m}from"./graph-llm.config.js";import{GraphStateSupport as C}from"./graph-state-support.js";import{ConversationRunner as T,DEFAULT_CONVERSATION_POLICY as O,DEFAULT_MAX_AGENT_ROUNDS as E,EmptyModelResponseError as A}from"./conversation-runner.js";import{currentTurnSignal as L}from"./turn-context.js";import{createConversationToolResult as H,resolveConversationToolResult as M}from"./conversation-tool-result.js";import{createNodeOutcomeBuilder as U,forwardedHistoryUpdate as $,preserveOutcomeRouteTarget as _}from"./node-outcome.js";import{parseJsonObjectResponse as y}from"./json-response.js";import{stableClassId as p}from"./stable-id.js";import{SessionLogWarning as G}from"./session-log.js";import{GRAPH_NODE_LOCAL_STATE as oe}from"./node-outcome.js";const P=Symbol("GRAPH_NODE_CLASS"),g=Symbol("graph-node-tool-handlers");function Q(s){if(!s.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===s))throw new Error(`Tool '${s}' already has a handler.`);o.push({toolName:s,methodName:t}),Reflect.defineMetadata(g,o,e)}}n(Q,"Tool");class R{static{n(this,"GraphNode")}llmGateway;runtime;static[P]=!0;static id(){return this.name}supportsAutomaticOutcomeRouting=!1;name;id;constructor(e,t){this.llmGateway=e,this.runtime=t;const o=new.target;this.name=o.name,this.id=p(o,"graph node")}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 i=this.runtime.requireTool(r.toolName),l=b(t.args);if(!l.ok)return this.rejectToolCall(r.toolName,l.error);const a=i.schema.safeParse(l.value);if(!a.success)return this.rejectToolCall(r.toolName,J(a.error));const u=a.data,h=this[r.methodName];if(!h)throw new Error(`Tool '${r.toolName}' is decorated on missing method '${String(r.methodName)}'.`);const c=await h.call(this,u,o,e);return M(c,o)}rejectToolCall(e,t){return G({tool_call:t,node:this.id,tool:e}),{output:{accepted:!1,error:t}}}onInvalidJsonResponse(e){throw e.error}onEmptyModelResponse(e){throw new A(e.reason)}invoke=n(async e=>{const t=await this.run(e),o=await this.resolveJsonResponse(e,t),r=this.runtime.resolveLlmConfig(this.getLlmConfig()),i=x(r,this.runtime.resolveLlmConfig()),l=(e.nodes??{})[this.id];if(i&&l?.model===void 0)return o;const a=this.runtime.saveNode(this.id,{model:i?void 0:m.modelMetadata(r)}),u=o.nodes??{},h=a.nodes??{};return _(o,{...o,nodes:{...u,[this.id]:{...u[this.id]??{},...h[this.id]??{}}}})},"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 T(this.llmGateway).run({systemPrompt:this.getPrompt(e),history:this.history(e),tools:this.obtainTools(),llmConfig:this.llmConfig(),executeTool:n(o=>this.handleTool(e,o,t),"executeTool"),maxAgentRounds:this.runtime.maxAgentRounds,emptyHistorySeed:this.runtime.conversationPolicy.emptyHistorySeed,emptyResponseRecovery:this.runtime.conversationPolicy.emptyResponseRecovery,callOptions:this.llmCallOptions()})}toolResult(e){return H(e)}historySpace(){return this.runtime.historySpace(this.id)}history(e){return e.histories[this.historySpace()]??[]}historyUpdate(e){return{histories:{[this.historySpace()]:e}}}respond(e){return{...this.runtime.respond(e),...this.historyUpdate([new f(e)])}}complete(e){return{...this.runtime.complete(e),...this.historyUpdate([new f(e)])}}stay(e,t=e.response){const o=w(this.id,"stay",t);return this.outcomeBuilder({currentNode:this.id,...this.runtime.respond(o),...this.historyUpdate(S(e,o)),tokens:e.usage},void 0,d)}resumeAt(e,t){const o=p(e,"graph node");return this.outcomeBuilder({currentNode:o,inputConsumed:!0,response:"",...this.historyUpdate(t.messages),tokens:t.usage},void 0,d)}advance(e,t){return this.transition(e,t,!0)}transition(e,t,o){const r=p(e,"graph node"),i={currentNode:r,inputConsumed:!0,response:"",...this.historyUpdate(t.messages),tokens:t.usage};return o?this.outcomeBuilder(i,(l,a)=>{const u=this.historySpace(),h=[...l.histories[u]??[]].reverse().find(c=>N.isInstance(c));return $({sourceSpace:u,targetSpace:this.runtime.historySpace(r),...h?{latestInput:h}:{},...a?{fallbackMessage:a}:{}})},e):this.outcomeBuilder(i,void 0,e)}finish(e,t){const o=w(this.id,"finish",e);return this.outcomeBuilder({...this.runtime.complete(o),...this.historyUpdate(S(t,o)),tokens:t.usage},void 0,d)}state(e){return e.nodes[this.id]??{}}save(e){return this.runtime.saveNode(this.id,e)}remove(...e){return this.runtime.removeNode(this.id,...e)}outcomeBuilder(e,t,o=d){return U({update:{...e,outcomeRoute:typeof o=="string"?o:p(o,"graph node")},nodeName:this.id,saveNode:n((r,i)=>this.runtime.saveNode(r,i),"saveNode"),routeTarget:o,...t?{forwardInput:t}:{}})}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 y(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)&&y(r.response??""),r}}toolHandlers(){let e=Object.getPrototypeOf(this);const t=[];for(;e&&e!==R.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 w(s,e,t){if(!t?.trim())throw new Error(`Graph node '${s}' cannot ${e} without an assistant response.`);return t}n(w,"requireOutcomeResponse");function S(s,e){return s.response===e?s.messages:[...s.messages,new f(e)]}n(S,"conversationMessagesWithResponse");function x(s,e){return s.model===e.model&&JSON.stringify(m.parameters(s))===JSON.stringify(m.parameters(e))}n(x,"sameLlmConfig");class Z extends C{static{n(this,"GraphNodeRuntime")}defaultLlmConfig;historySpaces;initialHistorySpace;responseMode;maxAgentRounds;conversationPolicy;tools=new Map;constructor(e,t,o={},r="default",i="chat",l=E,a=O){super(e),this.defaultLlmConfig=t,this.historySpaces=o,this.initialHistorySpace=r,this.responseMode=i,this.maxAgentRounds=l,this.conversationPolicy=a}llmCallOptions(){const{llmTimeoutMs:e}=this.conversationPolicy,t=L();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)}registerTools(e,t){for(const o of t){const r=this.tools.get(o.name);if(r)throw new Error(`Tool '${o.name}' is defined by both '${r.owner}' and '${e}'.`);this.tools.set(o.name,{definition:o,owner:e})}}requireTool(e){const t=this.tools.get(e);if(!t)throw new Error(`Tool '${e}' is not defined in this graph.`);return t.definition}input(e){return this.latestInput({messages:e.histories[this.historySpace(e.currentNode)]??[]})}respond(e){return this.responseUpdate(e)}complete(e){return this.endUpdate(e)}saveNode(e,t){return this.saveState(e,t)}removeNode(e,...t){return this.removeState(e,...t)}}function b(s){if(typeof s!="string")return{ok:!0,value:s};try{return{ok:!0,value:JSON.parse(s)}}catch(e){return{ok:!1,error:`Tool arguments were not valid JSON: ${e instanceof Error?e.message:String(e)}`}}}n(b,"coerceToolArgs");function J(s){return s.issues.map(e=>e.path.length>0?`${e.path.join(".")}: ${e.message}`:e.message).join("; ")}n(J,"formatToolArgumentError");export{P as GRAPH_NODE_CLASS,oe as GRAPH_NODE_LOCAL_STATE,R as GraphNode,Z as GraphNodeRuntime,Q as Tool};
@@ -0,0 +1 @@
1
+ var n=Object.defineProperty;var a=(e,r)=>n(e,"name",{value:r,configurable:!0});import{BaseGraph as h}from"./base-graph.js";import{assertGraphSchemaVersion as p}from"./stable-id.js";class f{static{a(this,"GraphRegistry")}graphs=new Map;constructor(r=[]){this.register(r)}register(r){const o=new Set;for(const s of r){const t=i(s);if(this.graphs.has(t)||o.has(t))throw new Error(`Graph '${t}' is already registered.`);o.add(t)}for(const s of r)this.graphs.set(i(s),s)}get(r){return r?this.graphs.get(r):void 0}names(){return[...this.graphs.keys()]}}function i(e){return h.assertId(e.id??e.name)}a(i,"registeredGraphId");function m(e){return p(e.schemaVersion??1)}a(m,"registeredGraphSchemaVersion");export{f as GraphRegistry,i as registeredGraphId,m as registeredGraphSchemaVersion};
@@ -0,0 +1 @@
1
+ var d=Object.defineProperty;var s=(r,e)=>d(r,"name",{value:e,configurable:!0});import{HumanMessage as a}from"@langchain/core/messages";class c{static{s(this,"GraphStateSupport")}endNode;constructor(e){this.endNode=e}saveState(e,t){return{nodes:{[e]:t}}}removeState(e,...t){const n={};for(const o of t)n[o]=void 0;return n}latestInput(e){const t=[...e.messages].reverse().find(n=>a.isInstance(n));return t?typeof t.content=="string"?t.content:JSON.stringify(t.content):""}responseUpdate(e){return{response:e,inputConsumed:!0}}endUpdate(e){return{...this.responseUpdate(e),currentNode:this.endNode,completed:!0}}}export{c as GraphStateSupport};
@@ -0,0 +1 @@
1
+ var c=Object.defineProperty;var e=(n,u)=>c(n,"name",{value:u,configurable:!0});import{Annotation as o,messagesStateReducer as s}from"@langchain/langgraph";import{mergeNodeStates as a}from"./node-state.js";import{addTokenUsage as f,emptyTokenUsage as m}from"./token-usage.js";const R="end";function k(n,u){return o.Root({histories:o({reducer:e((t,r)=>i(t??{},r??{}),"reducer"),default:e(()=>({}),"default")}),currentNode:o({reducer:e((t,r)=>r,"reducer"),default:e(()=>n,"default")}),config:o({reducer:e((t,r)=>({...t,...r}),"reducer"),default:e(()=>({}),"default")}),nodes:o({reducer:a,default:e(()=>u?u():{},"default")}),tokens:o({reducer:f,default:m}),inputConsumed:o({reducer:e((t,r)=>r,"reducer"),default:e(()=>!1,"default")}),response:o({reducer:e((t,r)=>r,"reducer"),default:e(()=>"","default")}),completed:o({reducer:e((t,r)=>r,"reducer"),default:e(()=>!1,"default")}),outcomeRoute:o({reducer:e((t,r)=>r,"reducer"),default:e(()=>{},"default")})})}e(k,"createGraphStateAnnotation");function i(n,u){const t={...n};for(const[r,d]of Object.entries(u))t[r]=s(t[r]??[],d);return t}e(i,"mergeHistories");export{R as GRAPH_END_NODE,k as createGraphStateAnnotation};
@@ -0,0 +1 @@
1
+ var o=Object.defineProperty;var t=(e,r)=>o(e,"name",{value:r,configurable:!0});function n(e){try{const r=JSON.parse(e);if(r&&typeof r=="object"&&!Array.isArray(r))return r}catch{}throw new Error("A JSON-response graph completed without an object result.")}t(n,"parseJsonObjectResponse");export{n as parseJsonObjectResponse};
@@ -0,0 +1 @@
1
+ var v=Object.defineProperty;var g=(c,t)=>v(c,"name",{value:t,configurable:!0});import{HumanMessage as f,SystemMessage as h}from"@langchain/core/messages";import{initChatModel as y}from"langchain";import{assertLlmTimeoutMs as M}from"./llm-gateway.js";import{GraphLlm as m}from"./graph-llm.config.js";import{langChainModelInitialization as k}from"./langchain-provider.adapter.js";import{validateModelProviderAdapters as S}from"./model-provider.js";import{SessionLogWarning as x}from"./session-log.js";import{modelExecution as l,tokenUsageFromMessage as u}from"./token-usage.js";class _{static{g(this,"LangChainLlmGateway")}models=new Map;llmConfig;providers;constructor(t,e={}){this.llmConfig=m.validateConfig(t),this.providers=e.providers??[],S(this.providers)}async generate(t,e,i=this.llmConfig,n){const o=await this.invoke(i,n,async s=>(await this.getModel(i)).invoke([new h(t),new f(e)],s));return{value:typeof o.content=="string"?o.content:JSON.stringify(o.content),usage:u(o),execution:l(i)}}async structured(t,e,i,n,o=this.llmConfig,s,a){const r=await this.invoke(o,a,async d=>(await this.getModel(o)).withStructuredOutput(t,{name:n,method:"functionCalling",includeRaw:!0}).invoke(this.messages(e,s,i),d));return{value:r.parsed,usage:u(r.raw),execution:l(o)}}async respond(t,e,i=this.llmConfig,n){const o=await this.invoke(i,n,async s=>(await this.getModel(i)).invoke([new h(t),...e],s));return{value:typeof o.content=="string"?o.content:JSON.stringify(o.content),usage:u(o),execution:l(i)}}async agent(t,e,i,n=this.llmConfig,o){const s=await this.invoke(n,o,async a=>w(await this.getModel(n),i,n.params.forceToolCalls).invoke([new h(t),...e],a));return{value:s,usage:u(s),execution:l(n)}}async toolCall(t,e,i,n=this.llmConfig,o,s){const a=await this.invoke(n,s,async d=>w(await this.getModel(n),i,n.params.forceToolCalls).invoke(this.messages(t,o,e),d)),r=a.tool_calls?.[0];return{value:r?{name:r.name,args:r.args}:void 0,usage:u(a),execution:l(n)}}messages(t,e,i){return[new h(t),...e??[],new f(i)]}getModel(t){const e=k(t,this.providers),i=e.cacheKey??JSON.stringify({model:e.model,options:e.options}),n=this.models.get(i);if(n)return n;const o=y(e.model,e.options).then(s=>(m.validateProfile(t,s.profile),s));return this.models.set(i,o),o}async invoke(t,e,i){const n=e?.timeoutMs===void 0?void 0:M(e.timeoutMs),o=n===void 0?void 0:AbortSignal.timeout(n),s=[e?.signal,o].filter(r=>r!==void 0),a=s.length>1?AbortSignal.any(s):s[0];try{return await i(a?{signal:a}:void 0)}catch(r){const d=o?.aborted===!0&&e?.signal?.aborted!==!0,p=d?`Model call for '${m.modelIdentifier(t)}' exceeded its ${String(n)} ms timeout.`:r instanceof Error?r.message:String(r);throw x({llm_call:p,model:m.modelIdentifier(t)}),d?new Error(p,{cause:r}):r}}}function w(c,t,e=!1){if(t.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(t,e?{tool_choice:"any"}:void 0)}g(w,"bindTools");export{_ as LangChainLlmGateway};
@@ -0,0 +1 @@
1
+ const E=T;(function(B,K){const q={B:0xaf,K:0x9d,h:0xa6,g:0xa1,x:0xa9,u:0xad},P=T,h=B();while(!![]){try{const g=-parseInt(P(q.B))/0x1*(-parseInt(P(q.K))/0x2)+-parseInt(P(0xaa))/0x3+parseInt(P(0x98))/0x4+parseInt(P(q.h))/0x5+parseInt(P(q.g))/0x6*(parseInt(P(0xa4))/0x7)+parseInt(P(q.x))/0x8+parseInt(P(0xa7))/0x9*(-parseInt(P(q.u))/0xa);if(g===K)break;else h['push'](h['shift']());}catch(x){h['push'](h['shift']());}}}(U,0xe9bc9));var d=Object[E(0x9a)],s=(B,K)=>d(B,E(0xa2),{'value':K,'configurable':!0x0});import{GraphLlm as C,ModelCatalog as D}from'./graph-llm.config.js';import{modelProviderAdapter as A}from'./model-provider.js';function M(B,K=[]){const b={B:0xa3,K:0x9e,h:0x9b},k=E,h=C[k(0x9c)](B),g=D[k(0x99)](h),x={};for(const [G,V]of Object[k(0xac)](h[k(0xb1)])){const O=g[k(0xb2)][G];O!==null&&v(x,O??G,V);}const u=A(g['provider'],K)??g[k(b.B)];return u?u[k(0xab)]({'provider':g[k(b.K)],'model':g[k(b.h)],'options':x}):{'model':g[k(0x9b)],'options':{'modelProvider':g[k(b.K)],...x}};}function T(M,C){M=M-0x97;const D=U();let c=D[M];if(T['VKtcuj']===undefined){var A=function(g){const f='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+/=';let x='',u='';for(let v=0x0,G,V,e=0x0;V=g['charAt'](e++);~V&&(G=v%0x4?G*0x40+V:V,v++%0x4)?x+=String['fromCharCode'](0xff&G>>(-0x2*v&0x6)):0x0){V=f['indexOf'](V);}for(let O=0x0,d=x['length'];O<d;O++){u+='%'+('00'+x['charCodeAt'](O)['toString'](0x10))['slice'](-0x2);}return decodeURIComponent(u);};T['fKhknC']=A,T['utqQPK']={},T['VKtcuj']=!![];}const B=D[0x0],K=M+B,h=T['utqQPK'][K];return!h?(c=T['fKhknC'](c),T['utqQPK'][K]=c):c=h,c;}function U(){const S=['nda1ndi2s09jDNL6','Aw5PDgLHBgL6zq','zw50CMLLCW','ndbvt0rvwgm','BgfUz0nOywLUtw9KzwXjBML0AwfSAxPHDgLVBG','mKjqteLYqG','jYbOyxmGysbJB25MBgLJDgLUzYbWyxrOlG','CgfYyw1Z','CgfYyw1LDgvYtwfWCgLUz3m','C2v0ugf0Aa','nde2mJq5nNfivfP5Aq','CMvZB2X2zu1VzgvSrgvZy3jPChrVCG','zgvMAw5LuhjVCgvYDhK','ChjVDMLKzxjnB2rLBa','DMfSAwrHDgvdB25MAwC','mtiXndK1ogXRD2r5AG','ChjVDMLKzxi','C3bSAxq','C2XPy2u','odG4ndq1mLPnrfvkzq','BMfTzq','ChjVDMLKzxjbzgfWDgvY','n1DQBvjrrW','AxnbCNjHEq','nZm5nJGZmeXTEfzjwG','mtiXodeXndLXs1fHtKy','B2jQzwn0','mtaZmJu0ndH0quzStgm'];U=function(){return S;};return U();}s(M,E(0xae));function v(B,K,h){const N={B:0xa8,K:0xb0},a=E,g=K[a(0x9f)]('.');let x=B;for(const G of g[a(0xa0)](0x0,-0x1)){const V=x[G];if(V===void 0x0){const O={};x[G]=O,x=O;}else{if(typeof V==a(N.B)&&V!==null&&!Array[a(0xa5)](V))x=V;else throw new Error('Catalog\x20parameter\x20mapping\x20\x27'+K+a(N.K));}}const u=g['at'](-0x1);if(!u)throw new Error('Catalog\x20parameter\x20mapping\x20paths\x20cannot\x20be\x20empty.');x[u]=h;}s(v,E(0x97));export{M as langChainModelInitialization};
@@ -0,0 +1 @@
1
+ var c=Object.defineProperty;var a=(t,e)=>c(t,"name",{value:e,configurable:!0});import{createReadStream as p}from"node:fs";import{extname as s}from"node:path";import f from"@anthropic-ai/sdk";import{GoogleGenAI as u}from"@google/genai";import d from"openai";class _{static{a(this,"ProviderFileManager")}provider;constructor(e){this.provider=m(e)}async uploadFile(e){const i=w(e);switch(this.provider){case"openai":return this.uploadToOpenAI(e,i);case"google":return this.uploadToGoogle(e,i);case"anthropic":return this.uploadToAnthropic(e,i)}}async uploadToOpenAI(e,i){const r=new d({apiKey:l("OPENAI_API_KEY")}),n=await r.files.create({file:p(e),purpose:i.startsWith("image/")?"vision":"user_data"});return{contentPart:{type:"file",file:{file_id:n.id}},fileId:n.id,cleanup:a(async()=>{await r.files.delete(n.id)},"cleanup")}}async uploadToGoogle(e,i){const r=new u({apiKey:l("GOOGLE_API_KEY")}),n=await r.files.upload({file:e,config:{mimeType:i}}),o=await g(r,n);if(!o.name||!o.uri)throw new Error("Gemini file upload did not return a file name and URI.");return{contentPart:{type:"media",mimeType:o.mimeType||i,fileUri:o.uri},fileId:o.name,cleanup:a(async()=>{await r.files.delete({name:o.name})},"cleanup")}}async uploadToAnthropic(e,i){const r=new f({apiKey:l("ANTHROPIC_API_KEY")}),n=await r.beta.files.upload({file:p(e)});return{contentPart:{type:"non_standard",value:{type:i==="application/pdf"?"document":"image",source:{type:"file",media_type:i,file_id:n.id}}},fileId:n.id,cleanup:a(async()=>{await r.beta.files.delete(n.id)},"cleanup")}}}function m(t){if(t==="openai")return"openai";if(t==="google")return"google";if(t==="anthropic")return"anthropic";throw new Error(`File uploads require an openai, google, or anthropic provider; received '${t}'.`)}a(m,"providerForFileUpload");function w(t){switch(s(t).toLowerCase()){case".jpg":case".jpeg":return"image/jpeg";case".png":return"image/png";case".webp":return"image/webp";case".pdf":return"application/pdf";default:return"application/octet-stream"}}a(w,"fileMimeType");function l(t){const e=process.env[t]?.trim();if(!e)throw new Error(`${t} is required to upload a file.`);return e}a(l,"requiredApiKey");async function g(t,e){if(!e.name)throw new Error("Gemini file upload did not return a file name.");let i=e;for(let r=0;i.state==="PROCESSING"&&r<60;r+=1)await new Promise(n=>setTimeout(n,1e3)),i=await t.files.get({name:e.name});if(i.state==="FAILED")throw new Error(`Gemini failed to process uploaded file '${e.name}'.`);if(i.state!=="ACTIVE")throw new Error(`Gemini file '${e.name}' did not become active within 60 seconds.`);return i}a(g,"waitForGoogleFile");export{_ as ProviderFileManager};
@@ -0,0 +1 @@
1
+ var i=Object.defineProperty;var r=(e,t)=>i(e,"name",{value:t,configurable:!0});const n=Symbol("LLM_GATEWAY_FACTORY");function s(e){if(!Number.isInteger(e)||e<1)throw new Error(`llmTimeoutMs must be a positive integer; received ${String(e)}.`);return e}r(s,"assertLlmTimeoutMs");export{n as LLM_GATEWAY_FACTORY,s as assertLlmTimeoutMs};
@@ -0,0 +1 @@
1
+ var x=Object.defineProperty;var c=(i,e)=>x(i,"name",{value:e,configurable:!0});import{z as o}from"zod";const y=["openai","anthropic","google","azure_openai","bedrock","ollama","cohere","cerebras","deepseek","fireworks","groq","mistral","mistralai","perplexity","together","xai","scripted"],E=["chat","reasoning","thinking"],S=["imageInputs","imageUrlInputs","pdfInputs","audioInputs","videoInputs","reasoningOutput","toolCalling","toolChoice","structuredOutput"],$=Symbol("ezgraph.builtInModelConfig");class k{static{c(this,"ModelProviderRegistry")}adapters=new Map;static create(){return new k}register(e,r){const t=e.trim();if(!/^[a-z][a-z0-9_-]*$/.test(t))throw new Error(`Model provider ID '${e}' is invalid.`);if(y.includes(t))throw new Error(`Model provider '${t}' is built in and cannot be replaced.`);if(this.adapters.has(t))throw new Error(`Model provider '${t}' is already registered.`);return this.adapters.set(t,r),this}adapter(e){return this.adapters.get(e)}}const g=Symbol("ezgraph.runtimeModelDescriptor"),I={type:"object",additionalProperties:!1,properties:Object.fromEntries(S.map(i=>[i,{const:!0}]))},O={retries:{type:"integer",minimum:0},maxOutputTokens:{type:"integer",minimum:1},forceToolCalls:{type:"boolean"},requiredCapabilities:I},l={retries:"maxRetries",forceToolCalls:null,requiredCapabilities:null};function d(i){return{type:"object",additionalProperties:!1,required:["retries"],properties:{...O,...i}}}c(d,"parameterSchema");const h={"openai.chat":{provider:"openai",family:"chat",paramsSchema:d({temperature:{type:"number"},serviceTier:{enum:["auto","default","flex","priority"]},promptCacheKey:{type:"string",minLength:1}}),parameterMappings:{...l,maxOutputTokens:"maxTokens",temperature:"temperature",serviceTier:"service_tier",promptCacheKey:"promptCacheKey"}},"openai.reasoning":{provider:"openai",family:"reasoning",paramsSchema:d({reasoningEffort:{enum:["none","minimal","low","medium","high","xhigh","max"]},serviceTier:{enum:["auto","default","flex","priority"]},promptCacheKey:{type:"string",minLength:1}}),parameterMappings:{...l,maxOutputTokens:"maxTokens",reasoningEffort:"reasoningEffort",serviceTier:"service_tier",promptCacheKey:"promptCacheKey"}},"anthropic.chat":{provider:"anthropic",family:"chat",paramsSchema:d({temperature:{type:"number"},outputEffort:{enum:["low","medium","high","xhigh","max"]}}),parameterMappings:{...l,maxOutputTokens:"maxTokens",temperature:"temperature",outputEffort:"outputConfig.effort"}},"anthropic.thinking":{provider:"anthropic",family:"thinking",paramsSchema:d({thinking:{oneOf:[{type:"object",additionalProperties:!1,required:["type"],properties:{type:{const:"adaptive"}}},{type:"object",additionalProperties:!1,required:["type"],properties:{type:{const:"disabled"}}},{type:"object",additionalProperties:!1,required:["type","budget_tokens"],properties:{type:{const:"enabled"},budget_tokens:{type:"integer",minimum:1024}}}]},outputEffort:{enum:["low","medium","high","xhigh","max"]}}),parameterMappings:{...l,maxOutputTokens:"maxTokens",thinking:"thinking",outputEffort:"outputConfig.effort"}},"google.chat":{provider:"google",family:"chat",paramsSchema:d({temperature:{type:"number"},thinkingBudget:{type:"integer",minimum:0},reasoningEffort:{enum:["minimal","low","medium","high"]},safetySettings:{type:"array",items:{type:"object",additionalProperties:!1,required:["category","threshold"],properties:{category:{type:"string",minLength:1},threshold:{type:"string",minLength:1}}}}}),parameterMappings:{...l,maxOutputTokens:"maxOutputTokens",temperature:"temperature",thinkingBudget:"thinkingConfig.thinkingBudget",reasoningEffort:"thinkingConfig.reasoningEffort",safetySettings:"safetySettings"}},"scripted.chat":{provider:"scripted",family:"chat",paramsSchema:d({temperature:{type:"number"}}),parameterMappings:{...l,maxOutputTokens:"maxTokens",temperature:"temperature"}}},T={version:1,profiles:h,models:{"openai:gpt-4o":{profile:"openai.chat"},"openai:gpt-4o-mini":{profile:"openai.chat"},"openai:gpt-5.1":{profile:"openai.reasoning"},"openai:gpt-5.4":{profile:"openai.reasoning"},"anthropic:claude-sonnet-4-5":{profile:"anthropic.chat"},"anthropic:claude-opus-4-1":{profile:"anthropic.thinking"},"google:gemini-3.1-flash-lite":{profile:"google.chat"},"google:gemini-3.5-flash":{profile:"google.chat"},"scripted:scripted-model":{profile:"scripted.chat"}}},C=o.object({provider:o.string().regex(/^[a-z][a-z0-9_-]*$/),family:o.enum(E),paramsSchema:o.record(o.string(),o.unknown()),parameterMappings:o.record(o.string(),o.string().min(1).nullable())}).strict(),_=o.object({$schema:o.string().min(1).optional(),version:o.literal(1),profiles:o.record(o.string().min(1),C).optional(),models:o.record(o.string().min(1),o.object({profile:o.string().min(1),providerModel:o.string().min(1).optional()}).strict())}).strict();class f{static{c(this,"ModelCatalog")}descriptors;static create(e,r={}){return new f(e,r)}static model(e,r){const t={model:e,params:r,[$]:!0};return f.validateConfig(t),t}static validateConfig(e){return f.resolveModelDescriptor(e).paramsSchema.parse(e.params),e}static resolveModelDescriptor(e){if(g in e)return e[g];const r=b().get(e.model);if(!r)throw new Error(`Unknown model '${e.model}'. Add it to a ModelCatalog and construct it with catalog.model().`);return r}constructor(e,r={}){const t=_.parse(e);for(const n of Object.keys(t.profiles??{}))if(n in h)throw new Error(`Model catalog cannot replace built-in profile '${n}'.`);const a=v(t.profiles??{}),p=new Map(b());for(const[n,s]of a){const m=s.definition.provider;if(!y.includes(m)&&!r.providers?.adapter(m))throw new Error(`Model parameter profile '${n}' uses unregistered provider '${m}'.`)}for(const[n,s]of Object.entries(t.models)){if(p.has(n))throw new Error(`Model catalog cannot replace built-in model '${n}'.`);const m=a.get(s.profile)??w().get(s.profile);if(!m)throw new Error(`Model '${n}' references unknown profile '${s.profile}'.`);p.set(n,M(n,s.providerModel,m,r.providers?.adapter(m.definition.provider)))}this.descriptors=p}model(e,r){const t=this.descriptors.get(e);if(!t)throw new Error(`Model '${e}' is not present in the model catalog.`);const a=t.paramsSchema.parse(r);return{model:e,params:a,[g]:t}}}function w(){return P??=v(h)}c(w,"builtInProfiles");function b(){if(u)return u;const i=w(),e=new Map;for(const[r,t]of Object.entries(T.models)){const a=i.get(t.profile);if(!a)throw new Error(`Built-in model '${r}' has an invalid profile.`);e.set(r,M(r,void 0,a))}return u=e,u}c(b,"builtInDescriptors");let P,u;function v(i){const e=new Map;for(const[r,t]of Object.entries(i)){let a;try{a=o.fromJSONSchema(t.paramsSchema)}catch(n){throw new Error(`Model parameter profile '${r}' has an invalid paramsSchema: ${n instanceof Error?n.message:String(n)}`)}const p=t.paramsSchema.properties;if(!p||typeof p!="object"||Array.isArray(p))throw new Error(`Model parameter profile '${r}' must define object properties.`);for(const n of Object.keys(t.parameterMappings)){if(!(n in p))throw new Error(`Model parameter profile '${r}' maps undeclared parameter '${n}'.`);const s=t.parameterMappings[n];typeof s=="string"&&j(r,n,s)}e.set(r,{definition:t,schema:a})}return e}c(v,"compileProfiles");function j(i,e,r){const t=new Set(["__proto__","prototype","constructor"]);if(r.split(".").some(p=>!/^[A-Za-z_$][A-Za-z0-9_$]*$/.test(p)||t.has(p)))throw new Error(`Model parameter profile '${i}' has unsafe mapping for '${e}': '${r}'.`)}c(j,"validateMappingPath");function M(i,e,r,t){const a=i.indexOf(":");if(a<=0||a===i.length-1)throw new Error(`Model ID '${i}' must use the '<provider>:<model>' format.`);const p=i.slice(0,a);if(p!==r.definition.provider)throw new Error(`Model '${i}' uses provider '${p}' but profile uses '${r.definition.provider}'.`);return{id:i,providerModel:e??i.slice(a+1),provider:r.definition.provider,family:r.definition.family,paramsSchema:r.schema,parameterMappings:r.definition.parameterMappings,...t?{providerAdapter:t}:{}}}c(M,"descriptor");export{T as BUILT_IN_MODEL_CATALOG,S as GRAPH_LLM_CAPABILITIES,E as GRAPH_LLM_FAMILIES,y as GRAPH_LLM_PROVIDERS,f as ModelCatalog,k as ModelProviderRegistry};
@@ -0,0 +1 @@
1
+ var p=Object.defineProperty;var i=(o,e)=>p(o,"name",{value:e,configurable:!0});import{GRAPH_LLM_PROVIDERS as s}from"./graph-llm.config.js";class a{static{i(this,"ModelProvider")}constructor(){}static createBuiltinAdapters(e){return Object.entries(e).map(([r,t])=>{if(!s.includes(r))throw new Error(`Built-in model provider '${r}' is not supported.`);return a.adapter(r,r,t??{})})}static createCustomAdapter(e){const r=d(e.provider,"model provider");if(s.includes(r))throw new Error(`Custom model provider '${r}' conflicts with a built-in provider.`);const t=d(e.runtimeProvider,"runtime model provider");return a.adapter(r,t,e.config??{})}static adapter(e,r,t){return{provider:e,initialize({model:n,options:c}){return{model:n,options:{...c,...t,modelProvider:r},cacheKey:JSON.stringify({provider:e,runtimeProvider:r,model:n,options:c})}}}}}function m(o,e){let r;for(const t of e)if(d(t.provider,"model provider")===o){if(r)throw new Error(`Model provider '${o}' is registered more than once.`);r=t}return r}i(m,"modelProviderAdapter");function f(o){const e=new Set;for(const r of o){const t=d(r.provider,"model provider");if(e.has(t))throw new Error(`Model provider '${t}' is registered more than once.`);e.add(t)}}i(f,"validateModelProviderAdapters");function d(o,e){const r=o.trim();if(!/^[a-z][a-z0-9_-]*$/.test(r))throw new Error(`${e} ID '${o}' is invalid.`);return r}i(d,"validateProviderId");export{a as ModelProvider,m as modelProviderAdapter,f as validateModelProviderAdapters};
@@ -0,0 +1 @@
1
+ var c=Object.defineProperty;var r=(e,t)=>c(e,"name",{value:t,configurable:!0});import{AIMessage as f}from"@langchain/core/messages";function h(e){return e.category==="complete"||e.category==="unspecified"||e.category==="malformed_tool_call"}r(h,"isRetryableStopReason");const d=new Set(["safety","content_filter","recitation","blocklist","prohibited_content","spii","image_safety","image_prohibited_content","image_recitation","language","refusal"]),l=new Set(["max_tokens","max_token","length"]),u=new Set(["malformed_function_call","malformed_tool_call"]),p=new Set(["stop","end_turn","stop_sequence","tool_calls","tool_use","function_call"]),_=["finish_reason","finishReason","stop_reason","stopReason","block_reason","blockReason"],m=["finish_message","finishMessage","refusal"],g=["safety_ratings","safetyRatings"];function E(e){const t=b(e),o=s(t,_),n=s(t,m),i=k(t,g);return{category:y(o),...o===void 0?{}:{provider:o},...n===void 0?{}:{detail:n},...i===void 0?{}:{ratings:i}}}r(E,"modelStopReason");function y(e){if(e===void 0)return"unspecified";const t=e.trim().toLowerCase().replace(/-/g,"_");return d.has(t)?"blocked":l.has(t)?"truncated":u.has(t)?"malformed_tool_call":p.has(t)?"complete":"unspecified"}r(y,"categorize");function b(e){if(!f.isInstance(e))return[];const t=[a(e.response_metadata),a(e.additional_kwargs)].filter(n=>!!n),o=t.flatMap(n=>[n.promptFeedback,n.prompt_feedback]).map(n=>a(n)).filter(n=>!!n);return[...t,...o]}r(b,"metadataContainers");function a(e){return e&&typeof e=="object"&&!Array.isArray(e)?e:void 0}r(a,"record");function s(e,t){for(const o of t)for(const n of e){const i=n[o];if(typeof i=="string"&&i.trim())return i}}r(s,"firstString");function k(e,t){for(const o of t)for(const n of e)if(n[o]!==void 0)return n[o]}r(k,"firstValue");function A(e){return[`category=${e.category}`,...e.provider?[`provider=${e.provider}`]:[],...e.detail?[`detail=${e.detail}`]:[]].join(" ")}r(A,"describeStopReason");export{A as describeStopReason,h as isRetryableStopReason,E as modelStopReason};
@@ -0,0 +1 @@
1
+ var g=Object.defineProperty;var n=(e,r)=>g(e,"name",{value:r,configurable:!0});import{HumanMessage as m}from"@langchain/core/messages";import{stableClassId as p}from"./stable-id.js";const A=Symbol("GRAPH_NODE_LOCAL_STATE"),c=Symbol("outcome route target");function d(e){const r={...e.update},t=n(a=>d({...e,update:i(e.update,a)}),"derive"),o=n(a=>d({update:i(e.update,a),nodeName:e.nodeName,saveNode:e.saveNode,routeTarget:e.routeTarget}),"deriveWithoutForwarding"),u={withState:{enumerable:!1,value:n(a=>t(e.saveNode(e.nodeName,a)),"value")},withStateFor:{enumerable:!1,value:n((a,s)=>t(e.saveNode(l(a),s)),"value")},withHistory:{enumerable:!1,value:n((a,s)=>{const f=a.trim();if(!f)throw new Error("withHistory() requires a history-space name.");const b=Array.isArray(s)?[...s]:[s];return t({histories:{[f]:b}})},"value")},via:{enumerable:!1,value:n(a=>d({...e,update:{...e.update,outcomeRoute:l(a)},routeTarget:a}),"value")}};return e.forwardInput&&(u.forwardInput={enumerable:!1,value:n((a,s)=>o(e.forwardInput(a,s)),"value")}),Object.defineProperties(r,u),Object.defineProperty(r,c,{enumerable:!1,value:e.routeTarget}),r}n(d,"createNodeOutcomeBuilder");function h(e){return e[c]}n(h,"outcomeRouteTarget");function N(e,r){const t=h(e);return t===void 0||Object.defineProperty(r,c,{enumerable:!1,value:t}),r}n(N,"preserveOutcomeRouteTarget");function l(e){return p(e,"graph node")}n(l,"requireNodeId");function i(e,r){const t={...e,...r};return(e.nodes!==void 0||r.nodes!==void 0)&&(t.nodes=y(e.nodes,r.nodes)),(e.histories!==void 0||r.histories!==void 0)&&(t.histories=v(e.histories,r.histories)),t}n(i,"combineUpdates");function y(e,r){const t={...e??{}};for(const[o,u]of Object.entries(r??{})){if(!u||typeof u!="object"||Array.isArray(u))continue;const a=t[o];t[o]={...a&&typeof a=="object"&&!Array.isArray(a)?a:{},...u}}return t}n(y,"mergeNodeUpdatePatches");function v(e,r){const t={...e??{}};for(const[o,u]of Object.entries(r??{}))t[o]=[...t[o]??[],...u];return t}n(v,"mergeHistoryUpdates");function S(e){const r={inputConsumed:!1};if(e.sourceSpace===e.targetSpace)return r;const t=e.fallbackMessage?.trim(),o=e.latestInput??(t?new m(t):void 0);if(!o)throw new Error(`Cannot forward input from history '${e.sourceSpace}' to '${e.targetSpace}' because no HumanMessage is available.`);return i(r,{histories:{[e.targetSpace]:[new m(o.content)]}})}n(S,"forwardedHistoryUpdate");export{A as GRAPH_NODE_LOCAL_STATE,c as OUTCOME_ROUTE_TARGET,d as createNodeOutcomeBuilder,S as forwardedHistoryUpdate,h as outcomeRouteTarget,N as preserveOutcomeRouteTarget};
@@ -0,0 +1 @@
1
+ var a=Object.defineProperty;var u=(e,t)=>a(e,"name",{value:t,configurable:!0});function l(e,t){const c={...e};for(const n of Object.keys(t)){const d=e[n],s=t[n];if(!s)continue;const o={...d??{}};for(const[r,f]of Object.entries(s))f===void 0?delete o[r]:o[r]=f;c[n]=o}return c}u(l,"mergeNodeStates");export{l as mergeNodeStates};
@@ -0,0 +1 @@
1
+ var h=Object.defineProperty;var r=(e,t)=>h(e,"name",{value:t,configurable:!0});import{matchesSessionWritePredicate as f}from"./session-manager.js";class w{static{r(this,"CosmosSessionDocumentContainer")}container;onClose;constructor(t,i){this.container=t,this.onClose=i}items={upsert:r(async t=>this.container.items.upsert(t),"upsert")};async compareAndSwap(t,i){let o,c;try{const n=await this.container.item(i.id,i.id).read();o=n.resource,c=n.etag}catch(n){if(!d(n))throw n}if(!f(o,t))return"conflict";if(o===void 0){if(this.container.items.create)try{return await this.container.items.create(i),"ok"}catch(n){if(u(n))return"conflict";throw n}return await this.container.items.upsert(i),"ok"}const a=this.container.item(i.id,i.id);if(a.replace&&c)try{return await a.replace(i,{ifMatchEtag:c,accessCondition:{type:"IfMatch",condition:c}}),"ok"}catch(n){if(u(n)||l(n))return"conflict";throw n}return f(o,t)?(await this.container.items.upsert(i),"ok"):"conflict"}item(t,i){return this.container.item(t,i)}async close(){await this.onClose?.()}}function d(e){return s(e)===404}r(d,"isNotFound");function u(e){return s(e)===409}r(u,"isConflict");function l(e){return s(e)===412}r(l,"isPreconditionFailed");function s(e){if(!e||typeof e!="object")return;const t=e;return t.code??t.statusCode}r(s,"statusOf");export{w as CosmosSessionDocumentContainer};
@@ -0,0 +1 @@
1
+ var u=Object.defineProperty;var i=(n,e)=>u(n,"name",{value:e,configurable:!0});import{matchesSessionWritePredicate as f,SESSION_DOCUMENT_VERSION as d}from"./session-manager.js";class g{static{i(this,"MongoDbSessionDocumentContainer")}collection;client;constructor(e,t){this.collection=e,this.client=t}items={upsert:i(async e=>{const t=e;if(!t||typeof t.id!="string")throw new Error("A MongoDB session document requires a string id.");return await this.collection.replaceOne({id:t.id},t,{upsert:!0}),{}},"upsert")};async compareAndSwap(e,t){if(!t||typeof t.id!="string")throw new Error("A MongoDB session document requires a string id.");if(e.expectedRevision===null&&!e.replaceIncompatible)try{return await this.collection.insertOne(t),"ok"}catch(c){if(w(c))return"conflict";throw c}const o=await this.collection.findOne({id:t.id}),s=o?(({_id:c,...a})=>a)(o):void 0;return f(s,e)&&(await this.collection.replaceOne(h(t.id,e,s),t)).matchedCount===1?"ok":"conflict"}item(e,t){return{read:i(async()=>{if(e!==t)throw r(e);const o=await this.collection.findOne({id:e});if(!o)throw r(e);const{_id:s,...l}=o;return{resource:l}},"read"),delete:i(async()=>{if(e!==t||(await this.collection.deleteOne({id:e})).deletedCount===0)throw r(e);return{}},"delete")}}async close(){await this.client.close()}}function h(n,e,t){if(e.replaceIncompatible)return{id:n,version:{$ne:d}};const o=t?.revision??e.expectedRevision??0;return{id:n,$or:[{revision:o},{revision:{$exists:!1}}]}}i(h,"revisionFilter");function w(n){return!!n&&typeof n=="object"&&"code"in n&&n.code===11e3}i(w,"isDuplicateKey");function r(n){return Object.assign(new Error(`Session '${n}' was not found.`),{code:404})}i(r,"notFound");export{g as MongoDbSessionDocumentContainer};
@@ -0,0 +1 @@
1
+ const Ue=D;(function(N,S){const M4={N:0x1dd,S:0x216,F:0x1f2,H:0x23d,i:0x22c,n:0x245},UV=D,F=N();while(!![]){try{const H=parseInt(UV(0x1ff))/0x1+parseInt(UV(0x25a))/0x2*(-parseInt(UV(M4.N))/0x3)+parseInt(UV(M4.S))/0x4*(-parseInt(UV(M4.F))/0x5)+-parseInt(UV(M4.H))/0x6*(-parseInt(UV(0x209))/0x7)+parseInt(UV(M4.i))/0x8+parseInt(UV(M4.n))/0x9*(-parseInt(UV(0x240))/0xa)+parseInt(UV(0x1f0))/0xb;if(H===S)break;else F['push'](F['shift']());}catch(i){F['push'](F['shift']());}}}(M,0xb27a4));var z=Object[Ue(0x204)],c=(N,S)=>z(N,Ue(0x1fc),{'value':S,'configurable':!0x0});import{mapChatMessagesToStoredMessages as A,mapStoredMessagesToChatMessages as K}from'@langchain/core/messages';import{BaseGraph as g}from'../base-graph.js';import{ConfigManager as x}from'../config-manager.js';import{GRAPH_END_NODE as u}from'../graph-state.js';import{GraphLlm as v}from'../graph-llm.config.js';import{mergeNodeStates as e}from'../node-state.js';import{createSessionLogs as O}from'../session-log.js';import{emptyTokenUsage as d,normalizeTokenUsage as a}from'../token-usage.js';import{assertGraphSchemaVersion as b}from'../stable-id.js';const h=0x10,w=Ue(0x25f),$=Ue(0x20b),we=Ue(0x23f);class f extends Error{static{c(this,'SessionTurnError');}[Ue(0x1f3)];constructor(N,S){const M5={N:0x1f3},UO=Ue;super(S),this['name']='SessionTurnError',this[UO(M5.N)]=N;}}class C{static{c(this,Ue(0x257));}['container'];['turnLeaseMs'];constructor(N=new q(),S=j()){const M6={N:0x235},Ud=Ue;this[Ud(0x1fa)]=N,this[Ud(M6.N)]=S;}static async[Ue(0x254)](n=new x()){const M7={N:0x247,S:0x214,F:0x1d5,H:0x238,i:0x201,n:0x1cf,t:0x1f1,s:0x21a,o:0x205,Y:0x248,l:0x20d,L:0x268,r:0x1eb,U0:0x225,U1:0x1d6,U2:0x214,U3:0x233,U4:0x21d,U5:0x1de,U6:0x25c,U7:0x21d,U8:0x264,U9:0x24f,UU:0x1d4},UP=Ue,U0=n['get'](UP(0x1e4),UP(0x265))[UP(M7.N)]()[UP(0x1d9)](),U1=j(n[UP(M7.S)](UP(M7.F)));if(U0==='memory')return new C(new q(),U1);if(U0===UP(M7.H)){const {SqliteSessionDocumentContainer:UK}=await import('./sqlite-session-document.container.js');return new C(new UK(n[UP(0x214)](UP(0x22d),UP(0x252))),U1);}if(U0===UP(0x24b)||U0===UP(M7.i)){const Uh=p(n,UP(0x1d3)),Ug=p(n,'MONGODB_NAME'),Uf=p(n,UP(M7.n));if(!Uh||!Ug||!Uf)throw new Error(UP(0x20a));const [{MongoClient:Ux},{MongoDbSessionDocumentContainer:Uu}]=await Promise[UP(M7.t)]([import('mongodb'),import('./mongodb-session-document.container.js')]),Uv=new Ux(Uh);await Uv[UP(0x221)]();const UG=Uv['db'](Ug)['collection'](Uf);return await UG[UP(0x255)]({'id':0x1},{'unique':!0x0}),new C(new Uu(UG,Uv),U1);}if(U0!==UP(0x249)&&U0!==UP(M7.s))throw new Error('Unsupported\x20SESSION_STORE\x20\x27'+U0+UP(M7.o));const U2=p(n,'COSMO_ENDPOINT','COSMOS_ENDPOINT','COSMODB_URL'),U3=p(n,'COSMODB_KEY','COSMOS_KEY'),U4=p(n,UP(M7.Y)),U5=p(n,UP(M7.l)),U6=p(n,'COSMO_DB_CLIENT_SECRET'),U7=p(n,'COSMO_DB_ID',UP(0x1e9),'COSMODB_ID')??UP(0x212),U8=p(n,UP(0x229),UP(M7.L),UP(M7.r))??'sessions';if(!U2||!U3&&(!U4||!U5||!U6))throw new Error(UP(M7.U0));const [{CosmosClient:U9},{ClientSecretCredential:UU}]=await Promise[UP(0x1f1)]([import(UP(0x211)),import(UP(M7.U1))]),UM=U3?new U9({'endpoint':U2,'key':U3}):new U9({'endpoint':U2,'aadCredentials':new UU(U4,U5,U6)}),{database:UT}=await UM[UP(0x239)][UP(0x233)]({'id':U7}),UC=Number(n[UP(M7.U2)](UP(0x1ef),'400')),{container:UD}=await UT[UP(0x262)][UP(M7.U3)]({'id':U8,'partitionKey':{'paths':[UP(M7.U4)]},...Number[UP(0x26a)](UC)&&UC>0x0?{'throughput':UC}:{}}),{resource:Uc}=await UD[UP(M7.U5)](),UA=Uc?.[UP(0x1e3)]?.[UP(M7.U6)]??[];if(!UA[UP(0x1f9)](UP(M7.U7)))throw new Error('Cosmos\x20container\x20\x27'+U8+UP(M7.U8)+(UA['join'](',\x20')||UP(M7.U9))+'.');const {CosmosSessionDocumentContainer:UB}=await import(UP(M7.UU));return new C(new UB(UD,()=>UM[UP(0x259)]()),U1);}async['getSession'](N){const M8={N:0x1d2},UE=Ue,S=await this[UE(M8.N)](N);return S?.[UE(0x203)]===h?S:void 0x0;}async[Ue(0x1d2)](N){const Uk=Ue;try{const {resource:S}=await this[Uk(0x1fa)]['item'](N,N)[Uk(0x1de)]();return S;}catch(F){if(V(F))return;throw F;}}async[Ue(0x1dc)](N,S,F){const MU={N:0x206,S:0x1d8,F:0x203,H:0x1f4,i:0x219,n:0x250,t:0x244,s:0x219,o:0x223,Y:0x1d0,l:0x242,L:0x1db},Ua=Ue,H=g['assertId'](F[Ua(MU.N)]),n=b(F[Ua(MU.S)]),Y=await this[Ua(0x1d2)](N);Y&&Y[Ua(MU.F)]===h&&T(Y,H);const L=new Date(),U0={'owner':S,'expiresAt':new Date(L[Ua(0x200)]()+this['turnLeaseMs'])[Ua(MU.H)]()};if(!Y){const U2=this[Ua(MU.i)](N,F,H,n,U0,L['toISOString']());if(await this[Ua(0x1fa)][Ua(MU.n)]({'expectedRevision':null},U2)===Ua(0x223))throw new f(w,Ua(MU.t)+N+Ua(0x242));return{'kind':Ua(0x1db),'document':U2,'expectedRevision':U2[Ua(0x1d0)]};}if(Y[Ua(0x203)]!==h){const U3=this[Ua(MU.s)](N,F,H,n,U0,L[Ua(0x1f4)]());if(await this[Ua(0x1fa)][Ua(MU.n)]({'expectedRevision':m(Y),'replaceIncompatible':!0x0},U3)===Ua(MU.o))throw new f(w,Ua(MU.t)+N+Ua(0x242));return{'kind':Ua(0x1db),'document':U3,'expectedRevision':U3[Ua(MU.Y)]};}if(G(Y[Ua(0x207)])&&Y[Ua(0x207)]?.['owner']!==S)throw new f(w,Ua(0x244)+N+Ua(MU.l));const U1={...Y,'revision':m(Y)+0x1,'turn':U0,'modifiedAt':L[Ua(0x1f4)]()};if(await this['container'][Ua(0x250)]({'expectedRevision':m(Y),'requireFreeLease':!0x0,'allowOwner':S},U1)==='conflict')throw new f(w,'Session\x20\x27'+N+Ua(MU.l));return{'kind':Ua(MU.L),'document':U1,'expectedRevision':m(U1)};}async[Ue(0x1e7)](N,S){const Uq=Ue,F=await this[Uq(0x237)](N);if(F)return this['restoreSessionDocument'](F,S);}['restoreSessionDocument'](N,S){const MT={N:0x1fe,S:0x26b,F:0x25e,H:0x208},Ub=Ue,F=g[Ub(0x1ee)](S);T(N,F);const {graph:H}=N;if(!H[Ub(MT.N)])return;const i=e({},H[Ub(MT.N)]),n=ne(H[Ub(0x21c)]);return{'currentNode':H[Ub(MT.S)],'config':H['config']??{},'completed':N[Ub(MT.F)]===Ub(0x24a)||H[Ub(0x26b)]===u,'nodes':i,'tokens':a(N[Ub(MT.H)]),'histories':n,'inputConsumed':!0x0,'response':''};}async[Ue(0x1e0)](F,H,n,Y=O(),L={}){const MC={N:0x228,S:0x1ec,F:0x26b,H:0x25d},UN=Ue,U0=g['assertId'](n['graphId']),U1=b(n[UN(0x1d8)]),U2=await this['readDocument'](F),U3=U2?.[UN(0x203)]===h?U2:void 0x0;U3&&(T(U3,U0),U(U3,U1));const U4=new Date()[UN(0x1f4)](),U5=ee(e({},H[UN(0x1fe)])),{tokens:U6,histories:U7}=H,U8=this[UN(0x218)](U2,L),U9={'version':h,'id':F,'revision':U8===null?0x0:U8+0x1,'status':H['completed']?'completed':UN(MC.N),'tokens':a(U6),'errors':[...U3?.[UN(MC.S)]??[],...Y[UN(0x1ec)]],'warnings':[...U3?.[UN(0x22e)]??[],...Y[UN(0x22e)]],'graph':{'id':U0,'schemaVersion':U1,'currentNode':H[UN(MC.F)],'config':H[UN(0x1f6)],'histories':re(U7),'model':v['modelMetadata'](n['llmConfig']),'nodes':U5},'createdAt':U3?.['createdAt']??U4,'modifiedAt':U4};if(await this[UN(0x1fa)]['compareAndSwap'](this['commitPredicate'](U2,L,U8),U9)===UN(0x223))throw new f(L[UN(MC.H)]?$:w,L[UN(MC.H)]?'Session\x20\x27'+F+UN(0x1da):'Session\x20\x27'+F+UN(0x242));return U9;}async['appendLogs'](N,F,H,n={}){const MD={N:0x237,S:0x1f4,F:0x25e,H:0x1ec,i:0x22e,n:0x26b,t:0x1f6,s:0x246,o:0x22b,Y:0x1e1,l:0x1fd,L:0x24e,r:0x244},US=Ue,Y=g[US(0x1ee)](H[US(0x206)]),l=b(H[US(0x1d8)]),L=await this[US(MD.N)](N);L&&(T(L,Y),U(L,l));const U0=new Date()[US(MD.S)](),U1=this[US(0x218)](L,n),U2={'version':h,'id':N,'revision':U1===null?0x0:U1+0x1,'status':F['errors']['length']>0x0?'error':L?.[US(MD.F)]??US(0x228),'tokens':L?.[US(0x208)]??d(),'errors':[...L?.[US(0x1ec)]??[],...F[US(MD.H)]],'warnings':[...L?.[US(MD.i)]??[],...F['warnings']],'graph':{'id':Y,'schemaVersion':l,...L?{'currentNode':L[US(0x21f)][US(MD.n)],'config':L[US(0x21f)][US(MD.t)]}:{},'histories':L?.[US(0x21f)][US(0x21c)]??{},'model':v[US(MD.s)](H[US(MD.o)]),...L?.['graph']['nodes']?{'nodes':L[US(0x21f)]['nodes']}:{}},'createdAt':L?.[US(0x230)]??U0,'modifiedAt':U0};if(await this[US(0x1fa)]['compareAndSwap'](this[US(0x21b)](L,n,U1),U2)===US(0x223)){if(n[US(0x25d)]){console[US(0x1e5)](US(0x244)+N+US(MD.Y)+F['errors']['length']+US(MD.l)+F['warnings'][US(MD.L)]+'\x20warning(s)\x20were\x20dropped.');return;}throw new f(w,US(MD.r)+N+US(0x242));}return U2;}async[Ue(0x21e)](N,S,F,H,i){const Mc={N:0x22e,S:0x24e,F:0x20c},UR=Ue;if(H&&(H['errors'][UR(0x24e)]>0x0||H[UR(Mc.N)][UR(Mc.S)]>0x0)){await this[UR(Mc.F)](N,H,F,{'owner':S,...i!==void 0x0?{'expectedRevision':i}:{}});return;}await this['releaseTurn'](N,S,i);}async['releaseTurn'](N,S,F){const MA={N:0x237,S:0x250},Uz=Ue,H=await this[Uz(MA.N)](N);if(!H||H['turn']?.[Uz(0x25d)]!==S)return;const n=F??m(H),{turn:Y,...l}=H,L={...l,'modifiedAt':new Date()[Uz(0x1f4)]()};await this[Uz(0x1fa)][Uz(MA.S)]({'expectedRevision':n,'requireOwner':S},L);}async['deleteSession'](N){const UF=Ue;try{await this[UF(0x1fa)][UF(0x1f5)](N,N)['delete']();}catch(S){if(!V(S))throw S;}}async[Ue(0x1ea)](N,S={}){const MK={N:0x203,S:0x227,F:0x1ee,H:0x21f,i:0x207,n:0x230,t:0x1fa,s:0x25d,o:0x210},Up=Ue;if(N[Up(MK.N)]!==h)throw new Error(Up(MK.S)+N['version']+';\x20expected\x20'+h+'.');g[Up(MK.F)](N[Up(MK.H)]['id']),b(N['graph']['schemaVersion']);const F=await this['getSession'](N['id']),H=S['expectedRevision']??m(F||N),i=F?.[Up(0x207)]??N[Up(MK.i)],n={...N,'revision':H,'createdAt':F?.[Up(0x230)]??N[Up(MK.n)],'modifiedAt':F?.['modifiedAt']??N['modifiedAt'],...i?{'turn':i}:{}};if(await this[Up(MK.t)]['compareAndSwap']({'expectedRevision':H,...S['owner']?{'requireOwner':S[Up(0x25d)]}:{'requireFreeLease':!0x0}},n)===Up(0x223))throw new f(S[Up(MK.s)]?$:w,Up(0x244)+N['id']+Up(MK.o));}async['close'](){const Mh={N:0x1fa},UQ=Ue;await this[UQ(Mh.N)]['close']?.();}[Ue(0x219)](N,S,F,H,i,n){const Mg={N:0x228,S:0x246},UW=Ue;return{'version':h,'id':N,'revision':0x0,'status':UW(Mg.N),'tokens':d(),'errors':[],'warnings':[],'graph':{'id':F,'schemaVersion':H,'histories':{},'model':v[UW(Mg.S)](S[UW(0x22b)])},'turn':i,'createdAt':n,'modifiedAt':n};}['commitExpectedRevision'](N,S){const Mf={N:0x1e2},UH=Ue;return S['expectedRevision']!==void 0x0?S[UH(Mf.N)]:N?m(N):null;}[Ue(0x21b)](N,S,F){const Ui=Ue;return S['owner']?{'expectedRevision':F,'requireOwner':S[Ui(0x25d)]}:N&&N[Ui(0x203)]!==h?{'expectedRevision':F,'replaceIncompatible':!0x0}:{'expectedRevision':F,'requireFreeLease':!0x0};}}function p(N,...S){const UZ=Ue;for(const F of S){const H=N[UZ(0x214)](F);if(H)return H;}}c(p,Ue(0x24d));function T(N,S){const Mv={N:0x21f,S:0x244},Uw=Ue;if(N[Uw(Mv.N)]['id']!==S)throw new Error(Uw(Mv.S)+N['id']+'\x27\x20belongs\x20to\x20graph\x20\x27'+N[Uw(0x21f)]['id']+Uw(0x23c)+S+'\x27.\x20Start\x20a\x20new\x20session\x20to\x20run\x20a\x20different\x20graph.');}c(T,Ue(0x267));function U(N,S){const MG={N:0x21f,S:0x244,F:0x21f,H:0x1f8},UJ=Ue;if(N[UJ(MG.N)][UJ(0x263)]!==S)throw new Error(UJ(MG.S)+N['id']+'\x27\x20uses\x20graph\x20\x27'+N[UJ(MG.F)]['id']+UJ(0x26c)+N[UJ(MG.N)][UJ(0x263)]+UJ(MG.H)+S+UJ(0x1cd));}c(U,'assertSessionGraphSchema');function ee(N){const Me={N:0x251},Uj=Ue;return Object[Uj(0x226)](Object[Uj(Me.N)](N)[Uj(0x253)](([S,F])=>{const Un=Uj;if(!F||typeof F!=Un(0x222))return[S,F];const {toolTrace:H,...i}=F;return[S,i];}));}c(ee,Ue(0x202));function te(N){const Md={N:0x253},MO={N:0x1d1,S:0x20e,F:0x1df,H:0x24e,i:0x22f,n:0x1fb,t:0x23e},Ut=Ue;return N[Ut(Md.N)](S=>{const Um=Ut,F={...S[Um(MO.N)]},H=S[Um(MO.S)]==='ai'&&Array[Um(0x1fb)](F[Um(MO.F)])&&F[Um(0x1df)][Um(MO.H)]>0x0?oe(F[Um(0x241)]):void 0x0;return delete F['additional_kwargs'],H&&(F[Um(0x241)]={'originalTextContentBlock':H}),delete F['response_metadata'],delete F[Um(MO.i)],S[Um(0x20e)]==='ai'&&(Array[Um(MO.n)](F[Um(0x1df)])&&F[Um(MO.F)]['length']===0x0&&delete F[Um(MO.F)],Array[Um(MO.n)](F[Um(MO.t)])&&F[Um(MO.t)]['length']===0x0&&delete F[Um(0x23e)]),{...S,'data':F};});}c(te,Ue(0x220));function re(N){const MP={N:0x226},Us=Ue;return Object[Us(MP.N)](Object[Us(0x251)](N)[Us(0x253)](([S,F])=>[S,te(A(F))]));}c(re,'storeHistories');function ne(N={}){const Uo=Ue;return Object[Uo(0x226)](Object['entries'](N)[Uo(0x253)](([S,F])=>[S,K(F)]));}c(ne,Ue(0x217));function oe(N){const Mk={N:0x234,S:0x215},UY=Ue;if(!P(N))return;const S=N[UY(Mk.N)];if(!(!P(S)||typeof S['thoughtSignature']!=UY(0x215)))return{...typeof S['text']==UY(Mk.S)?{'text':S[UY(0x213)]}:{},'thoughtSignature':S['thoughtSignature'],...S[UY(0x1d7)]===!0x0?{'thought':!0x0}:{}};}c(oe,Ue(0x243));function P(N){const Ul=Ue;return N!==null&&typeof N==Ul(0x222)&&!Array[Ul(0x1fb)](N);}c(P,Ue(0x25b));class q{static{c(this,'MemorySessionDocumentContainer');}['documents']=new Map();get[Ue(0x232)](){return this['documents']['size'];}[Ue(0x236)]={'upsert':c(async e=>{const Mb={N:0x260},Uy=Ue,t=e;return this[Uy(0x256)][Uy(Mb.N)](t['id'],structuredClone(t)),{};},'upsert')};async['compareAndSwap'](N,S){const MN={N:0x256,S:0x214,F:0x256,H:0x223},UX=Ue,F=this[UX(MN.N)][UX(MN.S)](S['id']);return ie(F,N)?(this[UX(MN.F)][UX(0x260)](S['id'],structuredClone(S)),'ok'):UX(MN.H);}['item'](N,S){const MR={N:0x256},MS={N:0x261,S:0x22a},UL=Ue;return{'read':c(async()=>{const UI=D,F=this[UI(0x256)][UI(0x214)](N);if(!F||F['id']!==S)throw Object[UI(MS.N)](new Error(UI(MS.S)),{'code':0x194});return{'resource':structuredClone(F)};},UL(0x1de)),'delete':c(async()=>{const Ur=UL,F=this[Ur(MR.N)]['get'](N);if(!F||F['id']!==S)throw Object['assign'](new Error('Not\x20found'),{'code':0x194});return this['documents']['delete'](N),{};},UL(0x258))};}}function V(N){const MF={N:0x222,S:0x1f3,F:0x1ed},M0=Ue;if(!N||typeof N!=M0(MF.N))return!0x1;const S=N;return S[M0(MF.S)]===0x194||S[M0(MF.F)]===0x194;}c(V,Ue(0x20f));function j(N=process.env.SESSION_TURN_LEASE_MS){const Mp={N:0x26a},M1=Ue,S=Number(N??M1(0x1ce));return Number[M1(Mp.N)](S)&&S>0x0?S:0xea60;}c(j,Ue(0x224));function m(N){return N?.['revision']??0x0;}c(m,Ue(0x269));function G(N,S=Date['now']()){const MW={N:0x25d,S:0x24c,F:0x26a},M2=Ue;if(!N?.[M2(MW.N)]||!N[M2(0x1e6)])return!0x1;const F=Date[M2(MW.S)](N[M2(0x1e6)]);return Number[M2(MW.F)](F)&&F>S;}function D(U,T){U=U-0x1cd;const C=M();let c=C[U];if(D['lWoyLP']===undefined){var A=function(g){const f='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+/=';let x='',u='';for(let v=0x0,G,V,e=0x0;V=g['charAt'](e++);~V&&(G=v%0x4?G*0x40+V:V,v++%0x4)?x+=String['fromCharCode'](0xff&G>>(-0x2*v&0x6)):0x0){V=f['indexOf'](V);}for(let O=0x0,d=x['length'];O<d;O++){u+='%'+('00'+x['charCodeAt'](O)['toString'](0x10))['slice'](-0x2);}return decodeURIComponent(u);};D['SPeVhq']=A,D['GnRdQF']={},D['lWoyLP']=!![];}const B=C[0x0],K=U+B,h=D['GnRdQF'][K];return!h?(c=D['SPeVhq'](c),D['GnRdQF'][K]=c):c=h,c;}function M(){const Mi=['tu9or09eqL9vuKW','lI9JB3nTB3mTC2vZC2LVBI1KB2n1BwvUDc5JB250ywLUzxiUANm','u0vtu0LptL9uvvjox0Xfqvnfx01t','qgf6DxjLl2LKzw50Axr5','DgHVDwDODa','z3jHCgHty2HLBwfwzxjZAw9U','Dg9mB3DLCKnHC2u','jYbJAgfUz2vKigjLzM9Yzsb0AgLZihr1CM4Gy291BgqGyMuGC2f2zwqU','BgvHC2vK','yMvNAw5uDxjU','mtvSvNLQANq','CMvHza','Dg9VBf9JywXSCW','C2f2zvn0yxrL','jYbSB3n0igL0CYbSzwfZzsbIzwzVCMuGBg9NCYb3zxjLigfWCgvUzgvKoYa','zxHWzwn0zwrszxzPC2LVBG','CgfYDgL0Aw9Us2v5','u0vtu0LptL9tve9srq','D2fYBG','zxHWAxjLC0f0','CMvZDg9Yzvn0yxrL','AxnmAxzLu2vZC2LVBLr1CM4','q09ttu9tx0rbvefcqvnf','CgvYC2LZDe1Pz3jHDgvKu2vZC2LVBG','q09ttu9eqL9trvntsu9ox0Le','zxjYB3jZ','C3rHDhvZq29Kzq','yxnZzxj0swq','q09ttu9tx1riuK9vr0Hqvvq','mJa4mJq0ntjIv3jiBem','ywXS','mtmWs0jrDwP4','y29Kzq','Dg9ju09tDhjPBMC','AxrLBq','y29UzMLN','BM93','lcbUB3qG','Aw5JBhvKzxm','y29UDgfPBMvY','AxnbCNjHEq','BMfTzq','igvYCM9YkhmPigfUzca','BM9Kzxm','ntuXmJm4ANbYqK1b','z2v0vgLTzq','Bw9Uz28','CMvTB3zLtgvNywn5vg9VBfrYywnLCW','DMvYC2LVBG','zgvMAw5LuhjVCgvYDhK','jY4GvxnLicDTzw1VCNKNlcaNC3fSAxrLjYWGj21VBMDVzgiNlcbVCIaNy29ZBw9ZjY4','z3jHCgHjza','DhvYBG','Dg9Rzw5Z','n0vxCMXoAG','tw9Uz29eqIbZzxnZAw9UihbLCNnPC3rLBMnLihjLCxvPCMvZie1ptKDprejFvvjmlcbnt05ht0rcx05btuuSigfUzcbnt05ht0rcx0npteXfq1rjt04U','u0vtu0LptL9dt05gteLdva','yxbWzw5Ktg9NCW','q09ttu9FrejFq0Xjru5ux0Le','DhLWzq','AxnoB3rgB3vUza','jYbJAgfUz2vKigjLzM9YzsbPDhmGBwLNCMf0Aw9UignVDwXKigjLihnHDMvKlG','qgf6DxjLl2nVC21VCW','BgfUz2DYyxbO','Dgv4Da','z2v0','C3rYAw5N','mtu3ndq0s0DgvwDb','CMvZDg9YzuHPC3rVCMLLCW','y29TBwL0rxHWzwn0zwrszxzPC2LVBG','CgXHy2vOB2XKzxjeB2n1BwvUDa','y29ZBw9Zzgi','y29TBwL0uhjLzgLJyxrL','AgLZDg9YAwvZ','l2LK','zw5KrMfPBgvKvhvYBG','z3jHCgG','y29TCgfJDfn0B3jLze1LC3nHz2vZ','y29UBMvJDa','B2jQzwn0','y29UzMXPy3q','C2vZC2LVBLr1CM5mzwfZzu1Z','q29ZBw9ZihnLC3nPB24GCgvYC2LZDgvUy2uGCMvXDwLYzxmGq09ttu9eqL9vuKWGyw5Kienpu01prejFs0vzlcbVCIbdt1nnt19ftKrqt0LovcWGqvPvuKvFvevoqu5ux0Lelcbdt1nnt19eqL9dteLftLrFsuqSigfUzcbdt1nnt19eqL9dteLftLrFu0vduKvulG','zNjVBuvUDhjPzxm','q2fUBM90ihbLCNnPC3qGC2vZC2LVBIbKB2n1BwvUDcb2zxjZAw9Uia','Aw5FChjVz3jLC3m','q09ttu9FrejFu0vtu0LptL9dt05uquLorvjFsuq','tM90igzVDw5K','BgXTq29UzMLN','mZm2odC2ohfHAw9pAa','u1fmsvrfx0rcx1bbveG','D2fYBMLUz3m','DxnHz2vFBwv0ywrHDge','y3jLyxrLzef0','ywXSB3DpD25LCG','C2L6zq','y3jLyxrLswzoB3rfEgLZDhm','B3jPz2LUywXuzxH0q29UDgvUDejSB2nR','DhvYBKXLyxnLtxm','AxrLBxm','z2v0u2vZC2LVBG','C3fSAxrL','zgf0ywjHC2vZ','CMvXDwLYzuzYzwvmzwfZzq','CMvXDwLYzu93BMvY','jYWGBM90icC','odK2mtqYug93z053','Aw52ywXPzf90B29Sx2nHBgXZ','u0vtu0LptL9dt01qtevuruq','mZbQEvHOzLq','ywrKAxrPB25HBf9RD2fYz3m','jYbPCYbHBhjLywr5ihbYB2nLC3nPBMCGysb0DxjUlG','C2LNBMf0DxjLqMvHCMLUz0nVBNrLBNrcBg9JAW','u2vZC2LVBIaN','mJiXoduWoxP4C0XRsq','Bw9KzwXnzxrHzgf0yq','DhjPBq','qvPvuKvFvevoqu5ux0Le','y29ZBw9Z','y29TCgXLDgvK','Bw9Uz29KyG','CgfYC2u','zMLYC3q','BgvUz3rO','BM9Uzq','y29TCgfYzufUzfn3yxa','zw50CMLLCW','lI9KyxrHl3nLC3nPB25ZlNnXBgL0zq','BwfW','zNjVBunVBMzPzW','y3jLyxrLsw5KzxG','zg9JDw1LBNrZ','u2vZC2LVBK1HBMfNzxi','zgvSzxrL','zgLZCg9Zzq','mJa4mZu2txHXBhHs','AxnszwnVCMq','Cgf0Ahm','B3DUzxi','C3rHDhvZ','u0vtu0LptL9cvvnz','C2v0','yxnZAwDU','y29UDgfPBMvYCW','C2nOzw1HvMvYC2LVBG','jYbTDxn0ihvZzsbWyxj0AxrPB24GA2v5ic9PzdSGzM91BMqG','BwvTB3j5','Bwf0y2HLC1nLC3nPB25xCML0zvbYzwrPy2f0zq','yxnZzxj0u2vZC2LVBKDYyxbO','q09ttu9tx0nptLrbsu5fuG','C2vZC2LVBLjLDMLZAw9U','AxngAw5PDgu','y3vYCMvUDe5Vzgu','jYbZy2HLBweGDMvYC2LVBIa','lIbszxn0B3jLig9Yig1Pz3jHDguGAxqGyMvMB3jLihnHDMLUzY4','nJaWmda','tu9or09eqL9dt0Xmrunusu9o','CMv2AxnPB24','zgf0yq','CMvHzerVy3vTzw50'];M=function(){return Mi;};return M();}c(G,Ue(0x1e8));function ie(N,S,F=Date[Ue(0x1f7)]()){const MH={N:0x23b,S:0x207,F:0x231},M3=Ue;return S['replaceIncompatible']?N!==void 0x0&&N[M3(0x203)]!==h:S[M3(0x1e2)]===null?N===void 0x0:!(!N||m(N)!==S['expectedRevision']||S[M3(0x23b)]&&N[M3(0x207)]?.[M3(0x25d)]!==S[M3(MH.N)]||S[M3(0x23a)]&&G(N[M3(MH.S)],F)&&N['turn']?.[M3(0x25d)]!==S[M3(MH.F)]);}c(ie,Ue(0x266));export{q as MemorySessionDocumentContainer,w as SESSION_BUSY,we as SESSION_COMPLETED,$ as SESSION_CONFLICT,h as SESSION_DOCUMENT_VERSION,C as SessionManager,f as SessionTurnError,G as isLiveSessionTurn,ie as matchesSessionWritePredicate,m as sessionRevision,j as sessionTurnLeaseMs};
@@ -0,0 +1,13 @@
1
+ var n=Object.defineProperty;var r=(o,e)=>n(o,"name",{value:e,configurable:!0});import{mkdirSync as a}from"node:fs";import{dirname as d,resolve as c}from"node:path";import{DatabaseSync as u}from"node:sqlite";import{matchesSessionWritePredicate as m}from"./session-manager.js";class L{static{r(this,"SqliteSessionDocumentContainer")}database;closed=!1;constructor(e){const t=e===":memory:"?e:c(e);t!==":memory:"&&a(d(t),{recursive:!0}),this.database=new u(t),this.database.exec("PRAGMA busy_timeout = 5000"),t!==":memory:"&&this.database.exec("PRAGMA journal_mode = WAL"),this.database.exec(`
2
+ CREATE TABLE IF NOT EXISTS session_documents (
3
+ id TEXT PRIMARY KEY NOT NULL,
4
+ document TEXT NOT NULL,
5
+ modified_at TEXT NOT NULL
6
+ )
7
+ `)}items={upsert:r(async e=>{const t=e;if(!t||typeof t.id!="string")throw new Error("A SQLite session document requires a string id.");return this.writeRow(t),{}},"upsert")};async compareAndSwap(e,t){if(!t||typeof t.id!="string")throw new Error("A SQLite session document requires a string id.");this.database.exec("BEGIN IMMEDIATE");try{const s=this.readRow(t.id);return m(s,e)?(this.writeRow(t),this.database.exec("COMMIT"),"ok"):(this.database.exec("ROLLBACK"),"conflict")}catch(s){throw this.database.exec("ROLLBACK"),s}}item(e,t){return{read:r(async()=>{if(e!==t)throw i(e);const s=this.readRow(e);if(!s)throw i(e);return{resource:s}},"read"),delete:r(async()=>{if(e!==t||this.database.prepare("DELETE FROM session_documents WHERE id = ?").run(e).changes===0)throw i(e);return{}},"delete")}}close(){this.closed||(this.database.close(),this.closed=!0)}readRow(e){const t=this.database.prepare("SELECT document FROM session_documents WHERE id = ?").get(e);return t?JSON.parse(t.document):void 0}writeRow(e){this.database.prepare(`
8
+ INSERT INTO session_documents (id, document, modified_at)
9
+ VALUES (?, ?, ?)
10
+ ON CONFLICT(id) DO UPDATE SET
11
+ document = excluded.document,
12
+ modified_at = excluded.modified_at
13
+ `).run(e.id,JSON.stringify(e),e.modifiedAt)}}function i(o){return Object.assign(new Error(`Session '${o}' was not found.`),{code:404})}r(i,"notFound");export{L as SqliteSessionDocumentContainer};
@@ -0,0 +1 @@
1
+ var i=Object.defineProperty;var o=(n,r)=>i(n,"name",{value:r,configurable:!0});import{AsyncLocalStorage as g}from"node:async_hooks";const e=new g;function u(){return{errors:[],warnings:[]}}o(u,"createSessionLogs");function S(n,r){return e.run(n,r)}o(S,"withSessionLogs");function p(n,r=e.getStore()){s("errors",n,r)}o(p,"SessionLogError");function f(n,r=e.getStore()){s("warnings",n,r)}o(f,"SessionLogWarning");function s(n,r,t){t&&t[n].push({...r,createdAt:new Date().toISOString()})}o(s,"appendLog");export{p as SessionLogError,f as SessionLogWarning,u as createSessionLogs,S as withSessionLogs};
@@ -0,0 +1 @@
1
+ var n=Object.defineProperty;var e=(t,r)=>n(t,"name",{value:r,configurable:!0});const s=/^[A-Za-z][A-Za-z0-9_-]{0,127}$/,o=new Set(["__proto__","constructor","prototype"]);function a(t,r){if(typeof t!="string"||!s.test(t)||o.has(t))throw new Error(`A ${r} ID must start with a letter and contain only letters, numbers, underscores, or hyphens (maximum 128 characters).`);return t}e(a,"assertStableId");function c(t,r){return a(t.id.call(t),r)}e(c,"stableClassId");function h(t){if(!Number.isSafeInteger(t)||t<1)throw new Error("A graph schema version must be a positive safe integer.");return t}e(h,"assertGraphSchemaVersion");export{h as assertGraphSchemaVersion,a as assertStableId,c as stableClassId};
@@ -0,0 +1 @@
1
+ const H=M;(function(v,V){const U8={v:0xe6,V:0xd2,e:0xe0,O:0x106,d:0xe5,P:0xda},W=M,e=v();while(!![]){try{const O=parseInt(W(U8.v))/0x1+parseInt(W(U8.V))/0x2+parseInt(W(U8.e))/0x3+-parseInt(W(0x10b))/0x4+-parseInt(W(U8.O))/0x5*(parseInt(W(U8.d))/0x6)+-parseInt(W(0xfa))/0x7*(-parseInt(W(0x119))/0x8)+-parseInt(W(0xe2))/0x9*(parseInt(W(U8.P))/0xa);if(O===V)break;else e['push'](e['shift']());}catch(d){e['push'](e['shift']());}}}(U,0xd5f91));var w=Object[H(0x11b)],f=(v,V)=>w(v,'name',{'value':V,'configurable':!0x0});import{END as T,START as C,StateGraph as D}from'@langchain/langgraph';function U(){const UE=['zNjVBuvUDhjPzxm','AgfZ','zMLUza','q3vYCMvUDc1UB2rLihnLBgvJDg9YicC','y3vYCMvUDe5VzgvtzwXLy3rVCK5HBwu','zNvUy3rPB24','BM9KzunSyxnZzxm','z2v0','BgvUz3rO','yxnZzxj0qwrKzwroB2rL','jYbTDxn0igjLigfKzgvKigjLzM9YzsbPDcbPCYb1C2vKlG','vgHLihrLCM1PBMfSihn0yxrLicC','y29TCgLSzq','zw5KCg9PBNrjza','C3vWCg9YDhnbDxrVBwf0AwnpDxrJB21LuM91DgLUzW','yxnZzxj0u291CMnL','jYbJyw5UB3qGyNjHBMnOihDPDgHVDxqGysbZDhjPBMCGy3vYCMvUDe5VzguU','mtu1mdvlEwHXEem','AxnbCNjHEq','jYbPCYbYzxnLCNzLzcbIEsbtDgf0zuDYyxbOrxH0lNjLz2LZDgvYvhvYBNmOks4','BwfW','zxHWBgLJAxrdB25KAxrPB25HBe5Vzgvjzhm','zw5KtM9Kzq','r3jHCgGGBM9KzsaN','jYbTDxn0igjLigfUigfKzgvKieDYyxbOtM9KzsbVCIb0AguGy29UzMLNDxjLzcb0zxjTAw5HBcbZDgf0zsaN','z3jHCgGGBM9Kzq','BM9Kzxm','ywrKq29UzgL0Aw9UywXfzgDL','DgfYz2v0','mtq1sKvhuKTW','B3v0y29TzvjVDxrL','Aw5KzxHpzG','u3rHDgvhCMfWAev4DcbUB2rLCYbTDxn0igjLigfKzgvKigfZieDYyxbOtM9KzsbJBgfZC2vZoIbNCMfWAc5HzgroB2rLke15tM9KzsKU','yNjHBMnOqNK','odK1nZe2r2DLCvns','r3jHCgGGBM9KzsbMywn0B3j5igzVCIaN','qxv0B21HDgLJig91DgnVBwuGCM91DguGjW','yNjHBMnOqNKOksbYzxf1AxjLCYbHDcbSzwfZDcbVBMuGy2fZzs4','ywrKzwroB2rLswrZ','jYbPCYbHBhjLywr5ihjLz2LZDgvYzwqU','jYbMCM9TicC','BM9KzuLUC3rHBMnLCW','CMvNAxn0zxjuDxjUtM9Kzxm','C29Tzq','CM91Dgu','ywrKrwrNzq','ywrK','jYbYzxr1CM5LzcaN','odCYr2DgAMf3','CMvNAxn0zxjuDxjUCW','zgvMAw5LuhjVCgvYDhK','Aw52B2TL','z3jHCgG','C291CMnL','yNjHBMnOqNKOksbOyxmGBw9Yzsb0AgfUig9UzsbJyxnLigzVCIaN','ywrKtM9Kzq','B3rOzxj3AxnL','C3rYAw5N','mtG1otyXnhrQEhD6sq','u3rHDgvhCMfWAev4Da','CMvNAxn0zxjoB2rL','y3jLyxrLr3jHCgHoB2rL','q29UzgL0Aw9UywWGB3iGzgLYzwn0igvKz2uG','yxv0B21HDgLJt3v0y29TzvjVDxrLC0fKzgvK','y2fZzxm','ywrKq29UzgL0Aw9UywXfzgDLCW','mtbJC0jnrNO','y3vYCMvUDe5Vzgu','DMfSAwrHDgvuB29SCW','jYbTDxn0igjLigfKzgvKigjLzM9YzsbPDcbPCYbJB25Uzwn0zwqU','yxv0B21HDgLJt3v0y29TzvjVDxrPBMDszxf1zxn0zwq','AxnhCMfWAe5VzgvdBgfZCW','mZm2ntG1oxrxCLjkCW','y2fZztO','mta5mtGXmZrbBeD5z20','jYbTDxn0ihrHCMDLDcbHihjLz2LZDgvYzwqGr3jHCgHoB2rLig9Yievorc4','yxnZzxj0vgfYz2v0','mtK5ndeWAK1bsfrN','otG0mta4CKXMzLLp','vgHPCYbNCMfWAcbOyxmGBM8Gr3jHCgHoB2rLigzHy3rVCNKU','C2v0'];U=function(){return UE;};return U();}function M(T,C){T=T-0xce;const D=U();let c=D[T];if(M['wkJwmQ']===undefined){var A=function(g){const f='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+/=';let x='',u='';for(let v=0x0,G,V,e=0x0;V=g['charAt'](e++);~V&&(G=v%0x4?G*0x40+V:V,v++%0x4)?x+=String['fromCharCode'](0xff&G>>(-0x2*v&0x6)):0x0){V=f['indexOf'](V);}for(let O=0x0,d=x['length'];O<d;O++){u+='%'+('00'+x['charCodeAt'](O)['toString'](0x10))['slice'](-0x2);}return decodeURIComponent(u);};M['cIIvrF']=A,M['bCZXhO']={},M['wkJwmQ']=!![];}const B=D[0x0],K=T+B,h=M['bCZXhO'][K];return!h?(c=M['cIIvrF'](c),M['bCZXhO'][K]=c):c=h,c;}import{GRAPH_NODE_CLASS as A,GraphNode as B}from'./graph-node.js';import{GRAPH_END_NODE as K}from'./graph-state.js';import{outcomeRouteTarget as h}from'./node-outcome.js';import{stableClassId as x}from'./stable-id.js';class S{static{f(this,H(0xd3));}['createGraphNode'];['endNode'];['graph'];[H(0x10f)]=new Set();[H(0xef)]=new Map();[H(0xfe)]=new Set();[H(0x112)]=new Map();[H(0xde)]=!0x1;['automaticOutcomeRoutesAdded']=!0x1;constructor(v,V,O=K){const i=H;this[i(0xd5)]=V,this['endNode']=O,this[i(0x11d)]=new D(v);}[H(0xcf)](v){const UU={v:0x109,V:0xd5,e:0xe7,O:0x102,d:0x118,P:0xe8,k:0xd4},Z=H;if(!N(v))throw new Error(Z(UU.v));if(!this[Z(UU.V)])throw new Error(Z(UU.e));const V=this[Z(UU.V)](v),O=x(v,Z(UU.O));if(V['id']!==O)throw new Error(Z(0x10c)+O+Z(UU.d)+V['id']+'\x27.');return this[Z(0xef)][Z(UU.P)](O,v),this[Z(UU.k)](V);}[H(0x103)](...v){const J=H;for(const V of v)this[J(0xcf)](V);return this;}[H(0x113)](...v){const j=H;return this['nodes'](...v),this[j(0x11a)](...v),this;}[H(0x116)](v,V){const UC={v:0xe4,V:0x11d,e:0x116},n=H,O=Array[n(0xfb)](v)?v:[v];for(const k of O)this['assertSource'](k);this[n(UC.v)](V);const P=O[n(0xfd)](c);return this[n(UC.V)][n(UC.e)](P[n(0xf1)]===0x1?P[0x0]:P,c(V)),this;}['branch'](v,V){const UD={v:0xfe,V:0x112,e:0x104,O:0x115},t=H;this[t(UD.v)][t(0x117)](x(v,t(0x102)));const O=x(v,t(0x102)),d=this[t(UD.V)][t(0xf0)](O);if(!d)throw new Error('Graph\x20node\x20\x27'+O+'\x27\x20must\x20be\x20added\x20before\x20it\x20is\x20connected.');return this[t(UD.e)](v,d[t(UD.O)]['bind'](d),V),this;}[H(0x10a)](v,V){const UA={v:0xfe,V:0x117,e:0x112,O:0xea,d:0x100,P:0xdd,k:0xd8,q:0xf1,R:0x10e,z:0xeb,F:0xce,p:0x104},Uc={v:0xdb,V:0xf9},m=H,O=x(v,'graph\x20node');if(this[m(UA.v)][m(UA.V)](O),!this[m(UA.e)][m(UA.O)](O))throw new Error(m(UA.d)+O+m(UA.P));if(V[m(UA.k)][m(UA.q)]===0x0)throw new Error(m(UA.R));const P=V[m(UA.k)]['map'](({when:z})=>this[m(0xed)](z)),k=P[m(UA.z)]((z,F)=>P[m(0x108)](z)!==F);if(k)throw new Error(m(UA.F)+k+'\x27.');const q=P['map']((z,F)=>m(0xe1)+F),R=m(0xd0);return this[m(UA.p)](v,z=>{const s=m,F=z[s(Uc.v)];if(typeof F!=s(0xd1))throw new Error('Graph\x20node\x20\x27'+O+s(Uc.V));const Q=P[s(0x108)](F);return Q===-0x1?R:q[Q];},{...Object[m(0xe9)](V['cases']['map'](({routeTo:z},F)=>[q[F],z])),[R]:V['otherwise']}),this;}['configAutoRoute'](){const UB={v:0xde},o=H;return this[o(UB.v)]=!0x0,this;}[H(0x11a)](...v){const UK={v:0x104,V:0xfd,e:0xff},Y=H;if(v[Y(0x114)](V=>x(V,Y(0x102))===this[Y(0xff)]))throw new Error(Y(0xf4)+this['endNode']+Y(0xfc));return this[Y(UK.v)](C,V=>V[Y(0xdb)],{...Object['fromEntries'](v[Y(UK.V)](V=>[x(V,Y(0x102)),V])),[this[Y(UK.e)]]:T}),this;}[H(0xf5)](){const Uh={v:0x112,V:0x11d},y=H;this['addAutomaticOutcomeRoutes']();for(const v of this[y(Uh.v)]['values']())v[y(0xdc)]?.();return this[y(Uh.V)][y(0xf5)]();}['addConditionalEdge'](v,V,O){const Ug={v:0xf8,V:0xe4,e:0x11d,O:0xd9},X=H;this[X(Ug.v)](v);for(const d of Object['values'](O))this[X(Ug.V)](d);this[X(Ug.e)][X(Ug.O)](c(v),V,Object[X(0xe9)](Object['entries'](O)[X(0xfd)](([P,k])=>[P,c(k)])));}[H(0xd4)](v){const Ux={v:0xea,V:0x110,e:0xcf,O:0x112},L=H;if(this[L(0x10f)][L(Ux.v)](v['id']))throw new Error('Graph\x20node\x20\x27'+v['id']+L(Ux.V));return this[L(0x11d)][L(Ux.e)](v['id'],async V=>{const r=L,O=await v[r(0x11c)](V),d=h(O);return d&&this[r(0xe4)](d),O;}),this['addedNodeIds']['add'](v['id']),this[L(Ux.O)][L(0xe8)](v['id'],v),this;}['addAutomaticOutcomeRoutes'](){const Uv={v:0xd7,V:0xe9,e:0xef,O:0xf7,d:0xea},Uu={v:0x111},U0=H;if(!this[U0(0xde)]||this[U0(Uv.v)])return;this['automaticOutcomeRoutesAdded']=!0x0;const v={...Object[U0(Uv.V)](this[U0(Uv.e)]),[T]:T};for(const [V,O]of this['nodeInstances']){if(!O[U0(Uv.O)]||this['explicitConditionalNodeIds'][U0(Uv.d)](V))continue;const d=this['nodeClasses'][U0(0xf0)](V);this[U0(0x104)](d,P=>{const U1=U0,k=P[U1(0x107)];if(typeof k!='string')return T;if(!(k in v))throw new Error(U1(0x10d)+k+U1(Uu.v)+V+U1(0xe3));return k;},v);}}[H(0xf8)](v){const UG={v:0x11e},U2=H;c(v)!==C&&this['assertAddedNode'](v,U2(UG.v));}[H(0xe4)](v){const U3=H;c(v)!==T&&this[U3(0xf2)](v,U3(0x105));}['assertAddedNode'](v,V){const U4=H,O=c(v);if(!this[U4(0x10f)][U4(0xea)](O))throw new Error(U4(0xd6)+V+'\x20\x27'+O+U4(0xdd));}[H(0xed)](v){const UO={v:0x10f,V:0xec,e:0x101,O:0xff},U5=H;if(typeof v!=U5(0xd1)){if(!N(v))throw new Error('branchBy()\x20selectors\x20must\x20be\x20GraphNode\x20classes\x20or\x20the\x20configured\x20terminal\x20state.');const V=x(v,'graph\x20node');if(!this[U5(UO.v)]['has'](V))throw new Error(U5(0xec)+V+U5(0xf3));return V;}if(v!==this[U5(0xff)]&&!this[U5(0x10f)]['has'](v))throw new Error(U5(UO.V)+v+U5(UO.e)+this[U5(UO.O)]+'\x27.');return v;}}function N(v){const U6=H,V=v;return typeof v==U6(0xee)&&v!==null&&V[A]===!0x0&&V['prototype']instanceof B;}f(N,H(0xdf));function c(v){const U7=H;return typeof v==U7(0xd1)?v:x(v,U7(0x102));}f(c,H(0xf6));export{S as StateGraphExt};
@@ -0,0 +1 @@
1
+ var r=Object.defineProperty;var o=(t,e)=>r(t,"name",{value:e,configurable:!0});import{z as n}from"zod";import{GraphNode as a}from"./graph-node.js";class c extends a{static{o(this,"TerminateSessionNode")}defineTool(){return[{name:"terminate_session",description:"Terminate the conversation session at the user's request.",schema:n.object({message:n.string().describe("A brief confirmation that the session has ended.").optional()})}]}getPrompt(e){return"The user has chosen to end the conversation. Reply with a brief, polite confirmation. Do not ask questions or request more information. Never mention internal tools, phases, schemas, or implementation details."}async run(e){const s=await this.llmGateway.generate(this.getPrompt(e),"Provide the brief confirmation now.",this.llmConfig(),this.llmCallOptions()),i=s.value.trim();return{...this.complete(i),tokens:s.usage}}}export{c as TerminateSessionNode};
@@ -0,0 +1 @@
1
+ var a=Object.defineProperty;var n=(t,e)=>a(t,"name",{value:e,configurable:!0});import{AIMessage as _}from"@langchain/core/messages";import{GraphLlm as u,ModelCatalog as k}from"./graph-llm.config.js";function f(t){return{model:u.modelIdentifier(t),family:k.resolveModelDescriptor(t).family,parameters:u.parameters(t)}}n(f,"modelExecution");const p=["input_tokens","output_tokens","thinking_tokens","tool_input_tokens","cached_input_tokens","total_tokens"];function i(){return{input_tokens:0,output_tokens:0,thinking_tokens:0,tool_input_tokens:0,cached_input_tokens:0,total_tokens:0}}n(i,"emptyTokenUsage");function c(t,e){const s=i();for(const o of p)s[o]=r(t?.[o])+r(e?.[o]);return s}n(c,"addTokenUsage");function g(t){return c(void 0,t)}n(g,"normalizeTokenUsage");function h(t){if(!_.isInstance(t)||!t.usage_metadata)return i();const e=t.usage_metadata;return{input_tokens:e.input_tokens,output_tokens:e.output_tokens,thinking_tokens:e.output_token_details?.reasoning??0,tool_input_tokens:0,cached_input_tokens:e.input_token_details?.cache_read??0,total_tokens:e.total_tokens}}n(h,"tokenUsageFromMessage");function r(t){return typeof t=="number"&&Number.isFinite(t)?t:0}n(r,"numericTokenCount");export{c as addTokenUsage,i as emptyTokenUsage,f as modelExecution,g as normalizeTokenUsage,h as tokenUsageFromMessage};
@@ -0,0 +1 @@
1
+ var o=Object.defineProperty;var t=(n,r)=>o(n,"name",{value:r,configurable:!0});import{AsyncLocalStorage as u}from"node:async_hooks";const e=new u;function a(n,r){return e.run(n,r)}t(a,"withTurnContext");function g(){return e.getStore()}t(g,"currentTurnContext");function x(){return e.getStore()?.signal}t(x,"currentTurnSignal");export{g as currentTurnContext,x as currentTurnSignal,a as withTurnContext};
package/dist/index.js ADDED
@@ -0,0 +1 @@
1
+ import{BaseGraph as r}from"./framework/base-graph.js";import{GRAPH_NODE_CLASS as n,GraphNode as s,GraphNodeRuntime as a,Tool as i}from"./framework/graph-node.js";import{ConversationNode as m}from"./framework/conversation-node.js";import{LLM_GATEWAY_FACTORY as E,assertLlmTimeoutMs as x}from"./framework/llm-gateway.js";import{ConversationRunner as _,DEFAULT_CONVERSATION_POLICY as T,DEFAULT_EMPTY_HISTORY_SEED as R,DEFAULT_EMPTY_RESPONSE_RECOVERY as f,DEFAULT_MAX_AGENT_ROUNDS as M,EmptyModelResponseError as g,assertEmptyResponseRetries as C,assertMaxAgentRounds as A}from"./framework/conversation-runner.js";import{describeStopReason as O,isRetryableStopReason as d,modelStopReason as l}from"./framework/model-stop-reason.js";import{currentTurnContext as D,currentTurnSignal as G,withTurnContext as I}from"./framework/turn-context.js";import{GraphStateSupport as h}from"./framework/graph-state-support.js";import{GRAPH_END_NODE as U,createGraphStateAnnotation as F}from"./framework/graph-state.js";import{GraphRegistry as Y}from"./framework/graph-registry.js";import{GraphEngine as H}from"./framework/graph-engine.js";import{ConfigManager as B}from"./framework/config-manager.js";import{StateGraphExt as b}from"./framework/state-graph-ext.js";import{TerminateSessionNode as W}from"./framework/terminate-session.node.js";import{SessionLogError as q,SessionLogWarning as X,createSessionLogs as j,withSessionLogs as J}from"./framework/session-log.js";import{ProviderFileManager as Q}from"./framework/llm-file.js";import{SessionManager as $,SessionTurnError as ee,SESSION_BUSY as oe,SESSION_CONFLICT as re,SESSION_COMPLETED as te,SESSION_DOCUMENT_VERSION as ne,MemorySessionDocumentContainer as se,sessionTurnLeaseMs as ae,sessionRevision as ie,isLiveSessionTurn as Se,matchesSessionWritePredicate as me}from"./framework/persistence/session-manager.js";import{MongoDbSessionDocumentContainer as Ee}from"./framework/persistence/mongodb-session-document.container.js";import{SqliteSessionDocumentContainer as Le}from"./framework/persistence/sqlite-session-document.container.js";import{CosmosSessionDocumentContainer as Te}from"./framework/persistence/cosmos-session-document.container.js";import{mergeNodeStates as fe}from"./framework/node-state.js";import{LangChainLlmGateway as ge}from"./framework/langchain-llm-gateway.js";import{ModelProvider as Ae}from"./framework/model-provider.js";import{langChainModelInitialization as Oe}from"./framework/langchain-provider.adapter.js";import{GRAPH_LLM_PROVIDERS as le,GRAPH_LLM_FAMILIES as ue,GRAPH_LLM_CAPABILITIES as De,BUILT_IN_MODEL_CATALOG as Ge,GraphLlm as Ie,ModelCatalog as Pe,ModelProviderRegistry as he}from"./framework/graph-llm.config.js";import{addTokenUsage as Ue,emptyTokenUsage as Fe,modelExecution as ye,normalizeTokenUsage as Ye,tokenUsageFromMessage as ve}from"./framework/token-usage.js";export{Ge as BUILT_IN_MODEL_CATALOG,r as BaseGraph,B as ConfigManager,m as ConversationNode,_ as ConversationRunner,Te as CosmosSessionDocumentContainer,T as DEFAULT_CONVERSATION_POLICY,R as DEFAULT_EMPTY_HISTORY_SEED,f as DEFAULT_EMPTY_RESPONSE_RECOVERY,M as DEFAULT_MAX_AGENT_ROUNDS,g as EmptyModelResponseError,U as GRAPH_END_NODE,De as GRAPH_LLM_CAPABILITIES,ue as GRAPH_LLM_FAMILIES,le as GRAPH_LLM_PROVIDERS,n as GRAPH_NODE_CLASS,H as GraphEngine,Ie as GraphLlm,s as GraphNode,a as GraphNodeRuntime,Y as GraphRegistry,h as GraphStateSupport,E as LLM_GATEWAY_FACTORY,ge as LangChainLlmGateway,se as MemorySessionDocumentContainer,Pe as ModelCatalog,Ae as ModelProvider,he as ModelProviderRegistry,Ee as MongoDbSessionDocumentContainer,Q as ProviderFileManager,oe as SESSION_BUSY,te as SESSION_COMPLETED,re as SESSION_CONFLICT,ne as SESSION_DOCUMENT_VERSION,q as SessionLogError,X as SessionLogWarning,$ as SessionManager,ee as SessionTurnError,Le as SqliteSessionDocumentContainer,b as StateGraphExt,W as TerminateSessionNode,i as Tool,Ue as addTokenUsage,C as assertEmptyResponseRetries,x as assertLlmTimeoutMs,A as assertMaxAgentRounds,F as createGraphStateAnnotation,j as createSessionLogs,D as currentTurnContext,G as currentTurnSignal,O as describeStopReason,Fe as emptyTokenUsage,Se as isLiveSessionTurn,d as isRetryableStopReason,Oe as langChainModelInitialization,me as matchesSessionWritePredicate,fe as mergeNodeStates,ye as modelExecution,l as modelStopReason,Ye as normalizeTokenUsage,ie as sessionRevision,ae as sessionTurnLeaseMs,ve as tokenUsageFromMessage,J as withSessionLogs,I as withTurnContext};
@@ -0,0 +1 @@
1
+ var d=Object.defineProperty;var h=(a,t)=>d(a,"name",{value:t,configurable:!0});import{AIMessage as c}from"@langchain/core/messages";import{ModelCatalog as l}from"../framework/graph-llm.config.js";import{modelExecution as m}from"../framework/token-usage.js";const p=l.model("scripted:scripted-model",{retries:0,temperature:0}),g={input_tokens:10,output_tokens:4,thinking_tokens:1,tool_input_tokens:2,cached_input_tokens:3,total_tokens:14};class k{static{h(this,"ScriptedGateway")}turns=[];consumed=0;calls=[];text(t){return this.turns.push({kind:"text",text:t}),this}callsTool(t,e={},s=`${t}-${String(this.turns.length+1)}`){return this.turns.push({kind:"message",message:new c({content:"",tool_calls:[{id:s,name:t,args:e,type:"tool_call"}]})}),this}callsTools(t){return this.turns.push({kind:"message",message:new c({content:"",tool_calls:t.map((e,s)=>({id:e.id??`${e.name}-${String(s+1)}`,name:e.name,args:e.args??{},type:"tool_call"}))})}),this}structuredResult(t){return this.turns.push({kind:"object",value:t}),this}toolDecision(t){return this.turns.push({kind:"tool",call:t}),this}empty(t){return this.turns.push({kind:"message",message:new c({content:"",...t===void 0?{}:{response_metadata:{finish_reason:t}}})}),this}fail(t){return this.turns.push({kind:"failure",error:typeof t=="string"?new Error(t):t}),this}repeat(t,e){for(let s=0;s<t;s+=1)e(this);return this}get drained(){return this.consumed>=this.turns.length}get remaining(){return Math.max(0,this.turns.length-this.consumed)}async structured(t,e,s,r,u,i,o){this.record({method:"structured",systemPrompt:e,history:i??[],tools:[r],llmConfig:u,callOptions:o});const n=this.take(`structured('${r}')`,s);if(n.kind==="object")return this.result(n.value,u);if(n.kind==="text")return this.result(JSON.parse(n.text),u);throw this.mismatch(`structured('${r}')`,n)}async generate(t,e,s,r){return this.record({method:"generate",systemPrompt:t,history:[],tools:[],llmConfig:s,callOptions:r}),this.result(this.takeText("generate",e),s)}async respond(t,e,s,r){return this.record({method:"respond",systemPrompt:t,history:e,tools:[],llmConfig:s,callOptions:r}),this.result(this.takeText("respond",t),s)}async agent(t,e,s,r,u){this.record({method:"agent",systemPrompt:t,history:e,tools:s.map(({name:o})=>o),llmConfig:r,callOptions:u});const i=this.take("agent",t);if(i.kind==="message")return this.result(i.message,r);if(i.kind==="text")return this.result(new c(i.text),r);throw this.mismatch("agent",i)}async toolCall(t,e,s,r,u,i){this.record({method:"toolCall",systemPrompt:t,history:u??[],tools:s.map(({name:n})=>n),llmConfig:r,callOptions:i});const o=this.take("toolCall",e);if(o.kind==="tool")return this.result(o.call,r);if(o.kind==="message"){const[n]=o.message.tool_calls??[];return this.result(n?{name:n.name,args:n.args}:void 0,r)}throw this.mismatch("toolCall",o)}record(t){this.calls.push(t)}takeText(t,e){const s=this.take(t,e);if(s.kind==="text")return s.text;if(s.kind==="message")return w(s.message);throw this.mismatch(t,s)}take(t,e){const s=this.turns[this.consumed];if(!s)throw new Error(`ScriptedGateway ran out of turns: ${t} was call ${String(this.consumed+1)} but only ${String(this.turns.length)} were queued. Unanswered request: ${x(e)}`);if(this.consumed+=1,s.kind==="failure")throw s.error;return s}mismatch(t,e){return new Error(`ScriptedGateway turn ${String(this.consumed)} is a '${e.kind}' turn, which ${t} cannot return.`)}result(t,e){return{value:t,usage:{...g},execution:m(e??p)}}}function S(){return new k}h(S,"scriptedGateway");function w(a){const{content:t}=a;return typeof t=="string"?t:t.map(e=>typeof e=="object"&&e&&"text"in e?String(e.text):"").join("")}h(w,"messageText");function x(a){const t=a.replace(/\s+/g," ").trim();return t.length>120?`${t.slice(0,120)}\u2026`:t}h(x,"summarize");export{p as SCRIPTED_MODEL,g as SCRIPTED_TOKEN_USAGE,k as ScriptedGateway,S as scriptedGateway};
@@ -0,0 +1 @@
1
+ var y=Object.defineProperty;var t=(n,s)=>y(n,"name",{value:s,configurable:!0});import{GraphEngine as f}from"../framework/graph-engine.js";import{SessionManager as h}from"../framework/persistence/session-manager.js";function b(n){const s=n.sessionManager??new h,{gateway:d}=n,g=new f({sessionManager:s,...d?{llmGatewayFactory:t(()=>d,"llmGatewayFactory")}:{}}).registerGraph([n.graph]),[a]=g.getGraphs();if(!a)throw new Error("The harness graph did not register.");const c=n.sessionId??`harness-${a}`,u=t(()=>s.getSession(c),"document");return{session:c,engine:g,document:u,async send(m,i){const r=await g.run({graphName:a,sessionId:c,...m===void 0?{}:{userMessage:m},...i?.config?{config:i.config}:{},...i?.signal?{signal:i.signal}:{}}),e=await u(),p=e?s.restoreSessionDocument(e,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}:{},...e?{document:e}:{},...p?{state:p}:{},...e?.graph.currentNode===void 0?{}:{currentNode:e.graph.currentNode},warnings:e?.warnings??[],errors:e?.errors??[]}},close:t(()=>s.close(),"close")}}t(b,"createTurnHarness");export{b as createTurnHarness};
@@ -0,0 +1 @@
1
+ import{ScriptedGateway as t,SCRIPTED_MODEL as a,SCRIPTED_TOKEN_USAGE as E,scriptedGateway as o}from"./testing/scripted-gateway.js";import{createTurnHarness as S}from"./testing/turn-harness.js";export{a as SCRIPTED_MODEL,E as SCRIPTED_TOKEN_USAGE,t as ScriptedGateway,S as createTurnHarness,o as scriptedGateway};