@farukada/aws-langgraph-dynamodb-ts 1.0.0-rc.1 → 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 (324) hide show
  1. package/README.md +1621 -288
  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 +44 -4
  5. package/dist/checkpointer/actions/delete-thread.js +56 -22
  6. package/dist/checkpointer/actions/get-tuple.d.ts +29 -5
  7. package/dist/checkpointer/actions/get-tuple.js +41 -13
  8. package/dist/checkpointer/actions/list.d.ts +42 -10
  9. package/dist/checkpointer/actions/list.js +86 -57
  10. package/dist/checkpointer/actions/put-writes.d.ts +41 -9
  11. package/dist/checkpointer/actions/put-writes.js +62 -48
  12. package/dist/checkpointer/actions/put.d.ts +82 -10
  13. package/dist/checkpointer/actions/put.js +166 -44
  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 -21
  27. package/dist/checkpointer/internal/setup.js +65 -31
  28. package/dist/checkpointer/saver.d.ts +242 -42
  29. package/dist/checkpointer/saver.js +257 -53
  30. package/dist/checkpointer/types.d.ts +37 -44
  31. package/dist/checkpointer/types.js +10 -0
  32. package/dist/factory/factory.d.ts +120 -11
  33. package/dist/factory/factory.js +195 -16
  34. package/dist/factory/types.d.ts +23 -4
  35. package/dist/factory/types.js +8 -0
  36. package/dist/history/actions/add-messages.d.ts +30 -2
  37. package/dist/history/actions/add-messages.js +37 -57
  38. package/dist/history/actions/clear.d.ts +46 -4
  39. package/dist/history/actions/clear.js +64 -15
  40. package/dist/history/actions/get-messages.d.ts +41 -0
  41. package/dist/history/actions/get-messages.js +94 -32
  42. package/dist/history/actions/list-sessions.d.ts +52 -10
  43. package/dist/history/actions/list-sessions.js +141 -38
  44. package/dist/history/actions/reconcile-count.d.ts +41 -8
  45. package/dist/history/actions/reconcile-count.js +44 -57
  46. package/dist/history/chat-message-history.d.ts +200 -38
  47. package/dist/history/chat-message-history.js +218 -51
  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 -19
  59. package/dist/history/internal/setup.js +90 -27
  60. package/dist/history/session-adapter.d.ts +95 -6
  61. package/dist/history/session-adapter.js +99 -8
  62. package/dist/history/types.d.ts +61 -31
  63. package/dist/history/types.js +10 -0
  64. package/dist/index.d.ts +38 -14
  65. package/dist/index.js +31 -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 +48 -4
  69. package/dist/shared/clock.js +51 -4
  70. package/dist/shared/codec/codec.d.ts +275 -9
  71. package/dist/shared/codec/codec.js +394 -19
  72. package/dist/shared/codec/compression.d.ts +43 -6
  73. package/dist/shared/codec/compression.js +52 -11
  74. package/dist/shared/codec/json-serde.d.ts +76 -3
  75. package/dist/shared/codec/json-serde.js +181 -7
  76. package/dist/shared/codec/s3/client-types.d.ts +20 -1
  77. package/dist/shared/codec/s3/client-types.js +20 -1
  78. package/dist/shared/codec/s3/client.d.ts +35 -8
  79. package/dist/shared/codec/s3/client.js +61 -10
  80. package/dist/shared/codec/s3/config.d.ts +226 -22
  81. package/dist/shared/codec/s3/config.js +274 -24
  82. package/dist/shared/codec/s3/lifecycle.d.ts +163 -11
  83. package/dist/shared/codec/s3/lifecycle.js +328 -36
  84. package/dist/shared/codec/s3/offloader.d.ts +390 -19
  85. package/dist/shared/codec/s3/offloader.js +590 -50
  86. package/dist/shared/concurrency.d.ts +40 -3
  87. package/dist/shared/concurrency.js +55 -7
  88. package/dist/shared/dynamodb/abort.d.ts +45 -7
  89. package/dist/shared/dynamodb/abort.js +46 -14
  90. package/dist/shared/dynamodb/batch-write.d.ts +77 -13
  91. package/dist/shared/dynamodb/batch-write.js +146 -26
  92. package/dist/shared/dynamodb/cancellation.d.ts +121 -3
  93. package/dist/shared/dynamodb/cancellation.js +147 -2
  94. package/dist/shared/dynamodb/client.d.ts +159 -12
  95. package/dist/shared/dynamodb/client.js +135 -10
  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 -8
  99. package/dist/shared/dynamodb/paginate.js +175 -6
  100. package/dist/shared/dynamodb/partition-delete.d.ts +181 -16
  101. package/dist/shared/dynamodb/partition-delete.js +312 -43
  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 +265 -10
  105. package/dist/shared/dynamodb/retry.js +426 -20
  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 +174 -8
  109. package/dist/shared/errors/base-error.js +154 -7
  110. package/dist/shared/errors/boundary.d.ts +63 -10
  111. package/dist/shared/errors/boundary.js +110 -13
  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 +76 -1
  115. package/dist/shared/errors/error-code.js +83 -1
  116. package/dist/shared/errors/errors.d.ts +157 -58
  117. package/dist/shared/errors/errors.js +218 -93
  118. package/dist/shared/logging/logger.d.ts +63 -1
  119. package/dist/shared/logging/logger.js +97 -2
  120. package/dist/shared/logging/redaction.d.ts +86 -6
  121. package/dist/shared/logging/redaction.js +265 -24
  122. package/dist/shared/logging/secret-patterns.d.ts +136 -24
  123. package/dist/shared/logging/secret-patterns.js +165 -30
  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 +52 -5
  127. package/dist/shared/options.js +9 -0
  128. package/dist/shared/ulid.d.ts +71 -14
  129. package/dist/shared/ulid.js +77 -14
  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 +142 -5
  135. package/dist/shared/validation/options.js +284 -46
  136. package/dist/shared/validation/primitives.d.ts +287 -24
  137. package/dist/shared/validation/primitives.js +347 -42
  138. package/dist/shared/validation/ttl.d.ts +61 -12
  139. package/dist/shared/validation/ttl.js +102 -22
  140. package/dist/store/actions/list-namespaces.d.ts +76 -5
  141. package/dist/store/actions/list-namespaces.js +160 -22
  142. package/dist/store/actions/put.d.ts +33 -7
  143. package/dist/store/actions/put.js +53 -71
  144. package/dist/store/actions/reconcile-vector-index.d.ts +28 -8
  145. package/dist/store/actions/reconcile-vector-index.js +33 -13
  146. package/dist/store/actions/search.d.ts +34 -5
  147. package/dist/store/actions/search.js +52 -20
  148. package/dist/store/internal/batch-plan.d.ts +24 -9
  149. package/dist/store/internal/batch-plan.js +91 -34
  150. package/dist/store/internal/filter.d.ts +36 -2
  151. package/dist/store/internal/filter.js +66 -14
  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 +146 -12
  161. package/dist/store/internal/semantic-search.js +317 -15
  162. package/dist/store/internal/setup.d.ts +86 -21
  163. package/dist/store/internal/setup.js +209 -26
  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 +258 -33
  169. package/dist/store/store.js +309 -53
  170. package/dist/store/types.d.ts +74 -28
  171. package/dist/store/types.js +13 -0
  172. package/dist/store/vector-backend.d.ts +64 -3
  173. package/dist/store/vector-backend.js +15 -0
  174. package/package.json +41 -25
  175. package/dist/checkpointer/internal/assemble.d.ts +0 -17
  176. package/dist/checkpointer/internal/assemble.js +0 -38
  177. package/dist/checkpointer/internal/checkpoint-write-verify.d.ts +0 -24
  178. package/dist/checkpointer/internal/checkpoint-write-verify.js +0 -67
  179. package/dist/checkpointer/internal/configurable.d.ts +0 -12
  180. package/dist/checkpointer/internal/configurable.js +0 -24
  181. package/dist/checkpointer/internal/fetch.d.ts +0 -19
  182. package/dist/checkpointer/internal/fetch.js +0 -88
  183. package/dist/checkpointer/internal/filter-match.d.ts +0 -13
  184. package/dist/checkpointer/internal/filter-match.js +0 -15
  185. package/dist/checkpointer/internal/item-reader.d.ts +0 -66
  186. package/dist/checkpointer/internal/item-reader.js +0 -113
  187. package/dist/checkpointer/internal/item-writer.d.ts +0 -35
  188. package/dist/checkpointer/internal/item-writer.js +0 -107
  189. package/dist/checkpointer/internal/keys.d.ts +0 -41
  190. package/dist/checkpointer/internal/keys.js +0 -117
  191. package/dist/checkpointer/internal/list-scope.d.ts +0 -61
  192. package/dist/checkpointer/internal/list-scope.js +0 -108
  193. package/dist/checkpointer/internal/pending-sends.d.ts +0 -13
  194. package/dist/checkpointer/internal/pending-sends.js +0 -29
  195. package/dist/checkpointer/internal/query.d.ts +0 -21
  196. package/dist/checkpointer/internal/query.js +0 -42
  197. package/dist/checkpointer/internal/regular-write.d.ts +0 -28
  198. package/dist/checkpointer/internal/regular-write.js +0 -66
  199. package/dist/checkpointer/internal/special-write-cas.d.ts +0 -29
  200. package/dist/checkpointer/internal/special-write-cas.js +0 -104
  201. package/dist/checkpointer/internal/special-write-cleanup.d.ts +0 -23
  202. package/dist/checkpointer/internal/special-write-cleanup.js +0 -50
  203. package/dist/checkpointer/internal/special-write-verify.d.ts +0 -53
  204. package/dist/checkpointer/internal/special-write-verify.js +0 -80
  205. package/dist/checkpointer/internal/stored-channels.d.ts +0 -31
  206. package/dist/checkpointer/internal/stored-channels.js +0 -70
  207. package/dist/checkpointer/internal/validation.d.ts +0 -18
  208. package/dist/checkpointer/internal/validation.js +0 -40
  209. package/dist/checkpointer/internal/write-guard.d.ts +0 -20
  210. package/dist/checkpointer/internal/write-guard.js +0 -48
  211. package/dist/checkpointer/internal/write-index.d.ts +0 -36
  212. package/dist/checkpointer/internal/write-index.js +0 -41
  213. package/dist/history/internal/append-saga.d.ts +0 -25
  214. package/dist/history/internal/append-saga.js +0 -79
  215. package/dist/history/internal/compensation.d.ts +0 -25
  216. package/dist/history/internal/compensation.js +0 -92
  217. package/dist/history/internal/item-mapper.d.ts +0 -9
  218. package/dist/history/internal/item-mapper.js +0 -27
  219. package/dist/history/internal/keys.d.ts +0 -16
  220. package/dist/history/internal/keys.js +0 -48
  221. package/dist/history/internal/message-chunker.d.ts +0 -13
  222. package/dist/history/internal/message-chunker.js +0 -67
  223. package/dist/history/internal/message-transaction.d.ts +0 -25
  224. package/dist/history/internal/message-transaction.js +0 -61
  225. package/dist/history/internal/message-window.d.ts +0 -17
  226. package/dist/history/internal/message-window.js +0 -49
  227. package/dist/history/internal/query.d.ts +0 -23
  228. package/dist/history/internal/query.js +0 -39
  229. package/dist/history/internal/session-count.d.ts +0 -47
  230. package/dist/history/internal/session-count.js +0 -115
  231. package/dist/history/internal/session-title.d.ts +0 -19
  232. package/dist/history/internal/session-title.js +0 -43
  233. package/dist/history/internal/session-update.d.ts +0 -27
  234. package/dist/history/internal/session-update.js +0 -69
  235. package/dist/history/internal/title-generator.d.ts +0 -12
  236. package/dist/history/internal/title-generator.js +0 -41
  237. package/dist/history/internal/ttl-anchor.d.ts +0 -24
  238. package/dist/history/internal/ttl-anchor.js +0 -38
  239. package/dist/history/internal/validation.d.ts +0 -25
  240. package/dist/history/internal/validation.js +0 -53
  241. package/dist/shared/codec/descriptor-keys.d.ts +0 -12
  242. package/dist/shared/codec/descriptor-keys.js +0 -14
  243. package/dist/shared/codec/encode.d.ts +0 -13
  244. package/dist/shared/codec/encode.js +0 -43
  245. package/dist/shared/codec/payload-loss.d.ts +0 -12
  246. package/dist/shared/codec/payload-loss.js +0 -38
  247. package/dist/shared/codec/s3/adapter-config.d.ts +0 -13
  248. package/dist/shared/codec/s3/adapter-config.js +0 -22
  249. package/dist/shared/codec/s3/bounded-body.d.ts +0 -14
  250. package/dist/shared/codec/s3/bounded-body.js +0 -47
  251. package/dist/shared/codec/s3/delete.d.ts +0 -7
  252. package/dist/shared/codec/s3/delete.js +0 -28
  253. package/dist/shared/codec/s3/key-scope.d.ts +0 -23
  254. package/dist/shared/codec/s3/key-scope.js +0 -44
  255. package/dist/shared/codec/s3/orphans.d.ts +0 -23
  256. package/dist/shared/codec/s3/orphans.js +0 -71
  257. package/dist/shared/codec/s3/read-write.d.ts +0 -18
  258. package/dist/shared/codec/s3/read-write.js +0 -51
  259. package/dist/shared/codec/s3/retry.d.ts +0 -5
  260. package/dist/shared/codec/s3/retry.js +0 -22
  261. package/dist/shared/constants.d.ts +0 -112
  262. package/dist/shared/constants.js +0 -115
  263. package/dist/shared/dynamodb/backoff.d.ts +0 -15
  264. package/dist/shared/dynamodb/backoff.js +0 -48
  265. package/dist/shared/dynamodb/conditional-put.d.ts +0 -67
  266. package/dist/shared/dynamodb/conditional-put.js +0 -76
  267. package/dist/shared/dynamodb/drain-unprocessed.d.ts +0 -21
  268. package/dist/shared/dynamodb/drain-unprocessed.js +0 -43
  269. package/dist/shared/dynamodb/expiry.d.ts +0 -16
  270. package/dist/shared/dynamodb/expiry.js +0 -29
  271. package/dist/shared/dynamodb/paginate-core.d.ts +0 -24
  272. package/dist/shared/dynamodb/paginate-core.js +0 -82
  273. package/dist/shared/dynamodb/retry-classifier.d.ts +0 -17
  274. package/dist/shared/dynamodb/retry-classifier.js +0 -118
  275. package/dist/shared/dynamodb/retry-policy.d.ts +0 -26
  276. package/dist/shared/dynamodb/retry-policy.js +0 -22
  277. package/dist/shared/dynamodb/scan.d.ts +0 -14
  278. package/dist/shared/dynamodb/scan.js +0 -19
  279. package/dist/shared/dynamodb/types.d.ts +0 -23
  280. package/dist/shared/dynamodb/types.js +0 -2
  281. package/dist/shared/errors/upstream-error.d.ts +0 -16
  282. package/dist/shared/errors/upstream-error.js +0 -27
  283. package/dist/shared/errors/wrap-error.d.ts +0 -7
  284. package/dist/shared/errors/wrap-error.js +0 -15
  285. package/dist/shared/logging/redaction-walk.d.ts +0 -23
  286. package/dist/shared/logging/redaction-walk.js +0 -112
  287. package/dist/store/actions/get.d.ts +0 -13
  288. package/dist/store/actions/get.js +0 -73
  289. package/dist/store/internal/backend-search.d.ts +0 -4
  290. package/dist/store/internal/backend-search.js +0 -74
  291. package/dist/store/internal/candidates.d.ts +0 -23
  292. package/dist/store/internal/candidates.js +0 -94
  293. package/dist/store/internal/index-reconcile.d.ts +0 -21
  294. package/dist/store/internal/index-reconcile.js +0 -118
  295. package/dist/store/internal/index-sync.d.ts +0 -10
  296. package/dist/store/internal/index-sync.js +0 -25
  297. package/dist/store/internal/item-mapper.d.ts +0 -27
  298. package/dist/store/internal/item-mapper.js +0 -61
  299. package/dist/store/internal/keys.d.ts +0 -17
  300. package/dist/store/internal/keys.js +0 -41
  301. package/dist/store/internal/namespace-match.d.ts +0 -11
  302. package/dist/store/internal/namespace-match.js +0 -40
  303. package/dist/store/internal/option-validation.d.ts +0 -13
  304. package/dist/store/internal/option-validation.js +0 -77
  305. package/dist/store/internal/overwrite-swap.d.ts +0 -32
  306. package/dist/store/internal/overwrite-swap.js +0 -68
  307. package/dist/store/internal/persist.d.ts +0 -28
  308. package/dist/store/internal/persist.js +0 -64
  309. package/dist/store/internal/query.d.ts +0 -11
  310. package/dist/store/internal/query.js +0 -48
  311. package/dist/store/internal/ranker.d.ts +0 -18
  312. package/dist/store/internal/ranker.js +0 -39
  313. package/dist/store/internal/read-existing.d.ts +0 -23
  314. package/dist/store/internal/read-existing.js +0 -41
  315. package/dist/store/internal/score-direction.d.ts +0 -31
  316. package/dist/store/internal/score-direction.js +0 -38
  317. package/dist/store/internal/search-filter.d.ts +0 -3
  318. package/dist/store/internal/search-filter.js +0 -10
  319. package/dist/store/internal/text-path.d.ts +0 -17
  320. package/dist/store/internal/text-path.js +0 -147
  321. package/dist/store/internal/validation.d.ts +0 -18
  322. package/dist/store/internal/validation.js +0 -51
  323. package/dist/store/internal/write-verify.d.ts +0 -42
  324. package/dist/store/internal/write-verify.js +0 -71
@@ -1,73 +1,235 @@
1
+ /**
2
+ * Hides that chat history is a set of actions behind one error boundary.
3
+ *
4
+ * The public class holds only what it resolved from its options and routes
5
+ * each read and write to the action that implements it, through
6
+ * `guardPublic`. Each asynchronous method is the error boundary, so no error
7
+ * but the library's own reaches a caller (record 13); the synchronous
8
+ * `destroy` and `forSession` are the exceptions — the latter is also the
9
+ * one route from it to LangChain's single-session history. Where an action
10
+ * lives, how it reads or writes, and which client or offloader it uses can
11
+ * change without touching this surface.
12
+ */
1
13
  import type { BaseMessage } from '@langchain/core/messages';
2
14
  import type { CancelOptions } from '../shared/options';
3
15
  import { type AdapterWindow, DynamoDBSessionChatMessageHistory } from './session-adapter';
4
- import type { DynamoDBChatMessageHistoryOptions, GetMessagesOptions, ListSessionsOptions, SessionMetadata } from './types';
16
+ import type { DynamoDBChatMessageHistoryOptions, GetMessagesOptions, ListSessionsOptions, SessionPage } from './types';
5
17
  /**
6
- * DynamoDB-backed multi-session chat history. Each message is its own item
7
- * (ordered by a monotonic ULID, compressed / S3-offloaded as needed) alongside a
8
- * per-session metadata item; every message in a session shares one uniform TTL.
9
- * Appends are O(1) and lock-free. Use {@link forSession} to get a single-session
10
- * LangChain adapter. Every public method is the library's error boundary — a
11
- * raw AWS SDK error escaping an action surfaces as an `UpstreamError`.
18
+ * DynamoDB-backed multi-session chat history. Each message is its own row,
19
+ * ordered by when it was appended, beside one metadata row per session, and
20
+ * every message in a session shares one TTL. An append costs the same however
21
+ * long the session is and takes no lock. Use {@link forSession} to get a
22
+ * single-session LangChain adapter. Every public method rejects only with this
23
+ * library's error.
12
24
  */
13
25
  export declare class DynamoDBChatMessageHistory {
14
26
  private readonly context;
15
- private readonly ownsClient;
16
- private readonly ddbClient;
27
+ private readonly shell;
28
+ /**
29
+ * Accepts: `options` — validated here, so a misconfiguration surfaces at
30
+ * construction rather than on the first request.
31
+ *
32
+ * Returns: an adapter that owns the client it built, or borrows the one it
33
+ * was given.
34
+ *
35
+ * Throws: `VALIDATION` naming the offending option.
36
+ *
37
+ * Guarantees: no I/O. Constructing the adapter issues no request.
38
+ */
17
39
  constructor(options: DynamoDBChatMessageHistoryOptions);
18
40
  /**
19
- * Get a session's messages in chronological order: the whole session by
20
- * default, or a window of it — `{ limit }` returns only the newest `limit`
21
- * messages, `{ before }` only those appended before that instant — so a
22
- * long-lived session can be read a page at a time instead of whole.
23
- * @remarks Strongly consistent; one query page plus one S3 download per offloaded message.
24
- * @throws ValidationError for a malformed session id or window; UpstreamError; AbortError; and, under `onCorruptMessage: 'throw'`, the decode error of a corrupt row.
41
+ * Get a session's messages in chronological order.
42
+ *
43
+ * Accepts: `sessionId` — validated. `options.limit` — an integer from 1 to
44
+ * `MAX_PAGE_LIMIT` (10,000); only the newest that many messages. `0` is
45
+ * refused rather than answered with an empty conversation, which is the one
46
+ * place this package refuses a `limit` of zero. `options.before` — a valid
47
+ * `Date`; only messages appended before that instant. Neither given reads
48
+ * the whole session. `options.signal` — aborts the reads.
49
+ *
50
+ * Returns: the messages, oldest first. A session that does not exist and one
51
+ * whose messages have all expired both return nothing.
52
+ *
53
+ * Throws: `VALIDATION` for a malformed session id or window, an invalid
54
+ * `signal`, or naming `options.<key>` for a key this package does not read;
55
+ * `VALIDATION` naming `s3Key` for a row addressing an object outside the
56
+ * session's own path, and naming `message` for a row in this session's
57
+ * message key space that this adapter did not write, both whatever the
58
+ * corruption policy;
59
+ * `FORMAT_UNSUPPORTED` for a row, or a payload, a newer release wrote;
60
+ * a classified AWS failure;
61
+ * `ABORTED`; and, under `onCorruptMessage: 'throw'`, the decode error of a
62
+ * corrupt row.
63
+ *
64
+ * Guarantees: strongly consistent, so the turn just appended is visible.
65
+ * Expired messages are filtered on read, so the history is never stale.
66
+ * @remarks One query page plus one S3 download per offloaded message.
25
67
  */
26
68
  getMessages(sessionId: string, options?: GetMessagesOptions): Promise<BaseMessage[]>;
27
69
  /**
28
- * Append messages to a session in one transaction per chunk of up to 99
29
- * messages, keeping the session's `messageCount` exact. Lock-free and safe
30
- * under concurrent appends to one session; every message shares the
31
- * session's TTL when one is configured.
32
- * @throws ValidationError for a message that could never be read back; CompensationFailedError when a later chunk fails and the rollback fails too; RetryExhaustedError after 18 contended attempts; UpstreamError; AbortError.
70
+ * Append messages to a session.
71
+ *
72
+ * Accepts: `sessionId` — validated. `messages` — LangChain messages; an empty
73
+ * list writes nothing and is not an error. `options.signal` — aborts between
74
+ * chunks.
75
+ *
76
+ * Returns: nothing, and only once every message has landed.
77
+ *
78
+ * Throws: `VALIDATION` naming `messages`, for a value that is not itself
79
+ * an array, or, with the offending index, for an element that is not a
80
+ * message or one that could never be read back; or naming `signal` or
81
+ * `options.<key>` for a key this package does not read;
82
+ * `COMPENSATION_FAILED` when a later chunk fails and the rollback fails
83
+ * too; `RETRY_EXHAUSTED` after 18 contended attempts; a classified AWS failure;
84
+ * `ABORTED`.
85
+ *
86
+ * Guarantees: a caller observes all messages or none. One transaction per
87
+ * chunk of up to 99 keeps `messageCount` exact. Lock-free and safe under
88
+ * concurrent appends to one session; every message shares the session's TTL
89
+ * when one is configured.
33
90
  */
34
91
  addMessages(sessionId: string, messages: BaseMessage[], options?: CancelOptions): Promise<void>;
35
- /** Append one message; see {@link addMessages}. */
92
+ /**
93
+ * Append one message.
94
+ *
95
+ * Accepts: as {@link addMessages}, for a single message.
96
+ *
97
+ * Returns: nothing.
98
+ *
99
+ * Throws: as {@link addMessages}.
100
+ */
36
101
  addMessage(sessionId: string, message: BaseMessage, options?: CancelOptions): Promise<void>;
37
102
  /**
38
- * Delete a session's messages, metadata and offloaded objects. Single pass:
39
- * call it when the session is quiescent.
40
- * @throws BatchWriteAllIncompleteError when a delete batch does not fully drain; UpstreamError; AbortError.
103
+ * Delete a session's messages, metadata and offloaded objects.
104
+ *
105
+ * Accepts: `sessionId` — validated. `options.signal` — aborts between pages.
106
+ *
107
+ * Returns: nothing. Clearing a session that does not exist is not an error.
108
+ *
109
+ * Throws: `VALIDATION` for a malformed session id, an invalid `signal`,
110
+ * or an `options.<key>` this package does not read;
111
+ * `BATCH_WRITE_INCOMPLETE` when a row's delete fails, counting rows
112
+ * rather than batches; a classified AWS failure; `ABORTED` when the signal fires,
113
+ * which is what a cancel surfaces as rather than an incomplete delete, even
114
+ * when it fires part-way through the pass. A row refused because it
115
+ * was rewritten after the partition read raises nothing: it is left in place,
116
+ * reported at `warn`, and counted as skipped.
117
+ *
118
+ * Guarantees: a row this adapter did not write is left in place and logged,
119
+ * and neither is a row rewritten since the read — an append landing during
120
+ * the call moves the session row's own write id, so that row survives with
121
+ * the session it belongs to instead of being removed under a live
122
+ * conversation. Single pass: call it when the session is quiescent, since a
123
+ * message appended while it runs may survive it, and the surviving session
124
+ * row then over-counts until `reconcileMessageCount` repairs it.
41
125
  */
42
126
  clear(sessionId: string, options?: CancelOptions): Promise<void>;
43
127
  /**
44
128
  * List every session as a metadata summary, most recently updated first.
45
- * A table scan: cross-tenant by construction and bounded by `maxItems` /
46
- * `maxIterations`.
47
- * @throws ResultTruncatedError past either cap; UpstreamError; AbortError.
129
+ * With a configured `indexName` this reads each index shard newest-first,
130
+ * merges the shards and pages by the opaque `nextCursor`. Without one it
131
+ * falls back to a filtered table scan — cross-tenant by construction,
132
+ * bounded by `maxItems` / `maxIterations`, and returning the newest `limit`
133
+ * sessions, or every session when no limit is given, with no cursor.
134
+ *
135
+ * Accepts: `options.limit` — an integer from 0 to `MAX_PAGE_LIMIT` (10,000);
136
+ * the page size with the index, the newest N without it, and `0` an empty
137
+ * page read from neither. `options.cursor` — from a previous page,
138
+ * and only with a configured `indexName`. `options.maxItems` /
139
+ * `maxIterations` — caps on the scan path. `options.signal` — aborts the
140
+ * reads.
141
+ *
142
+ * Returns: the page and, while rows may remain, a `nextCursor`. A page may
143
+ * come back shorter than `limit` while more rows remain: expired and foreign
144
+ * rows are dropped after the read. A cursor does not promise more rows:
145
+ * DynamoDB can end a shard's page at its last row and still return a key to
146
+ * continue from, and the page after such a cursor can come back empty. Stop
147
+ * when `nextCursor` is absent, never when a page looks short.
148
+ *
149
+ * Throws: `VALIDATION` naming `limit`, `cursor`, `maxItems`,
150
+ * `maxIterations`, `signal`, or `options.<key>` for a key this package does
151
+ * not read; `RESULT_TRUNCATED` past either cap on the scan path, or for an
152
+ * index shard whose pages do not end; `FORMAT_UNSUPPORTED` for a session row
153
+ * a newer release wrote; a classified AWS failure; `ABORTED`.
154
+ *
155
+ * Guarantees: with a configured `indexName` each shard is read one DynamoDB
156
+ * page at a time, and its next page whenever it has no row buffered and the
157
+ * page still needs one, so a shard can cost a query whose rows the page never
158
+ * takes; at most `readConcurrency` shards are queried at once. Memory is the
159
+ * page being built, up to `limit` rows and so bounded by
160
+ * `MAX_PAGE_LIMIT` (10,000), plus at most one DynamoDB page per shard,
161
+ * whatever the table holds.
48
162
  */
49
- listSessions(options?: ListSessionsOptions): Promise<SessionMetadata[]>;
163
+ listSessions(options?: ListSessionsOptions): Promise<SessionPage>;
50
164
  /**
51
165
  * Recompute and repair a session's `messageCount` from the stored messages.
52
166
  * A maintenance tool for external corruption; run it when the session is idle.
53
- * @throws ConflictError when the session does not exist or changed while counting; UpstreamError; AbortError.
167
+ *
168
+ * Accepts: `sessionId` — validated, and an existing session.
169
+ * `options.signal` — aborts the reads.
170
+ *
171
+ * Returns: the count now stored, which is the number of messages a reader
172
+ * would see.
173
+ *
174
+ * Throws: `VALIDATION` for a malformed session id, an invalid `signal`,
175
+ * or an `options.<key>` this package does not read; `CONDITION_CONFLICT` when the
176
+ * session does not exist or stayed busy through every attempt;
177
+ * `FORMAT_UNSUPPORTED` for a message row a newer release wrote, and
178
+ * `VALIDATION` naming `message` for a row in the session's message key
179
+ * space that this adapter did not write, both of which `getMessages` refuses
180
+ * too — a count is a repair only while it agrees with the read;
181
+ * a classified AWS failure; `ABORTED`.
182
+ *
183
+ * Guarantees: safe on a live session — the write is pinned to the value the
184
+ * row held when the count was computed, so a concurrent append makes it
185
+ * recount instead of clobbering the increment.
54
186
  */
55
187
  reconcileMessageCount(sessionId: string, options?: CancelOptions): Promise<number>;
56
188
  /**
57
- * Get a single-session LangChain adapter for `sessionId`. `{ limit }` bounds
58
- * what the adapter feeds the chain to the newest `limit` messages.
189
+ * Get a single-session LangChain adapter for `sessionId`.
190
+ *
191
+ * Accepts: `sessionId` — validated by the adapter's own constructor, the
192
+ * same rule every other method applies. `window.limit` — bounds what the
193
+ * adapter feeds the chain to the newest that many messages; validated the
194
+ * same way.
195
+ *
196
+ * Returns: an adapter implementing `BaseListChatMessageHistory`, which is
197
+ * what `RunnableWithMessageHistory` takes.
198
+ *
199
+ * Throws: `VALIDATION` naming `sessionId`, `window` for a window that is
200
+ * not an object, `window.<key>` for a key the adapter does not declare, or
201
+ * `limit` — raised by the constructed adapter, so a bad id or window fails
202
+ * here rather than on first use.
59
203
  */
60
204
  forSession(sessionId: string, window?: AdapterWindow): DynamoDBSessionChatMessageHistory;
61
- /** Release owned resources (the underlying client and any S3 client). */
205
+ /**
206
+ * Release owned resources.
207
+ *
208
+ * Accepts: nothing.
209
+ *
210
+ * Returns: nothing. Idempotent, and a no-op for a client the caller injected
211
+ * — that one is theirs to close.
212
+ *
213
+ * Throws: whatever a resource's own `destroy` raises — but only after every
214
+ * other one has been released, so a client that fails to close never strands
215
+ * the one behind it.
216
+ */
62
217
  destroy(): void;
63
218
  /**
64
219
  * Provision an S3 lifecycle expiration rule matching the configured TTL, so
65
- * offloaded objects don't outlive their DynamoDB item forever. No-ops when
66
- * S3 offload or TTL isn't configured; throws when the bucket cannot be read
67
- * or written. Requires the `s3:GetLifecycleConfiguration` /
68
- * `s3:PutLifecycleConfiguration` bucket-level permissions (broader than the
69
- * object-level CRUD the rest of S3 offload needs) — call this once during
70
- * deployment/provisioning, not per-request.
220
+ * offloaded objects don't outlive their DynamoDB item forever.
221
+ *
222
+ * Accepts: nothing; the rule follows the configured `s3` and `ttl`. A no-op
223
+ * without both.
224
+ *
225
+ * Returns: nothing. Installing a rule that is already there is a no-op too.
226
+ *
227
+ * Throws: `VALIDATION` naming `s3.keyPrefix` on a rule-id collision;
228
+ * a classified AWS failure when the bucket's lifecycle cannot be read or written.
229
+ * @remarks Requires the bucket-level `s3:GetLifecycleConfiguration` /
230
+ * `s3:PutLifecycleConfiguration` permissions, broader than the object-level
231
+ * CRUD the rest of S3 offload needs — call it once during provisioning, not
232
+ * per request.
71
233
  */
72
234
  ensureS3LifecycleRule(): Promise<void>;
73
235
  }
@@ -1,8 +1,20 @@
1
1
  "use strict";
2
+ /**
3
+ * Hides that chat history is a set of actions behind one error boundary.
4
+ *
5
+ * The public class holds only what it resolved from its options and routes
6
+ * each read and write to the action that implements it, through
7
+ * `guardPublic`. Each asynchronous method is the error boundary, so no error
8
+ * but the library's own reaches a caller (record 13); the synchronous
9
+ * `destroy` and `forSession` are the exceptions — the latter is also the
10
+ * one route from it to LangChain's single-session history. Where an action
11
+ * lives, how it reads or writes, and which client or offloader it uses can
12
+ * change without touching this surface.
13
+ */
2
14
  Object.defineProperty(exports, "__esModule", { value: true });
3
15
  exports.DynamoDBChatMessageHistory = void 0;
4
16
  const boundary_1 = require("../shared/errors/boundary");
5
- const ttl_1 = require("../shared/validation/ttl");
17
+ const collaborators_1 = require("../shared/validation/collaborators");
6
18
  const add_messages_1 = require("./actions/add-messages");
7
19
  const clear_1 = require("./actions/clear");
8
20
  const get_messages_1 = require("./actions/get-messages");
@@ -11,61 +23,171 @@ const reconcile_count_1 = require("./actions/reconcile-count");
11
23
  const setup_1 = require("./internal/setup");
12
24
  const session_adapter_1 = require("./session-adapter");
13
25
  /**
14
- * DynamoDB-backed multi-session chat history. Each message is its own item
15
- * (ordered by a monotonic ULID, compressed / S3-offloaded as needed) alongside a
16
- * per-session metadata item; every message in a session shares one uniform TTL.
17
- * Appends are O(1) and lock-free. Use {@link forSession} to get a single-session
18
- * LangChain adapter. Every public method is the library's error boundary — a
19
- * raw AWS SDK error escaping an action surfaces as an `UpstreamError`.
26
+ * DynamoDB-backed multi-session chat history. Each message is its own row,
27
+ * ordered by when it was appended, beside one metadata row per session, and
28
+ * every message in a session shares one TTL. An append costs the same however
29
+ * long the session is and takes no lock. Use {@link forSession} to get a
30
+ * single-session LangChain adapter. Every public method rejects only with this
31
+ * library's error.
20
32
  */
21
33
  class DynamoDBChatMessageHistory {
22
34
  context;
23
- ownsClient;
24
- ddbClient;
35
+ shell;
36
+ /**
37
+ * Accepts: `options` — validated here, so a misconfiguration surfaces at
38
+ * construction rather than on the first request.
39
+ *
40
+ * Returns: an adapter that owns the client it built, or borrows the one it
41
+ * was given.
42
+ *
43
+ * Throws: `VALIDATION` naming the offending option.
44
+ *
45
+ * Guarantees: no I/O. Constructing the adapter issues no request.
46
+ */
25
47
  constructor(options) {
26
48
  const setup = (0, setup_1.setUpHistory)(options);
27
49
  this.context = setup.context;
28
- this.ownsClient = setup.ownsClient;
29
- this.ddbClient = setup.ddbClient;
50
+ this.shell = setup.shell;
30
51
  }
31
52
  /**
32
- * Get a session's messages in chronological order: the whole session by
33
- * default, or a window of it — `{ limit }` returns only the newest `limit`
34
- * messages, `{ before }` only those appended before that instant — so a
35
- * long-lived session can be read a page at a time instead of whole.
36
- * @remarks Strongly consistent; one query page plus one S3 download per offloaded message.
37
- * @throws ValidationError for a malformed session id or window; UpstreamError; AbortError; and, under `onCorruptMessage: 'throw'`, the decode error of a corrupt row.
53
+ * Get a session's messages in chronological order.
54
+ *
55
+ * Accepts: `sessionId` — validated. `options.limit` — an integer from 1 to
56
+ * `MAX_PAGE_LIMIT` (10,000); only the newest that many messages. `0` is
57
+ * refused rather than answered with an empty conversation, which is the one
58
+ * place this package refuses a `limit` of zero. `options.before` — a valid
59
+ * `Date`; only messages appended before that instant. Neither given reads
60
+ * the whole session. `options.signal` — aborts the reads.
61
+ *
62
+ * Returns: the messages, oldest first. A session that does not exist and one
63
+ * whose messages have all expired both return nothing.
64
+ *
65
+ * Throws: `VALIDATION` for a malformed session id or window, an invalid
66
+ * `signal`, or naming `options.<key>` for a key this package does not read;
67
+ * `VALIDATION` naming `s3Key` for a row addressing an object outside the
68
+ * session's own path, and naming `message` for a row in this session's
69
+ * message key space that this adapter did not write, both whatever the
70
+ * corruption policy;
71
+ * `FORMAT_UNSUPPORTED` for a row, or a payload, a newer release wrote;
72
+ * a classified AWS failure;
73
+ * `ABORTED`; and, under `onCorruptMessage: 'throw'`, the decode error of a
74
+ * corrupt row.
75
+ *
76
+ * Guarantees: strongly consistent, so the turn just appended is visible.
77
+ * Expired messages are filtered on read, so the history is never stale.
78
+ * @remarks One query page plus one S3 download per offloaded message.
38
79
  */
39
80
  getMessages(sessionId, options) {
40
81
  return (0, boundary_1.guardPublic)('history.getMessages', () => (0, get_messages_1.getMessages)(this.context, sessionId, options));
41
82
  }
42
83
  /**
43
- * Append messages to a session in one transaction per chunk of up to 99
44
- * messages, keeping the session's `messageCount` exact. Lock-free and safe
45
- * under concurrent appends to one session; every message shares the
46
- * session's TTL when one is configured.
47
- * @throws ValidationError for a message that could never be read back; CompensationFailedError when a later chunk fails and the rollback fails too; RetryExhaustedError after 18 contended attempts; UpstreamError; AbortError.
84
+ * Append messages to a session.
85
+ *
86
+ * Accepts: `sessionId` — validated. `messages` — LangChain messages; an empty
87
+ * list writes nothing and is not an error. `options.signal` — aborts between
88
+ * chunks.
89
+ *
90
+ * Returns: nothing, and only once every message has landed.
91
+ *
92
+ * Throws: `VALIDATION` naming `messages`, for a value that is not itself
93
+ * an array, or, with the offending index, for an element that is not a
94
+ * message or one that could never be read back; or naming `signal` or
95
+ * `options.<key>` for a key this package does not read;
96
+ * `COMPENSATION_FAILED` when a later chunk fails and the rollback fails
97
+ * too; `RETRY_EXHAUSTED` after 18 contended attempts; a classified AWS failure;
98
+ * `ABORTED`.
99
+ *
100
+ * Guarantees: a caller observes all messages or none. One transaction per
101
+ * chunk of up to 99 keeps `messageCount` exact. Lock-free and safe under
102
+ * concurrent appends to one session; every message shares the session's TTL
103
+ * when one is configured.
48
104
  */
49
105
  addMessages(sessionId, messages, options) {
50
- return (0, boundary_1.guardPublic)('history.addMessages', () => (0, add_messages_1.addMessages)(this.context, sessionId, messages, options?.signal));
106
+ return (0, boundary_1.guardPublic)('history.addMessages', () => {
107
+ (0, collaborators_1.assertCancelOptions)(options);
108
+ return (0, add_messages_1.addMessages)(this.context, sessionId, messages, options?.signal);
109
+ });
51
110
  }
52
- /** Append one message; see {@link addMessages}. */
111
+ /**
112
+ * Append one message.
113
+ *
114
+ * Accepts: as {@link addMessages}, for a single message.
115
+ *
116
+ * Returns: nothing.
117
+ *
118
+ * Throws: as {@link addMessages}.
119
+ */
53
120
  addMessage(sessionId, message, options) {
54
- return (0, boundary_1.guardPublic)('history.addMessage', () => (0, add_messages_1.addMessages)(this.context, sessionId, [message], options?.signal));
121
+ return (0, boundary_1.guardPublic)('history.addMessage', () => {
122
+ (0, collaborators_1.assertCancelOptions)(options);
123
+ return (0, add_messages_1.addMessages)(this.context, sessionId, [message], options?.signal);
124
+ });
55
125
  }
56
126
  /**
57
- * Delete a session's messages, metadata and offloaded objects. Single pass:
58
- * call it when the session is quiescent.
59
- * @throws BatchWriteAllIncompleteError when a delete batch does not fully drain; UpstreamError; AbortError.
127
+ * Delete a session's messages, metadata and offloaded objects.
128
+ *
129
+ * Accepts: `sessionId` — validated. `options.signal` — aborts between pages.
130
+ *
131
+ * Returns: nothing. Clearing a session that does not exist is not an error.
132
+ *
133
+ * Throws: `VALIDATION` for a malformed session id, an invalid `signal`,
134
+ * or an `options.<key>` this package does not read;
135
+ * `BATCH_WRITE_INCOMPLETE` when a row's delete fails, counting rows
136
+ * rather than batches; a classified AWS failure; `ABORTED` when the signal fires,
137
+ * which is what a cancel surfaces as rather than an incomplete delete, even
138
+ * when it fires part-way through the pass. A row refused because it
139
+ * was rewritten after the partition read raises nothing: it is left in place,
140
+ * reported at `warn`, and counted as skipped.
141
+ *
142
+ * Guarantees: a row this adapter did not write is left in place and logged,
143
+ * and neither is a row rewritten since the read — an append landing during
144
+ * the call moves the session row's own write id, so that row survives with
145
+ * the session it belongs to instead of being removed under a live
146
+ * conversation. Single pass: call it when the session is quiescent, since a
147
+ * message appended while it runs may survive it, and the surviving session
148
+ * row then over-counts until `reconcileMessageCount` repairs it.
60
149
  */
61
150
  clear(sessionId, options) {
62
- return (0, boundary_1.guardPublic)('history.clear', () => (0, clear_1.clearSession)(this.context, sessionId, options));
151
+ return (0, boundary_1.guardPublic)('history.clear', () => {
152
+ (0, collaborators_1.assertCancelOptions)(options);
153
+ return (0, clear_1.clearSession)(this.context, sessionId, options);
154
+ });
63
155
  }
64
156
  /**
65
157
  * List every session as a metadata summary, most recently updated first.
66
- * A table scan: cross-tenant by construction and bounded by `maxItems` /
67
- * `maxIterations`.
68
- * @throws ResultTruncatedError past either cap; UpstreamError; AbortError.
158
+ * With a configured `indexName` this reads each index shard newest-first,
159
+ * merges the shards and pages by the opaque `nextCursor`. Without one it
160
+ * falls back to a filtered table scan — cross-tenant by construction,
161
+ * bounded by `maxItems` / `maxIterations`, and returning the newest `limit`
162
+ * sessions, or every session when no limit is given, with no cursor.
163
+ *
164
+ * Accepts: `options.limit` — an integer from 0 to `MAX_PAGE_LIMIT` (10,000);
165
+ * the page size with the index, the newest N without it, and `0` an empty
166
+ * page read from neither. `options.cursor` — from a previous page,
167
+ * and only with a configured `indexName`. `options.maxItems` /
168
+ * `maxIterations` — caps on the scan path. `options.signal` — aborts the
169
+ * reads.
170
+ *
171
+ * Returns: the page and, while rows may remain, a `nextCursor`. A page may
172
+ * come back shorter than `limit` while more rows remain: expired and foreign
173
+ * rows are dropped after the read. A cursor does not promise more rows:
174
+ * DynamoDB can end a shard's page at its last row and still return a key to
175
+ * continue from, and the page after such a cursor can come back empty. Stop
176
+ * when `nextCursor` is absent, never when a page looks short.
177
+ *
178
+ * Throws: `VALIDATION` naming `limit`, `cursor`, `maxItems`,
179
+ * `maxIterations`, `signal`, or `options.<key>` for a key this package does
180
+ * not read; `RESULT_TRUNCATED` past either cap on the scan path, or for an
181
+ * index shard whose pages do not end; `FORMAT_UNSUPPORTED` for a session row
182
+ * a newer release wrote; a classified AWS failure; `ABORTED`.
183
+ *
184
+ * Guarantees: with a configured `indexName` each shard is read one DynamoDB
185
+ * page at a time, and its next page whenever it has no row buffered and the
186
+ * page still needs one, so a shard can cost a query whose rows the page never
187
+ * takes; at most `readConcurrency` shards are queried at once. Memory is the
188
+ * page being built, up to `limit` rows and so bounded by
189
+ * `MAX_PAGE_LIMIT` (10,000), plus at most one DynamoDB page per shard,
190
+ * whatever the table holds.
69
191
  */
70
192
  listSessions(options) {
71
193
  return (0, boundary_1.guardPublic)('history.listSessions', () => (0, list_sessions_1.listSessions)(this.context, options));
@@ -73,39 +195,84 @@ class DynamoDBChatMessageHistory {
73
195
  /**
74
196
  * Recompute and repair a session's `messageCount` from the stored messages.
75
197
  * A maintenance tool for external corruption; run it when the session is idle.
76
- * @throws ConflictError when the session does not exist or changed while counting; UpstreamError; AbortError.
198
+ *
199
+ * Accepts: `sessionId` — validated, and an existing session.
200
+ * `options.signal` — aborts the reads.
201
+ *
202
+ * Returns: the count now stored, which is the number of messages a reader
203
+ * would see.
204
+ *
205
+ * Throws: `VALIDATION` for a malformed session id, an invalid `signal`,
206
+ * or an `options.<key>` this package does not read; `CONDITION_CONFLICT` when the
207
+ * session does not exist or stayed busy through every attempt;
208
+ * `FORMAT_UNSUPPORTED` for a message row a newer release wrote, and
209
+ * `VALIDATION` naming `message` for a row in the session's message key
210
+ * space that this adapter did not write, both of which `getMessages` refuses
211
+ * too — a count is a repair only while it agrees with the read;
212
+ * a classified AWS failure; `ABORTED`.
213
+ *
214
+ * Guarantees: safe on a live session — the write is pinned to the value the
215
+ * row held when the count was computed, so a concurrent append makes it
216
+ * recount instead of clobbering the increment.
77
217
  */
78
218
  reconcileMessageCount(sessionId, options) {
79
- return (0, boundary_1.guardPublic)('history.reconcileMessageCount', () => (0, reconcile_count_1.reconcileMessageCount)(this.context, sessionId, options?.signal));
219
+ return (0, boundary_1.guardPublic)('history.reconcileMessageCount', () => {
220
+ (0, collaborators_1.assertCancelOptions)(options);
221
+ return (0, reconcile_count_1.reconcileMessageCount)(this.context, sessionId, options?.signal);
222
+ });
80
223
  }
81
224
  /**
82
- * Get a single-session LangChain adapter for `sessionId`. `{ limit }` bounds
83
- * what the adapter feeds the chain to the newest `limit` messages.
225
+ * Get a single-session LangChain adapter for `sessionId`.
226
+ *
227
+ * Accepts: `sessionId` — validated by the adapter's own constructor, the
228
+ * same rule every other method applies. `window.limit` — bounds what the
229
+ * adapter feeds the chain to the newest that many messages; validated the
230
+ * same way.
231
+ *
232
+ * Returns: an adapter implementing `BaseListChatMessageHistory`, which is
233
+ * what `RunnableWithMessageHistory` takes.
234
+ *
235
+ * Throws: `VALIDATION` naming `sessionId`, `window` for a window that is
236
+ * not an object, `window.<key>` for a key the adapter does not declare, or
237
+ * `limit` — raised by the constructed adapter, so a bad id or window fails
238
+ * here rather than on first use.
84
239
  */
85
240
  forSession(sessionId, window) {
86
241
  return new session_adapter_1.DynamoDBSessionChatMessageHistory(this, sessionId, window);
87
242
  }
88
- /** Release owned resources (the underlying client and any S3 client). */
243
+ /**
244
+ * Release owned resources.
245
+ *
246
+ * Accepts: nothing.
247
+ *
248
+ * Returns: nothing. Idempotent, and a no-op for a client the caller injected
249
+ * — that one is theirs to close.
250
+ *
251
+ * Throws: whatever a resource's own `destroy` raises — but only after every
252
+ * other one has been released, so a client that fails to close never strands
253
+ * the one behind it.
254
+ */
89
255
  destroy() {
90
- this.context.offloader?.destroy();
91
- if (this.ownsClient)
92
- this.ddbClient?.destroy();
256
+ this.shell.release();
93
257
  }
94
258
  /**
95
259
  * Provision an S3 lifecycle expiration rule matching the configured TTL, so
96
- * offloaded objects don't outlive their DynamoDB item forever. No-ops when
97
- * S3 offload or TTL isn't configured; throws when the bucket cannot be read
98
- * or written. Requires the `s3:GetLifecycleConfiguration` /
99
- * `s3:PutLifecycleConfiguration` bucket-level permissions (broader than the
100
- * object-level CRUD the rest of S3 offload needs) — call this once during
101
- * deployment/provisioning, not per-request.
260
+ * offloaded objects don't outlive their DynamoDB item forever.
261
+ *
262
+ * Accepts: nothing; the rule follows the configured `s3` and `ttl`. A no-op
263
+ * without both.
264
+ *
265
+ * Returns: nothing. Installing a rule that is already there is a no-op too.
266
+ *
267
+ * Throws: `VALIDATION` naming `s3.keyPrefix` on a rule-id collision;
268
+ * a classified AWS failure when the bucket's lifecycle cannot be read or written.
269
+ * @remarks Requires the bucket-level `s3:GetLifecycleConfiguration` /
270
+ * `s3:PutLifecycleConfiguration` permissions, broader than the object-level
271
+ * CRUD the rest of S3 offload needs — call it once during provisioning, not
272
+ * per request.
102
273
  */
103
274
  async ensureS3LifecycleRule() {
104
- return (0, boundary_1.guardPublic)('history.ensureS3LifecycleRule', async () => {
105
- if (!this.context.offloader || !this.context.ttl)
106
- return;
107
- await this.context.offloader.ensureLifecycleRule((0, ttl_1.lifecycleExpirationDays)(this.context.ttl));
108
- });
275
+ return (0, boundary_1.guardPublic)('history.ensureS3LifecycleRule', () => this.shell.ensureLifecycleRule());
109
276
  }
110
277
  }
111
278
  exports.DynamoDBChatMessageHistory = DynamoDBChatMessageHistory;