@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,17 +0,0 @@
1
- /**
2
- * Default retryable transient signals. TransactionCanceledException is
3
- * intentionally absent (its reasons include permanent failures);
4
- * TransactionConflictException (transient row contention) IS retryable.
5
- */
6
- export declare const DEFAULT_RETRYABLE_ERRORS: readonly string[];
7
- /**
8
- * True when `error` (or any cause in its chain) is transient: a transaction
9
- * cancellation whose every reason is transient (that verdict takes precedence,
10
- * because a permanent reason arrives with the same statuses as a transient
11
- * one), an HTTP status in {@link TRANSIENT_HTTP_STATUSES}, the SDK's
12
- * `$retryable` trait, or an exact match of a `name`/`code`/`errno`/`syscall`
13
- * token against `retryableErrors`. Exact, not substring: the fields are
14
- * whole tokens, and a substring rule would let an unrelated name that merely
15
- * contains one ride along.
16
- */
17
- export declare function isRetryableError(error: Error, retryableErrors: readonly string[]): boolean;
@@ -1,118 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DEFAULT_RETRYABLE_ERRORS = void 0;
4
- exports.isRetryableError = isRetryableError;
5
- const cancellation_1 = require("./cancellation");
6
- const MAX_CAUSE_DEPTH = 32;
7
- /**
8
- * Default retryable transient signals. TransactionCanceledException is
9
- * intentionally absent (its reasons include permanent failures);
10
- * TransactionConflictException (transient row contention) IS retryable.
11
- */
12
- exports.DEFAULT_RETRYABLE_ERRORS = [
13
- 'ProvisionedThroughputExceededException',
14
- 'ThrottlingException',
15
- 'RequestLimitExceeded',
16
- 'InternalServerError',
17
- 'ServiceUnavailable',
18
- 'TransactionConflictException',
19
- 'TransactionInProgressException',
20
- 'RequestTimeout',
21
- 'RequestTimeoutException',
22
- 'ECONNRESET',
23
- 'ECONNREFUSED',
24
- 'ETIMEDOUT',
25
- 'EPIPE',
26
- 'EAI_AGAIN',
27
- 'NetworkingError',
28
- 'TimeoutError',
29
- 'EHOSTUNREACH',
30
- 'ENETUNREACH',
31
- 'ENOTFOUND',
32
- ];
33
- /**
34
- * HTTP statuses the AWS SDK retries regardless of the error name: throttling
35
- * (429) and the transient server statuses. They matter most for an error the
36
- * SDK could not map to a modeled exception (an intermediary's HTML 503, a
37
- * truncated body), which arrives as `name: 'Unknown'` with only its status.
38
- */
39
- const TRANSIENT_HTTP_STATUSES = [429, 500, 502, 503, 504];
40
- /**
41
- * Cancellation reason codes (from a `TransactionCanceledException`'s
42
- * `CancellationReasons`) that are transient and safe to retry. `None` marks an
43
- * item that was not the cause and is ignored.
44
- */
45
- const TRANSIENT_CANCELLATION_REASONS = [
46
- 'None',
47
- 'TransactionConflict',
48
- 'ThrottlingError',
49
- 'ProvisionedThroughputExceeded',
50
- ];
51
- /**
52
- * When `error` is a transaction cancellation carrying reasons, return whether
53
- * every reason is transient; otherwise undefined so normal signal matching
54
- * applies. A bare cancellation with no reasons is treated as non-retryable.
55
- */
56
- function transactionCancellationRetryable(error) {
57
- const reasons = (0, cancellation_1.getCancellationReasons)(error);
58
- if (!reasons)
59
- return undefined;
60
- /**
61
- * `length > 0` is load-bearing: `.every()` is vacuously true on an empty
62
- * array, which would make a reason-less cancellation retryable — the exact
63
- * opposite of what this function documents. AWS populates one reason per
64
- * `TransactItems` entry, so an empty array should not occur; if it ever
65
- * does, the conservative answer is not to retry.
66
- */
67
- return (reasons.length > 0 &&
68
- reasons.every((reason) => reason.Code === undefined || TRANSIENT_CANCELLATION_REASONS.includes(reason.Code)));
69
- }
70
- /** Add one node's signal tokens, HTTP status and retryable trait to `evidence`. */
71
- function recordNode(fields, evidence) {
72
- for (const value of [fields.name, fields.code, fields.errno, fields.syscall]) {
73
- if (typeof value === 'string')
74
- evidence.signals.push(value);
75
- }
76
- if (typeof fields.$metadata?.httpStatusCode === 'number') {
77
- evidence.statuses.push(fields.$metadata.httpStatusCode);
78
- }
79
- if (fields.$retryable !== undefined && fields.$retryable !== null)
80
- evidence.retryableByTrait = true;
81
- }
82
- function collectEvidence(error) {
83
- const seen = new WeakSet();
84
- const evidence = { signals: [], statuses: [], retryableByTrait: false };
85
- const walk = (node, depth) => {
86
- if (depth > MAX_CAUSE_DEPTH || node === null || typeof node !== 'object' || seen.has(node)) {
87
- return;
88
- }
89
- seen.add(node);
90
- const fields = node;
91
- recordNode(fields, evidence);
92
- if (fields.cause)
93
- walk(fields.cause, depth + 1);
94
- };
95
- walk(error, 0);
96
- return evidence;
97
- }
98
- /**
99
- * True when `error` (or any cause in its chain) is transient: a transaction
100
- * cancellation whose every reason is transient (that verdict takes precedence,
101
- * because a permanent reason arrives with the same statuses as a transient
102
- * one), an HTTP status in {@link TRANSIENT_HTTP_STATUSES}, the SDK's
103
- * `$retryable` trait, or an exact match of a `name`/`code`/`errno`/`syscall`
104
- * token against `retryableErrors`. Exact, not substring: the fields are
105
- * whole tokens, and a substring rule would let an unrelated name that merely
106
- * contains one ride along.
107
- */
108
- function isRetryableError(error, retryableErrors) {
109
- const cancellation = transactionCancellationRetryable(error);
110
- if (cancellation !== undefined)
111
- return cancellation;
112
- const evidence = collectEvidence(error);
113
- if (evidence.retryableByTrait)
114
- return true;
115
- if (evidence.statuses.some((status) => TRANSIENT_HTTP_STATUSES.includes(status)))
116
- return true;
117
- return evidence.signals.some((signal) => retryableErrors.includes(signal));
118
- }
@@ -1,26 +0,0 @@
1
- import type { Logger } from '../logging/logger';
2
- import type { RetryOptions } from './retry';
3
- /**
4
- * Caller-facing retry tunables for every DynamoDB call an adapter makes. The
5
- * schedule is full-jitter exponential backoff: `baseDelayMs` doubling per
6
- * attempt, capped at `maxDelayMs`, for `maxAttempts` attempts. The
7
- * message-append path never goes below its own contention floor.
8
- */
9
- export interface RetryPolicy {
10
- /** Attempts per call before `RetryExhaustedError` (default 5). */
11
- maxAttempts?: number;
12
- /** First backoff delay in milliseconds (default 100). */
13
- baseDelayMs?: number;
14
- /** Cap on a single backoff delay in milliseconds (default 5000). */
15
- maxDelayMs?: number;
16
- }
17
- /**
18
- * Resolve an adapter's retry policy once, attaching the context logger so
19
- * every retry is visible at `debug` (attempt, the delay about to be slept, the
20
- * error name) instead of only surfacing once the budget is exhausted.
21
- */
22
- export declare function resolveRetryPolicy(policy: RetryPolicy | undefined, logger: Logger): RetryOptions;
23
- /** The context's retry options plus a per-call cancellation signal, when one is given. */
24
- export declare function retryFor(context: {
25
- retry?: RetryOptions;
26
- }, signal?: AbortSignal): RetryOptions | undefined;
@@ -1,22 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.resolveRetryPolicy = resolveRetryPolicy;
4
- exports.retryFor = retryFor;
5
- const constants_1 = require("../constants");
6
- /**
7
- * Resolve an adapter's retry policy once, attaching the context logger so
8
- * every retry is visible at `debug` (attempt, the delay about to be slept, the
9
- * error name) instead of only surfacing once the budget is exhausted.
10
- */
11
- function resolveRetryPolicy(policy, logger) {
12
- return {
13
- maxAttempts: policy?.maxAttempts ?? constants_1.DEFAULT_RETRY_MAX_ATTEMPTS,
14
- baseDelayMs: policy?.baseDelayMs ?? constants_1.INITIAL_BACKOFF_DELAY_MS,
15
- maxDelayMs: policy?.maxDelayMs ?? constants_1.MAX_BACKOFF_DELAY_MS,
16
- onRetry: ({ attempt, delayMs, error }) => logger.debug('retrying after a transient error', { attempt, delayMs, error: error.name }),
17
- };
18
- }
19
- /** The context's retry options plus a per-call cancellation signal, when one is given. */
20
- function retryFor(context, signal) {
21
- return signal === undefined ? context.retry : { ...context.retry, signal };
22
- }
@@ -1,14 +0,0 @@
1
- import type { DynamoDBDocument, ScanCommandInput } from '@aws-sdk/lib-dynamodb';
2
- import { type PaginateCoreOptions } from './paginate-core';
3
- import type { DocItem } from './types';
4
- /** Options for {@link paginateScan}. */
5
- export interface ScanOptions extends PaginateCoreOptions {
6
- client: DynamoDBDocument;
7
- params: ScanCommandInput;
8
- }
9
- /**
10
- * Drive a DynamoDB Scan across all pages, yielding each item. Shares the
11
- * pagination core with {@link paginateQuery}: abort handling, retry per page,
12
- * and runaway guards.
13
- */
14
- export declare function paginateScan(options: ScanOptions): AsyncGenerator<DocItem>;
@@ -1,19 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.paginateScan = paginateScan;
4
- const paginate_core_1 = require("./paginate-core");
5
- const retry_1 = require("./retry");
6
- /**
7
- * Drive a DynamoDB Scan across all pages, yielding each item. Shares the
8
- * pagination core with {@link paginateQuery}: abort handling, retry per page,
9
- * and runaway guards.
10
- */
11
- function paginateScan(options) {
12
- return (0, paginate_core_1.paginatePages)(async (startKey) => {
13
- const page = await (0, retry_1.withDynamoDBRetry)(() => options.client.scan({ ...options.params, ExclusiveStartKey: startKey }), { ...options.retry, signal: options.signal });
14
- return {
15
- items: page.Items ?? [],
16
- lastKey: page.LastEvaluatedKey,
17
- };
18
- }, options);
19
- }
@@ -1,23 +0,0 @@
1
- import type { NativeAttributeValue } from '@aws-sdk/lib-dynamodb';
2
- /**
3
- * A DynamoDB item as returned/accepted by the DocumentClient. Reads that we
4
- * wrote ourselves are narrowed with a single structural `as` at the mapper
5
- * boundary (never `as any`/`as unknown`); untrusted shared-table scans go
6
- * through `narrowStoreRecord`.
7
- */
8
- export type DocItem = Record<string, NativeAttributeValue>;
9
- /** A BatchWriteItem PutRequest. */
10
- interface PutWriteRequest {
11
- PutRequest: {
12
- Item: DocItem;
13
- };
14
- }
15
- /** A BatchWriteItem DeleteRequest. */
16
- interface DeleteWriteRequest {
17
- DeleteRequest: {
18
- Key: DocItem;
19
- };
20
- }
21
- /** A single BatchWriteItem write request. */
22
- export type WriteRequest = PutWriteRequest | DeleteWriteRequest;
23
- export {};
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,16 +0,0 @@
1
- import { DynamoDBLangGraphError } from './base-error';
2
- /**
3
- * A failure that originated below this library — the AWS SDK, the transport,
4
- * a third-party `VectorBackend` or `Embeddings` — and surfaced through one of
5
- * its public methods. Wrapping it keeps the promise that every rejection a
6
- * caller sees is a {@link DynamoDBLangGraphError} with a branchable `code`,
7
- * while losing nothing a support ticket needs: the SDK's own error name, the
8
- * request id and HTTP status when present, and the original as `cause`.
9
- */
10
- export declare class UpstreamError extends DynamoDBLangGraphError {
11
- readonly upstreamName: string;
12
- /** Declared, not emitted: absent metadata leaves no `undefined`-valued own property behind. */
13
- readonly requestId?: string;
14
- readonly httpStatusCode?: number;
15
- constructor(cause: Error, operation: string);
16
- }
@@ -1,27 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.UpstreamError = void 0;
4
- const base_error_1 = require("./base-error");
5
- const error_code_1 = require("./error-code");
6
- /**
7
- * A failure that originated below this library — the AWS SDK, the transport,
8
- * a third-party `VectorBackend` or `Embeddings` — and surfaced through one of
9
- * its public methods. Wrapping it keeps the promise that every rejection a
10
- * caller sees is a {@link DynamoDBLangGraphError} with a branchable `code`,
11
- * while losing nothing a support ticket needs: the SDK's own error name, the
12
- * request id and HTTP status when present, and the original as `cause`.
13
- */
14
- class UpstreamError extends base_error_1.DynamoDBLangGraphError {
15
- upstreamName;
16
- constructor(cause, operation) {
17
- super(`${operation}: ${cause.name}: ${cause.message}`, error_code_1.ErrorCode.UPSTREAM, { operation }, cause);
18
- this.name = 'UpstreamError';
19
- this.upstreamName = cause.name;
20
- const metadata = cause.$metadata;
21
- if (metadata?.requestId !== undefined)
22
- this.requestId = metadata.requestId;
23
- if (metadata?.httpStatusCode !== undefined)
24
- this.httpStatusCode = metadata.httpStatusCode;
25
- }
26
- }
27
- exports.UpstreamError = UpstreamError;
@@ -1,7 +0,0 @@
1
- /**
2
- * Normalize a caught value (TypeScript types catch clauses as the implicit
3
- * unknown) into an `Error`. Error-shaped values pass through; anything else is
4
- * stringified into a fresh `Error`. This is the boundary where caught values
5
- * are narrowed — callers do `toError(error as Error)`.
6
- */
7
- export declare function toError(value: Error): Error;
@@ -1,15 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.toError = toError;
4
- /**
5
- * Normalize a caught value (TypeScript types catch clauses as the implicit
6
- * unknown) into an `Error`. Error-shaped values pass through; anything else is
7
- * stringified into a fresh `Error`. This is the boundary where caught values
8
- * are narrowed — callers do `toError(error as Error)`.
9
- */
10
- function toError(value) {
11
- if (value !== null && typeof value === 'object' && typeof value.message === 'string') {
12
- return value;
13
- }
14
- return new Error(typeof value === 'string' ? value : JSON.stringify(value));
15
- }
@@ -1,23 +0,0 @@
1
- /** A value that {@link redactSecrets} can recurse through. */
2
- export type Redactable = string | number | boolean | null | undefined | Redactable[] | {
3
- [key: string]: Redactable;
4
- };
5
- /** Any `Redactable` that is a non-null object — what the walk dispatches on. */
6
- export type RedactableObject = Redactable[] | {
7
- [key: string]: Redactable;
8
- };
9
- /** One step of the recursive walk, threaded into the entry helpers. */
10
- type Walk = (value: Redactable) => Redactable;
11
- /** Collaborators threaded through the recursive walk. */
12
- export interface WalkDeps {
13
- keyPatterns: readonly string[];
14
- valuePatterns: readonly RegExp[];
15
- walk: Walk;
16
- }
17
- /**
18
- * Dispatch one non-null object by its shape: arrays and plain objects recurse,
19
- * binary views collapse to a label, `Date`/`RegExp` pass through by reference,
20
- * `Set`/`Map` render as their contents, and an Error takes the path above.
21
- */
22
- export declare function walkObject(current: RedactableObject, deps: WalkDeps): Redactable;
23
- export {};
@@ -1,112 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.walkObject = walkObject;
4
- const secret_patterns_1 = require("./secret-patterns");
5
- /** True when `value` is a Set, tested by tag so a cross-realm Set still matches. */
6
- function isSetValue(value) {
7
- return Object.prototype.toString.call(value) === '[object Set]';
8
- }
9
- /** True when `value` is a Map, tested by tag so a cross-realm Map still matches. */
10
- function isMapValue(value) {
11
- return Object.prototype.toString.call(value) === '[object Map]';
12
- }
13
- /**
14
- * True when `value` is an Error (or subclass) or a `DOMException` — which has
15
- * its own tag yet carries the same `name`/`message`/`stack` — tested by tag,
16
- * not `instanceof`, so a cross-realm error still matches.
17
- */
18
- function isErrorValue(value) {
19
- const tag = Object.prototype.toString.call(value);
20
- return tag === '[object Error]' || tag === '[object DOMException]';
21
- }
22
- /**
23
- * True for a value whose identity matters more than its own properties.
24
- * `Date` and `RegExp` have none, so recursing either would yield a bare `{}`.
25
- */
26
- function isOpaqueValue(value) {
27
- const tag = Object.prototype.toString.call(value);
28
- return tag === '[object Date]' || tag === '[object RegExp]';
29
- }
30
- /**
31
- * Rebuild entries into a plain object, redacting values at secret-looking
32
- * keys. Properties are defined, not assigned: `out['__proto__'] = …` would
33
- * replace the result's prototype (and drop the entry) instead of recording the
34
- * key as data.
35
- */
36
- function redactEntries(entries, keyPatterns, walk) {
37
- const out = {};
38
- for (const [key, value] of entries) {
39
- Object.defineProperty(out, key, {
40
- value: (0, secret_patterns_1.isSecretKey)(key, keyPatterns) ? secret_patterns_1.REDACTED : walk(value),
41
- enumerable: true,
42
- writable: true,
43
- configurable: true,
44
- });
45
- }
46
- return out;
47
- }
48
- /**
49
- * A Map's entries as an object. Keys are stringified so a non-string key is
50
- * still reported rather than dropped, and each is checked against the
51
- * secret-key patterns exactly as a plain object's own keys are.
52
- */
53
- function redactMap(value, deps) {
54
- const entries = [...value].map(([key, entry]) => [String(key), entry]);
55
- return redactEntries(entries, deps.keyPatterns, deps.walk);
56
- }
57
- /**
58
- * Rebuild an Error as a plain object carrying its redacted text alongside its
59
- * redacted own properties. The one exception is an Error with no own
60
- * enumerable data, no `cause`, no aggregated `errors`, and no secret in its
61
- * text: it is returned by reference so its identity and stack trace survive,
62
- * which is what keeps a caught error useful in a log.
63
- *
64
- * `cause` and `AggregateError.errors` are copied explicitly because both are
65
- * defined *non-enumerable* per spec, so `Object.entries` never sees them.
66
- * Without this the whole chain vanished on every rebuild — and the rebuild
67
- * always fires for this library's own error types, since each attaches an
68
- * enumerable `code`/`context`. A redacted `RetryExhaustedError` would then no
69
- * longer say whether the underlying failure was a throttle, a validation error
70
- * or a network fault, which is the entire reason it carries a cause. A bare
71
- * Error *with* a cause is rebuilt for the same reason: passing it by reference
72
- * would hand the caller whatever secret the cause carries. Recursing through
73
- * `walk` redacts the chain too, and the cycle guard handles a cause that
74
- * points back at its own wrapper.
75
- */
76
- function redactError(current, entries, deps) {
77
- const text = (0, secret_patterns_1.redactErrorText)(current, deps.valuePatterns);
78
- const aggregated = current.errors;
79
- const bare = entries.length === 0 && current.cause === undefined && aggregated === undefined;
80
- if (bare && !text.changed)
81
- return current;
82
- const out = redactEntries(entries, deps.keyPatterns, deps.walk);
83
- out.name = text.name;
84
- out.message = text.message;
85
- out.stack = text.stack;
86
- if (current.cause !== undefined)
87
- out.cause = deps.walk(current.cause);
88
- if (Array.isArray(aggregated))
89
- out.errors = deps.walk(aggregated);
90
- return out;
91
- }
92
- /**
93
- * Dispatch one non-null object by its shape: arrays and plain objects recurse,
94
- * binary views collapse to a label, `Date`/`RegExp` pass through by reference,
95
- * `Set`/`Map` render as their contents, and an Error takes the path above.
96
- */
97
- function walkObject(current, deps) {
98
- if (Array.isArray(current))
99
- return current.map(deps.walk);
100
- if (ArrayBuffer.isView(current))
101
- return (0, secret_patterns_1.binaryLabel)(current);
102
- if (isOpaqueValue(current))
103
- return current;
104
- if (isSetValue(current))
105
- return [...current].map(deps.walk);
106
- if (isMapValue(current))
107
- return redactMap(current, deps);
108
- const entries = Object.entries(current);
109
- if (isErrorValue(current))
110
- return redactError(current, entries, deps);
111
- return redactEntries(entries, deps.keyPatterns, deps.walk);
112
- }
@@ -1,13 +0,0 @@
1
- import type { Item } from '@langchain/langgraph-checkpoint';
2
- import type { StoreContext } from '../internal/setup';
3
- /**
4
- * Retrieve a single item by namespace and key (strongly consistent), or null.
5
- *
6
- * An offloaded item can lose a race with a concurrent overwrite: between the
7
- * row read and the S3 download the writer commits a new descriptor and deletes
8
- * the object this read was about to fetch. That surfaces as `NoSuchKey`, and
9
- * one strongly-consistent re-read settles it — the row now points at the new
10
- * object (return that), is gone (null), or still points at the same missing
11
- * object (a genuine loss, rethrown). Any other download failure propagates.
12
- */
13
- export declare function getItem(context: StoreContext, namespace: string[], key: string, signal?: AbortSignal): Promise<Item | null>;
@@ -1,73 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getItem = getItem;
4
- const clock_1 = require("../../shared/clock");
5
- const codec_1 = require("../../shared/codec/codec");
6
- const payload_loss_1 = require("../../shared/codec/payload-loss");
7
- const expiry_1 = require("../../shared/dynamodb/expiry");
8
- const retry_1 = require("../../shared/dynamodb/retry");
9
- const retry_policy_1 = require("../../shared/dynamodb/retry-policy");
10
- const item_mapper_1 = require("../internal/item-mapper");
11
- const keys_1 = require("../internal/keys");
12
- const validation_1 = require("../internal/validation");
13
- /**
14
- * Read the row strongly consistently and narrow it rather than cast. A
15
- * foreign row sharing this key has no `namespace`, and one carrying a `value`
16
- * PayloadDescriptor in the same shape a store item uses (a checkpointer WRITE
17
- * row) would otherwise decode cleanly and be handed back as the caller's own
18
- * value.
19
- */
20
- async function readRow(context, namespace, key, signal) {
21
- const result = await (0, retry_1.withDynamoDBRetry)(() => context.client.get({
22
- TableName: context.tableName,
23
- Key: { PK: (0, keys_1.partitionKey)(namespace), SK: (0, keys_1.sortKey)(namespace, key) },
24
- ConsistentRead: true,
25
- }), (0, retry_policy_1.retryFor)(context, signal));
26
- if (!result.Item)
27
- return undefined;
28
- const record = (0, item_mapper_1.narrowStoreRecord)(result.Item);
29
- if (!record) {
30
- context.logger.warn('store.get: ignored a row that is not a store item', {
31
- partitionKey: (0, keys_1.partitionKey)(namespace),
32
- sortKey: (0, keys_1.sortKey)(namespace, key),
33
- });
34
- return undefined;
35
- }
36
- /** A row past its ttl is absent to every reader, however long DynamoDB's sweep lags. */
37
- return (0, expiry_1.isExpiredRow)(record, (0, clock_1.nowSeconds)()) ? undefined : record;
38
- }
39
- /** True when both records point at the same offloaded object. */
40
- function sameObject(a, b) {
41
- return (a.value.location === codec_1.PayloadLocation.S3 &&
42
- b.value.location === codec_1.PayloadLocation.S3 &&
43
- a.value.s3Key === b.value.s3Key);
44
- }
45
- /**
46
- * Retrieve a single item by namespace and key (strongly consistent), or null.
47
- *
48
- * An offloaded item can lose a race with a concurrent overwrite: between the
49
- * row read and the S3 download the writer commits a new descriptor and deletes
50
- * the object this read was about to fetch. That surfaces as `NoSuchKey`, and
51
- * one strongly-consistent re-read settles it — the row now points at the new
52
- * object (return that), is gone (null), or still points at the same missing
53
- * object (a genuine loss, rethrown). Any other download failure propagates.
54
- */
55
- async function getItem(context, namespace, key, signal) {
56
- (0, validation_1.validateStoreKey)(namespace, key);
57
- const record = await readRow(context, namespace, key, signal);
58
- if (!record)
59
- return null;
60
- try {
61
- return await (0, item_mapper_1.readStoreItem)(context, record);
62
- }
63
- catch (error) {
64
- if (!(0, payload_loss_1.isMissingObjectError)(error))
65
- throw error;
66
- const fresh = await readRow(context, namespace, key, signal);
67
- if (!fresh)
68
- return null;
69
- if (sameObject(record, fresh))
70
- throw error;
71
- return (0, item_mapper_1.readStoreItem)(context, fresh);
72
- }
73
- }
@@ -1,4 +0,0 @@
1
- import type { IndexConfig, SearchItem, SearchOperation } from '@langchain/langgraph-checkpoint';
2
- import type { VectorBackend } from '../vector-backend';
3
- import type { StoreContext } from './setup';
4
- export declare function searchViaBackend(context: StoreContext, backend: VectorBackend, index: IndexConfig, op: SearchOperation, offset: number, limit: number, signal?: AbortSignal): Promise<SearchItem[]>;
@@ -1,74 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.searchViaBackend = searchViaBackend;
4
- const errors_1 = require("../../shared/errors/errors");
5
- const get_1 = require("../actions/get");
6
- const keys_1 = require("./keys");
7
- const score_direction_1 = require("./score-direction");
8
- const search_filter_1 = require("./search-filter");
9
- const semantic_search_1 = require("./semantic-search");
10
- /**
11
- * Warn when a backend's own ordering disagrees with its scores. A backend
12
- * returning a raw distance still hands back nearest-first, so the order looks
13
- * right while every score means the opposite of what {@link VectorMatch.score}
14
- * promises — ascending scores are that exact signature. Results are never
15
- * reordered on this basis: a correctly-scored backend's order is authoritative.
16
- */
17
- function warnOnNonDescendingScores(context, matches, namespacePrefix) {
18
- const descending = matches.every((match, position) => position === 0 || matches[position - 1].score >= match.score);
19
- if (descending)
20
- return;
21
- context.logger.warn('search: vectorBackend returned ascending scores; VectorMatch.score must be a relevance ' +
22
- '(higher is better), not a distance — results are forwarded in the order the backend gave', { namespacePrefix });
23
- }
24
- /**
25
- * Read the canonical item a backend match points at, or `undefined` when the
26
- * match is unusable. `getItem` validates, so a backend returning a namespace
27
- * element containing the reserved separator would otherwise turn the whole
28
- * search into a ValidationError instead of dropping the one bad match.
29
- */
30
- async function fetchMatch(context, match, signal) {
31
- try {
32
- return await (0, get_1.getItem)(context, match.namespace, match.key, signal);
33
- }
34
- catch (error) {
35
- context.logger.warn('search: skipped an unusable vectorBackend match', {
36
- namespace: match.namespace,
37
- key: match.key,
38
- reason: error.name,
39
- });
40
- return null;
41
- }
42
- }
43
- async function searchViaBackend(context, backend, index, op, offset, limit, signal) {
44
- const queryVector = await index.embeddings.embedQuery(op.query);
45
- (0, semantic_search_1.assertVectorDims)(index, queryVector, 'query');
46
- const need = offset + limit;
47
- if (need > context.maxSearchCandidates) {
48
- throw new errors_1.ValidationError(`Requested page (offset ${offset} + limit ${limit} = ${need}) exceeds maxSearchCandidates ` +
49
- `(${context.maxSearchCandidates}); narrow the page or raise maxSearchCandidates`, 'maxSearchCandidates');
50
- }
51
- let topK = Math.min(need, context.maxSearchCandidates);
52
- let results;
53
- for (;;) {
54
- const matches = (0, score_direction_1.toRelevanceScores)(await backend.query(op.namespacePrefix, queryVector, topK), context.vectorScoreDirection);
55
- warnOnNonDescendingScores(context, matches, op.namespacePrefix);
56
- results = [];
57
- for (const match of matches) {
58
- if (!(0, keys_1.namespaceMatchesPrefix)(match.namespace, op.namespacePrefix))
59
- continue;
60
- const item = await fetchMatch(context, match, signal);
61
- if (item && (0, search_filter_1.passesFilter)(item, op))
62
- results.push({ ...item, score: match.score });
63
- }
64
- if (results.length >= need || matches.length < topK)
65
- break;
66
- if (topK >= context.maxSearchCandidates) {
67
- /** The backend still holds matches, but the filter left the page short at the cap: the same answer the in-DB ranker gives, not a silently short page. */
68
- throw new errors_1.ValidationError(`Semantic search collected ${results.length} of ${need} matches within maxSearchCandidates ` +
69
- `(${context.maxSearchCandidates}); narrow the filter or raise maxSearchCandidates`, 'maxSearchCandidates');
70
- }
71
- topK = Math.min(topK * 2, context.maxSearchCandidates);
72
- }
73
- return results;
74
- }
@@ -1,23 +0,0 @@
1
- import type { SearchOperation } from '@langchain/langgraph-checkpoint';
2
- import type { RankCandidate } from './ranker';
3
- import type { StoreContext } from './setup';
4
- /**
5
- * How far a collection must go. A plain page is complete once `need`
6
- * (`offset + limit`) matching items are in hand, so rows past it are never
7
- * read or decoded; a semantic ranking needs every candidate but is refused as
8
- * soon as more than `cap` rows exist, before a single decode or embedding.
9
- */
10
- export type CollectBound = {
11
- kind: 'page';
12
- need: number;
13
- } | {
14
- kind: 'semantic';
15
- cap: number;
16
- };
17
- /**
18
- * Collect the live rows under the prefix and decode them within `bound`. A
19
- * page decodes rows in batches of {@link DEFAULT_READ_CONCURRENCY} and closes
20
- * the paginator as soon as the page is full, so a namespace far larger than the
21
- * page costs neither a full decode nor a truncation error.
22
- */
23
- export declare function collectCandidates(context: StoreContext, op: SearchOperation, bound: CollectBound, signal?: AbortSignal): Promise<RankCandidate[]>;