dsh-lifecard 0.1.2 → 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/README.md +62 -1
- package/cordis.patch.yml +163 -2
- package/lib/career.js +488 -0
- package/lib/client.js +797 -46
- package/lib/game.js +373 -0
- package/lib/index.js +690 -49
- package/lib/novel.js +109 -10
- package/lib/presets.js +459 -0
- package/lib/store.js +89 -15
- package/lib/tavern.js +56 -1
- package/lifecard-tools.js +549 -0
- package/package.json +11 -3
- package/skills/blind-review-loop/SKILL.md +205 -0
- package/skills/human-writing/LICENSE +21 -0
- package/skills/human-writing/SKILL.md +170 -0
- package/skills/human-writing/VERSION +1 -0
- package/skills/human-writing/agents/openai.yaml +4 -0
- package/skills/human-writing/dist/human-writing-lite.md +29 -0
- package/skills/human-writing/references/essay-or-fiction.md +79 -0
- package/skills/human-writing/references/fiction.md +115 -0
- package/skills/human-writing/references/formats.md +99 -0
- package/skills/human-writing/references/forum-prose.md +349 -0
- package/skills/human-writing/references/reality.md +119 -0
- package/skills/human-writing/references/revision.md +204 -0
- package/skills/human-writing/references/story-diagnosis.md +131 -0
- package/skills/human-writing/references/writing-ceiling.md +151 -0
- package/skills/human-writing/scripts/check_prose.py +781 -0
- package/skills/lifecard-novel-writing/SKILL.md +88 -0
- package/skills/visual-novel/SKILL.md +139 -0
- package/skills/visual-novel/references/script-and-flow.md +89 -0
package/lib/client.js
CHANGED
|
@@ -727,7 +727,7 @@ const SECTIONS_REL = [
|
|
|
727
727
|
|
|
728
728
|
// ── 主界面 ────────────────────────────────────────────────────────
|
|
729
729
|
|
|
730
|
-
const VIEWS = { doors: 'doors', novel: 'novel', book: 'book', tavern: 'tavern', tavernChat: 'tavernChat', home: 'home', card: 'card', interview: 'interview', import: 'import', analyze: 'analyze', doctor: 'doctor', setup: 'setup', newCard: 'newCard', world: 'world', memory: 'memory', jobs: 'jobs' }
|
|
730
|
+
const VIEWS = { doors: 'doors', novel: 'novel', book: 'book', game: 'game', career: 'career', tavern: 'tavern', tavernChat: 'tavernChat', home: 'home', card: 'card', interview: 'interview', import: 'import', analyze: 'analyze', doctor: 'doctor', setup: 'setup', newCard: 'newCard', world: 'world', memory: 'memory', jobs: 'jobs' }
|
|
731
731
|
|
|
732
732
|
/**
|
|
733
733
|
* tab 组件。接收宿主给的 props(ctx / store / scope / tab / visible)。
|
|
@@ -923,12 +923,15 @@ function LifeCardTab(props) {
|
|
|
923
923
|
setView(next)
|
|
924
924
|
}, [])
|
|
925
925
|
|
|
926
|
-
const openCard = useCallback(async (card) => {
|
|
926
|
+
const openCard = useCallback(async (card, edit) => {
|
|
927
927
|
setBusy('card')
|
|
928
928
|
try {
|
|
929
929
|
const detail = await call('card.get', { path: card.path })
|
|
930
930
|
if (detail?.ok !== true) throw new Error(detail?.error ?? '这张卡读不出来')
|
|
931
931
|
setActiveCard(detail)
|
|
932
|
+
// 先摆好「打开就进修改」,再切屏——反过来的话 CardView 会先以
|
|
933
|
+
// editing=false 挂载一次,之后再传初始值也不生效了。
|
|
934
|
+
setCardEdit(edit === true)
|
|
932
935
|
setView(VIEWS.card)
|
|
933
936
|
} catch (e) {
|
|
934
937
|
setActiveCard(null)
|
|
@@ -970,8 +973,54 @@ function LifeCardTab(props) {
|
|
|
970
973
|
const [activeBook, setActiveBook] = useState(null)
|
|
971
974
|
// 书架上的书(写小说那扇门要列出来)
|
|
972
975
|
const [books, setBooks] = useState([])
|
|
976
|
+
// 哪些功能装了。null = 还没问到(先都按「装了」显示,别闪一下少一扇门)。
|
|
977
|
+
//
|
|
978
|
+
// 这个插件的每一块都能整个删掉:删了酒馆的文件,酒馆就没了,别的照常。
|
|
979
|
+
// 所以界面不能写死「一定有三扇门」,得先问一句「现在有哪些」。
|
|
980
|
+
const [features, setFeatures] = useState(null)
|
|
981
|
+
// 从列表点铅笔进来的:卡页一打开就是修改状态。放在最后一个 hook,
|
|
982
|
+
// 免得把前面那些按槽位摆状态的测试全挤错位。
|
|
983
|
+
const [cardEdit, setCardEdit] = useState(false)
|
|
984
|
+
// 三扇门各自「现在用哪张卡」:写进这个文件夹的 config.json,重启还在。
|
|
985
|
+
const [pins, setPins] = useState({ real: '', tavern: '', novel: '' })
|
|
986
|
+
const loadPins = useCallback(async () => {
|
|
987
|
+
try {
|
|
988
|
+
const r = await call('card.defaults.get', {})
|
|
989
|
+
if (r?.ok === true && r.cards !== undefined) setPins(r.cards)
|
|
990
|
+
} catch { /* 读不到就按「还没选」显示,不挡人用 */ }
|
|
991
|
+
}, [])
|
|
992
|
+
|
|
993
|
+
const pinCard = useCallback(async (mode, id) => {
|
|
994
|
+
const before = pins
|
|
995
|
+
setPins({ ...pins, [mode]: id })
|
|
996
|
+
try {
|
|
997
|
+
const r = await call('card.defaults.set', { mode, id })
|
|
998
|
+
if (r?.ok !== true) {
|
|
999
|
+
setPins(before)
|
|
1000
|
+
setError(r?.error ?? '这个没存上,再点一次。')
|
|
1001
|
+
}
|
|
1002
|
+
} catch (e) {
|
|
1003
|
+
setPins(before)
|
|
1004
|
+
setError(humanizeError(e))
|
|
1005
|
+
}
|
|
1006
|
+
}, [pins])
|
|
1007
|
+
|
|
1008
|
+
|
|
1009
|
+
useEffect(() => {
|
|
1010
|
+
let gone = false
|
|
1011
|
+
call('features.list', {})
|
|
1012
|
+
.then((r) => { if (!gone && r?.ok === true && r.features !== undefined) setFeatures(r.features) })
|
|
1013
|
+
.catch(() => { /* 问不到就按「都装了」显示,不影响用 */ })
|
|
1014
|
+
return () => { gone = true }
|
|
1015
|
+
}, [])
|
|
1016
|
+
// 三扇门各自「现在用哪张卡」:进哪扇门就读一次,免得改完别处又盖回去。
|
|
1017
|
+
useEffect(() => {
|
|
1018
|
+
if (view !== VIEWS.doors && view !== VIEWS.home && view !== VIEWS.tavern && view !== VIEWS.novel) return
|
|
1019
|
+
loadPins()
|
|
1020
|
+
}, [view, loadPins])
|
|
1021
|
+
|
|
973
1022
|
// 门自己的那两屏直接说了算;其余屏(聊着建、卡片、分析…)沿用上次选的门。
|
|
974
|
-
const mode = (view === VIEWS.novel || view === VIEWS.book) ? 'novel' : (view === VIEWS.tavern || view === VIEWS.tavernChat) ? 'tavern' : door
|
|
1023
|
+
const mode = (view === VIEWS.novel || view === VIEWS.book || view === VIEWS.game) ? 'novel' : (view === VIEWS.tavern || view === VIEWS.tavernChat) ? 'tavern' : door
|
|
975
1024
|
// 回到酒馆那两屏就重新拿一遍说过的场次:刚说完、刚删完再回来,
|
|
976
1025
|
// 还挂着进这一屏之前的旧列表,用户会以为刚才那一步没生效。
|
|
977
1026
|
useEffect(() => {
|
|
@@ -1070,7 +1119,7 @@ function LifeCardTab(props) {
|
|
|
1070
1119
|
try {
|
|
1071
1120
|
const r = await call('tavern.get', { id: row?.id })
|
|
1072
1121
|
if (r?.ok !== true) throw new Error(r?.error ?? '这一场打不开')
|
|
1073
|
-
setChat({ id: r.id, card_name: r.card_name, world_name: r.world_name, turns: r.turns ?? [], err: null, busy: false })
|
|
1122
|
+
setChat({ id: r.id, card_name: r.card_name, world_name: r.world_name, turns: r.turns ?? [], notes: r.notes ?? [], err: null, busy: false })
|
|
1074
1123
|
setView(VIEWS.tavernChat)
|
|
1075
1124
|
} catch (e) {
|
|
1076
1125
|
setError(humanizeError(e))
|
|
@@ -1085,7 +1134,7 @@ function LifeCardTab(props) {
|
|
|
1085
1134
|
try {
|
|
1086
1135
|
const r = await call('tavern.start', { card: card?.path ?? String(card?.id ?? '') })
|
|
1087
1136
|
if (r?.ok !== true) throw new Error(r?.error ?? '这一场没开起来')
|
|
1088
|
-
setChat({ id: r.id, card_name: r.card_name, world_name: r.world_name, turns: r.turns ?? [], err: null, busy: false })
|
|
1137
|
+
setChat({ id: r.id, card_name: r.card_name, world_name: r.world_name, turns: r.turns ?? [], notes: r.notes ?? [], err: null, busy: false })
|
|
1089
1138
|
setView(VIEWS.tavernChat)
|
|
1090
1139
|
} catch (e) {
|
|
1091
1140
|
setError(humanizeError(e))
|
|
@@ -1096,7 +1145,9 @@ function LifeCardTab(props) {
|
|
|
1096
1145
|
|
|
1097
1146
|
// 首页那张卡片点下去之后去哪儿,由门决定:酒馆里是「聊一场」,
|
|
1098
1147
|
// 别的两扇门里还是「打开这张卡」。
|
|
1099
|
-
|
|
1148
|
+
// 以前在酒馆门里点一张卡就直接开演了,想先看看卡上写了什么都做不到。
|
|
1149
|
+
// 现在点卡统一是「打开这张卡」,要不要演由卡页上的「和 TA 演一段」决定。
|
|
1150
|
+
const openFromList = (card) => openCard(card)
|
|
1100
1151
|
// 现实里的卡拿去演:先复制成一份独立的角色卡,再开聊。
|
|
1101
1152
|
// 不复制直接用原来那张的话,演上十分钟,现实记录里的性格就被改写了。
|
|
1102
1153
|
const forkForTavern = async (card) => {
|
|
@@ -1114,6 +1165,8 @@ function LifeCardTab(props) {
|
|
|
1114
1165
|
[VIEWS.doors]: '你要用哪个?',
|
|
1115
1166
|
[VIEWS.home]: '真实人物记录',
|
|
1116
1167
|
[VIEWS.novel]: '写小说',
|
|
1168
|
+
[VIEWS.game]: '玩一段',
|
|
1169
|
+
[VIEWS.career]: '简历与规划',
|
|
1117
1170
|
[VIEWS.book]: activeBook?.title === undefined || String(activeBook.title).trim() === '' ? '这本书' : String(activeBook.title),
|
|
1118
1171
|
[VIEWS.tavern]: '酒馆',
|
|
1119
1172
|
[VIEWS.tavernChat]: chat === null ? '聊一场' : (String(chat.card_name ?? '').trim() === '' ? '聊一场' : String(chat.card_name)),
|
|
@@ -1186,7 +1239,7 @@ function LifeCardTab(props) {
|
|
|
1186
1239
|
})
|
|
1187
1240
|
}
|
|
1188
1241
|
// 门还没选:先问「你要用哪个」。选完才进首页,首页再按门决定露出什么。
|
|
1189
|
-
if (view === VIEWS.doors) return h(DoorsView, { state, onPick: pickDoor })
|
|
1242
|
+
if (view === VIEWS.doors) return h(DoorsView, { state, features, onPick: pickDoor })
|
|
1190
1243
|
if (view === VIEWS.tavernChat) {
|
|
1191
1244
|
return h(TavernView, {
|
|
1192
1245
|
chat,
|
|
@@ -1219,7 +1272,12 @@ function LifeCardTab(props) {
|
|
|
1219
1272
|
return h(InterviewView, {
|
|
1220
1273
|
state, listing, preset: interviewFor, onRecorded: refresh, flash, mode,
|
|
1221
1274
|
onDone: () => { setInterviewFor(null); setMaterialFor(null); setView(VIEWS.home); refresh() },
|
|
1222
|
-
onAnalyze: (about) => {
|
|
1275
|
+
onAnalyze: (about) => {
|
|
1276
|
+
const list = Array.isArray(about?.materials) ? about.materials.filter((x) => typeof x === 'string' && x !== '') : []
|
|
1277
|
+
setMaterialFor(list.length > 0 ? list : null)
|
|
1278
|
+
setInterviewFor(about ?? null)
|
|
1279
|
+
setView(VIEWS.analyze)
|
|
1280
|
+
},
|
|
1223
1281
|
})
|
|
1224
1282
|
case VIEWS.memory:
|
|
1225
1283
|
// 提取完直接跳到「让 AI 读」,省掉用户自己再想「我刚存的材料去哪了」。
|
|
@@ -1241,6 +1299,14 @@ function LifeCardTab(props) {
|
|
|
1241
1299
|
onProposal: showProposal,
|
|
1242
1300
|
onBack: () => { setInterviewFor(null); setMaterialFor(null); setView(VIEWS.home) },
|
|
1243
1301
|
onNeedMaterial: () => setView(VIEWS.import),
|
|
1302
|
+
// 一键建成卡之后直接把人带到那张卡上:建完就站在门口看着,
|
|
1303
|
+
// 不知道它在哪儿、还得自己回列表找,等于没建。
|
|
1304
|
+
onAppliedCard: async (path) => {
|
|
1305
|
+
const hit = (listing?.cards ?? []).find((c) => c.path === path)
|
|
1306
|
+
await refresh(state?.workspace)
|
|
1307
|
+
if (hit !== undefined) await openCard(hit)
|
|
1308
|
+
else setView(VIEWS.home)
|
|
1309
|
+
},
|
|
1244
1310
|
})
|
|
1245
1311
|
case VIEWS.card:
|
|
1246
1312
|
// 首页那条「还等着你看的建议」点进来时,如果这个人还没有卡(很正常:
|
|
@@ -1248,7 +1314,7 @@ function LifeCardTab(props) {
|
|
|
1248
1314
|
// 直接退回首页,用户点了没反应,还以为坏了。现在把清单单独摊开。
|
|
1249
1315
|
return activeCard === null
|
|
1250
1316
|
? proposal === null
|
|
1251
|
-
? h(HomeView, { state, listing, mode, onOpen: openFromList, chats, onOpenChat: openChat, onOpenWorld: openWorld, onNavigate: go, onMore: () => setShowMore(!showMore), showMore, onProposal: openProposal, busy, intro: introSeen === false, onIntroDone: dismissIntro, onMaterial: (m) => { setMaterialFor(m.path); setView(VIEWS.analyze) }, onDeleteMaterial: deleteMaterial, onDoDoctor: () => runDoctor(), onForkCard: forkForTavern, onDeleteCard: deleteCard, books, onOpenBook: openBook, onCreateBook: createBook })
|
|
1317
|
+
? h(HomeView, { state, listing, mode, onOpen: openFromList, chats, onOpenChat: openChat, onOpenWorld: openWorld, onNavigate: go, onMore: () => setShowMore(!showMore), showMore, onProposal: openProposal, busy, intro: introSeen === false, onIntroDone: dismissIntro, onMaterial: (m) => { setMaterialFor(m.path); setView(VIEWS.analyze) }, onDeleteMaterial: deleteMaterial, onDoDoctor: () => runDoctor(), onForkCard: forkForTavern, onDeleteCard: deleteCard, onEditCard: (c) => openCard(c, true), pinId: (mode === 'real' ? pins.real : mode === 'tavern' ? pins.tavern : pins.novel), onPickPin: (id) => pinCard(mode, id), books, onOpenBook: openBook, onCreateBook: createBook })
|
|
1252
1318
|
: h('div', { className: 'lc-pad lc-stack' },
|
|
1253
1319
|
proposal.about === undefined || String(proposal.about).trim() === ''
|
|
1254
1320
|
? null
|
|
@@ -1273,6 +1339,7 @@ function LifeCardTab(props) {
|
|
|
1273
1339
|
)
|
|
1274
1340
|
: h(CardView, {
|
|
1275
1341
|
card: activeCard,
|
|
1342
|
+
initialEditing: cardEdit,
|
|
1276
1343
|
worlds: listing?.worlds ?? [],
|
|
1277
1344
|
onOpenWorld: openWorld,
|
|
1278
1345
|
proposal,
|
|
@@ -1290,6 +1357,7 @@ function LifeCardTab(props) {
|
|
|
1290
1357
|
onDeleted: async () => { setActiveCard(null); setView(VIEWS.home); await refresh() },
|
|
1291
1358
|
onInterview: (preset) => { setInterviewFor(preset); setView(VIEWS.interview) },
|
|
1292
1359
|
onAnalyze: () => { setInterviewFor({ id: activeCard.data?.id, name: activeCard.data?.name }); setView(VIEWS.analyze) },
|
|
1360
|
+
onTavern: mode === 'tavern' ? (preset) => startTavern(preset) : undefined,
|
|
1293
1361
|
})
|
|
1294
1362
|
case VIEWS.newCard:
|
|
1295
1363
|
return h(NewCardView, {
|
|
@@ -1307,12 +1375,18 @@ function LifeCardTab(props) {
|
|
|
1307
1375
|
})
|
|
1308
1376
|
case VIEWS.world:
|
|
1309
1377
|
return activeWorld === null
|
|
1310
|
-
? h(HomeView, { state, listing, mode, onOpen: openFromList, chats, onOpenChat: openChat, onOpenWorld: openWorld, onNavigate: go, onMore: () => setShowMore(!showMore), showMore, onProposal: openProposal, busy, intro: introSeen === false, onIntroDone: dismissIntro, onMaterial: (m) => { setMaterialFor(m.path); setView(VIEWS.analyze) }, onDeleteMaterial: deleteMaterial, onDoDoctor: () => runDoctor(), onForkCard: forkForTavern, onDeleteCard: deleteCard, books, onOpenBook: openBook, onCreateBook: createBook })
|
|
1378
|
+
? h(HomeView, { state, listing, mode, onOpen: openFromList, chats, onOpenChat: openChat, onOpenWorld: openWorld, onNavigate: go, onMore: () => setShowMore(!showMore), showMore, onProposal: openProposal, busy, intro: introSeen === false, onIntroDone: dismissIntro, onMaterial: (m) => { setMaterialFor(m.path); setView(VIEWS.analyze) }, onDeleteMaterial: deleteMaterial, onDoDoctor: () => runDoctor(), onForkCard: forkForTavern, onDeleteCard: deleteCard, onEditCard: (c) => openCard(c, true), pinId: (mode === 'real' ? pins.real : mode === 'tavern' ? pins.tavern : pins.novel), onPickPin: (id) => pinCard(mode, id), books, onOpenBook: openBook, onCreateBook: createBook })
|
|
1311
1379
|
: h(WorldView, {
|
|
1312
1380
|
world: activeWorld,
|
|
1313
1381
|
listing,
|
|
1314
1382
|
onOpenCard: openCard,
|
|
1315
1383
|
})
|
|
1384
|
+
case VIEWS.game:
|
|
1385
|
+
return h(GameView, {
|
|
1386
|
+
bookId: String(activeBook?.id ?? ''),
|
|
1387
|
+
flash,
|
|
1388
|
+
onBack: () => { setActiveBook(null); setView(VIEWS.novel) },
|
|
1389
|
+
})
|
|
1316
1390
|
case VIEWS.book:
|
|
1317
1391
|
return h(BookView, {
|
|
1318
1392
|
bookId: String(activeBook?.id ?? ''),
|
|
@@ -1321,10 +1395,12 @@ function LifeCardTab(props) {
|
|
|
1321
1395
|
})
|
|
1322
1396
|
case VIEWS.doctor:
|
|
1323
1397
|
return h(DoctorView, { report: doctor, onOpenCard: openCard, onRun: () => runDoctor(true) })
|
|
1398
|
+
case VIEWS.career:
|
|
1399
|
+
return h(CareerView, { flash, onBack: () => setView(VIEWS.home) })
|
|
1324
1400
|
case VIEWS.jobs:
|
|
1325
1401
|
return h(JobsView, { onBack: () => setView(VIEWS.home), flash })
|
|
1326
1402
|
default:
|
|
1327
|
-
return h(HomeView, { state, listing, mode, onOpen: openFromList, chats, onOpenChat: openChat, onOpenWorld: openWorld, onNavigate: go, onMore: () => setShowMore(!showMore), showMore, onProposal: openProposal, busy, intro: introSeen === false, onIntroDone: dismissIntro, onMaterial: (m) => { setMaterialFor(m.path); setView(VIEWS.analyze) }, onDeleteMaterial: deleteMaterial, onDoDoctor: () => runDoctor(), onForkCard: forkForTavern, onDeleteCard: deleteCard, books, onOpenBook: openBook, onCreateBook: createBook })
|
|
1403
|
+
return h(HomeView, { state, listing, mode, onOpen: openFromList, chats, onOpenChat: openChat, onOpenWorld: openWorld, onNavigate: go, onMore: () => setShowMore(!showMore), showMore, onProposal: openProposal, busy, intro: introSeen === false, onIntroDone: dismissIntro, onMaterial: (m) => { setMaterialFor(m.path); setView(VIEWS.analyze) }, onDeleteMaterial: deleteMaterial, onDoDoctor: () => runDoctor(), onForkCard: forkForTavern, onDeleteCard: deleteCard, onEditCard: (c) => openCard(c, true), pinId: (mode === 'real' ? pins.real : mode === 'tavern' ? pins.tavern : pins.novel), onPickPin: (id) => pinCard(mode, id), books, onOpenBook: openBook, onCreateBook: createBook })
|
|
1328
1404
|
}
|
|
1329
1405
|
}
|
|
1330
1406
|
|
|
@@ -1448,8 +1524,12 @@ const DOORS = [
|
|
|
1448
1524
|
* 顶上一条门楣色块、中间竖着写门名、底部一道门槛写着「推门进去」。
|
|
1449
1525
|
* 三扇并排、各占三分之一宽、高度撑满;窄窗口自动换行。
|
|
1450
1526
|
*/
|
|
1451
|
-
function DoorsView({ onPick, state }) {
|
|
1527
|
+
function DoorsView({ onPick, state, features }) {
|
|
1452
1528
|
const workspace = String(state?.workspace ?? '')
|
|
1529
|
+
// 没装的门不摆出来。`features === null` 时全摆(还没问到,别闪一下少一扇)。
|
|
1530
|
+
const doors = (features === null || features === undefined)
|
|
1531
|
+
? DOORS
|
|
1532
|
+
: DOORS.filter((d) => (d.id === 'real' ? true : d.id === 'novel' ? features.novel !== false : features.tavern !== false))
|
|
1453
1533
|
const tint = {
|
|
1454
1534
|
real: {
|
|
1455
1535
|
fg: 'var(--lc-interview)', bg: 'var(--lc-interview-soft)', icon: 'people',
|
|
@@ -1482,7 +1562,7 @@ function DoorsView({ onPick, state }) {
|
|
|
1482
1562
|
alignItems: 'stretch', flexWrap: 'wrap', minHeight: 280,
|
|
1483
1563
|
},
|
|
1484
1564
|
},
|
|
1485
|
-
|
|
1565
|
+
doors.map((door) => {
|
|
1486
1566
|
const t = tint[door.id] ?? tint.real
|
|
1487
1567
|
return h('button', {
|
|
1488
1568
|
key: door.id,
|
|
@@ -1564,11 +1644,11 @@ function DoorsView({ onPick, state }) {
|
|
|
1564
1644
|
)
|
|
1565
1645
|
}),
|
|
1566
1646
|
),
|
|
1567
|
-
workspace === '' ? null : h('div', { className: 'lc-meta', style: { flex: '0 0 auto', paddingTop: 10 } },
|
|
1647
|
+
workspace === '' ? null : h('div', { className: 'lc-meta', style: { flex: '0 0 auto', paddingTop: 10 } }, '档案就在你选的那个文件夹里'),
|
|
1568
1648
|
)
|
|
1569
1649
|
}
|
|
1570
1650
|
|
|
1571
|
-
function HomeView({ state, listing, mode, onOpen, onOpenWorld, onNavigate, onProposal, busy, onDoDoctor, showMore, onMore, intro, onIntroDone, onMaterial, onDeleteMaterial, chats, onOpenChat, onForkCard, onDeleteCard, books, onOpenBook, onCreateBook }) {
|
|
1651
|
+
function HomeView({ state, listing, mode, onOpen, onOpenWorld, onNavigate, onProposal, busy, onDoDoctor, showMore, onMore, intro, onIntroDone, onMaterial, onDeleteMaterial, chats, onOpenChat, onForkCard, onDeleteCard, onEditCard, books, onOpenBook, onCreateBook, pinId, onPickPin }) {
|
|
1572
1652
|
// 这扇门是不是「真实人物记录」。写小说、酒馆那两扇门里不该出现
|
|
1573
1653
|
// 「贴一份招聘说明」「从记忆里认人」这类动作——那是记录真人才用得上的。
|
|
1574
1654
|
const isReal = mode !== 'novel' && mode !== 'tavern'
|
|
@@ -1716,6 +1796,9 @@ function HomeView({ state, listing, mode, onOpen, onOpenWorld, onNavigate, onPro
|
|
|
1716
1796
|
isReal
|
|
1717
1797
|
? h(Btn, { tone: 'primary', size: 'sm', icon: 'briefcase', onClick: () => onNavigate(VIEWS.jobs), title: '贴一份招聘说明,看看该不该投;或者练一轮面试' }, '下一步')
|
|
1718
1798
|
: null,
|
|
1799
|
+
isReal
|
|
1800
|
+
? h(Btn, { size: 'sm', icon: 'book', onClick: () => onNavigate(VIEWS.career), title: '把自己的情况写清楚,让 AI 帮你看简历、算差距、规划怎么走' }, '简历与规划')
|
|
1801
|
+
: null,
|
|
1719
1802
|
h('div', { className: 'lc-grow' }),
|
|
1720
1803
|
// 「贴一段文章让 AI 读」不是只有记录真人才用得上:写小说、酒馆里
|
|
1721
1804
|
// 手里有一段人物设定/小说片段,一样想让它读成人设。所以三扇门都给。
|
|
@@ -1724,6 +1807,37 @@ function HomeView({ state, listing, mode, onOpen, onOpenWorld, onNavigate, onPro
|
|
|
1724
1807
|
: null,
|
|
1725
1808
|
),
|
|
1726
1809
|
|
|
1810
|
+
// 一眼看到「这里有多少东西」:以前首页只有标题和一排按钮,一大片空。
|
|
1811
|
+
// 数字本身就是内容,也让人知道还有多少没用起来。
|
|
1812
|
+
h('div', { className: 'lc-sec', style: { paddingTop: 2 } },
|
|
1813
|
+
h('div', { className: 'lc-row', style: { flexWrap: 'wrap', gap: 14 } },
|
|
1814
|
+
h('div', { className: 'lc-stack', style: { gap: 1, minWidth: 62 } },
|
|
1815
|
+
h('div', { style: { fontSize: 22, fontWeight: 700, lineHeight: 1.2 } }, String(cards.length)),
|
|
1816
|
+
h('div', { className: 'lc-meta' }, isReal ? '认识的人' : '角色'),
|
|
1817
|
+
),
|
|
1818
|
+
h('div', { className: 'lc-stack', style: { gap: 1, minWidth: 62 } },
|
|
1819
|
+
h('div', { style: { fontSize: 22, fontWeight: 700, lineHeight: 1.2 } }, String(materials.length)),
|
|
1820
|
+
h('div', { className: 'lc-meta' }, '材料'),
|
|
1821
|
+
),
|
|
1822
|
+
h('div', { className: 'lc-stack', style: { gap: 1, minWidth: 62 } },
|
|
1823
|
+
h('div', { style: { fontSize: 22, fontWeight: 700, lineHeight: 1.2 } }, String(pendingProposals.length)),
|
|
1824
|
+
h('div', { className: 'lc-meta' }, '待你看'),
|
|
1825
|
+
),
|
|
1826
|
+
mode === 'novel'
|
|
1827
|
+
? h('div', { className: 'lc-stack', style: { gap: 1, minWidth: 62 } },
|
|
1828
|
+
h('div', { style: { fontSize: 22, fontWeight: 700, lineHeight: 1.2 } }, String((books ?? []).length)),
|
|
1829
|
+
h('div', { className: 'lc-meta' }, '书'),
|
|
1830
|
+
)
|
|
1831
|
+
: null,
|
|
1832
|
+
mode === 'tavern'
|
|
1833
|
+
? h('div', { className: 'lc-stack', style: { gap: 1, minWidth: 62 } },
|
|
1834
|
+
h('div', { style: { fontSize: 22, fontWeight: 700, lineHeight: 1.2 } }, String((chats ?? []).length)),
|
|
1835
|
+
h('div', { className: 'lc-meta' }, '聊过的场'),
|
|
1836
|
+
)
|
|
1837
|
+
: null,
|
|
1838
|
+
),
|
|
1839
|
+
),
|
|
1840
|
+
|
|
1727
1841
|
// 写小说那扇门:先列书架。没有它,用户建了一本书再回来就找不到了。
|
|
1728
1842
|
mode === 'novel'
|
|
1729
1843
|
? h('div', null,
|
|
@@ -1781,7 +1895,7 @@ function HomeView({ state, listing, mode, onOpen, onOpenWorld, onNavigate, onPro
|
|
|
1781
1895
|
? (isReal
|
|
1782
1896
|
? h('div', null,
|
|
1783
1897
|
h(GroupTitle, { icon: 'people' }, `认识的人 · ${byKind.real.length}`),
|
|
1784
|
-
h('div', { className: 'lc-stack' }, byKind.real.map((c) => h(CardRow, { key: c.path, card: c, onOpen, photo: avatars[c.id], onDelete: onDeleteCard }))),
|
|
1898
|
+
h('div', { className: 'lc-stack' }, byKind.real.map((c) => h(CardRow, { key: c.path, card: c, onOpen, photo: avatars[c.id], onDelete: onDeleteCard, onEdit: onEditCard }))),
|
|
1785
1899
|
)
|
|
1786
1900
|
// 同一个文件夹里可能两样都有。这扇门不直接铺开真人,但也不能装作没有——
|
|
1787
1901
|
// 用户会以为卡丢了。收起来一行,想看再展开,展开后是「复制一份来演」。
|
|
@@ -1813,17 +1927,49 @@ function HomeView({ state, listing, mode, onOpen, onOpenWorld, onNavigate, onPro
|
|
|
1813
1927
|
))
|
|
1814
1928
|
: null,
|
|
1815
1929
|
|
|
1930
|
+
// 「现在用哪张」:写小说、酒馆那两扇门里演谁 / 写谁不用每次现挑;
|
|
1931
|
+
// 真实人物那扇门用它决定首页先给谁。存在这个文件夹的 config.json 里。
|
|
1932
|
+
(() => {
|
|
1933
|
+
const pool = isReal ? byKind.real : byKind.fic
|
|
1934
|
+
if (pool.length === 0) return null
|
|
1935
|
+
const label = isReal ? '这扇门先看谁' : (mode === 'tavern' ? '现在演谁' : '现在写谁')
|
|
1936
|
+
const chosen = String(pinId ?? '')
|
|
1937
|
+
const hit = chosen === '' ? undefined : pool.find((c) => String(c.id ?? '') === chosen)
|
|
1938
|
+
// 空着也是一档:不挑卡。用户按一下下拉里的第一项就能取消选择,
|
|
1939
|
+
// 之后写小说 / 演都从零开始,不读卡上的设定。
|
|
1940
|
+
return h('div', null,
|
|
1941
|
+
h('div', { className: 'lc-row', style: { marginTop: 10, marginBottom: 2, gap: 8 } },
|
|
1942
|
+
h('span', { className: 'lc-meta', style: { flexShrink: 0 } }, label),
|
|
1943
|
+
h('select', {
|
|
1944
|
+
className: 'lc-select',
|
|
1945
|
+
value: chosen,
|
|
1946
|
+
onChange: (e) => onPickPin?.(String(e?.target?.value ?? '')),
|
|
1947
|
+
},
|
|
1948
|
+
h('option', { value: '' }, '不挑卡(从零开始)'),
|
|
1949
|
+
pool.map((c) => h('option', { key: c.path, value: String(c.id ?? '') }, String(c.name ?? '(还没起名字)'))),
|
|
1950
|
+
),
|
|
1951
|
+
hit === undefined ? null : h('span', { className: 'lc-meta' }, '说「演他」「写他」就默认用这张'),
|
|
1952
|
+
),
|
|
1953
|
+
chosen !== '' ? null : h('div', { className: 'lc-meta', style: { marginTop: 2 } },
|
|
1954
|
+
isReal
|
|
1955
|
+
? '没挑卡:这扇门不需要它,看谁点谁就行。'
|
|
1956
|
+
: (mode === 'tavern'
|
|
1957
|
+
? '没挑卡:这一场不读卡上的设定,TA 会先问你两三句把人立起来。'
|
|
1958
|
+
: '没挑卡:这一本不读卡上和世界书里的设定,AI 只按写作方法来写。')),
|
|
1959
|
+
)
|
|
1960
|
+
})(),
|
|
1961
|
+
|
|
1816
1962
|
byKind.fic.length > 0
|
|
1817
1963
|
? h('div', null,
|
|
1818
1964
|
h(GroupTitle, { tone: 'interview', icon: 'book' }, `${isReal ? '虚构角色' : (mode === 'tavern' ? '可以拿来演的角色' : '角色')} · ${byKind.fic.length}`),
|
|
1819
|
-
h('div', { className: 'lc-stack' }, byKind.fic.map((c) => h(CardRow, { key: c.path, card: c, onOpen, photo: avatars[c.id], onDelete: onDeleteCard }))),
|
|
1965
|
+
h('div', { className: 'lc-stack' }, byKind.fic.map((c) => h(CardRow, { key: c.path, card: c, onOpen, photo: avatars[c.id], onDelete: onDeleteCard, onEdit: onEditCard }))),
|
|
1820
1966
|
)
|
|
1821
1967
|
: null,
|
|
1822
1968
|
|
|
1823
1969
|
byKind.other.length > 0
|
|
1824
1970
|
? h('div', null,
|
|
1825
1971
|
h(GroupTitle, { tone: 'analyze', icon: 'list' }, `其他 · ${byKind.other.length}`),
|
|
1826
|
-
h('div', { className: 'lc-stack' }, byKind.other.map((c) => h(CardRow, { key: c.path, card: c, onOpen, photo: avatars[c.id], onDelete: onDeleteCard }))),
|
|
1972
|
+
h('div', { className: 'lc-stack' }, byKind.other.map((c) => h(CardRow, { key: c.path, card: c, onOpen, photo: avatars[c.id], onDelete: onDeleteCard, onEdit: onEditCard }))),
|
|
1827
1973
|
)
|
|
1828
1974
|
: null,
|
|
1829
1975
|
|
|
@@ -1915,14 +2061,14 @@ function HomeView({ state, listing, mode, onOpen, onOpenWorld, onNavigate, onPro
|
|
|
1915
2061
|
h(Btn, { size: 'sm', ghost: true, icon: 'folder', onClick: () => onNavigate(VIEWS.setup) }, '换个文件夹'),
|
|
1916
2062
|
// 路径照实写出来:这是唯一一处「档案到底在哪儿」的线索。
|
|
1917
2063
|
// 藏起来,选错文件夹的人就永远找不回去了。
|
|
1918
|
-
h('span', { className: 'lc-meta lc-ellipsis' }, state?.workspace === undefined || state?.workspace === '' ? '' :
|
|
2064
|
+
h('span', { className: 'lc-meta lc-ellipsis' }, state?.workspace === undefined || state?.workspace === '' ? '' : '档案就在你选的那个文件夹里'),
|
|
1919
2065
|
),
|
|
1920
2066
|
)
|
|
1921
2067
|
: null,
|
|
1922
2068
|
)
|
|
1923
2069
|
}
|
|
1924
2070
|
|
|
1925
|
-
function CardRow({ card, onOpen, photo, onDelete }) {
|
|
2071
|
+
function CardRow({ card, onOpen, photo, onDelete, onEdit }) {
|
|
1926
2072
|
// 整行是一个 button(点哪儿都能打开)。要再塞一个「删」进去,就不能
|
|
1927
2073
|
// 在 button 里放 button——浏览器会把它们当兄弟节点拆开,React 也会警告。
|
|
1928
2074
|
// 所以行改成 div,左边一块可点区域负责打开,右边单独一个真 button 负责删。
|
|
@@ -1949,7 +2095,9 @@ function CardRow({ card, onOpen, photo, onDelete }) {
|
|
|
1949
2095
|
),
|
|
1950
2096
|
h('div', { className: 'lc-row', style: { marginTop: 3 } },
|
|
1951
2097
|
h(Bar, { value: card.coverage }),
|
|
1952
|
-
|
|
2098
|
+
// 「10%」以前只有一个数字,没人知道是什么。它是这张卡写全了多少:
|
|
2099
|
+
// 关系、性格、说话习惯、做过的事……这些栏里填了几样。
|
|
2100
|
+
h('span', { className: 'lc-meta', style: { flexShrink: 0 }, title: '这张卡写全了多少:性格、说话习惯、做过的事这些填了几样' }, `写全 ${card.coverage}%`),
|
|
1953
2101
|
),
|
|
1954
2102
|
(card.tags ?? []).length > 0
|
|
1955
2103
|
? h('div', { className: 'lc-wrap', style: { marginTop: 5 } }, card.tags.slice(0, 4).map((t) => h(Tag, { key: t }, t)))
|
|
@@ -1958,6 +2106,15 @@ function CardRow({ card, onOpen, photo, onDelete }) {
|
|
|
1958
2106
|
),
|
|
1959
2107
|
// 列表里直接能删:以前必须先点开卡、滚到最底下才找得到「删掉这张卡」,
|
|
1960
2108
|
// 建错一张(比如「复制一份来演」试了几次)就得来回点好几屏。
|
|
2109
|
+
// 「写全 10%」后面以前没有任何「去补它」的入口:要改这张卡,得先点开、
|
|
2110
|
+
// 再在卡页上找「改这张卡」。一行一个铅笔,直接进修改。
|
|
2111
|
+
onEdit === undefined ? null : h('button', {
|
|
2112
|
+
type: 'button',
|
|
2113
|
+
className: 'lc-btn ghost sm',
|
|
2114
|
+
title: `改「${card.name ?? '这张卡'}」`,
|
|
2115
|
+
onClick: (e) => { e?.stopPropagation?.(); onEdit(card) },
|
|
2116
|
+
style: { flex: '0 0 auto' },
|
|
2117
|
+
}, h(Icon, { name: 'pencil', size: 13 })),
|
|
1961
2118
|
onDelete === undefined ? null : h('button', {
|
|
1962
2119
|
type: 'button',
|
|
1963
2120
|
className: 'lc-btn ghost sm',
|
|
@@ -2104,6 +2261,386 @@ function WorldView({ world, listing, onOpenCard }) {
|
|
|
2104
2261
|
* 没人会读,也没人改得动。
|
|
2105
2262
|
* - 不问「要不要继续」。按钮在那儿,要不要点是人自己的事。
|
|
2106
2263
|
*/
|
|
2264
|
+
/**
|
|
2265
|
+
* 预设选择条:三种玩法共用。
|
|
2266
|
+
*
|
|
2267
|
+
* 为什么做成一行小按钮而不是下拉框:这些名字(慢热 / 直球 / 冷峻白描 /
|
|
2268
|
+
* 查一件事)本身就说明了效果,扫一眼就能选。下拉框要点两下才看见有什么。
|
|
2269
|
+
*/
|
|
2270
|
+
function PresetBar({ mode, value, onChange, onManage }) {
|
|
2271
|
+
const [groups, setGroups] = useState(null)
|
|
2272
|
+
const [err, setErr] = useState(null)
|
|
2273
|
+
useEffect(() => {
|
|
2274
|
+
let gone = false
|
|
2275
|
+
call('preset.list', {})
|
|
2276
|
+
.then((r) => { if (!gone && r?.ok === true) setGroups(Array.isArray(r.groups) ? r.groups : []) })
|
|
2277
|
+
.catch((e) => { if (!gone) setErr(humanizeError(e)) })
|
|
2278
|
+
return () => { gone = true }
|
|
2279
|
+
}, [])
|
|
2280
|
+
if (groups === null) return null
|
|
2281
|
+
const mine = groups.find((g) => String(g.mode) === mode)
|
|
2282
|
+
const items = mine === undefined ? [] : (mine.items ?? [])
|
|
2283
|
+
if (items.length === 0) return null
|
|
2284
|
+
return h('div', { className: 'lc-stack', style: { gap: 6 } },
|
|
2285
|
+
h('div', { className: 'lc-row' },
|
|
2286
|
+
h('div', { className: 'lc-grow lc-meta' }, '演法 / 写法(选一个,能不选)'),
|
|
2287
|
+
onManage === undefined ? null : h(Btn, { size: 'sm', ghost: true, icon: 'edit', onClick: onManage }, '管理'),
|
|
2288
|
+
),
|
|
2289
|
+
h('div', { className: 'lc-row', style: { flexWrap: 'wrap', gap: 6 } },
|
|
2290
|
+
items.map((p) => h(Btn, {
|
|
2291
|
+
key: p.id,
|
|
2292
|
+
size: 'sm',
|
|
2293
|
+
tone: value === p.id ? 'primary' : undefined,
|
|
2294
|
+
onClick: () => onChange(value === p.id ? '' : p.id),
|
|
2295
|
+
title: String(p.desc ?? ''),
|
|
2296
|
+
}, String(p.name ?? p.id))),
|
|
2297
|
+
),
|
|
2298
|
+
err === null ? null : h(Note, { tone: 'err', icon: 'warning' }, err),
|
|
2299
|
+
)
|
|
2300
|
+
}
|
|
2301
|
+
|
|
2302
|
+
/**
|
|
2303
|
+
* 文字小说游戏:进到一本书的某一段情节里,你来选,它来推。
|
|
2304
|
+
*
|
|
2305
|
+
* 和「写小说」摆在一起但不是一个东西:那边是你在写,这边是你在里面。
|
|
2306
|
+
* 所以这一屏的重点是**局面清楚**——现在在哪、手上有什么、这一步要付什么代价。
|
|
2307
|
+
*/
|
|
2308
|
+
function GameView({ bookId, onBack, flash }) {
|
|
2309
|
+
const [play, setPlay] = useState(null)
|
|
2310
|
+
const [move, setMove] = useState('')
|
|
2311
|
+
const [busy, setBusy] = useState('')
|
|
2312
|
+
const [err, setErr] = useState(null)
|
|
2313
|
+
const [preset, setPreset] = useState('')
|
|
2314
|
+
const [chapter, setChapter] = useState(0)
|
|
2315
|
+
const [chapterList, setChapterList] = useState([])
|
|
2316
|
+
// 「把这一局写成小说的一章」。这几个 state 放在所有 hook 之后:
|
|
2317
|
+
// 上面那几个槽位有测试按号码摆状态,插在中间会全体错位。
|
|
2318
|
+
const [toOpen, setToOpen] = useState(false)
|
|
2319
|
+
const [toNote, setToNote] = useState('')
|
|
2320
|
+
const [toBusy, setToBusy] = useState(false)
|
|
2321
|
+
// 以前这一局退出就找不回来了,而界面还写着「退出再进来还能接着走」。
|
|
2322
|
+
// 存档后台一直都有(game.list),缺的就是这半截入口。
|
|
2323
|
+
const [plays, setPlays] = useState([])
|
|
2324
|
+
|
|
2325
|
+
const loadPlays = async () => {
|
|
2326
|
+
try {
|
|
2327
|
+
const r = await call('game.list', { book: bookId })
|
|
2328
|
+
if (r?.ok === true) setPlays(Array.isArray(r.items) ? r.items : [])
|
|
2329
|
+
} catch { /* 列不出来不影响新开一局 */ }
|
|
2330
|
+
}
|
|
2331
|
+
|
|
2332
|
+
const toChapter = async () => {
|
|
2333
|
+
if (play === null) return
|
|
2334
|
+
setToBusy(true); setErr(null)
|
|
2335
|
+
try {
|
|
2336
|
+
const r = await call('game.toChapter', { book: bookId, id: play.id, note: toNote })
|
|
2337
|
+
if (r?.ok !== true) { setErr(r?.error ?? '没写成'); return }
|
|
2338
|
+
setToOpen(false); setToNote('')
|
|
2339
|
+
if (typeof flash === 'function') flash(`写成了第 ${r.chapter ?? '?'} 章`)
|
|
2340
|
+
} catch (e) { setErr(humanizeError(e)) } finally { setToBusy(false) }
|
|
2341
|
+
}
|
|
2342
|
+
|
|
2343
|
+
const open = async (row) => {
|
|
2344
|
+
setErr(null)
|
|
2345
|
+
try {
|
|
2346
|
+
const r = await call('game.get', { book: bookId, id: row.id })
|
|
2347
|
+
if (r?.ok !== true) { setErr(r?.error ?? '这一局打不开'); return }
|
|
2348
|
+
setPlay({ id: row.id, turns: r.turns ?? [], choices: r.choices ?? [], scene: r.scene ?? '', holding: r.holding ?? [], chapter: r.chapter })
|
|
2349
|
+
} catch (e) { setErr(humanizeError(e)) }
|
|
2350
|
+
}
|
|
2351
|
+
|
|
2352
|
+
useEffect(() => {
|
|
2353
|
+
let gone = false
|
|
2354
|
+
loadPlays()
|
|
2355
|
+
call('novel.get', { id: bookId })
|
|
2356
|
+
.then((r) => { if (!gone && r?.ok === true) setChapterList(Array.isArray(r.chapters) ? r.chapters : []) })
|
|
2357
|
+
.catch(() => {})
|
|
2358
|
+
return () => { gone = true }
|
|
2359
|
+
}, [bookId])
|
|
2360
|
+
|
|
2361
|
+
const start = async () => {
|
|
2362
|
+
setBusy('start'); setErr(null)
|
|
2363
|
+
try {
|
|
2364
|
+
const r = await call('game.start', { book: bookId, chapter, preset })
|
|
2365
|
+
if (r?.ok !== true) { setErr(r?.error ?? '这一局开不起来'); return }
|
|
2366
|
+
setPlay({ id: r.id, turns: r.turns ?? [], choices: r.choices ?? [], scene: '', holding: [], chapter: r.chapter })
|
|
2367
|
+
flash?.('开局了')
|
|
2368
|
+
} catch (e) { setErr(humanizeError(e)) } finally { setBusy('') }
|
|
2369
|
+
}
|
|
2370
|
+
|
|
2371
|
+
const step = async (text) => {
|
|
2372
|
+
const said = String(text ?? '').trim()
|
|
2373
|
+
if (said === '' || play === null) return
|
|
2374
|
+
setBusy('step'); setErr(null)
|
|
2375
|
+
try {
|
|
2376
|
+
const r = await call('game.say', { book: bookId, id: play.id, move: said })
|
|
2377
|
+
if (Array.isArray(r?.turns)) setPlay({ ...play, turns: r.turns, choices: r.choices ?? [] })
|
|
2378
|
+
if (r?.ok !== true) { setErr(r?.error ?? '这一步没成'); return }
|
|
2379
|
+
setMove('')
|
|
2380
|
+
} catch (e) { setErr(humanizeError(e)) } finally { setBusy('') }
|
|
2381
|
+
}
|
|
2382
|
+
|
|
2383
|
+
if (play === null) {
|
|
2384
|
+
return h('div', { className: 'lc-pad lc-stack' },
|
|
2385
|
+
h(Btn, { size: 'sm', icon: 'back', onClick: onBack }, '回书架'),
|
|
2386
|
+
h('h3', { style: { margin: '4px 0 0' } }, '挑一个地方进去'),
|
|
2387
|
+
h('div', { className: 'lc-meta' }, '从哪一章接着演都行。没有正文也行,它会自己起头。'),
|
|
2388
|
+
h('div', { className: 'lc-row', style: { flexWrap: 'wrap', gap: 6 } },
|
|
2389
|
+
h(Btn, { size: 'sm', tone: chapter === 0 ? 'primary' : undefined, onClick: () => setChapter(0) }, '从头开始'),
|
|
2390
|
+
chapterList.map((c) => h(Btn, {
|
|
2391
|
+
key: c.index, size: 'sm', tone: chapter === c.index ? 'primary' : undefined,
|
|
2392
|
+
onClick: () => setChapter(c.index),
|
|
2393
|
+
}, `第 ${c.index} 章`)),
|
|
2394
|
+
),
|
|
2395
|
+
h(PresetBar, { mode: 'game', value: preset, onChange: setPreset }),
|
|
2396
|
+
h(Btn, { tone: 'primary', block: true, icon: 'spark', disabled: busy !== '', onClick: start },
|
|
2397
|
+
busy === 'start' ? '正在开局…' : '进这一段'),
|
|
2398
|
+
plays.length === 0
|
|
2399
|
+
? null
|
|
2400
|
+
: h('div', { className: 'lc-stack', style: { gap: 6, marginTop: 10 } },
|
|
2401
|
+
h('div', { className: 'lc-fhint' }, `之前玩到一半的 · ${plays.length}`),
|
|
2402
|
+
plays.map((row) => h(Btn, {
|
|
2403
|
+
key: row.id, block: true, size: 'sm', icon: 'history',
|
|
2404
|
+
onClick: () => open(row),
|
|
2405
|
+
}, `${String(row.scene ?? '').trim() === '' ? '那一局' : String(row.scene)} · 走了 ${Number(row.turns ?? 0)} 步`)),
|
|
2406
|
+
),
|
|
2407
|
+
err === null ? null : h(Note, { tone: 'err', icon: 'warning' }, err),
|
|
2408
|
+
)
|
|
2409
|
+
}
|
|
2410
|
+
|
|
2411
|
+
const narrations = (play.turns ?? []).filter((t) => t.kind === 'narrate' || t.kind === 'choose')
|
|
2412
|
+
return h('div', { className: 'lc-pad lc-stack', style: { gap: 10 } },
|
|
2413
|
+
h('div', { className: 'lc-row' },
|
|
2414
|
+
h(Btn, { size: 'sm', icon: 'back', onClick: onBack }, '这一局先放着'),
|
|
2415
|
+
h('div', { className: 'lc-grow lc-meta' },
|
|
2416
|
+
[play.chapter > 0 ? `从第 ${play.chapter} 章进来的` : '从头开的',
|
|
2417
|
+
`已经走了 ${(play.turns ?? []).filter((t) => t.kind === 'choose').length} 步`].join(' · ')),
|
|
2418
|
+
h(Btn, {
|
|
2419
|
+
size: 'sm', icon: 'book',
|
|
2420
|
+
disabled: busy !== '' || (play.turns ?? []).length === 0,
|
|
2421
|
+
onClick: () => setToOpen(true),
|
|
2422
|
+
}, '写成小说的一章'),
|
|
2423
|
+
),
|
|
2424
|
+
toOpen === true
|
|
2425
|
+
? h('div', { className: 'lc-sec lc-stack' },
|
|
2426
|
+
h('div', { className: 'lc-fhint' }, '这一局会改写成《' + bookId + '》的下一章'),
|
|
2427
|
+
h('input', {
|
|
2428
|
+
className: 'lc-input', value: toNote, spellCheck: false,
|
|
2429
|
+
placeholder: '这一章要往哪走(可以不写)',
|
|
2430
|
+
onChange: (e) => setToNote(e.target.value),
|
|
2431
|
+
}),
|
|
2432
|
+
h('div', { className: 'lc-row' },
|
|
2433
|
+
h(Btn, { tone: 'primary', disabled: toBusy, onClick: toChapter }, toBusy ? '写着…' : '写成这一章'),
|
|
2434
|
+
h(Btn, { ghost: true, disabled: toBusy, onClick: () => setToOpen(false) }, '先不变'),
|
|
2435
|
+
),
|
|
2436
|
+
)
|
|
2437
|
+
: null,
|
|
2438
|
+
String(play.scene ?? '').trim() === '' ? null : h(Note, { icon: 'book' }, play.scene),
|
|
2439
|
+
Array.isArray(play.holding) && play.holding.length > 0
|
|
2440
|
+
? h('div', { className: 'lc-meta' }, `手上的:${play.holding.join('、')}`)
|
|
2441
|
+
: null,
|
|
2442
|
+
h('div', { className: 'lc-stack', style: { gap: 10 } },
|
|
2443
|
+
narrations.map((t, i) => h('div', {
|
|
2444
|
+
key: i,
|
|
2445
|
+
style: {
|
|
2446
|
+
whiteSpace: 'pre-wrap', lineHeight: 1.85, fontSize: 14.5,
|
|
2447
|
+
padding: '10px 12px', borderRadius: 10,
|
|
2448
|
+
background: t.kind === 'choose' ? 'var(--lc-accent-soft)' : 'var(--lc-panel)',
|
|
2449
|
+
border: `1px solid ${t.kind === 'choose' ? 'var(--lc-accent)' : 'var(--lc-line)'}`,
|
|
2450
|
+
color: t.kind === 'choose' ? 'var(--lc-accent)' : undefined,
|
|
2451
|
+
},
|
|
2452
|
+
}, t.kind === 'choose' ? `我:${t.text}${String(t.result ?? '') === '' ? '' : `\n\n${t.result}`}` : String(t.text ?? ''))),
|
|
2453
|
+
),
|
|
2454
|
+
(play.choices ?? []).length > 0
|
|
2455
|
+
? h('div', { className: 'lc-stack', style: { gap: 6 } },
|
|
2456
|
+
h('div', { className: 'lc-meta' }, '这一步可以走:'),
|
|
2457
|
+
(play.choices ?? []).map((c, i) => h(Btn, {
|
|
2458
|
+
key: i, block: true, disabled: busy !== '', onClick: () => step(c.text),
|
|
2459
|
+
}, `${c.label}. ${c.text}`)),
|
|
2460
|
+
)
|
|
2461
|
+
: null,
|
|
2462
|
+
h('div', { className: 'lc-row' },
|
|
2463
|
+
h('input', {
|
|
2464
|
+
className: 'lc-input', value: move, spellCheck: false,
|
|
2465
|
+
placeholder: '或者自己写一句这一步怎么做',
|
|
2466
|
+
onChange: (e) => setMove(e.target.value),
|
|
2467
|
+
onKeyDown: (e) => { if (e.key === 'Enter') { e.preventDefault(); step(move) } },
|
|
2468
|
+
}),
|
|
2469
|
+
h(Btn, { tone: 'primary', disabled: busy !== '' || move.trim() === '', onClick: () => step(move) },
|
|
2470
|
+
busy === 'step' ? '等一下…' : '走这一步'),
|
|
2471
|
+
),
|
|
2472
|
+
err === null ? null : h(Note, { tone: 'err', icon: 'warning' }, err),
|
|
2473
|
+
h('div', { className: 'lc-meta' }, '每一步都会存下来,退出再进来还能接着走。'),
|
|
2474
|
+
)
|
|
2475
|
+
}
|
|
2476
|
+
|
|
2477
|
+
/**
|
|
2478
|
+
* 简历与规划。放在「真实人物记录」那扇门里(写小说和酒馆用不上)。
|
|
2479
|
+
*
|
|
2480
|
+
* 为什么分成「先把自己写清楚」和「再让 AI 帮忙」两步:
|
|
2481
|
+
* 简历这东西最怕 AI 编。先把真实情况填进去,AI 只做整理和措辞,
|
|
2482
|
+
* 不编经历——不然投出去被问一句就露了。
|
|
2483
|
+
*/
|
|
2484
|
+
function CareerView({ onBack, flash }) {
|
|
2485
|
+
const [profile, setProfile] = useState(null)
|
|
2486
|
+
const [target, setTarget] = useState('')
|
|
2487
|
+
const [goal, setGoal] = useState('')
|
|
2488
|
+
const [horizon, setHorizon] = useState('1年')
|
|
2489
|
+
const [out, setOut] = useState(null)
|
|
2490
|
+
const [busy, setBusy] = useState('')
|
|
2491
|
+
const [err, setErr] = useState(null)
|
|
2492
|
+
const [dirty, setDirty] = useState(false)
|
|
2493
|
+
|
|
2494
|
+
useEffect(() => {
|
|
2495
|
+
let gone = false
|
|
2496
|
+
call('career.get', {})
|
|
2497
|
+
.then((r) => {
|
|
2498
|
+
if (gone) return
|
|
2499
|
+
if (r?.ok !== true) { setErr(r?.error ?? '你的简历这一份读不出来'); return }
|
|
2500
|
+
setProfile(buildCareerForm(r.profileSections ?? {}))
|
|
2501
|
+
setGoal(String(r.plan?.goal ?? ''))
|
|
2502
|
+
setHorizon(String(r.plan?.horizon ?? '1年'))
|
|
2503
|
+
})
|
|
2504
|
+
.catch((e) => { if (!gone) setErr(humanizeError(e)) })
|
|
2505
|
+
return () => { gone = true }
|
|
2506
|
+
}, [])
|
|
2507
|
+
|
|
2508
|
+
const setField = (key, value) => { setProfile({ ...(profile ?? {}), [key]: value }); setDirty(true) }
|
|
2509
|
+
|
|
2510
|
+
const save = async () => {
|
|
2511
|
+
setBusy('save'); setErr(null)
|
|
2512
|
+
try {
|
|
2513
|
+
const r = await call('career.profile.save', { profile: profile ?? {} })
|
|
2514
|
+
if (r?.ok !== true) { setErr(r?.error ?? '没存下来'); return }
|
|
2515
|
+
setDirty(false); flash?.('存好了')
|
|
2516
|
+
} catch (e) { setErr(humanizeError(e)) } finally { setBusy('') }
|
|
2517
|
+
}
|
|
2518
|
+
|
|
2519
|
+
const run = async (kind) => {
|
|
2520
|
+
if (dirty) { setErr('简历改过了,先点「存好」再让它做。'); return }
|
|
2521
|
+
setBusy(kind); setErr(null); setOut(null)
|
|
2522
|
+
try {
|
|
2523
|
+
const r = kind === 'resume'
|
|
2524
|
+
? await call('career.resume', { target })
|
|
2525
|
+
: kind === 'gap'
|
|
2526
|
+
? await call('career.gap', { target })
|
|
2527
|
+
: await call('career.path', { goal, horizon })
|
|
2528
|
+
if (r?.ok !== true) { setErr(r?.error ?? '没做成'); return }
|
|
2529
|
+
setOut({ kind, text: String(r.text ?? ''), steps: r.steps ?? [] })
|
|
2530
|
+
} catch (e) { setErr(humanizeError(e)) } finally { setBusy('') }
|
|
2531
|
+
}
|
|
2532
|
+
|
|
2533
|
+
// 先看有没有出错:出错的渲染在下面(要 profile 读出来才轮得到),
|
|
2534
|
+
// 所以这里必须自己先把错说出来,否则用户看到的是一辈子转圈。
|
|
2535
|
+
if (profile === null) {
|
|
2536
|
+
return h('div', { className: 'lc-pad lc-stack' },
|
|
2537
|
+
h(Btn, { size: 'sm', icon: 'back', onClick: onBack }, '回首页'),
|
|
2538
|
+
err === null
|
|
2539
|
+
? h(Spinner)
|
|
2540
|
+
: h('div', { className: 'lc-stack' },
|
|
2541
|
+
h(Note, { tone: 'err', icon: 'warning' }, err),
|
|
2542
|
+
h(Btn, { block: true, onClick: () => { setErr(null); call('career.get', {}) } }, '再试一次'),
|
|
2543
|
+
),
|
|
2544
|
+
)
|
|
2545
|
+
}
|
|
2546
|
+
|
|
2547
|
+
const field = (key, label, rows, placeholder) => h('div', { className: 'lc-stack', style: { gap: 6 } },
|
|
2548
|
+
h('div', { className: 'lc-fhint' }, label),
|
|
2549
|
+
h('textarea', {
|
|
2550
|
+
className: 'lc-textarea', rows, value: String(profile[key] ?? ''), placeholder, spellCheck: false,
|
|
2551
|
+
onChange: (e) => setField(key, e.target.value),
|
|
2552
|
+
}),
|
|
2553
|
+
)
|
|
2554
|
+
|
|
2555
|
+
return h('div', { className: 'lc-pad lc-stack', style: { gap: 12 } },
|
|
2556
|
+
h('div', { className: 'lc-row' },
|
|
2557
|
+
h(Btn, { size: 'sm', icon: 'back', onClick: onBack }, '回首页'),
|
|
2558
|
+
h('div', { className: 'lc-grow' }),
|
|
2559
|
+
h(Btn, { size: 'sm', tone: dirty ? 'primary' : undefined, icon: 'check', disabled: busy !== '', onClick: save },
|
|
2560
|
+
busy === 'save' ? '存着…' : (dirty ? '存好' : '存好了')),
|
|
2561
|
+
),
|
|
2562
|
+
h('div', { className: 'lc-meta' }, '先把真事写在这儿。AI 只帮你整理,不会替你编经历。'),
|
|
2563
|
+
|
|
2564
|
+
h('div', { className: 'lc-sec lc-stack' },
|
|
2565
|
+
field('基本情况', '基本情况', 3, '哪个学校、什么专业、几年级、现在在哪'),
|
|
2566
|
+
field('学过什么', '学过什么(一行一门)', 4, '现代汉语|能讲清音韵那套\n写作|能改到能发'),
|
|
2567
|
+
field('做过什么', '做过什么(一行一件)', 4, '校刊编辑|2025 秋|出了两期\n家教|2025 夏|带过一个高三'),
|
|
2568
|
+
field('会用哪些工具', '会用哪些工具(一行一个)', 2, 'Word\n剪映'),
|
|
2569
|
+
field('想去哪', '想去哪', 3, '公司加岗位,或者学校加专业。写具体一点。'),
|
|
2570
|
+
field('还差什么', '你自己觉得还差什么(一行一条)', 3, '六级还没过\n没写过正式的报告'),
|
|
2571
|
+
),
|
|
2572
|
+
|
|
2573
|
+
h('div', { className: 'lc-sec lc-stack' },
|
|
2574
|
+
h('div', { className: 'lc-fhint' }, '让 AI 帮忙'),
|
|
2575
|
+
h('input', {
|
|
2576
|
+
className: 'lc-input', value: target, spellCheck: false,
|
|
2577
|
+
placeholder: '要投哪儿:公司加岗位,或者学校加专业',
|
|
2578
|
+
onChange: (e) => setTarget(e.target.value),
|
|
2579
|
+
}),
|
|
2580
|
+
h('div', { className: 'lc-row', style: { flexWrap: 'wrap' } },
|
|
2581
|
+
h(Btn, { disabled: busy !== '' || target.trim() === '', onClick: () => run('resume') }, busy === 'resume' ? '写着…' : '照这个写简历'),
|
|
2582
|
+
h(Btn, { disabled: busy !== '' || target.trim() === '', onClick: () => run('gap') }, busy === 'gap' ? '算着…' : '看差在哪'),
|
|
2583
|
+
),
|
|
2584
|
+
h('div', { className: 'lc-row' },
|
|
2585
|
+
h('input', {
|
|
2586
|
+
className: 'lc-input', value: goal, spellCheck: false,
|
|
2587
|
+
placeholder: '想到哪儿去(一句具体的)',
|
|
2588
|
+
onChange: (e) => setGoal(e.target.value),
|
|
2589
|
+
}),
|
|
2590
|
+
h('select', { className: 'lc-select', value: horizon, onChange: (e) => setHorizon(e.target.value), style: { maxWidth: 110 } },
|
|
2591
|
+
['3个月', '1年', '4年'].map((x) => h('option', { key: x, value: x }, x))),
|
|
2592
|
+
),
|
|
2593
|
+
h(Btn, { block: true, disabled: busy !== '' || goal.trim() === '', onClick: () => run('path') },
|
|
2594
|
+
busy === 'path' ? '规划着…' : '规划怎么走'),
|
|
2595
|
+
),
|
|
2596
|
+
|
|
2597
|
+
err === null ? null : h(Note, { tone: 'err', icon: 'warning' }, err),
|
|
2598
|
+
out === null ? null : h('div', { className: 'lc-sec lc-stack' },
|
|
2599
|
+
h('div', { className: 'lc-row' },
|
|
2600
|
+
h('div', { className: 'lc-grow lc-fhint' },
|
|
2601
|
+
out.kind === 'resume' ? '写好的简历' : out.kind === 'gap' ? '差在哪' : '怎么走'),
|
|
2602
|
+
h(Btn, { size: 'sm', icon: 'download', onClick: () => copyText(out.text) }, '复制'),
|
|
2603
|
+
),
|
|
2604
|
+
h('div', { style: { whiteSpace: 'pre-wrap', lineHeight: 1.8, fontSize: 14.5 } }, out.text),
|
|
2605
|
+
out.steps.length === 0 ? null : h('div', { className: 'lc-meta' }, `认出 ${out.steps.length} 步`),
|
|
2606
|
+
),
|
|
2607
|
+
)
|
|
2608
|
+
}
|
|
2609
|
+
|
|
2610
|
+
/** 把后端读出来的小节拍平成表单能直接用的字段。 */
|
|
2611
|
+
function buildCareerForm(sections) {
|
|
2612
|
+
const pick = (key) => {
|
|
2613
|
+
const v = sections?.[key]
|
|
2614
|
+
if (Array.isArray(v)) return v.join('\n')
|
|
2615
|
+
return String(v ?? '')
|
|
2616
|
+
}
|
|
2617
|
+
return {
|
|
2618
|
+
基本情况: pick('基本情况'),
|
|
2619
|
+
学过什么: pick('学过什么'),
|
|
2620
|
+
做过什么: pick('做过什么'),
|
|
2621
|
+
会用哪些工具: pick('会用哪些工具'),
|
|
2622
|
+
想去哪: pick('想去哪'),
|
|
2623
|
+
还差什么: pick('还差什么'),
|
|
2624
|
+
}
|
|
2625
|
+
}
|
|
2626
|
+
|
|
2627
|
+
/** 复制到剪贴板;不支持就退回「选中让用户自己复制」。 */
|
|
2628
|
+
function copyText(text) {
|
|
2629
|
+
const value = String(text ?? '')
|
|
2630
|
+
if (typeof navigator !== 'undefined' && navigator?.clipboard?.writeText !== undefined) {
|
|
2631
|
+
navigator.clipboard.writeText(value).catch(() => {})
|
|
2632
|
+
return
|
|
2633
|
+
}
|
|
2634
|
+
if (typeof document !== 'undefined' && typeof document.createElement === 'function') {
|
|
2635
|
+
const box = document.createElement('textarea')
|
|
2636
|
+
box.value = value
|
|
2637
|
+
document.body.appendChild(box)
|
|
2638
|
+
box.select()
|
|
2639
|
+
try { document.execCommand('copy') } catch { /* 复制不了就算了 */ }
|
|
2640
|
+
document.body.removeChild(box)
|
|
2641
|
+
}
|
|
2642
|
+
}
|
|
2643
|
+
|
|
2107
2644
|
function BookView({ bookId, onBack, flash }) {
|
|
2108
2645
|
const [book, setBook] = useState(null)
|
|
2109
2646
|
const [outline, setOutline] = useState(null)
|
|
@@ -2116,6 +2653,8 @@ function BookView({ bookId, onBack, flash }) {
|
|
|
2116
2653
|
const [ask, setAsk] = useState('')
|
|
2117
2654
|
const [editingOutline, setEditingOutline] = useState(false)
|
|
2118
2655
|
const [outlineText, setOutlineText] = useState('')
|
|
2656
|
+
// 这一章的正文有没有还没存下的改动。切章之前必须先处理,否则写的东西会没。
|
|
2657
|
+
const [bodyDirty, setBodyDirty] = useState(false)
|
|
2119
2658
|
|
|
2120
2659
|
const load = async (want) => {
|
|
2121
2660
|
setErr(null)
|
|
@@ -2140,6 +2679,24 @@ function BookView({ bookId, onBack, flash }) {
|
|
|
2140
2679
|
} catch (e) { setErr(humanizeError(e)) }
|
|
2141
2680
|
}
|
|
2142
2681
|
|
|
2682
|
+
// 切章之前先把没存的正文收好。存不上就留在这一章,别让人以为写进去了。
|
|
2683
|
+
const keepBody = async () => {
|
|
2684
|
+
if (bodyDirty !== true) return true
|
|
2685
|
+
if (body.trim() === '') { setBodyDirty(false); return true }
|
|
2686
|
+
try {
|
|
2687
|
+
const r = await call('novel.chapter.save', { id: bookId, index: chapterIndex, body })
|
|
2688
|
+
if (r?.ok !== true) { setErr(r?.error ?? '这一章没存上,先别走'); return false }
|
|
2689
|
+
setBodyDirty(false)
|
|
2690
|
+
return true
|
|
2691
|
+
} catch (e) { setErr(humanizeError(e)); return false }
|
|
2692
|
+
}
|
|
2693
|
+
|
|
2694
|
+
const goChapter = async (index) => {
|
|
2695
|
+
if ((await keepBody()) !== true) return
|
|
2696
|
+
setChapterIndex(index)
|
|
2697
|
+
await openChapter(index)
|
|
2698
|
+
}
|
|
2699
|
+
|
|
2143
2700
|
useEffect(() => { load(0) }, [bookId])
|
|
2144
2701
|
|
|
2145
2702
|
const doPlan = async () => {
|
|
@@ -2157,7 +2714,16 @@ function BookView({ bookId, onBack, flash }) {
|
|
|
2157
2714
|
try {
|
|
2158
2715
|
const r = await call('novel.outline.save', { id: bookId, text: outlineText })
|
|
2159
2716
|
if (r?.ok !== true) { setErr(r?.error ?? '大纲没存上'); return }
|
|
2160
|
-
|
|
2717
|
+
// 只取存盘结果里跟大纲正文有关的那几样。服务端回的 chapters 是「几条」这个数字,
|
|
2718
|
+
// 整包铺出去会把本地那份逐章列表盖掉,下一屏渲染就会拿数字去 find。
|
|
2719
|
+
setOutline({
|
|
2720
|
+
ok: true,
|
|
2721
|
+
path: r.path,
|
|
2722
|
+
text: outlineText,
|
|
2723
|
+
theme: r.theme,
|
|
2724
|
+
ending: r.ending,
|
|
2725
|
+
chapters: Array.isArray(outline?.chapters) ? outline.chapters : [],
|
|
2726
|
+
})
|
|
2161
2727
|
setEditingOutline(false)
|
|
2162
2728
|
flash?.('大纲存好了')
|
|
2163
2729
|
} catch (e) { setErr(humanizeError(e)) } finally { setBusy('') }
|
|
@@ -2179,7 +2745,7 @@ function BookView({ bookId, onBack, flash }) {
|
|
|
2179
2745
|
const merged = body.trim() === '' ? draft : `${body.trim()}\n\n${draft}`
|
|
2180
2746
|
const r = await call('novel.chapter.save', { id: bookId, index: chapterIndex, body: merged })
|
|
2181
2747
|
if (r?.ok !== true) { setErr(r?.error ?? '没存上'); return }
|
|
2182
|
-
setBody(merged); setDraft(null)
|
|
2748
|
+
setBody(merged); setDraft(null); setBodyDirty(false)
|
|
2183
2749
|
flash?.(`第 ${chapterIndex} 章存好了`)
|
|
2184
2750
|
await load(chapterIndex)
|
|
2185
2751
|
} catch (e) { setErr(humanizeError(e)) } finally { setBusy('') }
|
|
@@ -2190,12 +2756,16 @@ function BookView({ bookId, onBack, flash }) {
|
|
|
2190
2756
|
try {
|
|
2191
2757
|
const r = await call('novel.chapter.save', { id: bookId, index: chapterIndex, body })
|
|
2192
2758
|
if (r?.ok !== true) { setErr(r?.error ?? '没存上'); return }
|
|
2759
|
+
setBodyDirty(false)
|
|
2193
2760
|
flash?.(`第 ${chapterIndex} 章存好了`)
|
|
2194
2761
|
await load(chapterIndex)
|
|
2195
2762
|
} catch (e) { setErr(humanizeError(e)) } finally { setBusy('') }
|
|
2196
2763
|
}
|
|
2197
2764
|
|
|
2198
2765
|
const doReview = async () => {
|
|
2766
|
+
// 挑毛病看的是存下来的那一版,所以正文有没存的改动就先存一次,
|
|
2767
|
+
// 否则你会以为它评的是刚写的那段。
|
|
2768
|
+
if ((await keepBody()) !== true) return
|
|
2199
2769
|
setBusy('review'); setErr(null)
|
|
2200
2770
|
try {
|
|
2201
2771
|
const r = await call('novel.chapter.review', { id: bookId, index: chapterIndex })
|
|
@@ -2212,13 +2782,13 @@ function BookView({ bookId, onBack, flash }) {
|
|
|
2212
2782
|
}
|
|
2213
2783
|
|
|
2214
2784
|
const chapters = Array.isArray(book.chapters) ? book.chapters : []
|
|
2215
|
-
const plan = outline?.ok === true
|
|
2785
|
+
const plan = outline?.ok === true && Array.isArray(outline.chapters) ? outline.chapters : []
|
|
2216
2786
|
const planItem = plan.find((c) => c.index === chapterIndex)
|
|
2217
2787
|
const title = String(book.data?.title ?? bookId)
|
|
2218
2788
|
|
|
2219
2789
|
return h('div', { className: 'lc-pad lc-stack', style: { gap: 12 } },
|
|
2220
2790
|
h('div', { className: 'lc-row' },
|
|
2221
|
-
h(Btn, { size: 'sm', icon: 'back', onClick: onBack }, '回书架'),
|
|
2791
|
+
h(Btn, { size: 'sm', icon: 'back', onClick: async () => { if ((await keepBody()) === true) onBack() } }, '回书架'),
|
|
2222
2792
|
h('div', { className: 'lc-grow lc-ellipsis', style: { fontWeight: 700, fontSize: 16.5 } }, `《${title}》`),
|
|
2223
2793
|
h('span', { className: 'lc-meta' }, `${chapters.length} 章`),
|
|
2224
2794
|
),
|
|
@@ -2248,7 +2818,7 @@ function BookView({ bookId, onBack, flash }) {
|
|
|
2248
2818
|
background: c.index === chapterIndex ? 'var(--lc-accent-soft)' : 'transparent',
|
|
2249
2819
|
color: c.index === chapterIndex ? 'var(--lc-accent)' : undefined,
|
|
2250
2820
|
},
|
|
2251
|
-
onClick: () => {
|
|
2821
|
+
onClick: () => { goChapter(c.index) },
|
|
2252
2822
|
}, `第 ${c.index} 章 · ${c.plan}`))),
|
|
2253
2823
|
outline.ending === '' ? null : h('div', { className: 'lc-meta' }, `结局:${outline.ending}`),
|
|
2254
2824
|
),
|
|
@@ -2314,7 +2884,7 @@ function BookView({ bookId, onBack, flash }) {
|
|
|
2314
2884
|
spellCheck: false,
|
|
2315
2885
|
placeholder: '这一章还空着。让 AI 写一段,或者自己动手。',
|
|
2316
2886
|
style: { minHeight: 260, marginTop: 6, lineHeight: 1.85 },
|
|
2317
|
-
onChange: (e) => setBody(e.target.value),
|
|
2887
|
+
onChange: (e) => { setBody(e.target.value); setBodyDirty(true) },
|
|
2318
2888
|
}),
|
|
2319
2889
|
h('div', { className: 'lc-row' },
|
|
2320
2890
|
h(Btn, { size: 'sm', tone: 'primary', icon: 'check', disabled: busy !== '', onClick: saveBody }, busy === 'save' ? '正在存…' : '存好这一章'),
|
|
@@ -2323,8 +2893,7 @@ function BookView({ bookId, onBack, flash }) {
|
|
|
2323
2893
|
h('div', { className: 'lc-grow' }),
|
|
2324
2894
|
h(Btn, { size: 'sm', ghost: true, icon: 'plus', onClick: async () => {
|
|
2325
2895
|
const next = chapterIndex + 1
|
|
2326
|
-
|
|
2327
|
-
await openChapter(next)
|
|
2896
|
+
await goChapter(next)
|
|
2328
2897
|
} }, `写第 ${chapterIndex + 1} 章`),
|
|
2329
2898
|
),
|
|
2330
2899
|
review === null
|
|
@@ -2339,7 +2908,7 @@ function BookView({ bookId, onBack, flash }) {
|
|
|
2339
2908
|
)
|
|
2340
2909
|
}
|
|
2341
2910
|
|
|
2342
|
-
function TavernView({ chat, onChat, onBack }) {
|
|
2911
|
+
function TavernView({ chat, onChat, onBack, flash }) {
|
|
2343
2912
|
const [draft, setDraft] = useState('')
|
|
2344
2913
|
const [busy, setBusy] = useState(false)
|
|
2345
2914
|
const [err, setErr] = useState(null)
|
|
@@ -2347,6 +2916,16 @@ function TavernView({ chat, onChat, onBack }) {
|
|
|
2347
2916
|
// 「到这儿为止」那段备忘。它存在会话文件里,跟着 chat 一起下发。
|
|
2348
2917
|
const [notes, setNotes] = useState(Array.isArray(chat?.notes) ? chat.notes : [])
|
|
2349
2918
|
const scrollRef = useRef(null)
|
|
2919
|
+
// 「把这一场变成小说的一章」。这几个 state 特意放在所有 hook 之后:
|
|
2920
|
+
// 上面那几个槽位有测试按号码摆状态,插在中间会让它们全体错位。
|
|
2921
|
+
const [toOpen, setToOpen] = useState(false)
|
|
2922
|
+
const [toBooks, setToBooks] = useState([])
|
|
2923
|
+
const [toBook, setToBook] = useState('')
|
|
2924
|
+
const [toBusy, setToBusy] = useState(false)
|
|
2925
|
+
const [toNote, setToNote] = useState('')
|
|
2926
|
+
// 「挑几句写进卡里」。同样排在最后。
|
|
2927
|
+
const [exBusy, setExBusy] = useState(false)
|
|
2928
|
+
const [exNote, setExNote] = useState('')
|
|
2350
2929
|
const turns = Array.isArray(chat?.turns) ? chat.turns : []
|
|
2351
2930
|
const rawName = String(chat?.card_name ?? '').trim()
|
|
2352
2931
|
const name = rawName === '' ? 'TA' : rawName
|
|
@@ -2396,6 +2975,52 @@ function TavernView({ chat, onChat, onBack }) {
|
|
|
2396
2975
|
}
|
|
2397
2976
|
}
|
|
2398
2977
|
|
|
2978
|
+
// 打开「变成小说的一章」时先问一次有哪些书。以前没有这条路,
|
|
2979
|
+
// 酒馆里演得好的一场只能靠人手动复制粘贴进小说。
|
|
2980
|
+
/**
|
|
2981
|
+
* 把这一场里最能代表 TA 的几句话写回那张卡的「对话示例」。
|
|
2982
|
+
*
|
|
2983
|
+
* 「性格:沉默寡言」这种话模型只能猜;「他说话只答半句,句尾带个『呗』」
|
|
2984
|
+
* 是能直接照做的。演着演着发现 TA 说话的样子比卡上写的准,就该固化下来。
|
|
2985
|
+
*/
|
|
2986
|
+
const toExample = async () => {
|
|
2987
|
+
if (exBusy || chat?.id === undefined) return
|
|
2988
|
+
setExBusy(true); setExNote('')
|
|
2989
|
+
try {
|
|
2990
|
+
const r = await call('tavern.toExample', { id: chat.id })
|
|
2991
|
+
if (r?.ok !== true) { setExNote(r?.error ?? '这次没挑出来'); return }
|
|
2992
|
+
const picked = Array.isArray(r.picked) ? r.picked : []
|
|
2993
|
+
setExNote(`写进卡里了,这次挑的是:${picked.map((x) => `「${x}」`).join('、')}`)
|
|
2994
|
+
flash?.('卡上的「对话示例」又厚了一点')
|
|
2995
|
+
} catch (e) {
|
|
2996
|
+
setExNote(humanizeError(e))
|
|
2997
|
+
} finally {
|
|
2998
|
+
setExBusy(false)
|
|
2999
|
+
}
|
|
3000
|
+
}
|
|
3001
|
+
|
|
3002
|
+
const openToChapter = async () => {
|
|
3003
|
+
setToOpen(true); setToBusy(true); setErr(null)
|
|
3004
|
+
try {
|
|
3005
|
+
const r = await call('novel.books', {})
|
|
3006
|
+
if (r?.ok !== true) { setErr(r?.error ?? '看不到书架'); return }
|
|
3007
|
+
const list = Array.isArray(r.books) ? r.books : []
|
|
3008
|
+
setToBooks(list)
|
|
3009
|
+
setToBook(toBook !== '' ? toBook : String(list[0]?.id ?? ''))
|
|
3010
|
+
} catch (e) { setErr(humanizeError(e)) } finally { setToBusy(false) }
|
|
3011
|
+
}
|
|
3012
|
+
|
|
3013
|
+
const toChapter = async () => {
|
|
3014
|
+
if (toBook === '') { setErr('还没有书。先回「写小说」那扇门建一本。'); return }
|
|
3015
|
+
setToBusy(true); setErr(null)
|
|
3016
|
+
try {
|
|
3017
|
+
const r = await call('tavern.toChapter', { id: chat?.id, book: toBook, note: toNote })
|
|
3018
|
+
if (r?.ok !== true) { setErr(r?.error ?? '没改成'); return }
|
|
3019
|
+
setToOpen(false); setToNote('')
|
|
3020
|
+
if (typeof flash === 'function') flash(`写成了第 ${r.chapter ?? '?'} 章`)
|
|
3021
|
+
} catch (e) { setErr(humanizeError(e)) } finally { setToBusy(false) }
|
|
3022
|
+
}
|
|
3023
|
+
|
|
2399
3024
|
const remove = async () => {
|
|
2400
3025
|
if (chat?.id === undefined) return
|
|
2401
3026
|
setBusy(true)
|
|
@@ -2493,8 +3118,36 @@ function TavernView({ chat, onChat, onBack }) {
|
|
|
2493
3118
|
onClick: summarize,
|
|
2494
3119
|
title: '把前面发生过的事记成几句,之后每轮都带上',
|
|
2495
3120
|
}, '收个尾'),
|
|
3121
|
+
h(Btn, { size: 'sm', icon: 'book', disabled: busy || turns.length === 0, onClick: openToChapter, title: '把这一场改写成某本小说的一章' }, '变成小说的一章'),
|
|
3122
|
+
h(Btn, { size: 'sm', icon: 'chat', disabled: busy || exBusy || turns.length === 0, onClick: toExample, title: '挑几句 TA 说过的话,写进那张卡的「对话示例」' }, exBusy ? '正在挑…' : '挑几句进卡里'),
|
|
2496
3123
|
h(Btn, { size: 'sm', ghost: true, icon: 'trash', disabled: busy, onClick: () => setConfirmDelete(true) }, '这一场不要了'),
|
|
2497
3124
|
),
|
|
3125
|
+
toOpen === true
|
|
3126
|
+
? h('div', { className: 'lc-sec lc-stack' },
|
|
3127
|
+
h('div', { className: 'lc-fhint' }, '挑一本书,这一场会改写成它的下一章'),
|
|
3128
|
+
toBusy && toBooks.length === 0
|
|
3129
|
+
? h(Spinner)
|
|
3130
|
+
: toBooks.length === 0
|
|
3131
|
+
? h('div', { className: 'lc-meta' }, '还没有书。先去「写小说」那扇门建一本,再回来。')
|
|
3132
|
+
: h('div', { className: 'lc-stack' },
|
|
3133
|
+
h('div', { className: 'lc-chips' }, toBooks.map((b) => h(Btn, {
|
|
3134
|
+
key: b.id,
|
|
3135
|
+
size: 'sm',
|
|
3136
|
+
tone: toBook === b.id ? 'primary' : undefined,
|
|
3137
|
+
onClick: () => setToBook(b.id),
|
|
3138
|
+
}, String(b.title ?? b.id)))),
|
|
3139
|
+
h('input', {
|
|
3140
|
+
className: 'lc-input', value: toNote, spellCheck: false,
|
|
3141
|
+
placeholder: '这一章要往哪走(可以不写)',
|
|
3142
|
+
onChange: (e) => setToNote(e.target.value),
|
|
3143
|
+
}),
|
|
3144
|
+
h('div', { className: 'lc-row' },
|
|
3145
|
+
h(Btn, { tone: 'primary', disabled: toBusy || toBook === '', onClick: toChapter }, toBusy ? '写着…' : '写成这一章'),
|
|
3146
|
+
h(Btn, { ghost: true, disabled: toBusy, onClick: () => setToOpen(false) }, '先不变'),
|
|
3147
|
+
),
|
|
3148
|
+
),
|
|
3149
|
+
)
|
|
3150
|
+
: null,
|
|
2498
3151
|
confirmDelete === true
|
|
2499
3152
|
? h('div', { className: 'lc-row' },
|
|
2500
3153
|
h('span', { className: 'lc-meta', className: 'lc-meta' }, '这一场的记录会删掉,删了就找不回来了。'),
|
|
@@ -2502,12 +3155,13 @@ function TavernView({ chat, onChat, onBack }) {
|
|
|
2502
3155
|
h(Btn, { size: 'sm', ghost: true, onClick: () => setConfirmDelete(false), disabled: busy }, '先不删'),
|
|
2503
3156
|
)
|
|
2504
3157
|
: null,
|
|
3158
|
+
exNote === '' ? null : h(Note, { tone: 'ok', icon: 'check' }, exNote),
|
|
2505
3159
|
h('div', { className: 'lc-meta' }, '每说一句都会存进「chats」里,退出再进来还能接着说。'),
|
|
2506
3160
|
)
|
|
2507
3161
|
}
|
|
2508
3162
|
|
|
2509
|
-
function CardView({ card, onRefresh, proposal, setProposal, flash, onDeleted, onInterview, onAnalyze, worlds, onOpenWorld }) {
|
|
2510
|
-
const [editing, setEditing] = useState(
|
|
3163
|
+
function CardView({ card, onRefresh, proposal, setProposal, flash, onDeleted, onInterview, onAnalyze, worlds, onOpenWorld, onTavern, initialEditing }) {
|
|
3164
|
+
const [editing, setEditing] = useState(initialEditing === true)
|
|
2511
3165
|
const [busy, setBusy] = useState('')
|
|
2512
3166
|
const [err, setErr] = useState(null)
|
|
2513
3167
|
const [showExport, setShowExport] = useState(false)
|
|
@@ -2643,6 +3297,7 @@ function CardView({ card, onRefresh, proposal, setProposal, flash, onDeleted, on
|
|
|
2643
3297
|
h('div', { className: 'lc-row', style: { marginTop: 2 } },
|
|
2644
3298
|
h(Btn, { tone: 'primary', icon: 'pencil', onClick: () => setEditing(true) }, '改这张卡'),
|
|
2645
3299
|
h(Btn, { tone: 'interview', icon: 'chat', onClick: () => onInterview(buildPreset(data)) }, '接着聊'),
|
|
3300
|
+
onTavern === undefined ? null : h(Btn, { tone: 'analyze', icon: 'mic', onClick: () => onTavern(buildPreset(data)) }, '和 TA 演一段'),
|
|
2646
3301
|
h(Btn, { tone: 'analyze', size: 'sm', icon: 'spark', onClick: onAnalyze }, '读材料'),
|
|
2647
3302
|
),
|
|
2648
3303
|
|
|
@@ -3823,6 +4478,9 @@ function InterviewView({ state, listing, preset, onRecorded, flash, onDone, onAn
|
|
|
3823
4478
|
// 结束页以前一律说「你说的都记下来了」;可要是手一滑点了结束,
|
|
3824
4479
|
// 正在写的那句其实没存进去——那句话就得改口。
|
|
3825
4480
|
const [dropped, setDropped] = useState(false)
|
|
4481
|
+
// 这一场访谈写出去的材料(interview.record 每次回传一份)。结束页要带上它们,
|
|
4482
|
+
// 不然分析页一条都不勾,而「一条都不勾」= 全读——别人的材料会被读进这张卡。
|
|
4483
|
+
const [materialPaths, setMaterialPaths] = useState([])
|
|
3826
4484
|
const scrollRef = useRef(null)
|
|
3827
4485
|
|
|
3828
4486
|
// 宿主给什么就用什么;一个都没有(还没重启、旧版宿主)就用本地这份。
|
|
@@ -3963,6 +4621,12 @@ function InterviewView({ state, listing, preset, onRecorded, flash, onDone, onAn
|
|
|
3963
4621
|
setErr(rec?.error ?? '这一句没记上。检查一下文件夹还在不在,再点一次。')
|
|
3964
4622
|
return
|
|
3965
4623
|
}
|
|
4624
|
+
// interview.record 会把你这一场的问答另存成一份材料。攒着它的路径,
|
|
4625
|
+
// 结束页「整理进卡里」必须带上——分析页一条不勾等于「全读」,
|
|
4626
|
+
// 别人说的那些也会被读进这张卡。
|
|
4627
|
+
if (typeof rec.material === 'string' && rec.material !== '') {
|
|
4628
|
+
setMaterialPaths((prev) => (prev.includes(rec.material) ? prev : [...prev, rec.material]))
|
|
4629
|
+
}
|
|
3966
4630
|
if (status === 'answered') {
|
|
3967
4631
|
setLog((prev) => [...prev, { role: 'bot', text: q.ask, options: q.options }, { role: 'me', text: answer.trim() }])
|
|
3968
4632
|
} else {
|
|
@@ -3973,6 +4637,12 @@ function InterviewView({ state, listing, preset, onRecorded, flash, onDone, onAn
|
|
|
3973
4637
|
const rest = queue.slice(1)
|
|
3974
4638
|
if (rest.length === 0) {
|
|
3975
4639
|
const p = await call('interview.plan', { about: aboutId, relation, limit: 3, kind: fiction ? 'fictional' : 'real' })
|
|
4640
|
+
// 没问着问题不等于问完了。以前这里不看结果:AI 没连上、模型抽风、
|
|
4641
|
+
// 文件夹读不出来,界面都会直接跳到结束页,还写「现在写满了 undefined%」。
|
|
4642
|
+
if (p?.ok !== true) {
|
|
4643
|
+
setErr(`${p?.error ?? '想不出下一题'}。刚才那一句已经记下了,这里是没接上——过一会儿点「再问一题」接着来。`)
|
|
4644
|
+
return
|
|
4645
|
+
}
|
|
3976
4646
|
setPlan(p)
|
|
3977
4647
|
setQueue(p.next ?? [])
|
|
3978
4648
|
setCurrent((p.next ?? [])[0] ?? null)
|
|
@@ -4130,7 +4800,7 @@ function InterviewView({ state, listing, preset, onRecorded, flash, onDone, onAn
|
|
|
4130
4800
|
plan === null || (plan.empty ?? []).length === 0
|
|
4131
4801
|
? null
|
|
4132
4802
|
: h('div', { className: 'lc-meta' }, `还空着:${(plan.empty ?? []).slice(0, 8).join('、')}`),
|
|
4133
|
-
h(Btn, { tone: 'primary', big: true, block: true, onClick: () => onAnalyze({ id: aboutId, name: preset?.name ?? name }) }, '把刚才说的整理进卡里'),
|
|
4803
|
+
h(Btn, { tone: 'primary', big: true, block: true, onClick: () => onAnalyze({ id: aboutId, name: preset?.name ?? name, materials: materialPaths }) }, '把刚才说的整理进卡里'),
|
|
4134
4804
|
h(Btn, { block: true, onClick: () => { onDone() } }, '先这样,回头再说'),
|
|
4135
4805
|
h('div', { className: 'lc-meta', style: { textAlign: 'center' } }, '你说的每句话都存成了材料。整理时会标出原文出处,编不出来的。'),
|
|
4136
4806
|
)
|
|
@@ -4193,9 +4863,16 @@ function ImportView({ busy, onImport, onAnalyze, listing }) {
|
|
|
4193
4863
|
const [drag, setDrag] = useState(false)
|
|
4194
4864
|
const [tab, setTab] = useState('card')
|
|
4195
4865
|
const inputRef = useRef(null)
|
|
4866
|
+
const [skipNote, setSkipNote] = useState('')
|
|
4196
4867
|
|
|
4197
4868
|
const handleFiles = (fileList) => {
|
|
4198
|
-
const
|
|
4869
|
+
const all = Array.from(fileList ?? [])
|
|
4870
|
+
const files = all.filter((f) => /\.(png|json|charx|zip)$/i.test(f.name))
|
|
4871
|
+
// 以前过滤完直接就 return:拖进来的是一张 jpg 头像或一份 md 设定,
|
|
4872
|
+
// 界面上什么都不发生,用户只会以为这块坏了。
|
|
4873
|
+
setSkipNote(files.length > 0 || all.length === 0
|
|
4874
|
+
? ''
|
|
4875
|
+
: `这些认不出来:${all.map((f) => f.name).join('、')}。只认角色卡文件(.png / .json / .charx / .zip)。想贴一段文字,就切到上面「一段文字」。`)
|
|
4199
4876
|
if (files.length === 0) return
|
|
4200
4877
|
onImport(files)
|
|
4201
4878
|
}
|
|
@@ -4231,6 +4908,7 @@ function ImportView({ busy, onImport, onAnalyze, listing }) {
|
|
|
4231
4908
|
style: { display: 'none' }, onChange: (e) => handleFiles(e.target.files),
|
|
4232
4909
|
}),
|
|
4233
4910
|
),
|
|
4911
|
+
skipNote === '' ? null : h(Note, { tone: 'warn', icon: 'warning' }, skipNote),
|
|
4234
4912
|
busy === 'import' ? h('div', { className: 'lc-row' }, h(Spinner), h('span', { className: 'lc-meta' }, '正在读…')) : null,
|
|
4235
4913
|
h(Note, { tone: undefined, icon: 'check' }, '导入进来的卡会原样保留所有内容,包括这个软件不认识的字段。你在这里改过的部分才会变,导出时一起带走。'),
|
|
4236
4914
|
),
|
|
@@ -4278,7 +4956,7 @@ function TextImport({ onAnalyze }) {
|
|
|
4278
4956
|
h('div', { className: 'lc-meta', style: { lineHeight: 1.7 } },
|
|
4279
4957
|
'把一大段话贴进来——小说片段、人物小传、你随口讲的关于某个人的事都行。',
|
|
4280
4958
|
h('br'),
|
|
4281
|
-
'存完点「让 AI
|
|
4959
|
+
'存完点「让 AI 读一读」,它会把里面的信息整理成一张卡。只认原文里写过的,编的会被丢掉。'),
|
|
4282
4960
|
h(Field, { label: '这是要建成什么人' },
|
|
4283
4961
|
h('div', { className: 'lc-row' },
|
|
4284
4962
|
h(Btn, { size: 'sm', tone: kind === 'real' ? 'interview' : undefined, onClick: () => setKind('real') }, '现实里的人'),
|
|
@@ -4471,7 +5149,7 @@ function peopleKey(p) {
|
|
|
4471
5149
|
|
|
4472
5150
|
// ── 让 AI 读材料 ──────────────────────────────────────────────────
|
|
4473
5151
|
|
|
4474
|
-
function AnalyzeView({ listing, state, flash, onProposal, presetAbout, presetMaterials, onBack, onNeedMaterial }) {
|
|
5152
|
+
function AnalyzeView({ listing, state, flash, onProposal, presetAbout, presetMaterials, onBack, onNeedMaterial, onAppliedCard }) {
|
|
4475
5153
|
const materials = listing?.materials ?? []
|
|
4476
5154
|
const cards = listing?.cards ?? []
|
|
4477
5155
|
// 从别的页带过来的人,可能只有一个名字:材料刚存下、卡还没建。
|
|
@@ -4480,7 +5158,13 @@ function AnalyzeView({ listing, state, flash, onProposal, presetAbout, presetMat
|
|
|
4480
5158
|
const presetId = String(presetAbout?.id ?? '').trim()
|
|
4481
5159
|
const presetName = String(presetAbout?.name ?? '').trim()
|
|
4482
5160
|
const [about, setAbout] = useState(presetId !== '' ? presetId : presetName)
|
|
4483
|
-
|
|
5161
|
+
// 带过来的材料可能是一份,也可能是好几份(访谈一路上记下来的)。
|
|
5162
|
+
// 不认数组的话会变成「[一份, 另一份]」被当成一个路径,一条都勾不上,
|
|
5163
|
+
// 而一条都不勾等于全读。
|
|
5164
|
+
const [chosen, setChosen] = useState(() => {
|
|
5165
|
+
if (Array.isArray(presetMaterials)) return presetMaterials.filter((x) => typeof x === 'string' && x !== '')
|
|
5166
|
+
return presetMaterials === undefined || presetMaterials === null ? [] : [presetMaterials]
|
|
5167
|
+
})
|
|
4484
5168
|
const [busy, setBusy] = useState(false)
|
|
4485
5169
|
const [err, setErr] = useState(null)
|
|
4486
5170
|
const [result, setResult] = useState(null)
|
|
@@ -4514,12 +5198,28 @@ function AnalyzeView({ listing, state, flash, onProposal, presetAbout, presetMat
|
|
|
4514
5198
|
// 卸载时补存一次,别让刚想出来的那句话白写。
|
|
4515
5199
|
const conceptDraftRef = useRef(null)
|
|
4516
5200
|
conceptDraftRef.current = conceptDraft
|
|
5201
|
+
// 下面这两个特意放在所有 hook 之后:上面那些槽位是有测试按号码摆状态的,
|
|
5202
|
+
// 中间插一个新 state 会让它们全体错位(conceptDraft 就是被这么挪过一次)。
|
|
5203
|
+
const [oneClick, setOneClick] = useState('')
|
|
5204
|
+
// 这一趟读的是虚构角色还是真人:虚构的才给「直接建成卡」,
|
|
5205
|
+
// 真人的卡要人自己填关系那些,不能一键生成。
|
|
5206
|
+
const isFiction = String(presetAbout?.kind ?? '').trim() === 'fictional'
|
|
4517
5207
|
useEffect(() => () => {
|
|
4518
5208
|
const pending = conceptDraftRef.current
|
|
4519
5209
|
if (pending === null || pending === undefined) return
|
|
4520
5210
|
call('concept.set', { concept: pending }).catch(() => {})
|
|
4521
5211
|
}, [])
|
|
4522
5212
|
|
|
5213
|
+
// 这一趟到底等了多久,明明白白数给人看。
|
|
5214
|
+
// 只说「正在读…」的话,超过半分钟人就开始怀疑卡死,去点第二次;
|
|
5215
|
+
// 两个请求叠在一起,后台更慢,看起来就更像卡死。
|
|
5216
|
+
const [waited, setWaited] = useState(0)
|
|
5217
|
+
useEffect(() => {
|
|
5218
|
+
if (busy !== true) { setWaited(0); return undefined }
|
|
5219
|
+
const timer = setInterval(() => setWaited((n) => n + 1), 1000)
|
|
5220
|
+
return () => clearInterval(timer)
|
|
5221
|
+
}, [busy])
|
|
5222
|
+
|
|
4523
5223
|
const flushConcept = async (value) => {
|
|
4524
5224
|
const next = value ?? conceptDraft ?? concept
|
|
4525
5225
|
setConceptDraft(null)
|
|
@@ -4559,6 +5259,11 @@ function AnalyzeView({ listing, state, flash, onProposal, presetAbout, presetMat
|
|
|
4559
5259
|
})
|
|
4560
5260
|
}
|
|
4561
5261
|
|
|
5262
|
+
// 选了哪几份就按哪几份算字数:「一条都不勾 = 全读」。
|
|
5263
|
+
const readChars = (chosen.length > 0 ? materials.filter((m) => chosen.includes(m.path)) : materials)
|
|
5264
|
+
.reduce((sum, m) => sum + (Number(m.chars) || Number(m.size) || 0), 0)
|
|
5265
|
+
const longRead = readChars > 20000
|
|
5266
|
+
|
|
4562
5267
|
const run = async () => {
|
|
4563
5268
|
// 「这一趟等了多久」从这里算。以前写成 startedAt 却没有声明,后台一连不上
|
|
4564
5269
|
// 就在 catch 里抛 ReferenceError,setErr 永远走不到——用户只看到按钮弹回来,
|
|
@@ -4700,14 +5405,45 @@ function AnalyzeView({ listing, state, flash, onProposal, presetAbout, presetMat
|
|
|
4700
5405
|
h(Btn, { tone: 'analyze', big: true, onClick: run, disabled: busy || about === '' || materials.length === 0, icon: 'spark' }, busy ? '正在读…' : '开始读'),
|
|
4701
5406
|
busy ? h(Spinner) : null,
|
|
4702
5407
|
),
|
|
5408
|
+
// 这一趟是真等:模型先在心里想一遍再写(实测小材料也要四十秒上下,
|
|
5409
|
+
// 长材料一分多钟)。不给时间预期的话,转圈超过半分钟人就会以为卡死了、
|
|
5410
|
+
// 去点第二次,两个请求叠在一起更慢。
|
|
5411
|
+
busy
|
|
5412
|
+
? h('div', { className: 'lc-meta' }, longRead
|
|
5413
|
+
? `材料有点长(约 ${Math.round(readChars / 1000)} 千字),这一趟可能一两分钟。已经等了 ${waited} 秒,别关这一页,等它说完。`
|
|
5414
|
+
: `它在先想一遍再写,一般要半分钟到一分钟。已经等了 ${waited} 秒,别关这一页,等它说完。`)
|
|
5415
|
+
: null,
|
|
4703
5416
|
|
|
4704
5417
|
result === null ? null : h('div', null,
|
|
4705
5418
|
h(Note, { tone: 'ok', icon: 'check' },
|
|
4706
5419
|
h('div', null, `读出了 ${result.accepted} 条。`),
|
|
4707
5420
|
result.rejected > 0 ? h('div', { className: 'lc-meta', style: { marginTop: 3 } }, `另有 ${result.rejected} 条在材料里找不到原句,已经丢掉——AI 编的东西进不来。`) : null,
|
|
4708
5421
|
),
|
|
5422
|
+
// 写小说和酒馆里,用户要的是「读完就有一张能用的角色卡」,
|
|
5423
|
+
// 不是再去访谈一遍——虚构角色本来就没有「他是我的什么人」这种问题,
|
|
5424
|
+
// 那些细节它自己会从材料里编。所以这里直接给一个一键建卡的入口。
|
|
5425
|
+
isFiction && result.json !== undefined
|
|
5426
|
+
? h('div', { style: { marginTop: 8 } },
|
|
5427
|
+
h(Btn, { tone: 'primary', big: true, block: true, icon: 'check', disabled: oneClick !== '', onClick: async () => {
|
|
5428
|
+
setOneClick('on')
|
|
5429
|
+
try {
|
|
5430
|
+
// 提案里默认一条都不勾(勾选是人的动作),所以这里要先把
|
|
5431
|
+
// 所有条目都勾上再采纳,否则只会得到「还没有勾选任何一条」。
|
|
5432
|
+
const got = await call('proposal.get', { json: result.json })
|
|
5433
|
+
if (got?.ok !== true) { setErr(got?.error ?? '这份建议读不出来'); return }
|
|
5434
|
+
const every = (got.items ?? []).map((item) => item.index).filter((n) => typeof n === 'number')
|
|
5435
|
+
if (every.length === 0) { setErr('这一份里没有能写进卡里的条目。'); return }
|
|
5436
|
+
const r = await call('proposal.apply', { json: result.json, checked: every })
|
|
5437
|
+
if (r?.ok !== true) { setErr(r?.error ?? '没能建成卡'); return }
|
|
5438
|
+
flash(`建好了,写进去 ${r.applied ?? every.length} 条`)
|
|
5439
|
+
if (typeof onAppliedCard === 'function' && r.path !== undefined) onAppliedCard(r.path)
|
|
5440
|
+
} catch (e) { setErr(humanizeError(e)) } finally { setOneClick('') }
|
|
5441
|
+
} }, oneClick === 'on' ? '正在建…' : '直接建成角色卡'),
|
|
5442
|
+
h('div', { className: 'lc-meta', style: { marginTop: 4 } }, '不用再访谈一遍。材料里读到什么就写什么,建完还能在卡上改。'),
|
|
5443
|
+
)
|
|
5444
|
+
: null,
|
|
4709
5445
|
h('div', { style: { marginTop: 8 } },
|
|
4710
|
-
h(Btn, { tone: 'primary', big: true, block: true, icon: 'check', onClick: async () => {
|
|
5446
|
+
h(Btn, { tone: isFiction ? undefined : 'primary', big: true, block: true, icon: 'check', onClick: async () => {
|
|
4711
5447
|
try {
|
|
4712
5448
|
const p = await call('proposal.get', { json: result.json })
|
|
4713
5449
|
// 读不出来当「没有新东西」会让界面绿字说「这一份里没有还没写进去的了」,
|
|
@@ -4867,6 +5603,7 @@ function JobsView({ onBack, flash }) {
|
|
|
4867
5603
|
// 这一页开头要读好几样东西(求职设置、以前读过的、投递表、故事)。
|
|
4868
5604
|
// 读失败时以前是静默吞掉——界面上就是「一片空」,跟「你还没填」长得一样。
|
|
4869
5605
|
const [loadFail, setLoadFail] = useState(false)
|
|
5606
|
+
const [savingStory, setSavingStory] = useState(false)
|
|
4870
5607
|
|
|
4871
5608
|
useEffect(() => {
|
|
4872
5609
|
let alive = true
|
|
@@ -5164,14 +5901,28 @@ function JobsView({ onBack, flash }) {
|
|
|
5164
5901
|
h('input', { className: 'lc-input', value: newStoryTitle, onChange: (e) => setNewStoryTitle(e.target.value), placeholder: '一次线上事故', spellCheck: false }),
|
|
5165
5902
|
),
|
|
5166
5903
|
h('textarea', { className: 'lc-textarea', value: newStoryBody, onChange: (e) => setNewStoryBody(e.target.value), placeholder: '凌晨两点被告警叫起来…', spellCheck: false }),
|
|
5167
|
-
h(Btn, {
|
|
5168
|
-
|
|
5169
|
-
|
|
5170
|
-
|
|
5171
|
-
|
|
5172
|
-
|
|
5173
|
-
|
|
5174
|
-
|
|
5904
|
+
h(Btn, {
|
|
5905
|
+
size: 'sm', icon: 'plus',
|
|
5906
|
+
disabled: savingStory || newStoryTitle.trim() === '' || newStoryBody.trim() === '',
|
|
5907
|
+
onClick: async () => {
|
|
5908
|
+
// 以前这里没有 try/catch:后台断了点它一声不响,用户只会以为按钮坏了;
|
|
5909
|
+
// 也没有忙等,网络慢连点两下会存出两条同名的记录。
|
|
5910
|
+
if (savingStory) return
|
|
5911
|
+
setSavingStory(true); setErr(null)
|
|
5912
|
+
try {
|
|
5913
|
+
const r = await call('job.story.add', { story: { title: newStoryTitle.trim(), body: newStoryBody.trim() } })
|
|
5914
|
+
if (r?.ok !== true) { setErr(r?.error ?? '没存上'); return }
|
|
5915
|
+
setNewStoryTitle(''); setNewStoryBody('')
|
|
5916
|
+
const again = await call('job.stories', {})
|
|
5917
|
+
if (again?.ok === true) setStories(again.stories ?? [])
|
|
5918
|
+
flash('记下来了')
|
|
5919
|
+
} catch (e) {
|
|
5920
|
+
setErr(humanizeError(e))
|
|
5921
|
+
} finally {
|
|
5922
|
+
setSavingStory(false)
|
|
5923
|
+
}
|
|
5924
|
+
},
|
|
5925
|
+
}, savingStory ? '正在存…' : '存下这段'),
|
|
5175
5926
|
),
|
|
5176
5927
|
),
|
|
5177
5928
|
|