@oobe-protocol-labs/synapse-client-sdk 1.2.1 → 1.2.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 (564) hide show
  1. package/CHANGELOG.md +74 -0
  2. package/dist/cjs/ai/gateway/index.d.ts +86 -5
  3. package/dist/cjs/ai/gateway/index.d.ts.map +1 -1
  4. package/dist/cjs/ai/gateway/index.js +278 -40
  5. package/dist/cjs/ai/gateway/index.js.map +1 -1
  6. package/dist/cjs/ai/gateway/registry.d.ts +223 -0
  7. package/dist/cjs/ai/gateway/registry.d.ts.map +1 -0
  8. package/dist/cjs/ai/gateway/registry.js +290 -0
  9. package/dist/cjs/ai/gateway/registry.js.map +1 -0
  10. package/dist/cjs/ai/gateway/types.d.ts +107 -1
  11. package/dist/cjs/ai/gateway/types.d.ts.map +1 -1
  12. package/dist/cjs/ai/gateway/x402/index.d.ts +2 -4
  13. package/dist/cjs/ai/gateway/x402/index.d.ts.map +1 -1
  14. package/dist/cjs/ai/gateway/x402/index.js +2 -1
  15. package/dist/cjs/ai/gateway/x402/index.js.map +1 -1
  16. package/dist/cjs/ai/gateway/x402/registry.d.ts +131 -1
  17. package/dist/cjs/ai/gateway/x402/registry.d.ts.map +1 -1
  18. package/dist/cjs/ai/gateway/x402/registry.js +229 -1
  19. package/dist/cjs/ai/gateway/x402/registry.js.map +1 -1
  20. package/dist/cjs/ai/index.d.ts +2 -1
  21. package/dist/cjs/ai/index.d.ts.map +1 -1
  22. package/dist/cjs/ai/index.js +21 -2
  23. package/dist/cjs/ai/index.js.map +1 -1
  24. package/dist/cjs/ai/persistence/helpers.d.ts +83 -0
  25. package/dist/cjs/ai/persistence/helpers.d.ts.map +1 -0
  26. package/dist/cjs/ai/persistence/helpers.js +193 -0
  27. package/dist/cjs/ai/persistence/helpers.js.map +1 -0
  28. package/dist/cjs/ai/persistence/index.d.ts +91 -0
  29. package/dist/cjs/ai/persistence/index.d.ts.map +1 -0
  30. package/dist/cjs/ai/persistence/index.js +109 -0
  31. package/dist/cjs/ai/persistence/index.js.map +1 -0
  32. package/dist/cjs/ai/persistence/memory.d.ts +71 -0
  33. package/dist/cjs/ai/persistence/memory.d.ts.map +1 -0
  34. package/dist/cjs/ai/persistence/memory.js +192 -0
  35. package/dist/cjs/ai/persistence/memory.js.map +1 -0
  36. package/dist/cjs/ai/persistence/postgresql.d.ts +119 -0
  37. package/dist/cjs/ai/persistence/postgresql.d.ts.map +1 -0
  38. package/dist/cjs/ai/persistence/postgresql.js +310 -0
  39. package/dist/cjs/ai/persistence/postgresql.js.map +1 -0
  40. package/dist/cjs/ai/persistence/redis.d.ts +84 -0
  41. package/dist/cjs/ai/persistence/redis.d.ts.map +1 -0
  42. package/dist/cjs/ai/persistence/redis.js +241 -0
  43. package/dist/cjs/ai/persistence/redis.js.map +1 -0
  44. package/dist/cjs/ai/persistence/types.d.ts +267 -0
  45. package/dist/cjs/ai/persistence/types.d.ts.map +1 -0
  46. package/dist/cjs/ai/persistence/types.js +40 -0
  47. package/dist/cjs/ai/persistence/types.js.map +1 -0
  48. package/dist/cjs/core/client.d.ts +16 -0
  49. package/dist/cjs/core/client.d.ts.map +1 -1
  50. package/dist/cjs/core/client.js +18 -0
  51. package/dist/cjs/core/client.js.map +1 -1
  52. package/dist/cjs/next/index.d.ts +141 -0
  53. package/dist/cjs/next/index.d.ts.map +1 -0
  54. package/dist/cjs/next/index.js +177 -0
  55. package/dist/cjs/next/index.js.map +1 -0
  56. package/dist/cjs/utils/helpers.d.ts +79 -1
  57. package/dist/cjs/utils/helpers.d.ts.map +1 -1
  58. package/dist/cjs/utils/helpers.js +109 -0
  59. package/dist/cjs/utils/helpers.js.map +1 -1
  60. package/dist/docs/assets/navigation.js +1 -1
  61. package/dist/docs/assets/search.js +1 -1
  62. package/dist/docs/classes/AccountReader.html +18 -18
  63. package/dist/docs/classes/AccountsClient.html +10 -10
  64. package/dist/docs/classes/AsyncProviderError.html +4 -4
  65. package/dist/docs/classes/CircularDependencyError.html +4 -4
  66. package/dist/docs/classes/DasClient.html +13 -13
  67. package/dist/docs/classes/GeyserParser.html +17 -17
  68. package/dist/docs/classes/GrpcTransport.html +6 -6
  69. package/dist/docs/classes/HttpTransport.html +4 -4
  70. package/dist/docs/classes/InstructionWriter.html +11 -11
  71. package/dist/docs/classes/MemoryGuard.html +9 -9
  72. package/dist/docs/classes/NetworkError.html +5 -5
  73. package/dist/docs/classes/RefRegistry.html +11 -11
  74. package/dist/docs/classes/RefReleasedError.html +4 -4
  75. package/dist/docs/classes/RpcMethodNotFoundError.html +4 -4
  76. package/dist/docs/classes/ServiceNotFoundError.html +4 -4
  77. package/dist/docs/classes/ServiceRef.html +13 -13
  78. package/dist/docs/classes/SolanaRpc.html +55 -55
  79. package/dist/docs/classes/SynapseClient.html +25 -15
  80. package/dist/docs/classes/SynapseContext.html +27 -27
  81. package/dist/docs/classes/SynapseError.html +4 -4
  82. package/dist/docs/classes/TimeoutError.html +4 -4
  83. package/dist/docs/classes/UpstreamError.html +6 -6
  84. package/dist/docs/classes/WeakServiceRef.html +4 -4
  85. package/dist/docs/classes/WsClient.html +10 -10
  86. package/dist/docs/enums/SynapseNetwork.html +2 -2
  87. package/dist/docs/enums/SynapseRegion.html +2 -2
  88. package/dist/docs/enums/TokenExtensionType.html +2 -2
  89. package/dist/docs/functions/Epoch-1.html +1 -1
  90. package/dist/docs/functions/Lamports-2.html +1 -1
  91. package/dist/docs/functions/Pubkey-1.html +1 -1
  92. package/dist/docs/functions/Sig.html +1 -1
  93. package/dist/docs/functions/Slot-1.html +1 -1
  94. package/dist/docs/functions/UnixTs.html +1 -1
  95. package/dist/docs/functions/autoSelectRegion.html +1 -1
  96. package/dist/docs/functions/autoWire.html +1 -1
  97. package/dist/docs/functions/base58Encode.html +1 -1
  98. package/dist/docs/functions/base64ToBytes.html +1 -1
  99. package/dist/docs/functions/bigIntReplacer.html +6 -0
  100. package/dist/docs/functions/chunk.html +1 -1
  101. package/dist/docs/functions/computeBalanceChanges.html +1 -1
  102. package/dist/docs/functions/computeTokenBalanceChanges.html +1 -1
  103. package/dist/docs/functions/createBareContext.html +1 -1
  104. package/dist/docs/functions/createBinding.html +1 -1
  105. package/dist/docs/functions/createBoundHook.html +1 -1
  106. package/dist/docs/functions/createReactAdapter.html +1 -1
  107. package/dist/docs/functions/createRefHook.html +1 -1
  108. package/dist/docs/functions/createServerMiddleware.html +1 -1
  109. package/dist/docs/functions/createServiceHook.html +1 -1
  110. package/dist/docs/functions/createSingleton.html +15 -0
  111. package/dist/docs/functions/createSynapse.html +1 -1
  112. package/dist/docs/functions/createSynapseContext.html +1 -1
  113. package/dist/docs/functions/createToken.html +1 -1
  114. package/dist/docs/functions/decodeBase58.html +1 -1
  115. package/dist/docs/functions/decodeLookupTable.html +1 -1
  116. package/dist/docs/functions/decodeMint.html +1 -1
  117. package/dist/docs/functions/decodeMultisig.html +1 -1
  118. package/dist/docs/functions/decodeNonceAccount.html +1 -1
  119. package/dist/docs/functions/decodeStakeAccount.html +1 -1
  120. package/dist/docs/functions/decodeToken2022Account.html +1 -1
  121. package/dist/docs/functions/decodeToken2022Mint.html +1 -1
  122. package/dist/docs/functions/decodeTokenAccount.html +1 -1
  123. package/dist/docs/functions/encodeBase58.html +1 -1
  124. package/dist/docs/functions/fetchLookupTable.html +1 -1
  125. package/dist/docs/functions/fetchMint.html +1 -1
  126. package/dist/docs/functions/fetchNonceAccount.html +1 -1
  127. package/dist/docs/functions/fetchStakeAccount.html +1 -1
  128. package/dist/docs/functions/fetchTokenAccount.html +1 -1
  129. package/dist/docs/functions/fetchTokenAccountsByOwner.html +1 -1
  130. package/dist/docs/functions/fromKitAddress.html +1 -1
  131. package/dist/docs/functions/getAccountInfo.html +1 -1
  132. package/dist/docs/functions/getAsset.html +1 -1
  133. package/dist/docs/functions/getAssetBatch.html +1 -1
  134. package/dist/docs/functions/getAssetProof.html +1 -1
  135. package/dist/docs/functions/getAssetProofBatch.html +1 -1
  136. package/dist/docs/functions/getAssetsByAuthority.html +1 -1
  137. package/dist/docs/functions/getAssetsByCreator.html +1 -1
  138. package/dist/docs/functions/getAssetsByGroup.html +1 -1
  139. package/dist/docs/functions/getAssetsByOwner.html +1 -1
  140. package/dist/docs/functions/getBalance.html +1 -1
  141. package/dist/docs/functions/getBlock.html +1 -1
  142. package/dist/docs/functions/getBlockCommitment.html +1 -1
  143. package/dist/docs/functions/getBlockHeight.html +1 -1
  144. package/dist/docs/functions/getBlockProduction.html +1 -1
  145. package/dist/docs/functions/getBlockTime.html +1 -1
  146. package/dist/docs/functions/getBlocks.html +1 -1
  147. package/dist/docs/functions/getBlocksWithLimit.html +1 -1
  148. package/dist/docs/functions/getClusterNodes.html +1 -1
  149. package/dist/docs/functions/getContext.html +1 -1
  150. package/dist/docs/functions/getDecodedAccount.html +1 -1
  151. package/dist/docs/functions/getDecodedAccounts.html +1 -1
  152. package/dist/docs/functions/getEnvironment.html +1 -1
  153. package/dist/docs/functions/getEpochInfo.html +1 -1
  154. package/dist/docs/functions/getEpochSchedule.html +1 -1
  155. package/dist/docs/functions/getFeeForMessage.html +1 -1
  156. package/dist/docs/functions/getFirstAvailableBlock.html +1 -1
  157. package/dist/docs/functions/getGenesisHash.html +1 -1
  158. package/dist/docs/functions/getHealth.html +1 -1
  159. package/dist/docs/functions/getHighestSnapshotSlot.html +1 -1
  160. package/dist/docs/functions/getIdentity.html +1 -1
  161. package/dist/docs/functions/getInflationGovernor.html +1 -1
  162. package/dist/docs/functions/getInflationRate.html +1 -1
  163. package/dist/docs/functions/getInflationReward.html +1 -1
  164. package/dist/docs/functions/getLargestAccounts.html +1 -1
  165. package/dist/docs/functions/getLatestBlockhash.html +1 -1
  166. package/dist/docs/functions/getLeaderSchedule.html +1 -1
  167. package/dist/docs/functions/getMaxRetransmitSlot.html +1 -1
  168. package/dist/docs/functions/getMaxShredInsertSlot.html +1 -1
  169. package/dist/docs/functions/getMinimumBalanceForRentExemption.html +1 -1
  170. package/dist/docs/functions/getMultipleAccounts.html +1 -1
  171. package/dist/docs/functions/getProgramAccounts.html +1 -1
  172. package/dist/docs/functions/getProgramCategory.html +1 -1
  173. package/dist/docs/functions/getRecentPerformanceSamples.html +1 -1
  174. package/dist/docs/functions/getRecentPrioritizationFees.html +1 -1
  175. package/dist/docs/functions/getSignatureStatuses.html +1 -1
  176. package/dist/docs/functions/getSignaturesForAddress.html +1 -1
  177. package/dist/docs/functions/getSignaturesForAsset.html +1 -1
  178. package/dist/docs/functions/getSlot.html +1 -1
  179. package/dist/docs/functions/getSlotLeader.html +1 -1
  180. package/dist/docs/functions/getSlotLeaders.html +1 -1
  181. package/dist/docs/functions/getStakeActivation.html +1 -1
  182. package/dist/docs/functions/getStakeMinimumDelegation.html +1 -1
  183. package/dist/docs/functions/getSupply.html +1 -1
  184. package/dist/docs/functions/getTokenAccountBalance.html +1 -1
  185. package/dist/docs/functions/getTokenAccounts.html +1 -1
  186. package/dist/docs/functions/getTokenAccountsByDelegate.html +1 -1
  187. package/dist/docs/functions/getTokenAccountsByOwner.html +1 -1
  188. package/dist/docs/functions/getTokenLargestAccounts.html +1 -1
  189. package/dist/docs/functions/getTokenSupply.html +1 -1
  190. package/dist/docs/functions/getTransaction.html +1 -1
  191. package/dist/docs/functions/getTransactionCount.html +1 -1
  192. package/dist/docs/functions/getVersion.html +1 -1
  193. package/dist/docs/functions/getVoteAccounts.html +1 -1
  194. package/dist/docs/functions/isBlockhashValid.html +1 -1
  195. package/dist/docs/functions/isBrowser.html +1 -1
  196. package/dist/docs/functions/isDisposable.html +1 -1
  197. package/dist/docs/functions/isProgramInCategory.html +1 -1
  198. package/dist/docs/functions/isServer.html +1 -1
  199. package/dist/docs/functions/isValidPubkey.html +1 -1
  200. package/dist/docs/functions/isValidSignature.html +1 -1
  201. package/dist/docs/functions/lamportsToSol.html +1 -1
  202. package/dist/docs/functions/listEndpoints.html +1 -1
  203. package/dist/docs/functions/listNetworks.html +1 -1
  204. package/dist/docs/functions/listRegions.html +1 -1
  205. package/dist/docs/functions/minimumLedgerSlot.html +1 -1
  206. package/dist/docs/functions/parseAccountUpdate.html +1 -1
  207. package/dist/docs/functions/parseBlockMeta.html +1 -1
  208. package/dist/docs/functions/parseEntry.html +1 -1
  209. package/dist/docs/functions/parseGeyserUpdate.html +1 -1
  210. package/dist/docs/functions/parseSlotUpdate.html +1 -1
  211. package/dist/docs/functions/parseTimestamp.html +1 -1
  212. package/dist/docs/functions/parseTransaction.html +1 -1
  213. package/dist/docs/functions/probeLatency.html +1 -1
  214. package/dist/docs/functions/rawBufferToBase58.html +1 -1
  215. package/dist/docs/functions/rawBufferToBase64.html +1 -1
  216. package/dist/docs/functions/rawBufferToBytes.html +1 -1
  217. package/dist/docs/functions/rawBufferToHex.html +1 -1
  218. package/dist/docs/functions/readonly.html +1 -1
  219. package/dist/docs/functions/readonlySigner.html +1 -1
  220. package/dist/docs/functions/requestAirdrop.html +1 -1
  221. package/dist/docs/functions/resolveEndpoint.html +1 -1
  222. package/dist/docs/functions/resolveProgram.html +1 -1
  223. package/dist/docs/functions/resolveProgramBatch.html +1 -1
  224. package/dist/docs/functions/retry.html +1 -1
  225. package/dist/docs/functions/searchAssets.html +1 -1
  226. package/dist/docs/functions/sendTransaction.html +1 -1
  227. package/dist/docs/functions/setGlobalContext.html +1 -1
  228. package/dist/docs/functions/simulateTransaction.html +1 -1
  229. package/dist/docs/functions/sleep.html +1 -1
  230. package/dist/docs/functions/solToLamports.html +1 -1
  231. package/dist/docs/functions/toClientConfig.html +1 -1
  232. package/dist/docs/functions/toJsonSafe.html +13 -0
  233. package/dist/docs/functions/toKitAddress.html +1 -1
  234. package/dist/docs/functions/toKitInstruction.html +1 -1
  235. package/dist/docs/functions/toKitLamports.html +1 -1
  236. package/dist/docs/functions/toKitSignatureString.html +1 -1
  237. package/dist/docs/functions/tryGetContext.html +1 -1
  238. package/dist/docs/functions/tryUseService.html +1 -1
  239. package/dist/docs/functions/useBoundServices.html +1 -1
  240. package/dist/docs/functions/useService.html +1 -1
  241. package/dist/docs/functions/useSharedRef.html +1 -1
  242. package/dist/docs/functions/withRef.html +1 -1
  243. package/dist/docs/functions/withRefAsync.html +1 -1
  244. package/dist/docs/functions/writable.html +1 -1
  245. package/dist/docs/functions/writableSigner.html +1 -1
  246. package/dist/docs/interfaces/AccountInfo.html +7 -7
  247. package/dist/docs/interfaces/AccountMeta.html +4 -4
  248. package/dist/docs/interfaces/AccountNotification.html +2 -2
  249. package/dist/docs/interfaces/AccountSubParams.html +2 -2
  250. package/dist/docs/interfaces/AddMemoParams.html +5 -5
  251. package/dist/docs/interfaces/AdvanceNonceParams.html +3 -3
  252. package/dist/docs/interfaces/AliasProvider.html +2 -2
  253. package/dist/docs/interfaces/AllocateParams.html +3 -3
  254. package/dist/docs/interfaces/ApproveCheckedParams.html +9 -9
  255. package/dist/docs/interfaces/ApproveParams.html +7 -7
  256. package/dist/docs/interfaces/AssetSignatureInfo.html +2 -2
  257. package/dist/docs/interfaces/AssetSignaturesPage.html +2 -2
  258. package/dist/docs/interfaces/AssignParams.html +3 -3
  259. package/dist/docs/interfaces/AsyncFactoryProvider.html +2 -2
  260. package/dist/docs/interfaces/AuthorizeNonceParams.html +4 -4
  261. package/dist/docs/interfaces/BalanceChange.html +6 -6
  262. package/dist/docs/interfaces/BlockProduction.html +3 -3
  263. package/dist/docs/interfaces/BlockResult.html +2 -2
  264. package/dist/docs/interfaces/BlockReward.html +2 -2
  265. package/dist/docs/interfaces/BlockhashResult.html +2 -2
  266. package/dist/docs/interfaces/BurnCheckedParams.html +8 -8
  267. package/dist/docs/interfaces/BurnParams.html +7 -7
  268. package/dist/docs/interfaces/CallOptions.html +6 -6
  269. package/dist/docs/interfaces/ClassProvider.html +2 -2
  270. package/dist/docs/interfaces/CloseAccountParams.html +6 -6
  271. package/dist/docs/interfaces/ConfirmedTransaction.html +6 -6
  272. package/dist/docs/interfaces/ContactInfo.html +2 -2
  273. package/dist/docs/interfaces/ContextAdapter.html +5 -5
  274. package/dist/docs/interfaces/ContextEvents.html +6 -6
  275. package/dist/docs/interfaces/ContextModule.html +3 -3
  276. package/dist/docs/interfaces/CreateATAParams.html +6 -6
  277. package/dist/docs/interfaces/CreateAccountParams.html +6 -6
  278. package/dist/docs/interfaces/CreateAccountWithSeedParams.html +8 -8
  279. package/dist/docs/interfaces/CreateSynapseContextOpts.html +4 -4
  280. package/dist/docs/interfaces/DasAsset.html +2 -2
  281. package/dist/docs/interfaces/DasAssetProof.html +2 -2
  282. package/dist/docs/interfaces/DasAuthority.html +2 -2
  283. package/dist/docs/interfaces/DasCompression.html +2 -2
  284. package/dist/docs/interfaces/DasContent.html +2 -2
  285. package/dist/docs/interfaces/DasCreator.html +2 -2
  286. package/dist/docs/interfaces/DasFile.html +2 -2
  287. package/dist/docs/interfaces/DasGrouping.html +2 -2
  288. package/dist/docs/interfaces/DasOpts.html +2 -2
  289. package/dist/docs/interfaces/DasOwnership.html +2 -2
  290. package/dist/docs/interfaces/DasPage.html +2 -2
  291. package/dist/docs/interfaces/DasRoyalty.html +2 -2
  292. package/dist/docs/interfaces/DasSearchParams.html +2 -2
  293. package/dist/docs/interfaces/DasSupply.html +2 -2
  294. package/dist/docs/interfaces/DataSlice.html +3 -3
  295. package/dist/docs/interfaces/DecodedAccountResult.html +4 -4
  296. package/dist/docs/interfaces/DecodedLookupTable.html +8 -8
  297. package/dist/docs/interfaces/DecodedMint.html +6 -6
  298. package/dist/docs/interfaces/DecodedMultisig.html +5 -5
  299. package/dist/docs/interfaces/DecodedNonceAccount.html +6 -6
  300. package/dist/docs/interfaces/DecodedStakeAccount.html +2 -2
  301. package/dist/docs/interfaces/DecodedToken2022Account.html +9 -9
  302. package/dist/docs/interfaces/DecodedToken2022Mint.html +6 -6
  303. package/dist/docs/interfaces/DecodedTokenAccount.html +9 -9
  304. package/dist/docs/interfaces/DefaultAccountStateExt.html +2 -2
  305. package/dist/docs/interfaces/Disposable.html +2 -2
  306. package/dist/docs/interfaces/EndpointConnectConfig.html +5 -5
  307. package/dist/docs/interfaces/EpochInfo.html +7 -7
  308. package/dist/docs/interfaces/EpochSchedule.html +2 -2
  309. package/dist/docs/interfaces/FactoryProvider.html +2 -2
  310. package/dist/docs/interfaces/FetchedMint.html +6 -6
  311. package/dist/docs/interfaces/FetchedTokenAccount.html +6 -6
  312. package/dist/docs/interfaces/FreezeThawParams.html +6 -6
  313. package/dist/docs/interfaces/GetAccountInfoOpts.html +6 -6
  314. package/dist/docs/interfaces/GetAssetsByAuthorityParams.html +2 -2
  315. package/dist/docs/interfaces/GetAssetsByCreatorParams.html +2 -2
  316. package/dist/docs/interfaces/GetAssetsByGroupParams.html +2 -2
  317. package/dist/docs/interfaces/GetAssetsByOwnerParams.html +2 -2
  318. package/dist/docs/interfaces/GetBlockOpts.html +6 -6
  319. package/dist/docs/interfaces/GetBlockProductionOpts.html +6 -6
  320. package/dist/docs/interfaces/GetMultipleAccountsOpts.html +6 -6
  321. package/dist/docs/interfaces/GetProgramAccountsOpts.html +6 -6
  322. package/dist/docs/interfaces/GetSignatureStatusesOpts.html +6 -6
  323. package/dist/docs/interfaces/GetSignaturesOpts.html +7 -7
  324. package/dist/docs/interfaces/GetTokenAccountsParams.html +2 -2
  325. package/dist/docs/interfaces/GetTransactionOpts.html +6 -6
  326. package/dist/docs/interfaces/GeyserParserConfig.html +6 -6
  327. package/dist/docs/interfaces/GeyserParserEvents.html +9 -9
  328. package/dist/docs/interfaces/GeyserParserStats.html +2 -2
  329. package/dist/docs/interfaces/GrpcCallOptions.html +2 -2
  330. package/dist/docs/interfaces/GrpcTransportConfig.html +6 -6
  331. package/dist/docs/interfaces/ImmutableOwnerExt.html +2 -2
  332. package/dist/docs/interfaces/InflationGovernor.html +2 -2
  333. package/dist/docs/interfaces/InflationRate.html +2 -2
  334. package/dist/docs/interfaces/InflationReward.html +2 -2
  335. package/dist/docs/interfaces/InitializeAccountParams.html +5 -5
  336. package/dist/docs/interfaces/InitializeMintParams.html +6 -6
  337. package/dist/docs/interfaces/InitializeNonceParams.html +3 -3
  338. package/dist/docs/interfaces/InterestBearingConfigExt.html +2 -2
  339. package/dist/docs/interfaces/LatencyProbeResult.html +2 -2
  340. package/dist/docs/interfaces/LeakReport.html +5 -5
  341. package/dist/docs/interfaces/LogsNotification.html +2 -2
  342. package/dist/docs/interfaces/LogsSubParams.html +2 -2
  343. package/dist/docs/interfaces/MemoTransferExt.html +2 -2
  344. package/dist/docs/interfaces/MemoryGuardConfig.html +4 -4
  345. package/dist/docs/interfaces/MetadataPointerExt.html +2 -2
  346. package/dist/docs/interfaces/MintCloseAuthorityExt.html +2 -2
  347. package/dist/docs/interfaces/MintToCheckedParams.html +8 -8
  348. package/dist/docs/interfaces/MintToParams.html +7 -7
  349. package/dist/docs/interfaces/NonTransferableExt.html +2 -2
  350. package/dist/docs/interfaces/PaginationOpts.html +2 -2
  351. package/dist/docs/interfaces/ParsedAccountUpdate.html +16 -16
  352. package/dist/docs/interfaces/ParsedBlockMeta.html +2 -2
  353. package/dist/docs/interfaces/ParsedEntry.html +2 -2
  354. package/dist/docs/interfaces/ParsedInstruction.html +9 -9
  355. package/dist/docs/interfaces/ParsedSlotUpdate.html +3 -3
  356. package/dist/docs/interfaces/ParsedTransaction.html +19 -19
  357. package/dist/docs/interfaces/PerfSample.html +2 -2
  358. package/dist/docs/interfaces/PermanentDelegateExt.html +2 -2
  359. package/dist/docs/interfaces/ProgramAccount.html +2 -2
  360. package/dist/docs/interfaces/ProgramNotification.html +2 -2
  361. package/dist/docs/interfaces/ProgramSubParams.html +2 -2
  362. package/dist/docs/interfaces/ProgramsBundle.html +33 -33
  363. package/dist/docs/interfaces/RawAccountInfo.html +2 -2
  364. package/dist/docs/interfaces/RawBlockMeta.html +2 -2
  365. package/dist/docs/interfaces/RawBuffer.html +2 -2
  366. package/dist/docs/interfaces/RawCompiledInstruction.html +2 -2
  367. package/dist/docs/interfaces/RawEntry.html +2 -2
  368. package/dist/docs/interfaces/RawGeyserUpdate.html +2 -2
  369. package/dist/docs/interfaces/RawInnerInstruction.html +2 -2
  370. package/dist/docs/interfaces/RawSlotInfo.html +2 -2
  371. package/dist/docs/interfaces/RawTimestamp.html +2 -2
  372. package/dist/docs/interfaces/RawTokenBalance.html +2 -2
  373. package/dist/docs/interfaces/RawTransactionInfo.html +2 -2
  374. package/dist/docs/interfaces/ReactAdapterConfig.html +2 -2
  375. package/dist/docs/interfaces/RecoverNestedParams.html +7 -7
  376. package/dist/docs/interfaces/RefRegistryConfig.html +2 -2
  377. package/dist/docs/interfaces/RefStats.html +7 -7
  378. package/dist/docs/interfaces/RequestHeapFrameParams.html +2 -2
  379. package/dist/docs/interfaces/ResolveMiddleware.html +1 -1
  380. package/dist/docs/interfaces/RevokeParams.html +5 -5
  381. package/dist/docs/interfaces/RootNotification.html +2 -2
  382. package/dist/docs/interfaces/RootSubParams.html +1 -1
  383. package/dist/docs/interfaces/RpcContext.html +2 -2
  384. package/dist/docs/interfaces/RpcError.html +4 -4
  385. package/dist/docs/interfaces/RpcRequest.html +3 -3
  386. package/dist/docs/interfaces/RpcResponse.html +2 -2
  387. package/dist/docs/interfaces/SendTransactionOpts.html +6 -6
  388. package/dist/docs/interfaces/ServerAdapterConfig.html +3 -3
  389. package/dist/docs/interfaces/ServiceBinding.html +6 -6
  390. package/dist/docs/interfaces/ServiceRegistration.html +3 -3
  391. package/dist/docs/interfaces/ServiceResolver.html +6 -6
  392. package/dist/docs/interfaces/ServiceToken.html +4 -4
  393. package/dist/docs/interfaces/SetComputeUnitLimitParams.html +2 -2
  394. package/dist/docs/interfaces/SetComputeUnitPriceParams.html +2 -2
  395. package/dist/docs/interfaces/SetLoadedAccountsDataSizeLimitParams.html +2 -2
  396. package/dist/docs/interfaces/SignatureInfo.html +7 -7
  397. package/dist/docs/interfaces/SignatureNotification.html +2 -2
  398. package/dist/docs/interfaces/SignatureStatus.html +5 -5
  399. package/dist/docs/interfaces/SignatureSubParams.html +2 -2
  400. package/dist/docs/interfaces/SignaturesForAssetParams.html +2 -2
  401. package/dist/docs/interfaces/SimulateResult.html +2 -2
  402. package/dist/docs/interfaces/SimulateTransactionOpts.html +7 -7
  403. package/dist/docs/interfaces/SingletonOptions.html +7 -0
  404. package/dist/docs/interfaces/SlotNotification.html +2 -2
  405. package/dist/docs/interfaces/SlotSubParams.html +1 -1
  406. package/dist/docs/interfaces/SortOpts.html +2 -2
  407. package/dist/docs/interfaces/StakeAuthorized.html +2 -2
  408. package/dist/docs/interfaces/StakeDelegation.html +3 -3
  409. package/dist/docs/interfaces/StakeLockup.html +4 -4
  410. package/dist/docs/interfaces/StakeMeta.html +2 -2
  411. package/dist/docs/interfaces/Supply.html +5 -5
  412. package/dist/docs/interfaces/SynapseClientConfig.html +9 -9
  413. package/dist/docs/interfaces/SynapseClientLike.html +2 -2
  414. package/dist/docs/interfaces/SynapseEndpoint.html +7 -7
  415. package/dist/docs/interfaces/SyncNativeParams.html +3 -3
  416. package/dist/docs/interfaces/SystemTransferParams.html +4 -4
  417. package/dist/docs/interfaces/TokenAccount.html +3 -3
  418. package/dist/docs/interfaces/TokenAccountsByOwnerResult.html +2 -2
  419. package/dist/docs/interfaces/TokenAmount.html +5 -5
  420. package/dist/docs/interfaces/TokenBalanceChange.html +2 -2
  421. package/dist/docs/interfaces/TokenTransferParams.html +7 -7
  422. package/dist/docs/interfaces/TransactionInstruction.html +4 -4
  423. package/dist/docs/interfaces/TransactionMeta.html +11 -11
  424. package/dist/docs/interfaces/TransferCheckedParams.html +9 -9
  425. package/dist/docs/interfaces/TransferFeeAmount.html +2 -2
  426. package/dist/docs/interfaces/TransferFeeConfig.html +2 -2
  427. package/dist/docs/interfaces/TransportConfig.html +7 -7
  428. package/dist/docs/interfaces/UnknownExtension.html +2 -2
  429. package/dist/docs/interfaces/ValueProvider.html +2 -2
  430. package/dist/docs/interfaces/VoteAccount.html +9 -9
  431. package/dist/docs/interfaces/VoteAccountsResult.html +3 -3
  432. package/dist/docs/interfaces/WithdrawNonceParams.html +5 -5
  433. package/dist/docs/interfaces/WsConfig.html +6 -6
  434. package/dist/docs/media/CHANGELOG.md +74 -0
  435. package/dist/docs/modules.html +4 -0
  436. package/dist/docs/types/AccountFetchOpts.html +1 -1
  437. package/dist/docs/types/AccountFilter.html +1 -1
  438. package/dist/docs/types/Base58.html +1 -1
  439. package/dist/docs/types/Brand.html +1 -1
  440. package/dist/docs/types/Commitment.html +1 -1
  441. package/dist/docs/types/DasSortBy.html +1 -1
  442. package/dist/docs/types/DasSortDirection.html +1 -1
  443. package/dist/docs/types/DataSizeFilter.html +1 -1
  444. package/dist/docs/types/DecodedExtension.html +1 -1
  445. package/dist/docs/types/Encoding.html +1 -1
  446. package/dist/docs/types/Epoch.html +1 -1
  447. package/dist/docs/types/Lamports.html +1 -1
  448. package/dist/docs/types/LogsFilter.html +1 -1
  449. package/dist/docs/types/MemcmpFilter.html +1 -1
  450. package/dist/docs/types/NonceState.html +1 -1
  451. package/dist/docs/types/ParsedGeyserUpdate.html +1 -1
  452. package/dist/docs/types/Pubkey.html +1 -1
  453. package/dist/docs/types/RuntimeEnv.html +1 -1
  454. package/dist/docs/types/ServiceLifecycle.html +1 -1
  455. package/dist/docs/types/ServiceProvider.html +1 -1
  456. package/dist/docs/types/Signature.html +1 -1
  457. package/dist/docs/types/Slot.html +1 -1
  458. package/dist/docs/types/StakeAccountType.html +1 -1
  459. package/dist/docs/types/SubscriptionId.html +1 -1
  460. package/dist/docs/types/TokenAccountState.html +1 -1
  461. package/dist/docs/types/TransactionDetail.html +1 -1
  462. package/dist/docs/types/UnaryMethod.html +1 -1
  463. package/dist/docs/types/UnixTimestamp.html +1 -1
  464. package/dist/docs/types/WsNotification.html +1 -1
  465. package/dist/docs/variables/ASSOCIATED_TOKEN_PROGRAM.html +1 -1
  466. package/dist/docs/variables/AssociatedToken.html +4 -4
  467. package/dist/docs/variables/COMPUTE_BUDGET_PROGRAM.html +1 -1
  468. package/dist/docs/variables/ComputeBudget.html +5 -5
  469. package/dist/docs/variables/JUPITER_PROGRAMS.html +1 -1
  470. package/dist/docs/variables/KNOWN_PROGRAMS.html +1 -1
  471. package/dist/docs/variables/KNOWN_PROGRAMS_COUNT.html +1 -1
  472. package/dist/docs/variables/LOOKUP_TABLE_HEADER_SIZE.html +1 -1
  473. package/dist/docs/variables/LOOKUP_TABLE_PROGRAM_ID.html +1 -1
  474. package/dist/docs/variables/MARINADE_PROGRAMS.html +1 -1
  475. package/dist/docs/variables/MAX_MULTISIG_SIGNERS.html +1 -1
  476. package/dist/docs/variables/MEMO_PROGRAM_V1.html +1 -1
  477. package/dist/docs/variables/MEMO_PROGRAM_V2.html +1 -1
  478. package/dist/docs/variables/METAPLEX_PROGRAMS.html +1 -1
  479. package/dist/docs/variables/METEORA_PROGRAMS.html +1 -1
  480. package/dist/docs/variables/MINT_SIZE.html +1 -1
  481. package/dist/docs/variables/MULTISIG_SIZE.html +1 -1
  482. package/dist/docs/variables/Memo.html +2 -2
  483. package/dist/docs/variables/NONCE_ACCOUNT_SIZE.html +1 -1
  484. package/dist/docs/variables/ORCA_PROGRAMS.html +1 -1
  485. package/dist/docs/variables/OTHER_PROGRAMS.html +1 -1
  486. package/dist/docs/variables/RAYDIUM_PROGRAMS.html +1 -1
  487. package/dist/docs/variables/SDK_USER_AGENT.html +1 -1
  488. package/dist/docs/variables/SPL_PROGRAMS.html +1 -1
  489. package/dist/docs/variables/STAKE_PROGRAM_ID.html +1 -1
  490. package/dist/docs/variables/SYNAPSE_DEVNET_EU.html +1 -1
  491. package/dist/docs/variables/SYNAPSE_DEVNET_US.html +1 -1
  492. package/dist/docs/variables/SYNAPSE_ENDPOINTS.html +1 -1
  493. package/dist/docs/variables/SYNAPSE_MAINNET_EU.html +1 -1
  494. package/dist/docs/variables/SYNAPSE_MAINNET_US.html +1 -1
  495. package/dist/docs/variables/SYSTEM_PROGRAM.html +1 -1
  496. package/dist/docs/variables/SYSTEM_PROGRAMS.html +1 -1
  497. package/dist/docs/variables/SYSTEM_PROGRAM_ID.html +1 -1
  498. package/dist/docs/variables/SplToken.html +16 -16
  499. package/dist/docs/variables/SystemProgram.html +10 -10
  500. package/dist/docs/variables/TOKEN_2022_PROGRAM.html +1 -1
  501. package/dist/docs/variables/TOKEN_2022_PROGRAM_ID.html +1 -1
  502. package/dist/docs/variables/TOKEN_ACCOUNT_SIZE.html +1 -1
  503. package/dist/docs/variables/TOKEN_PROGRAM.html +1 -1
  504. package/dist/docs/variables/TOKEN_PROGRAM_ID.html +1 -1
  505. package/dist/docs/variables/Tokens.html +1 -1
  506. package/dist/esm/ai/gateway/index.d.ts +86 -5
  507. package/dist/esm/ai/gateway/index.d.ts.map +1 -1
  508. package/dist/esm/ai/gateway/index.js +275 -39
  509. package/dist/esm/ai/gateway/index.js.map +1 -1
  510. package/dist/esm/ai/gateway/registry.d.ts +223 -0
  511. package/dist/esm/ai/gateway/registry.d.ts.map +1 -0
  512. package/dist/esm/ai/gateway/registry.js +285 -0
  513. package/dist/esm/ai/gateway/registry.js.map +1 -0
  514. package/dist/esm/ai/gateway/types.d.ts +107 -1
  515. package/dist/esm/ai/gateway/types.d.ts.map +1 -1
  516. package/dist/esm/ai/gateway/x402/index.d.ts +2 -4
  517. package/dist/esm/ai/gateway/x402/index.d.ts.map +1 -1
  518. package/dist/esm/ai/gateway/x402/index.js +2 -3
  519. package/dist/esm/ai/gateway/x402/index.js.map +1 -1
  520. package/dist/esm/ai/gateway/x402/registry.d.ts +131 -1
  521. package/dist/esm/ai/gateway/x402/registry.d.ts.map +1 -1
  522. package/dist/esm/ai/gateway/x402/registry.js +227 -0
  523. package/dist/esm/ai/gateway/x402/registry.js.map +1 -1
  524. package/dist/esm/ai/index.d.ts +2 -1
  525. package/dist/esm/ai/index.d.ts.map +1 -1
  526. package/dist/esm/ai/index.js +13 -1
  527. package/dist/esm/ai/index.js.map +1 -1
  528. package/dist/esm/ai/persistence/helpers.d.ts +83 -0
  529. package/dist/esm/ai/persistence/helpers.d.ts.map +1 -0
  530. package/dist/esm/ai/persistence/helpers.js +183 -0
  531. package/dist/esm/ai/persistence/helpers.js.map +1 -0
  532. package/dist/esm/ai/persistence/index.d.ts +91 -0
  533. package/dist/esm/ai/persistence/index.d.ts.map +1 -0
  534. package/dist/esm/ai/persistence/index.js +94 -0
  535. package/dist/esm/ai/persistence/index.js.map +1 -0
  536. package/dist/esm/ai/persistence/memory.d.ts +71 -0
  537. package/dist/esm/ai/persistence/memory.d.ts.map +1 -0
  538. package/dist/esm/ai/persistence/memory.js +188 -0
  539. package/dist/esm/ai/persistence/memory.js.map +1 -0
  540. package/dist/esm/ai/persistence/postgresql.d.ts +119 -0
  541. package/dist/esm/ai/persistence/postgresql.d.ts.map +1 -0
  542. package/dist/esm/ai/persistence/postgresql.js +306 -0
  543. package/dist/esm/ai/persistence/postgresql.js.map +1 -0
  544. package/dist/esm/ai/persistence/redis.d.ts +84 -0
  545. package/dist/esm/ai/persistence/redis.d.ts.map +1 -0
  546. package/dist/esm/ai/persistence/redis.js +237 -0
  547. package/dist/esm/ai/persistence/redis.js.map +1 -0
  548. package/dist/esm/ai/persistence/types.d.ts +267 -0
  549. package/dist/esm/ai/persistence/types.d.ts.map +1 -0
  550. package/dist/esm/ai/persistence/types.js +36 -0
  551. package/dist/esm/ai/persistence/types.js.map +1 -0
  552. package/dist/esm/core/client.d.ts +16 -0
  553. package/dist/esm/core/client.d.ts.map +1 -1
  554. package/dist/esm/core/client.js +18 -0
  555. package/dist/esm/core/client.js.map +1 -1
  556. package/dist/esm/next/index.d.ts +141 -0
  557. package/dist/esm/next/index.d.ts.map +1 -0
  558. package/dist/esm/next/index.js +171 -0
  559. package/dist/esm/next/index.js.map +1 -0
  560. package/dist/esm/utils/helpers.d.ts +79 -1
  561. package/dist/esm/utils/helpers.d.ts.map +1 -1
  562. package/dist/esm/utils/helpers.js +106 -0
  563. package/dist/esm/utils/helpers.js.map +1 -1
  564. package/package.json +20 -2
@@ -0,0 +1,310 @@
1
+ "use strict";
2
+ /**
3
+ * @module ai/persistence/postgresql
4
+ * @description PostgreSQL persistence adapter for Synapse AI gateway data.
5
+ *
6
+ * Stores agent snapshots, sessions, receipts, and metric time-series in
7
+ * PostgreSQL using JSONB columns, with automatic schema migration on
8
+ * first `connect()`.
9
+ *
10
+ * Bring your own client — the adapter works with any library that satisfies
11
+ * the {@link PgLike} interface:
12
+ * - **pg** (`new Pool()` or `new Client()`)
13
+ * - **@vercel/postgres** (`createPool()`)
14
+ * - **@neondatabase/serverless** (`neon()`)
15
+ *
16
+ * @since 1.2.2
17
+ *
18
+ * @example
19
+ * ```ts
20
+ * import { Pool } from 'pg';
21
+ * import { PostgresPersistence } from '@oobe-protocol-labs/synapse-client-sdk/ai';
22
+ *
23
+ * const pool = new Pool({ connectionString: process.env.DATABASE_URL });
24
+ * const store = new PostgresPersistence({ client: pool });
25
+ * await store.connect(); // runs migrations
26
+ *
27
+ * await store.saveAgent(gateway.snapshot());
28
+ * const receipts = await store.listReceipts('agent-1', { limit: 50 });
29
+ *
30
+ * // Drop-in for AgentRegistry:
31
+ * const registry = new AgentRegistry({ persistence: store });
32
+ * ```
33
+ */
34
+ Object.defineProperty(exports, "__esModule", { value: true });
35
+ exports.PostgresPersistence = void 0;
36
+ const types_1 = require("./types");
37
+ const helpers_1 = require("./helpers");
38
+ /**
39
+ * @description PostgreSQL implementation of {@link PersistenceStore}.
40
+ *
41
+ * Table layout (default prefix `synapse`):
42
+ * ```
43
+ * synapse_agents (agent_id PK, snapshot JSONB)
44
+ * synapse_sessions (agent_id + id PK, state JSONB, status)
45
+ * synapse_receipts (id PK, agent_id, receipt JSONB)
46
+ * synapse_metrics (id BIGSERIAL, agent_id, metric_key, value, labels, recorded_at)
47
+ * synapse_kv (key PK, value JSONB, expires_at)
48
+ * synapse_schema_version (version PK, applied_at)
49
+ * ```
50
+ *
51
+ * @since 1.2.2
52
+ */
53
+ class PostgresPersistence {
54
+ name = 'postgresql';
55
+ client;
56
+ prefix;
57
+ autoMigrate;
58
+ migrated = false;
59
+ constructor(config) {
60
+ this.client = config.client;
61
+ this.prefix = config.keyPrefix ?? 'synapse';
62
+ this.autoMigrate = config.autoMigrate ?? true;
63
+ }
64
+ /* ── Lifecycle ─────────────────────────────────────────── */
65
+ async connect() {
66
+ try {
67
+ // Verify connection
68
+ await this.client.query('SELECT 1');
69
+ // Auto-migrate if enabled and not yet done
70
+ if (this.autoMigrate && !this.migrated) {
71
+ await this.migrate();
72
+ }
73
+ }
74
+ catch (err) {
75
+ throw new types_1.PersistenceError('Failed to connect to PostgreSQL', 'CONN_FAILED', err);
76
+ }
77
+ }
78
+ async disconnect() {
79
+ try {
80
+ if (this.client.end)
81
+ await this.client.end();
82
+ }
83
+ catch {
84
+ // Swallow — already disconnected
85
+ }
86
+ }
87
+ async ping() {
88
+ try {
89
+ await this.client.query('SELECT 1');
90
+ return true;
91
+ }
92
+ catch {
93
+ return false;
94
+ }
95
+ }
96
+ /**
97
+ * @description Run schema migrations.
98
+ *
99
+ * Called automatically on `connect()` if `autoMigrate` is `true` (default).
100
+ * Safe to call multiple times — all DDL uses `IF NOT EXISTS`.
101
+ *
102
+ * @since 1.2.2
103
+ */
104
+ async migrate() {
105
+ try {
106
+ const ddl = (0, helpers_1.buildSchema)(this.prefix);
107
+ await this.client.query(ddl);
108
+ this.migrated = true;
109
+ }
110
+ catch (err) {
111
+ throw new types_1.PersistenceError('Schema migration failed', 'MIGRATION_FAILED', err);
112
+ }
113
+ }
114
+ /* ── Generic KV ────────────────────────────────────────── */
115
+ t(name) {
116
+ return `${this.prefix}_${name}`;
117
+ }
118
+ async get(key) {
119
+ const { rows } = await this.client.query(`SELECT value FROM ${this.t('kv')}
120
+ WHERE key = $1 AND (expires_at IS NULL OR expires_at > NOW())`, [key]);
121
+ if (rows.length === 0)
122
+ return null;
123
+ return rows[0].value;
124
+ }
125
+ async set(key, value, opts) {
126
+ const parsed = JSON.parse((0, helpers_1.serialize)(value));
127
+ const expiresAt = opts?.ttl && opts.ttl > 0
128
+ ? new Date(Date.now() + opts.ttl * 1000).toISOString()
129
+ : null;
130
+ await this.client.query(`INSERT INTO ${this.t('kv')} (key, value, expires_at)
131
+ VALUES ($1, $2, $3)
132
+ ON CONFLICT (key)
133
+ DO UPDATE SET value = EXCLUDED.value, expires_at = EXCLUDED.expires_at`, [key, parsed, expiresAt]);
134
+ }
135
+ async del(key) {
136
+ const { rowCount } = await this.client.query(`DELETE FROM ${this.t('kv')} WHERE key = $1`, [key]);
137
+ return (rowCount ?? 0) > 0;
138
+ }
139
+ async has(key) {
140
+ const { rows } = await this.client.query(`SELECT COUNT(*)::text AS n FROM ${this.t('kv')}
141
+ WHERE key = $1 AND (expires_at IS NULL OR expires_at > NOW())`, [key]);
142
+ return parseInt(rows[0]?.n ?? '0', 10) > 0;
143
+ }
144
+ /* ── Agents ────────────────────────────────────────────── */
145
+ async saveAgent(snapshot) {
146
+ const parsed = JSON.parse((0, helpers_1.serialize)(snapshot));
147
+ await this.client.query(`INSERT INTO ${this.t('agents')} (agent_id, snapshot, updated_at)
148
+ VALUES ($1, $2, NOW())
149
+ ON CONFLICT (agent_id)
150
+ DO UPDATE SET snapshot = EXCLUDED.snapshot, updated_at = NOW()`, [snapshot.agentId, parsed]);
151
+ }
152
+ async loadAgent(agentId) {
153
+ const { rows } = await this.client.query(`SELECT snapshot FROM ${this.t('agents')} WHERE agent_id = $1`, [agentId]);
154
+ return rows[0]?.snapshot ?? null;
155
+ }
156
+ async deleteAgent(agentId) {
157
+ const { rowCount } = await this.client.query(`DELETE FROM ${this.t('agents')} WHERE agent_id = $1`, [agentId]);
158
+ return (rowCount ?? 0) > 0;
159
+ }
160
+ async listAgents() {
161
+ const { rows } = await this.client.query(`SELECT agent_id FROM ${this.t('agents')} ORDER BY created_at`);
162
+ return rows.map(r => r.agent_id);
163
+ }
164
+ /* ── Sessions ──────────────────────────────────────────── */
165
+ async saveSession(record) {
166
+ const parsed = JSON.parse((0, helpers_1.serialize)(record));
167
+ await this.client.query(`INSERT INTO ${this.t('sessions')} (id, agent_id, state, status, updated_at)
168
+ VALUES ($1, $2, $3, $4, NOW())
169
+ ON CONFLICT (agent_id, id)
170
+ DO UPDATE SET state = EXCLUDED.state, status = EXCLUDED.status, updated_at = NOW()`, [record.id, record.agentId, parsed, record.status]);
171
+ }
172
+ async loadSession(agentId, sessionId) {
173
+ const { rows } = await this.client.query(`SELECT state FROM ${this.t('sessions')} WHERE agent_id = $1 AND id = $2`, [agentId, sessionId]);
174
+ return rows[0]?.state ?? null;
175
+ }
176
+ async deleteSessions(agentId) {
177
+ const { rowCount } = await this.client.query(`DELETE FROM ${this.t('sessions')} WHERE agent_id = $1`, [agentId]);
178
+ return rowCount ?? 0;
179
+ }
180
+ async listSessions(agentId, opts = {}) {
181
+ const conditions = ['agent_id = $1'];
182
+ const params = [agentId];
183
+ let paramIdx = 2;
184
+ if (opts.status) {
185
+ conditions.push(`status = $${paramIdx++}`);
186
+ params.push(opts.status);
187
+ }
188
+ const limit = opts.limit ?? 100;
189
+ const offset = opts.offset ?? 0;
190
+ const { rows } = await this.client.query(`SELECT state FROM ${this.t('sessions')}
191
+ WHERE ${conditions.join(' AND ')}
192
+ ORDER BY created_at DESC
193
+ LIMIT $${paramIdx++} OFFSET $${paramIdx}`, [...params, limit, offset]);
194
+ return rows.map(r => r.state);
195
+ }
196
+ /* ── Receipts ──────────────────────────────────────────── */
197
+ async saveReceipt(record) {
198
+ const parsed = JSON.parse((0, helpers_1.serialize)(record));
199
+ await this.client.query(`INSERT INTO ${this.t('receipts')} (id, agent_id, session_id, receipt, amount_charged, settled_at)
200
+ VALUES ($1, $2, $3, $4, $5, to_timestamp($6 / 1000.0))
201
+ ON CONFLICT (id) DO NOTHING`, [record.id, record.agentId, record.sessionId ?? null, parsed, record.amountCharged, record.settledAt]);
202
+ }
203
+ async listReceipts(agentId, opts = {}) {
204
+ const limit = opts.limit ?? 100;
205
+ const offset = opts.offset ?? 0;
206
+ const { rows } = await this.client.query(`SELECT receipt FROM ${this.t('receipts')}
207
+ WHERE agent_id = $1
208
+ ORDER BY settled_at DESC
209
+ LIMIT $2 OFFSET $3`, [agentId, limit, offset]);
210
+ return rows.map(r => r.receipt);
211
+ }
212
+ /* ── Metrics ───────────────────────────────────────────── */
213
+ async recordMetric(agentId, key, value, labels) {
214
+ await this.client.query(`INSERT INTO ${this.t('metrics')} (agent_id, metric_key, value, labels)
215
+ VALUES ($1, $2, $3, $4)`, [agentId, key, value, labels ? JSON.parse(JSON.stringify(labels)) : {}]);
216
+ }
217
+ async queryMetrics(agentId, key, opts = {}) {
218
+ const conditions = ['agent_id = $1', 'metric_key = $2'];
219
+ const params = [agentId, key];
220
+ let paramIdx = 3;
221
+ if (opts.from != null) {
222
+ conditions.push(`recorded_at >= to_timestamp($${paramIdx++} / 1000.0)`);
223
+ params.push(opts.from);
224
+ }
225
+ if (opts.to != null) {
226
+ conditions.push(`recorded_at <= to_timestamp($${paramIdx++} / 1000.0)`);
227
+ params.push(opts.to);
228
+ }
229
+ const limit = opts.limit ?? 1000;
230
+ const { rows } = await this.client.query(`SELECT value, labels, recorded_at
231
+ FROM ${this.t('metrics')}
232
+ WHERE ${conditions.join(' AND ')}
233
+ ORDER BY recorded_at DESC
234
+ LIMIT $${paramIdx}`, [...params, limit]);
235
+ return rows.map(r => ({
236
+ timestamp: new Date(r.recorded_at).getTime(),
237
+ value: Number(r.value),
238
+ labels: r.labels && Object.keys(r.labels).length > 0 ? r.labels : undefined,
239
+ }));
240
+ }
241
+ /* ── Maintenance ───────────────────────────────────────── */
242
+ /**
243
+ * @description Delete expired KV entries and old metric data.
244
+ *
245
+ * Call periodically (e.g. via a cron job) to reclaim storage.
246
+ *
247
+ * @param {object} [opts] - Cleanup options
248
+ * @param {number} [opts.metricsOlderThanDays=90] - Delete metrics older than N days
249
+ * @returns {Promise<{ kvDeleted: number; metricsDeleted: number }>}
250
+ * @since 1.2.2
251
+ */
252
+ async cleanup(opts = {}) {
253
+ const kvResult = await this.client.query((0, helpers_1.buildKvCleanupSql)(this.prefix));
254
+ const days = opts.metricsOlderThanDays ?? 90;
255
+ const metricsResult = await this.client.query(`DELETE FROM ${this.t('metrics')}
256
+ WHERE recorded_at < NOW() - INTERVAL '${days} days'`);
257
+ return {
258
+ kvDeleted: kvResult.rowCount ?? 0,
259
+ metricsDeleted: metricsResult.rowCount ?? 0,
260
+ };
261
+ }
262
+ /**
263
+ * @description Get the currently applied schema version.
264
+ * @returns {Promise<number>} Schema version, or `0` if not yet migrated.
265
+ * @since 1.2.2
266
+ */
267
+ async getSchemaVersion() {
268
+ try {
269
+ const { rows } = await this.client.query(`SELECT MAX(version) AS version FROM ${this.t('schema_version')}`);
270
+ return rows[0]?.version ?? 0;
271
+ }
272
+ catch {
273
+ return 0; // Table doesn't exist yet
274
+ }
275
+ }
276
+ /**
277
+ * @description Get row counts for all tables (useful for monitoring).
278
+ * @returns {Promise<Record<string, number>>} Table name → row count
279
+ * @since 1.2.2
280
+ */
281
+ async getTableStats() {
282
+ const tables = ['agents', 'sessions', 'receipts', 'metrics', 'kv'];
283
+ const stats = {};
284
+ for (const table of tables) {
285
+ try {
286
+ const { rows } = await this.client.query(`SELECT COUNT(*)::text AS n FROM ${this.t(table)}`);
287
+ stats[table] = parseInt(rows[0]?.n ?? '0', 10);
288
+ }
289
+ catch {
290
+ stats[table] = -1; // Table doesn't exist
291
+ }
292
+ }
293
+ return stats;
294
+ }
295
+ /* ── PersistenceAdapter compat ─────────────────────────── */
296
+ async save(agentId, snapshot) {
297
+ return this.saveAgent(snapshot);
298
+ }
299
+ async load(agentId) {
300
+ return this.loadAgent(agentId);
301
+ }
302
+ async delete(agentId) {
303
+ await this.deleteAgent(agentId);
304
+ }
305
+ async keys() {
306
+ return this.listAgents();
307
+ }
308
+ }
309
+ exports.PostgresPersistence = PostgresPersistence;
310
+ //# sourceMappingURL=postgresql.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"postgresql.js","sourceRoot":"","sources":["../../../../src/ai/persistence/postgresql.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;;;AAaH,mCA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AM,EAAE,CAAC;YAC3B,IAAI,CAAC;gBACH,MAAM,EAAE,IAAI,EAAE,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,KAAK,CACtC,mCAAmC,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC,EAAE,CACnD,CAAC;gBACF,KAAK,CAAC,KAAK,CAAC,GAAG,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,IAAI,GAAG,EAAE,EAAE,CAAC,CAAC;YACjD,CAAC;YAAC,MAAM,CAAC;gBACP,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,sBAAsB;YAC3C,CAAC;QACH,CAAC;QACD,OAAO,KAAK,CAAC;IACf,CAAC;IAED,8DAA8D;IAE9D,KAAK,CAAC,IAAI,CAAC,OAAe,EAAE,QAAyB;QACnD,OAAO,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC;IAClC,CAAC;IAED,KAAK,CAAC,IAAI,CAAC,OAAe;QACxB,OAAO,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC;IACjC,CAAC;IAED,KAAK,CAAC,MAAM,CAAC,OAAe;QAC1B,MAAM,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;IAClC,CAAC;IAED,KAAK,CAAC,IAAI;QACR,OAAO,IAAI,CAAC,UAAU,EAAE,CAAC;IAC3B,CAAC;CACF;AAzWD,kDAyWC"}
@@ -0,0 +1,84 @@
1
+ /**
2
+ * @module ai/persistence/redis
3
+ * @description Redis persistence adapter for Synapse AI gateway data.
4
+ *
5
+ * Stores agent snapshots, sessions, receipts, metrics, and arbitrary
6
+ * key-value data in Redis using JSON serialization and configurable
7
+ * key prefixing.
8
+ *
9
+ * Bring your own Redis client — the adapter works with any library
10
+ * that satisfies the {@link RedisLike} interface:
11
+ * - **ioredis** (`new Redis()`)
12
+ * - **node-redis v4** (`createClient()`)
13
+ * - **@upstash/redis** (REST-based, partial)
14
+ *
15
+ * @since 1.2.2
16
+ *
17
+ * @example
18
+ * ```ts
19
+ * import Redis from 'ioredis';
20
+ * import { RedisPersistence } from '@oobe-protocol-labs/synapse-client-sdk/ai';
21
+ *
22
+ * const redis = new Redis(process.env.REDIS_URL);
23
+ * const store = new RedisPersistence({ client: redis });
24
+ * await store.connect();
25
+ *
26
+ * await store.saveAgent(gateway.snapshot());
27
+ * await store.saveSession(sessionRecord);
28
+ *
29
+ * // Drop-in for AgentRegistry:
30
+ * const registry = new AgentRegistry({ persistence: store });
31
+ * ```
32
+ */
33
+ import type { PersistenceStore, RedisStoreConfig, SetOptions, ListOptions, MetricQueryOpts, SessionRecord, ReceiptRecord, MetricPoint } from './types';
34
+ import type { GatewaySnapshot } from '../gateway/types';
35
+ /**
36
+ * @description Redis implementation of {@link PersistenceStore}.
37
+ *
38
+ * Key layout (default prefix `synapse`):
39
+ * ```
40
+ * synapse:kv:{key} → generic KV
41
+ * synapse:agent:{agentId} → agent snapshot JSON
42
+ * synapse:session:{agentId}:{sessionId} → session record JSON
43
+ * synapse:receipts:{agentId} → JSON array of receipts
44
+ * synapse:metrics:{agentId}:{metricKey} → JSON array of MetricPoint
45
+ * ```
46
+ *
47
+ * @since 1.2.2
48
+ */
49
+ export declare class RedisPersistence implements PersistenceStore {
50
+ readonly name = "redis";
51
+ private readonly client;
52
+ private readonly prefix;
53
+ private readonly defaultTtl;
54
+ constructor(config: RedisStoreConfig);
55
+ connect(): Promise<void>;
56
+ disconnect(): Promise<void>;
57
+ ping(): Promise<boolean>;
58
+ private kvKey;
59
+ get<T = unknown>(key: string): Promise<T | null>;
60
+ set(key: string, value: unknown, opts?: SetOptions): Promise<void>;
61
+ del(key: string): Promise<boolean>;
62
+ has(key: string): Promise<boolean>;
63
+ private agentKey;
64
+ saveAgent(snapshot: GatewaySnapshot): Promise<void>;
65
+ loadAgent(agentId: string): Promise<GatewaySnapshot | null>;
66
+ deleteAgent(agentId: string): Promise<boolean>;
67
+ listAgents(): Promise<string[]>;
68
+ private sessionKey;
69
+ saveSession(record: SessionRecord): Promise<void>;
70
+ loadSession(agentId: string, sessionId: string): Promise<SessionRecord | null>;
71
+ deleteSessions(agentId: string): Promise<number>;
72
+ listSessions(agentId: string, opts?: ListOptions): Promise<SessionRecord[]>;
73
+ private receiptsKey;
74
+ saveReceipt(record: ReceiptRecord): Promise<void>;
75
+ listReceipts(agentId: string, opts?: ListOptions): Promise<ReceiptRecord[]>;
76
+ private metricsKey;
77
+ recordMetric(agentId: string, key: string, value: number, labels?: Record<string, string>): Promise<void>;
78
+ queryMetrics(agentId: string, key: string, opts?: MetricQueryOpts): Promise<MetricPoint[]>;
79
+ save(agentId: string, snapshot: GatewaySnapshot): Promise<void>;
80
+ load(agentId: string): Promise<GatewaySnapshot | null>;
81
+ delete(agentId: string): Promise<void>;
82
+ keys(): Promise<string[]>;
83
+ }
84
+ //# sourceMappingURL=redis.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"redis.d.ts","sourceRoot":"","sources":["../../../../src/ai/persistence/redis.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AAEH,OAAO,KAAK,EACV,gBAAgB,EAChB,gBAAgB,EAEhB,UAAU,EACV,WAAW,EACX,eAAe,EACf,aAAa,EACb,aAAa,EACb,WAAW,EACZ,MAAM,SAAS,CAAC;AAEjB,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAGxD;;;;;;;;;;;;;GAaG;AACH,qBAAa,gBAAiB,YAAW,gBAAgB;IACvD,QAAQ,CAAC,IAAI,WAAW;IAExB,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAY;IACnC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAS;IAChC,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAS;gBAExB,MAAM,EAAE,gBAAgB;IAQ9B,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAQxB,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;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B,GAAG,OAAO,CAAC,aAAa,EAAE,CAAC;IAYrF,OAAO,CAAC,UAAU;IAIZ,YAAY,CAChB,OAAO,EAAE,MAAM,EACf,GAAG,EAAE,MAAM,EACX,KAAK,EAAE,MAAM,EACb,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAC9B,OAAO,CAAC,IAAI,CAAC;IAUV,YAAY,CAChB,OAAO,EAAE,MAAM,EACf,GAAG,EAAE,MAAM,EACX,IAAI,GAAE,eAAoB,GACzB,OAAO,CAAC,WAAW,EAAE,CAAC;IAenB,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,eAAe,GAAG,OAAO,CAAC,IAAI,CAAC;IAI/D,IAAI,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,GAAG,IAAI,CAAC;IAItD,MAAM,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAItC,IAAI,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;CAGhC"}
@@ -0,0 +1,241 @@
1
+ "use strict";
2
+ /**
3
+ * @module ai/persistence/redis
4
+ * @description Redis persistence adapter for Synapse AI gateway data.
5
+ *
6
+ * Stores agent snapshots, sessions, receipts, metrics, and arbitrary
7
+ * key-value data in Redis using JSON serialization and configurable
8
+ * key prefixing.
9
+ *
10
+ * Bring your own Redis client — the adapter works with any library
11
+ * that satisfies the {@link RedisLike} interface:
12
+ * - **ioredis** (`new Redis()`)
13
+ * - **node-redis v4** (`createClient()`)
14
+ * - **@upstash/redis** (REST-based, partial)
15
+ *
16
+ * @since 1.2.2
17
+ *
18
+ * @example
19
+ * ```ts
20
+ * import Redis from 'ioredis';
21
+ * import { RedisPersistence } from '@oobe-protocol-labs/synapse-client-sdk/ai';
22
+ *
23
+ * const redis = new Redis(process.env.REDIS_URL);
24
+ * const store = new RedisPersistence({ client: redis });
25
+ * await store.connect();
26
+ *
27
+ * await store.saveAgent(gateway.snapshot());
28
+ * await store.saveSession(sessionRecord);
29
+ *
30
+ * // Drop-in for AgentRegistry:
31
+ * const registry = new AgentRegistry({ persistence: store });
32
+ * ```
33
+ */
34
+ Object.defineProperty(exports, "__esModule", { value: true });
35
+ exports.RedisPersistence = void 0;
36
+ const types_1 = require("./types");
37
+ const helpers_1 = require("./helpers");
38
+ /**
39
+ * @description Redis implementation of {@link PersistenceStore}.
40
+ *
41
+ * Key layout (default prefix `synapse`):
42
+ * ```
43
+ * synapse:kv:{key} → generic KV
44
+ * synapse:agent:{agentId} → agent snapshot JSON
45
+ * synapse:session:{agentId}:{sessionId} → session record JSON
46
+ * synapse:receipts:{agentId} → JSON array of receipts
47
+ * synapse:metrics:{agentId}:{metricKey} → JSON array of MetricPoint
48
+ * ```
49
+ *
50
+ * @since 1.2.2
51
+ */
52
+ class RedisPersistence {
53
+ name = 'redis';
54
+ client;
55
+ prefix;
56
+ defaultTtl;
57
+ constructor(config) {
58
+ this.client = config.client;
59
+ this.prefix = config.keyPrefix ?? 'synapse';
60
+ this.defaultTtl = config.defaultTtl ?? 0;
61
+ }
62
+ /* ── Lifecycle ─────────────────────────────────────────── */
63
+ async connect() {
64
+ try {
65
+ await this.client.ping();
66
+ }
67
+ catch (err) {
68
+ throw new types_1.PersistenceError('Failed to connect to Redis', 'CONN_FAILED', err);
69
+ }
70
+ }
71
+ async disconnect() {
72
+ try {
73
+ await this.client.quit();
74
+ }
75
+ catch {
76
+ // Swallow — already disconnected
77
+ }
78
+ }
79
+ async ping() {
80
+ try {
81
+ const res = await this.client.ping();
82
+ return res === 'PONG' || res === 'pong';
83
+ }
84
+ catch {
85
+ return false;
86
+ }
87
+ }
88
+ /* ── Generic KV ────────────────────────────────────────── */
89
+ kvKey(key) {
90
+ return (0, helpers_1.buildKey)(this.prefix, 'kv', key);
91
+ }
92
+ async get(key) {
93
+ const raw = await this.client.get(this.kvKey(key));
94
+ return raw ? (0, helpers_1.deserialize)(raw) : null;
95
+ }
96
+ async set(key, value, opts) {
97
+ const k = this.kvKey(key);
98
+ await this.client.set(k, (0, helpers_1.serialize)(value));
99
+ const ttl = opts?.ttl ?? this.defaultTtl;
100
+ if (ttl > 0)
101
+ await this.client.expire(k, ttl);
102
+ }
103
+ async del(key) {
104
+ const n = await this.client.del(this.kvKey(key));
105
+ return n > 0;
106
+ }
107
+ async has(key) {
108
+ const n = await this.client.exists(this.kvKey(key));
109
+ return n > 0;
110
+ }
111
+ /* ── Agents ────────────────────────────────────────────── */
112
+ agentKey(agentId) {
113
+ return (0, helpers_1.buildKey)(this.prefix, 'agent', agentId);
114
+ }
115
+ async saveAgent(snapshot) {
116
+ const k = this.agentKey(snapshot.agentId);
117
+ await this.client.set(k, (0, helpers_1.serialize)(snapshot));
118
+ if (this.defaultTtl > 0)
119
+ await this.client.expire(k, this.defaultTtl);
120
+ }
121
+ async loadAgent(agentId) {
122
+ const raw = await this.client.get(this.agentKey(agentId));
123
+ return raw ? (0, helpers_1.deserialize)(raw) : null;
124
+ }
125
+ async deleteAgent(agentId) {
126
+ const n = await this.client.del(this.agentKey(agentId));
127
+ return n > 0;
128
+ }
129
+ async listAgents() {
130
+ const pattern = (0, helpers_1.buildKey)(this.prefix, 'agent', '*');
131
+ const keys = await this.client.keys(pattern);
132
+ const prefixLen = (0, helpers_1.buildKey)(this.prefix, 'agent', '').length;
133
+ return keys.map(k => k.slice(prefixLen));
134
+ }
135
+ /* ── Sessions ──────────────────────────────────────────── */
136
+ sessionKey(agentId, sessionId) {
137
+ return (0, helpers_1.buildKey)(this.prefix, 'session', agentId, sessionId);
138
+ }
139
+ async saveSession(record) {
140
+ const k = this.sessionKey(record.agentId, record.id);
141
+ await this.client.set(k, (0, helpers_1.serialize)(record));
142
+ // Auto-expire sessions based on their TTL
143
+ if (record.ttl > 0)
144
+ await this.client.expire(k, record.ttl);
145
+ }
146
+ async loadSession(agentId, sessionId) {
147
+ const raw = await this.client.get(this.sessionKey(agentId, sessionId));
148
+ return raw ? (0, helpers_1.deserialize)(raw) : null;
149
+ }
150
+ async deleteSessions(agentId) {
151
+ const pattern = (0, helpers_1.buildKey)(this.prefix, 'session', agentId, '*');
152
+ const keys = await this.client.keys(pattern);
153
+ let count = 0;
154
+ for (const k of keys) {
155
+ count += await this.client.del(k);
156
+ }
157
+ return count;
158
+ }
159
+ async listSessions(agentId, opts = {}) {
160
+ const pattern = (0, helpers_1.buildKey)(this.prefix, 'session', agentId, '*');
161
+ const keys = await this.client.keys(pattern);
162
+ let records = [];
163
+ for (const k of keys) {
164
+ const raw = await this.client.get(k);
165
+ if (raw) {
166
+ const rec = (0, helpers_1.deserialize)(raw);
167
+ if (opts.status && rec.status !== opts.status)
168
+ continue;
169
+ records.push(rec);
170
+ }
171
+ }
172
+ records.sort((a, b) => b.createdAt - a.createdAt);
173
+ const offset = opts.offset ?? 0;
174
+ const limit = opts.limit ?? records.length;
175
+ return records.slice(offset, offset + limit);
176
+ }
177
+ /* ── Receipts ──────────────────────────────────────────── */
178
+ receiptsKey(agentId) {
179
+ return (0, helpers_1.buildKey)(this.prefix, 'receipts', agentId);
180
+ }
181
+ async saveReceipt(record) {
182
+ const k = this.receiptsKey(record.agentId);
183
+ const raw = await this.client.get(k);
184
+ const list = raw ? (0, helpers_1.deserialize)(raw) : [];
185
+ list.push(record);
186
+ await this.client.set(k, (0, helpers_1.serialize)(list));
187
+ }
188
+ async listReceipts(agentId, opts = {}) {
189
+ const raw = await this.client.get(this.receiptsKey(agentId));
190
+ if (!raw)
191
+ return [];
192
+ const list = (0, helpers_1.deserialize)(raw);
193
+ const sorted = list.sort((a, b) => b.settledAt - a.settledAt);
194
+ const offset = opts.offset ?? 0;
195
+ const limit = opts.limit ?? sorted.length;
196
+ return sorted.slice(offset, offset + limit);
197
+ }
198
+ /* ── Metrics ───────────────────────────────────────────── */
199
+ metricsKey(agentId, key) {
200
+ return (0, helpers_1.buildKey)(this.prefix, 'metrics', agentId, key);
201
+ }
202
+ async recordMetric(agentId, key, value, labels) {
203
+ const k = this.metricsKey(agentId, key);
204
+ const raw = await this.client.get(k);
205
+ const list = raw ? (0, helpers_1.deserialize)(raw) : [];
206
+ list.push({ timestamp: Date.now(), value, labels });
207
+ // Keep last 10 000 points per metric key (prevent unbounded growth)
208
+ if (list.length > 10_000)
209
+ list.splice(0, list.length - 10_000);
210
+ await this.client.set(k, (0, helpers_1.serialize)(list));
211
+ }
212
+ async queryMetrics(agentId, key, opts = {}) {
213
+ const raw = await this.client.get(this.metricsKey(agentId, key));
214
+ if (!raw)
215
+ return [];
216
+ let points = (0, helpers_1.deserialize)(raw);
217
+ if (opts.from != null)
218
+ points = points.filter(p => p.timestamp >= opts.from);
219
+ if (opts.to != null)
220
+ points = points.filter(p => p.timestamp <= opts.to);
221
+ points.sort((a, b) => b.timestamp - a.timestamp);
222
+ if (opts.limit != null)
223
+ points = points.slice(0, opts.limit);
224
+ return points;
225
+ }
226
+ /* ── PersistenceAdapter compat ─────────────────────────── */
227
+ async save(agentId, snapshot) {
228
+ return this.saveAgent(snapshot);
229
+ }
230
+ async load(agentId) {
231
+ return this.loadAgent(agentId);
232
+ }
233
+ async delete(agentId) {
234
+ await this.deleteAgent(agentId);
235
+ }
236
+ async keys() {
237
+ return this.listAgents();
238
+ }
239
+ }
240
+ exports.RedisPersistence = RedisPersistence;
241
+ //# sourceMappingURL=redis.js.map