@lota-sdk/core 0.1.20 → 0.1.21
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.1.
|
|
3
|
+
"version": "0.1.21",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./src/index.ts",
|
|
6
6
|
"types": "./src/index.ts",
|
|
@@ -32,11 +32,11 @@
|
|
|
32
32
|
"@chat-adapter/slack": "^4.23.0",
|
|
33
33
|
"@chat-adapter/state-ioredis": "^4.23.0",
|
|
34
34
|
"@logtape/logtape": "^2.0.5",
|
|
35
|
-
"@lota-sdk/shared": "0.1.
|
|
36
|
-
"@mendable/firecrawl-js": "^4.
|
|
35
|
+
"@lota-sdk/shared": "0.1.21",
|
|
36
|
+
"@mendable/firecrawl-js": "^4.18.0",
|
|
37
37
|
"@surrealdb/node": "^3.0.3",
|
|
38
|
-
"ai": "^6.0.
|
|
39
|
-
"bullmq": "^5.71.
|
|
38
|
+
"ai": "^6.0.141",
|
|
39
|
+
"bullmq": "^5.71.1",
|
|
40
40
|
"chat": "^4.23.0",
|
|
41
41
|
"cron-parser": "^5.5.0",
|
|
42
42
|
"hono": "^4.12.9",
|
|
@@ -349,7 +349,7 @@ function createAiGatewayFetch(extraParams?: AiGatewayExtraParams): typeof fetch
|
|
|
349
349
|
? injectAiGatewayExtraParamsRequestBody(bodyWithPromptCacheRetention, extraParams)
|
|
350
350
|
: bodyWithPromptCacheRetention
|
|
351
351
|
|
|
352
|
-
const headers = new Headers(init?.headers
|
|
352
|
+
const headers = new Headers(init?.headers)
|
|
353
353
|
if (extraParams !== undefined || (isAiGatewayOpenAIModelRequest(body) && hasAiGatewayPromptCacheRetention(body))) {
|
|
354
354
|
// Bifrost only forwards provider-specific extra params when passthrough is enabled.
|
|
355
355
|
headers.set(AI_GATEWAY_EXTRA_PARAMS_HEADER, 'true')
|
|
@@ -370,9 +370,7 @@ function createAiGatewayProvider(extraParams?: AiGatewayExtraParams) {
|
|
|
370
370
|
return createOpenAI({
|
|
371
371
|
baseURL,
|
|
372
372
|
apiKey,
|
|
373
|
-
headers: {
|
|
374
|
-
[AI_GATEWAY_VIRTUAL_KEY_HEADER]: apiKey,
|
|
375
|
-
},
|
|
373
|
+
headers: { [AI_GATEWAY_VIRTUAL_KEY_HEADER]: apiKey },
|
|
376
374
|
fetch: createAiGatewayFetch(extraParams),
|
|
377
375
|
})
|
|
378
376
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Queue, Worker } from 'bullmq'
|
|
2
|
+
import type { QueueOptions } from 'bullmq'
|
|
2
3
|
import type IORedis from 'ioredis'
|
|
3
4
|
|
|
4
5
|
import type { chatLogger } from '../config/logger'
|
|
@@ -70,22 +71,24 @@ export function createDocumentProcessorQueueRuntime<TJob extends DocumentProcess
|
|
|
70
71
|
enqueue: (job: TJob) => Promise<unknown>
|
|
71
72
|
startWorker: (options?: { registerSignals?: boolean }) => WorkerHandle
|
|
72
73
|
} {
|
|
74
|
+
type QueueShape = Queue<TJob, unknown, string, TJob, unknown, string>
|
|
75
|
+
|
|
73
76
|
const queueName = params.queueName ?? DEFAULT_DOCUMENT_PROCESSOR_QUEUE
|
|
74
77
|
const workerName = params.workerName ?? DEFAULT_WORKER_NAME
|
|
75
78
|
const concurrency = params.concurrency ?? 10
|
|
76
79
|
const lockDuration = params.lockDuration ?? 300_000
|
|
77
|
-
const jobName = 'process-document' as Parameters<
|
|
78
|
-
const toQueueData = (job: TJob): Parameters<
|
|
79
|
-
|
|
80
|
-
|
|
80
|
+
const jobName = 'process-document' as Parameters<QueueShape['add']>[0]
|
|
81
|
+
const toQueueData = (job: TJob): Parameters<QueueShape['add']>[1] => job
|
|
82
|
+
let queue: QueueShape | null = null
|
|
83
|
+
const getConnection = (): IORedis => params.getConnectionForBullMQ()
|
|
81
84
|
|
|
82
|
-
const getQueue = ():
|
|
85
|
+
const getQueue = (): QueueShape => {
|
|
83
86
|
if (queue) {
|
|
84
87
|
return queue
|
|
85
88
|
}
|
|
86
89
|
|
|
87
|
-
queue = new Queue<TJob, unknown, string>(queueName, {
|
|
88
|
-
connection:
|
|
90
|
+
queue = new Queue<TJob, unknown, string, TJob, unknown, string>(queueName, {
|
|
91
|
+
connection: getConnection() as QueueOptions['connection'],
|
|
89
92
|
defaultJobOptions: { ...DEFAULT_JOB_RETENTION, attempts: 3, backoff: { type: 'exponential', delay: 1000 } },
|
|
90
93
|
})
|
|
91
94
|
|
|
@@ -108,7 +111,7 @@ export function createDocumentProcessorQueueRuntime<TJob extends DocumentProcess
|
|
|
108
111
|
startWorker: (options = {}) => {
|
|
109
112
|
const { registerSignals = import.meta.main } = options
|
|
110
113
|
const worker = new Worker(queueName, params.getWorkerPath(), {
|
|
111
|
-
connection:
|
|
114
|
+
connection: getConnection() as QueueOptions['connection'],
|
|
112
115
|
concurrency,
|
|
113
116
|
lockDuration,
|
|
114
117
|
})
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Queue, Worker } from 'bullmq'
|
|
2
|
-
import type { Job, JobsOptions, WorkerOptions } from 'bullmq'
|
|
2
|
+
import type { Job, JobsOptions, QueueOptions, WorkerOptions } from 'bullmq'
|
|
3
3
|
import type IORedis from 'ioredis'
|
|
4
4
|
|
|
5
5
|
import { serverLogger } from '../config/logger'
|
|
@@ -39,18 +39,20 @@ interface QueueFactoryConfigFile extends QueueFactoryConfigBase {
|
|
|
39
39
|
export type QueueFactoryConfig<TJob> = QueueFactoryConfigInline<TJob> | QueueFactoryConfigFile
|
|
40
40
|
|
|
41
41
|
export interface QueueFactory<TJob> {
|
|
42
|
-
getQueue: () => Queue<TJob, unknown, string>
|
|
42
|
+
getQueue: () => Queue<TJob, unknown, string, TJob, unknown, string>
|
|
43
43
|
enqueue: (job: TJob, options?: JobsOptions) => Promise<void>
|
|
44
44
|
startWorker: (options?: { registerSignals?: boolean }) => WorkerHandle
|
|
45
45
|
}
|
|
46
46
|
|
|
47
47
|
export function createQueueFactory<TJob>(config: QueueFactoryConfig<TJob>): QueueFactory<TJob> {
|
|
48
|
-
|
|
48
|
+
type QueueShape = Queue<TJob, unknown, string, TJob, unknown, string>
|
|
49
|
+
|
|
50
|
+
let _queue: QueueShape | null = null
|
|
49
51
|
let _queueConnection: IORedis | null = null
|
|
50
52
|
|
|
51
|
-
const getConnection = () => config.connectionProvider?.() ?? getRedisConnectionForBullMQ()
|
|
53
|
+
const getConnection = (): IORedis => config.connectionProvider?.() ?? getRedisConnectionForBullMQ()
|
|
52
54
|
|
|
53
|
-
const getQueue = ():
|
|
55
|
+
const getQueue = (): QueueShape => {
|
|
54
56
|
const connection = getConnection()
|
|
55
57
|
const shouldRecreateQueue =
|
|
56
58
|
_queue === null ||
|
|
@@ -66,8 +68,8 @@ export function createQueueFactory<TJob>(config: QueueFactoryConfig<TJob>): Queu
|
|
|
66
68
|
})
|
|
67
69
|
}
|
|
68
70
|
|
|
69
|
-
_queue = new Queue<TJob, unknown, string>(config.name, {
|
|
70
|
-
connection,
|
|
71
|
+
_queue = new Queue<TJob, unknown, string, TJob, unknown, string>(config.name, {
|
|
72
|
+
connection: connection as QueueOptions['connection'],
|
|
71
73
|
defaultJobOptions: { ...DEFAULT_JOB_RETENTION, ...config.defaultJobOptions },
|
|
72
74
|
})
|
|
73
75
|
_queueConnection = connection
|
|
@@ -78,9 +80,8 @@ export function createQueueFactory<TJob>(config: QueueFactoryConfig<TJob>): Queu
|
|
|
78
80
|
return _queue
|
|
79
81
|
}
|
|
80
82
|
|
|
81
|
-
|
|
82
|
-
const
|
|
83
|
-
const toData = (job: TJob) => job as Parameters<QueueAdd>[1]
|
|
83
|
+
const jobName = config.jobName
|
|
84
|
+
const toData = (job: TJob) => job
|
|
84
85
|
|
|
85
86
|
const enqueue = async (job: TJob, options?: JobsOptions): Promise<void> => {
|
|
86
87
|
const queuedJob = await getQueue().add(jobName, toData(job), options)
|
|
@@ -99,7 +100,7 @@ export function createQueueFactory<TJob>(config: QueueFactoryConfig<TJob>): Queu
|
|
|
99
100
|
const { registerSignals = import.meta.main } = options
|
|
100
101
|
|
|
101
102
|
const workerOptions: WorkerOptions = {
|
|
102
|
-
connection: getConnection(),
|
|
103
|
+
connection: getConnection() as QueueOptions['connection'],
|
|
103
104
|
concurrency: config.concurrency,
|
|
104
105
|
...(config.lockDuration !== undefined ? { lockDuration: config.lockDuration } : {}),
|
|
105
106
|
...(config.stalledInterval !== undefined ? { stalledInterval: config.stalledInterval } : {}),
|