feat: chaite 初始化逻辑

This commit is contained in:
ikechan8370 2025-03-10 23:08:23 +08:00
parent 88312cdf38
commit fbcf4e6c08
16 changed files with 549 additions and 1269 deletions

View file

@ -1,18 +1,16 @@
import ChatGPTStorage from '../storage.js'
import { ChaiteStorage } from 'chaite'
/**
* @returns {import('chaite').ChatPresetsStorage}
* @extends {ChaiteStorage<import('chaite').ChatPreset>}
*/
export async function createChatPresetsStorage () {
return new LowDBChatPresetsStorage(ChatGPTStorage)
}
class LowDBChatPresetsStorage {
class LowDBChatPresetsStorage extends ChaiteStorage {
/**
*
* @param { LowDBStorage } storage
*/
constructor (storage) {
constructor (storage = ChatGPTStorage) {
super()
this.storage = storage
/**
* 集合
@ -23,31 +21,48 @@ class LowDBChatPresetsStorage {
/**
*
* @param {import('chaite').ChatPreset} preset
* @returns {Promise<void>}
* @param key
* @returns {Promise<import('chaite').ChatPreset>}
*/
async savePreset (preset) {
await this.collection.insert(preset)
async getItem (key) {
}
/**
*
* @param { string } name
* @returns {Promise<import('chaite').ChatPreset | null>}
* @param {string} id
* @param {import('chaite').ChatPreset} preset
* @returns {Promise<string>}
*/
async getPreset (name) {
return this.collection.findOne({ name })
async setItem (id, preset) {
if (id) {
await this.collection.updateById(id, preset)
return id
}
const result = await this.collection.insert(preset)
return result.id
}
/**
*
* @param {string} key
* @returns {Promise<void>}
*/
async removeItem (key) {
await this.collection.deleteById(key)
}
/**
*
* @returns {Promise<import('chaite').ChatPreset[]>}
*/
async getAllPresets () {
async listItems () {
return this.collection.findAll()
}
async deletePreset (name) {
await this.collection.delete({ name })
async clear () {
await this.collection.deleteAll()
}
}
export default new LowDBChatPresetsStorage()