tavern-harness 0.1.13 → 0.1.14
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/CHANGELOG.md +65 -0
- package/index.html +1 -1
- package/package.json +1 -1
- package/persistence-server.mjs +54 -2
- package/src/App.tsx +91 -25
- package/src/components/AchievementModal.tsx +4 -2
- package/src/components/CharactersView.tsx +53 -25
- package/src/components/ChatView.tsx +264 -135
- package/src/components/Dashboard.tsx +12 -8
- package/src/components/DeleteConfirmDialog.tsx +1 -1
- package/src/components/FileDisplayModal.tsx +1 -1
- package/src/components/GameplayDialogs.tsx +2 -2
- package/src/components/NewSessionMenu.tsx +1 -1
- package/src/components/SettingsView.tsx +46 -29
- package/src/components/Sidebar.tsx +30 -3
- package/src/components/StatsView.tsx +55 -45
- package/src/components/VersionHistoryModal.tsx +1 -1
- package/src/components/WorkspaceFileManagerModal.tsx +1 -1
- package/src/components/shared.tsx +84 -24
- package/src/core/achievements.ts +22 -4
- package/src/core/avatarThumbnail.ts +245 -0
- package/src/core/characterBook.ts +2 -1
- package/src/core/i18n.ts +42 -6
- package/src/core/mobileViewport.ts +18 -3
- package/src/core/openai.ts +41 -19
- package/src/core/randomId.ts +19 -0
- package/src/core/rowFingerprint.ts +75 -0
- package/src/core/stats.ts +50 -5
- package/src/core/stickyBottom.ts +10 -1
- package/src/core/textPreview.ts +16 -0
- package/src/db/database.ts +101 -13
- package/src/generated/changelog.json +87 -1
- package/src/main.tsx +12 -21
- package/src/store/store.ts +179 -53
- package/src/theme/chat.css +62 -71
- package/src/theme/global.css +85 -21
- package/src/theme/theme.ts +13 -10
- package/src/theme/views.css +82 -5
- package/src/types/models.ts +2 -0
- package/vite.config.ts +8 -2
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 生成一个唯一 id。
|
|
3
|
+
*
|
|
4
|
+
* `crypto.randomUUID()` 只在安全上下文(HTTPS / localhost)可用;通过局域网
|
|
5
|
+
* http 地址(手机扫码)打开的页面里它是 undefined,直接调用会让整个回合抛错。
|
|
6
|
+
* 因此优先使用它,其次退回 `crypto.getRandomValues()`(非安全上下文同样可用),
|
|
7
|
+
* 最后才是 Math.random 兜底。
|
|
8
|
+
*/
|
|
9
|
+
export function randomId(): string {
|
|
10
|
+
const cryptoApi: Crypto | undefined = globalThis.crypto;
|
|
11
|
+
if (typeof cryptoApi?.randomUUID === 'function') return cryptoApi.randomUUID();
|
|
12
|
+
if (typeof cryptoApi?.getRandomValues === 'function') {
|
|
13
|
+
const bytes = cryptoApi.getRandomValues(new Uint8Array(16));
|
|
14
|
+
let hex = '';
|
|
15
|
+
for (const byte of bytes) hex += byte.toString(16).padStart(2, '0');
|
|
16
|
+
return hex;
|
|
17
|
+
}
|
|
18
|
+
return `${Date.now().toString(36)}${Math.random().toString(36).slice(2, 10)}`;
|
|
19
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
// 刷新集合时判断记录是否变化。
|
|
2
|
+
|
|
3
|
+
import type { McpTool, NpcCharacter, WorldBook } from '../types/models';
|
|
4
|
+
|
|
5
|
+
/** 32 位 FNV-1a。 */
|
|
6
|
+
export function hashText(value: string | null | undefined): number {
|
|
7
|
+
if (!value) return 0;
|
|
8
|
+
let hash = 2166136261;
|
|
9
|
+
for (let i = 0; i < value.length; i += 1) {
|
|
10
|
+
hash ^= value.charCodeAt(i);
|
|
11
|
+
hash = Math.imul(hash, 16777619);
|
|
12
|
+
}
|
|
13
|
+
return hash >>> 0;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/** 小图直接做内容指纹;超过该长度的图片只比长度,避免刷新时扫描几 MB。 */
|
|
17
|
+
const IMAGE_FINGERPRINT_MAX_CHARS = 32 * 1024;
|
|
18
|
+
|
|
19
|
+
function imageFingerprint(url: string | null | undefined): string {
|
|
20
|
+
if (!url) return '0';
|
|
21
|
+
if (url.length > IMAGE_FINGERPRINT_MAX_CHARS) return `len:${url.length}`;
|
|
22
|
+
return `hash:${url.length}:${hashText(url)}`;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** 角色记录指纹(小头像做内容指纹,大图只比长度)。 */
|
|
26
|
+
export function npcFingerprint(n: NpcCharacter): string {
|
|
27
|
+
return [
|
|
28
|
+
n.id ?? 0,
|
|
29
|
+
hashText(n.name),
|
|
30
|
+
hashText(n.prompt),
|
|
31
|
+
hashText(n.greeting),
|
|
32
|
+
hashText(n.characterBook),
|
|
33
|
+
hashText((n.alternateGreetings ?? []).join('\u0002')),
|
|
34
|
+
imageFingerprint(n.avatarDataUrl),
|
|
35
|
+
(n.enabledToolNames ?? []).join(','),
|
|
36
|
+
n.avatarColorOrdinal ?? 0,
|
|
37
|
+
n.isBuiltIn ? 1 : 0,
|
|
38
|
+
n.isTavernKeeper ? 1 : 0,
|
|
39
|
+
].join('\u0001');
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** 世界书记录指纹(小配图做内容指纹,大图只比长度)。 */
|
|
43
|
+
export function worldBookFingerprint(b: WorldBook): string {
|
|
44
|
+
return [
|
|
45
|
+
b.id ?? 0,
|
|
46
|
+
hashText(b.name),
|
|
47
|
+
hashText(b.content),
|
|
48
|
+
hashText(b.characterBook),
|
|
49
|
+
imageFingerprint(b.imageUri),
|
|
50
|
+
b.isBuiltIn ? 1 : 0,
|
|
51
|
+
].join('\u0001');
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** 技能记录指纹。 */
|
|
55
|
+
export function toolFingerprint(t: McpTool): string {
|
|
56
|
+
return [
|
|
57
|
+
t.id ?? 0,
|
|
58
|
+
hashText(t.name),
|
|
59
|
+
hashText(t.jsonContent),
|
|
60
|
+
hashText(t.executionJson),
|
|
61
|
+
t.isBuiltIn ? 1 : 0,
|
|
62
|
+
t.origin ?? '',
|
|
63
|
+
t.displayOrder ?? 0,
|
|
64
|
+
].join('\u0001');
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/** 同长度且逐项指纹一致 → 视为没有变化(跳过写入,避免无谓的重新渲染)。 */
|
|
68
|
+
export function sameRows<T>(prev: T[], next: T[], fingerprint: (row: T) => string): boolean {
|
|
69
|
+
if (prev === next) return true;
|
|
70
|
+
if (prev.length !== next.length) return false;
|
|
71
|
+
for (let i = 0; i < prev.length; i += 1) {
|
|
72
|
+
if (prev[i] !== next[i] && fingerprint(prev[i]) !== fingerprint(next[i])) return false;
|
|
73
|
+
}
|
|
74
|
+
return true;
|
|
75
|
+
}
|
package/src/core/stats.ts
CHANGED
|
@@ -13,6 +13,42 @@ interface StatsDelta {
|
|
|
13
13
|
npcRounds?: { npcId: number; npcName: string; rounds: number };
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
+
export interface CareerStats {
|
|
17
|
+
inputTokens: number;
|
|
18
|
+
outputTokens: number;
|
|
19
|
+
totalRounds: number;
|
|
20
|
+
sessionCount: number;
|
|
21
|
+
npcStats: Array<{ npcId: number; npcName: string; rounds: number }>;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
let cachedCareerStats: CareerStats | null = null;
|
|
25
|
+
let loadingCareerStats: Promise<CareerStats> | null = null;
|
|
26
|
+
|
|
27
|
+
async function loadCareerStats(): Promise<CareerStats> {
|
|
28
|
+
const [stats, npcStats, sessionCount] = await Promise.all([
|
|
29
|
+
db.careerStats.get(1),
|
|
30
|
+
db.careerNpcStats.toArray(),
|
|
31
|
+
db.sessions.count(),
|
|
32
|
+
]);
|
|
33
|
+
return {
|
|
34
|
+
...(stats ?? { id: 1, inputTokens: 0, outputTokens: 0, totalRounds: 0 }),
|
|
35
|
+
npcStats,
|
|
36
|
+
sessionCount,
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** 后台预读成就页所需的统计,避免首次打开页面时等待远端持久化服务。 */
|
|
41
|
+
export async function preloadCareerStats(): Promise<void> {
|
|
42
|
+
if (cachedCareerStats) return;
|
|
43
|
+
loadingCareerStats ??= loadCareerStats().then((stats) => {
|
|
44
|
+
cachedCareerStats = stats;
|
|
45
|
+
return stats;
|
|
46
|
+
}).finally(() => {
|
|
47
|
+
loadingCareerStats = null;
|
|
48
|
+
});
|
|
49
|
+
await loadingCareerStats;
|
|
50
|
+
}
|
|
51
|
+
|
|
16
52
|
/** 消息产生后累计到生涯统计(服务器关闭也不丢失:已持久化消息带 usage) */
|
|
17
53
|
export async function accumulateStats(delta: StatsDelta, sessionId: number | null, _npcId: number | null): Promise<void> {
|
|
18
54
|
if (delta.inputTokens <= 0 && delta.outputTokens <= 0 && delta.rounds <= 0) return;
|
|
@@ -38,21 +74,30 @@ export async function accumulateStats(delta: StatsDelta, sessionId: number | nul
|
|
|
38
74
|
}
|
|
39
75
|
}
|
|
40
76
|
void sessionId;
|
|
77
|
+
cachedCareerStats = null;
|
|
41
78
|
|
|
42
79
|
// 成就检测(基于累计 Token 数)
|
|
43
80
|
await checkAchievementUnlocks();
|
|
44
81
|
}
|
|
45
82
|
|
|
46
|
-
export async function getCareerStats() {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
83
|
+
export async function getCareerStats(): Promise<CareerStats> {
|
|
84
|
+
if (cachedCareerStats) {
|
|
85
|
+
const stats = cachedCareerStats;
|
|
86
|
+
cachedCareerStats = null;
|
|
87
|
+
return stats;
|
|
88
|
+
}
|
|
89
|
+
if (loadingCareerStats) {
|
|
90
|
+
const stats = await loadingCareerStats;
|
|
91
|
+
cachedCareerStats = null;
|
|
92
|
+
return stats;
|
|
93
|
+
}
|
|
94
|
+
return loadCareerStats();
|
|
51
95
|
}
|
|
52
96
|
|
|
53
97
|
export async function resetCareerStats(): Promise<void> {
|
|
54
98
|
await db.careerStats.put({ id: 1, inputTokens: 0, outputTokens: 0, totalRounds: 0 });
|
|
55
99
|
await db.careerNpcStats.clear();
|
|
100
|
+
cachedCareerStats = null;
|
|
56
101
|
}
|
|
57
102
|
|
|
58
103
|
|
package/src/core/stickyBottom.ts
CHANGED
|
@@ -30,11 +30,20 @@ export function isNearBottom(
|
|
|
30
30
|
*
|
|
31
31
|
* @returns 解除监听的函数
|
|
32
32
|
*/
|
|
33
|
-
export function keepStickyBottom(
|
|
33
|
+
export function keepStickyBottom(
|
|
34
|
+
el: HTMLElement,
|
|
35
|
+
threshold = STICKY_BOTTOM_THRESHOLD,
|
|
36
|
+
isSuspended: () => boolean = () => false,
|
|
37
|
+
): () => void {
|
|
34
38
|
let lastHeight = el.clientHeight;
|
|
35
39
|
const observer = new ResizeObserver(() => {
|
|
36
40
|
const height = el.clientHeight;
|
|
41
|
+
if (height === 0) return;
|
|
37
42
|
if (height === lastHeight) return;
|
|
43
|
+
if (isSuspended()) {
|
|
44
|
+
lastHeight = height;
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
38
47
|
// 用变化前的高度判断,避免容器长高时浏览器已经把 scrollTop 夹到新上限而误判。
|
|
39
48
|
const wasNearBottom = isNearBottom(el.scrollHeight, el.scrollTop, lastHeight, threshold);
|
|
40
49
|
lastHeight = height;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/** 截断卡片列表中的长文本预览。 */
|
|
2
|
+
export const CARD_PREVIEW_MAX_CHARS = 2000;
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* 截断卡片预览文本;不拆开代理对(emoji / 生僻字),并追加省略号。
|
|
6
|
+
* `maxChars <= 0` 表示不截断(调用方默认使用 CARD_PREVIEW_MAX_CHARS)。
|
|
7
|
+
*/
|
|
8
|
+
export function textPreview(text: string | null | undefined, maxChars: number = CARD_PREVIEW_MAX_CHARS): string {
|
|
9
|
+
if (!text) return '';
|
|
10
|
+
if (maxChars <= 0 || text.length <= maxChars) return text;
|
|
11
|
+
let end = maxChars;
|
|
12
|
+
const last = text.charCodeAt(end - 1);
|
|
13
|
+
// 高代理项结尾:少切一个,避免把两段 UTF-16 组成的字符劈开
|
|
14
|
+
if (last >= 0xd800 && last <= 0xdbff) end -= 1;
|
|
15
|
+
return `${text.slice(0, end).trimEnd()}…`;
|
|
16
|
+
}
|
package/src/db/database.ts
CHANGED
|
@@ -17,6 +17,7 @@ import type {
|
|
|
17
17
|
import { BUILTIN_TOOLS, ALL_BUILTIN_TOOL_NAMES } from '../core/toolDefinitions';
|
|
18
18
|
import { currentLanguage, translate } from '../core/i18n';
|
|
19
19
|
import { hasBrowserUiPreferences, saveBrowserUiPreferences } from '../core/browserPreferences';
|
|
20
|
+
import { randomId } from '../core/randomId';
|
|
20
21
|
import BUILTIN_TAVERN_HANDBOOK_CONTENT from '../assets/tavern-handbook.md?raw';
|
|
21
22
|
|
|
22
23
|
export class TavernDB extends Dexie {
|
|
@@ -272,7 +273,7 @@ const clientId = (() => {
|
|
|
272
273
|
if (existing) return existing;
|
|
273
274
|
const created = typeof crypto !== 'undefined' && typeof crypto.randomUUID === 'function'
|
|
274
275
|
? crypto.randomUUID()
|
|
275
|
-
: `non-browser-${
|
|
276
|
+
: `non-browser-${randomId()}`;
|
|
276
277
|
browserSessionStorage?.setItem(key, created);
|
|
277
278
|
return created;
|
|
278
279
|
})();
|
|
@@ -333,6 +334,67 @@ async function requireWriteLock(): Promise<void> {
|
|
|
333
334
|
}
|
|
334
335
|
}
|
|
335
336
|
|
|
337
|
+
type StartupSnapshot = {
|
|
338
|
+
lock: { writable: boolean; held: boolean };
|
|
339
|
+
collections: {
|
|
340
|
+
settings: Array<{ value: AppSettings }>;
|
|
341
|
+
providers: Array<{ value: ApiProvider }>;
|
|
342
|
+
npcs: Array<{ value: NpcCharacter }>;
|
|
343
|
+
sessions: Array<{ value: ChatSession }>;
|
|
344
|
+
worldBooks: Array<{ value: WorldBook }>;
|
|
345
|
+
tools: Array<{ value: McpTool }>;
|
|
346
|
+
achievementUnlocks: Array<{ value: AchievementUnlock }>;
|
|
347
|
+
};
|
|
348
|
+
};
|
|
349
|
+
|
|
350
|
+
/** 一次请求取得首屏所需的轻量数据,避免逐表读取产生的串行 HTTP 往返。 */
|
|
351
|
+
export async function loadStartupSnapshot(): Promise<StartupSnapshot> {
|
|
352
|
+
let snapshot: StartupSnapshot;
|
|
353
|
+
try {
|
|
354
|
+
snapshot = await persistenceRequest<StartupSnapshot>('/startup/snapshot');
|
|
355
|
+
} catch (error) {
|
|
356
|
+
// 热更新期间旧服务进程可能还未注册快照路由。临时降级到旧的逐表读取,
|
|
357
|
+
// 让页面可用;Vite 会在 persistence-server.mjs 变更后重启该进程。
|
|
358
|
+
if (!(error instanceof Error) || !error.message.includes('Unknown persistence endpoint: /startup/snapshot')) throw error;
|
|
359
|
+
await initDatabase();
|
|
360
|
+
const readOnly = await isWriteLocked();
|
|
361
|
+
const [settings, providers, npcs, sessions, worldBooks, tools, achievementUnlocks] = await Promise.all([
|
|
362
|
+
db.settings.toArray(),
|
|
363
|
+
db.providers.toArray(),
|
|
364
|
+
db.npcs.toArray(),
|
|
365
|
+
db.sessions.toArray(),
|
|
366
|
+
db.worldBooks.toArray(),
|
|
367
|
+
db.tools.toArray(),
|
|
368
|
+
db.achievementUnlocks.toArray(),
|
|
369
|
+
]);
|
|
370
|
+
return {
|
|
371
|
+
lock: { writable: !readOnly, held: readOnly || hasWriteLock },
|
|
372
|
+
collections: {
|
|
373
|
+
settings: settings.map((value) => ({ value })),
|
|
374
|
+
providers: providers.map((value) => ({ value })),
|
|
375
|
+
npcs: npcs.map((value) => ({ value })),
|
|
376
|
+
sessions: sessions.map((value) => ({ value })),
|
|
377
|
+
worldBooks: worldBooks.map((value) => ({ value })),
|
|
378
|
+
tools: tools.map((value) => ({ value })),
|
|
379
|
+
achievementUnlocks: achievementUnlocks.map((value) => ({ value })),
|
|
380
|
+
},
|
|
381
|
+
};
|
|
382
|
+
}
|
|
383
|
+
hasWriteLock = snapshot.lock.writable;
|
|
384
|
+
if (snapshot.lock.writable && lockHeartbeat == null) {
|
|
385
|
+
lockHeartbeat = window.setInterval(async () => {
|
|
386
|
+
try {
|
|
387
|
+
const state = await persistenceRequest<{ lock: { writable: boolean } }>('/lock/status');
|
|
388
|
+
hasWriteLock = state.lock.writable;
|
|
389
|
+
} catch {
|
|
390
|
+
hasWriteLock = false;
|
|
391
|
+
}
|
|
392
|
+
}, 1_000);
|
|
393
|
+
}
|
|
394
|
+
if (snapshot.lock.held && !snapshot.lock.writable) markControlReadOnly();
|
|
395
|
+
return snapshot;
|
|
396
|
+
}
|
|
397
|
+
|
|
336
398
|
export async function isWriteLocked(): Promise<boolean> {
|
|
337
399
|
if (isControlReadOnly()) return true;
|
|
338
400
|
const result = await persistenceRequest<{ lock: { writable: boolean; held: boolean } }>('/lock/status');
|
|
@@ -371,18 +433,31 @@ function primaryKey(collection: CollectionName, value: Row): string {
|
|
|
371
433
|
}
|
|
372
434
|
|
|
373
435
|
class RemoteQuery<T extends object> {
|
|
374
|
-
constructor(
|
|
436
|
+
constructor(
|
|
437
|
+
private readonly table: RemoteTable<T>,
|
|
438
|
+
private readonly predicate: (value: T) => boolean = () => true,
|
|
439
|
+
private readonly field?: string,
|
|
440
|
+
private readonly fieldValue?: string | number | boolean,
|
|
441
|
+
) {}
|
|
375
442
|
equals(value: unknown): RemoteQuery<T> {
|
|
376
443
|
const fields = this.table.queryField === '[sessionId+participantId]'
|
|
377
444
|
? ['sessionId', 'participantId']
|
|
378
445
|
: [this.table.queryField];
|
|
446
|
+
const canQueryServer = fields.length === 1 && (typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean');
|
|
379
447
|
return new RemoteQuery(this.table, (row) => {
|
|
380
448
|
const actual = fields.length === 1 ? (row as Row)[fields[0]] : fields.map((field) => (row as Row)[field]);
|
|
381
449
|
return this.predicate(row) && JSON.stringify(actual) === JSON.stringify(value);
|
|
382
|
-
});
|
|
450
|
+
}, canQueryServer ? fields[0] : undefined, canQueryServer ? value : undefined);
|
|
451
|
+
}
|
|
452
|
+
filter(predicate: (value: T) => boolean): RemoteQuery<T> {
|
|
453
|
+
return new RemoteQuery(this.table, (row) => this.predicate(row) && predicate(row), this.field, this.fieldValue);
|
|
454
|
+
}
|
|
455
|
+
async toArray(): Promise<T[]> {
|
|
456
|
+
const rows = this.field && this.fieldValue !== undefined
|
|
457
|
+
? await this.table.toArrayByField(this.field, this.fieldValue)
|
|
458
|
+
: await this.table.toArray();
|
|
459
|
+
return rows.filter(this.predicate);
|
|
383
460
|
}
|
|
384
|
-
filter(predicate: (value: T) => boolean): RemoteQuery<T> { return new RemoteQuery(this.table, (row) => this.predicate(row) && predicate(row)); }
|
|
385
|
-
async toArray(): Promise<T[]> { return (await this.table.toArray()).filter(this.predicate); }
|
|
386
461
|
async first(): Promise<T | undefined> { return (await this.toArray())[0]; }
|
|
387
462
|
async count(): Promise<number> { return (await this.toArray()).length; }
|
|
388
463
|
async sortBy(field: string): Promise<T[]> { return (await this.toArray()).sort((a, b) => Number((a as Row)[field]) - Number((b as Row)[field])); }
|
|
@@ -410,6 +485,14 @@ class RemoteTable<T extends object> {
|
|
|
410
485
|
const result = await persistenceRequest<{ records: Array<{ value: T }> }>('/records/list', { collection: this.collection });
|
|
411
486
|
return result.records.map((record) => record.value);
|
|
412
487
|
}
|
|
488
|
+
async toArrayByField(field: string, value: string | number | boolean): Promise<T[]> {
|
|
489
|
+
const result = await persistenceRequest<{ records: Array<{ value: T }> }>('/records/list-by-field', {
|
|
490
|
+
collection: this.collection,
|
|
491
|
+
field,
|
|
492
|
+
value,
|
|
493
|
+
});
|
|
494
|
+
return result.records.map((record) => record.value);
|
|
495
|
+
}
|
|
413
496
|
async get(key: unknown): Promise<T | undefined> {
|
|
414
497
|
const result = await persistenceRequest<{ record: { value: T } | null }>('/records/get', { collection: this.collection, key: Array.isArray(key) ? key.join(':') : String(key) });
|
|
415
498
|
return result.record?.value;
|
|
@@ -540,14 +623,8 @@ export function isTavernKeeper(npc: Pick<NpcCharacter, 'isTavernKeeper'>): boole
|
|
|
540
623
|
return npc.isTavernKeeper === true;
|
|
541
624
|
}
|
|
542
625
|
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
baseUrl: 'https://api.openai.com/v1/',
|
|
546
|
-
apiKey: '',
|
|
547
|
-
defaultModel: '',
|
|
548
|
-
defaultProviderId: null,
|
|
549
|
-
themeMode: 'system',
|
|
550
|
-
language: null,
|
|
626
|
+
/** 「生成参数」卡片的默认值;设置页重置按钮与首次初始化共用这一份来源。 */
|
|
627
|
+
export const DEFAULT_GENERATION_SETTINGS = {
|
|
551
628
|
temperature: 1.0,
|
|
552
629
|
topP: 0.95,
|
|
553
630
|
maxTokens: 0,
|
|
@@ -557,6 +634,17 @@ export const DEFAULT_SETTINGS: AppSettings = {
|
|
|
557
634
|
repetitionPenalty: 1,
|
|
558
635
|
reasoningEffort: 'auto',
|
|
559
636
|
contextCompressionThreshold: 'off',
|
|
637
|
+
} satisfies Partial<AppSettings>;
|
|
638
|
+
|
|
639
|
+
export const DEFAULT_SETTINGS: AppSettings = {
|
|
640
|
+
id: 1,
|
|
641
|
+
baseUrl: 'https://api.openai.com/v1/',
|
|
642
|
+
apiKey: '',
|
|
643
|
+
defaultModel: '',
|
|
644
|
+
defaultProviderId: null,
|
|
645
|
+
themeMode: 'system',
|
|
646
|
+
language: null,
|
|
647
|
+
...DEFAULT_GENERATION_SETTINGS,
|
|
560
648
|
seed: -1,
|
|
561
649
|
stop: '',
|
|
562
650
|
isStreaming: true,
|
|
@@ -1,7 +1,93 @@
|
|
|
1
1
|
{
|
|
2
|
-
"latest": "0.1.
|
|
2
|
+
"latest": "0.1.14",
|
|
3
3
|
"repo": "https://github.com/Rannichan/Tavern-Harness",
|
|
4
4
|
"entries": [
|
|
5
|
+
{
|
|
6
|
+
"version": "0.1.14",
|
|
7
|
+
"date": "2026-10-24",
|
|
8
|
+
"breaking": false,
|
|
9
|
+
"compare": "v0.1.13...v0.1.14",
|
|
10
|
+
"groups": {
|
|
11
|
+
"zh-CN": [
|
|
12
|
+
{
|
|
13
|
+
"kind": "added",
|
|
14
|
+
"items": [
|
|
15
|
+
"设置 → 生成参数新增「重置」按钮,一键恢复温度、Top P、Top K 等默认值;已是默认值时按钮不可用"
|
|
16
|
+
]
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
"kind": "changed",
|
|
20
|
+
"items": [
|
|
21
|
+
"启动体验:界面先于数据加载显示,启动期间展示加载动画而非空白页;启动数据合并为一次快照请求,长列表通过增量渲染与缓存保持流畅",
|
|
22
|
+
"成就页重新排版:奖杯陈列柜置顶,生涯统计与「重置统计」分区展示",
|
|
23
|
+
"统一弹窗尺寸(紧凑 / 标准 / 宽屏三档)并适配移动端;弹窗不再响应点击遮罩关闭,避免编辑内容时误触丢失",
|
|
24
|
+
"流式生成更稳定:自动跟随最新内容,向上回看历史时不会被拉回底部;键盘弹出时思考与回复内容不再被输入框遮挡",
|
|
25
|
+
"移动端消息编辑器:键盘开合过渡更平滑,消息操作与编辑时的附件按钮更易用",
|
|
26
|
+
"聊天附件、思考面板与工具卡片的样式更清晰,浅色主题配色更柔和统一"
|
|
27
|
+
]
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
"kind": "fixed",
|
|
31
|
+
"items": [
|
|
32
|
+
"修复生成失败或模型返回空内容时界面停留在「生成中」的问题:现在会回滚本轮并提示;已收到的部分正文会保留并标注「生成已中断」",
|
|
33
|
+
"修复通过局域网地址(侧栏二维码)在手机上打开时,回合可能一直卡住没有回复的问题;连接超时会自动改用同源代理,全部失败时明确提示网络错误",
|
|
34
|
+
"修复刷新或切换标签页时短暂闪出错误主题的问题,首帧即应用正确的深浅色背景",
|
|
35
|
+
"修复首页角色卡片不显示自定义头像的问题",
|
|
36
|
+
"修复移动端消息操作按钮、编辑附件动作与聊天附件样式的问题",
|
|
37
|
+
"修复启动时模型服务列表可能为空、旧会话消息加载较慢的问题"
|
|
38
|
+
]
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
"kind": "internal",
|
|
42
|
+
"items": [
|
|
43
|
+
"持久化服务新增启动快照与按字段查询接口,减少启动请求数量,并补充相应测试",
|
|
44
|
+
"新增头像缩略图与行指纹缓存,降低长列表重复渲染开销",
|
|
45
|
+
"统一弹窗组件与尺寸定义,移除重复的遮罩点击逻辑",
|
|
46
|
+
"补全 yolo 集成测试所需的持久化接口 mock"
|
|
47
|
+
]
|
|
48
|
+
}
|
|
49
|
+
],
|
|
50
|
+
"en": [
|
|
51
|
+
{
|
|
52
|
+
"kind": "added",
|
|
53
|
+
"items": [
|
|
54
|
+
"New \"Reset\" button in Settings → Generation parameters restores the default temperature, Top P, Top K, and related values; it is disabled when everything is already at defaults"
|
|
55
|
+
]
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
"kind": "changed",
|
|
59
|
+
"items": [
|
|
60
|
+
"Startup: the UI mounts before data loads and shows a loading indicator instead of a blank page; startup data is fetched in a single snapshot request, and long lists stay smooth through incremental rendering and caching",
|
|
61
|
+
"Achievements page reorganized: the trophy shelf comes first, with career stats and a separate \"Reset stats\" section below",
|
|
62
|
+
"Modals now share three sizes (compact, standard, wide) and adapt to mobile; clicking the backdrop no longer dismisses them, preventing accidental loss of edits",
|
|
63
|
+
"Streaming is more stable: the view follows new content automatically but stops following when you scroll up to read history, and the keyboard no longer covers thinking or reply content",
|
|
64
|
+
"Mobile message editor: smoother keyboard transitions and easier access to attachment actions while editing",
|
|
65
|
+
"Clearer styling for chat attachments, thinking panels, and tool cards, with softer, more consistent light-theme colors"
|
|
66
|
+
]
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
"kind": "fixed",
|
|
70
|
+
"items": [
|
|
71
|
+
"Fixed the UI getting stuck in \"generating\" when generation failed or the model returned no content: the turn now rolls back with a clear message, while partial text is kept and marked as interrupted",
|
|
72
|
+
"Fixed turns occasionally hanging without a reply when the app is opened on a phone through its LAN address (sidebar QR code); connection timeouts now fall back to the same-origin proxy and report a network error when every candidate fails",
|
|
73
|
+
"Fixed a brief flash of the wrong theme when refreshing or switching tabs; the correct light/dark background is applied on the first frame",
|
|
74
|
+
"Fixed character cards on the home page not showing custom avatars",
|
|
75
|
+
"Fixed mobile message action buttons, attachment actions while editing, and chat attachment styling",
|
|
76
|
+
"Fixed the model provider list sometimes being empty at startup and slow loading of older session messages"
|
|
77
|
+
]
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
"kind": "internal",
|
|
81
|
+
"items": [
|
|
82
|
+
"Added startup snapshot and list-by-field persistence endpoints to reduce startup requests, with tests",
|
|
83
|
+
"Added avatar thumbnail and row fingerprint caches to cut repeated rendering work in long lists",
|
|
84
|
+
"Unified the modal component and sizing, removing duplicate backdrop-click logic",
|
|
85
|
+
"Filled in the persistence endpoint mocks required by the yolo integration test"
|
|
86
|
+
]
|
|
87
|
+
}
|
|
88
|
+
]
|
|
89
|
+
}
|
|
90
|
+
},
|
|
5
91
|
{
|
|
6
92
|
"version": "0.1.13",
|
|
7
93
|
"date": "2026-10-21",
|
package/src/main.tsx
CHANGED
|
@@ -1,39 +1,30 @@
|
|
|
1
1
|
import { StrictMode } from 'react';
|
|
2
2
|
import { createRoot } from 'react-dom/client';
|
|
3
3
|
import App from './App';
|
|
4
|
-
import { initDatabase } from './db/database';
|
|
5
4
|
import { applyThemeFromCache } from './theme/theme';
|
|
6
5
|
import { enableHorizontalWheel } from './core/horizontalWheel';
|
|
7
6
|
import { initMobileViewport } from './core/mobileViewport';
|
|
8
7
|
import { installWeChatTouchSelectionGuard } from './core/wechatTouch';
|
|
9
8
|
import './theme/global.css';
|
|
10
9
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
async function bootstrap() {
|
|
14
|
-
// 首帧同步应用主题(读 localStorage 缓存),避免刷新闪动
|
|
10
|
+
try {
|
|
11
|
+
// React 挂载前完成主题变量初始化,避免新标签页先按 CSS 默认主题绘制壳层。
|
|
15
12
|
applyThemeFromCache();
|
|
16
13
|
// 移动端视口高度控制:吸收键盘开合时地址栏/底部工具栏的两段式变化
|
|
17
14
|
initMobileViewport();
|
|
18
15
|
// 微信 Android 的长按由原生层接管:兜底阻止系统选词、清掉残留选区
|
|
19
16
|
installWeChatTouchSelectionGuard();
|
|
20
|
-
await initDatabase();
|
|
21
17
|
// 全局:支持 .side-nav 等横向滚动容器响应鼠标滚轮(垂直 → 水平)
|
|
22
18
|
enableHorizontalWheel();
|
|
19
|
+
} catch (error) {
|
|
20
|
+
// 非核心的浏览器增强失败不能阻止应用及其初始化错误界面出现。
|
|
21
|
+
console.error('Failed to configure Tavern Harness browser enhancements', error);
|
|
23
22
|
}
|
|
24
23
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
</StrictMode>
|
|
33
|
-
);
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
bootstrap().then(renderApp).catch((error: unknown) => {
|
|
37
|
-
console.error('Failed to start Tavern Harness', error);
|
|
38
|
-
renderApp();
|
|
39
|
-
});
|
|
24
|
+
// 在数据层完成异步初始化前先挂载 React。App 会立即显示壳层和启动状态,
|
|
25
|
+
// 避免 IndexedDB / 持久化服务较慢时出现无内容的空白页。
|
|
26
|
+
createRoot(document.getElementById('root')!).render(
|
|
27
|
+
<StrictMode>
|
|
28
|
+
<App />
|
|
29
|
+
</StrictMode>
|
|
30
|
+
);
|