@farukada/aws-langgraph-dynamodb-ts 0.9.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 (512) hide show
  1. package/README.md +1720 -154
  2. package/dist/backfill/backfill.d.ts +168 -0
  3. package/dist/backfill/backfill.js +393 -0
  4. package/dist/checkpointer/actions/delete-thread.d.ts +47 -6
  5. package/dist/checkpointer/actions/delete-thread.js +58 -21
  6. package/dist/checkpointer/actions/get-tuple.d.ts +29 -4
  7. package/dist/checkpointer/actions/get-tuple.js +44 -10
  8. package/dist/checkpointer/actions/list.d.ts +46 -4
  9. package/dist/checkpointer/actions/list.js +121 -66
  10. package/dist/checkpointer/actions/put-writes.d.ts +41 -9
  11. package/dist/checkpointer/actions/put-writes.js +62 -77
  12. package/dist/checkpointer/actions/put.d.ts +83 -4
  13. package/dist/checkpointer/actions/put.js +177 -25
  14. package/dist/checkpointer/internal/delta-history.d.ts +112 -0
  15. package/dist/checkpointer/internal/delta-history.js +252 -0
  16. package/dist/checkpointer/internal/listing.d.ts +149 -0
  17. package/dist/checkpointer/internal/listing.js +245 -0
  18. package/dist/checkpointer/internal/parse.d.ts +262 -0
  19. package/dist/checkpointer/internal/parse.js +372 -0
  20. package/dist/checkpointer/internal/pending-writes.d.ts +275 -0
  21. package/dist/checkpointer/internal/pending-writes.js +588 -0
  22. package/dist/checkpointer/internal/read.d.ts +130 -0
  23. package/dist/checkpointer/internal/read.js +264 -0
  24. package/dist/checkpointer/internal/rows.d.ts +571 -0
  25. package/dist/checkpointer/internal/rows.js +834 -0
  26. package/dist/checkpointer/internal/setup.d.ts +42 -19
  27. package/dist/checkpointer/internal/setup.js +65 -29
  28. package/dist/checkpointer/saver.d.ts +256 -16
  29. package/dist/checkpointer/saver.js +275 -29
  30. package/dist/checkpointer/types.d.ts +39 -39
  31. package/dist/checkpointer/types.js +10 -1
  32. package/dist/factory/factory.d.ts +134 -28
  33. package/dist/factory/factory.js +240 -21
  34. package/dist/factory/types.d.ts +76 -0
  35. package/dist/factory/types.js +10 -0
  36. package/dist/history/actions/add-messages.d.ts +31 -4
  37. package/dist/history/actions/add-messages.js +38 -58
  38. package/dist/history/actions/clear.d.ts +49 -6
  39. package/dist/history/actions/clear.js +66 -14
  40. package/dist/history/actions/get-messages.d.ts +54 -6
  41. package/dist/history/actions/get-messages.js +126 -43
  42. package/dist/history/actions/list-sessions.d.ts +52 -10
  43. package/dist/history/actions/list-sessions.js +139 -40
  44. package/dist/history/actions/reconcile-count.d.ts +42 -10
  45. package/dist/history/actions/reconcile-count.js +45 -45
  46. package/dist/history/chat-message-history.d.ts +220 -33
  47. package/dist/history/chat-message-history.js +240 -43
  48. package/dist/history/internal/append.d.ts +212 -0
  49. package/dist/history/internal/append.js +500 -0
  50. package/dist/history/internal/message-read.d.ts +84 -0
  51. package/dist/history/internal/message-read.js +204 -0
  52. package/dist/history/internal/parse.d.ts +153 -0
  53. package/dist/history/internal/parse.js +252 -0
  54. package/dist/history/internal/rows.d.ts +195 -0
  55. package/dist/history/internal/rows.js +250 -0
  56. package/dist/history/internal/session.d.ts +331 -0
  57. package/dist/history/internal/session.js +628 -0
  58. package/dist/history/internal/setup.d.ts +52 -17
  59. package/dist/history/internal/setup.js +92 -21
  60. package/dist/history/session-adapter.d.ts +102 -7
  61. package/dist/history/session-adapter.js +103 -9
  62. package/dist/history/types.d.ts +80 -29
  63. package/dist/history/types.js +10 -1
  64. package/dist/index.d.ts +42 -11
  65. package/dist/index.js +33 -12
  66. package/dist/shared/adapter.d.ts +135 -0
  67. package/dist/shared/adapter.js +143 -0
  68. package/dist/shared/clock.d.ts +51 -2
  69. package/dist/shared/clock.js +57 -2
  70. package/dist/shared/codec/codec.d.ts +288 -13
  71. package/dist/shared/codec/codec.js +416 -19
  72. package/dist/shared/codec/compression.d.ts +43 -7
  73. package/dist/shared/codec/compression.js +53 -13
  74. package/dist/shared/codec/json-serde.d.ts +76 -4
  75. package/dist/shared/codec/json-serde.js +181 -8
  76. package/dist/shared/codec/s3/client-types.d.ts +53 -0
  77. package/dist/shared/codec/s3/client-types.js +26 -0
  78. package/dist/shared/codec/s3/client.d.ts +43 -10
  79. package/dist/shared/codec/s3/client.js +82 -9
  80. package/dist/shared/codec/s3/config.d.ts +242 -11
  81. package/dist/shared/codec/s3/config.js +293 -11
  82. package/dist/shared/codec/s3/lifecycle.d.ts +164 -6
  83. package/dist/shared/codec/s3/lifecycle.js +335 -27
  84. package/dist/shared/codec/s3/offloader.d.ts +393 -18
  85. package/dist/shared/codec/s3/offloader.js +595 -37
  86. package/dist/shared/concurrency.d.ts +43 -0
  87. package/dist/shared/concurrency.js +78 -0
  88. package/dist/shared/dynamodb/abort.d.ts +47 -0
  89. package/dist/shared/dynamodb/abort.js +59 -0
  90. package/dist/shared/dynamodb/batch-write.d.ts +77 -14
  91. package/dist/shared/dynamodb/batch-write.js +146 -27
  92. package/dist/shared/dynamodb/cancellation.d.ts +121 -4
  93. package/dist/shared/dynamodb/cancellation.js +147 -3
  94. package/dist/shared/dynamodb/client.d.ts +162 -8
  95. package/dist/shared/dynamodb/client.js +153 -5
  96. package/dist/shared/dynamodb/idempotent-write.d.ts +551 -0
  97. package/dist/shared/dynamodb/idempotent-write.js +593 -0
  98. package/dist/shared/dynamodb/paginate.d.ts +105 -9
  99. package/dist/shared/dynamodb/paginate.js +175 -7
  100. package/dist/shared/dynamodb/partition-delete.d.ts +185 -14
  101. package/dist/shared/dynamodb/partition-delete.js +314 -44
  102. package/dist/shared/dynamodb/recency-index.d.ts +231 -0
  103. package/dist/shared/dynamodb/recency-index.js +377 -0
  104. package/dist/shared/dynamodb/retry.d.ts +276 -8
  105. package/dist/shared/dynamodb/retry.js +433 -23
  106. package/dist/shared/dynamodb/table-schema.d.ts +190 -0
  107. package/dist/shared/dynamodb/table-schema.js +209 -0
  108. package/dist/shared/errors/base-error.d.ts +184 -10
  109. package/dist/shared/errors/base-error.js +160 -14
  110. package/dist/shared/errors/boundary.d.ts +71 -0
  111. package/dist/shared/errors/boundary.js +143 -0
  112. package/dist/shared/errors/classify.d.ts +97 -0
  113. package/dist/shared/errors/classify.js +257 -0
  114. package/dist/shared/errors/error-code.d.ts +77 -2
  115. package/dist/shared/errors/error-code.js +83 -1
  116. package/dist/shared/errors/errors.d.ts +158 -59
  117. package/dist/shared/errors/errors.js +219 -92
  118. package/dist/shared/logging/logger.d.ts +69 -3
  119. package/dist/shared/logging/logger.js +97 -3
  120. package/dist/shared/logging/redaction.d.ts +92 -8
  121. package/dist/shared/logging/redaction.js +273 -17
  122. package/dist/shared/logging/secret-patterns.d.ts +149 -19
  123. package/dist/shared/logging/secret-patterns.js +188 -27
  124. package/dist/shared/logging/truncate.d.ts +197 -0
  125. package/dist/shared/logging/truncate.js +231 -0
  126. package/dist/shared/options.d.ts +59 -7
  127. package/dist/shared/options.js +9 -1
  128. package/dist/shared/ulid.d.ts +77 -7
  129. package/dist/shared/ulid.js +103 -8
  130. package/dist/shared/validation/collaborators.d.ts +141 -0
  131. package/dist/shared/validation/collaborators.js +188 -0
  132. package/dist/shared/validation/option-shape.d.ts +89 -0
  133. package/dist/shared/validation/option-shape.js +113 -0
  134. package/dist/shared/validation/options.d.ts +145 -0
  135. package/dist/shared/validation/options.js +328 -0
  136. package/dist/shared/validation/primitives.d.ts +288 -21
  137. package/dist/shared/validation/primitives.js +353 -50
  138. package/dist/shared/validation/ttl.d.ts +66 -10
  139. package/dist/shared/validation/ttl.js +113 -15
  140. package/dist/store/actions/list-namespaces.d.ts +76 -6
  141. package/dist/store/actions/list-namespaces.js +166 -24
  142. package/dist/store/actions/put.d.ts +33 -8
  143. package/dist/store/actions/put.js +53 -60
  144. package/dist/store/actions/reconcile-vector-index.d.ts +31 -10
  145. package/dist/store/actions/reconcile-vector-index.js +34 -15
  146. package/dist/store/actions/search.d.ts +34 -6
  147. package/dist/store/actions/search.js +56 -51
  148. package/dist/store/internal/batch-plan.d.ts +26 -0
  149. package/dist/store/internal/batch-plan.js +109 -0
  150. package/dist/store/internal/filter.d.ts +36 -3
  151. package/dist/store/internal/filter.js +66 -15
  152. package/dist/store/internal/get-item.d.ts +45 -0
  153. package/dist/store/internal/get-item.js +115 -0
  154. package/dist/store/internal/item-write.d.ts +230 -0
  155. package/dist/store/internal/item-write.js +463 -0
  156. package/dist/store/internal/parse.d.ts +225 -0
  157. package/dist/store/internal/parse.js +350 -0
  158. package/dist/store/internal/rows.d.ts +355 -0
  159. package/dist/store/internal/rows.js +447 -0
  160. package/dist/store/internal/semantic-search.d.ts +161 -6
  161. package/dist/store/internal/semantic-search.js +360 -18
  162. package/dist/store/internal/setup.d.ts +77 -20
  163. package/dist/store/internal/setup.js +178 -47
  164. package/dist/store/internal/table-search.d.ts +100 -0
  165. package/dist/store/internal/table-search.js +213 -0
  166. package/dist/store/internal/vector-index.d.ts +247 -0
  167. package/dist/store/internal/vector-index.js +546 -0
  168. package/dist/store/store.d.ts +270 -17
  169. package/dist/store/store.js +329 -38
  170. package/dist/store/types.d.ts +76 -26
  171. package/dist/store/types.js +13 -1
  172. package/dist/store/vector-backend.d.ts +64 -4
  173. package/dist/store/vector-backend.js +15 -1
  174. package/package.json +58 -36
  175. package/dist/checkpointer/actions/delete-thread.d.ts.map +0 -1
  176. package/dist/checkpointer/actions/delete-thread.js.map +0 -1
  177. package/dist/checkpointer/actions/get-tuple.d.ts.map +0 -1
  178. package/dist/checkpointer/actions/get-tuple.js.map +0 -1
  179. package/dist/checkpointer/actions/list.d.ts.map +0 -1
  180. package/dist/checkpointer/actions/list.js.map +0 -1
  181. package/dist/checkpointer/actions/put-writes.d.ts.map +0 -1
  182. package/dist/checkpointer/actions/put-writes.js.map +0 -1
  183. package/dist/checkpointer/actions/put.d.ts.map +0 -1
  184. package/dist/checkpointer/actions/put.js.map +0 -1
  185. package/dist/checkpointer/internal/assemble.d.ts +0 -10
  186. package/dist/checkpointer/internal/assemble.d.ts.map +0 -1
  187. package/dist/checkpointer/internal/assemble.js +0 -37
  188. package/dist/checkpointer/internal/assemble.js.map +0 -1
  189. package/dist/checkpointer/internal/configurable.d.ts +0 -13
  190. package/dist/checkpointer/internal/configurable.d.ts.map +0 -1
  191. package/dist/checkpointer/internal/configurable.js +0 -23
  192. package/dist/checkpointer/internal/configurable.js.map +0 -1
  193. package/dist/checkpointer/internal/fetch.d.ts +0 -10
  194. package/dist/checkpointer/internal/fetch.d.ts.map +0 -1
  195. package/dist/checkpointer/internal/fetch.js +0 -46
  196. package/dist/checkpointer/internal/fetch.js.map +0 -1
  197. package/dist/checkpointer/internal/filter-match.d.ts +0 -12
  198. package/dist/checkpointer/internal/filter-match.d.ts.map +0 -1
  199. package/dist/checkpointer/internal/filter-match.js +0 -14
  200. package/dist/checkpointer/internal/filter-match.js.map +0 -1
  201. package/dist/checkpointer/internal/item-reader.d.ts +0 -55
  202. package/dist/checkpointer/internal/item-reader.d.ts.map +0 -1
  203. package/dist/checkpointer/internal/item-reader.js +0 -88
  204. package/dist/checkpointer/internal/item-reader.js.map +0 -1
  205. package/dist/checkpointer/internal/item-writer.d.ts +0 -26
  206. package/dist/checkpointer/internal/item-writer.d.ts.map +0 -1
  207. package/dist/checkpointer/internal/item-writer.js +0 -92
  208. package/dist/checkpointer/internal/item-writer.js.map +0 -1
  209. package/dist/checkpointer/internal/keys.d.ts +0 -31
  210. package/dist/checkpointer/internal/keys.d.ts.map +0 -1
  211. package/dist/checkpointer/internal/keys.js +0 -87
  212. package/dist/checkpointer/internal/keys.js.map +0 -1
  213. package/dist/checkpointer/internal/query.d.ts +0 -20
  214. package/dist/checkpointer/internal/query.d.ts.map +0 -1
  215. package/dist/checkpointer/internal/query.js +0 -36
  216. package/dist/checkpointer/internal/query.js.map +0 -1
  217. package/dist/checkpointer/internal/setup.d.ts.map +0 -1
  218. package/dist/checkpointer/internal/setup.js.map +0 -1
  219. package/dist/checkpointer/internal/special-write-cas.d.ts +0 -30
  220. package/dist/checkpointer/internal/special-write-cas.d.ts.map +0 -1
  221. package/dist/checkpointer/internal/special-write-cas.js +0 -104
  222. package/dist/checkpointer/internal/special-write-cas.js.map +0 -1
  223. package/dist/checkpointer/internal/special-write-cleanup.d.ts +0 -24
  224. package/dist/checkpointer/internal/special-write-cleanup.d.ts.map +0 -1
  225. package/dist/checkpointer/internal/special-write-cleanup.js +0 -47
  226. package/dist/checkpointer/internal/special-write-cleanup.js.map +0 -1
  227. package/dist/checkpointer/internal/special-write-verify.d.ts +0 -54
  228. package/dist/checkpointer/internal/special-write-verify.d.ts.map +0 -1
  229. package/dist/checkpointer/internal/special-write-verify.js +0 -65
  230. package/dist/checkpointer/internal/special-write-verify.js.map +0 -1
  231. package/dist/checkpointer/internal/validation.d.ts +0 -13
  232. package/dist/checkpointer/internal/validation.d.ts.map +0 -1
  233. package/dist/checkpointer/internal/validation.js +0 -30
  234. package/dist/checkpointer/internal/validation.js.map +0 -1
  235. package/dist/checkpointer/internal/write-guard.d.ts +0 -13
  236. package/dist/checkpointer/internal/write-guard.d.ts.map +0 -1
  237. package/dist/checkpointer/internal/write-guard.js +0 -39
  238. package/dist/checkpointer/internal/write-guard.js.map +0 -1
  239. package/dist/checkpointer/internal/write-index.d.ts +0 -37
  240. package/dist/checkpointer/internal/write-index.d.ts.map +0 -1
  241. package/dist/checkpointer/internal/write-index.js +0 -42
  242. package/dist/checkpointer/internal/write-index.js.map +0 -1
  243. package/dist/checkpointer/saver.d.ts.map +0 -1
  244. package/dist/checkpointer/saver.js.map +0 -1
  245. package/dist/checkpointer/types.d.ts.map +0 -1
  246. package/dist/checkpointer/types.js.map +0 -1
  247. package/dist/factory/factory.d.ts.map +0 -1
  248. package/dist/factory/factory.js.map +0 -1
  249. package/dist/history/actions/add-messages.d.ts.map +0 -1
  250. package/dist/history/actions/add-messages.js.map +0 -1
  251. package/dist/history/actions/clear.d.ts.map +0 -1
  252. package/dist/history/actions/clear.js.map +0 -1
  253. package/dist/history/actions/get-messages.d.ts.map +0 -1
  254. package/dist/history/actions/get-messages.js.map +0 -1
  255. package/dist/history/actions/list-sessions.d.ts.map +0 -1
  256. package/dist/history/actions/list-sessions.js.map +0 -1
  257. package/dist/history/actions/reconcile-count.d.ts.map +0 -1
  258. package/dist/history/actions/reconcile-count.js.map +0 -1
  259. package/dist/history/chat-message-history.d.ts.map +0 -1
  260. package/dist/history/chat-message-history.js.map +0 -1
  261. package/dist/history/internal/append-saga.d.ts +0 -20
  262. package/dist/history/internal/append-saga.d.ts.map +0 -1
  263. package/dist/history/internal/append-saga.js +0 -35
  264. package/dist/history/internal/append-saga.js.map +0 -1
  265. package/dist/history/internal/compensation.d.ts +0 -21
  266. package/dist/history/internal/compensation.d.ts.map +0 -1
  267. package/dist/history/internal/compensation.js +0 -84
  268. package/dist/history/internal/compensation.js.map +0 -1
  269. package/dist/history/internal/item-mapper.d.ts +0 -12
  270. package/dist/history/internal/item-mapper.d.ts.map +0 -1
  271. package/dist/history/internal/item-mapper.js +0 -33
  272. package/dist/history/internal/item-mapper.js.map +0 -1
  273. package/dist/history/internal/keys.d.ts +0 -17
  274. package/dist/history/internal/keys.d.ts.map +0 -1
  275. package/dist/history/internal/keys.js +0 -49
  276. package/dist/history/internal/keys.js.map +0 -1
  277. package/dist/history/internal/message-chunker.d.ts +0 -14
  278. package/dist/history/internal/message-chunker.d.ts.map +0 -1
  279. package/dist/history/internal/message-chunker.js +0 -68
  280. package/dist/history/internal/message-chunker.js.map +0 -1
  281. package/dist/history/internal/message-transaction.d.ts +0 -26
  282. package/dist/history/internal/message-transaction.d.ts.map +0 -1
  283. package/dist/history/internal/message-transaction.js +0 -60
  284. package/dist/history/internal/message-transaction.js.map +0 -1
  285. package/dist/history/internal/query.d.ts +0 -10
  286. package/dist/history/internal/query.d.ts.map +0 -1
  287. package/dist/history/internal/query.js +0 -31
  288. package/dist/history/internal/query.js.map +0 -1
  289. package/dist/history/internal/session-count.d.ts +0 -41
  290. package/dist/history/internal/session-count.d.ts.map +0 -1
  291. package/dist/history/internal/session-count.js +0 -109
  292. package/dist/history/internal/session-count.js.map +0 -1
  293. package/dist/history/internal/session-title.d.ts +0 -20
  294. package/dist/history/internal/session-title.d.ts.map +0 -1
  295. package/dist/history/internal/session-title.js +0 -44
  296. package/dist/history/internal/session-title.js.map +0 -1
  297. package/dist/history/internal/session-update.d.ts +0 -28
  298. package/dist/history/internal/session-update.d.ts.map +0 -1
  299. package/dist/history/internal/session-update.js +0 -70
  300. package/dist/history/internal/session-update.js.map +0 -1
  301. package/dist/history/internal/setup.d.ts.map +0 -1
  302. package/dist/history/internal/setup.js.map +0 -1
  303. package/dist/history/internal/title-generator.d.ts +0 -13
  304. package/dist/history/internal/title-generator.d.ts.map +0 -1
  305. package/dist/history/internal/title-generator.js +0 -25
  306. package/dist/history/internal/title-generator.js.map +0 -1
  307. package/dist/history/internal/ttl-anchor.d.ts +0 -25
  308. package/dist/history/internal/ttl-anchor.d.ts.map +0 -1
  309. package/dist/history/internal/ttl-anchor.js +0 -38
  310. package/dist/history/internal/ttl-anchor.js.map +0 -1
  311. package/dist/history/internal/validation.d.ts +0 -9
  312. package/dist/history/internal/validation.d.ts.map +0 -1
  313. package/dist/history/internal/validation.js +0 -16
  314. package/dist/history/internal/validation.js.map +0 -1
  315. package/dist/history/session-adapter.d.ts.map +0 -1
  316. package/dist/history/session-adapter.js.map +0 -1
  317. package/dist/history/types.d.ts.map +0 -1
  318. package/dist/history/types.js.map +0 -1
  319. package/dist/index.d.ts.map +0 -1
  320. package/dist/index.js.map +0 -1
  321. package/dist/shared/clock.d.ts.map +0 -1
  322. package/dist/shared/clock.js.map +0 -1
  323. package/dist/shared/codec/codec.d.ts.map +0 -1
  324. package/dist/shared/codec/codec.js.map +0 -1
  325. package/dist/shared/codec/compression.d.ts.map +0 -1
  326. package/dist/shared/codec/compression.js.map +0 -1
  327. package/dist/shared/codec/descriptor-keys.d.ts +0 -4
  328. package/dist/shared/codec/descriptor-keys.d.ts.map +0 -1
  329. package/dist/shared/codec/descriptor-keys.js +0 -14
  330. package/dist/shared/codec/descriptor-keys.js.map +0 -1
  331. package/dist/shared/codec/json-serde.d.ts.map +0 -1
  332. package/dist/shared/codec/json-serde.js.map +0 -1
  333. package/dist/shared/codec/s3/client.d.ts.map +0 -1
  334. package/dist/shared/codec/s3/client.js.map +0 -1
  335. package/dist/shared/codec/s3/config.d.ts.map +0 -1
  336. package/dist/shared/codec/s3/config.js.map +0 -1
  337. package/dist/shared/codec/s3/delete.d.ts +0 -8
  338. package/dist/shared/codec/s3/delete.d.ts.map +0 -1
  339. package/dist/shared/codec/s3/delete.js +0 -29
  340. package/dist/shared/codec/s3/delete.js.map +0 -1
  341. package/dist/shared/codec/s3/lifecycle.d.ts.map +0 -1
  342. package/dist/shared/codec/s3/lifecycle.js.map +0 -1
  343. package/dist/shared/codec/s3/offloader.d.ts.map +0 -1
  344. package/dist/shared/codec/s3/offloader.js.map +0 -1
  345. package/dist/shared/codec/s3/orphans.d.ts +0 -18
  346. package/dist/shared/codec/s3/orphans.d.ts.map +0 -1
  347. package/dist/shared/codec/s3/orphans.js +0 -58
  348. package/dist/shared/codec/s3/orphans.js.map +0 -1
  349. package/dist/shared/codec/s3/read-write.d.ts +0 -14
  350. package/dist/shared/codec/s3/read-write.d.ts.map +0 -1
  351. package/dist/shared/codec/s3/read-write.js +0 -43
  352. package/dist/shared/codec/s3/read-write.js.map +0 -1
  353. package/dist/shared/codec/s3/retry.d.ts +0 -5
  354. package/dist/shared/codec/s3/retry.d.ts.map +0 -1
  355. package/dist/shared/codec/s3/retry.js +0 -25
  356. package/dist/shared/codec/s3/retry.js.map +0 -1
  357. package/dist/shared/constants.d.ts +0 -64
  358. package/dist/shared/constants.d.ts.map +0 -1
  359. package/dist/shared/constants.js +0 -67
  360. package/dist/shared/constants.js.map +0 -1
  361. package/dist/shared/dynamodb/backoff.d.ts +0 -15
  362. package/dist/shared/dynamodb/backoff.d.ts.map +0 -1
  363. package/dist/shared/dynamodb/backoff.js +0 -48
  364. package/dist/shared/dynamodb/backoff.js.map +0 -1
  365. package/dist/shared/dynamodb/batch-write.d.ts.map +0 -1
  366. package/dist/shared/dynamodb/batch-write.js.map +0 -1
  367. package/dist/shared/dynamodb/cancellation.d.ts.map +0 -1
  368. package/dist/shared/dynamodb/cancellation.js.map +0 -1
  369. package/dist/shared/dynamodb/client.d.ts.map +0 -1
  370. package/dist/shared/dynamodb/client.js.map +0 -1
  371. package/dist/shared/dynamodb/conditional-put.d.ts +0 -51
  372. package/dist/shared/dynamodb/conditional-put.d.ts.map +0 -1
  373. package/dist/shared/dynamodb/conditional-put.js +0 -59
  374. package/dist/shared/dynamodb/conditional-put.js.map +0 -1
  375. package/dist/shared/dynamodb/drain-unprocessed.d.ts +0 -19
  376. package/dist/shared/dynamodb/drain-unprocessed.d.ts.map +0 -1
  377. package/dist/shared/dynamodb/drain-unprocessed.js +0 -44
  378. package/dist/shared/dynamodb/drain-unprocessed.js.map +0 -1
  379. package/dist/shared/dynamodb/paginate-core.d.ts +0 -22
  380. package/dist/shared/dynamodb/paginate-core.d.ts.map +0 -1
  381. package/dist/shared/dynamodb/paginate-core.js +0 -52
  382. package/dist/shared/dynamodb/paginate-core.js.map +0 -1
  383. package/dist/shared/dynamodb/paginate.d.ts.map +0 -1
  384. package/dist/shared/dynamodb/paginate.js.map +0 -1
  385. package/dist/shared/dynamodb/partition-delete.d.ts.map +0 -1
  386. package/dist/shared/dynamodb/partition-delete.js.map +0 -1
  387. package/dist/shared/dynamodb/retry-classifier.d.ts +0 -9
  388. package/dist/shared/dynamodb/retry-classifier.d.ts.map +0 -1
  389. package/dist/shared/dynamodb/retry-classifier.js +0 -87
  390. package/dist/shared/dynamodb/retry-classifier.js.map +0 -1
  391. package/dist/shared/dynamodb/retry.d.ts.map +0 -1
  392. package/dist/shared/dynamodb/retry.js.map +0 -1
  393. package/dist/shared/dynamodb/scan.d.ts +0 -15
  394. package/dist/shared/dynamodb/scan.d.ts.map +0 -1
  395. package/dist/shared/dynamodb/scan.js +0 -20
  396. package/dist/shared/dynamodb/scan.js.map +0 -1
  397. package/dist/shared/dynamodb/types.d.ts +0 -24
  398. package/dist/shared/dynamodb/types.d.ts.map +0 -1
  399. package/dist/shared/dynamodb/types.js +0 -3
  400. package/dist/shared/dynamodb/types.js.map +0 -1
  401. package/dist/shared/errors/base-error.d.ts.map +0 -1
  402. package/dist/shared/errors/base-error.js.map +0 -1
  403. package/dist/shared/errors/error-code.d.ts.map +0 -1
  404. package/dist/shared/errors/error-code.js.map +0 -1
  405. package/dist/shared/errors/errors.d.ts.map +0 -1
  406. package/dist/shared/errors/errors.js.map +0 -1
  407. package/dist/shared/errors/wrap-error.d.ts +0 -16
  408. package/dist/shared/errors/wrap-error.d.ts.map +0 -1
  409. package/dist/shared/errors/wrap-error.js +0 -30
  410. package/dist/shared/errors/wrap-error.js.map +0 -1
  411. package/dist/shared/logging/logger.d.ts.map +0 -1
  412. package/dist/shared/logging/logger.js.map +0 -1
  413. package/dist/shared/logging/redaction-walk.d.ts +0 -23
  414. package/dist/shared/logging/redaction-walk.d.ts.map +0 -1
  415. package/dist/shared/logging/redaction-walk.js +0 -92
  416. package/dist/shared/logging/redaction-walk.js.map +0 -1
  417. package/dist/shared/logging/redaction.d.ts.map +0 -1
  418. package/dist/shared/logging/redaction.js.map +0 -1
  419. package/dist/shared/logging/secret-patterns.d.ts.map +0 -1
  420. package/dist/shared/logging/secret-patterns.js.map +0 -1
  421. package/dist/shared/options.d.ts.map +0 -1
  422. package/dist/shared/options.js.map +0 -1
  423. package/dist/shared/ulid.d.ts.map +0 -1
  424. package/dist/shared/ulid.js.map +0 -1
  425. package/dist/shared/validation/primitives.d.ts.map +0 -1
  426. package/dist/shared/validation/primitives.js.map +0 -1
  427. package/dist/shared/validation/ttl.d.ts.map +0 -1
  428. package/dist/shared/validation/ttl.js.map +0 -1
  429. package/dist/store/actions/get.d.ts +0 -5
  430. package/dist/store/actions/get.d.ts.map +0 -1
  431. package/dist/store/actions/get.js +0 -35
  432. package/dist/store/actions/get.js.map +0 -1
  433. package/dist/store/actions/list-namespaces.d.ts.map +0 -1
  434. package/dist/store/actions/list-namespaces.js.map +0 -1
  435. package/dist/store/actions/put.d.ts.map +0 -1
  436. package/dist/store/actions/put.js.map +0 -1
  437. package/dist/store/actions/reconcile-vector-index.d.ts.map +0 -1
  438. package/dist/store/actions/reconcile-vector-index.js.map +0 -1
  439. package/dist/store/actions/search.d.ts.map +0 -1
  440. package/dist/store/actions/search.js.map +0 -1
  441. package/dist/store/internal/backend-search.d.ts +0 -5
  442. package/dist/store/internal/backend-search.d.ts.map +0 -1
  443. package/dist/store/internal/backend-search.js +0 -68
  444. package/dist/store/internal/backend-search.js.map +0 -1
  445. package/dist/store/internal/filter.d.ts.map +0 -1
  446. package/dist/store/internal/filter.js.map +0 -1
  447. package/dist/store/internal/index-reconcile.d.ts +0 -22
  448. package/dist/store/internal/index-reconcile.d.ts.map +0 -1
  449. package/dist/store/internal/index-reconcile.js +0 -105
  450. package/dist/store/internal/index-reconcile.js.map +0 -1
  451. package/dist/store/internal/index-sync.d.ts +0 -11
  452. package/dist/store/internal/index-sync.d.ts.map +0 -1
  453. package/dist/store/internal/index-sync.js +0 -26
  454. package/dist/store/internal/index-sync.js.map +0 -1
  455. package/dist/store/internal/item-mapper.d.ts +0 -25
  456. package/dist/store/internal/item-mapper.d.ts.map +0 -1
  457. package/dist/store/internal/item-mapper.js +0 -53
  458. package/dist/store/internal/item-mapper.js.map +0 -1
  459. package/dist/store/internal/keys.d.ts +0 -18
  460. package/dist/store/internal/keys.d.ts.map +0 -1
  461. package/dist/store/internal/keys.js +0 -42
  462. package/dist/store/internal/keys.js.map +0 -1
  463. package/dist/store/internal/namespace-match.d.ts +0 -12
  464. package/dist/store/internal/namespace-match.d.ts.map +0 -1
  465. package/dist/store/internal/namespace-match.js +0 -41
  466. package/dist/store/internal/namespace-match.js.map +0 -1
  467. package/dist/store/internal/overwrite-swap.d.ts +0 -33
  468. package/dist/store/internal/overwrite-swap.d.ts.map +0 -1
  469. package/dist/store/internal/overwrite-swap.js +0 -62
  470. package/dist/store/internal/overwrite-swap.js.map +0 -1
  471. package/dist/store/internal/persist.d.ts +0 -27
  472. package/dist/store/internal/persist.d.ts.map +0 -1
  473. package/dist/store/internal/persist.js +0 -59
  474. package/dist/store/internal/persist.js.map +0 -1
  475. package/dist/store/internal/query.d.ts +0 -6
  476. package/dist/store/internal/query.d.ts.map +0 -1
  477. package/dist/store/internal/query.js +0 -32
  478. package/dist/store/internal/query.js.map +0 -1
  479. package/dist/store/internal/ranker.d.ts +0 -13
  480. package/dist/store/internal/ranker.d.ts.map +0 -1
  481. package/dist/store/internal/ranker.js +0 -31
  482. package/dist/store/internal/ranker.js.map +0 -1
  483. package/dist/store/internal/read-existing.d.ts +0 -19
  484. package/dist/store/internal/read-existing.d.ts.map +0 -1
  485. package/dist/store/internal/read-existing.js +0 -29
  486. package/dist/store/internal/read-existing.js.map +0 -1
  487. package/dist/store/internal/score-direction.d.ts +0 -32
  488. package/dist/store/internal/score-direction.d.ts.map +0 -1
  489. package/dist/store/internal/score-direction.js +0 -39
  490. package/dist/store/internal/score-direction.js.map +0 -1
  491. package/dist/store/internal/search-filter.d.ts +0 -4
  492. package/dist/store/internal/search-filter.d.ts.map +0 -1
  493. package/dist/store/internal/search-filter.js +0 -11
  494. package/dist/store/internal/search-filter.js.map +0 -1
  495. package/dist/store/internal/semantic-search.d.ts.map +0 -1
  496. package/dist/store/internal/semantic-search.js.map +0 -1
  497. package/dist/store/internal/setup.d.ts.map +0 -1
  498. package/dist/store/internal/setup.js.map +0 -1
  499. package/dist/store/internal/validation.d.ts +0 -13
  500. package/dist/store/internal/validation.d.ts.map +0 -1
  501. package/dist/store/internal/validation.js +0 -35
  502. package/dist/store/internal/validation.js.map +0 -1
  503. package/dist/store/internal/write-verify.d.ts +0 -37
  504. package/dist/store/internal/write-verify.d.ts.map +0 -1
  505. package/dist/store/internal/write-verify.js +0 -68
  506. package/dist/store/internal/write-verify.js.map +0 -1
  507. package/dist/store/store.d.ts.map +0 -1
  508. package/dist/store/store.js.map +0 -1
  509. package/dist/store/types.d.ts.map +0 -1
  510. package/dist/store/types.js.map +0 -1
  511. package/dist/store/vector-backend.d.ts.map +0 -1
  512. package/dist/store/vector-backend.js.map +0 -1
@@ -1,31 +1,83 @@
1
1
  "use strict";
2
+ /**
3
+ * Hides which rows a clear may delete.
4
+ *
5
+ * A clear removes only what the partition read observed and this adapter
6
+ * wrote, each row pinned to the write id it was read with, and reaches a
7
+ * message's offloaded payload through the attribute that holds it. A caller
8
+ * asks for a session to go and never decides that a foreign row, or one a
9
+ * concurrent append rewrote, is left in place and reported rather than
10
+ * deleted; the paging, the per-row deletes and the S3 cleanup are the shared
11
+ * partition delete's.
12
+ */
2
13
  Object.defineProperty(exports, "__esModule", { value: true });
3
14
  exports.clearSession = clearSession;
15
+ const idempotent_write_1 = require("../../shared/dynamodb/idempotent-write");
4
16
  const partition_delete_1 = require("../../shared/dynamodb/partition-delete");
5
- const keys_1 = require("../internal/keys");
6
- const query_1 = require("../internal/query");
7
- const validation_1 = require("../internal/validation");
8
- /** The offloaded payload a chat-history row can reference. */
17
+ const retry_1 = require("../../shared/dynamodb/retry");
18
+ const parse_1 = require("../internal/parse");
19
+ const rows_1 = require("../internal/rows");
20
+ /**
21
+ * The offloaded payload a chat-history row references, named by the attribute
22
+ * holding it, because a message row is pinned through a document path over that
23
+ * name. The session row carries no payload and is pinned top-level instead, and
24
+ * a row holding `null` there carries none either — `namedDescriptor` decides.
25
+ */
9
26
  function descriptorsOf(row) {
10
- return [row.message];
27
+ const entry = (0, partition_delete_1.namedDescriptor)(row, 'message');
28
+ return entry === undefined ? [] : [entry];
11
29
  }
12
30
  /**
13
- * Delete a whole session: every message item plus the metadata item, best-effort
14
- * deleting any offloaded S3 objects. Rows this adapter does not own are left in
15
- * place and logged, so a shared-table partition holding a foreign row is never
16
- * collaterally wiped.
31
+ * Delete exactly the message rows and the session row of one session that the
32
+ * partition read observed.
33
+ *
34
+ * Accepts: `sessionId` — validated. `options.signal` — aborts between pages.
35
+ *
36
+ * Returns: nothing. Clearing a session that does not exist is not an error;
37
+ * there is simply nothing in the partition.
38
+ *
39
+ * Throws: `VALIDATION` naming `sessionId`; `BATCH_WRITE_INCOMPLETE`
40
+ * when a row's delete fails, carrying what did succeed; `ABORTED` when the
41
+ * signal fires, whether between pages or during a row's delete — a cancel is
42
+ * reported as a cancel and never as an incomplete delete, and no further row
43
+ * is issued after it. A refused
44
+ * row raises nothing and is not one of those failures: the pin turned it away
45
+ * because an append landed after the read, and deleting the session row then
46
+ * would remove the `messageCount`, the `updatedAt` and the recency-index entry
47
+ * of a session that is still alive — leaving it is the safe answer. The error's
48
+ * two counts are **rows**, not batches — rows deleted and rows attempted,
49
+ * summed across every flush of the pass, with `details.succeededCount` repeating
50
+ * the first and `details.failedChunks` holding each failing row's own error — and its
51
+ * message says so, because a pass that sends one request per row is not a batch
52
+ * that did not drain. Refused rows are in neither count; each is reported at
53
+ * `warn` with its sort key and counted as skipped. The remedy is to re-run once
54
+ * the session is quiescent, and `reconcileMessageCount` repairs the count the
55
+ * surviving session row is left over-counting in the meantime.
56
+ *
57
+ * Guarantees: a row this adapter did not write is left in place and logged, so
58
+ * a shared-table partition is never collaterally wiped. Offloaded objects are
59
+ * deleted best-effort after their rows, and only objects under this session's
60
+ * own path. A row rewritten after the read is left in place and reported: an
61
+ * append landing during the call moves the session row's own write id, so that
62
+ * row survives while the messages the read saw are still deleted, and its
63
+ * `messageCount` then over-counts until `reconcileMessageCount` repairs it —
64
+ * which is the right outcome, the session being alive. One pass over a
65
+ * quiescent session: a message appended while this runs may survive it.
17
66
  */
18
- async function clearSession(context, sessionId) {
19
- (0, validation_1.validateSessionId)(sessionId);
67
+ async function clearSession(context, sessionId, options = {}) {
68
+ const session = (0, parse_1.parseSessionId)(sessionId);
20
69
  await (0, partition_delete_1.deletePartitionRows)({
21
70
  client: context.client,
22
71
  tableName: context.tableName,
23
- params: (0, query_1.sessionItemsQuery)(context.tableName, sessionId, { consistent: true }),
72
+ params: (0, rows_1.sessionRowsQuery)(context.tableName, session, { consistent: true }),
24
73
  logger: context.logger,
74
+ retry: (0, retry_1.retryFor)(context, options.signal),
75
+ signal: options.signal,
25
76
  offloader: context.offloader,
26
77
  operation: 'history.clear',
27
- ownsSortKey: keys_1.isHistorySortKey,
78
+ ownsSortKey: rows_1.isHistorySortKey,
28
79
  descriptorsOf,
80
+ idAttribute: idempotent_write_1.WRITE_ID_ATTRIBUTE,
81
+ scope: [session],
29
82
  });
30
83
  }
31
- //# sourceMappingURL=clear.js.map
@@ -1,10 +1,58 @@
1
+ /**
2
+ * Hides which decode failures cost one message and which fail the read.
3
+ *
4
+ * A stored message is fetched, deserialized and rebuilt in three stages, and
5
+ * the stage a failure comes from decides its fate: only a loss no reader could
6
+ * ever recover is confined to that message and handed to `onCorruptMessage`
7
+ * (record 12); a transport fault, an out-of-scope key, a newer payload or a
8
+ * serializer's refusal fails the read under either policy. A caller gets a
9
+ * conversation that is whole or, under `'skip'`, missing a lost turn
10
+ * reported at `error` — never one silently truncated without a trace —
11
+ * however many downloads run at once.
12
+ */
1
13
  import { type BaseMessage } from '@langchain/core/messages';
14
+ import type { CancelOptions } from '../../shared/options';
2
15
  import type { HistoryContext } from '../internal/setup';
16
+ import type { MessageWindow } from '../types';
3
17
  /**
4
- * Return a session's messages in chronological order. Items past their TTL are
5
- * filtered out on read (DynamoDB's background TTL sweep can lag by up to 48h),
6
- * so the returned history is never stale. An item that cannot be decoded is
7
- * handled per `onCorruptMessage` (see {@link decodeOrSkip}).
18
+ * Return a session's messages in chronological order — the whole session, or
19
+ * the window `options` selects: `limit` keeps only the newest `limit`
20
+ * messages, `before` only those appended before that instant (see
21
+ * {@link readWindow}). Items past their TTL are filtered out on read
22
+ * (DynamoDB's background TTL sweep can lag by up to 48h), so the returned
23
+ * history is never stale. A corrupt item — see
24
+ * {@link decodeMessage} for exactly what counts — is handled per
25
+ * `onCorruptMessage`: `'throw'` fails the read with the underlying error;
26
+ * `'skip'` (the default) reports it at `error` with its sort key and returns
27
+ * the rest. Every other failure propagates regardless of the policy.
28
+ *
29
+ * Accepts: `options.limit` — the newest N, at least 1; absent asks for the
30
+ * whole session, and `0` is refused rather than read as an empty conversation
31
+ * (see {@link parseMessageWindow}).
32
+ * `options.before` — only messages appended before that instant.
33
+ * `options.signal` — aborts the reads.
34
+ *
35
+ * Returns: the messages in chronological order, oldest first. A session that
36
+ * does not exist and one whose messages have all expired both return nothing:
37
+ * a conversation nobody can read is a conversation that is not there.
38
+ *
39
+ * Throws: `VALIDATION` naming `sessionId`, `limit`, `before`, `signal`, or
40
+ * `options.<key>` for a key this package does not read;
41
+ * `FORMAT_UNSUPPORTED` for a row, or a payload, a newer version wrote — the
42
+ * payload half whatever the policy, because a newer reader reads it and
43
+ * dropping it would lose a turn a rollback could still serve; the decode error
44
+ * of a corrupt row under `onCorruptMessage: 'throw'`; `VALIDATION` naming
45
+ * `message` for a row in this session's message key space that this adapter
46
+ * did not write, naming
47
+ * `s3Key` for a row addressing an object outside the session's own path, and
48
+ * naming `serde` for a row whose payload the serializer refuses to
49
+ * reconstruct, all three whatever the policy; any infrastructure failure — a
50
+ * throttle, a permission, a transport error — whatever the policy, because
51
+ * dropping a message for one of those would hand back a silently truncated
52
+ * conversation that the chain then re-persists as the truth.
53
+ *
54
+ * Guarantees: strongly consistent, so the turn just appended is visible.
55
+ * Offloaded messages download several at a time, and the corruption policy is
56
+ * applied in message order however they finish.
8
57
  */
9
- export declare function getMessages(context: HistoryContext, sessionId: string): Promise<BaseMessage[]>;
10
- //# sourceMappingURL=get-messages.d.ts.map
58
+ export declare function getMessages(context: HistoryContext, sessionId: string, options?: MessageWindow & CancelOptions): Promise<BaseMessage[]>;
@@ -1,58 +1,141 @@
1
1
  "use strict";
2
+ /**
3
+ * Hides which decode failures cost one message and which fail the read.
4
+ *
5
+ * A stored message is fetched, deserialized and rebuilt in three stages, and
6
+ * the stage a failure comes from decides its fate: only a loss no reader could
7
+ * ever recover is confined to that message and handed to `onCorruptMessage`
8
+ * (record 12); a transport fault, an out-of-scope key, a newer payload or a
9
+ * serializer's refusal fails the read under either policy. A caller gets a
10
+ * conversation that is whole or, under `'skip'`, missing a lost turn
11
+ * reported at `error` — never one silently truncated without a trace —
12
+ * however many downloads run at once.
13
+ */
2
14
  Object.defineProperty(exports, "__esModule", { value: true });
3
15
  exports.getMessages = getMessages;
4
16
  const messages_1 = require("@langchain/core/messages");
5
- const paginate_1 = require("../../shared/dynamodb/paginate");
6
- const item_mapper_1 = require("../internal/item-mapper");
7
- const query_1 = require("../internal/query");
8
- const validation_1 = require("../internal/validation");
9
- function isExpired(item, nowSeconds) {
10
- return item.ttl !== undefined && item.ttl <= nowSeconds;
17
+ const codec_1 = require("../../shared/codec/codec");
18
+ const concurrency_1 = require("../../shared/concurrency");
19
+ const base_error_1 = require("../../shared/errors/base-error");
20
+ const truncate_1 = require("../../shared/logging/truncate");
21
+ const message_read_1 = require("../internal/message-read");
22
+ const parse_1 = require("../internal/parse");
23
+ /**
24
+ * This message's own loss, or the whole read's failure. Only what no reader
25
+ * could ever recover is confined to one message; everything else would hand
26
+ * the caller a silently truncated conversation that
27
+ * `RunnableWithMessageHistory` then re-persists as the truth.
28
+ */
29
+ function corruptOrRethrow(error) {
30
+ if ((0, codec_1.isPermanentPayloadLoss)(error))
31
+ return { kind: 'corrupt', error };
32
+ throw error;
11
33
  }
12
34
  /**
13
- * Decode one item, honouring the configured corrupt-message policy. Under the
14
- * default `'skip'` an undecodable item is reported and dropped rather than
15
- * taking the whole session down with it: one bad row used to throw out of
16
- * `getMessages` entirely, making every other message in the session
17
- * permanently unreadable with no API to remove just the bad one.
35
+ * Decode one item in three stages so failures are classified by what caused
36
+ * them. Fetching the bytes (an S3 download, decompression) is infrastructure:
37
+ * a transport, throttling or permission failure there is rethrown. Only a
38
+ * *permanent* loss at that stage — the object is gone, or the decompression
39
+ * guard tripped — is corruption; a row whose `s3Key` lies outside the session's
40
+ * own path is a configuration or tenancy fault, and a payload whose
41
+ * `schemaVersion` is newer than this release reads is a turn a newer reader
42
+ * still serves, so both are rethrown like any other infrastructure failure (see
43
+ * `assertKeyInScope` and `assertReadableDescriptor`).
44
+ *
45
+ * Deserializing is classified the same way, through the same predicate: bytes
46
+ * that are no longer the form the row declares are this message's own loss, but
47
+ * a serde that refuses to reconstruct what intact bytes *name* — the branded
48
+ * refusal {@link loadPayloadValue} raises for a stored `lc` record naming a
49
+ * class outside its allow-list — is a misconfigured serde or a planted row, and
50
+ * is reported for the same reason the out-of-scope key is. Bytes reached this
51
+ * stage bare before it existed, so a refusal of that kind was skipped here
52
+ * while the store and the saver raised on the identical row.
53
+ *
54
+ * Rebuilding the message from what the serde returned is pure data handling, so
55
+ * any failure there — a type LangChain cannot rebuild, such as a
56
+ * `RemoveMessage` — is corruption confined to that one message.
18
57
  */
19
- async function decodeOrSkip(context, sessionId, item) {
58
+ async function decodeMessage(context, item, sessionId, signal) {
59
+ const deps = (0, codec_1.codecDepsOf)(context, signal);
60
+ let bytes;
20
61
  try {
21
- return await (0, item_mapper_1.decodeMessageItem)(context, item);
62
+ bytes = await (0, codec_1.readPayloadBytes)(item.message, deps, [sessionId]);
22
63
  }
23
64
  catch (error) {
24
- if (context.onCorruptMessage === 'throw')
25
- throw error;
26
- context.logger.error('getMessages: skipped a corrupt message item', {
27
- sessionId,
28
- sortKey: item.SK,
29
- });
30
- return undefined;
65
+ return corruptOrRethrow(error);
66
+ }
67
+ let stored;
68
+ try {
69
+ stored = await (0, codec_1.loadPayloadValue)(item.message.serdeType, bytes, deps);
70
+ }
71
+ catch (error) {
72
+ return corruptOrRethrow(error);
73
+ }
74
+ try {
75
+ return { kind: 'ok', message: (0, messages_1.mapStoredMessagesToChatMessages)([stored])[0] };
76
+ }
77
+ catch (error) {
78
+ return { kind: 'corrupt', error: (0, base_error_1.toError)(error) };
31
79
  }
32
80
  }
33
81
  /**
34
- * Return a session's messages in chronological order. Items past their TTL are
35
- * filtered out on read (DynamoDB's background TTL sweep can lag by up to 48h),
36
- * so the returned history is never stale. An item that cannot be decoded is
37
- * handled per `onCorruptMessage` (see {@link decodeOrSkip}).
82
+ * Return a session's messages in chronological order — the whole session, or
83
+ * the window `options` selects: `limit` keeps only the newest `limit`
84
+ * messages, `before` only those appended before that instant (see
85
+ * {@link readWindow}). Items past their TTL are filtered out on read
86
+ * (DynamoDB's background TTL sweep can lag by up to 48h), so the returned
87
+ * history is never stale. A corrupt item — see
88
+ * {@link decodeMessage} for exactly what counts — is handled per
89
+ * `onCorruptMessage`: `'throw'` fails the read with the underlying error;
90
+ * `'skip'` (the default) reports it at `error` with its sort key and returns
91
+ * the rest. Every other failure propagates regardless of the policy.
92
+ *
93
+ * Accepts: `options.limit` — the newest N, at least 1; absent asks for the
94
+ * whole session, and `0` is refused rather than read as an empty conversation
95
+ * (see {@link parseMessageWindow}).
96
+ * `options.before` — only messages appended before that instant.
97
+ * `options.signal` — aborts the reads.
98
+ *
99
+ * Returns: the messages in chronological order, oldest first. A session that
100
+ * does not exist and one whose messages have all expired both return nothing:
101
+ * a conversation nobody can read is a conversation that is not there.
102
+ *
103
+ * Throws: `VALIDATION` naming `sessionId`, `limit`, `before`, `signal`, or
104
+ * `options.<key>` for a key this package does not read;
105
+ * `FORMAT_UNSUPPORTED` for a row, or a payload, a newer version wrote — the
106
+ * payload half whatever the policy, because a newer reader reads it and
107
+ * dropping it would lose a turn a rollback could still serve; the decode error
108
+ * of a corrupt row under `onCorruptMessage: 'throw'`; `VALIDATION` naming
109
+ * `message` for a row in this session's message key space that this adapter
110
+ * did not write, naming
111
+ * `s3Key` for a row addressing an object outside the session's own path, and
112
+ * naming `serde` for a row whose payload the serializer refuses to
113
+ * reconstruct, all three whatever the policy; any infrastructure failure — a
114
+ * throttle, a permission, a transport error — whatever the policy, because
115
+ * dropping a message for one of those would hand back a silently truncated
116
+ * conversation that the chain then re-persists as the truth.
117
+ *
118
+ * Guarantees: strongly consistent, so the turn just appended is visible.
119
+ * Offloaded messages download several at a time, and the corruption policy is
120
+ * applied in message order however they finish.
38
121
  */
39
- async function getMessages(context, sessionId) {
40
- (0, validation_1.validateSessionId)(sessionId);
41
- const nowSeconds = Math.floor(Date.now() / 1000);
42
- const stored = [];
43
- for await (const raw of (0, paginate_1.paginateQuery)({
44
- client: context.client,
45
- params: (0, query_1.messageQuery)(context.tableName, sessionId),
46
- maxItems: Number.POSITIVE_INFINITY,
47
- maxIterations: Number.POSITIVE_INFINITY,
48
- })) {
49
- const item = raw;
50
- if (isExpired(item, nowSeconds))
51
- continue;
52
- const message = await decodeOrSkip(context, sessionId, item);
53
- if (message)
54
- stored.push(message);
55
- }
56
- return (0, messages_1.mapStoredMessagesToChatMessages)(stored);
122
+ async function getMessages(context, sessionId, options = {}) {
123
+ const request = (0, parse_1.parseGetMessagesRequest)(sessionId, options);
124
+ const items = await (0, message_read_1.readWindow)(context, request.sessionId, request.window, request.signal);
125
+ const decoded = await (0, concurrency_1.mapWithConcurrency)(items, context.readConcurrency ?? concurrency_1.DEFAULT_READ_CONCURRENCY, (item) => decodeMessage(context, item, request.sessionId, request.signal));
126
+ const messages = [];
127
+ decoded.forEach((result, index) => {
128
+ if (result.kind === 'ok') {
129
+ messages.push(result.message);
130
+ return;
131
+ }
132
+ if (context.onCorruptMessage === 'throw')
133
+ throw result.error;
134
+ context.logger.error('getMessages: skipped a corrupt message item', {
135
+ sessionId: request.sessionId,
136
+ sortKey: (0, truncate_1.truncateForLog)(items[index].SK),
137
+ reason: (0, truncate_1.truncateForLog)((0, base_error_1.failureLabel)(result.error)),
138
+ });
139
+ });
140
+ return messages;
57
141
  }
58
- //# sourceMappingURL=get-messages.js.map
@@ -1,13 +1,55 @@
1
+ /**
2
+ * Hides whether a listing reads the recency index or scans the table.
3
+ *
4
+ * With a configured `indexName` a listing is a cursor-paged, newest-first
5
+ * merge of the index shards; without one it is a filtered scan sorted in
6
+ * memory, with no cursor (record 8). A caller passes the same options and gets
7
+ * the same `SessionPage` either way: `limit` is the newest N on both paths,
8
+ * `0` reads neither, and the same rule summarises each session and drops the
9
+ * expired, foreign and malformed ones.
10
+ */
1
11
  import type { HistoryContext } from '../internal/setup';
2
- import type { SessionMetadata } from '../types';
12
+ import type { ListSessionsOptions, SessionPage } from '../types';
3
13
  /**
4
- * List all sessions as metadata summaries, newest-updated first. The scan is
5
- * filtered to session items so the adapter works on a table shared with the
6
- * checkpointer/store; foreign rows are also skipped defensively, and rows past
7
- * their TTL are filtered out exactly as `getMessages` filters expired messages.
14
+ * List sessions as metadata summaries, most recently updated first.
15
+ *
16
+ * Accepts: `options.limit` — the package-wide page rule, an integer from 0 to
17
+ * the page ceiling; absent means one index page (100) with the index, and
18
+ * every session without it, since a scan has no cursor to fetch the rest with.
19
+ * `0` returns an empty page on either path without reading the table, which
20
+ * matters most on the scan path: a scan has to finish before the newest can be
21
+ * known, so answering `limit: 0` by scanning and then slicing to nothing would
22
+ * have paid for the whole table to return an empty page.
23
+ * `options.cursor` — from a previous page, and
24
+ * only with a configured `indexName`. `options.maxItems` and
25
+ * `maxIterations` — caps on the scan path; with the index the page size is the
26
+ * bound and they do nothing. Each must be a positive integer or `Infinity`
27
+ * (the paginator's own way to ask for no cap); absent keeps its default.
28
+ *
29
+ * Returns: the page, newest-updated first, and a `nextCursor` while rows may
30
+ * remain. A page can come back shorter than `limit` while more remain: expired
31
+ * and foreign rows are dropped after the read, and so is a row of this
32
+ * package's own whose `messageCount`, `createdAt`, `updatedAt`, `title` or
33
+ * `ttl` is not the type written there — otherwise one unreadable `ttl` would fail the
34
+ * whole call, taking every healthy session with it. The cursor is a position in
35
+ * the index rather than a count of what survived filtering. A cursor does not
36
+ * promise more rows: the page after it can come back empty (see
37
+ * `queryRecencyIndex`).
38
+ *
39
+ * Throws: `VALIDATION` naming `limit`, `cursor`, `maxItems`,
40
+ * `maxIterations`, `signal`, or `options.<key>` for a key this package does
41
+ * not read; `RESULT_TRUNCATED` past the scan path's caps, or for an
42
+ * index shard whose pages do not end within `MAX_LOOP_ITERATIONS`;
43
+ * `FORMAT_UNSUPPORTED` for a SESSION row a newer release wrote, on either
44
+ * path; `ABORTED`.
45
+ *
46
+ * Guarantees: with a configured `indexName` each index shard is read
47
+ * newest-first one DynamoDB page at a time, and its next page whenever it has
48
+ * no row buffered and the page still needs one, which can cost a query per
49
+ * shard per page whose rows the page never takes; at most `readConcurrency`
50
+ * shards are queried at once. Memory is the page being built, up to `limit`
51
+ * rows and so bounded by the page ceiling, plus at most one DynamoDB page per shard,
52
+ * whatever the table holds. Without one it is a filtered table scan that holds
53
+ * every session at once and returns no cursor, as earlier releases did.
8
54
  */
9
- export declare function listSessions(context: HistoryContext, options?: {
10
- maxIterations?: number;
11
- maxItems?: number;
12
- }): Promise<SessionMetadata[]>;
13
- //# sourceMappingURL=list-sessions.d.ts.map
55
+ export declare function listSessions(context: HistoryContext, options?: ListSessionsOptions): Promise<SessionPage>;
@@ -1,57 +1,156 @@
1
1
  "use strict";
2
+ /**
3
+ * Hides whether a listing reads the recency index or scans the table.
4
+ *
5
+ * With a configured `indexName` a listing is a cursor-paged, newest-first
6
+ * merge of the index shards; without one it is a filtered scan sorted in
7
+ * memory, with no cursor (record 8). A caller passes the same options and gets
8
+ * the same `SessionPage` either way: `limit` is the newest N on both paths,
9
+ * `0` reads neither, and the same rule summarises each session and drops the
10
+ * expired, foreign and malformed ones.
11
+ */
2
12
  Object.defineProperty(exports, "__esModule", { value: true });
3
13
  exports.listSessions = listSessions;
4
- const scan_1 = require("../../shared/dynamodb/scan");
5
- const keys_1 = require("../internal/keys");
14
+ const clock_1 = require("../../shared/clock");
15
+ const concurrency_1 = require("../../shared/concurrency");
16
+ const paginate_1 = require("../../shared/dynamodb/paginate");
17
+ const recency_index_1 = require("../../shared/dynamodb/recency-index");
18
+ const retry_1 = require("../../shared/dynamodb/retry");
19
+ const table_schema_1 = require("../../shared/dynamodb/table-schema");
20
+ const primitives_1 = require("../../shared/validation/primitives");
21
+ const parse_1 = require("../internal/parse");
22
+ const rows_1 = require("../internal/rows");
23
+ const session_1 = require("../internal/session");
24
+ /** Rows per page when the caller names none. */
25
+ const DEFAULT_PAGE_SIZE = (0, primitives_1.parseLimit)(100, 0);
6
26
  /**
7
- * True when a session row is past its TTL. DynamoDB's background sweep can lag
8
- * up to 48h, so an expired session would otherwise keep appearing in listings
9
- * after `getMessages` had already stopped returning its messages — the same
10
- * filter that read path applies.
27
+ * One page from the recency index, newest-updated first.
28
+ *
29
+ * Expired, foreign and malformed rows are dropped after the read, so a page can
30
+ * come back shorter than `limit` while more rows remain. The cursor still advances,
31
+ * because it is the position in the index rather than a count of what survived
32
+ * filtering.
11
33
  */
12
- function isExpired(item, nowSeconds) {
13
- return item.ttl !== undefined && item.ttl <= nowSeconds;
34
+ async function pageFromIndex(context, indexName, request) {
35
+ const atSeconds = (0, clock_1.nowSeconds)();
36
+ const page = await (0, recency_index_1.queryRecencyIndex)({
37
+ client: context.client,
38
+ tableName: context.tableName,
39
+ indexName,
40
+ tag: 'SESS',
41
+ shards: context.indexShards ?? recency_index_1.DEFAULT_INDEX_SHARDS,
42
+ concurrency: context.readConcurrency ?? concurrency_1.DEFAULT_READ_CONCURRENCY,
43
+ limit: request.limit ?? DEFAULT_PAGE_SIZE,
44
+ cursor: request.cursor,
45
+ retry: (0, retry_1.retryFor)(context, request.signal),
46
+ signal: request.signal,
47
+ });
48
+ const sessions = page.items
49
+ .map((raw) => (0, session_1.summariseSession)(raw, atSeconds))
50
+ .filter((session) => session !== undefined);
51
+ return { sessions, ...(page.nextCursor === undefined ? {} : { nextCursor: page.nextCursor }) };
14
52
  }
15
53
  /**
16
- * List all sessions as metadata summaries, newest-updated first. The scan is
17
- * filtered to session items so the adapter works on a table shared with the
18
- * checkpointer/store; foreign rows are also skipped defensively, and rows past
19
- * their TTL are filtered out exactly as `getMessages` filters expired messages.
54
+ * Every session, read by scanning the table and sorted in memory.
55
+ *
56
+ * The fallback for a table without the recency index. It consumes read capacity
57
+ * for every row the scan *evaluates*, not every row it returns, and it holds
58
+ * every session at once — which is why the index exists and why this path
59
+ * offers no cursor.
60
+ *
61
+ * An explicit `limit` is honoured here as the newest N, the same thing it means
62
+ * on the index path. It cannot bound the read — a scan has to finish before the
63
+ * newest can be known — but answering a caller who asked for ten with five
64
+ * thousand sessions was a wrong answer, not a cheaper one.
65
+ *
66
+ * The filter names the partition tag before the sort key. The sort key alone
67
+ * does not identify this adapter: a store namespace element may not hold the
68
+ * separator, but the join inserts one, so the legal store key
69
+ * `sortKey(['t', 'HISTORY'], 'SESSION')` composes `SESSION_SORT_KEY` byte for
70
+ * byte. Such a row sits in a `STORE#` partition, and since a row stamped with a
71
+ * format version above this release is *reported* rather than skipped, one of
72
+ * them was enough to fail this listing on a table the three adapters share.
73
+ * `summariseSession` already requires `PK` to equal `sessionPartition(sessionId)`, so
74
+ * the tag excludes only rows it was dropping after the read. Filtering costs no
75
+ * read capacity either way: DynamoDB applies it once the scan has finished.
20
76
  */
21
- async function listSessions(context, options) {
77
+ async function allByScan(context, request) {
22
78
  const sessions = [];
23
- const nowSeconds = Math.floor(Date.now() / 1000);
24
- for await (const raw of (0, scan_1.paginateScan)({
79
+ const atSeconds = (0, clock_1.nowSeconds)();
80
+ for await (const raw of (0, paginate_1.paginateScan)({
81
+ retry: (0, retry_1.retryFor)(context, request.signal),
82
+ signal: request.signal,
25
83
  client: context.client,
26
84
  params: {
27
85
  TableName: context.tableName,
28
- FilterExpression: '#sk = :session',
29
- ExpressionAttributeNames: { '#sk': 'SK' },
30
- ExpressionAttributeValues: { ':session': keys_1.SESSION_SORT_KEY },
86
+ FilterExpression: 'begins_with(#pk, :pkp) AND #sk = :session',
87
+ ExpressionAttributeNames: { '#pk': table_schema_1.PARTITION_KEY_ATTRIBUTE, '#sk': table_schema_1.SORT_KEY_ATTRIBUTE },
88
+ ExpressionAttributeValues: {
89
+ ':pkp': (0, rows_1.historyPartitionPrefix)(),
90
+ ':session': rows_1.SESSION_SORT_KEY,
91
+ },
31
92
  },
32
- maxIterations: options?.maxIterations,
33
- maxItems: options?.maxItems,
93
+ maxIterations: request.maxIterations,
94
+ maxItems: request.maxItems,
34
95
  })) {
35
- const item = raw;
36
- if (item.SK !== keys_1.SESSION_SORT_KEY || typeof item.sessionId !== 'string')
37
- continue;
38
- if (isExpired(item, nowSeconds))
39
- continue;
40
- sessions.push({
41
- sessionId: item.sessionId,
42
- title: item.title,
43
- messageCount: item.messageCount,
44
- createdAt: item.createdAt,
45
- updatedAt: item.updatedAt,
46
- });
96
+ const session = (0, session_1.summariseSession)(raw, atSeconds);
97
+ if (session)
98
+ sessions.push(session);
47
99
  }
48
- /**
49
- * Ordinal, not `localeCompare`: these are ISO-8601 timestamps, whose
50
- * byte order already is their chronological order. Locale-aware collation
51
- * applies rules (case folding, punctuation weighting) that have no meaning
52
- * here and are not guaranteed to agree with it in every locale.
53
- */
100
+ // Ordinal, not `localeCompare`: these are ISO-8601 timestamps, whose byte
101
+ // order already is their chronological order. Locale-aware collation applies
102
+ // rules (case folding, punctuation weighting) that have no meaning here and
103
+ // are not guaranteed to agree with it in every locale.
54
104
  sessions.sort((a, b) => (a.updatedAt < b.updatedAt ? 1 : a.updatedAt > b.updatedAt ? -1 : 0));
55
- return sessions;
105
+ return { sessions: request.limit === undefined ? sessions : sessions.slice(0, request.limit) };
106
+ }
107
+ /**
108
+ * List sessions as metadata summaries, most recently updated first.
109
+ *
110
+ * Accepts: `options.limit` — the package-wide page rule, an integer from 0 to
111
+ * the page ceiling; absent means one index page (100) with the index, and
112
+ * every session without it, since a scan has no cursor to fetch the rest with.
113
+ * `0` returns an empty page on either path without reading the table, which
114
+ * matters most on the scan path: a scan has to finish before the newest can be
115
+ * known, so answering `limit: 0` by scanning and then slicing to nothing would
116
+ * have paid for the whole table to return an empty page.
117
+ * `options.cursor` — from a previous page, and
118
+ * only with a configured `indexName`. `options.maxItems` and
119
+ * `maxIterations` — caps on the scan path; with the index the page size is the
120
+ * bound and they do nothing. Each must be a positive integer or `Infinity`
121
+ * (the paginator's own way to ask for no cap); absent keeps its default.
122
+ *
123
+ * Returns: the page, newest-updated first, and a `nextCursor` while rows may
124
+ * remain. A page can come back shorter than `limit` while more remain: expired
125
+ * and foreign rows are dropped after the read, and so is a row of this
126
+ * package's own whose `messageCount`, `createdAt`, `updatedAt`, `title` or
127
+ * `ttl` is not the type written there — otherwise one unreadable `ttl` would fail the
128
+ * whole call, taking every healthy session with it. The cursor is a position in
129
+ * the index rather than a count of what survived filtering. A cursor does not
130
+ * promise more rows: the page after it can come back empty (see
131
+ * `queryRecencyIndex`).
132
+ *
133
+ * Throws: `VALIDATION` naming `limit`, `cursor`, `maxItems`,
134
+ * `maxIterations`, `signal`, or `options.<key>` for a key this package does
135
+ * not read; `RESULT_TRUNCATED` past the scan path's caps, or for an
136
+ * index shard whose pages do not end within `MAX_LOOP_ITERATIONS`;
137
+ * `FORMAT_UNSUPPORTED` for a SESSION row a newer release wrote, on either
138
+ * path; `ABORTED`.
139
+ *
140
+ * Guarantees: with a configured `indexName` each index shard is read
141
+ * newest-first one DynamoDB page at a time, and its next page whenever it has
142
+ * no row buffered and the page still needs one, which can cost a query per
143
+ * shard per page whose rows the page never takes; at most `readConcurrency`
144
+ * shards are queried at once. Memory is the page being built, up to `limit`
145
+ * rows and so bounded by the page ceiling, plus at most one DynamoDB page per shard,
146
+ * whatever the table holds. Without one it is a filtered table scan that holds
147
+ * every session at once and returns no cursor, as earlier releases did.
148
+ */
149
+ async function listSessions(context, options = {}) {
150
+ const request = (0, parse_1.parseListSessionsRequest)(options, context.indexName);
151
+ if (request.limit === 0)
152
+ return { sessions: [] };
153
+ return context.indexName === undefined
154
+ ? allByScan(context, request)
155
+ : pageFromIndex(context, context.indexName, request);
56
156
  }
57
- //# sourceMappingURL=list-sessions.js.map