@lota-sdk/core 0.4.31 → 0.4.32
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.
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lota-sdk/core",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.32",
|
|
4
4
|
"files": [
|
|
5
5
|
"src",
|
|
6
6
|
"infrastructure/schema"
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
"@ai-sdk/provider": "^3.0.9",
|
|
33
33
|
"@chat-adapter/slack": "^4.26.0",
|
|
34
34
|
"@chat-adapter/state-ioredis": "^4.26.0",
|
|
35
|
-
"@lota-sdk/shared": "0.4.
|
|
35
|
+
"@lota-sdk/shared": "0.4.32",
|
|
36
36
|
"@mendable/firecrawl-js": "^4.20.0",
|
|
37
37
|
"@surrealdb/node": "^3.0.3",
|
|
38
38
|
"ai": "^6.0.170",
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import type { Context } from 'effect'
|
|
2
|
-
import { Schema, Effect } from 'effect'
|
|
2
|
+
import { Duration, Schema, Effect, Schedule } from 'effect'
|
|
3
3
|
|
|
4
4
|
import { serverLogger } from '../../config/logger'
|
|
5
5
|
import type { RecordIdRef } from '../../db/record-id'
|
|
6
6
|
import { ensureRecordId, recordIdToString } from '../../db/record-id'
|
|
7
7
|
import { TABLES } from '../../db/tables'
|
|
8
|
+
import { isRetriableTransactionConflict } from '../../db/transaction-conflict'
|
|
8
9
|
import { ERROR_TAGS } from '../../effect/errors'
|
|
9
10
|
import {
|
|
10
11
|
appendToMemoryBlock,
|
|
@@ -24,6 +25,9 @@ type ContextCompactionServiceLike = Pick<ReturnType<typeof makeContextCompaction
|
|
|
24
25
|
|
|
25
26
|
type BackgroundWorker = Context.Service.Shape<typeof BackgroundWorkServiceTag>
|
|
26
27
|
|
|
28
|
+
const MEMORY_BLOCK_COMPACTION_RETRY_ATTEMPTS = 4
|
|
29
|
+
const MEMORY_BLOCK_COMPACTION_RETRY_BASE_DELAY_MS = 50
|
|
30
|
+
|
|
27
31
|
class ThreadMemoryBlockError extends Schema.TaggedErrorClass<ThreadMemoryBlockError>()(
|
|
28
32
|
ERROR_TAGS.ThreadMemoryBlockError,
|
|
29
33
|
{ message: Schema.String, cause: Schema.optional(Schema.Defect) },
|
|
@@ -94,7 +98,7 @@ export function createThreadMemoryBlockHelpers(deps: {
|
|
|
94
98
|
})
|
|
95
99
|
}
|
|
96
100
|
|
|
97
|
-
function
|
|
101
|
+
function compactMemoryBlockOnce(threadId: RecordIdRef): Effect.Effect<boolean, ThreadMemoryBlockError> {
|
|
98
102
|
return Effect.gen(function* () {
|
|
99
103
|
const threadRef = ensureRecordId(threadId, TABLES.THREAD)
|
|
100
104
|
const threadIdString = recordIdToString(threadRef, TABLES.THREAD)
|
|
@@ -151,5 +155,17 @@ export function createThreadMemoryBlockHelpers(deps: {
|
|
|
151
155
|
})
|
|
152
156
|
}
|
|
153
157
|
|
|
158
|
+
function compactMemoryBlock(threadId: RecordIdRef): Effect.Effect<boolean, ThreadMemoryBlockError> {
|
|
159
|
+
return compactMemoryBlockOnce(threadId).pipe(
|
|
160
|
+
Effect.retry({
|
|
161
|
+
times: MEMORY_BLOCK_COMPACTION_RETRY_ATTEMPTS - 1,
|
|
162
|
+
schedule: Schedule.jittered(
|
|
163
|
+
Schedule.exponential(Duration.millis(MEMORY_BLOCK_COMPACTION_RETRY_BASE_DELAY_MS), 2),
|
|
164
|
+
),
|
|
165
|
+
while: isRetriableTransactionConflict,
|
|
166
|
+
}),
|
|
167
|
+
)
|
|
168
|
+
}
|
|
169
|
+
|
|
154
170
|
return { appendMemoryBlock, compactMemoryBlock }
|
|
155
171
|
}
|