@lota-sdk/core 0.4.45 → 0.4.46
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.46",
|
|
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.46",
|
|
36
36
|
"@mendable/firecrawl-js": "^4.20.0",
|
|
37
37
|
"@surrealdb/node": "^3.0.3",
|
|
38
38
|
"ai": "^6.0.170",
|
|
@@ -11,6 +11,7 @@ import {
|
|
|
11
11
|
readString,
|
|
12
12
|
stringifyUnknown,
|
|
13
13
|
} from '../../utils/string'
|
|
14
|
+
import { trimOversizedTextForRequestBudget } from '../model-input-budget'
|
|
14
15
|
import {
|
|
15
16
|
COMPACTION_CHUNK_MAX_CHARS,
|
|
16
17
|
CONTEXT_COMPACTION_INCLUDED_TOOL_NAMES,
|
|
@@ -71,6 +72,8 @@ class CompactionParseError extends Schema.TaggedErrorClass<CompactionParseError>
|
|
|
71
72
|
}) {}
|
|
72
73
|
|
|
73
74
|
const COMPACTION_RUNNER_RETRY_OPTIONS = { times: 2, schedule: Schedule.exponential(Duration.millis(500), 2) } as const
|
|
75
|
+
const COMPACTION_CONTEXT_MESSAGE_TEXT_MAX_CHARS = 24_000
|
|
76
|
+
const COMPACTION_MIN_SOURCE_CHARS = 2_000
|
|
74
77
|
|
|
75
78
|
export interface ContextCompactionPromptParams {
|
|
76
79
|
previousSummary: string
|
|
@@ -294,11 +297,14 @@ export function createContextCompactionRuntime(
|
|
|
294
297
|
return chunks.join('\n').trim()
|
|
295
298
|
}
|
|
296
299
|
|
|
297
|
-
const toContextMessageFromChatMessage = (message: ChatMessage): ContextMessage =>
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
300
|
+
const toContextMessageFromChatMessage = (message: ChatMessage): ContextMessage => {
|
|
301
|
+
const text = toContextTextFromChatMessage(message)
|
|
302
|
+
return {
|
|
303
|
+
role: message.role,
|
|
304
|
+
text: trimOversizedTextForRequestBudget(text, COMPACTION_CONTEXT_MESSAGE_TEXT_MAX_CHARS),
|
|
305
|
+
sourceMessageId: message.id,
|
|
306
|
+
}
|
|
307
|
+
}
|
|
302
308
|
|
|
303
309
|
const createSummaryMessage = (summaryText: string): ChatMessage | null => {
|
|
304
310
|
const summary = normalizeSummary(summaryText)
|
|
@@ -458,6 +464,10 @@ export function createContextCompactionRuntime(
|
|
|
458
464
|
return { ...state, estimatedTokens: assessment.estimatedTokens, done: true }
|
|
459
465
|
}
|
|
460
466
|
|
|
467
|
+
if (sourceText.length < COMPACTION_MIN_SOURCE_CHARS) {
|
|
468
|
+
return { ...state, estimatedTokens: assessment.estimatedTokens, done: true }
|
|
469
|
+
}
|
|
470
|
+
|
|
461
471
|
const compacted = yield* compactContextMessagesEffect({
|
|
462
472
|
previousSummary: state.summaryText,
|
|
463
473
|
newMessages: contextMessages,
|
|
@@ -465,9 +475,7 @@ export function createContextCompactionRuntime(
|
|
|
465
475
|
const rolledSummary = yield* rollupSummaryIfOversizedEffect(normalizeSummary(compacted.summary))
|
|
466
476
|
|
|
467
477
|
if (rolledSummary.length >= sourceText.length) {
|
|
468
|
-
return
|
|
469
|
-
message: 'Compaction summary is not shorter than compacted source',
|
|
470
|
-
})
|
|
478
|
+
return { ...state, estimatedTokens: assessment.estimatedTokens, done: true }
|
|
471
479
|
}
|
|
472
480
|
|
|
473
481
|
return yield* stepHistory({
|