@huyooo/ai-chat-storage 0.2.18 → 0.2.20
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/dist/{chunk-CQ66EXL6.js → chunk-EXGLTJH4.js} +10 -28
- package/dist/chunk-V5E7YX6J.js +1 -0
- package/dist/index.d.ts +64 -3
- package/dist/index.js +1 -1
- package/dist/postgres-JFFEO52T.js +1 -0
- package/dist/sqlite-BVA3FN4Z.js +1 -0
- package/package.json +6 -3
- package/dist/chunk-6L6KHCOT.js +0 -1
- package/dist/postgres-CIPWMGYI.js +0 -1
- package/dist/sqlite-MZGQZHVI.js +0 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import e from"postgres";function s(e){return{id:e.id,appId:e.app_id,userId:e.user_id,title:e.title,model:e.model,mode:e.mode,webSearchEnabled:e.web_search_enabled,thinkingEnabled:e.thinking_enabled,hidden:e.hidden,createdAt:new Date(e.created_at),updatedAt:new Date(e.updated_at)}}function i(e){if(null===e.sequence||void 0===e.sequence)throw new Error(`消息 ${e.id} 缺少序号,数据损坏`);let s=[];if(e.images)try{const i=JSON.parse(e.images);Array.isArray(i)&&(s=i)}catch{}return{id:e.id,sessionId:e.session_id,appId:e.app_id,userId:e.user_id,role:e.role,content:e.content,images:s,model:e.model,mode:e.mode,webSearchEnabled:e.web_search_enabled,thinkingEnabled:e.thinking_enabled,steps:e.steps,operationIds:e.operation_ids,sequence:(s=>{if("number"==typeof s&&Number.isFinite(s))return s;if("string"==typeof s){const e=Number(s);if(Number.isFinite(e))return e}throw new Error(`消息 ${e.id} 的序号无效: ${s}`)})(e.sequence),timestamp:(s=>{if("number"==typeof s&&Number.isFinite(s))return s;if(s instanceof Date)return s.getTime();if("string"==typeof s){const e=Date.parse(s);if(!Number.isNaN(e))return e;const i=Number(s);if(Number.isFinite(i))return i}throw new Error(`消息 ${e.id} 的时间戳无效: ${s}`)})(e.timestamp)}}function t(e){return{id:e.id,sessionId:e.session_id,messageId:e.message_id,appId:e.app_id,userId:e.user_id,command:e.command,operationType:e.operation_type,affectedFiles:e.affected_files,backupPath:e.backup_path,status:e.status,errorMessage:e.error_message,timestamp:new Date(e.timestamp)}}function a(e){return{id:e.id,operationId:e.operation_id,originalPath:e.original_path,backupPath:e.backup_path,fileSize:e.file_size,fileHash:e.file_hash,createdAt:new Date(e.created_at),expiresAt:new Date(e.expires_at)}}function n(e){return{id:e.id,sessionId:e.session_id,appId:e.app_id,userId:e.user_id,originalPath:e.original_path,trashPath:e.trash_path,deletedAt:new Date(e.deleted_at),autoDeleteAt:new Date(e.auto_delete_at)}}async function d(e,s,i,t){const{limit:a=10,threshold:n=.7,sessionId:d}=i,r=`[${s.join(",")}]`;try{return(await(e`
|
|
1
|
+
import e from"postgres";function s(e){return{id:e.id,appId:e.app_id,userId:e.user_id,title:e.title,model:e.model,mode:e.mode,webSearchEnabled:e.web_search_enabled,thinkingEnabled:e.thinking_enabled,hidden:e.hidden,createdAt:new Date(e.created_at),updatedAt:new Date(e.updated_at)}}function i(e){if(null===e.sequence||void 0===e.sequence)throw new Error(`消息 ${e.id} 缺少序号,数据损坏`);let s=[];if(e.images)try{const i=JSON.parse(e.images);Array.isArray(i)&&(s=i)}catch{}return{id:e.id,clientId:e.client_id||e.id,sessionId:e.session_id,appId:e.app_id,userId:e.user_id,role:e.role,content:e.content,images:s,model:e.model,mode:e.mode,webSearchEnabled:e.web_search_enabled,thinkingEnabled:e.thinking_enabled,steps:e.steps,operationIds:e.operation_ids,usage:e.usage,duration:null!=e.duration?Number(e.duration):null,sequence:(s=>{if("number"==typeof s&&Number.isFinite(s))return s;if("string"==typeof s){const e=Number(s);if(Number.isFinite(e))return e}throw new Error(`消息 ${e.id} 的序号无效: ${s}`)})(e.sequence),timestamp:(s=>{if("number"==typeof s&&Number.isFinite(s))return s;if(s instanceof Date)return s.getTime();if("string"==typeof s){const e=Date.parse(s);if(!Number.isNaN(e))return e;const i=Number(s);if(Number.isFinite(i))return i}throw new Error(`消息 ${e.id} 的时间戳无效: ${s}`)})(e.timestamp)}}function t(e){return{id:e.id,sessionId:e.session_id,messageId:e.message_id,appId:e.app_id,userId:e.user_id,command:e.command,operationType:e.operation_type,affectedFiles:e.affected_files,backupPath:e.backup_path,status:e.status,errorMessage:e.error_message,timestamp:new Date(e.timestamp)}}function a(e){return{id:e.id,operationId:e.operation_id,originalPath:e.original_path,backupPath:e.backup_path,fileSize:e.file_size,fileHash:e.file_hash,createdAt:new Date(e.created_at),expiresAt:new Date(e.expires_at)}}function n(e){return{id:e.id,sessionId:e.session_id,appId:e.app_id,userId:e.user_id,originalPath:e.original_path,trashPath:e.trash_path,deletedAt:new Date(e.deleted_at),autoDeleteAt:new Date(e.auto_delete_at)}}async function d(e,s,i,t){const{limit:a=10,threshold:n=.7,sessionId:d}=i,r=`[${s.join(",")}]`;try{return(await(e`
|
|
2
2
|
SELECT id, content, content_type, metadata,
|
|
3
3
|
1 - (embedding <=> ${r}::vector) as similarity
|
|
4
4
|
FROM embeddings
|
|
@@ -43,7 +43,7 @@ import e from"postgres";function s(e){return{id:e.id,appId:e.app_id,userId:e.use
|
|
|
43
43
|
sequence INTEGER,
|
|
44
44
|
timestamp TIMESTAMPTZ NOT NULL DEFAULT NOW()
|
|
45
45
|
)
|
|
46
|
-
`);try{await(e`ALTER TABLE messages ADD COLUMN IF NOT EXISTS sequence INTEGER`)}catch{}try{await(e`ALTER TABLE messages ADD COLUMN IF NOT EXISTS images TEXT`)}catch{}try{await(e`
|
|
46
|
+
`);try{await(e`ALTER TABLE messages ADD COLUMN IF NOT EXISTS sequence INTEGER`)}catch{}try{await(e`ALTER TABLE messages ADD COLUMN IF NOT EXISTS images TEXT`)}catch{}try{await(e`ALTER TABLE messages ADD COLUMN IF NOT EXISTS usage TEXT`)}catch{}try{await(e`ALTER TABLE messages ADD COLUMN IF NOT EXISTS duration INTEGER`)}catch{}try{await(e`
|
|
47
47
|
UPDATE messages
|
|
48
48
|
SET sequence = sub.rank
|
|
49
49
|
FROM (
|
|
@@ -171,14 +171,14 @@ import e from"postgres";function s(e){return{id:e.id,appId:e.app_id,userId:e.use
|
|
|
171
171
|
AND (${i.appId||null}::TEXT IS NULL OR app_id = ${i.appId||null})
|
|
172
172
|
AND (${i.userId||null}::TEXT IS NULL OR user_id = ${i.userId||null})
|
|
173
173
|
`)}(this.sql,e,s)}async getMessages(e,s){await this.ensureInitialized();return await this.getSession(e,s)?async function(e,s){return(await(e`
|
|
174
|
-
SELECT id, session_id, app_id, user_id, role, content, images, model, mode,
|
|
175
|
-
web_search_enabled, thinking_enabled, steps, operation_ids, sequence, timestamp
|
|
174
|
+
SELECT id, client_id, session_id, app_id, user_id, role, content, images, model, mode,
|
|
175
|
+
web_search_enabled, thinking_enabled, steps, operation_ids, usage, duration, sequence, timestamp
|
|
176
176
|
FROM messages
|
|
177
177
|
WHERE session_id = ${s}
|
|
178
178
|
ORDER BY sequence NULLS LAST, timestamp
|
|
179
179
|
`)).map(i)}(this.sql,e):[]}async getMessage(e,s){return await this.ensureInitialized(),async function(e,s,t){const a=await(e`
|
|
180
|
-
SELECT id, session_id, app_id, user_id, role, content, images, model, mode,
|
|
181
|
-
web_search_enabled, thinking_enabled, steps, operation_ids, sequence, timestamp
|
|
180
|
+
SELECT id, client_id, session_id, app_id, user_id, role, content, images, model, mode,
|
|
181
|
+
web_search_enabled, thinking_enabled, steps, operation_ids, usage, duration, sequence, timestamp
|
|
182
182
|
FROM messages
|
|
183
183
|
WHERE id = ${s}
|
|
184
184
|
AND (${t.appId||null}::TEXT IS NULL OR app_id = ${t.appId||null})
|
|
@@ -187,28 +187,10 @@ import e from"postgres";function s(e){return{id:e.id,appId:e.app_id,userId:e.use
|
|
|
187
187
|
SELECT MAX(sequence) as max_seq
|
|
188
188
|
FROM messages
|
|
189
189
|
WHERE session_id = ${s}
|
|
190
|
-
`),t=i[0]?.max_seq;return null!=t?t:0}(e,s.sessionId),d=n+1,r=s.images&&s.images.length>0?JSON.stringify(s.images):null;return await(e`
|
|
191
|
-
INSERT INTO messages (id, session_id, app_id, user_id, role, content, images, model, mode, web_search_enabled, thinking_enabled, steps, operation_ids, sequence, timestamp)
|
|
192
|
-
VALUES (${s.id}, ${s.sessionId}, ${i.appId||null}, ${i.userId||null}, ${s.role}, ${s.content}, ${r}, ${s.model}, ${s.mode}, ${s.webSearchEnabled}, ${s.thinkingEnabled}, ${s.steps}, ${s.operationIds}, ${d}, ${a})
|
|
193
|
-
`),await(e`UPDATE sessions SET updated_at = ${a} WHERE id = ${s.sessionId}`),{id:s.id,sessionId:s.sessionId,appId:i.appId||null,userId:i.userId||null,role:s.role,content:s.content,images:s.images||[],model:s.model,mode:s.mode,webSearchEnabled:s.webSearchEnabled,thinkingEnabled:s.thinkingEnabled,steps:s.steps,operationIds:s.operationIds,sequence:d,timestamp:t}}(this.sql,e,s)}async updateMessage(e,s,i){await this.ensureInitialized(),await async function(e,s,i,t){const a=[];void 0!==i.content&&a.push("content"),void 0!==i.steps&&a.push("steps"),0!==
|
|
194
|
-
UPDATE messages
|
|
195
|
-
SET content = ${i.content}, steps = ${i.steps}
|
|
196
|
-
WHERE id = ${s}
|
|
197
|
-
AND (${t.appId||null}::TEXT IS NULL OR app_id = ${t.appId||null})
|
|
198
|
-
AND (${t.userId||null}::TEXT IS NULL OR user_id = ${t.userId||null})
|
|
199
|
-
`):void 0!==i.content?await(e`
|
|
200
|
-
UPDATE messages
|
|
201
|
-
SET content = ${i.content}
|
|
202
|
-
WHERE id = ${s}
|
|
203
|
-
AND (${t.appId||null}::TEXT IS NULL OR app_id = ${t.appId||null})
|
|
204
|
-
AND (${t.userId||null}::TEXT IS NULL OR user_id = ${t.userId||null})
|
|
205
|
-
`):void 0!==i.steps&&await(e`
|
|
206
|
-
UPDATE messages
|
|
207
|
-
SET steps = ${i.steps}
|
|
208
|
-
WHERE id = ${s}
|
|
209
|
-
AND (${t.appId||null}::TEXT IS NULL OR app_id = ${t.appId||null})
|
|
210
|
-
AND (${t.userId||null}::TEXT IS NULL OR user_id = ${t.userId||null})
|
|
211
|
-
`))}(this.sql,e,s,i)}async deleteMessagesAfter(e,s,i){await this.ensureInitialized();await this.getSession(e,i)&&await async function(e,s,i){await(e`
|
|
190
|
+
`),t=i[0]?.max_seq;return null!=t?t:0}(e,s.sessionId),d=n+1,r=s.images&&s.images.length>0?JSON.stringify(s.images):null,u=s.clientId||s.id;return await(e`
|
|
191
|
+
INSERT INTO messages (id, client_id, session_id, app_id, user_id, role, content, images, model, mode, web_search_enabled, thinking_enabled, steps, operation_ids, sequence, timestamp)
|
|
192
|
+
VALUES (${s.id}, ${u}, ${s.sessionId}, ${i.appId||null}, ${i.userId||null}, ${s.role}, ${s.content}, ${r}, ${s.model}, ${s.mode}, ${s.webSearchEnabled}, ${s.thinkingEnabled}, ${s.steps}, ${s.operationIds}, ${d}, ${a})
|
|
193
|
+
`),await(e`UPDATE sessions SET updated_at = ${a} WHERE id = ${s.sessionId}`),{id:s.id,clientId:u,sessionId:s.sessionId,appId:i.appId||null,userId:i.userId||null,role:s.role,content:s.content,images:s.images||[],model:s.model,mode:s.mode,webSearchEnabled:s.webSearchEnabled,thinkingEnabled:s.thinkingEnabled,steps:s.steps,operationIds:s.operationIds,sequence:d,timestamp:t}}(this.sql,e,s)}async updateMessage(e,s,i){await this.ensureInitialized(),await async function(e,s,i,t){const a=[],n=[];let d=1;if(void 0!==i.content&&(a.push("content = $"+d++),n.push(i.content)),void 0!==i.steps&&(a.push("steps = $"+d++),n.push(i.steps)),void 0!==i.operationIds&&(a.push("operation_ids = $"+d++),n.push(i.operationIds)),void 0!==i.usage&&(a.push("usage = $"+d++),n.push(i.usage)),void 0!==i.duration&&(a.push("duration = $"+d++),n.push(i.duration)),0===a.length)return;const r=`WHERE id = $${d++}${t.appId?" AND app_id = $"+d++:""}${t.userId?" AND user_id = $"+d++:""}`;n.push(s),t.appId&&n.push(t.appId),t.userId&&n.push(t.userId),await e.unsafe(`UPDATE messages SET ${a.join(", ")} ${r}`,n)}(this.sql,e,s,i)}async deleteMessagesAfter(e,s,i){await this.ensureInitialized();await this.getSession(e,i)&&await async function(e,s,i){await(e`
|
|
212
194
|
DELETE FROM messages
|
|
213
195
|
WHERE session_id = ${s}
|
|
214
196
|
AND timestamp > ${i}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{drizzle as e}from"drizzle-orm/better-sqlite3";import s from"better-sqlite3";import{sqliteTable as t,text as n,integer as i,index as a}from"drizzle-orm/sqlite-core";var d=t("sessions",{id:n("id").primaryKey(),appId:n("app_id"),userId:n("user_id"),title:n("title").notNull(),model:n("model").notNull(),mode:n("mode").notNull(),webSearchEnabled:i("web_search_enabled",{mode:"boolean"}).notNull().default(!0),thinkingEnabled:i("thinking_enabled",{mode:"boolean"}).notNull().default(!0),hidden:i("hidden",{mode:"boolean"}).notNull().default(!1),createdAt:i("created_at",{mode:"timestamp"}).notNull(),updatedAt:i("updated_at",{mode:"timestamp"}).notNull()},e=>[a("idx_sessions_tenant").on(e.appId,e.userId),a("idx_sessions_updated").on(e.updatedAt)]),r=t("messages",{id:n("id").primaryKey(),clientId:n("client_id"),sessionId:n("session_id").notNull(),appId:n("app_id"),userId:n("user_id"),role:n("role").notNull(),content:n("content").notNull(),images:n("images"),model:n("model"),mode:n("mode"),webSearchEnabled:i("web_search_enabled",{mode:"boolean"}),thinkingEnabled:i("thinking_enabled",{mode:"boolean"}),steps:n("steps"),operationIds:n("operation_ids"),usage:n("usage"),duration:i("duration"),sequence:i("sequence").notNull(),timestamp:i("timestamp",{mode:"timestamp"}).notNull()},e=>[a("idx_messages_session").on(e.sessionId),a("idx_messages_tenant").on(e.appId,e.userId),a("idx_messages_sequence").on(e.sessionId,e.sequence)]),o=t("operations",{id:n("id").primaryKey(),sessionId:n("session_id").notNull(),messageId:n("message_id"),appId:n("app_id"),userId:n("user_id"),command:n("command").notNull(),operationType:n("operation_type").notNull(),affectedFiles:n("affected_files").notNull(),backupPath:n("backup_path"),status:n("status").notNull().default("pending"),errorMessage:n("error_message"),timestamp:i("timestamp",{mode:"timestamp"}).notNull()},e=>[a("idx_operations_session").on(e.sessionId),a("idx_operations_message").on(e.messageId),a("idx_operations_tenant").on(e.appId,e.userId)]),u=t("backups",{id:n("id").primaryKey(),operationId:n("operation_id").notNull(),originalPath:n("original_path").notNull(),backupPath:n("backup_path").notNull(),fileSize:i("file_size").notNull(),fileHash:n("file_hash").notNull(),createdAt:i("created_at",{mode:"timestamp"}).notNull(),expiresAt:i("expires_at",{mode:"timestamp"}).notNull()},e=>[a("idx_backups_operation").on(e.operationId),a("idx_backups_expires").on(e.expiresAt)]),l=t("trash",{id:n("id").primaryKey(),sessionId:n("session_id").notNull(),appId:n("app_id"),userId:n("user_id"),originalPath:n("original_path").notNull(),trashPath:n("trash_path").notNull(),deletedAt:i("deleted_at",{mode:"timestamp"}).notNull(),autoDeleteAt:i("auto_delete_at",{mode:"timestamp"}).notNull()},e=>[a("idx_trash_tenant").on(e.appId,e.userId),a("idx_trash_auto_delete").on(e.autoDeleteAt)]),p=t("embeddings",{id:n("id").primaryKey(),sessionId:n("session_id").notNull(),messageId:n("message_id"),appId:n("app_id"),userId:n("user_id"),content:n("content").notNull(),contentType:n("content_type").notNull(),embedding:n("embedding"),metadata:n("metadata"),createdAt:i("created_at",{mode:"timestamp"}).notNull()},e=>[a("idx_embeddings_session").on(e.sessionId),a("idx_embeddings_tenant").on(e.appId,e.userId)]);import{eq as c,and as T}from"drizzle-orm";function E(e){const s=[];return e.appId&&s.push(c(d.appId,e.appId)),e.userId&&s.push(c(d.userId,e.userId)),s.length>0?T(...s):void 0}function m(e){const s=[];return e.appId&&s.push(c(r.appId,e.appId)),e.userId&&s.push(c(r.userId,e.userId)),s.length>0?T(...s):void 0}function I(e){const s=[];return e.appId&&s.push(c(l.appId,e.appId)),e.userId&&s.push(c(l.userId,e.userId)),s.length>0?T(...s):void 0}import{eq as h,and as N,desc as _}from"drizzle-orm";function g(e){return{id:e.id,appId:e.appId,userId:e.userId,title:e.title,model:e.model,mode:e.mode,webSearchEnabled:e.webSearchEnabled,thinkingEnabled:e.thinkingEnabled,hidden:e.hidden,createdAt:e.createdAt,updatedAt:e.updatedAt}}import{eq as b,and as L,gt as A,max as f}from"drizzle-orm";function O(e){if(null===e.sequence||void 0===e.sequence)throw new Error(`消息 ${e.id} 缺少序号,数据损坏`);let s=[];if(e.images)try{const t=JSON.parse(e.images);Array.isArray(t)&&(s=t)}catch{}return{id:e.id,clientId:e.clientId||e.id,sessionId:e.sessionId,appId:e.appId,userId:e.userId,role:e.role,content:e.content,images:s,model:e.model,mode:e.mode,webSearchEnabled:e.webSearchEnabled,thinkingEnabled:e.thinkingEnabled,steps:e.steps,operationIds:e.operationIds,usage:e.usage,duration:e.duration,sequence:(s=>{if("number"==typeof s&&Number.isFinite(s))return s;if("string"==typeof s){const e=Number(s);if(Number.isFinite(e))return e}throw new Error(`消息 ${e.id} 的序号无效: ${s}`)})(e.sequence),timestamp:(s=>{if("number"==typeof s&&Number.isFinite(s))return s;if(s instanceof Date)return s.getTime();if("string"==typeof s){const e=Date.parse(s);if(!Number.isNaN(e))return e;const t=Number(s);if(Number.isFinite(t))return t}throw new Error(`消息 ${e.id} 的时间戳无效: ${s}`)})(e.timestamp)}}function S(e,s,t){const n=Date.now(),i=function(e,s){const t=e.select({maxSeq:f(r.sequence)}).from(r).where(b(r.sessionId,s)).get();return t?.maxSeq??0}(e,s.sessionId)+1,a={id:s.id,clientId:s.clientId||s.id,sessionId:s.sessionId,appId:t.appId||null,userId:t.userId||null,role:s.role,content:s.content,images:s.images||[],model:s.model,mode:s.mode,webSearchEnabled:s.webSearchEnabled,thinkingEnabled:s.thinkingEnabled,steps:s.steps,operationIds:s.operationIds,sequence:i,timestamp:n};return e.insert(r).values({id:a.id,clientId:a.clientId,sessionId:a.sessionId,appId:a.appId,userId:a.userId,role:a.role,content:a.content,images:a.images.length>0?JSON.stringify(a.images):null,model:a.model,mode:a.mode,webSearchEnabled:a.webSearchEnabled,thinkingEnabled:a.thinkingEnabled,steps:a.steps,operationIds:a.operationIds,sequence:a.sequence,timestamp:new Date(a.timestamp)}).run(),e.update(d).set({updatedAt:new Date(n)}).where(b(d.id,s.sessionId)).run(),a}import{eq as y,and as R}from"drizzle-orm";function X(e){return{id:e.id,sessionId:e.sessionId,messageId:e.messageId,appId:e.appId,userId:e.userId,command:e.command,operationType:e.operationType,affectedFiles:e.affectedFiles,backupPath:e.backupPath,status:e.status,errorMessage:e.errorMessage,timestamp:e.timestamp}}function D(e,s,t){const n=function(e){const s=[];return e.appId&&s.push(c(o.appId,e.appId)),e.userId&&s.push(c(o.userId,e.userId)),s.length>0?T(...s):void 0}(t),i=n?R(y(o.messageId,s),n):y(o.messageId,s);return e.select().from(o).where(i).all().map(X)}import{eq as w,lt as U}from"drizzle-orm";function x(e){return{id:e.id,operationId:e.operationId,originalPath:e.originalPath,backupPath:e.backupPath,fileSize:e.fileSize,fileHash:e.fileHash,createdAt:e.createdAt,expiresAt:e.expiresAt}}import{eq as k,and as q,desc as F,lt as M}from"drizzle-orm";function C(e){return{id:e.id,sessionId:e.sessionId,appId:e.appId,userId:e.userId,originalPath:e.originalPath,trashPath:e.trashPath,deletedAt:e.deletedAt,autoDeleteAt:e.autoDeleteAt}}import{eq as v,and as P}from"drizzle-orm";function B(e,s,t,n){const{limit:i=10,threshold:a=.7,sessionId:d}=t,r=[];n.appId&&r.push(v(p.appId,n.appId)),n.userId&&r.push(v(p.userId,n.userId)),d&&r.push(v(p.sessionId,d));return e.select().from(p).where(r.length>0?P(...r):void 0).all().map(e=>{const t=e.embedding?JSON.parse(e.embedding):[],n=function(e,s){if(e.length!==s.length)return 0;let t=0,n=0,i=0;for(let a=0;a<e.length;a++)t+=e[a]*s[a],n+=e[a]*e[a],i+=s[a]*s[a];return 0===n||0===i?0:t/(Math.sqrt(n)*Math.sqrt(i))}(s,t);return{id:e.id,content:e.content,contentType:e.contentType,similarity:n,metadata:e.metadata?JSON.parse(e.metadata):void 0}}).filter(e=>e.similarity>=a).sort((e,s)=>s.similarity-e.similarity).slice(0,i)}var G=class{sqlite;db;config;get sqliteInstance(){return this.sqlite}constructor(t,n={type:"sqlite"}){this.sqlite=new s(t),this.db=e(this.sqlite),this.config=n,function(e){e.exec("\n CREATE TABLE IF NOT EXISTS sessions (\n id TEXT PRIMARY KEY,\n app_id TEXT,\n user_id TEXT,\n title TEXT NOT NULL,\n model TEXT NOT NULL,\n mode TEXT NOT NULL,\n web_search_enabled INTEGER NOT NULL DEFAULT 1,\n thinking_enabled INTEGER NOT NULL DEFAULT 1,\n hidden INTEGER NOT NULL DEFAULT 0,\n created_at INTEGER NOT NULL,\n updated_at INTEGER NOT NULL\n );\n\n CREATE TABLE IF NOT EXISTS messages (\n id TEXT PRIMARY KEY,\n client_id TEXT,\n session_id TEXT NOT NULL,\n app_id TEXT,\n user_id TEXT,\n role TEXT NOT NULL,\n content TEXT NOT NULL,\n images TEXT,\n model TEXT,\n mode TEXT,\n web_search_enabled INTEGER,\n thinking_enabled INTEGER,\n steps TEXT,\n operation_ids TEXT,\n usage TEXT,\n duration INTEGER,\n sequence INTEGER,\n timestamp INTEGER NOT NULL\n );\n\n CREATE TABLE IF NOT EXISTS operations (\n id TEXT PRIMARY KEY,\n session_id TEXT NOT NULL,\n message_id TEXT,\n app_id TEXT,\n user_id TEXT,\n command TEXT NOT NULL,\n operation_type TEXT NOT NULL,\n affected_files TEXT NOT NULL,\n backup_path TEXT,\n status TEXT NOT NULL DEFAULT 'pending',\n error_message TEXT,\n timestamp INTEGER NOT NULL\n );\n\n CREATE TABLE IF NOT EXISTS backups (\n id TEXT PRIMARY KEY,\n operation_id TEXT NOT NULL,\n original_path TEXT NOT NULL,\n backup_path TEXT NOT NULL,\n file_size INTEGER NOT NULL,\n file_hash TEXT NOT NULL,\n created_at INTEGER NOT NULL,\n expires_at INTEGER NOT NULL\n );\n\n CREATE TABLE IF NOT EXISTS trash (\n id TEXT PRIMARY KEY,\n session_id TEXT NOT NULL,\n app_id TEXT,\n user_id TEXT,\n original_path TEXT NOT NULL,\n trash_path TEXT NOT NULL,\n deleted_at INTEGER NOT NULL,\n auto_delete_at INTEGER NOT NULL\n );\n\n CREATE TABLE IF NOT EXISTS embeddings (\n id TEXT PRIMARY KEY,\n session_id TEXT NOT NULL,\n message_id TEXT,\n app_id TEXT,\n user_id TEXT,\n content TEXT NOT NULL,\n content_type TEXT NOT NULL,\n embedding TEXT,\n metadata TEXT,\n created_at INTEGER NOT NULL\n );\n\n CREATE TABLE IF NOT EXISTS user_settings (\n id TEXT PRIMARY KEY,\n app_id TEXT,\n user_id TEXT,\n key TEXT NOT NULL,\n value TEXT NOT NULL,\n created_at INTEGER NOT NULL,\n updated_at INTEGER NOT NULL,\n UNIQUE(app_id, user_id, key)\n );\n\n -- 索引\n CREATE INDEX IF NOT EXISTS idx_sessions_tenant ON sessions(app_id, user_id);\n CREATE INDEX IF NOT EXISTS idx_sessions_updated ON sessions(updated_at);\n CREATE INDEX IF NOT EXISTS idx_messages_session ON messages(session_id);\n CREATE INDEX IF NOT EXISTS idx_messages_tenant ON messages(app_id, user_id);\n CREATE INDEX IF NOT EXISTS idx_operations_session ON operations(session_id);\n CREATE INDEX IF NOT EXISTS idx_operations_message ON operations(message_id);\n CREATE INDEX IF NOT EXISTS idx_backups_operation ON backups(operation_id);\n CREATE INDEX IF NOT EXISTS idx_backups_expires ON backups(expires_at);\n CREATE INDEX IF NOT EXISTS idx_trash_tenant ON trash(app_id, user_id);\n CREATE INDEX IF NOT EXISTS idx_trash_auto_delete ON trash(auto_delete_at);\n CREATE INDEX IF NOT EXISTS idx_embeddings_session ON embeddings(session_id);\n CREATE INDEX IF NOT EXISTS idx_user_settings_tenant ON user_settings(app_id, user_id);\n CREATE INDEX IF NOT EXISTS idx_user_settings_key ON user_settings(key);\n ");try{e.exec("ALTER TABLE messages ADD COLUMN client_id TEXT")}catch{}try{e.exec("ALTER TABLE sessions ADD COLUMN web_search_enabled INTEGER NOT NULL DEFAULT 1")}catch{}try{e.exec("ALTER TABLE sessions ADD COLUMN thinking_enabled INTEGER NOT NULL DEFAULT 1")}catch{}try{e.exec("ALTER TABLE messages ADD COLUMN model TEXT")}catch{}try{e.exec("ALTER TABLE messages ADD COLUMN mode TEXT")}catch{}try{e.exec("ALTER TABLE messages ADD COLUMN web_search_enabled INTEGER")}catch{}try{e.exec("ALTER TABLE messages ADD COLUMN thinking_enabled INTEGER")}catch{}try{e.exec("ALTER TABLE sessions ADD COLUMN hidden INTEGER NOT NULL DEFAULT 0")}catch{}try{e.exec("ALTER TABLE messages ADD COLUMN steps TEXT")}catch{}try{e.exec("ALTER TABLE messages ADD COLUMN sequence INTEGER")}catch{}try{e.exec("ALTER TABLE messages ADD COLUMN images TEXT")}catch{}try{e.exec("ALTER TABLE messages ADD COLUMN usage TEXT")}catch{}try{e.exec("ALTER TABLE messages ADD COLUMN duration INTEGER")}catch{}try{e.exec("\n UPDATE messages\n SET sequence = (\n SELECT COUNT(*) + 1\n FROM messages m2\n WHERE m2.session_id = messages.session_id\n AND (m2.timestamp < messages.timestamp\n OR (m2.timestamp = messages.timestamp AND m2.id < messages.id))\n )\n WHERE sequence IS NULL\n ")}catch{}try{e.exec("\n UPDATE messages\n SET sequence = (\n SELECT COUNT(*) + 1\n FROM messages m2\n WHERE m2.session_id = messages.session_id\n AND (m2.timestamp < messages.timestamp\n OR (m2.timestamp = messages.timestamp AND m2.id < messages.id))\n )\n WHERE sequence IS NULL\n "),e.exec("\n UPDATE messages\n SET sequence = (\n SELECT COALESCE(MAX(sequence), 0) + 1\n FROM messages m2\n WHERE m2.session_id = messages.session_id\n )\n WHERE sequence IS NULL\n ")}catch{}try{e.exec("CREATE INDEX IF NOT EXISTS idx_messages_sequence ON messages(session_id, sequence)")}catch{}}(this.sqlite)}async getSessions(e){return function(e,s){const t=E(s);return e.select().from(d).where(t).orderBy(_(d.updatedAt)).all().map(g)}(this.db,e)}async getSession(e,s){return function(e,s,t){const n=E(t),i=n?N(h(d.id,s),n):h(d.id,s),a=e.select().from(d).where(i).get();return a?g(a):null}(this.db,e,s)}async createSession(e,s){return function(e,s,t){const n=new Date,i={id:s.id,appId:t.appId||null,userId:t.userId||null,title:s.title,model:s.model,mode:s.mode,webSearchEnabled:s.webSearchEnabled,thinkingEnabled:s.thinkingEnabled,hidden:s.hidden??!1,createdAt:n,updatedAt:n};return e.insert(d).values({id:i.id,appId:i.appId,userId:i.userId,title:i.title,model:i.model,mode:i.mode,webSearchEnabled:i.webSearchEnabled,thinkingEnabled:i.thinkingEnabled,hidden:i.hidden,createdAt:i.createdAt,updatedAt:i.updatedAt}).run(),i}(this.db,e,s)}async updateSession(e,s,t){!function(e,s,t,n){const i=E(n),a=i?N(h(d.id,s),i):h(d.id,s),r={updatedAt:new Date};void 0!==t.title&&(r.title=t.title),void 0!==t.model&&(r.model=t.model),void 0!==t.mode&&(r.mode=t.mode),void 0!==t.webSearchEnabled&&(r.webSearchEnabled=t.webSearchEnabled),void 0!==t.thinkingEnabled&&(r.thinkingEnabled=t.thinkingEnabled),void 0!==t.hidden&&(r.hidden=t.hidden),e.update(d).set(r).where(a).run()}(this.db,e,s,t)}async deleteSession(e,s){var t,n;t=this.db,n=e,t.delete(r).where(b(r.sessionId,n)).run(),function(e,s){e.delete(o).where(y(o.sessionId,s)).run()}(this.db,e),function(e,s){e.delete(p).where(v(p.sessionId,s)).run()}(this.db,e),function(e,s,t){const n=E(t),i=n?N(h(d.id,s),n):h(d.id,s);e.delete(d).where(i).run()}(this.db,e,s)}async getMessages(e,s){return await this.getSession(e,s)?function(e,s){return e.select().from(r).where(b(r.sessionId,s)).orderBy(r.sequence,r.timestamp).all().map(O)}(this.db,e):[]}async getMessage(e,s){return function(e,s,t){const n=m(t),i=n?L(b(r.id,s),n):b(r.id,s),a=e.select().from(r).where(i).get();return a?O(a):null}(this.db,e,s)}async saveMessage(e,s){return S(this.db,e,s)}async updateMessage(e,s,t){!function(e,s,t,n){const i=m(n),a=i?L(b(r.id,s),i):b(r.id,s),d={};void 0!==t.content&&(d.content=t.content),void 0!==t.steps&&(d.steps=t.steps),void 0!==t.operationIds&&(d.operationIds=t.operationIds),void 0!==t.usage&&(d.usage=t.usage),void 0!==t.duration&&(d.duration=t.duration),Object.keys(d).length>0&&e.update(r).set(d).where(a).run()}(this.db,e,s,t)}async deleteMessagesAfter(e,s,t){await this.getSession(e,t)&&function(e,s,t){e.delete(r).where(L(b(r.sessionId,s),A(r.timestamp,t))).run()}(this.db,e,s)}async deleteMessagesAfterMessageId(e,s,t){if(!await this.getSession(e,t))return;const n=await this.getMessage(s,t);if(n&&n.sessionId===e){if(null===n.sequence||void 0===n.sequence)throw new Error(`消息 ${s} 缺少序号,无法删除后续消息`);!function(e,s,t,n){if(null==n)throw new Error(`消息 ${t} 缺少序号,无法删除后续消息`);e.delete(r).where(L(b(r.sessionId,s),A(r.sequence,n))).run()}(this.db,e,s,n.sequence)}}async getOperations(e,s){return await this.getSession(e,s)?function(e,s){return e.select().from(o).where(y(o.sessionId,s)).orderBy(o.timestamp).all().map(X)}(this.db,e):[]}async getOperationsByMessage(e,s){return D(this.db,e,s)}async saveOperation(e,s){return function(e,s,t){const n=new Date,i={id:s.id,sessionId:s.sessionId,messageId:s.messageId,appId:t.appId||null,userId:t.userId||null,command:s.command,operationType:s.operationType,affectedFiles:s.affectedFiles,backupPath:s.backupPath,status:s.status||"pending",errorMessage:null,timestamp:n};return e.insert(o).values({id:i.id,sessionId:i.sessionId,messageId:i.messageId,appId:i.appId,userId:i.userId,command:i.command,operationType:i.operationType,affectedFiles:i.affectedFiles,backupPath:i.backupPath,status:i.status,errorMessage:i.errorMessage,timestamp:i.timestamp}).run(),i}(this.db,e,s)}async updateOperationStatus(e,s,t){!function(e,s,t,n){const i={status:t};void 0!==n&&(i.errorMessage=n),e.update(o).set(i).where(y(o.id,s)).run()}(this.db,e,s,t)}async getBackups(e){return function(e,s){return e.select().from(u).where(w(u.operationId,s)).all().map(x)}(this.db,e)}async saveBackup(e){return function(e,s){const t={...s,createdAt:new Date};return e.insert(u).values({id:t.id,operationId:t.operationId,originalPath:t.originalPath,backupPath:t.backupPath,fileSize:t.fileSize,fileHash:t.fileHash,createdAt:t.createdAt,expiresAt:t.expiresAt}).run(),t}(this.db,e)}async deleteExpiredBackups(){return function(e){const s=new Date;return e.delete(u).where(U(u.expiresAt,s)).run().changes}(this.db)}async getTrashItems(e){return function(e,s){const t=I(s);return e.select().from(l).where(t).orderBy(F(l.deletedAt)).all().map(C)}(this.db,e)}async moveToTrash(e,s){return function(e,s,t,n){const i=new Date,a=n.trashRetentionDays||30,d=new Date(i.getTime()+24*a*60*60*1e3),r={...s,appId:t.appId||null,userId:t.userId||null,deletedAt:i,autoDeleteAt:d};return e.insert(l).values({id:r.id,sessionId:r.sessionId,appId:r.appId,userId:r.userId,originalPath:r.originalPath,trashPath:r.trashPath,deletedAt:r.deletedAt,autoDeleteAt:r.autoDeleteAt}).run(),r}(this.db,e,s,this.config)}async restoreFromTrash(e,s){return function(e,s,t){const n=I(t),i=n?q(k(l.id,s),n):k(l.id,s),a=e.select().from(l).where(i).get();if(!a)throw new Error("回收站记录不存在");return e.delete(l).where(k(l.id,s)).run(),C(a)}(this.db,e,s)}async emptyExpiredTrash(){return function(e){const s=new Date;return e.delete(l).where(M(l.autoDeleteAt,s)).run().changes}(this.db)}async saveEmbedding(e,s,t,n,i){!function(e,s,t,n,i,a){const d=new Date;e.insert(p).values({id:s,sessionId:i.sessionId,messageId:i.messageId||null,appId:a.appId||null,userId:a.userId||null,content:t,contentType:i.contentType,embedding:JSON.stringify(n),metadata:JSON.stringify(i),createdAt:d}).run()}(this.db,e,s,t,n,i)}async searchSimilar(e,s,t){return B(this.db,e,s,t)}async getUserSetting(e,s){return function(e,s,t){const n=e.prepare("\n SELECT value FROM user_settings\n WHERE key = ? AND app_id IS ? AND user_id IS ?\n LIMIT 1\n ").get(s,t.appId||null,t.userId||null);return n?.value||null}(this.sqlite,e,s)}async setUserSetting(e,s,t){return function(e,s,t,n){const i=Date.now(),a=`${n.appId||"default"}_${n.userId||"default"}_${s}`,d=e.prepare("\n SELECT created_at FROM user_settings WHERE id = ?\n ").get(a),r=d?.created_at||i;e.prepare("\n INSERT OR REPLACE INTO user_settings \n (id, app_id, user_id, key, value, created_at, updated_at)\n VALUES (?, ?, ?, ?, ?, ?, ?)\n ").run(a,n.appId||null,n.userId||null,s,t,r,i)}(this.sqlite,e,s,t)}async getUserSettings(e){return function(e,s){const t=e.prepare("\n SELECT key, value FROM user_settings\n WHERE app_id IS ? AND user_id IS ?\n ").all(s.appId||null,s.userId||null),n={};for(const e of t)n[e.key]=e.value;return n}(this.sqlite,e)}async deleteUserSetting(e,s){return function(e,s,t){e.prepare("\n DELETE FROM user_settings\n WHERE key = ? AND app_id IS ? AND user_id IS ?\n ").run(s,t.appId||null,t.userId||null)}(this.sqlite,e,s)}async close(){this.sqlite.close()}};export{d as sessions,r as messages,o as operations,u as backups,l as trash,p as embeddings,G as SqliteAdapter};
|
package/dist/index.d.ts
CHANGED
|
@@ -28,6 +28,8 @@ type CreateSessionInput = Omit<SessionRecord, 'createdAt' | 'updatedAt' | 'appId
|
|
|
28
28
|
type UpdateSessionInput = Partial<Pick<SessionRecord, 'title' | 'model' | 'mode' | 'webSearchEnabled' | 'thinkingEnabled' | 'hidden'>>;
|
|
29
29
|
interface MessageRecord {
|
|
30
30
|
id: string;
|
|
31
|
+
/** 前端关联 ID(本地模式与 id 相同,云端模式为前端生成的 UUID) */
|
|
32
|
+
clientId: string | null;
|
|
31
33
|
sessionId: string;
|
|
32
34
|
appId: string | null;
|
|
33
35
|
userId: string | null;
|
|
@@ -46,14 +48,18 @@ interface MessageRecord {
|
|
|
46
48
|
/** 执行步骤列表 JSON */
|
|
47
49
|
steps: string | null;
|
|
48
50
|
operationIds: string | null;
|
|
51
|
+
/** Token 使用统计(JSON 字符串) */
|
|
52
|
+
usage: string | null;
|
|
53
|
+
/** 响应耗时(毫秒) */
|
|
54
|
+
duration: number | null;
|
|
49
55
|
/** 消息序号(会话内递增,用于分叉删除,必须) */
|
|
50
56
|
sequence: number;
|
|
51
57
|
/** 时间戳(毫秒,Unix 时间戳,不受 JSON 序列化影响) */
|
|
52
58
|
timestamp: number;
|
|
53
59
|
}
|
|
54
|
-
type CreateMessageInput = Omit<MessageRecord, 'timestamp' | 'appId' | 'userId' | 'sequence'>;
|
|
55
|
-
/**
|
|
56
|
-
type UpdateMessageInput = Partial<Pick<MessageRecord, 'content' | 'steps'>>;
|
|
60
|
+
type CreateMessageInput = Omit<MessageRecord, 'timestamp' | 'appId' | 'userId' | 'sequence' | 'usage' | 'duration'>;
|
|
61
|
+
/** 更新消息输入 */
|
|
62
|
+
type UpdateMessageInput = Partial<Pick<MessageRecord, 'content' | 'steps' | 'operationIds' | 'usage' | 'duration'>>;
|
|
57
63
|
type OperationStatus = 'pending' | 'confirmed' | 'executed' | 'reverted' | 'failed';
|
|
58
64
|
interface OperationRecord {
|
|
59
65
|
id: string;
|
|
@@ -402,6 +408,25 @@ declare const messages: drizzle_orm_sqlite_core.SQLiteTableWithColumns<{
|
|
|
402
408
|
}, {}, {
|
|
403
409
|
length: number | undefined;
|
|
404
410
|
}>;
|
|
411
|
+
clientId: drizzle_orm_sqlite_core.SQLiteColumn<{
|
|
412
|
+
name: "client_id";
|
|
413
|
+
tableName: "messages";
|
|
414
|
+
dataType: "string";
|
|
415
|
+
columnType: "SQLiteText";
|
|
416
|
+
data: string;
|
|
417
|
+
driverParam: string;
|
|
418
|
+
notNull: false;
|
|
419
|
+
hasDefault: false;
|
|
420
|
+
isPrimaryKey: false;
|
|
421
|
+
isAutoincrement: false;
|
|
422
|
+
hasRuntimeDefault: false;
|
|
423
|
+
enumValues: [string, ...string[]];
|
|
424
|
+
baseColumn: never;
|
|
425
|
+
identity: undefined;
|
|
426
|
+
generated: undefined;
|
|
427
|
+
}, {}, {
|
|
428
|
+
length: number | undefined;
|
|
429
|
+
}>;
|
|
405
430
|
sessionId: drizzle_orm_sqlite_core.SQLiteColumn<{
|
|
406
431
|
name: "session_id";
|
|
407
432
|
tableName: "messages";
|
|
@@ -626,6 +651,42 @@ declare const messages: drizzle_orm_sqlite_core.SQLiteTableWithColumns<{
|
|
|
626
651
|
}, {}, {
|
|
627
652
|
length: number | undefined;
|
|
628
653
|
}>;
|
|
654
|
+
usage: drizzle_orm_sqlite_core.SQLiteColumn<{
|
|
655
|
+
name: "usage";
|
|
656
|
+
tableName: "messages";
|
|
657
|
+
dataType: "string";
|
|
658
|
+
columnType: "SQLiteText";
|
|
659
|
+
data: string;
|
|
660
|
+
driverParam: string;
|
|
661
|
+
notNull: false;
|
|
662
|
+
hasDefault: false;
|
|
663
|
+
isPrimaryKey: false;
|
|
664
|
+
isAutoincrement: false;
|
|
665
|
+
hasRuntimeDefault: false;
|
|
666
|
+
enumValues: [string, ...string[]];
|
|
667
|
+
baseColumn: never;
|
|
668
|
+
identity: undefined;
|
|
669
|
+
generated: undefined;
|
|
670
|
+
}, {}, {
|
|
671
|
+
length: number | undefined;
|
|
672
|
+
}>;
|
|
673
|
+
duration: drizzle_orm_sqlite_core.SQLiteColumn<{
|
|
674
|
+
name: "duration";
|
|
675
|
+
tableName: "messages";
|
|
676
|
+
dataType: "number";
|
|
677
|
+
columnType: "SQLiteInteger";
|
|
678
|
+
data: number;
|
|
679
|
+
driverParam: number;
|
|
680
|
+
notNull: false;
|
|
681
|
+
hasDefault: false;
|
|
682
|
+
isPrimaryKey: false;
|
|
683
|
+
isAutoincrement: false;
|
|
684
|
+
hasRuntimeDefault: false;
|
|
685
|
+
enumValues: undefined;
|
|
686
|
+
baseColumn: never;
|
|
687
|
+
identity: undefined;
|
|
688
|
+
generated: undefined;
|
|
689
|
+
}, {}, {}>;
|
|
629
690
|
sequence: drizzle_orm_sqlite_core.SQLiteColumn<{
|
|
630
691
|
name: "sequence";
|
|
631
692
|
tableName: "messages";
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{SqliteAdapter as t,backups as r,embeddings as e,messages as s,operations as o,sessions as n,trash as i}from"./chunk-
|
|
1
|
+
import{SqliteAdapter as t,backups as r,embeddings as e,messages as s,operations as o,sessions as n,trash as i}from"./chunk-V5E7YX6J.js";import{PostgresAdapter as c}from"./chunk-EXGLTJH4.js";import{mkdirSync as p,existsSync as a}from"fs";import{dirname as h}from"path";async function E(t){switch(t.type){case"sqlite":{if(!t.sqlitePath)throw new Error("SQLite 需要提供 sqlitePath 配置");const r=h(t.sqlitePath);a(r)||p(r,{recursive:!0});const{SqliteAdapter:e}=await import("./sqlite-BVA3FN4Z.js");return new e(t.sqlitePath,t)}case"postgres":{if(!t.postgresUrl)throw new Error("PostgreSQL 需要提供 postgresUrl 配置");const{PostgresAdapter:r}=await import("./postgres-JFFEO52T.js");return new r(t.postgresUrl,t)}default:throw new Error(`不支持的存储类型: ${t.type}`)}}function u(){return`${process.env.HOME||process.env.USERPROFILE||"."}/.ai-chat/db.sqlite`}function f(){return`${process.env.HOME||process.env.USERPROFILE||"."}/.ai-chat/backups`}function l(){return`${process.env.HOME||process.env.USERPROFILE||"."}/.ai-chat/trash`}export{c as PostgresAdapter,t as SqliteAdapter,r as backups,E as createStorage,e as embeddings,f as getDefaultBackupDir,u as getDefaultStoragePath,l as getDefaultTrashDir,s as messages,o as operations,n as sessions,i as trash};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{PostgresAdapter as o}from"./chunk-EXGLTJH4.js";export{o as PostgresAdapter};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{SqliteAdapter as o}from"./chunk-V5E7YX6J.js";export{o as SqliteAdapter};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@huyooo/ai-chat-storage",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.20",
|
|
4
4
|
"description": "AI Chat 统一存储层 - SQLite",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -19,7 +19,9 @@
|
|
|
19
19
|
"scripts": {
|
|
20
20
|
"build": "tsup",
|
|
21
21
|
"dev": "tsup --watch",
|
|
22
|
-
"typecheck": "tsc --noEmit"
|
|
22
|
+
"typecheck": "tsc --noEmit",
|
|
23
|
+
"test": "vitest run",
|
|
24
|
+
"test:watch": "vitest"
|
|
23
25
|
},
|
|
24
26
|
"dependencies": {
|
|
25
27
|
"drizzle-orm": "^0.38.0",
|
|
@@ -36,7 +38,8 @@
|
|
|
36
38
|
"devDependencies": {
|
|
37
39
|
"@types/better-sqlite3": "^7.6.11",
|
|
38
40
|
"tsup": "^8.3.0",
|
|
39
|
-
"typescript": "^5.6.3"
|
|
41
|
+
"typescript": "^5.6.3",
|
|
42
|
+
"vitest": "^4.0.18"
|
|
40
43
|
},
|
|
41
44
|
"publishConfig": {
|
|
42
45
|
"access": "public"
|
package/dist/chunk-6L6KHCOT.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{drizzle as e}from"drizzle-orm/better-sqlite3";import s from"better-sqlite3";import{sqliteTable as t,text as n,integer as i,index as a}from"drizzle-orm/sqlite-core";var d=t("sessions",{id:n("id").primaryKey(),appId:n("app_id"),userId:n("user_id"),title:n("title").notNull(),model:n("model").notNull(),mode:n("mode").notNull(),webSearchEnabled:i("web_search_enabled",{mode:"boolean"}).notNull().default(!0),thinkingEnabled:i("thinking_enabled",{mode:"boolean"}).notNull().default(!0),hidden:i("hidden",{mode:"boolean"}).notNull().default(!1),createdAt:i("created_at",{mode:"timestamp"}).notNull(),updatedAt:i("updated_at",{mode:"timestamp"}).notNull()},e=>[a("idx_sessions_tenant").on(e.appId,e.userId),a("idx_sessions_updated").on(e.updatedAt)]),r=t("messages",{id:n("id").primaryKey(),sessionId:n("session_id").notNull(),appId:n("app_id"),userId:n("user_id"),role:n("role").notNull(),content:n("content").notNull(),images:n("images"),model:n("model"),mode:n("mode"),webSearchEnabled:i("web_search_enabled",{mode:"boolean"}),thinkingEnabled:i("thinking_enabled",{mode:"boolean"}),steps:n("steps"),operationIds:n("operation_ids"),sequence:i("sequence").notNull(),timestamp:i("timestamp",{mode:"timestamp"}).notNull()},e=>[a("idx_messages_session").on(e.sessionId),a("idx_messages_tenant").on(e.appId,e.userId),a("idx_messages_sequence").on(e.sessionId,e.sequence)]),o=t("operations",{id:n("id").primaryKey(),sessionId:n("session_id").notNull(),messageId:n("message_id"),appId:n("app_id"),userId:n("user_id"),command:n("command").notNull(),operationType:n("operation_type").notNull(),affectedFiles:n("affected_files").notNull(),backupPath:n("backup_path"),status:n("status").notNull().default("pending"),errorMessage:n("error_message"),timestamp:i("timestamp",{mode:"timestamp"}).notNull()},e=>[a("idx_operations_session").on(e.sessionId),a("idx_operations_message").on(e.messageId),a("idx_operations_tenant").on(e.appId,e.userId)]),u=t("backups",{id:n("id").primaryKey(),operationId:n("operation_id").notNull(),originalPath:n("original_path").notNull(),backupPath:n("backup_path").notNull(),fileSize:i("file_size").notNull(),fileHash:n("file_hash").notNull(),createdAt:i("created_at",{mode:"timestamp"}).notNull(),expiresAt:i("expires_at",{mode:"timestamp"}).notNull()},e=>[a("idx_backups_operation").on(e.operationId),a("idx_backups_expires").on(e.expiresAt)]),p=t("trash",{id:n("id").primaryKey(),sessionId:n("session_id").notNull(),appId:n("app_id"),userId:n("user_id"),originalPath:n("original_path").notNull(),trashPath:n("trash_path").notNull(),deletedAt:i("deleted_at",{mode:"timestamp"}).notNull(),autoDeleteAt:i("auto_delete_at",{mode:"timestamp"}).notNull()},e=>[a("idx_trash_tenant").on(e.appId,e.userId),a("idx_trash_auto_delete").on(e.autoDeleteAt)]),l=t("embeddings",{id:n("id").primaryKey(),sessionId:n("session_id").notNull(),messageId:n("message_id"),appId:n("app_id"),userId:n("user_id"),content:n("content").notNull(),contentType:n("content_type").notNull(),embedding:n("embedding"),metadata:n("metadata"),createdAt:i("created_at",{mode:"timestamp"}).notNull()},e=>[a("idx_embeddings_session").on(e.sessionId),a("idx_embeddings_tenant").on(e.appId,e.userId)]);import{eq as m,and as c}from"drizzle-orm";function E(e){const s=[];return e.appId&&s.push(m(d.appId,e.appId)),e.userId&&s.push(m(d.userId,e.userId)),s.length>0?c(...s):void 0}function T(e){const s=[];return e.appId&&s.push(m(r.appId,e.appId)),e.userId&&s.push(m(r.userId,e.userId)),s.length>0?c(...s):void 0}function I(e){const s=[];return e.appId&&s.push(m(p.appId,e.appId)),e.userId&&s.push(m(p.userId,e.userId)),s.length>0?c(...s):void 0}import{eq as h,and as N,desc as _}from"drizzle-orm";function g(e){return{id:e.id,appId:e.appId,userId:e.userId,title:e.title,model:e.model,mode:e.mode,webSearchEnabled:e.webSearchEnabled,thinkingEnabled:e.thinkingEnabled,hidden:e.hidden,createdAt:e.createdAt,updatedAt:e.updatedAt}}import{eq as b,and as L,gt as A,max as f}from"drizzle-orm";function O(e){if(null===e.sequence||void 0===e.sequence)throw new Error(`消息 ${e.id} 缺少序号,数据损坏`);let s=[];if(e.images)try{const t=JSON.parse(e.images);Array.isArray(t)&&(s=t)}catch{}return{id:e.id,sessionId:e.sessionId,appId:e.appId,userId:e.userId,role:e.role,content:e.content,images:s,model:e.model,mode:e.mode,webSearchEnabled:e.webSearchEnabled,thinkingEnabled:e.thinkingEnabled,steps:e.steps,operationIds:e.operationIds,sequence:(s=>{if("number"==typeof s&&Number.isFinite(s))return s;if("string"==typeof s){const e=Number(s);if(Number.isFinite(e))return e}throw new Error(`消息 ${e.id} 的序号无效: ${s}`)})(e.sequence),timestamp:(s=>{if("number"==typeof s&&Number.isFinite(s))return s;if(s instanceof Date)return s.getTime();if("string"==typeof s){const e=Date.parse(s);if(!Number.isNaN(e))return e;const t=Number(s);if(Number.isFinite(t))return t}throw new Error(`消息 ${e.id} 的时间戳无效: ${s}`)})(e.timestamp)}}function S(e,s,t){const n=Date.now(),i=function(e,s){const t=e.select({maxSeq:f(r.sequence)}).from(r).where(b(r.sessionId,s)).get();return t?.maxSeq??0}(e,s.sessionId)+1,a={id:s.id,sessionId:s.sessionId,appId:t.appId||null,userId:t.userId||null,role:s.role,content:s.content,images:s.images||[],model:s.model,mode:s.mode,webSearchEnabled:s.webSearchEnabled,thinkingEnabled:s.thinkingEnabled,steps:s.steps,operationIds:s.operationIds,sequence:i,timestamp:n};return e.insert(r).values({id:a.id,sessionId:a.sessionId,appId:a.appId,userId:a.userId,role:a.role,content:a.content,images:a.images.length>0?JSON.stringify(a.images):null,model:a.model,mode:a.mode,webSearchEnabled:a.webSearchEnabled,thinkingEnabled:a.thinkingEnabled,steps:a.steps,operationIds:a.operationIds,sequence:a.sequence,timestamp:new Date(a.timestamp)}).run(),e.update(d).set({updatedAt:new Date(n)}).where(b(d.id,s.sessionId)).run(),a}import{eq as y,and as X}from"drizzle-orm";function R(e){return{id:e.id,sessionId:e.sessionId,messageId:e.messageId,appId:e.appId,userId:e.userId,command:e.command,operationType:e.operationType,affectedFiles:e.affectedFiles,backupPath:e.backupPath,status:e.status,errorMessage:e.errorMessage,timestamp:e.timestamp}}function w(e,s,t){const n=function(e){const s=[];return e.appId&&s.push(m(o.appId,e.appId)),e.userId&&s.push(m(o.userId,e.userId)),s.length>0?c(...s):void 0}(t),i=n?X(y(o.messageId,s),n):y(o.messageId,s);return e.select().from(o).where(i).all().map(R)}import{eq as D,lt as U}from"drizzle-orm";function k(e){return{id:e.id,operationId:e.operationId,originalPath:e.originalPath,backupPath:e.backupPath,fileSize:e.fileSize,fileHash:e.fileHash,createdAt:e.createdAt,expiresAt:e.expiresAt}}import{eq as x,and as q,desc as F,lt as M}from"drizzle-orm";function C(e){return{id:e.id,sessionId:e.sessionId,appId:e.appId,userId:e.userId,originalPath:e.originalPath,trashPath:e.trashPath,deletedAt:e.deletedAt,autoDeleteAt:e.autoDeleteAt}}import{eq as P,and as v}from"drizzle-orm";function z(e,s,t,n){const{limit:i=10,threshold:a=.7,sessionId:d}=t,r=[];n.appId&&r.push(P(l.appId,n.appId)),n.userId&&r.push(P(l.userId,n.userId)),d&&r.push(P(l.sessionId,d));return e.select().from(l).where(r.length>0?v(...r):void 0).all().map(e=>{const t=e.embedding?JSON.parse(e.embedding):[],n=function(e,s){if(e.length!==s.length)return 0;let t=0,n=0,i=0;for(let a=0;a<e.length;a++)t+=e[a]*s[a],n+=e[a]*e[a],i+=s[a]*s[a];return 0===n||0===i?0:t/(Math.sqrt(n)*Math.sqrt(i))}(s,t);return{id:e.id,content:e.content,contentType:e.contentType,similarity:n,metadata:e.metadata?JSON.parse(e.metadata):void 0}}).filter(e=>e.similarity>=a).sort((e,s)=>s.similarity-e.similarity).slice(0,i)}var B=class{sqlite;db;config;get sqliteInstance(){return this.sqlite}constructor(t,n={type:"sqlite"}){this.sqlite=new s(t),this.db=e(this.sqlite),this.config=n,function(e){e.exec("\n CREATE TABLE IF NOT EXISTS sessions (\n id TEXT PRIMARY KEY,\n app_id TEXT,\n user_id TEXT,\n title TEXT NOT NULL,\n model TEXT NOT NULL,\n mode TEXT NOT NULL,\n web_search_enabled INTEGER NOT NULL DEFAULT 1,\n thinking_enabled INTEGER NOT NULL DEFAULT 1,\n hidden INTEGER NOT NULL DEFAULT 0,\n created_at INTEGER NOT NULL,\n updated_at INTEGER NOT NULL\n );\n\n CREATE TABLE IF NOT EXISTS messages (\n id TEXT PRIMARY KEY,\n session_id TEXT NOT NULL,\n app_id TEXT,\n user_id TEXT,\n role TEXT NOT NULL,\n content TEXT NOT NULL,\n images TEXT,\n model TEXT,\n mode TEXT,\n web_search_enabled INTEGER,\n thinking_enabled INTEGER,\n steps TEXT,\n operation_ids TEXT,\n timestamp INTEGER NOT NULL\n );\n\n CREATE TABLE IF NOT EXISTS operations (\n id TEXT PRIMARY KEY,\n session_id TEXT NOT NULL,\n message_id TEXT,\n app_id TEXT,\n user_id TEXT,\n command TEXT NOT NULL,\n operation_type TEXT NOT NULL,\n affected_files TEXT NOT NULL,\n backup_path TEXT,\n status TEXT NOT NULL DEFAULT 'pending',\n error_message TEXT,\n timestamp INTEGER NOT NULL\n );\n\n CREATE TABLE IF NOT EXISTS backups (\n id TEXT PRIMARY KEY,\n operation_id TEXT NOT NULL,\n original_path TEXT NOT NULL,\n backup_path TEXT NOT NULL,\n file_size INTEGER NOT NULL,\n file_hash TEXT NOT NULL,\n created_at INTEGER NOT NULL,\n expires_at INTEGER NOT NULL\n );\n\n CREATE TABLE IF NOT EXISTS trash (\n id TEXT PRIMARY KEY,\n session_id TEXT NOT NULL,\n app_id TEXT,\n user_id TEXT,\n original_path TEXT NOT NULL,\n trash_path TEXT NOT NULL,\n deleted_at INTEGER NOT NULL,\n auto_delete_at INTEGER NOT NULL\n );\n\n CREATE TABLE IF NOT EXISTS embeddings (\n id TEXT PRIMARY KEY,\n session_id TEXT NOT NULL,\n message_id TEXT,\n app_id TEXT,\n user_id TEXT,\n content TEXT NOT NULL,\n content_type TEXT NOT NULL,\n embedding TEXT,\n metadata TEXT,\n created_at INTEGER NOT NULL\n );\n\n CREATE TABLE IF NOT EXISTS user_settings (\n id TEXT PRIMARY KEY,\n app_id TEXT,\n user_id TEXT,\n key TEXT NOT NULL,\n value TEXT NOT NULL,\n created_at INTEGER NOT NULL,\n updated_at INTEGER NOT NULL,\n UNIQUE(app_id, user_id, key)\n );\n\n -- 索引\n CREATE INDEX IF NOT EXISTS idx_sessions_tenant ON sessions(app_id, user_id);\n CREATE INDEX IF NOT EXISTS idx_sessions_updated ON sessions(updated_at);\n CREATE INDEX IF NOT EXISTS idx_messages_session ON messages(session_id);\n CREATE INDEX IF NOT EXISTS idx_messages_tenant ON messages(app_id, user_id);\n CREATE INDEX IF NOT EXISTS idx_operations_session ON operations(session_id);\n CREATE INDEX IF NOT EXISTS idx_operations_message ON operations(message_id);\n CREATE INDEX IF NOT EXISTS idx_backups_operation ON backups(operation_id);\n CREATE INDEX IF NOT EXISTS idx_backups_expires ON backups(expires_at);\n CREATE INDEX IF NOT EXISTS idx_trash_tenant ON trash(app_id, user_id);\n CREATE INDEX IF NOT EXISTS idx_trash_auto_delete ON trash(auto_delete_at);\n CREATE INDEX IF NOT EXISTS idx_embeddings_session ON embeddings(session_id);\n CREATE INDEX IF NOT EXISTS idx_user_settings_tenant ON user_settings(app_id, user_id);\n CREATE INDEX IF NOT EXISTS idx_user_settings_key ON user_settings(key);\n ");try{e.exec("ALTER TABLE sessions ADD COLUMN web_search_enabled INTEGER NOT NULL DEFAULT 1")}catch{}try{e.exec("ALTER TABLE sessions ADD COLUMN thinking_enabled INTEGER NOT NULL DEFAULT 1")}catch{}try{e.exec("ALTER TABLE messages ADD COLUMN model TEXT")}catch{}try{e.exec("ALTER TABLE messages ADD COLUMN mode TEXT")}catch{}try{e.exec("ALTER TABLE messages ADD COLUMN web_search_enabled INTEGER")}catch{}try{e.exec("ALTER TABLE messages ADD COLUMN thinking_enabled INTEGER")}catch{}try{e.exec("ALTER TABLE sessions ADD COLUMN hidden INTEGER NOT NULL DEFAULT 0")}catch{}try{e.exec("ALTER TABLE messages ADD COLUMN steps TEXT")}catch{}try{e.exec("ALTER TABLE messages ADD COLUMN sequence INTEGER")}catch{}try{e.exec("ALTER TABLE messages ADD COLUMN images TEXT")}catch{}try{e.exec("\n UPDATE messages\n SET sequence = (\n SELECT COUNT(*) + 1\n FROM messages m2\n WHERE m2.session_id = messages.session_id\n AND (m2.timestamp < messages.timestamp\n OR (m2.timestamp = messages.timestamp AND m2.id < messages.id))\n )\n WHERE sequence IS NULL\n ")}catch{}try{e.exec("\n UPDATE messages\n SET sequence = (\n SELECT COUNT(*) + 1\n FROM messages m2\n WHERE m2.session_id = messages.session_id\n AND (m2.timestamp < messages.timestamp\n OR (m2.timestamp = messages.timestamp AND m2.id < messages.id))\n )\n WHERE sequence IS NULL\n "),e.exec("\n UPDATE messages\n SET sequence = (\n SELECT COALESCE(MAX(sequence), 0) + 1\n FROM messages m2\n WHERE m2.session_id = messages.session_id\n )\n WHERE sequence IS NULL\n ")}catch{}try{e.exec("CREATE INDEX IF NOT EXISTS idx_messages_sequence ON messages(session_id, sequence)")}catch{}}(this.sqlite)}async getSessions(e){return function(e,s){const t=E(s);return e.select().from(d).where(t).orderBy(_(d.updatedAt)).all().map(g)}(this.db,e)}async getSession(e,s){return function(e,s,t){const n=E(t),i=n?N(h(d.id,s),n):h(d.id,s),a=e.select().from(d).where(i).get();return a?g(a):null}(this.db,e,s)}async createSession(e,s){return function(e,s,t){const n=new Date,i={id:s.id,appId:t.appId||null,userId:t.userId||null,title:s.title,model:s.model,mode:s.mode,webSearchEnabled:s.webSearchEnabled,thinkingEnabled:s.thinkingEnabled,hidden:s.hidden??!1,createdAt:n,updatedAt:n};return e.insert(d).values({id:i.id,appId:i.appId,userId:i.userId,title:i.title,model:i.model,mode:i.mode,webSearchEnabled:i.webSearchEnabled,thinkingEnabled:i.thinkingEnabled,hidden:i.hidden,createdAt:i.createdAt,updatedAt:i.updatedAt}).run(),i}(this.db,e,s)}async updateSession(e,s,t){!function(e,s,t,n){const i=E(n),a=i?N(h(d.id,s),i):h(d.id,s),r={updatedAt:new Date};void 0!==t.title&&(r.title=t.title),void 0!==t.model&&(r.model=t.model),void 0!==t.mode&&(r.mode=t.mode),void 0!==t.webSearchEnabled&&(r.webSearchEnabled=t.webSearchEnabled),void 0!==t.thinkingEnabled&&(r.thinkingEnabled=t.thinkingEnabled),void 0!==t.hidden&&(r.hidden=t.hidden),e.update(d).set(r).where(a).run()}(this.db,e,s,t)}async deleteSession(e,s){var t,n;t=this.db,n=e,t.delete(r).where(b(r.sessionId,n)).run(),function(e,s){e.delete(o).where(y(o.sessionId,s)).run()}(this.db,e),function(e,s){e.delete(l).where(P(l.sessionId,s)).run()}(this.db,e),function(e,s,t){const n=E(t),i=n?N(h(d.id,s),n):h(d.id,s);e.delete(d).where(i).run()}(this.db,e,s)}async getMessages(e,s){return await this.getSession(e,s)?function(e,s){return e.select().from(r).where(b(r.sessionId,s)).orderBy(r.sequence,r.timestamp).all().map(O)}(this.db,e):[]}async getMessage(e,s){return function(e,s,t){const n=T(t),i=n?L(b(r.id,s),n):b(r.id,s),a=e.select().from(r).where(i).get();return a?O(a):null}(this.db,e,s)}async saveMessage(e,s){return S(this.db,e,s)}async updateMessage(e,s,t){!function(e,s,t,n){const i=T(n),a=i?L(b(r.id,s),i):b(r.id,s),d={};void 0!==t.content&&(d.content=t.content),void 0!==t.steps&&(d.steps=t.steps),Object.keys(d).length>0&&e.update(r).set(d).where(a).run()}(this.db,e,s,t)}async deleteMessagesAfter(e,s,t){await this.getSession(e,t)&&function(e,s,t){e.delete(r).where(L(b(r.sessionId,s),A(r.timestamp,t))).run()}(this.db,e,s)}async deleteMessagesAfterMessageId(e,s,t){if(!await this.getSession(e,t))return;const n=await this.getMessage(s,t);if(n&&n.sessionId===e){if(null===n.sequence||void 0===n.sequence)throw new Error(`消息 ${s} 缺少序号,无法删除后续消息`);!function(e,s,t,n){if(null==n)throw new Error(`消息 ${t} 缺少序号,无法删除后续消息`);e.delete(r).where(L(b(r.sessionId,s),A(r.sequence,n))).run()}(this.db,e,s,n.sequence)}}async getOperations(e,s){return await this.getSession(e,s)?function(e,s){return e.select().from(o).where(y(o.sessionId,s)).orderBy(o.timestamp).all().map(R)}(this.db,e):[]}async getOperationsByMessage(e,s){return w(this.db,e,s)}async saveOperation(e,s){return function(e,s,t){const n=new Date,i={id:s.id,sessionId:s.sessionId,messageId:s.messageId,appId:t.appId||null,userId:t.userId||null,command:s.command,operationType:s.operationType,affectedFiles:s.affectedFiles,backupPath:s.backupPath,status:s.status||"pending",errorMessage:null,timestamp:n};return e.insert(o).values({id:i.id,sessionId:i.sessionId,messageId:i.messageId,appId:i.appId,userId:i.userId,command:i.command,operationType:i.operationType,affectedFiles:i.affectedFiles,backupPath:i.backupPath,status:i.status,errorMessage:i.errorMessage,timestamp:i.timestamp}).run(),i}(this.db,e,s)}async updateOperationStatus(e,s,t){!function(e,s,t,n){const i={status:t};void 0!==n&&(i.errorMessage=n),e.update(o).set(i).where(y(o.id,s)).run()}(this.db,e,s,t)}async getBackups(e){return function(e,s){return e.select().from(u).where(D(u.operationId,s)).all().map(k)}(this.db,e)}async saveBackup(e){return function(e,s){const t={...s,createdAt:new Date};return e.insert(u).values({id:t.id,operationId:t.operationId,originalPath:t.originalPath,backupPath:t.backupPath,fileSize:t.fileSize,fileHash:t.fileHash,createdAt:t.createdAt,expiresAt:t.expiresAt}).run(),t}(this.db,e)}async deleteExpiredBackups(){return function(e){const s=new Date;return e.delete(u).where(U(u.expiresAt,s)).run().changes}(this.db)}async getTrashItems(e){return function(e,s){const t=I(s);return e.select().from(p).where(t).orderBy(F(p.deletedAt)).all().map(C)}(this.db,e)}async moveToTrash(e,s){return function(e,s,t,n){const i=new Date,a=n.trashRetentionDays||30,d=new Date(i.getTime()+24*a*60*60*1e3),r={...s,appId:t.appId||null,userId:t.userId||null,deletedAt:i,autoDeleteAt:d};return e.insert(p).values({id:r.id,sessionId:r.sessionId,appId:r.appId,userId:r.userId,originalPath:r.originalPath,trashPath:r.trashPath,deletedAt:r.deletedAt,autoDeleteAt:r.autoDeleteAt}).run(),r}(this.db,e,s,this.config)}async restoreFromTrash(e,s){return function(e,s,t){const n=I(t),i=n?q(x(p.id,s),n):x(p.id,s),a=e.select().from(p).where(i).get();if(!a)throw new Error("回收站记录不存在");return e.delete(p).where(x(p.id,s)).run(),C(a)}(this.db,e,s)}async emptyExpiredTrash(){return function(e){const s=new Date;return e.delete(p).where(M(p.autoDeleteAt,s)).run().changes}(this.db)}async saveEmbedding(e,s,t,n,i){!function(e,s,t,n,i,a){const d=new Date;e.insert(l).values({id:s,sessionId:i.sessionId,messageId:i.messageId||null,appId:a.appId||null,userId:a.userId||null,content:t,contentType:i.contentType,embedding:JSON.stringify(n),metadata:JSON.stringify(i),createdAt:d}).run()}(this.db,e,s,t,n,i)}async searchSimilar(e,s,t){return z(this.db,e,s,t)}async getUserSetting(e,s){return function(e,s,t){const n=e.prepare("\n SELECT value FROM user_settings\n WHERE key = ? AND app_id IS ? AND user_id IS ?\n LIMIT 1\n ").get(s,t.appId||null,t.userId||null);return n?.value||null}(this.sqlite,e,s)}async setUserSetting(e,s,t){return function(e,s,t,n){const i=Date.now(),a=`${n.appId||"default"}_${n.userId||"default"}_${s}`,d=e.prepare("\n SELECT created_at FROM user_settings WHERE id = ?\n ").get(a),r=d?.created_at||i;e.prepare("\n INSERT OR REPLACE INTO user_settings \n (id, app_id, user_id, key, value, created_at, updated_at)\n VALUES (?, ?, ?, ?, ?, ?, ?)\n ").run(a,n.appId||null,n.userId||null,s,t,r,i)}(this.sqlite,e,s,t)}async getUserSettings(e){return function(e,s){const t=e.prepare("\n SELECT key, value FROM user_settings\n WHERE app_id IS ? AND user_id IS ?\n ").all(s.appId||null,s.userId||null),n={};for(const e of t)n[e.key]=e.value;return n}(this.sqlite,e)}async deleteUserSetting(e,s){return function(e,s,t){e.prepare("\n DELETE FROM user_settings\n WHERE key = ? AND app_id IS ? AND user_id IS ?\n ").run(s,t.appId||null,t.userId||null)}(this.sqlite,e,s)}async close(){this.sqlite.close()}};export{d as sessions,r as messages,o as operations,u as backups,p as trash,l as embeddings,B as SqliteAdapter};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{PostgresAdapter as o}from"./chunk-CQ66EXL6.js";export{o as PostgresAdapter};
|
package/dist/sqlite-MZGQZHVI.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{SqliteAdapter as o}from"./chunk-6L6KHCOT.js";export{o as SqliteAdapter};
|