@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,113 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.narrowMetaItem = narrowMetaItem;
4
- exports.narrowHead = narrowHead;
5
- exports.readCheckpoint = readCheckpoint;
6
- exports.readMetadata = readMetadata;
7
- exports.dropSupersededWrites = dropSupersededWrites;
8
- exports.toPendingWrites = toPendingWrites;
9
- const codec_1 = require("../../shared/codec/codec");
10
- const concurrency_1 = require("../../shared/concurrency");
11
- const constants_1 = require("../../shared/constants");
12
- const item_writer_1 = require("./item-writer");
13
- /**
14
- * Narrow a raw row to a {@link CheckpointMetaItem}, or `undefined` for a row
15
- * that merely shares the `META#` sort-key prefix. Replaces an unchecked cast
16
- * at the one boundary where a row may not have been written by this adapter.
17
- */
18
- function narrowMetaItem(raw) {
19
- return typeof raw.checkpointId === 'string' &&
20
- typeof raw.checkpointNs === 'string' &&
21
- raw.metadata !== undefined
22
- ? raw
23
- : undefined;
24
- }
25
- /**
26
- * Narrow a candidate head row, warning when a row that merely shares the
27
- * `META#` prefix is not a checkpoint meta item. Returning such a row used to
28
- * make `assembleTuple` miss its payload and report the thread as empty, so
29
- * LangGraph started a new run on top of the real history; a foreign row is
30
- * skipped and logged instead, exactly as `list()` treats it.
31
- */
32
- function narrowHead(context, raw) {
33
- if (raw === undefined)
34
- return undefined;
35
- const meta = narrowMetaItem(raw);
36
- if (!meta) {
37
- context.logger.warn('getTuple: skipped a row that is not a checkpoint meta item', {
38
- sortKey: raw.SK,
39
- });
40
- }
41
- return meta;
42
- }
43
- /**
44
- * Decode the checkpoint stored in a PAYLOAD item. `threadId` is the caller's
45
- * (from the config), never the row's: it scopes which S3 object the row may
46
- * point at, so it must come from the partition the caller asked for.
47
- */
48
- async function readCheckpoint(context, item, threadId) {
49
- return (0, codec_1.decodePayload)(item.checkpoint, (0, item_writer_1.codecDeps)(context), [threadId]);
50
- }
51
- /** Decode the metadata stored in a META item; see {@link readCheckpoint} for `threadId`. */
52
- async function readMetadata(context, item, threadId) {
53
- return (0, codec_1.decodePayload)(item.metadata, (0, item_writer_1.codecDeps)(context), [threadId]);
54
- }
55
- /**
56
- * Drop rows a later `putWrites` call added for a task and channel an earlier
57
- * call had already committed.
58
- *
59
- * A regular write's index is its position in the caller's array, so a retried
60
- * task whose write mix changed can place an already-committed channel at a
61
- * second index — a new row, which would replay that channel's value twice. For
62
- * an accumulating channel (a `messages` add-reducer, a Topic) that
63
- * double-counts. Every row carries the `writeGroup` of the call that wrote it,
64
- * which distinguishes that case from a channel a *single* call legitimately
65
- * wrote more than once (a task emitting two Sends), where both values must
66
- * survive.
67
- *
68
- * Write groups are time-ordered ULIDs, so the smallest one for a `(task,
69
- * channel)` pair identifies the earliest committed call — first-write-wins,
70
- * the same rule the write-side guard applies, extended to the case the guard
71
- * cannot see. Selecting by *order encountered* would not do: rows arrive
72
- * sorted by index, and a retry emitting fewer writes moves an
73
- * already-committed channel to a smaller index, where it sorts ahead of the
74
- * original row and would hand back the later call's value instead. The
75
- * superseded row stays in DynamoDB and is removed by `deleteThread` or TTL
76
- * like any other.
77
- *
78
- * Identity is `(task, channel, occurrence)`, not `(task, channel)`. Keying on
79
- * the channel alone treated *any* second row for a channel as a superseding
80
- * duplicate — including one a retry added at an occurrence no earlier call had
81
- * ever written, which the write-side guard accepted cleanly. That row was then
82
- * discarded on read, silently returning fewer values than were written, with
83
- * `putWrites()` having reported success. For that specific shape — a retry
84
- * that legitimately emits a channel *more* often than the original call —
85
- * keeping the occurrence restores the upstream outcome: `MemorySaver` keys
86
- * first-write-wins on `(taskId, idx)`, so a grown retry keeps both values
87
- * there too. That is not a claim of parity in general: a retry that reorders
88
- * or shrinks its writes is still resolved to the earliest call per `(task,
89
- * channel, occurrence)` as above, which is what keeps an accumulating channel
90
- * from being double-counted — a case `MemorySaver` does not have to handle.
91
- */
92
- function dropSupersededWrites(items) {
93
- const identity = (item) => JSON.stringify([item.taskId, item.channel, item.occurrence ?? 0]);
94
- const earliestGroup = new Map();
95
- for (const item of items) {
96
- const id = identity(item);
97
- const seen = earliestGroup.get(id);
98
- if (seen === undefined || item.writeGroup < seen)
99
- earliestGroup.set(id, item.writeGroup);
100
- }
101
- return items.filter((item) => earliestGroup.get(identity(item)) === item.writeGroup);
102
- }
103
- /** Decode WRITE items into `[taskId, channel, value]` pending-write tuples. */
104
- async function toPendingWrites(context, items, threadId) {
105
- const deps = (0, item_writer_1.codecDeps)(context);
106
- const live = dropSupersededWrites(items);
107
- const values = await (0, concurrency_1.mapWithConcurrency)(live, constants_1.DEFAULT_READ_CONCURRENCY, (item) => (0, codec_1.decodePayload)(item.value, deps, [threadId]));
108
- return live.map((item, index) => [
109
- item.taskId,
110
- item.channel,
111
- values[index],
112
- ]);
113
- }
@@ -1,35 +0,0 @@
1
- import type { Checkpoint, CheckpointMetadata, PendingWrite } from '@langchain/langgraph-checkpoint';
2
- import { type CodecDeps } from '../../shared/codec/codec';
3
- import type { CheckpointMetaItem, CheckpointPayloadItem, CheckpointWriteItem } from '../types';
4
- import type { CheckpointerContext } from './setup';
5
- /** Map a context to the codec collaborators. */
6
- export declare function codecDeps(context: CheckpointerContext): CodecDeps;
7
- /**
8
- * Encode a checkpoint + metadata into its META and PAYLOAD items. `nonce` is
9
- * unique per `put()` call and is appended to both S3 key part lists, so a
10
- * second put of the same checkpoint id — a retry after a lost response, or a
11
- * repair tool re-writing a checkpoint — never shares an object with the first.
12
- * That is what makes "the row holds my key" equivalent to "my write is live"
13
- * for the post-failure verification in `put.ts`, and what keeps a failed
14
- * re-put's cleanup from deleting the object the first, successful put's rows
15
- * point at. `storedChannels` narrows the stored `channel_values` (see
16
- * `selectStoredChannels`); by default every value is stored.
17
- */
18
- export declare function buildCheckpointItems(context: CheckpointerContext, threadId: string, checkpointNs: string, checkpoint: Checkpoint, metadata: CheckpointMetadata, nonce: string, parentCheckpointId?: string, ttlTimestamp?: number, storedChannels?: readonly string[]): Promise<{
19
- meta: CheckpointMetaItem;
20
- payload: CheckpointPayloadItem;
21
- }>;
22
- /**
23
- * Encode a task's pending writes into one item per write. `nonce` must be
24
- * unique per `putWrites` *call* (not per write) and is appended to every
25
- * write's S3 offload keyParts — regular and special alike — so a repeated
26
- * write (a retried task re-emitting the same channel, or two calls to the
27
- * same special channel) never shares an S3 location with any earlier
28
- * attempt. Special (negative-index) writes still overwrite their DynamoDB
29
- * row in place (see {@link writeSpecialItemsWithCleanup}), but that
30
- * overwrite-safety now comes from reading the previous descriptor before
31
- * writing and only cleaning it up after the new row is confirmed committed —
32
- * the same pattern store/actions/put.ts uses for the identical "overwrite in
33
- * place, nonce every upload" shape.
34
- */
35
- export declare function buildWriteItems(context: CheckpointerContext, threadId: string, checkpointNs: string, checkpointId: string, taskId: string, writes: PendingWrite[], nonce: string, ttlTimestamp?: number): Promise<CheckpointWriteItem[]>;
@@ -1,107 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.codecDeps = codecDeps;
4
- exports.buildCheckpointItems = buildCheckpointItems;
5
- exports.buildWriteItems = buildWriteItems;
6
- const encode_1 = require("../../shared/codec/encode");
7
- const keys_1 = require("./keys");
8
- const stored_channels_1 = require("./stored-channels");
9
- const validation_1 = require("./validation");
10
- const write_index_1 = require("./write-index");
11
- /** Map a context to the codec collaborators. */
12
- function codecDeps(context) {
13
- return { serde: context.serde, compression: context.compression, offloader: context.offloader };
14
- }
15
- function withTtl(item, ttlTimestamp) {
16
- if (ttlTimestamp !== undefined)
17
- item.ttl = ttlTimestamp;
18
- return item;
19
- }
20
- /**
21
- * Encode a checkpoint + metadata into its META and PAYLOAD items. `nonce` is
22
- * unique per `put()` call and is appended to both S3 key part lists, so a
23
- * second put of the same checkpoint id — a retry after a lost response, or a
24
- * repair tool re-writing a checkpoint — never shares an object with the first.
25
- * That is what makes "the row holds my key" equivalent to "my write is live"
26
- * for the post-failure verification in `put.ts`, and what keeps a failed
27
- * re-put's cleanup from deleting the object the first, successful put's rows
28
- * point at. `storedChannels` narrows the stored `channel_values` (see
29
- * `selectStoredChannels`); by default every value is stored.
30
- */
31
- async function buildCheckpointItems(context, threadId, checkpointNs, checkpoint, metadata, nonce, parentCheckpointId, ttlTimestamp, storedChannels = Object.keys(checkpoint.channel_values)) {
32
- const deps = codecDeps(context);
33
- const pk = (0, keys_1.partitionKey)(threadId);
34
- const checkpointDescriptor = await (0, encode_1.encodePayload)((0, stored_channels_1.withStoredChannels)(checkpoint, storedChannels), deps, {
35
- keyParts: [threadId, checkpointNs, checkpoint.id, 'checkpoint', nonce],
36
- });
37
- const metadataDescriptor = await (0, encode_1.encodePayload)(metadata, deps, {
38
- keyParts: [threadId, checkpointNs, checkpoint.id, 'metadata', nonce],
39
- });
40
- const meta = {
41
- PK: pk,
42
- SK: (0, keys_1.metaSortKey)(checkpointNs, checkpoint.id),
43
- threadId,
44
- checkpointNs,
45
- checkpointId: checkpoint.id,
46
- metadata: metadataDescriptor,
47
- storedChannels: [...storedChannels],
48
- };
49
- if (parentCheckpointId !== undefined)
50
- meta.parentCheckpointId = parentCheckpointId;
51
- const payload = {
52
- PK: pk,
53
- SK: (0, keys_1.payloadSortKey)(checkpointNs, checkpoint.id),
54
- checkpoint: checkpointDescriptor,
55
- };
56
- return { meta: withTtl(meta, ttlTimestamp), payload: withTtl(payload, ttlTimestamp) };
57
- }
58
- /**
59
- * Encode a task's pending writes into one item per write. `nonce` must be
60
- * unique per `putWrites` *call* (not per write) and is appended to every
61
- * write's S3 offload keyParts — regular and special alike — so a repeated
62
- * write (a retried task re-emitting the same channel, or two calls to the
63
- * same special channel) never shares an S3 location with any earlier
64
- * attempt. Special (negative-index) writes still overwrite their DynamoDB
65
- * row in place (see {@link writeSpecialItemsWithCleanup}), but that
66
- * overwrite-safety now comes from reading the previous descriptor before
67
- * writing and only cleaning it up after the new row is confirmed committed —
68
- * the same pattern store/actions/put.ts uses for the identical "overwrite in
69
- * place, nonce every upload" shape.
70
- */
71
- async function buildWriteItems(context, threadId, checkpointNs, checkpointId, taskId, writes, nonce, ttlTimestamp) {
72
- /** Reject a bad channel before any payload is encoded or uploaded. */
73
- for (const [channel] of writes)
74
- (0, validation_1.validateChannel)(channel);
75
- const deps = codecDeps(context);
76
- const pk = (0, keys_1.partitionKey)(threadId);
77
- const items = [];
78
- for (const { channel, value, index, occurrence } of (0, write_index_1.resolveWriteIndices)(writes)) {
79
- /**
80
- * `channel` is part of the key as well as the index: two channels can
81
- * share an index (each channel's first occurrence is 0), so without it
82
- * their uploads would collide on one S3 object within a single call.
83
- */
84
- const descriptor = await (0, encode_1.encodePayload)(value, deps, {
85
- keyParts: [threadId, checkpointNs, checkpointId, taskId, `write-${index}`, channel, nonce],
86
- });
87
- const item = {
88
- PK: pk,
89
- SK: (0, keys_1.writeSortKey)(checkpointNs, checkpointId, taskId, index, channel),
90
- taskId,
91
- index,
92
- channel,
93
- /**
94
- * Shared by every row this call writes. Positions shift when a retried
95
- * task's write mix changes, so a channel an earlier call already
96
- * committed can land at a second index and be replayed twice; the group
97
- * is what lets the read side tell that apart from a channel a single
98
- * call legitimately wrote more than once.
99
- */
100
- writeGroup: nonce,
101
- occurrence,
102
- value: descriptor,
103
- };
104
- items.push(withTtl(item, ttlTimestamp));
105
- }
106
- return items;
107
- }
@@ -1,41 +0,0 @@
1
- /** Reserved separator joining sort-key segments; forbidden inside any segment. */
2
- export declare const SORT_KEY_SEPARATOR = "#";
3
- /**
4
- * The most negative write index the sort key can encode, `-WRITE_INDEX_OFFSET`.
5
- * A static test pins it against the peer's `WRITES_IDX_MAP`, so a peer bump
6
- * that adds a more negative special slot fails loudly instead of producing
7
- * unsortable keys.
8
- */
9
- export declare const MIN_ENCODABLE_WRITE_INDEX: number;
10
- /** The tag every checkpointer partition key starts with, for a table-wide `begins_with`. */
11
- export declare function checkpointerPartitionPrefix(): string;
12
- /** Partition key for a thread: the adapter tag plus the thread id. */
13
- export declare function partitionKey(threadId: string): string;
14
- /** Sort key for a checkpoint's lightweight metadata item. */
15
- export declare function metaSortKey(checkpointNs: string, checkpointId: string): string;
16
- /** `begins_with` prefix selecting every META item in a namespace (for list). */
17
- export declare function metaSortKeyPrefix(checkpointNs: string): string;
18
- /** `begins_with` prefix selecting every META item of a thread, whatever its namespace. */
19
- export declare function metaAnyNamespacePrefix(): string;
20
- /** Sort key for a checkpoint's heavy payload item. */
21
- export declare function payloadSortKey(checkpointNs: string, checkpointId: string): string;
22
- /**
23
- * Sort key for a single pending write. The trailing `channel` segment is what
24
- * keeps two *different* channels from ever occupying one row: without it, a
25
- * retried task whose write mix changed could compute an index another
26
- * channel already holds, and the first-write-wins guard — which cannot tell a
27
- * genuine retry from an unrelated write — would silently discard it. The
28
- * channel is appended verbatim as the final segment, so two sort keys collide
29
- * only when their channels are byte-identical; `writeSortKeyPrefix` stops at
30
- * the checkpoint id, ahead of this segment, so `begins_with` reads are
31
- * unaffected.
32
- */
33
- export declare function writeSortKey(checkpointNs: string, checkpointId: string, taskId: string, index: number, channel: string): string;
34
- /**
35
- * True when `sortKey` is one this adapter writes. A partition query carries no
36
- * sort-key condition, so a partition-wide delete uses this to leave any row it
37
- * does not own in place rather than deleting the whole partition blindly.
38
- */
39
- export declare function isCheckpointerSortKey(sortKey: string): boolean;
40
- /** `begins_with` prefix selecting every WRITE item for one checkpoint. */
41
- export declare function writeSortKeyPrefix(checkpointNs: string, checkpointId: string): string;
@@ -1,117 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.MIN_ENCODABLE_WRITE_INDEX = exports.SORT_KEY_SEPARATOR = void 0;
4
- exports.checkpointerPartitionPrefix = checkpointerPartitionPrefix;
5
- exports.partitionKey = partitionKey;
6
- exports.metaSortKey = metaSortKey;
7
- exports.metaSortKeyPrefix = metaSortKeyPrefix;
8
- exports.metaAnyNamespacePrefix = metaAnyNamespacePrefix;
9
- exports.payloadSortKey = payloadSortKey;
10
- exports.writeSortKey = writeSortKey;
11
- exports.isCheckpointerSortKey = isCheckpointerSortKey;
12
- exports.writeSortKeyPrefix = writeSortKeyPrefix;
13
- const constants_1 = require("../../shared/constants");
14
- const errors_1 = require("../../shared/errors/errors");
15
- /** Reserved separator joining sort-key segments; forbidden inside any segment. */
16
- exports.SORT_KEY_SEPARATOR = '#';
17
- /** Fixed digit width for the WRITE index so sort keys order numerically. */
18
- const WRITE_INDEX_PAD_WIDTH = 10;
19
- /**
20
- * Added to every write index before padding so the special negative slots from
21
- * `WRITES_IDX_MAP` (-1 ERROR .. -4 RESUME) encode as non-negative, sortable
22
- * integers that order below positional (0+) writes.
23
- */
24
- const WRITE_INDEX_OFFSET = 8;
25
- /**
26
- * The most negative write index the sort key can encode, `-WRITE_INDEX_OFFSET`.
27
- * A static test pins it against the peer's `WRITES_IDX_MAP`, so a peer bump
28
- * that adds a more negative special slot fails loudly instead of producing
29
- * unsortable keys.
30
- */
31
- exports.MIN_ENCODABLE_WRITE_INDEX = -WRITE_INDEX_OFFSET;
32
- /** Sort-key kinds for the checkpoints table (the approved SK separation). */
33
- var CheckpointItemKind;
34
- (function (CheckpointItemKind) {
35
- CheckpointItemKind["META"] = "META";
36
- CheckpointItemKind["PAYLOAD"] = "PAYLOAD";
37
- CheckpointItemKind["WRITE"] = "WRITE";
38
- })(CheckpointItemKind || (CheckpointItemKind = {}));
39
- /**
40
- * Adapter tag prefixed to every checkpointer partition key. Without it a
41
- * `thread_id` reused as a `sessionId` or a store namespace root — an ordinary
42
- * design choice — put all three adapters' rows in one partition on a table
43
- * shared via `DynamoDBFactory.createAll()`, where a partition-wide delete
44
- * reached another adapter's data and composed sort keys could collide
45
- * byte-for-byte. The three tags differ in their first character, so the key
46
- * spaces are disjoint by construction.
47
- */
48
- const ADAPTER_PARTITION_PREFIX = `CHKPT${exports.SORT_KEY_SEPARATOR}`;
49
- /** The tag every checkpointer partition key starts with, for a table-wide `begins_with`. */
50
- function checkpointerPartitionPrefix() {
51
- return ADAPTER_PARTITION_PREFIX;
52
- }
53
- /** Partition key for a thread: the adapter tag plus the thread id. */
54
- function partitionKey(threadId) {
55
- return `${ADAPTER_PARTITION_PREFIX}${threadId}`;
56
- }
57
- /** Sort key for a checkpoint's lightweight metadata item. */
58
- function metaSortKey(checkpointNs, checkpointId) {
59
- return `${CheckpointItemKind.META}${exports.SORT_KEY_SEPARATOR}${checkpointNs}${exports.SORT_KEY_SEPARATOR}${checkpointId}`;
60
- }
61
- /** `begins_with` prefix selecting every META item in a namespace (for list). */
62
- function metaSortKeyPrefix(checkpointNs) {
63
- return `${CheckpointItemKind.META}${exports.SORT_KEY_SEPARATOR}${checkpointNs}${exports.SORT_KEY_SEPARATOR}`;
64
- }
65
- /** `begins_with` prefix selecting every META item of a thread, whatever its namespace. */
66
- function metaAnyNamespacePrefix() {
67
- return `${CheckpointItemKind.META}${exports.SORT_KEY_SEPARATOR}`;
68
- }
69
- /** Sort key for a checkpoint's heavy payload item. */
70
- function payloadSortKey(checkpointNs, checkpointId) {
71
- return `${CheckpointItemKind.PAYLOAD}${exports.SORT_KEY_SEPARATOR}${checkpointNs}${exports.SORT_KEY_SEPARATOR}${checkpointId}`;
72
- }
73
- /**
74
- * Sort key for a single pending write. The trailing `channel` segment is what
75
- * keeps two *different* channels from ever occupying one row: without it, a
76
- * retried task whose write mix changed could compute an index another
77
- * channel already holds, and the first-write-wins guard — which cannot tell a
78
- * genuine retry from an unrelated write — would silently discard it. The
79
- * channel is appended verbatim as the final segment, so two sort keys collide
80
- * only when their channels are byte-identical; `writeSortKeyPrefix` stops at
81
- * the checkpoint id, ahead of this segment, so `begins_with` reads are
82
- * unaffected.
83
- */
84
- function writeSortKey(checkpointNs, checkpointId, taskId, index, channel) {
85
- const offsetIndex = index + WRITE_INDEX_OFFSET;
86
- if (offsetIndex < 0 || offsetIndex.toString().length > WRITE_INDEX_PAD_WIDTH) {
87
- throw new errors_1.ValidationError(`write index ${index} is outside the range encodable at offset ${WRITE_INDEX_OFFSET} ` +
88
- `with ${WRITE_INDEX_PAD_WIDTH} digits`, 'index');
89
- }
90
- const paddedIndex = offsetIndex.toString().padStart(WRITE_INDEX_PAD_WIDTH, '0');
91
- const sortKey = [
92
- CheckpointItemKind.WRITE,
93
- checkpointNs,
94
- checkpointId,
95
- taskId,
96
- paddedIndex,
97
- channel,
98
- ].join(exports.SORT_KEY_SEPARATOR);
99
- const bytes = Buffer.byteLength(sortKey, 'utf8');
100
- if (bytes > constants_1.MAX_SORT_KEY_BYTES) {
101
- throw new errors_1.ValidationError(`checkpoint_ns, checkpoint_id, taskId and channel compose a ${bytes}-byte sort key; ` +
102
- `DynamoDB caps sort keys at ${constants_1.MAX_SORT_KEY_BYTES} bytes`, 'sortKey');
103
- }
104
- return sortKey;
105
- }
106
- /**
107
- * True when `sortKey` is one this adapter writes. A partition query carries no
108
- * sort-key condition, so a partition-wide delete uses this to leave any row it
109
- * does not own in place rather than deleting the whole partition blindly.
110
- */
111
- function isCheckpointerSortKey(sortKey) {
112
- return Object.values(CheckpointItemKind).some((kind) => sortKey.startsWith(`${kind}${exports.SORT_KEY_SEPARATOR}`));
113
- }
114
- /** `begins_with` prefix selecting every WRITE item for one checkpoint. */
115
- function writeSortKeyPrefix(checkpointNs, checkpointId) {
116
- return `${CheckpointItemKind.WRITE}${exports.SORT_KEY_SEPARATOR}${checkpointNs}${exports.SORT_KEY_SEPARATOR}${checkpointId}${exports.SORT_KEY_SEPARATOR}`;
117
- }
@@ -1,61 +0,0 @@
1
- import type { QueryCommandInput, ScanCommandInput } from '@aws-sdk/lib-dynamodb';
2
- import type { RunnableConfig } from '@langchain/core/runnables';
3
- import type { CheckpointListOptions, CheckpointMetadata } from '@langchain/langgraph-checkpoint';
4
- import type { CheckpointMetaItem } from '../types';
5
- import { type FilterValue } from './filter-match';
6
- import type { CheckpointerContext } from './setup';
7
- /** What one `list()` call covers, read once from its config and options. */
8
- export interface ListScope {
9
- /** Undefined when the caller gave no `thread_id`: every thread in the table is listed. */
10
- threadId: string | undefined;
11
- /** Undefined when the caller gave no `checkpoint_ns`: every namespace of the thread is listed. */
12
- checkpointNs: string | undefined;
13
- checkpointId: string | undefined;
14
- before: string | undefined;
15
- filter: Record<string, FilterValue> | undefined;
16
- limit: number | undefined;
17
- signal: AbortSignal | undefined;
18
- }
19
- /**
20
- * Read the scope. Unlike `getTuple`, which addresses the root namespace when
21
- * none is given, `list()` without a `checkpoint_ns` covers every namespace,
22
- * and without a `thread_id` every thread, as the reference savers do; the
23
- * identifiers that are given are validated either way.
24
- */
25
- export declare function readListScope(config: RunnableConfig, options?: CheckpointListOptions): ListScope;
26
- /**
27
- * The META query for a scope. A metadata filter means rows may be dropped
28
- * client-side, so only an unfiltered list passes the caller's limit through as
29
- * the page size. With an explicit namespace `before` bounds the key range so
30
- * rows newer than it are never read; across namespaces ids do not share one
31
- * order and `before` is applied in-process.
32
- */
33
- export declare function listQuery(context: CheckpointerContext, scope: ListScope & {
34
- threadId: string;
35
- }): QueryCommandInput;
36
- /**
37
- * The table `Scan` a thread-less `list()` runs: every checkpointer META row,
38
- * narrowed to one namespace when the caller gave one. It is what the
39
- * reference savers do for a config without a thread, and on DynamoDB it costs
40
- * a read of the whole table.
41
- */
42
- export declare function listScan(context: CheckpointerContext, scope: ListScope): ScanCommandInput;
43
- /**
44
- * True when `meta` passes the key-level filters: strictly older than `before`,
45
- * and — on a table scan, where the key condition cannot narrow them — in the
46
- * requested namespace and, when one is given, the requested checkpoint.
47
- */
48
- export declare function passesKeyFilters(meta: CheckpointMetaItem, scope: ListScope): boolean;
49
- /** Outcome of the metadata filter: rejected, or accepted with any metadata decoded on the way. */
50
- export type MetadataVerdict = {
51
- pass: false;
52
- } | {
53
- pass: true;
54
- metadata?: CheckpointMetadata;
55
- };
56
- /**
57
- * Apply the optional metadata-equality filter. The metadata decoded here is
58
- * handed to the tuple assembly, so a filtered list decodes (and, when offloaded,
59
- * downloads) each metadata blob once instead of twice.
60
- */
61
- export declare function passesMetadataFilter(context: CheckpointerContext, meta: CheckpointMetaItem, scope: ListScope): Promise<MetadataVerdict>;
@@ -1,108 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.readListScope = readListScope;
4
- exports.listQuery = listQuery;
5
- exports.listScan = listScan;
6
- exports.passesKeyFilters = passesKeyFilters;
7
- exports.passesMetadataFilter = passesMetadataFilter;
8
- const configurable_1 = require("./configurable");
9
- const filter_match_1 = require("./filter-match");
10
- const item_reader_1 = require("./item-reader");
11
- const keys_1 = require("./keys");
12
- const query_1 = require("./query");
13
- const validation_1 = require("./validation");
14
- /** The identifiers of a config that names no thread, validated the same way. */
15
- function readThreadless(config) {
16
- const checkpointNs = config.configurable?.checkpoint_ns ?? '';
17
- (0, validation_1.validateCheckpointNs)(checkpointNs);
18
- const rawId = config.configurable?.checkpoint_id;
19
- const checkpointId = rawId ? rawId : undefined;
20
- if (checkpointId !== undefined)
21
- (0, validation_1.validateCheckpointId)(checkpointId);
22
- return { threadId: '', checkpointNs, checkpointId };
23
- }
24
- /** The identifiers a list config names; a config without a thread is still validated for the ids it gives. */
25
- function resolveListIds(config) {
26
- if (config.configurable?.thread_id === undefined) {
27
- return { ...readThreadless(config), threadId: undefined };
28
- }
29
- return (0, configurable_1.readConfigurable)(config);
30
- }
31
- /**
32
- * Read the scope. Unlike `getTuple`, which addresses the root namespace when
33
- * none is given, `list()` without a `checkpoint_ns` covers every namespace,
34
- * and without a `thread_id` every thread, as the reference savers do; the
35
- * identifiers that are given are validated either way.
36
- */
37
- function readListScope(config, options) {
38
- const { threadId, checkpointNs, checkpointId } = resolveListIds(config);
39
- return {
40
- threadId,
41
- checkpointNs: config.configurable?.checkpoint_ns === undefined ? undefined : checkpointNs,
42
- checkpointId,
43
- before: options?.before?.configurable?.checkpoint_id,
44
- filter: options?.filter,
45
- limit: options?.limit,
46
- signal: config.signal,
47
- };
48
- }
49
- /**
50
- * The META query for a scope. A metadata filter means rows may be dropped
51
- * client-side, so only an unfiltered list passes the caller's limit through as
52
- * the page size. With an explicit namespace `before` bounds the key range so
53
- * rows newer than it are never read; across namespaces ids do not share one
54
- * order and `before` is applied in-process.
55
- */
56
- function listQuery(context, scope) {
57
- const partition = (0, keys_1.partitionKey)(scope.threadId);
58
- const limit = scope.filter === undefined ? scope.limit : undefined;
59
- if (scope.checkpointNs === undefined) {
60
- return (0, query_1.beginsWithQuery)(context.tableName, partition, (0, keys_1.metaAnyNamespacePrefix)(), { limit });
61
- }
62
- return (0, query_1.beginsWithQuery)(context.tableName, partition, (0, keys_1.metaSortKeyPrefix)(scope.checkpointNs), {
63
- limit,
64
- beforeSortKey: scope.before === undefined ? undefined : (0, keys_1.metaSortKey)(scope.checkpointNs, scope.before),
65
- });
66
- }
67
- /**
68
- * The table `Scan` a thread-less `list()` runs: every checkpointer META row,
69
- * narrowed to one namespace when the caller gave one. It is what the
70
- * reference savers do for a config without a thread, and on DynamoDB it costs
71
- * a read of the whole table.
72
- */
73
- function listScan(context, scope) {
74
- return {
75
- TableName: context.tableName,
76
- FilterExpression: 'begins_with(#pk, :pk) AND begins_with(#sk, :sk)',
77
- ExpressionAttributeNames: { '#pk': 'PK', '#sk': 'SK' },
78
- ExpressionAttributeValues: {
79
- ':pk': (0, keys_1.checkpointerPartitionPrefix)(),
80
- ':sk': scope.checkpointNs === undefined
81
- ? (0, keys_1.metaAnyNamespacePrefix)()
82
- : (0, keys_1.metaSortKeyPrefix)(scope.checkpointNs),
83
- },
84
- };
85
- }
86
- /**
87
- * True when `meta` passes the key-level filters: strictly older than `before`,
88
- * and — on a table scan, where the key condition cannot narrow them — in the
89
- * requested namespace and, when one is given, the requested checkpoint.
90
- */
91
- function passesKeyFilters(meta, scope) {
92
- return ((scope.before === undefined || meta.checkpointId < scope.before) &&
93
- (scope.checkpointNs === undefined || meta.checkpointNs === scope.checkpointNs) &&
94
- (scope.checkpointId === undefined || meta.checkpointId === scope.checkpointId));
95
- }
96
- /**
97
- * Apply the optional metadata-equality filter. The metadata decoded here is
98
- * handed to the tuple assembly, so a filtered list decodes (and, when offloaded,
99
- * downloads) each metadata blob once instead of twice.
100
- */
101
- async function passesMetadataFilter(context, meta, scope) {
102
- if (!scope.filter)
103
- return { pass: true };
104
- const metadata = await (0, item_reader_1.readMetadata)(context, meta, meta.threadId);
105
- return (0, filter_match_1.matchesFilter)(metadata, scope.filter)
106
- ? { pass: true, metadata }
107
- : { pass: false };
108
- }
@@ -1,13 +0,0 @@
1
- import { type Checkpoint } from '@langchain/langgraph-checkpoint';
2
- import { type ReadOptions } from './fetch';
3
- import type { CheckpointerContext } from './setup';
4
- /**
5
- * Pre-v4 checkpoints kept a task's `Send`s as `__pregel_tasks` pending writes
6
- * on the parent rather than in the checkpoint itself. Reading such a
7
- * checkpoint rebuilds `channel_values[TASKS]` from those writes and stamps
8
- * the channel with the highest version the checkpoint already carries (or
9
- * the first version when it carries none), exactly as the reference savers
10
- * do, so a thread written before LangGraph 0.2 still resumes. A v4 checkpoint,
11
- * or one without a parent, is returned untouched.
12
- */
13
- export declare function migratePendingSends(context: CheckpointerContext, checkpoint: Checkpoint, threadId: string, checkpointNs: string, parentCheckpointId: string | undefined, read: ReadOptions): Promise<Checkpoint>;
@@ -1,29 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.migratePendingSends = migratePendingSends;
4
- const langgraph_checkpoint_1 = require("@langchain/langgraph-checkpoint");
5
- const fetch_1 = require("./fetch");
6
- /**
7
- * Pre-v4 checkpoints kept a task's `Send`s as `__pregel_tasks` pending writes
8
- * on the parent rather than in the checkpoint itself. Reading such a
9
- * checkpoint rebuilds `channel_values[TASKS]` from those writes and stamps
10
- * the channel with the highest version the checkpoint already carries (or
11
- * the first version when it carries none), exactly as the reference savers
12
- * do, so a thread written before LangGraph 0.2 still resumes. A v4 checkpoint,
13
- * or one without a parent, is returned untouched.
14
- */
15
- async function migratePendingSends(context, checkpoint, threadId, checkpointNs, parentCheckpointId, read) {
16
- if (checkpoint.v >= 4 || parentCheckpointId === undefined)
17
- return checkpoint;
18
- const writes = await (0, fetch_1.fetchPendingWrites)(context, threadId, checkpointNs, parentCheckpointId, read);
19
- const sends = writes.filter(([, channel]) => channel === langgraph_checkpoint_1.TASKS).map(([, , value]) => value);
20
- const versions = Object.values(checkpoint.channel_versions);
21
- return {
22
- ...checkpoint,
23
- channel_values: { ...checkpoint.channel_values, [langgraph_checkpoint_1.TASKS]: sends },
24
- channel_versions: {
25
- ...checkpoint.channel_versions,
26
- [langgraph_checkpoint_1.TASKS]: versions.length > 0 ? (0, langgraph_checkpoint_1.maxChannelVersion)(...versions) : 1,
27
- },
28
- };
29
- }
@@ -1,21 +0,0 @@
1
- import type { QueryCommandInput } from '@aws-sdk/lib-dynamodb';
2
- /** Options for {@link partitionQuery}. */
3
- export interface PartitionQueryOptions {
4
- consistent?: boolean;
5
- }
6
- /** Options for {@link beginsWithQuery}. */
7
- export interface BeginsWithQueryOptions {
8
- limit?: number;
9
- /** Inclusive upper bound on the sort key; turns the prefix match into a `BETWEEN`. */
10
- beforeSortKey?: string;
11
- ascending?: boolean;
12
- consistent?: boolean;
13
- }
14
- /** Build a Query input selecting every item in a partition (all sort keys). */
15
- export declare function partitionQuery(tableName: string, partition: string, options?: PartitionQueryOptions): QueryCommandInput;
16
- /**
17
- * Build a Query input selecting items whose partition equals `partition` and
18
- * whose sort key begins with `skPrefix`. Names are aliased so reserved words
19
- * never appear bare. Defaults to newest-first ordering.
20
- */
21
- export declare function beginsWithQuery(tableName: string, partition: string, skPrefix: string, options?: BeginsWithQueryOptions): QueryCommandInput;