tavern-harness 0.2.0 → 0.2.1
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 +49 -0
- package/package.json +1 -1
- package/persistence-server.mjs +60 -1
- package/sandbox-server.mjs +11 -8
- package/src/components/ChatView.tsx +4 -2
- package/src/components/FileDisplayModal.tsx +105 -2
- package/src/components/SettingsView.tsx +112 -1
- package/src/components/WorkspaceFileManagerModal.tsx +2 -2
- package/src/components/shared.tsx +28 -9
- package/src/core/i18n.ts +39 -0
- package/src/core/imageFilename.ts +21 -0
- package/src/core/imageGeneration.ts +32 -0
- package/src/core/prompts.ts +6 -1
- package/src/core/toolDefinitions.ts +21 -0
- package/src/core/tools/generatedSkillExecutor.ts +31 -2
- package/src/core/tools/toolExecutor.ts +104 -8
- package/src/db/database.ts +36 -4
- package/src/generated/changelog.json +71 -1
- package/src/store/store.ts +19 -5
- package/src/theme/chat.css +46 -3
- package/src/theme/views.css +27 -10
- package/src/types/models.ts +14 -1
- package/vite.config.ts +1 -1
|
@@ -1,7 +1,77 @@
|
|
|
1
1
|
{
|
|
2
|
-
"latest": "0.2.
|
|
2
|
+
"latest": "0.2.1",
|
|
3
3
|
"repo": "https://github.com/Rannichan/Tavern-Harness",
|
|
4
4
|
"entries": [
|
|
5
|
+
{
|
|
6
|
+
"version": "0.2.1",
|
|
7
|
+
"date": "2026-11-21",
|
|
8
|
+
"breaking": false,
|
|
9
|
+
"compare": "v0.2.0...v0.2.1",
|
|
10
|
+
"groups": {
|
|
11
|
+
"zh-CN": [
|
|
12
|
+
{
|
|
13
|
+
"kind": "added",
|
|
14
|
+
"items": [
|
|
15
|
+
"新增内置「生成图片」技能:在设置中添加「百炼 Token Plan」生图供应商并选定默认模型(qwen-image-3.0-pro / qwen-image-2.0-pro / qwen-image-2.0 / wan2.7-image / wan2.7-image-pro)后,角色即可按提示词生成图片,图片保存到工作区 `images/` 目录并自动打开预览",
|
|
16
|
+
"角色创建与更新技能支持 `avatar_path`:酒馆助手可以从工作区的 PNG / JPEG / WebP / BMP / AVIF 图片生成或清空角色头像,保存前会校验图片真实格式并压缩到存储上限",
|
|
17
|
+
"对话中的图片附件改为缩略图卡片,点击即可放大查看"
|
|
18
|
+
]
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
"kind": "changed",
|
|
22
|
+
"items": [
|
|
23
|
+
"生成的图片文件名改为根据提示词或指定文件名生成的可读名称,并自动追加时间戳与正确的扩展名,不再是一串 `generated-数字`"
|
|
24
|
+
]
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
"kind": "fixed",
|
|
28
|
+
"items": [
|
|
29
|
+
"修复图片预览弹窗缩放后无法平移、大图看不全的问题;图片现在按窗口自适应缩放,超出窗口时可在横向与纵向滚动,并保持居中",
|
|
30
|
+
"修复输入框内边距在不同屏幕宽度下不一致的问题"
|
|
31
|
+
]
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
"kind": "internal",
|
|
35
|
+
"items": [
|
|
36
|
+
"新增 `imageGeneration`、`imageFilename` 模块,并为生成图片文件名补充测试",
|
|
37
|
+
"持久化服务新增 `/image/generate` 端点,代理百炼 Token Plan 生图请求并下载结果;数据库升级至 v14,新增 `imageProviders` 表",
|
|
38
|
+
"沙箱服务新增二进制文件写入端点(上限 8MB),图片预览与 base64 写入端点纳入同源代理"
|
|
39
|
+
]
|
|
40
|
+
}
|
|
41
|
+
],
|
|
42
|
+
"en": [
|
|
43
|
+
{
|
|
44
|
+
"kind": "added",
|
|
45
|
+
"items": [
|
|
46
|
+
"Built-in Generate Image skill: after adding a Bailian Token Plan image provider in Settings and choosing a default model (qwen-image-3.0-pro, qwen-image-2.0-pro, qwen-image-2.0, wan2.7-image, wan2.7-image-pro), characters can generate images from prompts; images are saved to the workspace `images/` folder and opened in a preview automatically",
|
|
47
|
+
"Character create/update skills accept `avatar_path`: the Tavern Keeper can set or clear a character avatar from a PNG, JPEG, WebP, BMP, or AVIF file in the workspace, with real format validation and compression before saving",
|
|
48
|
+
"Image attachments in conversations are now thumbnail cards that open a larger preview on click"
|
|
49
|
+
]
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
"kind": "changed",
|
|
53
|
+
"items": [
|
|
54
|
+
"Generated images now get readable file names derived from the prompt or a requested filename, with a timestamp and the correct extension, instead of `generated-<number>`"
|
|
55
|
+
]
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
"kind": "fixed",
|
|
59
|
+
"items": [
|
|
60
|
+
"Fixed the image preview being impossible to pan after zooming; images now fit the window, scroll horizontally and vertically when larger, and stay centered",
|
|
61
|
+
"Fixed inconsistent composer padding across screen widths"
|
|
62
|
+
]
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
"kind": "internal",
|
|
66
|
+
"items": [
|
|
67
|
+
"Added the `imageGeneration` and `imageFilename` modules, with tests for generated image filenames",
|
|
68
|
+
"The persistence service gained an `/image/generate` endpoint that proxies Bailian Token Plan requests and downloads the result; the database moved to v14 with a new `imageProviders` table",
|
|
69
|
+
"The sandbox service gained a binary file-write endpoint (8MB limit), and the preview/base64 write endpoints are covered by the same-origin proxy"
|
|
70
|
+
]
|
|
71
|
+
}
|
|
72
|
+
]
|
|
73
|
+
}
|
|
74
|
+
},
|
|
5
75
|
{
|
|
6
76
|
"version": "0.2.0",
|
|
7
77
|
"date": "2026-11-20",
|
package/src/store/store.ts
CHANGED
|
@@ -5,6 +5,7 @@ import {
|
|
|
5
5
|
type AppSettings,
|
|
6
6
|
type ProviderModelOption,
|
|
7
7
|
type VoiceProvider,
|
|
8
|
+
type ImageProvider,
|
|
8
9
|
enabledModelIds,
|
|
9
10
|
modelAliases,
|
|
10
11
|
ChatMessage,
|
|
@@ -47,7 +48,7 @@ import {
|
|
|
47
48
|
PERFORMANCE_GUIDANCE_TOOL,
|
|
48
49
|
PERFORMANCE_GUIDANCE_TOOL_NAME,
|
|
49
50
|
} from '../core/toolDefinitions';
|
|
50
|
-
import { getEnabledToolsForSession, executeToolCall, parseDisplayRef, applySessionWorkspace } from '../core/tools/toolExecutor';
|
|
51
|
+
import { getEnabledToolsForSession, executeToolCall, parseDisplayRef, parseImageResult, applySessionWorkspace } from '../core/tools/toolExecutor';
|
|
51
52
|
import { CHARACTER_BOOK_TOOL, hasUsableCharacterBook, injectCharacterBookToolContext, mergeCharacterBooks } from '../core/characterBook';
|
|
52
53
|
import { createSessionWorkspaceDir, ensureSessionWorkspaceDir, deleteSessionWorkspace, isCurrentInstanceWorkspaceDir } from '../core/tools/generatedSkillExecutor';
|
|
53
54
|
import { applyTheme as applyThemeManual, cacheTheme, watchSystemTheme } from '../theme/theme';
|
|
@@ -91,7 +92,7 @@ export interface AchievementState {
|
|
|
91
92
|
/** 展示类工具(file_display)当前打开的弹窗载荷 */
|
|
92
93
|
export interface ActiveDisplay {
|
|
93
94
|
path: string;
|
|
94
|
-
kind: 'text' | 'html' | 'unsupported';
|
|
95
|
+
kind: 'text' | 'html' | 'image' | 'unsupported';
|
|
95
96
|
title?: string;
|
|
96
97
|
/** 产生该展示的会话 id(读取文件时按其专属工作目录解析,null = 共享工作区) */
|
|
97
98
|
sessionId: number | null;
|
|
@@ -111,6 +112,7 @@ interface AppState {
|
|
|
111
112
|
settings: AppSettings | null;
|
|
112
113
|
providers: ApiProvider[];
|
|
113
114
|
voiceProviders: VoiceProvider[];
|
|
115
|
+
imageProviders: ImageProvider[];
|
|
114
116
|
npcs: NpcCharacter[];
|
|
115
117
|
sessions: ChatSession[];
|
|
116
118
|
worldBooks: WorldBook[];
|
|
@@ -191,6 +193,7 @@ interface AppState {
|
|
|
191
193
|
refreshTools: () => Promise<void>;
|
|
192
194
|
refreshProviders: () => Promise<void>;
|
|
193
195
|
refreshVoiceProviders: () => Promise<void>;
|
|
196
|
+
refreshImageProviders: () => Promise<void>;
|
|
194
197
|
speakMessage: (text: string) => Promise<void>;
|
|
195
198
|
refreshAchievements: () => Promise<void>;
|
|
196
199
|
loadMessages: (sessionId: number) => Promise<void>;
|
|
@@ -318,6 +321,7 @@ export const useStore = create<AppState>((set, get) => ({
|
|
|
318
321
|
settings: null,
|
|
319
322
|
providers: [],
|
|
320
323
|
voiceProviders: [],
|
|
324
|
+
imageProviders: [],
|
|
321
325
|
npcs: [],
|
|
322
326
|
sessions: [],
|
|
323
327
|
worldBooks: [],
|
|
@@ -362,6 +366,7 @@ export const useStore = create<AppState>((set, get) => ({
|
|
|
362
366
|
setLanguage(settings.language);
|
|
363
367
|
const providers = snapshot.collections.providers.map((record) => record.value);
|
|
364
368
|
const voiceProviders = (snapshot.collections.voiceProviders ?? []).map((record) => record.value);
|
|
369
|
+
const imageProviders = (snapshot.collections.imageProviders ?? []).map((record) => record.value);
|
|
365
370
|
const npcs = sortNpcs(snapshot.collections.npcs.map((record) => record.value));
|
|
366
371
|
const sessions = sortSessionsPinnedFirst(snapshot.collections.sessions.map((record) => record.value));
|
|
367
372
|
const worldBooks = sortWorldBooks(snapshot.collections.worldBooks.map((record) => record.value));
|
|
@@ -379,6 +384,7 @@ export const useStore = create<AppState>((set, get) => ({
|
|
|
379
384
|
settings,
|
|
380
385
|
providers,
|
|
381
386
|
voiceProviders,
|
|
387
|
+
imageProviders,
|
|
382
388
|
modelsList: aggregateEnabledProviderModels(providers),
|
|
383
389
|
npcs,
|
|
384
390
|
sessions,
|
|
@@ -553,6 +559,10 @@ export const useStore = create<AppState>((set, get) => ({
|
|
|
553
559
|
set({ voiceProviders: await db.voiceProviders.toArray() });
|
|
554
560
|
},
|
|
555
561
|
|
|
562
|
+
refreshImageProviders: async () => {
|
|
563
|
+
set({ imageProviders: await db.imageProviders.toArray() });
|
|
564
|
+
},
|
|
565
|
+
|
|
556
566
|
speakMessage: async (text) => {
|
|
557
567
|
const state = get();
|
|
558
568
|
const settings = state.settings;
|
|
@@ -2435,12 +2445,14 @@ async function performAssistantTurn(
|
|
|
2435
2445
|
await useStore.getState().refreshNpcs();
|
|
2436
2446
|
}
|
|
2437
2447
|
}
|
|
2448
|
+
const imageResult = parseImageResult(result);
|
|
2449
|
+
const storedResult = imageResult ? result.replace(/^IMAGE_RESULT: [^\n]*\n?/, '') : result;
|
|
2438
2450
|
await db.messages.add({
|
|
2439
2451
|
sessionId,
|
|
2440
2452
|
role: 'tool',
|
|
2441
2453
|
speakerParticipantId: null,
|
|
2442
2454
|
speakerName: null,
|
|
2443
|
-
content:
|
|
2455
|
+
content: storedResult,
|
|
2444
2456
|
toolCallsJson: '[]',
|
|
2445
2457
|
toolCallId: tc.id,
|
|
2446
2458
|
thinkingContent: null,
|
|
@@ -2454,13 +2466,15 @@ async function performAssistantTurn(
|
|
|
2454
2466
|
modelUsed: null,
|
|
2455
2467
|
attachments: [],
|
|
2456
2468
|
attachmentInfos: [],
|
|
2457
|
-
displayRef: displayRefForResult(result, sessionId),
|
|
2469
|
+
displayRef: imageResult ? JSON.stringify({ path: imageResult.path, kind: 'image', title: imageResult.name, sessionId }) : displayRefForResult(result, sessionId),
|
|
2458
2470
|
rawRequestBody: null,
|
|
2459
2471
|
rawResponseBody: null,
|
|
2460
2472
|
});
|
|
2461
2473
|
|
|
2462
2474
|
// 展示工具与 JavaScript 的 $display:执行成功后自动打开展示弹窗
|
|
2463
|
-
const displayPayload =
|
|
2475
|
+
const displayPayload = imageResult
|
|
2476
|
+
? { path: imageResult.path, kind: 'image' as const, title: imageResult.name }
|
|
2477
|
+
: parseDisplayRef(result);
|
|
2464
2478
|
if (displayPayload) {
|
|
2465
2479
|
useStore.getState().setActiveDisplay({
|
|
2466
2480
|
path: displayPayload.path,
|
package/src/theme/chat.css
CHANGED
|
@@ -216,6 +216,49 @@
|
|
|
216
216
|
text-overflow: ellipsis;
|
|
217
217
|
font-weight: var(--font-weight-semibold);
|
|
218
218
|
}
|
|
219
|
+
.attach-card-image {
|
|
220
|
+
flex-direction: column;
|
|
221
|
+
align-items: stretch;
|
|
222
|
+
max-width: 180px;
|
|
223
|
+
padding: 6px;
|
|
224
|
+
}
|
|
225
|
+
.attach-thumb-button {
|
|
226
|
+
display: block;
|
|
227
|
+
padding: 0;
|
|
228
|
+
border: 0;
|
|
229
|
+
border-radius: 8px;
|
|
230
|
+
overflow: hidden;
|
|
231
|
+
background: transparent;
|
|
232
|
+
cursor: zoom-in;
|
|
233
|
+
}
|
|
234
|
+
.attach-thumb {
|
|
235
|
+
display: block;
|
|
236
|
+
width: 166px;
|
|
237
|
+
height: 124px;
|
|
238
|
+
object-fit: cover;
|
|
239
|
+
}
|
|
240
|
+
.attach-card-image .attach-card-name {
|
|
241
|
+
padding: 0 3px 2px;
|
|
242
|
+
}
|
|
243
|
+
.image-preview-modal {
|
|
244
|
+
max-width: min(92vw, 1100px);
|
|
245
|
+
}
|
|
246
|
+
.image-preview-body {
|
|
247
|
+
display: grid;
|
|
248
|
+
place-items: center;
|
|
249
|
+
min-height: 240px;
|
|
250
|
+
max-height: 78vh;
|
|
251
|
+
padding: 16px;
|
|
252
|
+
overflow: auto;
|
|
253
|
+
background: var(--surface-2);
|
|
254
|
+
cursor: zoom-out;
|
|
255
|
+
}
|
|
256
|
+
.image-preview-body img {
|
|
257
|
+
display: block;
|
|
258
|
+
max-width: 100%;
|
|
259
|
+
max-height: 72vh;
|
|
260
|
+
object-fit: contain;
|
|
261
|
+
}
|
|
219
262
|
|
|
220
263
|
/* ---------- 工具调用卡片 ---------- */
|
|
221
264
|
.tool-calls {
|
|
@@ -307,7 +350,7 @@
|
|
|
307
350
|
/* 未展开时展示的工具调用结果摘要行 */
|
|
308
351
|
.tool-card-result-line {
|
|
309
352
|
display: flex;
|
|
310
|
-
align-items:
|
|
353
|
+
align-items: center;
|
|
311
354
|
gap: 6px;
|
|
312
355
|
padding: 6px 12px 7px;
|
|
313
356
|
border-top: none;
|
|
@@ -464,7 +507,7 @@
|
|
|
464
507
|
bottom: 12px;
|
|
465
508
|
left: 12px;
|
|
466
509
|
z-index: 5;
|
|
467
|
-
padding:
|
|
510
|
+
padding: 10px 10px 8px;
|
|
468
511
|
border: 1px solid color-mix(in srgb, var(--border) 58%, transparent);
|
|
469
512
|
border-radius: var(--radius);
|
|
470
513
|
background: color-mix(in srgb, var(--surface) 38%, transparent);
|
|
@@ -1303,7 +1346,7 @@
|
|
|
1303
1346
|
right: 8px;
|
|
1304
1347
|
bottom: max(8px, env(safe-area-inset-bottom));
|
|
1305
1348
|
left: 8px;
|
|
1306
|
-
padding:
|
|
1349
|
+
padding: 6px;
|
|
1307
1350
|
}
|
|
1308
1351
|
|
|
1309
1352
|
.composer-group {
|
package/src/theme/views.css
CHANGED
|
@@ -1702,6 +1702,7 @@
|
|
|
1702
1702
|
flex: 1;
|
|
1703
1703
|
display: flex;
|
|
1704
1704
|
flex-direction: column;
|
|
1705
|
+
background: var(--surface);
|
|
1705
1706
|
}
|
|
1706
1707
|
.display-pip .display-modal-head {
|
|
1707
1708
|
padding: 9px 10px;
|
|
@@ -1833,22 +1834,29 @@
|
|
|
1833
1834
|
}
|
|
1834
1835
|
|
|
1835
1836
|
/* 图片 */
|
|
1837
|
+
.display-image-wrap {
|
|
1838
|
+
flex: 1;
|
|
1839
|
+
min-height: 0;
|
|
1840
|
+
display: flex;
|
|
1841
|
+
flex-direction: column;
|
|
1842
|
+
}
|
|
1836
1843
|
.display-image-viewport {
|
|
1837
1844
|
flex: 1;
|
|
1838
1845
|
min-height: 0;
|
|
1839
1846
|
overflow: hidden;
|
|
1847
|
+
background: var(--surface);
|
|
1848
|
+
user-select: none;
|
|
1849
|
+
}
|
|
1850
|
+
.display-image-scroll-area {
|
|
1851
|
+
min-width: 100%;
|
|
1852
|
+
min-height: 100%;
|
|
1840
1853
|
display: grid;
|
|
1841
1854
|
place-items: center;
|
|
1842
|
-
background: var(--surface-2);
|
|
1843
|
-
user-select: none;
|
|
1844
|
-
touch-action: none;
|
|
1845
1855
|
}
|
|
1846
1856
|
.display-image {
|
|
1847
|
-
|
|
1848
|
-
max-height: none;
|
|
1857
|
+
display: block;
|
|
1849
1858
|
object-fit: contain;
|
|
1850
|
-
|
|
1851
|
-
will-change: transform;
|
|
1859
|
+
cursor: default;
|
|
1852
1860
|
}
|
|
1853
1861
|
|
|
1854
1862
|
/* HTML 沙箱 */
|
|
@@ -1974,15 +1982,24 @@
|
|
|
1974
1982
|
align-items: center;
|
|
1975
1983
|
gap: 5px;
|
|
1976
1984
|
}
|
|
1985
|
+
.tool-card-result-line .display-view-btn,
|
|
1986
|
+
.tool-card-body .tool-result .display-view-btn {
|
|
1987
|
+
min-height: 22px;
|
|
1988
|
+
height: 22px;
|
|
1989
|
+
padding: 0 7px;
|
|
1990
|
+
gap: 3px;
|
|
1991
|
+
border-radius: 6px;
|
|
1992
|
+
font-size: var(--font-size-caption);
|
|
1993
|
+
line-height: 1;
|
|
1994
|
+
flex-shrink: 0;
|
|
1995
|
+
}
|
|
1977
1996
|
.tool-card-result-line .display-view-btn {
|
|
1978
|
-
margin
|
|
1979
|
-
margin-left: 8px;
|
|
1997
|
+
margin: 0 0 0 6px;
|
|
1980
1998
|
}
|
|
1981
1999
|
/* 展开态工具结果:查看按钮固定在结果行右侧、垂直居中 */
|
|
1982
2000
|
.tool-card-body .tool-result .display-view-btn {
|
|
1983
2001
|
margin-top: 0;
|
|
1984
2002
|
margin-left: auto;
|
|
1985
|
-
flex-shrink: 0;
|
|
1986
2003
|
}
|
|
1987
2004
|
|
|
1988
2005
|
/* ---------- 会话工作区文件管理器(只读) ---------- */
|
package/src/types/models.ts
CHANGED
|
@@ -21,7 +21,7 @@ export interface DisplayFileRef {
|
|
|
21
21
|
/** 工作区相对路径(与 file_read / file_write 同一沙箱工作区) */
|
|
22
22
|
path: string;
|
|
23
23
|
/** 展示方式:text(按扩展名智能渲染)/ html / unsupported */
|
|
24
|
-
kind: 'text' | 'html' | 'unsupported';
|
|
24
|
+
kind: 'text' | 'html' | 'image' | 'unsupported';
|
|
25
25
|
/** 展示标题(默认取文件名) */
|
|
26
26
|
title?: string;
|
|
27
27
|
/** 产生该展示的会话 id(回看时按其专属工作目录解析;null = 共享工作区) */
|
|
@@ -67,11 +67,24 @@ export interface AppSettings {
|
|
|
67
67
|
activeVoiceProviderId: number | null;
|
|
68
68
|
/** 当前旁白音色。 */
|
|
69
69
|
activeVoiceId: VoiceId | null;
|
|
70
|
+
/** 当前启用的生图 Provider。 */
|
|
71
|
+
activeImageProviderId: number | null;
|
|
72
|
+
/** 默认生图模型。 */
|
|
73
|
+
defaultImageModel: string;
|
|
70
74
|
statsResetTime: number | null;
|
|
71
75
|
}
|
|
72
76
|
|
|
73
77
|
export type VoiceProviderKind = 'deepseek' | 'bailian';
|
|
74
78
|
export type VoiceId = 'stella' | 'tide' | 'longanlingxin' | 'longanlufeng';
|
|
79
|
+
export type ImageProviderKind = 'bailian-token-plan';
|
|
80
|
+
|
|
81
|
+
export interface ImageProvider {
|
|
82
|
+
id?: number;
|
|
83
|
+
kind: ImageProviderKind;
|
|
84
|
+
apiKey: string;
|
|
85
|
+
isEnabled: boolean;
|
|
86
|
+
createdAt: number;
|
|
87
|
+
}
|
|
75
88
|
|
|
76
89
|
export interface VoiceProvider {
|
|
77
90
|
id?: number;
|
package/vite.config.ts
CHANGED
|
@@ -557,7 +557,7 @@ function sandboxProxyPlugin(): Plugin {
|
|
|
557
557
|
});
|
|
558
558
|
server.middlewares.use((req: IncomingMessage, res: ServerResponse, next) => {
|
|
559
559
|
// 转发与沙箱服务相关的端点:/exec 及真实工作区文件端点
|
|
560
|
-
const m = /^\/api-v2\/(exec|approve|file_read|file_write|file_delete|file_list|workspace_open|session_create|session_delete)$/.exec(req.url || '');
|
|
560
|
+
const m = /^\/api-v2\/(exec|approve|file_read|file_write|file_write_base64|file_delete|file_list|preview_read|workspace_open|session_create|session_delete)$/.exec(req.url || '');
|
|
561
561
|
if (!m || req.method !== 'POST') return next();
|
|
562
562
|
if (!isSameOriginRequest(req)) {
|
|
563
563
|
res.writeHead(403, { 'Content-Type': 'application/json' });
|