@musnows/scriverse 0.8.7 → 0.8.8
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/README.en.md +3 -1
- package/README.md +3 -1
- package/dist/ai.js +532 -131
- package/dist/ai.js.map +1 -1
- package/dist/app.js +73 -8
- package/dist/app.js.map +1 -1
- package/dist/database.js +94 -2
- package/dist/database.js.map +1 -1
- package/dist/public/ai-connectivity-test.js +5 -2
- package/dist/public/app.js +448 -72
- package/dist/public/index.html +23 -10
- package/dist/public/roleplay-turn.js +100 -0
- package/dist/public/styles.css +66 -15
- package/dist/public/toast-layer.d.ts +4 -0
- package/dist/public/toast-layer.js +5 -0
- package/dist/roleplay-turn.js +98 -0
- package/dist/roleplay-turn.js.map +1 -0
- package/dist/security.js +33 -7
- package/dist/security.js.map +1 -1
- package/dist/server-runtime.js +2 -1
- package/dist/server-runtime.js.map +1 -1
- package/dist/store.js +95 -12
- package/dist/store.js.map +1 -1
- package/dist/user-auth.js +36 -6
- package/dist/user-auth.js.map +1 -1
- package/dist/version.js +1 -1
- package/package.json +1 -1
package/dist/database.js
CHANGED
|
@@ -5,9 +5,9 @@ import { documentParagraphLineRanges } from "./hybrid-search.js";
|
|
|
5
5
|
import { logger, sanitizeError } from "./logger.js";
|
|
6
6
|
import { documentShortSearchTerms, normalizeDocumentSearchText, splitDocumentParagraphs } from "./utils.js";
|
|
7
7
|
export const PLATFORM_AI_WORK_ID = "__scriverse_platform_ai__";
|
|
8
|
-
// 版本 81 用于列表查询索引;版本 82 由 Store 写入实体版本基线标记;版本 83 创建协作状态表;版本 84 创建备份加密表;版本 85 持久化协作变更动作;版本 86 扩展直接图片上传格式;版本 87 增加作品与分卷回收站;版本 88 持久化 AI 对话分支幂等键;版本 89 持久化 AI 对话流请求锁与幂等状态;版本 90 持久化 AI 连通性测试冷却状态;版本 91 建立章节段落行号索引;版本 92 增加 AI 对话收藏状态;版本 93 优化伏笔计划回收章节查询;版本 94 增加模型思考强度;版本 95 增加供应商最大输出参数选择;版本 96 扩展模型思考强度档位;版本 97 增加人物性别字段;版本 98 增加正文稳定等待配置;版本 99 持久化关系扮演中的用户角色;版本 100 增加平台 AI 流事件空闲超时配置;版本 101 将平台 AI 流事件空闲超时上限提升至 600 秒;版本 102 创建角色头像元数据表;版本 103 回填历史 AI 对话归属并建立用户列表索引;版本 104 扩大供应商协议约束以支持 OpenAI Responses;版本 105 增加独立分卷剧情顺序;版本 106 增加供应商思考类型配置;版本 107 增加 AI Cache Write 输入 Token 统计;版本 108 增加作品 AI 每月 Token 额度;版本 109 增加供应商日、月 Token 额度;版本 110 将日、月 Token 额度下限调整为大于 0;版本 111 扩展模型思考强度为 auto
|
|
8
|
+
// 版本 81 用于列表查询索引;版本 82 由 Store 写入实体版本基线标记;版本 83 创建协作状态表;版本 84 创建备份加密表;版本 85 持久化协作变更动作;版本 86 扩展直接图片上传格式;版本 87 增加作品与分卷回收站;版本 88 持久化 AI 对话分支幂等键;版本 89 持久化 AI 对话流请求锁与幂等状态;版本 90 持久化 AI 连通性测试冷却状态;版本 91 建立章节段落行号索引;版本 92 增加 AI 对话收藏状态;版本 93 优化伏笔计划回收章节查询;版本 94 增加模型思考强度;版本 95 增加供应商最大输出参数选择;版本 96 扩展模型思考强度档位;版本 97 增加人物性别字段;版本 98 增加正文稳定等待配置;版本 99 持久化关系扮演中的用户角色;版本 100 增加平台 AI 流事件空闲超时配置;版本 101 将平台 AI 流事件空闲超时上限提升至 600 秒;版本 102 创建角色头像元数据表;版本 103 回填历史 AI 对话归属并建立用户列表索引;版本 104 扩大供应商协议约束以支持 OpenAI Responses;版本 105 增加独立分卷剧情顺序;版本 106 增加供应商思考类型配置;版本 107 增加 AI Cache Write 输入 Token 统计;版本 108 增加作品 AI 每月 Token 额度;版本 109 增加供应商日、月 Token 额度;版本 110 将日、月 Token 额度下限调整为大于 0;版本 111 扩展模型思考强度为 auto;版本 112 为 CLI API Key 增加可复制的加密密文;版本 113 增加角色收藏状态与列表索引;版本 114 增加组织、设定档案与想法收藏状态及列表索引;版本 115 增加 AI 对话会话级场景钉。
|
|
9
9
|
export const ENTITY_VERSION_BASELINE_MIGRATION_VERSION = 82;
|
|
10
|
-
export const DATABASE_SCHEMA_VERSION =
|
|
10
|
+
export const DATABASE_SCHEMA_VERSION = 115;
|
|
11
11
|
export const SQLITE_IOERR_SHMSIZE = 4874;
|
|
12
12
|
export function isSqliteDiskIoError(error) {
|
|
13
13
|
if (!(error instanceof Error))
|
|
@@ -278,6 +278,7 @@ export class Database {
|
|
|
278
278
|
tags_json TEXT NOT NULL DEFAULT '[]',
|
|
279
279
|
status TEXT NOT NULL DEFAULT 'draft',
|
|
280
280
|
locked INTEGER NOT NULL DEFAULT 0,
|
|
281
|
+
is_favorite INTEGER NOT NULL DEFAULT 0 CHECK(is_favorite IN (0, 1)),
|
|
281
282
|
evidence_json TEXT NOT NULL DEFAULT '[]',
|
|
282
283
|
scope_json TEXT NOT NULL DEFAULT '{}',
|
|
283
284
|
author_note TEXT NOT NULL DEFAULT '',
|
|
@@ -293,6 +294,7 @@ export class Database {
|
|
|
293
294
|
setting_module TEXT,
|
|
294
295
|
title TEXT NOT NULL,
|
|
295
296
|
content TEXT NOT NULL DEFAULT '',
|
|
297
|
+
is_favorite INTEGER NOT NULL DEFAULT 0 CHECK(is_favorite IN (0, 1)),
|
|
296
298
|
created_at TEXT NOT NULL,
|
|
297
299
|
updated_at TEXT NOT NULL,
|
|
298
300
|
CHECK(setting_module IS NULL OR setting_module IN ('settings', 'characters', 'races', 'organizations', 'timeline', 'relationships', 'outlines')),
|
|
@@ -326,6 +328,7 @@ export class Database {
|
|
|
326
328
|
profile_json TEXT NOT NULL DEFAULT '{}',
|
|
327
329
|
current_state_json TEXT NOT NULL DEFAULT '{}',
|
|
328
330
|
is_dead INTEGER NOT NULL DEFAULT 0 CHECK(is_dead IN (0, 1)),
|
|
331
|
+
is_favorite INTEGER NOT NULL DEFAULT 0 CHECK(is_favorite IN (0, 1)),
|
|
329
332
|
locked_fields_json TEXT NOT NULL DEFAULT '[]',
|
|
330
333
|
first_chapter_id TEXT REFERENCES chapters(id) ON DELETE SET NULL,
|
|
331
334
|
merged_into_character_id TEXT,
|
|
@@ -613,6 +616,7 @@ export class Database {
|
|
|
613
616
|
agent_tools_json TEXT,
|
|
614
617
|
injected_entities_json TEXT NOT NULL DEFAULT '{"characters":[],"races":[],"organizations":[]}',
|
|
615
618
|
system_clock_text TEXT NOT NULL DEFAULT '',
|
|
619
|
+
scene_pin_json TEXT NOT NULL DEFAULT '{}',
|
|
616
620
|
created_at TEXT NOT NULL,
|
|
617
621
|
updated_at TEXT NOT NULL
|
|
618
622
|
);
|
|
@@ -724,6 +728,7 @@ export class Database {
|
|
|
724
728
|
normalized_name TEXT NOT NULL,
|
|
725
729
|
description TEXT NOT NULL DEFAULT '',
|
|
726
730
|
is_dissolved INTEGER NOT NULL DEFAULT 0 CHECK(is_dissolved IN (0, 1)),
|
|
731
|
+
is_favorite INTEGER NOT NULL DEFAULT 0 CHECK(is_favorite IN (0, 1)),
|
|
727
732
|
settings_json TEXT NOT NULL DEFAULT '[]',
|
|
728
733
|
created_at TEXT NOT NULL,
|
|
729
734
|
updated_at TEXT NOT NULL,
|
|
@@ -4127,6 +4132,93 @@ export class Database {
|
|
|
4127
4132
|
if (foreignKeys.length > 0)
|
|
4128
4133
|
throw new Error(`数据库外键检查失败:发现 ${foreignKeys.length} 条异常记录`);
|
|
4129
4134
|
}
|
|
4135
|
+
if (!applied.has(112)) {
|
|
4136
|
+
this.transaction(() => {
|
|
4137
|
+
const columns = new Set(this.all("PRAGMA table_info(user_api_keys)").map((row) => String(row.name)));
|
|
4138
|
+
if (!columns.has("key_encrypted")) {
|
|
4139
|
+
this.run("ALTER TABLE user_api_keys ADD COLUMN key_encrypted TEXT");
|
|
4140
|
+
}
|
|
4141
|
+
if (!columns.has("key_iv")) {
|
|
4142
|
+
this.run("ALTER TABLE user_api_keys ADD COLUMN key_iv TEXT");
|
|
4143
|
+
}
|
|
4144
|
+
if (!columns.has("key_tag")) {
|
|
4145
|
+
this.run("ALTER TABLE user_api_keys ADD COLUMN key_tag TEXT");
|
|
4146
|
+
}
|
|
4147
|
+
this.run("INSERT OR IGNORE INTO schema_migrations (version, applied_at) VALUES (112, ?)", new Date().toISOString());
|
|
4148
|
+
});
|
|
4149
|
+
const integrity = this.all("PRAGMA integrity_check");
|
|
4150
|
+
if (integrity.some((row) => row.integrity_check !== "ok")) {
|
|
4151
|
+
throw new Error(`数据库完整性检查失败:${integrity.map((row) => row.integrity_check).join(";")}`);
|
|
4152
|
+
}
|
|
4153
|
+
const foreignKeys = this.all("PRAGMA foreign_key_check");
|
|
4154
|
+
if (foreignKeys.length > 0)
|
|
4155
|
+
throw new Error(`数据库外键检查失败:发现 ${foreignKeys.length} 条异常记录`);
|
|
4156
|
+
}
|
|
4157
|
+
const characterFavoritePresent = this.all("PRAGMA table_info(characters)").some((row) => String(row.name) === "is_favorite");
|
|
4158
|
+
const characterFavoriteIndexPresent = this.all("PRAGMA index_list(characters)").some((row) => String(row.name) === "idx_characters_favorite");
|
|
4159
|
+
if (!applied.has(113) || !characterFavoritePresent || !characterFavoriteIndexPresent) {
|
|
4160
|
+
this.transaction(() => {
|
|
4161
|
+
const columns = new Set(this.all("PRAGMA table_info(characters)").map((row) => String(row.name)));
|
|
4162
|
+
if (!columns.has("is_favorite")) {
|
|
4163
|
+
this.run("ALTER TABLE characters ADD COLUMN is_favorite INTEGER NOT NULL DEFAULT 0 CHECK(is_favorite IN (0, 1))");
|
|
4164
|
+
}
|
|
4165
|
+
this.run("CREATE INDEX IF NOT EXISTS idx_characters_favorite ON characters(work_id, is_favorite DESC, name)");
|
|
4166
|
+
this.run("INSERT OR IGNORE INTO schema_migrations (version, applied_at) VALUES (113, ?)", new Date().toISOString());
|
|
4167
|
+
});
|
|
4168
|
+
const integrity = this.all("PRAGMA integrity_check");
|
|
4169
|
+
if (integrity.some((row) => row.integrity_check !== "ok")) {
|
|
4170
|
+
throw new Error(`数据库完整性检查失败:${integrity.map((row) => row.integrity_check).join(";")}`);
|
|
4171
|
+
}
|
|
4172
|
+
const foreignKeys = this.all("PRAGMA foreign_key_check");
|
|
4173
|
+
if (foreignKeys.length > 0)
|
|
4174
|
+
throw new Error(`数据库外键检查失败:发现 ${foreignKeys.length} 条异常记录`);
|
|
4175
|
+
}
|
|
4176
|
+
const favoriteRecordTables = ["drafts", "settings", "organizations"];
|
|
4177
|
+
const favoriteRecordColumnsPresent = favoriteRecordTables.every((table) => (this.all(`PRAGMA table_info(${table})`).some((row) => String(row.name) === "is_favorite")));
|
|
4178
|
+
const favoriteRecordIndexes = [
|
|
4179
|
+
["drafts", "idx_drafts_favorite"],
|
|
4180
|
+
["settings", "idx_settings_favorite"],
|
|
4181
|
+
["organizations", "idx_organizations_favorite"]
|
|
4182
|
+
];
|
|
4183
|
+
const favoriteRecordIndexesPresent = favoriteRecordIndexes.every(([table, index]) => (this.all(`PRAGMA index_list(${table})`).some((row) => String(row.name) === index)));
|
|
4184
|
+
if (!applied.has(114) || !favoriteRecordColumnsPresent || !favoriteRecordIndexesPresent) {
|
|
4185
|
+
this.transaction(() => {
|
|
4186
|
+
for (const table of favoriteRecordTables) {
|
|
4187
|
+
const columns = new Set(this.all(`PRAGMA table_info(${table})`).map((row) => String(row.name)));
|
|
4188
|
+
if (!columns.has("is_favorite")) {
|
|
4189
|
+
this.run(`ALTER TABLE ${table} ADD COLUMN is_favorite INTEGER NOT NULL DEFAULT 0 CHECK(is_favorite IN (0, 1))`);
|
|
4190
|
+
}
|
|
4191
|
+
}
|
|
4192
|
+
this.run("CREATE INDEX IF NOT EXISTS idx_drafts_favorite ON drafts(work_id, is_favorite DESC, updated_at DESC, title)");
|
|
4193
|
+
this.run("CREATE INDEX IF NOT EXISTS idx_settings_favorite ON settings(work_id, is_favorite DESC, locked DESC, category, title)");
|
|
4194
|
+
this.run("CREATE INDEX IF NOT EXISTS idx_organizations_favorite ON organizations(work_id, is_favorite DESC, name)");
|
|
4195
|
+
this.run("INSERT OR IGNORE INTO schema_migrations (version, applied_at) VALUES (114, ?)", new Date().toISOString());
|
|
4196
|
+
});
|
|
4197
|
+
const integrity = this.all("PRAGMA integrity_check");
|
|
4198
|
+
if (integrity.some((row) => row.integrity_check !== "ok")) {
|
|
4199
|
+
throw new Error(`数据库完整性检查失败:${integrity.map((row) => row.integrity_check).join(";")}`);
|
|
4200
|
+
}
|
|
4201
|
+
const foreignKeys = this.all("PRAGMA foreign_key_check");
|
|
4202
|
+
if (foreignKeys.length > 0)
|
|
4203
|
+
throw new Error(`数据库外键检查失败:发现 ${foreignKeys.length} 条异常记录`);
|
|
4204
|
+
}
|
|
4205
|
+
const scenePinPresent = this.all("PRAGMA table_info(ai_conversations)").some((row) => String(row.name) === "scene_pin_json");
|
|
4206
|
+
if (!applied.has(115) || !scenePinPresent) {
|
|
4207
|
+
this.transaction(() => {
|
|
4208
|
+
const columns = new Set(this.all("PRAGMA table_info(ai_conversations)").map((row) => String(row.name)));
|
|
4209
|
+
if (!columns.has("scene_pin_json")) {
|
|
4210
|
+
this.run("ALTER TABLE ai_conversations ADD COLUMN scene_pin_json TEXT NOT NULL DEFAULT '{}'");
|
|
4211
|
+
}
|
|
4212
|
+
this.run("INSERT OR IGNORE INTO schema_migrations (version, applied_at) VALUES (115, ?)", new Date().toISOString());
|
|
4213
|
+
});
|
|
4214
|
+
const integrity = this.all("PRAGMA integrity_check");
|
|
4215
|
+
if (integrity.some((row) => row.integrity_check !== "ok")) {
|
|
4216
|
+
throw new Error(`数据库完整性检查失败:${integrity.map((row) => row.integrity_check).join(";")}`);
|
|
4217
|
+
}
|
|
4218
|
+
const foreignKeys = this.all("PRAGMA foreign_key_check");
|
|
4219
|
+
if (foreignKeys.length > 0)
|
|
4220
|
+
throw new Error(`数据库外键检查失败:发现 ${foreignKeys.length} 条异常记录`);
|
|
4221
|
+
}
|
|
4130
4222
|
}
|
|
4131
4223
|
normalizeCharacterName(value) {
|
|
4132
4224
|
return value.normalize("NFKC").trim().replace(/\s+/gu, " ").toLocaleLowerCase("zh-CN");
|