feat: support ai context

This commit is contained in:
Gabe
2025-09-03 20:43:07 +08:00
parent b631703aa6
commit 343edcdbad
9 changed files with 241 additions and 55 deletions

View File

@@ -2,7 +2,7 @@ import {
DEFAULT_BATCH_INTERVAL,
DEFAULT_BATCH_SIZE,
DEFAULT_BATCH_LENGTH,
} from "../../config";
} from "../config";
/**
* 批处理队列
@@ -10,7 +10,7 @@ import {
* @param {*} param1
* @returns
*/
const batchQueue = (
const BatchQueue = (
{ taskFn, ...args },
{
batchInterval = DEFAULT_BATCH_INTERVAL,
@@ -141,7 +141,7 @@ export const getBatchQueue = (args, opts) => {
return queueMap.get(key);
}
const queue = batchQueue(args, opts);
const queue = BatchQueue(args, opts);
queueMap.set(key, queue);
return queue;
};
@@ -150,7 +150,7 @@ export const getBatchQueue = (args, opts) => {
* 清除所有任务
*/
export const clearAllBatchQueue = () => {
for (const queue of queueMap.entries()) {
for (const queue of queueMap.values()) {
queue.destroy();
}
};

View File

@@ -8,7 +8,7 @@ import { kissLog } from "./log";
* @param {*} _retryInteral
* @returns
*/
const taskPool = (_interval = 100, _limit = 100, _retryInteral = 1000) => {
const TaskPool = (_interval = 100, _limit = 100, _retryInteral = 1000) => {
const pool = [];
const maxRetry = 2; // 最大重试次数
let maxCount = _limit; // 最大数量
@@ -34,7 +34,7 @@ const taskPool = (_interval = 100, _limit = 100, _retryInteral = 1000) => {
if (retry < maxRetry) {
const retryTimer = setTimeout(() => {
clearTimeout(retryTimer);
pool.push({ args, resolve, reject, retry: retry + 1 });
pool.push({ fn, args, resolve, reject, retry: retry + 1 });
}, _retryInteral);
} else {
reject(err);
@@ -85,7 +85,7 @@ let fetchPool;
*/
export const getFetchPool = (interval, limit) => {
if (!fetchPool) {
fetchPool = taskPool(
fetchPool = TaskPool(
interval ?? DEFAULT_FETCH_INTERVAL,
limit ?? DEFAULT_FETCH_LIMIT
);