@lota-sdk/core 0.4.41 → 0.4.42
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 +2 -2
- package/src/ai-gateway/ai-gateway.ts +4 -24
- package/src/ai-gateway/index.ts +0 -1
- package/src/system-agents/context-compaction.agent.ts +0 -2
- package/src/system-agents/memory-reranker.agent.ts +0 -2
- package/src/system-agents/memory.agent.ts +0 -2
- package/src/system-agents/recent-activity-title-refiner.agent.ts +0 -2
- package/src/system-agents/regular-chat-memory-digest.agent.ts +0 -2
- package/src/system-agents/skill-extractor.agent.ts +0 -2
- package/src/system-agents/skill-manager.agent.ts +0 -2
- package/src/system-agents/thread-router.agent.ts +0 -2
- package/src/system-agents/title-generator.agent.ts +0 -2
- package/src/tools/research-topic.tool.ts +0 -2
- package/src/ai-gateway/cache-headers.ts +0 -42
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lota-sdk/core",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.42",
|
|
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.42",
|
|
36
36
|
"@mendable/firecrawl-js": "^4.20.0",
|
|
37
37
|
"@surrealdb/node": "^3.0.3",
|
|
38
38
|
"ai": "^6.0.170",
|
|
@@ -10,7 +10,6 @@ import { ERROR_TAGS, AiGenerationError, ConfigurationError } from '../effect/err
|
|
|
10
10
|
import { RuntimeConfigServiceTag } from '../effect/services'
|
|
11
11
|
import { openRouterEmbeddingModel } from '../embeddings/openrouter'
|
|
12
12
|
import { isRecord, readString } from '../utils/string'
|
|
13
|
-
import { buildAiGatewayCacheHeaders } from './cache-headers'
|
|
14
13
|
|
|
15
14
|
type AiGatewayChatResponse = { body?: unknown }
|
|
16
15
|
type AiGatewayTransformParamsOptions = Parameters<NonNullable<LanguageModelMiddleware['transformParams']>>[0]
|
|
@@ -473,23 +472,6 @@ function withAiGatewayStreamIdleTimeout(
|
|
|
473
472
|
})
|
|
474
473
|
}
|
|
475
474
|
|
|
476
|
-
function mergeAiGatewayHeaders(
|
|
477
|
-
existingHeaders: AiGatewayCallOptions['headers'] | undefined,
|
|
478
|
-
additionalHeaders: Record<string, string>,
|
|
479
|
-
): Record<string, string> {
|
|
480
|
-
const merged = new Headers(existingHeaders as HeadersInit | undefined)
|
|
481
|
-
for (const [key, value] of Object.entries(additionalHeaders)) {
|
|
482
|
-
if (!merged.has(key)) {
|
|
483
|
-
merged.set(key, value)
|
|
484
|
-
}
|
|
485
|
-
}
|
|
486
|
-
return Object.fromEntries(merged.entries())
|
|
487
|
-
}
|
|
488
|
-
|
|
489
|
-
function withDefaultAiGatewayCacheHeaders(params: AiGatewayCallOptions): AiGatewayCallOptions {
|
|
490
|
-
return { ...params, headers: mergeAiGatewayHeaders(params.headers, buildAiGatewayCacheHeaders('lota-sdk')) }
|
|
491
|
-
}
|
|
492
|
-
|
|
493
475
|
function normalizeAiGatewayUrlEffect(value: string): Effect.Effect<string, ConfigurationError> {
|
|
494
476
|
const trimmed = value.trim()
|
|
495
477
|
if (!trimmed) {
|
|
@@ -1122,13 +1104,11 @@ function createAiGatewayLanguageModelMiddleware(
|
|
|
1122
1104
|
specificationVersion: 'v3',
|
|
1123
1105
|
transformParams: ({ params, type }) =>
|
|
1124
1106
|
Promise.resolve(
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
providerId === OPENAI_CHAT_PROVIDER_ID ? normalizeAiGatewayChatProviderOptions(params, modelId) : params,
|
|
1129
|
-
),
|
|
1130
|
-
type,
|
|
1107
|
+
addAiGatewayReasoningRawChunks(
|
|
1108
|
+
normalizeAiGatewayJsonSchemas(
|
|
1109
|
+
providerId === OPENAI_CHAT_PROVIDER_ID ? normalizeAiGatewayChatProviderOptions(params, modelId) : params,
|
|
1131
1110
|
),
|
|
1111
|
+
type,
|
|
1132
1112
|
),
|
|
1133
1113
|
),
|
|
1134
1114
|
wrapGenerate: ({ params }) => {
|
package/src/ai-gateway/index.ts
CHANGED
|
@@ -2,7 +2,6 @@ import type { CreateHelperToolLoopAgentOptions } from '@lota-sdk/shared'
|
|
|
2
2
|
import { ToolLoopAgent } from 'ai'
|
|
3
3
|
|
|
4
4
|
import type { AiGatewayModels } from '../ai-gateway/ai-gateway'
|
|
5
|
-
import { buildAiGatewayDirectCacheHeaders } from '../ai-gateway/cache-headers'
|
|
6
5
|
import { OPENROUTER_STRUCTURED_HELPER_MODEL_ID } from '../config/model-constants'
|
|
7
6
|
import { resolveHelperAgentOptions } from './helper-agent-options'
|
|
8
7
|
|
|
@@ -33,7 +32,6 @@ export function makeContextCompactionAgentFactory(models: AiGatewayModels) {
|
|
|
33
32
|
new ToolLoopAgent({
|
|
34
33
|
id: 'context-compaction',
|
|
35
34
|
model: models.chatModel(OPENROUTER_STRUCTURED_HELPER_MODEL_ID),
|
|
36
|
-
headers: buildAiGatewayDirectCacheHeaders('lota-sdk'),
|
|
37
35
|
...resolveHelperAgentOptions(options, { instructions: CONTEXT_COMPACTION_PROMPT }),
|
|
38
36
|
})
|
|
39
37
|
}
|
|
@@ -2,7 +2,6 @@ import type { CreateHelperToolLoopAgentOptions } from '@lota-sdk/shared'
|
|
|
2
2
|
import { ToolLoopAgent } from 'ai'
|
|
3
3
|
|
|
4
4
|
import type { AiGatewayModels } from '../ai-gateway/ai-gateway'
|
|
5
|
-
import { buildAiGatewayDirectCacheHeaders } from '../ai-gateway/cache-headers'
|
|
6
5
|
import {
|
|
7
6
|
OPENROUTER_LOW_REASONING_PROVIDER_OPTIONS,
|
|
8
7
|
OPENROUTER_STRUCTURED_HELPER_MODEL_ID,
|
|
@@ -34,7 +33,6 @@ export function makeMemoryRerankerAgentFactory(models: AiGatewayModels) {
|
|
|
34
33
|
new ToolLoopAgent({
|
|
35
34
|
id: 'memory-reranker',
|
|
36
35
|
model: models.chatModel(OPENROUTER_STRUCTURED_HELPER_MODEL_ID),
|
|
37
|
-
headers: buildAiGatewayDirectCacheHeaders('lota-sdk'),
|
|
38
36
|
providerOptions: OPENROUTER_LOW_REASONING_PROVIDER_OPTIONS,
|
|
39
37
|
...resolveHelperAgentOptions(options),
|
|
40
38
|
})
|
|
@@ -2,7 +2,6 @@ import type { CreateHelperToolLoopAgentOptions } from '@lota-sdk/shared'
|
|
|
2
2
|
import { ToolLoopAgent } from 'ai'
|
|
3
3
|
|
|
4
4
|
import type { AiGatewayModels } from '../ai-gateway/ai-gateway'
|
|
5
|
-
import { buildAiGatewayDirectCacheHeaders } from '../ai-gateway/cache-headers'
|
|
6
5
|
import {
|
|
7
6
|
OPENROUTER_STRUCTURED_HELPER_MODEL_ID,
|
|
8
7
|
OPENROUTER_HIGH_REASONING_PROVIDER_OPTIONS,
|
|
@@ -54,7 +53,6 @@ export function makeOrgMemoryAgentFactory(models: AiGatewayModels) {
|
|
|
54
53
|
new ToolLoopAgent({
|
|
55
54
|
id: 'org-memory',
|
|
56
55
|
model: models.chatModel(OPENROUTER_STRUCTURED_HELPER_MODEL_ID),
|
|
57
|
-
headers: buildAiGatewayDirectCacheHeaders('lota-sdk'),
|
|
58
56
|
providerOptions: OPENROUTER_HIGH_REASONING_PROVIDER_OPTIONS,
|
|
59
57
|
...resolveHelperAgentOptions(options),
|
|
60
58
|
})
|
|
@@ -2,7 +2,6 @@ import type { CreateHelperToolLoopAgentOptions } from '@lota-sdk/shared'
|
|
|
2
2
|
import { ToolLoopAgent } from 'ai'
|
|
3
3
|
|
|
4
4
|
import type { AiGatewayModels } from '../ai-gateway/ai-gateway'
|
|
5
|
-
import { buildAiGatewayDirectCacheHeaders } from '../ai-gateway/cache-headers'
|
|
6
5
|
import type { ResolvedAgentConfig } from '../config/agent-defaults'
|
|
7
6
|
import { OPENROUTER_STRUCTURED_HELPER_MODEL_ID } from '../config/model-constants'
|
|
8
7
|
import { resolveHelperAgentOptions } from './helper-agent-options'
|
|
@@ -78,7 +77,6 @@ export function makeRecentActivityTitleRefinerAgentFactory(models: AiGatewayMode
|
|
|
78
77
|
new ToolLoopAgent({
|
|
79
78
|
id: 'recent-activity-title-refiner',
|
|
80
79
|
model: models.chatModel(OPENROUTER_STRUCTURED_HELPER_MODEL_ID),
|
|
81
|
-
headers: buildAiGatewayDirectCacheHeaders('lota-sdk'),
|
|
82
80
|
...resolveHelperAgentOptions(options, {
|
|
83
81
|
instructions: buildRecentActivityTitleRefinerPrompt(agentConfig),
|
|
84
82
|
maxOutputTokens: RECENT_ACTIVITY_TITLE_MAX_TOKENS,
|
|
@@ -2,7 +2,6 @@ import type { CreateHelperToolLoopAgentOptions } from '@lota-sdk/shared'
|
|
|
2
2
|
import { ToolLoopAgent } from 'ai'
|
|
3
3
|
|
|
4
4
|
import type { AiGatewayModels } from '../ai-gateway/ai-gateway'
|
|
5
|
-
import { buildAiGatewayDirectCacheHeaders } from '../ai-gateway/cache-headers'
|
|
6
5
|
import {
|
|
7
6
|
OPENROUTER_STRUCTURED_HELPER_MODEL_ID,
|
|
8
7
|
OPENROUTER_HIGH_REASONING_PROVIDER_OPTIONS,
|
|
@@ -29,7 +28,6 @@ export function makeRegularChatMemoryDigestAgentFactory(models: AiGatewayModels)
|
|
|
29
28
|
new ToolLoopAgent({
|
|
30
29
|
id: 'regular-chat-memory-digest',
|
|
31
30
|
model: models.chatModel(OPENROUTER_STRUCTURED_HELPER_MODEL_ID),
|
|
32
|
-
headers: buildAiGatewayDirectCacheHeaders('lota-sdk'),
|
|
33
31
|
providerOptions: OPENROUTER_HIGH_REASONING_PROVIDER_OPTIONS,
|
|
34
32
|
...resolveHelperAgentOptions(options, {
|
|
35
33
|
instructions: regularChatMemoryDigestPrompt,
|
|
@@ -3,7 +3,6 @@ import { ToolLoopAgent } from 'ai'
|
|
|
3
3
|
import { z } from 'zod'
|
|
4
4
|
|
|
5
5
|
import type { AiGatewayModels } from '../ai-gateway/ai-gateway'
|
|
6
|
-
import { buildAiGatewayDirectCacheHeaders } from '../ai-gateway/cache-headers'
|
|
7
6
|
import {
|
|
8
7
|
OPENROUTER_STRUCTURED_HELPER_MODEL_ID,
|
|
9
8
|
OPENROUTER_HIGH_REASONING_PROVIDER_OPTIONS,
|
|
@@ -47,7 +46,6 @@ export function makeSkillExtractorAgentFactory(models: AiGatewayModels) {
|
|
|
47
46
|
new ToolLoopAgent({
|
|
48
47
|
id: 'skill-extractor',
|
|
49
48
|
model: models.chatModel(OPENROUTER_STRUCTURED_HELPER_MODEL_ID),
|
|
50
|
-
headers: buildAiGatewayDirectCacheHeaders('lota-sdk'),
|
|
51
49
|
providerOptions: OPENROUTER_HIGH_REASONING_PROVIDER_OPTIONS,
|
|
52
50
|
...resolveHelperAgentOptions(options, {
|
|
53
51
|
instructions: skillExtractorPrompt,
|
|
@@ -3,7 +3,6 @@ import { ToolLoopAgent } from 'ai'
|
|
|
3
3
|
import { z } from 'zod'
|
|
4
4
|
|
|
5
5
|
import type { AiGatewayModels } from '../ai-gateway/ai-gateway'
|
|
6
|
-
import { buildAiGatewayDirectCacheHeaders } from '../ai-gateway/cache-headers'
|
|
7
6
|
import {
|
|
8
7
|
OPENROUTER_STRUCTURED_HELPER_MODEL_ID,
|
|
9
8
|
OPENROUTER_HIGH_REASONING_PROVIDER_OPTIONS,
|
|
@@ -71,7 +70,6 @@ export function makeSkillManagerAgentFactory(models: AiGatewayModels) {
|
|
|
71
70
|
new ToolLoopAgent({
|
|
72
71
|
id: 'skill-manager',
|
|
73
72
|
model: models.chatModel(OPENROUTER_STRUCTURED_HELPER_MODEL_ID),
|
|
74
|
-
headers: buildAiGatewayDirectCacheHeaders('lota-sdk'),
|
|
75
73
|
providerOptions: OPENROUTER_HIGH_REASONING_PROVIDER_OPTIONS,
|
|
76
74
|
...resolveHelperAgentOptions(options, {
|
|
77
75
|
instructions: skillManagerPrompt,
|
|
@@ -3,7 +3,6 @@ import { Effect } from 'effect'
|
|
|
3
3
|
import { z } from 'zod'
|
|
4
4
|
|
|
5
5
|
import type { AiGatewayModels } from '../ai-gateway/ai-gateway'
|
|
6
|
-
import { buildAiGatewayDirectCacheHeaders } from '../ai-gateway/cache-headers'
|
|
7
6
|
import type { ResolvedAgentConfig } from '../config/agent-defaults'
|
|
8
7
|
import { chatLogger } from '../config/logger'
|
|
9
8
|
import type { ValidationError } from '../effect/errors'
|
|
@@ -182,7 +181,6 @@ function generateRouterObjectEffect<TSchema extends z.ZodTypeAny>(params: {
|
|
|
182
181
|
try: () =>
|
|
183
182
|
generateObject({
|
|
184
183
|
model: params.aiGatewayModels.chatModel(modelId),
|
|
185
|
-
headers: buildAiGatewayDirectCacheHeaders('lota-sdk'),
|
|
186
184
|
schema: params.schema,
|
|
187
185
|
system: params.system,
|
|
188
186
|
prompt: params.prompt,
|
|
@@ -2,7 +2,6 @@ import type { CreateHelperToolLoopAgentOptions } from '@lota-sdk/shared'
|
|
|
2
2
|
import { ToolLoopAgent } from 'ai'
|
|
3
3
|
|
|
4
4
|
import type { AiGatewayModels } from '../ai-gateway/ai-gateway'
|
|
5
|
-
import { buildAiGatewayDirectCacheHeaders } from '../ai-gateway/cache-headers'
|
|
6
5
|
import {
|
|
7
6
|
OPENROUTER_FAST_REASONING_MODEL_ID,
|
|
8
7
|
OPENROUTER_MINIMAL_REASONING_PROVIDER_OPTIONS,
|
|
@@ -35,7 +34,6 @@ export function makeThreadTitleGeneratorAgentFactory(models: AiGatewayModels) {
|
|
|
35
34
|
new ToolLoopAgent({
|
|
36
35
|
id: 'thread-title-generator',
|
|
37
36
|
model: models.chatModel(OPENROUTER_FAST_REASONING_MODEL_ID),
|
|
38
|
-
headers: buildAiGatewayDirectCacheHeaders('lota-sdk'),
|
|
39
37
|
providerOptions: OPENROUTER_MINIMAL_REASONING_PROVIDER_OPTIONS,
|
|
40
38
|
...resolveHelperAgentOptions(options, {
|
|
41
39
|
instructions: THREAD_TITLE_GENERATOR_PROMPT,
|
|
@@ -3,7 +3,6 @@ import type { Effect } from 'effect'
|
|
|
3
3
|
|
|
4
4
|
import type { AiGatewayModels } from '../ai-gateway/ai-gateway'
|
|
5
5
|
import { aiGatewayChatModel, getDefaultAiGatewayRunPromise } from '../ai-gateway/ai-gateway'
|
|
6
|
-
import { buildAiGatewayStrictSemanticCacheHeaders } from '../ai-gateway/cache-headers'
|
|
7
6
|
import {
|
|
8
7
|
OPENROUTER_FAST_REASONING_MODEL_ID,
|
|
9
8
|
OPENROUTER_LOW_REASONING_PROVIDER_OPTIONS,
|
|
@@ -28,7 +27,6 @@ export const researchTopicTool = createDelegatedAgentToolWithContext<ResearchTop
|
|
|
28
27
|
? aiGatewayModels.chatModel(OPENROUTER_FAST_REASONING_MODEL_ID)
|
|
29
28
|
: aiGatewayChatModel(OPENROUTER_FAST_REASONING_MODEL_ID),
|
|
30
29
|
providerOptions: OPENROUTER_LOW_REASONING_PROVIDER_OPTIONS,
|
|
31
|
-
headers: buildAiGatewayStrictSemanticCacheHeaders('researchTopic'),
|
|
32
30
|
instructions: RESEARCHER_PROMPT,
|
|
33
31
|
createTools: ({ firecrawl, runPromise }) => ({
|
|
34
32
|
searchWeb: searchWebTool.create({ firecrawl, runPromise }),
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
const AI_GATEWAY_CACHE_KEY_HEADER = 'x-bf-cache-key'
|
|
2
|
-
const AI_GATEWAY_CACHE_TTL_HEADER = 'x-bf-cache-ttl'
|
|
3
|
-
const AI_GATEWAY_CACHE_THRESHOLD_HEADER = 'x-bf-cache-threshold'
|
|
4
|
-
const AI_GATEWAY_CACHE_TYPE_HEADER = 'x-bf-cache-type'
|
|
5
|
-
|
|
6
|
-
export const AI_GATEWAY_STRICT_SEMANTIC_CACHE_THRESHOLD = 0.975
|
|
7
|
-
|
|
8
|
-
export type AiGatewayCacheType = 'direct' | 'semantic'
|
|
9
|
-
|
|
10
|
-
export function toAiGatewayCacheKeyPart(value: string): string {
|
|
11
|
-
const normalized = value
|
|
12
|
-
.trim()
|
|
13
|
-
.toLowerCase()
|
|
14
|
-
.replace(/[^a-z0-9:_-]+/g, '-')
|
|
15
|
-
.replace(/-+/g, '-')
|
|
16
|
-
return normalized.replace(/^-+|-+$/g, '') || 'request'
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export function buildAiGatewayCacheHeaders(
|
|
20
|
-
cacheKey: string,
|
|
21
|
-
ttl?: string,
|
|
22
|
-
threshold?: number,
|
|
23
|
-
cacheType?: AiGatewayCacheType,
|
|
24
|
-
): Record<string, string> {
|
|
25
|
-
const headers: Record<string, string> = { [AI_GATEWAY_CACHE_KEY_HEADER]: cacheKey }
|
|
26
|
-
if (ttl) headers[AI_GATEWAY_CACHE_TTL_HEADER] = ttl
|
|
27
|
-
if (typeof threshold === 'number') headers[AI_GATEWAY_CACHE_THRESHOLD_HEADER] = String(threshold)
|
|
28
|
-
if (cacheType) headers[AI_GATEWAY_CACHE_TYPE_HEADER] = cacheType
|
|
29
|
-
return headers
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
export function buildAiGatewayDirectCacheHeaders(cacheKey: string, ttl?: string): Record<string, string> {
|
|
33
|
-
return buildAiGatewayCacheHeaders(cacheKey, ttl, undefined, 'direct')
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
export function buildAiGatewayStrictSemanticCacheHeaders(
|
|
37
|
-
cacheKey: string,
|
|
38
|
-
ttl?: string,
|
|
39
|
-
threshold = AI_GATEWAY_STRICT_SEMANTIC_CACHE_THRESHOLD,
|
|
40
|
-
): Record<string, string> {
|
|
41
|
-
return buildAiGatewayCacheHeaders(cacheKey, ttl, threshold, 'semantic')
|
|
42
|
-
}
|