10xgraph-client 0.6.0 → 1.0.0-rc.2

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 (149) hide show
  1. package/CHANGELOG.md +207 -0
  2. package/README.md +11 -5
  3. package/dist/agent.d.ts +17 -5
  4. package/dist/agent.d.ts.map +1 -1
  5. package/dist/cjs/agent.d.ts +33 -0
  6. package/dist/cjs/client.d.ts +533 -0
  7. package/dist/cjs/compat.d.ts +27 -0
  8. package/dist/cjs/endpoints/addThreadMessages.d.ts +25 -0
  9. package/dist/cjs/endpoints/clearThreadState.d.ts +14 -0
  10. package/dist/cjs/endpoints/deleteFile.d.ts +13 -0
  11. package/dist/cjs/endpoints/deleteMemory.d.ts +18 -0
  12. package/dist/cjs/endpoints/deleteThread.d.ts +18 -0
  13. package/dist/cjs/endpoints/deleteThreadMessage.d.ts +19 -0
  14. package/dist/cjs/endpoints/files.d.ts +115 -0
  15. package/dist/cjs/endpoints/fixGraph.d.ts +33 -0
  16. package/dist/cjs/endpoints/forgetMemories.d.ts +21 -0
  17. package/dist/cjs/endpoints/getMemory.d.ts +18 -0
  18. package/dist/cjs/endpoints/graph.d.ts +50 -0
  19. package/dist/cjs/endpoints/graphTools.d.ts +31 -0
  20. package/dist/cjs/endpoints/invoke.d.ts +66 -0
  21. package/dist/cjs/endpoints/listMemories.d.ts +24 -0
  22. package/dist/cjs/endpoints/metadata.d.ts +5 -0
  23. package/dist/cjs/endpoints/observability.d.ts +111 -0
  24. package/dist/cjs/endpoints/ping.d.ts +9 -0
  25. package/dist/cjs/endpoints/realtime.d.ts +154 -0
  26. package/dist/cjs/endpoints/searchMemory.d.ts +56 -0
  27. package/dist/cjs/endpoints/stateSchema.d.ts +49 -0
  28. package/dist/cjs/endpoints/stopGraph.d.ts +35 -0
  29. package/dist/cjs/endpoints/storeMemory.d.ts +32 -0
  30. package/dist/cjs/endpoints/stream.d.ts +67 -0
  31. package/dist/cjs/endpoints/threadDetails.d.ts +18 -0
  32. package/dist/cjs/endpoints/threadMessage.d.ts +16 -0
  33. package/dist/cjs/endpoints/threadMessages.d.ts +28 -0
  34. package/dist/cjs/endpoints/threadState.d.ts +13 -0
  35. package/dist/cjs/endpoints/threads.d.ts +35 -0
  36. package/dist/cjs/endpoints/updateMemory.d.ts +20 -0
  37. package/dist/cjs/endpoints/updateThreadMessageFeedback.d.ts +19 -0
  38. package/dist/cjs/endpoints/updateThreadState.d.ts +22 -0
  39. package/dist/cjs/endpoints/wsStream.d.ts +34 -0
  40. package/dist/cjs/errors.d.ts +212 -0
  41. package/dist/cjs/index.d.ts +41 -0
  42. package/dist/cjs/interrupt.d.ts +45 -0
  43. package/dist/cjs/message.d.ts +173 -0
  44. package/dist/cjs/package.json +1 -0
  45. package/dist/cjs/request.d.ts +60 -0
  46. package/dist/cjs/tools.d.ts +80 -0
  47. package/dist/cjs/ws.d.ts +47 -0
  48. package/dist/client.d.ts +95 -40
  49. package/dist/client.d.ts.map +1 -1
  50. package/dist/endpoints/addThreadMessages.d.ts +4 -0
  51. package/dist/endpoints/addThreadMessages.d.ts.map +1 -1
  52. package/dist/endpoints/clearThreadState.d.ts.map +1 -1
  53. package/dist/endpoints/deleteFile.d.ts +14 -0
  54. package/dist/endpoints/deleteFile.d.ts.map +1 -0
  55. package/dist/endpoints/deleteMemory.d.ts.map +1 -1
  56. package/dist/endpoints/deleteThread.d.ts.map +1 -1
  57. package/dist/endpoints/deleteThreadMessage.d.ts.map +1 -1
  58. package/dist/endpoints/files.d.ts +33 -0
  59. package/dist/endpoints/files.d.ts.map +1 -1
  60. package/dist/endpoints/fixGraph.d.ts +8 -3
  61. package/dist/endpoints/fixGraph.d.ts.map +1 -1
  62. package/dist/endpoints/forgetMemories.d.ts.map +1 -1
  63. package/dist/endpoints/getMemory.d.ts.map +1 -1
  64. package/dist/endpoints/graph.d.ts +20 -8
  65. package/dist/endpoints/graph.d.ts.map +1 -1
  66. package/dist/endpoints/graphTools.d.ts.map +1 -1
  67. package/dist/endpoints/invoke.d.ts +8 -0
  68. package/dist/endpoints/invoke.d.ts.map +1 -1
  69. package/dist/endpoints/listMemories.d.ts +6 -0
  70. package/dist/endpoints/listMemories.d.ts.map +1 -1
  71. package/dist/endpoints/observability.d.ts +54 -0
  72. package/dist/endpoints/observability.d.ts.map +1 -1
  73. package/dist/endpoints/ping.d.ts.map +1 -1
  74. package/dist/endpoints/realtime.d.ts +25 -4
  75. package/dist/endpoints/realtime.d.ts.map +1 -1
  76. package/dist/endpoints/searchMemory.d.ts.map +1 -1
  77. package/dist/endpoints/stateSchema.d.ts.map +1 -1
  78. package/dist/endpoints/stopGraph.d.ts +13 -3
  79. package/dist/endpoints/stopGraph.d.ts.map +1 -1
  80. package/dist/endpoints/storeMemory.d.ts.map +1 -1
  81. package/dist/endpoints/stream.d.ts +8 -0
  82. package/dist/endpoints/stream.d.ts.map +1 -1
  83. package/dist/endpoints/threadDetails.d.ts.map +1 -1
  84. package/dist/endpoints/threadMessage.d.ts.map +1 -1
  85. package/dist/endpoints/threadMessages.d.ts +6 -0
  86. package/dist/endpoints/threadMessages.d.ts.map +1 -1
  87. package/dist/endpoints/threadState.d.ts.map +1 -1
  88. package/dist/endpoints/threads.d.ts +6 -0
  89. package/dist/endpoints/threads.d.ts.map +1 -1
  90. package/dist/endpoints/updateMemory.d.ts.map +1 -1
  91. package/dist/endpoints/updateThreadMessageFeedback.d.ts +20 -0
  92. package/dist/endpoints/updateThreadMessageFeedback.d.ts.map +1 -0
  93. package/dist/endpoints/updateThreadState.d.ts +6 -1
  94. package/dist/endpoints/updateThreadState.d.ts.map +1 -1
  95. package/dist/endpoints/wsStream.d.ts +2 -0
  96. package/dist/endpoints/wsStream.d.ts.map +1 -1
  97. package/dist/errors.d.ts +60 -2
  98. package/dist/errors.d.ts.map +1 -1
  99. package/dist/index.cjs +3 -3
  100. package/dist/index.cjs.map +1 -1
  101. package/dist/index.d.ts +3 -0
  102. package/dist/index.d.ts.map +1 -1
  103. package/dist/index.js +1742 -1217
  104. package/dist/index.js.map +1 -1
  105. package/dist/interrupt.d.ts +46 -0
  106. package/dist/interrupt.d.ts.map +1 -0
  107. package/dist/request.d.ts +28 -0
  108. package/dist/request.d.ts.map +1 -1
  109. package/dist/tools.d.ts +14 -0
  110. package/dist/tools.d.ts.map +1 -1
  111. package/package.json +11 -6
  112. package/src/agent.ts +17 -4
  113. package/src/client.ts +248 -128
  114. package/src/endpoints/addThreadMessages.ts +15 -10
  115. package/src/endpoints/clearThreadState.ts +19 -20
  116. package/src/endpoints/deleteFile.ts +65 -0
  117. package/src/endpoints/deleteMemory.ts +9 -13
  118. package/src/endpoints/deleteThread.ts +9 -13
  119. package/src/endpoints/deleteThreadMessage.ts +9 -13
  120. package/src/endpoints/files.ts +164 -131
  121. package/src/endpoints/fixGraph.ts +15 -16
  122. package/src/endpoints/forgetMemories.ts +44 -60
  123. package/src/endpoints/getMemory.ts +9 -9
  124. package/src/endpoints/graph.ts +28 -21
  125. package/src/endpoints/graphTools.ts +7 -13
  126. package/src/endpoints/invoke.ts +105 -84
  127. package/src/endpoints/listMemories.ts +18 -13
  128. package/src/endpoints/observability.ts +77 -34
  129. package/src/endpoints/ping.ts +7 -13
  130. package/src/endpoints/realtime.ts +101 -39
  131. package/src/endpoints/searchMemory.ts +19 -13
  132. package/src/endpoints/stateSchema.ts +7 -13
  133. package/src/endpoints/stopGraph.ts +20 -16
  134. package/src/endpoints/storeMemory.ts +7 -8
  135. package/src/endpoints/stream.ts +179 -61
  136. package/src/endpoints/threadDetails.ts +9 -14
  137. package/src/endpoints/threadMessage.ts +9 -9
  138. package/src/endpoints/threadMessages.ts +15 -9
  139. package/src/endpoints/threadState.ts +19 -20
  140. package/src/endpoints/threads.ts +13 -12
  141. package/src/endpoints/updateMemory.ts +9 -9
  142. package/src/endpoints/updateThreadMessageFeedback.ts +80 -0
  143. package/src/endpoints/updateThreadState.ts +28 -22
  144. package/src/endpoints/wsStream.ts +167 -42
  145. package/src/errors.ts +332 -93
  146. package/src/index.ts +9 -0
  147. package/src/interrupt.ts +60 -0
  148. package/src/request.ts +134 -0
  149. package/src/tools.ts +95 -0
package/dist/index.cjs CHANGED
@@ -1,6 +1,6 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});class b{constructor(e="url",r,o,s,n,a,i,c,d,h,l,u){this.kind="url",this.kind=e,this.url=r,this.file_id=o,this.data_base64=s,this.mime_type=n,this.size_bytes=a,this.sha256=i,this.filename=c,this.width=d,this.height=h,this.duration_ms=l,this.page=u}}class Be{constructor(e,r,o,s,n){this.url=e,this.file_id=r,this.page=o,this.index=s,this.title=n}}class S{constructor(e="",r=[]){this.type="text",this.text="",this.annotations=[],this.text=e,this.annotations=r}}class R{constructor(e=new b,r,o){this.type="image",this.media=new b,this.media=e,this.alt_text=r,this.bbox=o}}class F{constructor(e=new b,r,o,s){this.type="audio",this.media=new b,this.media=e,this.transcript=r,this.sample_rate=o,this.channels=s}}class L{constructor(e=new b,r){this.type="video",this.media=new b,this.media=e,this.thumbnail=r}}class H{constructor(e=new b,r,o){this.type="document",this.media=new b,this.media=e,this.pages=r,this.excerpt=o}}class Fe{constructor(e="",r,o){this.type="data",this.mime_type="",this.mime_type=e,this.data_base64=r,this.media=o}}class Le{constructor(e="",r="",o={},s){this.type="tool_call",this.id="",this.name="",this.args={},this.id=e,this.name=r,this.args=o,this.tool_type=s}}class He{constructor(e="",r="",o={},s="remote"){this.type="remote_tool_call",this.id="",this.name="",this.args={},this.tool_type="remote",this.id=e,this.name=r,this.args=o,this.tool_type=s}}class G{constructor(e){this.type="tool_result",this.call_id="",this.is_error=!1,this.call_id=e.call_id,this.output=e.output,this.status=e.status,this.is_error=e.is_error}}class Je{constructor(e="",r){this.type="reasoning",this.summary="",this.summary=e,this.details=r}}class We{constructor(e="citation",r=[],o){this.type="annotation",this.kind="citation",this.refs=[],this.kind=e,this.refs=r,this.spans=o}}class ze{constructor(e="",r,o){this.type="error",this.message="",this.message=e,this.code=r,this.data=o}}class Ve{constructor(){this.completion_tokens=0,this.prompt_tokens=0,this.total_tokens=0,this.reasoning_tokens=0,this.cache_creation_input_tokens=0,this.cache_read_input_tokens=0,this.image_tokens=0,this.audio_tokens=0}}class C{constructor(e,r,o=null){this.message_id=null,this.content=[],this.delta=!1,this.timestamp=Date.now(),this.metadata={},this.role=e,this.content=r,this.message_id=o}static text_message(e,r="user",o=null){return new C(r,[{type:"text",text:e}],o)}static tool_message(e,r=null,o={}){const s=new C("tool",e,r);return s.metadata=o,s}text(){return this.content.map(e=>{if(e.type==="text")return e.text;if(e.type==="tool_result"){const r=e.output;return typeof r=="string"?r:JSON.stringify(r)}return""}).join("")}attach_media(e,r){let o;switch(r){case"image":o={type:"image",media:e};break;case"audio":o={type:"audio",media:e};break;case"video":o={type:"video",media:e};break;case"document":o={type:"document",media:e};break;default:throw new Error(`Unsupported media type: ${r}`)}this.content.push(o)}static withImage(e,r,o="user"){return new C(o,[new S(e),new R(new b("url",r,void 0,void 0,void 0))])}static withFile(e,r,o,s="user"){const n=new b("file_id",void 0,r,void 0,o),a=o?.startsWith("image/"),i=o?.startsWith("audio/"),c=o?.startsWith("video/");let d;return a?d=new R(n):i?d=new F(n):c?d=new L(n):d=new H(n),new C(s,[new S(e),d])}static multimodal(e,r="user"){return new C(r,e)}}function J(t){const e=t??{},{type:r,properties:o,required:s,...n}=e;return{...n,type:r??"object",properties:o??{},required:s??[]}}class W{constructor(e=[]){this.tools=new Map,this.toolsByNode=new Map;for(const r of e)this.tools.set(r.name,r),r.node&&(this.toolsByNode.has(r.node)||this.toolsByNode.set(r.node,new Map),this.toolsByNode.get(r.node).set(r.name,r))}registerTool(e){const r=async o=>e.handler(o);Object.defineProperty(r,"name",{value:e.name,writable:!0,configurable:!0}),Object.defineProperty(r,"description",{value:e.description,writable:!0,configurable:!0}),Object.defineProperty(r,"parameters",{value:e.parameters,writable:!0,configurable:!0}),Object.defineProperty(r,"node",{value:e.node,writable:!0,configurable:!0}),this.tools.set(e.name,r),e.node&&(this.toolsByNode.has(e.node)||this.toolsByNode.set(e.node,new Map),this.toolsByNode.get(e.node).set(e.name,r))}getToolsForNode(e){const r=this.toolsByNode.get(e);return r?Array.from(r.values()):[]}all_tools(){const e=[];for(const[r,o]of this.tools){const s={type:"function",function:{name:r,description:o.description||`Execute ${r}`,parameters:J(o.parameters)}};e.push(s)}return e}async executeToolCalls(e){const r=[];for(const s of e)if(s.content)for(const n of s.content)n.type==="remote_tool_call"&&r.push(n);const o=[];for(const s of r){const n=s.name;if(this.tools.has(n)){const a=this.tools.get(n);try{const i=await a(s.args),c=new G({call_id:s.id,output:i,status:"completed",is_error:!1});o.push(C.tool_message([c]))}catch(i){const c=i instanceof Error?i.message:String(i),d=new G({call_id:s.id,output:{error:c},status:"failed",is_error:!0});o.push(C.tool_message([d]))}}else{const a=new G({call_id:s.id,output:{error:`Tool '${n}' not found`},status:"failed",is_error:!0});o.push(C.tool_message([a]))}}return o}}class g extends Error{constructor(e,r,o,s,n,a=[],i,c,d,h){super(e),this.name="TenxGraphError",this.statusCode=r,this.errorCode=o,this.requestId=s,this.timestamp=n,this.details=a,this.context=i,this.endpoint=c,this.method=d,this.recoverySuggestion=h;const l=Error.captureStackTrace;l&&l(this,this.constructor)}getUserMessage(){return this.recoverySuggestion?`${this.message}
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});class O{constructor(e="url",r,o,s,n,a,i,c,l,y,g,b){this.kind="url",this.kind=e,this.url=r,this.file_id=o,this.data_base64=s,this.mime_type=n,this.size_bytes=a,this.sha256=i,this.filename=c,this.width=l,this.height=y,this.duration_ms=g,this.page=b}}class yt{constructor(e,r,o,s,n){this.url=e,this.file_id=r,this.page=o,this.index=s,this.title=n}}class K{constructor(e="",r=[]){this.type="text",this.text="",this.annotations=[],this.text=e,this.annotations=r}}class Z{constructor(e=new O,r,o){this.type="image",this.media=new O,this.media=e,this.alt_text=r,this.bbox=o}}class ne{constructor(e=new O,r,o,s){this.type="audio",this.media=new O,this.media=e,this.transcript=r,this.sample_rate=o,this.channels=s}}class ae{constructor(e=new O,r){this.type="video",this.media=new O,this.media=e,this.thumbnail=r}}class ie{constructor(e=new O,r,o){this.type="document",this.media=new O,this.media=e,this.pages=r,this.excerpt=o}}class Tt{constructor(e="",r,o){this.type="data",this.mime_type="",this.mime_type=e,this.data_base64=r,this.media=o}}class bt{constructor(e="",r="",o={},s){this.type="tool_call",this.id="",this.name="",this.args={},this.id=e,this.name=r,this.args=o,this.tool_type=s}}class wt{constructor(e="",r="",o={},s="remote"){this.type="remote_tool_call",this.id="",this.name="",this.args={},this.tool_type="remote",this.id=e,this.name=r,this.args=o,this.tool_type=s}}class B{constructor(e){this.type="tool_result",this.call_id="",this.is_error=!1,this.call_id=e.call_id,this.output=e.output,this.status=e.status,this.is_error=e.is_error}}class Et{constructor(e="",r){this.type="reasoning",this.summary="",this.summary=e,this.details=r}}class _t{constructor(e="citation",r=[],o){this.type="annotation",this.kind="citation",this.refs=[],this.kind=e,this.refs=r,this.spans=o}}class Ct{constructor(e="",r,o){this.type="error",this.message="",this.message=e,this.code=r,this.data=o}}class St{constructor(){this.completion_tokens=0,this.prompt_tokens=0,this.total_tokens=0,this.reasoning_tokens=0,this.cache_creation_input_tokens=0,this.cache_read_input_tokens=0,this.image_tokens=0,this.audio_tokens=0}}class A{constructor(e,r,o=null){this.message_id=null,this.content=[],this.delta=!1,this.timestamp=Date.now(),this.metadata={},this.role=e,this.content=r,this.message_id=o}static text_message(e,r="user",o=null){return new A(r,[{type:"text",text:e}],o)}static tool_message(e,r=null,o={}){const s=new A("tool",e,r);return s.metadata=o,s}text(){return this.content.map(e=>{if(e.type==="text")return e.text;if(e.type==="tool_result"){const r=e.output;return typeof r=="string"?r:JSON.stringify(r)}return""}).join("")}attach_media(e,r){let o;switch(r){case"image":o={type:"image",media:e};break;case"audio":o={type:"audio",media:e};break;case"video":o={type:"video",media:e};break;case"document":o={type:"document",media:e};break;default:throw new Error(`Unsupported media type: ${r}`)}this.content.push(o)}static withImage(e,r,o="user"){return new A(o,[new K(e),new Z(new O("url",r,void 0,void 0,void 0))])}static withFile(e,r,o,s="user"){const n=new O("file_id",void 0,r,void 0,o),a=o?.startsWith("image/"),i=o?.startsWith("audio/"),c=o?.startsWith("video/");let l;return a?l=new Z(n):i?l=new ne(n):c?l=new ae(n):l=new ie(n),new A(s,[new K(e),l])}static multimodal(e,r="user"){return new A(r,e)}}function ce(t){const e=t??{},{type:r,properties:o,required:s,...n}=e;return{...n,type:r??"object",properties:o??{},required:s??[]}}const le=1024*1024;function de(t,e){if(!e)return null;if(t===null||typeof t!="object"||Array.isArray(t))return"arguments must be an object";const r=t;for(const s of e.required??[])if(!(s in r))return`missing required argument '${s}'`;const o=e.properties??{};if(e.additionalProperties===!1){for(const s of Object.keys(r))if(!(s in o))return`unexpected argument '${s}'`}for(const[s,n]of Object.entries(o)){const a=r[s],i=n?.type;if(a===void 0||typeof i!="string")continue;if(!(i==="string"?typeof a=="string":i==="number"?typeof a=="number":i==="integer"?Number.isInteger(a):i==="boolean"?typeof a=="boolean":i==="array"?Array.isArray(a):i==="object"?a!==null&&typeof a=="object"&&!Array.isArray(a):!0))return`argument '${s}' must be of type ${i}`}return null}class he{constructor(e=[]){this.tools=new Map,this.toolsByNode=new Map;for(const r of e)this.tools.set(r.name,r),r.node&&(this.toolsByNode.has(r.node)||this.toolsByNode.set(r.node,new Map),this.toolsByNode.get(r.node).set(r.name,r))}registerTool(e){const r=async o=>e.handler(o);Object.defineProperty(r,"name",{value:e.name,writable:!0,configurable:!0}),Object.defineProperty(r,"description",{value:e.description,writable:!0,configurable:!0}),Object.defineProperty(r,"parameters",{value:e.parameters,writable:!0,configurable:!0}),Object.defineProperty(r,"validate",{value:e.validate,writable:!0,configurable:!0}),Object.defineProperty(r,"maxArgsBytes",{value:e.maxArgsBytes,writable:!0,configurable:!0}),Object.defineProperty(r,"node",{value:e.node,writable:!0,configurable:!0}),this.tools.set(e.name,r),e.node&&(this.toolsByNode.has(e.node)||this.toolsByNode.set(e.node,new Map),this.toolsByNode.get(e.node).set(e.name,r))}getToolsForNode(e){const r=this.toolsByNode.get(e);return r?Array.from(r.values()):[]}all_tools(){const e=[];for(const[r,o]of this.tools){const s={type:"function",function:{name:r,description:o.description||`Execute ${r}`,parameters:ce(o.parameters)}};e.push(s)}return e}async executeToolCalls(e){const r=[];for(const a of e)if(a.content)for(const i of a.content)i.type==="remote_tool_call"&&r.push(i);const o=[],s=new Set,n=(a,i)=>A.tool_message([new B({call_id:a,output:{error:i},status:"failed",is_error:!0})]);for(const a of r){const i=a.name;if(a.id&&s.has(a.id)){o.push(n(a.id,`Duplicate tool call id '${a.id}' rejected`));continue}if(a.id&&s.add(a.id),this.tools.has(i)){const c=this.tools.get(i);try{const l=c.maxArgsBytes??le;if((JSON.stringify(a.args??null)?.length??0)>l){o.push(n(a.id,`Arguments for '${i}' exceed ${l} bytes`));continue}const g=de(a.args??{},c.parameters);if(g){o.push(n(a.id,`Invalid arguments for '${i}': ${g}`));continue}if(c.validate&&await c.validate(a.args)===!1){o.push(n(a.id,`Arguments for '${i}' were rejected`));continue}const b=await c(a.args),R=new B({call_id:a.id,output:b,status:"completed",is_error:!1});o.push(A.tool_message([R]))}catch(l){const y=l instanceof Error?l.message:String(l),g=new B({call_id:a.id,output:{error:y},status:"failed",is_error:!0});o.push(A.tool_message([g]))}}else{const c=new B({call_id:a.id,output:{error:`Tool '${i}' not found`},status:"failed",is_error:!0});o.push(A.tool_message([c]))}}return o}}class T extends Error{constructor(e,r,o,s,n,a=[],i,c,l,y){super(e),this.name="TenxGraphError",this.statusCode=r,this.errorCode=o,this.requestId=s,this.timestamp=n,this.details=a,this.context=i,this.endpoint=c,this.method=l,this.recoverySuggestion=y;const g=Error.captureStackTrace;g&&g(this,this.constructor)}getUserMessage(){return this.recoverySuggestion?`${this.message}
2
2
 
3
- Suggestion: ${this.recoverySuggestion}`:this.message}toJSON(){return{name:this.name,message:this.message,statusCode:this.statusCode,errorCode:this.errorCode,requestId:this.requestId,timestamp:this.timestamp,details:this.details,context:this.context,endpoint:this.endpoint,method:this.method,recoverySuggestion:this.recoverySuggestion,stack:this.stack}}}class v extends g{constructor(e,r,o,s=[]){super(e,400,"BAD_REQUEST",r,o,s),this.name="BadRequestError"}}class k extends g{constructor(e,r,o,s=[]){super(e,401,"AUTHENTICATION_FAILED",r,o,s),this.name="AuthenticationError"}}class A extends g{constructor(e,r,o,s=[]){super(e,403,"PERMISSION_ERROR",r,o,s),this.name="PermissionError"}}class $ extends g{constructor(e,r,o,s=[]){super(e,404,"RESOURCE_NOT_FOUND",r,o,s),this.name="NotFoundError"}}class I extends g{constructor(e,r,o,s=[]){super(e,422,"VALIDATION_ERROR",r,o,s),this.name="ValidationError"}}class O extends g{constructor(e,r,o,s="INTERNAL_SERVER_ERROR",n=[],a=500){super(e,a,s,r,o,n),this.name="ServerError"}}class z extends g{constructor(e,r,o,s=[],n){super(e,500,"GRAPH_ERROR",r,o,s,n,void 0,void 0,"Check your graph configuration and ensure all nodes are properly connected."),this.name="GraphError"}}class V extends g{constructor(e,r,o,s=[],n,a){super(e,500,"NODE_ERROR",r,o,s,n,void 0,void 0,"Review the node implementation and ensure all required inputs are provided."),this.name="NodeError",this.nodeName=a}}class Y extends g{constructor(e,r,o,s=[],n,a){super(e,500,"GRAPH_RECURSION_ERROR",r,o,s,n,void 0,void 0,"Consider increasing the recursion_limit parameter or check for infinite loops in your graph."),this.name="GraphRecursionError",this.recursionLimit=a}}class K extends g{constructor(e,r,o,s=[],n){super(e,500,"STORAGE_ERROR",r,o,s,n,void 0,void 0,"Check your storage configuration and ensure the storage backend is accessible."),this.name="StorageError"}}class Z extends g{constructor(e,r,o,s=[],n){super(e,503,"TRANSIENT_STORAGE_ERROR",r,o,s,n,void 0,void 0,"This is a temporary issue. Please retry your request after a short delay."),this.name="TransientStorageError"}}class Q extends g{constructor(e,r,o,s=[],n){super(e,500,"METRICS_ERROR",r,o,s,n,void 0,void 0,"Check your metrics configuration. This error typically doesn't affect core functionality."),this.name="MetricsError"}}class X extends g{constructor(e,r,o,s=[],n,a,i){super(e,422,"SCHEMA_VERSION_ERROR",r,o,s,n,void 0,void 0,"Update your client to match the server schema version or contact support."),this.name="SchemaVersionError",this.expectedVersion=a,this.actualVersion=i}}class q extends g{constructor(e,r,o,s=[],n){super(e,500,"SERIALIZATION_ERROR",r,o,s,n,void 0,void 0,"Ensure your data format is compatible with the API schema."),this.name="SerializationError"}}async function ee(t){try{const e=t.headers.get("content-type");return e&&e.includes("application/json")?await t.json():null}catch{return null}}async function p(t,e,r,o){const s=await ee(t);if(s){const{metadata:i,error:c}=s,d=c.message||e||`HTTP error ${t.status}`,h=i.request_id||"unknown",l=i.timestamp||new Date().toISOString(),u=c.details||[],T=c.code||"";if(T.startsWith("GRAPH_RECURSION"))return new Y(d,h,l,u);if(T.startsWith("GRAPH"))return new z(d,h,l,u);if(T.startsWith("NODE"))return new V(d,h,l,u);if(T.startsWith("TRANSIENT_STORAGE"))return new Z(d,h,l,u);if(T.startsWith("STORAGE"))return new K(d,h,l,u);if(T.startsWith("METRICS"))return new Q(d,h,l,u);if(T.startsWith("SCHEMA_VERSION"))return new X(d,h,l,u);if(T.startsWith("SERIALIZATION"))return new q(d,h,l,u);switch(t.status){case 400:return new v(d,h,l,u);case 401:return new k(d,h,l,u);case 403:return new A(d,h,l,u);case 404:return new $(d,h,l,u);case 422:return new I(d,h,l,u);case 500:case 502:case 503:case 504:return new O(d,h,l,T||"INTERNAL_SERVER_ERROR",u,t.status);default:return new g(d,t.status,T||"UNKNOWN_ERROR",h,l,u,void 0,r,o)}}const n=e||`HTTP error! status: ${t.status}`,a=new Date().toISOString();switch(t.status){case 400:return new v(n,"unknown",a);case 401:return new k(n,"unknown",a);case 403:return new A(n,"unknown",a);case 404:return new $(n,"unknown",a);case 422:return new I(n,"unknown",a);case 500:case 502:case 503:case 504:return new O(n,"unknown",a,"INTERNAL_SERVER_ERROR",[],t.status);default:return new g(n,t.status,"UNKNOWN_ERROR","unknown",a,[],void 0,r,o)}}function _(t,e,r){if(r!=null){for(const o of Object.keys(t))o.toLowerCase()===e.toLowerCase()&&delete t[o];t[e]=r}}function D(t,e){if(e){if(e instanceof Headers){e.forEach((r,o)=>{_(t,o,r)});return}if(Array.isArray(e)){for(const[r,o]of e)_(t,r,o);return}for(const[r,o]of Object.entries(e))o!==void 0&&_(t,r,String(o))}}function Ye(t,e){return Object.keys(t).some(r=>r.toLowerCase()===e.toLowerCase())}function Ke(t){const e=globalThis.Buffer;if(e)return e.from(t,"utf-8").toString("base64");if(typeof btoa=="function"){const r=new TextEncoder().encode(t);let o="";for(const s of r)o+=String.fromCharCode(s);return btoa(o)}throw new Error("Basic authentication is not supported in this runtime")}function Ze(t,e){if(!e)return;if(e.type==="bearer"){_(t,"Authorization",`Bearer ${e.token}`);return}if(e.type==="basic"){const o=Ke(`${e.username}:${e.password}`);_(t,"Authorization",`Basic ${o}`);return}const r=e.prefix?`${e.prefix} ${e.value}`:e.value;_(t,e.name,r)}function m(t,e){const r={};return D(r,e),D(r,t.headers),t.auth?Ze(r,t.auth):t.authToken&&!Ye(r,"Authorization")&&_(r,"Authorization",`Bearer ${t.authToken}`),r}function f(t){return t.credentials?{credentials:t.credentials}:{}}function Qe(t){return{type:"bearer",token:t}}function Xe(t,e){return{type:"basic",username:t,password:e}}function qe(t,e,r){return{type:"header",name:t,value:e,prefix:r}}async function te(t){try{t.debug&&console.debug("TenxGraphClient: Pinging server at",t.baseUrl);const e=new AbortController,r=setTimeout(()=>e.abort(),t.timeout),o=await fetch(`${t.baseUrl}/ping`,{method:"GET",headers:m(t,{"Content-Type":"application/json"}),...f(t),signal:e.signal});if(clearTimeout(r),!o.ok)throw console.warn(`TenxGraphClient: Ping failed with HTTP ${o.status}`),await p(o,"Ping request failed","/ping","GET");const s=await o.json();return t.debug&&console.info("TenxGraphClient: Ping successful",s),s}catch(e){throw t.debug&&console.debug("TenxGraphClient: Ping failed:",e),e.name==="AbortError"?(console.warn(`TenxGraphClient: Ping timeout after ${t.timeout}ms`),new Error(`Request timeout after ${t.timeout}ms`)):(console.error("TenxGraphClient: Ping failed:",e),e)}}async function re(t){try{t.debug&&console.debug("TenxGraphClient: Fetching graph from",t.baseUrl);const e=new AbortController,r=setTimeout(()=>e.abort(),t.timeout),o=await fetch(`${t.baseUrl}/v1/graph`,{method:"GET",headers:m(t,{"Content-Type":"application/json",accept:"application/json"}),...f(t),signal:e.signal});if(clearTimeout(r),!o.ok)throw console.warn(`TenxGraphClient: Graph fetch failed with HTTP ${o.status}`),await p(o,"Graph fetch failed","/v1/graph","GET");const s=await o.json();return t.debug&&console.info("TenxGraphClient: Graph fetch successful",s),s}catch(e){throw t.debug&&console.debug("TenxGraphClient: Graph fetch failed:",e),e.name==="AbortError"?(console.warn(`TenxGraphClient: Graph fetch timeout after ${t.timeout}ms`),new Error(`Request timeout after ${t.timeout}ms`)):(console.error("TenxGraphClient: Graph fetch failed:",e),e)}}async function oe(t){try{t.debug&&console.debug("TenxGraphClient: Fetching graph tools from",t.baseUrl);const e=new AbortController,r=setTimeout(()=>e.abort(),t.timeout),o=await fetch(`${t.baseUrl}/v1/graph/tools`,{method:"GET",headers:m(t,{"Content-Type":"application/json",accept:"application/json"}),...f(t),signal:e.signal});if(clearTimeout(r),!o.ok)throw console.warn(`TenxGraphClient: Graph tools fetch failed with HTTP ${o.status}`),await p(o,"Graph tools fetch failed","/v1/graph/tools","GET");const s=await o.json();return t.debug&&console.info("TenxGraphClient: Graph tools fetch successful",s),s}catch(e){throw t.debug&&console.debug("TenxGraphClient: Graph tools fetch failed:",e),e.name==="AbortError"?(console.warn(`TenxGraphClient: Graph tools fetch timeout after ${t.timeout}ms`),new Error(`Request timeout after ${t.timeout}ms`)):(console.error("TenxGraphClient: Graph tools fetch failed:",e),e)}}async function se(t,e,r){try{const o=new AbortController,s=setTimeout(()=>o.abort(),t.timeout),n=r?`?run_id=${encodeURIComponent(r)}`:"",a=await fetch(`${t.baseUrl}/v1/observability/${encodeURIComponent(e)}${n}`,{method:"GET",headers:m(t,{"Content-Type":"application/json",accept:"application/json"}),...f(t),signal:o.signal});if(clearTimeout(s),!a.ok)throw await p(a,"Observability fetch failed",`/v1/observability/${e}`,"GET");return await a.json()}catch(o){throw o.name==="AbortError"?new Error(`Request timeout after ${t.timeout}ms`):o}}async function ne(t){try{t.debug&&console.debug("TenxGraphClient: Fetching state schema from",t.baseUrl);const e=new AbortController,r=setTimeout(()=>e.abort(),t.timeout),o=await fetch(`${t.baseUrl}/v1/graph:StateSchema`,{method:"GET",headers:m(t,{"Content-Type":"application/json",accept:"application/json"}),...f(t),signal:e.signal});if(clearTimeout(r),!o.ok)throw console.warn(`TenxGraphClient: State schema fetch failed with HTTP ${o.status}`),await p(o,"State schema fetch failed","/v1/state_schema","GET");const s=await o.json();return t.debug&&console.info("TenxGraphClient: State schema fetch successful",s),s}catch(e){throw t.debug&&console.debug("TenxGraphClient: State schema fetch failed:",e),e.name==="AbortError"?(console.warn(`TenxGraphClient: State schema fetch timeout after ${t.timeout}ms`),new Error(`Request timeout after ${t.timeout}ms`)):(console.error("TenxGraphClient: State schema fetch failed:",e),e)}}async function ae(t,e){try{t.debug&&console.debug(`TenxGraphClient: Fetching thread state for thread ${e}`);const r=new AbortController,o=setTimeout(()=>r.abort(),t.timeout),s=await fetch(`${t.baseUrl}/v1/threads/${e}/state`,{method:"GET",headers:m(t,{"Content-Type":"application/json",accept:"application/json"}),...f(t),signal:r.signal});if(clearTimeout(o),!s.ok)throw console.warn(`TenxGraphClient: Thread state fetch failed with HTTP ${s.status}`),await p(s,"Thread state fetch failed","/v1/threads/{thread_id}/state","GET");const n=await s.json();return t.debug&&console.info(`TenxGraphClient: Thread state fetched successfully for thread ${e}`,n),n}catch(r){throw r.name==="AbortError"?(console.warn(`TenxGraphClient: Thread state fetch timeout after ${t.timeout}ms`),new Error(`Request timeout after ${t.timeout}ms`)):(t.debug&&console.debug("TenxGraphClient: Thread state fetch failed:",r),r)}}async function ie(t,e,r){try{t.debug&&(console.debug(`TenxGraphClient: Updating thread state for thread ${e}`),console.debug("TenxGraphClient: Request payload:",JSON.stringify(r,null,2)));const o=new AbortController,s=setTimeout(()=>o.abort(),t.timeout),n=await fetch(`${t.baseUrl}/v1/threads/${e}/state`,{method:"PUT",headers:m(t,{"Content-Type":"application/json",accept:"application/json"}),...f(t),body:JSON.stringify(r),signal:o.signal});if(clearTimeout(s),!n.ok)throw console.warn(`TenxGraphClient: Thread state update failed with HTTP ${n.status}`),await p(n,"Thread state update failed","/v1/threads/{thread_id}/state","PUT");const a=await n.json();return t.debug&&console.info(`TenxGraphClient: Thread state updated successfully for thread ${e}`,a),a}catch(o){throw o.name==="AbortError"?(console.warn(`TenxGraphClient: Thread state update timeout after ${t.timeout}ms`),new Error(`Request timeout after ${t.timeout}ms`)):(t.debug&&console.debug("TenxGraphClient: Thread state update failed:",o),o)}}async function le(t,e){try{t.debug&&console.debug(`TenxGraphClient: Clearing thread state for thread ${e}`);const r=new AbortController,o=setTimeout(()=>r.abort(),t.timeout),s=await fetch(`${t.baseUrl}/v1/threads/${e}/state`,{method:"DELETE",headers:m(t,{"Content-Type":"application/json",accept:"application/json"}),...f(t),signal:r.signal});if(clearTimeout(o),!s.ok)throw console.warn(`TenxGraphClient: Thread state clear failed with HTTP ${s.status}`),await p(s,"Thread state clear failed","/v1/threads/{thread_id}/state","DELETE");const n=await s.json();return t.debug&&console.info(`TenxGraphClient: Thread state cleared successfully for thread ${e}`,n),n}catch(r){throw r.name==="AbortError"?(console.warn(`TenxGraphClient: Thread state clear timeout after ${t.timeout}ms`),new Error(`Request timeout after ${t.timeout}ms`)):(t.debug&&console.debug("TenxGraphClient: Thread state clear failed:",r),r)}}async function N(t,e){try{t.debug&&console.debug("TenxGraphClient: Fetching thread messages for thread",e.threadId);const r=new AbortController,o=setTimeout(()=>r.abort(),t.timeout),s=new URLSearchParams;e.search!==void 0&&s.append("search",e.search),e.offset!==void 0&&s.append("offset",e.offset.toString()),e.limit!==void 0&&s.append("limit",e.limit.toString());const n=s.toString(),a=`${t.baseUrl}/v1/threads/${e.threadId}/messages${n?"?"+n:""}`,i=await fetch(a,{method:"GET",headers:m(t,{"Content-Type":"application/json"}),...f(t),signal:r.signal});if(clearTimeout(o),!i.ok)throw console.warn(`TenxGraphClient: Checkpoint messages fetch failed with HTTP ${i.status}`),await p(i,"Thread messages fetch failed","/v1/threads/{thread_id}/messages","GET");const c=await i.json();return t.debug&&console.info("TenxGraphClient: Thread messages fetched successfully",c),c}catch(r){throw t.debug&&console.debug("TenxGraphClient: Checkpoint messages fetch failed:",r),r}}const et=N;async function ce(t,e){try{t.debug&&console.debug("TenxGraphClient: Adding thread messages to thread",e.threadId);const r=new AbortController,o=setTimeout(()=>r.abort(),t.timeout),s=`${t.baseUrl}/v1/threads/${e.threadId}/messages`,n={config:e.config,messages:e.messages,metadata:e.metadata||{}},a=await fetch(s,{method:"POST",headers:m(t,{"Content-Type":"application/json"}),...f(t),body:JSON.stringify(n),signal:r.signal});if(clearTimeout(o),!a.ok)throw console.warn(`TenxGraphClient: Add checkpoint messages failed with HTTP ${a.status}`),await p(a,"Add thread messages failed","/v1/threads/{thread_id}/messages","POST");const i=await a.json();return t.debug&&console.info("TenxGraphClient: Thread messages added successfully",i),i}catch(r){throw t.debug&&console.debug("TenxGraphClient: Add checkpoint messages failed:",r),r}}async function he(t,e){try{t.debug&&console.debug("TenxGraphClient: Fetching thread message",`thread: ${e.threadId}`,`message: ${e.messageId}`);const r=new AbortController,o=setTimeout(()=>r.abort(),t.timeout),s=`${t.baseUrl}/v1/threads/${e.threadId}/messages/${e.messageId}`,n=await fetch(s,{method:"GET",headers:m(t,{"Content-Type":"application/json"}),...f(t),signal:r.signal});if(clearTimeout(o),!n.ok)throw console.warn(`TenxGraphClient: Thread message fetch failed with HTTP ${n.status}`),await p(n,"Thread message fetch failed","/v1/threads/{thread_id}/messages/{message_id}","GET");const a=await n.json();return t.debug&&console.info("TenxGraphClient: Thread message fetched successfully",a),a}catch(r){throw t.debug&&console.debug("TenxGraphClient: Thread message fetch failed:",r),r}}async function de(t,e){try{t.debug&&console.debug(`TenxGraphClient: Fetching thread details for thread ${e}`);const r=new AbortController,o=setTimeout(()=>r.abort(),t.timeout),s=`${t.baseUrl}/v1/threads/${e}`,n=await fetch(s,{method:"GET",headers:m(t,{"Content-Type":"application/json",accept:"application/json"}),...f(t),signal:r.signal});if(clearTimeout(o),!n.ok)throw console.warn(`TenxGraphClient: Thread details fetch failed with HTTP ${n.status}`),await p(n,"Thread details fetch failed","/v1/threads/{thread_id}","GET");const a=await n.json();return t.debug&&console.info("TenxGraphClient: Thread details fetched successfully",a),a}catch(r){throw r.name==="AbortError"?(console.warn(`TenxGraphClient: Thread details fetch timeout after ${t.timeout}ms`),new Error(`Request timeout after ${t.timeout}ms`)):(t.debug&&console.debug("TenxGraphClient: Thread details fetch failed:",r),r)}}async function ue(t,e){try{t.debug&&console.debug("TenxGraphClient: Deleting thread message",`thread: ${e.threadId}`,`message: ${e.messageId}`);const r=new AbortController,o=setTimeout(()=>r.abort(),t.timeout),s=`${t.baseUrl}/v1/threads/${e.threadId}/messages/${e.messageId}`,n=await fetch(s,{method:"DELETE",headers:m(t,{"Content-Type":"application/json",accept:"application/json"}),...f(t),body:JSON.stringify({config:e.config||{}}),signal:r.signal});if(clearTimeout(o),!n.ok)throw console.warn(`TenxGraphClient: Delete thread message failed with HTTP ${n.status}`),await p(n,"Delete thread message failed","/v1/threads/{thread_id}/messages/{message_id}","DELETE");const a=await n.json();return t.debug&&console.info("TenxGraphClient: Thread message deleted successfully",a),a}catch(r){throw r.name==="AbortError"?(console.warn(`TenxGraphClient: Delete thread message timeout after ${t.timeout}ms`),new Error(`Request timeout after ${t.timeout}ms`)):(t.debug&&console.debug("TenxGraphClient: Delete thread message failed:",r),r)}}async function me(t,e){try{t.debug&&console.debug("TenxGraphClient: Deleting thread",`thread: ${e.threadId}`);const r=new AbortController,o=setTimeout(()=>r.abort(),t.timeout),s=`${t.baseUrl}/v1/threads/${e.threadId}`,n=await fetch(s,{method:"DELETE",headers:m(t,{"Content-Type":"application/json",accept:"application/json"}),...f(t),body:JSON.stringify({config:e.config||{}}),signal:r.signal});if(clearTimeout(o),!n.ok)throw console.warn(`TenxGraphClient: Delete thread failed with HTTP ${n.status}`),await p(n,"Delete thread failed","/v1/threads/{thread_id}","DELETE");const a=await n.json();return t.debug&&console.info("TenxGraphClient: Thread deleted successfully",a),a}catch(r){throw r.name==="AbortError"?(console.warn(`TenxGraphClient: Delete thread timeout after ${t.timeout}ms`),new Error(`Request timeout after ${t.timeout}ms`)):(t.debug&&console.debug("TenxGraphClient: Delete thread failed:",r),r)}}async function fe(t,e){try{t.debug&&(console.debug("TenxGraphClient: Fetching threads list"),e?.search&&console.debug(` Search: ${e.search}`),e?.offset!==void 0&&console.debug(` Offset: ${e.offset}`),e?.limit!==void 0&&console.debug(` Limit: ${e.limit}`));const r=new AbortController,o=setTimeout(()=>r.abort(),t.timeout),s=new URLSearchParams;e?.search&&s.append("search",e.search),e?.offset!==void 0&&s.append("offset",e.offset.toString()),e?.limit!==void 0&&s.append("limit",e.limit.toString());const n=s.toString(),a=`${t.baseUrl}/v1/threads${n?`?${n}`:""}`,i=await fetch(a,{method:"GET",headers:m(t,{"Content-Type":"application/json",accept:"application/json"}),...f(t),signal:r.signal});if(clearTimeout(o),!i.ok)throw console.warn(`TenxGraphClient: Threads list fetch failed with HTTP ${i.status}`),await p(i,"Threads list fetch failed","/v1/threads","GET");const c=await i.json();return t.debug&&(console.info("TenxGraphClient: Threads list fetched successfully",c),console.debug(` Found ${c.data.threads.length} threads`)),c}catch(r){throw r.name==="AbortError"?(console.warn(`TenxGraphClient: Threads list fetch timeout after ${t.timeout}ms`),new Error(`Request timeout after ${t.timeout}ms`)):(t.debug&&console.debug("TenxGraphClient: Threads list fetch failed:",r),r)}}async function tt(t,e){const r=new AbortController,o=setTimeout(()=>r.abort(),t.timeout);try{const s=await fetch(`${t.baseUrl}/v1/graph/invoke`,{method:"POST",headers:m(t,{"Content-Type":"application/json",accept:"application/json"}),...f(t),body:JSON.stringify(e),signal:r.signal});if(clearTimeout(o),!s.ok)throw console.warn(`TenxGraphClient: Invoke failed with HTTP ${s.status}`),await p(s,"Invoke request failed","/v1/invoke","POST");return await s.json()}catch(s){throw clearTimeout(o),s.name==="AbortError"?(console.warn(`TenxGraphClient: Invoke timeout after ${t.timeout}ms`),new Error(`Request timeout after ${t.timeout}ms`)):(console.error("TenxGraphClient: Invoke failed:",s),s)}}function rt(t){return!t.data||!t.data.messages?!1:t.data.messages.some(e=>e.content&&e.content.some(r=>r.type==="remote_tool_call"))}async function pe(t,e,r){const o=e.recursion_limit||25;t.debug&&(console.debug("TenxGraphClient: Starting invoke with recursion_limit:",o),console.debug("TenxGraphClient: Initial request:",JSON.stringify(e,null,2)));const s=[];let n=e.messages,a=0,i=!1,c;const d=e.initial_state,h=e.config,l=e.response_granularity;for(;a<o;){a++,t.debug&&console.debug(`TenxGraphClient: Iteration ${a}/${o}`);const T={messages:n,initial_state:a===1?d:void 0,config:h,recursion_limit:o,response_granularity:l};t.debug&&console.debug("TenxGraphClient: Request payload:",JSON.stringify(T,null,2));const y=await tt(t,T);c=y,t.debug&&(console.info("TenxGraphClient: Invoke successful"),console.debug("TenxGraphClient: Response:",JSON.stringify(y,null,2))),y.data.messages&&s.push(...y.data.messages);const w=rt(y);if(r){const E={iteration:a,messages:y.data.messages,state:y.data.state,context:y.data.context,summary:y.data.summary,meta:y.data.meta,has_tool_calls:w,is_final:!w};await r(E)}if(w&&t.toolExecutor){t.debug&&console.debug("TenxGraphClient: Found remote tool calls, executing...");const E=await t.toolExecutor.executeToolCalls(y.data.messages);t.debug&&console.debug(`TenxGraphClient: Executed ${E.length} tool calls`),s.push(...E),n=E.map(De=>st(De));continue}else{t.debug&&console.debug("TenxGraphClient: No remote tool calls found, finishing");break}}a>=o&&(i=!0,t.debug&&console.warn(`TenxGraphClient: Recursion limit of ${o} reached`));const u={messages:c?.data.messages||[],state:c?.data.state,context:c?.data.context,summary:c?.data.summary,meta:c?.data.meta||{is_new_thread:!1,thread_id:""},all_messages:s,iterations:a,recursion_limit_reached:i};return t.debug&&(console.debug(`TenxGraphClient: Invoke completed after ${a} iterations`),console.debug(`TenxGraphClient: Total messages: ${s.length}`)),u}function ot(t){return t.map(e=>{const r={};for(const[o,s]of Object.entries(e))Array.isArray(s)&&s.length===0||s!==void 0&&(r[o]=s);return r})}function st(t){const e={role:t.role,content:ot(t.content)};return t.message_id!==null&&t.message_id!==void 0?e.message_id=String(t.message_id):e.message_id="0",t.tools_calls&&(e.tools_calls=t.tools_calls),t.metadata&&Object.keys(t.metadata).length>0&&(e.metadata=t.metadata),e}var U=(t=>(t.MESSAGE="message",t.UPDATES="updates",t.STATE="state",t.ERROR="error",t))(U||{});async function*nt(t,e){const r=new TextDecoder;let o="";try{for(;;){const{done:s,value:n}=await t.read();if(s){o.trim()&&(yield*B(o,e,!0));break}o+=r.decode(n,{stream:!0}),o=(yield*B(o,e,!1)).remaining}}finally{t.releaseLock()}}function*B(t,e,r){for(;t.includes(`
3
+ Suggestion: ${this.recoverySuggestion}`:this.message}toJSON(){return{name:this.name,message:this.message,statusCode:this.statusCode,errorCode:this.errorCode,requestId:this.requestId,timestamp:this.timestamp,details:this.details,context:this.context,endpoint:this.endpoint,method:this.method,recoverySuggestion:this.recoverySuggestion,stack:this.stack}}}class ue extends T{constructor(e,r,o,s=[]){super(e,400,"BAD_REQUEST",r,o,s),this.name="BadRequestError"}}class fe extends T{constructor(e,r,o,s=[]){super(e,401,"AUTHENTICATION_FAILED",r,o,s),this.name="AuthenticationError"}}class pe extends T{constructor(e,r,o,s=[]){super(e,403,"PERMISSION_ERROR",r,o,s),this.name="PermissionError"}}class me extends T{constructor(e,r,o,s=[]){super(e,404,"RESOURCE_NOT_FOUND",r,o,s),this.name="NotFoundError"}}class ge extends T{constructor(e,r,o,s=[]){super(e,409,"CONFLICT",r,o,s),this.name="ConflictError"}}class Q extends T{constructor(e,r,o,s=[]){super(e,422,"VALIDATION_ERROR",r,o,s),this.name="ValidationError"}}class ye extends T{constructor(e,r,o,s="INTERNAL_SERVER_ERROR",n=[],a=500){super(e,a,s,r,o,n),this.name="ServerError"}}class Te extends T{constructor(e,r,o,s=[],n){super(e,500,"GRAPH_ERROR",r,o,s,n,void 0,void 0,"Check your graph configuration and ensure all nodes are properly connected."),this.name="GraphError"}}class be extends T{constructor(e,r,o,s=[],n,a){super(e,500,"NODE_ERROR",r,o,s,n,void 0,void 0,"Review the node implementation and ensure all required inputs are provided."),this.name="NodeError",this.nodeName=a}}class we extends T{constructor(e,r,o,s=[],n,a){super(e,500,"GRAPH_RECURSION_ERROR",r,o,s,n,void 0,void 0,"Consider increasing the recursion_limit parameter or check for infinite loops in your graph."),this.name="GraphRecursionError",this.recursionLimit=a}}class Ee extends T{constructor(e,r,o,s=[],n){super(e,500,"STORAGE_ERROR",r,o,s,n,void 0,void 0,"Check your storage configuration and ensure the storage backend is accessible."),this.name="StorageError"}}class _e extends T{constructor(e,r,o,s=[],n){super(e,503,"TRANSIENT_STORAGE_ERROR",r,o,s,n,void 0,void 0,"This is a temporary issue. Please retry your request after a short delay."),this.name="TransientStorageError"}}class Ce extends T{constructor(e,r,o,s=[],n){super(e,500,"METRICS_ERROR",r,o,s,n,void 0,void 0,"Check your metrics configuration. This error typically doesn't affect core functionality."),this.name="MetricsError"}}class Se extends T{constructor(e,r,o,s=[],n,a,i){super(e,422,"SCHEMA_VERSION_ERROR",r,o,s,n,void 0,void 0,"Update your client to match the server schema version or contact support."),this.name="SchemaVersionError",this.expectedVersion=a,this.actualVersion=i}}class ve extends T{constructor(e,r,o,s=[],n){super(e,500,"SERIALIZATION_ERROR",r,o,s,n,void 0,void 0,"Ensure your data format is compatible with the API schema."),this.name="SerializationError"}}class Re extends T{constructor(e,r,o,s=[],n){super(e,429,"RATE_LIMIT_EXCEEDED",r,o,s,void 0,void 0,void 0,"Wait for the retry-after period before sending the request again."),this.name="RateLimitError",this.retryAfterSeconds=n}}class D extends T{constructor(e,r,o,s){super(`Request timeout after ${e}ms`,0,"REQUEST_TIMEOUT","unknown",new Date().toISOString(),[],void 0,r,o,"Increase the client timeout or check that the server is reachable and not overloaded."),this.name="RequestTimeoutError",this.timeoutMs=e,s!==void 0&&(this.cause=s)}}class L extends T{constructor(e,r,o,s){super(e,0,"NETWORK_ERROR","unknown",new Date().toISOString(),[],void 0,r,o,"Check that the server is running, the base URL is correct and the network is reachable."),this.name="NetworkError",s!==void 0&&(this.cause=s)}}class F extends T{constructor(e,r,o,s){super(e,0,"WEBSOCKET_ERROR","unknown",new Date().toISOString(),[],void 0,o,"WS"),this.name="WebSocketError",this.closeCode=r,s!==void 0&&(this.cause=s)}}class W extends T{constructor(e,r="STREAM_ERROR",o="unknown",s,n,a){super(e,0,r,o,new Date().toISOString(),[],void 0,s,n),this.name="StreamError",a!==void 0&&(this.cause=a)}}function J(t){return t!==null&&typeof t=="object"&&!Array.isArray(t)?t:null}function vt(t){const e=J(t);if(!e)return null;const r=J(e.metadata)??{},o={message:typeof r.message=="string"?r.message:"",request_id:typeof r.request_id=="string"?r.request_id:"",timestamp:typeof r.timestamp=="string"?r.timestamp:""},s=J(e.error);if(s)return{metadata:o,error:{code:typeof s.code=="string"?s.code:"",message:typeof s.message=="string"?s.message:"",details:Array.isArray(s.details)?s.details:[],...typeof s.retry_after_seconds=="number"?{retry_after_seconds:s.retry_after_seconds}:{}}};if(typeof e.error=="string"){const n=typeof e.detail=="string"?e.detail:e.error;return{metadata:o,error:{code:e.error,message:n,details:[]}}}if(typeof e.detail=="string")return{metadata:o,error:{code:"",message:e.detail,details:[]}};if(Array.isArray(e.detail)){const n=e.detail.filter(a=>J(a)!==null);return{metadata:o,error:{code:"",message:n[0]?.msg||"Validation error",details:n}}}return null}async function ke(t){try{const e=t.headers?.get("content-type");if(e&&e.includes("application/json")){const r=await t.json();return{parsed:vt(r),raw:r}}return{parsed:null,raw:void 0}}catch{return{parsed:null,raw:void 0}}}async function Rt(t){return(await ke(t)).parsed}function kt(t){const e={};try{t.headers?.forEach((r,o)=>{e[o.toLowerCase()]=r})}catch{}return e}function Gt(t){if(!t)return;const e=Number(t);if(Number.isFinite(e)&&e>=0)return e;const r=Date.parse(t);if(!Number.isNaN(r))return Math.max(0,Math.ceil((r-Date.now())/1e3))}function I(t,e){const r=t.toUpperCase();return e.some(o=>r.startsWith(o))}async function u(t,e,r,o){const{parsed:s,raw:n}=await ke(t),a=t.headers?.get("x-request-id")||"",i=s?.error.message||e||`HTTP error! status: ${t.status}`,c=s?.metadata.request_id||a||"unknown",l=s?.metadata.timestamp||new Date().toISOString(),y=s?.error.details||[],g=s?.error.code||"",b=At(t.status,g,i,c,l,y,{retryAfter:Gt(t.headers?.get("retry-after"))??s?.error.retry_after_seconds,endpoint:r,method:o});return b.endpoint=r,b.method=o,b.responseHeaders=kt(t),n!==void 0&&(b.responseBody=n),b}function At(t,e,r,o,s,n,a){if(I(e,["RECURSION","GRAPH_RECURSION"]))return new we(r,o,s,n);if(I(e,["GRAPH"]))return new Te(r,o,s,n);if(I(e,["NODE"]))return new be(r,o,s,n);if(I(e,["STORAGE_TRANSIENT","TRANSIENT_STORAGE"]))return new _e(r,o,s,n);if(I(e,["STORAGE_SCHEMA","SCHEMA_VERSION"]))return new Se(r,o,s,n);if(I(e,["STORAGE_SERIALIZATION","SERIALIZATION"]))return new ve(r,o,s,n);if(I(e,["STORAGE"]))return new Ee(r,o,s,n);if(I(e,["METRICS"]))return new Ce(r,o,s,n);if(e==="VALIDATION_ERROR"||e==="AGENTFLOW_VALIDATION_ERROR")return new Q(r,o,s,n);switch(t){case 400:return new ue(r,o,s,n);case 401:return new fe(r,o,s,n);case 403:return new pe(r,o,s,n);case 404:return new me(r,o,s,n);case 409:return new ge(r,o,s,n);case 422:return new Q(r,o,s,n);case 429:return new Re(r,o,s,n,a.retryAfter);case 500:case 502:case 503:case 504:return new ye(r,o,s,e||"INTERNAL_SERVER_ERROR",n,t);default:return new T(r,t,e||"UNKNOWN_ERROR",o,s,n,void 0,a.endpoint,a.method)}}function z(t,e){if(!e)return()=>{};if(e.aborted)return t.abort(),()=>{};const r=()=>t.abort();return e.addEventListener("abort",r,{once:!0}),()=>e.removeEventListener("abort",r)}function P(t,e,r){if(r!=null){for(const o of Object.keys(t))o.toLowerCase()===e.toLowerCase()&&delete t[o];t[e]=r}}function re(t,e){if(e){if(e instanceof Headers){e.forEach((r,o)=>{P(t,o,r)});return}if(Array.isArray(e)){for(const[r,o]of e)P(t,r,o);return}for(const[r,o]of Object.entries(e))o!==void 0&&P(t,r,String(o))}}function Ot(t,e){return Object.keys(t).some(r=>r.toLowerCase()===e.toLowerCase())}function $t(t){const e=globalThis.Buffer;if(e)return e.from(t,"utf-8").toString("base64");if(typeof btoa=="function"){const r=new TextEncoder().encode(t);let o="";for(const s of r)o+=String.fromCharCode(s);return btoa(o)}throw new Error("Basic authentication is not supported in this runtime")}function It(t,e){if(!e)return;if(e.type==="bearer"){P(t,"Authorization",`Bearer ${e.token}`);return}if(e.type==="basic"){const o=$t(`${e.username}:${e.password}`);P(t,"Authorization",`Basic ${o}`);return}const r=e.prefix?`${e.prefix} ${e.value}`:e.value;P(t,e.name,r)}function d(t,e){const r={};return re(r,e),re(r,t.headers),t.auth?It(r,t.auth):t.authToken&&!Ot(r,"Authorization")&&P(r,"Authorization",`Bearer ${t.authToken}`),r}function h(t){return t.credentials?{credentials:t.credentials}:{}}function Nt(t){return{type:"bearer",token:t}}function Ut(t,e){return{type:"basic",username:t,password:e}}function jt(t,e,r){return{type:"header",name:t,value:e,prefix:r}}function C(t){return encodeURIComponent(String(t))}function Ge(t){let e=t.length;for(;e>0&&t.charCodeAt(e-1)===47;)e--;return t.slice(0,e)}const Pt=5;function oe(t){try{return new URL(t).origin}catch{return null}}function V(t){try{return new URL(t).pathname}catch{return t}}async function f(t,e,r={}){const o=new AbortController,s=t.timeout>0?setTimeout(()=>o.abort(),t.timeout):void 0;s?.unref?.();const n=z(o,t.signal),a=(r.method||"GET").toUpperCase(),i=t.auth?.type==="header"&&t.auth.name.toLowerCase()!=="authorization";try{let c=e,l={...r,signal:o.signal};i&&(l.redirect="manual");for(let y=0;;y++){const g=await fetch(c,l);if(i&&g.type==="opaqueredirect")throw new L("The server redirected the request and the browser does not expose the target, so it was not followed (header credentials must not be sent to another origin). Point baseUrl at the final URL.",V(e),a);if(!i||!(g.status>=300&&g.status<400))return g;const b=g.headers?.get("location"),R=b?new URL(b,c).toString():null;if(!R||oe(R)!==oe(e)||y>=Pt)throw new L("Refusing to follow a redirect that leaves the base URL origin (credentials would be forwarded)",V(e),a);c=R,g.status===303&&(l={...l,method:"GET",body:void 0})}}catch(c){if(c instanceof T)throw c;if(c?.name==="AbortError")throw t.signal?.aborted?c:new D(t.timeout,V(e),a,c);const y=c instanceof Error?c.message:String(c);throw new L(`Network request failed: ${y}`,V(e),a,c)}finally{s!==void 0&&clearTimeout(s),n()}}async function Ae(t){try{t.debug&&console.debug("TenxGraphClient: Pinging server at",t.baseUrl);const e=await f(t,`${t.baseUrl}/ping`,{method:"GET",headers:d(t,{"Content-Type":"application/json"}),...h(t)});if(!e.ok)throw console.warn(`TenxGraphClient: Ping failed with HTTP ${e.status}`),await u(e,"Ping request failed","/ping","GET");const r=await e.json();return t.debug&&console.info("TenxGraphClient: Ping successful",r),r}catch(e){throw t.debug&&console.debug("TenxGraphClient: Ping failed:",e),console.error("TenxGraphClient: Ping failed:",e),e}}async function Oe(t){try{t.debug&&console.debug("TenxGraphClient: Fetching graph from",t.baseUrl);const e=await f(t,`${t.baseUrl}/v1/graph`,{method:"GET",headers:d(t,{"Content-Type":"application/json",accept:"application/json"}),...h(t)});if(!e.ok)throw console.warn(`TenxGraphClient: Graph fetch failed with HTTP ${e.status}`),await u(e,"Graph fetch failed","/v1/graph","GET");const r=await e.json();return t.debug&&console.info("TenxGraphClient: Graph fetch successful",r),r}catch(e){throw t.debug&&console.debug("TenxGraphClient: Graph fetch failed:",e),console.error("TenxGraphClient: Graph fetch failed:",e),e}}async function $e(t){try{t.debug&&console.debug("TenxGraphClient: Fetching graph tools from",t.baseUrl);const e=await f(t,`${t.baseUrl}/v1/graph/tools`,{method:"GET",headers:d(t,{"Content-Type":"application/json",accept:"application/json"}),...h(t)});if(!e.ok)throw console.warn(`TenxGraphClient: Graph tools fetch failed with HTTP ${e.status}`),await u(e,"Graph tools fetch failed","/v1/graph/tools","GET");const r=await e.json();return t.debug&&console.info("TenxGraphClient: Graph tools fetch successful",r),r}catch(e){throw t.debug&&console.debug("TenxGraphClient: Graph tools fetch failed:",e),console.error("TenxGraphClient: Graph tools fetch failed:",e),e}}async function Ie(t,e,r){const o=r?`?run_id=${encodeURIComponent(r)}`:"",s=await f(t,`${t.baseUrl}/v1/observability/${encodeURIComponent(e)}${o}`,{method:"GET",headers:d(t,{"Content-Type":"application/json",accept:"application/json"}),...h(t)});if(!s.ok)throw await u(s,"Observability fetch failed",`/v1/observability/${e}`,"GET");return await s.json()}async function Ne(t){try{t.debug&&console.debug("TenxGraphClient: Fetching state schema from",t.baseUrl);const e=await f(t,`${t.baseUrl}/v1/graph:StateSchema`,{method:"GET",headers:d(t,{"Content-Type":"application/json",accept:"application/json"}),...h(t)});if(!e.ok)throw console.warn(`TenxGraphClient: State schema fetch failed with HTTP ${e.status}`),await u(e,"State schema fetch failed","/v1/state_schema","GET");const r=await e.json();return t.debug&&console.info("TenxGraphClient: State schema fetch successful",r),r}catch(e){throw t.debug&&console.debug("TenxGraphClient: State schema fetch failed:",e),console.error("TenxGraphClient: State schema fetch failed:",e),e}}async function Ue(t,e){try{t.debug&&console.debug(`TenxGraphClient: Fetching thread state for thread ${e}`);const r=await f(t,`${t.baseUrl}/v1/threads/${C(e)}/state`,{method:"GET",headers:d(t,{"Content-Type":"application/json",accept:"application/json"}),...h(t)});if(!r.ok)throw console.warn(`TenxGraphClient: Thread state fetch failed with HTTP ${r.status}`),await u(r,"Thread state fetch failed","/v1/threads/{thread_id}/state","GET");const o=await r.json();return t.debug&&console.info(`TenxGraphClient: Thread state fetched successfully for thread ${e}`,o),o}catch(r){throw t.debug&&console.debug("TenxGraphClient: Thread state fetch failed:",r),r}}async function je(t,e,r){try{t.debug&&(console.debug(`TenxGraphClient: Updating thread state for thread ${e}`),console.debug("TenxGraphClient: Request payload:",JSON.stringify(r,null,2)));const o=await f(t,`${t.baseUrl}/v1/threads/${C(e)}/state`,{method:"PUT",headers:d(t,{"Content-Type":"application/json",accept:"application/json"}),...h(t),body:JSON.stringify(r)});if(!o.ok)throw console.warn(`TenxGraphClient: Thread state update failed with HTTP ${o.status}`),await u(o,"Thread state update failed","/v1/threads/{thread_id}/state","PUT");const s=await o.json();return t.debug&&console.info(`TenxGraphClient: Thread state updated successfully for thread ${e}`,s),s}catch(o){throw t.debug&&console.debug("TenxGraphClient: Thread state update failed:",o),o}}async function Pe(t,e){try{t.debug&&console.debug(`TenxGraphClient: Clearing thread state for thread ${e}`);const r=await f(t,`${t.baseUrl}/v1/threads/${C(e)}/state`,{method:"DELETE",headers:d(t,{"Content-Type":"application/json",accept:"application/json"}),...h(t)});if(!r.ok)throw console.warn(`TenxGraphClient: Thread state clear failed with HTTP ${r.status}`),await u(r,"Thread state clear failed","/v1/threads/{thread_id}/state","DELETE");const o=await r.json();return t.debug&&console.info(`TenxGraphClient: Thread state cleared successfully for thread ${e}`,o),o}catch(r){throw t.debug&&console.debug("TenxGraphClient: Thread state clear failed:",r),r}}async function q(t,e){try{t.debug&&console.debug("TenxGraphClient: Fetching thread messages for thread",e.threadId);const r=new URLSearchParams;e.search!==void 0&&r.append("search",e.search),e.offset!==void 0&&r.append("offset",e.offset.toString()),e.limit!==void 0&&r.append("limit",e.limit.toString());const o=r.toString(),s=`${t.baseUrl}/v1/threads/${C(e.threadId)}/messages${o?"?"+o:""}`,n=await f(t,s,{method:"GET",headers:d(t,{"Content-Type":"application/json"}),...h(t)});if(!n.ok)throw console.warn(`TenxGraphClient: Checkpoint messages fetch failed with HTTP ${n.status}`),await u(n,"Thread messages fetch failed","/v1/threads/{thread_id}/messages","GET");const a=await n.json();return t.debug&&console.info("TenxGraphClient: Thread messages fetched successfully",a),a}catch(r){throw t.debug&&console.debug("TenxGraphClient: Checkpoint messages fetch failed:",r),r}}const xt=q;var H=(t=>(t.MESSAGE="message",t.UPDATES="updates",t.STATE="state",t.ERROR="error",t))(H||{});const M="/v1/graph/stream";async function*Mt(t,e,r){const o=new TextDecoder;let s="",n=!1;try{for(;;){let a;r?.beforeRead();try{a=await t.read()}catch(y){throw y?.name==="AbortError"?y:new W(`Stream connection lost: ${y?.message??String(y)}`,"STREAM_INTERRUPTED","unknown",M,"POST",y)}finally{r?.afterRead()}const{done:i,value:c}=a;if(i){s+=o.decode(),s.trim()&&(yield*se(s,e,!0)),n=!0;break}s+=o.decode(c,{stream:!0}),s=(yield*se(s,e,!1)).remaining}}finally{if(!n)try{await t.cancel()}catch{}t.releaseLock()}}function X(t,e){return new W(`Stream data could not be parsed (${t.slice(0,100)}); the stream was cut or corrupted`,"STREAM_TRUNCATED","unknown",M,"POST",e)}function*se(t,e,r){for(;t.includes(`
4
4
  `);){const o=t.indexOf(`
5
- `),s=t.slice(0,o).trim();if(t=t.slice(o+1),s)try{const n=JSON.parse(s);e&&console.debug("TenxGraphClient: Stream chunk received (NDJSON):",n.event),yield n}catch(n){e&&console.warn("TenxGraphClient: Failed to parse NDJSON line:",s.slice(0,100),n)}}for(;t.trim();){const o=at(t);if(o)try{const s=JSON.parse(o.json);e&&console.debug("TenxGraphClient: Stream chunk received (concat):",s.event),yield s,t=o.remaining}catch(s){e&&console.warn("TenxGraphClient: Failed to parse concatenated JSON:",o.json.slice(0,100),s);break}else{if(r&&t.trim())try{const s=JSON.parse(t.trim());e&&console.debug("TenxGraphClient: Final stream chunk:",s.event),yield s,t=""}catch(s){e&&console.warn("TenxGraphClient: Failed to parse final buffer:",t.slice(0,100),s)}break}}return{remaining:t}}function at(t){if(t=t.trim(),!t||t[0]!=="{")return null;let e=0,r=!1,o=!1;for(let s=0;s<t.length;s++){const n=t[s];if(o){o=!1;continue}if(n==="\\"){o=!0;continue}if(n==='"'){r=!r;continue}if(!r){if(n==="{")e++;else if(n==="}"&&(e--,e===0))return{json:t.slice(0,s+1),remaining:t.slice(s+1).trim()}}}return null}function it(t){return t.some(e=>e.content&&e.content.some(r=>r.type==="remote_tool_call"))}async function*ge(t,e){const r=e.recursion_limit||25;t.debug&&(console.debug("TenxGraphClient: Starting stream invoke with recursion_limit:",r),console.debug("TenxGraphClient: Initial request:",JSON.stringify(e,null,2)));let o=e.messages,s=0;const n=e.initial_state,a=e.config,i=e.response_granularity;for(;s<r;){s++,t.debug&&console.debug(`TenxGraphClient: Stream iteration ${s}/${r}`);const c={messages:o,initial_state:s===1?n:void 0,config:a,recursion_limit:r,response_granularity:i};t.debug&&console.debug("TenxGraphClient: Stream request payload:",JSON.stringify(c,null,2));const d=new AbortController,h=setTimeout(()=>d.abort(),t.timeout);try{const l=await fetch(`${t.baseUrl}/v1/graph/stream`,{method:"POST",headers:m(t,{"Content-Type":"application/json",Accept:"application/x-ndjson, application/json"}),...f(t),body:JSON.stringify(c),signal:d.signal});if(clearTimeout(h),!l.ok)throw console.warn(`TenxGraphClient: Stream failed with HTTP ${l.status}`),await p(l,"Stream request failed","/v1/stream","POST");if(!l.body)throw new Error("No response body for stream");const u=[],T=l.body.getReader();for await(const w of nt(T,t.debug))yield w,w.message&&u.push(w.message);if(t.debug&&(console.info("TenxGraphClient: Stream iteration completed"),console.debug("TenxGraphClient: Received",u.length,"messages")),it(u)&&t.toolExecutor){t.debug&&console.debug("TenxGraphClient: Found remote tool calls, executing...");const w=await t.toolExecutor.executeToolCalls(u);t.debug&&console.debug(`TenxGraphClient: Executed ${w.length} tool calls`),o=w.map(E=>j(E));continue}else{t.debug&&console.debug("TenxGraphClient: No remote tool calls found, finishing");break}}catch(l){throw clearTimeout(h),l.name==="AbortError"?(console.warn(`TenxGraphClient: Stream timeout after ${t.timeout}ms`),new Error(`Request timeout after ${t.timeout}ms`)):(console.error("TenxGraphClient: Stream failed:",l),l)}}s>=r&&t.debug&&console.warn(`TenxGraphClient: Recursion limit of ${r} reached`),t.debug&&console.debug(`TenxGraphClient: Stream invoke completed after ${s} iterations`)}function lt(t){return t.map(e=>{const r={};for(const[o,s]of Object.entries(e))Array.isArray(s)&&s.length===0||s!==void 0&&(r[o]=s);return r})}function j(t){const e={role:t.role,content:lt(t.content)};return t.message_id!==null&&t.message_id!==void 0?e.message_id=String(t.message_id):e.message_id="0",t.tools_calls&&(e.tools_calls=t.tools_calls),t.metadata&&Object.keys(t.metadata).length>0&&(e.metadata=t.metadata),e}const Te="10xgraph-bearer";function ye(t){return t.auth?t.auth.type==="bearer"?t.auth.token:null:t.authToken?t.authToken:null}function P(t,e){return t.baseUrl.replace(/^https:/,"wss:").replace(/^http:/,"ws:").replace(/\/$/,"")+e}function x(t,e){const r=e.webSocketImpl??globalThis.WebSocket;if(!r)throw new Error("No WebSocket implementation available. In Node < 21 pass `webSocketImpl` in the client config (e.g. the `ws` package: `new TenxGraphClient({ ..., webSocketImpl: WebSocket })`).");const o=ye(e),s=o?[Te,o]:void 0,n=m(e),a=n.Authorization??n.authorization;if(a)try{return new r(t,s,{headers:{Authorization:a}})}catch{}return new r(t,s)}function ct(t){return t.some(e=>e.content&&e.content.some(r=>r.type==="remote_tool_call"))}async function*we(t,e){const r=P(t,"/v1/graph/ws");t.debug&&console.debug("TenxGraphClient [WS]: connecting to",r);const o=x(r,t),s=[];let n=null;const a=h=>{if(s.push(h),n){const l=n;n=null,l()}},i=()=>new Promise(h=>{s.length>0?h():n=h});o.addEventListener("message",h=>{try{const l=JSON.parse(h.data);a(l)}catch(l){t.debug&&console.warn("TenxGraphClient [WS]: failed to parse chunk:",l)}}),o.addEventListener("error",()=>{a(new Error("WebSocket error"))}),o.addEventListener("close",h=>{t.debug&&console.debug("TenxGraphClient [WS]: connection closed, code=",h.code),a("close")}),await new Promise((h,l)=>{if(o.readyState===1){h();return}o.addEventListener("open",()=>h(),{once:!0}),o.addEventListener("error",()=>l(new Error("WebSocket connection failed")),{once:!0})}),t.debug&&console.debug("TenxGraphClient [WS]: connected");let c=e.config?.thread_id,d={invoke_type:"fresh",messages:e.messages,initial_state:e.initial_state,config:e.config,recursion_limit:e.recursion_limit??25,response_granularity:e.response_granularity};try{e:for(;;){t.debug&&console.debug(`TenxGraphClient [WS]: sending ${d.invoke_type} request, thread_id=${c??"new"}`),o.send(JSON.stringify(d));const h=[];t:for(;;){await i();const l=s.shift();if(l==="close")break e;if(l instanceof Error)throw l;const u=l;if(u.thread_id&&(c=u.thread_id),u.metadata?.thread_id&&(c=u.metadata.thread_id),u.event===U.UPDATES&&u.data?.status==="done")break t;u.message&&h.push(u.message),yield u}if(t.debug&&console.debug(`TenxGraphClient [WS]: run complete, ${h.length} messages collected`),ct(h)&&t.toolExecutor){t.debug&&console.debug("TenxGraphClient [WS]: remote tool calls detected, executing…");const l=await t.toolExecutor.executeToolCalls(h);t.debug&&console.debug(`TenxGraphClient [WS]: ${l.length} tool result(s) ready, resuming`),d={invoke_type:"resume",tool_result:l.map(j),config:{...e.config??{},thread_id:c},recursion_limit:e.recursion_limit??25,response_granularity:e.response_granularity}}else break e}}finally{(o.readyState===1||o.readyState===0)&&o.close(1e3),t.debug&&console.debug("TenxGraphClient [WS]: stream finished")}}const be=24e3,ht=16e3;function dt(){const t=globalThis.crypto;return t?.randomUUID?t.randomUUID():"rt-"+Math.abs(ut(String(Date.now()))).toString(36)}function ut(t){let e=0;for(let r=0;r<t.length;r++)e=(e<<5)-e+t.charCodeAt(r),e|=0;return e}function mt(t){if(t instanceof ArrayBuffer)return new Uint8Array(t);if(ArrayBuffer.isView(t)){const e=t;return new Uint8Array(e.buffer,e.byteOffset,e.byteLength)}return null}class Ce{constructor(e,r,o){this.resumptionHandle=null,this.ws=null,this.listeners={},this.readyResolved=!1,this.closedByUser=!1,this.fatal=!1,this.reconnectAttempts=0,this.ctx=e,this.threadId=r.thread_id??dt(),this.init={...r,thread_id:this.threadId},this.reconnectCfg={enabled:o?.reconnect?.enabled??!0,baseDelay:o?.reconnect?.baseDelay??.5,maxDelay:o?.reconnect?.maxDelay??10,maxAttempts:o?.reconnect?.maxAttempts??5},o?.onAudio&&this.on("audio",o.onAudio),o?.onEvent&&this.on("event",o.onEvent),o?.onError&&this.on("error",o.onError),this.ready=new Promise((s,n)=>{this.resolveReady=s,this.rejectReady=n}),this.connect()}sendAudio(e){this.ws?.send(e)}sendText(e){this.sendControl({type:"text",text:e})}activityStart(){this.sendControl({type:"activity_start"})}activityEnd(){this.sendControl({type:"activity_end"})}close(){this.closedByUser=!0,this.sendControl({type:"close"});const e=this.ws;e&&(e.readyState===0||e.readyState===1)&&e.close(1e3)}on(e,r){return this.listeners[e]||(this.listeners[e]=[]),this.listeners[e].push(r),this}off(e,r){return this.listeners[e]=(this.listeners[e]??[]).filter(o=>o!==r),this}emit(e,...r){(this.listeners[e]??[]).forEach(o=>{try{o(...r)}catch(s){this.ctx.debug&&console.warn("TenxGraphClient [realtime]: listener threw",s)}})}sendControl(e){this.ws?.send(JSON.stringify(e))}connect(){const e=P(this.ctx,"/v1/graph/live");this.ctx.debug&&console.debug("TenxGraphClient [realtime]: connecting to",e);const r=x(e,this.ctx);try{r.binaryType="arraybuffer"}catch{}this.ws=r,r.addEventListener("open",()=>{this.ws===r&&(this.sendControl(this.init),this.readyResolved||(this.readyResolved=!0,this.resolveReady()),this.emit("open"))}),r.addEventListener("message",o=>{this.ws===r&&this.handleMessage(o.data)}),r.addEventListener("close",o=>{if(this.ws!==r)return;const s=o?.code??1e3;this.emit("close",s),this.maybeReconnect()}),r.addEventListener("error",()=>{this.ws===r&&(this.readyResolved||(this.readyResolved=!0,this.rejectReady(new Error("Realtime WebSocket connection failed"))))})}handleMessage(e){const r=mt(e);if(r){this.emit("audio",r,be);return}if(typeof e!="string")return;let o;try{o=JSON.parse(e)}catch{this.ctx.debug&&console.warn("TenxGraphClient [realtime]: bad JSON frame",e);return}o.type==="session_update"&&(this.resumptionHandle=o.resumption_handle??this.resumptionHandle),o.type==="error"&&o.fatal&&(this.fatal=!0),this.emit("event",o),this.emit(o.type,o)}maybeReconnect(){if(this.closedByUser||this.fatal||!this.reconnectCfg.enabled)return;if(this.reconnectAttempts>=this.reconnectCfg.maxAttempts){this.fatal=!0;const o={type:"error",code:"reconnect_failed",message:`Realtime reconnect gave up after ${this.reconnectCfg.maxAttempts} attempt(s)`,fatal:!0};this.emit("error",o),this.emit("event",o);return}this.reconnectAttempts+=1;const e=this.reconnectAttempts,r=Math.min(this.reconnectCfg.baseDelay*2**(e-1),this.reconnectCfg.maxDelay)*1e3;this.emit("reconnecting",e),setTimeout(()=>this.reconnect(),r)}reconnect(){this.init={...this.init,thread_id:this.threadId,...this.resumptionHandle?{resumption_handle:this.resumptionHandle}:{}};const e=()=>{this.reconnectAttempts=0,this.emit("reconnected")};this.connect(),this.ws?.addEventListener("open",e,{once:!0})}}var M=(t=>(t.EPISODIC="episodic",t.SEMANTIC="semantic",t.PROCEDURAL="procedural",t.ENTITY="entity",t.RELATIONSHIP="relationship",t.CUSTOM="custom",t.DECLARATIVE="declarative",t))(M||{});async function Ee(t,e){try{t.debug&&console.debug("TenxGraphClient: Storing memory with type",e.memory_type);const r=new AbortController,o=setTimeout(()=>r.abort(),t.timeout),s=`${t.baseUrl}/v1/store/memories`,n={config:e.config||{},options:e.options||{},content:e.content,memory_type:e.memory_type,category:e.category,metadata:e.metadata||{}},a=await fetch(s,{method:"POST",headers:m(t,{"Content-Type":"application/json"}),...f(t),body:JSON.stringify(n),signal:r.signal});if(clearTimeout(o),!a.ok)throw console.warn(`TenxGraphClient: Store memory failed with HTTP ${a.status}`),await p(a,"Store memory request failed","/v1/memory","POST");const i=await a.json();return t.debug&&console.info("TenxGraphClient: Memory stored successfully",i),i}catch(r){throw t.debug&&console.debug("TenxGraphClient: Store memory failed:",r),r}}var _e=(t=>(t.SIMILARITY="similarity",t.TEMPORAL="temporal",t.RELEVANCE="relevance",t.HYBRID="hybrid",t.GRAPH_TRAVERSAL="graph_traversal",t))(_e||{}),Ge=(t=>(t.COSINE="cosine",t.EUCLIDEAN="euclidean",t.DOT_PRODUCT="dot_product",t.MANHATTAN="manhattan",t))(Ge||{});async function Se(t,e){try{t.debug&&console.debug("TenxGraphClient: Searching memories with query:",e.query);const r=new AbortController,o=setTimeout(()=>r.abort(),t.timeout),s=`${t.baseUrl}/v1/store/search`,n={config:e.config||{},options:e.options||{},query:e.query,memory_type:e.memory_type||M.EPISODIC,category:e.category||"",limit:e.limit!==void 0?e.limit:10,score_threshold:e.score_threshold!==void 0?e.score_threshold:0,filters:e.filters||{},retrieval_strategy:e.retrieval_strategy||"similarity",distance_metric:e.distance_metric||"cosine",max_tokens:e.max_tokens!==void 0?e.max_tokens:4e3},a=await fetch(s,{method:"POST",headers:m(t,{"Content-Type":"application/json"}),...f(t),body:JSON.stringify(n),signal:r.signal});if(clearTimeout(o),!a.ok)throw console.warn(`TenxGraphClient: Search memory failed with HTTP ${a.status}`),await p(a,"Search memory request failed","/v1/memory/search","POST");const i=await a.json();return t.debug&&console.info("TenxGraphClient: Memory search successful",{query:e.query,results_count:i.data.results.length}),i}catch(r){throw t.debug&&console.debug("TenxGraphClient: Search memory failed:",r),r}}async function Re(t,e){try{t.debug&&console.debug("TenxGraphClient: Fetching memory with ID:",e.memoryId);const r=new AbortController,o=setTimeout(()=>r.abort(),t.timeout),s=`${t.baseUrl}/v1/store/memories/${e.memoryId}`,n={config:e.config||{},options:e.options||{}},a=await fetch(s,{method:"POST",headers:m(t,{"Content-Type":"application/json"}),...f(t),body:JSON.stringify(n),signal:r.signal});if(clearTimeout(o),!a.ok)throw console.warn(`TenxGraphClient: Get memory failed with HTTP ${a.status}`),await p(a,"Get memory request failed","/v1/memory/{memory_id}","GET");const i=await a.json();return t.debug&&console.info("TenxGraphClient: Memory fetched successfully",{memory_id:e.memoryId,content:i.data.memory.content.substring(0,50)}),i}catch(r){throw t.debug&&console.debug("TenxGraphClient: Get memory failed:",r),r}}async function ve(t,e){try{t.debug&&console.debug("TenxGraphClient: Updating memory with ID:",e.memoryId);const r=new AbortController,o=setTimeout(()=>r.abort(),t.timeout),s=`${t.baseUrl}/v1/store/memories/${e.memoryId}`,n={config:e.config||{},options:e.options||{},content:e.content,metadata:e.metadata||{}};t.debug&&console.debug("TenxGraphClient: Request payload:",JSON.stringify(n,null,2));const a=await fetch(s,{method:"PUT",headers:m(t,{"Content-Type":"application/json"}),...f(t),body:JSON.stringify(n),signal:r.signal});if(clearTimeout(o),!a.ok)throw console.warn(`TenxGraphClient: Update memory failed with HTTP ${a.status}`),await p(a,"Update memory request failed","/v1/memory/{memory_id}","PUT");const i=await a.json();return t.debug&&console.info("TenxGraphClient: Memory updated successfully",{memory_id:e.memoryId,success:i.data.success}),i}catch(r){throw t.debug&&console.debug("TenxGraphClient: Update memory failed:",r),r}}async function ke(t,e){try{t.debug&&console.debug("TenxGraphClient: Deleting memory with ID:",e.memoryId);const r=new AbortController,o=setTimeout(()=>r.abort(),t.timeout),s=`${t.baseUrl}/v1/store/memories/${e.memoryId}`,n={config:e.config||{},options:e.options||{}};t.debug&&console.debug("TenxGraphClient: Delete request payload:",JSON.stringify(n,null,2));const a=await fetch(s,{method:"DELETE",headers:m(t,{"Content-Type":"application/json",accept:"application/json"}),...f(t),body:JSON.stringify(n),signal:r.signal});if(clearTimeout(o),!a.ok)throw console.warn(`TenxGraphClient: Delete memory failed with HTTP ${a.status}`),await p(a,"Delete memory request failed","/v1/memory/{memory_id}","DELETE");const i=await a.json();return t.debug&&console.info("TenxGraphClient: Memory deleted successfully",{memory_id:e.memoryId,success:i.data.success}),i}catch(r){throw r.name==="AbortError"?(console.warn(`TenxGraphClient: Delete memory timeout after ${t.timeout}ms`),new Error(`Request timeout after ${t.timeout}ms`)):(t.debug&&console.debug("TenxGraphClient: Delete memory failed:",r),r)}}async function Ae(t,e){try{t.debug&&console.debug("TenxGraphClient: Fetching list of memories",{limit:e.limit});const r=new AbortController,o=setTimeout(()=>r.abort(),t.timeout),s=`${t.baseUrl}/v1/store/memories/list`,n={config:e.config||{},options:e.options||{},limit:e.limit||100};t.debug&&console.debug("TenxGraphClient: List memories request payload:",JSON.stringify(n,null,2));const a=await fetch(s,{method:"POST",headers:m(t,{"Content-Type":"application/json",accept:"application/json"}),...f(t),body:JSON.stringify(n),signal:r.signal});if(clearTimeout(o),!a.ok)throw console.warn(`TenxGraphClient: List memories failed with HTTP ${a.status}`),await p(a,"List memories request failed","/v1/memory","GET");const i=await a.json();return t.debug&&console.info("TenxGraphClient: Memories list fetched successfully",{count:i.data.memories.length,limit:e.limit}),i}catch(r){throw r.name==="AbortError"?(console.warn(`TenxGraphClient: List memories timeout after ${t.timeout}ms`),new Error(`Request timeout after ${t.timeout}ms`)):(t.debug&&console.debug("TenxGraphClient: List memories failed:",r),r)}}async function $e(t,e){try{const r=`${t.baseUrl}/v1/store/memories/forget`,o={};e.config&&(o.config=e.config),e.options&&(o.options=e.options),e.memory_type&&(o.memory_type=e.memory_type),e.category&&(o.category=e.category),e.filters&&(o.filters=e.filters),t.debug&&console.log("[DEBUG] Forget memories request:",o);const s=new AbortController;let n;t.timeout>0&&(n=setTimeout(()=>s.abort(),t.timeout));const a=await fetch(r,{method:"POST",headers:m(t,{"Content-Type":"application/json"}),...f(t),body:JSON.stringify(o),...t.timeout>0&&{signal:s.signal}});if(n&&clearTimeout(n),!a.ok)throw new Error(`Forget memories failed: ${a.status} ${a.statusText}`);const i=await a.json();return t.debug&&console.log("[DEBUG] Forget memories response:",i),i}catch(r){throw r.name==="AbortError",r}}async function Ie(t,e){try{t.debug&&console.debug("TenxGraphClient: Stopping graph execution for thread:",e.thread_id);const r=new AbortController,o=setTimeout(()=>r.abort(),t.timeout),s=await fetch(`${t.baseUrl}/v1/graph/stop`,{method:"POST",headers:m(t,{"Content-Type":"application/json",accept:"application/json"}),...f(t),body:JSON.stringify(e),signal:r.signal});if(clearTimeout(o),!s.ok)throw console.warn(`TenxGraphClient: Stop graph failed with HTTP ${s.status}`),await p(s,"Stop graph execution failed","/v1/graph/stop","POST");const n=await s.json();return t.debug&&console.info("TenxGraphClient: Graph execution stopped successfully",n),n}catch(r){throw t.debug&&console.debug("TenxGraphClient: Stop graph failed:",r),r.name==="AbortError"?(console.warn(`TenxGraphClient: Stop graph timeout after ${t.timeout}ms`),new Error(`Request timeout after ${t.timeout}ms`)):(console.error("TenxGraphClient: Stop graph failed:",r),r)}}async function Oe(t,e){try{t.debug&&console.debug("TenxGraphClient: Fixing graph state for thread:",e.thread_id);const r=new AbortController,o=setTimeout(()=>r.abort(),t.timeout),s=await fetch(`${t.baseUrl}/v1/graph/fix`,{method:"POST",headers:m(t,{"Content-Type":"application/json",accept:"application/json"}),...f(t),body:JSON.stringify(e),signal:r.signal});if(clearTimeout(o),!s.ok)throw console.warn(`TenxGraphClient: Fix graph failed with HTTP ${s.status}`),await p(s,"Fix graph state failed","/v1/graph/fix","POST");const n=await s.json();return t.debug&&console.info("TenxGraphClient: Graph state fixed successfully",{removed_count:n.data.removed_count,success:n.data.success}),n}catch(r){throw t.debug&&console.debug("TenxGraphClient: Fix graph failed:",r),r.name==="AbortError"?(console.warn(`TenxGraphClient: Fix graph timeout after ${t.timeout}ms`),new Error(`Request timeout after ${t.timeout}ms`)):(console.error("TenxGraphClient: Fix graph failed:",r),r)}}async function Ne(t,e){const r=new AbortController,o=setTimeout(()=>r.abort(),t.timeout);try{const s=new FormData;typeof File<"u"&&e instanceof File?s.append("file",e,e.name):"data"in e&&"filename"in e?s.append("file",e.data,e.filename):s.append("file",e,"upload");const n=await fetch(`${t.baseUrl}/v1/files/upload`,{method:"POST",headers:m(t),body:s,...f(t),signal:r.signal});if(clearTimeout(o),!n.ok)throw await p(n,"File upload failed","/v1/files/upload","POST");return await n.json()}finally{clearTimeout(o)}}async function Ue(t,e){const r=new AbortController,o=setTimeout(()=>r.abort(),t.timeout);try{const s=await fetch(`${t.baseUrl}/v1/files/${encodeURIComponent(e)}`,{method:"GET",headers:m(t),...f(t),signal:r.signal});if(clearTimeout(o),!s.ok)throw await p(s,"File download failed",`/v1/files/${e}`,"GET");return await s.blob()}finally{clearTimeout(o)}}async function je(t,e){const r=new AbortController,o=setTimeout(()=>r.abort(),t.timeout);try{const s=await fetch(`${t.baseUrl}/v1/files/${encodeURIComponent(e)}/info`,{method:"GET",headers:m(t),...f(t),signal:r.signal});if(clearTimeout(o),!s.ok)throw await p(s,"File info request failed",`/v1/files/${e}/info`,"GET");return await s.json()}finally{clearTimeout(o)}}async function Pe(t,e){const r=new AbortController,o=setTimeout(()=>r.abort(),t.timeout);try{const s=await fetch(`${t.baseUrl}/v1/files/${encodeURIComponent(e)}/url`,{method:"GET",headers:m(t),...f(t),signal:r.signal});if(clearTimeout(o),!s.ok)throw await p(s,"File access URL request failed",`/v1/files/${e}/url`,"GET");return await s.json()}finally{clearTimeout(o)}}async function xe(t){const e=new AbortController,r=setTimeout(()=>e.abort(),t.timeout);try{const o=await fetch(`${t.baseUrl}/v1/config/multimodal`,{method:"GET",headers:m(t,{accept:"application/json"}),...f(t),signal:e.signal});if(clearTimeout(r),!o.ok)throw await p(o,"Multimodal config request failed","/v1/config/multimodal","GET");return await o.json()}finally{clearTimeout(r)}}function ft(t){return typeof t=="object"&&t!==null}function pt(t,e,r){return ft(t)?{search:t.search,offset:t.offset,limit:t.limit}:{search:t,offset:e,limit:r}}function gt(t){return typeof t=="object"&&t!==null}function Tt(t,e,r,o){return gt(e)?{threadId:t,search:e.search,offset:e.offset,limit:e.limit}:{threadId:t,search:e,offset:r,limit:o}}class Me{constructor(e){this.baseUrl=e.baseUrl,this.authToken=e.authToken,this.auth=e.auth,this.headers=e.headers,this.credentials=e.credentials,this.timeout=e.timeout||3e5,this.debug=e.debug||!1,this.webSocketImpl=e.webSocketImpl,this.toolExecutor=new W([])}createContext(){return{baseUrl:this.baseUrl,authToken:this.authToken,auth:this.auth,headers:this.headers,credentials:this.credentials,timeout:this.timeout,debug:this.debug,webSocketImpl:this.webSocketImpl}}registerTool(e){this.toolExecutor.registerTool(e),this.debug&&console.debug(`TenxGraphClient: Registered remote tool handler '${e.name}'`)}registerToolHandler(e,r){this.registerTool({name:e,handler:r})}async ping(){const e=this.createContext();return te(e)}async graph(){const e=this.createContext();return re(e)}async graphTools(){const e=this.createContext();return oe(e)}async observability(e,r){const o=this.createContext();return se(o,e,r)}async stopGraph(e,r){const o=this.createContext();return Ie(o,{thread_id:e,config:r})}async fixGraph(e,r){const o=this.createContext();return Oe(o,{thread_id:e,config:r})}async graphStateSchema(){const e=this.createContext();return ne(e)}async threadState(e){const r=this.createContext();return ae(r,e)}async updateThreadState(e,r,o){const s=this.createContext();return ie(s,e,{config:r,state:o})}async clearThreadState(e){const r=this.createContext();return le(r,e)}async threadDetails(e){const r=this.createContext();return de(r,e)}async threads(e,r,o){const s=this.createContext(),n=pt(e,r,o);return fe(s,n)}async threadMessages(e,r,o,s){const n=this.createContext(),a=Tt(e,r,o,s);return N(n,a)}async addThreadMessages(e,r,o={},s){const n=this.createContext();return ce(n,{threadId:e,config:o,messages:r,metadata:s})}async singleMessage(e,r){const o=this.createContext();return he(o,{threadId:e,messageId:r})}async deleteMessage(e,r,o){const s=this.createContext();return ue(s,{threadId:e,messageId:r,config:o})}async deleteThread(e,r){const o=this.createContext();return me(o,{threadId:e,config:r})}async invoke(e,r){const o={...this.createContext(),toolExecutor:this.toolExecutor},s={messages:e.map(n=>this.serializeMessage(n)),initial_state:r?.initial_state,config:r?.config,recursion_limit:r?.recursion_limit||25,response_granularity:r?.response_granularity||"full"};return pe(o,s,r?.onPartialResult)}stream(e,r){const o={...this.createContext(),toolExecutor:this.toolExecutor},s={messages:e.map(n=>this.serializeMessage(n)),initial_state:r?.initial_state,config:r?.config,recursion_limit:r?.recursion_limit||25,response_granularity:r?.response_granularity||"low"};return ge(o,s)}wsStream(e,r){const o={...this.createContext(),toolExecutor:this.toolExecutor},s={messages:e.map(n=>this.serializeMessage(n)),initial_state:r?.initial_state,config:r?.config,recursion_limit:r?.recursion_limit??25,response_granularity:r?.response_granularity??"low"};return we(o,s)}realtime(e,r){const o=this.createContext();return new Ce(o,e,r)}async storeMemory(e){const r=this.createContext();return Ee(r,e)}async searchMemory(e){const r=this.createContext();return Se(r,e)}async getMemory(e,r){const o=this.createContext(),s={memoryId:e,config:r?.config,options:r?.options};return Re(o,s)}async updateMemory(e,r,o){const s=this.createContext(),n={memoryId:e,content:r,config:o?.config,options:o?.options,metadata:o?.metadata};return ve(s,n)}async deleteMemory(e,r){const o=this.createContext(),s={memoryId:e,config:r?.config,options:r?.options};return ke(o,s)}async listMemories(e){const r=this.createContext(),o={config:e?.config,options:e?.options,limit:e?.limit};return Ae(r,o)}async forgetMemories(e){const r=this.createContext(),o={config:e?.config,options:e?.options,memory_type:e?.memory_type,category:e?.category,filters:e?.filters};return $e(r,o)}async uploadFile(e){const r=this.createContext();return Ne(r,e)}async getFile(e){const r=this.createContext();return Ue(r,e)}async getFileInfo(e){const r=this.createContext();return je(r,e)}async getFileAccessUrl(e){const r=this.createContext();return Pe(r,e)}async getMultimodalConfig(){const e=this.createContext();return xe(e)}serializeMessage(e){const r={role:e.role,content:this.cleanContent(e.content)};return e.message_id!==null&&e.message_id!==void 0?r.message_id=String(e.message_id):r.message_id="0",e.tools_calls&&(r.tools_calls=e.tools_calls),e.metadata&&Object.keys(e.metadata).length>0&&(r.metadata=e.metadata),r}cleanContent(e){return e.map(r=>{const o={};for(const[s,n]of Object.entries(r))Array.isArray(n)&&n.length===0||n!==void 0&&(o[s]=n);return o})}}class yt{constructor(){this.current_node="START",this.step=0,this.is_running=!0,this.is_interrupted=!1,this.is_stopped_requested=!1}}class wt{constructor(e={}){this.context=[],this.context_summary=null,this.execution_meta=new yt,Object.assign(this,e)}}const bt=Me,Ct=g;exports.AgentFlowClient=bt;exports.AgentFlowError=Ct;exports.AgentState=wt;exports.AnnotationBlock=We;exports.AnnotationRef=Be;exports.AudioBlock=F;exports.AuthenticationError=k;exports.BadRequestError=v;exports.DataBlock=Fe;exports.DistanceMetric=Ge;exports.DocumentBlock=H;exports.ErrorBlock=ze;exports.GraphError=z;exports.GraphRecursionError=Y;exports.ImageBlock=R;exports.MediaRef=b;exports.MemoryType=M;exports.Message=C;exports.MetricsError=Q;exports.NodeError=V;exports.NotFoundError=$;exports.PermissionError=A;exports.REALTIME_INPUT_SAMPLE_RATE=ht;exports.REALTIME_OUTPUT_SAMPLE_RATE=be;exports.RealtimeSession=Ce;exports.ReasoningBlock=Je;exports.RemoteToolCallBlock=He;exports.RetrievalStrategy=_e;exports.SchemaVersionError=X;exports.SerializationError=q;exports.ServerError=O;exports.StorageError=K;exports.StreamEventType=U;exports.TenxGraphClient=Me;exports.TenxGraphError=g;exports.TextBlock=S;exports.TokenUsages=Ve;exports.ToolCallBlock=Le;exports.ToolExecutor=W;exports.ToolResultBlock=G;exports.TransientStorageError=Z;exports.ValidationError=I;exports.VideoBlock=L;exports.WS_BEARER_SUBPROTOCOL=Te;exports.addThreadMessages=ce;exports.basicAuth=Xe;exports.bearerAuth=Qe;exports.buildHeaders=m;exports.buildWsUrl=P;exports.checkpointMessages=et;exports.clearThreadState=le;exports.createErrorFromResponse=p;exports.deleteMemory=ke;exports.deleteThread=me;exports.deleteThreadMessage=ue;exports.fixGraph=Oe;exports.forgetMemories=$e;exports.getFile=Ue;exports.getFileAccessUrl=Pe;exports.getFileInfo=je;exports.getMemory=Re;exports.getMultimodalConfig=xe;exports.getRequestCredentials=f;exports.graph=re;exports.graphTools=oe;exports.headerAuth=qe;exports.invoke=pe;exports.listMemories=Ae;exports.normalizeToolParameters=J;exports.observability=se;exports.openWebSocket=x;exports.parseErrorResponse=ee;exports.ping=te;exports.resolveBearerToken=ye;exports.searchMemory=Se;exports.serializeMessage=j;exports.stateSchema=ne;exports.stopGraph=Ie;exports.storeMemory=Ee;exports.streamInvoke=ge;exports.threadDetails=de;exports.threadMessage=he;exports.threadMessages=N;exports.threadState=ae;exports.threads=fe;exports.updateMemory=ve;exports.updateThreadState=ie;exports.uploadFile=Ne;exports.wsStreamInvoke=we;
5
+ `),s=t.slice(0,o).trim();if(t=t.slice(o+1),s)try{const n=JSON.parse(s);e&&console.debug("TenxGraphClient: Stream chunk received (NDJSON):",n.event),yield n}catch(n){throw X(s,n)}}for(;t.trim();){const o=Lt(t);if(o)try{const s=JSON.parse(o.json);e&&console.debug("TenxGraphClient: Stream chunk received (concat):",s.event),yield s,t=o.remaining}catch(s){throw X(o.json,s)}else{if(r&&t.trim())try{const s=JSON.parse(t.trim());e&&console.debug("TenxGraphClient: Final stream chunk:",s.event),yield s,t=""}catch(s){throw X(t.trim(),s)}break}}return{remaining:t}}function Lt(t){if(t=t.trim(),!t||t[0]!=="{")return null;let e=0,r=!1,o=!1;for(let s=0;s<t.length;s++){const n=t[s];if(o){o=!1;continue}if(n==="\\"){o=!0;continue}if(n==='"'){r=!r;continue}if(!r){if(n==="{")e++;else if(n==="}"&&(e--,e===0))return{json:t.slice(0,s+1),remaining:t.slice(s+1).trim()}}}return null}function Dt(t){return t.some(e=>e.content&&e.content.some(r=>r.type==="remote_tool_call"))}async function*xe(t,e){const r=e.recursion_limit??25,o=Math.max(1,r),s=t.timeout>0?t.timeout:0;t.debug&&(console.debug("TenxGraphClient: Starting stream invoke with recursion_limit:",r),console.debug("TenxGraphClient: Initial request:",JSON.stringify(e,null,2)));let n=e.messages,a=0;const i=e.initial_state;let c=e.config;const l=e.response_granularity,y=e.on_busy,g=e.resume,b=e.interrupt_id;for(;;){t.signal?.throwIfAborted(),a++,t.debug&&console.debug(`TenxGraphClient: Stream iteration ${a}/${o}`);const R={messages:n,initial_state:a===1?i:void 0,config:c,recursion_limit:r,on_busy:y,resume:a===1?g:void 0,interrupt_id:a===1?b:void 0,response_granularity:l};t.debug&&console.debug("TenxGraphClient: Stream request payload:",JSON.stringify(R,null,2));const m=new AbortController;let S;const $=()=>{S!==void 0&&clearTimeout(S),S=void 0},v=()=>{$(),s>0&&(S=setTimeout(()=>m.abort(),s))},p=z(m,t.signal);let w=!1,k=!1;try{v();let E;try{E=await fetch(`${t.baseUrl}${M}`,{method:"POST",headers:d(t,{"Content-Type":"application/json",Accept:"application/x-ndjson, application/json"}),...h(t),body:JSON.stringify(R),signal:m.signal})}catch(_){throw _ instanceof TypeError?new L(`Network error: ${_.message}`,M,"POST",_):_}if($(),!E.ok)throw console.warn(`TenxGraphClient: Stream failed with HTTP ${E.status}`),v(),await u(E,"Stream request failed",M,"POST");if(!E.body)throw new Error("No response body for stream");const G=[],x=E.body.getReader();for await(const _ of Mt(x,t.debug,{beforeRead:v,afterRead:$})){yield _;const j=_.thread_id||_.metadata?.thread_id;j&&!c?.thread_id&&(c={...c??{},thread_id:j}),_.event==="error"&&(k=!0),_.message&&G.push(_.message)}if(w=!0,t.debug&&(console.info("TenxGraphClient: Stream iteration completed"),console.debug("TenxGraphClient: Received",G.length,"messages")),Dt(G)&&t.toolExecutor&&!k){if(a>=o){t.debug&&console.warn(`TenxGraphClient: Recursion limit of ${r} reached`),yield{event:"error",data:{recursion_limit_reached:!0,message:`Recursion limit of ${r} reached with tool calls still pending`},thread_id:c?.thread_id};break}t.debug&&console.debug("TenxGraphClient: Found remote tool calls, executing...");const _=await t.toolExecutor.executeToolCalls(G);t.debug&&console.debug(`TenxGraphClient: Executed ${_.length} tool calls`),n=_.map(j=>U(j));continue}else{t.debug&&console.debug("TenxGraphClient: No remote tool calls found, finishing");break}}catch(E){throw E.name==="AbortError"?t.signal?.aborted?E:(console.warn(`TenxGraphClient: Stream timeout after ${t.timeout}ms`),new D(t.timeout,M,"POST",E)):(console.error("TenxGraphClient: Stream failed:",E),E)}finally{$(),p(),w||m.abort()}}t.debug&&console.debug(`TenxGraphClient: Stream invoke completed after ${a} iterations`)}function Bt(t){return t.map(e=>{const r={};for(const[o,s]of Object.entries(e))s!==void 0&&(r[o]=s);return r})}function U(t){const e={role:t.role,content:Bt(t.content)};return t.message_id!==null&&t.message_id!==void 0?e.message_id=String(t.message_id):e.message_id="0",t.tools_calls&&(e.tools_calls=t.tools_calls),t.metadata&&Object.keys(t.metadata).length>0&&(e.metadata=t.metadata),e}async function Me(t,e){try{t.debug&&console.debug("TenxGraphClient: Adding thread messages to thread",e.threadId);const r=`${t.baseUrl}/v1/threads/${C(e.threadId)}/messages`,o={config:e.config,messages:e.messages.map(a=>U(a)),metadata:e.metadata||{}},s=await f(t,r,{method:"POST",headers:d(t,{"Content-Type":"application/json"}),...h(t),body:JSON.stringify(o)});if(!s.ok)throw console.warn(`TenxGraphClient: Add checkpoint messages failed with HTTP ${s.status}`),await u(s,"Add thread messages failed","/v1/threads/{thread_id}/messages","POST");const n=await s.json();return t.debug&&console.info("TenxGraphClient: Thread messages added successfully",n),n}catch(r){throw t.debug&&console.debug("TenxGraphClient: Add checkpoint messages failed:",r),r}}async function Le(t,e){try{t.debug&&console.debug("TenxGraphClient: Fetching thread message",`thread: ${e.threadId}`,`message: ${e.messageId}`);const r=`${t.baseUrl}/v1/threads/${C(e.threadId)}/messages/${C(e.messageId)}`,o=await f(t,r,{method:"GET",headers:d(t,{"Content-Type":"application/json"}),...h(t)});if(!o.ok)throw console.warn(`TenxGraphClient: Thread message fetch failed with HTTP ${o.status}`),await u(o,"Thread message fetch failed","/v1/threads/{thread_id}/messages/{message_id}","GET");const s=await o.json();return t.debug&&console.info("TenxGraphClient: Thread message fetched successfully",s),s}catch(r){throw t.debug&&console.debug("TenxGraphClient: Thread message fetch failed:",r),r}}async function De(t,e){try{t.debug&&console.debug(`TenxGraphClient: Fetching thread details for thread ${e}`);const r=`${t.baseUrl}/v1/threads/${C(e)}`,o=await f(t,r,{method:"GET",headers:d(t,{"Content-Type":"application/json",accept:"application/json"}),...h(t)});if(!o.ok)throw console.warn(`TenxGraphClient: Thread details fetch failed with HTTP ${o.status}`),await u(o,"Thread details fetch failed","/v1/threads/{thread_id}","GET");const s=await o.json();return t.debug&&console.info("TenxGraphClient: Thread details fetched successfully",s),s}catch(r){throw t.debug&&console.debug("TenxGraphClient: Thread details fetch failed:",r),r}}async function Be(t,e){try{t.debug&&console.debug("TenxGraphClient: Deleting thread message",`thread: ${e.threadId}`,`message: ${e.messageId}`);const r=`${t.baseUrl}/v1/threads/${C(e.threadId)}/messages/${C(e.messageId)}`,o=await f(t,r,{method:"DELETE",headers:d(t,{"Content-Type":"application/json",accept:"application/json"}),...h(t),body:JSON.stringify({config:e.config||{}})});if(!o.ok)throw console.warn(`TenxGraphClient: Delete thread message failed with HTTP ${o.status}`),await u(o,"Delete thread message failed","/v1/threads/{thread_id}/messages/{message_id}","DELETE");const s=await o.json();return t.debug&&console.info("TenxGraphClient: Thread message deleted successfully",s),s}catch(r){throw t.debug&&console.debug("TenxGraphClient: Delete thread message failed:",r),r}}async function Fe(t,e){try{t.debug&&console.debug("TenxGraphClient: Updating thread message feedback",`thread: ${e.threadId}`,`message: ${e.messageId}`);const r=`${t.baseUrl}/v1/threads/${C(e.threadId)}/messages/${C(e.messageId)}`,o=await f(t,r,{method:"PUT",headers:d(t,{"Content-Type":"application/json",accept:"application/json"}),...h(t),body:JSON.stringify({feedback:e.feedback})});if(!o.ok)throw console.warn(`TenxGraphClient: Update thread message feedback failed with HTTP ${o.status}`),await u(o,"Update thread message feedback failed","/v1/threads/{thread_id}/messages/{message_id}","PUT");const s=await o.json();return t.debug&&console.info("TenxGraphClient: Thread message feedback updated successfully",s),s}catch(r){throw t.debug&&console.debug("TenxGraphClient: Update thread message feedback failed:",r),r}}async function He(t,e){try{t.debug&&console.debug("TenxGraphClient: Deleting thread",`thread: ${e.threadId}`);const r=`${t.baseUrl}/v1/threads/${C(e.threadId)}`,o=await f(t,r,{method:"DELETE",headers:d(t,{"Content-Type":"application/json",accept:"application/json"}),...h(t),body:JSON.stringify({config:e.config||{}})});if(!o.ok)throw console.warn(`TenxGraphClient: Delete thread failed with HTTP ${o.status}`),await u(o,"Delete thread failed","/v1/threads/{thread_id}","DELETE");const s=await o.json();return t.debug&&console.info("TenxGraphClient: Thread deleted successfully",s),s}catch(r){throw t.debug&&console.debug("TenxGraphClient: Delete thread failed:",r),r}}async function We(t,e){try{t.debug&&(console.debug("TenxGraphClient: Fetching threads list"),e?.search&&console.debug(` Search: ${e.search}`),e?.offset!==void 0&&console.debug(` Offset: ${e.offset}`),e?.limit!==void 0&&console.debug(` Limit: ${e.limit}`));const r=new URLSearchParams;e?.search&&r.append("search",e.search),e?.offset!==void 0&&r.append("offset",e.offset.toString()),e?.limit!==void 0&&r.append("limit",e.limit.toString());const o=r.toString(),s=`${t.baseUrl}/v1/threads${o?`?${o}`:""}`,n=await f(t,s,{method:"GET",headers:d(t,{"Content-Type":"application/json",accept:"application/json"}),...h(t)});if(!n.ok)throw console.warn(`TenxGraphClient: Threads list fetch failed with HTTP ${n.status}`),await u(n,"Threads list fetch failed","/v1/threads","GET");const a=await n.json();return t.debug&&(console.info("TenxGraphClient: Threads list fetched successfully",a),console.debug(` Found ${a.data.threads.length} threads`)),a}catch(r){throw t.debug&&console.debug("TenxGraphClient: Threads list fetch failed:",r),r}}async function Ft(t,e){const r=new AbortController,o=t.timeout>0?setTimeout(()=>r.abort(),t.timeout):void 0,s=z(r,t.signal);try{let n;try{n=await fetch(`${t.baseUrl}/v1/graph/invoke`,{method:"POST",headers:d(t,{"Content-Type":"application/json",accept:"application/json"}),...h(t),body:JSON.stringify(e),signal:r.signal})}catch(i){throw i instanceof TypeError?new L(`Network error: ${i.message}`,"/v1/graph/invoke","POST",i):i}if(!n.ok)throw console.warn(`TenxGraphClient: Invoke failed with HTTP ${n.status}`),await u(n,"Invoke request failed","/v1/graph/invoke","POST");const a=await n.json();if(!a||typeof a!="object"||!a.data||typeof a.data!="object")throw new W("Invoke response had no data object","INVALID_RESPONSE","unknown","/v1/graph/invoke","POST");return Array.isArray(a.data.messages)||(a.data.messages=[]),a}catch(n){throw n.name==="AbortError"?t.signal?.aborted?n:(console.warn(`TenxGraphClient: Invoke timeout after ${t.timeout}ms`),new D(t.timeout,"/v1/graph/invoke","POST",n)):(console.error("TenxGraphClient: Invoke failed:",n),n)}finally{o!==void 0&&clearTimeout(o),s()}}function Ht(t){return!t.data||!t.data.messages?!1:t.data.messages.some(e=>e.content&&e.content.some(r=>r.type==="remote_tool_call"))}async function Je(t,e,r){const o=e.recursion_limit??25,s=Math.max(1,o);t.debug&&(console.debug("TenxGraphClient: Starting invoke with recursion_limit:",o),console.debug("TenxGraphClient: Initial request:",JSON.stringify(e,null,2)));const n=[];let a=e.messages,i=0,c=!1,l;const y=e.initial_state;let g=e.config;const b=e.response_granularity,R=e.on_busy,m=e.resume,S=e.interrupt_id;for(;;){t.signal?.throwIfAborted(),i++,t.debug&&console.debug(`TenxGraphClient: Iteration ${i}/${s}`);const v={messages:a,initial_state:i===1?y:void 0,config:g,recursion_limit:o,on_busy:R,resume:i===1?m:void 0,interrupt_id:i===1?S:void 0,response_granularity:b};t.debug&&console.debug("TenxGraphClient: Request payload:",JSON.stringify(v,null,2));const p=await Ft(t,v);l=p;const w=p.data.meta?.thread_id;w&&!g?.thread_id&&(g={...g??{},thread_id:w}),t.debug&&(console.info("TenxGraphClient: Invoke successful"),console.debug("TenxGraphClient: Response:",JSON.stringify(p,null,2))),p.data.messages&&n.push(...p.data.messages);const k=Ht(p),E=k&&!!t.toolExecutor&&i<s;if(r){const G={iteration:i,messages:p.data.messages,state:p.data.state,context:p.data.context,summary:p.data.summary,meta:p.data.meta,has_tool_calls:k,is_final:!E};await r(G)}if(k&&t.toolExecutor&&i>=s){c=!0,t.debug&&console.warn(`TenxGraphClient: Recursion limit of ${o} reached`);break}if(k&&t.toolExecutor){t.debug&&console.debug("TenxGraphClient: Found remote tool calls, executing...");const G=await t.toolExecutor.executeToolCalls(p.data.messages);t.debug&&console.debug(`TenxGraphClient: Executed ${G.length} tool calls`),n.push(...G),a=G.map(x=>U(x));continue}else{t.debug&&console.debug("TenxGraphClient: No remote tool calls found, finishing");break}}const $={messages:l?.data.messages||[],state:l?.data.state,context:l?.data.context,summary:l?.data.summary,meta:l?.data.meta||{is_new_thread:!1,thread_id:""},all_messages:n,iterations:i,recursion_limit_reached:c};return t.debug&&(console.debug(`TenxGraphClient: Invoke completed after ${i} iterations`),console.debug(`TenxGraphClient: Total messages: ${n.length}`)),$}const Ve="10xgraph-bearer";function ze(t){return t.auth?t.auth.type==="bearer"?t.auth.token:null:t.authToken?t.authToken:null}function ee(t,e){return t.baseUrl.replace(/^https:/,"wss:").replace(/^http:/,"ws:").replace(/\/$/,"")+e}function te(t,e){const r=e.webSocketImpl??globalThis.WebSocket;if(!r)throw new Error("No WebSocket implementation available. In Node < 21 pass `webSocketImpl` in the client config (e.g. the `ws` package: `new TenxGraphClient({ ..., webSocketImpl: WebSocket })`).");const o=ze(e),s=o?[Ve,o]:void 0,n=d(e),a=n.Authorization??n.authorization;if(a)try{return new r(t,s,{headers:{Authorization:a}})}catch{}return new r(t,s)}const N="/v1/graph/ws";function Wt(t){return t.some(e=>e.content&&e.content.some(r=>r.type==="remote_tool_call"))}async function*Ye(t,e){t.signal?.throwIfAborted();const r=ee(t,N);t.debug&&console.debug("TenxGraphClient [WS]: connecting to",r);const o=te(r,t),s=e.recursion_limit??25,n=Math.max(1,s),a=t.timeout>0?t.timeout:0,i=[];let c=null;const l=m=>{if(i.push(m),c){const S=c;c=null,S()}},y=()=>new Promise(m=>{i.length>0?m():c=m}),g=async()=>{let m;a>0&&(m=setTimeout(()=>l(new D(a,N,"WS")),a));try{await y()}finally{m!==void 0&&clearTimeout(m)}return i.shift()};o.addEventListener("message",m=>{try{const S=JSON.parse(m.data);l(S)}catch(S){l(new W("WebSocket frame could not be parsed as JSON","STREAM_TRUNCATED","unknown",N,"WS",S))}}),o.addEventListener("error",()=>{l(new F("WebSocket error",void 0,N))}),o.addEventListener("close",m=>{t.debug&&console.debug("TenxGraphClient [WS]: connection closed, code=",m.code),l({closed:!0,code:m.code})});const b=()=>{const m=new Error("The operation was aborted");return m.name="AbortError",m},R=()=>{l(b()),(o.readyState===1||o.readyState===0)&&o.close(1e3)};t.signal?.addEventListener("abort",R,{once:!0});try{await new Promise((v,p)=>{if(t.signal?.aborted){p(b());return}if(o.readyState===1){v();return}let w;const k=()=>{w!==void 0&&clearTimeout(w),o.removeEventListener("open",E),o.removeEventListener("error",G),o.removeEventListener("close",x),t.signal?.removeEventListener("abort",Y)},E=()=>{k(),v()},G=()=>{k(),p(new F("WebSocket connection failed",void 0,N))},x=_=>{k();const j=_?.code;p(new F(`WebSocket closed before it opened (code ${j})`,j,N))},Y=()=>{k(),p(b())};o.addEventListener("open",E),o.addEventListener("error",G),o.addEventListener("close",x),t.signal?.addEventListener("abort",Y,{once:!0}),a>0&&(w=setTimeout(()=>{k(),p(new D(a,N,"WS"))},a))}),i.length=0,t.debug&&console.debug("TenxGraphClient [WS]: connected");let m=e.config?.thread_id,S=0,$={invoke_type:"fresh",messages:e.messages,initial_state:e.initial_state,config:e.config,recursion_limit:s,on_busy:e.on_busy,resume:e.resume,interrupt_id:e.interrupt_id,response_granularity:e.response_granularity};e:for(;;){S++,t.debug&&console.debug(`TenxGraphClient [WS]: sending ${$.invoke_type} request, thread_id=${m??"new"}`),o.send(JSON.stringify($));const v=[];t:for(;;){const p=await g();if("closed"in p)throw new F(`WebSocket closed before the run finished (code ${p.code})`,p.code,N);if(p instanceof Error)throw p;const w=p;if(w.thread_id&&(m=w.thread_id),w.metadata?.thread_id&&(m=w.metadata.thread_id),w.event===H.UPDATES&&w.data?.status==="done")break t;if(w.message&&v.push(w.message),yield w,w.event===H.ERROR)break e}if(t.debug&&console.debug(`TenxGraphClient [WS]: run complete, ${v.length} messages collected`),Wt(v)&&t.toolExecutor){if(S>=n){t.debug&&console.warn(`TenxGraphClient [WS]: recursion limit of ${s} reached`),yield{event:H.ERROR,data:{recursion_limit_reached:!0,message:`Recursion limit of ${s} reached with tool calls still pending`},thread_id:m};break e}t.debug&&console.debug("TenxGraphClient [WS]: remote tool calls detected, executing…");const p=await t.toolExecutor.executeToolCalls(v);t.debug&&console.debug(`TenxGraphClient [WS]: ${p.length} tool result(s) ready, resuming`),$={invoke_type:"resume",tool_result:p.map(U),config:{...e.config??{},thread_id:m},recursion_limit:s,on_busy:e.on_busy,response_granularity:e.response_granularity}}else break e}}finally{t.signal?.removeEventListener("abort",R),(o.readyState===1||o.readyState===0)&&o.close(1e3),t.debug&&console.debug("TenxGraphClient [WS]: stream finished")}}const Xe=24e3,Jt=16e3,Vt=1e4;function zt(t){if(t instanceof ArrayBuffer)return new Uint8Array(t);if(ArrayBuffer.isView(t)){const e=t;return new Uint8Array(e.buffer,e.byteOffset,e.byteLength)}return null}class Ke{constructor(e,r,o){this.resumptionHandle=null,this.ws=null,this.listeners={},this.readyResolved=!1,this.closedByUser=!1,this.fatal=!1,this.reconnectAttempts=0,this.ctx=e,this.threadId=r.thread_id??null,this.init={...r},this.threadId===null&&delete this.init.thread_id,this.reconnectCfg={enabled:o?.reconnect?.enabled??!0,baseDelay:o?.reconnect?.baseDelay??.5,maxDelay:o?.reconnect?.maxDelay??10,maxAttempts:o?.reconnect?.maxAttempts??5},o?.onAudio&&this.on("audio",o.onAudio),o?.onEvent&&this.on("event",o.onEvent),o?.onError&&this.on("error",o.onError),this.ready=new Promise((s,n)=>{this.resolveReady=s,this.rejectReady=n}),this.ready.catch(()=>{}),this.connect()}sendAudio(e){const r=this.ws;r&&r.readyState===1&&r.send(e)}sendText(e){this.sendControl({type:"text",text:e})}activityStart(){this.sendControl({type:"activity_start"})}activityEnd(){this.sendControl({type:"activity_end"})}close(){this.closedByUser=!0,this.clearTimers(),this.sendControl({type:"close"});const e=this.ws;e&&(e.readyState===0||e.readyState===1)&&e.close(1e3)}on(e,r){return this.listeners[e]||(this.listeners[e]=[]),this.listeners[e].push(r),this}off(e,r){return this.listeners[e]=(this.listeners[e]??[]).filter(o=>o!==r),this}emit(e,...r){(this.listeners[e]??[]).forEach(o=>{try{o(...r)}catch(s){this.ctx.debug&&console.warn("TenxGraphClient [realtime]: listener threw",s)}})}sendControl(e){const r=this.ws;r&&r.readyState===1&&r.send(JSON.stringify(e))}clearTimers(){this.reconnectTimer!==void 0&&clearTimeout(this.reconnectTimer),this.stableTimer!==void 0&&clearTimeout(this.stableTimer),this.reconnectTimer=void 0,this.stableTimer=void 0}connect(){const e=ee(this.ctx,"/v1/graph/live");this.ctx.debug&&console.debug("TenxGraphClient [realtime]: connecting to",e);const r=this.ctx.getAuthToken,o=te(e,r?{...this.ctx,authToken:r()}:this.ctx);try{o.binaryType="arraybuffer"}catch{}this.ws=o,o.addEventListener("open",()=>{this.ws===o&&(this.sendControl(this.init),this.readyResolved||(this.readyResolved=!0,this.resolveReady()),this.emit("open"),this.stableTimer!==void 0&&clearTimeout(this.stableTimer),this.stableTimer=setTimeout(()=>{this.stableTimer=void 0,this.reconnectAttempts=0},Vt))}),o.addEventListener("message",s=>{this.ws===o&&this.handleMessage(s.data)}),o.addEventListener("close",s=>{if(this.ws!==o)return;const n=s?.code??1e3;if(this.stableTimer!==void 0&&clearTimeout(this.stableTimer),this.stableTimer=void 0,this.emit("close",n),n===1008&&!this.closedByUser&&!this.fatal){this.fatal=!0;const a={type:"error",code:"policy_violation",message:"Realtime connection closed by the server (1008, policy violation)",fatal:!0};this.emit("error",a),this.emit("event",a);return}this.maybeReconnect(n)}),o.addEventListener("error",()=>{this.ws===o&&(this.readyResolved||(this.readyResolved=!0,this.rejectReady(new Error("Realtime WebSocket connection failed"))))})}handleMessage(e){const r=zt(e);if(r){this.emit("audio",r,Xe);return}if(typeof e!="string")return;let o;try{o=JSON.parse(e)}catch{this.ctx.debug&&console.warn("TenxGraphClient [realtime]: bad JSON frame",e);return}o.type==="session_started"&&o.thread_id&&(this.threadId=o.thread_id),o.type==="session_update"&&(this.resumptionHandle=o.resumption_handle??this.resumptionHandle),o.type==="error"&&o.fatal&&(this.fatal=!0),this.emit("event",o),this.emit(o.type,o)}maybeReconnect(e){if(this.closedByUser||this.fatal||!this.reconnectCfg.enabled)return;if(this.reconnectAttempts>=this.reconnectCfg.maxAttempts){this.fatal=!0;const n={type:"error",code:"reconnect_failed",message:`Realtime reconnect gave up after ${this.reconnectCfg.maxAttempts} attempt(s)`,fatal:!0};this.emit("error",n),this.emit("event",n);return}this.reconnectAttempts+=1;const r=this.reconnectAttempts,s=(e===1013?this.reconnectCfg.maxDelay:Math.min(this.reconnectCfg.baseDelay*2**(r-1),this.reconnectCfg.maxDelay))*1e3*(.5+Math.random()*.5);this.emit("reconnecting",r),this.reconnectTimer=setTimeout(()=>{this.reconnectTimer=void 0,this.reconnect()},s)}reconnect(){if(!this.closedByUser){this.init={...this.init,...this.threadId?{thread_id:this.threadId}:{},...this.resumptionHandle?{resumption_handle:this.resumptionHandle}:{}};try{this.connect(),this.ws?.addEventListener("open",()=>this.emit("reconnected"),{once:!0})}catch(e){this.ctx.debug&&console.warn("TenxGraphClient [realtime]: reconnect failed",e),this.maybeReconnect()}}}}var Ze=(t=>(t.EPISODIC="episodic",t.SEMANTIC="semantic",t.PROCEDURAL="procedural",t.ENTITY="entity",t.RELATIONSHIP="relationship",t.CUSTOM="custom",t.DECLARATIVE="declarative",t))(Ze||{});async function Qe(t,e){try{t.debug&&console.debug("TenxGraphClient: Storing memory with type",e.memory_type);const r=`${t.baseUrl}/v1/store/memories`,o={config:e.config||{},options:e.options||{},content:e.content,memory_type:e.memory_type,category:e.category,metadata:e.metadata||{}},s=await f(t,r,{method:"POST",headers:d(t,{"Content-Type":"application/json"}),...h(t),body:JSON.stringify(o)});if(!s.ok)throw console.warn(`TenxGraphClient: Store memory failed with HTTP ${s.status}`),await u(s,"Store memory request failed","/v1/memory","POST");const n=await s.json();return t.debug&&console.info("TenxGraphClient: Memory stored successfully",n),n}catch(r){throw t.debug&&console.debug("TenxGraphClient: Store memory failed:",r),r}}var qe=(t=>(t.SIMILARITY="similarity",t.TEMPORAL="temporal",t.RELEVANCE="relevance",t.HYBRID="hybrid",t.GRAPH_TRAVERSAL="graph_traversal",t))(qe||{}),et=(t=>(t.COSINE="cosine",t.EUCLIDEAN="euclidean",t.DOT_PRODUCT="dot_product",t.MANHATTAN="manhattan",t))(et||{});async function tt(t,e){try{t.debug&&console.debug("TenxGraphClient: Searching memories with query:",e.query);const r=`${t.baseUrl}/v1/store/search`,o={config:e.config||{},options:e.options||{},query:e.query,limit:e.limit!==void 0?e.limit:10,filters:e.filters||{},retrieval_strategy:e.retrieval_strategy||"similarity",distance_metric:e.distance_metric||"cosine",max_tokens:e.max_tokens!==void 0?e.max_tokens:4e3};e.memory_type!==void 0&&e.memory_type!==null&&(o.memory_type=e.memory_type),e.category!==void 0&&e.category!==null&&(o.category=e.category),e.score_threshold!==void 0&&e.score_threshold!==null&&(o.score_threshold=e.score_threshold);const s=await f(t,r,{method:"POST",headers:d(t,{"Content-Type":"application/json"}),...h(t),body:JSON.stringify(o)});if(!s.ok)throw console.warn(`TenxGraphClient: Search memory failed with HTTP ${s.status}`),await u(s,"Search memory request failed","/v1/memory/search","POST");const n=await s.json();return t.debug&&console.info("TenxGraphClient: Memory search successful",{query:e.query,results_count:n.data.results.length}),n}catch(r){throw t.debug&&console.debug("TenxGraphClient: Search memory failed:",r),r}}async function rt(t,e){try{t.debug&&console.debug("TenxGraphClient: Fetching memory with ID:",e.memoryId);const r=`${t.baseUrl}/v1/store/memories/${C(e.memoryId)}`,o={config:e.config||{},options:e.options||{}},s=await f(t,r,{method:"POST",headers:d(t,{"Content-Type":"application/json"}),...h(t),body:JSON.stringify(o)});if(!s.ok)throw console.warn(`TenxGraphClient: Get memory failed with HTTP ${s.status}`),await u(s,"Get memory request failed","/v1/memory/{memory_id}","GET");const n=await s.json();return t.debug&&console.info("TenxGraphClient: Memory fetched successfully",{memory_id:e.memoryId,content:n.data.memory.content.substring(0,50)}),n}catch(r){throw t.debug&&console.debug("TenxGraphClient: Get memory failed:",r),r}}async function ot(t,e){try{t.debug&&console.debug("TenxGraphClient: Updating memory with ID:",e.memoryId);const r=`${t.baseUrl}/v1/store/memories/${C(e.memoryId)}`,o={config:e.config||{},options:e.options||{},content:e.content,metadata:e.metadata||{}};t.debug&&console.debug("TenxGraphClient: Request payload:",JSON.stringify(o,null,2));const s=await f(t,r,{method:"PUT",headers:d(t,{"Content-Type":"application/json"}),...h(t),body:JSON.stringify(o)});if(!s.ok)throw console.warn(`TenxGraphClient: Update memory failed with HTTP ${s.status}`),await u(s,"Update memory request failed","/v1/memory/{memory_id}","PUT");const n=await s.json();return t.debug&&console.info("TenxGraphClient: Memory updated successfully",{memory_id:e.memoryId,success:n.data.success}),n}catch(r){throw t.debug&&console.debug("TenxGraphClient: Update memory failed:",r),r}}async function st(t,e){try{t.debug&&console.debug("TenxGraphClient: Deleting memory with ID:",e.memoryId);const r=`${t.baseUrl}/v1/store/memories/${C(e.memoryId)}`,o={config:e.config||{},options:e.options||{}};t.debug&&console.debug("TenxGraphClient: Delete request payload:",JSON.stringify(o,null,2));const s=await f(t,r,{method:"DELETE",headers:d(t,{"Content-Type":"application/json",accept:"application/json"}),...h(t),body:JSON.stringify(o)});if(!s.ok)throw console.warn(`TenxGraphClient: Delete memory failed with HTTP ${s.status}`),await u(s,"Delete memory request failed","/v1/memory/{memory_id}","DELETE");const n=await s.json();return t.debug&&console.info("TenxGraphClient: Memory deleted successfully",{memory_id:e.memoryId,success:n.data.success}),n}catch(r){throw t.debug&&console.debug("TenxGraphClient: Delete memory failed:",r),r}}async function nt(t,e){try{t.debug&&console.debug("TenxGraphClient: Fetching list of memories",{limit:e.limit});const r=`${t.baseUrl}/v1/store/memories/list`,o={config:e.config||{},options:e.options||{},limit:e.limit||100};e.offset!==void 0&&(o.offset=e.offset),t.debug&&console.debug("TenxGraphClient: List memories request payload:",JSON.stringify(o,null,2));const s=await f(t,r,{method:"POST",headers:d(t,{"Content-Type":"application/json",accept:"application/json"}),...h(t),body:JSON.stringify(o)});if(!s.ok)throw console.warn(`TenxGraphClient: List memories failed with HTTP ${s.status}`),await u(s,"List memories request failed","/v1/memory","GET");const n=await s.json();return t.debug&&console.info("TenxGraphClient: Memories list fetched successfully",{count:n.data.memories.length,limit:e.limit}),n}catch(r){throw t.debug&&console.debug("TenxGraphClient: List memories failed:",r),r}}async function at(t,e){const r=`${t.baseUrl}/v1/store/memories/forget`,o={};e.config&&(o.config=e.config),e.options&&(o.options=e.options),e.memory_type&&(o.memory_type=e.memory_type),e.category&&(o.category=e.category),e.filters&&(o.filters=e.filters),t.debug&&console.log("[DEBUG] Forget memories request:",o);const s=await f(t,r,{method:"POST",headers:d(t,{"Content-Type":"application/json"}),...h(t),body:JSON.stringify(o)});if(!s.ok)throw new Error(`Forget memories failed: ${s.status} ${s.statusText}`);const n=await s.json();return t.debug&&console.log("[DEBUG] Forget memories response:",n),n}async function it(t,e){try{t.debug&&console.debug("TenxGraphClient: Stopping graph execution for thread:",e.thread_id);const r=await f(t,`${t.baseUrl}/v1/graph/stop`,{method:"POST",headers:d(t,{"Content-Type":"application/json",accept:"application/json"}),...h(t),body:JSON.stringify(e)});if(!r.ok)throw console.warn(`TenxGraphClient: Stop graph failed with HTTP ${r.status}`),await u(r,"Stop graph execution failed","/v1/graph/stop","POST");const o=await r.json();return t.debug&&console.info("TenxGraphClient: Graph execution stopped successfully",o),o}catch(r){throw t.debug&&console.debug("TenxGraphClient: Stop graph failed:",r),console.error("TenxGraphClient: Stop graph failed:",r),r}}async function ct(t,e){try{t.debug&&console.debug("TenxGraphClient: Fixing graph state for thread:",e.thread_id);const r=await f(t,`${t.baseUrl}/v1/graph/fix`,{method:"POST",headers:d(t,{"Content-Type":"application/json",accept:"application/json"}),...h(t),body:JSON.stringify(e)});if(!r.ok)throw console.warn(`TenxGraphClient: Fix graph failed with HTTP ${r.status}`),await u(r,"Fix graph state failed","/v1/graph/fix","POST");const o=await r.json();return t.debug&&console.info("TenxGraphClient: Graph state fixed successfully",{removed_count:o.data.removed_count,success:o.data.success}),o}catch(r){throw t.debug&&console.debug("TenxGraphClient: Fix graph failed:",r),console.error("TenxGraphClient: Fix graph failed:",r),r}}async function lt(t,e){const r=new FormData;typeof File<"u"&&e instanceof File?r.append("file",e,e.name):"data"in e&&"filename"in e?r.append("file",e.data,e.filename):r.append("file",e,"upload");const o=await f(t,`${t.baseUrl}/v1/files/upload`,{method:"POST",headers:d(t),body:r,...h(t)});if(!o.ok)throw await u(o,"File upload failed","/v1/files/upload","POST");return await o.json()}async function dt(t,e){const r=await f(t,`${t.baseUrl}/v1/files/${encodeURIComponent(e)}`,{method:"GET",headers:d(t),...h(t)});if(!r.ok)throw await u(r,"File download failed",`/v1/files/${e}`,"GET");return await r.blob()}async function ht(t,e){const r=new URLSearchParams;e?.limit!==void 0&&r.append("limit",String(e.limit)),e?.offset!==void 0&&r.append("offset",String(e.offset));const o=r.toString(),s=await f(t,`${t.baseUrl}/v1/files${o?`?${o}`:""}`,{method:"GET",headers:d(t),...h(t)});if(!s.ok)throw await u(s,"List files request failed","/v1/files","GET");return await s.json()}async function ut(t,e){const r=await f(t,`${t.baseUrl}/v1/files/${encodeURIComponent(e)}/info`,{method:"GET",headers:d(t),...h(t)});if(!r.ok)throw await u(r,"File info request failed",`/v1/files/${e}/info`,"GET");return await r.json()}async function ft(t,e){const r=await f(t,`${t.baseUrl}/v1/files/${encodeURIComponent(e)}/url`,{method:"GET",headers:d(t),...h(t)});if(!r.ok)throw await u(r,"File access URL request failed",`/v1/files/${e}/url`,"GET");return await r.json()}async function pt(t){const e=await f(t,`${t.baseUrl}/v1/config/multimodal`,{method:"GET",headers:d(t,{accept:"application/json"}),...h(t)});if(!e.ok)throw await u(e,"Multimodal config request failed","/v1/config/multimodal","GET");return await e.json()}async function mt(t,e){try{t.debug&&console.debug("TenxGraphClient: Deleting file",`file: ${e}`);const r=`${t.baseUrl}/v1/files/${encodeURIComponent(e)}`,o=await f(t,r,{method:"DELETE",headers:d(t,{accept:"application/json"}),...h(t)});if(!o.ok)throw console.warn(`TenxGraphClient: Delete file failed with HTTP ${o.status}`),await u(o,"Delete file failed",`/v1/files/${e}`,"DELETE");const s=await o.json();return t.debug&&console.info("TenxGraphClient: File deleted successfully",s),s}catch(r){throw t.debug&&console.debug("TenxGraphClient: Delete file failed:",r),r}}function Yt(t){return typeof t=="object"&&t!==null}function Xt(t,e,r){return Yt(t)?{search:t.search,offset:t.offset,limit:t.limit}:{search:t,offset:e,limit:r}}function Kt(t){return typeof t=="object"&&t!==null}function Zt(t,e,r,o){return Kt(e)?{threadId:t,search:e.search,offset:e.offset,limit:e.limit}:{threadId:t,search:e,offset:r,limit:o}}class gt{constructor(e){this.baseUrl=Ge(e.baseUrl),this.authToken=e.authToken,this.auth=e.auth,this.headers=e.headers,this.credentials=e.credentials,this.timeout=e.timeout||3e5,this.debug=e.debug||!1,this.webSocketImpl=e.webSocketImpl,this.toolExecutor=new he([])}setAuthToken(e){this.authToken=e}clearAuth(){this.authToken=null,this.auth=null}createContext(e){const r=typeof this.authToken=="function"?this.authToken():this.authToken;return{baseUrl:this.baseUrl,authToken:r,signal:e?.signal,auth:this.auth,headers:this.headers,credentials:this.credentials,timeout:this.timeout,debug:this.debug,webSocketImpl:this.webSocketImpl}}registerTool(e){this.toolExecutor.registerTool(e),this.debug&&console.debug(`TenxGraphClient: Registered remote tool handler '${e.name}'`)}registerToolHandler(e,r){this.registerTool({name:e,handler:r})}async ping(e){const r=this.createContext(e);return Ae(r)}async graph(e){const r=this.createContext(e);return Oe(r)}async graphTools(e){const r=this.createContext(e);return $e(r)}async observability(e,r,o){const s=this.createContext(o);return Ie(s,e,r)}async stopGraph(e,r,o){const s=this.createContext(o);return it(s,{thread_id:e,config:r})}async fixGraph(e,r,o){const s=this.createContext(o);return ct(s,{thread_id:e,config:r})}async graphStateSchema(e){const r=this.createContext(e);return Ne(r)}async threadState(e,r){const o=this.createContext(r);return Ue(o,e)}async updateThreadState(e,r,o,s){const n=this.createContext(s);return je(n,e,{config:r,state:o})}async clearThreadState(e,r){const o=this.createContext(r);return Pe(o,e)}async threadDetails(e,r){const o=this.createContext(r);return De(o,e)}async threads(e,r,o,s){const n=typeof r=="object"?r:s,a=this.createContext(n),i=Xt(e,typeof r=="number"?r:void 0,o);return We(a,i)}async threadMessages(e,r,o,s,n){const a=typeof o=="object"?o:n,i=this.createContext(a),c=Zt(e,r,typeof o=="number"?o:void 0,s);return q(i,c)}async addThreadMessages(e,r,o={},s,n){const a=this.createContext(n);return Me(a,{threadId:e,config:o,messages:r,metadata:s})}async singleMessage(e,r,o){const s=this.createContext(o);return Le(s,{threadId:e,messageId:r})}async deleteMessage(e,r,o,s){const n=this.createContext(s);return Be(n,{threadId:e,messageId:r,config:o})}async updateThreadMessageFeedback(e,r,o,s){const n=this.createContext(s);return Fe(n,{threadId:e,messageId:r,feedback:o})}async deleteThread(e,r,o){const s=this.createContext(o);return He(s,{threadId:e,config:r})}async invoke(e,r){const o={...this.createContext(),toolExecutor:this.toolExecutor,signal:r?.signal},s={messages:e.map(n=>U(n)),initial_state:r?.initial_state,config:r?.config,recursion_limit:r?.recursion_limit??25,on_busy:r?.on_busy,resume:r?.resume,interrupt_id:r?.interrupt_id,response_granularity:r?.response_granularity||"full"};return Je(o,s,r?.onPartialResult)}stream(e,r){const o={...this.createContext(),toolExecutor:this.toolExecutor,signal:r?.signal},s={messages:e.map(n=>U(n)),initial_state:r?.initial_state,config:r?.config,recursion_limit:r?.recursion_limit??25,on_busy:r?.on_busy,resume:r?.resume,interrupt_id:r?.interrupt_id,response_granularity:r?.response_granularity||"low"};return xe(o,s)}wsStream(e,r){const o={...this.createContext(),toolExecutor:this.toolExecutor,signal:r?.signal},s={messages:e.map(n=>U(n)),initial_state:r?.initial_state,config:r?.config,recursion_limit:r?.recursion_limit??25,on_busy:r?.on_busy,resume:r?.resume,interrupt_id:r?.interrupt_id,response_granularity:r?.response_granularity??"low"};return Ye(o,s)}realtime(e,r){const o={...this.createContext(),getAuthToken:()=>typeof this.authToken=="function"?this.authToken():this.authToken};return new Ke(o,e,r)}async storeMemory(e,r){const o=this.createContext(r);return Qe(o,e)}async searchMemory(e,r){const o=this.createContext(r);return tt(o,e)}async getMemory(e,r){const o=this.createContext(r),s={memoryId:e,config:r?.config,options:r?.options};return rt(o,s)}async updateMemory(e,r,o){const s=this.createContext(o),n={memoryId:e,content:r,config:o?.config,options:o?.options,metadata:o?.metadata};return ot(s,n)}async deleteMemory(e,r){const o=this.createContext(r),s={memoryId:e,config:r?.config,options:r?.options};return st(o,s)}async listMemories(e){const r=this.createContext(e),o={config:e?.config,options:e?.options,limit:e?.limit,offset:e?.offset};return nt(r,o)}async forgetMemories(e){const r=this.createContext(e),o={config:e?.config,options:e?.options,memory_type:e?.memory_type,category:e?.category,filters:e?.filters};return at(r,o)}async uploadFile(e,r){const o=this.createContext(r);return lt(o,e)}async getFile(e,r){const o=this.createContext(r);return dt(o,e)}async listFiles(e,r){const o=this.createContext(r);return ht(o,e)}async getFileInfo(e,r){const o=this.createContext(r);return ut(o,e)}async getFileAccessUrl(e,r){const o=this.createContext(r);return ft(o,e)}async deleteFile(e,r){const o=this.createContext(r);return mt(o,e)}async getMultimodalConfig(e){const r=this.createContext(e);return pt(r)}}function Qt(t){const e=t.data;if(t.event!=="updates"||e===null||typeof e!="object")return null;const r=e.interrupt;return r===null||typeof r!="object"?null:typeof r.id=="string"?r:null}function qt(t,e=!0){return{resume:e,interrupt_id:t.id}}function er(t){return{resume:null,interrupt_id:t.id}}class tr{constructor(){this.current_node="START",this.step=0,this.is_running=!0,this.is_interrupted=!1,this.is_stopped_requested=!1}}class rr{constructor(e={}){this.context=[],this.context_summary=null,this.execution_meta=new tr,Object.assign(this,e)}}const or=gt,sr=T;exports.AgentFlowClient=or;exports.AgentFlowError=sr;exports.AgentState=rr;exports.AnnotationBlock=_t;exports.AnnotationRef=yt;exports.AudioBlock=ne;exports.AuthenticationError=fe;exports.BadRequestError=ue;exports.ConflictError=ge;exports.DEFAULT_MAX_TOOL_ARGS_BYTES=le;exports.DataBlock=Tt;exports.DistanceMetric=et;exports.DocumentBlock=ie;exports.ErrorBlock=Ct;exports.GraphError=Te;exports.GraphRecursionError=we;exports.ImageBlock=Z;exports.MediaRef=O;exports.MemoryType=Ze;exports.Message=A;exports.MetricsError=Ce;exports.NetworkError=L;exports.NodeError=be;exports.NotFoundError=me;exports.PermissionError=pe;exports.REALTIME_INPUT_SAMPLE_RATE=Jt;exports.REALTIME_OUTPUT_SAMPLE_RATE=Xe;exports.RateLimitError=Re;exports.RealtimeSession=Ke;exports.ReasoningBlock=Et;exports.RemoteToolCallBlock=wt;exports.RequestTimeoutError=D;exports.RetrievalStrategy=qe;exports.SchemaVersionError=Se;exports.SerializationError=ve;exports.ServerError=ye;exports.StorageError=Ee;exports.StreamError=W;exports.StreamEventType=H;exports.TenxGraphClient=gt;exports.TenxGraphError=T;exports.TextBlock=K;exports.TokenUsages=St;exports.ToolCallBlock=bt;exports.ToolExecutor=he;exports.ToolResultBlock=B;exports.TransientStorageError=_e;exports.ValidationError=Q;exports.VideoBlock=ae;exports.WS_BEARER_SUBPROTOCOL=Ve;exports.WebSocketError=F;exports.addThreadMessages=Me;exports.approveInterrupt=qt;exports.basicAuth=Ut;exports.bearerAuth=Nt;exports.buildHeaders=d;exports.buildWsUrl=ee;exports.checkToolArguments=de;exports.checkpointMessages=xt;exports.clearThreadState=Pe;exports.createErrorFromResponse=u;exports.deleteFile=mt;exports.deleteMemory=st;exports.deleteThread=He;exports.deleteThreadMessage=Be;exports.encodePathSegment=C;exports.fetchWithTimeout=f;exports.fixGraph=ct;exports.forgetMemories=at;exports.getFile=dt;exports.getFileAccessUrl=ft;exports.getFileInfo=ut;exports.getInterrupt=Qt;exports.getMemory=rt;exports.getMultimodalConfig=pt;exports.getRequestCredentials=h;exports.graph=Oe;exports.graphTools=$e;exports.headerAuth=jt;exports.invoke=Je;exports.linkAbortSignal=z;exports.listFiles=ht;exports.listMemories=nt;exports.normalizeBaseUrl=Ge;exports.normalizeToolParameters=ce;exports.observability=Ie;exports.openWebSocket=te;exports.parseErrorResponse=Rt;exports.ping=Ae;exports.rejectInterrupt=er;exports.resolveBearerToken=ze;exports.searchMemory=tt;exports.serializeMessage=U;exports.stateSchema=Ne;exports.stopGraph=it;exports.storeMemory=Qe;exports.streamInvoke=xe;exports.threadDetails=De;exports.threadMessage=Le;exports.threadMessages=q;exports.threadState=Ue;exports.threads=We;exports.updateMemory=ot;exports.updateThreadMessageFeedback=Fe;exports.updateThreadState=je;exports.uploadFile=lt;exports.wsStreamInvoke=Ye;
6
6
  //# sourceMappingURL=index.cjs.map